diff --git a/lean/OAI/Probability/MatroidSecretary/Secretary/SourcePrefixLaw.lean b/lean/OAI/Probability/MatroidSecretary/Secretary/SourcePrefixLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1a4461112c13e7ea42d0598b3c4bcd9dba0ae35 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Secretary/SourcePrefixLaw.lean @@ -0,0 +1,108 @@ +import OAI.Probability.MatroidSecretary.Secretary.PrefixObservationModel +import OAI.Probability.MatroidSecretary.Secretary.SourceMask +import OAI.Probability.MatroidSecretary.Secretary.Prefix +import OAI.Probability.MatroidSecretary.Secretary.BinomialMixture +import Mathlib.MeasureTheory.Integral.Prod + +namespace OAI + +/-! +# The concrete source observation law after a uniform random prefix + +The initially sampled source seed determines the branch and prefix length. +An independent uniform permutation supplies the actual observed prefix. +Averaging the length, rather than conditioning on the complete initial seed, +recovers the full joint law of the branch and sacrificed source mask. + +This is the actual source-law input to conditional-table reconstruction in +`sections/secretary.tex`, equations `eq:secretary-prefix-mask` and its following +kernel argument (SHA256 +`3554fe0f7296782edf63cc7f1305c377e7a7b9d8f8948b9510ea4ad02a702d63`). +It does not assume a caller-given source transport law. +-/ + +namespace MatroidProphet.Secretary + +open MeasureTheory Finset + +/-- A predrawn Bernoulli mask supplies only the length; the independent random +prefix has the original product-mask law after averaging that length. -/ +theorem predrawn_mask_prefix_integral {n : ℕ} (p : ℝ) + (f : Finset (Fin n) → ℝ) : + bitsExpectation (fun _ : Fin n => p) univ (fun B => + ∫ σ : ArrivalOrder n, + f (univ.filter fun e : Fin n => (σ.symm e).val < B.card) + ∂(PMF.uniformOfFintype (ArrivalOrder n)).toMeasure) = + bitsExpectation (fun _ : Fin n => p) univ f := by + have hB (B : Finset (Fin n)) : + (∫ σ : ArrivalOrder n, + f (univ.filter fun e : Fin n => (σ.symm e).val < B.card) + ∂(PMF.uniformOfFintype (ArrivalOrder n)).toMeasure) = + (∑ S ∈ (univ : Finset (Fin n)).powersetCard B.card, f S) / + Nat.choose n B.card := + integral_uniform_prefix (by simpa using Finset.card_le_univ B) f + simp_rw [hB] + simpa only [Finset.card_univ, Fintype.card_fin, div_eq_mul_inv, mul_comm] using + SecretaryBinomialMixture.predrawn_card_uniform_subset p (univ : Finset (Fin n)) f + +/-- Exact test-function identity for the manuscript's concrete full source seed. +The branch, prefix length and every unused source coin are sampled before the +independent uniform permutation. -/ +theorem integral_source_random_prefix {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) (f : Bool → Finset (Fin n) → ℝ) : + (∫ r, ∫ σ : ArrivalOrder n, + f (mainBranch r) + (univ.filter fun e : Fin n => + (σ.symm e).val < ((completeHiddenRule M hE).mask r).card) + ∂(PMF.uniformOfFintype (ArrivalOrder n)).toMeasure ∂sourceSeedLaw n) = + ∫ r, f (mainBranch r) ((completeHiddenRule M hE).mask r) ∂sourceSeedLaw n := by + rw [integral_source_branch_mask M hE (fun j B => + ∫ σ : ArrivalOrder n, + f j (univ.filter fun e : Fin n => (σ.symm e).val < B.card) + ∂(PMF.uniformOfFintype (ArrivalOrder n)).toMeasure)] + rw [integral_source_branch_mask M hE f] + simp_rw [predrawn_mask_prefix_integral] + +/-- The full branch/prefix pushforward equals the branch/sacrificed-mask law of +our concrete source algorithm. This is the exact input used by the finite +conditional-table reconstruction, including empty and full prefixes. -/ +theorem source_random_prefix_joint_law {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) : + ((sourceSeedLaw n).prod + (PMF.uniformOfFintype (ArrivalOrder n)).toMeasure).map + (fun z : Seed (mainSeedBits n) × ArrivalOrder n => + (mainBranch z.1, orderPrefix z.2 ((completeHiddenRule M hE).mask z.1).card)) = + (sourceSeedLaw n).map + (fun r => (mainBranch r, (completeHiddenRule M hE).mask r)) := by + classical + let index : Seed (mainSeedBits n) × ArrivalOrder n → Bool × Finset (Fin n) := + fun z => (mainBranch z.1, orderPrefix z.2 ((completeHiddenRule M hE).mask z.1).card) + let obs : Seed (mainSeedBits n) → Bool × Finset (Fin n) := + fun r => (mainBranch r, (completeHiddenRule M hE).mask r) + let μ := (sourceSeedLaw n).prod (PMF.uniformOfFintype (ArrivalOrder n)).toMeasure + have htest (f : Bool × Finset (Fin n) → ℝ) : + (∫ z, f (index z) ∂μ) = ∫ r, f (obs r) ∂sourceSeedLaw n := by + rw [integral_prod _ Integrable.of_finite] + simpa only [index, obs, orderPrefix] using + integral_source_random_prefix M hE (fun j P => f (j, P)) + change μ.map index = (sourceSeedLaw n).map obs + apply Measure.ext_of_singleton + intro b + have hreal : (μ.map index).real {b} = ((sourceSeedLaw n).map obs).real {b} := by + rw [← integral_indicator_one (measurableSet_singleton b), + ← integral_indicator_one (measurableSet_singleton b)] + rw [integral_map_of_stronglyMeasurable (measurable_of_countable index) + (measurable_of_countable _).stronglyMeasurable, + integral_map_of_stronglyMeasurable (measurable_of_countable obs) + (measurable_of_countable _).stronglyMeasurable] + exact htest _ + calc + μ.map index {b} = ENNReal.ofReal ((μ.map index).real {b}) := + (ofReal_measureReal).symm + _ = ENNReal.ofReal (((sourceSeedLaw n).map obs).real {b}) := + congrArg ENNReal.ofReal hreal + _ = (sourceSeedLaw n).map obs {b} := ofReal_measureReal + +end MatroidProphet.Secretary + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Secretary/Specification.lean b/lean/OAI/Probability/MatroidSecretary/Secretary/Specification.lean new file mode 100644 index 0000000000000000000000000000000000000000..8c07ba157950c63861af5b498e5fa5d28a57edea --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Secretary/Specification.lean @@ -0,0 +1,18 @@ +import OAI.Probability.MatroidSecretary.Secretary.ProbabilityModel +import Mathlib.Probability.Independence.Basic +import Mathlib.MeasureTheory.Integral.Bochner.Basic + +/-! +# Independent specification of the full-seed secretary endpoint + +The rule and its finite initial seed law are chosen before the fixed vector +of weights and before the probability space or adversary. The initial +uniform order is independent of the complete seed. Only its ordered prefix +is preserved in the actual execution; the suffix may depend on all available +information, and even on additional randomization carried by the ambient +space. No independence assumption is made on the executed order. + +Finite seed types suffice for the manuscript construction: all conditional +reconstruction tables can be sampled in advance. `Fin q` is just an +enumeration of this finite seed space, with its arbitrary probability law. +-/ diff --git a/lean/OAI/Probability/MatroidSecretary/Secretary/TableLaw.lean b/lean/OAI/Probability/MatroidSecretary/Secretary/TableLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..04fe9f4a5ce936e8d68af3a031f80f7e091dbdf9 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Secretary/TableLaw.lean @@ -0,0 +1,60 @@ +import Mathlib.MeasureTheory.Integral.Pi +import Mathlib.MeasureTheory.Integral.Prod +import Mathlib.MeasureTheory.Integral.Bochner.SumMeasure + +namespace OAI + +/-! +# Precommitted finite conditional-randomness tables + +The secretary construction draws all conditional random choices before the +random arrival permutation. A table indexed by every possible branch/prefix +pair does this without concealing later randomness. Its law is the ordinary +finite product measure `Measure.pi κ`. Evaluating the table after an independent +prefix experiment has exactly the corresponding conditional law. + +These lemmas concern only this sampling construction, not the source theorem's +competitive guarantee. In particular an application must separately prove the +prefix law and the concrete source conditional-kernel laws. +-/ + +namespace MatroidProphet.Secretary + +open MeasureTheory +open scoped BigOperators + +variable {ι α Ω : Type*} [Fintype ι] [Fintype α] [Fintype Ω] + [MeasurableSpace α] [MeasurableSingletonClass α] + [MeasurableSpace Ω] [MeasurableSingletonClass Ω] + +/-- All conditional samples can be drawn initially and independently. Evaluating +one coordinate after an independent finite experiment has the prescribed law. -/ +theorem integral_precommittedTable + (κ : ι → Measure α) [∀ i, IsProbabilityMeasure (κ i)] + (μ : Measure Ω) [IsFiniteMeasure μ] (index : Ω → ι) (f : ι → α → ℝ) : + (∫ z : Ω × (ι → α), f (index z.1) (z.2 (index z.1)) + ∂μ.prod (Measure.pi κ)) = + ∫ ω, ∫ r, f (index ω) r ∂κ (index ω) ∂μ := by + rw [integral_prod _ Integrable.of_finite] + apply integral_congr_ae + exact ae_of_all _ fun ω => by + exact integral_comp_eval (μ := κ) (i := index ω) + (f := f (index ω)) + (measurable_of_countable (f (index ω))).aestronglyMeasurable + +/-- The same identity with the independent experiment explicitly summed. It +retains the complete table, including all coordinates unused in this run. -/ +theorem integral_precommittedTable_eq_sum + (κ : ι → Measure α) [∀ i, IsProbabilityMeasure (κ i)] + (μ : Measure Ω) [IsFiniteMeasure μ] (index : Ω → ι) (f : ι → α → ℝ) : + (∫ z : Ω × (ι → α), f (index z.1) (z.2 (index z.1)) + ∂μ.prod (Measure.pi κ)) = + ∑ ω, μ.real {ω} * (∫ r, f (index ω) r ∂κ (index ω)) := by + rw [integral_precommittedTable] + simpa only [smul_eq_mul, measureReal_def] using + (integral_fintype (μ := μ) + (f := fun ω => ∫ r, f (index ω) r ∂κ (index ω)) Integrable.of_finite) + +end MatroidProphet.Secretary + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernel.lean b/lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..b100d865358b6cad42f0df74009ac04fffd73141 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernel.lean @@ -0,0 +1,127 @@ +import OAI.Probability.MatroidProphet.Main +import OAI.Probability.MatroidSecretary.Secretary.TripleKernelModel +import Mathlib.Algebra.BigOperators.Finprod +import Mathlib.Probability.ProbabilityMassFunction.Constructions +import Mathlib.Tactic + +namespace OAI + +/-! Explicit normalized one-label reconstruction kernel from secretary.tex, +lines 64--81. These are finite identities, including the zero-mask case. -/ + +namespace MatroidProphet.Secretary + +open Finset + +lemma tripleWeight_sum (t : ℝ) : (∑ x : MaskTriple, tripleWeight t x) = 1 := by + simp [MaskTriple, Fintype.sum_prod_type, tripleWeight] + ring + +lemma tripleWeight_nonneg {t : ℝ} (ht0 : 0 ≤ t) (ht1 : t ≤ 1) + (x : MaskTriple) : 0 ≤ tripleWeight t x := by + rcases x with ⟨h,d,c⟩ + cases d <;> cases c <;> norm_num [tripleWeight] <;> linarith + +lemma tripleWeight_zero (t : ℝ) : + tripleWeight t (false, false, false) = 3 / 8 * (1-t) := by + norm_num [tripleWeight] + +lemma mainRevealRate_eq_source : + mainRevealRate = (5 : ℝ) / 8 + 3 * ((2 : ℝ)^143)⁻¹ := by + norm_num [mainRevealRate, thinningRate] + +lemma mainRevealRate_pos : 0 < mainRevealRate := by + norm_num [mainRevealRate, thinningRate] + +lemma mainRevealRate_lt_one : mainRevealRate < 1 := by + norm_num [mainRevealRate, thinningRate] + +lemma mainRevealRate_complement : + 1 - mainRevealRate = tripleWeight thinningRate (false, false, false) := by + simp [mainRevealRate, tripleWeight] + ring + +lemma tripleRevealed_eq_false (x : MaskTriple) : + tripleRevealed x = false ↔ x = (false, false, false) := by + rcases x with ⟨h,d,c⟩ + cases h <;> cases d <;> cases c <;> decide + +lemma conditionalTripleWeight_nonneg (b : Bool) (x : MaskTriple) : + 0 ≤ conditionalTripleWeight b x := by + have ht0 : 0 ≤ thinningRate := constants_positive.2.2.1.le + have ht1 : thinningRate ≤ 1 := by norm_num [thinningRate] + unfold conditionalTripleWeight + split_ifs + · exact div_nonneg (tripleWeight_nonneg ht0 ht1 x) mainRevealRate_pos.le + · norm_num + · norm_num + · norm_num + +lemma conditionalTripleWeight_sum (b : Bool) : + (∑ x : MaskTriple, conditionalTripleWeight b x) = 1 := by + cases b + · simp [conditionalTripleWeight] + · simp [MaskTriple, Fintype.sum_prod_type, + conditionalTripleWeight, tripleRevealed, tripleWeight] + field_simp [ne_of_gt mainRevealRate_pos] + simp [mainRevealRate] + ring + +lemma conditionalTripleWeight_support (b : Bool) (x : MaskTriple) + (h : tripleRevealed x ≠ b) : conditionalTripleWeight b x = 0 := by + rcases x with ⟨x,y,z⟩ + cases b <;> cases x <;> cases y <;> cases z <;> + simp_all [conditionalTripleWeight, tripleRevealed] + +/-- Multiplying the explicit conditional kernel by the observed-bit law +recovers the original joint law, not just a marginal event probability. -/ +lemma conditionalTripleWeight_joint (b : Bool) (x : MaskTriple) : + revealBitWeight b * conditionalTripleWeight b x = + if tripleRevealed x = b then tripleWeight thinningRate x else 0 := by + rcases x with ⟨x,y,z⟩ + cases b <;> cases x <;> cases y <;> cases z <;> + simp [revealBitWeight, conditionalTripleWeight, tripleRevealed, + mainRevealRate_complement] <;> + field_simp [ne_of_gt mainRevealRate_pos] + +lemma conditionalTripleWeight_reconstruct (x : MaskTriple) : + (∑ b : Bool, revealBitWeight b * conditionalTripleWeight b x) = + tripleWeight thinningRate x := by + simp only [conditionalTripleWeight_joint, Fintype.sum_bool] + cases h : tripleRevealed x <;> simp + +lemma revealBitWeight_pos (b : Bool) : 0 < revealBitWeight b := by + cases b + · exact sub_pos.mpr mainRevealRate_lt_one + · exact mainRevealRate_pos + +lemma revealBitWeight_sum : (∑ b : Bool, revealBitWeight b) = 1 := by + simp [revealBitWeight] + +lemma tripleWeight_source_pos (x : MaskTriple) : + 0 < tripleWeight thinningRate x := by + rcases x with ⟨h,d,c⟩ + cases d <;> cases c <;> norm_num [tripleWeight, thinningRate] + +/-- Exactly seven triples are compatible with an observed label. -/ +lemma card_revealed_triples : + Fintype.card {x : MaskTriple // tripleRevealed x = true} = 7 := by decide + +lemma conditionalTripleWeight_pos_iff (b : Bool) (x : MaskTriple) : + 0 < conditionalTripleWeight b x ↔ tripleRevealed x = b := by + constructor + · intro hx + by_contra h + rw [conditionalTripleWeight_support b x h] at hx + exact (lt_irrefl (0 : ℝ)) hx + · intro hx + have h := conditionalTripleWeight_joint b x + rw [ite_eq_left hx] at h + have hp : 0 < revealBitWeight b * conditionalTripleWeight b x := by + rw [h] + exact tripleWeight_source_pos x + exact (mul_pos_iff_of_pos_left (revealBitWeight_pos b)).mp hp + +end MatroidProphet.Secretary + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernelModel.lean b/lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernelModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..4b2630addabee6565e660afe5d1ca1dfcce18b01 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Secretary/TripleKernelModel.lean @@ -0,0 +1,39 @@ +import OAI.Probability.MatroidProphet.Main +import Mathlib.Data.Fintype.Prod + +namespace OAI + +/-! Concrete one-label conditional kernel for the secretary reconstruction. +The boolean records membership in the sacrificed observation mask, not branch choice. +The three coordinates are the original H, D, C coins; the T coin is not sacrificed. +-/ + +namespace MatroidProphet.Secretary + +abbrev MaskTriple := Bool × Bool × Bool + +/-- Whether at least one of the three observation coins is set. -/ +def tripleRevealed (x : MaskTriple) : Bool := x.1 || x.2.1 || x.2.2 + +/-- The independent H,D,C law at one label, retaining the thinning parameter. -/ +noncomputable def tripleWeight (t : ℝ) (x : MaskTriple) : ℝ := + (1 / 2) * (if x.2.1 then 1 / 4 else 3 / 4) * + (if x.2.2 then t else 1 - t) + +/-- Probability that a label is sacrificed in the main branch. -/ +noncomputable def mainRevealRate : ℝ := 5 / 8 + 3 * thinningRate / 8 + +/-- The source specifies all seven nonzero triple masses divided by the reveal rate. +Outside the observation set the triple is deterministically zero. -/ +noncomputable def conditionalTripleWeight (revealed : Bool) (x : MaskTriple) : ℝ := + if revealed then + if tripleRevealed x then tripleWeight thinningRate x / mainRevealRate else 0 + else if x = (false, false, false) then 1 else 0 + +/-- Probability of a prescribed observation-mask membership bit. -/ +noncomputable def revealBitWeight (revealed : Bool) : ℝ := + if revealed then mainRevealRate else 1 - mainRevealRate + +end MatroidProphet.Secretary + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/AssignedSafe.lean b/lean/OAI/Probability/MatroidSecretary/Selection/AssignedSafe.lean new file mode 100644 index 0000000000000000000000000000000000000000..339ac286c83a20104a7851dd60380fe84c4b6cea --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/AssignedSafe.lean @@ -0,0 +1,137 @@ +import OAI.Probability.MatroidProphet.Main +import OAI.Probability.MatroidSecretary.Selection.SafeSpecification + +namespace OAI + +namespace MatroidProphet + +open Finset +variable {α : Type*} [Fintype α] [DecidableEq α] + +/-- The stronger half-loss estimate explicitly obtained in the source proof. +The named lemma then enlarges the loss from `|D_h|/(2κ)` to `|D_h|/κ`. -/ +theorem safeSampleCount_half_loss + (M : Matroid α) (hE : M.E = Set.univ) + (κ : ℕ) (hκ : 0 < κ) (D : ℕ → Set α) (G : ℕ → Finset α) + (hG : Pairwise (fun i j => Disjoint (G i) (G j))) + (q : α → ℝ) (hq0 : ∀ e, 0 ≤ q e) (hq1 : ∀ e, q e ≤ 1) + (h : ℕ) (I : Finset α) (hI : M.Indep (I : Set α)) : + (((2 : ℝ) ^ 12)⁻¹) / 4 * I.card - (D h).ncard / (2 * (κ : ℝ)) ≤ + bitsExpectation q univ (fun C => bitsExpectation q univ (fun T => + fairParityExpectation (safeSampleCount M hE κ D G h I C T))) := by + have hpre := safeCountBeforeParity_lower M hE κ hκ D G hG q hq0 hq1 h I hI + have heq : bitsExpectation q univ (fun C => bitsExpectation q univ (fun T => + fairParityExpectation (safeSampleCount M hE κ D G h I C T))) = + bitsExpectation q univ (fun C => + bitsExpectation q univ (safeCountBeforeParity M hE κ D G h I C)) / 2 := by + simp only [safeSampleCount_fair_parity, div_eq_mul_inv] + simp_rw [bitsExpectation_mul_right] + rw [heq] + have hloss : ((D h).ncard : ℝ) / (2 * (κ : ℝ)) = + ((D h).ncard : ℝ) / (κ : ℝ) / 2 := by ring + rw [hloss] + linarith + +end MatroidProphet + +namespace MatroidProphet.MainAlgorithm + +open Finset +variable {n : ℕ} +attribute [local instance] Classical.propDecidable + +/-- The fixed-density safety estimate with the exact density-sample loss. -/ +theorem listedSafeStatistic_exact_density + (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (κ : ℕ) (hκ : 0 < κ) (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ) + (Y : Set (Fin n)) (hY : Y ⊆ (trueGroup M d s i : Set (Fin n))) + (hI : M.Indep Y) (q : Fin n → ℝ) + (hq0 : ∀ e, 0 ≤ q e) (hq1 : ∀ e, q e ≤ 1) : + exitThreshold / 4 * ((d.D : Set (Fin n)) ∩ Y).ncard - + (d.D ∩ trueGroup M d s i).card / (κ : ℝ) ≤ + bitsExpectation q univ (fun C => bitsExpectation q univ (fun T => + fairParityExpectation (fun p => + (listedSafeStatistic M hE κ (withMasks d d.D C T) s i Y + (boolParity p) : ℝ)))) := by + by_cases hi : i ∈ groups M d s + · have hsafe := safeLayerStatistic_lower M hE κ hκ (groupMask M d s d.D) + (groupGround M d s) (groupGround_disjoint M d s) q hq0 hq1 + ((groups M d s).idxOf i) (trueGroup M d s i : Set (Fin n)) + ((d.D : Set (Fin n)) ∩ Y) (Set.inter_subset_right.trans hY) + (hI.subset Set.inter_subset_right) + rw [groupMask_at_key M d s d.D _ i (groups_get?_idxOf M d s i hi), + Set.ncard_coe_finset] at hsafe + simpa only [listedSafeStatistic_guards M hE κ d s i Y, + hi, exitThreshold] using hsafe + · have hempty := unlisted_density_inter_empty M d s i hi Y hY + have hzero (C T : Finset (Fin n)) (p : Bool) : + listedSafeStatistic M hE κ (withMasks d d.D C T) s i Y + (boolParity p) = 0 := by + change (if i ∈ groups M d s then _ else 0) = 0 + rw [ite_eq_right hi] + simp only [hempty, Set.ncard_empty, Nat.cast_zero, mul_zero, zero_sub, + hzero, fairParityExpectation, zero_add, zero_div, bitsExpectation_const] + exact neg_nonpos.mpr (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) + +/-- Restricting the comparison set to this true group does not change its +safe-label statistic. This permits the source's global independent set `Y`. -/ +theorem listedSafeStatistic_inter_trueGroup + (M : Matroid (Fin n)) (hE : M.E = Set.univ) (κ : ℕ) + (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ) + (Y : Set (Fin n)) (ε : Fin 2) : + listedSafeStatistic M hE κ d s i + (Y ∩ (trueGroup M d s i : Set (Fin n))) ε = + listedSafeStatistic M hE κ d s i Y ε := by + unfold listedSafeStatistic + split_ifs + · unfold safeLayerStatistic + apply sum_congr rfl + intro b _ + congr 1 + ext e + simp only [safeLayerSet, Set.mem_sdiff, Set.mem_inter_iff] + constructor + · rintro ⟨⟨⟨heD, heY, _⟩, heL⟩, heN⟩ + exact ⟨⟨⟨heD, heY⟩, heL⟩, heN⟩ + · rintro ⟨⟨⟨heD, heY⟩, heL⟩, heN⟩ + exact ⟨⟨⟨heD, heY, heL.1⟩, heL⟩, heN⟩ + · rfl + +/-- Source `lem:safe`, specialized to the manuscript's literal density +threshold and thinning rate, for the global independent comparison set. +It also covers an unlisted group, whose safe count is defined to be zero. -/ +theorem safe_sampled_labels + (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ) + (Y : Set (Fin n)) (hI : M.Indep Y) : + exitThreshold / 4 * + ((d.D : Set (Fin n)) ∩ (Y ∩ (trueGroup M d s i : Set (Fin n)))).ncard - + (d.D ∩ trueGroup M d s i).card / densityThreshold ≤ + bitsExpectation (fun _ => thinningRate) univ (fun C => + bitsExpectation (fun _ => thinningRate) univ (fun T => + fairParityExpectation (fun p => + (listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i Y + (boolParity p) : ℝ)))) := by + have hs := listedSafeStatistic_exact_density M hE (2 ^ 100) (by positivity) + d s i (Y ∩ (trueGroup M d s i : Set (Fin n))) Set.inter_subset_right + (hI.subset Set.inter_subset_left) (fun _ => thinningRate) + (fun _ => constants_positive.2.2.1.le) + (fun _ => by norm_num [thinningRate]) + have heq (C T : Finset (Fin n)) (p : Bool) : + listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i + (Y ∩ (trueGroup M d s i : Set (Fin n))) (boolParity p) = + listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i Y + (boolParity p) := by + simpa only [trueGroup_withMasks] using + listedSafeStatistic_inter_trueGroup M hE (2 ^ 100) + (withMasks d d.D C T) s i Y (boolParity p) + simpa only [Nat.cast_pow, Nat.cast_ofNat, densityThreshold, heq] using hs + +/-- Proof of the independently stated complete safe-label claim. -/ +theorem safe_sampled_labels_claim : SafeSampleClaim := by + intro n M hE d s i Y hI + exact safe_sampled_labels M hE d s i Y hI + +end MatroidProphet.MainAlgorithm + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/AveragedSafeExact.lean b/lean/OAI/Probability/MatroidSecretary/Selection/AveragedSafeExact.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a7cd488b36e1960b65164d7bb847abcda62e49a --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/AveragedSafeExact.lean @@ -0,0 +1,119 @@ +import OAI.Probability.MatroidSecretary.Selection.AssignedSafe + +namespace OAI + +/-! +# The exact density-averaged safety loss + +This retains the first, sharper inequality in `eq:averaged-safe-count` +(`sections/transfer.tex`, line 330). The density mask is averaged only after +the exact conditional loss has been bounded by `|D ∩ U_i| / κ`. The previous +endpoint route weakened this to `|U_i| / κ` before averaging, which suffices +there but does not state the displayed `|U_i| / (4κ)` estimate. + +The statistic remains zero on unlisted outcomes. No conditioning on listing, +focal density bits, or an arrival order is introduced. +-/ + +namespace MatroidProphet.MainAlgorithm + +open Finset + +variable {n : ℕ} + +/-- Literal first inequality of `eq:averaged-safe-count`, for a fixed true +group and any independent comparison subset of that group. -/ +theorem listedSafeStatistic_averaged_exact + (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (κ : ℕ) (hκ : 0 < κ) (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ) + (Y : Set (Fin n)) (hY : Y ⊆ (trueGroup M d s i : Set (Fin n))) + (hI : M.Indep Y) (q : Fin n → ℝ) + (hq0 : ∀ e, 0 ≤ q e) (hq1 : ∀ e, q e ≤ 1) : + retainedFraction * Y.ncard - (trueGroup M d s i).card / (4 * (κ : ℝ)) ≤ + tripleMaskExpectation (fun _ => (1 : ℝ) / 4) q q univ (fun D C T => + fairParityExpectation (fun p => + (listedSafeStatistic M hE κ (withMasks d D C T) s i Y + (boolParity p) : ℝ))) := by + classical + have hfixed (D : Finset (Fin n)) : + exitThreshold / 4 * ((D : Set (Fin n)) ∩ Y).ncard - + (D ∩ trueGroup M d s i).card / (κ : ℝ) ≤ + bitsExpectation q univ (fun C => bitsExpectation q univ (fun T => + fairParityExpectation (fun p => + (listedSafeStatistic M hE κ (withMasks d D C T) s i Y + (boolParity p) : ℝ)))) := + listedSafeStatistic_exact_density M hE κ hκ (withMasks d D ∅ ∅) + s i Y hY hI q hq0 hq1 + have hmean := bitsExpectation_mono (fun _ : Fin n => (1 : ℝ) / 4) + (by intro e; norm_num) (by intro e; norm_num) univ (fun D _ => hfixed D) + have hcardY : bitsExpectation (fun _ : Fin n => (1 : ℝ) / 4) univ + (fun D => (((D : Set (Fin n)) ∩ Y).ncard : ℝ)) = Y.ncard / 4 := by + have hset (D : Finset (Fin n)) : (D : Set (Fin n)) ∩ Y = + ((Y.toFinset ∩ D : Finset (Fin n)) : Set (Fin n)) := by + ext e + simp only [Set.mem_inter_iff, Finset.mem_coe, mem_inter, Set.mem_toFinset] + exact and_comm + simp only [hset, Set.ncard_coe_finset] + rw [bitsExpectation_card_inter (fun _ : Fin n => (1 : ℝ) / 4) + univ Y.toFinset (subset_univ _)] + simp only [sum_const, nsmul_eq_mul, ← Set.ncard_eq_toFinset_card'] + ring + have hcardU : bitsExpectation (fun _ : Fin n => (1 : ℝ) / 4) univ + (fun D => ((D ∩ trueGroup M d s i).card : ℝ)) = + (trueGroup M d s i).card / 4 := by + simpa [Finset.inter_comm, div_eq_mul_inv] using + bitsExpectation_card_inter (fun _ : Fin n => (1 : ℝ) / 4) + univ (trueGroup M d s i) (subset_univ _) + have heq : bitsExpectation (fun _ : Fin n => (1 : ℝ) / 4) univ + (fun D => exitThreshold / 4 * ((D : Set (Fin n)) ∩ Y).ncard - + (D ∩ trueGroup M d s i).card / (κ : ℝ)) = + retainedFraction * Y.ncard - (trueGroup M d s i).card / (4 * (κ : ℝ)) := by + calc + _ = bitsExpectation (fun _ : Fin n => (1 : ℝ) / 4) univ + (fun D => exitThreshold / 4 * ((D : Set (Fin n)) ∩ Y).ncard + + (-(κ : ℝ)⁻¹) * (D ∩ trueGroup M d s i).card) := by + apply bitsExpectation_congr + intro D _ + ring + _ = exitThreshold / 4 * (Y.ncard / 4) + + (-(κ : ℝ)⁻¹) * ((trueGroup M d s i).card / 4) := by + rw [bitsExpectation_add, bitsExpectation_mul_const, + bitsExpectation_mul_const, hcardY, hcardU] + _ = _ := by + norm_num [exitThreshold, retainedFraction] + ring + rw [heq] at hmean + exact hmean + +/-- Source specialization for its global independent comparison set `Y`. +The intersection appearing here is exactly the source's `Y_i`; all statistics +are those of the actual density-dependent listed groups. -/ +theorem averaged_safe_sampled_labels + (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ) + (Y : Set (Fin n)) (hI : M.Indep Y) : + retainedFraction * (Y ∩ (trueGroup M d s i : Set (Fin n))).ncard - + (trueGroup M d s i).card / (4 * densityThreshold) ≤ + tripleMaskExpectation (fun _ => (1 : ℝ) / 4) + (fun _ => thinningRate) (fun _ => thinningRate) univ (fun D C T => + fairParityExpectation (fun p => + (listedSafeStatistic M hE (2 ^ 100) (withMasks d D C T) s i Y + (boolParity p) : ℝ))) := by + have hs := listedSafeStatistic_averaged_exact M hE (2 ^ 100) (by positivity) + d s i (Y ∩ (trueGroup M d s i : Set (Fin n))) Set.inter_subset_right + (hI.subset Set.inter_subset_left) (fun _ => thinningRate) + (fun _ => constants_positive.2.2.1.le) + (fun _ => by norm_num [thinningRate]) + have heq (D C T : Finset (Fin n)) (p : Bool) : + listedSafeStatistic M hE (2 ^ 100) (withMasks d D C T) s i + (Y ∩ (trueGroup M d s i : Set (Fin n))) (boolParity p) = + listedSafeStatistic M hE (2 ^ 100) (withMasks d D C T) s i Y + (boolParity p) := by + simpa only [trueGroup_withMasks] using + listedSafeStatistic_inter_trueGroup M hE (2 ^ 100) + (withMasks d D C T) s i Y (boolParity p) + simpa only [Nat.cast_pow, Nat.cast_ofNat, densityThreshold, heq] using hs + +end MatroidProphet.MainAlgorithm + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/CandidateContract.lean b/lean/OAI/Probability/MatroidSecretary/Selection/CandidateContract.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2e4e38e31dc2d9f471b76a6ee8bcd60c7a87f5b --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/CandidateContract.lean @@ -0,0 +1,89 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +namespace MatroidProphet.SourceContracts + +open Finset Set MainAlgorithm + +/-- Positive rounding does not remove a positive weight or create one at zero. -/ +theorem roundedWeight_pos_iff {B x : ℝ} (hB : 0 < B) : + 0 < roundedWeight B x ↔ 0 < x := by + unfold roundedWeight roundedLevel + by_cases hx : 0 < x + · rw [ite_eq_left hx, levelWeight] + exact iff_of_true (zpow_pos hB _) hx + · rw [ite_eq_right hx, levelWeight] + exact iff_of_false (lt_irrefl 0) hx + +/-- The actual candidate test is exactly `eq:candidates`, with higher rounded +levels taking priority and the original fixed label order breaking ties. -/ +theorem mem_candidateLabels_iff {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) (B : ℝ) (H : Finset (Fin n)) (e : Fin n) : + e ∈ candidateLabels M (fun f => roundedLevel B (w f)) H ↔ + 0 < w e ∧ e ∉ H ∧ + e ∉ M.closure {f | f ∈ H ∧ + higher f (roundedLevel B (w f)) e (roundedLevel B (w e))} := by + classical + have hpos : roundedLevel B (w e) ≠ none ↔ 0 < w e := by + simp [roundedLevel] + constructor + · intro hcandidate + obtain ⟨hlevel, houtside, hclosure⟩ := (Finset.mem_filter.mp hcandidate).2 + exact ⟨hpos.mp hlevel, houtside, hclosure⟩ + · rintro ⟨hpositive, houtside, hclosure⟩ + exact Finset.mem_filter.mpr + ⟨Finset.mem_univ _, hpos.mpr hpositive, houtside, hclosure⟩ + +/-- The same test in the source's literal `u_e > 0` notation. -/ +theorem mem_candidateLabels_iff_rounded {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) {B : ℝ} (hB : 0 < B) (H : Finset (Fin n)) (e : Fin n) : + e ∈ candidateLabels M (fun f => roundedLevel B (w f)) H ↔ + 0 < roundedWeight B (w e) ∧ e ∉ H ∧ + e ∉ M.closure {f | f ∈ H ∧ + higher f (roundedLevel B (w f)) e (roundedLevel B (w e))} := by + rw [roundedWeight_pos_iff hB] + exact mem_candidateLabels_iff M w B H e + +/-- Candidates cannot be loops, including when loops have positive weights. -/ +theorem candidateLabels_nonloop {n : ℕ} (M : Matroid (Fin n)) + (a : Fin n → Option ℤ) (H : Finset (Fin n)) (e : Fin n) + (he : e ∈ candidateLabels M a H) : e ∉ M.closure ∅ := by + classical + exact candidate_not_mem_closure_empty M ⟨H, ∅, ∅, ∅, false⟩ a e (a e) + (Finset.mem_filter.mp he).2 + +/-- Both deterministic assertions and both expectation assertions in `lem:filter`. +The assumptions include no positive-rank, nonempty-ground, or no-ties condition. -/ +theorem candidate_mass {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (w : Weights n) (_hw : ∀ e, 0 ≤ w e) {B : ℝ} (hB : 1 < B) : + (∀ H : Finset (Fin n), + M.Indep ((positiveGreedy M (fun e => roundedLevel B (w e)) \ H : + Finset (Fin n)) : Set (Fin n)) ∧ + positiveGreedy M (fun e => roundedLevel B (w e)) \ H ⊆ + candidateLabels M (fun e => roundedLevel B (w e)) H) ∧ + bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ + (fun H => ∑ e ∈ positiveGreedy M (fun e => roundedLevel B (w e)) \ H, + roundedWeight B (w e)) = optimum M (fun e => roundedWeight B (w e)) / 2 ∧ + bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ + (fun H => ∑ e ∈ candidateLabels M (fun e => roundedLevel B (w e)) H, + roundedWeight B (w e)) ≤ optimum M (fun e => roundedWeight B (w e)) := by + refine ⟨?_, expectation_positiveGreedy_survivors M hE w hB, + expectation_candidateLabels_le_optimum M hE w B⟩ + intro H + exact ⟨positiveGreedy_survivors_indep M hE _ H, + positiveGreedy_survivors_subset M _ H⟩ + +/-- The two-sided optimum rounding estimate `eq:rounding`, including zero weights. -/ +theorem optimum_rounding {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) (hw : ∀ e, 0 ≤ w e) {B : ℝ} (hB : 1 < B) : + optimum M w / B ≤ optimum M (fun e => roundedWeight B (w e)) ∧ + optimum M (fun e => roundedWeight B (w e)) ≤ optimum M w := by + constructor + · apply (div_le_iff₀ (zero_lt_one.trans hB)).2 + simpa only [mul_comm] using optimum_rounding_bound M B hB w hw + · exact optimum_mono M _ w (fun e => roundedWeight_le hB (hw e)) + +end MatroidProphet.SourceContracts + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/CandidateContracts.lean b/lean/OAI/Probability/MatroidSecretary/Selection/CandidateContracts.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b429367b9a39f6164f29862f009395bacbb061f --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/CandidateContracts.lean @@ -0,0 +1,77 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +/-! +Source-facing contracts for the candidate filter (setup.tex, Lemma `lem:filter`). +The sets below are the actual rounded-priority greedy survivors and candidate +labels, not arbitrary sets satisfying a desired inequality. The fair-mask law +is the concrete product law `bitsExpectation` on the entire labeled ground set. +-/ + +namespace MatroidProphet.CandidateContracts + +open Finset MainAlgorithm + +/-- The full candidate-mass contract, including pointwise independence and +containment for every mask. No positivity premise is needed here because the +rounding map itself discards nonpositive coordinates. -/ +theorem candidate_mass {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) (w : Weights n) : + let a := fun e => roundedLevel weightBase (w e) + let Y := fun H => positiveGreedy M a \ H + let U := candidateLabels M a + (∀ H, M.Indep (Y H : Set (Fin n)) ∧ Y H ⊆ U H) ∧ + bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ + (fun H => ∑ e ∈ Y H, roundedWeight weightBase (w e)) = + optimum M (fun e => roundedWeight weightBase (w e)) / 2 ∧ + bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ + (fun H => ∑ e ∈ U H, roundedWeight weightBase (w e)) ≤ + optimum M (fun e => roundedWeight weightBase (w e)) := by + dsimp only + refine ⟨?_, ?_, ?_⟩ + · intro H + exact ⟨positiveGreedy_survivors_indep M hE _ H, + positiveGreedy_survivors_subset M _ H⟩ + · exact expectation_positiveGreedy_survivors M hE w (by norm_num [weightBase]) + · exact expectation_candidateLabels_le_optimum M hE w weightBase + +/-- Both inequalities of the source's rounding bound, together with an actual +independent positive-priority greedy maximizer. This includes zero weights, +loops, ties, the empty ground set, and rank zero. -/ +theorem rounding_and_greedy {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) (w : Weights n) (hw : ∀ e, 0 ≤ w e) : + let u := fun e => roundedWeight weightBase (w e) + let I := positiveGreedy M (fun e => roundedLevel weightBase (w e)) + optimum M w / weightBase ≤ optimum M u ∧ + optimum M u ≤ optimum M w ∧ + M.Indep (I : Set (Fin n)) ∧ + (∑ e ∈ I, u e) = optimum M u := by + dsimp only + have hB : (1 : ℝ) < weightBase := by norm_num [weightBase] + refine ⟨?_, ?_, positiveGreedy_indep M hE _, ?_⟩ + · apply (div_le_iff₀ (zero_lt_one.trans hB)).2 + simpa only [mul_comm] using optimum_rounding_bound M weightBase hB w hw + · exact optimum_mono M _ w (fun e => roundedWeight_le hB (hw e)) + · change (∑ e ∈ positiveGreedy M (fun e => roundedLevel weightBase (w e)), + levelWeight weightBase (roundedLevel weightBase (w e))) = _ + rw [sum_positiveGreedy] + exact Priority.rounded_greedy_optimal M hE w hB + +/-- The actual candidate predicate never includes a loop or a nonpositive label. +This is a pointwise statement for every mask, not only almost surely. -/ +theorem candidate_positive_nonloop {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) (H : Finset (Fin n)) (e : Fin n) + (he : e ∈ candidateLabels M (fun f => roundedLevel weightBase (w f)) H) : + 0 < w e ∧ e ∉ H ∧ e ∉ M.closure ∅ := by + classical + have hc : candidate M ⟨H, ∅, ∅, ∅, false⟩ + (fun f => roundedLevel weightBase (w f)) e (roundedLevel weightBase (w e)) := + (Finset.mem_filter.mp he).2 + refine ⟨?_, hc.2.1, candidate_not_mem_closure_empty M _ _ _ _ hc⟩ + by_contra hn + exact hc.1 (by simp [roundedLevel, hn]) + +end MatroidProphet.CandidateContracts + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecification.lean b/lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecification.lean new file mode 100644 index 0000000000000000000000000000000000000000..be512870114bd6d1583b35550966ace2e57097ce --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecification.lean @@ -0,0 +1,53 @@ +import Mathlib.Combinatorics.Matroid.Closure +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +namespace MatroidProphet.CandidateSpecification + +open Finset + +/-- Strict rounded-weight priority, including the fixed label tie-breaking rule. -/ +def higher {n : ℕ} (f : Fin n) (a : Option ℤ) (e : Fin n) (b : Option ℤ) : Prop := + match a, b with + | some i, some j => j < i ∨ j = i ∧ f < e + | some _, none => True + | _, _ => False + +/-- Source candidate set: positive, unobserved, and not spanned by higher-priority +observed labels. The full candidate set is analytical, not given to the algorithm. -/ +noncomputable def candidates {n : ℕ} (M : Matroid (Fin n)) + (a : Fin n → Option ℤ) (H : Finset (Fin n)) : Finset (Fin n) := by + classical + exact Finset.univ.filter fun e => a e ≠ none ∧ e ∉ H ∧ + e ∉ M.closure {f | f ∈ H ∧ higher f (a f) e (a e)} + +/-- Positive priority-greedy on the entire ground set, characterized by failure +of the strictly higher-priority labels to span the current label. -/ +noncomputable def greedy {n : ℕ} (M : Matroid (Fin n)) + (a : Fin n → Option ℤ) : Finset (Fin n) := by + classical + exact Finset.univ.filter fun e => a e ≠ none ∧ + e ∉ M.closure {f | higher f (a f) e (a e)} + +/-- The source comparison independent set after sacrificing the fair mask. -/ +noncomputable def survivors {n : ℕ} (M : Matroid (Fin n)) + (a : Fin n → Option ℤ) (H : Finset (Fin n)) : Finset (Fin n) := + greedy M a \ H + +/-- The complete mathematical assertion of Lemma `lem:filter`, stated solely +using the concrete source definitions and the finite independent fair-mask law. -/ +def CandidateMass : Prop := + ∀ (n : ℕ) (M : Matroid (Fin n)), M.E = Set.univ → ∀ w : Weights n, + let a := fun e => roundedLevel weightBase (w e) + let u := fun e => roundedWeight weightBase (w e) + (∀ H, M.Indep (survivors M a H : Set (Fin n)) ∧ + survivors M a H ⊆ candidates M a H) ∧ + bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ + (fun H => ∑ e ∈ survivors M a H, u e) = optimum M u / 2 ∧ + bitsExpectation (fun _ => (1 / 2 : ℝ)) Finset.univ + (fun H => ∑ e ∈ candidates M a H, u e) ≤ optimum M u + +end MatroidProphet.CandidateSpecification + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecificationTheorems.lean b/lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecificationTheorems.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1ca9b9837034583334dbb521a2f7368f8c72bcf --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/CandidateSpecificationTheorems.lean @@ -0,0 +1,88 @@ +import OAI.Probability.MatroidSecretary.Selection.CandidateSpecification +import OAI.Probability.MatroidSecretary.Selection.CandidateContracts + +namespace OAI + +/-! Correspondence of the independent source definitions with the implemented +candidate filter and positive priority-greedy, followed by the source contract. -/ + +namespace MatroidProphet.CandidateSpecification + +open Finset + +lemma higher_eq_main {n : ℕ} (f : Fin n) (a : Option ℤ) + (e : Fin n) (b : Option ℤ) : + higher f a e b ↔ MainAlgorithm.higher f a e b := Iff.rfl + +lemma candidates_eq_main {n : ℕ} (M : Matroid (Fin n)) + (a : Fin n → Option ℤ) (H : Finset (Fin n)) : + candidates M a H = MainAlgorithm.candidateLabels M a H := by + classical + rw [MainAlgorithm.candidateLabels, MainAlgorithm.candidateSet_eq_filter] + ext element + by_cases hpositive : a element = none + · simp [candidates, hpositive] + · have hprior : {label | label ∈ H ∧ higher label (a label) element (a element)} = + Candidates.prior (Priority.time a) H element := by + ext label + simp only [Candidates.prior, Set.mem_ofPred_eq, higher_eq_main, + Priority.main_higher_iff_time a label element hpositive] + simp [candidates, Candidates.candidates, hpositive, hprior] + +lemma greedy_eq_main {n : ℕ} (M : Matroid (Fin n)) + (a : Fin n → Option ℤ) : greedy M a = MainAlgorithm.positiveGreedy M a := by + classical + ext e + by_cases ha : a e = none + · simp [greedy, MainAlgorithm.positiveGreedy, ha] + · have hp : {f | higher f (a f) e (a e)} = + Candidates.prior (Priority.time a) Finset.univ e := by + ext f + simp only [Candidates.prior, Finset.mem_univ, true_and, + Set.mem_ofPred_eq, higher_eq_main, Priority.main_higher_iff_time a f e ha] + simp [greedy, MainAlgorithm.positiveGreedy, Candidates.greedy, ha, hp] + +lemma survivors_eq_main {n : ℕ} (M : Matroid (Fin n)) + (a : Fin n → Option ℤ) (H : Finset (Fin n)) : + survivors M a H = MainAlgorithm.positiveGreedy M a \ H := by + rw [survivors, greedy_eq_main] + + + +theorem candidateMass : CandidateMass := by + intro n M hE w + simpa only [survivors_eq_main, candidates_eq_main] using + CandidateContracts.candidate_mass M hE w + +/-- Candidate membership uses only the focal key and keys on the revealed mask, +never another unobserved label's key. -/ +lemma candidate_membership_congr {n : ℕ} (M : Matroid (Fin n)) + (a a' : Fin n → Option ℤ) (H : Finset (Fin n)) (e : Fin n) + (he : a e = a' e) (hH : ∀ f ∈ H, a f = a' f) : + e ∈ candidates M a H ↔ e ∈ candidates M a' H := by + classical + have hp : {f | f ∈ H ∧ higher f (a f) e (a e)} = + {f | f ∈ H ∧ higher f (a' f) e (a' e)} := by + ext f + by_cases hf : f ∈ H + · simp [hf, he, hH f hf] + · simp [hf] + simp only [candidates, Finset.mem_filter, Finset.mem_univ, true_and] + rw [hp, he] + +/-- The source greedy definition really attains rounded OPT, with the source's +rounding comparison on both sides. This verifies the ancillary input `I*` rather +than assuming its optimality. -/ +theorem source_rounding_and_greedy {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) (w : Weights n) (hw : ∀ e, 0 ≤ w e) : + let u := fun e => roundedWeight weightBase (w e) + let I := greedy M (fun e => roundedLevel weightBase (w e)) + optimum M w / weightBase ≤ optimum M u ∧ + optimum M u ≤ optimum M w ∧ + M.Indep (I : Set (Fin n)) ∧ + (∑ e ∈ I, u e) = optimum M u := by + simpa only [greedy_eq_main] using CandidateContracts.rounding_and_greedy M hE w hw + +end MatroidProphet.CandidateSpecification + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/FeasibilityContract.lean b/lean/OAI/Probability/MatroidSecretary/Selection/FeasibilityContract.lean new file mode 100644 index 0000000000000000000000000000000000000000..03a8479cdf5a624b62da700ccf73baccb85e4ace --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/FeasibilityContract.lean @@ -0,0 +1,123 @@ +import OAI.Probability.MatroidProphet.Main +import OAI.Probability.MatroidSecretary.Accounting.MainFeasibilityContract +import OAI.Probability.MatroidSecretary.Selection.FeasibilitySpec +import OAI.Probability.MatroidSecretary.Selection.GreedyExecution + +namespace OAI + +/-! Complete source contract for `algorithm.tex`, `lem:feasibility` (lines +179--183; source SHA256 b702fa1da832d3cbebcf5a70f0b0e9505b3423e2ed9884c22fe4194ba4974fbe). +The actual main rule is used, not an abstract feasible-rule hypothesis. -/ + +namespace MatroidProphet +namespace FeasibilityContract +open Set Finset MeasureTheory + +/-- Hidden observations depend only on the initially sacrificed coordinates. -/ +theorem observed_eq_of_eq_on_mask {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w w' : Weights n) + (h : ∀ e ∈ A.mask r, w e = w' e) : + observed A r w = observed A r w' := by + classical + funext e + by_cases he : e ∈ A.mask r + · simp only [observed, ite_eq_left he, h e he] + · simp only [observed, ite_eq_right he] + +/-- Hidden execution is nonanticipating: equal initial observations and equal +revealed histories force equal current decisions, irrespective of future data. -/ +theorem hidden_decision_congr {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w w' : Weights n) (π π' : ArrivalOrder n) (k : Fin n) + (hmask : ∀ e ∈ A.mask r, w e = w' e) + (hhist : history w π k = history w' π' k) : + decisionAt A.core r (observed A r w) w π k = + decisionAt A.core r (observed A r w') w' π' k := by + rw [observed_eq_of_eq_on_mask A r w w' hmask] + exact decisionAt_congr A.core r (observed A r w') w w' π π' k hhist + +/-- Sacrificing the fixed mask preserves irrevocability. -/ +theorem hiddenAcceptedThrough_mono {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) + {t t' : ℕ} (h : t ≤ t') : + hiddenAcceptedThrough A r w π t ⊆ hiddenAcceptedThrough A r w π t' := by + intro e he + obtain ⟨he, hm⟩ := Finset.mem_sdiff.mp he + exact Finset.mem_sdiff.mpr + ⟨acceptedThrough_mono A.core r (observed A r w) w π h he, hm⟩ + +/-- No sacrificed observation label is ever accepted. -/ +theorem hiddenAcceptedThrough_disjoint_mask {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) (t : ℕ) : + Disjoint (hiddenAcceptedThrough A r w π t) (A.mask r) := by + apply Finset.disjoint_left.mpr + intro e he hm + exact (Finset.mem_sdiff.mp he).2 hm + +/-- All parts of the manuscript's feasibility and information contract for the +actual layered main algorithm. Empty ground sets, loops, zero weights, ties, +and empty group lists remain within the quantified input domain. -/ +theorem main_rule {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ) : + (∀ (w : Weights n), (∀ e, 0 ≤ w e) → + ∀ (r : Seed (mainSeedBits n)) (π : ArrivalOrder n) (t : ℕ), + M.Indep (hiddenAcceptedThrough (MainAlgorithm.hidden M hE) r w π t : Set (Fin n))) ∧ + (∀ k, Measurable + (fun x : Seed (mainSeedBits n) × (Weights n × History n k) => + (MainAlgorithm.core M hE).decide k x.1 x.2.1 x.2.2)) ∧ + (∀ (r : Seed (mainSeedBits n)) (w w' : Weights n) + (π π' : ArrivalOrder n) (k : Fin n), + (∀ e ∈ (MainAlgorithm.hidden M hE).mask r, w e = w' e) → + history w π k = history w' π' k → + decisionAt (MainAlgorithm.core M hE) r + (observed (MainAlgorithm.hidden M hE) r w) w π k = + decisionAt (MainAlgorithm.core M hE) r + (observed (MainAlgorithm.hidden M hE) r w') w' π' k) ∧ + (∀ (r : Seed (mainSeedBits n)) (w : Weights n) (π : ArrivalOrder n) + (t t' : ℕ), t ≤ t' → + hiddenAcceptedThrough (MainAlgorithm.hidden M hE) r w π t ⊆ + hiddenAcceptedThrough (MainAlgorithm.hidden M hE) r w π t') ∧ + (∀ (r : Seed (mainSeedBits n)) (w : Weights n) (π : ArrivalOrder n) (t : ℕ), + Disjoint (hiddenAcceptedThrough (MainAlgorithm.hidden M hE) r w π t) + ((mainMasks r).H ∪ (mainMasks r).D ∪ (mainMasks r).C)) := by + refine ⟨MainAlgorithm.hidden_feasible M hE, ?_, ?_, ?_, ?_⟩ + · exact (MainAlgorithm.core M hE).measurable_decide + · exact hidden_decision_congr (MainAlgorithm.hidden M hE) + · intro r w π t t' ht + exact hiddenAcceptedThrough_mono (MainAlgorithm.hidden M hE) r w π ht + · exact hiddenAcceptedThrough_disjoint_mask (MainAlgorithm.hidden M hE) + +/-- The empty listed-group case cannot assign any arriving label to a layer. -/ +theorem assign_none_of_groups_nil {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) (d : MainMasks n) (seen : Fin n → Option ℤ) + (hg : MainAlgorithm.groups M d seen = []) (e : Fin n) (w : Option ℤ) : + MainAlgorithm.assign M hE d seen e w = none := by + classical + cases w with + | none => rfl + | some i => + have hn : ¬ MainAlgorithm.eligible M hE d seen e i := by + intro he + simpa [hg] using he.2.2.1 + simp [MainAlgorithm.assign, hn] + +/-- Zero weights do not enter a logarithm and are assigned no layer. -/ +theorem assign_zero {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (d : MainMasks n) (seen : Fin n → Option ℤ) (e : Fin n) : + MainAlgorithm.assign M hE d seen e (roundedLevel weightBase 0) = none := by + simp [roundedLevel, MainAlgorithm.assign] + +/-- A loop can never pass the actual candidate test, regardless of priorities. -/ +theorem not_candidate_of_loop {n : ℕ} (M : Matroid (Fin n)) (d : MainMasks n) + (seen : Fin n → Option ℤ) (e : Fin n) (w : Option ℤ) + (he : e ∈ M.closure ∅) : ¬ MainAlgorithm.candidate M d seen e w := by + intro hc + exact hc.2.2 (M.closure_subset_closure (Set.empty_subset _) he) + +/-- The complete required `lem:feasibility` contract, for the concrete source rule. -/ +theorem source_main_feasibility {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) : MainRuleFeasibility M (MainAlgorithm.hidden M hE) := + MainAlgorithm.source_feasibility_contract M hE + +end FeasibilityContract +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/FeasibilitySpec.lean b/lean/OAI/Probability/MatroidSecretary/Selection/FeasibilitySpec.lean new file mode 100644 index 0000000000000000000000000000000000000000..af1ce4597fc2af43c07015469cd9fa1d3585ac3f --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/FeasibilitySpec.lean @@ -0,0 +1,31 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +namespace MatroidProphet +open Set Finset MeasureTheory + +/-- Core and hidden prefix feasibility, measurability after masking the initial +observations, complete accepted-set nonanticipation, irrevocability, and literal +rejection of sacrificed labels. The mask depends only on the initial seed by +the type of `HiddenRule`; no weight-dependent mask is allowed. -/ +def MainRuleFeasibility {n bits : ℕ} (M : Matroid (Fin n)) + (A : HiddenRule n bits) : Prop := + Feasible M A.core ∧ + (∀ k, Measurable (fun x : Seed bits × (Weights n × History n k) => + A.core.decide k x.1 (observed A x.1 x.2.1) x.2.2)) ∧ + (∀ (w : Weights n), (∀ e, 0 ≤ w e) → + ∀ (r : Seed bits) (π : ArrivalOrder n) (t : ℕ), + M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n))) ∧ + (∀ (r : Seed bits) (w w' : Weights n) (π π' : ArrivalOrder n) (t : ℕ), + (∀ e ∈ A.mask r, w e = w' e) → + (∀ j : Fin n, j.val < t → (π j, w (π j)) = (π' j, w' (π' j))) → + hiddenAcceptedThrough A r w π t = hiddenAcceptedThrough A r w' π' t) ∧ + (∀ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n), + Monotone (hiddenAcceptedThrough A r w π)) ∧ + (∀ (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) (t : ℕ), + Disjoint (hiddenAcceptedThrough A r w π t) (A.mask r)) + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/GreedyExecution.lean b/lean/OAI/Probability/MatroidSecretary/Selection/GreedyExecution.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d558b9bc33d23c22707a38ef885a6cfa68e9497 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/GreedyExecution.lean @@ -0,0 +1,90 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +/-! Exact agreement between the source's previous-accepted-label test and the +concrete implementation's previous-eligible-label test. No arrival-order +assumption beyond the explicit arrival times is used in span preservation. -/ + +namespace MatroidProphet +open Set Finset + +variable {α : Type*} [DecidableEq α] + +/-- Rejected earlier eligible labels do not change the span of a layer prefix. -/ +theorem layerGreedy_closure_prior (M : Matroid α) (E : Finset α) + (base : ℤ → Set α) (layer : α → ℤ) (time : α → ℕ) + (hE : M.E = Set.univ) (b : ℤ) (k : ℕ) : + M.closure (base b ∪ layerPrior E layer time b k) = + M.closure (base b ∪ + layerPrior (layerGreedy M E base layer time) layer time b k) := by + apply Set.Subset.antisymm + · apply M.closure_subset_closure_of_subset_closure + rintro e (he | ⟨he, hb, ht⟩) + · exact M.mem_closure_of_mem' (Or.inl he) (by simp [hE]) + · have hs := layerGreedy_spans_prefix M E base layer time hE e he + apply M.closure_subset_closure ?_ hs + rintro f (hf | ⟨hf, hfb, hft⟩) + · exact Or.inl (by simpa [hb] using hf) + · exact Or.inr ⟨hf, hfb.trans hb, hft.trans_lt ht⟩ + · apply M.closure_subset_closure + rintro e (he | ⟨he, hb, ht⟩) + · exact Or.inl he + · exact Or.inr ⟨layerGreedy_subset M E base layer time he, hb, ht⟩ + +/-- The online decision can be implemented using only earlier accepted labels +of the same layer, exactly as in step 3 of the manuscript algorithm. -/ +theorem layerGreedy_mem_iff_previous_accepted (M : Matroid α) (E : Finset α) + (base : ℤ → Set α) (layer : α → ℤ) (time : α → ℕ) + (hE : M.E = Set.univ) (e : α) : + e ∈ layerGreedy M E base layer time ↔ + e ∈ E ∧ e ∉ M.closure (base (layer e) ∪ + layerPrior (layerGreedy M E base layer time) layer time (layer e) (time e)) := by + classical + conv_lhs => unfold layerGreedy + rw [Finset.mem_filter] + rw [layerGreedy_closure_prior M E base layer time hE] + +omit [DecidableEq α] in +/-- On a finite ground set the source's rank-one test is precisely nonmembership +in the closure, including rank-zero and loop cases. -/ +theorem conditionalRank_singleton_eq_one_iff [Fintype α] (M : Matroid α) + (hE : M.E = Set.univ) (P : Set α) (e : α) : + conditionalRank M {e} P = 1 ↔ e ∉ M.closure P := by + by_cases he : e ∈ M.closure P + · rw [Pivots.conditionalRank_singleton_of_mem_closure M P he] + simp [he] + · rw [Pivots.conditionalRank_singleton_of_notMem_closure M P (by simp [hE]) he] + simp [he] + +/-- Exact rank form of the source's accept/reject condition. -/ +theorem layerGreedy_mem_iff_rank_previous_accepted [Fintype α] + (M : Matroid α) (E : Finset α) (base : ℤ → Set α) + (layer : α → ℤ) (time : α → ℕ) (hE : M.E = Set.univ) (e : α) : + e ∈ layerGreedy M E base layer time ↔ + e ∈ E ∧ conditionalRank M {e} (base (layer e) ∪ + layerPrior (layerGreedy M E base layer time) layer time (layer e) (time e)) = 1 := by + rw [layerGreedy_mem_iff_previous_accepted M E base layer time hE, + conditionalRank_singleton_eq_one_iff M hE] + +/-- The concrete history-based online decision agrees with the rank test on +previously accepted labels in the current layer. -/ +theorem layerKeyDecision_eq_rank_previous_accepted {n : ℕ} {K : Type*} + (M : Matroid (Fin n)) (hE : M.E = Set.univ) (base : ℤ → Set (Fin n)) + (assign : Fin n → K → Option ℤ) (v : Fin n → K) + (π : ArrivalOrder n) (k : Fin n) : + layerKeyDecision M base assign k (keyHistory v π k) = true ↔ + π k ∈ assignedEligible assign v ∧ + conditionalRank M {π k} (base (assignedLayer assign v (π k)) ∪ + layerPrior + (layerGreedy M (assignedEligible assign v) base (assignedLayer assign v) + (fun e => (π.symm e).val)) + (assignedLayer assign v) (fun e => (π.symm e).val) + (assignedLayer assign v (π k)) k.val) = 1 := by + rw [layerKeyDecision_eq_greedy, + layerGreedy_mem_iff_rank_previous_accepted M _ _ _ _ hE] + simp only [Equiv.symm_apply_apply] + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/LayerImplementation.lean b/lean/OAI/Probability/MatroidSecretary/Selection/LayerImplementation.lean new file mode 100644 index 0000000000000000000000000000000000000000..49e32d776060b6c6bed5e75c59ee29507cadeff1 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/LayerImplementation.lean @@ -0,0 +1,71 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +/-! +# The layer rule is the source's accepted-prefix greedy rule + +The implementation tests the span of all previous eligible labels. The source +algorithm tests the span of the previous accepted labels. Prefix span preservation +makes these tests exactly equal, not merely comparable in final reward. +-/ + +namespace MatroidProphet +open Set Finset + +lemma layerGreedy_closure_prefix {α : Type*} [DecidableEq α] + (M : Matroid α) (E : Finset α) (base : ℤ → Set α) + (layer : α → ℤ) (time : α → ℕ) (hE : M.E = Set.univ) (b : ℤ) (k : ℕ) : + M.closure (base b ∪ layerPrior E layer time b k) = + M.closure (base b ∪ + {e | e ∈ layerGreedy M E base layer time ∧ layer e = b ∧ time e < k}) := by + apply Set.Subset.antisymm + · apply M.closure_subset_closure_of_subset_closure + rintro e (he | ⟨he, hb, ht⟩) + · exact M.mem_closure_of_mem' (Or.inl he) (by simp [hE]) + · have hs := layerGreedy_spans_prefix M E base layer time hE e he + apply M.closure_subset_closure _ hs + rintro f (hf | ⟨hf, hfb, hft⟩) + · exact Or.inl (by simpa only [hb] using hf) + · exact Or.inr ⟨hf, hfb.trans hb, hft.trans_lt ht⟩ + · apply M.closure_subset_closure + rintro e (he | ⟨he, hb, ht⟩) + · exact Or.inl he + · exact Or.inr ⟨layerGreedy_subset M E base layer time he, hb, ht⟩ + +/-- The actual layer acceptance test may use only its earlier accepted labels. -/ +theorem layerGreedy_mem_iff_accepted_prefix {α : Type*} [DecidableEq α] + (M : Matroid α) (E : Finset α) (base : ℤ → Set α) + (layer : α → ℤ) (time : α → ℕ) (hE : M.E = Set.univ) (e : α) : + e ∈ layerGreedy M E base layer time ↔ + e ∈ E ∧ e ∉ M.closure (base (layer e) ∪ + {f | f ∈ layerGreedy M E base layer time ∧ + layer f = layer e ∧ time f < time e}) := by + classical + rw [show e ∈ layerGreedy M E base layer time ↔ e ∈ E ∧ + e ∉ M.closure (base (layer e) ∪ layerPrior E layer time (layer e) (time e)) from + Finset.mem_filter] + rw [layerGreedy_closure_prefix M E base layer time hE] + +/-- Exact conditional-rank form of the source test at an arrival. -/ +theorem layerGreedy_mem_iff_rank_one {α : Type*} [Fintype α] [DecidableEq α] + (M : Matroid α) (E : Finset α) (base : ℤ → Set α) + (layer : α → ℤ) (time : α → ℕ) (hE : M.E = Set.univ) (e : α) : + e ∈ layerGreedy M E base layer time ↔ + e ∈ E ∧ conditionalRank M {e} (base (layer e) ∪ + {f | f ∈ layerGreedy M E base layer time ∧ + layer f = layer e ∧ time f < time e}) = 1 := by + rw [layerGreedy_mem_iff_accepted_prefix M E base layer time hE] + constructor + · rintro ⟨he, hne⟩ + exact ⟨he, Pivots.conditionalRank_singleton_of_notMem_closure M _ + (by simp [hE]) hne⟩ + · rintro ⟨he, hr⟩ + refine ⟨he, ?_⟩ + intro hmem + have hz := Pivots.conditionalRank_singleton_of_mem_closure M _ hmem + omega + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Selection/SafeSpecification.lean b/lean/OAI/Probability/MatroidSecretary/Selection/SafeSpecification.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a8475f4d8c1d1b64c959fe5e61a9fc77b984693 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Selection/SafeSpecification.lean @@ -0,0 +1,26 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +namespace MatroidProphet + +open MainAlgorithm + +/-- The source safety guarantee, including the literal constants, all listed +groups, global independent comparison set, and the harmless unlisted zero case. -/ +def SafeSampleClaim : Prop := + ∀ (n : ℕ) (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ) + (Y : Set (Fin n)), M.Indep Y → + exitThreshold / 4 * + ((d.D : Set (Fin n)) ∩ (Y ∩ (trueGroup M d s i : Set (Fin n)))).ncard - + (d.D ∩ trueGroup M d s i).card / densityThreshold ≤ + bitsExpectation (fun _ => thinningRate) Finset.univ (fun C => + bitsExpectation (fun _ => thinningRate) Finset.univ (fun T => + fairParityExpectation (fun p => + (listedSafeStatistic M hE (2 ^ 100) (withMasks d d.D C T) s i Y + (boolParity p) : ℝ)))) + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/AdversarialMinimum.lean b/lean/OAI/Probability/MatroidSecretary/Transport/AdversarialMinimum.lean new file mode 100644 index 0000000000000000000000000000000000000000..a7f8e2f9f77d86e67e7a92fc040dec0b22cb3890 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/AdversarialMinimum.lean @@ -0,0 +1,94 @@ +import OAI.Probability.MatroidProphet.Main +import Mathlib.MeasureTheory.Integral.Bochner.Basic + +namespace OAI + +open MeasureTheory + +namespace MatroidProphet + +/-- For a fixed vector, arbitrary measurable seed-dependent orders give an +integrable reward under every finite measure. No feasibility or sign assumption +is needed, since the seed and order spaces are finite. -/ +lemma integrable_hiddenReward_randomOrder {n bits : ℕ} (A : HiddenRule n bits) + (w : Weights n) {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsFiniteMeasure μ] + (R : Ω → Seed bits) (π : Ω → ArrivalOrder n) + (hR : Measurable R) (hπ : Measurable π) : + Integrable (fun ω => hiddenReward A (R ω) w (π ω)) μ := by + let f : Seed bits × ArrivalOrder n → ℝ := fun x => hiddenReward A x.1 w x.2 + have hf : Measurable f := measurable_of_finite f + have hpair : Measurable (fun ω => (R ω, π ω)) := hR.prodMk hπ + exact (integrable_map_measure hf.aestronglyMeasurable hpair.aemeasurable).1 + (Integrable.of_finite (f := f)) + +/-- The seedwise minimum is integrable after any measurable finite-seed map. -/ +lemma integrable_hiddenWorstReward_comp {n bits : ℕ} (A : HiddenRule n bits) + (w : Weights n) {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsFiniteMeasure μ] + (R : Ω → Seed bits) (hR : Measurable R) : + Integrable (fun ω => hiddenWorstReward A w (R ω)) μ := by + have hf : Measurable (hiddenWorstReward A w) := measurable_of_finite _ + exact (integrable_map_measure hf.aestronglyMeasurable hR.aemeasurable).1 + (Integrable.of_finite (f := hiddenWorstReward A w)) + +/-- A reconstructed seed's correct marginal transports the expected minimum to +any measurable full-information order. The order need not be independent of the +seed, and the ambient space may carry arbitrarily much additional information. -/ +theorem hiddenWorstReward_integral_le_randomOrder {n bits : ℕ} + (A : HiddenRule n bits) (w : Weights n) + {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ] + (ν : Measure (Seed bits)) (R : Ω → Seed bits) (π : Ω → ArrivalOrder n) + (hR : Measurable R) (hπ : Measurable π) (hRlaw : μ.map R = ν) : + (∫ r, hiddenWorstReward A w r ∂ν) ≤ + ∫ ω, hiddenReward A (R ω) w (π ω) ∂μ := by + have hf : Measurable (hiddenWorstReward A w) := measurable_of_finite _ + rw [← hRlaw, integral_map_of_stronglyMeasurable hR hf.stronglyMeasurable] + apply integral_mono + (integrable_hiddenWorstReward_comp A w μ R hR) + (integrable_hiddenReward_randomOrder A w μ R π hR hπ) + intro ω + exact hiddenWorstReward_le A w (R ω) (π ω) + +/-- A pointwise accepted-reward identity may be replaced by an almost-everywhere +identity. This is useful when a reconstruction kernel has zero-mass seed outcomes. -/ +theorem hiddenWorstReward_integral_le_replayed {n bits : ℕ} + (A : HiddenRule n bits) (w : Weights n) + {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ] + (ν : Measure (Seed bits)) (R : Ω → Seed bits) (π : Ω → ArrivalOrder n) + (hR : Measurable R) (hπ : Measurable π) (hRlaw : μ.map R = ν) + (payoff : Ω → ℝ) + (hreplay : payoff =ᵐ[μ] fun ω => hiddenReward A (R ω) w (π ω)) : + Integrable payoff μ ∧ (∫ r, hiddenWorstReward A w r ∂ν) ≤ ∫ ω, payoff ω ∂μ := by + refine ⟨(integrable_hiddenReward_randomOrder A w μ R π hR hπ).congr hreplay.symm, ?_⟩ + rw [integral_congr_ae hreplay] + exact hiddenWorstReward_integral_le_randomOrder A w μ ν R π hR hπ hRlaw + +/-- There is a measurable adversary attaining the minimum separately at every +seed. Thus the minimum used above is genuinely inside expectation, not the +minimum of fixed-order expected rewards. -/ +lemma exists_measurable_worstOrder {n bits : ℕ} (A : HiddenRule n bits) + (w : Weights n) : + ∃ π : Seed bits → ArrivalOrder n, Measurable π ∧ + ∀ r, hiddenReward A r w (π r) = hiddenWorstReward A w r := by + classical + have hex (r : Seed bits) : + ∃ π : ArrivalOrder n, hiddenReward A r w π = hiddenWorstReward A w r := by + obtain ⟨π, _, hπ⟩ := Finset.exists_mem_eq_inf' + (s := (Finset.univ : Finset (ArrivalOrder n))) Finset.univ_nonempty + (hiddenReward A r w) + exact ⟨π, hπ.symm⟩ + choose π hπ using hex + exact ⟨π, measurable_of_finite π, hπ⟩ + +/-- The lower bound is sharp among measurable full-seed order policies. -/ +lemma exists_order_integral_eq_hiddenWorstReward {n bits : ℕ} + (A : HiddenRule n bits) (w : Weights n) (ν : Measure (Seed bits)) : + ∃ π : Seed bits → ArrivalOrder n, Measurable π ∧ + (∫ r, hiddenReward A r w (π r) ∂ν) = ∫ r, hiddenWorstReward A w r ∂ν := by + obtain ⟨π, hπ, heq⟩ := exists_measurable_worstOrder A w + exact ⟨π, hπ, integral_congr_ae (ae_of_all _ heq)⟩ + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulation.lean b/lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulation.lean new file mode 100644 index 0000000000000000000000000000000000000000..b527c421e45f2991a62295cdf44f00f4c2be6abf --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulation.lean @@ -0,0 +1,391 @@ +import OAI.Probability.MatroidSecretary.Transport.GeneralSimulationModel +import OAI.Probability.MatroidProphet.Main +import Mathlib.MeasureTheory.Integral.Prod + +namespace OAI + +/-! One-sample simulation for an arbitrary measurable complete seed. -/ + +namespace MatroidProphet.General + +open MeasureTheory ProbabilityTheory + +variable {n : ℕ} {R : Type*} [MeasurableSpace R] + +lemma measurable_mask_membership : + MeasurableSet {x : Finset (Fin n) × Fin n | x.2 ∈ x.1} := + (Set.toFinite _).measurableSet + +lemma measurable_observed (A : HiddenRule n R) : + Measurable (fun x : R × Weights n => observed A x.1 x.2) := by + classical + apply Measurable.of_eval + intro e + have hm : MeasurableSet {x : R × Weights n | e ∈ A.mask x.1} := + (measurableSet_mem_finset e).preimage (A.measurable_mask.comp measurable_fst) + exact Measurable.ite hm ((measurable_pi_apply e).comp measurable_snd) measurable_const + +lemma measurable_simulationHistory (A : HiddenRule n R) (k : Fin n) : + Measurable (fun x : R × (Weights n × History n k) => + simulationHistory A x.1 x.2.1 x.2.2) := by + classical + apply Measurable.of_eval + intro j + have hh : Measurable (fun x : R × (Weights n × History n k) => x.2.2 j) := + (measurable_pi_apply j).comp (measurable_snd.comp measurable_snd) + have hm : MeasurableSet {x : R × (Weights n × History n k) | + (x.2.2 j).1 ∈ A.mask x.1} := + measurable_mask_membership.preimage + ((A.measurable_mask.comp measurable_fst).prodMk (measurable_fst.comp hh)) + exact (measurable_fst.comp hh).prodMk (Measurable.ite hm + (MatroidProphet.measurable_weight_eval.comp + ((measurable_fst.comp measurable_snd).prodMk (measurable_fst.comp hh))) + (measurable_snd.comp hh)) + +lemma measurable_simulationDecision (A : HiddenRule n R) (k : Fin n) : + Measurable (fun x : R × (Weights n × History n k) => + simulationDecision A k x.1 x.2.1 x.2.2) := by + classical + have hc : Measurable (fun x : R × (Weights n × History n k) => + (x.2.2 ⟨k.val, Nat.lt_succ_self _⟩).1) := + measurable_fst.comp ((measurable_pi_apply + (⟨k.val, Nat.lt_succ_self _⟩ : Fin (k.val + 1))).comp + (measurable_snd.comp measurable_snd)) + have hm : MeasurableSet {x : R × (Weights n × History n k) | + (x.2.2 ⟨k.val, Nat.lt_succ_self _⟩).1 ∈ A.mask x.1} := + measurable_mask_membership.preimage + ((A.measurable_mask.comp measurable_fst).prodMk hc) + exact Measurable.ite hm measurable_const + ((A.core.measurable_decide k).comp (measurable_fst.prodMk + (((measurable_observed A).comp + (measurable_fst.prodMk (measurable_fst.comp measurable_snd))).prodMk + (measurable_simulationHistory A k)))) + +noncomputable def sampleSimulation (A : HiddenRule n R) : OnlineRule n R where + decide := simulationDecision A + measurable_decide := measurable_simulationDecision A + +lemma observed_glue (A : HiddenRule n R) (r : R) (s v : Weights n) : + observed A r (glue (A.mask r) s v) = observed A r s := by + classical + funext e + by_cases he : e ∈ A.mask r <;> simp [observed, glue, he] + +lemma simulationHistory_eq (A : HiddenRule n R) (r : R) + (s v : Weights n) (π : ArrivalOrder n) (k : Fin n) : + simulationHistory A r s (history v π k) = history (glue (A.mask r) s v) π k := rfl + +theorem sampleSimulation_acceptedThrough (A : HiddenRule n R) (r : R) + (s v : Weights n) (π : ArrivalOrder n) (t : ℕ) : + acceptedThrough (sampleSimulation A) r s v π t = + hiddenAcceptedThrough A r (glue (A.mask r) s v) π t := by + classical + ext e + by_cases he : e ∈ A.mask r <;> + simp [acceptedThrough, hiddenAcceptedThrough, decisionAt, sampleSimulation, + simulationDecision, history, prefixIndex, simulationHistory_eq, observed_glue, he] + +theorem sampleSimulation_reward (A : HiddenRule n R) (r : R) + (s v : Weights n) (π : ArrivalOrder n) : + reward (sampleSimulation A) r s v π = hiddenReward A r (glue (A.mask r) s v) π := by + classical + unfold reward hiddenReward + rw [sampleSimulation_acceptedThrough] + apply Finset.sum_congr rfl + intro e he + have he' : e ∉ A.mask r := (Finset.mem_sdiff.mp he).2 + simp [glue, he'] + +theorem sampleSimulation_feasible (M : Matroid (Fin n)) (A : HiddenRule n R) + (hA : HiddenFeasible M A) : Feasible M (sampleSimulation A) := by + intro r s v π t hs hv + rw [sampleSimulation_acceptedThrough] + apply hA + intro e + classical + by_cases he : e ∈ A.mask r + · simpa [glue, he] using hs e + · simpa [glue, he] using hv e + +lemma reward_nonneg (A : OnlineRule n R) (r : R) (s v : Weights n) + (π : ArrivalOrder n) (hv : ∀ e, 0 ≤ v e) : 0 ≤ reward A r s v π := + Finset.sum_nonneg fun e _ => hv e + +lemma reward_le_optimum (M : Matroid (Fin n)) (A : OnlineRule n R) + (hA : Feasible M A) (r : R) (s v : Weights n) (π : ArrivalOrder n) + (hs : ∀ e, 0 ≤ s e) (hv : ∀ e, 0 ≤ v e) : + reward A r s v π ≤ optimum M v := + sum_le_optimum M v _ (hA r s v π n hs hv) + +lemma hiddenWorstReward_le (A : HiddenRule n R) (w : Weights n) + (r : R) (π : ArrivalOrder n) : + hiddenWorstReward A w r ≤ hiddenReward A r w π := by + classical + exact Finset.inf'_le (hiddenReward A r w) (Finset.mem_univ π) + +lemma hiddenWorstReward_nonneg (A : HiddenRule n R) (w : Weights n) + (hw : ∀ e, 0 ≤ w e) (r : R) : 0 ≤ hiddenWorstReward A w r := by + classical + apply Finset.le_inf' + intro π _ + exact Finset.sum_nonneg fun e _ => hw e + +lemma hiddenWorstReward_le_optimum (M : Matroid (Fin n)) (A : HiddenRule n R) + (hA : HiddenFeasible M A) (w : Weights n) (hw : ∀ e, 0 ≤ w e) (r : R) : + hiddenWorstReward A w r ≤ optimum M w := by + apply (hiddenWorstReward_le A w r (Equiv.refl _)).trans + exact sum_le_optimum M w _ (hA w hw r (Equiv.refl _) n) + +lemma measurable_decisionAt {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R) + (π : ArrivalOrder n) (k : Fin n) : + Measurable (fun x : R × (Weights n × Weights n) => + decisionAt A x.1 x.2.1 x.2.2 π k) := + (A.measurable_decide k).comp + (measurable_fst.prodMk ((measurable_fst.comp measurable_snd).prodMk + ((measurable_history π k).comp (measurable_snd.comp measurable_snd)))) + +lemma reward_eq_sum {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R) (r : R) + (s v : Weights n) (π : ArrivalOrder n) : + reward A r s v π = + ∑ e : Fin n, if decisionAt A r s v π (π.symm e) = true then v e else 0 := by + classical + unfold reward acceptedThrough + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro e _ + simp only [(π.symm e).isLt, true_and] + +lemma measurable_reward_fixed_order {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R) + (π : ArrivalOrder n) : + Measurable (fun x : R × (Weights n × Weights n) => + reward A x.1 x.2.1 x.2.2 π) := by + classical + simp_rw [reward_eq_sum] + apply Finset.measurable_sum + intro e _ + have hd := measurable_decisionAt A π (π.symm e) + have ht : MeasurableSet {x : R × (Weights n × Weights n) | + decisionAt A x.1 x.2.1 x.2.2 π (π.symm e) = true} := + hd (measurableSet_singleton true) + exact Measurable.ite ht + ((measurable_pi_apply e).comp (measurable_snd.comp measurable_snd)) measurable_const + +/-- The realized reward remains measurable for arbitrary measurable adversarial permutations. -/ +theorem measurable_reward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : OnlineRule n R) : + Measurable (fun x : ArrivalOrder n × (R × (Weights n × Weights n)) => + reward A x.2.1 x.2.2.1 x.2.2.2 x.1) := + measurable_from_prod_countable_right (measurable_reward_fixed_order A) + +@[simp] lemma glue_self (mask : Finset (Fin n)) (w : Weights n) : + glue mask w w = w := by + classical + funext e + simp [glue] + +lemma measurable_hiddenReward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : HiddenRule n R) (π : ArrivalOrder n) : + Measurable (fun x : R × Weights n => hiddenReward A x.1 x.2 π) := by + have hm := (measurable_reward_fixed_order (sampleSimulation A) π).comp + (measurable_fst.prodMk (measurable_snd.prodMk measurable_snd)) + simpa only [Function.comp_def, sampleSimulation_reward, glue_self] using hm + +lemma measurable_hiddenWorstReward {n : ℕ} {R : Type*} [MeasurableSpace R] (A : HiddenRule n R) : + Measurable (fun x : R × Weights n => hiddenWorstReward A x.2 x.1) := by + classical + have hm : Measurable ((Finset.univ : Finset (ArrivalOrder n)).inf' + Finset.univ_nonempty (fun π (x : R × Weights n) => hiddenReward A x.1 x.2 π)) := + Finset.inf'_induction Finset.univ_nonempty _ + (fun _ hf _ hg => hf.inf hg) (fun π _ => measurable_hiddenReward A π) + convert hm using 1 + ext x + simp only [hiddenWorstReward, Finset.inf'_apply] + +lemma measurable_glue (mask : Finset (Fin n)) : + Measurable (fun x : Weights n × Weights n => glue mask x.1 x.2) := + MatroidProphet.measurable_glue mask + +lemma measurable_glue_seed (mask : R → Finset (Fin n)) (hmask : Measurable mask) : + Measurable (fun x : R × (Weights n × Weights n) => glue (mask x.1) x.2.1 x.2.2) := by + have h : Measurable (fun x : Finset (Fin n) × (Weights n × Weights n) => + glue x.1 x.2.1 x.2.2) := + measurable_from_prod_countable_right measurable_glue + exact h.comp ((hmask.comp measurable_fst).prodMk measurable_snd) + +theorem glue_fixed_law {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (S V : Ω → Weights n) (hS : Measurable S) (hV : Measurable V) + (hi : iIndepFun (pairedCoordinates S V) μ) + (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e)) + (mask : Finset (Fin n)) : + μ.map (fun ω => glue mask (S ω) (V ω)) = μ.map V := + MatroidProphet.glue_fixed_law μ S V hS hV hi hlaw mask + +/-- Joint gluing law with an arbitrary measurable complete seed; in particular, +the observation mask may depend on all of that seed. -/ +theorem glue_seed_joint_law {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] + (ν : Measure R) [IsProbabilityMeasure ν] + (S V : Ω → Weights n) (seed : Ω → R) + (hS : Measurable S) (hV : Measurable V) (hseedM : Measurable seed) + (hi : iIndepFun (pairedCoordinates S V) μ) + (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e)) + (hseed : IndepFun (fun ω => (S ω, V ω)) seed μ) + (hseedLaw : μ.map seed = ν) (mask : R → Finset (Fin n)) (hmask : Measurable mask) : + MeasurePreserving (fun ω => (seed ω, glue (mask (seed ω)) (S ω) (V ω))) + μ (ν.prod (μ.map V)) := by + have hfiber (r : R) : + (μ.map (fun ω => (S ω, V ω))).map (fun d => glue (mask r) d.1 d.2) = μ.map V := by + rw [Measure.map_map (measurable_glue (mask r)) (hS.prodMk hV)] + exact glue_fixed_law μ S V hS hV hi hlaw (mask r) + have hstart : MeasurePreserving (fun ω => (seed ω, (S ω, V ω))) μ + (ν.prod (μ.map (fun ω => (S ω, V ω)))) := by + refine ⟨hseedM.prodMk (hS.prodMk hV), ?_⟩ + rw [hseed.symm.map_prod_eq_prod_map_map hseedM.aemeasurable + (hS.prodMk hV).aemeasurable, hseedLaw] + have hend := (MeasurePreserving.id ν).skew_product + (g := fun (r : R) (d : Weights n × Weights n) => glue (mask r) d.1 d.2) + (measurable_glue_seed mask hmask) (ae_of_all _ hfiber) + exact hend.comp hstart + +/-- Nonnegativity of a finite vector is a Borel condition. -/ +lemma measurableSet_nonnegative (n : ℕ) : + MeasurableSet {w : Weights n | ∀ e, 0 ≤ w e} := by + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun e => measurableSet_le measurable_const (measurable_pi_apply e) + +lemma integrable_hidden_product {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n)) (A : HiddenRule n Ξ) + (ν : Measure (Ξ)) [IsProbabilityMeasure ν] (ρ : Measure (Weights n)) [SFinite ρ] + (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) → + ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ), + M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n))) + (hNN : ∀ᵐ w ∂ρ, ∀ e, 0 ≤ w e) (hopt : Integrable (optimum M) ρ) : + Integrable (fun x : Ξ × Weights n => hiddenWorstReward A x.2 x.1) + (ν.prod ρ) := by + apply (hopt.comp_snd ν).mono' (measurable_hiddenWorstReward A).aestronglyMeasurable + filter_upwards [(Measure.quasiMeasurePreserving_snd (μ := ν) (ν := ρ)).ae hNN] with x hx + rw [Real.norm_eq_abs, abs_of_nonneg (hiddenWorstReward_nonneg A x.2 hx x.1)] + exact hiddenWorstReward_le_optimum M A hA x.2 hx x.1 + +lemma hidden_product_integral_bound {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n)) + (A : HiddenRule n Ξ) (ν : Measure (Ξ)) [IsProbabilityMeasure ν] + (ρ : Measure (Weights n)) [IsProbabilityMeasure ρ] (c : ℝ) + (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) → + ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ), + M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n))) + (hNN : ∀ᵐ w ∂ρ, ∀ e, 0 ≤ w e) (hopt : Integrable (optimum M) ρ) + (hbound : ∀ (w : Weights n), (∀ e, 0 ≤ w e) → + c * optimum M w ≤ ∫ r, hiddenWorstReward A w r ∂ν) : + c * (∫ w, optimum M w ∂ρ) ≤ + ∫ x : Ξ × Weights n, hiddenWorstReward A x.2 x.1 ∂ν.prod ρ := by + have hip := integrable_hidden_product M A ν ρ hA hNN hopt + rw [← integral_const_mul] + calc + _ ≤ ∫ w, ∫ r, hiddenWorstReward A w r ∂ν ∂ρ := by + apply integral_mono_ae (hopt.const_mul c) hip.integral_prod_right + filter_upwards [hNN] with w hw + exact hbound w hw + _ = _ := (integral_prod_symm _ hip).symm + +lemma integrable_feasible_reward {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n)) + (A : OnlineRule n Ξ) (hA : Feasible M A) + {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (S V : Ω → Weights n) (R : Ω → Ξ) (π : Ω → ArrivalOrder n) + (hS : Measurable S) (hV : Measurable V) (hR : Measurable R) (hπ : Measurable π) + (hSN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) + (hopt : Integrable (fun ω => optimum M (V ω)) μ) : + Integrable (fun ω => reward A (R ω) (S ω) (V ω) (π ω)) μ := by + have hrm := (measurable_reward A).comp (hπ.prodMk (hR.prodMk (hS.prodMk hV))) + apply hopt.mono' hrm.aestronglyMeasurable + filter_upwards [hSN, hVN] with ω hs hv + change ‖reward A (R ω) (S ω) (V ω) (π ω)‖ ≤ optimum M (V ω) + rw [Real.norm_eq_abs, abs_of_nonneg (reward_nonneg A (R ω) (S ω) (V ω) (π ω) hv)] + exact reward_le_optimum M A hA (R ω) (S ω) (V ω) (π ω) hs hv + +/-- The full one-sample integration step preserves the expected minimum over all orders. -/ +theorem oneSample_of_hidden {n : ℕ} {Ξ : Type*} [MeasurableSpace Ξ] (M : Matroid (Fin n)) (A : HiddenRule n Ξ) + (ν : Measure (Ξ)) [IsProbabilityMeasure ν] (c : ℝ) + (hA : ∀ (w : Weights n), (∀ e, 0 ≤ w e) → + ∀ (r : Ξ) (π : ArrivalOrder n) (t : ℕ), + M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n))) + (hbound : ∀ (w : Weights n), (∀ e, 0 ≤ w e) → + c * optimum M w ≤ ∫ r, hiddenWorstReward A w r ∂ν) + {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] + (S V : Ω → Weights n) (R : Ω → Ξ) + (hS : Measurable S) (hV : Measurable V) (hR : Measurable R) + (hSN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) + (hi : iIndepFun (pairedCoordinates S V) μ) + (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e)) + (hseed : IndepFun (fun ω => (S ω, V ω)) R μ) + (hRlaw : μ.map R = ν) + (hopt : Integrable (fun ω => optimum M (V ω)) μ) + (π : Ω → ArrivalOrder n) (hπ : Measurable π) : + Integrable (fun ω => reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω)) μ ∧ + c * (∫ ω, optimum M (V ω) ∂μ) ≤ + ∫ ω, reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω) ∂μ := by + have hj := glue_seed_joint_law μ ν S V R hS hV hR hi hlaw hseed hRlaw A.mask A.measurable_mask + have hoptLaw : Integrable (optimum M) (μ.map V) := + (integrable_map_measure (measurable_optimum M).aestronglyMeasurable hV.aemeasurable).2 hopt + have hNNLaw : ∀ᵐ w ∂μ.map V, ∀ e, 0 ≤ w e := + (ae_map_iff hV.aemeasurable (measurableSet_nonnegative n)).2 hVN + have hip := integrable_hidden_product M A ν (μ.map V) hA hNNLaw hoptLaw + have him := hj.integrable_comp_of_integrable hip + have hri := integrable_feasible_reward M (sampleSimulation A) + (sampleSimulation_feasible M A hA) μ S V R π hS hV hR hπ hSN hVN hopt + have hb := hidden_product_integral_bound M A ν (μ.map V) c hA hNNLaw hoptLaw hbound + have hoptEq := integral_map_of_stronglyMeasurable (μ := μ) hV + (measurable_optimum M).stronglyMeasurable + have hminEq := integral_map_of_stronglyMeasurable (μ := μ) hj.measurable + (measurable_hiddenWorstReward A).stronglyMeasurable + rw [hj.map_eq] at hminEq + rw [hoptEq, hminEq] at hb + refine ⟨hri, hb.trans (integral_mono_ae him hri (ae_of_all _ ?_))⟩ + intro ω + change hiddenWorstReward A (glue (A.mask (R ω)) (S ω) (V ω)) (R ω) ≤ + reward (sampleSimulation A) (R ω) (S ω) (V ω) (π ω) + rw [sampleSimulation_reward] + exact hiddenWorstReward_le A _ (R ω) (π ω) + +/-- The manuscript's simulation lemma without any finite-seed restriction. -/ +theorem simulation_contract.{u, v} : SimulationContract.{u, v} := by + intro n R mR M A ν hν c hA hbound + let := hν + refine ⟨sampleSimulation A, ?_, sampleSimulation_feasible M A hA, + sampleSimulation_acceptedThrough A, sampleSimulation_reward A, ?_⟩ + · intro k r s h + rfl + · intro Ω mΩ μ hμ S V seed hS hV hseedM hSN hVN hi hlaw hseed hseedLaw hopt π hπ + exact ⟨glue_seed_joint_law μ ν S V seed hS hV hseedM hi hlaw hseed hseedLaw + A.mask A.measurable_mask, + oneSample_of_hidden M A ν c hA hbound μ S V seed hS hV hseedM hSN hVN + hi hlaw hseed hseedLaw hopt π hπ⟩ + +/-- The concrete finite-seed information model is a special case, with exactly +the same decisions rather than an unrelated replacement rule. -/ +def OnlineRule.ofFinite {bits : ℕ} (A : MatroidProphet.OnlineRule n bits) : + OnlineRule n (Seed bits) where + decide := A.decide + measurable_decide := A.measurable_decide + +def HiddenRule.ofFinite {bits : ℕ} (A : MatroidProphet.HiddenRule n bits) : + HiddenRule n (Seed bits) where + mask := A.mask + measurable_mask := measurable_of_countable A.mask + core := OnlineRule.ofFinite A.core + +@[simp] lemma acceptedThrough_ofFinite {bits : ℕ} + (A : MatroidProphet.OnlineRule n bits) (r : Seed bits) (s v : Weights n) + (π : ArrivalOrder n) (t : ℕ) : + acceptedThrough (OnlineRule.ofFinite A) r s v π t = + MatroidProphet.acceptedThrough A r s v π t := rfl + +@[simp] lemma hiddenAcceptedThrough_ofFinite {bits : ℕ} + (A : MatroidProphet.HiddenRule n bits) (r : Seed bits) (w : Weights n) + (π : ArrivalOrder n) (t : ℕ) : + hiddenAcceptedThrough (HiddenRule.ofFinite A) r w π t = + MatroidProphet.hiddenAcceptedThrough A r w π t := rfl + +@[simp] lemma hiddenWorstReward_ofFinite {bits : ℕ} + (A : MatroidProphet.HiddenRule n bits) (w : Weights n) (r : Seed bits) : + hiddenWorstReward (HiddenRule.ofFinite A) w r = MatroidProphet.hiddenWorstReward A w r := rfl + +end MatroidProphet.General + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulationModel.lean b/lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulationModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..361ceea005cbb3db204276efb5ccffb6df425e8d --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/GeneralSimulationModel.lean @@ -0,0 +1,130 @@ +import OAI.Probability.MatroidProphet.Main +import Mathlib.Probability.Independence.Basic +import Mathlib.MeasureTheory.Integral.Bochner.Basic + +namespace OAI + +namespace MatroidProphet.General + +open MeasureTheory ProbabilityTheory + +/-- A decision uses only the entire initial seed, the initially observed vector, +and the label/value history through the current arrival. -/ +structure OnlineRule (n : ℕ) (R : Type*) [MeasurableSpace R] where + decide : (k : Fin n) → R → Weights n → History n k → Bool + measurable_decide : ∀ k, Measurable + (fun x : R × (Weights n × History n k) => decide k x.1 x.2.1 x.2.2) + +def decisionAt {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : OnlineRule n R) (r : R) (s v : Weights n) + (π : ArrivalOrder n) (k : Fin n) : Bool := + A.decide k r s (history v π k) + +noncomputable def acceptedThrough {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : OnlineRule n R) (r : R) (s v : Weights n) + (π : ArrivalOrder n) (t : ℕ) : Finset (Fin n) := by + classical + exact Finset.univ.filter fun e => + (π.symm e).val < t ∧ decisionAt A r s v π (π.symm e) = true + +noncomputable def reward {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : OnlineRule n R) (r : R) (s v : Weights n) (π : ArrivalOrder n) : ℝ := + ∑ e ∈ acceptedThrough A r s v π n, v e + +def Feasible {n : ℕ} {R : Type*} [MeasurableSpace R] + (M : Matroid (Fin n)) (A : OnlineRule n R) : Prop := + ∀ (r : R) (s v : Weights n) (π : ArrivalOrder n) (t : ℕ), + (∀ e, 0 ≤ s e) → (∀ e, 0 ≤ v e) → + M.Indep (acceptedThrough A r s v π t : Set (Fin n)) + +/-- The observation mask is a measurable function of the seed alone. -/ +structure HiddenRule (n : ℕ) (R : Type*) [MeasurableSpace R] where + mask : R → Finset (Fin n) + measurable_mask : Measurable mask + core : OnlineRule n R + +noncomputable def observed {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : HiddenRule n R) (r : R) (w : Weights n) : Weights n := by + classical + exact fun e => if e ∈ A.mask r then w e else 0 + +noncomputable def hiddenAcceptedThrough {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : HiddenRule n R) (r : R) (w : Weights n) + (π : ArrivalOrder n) (t : ℕ) : Finset (Fin n) := + acceptedThrough A.core r (observed A r w) w π t \ A.mask r + +noncomputable def hiddenReward {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : HiddenRule n R) (r : R) (w : Weights n) (π : ArrivalOrder n) : ℝ := + ∑ e ∈ hiddenAcceptedThrough A r w π n, w e + +noncomputable def hiddenWorstReward {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : HiddenRule n R) (w : Weights n) (r : R) : ℝ := by + classical + exact Finset.univ.inf' Finset.univ_nonempty (hiddenReward A r w) + +def HiddenFeasible {n : ℕ} {R : Type*} [MeasurableSpace R] + (M : Matroid (Fin n)) (A : HiddenRule n R) : Prop := + ∀ (w : Weights n), (∀ e, 0 ≤ w e) → + ∀ (r : R) (π : ArrivalOrder n) (t : ℕ), + M.Indep (hiddenAcceptedThrough A r w π t : Set (Fin n)) + +/-- Sample values on the sacrificed mask, and realized values elsewhere. -/ +noncomputable def glue {n : ℕ} (mask : Finset (Fin n)) (s v : Weights n) : Weights n := by + classical + exact fun e => if e ∈ mask then s e else v e + +noncomputable def simulationHistory {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : HiddenRule n R) (r : R) (s : Weights n) + {k : Fin n} (h : History n k) : History n k := by + classical + exact fun j => ((h j).1, if (h j).1 ∈ A.mask r then s (h j).1 else (h j).2) + + + +noncomputable def simulationDecision {n : ℕ} {R : Type*} [MeasurableSpace R] + (A : HiddenRule n R) (k : Fin n) (r : R) (s : Weights n) + (h : History n k) : Bool := by + classical + exact if (h ⟨k.val, Nat.lt_succ_self _⟩).1 ∈ A.mask r then false + else A.core.decide k r (observed A r s) (simulationHistory A r s h) + +/-- Full source contract for `lem:simulation`, with arbitrary measurable seed +and probability spaces. The simulator is constructed before the distributions +and adversary are supplied. Its decision function is specified concretely; +the conjunction includes exact execution, feasibility, the seed/glued-vector +joint law, integrability, and preservation of the same competitive ratio. -/ +def SimulationContract.{u, v} : Prop := + ∀ (n : ℕ) (R : Type v) [MeasurableSpace R] + (M : Matroid (Fin n)) (A : HiddenRule n R) + (ν : Measure R), IsProbabilityMeasure ν → + ∀ (c : ℝ), HiddenFeasible M A → + (∀ (w : Weights n), (∀ e, 0 ≤ w e) → + c * optimum M w ≤ ∫ r, hiddenWorstReward A w r ∂ν) → + ∃ B : OnlineRule n R, + (∀ (k : Fin n) (r : R) (s : Weights n) (h : History n k), + B.decide k r s h = simulationDecision A k r s h) ∧ + Feasible M B ∧ + (∀ (r : R) (s v : Weights n) (π : ArrivalOrder n) (t : ℕ), + acceptedThrough B r s v π t = + hiddenAcceptedThrough A r (glue (A.mask r) s v) π t) ∧ + (∀ (r : R) (s v : Weights n) (π : ArrivalOrder n), + reward B r s v π = hiddenReward A r (glue (A.mask r) s v) π) ∧ + ∀ {Ω : Type u} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] + (S V : Ω → Weights n) (seed : Ω → R), + Measurable S → Measurable V → Measurable seed → + (∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) → + (∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) → + iIndepFun (pairedCoordinates S V) μ → + (∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e)) → + IndepFun (fun ω => (S ω, V ω)) seed μ → μ.map seed = ν → + Integrable (fun ω => optimum M (V ω)) μ → + ∀ (π : Ω → ArrivalOrder n), Measurable π → + MeasurePreserving (fun ω => (seed ω, glue (A.mask (seed ω)) (S ω) (V ω))) + μ (ν.prod (μ.map V)) ∧ + Integrable (fun ω => reward B (seed ω) (S ω) (V ω) (π ω)) μ ∧ + c * (∫ ω, optimum M (V ω) ∂μ) ≤ + ∫ ω, reward B (seed ω) (S ω) (V ω) (π ω) ∂μ + +end MatroidProphet.General + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/InformationRestriction.lean b/lean/OAI/Probability/MatroidSecretary/Transport/InformationRestriction.lean new file mode 100644 index 0000000000000000000000000000000000000000..04651fea754de7b6790c3dadef9147c6d282deed --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/InformationRestriction.lean @@ -0,0 +1,128 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +/-! +# Explicit information restrictions for hidden-vector rules + +These lemmas formalize the no-future-information and irrevocability clauses of +`sections/algorithm.tex`, Lemma `lem:feasibility`. They use only the concrete +history and acceptance definitions; no correctness hypothesis for an algorithm +is introduced. +-/ + +namespace MatroidProphet + +open Finset + +lemma observed_eq_of_eq_on_mask {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w w' : Weights n) + (h : ∀ e ∈ A.mask r, w e = w' e) : + observed A r w = observed A r w' := by + classical + funext e + by_cases he : e ∈ A.mask r + · simp only [observed, ite_eq_left he, h e he] + · simp only [observed, ite_eq_right he] + +lemma history_eq_of_agree_before {n : ℕ} (v v' : Weights n) + (π π' : ArrivalOrder n) (t : ℕ) + (h : ∀ j : Fin n, j.val < t → (π j, v (π j)) = (π' j, v' (π' j))) + (k : Fin n) (hk : k.val < t) : + history v π k = history v' π' k := by + funext j + exact h (prefixIndex k j) (by dsimp [prefixIndex]; omega) + +/-- Equal available label/value pairs give the same accepted set through a prefix. +The two complete arrival orders and all later values may be different. -/ +theorem acceptedThrough_eq_of_agree_before {n bits : ℕ} (A : OnlineRule n bits) + (r : Seed bits) (s v v' : Weights n) (π π' : ArrivalOrder n) (t : ℕ) + (h : ∀ j : Fin n, j.val < t → (π j, v (π j)) = (π' j, v' (π' j))) : + acceptedThrough A r s v π t = acceptedThrough A r s v' π' t := by + classical + have subset (v₁ v₂ : Weights n) (ρ₁ ρ₂ : ArrivalOrder n) + (hρ : ∀ j : Fin n, j.val < t → + (ρ₁ j, v₁ (ρ₁ j)) = (ρ₂ j, v₂ (ρ₂ j))) : + acceptedThrough A r s v₁ ρ₁ t ⊆ acceptedThrough A r s v₂ ρ₂ t := by + intro e he + have hmem := (Finset.mem_filter.mp he).2 + have hl := congrArg Prod.fst (hρ (ρ₁.symm e) hmem.1) + have hidx : ρ₂.symm e = ρ₁.symm e := by + apply ρ₂.injective + simpa only [Equiv.apply_symm_apply] using hl + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ e, ?_, ?_⟩ + · simpa only [hidx] using hmem.1 + · rw [hidx] + rw [← decisionAt_congr A r s v₁ v₂ ρ₁ ρ₂ (ρ₁.symm e) + (history_eq_of_agree_before v₁ v₂ ρ₁ ρ₂ t hρ _ hmem.1)] + exact hmem.2 + exact Finset.Subset.antisymm (subset v v' π π' h) + (subset v' v π' π (fun j hj => (h j hj).symm)) + +/-- A hidden-vector execution depends only on its revealed coordinates and the +actual arrival history, never on the unobserved future values or future order. -/ +theorem hiddenAcceptedThrough_eq_of_same_information {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (w w' : Weights n) + (π π' : ArrivalOrder n) (t : ℕ) + (hmask : ∀ e ∈ A.mask r, w e = w' e) + (hhist : ∀ j : Fin n, j.val < t → + (π j, w (π j)) = (π' j, w' (π' j))) : + hiddenAcceptedThrough A r w π t = hiddenAcceptedThrough A r w' π' t := by + unfold hiddenAcceptedThrough + rw [observed_eq_of_eq_on_mask A r w w' hmask] + rw [acceptedThrough_eq_of_agree_before A.core r (observed A r w') w w' π π' t hhist] + +/-- Hidden-vector acceptances cannot be revoked. -/ +theorem hiddenAcceptedThrough_monotone {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) : + Monotone (hiddenAcceptedThrough A r w π) := by + intro t t' htt' e he + have hm := Finset.mem_sdiff.mp he + exact Finset.mem_sdiff.mpr + ⟨acceptedThrough_mono A.core r (observed A r w) w π htt' hm.1, hm.2⟩ + +/-- Sacrifice is literal rejection, not merely exclusion from the reward sum. -/ +theorem hiddenAcceptedThrough_disjoint_mask {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) (t : ℕ) : + Disjoint (hiddenAcceptedThrough A r w π t) (A.mask r) := by + exact Finset.sdiff_disjoint + +/-- Every accepted hidden-vector label has actually arrived. -/ +theorem hiddenAcceptedThrough_arrived {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w : Weights n) (π : ArrivalOrder n) (t : ℕ) + (e : Fin n) (he : e ∈ hiddenAcceptedThrough A r w π t) : + (π.symm e).val < t := + acceptedThrough_arrived A.core r (observed A r w) w π t e + (Finset.mem_sdiff.mp he).1 + +/-- The observation operation is jointly measurable in the complete initial seed +and the hidden vector, despite an arbitrary seed-dependent mask. -/ +lemma measurable_observed_seed {n bits : ℕ} (A : HiddenRule n bits) : + Measurable (fun x : Seed bits × Weights n => observed A x.1 x.2) := by + classical + apply measurable_from_prod_countable_right + intro r + apply Measurable.of_eval + intro e + by_cases he : e ∈ A.mask r + · simpa only [observed, ite_eq_left he] using + (measurable_pi_apply e : Measurable (fun w : Weights n => w e)) + · simpa only [observed, ite_eq_right he] using + (measurable_const : Measurable (fun _ : Weights n => (0 : ℝ))) + +/-- With observations substituted, the actual core decision remains measurable. -/ +lemma measurable_hidden_core_decide {n bits : ℕ} (A : HiddenRule n bits) + (k : Fin n) : + Measurable (fun x : Seed bits × (Weights n × History n k) => + A.core.decide k x.1 (observed A x.1 x.2.1) x.2.2) := by + apply measurable_from_prod_countable_right + intro r + exact (A.core.measurable_decide k).comp + (measurable_const.prodMk + (((measurable_observed_seed A).comp + (measurable_const.prodMk measurable_fst)).prodMk measurable_snd)) + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/SimulationInformation.lean b/lean/OAI/Probability/MatroidSecretary/Transport/SimulationInformation.lean new file mode 100644 index 0000000000000000000000000000000000000000..94d665f8b41e1ee8edeacd864502ba5f45c011a7 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/SimulationInformation.lean @@ -0,0 +1,116 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +/-! +# Information restrictions of the one-sample simulation + +These pointwise statements make explicit the information restrictions used in +`sections/setup.tex`, Lemma `lem:simulation`: unused samples and online values +of sacrificed labels cannot affect the execution. The final two replay +identities also support the prefix/suffix construction in `sections/secretary.tex`. +No independence, positivity, or feasibility assumptions are needed for these +deterministic identities. +-/ + +namespace MatroidProphet + +lemma simulationObserved_eq_of_eq_on_mask {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (s s' : Weights n) + (hs : ∀ e ∈ A.mask r, s e = s' e) : + observed A r s = observed A r s' := by + classical + funext e + by_cases he : e ∈ A.mask r + · simp [observed, he, hs e he] + · simp [observed, he] + +lemma simulationHistory_eq_of_eq_on_mask {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (s s' : Weights n) {k : Fin n} (h : History n k) + (hs : ∀ e ∈ A.mask r, s e = s' e) : + simulationHistory A r s h = simulationHistory A r s' h := by + classical + funext j + by_cases he : (h j).1 ∈ A.mask r + · simp [simulationHistory, he, hs _ he] + · simp [simulationHistory, he] + +/-- The simulator's current decision ignores every sample outside its mask. -/ +theorem sampleSimulation_decide_eq_of_eq_on_mask {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (s s' : Weights n) + (k : Fin n) (h : History n k) + (hs : ∀ e ∈ A.mask r, s e = s' e) : + (sampleSimulation A).decide k r s h = + (sampleSimulation A).decide k r s' h := by + classical + simp only [sampleSimulation] + rw [simulationObserved_eq_of_eq_on_mask A r s s' hs, + simulationHistory_eq_of_eq_on_mask A r s s' h hs] + +lemma glue_eq_of_eq_on_regions {n : ℕ} (mask : Finset (Fin n)) + (s s' v v' : Weights n) + (hs : ∀ e ∈ mask, s e = s' e) + (hv : ∀ e ∉ mask, v e = v' e) : + glue mask s v = glue mask s' v' := by + classical + funext e + by_cases he : e ∈ mask + · simp [glue, he, hs e he] + · simp [glue, he, hv e he] + +/-- Neither unused samples nor sacrificed online values change any accepted prefix. -/ +theorem sampleSimulation_acceptedThrough_noninterference {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (s s' v v' : Weights n) + (π : ArrivalOrder n) (t : ℕ) + (hs : ∀ e ∈ A.mask r, s e = s' e) + (hv : ∀ e ∉ A.mask r, v e = v' e) : + acceptedThrough (sampleSimulation A) r s v π t = + acceptedThrough (sampleSimulation A) r s' v' π t := by + rw [sampleSimulation_acceptedThrough, sampleSimulation_acceptedThrough, + glue_eq_of_eq_on_regions (A.mask r) s s' v v' hs hv] + +/-- The same information invariance holds for the reward in actual online values. -/ +theorem sampleSimulation_reward_noninterference {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (s s' v v' : Weights n) + (π : ArrivalOrder n) + (hs : ∀ e ∈ A.mask r, s e = s' e) + (hv : ∀ e ∉ A.mask r, v e = v' e) : + reward (sampleSimulation A) r s v π = + reward (sampleSimulation A) r s' v' π := by + rw [sampleSimulation_reward, sampleSimulation_reward, + glue_eq_of_eq_on_regions (A.mask r) s s' v v' hs hv] + +/-- A sacrificed label is rejected at every prefix, irrespective of its value. -/ +theorem sampleSimulation_rejects_mask {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (s v : Weights n) (π : ArrivalOrder n) (t : ℕ) + (e : Fin n) (he : e ∈ A.mask r) : + e ∉ acceptedThrough (sampleSimulation A) r s v π t := by + rw [sampleSimulation_acceptedThrough] + exact fun h => (Finset.mem_sdiff.mp h).2 he + +lemma glue_observed_left {n bits : ℕ} (A : HiddenRule n bits) + (r : Seed bits) (w : Weights n) : + glue (A.mask r) (observed A r w) w = w := by + classical + funext e + by_cases he : e ∈ A.mask r <;> simp [glue, observed, he] + +/-- Replaying the full arrived history after supplying only the observed mask +agrees exactly with the hidden rule, at every prefix including zero. -/ +theorem sampleSimulation_replay_acceptedThrough {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (w : Weights n) + (π : ArrivalOrder n) (t : ℕ) : + acceptedThrough (sampleSimulation A) r (observed A r w) w π t = + hiddenAcceptedThrough A r w π t := by + rw [sampleSimulation_acceptedThrough, glue_observed_left] + +/-- The replay identity preserves the actual reward without a numerical loss. -/ +theorem sampleSimulation_replay_reward {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (w : Weights n) + (π : ArrivalOrder n) : + reward (sampleSimulation A) r (observed A r w) w π = hiddenReward A r w π := by + rw [sampleSimulation_reward, glue_observed_left] + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/StrongOneSample.lean b/lean/OAI/Probability/MatroidSecretary/Transport/StrongOneSample.lean new file mode 100644 index 0000000000000000000000000000000000000000..f353de5abcb17a29a9ed8b12669b6e6631e4a80d --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/StrongOneSample.lean @@ -0,0 +1,59 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +/-! +# The stronger constant for the concrete one-sample rule + +The introduction explicitly records the stronger `2⁻²⁹³` constant proved in +accounting.tex. The root endpoint uses its announced `2⁻³¹⁰` constant. This +supporting theorem exposes the stronger claim for the actual constructed rule, +without changing the endpoint or imposing moments on individual loop values. + +The rule and initial seed law below depend only on the known labeled matroid. +The probability space, matching input laws, and full-seed-aware adversary are +supplied afterwards. Feasibility is pointwise at every prefix and the reward +estimate uses only integrability of the actual offline optimum. +-/ + +namespace MatroidProphet + +open MeasureTheory ProbabilityTheory + +/-- The actual simulated source rule is feasible before any laws are chosen. -/ +theorem source_one_sample_feasible {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) : + Feasible M (sampleSimulation (completeHiddenRule M hE)) := + sampleSimulation_feasible M (completeHiddenRule M hE) + (completeHiddenRule_feasible M hE) + +/-- The source construction attains the stronger constant advertised after +`thm:main`, even when the order sees the complete initial seed. This is a +consequence for the concrete rule, not a premise asserting its performance. -/ +theorem source_one_sample_strong {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) + {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] + (S V : Ω → Weights n) (R : Ω → Seed (mainSeedBits n)) + (hS : Measurable S) (hV : Measurable V) (hR : Measurable R) + (hSN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ S ω e) + (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) + (hi : iIndepFun (pairedCoordinates S V) μ) + (hlaw : ∀ e, μ.map (fun ω => S ω e) = μ.map (fun ω => V ω e)) + (hseed : IndepFun (fun ω => (S ω, V ω)) R μ) + (hRlaw : μ.map R = sourceSeedLaw n) + (hopt : Integrable (fun ω => optimum M (V ω)) μ) + (π : Ω → ArrivalOrder n) (hπ : Measurable π) : + Integrable (fun ω => + reward (sampleSimulation (completeHiddenRule M hE)) + (R ω) (S ω) (V ω) (π ω)) μ ∧ + ((2 : ℝ) ^ 293)⁻¹ * (∫ ω, optimum M (V ω) ∂μ) ≤ + ∫ ω, reward (sampleSimulation (completeHiddenRule M hE)) + (R ω) (S ω) (V ω) (π ω) ∂μ := + oneSample_of_hidden M (completeHiddenRule M hE) (sourceSeedLaw n) + (((2 : ℝ) ^ 293)⁻¹) (completeHiddenRule_feasible M hE) + (complete_hidden_guarantee M hE) μ S V R hS hV hR hSN hVN + hi hlaw hseed hRlaw hopt π hπ + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/TransferContract.lean b/lean/OAI/Probability/MatroidSecretary/Transport/TransferContract.lean new file mode 100644 index 0000000000000000000000000000000000000000..47e00a6e303a3499c9ac46bffd57a48119ce386c --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/TransferContract.lean @@ -0,0 +1,95 @@ +import OAI.Probability.MatroidProphet.Main +import OAI.Probability.MatroidSecretary.Transport.TransferSpecification + +namespace OAI + +/-! +# Source-facing sample-to-rank transfer + +Source: `sections/transfer.tex`, `lem:transfer` / `eq:rank-transfer`. +The comparison set is the actual priority-greedy survivor group; its independence +and containment are proved, not supplied as extra assumptions. `mainMean` fixes +only H and averages the density, guard, test, and parity coins. `trueZ` uses zero +on unlisted outcomes, so the expectation is not conditioned on listing. +-/ + +namespace MatroidProphet.SourceProof + +open Finset MainAlgorithm + +/-- Conditional averaging depends on the fixed filter mask only. All other +fields of the initial record are overwritten by independent product samples. -/ +lemma mainMean_filter_congr {n : ℕ} (d d' : MainMasks n) + (hH : d.H = d'.H) (f : MainMasks n → ℝ) : mainMean d f = mainMean d' f := by + rcases d with ⟨H, D, C, T, p⟩ + rcases d' with ⟨H', D', C', T', p'⟩ + change H = H' at hH + subst H' + rfl + +/-- The unlisted branch is included in the product average with zero statistic. -/ +lemma trueZ_unlisted {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ) + (hi : i ∉ groups M d s) : trueZ M hE d s i = 0 := by + classical + simp only [trueZ, ite_eq_right hi] + +/-- In particular, a true group missed by the discovery sample contributes zero; +no positivity or listing assumption is imposed on the individual outcomes. -/ +lemma trueZ_zero_of_no_discovery {n : ℕ} (M : Matroid (Fin n)) + (hE : M.E = Set.univ) (d : MainMasks n) (s : Fin n → Option ℤ) (i : ℤ) + (hmiss : d.D ∩ trueGroup M d s i = ∅) : trueZ M hE d s i = 0 := by + apply trueZ_unlisted + intro hi + obtain ⟨e, heD, heU⟩ := (mem_listed_iff M d s i).mp ((mem_groups M d s i).mp hi) + have he : e ∈ d.D ∩ trueGroup M d s i := mem_inter.mpr ⟨heD, heU⟩ + rw [hmiss] at he + exact notMem_empty e he + +/-- The source transfer at arbitrary rounded-level keys. This stronger helper +also covers the `none` keys representing zero/nonpositive weights. -/ +theorem transfer_keys {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (s : Fin n → Option ℤ) (H : Finset (Fin n)) (i : ℤ) : + let d : MainMasks n := ⟨H, ∅, ∅, ∅, false⟩ + let U := trueGroup M d s i + let Y := (positiveGreedy M s \ H).filter (fun e => s e = some i) + densityThreshold ≤ (U.card : ℝ) → + ((((2 : ℝ)^16)⁻¹ * Y.card - ((2 : ℝ)^23)⁻¹ * U.card) / (2 : ℝ)^100) ≤ + mainMean d (fun d' => (trueZ M hE d' s i : ℝ)) := by + classical + dsimp only + intro hn + let d : MainMasks n := ⟨H, ∅, ∅, ∅, false⟩ + let Y := (positiveGreedy M s \ H).filter (fun e => s e = some i) + have hY : (Y : Set (Fin n)) ⊆ (trueGroup M d s i : Set (Fin n)) := by + intro e he + rw [trueGroup_eq_candidate_filter] + rcases mem_filter.mp he with ⟨heG, hei⟩ + exact mem_filter.mpr ⟨positiveGreedy_survivors_subset M s H heG, hei⟩ + have hI : M.Indep (Y : Set (Fin n)) := + (positiveGreedy_survivors_indep M hE s H).subset + (fun _ he => (mem_filter.mp he).1) + have h := mainMean_trueZ_lower M hE d s i (Y : Set (Fin n)) hY hI hn + simpa only [Set.ncard_coe_finset, retainedFraction, densityThreshold, d, Y] using h + +/-- `lem:transfer` for the manuscript's actual rounded nonnegative weights, +with literal constants gamma = 2^-16 and kappa = 2^100. -/ +theorem transfer {n : ℕ} (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (w : Weights n) (_hw : ∀ e, 0 ≤ w e) (H : Finset (Fin n)) (i : ℤ) : + let s : Fin n → Option ℤ := fun e => roundedLevel weightBase (w e) + let d : MainMasks n := ⟨H, ∅, ∅, ∅, false⟩ + let U := trueGroup M d s i + let Y := (positiveGreedy M s \ H).filter (fun e => s e = some i) + densityThreshold ≤ (U.card : ℝ) → + ((((2 : ℝ)^16)⁻¹ * Y.card - ((2 : ℝ)^23)⁻¹ * U.card) / (2 : ℝ)^100) ≤ + mainMean d (fun d' => (trueZ M hE d' s i : ℝ)) := + transfer_keys M hE (fun e => roundedLevel weightBase (w e)) H i + +/-- Thin proof alias for the independent root-target specification. -/ +theorem transfer_claim : TransferClaim := by + intro n M hE w hw H i + exact transfer M hE w hw H i + +end MatroidProphet.SourceProof + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/TransferContracts.lean b/lean/OAI/Probability/MatroidSecretary/Transport/TransferContracts.lean new file mode 100644 index 0000000000000000000000000000000000000000..e8b84d039015405dbc21760af57219a98c77816c --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/TransferContracts.lean @@ -0,0 +1,106 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +namespace MatroidProphet +namespace TransferContracts + +open Finset Set Pivots MainAlgorithm + +section Pivots + +variable {α : Type*} {r q n : ℕ} + +/-- An injectively timed sequence determines one recorded pivot-mark vector. -/ +lemma recordsPivots_unique (M : Matroid α) (label : Occurrence r q → α) + (test : Fin n → α) (time : Occurrence r q → ℕ) + (htime : Function.Injective time) (oldMark : Fin r → Bool) + (movableMark : Fin q → Bool) {t u : Finset (Fin n)} + (ht : RecordsPivots M label test time oldMark movableMark t) + (hu : RecordsPivots M label test time oldMark movableMark u) : t = u := by + ext f + obtain ⟨o, ho, hto⟩ := ht f + obtain ⟨p, hp, hup⟩ := hu f + have hop := pivot_unique M label time htime ho hp + subst p + exact hto.symm.trans hup + +variable [Fintype α] + +/-- Complete marked-pivot contract: arbitrary repeated/redundant old labels, +all placements/orders/marks of at most `s` movable occurrences, and the exact +binomial bound. Source old-spanning/nonloop assumptions ensure every permitted +interleaving actually contributes exactly one vector. No positivity assumption +on `s`, `q`, `r`, or `n` is imposed. -/ +theorem marked_pivot_contract (M : Matroid α) (b : ℕ → α) (a : Fin q → α) + (test : Fin n → α) (oldMark : Fin r → Bool) (s : ℕ) (hqs : q ≤ s) + (hground : ∀ o : Occurrence r q, occurrenceLabel b a o ∈ M.E) + (holdspan : M.closure (oldPrefix b r) = M.E) + (htest : ∀ f, test f ∈ M.E ∧ test f ∉ M.closure ∅) : + (markedPivotPatterns M b a test oldMark).card ≤ + 4 ^ s * ∑ k ∈ Finset.Iic s, n.choose k ∧ + ∀ (time : Occurrence r q → ℕ), OldOrdered time → Function.Injective time → + ∀ movableMark : Fin q → Bool, + ∃! t, t ∈ markedPivotPatterns M b a test oldMark ∧ + RecordsPivots M (occurrenceLabel b a) test time oldMark movableMark t := by + refine ⟨card_markedPivotPatterns_le M b a test oldMark s hqs hground, ?_⟩ + intro time horder htime movableMark + obtain ⟨t, htmem, ht⟩ := recorded_pattern_exists_of_old_spanning M b a test oldMark + holdspan htest time horder htime movableMark + refine ⟨t, ⟨htmem, ht⟩, ?_⟩ + intro u hu + exact recordsPivots_unique M (occurrenceLabel b a) test time htime oldMark movableMark hu.2 ht + +end Pivots + +section Transfer + +variable {n : ℕ} + +/-- The independent comparison group is constructed by priority greedy and +fair-mask deletion, exactly as in the manuscript (`Y_i = (I* \ H) ∩ U_i`). -/ +lemma comparison_group_indep_subset (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (d : MainMasks n) (a : Fin n → Option ℤ) (i : ℤ) : + let Y := (positiveGreedy M a \ d.H).filter (fun e => a e = some i) + M.Indep (Y : Set (Fin n)) ∧ (Y : Set (Fin n)) ⊆ (trueGroup M d a i : Set (Fin n)) := by + classical + dsimp only + constructor + · exact (positiveGreedy_survivors_indep M hE a d.H).subset (Finset.filter_subset _ _) + · intro e he + obtain ⟨heY, hei⟩ := Finset.mem_filter.mp he + apply (mem_trueGroup M d a i e).mpr + refine ⟨?_, hei⟩ + exact (Finset.mem_filter.mp (positiveGreedy_survivors_subset M a d.H heY)).2 + +/-- Full sample-to-rank inequality for the actual rounded weight vector. +`withMasks` averages all density, guard and test bits while fixing `H`; +`fairParityExpectation` averages parity. `listedRankStatistic` is explicitly +zero on the unlisted branch. Thus there is no conditioning on listing and no +independence assumption about the selected residual. -/ +theorem sample_to_rank_contract (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (w : Weights n) (d : MainMasks n) (i : ℤ) + (hn : densityThreshold ≤ + ((trueGroup M d (fun e => roundedLevel weightBase (w e)) i).card : ℝ)) : + let a := fun e => roundedLevel weightBase (w e) + let Y := (positiveGreedy M a \ d.H).filter (fun e => a e = some i) + (retainedFraction * (Y.card : ℝ) - ((2 : ℝ) ^ 23)⁻¹ * + (trueGroup M d a i).card) / densityThreshold ≤ + tripleMaskExpectation (fun _ => (1 : ℝ) / 4) + (fun _ => thinningRate) (fun _ => thinningRate) Finset.univ + (fun D C T => fairParityExpectation (fun p => + (listedRankStatistic M hE (2 ^ 100) (withMasks d D C T) a i + (boolParity p) : ℝ))) := by + classical + let a := fun e => roundedLevel weightBase (w e) + let Y := (positiveGreedy M a \ d.H).filter (fun e => a e = some i) + have hY := comparison_group_indep_subset M hE d a i + have h := listedRankStatistic_lower M hE d a i (Y : Set (Fin n)) hY.2 hY.1 hn + simpa only [Set.ncard_coe_finset] using h + +end Transfer + +end TransferContracts +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Transport/TransferSpecification.lean b/lean/OAI/Probability/MatroidSecretary/Transport/TransferSpecification.lean new file mode 100644 index 0000000000000000000000000000000000000000..e76e61207724dbecd8597c34f0b0d6da4ea60517 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Transport/TransferSpecification.lean @@ -0,0 +1,28 @@ +import OAI.Probability.MatroidProphet.Main + +namespace OAI + +/-! Independent specification of source `lem:transfer` / `eq:rank-transfer`. +The fixed filter mask is arbitrary. Every remaining product coordinate and parity +is averaged, and the actual nominal rank statistic is zero when unlisted. -/ + +namespace MatroidProphet + +open Finset MainAlgorithm + +/-- Full sample-to-rank contract for the actual rounded greedy survivor groups. -/ +def TransferClaim : Prop := + ∀ (n : ℕ) (M : Matroid (Fin n)) (hE : M.E = Set.univ) + (w : Weights n), (∀ e, 0 ≤ w e) → + ∀ (H : Finset (Fin n)) (i : ℤ), + let s : Fin n → Option ℤ := fun e => roundedLevel weightBase (w e) + let d : MainMasks n := ⟨H, ∅, ∅, ∅, false⟩ + let U := trueGroup M d s i + let Y := (positiveGreedy M s \ H).filter (fun e => s e = some i) + densityThreshold ≤ (U.card : ℝ) → + ((((2 : ℝ)^16)⁻¹ * Y.card - ((2 : ℝ)^23)⁻¹ * U.card) / (2 : ℝ)^100) ≤ + mainMean d (fun d' => (trueZ M hE d' s i : ℝ)) + +end MatroidProphet + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Weights/DegenerateCases.lean b/lean/OAI/Probability/MatroidSecretary/Weights/DegenerateCases.lean new file mode 100644 index 0000000000000000000000000000000000000000..c5d77eecc8e604278a0f34fbec202fb3b5a2d8b1 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Weights/DegenerateCases.lean @@ -0,0 +1,124 @@ +import OAI.Probability.MatroidProphet.Main +import Mathlib.Combinatorics.Matroid.Loop + +namespace OAI + +/-! +# Degenerate inputs and loop coordinates + +These lemmas concern the actual optimum and online execution, not a surrogate +benchmark. They make explicit the empty-ground, all-loop, zero-optimum and +fully-sacrificed cases admitted by setup.tex and secretary.tex. In particular, +no moment or boundedness hypothesis on a loop coordinate is needed for OPT. +-/ + +namespace MatroidProphet.DegenerateCases + +open Finset + +/-- Offline optimization is unaffected by any change in loop coordinates. -/ +theorem optimum_congr_on_nonloops {n : ℕ} (M : Matroid (Fin n)) + (v w : Weights n) (h : ∀ e, M.IsNonloop e → v e = w e) : + optimum M v = optimum M w := by + classical + unfold optimum + congr 1 + funext I + split_ifs with hI + · apply Finset.sum_congr rfl + intro e he + exact h e (hI.isNonloop_of_mem he) + · rfl + +/-- Zero weights have zero optimum, without a full-ground assumption. -/ +theorem optimum_zero {n : ℕ} (M : Matroid (Fin n)) : + optimum M (fun _ => 0) = 0 := by + classical + unfold optimum + simp + +/-- If every nonloop has zero weight, arbitrary loop weights do not affect OPT. -/ +theorem optimum_eq_zero_of_nonloops_zero {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) (hw : ∀ e, M.IsNonloop e → w e = 0) : + optimum M w = 0 := by + rw [optimum_congr_on_nonloops M w (fun _ => 0) hw, optimum_zero] + +/-- The all-loop case includes arbitrarily large and arbitrary-sign loop weights. -/ +theorem optimum_eq_zero_of_all_loops {n : ℕ} (M : Matroid (Fin n)) + (hM : ∀ e, M.IsLoop e) (w : Weights n) : optimum M w = 0 := by + apply optimum_eq_zero_of_nonloops_zero + intro e he + exact False.elim (he.not_isLoop (hM e)) + +/-- No labels is a valid input, and its actual offline optimum is zero. -/ +theorem optimum_empty (M : Matroid (Fin 0)) (w : Weights 0) : + optimum M w = 0 := by + apply optimum_eq_zero_of_nonloops_zero + intro e + exact Fin.elim0 e + +/-- A nonloop singleton is one of the sets in the optimization benchmark. -/ +theorem nonloop_weight_le_optimum {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) (e : Fin n) (he : M.IsNonloop e) : + w e ≤ optimum M w := by + simpa using sum_le_optimum M w {e} (by simpa using he.indep) + +/-- On nonnegative vectors, OPT vanishes exactly when every nonloop weight does. -/ +theorem optimum_eq_zero_iff {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) (hw : ∀ e, 0 ≤ w e) : + optimum M w = 0 ↔ ∀ e, M.IsNonloop e → w e = 0 := by + constructor + · intro h e he + exact le_antisymm (h ▸ nonloop_weight_le_optimum M w e he) (hw e) + · exact optimum_eq_zero_of_nonloops_zero M w + +/-- Every feasible rule has exactly zero reward on a zero-OPT input. -/ +theorem reward_eq_zero_of_optimum_eq_zero {n bits : ℕ} + (M : Matroid (Fin n)) (A : OnlineRule n bits) (hA : Feasible M A) + (r : Seed bits) (s v : Weights n) (π : ArrivalOrder n) + (hs : ∀ e, 0 ≤ s e) (hv : ∀ e, 0 ≤ v e) (hopt : optimum M v = 0) : + reward A r s v π = 0 := by + apply le_antisymm + · simpa only [hopt] using reward_le_optimum M A hA r s v π hs hv + · exact reward_nonneg A r s v π hv + +/-- Running past the finite final arrival does not create any further decisions. -/ +theorem acceptedThrough_stabilizes {n bits : ℕ} (A : OnlineRule n bits) + (r : Seed bits) (s v : Weights n) (π : ArrivalOrder n) + (t : ℕ) (ht : n ≤ t) : + acceptedThrough A r s v π t = accepted A r s v π := by + classical + ext e + have he : (π.symm e).val < t := lt_of_lt_of_le (π.symm e).isLt ht + simp [accepted, acceptedThrough, he] + +/-- The empty prefix never accepts anything, regardless of the rule. -/ +theorem acceptedThrough_zero {n bits : ℕ} (A : OnlineRule n bits) + (r : Seed bits) (s v : Weights n) (π : ArrivalOrder n) : + acceptedThrough A r s v π 0 = ∅ := by + classical + simp [acceptedThrough] + +/-- Fully revealed hidden-vector inputs are fully sacrificed, at every prefix. -/ +theorem hiddenAcceptedThrough_eq_empty_of_full_mask {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (hmask : A.mask r = Finset.univ) + (w : Weights n) (π : ArrivalOrder n) (t : ℕ) : + hiddenAcceptedThrough A r w π t = ∅ := by + simp [hiddenAcceptedThrough, hmask] + +/-- Full sacrifice gives zero reward for every order, including the empty order. -/ +theorem hiddenReward_eq_zero_of_full_mask {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (hmask : A.mask r = Finset.univ) + (w : Weights n) (π : ArrivalOrder n) : hiddenReward A r w π = 0 := by + simp [hiddenReward, hiddenAcceptedThrough_eq_empty_of_full_mask A r hmask] + +/-- The seed-wise adversarial minimum also vanishes under full sacrifice. -/ +theorem hiddenWorstReward_eq_zero_of_full_mask {n bits : ℕ} + (A : HiddenRule n bits) (r : Seed bits) (hmask : A.mask r = Finset.univ) + (w : Weights n) : hiddenWorstReward A w r = 0 := by + classical + simp [hiddenWorstReward, hiddenReward_eq_zero_of_full_mask A r hmask] + +end MatroidProphet.DegenerateCases + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawModel.lean b/lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..f0d2c78f38756c0b353b458463ebf8ad10d80cce --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawModel.lean @@ -0,0 +1,39 @@ +import Mathlib.Probability.ProbabilityMassFunction.Integrals + +namespace OAI + +namespace MatroidProphet.FiniteLaw + +open MeasureTheory +open scoped BigOperators + +noncomputable def weightPMF {α : Type*} [Fintype α] (p : α → ℝ) + (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) : PMF α := + PMF.ofFintype (fun a => ENNReal.ofReal (p a)) (by + rw [← ENNReal.ofReal_sum_of_nonneg (fun a _ => hp a), hp1] + exact ENNReal.ofReal_one) + +noncomputable def weightMeasure {α : Type*} [Fintype α] [MeasurableSpace α] + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) : Measure α := + (weightPMF p hp hp1).toMeasure + +noncomputable def kernelJointPMF {α β : Type*} [Fintype α] [Fintype β] + (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) : PMF (β × α) := + weightPMF (fun ba => m ba.1 * k ba.1 ba.2) + (fun ba => mul_nonneg (hm ba.1) (hk ba.1 ba.2)) (by + rw [Fintype.sum_prod_type] + simp_rw [← Finset.mul_sum, hk1, mul_one] + exact hm1) + +noncomputable def kernelJointMeasure {α β : Type*} [Fintype α] [Fintype β] + [MeasurableSpace α] [MeasurableSpace β] + (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) : Measure (β × α) := + (kernelJointPMF m k hm hm1 hk hk1).toMeasure + +end MatroidProphet.FiniteLaw + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawTheorems.lean b/lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawTheorems.lean new file mode 100644 index 0000000000000000000000000000000000000000..0144b30dcfffd95dd8a3a9e1fac1f4228df1f9f4 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Weights/FiniteWeightLawTheorems.lean @@ -0,0 +1,170 @@ +import OAI.Probability.MatroidSecretary.Weights.FiniteWeightLawModel + +namespace OAI + +/-! +Finite conditional-kernel bridge for the secretary transport. The algebraic +fiber identity is a hypothesis of these reusable lemmas, not a substitute for +proving that identity for the manuscript's actual source-seed law. +-/ + +namespace MatroidProphet.FiniteLaw + +open MeasureTheory +open scoped BigOperators Classical + +variable {α β : Type*} [Fintype α] [Fintype β] + +@[simp] theorem weightPMF_apply (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) + (hp1 : ∑ a, p a = 1) (a : α) : + weightPMF p hp hp1 a = ENNReal.ofReal (p a) := rfl + +instance weightMeasure_probability [MeasurableSpace α] + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) : + IsProbabilityMeasure (weightMeasure p hp hp1) := by + unfold weightMeasure + infer_instance + +theorem weightMeasure_singleton [MeasurableSpace α] [MeasurableSingletonClass α] + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) (a : α) : + weightMeasure p hp hp1 {a} = ENNReal.ofReal (p a) := by + exact PMF.toMeasure_apply_singleton _ a (MeasurableSet.singleton a) + +theorem integral_weightMeasure [MeasurableSpace α] [MeasurableSingletonClass α] + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) (f : α → ℝ) : + (∫ a, f a ∂weightMeasure p hp hp1) = ∑ a, p a * f a := by + rw [weightMeasure, PMF.integral_eq_sum] + simp only [weightPMF_apply, ENNReal.toReal_ofReal (hp _), smul_eq_mul] + +theorem sum_real_singleton [MeasurableSpace α] [MeasurableSingletonClass α] + (μ : Measure α) [IsProbabilityMeasure μ] : + (∑ a, μ.real {a}) = 1 := by + simp + +/-- No finite-law assumption is added: every probability measure on a finite +discrete space is exactly the measure of its real singleton weights. -/ +theorem weightMeasure_real_singleton [MeasurableSpace α] [MeasurableSingletonClass α] + (μ : Measure α) [IsProbabilityMeasure μ] : + weightMeasure (fun a => μ.real {a}) (fun _ => measureReal_nonneg) + (sum_real_singleton μ) = μ := by + apply Measure.ext_of_singleton + intro a + rw [weightMeasure_singleton, measureReal_def] + exact ENNReal.ofReal_toReal (measure_ne_top μ {a}) + +omit [Fintype β] in +theorem map_real_singleton + [MeasurableSpace α] [MeasurableSingletonClass α] + [MeasurableSpace β] [MeasurableSingletonClass β] + (μ : Measure α) [IsProbabilityMeasure μ] (obs : α → β) (b : β) : + (μ.map obs).real {b} = ∑ a, if obs a = b then μ.real {a} else 0 := by + classical + have hs : ((Finset.univ.filter fun a => obs a = b : Finset α) : Set α) = + obs ⁻¹' {b} := by + ext a + simp + rw [← Finset.sum_filter, sum_measureReal_singleton, hs] + simp only [measureReal_def, + Measure.map_apply (measurable_of_countable obs) (MeasurableSet.singleton b)] + +@[simp] theorem kernelJointPMF_apply + (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) + (b : β) (a : α) : + kernelJointPMF m k hm hm1 hk hk1 (b, a) = ENNReal.ofReal (m b * k b a) := rfl + +instance kernelJointMeasure_probability [MeasurableSpace α] [MeasurableSpace β] + (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) : + IsProbabilityMeasure (kernelJointMeasure m k hm hm1 hk hk1) := by + unfold kernelJointMeasure + infer_instance + +theorem integral_kernelJointMeasure + [MeasurableSpace α] [MeasurableSingletonClass α] + [MeasurableSpace β] [MeasurableSingletonClass β] + (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) + (f : β × α → ℝ) : + (∫ ba, f ba ∂kernelJointMeasure m k hm hm1 hk hk1) = + ∫ b, ∫ a, f (b, a) ∂weightMeasure (k b) (hk b) (hk1 b) + ∂weightMeasure m hm hm1 := by + rw [kernelJointMeasure, kernelJointPMF] + change (∫ ba, f ba ∂weightMeasure _ _ _) = _ + rw [integral_weightMeasure, Fintype.sum_prod_type, integral_weightMeasure] + simp_rw [integral_weightMeasure, Finset.mul_sum, mul_assoc] + +theorem kernelJointPMF_eq_map + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) + (obs : α → β) (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) + (hjoint : ∀ b a, m b * k b a = if obs a = b then p a else 0) : + kernelJointPMF m k hm hm1 hk hk1 = + (weightPMF p hp hp1).map (fun a => (obs a, a)) := by + classical + ext ba : 1 + obtain ⟨b, a⟩ := ba + rw [kernelJointPMF_apply, hjoint] + simp only [PMF.map_apply, tsum_fintype, Prod.mk.injEq, weightPMF_apply] + rw [Finset.sum_eq_single a] + · by_cases h : obs a = b + · simp [h] + · have h' : b ≠ obs a := Ne.symm h + simp [h, h'] + · intro a' _ hne + simp [Ne.symm hne] + · simp + +theorem kernelJointMeasure_eq_map + [MeasurableSpace α] [MeasurableSingletonClass α] + [MeasurableSpace β] [MeasurableSingletonClass β] + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) + (obs : α → β) (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) + (hjoint : ∀ b a, m b * k b a = if obs a = b then p a else 0) : + kernelJointMeasure m k hm hm1 hk hk1 = + (weightMeasure p hp hp1).map (fun a => (obs a, a)) := by + rw [kernelJointMeasure, kernelJointPMF_eq_map p hp hp1 obs m k hm hm1 hk hk1 hjoint] + exact (PMF.toMeasure_map (fun a => (obs a, a)) (weightPMF p hp hp1) + (measurable_of_countable _)).symm + +/-- The joint law transports every statistic of the observation and full seed, +not merely statistics of the sacrificed mask. -/ +theorem integral_reconstruction + [MeasurableSpace α] [MeasurableSingletonClass α] + [MeasurableSpace β] [MeasurableSingletonClass β] + (p : α → ℝ) (hp : ∀ a, 0 ≤ p a) (hp1 : ∑ a, p a = 1) + (obs : α → β) (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) + (hjoint : ∀ b a, m b * k b a = if obs a = b then p a else 0) + (f : β × α → ℝ) : + (∫ b, ∫ a, f (b, a) ∂weightMeasure (k b) (hk b) (hk1 b) + ∂weightMeasure m hm hm1) = + ∫ a, f (obs a, a) ∂weightMeasure p hp hp1 := by + rw [← integral_kernelJointMeasure m k hm hm1 hk hk1 f, + kernelJointMeasure_eq_map p hp hp1 obs m k hm hm1 hk hk1 hjoint] + exact integral_map_of_stronglyMeasurable (measurable_of_countable _) + (measurable_of_countable f).stronglyMeasurable + +/-- Every positive-mass reconstructed joint outcome has exactly its advertised +observation. Zero-mass fibers are not silently ruled out. -/ +theorem observation_eq_of_joint_support + (p : α → ℝ) (obs : α → β) (m : β → ℝ) (k : β → α → ℝ) + (hm : ∀ b, 0 ≤ m b) (hm1 : ∑ b, m b = 1) + (hk : ∀ b a, 0 ≤ k b a) (hk1 : ∀ b, ∑ a, k b a = 1) + (hjoint : ∀ b a, m b * k b a = if obs a = b then p a else 0) + (b : β) (a : α) + (ha : (b, a) ∈ (kernelJointPMF m k hm hm1 hk hk1).support) : obs a = b := by + rw [PMF.mem_support_iff, kernelJointPMF_apply, hjoint] at ha + by_contra h + exact ha (by simp [h]) + +end MatroidProphet.FiniteLaw + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Weights/OptimumIntegrability.lean b/lean/OAI/Probability/MatroidSecretary/Weights/OptimumIntegrability.lean new file mode 100644 index 0000000000000000000000000000000000000000..a633f3edc56fe5146c35f84281f6e364d0c9bbcb --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Weights/OptimumIntegrability.lean @@ -0,0 +1,90 @@ +import OAI.Probability.MatroidSecretary.Weights.DegenerateCases +import OAI.Probability.MatroidProphet.Main +import Mathlib.MeasureTheory.Integral.Bochner.Basic + +namespace OAI + +/-! +# The exact finite-moment requirement + +For a finite matroid and nonnegative measurable weights, integrability of the +actual offline optimum is equivalent to integrability of the nonloop +coordinates. No loop-coordinate moments are imposed. This is a supporting +scope check for introduction.tex, Theorem `thm:main`, and setup.tex's +one-sample simulation argument; it does not replace its competitive claim. +-/ + +namespace MatroidProphet.DegenerateCases + +open MeasureTheory Classical +open scoped BigOperators + +/-- Only nonloops can contribute to a feasible sum. -/ +theorem optimum_le_sum_nonloops {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) (hw : ∀ e, 0 ≤ w e) : + optimum M w ≤ ∑ e : Fin n, if M.IsNonloop e then w e else 0 := by + classical + have hn (e : Fin n) : 0 ≤ if M.IsNonloop e then w e else 0 := by + split_ifs + · exact hw e + · exact le_rfl + apply optimum_le_of_independent_bound M w _ (Finset.sum_nonneg fun e _ => hn e) + intro I hI + calc + (∑ e ∈ I, w e) = ∑ e ∈ I, if M.IsNonloop e then w e else 0 := by + apply Finset.sum_congr rfl + intro e he + simp [hI.isNonloop_of_mem he] + _ ≤ ∑ e : Fin n, if M.IsNonloop e then w e else 0 := by + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ I) + (fun e _ _ => hn e) + +/-- Nonloop moments follow from the assumed finite offline optimum moment. -/ +theorem integrable_nonloop_of_integrable_optimum {n : ℕ} + (M : Matroid (Fin n)) {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (V : Ω → Weights n) (hV : Measurable V) + (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) + (hopt : Integrable (fun ω => optimum M (V ω)) μ) + (e : Fin n) (he : M.IsNonloop e) : Integrable (fun ω => V ω e) μ := by + apply hopt.mono' ((measurable_pi_apply e).comp hV).aestronglyMeasurable + filter_upwards [hVN] with ω hω + change ‖V ω e‖ ≤ optimum M (V ω) + rw [Real.norm_eq_abs, abs_of_nonneg (hω e)] + exact nonloop_weight_le_optimum M (V ω) e he + +/-- Conversely, finite moments only on the nonloops suffice for finite E[OPT]. -/ +theorem integrable_optimum_of_integrable_nonloops {n : ℕ} + (M : Matroid (Fin n)) {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (V : Ω → Weights n) (hV : Measurable V) + (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) + (hmom : ∀ e, M.IsNonloop e → Integrable (fun ω => V ω e) μ) : + Integrable (fun ω => optimum M (V ω)) μ := by + classical + have hsum : Integrable (fun ω => + ∑ e : Fin n, if M.IsNonloop e then V ω e else 0) μ := by + apply integrable_finsetSum + intro e _ + by_cases he : M.IsNonloop e + · simpa only [ite_eq_left he] using hmom e he + · simp only [ite_eq_right he] + exact integrable_zero _ _ _ + apply hsum.mono' ((measurable_optimum M).comp hV).aestronglyMeasurable + filter_upwards [hVN] with ω hω + change ‖optimum M (V ω)‖ ≤ ∑ e : Fin n, if M.IsNonloop e then V ω e else 0 + rw [Real.norm_eq_abs, abs_of_nonneg (optimum_nonneg M (V ω))] + exact optimum_le_sum_nonloops M (V ω) hω + +/-- An exact criterion: loop moments are deliberately absent on the right. -/ +theorem integrable_optimum_iff {n : ℕ} (M : Matroid (Fin n)) + {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (V : Ω → Weights n) (hV : Measurable V) + (hVN : ∀ᵐ ω ∂μ, ∀ e, 0 ≤ V ω e) : + Integrable (fun ω => optimum M (V ω)) μ ↔ + ∀ e, M.IsNonloop e → Integrable (fun ω => V ω e) μ := by + constructor + · exact integrable_nonloop_of_integrable_optimum M μ V hV hVN + · exact integrable_optimum_of_integrable_nonloops M μ V hV hVN + +end MatroidProphet.DegenerateCases + +end OAI diff --git a/lean/OAI/Probability/MatroidSecretary/Weights/ZeroBenchmark.lean b/lean/OAI/Probability/MatroidSecretary/Weights/ZeroBenchmark.lean new file mode 100644 index 0000000000000000000000000000000000000000..bc4f34bd939f05d8a5fa834dbe6e984815bf3457 --- /dev/null +++ b/lean/OAI/Probability/MatroidSecretary/Weights/ZeroBenchmark.lean @@ -0,0 +1,134 @@ +import OAI.Probability.MatroidProphet.Main +import Mathlib.MeasureTheory.Integral.Bochner.Basic + +namespace OAI + +namespace MatroidProphet.ZeroBenchmark + +open MeasureTheory Finset +open scoped Classical + +/-- Only singleton-independent labels can affect the offline optimum. +No sign or integrability assumption is necessary for this identity. -/ +theorem optimum_congr_on_singletons {n : ℕ} (M : Matroid (Fin n)) + (w v : Weights n) + (h : ∀ e, M.Indep ({e} : Set (Fin n)) → w e = v e) : + optimum M w = optimum M v := by + classical + unfold optimum + apply Finset.sup'_congr Finset.univ_nonempty rfl + intro I _ + by_cases hI : M.Indep (I : Set (Fin n)) + · simp only [ite_eq_left hI] + apply Finset.sum_congr rfl + intro e he + exact h e (hI.subset (Set.singleton_subset_iff.mpr he)) + · simp only [ite_eq_right hI] + +/-- The zero-weight benchmark is zero, also for empty or rank-zero matroids. -/ +@[simp] theorem optimum_zero {n : ℕ} (M : Matroid (Fin n)) : + optimum M (fun _ => 0) = 0 := by + classical + simp [optimum] + +/-- On nonnegative inputs, a zero benchmark is exactly the condition that +every label that could be accepted on its own has zero weight. -/ +theorem optimum_eq_zero_iff {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) (hw : ∀ e, 0 ≤ w e) : + optimum M w = 0 ↔ ∀ e, M.Indep ({e} : Set (Fin n)) → w e = 0 := by + constructor + · intro h e he + have hb := sum_le_optimum M w {e} (by simpa using he) + simp only [Finset.sum_singleton, h] at hb + exact le_antisymm hb (hw e) + · intro h + rw [optimum_congr_on_singletons M w (fun _ => 0) h] + exact optimum_zero M + +/-- Replacing all loop coordinates by zero never changes the objective. +Here ground-set outsiders, if any, are also harmless. -/ +theorem optimum_ignore_infeasible_coordinates {n : ℕ} (M : Matroid (Fin n)) + (w : Weights n) : + optimum M (fun e => if M.Indep ({e} : Set (Fin n)) then w e else 0) = + optimum M w := by + classical + apply optimum_congr_on_singletons + intro e he + simp only [ite_eq_left he] + +/-- Rank-zero behavior needs no bound at all on the values of its labels. -/ +theorem optimum_eq_zero_of_no_independent_singleton {n : ℕ} + (M : Matroid (Fin n)) + (hM : ∀ e, ¬ M.Indep ({e} : Set (Fin n))) (w : Weights n) : + optimum M w = 0 := by + rw [optimum_congr_on_singletons M w (fun _ => 0) (fun e he => (hM e he).elim)] + exact optimum_zero M + +/-- The empty instance has the zero benchmark without a positive-size premise. -/ +@[simp] theorem optimum_empty (M : Matroid (Fin 0)) (w : Weights 0) : + optimum M w = 0 := by + apply optimum_eq_zero_of_no_independent_singleton + intro e + exact Fin.elim0 e + +/-- Every feasible realized hidden reward vanishes when the benchmark does. -/ +theorem hiddenReward_eq_zero {n bits : ℕ} (M : Matroid (Fin n)) + (A : HiddenRule n bits) (r : Seed bits) (w : Weights n) + (π : ArrivalOrder n) (hw : ∀ e, 0 ≤ w e) + (hA : M.Indep (hiddenAcceptedThrough A r w π n : Set (Fin n))) + (hopt : optimum M w = 0) : hiddenReward A r w π = 0 := by + apply le_antisymm + · exact (sum_le_optimum M w _ hA).trans_eq hopt + · exact Finset.sum_nonneg fun e _ => hw e + +/-- The zero-benchmark conclusion also holds for the minimum taken separately +at each complete seed, before any expectation. -/ +theorem hiddenWorstReward_eq_zero {n bits : ℕ} (M : Matroid (Fin n)) + (A : HiddenRule n bits) (w : Weights n) (hw : ∀ e, 0 ≤ w e) + (hA : ∀ r π, M.Indep (hiddenAcceptedThrough A r w π n : Set (Fin n))) + (hopt : optimum M w = 0) (r : Seed bits) : + hiddenWorstReward A w r = 0 := by + apply le_antisymm + · exact (hiddenWorstReward_le A w r (Equiv.refl _)).trans_eq + (hiddenReward_eq_zero M A r w (Equiv.refl _) hw (hA r _) hopt) + · exact hiddenWorstReward_nonneg A w hw r + +/-- No probability-law or moment premise is needed in the zero case. -/ +theorem integral_hiddenWorstReward_eq_zero {n bits : ℕ} (M : Matroid (Fin n)) + (A : HiddenRule n bits) (w : Weights n) (hw : ∀ e, 0 ≤ w e) + (hA : ∀ r π, M.Indep (hiddenAcceptedThrough A r w π n : Set (Fin n))) + (hopt : optimum M w = 0) (ν : Measure (Seed bits)) : + (∫ r, hiddenWorstReward A w r ∂ν) = 0 := by + simp only [hiddenWorstReward_eq_zero M A w hw hA hopt] + exact integral_zero _ _ + +/-- Even completely unrestricted loop coordinates cannot create a moment +requirement when the usable coordinates vanish almost everywhere. -/ +theorem integrable_optimum_of_usable_coordinates_zero {n : ℕ} + (M : Matroid (Fin n)) {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (V : Ω → Weights n) + (hV : ∀ᵐ ω ∂μ, ∀ e, M.Indep ({e} : Set (Fin n)) → V ω e = 0) : + Integrable (fun ω => optimum M (V ω)) μ := by + apply (integrable_zero Ω ℝ μ).congr + filter_upwards [hV] with ω hω + symm + rw [optimum_congr_on_singletons M (V ω) (fun _ => 0) hω] + exact optimum_zero M + + +theorem integral_optimum_of_usable_coordinates_zero {n : ℕ} + (M : Matroid (Fin n)) {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (V : Ω → Weights n) + (hV : ∀ᵐ ω ∂μ, ∀ e, M.Indep ({e} : Set (Fin n)) → V ω e = 0) : + (∫ ω, optimum M (V ω) ∂μ) = 0 := by + calc + (∫ ω, optimum M (V ω) ∂μ) = ∫ _ : Ω, (0 : ℝ) ∂μ := by + apply integral_congr_ae + filter_upwards [hV] with ω hω + rw [optimum_congr_on_singletons M (V ω) (fun _ => 0) hω] + exact optimum_zero M + _ = 0 := integral_zero _ _ + +end MatroidProphet.ZeroBenchmark + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/AmbientGram.lean b/lean/OAI/Probability/MemoryPrecision/AmbientGram.lean new file mode 100644 index 0000000000000000000000000000000000000000..8ab96209f13973f367f2381d02db74e091a3e982 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/AmbientGram.lean @@ -0,0 +1,664 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + + +open MeasureTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision + +abbrev Space (d : ℕ) := EuclideanSpace ℝ (Fin d) + +def J (β : ℝ) (m j : ℕ) : ℝ := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let three : ℝ := @OfNat.ofNat ℝ 3 (@instOfNatAtLeastTwo ℝ 3 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 1))) + 1 + three^j * two^β * (m : ℝ) / (β - (j : ℝ) - (m : ℝ)) + +def AmbientBallBound {d : ℕ} (μ : Measure (Space d)) (H β : ℝ) : Prop := + ∀ x : Space d, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H * r^β) + +def InverseGram {d p : ℕ} (m : ℕ) (v : Space d × (Fin (p-1) → Space d)) : ℝ≥0∞ := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + letI : AddCommGroup (Space d) := WithLp.instAddCommGroup exponent (Fin d → ℝ) + letI : Inner ℝ (Space d) := @InnerProductSpace.toInner ℝ (Space d) _ + (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ)) + ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ (fun i => v.2 i - v.1)).det)⁻¹ ^ m) + +lemma sharp_inverse_unit {X : Type*} [MeasurableSpace X] + (μ : Measure X) (f : X → ℝ) (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) + {m a C : ℝ} (hm : 0 < m) (ha : m < a) (hC : 0 ≤ C) + (htube : ∀ t : ℝ, 0 < t → t ≤ 1 → + μ {x | f x ≤ t} ≤ ENNReal.ofReal (C * t^a)) : + (∫⁻ x, ENNReal.ofReal (f x ^ (-m)) ∂μ) ≤ + μ univ + ENNReal.ofReal (C * m / (a-m)) := by + have htail (t : ℝ) (ht : 1 < t) : + μ {x | t < f x ^ (-m)} ≤ ENNReal.ofReal (C * t ^ (-a/m)) := by + have ht0 : 0 < t := by linarith + have hr0 : 0 < t ^ ((-m)⁻¹) := Real.rpow_pos_of_pos ht0 _ + have hr1 : t ^ ((-m)⁻¹) ≤ 1 := by + calc + _ ≤ t ^ (0 : ℝ) := Real.rpow_le_rpow_of_exponent_le ht.le (inv_nonpos.mpr (by linarith)) + _ = 1 := Real.rpow_zero _ + have hsub : {x | t < f x ^ (-m)} ⊆ {x | f x ≤ t ^ ((-m)⁻¹)} := by + intro x hx + have hfx : 0 < f x := by + by_contra h + have heq : f x = 0 := le_antisymm (le_of_not_gt h) (hf0 x) + simp only [mem_ofPred_eq, heq, Real.zero_rpow (neg_ne_zero.mpr hm.ne')] at hx + linarith + exact ((Real.lt_rpow_inv_iff_of_neg hfx ht0 (by linarith)).2 hx).le + calc + _ ≤ μ {x | f x ≤ t ^ ((-m)⁻¹)} := measure_mono hsub + _ ≤ ENNReal.ofReal (C * (t ^ ((-m)⁻¹)) ^ a) := htube _ hr0 hr1 + _ = _ := by + rw [← Real.rpow_mul ht0.le] + congr 2 + ring_nf + have hb : -a/m < -1 := by + rw [div_lt_iff₀ hm] + linarith + have hint : IntegrableOn (fun t : ℝ => C * t ^ (-a/m)) (Ioi 1) := + (integrableOn_Ioi_rpow_of_lt hb (by norm_num)).const_mul C + have hnn : 0 ≤ᵐ[volume.restrict (Ioi (1:ℝ))] (fun t : ℝ => C * t ^ (-a/m)) := by + filter_upwards [ae_restrict_mem (μ := (volume : Measure ℝ)) measurableSet_Ioi] with t ht + exact mul_nonneg hC (Real.rpow_nonneg (by have ht' : (1:ℝ) < t := ht; linarith : 0 ≤ t) _) + have htailint : (∫⁻ t in Ioi (1:ℝ), ENNReal.ofReal (C * t ^ (-a/m))) = + ENNReal.ofReal (C * m / (a-m)) := by + rw [← ofReal_integral_eq_lintegral_ofReal hint hnn, integral_const_mul, + integral_Ioi_rpow_of_lt hb (by norm_num), Real.one_rpow] + congr 1 + field_simp [hm.ne', show a - m ≠ 0 by linarith, show -a + m ≠ 0 by linarith] + ring + have hsplit : Ioi (0:ℝ) = Ioc 0 1 ∪ Ioi 1 := by + ext t + simp only [mem_Ioi, mem_union, mem_Ioc] + constructor + · intro ht + by_cases h : t ≤ 1 + · exact Or.inl ⟨ht,h⟩ + · exact Or.inr (lt_of_not_ge h) + · rintro (⟨ht,_⟩ | ht) <;> linarith + rw [lintegral_eq_lintegral_meas_lt μ + (Filter.Eventually.of_forall fun x => Real.rpow_nonneg (hf0 x) _) (hf.pow_const _).aemeasurable, + hsplit] + apply (lintegral_union_le _ _ _).trans + apply add_le_add + · calc + _ ≤ ∫⁻ _t in Ioc (0:ℝ) 1, μ univ := lintegral_mono fun t => measure_mono (subset_univ _) + _ = μ univ := by simp [Real.volume_Ioc] + · calc + _ ≤ ∫⁻ t in Ioi (1:ℝ), ENNReal.ofReal (C * t ^ (-a/m)) := by + apply lintegral_mono_ae + filter_upwards [ae_restrict_mem (μ := (volume : Measure ℝ)) measurableSet_Ioi] with t ht + exact htail t ht + _ = _ := htailint + +lemma ae_pos_of_power_tube {X : Type*} [MeasurableSpace X] + (μ : Measure X) (f : X → ℝ) {a C : ℝ} (ha : 0 < a) + (htube : ∀ t : ℝ, 0 < t → t ≤ 1 → + μ {x | f x ≤ t} ≤ ENNReal.ofReal (C * t^a)) : ∀ᵐ x ∂μ, 0 < f x := by + have hb (n : ℕ) : μ {x | f x ≤ 0} ≤ ENNReal.ofReal (C * ((1/2 : ℝ)^n)^a) := by + calc + μ {x | f x ≤ 0} ≤ μ {x | f x ≤ (1/2 : ℝ)^n} := + measure_mono fun x hx => (show f x ≤ 0 from hx).trans (by positivity) + _ ≤ _ := htube _ (by positivity) (pow_le_one₀ (by norm_num) (by norm_num)) + have hlim : Tendsto (fun n : ℕ => ENNReal.ofReal (C * ((1/2 : ℝ)^n)^a)) atTop (𝓝 (0:ℝ≥0∞)) := by + have h := (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : (0:ℝ) ≤ 1/2) + (by norm_num : (1/2:ℝ) < 1)).rpow_const_nhds_zero ha + simpa using ENNReal.tendsto_ofReal (tendsto_const_nhds.mul h) + have hz := le_antisymm (ge_of_tendsto' hlim hb) (bot_le : (0:ℝ≥0∞) ≤ μ {x | f x ≤ 0}) + simpa only [ae_iff, not_lt] using hz + +lemma sharp_inverse_scaled {X : Type*} [MeasurableSpace X] + (μ : Measure X) (f : X → ℝ) (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) + {m a B C R : ℝ} (hm : 0 < m) (ha : m < a) + (hB : 0 ≤ B) (hC : 0 ≤ C) (hR : 0 < R) + (hmass : μ univ ≤ ENNReal.ofReal B) + (htube : ∀ t : ℝ, 0 < t → t ≤ 1 → + μ {x | f x ≤ R*t} ≤ ENNReal.ofReal (C * t^a)) : + (∀ᵐ x ∂μ, 0 < f x) ∧ + (∫⁻ x, (ENNReal.ofReal (f x)) ^ (-m) ∂μ) ≤ + ENNReal.ofReal ((B + C*m/(a-m)) * R^(-m)) := by + have hg0 (x : X) : 0 ≤ f x / R := div_nonneg (hf0 x) hR.le + have hg : Measurable (fun x => f x / R) := hf.div_const R + have hgtube (t : ℝ) (ht : 0 < t) (ht1 : t ≤ 1) : + μ {x | f x / R ≤ t} ≤ ENNReal.ofReal (C*t^a) := by + have heq : {x | f x / R ≤ t} = {x | f x ≤ R*t} := by + ext x + simp only [mem_ofPred_eq, div_le_iff₀ hR, mul_comm] + rw [heq] + exact htube t ht ht1 + have hgp := ae_pos_of_power_tube μ (fun x => f x / R) (hm.trans ha) hgtube + have hfp : ∀ᵐ x ∂μ, 0 < f x := by + filter_upwards [hgp] with x hx + exact (div_pos_iff_of_pos_right hR).mp hx + refine ⟨hfp, ?_⟩ + have hi := sharp_inverse_unit μ (fun x => f x/R) hg hg0 hm ha hC hgtube + have hcpos : 0 < R^(-m) := Real.rpow_pos_of_pos hR _ + calc + _ = ∫⁻ x, ENNReal.ofReal (R^(-m)) * ENNReal.ofReal ((f x/R)^(-m)) ∂μ := by + apply lintegral_congr_ae + filter_upwards [hfp] with x hx + rw [ENNReal.ofReal_rpow_of_pos hx, ← ENNReal.ofReal_mul hcpos.le, + Real.div_rpow hx.le hR.le] + congr 1 + exact (mul_div_cancel₀ _ hcpos.ne').symm + _ = ENNReal.ofReal (R^(-m)) * (∫⁻ x, ENNReal.ofReal ((f x/R)^(-m)) ∂μ) := + lintegral_const_mul _ (hg.pow_const _).ennreal_ofReal + _ ≤ ENNReal.ofReal (R^(-m)) * + (ENNReal.ofReal B + ENNReal.ofReal (C*m/(a-m))) := + mul_le_mul' le_rfl (hi.trans (add_le_add hmass le_rfl)) + _ = _ := by + rw [← ENNReal.ofReal_add hB (by positivity), ← ENNReal.ofReal_mul hcpos.le] + congr 1 + ring + +section Geometry +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma affine_tube_cover_radius (L : AffineSubspace ℝ E) [Nonempty L] + (z : E) {R t : ℝ} (hR : 0 < R) (ht : 0 < t) (htR : t ≤ R) : + ∃ s : Finset L.direction, + (s.card : ℝ) ≤ (3*R/t)^Module.finrank ℝ L.direction ∧ + ∀ x : E, dist x z ≤ R → Metric.infDist x L ≤ t → + ∃ y ∈ s, dist x (R • (y:E) + (orthogonalProjection L z : E)) ≤ 2*t := by + classical + have hr : 0 < t/R := div_pos ht hR + have hr1 : t/R ≤ 1 := (div_le_one hR).2 htR + obtain ⟨s, _, hcard, hnet⟩ := NoiselessRegression.exists_unit_ball_net + (E := L.direction) hr hr1 + refine ⟨s, ?_, ?_⟩ + · convert hcard using 1 + congr 1 + field_simp + · intro x hx hdist + let v : L.direction := L.direction.orthogonalProjectionOnto (x-z) + have hv : ‖v‖ ≤ R := by + apply (L.direction.norm_orthogonalProjectionOnto_apply_le (x-z)).trans + simpa only [dist_eq_norm] using hx + have hvnorm : ‖R⁻¹ • v‖ ≤ 1 := by + rw [norm_smul, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr hR)] + calc + _ ≤ R⁻¹ * R := mul_le_mul_of_nonneg_left hv (inv_nonneg.mpr hR.le) + _ = 1 := inv_mul_cancel₀ hR.ne' + obtain ⟨y, hy, hclose⟩ := hnet (R⁻¹ • v) hvnorm + refine ⟨y, hy, ?_⟩ + have hscaled : dist (v:E) (R • (y:E)) ≤ t := by + have heq : (v:E) = R • (R⁻¹ • (v:E)) := by simp [smul_smul, hR.ne'] + rw [heq, dist_smul₀, Real.norm_eq_abs, abs_of_pos hR] + calc + _ ≤ R * (t/R) := mul_le_mul_of_nonneg_left hclose hR.le + _ = t := mul_div_cancel₀ _ hR.ne' + have hproj : (orthogonalProjection L x : E) = + (v:E) + (orthogonalProjection L z : E) := by + have h := (orthogonalProjection L).map_vadd z (x-z) + simpa only [vadd_eq_add, sub_add_cancel, orthogonalProjection_contLinear, + AffineSubspace.coe_vadd] using congrArg (fun q : L => (q:E)) h + have hpd : dist (orthogonalProjection L x : E) + (R • (y:E) + (orthogonalProjection L z : E)) ≤ t := by + rw [hproj, dist_add_right] + exact hscaled + have hxp : dist x (orthogonalProjection L x : E) ≤ t := by + rwa [dist_orthogonalProjection_eq_infDist] + calc + _ ≤ dist x (orthogonalProjection L x : E) + + dist (orthogonalProjection L x : E) (R • (y:E) + (orthogonalProjection L z : E)) := + dist_triangle _ _ _ + _ ≤ t+t := add_le_add hxp hpd + _ = 2*t := by ring + +end Geometry + +section AmbientMoments +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma ambient_tube_radius_factors (j : ℕ) (β : ℝ) {R t : ℝ} (ht : 0 < t) : + (3*R/t)^j * (2*t)^β = (3:ℝ)^j * (2:ℝ)^β * R^j * t^(β-(j:ℝ)) := by + rw [div_pow, mul_pow, Real.mul_rpow (by norm_num) ht.le, + Real.rpow_sub_natCast ht.ne'] + ring + +lemma ambient_tube {μ : Measure E} {H β R : ℝ} {z : E} + (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + (L : AffineSubspace ℝ E) [Nonempty L] {t : ℝ} (ht : 0 < t) (htR : t ≤ R) : + μ {x | Metric.infDist x L ≤ t} ≤ ENNReal.ofReal + ((3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H * + R^Module.finrank ℝ L.direction * t^(β-(Module.finrank ℝ L.direction:ℝ))) := by + classical + obtain ⟨s, hcard, hcover⟩ := affine_tube_cover_radius L z hR ht htR + let c : L.direction → E := fun y => R • (y:E) + (orthogonalProjection L z : E) + have hsub : {x | Metric.infDist x L ≤ t} ≤ᵐ[μ] + ⋃ y ∈ s, Metric.closedBall (c y) (2*t) := by + filter_upwards [μ.support_mem_ae] with x hx + intro hxL + have hxR : dist x z ≤ R := hsupport hx + obtain ⟨y, hy, hxy⟩ := hcover x hxR hxL + exact mem_iUnion₂.mpr ⟨y, hy, hxy⟩ + calc + _ ≤ μ (⋃ y ∈ s, Metric.closedBall (c y) (2*t)) := measure_mono_ae hsub + _ ≤ ∑ y ∈ s, μ (Metric.closedBall (c y) (2*t)) := measure_biUnion_finset_le _ _ + _ ≤ ∑ _y ∈ s, ENNReal.ofReal (H*(2*t)^β) := + Finset.sum_le_sum fun y _ => hball (c y) _ (by positivity) + _ = (s.card : ℝ≥0∞) * ENNReal.ofReal (H*(2*t)^β) := by simp + _ ≤ ENNReal.ofReal ((3*R/t)^Module.finrank ℝ L.direction) * + ENNReal.ofReal (H*(2*t)^β) := by + gcongr + exact_mod_cast ENNReal.ofReal_le_ofReal hcard + _ = _ := by + rw [← ENNReal.ofReal_mul (by positivity)] + congr 1 + calc + _ = H * ((3*R/t)^Module.finrank ℝ L.direction * (2*t)^β) := by ring + _ = _ := by rw [ambient_tube_radius_factors _ _ ht]; ring + +omit [BorelSpace E] in +lemma ambient_mass_bound {μ : Measure E} {H β R : ℝ} {z : E} + (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) : + μ univ ≤ ENNReal.ofReal (H * R^β) := by + calc + _ ≤ μ (Metric.closedBall z R) := by + apply measure_mono_ae + filter_upwards [μ.support_mem_ae] with x hx + intro _ + exact hsupport hx + _ ≤ _ := hball z R hR + +lemma ambient_tube_scaled {μ : Measure E} {H β R : ℝ} {z : E} + (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + (L : AffineSubspace ℝ E) [Nonempty L] {t : ℝ} (ht : 0 < t) (ht1 : t ≤ 1) : + μ {x | Metric.infDist x L ≤ R*t} ≤ ENNReal.ofReal + (((3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H * R^β) * + t^(β-(Module.finrank ℝ L.direction:ℝ))) := by + refine (ambient_tube hR hsupport hball L (mul_pos hR ht) + (by nlinarith)).trans_eq ?_ + congr 1 + rw [Real.mul_rpow hR.le ht.le] + have heq : R^Module.finrank ℝ L.direction * R^(β-(Module.finrank ℝ L.direction:ℝ)) = R^β := by + rw [← Real.rpow_natCast, ← Real.rpow_add hR] + congr 1 + ring + calc + _ = ((3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H) * + (R^Module.finrank ℝ L.direction * R^(β-(Module.finrank ℝ L.direction:ℝ))) * + t^(β-(Module.finrank ℝ L.direction:ℝ)) := by ring + _ = _ := by rw [heq] + +lemma ambient_inverse_moment {μ : Measure E} {H β R : ℝ} {z : E} + (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + (L : AffineSubspace ℝ E) [Nonempty L] {m : ℕ} (hm : 0 < m) + (hgap : (Module.finrank ℝ L.direction:ℝ) + (m:ℝ) < β) : + (∀ᵐ x ∂μ, 0 < Metric.infDist x L) ∧ + (∫⁻ x, (ENNReal.ofReal (Metric.infDist x L)) ^ (-(m:ℝ)) ∂μ) ≤ + ENNReal.ofReal (J β m (Module.finrank ℝ L.direction) * H * R^(β-(m:ℝ))) := by + have hm' : (0:ℝ) < m := by exact_mod_cast hm + have hi := sharp_inverse_scaled μ (fun x => Metric.infDist x L) + (Metric.continuous_infDist_pt _).measurable (fun _ => Metric.infDist_nonneg) + hm' (show (m:ℝ) < β-(Module.finrank ℝ L.direction:ℝ) by linarith) + (show 0 ≤ H*R^β by positivity) + (show 0 ≤ (3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H * R^β by positivity) + hR (ambient_mass_bound hR hsupport hball) + (fun t ht ht1 => ambient_tube_scaled hR hsupport hball L ht ht1) + refine ⟨hi.1, hi.2.trans_eq ?_⟩ + congr 1 + have heq : H*R^β + ((3:ℝ)^Module.finrank ℝ L.direction * (2:ℝ)^β * H * R^β) * + (m:ℝ)/(β-(Module.finrank ℝ L.direction:ℝ)-(m:ℝ)) = + J β m (Module.finrank ℝ L.direction) * H * R^β := by + unfold J + ring + rw [heq, mul_assoc, ← Real.rpow_add hR] + congr 2 + +end AmbientMoments + +lemma J_pos {β : ℝ} {m j : ℕ} (hgap : (j:ℝ)+(m:ℝ)<β) : 0 < J β m j := by + unfold J + have hd : 0 < β-(j:ℝ)-(m:ℝ) := by linarith + positivity + +lemma J_mono {β : ℝ} {m j k : ℕ} (hjk : j ≤ k) + (hgap : (k:ℝ)+(m:ℝ)<β) : J β m j ≤ J β m k := by + have hjk' : (j:ℝ) ≤ k := by exact_mod_cast hjk + unfold J + apply add_le_add le_rfl + apply div_le_div₀ + · positivity + · gcongr + norm_num + · linarith + · linarith + +section ReplicaExact +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +open NoiselessRegression InnerProductSpace + +lemma ambient_inverse_moment_le {μ : Measure E} {H β R : ℝ} {z : E} + (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + (L : AffineSubspace ℝ E) [Nonempty L] {m k : ℕ} (hm : 0 < m) + (hdim : Module.finrank ℝ L.direction ≤ k) (hgap : (k:ℝ)+(m:ℝ)<β) : + (∫⁻ x, ENNReal.ofReal ((Metric.infDist x L)⁻¹ ^ m) ∂μ) ≤ + ENNReal.ofReal (J β m k * H * R^(β-(m:ℝ))) := by + have hdim' : (Module.finrank ℝ L.direction:ℝ) ≤ k := by exact_mod_cast hdim + obtain ⟨ha, hi⟩ := ambient_inverse_moment hH hR hsupport hball L hm (by linarith) + calc + _ = ∫⁻ x, (ENNReal.ofReal (Metric.infDist x L)) ^ (-(m:ℝ)) ∂μ := by + apply lintegral_congr_ae + filter_upwards [ha] with x hx + rw [ENNReal.ofReal_rpow_of_pos hx, Real.rpow_neg hx.le, Real.rpow_natCast, inv_pow] + _ ≤ ENNReal.ofReal (J β m (Module.finrank ℝ L.direction) * H * R^(β-(m:ℝ))) := hi + _ ≤ _ := by + apply ENNReal.ofReal_le_ofReal + gcongr + exact J_mono hdim hgap + +lemma replica_integral_exact {μ : Measure E} [IsFiniteMeasure μ] {H β R : ℝ} {z : E} + (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + {m : ℕ} (hm : 0 < m) (p : E) (n : ℕ) + (hgap : (n:ℝ)+(m:ℝ)-1<β) : + (∫⁻ v : Fin n → E, replicaWeight m p v ∂Measure.pi (fun _ => μ)) ≤ + ∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ))) := by + induction n with + | zero => simp [replicaWeight] + | succ n ih => + have hngap : (n:ℝ)+(m:ℝ)<β := by push_cast at hgap; linarith + have hinner (v : Fin n → E) : + (∫⁻ x, replicaWeight m p (Fin.snoc v x) ∂μ) ≤ + replicaWeight m p v * ENNReal.ofReal (J β m n * H * R^(β-(m:ℝ))) := by + simp_rw [replicaWeight_snoc] + rw [lintegral_const_mul _ (by fun_prop)] + apply mul_le_mul' le_rfl + apply ambient_inverse_moment_le hH hR hsupport hball _ hm _ hngap + rw [AffineSubspace.direction_mk'] + simpa only [Fintype.card_fin, Set.finrank] using + finrank_range_le_card (R := ℝ) (fun i : Fin n => v i - p) + calc + _ = ∫⁻ v : Fin n → E, ∫⁻ x, replicaWeight m p (Fin.snoc v x) ∂μ + ∂Measure.pi (fun _ => μ) := lintegral_pi_snoc μ _ (measurable_replicaWeight m p (n+1)) + _ ≤ ∫⁻ v : Fin n → E, replicaWeight m p v * + ENNReal.ofReal (J β m n * H * R^(β-(m:ℝ))) ∂Measure.pi (fun _ => μ) := + lintegral_mono hinner + _ = (∫⁻ v : Fin n → E, replicaWeight m p v ∂Measure.pi (fun _ => μ)) * + ENNReal.ofReal (J β m n * H * R^(β-(m:ℝ))) := + lintegral_mul_const _ (measurable_replicaWeight m p n) + _ ≤ (∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ)))) * + ENNReal.ofReal (J β m n * H * R^(β-(m:ℝ))) := + mul_le_mul' (ih (by linarith)) le_rfl + _ = _ := by rw [Fin.prod_univ_castSucc]; rfl + +lemma ae_replica_nondegenerate_exact {μ : Measure E} [IsFiniteMeasure μ] {H β R : ℝ} {z : E} + (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + {m : ℕ} (hm : 0 < m) (p : E) (n : ℕ) + (hgap : (n:ℝ)+(m:ℝ)-1<β) : + ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => μ), + ∀ i, gramSchmidt ℝ (fun j => v j-p) i ≠ 0 := by + induction n with + | zero => exact Filter.Eventually.of_forall fun _ i => Fin.elim0 i + | succ n ih => + rw [ae_pi_snoc μ (measurableSet_gramSchmidt_ne_zero p (n+1))] + have hngap : (n:ℝ)+(m:ℝ)<β := by push_cast at hgap; linarith + filter_upwards [ih (by linarith)] with v hv + let L := AffineSubspace.mk' p (Submodule.span ℝ (Set.range (fun i : Fin n => v i-p))) + have hdim : (Module.finrank ℝ L.direction:ℝ) ≤ n := by + dsimp [L] + rw [AffineSubspace.direction_mk'] + have hh := finrank_range_le_card (R := ℝ) (fun i : Fin n => v i-p) + simp only [Fintype.card_fin, Set.finrank] at hh + exact_mod_cast hh + have ha := (ambient_inverse_moment hH hR hsupport hball L hm (by linarith)).1 + filter_upwards [ha] with x hx + intro i + induction i using Fin.lastCases with + | last => + apply norm_ne_zero_iff.mp + rw [norm_gramSchmidt_sub_eq_affine_infDist, image_Iio_last] + simp only [Fin.snoc_castSucc, Fin.snoc_last] + exact hx.ne' + | cast j => simpa only [gramSchmidt_castSucc, Fin.snoc_castSucc] using hv j + +lemma measurable_joint_replicaWeight (m n : ℕ) : + Measurable (fun v : E × (Fin n → E) => replicaWeight m v.1 v.2) := by + have hs : Measurable (fun v : E × (Fin n → E) => fun j => v.2 j-v.1) := by fun_prop + exact Finset.measurable_prod _ fun i _ => + (((measurable_gramSchmidt i).comp hs).norm.inv.pow_const m).ennreal_ofReal + +lemma ae_joint_replica_independent {μ : Measure E} [IsFiniteMeasure μ] {H β R : ℝ} {z : E} + (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + {m : ℕ} (hm : 0 < m) (n : ℕ) + (hgap : (n:ℝ)+(m:ℝ)-1<β) : + ∀ᵐ v : E × (Fin n → E) ∂μ.prod (Measure.pi (fun _ => μ)), + LinearIndependent ℝ (fun j => v.2 j-v.1) := by + have hmeas : MeasurableSet {v : E × (Fin n → E) | + ∀ i, gramSchmidt ℝ (fun j => v.2 j-v.1) i ≠ 0} := by + rw [Set.ofPred_forall] + apply MeasurableSet.iInter + intro i + have h := (measurable_gramSchmidt i).comp + (show Measurable (fun v : E × (Fin n → E) => fun j => v.2 j-v.1) by fun_prop) + exact (measurableSet_eq_fun h measurable_const).compl + have ha : ∀ᵐ v : E × (Fin n → E) ∂μ.prod (Measure.pi (fun _ => μ)), + ∀ i, gramSchmidt ℝ (fun j => v.2 j-v.1) i ≠ 0 := by + rw [Measure.ae_prod_iff_ae_ae hmeas] + exact Filter.Eventually.of_forall fun p => + ae_replica_nondegenerate_exact hH hR hsupport hball hm p n hgap + filter_upwards [ha] with v hv + apply Matrix.linearIndependent_of_det_gram_ne_zero + rw [det_gram_eq_prod_gramSchmidt] + exact Finset.prod_ne_zero_iff.mpr fun i _ => pow_ne_zero _ (norm_ne_zero_iff.mpr (hv i)) + +lemma joint_replica_integral_exact {μ : Measure E} [IsFiniteMeasure μ] {H β R : ℝ} {z : E} + (hH : 0 < H) (hR : 0 < R) (hsupport : μ.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + μ (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + {m : ℕ} (hm : 0 < m) (n : ℕ) + (hgap : (n:ℝ)+(m:ℝ)-1<β) : + (∫⁻ v : E × (Fin n → E), replicaWeight m v.1 v.2 + ∂μ.prod (Measure.pi (fun _ => μ))) ≤ + ENNReal.ofReal (H^(n+1) * R^(β*(n+1:ℕ)-(m:ℝ)*(n:ℝ)) * + ∏ j : Fin n, J β m j) := by + have hJ (j : Fin n) : 0 < J β m j := by + apply J_pos + have hj : (j:ℝ)+1 ≤ n := by exact_mod_cast Nat.succ_le_of_lt j.isLt + linarith + have hfac (j : Fin n) : 0 ≤ J β m j * H * R^(β-(m:ℝ)) := by + exact le_of_lt (mul_pos (mul_pos (hJ j) hH) (Real.rpow_pos_of_pos hR _)) + calc + _ = ∫⁻ p, ∫⁻ v : Fin n → E, replicaWeight m p v + ∂Measure.pi (fun _ => μ) ∂μ := + lintegral_prod _ (measurable_joint_replicaWeight m n).aemeasurable + _ ≤ ∫⁻ _p, ∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ))) ∂μ := + lintegral_mono fun p => replica_integral_exact hH hR hsupport hball hm p n hgap + _ = (∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ)))) * μ univ := + lintegral_const _ + _ ≤ (∏ j : Fin n, ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ)))) * + ENNReal.ofReal (H*R^β) := mul_le_mul' le_rfl (ambient_mass_bound hR hsupport hball) + _ = _ := by + rw [← ENNReal.ofReal_prod_of_nonneg (fun j _ => hfac j), + ← ENNReal.ofReal_mul (Finset.prod_nonneg fun j _ => hfac j)] + congr 1 + simp only [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin] + rw [← Real.rpow_mul_natCast hR.le] + have heq : R^((β-(m:ℝ))*(n:ℝ)) * R^β = + R^(β*(n+1:ℕ)-(m:ℝ)*(n:ℝ)) := by + rw [← Real.rpow_add hR] + congr 1 + push_cast + ring + calc + _ = (H^n*H) * (R^((β-(m:ℝ))*(n:ℝ)) * R^β) * ∏ j : Fin n, J β m j := by ring + _ = _ := by rw [← pow_succ, heq] + +end ReplicaExact + +lemma specialized_J_bound (d m p : ℕ) (hd : 16 ≤ d) (hp : p=d/8) + (_ : 1 ≤ m) (hmp : m ≤ p) (β : ℝ) + (hβlo : ((d:ℝ)-1)/2 ≤ β) (hβhi : β ≤ (d:ℝ)/2) : + ∀ j : ℕ, j ≤ p-2 → + ((d:ℝ)-1)/2 - 2*(p:ℝ) + 2 ≤ β-(j:ℝ)-(m:ℝ) ∧ + (d:ℝ)/4 + 3/2 ≤ ((d:ℝ)-1)/2 - 2*(p:ℝ) + 2 ∧ + J β m j ≤ (7:ℝ)^d := by + have hp2 : 2 ≤ p := by omega + have hp8 : p*8 ≤ d := by rw [hp]; exact Nat.div_mul_le_self d 8 + have hp8' : (p:ℝ)*8 ≤ d := by exact_mod_cast hp8 + have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd + have hm' : (m:ℝ) ≤ p := by exact_mod_cast hmp + intro j hj + have hj' : (j:ℝ)+2 ≤ p := by exact_mod_cast (show j+2 ≤ p by omega) + have hmargin : ((d:ℝ)-1)/2-2*(p:ℝ)+2 ≤ β-(j:ℝ)-(m:ℝ) := by linarith + have hdim : (d:ℝ)/4+3/2 ≤ ((d:ℝ)-1)/2-2*(p:ℝ)+2 := by linarith + refine ⟨hmargin, hdim, ?_⟩ + have hgap : 0 < β-(j:ℝ)-(m:ℝ) := by linarith + have hquot : (m:ℝ)/(β-(j:ℝ)-(m:ℝ)) ≤ 1 := by + rw [div_le_one hgap] + linarith + have h3 : (3:ℝ)^j ≤ (3:ℝ)^d := by + apply pow_le_pow_right₀ (by norm_num) + omega + have h2 : (2:ℝ)^β ≤ (2:ℝ)^d := by + rw [← Real.rpow_natCast] + apply Real.rpow_le_rpow_of_exponent_le (by norm_num) + linarith + calc + J β m j = 1 + (3:ℝ)^j * (2:ℝ)^β * ((m:ℝ)/(β-(j:ℝ)-(m:ℝ))) := by unfold J; ring + _ ≤ 1 + (3:ℝ)^j * (2:ℝ)^β * 1 := by gcongr + _ ≤ 1 + (3:ℝ)^d * (2:ℝ)^d := by rw [mul_one]; gcongr + _ = 1 + (6:ℝ)^d := by rw [← mul_pow]; norm_num + _ ≤ (7:ℝ)^d := by + simpa only [one_pow, show (1:ℝ)+6=7 by norm_num] using pow_add_pow_le (show (0:ℝ) ≤ 1 by norm_num) + (show (0:ℝ) ≤ 6 by norm_num) (show d ≠ 0 by omega) + +lemma specialized_gram_product_bound (d m p : ℕ) (hd : 16 ≤ d) (hp : p=d/8) + (hm : 1 ≤ m) (hmp : m ≤ p) (β : ℝ) + (hβlo : ((d:ℝ)-1)/2 ≤ β) (hβhi : β ≤ (d:ℝ)/2) + (H R : ℝ) (hH : 0 < H) (hR : 0 < R) : + H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) * (∏ j : Fin (p-1), J β m j) ≤ + (7:ℝ)^(d*(p-1)) * H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) := by + have hp2 : 2 ≤ p := by omega + have hs := specialized_J_bound d m p hd hp hm hmp β hβlo hβhi + have hprod : (∏ j : Fin (p-1), J β m j) ≤ (7:ℝ)^(d*(p-1)) := by + calc + _ ≤ ∏ _j : Fin (p-1), (7:ℝ)^d := by + apply Finset.prod_le_prod₀ + · intro j _ + apply (J_pos ?_).le + have hh := hs j (by have := j.isLt; omega) + have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd + linarith [hh.1, hh.2.1] + · intro j _ + exact (hs j (by have := j.isLt; omega)).2.2 + _ = _ := by simp [← pow_mul] + calc + _ ≤ H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) * (7:ℝ)^(d*(p-1)) := by gcongr + _ = _ := by ring + +def AmbientGramStatement : Prop := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let three : ℝ := @OfNat.ofNat ℝ 3 (@instOfNatAtLeastTwo ℝ 3 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 1))) + let four : ℝ := @OfNat.ofNat ℝ 4 (@instOfNatAtLeastTwo ℝ 4 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 2))) + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + (∀ (d m p : ℕ), + letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ) + letI : PseudoMetricSpace (Space d) := + PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ) + letI : AddCommGroup (Space d) := WithLp.instAddCommGroup exponent (Fin d → ℝ) + letI : Module ℝ (Space d) := WithLp.instModule (p := exponent) (K := ℝ) (V := Fin d → ℝ) + 1 ≤ d → 1 ≤ m → 2 ≤ p → + ∀ β R H : ℝ, (m : ℝ) + (p : ℝ) - two < β → 0 < R → 0 < H → + ∀ (μ : Measure (Space d)), IsFiniteMeasure μ → + ∀ z : Space d, μ.support ⊆ Metric.closedBall z R → + AmbientBallBound μ H β → + (∀ (j : ℕ), j ≤ p-2 → ∀ L : AffineSubspace ℝ (Space d), + Nonempty L → Module.finrank ℝ L.direction = j → + (∀ t : ℝ, 0 < t → t ≤ R → + μ {s | Metric.infDist s L ≤ t} ≤ + ENNReal.ofReal (three^j * two^β * H * R^j * t^(β-(j:ℝ)))) ∧ + (∫⁻ s, (ENNReal.ofReal (Metric.infDist s L)) ^ (-(m:ℝ)) ∂μ) ≤ + ENNReal.ofReal (J β m j * H * R^(β-(m:ℝ)))) ∧ + (∀ᵐ v : Space d × (Fin (p-1) → Space d) + ∂μ.prod (Measure.pi (fun _ : Fin (p-1) => μ)), + LinearIndependent ℝ (fun i => v.2 i - v.1)) ∧ + (∫⁻ v : Space d × (Fin (p-1) → Space d), InverseGram m v + ∂μ.prod (Measure.pi (fun _ : Fin (p-1) => μ))) ≤ + ENNReal.ofReal (H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) * + ∏ j : Fin (p-1), J β m j)) ∧ + (∃ C : ℝ, 1 ≤ C ∧ ∀ (d m p : ℕ), 16 ≤ d → p = d/8 → + 1 ≤ m → m ≤ p → ∀ β : ℝ, ((d:ℝ)-1)/two ≤ β → β ≤ (d:ℝ)/two → + (∀ j : ℕ, j ≤ p-2 → + ((d:ℝ)-1)/two - two*(p:ℝ) + two ≤ β-(j:ℝ)-(m:ℝ) ∧ + (d:ℝ)/four + three/two ≤ ((d:ℝ)-1)/two - two*(p:ℝ) + two ∧ + J β m j ≤ C^d) ∧ + (∀ H R : ℝ, 0 < H → 0 < R → + H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)) * (∏ j : Fin (p-1), J β m j) ≤ + C^(d*(p-1)) * H^p * R^(β*(p:ℝ)-(m:ℝ)*(p-1:ℕ)))) + +theorem ambient_gram : AmbientGramStatement := by + constructor + · intro d m p _hd hm hp β R H hβ hR hH μ hfin z hsupport hball + let : IsFiniteMeasure μ := hfin + have hm0 : 0 < m := by omega + have hp1 : 1 ≤ p := by omega + have hgap : ((p-1:ℕ):ℝ)+(m:ℝ)-1<β := by + rw [Nat.cast_sub hp1] + push_cast + linarith + refine ⟨?_, ?_, ?_⟩ + · intro j hj L hnonempty hdim + let : Nonempty L := hnonempty + have hj' : (j:ℝ)+2 ≤ p := by exact_mod_cast (show j+2 ≤ p by omega) + constructor + · intro t ht htR + simpa only [hdim] using ambient_tube hR hsupport hball L ht htR + · have hi := (ambient_inverse_moment hH hR hsupport hball L hm0 + (by rw [hdim]; linarith)).2 + simpa only [hdim] using hi + · exact ae_joint_replica_independent hH hR hsupport hball hm0 (p-1) hgap + · have hi := joint_replica_integral_exact hH hR hsupport hball hm0 (p-1) hgap + simpa only [NoiselessRegression.replicaWeight_eq_det, InverseGram, + Nat.sub_add_cancel hp1] using hi + · refine ⟨7, by norm_num, ?_⟩ + intro d m p hd hp hm hmp β hβlo hβhi + exact ⟨specialized_J_bound d m p hd hp hm hmp β hβlo hβhi, + specialized_gram_product_bound d m p hd hp hm hmp β hβlo hβhi⟩ + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/BallAverages.lean b/lean/OAI/Probability/MemoryPrecision/BallAverages.lean new file mode 100644 index 0000000000000000000000000000000000000000..baf7406018e7725bf24e58d8b2f60099971ec2e8 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/BallAverages.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.RadialMixture + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma gaussianKernel_scale (m : ℕ) {δ : ℝ} (hδ : 0 < δ) (y : Space m) : + GaussianKernel m δ (δ • y) = δ⁻¹ ^ m * GaussianKernel m 1 y := by + have he (a : ℝ) : gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (δ*a) = + δ⁻¹ * gaussianPDFReal 0 1 a := by + have h := gaussianPDFReal_inv_mul (μ := 0) (v := 1) hδ.ne' (δ*a) + simp only [inv_mul_cancel_left₀ hδ.ne', mul_zero, mul_one, abs_of_pos hδ] at h + rw [h] + field_simp + rfl + unfold GaussianKernel + simp only [PiLp.smul_apply, smul_eq_mul, one_pow] + simp_rw [he] + simp only [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin] + rfl + +lemma radialMixture_scale (m : ℕ) {δ : ℝ} (hδ : 0 < δ) (r : ℝ) : + RadialMixture m δ (δ*r) = δ⁻¹ * RadialMixture m 1 r := by + unfold RadialMixture + rw [mul_smul, gaussianKernel_scale m hδ] + simp only [one_pow, div_one, mul_pow, inv_pow] + field_simp + +def BallAverage {m : ℕ} (ν : Measure (Space m)) (y : Space m) (r : ℝ) : ℝ := + (ν (Metric.ball y r)).toReal / (UnitBallVolume m * r^m) + +lemma ballAverage_measurable {m : ℕ} (ν : Measure (Space m)) (y : Space m) : + Measurable (BallAverage ν y) := by + have h : Monotone (fun r : ℝ => ν (Metric.ball y r)) := fun r t h => + measure_mono (Metric.ball_subset_ball h) + exact h.measurable.ennreal_toReal.div (by fun_prop) + +lemma ballAverage_nonneg {m : ℕ} (ν : Measure (Space m)) (y : Space m) {r : ℝ} + (hr : 0 < r) : 0 ≤ BallAverage ν y r := by + exact div_nonneg ENNReal.toReal_nonneg (mul_nonneg (unitBallVolume_pos m).le + (pow_nonneg hr.le _)) + +lemma ac_ball_eq_closedBall {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m)) + (hν : ν ≪ volume) (y : Space m) (r : ℝ) : + ν (Metric.ball y r) = ν (Metric.closedBall y r) := by + have : NeZero m := ⟨by omega⟩ + apply measure_eq_measure_of_null_sdiff Metric.ball_subset_closedBall + rw [Metric.closedBall_sdiff_ball] + exact hν (Measure.addHaar_sphere volume y r) + +lemma ae_tendsto_ballAverage {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m)) + [IsFiniteMeasure ν] (hν : ν ≪ volume) : + ∀ᵐ y ∂(volume : Measure (Space m)), Tendsto (BallAverage ν y) + (𝓝[>] (0:ℝ)) (𝓝 ((ν.rnDeriv volume y).toReal)) := by + have : NeZero m := ⟨by omega⟩ + filter_upwards [Besicovitch.ae_tendsto_rnDeriv ν volume, ν.rnDeriv_lt_top volume] with y hy hyfin + have ht := (ENNReal.continuousAt_toReal hyfin.ne).tendsto.comp hy + apply ht.congr' + filter_upwards [self_mem_nhdsWithin] with r hr + unfold BallAverage + simp only [Function.comp_apply] + rw [ENNReal.toReal_div, Measure.addHaar_closedBall_eq_addHaar_ball volume y r, + ← ac_ball_eq_closedBall hm ν hν y r, volume_ball_eq m hm y hr, + ENNReal.toReal_ofReal (mul_nonneg (unitBallVolume_pos m).le (pow_nonneg hr.le _))] + +lemma ballAverage_bounded {m : ℕ} (ν : Measure (Space m)) [IsFiniteMeasure ν] + (y : Space m) {f : ℝ} (hf : 0 ≤ f) + (ht : Tendsto (BallAverage ν y) (𝓝[>] (0:ℝ)) (𝓝 f)) : + ∃ B : ℝ, 0 ≤ B ∧ ∀ r : ℝ, 0 < r → ‖BallAverage ν y r‖ ≤ B := by + rcases Metric.tendsto_nhdsWithin_nhds.mp ht 1 zero_lt_one with ⟨b,hb,hnear⟩ + let C : ℝ := max (f+1) ((ν Set.univ).toReal / (UnitBallVolume m * b^m)) + refine ⟨C, le_trans (by linarith : 0 ≤ f+1) (le_max_left _ _), ?_⟩ + intro r hr + rw [Real.norm_eq_abs, abs_of_nonneg (ballAverage_nonneg ν y hr)] + by_cases h : r < b + · have he := hnear hr (by simpa [Real.dist_eq, abs_of_pos hr] using h) + have he' : BallAverage ν y r < f+1 := by + rw [Real.dist_eq] at he + have := (abs_lt.mp he).2 + linarith + exact he'.le.trans (le_max_left _ _) + · apply le_trans ?_ (le_max_right _ _) + unfold BallAverage + have hvol : 0 < UnitBallVolume m := unitBallVolume_pos m + apply div_le_div₀ (by positivity) ?_ (by positivity) ?_ + · exact (ENNReal.toReal_le_toReal (measure_ne_top _ _) (measure_ne_top _ _)).mpr + (measure_mono (Set.subset_univ _)) + · exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ hb.le (le_of_not_gt h) _) + (unitBallVolume_pos m).le + +lemma tendsto_radial_average {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m)) [IsFiniteMeasure ν] + (y : Space m) {f : ℝ} (hf : 0 ≤ f) + (ht : Tendsto (BallAverage ν y) (𝓝[>] (0:ℝ)) (𝓝 f)) : + Tendsto (fun δ : ℝ => ∫ r in Ioi 0, RadialMixture m 1 r * BallAverage ν y (δ*r)) + (𝓝[>] (0:ℝ)) (𝓝 f) := by + obtain ⟨B,hB,hbound⟩ := ballAverage_bounded ν y hf ht + have hw : IntegrableOn (RadialMixture m 1) (Ioi 0) := + integrable_of_integral_eq_one (radialMixture_integral m hm zero_lt_one) + have hl := tendsto_integral_filter_of_dominated_convergence + (μ := volume.restrict (Ioi 0)) (l := 𝓝[>] (0:ℝ)) + (F := fun δ r => RadialMixture m 1 r * BallAverage ν y (δ*r)) + (f := fun r => RadialMixture m 1 r * f) + (fun r => RadialMixture m 1 r * B) + (Eventually.of_forall (fun δ => + ((radialMixture_measurable m 1).mul ((ballAverage_measurable ν y).comp + (by fun_prop))).aestronglyMeasurable)) + (show ∀ᶠ δ in 𝓝[>] (0:ℝ), ∀ᵐ r ∂volume.restrict (Ioi 0), + ‖RadialMixture m 1 r * BallAverage ν y (δ*r)‖ ≤ RadialMixture m 1 r * B from by + filter_upwards [self_mem_nhdsWithin] with δ hδ + filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr + rw [norm_mul, Real.norm_eq_abs, abs_of_nonneg (radialMixture_nonneg m 1 hr)] + exact mul_le_mul_of_nonneg_left (hbound _ (mul_pos hδ hr)) (radialMixture_nonneg m 1 hr)) + (hw.mul_const B) (show ∀ᵐ r ∂volume.restrict (Ioi 0), + Tendsto (fun δ => RadialMixture m 1 r * BallAverage ν y (δ*r)) + (𝓝[>] (0:ℝ)) (𝓝 (RadialMixture m 1 r * f)) from by + filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr + apply Tendsto.const_mul + apply ht.comp + apply tendsto_nhdsWithin_iff.mpr + refine ⟨?_, ?_⟩ + · simpa using ((continuous_id.mul_const r).tendsto (0:ℝ)).mono_left nhdsWithin_le_nhds + · filter_upwards [self_mem_nhdsWithin] with δ hδ + change 0 < δ*r + exact mul_pos hδ hr) + simpa only [integral_mul_const, radialMixture_integral m hm zero_lt_one, one_mul] using hl +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/CoefficientStep.lean b/lean/OAI/Probability/MemoryPrecision/CoefficientStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..36cfbba049b294589e23aaf4313406ec5f6c6d99 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/CoefficientStep.lean @@ -0,0 +1,81 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelModel +import OAI.Probability.MemoryPrecision.WeightedImage +import OAI.Probability.MemoryPrecision.WeightedSelection + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +abbrev Sphere (d : ℕ) := Metric.sphere (0 : Space d) 1 +def SpherePrior (d : ℕ) : Measure (Sphere d) := + MemoryPrecision.Kernel.UniformSphere d + +def SphereBallBound {d : ℕ} (h : Sphere d → ℝ≥0∞) (H α : ℝ) : Prop := + ∀ z : Space d, ∀ r : ℝ, 0 < r → + (∫⁻ s in {s : Sphere d | dist s.val z ≤ r}, h s ∂SpherePrior d) ≤ + ENNReal.ofReal (H * r^α) +def SphereBlock {d m N : ℕ} (h : Fin N → Sphere d → ℝ≥0∞) + (g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞) + (s : Sphere d) : ℝ≥0∞ := + WeightedBlock Subtype.val h g s +def CoefficientStepStatement : Prop := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + ∃ C : ℝ, 1 ≤ C ∧ ∀ d m N : ℕ, 16 ≤ d → + 1 ≤ m → m ≤ d/8 → 1 ≤ N → + ∀ α H : ℝ, ((d:ℝ)-1)/two ≤ α → α ≤ (d:ℝ)/two → 0 < H → + ∀ h : Fin N → Sphere d → ℝ≥0∞, + (∀ w, Measurable (h w)) → (∀ w s, h w s ≤ 1) → + (∀ w, SphereBallBound (h w) H α) → + ∀ g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞, + (∀ w, Measurable (g w)) → (∀ x, ∑ w, g w x ≤ 1) → + SphereBallBound (SphereBlock h g) (C^d * (N:ℝ)^(1/((d/8:ℕ):ℝ)) * H) α + +theorem coefficient_step : CoefficientStepStatement := by + refine ⟨1344, by norm_num, ?_⟩ + intro d m N hd hm hmp hN α H hαlo hαhi hH h hh hh1 hb g hg hgsum z r hr + have : NeZero d := ⟨by omega⟩ + have : IsProbabilityMeasure (SpherePrior d) := + (show IsProbabilityMeasure (NoiselessRegression.sphereLaw (E := Space d)) from inferInstance) + let ν (w : Fin N) := ((SpherePrior d).withDensity (h w)).map Subtype.val + let (w : Fin N) : IsFiniteMeasure (ν w) := + weighted_image_finite (SpherePrior d) Subtype.val (h w) (hh1 w) + have hν (w) : AmbientBallBound (ν w) H α := by + intro x ρ hρ + rw [show ν w = ((SpherePrior d).withDensity (h w)).map Subtype.val from rfl, + weighted_image_ball _ measurable_subtype_coe] + exact hb w x ρ hρ + have hp : 2 ≤ d/8 := by omega + have hmd : m ≤ d := hmp.trans (Nat.div_le_self _ _) + have hgap : (m:ℝ)+((d/8:ℕ):ℝ)-2 < α := by + have hm' : (m:ℝ) ≤ (d/8:ℕ) := by exact_mod_cast hmp + have hp' : ((d/8:ℕ):ℝ)*8 ≤ d := by exact_mod_cast Nat.div_mul_le_self d 8 + have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd + linarith + have hJ := fun j hj => (specialized_J_bound d m (d/8) hd rfl hm hmp α hαlo hαhi j hj).2.2 + have hsel := localized_weighted_selection ν hp hm hmd (by norm_num : (1:ℝ) ≤ 7) + hH hgap hJ hν g hg hgsum z hr + have he := weightedBlock_mass_identity (SpherePrior d) measurable_subtype_coe hh hh1 hg + (show MeasurableSet (Metric.closedBall z r) from Metric.isClosed_closedBall.measurableSet) + change (∫⁻ s in Subtype.val ⁻¹' Metric.closedBall z r, + WeightedBlock Subtype.val h g s ∂SpherePrior d) ≤ _ + rw [he] + convert hsel using 1 + norm_num [ν, mul_assoc] + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/CubeArithmetic.lean b/lean/OAI/Probability/MemoryPrecision/CubeArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..16735384e7fa4548414ac11ffdc644985bc6ac09 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/CubeArithmetic.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeContinuation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision + +lemma cube_memory_ratio {d M : ℕ} (hd : 16 ≤ d) (hM : M ≤ d^2) : + (M:ℝ) / (((d/2)/4:ℕ):ℝ) ≤ 72 * (d/2:ℕ) := by + have hd3 : d ≤ 3*(d/2) := by omega + have hn8 : d/2 ≤ 8*((d/2)/4) := by omega + have hm : M ≤ (72*(d/2))*((d/2)/4) := by + calc + M ≤ d^2 := hM + _ ≤ (3*(d/2))^2 := Nat.pow_le_pow_left hd3 2 + _ = 9*(d/2)*(d/2) := by ring + _ ≤ 9*(d/2)*(8*((d/2)/4)) := Nat.mul_le_mul_left _ hn8 + _ = _ := by ring + apply (div_le_iff₀ (by exact_mod_cast (show 0 < (d/2)/4 by omega))).2 + exact_mod_cast hm + +lemma cube_memory_factor {d M : ℕ} (hd : 16 ≤ d) (hM : M ≤ d^2) : + ((2^M:ℕ):ℝ)^(1/(((d/2)/4:ℕ):ℝ)) ≤ ((2:ℝ)^72)^(d/2) := by + have he : ((2^M:ℕ):ℝ)^(1/(((d/2)/4:ℕ):ℝ)) = + (2:ℝ)^((M:ℝ)/(((d/2)/4:ℕ):ℝ)) := by + rw [Nat.cast_pow, Nat.cast_ofNat, ← Real.rpow_natCast, + ← Real.rpow_mul (by norm_num : (0:ℝ) ≤ 2)] + congr 1 + ring + rw [he, ← pow_mul, ← Real.rpow_natCast] + apply Real.rpow_le_rpow_of_exponent_le (by norm_num : (1:ℝ) ≤ 2) + simpa using cube_memory_ratio hd hM + +lemma cube_stopping_factor {d : ℕ} (hd : 16 ≤ d) (T : ℕ) : + (T+1:ℝ) ≤ ((2:ℝ)^(d/2))^BlockCount T ((d/2)/4) := by + have hT := blockCount_mul_ge T (by omega : 0 < (d/2)/4) + have hp : (d/2)/4 ≤ d/2 := Nat.div_le_self _ _ + have hTn : T ≤ (d/2) * BlockCount T ((d/2)/4) := by nlinarith + have htwo : (T+1:ℕ) ≤ 2^T := Nat.lt_two_pow_self + have hpow : (2:ℝ)^T ≤ 2^((d/2) * BlockCount T ((d/2)/4)) := + pow_le_pow_right₀ (by norm_num) hTn + rw [pow_mul] at hpow + exact (by exact_mod_cast htwo : (T+1:ℝ) ≤ (2:ℝ)^T).trans hpow + +def CubeSuccessConstant : ℝ := max 12 (2*CubeStepConstant*2^72) +lemma cubeSuccessConstant_twelve : 12 ≤ CubeSuccessConstant := le_max_left _ _ +lemma cubeSuccessConstant_one : 1 ≤ CubeSuccessConstant := + (by norm_num : (1:ℝ) ≤ 12).trans cubeSuccessConstant_twelve +lemma cubeSuccessConstant_exp : Real.exp 1 ≤ CubeSuccessConstant := + Real.exp_one_lt_three.le.trans ((by norm_num : (3:ℝ) ≤ 12).trans cubeSuccessConstant_twelve) +lemma cubeSuccessConstant_pos : 0 < CubeSuccessConstant := + lt_of_lt_of_le zero_lt_one cubeSuccessConstant_one + +lemma cube_whole_factor {d M : ℕ} (hd : 16 ≤ d) (hM : M ≤ d^2) (T : ℕ) : + (T+1:ℝ) * ((12:ℝ)^(d/2) * CubeStep d (2^M) ^ BlockCount T ((d/2)/4)) ≤ + CubeSuccessConstant^((d/2)*(BlockCount T ((d/2)/4)+1)) := by + have hC := cubeStepConstant_pos + have hD := cubeSuccessConstant_pos + have hS := cubeStep_pos d (show 1 ≤ 2^M by exact one_le_pow₀ (by norm_num)) + have hmem := cube_memory_factor hd hM + have hstep : (2:ℝ)^(d/2) * CubeStep d (2^M) ≤ CubeSuccessConstant^(d/2) := by + calc + _ ≤ 2^(d/2) * (CubeStepConstant^(d/2) * ((2:ℝ)^72)^(d/2)) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hmem (by positivity)) (by positivity) + _ = (2*CubeStepConstant*2^72)^(d/2) := by simp only [mul_pow]; ring + _ ≤ _ := pow_le_pow_left₀ (by positivity) (le_max_right _ _) _ + calc + _ = 12^(d/2) * ((T+1:ℝ) * CubeStep d (2^M) ^ BlockCount T ((d/2)/4)) := by ring + _ ≤ 12^(d/2) * (((2:ℝ)^(d/2))^BlockCount T ((d/2)/4) * + CubeStep d (2^M) ^ BlockCount T ((d/2)/4)) := + mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right (cube_stopping_factor hd T) (by positivity)) + (by positivity) + _ = 12^(d/2) * ((2:ℝ)^(d/2) * CubeStep d (2^M))^BlockCount T ((d/2)/4) := by rw [mul_pow] + _ ≤ CubeSuccessConstant^(d/2) * (CubeSuccessConstant^(d/2))^BlockCount T ((d/2)/4) := + mul_le_mul (pow_le_pow_left₀ (by norm_num) cubeSuccessConstant_twelve _) + (pow_le_pow_left₀ (by positivity) hstep _) (by positivity) (by positivity) + _ = _ := by rw [pow_mul, pow_succ]; ring +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/CubeBlock.lean b/lean/OAI/Probability/MemoryPrecision/CubeBlock.lean new file mode 100644 index 0000000000000000000000000000000000000000..60862cfbb60998ac6424f5ca0323da4a8602e174 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/CubeBlock.lean @@ -0,0 +1,165 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeGeometry +import OAI.Probability.MemoryPrecision.WeightedImage +import OAI.Probability.MemoryPrecision.WeightedSelection + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma cube_J_bound {d k : ℕ} (hd : 16 ≤ d) (hk : k ≤ (d/2)/4) : + ∀ j : ℕ, j ≤ (d/2)/4-2 → J (3*(d/2:ℕ)/4:ℝ) k j ≤ (7:ℝ)^d := by + have hp2 : 2 ≤ (d/2)/4 := by omega + have hn4 : (((d/2)/4:ℕ):ℝ)*4 ≤ (d/2:ℕ) := by exact_mod_cast Nat.div_mul_le_self (d/2) 4 + have hn : ((d/2:ℕ):ℝ) ≤ d := by exact_mod_cast Nat.div_le_self d 2 + have hm : (k:ℝ) ≤ ((d/2)/4:ℕ) := by exact_mod_cast hk + intro j hj + have hj' : (j:ℝ)+2 ≤ ((d/2)/4:ℕ) := by exact_mod_cast (show j+2 ≤ (d/2)/4 by omega) + have hgap : 0 < (3*(d/2:ℕ)/4:ℝ)-(j:ℝ)-(k:ℝ) := by linarith + have hquot : (k:ℝ)/((3*(d/2:ℕ)/4:ℝ)-(j:ℝ)-(k:ℝ)) ≤ 1 := by + rw [div_le_one hgap] + linarith + have h3 : (3:ℝ)^j ≤ (3:ℝ)^d := pow_le_pow_right₀ (by norm_num) (by omega) + have h2 : (2:ℝ)^(3*(d/2:ℕ)/4:ℝ) ≤ (2:ℝ)^d := by + rw [← Real.rpow_natCast] + apply Real.rpow_le_rpow_of_exponent_le (by norm_num) + linarith + calc + J (3*(d/2:ℕ)/4:ℝ) k j = 1+(3:ℝ)^j*(2:ℝ)^(3*(d/2:ℕ)/4:ℝ)* + ((k:ℝ)/((3*(d/2:ℕ)/4:ℝ)-(j:ℝ)-(k:ℝ))) := by unfold J; ring + _ ≤ 1+(3:ℝ)^j*(2:ℝ)^(3*(d/2:ℕ)/4:ℝ)*1 := by gcongr + _ ≤ 1+(3:ℝ)^d*(2:ℝ)^d := by rw [mul_one]; gcongr + _ = 1+(6:ℝ)^d := by rw [← mul_pow]; norm_num + _ ≤ (7:ℝ)^d := by + simpa only [one_pow, show (1:ℝ)+6=7 by norm_num] using + pow_add_pow_le (show (0:ℝ) ≤ 1 by norm_num) (show (0:ℝ) ≤ 6 by norm_num) (show d ≠ 0 by omega) + +lemma cube_weighted_ambient {d : ℕ} (hd : 2 ≤ d) {f : Cube d → ℝ≥0∞} + {L : ℝ} (hf : CubeLocal f L) : + AmbientBallBound (((CubeLaw d).withDensity f).map (CubeEmbedding d)) L (3*(d/2:ℕ)/4:ℝ) := by + intro x r hr + rw [weighted_image_ball _ (cubeEmbedding_measurable d)] + apply (lintegral_mono_set (show {u | dist (CubeEmbedding d u) x ≤ r} ⊆ + CubeBall d (Real.sqrt (d/2:ℕ) • cubeProject d x) r from ?_)).trans + (hf _ _ hr) + intro u hu + exact (cubeProject_parameter_dist hd u x).trans + (mul_le_mul_of_nonneg_left hu (Real.sqrt_nonneg _)) + +lemma cubeBall_embedding_subset {d : ℕ} (hd : 2 ≤ d) (z : Space (d/2)) {r : ℝ} + (u₀ : Cube d) (hu₀ : u₀ ∈ CubeBall d z r) : + CubeBall d z r ⊆ CubeEmbedding d ⁻¹' Metric.closedBall (CubeEmbedding d u₀) (4*r) := by + have hs : 0 < Real.sqrt (d/2:ℕ) := Real.sqrt_pos.2 (by exact_mod_cast (show 0 < d/2 by omega)) + intro u hu + have hu' : dist u.val z ≤ Real.sqrt (d/2:ℕ)*r := hu + have hu₀' : dist u₀.val z ≤ Real.sqrt (d/2:ℕ)*r := hu₀ + have hab : dist u.val u₀.val ≤ 2*Real.sqrt (d/2:ℕ)*r := by + have := dist_triangle u.val z u₀.val + rw [dist_comm z u₀.val] at this + linarith + apply (cubeEmbedding_dist hd u u₀).trans + calc + _ ≤ 2/Real.sqrt (d/2:ℕ)*(2*Real.sqrt (d/2:ℕ)*r) := + mul_le_mul_of_nonneg_left hab (by positivity) + _ = 4*r := by field_simp [ne_of_gt hs]; ring + +lemma weightedBlock_le_sum {X : Type*} {d m N : ℕ} + (ι : X → Space d) (f : Fin N → X → ℝ≥0∞) + {g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞} + (hg : ∀ x, ∑ w, g w x ≤ 1) (x : X) : WeightedBlock ι f g x ≤ ∑ w, f w x := by + unfold WeightedBlock + calc + _ ≤ ∫⁻ _A : Fin m → Space d, (∑ w, f w x) ∂Measure.pi (fun _ => stdGaussian (Space d)) := by + apply lintegral_mono + intro A + apply Finset.sum_le_sum + intro w _ + exact mul_le_of_le_one_left' ((Finset.single_le_sum (fun _ _ => zero_le) (Finset.mem_univ w)).trans (hg _)) + _ = _ := by simp + +def CubeBlockConstant : ℝ := 4*1344^3 +lemma cubeBlockConstant_one : 1 ≤ CubeBlockConstant := by norm_num [CubeBlockConstant] + +lemma cube_constant_scale {d : ℕ} (hd : 2 ≤ d) {r : ℝ} (hr : 0 < r) : + (1344:ℝ)^d * (4*r)^(3*(d/2:ℕ)/4:ℝ) ≤ CubeBlockConstant^(d/2) * r^(3*(d/2:ℕ)/4:ℝ) := by + rw [Real.mul_rpow (by norm_num) hr.le] + have hp : (1344:ℝ)^d ≤ (1344^3:ℝ)^(d/2) := by + rw [← pow_mul] + apply pow_le_pow_right₀ (by norm_num) + omega + have h4 : (4:ℝ)^(3*(d/2:ℕ)/4:ℝ) ≤ (4:ℝ)^(d/2) := by + rw [← Real.rpow_natCast] + apply Real.rpow_le_rpow_of_exponent_le (by norm_num) + have := Nat.cast_nonneg (α := ℝ) (d/2) + linarith + calc + _ = ((1344:ℝ)^d*(4:ℝ)^(3*(d/2:ℕ)/4:ℝ))*r^(3*(d/2:ℕ)/4:ℝ) := by ring + _ ≤ ((1344^3:ℝ)^(d/2)*(4:ℝ)^(d/2))*r^(3*(d/2:ℕ)/4:ℝ) := by gcongr + _ = _ := by rw [← mul_pow]; congr 2; norm_num [CubeBlockConstant] + +def CubeBlockStatement : Prop := + ∃ C : ℝ, 1 ≤ C ∧ ∀ d k N : ℕ, 16 ≤ d → 1 ≤ k → k ≤ (d/2)/4 → 1 ≤ N → + ∀ L : ℝ, 0 ≤ L → ∀ f : Fin N → Cube d → ℝ≥0∞, + (∀ v, Measurable (f v)) → (∀ v u, f v u ≤ 1) → (∀ v, CubeLocal (f v) L) → + ∀ g : Fin N → ((Fin k → Space d) × (Fin k → ℝ)) → ℝ≥0∞, + (∀ v, Measurable (g v)) → (∀ x, ∑ v, g v x ≤ 1) → + CubeLocal (WeightedBlock (CubeEmbedding d) f g) + (C^(d/2) * (N:ℝ)^(1/(((d/2)/4:ℕ):ℝ)) * L) +theorem cube_block : CubeBlockStatement := by + refine ⟨CubeBlockConstant, cubeBlockConstant_one, ?_⟩ + intro d k N hd hk hkp hN L hL f hf hf1 hloc g hg hgs z r hr + by_cases hL0 : L = 0 + · simp only [hL0, mul_zero, zero_mul, ENNReal.ofReal_zero] + calc + _ ≤ ∫⁻ u in CubeBall d z r, ∑ w, f w u ∂CubeLaw d := + lintegral_mono (weightedBlock_le_sum _ _ hgs) + _ = ∑ w, ∫⁻ u in CubeBall d z r, f w u ∂CubeLaw d := + lintegral_finsetSum _ (fun w _ => hf w) + _ ≤ ∑ _w : Fin N, ENNReal.ofReal (L*r^(3*(d/2:ℕ)/4:ℝ)) := + Finset.sum_le_sum (fun w _ => hloc w z r hr) + _ = 0 := by simp [hL0] + have hLpos : 0 < L := lt_of_le_of_ne hL (Ne.symm hL0) + by_cases hempty : CubeBall d z r = ∅ + · simp [hempty] + obtain ⟨u₀,hu₀⟩ := Set.nonempty_iff_ne_empty.mpr hempty + let ν (w : Fin N) := ((CubeLaw d).withDensity (f w)).map (CubeEmbedding d) + let (w : Fin N) : IsFiniteMeasure (ν w) := weighted_image_finite (CubeLaw d) (CubeEmbedding d) (f w) (hf1 w) + have hν w : AmbientBallBound (ν w) L (3*(d/2:ℕ)/4:ℝ) := cube_weighted_ambient (by omega) (hloc w) + have hp : 2 ≤ (d/2)/4 := by omega + have hkd : k ≤ d := by omega + have hgap : (k:ℝ)+(((d/2)/4:ℕ):ℝ)-2 < (3*(d/2:ℕ)/4:ℝ) := by + have hp' : (((d/2)/4:ℕ):ℝ)*4 ≤ (d/2:ℕ) := by exact_mod_cast Nat.div_mul_le_self (d/2) 4 + have hk' : (k:ℝ) ≤ ((d/2)/4:ℕ) := by exact_mod_cast hkp + have hn' : (8:ℝ) ≤ (d/2:ℕ) := by exact_mod_cast (show 8 ≤ d/2 by omega) + linarith + have hsel := localized_weighted_selection ν hp hk hkd (by norm_num : (1:ℝ) ≤ 7) + hLpos hgap (cube_J_bound hd hkp) hν g hg hgs (CubeEmbedding d u₀) (by positivity : 0 < 4*r) + have he := weightedBlock_mass_identity (CubeLaw d) (cubeEmbedding_measurable d) hf hf1 hg + (show MeasurableSet (Metric.closedBall (CubeEmbedding d u₀) (4*r)) from Metric.isClosed_closedBall.measurableSet) + apply (lintegral_mono_set (cubeBall_embedding_subset (by omega) z u₀ hu₀)).trans + rw [he] + apply hsel.trans (ENNReal.ofReal_le_ofReal ?_) + have hscale := cube_constant_scale (d := d) (by omega) hr + norm_num only [show (7:ℝ)*192=1344 by norm_num] + calc + _ = ((1344:ℝ)^d*(4*r)^(3*(d/2:ℕ)/4:ℝ))*((N:ℝ)^(1/(((d/2)/4:ℕ):ℝ))*L) := by ring + _ ≤ (CubeBlockConstant^(d/2)*r^(3*(d/2:ℕ)/4:ℝ))*((N:ℝ)^(1/(((d/2)/4:ℕ):ℝ))*L) := + mul_le_mul_of_nonneg_right hscale (by positivity) + _ = _ := by ring +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/CubeCaps.lean b/lean/OAI/Probability/MemoryPrecision/CubeCaps.lean new file mode 100644 index 0000000000000000000000000000000000000000..6335cd33bb701a3f59d6257e46133feafe3f5210 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/CubeCaps.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeGeometry + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma coordinate_ball_root_volume (n : ℕ) : + volume (coordinateBall n (Real.sqrt n)) ≤ ENNReal.ofReal ((12:ℝ)^n) := by + have hpoint (x : Fin n → ℝ) : + (coordinateBall n (Real.sqrt n)).indicator (fun _ => (1:ℝ≥0∞)) x ≤ + ENNReal.ofReal (Real.exp n) * ∏ i, ENNReal.ofReal (Real.exp (-(x i)^2/4)) := by + by_cases hx : x ∈ coordinateBall n (Real.sqrt n) + · rw [Set.indicator_of_mem hx, ← ENNReal.ofReal_prod_of_nonneg (fun i _ => Real.exp_nonneg _), + ← ENNReal.ofReal_mul (Real.exp_nonneg _), ← Real.exp_sum, ← Real.exp_add] + have hs : (∑ i, (x i)^2) ≤ n := by + have hp := pow_le_pow_left₀ (norm_nonneg _) hx 2 + change coordinateNorm x ^ 2 ≤ (Real.sqrt (n:ℝ)) ^ 2 at hp + rw [coordinateNorm_sq, Real.sq_sqrt (by positivity)] at hp + exact hp + have he : 1 ≤ Real.exp ((n:ℝ) + ∑ i, -(x i)^2/4) := by + apply Real.one_le_exp_iff.mpr + rw [← Finset.sum_div, Finset.sum_neg_distrib] + have hn : (0:ℝ) ≤ n := Nat.cast_nonneg n + linarith + exact_mod_cast (ENNReal.ofReal_le_ofReal he) + · rw [Set.indicator_of_notMem hx] + exact zero_le + calc + volume (coordinateBall n (Real.sqrt n)) = + ∫⁻ x : Fin n → ℝ, (coordinateBall n (Real.sqrt n)).indicator (fun _ => (1:ℝ≥0∞)) x := by + rw [lintegral_indicator_const (measurableSet_coordinateBall _ _), one_mul] + _ ≤ ∫⁻ x : Fin n → ℝ, ENNReal.ofReal (Real.exp n) * + ∏ i, ENNReal.ofReal (Real.exp (-(x i)^2/4)) := lintegral_mono hpoint + _ = ENNReal.ofReal (Real.exp n) * + (∫⁻ z : ℝ, ENNReal.ofReal (Real.exp (-(z^2)/4)))^n := by + rw [lintegral_const_mul _ (by fun_prop), volume_pi, + lintegral_fin_prod volume n (fun _ => fun z : ℝ => ENNReal.ofReal (Real.exp (-(z^2)/4))) (fun _ => by fun_prop)] + simp + _ ≤ ENNReal.ofReal (Real.exp n) * (4:ℝ≥0∞)^n := by + gcongr + exact lintegral_quarterGaussian_le + _ ≤ ENNReal.ofReal ((12:ℝ)^n) := by + have he : Real.exp (n:ℝ) ≤ (3:ℝ)^n := by + rw [← mul_one (n:ℝ), Real.exp_nat_mul] + exact pow_le_pow_left₀ (Real.exp_nonneg _) Real.exp_one_lt_three.le n + calc + _ ≤ ENNReal.ofReal ((3:ℝ)^n) * (4:ℝ≥0∞)^n := mul_le_mul' (ENNReal.ofReal_le_ofReal he) le_rfl + _ = _ := by rw [ENNReal.ofReal_pow (by norm_num), ← mul_pow]; norm_num + +lemma cube_scaled_ball_volume (n : ℕ) (z : Space n) {r : ℝ} (hr : 0 < r) : + volume (Metric.closedBall z (Real.sqrt n*r)) ≤ ENNReal.ofReal ((12:ℝ)^n*r^n) := by + rw [Measure.addHaar_closedBall_center] + have he : (WithLp.toLp 2 : (Fin n → ℝ) → Space n) ⁻¹' Metric.closedBall 0 (Real.sqrt n*r) = + coordinateBall n (r*Real.sqrt n) := by + ext x + simp [Metric.mem_closedBall, dist_zero_right, coordinateBall, coordinateNorm, mul_comm] + rw [← (PiLp.volume_preserving_toLp (Fin n)).measure_preimage (show NullMeasurableSet (Metric.closedBall (0:Space n) (Real.sqrt n*r)) volume from Metric.isClosed_closedBall.measurableSet.nullMeasurableSet), he, + volume_coordinateBall_smul n r (Real.sqrt n) hr] + calc + _ ≤ ENNReal.ofReal (r^n) * ENNReal.ofReal ((12:ℝ)^n) := + mul_le_mul' le_rfl (coordinate_ball_root_volume n) + _ = _ := by rw [← ENNReal.ofReal_mul (by positivity)]; congr 1; ring + +lemma cubeBall_volume (d : ℕ) (z : Space (d/2)) {r : ℝ} (hr : 0 < r) : + CubeLaw d (CubeBall d z r) ≤ ENNReal.ofReal ((12:ℝ)^(d/2)*r^(d/2)) := by + rw [CubeLaw, comap_subtype_coe_apply (cubeSet_measurable _)] + apply (measure_mono (show Subtype.val '' CubeBall d z r ⊆ Metric.closedBall z (Real.sqrt (d/2:ℕ)*r) from ?_)).trans + (cube_scaled_ball_volume (d/2) z hr) + rintro _ ⟨u,hu,rfl⟩ + exact hu + +lemma cube_cap_local {d : ℕ} (hd : 2 ≤ d) (y : Space d) {ε : ℝ} (hε : 0 < ε) : + CubeLocal (fun u => capWeight y ε (CubeEmbedding d u)) + ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ)) := by + intro z r hr + let A : Set (Cube d) := CubeEmbedding d ⁻¹' Metric.closedBall y ε + have hA : MeasurableSet A := Metric.isClosed_closedBall.measurableSet.preimage (cubeEmbedding_measurable d) + have hint : (∫⁻ u in CubeBall d z r, capWeight y ε (CubeEmbedding d u) ∂CubeLaw d) = + CubeLaw d (A ∩ CubeBall d z r) := by + change (∫⁻ u in CubeBall d z r, A.indicator (fun _ => (1:ℝ≥0∞)) u ∂CubeLaw d) = _ + rw [lintegral_indicator_const hA, one_mul, Measure.restrict_apply hA] + rw [hint] + have hεball : A ⊆ CubeBall d (Real.sqrt (d/2:ℕ) • cubeProject d y) ε := by + intro u hu + exact (cubeProject_parameter_dist hd u y).trans + (mul_le_mul_of_nonneg_left hu (Real.sqrt_nonneg _)) + have hs : (0:ℝ) ≤ (d/2:ℕ)/4 := by positivity + have ht : (0:ℝ) ≤ 3*(d/2:ℕ)/4 := by positivity + have he (t : ℝ) (ht : 0 < t) : t^(d/2) = t^((d/2:ℕ)/4:ℝ)*t^(3*(d/2:ℕ)/4:ℝ) := by + rw [← Real.rpow_add ht, show ((d/2:ℕ)/4:ℝ)+(3*(d/2:ℕ)/4:ℝ) = (d/2:ℕ) by ring, Real.rpow_natCast] + by_cases hh : r ≤ ε + · apply ((measure_mono Set.inter_subset_right).trans (cubeBall_volume d z hr)).trans + apply ENNReal.ofReal_le_ofReal + rw [he r hr, ← mul_assoc] + gcongr + · apply ((measure_mono (Set.inter_subset_left.trans hεball)).trans + (cubeBall_volume d (Real.sqrt (d/2:ℕ) • cubeProject d y) hε)).trans + apply ENNReal.ofReal_le_ofReal + rw [he ε hε, ← mul_assoc] + gcongr + exact le_of_not_ge hh + +lemma cubeBall_univ (d : ℕ) : CubeBall d 0 1 = Set.univ := by + ext u + simp only [Set.mem_univ, iff_true] + change dist u.val 0 ≤ Real.sqrt (d/2:ℕ)*1 + rw [dist_zero_right, mul_one] + apply nonneg_le_nonneg_of_sq_le_sq (Real.sqrt_nonneg _) + simp only [← pow_two] + rw [Real.sq_sqrt (by positivity), EuclideanSpace.norm_sq_eq] + calc + _ ≤ ∑ _i : Fin (d/2), (1:ℝ) := by + apply Finset.sum_le_sum + intro i _ + have h := u.property i + have hab := abs_le.mp h + simp only [Real.norm_eq_abs, sq_abs] + nlinarith + _ = _ := by simp + +lemma cube_mass_bound {d : ℕ} {f : Cube d → ℝ≥0∞} {L : ℝ} (h : CubeLocal f L) : + (∫⁻ u, f u ∂CubeLaw d) ≤ ENNReal.ofReal L := by + simpa [cubeBall_univ] using h 0 1 zero_lt_one + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/CubeContinuation.lean b/lean/OAI/Probability/MemoryPrecision/CubeContinuation.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a4fe495011f0c9d79055ce8bdb92cadfbd7b8ee --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/CubeContinuation.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeBlock +import OAI.Probability.MemoryPrecision.CubeCaps +import OAI.Probability.MemoryPrecision.RealContinuation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression +def CubeStepConstant : ℝ := Classical.choose cube_block +lemma cubeStepConstant_one : 1 ≤ CubeStepConstant := (Classical.choose_spec cube_block).1 +lemma cubeStepConstant_pos : 0 < CubeStepConstant := lt_of_lt_of_le zero_lt_one cubeStepConstant_one + +def CubeStep (d N : ℕ) : ℝ := CubeStepConstant^(d/2) * (N:ℝ)^(1/(((d/2)/4:ℕ):ℝ)) +lemma cubeStep_one (d : ℕ) {N : ℕ} (hN : 1 ≤ N) : 1 ≤ CubeStep d N := by + apply one_le_mul_of_one_le_of_one_le + · exact one_le_pow₀ cubeStepConstant_one + · exact Real.one_le_rpow (by exact_mod_cast hN) (by positivity) +lemma cubeStep_pos (d : ℕ) {N : ℕ} (hN : 1 ≤ N) : 0 < CubeStep d N := + lt_of_lt_of_le zero_lt_one (cubeStep_one d hN) + +lemma cube_deterministic_step {d m N : ℕ} (hd : 16 ≤ d) (hm : 1 ≤ m) + (hmp : m ≤ (d/2)/4) (hN : 1 ≤ N) {H : ℝ} (hH : 0 < H) + (h : Fin N → Space d → ℝ≥0∞) (hh : ∀ w, Measurable (h w)) + (hh1 : ∀ w s, h w s ≤ 1) + (hb : ∀ w, CubeLocal (fun u => h w (CubeEmbedding d u)) H) + (φ : ((Fin m → Space d) × (Fin m → ℝ)) → Fin N) (hφ : Measurable φ) : + CubeLocal (fun u => blockValue h φ (CubeEmbedding d u)) (CubeStep d N * H) := by + classical + let g (w : Fin N) (x : (Fin m → Space d) × (Fin m → ℝ)) : ℝ≥0∞ := + if φ x = w then 1 else 0 + have hg (w) : Measurable (g w) := by + exact Measurable.ite (measurableSet_eq_fun hφ measurable_const) measurable_const measurable_const + have hg1 (x) : ∑ w, g w x ≤ 1 := by simp [g] + have hb' := (Classical.choose_spec cube_block).2 d m N hd hm hmp hN H hH.le + (fun w u => h w (CubeEmbedding d u)) (fun w => (hh w).comp (cubeEmbedding_measurable d)) + (fun w u => hh1 w (CubeEmbedding d u)) hb g hg hg1 + convert hb' using 1 + · funext u + unfold blockValue WeightedBlock + congr 1 + funext A + simp [g] + · rfl + +lemma CubeLocal.mono {d : ℕ} {h : Cube d → ℝ≥0∞} {H K : ℝ} + (hh : CubeLocal h H) (hHK : H ≤ K) : CubeLocal h K := by + intro z r hr + exact (hh z r hr).trans (ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_right hHK (by positivity))) + +lemma cube_continuation_mass {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + {δ : ℕ → Fin N → (Space d × ℝ) → Fin N} + {w : ℕ → Fin N → Space d → ℝ≥0∞} + (hδ : ∀ n j, Measurable (δ n j)) (hw : ∀ n j, Measurable (w n j)) + (hw1 : ∀ n j s, w n j s ≤ 1) {H : ℝ} (hH : 0 < H) + (hlocal : ∀ n j, CubeLocal (fun s => w n j (CubeEmbedding d s)) H) + (b k : ℕ) (hk : k ≤ b*((d/2)/4)) (n : ℕ) (j : Fin N) : + CubeLocal (fun s => continuation δ w n k j (CubeEmbedding d s)) + (H * CubeStep d N ^ b) := by + have hp : 0 < (d/2)/4 := by omega + have hK := cubeStep_one d hN + have hK0 := cubeStep_pos d hN + induction b generalizing k n j with + | zero => + have : k = 0 := by omega + subst k + simpa [continuation] using hlocal n j + | succ b ih => + by_cases hk0 : k = 0 + · subst k + apply (hlocal n j).mono + simpa [continuation] using le_mul_of_one_le_right hH.le (one_le_pow₀ hK) + · let m := min k ((d/2)/4) + have hm : 1 ≤ m := by dsimp [m]; omega + have hmp : m ≤ (d/2)/4 := min_le_right _ _ + have hmk : m ≤ k := min_le_left _ _ + have hk' : k-m ≤ b*((d/2)/4) := by + dsimp [m] + rw [Nat.succ_mul] at hk + omega + have hb := cube_deterministic_step hd hm hmp hN + (mul_pos hH (pow_pos hK0 b)) + (fun a => continuation δ w (n+m) (k-m) a) + (fun a => measurable_continuation hδ hw _ _ a) + (fun a s => continuation_le_one hw1 _ _ a s) + (fun a => ih (k-m) hk' (n+m) a) (streamRoute δ n m j) + (measurable_streamRoute hδ n m j) + have he : (fun s : Cube d => continuation δ w n k j (CubeEmbedding d s)) = + (fun s : Cube d => blockValue (fun a => continuation δ w (n+m) (k-m) a) + (streamRoute δ n m j) (CubeEmbedding d s)) := by + funext s + simpa [Nat.add_sub_of_le hmk] using continuation_unroll hδ n m (k-m) j (CubeEmbedding d s) + rw [he] + convert hb using 1 + rw [pow_succ]; ring + +lemma cube_continuation_cap_integral {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + {δ : ℕ → Fin N → (Space d × ℝ) → Fin N} (hδ : ∀ n j, Measurable (δ n j)) + (y : ℕ → Fin N → Space d) {ε : ℝ} (hε : 0 < ε) (n k : ℕ) (j : Fin N) : + (∫⁻ u, continuation δ (fun n j => capWeight (y n j) ε) n k j (CubeEmbedding d u) ∂CubeLaw d) ≤ + ENNReal.ofReal ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * CubeStep d N ^ BlockCount k ((d/2)/4)) := by + apply cube_mass_bound + apply cube_continuation_mass hd hN hδ (fun n j => measurable_capWeight _ _) + (fun n j s => capWeight_le_one _ _ _) (by positivity) + (fun n j => cube_cap_local (by omega) (y n j) hε) + simpa [mul_comm] using blockCount_mul_ge k (by omega : 0 < (d/2)/4) + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/CubeExperiment.lean b/lean/OAI/Probability/MemoryPrecision/CubeExperiment.lean new file mode 100644 index 0000000000000000000000000000000000000000..d6155c876f6dea14b27898335dbe1f0835034db2 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/CubeExperiment.lean @@ -0,0 +1,103 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeCaps +import OAI.Probability.MemoryPrecision.PriorMeasurability + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def CubeSphere {d : ℕ} (hd : 2 ≤ d) (u : Cube d) : UnitSphere d := + ⟨CubeEmbedding d u, by simpa [Metric.mem_sphere, dist_zero_right] using cubeEmbedding_norm hd u⟩ +lemma cubeSphere_measurable {d : ℕ} (hd : 2 ≤ d) : Measurable (CubeSphere hd) := + (cubeEmbedding_measurable d).subtype_mk + +def CubeSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) (hd : 2 ≤ d) (ε : ℝ) : ℝ≥0∞ := + ((CubeLaw d).prod (ρ.prod (sampleLaw d T))) + {z | Learner.angularError (CubeSphere hd z.1) + (L.estimate (CubeSphere hd z.1) z.2.1 z.2.2) ≤ ε} +def CubeAmbient (d : ℕ) : Measure (Space d) := (CubeLaw d).map (CubeEmbedding d) +instance (d : ℕ) : IsProbabilityMeasure (CubeAmbient d) := + inferInstanceAs (IsProbabilityMeasure ((CubeLaw d).map (CubeEmbedding d))) + +lemma cubeAmbient_support {d : ℕ} (hd : 2 ≤ d) : (CubeAmbient d).support ⊆ Metric.closedBall 0 1 := by + apply Measure.support_subset_of_isClosed Metric.isClosed_closedBall + rw [mem_ae_iff, CubeAmbient, Measure.map_apply (cubeEmbedding_measurable d) + Metric.isClosed_closedBall.measurableSet.compl] + have he : CubeEmbedding d ⁻¹' (Metric.closedBall (0:Space d) 1)ᶜ = ∅ := by + ext u + simp [cubeEmbedding_norm hd, Metric.mem_closedBall, dist_zero_right] + rw [he, measure_empty] + +lemma cubeAmbient_polynomial {d : ℕ} (hd : 2 ≤ d) : + PolynomialMass (CubeAmbient d) (d/2) (ENNReal.ofReal ((12:ℝ)^(d/2))) := by + intro x r hr + rw [CubeAmbient, Measure.map_apply (cubeEmbedding_measurable d) Metric.isClosed_closedBall.measurableSet] + have hsub : CubeEmbedding d ⁻¹' Metric.closedBall x r ⊆ + CubeBall d (Real.sqrt (d/2:ℕ) • cubeProject d x) r := by + intro u hu + exact (cubeProject_parameter_dist hd u x).trans + (mul_le_mul_of_nonneg_left hu (Real.sqrt_nonneg _)) + exact ((measure_mono hsub).trans (cubeBall_volume d _ hr)).trans_eq (ENNReal.ofReal_mul (by positivity)) + +lemma cube_observation_quasi {d : ℕ} (hd : 16 ≤ d) : + Measure.QuasiMeasurePreserving + (fun z : Cube d × Space d => (z.2,⟪CubeEmbedding d z.1,z.2⟫)) + ((CubeLaw d).prod (stdGaussian (Space d))) (observationReference d) := by + have hac : projectionLaw (CubeAmbient d) 1 ≪ matrixLabelReference (E := Space d) 1 := by + apply projectionLaw_absolutelyContinuous (cubeAmbient_polynomial (by omega : 2 ≤ d)) + (C := ENNReal.ofReal ((12:ℝ)^(d/2))) (n := 1) + · positivity + · exact ENNReal.ofReal_ne_top + · exact cubeAmbient_support (by omega) + · omega + · omega + have hp : Measure.QuasiMeasurePreserving + (fun z : (Fin 1 → Space d) × Space d => (z.1,fun j => ⟪z.2,z.1 j⟫)) + ((Measure.pi (fun _ : Fin 1 => stdGaussian (Space d))).prod (CubeAmbient d)) + (matrixLabelReference (E := Space d) 1) := ⟨by fun_prop,hac⟩ + have h1 := ((measurePreserving_funUnique (stdGaussian (Space d)) (Fin 1)).symm + (MeasurableEquiv.funUnique (Fin 1) (Space d))).prod + ((cubeEmbedding_measurable d).measurePreserving (CubeLaw d)) + have h2 := (measurePreserving_funUnique (stdGaussian (Space d)) (Fin 1)).prod + (volume_preserving_funUnique (Fin 1) ℝ) + have h3 := h2.quasiMeasurePreserving.comp (hp.comp (h1.quasiMeasurePreserving.comp + Measure.measurePreserving_swap.quasiMeasurePreserving)) + convert h3 using 1 + · ext z <;> simp [MeasurableEquiv.funUnique] + · rfl + +lemma cube_sample_observation_quasi {d T : ℕ} (hd : 16 ≤ d) (i : Fin T) : + Measure.QuasiMeasurePreserving + (fun z : Cube d × Samples d T => (z.2 i,⟪CubeEmbedding d z.1,z.2 i⟫)) + ((CubeLaw d).prod (sampleLaw d T)) (observationReference d) := by + exact (cube_observation_quasi hd).comp + ((MeasurePreserving.id (CubeLaw d)).prod + (measurePreserving_eval (fun _ : Fin T => stdGaussian (Space d)) i)).quasiMeasurePreserving + +lemma cube_estimate_aemeasurable {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 16 ≤ d) : + AEMeasurable (fun z : Cube d × (Ω × Samples d T) => + L.estimate (CubeSphere (by omega) z.1) z.2.1 z.2.2) + ((CubeLaw d).prod (ρ.prod (sampleLaw d T))) := + prior_estimate_aemeasurable (CubeLaw d) ρ (CubeSphere (by omega)) L hL + (cube_sample_observation_quasi hd) + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/CubeGeometry.lean b/lean/OAI/Probability/MemoryPrecision/CubeGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..2cb5dba312a5aca601c3eb0422e46f1e51368467 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/CubeGeometry.lean @@ -0,0 +1,279 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.AmbientGram + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression +abbrev CubeSet (n : ℕ) : Set (EuclideanSpace ℝ (Fin n)) := + fun (point : EuclideanSpace ℝ (Fin n)) => ∀ index : Fin n, + @LE.le ℝ Real.instLE + (@abs ℝ Real.lattice Real.instAddGroup + (@WithLp.ofLp + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) + (Fin n → ℝ) point index)) + (@HDiv.hDiv ℝ ℝ ℝ (@instHDiv ℝ Real.instDivInvMonoid.toDiv) + (@OfNat.ofNat ℝ 1 (@One.toOfNat1 ℝ Real.instOne)) + (@OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))))) +abbrev Cube (d : ℕ) := CubeSet (d/2) +def CubeLaw (d : ℕ) : Measure (Cube d) := + (volume : Measure (Space (d/2))).comap Subtype.val +lemma cube_second_coordinate_lt (d : ℕ) (index : Fin d) + (lower : ¬index.val < d/2) (upper : index.val < 2*(d/2)) : + index.val - d/2 < d/2 := by omega + +def cubeRaw (d : ℕ) (u : Space (d/2)) : Space d := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + @HSMul.hSMul ℝ (Space d) (Space d) + (@instHSMul ℝ (Space d) (WithLp.instSMul exponent ℝ (Fin d → ℝ))) + (Real.sqrt (d/2:ℕ))⁻¹ (WithLp.toLp exponent (fun index : Fin d => + if lower : index.val < d/2 then + @WithLp.ofLp exponent (Fin (d/2) → ℝ) u ⟨index.val, lower⟩ + else if upper : index.val < 2*(d/2) then + Real.sqrt (1-(@WithLp.ofLp exponent (Fin (d/2) → ℝ) u + ⟨index.val-d/2, cube_second_coordinate_lt d index lower upper⟩)^2) + else 0)) +def CubeEmbedding (d : ℕ) (u : Cube d) : Space d := cubeRaw d u.val +def CubeBall (d : ℕ) (z : Space (d/2)) (r : ℝ) : Set (Cube d) := + {u | dist u.val z ≤ Real.sqrt (d/2:ℕ) * r} +def CubeLocal {d : ℕ} (f : Cube d → ℝ≥0∞) (L : ℝ) : Prop := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let cubeMeasurable := @Subtype.instMeasurableSpace (Space (d/2)) (CubeSet (d/2)) + (@WithLp.measurableSpace exponent (Fin (d/2) → ℝ) inferInstance) + ∀ z : Space (d/2), ∀ r : ℝ, 0 < r → + @MeasureTheory.lintegral (Cube d) cubeMeasurable + (@Measure.restrict (Cube d) cubeMeasurable (CubeLaw d) (CubeBall d z r)) f ≤ + ENNReal.ofReal (L * r^( + (@OfNat.ofNat ℝ 3 (@instOfNatAtLeastTwo ℝ 3 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 1)))) * (d/2:ℕ) / + (@OfNat.ofNat ℝ 4 (@instOfNatAtLeastTwo ℝ 4 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 2)))) : ℝ)) + +lemma cubeSet_closed (n : ℕ) : IsClosed (CubeSet n) := by + change IsClosed {u : Space n | ∀ i, |u i| ≤ 1/2} + simp only [Set.ofPred_forall] + exact isClosed_iInter (fun i => isClosed_le (by fun_prop) continuous_const) + +lemma cubeSet_measurable (n : ℕ) : MeasurableSet (CubeSet n) := + (cubeSet_closed n).measurableSet + +lemma cubeLaw_probability (d : ℕ) : IsProbabilityMeasure (CubeLaw d) := by + constructor + rw [CubeLaw, comap_subtype_coe_apply (cubeSet_measurable _), Set.image_univ, + Subtype.range_coe] + have he : CubeSet (d/2) = WithLp.ofLp ⁻¹' (Set.univ.pi (fun _ : Fin (d/2) => Icc (-1/2:ℝ) (1/2))) := by + ext u + change (∀ i, |u i| ≤ (1/2 : ℝ)) ↔ _ + simp only [Set.mem_preimage, Set.mem_univ_pi, Set.mem_Icc, abs_le] + norm_num + rw [he, (PiLp.volume_preserving_ofLp (Fin (d/2))).measure_preimage (by measurability)] + rw [volume_pi, Measure.pi_pi] + norm_num [Real.volume_Icc] + +instance (d : ℕ) : IsProbabilityMeasure (CubeLaw d) := cubeLaw_probability d + +lemma cubeBall_measurable (d : ℕ) (z : Space (d/2)) (r : ℝ) : MeasurableSet (CubeBall d z r) := by + exact measurableSet_le (by fun_prop) measurable_const + +lemma cubeRaw_continuous (d : ℕ) : Continuous (cubeRaw d) := by + unfold cubeRaw + refine Continuous.const_smul (c := (Real.sqrt (d/2:ℕ))⁻¹) ?_ + apply (PiLp.continuous_toLp 2 (fun _ : Fin d => ℝ)).comp + apply continuous_pi + intro i + dsimp + split_ifs <;> fun_prop + +lemma cubeEmbedding_continuous (d : ℕ) : Continuous (CubeEmbedding d) := + (cubeRaw_continuous d).comp continuous_subtype_val + +lemma cubeEmbedding_measurable (d : ℕ) : Measurable (CubeEmbedding d) := + (cubeEmbedding_continuous d).measurable + +lemma sum_fin_split {n d : ℕ} (hn : n ≤ d) (f : Fin d → ℝ) : + (∑ i, f i) = (∑ i : Fin n, f ⟨i.val,by omega⟩) + + ∑ i : Fin (d-n), f ⟨n+i.val,by omega⟩ := by + let e : Fin (n+(d-n)) ≃ Fin d := finCongr (Nat.add_sub_of_le hn) + calc + _ = ∑ i : Fin (n+(d-n)), f (e i) := (Equiv.sum_comp e f).symm + _ = _ := by rw [Fin.sum_univ_add]; rfl + +def cubeCoords (d : ℕ) (u : Space (d/2)) : Space d := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + WithLp.toLp exponent (fun index : Fin d => + if lower : index.val < d/2 then + @WithLp.ofLp exponent (Fin (d/2) → ℝ) u ⟨index.val, lower⟩ + else if upper : index.val < 2*(d/2) then + Real.sqrt (1-(@WithLp.ofLp exponent (Fin (d/2) → ℝ) u + ⟨index.val-d/2, cube_second_coordinate_lt d index lower upper⟩)^2) + else 0) + +lemma cubeCoords_first (d : ℕ) (u : Space (d/2)) (i : Fin (d/2)) : + cubeCoords d u ⟨i.val,by omega⟩ = u i := by + simp [cubeCoords, i.isLt] + +lemma cubeCoords_second (d : ℕ) (u : Space (d/2)) (i : Fin (d/2)) : + cubeCoords d u ⟨d/2+i.val,by omega⟩ = Real.sqrt (1-u i^2) := by + simp [cubeCoords, show ¬d/2+i.val < d/2 by omega, show d/2+i.val < 2*(d/2) by omega] + +lemma cubeCoords_tail (d : ℕ) (u : Space (d/2)) (i : Fin d) (hi : 2*(d/2) ≤ i.val) : + cubeCoords d u i = 0 := by + simp [cubeCoords, show ¬i.val < d/2 by omega, show ¬i.val < 2*(d/2) by omega] + +lemma cubeCoords_sum (d : ℕ) (u : Space (d/2)) (f : ℝ → ℝ) (hf : f 0 = 0) : + (∑ i : Fin d, f (cubeCoords d u i)) = + (∑ i : Fin (d/2), f (u i)) + ∑ i : Fin (d/2), f (Real.sqrt (1-u i^2)) := by + rw [sum_fin_split (show d/2 ≤ d by omega)] + simp_rw [cubeCoords_first] + rw [sum_fin_split (show d/2 ≤ d-d/2 by omega)] + congr 1 + have h1 : (∑ i : Fin (d/2), f (cubeCoords d u ⟨d/2+i.val,by omega⟩)) = + ∑ i : Fin (d/2), f (Real.sqrt (1-u i^2)) := by simp_rw [cubeCoords_second] + rw [h1] + have h0 : (∑ i : Fin (d-d/2-d/2), f (cubeCoords d u ⟨d/2+(d/2+i.val),by omega⟩)) = 0 := by + apply Finset.sum_eq_zero + intro i _ + rw [cubeCoords_tail d u _ (show 2*(d/2) ≤ d/2+(d/2+i.val) by omega), hf] + rw [h0, add_zero] + +lemma cube_coordinate_square_le {d : ℕ} (u : Cube d) (i : Fin (d/2)) : u.val i^2 ≤ 1/4 := by + have hu : -(1/2 : ℝ) ≤ u.val i ∧ u.val i ≤ 1/2 := abs_le.mp (u.property i) + nlinarith [sq_nonneg (u.val i-1/2), sq_nonneg (u.val i+1/2)] + +lemma cubeEmbedding_norm {d : ℕ} (hd : 2 ≤ d) (u : Cube d) : + @Norm.norm (Space d) (PiLp.instNorm + (p := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (β := fun _ : Fin d => ℝ)) + (CubeEmbedding d u) = (1 : ℝ) := by + have hs : ‖cubeCoords d u.val‖^2 = (d/2:ℕ) := by + rw [EuclideanSpace.real_norm_sq_eq, cubeCoords_sum d u.val (fun x => x^2) (by norm_num)] + have he (i : Fin (d/2)) : Real.sqrt (1-u.val i^2)^2 = 1-u.val i^2 := + Real.sq_sqrt (by have := cube_coordinate_square_le u i; linarith) + simp_rw [he] + rw [← Finset.sum_add_distrib] + simp + have hn : 0 < (d/2:ℕ) := by omega + have hr : 0 < Real.sqrt (d/2:ℕ) := Real.sqrt_pos.2 (by exact_mod_cast hn) + have hnorm : ‖cubeCoords d u.val‖ = Real.sqrt (d/2:ℕ) := by + rw [← Real.sqrt_sq (norm_nonneg _), hs] + change ‖(Real.sqrt (d/2:ℕ))⁻¹ • cubeCoords d u.val‖ = 1 + rw [norm_smul, Real.norm_eq_abs, abs_inv, abs_of_pos hr, hnorm, inv_mul_cancel₀ hr.ne'] + +lemma sqrt_pair_lipschitz {a b : ℝ} (ha : |a| ≤ 1/2) (hb : |b| ≤ 1/2) : + |Real.sqrt (1-a^2) - Real.sqrt (1-b^2)| ≤ |a-b| := by + have ha2 : a^2 ≤ 1/4 := by rcases abs_le.mp ha with ⟨ha₁,ha₂⟩; nlinarith + have hb2 : b^2 ≤ 1/4 := by rcases abs_le.mp hb with ⟨hb₁,hb₂⟩; nlinarith + have hsa := Real.sq_sqrt (show 0 ≤ 1-a^2 by linarith) + have hsb := Real.sq_sqrt (show 0 ≤ 1-b^2 by linarith) + have has : 1/2 ≤ Real.sqrt (1-a^2) := by nlinarith [Real.sqrt_nonneg (1-a^2)] + have hbs : 1/2 ≤ Real.sqrt (1-b^2) := by nlinarith [Real.sqrt_nonneg (1-b^2)] + have hab : |a+b| ≤ 1 := (abs_add_le a b).trans (by linarith) + have he : (Real.sqrt (1-a^2)-Real.sqrt (1-b^2)) * + (Real.sqrt (1-a^2)+Real.sqrt (1-b^2)) = -(a-b)*(a+b) := by nlinarith + calc + _ ≤ |Real.sqrt (1-a^2)-Real.sqrt (1-b^2)| * + |Real.sqrt (1-a^2)+Real.sqrt (1-b^2)| := by + apply le_mul_of_one_le_right (abs_nonneg _) + rw [abs_of_nonneg (by positivity)] + linarith + _ = |a-b| * |a+b| := by rw [← abs_mul, he, abs_mul, abs_neg] + _ ≤ |a-b| := mul_le_of_le_one_right (abs_nonneg _) hab + +private lemma cubeCoords_sub_norm (d : ℕ) (u v : Cube d) : + ‖cubeCoords d u.val - cubeCoords d v.val‖ ≤ 2 * ‖u.val-v.val‖ := by + have hs : ‖cubeCoords d u.val - cubeCoords d v.val‖^2 = + (∑ i : Fin (d/2), (u.val i-v.val i)^2) + + ∑ i : Fin (d/2), (Real.sqrt (1-u.val i^2)-Real.sqrt (1-v.val i^2))^2 := by + rw [EuclideanSpace.real_norm_sq_eq, sum_fin_split (show d/2 ≤ d by omega)] + simp only [PiLp.sub_apply, cubeCoords_first] + rw [sum_fin_split (show d/2 ≤ d-d/2 by omega)] + simp only [cubeCoords_second] + have hz : (∑ i : Fin (d-d/2-d/2), + (cubeCoords d u.val ⟨d/2+(d/2+i.val),by omega⟩ - + cubeCoords d v.val ⟨d/2+(d/2+i.val),by omega⟩)^2) = 0 := by + apply Finset.sum_eq_zero + intro i _ + rw [cubeCoords_tail d u.val _ (show 2*(d/2) ≤ d/2+(d/2+i.val) by omega), + cubeCoords_tail d v.val _ (show 2*(d/2) ≤ d/2+(d/2+i.val) by omega)] + norm_num + rw [hz, add_zero] + have hsq : (∑ i : Fin (d/2), (Real.sqrt (1-u.val i^2)-Real.sqrt (1-v.val i^2))^2) ≤ + ∑ i : Fin (d/2), (u.val i-v.val i)^2 := by + apply Finset.sum_le_sum + intro i _ + exact (sq_le_sq).2 (sqrt_pair_lipschitz (u.property i) (v.property i)) + have hv : ‖u.val-v.val‖^2 = ∑ i : Fin (d/2), (u.val i-v.val i)^2 := by + simp [EuclideanSpace.real_norm_sq_eq] + nlinarith [norm_nonneg (cubeCoords d u.val-cubeCoords d v.val), norm_nonneg (u.val-v.val)] + +lemma cubeEmbedding_dist {d : ℕ} (hd : 2 ≤ d) (u v : Cube d) : + dist (CubeEmbedding d u) (CubeEmbedding d v) ≤ + 2 / Real.sqrt (d/2:ℕ) * dist u.val v.val := by + have hr : 0 < Real.sqrt (d/2:ℕ) := Real.sqrt_pos.2 (by exact_mod_cast (show 0 < d/2 by omega)) + change dist ((Real.sqrt (d/2:ℕ))⁻¹ • cubeCoords d u.val) + ((Real.sqrt (d/2:ℕ))⁻¹ • cubeCoords d v.val) ≤ _ + rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_inv, abs_of_pos hr, dist_eq_norm] + calc + _ ≤ (Real.sqrt (d/2:ℕ))⁻¹ * (2*‖u.val-v.val‖) := + mul_le_mul_of_nonneg_left (cubeCoords_sub_norm d u v) (inv_nonneg.mpr hr.le) + _ = _ := by ring + +def cubeProject (d : ℕ) (x : Space d) : Space (d/2) := + WithLp.toLp 2 (fun i : Fin (d/2) => x ⟨i.val,by omega⟩) + +lemma cubeProject_continuous (d : ℕ) : Continuous (cubeProject d) := by + unfold cubeProject + fun_prop + +lemma cubeProject_norm (d : ℕ) (x : Space d) : ‖cubeProject d x‖ ≤ ‖x‖ := by + have h : ‖cubeProject d x‖^2 ≤ ‖x‖^2 := by + rw [EuclideanSpace.real_norm_sq_eq, EuclideanSpace.real_norm_sq_eq, + sum_fin_split (show d/2 ≤ d by omega)] + change (∑ i : Fin (d/2), x ⟨i.val,by omega⟩^2) ≤ _ + exact le_add_of_nonneg_right (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) + nlinarith [norm_nonneg (cubeProject d x), norm_nonneg x] + +lemma cubeProject_sub (d : ℕ) (x y : Space d) : cubeProject d (x-y) = cubeProject d x-cubeProject d y := by + ext i + rfl + +lemma cubeProject_embedding (d : ℕ) (u : Cube d) : + cubeProject d (CubeEmbedding d u) = (Real.sqrt (d/2:ℕ))⁻¹ • u.val := by + ext i + simp [cubeProject, CubeEmbedding, cubeRaw] + +lemma cubeProject_parameter_dist {d : ℕ} (hd : 2 ≤ d) (u : Cube d) (x : Space d) : + dist u.val (Real.sqrt (d/2:ℕ) • cubeProject d x) ≤ + Real.sqrt (d/2:ℕ) * dist (CubeEmbedding d u) x := by + have hr : 0 < Real.sqrt (d/2:ℕ) := Real.sqrt_pos.2 (by exact_mod_cast (show 0 < d/2 by omega)) + have he : u.val - Real.sqrt (d/2:ℕ) • cubeProject d x = + Real.sqrt (d/2:ℕ) • cubeProject d (CubeEmbedding d u-x) := by + rw [cubeProject_sub, cubeProject_embedding, smul_sub, smul_smul, mul_inv_cancel₀ hr.ne', one_smul] + rw [dist_eq_norm, he, norm_smul, Real.norm_eq_abs, abs_of_pos hr, dist_eq_norm] + exact mul_le_mul_of_nonneg_left (cubeProject_norm d _) hr.le +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/CubeSuccess.lean b/lean/OAI/Probability/MemoryPrecision/CubeSuccess.lean new file mode 100644 index 0000000000000000000000000000000000000000..196ed1eeb981dbd3ff7d888388a3592a8c467c74 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/CubeSuccess.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeArithmetic +import OAI.Probability.MemoryPrecision.KernelCube +import OAI.Probability.MemoryPrecision.Precision + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +open MemoryPrecision NoiselessRegression Policy + +lemma source_cube_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Ω → Policy d M T) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hd : 16 ≤ d) (hL : Admissible L ρ (CubePrior (by omega))) + (hM : M ≤ d^2) {ε : ℝ} (hε : 0 < ε) : + Success L ρ (CubePrior (by omega)) ε ≤ min 1 (ENNReal.ofReal + (CubeSuccessConstant^((d/2)*(BlockCount T ((d/2)/4)+1)) * ε^((d/2:ℕ)/4:ℝ))) := by + refine le_min (Policy.success_le_one L ρ (CubePrior (by omega)) ε) ?_ + have hb := (Policy.success_le_chord L ρ (CubePrior (by omega)) ε).trans + (Policy.source_cube_chord_bound L ρ hd hL hε) + have he : (T+1:ℝ≥0∞) * ENNReal.ofReal + ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4)) = + ENNReal.ofReal ((T+1:ℝ) * + ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4))) := by + rw [ENNReal.ofReal_mul (by positivity : (0:ℝ) ≤ T+1)] + congr 1 + simp [ENNReal.ofReal_add] + rw [he] at hb + apply hb.trans (ENNReal.ofReal_le_ofReal ?_) + calc + _ = ((T+1:ℝ) * ((12:ℝ)^(d/2) * CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4))) * + ε^((d/2:ℕ)/4:ℝ) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_right (cube_whole_factor hd hM T) (by positivity) + +lemma cubePrior_dimension {d₀ d : ℕ} (hd₀ : 16 ≤ d₀) (hd : d₀ ≤ d) : 2 ≤ d := + Nat.le_trans (by decide : 2 ≤ 16) (Nat.le_trans hd₀ hd) + +def CubeSuccessEstimate {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (D : ℝ) (hd : 2 ≤ d) (ε : ℝ) (K : Ω → Policy d M T) (ρ : Measure Ω) : Prop := + Policy.Success K ρ (CubePrior hd) ε ≤ min 1 (ENNReal.ofReal + (D^((d/2)*(MemoryPrecision.Kernel.BlockCount T ((d/2)/4)+1)) * ε^((d/2:ℕ)/4:ℝ))) + +def PointwisePrecisionEstimate {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (c ε : ℝ) (K : Ω → Policy d M T) (ρ : Measure Ω) : Prop := + (∀ signal : MemoryPrecision.Kernel.Sphere d, + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) / + (@OfNat.ofNat ℝ≥0∞ 3 + (@instOfNatAtLeastTwo ℝ≥0∞ 3 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) ≤ + Policy.FixedSuccess K ρ ε signal) → c*(d:ℝ)*Real.log (1/ε) ≤ (T:ℝ) + +abbrev SourceCubeStatement : Prop := + ∃ D : ℝ, Real.exp 1 ≤ D ∧ ∃ d₀ : ℕ, ∃ hd₀ : 16 ≤ d₀, ∃ c : ℝ, 0 < c ∧ + ∀ d M T : ℕ, ∀ hd : d₀ ≤ d, M ≤ d^2 → ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ K : Ω → MemoryPrecision.Kernel.Policy d M T, Policy.ModelAdmissible.{u} K ρ → + CubeSuccessEstimate.{u} D (cubePrior_dimension hd₀ hd) ε K ρ ∧ + PointwisePrecisionEstimate.{u} c ε K ρ + +theorem source_cube_success : SourceCubeStatement := by + refine ⟨CubeSuccessConstant,cubeSuccessConstant_exp,32,by norm_num, + 1/(8+20*StreamConstant*(1+1)),by have := streamConstant_pos; positivity,?_⟩ + intro d M T hd hM ε hε hε1 Ω _ ρ hρ L hL + have : IsProbabilityMeasure ρ := hρ + let : NeZero d := ⟨by omega⟩ + refine ⟨source_cube_bound L ρ (by omega) (hL _ inferInstance) hM hε, ?_⟩ + intro hs + apply Policy.source_precision L ρ hd (hL _ inferInstance) (by norm_num : (0:ℝ) < 1) + (by exact_mod_cast (by simpa using hM : M ≤ 1*d^2)) hε hε1 + exact Policy.source_uniform_of_pointwise L ρ (by omega) (hL _ inferInstance) ε hs +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/DensityPassage.lean b/lean/OAI/Probability/MemoryPrecision/DensityPassage.lean new file mode 100644 index 0000000000000000000000000000000000000000..34936e24c33b602eb833747ae88a064cc79ee614 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/DensityPassage.lean @@ -0,0 +1,313 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +section FiberSmoothing +variable {Ω Y : Type*} [MeasurableSpace Ω] [NormedAddCommGroup Y] + [MeasurableSpace Y] [BorelSpace Y] [SecondCountableTopology Y] + (γ : Measure Ω) (τ : Measure Y) [SigmaFinite τ] + +def fiberSmoothing (F : Ω × Y → ℝ≥0∞) (ρ : Y → ℝ≥0∞) (z : Ω × Y) : ℝ≥0∞ := + ∫⁻ b, ρ (z.2 - b) * F (z.1, b) ∂τ + +@[fun_prop] lemma measurable_fiberSmoothing {F : Ω × Y → ℝ≥0∞} {ρ : Y → ℝ≥0∞} + (hF : Measurable F) (hρ : Measurable ρ) : + Measurable (fiberSmoothing τ F ρ) := by + unfold fiberSmoothing + exact Measurable.lintegral_prod_right (by fun_prop) + +lemma lintegral_fiberSmoothing_test {F : Ω × Y → ℝ≥0∞} {ρ : Y → ℝ≥0∞} + (hF : Measurable F) (hρ : Measurable ρ) (f : Ω × Y → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ z, fiberSmoothing τ F ρ z * f z ∂γ.prod τ) = + ∫⁻ z, (∫⁻ y, ρ (y - z.2) * f (z.1, y) ∂τ) ∂(γ.prod τ).withDensity F := by + have hK : Measurable (fun z : Ω × Y => ∫⁻ y, ρ (y-z.2) * f (z.1,y) ∂τ) := + Measurable.lintegral_prod_right (by fun_prop) + rw [lintegral_withDensity_eq_lintegral_mul _ hF hK] + simp only [Pi.mul_apply] + rw [lintegral_prod (fun z => fiberSmoothing τ F ρ z * f z) + ((measurable_fiberSmoothing τ hF hρ).mul hf).aemeasurable, + lintegral_prod (fun z => F z * ∫⁻ y, ρ (y-z.2) * f (z.1,y) ∂τ) + (hF.mul hK).aemeasurable] + apply lintegral_congr + intro A + dsimp only [fiberSmoothing] + have hmul (y : Y) : (∫⁻ b, ρ (y-b) * F (A,b) ∂τ) * f (A,y) = + ∫⁻ b, (ρ (y-b) * F (A,b)) * f (A,y) ∂τ := + (lintegral_mul_const _ (by fun_prop)).symm + simp_rw [hmul] + rw [lintegral_lintegral_swap (by fun_prop)] + apply lintegral_congr + intro b + rw [← lintegral_const_mul _ (by fun_prop : Measurable (fun y => ρ (y-b) * f (A,y)))] + apply lintegral_congr + intro y + ring +end FiberSmoothing + +section ProjectionSmoothing +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +local instance density_reference_sigmaFinite (m : ℕ) : + SigmaFinite (matrixLabelReference (E := E) m) := by + unfold matrixLabelReference + infer_instance + +lemma lintegral_projectionSmoothing_test (ν : Measure E) [SigmaFinite ν] + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (m : ℕ) + (f : (Fin m → E) × (Fin m → ℝ) → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ z, projectionSmoothing ν φ m z * f z ∂matrixLabelReference m) = + ∫⁻ z, (∫⁻ y : Fin m → ℝ, (∏ j, φ (y j - z.2 j)) * f (z.1, y)) + ∂projectionLaw ν m := by + have hK : Measurable (fun z : (Fin m → E) × (Fin m → ℝ) => + ∫⁻ y : Fin m → ℝ, (∏ j, φ (y j-z.2 j)) * f (z.1,y)) := + Measurable.lintegral_prod_right (by fun_prop) + rw [projectionLaw, lintegral_map hK (by fun_prop), matrixLabelReference, + lintegral_prod (fun z => projectionSmoothing ν φ m z * f z) + ((measurable_projectionSmoothing ν φ hφ m).mul hf).aemeasurable, + lintegral_prod _ (by fun_prop)] + apply lintegral_congr + intro A + dsimp only [projectionSmoothing] + have hmul (y : Fin m → ℝ) : (∫⁻ t : E, ∏ j, φ (y j-⟪t,A j⟫) ∂ν) * f (A,y) = + ∫⁻ t : E, (∏ j, φ (y j-⟪t,A j⟫)) * f (A,y) ∂ν := + (lintegral_mul_const _ (by fun_prop)).symm + simp_rw [hmul] + rw [lintegral_lintegral_swap (by fun_prop)] + +lemma projectionSmoothing_ae_eq_fiberSmoothing (ν : Measure E) [SigmaFinite ν] + (m : ℕ) (F : (Fin m → E) × (Fin m → ℝ) → ℝ≥0∞) (hF : Measurable F) + (hden : (matrixLabelReference m).withDensity F = projectionLaw ν m) + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) : + projectionSmoothing ν φ m =ᵐ[matrixLabelReference m] + fiberSmoothing volume F (fun y : Fin m → ℝ => ∏ j, φ (y j)) := by + apply (withDensity_eq_iff_of_sigmaFinite + (measurable_projectionSmoothing ν φ hφ m).aemeasurable + (measurable_fiberSmoothing volume hF (by fun_prop)).aemeasurable).mp + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_withDensity_eq_lintegral_mul _ + (measurable_projectionSmoothing ν φ hφ m) hf, + lintegral_withDensity_eq_lintegral_mul _ + (measurable_fiberSmoothing volume hF (by fun_prop)) hf] + simp only [Pi.mul_apply] + rw [lintegral_projectionSmoothing_test ν φ hφ m f hf] + change _ = ∫⁻ z, fiberSmoothing volume F (fun y : Fin m → ℝ => ∏ j, φ (y j)) z * f z + ∂(Measure.pi (fun _ : Fin m => stdGaussian E)).prod volume + rw [lintegral_fiberSmoothing_test _ volume hF (by fun_prop) f hf] + + unfold matrixLabelReference at hden + rw [hden] + rfl +end ProjectionSmoothing + +def boxScalar (δ : ℝ) (t : ℝ) : ℝ≥0∞ := + (ENNReal.ofReal (2*δ))⁻¹ * (Icc (-δ) δ).indicator 1 t + +@[fun_prop] lemma measurable_boxScalar (δ : ℝ) : Measurable (boxScalar δ) := by + exact measurable_const.mul (measurable_const.indicator measurableSet_Icc) + +lemma lintegral_boxScalar {δ : ℝ} (hδ : 0 < δ) : ∫⁻ t, boxScalar δ t = 1 := by + unfold boxScalar + rw [lintegral_const_mul _ (show Measurable ((Icc (-δ) δ).indicator (1 : ℝ → ℝ≥0∞)) from + measurable_one.indicator measurableSet_Icc), lintegral_indicator measurableSet_Icc] + simp only [Pi.one_apply, lintegral_const, one_mul, Measure.restrict_apply_univ, + Real.volume_Icc, sub_neg_eq_add] + rw [← two_mul] + exact ENNReal.inv_mul_cancel (ENNReal.ofReal_ne_zero_iff.mpr (by positivity)) ENNReal.ofReal_ne_top + +lemma box_product_eq (m : ℕ) {δ : ℝ} (hδ : 0 < δ) (y : Fin m → ℝ) : + (∏ j, boxScalar δ (y j)) = + ((volume : Measure (Fin m → ℝ)) (Metric.closedBall 0 δ))⁻¹ * + (Metric.closedBall 0 δ).indicator 1 y := by + have hv : (volume : Measure (Fin m → ℝ)) (Metric.closedBall 0 δ) = + (ENNReal.ofReal (2*δ))^m := by + rw [volume_pi, closedBall_pi _ hδ.le, Measure.pi_pi] + simp [Real.closedBall_eq_Icc, ← two_mul] + rw [hv] + simp only [boxScalar, Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin, + ENNReal.inv_pow] + congr 1 + by_cases hy : y ∈ Metric.closedBall (0 : Fin m → ℝ) δ + · rw [Set.indicator_of_mem hy] + have hy' : ∀ j, y j ∈ Icc (-δ) δ := by + intro j + rw [closedBall_pi _ hδ.le] at hy + simpa [Real.closedBall_eq_Icc] using hy j (mem_univ j) + simp [hy'] + · rw [Set.indicator_of_notMem hy] + have hy' : ∃ j, y j ∉ Icc (-δ) δ := by + by_contra h + apply hy + rw [closedBall_pi _ hδ.le] + intro j _ + have hh := not_not.mp (not_exists.mp h j) + simpa [Real.closedBall_eq_Icc] using hh + obtain ⟨j,hj⟩ := hy' + exact Finset.prod_eq_zero (Finset.mem_univ j) (Set.indicator_of_notMem hj _) + +section Differentiation +variable {Ω : Type*} [MeasurableSpace Ω] + +lemma fiberSmoothing_box_eq_average (m : ℕ) + (F : Ω × (Fin m → ℝ) → ℝ≥0∞) (hF : Measurable F) + {δ : ℝ} (hδ : 0 < δ) (A : Ω) (y : Fin m → ℝ) : + fiberSmoothing volume F (fun x : Fin m → ℝ => ∏ j, boxScalar δ (x j)) (A,y) = + (∫⁻ b in Metric.closedBall y δ, F (A,b)) / + (volume : Measure (Fin m → ℝ)) (Metric.closedBall y δ) := by + unfold fiberSmoothing + simp_rw [box_product_eq m hδ] + have he (b : Fin m → ℝ) : + (Metric.closedBall (0 : Fin m → ℝ) δ).indicator (1 : (Fin m → ℝ) → ℝ≥0∞) (y-b) * F (A,b) = + (Metric.closedBall y δ).indicator (fun b => F (A,b)) b := by + have hb : y-b ∈ Metric.closedBall (0 : Fin m → ℝ) δ ↔ b ∈ Metric.closedBall y δ := by + simp [Metric.mem_closedBall, dist_eq_norm, norm_sub_rev] + by_cases h : b ∈ Metric.closedBall y δ + · rw [Set.indicator_of_mem (hb.mpr h), Set.indicator_of_mem h]; simp + · rw [Set.indicator_of_notMem (mt hb.mp h), Set.indicator_of_notMem h]; simp + simp_rw [mul_assoc, he] + rw [lintegral_const_mul _ (show Measurable ((Metric.closedBall y δ).indicator + (fun b => F (A,b))) from (hF.comp (measurable_const.prodMk measurable_id)).indicator + Metric.isClosed_closedBall.measurableSet), lintegral_indicator Metric.isClosed_closedBall.measurableSet, + div_eq_mul_inv, Measure.addHaar_closedBall_center volume y δ, mul_comm] + +lemma ae_tendsto_fiberSmoothing_box (γ : Measure Ω) [SigmaFinite γ] (m : ℕ) + (F : Ω × (Fin m → ℝ) → ℝ≥0∞) (hF : Measurable F) + (hfin : (∫⁻ z, F z ∂γ.prod volume) ≠ ∞) : + ∀ᵐ z ∂γ.prod volume, + Tendsto (fun k : ℕ => fiberSmoothing volume F + (fun x : Fin m → ℝ => ∏ j, boxScalar (1 / ((k:ℝ)+1)) (x j)) z) + atTop (𝓝 (F z)) := by + have hmeas (k : ℕ) : Measurable (fiberSmoothing volume F + (fun x : Fin m → ℝ => ∏ j, boxScalar (1 / ((k:ℝ)+1)) (x j))) := + measurable_fiberSmoothing volume hF (by fun_prop) + rw [Measure.ae_prod_iff_ae_ae (measurableSet_tendsto_fun hmeas hF)] + have hinner : (∫⁻ A, ∫⁻ y : Fin m → ℝ, F (A,y) ∂volume ∂γ) ≠ ∞ := by + rwa [← lintegral_prod _ hF.aemeasurable] + filter_upwards [ae_lt_top (Measurable.lintegral_prod_right + (show Measurable (fun z : Ω × (Fin m → ℝ) => F (z.1,z.2)) from hF)) hinner] with A hA + have hFA : Measurable (fun y : Fin m → ℝ => F (A,y)) := + hF.comp (measurable_const.prodMk measurable_id) + filter_upwards [(Besicovitch.vitaliFamily (volume : Measure (Fin m → ℝ))).ae_tendsto_lintegral_div + hFA.aemeasurable hA.ne] with y hy + have hδ : Tendsto (fun k : ℕ => 1 / ((k:ℝ)+1)) atTop (𝓝[>] (0:ℝ)) := + tendsto_nhdsWithin_iff.mpr ⟨tendsto_one_div_add_atTop_nhds_zero_nat, + Filter.Eventually.of_forall (fun k => by change 0 < 1 / ((k:ℝ)+1); positivity)⟩ + convert (hy.comp (Besicovitch.tendsto_filterAt volume y)).comp hδ using 1 + ext k + exact fiberSmoothing_box_eq_average m F hF (by positivity) A y +end Differentiation + +section MomentPassage +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +local instance passage_reference_sigmaFinite (m : ℕ) : + SigmaFinite (matrixLabelReference (E := E) m) := by + unfold matrixLabelReference + infer_instance +local instance passage_projection_finite (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) : + IsFiniteMeasure (projectionLaw ν m) := by + unfold projectionLaw + infer_instance + +lemma projectionLaw_set_bound_of_moment (ν : Measure E) [IsFiniteMeasure ν] + (m n : ℕ) (hn : 1 ≤ n) (C : ℝ≥0∞) (hC : C ≠ ∞) + (hbound : ∀ φ : ℝ → ℝ≥0∞, Measurable φ → (∫⁻ x, φ x = 1) → + (∫⁻ Ay, projectionSmoothing ν φ m Ay ^ (n+1) ∂matrixLabelReference m) ≤ C) + (S : Set ((Fin m → E) × (Fin m → ℝ))) : + projectionLaw ν m S ≤ C^(1 / ((n : ℝ) + 1)) * + (matrixLabelReference (E := E) m S)^(1 - 1 / ((n : ℝ) + 1)) := by + have hp : 1 < (n : ℝ) + 1 := by exact_mod_cast (by omega : 1 < n + 1) + have hα : 0 < 1 - 1 / ((n : ℝ) + 1) := by + exact sub_pos.mpr ((div_lt_one (by positivity)).mpr hp) + have := matrixLabelReference_outerRegular (E := E) m + apply measure_apply_le_of_isOpen _ _ (ENNReal.rpow_ne_top_of_nonneg (by positivity) hC) hα + intro U hU + rw [← gaussianCoupling_map_noisyObservation_zero ν m] + apply map_apply_open_le_of_tendsto (gaussianCoupling ν m) + (matrixLabelReference (E := E) m) (noisyObservation m 0) + (fun k => noisyObservation m (1 / ((k : ℝ) + 1))) + (measurable_noisyObservation m 0) (fun k => measurable_noisyObservation m _) + (tendsto_noisyObservation m) _ _ (U := U) (hU := hU) + intro k V hV + have hδ : (1 / ((k : ℝ) + 1)) ≠ 0 := by positivity + rw [gaussianCoupling_map_noisyObservation ν m _ hδ] + apply withDensity_apply_le_moment _ _ + (measurable_projectionSmoothing _ _ (measurable_gaussianPDF _ _) _) hp _ _ hV.measurableSet + have hv : (NNReal.mk ((1 / ((k : ℝ) + 1)) ^ 2) + (sq_nonneg (1 / ((k : ℝ) + 1)))) ≠ 0 := by + rw [← NNReal.coe_ne_zero] + exact pow_ne_zero 2 hδ + simpa only [← ENNReal.rpow_natCast, Nat.cast_add, Nat.cast_one] using + hbound (gaussianPDF 0 (NNReal.mk ((1 / ((k : ℝ) + 1)) ^ 2) + (sq_nonneg (1 / ((k : ℝ) + 1))))) (measurable_gaussianPDF _ _) + (lintegral_gaussianPDF_eq_one _ hv) + +lemma projectionLaw_ac_of_moment (ν : Measure E) [IsFiniteMeasure ν] + (m n : ℕ) (hn : 1 ≤ n) (C : ℝ≥0∞) (hC : C ≠ ∞) + (hbound : ∀ φ : ℝ → ℝ≥0∞, Measurable φ → (∫⁻ x, φ x = 1) → + (∫⁻ Ay, projectionSmoothing ν φ m Ay ^ (n+1) ∂matrixLabelReference m) ≤ C) : + projectionLaw ν m ≪ matrixLabelReference m := by + intro S hS + have hh := projectionLaw_set_bound_of_moment ν m n hn C hC hbound S + have hα : 0 < 1 - 1 / ((n : ℝ) + 1) := by + have hn' : (1:ℝ) ≤ n := by exact_mod_cast hn + exact sub_pos.mpr ((div_lt_one (by positivity)).mpr (by linarith)) + rw [hS, ENNReal.zero_rpow_of_pos hα, mul_zero] at hh + exact le_zero_iff.mp hh + +lemma projectionLaw_rnDeriv_moment (ν : Measure E) [IsFiniteMeasure ν] + (m n : ℕ) (hn : 1 ≤ n) (C : ℝ≥0∞) (hC : C ≠ ∞) + (hbound : ∀ φ : ℝ → ℝ≥0∞, Measurable φ → (∫⁻ x, φ x = 1) → + (∫⁻ Ay, projectionSmoothing ν φ m Ay ^ (n+1) ∂matrixLabelReference m) ≤ C) : + (∫⁻ Ay, ((projectionLaw ν m).rnDeriv (matrixLabelReference m) Ay)^(n+1) + ∂matrixLabelReference m) ≤ C := by + let F := (projectionLaw ν m).rnDeriv (matrixLabelReference m) + have hF : Measurable F := Measure.measurable_rnDeriv _ _ + have hden : (matrixLabelReference m).withDensity F = projectionLaw ν m := + Measure.withDensity_rnDeriv_eq _ _ (projectionLaw_ac_of_moment ν m n hn C hC hbound) + let f : ℕ → ((Fin m → E) × (Fin m → ℝ)) → ℝ≥0∞ := fun k => + projectionSmoothing ν (boxScalar (1/((k:ℝ)+1))) m + have hf (k : ℕ) : Measurable (f k) := + measurable_projectionSmoothing ν _ (measurable_boxScalar _) m + have heq (k : ℕ) : f k =ᵐ[matrixLabelReference m] + fiberSmoothing volume F (fun y : Fin m → ℝ => ∏ j, boxScalar (1/((k:ℝ)+1)) (y j)) := + projectionSmoothing_ae_eq_fiberSmoothing ν m F hF hden _ (measurable_boxScalar _) + have ht : ∀ᵐ Ay ∂matrixLabelReference m, Tendsto (fun k => f k Ay) atTop (𝓝 (F Ay)) := by + filter_upwards [ae_all_iff.mpr heq, + ae_tendsto_fiberSmoothing_box (Measure.pi (fun _ : Fin m => stdGaussian E)) m F hF + (Measure.lintegral_rnDeriv_lt_top (projectionLaw ν m) (matrixLabelReference m)).ne] + with Ay he ht + exact ht.congr (fun k => (he k).symm) + calc + _ = ∫⁻ Ay, atTop.liminf (fun k => (f k Ay)^(n+1)) ∂matrixLabelReference m := by + apply lintegral_congr_ae + filter_upwards [ht] with Ay hAy + exact (((ENNReal.continuous_pow (n+1)).tendsto _ |>.comp hAy).liminf_eq).symm + _ ≤ atTop.liminf (fun k => ∫⁻ Ay, (f k Ay)^(n+1) ∂matrixLabelReference m) := + lintegral_liminf_le (fun k => (hf k).pow_const _) + _ ≤ C := by + apply liminf_le_of_frequently_le (hu_le := by isBoundedDefault) + exact (Filter.Eventually.of_forall (fun k => + hbound _ (measurable_boxScalar _) (lintegral_boxScalar (by positivity)))).frequently +end MomentPassage + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/DensityUniqueness.lean b/lean/OAI/Probability/MemoryPrecision/DensityUniqueness.lean new file mode 100644 index 0000000000000000000000000000000000000000..c928c750ea66ba31f204db8ae6a955a7661bb894 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/DensityUniqueness.lean @@ -0,0 +1,95 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.FiberDensity + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma piGaussianConvolution_withDensity {m : ℕ} (F : (Fin m → ℝ) → ℝ≥0∞) + (hF : Measurable F) (δ : ℝ) (y : Fin m → ℝ) : + PiGaussianConvolution (volume.withDensity F) δ y = + (∫⁻ x, (∏ j, gaussianPDF 0 ⟨δ^2,sq_nonneg δ⟩ (y j-x j)) * F x).toReal := by + unfold PiGaussianConvolution + rw [integral_eq_lintegral_of_nonneg_ae + (Eventually.of_forall (fun x => Finset.prod_nonneg (fun j _ => gaussianPDFReal_nonneg _ _ _))) + ((show Continuous (fun x : Fin m → ℝ => ∏ j, + gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (y j-x j)) from + by unfold gaussianPDFReal; fun_prop).aestronglyMeasurable), + lintegral_withDensity_eq_lintegral_mul _ hF (by fun_prop)] + congr 1 + apply lintegral_congr + intro x + simp only [Pi.mul_apply, gaussianPDF] + rw [ENNReal.ofReal_prod_of_nonneg (fun j _ => + gaussianPDFReal_nonneg 0 ⟨δ^2,sq_nonneg δ⟩ (y j-x j)), mul_comm] + +lemma ae_tendsto_fiberGaussian {Ω : Type*} [MeasurableSpace Ω] (γ : Measure Ω) + [SigmaFinite γ] {m : ℕ} (hm : 1 ≤ m) + (F : Ω × (Fin m → ℝ) → ℝ≥0∞) (hF : Measurable F) + (hfin : (∫⁻ z, F z ∂γ.prod volume) ≠ ∞) : + ∀ᵐ z ∂γ.prod volume, Tendsto + (fun i : ℕ => (fiberSmoothing volume F + (fun y : Fin m → ℝ => ∏ j, gaussianPDF 0 + ⟨(1/(i:ℝ))^2,sq_nonneg _⟩ (y j)) z).toReal) + atTop (𝓝 (F z).toReal) := by + have hmeas (i : ℕ) : Measurable (fun z => (fiberSmoothing volume F + (fun y : Fin m → ℝ => ∏ j, gaussianPDF 0 + ⟨(1/(i:ℝ))^2,sq_nonneg _⟩ (y j)) z).toReal) := + (measurable_fiberSmoothing volume hF (by fun_prop)).ennreal_toReal + rw [Measure.ae_prod_iff_ae_ae (measurableSet_tendsto_fun hmeas hF.ennreal_toReal)] + have hinner : (∫⁻ A, ∫⁻ y : Fin m → ℝ, F (A,y) ∂volume ∂γ) ≠ ∞ := by + rwa [← lintegral_prod _ hF.aemeasurable] + filter_upwards [ae_lt_top (Measurable.lintegral_prod_right + (show Measurable (fun z : Ω × (Fin m → ℝ) => F (z.1,z.2)) from hF)) hinner] with A hA + let ν : Measure (Fin m → ℝ) := volume.withDensity (fun y => F (A,y)) + have hFA : Measurable (fun y : Fin m → ℝ => F (A,y)) := + hF.comp (measurable_const.prodMk measurable_id) + let : IsFiniteMeasure ν := isFiniteMeasure_withDensity hA.ne + have hac : ν ≪ volume := withDensity_absolutelyContinuous _ _ + have hRN := Measure.rnDeriv_withDensity volume hFA + filter_upwards [ae_tendsto_piGaussianConvolution hm ν hac, hRN] with y hy hyRN + rw [hyRN] at hy + convert hy.comp reciprocal_nat_tendsto using 1 + ext i + exact (piGaussianConvolution_withDensity (fun y => F (A,y)) hFA _ y).symm + +lemma pointwiseDensity_ae_eq {d m : ℕ} (hm : 1 ≤ m) (μ : Measure (Space d)) + [IsFiniteMeasure μ] (F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ) + (hFm : Measurable F) (hF0 : ∀ x, 0 ≤ F x) + (hden : (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) = + ProjectionLaw μ m) : + PointwiseDensity μ m =ᵐ[MatrixLabelReference d m] F := by + have hfin : (∫⁻ z, ENNReal.ofReal (F z) ∂MatrixLabelReference d m) ≠ ∞ := by + have he := congrArg (fun ν => ν Set.univ) hden + rw [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] at he + rw [he] + let : IsFiniteMeasure (ProjectionLaw μ m) := by unfold ProjectionLaw; infer_instance + exact measure_ne_top _ _ + have ht := ae_tendsto_fiberGaussian + (Measure.pi (fun _ : Fin m => stdGaussian (Space d))) hm + (fun x => ENNReal.ofReal (F x)) hFm.ennreal_ofReal hfin + have he (i : ℕ) := projectionSmoothing_ae_eq_fiberSmoothing μ m + (fun x => ENNReal.ofReal (F x)) hFm.ennreal_ofReal hden + (gaussianPDF 0 ⟨(1/(i:ℝ))^2,sq_nonneg _⟩) (measurable_gaussianPDF _ _) + filter_upwards [ht, ae_all_iff.mpr he] with x hx hxe + apply PointwiseDensity_eq_of_tendsto + rw [ENNReal.toReal_ofReal (hF0 x)] at hx + convert hx using 1 + ext i + rw [GaussianRegularization_eq_toReal μ m _, hxe i] +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/EllipsoidSuccess.lean b/lean/OAI/Probability/MemoryPrecision/EllipsoidSuccess.lean new file mode 100644 index 0000000000000000000000000000000000000000..4febcd9edd9744e585bc930819be427a1f9f7c0d --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/EllipsoidSuccess.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.SuccessArithmetic +import OAI.Probability.MemoryPrecision.ZeroHorizon + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma chord_real_coefficient {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) + {α : ℝ} (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) : + uniformChordSuccess L ρ ε ≤ ENNReal.ofReal + ((T+1:ℝ) * ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d (2^M)^BlockCount T (d/8))) := by + apply (chord_real_bound L ρ hL hd hε hαlo hαhi).trans_eq + rw [ENNReal.ofReal_mul (by positivity : (0:ℝ) ≤ T+1)] + congr 1 + simp [ENNReal.ofReal_add] + +lemma chord_half_sphere_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1/10) : + uniformChordSuccess L ρ ε ≤ ENNReal.ofReal + (4^d * ε^(((d:ℝ)-1)/2) * + (SuccessConstant^d * (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^BlockCount T (d/8)) := by + by_cases hT : T = 0 + · subst T + simp only [blockCount_zero, pow_zero, mul_one] + exact (chord_zero_bound L ρ hL (by omega) hε).trans + (ENNReal.ofReal_le_ofReal (terminal_angular_zero_bound hd hε hε1)) + · have hb := chord_real_coefficient L ρ hL hd hε (le_refl (((d:ℝ)-1)/2)) (by linarith) + have he : (d:ℝ)-1-((d:ℝ)-1)/2 = ((d:ℝ)-1)/2 := by ring + rw [he] at hb + apply hb.trans (ENNReal.ofReal_le_ofReal ?_) + have hN : 1 ≤ 2^M := one_le_pow₀ (by norm_num) + have hNK : 2^M ≤ (d/8+2)*2^M := by + simp + have hs := stopping_step_bound_three hd hN hNK (by omega : 0 < T) + calc + _ = (4^d * ε^(((d:ℝ)-1)/2)) * (3*((T+1:ℝ)*RealStep d (2^M)^BlockCount T (d/8))) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hs (by positivity) + +lemma chord_half_ambient_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) : + uniformChordSuccess L ρ ε ≤ ENNReal.ofReal + (12^d * ε^((d:ℝ)/2-1) * + (SuccessConstant^d * (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^BlockCount T (d/8)) := by + have hb := chord_real_coefficient L ρ hL hd hε (by linarith : ((d:ℝ)-1)/2 ≤ (d:ℝ)/2) le_rfl + have he : (d:ℝ)-1-(d:ℝ)/2 = (d:ℝ)/2-1 := by ring + rw [he] at hb + apply hb.trans (ENNReal.ofReal_le_ofReal ?_) + have hN : 1 ≤ 2^M := one_le_pow₀ (by norm_num) + have hNK : 2^M ≤ (2*(d/8)+4)*2^M := by + simp + have hR := realStep_pos d hN + have hs := stopping_step_bound hd hN hNK T + have hSp := stepConstant_pos + have hK : 2*StepConstant ≤ SuccessConstant := by dsimp [SuccessConstant]; linarith + have hroot : 0 ≤ (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)) := by positivity + have hbase := mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (by positivity : 0 ≤ 2*StepConstant) hK d) hroot + have hpow := pow_le_pow_left₀ (by positivity : 0 ≤ (2*StepConstant)^d * + (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ))) hbase (BlockCount T (d/8)) + calc + _ = ((3*4^d:ℝ)*ε^((d:ℝ)/2-1))*((T+1:ℝ)*RealStep d (2^M)^BlockCount T (d/8)) := by ring + _ ≤ _ := mul_le_mul + (mul_le_mul_of_nonneg_right (cap_constant_le (by omega : 1 ≤ d)) (by positivity)) + (hs.trans hpow) (by positivity) (by positivity) + +def EllipsoidSuccessStatement : Prop := + ∃ C C₀ : ℝ, 1 ≤ C ∧ 1 ≤ C₀ ∧ + ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Learner d M T Ω, L.Admissible ρ → + L.uniformSuccess ρ ε ≤ min 1 (ENNReal.ofReal + (4^d * ε^(((d:ℝ)-1)/2) * + (C^d * (((d/8+2)*2^M : ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^(BlockCount T (d/8)))) ∧ + uniformChordSuccess L ρ ε ≤ min 1 (ENNReal.ofReal + (C₀^d * ε^((d:ℝ)/2-1) * + (C^d * (((2*(d/8)+4)*2^M : ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^(BlockCount T (d/8)))) ∧ + {z : UnitSphere d × (Ω × Samples d T) | + Learner.angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} ⊆ + {z | dist (L.estimate z.1 z.2.1 z.2.2).val z.1.val ≤ ε} + +theorem ellipsoid_success : EllipsoidSuccessStatement := by + refine ⟨SuccessConstant, 12, successConstant_one, by norm_num, ?_⟩ + intro d M T hd ε hε hε1 Ω _ ρ hρ L hL + have : IsProbabilityMeasure ρ := hρ + let : NeZero d := ⟨by omega⟩ + refine ⟨le_min ?_ ?_, le_min ?_ ?_, angular_event_subset_chord L ε⟩ + · exact prob_le_one + · exact (angular_le_chord L ρ ε).trans (chord_half_sphere_bound L ρ hL hd hε hε1) + · exact prob_le_one + · exact chord_half_ambient_bound L ρ hL hd hε +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/FiberDensity.lean b/lean/OAI/Probability/MemoryPrecision/FiberDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..f999b6b0808dfcf81545492c6d7e1a7ad8355d13 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/FiberDensity.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.GaussianConvolution +import OAI.Probability.MemoryPrecision.PointwiseDensity +import OAI.Probability.MemoryPrecision.SphericalProjection + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def PiGaussianConvolution {m : ℕ} (ν : Measure (Fin m → ℝ)) (δ : ℝ) (y : Fin m → ℝ) : ℝ := + ∫ x, ∏ j, gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (y j - x j) ∂ν + +lemma piGaussianConvolution_eq {m : ℕ} (ν : Measure (Fin m → ℝ)) (δ : ℝ) (y : Fin m → ℝ) : + PiGaussianConvolution ν δ y = + GaussianConvolution (ν.map (WithLp.toLp 2)) δ (WithLp.toLp 2 y) := by + unfold GaussianConvolution + rw [integral_map (WithLp.measurable_toLp 2 (Fin m → ℝ)).aemeasurable + ((show Continuous (fun x : Space m => GaussianKernel m δ (WithLp.toLp 2 y - x)) from + (gaussianKernel_continuous m δ).comp (continuous_const.sub continuous_id)).aestronglyMeasurable)] + rfl + +lemma ae_tendsto_piGaussianConvolution {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Fin m → ℝ)) + [IsFiniteMeasure ν] (hν : ν ≪ volume) : + ∀ᵐ y ∂(volume : Measure (Fin m → ℝ)), Tendsto (fun δ : ℝ => PiGaussianConvolution ν δ y) + (𝓝[>] (0:ℝ)) (𝓝 ((ν.rnDeriv volume y).toReal)) := by + let e := MeasurableEquiv.toLp 2 (Fin m → ℝ) + have hp : MeasurePreserving e volume volume := PiLp.volume_preserving_toLp (Fin m) + have hac : ν.map e ≪ volume := by + rw [← hp.map_eq] + exact hν.map e.measurable + have ht := ae_tendsto_gaussianConvolution hm (ν.map e) hac + have ht' : ∀ᵐ y ∂(volume : Measure (Fin m → ℝ)), + Tendsto (fun δ : ℝ => GaussianConvolution (ν.map e) δ (e y)) + (𝓝[>] (0:ℝ)) (𝓝 (((ν.map e).rnDeriv volume (e y)).toReal)) := by + have ht0 : ∀ᵐ y ∂(volume.map e), + Tendsto (fun δ : ℝ => GaussianConvolution (ν.map e) δ y) + (𝓝[>] (0:ℝ)) (𝓝 (((ν.map e).rnDeriv volume y).toReal)) := by + rwa [hp.map_eq] + exact e.measurableEmbedding.ae_map_iff.mp ht0 + have hRN := e.measurableEmbedding.rnDeriv_map ν volume + rw [hp.map_eq] at hRN + filter_upwards [ht', hRN] with y hy hyRN + rw [hyRN] at hy + simpa only [piGaussianConvolution_eq, e, MeasurableEquiv.coe_toLp] using hy + +lemma GaussianRegularization_eq_convolution {d m : ℕ} (μ : Measure (Space d)) + (A : Fin m → Space d) (δ : ℝ) (y : Fin m → ℝ) : + GaussianRegularization μ m δ (A,y) = + PiGaussianConvolution (μ.map (fun s => fun j => ⟪s,A j⟫)) δ y := by + unfold PiGaussianConvolution + rw [integral_map (by fun_prop) + (((show Continuous (fun x : Fin m → ℝ => ∏ j, + gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (y j - x j)) from + by unfold gaussianPDFReal; fun_prop)).aestronglyMeasurable)] + rfl + +lemma ae_tendsto_GaussianRegularization {d m : ℕ} (hm : 1 ≤ m) (μ : Measure (Space d)) + [IsFiniteMeasure μ] (A : Fin m → Space d) + (hA : μ.map (fun s => fun j => ⟪s,A j⟫) ≪ (volume : Measure (Fin m → ℝ))) : + ∀ᵐ y ∂(volume : Measure (Fin m → ℝ)), Tendsto + (fun δ : ℝ => GaussianRegularization μ m δ (A,y)) (𝓝[>] (0:ℝ)) + (𝓝 (((μ.map (fun s => fun j => ⟪s,A j⟫)).rnDeriv volume y).toReal)) := by + simpa only [GaussianRegularization_eq_convolution] using + ae_tendsto_piGaussianConvolution hm (μ.map (fun s => fun j => ⟪s,A j⟫)) hA + +lemma reciprocal_nat_tendsto : + Tendsto (fun i : ℕ => 1/(i:ℝ)) atTop (𝓝[>] (0:ℝ)) := by + refine tendsto_nhdsWithin_iff.mpr ⟨tendsto_one_div_atTop_nhds_zero_nat, ?_⟩ + filter_upwards [eventually_gt_atTop (0:ℕ)] with i hi + change 0 < 1/(i:ℝ) + positivity + +lemma pointwiseDensity_fiber {d m : ℕ} (hm : 1 ≤ m) (μ : Measure (Space d)) + [IsFiniteMeasure μ] (A : Fin m → Space d) + (hA : μ.map (fun s => fun j => ⟪s,A j⟫) ≪ (volume : Measure (Fin m → ℝ))) : + (volume : Measure (Fin m → ℝ)).withDensity + (fun y => ENNReal.ofReal (PointwiseDensity μ m (A,y))) = + μ.map (fun s => fun j => ⟪s,A j⟫) := by + let ν := μ.map (fun s => fun j => ⟪s,A j⟫) + have he : (fun y => ENNReal.ofReal (PointwiseDensity μ m (A,y))) =ᵐ[volume] + ν.rnDeriv volume := by + filter_upwards [ae_tendsto_GaussianRegularization hm μ A hA, ν.rnDeriv_lt_top volume] + with y hy hyfin + rw [PointwiseDensity_eq_of_tendsto μ (A,y) (hy.comp reciprocal_nat_tendsto)] + exact ENNReal.ofReal_toReal hyfin.ne + rw [withDensity_congr_ae he] + exact Measure.withDensity_rnDeriv_eq _ _ hA + +lemma pointwiseDensity_fullRank {d m : ℕ} (hd : 2 ≤ d) (hm : 1 ≤ m) (hmd : m < d) + (μ : Measure (Space d)) [IsFiniteMeasure μ] (hμ : μ ≪ UniformSphere d) + (A : Fin m → Space d) (hA : LinearIndependent ℝ A) : + (volume : Measure (Fin m → ℝ)).withDensity + (fun y => ENNReal.ofReal (PointwiseDensity μ m (A,y))) = + μ.map (fun s => fun j => ⟪s,A j⟫) := + pointwiseDensity_fiber hm μ A (spherical_projection_ac hd hmd A hA μ hμ) +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/FiniteDensity.lean b/lean/OAI/Probability/MemoryPrecision/FiniteDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..090842128141f3b535edba321f7545e4c77d4cd3 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/FiniteDensity.lean @@ -0,0 +1,281 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.DensityPassage +import OAI.Probability.MemoryPrecision.SharpGaussian + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def MatrixLabelReference (d m : ℕ) : @Measure ((Fin m → Space d) × (Fin m → ℝ)) + (@MeasurableSpace.prod (Fin m → Space d) (Fin m → ℝ) + (@MeasurableSpace.pi (Fin m) (fun _ => Space d) + (fun _ => WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ))) + inferInstance) := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let euclideanMeasurable := WithLp.measurableSpace exponent (Fin d → ℝ) + let rowMeasurable := @MeasurableSpace.pi (Fin m) (fun _ => Space d) + (fun _ => euclideanMeasurable) + let rowLaw := @Measure.pi (Fin m) (fun _ => Space d) inferInstance + (fun _ => euclideanMeasurable) + (fun _ => @stdGaussian (Space d) + (PiLp.normedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ)) + inferInstance euclideanMeasurable) + @Measure.prod _ _ rowMeasurable inferInstance rowLaw volume + +def ProjectionLaw {d : ℕ} + (μ : @Measure (Space d) + (WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ))) + (m : ℕ) : @Measure ((Fin m → Space d) × (Fin m → ℝ)) + (@MeasurableSpace.prod (Fin m → Space d) (Fin m → ℝ) + (@MeasurableSpace.pi (Fin m) (fun _ => Space d) + (fun _ => WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ))) + inferInstance) := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let euclideanMeasurable := WithLp.measurableSpace exponent (Fin d → ℝ) + let rowMeasurable := @MeasurableSpace.pi (Fin m) (fun _ => Space d) + (fun _ => euclideanMeasurable) + let rowLaw := @Measure.pi (Fin m) (fun _ => Space d) inferInstance + (fun _ => euclideanMeasurable) + (fun _ => @stdGaussian (Space d) + (PiLp.normedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ)) + inferInstance euclideanMeasurable) + @Measure.map ((Fin m → Space d) × Space d) ((Fin m → Space d) × (Fin m → ℝ)) + (@MeasurableSpace.prod _ _ rowMeasurable euclideanMeasurable) + (@MeasurableSpace.prod _ _ rowMeasurable inferInstance) + (fun pair => (pair.1, fun index => @inner ℝ (Space d) + (@InnerProductSpace.toInner ℝ (Space d) _ + (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))) + pair.2 (pair.1 index))) + (@Measure.prod _ _ rowMeasurable euclideanMeasurable rowLaw μ) +def ProjectedEllipsoid {d m : ℕ} (z : Space d) (R : ℝ) : + Set ((Fin m → Space d) × (Fin m → ℝ)) := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let euclideanInner := @InnerProductSpace.toInner ℝ (Space d) _ + (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ)) + {pair | ∃ displacement ∈ @Metric.closedBall (Space d) + (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ)) + (WithLp.toLp exponent (fun _ => (0 : ℝ))) R, + pair.2 = fun index => @inner ℝ (Space d) euclideanInner z (pair.1 index) + + @inner ℝ (Space d) euclideanInner displacement (pair.1 index)} +def ProjectionNormScale (m p : ℕ) (H β R : ℝ) : ℝ := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + (two * Real.pi) ^ (-(m : ℝ) * ((p : ℝ)-1) / (two*(p : ℝ))) * H * + R ^ (β - (m : ℝ)*(1-1/(p : ℝ))) * + (∏ j ∈ Finset.range (p-1), J β m j) ^ (1/(p : ℝ)) + +lemma isClosed_projectedEllipsoid {d m : ℕ} (z : Space d) (R : ℝ) : + IsClosed (ProjectedEllipsoid (m := m) z R) := by + let K := Metric.closedBall (0 : Space d) R + have hK : IsCompact K := isCompact_closedBall _ _ + let : CompactSpace K := isCompact_iff_compactSpace.mp hK + let D : Set (((Fin m → Space d) × (Fin m → ℝ)) × K) := + {w | w.1.2 = fun j => ⟪z, w.1.1 j⟫ + ⟪(w.2 : Space d), w.1.1 j⟫} + have hD : IsClosed D := isClosed_eq (by fun_prop) (by fun_prop) + have he : ProjectedEllipsoid (m := m) z R = Prod.fst '' D := by + ext Ay + constructor + · rintro ⟨v, hv, he⟩ + exact ⟨(Ay, ⟨v,hv⟩), he, rfl⟩ + · rintro ⟨⟨Ay,v⟩, hv, rfl⟩ + exact ⟨v, v.property, hv⟩ + rw [he] + exact isClosedMap_fst_of_compactSpace D hD + +lemma projectionLaw_ellipsoid_compl {d m : ℕ} (μ : Measure (Space d)) [IsFiniteMeasure μ] + {z : Space d} {R : ℝ} (hsupport : μ.support ⊆ Metric.closedBall z R) : + projectionLaw μ m (ProjectedEllipsoid z R)ᶜ = 0 := by + rw [projectionLaw, Measure.map_apply (by fun_prop) + (isClosed_projectedEllipsoid z R).measurableSet.compl] + apply measure_mono_null (t := Set.univ ×ˢ μ.supportᶜ) + · rintro ⟨A,s⟩ hs + refine ⟨mem_univ _, ?_⟩ + intro hss + apply hs + refine ⟨s-z, ?_, ?_⟩ + · change dist (s - z) (0 : Space d) ≤ R + simpa [Metric.mem_closedBall, dist_eq_norm] using hsupport hss + · ext j + simp [inner_sub_left] + · rw [Measure.prod_prod] + simp [μ.measure_compl_support] + +lemma projectionNormScale_pos {m p : ℕ} {H β R : ℝ} (hp : 2 ≤ p) (hH : 0 < H) + (hR : 0 < R) (hgap : (m:ℝ)+(p:ℝ)-2 < β) : + 0 < ProjectionNormScale m p H β R := by + have hJ : 0 < ∏ j ∈ Finset.range (p-1), J β m j := by + apply Finset.prod_pos + intro j hj + apply J_pos + have hj' : j+2 ≤ p := by have := Finset.mem_range.mp hj; omega + have hj'' : (j:ℝ)+2 ≤ p := by exact_mod_cast hj' + linarith + unfold ProjectionNormScale + positivity + +lemma moment_root_eq_scale {m p : ℕ} {H β R : ℝ} (hp : 2 ≤ p) (hH : 0 < H) + (hR : 0 < R) (hgap : (m:ℝ)+(p:ℝ)-2 < β) : + (gaussianPeak ^ ((p-1)*m) * ENNReal.ofReal + (H^p * R^(β*(p:ℝ)-(m:ℝ)*((p-1:ℕ):ℝ)) * ∏ j : Fin (p-1), J β m j)) ^ (1/(p:ℝ)) = + ENNReal.ofReal (ProjectionNormScale m p H β R) := by + have hp0 : (p:ℝ) ≠ 0 := by exact_mod_cast (by omega : p ≠ 0) + have hp1 : 1 ≤ p := by omega + have hprod : 0 < ∏ j : Fin (p-1), J β m j := by + apply Finset.prod_pos + intro j _ + apply J_pos + have hj : (j:ℝ)+2 ≤ p := by exact_mod_cast (show (j:ℕ)+2 ≤ p by have := j.isLt; omega) + linarith + have hpi : 0 < 2 * Real.pi := by positivity + rw [ENNReal.mul_rpow_of_nonneg _ _ (by positivity), gaussianPeak, + ← ENNReal.ofReal_pow (by positivity), ENNReal.ofReal_rpow_of_pos (by positivity), + ENNReal.ofReal_rpow_of_pos (by positivity), ← ENNReal.ofReal_mul (by positivity)] + congr 1 + rw [Real.mul_rpow (by positivity : 0 ≤ H^p * R^(β*p-m*((p-1:ℕ):ℝ))) hprod.le, + Real.mul_rpow (by positivity : 0 ≤ H^p) (by positivity), + ← Real.rpow_natCast_mul hH.le, mul_one_div_cancel hp0, Real.rpow_one, + ← Real.rpow_mul hR.le, + ← Real.rpow_natCast_mul (by positivity : 0 ≤ (Real.sqrt (2*Real.pi))⁻¹), + Real.inv_rpow (by positivity), Real.sqrt_eq_rpow, ← Real.rpow_mul hpi.le, + ← Real.rpow_neg hpi.le] + have he1 : -(1/2 * (((p-1:ℕ):ℝ)*(m:ℝ) * (1/(p:ℝ)))) = + -(m:ℝ)*((p:ℝ)-1)/(2*(p:ℝ)) := by rw [Nat.cast_sub hp1]; push_cast; ring + have he2 : (β*(p:ℝ)-(m:ℝ)*((p-1:ℕ):ℝ)) * (1/(p:ℝ)) = + β-(m:ℝ)*(1-1/(p:ℝ)) := by rw [Nat.cast_sub hp1]; push_cast; field_simp + simp only [Nat.cast_mul] at * + rw [he1, he2, Fin.prod_univ_eq_prod_range] + unfold ProjectionNormScale + ring + +local instance final_reference_sigmaFinite (d m : ℕ) : + SigmaFinite (matrixLabelReference (E := Space d) m) := by + unfold matrixLabelReference + infer_instance +local instance final_projection_finite {d : ℕ} (μ : Measure (Space d)) [IsFiniteMeasure μ] (m : ℕ) : + IsFiniteMeasure (projectionLaw μ m) := by + unfold projectionLaw + infer_instance + +lemma exact_finite_density (d m p : ℕ) (hp : 2 ≤ p) (hm : 1 ≤ m) + (β H R : ℝ) (hgap : (m:ℝ)+(p:ℝ)-2 < β) (hH : 0 < H) (hR : 0 < R) + (z : Space d) (μ : Measure (Space d)) [IsFiniteMeasure μ] + (hsupport : μ.support ⊆ Metric.closedBall z R) (hball : AmbientBallBound μ H β) : + ∃ F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ, + Measurable F ∧ (∀ x, 0 ≤ F x) ∧ + (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) = + ProjectionLaw μ m ∧ + (∀ᵐ x ∂MatrixLabelReference d m, x ∉ ProjectedEllipsoid z R → F x = 0) ∧ + eLpNorm F (p : ℝ≥0∞) (MatrixLabelReference d m) ≤ + ENNReal.ofReal (ProjectionNormScale m p H β R) := by + let C := gaussianPeak ^ ((p-1)*m) * ENNReal.ofReal + (H^p * R^(β*(p:ℝ)-(m:ℝ)*((p-1:ℕ):ℝ)) * ∏ j : Fin (p-1), J β m j) + have hC : C ≠ ∞ := by unfold C gaussianPeak; finiteness + have hp1 : p-1+1 = p := by omega + have hmom : ∀ φ : ℝ → ℝ≥0∞, Measurable φ → (∫⁻ x, φ x = 1) → + (∫⁻ Ay, projectionSmoothing μ φ m Ay ^ (p-1+1) ∂matrixLabelReference m) ≤ C := by + intro φ hφ hφ1 + have hg : ((p-1:ℕ):ℝ)+(m:ℝ)-1 < β := by + rw [Nat.cast_sub (by omega : 1 ≤ p)] + push_cast + linarith + simpa only [hp1] using sharp_projectionSmoothing_moment hH hR hsupport hball φ hφ hφ1 hm (p-1) hg + have hac := projectionLaw_ac_of_moment μ m (p-1) (by omega) C hC hmom + let G := (projectionLaw μ m).rnDeriv (matrixLabelReference m) + have hG : Measurable G := Measure.measurable_rnDeriv _ _ + have hden : (matrixLabelReference m).withDensity G = projectionLaw μ m := + Measure.withDensity_rnDeriv_eq _ _ hac + have hGtop : ∀ᵐ x ∂matrixLabelReference m, G x ≠ ∞ := Measure.rnDeriv_ne_top _ _ + have hGmom : (∫⁻ x, G x^p ∂matrixLabelReference m) ≤ C := by + simpa only [hp1] using projectionLaw_rnDeriv_moment μ m (p-1) (by omega) C hC hmom + let F := fun x => (G x).toReal + have hFG : (fun x => ENNReal.ofReal (F x)) =ᵐ[matrixLabelReference m] G := by + filter_upwards [hGtop] with x hx + exact ENNReal.ofReal_toReal hx + refine ⟨F, hG.ennreal_toReal, fun _ => ENNReal.toReal_nonneg, ?_, ?_, ?_⟩ + · change (matrixLabelReference m).withDensity _ = projectionLaw μ m + rw [withDensity_congr_ae hFG, hden] + · have hnull := projectionLaw_ellipsoid_compl μ hsupport (m := m) + rw [← hden, withDensity_apply _ (isClosed_projectedEllipsoid z R).measurableSet.compl] at hnull + have hz := (lintegral_eq_zero_iff' hG.aemeasurable).mp hnull + change ∀ᵐ x ∂(matrixLabelReference m).restrict (ProjectedEllipsoid z R)ᶜ, G x = 0 at hz + rw [ae_restrict_iff' (isClosed_projectedEllipsoid z R).measurableSet.compl] at hz + filter_upwards [hz] with x hx hnot + dsimp [F] + rw [hx hnot] + rfl + · change eLpNorm F (p:ℝ≥0∞) (matrixLabelReference m) ≤ _ + rw [eLpNorm_eq_lintegral_rpow_enorm_toReal (by exact_mod_cast (by omega : p ≠ 0)) + (by finiteness) hG.ennreal_toReal.aestronglyMeasurable] + simp only [ENNReal.toReal_natCast] + have he : (fun x => ‖F x‖ₑ ^ (p:ℝ)) =ᵐ[matrixLabelReference m] (fun x => G x^p) := by + filter_upwards [hFG] with x hx + rw [Real.enorm_eq_ofReal ENNReal.toReal_nonneg, hx, ENNReal.rpow_natCast] + rw [lintegral_congr_ae he] + exact (ENNReal.rpow_le_rpow hGmom (by positivity)).trans_eq + (moment_root_eq_scale hp hH hR hgap) + +def FiniteDensityStatement : Prop := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + ∀ d m p : ℕ, + letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ) + 1 ≤ d → 1 ≤ m → 2 ≤ p → + ∀ β H R : ℝ, (m : ℝ)+(p : ℝ)-two < β → 0 < H → 0 < R → + ∀ z : Space d, ∀ μ : Measure (Space d), IsFiniteMeasure μ → + @Measure.support (Space d) + (PiLp.topologicalSpace (p := exponent) (β := fun _ : Fin d => ℝ)) + (WithLp.measurableSpace exponent (Fin d → ℝ)) μ ⊆ + @Metric.closedBall (Space d) + (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ)) z R → + AmbientBallBound μ H β → + ∃ F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ, + Measurable F ∧ (∀ x, 0 ≤ F x) ∧ + (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) = + ProjectionLaw μ m ∧ + (∀ᵐ x ∂MatrixLabelReference d m, x ∉ ProjectedEllipsoid z R → F x = 0) ∧ + eLpNorm F (p : ℝ≥0∞) (MatrixLabelReference d m) ≤ + ENNReal.ofReal (ProjectionNormScale m p H β R) + +theorem finite_density : FiniteDensityStatement := by + intro d m p _ hm hp β H R hgap hH hR z μ hμ hs hb + let := hμ + exact exact_finite_density d m p hp hm β H R hgap hH hR z μ hs hb +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/GaussianConvolution.lean b/lean/OAI/Probability/MemoryPrecision/GaussianConvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..f9d82ba3e7aa28290fe6141ac73f6a302bcbc0ae --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/GaussianConvolution.lean @@ -0,0 +1,114 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.BallAverages + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma gaussianKernel_translated_ball_mixture (m : ℕ) (hm : 1 ≤ m) {δ : ℝ} (hδ : 0 < δ) + (y x : Space m) : + ENNReal.ofReal (GaussianKernel m δ (y-x)) = + ∫⁻ r in Ioi 0, (Metric.ball y r).indicator + (fun _ => ENNReal.ofReal ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m))) x := by + rw [gaussianKernel_ball_mixture m hm hδ] + apply lintegral_congr + intro r + have he : y-x ∈ Metric.ball (0 : Space m) r ↔ x ∈ Metric.ball y r := by + simp only [Metric.mem_ball, dist_eq_norm, sub_zero, norm_sub_rev] + by_cases hx : x ∈ Metric.ball y r + · rw [Set.indicator_of_mem (he.mpr hx), Set.indicator_of_mem hx] + · rw [Set.indicator_of_notMem (mt he.mp hx), Set.indicator_of_notMem hx] + +def GaussianConvolution {m : ℕ} (ν : Measure (Space m)) (δ : ℝ) (y : Space m) : ℝ := + ∫ x, GaussianKernel m δ (y-x) ∂ν + +lemma gaussianConvolution_shell {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m)) + [IsFiniteMeasure ν] {δ : ℝ} (hδ : 0 < δ) (y : Space m) : + GaussianConvolution ν δ y = ∫ r in Ioi 0, + ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m)) * (ν (Metric.ball y r)).toReal := by + have hk : Measurable (GaussianKernel m δ) := (gaussianKernel_continuous m δ).measurable + have hmeas : Measurable (fun z : Space m × ℝ => + (Metric.ball y z.2).indicator + (fun _ => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) z.1) := by + have he : (fun z : Space m × ℝ => (Metric.ball y z.2).indicator + (fun _ => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) z.1) = + {z : Space m × ℝ | dist z.1 y < z.2}.indicator + (fun z => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) := by + ext z + by_cases hz : z.1 ∈ Metric.ball y z.2 + · rw [Set.indicator_of_mem hz, Set.indicator_of_mem + (show z ∈ {z : Space m × ℝ | dist z.1 y < z.2} from hz)] + · rw [Set.indicator_of_notMem hz, Set.indicator_of_notMem + (show z ∉ {z : Space m × ℝ | dist z.1 y < z.2} from hz)] + rw [he] + exact (by fun_prop : Measurable (fun z : Space m × ℝ => + ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m)))).indicator + (measurableSet_lt (by fun_prop) (by fun_prop)) + unfold GaussianConvolution + rw [integral_eq_lintegral_of_nonneg_ae + (Eventually.of_forall (fun _ => gaussianKernel_nonneg m δ _)) + ((hk.comp (by fun_prop)).aestronglyMeasurable)] + simp_rw [gaussianKernel_translated_ball_mixture m hm hδ y] + rw [lintegral_lintegral_swap hmeas.aemeasurable] + simp_rw [lintegral_indicator Metric.isOpen_ball.measurableSet, setLIntegral_const] + have hmass : Measurable (fun r : ℝ => (ν (Metric.ball y r)).toReal) := + (show Monotone (fun r : ℝ => ν (Metric.ball y r)) from + fun a b h => measure_mono (Metric.ball_subset_ball h)).measurable.ennreal_toReal + rw [integral_eq_lintegral_of_nonneg_ae + ((ae_restrict_mem measurableSet_Ioi).mono (fun r hr => + mul_nonneg (mul_nonneg (div_nonneg hr.le (sq_nonneg δ)) (gaussianKernel_nonneg m δ _)) + ENNReal.toReal_nonneg)) (by fun_prop)] + congr 1 + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr + rw [ENNReal.ofReal_mul (mul_nonneg (div_nonneg hr.le (sq_nonneg δ)) + (gaussianKernel_nonneg m δ _)), ENNReal.ofReal_toReal (measure_ne_top _ _)] + +lemma gaussianConvolution_mixture {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m)) + [IsFiniteMeasure ν] {δ : ℝ} (hδ : 0 < δ) (y : Space m) : + GaussianConvolution ν δ y = ∫ r in Ioi 0, RadialMixture m δ r * BallAverage ν y r := by + rw [gaussianConvolution_shell hm ν hδ y] + apply integral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr + have hr0 : 0 < r := hr + unfold RadialMixture BallAverage + field_simp [(unitBallVolume_pos m).ne', hr0.ne'] + +lemma gaussianConvolution_scaled_mixture {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m)) + [IsFiniteMeasure ν] {δ : ℝ} (hδ : 0 < δ) (y : Space m) : + GaussianConvolution ν δ y = ∫ r in Ioi 0, RadialMixture m 1 r * BallAverage ν y (δ*r) := by + rw [gaussianConvolution_mixture hm ν hδ y] + have he := integral_comp_mul_left_Ioi' + (fun r => RadialMixture m δ r * BallAverage ν y r) 0 hδ + simp only [mul_zero, smul_eq_mul] at he + rw [← he, ← integral_const_mul] + apply integral_congr_ae + exact Eventually.of_forall (fun radius => by + dsimp only + rw [radialMixture_scale m hδ] + field_simp [hδ.ne']) + +lemma ae_tendsto_gaussianConvolution {m : ℕ} (hm : 1 ≤ m) (ν : Measure (Space m)) + [IsFiniteMeasure ν] (hν : ν ≪ volume) : + ∀ᵐ y ∂(volume : Measure (Space m)), Tendsto (fun δ : ℝ => GaussianConvolution ν δ y) + (𝓝[>] (0:ℝ)) (𝓝 ((ν.rnDeriv volume y).toReal)) := by + filter_upwards [ae_tendsto_ballAverage hm ν hν] with y hy + apply (tendsto_radial_average hm ν y ENNReal.toReal_nonneg hy).congr' + filter_upwards [self_mem_nhdsWithin] with δ hδ + exact (gaussianConvolution_scaled_mixture hm ν hδ y).symm +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/JointL1.lean b/lean/OAI/Probability/MemoryPrecision/JointL1.lean new file mode 100644 index 0000000000000000000000000000000000000000..274ea3328daed461e1d08344a14bfb263e9c774b --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/JointL1.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.FiniteDensity +import OAI.Probability.MemoryPrecision.KernelModel +import OAI.Probability.MemoryPrecision.LabelTranslations + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression +def UniformSphere (d : ℕ) : @Measure (Space d) + (WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ)) := + let euclideanMeasurable := WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ) + @Measure.map (Kernel.Sphere d) (Space d) + (MeasurableSpace.comap Subtype.val euclideanMeasurable) euclideanMeasurable + Subtype.val (Kernel.UniformSphere d) + +def GaussianRegularization {d : ℕ} + (μ : @Measure (Space d) + (WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ))) + (m : ℕ) (δ : ℝ) + (Ay : (Fin m → Space d) × (Fin m → ℝ)) : ℝ := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ) + ∫ signal, ∏ index, gaussianPDFReal 0 ⟨δ^2, sq_nonneg δ⟩ + (Ay.2 index - @inner ℝ (Space d) + (@InnerProductSpace.toInner ℝ (Space d) _ + (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))) + signal (Ay.1 index)) ∂μ + +lemma gaussianPDF_zero_sub_comm (v : ℝ≥0) (a b : ℝ) : + gaussianPDF 0 v (a-b) = gaussianPDF 0 v (b-a) := by + simp only [gaussianPDF, gaussianPDFReal, sub_zero] + congr 4 + ring + +lemma GaussianRegularization_eq_toReal {d : ℕ} (μ : Measure (Space d)) + [IsFiniteMeasure μ] (m : ℕ) (δ : ℝ) + (x : (Fin m → Space d) × (Fin m → ℝ)) : + GaussianRegularization μ m δ x = + (projectionSmoothing μ (gaussianPDF 0 ⟨δ^2,sq_nonneg δ⟩) m x).toReal := by + let v : ℝ≥0 := ⟨δ^2,sq_nonneg δ⟩ + change (∫ s, ∏ j, gaussianPDFReal 0 v (x.2 j - ⟪s,x.1 j⟫) ∂μ) = _ + have hn : ∀ s : Space d, 0 ≤ ∏ j, gaussianPDFReal 0 v (x.2 j - ⟪s,x.1 j⟫) := + fun s => Finset.prod_nonneg (fun _ _ => gaussianPDFReal_nonneg _ _ _) + have hm : Measurable (fun s : Space d => ∏ j, gaussianPDFReal 0 v (x.2 j - ⟪s,x.1 j⟫)) := by + fun_prop + rw [integral_eq_lintegral_of_nonneg_ae (Eventually.of_forall hn) hm.aestronglyMeasurable] + unfold projectionSmoothing + congr 1 + apply lintegral_congr + intro s + rw [ENNReal.ofReal_prod_of_nonneg (fun _ _ => gaussianPDFReal_nonneg _ _ _)] + rfl + +lemma GaussianRegularization_ae_eq_average {d : ℕ} (μ : Measure (Space d)) + [IsFiniteMeasure μ] (m : ℕ) + (F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ) + (hF : Measurable F) (hF0 : ∀ x, 0 ≤ F x) + (hden : (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) = + ProjectionLaw μ m) (δ : ℝ) (hδ : δ ≠ 0) : + GaussianRegularization μ m δ =ᵐ[MatrixLabelReference d m] + averageTranslate (Measure.pi (fun _ : Fin m => gaussianReal 0 1)) δ F := by + have he := projectionSmoothing_ae_eq_fiberSmoothing μ m + (fun x => ENNReal.ofReal (F x)) hF.ennreal_ofReal hden + (gaussianPDF 0 ⟨δ^2,sq_nonneg δ⟩) (measurable_gaussianPDF _ _) + filter_upwards [he] with x hx + rw [GaussianRegularization_eq_toReal, hx] + unfold averageTranslate + rw [integral_eq_lintegral_of_nonneg_ae (Eventually.of_forall (fun u => hF0 _)) + ((hF.comp (by fun_prop)).aestronglyMeasurable)] + congr 1 + change fiberSmoothing volume (fun x => ENNReal.ofReal (F x)) + (fun y : Fin m → ℝ => ∏ j, gaussianPDF 0 _ (y j)) x = + ∫⁻ u : Fin m → ℝ, ENNReal.ofReal (F (x.1,fun j => x.2 j + δ * u j)) + ∂Measure.pi (fun _ => gaussianReal 0 1) + rw [lintegral_gaussian_shift_scale m δ hδ x.2 (fun y => ENNReal.ofReal (F (x.1,y))) + (by fun_prop)] + apply lintegral_congr + intro y + congr 1 + apply Finset.prod_congr rfl + intro j _ + exact gaussianPDF_zero_sub_comm _ _ _ + +lemma memLp_density_of_finite {X : Type*} [MeasurableSpace X] + (ν₀ η : Measure X) [IsFiniteMeasure η] {F : X → ℝ} + (hFm : Measurable F) (hF0 : ∀ x, 0 ≤ F x) + (hden : ν₀.withDensity (fun x => ENNReal.ofReal (F x)) = η) : + MemLp F 1 ν₀ := by + rw [memLp_iff, eLpNorm_one_eq_lintegral_enorm hFm.aestronglyMeasurable] + have he : (fun x => ‖F x‖ₑ) = (fun x => ENNReal.ofReal (F x)) := by + funext x + exact Real.enorm_eq_ofReal (hF0 x) + rw [he] + have he2 := congrArg (fun ν : Measure X => ν Set.univ) hden + rw [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] at he2 + rw [he2] + exact measure_lt_top _ _ + +lemma density_ae_unique_real {X : Type*} [MeasurableSpace X] + (ν₀ : Measure X) [SigmaFinite ν₀] {F G : X → ℝ} + (hFm : Measurable F) (hF0 : ∀ x, 0 ≤ F x) + (hGm : Measurable G) (hG0 : ∀ x, 0 ≤ G x) + (hden : ν₀.withDensity (fun x => ENNReal.ofReal (F x)) = + ν₀.withDensity (fun x => ENNReal.ofReal (G x))) : F =ᵐ[ν₀] G := by + have he := (withDensity_eq_iff_of_sigmaFinite hFm.ennreal_ofReal.aemeasurable + hGm.ennreal_ofReal.aemeasurable).mp hden + filter_upwards [he] with x hx + exact (ENNReal.ofReal_eq_ofReal_iff (hF0 x) (hG0 x)).mp hx + +def JointL1Statement : Prop := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + ∀ d m p : ℕ, + letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ) + 2 ≤ d → 1 ≤ m → m < d → 2 ≤ p → + ∀ β H R : ℝ, (m : ℝ)+(p : ℝ)-two < β → 0 < H → 0 < R → + ∀ z : Space d, ∀ μ : Measure (Space d), IsFiniteMeasure μ → + @Measure.support (Space d) + (PiLp.topologicalSpace (p := exponent) (β := fun _ : Fin d => ℝ)) + (WithLp.measurableSpace exponent (Fin d → ℝ)) μ ⊆ + @Metric.closedBall (Space d) + (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ)) z R → + AmbientBallBound μ H β → + μ ≪ UniformSphere d → + ∀ F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ, + Measurable F → (∀ x, 0 ≤ F x) → + (MatrixLabelReference d m).withDensity (fun x => ENNReal.ofReal (F x)) = + ProjectionLaw μ m → + Tendsto (fun δ => eLpNorm (fun Ay => GaussianRegularization μ m δ Ay - F Ay) + 1 (MatrixLabelReference d m)) (𝓝[Set.Ioi 0] 0) (𝓝 0) ∧ + eLpNorm F (p : ℝ≥0∞) (MatrixLabelReference d m) ≤ + ENNReal.ofReal (ProjectionNormScale m p H β R) +theorem joint_l1 : JointL1Statement := by + intro d m p hd hm hmd hp β H R hgap hH hR z μ hμ hs hb hac F hFm hF0 hden + have : IsFiniteMeasure μ := hμ + have : IsFiniteMeasure (ProjectionLaw μ m) := by unfold ProjectionLaw; infer_instance + have : SigmaFinite (MatrixLabelReference d m) := by unfold MatrixLabelReference; infer_instance + have hF := memLp_density_of_finite (MatrixLabelReference d m) (ProjectionLaw μ m) hFm hF0 hden + constructor + · have ht := tendsto_eLpNorm_averageTranslate_sub + (Measure.pi (fun _ : Fin m => stdGaussian (Space d))) + (volume : Measure (Fin m → ℝ)) + (Measure.pi (fun _ : Fin m => gaussianReal 0 1)) hFm hF + apply (ht.mono_left nhdsWithin_le_nhds).congr' + filter_upwards [self_mem_nhdsWithin] with δ hδ + apply eLpNorm_congr_ae + filter_upwards [GaussianRegularization_ae_eq_average μ m F hFm hF0 hden δ + (ne_of_gt hδ)] with x hx + exact congrArg (fun t => t - F x) hx.symm + · obtain ⟨G,hGm,hG0,hGden,hGs,hGnorm⟩ := + exact_finite_density d m p hp hm β H R hgap hH hR z μ hs hb + have he := density_ae_unique_real (MatrixLabelReference d m) hFm hF0 hGm hG0 + (hden.trans hGden.symm) + exact (eLpNorm_congr_ae he).symm ▸ hGnorm +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelAdmissibility.lean b/lean/OAI/Probability/MemoryPrecision/KernelAdmissibility.lean new file mode 100644 index 0000000000000000000000000000000000000000..5bb7b6639837ecb9c69c62b9f927400e42f43804 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelAdmissibility.lean @@ -0,0 +1,48 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CoefficientStep + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +namespace Policy + +def ModelAdmissible {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (K : Ω → Policy d M T) (ρ : Measure Ω) : Prop := + ∀ π : Measure (Sphere d), IsProbabilityMeasure π → Admissible K ρ π + +def FixedSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (K : Ω → Policy d M T) (ρ : Measure Ω) (ε : ℝ) (s : Sphere d) : ℝ≥0∞ := + let rowMeasurable := @MeasurableSpace.pi (Fin T) (fun _ => Vector d) + (fun _ => @WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) + (Fin d → ℝ) inferInstance) + @lintegral (Ω × Rows d T) + (@Prod.instMeasurableSpace Ω (Rows d T) inferInstance rowMeasurable) + (@Measure.prod Ω (Rows d T) inferInstance rowMeasurable ρ (RowLaw d T)) + (fun z => experiment K (angleTest ε) (s,z)) + +lemma modelAdmissible_of_measurable {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (K : Ω → Policy d M T) (ρ : Measure Ω) + (hc : ∀ᵐ ω ∂ρ, (K ω).Completed) + (hm : ∀ f : Sphere d × Sphere d → ℝ≥0∞, Measurable f → (∀ x, f x ≤ 1) → + Measurable (experiment K f)) : ModelAdmissible K ρ := by + intro π hπ + exact ⟨hc, fun f hf h1 => (hm f hf h1).aemeasurable⟩ +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelCaps.lean b/lean/OAI/Probability/MemoryPrecision/KernelCaps.lean new file mode 100644 index 0000000000000000000000000000000000000000..239ae6627696470d2f126cbc1704f85330a197fb --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelCaps.lean @@ -0,0 +1,119 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeExperiment +import OAI.Probability.MemoryPrecision.KernelEvaluation +import OAI.Probability.MemoryPrecision.SphereCaps + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +open MemoryPrecision NoiselessRegression +instance {d : ℕ} [NeZero d] : IsProbabilityMeasure (UniformSphere d) := + (show IsProbabilityMeasure (NoiselessRegression.sphereLaw (E := Vector d)) from inferInstance) +instance (d T : ℕ) : IsProbabilityMeasure (RowLaw d T) := by unfold RowLaw; infer_instance + +namespace Policy +variable {d M T : ℕ} (K : Policy d M T) + +lemma chordTest_eq_cap (ε : ℝ) (s v : MemoryPrecision.Kernel.Sphere d) : + chordTest ε (s,v) = capWeight v.val ε s.val := by + classical + change (if dist v.val s.val ≤ ε then 1 else 0) = + (if dist s.val v.val ≤ ε then 1 else 0) + rw [dist_comm] + +lemma output_chord_sphere_local (hd : 1 ≤ d) {ε α : ℝ} (hε : 0 < ε) + (hα : 0 ≤ α) (hαn : α ≤ (d:ℝ)-1) (t : ℕ) (j : MemoryPrecision.Kernel.State M) : + SphereBallBound (K.outputTest (chordTest ε) t j) + ((3*4^d:ℝ)*ε^((d:ℝ)-1-α)) α := by + have : NeZero d := ⟨by omega⟩ + intro z r hr + change (∫⁻ s in {s : MemoryPrecision.Kernel.Sphere d | dist s.val z ≤ r}, + ∫⁻ v, chordTest ε (s,v) ∂K.output t j ∂UniformSphere d) ≤ _ + have hm : Measurable (Function.uncurry (fun s v : MemoryPrecision.Kernel.Sphere d => chordTest ε (s,v))) := + measurable_chordTest ε + rw [lintegral_lintegral_swap hm.aemeasurable] + have hb (v : MemoryPrecision.Kernel.Sphere d) := sphere_cap_real_mass hd v.val hε hα hαn z r hr + simp_rw [chordTest_eq_cap] + exact (lintegral_mono hb).trans_eq (by simp) + +lemma output_chord_cube_local (hd : 2 ≤ d) {ε : ℝ} (hε : 0 < ε) + (t : ℕ) (j : MemoryPrecision.Kernel.State M) : + CubeLocal (fun u => K.outputTest (chordTest ε) t j (CubeSphere hd u)) + ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ)) := by + intro z r hr + change (∫⁻ u in CubeBall d z r, ∫⁻ v, chordTest ε (CubeSphere hd u,v) + ∂K.output t j ∂CubeLaw d) ≤ _ + have hf : Measurable (Function.uncurry (fun (u : Cube d) (v : MemoryPrecision.Kernel.Sphere d) => + chordTest ε (CubeSphere hd u,v))) := + (measurable_chordTest ε).comp ((cubeSphere_measurable hd).comp measurable_fst |>.prodMk measurable_snd) + rw [lintegral_lintegral_swap hf.aemeasurable] + simp_rw [chordTest_eq_cap] + change (∫⁻ v : MemoryPrecision.Kernel.Sphere d, ∫⁻ u in CubeBall d z r, + capWeight v.val ε (CubeEmbedding d u) ∂CubeLaw d ∂K.output t j) ≤ _ + have hb (v : MemoryPrecision.Kernel.Sphere d) := cube_cap_local hd v.val hε z r hr + exact (lintegral_mono hb).trans_eq (by simp) + +lemma output_chord_sphere_total (hd : 1 ≤ d) {ε : ℝ} (hε : 0 < ε) + (t : ℕ) (j : MemoryPrecision.Kernel.State M) : + (∫⁻ s, K.outputTest (chordTest ε) t j s ∂UniformSphere d) ≤ + ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1)) := by + have h := sphere_mass_bound (K.output_chord_sphere_local hd hε (α := 0) le_rfl (by + have hd' : (1:ℝ) ≤ d := by exact_mod_cast hd + linarith) t j) + have hn : ((d-1:ℕ):ℝ) = (d:ℝ)-1 := by rw [Nat.cast_sub hd, Nat.cast_one] + simpa only [UniformSphere, SpherePrior,sub_zero, ← hn, Real.rpow_natCast] using h + +lemma angleTest_le_chordTest (ε : ℝ) (x : MemoryPrecision.Kernel.Sphere d × MemoryPrecision.Kernel.Sphere d) : + angleTest ε x ≤ chordTest ε x := by + classical + by_cases ha : Real.arccos ⟪x.2.val,x.1.val⟫ ≤ ε + · have hc : dist x.2.val x.1.val ≤ ε := (chord_le_arccos x.2 x.1).trans ha + simp [angleTest, chordTest, ha, hc] + · simp [angleTest, ha] + +lemma eval_mono {X : Type*} {w v : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞} + (h : ∀ n j s, w n j s ≤ v n j s) (n k : ℕ) (j : MemoryPrecision.Kernel.State M) + (s : X) (obs : Observations d k) : K.eval w n k j s obs ≤ K.eval v n k j s obs := by + induction k generalizing n j with + | zero => exact h n j s + | succ k ih => + apply Finset.sum_le_sum + intro a _ + apply mul_le_mul' le_rfl + split + · exact h _ _ _ + · exact ih _ _ _ + +lemma pathValue_mono {X : Type*} {w v : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞} + (h : ∀ n j s, w n j s ≤ v n j s) (s : X) (obs : Observations d T) : + K.pathValue w s obs ≤ K.pathValue v s obs := by + apply Finset.sum_le_sum + intro a _ + apply mul_le_mul' le_rfl + split + · exact h _ _ _ + · exact K.eval_mono h _ _ _ _ _ + +lemma success_le_chord {Ω : Type*} [MeasurableSpace Ω] (L : Ω → Policy d M T) + (ρ : Measure Ω) (π : Measure (MemoryPrecision.Kernel.Sphere d)) (ε : ℝ) : + Success L ρ π ε ≤ ChordSuccess L ρ π ε := by + apply lintegral_mono + intro z + exact (L z.2.1).pathValue_mono (fun n j s => lintegral_mono (fun v => angleTest_le_chordTest ε (s,v))) _ _ +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelCube.lean b/lean/OAI/Probability/MemoryPrecision/KernelCube.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a472d5886ee49408074ed20fba301551278ac57 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelCube.lean @@ -0,0 +1,124 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelCaps +import OAI.Probability.MemoryPrecision.KernelIntegral +import OAI.Probability.MemoryPrecision.KernelVersion +import OAI.Probability.MemoryPrecision.SeedAverage +import OAI.Probability.MemoryPrecision.StochasticMass + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +open MemoryPrecision NoiselessRegression + +def CubePrior {d : ℕ} (hd : 2 ≤ d) : Measure (MemoryPrecision.Kernel.Sphere d) := + (CubeLaw d).map (CubeSphere hd) +instance {d : ℕ} (hd : 2 ≤ d) : IsProbabilityMeasure (CubePrior hd) := by + unfold CubePrior + infer_instance + +lemma cubeSphere_preserving {d : ℕ} (hd : 2 ≤ d) : + MeasurePreserving (CubeSphere hd) (CubeLaw d) (CubePrior hd) := + ⟨cubeSphere_measurable hd, rfl⟩ + +namespace Policy +variable {d M T : ℕ} (K : Policy d M T) + +lemma eval_comp {X Y : Type*} (w : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞) (ι : Y → X) + (n k : ℕ) (j : MemoryPrecision.Kernel.State M) (s : Y) (obs : Observations d k) : + K.eval w n k j (ι s) obs = K.eval (fun n j s => w n j (ι s)) n k j s obs := by + induction k generalizing n j with + | zero => rfl + | succ k ih => + simp only [eval] + apply Finset.sum_congr rfl + intro a _ + rw [ih] +lemma pathValue_comp {X Y : Type*} (w : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞) (ι : Y → X) + (s : Y) (obs : Observations d T) : + K.pathValue w (ι s) obs = K.pathValue (fun n j s => w n j (ι s)) s obs := by + simp only [pathValue, K.eval_comp w ι] + +lemma borel_cube_bound (hK : K.Borel) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) : + (∫⁻ z : Cube d × Rows d T, + K.pathValue (K.outputTest (chordTest ε)) (CubeSphere (d := d) (by omega) z.1) + (records (CubeSphere (d := d) (by omega) z.1) z.2) + ∂(CubeLaw d).prod (RowLaw d T)) ≤ + (T+1:ℝ≥0∞)*ENNReal.ofReal ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * + CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4)) := by + have hm₁ : Measurable (fun z : Cube d × Rows d T => + (CubeSphere (d := d) (by omega) z.1,z.2)) := + ((cubeSphere_measurable (d := d) (by omega)).comp measurable_fst).prodMk measurable_snd + have hm₀ := K.experiment_fixed_measurable (f := chordTest (d := d) ε) hK (measurable_chordTest ε) + have hm := hm₀.comp hm₁ + have hprod := lintegral_prod (μ := CubeLaw d) (ν := RowLaw d T) _ hm.aemeasurable + simp only [Function.comp_apply] at hprod + rw [hprod] + simp_rw [K.pathValue_comp _ (CubeSphere (d := d) (by omega))] + apply K.integral_pathValue_bound (fun n j u => K.outputTest (chordTest ε) n j (CubeSphere (d := d) (by omega) u)) + (CubeEmbedding d) hK + (fun n j => (K.outputTest_measurable (measurable_chordTest ε) n j).comp (cubeSphere_measurable (d := d) (by omega))) + (cubeEmbedding_measurable d) (CubeLaw d) + intro r hr j + apply cube_mass_bound + exact stoch_cube_mass hd (show 1 ≤ 2^M from one_le_pow₀ (by norm_num)) + (K.marginal_measurable hK) (fun n j obs => (K.marginal_sum n j obs).le) + (fun n j => (K.outputTest_measurable (measurable_chordTest ε) n j).comp (cubeSphere_measurable (d := d) (by omega))) + (fun n j u => K.outputTest_le_one (chordTest_le_one ε) n j (CubeSphere (d := d) (by omega) u)) + (by positivity) (K.output_chord_cube_local (by omega) hε) + (MemoryPrecision.BlockCount T ((d/2)/4)) r + (hr.trans (blockCount_mul_ge T (by omega))) 0 j + +lemma completed_cube_bound (hK : K.Completed) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) : + (∫⁻ z : Cube d × Rows d T, + K.pathValue (K.outputTest (chordTest ε)) (CubeSphere (d := d) (by omega) z.1) + (records (CubeSphere (d := d) (by omega) z.1) z.2) + ∂(CubeLaw d).prod (RowLaw d T)) ≤ + (T+1:ℝ≥0∞)*ENNReal.ofReal ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * + CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4)) := by + have he := K.version_pathValue_ae ((CubeLaw d).prod (RowLaw d T)) hK + (fun z : Cube d × Rows d T => CubeSphere (d := d) (by omega) z.1) + (fun z : Cube d × Rows d T => records (CubeSphere (d := d) (by omega) z.1) z.2) + (fun i => show Measure.QuasiMeasurePreserving _ _ _ from cube_sample_observation_quasi hd i) + (chordTest ε) + rw [← lintegral_congr_ae he] + exact (K.version hK).borel_cube_bound (K.version_borel hK) hd hε + +lemma source_cube_chord_bound {Ω : Type u} [MeasurableSpace Ω] (L : Ω → Policy d M T) + (ρ : Measure Ω) [IsProbabilityMeasure ρ] (hd : 16 ≤ d) + (hL : Admissible L ρ (CubePrior (by omega))) {ε : ℝ} (hε : 0 < ε) : + ChordSuccess L ρ (CubePrior (by omega)) ε ≤ + (T+1:ℝ≥0∞)*ENNReal.ofReal ((12:ℝ)^(d/2)*ε^((d/2:ℕ)/4:ℝ) * + CubeStep d (2^M)^MemoryPrecision.BlockCount T ((d/2)/4)) := by + have hp := (cubeSphere_preserving (by omega : 2 ≤ d)).prod + (MeasurePreserving.id (ρ.prod (RowLaw d T))) + have hf := hL.experiment (chordTest ε) (measurable_chordTest ε) (chordTest_le_one ε) + have he : (∫⁻ z : Cube d × (Ω × Rows d T), + experiment L (chordTest ε) (CubeSphere (d := d) (by omega) z.1,z.2) + ∂(CubeLaw d).prod (ρ.prod (RowLaw d T))) = ChordSuccess L ρ (CubePrior (by omega)) ε := by + calc + _ = ∫⁻ z, experiment L (chordTest ε) z ∂((CubeLaw d).prod (ρ.prod (RowLaw d T))).map + (Prod.map (CubeSphere (d := d) (by omega)) id) := + (lintegral_map' (by simpa only [hp.map_eq] using hf) hp.measurable.aemeasurable).symm + _ = _ := by rw [hp.map_eq]; rfl + rw [← he] + apply seed_average_bound (CubeLaw d) (RowLaw d T) ρ + (hf.comp_quasiMeasurePreserving hp.quasiMeasurePreserving) + filter_upwards [hL.completed] with ω hω + exact (L ω).completed_cube_bound hω hd hε +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelEllipsoid.lean b/lean/OAI/Probability/MemoryPrecision/KernelEllipsoid.lean new file mode 100644 index 0000000000000000000000000000000000000000..059c990f93012769f9dac4e1f85188a459fc78d1 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelEllipsoid.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.EllipsoidSuccess + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +open MemoryPrecision Policy + +lemma chord_real_coefficient {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Ω → Policy d M T) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : Admissible L ρ (UniformSphere d)) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) + {α : ℝ} (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) : + ChordSuccess L ρ (UniformSphere d) ε ≤ ENNReal.ofReal + ((T+1:ℝ) * ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d (2^M)^BlockCount T (d/8))) := by + apply (Policy.chord_real_bound L ρ hL hd hε hαlo hαhi).trans_eq + rw [ENNReal.ofReal_mul (by positivity : (0:ℝ) ≤ T+1)] + congr 1 + simp [ENNReal.ofReal_add] + +lemma chord_half_sphere_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Ω → Policy d M T) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : Admissible L ρ (UniformSphere d)) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1/10) : + ChordSuccess L ρ (UniformSphere d) ε ≤ ENNReal.ofReal + (4^d * ε^(((d:ℝ)-1)/2) * + (SuccessConstant^d * (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^BlockCount T (d/8)) := by + by_cases hT : T = 0 + · subst T + simp only [blockCount_zero, pow_zero, mul_one] + exact (Policy.chord_zero_bound L ρ hL (by omega) hε).trans + (ENNReal.ofReal_le_ofReal (terminal_angular_zero_bound hd hε hε1)) + · have hb := chord_real_coefficient L ρ hL hd hε (le_refl (((d:ℝ)-1)/2)) (by linarith) + have he : (d:ℝ)-1-((d:ℝ)-1)/2 = ((d:ℝ)-1)/2 := by ring + rw [he] at hb + apply hb.trans (ENNReal.ofReal_le_ofReal ?_) + have hN : 1 ≤ 2^M := one_le_pow₀ (by norm_num) + have hNK : 2^M ≤ (d/8+2)*2^M := by + simp + have hs := stopping_step_bound_three hd hN hNK (by omega : 0 < T) + calc + _ = (4^d * ε^(((d:ℝ)-1)/2)) * (3*((T+1:ℝ)*RealStep d (2^M)^BlockCount T (d/8))) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hs (by positivity) + +lemma chord_half_ambient_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Ω → Policy d M T) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : Admissible L ρ (UniformSphere d)) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) : + ChordSuccess L ρ (UniformSphere d) ε ≤ ENNReal.ofReal + (12^d * ε^((d:ℝ)/2-1) * + (SuccessConstant^d * (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^BlockCount T (d/8)) := by + have hb := chord_real_coefficient L ρ hL hd hε (by linarith : ((d:ℝ)-1)/2 ≤ (d:ℝ)/2) le_rfl + have he : (d:ℝ)-1-(d:ℝ)/2 = (d:ℝ)/2-1 := by ring + rw [he] at hb + apply hb.trans (ENNReal.ofReal_le_ofReal ?_) + have hN : 1 ≤ 2^M := one_le_pow₀ (by norm_num) + have hNK : 2^M ≤ (2*(d/8)+4)*2^M := by + simp + have hR := realStep_pos d hN + have hs := stopping_step_bound hd hN hNK T + have hSp := stepConstant_pos + have hK : 2*StepConstant ≤ SuccessConstant := by dsimp [SuccessConstant]; linarith + have hroot : 0 ≤ (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)) := by positivity + have hbase := mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (by positivity : 0 ≤ 2*StepConstant) hK d) hroot + have hpow := pow_le_pow_left₀ (by positivity : 0 ≤ (2*StepConstant)^d * + (((2*(d/8)+4)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ))) hbase (BlockCount T (d/8)) + calc + _ = ((3*4^d:ℝ)*ε^((d:ℝ)/2-1))*((T+1:ℝ)*RealStep d (2^M)^BlockCount T (d/8)) := by ring + _ ≤ _ := mul_le_mul + (mul_le_mul_of_nonneg_right (cap_constant_le (by omega : 1 ≤ d)) (by positivity)) + (hs.trans hpow) (by positivity) (by positivity) + +end MemoryPrecision.Kernel + +namespace MemoryPrecision.Kernel +open Policy +def BlockCount (T p : ℕ) : ℕ := ⌈(T:ℝ)/(p:ℝ)⌉₊ +def SourceEllipsoidStatement : Prop := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let four : ℝ := @OfNat.ofNat ℝ 4 (@instOfNatAtLeastTwo ℝ 4 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 2))) + let ten : ℝ := @OfNat.ofNat ℝ 10 (@instOfNatAtLeastTwo ℝ 10 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 8))) + ∃ C C₀ : ℝ, 1 ≤ C ∧ 1 ≤ C₀ ∧ + ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, 0 < ε → ε ≤ 1/ten → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ K : Ω → Policy d M T, Policy.Admissible K ρ (UniformSphere d) → + Policy.Success K ρ (UniformSphere d) ε ≤ min 1 (ENNReal.ofReal + (four^d * ε^(((d:ℝ)-1)/two) * + (C^d * (((d/8+2)*2^M : ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^(BlockCount T (d/8)))) ∧ + Policy.ChordSuccess K ρ (UniformSphere d) ε ≤ min 1 (ENNReal.ofReal + (C₀^d * ε^((d:ℝ)/two-1) * + (C^d * (((2*(d/8)+4)*2^M : ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^(BlockCount T (d/8)))) ∧ + {x : Sphere d × Sphere d | Real.arccos (@inner ℝ (Vector d) + (@InnerProductSpace.toInner ℝ (Vector d) _ + (PiLp.seminormedAddCommGroup + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) + (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))) + x.2.val x.1.val) ≤ ε} ⊆ + {x | @Dist.dist (Vector d) + (PiLp.instDist (p := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) + (α := fun _ : Fin d => ℝ)) x.2.val x.1.val ≤ ε} + +theorem source_ellipsoid_success : SourceEllipsoidStatement := by + refine ⟨MemoryPrecision.SuccessConstant, 12, MemoryPrecision.successConstant_one, by norm_num, ?_⟩ + intro d M T hd ε hε hε1 Ω _ ρ hρ L hL + have : IsProbabilityMeasure ρ := hρ + let : NeZero d := ⟨by omega⟩ + refine ⟨le_min (Policy.success_le_one L ρ (UniformSphere d) ε) ?_, + le_min (Policy.chordSuccess_le_one L ρ (UniformSphere d) ε) ?_, ?_⟩ + · exact (Policy.success_le_chord L ρ (UniformSphere d) ε).trans + (chord_half_sphere_bound L ρ hL hd hε hε1) + · exact chord_half_ambient_bound L ρ hL hd hε + · intro x hx + exact (NoiselessRegression.chord_le_arccos x.2 x.1).trans hx +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelEvaluation.lean b/lean/OAI/Probability/MemoryPrecision/KernelEvaluation.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d11aa92fed041ebd8183f03503273dc9e36c0da --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelEvaluation.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CoefficientStep +import OAI.Probability.MemoryPrecision.StochasticContinuation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +namespace Policy +variable {d M T : ℕ} (K : Policy d M T) + +lemma measurable_angleTest (ε : ℝ) : Measurable (angleTest (d := d) ε) := by + unfold angleTest + exact Measurable.ite (measurableSet_le (by fun_prop) measurable_const) + measurable_const measurable_const +lemma measurable_chordTest (ε : ℝ) : Measurable (chordTest (d := d) ε) := by + apply Measurable.indicator measurable_const + exact measurableSet_le (by fun_prop) measurable_const +lemma angleTest_le_one (ε : ℝ) (x : Sphere d × Sphere d) : angleTest ε x ≤ 1 := by + unfold angleTest + split <;> simp +lemma chordTest_le_one (ε : ℝ) (x : Sphere d × Sphere d) : chordTest ε x ≤ 1 := by + exact Set.indicator_le_self' (fun _ _ => bot_le) x +lemma outputTest_measurable {f : Sphere d × Sphere d → ℝ≥0∞} (hf : Measurable f) + (t : ℕ) (j : State M) : Measurable (K.outputTest f t j) := by + exact (show Measurable (Function.uncurry (fun s v => f (s,v))) from hf).lintegral_prod_right +lemma outputTest_le_one {f : Sphere d × Sphere d → ℝ≥0∞} (hf : ∀ x, f x ≤ 1) + (t : ℕ) (j : State M) (s : Sphere d) : K.outputTest f t j s ≤ 1 := by + exact (lintegral_mono (fun v => hf (s,v))).trans_eq (by simp) + +def marginal (n : ℕ) (j : State M) (obs : Vector d × ℝ) (a : State M) : ℝ≥0∞ := + ∑ b : Bool, K.transition n j obs (b,a) +lemma marginal_sum (n : ℕ) (j : State M) (obs : Vector d × ℝ) : + ∑ a, K.marginal n j obs a = 1 := by + simp only [marginal] + rw [Finset.sum_comm, ← Fintype.sum_prod_type] + exact K.transition_sum n j obs +lemma marginal_measurable (hK : K.Borel) (n : ℕ) (j a : State M) : + Measurable (fun obs => K.marginal n j obs a) := by + exact Finset.measurable_sum _ (fun b _ => hK n j (b,a)) + +section Evaluation +variable {X : Type*} [MeasurableSpace X] +variable (w : ℕ → State M → X → ℝ≥0∞) (ι : X → Vector d) + +lemma measurable_eval (hK : K.Borel) (hw : ∀ n j, Measurable (w n j)) + (n k : ℕ) (j : State M) : + Measurable (fun z : X × Observations d k => K.eval w n k j z.1 z.2) := by + induction k generalizing n j with + | zero => exact (hw n j).comp measurable_fst + | succ k ih => + apply Finset.measurable_sum _ + intro a _ + apply ((hK (n+1) j a).comp (by fun_prop)).mul + cases a with + | mk b a => + cases b + · exact (ih (n+1) a).comp (measurable_fst.prodMk + (Measurable.of_eval (fun index => (measurable_pi_apply index.succ).comp measurable_snd))) + · exact (hw (n+1) a).comp measurable_fst + +omit [MeasurableSpace X] in +lemma eval_le_one (hw : ∀ n j s, w n j s ≤ 1) (n k : ℕ) (j : State M) + (s : X) (obs : Observations d k) : K.eval w n k j s obs ≤ 1 := by + induction k generalizing n j with + | zero => exact hw n j s + | succ k ih => + apply (Finset.sum_le_sum (fun a _ => mul_le_of_le_one_right' ?_)).trans_eq + (K.transition_sum (n+1) j (obs 0)) + split + · exact hw _ _ _ + · exact ih _ _ _ + +omit [MeasurableSpace X] in +lemma pathValue_le_one (hw : ∀ n j s, w n j s ≤ 1) (s : X) (obs : Observations d T) : + K.pathValue w s obs ≤ 1 := by + apply (Finset.sum_le_sum (fun a _ => mul_le_of_le_one_right' ?_)).trans_eq K.initial_sum + split + · exact hw _ _ _ + · exact K.eval_le_one w hw _ _ _ _ _ + +def cont (n : ℕ) : ℕ → State M → X → ℝ≥0∞ + | 0, j, s => w n j s + | k+1, j, s => ∫⁻ x, ∑ a : Action M, K.transition (n+1) j (x,⟪ι s,x⟫) a * + if a.1 then w (n+1) a.2 s else cont (n+1) k a.2 s ∂stdGaussian (Vector d) + +lemma measurable_cont (hK : K.Borel) (hw : ∀ n j, Measurable (w n j)) + (hι : Measurable ι) (n k : ℕ) (j : State M) : Measurable (K.cont w ι n k j) := by + induction k generalizing n j with + | zero => exact hw n j + | succ k ih => + apply Measurable.lintegral_prod_left + apply Finset.measurable_sum _ + intro a _ + apply ((hK (n+1) j a).comp (by fun_prop)).mul + rcases a with ⟨b,a⟩ + cases b + · exact (ih (n+1) a).comp measurable_snd + · exact (hw (n+1) a).comp measurable_snd + +omit [MeasurableSpace X] in +lemma cont_le_forced_sum (hK : K.Borel) (n k : ℕ) (j : State M) (s : X) : + K.cont w ι n k j s ≤ ∑ r ∈ Finset.range (k+1), + MemoryPrecision.stochCont K.marginal w ι n r j s := by + classical + induction k generalizing n j with + | zero => simp [cont, MemoryPrecision.stochCont] + | succ k ih => + let V (a : State M) := ∑ r ∈ Finset.range (k+1), + MemoryPrecision.stochCont K.marginal w ι (n+1) r a s + have hwV (a : State M) : w (n+1) a s ≤ V a := by + simpa [MemoryPrecision.stochCont] using + (Finset.single_le_sum (fun r _ => bot_le (a := MemoryPrecision.stochCont K.marginal w ι (n+1) r a s)) + (show 0 ∈ Finset.range (k+1) by simp)) + calc + _ ≤ ∫⁻ x, ∑ a : Action M, K.transition (n+1) j (x,⟪ι s,x⟫) a * V a.2 + ∂stdGaussian (Vector d) := lintegral_mono (fun x => Finset.sum_le_sum (fun a _ => by + apply mul_le_mul' le_rfl + split + · exact hwV a.2 + · exact ih (n+1) a.2)) + _ = ∑ r ∈ Finset.range (k+1), MemoryPrecision.stochCont K.marginal w ι n (r+1) j s := by + simp only [MemoryPrecision.stochCont] + have hm (r : ℕ) : Measurable (fun x : Vector d => ∑ a, + K.marginal (n+1) j (x,⟪ι s,x⟫) a * + MemoryPrecision.stochCont K.marginal w ι (n+1) r a s) := + Finset.measurable_sum _ (fun a _ => + ((K.marginal_measurable hK (n+1) j a).comp (by fun_prop)).mul measurable_const) + rw [← lintegral_finsetSum _ (fun r _ => hm r)] + apply lintegral_congr + intro x + simp only [V, Finset.mul_sum, Fintype.sum_prod_type, marginal, Finset.sum_mul] + rw [Finset.sum_comm] + conv_lhs => + arg 2 + ext a + rw [Finset.sum_comm] + rw [Finset.sum_comm] + _ ≤ ∑ r ∈ Finset.range (k+1+1), MemoryPrecision.stochCont K.marginal w ι n r j s := by + conv_rhs => rw [Finset.sum_range_succ'] + exact le_add_of_nonneg_right (show (0 : ℝ≥0∞) ≤ _ from zero_le) + +end Evaluation +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelIntegral.lean b/lean/OAI/Probability/MemoryPrecision/KernelIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d07d310ce6b9adfd528708098680e186f065eb6 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelIntegral.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelEvaluation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +namespace Policy +variable {d M T : ℕ} (K : Policy d M T) +variable {X : Type*} [MeasurableSpace X] +variable (w : ℕ → State M → X → ℝ≥0∞) (ι : X → Vector d) + +lemma measurable_records_at (s : X) (k : ℕ) : + Measurable (fun A : Rows d k => ((s, (fun i => (A i,⟪ι s,A i⟫))) : X × Observations d k)) := by + exact measurable_const.prodMk + (Measurable.of_eval (fun index => (measurable_pi_apply index).prodMk (by fun_prop))) + +lemma cont_eq_integral (hK : K.Borel) (hw : ∀ n j, Measurable (w n j)) + (n k : ℕ) (j : State M) (s : X) : + K.cont w ι n k j s = + ∫⁻ A : Rows d k, K.eval w n k j s (fun i => (A i,⟪ι s,A i⟫)) ∂(RowLaw d k) := by + classical + induction k generalizing n j with + | zero => simp [cont, eval, RowLaw] + | succ k ih => + have hf : Measurable (fun A : Rows d (k+1) => + K.eval w n (k+1) j s (fun i => (A i,⟪ι s,A i⟫))) := by + exact (K.measurable_eval w hK hw n (k+1) j).comp (measurable_records_at ι s (k+1)) + rw [RowLaw, NoiselessRegression.lintegral_pi_cons _ _ hf] + unfold cont + apply lintegral_congr + intro x + simp only [eval, Fin.cons_zero] + have hm (a : Action M) : Measurable (fun A : Rows d k => + if a.1 then w (n+1) a.2 s + else K.eval w (n+1) k a.2 s (fun i => (A i,⟪ι s,A i⟫))) := by + rcases a with ⟨b,a⟩ + cases b + · exact (K.measurable_eval w hK hw (n+1) k a).comp (measurable_records_at ι s k) + · exact measurable_const + change (∑ a : Action M, K.transition (n+1) j (x,⟪ι s,x⟫) a * + if a.1 then w (n+1) a.2 s else K.cont w ι (n+1) k a.2 s) = + ∫⁻ A : Rows d k, ∑ a : Action M, K.transition (n+1) j (x,⟪ι s,x⟫) a * + if a.1 then w (n+1) a.2 s + else K.eval w (n+1) k a.2 s (fun i => (A i,⟪ι s,A i⟫)) + ∂Measure.pi (fun _ => stdGaussian (Vector d)) + rw [lintegral_finsetSum _ (fun a _ => (hm a).const_mul _)] + apply Finset.sum_congr rfl + intro a _ + rw [lintegral_const_mul _ (hm a)] + congr 1 + rcases a with ⟨b,a⟩ + cases b + · exact ih (n+1) a + · simp + +lemma pathValue_integral_le (hK : K.Borel) (hw : ∀ n j, Measurable (w n j)) + (s : X) : + (∫⁻ A : Rows d T, K.pathValue w s (fun i => (A i,⟪ι s,A i⟫)) ∂(RowLaw d T)) ≤ + ∑ a : Action M, K.initial a * + (∑ r ∈ Finset.range (T+1), MemoryPrecision.stochCont K.marginal w ι 0 r a.2 s) := by + classical + have hm (a : Action M) : Measurable (fun A : Rows d T => + if a.1 then w 0 a.2 s else K.eval w 0 T a.2 s (fun i => (A i,⟪ι s,A i⟫))) := by + rcases a with ⟨b,a⟩ + cases b + · exact (K.measurable_eval w hK hw 0 T a).comp (measurable_records_at ι s T) + · exact measurable_const + unfold pathValue + rw [lintegral_finsetSum _ (fun a _ => (hm a).const_mul _)] + apply Finset.sum_le_sum + intro a _ + rw [lintegral_const_mul _ (hm a)] + apply mul_le_mul' le_rfl + rcases a with ⟨b,a⟩ + cases b + · change (∫⁻ A : Rows d T, K.eval w 0 T a s (fun i => (A i,⟪ι s,A i⟫)) ∂(RowLaw d T)) ≤ _ + rw [← K.cont_eq_integral w ι hK hw 0 T a s] + exact K.cont_le_forced_sum w ι hK 0 T a s + · change (∫⁻ _A : Rows d T, w 0 a s ∂(RowLaw d T)) ≤ _ + rw [lintegral_const] + have : IsProbabilityMeasure (RowLaw d T) := by unfold RowLaw; infer_instance + simp only [measure_univ, mul_one] + simpa only [MemoryPrecision.stochCont] using + (Finset.single_le_sum (fun length _ => + (show (0:ℝ≥0∞) ≤ MemoryPrecision.stochCont K.marginal w ι 0 length a s from zero_le)) + (show 0 ∈ Finset.range (T+1) by simp) : + MemoryPrecision.stochCont K.marginal w ι 0 0 a s ≤ + ∑ r ∈ Finset.range (T+1), MemoryPrecision.stochCont K.marginal w ι 0 r a s) + +lemma experiment_fixed_measurable (hK : K.Borel) + {f : Sphere d × Sphere d → ℝ≥0∞} (hf : Measurable f) : + Measurable (fun z : Sphere d × Rows d T => K.pathValue (K.outputTest f) z.1 (records z.1 z.2)) := by + apply Finset.measurable_sum _ + intro a _ + apply Measurable.const_mul + rcases a with ⟨b,a⟩ + cases b + · exact (K.measurable_eval (K.outputTest f) hK (K.outputTest_measurable hf) 0 T a).comp (by + exact measurable_fst.prodMk (Measurable.of_eval (fun index => by + change Measurable (fun z : Sphere d × Rows d T => (z.2 index,⟪z.1.val,z.2 index⟫)) + fun_prop))) + · exact (K.outputTest_measurable hf 0 a).comp measurable_fst + +lemma integral_pathValue_bound (hK : K.Borel) (hw : ∀ n j, Measurable (w n j)) + (hι : Measurable ι) (ν : Measure X) {B : ℝ≥0∞} + (hb : ∀ (r : ℕ), r ≤ T → ∀ j, + (∫⁻ s, MemoryPrecision.stochCont K.marginal w ι 0 r j s ∂ν) ≤ B) : + (∫⁻ s, ∫⁻ A : Rows d T, K.pathValue w s (fun i => (A i,⟪ι s,A i⟫)) ∂(RowLaw d T) ∂ν) ≤ + (T+1:ℝ≥0∞) * B := by + classical + have hm (a : Action M) : Measurable (fun s => + ∑ r ∈ Finset.range (T+1), MemoryPrecision.stochCont K.marginal w ι 0 r a.2 s) := + Finset.measurable_sum _ (fun r _ => + MemoryPrecision.measurable_stochCont (K.marginal_measurable hK) hw hι 0 r a.2) + calc + _ ≤ ∫⁻ s, ∑ a : Action M, K.initial a * + (∑ r ∈ Finset.range (T+1), MemoryPrecision.stochCont K.marginal w ι 0 r a.2 s) ∂ν := + lintegral_mono (K.pathValue_integral_le w ι hK hw) + _ = ∑ a : Action M, K.initial a * + (∑ r ∈ Finset.range (T+1), ∫⁻ s, + MemoryPrecision.stochCont K.marginal w ι 0 r a.2 s ∂ν) := by + rw [lintegral_finsetSum _ (fun a _ => (hm a).const_mul _)] + apply Finset.sum_congr rfl + intro a _ + rw [lintegral_const_mul _ (hm a), lintegral_finsetSum _ (fun r _ => + MemoryPrecision.measurable_stochCont (K.marginal_measurable hK) hw hι 0 r a.2)] + _ ≤ ∑ a : Action M, K.initial a * ((T+1:ℝ≥0∞)*B) := by + apply Finset.sum_le_sum + intro a _ + apply mul_le_mul' le_rfl + calc + _ ≤ ∑ _r ∈ Finset.range (T+1), B := Finset.sum_le_sum (fun r hr => hb r (by simpa using Nat.le_of_lt_succ (Finset.mem_range.mp hr)) a.2) + _ = _ := by simp [nsmul_eq_mul] + _ = _ := by rw [← Finset.sum_mul, K.initial_sum, one_mul] +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelModel.lean b/lean/OAI/Probability/MemoryPrecision/KernelModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..0f049b6b714ce4cd459038ccbce2e81f4681cdd0 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelModel.lean @@ -0,0 +1,133 @@ +import Mathlib + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +abbrev Vector (d : ℕ) := EuclideanSpace ℝ (Fin d) +abbrev Sphere (d : ℕ) := Metric.sphere (0 : Vector d) 1 +abbrev State (M : ℕ) := Fin (2^M) +abbrev Action (M : ℕ) := Bool × State M +abbrev Observations (d k : ℕ) := Fin k → (Vector d × ℝ) +abbrev Rows (d k : ℕ) := Fin k → Vector d + +def UniformSphere (d : ℕ) : Measure (Sphere d) := + let euclideanGroup : NormedAddCommGroup (Vector d) := + PiLp.normedAddCommGroup + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) + (fun _ : Fin d => ℝ) + let euclideanInner := PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ) + let σ := @Measure.toSphere (Vector d) euclideanGroup + (@InnerProductSpace.toNormedSpace ℝ (Vector d) _ + euclideanGroup.toSeminormedAddCommGroup euclideanInner) inferInstance + (@volume (Vector d) (@measureSpaceOfInnerProductSpace (Vector d) + euclideanGroup euclideanInner inferInstance inferInstance inferInstance)) + (σ Set.univ)⁻¹ • σ + +def RowLaw (d k : ℕ) : @Measure (Rows d k) + (@MeasurableSpace.pi (Fin k) (fun _ => Vector d) + (fun _ => @WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) + (Fin d → ℝ) inferInstance)) := + let euclideanMeasurable := @WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) + (Fin d → ℝ) inferInstance + @Measure.pi (Fin k) (fun _ => Vector d) inferInstance (fun _ => euclideanMeasurable) + (fun _ => @stdGaussian (Vector d) + (PiLp.normedAddCommGroup + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) + (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ)) inferInstance euclideanMeasurable) +def ObservationReference (d : ℕ) : Measure (Vector d × ℝ) := + (stdGaussian (Vector d)).prod volume + +structure Policy (d M T : ℕ) where + initial : Action M → ℝ≥0∞ + initial_sum : ∑ a, initial a = 1 + transition : ℕ → State M → (Vector d × ℝ) → Action M → ℝ≥0∞ + transition_sum : ∀ t j obs, ∑ a, transition t j obs a = 1 + output : ℕ → State M → Measure (Sphere d) + output_probability : ∀ t j, IsProbabilityMeasure (output t j) + +namespace Policy +instance {d M T : ℕ} (K : Policy d M T) (t : ℕ) (j : State M) : + IsProbabilityMeasure (K.output t j) := K.output_probability t j + +def Completed {d M T : ℕ} (K : Policy d M T) : Prop := + ∀ t j a, AEMeasurable (fun obs => K.transition t j obs a) (ObservationReference d) +def Borel {d M T : ℕ} (K : Policy d M T) : Prop := + ∀ t j a, Measurable (fun obs => K.transition t j obs a) + +def eval {d M T : ℕ} {X : Type*} (K : Policy d M T) + (w : ℕ → State M → X → ℝ≥0∞) (n : ℕ) : + (k : ℕ) → State M → X → Observations d k → ℝ≥0∞ + | 0, j, s, _ => w n j s + | k+1, j, s, obs => ∑ a : Action M, K.transition (n+1) j (obs 0) a * + if a.1 then w (n+1) a.2 s else K.eval w (n+1) k a.2 s (Fin.tail obs) + +def pathValue {d M T : ℕ} {X : Type*} (K : Policy d M T) + (w : ℕ → State M → X → ℝ≥0∞) (s : X) (obs : Observations d T) : ℝ≥0∞ := + ∑ a : Action M, K.initial a * if a.1 then w 0 a.2 s else K.eval w 0 T a.2 s obs + +def records {d T : ℕ} (s : Sphere d) (A : Rows d T) : Observations d T := + fun index => (A index, @inner ℝ (EuclideanSpace ℝ (Fin d)) + (@InnerProductSpace.toInner ℝ (EuclideanSpace ℝ (Fin d)) _ + (PiLp.seminormedAddCommGroup + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) + (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))) s.val (A index)) + +def outputTest {d M T : ℕ} (K : Policy d M T) (f : Sphere d × Sphere d → ℝ≥0∞) + (t : ℕ) (j : State M) (s : Sphere d) : ℝ≥0∞ := + ∫⁻ v, f (s,v) ∂K.output t j + +def angleTest {d : ℕ} (ε : ℝ) + (point : MemoryPrecision.Kernel.Sphere d × MemoryPrecision.Kernel.Sphere d) : ℝ≥0∞ := + @ite ℝ≥0∞ (Real.arccos (@inner ℝ (EuclideanSpace ℝ (Fin d)) + (@InnerProductSpace.toInner ℝ (EuclideanSpace ℝ (Fin d)) _ + (PiLp.seminormedAddCommGroup + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) + (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))) + point.2.val point.1.val) ≤ ε) (Classical.propDecidable _) 1 0 + +def chordTest {d : ℕ} (ε : ℝ) (x : Sphere d × Sphere d) : ℝ≥0∞ := + {x : Sphere d × Sphere d | dist x.2.val x.1.val ≤ ε}.indicator (fun _ => 1) x + +def experiment {d M T : ℕ} {Ω : Type u} (K : Ω → Policy d M T) + (f : Sphere d × Sphere d → ℝ≥0∞) (z : Sphere d × (Ω × Rows d T)) : ℝ≥0∞ := + (K z.2.1).pathValue ((K z.2.1).outputTest f) z.1 (records z.1 z.2.2) + +structure Admissible {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (K : Ω → Policy d M T) (ρ : Measure Ω) (π : Measure (Sphere d)) : Prop where + completed : ∀ᵐ ω ∂ρ, (K ω).Completed + experiment : ∀ f : Sphere d × Sphere d → ℝ≥0∞, Measurable f → + (∀ x, f x ≤ 1) → AEMeasurable (experiment K f) (π.prod (ρ.prod (RowLaw d T))) + +def Success {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (K : Ω → Policy d M T) (ρ : Measure Ω) (π : Measure (Sphere d)) (ε : ℝ) : ℝ≥0∞ := + ∫⁻ z, experiment K (angleTest ε) z ∂π.prod (ρ.prod (RowLaw d T)) +def ChordSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (K : Ω → Policy d M T) (ρ : Measure Ω) (π : Measure (Sphere d)) (ε : ℝ) : ℝ≥0∞ := + ∫⁻ z, experiment K (chordTest ε) z ∂π.prod (ρ.prod (RowLaw d T)) +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelSphere.lean b/lean/OAI/Probability/MemoryPrecision/KernelSphere.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a241df7d31348e3541ccc7a3aea2c1954df6b14 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelSphere.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelCaps +import OAI.Probability.MemoryPrecision.KernelIntegral +import OAI.Probability.MemoryPrecision.KernelVersion +import OAI.Probability.MemoryPrecision.SeedAverage +import OAI.Probability.MemoryPrecision.StochasticMass + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +open MemoryPrecision NoiselessRegression +namespace Policy +variable {d M T : ℕ} (K : Policy d M T) + +lemma borel_sphere_bound (hK : K.Borel) (hd : 16 ≤ d) {ε α : ℝ} (hε : 0 < ε) + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) : + (∫⁻ z : MemoryPrecision.Kernel.Sphere d × Rows d T, + K.pathValue (K.outputTest (chordTest ε)) z.1 (records z.1 z.2) + ∂(UniformSphere d).prod (RowLaw d T)) ≤ + (T+1:ℝ≥0∞)*ENNReal.ofReal + ((3*4^d:ℝ)*ε^((d:ℝ)-1-α)*RealStep d (2^M)^BlockCount T (d/8)) := by + have : NeZero d := ⟨by omega⟩ + rw [lintegral_prod _ (K.experiment_fixed_measurable hK (measurable_chordTest ε)).aemeasurable] + apply K.integral_pathValue_bound (K.outputTest (chordTest ε)) Subtype.val hK + (K.outputTest_measurable (measurable_chordTest ε)) measurable_subtype_coe (UniformSphere d) + intro r hr j + have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd + have hb := stoch_sphere_mass hd (show 1 ≤ 2^M from one_le_pow₀ (by norm_num)) + (K.marginal_measurable hK) (fun n j obs => (K.marginal_sum n j obs).le) + (K.outputTest_measurable (measurable_chordTest ε)) + (K.outputTest_le_one (chordTest_le_one ε)) + (H := (3*4^d)*ε^((d:ℝ)-1-α)) (by positivity) hαlo hαhi + (K.output_chord_sphere_local (by omega) hε (by linarith) (by linarith)) + (BlockCount T (d/8)) r (hr.trans (blockCount_mul_ge T (by omega))) 0 j + exact sphere_mass_bound hb + +lemma completed_sphere_bound (hK : K.Completed) (hd : 16 ≤ d) {ε α : ℝ} (hε : 0 < ε) + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) : + (∫⁻ z : MemoryPrecision.Kernel.Sphere d × Rows d T, + K.pathValue (K.outputTest (chordTest ε)) z.1 (records z.1 z.2) + ∂(UniformSphere d).prod (RowLaw d T)) ≤ + (T+1:ℝ≥0∞)*ENNReal.ofReal + ((3*4^d:ℝ)*ε^((d:ℝ)-1-α)*RealStep d (2^M)^BlockCount T (d/8)) := by + have : NeZero d := ⟨by omega⟩ + have he := K.version_pathValue_ae ((UniformSphere d).prod (RowLaw d T)) hK Prod.fst + (fun z : MemoryPrecision.Kernel.Sphere d × Rows d T => records z.1 z.2) + (fun i => show Measure.QuasiMeasurePreserving _ _ _ from + sphere_sample_observation_quasi (by simpa using (show 3 ≤ d by omega)) i) (chordTest ε) + rw [← lintegral_congr_ae he] + exact (K.version hK).borel_sphere_bound (K.version_borel hK) hd hε hαlo hαhi + +lemma chord_real_bound {Ω : Type u} [MeasurableSpace Ω] (L : Ω → Policy d M T) + (ρ : Measure Ω) [IsProbabilityMeasure ρ] (hL : Admissible L ρ (UniformSphere d)) + (hd : 16 ≤ d) {ε α : ℝ} (hε : 0 < ε) + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) : + ChordSuccess L ρ (UniformSphere d) ε ≤ + (T+1:ℝ≥0∞)*ENNReal.ofReal + ((3*4^d:ℝ)*ε^((d:ℝ)-1-α)*RealStep d (2^M)^BlockCount T (d/8)) := by + have : NeZero d := ⟨by omega⟩ + apply seed_average_bound (UniformSphere d) (RowLaw d T) ρ + (hL.experiment (chordTest ε) (measurable_chordTest ε) (chordTest_le_one ε)) + filter_upwards [hL.completed] with ω hω + exact (L ω).completed_sphere_bound hω hd hε hαlo hαhi + +lemma zero_fixed_sphere_bound {d M : ℕ} (K : Policy d M 0) (hd : 1 ≤ d) + {ε : ℝ} (hε : 0 < ε) : + (∫⁻ z : MemoryPrecision.Kernel.Sphere d × Rows d 0, + K.pathValue (K.outputTest (chordTest ε)) z.1 (records z.1 z.2) + ∂(UniformSphere d).prod (RowLaw d 0)) ≤ ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1)) := by + have : NeZero d := ⟨by omega⟩ + have he (s : MemoryPrecision.Kernel.Sphere d) (obs : Observations d 0) : + K.pathValue (K.outputTest (chordTest ε)) s obs = + ∑ a : Action M, K.initial a * K.outputTest (chordTest ε) 0 a.2 s := by + unfold pathValue + simp only [eval, ite_self] + simp_rw [he] + have hm : Measurable (fun s : MemoryPrecision.Kernel.Sphere d => + ∑ a : Action M, K.initial a * K.outputTest (chordTest ε) 0 a.2 s) := + Finset.measurable_sum _ (fun a _ => (K.outputTest_measurable (measurable_chordTest ε) 0 a.2).const_mul _) + have hm' : Measurable (fun z : MemoryPrecision.Kernel.Sphere d × Rows d 0 => + ∑ a : Action M, K.initial a * K.outputTest (chordTest ε) 0 a.2 z.1) := + hm.comp measurable_fst + rw [lintegral_prod _ hm'.aemeasurable] + simp only [lintegral_const, measure_univ, mul_one] + rw [lintegral_finsetSum _ (fun a _ => + (K.outputTest_measurable (measurable_chordTest ε) 0 a.2).const_mul _)] + calc + _ = ∑ a : Action M, K.initial a * + (∫⁻ s, K.outputTest (chordTest ε) 0 a.2 s ∂UniformSphere d) := by + apply Finset.sum_congr rfl + intro a _ + exact lintegral_const_mul _ (K.outputTest_measurable (measurable_chordTest ε) 0 a.2) + _ ≤ ∑ a : Action M, K.initial a * ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1)) := + Finset.sum_le_sum (fun a _ => mul_le_mul' le_rfl (K.output_chord_sphere_total hd hε 0 a.2)) + _ = _ := by rw [← Finset.sum_mul, K.initial_sum, one_mul] + +lemma chord_zero_bound {d M : ℕ} {Ω : Type u} [MeasurableSpace Ω] (L : Ω → Policy d M 0) + (ρ : Measure Ω) [IsProbabilityMeasure ρ] (hL : Admissible L ρ (UniformSphere d)) + (hd : 1 ≤ d) {ε : ℝ} (hε : 0 < ε) : + ChordSuccess L ρ (UniformSphere d) ε ≤ ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1)) := by + have : NeZero d := ⟨by omega⟩ + apply seed_average_bound (UniformSphere d) (RowLaw d 0) ρ + (hL.experiment (chordTest ε) (measurable_chordTest ε) (chordTest_le_one ε)) + exact Filter.Eventually.of_forall (fun ω => (L ω).zero_fixed_sphere_bound hd hε) +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelStream.lean b/lean/OAI/Probability/MemoryPrecision/KernelStream.lean new file mode 100644 index 0000000000000000000000000000000000000000..5ad40d1c10a7524a529a873d32a91b4a2fece03e --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelStream.lean @@ -0,0 +1,73 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelEllipsoid +import OAI.Probability.MemoryPrecision.StreamArithmetic +import OAI.Probability.MemoryPrecision.StreamZero + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +open MemoryPrecision Policy + +def SourceStreamStatement : Prop := + ∃ C : ℝ, 0 < C ∧ ∃ d₀ : ℕ, 0 < d₀ ∧ + ∀ d M T : ℕ, d₀ ≤ d → ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Ω → MemoryPrecision.Kernel.Policy d M T, + MemoryPrecision.Kernel.Policy.Admissible L ρ (MemoryPrecision.Kernel.UniformSphere d) → + MemoryPrecision.Kernel.Policy.Success L ρ (MemoryPrecision.Kernel.UniformSphere d) ε ≤ min 1 (ENNReal.ofReal + ((2*ε*Real.exp (C*(1+(M:ℝ)/(d:ℝ)^2)*(MemoryPrecision.Kernel.BlockCount T ((d-1)/8):ℝ)))^(((d:ℝ)-1)/2))) + +lemma source_stream_explicit : + ∀ d M T : ℕ, 32 ≤ d → ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Ω → Policy d M T, Admissible L ρ (UniformSphere d) → + Success L ρ (UniformSphere d) ε ≤ min 1 (ENNReal.ofReal + ((2*ε*Real.exp (StreamConstant*(1+(M:ℝ)/(d:ℝ)^2)*(BlockCount T ((d-1)/8):ℝ)))^(((d:ℝ)-1)/2))) := by + intro d M T hd ε hε hε1 Ω _ ρ hρ L hL + have : IsProbabilityMeasure ρ := hρ + let : NeZero d := ⟨by omega⟩ + refine le_min (Policy.success_le_one L ρ (UniformSphere d) ε) ?_ + apply (Policy.success_le_chord L ρ (UniformSphere d) ε).trans + by_cases hT : T = 0 + · subst T + simp only [BlockCount, Nat.ceil_zero, zero_div, Nat.cast_zero, mul_zero, Real.exp_zero, mul_one] + exact (Policy.chord_zero_bound L ρ hL (by omega) hε).trans + (ENNReal.ofReal_le_ofReal (zero_cap_precise hd hε hε1)) + · apply (chord_half_sphere_bound L ρ hL (by omega) hε hε1).trans + apply ENNReal.ofReal_le_ofReal + let a := ((d:ℝ)-1)/2 + let X := StreamConstant*(1+(M:ℝ)/(d:ℝ)^2)*(BlockCount T ((d-1)/8):ℝ) + have ha : 0 ≤ a := by + dsimp [a] + have : (32:ℝ) ≤ d := by exact_mod_cast hd + linarith + have he : Real.exp (a*X) = (Real.exp X)^a := by rw [← Real.exp_mul, mul_comm] + have h2 : ε^a ≤ (2*ε)^a := Real.rpow_le_rpow hε.le (by linarith) ha + calc + _ = ε^a * ((4:ℝ)^d * (SuccessConstant^d * + (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^BlockCount T (d/8)) := by dsimp [a, BlockCount, MemoryPrecision.BlockCount]; ring + _ ≤ ε^a * Real.exp (a*X) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + simpa only [a, X, BlockCount, MemoryPrecision.BlockCount, mul_assoc] using stream_full_factor hd (by omega : 0 < T) + _ ≤ (2*ε)^a * Real.exp (a*X) := mul_le_mul_of_nonneg_right h2 (by positivity) + _ = (2*ε*Real.exp X)^a := by + rw [he] + exact (Real.mul_rpow (by positivity : (0:ℝ) ≤ 2*ε) (Real.exp_pos X).le).symm +theorem source_stream_success : SourceStreamStatement := + ⟨StreamConstant, streamConstant_pos, 32, by norm_num, source_stream_explicit⟩ +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/KernelVersion.lean b/lean/OAI/Probability/MemoryPrecision/KernelVersion.lean new file mode 100644 index 0000000000000000000000000000000000000000..767cbd0183ae358ed077eee7602734d79094f3ec --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/KernelVersion.lean @@ -0,0 +1,107 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CoefficientStep + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +namespace Policy +variable {d M T : ℕ} (K : Policy d M T) +private def versionCoordinates (hK : K.Completed) (t : ℕ) (j : State M) + (obs : Vector d × ℝ) (a : Action M) : ℝ≥0∞ := + (hK t j a).mk (fun obs => K.transition t j obs a) obs +private lemma measurable_versionCoordinates (hK : K.Completed) (t : ℕ) (j : State M) (a : Action M) : + Measurable (fun obs => K.versionCoordinates hK t j obs a) := + (hK t j a).measurable_mk +private lemma versionCoordinates_ae (hK : K.Completed) (t : ℕ) (j : State M) : + ∀ᵐ obs ∂ObservationReference d, ∀ a, K.versionCoordinates hK t j obs a = K.transition t j obs a := by + apply ae_all_iff.mpr + intro a + exact (hK t j a).ae_eq_mk.symm + +def version (hK : K.Completed) : Policy d M T where + initial := K.initial + initial_sum := K.initial_sum + transition := fun t j obs a => if ∑ b, K.versionCoordinates hK t j obs b = 1 + then K.versionCoordinates hK t j obs a else if a = (false,0) then 1 else 0 + transition_sum := by + intro t j obs + split_ifs with h + · exact h + · simp + output := K.output + output_probability := K.output_probability + +lemma version_borel (hK : K.Completed) : (K.version hK).Borel := by + intro t j a + exact Measurable.ite + (measurableSet_eq_fun (Finset.measurable_sum _ (fun b _ => + K.measurable_versionCoordinates hK t j b)) measurable_const) + (K.measurable_versionCoordinates hK t j a) measurable_const + +lemma version_transition_ae (hK : K.Completed) (t : ℕ) (j : State M) : + ∀ᵐ obs ∂ObservationReference d, ∀ a, (K.version hK).transition t j obs a = K.transition t j obs a := by + filter_upwards [K.versionCoordinates_ae hK t j] with obs h + have he : ∑ a, K.versionCoordinates hK t j obs a = 1 := by + simpa only [h] using K.transition_sum t j obs + intro a + simp only [version, h, K.transition_sum, ite_true] + +lemma eval_eq_of_rules {L : Policy d M T} {X : Type*} + (w : ℕ → State M → X → ℝ≥0∞) (n k : ℕ) (j : State M) (s : X) + (obs : Observations d k) + (h : ∀ t j i a, K.transition t j (obs i) a = L.transition t j (obs i) a) : + K.eval w n k j s obs = L.eval w n k j s obs := by + induction k generalizing n j with + | zero => rfl + | succ k ih => + simp only [eval, h] + congr 1 + funext a + congr 1 + split + · rfl + · exact ih (n+1) a.2 (Fin.tail obs) (fun t j i a => h t j i.succ a) + +lemma version_pathValue_ae {X : Type*} [MeasurableSpace X] (μ : Measure X) + (hK : K.Completed) (s : X → Sphere d) (obs : X → Observations d T) + (ho : ∀ i : Fin T, Measure.QuasiMeasurePreserving (fun z => obs z i) μ (ObservationReference d)) + (f : Sphere d × Sphere d → ℝ≥0∞) : + (fun z => (K.version hK).pathValue ((K.version hK).outputTest f) (s z) (obs z)) =ᵐ[μ] + (fun z => K.pathValue (K.outputTest f) (s z) (obs z)) := by + have hall : ∀ᵐ z ∂μ, ∀ i t j a, + (K.version hK).transition t j (obs z i) a = K.transition t j (obs z i) a := by + apply ae_all_iff.mpr + intro i + apply ae_all_iff.mpr + intro t + apply ae_all_iff.mpr + intro j + exact (ho i).ae (K.version_transition_ae hK t j) + filter_upwards [hall] with z hz + change (∑ a : Action M, K.initial a * if a.1 then K.outputTest f 0 a.2 (s z) + else (K.version hK).eval (K.outputTest f) 0 T a.2 (s z) (obs z)) = _ + simp only [pathValue] + congr 1 + funext a + congr 1 + split + · rfl + · exact (K.version hK).eval_eq_of_rules (K.outputTest f) 0 T a.2 (s z) (obs z) + (fun t j i a => hz i t j a) +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/LabelTranslations.lean b/lean/OAI/Probability/MemoryPrecision/LabelTranslations.lean new file mode 100644 index 0000000000000000000000000000000000000000..f8b181e9798a7b1bdd5b62a2b0a5f9d55c2a9613 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/LabelTranslations.lean @@ -0,0 +1,160 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +section Translation +variable {Ω Y : Type*} + [TopologicalSpace Ω] [MeasurableSpace Ω] [BorelSpace Ω] [R1Space Ω] + [NormedAddCommGroup Y] [MeasurableSpace Y] [BorelSpace Y] [SecondCountableTopology Y] + (γ : Measure Ω) [SFinite γ] (τ : Measure Y) [SFinite τ] [τ.IsAddRightInvariant] + +def labelTranslate (u : Y) : C(Ω × Y, Ω × Y) := + ⟨fun x => (x.1, x.2 + u), by fun_prop⟩ + +omit [BorelSpace Ω] [R1Space Ω] [SecondCountableTopology Y] in +lemma measurePreserving_labelTranslate (u : Y) : + MeasurePreserving (labelTranslate u) (γ.prod τ) (γ.prod τ) := by + exact (MeasurePreserving.id γ).prod (measurePreserving_add_right τ u) + +omit [MeasurableSpace Ω] [BorelSpace Ω] [R1Space Ω] + [MeasurableSpace Y] [BorelSpace Y] [SecondCountableTopology Y] in +lemma continuous_labelTranslate : Continuous (labelTranslate (Ω := Ω) (Y := Y)) := by + apply ContinuousMap.continuous_of_continuous_uncurry + change Continuous (fun z : Y × (Ω × Y) => (z.2.1, z.2.2 + z.1)) + fun_prop + +variable [(γ.prod τ).InnerRegularCompactLTTop] [IsLocallyFiniteMeasure (γ.prod τ)] + +lemma tendsto_eLpNorm_labelTranslate_sub {F : Ω × Y → ℝ} (hF : MemLp F 1 (γ.prod τ)) : + Tendsto (fun u : Y => eLpNorm (fun x => F (x.1, x.2 + u) - F x) 1 (γ.prod τ)) + (𝓝 0) (𝓝 0) := by + let f := hF.toLp F + let g := fun u => Lp.compMeasurePreserving (labelTranslate u) + (measurePreserving_labelTranslate γ τ u) f + have hc : Continuous g := continuous_const.compMeasurePreservingLp continuous_labelTranslate + (measurePreserving_labelTranslate γ τ) (by simp) + have hg0 : g 0 = f := by + have he : (labelTranslate (Ω := Ω) (0:Y) : Ω × Y → Ω × Y) = id := by + ext x <;> simp [labelTranslate] + dsimp only [g] + simp only [he, Lp.compMeasurePreserving_id_apply] + have ht : Tendsto g (𝓝 0) (𝓝 (hF.toLp F)) := by + simpa only [hg0] using hc.tendsto 0 + have hl := (Lp.tendsto_Lp_iff_tendsto_eLpNorm g F hF).mp ht + apply hl.congr' + apply Eventually.of_forall + intro u + apply eLpNorm_congr_ae + have he := (Lp.coeFn_compMeasurePreserving f (measurePreserving_labelTranslate γ τ u)).trans + ((measurePreserving_labelTranslate γ τ u).quasiMeasurePreserving.ae_eq_comp hF.coeFn_toLp) + filter_upwards [he] with x hx + exact congrArg (fun t => t - F x) hx + +omit [BorelSpace Ω] [R1Space Ω] [SecondCountableTopology Y] + [(γ.prod τ).InnerRegularCompactLTTop] [IsLocallyFiniteMeasure (γ.prod τ)] in +lemma eLpNorm_labelTranslate_sub_le {F : Ω × Y → ℝ} (hF : MemLp F 1 (γ.prod τ)) (u : Y) : + eLpNorm (fun x => F (x.1,x.2+u) - F x) 1 (γ.prod τ) ≤ + eLpNorm F 1 (γ.prod τ) + eLpNorm F 1 (γ.prod τ) := by + have hp := measurePreserving_labelTranslate γ τ u + have he := eLpNorm_comp_measurePreserving (p := (1:ℝ≥0∞)) hF.aestronglyMeasurable hp + exact (eLpNorm_sub_le le_rfl).trans_eq + (congrArg (fun t => t + eLpNorm F 1 (γ.prod τ)) he) +variable [NormedSpace ℝ Y] + +def averageTranslate (κ : Measure Y) (δ : ℝ) (F : Ω × Y → ℝ) (x : Ω × Y) : ℝ := + ∫ u, F (x.1, x.2 + δ • u) ∂κ + +omit [BorelSpace Ω] [R1Space Ω] + [(γ.prod τ).InnerRegularCompactLTTop] [IsLocallyFiniteMeasure (γ.prod τ)] in +lemma integrable_translate_product (κ : Measure Y) [IsProbabilityMeasure κ] + {F : Ω × Y → ℝ} (hFm : Measurable F) (hF : MemLp F 1 (γ.prod τ)) (δ : ℝ) : + Integrable (fun z : Y × (Ω × Y) => F (z.2.1,z.2.2 + δ • z.1)) + (κ.prod (γ.prod τ)) := by + refine ⟨(by fun_prop : Measurable _).aestronglyMeasurable, ?_⟩ + rw [hasFiniteIntegral_iff_enorm, lintegral_prod _ (by fun_prop)] + have he (u : Y) : (∫⁻ x, ‖F (x.1,x.2 + δ • u)‖ₑ ∂γ.prod τ) = + eLpNorm F 1 (γ.prod τ) := by + rw [← eLpNorm_one_eq_lintegral_enorm + ((show Measurable (fun point : Ω × Y => F (point.1, point.2 + δ • u)) + from by fun_prop).aestronglyMeasurable)] + exact eLpNorm_comp_measurePreserving hF.aestronglyMeasurable + (measurePreserving_labelTranslate γ τ (δ • u)) + simp_rw [he] + simpa using hF.eLpNorm_lt_top + +omit [BorelSpace Ω] [R1Space Ω] + [(γ.prod τ).InnerRegularCompactLTTop] [IsLocallyFiniteMeasure (γ.prod τ)] in +lemma eLpNorm_averageTranslate_sub_le (κ : Measure Y) [IsProbabilityMeasure κ] + {F : Ω × Y → ℝ} (hFm : Measurable F) (hF : MemLp F 1 (γ.prod τ)) (δ : ℝ) : + eLpNorm (fun x => averageTranslate κ δ F x - F x) 1 (γ.prod τ) ≤ + ∫⁻ u, eLpNorm (fun x => F (x.1,x.2 + δ • u) - F x) 1 (γ.prod τ) ∂κ := by + have haverage : StronglyMeasurable (averageTranslate κ δ F) := + ((show Measurable (fun pair : (Ω × Y) × Y => + F (pair.1.1, pair.1.2 + δ • pair.2)) from by fun_prop).stronglyMeasurable).integral_prod_right' + rw [eLpNorm_one_eq_lintegral_enorm + (f := fun point => averageTranslate κ δ F point - F point) + (haverage.aestronglyMeasurable.sub hF.aestronglyMeasurable)] + have hi := (integrable_translate_product γ τ κ hFm hF δ).prod_left_ae + calc + _ ≤ ∫⁻ x, ∫⁻ u, ‖F (x.1,x.2 + δ • u) - F x‖ₑ ∂κ ∂γ.prod τ := by + apply lintegral_mono_ae + filter_upwards [hi] with x hx + have he : averageTranslate κ δ F x - F x = + ∫ u, F (x.1,x.2 + δ • u) - F x ∂κ := by + rw [integral_sub hx (integrable_const (F x)), integral_const] + simp [averageTranslate] + rw [he] + exact enorm_integral_le_lintegral_enorm _ + _ = _ := by + rw [lintegral_lintegral_swap (by fun_prop)] + congr 1 + funext u + exact (eLpNorm_one_eq_lintegral_enorm (by fun_prop)).symm + +lemma tendsto_eLpNorm_averageTranslate_sub (κ : Measure Y) [IsProbabilityMeasure κ] + {F : Ω × Y → ℝ} (hFm : Measurable F) (hF : MemLp F 1 (γ.prod τ)) : + Tendsto (fun δ : ℝ => eLpNorm (fun x => averageTranslate κ δ F x - F x) + 1 (γ.prod τ)) (𝓝 0) (𝓝 0) := by + have ht : Tendsto (fun δ : ℝ => ∫⁻ u, eLpNorm + (fun x => F (x.1,x.2 + δ • u) - F x) 1 (γ.prod τ) ∂κ) + (𝓝 0) (𝓝 0) := by + have h := tendsto_lintegral_filter_of_dominated_convergence + (μ := κ) (l := 𝓝 (0:ℝ)) (f := fun _ => 0) + (fun _ => eLpNorm F 1 (γ.prod τ) + eLpNorm F 1 (γ.prod τ)) + (Eventually.of_forall (fun δ => ?_)) + (Eventually.of_forall (fun δ => Eventually.of_forall (fun u => + eLpNorm_labelTranslate_sub_le γ τ hF (δ • u)))) + (by simpa using ENNReal.add_ne_top.mpr ⟨hF.eLpNorm_lt_top.ne, hF.eLpNorm_lt_top.ne⟩) + (Eventually.of_forall (fun u => ?_)) + · simpa using h + · have hnorm (translation : Y) : + eLpNorm (fun point => F (point.1, point.2 + δ • translation) - F point) + 1 (γ.prod τ) = + ∫⁻ point, ‖F (point.1, point.2 + δ • translation) - F point‖ₑ ∂γ.prod τ := + eLpNorm_one_eq_lintegral_enorm (by fun_prop) + simp_rw [hnorm] + exact Measurable.lintegral_prod_right (by fun_prop) + · exact (tendsto_eLpNorm_labelTranslate_sub γ τ hF).comp + (by + have hc : Continuous (fun δ : ℝ => δ • u) := by fun_prop + simpa using hc.tendsto (0:ℝ)) + exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds ht + (fun _ => bot_le) (eLpNorm_averageTranslate_sub_le γ τ κ hFm hF) +end Translation +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/Main.lean b/lean/OAI/Probability/MemoryPrecision/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..37a55271d3acd46185eedc7ddef076013e2c520c --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/Main.lean @@ -0,0 +1,98 @@ +import OAI.Probability.MemoryPrecision.KernelModel +import OAI.Probability.MemoryPrecision.AmbientGram +import OAI.Probability.MemoryPrecision.SharpGaussian +import OAI.Probability.MemoryPrecision.DensityPassage +import OAI.Probability.MemoryPrecision.FiniteDensity +import OAI.Probability.MemoryPrecision.MeasurableTests +import OAI.Probability.MemoryPrecision.WeightedSelection +import OAI.Probability.MemoryPrecision.WeightedImage +import OAI.Probability.MemoryPrecision.CoefficientStep +import OAI.Probability.MemoryPrecision.RealContinuation +import OAI.Probability.MemoryPrecision.StochasticContinuation +import OAI.Probability.MemoryPrecision.KernelEvaluation +import OAI.Probability.MemoryPrecision.KernelIntegral +import OAI.Probability.MemoryPrecision.SphereCaps +import OAI.Probability.MemoryPrecision.CubeGeometry +import OAI.Probability.MemoryPrecision.CubeBlock +import OAI.Probability.MemoryPrecision.CubeCaps +import OAI.Probability.MemoryPrecision.CubeContinuation +import OAI.Probability.MemoryPrecision.StochasticMass +import OAI.Probability.MemoryPrecision.PriorMeasurability +import OAI.Probability.MemoryPrecision.CubeExperiment +import OAI.Probability.MemoryPrecision.KernelCaps +import OAI.Probability.MemoryPrecision.KernelVersion +import OAI.Probability.MemoryPrecision.SeedAverage +import OAI.Probability.MemoryPrecision.KernelSphere +import OAI.Probability.MemoryPrecision.KernelAdmissibility +import OAI.Probability.MemoryPrecision.CubeArithmetic +import OAI.Probability.MemoryPrecision.KernelCube +import OAI.Probability.MemoryPrecision.RealStream +import OAI.Probability.MemoryPrecision.ZeroHorizon +import OAI.Probability.MemoryPrecision.SuccessArithmetic +import OAI.Probability.MemoryPrecision.EllipsoidSuccess +import OAI.Probability.MemoryPrecision.StreamArithmetic +import OAI.Probability.MemoryPrecision.KernelEllipsoid +import OAI.Probability.MemoryPrecision.StreamZero +import OAI.Probability.MemoryPrecision.KernelStream +import OAI.Probability.MemoryPrecision.Reflection +import OAI.Probability.MemoryPrecision.Precision +import OAI.Probability.MemoryPrecision.CubeSuccess +import OAI.Probability.MemoryPrecision.LabelTranslations +import OAI.Probability.MemoryPrecision.JointL1 +import OAI.Probability.MemoryPrecision.SphericalProjection +import OAI.Probability.MemoryPrecision.PointwiseDensity +import OAI.Probability.MemoryPrecision.RadialMixture +import OAI.Probability.MemoryPrecision.BallAverages +import OAI.Probability.MemoryPrecision.GaussianConvolution +import OAI.Probability.MemoryPrecision.FiberDensity +import OAI.Probability.MemoryPrecision.DensityUniqueness +import OAI.Probability.MemoryPrecision.PointwiseMain + +namespace OAI + +universe u +namespace MemoryPrecision + +open MeasureTheory +open scoped ENNReal + +theorem main : + AmbientGramStatement ∧ + FiniteDensityStatement ∧ + MeasurableTestStatement ∧ + JointL1Statement ∧ + PointwiseDensityStatement ∧ + CoefficientStepStatement ∧ + Kernel.SourceEllipsoidStatement.{u} ∧ + CubeBlockStatement ∧ + (∃ D : ℝ, Real.exp 1 ≤ D ∧ ∃ d₀ : ℕ, ∃ hd₀ : 16 ≤ d₀, ∃ c : ℝ, 0 < c ∧ + ∀ d M T : ℕ, ∀ hd : d₀ ≤ d, M ≤ d^2 → ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ K : Ω → MemoryPrecision.Kernel.Policy d M T, + MemoryPrecision.Kernel.Policy.ModelAdmissible.{u} K ρ → + MemoryPrecision.Kernel.Policy.Success K ρ + (MemoryPrecision.Kernel.CubePrior (MemoryPrecision.Kernel.cubePrior_dimension hd₀ hd)) ε ≤ + min 1 (ENNReal.ofReal + (D^((d/2)*(MemoryPrecision.Kernel.BlockCount T ((d/2)/4)+1)) * ε^((d/2:ℕ)/4:ℝ))) ∧ + ((∀ signal : MemoryPrecision.Kernel.Sphere d, + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) / + (@OfNat.ofNat ℝ≥0∞ 3 + (@instOfNatAtLeastTwo ℝ≥0∞ 3 ENNReal.instAddCommMonoidWithOne.toNatCast inferInstance)) ≤ + (∫⁻ observation, + MemoryPrecision.Kernel.Policy.experiment K + (MemoryPrecision.Kernel.Policy.angleTest ε) (signal, observation) + ∂ρ.prod (MemoryPrecision.Kernel.RowLaw d T))) → + c*(d:ℝ)*Real.log (1/ε) ≤ (T:ℝ))) ∧ + (∃ C : ℝ, 0 < C ∧ ∃ d₀ : ℕ, 0 < d₀ ∧ + ∀ d M T : ℕ, d₀ ≤ d → ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Ω → MemoryPrecision.Kernel.Policy d M T, + MemoryPrecision.Kernel.Policy.Admissible L ρ (MemoryPrecision.Kernel.UniformSphere d) → + MemoryPrecision.Kernel.Policy.Success L ρ (MemoryPrecision.Kernel.UniformSphere d) ε ≤ min 1 (ENNReal.ofReal + ((2*ε*Real.exp (C*(1+(M:ℝ)/(d:ℝ)^2)*(MemoryPrecision.Kernel.BlockCount T ((d-1)/8):ℝ)))^(((d:ℝ)-1)/2)))) := + ⟨ambient_gram, finite_density, measurable_test, joint_l1, pointwise_density, coefficient_step, Kernel.source_ellipsoid_success, cube_block, Kernel.source_cube_success, Kernel.source_stream_success⟩ + +end MemoryPrecision + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/MeasurableTests.lean b/lean/OAI/Probability/MemoryPrecision/MeasurableTests.lean new file mode 100644 index 0000000000000000000000000000000000000000..3fedf0e827826a58518a763c8201692342842d2e --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/MeasurableTests.lean @@ -0,0 +1,181 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.FiniteDensity + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision + +section TestTransfer +variable {X : Type*} [mX : MeasurableSpace X] + +lemma original_le_completion (ν : Measure X) : + mX ≤ (inferInstance : MeasurableSpace (NullMeasurableSpace X ν)) := + fun _ hs => hs.nullMeasurableSet + +lemma trim_completion (ν : Measure X) : + ν.completion.trim (original_le_completion ν) = ν := by + unfold NullMeasurableSpace at * + apply Measure.ext + intro S hS + exact trim_measurableSet_eq (original_le_completion ν) hS + +lemma lintegral_completion (ν : Measure X) {f : X → ℝ≥0∞} (hf : AEMeasurable f ν) : + (∫⁻ x, f x ∂ν.completion) = ∫⁻ x, f x ∂ν := by + have ht : @Measure.trim X mX (inferInstance : MeasurableSpace (NullMeasurableSpace X ν)) + ν.completion (original_le_completion ν) = ν := trim_completion ν + have h := lintegral_trim_ae (α := X) (μ := ν.completion) (original_le_completion ν) + (f := f) (by rwa [ht]) + rw [ht] at h + exact h.symm + +lemma eLpNorm_completion (ν : Measure X) (F : X → ℝ) (hF : Measurable F) (p : ℕ) + (hp : p ≠ 0) : eLpNorm F (p:ℝ≥0∞) ν.completion = eLpNorm F (p:ℝ≥0∞) ν := by + have hFc : @Measurable (NullMeasurableSpace X ν) ℝ _ _ F := + hF.mono (original_le_completion ν) le_rfl + erw [eLpNorm_eq_lintegral_rpow_enorm_toReal (by exact_mod_cast hp) (by finiteness) + hFc.aestronglyMeasurable, + eLpNorm_eq_lintegral_rpow_enorm_toReal (by exact_mod_cast hp) (by finiteness) + hF.aestronglyMeasurable, + lintegral_completion ν (by fun_prop)] + +lemma density_test_bound (ν : Measure X) (F : X → ℝ) (hF : Measurable F) + (hF0 : ∀ x, 0 ≤ F x) (p : ℕ) (hp : 2 ≤ p) (B : ℝ≥0∞) + (hnorm : eLpNorm F (p:ℝ≥0∞) ν ≤ B) (S : Set X) (hS : MeasurableSet S) + (hsupp : ∀ᵐ x ∂ν, x ∉ S → F x = 0) + (φ : X → ℝ≥0∞) (hφ : AEMeasurable φ ν) (hφ1 : ∀ x, φ x ≤ 1) : + (∫⁻ x, φ x ∂ν.withDensity (fun x => ENNReal.ofReal (F x))) ≤ + B * (∫⁻ x in S, φ x ∂ν)^(1-1/(p:ℝ)) := by + have hp' : 1 < (p:ℝ) := by exact_mod_cast (by omega : 1 < p) + have hpq := Real.HolderConjugate.conjExponent hp' + have hq : 1 / Real.conjExponent (p:ℝ) = 1-1/(p:ℝ) := by + simpa only [one_div] using (eq_sub_of_add_eq' hpq.inv_add_inv_eq_one) + let K := S.indicator φ + have hK : AEMeasurable K ν := hφ.indicator hS + have hK1 : ∀ x, K x ≤ 1 := by + intro x + exact (Set.indicator_le (g := fun _ => 1) (fun _ _ => hφ1 _)) x + rw [lintegral_withDensity_eq_lintegral_mul₀ (hF.ennreal_ofReal.aemeasurable) hφ] + have he : (fun x => ENNReal.ofReal (F x) * φ x) =ᵐ[ν] + (fun x => ENNReal.ofReal (F x) * K x) := by + filter_upwards [hsupp] with x hx + by_cases hxS : x ∈ S + · simp [K, Set.indicator_of_mem hxS] + · simp [K, Set.indicator_of_notMem hxS, hx hxS] + simp only [Pi.mul_apply] + rw [lintegral_congr_ae he] + have hholder := ENNReal.lintegral_mul_le_Lp_mul_Lq ν hpq hF.ennreal_ofReal.aemeasurable hK + have hnormeq : (∫⁻ x, ENNReal.ofReal (F x) ^ (p:ℝ) ∂ν) ^ (1/(p:ℝ)) = + eLpNorm F (p:ℝ≥0∞) ν := by + rw [eLpNorm_eq_lintegral_rpow_enorm_toReal (by exact_mod_cast (by omega : p ≠ 0)) + (by finiteness) hF.aestronglyMeasurable] + simp only [ENNReal.toReal_natCast, Real.enorm_eq_ofReal (hF0 _)] + rw [hnormeq, hq] at hholder + refine hholder.trans (mul_le_mul' hnorm ?_) + apply ENNReal.rpow_le_rpow _ (by rw [← hq]; exact hpq.symm.one_div_nonneg) + calc + (∫⁻ x, K x ^ Real.conjExponent (p:ℝ) ∂ν) ≤ ∫⁻ x, K x ∂ν := + lintegral_mono (fun x => ENNReal.rpow_le_self_of_le_one (hK1 x) hpq.symm.lt.le) + _ = _ := lintegral_indicator hS _ + +lemma density_set_bound (ν : Measure X) (F : X → ℝ) (hF : Measurable F) + (hF0 : ∀ x, 0 ≤ F x) (p : ℕ) (hp : 2 ≤ p) (B : ℝ≥0∞) + (hnorm : eLpNorm F (p:ℝ≥0∞) ν ≤ B) (E : Set X) (hE : MeasurableSet E) : + ν.withDensity (fun x => ENNReal.ofReal (F x)) E ≤ B * (ν E)^(1-1/(p:ℝ)) := by + have h := density_test_bound ν F hF hF0 p hp B hnorm Set.univ MeasurableSet.univ + (by simp) (E.indicator 1) (measurable_one.indicator hE).aemeasurable + (fun x => (Set.indicator_le (g := fun _ => (1:ℝ≥0∞)) (fun _ _ => le_rfl)) x) + simpa only [lintegral_indicator hE, Measure.restrict_apply_univ, + setLIntegral_const, Pi.one_apply, one_mul, Measure.restrict_univ] using h + +lemma withDensity_completion_apply (ν : Measure X) (F : X → ℝ) (hF : Measurable F) + (E : Set X) (hE : NullMeasurableSet E ν) : + ν.completion.withDensity (fun x => ENNReal.ofReal (F x)) E = + ν.withDensity (fun x => ENNReal.ofReal (F x)) E := by + erw [withDensity_apply _ hE, withDensity_apply₀ _ hE, + ← lintegral_indicator hE, ← lintegral_indicator₀ hE, + lintegral_completion ν (hF.ennreal_ofReal.aemeasurable.indicator₀ hE)] +end TestTransfer + +def MeasurableTestStatement : Prop := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + ∀ d m p : ℕ, + letI : MeasurableSpace (Space d) := WithLp.measurableSpace exponent (Fin d → ℝ) + 1 ≤ d → 1 ≤ m → 2 ≤ p → + ∀ β H R : ℝ, (m : ℝ)+(p : ℝ)-two < β → 0 < H → 0 < R → + ∀ z : Space d, ∀ μ : Measure (Space d), IsFiniteMeasure μ → + @Measure.support (Space d) + (PiLp.topologicalSpace (p := exponent) (β := fun _ : Fin d => ℝ)) + (WithLp.measurableSpace exponent (Fin d → ℝ)) μ ⊆ + @Metric.closedBall (Space d) + (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ)) z R → + AmbientBallBound μ H β → + let ν := MatrixLabelReference d m + let η := ProjectionLaw μ m + let B := ENNReal.ofReal (ProjectionNormScale m p H β R) + let α := 1-1/(p:ℝ) + (∀ E, MeasurableSet E → ν E ≠ ∞ → η E ≤ B * (ν E)^α) ∧ + η ≪ ν ∧ + ∃ ηc : Measure (NullMeasurableSpace ((Fin m → Space d) × (Fin m → ℝ)) ν), + (∀ E, NullMeasurableSet E ν → ηc E = η E) ∧ + (∀ E, NullMeasurableSet E ν → ν.completion E ≠ ∞ → + ηc E ≤ B * (ν.completion E)^α) ∧ + (∀ φ : NullMeasurableSpace ((Fin m → Space d) × (Fin m → ℝ)) ν → ℝ≥0∞, + Measurable φ → (∀ x, φ x ≤ 1) → + (∫⁻ x, φ x ∂ηc) ≤ B * (∫⁻ x in ProjectedEllipsoid z R, φ x ∂ν.completion)^α) +theorem measurable_test : MeasurableTestStatement := by + intro d m p hd hm hp β H R hgap hH hR z μ hμ hs hb + let := hμ + obtain ⟨F, hF, hF0, hden, hsupp, hnorm⟩ := + exact_finite_density d m p hp hm β H R hgap hH hR z μ hs hb + dsimp only + let ν := MatrixLabelReference d m + let B := ENNReal.ofReal (ProjectionNormScale m p H β R) + refine ⟨?_, ?_, ?_⟩ + · intro E hE _ + rw [← hden] + exact density_set_bound ν F hF hF0 p hp B hnorm E hE + · rw [← hden] + exact withDensity_absolutelyContinuous _ _ + · let ηc := ν.completion.withDensity (fun x => ENNReal.ofReal (F x)) + refine ⟨ηc, ?_, ?_, ?_⟩ + · intro E hE + calc + ηc E = ν.withDensity (fun x => ENNReal.ofReal (F x)) E := + withDensity_completion_apply ν F hF E hE + _ = ProjectionLaw μ m E := congrArg (fun q => q E) hden + · intro E hE _ + have hFc : @Measurable (NullMeasurableSpace _ ν) ℝ _ _ F := + hF.mono (original_le_completion ν) le_rfl + have hnormc : eLpNorm F (p:ℝ≥0∞) ν.completion ≤ B := by + erw [eLpNorm_completion ν F hF p (by omega)] + exact hnorm + exact density_set_bound ν.completion F hFc hF0 p hp B hnormc E hE + · intro φ hφ hφ1 + have hFc : @Measurable (NullMeasurableSpace _ ν) ℝ _ _ F := + hF.mono (original_le_completion ν) le_rfl + have hnormc : eLpNorm F (p:ℝ≥0∞) ν.completion ≤ B := by + erw [eLpNorm_completion ν F hF p (by omega)] + exact hnorm + exact density_test_bound ν.completion F hFc hF0 p hp B hnormc + (ProjectedEllipsoid z R) (isClosed_projectedEllipsoid z R).measurableSet.nullMeasurableSet + hsupp φ hφ.aemeasurable hφ1 +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/PointwiseDensity.lean b/lean/OAI/Probability/MemoryPrecision/PointwiseDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..ddad79726aa9ae4f2f9ec6581e91293312264264 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/PointwiseDensity.lean @@ -0,0 +1,82 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.JointL1 + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def PointwiseDensity {d : ℕ} (μ : Measure (Space d)) (m : ℕ) + (x : (Fin m → Space d) × (Fin m → ℝ)) : ℝ := by + classical + exact if h : ∃ l : ℝ, Tendsto (fun i : ℕ => GaussianRegularization μ m (1/(i:ℝ)) x) + atTop (𝓝 l) then Classical.choose h else 0 + +lemma measurable_GaussianRegularization {d : ℕ} (μ : Measure (Space d)) [IsFiniteMeasure μ] + (m : ℕ) (δ : ℝ) : Measurable (GaussianRegularization μ m δ) := by + have he : GaussianRegularization μ m δ = fun x => + (projectionSmoothing μ (gaussianPDF 0 ⟨δ^2,sq_nonneg δ⟩) m x).toReal := + funext (GaussianRegularization_eq_toReal μ m δ) + rw [he] + exact (measurable_projectionSmoothing μ _ (measurable_gaussianPDF _ _) m).ennreal_toReal + +lemma PointwiseDensity_eq_of_tendsto {d m : ℕ} (μ : Measure (Space d)) + (x : (Fin m → Space d) × (Fin m → ℝ)) {l : ℝ} + (h : Tendsto (fun i : ℕ => GaussianRegularization μ m (1/(i:ℝ)) x) atTop (𝓝 l)) : + PointwiseDensity μ m x = l := by + classical + unfold PointwiseDensity + rw [dite_eq_left ⟨l,h⟩] + exact tendsto_nhds_unique (Classical.choose_spec (show ∃ l : ℝ, + Tendsto (fun i : ℕ => GaussianRegularization μ m (1/(i:ℝ)) x) atTop (𝓝 l) from ⟨l,h⟩)) h + +lemma measurable_PointwiseDensity {d : ℕ} (μ : Measure (Space d)) [IsFiniteMeasure μ] + (m : ℕ) : Measurable (PointwiseDensity μ m) := by + classical + let S := {x : (Fin m → Space d) × (Fin m → ℝ) | ∃ l : ℝ, + Tendsto (fun i : ℕ => GaussianRegularization μ m (1/(i:ℝ)) x) atTop (𝓝 l)} + have hS : MeasurableSet S := + measurableSet_exists_tendsto (fun i => measurable_GaussianRegularization μ m _) + apply measurable_of_tendsto_metrizable + (f := fun i => S.indicator (GaussianRegularization μ m (1/(i:ℝ)))) + (fun i => (measurable_GaussianRegularization μ m _).indicator hS) + apply tendsto_pi_nhds.mpr + intro x + by_cases hx : x ∈ S + · rcases hx with ⟨l,hl⟩ + rw [PointwiseDensity_eq_of_tendsto μ x hl] + simpa only [Set.indicator_of_mem (show x ∈ S from ⟨l,hl⟩)] using hl + · have he : PointwiseDensity μ m x = 0 := by + unfold PointwiseDensity + exact dite_eq_right hx + rw [he] + simpa only [Set.indicator_of_notMem hx] using + (tendsto_const_nhds : Tendsto (fun _ : ℕ => (0:ℝ)) atTop (𝓝 0)) + +lemma GaussianRegularization_nonneg {d : ℕ} (μ : Measure (Space d)) (m : ℕ) (δ : ℝ) + (x : (Fin m → Space d) × (Fin m → ℝ)) : 0 ≤ GaussianRegularization μ m δ x := + integral_nonneg (fun _ => Finset.prod_nonneg (fun _ _ => gaussianPDFReal_nonneg _ _ _)) + +lemma PointwiseDensity_nonneg {d : ℕ} (μ : Measure (Space d)) (m : ℕ) + (x : (Fin m → Space d) × (Fin m → ℝ)) : 0 ≤ PointwiseDensity μ m x := by + classical + unfold PointwiseDensity + split_ifs with h + · exact ge_of_tendsto (Classical.choose_spec h) + (Eventually.of_forall (fun i => GaussianRegularization_nonneg μ m _ x)) + · exact le_rfl +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/PointwiseMain.lean b/lean/OAI/Probability/MemoryPrecision/PointwiseMain.lean new file mode 100644 index 0000000000000000000000000000000000000000..05a3fed3e0d54224f93e909518fad233edb4b6a2 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/PointwiseMain.lean @@ -0,0 +1,127 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.DensityUniqueness + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def RadialMixtureRepresentation (m : ℕ) : Prop := + ∀ δ : ℝ, 0 < δ → + (∀ r : ℝ, 0 < r → 0 ≤ RadialMixture m δ r) ∧ + Measurable (RadialMixture m δ) ∧ + (∫ r in Set.Ioi 0, RadialMixture m δ r) = 1 ∧ + (∀ y : Space m, GaussianKernel m δ y = + ∫ r in Set.Ioi ‖y‖, RadialMixture m δ r / (UnitBallVolume m * r^m)) + +def FullRankDensityFormula {d : ℕ} + (μ : @Measure (Space d) + (WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ))) + (m : ℕ) : Prop := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + ∀ A : Fin m → Space d, + @LinearIndependent (Fin m) ℝ (Space d) A Real.commRing.toSemiring + (WithLp.instAddCommGroup exponent (Fin d → ℝ)).toAddCommMonoid + (WithLp.instModule (p := exponent) (K := ℝ) (V := Fin d → ℝ)) → + (volume : Measure (Fin m → ℝ)).withDensity + (fun y => ENNReal.ofReal (PointwiseDensity μ m (A,y))) = + @Measure.map (Space d) (Fin m → ℝ) + (WithLp.measurableSpace exponent (Fin d → ℝ)) inferInstance + (fun signal => fun index => @inner ℝ (Space d) + (@InnerProductSpace.toInner ℝ (Space d) _ + (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))) + signal (A index)) μ + +def PointwiseDensityProperties {d : ℕ} + (μ : @Measure (Space d) + (WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ))) + (m p : ℕ) (H β R : ℝ) : Prop := + letI : MeasurableSpace (Space d) := WithLp.measurableSpace + (@OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0)))) (Fin d → ℝ) + let reference : Measure ((Fin m → Space d) × (Fin m → ℝ)) := MatrixLabelReference d m + RadialMixtureRepresentation m ∧ + (∀ x, 0 ≤ PointwiseDensity μ m x) ∧ + Measurable (PointwiseDensity μ m) ∧ + FullRankDensityFormula μ m ∧ + reference.withDensity (fun x => ENNReal.ofReal (PointwiseDensity μ m x)) = + ProjectionLaw μ m ∧ + (∀ F : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ, + Measurable F → (∀ x, 0 ≤ F x) → + reference.withDensity (fun x => ENNReal.ofReal (F x)) = + ProjectionLaw μ m → PointwiseDensity μ m =ᵐ[reference] F) ∧ + (∫⁻ x, ENNReal.ofReal (PointwiseDensity μ m x)^p ∂reference) ≤ + ENNReal.ofReal (ProjectionNormScale m p H β R)^p + +def PointwiseDensityStatement : Prop := + let two : ℝ := @OfNat.ofNat ℝ 2 (@instOfNatAtLeastTwo ℝ 2 Real.commRing.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + ∀ d m p : ℕ, 2 ≤ d → 1 ≤ m → m < d → 2 ≤ p → + ∀ β H R : ℝ, (m : ℝ)+(p : ℝ)-two < β → 0 < H → 0 < R → + ∀ z : Space d, + ∀ μ : @Measure (Space d) (WithLp.measurableSpace exponent (Fin d → ℝ)), + IsFiniteMeasure μ → + @Measure.support (Space d) + (PiLp.topologicalSpace (p := exponent) (β := fun _ : Fin d => ℝ)) + (WithLp.measurableSpace exponent (Fin d → ℝ)) μ ⊆ + @Metric.closedBall (Space d) + (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin d => ℝ)) z R → + AmbientBallBound μ H β → + μ ≪ UniformSphere d → PointwiseDensityProperties μ m p H β R + +theorem pointwise_density : PointwiseDensityStatement := by + intro d m p hd hm hmd hp β H R hgap hH hR z μ hμ hs hb hac + let : IsFiniteMeasure μ := hμ + obtain ⟨F,hFm,hF0,hden,hFs,hFnorm⟩ := + exact_finite_density d m p hp hm β H R hgap hH hR z μ hs hb + have he := pointwiseDensity_ae_eq hm μ F hFm hF0 hden + refine ⟨?_, PointwiseDensity_nonneg μ m, measurable_PointwiseDensity μ m, + ?_, ?_, pointwiseDensity_ae_eq hm μ, ?_⟩ + · intro δ hδ + exact ⟨fun r hr => radialMixture_nonneg m δ hr, radialMixture_measurable m δ, + radialMixture_integral m hm hδ, radialMixture_tail m hm hδ⟩ + · intro A hA + exact pointwiseDensity_fullRank hd hm hmd μ hac A hA + · exact (withDensity_congr_ae (he.fun_comp ENNReal.ofReal)).trans hden + · have hp0 : (p:ℝ) ≠ 0 := by exact_mod_cast (by omega : p ≠ 0) + have hpE : (p:ℝ≥0∞) ≠ 0 := by exact_mod_cast (by omega : p ≠ 0) + have hpow := ENNReal.rpow_le_rpow hFnorm (show 0 ≤ (p:ℝ) by positivity) + rw [eLpNorm_eq_lintegral_rpow_enorm_toReal hpE (by finiteness) + hFm.aestronglyMeasurable] at hpow + simp only [ENNReal.toReal_natCast] at hpow + rw [← ENNReal.rpow_mul, one_div_mul_cancel hp0, ENNReal.rpow_one] at hpow + simp only [ENNReal.rpow_natCast] at hpow + have hi : (fun x => ENNReal.ofReal (PointwiseDensity μ m x)^p) =ᵐ[MatrixLabelReference d m] + (fun x => ‖F x‖ₑ^p) := by + filter_upwards [he] with x hx + rw [hx, Real.enorm_eq_ofReal (hF0 x)] + rw [lintegral_congr_ae hi] + exact hpow +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/Precision.lean b/lean/OAI/Probability/MemoryPrecision/Precision.lean new file mode 100644 index 0000000000000000000000000000000000000000..2c03279507fc37a5a1a48899333299e97e8358cc --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/Precision.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelAdmissibility +import OAI.Probability.MemoryPrecision.KernelStream +import OAI.Probability.MemoryPrecision.Reflection + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +open MemoryPrecision NoiselessRegression + +lemma precision_from_exact_bound {d M T : ℕ} {ε C A : ℝ} + (hd : 32 ≤ d) (hT : d ≤ 4*T) (hC : 0 < C) (hA : 0 < A) + (hM : (M:ℝ) ≤ A*(d:ℝ)^2) (hε : 0 < ε) + (hb : (2/3:ℝ) ≤ + (2*ε*Real.exp (C*(1+(M:ℝ)/(d:ℝ)^2)*(BlockCount T ((d-1)/8):ℝ)))^(((d:ℝ)-1)/2)) : + (1/(8+20*C*(1+A)))*(d:ℝ)*Real.log (1/ε) ≤ (T:ℝ) := by + have hd0 : (0:ℝ) < d := by exact_mod_cast (show 0 < d by omega) + have hdp : (d:ℝ) ≤ 4*T := by exact_mod_cast hT + let q := (d-1)/8 + let b := BlockCount T q + let a := ((d:ℝ)-1)/2 + let X := C*(1+(M:ℝ)/(d:ℝ)^2)*(b:ℝ) + have hq : 0 < q := by dsimp [q]; omega + have hdq : (d:ℝ) ≤ 16*(q:ℝ) := by + exact_mod_cast (show d ≤ 16*q by dsimp [q]; omega) + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hbd : (b:ℝ)*(d:ℝ) ≤ 20*T := by + have hceil : (b:ℝ) ≤ (T:ℝ)/q+1 := + (Nat.ceil_lt_add_one (by positivity : (0:ℝ) ≤ (T:ℝ)/q)).le + calc + _ ≤ ((T:ℝ)/q+1)*d := mul_le_mul_of_nonneg_right hceil hd0.le + _ = ((T:ℝ)/q)*d+d := by ring + _ ≤ ((T:ℝ)/q)*(16*q)+d := by gcongr + _ = 16*T+d := by field_simp + _ ≤ _ := by linarith + have ha : 1 ≤ a := by + dsimp [a] + have : (32:ℝ) ≤ d := by exact_mod_cast hd + linarith + have ha0 : 0 < a := by linarith + have hlog := Real.log_le_log (by norm_num : (0:ℝ) < 2/3) hb + change Real.log (2/3:ℝ) ≤ Real.log ((2*ε*Real.exp X)^a) at hlog + rw [Real.log_rpow (by positivity), Real.log_mul (by positivity) (by positivity), + Real.log_exp, Real.log_mul (by norm_num) hε.ne'] at hlog + have hl2 : Real.log 2 ≤ (1:ℝ) := by + convert Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ) < 2) using 1 + norm_num + have hl23 : -(1:ℝ) ≤ Real.log (2/3:ℝ) := by + have h := Real.one_sub_inv_le_log_of_pos (by norm_num : (0:ℝ) < 2/3) + norm_num at h + linarith + have hle : Real.log (1/ε) ≤ 2+X := by + have hmul := mul_le_mul_of_nonneg_left hl2 ha0.le + have he : Real.log (1/ε) = -Real.log ε := by simp + rw [he] + nlinarith + have hmem : (M:ℝ)/(d:ℝ)^2 ≤ A := (div_le_iff₀ (sq_pos_of_pos hd0)).2 hM + have hX : X*(d:ℝ) ≤ 20*C*(1+A)*T := by + calc + _ = C*(1+(M:ℝ)/(d:ℝ)^2)*((b:ℝ)*d) := by dsimp [X]; ring + _ ≤ C*(1+A)*((b:ℝ)*d) := by gcongr + _ ≤ C*(1+A)*(20*T) := mul_le_mul_of_nonneg_left hbd (by positivity) + _ = _ := by ring + have hfinal : (d:ℝ)*Real.log (1/ε) ≤ (8+20*C*(1+A))*T := by + have hh := mul_le_mul_of_nonneg_left hle hd0.le + nlinarith + have hp : 0 < 8+20*C*(1+A) := by positivity + calc + _ = ((d:ℝ)*Real.log (1/ε))/(8+20*C*(1+A)) := by ring + _ ≤ _ := (div_le_iff₀ hp).2 (by nlinarith) + +namespace Policy +lemma source_uniform_of_pointwise {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Ω → Policy d M T) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hd : 0 < d) (hL : Admissible L ρ (UniformSphere d)) (ε : ℝ) + (hs : ∀ s, (2/3:ℝ≥0∞) ≤ FixedSuccess L ρ ε s) : + (2/3:ℝ≥0∞) ≤ Success L ρ (UniformSphere d) ε := by + let : NeZero d := ⟨hd.ne'⟩ + have hm := hL.experiment (angleTest ε) (measurable_angleTest ε) (angleTest_le_one ε) + unfold Success + rw [lintegral_prod _ hm] + calc + _ = ∫⁻ _s : MemoryPrecision.Kernel.Sphere d, (2/3:ℝ≥0∞) ∂UniformSphere d := by simp + _ ≤ _ := lintegral_mono hs + +lemma source_precision {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Ω → Policy d M T) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hd : 32 ≤ d) (hL : Admissible L ρ (UniformSphere d)) {ε A : ℝ} + (hA : 0 < A) (hM : (M:ℝ) ≤ A*(d:ℝ)^2) (hε : 0 < ε) (hε1 : ε ≤ 1/10) + (hs : (2/3:ℝ≥0∞) ≤ Success L ρ (UniformSphere d) ε) : + (1/(8+20*StreamConstant*(1+A)))*(d:ℝ)*Real.log (1/ε) ≤ (T:ℝ) := by + have hT : d ≤ 4*T := by + by_contra hn + have hb := hs.trans (source_linear_success_bound L ρ (by omega) (by omega) hε1 hL) + have hb' : ENNReal.ofReal (2/3:ℝ) ≤ ENNReal.ofReal (21/32:ℝ) := by + simpa [ENNReal.ofReal_div_of_pos] using hb + have hh := (ENNReal.ofReal_le_ofReal_iff (by norm_num : (0:ℝ) ≤ 21/32)).mp hb' + norm_num at hh + have hb := hs.trans (source_stream_explicit d M T hd ε hε hε1 Ω ρ inferInstance L hL) + have hb' : (2/3:ℝ) ≤ + (2*ε*Real.exp (StreamConstant*(1+(M:ℝ)/(d:ℝ)^2)*(BlockCount T ((d-1)/8):ℝ)))^(((d:ℝ)-1)/2) := by + apply (ENNReal.ofReal_le_ofReal_iff (by positivity)).mp + simpa [ENNReal.ofReal_div_of_pos] using hb.trans (min_le_right _ _) + exact precision_from_exact_bound hd hT streamConstant_pos hA hM hε hb' +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/PriorMeasurability.lean b/lean/OAI/Probability/MemoryPrecision/PriorMeasurability.lean new file mode 100644 index 0000000000000000000000000000000000000000..c4e78639aab24d666b3ef8d1b440eec846523c4f --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/PriorMeasurability.lean @@ -0,0 +1,112 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.ProjectionMoments.BorelRules +import OAI.Probability.MemoryPrecision.AmbientGram +import OAI.Probability.MemoryPrecision.KernelModel + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma aemeasurable_countable_select {X J Y : Type*} [MeasurableSpace X] + [MeasurableSpace J] [MeasurableSingletonClass J] [Countable J] [MeasurableSpace Y] + {μ : Measure X} {h : J → X → Y} (hh : ∀ j, AEMeasurable (h j) μ) + {φ : X → J} (hφ : AEMeasurable φ μ) : AEMeasurable (fun x => h (φ x) x) μ := by + have hmk : Measurable (fun x => (hh (hφ.mk φ x)).mk (h (hφ.mk φ x)) x) := + (measurable_from_prod_countable_right + (f := fun z : J × X => (hh z.1).mk (h z.1) z.2) + (fun j => (hh j).measurable_mk)).comp (hφ.measurable_mk.prodMk measurable_id) + apply hmk.aemeasurable.congr + have hall : ∀ᵐ x ∂μ, ∀ j, h j x = (hh j).mk (h j) x := + ae_all_iff.mpr (fun j => (hh j).ae_eq_mk) + filter_upwards [hφ.ae_eq_mk, hall] with x hx hx' + rw [← hx, ← hx'] + +lemma prior_observation_with_seed {X : Type v} [MeasurableSpace X] + {d T : ℕ} (ν : Measure X) [SFinite ν] {Ω : Type u} [MeasurableSpace Ω] + (ρ : Measure Ω) [SFinite ρ] (ι : X → UnitSphere d) (i : Fin T) + (ho : Measure.QuasiMeasurePreserving + (fun z : X × Samples d T => (z.2 i,⟪(ι z.1).val,z.2 i⟫)) + (ν.prod (sampleLaw d T)) (observationReference d)) : + Measure.QuasiMeasurePreserving + (fun z : X × (Ω × Samples d T) => (z.2.1,(z.2.2 i,⟪(ι z.1).val,z.2.2 i⟫))) + (ν.prod (ρ.prod (sampleLaw d T))) (ρ.prod (observationReference d)) := by + let : IsProbabilityMeasure (sampleLaw d T) := by unfold sampleLaw; infer_instance + let : SigmaFinite (observationReference d) := by unfold observationReference; infer_instance + have h1 := (MeasurePreserving.id ν).prod + (Measure.measurePreserving_swap (μ := ρ) (ν := sampleLaw d T)) + have h2 := (measurePreserving_prodAssoc ν (sampleLaw d T) ρ).symm + (MeasurableEquiv.prodAssoc : (X × Samples d T) × Ω ≃ᵐ X × (Samples d T × Ω)) + have h3 := (Measure.measurePreserving_swap (μ := ν.prod (sampleLaw d T)) (ν := ρ)).comp (h2.comp h1) + have h4 := MeasureTheory.QuasiMeasurePreserving.prodMap (MeasurePreserving.id ρ).quasiMeasurePreserving ho + convert h4.comp h3.quasiMeasurePreserving using 1 + rfl + +lemma prior_estimate_aemeasurable {X : Type v} [MeasurableSpace X] + {d M T : ℕ} (ν : Measure X) [SFinite ν] {Ω : Type u} [MeasurableSpace Ω] + (ρ : Measure Ω) [SFinite ρ] (ι : X → UnitSphere d) + (L : Learner d M T Ω) (hL : L.Admissible ρ) + (ho : ∀ i : Fin T, Measure.QuasiMeasurePreserving + (fun z : X × Samples d T => (z.2 i,⟪(ι z.1).val,z.2 i⟫)) + (ν.prod (sampleLaw d T)) (observationReference d)) : + AEMeasurable (fun z : X × (Ω × Samples d T) => L.estimate (ι z.1) z.2.1 z.2.2) + (ν.prod (ρ.prod (sampleLaw d T))) := by + let μ := ν.prod (ρ.prod (sampleLaw d T)) + let : IsProbabilityMeasure (sampleLaw d T) := by unfold sampleLaw; infer_instance + have hω : Measure.QuasiMeasurePreserving (fun z : X × (Ω × Samples d T) => z.2.1) μ ρ := + Measure.quasiMeasurePreserving_fst.comp Measure.quasiMeasurePreserving_snd + have ht (t : ℕ) (a : State M) (i : Fin T) : + AEMeasurable (fun z : X × (Ω × Samples d T) => + L.transition t z.2.1 a (z.2.2 i,⟪z.2.2 i,(ι z.1).val⟫)) μ := by + have h := (hL.transition t a).comp_quasiMeasurePreserving + (prior_observation_with_seed ν ρ ι i (ho i)) + simpa only [Function.comp_def, μ, real_inner_comm] using h + have hr (n : ℕ) : AEMeasurable + (fun z : X × (Ω × Samples d T) => L.run (ι z.1) z.2.1 z.2.2 n) μ := by + induction n with + | zero => + exact (measurable_of_countable (fun a : Bool × State M => + if a.1 then Sum.inr (0,a.2) else Sum.inl a.2)).comp_aemeasurable + (hL.initialChoice.comp_quasiMeasurePreserving hω) + | succ n ih => + let g : Learner.RunStatus M → (X × (Ω × Samples d T)) → Learner.RunStatus M := fun j z => + match j with + | .inr done => .inr done + | .inl a => if hn : n < T then + let b := L.transition (n+1) z.2.1 a (z.2.2 ⟨n,hn⟩,⟪z.2.2 ⟨n,hn⟩,(ι z.1).val⟫) + if b.1 then .inr (n+1,b.2) else .inl b.2 + else .inl a + apply aemeasurable_countable_select (h := g) ?_ ih + intro j + cases j with + | inr done => exact aemeasurable_const + | inl a => + by_cases hn : n < T + · simpa only [g, dite_eq_left hn, Function.comp_def] using + (measurable_of_countable (fun b : Bool × State M => + if b.1 then Sum.inr (n+1,b.2) else Sum.inl b.2)).comp_aemeasurable (ht (n+1) a ⟨n,hn⟩) + · simpa only [g, dite_eq_right hn] using (aemeasurable_const (b := Sum.inl a)) + have hterm : AEMeasurable + (fun z : X × (Ω × Samples d T) => L.terminal (ι z.1) z.2.1 z.2.2) μ := by + convert + (measurable_of_countable (fun j : Learner.RunStatus M => + (match j with | .inl a => (T,a) | .inr p => p : ℕ × State M))).comp_aemeasurable (hr T) using 1 + rfl + exact aemeasurable_countable_select + (fun j : ℕ × State M => (hL.output j.1 j.2).comp_quasiMeasurePreserving hω) hterm +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/RadialMixture.lean b/lean/OAI/Probability/MemoryPrecision/RadialMixture.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d5f27f658e6770f9ef7c29f8af1a58b899b0187 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/RadialMixture.lean @@ -0,0 +1,258 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeContinuation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def UnitBallVolume (m : ℕ) : ℝ := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let euclideanGroup := PiLp.normedAddCommGroup exponent (fun _ : Fin m => ℝ) + letI : MeasurableSpace (Space m) := WithLp.measurableSpace exponent (Fin m → ℝ) + let euclideanVolume := @volume (Space m) (@measureSpaceOfInnerProductSpace (Space m) + euclideanGroup (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin m => ℝ)) + (space_finiteDimensional m) inferInstance inferInstance) + (euclideanVolume (@Metric.ball (Space m) + (PiLp.instPseudoMetricSpace (p := exponent) (β := fun _ : Fin m => ℝ)) + (WithLp.toLp exponent (fun _ : Fin m => (0 : ℝ))) 1)).toReal + +def CoordinateUnit (m : ℕ) : Space m := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + WithLp.toLp exponent (fun j : Fin m => if (j:ℕ) = 0 then (1:ℝ) else 0) + +lemma gaussianVariance_nonneg (δ : ℝ) : 0 ≤ δ^2 := sq_nonneg δ + +def GaussianKernel (m : ℕ) (δ : ℝ) (y : Space m) : ℝ := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + ∏ index, gaussianPDFReal 0 ⟨δ^2, gaussianVariance_nonneg δ⟩ + (@WithLp.ofLp exponent (Fin m → ℝ) y index) + +def RadialMixture (m : ℕ) (δ r : ℝ) : ℝ := + UnitBallVolume m * r^m * (r / δ^2) * GaussianKernel m δ (r • CoordinateUnit m) + +def GaussianAmplitude (m : ℕ) (δ : ℝ) : ℝ := + (1 / Real.sqrt (2 * Real.pi * δ^2)) ^ m + +lemma coordinateUnit_norm (m : ℕ) (hm : 1 ≤ m) : ‖CoordinateUnit m‖ = 1 := by + have he : ‖CoordinateUnit m‖^2 = 1 := by + rw [EuclideanSpace.real_norm_sq_eq] + change (∑ j : Fin m, (if (j:ℕ) = 0 then (1:ℝ) else 0)^2) = 1 + let j : Fin m := ⟨0, by omega⟩ + rw [Finset.sum_eq_single j] + · simp [j] + · intro b _ hb + have hb0 : (b:ℕ) ≠ 0 := by intro h; apply hb; exact Fin.ext h + simp [hb0] + · simp + nlinarith [norm_nonneg (CoordinateUnit m)] + +lemma gaussianKernel_radial (m : ℕ) (δ : ℝ) (y : Space m) : + GaussianKernel m δ y = GaussianAmplitude m δ * + Real.exp (-‖y‖^2 / (2*δ^2)) := by + change (∏ j, (Real.sqrt (2*Real.pi*δ^2))⁻¹ * + Real.exp (-(y j - 0)^2 / (2*δ^2))) = _ + simp only [sub_zero, Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ] + rw [← Real.exp_sum] + unfold GaussianAmplitude + simp only [one_div, Fintype.card_fin] + congr 1 + congr 1 + rw [EuclideanSpace.real_norm_sq_eq, ← Finset.sum_div, Finset.sum_neg_distrib] + +lemma gaussianKernel_nonneg (m : ℕ) (δ : ℝ) (y : Space m) : + 0 ≤ GaussianKernel m δ y := + Finset.prod_nonneg (fun _ _ => gaussianPDFReal_nonneg _ _ _) + +lemma gaussianKernel_continuous (m : ℕ) (δ : ℝ) : Continuous (GaussianKernel m δ) := by + have he : GaussianKernel m δ = fun y => GaussianAmplitude m δ * + Real.exp (-‖y‖^2 / (2*δ^2)) := funext (gaussianKernel_radial m δ) + rw [he] + fun_prop + +lemma unitBallVolume_pos (m : ℕ) : 0 < UnitBallVolume m := by + exact ENNReal.toReal_pos (Metric.measure_ball_pos volume 0 zero_lt_one).ne' + measure_ball_lt_top.ne + +lemma volume_ball_eq (m : ℕ) (hm : 1 ≤ m) (x : Space m) {r : ℝ} (hr : 0 < r) : + (volume : Measure (Space m)) (Metric.ball x r) = + ENNReal.ofReal (UnitBallVolume m * r^m) := by + have : NeZero m := ⟨by omega⟩ + rw [Measure.addHaar_ball volume x hr.le] + simp only [finrank_euclideanSpace, Fintype.card_fin] + rw [ENNReal.ofReal_mul (unitBallVolume_pos m).le, mul_comm, + UnitBallVolume, ENNReal.ofReal_toReal measure_ball_lt_top.ne] + rfl + +lemma gaussianKernel_radial_line (m : ℕ) (hm : 1 ≤ m) (δ r : ℝ) : + GaussianKernel m δ (r • CoordinateUnit m) = + GaussianAmplitude m δ * Real.exp (-r^2/(2*δ^2)) := by + rw [gaussianKernel_radial, norm_smul, coordinateUnit_norm m hm, mul_one, + Real.norm_eq_abs, sq_abs] + +lemma gaussianRadial_deriv (m : ℕ) (hm : 1 ≤ m) {δ : ℝ} (hδ : 0 < δ) (r : ℝ) : + HasDerivAt (fun r : ℝ => -GaussianKernel m δ (r • CoordinateUnit m)) + ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m)) r := by + simp_rw [gaussianKernel_radial_line m hm] + have ht := ((((hasDerivAt_id r).pow 2).neg.div_const (2*δ^2)).exp.const_mul + (GaussianAmplitude m δ)).neg + convert! ht using 1 + simp [id] + field_simp + +lemma gaussianRadial_tendsto (m : ℕ) (hm : 1 ≤ m) {δ : ℝ} (hδ : 0 < δ) : + Tendsto (fun r : ℝ => -GaussianKernel m δ (r • CoordinateUnit m)) atTop (𝓝 0) := by + simp_rw [gaussianKernel_radial_line m hm] + have he : Tendsto (fun r : ℝ => -r^2/(2*δ^2)) atTop atBot := by + have hsq : Tendsto (fun r : ℝ => r^2) atTop atTop := tendsto_pow_atTop (by norm_num) + exact Filter.Tendsto.atBot_div_const (by positivity) (tendsto_neg_atTop_atBot.comp hsq) + have ht := (Real.tendsto_exp_atBot.comp he).const_mul (GaussianAmplitude m δ) + simpa using ht.neg + +lemma gaussianRadial_tail (m : ℕ) (hm : 1 ≤ m) {δ ρ : ℝ} + (hδ : 0 < δ) (hρ : 0 ≤ ρ) : + (∫ r in Set.Ioi ρ, (r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m)) = + GaussianKernel m δ (ρ • CoordinateUnit m) := by + have h := integral_Ioi_of_hasDerivAt_of_nonneg' + (fun r (_ : r ∈ Set.Ici ρ) => gaussianRadial_deriv m hm hδ r) + (fun _ hr => mul_nonneg (div_nonneg (le_trans hρ hr.le) (sq_nonneg δ)) + (gaussianKernel_nonneg m δ _)) (gaussianRadial_tendsto m hm hδ) + simpa using h + +lemma gaussianKernel_integral (m : ℕ) {δ : ℝ} (hδ : 0 < δ) : + (∫ y : Space m, GaussianKernel m δ y) = 1 := by + rw [← (PiLp.volume_preserving_toLp (Fin m)).integral_comp + (show MeasurableEmbedding (WithLp.toLp 2 : (Fin m → ℝ) → Space m) from + (MeasurableEquiv.toLp 2 (Fin m → ℝ)).measurableEmbedding)] + change (∫ y : Fin m → ℝ, ∏ j, gaussianPDFReal 0 ⟨δ^2,sq_nonneg δ⟩ (y j)) = 1 + rw [integral_fintype_prod_volume_eq_pow, integral_gaussianPDFReal_eq_one 0 + (show (⟨δ^2,sq_nonneg δ⟩ : ℝ≥0) ≠ 0 from by + intro h; have := congrArg (fun x : ℝ≥0 => (x:ℝ)) h; change δ^2 = 0 at this; nlinarith)] + simp + +lemma gaussianKernel_lintegral (m : ℕ) {δ : ℝ} (hδ : 0 < δ) : + (∫⁻ y : Space m, ENNReal.ofReal (GaussianKernel m δ y)) = 1 := by + rw [← ofReal_integral_eq_lintegral_ofReal + (integrable_of_integral_eq_one (gaussianKernel_integral m hδ)) + (Eventually.of_forall (gaussianKernel_nonneg m δ)), gaussianKernel_integral m hδ] + simp + +lemma gaussianRadial_integrable (m : ℕ) (hm : 1 ≤ m) {δ ρ : ℝ} + (hδ : 0 < δ) (hρ : 0 ≤ ρ) : + IntegrableOn (fun r : ℝ => (r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m)) (Ioi ρ) := + integrableOn_Ioi_deriv_of_nonneg' + (fun r (_ : r ∈ Set.Ici ρ) => gaussianRadial_deriv m hm hδ r) + (fun _ hr => mul_nonneg (div_nonneg (le_trans hρ hr.le) (sq_nonneg δ)) + (gaussianKernel_nonneg m δ _)) (gaussianRadial_tendsto m hm hδ) + +lemma gaussianRadial_ltail (m : ℕ) (hm : 1 ≤ m) {δ ρ : ℝ} + (hδ : 0 < δ) (hρ : 0 ≤ ρ) : + (∫⁻ r in Ioi ρ, ENNReal.ofReal ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m))) = + ENNReal.ofReal (GaussianKernel m δ (ρ • CoordinateUnit m)) := by + rw [← ofReal_integral_eq_lintegral_ofReal (gaussianRadial_integrable m hm hδ hρ) + ((ae_restrict_mem measurableSet_Ioi).mono (fun r hr => + mul_nonneg (div_nonneg (le_trans hρ hr.le) (sq_nonneg δ)) (gaussianKernel_nonneg m δ _))), + gaussianRadial_tail m hm hδ hρ] + +lemma gaussianKernel_ball_mixture (m : ℕ) (hm : 1 ≤ m) {δ : ℝ} (hδ : 0 < δ) + (y : Space m) : + ENNReal.ofReal (GaussianKernel m δ y) = + ∫⁻ r in Ioi 0, (Metric.ball (0 : Space m) r).indicator + (fun _ => ENNReal.ofReal ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m))) y := by + have he (r : ℝ) : (Metric.ball (0 : Space m) r).indicator + (fun _ => ENNReal.ofReal ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m))) y = + (Ioi ‖y‖).indicator + (fun r => ENNReal.ofReal ((r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m))) r := by + have hb : y ∈ Metric.ball (0 : Space m) r ↔ ‖y‖ < r := by simp + by_cases h : ‖y‖ < r + · rw [Set.indicator_of_mem (hb.mpr h), Set.indicator_of_mem (show r ∈ Ioi ‖y‖ from h)] + · rw [Set.indicator_of_notMem (mt hb.mp h), Set.indicator_of_notMem (show r ∉ Ioi ‖y‖ from h)] + simp_rw [he] + rw [lintegral_indicator measurableSet_Ioi, Measure.restrict_restrict measurableSet_Ioi, + inter_eq_left.mpr (Ioi_subset_Ioi (norm_nonneg y)), gaussianRadial_ltail m hm hδ (norm_nonneg y), + gaussianKernel_radial_line m hm, gaussianKernel_radial] + +lemma radialMixture_nonneg (m : ℕ) (δ : ℝ) {r : ℝ} (hr : 0 < r) : + 0 ≤ RadialMixture m δ r := by + unfold RadialMixture + exact mul_nonneg (mul_nonneg (mul_nonneg (unitBallVolume_pos m).le (pow_nonneg hr.le _)) + (div_nonneg hr.le (sq_nonneg δ))) (gaussianKernel_nonneg m δ _) + +lemma radialMixture_measurable (m : ℕ) (δ : ℝ) : Measurable (RadialMixture m δ) := by + unfold RadialMixture + exact (continuous_const.mul (continuous_id.pow _ ) |>.mul + (continuous_id.div_const _) |>.mul + ((gaussianKernel_continuous m δ).comp (continuous_id.smul continuous_const))).measurable + +lemma radialMixture_lintegral (m : ℕ) (hm : 1 ≤ m) {δ : ℝ} (hδ : 0 < δ) : + (∫⁻ r in Ioi 0, ENNReal.ofReal (RadialMixture m δ r)) = 1 := by + have hmeas : Measurable (fun z : Space m × ℝ => + (Metric.ball (0 : Space m) z.2).indicator + (fun _ => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) z.1) := by + have he : (fun z : Space m × ℝ => (Metric.ball (0 : Space m) z.2).indicator + (fun _ => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) z.1) = + {z : Space m × ℝ | ‖z.1‖ < z.2}.indicator + (fun z => ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m))) := by + ext z + by_cases hz : ‖z.1‖ < z.2 + · rw [Set.indicator_of_mem (show z.1 ∈ Metric.ball (0 : Space m) z.2 by simpa using hz), + Set.indicator_of_mem (show z ∈ {z : Space m × ℝ | ‖z.1‖ < z.2} from hz)] + · rw [Set.indicator_of_notMem (show z.1 ∉ Metric.ball (0 : Space m) z.2 by simpa using hz), + Set.indicator_of_notMem (show z ∉ {z : Space m × ℝ | ‖z.1‖ < z.2} from hz)] + rw [he] + have hk : Measurable (GaussianKernel m δ) := (gaussianKernel_continuous m δ).measurable + exact (by fun_prop : Measurable (fun z : Space m × ℝ => + ENNReal.ofReal ((z.2/δ^2)*GaussianKernel m δ (z.2 • CoordinateUnit m)))).indicator + (measurableSet_lt (by fun_prop) (by fun_prop)) + have he := gaussianKernel_lintegral m hδ + simp_rw [gaussianKernel_ball_mixture m hm hδ] at he + rw [lintegral_lintegral_swap hmeas.aemeasurable] at he + convert he using 1 + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr + rw [lintegral_indicator Metric.isOpen_ball.measurableSet, setLIntegral_const, + volume_ball_eq m hm 0 hr] + unfold RadialMixture + rw [← ENNReal.ofReal_mul (mul_nonneg (div_nonneg hr.le (sq_nonneg δ)) + (gaussianKernel_nonneg m δ _))] + congr 1 + ring + +lemma radialMixture_integral (m : ℕ) (hm : 1 ≤ m) {δ : ℝ} (hδ : 0 < δ) : + (∫ r in Ioi 0, RadialMixture m δ r) = 1 := by + rw [integral_eq_lintegral_of_nonneg_ae + ((ae_restrict_mem measurableSet_Ioi).mono (fun r hr => radialMixture_nonneg m δ hr)) + (radialMixture_measurable m δ).aestronglyMeasurable, radialMixture_lintegral m hm hδ] + simp + +lemma radialMixture_tail (m : ℕ) (hm : 1 ≤ m) {δ : ℝ} (hδ : 0 < δ) (y : Space m) : + GaussianKernel m δ y = + ∫ r in Ioi ‖y‖, RadialMixture m δ r / (UnitBallVolume m * r^m) := by + rw [integral_congr_ae (show (fun r => RadialMixture m δ r / (UnitBallVolume m * r^m)) =ᵐ[ + volume.restrict (Ioi ‖y‖)] (fun r => (r/δ^2)*GaussianKernel m δ (r • CoordinateUnit m)) from by + filter_upwards [ae_restrict_mem measurableSet_Ioi] with r hr + have hr0 : 0 < r := lt_of_le_of_lt (norm_nonneg y) hr + unfold RadialMixture + field_simp [(unitBallVolume_pos m).ne', hr0.ne']), gaussianRadial_tail m hm hδ (norm_nonneg y), + gaussianKernel_radial_line m hm, gaussianKernel_radial] +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/RealContinuation.lean b/lean/OAI/Probability/MemoryPrecision/RealContinuation.lean new file mode 100644 index 0000000000000000000000000000000000000000..ef23778b10e94367be65095a809b224d7ac4c095 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/RealContinuation.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CoefficientStep + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def BlockCount (T p : ℕ) : ℕ := ⌈(T:ℝ)/(p:ℝ)⌉₊ +lemma blockCount_mul_ge (T : ℕ) {p : ℕ} (hp : 0 < p) : T ≤ BlockCount T p * p := by + have hp' : (0:ℝ) < p := by exact_mod_cast hp + have h := (div_le_iff₀ hp').mp (Nat.le_ceil ((T:ℝ)/(p:ℝ))) + exact_mod_cast h +lemma blockCount_mono {T S p : ℕ} (h : T ≤ S) : BlockCount T p ≤ BlockCount S p := + Nat.ceil_mono (div_le_div_of_nonneg_right (by exact_mod_cast h) (by positivity)) +@[simp] lemma blockCount_zero (p : ℕ) : BlockCount 0 p = 0 := by simp [BlockCount] +lemma blockCount_pos {T p : ℕ} (hT : 0 < T) (hp : 0 < p) : 0 < BlockCount T p := by + apply Nat.ceil_pos.mpr + exact div_pos (by exact_mod_cast hT) (by exact_mod_cast hp) + +def StepConstant : ℝ := Classical.choose coefficient_step +lemma stepConstant_one : 1 ≤ StepConstant := (Classical.choose_spec coefficient_step).1 +lemma stepConstant_pos : 0 < StepConstant := lt_of_lt_of_le zero_lt_one stepConstant_one + +def RealStep (d N : ℕ) : ℝ := StepConstant^d * (N:ℝ)^(1/((d/8:ℕ):ℝ)) +lemma realStep_one (d : ℕ) {N : ℕ} (hN : 1 ≤ N) : 1 ≤ RealStep d N := by + apply one_le_mul_of_one_le_of_one_le + · exact one_le_pow₀ stepConstant_one + · exact Real.one_le_rpow (by exact_mod_cast hN) (by positivity) +lemma realStep_pos (d : ℕ) {N : ℕ} (hN : 1 ≤ N) : 0 < RealStep d N := + lt_of_lt_of_le zero_lt_one (realStep_one d hN) + +lemma sphere_deterministic_step {d m N : ℕ} (hd : 16 ≤ d) (hm : 1 ≤ m) + (hmp : m ≤ d/8) (hN : 1 ≤ N) {α H : ℝ} + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) (hH : 0 < H) + (h : Fin N → Space d → ℝ≥0∞) (hh : ∀ w, Measurable (h w)) + (hh1 : ∀ w s, h w s ≤ 1) + (hb : ∀ w, SphereBallBound (fun s => h w s.val) H α) + (φ : ((Fin m → Space d) × (Fin m → ℝ)) → Fin N) (hφ : Measurable φ) : + SphereBallBound (fun s => blockValue h φ s.val) (RealStep d N * H) α := by + classical + let g (w : Fin N) (x : (Fin m → Space d) × (Fin m → ℝ)) : ℝ≥0∞ := + if φ x = w then 1 else 0 + have hg (w) : Measurable (g w) := by + exact Measurable.ite (measurableSet_eq_fun hφ measurable_const) measurable_const measurable_const + have hg1 (x) : ∑ w, g w x ≤ 1 := by simp [g] + have hb' := (Classical.choose_spec coefficient_step).2 d m N hd hm hmp hN α H + hαlo hαhi hH (fun w s => h w s.val) (fun w => (hh w).comp measurable_subtype_coe) + (fun w s => hh1 w s.val) hb g hg hg1 + convert hb' using 1 + · funext s + unfold blockValue SphereBlock + congr 1 + funext A + simp [g] + · rfl + +lemma SphereBallBound.mono {d : ℕ} {h : Sphere d → ℝ≥0∞} {H K α : ℝ} + (hh : SphereBallBound h H α) (hHK : H ≤ K) : SphereBallBound h K α := by + intro z r hr + exact (hh z r hr).trans (ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_right hHK (by positivity))) + +lemma real_continuation_mass {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + {δ : ℕ → Fin N → (Space d × ℝ) → Fin N} + {w : ℕ → Fin N → Space d → ℝ≥0∞} + (hδ : ∀ n j, Measurable (δ n j)) (hw : ∀ n j, Measurable (w n j)) + (hw1 : ∀ n j s, w n j s ≤ 1) {H α : ℝ} (hH : 0 < H) + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) + (hlocal : ∀ n j, SphereBallBound (fun s => w n j s.val) H α) + (b k : ℕ) (hk : k ≤ b*(d/8)) (n : ℕ) (j : Fin N) : + SphereBallBound (fun s => continuation δ w n k j s.val) + (H * RealStep d N ^ b) α := by + have hp : 0 < d/8 := by omega + have hK := realStep_one d hN + have hK0 := realStep_pos d hN + induction b generalizing k n j with + | zero => + have : k = 0 := by omega + subst k + simpa [continuation] using hlocal n j + | succ b ih => + by_cases hk0 : k = 0 + · subst k + apply (hlocal n j).mono + simpa [continuation] using le_mul_of_one_le_right hH.le (one_le_pow₀ hK) + · let m := min k (d/8) + have hm : 1 ≤ m := by dsimp [m]; omega + have hmp : m ≤ d/8 := min_le_right _ _ + have hmk : m ≤ k := min_le_left _ _ + have hk' : k-m ≤ b*(d/8) := by + dsimp [m] + rw [Nat.succ_mul] at hk + omega + have hb := sphere_deterministic_step hd hm hmp hN hαlo hαhi + (mul_pos hH (pow_pos hK0 b)) + (fun a => continuation δ w (n+m) (k-m) a) + (fun a => measurable_continuation hδ hw _ _ a) + (fun a s => continuation_le_one hw1 _ _ a s) + (fun a => ih (k-m) hk' (n+m) a) (streamRoute δ n m j) + (measurable_streamRoute hδ n m j) + have he : (fun s : Sphere d => continuation δ w n k j s.val) = + (fun s : Sphere d => blockValue (fun a => continuation δ w (n+m) (k-m) a) + (streamRoute δ n m j) s.val) := by + funext s + simpa [Nat.add_sub_of_le hmk] using continuation_unroll hδ n m (k-m) j s.val + rw [he] + convert hb using 1 + rw [pow_succ]; ring + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/RealStream.lean b/lean/OAI/Probability/MemoryPrecision/RealStream.lean new file mode 100644 index 0000000000000000000000000000000000000000..5b55611b773e503782d6123cd8a6f13fa23da714 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/RealStream.lean @@ -0,0 +1,176 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelSphere + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def uniformChordSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) (ε : ℝ) : ℝ≥0∞ := + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) + {z | dist (L.estimate z.1 z.2.1 z.2.2).val z.1.val ≤ ε} +end MemoryPrecision +namespace MemoryPrecision +open NoiselessRegression +lemma real_route_cap_bound {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + {δ : ℕ → Fin N → (Space d × ℝ) → Fin N} (hδ : ∀ n j, Measurable (δ n j)) + (y : Fin N → Space d) {ε α : ℝ} (hε : 0 < ε) + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) (k : ℕ) (j : Fin N) : + ((SpherePrior d).prod (Measure.pi (fun _ : Fin k => stdGaussian (Space d)))) + {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} ≤ + ENNReal.ofReal ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d N ^ BlockCount k (d/8)) := by + let : NeZero d := ⟨by omega⟩ + let : NeZero N := ⟨by omega⟩ + let : IsProbabilityMeasure (SpherePrior d) := + (show IsProbabilityMeasure (sphereLaw (E := Space d)) from inferInstance) + let w : ℕ → Fin N → Space d → ℝ≥0∞ := fun _ j => capWeight (y j) ε + have he (s : Space d) : continuation δ w 0 k j s = + ∫⁻ A : Fin k → Space d, capWeight (y (streamRoute δ 0 k j (A,fun i => ⟪s,A i⟫))) ε s + ∂Measure.pi (fun _ => stdGaussian (Space d)) := by + simpa [w, blockValue, continuation] using continuation_unroll (w := w) hδ 0 k 0 j s + let S : Set (Sphere d × (Fin k → Space d)) := + {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} + have hS : MeasurableSet S := by + apply measurableSet_le _ measurable_const + exact measurable_subtype_coe.comp measurable_fst |>.dist + ((measurable_of_finite y).comp ((measurable_streamRoute hδ 0 k j).comp (by fun_prop))) + change ((SpherePrior d).prod _) S ≤ _ + rw [← one_mul (((SpherePrior d).prod _) S), ← lintegral_indicator_const hS 1, + lintegral_prod _ (measurable_const.indicator hS).aemeasurable] + have hf : ∀ s : Sphere d, + (∫⁻ A, S.indicator (fun _ => (1 : ℝ≥0∞)) (s,A) ∂Measure.pi (fun _ => stdGaussian (Space d))) = + continuation δ w 0 k j s.val := by + intro s + rw [he] + apply lintegral_congr + intro A + classical + change (if dist s.val (y (streamRoute δ 0 k j (A,fun i => ⟪s.val,A i⟫))) ≤ ε then 1 else 0) = _ + unfold capWeight + rw [Set.indicator_apply] + rfl + simp_rw [hf] + exact real_continuation_cap_integral hd hN hδ (fun _ => y) hε hαlo hαhi 0 k j + +lemma real_prefix_route_cap_bound {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + {δ : ℕ → Fin N → (Space d × ℝ) → Fin N} (hδ : ∀ n j, Measurable (δ n j)) + (y : Fin N → Space d) {ε α : ℝ} (hε : 0 < ε) + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) {k T : ℕ} (hk : k ≤ T) (j : Fin N) : + ((SpherePrior d).prod (Measure.pi (fun _ : Fin T => stdGaussian (Space d)))) + {z | dist z.1.val (y (streamRoute δ 0 k j + ((fun i => z.2 (Fin.castLE hk i)),fun i => ⟪z.1.val,z.2 (Fin.castLE hk i)⟫))) ≤ ε} ≤ + ENNReal.ofReal ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d N ^ BlockCount T (d/8)) := by + let : NeZero d := ⟨by omega⟩ + let : NeZero N := ⟨by omega⟩ + let : IsProbabilityMeasure (SpherePrior d) := + (show IsProbabilityMeasure (sphereLaw (E := Space d)) from inferInstance) + have hp := (MeasurePreserving.id (SpherePrior d)).prod + (measurePreserving_pi_prefix (stdGaussian (Space d)) hk) + have hs : MeasurableSet + {z : Sphere d × (Fin k → Space d) | + dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} := by + apply measurableSet_le _ measurable_const + exact (measurable_subtype_coe.comp measurable_fst).dist + ((measurable_of_finite y).comp ((measurable_streamRoute hδ 0 k j).comp (by fun_prop))) + apply (le_of_eq (hp.measure_preimage hs.nullMeasurableSet)).trans + apply (real_route_cap_bound hd hN hδ y hε hαlo hαhi k j).trans + exact ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left + (pow_le_pow_right₀ (realStep_one d hN) (blockCount_mono hk)) (by positivity)) + +open NoiselessRegression.Learner + +lemma frozen_chord_real_bound {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (ω : Ω) (hd : 16 ≤ d) + (htrans : ∀ t j, AEMeasurable (fun obs => (L.transition t ω j obs).2) (observationReference d)) + {ε : ℝ} (hε : 0 < ε) {α : ℝ} (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) : + ((uniformSphere d).prod (sampleLaw d T)) + {z | dist z.1.val (L.estimate z.1 ω z.2).val ≤ ε} ≤ + (T+1 : ℝ≥0∞) * ENNReal.ofReal ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d (2^M) ^ BlockCount T (d/8)) := by + classical + let : NeZero d := ⟨by omega⟩ + let δ : ℕ → State M → (Vector d × ℝ) → State M := fun t j => (htrans t j).mk _ + have hδ (t : ℕ) (j : State M) : Measurable (δ t j) := (htrans t j).measurable_mk + let μ := (uniformSphere d).prod (sampleLaw d T) + have hgood : ∀ᵐ z ∂μ, ∀ t j (i : Fin T), + (L.transition t ω j (z.2 i,⟪z.1.val,z.2 i⟫)).2 = δ t j (z.2 i,⟪z.1.val,z.2 i⟫) := by + simp only [ae_all_iff] + intro t j i + exact (sphere_sample_observation_quasi (by simpa using (show 3 ≤ d by omega)) i).ae (htrans t j).ae_eq_mk + let S : Fin (T+1) → Set (UnitSphere d × Samples d T) := fun t => + {z | dist z.1.val (L.output t ω (streamRoute δ 0 t (L.initialChoice ω).2 + ((fun i => z.2 (Fin.castLE (by omega) i)),fun i => ⟪z.1.val,z.2 (Fin.castLE (by omega) i)⟫))).val ≤ ε} + have hmono : {z : UnitSphere d × Samples d T | dist z.1.val (L.estimate z.1 ω z.2).val ≤ ε} + ≤ᵐ[μ] ⋃ t, S t := by + filter_upwards [hgood] with z hz + intro hs + rcases L.terminal_forced_witness z.1 ω z.2 with ⟨t,ht,he⟩ + have hf : L.forcedRun z.1 ω z.2 t = streamRoute δ 0 t (L.initialChoice ω).2 + ((fun i => z.2 (Fin.castLE ht i)),fun i => ⟪z.1.val,z.2 (Fin.castLE ht i)⟫) := by + rw [L.forcedRun_eq_route z.1 ω z.2 ht] + exact streamRoute_congr _ _ 0 t _ _ _ (fun n j i => hz n j (Fin.castLE ht i)) + refine Set.mem_iUnion.mpr ⟨⟨t,by omega⟩, ?_⟩ + change dist z.1.val (L.output t ω _) ≤ ε + change dist z.1.val (L.estimate z.1 ω z.2).val ≤ ε at hs + simpa only [estimate, he, hf] using hs + let B : ℝ≥0∞ := ENNReal.ofReal ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d (2^M) ^ BlockCount T (d/8)) + have hb (t : Fin (T+1)) : μ (S t) ≤ B := by + simpa only [B, μ, S, uniformSphere, SpherePrior, MemoryPrecision.Kernel.UniformSphere, + sampleLaw] using + real_prefix_route_cap_bound (N := 2^M) hd (one_le_pow₀ (by norm_num)) hδ (fun j => (L.output t ω j).val) hε + hαlo hαhi (by omega : (t : ℕ) ≤ T) (L.initialChoice ω).2 + calc + _ ≤ μ (⋃ t, S t) := measure_mono_ae hmono + _ ≤ ∑' t, μ (S t) := measure_iUnion_le S + _ ≤ ∑' _ : Fin (T+1), B := ENNReal.tsum_le_tsum hb + _ = _ := by simp [B, tsum_fintype, nsmul_eq_mul, mul_assoc] + +lemma chord_real_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 16 ≤ d) {ε : ℝ} (hε : 0 < ε) + {α : ℝ} (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) : + uniformChordSuccess L ρ ε ≤ + (T+1 : ℝ≥0∞) * ENNReal.ofReal ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d (2^M) ^ BlockCount T (d/8)) := by + let : NeZero d := ⟨by omega⟩ + let : SigmaFinite (observationReference d) := by unfold observationReference; infer_instance + have hω : ∀ᵐ ω ∂ρ, ∀ t j, + AEMeasurable (fun obs => (L.transition t ω j obs).2) (observationReference d) := by + simp only [ae_all_iff] + intro t j + filter_upwards [ae_fiber_aemeasurable (hL.transition t j).prod_swap] with ω hω + exact measurable_snd.comp_aemeasurable hω + have hp := ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := ρ))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) ρ) + let S := {z : UnitSphere d × (Ω × Samples d T) | + dist (L.estimate z.1 z.2.1 z.2.2).val z.1.val ≤ ε} + have hS : NullMeasurableSet S ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := + nullMeasurableSet_le + ((measurable_subtype_coe.comp_aemeasurable hL.uniform_experiment).dist + (measurable_subtype_coe.comp measurable_fst).aemeasurable) aemeasurable_const + have he := hp.measure_preimage hS + have hb := prod_null_set_bound (hS.preimage hp.quasiMeasurePreserving) + (c := (T+1 : ℝ≥0∞) * ENNReal.ofReal ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d (2^M) ^ BlockCount T (d/8))) + (by + filter_upwards [hω] with ω hω + change ((uniformSphere d).prod (sampleLaw d T)) + {z | dist (L.estimate z.1 ω z.2).val z.1.val ≤ ε} ≤ _ + simpa only [dist_comm] using frozen_chord_real_bound L ω hd hω hε hαlo hαhi) + simpa only [he, measure_univ, mul_one, S, uniformChordSuccess] using hb + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/Reflection.lean b/lean/OAI/Probability/MemoryPrecision/Reflection.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d4175a23796e5c82f1bbb18a3a606b7e4c7c077 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/Reflection.lean @@ -0,0 +1,189 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelCaps + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel +open NoiselessRegression +namespace Policy +variable {d M T : ℕ} (K : Policy d M T) + +lemma eval_pair_le_one {X : Type*} (w v : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞) + (s t : X) (hpair : ∀ n j, w n j s + v n j t ≤ 1) + (n k : ℕ) (j : MemoryPrecision.Kernel.State M) (obs : Observations d k) : + K.eval w n k j s obs + K.eval v n k j t obs ≤ 1 := by + induction k generalizing n j with + | zero => exact hpair n j + | succ k ih => + simp only [eval, ← Finset.sum_add_distrib, ← mul_add] + calc + _ ≤ ∑ a : Action M, K.transition (n+1) j (obs 0) a * 1 := by + apply Finset.sum_le_sum + intro a _ + apply mul_le_mul' le_rfl + split_ifs + · exact hpair _ _ + · exact ih _ _ _ + _ = 1 := by simpa only [mul_one] using K.transition_sum (n+1) j (obs 0) + +lemma pathValue_pair_le_one {X : Type*} (w v : ℕ → MemoryPrecision.Kernel.State M → X → ℝ≥0∞) + (s t : X) (hpair : ∀ n j, w n j s + v n j t ≤ 1) (obs : Observations d T) : + K.pathValue w s obs + K.pathValue v t obs ≤ 1 := by + simp only [pathValue, ← Finset.sum_add_distrib, ← mul_add] + calc + _ ≤ ∑ a : Action M, K.initial a * 1 := by + apply Finset.sum_le_sum + intro a _ + apply mul_le_mul' le_rfl + split_ifs + · exact hpair _ _ + · exact K.eval_pair_le_one w v s t hpair _ _ _ _ + _ = 1 := by simpa only [mul_one] using K.initial_sum + +lemma chord_pair_le_one {ε : ℝ} (hε : ε ≤ 1/10) + (s t v : MemoryPrecision.Kernel.Sphere d) (hst : 1/5 < dist s.val t.val) : + chordTest ε (s,v) + chordTest ε (t,v) ≤ 1 := by + classical + have hn : ¬(dist v.val s.val ≤ ε ∧ dist v.val t.val ≤ ε) := by + rintro ⟨hs,ht⟩ + have htri := dist_triangle s.val v.val t.val + rw [dist_comm s.val v.val] at htri + linarith + simp only [chordTest, Set.indicator_apply, Set.mem_ofPred_eq] + split_ifs <;> simp_all + +lemma output_chord_pair_le_one {ε : ℝ} (hε : ε ≤ 1/10) + (s t : MemoryPrecision.Kernel.Sphere d) (hst : 1/5 < dist s.val t.val) + (n : ℕ) (j : MemoryPrecision.Kernel.State M) : + K.outputTest (chordTest ε) n j s + K.outputTest (chordTest ε) n j t ≤ 1 := by + have hm : Measurable (fun v : MemoryPrecision.Kernel.Sphere d => chordTest ε (s,v)) := + (measurable_chordTest ε).comp (measurable_const.prodMk measurable_id) + simp only [outputTest] + rw [← lintegral_add_left hm] + exact (lintegral_mono (fun v => chord_pair_le_one hε s t v hst)).trans_eq (by simp) + +lemma path_reflection_pair {ε : ℝ} (hε : ε ≤ 1/10) + (A : Rows d T) (s : MemoryPrecision.Kernel.Sphere d) + (U : Submodule ℝ (MemoryPrecision.Kernel.Vector d)) (hA : ∀ i, A i ∈ U) + (hst : 1/5 < dist s.val (U.reflection s.val)) : + K.pathValue (K.outputTest (chordTest ε)) s (records s A) + + K.pathValue (K.outputTest (chordTest ε)) (sphereIsometry U.reflection s) + (records (sphereIsometry U.reflection s) A) ≤ 1 := by + have he : records (sphereIsometry U.reflection s) A = records s A := by + funext i + change (A i, ⟪U.reflection s.val, A i⟫) = (A i, ⟪s.val, A i⟫) + apply Prod.ext + · rfl + · have h := U.reflection.inner_map_map s.val (A i) + rw [(Submodule.reflection_eq_self_iff (A i)).2 (hA i)] at h + exact h + rw [he] + have hpair : ∀ n j, K.outputTest (chordTest ε) n j s + + K.outputTest (chordTest ε) n j (sphereIsometry U.reflection s) ≤ 1 := + fun n j => K.output_chord_pair_le_one hε s (sphereIsometry U.reflection s) hst n j + exact K.pathValue_pair_le_one (K.outputTest (chordTest ε)) + (K.outputTest (chordTest ε)) s (sphereIsometry U.reflection s) hpair (records s A) +end Policy + +lemma sphere_reflection_function_bound {d : ℕ} [NeZero d] + (U : Submodule ℝ (MemoryPrecision.Kernel.Vector d)) (hU : 4*Module.finrank ℝ U ≤ d) + {f : MemoryPrecision.Kernel.Sphere d → ℝ≥0∞} (hf : AEMeasurable f (UniformSphere d)) + (hf1 : ∀ s, f s ≤ 1) + (hpair : ∀ s, 1/5 < dist s.val (U.reflection s.val) → + f s + f (sphereIsometry U.reflection s) ≤ 1) : + (∫⁻ s, f s ∂UniformSphere d) ≤ ENNReal.ofReal (21/32:ℝ) := by + let R := sphereIsometry U.reflection + let B : Set (MemoryPrecision.Kernel.Sphere d) := {s | (4/5:ℝ) ≤ ‖U.orthogonalProjectionOnto s.val‖^2} + have hB : MeasurableSet B := by dsimp [B]; exact measurableSet_le measurable_const (by fun_prop) + have hp : MeasurePreserving R (UniformSphere d) (UniformSphere d) := sphereIsometry_preserving U.reflection + have he : (∫⁻ s, f (R s) ∂UniformSphere d) = ∫⁻ s, f s ∂UniformSphere d := by + calc + _ = ∫⁻ s, f s ∂(UniformSphere d).map R := + (lintegral_map' (by simpa only [hp.map_eq] using hf) hp.measurable.aemeasurable).symm + _ = _ := by rw [hp.map_eq] + have hb : UniformSphere d B ≤ ENNReal.ofReal (5/16:ℝ) := + sphere_projection_large U (by simpa using hU) + have hsum : ∀ s, f s + f (R s) ≤ 1 + B.indicator (fun _ => 1) s := by + intro s + classical + by_cases hs : s ∈ B + · simpa [hs] using add_le_add (hf1 s) (hf1 (R s)) + · have hst : 1/5 < dist s.val (U.reflection s.val) := by + by_contra hn + have hd : dist s.val (U.reflection s.val) ≤ 1/5 := le_of_not_gt hn + rw [reflection_dist] at hd + have hn := U.norm_sq_eq_add_norm_sq_starProjection s.val + rw [mem_sphere_zero_iff_norm.mp s.property] at hn + have he : ‖U.starProjection s.val‖ = ‖U.orthogonalProjectionOnto s.val‖ := rfl + rw [he] at hn + apply hs + change (4/5:ℝ) ≤ ‖U.orthogonalProjectionOnto s.val‖^2 + nlinarith [norm_nonneg (Uᗮ.starProjection s.val)] + simpa [hs] using hpair s hst + have hi : (∫⁻ s, f s ∂UniformSphere d) + (∫⁻ s, f s ∂UniformSphere d) ≤ + 1 + ENNReal.ofReal (5/16:ℝ) := by + calc + _ = (∫⁻ s, f s ∂UniformSphere d) + (∫⁻ s, f (R s) ∂UniformSphere d) := by rw [he] + _ = ∫⁻ s, f s + f (R s) ∂UniformSphere d := (lintegral_add_left' hf _).symm + _ ≤ ∫⁻ s, 1 + B.indicator (fun _ => (1:ℝ≥0∞)) s ∂UniformSphere d := lintegral_mono hsum + _ = 1 + UniformSphere d B := by rw [lintegral_add_left measurable_const]; simp [lintegral_indicator_const hB] + _ ≤ _ := add_le_add le_rfl hb + calc + _ = ENNReal.ofReal (1/2:ℝ) * ((∫⁻ s, f s ∂UniformSphere d) + + (∫⁻ s, f s ∂UniformSphere d)) := by + rw [← two_mul, ← mul_assoc] + have hc : ENNReal.ofReal (1/2:ℝ) * 2 = 1 := by + rw [← ENNReal.ofReal_ofNat, ← ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 1/2)] + norm_num + rw [hc, one_mul] + _ ≤ ENNReal.ofReal (1/2:ℝ) * (1 + ENNReal.ofReal (5/16:ℝ)) := mul_le_mul' le_rfl hi + _ = ENNReal.ofReal (21/32:ℝ) := by + rw [← ENNReal.ofReal_one, ← ENNReal.ofReal_add (by norm_num : (0:ℝ) ≤ 1) + (by norm_num : (0:ℝ) ≤ 5/16), + ← ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 1/2)] + norm_num + +namespace Policy +lemma source_linear_success_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Ω → Policy d M T) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hd : 0 < d) (hT : 4*T ≤ d) {ε : ℝ} (hε : ε ≤ 1/10) + (hL : Admissible L ρ (UniformSphere d)) : + Success L ρ (UniformSphere d) ε ≤ ENNReal.ofReal (21/32:ℝ) := by + let : NeZero d := ⟨hd.ne'⟩ + apply (success_le_chord L ρ (UniformSphere d) ε).trans + have hm := hL.experiment (chordTest ε) (measurable_chordTest ε) (chordTest_le_one ε) + unfold ChordSuccess + rw [lintegral_prod_symm _ hm] + apply le_trans (b := ∫⁻ _z : Ω × Rows d T, ENNReal.ofReal (21/32:ℝ) + ∂ρ.prod (RowLaw d T)) ?_ (by simp) + apply lintegral_mono_ae + filter_upwards [ae_fiber_aemeasurable hm] with z hz + let U : Submodule ℝ (MemoryPrecision.Kernel.Vector d) := Submodule.span ℝ (Set.range z.2) + have hdim : Module.finrank ℝ U ≤ T := by + have h := finrank_span_le_card (R := ℝ) (Set.range z.2) + apply h.trans + rw [Set.toFinset_range] + exact (Finset.card_image_le).trans_eq (by simp) + apply sphere_reflection_function_bound U ((Nat.mul_le_mul_left 4 hdim).trans hT) hz + · intro s + exact (L z.1).pathValue_le_one _ ((L z.1).outputTest_le_one (chordTest_le_one ε)) _ _ + · intro s hs + exact (L z.1).path_reflection_pair hε z.2 s U + (fun i => Submodule.subset_span (Set.mem_range_self i)) hs +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/SeedAverage.lean b/lean/OAI/Probability/MemoryPrecision/SeedAverage.lean new file mode 100644 index 0000000000000000000000000000000000000000..290b4621bdb66b1d6c11c634b209b5d4c13795b1 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/SeedAverage.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.KernelEvaluation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision.Kernel + +lemma seed_average_bound {X Y : Type*} {Ω : Type u} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace Ω] (π : Measure X) [SFinite π] (ν : Measure Y) [SFinite ν] + (ρ : Measure Ω) [IsProbabilityMeasure ρ] + {f : X × (Ω × Y) → ℝ≥0∞} + (hf : AEMeasurable f (π.prod (ρ.prod ν))) {B : ℝ≥0∞} + (hb : ∀ᵐ ω ∂ρ, (∫⁻ z : X × Y, f (z.1,(ω,z.2)) ∂π.prod ν) ≤ B) : + (∫⁻ z, f z ∂π.prod (ρ.prod ν)) ≤ B := by + have hp := ((MeasurePreserving.id π).prod + (Measure.measurePreserving_swap (μ := ν) (ν := ρ))).comp + (measurePreserving_prodAssoc π ν ρ) + let g : (X × Y) × Ω → ℝ≥0∞ := fun z => f (z.1.1,(z.2,z.1.2)) + have hg : AEMeasurable g ((π.prod ν).prod ρ) := + hf.comp_quasiMeasurePreserving hp.quasiMeasurePreserving + have he : (∫⁻ z, g z ∂(π.prod ν).prod ρ) = ∫⁻ z, f z ∂π.prod (ρ.prod ν) := by + rw [← hp.map_eq] + exact (lintegral_map' (by simpa only [hp.map_eq] using hf) hp.measurable.aemeasurable).symm + rw [← he, lintegral_prod_symm _ hg] + exact (lintegral_mono_ae hb).trans_eq (by simp) + +namespace Policy +variable {d M T : ℕ} +lemma success_le_one {Ω : Type u} [MeasurableSpace Ω] (L : Ω → Policy d M T) + (ρ : Measure Ω) [IsProbabilityMeasure ρ] (π : Measure (Sphere d)) [IsProbabilityMeasure π] + (ε : ℝ) : Success L ρ π ε ≤ 1 := by + have : IsProbabilityMeasure (RowLaw d T) := by unfold RowLaw; infer_instance + unfold Success experiment + calc + _ ≤ ∫⁻ _z : Sphere d × (Ω × Rows d T), (1 : ℝ≥0∞) ∂π.prod (ρ.prod (RowLaw d T)) := + lintegral_mono (fun z => (L z.2.1).pathValue_le_one _ + ((L z.2.1).outputTest_le_one (angleTest_le_one ε)) z.1 (records z.1 z.2.2)) + _ = 1 := by simp +lemma chordSuccess_le_one {Ω : Type u} [MeasurableSpace Ω] (L : Ω → Policy d M T) + (ρ : Measure Ω) [IsProbabilityMeasure ρ] (π : Measure (Sphere d)) [IsProbabilityMeasure π] + (ε : ℝ) : ChordSuccess L ρ π ε ≤ 1 := by + have : IsProbabilityMeasure (RowLaw d T) := by unfold RowLaw; infer_instance + unfold ChordSuccess experiment + calc + _ ≤ ∫⁻ _z : Sphere d × (Ω × Rows d T), (1 : ℝ≥0∞) ∂π.prod (ρ.prod (RowLaw d T)) := + lintegral_mono (fun z => (L z.2.1).pathValue_le_one _ + ((L z.2.1).outputTest_le_one (chordTest_le_one ε)) z.1 (records z.1 z.2.2)) + _ = 1 := by simp +end Policy +end MemoryPrecision.Kernel + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/SharpGaussian.lean b/lean/OAI/Probability/MemoryPrecision/SharpGaussian.lean new file mode 100644 index 0000000000000000000000000000000000000000..3519c50550300ec935ee4d478f979042aae5017b --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/SharpGaussian.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.AmbientGram + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression InnerProductSpace + +def gaussianPeak : ℝ≥0∞ := ENNReal.ofReal ((Real.sqrt (2 * Real.pi))⁻¹) + +lemma sharp_gaussianReal_le_volume : + gaussianReal 0 1 ≤ gaussianPeak • (volume : Measure ℝ) := by + rw [gaussianReal_of_var_ne_zero _ (by norm_num)] + calc + _ ≤ (volume : Measure ℝ).withDensity (fun _ => gaussianPeak) := by + apply withDensity_mono + filter_upwards [] with x + apply ENNReal.ofReal_le_ofReal + unfold gaussianPDFReal + simp only [NNReal.coe_one, mul_one, sub_zero] + exact mul_le_of_le_one_right (by positivity) + (Real.exp_le_one_iff.mpr (div_nonpos_of_nonpos_of_nonneg + (neg_nonpos.mpr (sq_nonneg x)) (by positivity))) + _ = _ := by rw [withDensity_const] + +lemma sharp_pi_gaussianReal_le_volume (n : ℕ) : + Measure.pi (fun _ : Fin n => gaussianReal 0 1) ≤ + gaussianPeak ^ n • (volume : Measure (Fin n → ℝ)) := by + have h := measure_pi_mono (fun _ : Fin n => sharp_gaussianReal_le_volume) + rw [measure_pi_smul _ _ (show gaussianPeak ≠ ∞ from ENNReal.ofReal_ne_top)] at h + simpa only [Fintype.card_fin, volume_pi] using h + +section Gaussian +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +local instance sharp_reference_sigmaFinite (m : ℕ) : + SigmaFinite (matrixLabelReference (E := E) m) := by + unfold matrixLabelReference + infer_instance + +lemma sharp_gaussian_pairings_le {n : ℕ} (v : Fin n → E) (hv : LinearIndependent ℝ v) : + (stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) ≤ + (gaussianPeak ^ n * ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹)) • + (volume : Measure (Fin n → ℝ)) := by + let u := gramSchmidtNormed ℝ v + let R : Matrix (Fin n) (Fin n) ℝ := + Matrix.diagonal (fun i => ‖gramSchmidt ℝ v i‖) * gsUpper n v + have hu : Orthonormal ℝ u := gramSchmidtNormed_orthonormal hv + have hn (i : Fin n) : ‖gramSchmidt ℝ v i‖ ≠ 0 := + norm_ne_zero_iff.mpr (gramSchmidt_ne_zero i hv) + have hexp (j : Fin n) : ∑ i, R i j • u i = v j := by + rw [← gsUpper_expansion n v j] + apply Finset.sum_congr rfl + intro i _ + simp only [R, u, Matrix.diagonal_mul, gramSchmidtNormed, smul_smul] + congr 1 + simp [hn i, mul_comm] + have hdet : R.transpose.det = ∏ i, ‖gramSchmidt ℝ v i‖ := by + dsimp only [R] + rw [Matrix.det_transpose, Matrix.det_mul, Matrix.det_diagonal, gsUpper_det, mul_one] + have hd : R.transpose.det ≠ 0 := by + rw [hdet] + exact Finset.prod_ne_zero_iff.mpr (fun i _ => hn i) + have hpos : 0 ≤ R.transpose.det := by rw [hdet]; positivity + have hf : Measurable (Matrix.toLin' R.transpose) := + (Matrix.toLin' R.transpose).continuous_of_finiteDimensional.measurable + have heq : (fun x : E => fun j => ⟪v j, x⟫) = + (Matrix.toLin' R.transpose) ∘ (fun x => fun i => ⟪u i, x⟫) := by + funext x j + rw [← hexp j] + simp [Matrix.toLin'_apply, Matrix.mulVec, dotProduct, sum_inner, + inner_smul_left] + rw [heq, ← Measure.map_map hf (by fun_prop), orthonormal_gaussian_map hu] + calc + _ ≤ (gaussianPeak ^ n • (volume : Measure (Fin n → ℝ))).map + (Matrix.toLin' R.transpose) := + Measure.map_mono (sharp_pi_gaussianReal_le_volume n) hf + _ = _ := by + rw [Measure.map_smul _ hf.aemeasurable, Real.map_matrix_volume_pi_eq_smul_volume_pi hd, + abs_of_nonneg (inv_nonneg.mpr hpos), hdet, smul_smul] + +lemma sharp_gaussian_rows_pairings_le {n : ℕ} (v : Fin n → E) + (hv : LinearIndependent ℝ v) (m : ℕ) : + (Measure.pi (fun _ : Fin m => stdGaussian E)).map + (fun A => fun j i => ⟪v i, A j⟫) ≤ + ((gaussianPeak ^ n * ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹)) ^ m) • + (volume : Measure (Fin m → Fin n → ℝ)) := by + rw [Measure.pi_map_pi (fun _ => (by fun_prop : Measurable + (fun x : E => fun i => ⟪v i, x⟫)).aemeasurable)] + have h := measure_pi_mono (fun _ : Fin m => sharp_gaussian_pairings_le v hv) + rw [measure_pi_smul _ _ (ENNReal.mul_ne_top (ENNReal.pow_ne_top + (show gaussianPeak ≠ ∞ from ENNReal.ofReal_ne_top)) ENNReal.ofReal_ne_top)] at h + simpa only [Fintype.card_fin, volume_pi] using h +lemma sharp_gaussian_rows_kernel_bound {n : ℕ} (v : Fin n → E) (hv : LinearIndependent ℝ v) + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ z, φ z = 1) + (m : ℕ) (y : Fin m → ℝ) : + ∫⁻ A : Fin m → E, (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫) + ∂Measure.pi (fun _ => stdGaussian E) ≤ + ((gaussianPeak ^ n * ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹)) ^ m) * ∏ j, φ (y j) := by + let H : (Fin m → Fin n → ℝ) → ℝ≥0∞ := + fun z => ∏ j, φ (y j) * ∏ i, φ (y j - z j i) + have hH : Measurable H := by dsimp [H]; fun_prop + have heq (A : Fin m → E) : + (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫) = + H (fun j i => ⟪v i, A j⟫) := by + dsimp [H] + rw [Finset.prod_mul_distrib, Finset.prod_comm] + simp_rw [heq] + rw [← lintegral_map hH (by fun_prop)] + calc + _ ≤ ∫⁻ z, H z ∂(((gaussianPeak ^ n * ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹)) ^ m) • + (volume : Measure (Fin m → Fin n → ℝ))) := + lintegral_mono' (sharp_gaussian_rows_pairings_le v hv m) (fun _ => le_rfl) + _ = _ := by + rw [lintegral_smul_measure] + change _ * (∫⁻ z : Fin m → Fin n → ℝ, ∏ j, φ (y j) * ∏ i, φ (y j - z j i)) = _ + rw [lintegral_product_differences φ hφ hφ1] + +lemma sharp_gaussian_replica_kernel_bound {n : ℕ} (p : E) (v : Fin n → E) + (hv : LinearIndependent ℝ (fun i => v i - p)) + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ z, φ z = 1) (m : ℕ) : + ∫⁻ A : Fin m → E, ∫⁻ y : Fin m → ℝ, + (∏ j, φ (y j - ⟪p, A j⟫)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫) + ∂volume ∂Measure.pi (fun _ => stdGaussian E) ≤ + ((gaussianPeak ^ n * ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ (fun i => v i - p) i‖)⁻¹)) ^ m) := by + have ht (A : Fin m → E) : + (∫⁻ y : Fin m → ℝ, (∏ j, φ (y j - ⟪p, A j⟫)) * + ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫)) = + ∫⁻ y : Fin m → ℝ, (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i - p, A j⟫) := by + have he (y : Fin m → ℝ) (i : Fin n) (j : Fin m) : + y j - ⟪p, A j⟫ - ⟪v i - p, A j⟫ = y j - ⟪v i, A j⟫ := by + rw [inner_sub_left] + ring + simpa only [Pi.sub_apply, he] using + lintegral_sub_right_eq_self + (fun y : Fin m → ℝ => (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i - p, A j⟫)) + (fun j => ⟪p, A j⟫) + simp_rw [ht] + rw [lintegral_lintegral_swap (by fun_prop)] + calc + _ ≤ ∫⁻ y : Fin m → ℝ, + ((gaussianPeak ^ n * ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ (fun i => v i - p) i‖)⁻¹)) ^ m) * + ∏ j, φ (y j) := lintegral_mono fun y => + sharp_gaussian_rows_kernel_bound (fun i => v i - p) hv φ hφ hφ1 m y + _ = _ := by + rw [lintegral_const_mul _ (by fun_prop), volume_pi, + lintegral_fin_prod volume m (fun _ => φ) (fun _ => hφ)] + simp [hφ1] + +lemma sharp_projectionSmoothing_moment {ν : Measure E} [IsFiniteMeasure ν] + {H β R : ℝ} {z : E} (hH : 0 < H) (hR : 0 < R) + (hsupport : ν.support ⊆ Metric.closedBall z R) + (hball : ∀ x : E, ∀ r : ℝ, 0 < r → + ν (Metric.closedBall x r) ≤ ENNReal.ofReal (H*r^β)) + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ x, φ x = 1) + {m : ℕ} (hm : 0 < m) (n : ℕ) (hgap : (n:ℝ)+(m:ℝ)-1 < β) : + (∫⁻ Ay : (Fin m → E) × (Fin m → ℝ), + (projectionSmoothing ν φ m Ay)^(n+1) ∂matrixLabelReference m) ≤ + gaussianPeak ^ (n*m) * ENNReal.ofReal + (H^(n+1) * R^(β*(n+1:ℕ)-(m:ℝ)*(n:ℝ)) * ∏ j : Fin n, J β m j) := by + simp_rw [projectionSmoothing_pow ν φ hφ m n] + rw [lintegral_lintegral_swap (by fun_prop)] + calc + _ ≤ ∫⁻ w : E × (Fin n → E), gaussianPeak ^ (n*m) * replicaWeight m w.1 w.2 + ∂ν.prod (Measure.pi (fun _ => ν)) := by + apply lintegral_mono_ae + filter_upwards [ae_joint_replica_independent hH hR hsupport hball hm n hgap] with w hw + rw [matrixLabelReference, lintegral_prod _ (by fun_prop)] + convert sharp_gaussian_replica_kernel_bound w.1 w.2 hw φ hφ hφ1 m using 1 + rw [mul_pow, ← pow_mul, replicaWeight_eq_det, sqrt_det_gram, + ENNReal.ofReal_pow (by positivity)] + _ = gaussianPeak ^ (n*m) * + (∫⁻ w : E × (Fin n → E), replicaWeight m w.1 w.2 + ∂ν.prod (Measure.pi (fun _ => ν))) := + lintegral_const_mul _ (measurable_joint_replicaWeight m n) + _ ≤ _ := mul_le_mul' le_rfl + (joint_replica_integral_exact hH hR hsupport hball hm n hgap) + +end Gaussian +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/SphereCaps.lean b/lean/OAI/Probability/MemoryPrecision/SphereCaps.lean new file mode 100644 index 0000000000000000000000000000000000000000..48dcba42d0128a3131f1694b6cc580c73800b975 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/SphereCaps.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.RealContinuation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma real_terminal_cap {d : ℕ} (hd : 1 ≤ d) (y z : Space d) + {ε r α : ℝ} (hε : 0 < ε) (hr : 0 < r) (hα : 0 ≤ α) (hαn : α ≤ (d:ℝ)-1) : + ((ambientSphereLaw (E := Space d)).restrict (Metric.closedBall y ε)) (Metric.closedBall z r) ≤ + ENNReal.ofReal ((3*4^d:ℝ) * ε^((d:ℝ)-1-α) * r^α) := by + let : NeZero d := ⟨by omega⟩ + have hn : ((d-1:ℕ):ℝ) = (d:ℝ)-1 := by rw [Nat.cast_sub hd, Nat.cast_one] + have hs : 0 ≤ (d:ℝ)-1-α := sub_nonneg.mpr hαn + have he (t : ℝ) (ht : 0 < t) : t^(d-1) = t^((d:ℝ)-1-α)*t^α := by + rw [← Real.rpow_add ht, sub_add_cancel, ← hn, Real.rpow_natCast] + rw [Measure.restrict_apply Metric.isClosed_closedBall.measurableSet] + by_cases h : r ≤ ε + · calc + _ ≤ ambientSphereLaw (E := Space d) (Metric.closedBall z r) := measure_mono Set.inter_subset_left + _ ≤ ENNReal.ofReal ((3*4^d:ℝ)*r^(d-1)) := by + simpa [ENNReal.ofReal_mul, finrank_euclideanSpace_fin] using + ambientSphereLaw_closedBall (E := Space d) z hr (d-1) (by simp) + _ ≤ _ := by + apply ENNReal.ofReal_le_ofReal + rw [he r hr, ← mul_assoc] + exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hr.le h hs) (by positivity)) (by positivity) + · calc + _ ≤ ambientSphereLaw (E := Space d) (Metric.closedBall y ε) := measure_mono Set.inter_subset_right + _ ≤ ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1)) := by + simpa [ENNReal.ofReal_mul, finrank_euclideanSpace_fin] using + ambientSphereLaw_closedBall (E := Space d) y hε (d-1) (by simp) + _ ≤ _ := by + apply ENNReal.ofReal_le_ofReal + rw [he ε hε, ← mul_assoc] + exact mul_le_mul_of_nonneg_left (Real.rpow_le_rpow hε.le (le_of_not_ge h) hα) (by positivity) + +lemma sphere_cap_real_mass {d : ℕ} (hd : 1 ≤ d) (y : Space d) {ε α : ℝ} + (hε : 0 < ε) (hα : 0 ≤ α) (hαn : α ≤ (d:ℝ)-1) : + SphereBallBound (fun s => capWeight y ε s.val) ((3*4^d:ℝ)*ε^((d:ℝ)-1-α)) α := by + intro z r hr + change (∫⁻ s in Subtype.val ⁻¹' Metric.closedBall z r, + capWeight y ε s.val ∂sphereLaw) ≤ _ + rw [← setLIntegral_map Metric.isClosed_closedBall.measurableSet (measurable_capWeight y ε) + measurable_subtype_coe] + change (∫⁻ s in Metric.closedBall z r, capWeight y ε s ∂ambientSphereLaw) ≤ _ + rw [← withDensity_apply _ Metric.isClosed_closedBall.measurableSet] + change ((ambientSphereLaw (E := Space d)).withDensity + ((Metric.closedBall y ε).indicator 1)) (Metric.closedBall z r) ≤ _ + rw [withDensity_indicator_one Metric.isClosed_closedBall.measurableSet] + exact real_terminal_cap hd y z hε hr hα hαn + +lemma sphere_mass_bound {d : ℕ} {h : Sphere d → ℝ≥0∞} {H α : ℝ} + (hh : SphereBallBound h H α) : (∫⁻ s, h s ∂SpherePrior d) ≤ ENNReal.ofReal H := by + have he : {s : Sphere d | dist s.val (0:Space d) ≤ 1} = Set.univ := by + ext s + simp [dist_zero_right] + simpa [SphereBallBound, he] using hh 0 1 zero_lt_one + +lemma real_continuation_cap_integral {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + {δ : ℕ → Fin N → (Space d × ℝ) → Fin N} (hδ : ∀ n j, Measurable (δ n j)) + (y : ℕ → Fin N → Space d) {ε α : ℝ} (hε : 0 < ε) + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) (n k : ℕ) (j : Fin N) : + (∫⁻ s, continuation δ (fun n j => capWeight (y n j) ε) n k j s.val ∂SpherePrior d) ≤ + ENNReal.ofReal ((3*4^d:ℝ)*ε^((d:ℝ)-1-α) * RealStep d N ^ BlockCount k (d/8)) := by + have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd + apply sphere_mass_bound + apply real_continuation_mass hd hN hδ (fun n j => measurable_capWeight _ _) + (fun n j s => capWeight_le_one _ _ _) (by positivity) hαlo hαhi + (fun n j => sphere_cap_real_mass (by omega) (y n j) hε (by linarith) (by linarith)) + simpa [mul_comm] using blockCount_mul_ge k (by omega : 0 < d/8) + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/SphericalProjection.lean b/lean/OAI/Probability/MemoryPrecision/SphericalProjection.lean new file mode 100644 index 0000000000000000000000000000000000000000..ad71d21de7fd3b61d5615f4f3a9efd694a05d765 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/SphericalProjection.lean @@ -0,0 +1,225 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeContinuation +import OAI.Probability.MemoryPrecision.JointL1 + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +section RadialCoordinates +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +def radialShrink (c : ℝ) (v : E) : E := + (Real.sqrt (‖v‖^2 + c^2))⁻¹ • v + +def radialExpand (c : ℝ) (u : E) : E := + (c / Real.sqrt (1 - ⟪u,u⟫)) • u + +lemma radialShrink_mem_ball {c : ℝ} (hc : 0 < c) (v : E) : + radialShrink c v ∈ Metric.ball 0 1 := by + have hp : 0 < ‖v‖^2 + c^2 := by positivity + have hs : 0 < Real.sqrt (‖v‖^2 + c^2) := Real.sqrt_pos.2 hp + have hsq := Real.sq_sqrt hp.le + rw [Metric.mem_ball, dist_zero_right, radialShrink, norm_smul, + Real.norm_eq_abs, abs_of_pos (inv_pos.mpr hs)] + have hlt : ‖v‖ < Real.sqrt (‖v‖^2 + c^2) := by nlinarith [sq_pos_of_pos hc] + simpa [div_eq_mul_inv, mul_comm] using (div_lt_one hs).mpr hlt + +lemma radialExpand_shrink {c : ℝ} (hc : 0 < c) (v : E) : + radialExpand c (radialShrink c v) = v := by + let t := Real.sqrt (‖v‖^2+c^2) + have ht : 0 < t := Real.sqrt_pos.2 (by positivity) + have ht2 : t^2 = ‖v‖^2+c^2 := Real.sq_sqrt (by positivity) + have he : 1 - ⟪radialShrink c v,radialShrink c v⟫ = (c/t)^2 := by + simp only [radialShrink, inner_smul_left, inner_smul_right, RCLike.conj_to_real, + real_inner_self_eq_norm_sq] + change 1 - t⁻¹ * (t⁻¹ * ‖v‖^2) = (c/t)^2 + field_simp + nlinarith [ht2] + rw [radialExpand, he, Real.sqrt_sq (le_of_lt (div_pos hc ht)), radialShrink, + smul_smul] + change (c / (c/t) * t⁻¹) • v = v + have he' : c / (c/t) * t⁻¹ = 1 := by field_simp + rw [he', one_smul] + +lemma radialExpand_differentiableOn (c : ℝ) : + DifferentiableOn ℝ (radialExpand (E := E) c) (Metric.ball 0 1) := by + intro u hu + have hu' : ‖u‖ < 1 := by simpa using hu + have hpos : 0 < 1 - ⟪u,u⟫ := by + rw [real_inner_self_eq_norm_sq] + nlinarith [norm_nonneg u] + apply DifferentiableAt.differentiableWithinAt + unfold radialExpand + apply DifferentiableAt.smul + · simp only [div_eq_mul_inv] + apply DifferentiableAt.const_mul + apply DifferentiableAt.inv + · apply DifferentiableAt.sqrt + · exact (differentiableAt_const 1).sub + (DifferentiableAt.inner ℝ differentiableAt_id differentiableAt_id) + · exact ne_of_gt hpos + · exact ne_of_gt (Real.sqrt_pos.2 hpos) + · exact differentiableAt_id + +variable [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma radialShrink_preimage_null {c : ℝ} (hc : 0 < c) {s : Set E} + (hs : volume s = 0) : volume (radialShrink c ⁻¹' s) = 0 := by + have hn : volume (s ∩ Metric.ball (0:E) 1) = 0 := + measure_mono_null Set.inter_subset_left hs + have hi := addHaar_image_eq_zero_of_differentiableOn_of_addHaar_eq_zero volume + ((radialExpand_differentiableOn (E:=E) c).mono Set.inter_subset_right) hn + apply measure_mono_null _ hi + intro v hv + refine ⟨radialShrink c v, ⟨hv, radialShrink_mem_ball hc v⟩, ?_⟩ + exact radialExpand_shrink hc v +end RadialCoordinates + +section Projection +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma orthogonal_normalized_preimage_null (K : Submodule ℝ E) [Nontrivial Kᗮ] + {s : Set K} (hs : MeasurableSet s) (hs0 : volume s = 0) : + volume {x : E | ‖x‖⁻¹ • K.orthogonalProjectionOnto x ∈ s} = 0 := by + let e : (Kᗮ × K) ≃ₗ[ℝ] E := + (LinearEquiv.prodComm ℝ Kᗮ K).trans (K.prodEquivOfIsCompl Kᗮ K.isCompl_orthogonal) + let t : Set (Kᗮ × K) := {x | radialShrink ‖x.1‖ x.2 ∈ s} + have ht : MeasurableSet t := by + apply hs.preimage + dsimp [radialShrink] + fun_prop + have ht0 : ((volume : Measure Kᗮ).prod (volume : Measure K)) t = 0 := by + rw [Measure.prod_apply ht] + rw [← lintegral_zero (μ := (volume : Measure Kᗮ))] + apply lintegral_congr_ae + have hk : ∀ᵐ k : Kᗮ ∂volume, k ≠ 0 := by + simpa only [Ne, ← Set.mem_singleton_iff] using + (measure_eq_zero_iff_ae_notMem.mp (measure_singleton (0:Kᗮ))) + filter_upwards [hk] with k hk + exact radialShrink_preimage_null (norm_pos_iff.mpr hk) hs0 + have hn : MeasurableSet {x : E | ‖x‖⁻¹ • K.orthogonalProjectionOnto x ∈ s} := by + apply hs.preimage + exact measurable_id.norm.inv.smul K.orthogonalProjectionOnto.continuous.measurable + have hnt : e ⁻¹' {x : E | ‖x‖⁻¹ • K.orthogonalProjectionOnto x ∈ s} = t := by + ext x + have hp : K.orthogonalProjectionOnto (e x) = x.2 := by + change K.orthogonalProjectionOnto ((x.2:E)+(x.1:E)) = x.2 + rw [map_add, Submodule.orthogonalProjectionOnto_mem_subspace_eq_self, + Submodule.orthogonalProjectionOnto_apply_of_mem_orthogonal x.1.property, add_zero] + have hnorm : ‖e x‖ = Real.sqrt (‖x.2‖^2 + ‖x.1‖^2) := by + have h := norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero (x.2:E) (x.1:E) + (Submodule.inner_right_of_mem_orthogonal x.2.property x.1.property) + have he : ‖e x‖^2 = ‖x.2‖^2 + ‖x.1‖^2 := by + change ‖(x.2:E)+(x.1:E)‖^2 = _ + simpa only [pow_two, Submodule.norm_coe] using h + rw [← he, Real.sqrt_sq (norm_nonneg _)] + simp only [Set.mem_preimage, Set.mem_ofPred_eq, hp, hnorm, t, radialShrink] + let : ((((volume : Measure Kᗮ).prod (volume : Measure K)).map e)).IsAddHaarMeasure := + Measure.MapLinearEquiv.isAddHaarMeasure _ e + have heac : (volume : Measure E) ≪ + (((volume : Measure Kᗮ).prod (volume : Measure K)).map e) := + Measure.absolutelyContinuous_isAddHaarMeasure _ _ + apply heac + rw [Measure.map_apply (f := e) e.toContinuousLinearEquiv.continuous.measurable hn, hnt, ht0] + +lemma sphere_projection_ac (K : Submodule ℝ E) [Nontrivial E] [Nontrivial Kᗮ] : + ((sphereLaw (E:=E)).map (fun x => K.orthogonalProjectionOnto x.val)) ≪ + (volume : Measure K) := by + apply Measure.AbsolutelyContinuous.mk + intro s hs hs0 + have hm : Measurable (fun x : Metric.sphere (0:E) 1 => K.orthogonalProjectionOnto x.val) := + K.orthogonalProjectionOnto.continuous.measurable.comp measurable_subtype_coe + rw [Measure.map_apply hm hs, sphereLaw_apply (hm hs)] + have hn := orthogonal_normalized_preimage_null K hs hs0 + have hcone : volume (Set.Ioo (0:ℝ) 1 • + (Subtype.val '' ((fun x : Metric.sphere (0:E) 1 => K.orthogonalProjectionOnto x.val) ⁻¹' s))) = 0 := by + apply measure_mono_null _ hn + rintro _ ⟨r, hr, _, ⟨x, hx, rfl⟩, rfl⟩ + change ‖r • x.val‖⁻¹ • K.orthogonalProjectionOnto (r • x.val) ∈ s + rw [norm_smul, Real.norm_eq_abs, abs_of_pos hr.1, + mem_sphere_zero_iff_norm.mp x.property, mul_one, map_smul, smul_smul, + inv_mul_cancel₀ hr.1.ne', one_smul] + exact hx + rw [unitBallLaw, Measure.smul_apply, smul_eq_mul, + Measure.restrict_apply' Metric.isClosed_closedBall.measurableSet] + rw [measure_mono_null Set.inter_subset_left hcone, mul_zero] + +lemma sphere_rows_ac [Nontrivial E] {m : ℕ} (A : Fin m → E) + (hA : LinearIndependent ℝ A) (hm : m < Module.finrank ℝ E) : + ((sphereLaw (E:=E)).map + (fun x : Metric.sphere (0:E) 1 => fun j => ⟪x.val,A j⟫)) ≪ + (volume : Measure (Fin m → ℝ)) := by + let K : Submodule ℝ E := Submodule.span ℝ (Set.range A) + have hd : Module.finrank ℝ K = m := by + simpa only [K, Fintype.card_fin] using finrank_span_eq_card hA + have hK : K ≠ ⊤ := by + intro he + rw [he, finrank_top] at hd + omega + have : Nontrivial Kᗮ := Submodule.nontrivial_iff_ne_bot.mpr + (fun h => hK (Submodule.orthogonal_eq_bot_iff.mp h)) + let L : K →ₗ[ℝ] (Fin m → ℝ) := + LinearMap.pi (fun j => (innerSL ℝ (A j)).toLinearMap.comp K.subtype) + have hLi : Function.Injective L := by + apply (injective_iff_map_eq_zero L).mpr + intro x hx + have hle : K ≤ (innerSL ℝ (x:E)).toLinearMap.ker := by + apply Submodule.span_le.mpr + rintro _ ⟨j,rfl⟩ + change ⟪(x:E),A j⟫ = 0 + have hj := congrFun hx j + change ⟪A j,(x:E)⟫ = 0 at hj + rwa [real_inner_comm] + have hz : ⟪(x:E),(x:E)⟫ = 0 := hle x.property + exact Subtype.ext (inner_self_eq_zero.mp hz) + have hdim : Module.finrank ℝ K = Module.finrank ℝ (Fin m → ℝ) := by + simpa using hd + let e : K ≃ₗ[ℝ] (Fin m → ℝ) := + LinearEquiv.ofBijective L ⟨hLi, + (LinearMap.injective_iff_surjective_of_finrank_eq_finrank hdim).mp hLi⟩ + have he : (fun x : Metric.sphere (0:E) 1 => fun j => ⟪x.val,A j⟫) = + e ∘ (fun x : Metric.sphere (0:E) 1 => K.orthogonalProjectionOnto x.val) := by + funext x j + change ⟪x.val,A j⟫ = ⟪A j,(K.orthogonalProjectionOnto x.val:E)⟫ + have hp := K.inner_orthogonalProjectionOnto_eq_of_mem_left + ⟨A j, Submodule.subset_span ⟨j,rfl⟩⟩ x.val + change ⟪A j,(K.orthogonalProjectionOnto x.val:E)⟫ = ⟪A j,x.val⟫ at hp + rw [hp, real_inner_comm] + rw [he, ← Measure.map_map (f := fun x : Metric.sphere (0:E) 1 => + K.orthogonalProjectionOnto x.val) (g := e) + e.toContinuousLinearEquiv.continuous.measurable (by fun_prop)] + apply ((sphere_projection_ac K).map + (show Measurable e from e.toContinuousLinearEquiv.continuous.measurable)).trans + let : ((volume : Measure K).map e).IsAddHaarMeasure := + Measure.MapLinearEquiv.isAddHaarMeasure _ e + exact Measure.absolutelyContinuous_isAddHaarMeasure _ _ +end Projection + +theorem spherical_projection_ac {d m : ℕ} (hd : 2 ≤ d) (hm : m < d) + (A : Fin m → Space d) (hA : LinearIndependent ℝ A) + (μ : Measure (Space d)) (hμ : μ ≪ UniformSphere d) : + μ.map (fun s => fun j => ⟪s,A j⟫) ≪ (volume : Measure (Fin m → ℝ)) := by + have : NeZero d := ⟨by omega⟩ + apply (hμ.map (by fun_prop)).trans + have h := sphere_rows_ac A hA (by simpa using hm) + simpa only [UniformSphere, Kernel.UniformSphere, sphereLaw, Measure.map_map (by fun_prop : + Measurable (fun s : Space d => fun j => ⟪s,A j⟫)) measurable_subtype_coe, + Function.comp_def] using h +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/StochasticContinuation.lean b/lean/OAI/Probability/MemoryPrecision/StochasticContinuation.lean new file mode 100644 index 0000000000000000000000000000000000000000..72f2293d437969705303a22f17b3bd5f78da742f --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/StochasticContinuation.lean @@ -0,0 +1,131 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.AmbientGram + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression +section Stochastic +variable {J X : Type*} [Fintype J] {d : ℕ} + +def stochRoute (δ : ℕ → J → (Space d × ℝ) → J → ℝ≥0∞) (n : ℕ) : + (k : ℕ) → J → ((Fin k → Space d) × (Fin k → ℝ)) → J → ℝ≥0∞ + | 0, j, _, w => by classical exact if j = w then 1 else 0 + | k+1, j, x, w => ∑ a, δ (n+1) j (x.1 0,x.2 0) a * + stochRoute δ (n+1) k a (Fin.tail x.1,Fin.tail x.2) w + +lemma measurable_stochRoute {δ : ℕ → J → (Space d × ℝ) → J → ℝ≥0∞} + (hδ : ∀ n j a, Measurable (fun obs => δ n j obs a)) (n k : ℕ) (j w : J) : + Measurable (fun x => stochRoute δ n k j x w) := by + induction k generalizing n j with + | zero => exact measurable_const + | succ k ih => + apply Finset.measurable_sum _ + intro a _ + exact ((hδ (n+1) j a).comp (by fun_prop)).mul ((ih (n+1) a).comp (by fun_prop)) + +lemma stochRoute_sum_le_one {δ : ℕ → J → (Space d × ℝ) → J → ℝ≥0∞} + (hδ : ∀ n j obs, ∑ a, δ n j obs a ≤ 1) (n k : ℕ) (j : J) + (x : (Fin k → Space d) × (Fin k → ℝ)) : ∑ w, stochRoute δ n k j x w ≤ 1 := by + classical + induction k generalizing n j with + | zero => simp [stochRoute] + | succ k ih => + simp only [stochRoute] + rw [Finset.sum_comm] + calc + _ = ∑ a, δ (n+1) j (x.1 0,x.2 0) a * + (∑ w, stochRoute δ (n+1) k a (Fin.tail x.1,Fin.tail x.2) w) := by simp [Finset.mul_sum] + _ ≤ ∑ a, δ (n+1) j (x.1 0,x.2 0) a := Finset.sum_le_sum (fun a _ => + mul_le_of_le_one_right' (ih (n+1) a _)) + _ ≤ 1 := hδ _ _ _ + +def stochCont (δ : ℕ → J → (Space d × ℝ) → J → ℝ≥0∞) + (w : ℕ → J → X → ℝ≥0∞) (ι : X → Space d) (n : ℕ) : ℕ → J → X → ℝ≥0∞ + | 0, j, s => w n j s + | k+1, j, s => ∫⁻ x, ∑ a, δ (n+1) j (x,⟪ι s,x⟫) a * + stochCont δ w ι (n+1) k a s ∂stdGaussian (Space d) + +lemma measurable_stochCont [MeasurableSpace X] {δ : ℕ → J → (Space d × ℝ) → J → ℝ≥0∞} + {w : ℕ → J → X → ℝ≥0∞} {ι : X → Space d} + (hδ : ∀ n j a, Measurable (fun obs => δ n j obs a)) + (hw : ∀ n j, Measurable (w n j)) (hι : Measurable ι) (n k : ℕ) (j : J) : + Measurable (stochCont δ w ι n k j) := by + induction k generalizing n j with + | zero => exact hw n j + | succ k ih => + apply Measurable.lintegral_prod_left + exact Finset.measurable_sum _ (fun a _ => + ((hδ (n+1) j a).comp (by fun_prop)).mul ((ih (n+1) a).comp measurable_snd)) + +lemma stochCont_le_one {δ : ℕ → J → (Space d × ℝ) → J → ℝ≥0∞} + {w : ℕ → J → X → ℝ≥0∞} (ι : X → Space d) + (hδ : ∀ n j obs, ∑ a, δ n j obs a ≤ 1) + (hw : ∀ n j s, w n j s ≤ 1) (n k : ℕ) (j : J) (s : X) : + stochCont δ w ι n k j s ≤ 1 := by + induction k generalizing n j with + | zero => exact hw n j s + | succ k ih => + apply (lintegral_mono (fun x => (Finset.sum_le_sum + (fun a _ => mul_le_of_le_one_right' (ih (n+1) a))).trans (hδ _ _ _))).trans_eq + simp + +lemma stochCont_unroll {δ : ℕ → J → (Space d × ℝ) → J → ℝ≥0∞} + {w : ℕ → J → X → ℝ≥0∞} (ι : X → Space d) + (hδ : ∀ n j a, Measurable (fun obs => δ n j obs a)) + (n m k : ℕ) (j : J) (s : X) : + stochCont δ w ι n (m+k) j s = + ∫⁻ A : Fin m → Space d, ∑ a, stochRoute δ n m j (A,fun i => ⟪ι s,A i⟫) a * + stochCont δ w ι (n+m) k a s ∂Measure.pi (fun _ => stdGaussian (Space d)) := by + classical + induction m generalizing n j with + | zero => simp [stochRoute] + | succ m ih => + rw [Nat.succ_add, stochCont] + simp_rw [ih] + have hf : Measurable (fun A : Fin (m+1) → Space d => ∑ a, + stochRoute δ n (m+1) j (A,fun i => ⟪ι s,A i⟫) a * + stochCont δ w ι (n+(m+1)) k a s) := by + exact Finset.measurable_sum _ (fun a _ => + ((measurable_stochRoute hδ n (m+1) j a).comp (by fun_prop)).mul measurable_const) + rw [lintegral_pi_cons _ _ hf] + apply lintegral_congr + intro x + have hm (a : J) : Measurable (fun A : Fin m → Space d => ∑ b, + stochRoute δ (n+1) m a (A,fun i => ⟪ι s,A i⟫) b * + stochCont δ w ι (n+1+m) k b s) := by + exact Finset.measurable_sum _ (fun b _ => + ((measurable_stochRoute hδ (n+1) m a b).comp (by fun_prop)).mul measurable_const) + simp_rw [← lintegral_const_mul _ (hm _)] + rw [← lintegral_finsetSum _ (fun a _ => (hm a).const_mul _)] + apply lintegral_congr + intro A + simp only [stochRoute, Fin.cons_zero, Fin.tail_cons] + have het : Fin.tail (fun i : Fin (m+1) => ⟪ι s,(Fin.cons x A : Fin (m+1) → Space d) i⟫) = + (fun i => ⟪ι s,A i⟫) := rfl + rw [het] + simp only [Finset.mul_sum, Finset.sum_mul, mul_assoc] + rw [Finset.sum_comm] + congr 1 + funext a + congr 1 + funext b + simp [Nat.add_comm, Nat.add_left_comm] + +end Stochastic +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/StochasticMass.lean b/lean/OAI/Probability/MemoryPrecision/StochasticMass.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d24b6889bb9cc00204ec73e28b30d8350b0912e --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/StochasticMass.lean @@ -0,0 +1,128 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.CubeContinuation +import OAI.Probability.MemoryPrecision.StochasticContinuation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression +lemma stoch_sphere_mass {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + {δ : ℕ → Fin N → (Space d × ℝ) → Fin N → ℝ≥0∞} + {w : ℕ → Fin N → Sphere d → ℝ≥0∞} + (hδ : ∀ n j a, Measurable (fun obs => δ n j obs a)) + (hδ1 : ∀ n j obs, ∑ a, δ n j obs a ≤ 1) (hw : ∀ n j, Measurable (w n j)) + (hw1 : ∀ n j s, w n j s ≤ 1) {H α : ℝ} (hH : 0 < H) + (hαlo : ((d:ℝ)-1)/2 ≤ α) (hαhi : α ≤ (d:ℝ)/2) + (hlocal : ∀ n j, SphereBallBound (w n j) H α) + (b k : ℕ) (hk : k ≤ b*(d/8)) (n : ℕ) (j : Fin N) : + SphereBallBound (stochCont δ w Subtype.val n k j) + (H * RealStep d N ^ b) α := by + have hp : 0 < d/8 := by omega + have hK := realStep_one d hN + have hK0 := realStep_pos d hN + induction b generalizing k n j with + | zero => + have : k = 0 := by omega + subst k + simpa [stochCont] using hlocal n j + | succ b ih => + by_cases hk0 : k = 0 + · subst k + apply (hlocal n j).mono + simpa [stochCont] using le_mul_of_one_le_right hH.le (one_le_pow₀ hK) + · let m := min k (d/8) + have hm : 1 ≤ m := by dsimp [m]; omega + have hmp : m ≤ d/8 := min_le_right _ _ + have hmk : m ≤ k := min_le_left _ _ + have hk' : k-m ≤ b*(d/8) := by + dsimp [m] + rw [Nat.succ_mul] at hk + omega + have hb := (Classical.choose_spec coefficient_step).2 d m N hd hm hmp hN α + (H * RealStep d N ^ b) hαlo hαhi (mul_pos hH (pow_pos hK0 b)) + (fun a => stochCont δ w Subtype.val (n+m) (k-m) a) + (fun a => measurable_stochCont hδ hw measurable_subtype_coe _ _ a) + (fun a s => stochCont_le_one Subtype.val hδ1 hw1 _ _ a s) + (fun a => ih (k-m) hk' (n+m) a) + (fun a x => stochRoute δ n m j x a) + (fun a => measurable_stochRoute hδ n m j a) + (fun x => stochRoute_sum_le_one hδ1 n m j x) + have he : stochCont δ w Subtype.val n k j = + SphereBlock (fun a => stochCont δ w Subtype.val (n+m) (k-m) a) + (fun a x => stochRoute δ n m j x a) := by + funext s + simpa [Nat.add_sub_of_le hmk, SphereBlock, WeightedBlock] using + stochCont_unroll Subtype.val hδ n m (k-m) j s + rw [he] + convert hb using 1 + change H * RealStep d N ^ (b+1) = RealStep d N * (H * RealStep d N ^ b) + rw [pow_succ]; ring + +lemma stoch_cube_mass {d N : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + {δ : ℕ → Fin N → (Space d × ℝ) → Fin N → ℝ≥0∞} + {w : ℕ → Fin N → Cube d → ℝ≥0∞} + (hδ : ∀ n j a, Measurable (fun obs => δ n j obs a)) + (hδ1 : ∀ n j obs, ∑ a, δ n j obs a ≤ 1) (hw : ∀ n j, Measurable (w n j)) + (hw1 : ∀ n j s, w n j s ≤ 1) {H : ℝ} (hH : 0 < H) + (hlocal : ∀ n j, CubeLocal (w n j) H) + (b k : ℕ) (hk : k ≤ b*((d/2)/4)) (n : ℕ) (j : Fin N) : + CubeLocal (stochCont δ w (CubeEmbedding d) n k j) + (H * CubeStep d N ^ b) := by + have hp : 0 < (d/2)/4 := by omega + have hK := cubeStep_one d hN + have hK0 := cubeStep_pos d hN + induction b generalizing k n j with + | zero => + have : k = 0 := by omega + subst k + simpa [stochCont] using hlocal n j + | succ b ih => + by_cases hk0 : k = 0 + · subst k + apply (hlocal n j).mono + simpa [stochCont] using le_mul_of_one_le_right hH.le (one_le_pow₀ hK) + · let m := min k ((d/2)/4) + have hm : 1 ≤ m := by dsimp [m]; omega + have hmp : m ≤ (d/2)/4 := min_le_right _ _ + have hmk : m ≤ k := min_le_left _ _ + have hk' : k-m ≤ b*((d/2)/4) := by + dsimp [m] + rw [Nat.succ_mul] at hk + omega + have hb := (Classical.choose_spec cube_block).2 d m N hd hm hmp hN + (H * CubeStep d N ^ b) (mul_pos hH (pow_pos hK0 b)).le + (fun a => stochCont δ w (CubeEmbedding d) (n+m) (k-m) a) + (fun a => measurable_stochCont hδ hw (cubeEmbedding_measurable d) _ _ a) + (fun a s => stochCont_le_one (CubeEmbedding d) hδ1 hw1 _ _ a s) + (fun a => ih (k-m) hk' (n+m) a) + (fun a x => stochRoute δ n m j x a) + (fun a => measurable_stochRoute hδ n m j a) + (fun x => stochRoute_sum_le_one hδ1 n m j x) + have he : stochCont δ w (CubeEmbedding d) n k j = + WeightedBlock (CubeEmbedding d) + (fun a => stochCont δ w (CubeEmbedding d) (n+m) (k-m) a) + (fun a x => stochRoute δ n m j x a) := by + funext s + simpa [Nat.add_sub_of_le hmk, WeightedBlock] using + stochCont_unroll (CubeEmbedding d) hδ n m (k-m) j s + rw [he] + convert hb using 1 + change H * CubeStep d N ^ (b+1) = CubeStep d N * (H * CubeStep d N ^ b) + rw [pow_succ]; ring + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/StreamArithmetic.lean b/lean/OAI/Probability/MemoryPrecision/StreamArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..927a980404c90446e4070c1d70eb524f253e0d28 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/StreamArithmetic.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.SuccessArithmetic + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision + +def StreamConstant : ℝ := 3*(SuccessConstant+21) +lemma streamConstant_pos : 0 < StreamConstant := by + have h := successConstant_one + dsimp [StreamConstant] + linarith + +lemma blockCount_antitone {p q : ℕ} (hq : 0 < q) (hqp : q ≤ p) (T : ℕ) : + BlockCount T p ≤ BlockCount T q := by + apply Nat.ceil_mono + exact div_le_div_of_nonneg_left (by positivity) (by exact_mod_cast hq) (by exact_mod_cast hqp) + +lemma power_le_exp {x : ℝ} (hx : 0 ≤ x) (d : ℕ) : x^d ≤ Real.exp (x*d) := by + have hl : x ≤ Real.exp x := by linarith [Real.add_one_le_exp x] + have h := pow_le_pow_left₀ hx hl d + simpa only [← Real.rpow_natCast, ← Real.exp_mul] using h + +lemma stream_root_exp {d M : ℕ} (hd : 32 ≤ d) : + (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)) ≤ Real.exp ((d:ℝ)+16*M/d) := by + have hn : (d/8+2)*2^M ≤ 2^(d+M) := by + have h : d/8+2 ≤ 2^d := (show d/8+2 ≤ d+1 by omega).trans Nat.lt_two_pow_self + simpa [pow_add] using Nat.mul_le_mul_right (2^M) h + have ht : (2:ℝ) ≤ Real.exp 1 := by linarith [Real.add_one_le_exp (1:ℝ)] + have hnum : (((d/8+2)*2^M:ℕ):ℝ) ≤ Real.exp ((d:ℝ)+M) := by + calc + _ ≤ (2:ℝ)^(d+M) := by exact_mod_cast hn + _ ≤ (Real.exp 1)^(d+M) := pow_le_pow_left₀ (by norm_num) ht _ + _ = _ := by rw [← Real.rpow_natCast, ← Real.exp_mul]; simp + have hdp : (d:ℝ)/16 ≤ (d/8:ℕ) := by + apply (div_le_iff₀ (by norm_num : (0:ℝ) < 16)).2 + exact_mod_cast (show d ≤ (d/8)*16 by omega) + have hd0 : (0:ℝ) < d := by exact_mod_cast (show 0 < d by omega) + have hr : ((d:ℝ)+M)/((d/8:ℕ):ℝ) ≤ (d:ℝ)+16*M/d := by + calc + _ ≤ ((d:ℝ)+M)/((d:ℝ)/16) := div_le_div_of_nonneg_left (by positivity) (by positivity) hdp + _ = 16+16*M/d := by field_simp + _ ≤ _ := by + have : (16:ℝ) ≤ d := by exact_mod_cast (show 16 ≤ d by omega) + linarith + calc + _ ≤ (Real.exp ((d:ℝ)+M))^(1/((d/8:ℕ):ℝ)) := + Real.rpow_le_rpow (by positivity) hnum (by positivity) + _ = Real.exp (((d:ℝ)+M)/((d/8:ℕ):ℝ)) := by rw [← Real.exp_mul]; congr 1; ring + _ ≤ _ := Real.exp_le_exp.mpr hr + +lemma stream_step_exp {d M : ℕ} (hd : 32 ≤ d) : + SuccessConstant^d * (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)) ≤ + Real.exp ((d:ℝ)*(SuccessConstant+1)+16*M/d) := by + have hS := successConstant_one + calc + _ ≤ Real.exp (SuccessConstant*d) * Real.exp ((d:ℝ)+16*M/d) := + mul_le_mul (power_le_exp (by linarith) d) (stream_root_exp hd) (by positivity) (by positivity) + _ = _ := by rw [← Real.exp_add]; congr 1; ring + +lemma stream_step_one (d M : ℕ) : + 1 ≤ SuccessConstant^d * (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)) := by + apply one_le_mul_of_one_le_of_one_le (one_le_pow₀ successConstant_one) + apply Real.one_le_rpow _ (by positivity) + exact_mod_cast (show 1 ≤ (d/8+2)*2^M by + exact Nat.succ_le_iff.mpr (Nat.mul_pos (by omega) (by positivity))) + +lemma stream_exponent_bound {d M : ℕ} (hd : 32 ≤ d) : + (d:ℝ)*(SuccessConstant+5)+16*M/d ≤ + (((d:ℝ)-1)/2)*StreamConstant*(1+(M:ℝ)/(d:ℝ)^2) := by + have hS := successConstant_one + have hd0 : (0:ℝ) < d := by exact_mod_cast (show 0 < d by omega) + have hd3 : (d:ℝ)/3 ≤ ((d:ℝ)-1)/2 := by + have : (32:ℝ) ≤ d := by exact_mod_cast hd + linarith + have hc : 0 ≤ StreamConstant := streamConstant_pos.le + calc + _ ≤ (SuccessConstant+21)*(d:ℝ)+(SuccessConstant+21)*(M/d) := by + have hM : 0 ≤ (M:ℝ)/d := by positivity + have hm := mul_le_mul_of_nonneg_right (show (16:ℝ) ≤ SuccessConstant+21 by linarith) hM + have hn : (d:ℝ)*(SuccessConstant+5) ≤ (SuccessConstant+21)*(d:ℝ) := by nlinarith + simpa only [mul_div_assoc] using add_le_add hn hm + _ = (d:ℝ)/3*StreamConstant*(1+(M:ℝ)/(d:ℝ)^2) := by + dsimp [StreamConstant] + field_simp + _ ≤ _ := mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hd3 hc) (by positivity) + +lemma stream_full_factor {d M T : ℕ} (hd : 32 ≤ d) (hT : 0 < T) : + (4:ℝ)^d * (SuccessConstant^d * (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)))^BlockCount T (d/8) ≤ + Real.exp ((((d:ℝ)-1)/2)*StreamConstant*(1+(M:ℝ)/(d:ℝ)^2)*(BlockCount T ((d-1)/8):ℝ)) := by + let b := BlockCount T ((d-1)/8) + let K := SuccessConstant^d * (((d/8+2)*2^M:ℕ):ℝ)^(1/((d/8:ℕ):ℝ)) + have hK : 1 ≤ K := stream_step_one d M + have hb : 1 ≤ b := blockCount_pos hT (by omega) + have hbp : BlockCount T (d/8) ≤ b := blockCount_antitone (by omega) (by omega) T + have h4 : (4:ℝ)^d ≤ Real.exp (4*d*(b:ℝ)) := by + apply (power_le_exp (by norm_num : (0:ℝ) ≤ 4) d).trans + apply Real.exp_le_exp.mpr + exact le_mul_of_one_le_right (by positivity) (by exact_mod_cast hb) + have hpow : K^b ≤ Real.exp (((d:ℝ)*(SuccessConstant+1)+16*M/d)*(b:ℝ)) := by + have h := pow_le_pow_left₀ (by linarith : 0 ≤ K) (stream_step_exp hd) b + simpa only [← Real.rpow_natCast, ← Real.exp_mul, K] using h + calc + _ ≤ (4:ℝ)^d * K^b := mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hK hbp) (by positivity) + _ ≤ Real.exp (4*d*(b:ℝ)) * Real.exp (((d:ℝ)*(SuccessConstant+1)+16*M/d)*(b:ℝ)) := + mul_le_mul h4 hpow (by positivity) (by positivity) + _ = Real.exp (((d:ℝ)*(SuccessConstant+5)+16*M/d)*(b:ℝ)) := by rw [← Real.exp_add]; congr 1; ring + _ ≤ _ := Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right (stream_exponent_bound hd) (by positivity)) + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/StreamZero.lean b/lean/OAI/Probability/MemoryPrecision/StreamZero.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d081d539a5801dd9becf016837f359238f371cd --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/StreamZero.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision + +lemma zero_cap_coefficient {d : ℕ} (hd : 32 ≤ d) : + (3*4^d:ℝ) ≤ (20:ℝ)^(((d:ℝ)-1)/2) := by + have hs : (9:ℝ)*16^d ≤ 20^(d-1) := by + obtain ⟨k,rfl⟩ := Nat.exists_eq_add_of_le hd + have he : 32+k-1 = 31+k := by omega + rw [he, pow_add, pow_add] + have hb : (9:ℝ)*16^32 ≤ 20^31 := by norm_num + calc + _ = ((9:ℝ)*16^32)*16^k := by ring + _ ≤ 20^31*20^k := mul_le_mul hb (pow_le_pow_left₀ (by norm_num) (by norm_num : (16:ℝ) ≤ 20) k) + (by positivity) (by positivity) + apply (sq_le_sq₀ (by positivity) (by positivity)).mp + have hl : (3*4^d:ℝ)^2 = 9*16^d := by + rw [mul_pow, ← pow_mul, Nat.mul_comm d 2, pow_mul] + norm_num + have hr : ((20:ℝ)^(((d:ℝ)-1)/2))^2 = 20^(d-1) := by + rw [← Real.rpow_natCast, ← Real.rpow_mul (by norm_num : (0:ℝ) ≤ 20)] + rw [← Real.rpow_natCast] + congr 1 + rw [Nat.cast_sub (by omega), Nat.cast_one] + ring + rwa [hl,hr] + +lemma zero_cap_precise {d : ℕ} (hd : 32 ≤ d) {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1/10) : + (3*4^d:ℝ)*ε^(d-1) ≤ (2*ε)^(((d:ℝ)-1)/2) := by + let a := ((d:ℝ)-1)/2 + have ha : 0 ≤ a := by + dsimp [a] + have : (32:ℝ) ≤ d := by exact_mod_cast hd + linarith + have he : ε^(d-1) = ε^a*ε^a := by + rw [← Real.rpow_add hε, ← Real.rpow_natCast] + congr 1 + dsimp [a] + rw [Nat.cast_sub (by omega), Nat.cast_one] + ring + have hsmall : (10*ε)^a ≤ 1 := Real.rpow_le_one (by positivity) (by linarith) ha + calc + _ ≤ (20:ℝ)^a * ε^(d-1) := mul_le_mul_of_nonneg_right (zero_cap_coefficient hd) (by positivity) + _ = (2*ε)^a*(10*ε)^a := by + rw [he, Real.mul_rpow (by norm_num : (0:ℝ) ≤ 2) hε.le, + Real.mul_rpow (by norm_num : (0:ℝ) ≤ 10) hε.le] + have h20 := Real.mul_rpow (z := a) (by norm_num : (0:ℝ) ≤ 2) (by norm_num : (0:ℝ) ≤ 10) + norm_num only [show (2:ℝ)*10=20 by norm_num] at h20 + rw [h20] + ring + _ ≤ (2*ε)^a * 1 := mul_le_mul_of_nonneg_left hsmall (by positivity) + _ = _ := mul_one _ +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/SuccessArithmetic.lean b/lean/OAI/Probability/MemoryPrecision/SuccessArithmetic.lean new file mode 100644 index 0000000000000000000000000000000000000000..f7173d0a06816d06d506788a15b34a9b9b4ebe15 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/SuccessArithmetic.lean @@ -0,0 +1,111 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.RealContinuation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision + +def SuccessConstant : ℝ := 6*StepConstant +lemma successConstant_one : 1 ≤ SuccessConstant := by + have h := stepConstant_one + dsimp [SuccessConstant] + linarith + +lemma stopping_factor_bound {d : ℕ} (hd : 16 ≤ d) (T : ℕ) : + (T+1:ℝ) ≤ ((2:ℝ)^d)^BlockCount T (d/8) := by + have hT := blockCount_mul_ge T (by omega : 0 < d/8) + have hp : d/8 ≤ d := Nat.div_le_self _ _ + have hTd : T ≤ d * BlockCount T (d/8) := by nlinarith + have htwo : (T+1:ℕ) ≤ 2^T := Nat.lt_two_pow_self + have hpow : (2:ℝ)^T ≤ 2^(d * BlockCount T (d/8)) := + pow_le_pow_right₀ (by norm_num) hTd + rw [pow_mul] at hpow + exact (by exact_mod_cast htwo : (T+1:ℝ) ≤ (2:ℝ)^T).trans hpow + +lemma stopping_step_bound {d N K : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) (hNK : N ≤ K) + (T : ℕ) : + (T+1:ℝ) * RealStep d N ^ BlockCount T (d/8) ≤ + ((2*StepConstant)^d * (K:ℝ)^(1/((d/8:ℕ):ℝ))) ^ BlockCount T (d/8) := by + have hSp := stepConstant_pos + have hR := realStep_pos d hN + have hn0 : (0:ℝ) ≤ N := by positivity + have hroot : (N:ℝ)^(1/((d/8:ℕ):ℝ)) ≤ (K:ℝ)^(1/((d/8:ℕ):ℝ)) := + Real.rpow_le_rpow hn0 (by exact_mod_cast hNK) (by positivity) + calc + _ ≤ ((2:ℝ)^d)^BlockCount T (d/8) * RealStep d N ^ BlockCount T (d/8) := + mul_le_mul_of_nonneg_right (stopping_factor_bound hd T) (by positivity) + _ = ((2*StepConstant)^d * (N:ℝ)^(1/((d/8:ℕ):ℝ))) ^ BlockCount T (d/8) := by + rw [← mul_pow] + congr 1 + simp only [RealStep, mul_pow] + ring + _ ≤ _ := pow_le_pow_left₀ (by positivity) + (mul_le_mul_of_nonneg_left hroot (by positivity)) _ + +lemma stopping_step_bound_three {d N K T : ℕ} (hd : 16 ≤ d) (hN : 1 ≤ N) + (hNK : N ≤ K) (hT : 0 < T) : + 3 * ((T+1:ℝ) * RealStep d N ^ BlockCount T (d/8)) ≤ + (SuccessConstant^d * (K:ℝ)^(1/((d/8:ℕ):ℝ))) ^ BlockCount T (d/8) := by + have hSp := stepConstant_pos + have hR := realStep_pos d hN + have hb := blockCount_pos hT (by omega : 0 < d/8) + have h3 : (3:ℝ) ≤ ((3:ℝ)^d)^BlockCount T (d/8) := by + rw [← pow_mul] + have hdb : 1 ≤ d * BlockCount T (d/8) := Nat.mul_pos (by omega) hb + simpa using pow_le_pow_right₀ (by norm_num : (1:ℝ) ≤ 3) hdb + have hroot0 : 0 ≤ (K:ℝ)^(1/((d/8:ℕ):ℝ)) := by positivity + calc + _ ≤ ((3:ℝ)^d)^BlockCount T (d/8) * + ((2*StepConstant)^d * (K:ℝ)^(1/((d/8:ℕ):ℝ))) ^ BlockCount T (d/8) := + mul_le_mul h3 (stopping_step_bound hd hN hNK T) + (by positivity) (by positivity) + _ = _ := by + rw [← mul_pow] + congr 1 + rw [← mul_assoc, ← mul_pow] + congr 2 + dsimp [SuccessConstant] + ring + +lemma cap_constant_le {d : ℕ} (hd : 1 ≤ d) : (3*4^d:ℝ) ≤ 12^d := by + have h3 : (3:ℝ) ≤ 3^d := by + simpa using pow_le_pow_right₀ (by norm_num : (1:ℝ) ≤ 3) hd + calc + _ ≤ 3^d*4^d := mul_le_mul_of_nonneg_right h3 (by positivity) + _ = _ := by rw [← mul_pow]; norm_num + +lemma terminal_angular_zero_bound {d : ℕ} (hd : 16 ≤ d) {ε : ℝ} + (hε : 0 < ε) (hε1 : ε ≤ 1/10) : + (3*4^d:ℝ)*ε^(d-1) ≤ 4^d*ε^(((d:ℝ)-1)/2) := by + have hd' : (16:ℝ) ≤ d := by exact_mod_cast hd + have hα : (1:ℝ) ≤ ((d:ℝ)-1)/2 := by linarith + have hεa : ε^(((d:ℝ)-1)/2) ≤ ε := by + simpa using Real.rpow_le_rpow_of_exponent_ge hε (by linarith : ε ≤ 1) hα + have hn : ((d-1:ℕ):ℝ) = (d:ℝ)-1 := by rw [Nat.cast_sub (by omega), Nat.cast_one] + have he : ε^(d-1) = ε^(((d:ℝ)-1)/2) * ε^(((d:ℝ)-1)/2) := by + rw [← Real.rpow_add hε, ← Real.rpow_natCast, hn] + congr 1 + ring + rw [he] + have haux : 3*ε^(((d:ℝ)-1)/2) ≤ 1 := by linarith + calc + _ = (4^d*ε^(((d:ℝ)-1)/2)) * (3*ε^(((d:ℝ)-1)/2)) := by ring + _ ≤ (4^d*ε^(((d:ℝ)-1)/2)) * 1 := mul_le_mul_of_nonneg_left haux (by positivity) + _ = _ := mul_one _ + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/WeightedImage.lean b/lean/OAI/Probability/MemoryPrecision/WeightedImage.lean new file mode 100644 index 0000000000000000000000000000000000000000..db79746e9f2073626ddbb22e1b72b72171bf474a --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/WeightedImage.lean @@ -0,0 +1,132 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.AmbientGram + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +lemma space_finiteDimensional (d : ℕ) : FiniteDimensional ℝ (Space d) := by + infer_instance + +section WeightedImage +variable {X : Type*} [MeasurableSpace X] {d m N : ℕ} + +def WeightedBlock (ι : X → Space d) (h : Fin N → X → ℝ≥0∞) + (g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞) (x : X) : ℝ≥0∞ := + let exponent : ℝ≥0∞ := @OfNat.ofNat ℝ≥0∞ 2 + (@instOfNatAtLeastTwo ℝ≥0∞ 2 ENNReal.instAddCommMonoidWithOne.toNatCast + (Mathlib.Meta.NormNum.instAtLeastTwo (nat_lit 0))) + let euclideanMeasurable := @WithLp.measurableSpace exponent (Fin d → ℝ) inferInstance + let rowMeasurable := @MeasurableSpace.pi (Fin m) (fun _ => Space d) + (fun _ => euclideanMeasurable) + @MeasureTheory.lintegral (Fin m → Space d) rowMeasurable + (@Measure.pi (Fin m) (fun _ => Space d) inferInstance (fun _ => euclideanMeasurable) + (fun _ => @stdGaussian (Space d) + (PiLp.normedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ)) + (space_finiteDimensional d) euclideanMeasurable)) + (fun rows => ∑ state, g state (rows, fun index => @inner ℝ (Space d) + (@InnerProductSpace.toInner ℝ (Space d) _ + (PiLp.seminormedAddCommGroup exponent (fun _ : Fin d => ℝ)) + (PiLp.innerProductSpace (𝕜 := ℝ) (fun _ : Fin d => ℝ))) + (ι x) (rows index)) * h state x) + +lemma measurable_weightedBlock {ι : X → Space d} (hι : Measurable ι) + {h : Fin N → X → ℝ≥0∞} (hh : ∀ w, Measurable (h w)) + {g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞} + (hg : ∀ w, Measurable (g w)) : Measurable (WeightedBlock ι h g) := by + apply Measurable.lintegral_prod_left + exact Finset.measurable_sum _ (fun w _ => ((hg w).comp (by fun_prop)).mul ((hh w).comp measurable_snd)) + +omit [MeasurableSpace X] in +lemma weightedBlock_le_one (ι : X → Space d) {h : Fin N → X → ℝ≥0∞} + (hh1 : ∀ w x, h w x ≤ 1) + {g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞} + (hg1 : ∀ x, ∑ w, g w x ≤ 1) (x : X) : WeightedBlock ι h g x ≤ 1 := by + unfold WeightedBlock + calc + _ ≤ ∫⁻ _A : Fin m → Space d, (1:ℝ≥0∞) ∂Measure.pi (fun _ => stdGaussian (Space d)) := by + apply lintegral_mono + intro A + exact (Finset.sum_le_sum (fun w _ => mul_le_of_le_one_right' (hh1 w x))).trans (hg1 _) + _ = 1 := by simp + +lemma weighted_image_finite (μ : Measure X) [IsFiniteMeasure μ] (ι : X → Space d) + (h : X → ℝ≥0∞) (hh1 : ∀ x, h x ≤ 1) : + IsFiniteMeasure ((μ.withDensity h).map ι) := by + let := isFiniteMeasure_withDensity (μ := μ) (ne_of_lt ((lintegral_mono hh1).trans_lt (by simp))) + infer_instance + +lemma weighted_image_ball (μ : Measure X) {ι : X → Space d} (hι : Measurable ι) + (h : X → ℝ≥0∞) (z : Space d) (r : ℝ) : + (μ.withDensity h).map ι (Metric.closedBall z r) = + ∫⁻ x in {x | dist (ι x) z ≤ r}, h x ∂μ := by + rw [Measure.map_apply hι Metric.isClosed_closedBall.measurableSet, + withDensity_apply _ (hι Metric.isClosed_closedBall.measurableSet)] + rfl + +lemma projectionLaw_lintegral (ν : Measure (Space d)) [SFinite ν] + (g : ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞) (hg : Measurable g) : + (∫⁻ x, g x ∂projectionLaw ν m) = + ∫⁻ s, ∫⁻ A, g (A,fun j => ⟪s,A j⟫) + ∂Measure.pi (fun _ : Fin m => stdGaussian (Space d)) ∂ν := by + have hobs : Measurable (fun x : (Fin m → Space d) × Space d => g (x.1,fun j => ⟪x.2,x.1 j⟫)) := + hg.comp (by fun_prop) + rw [projectionLaw, lintegral_map hg (by fun_prop)] + exact lintegral_prod_symm _ hobs.aemeasurable + +lemma weightedBlock_mass_identity (μ : Measure X) [IsFiniteMeasure μ] + {ι : X → Space d} (hι : Measurable ι) + {h : Fin N → X → ℝ≥0∞} (hh : ∀ w, Measurable (h w)) (hh1 : ∀ w x, h w x ≤ 1) + {g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞} + (hg : ∀ w, Measurable (g w)) {B : Set (Space d)} (hB : MeasurableSet B) : + (∫⁻ x in ι ⁻¹' B, WeightedBlock ι h g x ∂μ) = + ∑ w, ∫⁻ x, g w x ∂projectionLaw (((μ.withDensity (h w)).map ι).restrict B) m := by + classical + let (w : Fin N) : IsFiniteMeasure (μ.withDensity (h w)) := + isFiniteMeasure_withDensity (ne_of_lt ((lintegral_mono (hh1 w)).trans_lt (by simp))) + let G (w : Fin N) (x : X) (A : Fin m → Space d) := g w (A, fun j => ⟪ι x,A j⟫) * h w x + have hG (w) : Measurable (Function.uncurry (G w)) := + ((hg w).comp (by fun_prop)).mul ((hh w).comp measurable_fst) + have he (w) : (∫⁻ u, g w u ∂projectionLaw (((μ.withDensity (h w)).map ι).restrict B) m) = + ∫⁻ x in ι ⁻¹' B, ∫⁻ A, G w x A + ∂Measure.pi (fun _ : Fin m => stdGaussian (Space d)) ∂μ := by + have hobs : Measurable (fun x : (Fin m → Space d) × Space d => + g w (x.1,fun j => ⟪x.2,x.1 j⟫)) := (hg w).comp (by fun_prop) + have htech : Measurable (fun x : (Fin m → Space d) × X => + g w (x.1,fun j => ⟪ι x.2,x.1 j⟫)) := (hg w).comp (by fun_prop) + rw [projectionLaw_lintegral _ _ (hg w), Measure.restrict_map hι hB, + lintegral_map hobs.lintegral_prod_left hι, + restrict_withDensity (hι hB), lintegral_withDensity_eq_lintegral_mul _ (hh w) + htech.lintegral_prod_left] + apply lintegral_congr + intro x + simp only [Pi.mul_apply] + rw [← lintegral_const_mul' _ _ (ne_of_lt ((hh1 w x).trans_lt (by simp)))] + apply lintegral_congr + intro A + exact mul_comm _ _ + simp_rw [he] + rw [← lintegral_finsetSum _ (fun w _ => (hG w).lintegral_prod_right)] + apply lintegral_congr + intro x + unfold WeightedBlock + exact lintegral_finsetSum _ (fun w _ => (hG w).comp (measurable_const.prodMk measurable_id)) +end WeightedImage +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/WeightedSelection.lean b/lean/OAI/Probability/MemoryPrecision/WeightedSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..209e7d67be13cae46694206bec2e619c12a56f08 --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/WeightedSelection.lean @@ -0,0 +1,240 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.MeasurableTests + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression + +def realNormalize {d : ℕ} (ν : Measure (Space d)) (β H : ℝ) (z : Space d) (r : ℝ) : + Measure (Space d) := + (ENNReal.ofReal (H * r^β))⁻¹ • + (ν.restrict (Metric.closedBall z r)).map (fun x => r⁻¹ • (x-z)) + +lemma realNormalize_local {d : ℕ} {ν : Measure (Space d)} {β H : ℝ} + (hν : AmbientBallBound ν H β) (hH : 0 < H) (z : Space d) {r : ℝ} (hr : 0 < r) : + AmbientBallBound (realNormalize ν β H z r) 1 β := by + have hc0 : ENNReal.ofReal (H*r^β) ≠ 0 := by positivity + intro t ρ hρ + rw [realNormalize, Measure.smul_apply, smul_eq_mul, + Measure.map_apply (by fun_prop) Metric.isClosed_closedBall.measurableSet] + have hsub : (fun x : Space d => r⁻¹ • (x-z)) ⁻¹' Metric.closedBall t ρ ⊆ + Metric.closedBall (z + r • t) (r*ρ) := by + intro x hx + have he : x-(z+r•t) = r • (r⁻¹ • (x-z)-t) := by + rw [smul_sub, smul_smul, mul_inv_cancel₀ hr.ne', one_smul] + abel + rw [Metric.mem_closedBall, dist_eq_norm, he, norm_smul, Real.norm_eq_abs, abs_of_pos hr] + exact mul_le_mul_of_nonneg_left + (by simpa only [Set.mem_preimage, Metric.mem_closedBall, dist_eq_norm] using hx) hr.le + calc + _ ≤ (ENNReal.ofReal (H*r^β))⁻¹ * ν (Metric.closedBall (z+r•t) (r*ρ)) := + mul_le_mul' le_rfl ((Measure.restrict_le_self _).trans (measure_mono hsub)) + _ ≤ (ENNReal.ofReal (H*r^β))⁻¹ * ENNReal.ofReal (H*(r*ρ)^β) := + mul_le_mul' le_rfl (hν _ _ (mul_pos hr hρ)) + _ = ENNReal.ofReal (1*ρ^β) := by + rw [Real.mul_rpow hr.le hρ.le, ← mul_assoc, + ENNReal.ofReal_mul (by positivity : 0 ≤ H*r^β), ← mul_assoc, + ENNReal.inv_mul_cancel hc0 ENNReal.ofReal_ne_top, one_mul, one_mul] + +lemma realNormalize_support {d : ℕ} (ν : Measure (Space d)) (β H : ℝ) + (z : Space d) {r : ℝ} (hr : 0 < r) : + (realNormalize ν β H z r).support ⊆ Metric.closedBall 0 1 := by + apply Measure.support_subset_of_isClosed Metric.isClosed_closedBall + rw [mem_ae_iff, realNormalize, Measure.smul_apply, Measure.map_apply (by fun_prop) + Metric.isClosed_closedBall.measurableSet.compl, + Measure.restrict_apply ((by fun_prop : Measurable (fun x : Space d => r⁻¹ • (x-z))) + Metric.isClosed_closedBall.measurableSet.compl)] + have he : (fun x : Space d => r⁻¹ • (x-z)) ⁻¹' (Metric.closedBall 0 1)ᶜ ∩ + Metric.closedBall z r = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro x ⟨hx,hb⟩ + apply hx + rw [Metric.mem_closedBall, dist_zero_right, norm_smul, Real.norm_eq_abs, + abs_of_pos (inv_pos.mpr hr)] + exact (inv_mul_le_iff₀ hr).2 (by simpa [dist_eq_norm] using hb) + rw [he, measure_empty, smul_zero] + +lemma realNormalize_finite {d : ℕ} (ν : Measure (Space d)) [IsFiniteMeasure ν] + {β H : ℝ} (hH : 0 < H) (z : Space d) {r : ℝ} (hr : 0 < r) : + IsFiniteMeasure (realNormalize ν β H z r) := by + constructor + rw [realNormalize, Measure.smul_apply, smul_eq_mul] + apply ENNReal.mul_lt_top + · exact ENNReal.inv_lt_top.mpr (by positivity) + · exact measure_lt_top _ _ + +lemma realNormalize_reconstruct {d : ℕ} (ν : Measure (Space d)) {β H : ℝ} + (hH : 0 < H) (z : Space d) {r : ℝ} (hr : 0 < r) : + ENNReal.ofReal (H*r^β) • (realNormalize ν β H z r).map (fun t => z+r•t) = + ν.restrict (Metric.closedBall z r) := by + have hc0 : ENNReal.ofReal (H*r^β) ≠ 0 := by positivity + rw [realNormalize, Measure.map_smul _ (by fun_prop), smul_smul, + ENNReal.mul_inv_cancel hc0 ENNReal.ofReal_ne_top, one_smul, + Measure.map_map (by fun_prop) (by fun_prop)] + have he : (fun t : Space d => z+r•t) ∘ (fun x => r⁻¹ • (x-z)) = id := by + ext x + simp [smul_smul, hr.ne'] + rw [he, Measure.map_id] + +lemma normalized_scale_le {d m p : ℕ} (hp : 2 ≤ p) {β K : ℝ} (hK : 1 ≤ K) + (hgap : (m:ℝ)+(p:ℝ)-2 < β) + (hJ : ∀ j : ℕ, j ≤ p-2 → J β m j ≤ K^d) : + ProjectionNormScale m p 1 β 1 ≤ K^d := by + have hp0 : (0:ℝ) < p := by exact_mod_cast (by omega : 0 < p) + have hprod0 : 0 ≤ ∏ j ∈ Finset.range (p-1), J β m j := by + apply Finset.prod_nonneg + intro j hj + apply (J_pos ?_).le + have hj' : (j:ℝ)+2 ≤ p := by exact_mod_cast (show j+2 ≤ p by have := Finset.mem_range.mp hj; omega) + linarith + have hprod : (∏ j ∈ Finset.range (p-1), J β m j) ≤ (K^d)^(p-1) := by + calc + _ ≤ ∏ _j ∈ Finset.range (p-1), K^d := by + apply Finset.prod_le_prod₀ + · intro j hj + apply (J_pos ?_).le + have hj' : (j:ℝ)+2 ≤ p := by exact_mod_cast (show j+2 ≤ p by have := Finset.mem_range.mp hj; omega) + linarith + · intro j hj + exact hJ j (by have := Finset.mem_range.mp hj; omega) + _ = _ := by simp + have hpeak : (2*Real.pi) ^ (-(m:ℝ)*((p:ℝ)-1)/(2*(p:ℝ))) ≤ 1 := by + apply Real.rpow_le_one_of_one_le_of_nonpos + · linarith [Real.pi_gt_three] + · have : (1:ℝ) ≤ p := by exact_mod_cast (by omega : 1 ≤ p) + apply div_nonpos_of_nonpos_of_nonneg + · exact mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (Nat.cast_nonneg m)) (by linarith) + · positivity + unfold ProjectionNormScale + simp only [mul_one, Real.one_rpow] + calc + _ ≤ 1 * (∏ j ∈ Finset.range (p-1), J β m j)^(1/(p:ℝ)) := + mul_le_mul_of_nonneg_right hpeak (Real.rpow_nonneg hprod0 _) + _ ≤ ((K^d)^(p-1))^(1/(p:ℝ)) := by rw [one_mul]; exact Real.rpow_le_rpow hprod0 hprod (by positivity) + _ = (K^d)^(((p-1:ℕ):ℝ)/(p:ℝ)) := by + rw [← Real.rpow_natCast_mul (by positivity : 0 ≤ K^d)] + congr 1 + ring + _ ≤ (K^d)^(1:ℝ) := by + apply Real.rpow_le_rpow_of_exponent_le (one_le_pow₀ hK) + rw [div_le_one hp0] + exact_mod_cast Nat.sub_le p 1 + _ = _ := Real.rpow_one _ + +lemma normalized_weighted_selection {d m p N : ℕ} (ν : Fin N → Measure (Space d)) + [∀ w, IsFiniteMeasure (ν w)] (hp : 2 ≤ p) (hm : 1 ≤ m) (hmd : m ≤ d) + {β K : ℝ} (hK : 1 ≤ K) (hgap : (m:ℝ)+(p:ℝ)-2 < β) + (hJ : ∀ j : ℕ, j ≤ p-2 → J β m j ≤ K^d) + (hball : ∀ w, AmbientBallBound (ν w) 1 β) + (hsupport : ∀ w, (ν w).support ⊆ Metric.closedBall 0 1) + (g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞) + (hg : ∀ w, Measurable (g w)) (hgsum : ∀ x, ∑ w, g w x ≤ 1) : + (∑ w, ∫⁻ x, g w x ∂projectionLaw (ν w) m) ≤ + ENNReal.ofReal (K*192)^d * (N:ℝ≥0∞)^(1/(p:ℝ)) := by + classical + obtain ⟨D,hD,hDs,hDV⟩ := exists_projection_support (E := Space d) m (by simpa using hmd) + have hg1 (w) (x) : g w x ≤ 1 := + (Finset.single_le_sum (fun _ _ => zero_le) (Finset.mem_univ w)).trans (hgsum x) + have hpoint (w) : (∫⁻ x, g w x ∂projectionLaw (ν w) m) ≤ + ENNReal.ofReal (K^d) * (∫⁻ x in D, g w x ∂matrixLabelReference m)^(1-1/(p:ℝ)) := by + obtain ⟨F,hF,hF0,hden,_,hnorm⟩ := exact_finite_density d m p hp hm β 1 1 hgap + (by norm_num) (by norm_num) 0 (ν w) (hsupport w) (hball w) + have hFD : ∀ᵐ x ∂matrixLabelReference m, x ∉ D → F x = 0 := by + have hz : projectionLaw (ν w) m Dᶜ = 0 := by + rw [← compl_mem_ae_iff, compl_compl] + unfold projectionLaw + apply (ae_map_iff (by fun_prop) hD).2 + filter_upwards [Measure.quasiMeasurePreserving_snd.ae (ν w).support_mem_ae] with x hx + exact hDs x.1 x.2 (by simpa using hsupport w hx) + change (matrixLabelReference m).withDensity _ = projectionLaw (ν w) m at hden + rw [← hden, withDensity_apply _ hD.compl] at hz + have ha := (lintegral_eq_zero_iff' hF.ennreal_ofReal.aemeasurable).mp hz + change ∀ᵐ x ∂(matrixLabelReference m).restrict Dᶜ, ENNReal.ofReal (F x) = 0 at ha + rw [ae_restrict_iff' hD.compl] at ha + filter_upwards [ha] with x hx hnot + exact le_antisymm (ENNReal.ofReal_eq_zero.mp (hx hnot)) (hF0 x) + have hn : eLpNorm F (p:ℝ≥0∞) (matrixLabelReference m) ≤ ENNReal.ofReal (K^d) := + hnorm.trans (ENNReal.ofReal_le_ofReal (normalized_scale_le hp hK hgap hJ)) + have ht := density_test_bound (matrixLabelReference m) F hF hF0 p hp + (ENNReal.ofReal (K^d)) hn D hD hFD (g w) (hg w).aemeasurable (hg1 w) + change (matrixLabelReference m).withDensity _ = projectionLaw (ν w) m at hden + rwa [hden] at ht + have hq0 : 0 ≤ 1-1/(p:ℝ) := by + have hp1 : (1:ℝ) ≤ p := by exact_mod_cast (by omega : 1 ≤ p) + linarith [one_div_le_one_div_of_le (by norm_num : (0:ℝ)<1) hp1] + have hsum : (∑ w, ∫⁻ x in D, g w x ∂matrixLabelReference m) ≤ + matrixLabelReference (E := Space d) m D := by + rw [← lintegral_finsetSum _ (fun w _ => hg w)] + simpa using lintegral_mono (μ := (matrixLabelReference (E := Space d) m).restrict D) hgsum + have hv : (matrixLabelReference (E := Space d) m D)^(1-1/(p:ℝ)) ≤ (192:ℝ≥0∞)^d := by + calc + _ ≤ ((192:ℝ≥0∞)^d)^(1-1/(p:ℝ)) := ENNReal.rpow_le_rpow (by simpa using hDV) hq0 + _ ≤ ((192:ℝ≥0∞)^d)^(1:ℝ) := + ENNReal.rpow_le_rpow_of_exponent_le (one_le_pow₀ (by norm_num)) (sub_le_self _ (by positivity)) + _ = _ := ENNReal.rpow_one _ + calc + _ ≤ ∑ w, ENNReal.ofReal (K^d) * (∫⁻ x in D, g w x ∂matrixLabelReference m)^(1-1/(p:ℝ)) := + Finset.sum_le_sum (fun w _ => hpoint w) + _ = ENNReal.ofReal (K^d) * ∑ w, (∫⁻ x in D, g w x ∂matrixLabelReference m)^(1-1/(p:ℝ)) := by rw [Finset.mul_sum] + _ ≤ ENNReal.ofReal (K^d) * ((N:ℝ≥0∞)^(1/(p:ℝ)) * + (∑ w, ∫⁻ x in D, g w x ∂matrixLabelReference m)^(1-1/(p:ℝ))) := by + apply mul_le_mul' le_rfl + simpa using finite_rpow_holder (fun w => ∫⁻ x in D, g w x ∂matrixLabelReference m) + (by exact_mod_cast (by omega : 1 < p)) + _ ≤ ENNReal.ofReal (K^d) * ((N:ℝ≥0∞)^(1/(p:ℝ)) * (192:ℝ≥0∞)^d) := + mul_le_mul' le_rfl (mul_le_mul' le_rfl ((ENNReal.rpow_le_rpow hsum hq0).trans hv)) + _ = _ := by + rw [ENNReal.ofReal_pow (by linarith : 0 ≤ K), mul_left_comm, ← mul_pow, + ENNReal.ofReal_mul (by linarith : 0 ≤ K)] + norm_num + ring +lemma localized_weighted_selection {d m p N : ℕ} (ν : Fin N → Measure (Space d)) + [∀ w, IsFiniteMeasure (ν w)] (hp : 2 ≤ p) (hm : 1 ≤ m) (hmd : m ≤ d) + {β K H : ℝ} (hK : 1 ≤ K) (hH : 0 < H) (hgap : (m:ℝ)+(p:ℝ)-2 < β) + (hJ : ∀ j : ℕ, j ≤ p-2 → J β m j ≤ K^d) + (hball : ∀ w, AmbientBallBound (ν w) H β) + (g : Fin N → ((Fin m → Space d) × (Fin m → ℝ)) → ℝ≥0∞) + (hg : ∀ w, Measurable (g w)) (hgsum : ∀ x, ∑ w, g w x ≤ 1) + (z : Space d) {r : ℝ} (hr : 0 < r) : + (∑ w, ∫⁻ x, g w x ∂projectionLaw ((ν w).restrict (Metric.closedBall z r)) m) ≤ + ENNReal.ofReal ((K*192)^d * (N:ℝ)^(1/(p:ℝ)) * H * r^β) := by + let τ w := realNormalize (ν w) β H z r + let (w : Fin N) : IsFiniteMeasure (τ w) := realNormalize_finite (ν w) hH z hr + let F : ((Fin m → Space d) × (Fin m → ℝ)) → ((Fin m → Space d) × (Fin m → ℝ)) := + fun x => (x.1, fun i => ⟪z,x.1 i⟫ + r*x.2 i) + have hF : Measurable F := by fun_prop + have hb := normalized_weighted_selection τ hp hm hmd hK hgap hJ + (fun w => realNormalize_local (hball w) hH z hr) + (fun w => realNormalize_support (ν w) β H z hr) + (fun w => g w ∘ F) (fun w => (hg w).comp hF) (fun x => hgsum (F x)) + have he (w) : (∫⁻ x, g w x ∂projectionLaw ((ν w).restrict (Metric.closedBall z r)) m) = + ENNReal.ofReal (H*r^β) * ∫⁻ x, g w (F x) ∂projectionLaw (τ w) m := by + rw [← realNormalize_reconstruct (ν w) (β := β) hH z hr, projectionLaw_smul, + projectionLaw_affine, lintegral_smul_measure, smul_eq_mul, lintegral_map (hg w) hF] + simp_rw [he] + rw [← Finset.mul_sum] + refine (mul_le_mul' le_rfl hb).trans_eq ?_ + rw [← ENNReal.ofReal_natCast N, ENNReal.ofReal_rpow_of_nonneg (Nat.cast_nonneg _) (by positivity), + ← ENNReal.ofReal_pow (by positivity : 0 ≤ K*192), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ (K*192)^d), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ H*r^β)] + congr 1 + ring + +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/MemoryPrecision/ZeroHorizon.lean b/lean/OAI/Probability/MemoryPrecision/ZeroHorizon.lean new file mode 100644 index 0000000000000000000000000000000000000000..702be80baf9d94391c39af31074ef5bdc2d6159b --- /dev/null +++ b/lean/OAI/Probability/MemoryPrecision/ZeroHorizon.lean @@ -0,0 +1,80 @@ +import Mathlib +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.MemoryPrecision.RealStream + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise + +noncomputable section +universe u v + + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology Pointwise +namespace MemoryPrecision +open NoiselessRegression NoiselessRegression.Learner + +lemma estimate_zero {d M : ℕ} {Ω : Type u} (L : Learner d M 0 Ω) + (s : UnitSphere d) (ω : Ω) (x : Samples d 0) : + L.estimate s ω x = L.output 0 ω (L.initialChoice ω).2 := by + by_cases h : (L.initialChoice ω).1 = true <;> simp [estimate, terminal, run, start, h] + +lemma frozen_chord_zero {d M : ℕ} {Ω : Type u} (L : Learner d M 0 Ω) + (ω : Ω) (hd : 1 ≤ d) {ε : ℝ} (hε : 0 < ε) : + ((uniformSphere d).prod (sampleLaw d 0)) + {z | dist z.1.val (L.estimate z.1 ω z.2).val ≤ ε} ≤ + ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1)) := by + let : NeZero d := ⟨by omega⟩ + let y := (L.output 0 ω (L.initialChoice ω).2).val + simp_rw [estimate_zero] + change ((uniformSphere d).prod (sampleLaw d 0)) + (Prod.fst ⁻¹' {s : UnitSphere d | dist s.val y ≤ ε}) ≤ _ + rw [measurePreserving_fst.measure_preimage + (measurableSet_le (measurable_subtype_coe.dist measurable_const) measurable_const).nullMeasurableSet] + have h := ambientSphereLaw_closedBall (E := Space d) y hε (d-1) (by simp) + rw [ambientSphereLaw, Measure.map_apply measurable_subtype_coe Metric.isClosed_closedBall.measurableSet] at h + simpa [uniformSphere, sphereLaw, ENNReal.ofReal_mul, finrank_euclideanSpace_fin, + Metric.closedBall, Set.preimage_ofPred_eq] using h + +lemma chord_zero_bound {d M : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M 0 Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 1 ≤ d) {ε : ℝ} (hε : 0 < ε) : + uniformChordSuccess L ρ ε ≤ ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1)) := by + let : NeZero d := ⟨by omega⟩ + have hp := ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d 0) (ν := ρ))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d 0) ρ) + let S := {z : UnitSphere d × (Ω × Samples d 0) | + dist (L.estimate z.1 z.2.1 z.2.2).val z.1.val ≤ ε} + have hS : NullMeasurableSet S ((uniformSphere d).prod (ρ.prod (sampleLaw d 0))) := + nullMeasurableSet_le + ((measurable_subtype_coe.comp_aemeasurable hL.uniform_experiment).dist + (measurable_subtype_coe.comp measurable_fst).aemeasurable) aemeasurable_const + have he := hp.measure_preimage hS + have hb := prod_null_set_bound (hS.preimage hp.quasiMeasurePreserving) + (c := ENNReal.ofReal ((3*4^d:ℝ)*ε^(d-1))) + (by + filter_upwards [] with ω + change ((uniformSphere d).prod (sampleLaw d 0)) + {z | dist (L.estimate z.1 ω z.2).val z.1.val ≤ ε} ≤ _ + simpa only [dist_comm] using frozen_chord_zero L ω hd hε) + simpa only [he, measure_univ, mul_one, S, uniformChordSuccess] using hb + +lemma angular_event_subset_chord {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) (ε : ℝ) : + {z : UnitSphere d × (Ω × Samples d T) | + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} ⊆ + {z | dist (L.estimate z.1 z.2.1 z.2.2).val z.1.val ≤ ε} := by + intro z hz + exact le_trans (chord_le_arccos (L.estimate z.1 z.2.1 z.2.2) z.1) hz +lemma angular_le_chord {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) (ε : ℝ) : + L.uniformSuccess ρ ε ≤ uniformChordSuccess L ρ ε := + measure_mono (angular_event_subset_chord L ε) +end MemoryPrecision + + +end + +end OAI diff --git a/lean/OAI/Probability/Moments/LineExpansion.lean b/lean/OAI/Probability/Moments/LineExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..064831c85ae6d75ef35e70c27e612feb6f2bfb9f --- /dev/null +++ b/lean/OAI/Probability/Moments/LineExpansion.lean @@ -0,0 +1,939 @@ +import Mathlib + +namespace OAI + +noncomputable section +open scoped BigOperators Matrix.Norms.L2Operator ComplexOrder +attribute [local instance] Classical.propDecidable +noncomputable section +open scoped BigOperators +attribute [local instance] Classical.propDecidable +noncomputable section +open scoped BigOperators +open MvPolynomial +namespace CoordinateSweeps.MomentExpansion +variable {L : Type*} [Fintype L] [DecidableEq L] + +/- The moment functional of independent line variables, defined algebraically +so only the finitely many moments actually used need be integrable. -/ +def tensorMoment (m : L → ℕ → ℝ) : MvPolynomial L ℝ →ₗ[ℝ] ℝ := + (MvPolynomial.basisMonomials L ℝ).constr ℝ (fun d => ∏ l, m l (d l)) + +omit [DecidableEq L] in +@[simp] theorem tensorMoment_monomial (m : L → ℕ → ℝ) (d : L →₀ ℕ) (a : ℝ) : + tensorMoment m (monomial d a) = a * ∏ l, m l (d l) := by + have hh : monomial d a = a • (MvPolynomial.basisMonomials L ℝ) d := by + rw [MvPolynomial.coe_basisMonomials] + rw [← map_smul] + simp + rw [hh, map_smul] + change a • (((MvPolynomial.basisMonomials L ℝ).constr ℝ) + (fun d => ∏ l, m l (d l))) ((MvPolynomial.basisMonomials L ℝ) d) = _ + rw [Module.Basis.constr_basis, smul_eq_mul] + +omit [DecidableEq L] in +@[simp] theorem tensorMoment_one (m : L → ℕ → ℝ) (hm : ∀ l, m l 0 = 1) : + tensorMoment m 1 = 1 := by + rw [MvPolynomial.one_def, tensorMoment_monomial] + simp [hm] + +omit [DecidableEq L] in +theorem tensorMoment_sum (m : L → ℕ → ℝ) (p : MvPolynomial L ℝ) : + tensorMoment m p = ∑ d ∈ p.support, p.coeff d * ∏ l, m l (d l) := by + conv_lhs => rw [p.as_sum] + simp only [map_sum, tensorMoment_monomial] + +/- Multiplicativity is asserted ONLY across disjoint sets of line variables. -/ +omit [DecidableEq L] in +theorem tensorMoment_mul_disjoint (m : L → ℕ → ℝ) (hm : ∀ l, m l 0 = 1) + (p q : MvPolynomial L ℝ) (hd : Disjoint p.vars q.vars) : + tensorMoment m (p*q) = tensorMoment m p * tensorMoment m q := by + conv_lhs => rw [p.as_sum, q.as_sum] + simp only [Finset.sum_mul, Finset.mul_sum, map_sum, monomial_mul_monomial, tensorMoment_monomial] + rw [tensorMoment_sum, tensorMoment_sum, Finset.sum_mul, Finset.sum_comm] + apply Finset.sum_congr rfl + intro d hd' + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he' + have heq : ∀ l, m l ((d+e) l) = m l (d l) * m l (e l) := by + intro l + by_cases hdl : d l = 0 + · simp [hdl, hm] + · have hdp : l ∈ p.vars := p.support_subset_vars_of_mem_support hd' + (Finsupp.mem_support_iff.mpr hdl) + have hnot : l ∉ q.vars := fun he => Finset.disjoint_left.mp hd hdp he + have hel := MvPolynomial.mem_support_notMem_vars_zero he' hnot + simp [hel, hm] + simp only [heq, Finset.prod_mul_distrib] + ring + +/- One-variable powers really have just the specified one-line moment. -/ +omit [DecidableEq L] in +theorem tensorMoment_X_pow (m : L → ℕ → ℝ) (hm : ∀ l, m l 0 = 1) (l : L) (n : ℕ) : + tensorMoment m (X l ^ n) = m l n := by + rw [X_pow_eq_monomial, tensorMoment_monomial, one_mul] + rw [Finset.prod_eq_single l] + · simp + · intro a _ ha + simp [ha, hm] + · simp + +/- Factorization of arbitrary polynomials, one for each distinct line. -/ +theorem tensorMoment_prod_separated (m : L → ℕ → ℝ) (hm : ∀ l, m l 0 = 1) + (S : Finset L) (p : L → MvPolynomial L ℝ) (hp : ∀ l ∈ S, (p l).vars ⊆ {l}) : + tensorMoment m (∏ l ∈ S, p l) = ∏ l ∈ S, tensorMoment m (p l) := by + induction S using Finset.induction_on with + | empty => simp [tensorMoment_one m hm] + | @insert l S hl ih => + rw [Finset.prod_insert hl, tensorMoment_mul_disjoint m hm, + Finset.prod_insert hl, ih (fun a ha => hp a (Finset.mem_insert_of_mem ha))] + apply Finset.disjoint_left.mpr + intro a ha hb + have hal : a = l := Finset.mem_singleton.mp (hp l (Finset.mem_insert_self _ _) ha) + subst a + have hv := MvPolynomial.vars_prod p hb + simp only [Finset.mem_biUnion] at hv + obtain ⟨a,ha,hla⟩ := hv + have hla' : l = a := Finset.mem_singleton.mp (hp a (Finset.mem_insert_of_mem ha) hla) + exact hl (hla'.symm ▸ ha) + +/- The exact linear functional for a fixed subset of the non-good paths. +Translation by -1 retains all correlations between repeated uses of a line. -/ +def shiftedMoment (m : L → ℕ → ℝ) (r : L → ℕ) : MvPolynomial L ℝ →ₗ[ℝ] ℝ := + (tensorMoment m).comp + ((LinearMap.mulLeft ℝ (∏ l, (X l : MvPolynomial L ℝ)^r l)).comp + (MvPolynomial.aeval (fun l => (X l : MvPolynomial L ℝ)-1)).toLinearMap) + +def lineCenteredMoment (m : L → ℕ → ℝ) (l : L) (r u : ℕ) : ℝ := + ∑ a ∈ Finset.range (u+1), (-1 : ℝ)^(a+u) * (u.choose a : ℝ) * m l (r+a) + +end CoordinateSweeps.MomentExpansion + +namespace CoordinateSweeps.MomentExpansion +variable {L : Type*} [Fintype L] [DecidableEq L] + +omit [Fintype L] in +theorem vars_X_centered_power (l : L) (r u : ℕ) : + (((X l : MvPolynomial L ℝ)^r) * (X l - 1)^u).vars ⊆ {l} := by + apply (MvPolynomial.vars_mul _ _).trans + apply Finset.union_subset + · exact (MvPolynomial.vars_pow _ _).trans (by simp) + · apply (MvPolynomial.vars_pow _ _).trans + exact (MvPolynomial.vars_sub_subset (p := (X l : MvPolynomial L ℝ)) (q := 1)).trans (by simp) + +omit [DecidableEq L] in +theorem tensorMoment_X_centered_power (m : L → ℕ → ℝ) (hm : ∀ l, m l 0 = 1) + (l : L) (r u : ℕ) : + tensorMoment m ((X l : MvPolynomial L ℝ)^r * (X l-1)^u) = + lineCenteredMoment m l r u := by + rw [sub_pow, Finset.mul_sum, map_sum] + unfold lineCenteredMoment + apply Finset.sum_congr rfl + intro a _ + have ht : (X l : MvPolynomial L ℝ)^r * + ((-1)^(a+u) * X l^a * 1^(u-a) * (u.choose a : MvPolynomial L ℝ)) = + (((-1 : ℝ)^(a+u) * (u.choose a : ℝ)) • (X l : MvPolynomial L ℝ)^(r+a)) := by + rw [Algebra.smul_def, map_mul, map_pow, map_neg, map_one, map_natCast, pow_add] + ring + rw [ht, map_smul, tensorMoment_X_pow m hm, smul_eq_mul] + +/- Repeated uses of one line are collected into a SINGLE mixed centered moment. -/ +theorem shiftedMoment_monomial (m : L → ℕ → ℝ) (hm : ∀ l, m l 0 = 1) + (r : L → ℕ) (d : L →₀ ℕ) (a : ℝ) : + shiftedMoment m r (monomial d a) = a * ∏ l, lineCenteredMoment m l (r l) (d l) := by + unfold shiftedMoment + simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, LinearMap.mulLeft_apply, + MvPolynomial.aeval_monomial] + rw [Finsupp.prod_fintype d _ (by simp)] + have he : (∏ l, (X l : MvPolynomial L ℝ)^r l) * + ((algebraMap ℝ (MvPolynomial L ℝ)) a * ∏ l, (X l-1)^d l) = + a • (∏ l, (X l : MvPolynomial L ℝ)^r l * (X l-1)^d l) := by + rw [Finset.prod_mul_distrib, Algebra.smul_def] + ring + rw [he, map_smul, tensorMoment_prod_separated m hm _ _ (fun l _ => vars_X_centered_power l _ _)] + simp only [tensorMoment_X_centered_power m hm, smul_eq_mul] + +/- Coefficientwise nonnegativity, used only for the positive centered expansion. -/ +def NonnegCoeffs (p : MvPolynomial L ℝ) : Prop := ∀ d, 0 ≤ p.coeff d + +omit [Fintype L] in +theorem nonnegCoeffs_one : NonnegCoeffs (1 : MvPolynomial L ℝ) := by + intro d + simp only [coeff_one] + split_ifs <;> norm_num + +omit [Fintype L] [DecidableEq L] in +theorem NonnegCoeffs.add {p q : MvPolynomial L ℝ} (hp : NonnegCoeffs p) (hq : NonnegCoeffs q) : + NonnegCoeffs (p+q) := by + intro d + exact add_nonneg (hp d) (hq d) + +omit [Fintype L] in +theorem NonnegCoeffs.mul {p q : MvPolynomial L ℝ} (hp : NonnegCoeffs p) (hq : NonnegCoeffs q) : + NonnegCoeffs (p*q) := by + intro d + rw [coeff_mul] + exact Finset.sum_nonneg (fun e _ => mul_nonneg (hp e.1) (hq e.2)) + +omit [Fintype L] in +theorem nonnegCoeffs_X (l : L) : NonnegCoeffs (X l : MvPolynomial L ℝ) := by + intro d + simp only [coeff_X] + split_ifs <;> norm_num + +omit [Fintype L] [DecidableEq L] in +theorem nonnegCoeffs_prod {I : Type*} (S : Finset I) (p : I → MvPolynomial L ℝ) + (hp : ∀ i ∈ S, NonnegCoeffs (p i)) : NonnegCoeffs (∏ i ∈ S, p i) := by + classical + induction S using Finset.induction_on with + | empty => simpa using (nonnegCoeffs_one (L := L)) + | @insert i S hi ih => + rw [Finset.prod_insert hi] + exact (hp i (Finset.mem_insert_self _ _)).mul (ih (fun j hj => hp j (Finset.mem_insert_of_mem hj))) + +omit [Fintype L] [DecidableEq L] in +theorem nonnegCoeffs_sum {I : Type*} (S : Finset I) (p : I → MvPolynomial L ℝ) + (hp : ∀ i ∈ S, NonnegCoeffs (p i)) : NonnegCoeffs (∑ i ∈ S, p i) := by + intro d + rw [coeff_sum] + exact Finset.sum_nonneg (fun i hi => hp i hi d) + +/- Exact tensor moment estimate. Its potential premise is local in each +line and each used degree, not independence of particle factors. -/ +theorem shiftedMoment_abs_le_eval (m : L → ℕ → ℝ) (hm : ∀ l, m l 0 = 1) + (r : L → ℕ) (p : MvPolynomial L ℝ) (hp : NonnegCoeffs p) + (C t : ℝ) + (hb : ∀ d ∈ p.support, ∀ l, + |lineCenteredMoment m l (r l) (d l)| ≤ C^(r l) * t^(d l)) : + |shiftedMoment m r p| ≤ C^(∑ l, r l) * MvPolynomial.eval (fun _ => t) p := by + conv_lhs => rw [p.as_sum] + rw [map_sum] + calc + _ ≤ ∑ d ∈ p.support, |shiftedMoment m r (monomial d (p.coeff d))| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ d ∈ p.support, p.coeff d * ∏ l, (C^(r l) * t^(d l)) := by + apply Finset.sum_le_sum + intro d hd + rw [shiftedMoment_monomial m hm, abs_mul, abs_of_nonneg (hp d), Finset.abs_prod] + exact mul_le_mul_of_nonneg_left + (Finset.prod_le_prod₀ (fun _ _ => abs_nonneg _) (fun l _ => hb d hd l)) (hp d) + _ = C^(∑ l, r l) * MvPolynomial.eval (fun _ => t) p := by + conv_rhs => rw [p.as_sum] + rw [map_sum, Finset.mul_sum] + apply Finset.sum_congr rfl + intro d _ + rw [MvPolynomial.eval_monomial, Finsupp.prod_fintype d _ (by simp), + Finset.prod_mul_distrib, Finset.prod_pow_eq_pow_sum] + ring + +end CoordinateSweeps.MomentExpansion + +namespace CoordinateSweeps.MomentExpansion +variable {L : Type*} [Fintype L] [DecidableEq L] +variable {I J : Type*} [DecidableEq I] [Fintype J] [DecidableEq J] + +/- Positive expansion for a centered particle factor. This is a sum over +NONEMPTY subsets of its stages; no independence of particle factors is used. -/ +def pathExpansion (S : Finset J) (f : J → L) : MvPolynomial L ℝ := + ∑ T ∈ S.powerset.erase ∅, ∏ j ∈ T, X (f j) + +omit [Fintype L] [DecidableEq L] [Fintype J] in +theorem pathExpansion_eq (S : Finset J) (f : J → L) : + pathExpansion S f = (∏ j ∈ S, ((X (f j) : MvPolynomial L ℝ)+1))-1 := by + have he := Finset.sum_erase_add S.powerset (fun T => ∏ j ∈ T, (X (f j) : MvPolynomial L ℝ)) + (Finset.empty_mem_powerset S) + simp only [Finset.prod_empty] at he + unfold pathExpansion + rw [Finset.prod_add_one] + exact eq_sub_of_add_eq he + +omit [Fintype L] [Fintype J] in +theorem pathExpansion_nonneg (S : Finset J) (f : J → L) : + NonnegCoeffs (pathExpansion S f) := by + exact nonnegCoeffs_sum _ _ (fun T _ => nonnegCoeffs_prod T _ (fun j _ => nonnegCoeffs_X _)) + +omit [Fintype L] [Fintype J] in +theorem pathExpansion_degree (S : Finset J) (f : J → L) (l : L) : + (pathExpansion S f).degreeOf l ≤ ∑ j ∈ S, if f j = l then 1 else 0 := by + rw [pathExpansion_eq] + apply (MvPolynomial.degreeOf_sub_le _ _ _).trans + rw [MvPolynomial.degreeOf_one, max_eq_left (Nat.zero_le _)] + apply (MvPolynomial.degreeOf_prod_le _ _ _).trans + apply Finset.sum_le_sum + intro j _ + have hd := MvPolynomial.degreeOf_add_le l (X (f j) : MvPolynomial L ℝ) 1 + simpa only [MvPolynomial.degreeOf_one, MvPolynomial.degreeOf_X, eq_comm, + max_eq_left (Nat.zero_le _)] using hd + +omit [Fintype L] [DecidableEq L] [Fintype J] in +theorem pathExpansion_eval (S : Finset J) (f : J → L) (t : ℝ) : + MvPolynomial.eval (fun _ => t) (pathExpansion S f) = (1+t)^S.card-1 := by + rw [pathExpansion_eq] + simp [add_comm] + +omit [Fintype L] [DecidableEq L] [Fintype J] in +theorem pathExpansion_shift (S : Finset J) (f : J → L) : + MvPolynomial.aeval (fun l => (X l : MvPolynomial L ℝ)-1) (pathExpansion S f) = + (∏ j ∈ S, (X (f j) : MvPolynomial L ℝ))-1 := by + rw [pathExpansion_eq] + simp + +/- Combined centered expansion, with the actual same variable on a shared line. -/ +def goodExpansion (G : Finset I) (path : I → J → L) : MvPolynomial L ℝ := + ∏ i ∈ G, pathExpansion Finset.univ (path i) + +omit [Fintype L] [DecidableEq I] in +theorem goodExpansion_nonneg (G : Finset I) (path : I → J → L) : + NonnegCoeffs (goodExpansion G path) := by + exact nonnegCoeffs_prod _ _ (fun i _ => pathExpansion_nonneg _ _) + +omit [Fintype L] [DecidableEq I] in +theorem goodExpansion_degree (G : Finset I) (path : I → J → L) (l : L) : + (goodExpansion G path).degreeOf l ≤ ∑ i ∈ G, ∑ j : J, if path i j = l then 1 else 0 := by + exact (MvPolynomial.degreeOf_prod_le _ _ _).trans + (Finset.sum_le_sum (fun _ _ => pathExpansion_degree _ _ _)) + +omit [Fintype L] [DecidableEq L] [DecidableEq I] in +theorem goodExpansion_eval (G : Finset I) (path : I → J → L) (t : ℝ) : + MvPolynomial.eval (fun _ => t) (goodExpansion G path) = + ((1+t)^Fintype.card J-1)^G.card := by + simp [goodExpansion, pathExpansion_eval] + +/- Uniform estimate for (1+C*x)^b-1, retaining one small factor per particle. -/ +theorem centered_power_le (C x : ℝ) (hC : 0 ≤ C) (hx : 0 ≤ x) (hx1 : x ≤ 1) (b : ℕ) : + (1+C*x)^b-1 ≤ ((1+C)^b-1)*x := by + induction b with + | zero => simp + | succ b ih => + have hCx : 0 ≤ C*x := mul_nonneg hC hx + have hb : 1 ≤ (1+C)^b := one_le_pow₀ (by linarith) + have hsmall : C*x ≤ C := mul_le_of_le_one_right hC hx1 + have hmul := mul_le_mul_of_nonneg_right ih (by linarith : 0 ≤ 1+C*x) + have her : ((1+C)^b-1)*x*(1+C*x) ≤ ((1+C)^b-1)*x*(1+C) := by + exact mul_le_mul_of_nonneg_left (by linarith) (mul_nonneg (by linarith) hx) + rw [pow_succ, pow_succ] + nlinarith + +omit [Fintype L] [DecidableEq L] [DecidableEq I] in +theorem goodExpansion_eval_le (G : Finset I) (path : I → J → L) + (C x : ℝ) (hC : 0 ≤ C) (hx : 0 ≤ x) (hx1 : x ≤ 1) : + MvPolynomial.eval (fun _ => C*x) (goodExpansion G path) ≤ + (1+C)^(Fintype.card J*G.card) * x^G.card := by + rw [goodExpansion_eval] + have h1 : 1 ≤ (1+C*x)^Fintype.card J := one_le_pow₀ (by nlinarith) + have he := centered_power_le C x hC hx hx1 (Fintype.card J) + have hu : ((1+C)^Fintype.card J-1)*x ≤ (1+C)^Fintype.card J*x := by nlinarith + calc + _ ≤ ((1+C)^Fintype.card J*x)^G.card := + pow_le_pow_left₀ (sub_nonneg.mpr h1) (he.trans hu) _ + _ = _ := by rw [mul_pow, ← pow_mul] + +/- Core shared-line estimate behind source (10), before inserting the actual +gamma moments. Each line degree is limited by the count of good trajectories +through it, and each good path supplies a factor sqrt(eta). -/ +omit [DecidableEq I] in +theorem goodExpansion_moment_le (m : L → ℕ → ℝ) (hm : ∀ l, m l 0 = 1) + (r : L → ℕ) (G : Finset I) (path : I → J → L) + (C x : ℝ) (hC : 0 ≤ C) (hx : 0 ≤ x) (hx1 : x ≤ 1) + (hb : ∀ l u, u ≤ (∑ i ∈ G, ∑ j : J, if path i j = l then 1 else 0) → + |lineCenteredMoment m l (r l) u| ≤ C^(r l) * (C*x)^u) : + |shiftedMoment m r (goodExpansion G path)| ≤ + C^(∑ l, r l) * (1+C)^(Fintype.card J*G.card) * x^G.card := by + have he := shiftedMoment_abs_le_eval m hm r (goodExpansion G path) + (goodExpansion_nonneg G path) C (C*x) (by + intro d hd l + exact hb l (d l) ((MvPolynomial.monomial_le_degreeOf l hd).trans + (goodExpansion_degree G path l))) + exact he.trans ((mul_le_mul_of_nonneg_left + (goodExpansion_eval_le G path C x hC hx hx1) (pow_nonneg hC _)).trans_eq (by ring)) + +end CoordinateSweeps.MomentExpansion + +namespace CoordinateSweeps.MomentExpansion +variable {L : Type*} [Fintype L] [DecidableEq L] +variable {I J : Type*} [DecidableEq I] [Fintype J] [DecidableEq J] + +def incidenceCount (A : Finset I) (path : I → J → L) (l : L) : ℕ := + ∑ i ∈ A, ∑ j : J, if path i j = l then 1 else 0 + +/- A monomial counts line uses, including simultaneous uses by distinct paths. -/ +omit [DecidableEq I] [DecidableEq J] in +theorem tensorMoment_path_monomial (m : L → ℕ → ℝ) (r : L → ℕ) + (A : Finset I) (path : I → J → L) : + tensorMoment m ((∏ l, (X l : MvPolynomial L ℝ)^r l) * + ∏ i ∈ A, ∏ j : J, X (path i j)) = + ∏ l, m l (r l+incidenceCount A path l) := by + have hr : (∏ l, (X l : MvPolynomial L ℝ)^r l) = + monomial (∑ l, Finsupp.single l (r l)) 1 := by + rw [MvPolynomial.monomial_sum_one] + apply Finset.prod_congr rfl + intro l _ + exact X_pow_eq_monomial + have hp : (∏ i ∈ A, ∏ j : J, (X (path i j) : MvPolynomial L ℝ)) = + monomial (∑ i ∈ A, ∑ j : J, Finsupp.single (path i j) 1) 1 := by + rw [MvPolynomial.monomial_sum_one] + apply Finset.prod_congr rfl + intro i _ + rw [MvPolynomial.monomial_sum_one] + rfl + rw [hr, hp, MvPolynomial.monomial_mul_monomial, one_mul, tensorMoment_monomial, one_mul] + apply Finset.prod_congr rfl + intro l _ + congr 1 + simp [incidenceCount, Finsupp.single_apply, eq_comm] + +/- Exact alternation identity. The summation set is the omitted subset of good +particles, so its sign is (-1)^|A|. This is source (10)'s inside-expectation +formula, with all shared-line correlations retained by the linear functional. -/ +theorem shiftedMoment_goodExpansion_eq (m : L → ℕ → ℝ) (r : L → ℕ) + (G : Finset I) (path : I → J → L) : + shiftedMoment m r (goodExpansion G path) = + ∑ A ∈ G.powerset, (-1 : ℝ)^A.card * ∏ l, m l (r l+incidenceCount (G\A) path l) := by + unfold shiftedMoment + simp only [LinearMap.comp_apply, AlgHom.toLinearMap_apply, LinearMap.mulLeft_apply, + goodExpansion, map_prod, pathExpansion_shift] + rw [Finset.prod_sub, Finset.mul_sum, map_sum] + apply Finset.sum_congr rfl + intro A _ + simp only [Finset.prod_const_one, mul_one] + have he : (∏ l, (X l : MvPolynomial L ℝ)^r l) * + ((-1 : MvPolynomial L ℝ)^A.card * + ∏ i ∈ G\A, ∏ j : J, X (path i j)) = + (-1 : ℝ)^A.card • ((∏ l, (X l : MvPolynomial L ℝ)^r l) * + ∏ i ∈ G\A, ∏ j : J, X (path i j)) := by + rw [Algebra.smul_def, map_pow, map_neg, map_one] + ring + rw [he, map_smul, tensorMoment_path_monomial, smul_eq_mul] + +end CoordinateSweeps.MomentExpansion + +/- Gamma-moment support. -/ + +/- The analytic light-line obligation 04-sparse.tex (11). The distribution +is exactly Mathlib's Gamma(shape, unit rate), not an assumed random variable. -/ +noncomputable section +open MeasureTheory ProbabilityTheory Real Set Filter +open scoped ENNReal NNReal BigOperators + +namespace CoordinateSweeps + +theorem integral_gamma_eq {a r : ℝ} (ha : 0 < a) (hr : 0 < r) (f : ℝ → ℝ) : + (∫ x, f x ∂gammaMeasure a r) = + ∫ x in Ioi 0, (r^a / Gamma a * x^(a-1) * exp (-(r*x))) * f x := by + rw [gammaMeasure] + change (∫ x, f x ∂volume.withDensity (fun x => ENNReal.ofReal (gammaPDFReal a r x))) = _ + rw [integral_withDensity_eq_integral_toReal_smul + ((measurable_gammaPDFReal a r).ennreal_ofReal) (ae_of_all _ (fun _ => ENNReal.ofReal_lt_top))] + simp only [ENNReal.toReal_ofReal (gammaPDFReal_nonneg ha hr _), smul_eq_mul] + have he : (fun x => gammaPDFReal a r x * f x) = + (Ici 0).indicator (fun x => (r^a / Gamma a * x^(a-1) * exp (-(r*x))) * f x) := by + funext x + by_cases hx : 0 ≤ x <;> simp [gammaPDFReal, hx, indicator_of_mem, indicator_of_notMem] + rw [he, integral_indicator measurableSet_Ici, integral_Ici_eq_integral_Ioi] + +theorem gamma_mgf {a t : ℝ} (ha : 0 < a) (ht : t < 1) : + (∫ x, exp (t*x) ∂gammaMeasure a 1) = (1/(1-t))^a := by + rw [integral_gamma_eq ha zero_lt_one] + simp only [one_rpow, one_mul] + have he : (fun x : ℝ => (1 / Gamma a * x^(a-1) * exp (-x)) * exp (t*x)) = + fun x => (1 / Gamma a) * (x^(a-1) * exp (-((1-t)*x))) := by + funext x + rw [mul_assoc, mul_assoc, ← exp_add] + congr 3 + ring + rw [he, integral_const_mul, integral_rpow_mul_exp_neg_mul_Ioi ha (sub_pos.mpr ht)] + field_simp [(Gamma_pos_of_pos ha).ne'] + +theorem gamma_mgf_integrable {a t : ℝ} (ha : 0 < a) (ht : t < 1) : + Integrable (fun x => exp (t*x)) (gammaMeasure a 1) := by + apply Integrable.of_integral_ne_zero + rw [gamma_mgf ha ht] + exact (rpow_pos_of_pos (one_div_pos.mpr (sub_pos.mpr ht)) _).ne' + +theorem gamma_centered_mgf {a t : ℝ} (ha : 0 < a) (ht : t < 1) : + (∫ x, exp (t*(x-a)) ∂gammaMeasure a 1) = exp (a*(-t-log (1-t))) := by + have he : (fun x => exp (t*(x-a))) = fun x => exp (-t*a) * exp (t*x) := by + funext x + rw [← exp_add] + congr 1 + ring + rw [he, integral_const_mul, gamma_mgf ha ht, + rpow_def_of_pos (one_div_pos.mpr (sub_pos.mpr ht)), ← exp_add, + one_div, log_inv] + congr 1 + ring + +theorem gamma_centered_mgf_integrable {a t : ℝ} (ha : 0 < a) (ht : t < 1) : + Integrable (fun x => exp (t*(x-a))) (gammaMeasure a 1) := by + apply Integrable.of_integral_ne_zero + rw [gamma_centered_mgf ha ht] + exact (exp_pos _).ne' + +theorem log_mgf_bound {t : ℝ} (ht : |t| ≤ 1/2) : -t - log (1-t) ≤ 2*t^2 := by + have ht1 : |t| < 1 := by linarith + have hh := abs_log_sub_add_sum_range_le ht1 1 + norm_num at hh + have hb : |t|^2 / (1-|t|) ≤ 2*t^2 := by + apply (div_le_iff₀ (by linarith : 0 < 1-|t|)).mpr + rw [sq_abs] + nlinarith [sq_nonneg t] + rw [sq_abs] at hb + have hl := neg_le_abs (t + log (1-t)) + linarith + +theorem gamma_centered_mgf_le {a t : ℝ} (ha : 0 < a) (ht : |t| ≤ 1/2) : + (∫ x, exp (t*(x-a)) ∂gammaMeasure a 1) ≤ exp (2*a*t^2) := by + rw [gamma_centered_mgf ha (by have := le_abs_self t; linarith)] + apply exp_le_exp.mpr + nlinarith [mul_le_mul_of_nonneg_left (log_mgf_bound ht) ha.le] + +/- Pointwise exponential domination, used to obtain the actual centered +moments without a separate probabilistic Chernoff axiom. -/ +theorem abs_pow_le_exp_sum (x : ℝ) (u : ℕ) {t : ℝ} (ht : 0 < t) : + |x|^u ≤ ((u : ℝ)/t)^u * (exp (t*x) + exp (-t*x)) := by + have hp := rpow_abs_le_mul_max_exp_of_pos x (Nat.cast_nonneg u) ht + rw [rpow_natCast, rpow_natCast] at hp + apply hp.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact max_le (le_add_of_nonneg_right (exp_nonneg _)) + (le_add_of_nonneg_left (exp_nonneg _)) + +theorem abs_pow_integrable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {X : Ω → ℝ} (hX : AEMeasurable X μ) (u : ℕ) {t : ℝ} (ht : 0 < t) + (hp : Integrable (fun x => exp (t * X x)) μ) + (hn : Integrable (fun x => exp (-t * X x)) μ) : + Integrable (fun x => |X x|^u) μ := by + apply ((hp.add hn).const_mul (((u : ℝ)/t)^u)).mono' + · exact (hX.abs.pow_const u).aestronglyMeasurable + · filter_upwards [] with x + simpa only [Real.norm_eq_abs, abs_pow, abs_abs, Pi.add_apply] using abs_pow_le_exp_sum (X x) u ht + +theorem abs_pow_integral_le {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {X : Ω → ℝ} (hX : AEMeasurable X μ) (u : ℕ) {t : ℝ} (ht : 0 < t) + (hp : Integrable (fun x => exp (t * X x)) μ) + (hn : Integrable (fun x => exp (-t * X x)) μ) : + (∫ x, |X x|^u ∂μ) ≤ ((u : ℝ)/t)^u * + ((∫ x, exp (t*X x) ∂μ) + (∫ x, exp (-t*X x) ∂μ)) := by + calc + _ ≤ ∫ x, ((u : ℝ)/t)^u * (exp (t*X x) + exp (-t*X x)) ∂μ := + integral_mono (abs_pow_integrable hX u ht hp hn) + ((hp.add hn).const_mul _) (fun x => abs_pow_le_exp_sum (X x) u ht) + _ = _ := by rw [integral_const_mul, integral_add hp hn] + +/- A centered gamma moment in the range needed by every light line. -/ +theorem gamma_abs_centered_moment_le {a : ℝ} (ha : 0 < a) {u : ℕ} + (hu : 1 ≤ u) (hua : 4*(u : ℝ) ≤ a) : + (∫ x, |x-a|^u ∂gammaMeasure a 1) ≤ + (2 * exp 2 * Real.sqrt (a*u))^u := by + let t := Real.sqrt ((u : ℝ)/a) + have hu0 : (0 : ℝ) < u := by exact_mod_cast hu + have ht : 0 < t := Real.sqrt_pos.mpr (div_pos hu0 ha) + have ht2 : t^2 = (u : ℝ)/a := Real.sq_sqrt (by positivity) + have ht_half : t ≤ 1/2 := by + have hh : (u : ℝ)/a ≤ 1/4 := (div_le_iff₀ ha).mpr (by linarith) + nlinarith + have htab : |t| ≤ 1/2 := by rw [abs_of_pos ht]; exact ht_half + have hp := gamma_centered_mgf_integrable ha (show t < 1 by linarith) + have hn := gamma_centered_mgf_integrable ha (show -t < 1 by linarith) + have hh := abs_pow_integral_le + (X := fun x : ℝ => x-a) (by fun_prop) u ht hp hn + have hplus := gamma_centered_mgf_le ha htab + have hminus := gamma_centered_mgf_le ha (t := -t) (by simpa only [abs_neg] using htab) + have hat : a*t^2 = (u : ℝ) := by rw [ht2]; field_simp + have hratio : (u : ℝ)/t = Real.sqrt (a*u) := by + have ht0 : t ≠ 0 := ht.ne' + have he : (u : ℝ)/t * ((u : ℝ)/t) = a*u := by + field_simp + nlinarith [hat] + have hs := Real.sq_sqrt (show 0 ≤ a*(u : ℝ) by positivity) + have hr : 0 ≤ (u : ℝ)/t := by positivity + nlinarith [he, Real.sqrt_nonneg (a*u)] + calc + _ ≤ ((u : ℝ)/t)^u * (exp (2*a*t^2) + exp (2*a*(-t)^2)) := + hh.trans (mul_le_mul_of_nonneg_left (add_le_add hplus hminus) (by positivity)) + _ = 2 * (exp 2 * Real.sqrt (a*u))^u := by + rw [hratio, neg_sq] + have he : 2*a*t^2 = 2*(u : ℝ) := by nlinarith [hat] + rw [he, mul_comm (2 : ℝ) (u : ℝ), exp_nat_mul, mul_pow] + ring + _ ≤ (2 * exp 2 * Real.sqrt (a*u))^u := by + have htwo : (2 : ℝ) ≤ 2^u := by + simpa using (pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 2) hu) + calc + _ ≤ 2^u * (exp 2 * Real.sqrt (a*u))^u := + mul_le_mul_of_nonneg_right htwo (by positivity) + _ = _ := by rw [← mul_pow]; congr 1; ring + +/- No restriction at the density's null endpoint is needed. -/ +theorem integral_gamma_congr {a r : ℝ} (ha : 0 < a) (hr : 0 < r) + {f g : ℝ → ℝ} (hfg : ∀ x, 0 < x → f x = g x) : + (∫ x, f x ∂gammaMeasure a r) = ∫ x, g x ∂gammaMeasure a r := by + rw [integral_gamma_eq ha hr, integral_gamma_eq ha hr] + apply setIntegral_congr_fun measurableSet_Ioi + intro x hx + dsimp only + rw [hfg x hx] + +/- The exact inverse-power density tilt used, with all gamma laws concrete. -/ +theorem gamma_inverse_tilt {a m : ℝ} (k : ℕ) (hak : (k : ℝ) < a) + (f : ℝ → ℝ) : + (∫ x, (m/x)^k * f x ∂gammaMeasure a 1) = + (m^k * Gamma (a-k) / Gamma a) * (∫ x, f x ∂gammaMeasure (a-k) 1) := by + have ha : 0 < a := lt_of_le_of_lt (Nat.cast_nonneg k) hak + have ha' : 0 < a-k := sub_pos.mpr hak + rw [integral_gamma_eq ha zero_lt_one, integral_gamma_eq ha' zero_lt_one, + ← integral_const_mul] + apply setIntegral_congr_fun measurableSet_Ioi + intro x hx + dsimp only + have hx0 : x ≠ 0 := ne_of_gt hx + have hp : x^(a-1) = x^((a-k)-1) * x^k := by + rw [← rpow_natCast x k, ← rpow_add hx] + congr 1 + ring + rw [hp] + simp only [one_rpow, one_mul, div_pow] + field_simp [(Gamma_pos_of_pos ha').ne', (Gamma_pos_of_pos ha).ne', hx0] + +/- The gamma-ratio is the exact falling factorial, not an asymptotic. -/ +theorem gamma_ratio_descFactorial {n k : ℕ} (hk : k ≤ n) : + Gamma ((n : ℝ)+1-k) / Gamma ((n : ℝ)+1) = (n.descFactorial k : ℝ)⁻¹ := by + have he : (n : ℝ)+1-k = (n-k : ℕ)+1 := by rw [Nat.cast_sub hk]; ring + rw [he, Gamma_nat_eq_factorial, Gamma_nat_eq_factorial] + have hh : ((n-k).factorial : ℝ) * (n.descFactorial k : ℝ) = n.factorial := by + exact_mod_cast Nat.factorial_mul_descFactorial hk + have hnp : (n.factorial : ℝ) ≠ 0 := by positivity + have hdp : (n.descFactorial k : ℝ) ≠ 0 := by + exact_mod_cast (Nat.descFactorial_pos.mpr hk).ne' + field_simp + exact hh + +/- The first equality of manuscript (11). -/ +theorem gamma_light_line_identity {m h u v : ℕ} (hm : 0 < m) (huv : h+u+v ≤ m) : + (∫ x, ((m : ℝ)/x)^v * |(m : ℝ)/x-1|^u + ∂gammaMeasure ((m-h : ℕ)+1) 1) = + ((m : ℝ)^(u+v) / ((m-h).descFactorial (u+v) : ℝ)) * + (∫ x, |1-x/(m : ℝ)|^u ∂gammaMeasure ((m-h : ℕ)+1-(u+v : ℕ)) 1) := by + have hh : h ≤ m := by omega + have hk : u+v ≤ m-h := by omega + have ha : (0 : ℝ) < (m-h : ℕ)+1 := by positivity + have hak : ((u+v : ℕ) : ℝ) < (m-h : ℕ)+1 := by exact_mod_cast (by omega : u+v < m-h+1) + have he := integral_gamma_congr ha zero_lt_one + (f := fun x => ((m : ℝ)/x)^v * |(m : ℝ)/x-1|^u) + (g := fun x => ((m : ℝ)/x)^(u+v) * |1-x/(m : ℝ)|^u) (by + intro x hx + have hm0 : (m : ℝ) ≠ 0 := by exact_mod_cast hm.ne' + have hx0 : x ≠ 0 := hx.ne' + have hz : (m : ℝ)/x-1 = ((m : ℝ)/x)*(1-x/(m : ℝ)) := by + field_simp + rw [hz, abs_mul, abs_of_pos (div_pos (by exact_mod_cast hm) hx), mul_pow, pow_add] + ring) + rw [he, gamma_inverse_tilt (u+v) hak] + rw [mul_div_assoc, gamma_ratio_descFactorial hk, ← div_eq_mul_inv] + +/- Scale and bias estimate for the tilted gamma law. -/ +theorem gamma_normalized_moment_le {a m η : ℝ} (ha : 0 < a) (hm : 0 < m) + (hη : 0 ≤ η) (hη1 : η ≤ 1) {u : ℕ} (hu : 1 ≤ u) + (hua : 4*(u : ℝ) ≤ a) (ham : a ≤ m) (huη : (u : ℝ) ≤ m*η) + (hbias : |1-a/m| ≤ η) : + (∫ x, |1-x/m|^u ∂gammaMeasure a 1) ≤ + (8 * exp 2 * Real.sqrt η)^u := by + let : IsProbabilityMeasure (gammaMeasure a 1) := isProbabilityMeasure_gammaMeasure ha zero_lt_one + have hu0 : (0 : ℝ) ≤ u := Nat.cast_nonneg u + have hηsqrt : η ≤ Real.sqrt η := by + have hs := Real.sq_sqrt hη + nlinarith [Real.sqrt_nonneg η] + have hcenter : Integrable (fun x : ℝ => |x-a|^u) (gammaMeasure a 1) := + abs_pow_integrable (by fun_prop) u (t := 1/4) (by norm_num) + (gamma_centered_mgf_integrable ha (by norm_num)) + (gamma_centered_mgf_integrable ha (by norm_num)) + have hratio : Real.sqrt (a*u)/m ≤ Real.sqrt η := by + apply (div_le_iff₀ hm).mpr + have hs := Real.sq_sqrt (show 0 ≤ a*(u : ℝ) by positivity) + have hsη := Real.sq_sqrt hη + have hp : a*(u : ℝ) ≤ m^2*η := by + nlinarith [mul_le_mul_of_nonneg_right ham hu0, + mul_le_mul_of_nonneg_left huη hm.le] + have hsq : (Real.sqrt η*m)^2 = m^2*η := by nlinarith [hsη] + nlinarith [Real.sqrt_nonneg (a*u), mul_nonneg (Real.sqrt_nonneg η) hm.le] + let B := 2 * exp 2 * Real.sqrt η + have he1 : (1 : ℝ) ≤ exp 2 := one_le_exp_iff.mpr (by norm_num) + have hB : 0 ≤ B := by dsimp [B]; positivity + have hsB : Real.sqrt η ≤ B := by dsimp [B]; nlinarith [Real.sqrt_nonneg η] + have hcB : (2*exp 2*Real.sqrt (a*u))/m ≤ B := by + calc + _ = (2*exp 2)*(Real.sqrt (a*u)/m) := by ring + _ ≤ B := mul_le_mul_of_nonneg_left hratio (by positivity) + have hmoment : (m^u)⁻¹ * (∫ x, |x-a|^u ∂gammaMeasure a 1) ≤ B^u := by + calc + _ ≤ (m^u)⁻¹ * (2*exp 2*Real.sqrt (a*u))^u := + mul_le_mul_of_nonneg_left (gamma_abs_centered_moment_le ha hu hua) (by positivity) + _ = ((2*exp 2*Real.sqrt (a*u))/m)^u := by rw [div_pow]; ring + _ ≤ B^u := pow_le_pow_left₀ (by positivity) hcB u + have hgint : Integrable (fun x : ℝ => (2 : ℝ)^u * + ((Real.sqrt η)^u + (m^u)⁻¹ * |x-a|^u)) (gammaMeasure a 1) := + ((integrable_const _).add (hcenter.const_mul _)).const_mul _ + have hpt (x : ℝ) : |1-x/m|^u ≤ (2 : ℝ)^u * + ((Real.sqrt η)^u + (m^u)⁻¹ * |x-a|^u) := by + have hde : 1-x/m = (1-a/m) + (-(x-a))/m := by ring + have hh : |1-x/m| ≤ Real.sqrt η + |x-a|/m := by + rw [hde] + apply (abs_add_le _ _).trans + rw [abs_div, abs_neg, abs_of_pos hm] + exact add_le_add (hbias.trans hηsqrt) le_rfl + calc + _ ≤ (Real.sqrt η + |x-a|/m)^u := pow_le_pow_left₀ (abs_nonneg _) hh u + _ ≤ 2^(u-1) * ((Real.sqrt η)^u + (|x-a|/m)^u) := + add_pow_le (Real.sqrt_nonneg _) (by positivity) u + _ ≤ 2^u * ((Real.sqrt η)^u + (|x-a|/m)^u) := by + apply mul_le_mul_of_nonneg_right _ (by positivity) + exact pow_le_pow_right₀ (by norm_num) (Nat.sub_le _ _) + _ = _ := by rw [div_pow]; ring + calc + _ ≤ ∫ x, (2 : ℝ)^u * ((Real.sqrt η)^u + (m^u)⁻¹ * |x-a|^u) + ∂gammaMeasure a 1 := integral_mono_of_nonneg + (ae_of_all _ (fun _ => by positivity)) hgint (ae_of_all _ hpt) + _ = 2^u * ((Real.sqrt η)^u + (m^u)⁻¹ * + (∫ x, |x-a|^u ∂gammaMeasure a 1)) := by + rw [integral_const_mul, integral_add (integrable_const _) (hcenter.const_mul _), + integral_const, integral_const_mul] + simp + _ ≤ 2^u * (B^u + B^u) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact add_le_add (pow_le_pow_left₀ (Real.sqrt_nonneg _) hsB _) hmoment + _ ≤ (8*exp 2*Real.sqrt η)^u := by + have htwo : (2 : ℝ) ≤ 2^u := by + simpa using (pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 2) hu) + calc + _ = 2^u * 2 * B^u := by ring + _ ≤ 2^u * 2^u * B^u := by gcongr + _ = (8*exp 2*Real.sqrt η)^u := by + rw [← mul_pow, ← mul_pow] + congr 1 + dsimp [B] + ring + +/- Uniform bound for the inverse-gamma prefactor, a light line cannot have +more than half of its sites assigned. -/ +theorem light_prefactor_le {m h k : ℕ} (hm : 0 < m) (hk : 2*(h+k) ≤ m) : + (m : ℝ)^k / ((m-h).descFactorial k : ℝ) ≤ 2^k := by + have hkm : k ≤ m-h := by omega + have hpos : (0 : ℝ) < (m-h).descFactorial k := by + exact_mod_cast Nat.descFactorial_pos.mpr hkm + apply (div_le_iff₀ hpos).mpr + rw [Nat.descFactorial_eq_prod_range, Nat.cast_prod] + calc + (m : ℝ)^k = ∏ j ∈ Finset.range k, (m : ℝ) := by simp + _ ≤ ∏ j ∈ Finset.range k, (2 : ℝ)*(m-h-j : ℕ) := by + apply Finset.prod_le_prod₀ + · intro _ _; positivity + · intro j hj + have hjk := Finset.mem_range.mp hj + have hjm : j ≤ m-h := by omega + rw [Nat.cast_sub hjm, Nat.cast_sub (show h ≤ m by omega)] + have hn : (2 : ℝ)*(h+k) ≤ m := by exact_mod_cast hk + have hjr : (j : ℝ) ≤ k := by exact_mod_cast (by omega : j ≤ k) + nlinarith + _ = 2^k * ∏ j ∈ Finset.range k, ((m-h-j : ℕ) : ℝ) := by + rw [Finset.prod_mul_distrib] + simp + +/- The light-line estimate (11), with an explicit absolute constant. -/ +theorem gamma_light_line_bound {m h u v : ℕ} (hm : 0 < m) {η : ℝ} + (hη : 0 ≤ η) (hηsmall : η ≤ 1/8) + (hlight : ((h+u+v : ℕ) : ℝ) ≤ (m : ℝ)*η) : + (∫ x, ((m : ℝ)/x)^v * |(m : ℝ)/x-1|^u + ∂gammaMeasure ((m-h : ℕ)+1) 1) ≤ + (16 * exp 2)^(u+v) * (Real.sqrt η)^u := by + have hm0 : (0 : ℝ) < m := by exact_mod_cast hm + have hmne : (m : ℝ) ≠ 0 := hm0.ne' + have htot : ((h+u+v : ℕ) : ℝ) ≤ (m : ℝ)/8 := by + nlinarith [mul_le_mul_of_nonneg_left hηsmall hm0.le] + have ht : h+u+v ≤ m := by + exact_mod_cast (show ((h+u+v : ℕ) : ℝ) ≤ (m : ℝ) by linarith) + have ht2 : 2*(h+(u+v)) ≤ m := by + have hh : (2 : ℝ)*(h+u+v) ≤ m := by push_cast at htot; linarith + simpa only [Nat.add_assoc] using (show 2*(h+u+v) ≤ m by exact_mod_cast hh) + have hh : h ≤ m := by omega + let a : ℝ := (m-h : ℕ)+1-(u+v : ℕ) + have hae : a = (m : ℝ)-(h+u+v : ℕ)+1 := by + dsimp [a] + rw [Nat.cast_sub hh] + push_cast + ring + have ha : 0 < a := by rw [hae]; linarith + have hnorm : (∫ x, |1-x/(m : ℝ)|^u ∂gammaMeasure a 1) ≤ + (8 * exp 2 * Real.sqrt η)^u := by + by_cases hu : u = 0 + · subst u + let : IsProbabilityMeasure (gammaMeasure a 1) := isProbabilityMeasure_gammaMeasure ha zero_lt_one + simp + · have hu1 : 1 ≤ u := by omega + have huS : (u : ℝ) ≤ (h+u+v : ℕ) := by exact_mod_cast (by omega : u ≤ h+u+v) + have hS1 : (1 : ℝ) ≤ (h+u+v : ℕ) := by exact_mod_cast (by omega : 1 ≤ h+u+v) + have hua : 4*(u : ℝ) ≤ a := by rw [hae]; linarith + have ham : a ≤ m := by rw [hae]; linarith + apply gamma_normalized_moment_le ha hm0 hη (by linarith) hu1 hua ham (huS.trans hlight) + have he : 1-a/(m : ℝ) = ((m : ℝ)-a)/m := by field_simp + rw [he, abs_of_nonneg (div_nonneg (sub_nonneg.mpr ham) hm0.le)] + apply (div_le_iff₀ hm0).mpr + rw [hae] + linarith + rw [gamma_light_line_identity hm ht] + have hpre := light_prefactor_le hm ht2 + change _ * (∫ x, |1-x/(m : ℝ)|^u ∂gammaMeasure a 1) ≤ _ + calc + _ ≤ (2 : ℝ)^(u+v) * (8 * exp 2 * Real.sqrt η)^u := by + apply mul_le_mul hpre hnorm + · exact integral_nonneg (fun _ => by positivity) + · positivity + _ = 2^(u+v) * (8*exp 2)^u * (Real.sqrt η)^u := by rw [mul_pow]; ring + _ ≤ 2^(u+v) * (8*exp 2)^(u+v) * (Real.sqrt η)^u := by + have hC : (1 : ℝ) ≤ 8*exp 2 := by nlinarith [one_le_exp_iff.mpr (show (0 : ℝ) ≤ 2 by norm_num)] + have hp := pow_le_pow_right₀ hC (Nat.le_add_right u v) + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hp (by positivity)) (by positivity) + _ = (16 * exp 2)^(u+v) * (Real.sqrt η)^u := by + rw [← mul_pow] + congr 2 + ring + +/- Exactly the power convention printed in manuscript (11). -/ +theorem gamma_light_line_bound_rpow {m h u v : ℕ} (hm : 0 < m) {η : ℝ} + (hη : 0 ≤ η) (hηsmall : η ≤ 1/8) + (hlight : ((h+u+v : ℕ) : ℝ) ≤ (m : ℝ)*η) : + (∫ x, ((m : ℝ)/x)^v * |(m : ℝ)/x-1|^u + ∂gammaMeasure ((m-h : ℕ)+1) 1) ≤ + (16 * exp 2)^(u+v) * η^((u : ℝ)/2) := by + have he : (Real.sqrt η)^u = η^((u : ℝ)/2) := by + rw [Real.sqrt_eq_rpow, ← Real.rpow_natCast (η^(1/2 : ℝ)) u, + ← Real.rpow_mul hη] + congr 1 + ring + simpa only [he] using gamma_light_line_bound hm hη hηsmall hlight + +end CoordinateSweeps + +namespace CoordinateSweeps.MomentExpansion +open MeasureTheory ProbabilityTheory Real + +/- Source light-line factorial moment, with its exact finite-population shift. -/ +def fallingMoment (m h n : ℕ) : ℝ := (m : ℝ)^n / ((m-h).descFactorial n : ℝ) + +@[simp] theorem fallingMoment_zero (m h : ℕ) : fallingMoment m h 0 = 1 := by + simp [fallingMoment] + +/- The algebraic moment is the ACTUAL inverse-gamma moment in every used degree. -/ +theorem fallingMoment_eq_integral {m h n : ℕ} (hn : n ≤ m-h) : + fallingMoment m h n = + ∫ x, ((m : ℝ)/x)^n ∂gammaMeasure ((m-h : ℕ)+1) 1 := by + have hak : (n : ℝ) < (m-h : ℕ)+1 := by exact_mod_cast (by omega : n < m-h+1) + have ha : (0 : ℝ) < (m-h : ℕ)+1-n := by linarith + let : IsProbabilityMeasure (gammaMeasure ((m-h : ℕ)+1-n) 1) := + isProbabilityMeasure_gammaMeasure ha zero_lt_one + have he := gamma_inverse_tilt (m := (m : ℝ)) n hak (fun _ => (1 : ℝ)) + simp only [mul_one, integral_const, Measure.real, measure_univ, ENNReal.toReal_one, smul_eq_mul, + mul_div_assoc, gamma_ratio_descFactorial hn] at he + simpa only [fallingMoment, div_eq_mul_inv] using he.symm + +theorem fallingMoment_integrable {m h n : ℕ} (hm : 0 < m) (hn : n ≤ m-h) : + Integrable (fun x => ((m : ℝ)/x)^n) (gammaMeasure ((m-h : ℕ)+1) 1) := by + apply Integrable.of_integral_ne_zero + rw [← fallingMoment_eq_integral hn] + apply ne_of_gt + unfold fallingMoment + exact div_pos (pow_pos (by exact_mod_cast hm) _) + (by exact_mod_cast Nat.descFactorial_pos.mpr hn) + +/- Centered finite differences collect all occurrences of the SAME line. -/ +theorem fallingCenteredMoment_eq_integral {L : Type*} (m h : L → ℕ) (l : L) + (hm : 0 < m l) (v u : ℕ) (huv : v+u ≤ m l-h l) : + lineCenteredMoment (fun l => fallingMoment (m l) (h l)) l v u = + ∫ x, ((m l : ℝ)/x)^v * ((m l : ℝ)/x-1)^u + ∂gammaMeasure ((m l-h l : ℕ)+1) 1 := by + have he (a : ℕ) (ha : a ∈ Finset.range (u+1)) : + v+a ≤ m l-h l := by simp only [Finset.mem_range] at ha; omega + have hi (a : ℕ) (ha : a ∈ Finset.range (u+1)) : + Integrable (fun x => (-1 : ℝ)^(a+u) * (u.choose a : ℝ) * ((m l : ℝ)/x)^(v+a)) + (gammaMeasure ((m l-h l : ℕ)+1) 1) := + (fallingMoment_integrable hm (he a ha)).const_mul _ + unfold lineCenteredMoment + have hs : (∑ a ∈ Finset.range (u+1), (-1 : ℝ)^(a+u) * (u.choose a : ℝ) * + fallingMoment (m l) (h l) (v+a)) = + ∫ x, ∑ a ∈ Finset.range (u+1), (-1 : ℝ)^(a+u) * (u.choose a : ℝ) * + ((m l : ℝ)/x)^(v+a) ∂gammaMeasure ((m l-h l : ℕ)+1) 1 := by + rw [integral_finsetSum _ hi] + apply Finset.sum_congr rfl + intro a ha + rw [integral_const_mul, ← fallingMoment_eq_integral (he a ha)] + rw [hs] + congr 1 + funext x + rw [sub_pow, Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + rw [pow_add] + ring + +/- Source (11) now applies directly to the exact finite-difference moment. +The gamma centered bound already existed; this bridge to Q's required moments is new. -/ +theorem fallingCenteredMoment_abs_le {L : Type*} (m h : L → ℕ) (l : L) + (hm : 0 < m l) (v u : ℕ) {η : ℝ} (hη : 0 ≤ η) (hηsmall : η ≤ 1/8) + (hlight : ((h l+u+v : ℕ) : ℝ) ≤ (m l : ℝ)*η) : + |lineCenteredMoment (fun l => fallingMoment (m l) (h l)) l v u| ≤ + (16 * exp 2)^v * ((16 * exp 2)*Real.sqrt η)^u := by + have huvn : h l+u+v ≤ m l := by + have hm0 : (0 : ℝ) ≤ m l := Nat.cast_nonneg _ + have ht : (m l : ℝ)*η ≤ m l := mul_le_of_le_one_right hm0 (by linarith) + exact_mod_cast hlight.trans ht + rw [fallingCenteredMoment_eq_integral m h l hm v u (by omega)] + have ha : (0 : ℝ) < (m l-h l : ℕ)+1 := by positivity + have he : (∫ x, |((m l : ℝ)/x)^v * ((m l : ℝ)/x-1)^u| + ∂gammaMeasure ((m l-h l : ℕ)+1) 1) = + ∫ x, ((m l : ℝ)/x)^v * |(m l : ℝ)/x-1|^u + ∂gammaMeasure ((m l-h l : ℕ)+1) 1 := by + apply integral_gamma_congr ha zero_lt_one + intro x hx + rw [abs_mul, abs_pow, abs_pow, abs_of_nonneg (div_nonneg (Nat.cast_nonneg _) hx.le)] + calc + _ ≤ ∫ x, |((m l : ℝ)/x)^v * ((m l : ℝ)/x-1)^u| + ∂gammaMeasure ((m l-h l : ℕ)+1) 1 := by + simpa only [Real.norm_eq_abs] using norm_integral_le_integral_norm + (fun x => ((m l : ℝ)/x)^v * ((m l : ℝ)/x-1)^u) + _ = _ := he + _ ≤ (16 * exp 2)^(u+v) * (Real.sqrt η)^u := gamma_light_line_bound hm hη hηsmall hlight + _ = _ := by rw [pow_add, mul_pow]; ring + +/- Actual inverse-gamma specialization of the shared-line expansion. -/ +theorem goodExpansion_fallingMoment_le {L I J : Type*} + [Fintype L] [DecidableEq L] [Fintype J] [DecidableEq J] + (m h r : L → ℕ) (hm : ∀ l, 0 < m l) (G : Finset I) (path : I → J → L) + {η : ℝ} (hη : 0 ≤ η) (hηsmall : η ≤ 1/8) + (hlight : ∀ l, ((h l+r l+(∑ i ∈ G, ∑ j : J, if path i j = l then 1 else 0) : ℕ) : ℝ) + ≤ (m l : ℝ)*η) : + |shiftedMoment (fun l => fallingMoment (m l) (h l)) r (goodExpansion G path)| ≤ + (16 * exp 2)^(∑ l, r l) * (1+16 * exp 2)^(Fintype.card J*G.card) * + η^((G.card : ℝ)/2) := by + have he := goodExpansion_moment_le (fun l => fallingMoment (m l) (h l)) + (fun l => fallingMoment_zero _ _) r G path (16*exp 2) (Real.sqrt η) + (by positivity) (Real.sqrt_nonneg _) (by + apply (Real.sqrt_le_left (by norm_num : (0 : ℝ) ≤ 1)).mpr + linarith) (by + intro l u hu + apply fallingCenteredMoment_abs_le m h l (hm l) (r l) u hη hηsmall + apply le_trans _ (hlight l) + exact_mod_cast (show h l+u+r l ≤ h l+r l+∑ i ∈ G, ∑ j : J, if path i j = l then 1 else 0 by omega)) + have hs : (Real.sqrt η)^G.card = η^((G.card : ℝ)/2) := by + rw [sqrt_eq_rpow, ← rpow_natCast, ← rpow_mul hη] + congr 1; ring + simpa only [hs] using he + +end CoordinateSweeps.MomentExpansion + +end +end +end +end +open scoped Matrix.Norms.L2Operator + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/AbsMulExpLe.lean b/lean/OAI/Probability/ParisiFinite/AbsMulExpLe.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2b4dad6bc1687e3ec4c7ea99e11eb1595a27aa2 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/AbsMulExpLe.lean @@ -0,0 +1,704 @@ +import Mathlib +import OAI.Probability.ParisiFinite.PartitionSite + +namespace OAI + +/-! Abs Mul Exp Le. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + +lemma abs_mul_exp_le (c z : ℝ) : + |z| * Real.exp (c*|z|) ≤ Real.exp ((c+1)*|z|) := by + have hz : |z| ≤ Real.exp |z| := by linarith [Real.add_one_le_exp |z|] + calc + _ ≤ Real.exp |z| * Real.exp (c*|z|) := mul_le_mul_of_nonneg_right hz (Real.exp_pos _).le + _ = Real.exp ((c+1)*|z|) := by rw [← Real.exp_add]; congr 1; ring + +lemma exp_scale_near_le {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a x s₀ : ℝ) {s : ℝ} (hs : |s-s₀| ≤ 1) (z : ℝ) : + Real.exp (a*f (x+s*z)) ≤ + Real.exp (|a| * |f x|)*Real.exp ((|a| * L*(|s₀|+1))*|z|) := by + have hss : |s| ≤ |s₀|+1 := by + have ht := abs_add_le (s-s₀) s₀ + rw [sub_add_cancel] at ht + linarith + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have hb := shift_norm_le hf x s z + have hmul := mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left hss L.coe_nonneg) (abs_nonneg z) + calc + a*f (x+s*z) ≤ |a| * |f (x+s*z)| := by simpa only [abs_mul] using le_abs_self (a*f (x+s*z)) + _ ≤ |a| * (|f x|+(L:ℝ)*(|s₀|+1)*|z|) := mul_le_mul_of_nonneg_left (by linarith) (abs_nonneg a) + _ = _ := by ring + +lemma coord_exp_scale_near_le {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a x s₀ : ℝ) {s : ℝ} (hs : |s-s₀| ≤ 1) (z : ℝ) : + |z| * Real.exp (a*f (x+s*z)) ≤ + Real.exp (|a| * |f x|)*Real.exp ((|a| * L*(|s₀|+1)+1)*|z|) := by + calc + _ ≤ |z| * (Real.exp (|a| * |f x|)*Real.exp ((|a| * L*(|s₀|+1))*|z|)) := + mul_le_mul_of_nonneg_left (exp_scale_near_le hf a x s₀ hs z) (abs_nonneg z) + _ = Real.exp (|a| * |f x|)*(|z| * Real.exp ((|a| * L*(|s₀|+1))*|z|)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left (abs_mul_exp_le _ z) (Real.exp_pos _).le + +lemma integrable_coord_exp_weight {L : ℝ≥0} {f g : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) {M : ℝ≥0} (hM : ∀ x, |g x| ≤ M) (a s x : ℝ) : + Integrable (fun z => z*(Real.exp (a*f (x+s*z))*g (x+s*z))) (gaussianReal 0 1) := by + have hc := hf.continuous + apply (((integrable_exp_abs _).const_mul (Real.exp (|a| * |f x|))).mul_const (M:ℝ)).mono' + (by fun_prop) + exact ae_of_all _ fun z => by + simp only [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + rw [← mul_assoc] + exact mul_le_mul (coord_exp_scale_near_le hf a x s (by simp) z) (hM _) + (abs_nonneg _) (by positivity) + +lemma hasDerivAt_scale_expMass (f : SmoothField) (a s x : ℝ) : + HasDerivAt (fun r => expMass a r f.val x) + (∫ z, a * (z*(Real.exp (a*f.val (x+s*z))*f.d1 (x+s*z))) ∂gaussianReal 0 1) s := by + have hc := f.continuousVal + have hc₁ := f.continuousD1 + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball s 1) + (bound := fun z => (Real.exp (|a| * |f.val x|)* + Real.exp ((|a| * f.bound1*(|s|+1)+1)*|z|)) * (|a| * f.bound1)) + (F' := fun r z => a * (z*(Real.exp (a*f.val (x+r*z))*f.d1 (x+r*z)))) + (Metric.ball_mem_nhds _ (by norm_num)) ?_ (integrable_exp_shift f.lipschitz a x s) + (by fun_prop) ?_ ?_ ?_).2 + · exact Eventually.of_forall fun _ => by fun_prop + · exact ae_of_all _ fun z r hr => by + simp only [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + have he : |a| * (|z| * (Real.exp (a*f.val (x+r*z))*|f.d1 (x+r*z)|)) = + (|z| * Real.exp (a*f.val (x+r*z)))*(|a| * |f.d1 (x+r*z)|) := by ring + rw [he] + apply mul_le_mul (coord_exp_scale_near_le f.lipschitz a x s + (by simpa [Real.dist_eq] using hr.le) z) + · exact mul_le_mul_of_nonneg_left (f.normD1 _) (abs_nonneg _) + · positivity + · positivity + · exact ((integrable_exp_abs _).const_mul _).mul_const _ + · exact ae_of_all _ fun z r _ => by + have h := ((f.hasD1 (x+r*z)).comp r (((hasDerivAt_id r).mul_const z).const_add x)).const_mul a + convert h.exp using 1 <;> first | rfl | (simp only [Function.comp_apply, id_eq, one_mul]; ring) + +lemma hasDerivAt_scale_average (f : SmoothField) (s x : ℝ) : + HasDerivAt (fun r => ∫ z, f.val (x+r*z) ∂gaussianReal 0 1) + (∫ z, z*f.d1 (x+s*z) ∂gaussianReal 0 1) s := by + have hc := f.continuousVal + have hc₁ := f.continuousD1 + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le (s := Set.univ) + (bound := fun z => |z| * (f.bound1:ℝ)) (F' := fun r z => z*f.d1 (x+r*z)) + univ_mem ?_ (integrable_shift f.lipschitz x s) (by fun_prop) ?_ + (SKQAOA.integrable_abs_standard.mul_const _) ?_).2 + · exact Eventually.of_forall fun _ => by fun_prop + · exact ae_of_all _ fun z r _ => by + rw [Real.norm_eq_abs, abs_mul] + exact mul_le_mul_of_nonneg_left (f.normD1 _) (abs_nonneg _) + · exact ae_of_all _ fun z r _ => by + convert (f.hasD1 (x+r*z)).comp r (((hasDerivAt_id r).mul_const z).const_add x) using 1 <;> + first | rfl | (simp only [one_mul]; ring) + + + +lemma gaussian_tilt_ibp (f : SmoothField) (a s x : ℝ) : + (∫ z, z*(Real.exp (a*f.val (x+s*z))*f.d1 (x+s*z)) ∂gaussianReal 0 1) = + s * (expMoment a s f.val f.d2 x + a*expMoment a s f.val (fun y => f.d1 y^2) x) := by + let G : ℝ → ℝ := fun z => Real.exp (a*f.val (x+s*z))*f.d1 (x+s*z) + let G' : ℝ → ℝ := fun z => s*(Real.exp (a*f.val (x+s*z))*(f.d2 (x+s*z)+a*f.d1 (x+s*z)^2)) + have hD : ∀ z, HasDerivAt G (G' z) z := by + intro z + have h₁ := (f.hasD1 (x+s*z)).comp z (((hasDerivAt_id z).const_mul s).const_add x) + have h₂ := (f.hasD2 (x+s*z)).comp z (((hasDerivAt_id z).const_mul s).const_add x) + convert ((h₁.const_mul a).exp.mul h₂) using 1 <;> + first | rfl | (dsimp [G']; ring) + have hi := integrable_exp_weight f.lipschitz f.continuousD1 f.normD1 a s x + have hi₂ := integrable_exp_weight f.lipschitz f.continuousD2 f.normD2 a s x + have hs := integrable_exp_weight f.lipschitz (g := fun y => f.d1 y^2) + (by have hc := f.continuousD1; fun_prop) (sq_bound f.normD1) a s x + have hi' : Integrable G' (gaussianReal 0 1) := by + convert (hi₂.add (hs.const_mul a)).const_mul s using 1 + funext z + dsimp [G'] + ring + have he := SKGaussian.integral_mul_eq_integral_deriv hD hi hi' + (integrable_coord_exp_weight f.lipschitz f.continuousD1 f.normD1 a s x) + change (∫ z, z*G z ∂gaussianReal 0 1) = _ + rw [he] + have heq : G' = fun z => s * + (Real.exp (a*f.val (x+s*z))*f.d2 (x+s*z) + + a*(Real.exp (a*f.val (x+s*z))*f.d1 (x+s*z)^2)) := by + funext z + dsimp [G'] + ring + rw [heq, integral_const_mul, integral_add hi₂ (hs.const_mul a), integral_const_mul] + rfl + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + + + +lemma hasDerivAt_step_scale (f : SmoothField) (a s x : ℝ) : + HasDerivAt (fun r => step a r f.val x) + (s*(tiltedMean a s f.val f.d2 x + a*tiltedMean a s f.val (fun y => f.d1 y^2) x)) s := by + by_cases ha : a = 0 + · subst a + have h := hasDerivAt_scale_average f s x + have hb := gaussian_tilt_ibp f 0 s x + simp only [zero_mul, Real.exp_zero, one_mul, add_zero, expMoment] at hb + rw [hb] at h + simpa only [step, logMean_zero, tiltedMean_zero, zero_mul, add_zero] using h + · have h := ((hasDerivAt_scale_expMass f a s x).log + (expMass_pos f.lipschitz a s x).ne').div_const a + rw [integral_const_mul, gaussian_tilt_ibp] at h + have he : (a*(s*(expMoment a s f.val f.d2 x + a*expMoment a s f.val (fun y => f.d1 y^2) x)) / + expMass a s f.val x) / a = + s*(tiltedMean a s f.val f.d2 x + a*tiltedMean a s f.val (fun y => f.d1 y^2) x) := by + unfold tiltedMean + field_simp + rw [he] at h + have hs : (fun r => step a r f.val x) = + (fun r => Real.log (expMass a r f.val x) / a) := by + funext r + simp [step, logMean, ha, expMass] + rw [hs] + exact h + +lemma hasDerivAt_transform_scale (f : SmoothField) (a s x : ℝ) : + HasDerivAt (fun r => (f.transform a r).val x) + (s*((f.transform a s).d2 x + a*((f.transform a s).d1 x)^2)) s := by + convert hasDerivAt_step_scale f a s x using 1 <;> + first | rfl | (dsimp [SmoothField.transform]; ring) + + + +def fieldOnInterval (f : SmoothField) (a b t : ℝ) : SmoothField := + f.transform a (Real.sqrt (b-t)) + + + +lemma hasDerivAt_fieldOnInterval_time (f : SmoothField) (a b t x : ℝ) (ht : t < b) : + HasDerivAt (fun r => (fieldOnInterval f a b r).val x) + (-(1/2 : ℝ)*((fieldOnInterval f a b t).d2 x + + a*((fieldOnInterval f a b t).d1 x)^2)) t := by + have hb : 0 < b-t := sub_pos.mpr ht + have hs := (((hasDerivAt_id t).const_sub b).sqrt (ne_of_gt hb)) + have h := (hasDerivAt_transform_scale f a (Real.sqrt (b-t)) x).comp t hs + convert h using 1 <;> + first | rfl | (dsimp [fieldOnInterval]; field_simp) + +@[simp] lemma fieldOnInterval_right (f : SmoothField) (a b x : ℝ) : + (fieldOnInterval f a b b).val x = f.val x := by + by_cases ha : a = 0 + · simp [fieldOnInterval, SmoothField.transform, step, logMean, ha] + · simp [fieldOnInterval, SmoothField.transform, step, logMean, ha] + +lemma fieldOnInterval_spatial1 (f : SmoothField) (a b t x : ℝ) : + HasDerivAt (fieldOnInterval f a b t).val ((fieldOnInterval f a b t).d1 x) x := + (fieldOnInterval f a b t).hasD1 x + +lemma fieldOnInterval_spatial2 (f : SmoothField) (a b t x : ℝ) : + HasDerivAt (fieldOnInterval f a b t).d1 ((fieldOnInterval f a b t).d2 x) x := + (fieldOnInterval f a b t).hasD2 x + + +lemma fieldOnInterval_terminal (β : ℝ≥0) (hβ : 0 < β) (a b x : ℝ) : + (fieldOnInterval (terminalField β hβ) a b b).val x = + Real.log (2*Real.cosh ((β:ℝ)*x)) / β := by + rw [fieldOnInterval_right] + rfl + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + +section Ambient +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + +def ambientStep (a : ℝ) (c : E) (f : E → ℝ) (x : E) : ℝ := + logMean (gaussianReal 0 1) a (fun z => f (x+z • c)) + +def ambientMass (a : ℝ) (c : E) (f : E → ℝ) (x : E) : ℝ := + ∫ z, Real.exp (a*f (x+z • c)) ∂gaussianReal 0 1 + +def ambientMoment (a : ℝ) (c : E) (f g : E → ℝ) (x : E) : ℝ := + ∫ z, Real.exp (a*f (x+z • c))*g (x+z • c) ∂gaussianReal 0 1 + +def ambientTilt (a : ℝ) (c : E) (f g : E → ℝ) (x : E) : ℝ := + ambientMoment a c f g x / ambientMass a c f x + +lemma line_lipschitz {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) (x c : E) : + LipschitzWith (L*‖c‖₊) (fun z : ℝ => f (x+z • c)) := by + rw [lipschitzWith_iff_norm_sub_le] + intro z w + have h := hf.norm_sub_le (x+z • c) (x+w • c) + rw [add_sub_add_left_eq_sub, ← sub_smul, norm_smul] at h + simpa [NNReal.coe_mul, mul_comm, mul_left_comm, mul_assoc] using h + +lemma integrable_ambient {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) (x c : E) : + Integrable (fun z : ℝ => f (x+z • c)) (gaussianReal 0 1) := by + simpa only [zero_add, one_mul] using integrable_shift (line_lipschitz hf x c) 0 1 + +lemma integrable_exp_ambient {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) (a : ℝ) (x c : E) : + Integrable (fun z : ℝ => Real.exp (a*f (x+z • c))) (gaussianReal 0 1) := by + simpa only [zero_add, one_mul] using integrable_exp_shift (line_lipschitz hf x c) a 0 1 + +lemma ambientMass_pos {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) (a : ℝ) (c x : E) : + 0 < ambientMass a c f x := integral_exp_pos (integrable_exp_ambient hf a x c) + +lemma integrable_ambient_weight {L : ℝ≥0} {f g : E → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) {M : ℝ} (hM : ∀ x, |g x| ≤ M) (a : ℝ) (c x : E) : + Integrable (fun z => Real.exp (a*f (x+z • c))*g (x+z • c)) (gaussianReal 0 1) := by + apply (integrable_exp_ambient hf a x c).mul_bdd (by fun_prop) + exact ae_of_all _ fun z => by simpa only [Real.norm_eq_abs] using hM (x+z • c) + +lemma ambientStep_lipschitz {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) + {a : ℝ} (ha : 0 ≤ a) (c : E) : LipschitzWith L (ambientStep a c f) := by + rw [lipschitzWith_iff_norm_sub_le] + intro x y + rw [Real.norm_eq_abs] + apply logMean_stable ha (integrable_ambient hf x c) (integrable_ambient hf y c) + (integrable_exp_ambient hf a x c) (integrable_exp_ambient hf a y c) + intro z + simpa only [Real.norm_eq_abs, add_sub_add_right_eq_sub] using + hf.norm_sub_le (x+z • c) (y+z • c) + +lemma ambient_exp_near_le {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) + (a : ℝ) (x₀ c : E) {x : E} (hx : ‖x-x₀‖ ≤ 1) (z : ℝ) : + Real.exp (a*f (x+z • c)) ≤ + Real.exp (|a| *(|f x₀|+L))*Real.exp ((|a| *L*‖c‖)*|z|) := by + have hb : |f (x+z • c)| ≤ |f x₀| + L + (L:ℝ)*‖c‖*|z| := by + have hv := hf.norm_sub_le (x+z • c) x₀ + have ht := norm_add_le (x-x₀) (z • c) + have he : x+z • c-x₀ = (x-x₀)+z • c := by abel + rw [he] at hv + rw [norm_smul, Real.norm_eq_abs] at ht + have htri := abs_add_le (f (x+z • c)-f x₀) (f x₀) + rw [sub_add_cancel] at htri + rw [Real.norm_eq_abs] at hv + nlinarith [L.coe_nonneg] + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + calc + _ ≤ |a| * |f (x+z • c)| := by simpa only [abs_mul] using le_abs_self (a*f (x+z • c)) + _ ≤ |a| *(|f x₀|+L+(L:ℝ)*‖c‖*|z|) := mul_le_mul_of_nonneg_left hb (abs_nonneg _) + _ = _ := by ring + +lemma continuous_ambientMoment {L : ℝ≥0} {f g : E → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) {M : ℝ} (hM : ∀ x, |g x| ≤ M) (a : ℝ) (c : E) : + Continuous (ambientMoment a c f g) := by + have hc := hf.continuous + apply continuous_iff_continuousAt.mpr + intro x₀ + apply continuousAt_of_dominated + (bound := fun z => (Real.exp (|a| *(|f x₀|+L))*Real.exp ((|a| *L*‖c‖)*|z|))*M) + · exact Eventually.of_forall fun _ => (integrable_ambient_weight hf hg hM a c _).aestronglyMeasurable + · filter_upwards [Metric.ball_mem_nhds x₀ (by norm_num : (0:ℝ)<1)] with x hx + exact ae_of_all _ fun z => by + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + apply mul_le_mul (ambient_exp_near_le hf a x₀ c (by have hh : dist x x₀ < 1 := hx; simpa only [dist_eq_norm] using hh.le) z) + (hM _) (abs_nonneg _) + positivity + · exact ((integrable_exp_abs _).const_mul _).mul_const _ + · exact ae_of_all _ fun z => by fun_prop + +lemma continuous_ambientTilt {L : ℝ≥0} {f g : E → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) {M : ℝ} (hM : ∀ x, |g x| ≤ M) (a : ℝ) (c : E) : + Continuous (ambientTilt a c f g) := by + have he : ambientMass a c f = ambientMoment a c f (fun _ => 1) := by + funext x + simp [ambientMass, ambientMoment] + have hm : Continuous (ambientMass a c f) := by + rw [he] + exact continuous_ambientMoment hf continuous_const (by intro; norm_num : ∀ x : E, |(1:ℝ)| ≤ 1) a c + exact (continuous_ambientMoment hf hg hM a c).div hm (fun x => (ambientMass_pos hf a c x).ne') + +@[simp] lemma ambientTilt_zero (c : E) (f g : E → ℝ) (x : E) : + ambientTilt 0 c f g x = ∫ z, g (x+z • c) ∂gaussianReal 0 1 := by + simp [ambientTilt, ambientMoment, ambientMass] + +lemma abs_ambientTilt_le {L : ℝ≥0} {f g : E → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) {M : ℝ} (hM : ∀ x, |g x| ≤ M) (a : ℝ) (c x : E) : + |ambientTilt a c f g x| ≤ M := by + have hi := integrable_ambient_weight hf hg hM a c x + have hp := ambientMass_pos hf a c x + unfold ambientTilt + rw [abs_div, abs_of_pos hp, div_le_iff₀ hp] + apply abs_integral_le_integral_abs.trans + have h := integral_mono hi.abs ((integrable_exp_ambient hf a x c).const_mul M) + (fun z => by + rw [abs_mul, abs_of_pos (Real.exp_pos _), mul_comm M] + exact mul_le_mul_of_nonneg_left (hM _) (Real.exp_pos _).le) + simpa only [integral_const_mul, ambientMass] using h + +end Ambient +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite +section Ambient +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +lemma ambient_exp_near_le_radius {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) + (a : ℝ) (x₀ c : E) {x : E} {r : ℝ} (hx : ‖x-x₀‖ ≤ r) (z : ℝ) : + Real.exp (a*f (x+z • c)) ≤ + Real.exp (|a| * (|f x₀|+(L:ℝ)*r))*Real.exp ((|a| * L*‖c‖)*|z|) := by + have hb : |f (x+z • c)| ≤ |f x₀| + (L:ℝ)*r + (L:ℝ)*‖c‖*|z| := by + have hv := hf.norm_sub_le (x+z • c) x₀ + have ht := norm_add_le (x-x₀) (z • c) + have he : x+z • c-x₀ = (x-x₀)+z • c := by abel + rw [he] at hv + rw [norm_smul, Real.norm_eq_abs] at ht + have htri := abs_add_le (f (x+z • c)-f x₀) (f x₀) + rw [sub_add_cancel] at htri + rw [Real.norm_eq_abs] at hv + nlinarith [L.coe_nonneg] + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + calc + _ ≤ |a| * |f (x+z • c)| := by simpa only [abs_mul] using le_abs_self (a*f (x+z • c)) + _ ≤ |a| * (|f x₀|+(L:ℝ)*r+(L:ℝ)*‖c‖*|z|) := mul_le_mul_of_nonneg_left hb (abs_nonneg _) + _ = _ := by ring + + + +lemma hasDerivAt_ambientMoment {L : ℝ≥0} {f f' g g' : E → ℝ} (hf : LipschitzWith L f) + (hf' : Continuous f') (hg : Continuous g) (hg' : Continuous g') + {M N P : ℝ≥0} (hM : ∀ x, |f' x| ≤ M) (hN : ∀ x, |g x| ≤ N) (hP : ∀ x, |g' x| ≤ P) + (v : E) + (hdf : ∀ y t, HasDerivAt (fun u : ℝ => f (y+u • v)) (f' (y+t • v)) t) + (hdg : ∀ y t, HasDerivAt (fun u : ℝ => g (y+u • v)) (g' (y+t • v)) t) + (a : ℝ) (c x : E) (t₀ : ℝ) : + HasDerivAt (fun t => ambientMoment a c f g (x+t • v)) + (∫ z, Real.exp (a*f (x+t₀ • v+z • c))* + (a*f' (x+t₀ • v+z • c)*g (x+t₀ • v+z • c)+g' (x+t₀ • v+z • c)) ∂gaussianReal 0 1) t₀ := by + have hc := hf.continuous + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball t₀ 1) + (bound := fun z => + (Real.exp (|a| * (|f (x+t₀ • v)|+(L:ℝ)*‖v‖))*Real.exp ((|a| * L*‖c‖)*|z|)) * (|a| * M*N+P)) + (F' := fun t z => Real.exp (a*f (x+t • v+z • c))* + (a*f' (x+t • v+z • c)*g (x+t • v+z • c)+g' (x+t • v+z • c))) + (Metric.ball_mem_nhds _ (by norm_num)) ?_ ?_ ?_ ?_ ?_ ?_).2 + · exact Eventually.of_forall fun _ => by fun_prop + · exact integrable_ambient_weight hf hg hN a c (x+t₀ • v) + · fun_prop + · exact ae_of_all _ fun z t ht => by + have hxt : ‖(x+t • v)-(x+t₀ • v)‖ ≤ ‖v‖ := by + rw [add_sub_add_left_eq_sub, ← sub_smul, norm_smul, Real.norm_eq_abs] + apply mul_le_of_le_one_left (norm_nonneg _) + have hh : dist t t₀ < 1 := ht + simpa only [Real.dist_eq] using hh.le + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + apply mul_le_mul (ambient_exp_near_le_radius hf a (x+t₀ • v) c hxt z) + · apply (abs_add_le _ _).trans + rw [abs_mul, abs_mul] + exact add_le_add (mul_le_mul + (mul_le_mul_of_nonneg_left (hM _) (abs_nonneg a)) (hN _) + (abs_nonneg _) (by positivity)) (hP _) + · exact abs_nonneg _ + · positivity + · exact ((integrable_exp_abs _).const_mul _).mul_const _ + · exact ae_of_all _ fun z t _ => by + have he (u : ℝ) : x+u • v+z • c = (x+z • c)+u • v := by abel + simp_rw [he] + convert ((hdf (x+z • c) t).const_mul a).exp.mul (hdg (x+z • c) t) using 1 + first | rfl | ring + +lemma hasDerivAt_ambientMass {L : ℝ≥0} {f f' : E → ℝ} (hf : LipschitzWith L f) + (hf' : Continuous f') {M : ℝ≥0} (hM : ∀ x, |f' x| ≤ M) (v : E) + (hdf : ∀ y t, HasDerivAt (fun u : ℝ => f (y+u • v)) (f' (y+t • v)) t) + (a : ℝ) (c x : E) (t₀ : ℝ) : + HasDerivAt (fun t => ambientMass a c f (x+t • v)) + (a*ambientMoment a c f f' (x+t₀ • v)) t₀ := by + have h := hasDerivAt_ambientMoment hf hf' continuous_const continuous_const hM + (N := 1) (P := 0) (by intro; norm_num) (by intro; norm_num) v hdf + (fun y t => hasDerivAt_const t (1:ℝ)) a c x t₀ + have he : ambientMoment a c f (fun _ => 1) = ambientMass a c f := by + funext y + simp [ambientMoment, ambientMass] + rw [he] at h + simpa only [mul_one, add_zero, mul_left_comm _ a, integral_const_mul, ambientMoment] using h + +lemma hasDerivAt_ambientMean {L : ℝ≥0} {f f' : E → ℝ} (hf : LipschitzWith L f) + (hf' : Continuous f') {M : ℝ≥0} (hM : ∀ x, |f' x| ≤ M) (v : E) + (hdf : ∀ y t, HasDerivAt (fun u : ℝ => f (y+u • v)) (f' (y+t • v)) t) + (c x : E) (t₀ : ℝ) : + HasDerivAt (fun t => ∫ z, f (x+t • v+z • c) ∂gaussianReal 0 1) + (∫ z, f' (x+t₀ • v+z • c) ∂gaussianReal 0 1) t₀ := by + have hc := hf.continuous + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le (s := Set.univ) + (bound := fun _ => (M:ℝ)) (F' := fun t z => f' (x+t • v+z • c)) univ_mem ?_ + (integrable_ambient hf (x+t₀ • v) c) (by fun_prop) ?_ (integrable_const _) ?_).2 + · exact Eventually.of_forall fun _ => by fun_prop + · exact ae_of_all _ fun z t _ => by simpa only [Real.norm_eq_abs] using hM _ + · exact ae_of_all _ fun z t _ => by + have he (u : ℝ) : x+u • v+z • c = (x+z • c)+u • v := by abel + simpa only [he] using hdf (x+z • c) t + +lemma hasDerivAt_ambientStep {L : ℝ≥0} {f f' : E → ℝ} (hf : LipschitzWith L f) + (hf' : Continuous f') {M : ℝ≥0} (hM : ∀ x, |f' x| ≤ M) (v : E) + (hdf : ∀ y t, HasDerivAt (fun u : ℝ => f (y+u • v)) (f' (y+t • v)) t) + (a : ℝ) (c x : E) (t₀ : ℝ) : + HasDerivAt (fun t => ambientStep a c f (x+t • v)) + (ambientTilt a c f f' (x+t₀ • v)) t₀ := by + by_cases ha : a=0 + · subst a + simpa only [ambientStep, logMean_zero, ambientTilt_zero] using + hasDerivAt_ambientMean hf hf' hM v hdf c x t₀ + · have h := ((hasDerivAt_ambientMass hf hf' hM v hdf a c x t₀).log + (ambientMass_pos hf a c (x+t₀ • v)).ne').div_const a + have he : (a*ambientMoment a c f f' (x+t₀ • v)/ambientMass a c f (x+t₀ • v))/a = + ambientTilt a c f f' (x+t₀ • v) := by + unfold ambientTilt + field_simp + rw [he] at h + have heq : (fun t : ℝ => ambientStep a c f (x+t • v)) = + (fun t : ℝ => Real.log (ambientMass a c f (x+t • v))/a) := by + funext t + simp [ambientStep, logMean, ha, ambientMass] + rw [heq] + exact h + +end Ambient +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite +section Ambient +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +lemma ambientMoment_add {L : ℝ≥0} {f g h : E → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) (hh : Continuous h) {M N : ℝ} + (hM : ∀ x, |g x| ≤ M) (hN : ∀ x, |h x| ≤ N) (a : ℝ) (c x : E) : + ambientMoment a c f (fun y => g y+h y) x = + ambientMoment a c f g x + ambientMoment a c f h x := by + simp only [ambientMoment, mul_add] + exact integral_add (integrable_ambient_weight hf hg hM a c x) (integrable_ambient_weight hf hh hN a c x) + +lemma ambientMoment_const_mul (a : ℝ) (c : E) (f g : E → ℝ) (x : E) (k : ℝ) : + ambientMoment a c f (fun y => k*g y) x = k*ambientMoment a c f g x := by + simp only [ambientMoment, mul_left_comm _ k, integral_const_mul] + +lemma ambientTilt_add {L : ℝ≥0} {f g h : E → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) (hh : Continuous h) {M N : ℝ} + (hM : ∀ x, |g x| ≤ M) (hN : ∀ x, |h x| ≤ N) (a : ℝ) (c x : E) : + ambientTilt a c f (fun y => g y+h y) x = + ambientTilt a c f g x + ambientTilt a c f h x := by + simp only [ambientTilt, ambientMoment_add hf hg hh hM hN, add_div] + +lemma ambientTilt_const_mul (a : ℝ) (c : E) (f g : E → ℝ) (x : E) (k : ℝ) : + ambientTilt a c f (fun y => k*g y) x = k*ambientTilt a c f g x := by + simp only [ambientTilt, ambientMoment_const_mul, mul_div_assoc] + +lemma ambientTilt_mono {L : ℝ≥0} {f g h : E → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) (hh : Continuous h) {M N : ℝ} + (hM : ∀ x, |g x| ≤ M) (hN : ∀ x, |h x| ≤ N) + (hgh : ∀ x, g x ≤ h x) (a : ℝ) (c x : E) : + ambientTilt a c f g x ≤ ambientTilt a c f h x := by + apply div_le_div_of_nonneg_right _ (ambientMass_pos hf a c x).le + apply integral_mono (integrable_ambient_weight hf hg hM a c x) + (integrable_ambient_weight hf hh hN a c x) + intro z + exact mul_le_mul_of_nonneg_left (hgh _) (Real.exp_pos _).le + +lemma ambientTilt_const {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) + (a : ℝ) (c x : E) (k : ℝ) : + ambientTilt a c f (fun _ => k) x = k := by + simp only [ambientTilt, ambientMoment, integral_mul_const, ambientMass] + exact mul_div_cancel_left₀ _ (ambientMass_pos hf a c x).ne' + + +lemma hasDerivAt_ambientTilt {L : ℝ≥0} {f f' g g' : E → ℝ} (hf : LipschitzWith L f) + (hf' : Continuous f') (hg : Continuous g) (hg' : Continuous g') + {M N P : ℝ≥0} (hM : ∀ x, |f' x| ≤ M) (hN : ∀ x, |g x| ≤ N) (hP : ∀ x, |g' x| ≤ P) + (v : E) + (hdf : ∀ y t, HasDerivAt (fun u : ℝ => f (y+u • v)) (f' (y+t • v)) t) + (hdg : ∀ y t, HasDerivAt (fun u : ℝ => g (y+u • v)) (g' (y+t • v)) t) + (a : ℝ) (c x : E) (t₀ : ℝ) : + HasDerivAt (fun t => ambientTilt a c f g (x+t • v)) + (ambientTilt a c f g' (x+t₀ • v) + a* + (ambientTilt a c f (fun y => f' y*g y) (x+t₀ • v) - + ambientTilt a c f f' (x+t₀ • v)*ambientTilt a c f g (x+t₀ • v))) t₀ := by + have h := hasDerivAt_ambientMoment hf hf' hg hg' hM hN hP v hdf hdg a c x t₀ + have he (y : E) : a*f' y*g y+g' y = g' y+a*(f' y*g y) := by ring + simp_rw [he] at h + change HasDerivAt (fun t => ambientMoment a c f g (x+t • v)) + (ambientMoment a c f (fun y => g' y+a*(f' y*g y)) (x+t₀ • v)) t₀ at h + rw [ambientMoment_add hf hg' (by fun_prop) hP + (fun y => by + rw [abs_mul, abs_mul] + exact mul_le_mul_of_nonneg_left (mul_le_mul (hM _) (hN _) (abs_nonneg _) M.coe_nonneg) (abs_nonneg a)), + ambientMoment_const_mul] at h + have hd := h.div (hasDerivAt_ambientMass hf hf' hM v hdf a c x t₀) + (ambientMass_pos hf a c (x+t₀ • v)).ne' + convert hd using 1 <;> first | rfl | (unfold ambientTilt; field_simp; ring) + +end Ambient +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + + + +structure DirectionalField (E : Type*) [NormedAddCommGroup E] [NormedSpace ℝ E] where + val : E → ℝ + first : E → E → ℝ + second : E → E → E → ℝ + lip : ℝ≥0 + lipschitz : LipschitzWith lip val + continuousFirst : ∀ v, Continuous (first v) + continuousSecond : ∀ v w, Continuous (second v w) + hasFirst : ∀ v x t, HasDerivAt (fun u : ℝ => val (x+u • v)) (first v (x+t • v)) t + hasSecond : ∀ v w x t, HasDerivAt (fun u : ℝ => first w (x+u • v)) (second v w (x+t • v)) t + boundFirst : E → ℝ≥0 + boundSecond : E → E → ℝ≥0 + normFirst : ∀ v x, |first v x| ≤ boundFirst v + normSecond : ∀ v w x, |second v w x| ≤ boundSecond v w + +namespace DirectionalField +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + + +def transform (f : DirectionalField E) (a : ℝ≥0) (c : E) : DirectionalField E where + val := ambientStep a c f.val + first v := ambientTilt a c f.val (f.first v) + second v w x := ambientTilt a c f.val (f.second v w) x + (a:ℝ)* + (ambientTilt a c f.val (fun y => f.first v y*f.first w y) x - + ambientTilt a c f.val (f.first v) x*ambientTilt a c f.val (f.first w) x) + lip := f.lip + lipschitz := ambientStep_lipschitz f.lipschitz a.coe_nonneg c + continuousFirst v := continuous_ambientTilt f.lipschitz (f.continuousFirst v) (f.normFirst v) a c + continuousSecond v w := by + have h1 := continuous_ambientTilt f.lipschitz (f.continuousFirst v) (f.normFirst v) a c + have h2 := continuous_ambientTilt f.lipschitz (f.continuousFirst w) (f.normFirst w) a c + have h12 := continuous_ambientTilt f.lipschitz (f.continuousSecond v w) (f.normSecond v w) a c + have hp := continuous_ambientTilt f.lipschitz ((f.continuousFirst v).mul (f.continuousFirst w)) + (fun y => by + simp only [Pi.mul_apply, abs_mul] + exact mul_le_mul (f.normFirst v y) (f.normFirst w y) (abs_nonneg _) (f.boundFirst v).coe_nonneg) (a:ℝ) c + fun_prop + hasFirst v x t := hasDerivAt_ambientStep f.lipschitz (f.continuousFirst v) (f.normFirst v) + v (f.hasFirst v) a c x t + hasSecond v w x t := hasDerivAt_ambientTilt f.lipschitz (f.continuousFirst v) + (f.continuousFirst w) (f.continuousSecond v w) (f.normFirst v) (f.normFirst w) + (f.normSecond v w) v (f.hasFirst v) (f.hasSecond v w) a c x t + boundFirst := f.boundFirst + boundSecond v w := f.boundSecond v w + 2*a*f.boundFirst v*f.boundFirst w + normFirst v := abs_ambientTilt_le f.lipschitz (f.continuousFirst v) (f.normFirst v) a c + normSecond v w x := by + have h1 := abs_ambientTilt_le f.lipschitz (f.continuousFirst v) (f.normFirst v) (a:ℝ) c x + have h2 := abs_ambientTilt_le f.lipschitz (f.continuousFirst w) (f.normFirst w) (a:ℝ) c x + have h12 := abs_ambientTilt_le f.lipschitz (f.continuousSecond v w) (f.normSecond v w) (a:ℝ) c x + have hp := abs_ambientTilt_le f.lipschitz ((f.continuousFirst v).mul (f.continuousFirst w)) + (fun y => by + simp only [Pi.mul_apply, abs_mul] + exact mul_le_mul (f.normFirst v y) (f.normFirst w y) (abs_nonneg _) (f.boundFirst v).coe_nonneg) (a:ℝ) c x + change |ambientTilt a c f.val (fun y => f.first v y * f.first w y) x| ≤ + (f.boundFirst v : ℝ) * (f.boundFirst w : ℝ) at hp + have hprod := mul_le_mul h1 h2 (abs_nonneg _) (f.boundFirst v).coe_nonneg + have hsub := abs_sub_le (ambientTilt a c f.val (fun y => f.first v y*f.first w y) x) 0 + (ambientTilt a c f.val (f.first v) x*ambientTilt a c f.val (f.first w) x) + simp only [sub_zero, zero_sub, abs_neg, abs_mul] at hsub + apply (abs_add_le _ _).trans + rw [abs_mul, abs_of_nonneg a.coe_nonneg] + simp only [NNReal.coe_add, NNReal.coe_mul, NNReal.coe_ofNat] + nlinarith [a.coe_nonneg] + + +def slice (f : DirectionalField E) (x v : E) : SmoothField where + val t := f.val (x+t • v) + d1 t := f.first v (x+t • v) + d2 t := f.second v v (x+t • v) + hasD1 := f.hasFirst v x + hasD2 := f.hasSecond v v x + continuousD2 := (f.continuousSecond v v).comp (by fun_prop) + bound1 := f.boundFirst v + bound2 := f.boundSecond v v + normD1 t := f.normFirst v _ + normD2 t := f.normSecond v v _ + + +lemma hasDerivAt_transform_scale (f : DirectionalField E) (a : ℝ≥0) (c x : E) (s : ℝ) : + HasDerivAt (fun r => (f.transform a (r • c)).val x) + (s*(ambientTilt a (s • c) f.val (f.second c c) x + + (a:ℝ)*ambientTilt a (s • c) f.val (fun y => (f.first c y)^2) x)) s := by + have h := ParisiFinite.hasDerivAt_step_scale (f.slice x c) a s 0 + convert h using 1 <;> + simp only [transform, slice, step, ambientStep, ambientTilt, tiltedMean, expMoment, + expMass, ambientMass, ambientMoment, zero_add, smul_smul, mul_comm] + +end DirectionalField +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Act.lean b/lean/OAI/Probability/ParisiFinite/Act.lean new file mode 100644 index 0000000000000000000000000000000000000000..6fab4c7ceea48c47de98292ebcf5b7a9eb3c0ca1 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Act.lean @@ -0,0 +1,680 @@ +import Mathlib +import OAI.Probability.ParisiFinite.WComm + +namespace OAI + +/-! Act. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped BigOperators +namespace ProbeProduct +variable {ι H : Type*} [NormedAddCommGroup H] [NormedSpace ℂ H] + +def act (T : ι → H →L[ℂ] H) : List ι → H →L[ℂ] H + | [] => ContinuousLinearMap.id ℂ H + | j::l => (T j).comp (act T l) + +@[simp] theorem act_nil (T : ι → H →L[ℂ] H) (x : H) : act T [] x=x := rfl +@[simp] theorem act_cons (T : ι → H →L[ℂ] H) (j : ι) (l : List ι) (x : H) : + act T (j::l) x=T j (act T l x) := rfl + +theorem norm_act_le (T : ι → H →L[ℂ] H) (l : List ι) + (hT : ∀ j ∈ l, ∀ x, ‖T j x‖ ≤ ‖x‖) (x : H) : ‖act T l x‖ ≤ ‖x‖ := by + induction l with + | nil => simp + | cons j l ih => + exact (hT j (by simp) _).trans (ih (fun k hk => hT k (by simp [hk]))) + + + +theorem firstOrder_remainder (T : ι → H →L[ℂ] H) (y : ι → H) (x : H) + (r a b : ℝ) (l : List ι) (_ha : 0 ≤ a) (hb : 0 ≤ b) + (hT : ∀ j ∈ l, ∀ z, ‖T j z‖ ≤ ‖z‖) + (hfirst : ∀ j ∈ l, ‖T j x-x-r • y j‖ ≤ a) + (hcross : ∀ j ∈ l, ∀ k ∈ l, ‖T j (y k)-y k‖ ≤ b) : + ‖act T l x-x-r • (l.map y).sum‖ ≤ l.length*a+l.length^2*|r| *b := by + induction l with + | nil => simp + | cons j l ih => + have hTl : ∀ k ∈ l, ∀ z, ‖T k z‖ ≤ ‖z‖ := fun k hk => hT k (by simp [hk]) + have hfl : ∀ k ∈ l, ‖T k x-x-r • y k‖ ≤ a := fun k hk => hfirst k (by simp [hk]) + have hcl : ∀ k ∈ l, ∀ k' ∈ l, ‖T k (y k')-y k'‖ ≤ b := + fun k hk k' hk' => hcross k (by simp [hk]) k' (by simp [hk']) + have hj := hfirst j (by simp) + have hi := ih hTl hfl hcl + have hc : ‖T j (l.map y).sum-(l.map y).sum‖ ≤ l.length*b := by + have hs : T j (l.map y).sum-(l.map y).sum = + (l.map (fun k => T j (y k)-y k)).sum := by + have hh : ∀ l : List ι, T j (l.map y).sum-(l.map y).sum = + (l.map (fun k => T j (y k)-y k)).sum := by + intro ll + induction ll with + | nil => simp + | cons k ll ihh => + simp only [List.map_cons,List.sum_cons,map_add] + rw [← ihh] + abel + exact hh l + rw [hs] + calc + _ ≤ ((l.map (fun k => T j (y k)-y k)).map norm).sum := by + have hh : ∀ xs : List H, ‖xs.sum‖ ≤ (xs.map norm).sum := by + intro xs + induction xs with + | nil => simp + | cons z xs ihh => + simpa only [List.sum_cons,List.map_cons] using + (norm_add_le z xs.sum).trans (add_le_add_right ihh ‖z‖) + exact hh _ + _ ≤ (l.map (fun _ => b)).sum := by + rw [List.map_map] + exact List.sum_le_sum (fun k hk => hcross j (by simp) k (by simp [hk])) + _ = _ := by simp + have he : act T (j::l) x-x-r • ((j::l).map y).sum = + T j (act T l x-x-r • (l.map y).sum) + + (T j x-x-r • y j) + r • (T j (l.map y).sum-(l.map y).sum) := by + simp only [act_cons,map_sub,ContinuousLinearMap.map_smul_of_tower, + List.map_cons,List.sum_cons,smul_add,smul_sub] + abel + rw [he] + calc + _ ≤ ‖T j (act T l x-x-r • (l.map y).sum)‖+ + ‖T j x-x-r • y j‖+‖r • (T j (l.map y).sum-(l.map y).sum)‖ := + (norm_add_le _ _).trans (add_le_add_left (norm_add_le _ _) _) + _ ≤ (l.length*a+l.length^2*|r| *b)+a+|r| *(l.length*b) := by + gcongr + · exact (hT j (by simp) _).trans hi + · simpa only [norm_smul,Real.norm_eq_abs] using + mul_le_mul_of_nonneg_left hc (abs_nonneg r) + _ ≤ _ := by + simp only [List.length_cons,Nat.cast_add,Nat.cast_one] + have hn : (0:ℝ) ≤ l.length := Nat.cast_nonneg _ + have hrb : 0 ≤ |r| *b := mul_nonneg (abs_nonneg r) hb + have hnr : 0 ≤ (l.length:ℝ)* (|r| *b) := mul_nonneg hn hrb + nlinarith + + +theorem zero_clock_remainder (T : ι → H →L[ℂ] H) (y : ι → H) (x : H) + (r a b : ℝ) (l : List ι) (ha : 0 ≤ a) (hb : 0 ≤ b) + (hT : ∀ j ∈ l, ∀ z, ‖T j z‖ ≤ ‖z‖) + (hfirst : ∀ j ∈ l, ‖T j x-x-r • y j‖ ≤ a) + (hcross : ∀ j ∈ l, ∀ k ∈ l, ‖T j (y k)-y k‖ ≤ b) + (hclock : (l.map y).sum=0) : + ‖act T l x-x‖ ≤ l.length*a+l.length^2*|r| *b := by + simpa only [hclock,smul_zero,sub_zero] using + firstOrder_remainder T y x r a b l ha hb hT hfirst hcross + + +theorem error_of_norm_remainder (T : ι → H →L[ℂ] H) (l : List ι) + (hT : ∀ j ∈ l, ∀ z, ‖T j z‖ ≤ ‖z‖) (x ρ : H) : + ‖act T l (x+ρ)-(x+ρ)‖ ≤ ‖act T l x-x‖+2*‖ρ‖ := by + have he : act T l (x+ρ)-(x+ρ)=(act T l x-x)+(act T l ρ-ρ) := by + rw [map_add] + abel + rw [he] + have hh := norm_sub_le (act T l ρ) ρ + have hn := norm_act_le T l hT ρ + have ht := norm_add_le (act T l x-x) (act T l ρ-ρ) + linarith + +end ProbeProduct + +namespace CoherentFock +open Complex +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem matrixMass_nonneg (A : Matrix (Fin 2) (Fin 2) ℂ) : 0 ≤ matrixMass A := + Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun _ _ => norm_nonneg _)) + + + +theorem scaled_probe_error (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (r : ℝ) (v w : E) (x : PreSpin E) : + ‖probe A (r • v) (spinCoe x)-spinCoe x-r • (I • probeField A w x)‖ ≤ + (r^2*‖v‖^2+|r| *‖v-w‖)*matrixMass A*spinBound x := by + have he : probe A (r • v) (spinCoe x)-spinCoe x-r • (I • probeField A w x) = + (probe A (r • v) (spinCoe x)-spinCoe x-I • probeField A (r • v) x)+ + r • (I • probeField A (v-w) x) := by + rw [probeField_real_smul,probeField_sub,smul_sub,smul_sub,smul_comm I r] + abel + rw [he] + calc + _ ≤ ‖probe A (r • v) (spinCoe x)-spinCoe x-I • probeField A (r • v) x‖+ + ‖r • (I • probeField A (v-w) x)‖ := norm_add_le _ _ + _ ≤ ‖r • v‖^2*matrixMass A*spinBound x+ + |r| *(‖v-w‖*matrixMass A*spinBound x) := by + apply add_le_add (probe_taylor A hA (r • v) x) + simp only [norm_smul,Complex.norm_I,one_mul,Real.norm_eq_abs] + exact mul_le_mul_of_nonneg_left (norm_probeField_le A hA (v-w) x) (abs_nonneg r) + _ = _ := by + simp only [norm_smul,Real.norm_eq_abs,mul_pow,sq_abs] + ring + + + +theorem zero_clock_spin_probes {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (v w : ι → E) + (r L M Δ : ℝ) (x : PreSpin E) + (hL : 0 ≤ L) (hM : 0 ≤ M) (hΔ : 0 ≤ Δ) + (hA : ∀ j ∈ l, A j ∈ unitary _) + (hv : ∀ j ∈ l, ‖v j‖ ≤ L) (hw : ∀ j ∈ l, ‖w j‖ ≤ L) + (hd : ∀ j ∈ l, ‖v j-w j‖ ≤ Δ) + (hMass : ∀ j ∈ l, matrixMass (A j) ≤ M) + (hMassStar : ∀ j ∈ l, matrixMass (A j).conjTranspose ≤ M) + (hclock : (l.map fun j => I • probeField (A j) (w j) x).sum=0) : + ‖ProbeProduct.act (fun j => probe (A j) (r • v j)) l (spinCoe x)-spinCoe x‖ ≤ + l.length*((r^2*L^2+|r| *Δ)*M*spinBound x)+ + l.length^2*|r| *(2*|r| *L^2*M^3*spinBound x) := by + have hS := spinBound_nonneg x + apply ProbeProduct.zero_clock_remainder + (fun j => probe (A j) (r • v j)) (fun j => I • probeField (A j) (w j) x) + (spinCoe x) r ((r^2*L^2+|r| *Δ)*M*spinBound x) (2*|r| *L^2*M^3*spinBound x) l + · positivity + · positivity + · intro j hj z + exact (norm_probe (A j) (hA j hj) (r • v j) z).le + · intro j hj + exact (scaled_probe_error (A j) (hA j hj) r (v j) (w j) x).trans (by + gcongr + · exact matrixMass_nonneg _ + · exact hv j hj + · exact hd j hj + · exact hMass j hj) + · intro j hj k hk + simp only [map_smul,← smul_sub,norm_smul,Complex.norm_I,one_mul] + have hb := probe_cross (A j) (A k) (hA j hj) (r • v j) (w k) x + simp only [norm_smul,Real.norm_eq_abs] at hb + calc + _ ≤ 2*(|r| *‖v j‖)*‖w k‖*matrixMass (A j)*matrixMass (A k).conjTranspose* + matrixMass (A k)*spinBound x := hb + _ ≤ 2*(|r| *L)*L*M*M*M*spinBound x := by + gcongr + · exact matrixMass_nonneg _ + · exact matrixMass_nonneg _ + · exact matrixMass_nonneg _ + · exact hv j hj + · exact hw k hk + · exact hMass j hj + · exact hMassStar k hk + · exact hMass k hk + _ = _ := by ring + · exact hclock + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +def mass (x : PreSpace E) : ℝ := (toFinsupp x).sum (fun _ a => ‖a‖) + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem mass_nonneg (x : PreSpace E) : 0 ≤ mass x := by + classical + exact Finset.sum_nonneg fun _ _ => norm_nonneg _ + + + +def RadiusLE (x : PreSpace E) (B : ℝ) : Prop := + ∀ e ∈ (toFinsupp x).support, ‖e‖ ≤ B + +theorem translated_coherent_bound (d e x y : E) (s : ℝ) (hs : 0 ≤ s) + (hsep : s+‖x‖+‖y‖ ≤ ‖d-e‖) : + ‖⟪W d (coherent x),W e (coherent y)⟫_ℂ‖ ≤ Real.exp (-s^2/2) := by + rw [norm_inner_translated_coherent] + apply Real.exp_le_exp.mpr + have ht := norm_sub_norm_le (d-e) (-(x-y)) + simp only [norm_neg,sub_neg_eq_add] at ht + have hxy := norm_sub_le x y + have heq : d-e+(x-y)=(d+x)-(e+y) := by abel + rw [heq] at ht + have hlow : s ≤ ‖(d+x)-(e+y)‖ := by linarith + nlinarith [norm_nonneg ((d+x)-(e+y))] + + + +theorem translated_pre_bound (d e : E) (x y : PreSpace E) (B s : ℝ) + (hx : RadiusLE x B) (hy : RadiusLE y B) (hs : 0 ≤ s) + (hsep : s+2*B ≤ ‖d-e‖) : + ‖⟪W d (↑x),W e (↑y)⟫_ℂ‖ ≤ mass x*mass y*Real.exp (-s^2/2) := by + classical + simp_rw [coe_eq_sum,Finsupp.sum,map_sum,map_smul,sum_inner,inner_sum, + inner_smul_left,inner_smul_right] + calc + _ ≤ ∑ a ∈ (toFinsupp x).support, ∑ b ∈ (toFinsupp y).support, + ‖conj ((toFinsupp x) a)*((toFinsupp y) b*⟪W d (coherent a),W e (coherent b)⟫_ℂ)‖ := by + exact (norm_sum_le _ _).trans (Finset.sum_le_sum fun a ha => norm_sum_le _ _) + _ ≤ ∑ a ∈ (toFinsupp x).support, ∑ b ∈ (toFinsupp y).support, + ‖(toFinsupp x) a‖*(‖(toFinsupp y) b‖*Real.exp (-s^2/2)) := by + apply Finset.sum_le_sum + intro a ha + apply Finset.sum_le_sum + intro b hb + simp only [norm_mul,Complex.norm_conj] + gcongr + exact translated_coherent_bound d e a b s hs (by linarith [hx a ha,hy b hb]) + _ = _ := by + simp only [mass,Finsupp.sum,Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm (s := (toFinsupp y).support)] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + ring + + +theorem scaled_translated_pre_bound (d e : E) (x y : PreSpace E) (B δ R : ℝ) + (hx : RadiusLE x B) (hy : RadiusLE y B) (hδ : 0 < δ) + (hsep : δ ≤ ‖d-e‖) (hR : 1 ≤ R) (hB : 4*B ≤ R*δ) : + ‖⟪W (R • d) (↑x),W (R • e) (↑y)⟫_ℂ‖ ≤ + mass x*mass y*Real.exp (-(δ^2/8)*R) := by + have hRn : 0 ≤ R := by linarith + have hnorm : R*δ/2+2*B ≤ ‖R • d-R • e‖ := by + rw [← smul_sub,norm_smul,Real.norm_of_nonneg hRn] + nlinarith + refine (translated_pre_bound (R • d) (R • e) x y B (R*δ/2) hx hy + (by positivity) hnorm).trans ?_ + apply mul_le_mul_of_nonneg_left _ (mul_nonneg (mass_nonneg x) (mass_nonneg y)) + apply Real.exp_le_exp.mpr + have hrr : R ≤ R^2 := by nlinarith + nlinarith [sq_nonneg δ,mul_nonneg (sq_nonneg δ) (sub_nonneg.mpr hrr)] + + + +theorem rapid_decay {α : Type*} {l : Filter α} + (R : α → ℝ) (d e : α → E) (x y : α → PreSpace E) + (hR : Tendsto R l atTop) (B A δ : ℝ) (hA : 0 ≤ A) (hδ : 0 < δ) + (hx : ∀ᶠ a in l, RadiusLE (x a) B ∧ mass (x a) ≤ A) + (hy : ∀ᶠ a in l, RadiusLE (y a) B ∧ mass (y a) ≤ A) + (hsep : ∀ᶠ a in l, δ ≤ ‖d a-e a‖) (M : ℕ) : + Tendsto (fun a => (R a)^M * ‖⟪W (R a • d a) (↑(x a)),W (R a • e a) (↑(y a))⟫_ℂ‖) + l (𝓝 0) := by + have ht : Tendsto (fun r : ℝ => r^M*Real.exp (-(δ^2/8)*r)) atTop (𝓝 0) := by + simpa only [Real.rpow_natCast] using + tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (M:ℝ) (δ^2/8) (by positivity) + have ht' := (ht.comp hR).mul_const (A*A) + have hr1 : ∀ᶠ a in l, 1 ≤ R a := hR.eventually (eventually_ge_atTop 1) + have hrB : ∀ᶠ a in l, 4*B ≤ R a*δ := by + filter_upwards [hR.eventually (eventually_ge_atTop (4*B/δ))] with a ha + exact (div_le_iff₀ hδ).mp ha + apply squeeze_zero' ?_ ?_ (by simpa using ht') + · filter_upwards [hr1] with a ha + exact mul_nonneg (pow_nonneg (by linarith) _) (norm_nonneg _) + · filter_upwards [hr1,hrB,hx,hy,hsep] with a ha hba hxa hya hsa + have hb := scaled_translated_pre_bound (d a) (e a) (x a) (y a) B δ (R a) + hxa.1 hya.1 hδ hsa ha hba + have hmass : mass (x a)*mass (y a) ≤ A*A := + mul_le_mul hxa.2 hya.2 (mass_nonneg _) hA + have hb' : ‖⟪W (R a • d a) (↑(x a)),W (R a • e a) (↑(y a))⟫_ℂ‖ ≤ + A*A*Real.exp (-(δ^2/8)*R a) := + hb.trans (mul_le_mul_of_nonneg_right hmass (Real.exp_nonneg _)) + have hm := mul_le_mul_of_nonneg_left hb' (pow_nonneg (by linarith : 0 ≤ R a) M) + rw [neg_mul] at hm + nlinarith + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +@[simp] theorem mass_basis (d : E) : mass (basis d)=1 := by + classical + simp [mass,basis] + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +@[simp] theorem mass_zero : mass (0 : PreSpace E)=0 := by simp [mass] + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem mass_add_le (x y : PreSpace E) : mass (x+y) ≤ mass x+mass y := by + convert! WeightedMass.add_le (fun _ : E => (1:ℝ)) (fun _ => zero_le_one) + (toFinsupp x) (toFinsupp y) using 1 <;> simp [mass,WeightedMass.mass] + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem mass_smul (c : ℂ) (x : PreSpace E) : mass (c • x)=‖c‖*mass x := by + convert! WeightedMass.smul (fun _ : E => (1:ℝ)) c (toFinsupp x) using 1 <;> + simp [mass,WeightedMass.mass] + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem mass_sum {ι : Type*} (s : Finset ι) (x : ι → PreSpace E) : + mass (∑ i ∈ s, x i) ≤ ∑ i ∈ s, mass (x i) := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => + simp only [Finset.sum_insert hi] + exact (mass_add_le _ _).trans (add_le_add_right ih _) + +omit [InnerProductSpace ℂ E] in +theorem RadiusLE.zero (B : ℝ) : RadiusLE (0 : PreSpace E) B := by simp [RadiusLE] + +omit [InnerProductSpace ℂ E] in +theorem RadiusLE.basis (d : E) (B : ℝ) (hd : ‖d‖ ≤ B) : RadiusLE (basis d) B := by + classical + simpa [RadiusLE,CoherentFock.basis] using hd + +omit [InnerProductSpace ℂ E] in +theorem RadiusLE.add {x y : PreSpace E} {B : ℝ} (hx : RadiusLE x B) (hy : RadiusLE y B) : + RadiusLE (x+y) B := by + classical + intro d hd + rw [map_add] at hd + rcases Finset.mem_union.mp (Finsupp.support_add hd) with h|h + · exact hx d h + · exact hy d h + +omit [InnerProductSpace ℂ E] in +theorem RadiusLE.smul {x : PreSpace E} {B : ℝ} (hx : RadiusLE x B) (c : ℂ) : + RadiusLE (c • x) B := by + intro d hd + rw [map_smul] at hd + exact hx d (Finsupp.support_smul hd) + +omit [InnerProductSpace ℂ E] in +theorem RadiusLE.sum {ι : Type*} (s : Finset ι) (x : ι → PreSpace E) (B : ℝ) + (hx : ∀ i ∈ s, RadiusLE (x i) B) : RadiusLE (∑ i ∈ s, x i) B := by + classical + induction s using Finset.induction_on with + | empty => simpa using RadiusLE.zero B + | @insert i s hi ih => + rw [Finset.sum_insert hi] + exact (hx i (Finset.mem_insert_self _ _)).add + (ih (fun j hj => hx j (Finset.mem_insert_of_mem hj))) + +omit [InnerProductSpace ℂ E] in +theorem RadiusLE.mono {x : PreSpace E} {B C : ℝ} (hx : RadiusLE x B) (hBC : B ≤ C) : + RadiusLE x C := fun d hd => (hx d hd).trans hBC + +theorem mass_preW_le (d : E) (x : PreSpace E) : mass (preWLinear d x) ≤ mass x := by + classical + conv_lhs => rw [← sum_basis x] + simp only [Finsupp.sum,map_sum] + calc + _ ≤ ∑ e ∈ (toFinsupp x).support, mass (preWLinear d ((toFinsupp x) e • basis e)) := + mass_sum _ _ + _ = mass x := by + simp only [map_smul,preWLinear_basis,mass_smul,mass_basis,norm_phase,mul_one] + rfl + +theorem RadiusLE.preW {x : PreSpace E} {B : ℝ} (hx : RadiusLE x B) (d : E) : + RadiusLE (preWLinear d x) (‖d‖+B) := by + classical + rw [← sum_basis x] + simp only [Finsupp.sum,map_sum] + apply RadiusLE.sum + intro e he + rw [map_smul,preWLinear_basis] + exact ((RadiusLE.basis (d+e) _ ((norm_add_le _ _).trans (add_le_add_right (hx e he) _))).smul _).smul _ + +omit [InnerProductSpace ℂ E] in +theorem secondTailBound_le_mass (x : PreSpace E) {B : ℝ} (_hB : 0 ≤ B) (hx : RadiusLE x B) : + secondTailBound x ≤ mass x*(1+2*B+12*B^2) := by + classical + simp only [secondTailBound,mass,Finsupp.sum,Finset.sum_mul] + apply Finset.sum_le_sum + intro d hd + gcongr <;> exact hx d hd + + + +theorem finite_packet_displacement (d : E) (x : PreSpace E) {B C : ℝ} + (hx : RadiusLE x B) (hd : ‖d‖ ≤ C) : + (↑(preWLinear d x) : Space E)=W d (↑x) ∧ + mass (preWLinear d x) ≤ mass x ∧ RadiusLE (preWLinear d x) (C+B) := by + exact ⟨(W_coe d x).symm,mass_preW_le d x,(hx.preW d).mono (by linarith)⟩ + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +variable {E' : Type*} [SeminormedAddCommGroup E'] [InnerProductSpace ℂ E'] + +theorem mass_preGamma_le (T : E →ₗᵢ[ℂ] E') (x : PreSpace E) : + mass (preGammaLinear T x) ≤ mass x := by + classical + conv_lhs => rw [← sum_basis x] + simp only [Finsupp.sum,map_sum] + calc + _ ≤ ∑ e ∈ (toFinsupp x).support, mass (preGammaLinear T ((toFinsupp x) e • basis e)) := + mass_sum _ _ + _ = mass x := by + simp only [map_smul,preGammaLinear_basis,mass_smul,mass_basis,mul_one] + rfl + +theorem RadiusLE.preGamma {x : PreSpace E} {B : ℝ} (hx : RadiusLE x B) (T : E →ₗᵢ[ℂ] E') : + RadiusLE (preGammaLinear T x) B := by + classical + rw [← sum_basis x] + simp only [Finsupp.sum,map_sum] + apply RadiusLE.sum + intro e he + rw [map_smul,preGammaLinear_basis] + exact (RadiusLE.basis (T e) _ (by simpa using hx e he)).smul _ + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +def spinMass (x : PreSpin E) : ℝ := ∑ i, mass (x i) + +def SpinRadiusLE (x : PreSpin E) (B : ℝ) : Prop := ∀ i, RadiusLE (x i) B + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem spinMass_nonneg (x : PreSpin E) : 0 ≤ spinMass x := + Finset.sum_nonneg (fun i _ => mass_nonneg (x i)) + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem mass_le_spinMass (x : PreSpin E) (i : Fin 2) : mass (x i) ≤ spinMass x := + Finset.single_le_sum (fun j _ => mass_nonneg (x j)) (Finset.mem_univ i) + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem spinMass_preRoot (A : Matrix (Fin 2) (Fin 2) ℂ) (x : PreSpin E) : + spinMass (preRoot A x) ≤ matrixMass A*spinMass x := by + classical + unfold spinMass preRoot + calc + _ ≤ ∑ i : Fin 2, ∑ j : Fin 2, ‖A i j‖*mass (x j) := by + apply Finset.sum_le_sum + intro i hi + simpa only [mass_smul] using mass_sum Finset.univ (fun j => A i j • x j) + _ ≤ ∑ i : Fin 2, ∑ j : Fin 2, ‖A i j‖*spinMass x := by + apply Finset.sum_le_sum + intro i hi + apply Finset.sum_le_sum + intro j hj + exact mul_le_mul_of_nonneg_left (mass_le_spinMass x j) (norm_nonneg _) + _ = _ := by simp only [matrixMass,Finset.sum_mul,spinMass] + +omit [InnerProductSpace ℂ E] in +theorem SpinRadiusLE.preRoot {x : PreSpin E} {B : ℝ} (hx : SpinRadiusLE x B) + (A : Matrix (Fin 2) (Fin 2) ℂ) : SpinRadiusLE (preRoot A x) B := by + intro i + exact RadiusLE.sum Finset.univ (fun j => A i j • x j) B (fun j _ => (hx j).smul _) + +omit [InnerProductSpace ℂ E] in +theorem spinBound_le_mass (x : PreSpin E) {B : ℝ} (hB : 0 ≤ B) (hx : SpinRadiusLE x B) : + spinBound x ≤ spinMass x*(1+2*B+12*B^2) := by + unfold spinBound spinMass + rw [Finset.sum_mul] + exact Finset.sum_le_sum (fun i _ => secondTailBound_le_mass (x i) hB (hx i)) + +def preWZ (d : E) (x : PreSpin E) : PreSpin E := + fun i => preWLinear (if i=0 then d else -d) (x i) + +@[simp] theorem spinCoe_preWZ (d : E) (x : PreSpin E) : spinCoe (preWZ d x)=WZ d (spinCoe x) := by + ext i + simp only [spinCoe_apply,preWZ,WZ_apply,W_coe] + +theorem spinMass_preWZ (d : E) (x : PreSpin E) : spinMass (preWZ d x) ≤ spinMass x := + Finset.sum_le_sum (fun i _ => mass_preW_le _ (x i)) + +theorem SpinRadiusLE.preWZ {x : PreSpin E} {B : ℝ} (hx : SpinRadiusLE x B) (d : E) : + SpinRadiusLE (preWZ d x) (‖d‖+B) := by + intro i + change RadiusLE (preWLinear (if i=0 then d else -d) (x i)) (‖d‖+B) + split_ifs + · exact (hx i).preW d + · simpa only [norm_neg] using (hx i).preW (-d) + + +def preProbe (A : Matrix (Fin 2) (Fin 2) ℂ) (d : E) (x : PreSpin E) : PreSpin E := + preRoot A.conjTranspose (preWZ d (preRoot A x)) + +@[simp] theorem spinCoe_preProbe (A : Matrix (Fin 2) (Fin 2) ℂ) (d : E) (x : PreSpin E) : + spinCoe (preProbe A d x)=probe A d (spinCoe x) := by + simp only [preProbe,spinCoe_preRoot,spinCoe_preWZ,probe_apply] + +theorem spinMass_preProbe (A : Matrix (Fin 2) (Fin 2) ℂ) (d : E) (x : PreSpin E) : + spinMass (preProbe A d x) ≤ matrixMass A.conjTranspose*matrixMass A*spinMass x := by + apply (spinMass_preRoot _ _).trans + calc + _ ≤ matrixMass A.conjTranspose*spinMass (preRoot A x) := + mul_le_mul_of_nonneg_left (spinMass_preWZ _ _) (matrixMass_nonneg _) + _ ≤ matrixMass A.conjTranspose*(matrixMass A*spinMass x) := + mul_le_mul_of_nonneg_left (spinMass_preRoot _ _) (matrixMass_nonneg _) + _ = _ := by ring + +theorem SpinRadiusLE.preProbe {x : PreSpin E} {B : ℝ} (hx : SpinRadiusLE x B) + (A : Matrix (Fin 2) (Fin 2) ℂ) (d : E) : SpinRadiusLE (preProbe A d x) (‖d‖+B) := + ((hx.preRoot A).preWZ d).preRoot A.conjTranspose + +end CoherentFock + +namespace ProbeProduct +variable {ι H : Type*} [NormedAddCommGroup H] [NormedSpace ℂ H] + + + +theorem perturbation_bound (T S : ι → H →L[ℂ] H) (l : List ι) (ε : ℝ) + (hε : 0 ≤ ε) (hT : ∀ j ∈ l, ∀x, ‖T j x‖ ≤ ‖x‖) + (hS : ∀ j ∈ l, ∀x, ‖S j x‖ ≤ ‖x‖) + (hE : ∀ j ∈ l, ∀x, ‖T j x-S j x‖ ≤ ε*‖x‖) (x : H) : + ‖act T l x-act S l x‖ ≤ l.length*ε*‖x‖ := by + induction l with + | nil => simp + | cons j l ih => + have hTl : ∀ k ∈ l, ∀z, ‖T k z‖ ≤ ‖z‖ := fun k hk => hT k (by simp [hk]) + have hSl : ∀ k ∈ l, ∀z, ‖S k z‖ ≤ ‖z‖ := fun k hk => hS k (by simp [hk]) + have hEl : ∀ k ∈ l, ∀z, ‖T k z-S k z‖ ≤ ε*‖z‖ := fun k hk => hE k (by simp [hk]) + have hi := ih hTl hSl hEl + have he : act T (j::l) x-act S (j::l) x = + T j (act T l x-act S l x)+(T j (act S l x)-S j (act S l x)) := by + simp only [act_cons,map_sub] + abel + rw [he] + calc + _ ≤ ‖T j (act T l x-act S l x)‖+‖T j (act S l x)-S j (act S l x)‖ := norm_add_le _ _ + _ ≤ l.length*ε*‖x‖+ε*‖act S l x‖ := + add_le_add ((hT j (by simp) _).trans hi) (hE j (by simp) _) + _ ≤ l.length*ε*‖x‖+ε*‖x‖ := by + gcongr + exact norm_act_le S l hSl x + _ = _ := by simp only [List.length_cons,Nat.cast_add,Nat.cast_one]; ring + +end ProbeProduct + +namespace CoherentFock +open Complex +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + +def spinW (d : E) : SpinSpace E →L[ℂ] SpinSpace E := + (PiLp.continuousLinearEquiv 2 ℂ (fun _ : Fin 2 => Space E)).symm.toContinuousLinearMap.comp + (ContinuousLinearMap.pi fun i => (W d).comp (PiLp.proj 2 (fun _ : Fin 2 => Space E) i)) + +@[simp] theorem spinW_apply (d : E) (x : SpinSpace E) (i : Fin 2) : spinW d x i=W d (x i) := rfl + +@[simp] theorem norm_spinW (d : E) (x : SpinSpace E) : ‖spinW d x‖=‖x‖ := by + have hh : ‖spinW d x‖^2=‖x‖^2 := by + rw [PiLp.norm_sq_eq_of_L2,PiLp.norm_sq_eq_of_L2] + simp + nlinarith [norm_nonneg x,norm_nonneg (spinW d x)] + +theorem spinW_root (d : E) (A : Matrix (Fin 2) (Fin 2) ℂ) (x : SpinSpace E) : + spinW d (SpinOperators.act A x)=SpinOperators.act A (spinW d x) := by + ext i + simp only [spinW_apply,SpinOperators.act_apply,map_sum,map_smul] + +def phaseZ (θ : ℝ) : SpinSpace E →L[ℂ] SpinSpace E := + SpinOperators.act (Matrix.diagonal fun i : Fin 2 => + Complex.exp (((if i=0 then θ else -θ : ℝ):ℂ)*I)) + +@[simp] theorem phaseZ_apply (θ : ℝ) (x : SpinSpace E) (i : Fin 2) : + phaseZ θ x i=Complex.exp (((if i=0 then θ else -θ : ℝ):ℂ)*I) • x i := by + simp [phaseZ,SpinOperators.act_apply,Matrix.diagonal_apply] + +@[simp] theorem norm_phaseZ (θ : ℝ) (x : SpinSpace E) : ‖phaseZ θ x‖=‖x‖ := by + have hh : ‖phaseZ θ x‖^2=‖x‖^2 := by + rw [PiLp.norm_sq_eq_of_L2,PiLp.norm_sq_eq_of_L2] + simp only [phaseZ_apply,norm_smul,Complex.norm_exp_ofReal_mul_I,one_mul] + nlinarith [norm_nonneg x,norm_nonneg (phaseZ θ x)] + +theorem phaseZ_sub_le (θ : ℝ) (x : SpinSpace E) : ‖phaseZ θ x-x‖ ≤ |θ| *‖x‖ := by + have hc (i : Fin 2) : ‖(phaseZ θ x-x) i‖ ≤ |θ| *‖x i‖ := by + simp only [PiLp.sub_apply,phaseZ_apply] + have he : Complex.exp (((if i=0 then θ else -θ : ℝ):ℂ)*I) • x i-x i = + (Complex.exp (((if i=0 then θ else -θ : ℝ):ℂ)*I)-1) • x i := by + rw [sub_smul,one_smul] + rw [he,norm_smul] + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + split_ifs + · simpa only [mul_comm,Real.norm_eq_abs] using Real.norm_exp_I_mul_ofReal_sub_one_le (x := θ) + · simpa only [mul_comm,Real.norm_eq_abs,abs_neg] using Real.norm_exp_I_mul_ofReal_sub_one_le (x := -θ) + have hh : ‖phaseZ θ x-x‖^2 ≤ (|θ| *‖x‖)^2 := by + rw [PiLp.norm_sq_eq_of_L2,mul_pow,PiLp.norm_sq_eq_of_L2,Finset.mul_sum] + apply Finset.sum_le_sum + intro i hi + have := hc i + nlinarith [norm_nonneg ((phaseZ θ x-x) i),norm_nonneg (x i),abs_nonneg θ] + nlinarith [norm_nonneg (phaseZ θ x-x),mul_nonneg (abs_nonneg θ) (norm_nonneg x)] + + + +theorem centered_WZ (d e : E) (x : SpinSpace E) : + spinW (-e) (WZ d (spinW e x))=phaseZ (-2*(⟪d,e⟫_ℂ).im) (WZ d x) := by + ext i + simp only [spinW_apply,WZ_apply,phaseZ_apply] + split_ifs with hi + · exact congrArg (fun T : Space E →L[ℂ] Space E => T (x i)) (centered_probe d e) + · simpa only [inner_neg_left,Complex.neg_im,mul_neg,neg_mul,neg_neg, + ContinuousLinearMap.comp_apply,smul_apply] + using congrArg (fun T : Space E →L[ℂ] Space E => T (x i)) (centered_probe (-d) e) + + +def probePhase (A : Matrix (Fin 2) (Fin 2) ℂ) (θ : ℝ) : SpinSpace E →L[ℂ] SpinSpace E := + (SpinOperators.act A.conjTranspose).comp ((phaseZ θ).comp (SpinOperators.act A)) + +@[simp] theorem probePhase_apply (A : Matrix (Fin 2) (Fin 2) ℂ) (θ : ℝ) (x : SpinSpace E) : + probePhase A θ x=SpinOperators.act A.conjTranspose (phaseZ θ (SpinOperators.act A x)) := rfl + +@[simp] theorem norm_probePhase (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) (θ : ℝ) + (x : SpinSpace E) : ‖probePhase A θ x‖=‖x‖ := by + rw [probePhase_apply,SpinOperators.norm_act (root_adjoint_unitary A hA),norm_phaseZ,SpinOperators.norm_act hA] + +theorem probePhase_sub_le (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) (θ : ℝ) + (x : SpinSpace E) : ‖probePhase A θ x-x‖ ≤ |θ| *‖x‖ := by + have he : probePhase A θ x-x=SpinOperators.act A.conjTranspose + (phaseZ θ (SpinOperators.act A x)-SpinOperators.act A x) := by + rw [map_sub,root_left_inverse A hA] + rfl + rw [he,SpinOperators.norm_act (root_adjoint_unitary A hA)] + simpa only [SpinOperators.norm_act hA] using phaseZ_sub_le θ (SpinOperators.act A x) + +theorem root_right_inverse (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (x : SpinSpace E) : SpinOperators.act A (SpinOperators.act A.conjTranspose x)=x := by + simpa only [Matrix.conjTranspose_conjTranspose] using + root_left_inverse A.conjTranspose (root_adjoint_unitary A hA) x + + +theorem centered_toggled_probe (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (d e : E) (x : SpinSpace E) : + spinW (-e) (probe A d (spinW e x))= + probePhase A (-2*(⟪d,e⟫_ℂ).im) (probe A d x) := by + rw [probe_apply,spinW_root,← spinW_root e A x,centered_WZ] + simp only [probePhase_apply,probe_apply,root_right_inverse A hA] + +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ActualCenterPhase.lean b/lean/OAI/Probability/ParisiFinite/ActualCenterPhase.lean new file mode 100644 index 0000000000000000000000000000000000000000..85b1c36cce6d985818ae70f24ee5066631aea9c0 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ActualCenterPhase.lean @@ -0,0 +1,705 @@ +import Mathlib +import OAI.Probability.ParisiFinite.IdentityErrorFinSumTendsto + +namespace OAI + +/-! Actual Center Phase. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +namespace PointedTree +open CoherentFock RootSpin +local instance phaseRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance phaseRealSMul : SMul ℝ ModeInfinity := phaseRealModule.toDistribMulAction.toSMul + + +theorem actual_center_phase (r S : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) (d : ModeInfinity) : + -2*(⟪actualDisplacement r w a k,S • d⟫_ℂ).im= + 2*r*S*(a k).2*(⟪actualProbeDirection r w a k,d⟫_ℂ).im := by + exact short_large_phase r S (a k).2 _ d + + + +theorem scaled_huge_center_phase {α : Type*} {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) (t : ℝ) + (hscale : ∀ᶠ q in l,r q*S q=1) + (hsmall : Tendsto (fun q => S q*|(⟪actualProbeDirection (r q) (w q) a k,insertionInfinity (w q)⟫_ℂ).im|) l (𝓝 0)) : + Tendsto (fun q => S q*|(-2*(⟪actualDisplacement (r q) (w q) a k, + S q • (t • insertionInfinity (w q))⟫_ℂ).im)|) l (𝓝 0) := by + have h := hsmall.mul_const |2*(a k).2*t| + simp only [zero_mul] at h + apply h.congr' + filter_upwards [hscale] with q hq + rw [actual_center_phase] + rw [RCLike.real_smul_eq_coe_smul (K:=ℂ) t (insertionInfinity (w q)),inner_smul_real_right, + Complex.smul_im,smul_eq_mul] + have he : 2*r q*S q*(a k).2*(t*(⟪actualProbeDirection (r q) (w q) a k,insertionInfinity (w q)⟫_ℂ).im)= + (2*(a k).2*t)*(⟪actualProbeDirection (r q) (w q) a k,insertionInfinity (w q)⟫_ℂ).im := by + calc + _ = (r q*S q)*((2*(a k).2*t)*(⟪actualProbeDirection (r q) (w q) a k,insertionInfinity (w q)⟫_ℂ).im) := by ring + _ = _ := by rw [hq,one_mul] + simp only [he,abs_mul] + ring + + + +theorem actual_special_phase_tendsto {α : Type*} {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (d : α → ModeInfinity) (C c : ℝ) (_hC : 0≤C) + (hscale : ∀ᶠ q in l,r q*S q=1) (hd : ∀ᶠ q in l,‖d q‖≤C) + (hchange : Tendsto (fun q => ‖actualProbeDirection (r q) (w q) a k- + insertionInfinity (.mixer (a k).1::w q)‖) l (𝓝 0)) + (hstart : Tendsto (fun q => (⟪insertionInfinity (.mixer (a k).1::w q),d q⟫_ℂ).im) l (𝓝 c)) : + Tendsto (fun q => -2*(⟪actualDisplacement (r q) (w q) a k,S q • d q⟫_ℂ).im) + l (𝓝 (2*(a k).2*c)) := by + have hdiff : Tendsto (fun q => (⟪actualProbeDirection (r q) (w q) a k,d q⟫_ℂ).im- + (⟪insertionInfinity (.mixer (a k).1::w q),d q⟫_ℂ).im) l (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + have hlo := hchange.mul_const C + simp only [zero_mul] at hlo + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ hlo + filter_upwards [hd] with q hq + exact (imaginary_projection_difference _ _ _).trans + (mul_le_mul_of_nonneg_left hq (norm_nonneg _)) + have hsum := hdiff.add hstart + simp only [sub_add_cancel,zero_add] at hsum + have h := hsum.const_mul (2*(a k).2) + apply h.congr' + filter_upwards [hscale] with q hq + rw [actual_center_phase] + symm + calc + _ = (r q*S q)*((2*(a k).2)*(⟪actualProbeDirection (r q) (w q) a k,d q⟫_ℂ).im) := by ring + _ = _ := by rw [hq,one_mul] + +end PointedTree + + + +open scoped InnerProductSpace Topology +open Filter +namespace PointedTree +open CoherentFock RootSpin + + + +theorem rotated_imaginary (w : List Gate) (β : ℝ) (d : ModeInfinity) : + -2*(⟪insertionInfinity (.mixer β::w),d⟫_ℂ).im= + Real.cos (2*β)*(-2*(⟪insertionInfinity w,d⟫_ℂ).im)+ + Real.sin (2*β)*(-2*(⟪insertionYInfinity w,d⟫_ℂ).im) := by + rw [rotated_insertion_eq,inner_add_left,inner_smul_left,inner_smul_left] + simp only [Complex.add_im,Complex.conj_ofReal,Complex.mul_im,Complex.ofReal_re, + Complex.ofReal_im,zero_mul,add_zero] + ring + + + +theorem rotated_projection_tendsto {α : Type*} {l : Filter α} + (w : α → List Gate) (d : α → ModeInfinity) (v : ℝ×ℝ) (β : ℝ) + (hZ : Tendsto (fun t => -2*(⟪insertionInfinity (w t),d t⟫_ℂ).im) l (𝓝 v.1)) + (hY : Tendsto (fun t => -2*(⟪insertionYInfinity (w t),d t⟫_ℂ).im) l (𝓝 v.2)) : + Tendsto (fun t => (⟪insertionInfinity (.mixer β::w t),d t⟫_ℂ).im) l + (𝓝 (-(Real.cos (2*β)*v.1+Real.sin (2*β)*v.2)/2)) := by + have h := ((hZ.const_mul (Real.cos (2*β))).add (hY.const_mul (Real.sin (2*β)))).mul_const (-1/2) + convert! h using 1 + · ext t + have he := rotated_imaginary (w t) β (d t) + linarith + · congr 1 + ring + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin + + + +theorem actual_special_packet_tendsto {α : Type*} {l : Filter α} + (r : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : α → ModeInfinity) (x : α → PreSpin ModeInfinity) (φ : ℕ → ℝ) + (T B A : ℝ) (hT : 0≤T) (_hB : 0≤B) (_hA : 0≤A) + (ha : ∀j -2*(⟪actualDisplacement (r t) (w t) a j,e t⟫_ℂ).im) l (𝓝 (φ j))) + (hx : ∀ᶠ t in l,spinBound (x t)≤B ∧ ‖spinCoe (x t)‖≤A) : + Tendsto (fun t => ‖spinW (-e t) (probeGain (r t) (w t) a k (spinW (e t) (spinCoe (x t))))- + ProbeProduct.act (fun j => probePhase (R (a j).1) (φ j)) (List.range k).reverse (spinCoe (x t))‖) l (𝓝 0) := by + let err (t : α) (j : ℕ) := (-2*(⟪actualDisplacement (r t) (w t) a j,e t⟫_ℂ).im)-φ j + let η (t : α) := FiniteError.envelope k (err t) + have hη : Tendsto η l (𝓝 0) := FiniteError.envelope_tendsto_zero k err (by + intro j hj + simpa only [sub_self] using (hphase j hj).sub_const (φ j)) + have habs : Tendsto (fun t => |r t|) l (𝓝 0) := by simpa only [abs_zero] using hr0.abs + have hlim := ((((((habs.mul_const T).pow 2).add (habs.mul_const T)).mul_const 4).mul_const (k:ℝ)).mul_const ((4^2:ℝ)^k)).mul_const B + have hlim' := hlim.add ((hη.const_mul (k:ℝ)).mul_const A) + simp only [zero_mul,zero_pow (by decide : 2≠0),add_zero,mul_zero] at hlim' + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ hlim' + filter_upwards [hx] with t hxt + rw [probeGain_product] + have hb := special_product_bound (List.range k).reverse (fun j => R (a j).1) + (actualDisplacement (r t) (w t) a) (e t) φ (|r t| *T) 4 (η t) + (by positivity) (by norm_num) (FiniteError.envelope_nonneg ..) + (fun j _ => R_unitary _) + (by intro j hj; rw [List.mem_reverse,List.mem_range] at hj + rw [norm_actualDisplacement]; exact mul_le_mul_of_nonneg_left (ha j hj) (abs_nonneg _)) + (fun j _ => matrixMass_R_le _) (fun j _ => by rw [R_star]; exact matrixMass_R_le _) + (by intro j hj; rw [List.mem_reverse,List.mem_range] at hj; exact FiniteError.le_envelope k (err t) j hj) (x t) + have hf : (fun j => probe (R (a j).1) (actualDisplacement (r t) (w t) a j))=actualProbe (r t) (w t) a := by + funext j; rfl + rw [hf] at hb + simp only [List.length_reverse,List.length_range] at hb + apply hb.trans + exact add_le_add (mul_le_mul_of_nonneg_left hxt.1 (by positivity)) + (mul_le_mul_of_nonneg_left hxt.2 (mul_nonneg (Nat.cast_nonneg _) (FiniteError.envelope_nonneg ..))) + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance selectRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance selectRealSMul : SMul ℝ ModeInfinity := selectRealModule.toDistribMulAction.toSMul + + + +theorem actual_rotation_on_special {α : Type*} {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (K : ℕ) + (d : α → ModeInfinity) (x : α → PreSpin ModeInfinity) (v : ℝ×ℝ) (θ : ℝ) + (C T B A : ℝ) (hC : 0≤C) (hT : 0≤T) (hB : 0≤B) (hA : 0≤A) + (ha : ∀j ‖actualProbeDirection (r t) (w t) a j- + insertionInfinity (.mixer (a j).1::w t)‖) l (𝓝 0)) + (hZ : Tendsto (fun t => -2*(⟪insertionInfinity (w t),d t⟫_ℂ).im) l (𝓝 v.1)) + (hY : Tendsto (fun t => -2*(⟪insertionYInfinity (w t),d t⟫_ℂ).im) l (𝓝 v.2)) + (hprod : ProbeProduct.act (fun j => probePhase (E:=ModeInfinity) (R (a j).1) + (projectionPhase v (a j))) (List.range K).reverse=SpinOperators.act (R θ)) : + Tendsto (fun t => ‖spinW (-(S t • d t)) + (probeGain (r t) (w t) a K (actualPacket (S t) (d t) (x t)))- + SpinOperators.act (R θ) (spinCoe (x t))‖) l (𝓝 0) := by + have hp : ∀j -2*(⟪actualDisplacement (r t) (w t) a j,S t • d t⟫_ℂ).im) + l (𝓝 (projectionPhase v (a j))) := by + intro j hj + have h := actual_special_phase_tendsto r S w a j d C + (-(Real.cos (2*(a j).1)*v.1+Real.sin (2*(a j).1)*v.2)/2) + hC hscale hd (hchange j hj) (rotated_projection_tendsto w d v (a j).1 hZ hY) + convert! h using 1 + congr 1 + dsimp only [projectionPhase] + ring + have hx' : ∀ᶠ t in l,spinBound (x t)≤A*(1+2*B+12*B^2) ∧ ‖spinCoe (x t)‖≤A := by + filter_upwards [hx] with t ht + exact tail_bounds_of_radius_mass (x t) B A hB ht + have h := actual_special_packet_tendsto r w a K (fun t => S t • d t) x + (fun j => projectionPhase v (a j)) T (A*(1+2*B+12*B^2)) A hT (by positivity) hA + ha hr hp hx' + simpa only [hprod,actualPacket] using h + + + +theorem selective_packet_accuracy {α ι κ : Type*} [Fintype ι] [Fintype κ] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) + (d : ι → α → ModeInfinity) (x : ι → α → PreSpin ModeInfinity) + (s ρ : α → SpinSpace ModeInfinity) (B A : ℝ) (hB : 0≤B) (hA : 0≤A) + (v : κ → ℝ×ℝ) (hv : ∀i,v i≠0) (θ : ℝ) + (hr : Tendsto r l (𝓝 0)) (hS : ∀ᶠ t in l,1≤S t) + (hscale : ∀ᶠ t in l,0≤r t ∧ 0≤S t ∧ S t*r t=1) + (hx : ∀i,∀ᶠ t in l,SpinRadiusLE (x i t) B ∧ spinMass (x i t)≤A) + (hψ : ∀ᶠ t in l,ordinaryLocal (w t) (vacuum ModeInfinity)= + (∑i,actualPacket (S t) (d i t) (x i t))+s t+ρ t) + (hs : Tendsto (fun t => ‖s t‖) l (𝓝 0)) (hρ : Tendsto (fun t => ‖ρ t‖) l (𝓝 0)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse) (T : ℝ),0≤T ∧ (∀j S t*|-2*(⟪actualDisplacement (r t) (w t) a j,S t • d i t⟫_ℂ).im|) l (𝓝 0)) → + (∀ (e : α → ModeInfinity) (z : α → PreSpin ModeInfinity) (B' A' : ℝ),0≤B' → 0≤A' → + (∀ᶠ t in l,SpinRadiusLE (z t) B' ∧ spinMass (z t)≤A') → + (∀j S t*|-2*(⟪actualDisplacement (r t) (w t) a j,S t • e t⟫_ℂ).im|) l (𝓝 0)) → + Tendsto (fun t => S t*‖probeGain (r t) (w t) a K (actualPacket (S t) (e t) (z t))- + actualPacket (S t) (e t) (z t)‖) l (𝓝 0)) ∧ + (∀ (i : κ) (e : α → ModeInfinity) (z : α → PreSpin ModeInfinity) (C B' A' : ℝ), + 0≤C → 0≤B' → 0≤A' → (∀ᶠ t in l,‖e t‖≤C) → + (∀ᶠ t in l,SpinRadiusLE (z t) B' ∧ spinMass (z t)≤A') → + Tendsto (fun t => -2*(⟪insertionInfinity (w t),e t⟫_ℂ).im) l (𝓝 (v i).1) → + Tendsto (fun t => -2*(⟪insertionYInfinity (w t),e t⟫_ℂ).im) l (𝓝 (v i).2) → + Tendsto (fun t => ‖spinW (-(S t • e t)) + (probeGain (r t) (w t) a K (actualPacket (S t) (e t) (z t)))- + SpinOperators.act (R θ) (spinCoe (z t))‖) l (𝓝 0))) := by + obtain ⟨K,a,T,hT,ha,hclock,hprod⟩ := selective_phase_control v hv θ + refine ⟨K,a,T,hT,ha,?_⟩ + intro hp + have hΔ := packet_direction_envelope_tendsto r S w a K d x s ρ B A T hB hA hT ha hr hS hx hp hψ hs hρ + have hc : ∀j ‖actualProbeDirection (r t) (w t) a j- + insertionInfinity (.mixer (a j).1::w t)‖) l (𝓝 0) := by + intro j hj + apply squeeze_zero (fun _ => norm_nonneg _) (fun t => ?_) hΔ + simpa only [abs_norm] using FiniteError.le_envelope K + (fun j => ‖actualProbeDirection (r t) (w t) a j-insertionInfinity (.mixer (a j).1::w t)‖) j hj + constructor + · intro e z B' A' hB' hA' hz he + exact packet_zero_clock_from_vacuum r S w a K d x s ρ B A T hB hA hT ha hr hS + hscale hx hp hψ hs hρ e z B' A' hB' hA' hz he + (Eventually.of_forall (fun t => hclock (w t) (z t))) + · intro i e z C B' A' hC hB' hA' he hz hZ hY + exact actual_rotation_on_special r S w a K e z (v i) θ C T B' A' hC hT hB' hA' + ha hr (hscale.mono (fun t ht => by rw [mul_comm]; exact ht.2.2)) he hz hc hZ hY (hprod i) + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +@[simp] theorem spinW_neg_cancel (d : E) (x : SpinSpace E) : spinW (-d) (spinW d x)=x := by + ext i + simp only [spinW_apply] + exact W_neg_cancel_left d (x i) + + + +theorem centered_rotation_error (d : E) (A : Matrix (Fin 2) (Fin 2) ℂ) + (V : SpinSpace E →ₗ[ℂ] SpinSpace E) (x : SpinSpace E) : + ‖spinW (-d) (V (spinW d x))-SpinOperators.act A x‖= + ‖V (spinW d x)-SpinOperators.act A (spinW d x)‖ := by + rw [←spinW_neg_cancel d (SpinOperators.act A x),spinW_root d A x, + ←map_sub,norm_spinW] + +end CoherentFock + +namespace ForwardControl +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + + + +theorem difference_sum_remainder_bound {ι : Type*} [Fintype ι] + (V : H ≃ₗᵢ[ℂ] H) (F : H →L[ℂ] H) (hF : ∀x,‖F x‖≤‖x‖) + (x : ι → H) (ρ : H) : + ‖V ((∑i,x i)+ρ)-F ((∑i,x i)+ρ)‖≤(∑i,‖V (x i)-F (x i)‖)+2*‖ρ‖ := by + have he : V ((∑i,x i)+ρ)-F ((∑i,x i)+ρ)= + (∑i,(V (x i)-F (x i)))+(V ρ-F ρ) := by + simp only [map_add,map_sum,Finset.sum_sub_distrib] + abel + rw [he] + apply (norm_add_le _ _).trans + apply add_le_add (norm_sum_le _ _) + calc + _ ≤ ‖V ρ‖+‖F ρ‖ := norm_sub_le _ _ + _ ≤ ‖ρ‖+‖ρ‖ := add_le_add (V.norm_map _).le (hF _) + _ = _ := by ring + + + +theorem scaled_difference_finSum_tendsto {α ι : Type*} [Fintype ι] {l : Filter α} + (V : α → H ≃ₗᵢ[ℂ] H) (F : H →L[ℂ] H) (hF : ∀x,‖F x‖≤‖x‖) + (S : α → ℝ) (x : α → ι → H) (ρ : α → H) + (hS : ∀ᶠ t in l,0≤S t) + (hx : ∀i,Tendsto (fun t => S t*‖V t (x t i)-F (x t i)‖) l (𝓝 0)) + (hρ : Tendsto (fun t => S t*‖ρ t‖) l (𝓝 0)) : + Tendsto (fun t => S t*‖V t ((∑i,x t i)+ρ t)-F ((∑i,x t i)+ρ t)‖) l (𝓝 0) := by + have hsum := tendsto_finsetSum Finset.univ (fun i _ => hx i) + simp only [Finset.sum_const_zero] at hsum + have h := hsum.add (hρ.mul_const 2) + simp only [zero_mul,add_zero] at h + apply squeeze_zero' _ _ h + · filter_upwards [hS] with t ht + exact mul_nonneg ht (norm_nonneg _) + · filter_upwards [hS] with t ht + have hb := mul_le_mul_of_nonneg_left (difference_sum_remainder_bound (V t) F hF (x t) (ρ t)) ht + simpa only [mul_add,Finset.mul_sum,mul_left_comm (S t) 2,mul_comm 2 (S t*‖ρ t‖)] using hb + + +theorem scaled_amplitude_error {α : Type*} {l : Filter α} + (V : α → H ≃ₗᵢ[ℂ] H) (F : H →L[ℂ] H) (r S : α → ℝ) (x : α → H) + (hscale : ∀ᶠ t in l,0≤r t ∧ S t*r t=1) + (hx : Tendsto (fun t => ‖V t (x t)-F (x t)‖) l (𝓝 0)) : + Tendsto (fun t => S t*‖V t ((r t:ℂ) • x t)-F ((r t:ℂ) • x t)‖) l (𝓝 0) := by + apply hx.congr' + filter_upwards [hscale] with t ht + simp only [map_smul,←smul_sub,norm_smul,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg ht.1,←mul_assoc,ht.2,one_mul] + +end ForwardControl + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace ForwardControl +variable {H α : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] {l : Filter α} + + + +theorem scaled_special_transport (U V : α → H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H) + (hZ : ∀x,‖Z x‖≤‖x‖) (hanti : ∀x,Z (F x)= -F (Z x)) + (s w : α → H) (S : α → ℝ) (hS : ∀ᶠ t in l,0≤S t) + (h1 : Tendsto (fun t => S t*‖V t (s t)-F (s t)‖) l (𝓝 0)) + (h2 : Tendsto (fun t => S t*‖V t (Z (s t))-F (Z (s t))‖) l (𝓝 0)) + (ht : Tendsto (fun t => ‖(S t:ℂ) • (U t).symm (Z (s t))-w t‖) l (𝓝 0)) : + Tendsto (fun t => ‖(S t:ℂ) • (U t).symm ((V t).symm (Z (V t (s t))))+w t‖) l (𝓝 0) := by + have he : Tendsto (fun t => S t*‖(V t).symm (Z (V t (s t)))+Z (s t)‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [add_zero] using h1.add h2) + · filter_upwards [hS] with t hst + exact mul_nonneg hst (norm_nonneg _) + · filter_upwards [hS] with t hst + simpa only [mul_add] using mul_le_mul_of_nonneg_left + (special_transport_bound (V t) Z F hZ hanti (s t)) hst + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ + (by simpa only [add_zero] using he.add ht) + filter_upwards [hS] with t hst + have heq : (S t:ℂ) • (U t).symm ((V t).symm (Z (V t (s t))))+w t= + (S t:ℂ) • (U t).symm ((V t).symm (Z (V t (s t)))+Z (s t))- + ((S t:ℂ) • (U t).symm (Z (s t))-w t) := by + simp only [map_add,smul_add] + abel + rw [heq] + apply (norm_sub_le _ _).trans + rw [norm_smul,(U t).symm.norm_map,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hst] + +end ForwardControl + +namespace CoherentFock +variable {E α : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] {l : Filter α} + + + +theorem scaled_echo_ordinary (t : ℝ) (r S : α → ℝ) (v v' : α → E) + (V₁ V₂ : α → SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E) (x : α → SpinSpace E) + (hS : ∀ᶠ q in l,0≤S q) + (h1 : Tendsto (fun q => S q*‖V₁ q (WZ (-(t/r q) • v q) (x q))- + WZ (-(t/r q) • v q) (x q)‖) l (𝓝 0)) + (h2 : Tendsto (fun q => S q*‖V₂ q (WZ ((t/r q) • v' q) + (V₁ q (WZ (-(t/r q) • v q) (x q))))- + WZ ((t/r q) • v' q) (V₁ q (WZ (-(t/r q) • v q) (x q)))‖) l (𝓝 0)) : + Tendsto (fun q => S q*‖(phase ((t/r q) • v' q) (-(t/r q) • v q))⁻¹ • + V₂ q (WZ ((t/r q) • v' q) (V₁ q (WZ (-(t/r q) • v q) (x q))))- + WZ ((t/r q) • (v' q-v q)) (x q)‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [add_zero] using h1.add h2) + · filter_upwards [hS] with q hq + exact mul_nonneg hq (norm_nonneg _) + · filter_upwards [hS] with q hq + simpa only [mul_add] using mul_le_mul_of_nonneg_left + (echo_ordinary_error t (r q) (v q) (v' q) (V₁ q) (V₂ q) (x q)) hq + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin +local instance wordRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance wordRealSMul : SMul ℝ ModeInfinity := wordRealModule.toDistribMulAction.toSMul + + +def wordGain (w u : List Gate) : SpinSpace ModeInfinity ≃ₗᵢ[ℂ] SpinSpace ModeInfinity := + (ordinaryLocal w).symm.trans (ordinaryLocal u) + +@[simp] theorem wordGain_apply (w u : List Gate) (x : SpinSpace ModeInfinity) : + wordGain w u x=ordinaryLocal u ((ordinaryLocal w).symm x) := rfl + + + +def echoWord (t r : ℝ) (w : List Gate) (a b : ℕ → ShortPulse) (K L : ℕ) : List Gate := + probePrefix r (.cost (-(t/r))::probePrefix r (.cost (t/r)::w) a K) b L + +@[simp] theorem probeGain_on_local (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (K : ℕ) + (x : SpinSpace ModeInfinity) : + probeGain r w a K (ordinaryLocal w x)=ordinaryLocal (probePrefix r w a K) x := by + simp only [probeGain_apply,LinearIsometryEquiv.symm_apply_apply] + + + +theorem wordGain_echo (t r : ℝ) (w : List Gate) (a b : ℕ → ShortPulse) (K L : ℕ) + (x : SpinSpace ModeInfinity) : + wordGain w (echoWord t r w a b K L) x= + probeGain r (.cost (-(t/r))::probePrefix r (.cost (t/r)::w) a K) b L + (WZ ((t/r) • insertionInfinity (probePrefix r (.cost (t/r)::w) a K)) + (probeGain r (.cost (t/r)::w) a K + (WZ (-(t/r) • insertionInfinity w) x))) := by + rw [wordGain_apply,echoWord,←probeGain_on_local] + rw [ordinaryLocal_cost,←probeGain_on_local,ordinaryLocal_cost] + simp only [LinearIsometryEquiv.apply_symm_apply,Complex.ofReal_neg,neg_neg] + simp only [RCLike.real_smul_eq_coe_smul (K:=ℂ), RCLike.ofReal_neg] + rfl + + +theorem actual_echo_ordinary_scaled {α : Type*} {l : Filter α} + (t : ℝ) (r S : α → ℝ) (w : α → List Gate) (a b : ℕ → ShortPulse) (K L : ℕ) + (x : α → SpinSpace ModeInfinity) (hS : ∀ᶠ q in l,0≤S q) + (h1 : Tendsto (fun q => S q*‖probeGain (r q) (.cost (t/r q)::w q) a K + (WZ (-(t/r q) • insertionInfinity (w q)) (x q))- + WZ (-(t/r q) • insertionInfinity (w q)) (x q)‖) l (𝓝 0)) + (h2 : Tendsto (fun q => S q*‖probeGain (r q) + (.cost (-(t/r q))::probePrefix (r q) (.cost (t/r q)::w q) a K) b L + (WZ ((t/r q) • insertionInfinity (probePrefix (r q) (.cost (t/r q)::w q) a K)) + (probeGain (r q) (.cost (t/r q)::w q) a K + (WZ (-(t/r q) • insertionInfinity (w q)) (x q))))- + WZ ((t/r q) • insertionInfinity (probePrefix (r q) (.cost (t/r q)::w q) a K)) + (probeGain (r q) (.cost (t/r q)::w q) a K + (WZ (-(t/r q) • insertionInfinity (w q)) (x q)))‖) l (𝓝 0)) : + Tendsto (fun q => S q*‖(phase + ((t/r q) • insertionInfinity (probePrefix (r q) (.cost (t/r q)::w q) a K)) + (-(t/r q) • insertionInfinity (w q)))⁻¹ • + wordGain (w q) (echoWord t (r q) (w q) a b K L) (x q)- + WZ ((t/r q) • (insertionInfinity (probePrefix (r q) (.cost (t/r q)::w q) a K)- + insertionInfinity (w q))) (x q)‖) l (𝓝 0) := by + simp_rw [wordGain_echo] + exact scaled_echo_ordinary t r S (fun q => insertionInfinity (w q)) + (fun q => insertionInfinity (probePrefix (r q) (.cost (t/r q)::w q) a K)) + (fun q => probeGain (r q) (.cost (t/r q)::w q) a K) + (fun q => probeGain (r q) + (.cost (-(t/r q))::probePrefix (r q) (.cost (t/r q)::w q) a K) b L) + x hS h1 h2 + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PacketGeometry + + + +theorem norm_tendsto_of_scaled_square {α H : Type*} [SeminormedAddCommGroup H] + {l : Filter α} (S : α → ℝ) (x : α → H) (hS : ∀ᶠ t in l,1≤S t) + (hx : Tendsto (fun t => S t*‖x t‖^2) l (𝓝 0)) : + Tendsto (fun t => ‖x t‖) l (𝓝 0) := by + have h2 := tendsto_of_scaled S (fun t => ‖x t‖^2) hS + (Eventually.of_forall (fun _ => sq_nonneg _)) hx + have h := (Real.continuous_sqrt.tendsto 0).comp h2 + simpa only [Function.comp_def, Real.sqrt_sq_eq_abs, abs_norm, Real.sqrt_zero] using h + +end PacketGeometry + +namespace PointedTree +open CoherentFock RootSpin + + + +theorem actual_huge_packet_phase {α ι : Type*} [Fintype ι] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k K : ℕ) (hk : k≤K) + (dp dm : α → ModeInfinity) (ds : ι → α → ModeInfinity) + (xp xm : α → PreSpin ModeInfinity) (xs : ι → α → PreSpin ModeInfinity) + (ρ : α → SpinSpace ModeInfinity) + (hS : Tendsto S l atTop) (B A δ T : ℝ) (hA : 0≤A) (hδ : 0<δ) (hT0 : 0≤T) + (hT : ∀j S t*‖ρ t‖) l (𝓝 0)) + (hs : Tendsto (fun t => S t*‖∑j,actualPacket (S t) (ds j t) (xs j t)‖^2) l (𝓝 0)) : + Tendsto (fun t => S t*|(⟪actualProbeDirection (r t) (w t) a k,insertionInfinity (w t)⟫_ℂ).im|) l (𝓝 0) := by + have he := hugeCrossError_packets_tendsto r S w a k K hk dp dm ds xp xm xs hS + B A δ T hA hδ hT0 hT hr hxp hxm hxs hpm hps hms + exact actual_huge_phase_tendsto r S w a k + (fun t => actualPacket (S t) (dp t) (xp t)) + (fun t => actualPacket (S t) (dm t) (xm t)) + (fun t => ∑j,actualPacket (S t) (ds j t) (xs j t)) ρ + (fun t => ‖ρ t‖) (fun t => ‖∑j,actualPacket (S t) (ds j t) (xs j t)‖) + (hS.eventually (eventually_ge_atTop 1)) + (Eventually.of_forall (fun _ => norm_nonneg _)) (Eventually.of_forall (fun _ => norm_nonneg _)) + hψ hop hom (Eventually.of_forall (fun _ => le_rfl)) (Eventually.of_forall (fun _ => le_rfl)) he hρ hs + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PacketGeometry + +lemma finite_positive_floor {ι : Type*} [Fintype ι] (c : ι → ℝ) (hc : ∀i,0 exact ⟨1,zero_lt_one,by simp⟩ + | @insert i s hi ih => + obtain ⟨δ,hδ,hd⟩ := ih + refine ⟨min δ (c i),lt_min hδ (hc i),?_⟩ + intro j hj + rcases Finset.mem_insert.mp hj with rfl|hj + · exact min_le_right _ _ + · exact (min_le_left _ _).trans (hd j hj) + simpa only [Finset.mem_univ,true_implies] using h Finset.univ + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + + + +lemma imaginary_real_multiple (v : E) (a : ℝ) : (⟪v,a • v⟫_ℂ).im=0 := by + rw [RCLike.real_smul_eq_coe_smul (K:=ℂ),inner_smul_real_right] + rw [Complex.smul_im] + change a • RCLike.im (inner ℂ v v)=0 + rw [inner_self_im,smul_zero] + +lemma projection_separation_bound (v d : E) (a : ℝ) (hv : ‖v‖≤1) : + |(⟪v,d⟫_ℂ).im|≤‖a • v-d‖ := by + have he : (⟪v,a • v-d⟫_ℂ).im= -(⟪v,d⟫_ℂ).im := by + rw [inner_sub_right,Complex.sub_im,imaginary_real_multiple,zero_sub] + calc + _ = |(⟪v,a • v-d⟫_ℂ).im| := by rw [he,abs_neg] + _ ≤ ‖⟪v,a • v-d⟫_ℂ‖ := Complex.abs_im_le_norm _ + _ ≤ ‖v‖*‖a • v-d‖ := norm_inner_le_norm _ _ + _ ≤ _ := by simpa only [one_mul] using mul_le_mul_of_nonneg_right hv (norm_nonneg (a • v-d)) + + + +theorem finite_projection_separation {α ι : Type*} [Fintype ι] {l : Filter α} + (v : α → E) (d : ι → α → E) (c : ι → ℝ) (a b : ℝ) + (hc : ∀i,c i≠0) (hv : ∀ᶠ t in l,‖v t‖≤1) + (hp : ∀i,Tendsto (fun t => (⟪v t,d i t⟫_ℂ).im) l (𝓝 (c i))) : + ∃ δ : ℝ,0<δ ∧ (∀i,∀ᶠ t in l,δ≤‖a • v t-d i t‖) ∧ + (∀i,∀ᶠ t in l,δ≤‖b • v t-d i t‖) := by + obtain ⟨δ,hδ,hd⟩ := finite_positive_floor (fun i => |c i|/2) + (fun i => half_pos (abs_pos.mpr (hc i))) + have h (q : ℝ) (i : ι) : ∀ᶠ t in l,δ≤‖q • v t-d i t‖ := by + have hp' := (hp i).abs.eventually (eventually_gt_nhds (half_lt_self (abs_pos.mpr (hc i)))) + filter_upwards [hv,hp'] with t hvt hpt + exact (hd i).trans (hpt.le.trans (projection_separation_bound (v t) (d i t) q hvt)) + exact ⟨δ,hδ,h a,h b⟩ + +end PacketGeometry + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance hugeRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance hugeRealSMul : SMul ℝ ModeInfinity := hugeRealModule.toDistribMulAction.toSMul +local instance hugeRealSMulZero : SMulZeroClass ℝ ModeInfinity := { smul_zero := hugeRealModule.toDistribMulAction.smul_zero } + + + +theorem standard_center_phase (r S : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : + S*|-2*(⟪actualDisplacement r w a k,S • (0:ModeInfinity)⟫_ℂ).im|=0 := by + simp only [smul_zero,inner_zero_right,Complex.zero_im,mul_zero,abs_zero] + + + +theorem huge_ordinary_scaled_phases {α ι : Type*} [Fintype ι] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (K : ℕ) + (t : ℝ) (ht : t≠0) (ds : ι → α → ModeInfinity) (c : ι → ℝ) + (xp xm : α → PreSpin ModeInfinity) (xs : ι → α → PreSpin ModeInfinity) + (ρ : α → SpinSpace ModeInfinity) + (hS : Tendsto S l atTop) (B A T : ℝ) (hA : 0≤A) (hT0 : 0≤T) + (hT : ∀j (⟪insertionInfinity (w q),ds i q⟫_ℂ).im) l (𝓝 (c i))) + (hψ : ∀ᶠ q in l,ordinaryLocal (w q) (vacuum ModeInfinity)= + actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q)+ + actualPacket (S q) (t • insertionInfinity (w q)) (xm q)+ + (∑i,actualPacket (S q) (ds i q) (xs i q))+ρ q) + (hop : ∀ᶠ q in l,SpinOperators.act Z + (actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q))= + actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q)) + (hom : ∀ᶠ q in l,SpinOperators.act Z + (actualPacket (S q) (t • insertionInfinity (w q)) (xm q))= + -actualPacket (S q) (t • insertionInfinity (w q)) (xm q)) + (hρ : Tendsto (fun q => S q*‖ρ q‖) l (𝓝 0)) + (hs : Tendsto (fun q => S q*‖∑i,actualPacket (S q) (ds i q) (xs i q)‖^2) l (𝓝 0)) : + ∀j S q*|-2*(⟪actualDisplacement (r q) (w q) a j, + S q • (b • insertionInfinity (w q))⟫_ℂ).im|) l (𝓝 0) := by + obtain ⟨δ,hδ,hps,hms⟩ := PacketGeometry.finite_projection_separation + (fun q => insertionInfinity (w q)) ds c (-t) t hc + (Eventually.of_forall (fun q => (norm_insertionInfinity (w q)).le)) hvis + let δ' := min δ (2*|t|) + have hδ' : 0<δ' := lt_min hδ (mul_pos (by norm_num) (abs_pos.mpr ht)) + have hpm : ∀ᶠ q in l,δ'≤‖(-t) • insertionInfinity (w q)-t • insertionInfinity (w q)‖ := by + apply Eventually.of_forall + intro q + rw [←sub_smul,norm_smul,norm_insertionInfinity,mul_one,Real.norm_eq_abs] + have he : -t-t= -(2*t) := by ring + rw [he,abs_neg,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] + exact min_le_right _ _ + intro j hj b + apply scaled_huge_center_phase r S w a j b hscale + apply actual_huge_packet_phase r S w a j K hj.le + (fun q => (-t) • insertionInfinity (w q)) (fun q => t • insertionInfinity (w q)) + ds xp xm xs ρ hS B A δ' T hA hδ' hT0 hT hr hxp hxm hxs hpm + (fun i => (hps i).mono (fun q hq => (min_le_left _ _).trans hq)) + (fun i => (hms i).mono (fun q hq => (min_le_left _ _).trans hq)) + hψ hop hom hρ hs + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace ForwardControl +variable {H α : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] {l : Filter α} + + + +theorem scaled_identity_transfer (V : α → H ≃ₗᵢ[ℂ] H) (S : α → ℝ) + (x y : α → H) (hS : ∀ᶠ t in l,0≤S t) + (hy : Tendsto (fun t => S t*‖V t (y t)-y t‖) l (𝓝 0)) + (hxy : Tendsto (fun t => S t*‖x t-y t‖) l (𝓝 0)) : + Tendsto (fun t => S t*‖V t (x t)-x t‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [zero_mul,add_zero] using hy.add (hxy.mul_const 2)) + · filter_upwards [hS] with t ht + exact mul_nonneg ht (norm_nonneg _) + · filter_upwards [hS] with t ht + have he : V t (x t)-x t=(V t (y t)-y t)+V t (x t-y t)-(x t-y t) := by + simp only [map_sub] + abel + have hn : ‖V t (x t)-x t‖≤‖V t (y t)-y t‖+2*‖x t-y t‖ := by + rw [he] + have h := (norm_sub_le (V t (y t)-y t+V t (x t-y t)) (x t-y t)).trans + (add_le_add (norm_add_le (V t (y t)-y t) (V t (x t-y t))) le_rfl) + rw [(V t).norm_map] at h + linarith + nlinarith + +end ForwardControl + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ActualDisplacement.lean b/lean/OAI/Probability/ParisiFinite/ActualDisplacement.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d40b1db212fc423c124f78fd4b842c7f1736091 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ActualDisplacement.lean @@ -0,0 +1,711 @@ +import Mathlib +import OAI.Probability.ParisiFinite.UnitaryUp + +namespace OAI + +/-! Actual Displacement. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace Topology +open Filter +namespace PointedTree +open CoherentFock RootSpin + +local instance modeRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance modeRealSMul : SMul ℝ ModeInfinity := modeRealModule.toDistribMulAction.toSMul + +def actualDisplacement (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : ModeInfinity := + -((r*(a k).2 : ℝ):ℂ) • actualProbeDirection r w a k + +@[simp] theorem norm_actualDisplacement (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : + ‖actualDisplacement r w a k‖=|r| *|(a k).2| := by + simp only [actualDisplacement,norm_smul,norm_neg,Complex.norm_real,Real.norm_eq_abs, + norm_actualProbeDirection,mul_one,abs_mul] + +def actualTail (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : ModeInfinity) (x : PreSpin ModeInfinity) : PreSpin ModeInfinity := + ProbeProduct.coreAct (fun j => preCenteredProbe (R (a j).1) (actualDisplacement r w a j) e) + (List.range k).reverse x + + +theorem probeGain_packet (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : ModeInfinity) (x : PreSpin ModeInfinity) : + probeGain r w a k (spinW e (spinCoe x))=spinW e (spinCoe (actualTail r w a k e x)) := by + have h := spinCoe_coreCentered (List.range k).reverse (fun j => R (a j).1) + (actualDisplacement r w a) e (fun j _ => R_unitary _) x + change spinCoe (actualTail r w a k e x)=spinW (-e) + (ProbeProduct.act (actualProbe r w a) (List.range k).reverse (spinW e (spinCoe x))) at h + rw [probeGain_product,h,spinW_inv'] + + +theorem spinMass_actualTail (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : ModeInfinity) (x : PreSpin ModeInfinity) : + spinMass (actualTail r w a k e x)≤(4^4:ℝ)^k*spinMass x := by + apply (spinMass_coreCentered (List.range k).reverse (fun j => R (a j).1) + (actualDisplacement r w a) e 4 (by norm_num) (fun j _ => matrixMass_R_le _) + (fun j _ => by rw [R_star]; exact matrixMass_R_le _) x).trans_eq + simp only [List.length_reverse,List.length_range] + + +theorem spinMass_actualTail_le (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k K : ℕ) + (hk : k≤K) (e : ModeInfinity) (x : PreSpin ModeInfinity) : + spinMass (actualTail r w a k e x)≤(4^4:ℝ)^K*spinMass x := by + exact (spinMass_actualTail r w a k e x).trans + (mul_le_mul_of_nonneg_right (pow_le_pow_right₀ (by norm_num) hk) (spinMass_nonneg _)) + +theorem radius_actualTail (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : ModeInfinity) (x : PreSpin ModeInfinity) (B T : ℝ) + (hx : SpinRadiusLE x B) (hT : ∀j R (a j).1) + (actualDisplacement r w a) e B (|r| *T) (by + intro j hj + rw [List.mem_reverse,List.mem_range] at hj + rw [norm_actualDisplacement] + exact mul_le_mul_of_nonneg_left (hT j hj) (abs_nonneg _)) x hx + simpa only [actualTail,List.length_reverse,List.length_range] using h + +theorem radius_actualTail_le (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k K : ℕ) + (hk : k≤K) (e : ModeInfinity) (x : PreSpin ModeInfinity) (B T : ℝ) + (hx : SpinRadiusLE x B) (hT0 : 0≤T) (hr : |r|≤1) (hT : ∀j hT j (hj.trans_le hk)) i).mono + have h1 : |r| *T≤T := by nlinarith [abs_nonneg r] + have h2 : (k:ℝ)≤K := Nat.cast_le.mpr hk + gcongr + + + +theorem rapid_decay_actual_packets {α : Type*} {l : Filter α} + (r Rsc : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k K : ℕ) (hk : k≤K) + (d e : α → ModeInfinity) (x y : α → PreSpin ModeInfinity) + (P : α → Matrix (Fin 2) (Fin 2) ℂ) (hR : Tendsto Rsc l atTop) + (B A C δ T : ℝ) (hA : 0≤A) (hC : 0≤C) (hδ : 0<δ) (hT0 : 0≤T) + (hT : ∀j (Rsc t)^M* + ‖⟪SpinOperators.act (P t) (probeGain (r t) (w t) a k (spinW (Rsc t • d t : ModeInfinity) (spinCoe (x t)))), + probeGain (r t) (w t) a k (spinW (Rsc t • e t : ModeInfinity) (spinCoe (y t)))⟫_ℂ‖) l (𝓝 0) := by + let X (t : α) : PreSpin ModeInfinity := actualTail (r t) (w t) a k (Rsc t • d t : ModeInfinity) (x t) + let Y (t : α) : PreSpin ModeInfinity := actualTail (r t) (w t) a k (Rsc t • e t : ModeInfinity) (y t) + have hX : ∀ᶠ t in l,SpinRadiusLE (X t) (B+K*T) ∧ spinMass (X t)≤(4^4:ℝ)^K*A := by + filter_upwards [hr,hx] with t hrt hxt + exact ⟨radius_actualTail_le _ _ _ k K hk _ _ B T hxt.1 hT0 hrt hT, + (spinMass_actualTail_le _ _ _ k K hk _ _).trans + (mul_le_mul_of_nonneg_left hxt.2 (by positivity))⟩ + have hY : ∀ᶠ t in l,SpinRadiusLE (Y t) (B+K*T) ∧ spinMass (Y t)≤(4^4:ℝ)^K*A := by + filter_upwards [hr,hy] with t hrt hyt + exact ⟨radius_actualTail_le _ _ _ k K hk _ _ B T hyt.1 hT0 hrt hT, + (spinMass_actualTail_le _ _ _ k K hk _ _).trans + (mul_le_mul_of_nonneg_left hyt.2 (by positivity))⟩ + simpa only [probeGain_packet] using rapid_decay_spin_matrix Rsc d e X Y P hR + (B+K*T) ((4^4:ℝ)^K*A) C δ (by positivity) hC hδ hX hY hP hsep M + +end PointedTree + + + +open scoped InnerProductSpace Topology +open Filter +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +@[simp] theorem phaseZ_zero_apply (x : SpinSpace E) : phaseZ 0 x=x := by + ext i + simp [phaseZ_apply] + +@[simp] theorem probePhase_zero_apply (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A∈unitary _) + (x : SpinSpace E) : probePhase A 0 x=x := by + rw [probePhase_apply,phaseZ_zero_apply,root_left_inverse A hA] + +theorem ProbeProduct.phase_zero {ι : Type*} (l : List ι) (A : ι → Matrix (Fin 2) (Fin 2) ℂ) + (hA : ∀j∈l,A j∈unitary _) (x : SpinSpace E) : + ProbeProduct.act (fun j => probePhase (A j) 0) l x=x := by + induction l with + | nil => rfl + | cons j l ih => + rw [ProbeProduct.act_cons, ih (fun i hi => hA i (List.mem_cons_of_mem _ hi)), + probePhase_zero_apply _ (hA j (List.mem_cons_self ..))] + + + +theorem centered_product_forward_bound {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (D : ι → E) (e : E) (L M α : ℝ) + (hL : 0≤L) (hM : 1≤M) (hα : 0≤α) + (hA : ∀j∈l,A j∈unitary _) (hD : ∀j∈l,‖D j‖≤L) + (hMass : ∀j∈l,matrixMass (A j)≤M) (hMS : ∀j∈l,matrixMass (A j).conjTranspose≤M) + (hp : ∀j∈l,|(-2*(⟪D j,e⟫_ℂ).im)|≤α) (x : PreSpin E) : + ‖spinW (-e) (ProbeProduct.act (fun j => probe (A j) (D j)) l (spinW e (spinCoe x)))-spinCoe x‖≤ + ((L^2+L)*M)*l.length*(M^2)^l.length*spinBound x+l.length*α*‖spinCoe x‖ := by + have h := special_product_bound l A D e (fun _ => 0) L M α hL hM hα + hA hD hMass hMS (by simpa only [sub_zero] using hp) x + rwa [ProbeProduct.phase_zero l A hA] at h + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin + + +theorem actual_forward_bound (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : ModeInfinity) (x : PreSpin ModeInfinity) (T α : ℝ) (hT : 0≤T) (hα : 0≤α) + (ha : ∀j R (a j).1) + (actualDisplacement r w a) e (|r| *T) 4 α (mul_nonneg (abs_nonneg _) hT) (by norm_num) hα + (fun j _ => R_unitary _) + (by intro j hj; rw [List.mem_reverse,List.mem_range] at hj + rw [norm_actualDisplacement]; exact mul_le_mul_of_nonneg_left (ha j hj) (abs_nonneg _)) + (fun j _ => matrixMass_R_le _) (fun j _ => by rw [R_star]; exact matrixMass_R_le _) + (by intro j hj; rw [List.mem_reverse,List.mem_range] at hj; exact hp j hj) x + have hfun : (fun j => probe (R (a j).1) (actualDisplacement r w a j))=actualProbe r w a := by + funext j; rfl + rw [hfun] at h + simpa only [List.length_reverse,List.length_range] using h + + + +theorem tendsto_actual_direction {α : Type*} {l : Filter α} + (r : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (h0 : Tendsto (fun t => + ‖probeGain (r t) (w t) a k (ordinaryLocal (w t) (vacuum ModeInfinity))- + ordinaryLocal (w t) (vacuum ModeInfinity)‖) l (𝓝 0)) + (hP : Tendsto (fun t => + ‖probeGain (r t) (w t) a k (SpinOperators.act ((R (a k).1).conjTranspose*Z*R (a k).1) + (ordinaryLocal (w t) (vacuum ModeInfinity)))- + SpinOperators.act ((R (a k).1).conjTranspose*Z*R (a k).1) + (ordinaryLocal (w t) (vacuum ModeInfinity))‖) l (𝓝 0)) : + Tendsto (fun t => ‖actualProbeDirection (r t) (w t) a k- + insertionInfinity (.mixer (a k).1::w t)‖) l (𝓝 0) := by + have h := h0.add hP + simp only [add_zero] at h + exact squeeze_zero (fun _ => norm_nonneg _) (fun t => actual_direction_change_bound (r t) (w t) a k) h + +end PointedTree + + + +open scoped InnerProductSpace BigOperators +namespace PulseControl +variable {H : Type*} [AddCommGroup H] [Module ℝ H] + + +theorem two_axis_sum (w : List (Bool×ℝ)) (f : Bool → H) : + (w.map (fun p => p.2 • f p.1)).sum= + (((w.filter (fun p => decide (p.1=true))).map Prod.snd).sum) • f true+ + (((w.filter (fun p => decide (p.1=false))).map Prod.snd).sum) • f false := by + induction w with + | nil => simp + | cons p w ih => + rcases p with ⟨b,t⟩ + cases b <;> simp only [List.map_cons,List.sum_cons,ih,List.filter_cons, + Bool.false_eq_true, Bool.true_eq_false,decide_false,decide_true,Bool.false_eq_true, + ite_false,ite_true,List.map_cons,List.sum_cons,add_smul] + all_goals abel + +theorem two_axis_zero_clock (w : List (Bool×ℝ)) + (hw : ∀b,((w.filter (fun p => decide (p.1=b))).map Prod.snd).sum=0) (f : Bool → H) : + (w.map (fun p => p.2 • f p.1)).sum=0 := by + rw [two_axis_sum,hw true,hw false,zero_smul,zero_smul,add_zero] + +end PulseControl + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + + +theorem probeField_zero_two_clocks (w : List (Bool×ℝ)) + (hw : ∀b,((w.filter (fun p => decide (p.1=b))).map Prod.snd).sum=0) + (A : Bool → Matrix (Fin 2) (Fin 2) ℂ) (v : Bool → E) (x : PreSpin E) : + (w.map (fun p => Complex.I • probeField (A p.1) (-p.2 • v p.1) x)).sum=0 := by + have h := PulseControl.two_axis_zero_clock w hw (fun b => -(Complex.I • probeField (A b) (v b) x)) + convert h using 2 + apply congrArg (fun f => List.map f w) + funext p + rw [probeField_real_smul] + module + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin +local instance clockRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance clockRealDistrib : DistribSMul ℝ ModeInfinity := clockRealModule.toDistribMulAction.toDistribSMul +local instance clockRealMulAction : MulAction ℝ ModeInfinity := clockRealModule.toDistribMulAction.toMulAction +local instance clockRealSMul : SMul ℝ ModeInfinity := clockRealModule.toDistribMulAction.toSMul + +def actualVelocity (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (j : ℕ) : ModeInfinity := + -(a j).2 • actualProbeDirection r w a j + +def startingVelocity (w : List Gate) (a : ℕ → ShortPulse) (j : ℕ) : ModeInfinity := + -(a j).2 • insertionInfinity (.mixer (a j).1::w) + +@[simp] theorem norm_actualVelocity (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (j : ℕ) : + ‖actualVelocity r w a j‖=|(a j).2| := by + simp only [actualVelocity,norm_smul,Real.norm_eq_abs,abs_neg,norm_actualProbeDirection,mul_one] + +@[simp] theorem norm_startingVelocity (w : List Gate) (a : ℕ → ShortPulse) (j : ℕ) : + ‖startingVelocity w a j‖=|(a j).2| := by + simp only [startingVelocity,norm_smul,Real.norm_eq_abs,abs_neg,norm_insertionInfinity,mul_one] + +theorem norm_velocity_difference (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (j : ℕ) : + ‖actualVelocity r w a j-startingVelocity w a j‖= + |(a j).2| *‖actualProbeDirection r w a j-insertionInfinity (.mixer (a j).1::w)‖ := by + rw [actualVelocity,startingVelocity,←smul_sub,norm_smul,Real.norm_eq_abs,abs_neg] + +theorem actualDisplacement_eq_velocity (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (j : ℕ) : + actualDisplacement r w a j=r • actualVelocity r w a j := by + simp only [actualDisplacement,actualVelocity,smul_smul,RCLike.real_smul_eq_coe_smul (K:=ℂ), + Complex.ofReal_mul,RCLike.ofReal_neg,mul_neg] + rfl + + + +theorem actual_zero_clock_bound (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : ModeInfinity) (x : PreSpin ModeInfinity) (T Δ α : ℝ) + (hT : 0≤T) (hΔ : 0≤Δ) (hα : 0≤α) + (ha : ∀j Complex.I • + probeField (R (a j).1) (startingVelocity w a j) x)).sum=0) : + ‖probeGain r w a k (spinW e (spinCoe x))-spinW e (spinCoe x)‖≤ + k*((r^2*T^2+|r| *(T*Δ))*4*spinBound x)+ + (k:ℝ)^2*|r| *(2*|r| *T^2*4^3*spinBound x)+k*α*‖spinCoe x‖ := by + have hn := norm_spinW (-e) (probeGain r w a k (spinW e (spinCoe x))-spinW e (spinCoe x)) + rw [map_sub,spinW_inv] at hn + rw [←hn,probeGain_product] + have h := centered_zero_clock_bound (List.range k).reverse (fun j => R (a j).1) + (actualVelocity r w a) (startingVelocity w a) r T 4 (T*Δ) α e x hT (by norm_num) + (mul_nonneg hT hΔ) hα (fun j _ => R_unitary _) + (by intro j hj; rw [List.mem_reverse,List.mem_range] at hj; simpa only [norm_actualVelocity] using ha j hj) + (by intro j hj; rw [List.mem_reverse,List.mem_range] at hj; simpa only [norm_startingVelocity] using ha j hj) + (by intro j hj; rw [List.mem_reverse,List.mem_range] at hj + rw [norm_velocity_difference]; exact mul_le_mul (ha j hj) (hd j hj) (norm_nonneg _) hT) + (fun j _ => matrixMass_R_le _) (fun j _ => by rw [R_star]; exact matrixMass_R_le _) + (by intro j hj; rw [List.mem_reverse,List.mem_range] at hj + rw [←actualDisplacement_eq_velocity]; exact hp j hj) hclock + have hf : (fun j => probe (R (a j).1) (r • actualVelocity r w a j))=actualProbe r w a := by + funext j + rw [←actualDisplacement_eq_velocity] + rfl + rw [hf] at h + simpa only [List.length_reverse,List.length_range] using h + +end PointedTree + + + +open scoped InnerProductSpace Topology +open Filter +namespace PacketGeometry +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + + + +theorem tendsto_of_scaled {α : Type*} {l : Filter α} (R d : α → ℝ) + (hR : ∀ᶠ t in l,1≤R t) (hd : ∀ᶠ t in l,0≤d t) + (h : Tendsto (fun t => R t*d t) l (𝓝 0)) : Tendsto d l (𝓝 0) := by + apply squeeze_zero' hd _ h + filter_upwards [hR,hd] with t hRt hdt + nlinarith + + + +theorem huge_imaginary_scaled_tendsto {α : Type*} {l : Filter α} + (P : α → H →ₗ[ℂ] H) (xp xm s z ρ σ : α → H) (R δ ε a : α → ℝ) + (hP : ∀t x y,⟪P t x,y⟫_ℂ=⟪x,P t y⟫_ℂ) (hPN : ∀t x,‖P t x‖≤‖x‖) + (hR : ∀ᶠ t in l,1≤R t) (hδ : ∀ᶠ t in l,0≤δ t) (ha : ∀ᶠ t in l,0≤a t) + (hx : ∀ᶠ t in l,‖xp t+xm t+s t+ρ t‖≤1) + (hy : ∀ᶠ t in l,‖xp t-xm t+z t+σ t‖≤1) + (hρ : ∀ᶠ t in l,‖ρ t‖≤δ t) (hσ : ∀ᶠ t in l,‖σ t‖≤δ t) + (hs : ∀ᶠ t in l,‖s t‖≤a t) (hz : ∀ᶠ t in l,‖z t‖≤a t) + (h1 : ∀ᶠ t in l,‖⟪P t (xp t),xm t⟫_ℂ‖≤ε t) + (h2 : ∀ᶠ t in l,‖⟪P t (xp t),z t⟫_ℂ‖≤ε t) + (h3 : ∀ᶠ t in l,‖⟪P t (xm t),z t⟫_ℂ‖≤ε t) + (h4 : ∀ᶠ t in l,‖⟪P t (s t),xp t⟫_ℂ‖≤ε t) + (h5 : ∀ᶠ t in l,‖⟪P t (s t),xm t⟫_ℂ‖≤ε t) + (he : Tendsto (fun t => R t*ε t) l (𝓝 0)) + (hd : Tendsto (fun t => R t*δ t) l (𝓝 0)) + (ha2 : Tendsto (fun t => R t*(a t)^2) l (𝓝 0)) : + Tendsto (fun t => R t*|(⟪P t (xp t+xm t+s t+ρ t),xp t-xm t+z t+σ t⟫_ℂ).im|) l (𝓝 0) := by + have hd0 := tendsto_of_scaled R δ hR hδ hd + have hb := ((he.const_mul 6).add ha2).add (hd.mul (hd0.const_add 2)) + simp only [mul_zero,zero_mul,add_zero] at hb + apply squeeze_zero' _ _ hb + · filter_upwards [hR] with t ht + exact mul_nonneg (by linarith) (abs_nonneg _) + · filter_upwards [hR,hδ,ha,hx,hy,hρ,hσ,hs,hz,h1,h2,h3,h4,h5] with t hRt hδt hat hxt hyt hρt hσt hst hzt h1t h2t h3t h4t h5t + have h := huge_imaginary_modulus (P t) (hP t) (hPN t) (xp t) (xm t) (s t) (z t) (ρ t) (σ t) + (δ t) (ε t) (a t) hδt hat hxt hyt hρt hσt hst hzt h1t h2t h3t h4t h5t + calc + _ ≤ R t*(6*ε t+(a t)^2+δ t*(2+δ t)) := mul_le_mul_of_nonneg_left h (by linarith) + _ = _ := by ring + +end PacketGeometry + +namespace RootSpin +open CoherentFock + +def rotatedZ (β : ℝ) : Matrix (Fin 2) (Fin 2) ℂ := (R β).conjTranspose*Z*R β + +@[simp] theorem rotatedZ_star (β : ℝ) : (rotatedZ β).conjTranspose=rotatedZ β := by + simp only [rotatedZ,Matrix.conjTranspose_mul,Matrix.conjTranspose_conjTranspose,Z_star,Matrix.mul_assoc] + +theorem rotatedZ_unitary (β : ℝ) : rotatedZ β∈unitary _ := + mul_mem (mul_mem (root_adjoint_unitary _ (R_unitary _)) Z_unitary) (R_unitary _) + +theorem rotatedZ_symmetric {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (β : ℝ) (x y : SpinSpace E) : + ⟪SpinOperators.act (rotatedZ β) x,y⟫_ℂ=⟪x,SpinOperators.act (rotatedZ β) y⟫_ℂ := by + have h := (SpinOperators.act (rotatedZ β) : SpinSpace E →L[ℂ] SpinSpace E).adjoint_inner_right x y + simpa only [SpinOperators.act_adjoint,rotatedZ_star] using h.symm + +end RootSpin + +namespace PointedTree +open CoherentFock RootSpin + + + +theorem actual_huge_phase_modulus (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (op om s ρ : SpinSpace ModeInfinity) (δ ε A : ℝ) (hδ : 0≤δ) (hA : 0≤A) + (hψ : ordinaryLocal w (vacuum ModeInfinity)=op+om+s+ρ) + (hop : SpinOperators.act Z op=op) (hom : SpinOperators.act Z om= -om) + (hρ : ‖ρ‖≤δ) (hs : ‖s‖≤A) + (h1 : ‖⟪SpinOperators.act (rotatedZ (a k).1) (probeGain r w a k op),probeGain r w a k om⟫_ℂ‖≤ε) + (h2 : ‖⟪SpinOperators.act (rotatedZ (a k).1) (probeGain r w a k op),probeGain r w a k (SpinOperators.act Z s)⟫_ℂ‖≤ε) + (h3 : ‖⟪SpinOperators.act (rotatedZ (a k).1) (probeGain r w a k om),probeGain r w a k (SpinOperators.act Z s)⟫_ℂ‖≤ε) + (h4 : ‖⟪SpinOperators.act (rotatedZ (a k).1) (probeGain r w a k s),probeGain r w a k op⟫_ℂ‖≤ε) + (h5 : ‖⟪SpinOperators.act (rotatedZ (a k).1) (probeGain r w a k s),probeGain r w a k om⟫_ℂ‖≤ε) : + |(⟪actualProbeDirection r w a k,insertionInfinity w⟫_ℂ).im|≤6*ε+A^2+δ*(2+δ) := by + let V := probeGain r w a k + let P := SpinOperators.act (rotatedZ (a k).1) (H:=Space ModeInfinity) + have he : SpinOperators.act Z (ordinaryLocal w (vacuum ModeInfinity))= + op-om+SpinOperators.act Z s+SpinOperators.act Z ρ := by + rw [hψ,map_add,map_add,map_add,hop,hom] + abel + have hx : ‖V op+V om+V s+V ρ‖≤1 := by + rw [←map_add,←map_add,←map_add,←hψ,V.norm_map,(ordinaryLocal w).norm_map,norm_vacuum] + have hy : ‖V op-V om+V (SpinOperators.act Z s)+V (SpinOperators.act Z ρ)‖≤1 := by + rw [←map_sub,←map_add,←map_add,←he,V.norm_map, + SpinOperators.norm_act Z_unitary,(ordinaryLocal w).norm_map,norm_vacuum] + rw [actual_hermitian_diagonal,he,hψ] + simp only [map_add,map_sub] + simpa only [P, V, rotatedZ, ContinuousLinearMap.coe_coe, map_add] using PacketGeometry.huge_imaginary_modulus P.toLinearMap + (rotatedZ_symmetric (a k).1) (fun x => (SpinOperators.norm_act (rotatedZ_unitary _) x).le) + (V op) (V om) (V s) (V (SpinOperators.act Z s)) (V ρ) (V (SpinOperators.act Z ρ)) δ ε A hδ hA hx hy + (by simpa only [V.norm_map] using hρ) + (by simpa only [V.norm_map,SpinOperators.norm_act Z_unitary] using hρ) + (by simpa only [V.norm_map] using hs) + (by simpa only [V.norm_map,SpinOperators.norm_act Z_unitary] using hs) + h1 h2 h3 h4 h5 + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PacketGeometry + + + +theorem scaled_norm_sum_tendsto {α H ι : Type*} {l : Filter α} + [SeminormedAddCommGroup H] [Fintype ι] + (R : α → ℝ) (f : α → ι → H) (hR : ∀ᶠ t in l,0≤R t) + (hf : ∀j,Tendsto (fun t => R t*‖f t j‖) l (𝓝 0)) : + Tendsto (fun t => R t*‖∑j,f t j‖) l (𝓝 0) := by + have h := tendsto_finsetSum Finset.univ (fun j _ => hf j) + simp only [Finset.sum_const_zero] at h + apply squeeze_zero' _ _ h + · filter_upwards [hR] with t ht + exact mul_nonneg ht (norm_nonneg _) + · filter_upwards [hR] with t ht + simpa only [Finset.mul_sum] using mul_le_mul_of_nonneg_left (norm_sum_le _ _) ht + +end PacketGeometry + +namespace PointedTree +open CoherentFock RootSpin +local instance packetRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance packetRealSMul : SMul ℝ ModeInfinity := packetRealModule.toDistribMulAction.toSMul + +def actualPacket (R : ℝ) (d : ModeInfinity) (x : PreSpin ModeInfinity) : SpinSpace ModeInfinity := + spinW (R • d) (spinCoe x) + +@[simp] theorem actualPacket_root (P : Matrix (Fin 2) (Fin 2) ℂ) (R : ℝ) + (d : ModeInfinity) (x : PreSpin ModeInfinity) : + SpinOperators.act P (actualPacket R d x)=actualPacket R d (preRoot P x) := by + simp only [actualPacket, spinCoe_preRoot, spinW_root] + + +def hugeCrossError (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (op om s : SpinSpace ModeInfinity) : ℝ := + let V := probeGain r w a k + let P := SpinOperators.act (rotatedZ (a k).1) (H:=Space ModeInfinity) + ‖⟪P (V op),V om⟫_ℂ‖+ + ‖⟪P (V op),V (SpinOperators.act Z s)⟫_ℂ‖+ + ‖⟪P (V om),V (SpinOperators.act Z s)⟫_ℂ‖+ + ‖⟪P (V s),V op⟫_ℂ‖+ + ‖⟪P (V s),V om⟫_ℂ‖ + + + +theorem actual_huge_phase_tendsto {α : Type*} {l : Filter α} + (r Rsc : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (op om s ρ : α → SpinSpace ModeInfinity) (δ A : α → ℝ) + (hR : ∀ᶠ t in l,1≤Rsc t) (hδ : ∀ᶠ t in l,0≤δ t) (hA : ∀ᶠ t in l,0≤A t) + (hψ : ∀ᶠ t in l,ordinaryLocal (w t) (vacuum ModeInfinity)=op t+om t+s t+ρ t) + (hop : ∀ᶠ t in l,SpinOperators.act Z (op t)=op t) + (hom : ∀ᶠ t in l,SpinOperators.act Z (om t)= -om t) + (hρ : ∀ᶠ t in l,‖ρ t‖≤δ t) (hs : ∀ᶠ t in l,‖s t‖≤A t) + (he : Tendsto (fun t => Rsc t*hugeCrossError (r t) (w t) a k (op t) (om t) (s t)) l (𝓝 0)) + (hd : Tendsto (fun t => Rsc t*δ t) l (𝓝 0)) + (ha : Tendsto (fun t => Rsc t*(A t)^2) l (𝓝 0)) : + Tendsto (fun t => Rsc t*|(⟪actualProbeDirection (r t) (w t) a k,insertionInfinity (w t)⟫_ℂ).im|) l (𝓝 0) := by + have hd0 := PacketGeometry.tendsto_of_scaled Rsc δ hR hδ hd + have hb := ((he.const_mul 6).add ha).add (hd.mul (hd0.const_add 2)) + simp only [mul_zero,zero_mul,add_zero] at hb + apply squeeze_zero' _ _ hb + · filter_upwards [hR] with t ht + exact mul_nonneg (by linarith) (abs_nonneg _) + · filter_upwards [hR,hδ,hA,hψ,hop,hom,hρ,hs] with t hRt hδt hAt hψt hopt homt hρt hst + have ht := actual_huge_phase_modulus (r t) (w t) a k (op t) (om t) (s t) (ρ t) + (δ t) (hugeCrossError (r t) (w t) a k (op t) (om t) (s t)) (A t) + hδt hAt hψt hopt homt hρt hst + (by apply le_of_sub_nonneg; dsimp only [hugeCrossError]; ring_nf; positivity) + (by apply le_of_sub_nonneg; dsimp only [hugeCrossError]; ring_nf; positivity) + (by apply le_of_sub_nonneg; dsimp only [hugeCrossError]; ring_nf; positivity) + (by apply le_of_sub_nonneg; dsimp only [hugeCrossError]; ring_nf; positivity) + (by apply le_of_sub_nonneg; dsimp only [hugeCrossError]; ring_nf; positivity) + calc + _ ≤ Rsc t*(6*hugeCrossError (r t) (w t) a k (op t) (om t) (s t)+(A t)^2+δ t*(2+δ t)) := + mul_le_mul_of_nonneg_left ht (by linarith) + _ = _ := by ring + + + +theorem rapid_actual_packet_sum_right {α ι : Type*} [Fintype ι] {l : Filter α} + (r Rsc : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k K : ℕ) (hk : k≤K) + (d : α → ModeInfinity) (e : ι → α → ModeInfinity) + (x : α → PreSpin ModeInfinity) (y : ι → α → PreSpin ModeInfinity) + (P : α → Matrix (Fin 2) (Fin 2) ℂ) (hR : Tendsto Rsc l atTop) + (B A C δ T : ℝ) (hA : 0≤A) (hC : 0≤C) (hδ : 0<δ) (hT0 : 0≤T) + (hT : ∀j Rsc t* + ‖⟪SpinOperators.act (P t) (probeGain (r t) (w t) a k (actualPacket (Rsc t) (d t) (x t))), + probeGain (r t) (w t) a k (∑j,actualPacket (Rsc t) (e j t) (y j t))⟫_ℂ‖) l (𝓝 0) := by + have h (j : ι) := rapid_decay_actual_packets r Rsc w a k K hk d (e j) x (y j) P hR + B A C δ T hA hC hδ hT0 hT hr hx (hy j) hP (hsep j) 1 + simp only [pow_one] at h + simpa only [actualPacket,map_sum,inner_sum] using PacketGeometry.scaled_norm_sum_tendsto Rsc + (fun t j => ⟪SpinOperators.act (P t) (probeGain (r t) (w t) a k (actualPacket (Rsc t) (d t) (x t))), + probeGain (r t) (w t) a k (actualPacket (Rsc t) (e j t) (y j t))⟫_ℂ) + (hR.eventually (eventually_ge_atTop 0)) h + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace RootSpin +open CoherentFock + +@[simp] theorem matrixMass_Z : matrixMass Z=2 := by + norm_num [matrixMass,Z,Fin.sum_univ_two] + +end RootSpin + +namespace PointedTree +open CoherentFock RootSpin + + +theorem rapid_actual_packet_sum_left {α ι : Type*} [Fintype ι] {l : Filter α} + (r Rsc : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k K : ℕ) (hk : k≤K) + (d : ι → α → ModeInfinity) (e : α → ModeInfinity) + (x : ι → α → PreSpin ModeInfinity) (y : α → PreSpin ModeInfinity) + (P : α → Matrix (Fin 2) (Fin 2) ℂ) (hR : Tendsto Rsc l atTop) + (B A C δ T : ℝ) (hA : 0≤A) (hC : 0≤C) (hδ : 0<δ) (hT0 : 0≤T) + (hT : ∀j Rsc t* + ‖⟪SpinOperators.act (P t) (probeGain (r t) (w t) a k (∑j,actualPacket (Rsc t) (d j t) (x j t))), + probeGain (r t) (w t) a k (actualPacket (Rsc t) (e t) (y t))⟫_ℂ‖) l (𝓝 0) := by + have h (j : ι) := rapid_decay_actual_packets r Rsc w a k K hk (d j) e (x j) y P hR + B A C δ T hA hC hδ hT0 hT hr (hx j) hy hP (hsep j) 1 + simp only [pow_one] at h + simpa only [actualPacket,map_sum,sum_inner] using PacketGeometry.scaled_norm_sum_tendsto Rsc + (fun t j => ⟪SpinOperators.act (P t) (probeGain (r t) (w t) a k (actualPacket (Rsc t) (d j t) (x j t))), + probeGain (r t) (w t) a k (actualPacket (Rsc t) (e t) (y t))⟫_ℂ) + (hR.eventually (eventually_ge_atTop 0)) h + + + +theorem hugeCrossError_packets_tendsto {α ι : Type*} [Fintype ι] {l : Filter α} + (r Rsc : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k K : ℕ) (hk : k≤K) + (dp dm : α → ModeInfinity) (ds : ι → α → ModeInfinity) + (xp xm : α → PreSpin ModeInfinity) (xs : ι → α → PreSpin ModeInfinity) + (hR : Tendsto Rsc l atTop) (B A δ T : ℝ) (hA : 0≤A) (hδ : 0<δ) (hT0 : 0≤T) + (hT : ∀j Rsc t*hugeCrossError (r t) (w t) a k + (actualPacket (Rsc t) (dp t) (xp t)) (actualPacket (Rsc t) (dm t) (xm t)) + (∑j,actualPacket (Rsc t) (ds j t) (xs j t))) l (𝓝 0) := by + let P := rotatedZ (a k).1 + let C := matrixMass P + have hC : 0≤C := matrixMass_nonneg _ + have hP : ∀ᶠ t in l,matrixMass P≤C := Eventually.of_forall (fun _ => le_rfl) + have hxp2 : ∀ᶠ t in l,SpinRadiusLE (xp t) B ∧ spinMass (xp t)≤2*A := by + filter_upwards [hxp] with t ht + exact ⟨ht.1,ht.2.trans (by linarith)⟩ + have hxm2 : ∀ᶠ t in l,SpinRadiusLE (xm t) B ∧ spinMass (xm t)≤2*A := by + filter_upwards [hxm] with t ht + exact ⟨ht.1,ht.2.trans (by linarith)⟩ + have hzs (j : ι) : ∀ᶠ t in l,SpinRadiusLE (preRoot Z (xs j t)) B ∧ spinMass (preRoot Z (xs j t))≤2*A := by + filter_upwards [hxs j] with t ht + exact ⟨ht.1.preRoot Z,(spinMass_preRoot Z _).trans (by rw [matrixMass_Z]; linarith [ht.2])⟩ + have hsp (j : ι) : ∀ᶠ t in l,δ≤‖ds j t-dp t‖ := by + filter_upwards [hps j] with t ht + exact ht.trans_eq (norm_sub_rev _ _) + have hsm (j : ι) : ∀ᶠ t in l,δ≤‖ds j t-dm t‖ := by + filter_upwards [hms j] with t ht + exact ht.trans_eq (norm_sub_rev _ _) + have h1 := rapid_decay_actual_packets r Rsc w a k K hk dp dm xp xm (fun _ => P) hR + B A C δ T hA hC hδ hT0 hT hr hxp hxm hP hpm 1 + simp only [pow_one] at h1 + have h2 := rapid_actual_packet_sum_right r Rsc w a k K hk dp ds xp + (fun j t => preRoot Z (xs j t)) (fun _ => P) hR B (2*A) C δ T (by positivity) hC hδ hT0 hT hr hxp2 hzs hP hps + have h3 := rapid_actual_packet_sum_right r Rsc w a k K hk dm ds xm + (fun j t => preRoot Z (xs j t)) (fun _ => P) hR B (2*A) C δ T (by positivity) hC hδ hT0 hT hr hxm2 hzs hP hms + have h4 := rapid_actual_packet_sum_left r Rsc w a k K hk ds dp xs xp (fun _ => P) hR + B A C δ T hA hC hδ hT0 hT hr hxs hxp hP hsp + have h5 := rapid_actual_packet_sum_left r Rsc w a k K hk ds dm xs xm (fun _ => P) hR + B A C δ T hA hC hδ hT0 hT hr hxs hxm hP hsm + have h := (((h1.add h2).add h3).add h4).add h5 + simpa only [hugeCrossError,P,mul_add,map_sum,actualPacket_root,actualPacket,spinCoe_preRoot,spinW_root,zero_add] using h + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin + + + +theorem actual_forward_tendsto {α : Type*} {l : Filter α} + (r : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : α → ModeInfinity) (x : α → PreSpin ModeInfinity) (phase : α → ℝ) + (T B A : ℝ) (hT : 0≤T) (_hB : 0≤B) (_hA : 0≤A) + (ha : ∀j ‖probeGain (r t) (w t) a k (spinW (e t) (spinCoe (x t)))- + spinW (e t) (spinCoe (x t))‖) l (𝓝 0) := by + have habs : Tendsto (fun t => |r t|) l (𝓝 0) := by simpa only [abs_zero] using hr0.abs + have hlim := ((((((habs.mul_const T).pow 2).add (habs.mul_const T)).mul_const 4).mul_const (k:ℝ)).mul_const ((4^2:ℝ)^k)).mul_const B + have hlim' := hlim.add ((hp0.const_mul (k:ℝ)).mul_const A) + simp only [zero_mul,zero_pow (by decide : 2≠0),add_zero,mul_zero] at hlim' + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ hlim' + filter_upwards [hpnonneg,hphase,hx] with t hpt hphaset hxt + apply (actual_forward_bound (r t) (w t) a k (e t) (x t) T (phase t) hT hpt ha hphaset).trans + exact add_le_add (mul_le_mul_of_nonneg_left hxt.1 (by positivity)) + (mul_le_mul_of_nonneg_left hxt.2 (by positivity)) + + + +theorem actual_zero_clock_tendsto {α : Type*} {l : Filter α} + (r Rsc : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (e : α → ModeInfinity) (x : α → PreSpin ModeInfinity) (Δ phase : α → ℝ) + (T B A : ℝ) (hT : 0≤T) (_hB : 0≤B) (_hA : 0≤A) + (ha : ∀j Rsc t*phase t) l (𝓝 0)) + (hscale : ∀ᶠ t in l,0≤r t ∧ 0≤Rsc t ∧ Rsc t*r t=1) + (hnonneg : ∀ᶠ t in l,0≤Δ t ∧ 0≤phase t) + (hd : ∀ᶠ t in l,∀j Complex.I • + probeField (R (a j).1) (startingVelocity (w t) a j) (x t))).sum=0) : + Tendsto (fun t => Rsc t*‖probeGain (r t) (w t) a k (spinW (e t) (spinCoe (x t)))- + spinW (e t) (spinCoe (x t))‖) l (𝓝 0) := by + have h1 := (((hr0.mul_const (T^2)).add (hΔ0.const_mul T)).mul_const (4*B)).const_mul (k:ℝ) + have h2 := (hr0.mul_const (2*T^2*4^3*B)).const_mul ((k:ℝ)^2) + have h3 := (hp0.mul_const A).const_mul (k:ℝ) + have hl := (h1.add h2).add h3 + simp only [zero_mul,mul_zero,add_zero] at hl + apply squeeze_zero' _ _ hl + · filter_upwards [hscale] with t ht + exact mul_nonneg ht.2.1 (norm_nonneg _) + · filter_upwards [hscale,hnonneg,hd,hp,hx,hclock] with t ht hnt hdt hpt hxt hct + have h := actual_zero_clock_bound (r t) (w t) a k (e t) (x t) T (Δ t) (phase t) + hT hnt.1 hnt.2 ha hdt hpt hct + have hb : ‖probeGain (r t) (w t) a k (spinW (e t) (spinCoe (x t)))- + spinW (e t) (spinCoe (x t))‖≤ + k*((r t^2*T^2+|r t| *(T*Δ t))*4*B)+ + (k:ℝ)^2*|r t| *(2*|r t| *T^2*4^3*B)+k*phase t*A := by + apply h.trans + have hΔt := hnt.1 + have hphaset := hnt.2 + have hBt := hxt.1 + have hAt := hxt.2 + gcongr + apply (mul_le_mul_of_nonneg_left hb ht.2.1).trans_eq + rw [abs_of_nonneg ht.1] + calc + _ = (Rsc t*r t)*((k:ℝ)*(r t*T^2+T*Δ t)*(4*B)+(k:ℝ)^2*(r t*(2*T^2*4^3*B)))+ + (k:ℝ)*(Rsc t*phase t*A) := by ring + _ = _ := by rw [ht.2.2,one_mul]; ring + +end PointedTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Average.lean b/lean/OAI/Probability/ParisiFinite/Average.lean new file mode 100644 index 0000000000000000000000000000000000000000..22659598a193116f001c7952593f88729567a6c9 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Average.lean @@ -0,0 +1,702 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Law +import OAI.Probability.ParisiFinite.SquareKernel + +namespace OAI + +/-! Average. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal +namespace SKCavity +open SKQAOA SKGaussian + + +def average {ι : Type*} [Fintype ι] (x f : ι → ℝ) : ℝ := ∑ i, weight x i*f i + +lemma average_pos {ι : Type*} [Fintype ι] [Nonempty ι] (x f : ι → ℝ) + (hf : ∀ i, 0 < f i) : 0 < average x f := by + apply Finset.sum_pos (fun i _ => mul_pos (weight_pos x i) (hf i)) Finset.univ_nonempty + +lemma partition_mul_average {ι : Type*} [Fintype ι] [Nonempty ι] (x f : ι → ℝ) : + partition x * average x f = ∑ i, Real.exp (x i)*f i := by + unfold average + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + unfold weight + field_simp [(partition_pos x).ne'] + +lemma log_average_exp {ι : Type*} [Fintype ι] [Nonempty ι] (x y : ι → ℝ) : + Real.log (average x (fun i => Real.exp (y i))) = + logPartition (fun i => x i+y i)-logPartition x := by + have hp : partition (fun i => x i+y i)=partition x*average x (fun i => Real.exp (y i)) := by + rw [partition_mul_average] + simp [partition,Real.exp_add] + rw [logPartition, hp, Real.log_mul (partition_pos x).ne' + (average_pos x _ (fun i => Real.exp_pos _)).ne'] + simp [logPartition] + +lemma restrictLeft_snoc {n : ℕ} (σ : Configuration n) (b : Bool) : + restrictLeft (Fin.snoc σ b) = σ := by + ext i + change (Fin.snoc σ b : Configuration (n+1)) i.castSucc=σ i + simp + + +def extend {n : ℕ} (x z : Configuration n → ℝ) (σ : Configuration (n+1)) : ℝ := + x (restrictLeft σ)+spin σ (Fin.last n)*z (restrictLeft σ) + +lemma partition_extend {n : ℕ} (x z : Configuration n → ℝ) : + partition (extend x z) = ∑ σ, Real.exp (x σ)*(2*Real.cosh (z σ)) := by + classical + let e : (Bool × Configuration n) ≃ Configuration (n+1) := Fin.snocEquiv (fun _ => Bool) + rw [partition, ← e.sum_comp, Fintype.sum_prod_type, Finset.sum_comm] + apply Finset.sum_congr rfl + intro σ _ + change (∑ b : Bool, Real.exp (extend x z (Fin.snoc σ b)))=_ + simp only [Fintype.sum_bool, extend, restrictLeft_snoc, spin, Fin.snoc_last, + Bool.false_eq_true, ite_true, ite_false] + simp [Real.cosh_eq, Real.exp_add, Real.exp_neg] + ring + +lemma logPartition_extend {n : ℕ} (x z : Configuration n → ℝ) : + logPartition (extend x z) = logPartition x+Real.log (average x (fun σ => 2*Real.cosh (z σ))) := by + rw [logPartition, partition_extend, ← partition_mul_average, + Real.log_mul (partition_pos x).ne' (average_pos x _ (fun σ => by positivity)).ne'] + rfl + + +def site (n : ℕ) (g : Fin n → ℝ) (σ : Configuration n) : ℝ := + cavityScale n * ∑ i, g i*spin σ i + +def core (n : ℕ) (J : Disorder n) (σ : Configuration n) : ℝ := + coreScale n*hamiltonian n J σ + +def correctionField (n : ℕ) (J : Disorder n) (σ : Configuration n) : ℝ := + cavityScale n*hamiltonian n J σ + +lemma field_cavityCoeff (n : ℕ) (J : (Edge n ⊕ Fin n) → ℝ) : + field (cavityCoeff n) J = extend (core n (fun e => J (Sum.inl e))) + (site n (fun i => J (Sum.inr i))) := by + ext σ + simp only [field, cavityCoeff, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, + extend, core, site, hamiltonian_eq_coeff, Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro i _ <;> ring + +lemma field_correctedCoeff (n : ℕ) (J : (Edge n ⊕ Edge n) → ℝ) : + field (correctedCoeff n) J = fun σ => core n (fun e => J (Sum.inl e)) σ+ + correctionField n (fun e => J (Sum.inr e)) σ := by + ext σ + simp only [field, correctedCoeff, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, + core, correctionField, hamiltonian_eq_coeff, Finset.mul_sum] + congr 1 <;> apply Finset.sum_congr rfl <;> intro i _ <;> ring + +lemma extend_scale {n : ℕ} (β : ℝ) (x z : Configuration n → ℝ) : + (fun σ => β*extend x z σ)=extend (fun σ => β*x σ) (fun σ => β*z σ) := by + ext σ + unfold extend + ring + + +def cavityLog (n : ℕ) (β : ℝ) (J : (Edge n ⊕ Fin n) → ℝ) : ℝ := + Real.log (average (fun σ => β*core n (fun e => J (Sum.inl e)) σ) + (fun σ => 2*Real.cosh (β*site n (fun i => J (Sum.inr i)) σ))) + + +def correctionLog (n : ℕ) (β : ℝ) (J : (Edge n ⊕ Edge n) → ℝ) : ℝ := + Real.log (average (fun σ => β*core n (fun e => J (Sum.inl e)) σ) + (fun σ => Real.exp (β*correctionField n (fun e => J (Sum.inr e)) σ))) + +lemma cavityLog_sub (n : ℕ) (β : ℝ) (J : (Edge n ⊕ Fin n) → ℝ) : + cavityLog n β J = logPartition (fun σ => β*field (cavityCoeff n) J σ)- + logPartition (fun σ => β*core n (fun e => J (Sum.inl e)) σ) := by + rw [field_cavityCoeff, extend_scale, logPartition_extend] + simp only [cavityLog, add_sub_cancel_left] + +lemma correctionLog_sub (n : ℕ) (β : ℝ) (J : (Edge n ⊕ Edge n) → ℝ) : + correctionLog n β J = logPartition (fun σ => β*field (correctedCoeff n) J σ)- + logPartition (fun σ => β*core n (fun e => J (Sum.inl e)) σ) := by + rw [field_correctedCoeff] + simp only [mul_add] + exact log_average_exp _ _ +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal +namespace SKCavity +open SKQAOA SKGaussian + + +def coreLift (n : ℕ) (κ : Type*) (β : ℝ) (σ : Configuration n) : Edge n ⊕ κ → ℝ := + Sum.elim (fun e => β*coreScale n*skCoeff n σ e) (fun _ => 0) + +lemma field_coreLift (n : ℕ) {κ : Type*} [Fintype κ] (β : ℝ) (J : (Edge n ⊕ κ) → ℝ) : + field (coreLift n κ β) J = fun σ => β*core n (fun e => J (Sum.inl e)) σ := by + ext σ + simp only [field, coreLift, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, + zero_mul, Finset.sum_const_zero, add_zero, core, hamiltonian_eq_coeff, Finset.mul_sum] + apply Finset.sum_congr rfl + intro e _ + ring + +lemma integrable_coreLift (n : ℕ) {κ : Type*} [Fintype κ] (β : ℝ) : + Integrable (fun J : (Edge n ⊕ κ) → ℝ => + logPartition (fun σ => β*core n (fun e => J (Sum.inl e)) σ)) (gaussianLaw (Edge n ⊕ κ)) := by + simp_rw [← field_coreLift] + exact integrable_logPartition (fun σ => integrable_field _ σ) + +lemma expected_coreLift (n : ℕ) {κ : Type*} [Fintype κ] (β : ℝ) : + (∫ J : (Edge n ⊕ κ) → ℝ, + logPartition (fun σ => β*core n (fun e => J (Sum.inl e)) σ) ∂gaussianLaw (Edge n ⊕ κ)) = + pressure (β*coreScale n) n := by + simp_rw [← field_coreLift] + unfold coreLift + rw [integral_field_inl] + simp_rw [field_scale, field_skCoeff] + rfl + +lemma integrable_cavityLog (n : ℕ) (β : ℝ) : + Integrable (cavityLog n β) (gaussianLaw (Edge n ⊕ Fin n)) := by + have he : cavityLog n β = fun J => logPartition (fun σ => β*field (cavityCoeff n) J σ)- + logPartition (fun σ => β*core n (fun e => J (Sum.inl e)) σ) := funext (cavityLog_sub n β) + rw [he] + exact (integrable_logPartition (fun σ => (integrable_field _ σ).const_mul β)).sub (integrable_coreLift n β) + +lemma integrable_correctionLog (n : ℕ) (β : ℝ) : + Integrable (correctionLog n β) (gaussianLaw (Edge n ⊕ Edge n)) := by + have he : correctionLog n β = fun J => logPartition (fun σ => β*field (correctedCoeff n) J σ)- + logPartition (fun σ => β*core n (fun e => J (Sum.inl e)) σ) := funext (correctionLog_sub n β) + rw [he] + exact (integrable_logPartition (fun σ => (integrable_field _ σ).const_mul β)).sub (integrable_coreLift n β) + +lemma expected_cavityLog {n : ℕ} (hn : 0 < n) (β : ℝ) : + (∫ J, cavityLog n β J ∂gaussianLaw (Edge n ⊕ Fin n)) = + pressure β (n+1)-pressure (β*coreScale n) n := by + simp_rw [cavityLog_sub] + rw [integral_sub (integrable_logPartition (fun σ => (integrable_field _ σ).const_mul β)) + (integrable_coreLift n β), expected_cavity_pressure hn, expected_coreLift] + +lemma expected_correctionLog (n : ℕ) (β : ℝ) : + (∫ J, correctionLog n β J ∂gaussianLaw (Edge n ⊕ Edge n)) = + pressure β n-pressure (β*coreScale n) n := by + simp_rw [correctionLog_sub] + rw [integral_sub (integrable_logPartition (fun σ => (integrable_field _ σ).const_mul β)) + (integrable_coreLift n β), expected_corrected_pressure, expected_coreLift] + + +def increment (β : ℝ) (n : ℕ) : ℝ := + (∫ J, cavityLog n β J ∂gaussianLaw (Edge n ⊕ Fin n))- + ∫ J, correctionLog n β J ∂gaussianLaw (Edge n ⊕ Edge n) + + +lemma increment_eq {n : ℕ} (hn : 0 < n) (β : ℝ) : + increment β n=pressure β (n+1)-pressure β n := by + rw [increment, expected_cavityLog hn, expected_correctionLog] + ring + +lemma increment_lower {n : ℕ} (hn : 0 < n) (β : ℝ) : + pressure β 1 ≤ increment β n := by + rw [increment_eq hn] + linarith [pressure_superadditive β n 1] +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal +namespace SKCavity +open SKQAOA SKGaussian + + + +lemma frequently_increment_le_of_slope {a : ℕ → ℝ} {L : ℝ} + (ha : Tendsto (fun n => a n/(n:ℝ)) atTop (𝓝 L)) {ε : ℝ} (hε : 0 < ε) : + ∃ᶠ n in atTop, a (n+1)-a n ≤ L+ε := by + rw [frequently_atTop] + intro N + by_contra! h + have hb (n : ℕ) (hn : N ≤ n) : a N+((n:ℝ)-N)*(L+ε) ≤ a n := by + induction n, hn using Nat.le_induction with + | base => simp + | succ n hn ih => + have hh := h n hn + push_cast + linarith + have hh : ∀ᶠ (n : ℕ) in atTop, (a N-(N:ℝ)*(L+ε))/(n:ℝ)+(L+ε) ≤ a n/(n:ℝ) := by + filter_upwards [eventually_ge_atTop N, eventually_gt_atTop 0] with n hn hp + have hn' : (0:ℝ) pressure β n/(n:ℝ)) atTop (𝓝 (β*limitingFreeEnergy β)) := by + have he (n : ℕ) : pressure β n/(n:ℝ)=β*freeEnergy β n := by + unfold freeEnergy + field_simp + simp_rw [he] + exact (tendsto_freeEnergy hβ).const_mul β + +lemma frequently_cavity_upper {β : ℝ} (hβ : 0 < β) {ε : ℝ} (hε : 0 < ε) : + ∃ᶠ n in atTop, increment β n ≤ β*limitingFreeEnergy β+ε := by + have h := frequently_increment_le_of_slope (tendsto_pressure_perSpin hβ) hε + apply (h.and_eventually (eventually_gt_atTop 0)).mono + rintro n ⟨hn,hp⟩ + rwa [increment_eq hp] + +lemma increment_bounded_below (β : ℝ) : + IsBoundedUnder (fun x y : ℝ => y ≤ x) atTop (increment β) := by + refine ⟨pressure β 1, ?_⟩ + change ∀ᶠ (n : ℕ) in atTop, pressure β 1 ≤ increment β n + filter_upwards [eventually_gt_atTop 0] with n hn + exact increment_lower hn β + + + +lemma limitingFreeEnergy_ge_cavity_liminf {β : ℝ} (hβ : 0 < β) : + liminf (increment β) atTop ≤ β*limitingFreeEnergy β := by + apply le_of_forall_pos_le_add + intro ε hε + exact liminf_le_of_frequently_le (frequently_cavity_upper hβ hε) (increment_bounded_below β) +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + +def replicaWeight {ι : Type*} [Fintype ι] {r : ℕ} (x : ι → ℝ) (σ : Fin r → ι) : ℝ := + ∏ l, weight x (σ l) + +lemma replicaWeight_nonneg {ι : Type*} [Fintype ι] [Nonempty ι] {r : ℕ} + (x : ι → ℝ) (σ : Fin r → ι) : 0 ≤ replicaWeight x σ := + Finset.prod_nonneg (fun l _ => (weight_pos x (σ l)).le) + +lemma replicaWeight_le_one {ι : Type*} [Fintype ι] [Nonempty ι] {r : ℕ} + (x : ι → ℝ) (σ : Fin r → ι) : replicaWeight x σ ≤ 1 := + Finset.prod_le_one₀ (fun l _ => (weight_pos x (σ l)).le) (fun l _ => weight_le_one x (σ l)) + +lemma sum_replicaWeight {ι : Type*} [Fintype ι] [Nonempty ι] (r : ℕ) (x : ι → ℝ) : + (∑ σ : Fin r → ι, replicaWeight x σ)=1 := by + classical + simp only [replicaWeight, ← Fintype.prod_sum, sum_weight, Finset.prod_const_one] + +lemma continuous_replicaWeight {ι : Type*} [Fintype ι] [Nonempty ι] {r : ℕ} + (σ : Fin r → ι) : Continuous (fun x : ι → ℝ => replicaWeight x σ) := by + unfold replicaWeight + apply continuous_finsetProd + intro l _ + exact continuous_weight (σ l) + + +def coreGibbs (n : ℕ) (β : ℝ) (J : Disorder n) : Configuration n → ℝ := + fun σ => β*core n J σ + +lemma coreGibbs_eq_field (n : ℕ) (β : ℝ) (J : Disorder n) : + coreGibbs n β J=field (fun σ e => β*coreScale n*skCoeff n σ e) J := by + rw [field_scale,field_skCoeff] + ext σ + simp [coreGibbs, core, mul_assoc] + +lemma continuous_coreGibbs (n : ℕ) (β : ℝ) : Continuous (coreGibbs n β) := by + have he : coreGibbs n β=field (fun σ e => β*coreScale n*skCoeff n σ e) := funext (coreGibbs_eq_field n β) + rw [he] + exact continuous_field _ + +lemma integrable_replicaWeight (n r : ℕ) (β : ℝ) (σ : Fin r → Configuration n) : + Integrable (fun J => replicaWeight (coreGibbs n β J) σ) (disorderLaw n) := by + have : IsProbabilityMeasure (disorderLaw n) := by unfold disorderLaw; infer_instance + apply (integrable_const (1:ℝ)).mono' + ((continuous_replicaWeight σ).comp (continuous_coreGibbs n β)).aestronglyMeasurable + filter_upwards with J + simp only [Function.comp_apply, Real.norm_eq_abs] + rw [abs_of_nonneg (replicaWeight_nonneg _ _)] + exact replicaWeight_le_one _ _ + + +def replicaMass (n r : ℕ) (β : ℝ) (σ : Fin r → Configuration n) : ℝ := + ∫ J, replicaWeight (coreGibbs n β J) σ ∂disorderLaw n + +lemma replicaMass_nonneg (n r : ℕ) (β : ℝ) (σ : Fin r → Configuration n) : + 0 ≤ replicaMass n r β σ := integral_nonneg (fun _ => replicaWeight_nonneg _ _) + +lemma sum_replicaMass (n r : ℕ) (β : ℝ) : + (∑ σ : Fin r → Configuration n, replicaMass n r β σ)=1 := by + have : IsProbabilityMeasure (disorderLaw n) := by unfold disorderLaw; infer_instance + unfold replicaMass + rw [← integral_finsetSum _ (fun σ _ => integrable_replicaWeight n r β σ)] + simp only [sum_replicaWeight] + simp + + +def finiteProbability {ι Ω : Type*} [Fintype ι] [MeasurableSpace Ω] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hs : ∑ i, p i=1) (f : ι → Ω) : ProbabilityMeasure Ω := + ⟨∑ i, ENNReal.ofReal (p i) • Measure.dirac (f i), ⟨by + rw [Measure.finsetSum_apply] + simp only [Measure.smul_apply, Measure.dirac_apply_of_mem (Set.mem_univ _), smul_eq_mul, mul_one] + rw [← ENNReal.ofReal_sum_of_nonneg (fun i _ => hp i), hs, ENNReal.ofReal_one]⟩⟩ + +lemma integral_finiteProbability {ι Ω : Type*} [Fintype ι] [MeasurableSpace Ω] + [MeasurableSingletonClass Ω] (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) + (hs : ∑ i, p i=1) (f : ι → Ω) (g : Ω → ℝ) : + (∫ x, g x ∂(finiteProbability p hp hs f : Measure Ω)) = ∑ i, p i*g (f i) := by + change (∫ x, g x ∂∑ i, ENNReal.ofReal (p i) • Measure.dirac (f i))=_ + rw [integral_finsetSum_measure (fun i _ => (integrable_dirac (by finiteness)).smul_measure (by finiteness))] + apply Finset.sum_congr rfl + intro i _ + rw [integral_smul_measure, integral_dirac, ENNReal.toReal_ofReal (hp i), smul_eq_mul] + + +def replicaLaw (n r : ℕ) (β : ℝ) : ProbabilityMeasure (Fin r → Configuration n) := + finiteProbability (replicaMass n r β) (replicaMass_nonneg n r β) (sum_replicaMass n r β) id + +lemma integral_replicaLaw (n r : ℕ) (β : ℝ) (f : (Fin r → Configuration n) → ℝ) : + (∫ σ, f σ ∂(replicaLaw n r β : Measure _)) = + ∫ J, ∑ σ : Fin r → Configuration n, replicaWeight (coreGibbs n β J) σ*f σ ∂disorderLaw n := by + rw [replicaLaw, integral_finiteProbability, integral_finsetSum _ + (fun σ _ => (integrable_replicaWeight n r β σ).mul_const (f σ))] + simp only [integral_mul_const, replicaMass, id_eq] +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +abbrev OverlapEntry := Set.Icc (-1 : ℝ) 1 +abbrev OverlapArray := ℕ → ℕ → OverlapEntry + +lemma abs_overlap_le_one {n : ℕ} (σ τ : Configuration n) : |overlap σ τ| ≤ 1 := by + have hs : |overlapSum σ τ| ≤ (n : ℝ) := by + calc + _ ≤ ∑ i, |spin σ i * spin τ i| := Finset.abs_sum_le_sum_abs _ _ + _ = n := by simp [abs_mul] + by_cases hn : n=0 + · subst n; simp [overlap] + · rw [overlap, abs_div, abs_of_nonneg (show (0:ℝ) ≤ (n:ℝ) by positivity)] + exact (div_le_one (Nat.cast_pos.mpr (Nat.pos_of_ne_zero hn))).mpr hs + +lemma overlap_symm {n : ℕ} (σ τ : Configuration n) : overlap σ τ=overlap τ σ := by + simp only [overlap, overlapSum, mul_comm] + +lemma overlap_self {n : ℕ} (hn : 0 ⟨overlap (extendReplicas σ i) (extendReplicas σ j), + (abs_le.mp (abs_overlap_le_one _ _))⟩ + + + +def overlapLaw (n : ℕ) (β : ℝ) : ProbabilityMeasure OverlapArray := + finiteProbability (replicaMass n (n+1) β) (replicaMass_nonneg n (n+1) β) + (sum_replicaMass n (n+1) β) configurationOverlap + +lemma integral_overlapLaw (n : ℕ) (β : ℝ) (f : OverlapArray → ℝ) : + (∫ R, f R ∂(overlapLaw n β : Measure _)) = + ∫ J, ∑ σ : Fin (n+1) → Configuration n, + replicaWeight (coreGibbs n β J) σ * f (configurationOverlap σ) ∂disorderLaw n := by + rw [overlapLaw, integral_finiteProbability, integral_finsetSum _ + (fun σ _ => (integrable_replicaWeight n (n+1) β σ).mul_const (f (configurationOverlap σ)))] + simp only [integral_mul_const, replicaMass] + + + +theorem exists_overlap_limit (β : ℝ) : + ∃ μ : ProbabilityMeasure OverlapArray, ∃ φ : ℕ → ℕ, + StrictMono φ ∧ Tendsto (fun k => overlapLaw (φ k) β) atTop (𝓝 μ) := by + exact CompactSpace.tendsto_subseq (fun n => overlapLaw n β) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma overlap_quadratic {n m : ℕ} (σ : Fin m → Configuration n) (c : Fin m → ℝ) : + (∑ a, ∑ b, c a*c b*overlap (σ a) (σ b)) = + (∑ i, (∑ a, c a*spin (σ a) i)^2)/(n:ℝ) := by + have hi (i : Fin n) : (∑ a, ∑ b, c a*c b*(spin (σ a) i*spin (σ b) i))= + (∑ a, c a*spin (σ a) i)^2 := by + rw [pow_two, Finset.sum_mul] + apply Finset.sum_congr rfl + intro a _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro b _ + ring + calc + _ = (∑ a, ∑ b, ∑ i, c a*c b*(spin (σ a) i*spin (σ b) i))/(n:ℝ) := by + simp only [overlap, overlapSum, mul_div_assoc, Finset.mul_sum, Finset.sum_div] + _ = (∑ i, ∑ a, ∑ b, c a*c b*(spin (σ a) i*spin (σ b) i))/(n:ℝ) := by + congr 1 + rw [Finset.sum_comm] + simp_rw [Finset.sum_comm (f := fun a i => c a * c _ * (spin (σ a) i * spin (σ _) i))] + rw [Finset.sum_comm] + exact Finset.sum_congr rfl (fun i _ => Finset.sum_comm) + _ = _ := by simp_rw [hi] + + +def GramArrays : Set OverlapArray := {R | + (∀ i j, R i j=R j i) ∧ (∀ i, (R i i : ℝ)=1) ∧ + ∀ (m : ℕ) (c : Fin m → ℝ), 0 ≤ ∑ a, ∑ b, c a*c b*(R a b : ℝ)} + +lemma isClosed_GramArrays : IsClosed GramArrays := by + unfold GramArrays + simp only [Set.ofPred_and, Set.ofPred_forall] + refine (isClosed_iInter fun i => isClosed_iInter fun j => isClosed_eq (by fun_prop) (by fun_prop)).inter ?_ + refine (isClosed_iInter fun i => isClosed_eq (by fun_prop) continuous_const).inter ?_ + exact isClosed_iInter fun m => isClosed_iInter fun c => isClosed_le continuous_const (by fun_prop) + +lemma configurationOverlap_mem_Gram {n r : ℕ} (hn : 0 Subtype.ext (overlap_symm _ _), fun i => overlap_self hn _, ?_⟩ + intro m c + change 0 ≤ ∑ a, ∑ b, c a*c b*overlap (extendReplicas σ a) (extendReplicas σ b) + rw [overlap_quadratic] + exact div_nonneg (Finset.sum_nonneg (fun _ _ => sq_nonneg _)) (Nat.cast_nonneg n) + +lemma finiteProbability_set_of_forall {ι Ω : Type*} [Fintype ι] [MeasurableSpace Ω] + (p : ι → ℝ) (hp : ∀ i, 0 ≤ p i) (hs : ∑ i, p i=1) (f : ι → Ω) + {s : Set Ω} (hf : ∀ i, f i ∈ s) : (finiteProbability p hp hs f : Measure Ω) s=1 := by + change (∑ i, ENNReal.ofReal (p i) • Measure.dirac (f i)) s=1 + rw [Measure.finsetSum_apply] + simp only [Measure.smul_apply, Measure.dirac_apply_of_mem (hf _), smul_eq_mul, mul_one] + rw [← ENNReal.ofReal_sum_of_nonneg (fun i _ => hp i), hs, ENNReal.ofReal_one] + +lemma overlapLaw_Gram {n : ℕ} (hn : 0 overlapLaw (φ k) β) atTop (𝓝 μ)) : + (μ : Measure OverlapArray) GramArrays=1 := by + have h := ProbabilityMeasure.limsup_measure_closed_le_of_tendsto hμ isClosed_GramArrays + have he : ∀ᶠ k in atTop, (overlapLaw (φ k) β : Measure OverlapArray) GramArrays=(1:ℝ≥0∞) := + (hφ.tendsto_atTop.eventually (eventually_gt_atTop 0)).mono (fun _ hk => overlapLaw_Gram hk β) + rw [limsup_congr he, limsup_const] at h + exact le_antisymm (prob_le_one) h + + + +theorem exists_Gram_overlap_limit (β : ℝ) : + ∃ μ : ProbabilityMeasure OverlapArray, (μ : Measure _) GramArrays=1 ∧ + ∃ φ : ℕ → ℕ, StrictMono φ ∧ Tendsto (fun k => overlapLaw (φ k) β) atTop (𝓝 μ) := by + obtain ⟨μ,φ,hφ,hμ⟩ := exists_overlap_limit β + exact ⟨μ,overlap_limit_Gram β hφ hμ,φ,hφ,hμ⟩ +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + + + +omit [Nonempty ι] in +lemma tuple_partition (r : ℕ) (x : ι → ℝ) : + partition (fun σ : Fin r → ι => ∑ l, x (σ l)) = ∏ _ : Fin r, partition x := by + simp only [partition, Real.exp_sum] + exact (Fintype.prod_sum (fun (_ : Fin r) (i : ι) => Real.exp (x i))).symm + +omit [Nonempty ι] in +lemma replicaWeight_eq_weight {r : ℕ} (x : ι → ℝ) (σ : Fin r → ι) : + replicaWeight x σ=weight (fun τ : Fin r → ι => ∑ l, x (τ l)) σ := by + rw [weight, tuple_partition, Real.exp_sum] + simp only [replicaWeight, weight, Finset.prod_div_distrib] + + +def tupleCoeff {d r : ℕ} (A : ι → Fin d → ℝ) (σ : Fin r → ι) (k : Fin d) : ℝ := + ∑ l, A (σ l) k + +omit [Fintype ι] [Nonempty ι] in +lemma linearField_tupleCoeff {d r : ℕ} (A : ι → Fin d → ℝ) (z : Fin d → ℝ) + (σ : Fin r → ι) : linearField (tupleCoeff A) z σ=∑ l, linearField A z (σ l) := by + simp only [linearField, tupleCoeff, Finset.sum_mul] + exact Finset.sum_comm + +omit [Nonempty ι] in +lemma replicaWeight_tupleCoeff {d r : ℕ} (A : ι → Fin d → ℝ) (z : Fin d → ℝ) + (σ : Fin r → ι) : weight (linearField (tupleCoeff A) z) σ=replicaWeight (linearField A z) σ := by + have he : linearField (tupleCoeff A (r:=r)) z = fun τ => ∑ l, linearField A z (τ l) := + funext (linearField_tupleCoeff A z) + rw [he] + exact (replicaWeight_eq_weight _ _).symm + +lemma integrable_linear_replicaWeight {d r : ℕ} (A : ι → Fin d → ℝ) (σ : Fin r → ι) : + Integrable (fun z => replicaWeight (linearField A z) σ) (standardLaw d) := by + simp_rw [← replicaWeight_tupleCoeff A] + exact integrable_weight (tupleCoeff A) σ + +lemma integrable_coord_replicaWeight {d r : ℕ} (A : ι → Fin d → ℝ) + (σ : Fin r → ι) (k : Fin d) : + Integrable (fun z => z k*replicaWeight (linearField A z) σ) (standardLaw d) := by + simp_rw [← replicaWeight_tupleCoeff A] + exact integrable_coord_weight (tupleCoeff A) σ k + + + +lemma integral_coord_replicaWeight {d r : ℕ} (A : ι → Fin d → ℝ) + (σ : Fin r → ι) (k : Fin d) : + (∫ z, z k*replicaWeight (linearField A z) σ ∂standardLaw d) = + ∫ z, replicaWeight (linearField A z) σ * + ((∑ l, A (σ l) k)-(∑ τ : Fin r → ι, + replicaWeight (linearField A z) τ * ∑ l, A (τ l) k)) ∂standardLaw d := by + have h := integral_coord_weight (tupleCoeff A) σ k + simp only [replicaWeight_tupleCoeff, tupleCoeff] at h + exact h + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace GaussianConcentration +open SKGaussian ParisiInterpolation + +lemma memLp_lipschitz {E : Type*} [NormedAddCommGroup E] [MeasurableSpace E] + {μ : Measure E} [IsFiniteMeasure μ] {L : ℝ≥0} {f : E → ℝ} + (hf : LipschitzWith L f) (hx : MemLp id 2 μ) : MemLp f 2 μ := by + have hsub : LipschitzWith L (fun x => f x-f 0) := by + rw [lipschitzWith_iff_norm_sub_le] + intro x y + simpa only [sub_sub_sub_cancel_right] using hf.norm_sub_le x y + have h := hsub.comp_memLp (by simp) hx + convert h.add (memLp_const (f 0)) using 1 + ext x + simp + +lemma memLp_standard_id (n : ℕ) : MemLp id 2 (standardLaw n) := by + apply memLp_pi_iff.mpr + intro i + exact (memLp_id_gaussianReal (μ:=0) (v:=1) 2).comp_measurePreserving + (measurePreserving_eval (fun _ : Fin n => gaussianReal 0 1) i) + +lemma standard_second_moment : (∫ z : ℝ, z^2 ∂gaussianReal 0 1)=1 := by + have h := variance_eq_sub (memLp_id_gaussianReal (μ:=0) (v:=1) 2) + rw [variance_id_gaussianReal] at h + simpa using h.symm + + + +lemma variance_lipschitz_real {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) : + variance f (gaussianReal 0 1) ≤ (L:ℝ)^2 := by + have hm := memLp_lipschitz hf (memLp_id_gaussianReal (μ:=0) (v:=1) 2) + have hs : variance f (gaussianReal 0 1)=variance (fun z => f z-f 0) (gaussianReal 0 1) := + (variance_sub_const hm.aestronglyMeasurable (f 0)).symm + rw [hs] + apply (variance_le_expectation_sq (hm.sub (memLp_const (f 0))).aestronglyMeasurable).trans + have hj := integral_mono ((hm.sub (memLp_const (f 0))).integrable_sq) + (((memLp_id_gaussianReal (μ:=0) (v:=1) 2).integrable_sq).const_mul ((L:ℝ)^2)) + (fun z => by + have h := hf.norm_sub_le z 0 + simp only [Real.norm_eq_abs, sub_zero] at h + have hsq := sq_le_sq₀ (abs_nonneg (f z-f 0)) (by positivity : 0 ≤ (L:ℝ)*|z|) |>.mpr h + simpa [mul_pow, sq_abs] using hsq) + simpa only [Pi.pow_apply, id_eq, integral_const_mul, standard_second_moment, mul_one] using hj + + + +def CoordinateLipschitz {n : ℕ} (c : Fin n → ℝ≥0) (f : (Fin n → ℝ) → ℝ) : Prop := + ∀ x y, |f x-f y| ≤ ∑ i, (c i:ℝ)*|x i-y i| + +lemma CoordinateLipschitz.lipschitz {n : ℕ} {c : Fin n → ℝ≥0} + {f : (Fin n → ℝ) → ℝ} (hf : CoordinateLipschitz c f) : + LipschitzWith (∑ i,c i) f := by + rw [lipschitzWith_iff_norm_sub_le] + intro x y + rw [Real.norm_eq_abs] + apply (hf x y).trans + calc + _ ≤ ∑ i, (c i:ℝ)*‖x-y‖ := Finset.sum_le_sum (fun i _ => + mul_le_mul_of_nonneg_left (by simpa only [Real.norm_eq_abs, Pi.sub_apply] using norm_le_pi_norm (x-y) i) + (c i).coe_nonneg) + _ = _ := by simp [← Finset.sum_mul] + +lemma CoordinateLipschitz.memLp {n : ℕ} {c : Fin n → ℝ≥0} + {f : (Fin n → ℝ) → ℝ} (hf : CoordinateLipschitz c f) : MemLp f 2 (standardLaw n) := + memLp_lipschitz hf.lipschitz (memLp_standard_id n) + +end GaussianConcentration + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/BalancedConeEqForest.lean b/lean/OAI/Probability/ParisiFinite/BalancedConeEqForest.lean new file mode 100644 index 0000000000000000000000000000000000000000..acfbb64b4e27657912e5bb8bf47070deadfff5d1 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/BalancedConeEqForest.lean @@ -0,0 +1,680 @@ +import Mathlib +import OAI.Probability.ParisiFinite.NegativeFlip +import OAI.Probability.ParisiFinite.TermNormSub + +namespace OAI + +/-! Balanced Cone Eq Forest. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open scoped BigOperators Topology +open Filter + +namespace SKQAOA.SiteHistories +open Locality BoundedBranch +attribute [local instance] Classical.propDecidable + + + +theorem balanced_cone_eq_forest {m : ℕ} (p : ℕ) (γ β : Fin p → ℝ) + (r : Edge m) (H : Finset (Edge m)) + (hc : H⊆relevantEdges (H∪{r}) (qaoaWord p γ β) (roots r)) + (hb : (usedVertices r H).card=H.card+2) : + H=forestEdges r (forestCode r H p) := by + apply (Finset.eq_of_subset_of_card_le (forestCode_edges_subset r H p) ?_).symm + rw [forestCode_edges_card] + have hu := used_card_eq_forestSize_add_two p γ β r H hc + omega + + + +theorem nonzero_shape_is_forest (m p : ℕ) (γ β : Fin p → ℝ) (g : FullGraph m) + (hn : shapeTermLimit m p γ β g≠0) : + m=g.1.2.card+2 ∧ g.1.2=forestEdges g.1.1 (forestCode g.1.1 g.1.2 p) ∧ + reached g.1.1 g.1.2 p=Finset.univ := by + have hb : m=g.1.2.card+2 := by + by_contra h + exact hn (by simp [shapeTermLimit,h]) + have hg : graphCoefficientLimit m p γ β g.1.1 g.1.2≠0 := by + intro hz + exact hn (by simp [shapeTermLimit,hb,hz]) + have hc : g.1.2⊆relevantEdges (g.1.2∪{g.1.1}) (qaoaWord p γ β) (roots g.1.1) := by + by_contra h + exact hg (graphCoefficientLimit_zero_of_not_cone m p γ β g.1.1 g.1.2 h) + have hcount : (usedVertices g.1.1 g.1.2).card=g.1.2.card+2 := by + rw [g.2,Finset.card_univ,Fintype.card_fin] + exact hb + refine ⟨hb,balanced_cone_eq_forest p γ β g.1.1 g.1.2 hc hcount,?_⟩ + exact (used_eq_ball p γ β g.1.1 g.1.2 hc).symm.trans g.2 + + + +theorem energySliceLimit_eq_forests (m p : ℕ) (γ β : Fin p → ℝ) : + energySliceLimit m p γ β= + ∑g : FullGraph m with m=g.1.2.card+2 ∧ + g.1.2=forestEdges g.1.1 (forestCode g.1.1 g.1.2 p) ∧ + reached g.1.1 g.1.2 p=Finset.univ, + (m.factorial:ℂ)⁻¹*graphCoefficientLimit m p γ β g.1.1 g.1.2 := by + unfold energySliceLimit + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro g hg + by_cases hc : m=g.1.2.card+2 ∧ + g.1.2=forestEdges g.1.1 (forestCode g.1.1 g.1.2 p) ∧ + reached g.1.1 g.1.2 p=Finset.univ + · simp only [ite_eq_left hc,shapeTermLimit,ite_eq_left hc.1] + · rw [ite_eq_right hc] + by_contra hn + exact hc (nonzero_shape_is_forest m p γ β g hn) + +end SKQAOA.SiteHistories + + + +open scoped BigOperators Topology +open Filter + +namespace SKQAOA.SiteHistories + +@[fun_prop] theorem continuous_step (σ τ : Bool) : Continuous (fun t : ℝ => step t σ τ) := by + unfold step + split_ifs <;> fun_prop + +@[fun_prop] theorem continuous_mix (p : ℕ) (σ : Bool) (h : Bits p) : + Continuous (fun β : Fin p → ℝ => mix p β σ h) := by + induction p generalizing σ with + | zero => simp only [mix]; fun_prop + | succ p ih => + simp only [mix] + apply Continuous.mul + · fun_prop + · exact (ih _ _).comp (continuous_pi fun i => continuous_apply i.castSucc) + +@[fun_prop] theorem continuous_weight (p : ℕ) (s : Site p) : + Continuous (fun β : Fin p → ℝ => weight p β s) := by + unfold weight + fun_prop + +@[fun_prop] theorem continuous_interaction (p : ℕ) (a b : Bits p) : + Continuous (fun γ : Fin p → ℝ => interaction p γ a b) := by + induction p with + | zero => simp only [interaction]; fun_prop + | succ p ih => + simp only [interaction] + apply Continuous.add + · fun_prop + · exact (ih _ _).comp (continuous_pi fun i => continuous_apply i.castSucc) + +@[fun_prop] theorem continuous_delta (p : ℕ) (a b : Site p) : + Continuous (fun γ : Fin p → ℝ => delta p γ a b) := by + unfold delta + fun_prop + +@[fun_prop] theorem continuous_angleMass (p : ℕ) : + Continuous (fun γ : Fin p → ℝ => angleMass p γ) := by + induction p with + | zero => simp only [angleMass]; fun_prop + | succ p ih => + simp only [angleMass] + apply Continuous.add + · fun_prop + · exact ih.comp (continuous_pi fun i => continuous_apply i.castSucc) + +@[fun_prop] theorem continuous_variation (p : ℕ) : + Continuous (fun β : Fin p → ℝ => variation p β) := by + unfold variation + fun_prop + +@[fun_prop] theorem continuous_activity (p : ℕ) : + Continuous (fun θ : (Fin p → ℝ)×(Fin p → ℝ) => activity p θ.1 θ.2) := by + unfold activity + fun_prop + +@[fun_prop] theorem continuous_markedBound (p : ℕ) : + Continuous (fun θ : (Fin p → ℝ)×(Fin p → ℝ) => markedBound p θ.1 θ.2) := by + unfold markedBound + fun_prop + +@[fun_prop] theorem continuous_tower (h : ℕ) : + Continuous (fun x : ℝ => BoundedBranch.tower x h) := by + induction h with + | zero => simp only [BoundedBranch.tower]; fun_prop + | succ h ih => + simp only [BoundedBranch.tower] + exact Real.continuous_exp.comp (continuous_id.mul ih) + +@[fun_prop] theorem continuous_tailConstant (p : ℕ) : + Continuous (fun θ : (Fin p → ℝ)×(Fin p → ℝ) => tailConstant p θ.1 θ.2) := by + unfold tailConstant + fun_prop + +@[fun_prop] theorem continuous_graphCoefficientLimit (m p : ℕ) (r : Edge m) + (H : Finset (Edge m)) : + Continuous (fun θ : (Fin p → ℝ)×(Fin p → ℝ) => graphCoefficientLimit m p θ.1 θ.2 r H) := by + unfold graphCoefficientLimit FiniteHistory.expectation + apply continuous_finsetSum + intro a ha + apply Continuous.mul + · fun_prop + · apply Continuous.mul + · fun_prop + · apply continuous_finsetProd + intro e he + split_ifs <;> fun_prop + +@[fun_prop] theorem continuous_shapeTermLimit (m p : ℕ) (g : FullGraph m) : + Continuous (fun θ : (Fin p → ℝ)×(Fin p → ℝ) => shapeTermLimit m p θ.1 θ.2 g) := by + unfold shapeTermLimit + split_ifs <;> fun_prop + +@[fun_prop] theorem continuous_energySliceLimit (m p : ℕ) : + Continuous (fun θ : (Fin p → ℝ)×(Fin p → ℝ) => energySliceLimit m p θ.1 θ.2) := by + unfold energySliceLimit + fun_prop + +end SKQAOA.SiteHistories + + + +open scoped Topology +open Filter + +namespace UniformApproximation + + + +theorem continuous_of_geometric_approximants {X E : Type*} [TopologicalSpace X] + [PseudoMetricSpace E] (f : X → E) (a : ℕ → X → E) (C : X → ℝ) + (ha : ∀ L,Continuous (a L)) (hC : Continuous C) + (_ : ∀ x,0≤C x) (hd : ∀ L x,dist (f x) (a L x)≤C x/(2:ℝ)^L) : + Continuous f := by + apply continuous_iff_continuousAt.mpr + intro x + change Tendsto f (𝓝 x) (𝓝 (f x)) + rw [Metric.tendsto_nhds] + intro ε hε + have ht : Tendsto (fun L : ℕ => (C x+1)/(2:ℝ)^L) atTop (𝓝 0) := by + have hh := (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : 0≤(2:ℝ)⁻¹) + (by norm_num : (2:ℝ)⁻¹<1)).const_mul (C x+1) + simpa only [div_eq_mul_inv,inv_pow,mul_zero] using hh + obtain ⟨L,hL⟩ := (ht.eventually (gt_mem_nhds (by positivity : 0<ε/4))).exists + have hnearC : ∀ᶠ y in 𝓝 x,C y valueApprox p L θ.1 θ.2) := by + unfold valueApprox + fun_prop + + + +theorem value_approx_error (p L : ℕ) (γ β : Fin p → ℝ) : + |value p γ β-valueApprox p L γ β|≤tailConstant p γ β/(2:ℝ)^L := by + have ht := (tendsto_expectedEnergy_value p γ β).sub + (Complex.continuous_re.continuousAt.tendsto.comp (tendsto_truncatedEnergy p L γ β)) + apply le_of_tendsto ht.abs + apply Eventually.of_forall + intro n + calc + |expectedEnergy n p γ β-(truncatedEnergy n p L γ β).re| + = |(complexEnergy n p γ β-truncatedEnergy n p L γ β).re| := by + rw [expectedEnergy_eq_complexEnergy,Complex.sub_re] + _ ≤ ‖complexEnergy n p γ β-truncatedEnergy n p L γ β‖ := Complex.abs_re_le_norm _ + _ ≤ _ := norm_complexEnergy_sub_truncated n p L γ β + +end SKQAOA.SiteHistories + +namespace SKQAOA + + + +@[fun_prop] theorem continuous_value (p : ℕ) : + Continuous (fun θ : (Fin p → ℝ)×(Fin p → ℝ) => value p θ.1 θ.2) := by + apply UniformApproximation.continuous_of_geometric_approximants + (a:=fun L θ => SiteHistories.valueApprox p L θ.1 θ.2) + (C:=fun θ => SiteHistories.tailConstant p θ.1 θ.2) + · exact SiteHistories.continuous_valueApprox p + · exact SiteHistories.continuous_tailConstant p + · exact fun θ => SiteHistories.tailConstant_nonneg p θ.1 θ.2 + · intro L θ + simpa only [Real.dist_eq] using SiteHistories.value_approx_error p L θ.1 θ.2 + +end SKQAOA + + + +open scoped BigOperators Topology +open Filter + +namespace SKQAOA.SiteHistories +attribute [local instance] Classical.propDecidable + + + +theorem norm_energySlice_bound (n p L : ℕ) (γ β : Fin p → ℝ) : + ‖energySlice n (L+2) p γ β‖≤tailConstant p γ β/(2:ℝ)^L := by + calc + _ ≤ ∑g : MarkedGraph n with (usedVertices g.1 g.2).card=L+2, + ‖clusterEnergy p γ β g.1 g.2‖ := norm_sum_le _ _ + _ ≤ ∑g : MarkedGraph n with L+2≤(usedVertices g.1 g.2).card, + ‖clusterEnergy p γ β g.1 g.2‖ := by + apply Finset.sum_le_sum_of_subset_of_nonneg + · intro g hg + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,le_of_eq (Finset.mem_filter.mp hg).2.symm⟩ + · intro g hg hgn + exact norm_nonneg _ + _ = ∑r : Edge n,∑H : Finset (Edge n) with L+2≤(usedVertices r H).card, + ‖clusterEnergy p γ β r H‖ := by + simp only [Finset.sum_filter,Fintype.sum_prod_type] + _ ≤ _ := sum_norm_clusterEnergy_tail n p L γ β + +theorem norm_energySliceLimit_bound (p L : ℕ) (γ β : Fin p → ℝ) : + ‖energySliceLimit (L+2) p γ β‖≤tailConstant p γ β/(2:ℝ)^L := by + apply le_of_tendsto (tendsto_energySlice (L+2) p γ β).norm + exact Eventually.of_forall (fun n => norm_energySlice_bound n p L γ β) + + + +theorem summable_energySliceLimit (p : ℕ) (γ β : Fin p → ℝ) : + Summable (fun m => energySliceLimit m p γ β) := by + have hg : Summable (fun L : ℕ => tailConstant p γ β/(2:ℝ)^L) := by + have := (summable_geometric_of_norm_lt_one (by norm_num : ‖(2:ℝ)⁻¹‖<1)).mul_left + (tailConstant p γ β) + simpa only [div_eq_mul_inv,inv_pow] using this + have hs : Summable (fun L => energySliceLimit (L+2) p γ β) := + Summable.of_norm_bounded hg (fun L => norm_energySliceLimit_bound p L γ β) + exact (summable_nat_add_iff 2).mp hs + + + +theorem value_eq_support_series (p : ℕ) (γ β : Fin p → ℝ) : + value p γ β=(∑'m : ℕ,energySliceLimit m p γ β).re := by + have hs := (summable_energySliceLimit p γ β).hasSum.tendsto_sum_nat + have ht : Tendsto (fun L : ℕ => valueApprox p L γ β) atTop + (𝓝 (∑'m : ℕ,energySliceLimit m p γ β).re) := by + exact Complex.continuous_re.continuousAt.tendsto.comp (hs.comp (tendsto_add_atTop_nat 2)) + have hz : Tendsto (fun L : ℕ => tailConstant p γ β/(2:ℝ)^L) atTop (𝓝 0) := by + have := (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : 0≤(2:ℝ)⁻¹) + (by norm_num : (2:ℝ)⁻¹<1)).const_mul (tailConstant p γ β) + simpa only [div_eq_mul_inv,inv_pow,mul_zero] using this + have hv : Tendsto (fun L : ℕ => valueApprox p L γ β) atTop (𝓝 (value p γ β)) := by + apply tendsto_iff_dist_tendsto_zero.mpr + apply squeeze_zero (fun L => dist_nonneg) _ hz + intro L + simpa only [Real.dist_eq,abs_sub_comm] using value_approx_error p L γ β + exact tendsto_nhds_unique hv ht + + + +theorem value_eq_forest_series (p : ℕ) (γ β : Fin p → ℝ) : + value p γ β=(∑'m : ℕ, + ∑g : FullGraph m with m=g.1.2.card+2 ∧ + g.1.2=forestEdges g.1.1 (forestCode g.1.1 g.1.2 p) ∧ + reached g.1.1 g.1.2 p=Finset.univ, + (m.factorial:ℂ)⁻¹*graphCoefficientLimit m p γ β g.1.1 g.1.2).re := by + rw [value_eq_support_series] + congr 1 + apply tsum_congr + intro m + exact energySliceLimit_eq_forests m p γ β + +end SKQAOA.SiteHistories + + + +open scoped Topology +open Filter + +namespace RawPulseControl +open PulseControl +variable {A κ : Type*} [NormedRing A] [NormedAlgebra ℝ A] + + +def words (G : κ → A) : Submonoid A where + carrier := Set.range (pulseValue G) + one_mem' := ⟨[],rfl⟩ + mul_mem' := by + rintro U V ⟨w,rfl⟩ ⟨v,rfl⟩ + exact ⟨w++v,pulseValue_append G w v⟩ + +variable [NormedAlgebra ℚ A] [CompleteSpace A] [StarRing A] [CStarRing A] [StarModule ℝ A] + +theorem words_unitary (G : κ → A) (hG : ∀a,G a∈skewAdjoint A) : + words G≤unitary A := by + rintro U ⟨w,rfl⟩ + apply (unitary A).list_prod_mem + intro x hx + obtain ⟨p,hp,rfl⟩ := List.mem_map.mp hx + exact NormedSpace.exp_mem_unitary_of_mem_skewAdjoint (skewAdjoint.smul_mem p.2 (hG p.1)) + +theorem closure_unitary (G : κ → A) (hG : ∀a,G a∈skewAdjoint A) : + (words G).topologicalClosure≤unitary A := + (words G).topologicalClosure_minimal (words_unitary G hG) isClosed_unitary + +variable [NormOneClass A] [Nontrivial A] + +def directions (G : κ → A) (hG : ∀a,G a∈skewAdjoint A) : Submodule ℝ A := + tangents _ (words G).isClosed_topologicalClosure (closure_unitary G hG) + +theorem generator_mem (G : κ → A) (hG : ∀a,G a∈skewAdjoint A) (a : κ) : + G a∈directions G hG := by + refine ⟨hG a,fun t => (words G).le_topologicalClosure ?_⟩ + exact ⟨[(a,t)],by simp only [pulseValue,List.map_cons,List.map_nil,List.prod_cons,List.prod_nil,mul_one]⟩ + +theorem bracket_mem (G : κ → A) (hG : ∀a,G a∈skewAdjoint A) {X Y : A} + (hX : X∈directions G hG) (hY : Y∈directions G hG) : + X*Y-Y*X∈directions G hG := by + apply commutator_loop_tangent_mem _ (words G).isClosed_topologicalClosure (closure_unitary G hG) hX.1 hY.1 + intro u v + exact (words G).topologicalClosure.mul_mem + ((words G).topologicalClosure.mul_mem + ((words G).topologicalClosure.mul_mem (hX.2 u) (hY.2 v)) (hX.2 (-u))) (hY.2 (-v)) + +theorem closed_directions (G : κ → A) (hG : ∀a,G a∈skewAdjoint A) : + IsClosed (directions G hG : Set A) := + isClosed_tangents _ (words G).isClosed_topologicalClosure (closure_unitary G hG) + + + +theorem approximate (G : κ → A) (hG : ∀a,G a∈skewAdjoint A) {X : A} + (hX : X∈directions G hG) (t : ℝ) {ε : ℝ} (hε : 0<ε) : + ∃w : List (κ×ℝ),‖pulseValue G w-NormedSpace.exp (t•X)‖<ε := by + obtain ⟨U,⟨w,rfl⟩,hd⟩ := Metric.mem_closure_iff.mp (hX.2 t) ε hε + exact ⟨w,by simpa only [dist_eq_norm,norm_sub_rev] using hd⟩ + +end RawPulseControl + + + +open scoped Topology +open Filter + +namespace CompactSeedControl +open QuaternionControl RawPulseControl +variable {S : Type*} [TopologicalSpace S] [CompactSpace S] [Nonempty S] + +abbrev SpinField (S : Type*) [TopologicalSpace S] := C(S,Quaternion ℝ) +local instance balancedConeEqForestSpinFieldNormedAlgebra : NormedAlgebra ℚ (SpinField S) := + NormedAlgebra.restrictScalars ℚ ℝ (SpinField S) + +def X (f : C(S,ℝ)) : SpinField S := + ⟨fun s => f s • (⟨0,0,0,1⟩ : Quaternion ℝ),f.continuous.smul continuous_const⟩ +def Y (f : C(S,ℝ)) : SpinField S := + ⟨fun s => f s • (⟨0,0,1,0⟩ : Quaternion ℝ),f.continuous.smul continuous_const⟩ +def Z (f : C(S,ℝ)) : SpinField S := + ⟨fun s => f s • (⟨0,1,0,0⟩ : Quaternion ℝ),f.continuous.smul continuous_const⟩ + +omit [CompactSpace S] [Nonempty S] in +@[simp] theorem X_apply (f : C(S,ℝ)) (s : S) : X f s=⟨0,0,0,f s⟩ := by + change f s • (⟨0,0,0,1⟩ : Quaternion ℝ) = _ + apply Quaternion.ext <;> simp +omit [CompactSpace S] [Nonempty S] in +@[simp] theorem Y_apply (f : C(S,ℝ)) (s : S) : Y f s=⟨0,0,f s,0⟩ := by + change f s • (⟨0,0,1,0⟩ : Quaternion ℝ) = _ + apply Quaternion.ext <;> simp +omit [CompactSpace S] [Nonempty S] in +@[simp] theorem Z_apply (f : C(S,ℝ)) (s : S) : Z f s=⟨0,f s,0,0⟩ := by + change f s • (⟨0,1,0,0⟩ : Quaternion ℝ) = _ + apply Quaternion.ext <;> simp + +omit [CompactSpace S] [Nonempty S] in +@[simp] theorem X_add (f g : C(S,ℝ)) : X (f+g)=X f+X g := by + apply ContinuousMap.ext + intro s + simpa only [ContinuousMap.add_apply,X_apply,qX,Pi.add_apply] using + congrFun (qX_add (fun t => f t) (fun t => g t)) s +omit [CompactSpace S] [Nonempty S] in +@[simp] theorem X_smul (r : ℝ) (f : C(S,ℝ)) : X (r•f)=r•X f := by + apply ContinuousMap.ext + intro s + simpa only [ContinuousMap.smul_apply,X_apply,qX,Pi.smul_apply,smul_eq_mul] using + congrFun (qX_smul r (fun t => f t)) s +omit [CompactSpace S] [Nonempty S] in +@[simp] theorem Y_smul (r : ℝ) (f : C(S,ℝ)) : Y (r•f)=r•Y f := by + apply ContinuousMap.ext + intro s + change (r * f s) • (⟨0,0,1,0⟩ : Quaternion ℝ) = r • (f s • (⟨0,0,1,0⟩ : Quaternion ℝ)) + exact mul_smul r (f s) _ +omit [CompactSpace S] [Nonempty S] in +@[simp] theorem Z_smul (r : ℝ) (f : C(S,ℝ)) : Z (r•f)=r•Z f := by + apply ContinuousMap.ext + intro s + change (r * f s) • (⟨0,1,0,0⟩ : Quaternion ℝ) = r • (f s • (⟨0,1,0,0⟩ : Quaternion ℝ)) + exact mul_smul r (f s) _ + +omit [CompactSpace S] [Nonempty S] in +theorem bracket_ZX (f g : C(S,ℝ)) : Z f*X g-X g*Z f=Y ((-2:ℝ)•(f*g)) := by + apply ContinuousMap.ext + intro s + simpa only [ContinuousMap.mul_apply,ContinuousMap.sub_apply,ContinuousMap.smul_apply, + X_apply,Y_apply,Z_apply,qX,qY,qZ,Pi.mul_apply,Pi.sub_apply,smul_eq_mul,mul_assoc] using + congrFun (bracket_zx (fun t => f t) (fun t => g t)) s + +omit [CompactSpace S] [Nonempty S] in +theorem bracket_ZY (f g : C(S,ℝ)) : Z f*Y g-Y g*Z f=X ((2:ℝ)•(f*g)) := by + rw [X_smul] + apply ContinuousMap.ext + intro s + simpa only [ContinuousMap.mul_apply,ContinuousMap.sub_apply,ContinuousMap.smul_apply, + X_apply,Y_apply,Z_apply,qX,qY,qZ,Pi.mul_apply,Pi.sub_apply,Pi.smul_apply,smul_eq_mul] using + congrFun (bracket_zy (fun t => f t) (fun t => g t)) s + +omit [CompactSpace S] [Nonempty S] in +theorem bracket_YX (f g : C(S,ℝ)) : Y f*X g-X g*Y f=Z ((2:ℝ)•(f*g)) := by + apply ContinuousMap.ext + intro s + simpa only [ContinuousMap.mul_apply,ContinuousMap.sub_apply,ContinuousMap.smul_apply, + X_apply,Y_apply,Z_apply,qX,qY,qZ,Pi.mul_apply,Pi.sub_apply,smul_eq_mul,mul_assoc] using + congrFun (bracket_yx (fun t => f t) (fun t => g t)) s + + + +def generator (s : C(S,ℝ)) (a : Bool) : SpinField S := if a then Z s else X 1 + +omit [CompactSpace S] [Nonempty S] in +theorem generator_skew (s : C(S,ℝ)) (a : Bool) : generator s a∈skewAdjoint (SpinField S) := by + rw [skewAdjoint.mem_iff] + apply ContinuousMap.ext + intro t + have hx (r : ℝ) : star (r • (⟨0,0,0,1⟩ : Quaternion ℝ)) = -(r • (⟨0,0,0,1⟩ : Quaternion ℝ)) := by + apply QuaternionAlgebra.star_eq_neg.mpr + change r * 0 = 0 + ring + have hz (r : ℝ) : star (r • (⟨0,1,0,0⟩ : Quaternion ℝ)) = -(r • (⟨0,1,0,0⟩ : Quaternion ℝ)) := by + apply QuaternionAlgebra.star_eq_neg.mpr + change r * 0 = 0 + ring + cases a + · exact hx 1 + · exact hz (s t) + +def available (s : C(S,ℝ)) : Submodule ℝ (SpinField S) := + directions (generator s) (generator_skew s) + +theorem X_one_mem (s : C(S,ℝ)) : X 1∈available s := + generator_mem (generator s) (generator_skew s) false + +theorem Z_seed_mem (s : C(S,ℝ)) : Z s∈available s := + generator_mem (generator s) (generator_skew s) true + +theorem Y_seed_mul_mem (s f : C(S,ℝ)) (hf : X f∈available s) : + Y (s*f)∈available s := by + have h := bracket_mem (generator s) (generator_skew s) (Z_seed_mem s) hf + rw [bracket_ZX,Y_smul] at h + have hh := (available s).smul_mem (-1/2:ℝ) h + simpa only [smul_smul,show (-1/2:ℝ)*(-2)=1 by norm_num,one_smul] using hh + +theorem X_sq_mul_mem (s f : C(S,ℝ)) (hf : X f∈available s) : + X (s^2*f)∈available s := by + have h := bracket_mem (generator s) (generator_skew s) (Z_seed_mem s) (Y_seed_mul_mem s f hf) + rw [bracket_ZY,X_smul] at h + have hh := (available s).smul_mem (1/2:ℝ) h + simp only [smul_smul,show (1/2:ℝ)*2=1 by norm_num,one_smul] at hh + simpa only [pow_two,mul_assoc] using hh + +theorem X_even_power_mem (s : C(S,ℝ)) (k : ℕ) : X ((s^2)^k)∈available s := by + induction k with + | zero => simpa only [pow_zero] using X_one_mem s + | succ k ih => simpa only [pow_succ'] using X_sq_mul_mem s ((s^2)^k) ih + + + +theorem X_even_polynomial_mem (s : C(S,ℝ)) (P : Polynomial ℝ) : + X (P.aeval (s^2))∈available s := by + induction P using Polynomial.induction_on' with + | add P Q hP hQ => simpa only [map_add,X_add] using (available s).add_mem hP hQ + | monomial k a => + have h := (available s).smul_mem a (X_even_power_mem s k) + rw [Polynomial.aeval_monomial,← Algebra.smul_def,X_smul] + exact h + +theorem Z_seed_mul_mem (s f : C(S,ℝ)) (hf : X f∈available s) : + Z (s*f)∈available s := by + have h := bracket_mem (generator s) (generator_skew s) (Y_seed_mul_mem s f hf) (X_one_mem s) + rw [bracket_YX,mul_one,Z_smul] at h + have hh := (available s).smul_mem (1/2:ℝ) h + simpa only [smul_smul,show (1/2:ℝ)*2=1 by norm_num,one_smul] using hh + + + +theorem polynomial_pulse_approximation (s : C(S,ℝ)) (P : Polynomial ℝ) (t : ℝ) + {ε : ℝ} (hε : 0<ε) : + ∃w : List (Bool×ℝ),‖PulseControl.pulseValue (generator s) w- + NormedSpace.exp (t•X (P.aeval (s^2)))‖<ε := + approximate (generator s) (generator_skew s) (X_even_polynomial_mem s P) t hε + +end CompactSeedControl + + + +open scoped Topology +open Filter + +namespace CompactSeedControl +variable {S : Type*} [TopologicalSpace S] [CompactSpace S] [Nonempty S] +local instance balancedConeEqForestContinuousSpinFieldNormedAlgebra : NormedAlgebra ℚ (SpinField S) := + NormedAlgebra.restrictScalars ℚ ℝ (SpinField S) + + +omit [CompactSpace S] [Nonempty S] in +theorem continuous_X : Continuous (X : C(S,ℝ) → SpinField S) := by + let k : Quaternion ℝ := ⟨0,0,0,1⟩ + exact (((ContinuousLinearMap.id ℝ ℝ).smulRight k).compLeftContinuous ℝ S).continuous + +omit [CompactSpace S] [Nonempty S] in +theorem continuous_Y : Continuous (Y : C(S,ℝ) → SpinField S) := by + let k : Quaternion ℝ := ⟨0,0,1,0⟩ + exact (((ContinuousLinearMap.id ℝ ℝ).smulRight k).compLeftContinuous ℝ S).continuous + +omit [CompactSpace S] [Nonempty S] in +theorem continuous_Z : Continuous (Z : C(S,ℝ) → SpinField S) := by + let k : Quaternion ℝ := ⟨0,1,0,0⟩ + exact (((ContinuousLinearMap.id ℝ ℝ).smulRight k).compLeftContinuous ℝ S).continuous + + + +theorem X_function_square_mem (s : C(S,ℝ)) (h : C(ℝ,ℝ)) : + X (h.comp (s^2))∈available s := by + let I := Set.Icc (0:ℝ) ‖s^2‖ + let η : C(S,I) := ⟨fun t => ⟨(s^2) t, by + constructor + · simpa only [ContinuousMap.pow_apply] using sq_nonneg (s t) + · exact (s^2).apply_le_norm t⟩, by fun_prop⟩ + have hc : Continuous (fun f : C(I,ℝ) => X (f.comp η)) := + continuous_X.comp (ContinuousMap.compRightAlgHom_continuous ℝ ℝ η) + have hz : IsClosed {f : C(I,ℝ) | X (f.comp η)∈available s} := + (RawPulseControl.closed_directions (generator s) (generator_skew s)).preimage hc + have hp : (polynomialFunctions I : Set C(I,ℝ)) ⊆ + {f : C(I,ℝ) | X (f.comp η)∈available s} := by + intro f hf + rw [polynomialFunctions_coe] at hf + obtain ⟨P,rfl⟩ := hf + change X ((P.toContinuousMapOn I).comp η)∈available s + have he : (P.toContinuousMapOn I).comp η = P.aeval (s^2) := by + ext t + simp [η,Polynomial.toContinuousMapOn,Polynomial.toContinuousMap] + rw [he] + exact X_even_polynomial_mem s P + have ht : h.restrict I ∈ closure (polynomialFunctions I : Set C(I,ℝ)) := + continuousMap_mem_polynomialFunctions_closure 0 ‖s^2‖ _ + have hh := closure_minimal hp hz ht + exact hh + + + +theorem X_even_continuous_mem (s : C(S,ℝ)) (f : C(ℝ,ℝ)) (hf : Function.Even f) : + X (f.comp s)∈available s := by + let h : C(ℝ,ℝ) := f.comp ⟨Real.sqrt,Real.continuous_sqrt⟩ + have hh := X_function_square_mem s h + have he : h.comp (s^2) = f.comp s := by + ext t + change f (Real.sqrt ((s t)^2))=f (s t) + rw [Real.sqrt_sq_eq_abs] + rcases le_total 0 (s t) with ht | ht + · rw [abs_of_nonneg ht] + · rw [abs_of_nonpos ht,hf] + rwa [he] at hh + +theorem even_continuous_pulse_approximation (s : C(S,ℝ)) (f : C(ℝ,ℝ)) + (hf : Function.Even f) (t : ℝ) {ε : ℝ} (hε : 0<ε) : + ∃w : List (Bool×ℝ),‖PulseControl.pulseValue (generator s) w- + NormedSpace.exp (t•X (f.comp s))‖<ε := + RawPulseControl.approximate (generator s) (generator_skew s) (X_even_continuous_mem s f hf) t hε + +end CompactSeedControl + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/BoundedOf.lean b/lean/OAI/Probability/ParisiFinite/BoundedOf.lean new file mode 100644 index 0000000000000000000000000000000000000000..68f22f1cfc481c8d8e6b1ec21f4e61d06332f8e7 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/BoundedOf.lean @@ -0,0 +1,685 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SpinTrace + +namespace OAI + +/-! Bounded Of. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + +def boundedOf (g : E → ℝ) (hg : Continuous g) {M : ℝ} (hM : ∀ x, |g x| ≤ M) : + BoundedContinuousFunction E ℝ where + toContinuousMap := ⟨g, hg⟩ + map_bounded' := ⟨2*M, fun x y => by + change |g x-g y| ≤ _ + have h := abs_sub_le (g x) 0 (g y) + simp only [sub_zero, zero_sub, abs_neg] at h + linarith [hM x, hM y]⟩ + +omit [NormedSpace ℝ E] in +lemma bounded_abs (g : BoundedContinuousFunction E ℝ) (x : E) : |g x| ≤ ‖g‖ := by + simpa only [Real.norm_eq_abs] using g.norm_coe_le_norm x + + + +def tiltMap (f : DirectionalField E) (a : ℝ) (c : E) : + BoundedContinuousFunction E ℝ →ₗ[ℝ] BoundedContinuousFunction E ℝ where + toFun g := boundedOf (ambientTilt a c f.val g) + (continuous_ambientTilt f.lipschitz g.continuous (bounded_abs g) a c) + (abs_ambientTilt_le f.lipschitz g.continuous (bounded_abs g) a c) + map_add' g h := by + ext x + exact ambientTilt_add f.lipschitz g.continuous h.continuous (bounded_abs g) (bounded_abs h) a c x + map_smul' k g := by + ext x + exact ambientTilt_const_mul a c f.val g x k + +@[simp] lemma tiltMap_apply (f : DirectionalField E) (a : ℝ) (c : E) + (g : BoundedContinuousFunction E ℝ) (x : E) : + tiltMap f a c g x = ambientTilt a c f.val g x := rfl + +lemma tiltMap_mono (f : DirectionalField E) (a : ℝ) (c : E) + {g h : BoundedContinuousFunction E ℝ} (hgh : ∀ x, g x ≤ h x) : + ∀ x, tiltMap f a c g x ≤ tiltMap f a c h x := + ambientTilt_mono f.lipschitz g.continuous h.continuous (bounded_abs g) (bounded_abs h) hgh a c + +@[simp] lemma tiltMap_const (f : DirectionalField E) (a : ℝ) (c : E) (k : ℝ) : + tiltMap f a c (BoundedContinuousFunction.const E k) = BoundedContinuousFunction.const E k := by + ext x + exact ambientTilt_const f.lipschitz a c x k + +lemma tiltMap_nonneg (f : DirectionalField E) (a : ℝ) (c : E) + {g : BoundedContinuousFunction E ℝ} (hg : ∀ x, 0 ≤ g x) : + ∀ x, 0 ≤ tiltMap f a c g x := by + have h := tiltMap_mono f a c (g:=0) (h:=g) hg + simpa only [map_zero, BoundedContinuousFunction.coe_zero, Pi.zero_apply] using h + +lemma norm_tiltMap_le (f : DirectionalField E) (a : ℝ) (c : E) + (g : BoundedContinuousFunction E ℝ) : ‖tiltMap f a c g‖ ≤ ‖g‖ := by + apply (BoundedContinuousFunction.norm_le (norm_nonneg g)).2 + intro x + exact abs_ambientTilt_le f.lipschitz g.continuous (bounded_abs g) a c x + +namespace DirectionalField + +def firstBCF (f : DirectionalField E) (v : E) : BoundedContinuousFunction E ℝ := + boundedOf (f.first v) (f.continuousFirst v) (f.normFirst v) + +def secondBCF (f : DirectionalField E) (v w : E) : BoundedContinuousFunction E ℝ := + boundedOf (f.second v w) (f.continuousSecond v w) (f.normSecond v w) + +@[simp] lemma firstBCF_apply (f : DirectionalField E) (v x : E) : f.firstBCF v x = f.first v x := rfl +@[simp] lemma secondBCF_apply (f : DirectionalField E) (v w x : E) : f.secondBCF v w x = f.second v w x := rfl + +lemma firstBCF_transform (f : DirectionalField E) (a : ℝ≥0) (c v : E) : + (f.transform a c).firstBCF v = tiltMap f a c (f.firstBCF v) := rfl + +lemma secondBCF_transform (f : DirectionalField E) (a : ℝ≥0) (c v w : E) : + (f.transform a c).secondBCF v w = tiltMap f a c (f.secondBCF v w) + + (a:ℝ) • (tiltMap f a c (f.firstBCF v*f.firstBCF w) - + tiltMap f a c (f.firstBCF v)*tiltMap f a c (f.firstBCF w)) := rfl +end DirectionalField + +namespace FieldFamily + +def dotBCF (F : FieldFamily E) (t : ℝ) : BoundedContinuousFunction E ℝ := + boundedOf (F.dot t) (F.continuousDot.comp (continuous_const.prodMk continuous_id)) (F.normDot t) + +@[simp] lemma dotBCF_apply (F : FieldFamily E) (t : ℝ) (x : E) : F.dotBCF t x = F.dot t x := rfl + +lemma dotBCF_constant (f : DirectionalField E) (t : ℝ) : (constant f).dotBCF t = 0 := rfl + +lemma dotBCF_transform (F : FieldFamily E) (a : ℝ≥0) (c : E) (s ds : ℝ → ℝ) + (hs : Continuous s) (hds : Continuous ds) (hd : ∀ t, HasDerivAt s (ds t) t) (t : ℝ) : + (F.transform a c s ds hs hds hd).dotBCF t = + tiltMap (F.field t) a (s t • c) (F.dotBCF t) + (s t*ds t) • + (tiltMap (F.field t) a (s t • c) ((F.field t).secondBCF c c) + (a:ℝ) • + tiltMap (F.field t) a (s t • c) ((F.field t).firstBCF c ^ 2)) := by + ext x + rfl +end FieldFamily +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + +def transport (f : DirectionalField E) : List (MovingCoordinate E) → ℝ → + (BoundedContinuousFunction E ℝ →ₗ[ℝ] BoundedContinuousFunction E ℝ) + | [], _ => LinearMap.id + | c::cs, t => (tiltMap ((hierarchy f cs).field t) c.gamma (c.scale t • c.direction)).comp + (transport f cs t) + +lemma transport_nonneg (f : DirectionalField E) (cs : List (MovingCoordinate E)) (t : ℝ) + {g : BoundedContinuousFunction E ℝ} (hg : ∀ x, 0 ≤ g x) : + ∀ x, 0 ≤ transport f cs t g x := by + induction cs with + | nil => exact hg + | cons c cs ih => exact tiltMap_nonneg _ _ _ ih + +lemma transport_const (f : DirectionalField E) (cs : List (MovingCoordinate E)) (t k : ℝ) : + transport f cs t (BoundedContinuousFunction.const E k) = BoundedContinuousFunction.const E k := by + induction cs with + | nil => rfl + | cons c cs ih => simp only [transport, LinearMap.comp_apply, ih, tiltMap_const] + +lemma hierarchy_firstBCF (f : DirectionalField E) (cs : List (MovingCoordinate E)) (t : ℝ) (v : E) : + ((hierarchy f cs).field t).firstBCF v = transport f cs t (f.firstBCF v) := by + induction cs with + | nil => rfl + | cons c cs ih => + change (((hierarchy f cs).field t).transform c.gamma (c.scale t • c.direction)).firstBCF v = _ + rw [DirectionalField.firstBCF_transform, ih] + rfl + +section FiniteSpin +variable {ι : Type*} [Fintype ι] [Nonempty ι] +open SKGaussian + + +def gibbsMap (β : ℝ) : (ι → ℝ) →ₗ[ℝ] BoundedContinuousFunction (ι → ℝ) ℝ where + toFun v := boundedOf (fun x => gibbsMean β x v) (continuous_gibbsMean β v) + (fun x => abs_gibbsMean_le β x v) + map_add' v w := by + ext x + simp [boundedOf, gibbsMean, mul_add, Finset.sum_add_distrib] + map_smul' k v := by + ext x + simp [boundedOf, gibbsMean, mul_left_comm _ k, Finset.mul_sum] + +@[simp] lemma gibbsMap_apply (β : ℝ) (v x : ι → ℝ) : gibbsMap β v x = gibbsMean β x v := rfl + +lemma gibbsMap_nonneg (β : ℝ) {v : ι → ℝ} (hv : ∀ i, 0 ≤ v i) : + ∀ x, 0 ≤ gibbsMap β v x := by + intro x + exact Finset.sum_nonneg (fun i _ => mul_nonneg (weight_pos _ _).le (hv i)) + +lemma gibbsMap_const (β k : ℝ) : gibbsMap (ι:=ι) β (fun _ => k) = + BoundedContinuousFunction.const (ι → ℝ) k := by + ext x + change (∑ i, weight (fun j => β*x j) i*k) = k + rw [← Finset.sum_mul, sum_weight, one_mul] + + + +def spinObserve (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) : + (ι → ℝ) →ₗ[ℝ] BoundedContinuousFunction (ι → ℝ) ℝ := + (transport (traceField β hβ) cs t).comp (gibbsMap β) + +lemma spinObserve_nonneg (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) + {v : ι → ℝ} (hv : ∀ i, 0 ≤ v i) : ∀ x, 0 ≤ spinObserve β hβ cs t v x := + transport_nonneg _ _ _ (gibbsMap_nonneg β hv) + +lemma spinObserve_const (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) (t k : ℝ) : + spinObserve β hβ cs t (fun _ => k) = BoundedContinuousFunction.const (ι → ℝ) k := by + simp only [spinObserve, LinearMap.comp_apply, gibbsMap_const, transport_const] + +lemma spin_first_observe (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) + (v : ι → ℝ) : ((hierarchy (traceField β hβ) cs).field t).firstBCF v = spinObserve β hβ cs t v := + hierarchy_firstBCF _ _ _ _ + + +def spinWeight [DecidableEq ι] (β : ℝ≥0) (hβ : 0 < β) + (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) (i : ι) : + BoundedContinuousFunction (ι → ℝ) ℝ := spinObserve β hβ cs t (Pi.single i 1) + +lemma spinWeight_nonneg [DecidableEq ι] (β : ℝ≥0) (hβ : 0 < β) + (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) (i : ι) (x : ι → ℝ) : + 0 ≤ spinWeight β hβ cs t i x := by + apply spinObserve_nonneg + intro j + by_cases hij : j=i <;> simp [hij] + +lemma spinObserve_eq_sum [DecidableEq ι] (β : ℝ≥0) (hβ : 0 < β) + (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) (v : ι → ℝ) : + spinObserve β hβ cs t v = ∑ i, v i • spinWeight β hβ cs t i := by + have he : v = ∑ i, v i • Pi.single i (1:ℝ) := by + ext j + simp [Pi.single_apply, apply_ite] + conv_lhs => rw [he] + simp only [map_sum, map_smul, spinWeight] + +lemma sum_spinWeight [DecidableEq ι] (β : ℝ≥0) (hβ : 0 < β) + (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) : + ∑ i, spinWeight β hβ cs t i = BoundedContinuousFunction.const (ι → ℝ) 1 := by + have he := spinObserve_eq_sum β hβ cs t (fun _ => 1) + rw [spinObserve_const] at he + simpa only [one_smul] using he.symm +end FiniteSpin +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + + +abbrev Noise (E : Type*) := List (ℝ × E) + +def noiseGradient (f : DirectionalField E) : Noise E → BoundedContinuousFunction E ℝ + | [] => 0 + | (k,v)::vs => k • (f.firstBCF v)^2 + noiseGradient f vs + +def noiseHessian (f : DirectionalField E) : Noise E → BoundedContinuousFunction E ℝ + | [] => 0 + | (k,v)::vs => k • f.secondBCF v v + noiseHessian f vs + +def noiseResponse (f : DirectionalField E) (a : ℝ) (vs : Noise E) : BoundedContinuousFunction E ℝ := + noiseHessian f vs + a • noiseGradient f vs + +lemma noiseResponse_nil (f : DirectionalField E) (a : ℝ) : noiseResponse f a [] = 0 := by + simp [noiseResponse, noiseHessian, noiseGradient] + +lemma noiseResponse_cons (f : DirectionalField E) (a k : ℝ) (v : E) (vs : Noise E) : + noiseResponse f a ((k,v)::vs) = k • (f.secondBCF v v+a •(f.firstBCF v)^2)+noiseResponse f a vs := by + simp only [noiseResponse, noiseHessian, noiseGradient] + module + +lemma noiseHessian_transform (f : DirectionalField E) (a : ℝ≥0) (c : E) (vs : Noise E) : + noiseHessian (f.transform a c) vs = tiltMap f a c (noiseHessian f vs) + (a:ℝ) • + (tiltMap f a c (noiseGradient f vs)-noiseGradient (f.transform a c) vs) := by + induction vs with + | nil => simp [noiseHessian, noiseGradient] + | cons kv vs ih => + rcases kv with ⟨k,v⟩ + simp only [noiseHessian, noiseGradient, DirectionalField.secondBCF_transform, ih, + map_add, map_smul, DirectionalField.firstBCF_transform, pow_two] + module + + +lemma noiseResponse_transform (f : DirectionalField E) (b : ℝ≥0) (a : ℝ) (c : E) (vs : Noise E) : + noiseResponse (f.transform b c) a vs = + tiltMap f b c (noiseResponse f b vs) - ((b:ℝ)-a) • noiseGradient (f.transform b c) vs := by + simp only [noiseResponse, noiseHessian_transform, map_add, map_smul] + module + +def coordinateNoise (c : MovingCoordinate E) (t : ℝ) : ℝ × E := (c.scale t*c.velocity t,c.direction) + +def allNoise : List (MovingCoordinate E) → ℝ → Noise E → Noise E + | [], _, vs => vs + | c::cs, t, vs => allNoise cs t (coordinateNoise c t::vs) + +lemma hierarchy_local_sum (f : DirectionalField E) (c : MovingCoordinate E) + (cs : List (MovingCoordinate E)) (t a : ℝ) (vs : Noise E) : + (hierarchy f (c::cs)).dotBCF t + noiseResponse ((hierarchy f (c::cs)).field t) a vs = + tiltMap ((hierarchy f cs).field t) c.gamma (c.scale t • c.direction) + ((hierarchy f cs).dotBCF t + + noiseResponse ((hierarchy f cs).field t) c.gamma (coordinateNoise c t::vs)) - + ((c.gamma:ℝ)-a) • noiseGradient ((hierarchy f (c::cs)).field t) vs := by + change ((hierarchy f cs).transform c.gamma c.direction c.scale c.velocity + c.continuousScale c.continuousVelocity c.hasScale).dotBCF t + + noiseResponse (((hierarchy f cs).field t).transform c.gamma (c.scale t • c.direction)) a vs = + tiltMap ((hierarchy f cs).field t) c.gamma (c.scale t • c.direction) + ((hierarchy f cs).dotBCF t + + noiseResponse ((hierarchy f cs).field t) c.gamma (coordinateNoise c t::vs)) - + ((c.gamma:ℝ)-a) • noiseGradient + (((hierarchy f cs).field t).transform c.gamma (c.scale t • c.direction)) vs + rw [FieldFamily.dotBCF_transform, noiseResponse_transform] + simp only [coordinateNoise, noiseResponse_cons, map_add, map_smul] + module + + + +def hierarchyRemainder (f : DirectionalField E) (β : ℝ) : List (MovingCoordinate E) → ℝ → ℝ → + Noise E → BoundedContinuousFunction E ℝ + | [], _, a, vs => (β-a) • noiseGradient f vs + | c::cs, t, a, vs => ((c.gamma:ℝ)-a) • noiseGradient ((hierarchy f (c::cs)).field t) vs + + tiltMap ((hierarchy f cs).field t) c.gamma (c.scale t • c.direction) + (hierarchyRemainder f β cs t c.gamma (coordinateNoise c t::vs)) + +section FiniteSpin +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +def diagonalNoise : Noise (ι → ℝ) → (ι → ℝ) + | [] => 0 + | (k,v)::vs => k • v^2+diagonalNoise vs + +lemma trace_firstBCF (β : ℝ≥0) (hβ : 0 < β) (v : ι → ℝ) : + (traceField β hβ).firstBCF v = gibbsMap β v := rfl + +lemma trace_secondBCF (β : ℝ≥0) (hβ : 0 < β) (v : ι → ℝ) : + (traceField β hβ).secondBCF v v = (β:ℝ) • (gibbsMap β (v^2)-(gibbsMap β v)^2) := by + ext x + change (β:ℝ)*(gibbsMean β x (fun i => v i*v i)-gibbsMean β x v*gibbsMean β x v) = + (β:ℝ)*(gibbsMean β x (v^2)-(gibbsMean β x v)^2) + have he : (fun i => v i*v i) = v^2 := by ext i; simp [pow_two] + rw [he] + simp only [pow_two] + +lemma trace_noiseResponse (β : ℝ≥0) (hβ : 0 < β) (a : ℝ) (vs : Noise (ι → ℝ)) : + noiseResponse (traceField β hβ) a vs = (β:ℝ) • gibbsMap β (diagonalNoise vs) - + ((β:ℝ)-a) • noiseGradient (traceField β hβ) vs := by + induction vs with + | nil => simp [noiseResponse_nil, diagonalNoise, noiseGradient] + | cons kv vs ih => + rcases kv with ⟨k,v⟩ + rw [noiseResponse_cons, ih] + simp only [diagonalNoise, noiseGradient, map_add, map_smul] + rw [trace_secondBCF, trace_firstBCF] + module + + + +lemma hierarchy_sum_rule (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) + (t a : ℝ) (vs : Noise (ι → ℝ)) : + (hierarchy (traceField β hβ) cs).dotBCF t + + noiseResponse ((hierarchy (traceField β hβ) cs).field t) a vs = + (β:ℝ) • spinObserve β hβ cs t (diagonalNoise (allNoise cs t vs)) - + hierarchyRemainder (traceField β hβ) β cs t a vs := by + induction cs generalizing a vs with + | nil => + change 0 + noiseResponse (traceField β hβ) a vs = _ + simpa only [zero_add, spinObserve, transport, LinearMap.comp_apply, LinearMap.id_apply, + hierarchyRemainder, allNoise] using trace_noiseResponse β hβ a vs + | cons c cs ih => + rw [hierarchy_local_sum, ih] + simp only [map_sub, map_smul, hierarchyRemainder, allNoise, spinObserve, + transport, LinearMap.comp_apply] + module + +lemma hierarchy_derivative_sum_rule (β : ℝ≥0) (hβ : 0 < β) + (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) (x : ι → ℝ) : + HasDerivAt (fun s => hierarchyValue (spinTrace β) cs s x) + ((β:ℝ)*spinObserve β hβ cs t (diagonalNoise (allNoise cs t [])) x - + hierarchyRemainder (traceField β hβ) β cs t 0 [] x) t := by + have h := hierarchy_sum_rule β hβ cs t 0 [] + simp only [noiseResponse_nil, add_zero] at h + have hd := hasDerivAt_hierarchyValue (traceField β hβ) cs t x + change HasDerivAt _ ((hierarchy (traceField β hβ) cs).dotBCF t x) t at hd + rw [h] at hd + exact hd +end FiniteSpin +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +variable {ι : Type*} [Fintype ι] [Nonempty ι] [DecidableEq ι] + + +def replicaObserve (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) : + (ι → ι → ℝ) →ₗ[ℝ] BoundedContinuousFunction (ι → ℝ) ℝ where + toFun K := ∑ i, ∑ j, K i j • (spinWeight β hβ cs t i * spinWeight β hβ cs t j) + map_add' K L := by simp [add_smul, Finset.sum_add_distrib] + map_smul' a K := by simp [mul_smul, Finset.smul_sum] + +lemma replicaObserve_apply (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) + (K : ι → ι → ℝ) (x : ι → ℝ) : + replicaObserve β hβ cs t K x = ∑ i, ∑ j, K i j * (spinWeight β hβ cs t i x * spinWeight β hβ cs t j x) := by + simp [replicaObserve, BoundedContinuousFunction.sum_apply] + +lemma sum_spinWeight_apply (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) + (x : ι → ℝ) : ∑ i, spinWeight β hβ cs t i x = 1 := by + simpa using congrArg (fun w : BoundedContinuousFunction (ι → ℝ) ℝ => w x) (sum_spinWeight β hβ cs t) + +lemma replicaObserve_nonneg (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) + {K : ι → ι → ℝ} (hK : ∀ i j, 0 ≤ K i j) (x : ι → ℝ) : + 0 ≤ replicaObserve β hβ cs t K x := by + rw [replicaObserve_apply] + exact Finset.sum_nonneg (fun i _ => Finset.sum_nonneg (fun j _ => + mul_nonneg (hK i j) (mul_nonneg (spinWeight_nonneg β hβ cs t i x) (spinWeight_nonneg β hβ cs t j x)))) + +@[simp] lemma replicaObserve_const (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) + (t k : ℝ) : replicaObserve β hβ cs t (fun _ _ => k) = BoundedContinuousFunction.const (ι → ℝ) k := by + ext x + simp only [replicaObserve_apply, ← Finset.mul_sum, sum_spinWeight_apply, mul_one] + rfl + +lemma replicaObserve_rankOne (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) + (t : ℝ) (v w : ι → ℝ) : + replicaObserve β hβ cs t (fun i j => v i*w j) = spinObserve β hβ cs t v * spinObserve β hβ cs t w := by + rw [spinObserve_eq_sum, spinObserve_eq_sum] + ext x + simp only [replicaObserve_apply, BoundedContinuousFunction.mul_apply, + BoundedContinuousFunction.sum_apply, BoundedContinuousFunction.smul_apply, smul_eq_mul, + Finset.sum_mul, Finset.mul_sum] + conv_rhs => rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + + +def kernelNoise : Noise (ι → ℝ) → (ι → ι → ℝ) + | [] => 0 + | (k,v)::vs => (fun i j => k*(v i*v j)) + kernelNoise vs + +omit [Fintype ι] [Nonempty ι] [DecidableEq ι] in +lemma kernelNoise_diagonal (vs : Noise (ι → ℝ)) (i : ι) : kernelNoise vs i i = diagonalNoise vs i := by + induction vs with + | nil => rfl + | cons kv vs ih => + rcases kv with ⟨k,v⟩ + simp only [kernelNoise, diagonalNoise, Pi.add_apply, Pi.smul_apply, smul_eq_mul, ih, pow_two, Pi.mul_apply] + +lemma noiseGradient_replica (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) + (t : ℝ) (vs : Noise (ι → ℝ)) : + noiseGradient ((hierarchy (traceField β hβ) cs).field t) vs = + replicaObserve β hβ cs t (kernelNoise vs) := by + induction vs with + | nil => simp [noiseGradient, kernelNoise] + | cons kv vs ih => + rcases kv with ⟨k,v⟩ + change k • (((hierarchy (traceField β hβ) cs).field t).firstBCF v)^2 + + noiseGradient ((hierarchy (traceField β hβ) cs).field t) vs = + replicaObserve β hβ cs t (k •(fun i j => v i*v j)+kernelNoise vs) + rw [map_add, map_smul, replicaObserve_rankOne, spin_first_observe, ih, pow_two] + +lemma replicaObserve_ge_const (β : ℝ≥0) (hβ : 0 < β) (cs : List (MovingCoordinate (ι → ℝ))) + (t : ℝ) {K : ι → ι → ℝ} {k : ℝ} (hK : ∀ i j, k ≤ K i j) (x : ι → ℝ) : + k ≤ replicaObserve β hβ cs t K x := by + have h := replicaObserve_nonneg β hβ cs t (K:=K-(fun _ _ => k)) (fun i j => sub_nonneg.mpr (hK i j)) x + simpa only [map_sub, replicaObserve_const, BoundedContinuousFunction.sub_apply, + BoundedContinuousFunction.const_apply, sub_nonneg] using h +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + +def prefixTransport (f : DirectionalField E) (tail : List (MovingCoordinate E)) : + List (MovingCoordinate E) → ℝ → + (BoundedContinuousFunction E ℝ →ₗ[ℝ] BoundedContinuousFunction E ℝ) + | [], _ => LinearMap.id + | c::cs, t => (tiltMap ((hierarchy f (cs++tail)).field t) c.gamma (c.scale t • c.direction)).comp + (prefixTransport f tail cs t) + +lemma prefixTransport_const (f : DirectionalField E) (tail pre : List (MovingCoordinate E)) (t k : ℝ) : + prefixTransport f tail pre t (BoundedContinuousFunction.const E k) = BoundedContinuousFunction.const E k := by + induction pre with + | nil => rfl + | cons c cs ih => simp only [prefixTransport, LinearMap.comp_apply, ih, tiltMap_const] + +lemma prefixTransport_nonneg (f : DirectionalField E) (tail pre : List (MovingCoordinate E)) (t : ℝ) + {g : BoundedContinuousFunction E ℝ} (hg : ∀ x, 0 ≤ g x) : + ∀ x, 0 ≤ prefixTransport f tail pre t g x := by + induction pre with + | nil => exact hg + | cons c cs ih => exact tiltMap_nonneg _ _ _ ih + +lemma transport_append (f : DirectionalField E) (pre tail : List (MovingCoordinate E)) (t : ℝ) : + transport f (pre++tail) t = (prefixTransport f tail pre t).comp (transport f tail t) := by + induction pre with + | nil => rfl + | cons c cs ih => + simp only [List.cons_append, transport, prefixTransport, ih, LinearMap.comp_assoc] + +omit [NormedAddCommGroup E] [NormedSpace ℝ E] in +lemma allNoise_append (pre tail : List (MovingCoordinate E)) (t : ℝ) (vs : Noise E) : + allNoise (pre++tail) t vs = allNoise tail t (allNoise pre t vs) := by + induction pre generalizing vs with + | nil => rfl + | cons c cs ih => simpa only [List.cons_append, allNoise] using ih (coordinateNoise c t::vs) + + + +lemma remainder_constant_prefix (f : DirectionalField E) (β : ℝ) (b : ℝ≥0) + (pre tail : List (MovingCoordinate E)) (t : ℝ) (vs : Noise E) + (hb : ∀ c ∈ pre, c.gamma = b) : + hierarchyRemainder f β (pre++tail) t b vs = prefixTransport f tail pre t + (hierarchyRemainder f β tail t b (allNoise pre t vs)) := by + induction pre generalizing vs with + | nil => rfl + | cons c cs ih => + have hc := hb c (by simp) + have hcs : ∀ d ∈ cs, d.gamma = b := fun d hd => hb d (by simp [hd]) + simp only [List.cons_append, hierarchyRemainder, hc, sub_self, zero_smul, zero_add, + allNoise, prefixTransport, LinearMap.comp_apply, ih (coordinateNoise c t::vs) hcs] + +lemma remainder_nonempty_constant_prefix (f : DirectionalField E) (β a : ℝ) (b : ℝ≥0) + (c : MovingCoordinate E) (pre tail : List (MovingCoordinate E)) (t : ℝ) (vs : Noise E) + (hb : ∀ d ∈ c::pre, d.gamma = b) : + hierarchyRemainder f β ((c::pre)++tail) t a vs = + ((b:ℝ)-a) • noiseGradient ((hierarchy f ((c::pre)++tail)).field t) vs + + prefixTransport f tail (c::pre) t + (hierarchyRemainder f β tail t b (allNoise (c::pre) t vs)) := by + have hc := hb c (by simp) + have hpre : ∀ d ∈ pre, d.gamma = b := fun d hd => hb d (by simp [hd]) + simp only [List.cons_append, hierarchyRemainder, hc, prefixTransport, LinearMap.comp_apply, allNoise] + rw [remainder_constant_prefix f β b pre tail t (coordinateNoise c t::vs) hpre] +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +variable {ι : Type*} + +def coordinatesKernel (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) : ι → ι → ℝ := + (cs.map (fun c => fun i j => (c.scale t*c.velocity t)*(c.direction i*c.direction j))).sum + +lemma coordinatesKernel_nil (t : ℝ) : coordinatesKernel ([] : List (MovingCoordinate (ι → ℝ))) t = 0 := rfl + +lemma coordinatesKernel_cons (c : MovingCoordinate (ι → ℝ)) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) : + coordinatesKernel (c::cs) t = (fun i j => (c.scale t*c.velocity t)*(c.direction i*c.direction j)) + coordinatesKernel cs t := rfl + +lemma coordinatesKernel_append (pre tail : List (MovingCoordinate (ι → ℝ))) (t : ℝ) : + coordinatesKernel (pre++tail) t = coordinatesKernel pre t + coordinatesKernel tail t := by + simp [coordinatesKernel, List.sum_append] + +lemma coordinatesKernel_ofFn {k : ℕ} (c : Fin k → MovingCoordinate (ι → ℝ)) (t : ℝ) (i j : ι) : + coordinatesKernel (List.ofFn c) t i j = ∑ l, (c l).scale t*(c l).velocity t*((c l).direction i*(c l).direction j) := by + simp [coordinatesKernel, List.map_ofFn, List.sum_ofFn] + +lemma kernelNoise_allNoise [Fintype ι] [Nonempty ι] (cs : List (MovingCoordinate (ι → ℝ))) + (t : ℝ) (vs : Noise (ι → ℝ)) : + kernelNoise (allNoise cs t vs) = kernelNoise vs + coordinatesKernel cs t := by + induction cs generalizing vs with + | nil => simp [allNoise, coordinatesKernel_nil] + | cons c cs ih => + rw [allNoise, ih, coordinatesKernel_cons] + ext i j + simp only [kernelNoise, coordinateNoise, Pi.add_apply] + ring + + + +def dummyCoordinate (a : ℝ≥0) : MovingCoordinate (ι → ℝ) := MovingCoordinate.constant a 0 0 + +lemma coordinatesKernel_dummy (a : ℝ≥0) (cs : List (MovingCoordinate (ι → ℝ))) (t : ℝ) : + coordinatesKernel (dummyCoordinate a::cs) t = coordinatesKernel cs t := by + ext i j + simp [coordinatesKernel_cons, dummyCoordinate, MovingCoordinate.constant] +end ParisiFinite + +namespace ParisiGuerra +open ParisiFinite SKQAOA SKGaussian ParisiInterpolation + +def costBlock (n : ℕ) : List (MovingCoordinate (Configuration n → ℝ)) := + dummyCoordinate 0 :: List.ofFn (fun k : Fin (Fintype.card (Edge n)) => + MovingCoordinate.sine 0 (fun σ => skCoeff n σ ((Fintype.equivFin (Edge n)).symm k))) + +def siteBlock (n : ℕ) (l : ℝ≥0 × ℝ≥0) : List (MovingCoordinate (Configuration n → ℝ)) := + dummyCoordinate l.1 :: List.ofFn (fun i : Fin n => + MovingCoordinate.cosine l.1 (fun σ => Real.sqrt l.2*spin σ i)) + +def siteCoordinates (n : ℕ) (ls : Schedule) : List (MovingCoordinate (Configuration n → ℝ)) := + ls.flatMap (siteBlock n) + +def coordinates (n : ℕ) (ls : Schedule) := costBlock n ++ siteCoordinates n ls + +def pressureCurve (n : ℕ) (β : ℝ) (ls : Schedule) (t : ℝ) : ℝ := + hierarchyValue (spinTrace β) (coordinates n ls) t 0 + +lemma costBlock_gamma (n : ℕ) : ∀ c ∈ costBlock n, c.gamma = 0 := by + intro c hc + simp only [costBlock, List.mem_cons, List.mem_ofFn] at hc + rcases hc with rfl | ⟨i,rfl⟩ <;> rfl + +lemma siteBlock_gamma (n : ℕ) (l : ℝ≥0 × ℝ≥0) : ∀ c ∈ siteBlock n l, c.gamma = l.1 := by + intro c hc + simp only [siteBlock, List.mem_cons, List.mem_ofFn] at hc + rcases hc with rfl | ⟨i,rfl⟩ <;> rfl + +lemma costBlock_kernel (n : ℕ) (t : ℝ) (σ τ : Configuration n) : + coordinatesKernel (costBlock n) t σ τ = + Real.sin t*Real.cos t*(∑ e, skCoeff n σ e*skCoeff n τ e) := by + rw [costBlock, coordinatesKernel_dummy, coordinatesKernel_ofFn] + simp only [MovingCoordinate.sine] + rw [← Finset.mul_sum] + congr 1 + exact ((Fintype.equivFin (Edge n)).symm.sum_comp (fun e => skCoeff n σ e*skCoeff n τ e)) + +lemma siteBlock_kernel (n : ℕ) (l : ℝ≥0 × ℝ≥0) (t : ℝ) (σ τ : Configuration n) : + coordinatesKernel (siteBlock n l) t σ τ = + -(Real.sin t*Real.cos t)*(l.2:ℝ)*overlapSum σ τ := by + rw [siteBlock, coordinatesKernel_dummy, coordinatesKernel_ofFn] + have hs := Real.sq_sqrt l.2.coe_nonneg + have he (i : Fin n) : Real.cos t*(-Real.sin t)* + ((Real.sqrt l.2*spin σ i)*(Real.sqrt l.2*spin τ i)) = + (-(Real.sin t*Real.cos t)*(l.2:ℝ))*(spin σ i*spin τ i) := by + calc + _ = (-(Real.sin t*Real.cos t))*(Real.sqrt l.2)^2*(spin σ i*spin τ i) := by ring + _ = _ := by rw [hs] + simp only [MovingCoordinate.cosine, he, ← Finset.mul_sum, overlapSum] + + +def frontierKernel (n : ℕ) (q t : ℝ) (σ τ : Configuration n) : ℝ := + Real.sin t*Real.cos t*((n:ℝ)/2*(overlap σ τ-q)^2-(n:ℝ)/2*q^2-1/2) + +lemma costBlock_frontier {n : ℕ} (hn : 0 < n) (t : ℝ) : + coordinatesKernel (costBlock n) t = frontierKernel n 0 t := by + ext σ τ + rw [costBlock_kernel, coeff_covariance hn] + unfold frontierKernel overlap + have hn' : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp [hn'] + ring + +lemma frontier_add_site {n : ℕ} (hn : 0 < n) (q t : ℝ) (l : ℝ≥0 × ℝ≥0) : + frontierKernel n q t + coordinatesKernel (siteBlock n l) t = frontierKernel n (q+l.2) t := by + ext σ τ + simp only [Pi.add_apply, siteBlock_kernel] + unfold frontierKernel overlap + have hn' : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp [hn'] + ring +end ParisiGuerra + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/BranchNumerator.lean b/lean/OAI/Probability/ParisiFinite/BranchNumerator.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c730d2f929cd270352e09843bc99666cf1c921e --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/BranchNumerator.lean @@ -0,0 +1,749 @@ +import Mathlib +import OAI.Probability.ParisiFinite.OrderedCode + +namespace OAI + +/-! Branch Numerator. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def branchNumerator {r : ℕ} (a b : ℝ) (c : Fin r → ℕ) : ℝ := + branchFactor a b (codeLabels c).card * ∏ x∈codeLabels c,blockFactor a (labelCount c x) + +lemma branchNumerator_existing {r : ℕ} (a b : ℝ) (c : Fin (r+1) → ℕ) (i : Fin r) + (hi : restrictCode c i=c (Fin.last r)) : + branchNumerator a b c= + ((clusterCount (restrictCode c) i:ℝ)-a)*branchNumerator a b (restrictCode c) := by + let x := c (Fin.last r) + have hx : x∈codeLabels (restrictCode c) := (codeLabels_mem _ _).mpr ⟨i,hi⟩ + have hlabels : codeLabels c=codeLabels (restrictCode c) := by + rw [codeLabels_succ,Finset.insert_eq_of_mem hx] + have hcount : labelCount (restrictCode c) x=clusterCount (restrictCode c) i := by + change labelCount (restrictCode c) (c (Fin.last r))=_ + rw [← hi] + rfl + have hprod : (∏ y∈codeLabels c,blockFactor a (labelCount c y))= + (((clusterCount (restrictCode c) i:ℝ)-a))* + ∏ y∈codeLabels (restrictCode c),blockFactor a (labelCount (restrictCode c) y) := by + rw [hlabels,← Finset.mul_prod_erase _ _ hx,← Finset.mul_prod_erase _ _ hx] + have he : (∏ y∈(codeLabels (restrictCode c)).erase x,blockFactor a (labelCount c y))= + ∏ y∈(codeLabels (restrictCode c)).erase x,blockFactor a (labelCount (restrictCode c) y) := by + apply Finset.prod_congr rfl + intro y hy + rw [labelCount_succ,ite_eq_right (Ne.symm (Finset.mem_erase.mp hy).1),add_zero] + rw [he,labelCount_succ,ite_eq_left rfl,hcount,blockFactor_succ a (clusterCount_pos _ i)] + ring + unfold branchNumerator + rw [hprod,hlabels] + ring + +lemma branchNumerator_fresh {r : ℕ} (hr : 0 hx (h ▸ hy) + rw [labelCount_succ,ite_eq_right hyx,add_zero] + unfold branchNumerator + rw [codeLabels_succ,Finset.card_insert_of_notMem hx, + branchFactor_succ a b (Finset.card_pos.mpr (codeLabels_nonempty hr _)),Finset.prod_insert hx] + have hn : labelCount c x=1 := by rw [labelCount_succ,hz,ite_eq_left rfl,zero_add] + rw [hn,blockFactor_one,one_mul] + have he := Finset.prod_congr (s₁:=codeLabels (restrictCode c)) (s₂:=codeLabels (restrictCode c)) + rfl (fun y hy => congrArg (blockFactor a) (hold y hy)) + rw [he] + ring + +lemma branchNumerator_one (a b : ℝ) (c : Fin 1 → ℕ) : branchNumerator a b c=1 := by + have hc : codeLabels c={c 0} := by + ext x + simp only [codeLabels_mem,Finset.mem_singleton] + exact ⟨fun ⟨i,hi⟩ => by fin_cases i; exact hi.symm,fun h => ⟨0,h.symm⟩⟩ + have hn : labelCount c (c 0)=1 := by simp [labelCount,Finset.filter_singleton] + simp [branchNumerator,hc,hn] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def branchEvent {r : ℕ} (c : Fin r → ℕ) (q t : ℝ) : Set OverlapArray := + partitionEvent (fun _ : Fin r => 0) q∩partitionEvent c t + +def branchBlock {r : ℕ} (c : Fin r → ℕ) (q t : ℝ) : Set (OverlapBlock r) := + partitionBlock (fun _ => 0) q∩partitionBlock c t + +lemma branchBlock_measurable {r : ℕ} (c : Fin r → ℕ) (q t : ℝ) : + MeasurableSet (branchBlock c q t) := + (measurableSet_partitionBlock _ _).inter (measurableSet_partitionBlock _ _) + +lemma branch_existing_iff {r : ℕ} (c : Fin (r+1) → ℕ) {q t : ℝ} + (hqt : q≤t) (ht : t<1) (i : Fin r) (hi : restrictCode c i=c (Fin.last r)) + {R : OverlapArray} (hG : R∈GramArrays) (hu : R∈UltrametricArrays) : + R∈branchEvent c q t ↔ R∈branchEvent (restrictCode c) q t ∧ t<(R i r:ℝ) := by + unfold branchEvent + rw [Set.mem_inter_iff,partition_existing_iff c ht i hi hG hu, + partition_existing_iff (fun _ => 0) (hqt.trans_lt ht) i rfl hG hu] + change (_ ∧ q<(R i r:ℝ)) ∧ _ ∧ t<(R i r:ℝ) ↔ (_ ∧ _) ∧ t<(R i r:ℝ) + constructor + · exact fun h => ⟨⟨h.1.1,h.2.1⟩,h.2.2⟩ + · exact fun h => ⟨⟨h.1.1,hqt.trans_lt h.2⟩,h.1.2,h.2⟩ + +lemma reps_row_le {r : ℕ} {c : Fin r → ℕ} {T : Finset (Fin r)} (hT : ClusterReps c T) + {t : ℝ} {R : OverlapArray} (hG : R∈GramArrays) (hu : R∈UltrametricArrays) + (hc : R∈partitionEvent c t) : (∀ i : Fin r,(R i r:ℝ)≤t) ↔ ∀ k∈T,(R k r:ℝ)≤t := by + refine ⟨fun h k _ => h k,fun h i => ?_⟩ + by_contra hn + have hi : t<(R i r:ℝ) := lt_of_not_ge hn + obtain ⟨k,hk,hki⟩ := hT.2 i + have hki' : t<(R k i:ℝ) := (hc k i).mpr hki + have hh := hu k r i + rw [hG.1 r i] at hh + exact (not_lt_of_ge (h k hk)) ((lt_min hki' hi).trans_le hh) + +lemma branch_fresh_iff {r : ℕ} (c : Fin (r+1) → ℕ) {q t : ℝ} + (hqt : q≤t) (ht : t<1) (i : Fin r) (hi : ∀ j,restrictCode c j≠c (Fin.last r)) + {T : Finset (Fin r)} (hT : ClusterReps (restrictCode c) T) + {R : OverlapArray} (hG : R∈GramArrays) (hu : R∈UltrametricArrays) : + R∈branchEvent c q t ↔ R∈branchEvent (restrictCode c) q t ∧ q<(R i r:ℝ) ∧ + ∀ k∈T,(R k r:ℝ)≤t := by + unfold branchEvent + rw [Set.mem_inter_iff,partition_fresh_iff c ht hi hG, + partition_existing_iff (fun _ => 0) (hqt.trans_lt ht) i rfl hG hu] + constructor + · rintro ⟨⟨hP,hq⟩,hC,hrow⟩ + exact ⟨⟨hP,hC⟩,hq,(reps_row_le hT hG hu hC).mp hrow⟩ + · rintro ⟨⟨hP,hC⟩,hq,hrow⟩ + exact ⟨⟨hP,hq⟩,hC,(reps_row_le hT hG hu hC).mpr hrow⟩ + +lemma GG_branch_existing {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {r : ℕ} (c : Fin (r+1) → ℕ) {q t : ℝ} (hqt : q≤t) (ht : t<1) (i : Fin r) + (hi : restrictCode c i=c (Fin.last r)) : + (r:ℝ)*(μ:Measure OverlapArray).real (branchEvent c q t)= + ((clusterCount (restrictCode c) i:ℝ)-overlapDiscount μ t)* + (μ:Measure OverlapArray).real (branchEvent (restrictCode c) q t) := by + have he : branchEvent c q t =ᵐ[(μ:Measure OverlapArray)] + {R | R∈branchEvent (restrictCode c) q t ∧ t<(R i r:ℝ)} := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG, + ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu] with R hg hu + exact propext (branch_existing_iff c hqt ht i hi hg hu) + rw [measureReal_congr he] + exact GG_join_on_block hgg (branchBlock_measurable _ q t) (restrictCode c) t (fun _ h => h.2) i + +lemma GG_branch_fresh {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {r : ℕ} (c : Fin (r+1) → ℕ) {q t : ℝ} (hqt : q≤t) (ht : t<1) (i : Fin r) + (hi : ∀ j,restrictCode c j≠c (Fin.last r)) + {T : Finset (Fin r)} (hT : ClusterReps (restrictCode c) T) : + (r:ℝ)*(μ:Measure OverlapArray).real (branchEvent c q t)= + ((T.card:ℝ)*overlapDiscount μ t-overlapDiscount μ q)* + (μ:Measure OverlapArray).real (branchEvent (restrictCode c) q t) := by + have he : branchEvent c q t =ᵐ[(μ:Measure OverlapArray)] + {R | R∈branchEvent (restrictCode c) q t ∧ q<(R i r:ℝ) ∧ ∀ k∈T,(R k r:ℝ)≤t} := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG, + ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu] with R hg hu + exact propext (branch_fresh_iff c hqt ht i hi hT hg hu) + rw [measureReal_congr he] + have hp : ParentReps (fun _ : Fin r => 0) (restrictCode c) i T := by + refine ⟨hT.1,fun _ _ => rfl,fun j => ?_⟩ + simp only [iff_true_left] + exact hT.2 j + exact GG_nested_innovation hG hgg hu (branchBlock_measurable _ q t) hqt + (fun _ h => h.1) (fun _ h => h.2) i hp + +lemma branch_one_real {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) + (c : Fin 1 → ℕ) {q t : ℝ} (hqt : q≤t) (ht : t<1) : + (μ:Measure OverlapArray).real (branchEvent c q t)=1 := by + have he : branchEvent c q t =ᵐ[(μ:Measure OverlapArray)] partitionEvent c t := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG] with R hg + apply propext + refine ⟨fun h => h.2,fun h => ⟨?_,h⟩⟩ + intro i j + fin_cases i; fin_cases j + change q<(R 0 0:ℝ) ↔ _ + rw [hg.2.1] + simp [hqt.trans_lt ht] + rw [measureReal_congr he,partition_one_real hG c ht] + + + +theorem GG_branch_EPPF {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q t : ℝ} (hqt : q≤t) (ht : t<1) {r : ℕ} (hr : 0 omega + | succ r ih => + by_cases hr0 : r=0 + · subst r + rw [branch_one_real hG c hqt ht,branchNumerator_one] + norm_num + have hr' : 0 (finiteMarkTransform (overlapDiscount μ t) w x z)^ + (overlapDiscount μ q/overlapDiscount μ t)) 0= + -overlapDiscount μ q*((n-1).factorial:ℝ)*branchMarkedMoment μ q t (finiteMarkMoment w x) n := by + rw [power_mark_derivative ha _ w x hw hn] + unfold branchMarkedMoment + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro c _ + have he := GG_branch_EPPF hG hgg hu hqt ht hn (orderedCode c) + rw [branchNumerator_ordered] at he + rw [Finset.prod_mul_distrib] + linear_combination (overlapDiscount μ q)*(∏ j,finiteMarkMoment w x (c.partSize j))*he + +lemma branchMarkedMoment_nonneg (μ : ProbabilityMeasure OverlapArray) (q t : ℝ) + {moments : ℕ → ℝ} (hm : ∀ n,0 ≤ moments n) (n : ℕ) : + 0≤branchMarkedMoment μ q t moments n := by + apply Finset.sum_nonneg + intro c _ + exact mul_nonneg measureReal_nonneg (Finset.prod_nonneg fun _ _ => hm _) + +lemma branchMarkedMoment_le_ordered (μ : ProbabilityMeasure OverlapArray) (q t : ℝ) + {moments : ℕ → ℝ} (hm : ∀ n,0 ≤ moments n) (n : ℕ) : + branchMarkedMoment μ q t moments n≤orderedMarkedMoment μ t moments n := by + apply Finset.sum_le_sum + intro c _ + exact mul_le_mul_of_nonneg_right (measureReal_mono Set.inter_subset_right) + (Finset.prod_nonneg fun _ _ => hm _) + +lemma overlapDiscount_mem_unit (μ : ProbabilityMeasure OverlapArray) (q : ℝ) : + 0≤overlapDiscount μ q ∧ overlapDiscount μ q≤1 := by + let := entryLaw_probability μ 0 1 + exact ⟨measureReal_nonneg,measureReal_le_one⟩ + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma ordered_range_iff_index {r : ℕ} (c : OrderedFinpartition r) (i : Fin c.length) (j : Fin r) : + j∈Set.range (c.emb i) ↔ c.index j=i := by + constructor + · rintro ⟨k,rfl⟩ + exact orderedIndex_emb c i k + · intro h + refine ⟨?_,?_⟩ + · exact h ▸ c.invEmbedding j + · subst i + exact c.emb_invEmbedding j + +def blockMax {r : ℕ} (c : OrderedFinpartition r) (i : Fin c.length) : Fin r := + c.emb i ⟨c.partSize i-1,Nat.sub_one_lt_of_lt (c.partSize_pos i)⟩ + +lemma blockMax_index {r : ℕ} (c : OrderedFinpartition r) (i : Fin c.length) : + c.index (blockMax c i)=i := orderedIndex_emb _ _ _ + +lemma le_blockMax {r : ℕ} (c : OrderedFinpartition r) {i : Fin c.length} {j : Fin r} + (h : c.index j=i) : j≤blockMax c i := by + obtain ⟨k,rfl⟩ := (ordered_range_iff_index c i j).mpr h + apply (c.emb_strictMono i).monotone + change (k:ℕ)≤c.partSize i-1 + omega + +lemma ordered_rel_range {r : ℕ} (c d : OrderedFinpartition r) + (h : ∀ i j,c.index i=c.index j ↔ d.index i=d.index j) (i : Fin c.length) : + Set.range (c.emb i)=Set.range (d.emb (d.index (blockMax c i))) := by + ext j + rw [ordered_range_iff_index,ordered_range_iff_index,← h j (blockMax c i),blockMax_index] + +lemma ordered_rel_max {r : ℕ} (c d : OrderedFinpartition r) + (h : ∀ i j,c.index i=c.index j ↔ d.index i=d.index j) (i : Fin c.length) : + blockMax c i=blockMax d (d.index (blockMax c i)) := by + apply le_antisymm + · exact le_blockMax d rfl + · apply le_blockMax c + have hd := blockMax_index d (d.index (blockMax c i)) + have hc := (h (blockMax d (d.index (blockMax c i))) (blockMax c i)).mpr hd + rwa [blockMax_index] at hc + +lemma ordered_rel_map_mono {r : ℕ} (c d : OrderedFinpartition r) + (h : ∀ i j,c.index i=c.index j ↔ d.index i=d.index j) : + StrictMono (fun i => d.index (blockMax c i)) := by + intro i j hij + have hh : blockMax c i (h i j).symm) + have hlen : c.length=d.length := by + apply le_antisymm + · simpa using Fintype.card_le_of_injective _ hm.injective + · simpa using Fintype.card_le_of_injective _ hm'.injective + have hf : ∀ i, d.index (blockMax c i)=Fin.cast hlen i := by + have hg : StrictMono (fun i => Fin.cast hlen.symm (d.index (blockMax c i))) := + (Fin.castOrderIso hlen.symm).strictMono.comp hm + intro i + have hh := congrFun hg.eq_id i + apply Fin.ext + have hv := congrArg (fun j : Fin c.length => (j:ℕ)) hh + exact hv + have hcode : ∀ j,(c.index j:ℕ)=(d.index j:ℕ) := by + intro j + have hj : d.index j=d.index (blockMax c (c.index j)) := + (h j (blockMax c (c.index j))).mp (by rw [blockMax_index]) + rw [hj,hf] + rfl + rcases c with ⟨cl,cs,cp,ce,cm,ct,cd,cc⟩ + rcases d with ⟨dl,ds,dp,de,dm,dt,dd,dc⟩ + dsimp only at hlen + subst dl + have hs : cs=ds := by + funext i + have hc := labelCount_orderedCode (OrderedFinpartition.mk cl cs cp ce cm ct cd cc) i + have hd := labelCount_orderedCode (OrderedFinpartition.mk cl ds dp de dm dt dd dc) i + have hh : orderedCode (OrderedFinpartition.mk cl cs cp ce cm ct cd cc)= + orderedCode (OrderedFinpartition.mk cl ds dp de dm dt dd dc) := funext hcode + rw [hh] at hc + exact hc.symm.trans hd + subst ds + have he : ce=de := by + funext i + apply (cm i).range_inj_of_wellFoundedLT (dm i) |>.mp + have hr := ordered_rel_range (OrderedFinpartition.mk cl cs cp ce cm ct cd cc) + (OrderedFinpartition.mk cl cs dp de dm dt dd dc) h i + rw [hf] at hr + exact hr + subst de + rfl + +lemma ordered_partition_disjoint {r : ℕ} {c d : OrderedFinpartition r} (hcd : c≠d) (q : ℝ) : + Disjoint (partitionEvent (orderedCode c) q) (partitionEvent (orderedCode d) q) := by + apply Set.disjoint_left.mpr + intro R hc hd + apply hcd + apply ordered_eq_of_same_relation + intro i j + have hh := (hc i j).symm.trans (hd i j) + simpa only [orderedCode,Fin.val_inj] using hh + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def Refines {r : ℕ} (p c : Fin r → ℕ) : Prop := ∀ i j,c i=c j → p i=p j + +def NestedCodes {d r : ℕ} (c : Fin (d+1) → Fin r → ℕ) : Prop := + ∀ k l,k≤l → Refines (c k) (c l) + +def hierarchyEvent {d r : ℕ} (c : Fin (d+1) → Fin r → ℕ) (q : Fin (d+1) → ℝ) : Set OverlapArray := + {R | ∀ k,R∈partitionEvent (c k) (q k)} + +def hierarchyBlock {d r : ℕ} (c : Fin (d+1) → Fin r → ℕ) (q : Fin (d+1) → ℝ) : Set (OverlapBlock r) := + {R | ∀ k,R∈partitionBlock (c k) (q k)} + +lemma hierarchyBlock_measurable {d r : ℕ} (c : Fin (d+1) → Fin r → ℕ) (q : Fin (d+1) → ℝ) : + MeasurableSet (hierarchyBlock c q) := by + unfold hierarchyBlock + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun k => measurableSet_partitionBlock _ _ + +lemma nestedCodes_restrict {d r : ℕ} {c : Fin (d+1) → Fin (r+1) → ℕ} (hc : NestedCodes c) : + NestedCodes (fun k => restrictCode (c k)) := + fun k l hkl i j hij => hc k l hkl i.castSucc j.castSucc hij + +lemma hierarchy_restrict {d r : ℕ} {c : Fin (d+1) → Fin (r+1) → ℕ} {q : Fin (d+1) → ℝ} + {R : OverlapArray} (h : R∈hierarchyEvent c q) : + R∈hierarchyEvent (fun k => restrictCode (c k)) q := fun k => partition_restrict (h k) + +lemma hierarchy_existing_iff {d r : ℕ} (c : Fin (d+1) → Fin (r+1) → ℕ) + (hc : NestedCodes c) (q : Fin (d+1) → ℝ) (hq : Monotone q) (h1 : q (Fin.last d)<1) + (i : Fin r) (hi : restrictCode (c (Fin.last d)) i=c (Fin.last d) (Fin.last r)) + {R : OverlapArray} (hG : R∈GramArrays) (hu : R∈UltrametricArrays) : + R∈hierarchyEvent c q ↔ R∈hierarchyEvent (fun k => restrictCode (c k)) q ∧ + q (Fin.last d)<(R i r:ℝ) := by + constructor + · exact fun h => ⟨hierarchy_restrict h,((h (Fin.last d)) i.castSucc (Fin.last r)).mpr hi⟩ + · rintro ⟨h,hrow⟩ k + have hki : restrictCode (c k) i=c k (Fin.last r) := + hc k (Fin.last d) (Fin.le_last k) _ _ hi + exact (partition_existing_iff (c k) ((hq (Fin.le_last k)).trans_lt h1) i hki hG hu).mpr + ⟨h k,(hq (Fin.le_last k)).trans_lt hrow⟩ + +lemma parentRep_no_join {r : ℕ} {p c : Fin r → ℕ} {q t : ℝ} (hqt : q≤t) + {i : Fin r} {T : Finset (Fin r)} (hT : ParentReps p c i T) + {R : OverlapArray} (hG : R∈GramArrays) (hu : R∈UltrametricArrays) + (hp : R∈partitionEvent p q) (hc : R∈partitionEvent c t) + (hi : q<(R i r:ℝ)) (hrow : ∀ k∈T,(R k r:ℝ)≤t) : + ∀ j : Fin r,(R j r:ℝ)≤t := by + intro j + by_contra hn + have hj : t<(R j r:ℝ) := lt_of_not_ge hn + have hji : p j=p i := (hp j i).mp + ((lt_min (hqt.trans_lt hj) hi).trans_le (hu j i r)) + obtain ⟨k,hk,hkj⟩ := (hT.2.2 j).mp hji + have hkj' : t<(R k j:ℝ) := (hc k j).mpr hkj + have hh := hu k r j + rw [hG.1 r j] at hh + exact (not_lt_of_ge (hrow k hk)) ((lt_min hkj' hj).trans_le hh) + + + +lemma hierarchy_fresh_iff {d r : ℕ} (c : Fin (d+1) → Fin (r+1) → ℕ) + (hc : NestedCodes c) (q : Fin (d+1) → ℝ) (hq : Monotone q) (h1 : q (Fin.last d)<1) + (k : Fin d) (i : Fin r) (hi : restrictCode (c k.castSucc) i=c k.castSucc (Fin.last r)) + (hn : ∀ j,restrictCode (c k.succ) j≠c k.succ (Fin.last r)) + {T : Finset (Fin r)} (hT : ParentReps (restrictCode (c k.castSucc)) (restrictCode (c k.succ)) i T) + {R : OverlapArray} (hG : R∈GramArrays) (hu : R∈UltrametricArrays) : + R∈hierarchyEvent c q ↔ R∈hierarchyEvent (fun l => restrictCode (c l)) q ∧ + q k.castSucc<(R i r:ℝ) ∧ ∀ j∈T,(R j r:ℝ)≤q k.succ := by + constructor + · intro h + refine ⟨hierarchy_restrict h,((h k.castSucc) i.castSucc (Fin.last r)).mpr hi,fun j _ => ?_⟩ + exact le_of_not_gt fun hj => hn j (((h k.succ) j.castSucc (Fin.last r)).mp hj) + · rintro ⟨h,hrow,hnew⟩ l + have hll : q l<1 := (hq (Fin.le_last l)).trans_lt h1 + by_cases hl : l≤k.castSucc + · have hli : restrictCode (c l) i=c l (Fin.last r) := hc l k.castSucc hl _ _ hi + exact (partition_existing_iff (c l) hll i hli hG hu).mpr ⟨h l,(hq hl).trans_lt hrow⟩ + · have hkl : k.succ≤l := by change (k:ℕ)+1≤(l:ℕ); have := not_le.mp hl; change (k:ℕ)<(l:ℕ) at this; omega + have hnf : ∀ j,restrictCode (c l) j≠c l (Fin.last r) := fun j hj => + hn j (hc k.succ l hkl _ _ hj) + apply (partition_fresh_iff (c l) hll hnf hG).mpr + refine ⟨h l,fun j => ?_⟩ + have hqs : q k.castSucc≤q k.succ := hq (by change (k:ℕ)≤(k:ℕ)+1; omega) + exact (parentRep_no_join hqs hT hG hu (h k.castSucc) (h k.succ) hrow hnew j).trans (hq hkl) + +lemma GG_hierarchy_existing {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d r : ℕ} (c : Fin (d+1) → Fin (r+1) → ℕ) (hc : NestedCodes c) + (q : Fin (d+1) → ℝ) (hq : Monotone q) (h1 : q (Fin.last d)<1) (i : Fin r) + (hi : restrictCode (c (Fin.last d)) i=c (Fin.last d) (Fin.last r)) : + (r:ℝ)*(μ:Measure OverlapArray).real (hierarchyEvent c q)= + ((clusterCount (restrictCode (c (Fin.last d))) i:ℝ)-overlapDiscount μ (q (Fin.last d)))* + (μ:Measure OverlapArray).real (hierarchyEvent (fun k => restrictCode (c k)) q) := by + have he : hierarchyEvent c q =ᵐ[(μ:Measure OverlapArray)] + {R | R∈hierarchyEvent (fun k => restrictCode (c k)) q ∧ q (Fin.last d)<(R i r:ℝ)} := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG, + ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu] with R hg hu + exact propext (hierarchy_existing_iff c hc q hq h1 i hi hg hu) + rw [measureReal_congr he] + exact GG_join_on_block hgg (hierarchyBlock_measurable _ q) _ _ (fun _ h => h (Fin.last d)) i + +lemma GG_hierarchy_fresh {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d r : ℕ} (c : Fin (d+1) → Fin (r+1) → ℕ) (hc : NestedCodes c) + (q : Fin (d+1) → ℝ) (hq : Monotone q) (h1 : q (Fin.last d)<1) + (k : Fin d) (i : Fin r) (hi : restrictCode (c k.castSucc) i=c k.castSucc (Fin.last r)) + (hn : ∀ j,restrictCode (c k.succ) j≠c k.succ (Fin.last r)) + {T : Finset (Fin r)} (hT : ParentReps (restrictCode (c k.castSucc)) (restrictCode (c k.succ)) i T) : + (r:ℝ)*(μ:Measure OverlapArray).real (hierarchyEvent c q)= + ((T.card:ℝ)*overlapDiscount μ (q k.succ)-overlapDiscount μ (q k.castSucc))* + (μ:Measure OverlapArray).real (hierarchyEvent (fun l => restrictCode (c l)) q) := by + have he : hierarchyEvent c q =ᵐ[(μ:Measure OverlapArray)] + {R | R∈hierarchyEvent (fun l => restrictCode (c l)) q ∧ q k.castSucc<(R i r:ℝ) ∧ + ∀ j∈T,(R j r:ℝ)≤q k.succ} := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG, + ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu] with R hg hu + exact propext (hierarchy_fresh_iff c hc q hq h1 k i hi hn hT hg hu) + rw [measureReal_congr he] + exact GG_nested_innovation hG hgg hu (hierarchyBlock_measurable _ q) + (hq (by change (k:ℕ)≤(k:ℕ)+1; omega)) + (fun _ h => h k.castSucc) (fun _ h => h k.succ) i hT + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def childLabels {r : ℕ} (p c : Fin r → ℕ) (x : ℕ) : Finset ℕ := + (Finset.univ.filter (fun i => p i=x)).image c + +lemma mem_childLabels {r : ℕ} (p c : Fin r → ℕ) (x y : ℕ) : + y∈childLabels p c x ↔ ∃ i,p i=x ∧ c i=y := by + simp only [childLabels,Finset.mem_image,Finset.mem_filter,Finset.mem_univ,true_and] + +lemma childLabels_nonempty {r : ℕ} (p c : Fin r → ℕ) {x : ℕ} (hx : x∈codeLabels p) : + (childLabels p c x).Nonempty := by + obtain ⟨i,hi⟩ := (codeLabels_mem _ _).mp hx + exact ⟨c i,(mem_childLabels _ _ _ _).mpr ⟨i,hi,rfl⟩⟩ + +lemma childLabels_empty {r : ℕ} (p c : Fin r → ℕ) {x : ℕ} (hx : x∉codeLabels p) : + childLabels p c x=∅ := by + apply Finset.eq_empty_iff_forall_notMem.mpr + intro y hy + obtain ⟨i,hi,_⟩ := (mem_childLabels _ _ _ _).mp hy + exact hx ((codeLabels_mem _ _).mpr ⟨i,hi⟩) + +lemma childLabels_succ {r : ℕ} (p c : Fin (r+1) → ℕ) (x : ℕ) : + childLabels p c x=if p (Fin.last r)=x then + insert (c (Fin.last r)) (childLabels (restrictCode p) (restrictCode c) x) + else childLabels (restrictCode p) (restrictCode c) x := by + ext y + simp only [mem_childLabels] + split_ifs with hp + · simp only [Finset.mem_insert,mem_childLabels] + constructor + · rintro ⟨i,hi,hc⟩ + exact Fin.lastCases (fun _ hc => Or.inl hc.symm) + (fun j hj hc => Or.inr ⟨j,hj,hc⟩) i hi hc + · rintro (hy | ⟨i,hi,hc⟩) + · exact ⟨Fin.last r,hp,hy.symm⟩ + · exact ⟨i.castSucc,hi,hc⟩ + · rw [mem_childLabels] + constructor + · rintro ⟨i,hi,hc⟩ + exact Fin.lastCases (fun hi _ => (hp hi).elim) (fun j hj hc => ⟨j,hj,hc⟩) i hi hc + · rintro ⟨i,hi,hc⟩ + exact ⟨i.castSucc,hi,hc⟩ + +lemma exists_parentReps {r : ℕ} {p c : Fin r → ℕ} (hpc : Refines p c) (i : Fin r) : + ∃ T, ParentReps p c i T := by + obtain ⟨S,hS⟩ := exists_clusterReps c + let T := S.filter (fun j => p j=p i) + refine ⟨T,hS.1.mono (by intro j hj; exact (Finset.mem_filter.mp hj).1),?_,?_⟩ + · exact fun j hj => (Finset.mem_filter.mp hj).2 + · intro j + constructor + · intro hj + obtain ⟨k,hk,hkj⟩ := hS.2 j + exact ⟨k,Finset.mem_filter.mpr ⟨hk,(hpc k j hkj).trans hj⟩,hkj⟩ + · rintro ⟨k,hk,hkj⟩ + exact (hpc k j hkj).symm.trans (Finset.mem_filter.mp hk).2 + +lemma ParentReps.card_childLabels {r : ℕ} {p c : Fin r → ℕ} {i : Fin r} {T : Finset (Fin r)} + (hT : ParentReps p c i T) : T.card=(childLabels p c (p i)).card := by + have he : T.image c=childLabels p c (p i) := by + ext y + simp only [Finset.mem_image,mem_childLabels] + constructor + · rintro ⟨j,hj,rfl⟩ + exact ⟨j,hT.2.1 j hj,rfl⟩ + · rintro ⟨j,hj,rfl⟩ + exact (hT.2.2 j).mp hj + rw [← he,Finset.card_image_of_injOn hT.1] + +def edgeFactor {r : ℕ} (a b : ℝ) (p c : Fin r → ℕ) : ℝ := + ∏ x∈codeLabels p,branchFactor a b (childLabels p c x).card + +def leafFactor {r : ℕ} (a : ℝ) (c : Fin r → ℕ) : ℝ := + ∏ x∈codeLabels c,blockFactor a (labelCount c x) + +lemma edgeFactor_existing {r : ℕ} (a b : ℝ) (p c : Fin (r+1) → ℕ) + (hpc : Refines p c) (i : Fin r) (hi : restrictCode c i=c (Fin.last r)) : + edgeFactor a b p c=edgeFactor a b (restrictCode p) (restrictCode c) := by + have hp : restrictCode p i=p (Fin.last r) := hpc _ _ hi + have hlabels : codeLabels p=codeLabels (restrictCode p) := by + rw [codeLabels_succ,Finset.insert_eq_of_mem ((codeLabels_mem _ _).mpr ⟨i,hp⟩)] + unfold edgeFactor + apply Finset.prod_congr hlabels + intro x _ + congr 2 + rw [childLabels_succ] + split_ifs with hx + · exact Finset.insert_eq_of_mem ((mem_childLabels _ _ _ _).mpr ⟨i,hp.trans hx,hi⟩) + · rfl + +lemma edgeFactor_fresh_parent {r : ℕ} (a b : ℝ) (p c : Fin (r+1) → ℕ) + (hp : ∀ i,restrictCode p i≠p (Fin.last r)) : + edgeFactor a b p c=edgeFactor a b (restrictCode p) (restrictCode c) := by + have hx : p (Fin.last r)∉codeLabels (restrictCode p) := by + simpa only [codeLabels_mem,not_exists] using hp + have hn : childLabels p c (p (Fin.last r))={c (Fin.last r)} := by + rw [childLabels_succ,ite_eq_left rfl,childLabels_empty _ _ hx,Finset.insert_empty] + unfold edgeFactor + rw [codeLabels_succ,Finset.prod_insert hx,hn,Finset.card_singleton,branchFactor_one,one_mul] + apply Finset.prod_congr rfl + intro x hxx + have hne : p (Fin.last r)≠x := fun hh => hx (hh ▸ hxx) + rw [childLabels_succ,ite_eq_right hne] + +lemma edgeFactor_fresh_child {r : ℕ} (a b : ℝ) (p c : Fin (r+1) → ℕ) + (i : Fin r) (hp : restrictCode p i=p (Fin.last r)) + (hc : ∀ j,restrictCode c j≠c (Fin.last r)) : + edgeFactor a b p c= + (a*((childLabels (restrictCode p) (restrictCode c) (restrictCode p i)).card:ℝ)-b)* + edgeFactor a b (restrictCode p) (restrictCode c) := by + let x := p (Fin.last r) + have hx : x∈codeLabels (restrictCode p) := (codeLabels_mem _ _).mpr ⟨i,hp⟩ + have hn : c (Fin.last r)∉childLabels (restrictCode p) (restrictCode c) x := by + rintro hy + obtain ⟨j,_,hj⟩ := (mem_childLabels _ _ _ _).mp hy + exact hc j hj + have hlabels : codeLabels p=codeLabels (restrictCode p) := by + rw [codeLabels_succ,Finset.insert_eq_of_mem hx] + unfold edgeFactor + rw [hlabels,← Finset.mul_prod_erase _ _ hx,← Finset.mul_prod_erase _ _ hx] + have he : (∏ y∈(codeLabels (restrictCode p)).erase x,branchFactor a b (childLabels p c y).card)= + ∏ y∈(codeLabels (restrictCode p)).erase x,branchFactor a b + (childLabels (restrictCode p) (restrictCode c) y).card := by + apply Finset.prod_congr rfl + intro y hy + rw [childLabels_succ,ite_eq_right (Ne.symm (Finset.mem_erase.mp hy).1)] + rw [he,childLabels_succ,ite_eq_left rfl,Finset.card_insert_of_notMem hn, + branchFactor_succ a b (Finset.card_pos.mpr (childLabels_nonempty _ _ hx)),hp] + ring + +lemma leafFactor_existing {r : ℕ} (a : ℝ) (c : Fin (r+1) → ℕ) (i : Fin r) + (hi : restrictCode c i=c (Fin.last r)) : + leafFactor a c=((clusterCount (restrictCode c) i:ℝ)-a)*leafFactor a (restrictCode c) := by + let x := c (Fin.last r) + have hx : x∈codeLabels (restrictCode c) := (codeLabels_mem _ _).mpr ⟨i,hi⟩ + have hlabels : codeLabels c=codeLabels (restrictCode c) := by + rw [codeLabels_succ,Finset.insert_eq_of_mem hx] + have hcount : labelCount (restrictCode c) x=clusterCount (restrictCode c) i := by + change labelCount (restrictCode c) (c (Fin.last r))=_ + rw [← hi] + rfl + unfold leafFactor + rw [hlabels,← Finset.mul_prod_erase _ _ hx,← Finset.mul_prod_erase _ _ hx] + have he : (∏ y∈(codeLabels (restrictCode c)).erase x,blockFactor a (labelCount c y))= + ∏ y∈(codeLabels (restrictCode c)).erase x,blockFactor a (labelCount (restrictCode c) y) := by + apply Finset.prod_congr rfl + intro y hy + rw [labelCount_succ,ite_eq_right (Ne.symm (Finset.mem_erase.mp hy).1),add_zero] + rw [he,labelCount_succ,ite_eq_left rfl,hcount,blockFactor_succ a (clusterCount_pos _ i)] + ring + +lemma leafFactor_fresh {r : ℕ} (a : ℝ) (c : Fin (r+1) → ℕ) + (hc : ∀ i,restrictCode c i≠c (Fin.last r)) : leafFactor a c=leafFactor a (restrictCode c) := by + have hx : c (Fin.last r)∉codeLabels (restrictCode c) := by simpa only [codeLabels_mem,not_exists] using hc + have hz : labelCount (restrictCode c) (c (Fin.last r))=0 := by + simpa only [← labelCount_pos_iff,not_lt,Nat.le_zero] using hx + have hn : labelCount c (c (Fin.last r))=1 := by rw [labelCount_succ,hz,ite_eq_left rfl,zero_add] + unfold leafFactor + rw [codeLabels_succ,Finset.prod_insert hx,hn,blockFactor_one,one_mul] + apply Finset.prod_congr rfl + intro y hy + have hne : c (Fin.last r)≠y := fun hh => hx (hh ▸ hy) + rw [labelCount_succ,ite_eq_right hne,add_zero] + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/CanonicalSpatialTest.lean b/lean/OAI/Probability/ParisiFinite/CanonicalSpatialTest.lean new file mode 100644 index 0000000000000000000000000000000000000000..1ce40740dda9ef8809b1e55e2158463b01a60dd3 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/CanonicalSpatialTest.lean @@ -0,0 +1,643 @@ +import Mathlib +import OAI.Probability.ParisiFinite.HasDerivAtDeviation +import OAI.Probability.ParisiFinite.WeightedGradientField + +namespace OAI + +/-! Canonical Spatial Test. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def canonicalSpatialTest (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) : QuadraticTest where + val := field β γ t + d1 := fieldGradient β γ t + d2 := fieldCurvature β γ t + hasD1 := hasDerivAt_field β hβ hγ hb t + hasD2 := hasDerivAt_fieldGradient β hβ hγ hb t + continuousD2 := (fieldCurvature_lipschitz β hβ hγ hb t).continuous + c1 := 1 + c2 := β + bound1 := fun x => fieldGradient_bound β hβ hγ hb t x + bound2 := fun x => fieldCurvature_abs β hβ hγ hb t x + +lemma finite_schedule_verification_at (hW : IsBrownianReal W P) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) + (c : ℝ≥0) (hc0 : c≠0) (hc1 : c≤1) : + (∫ ω,(finiteTimeField β hβ ls 0 c).val + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1⟩) ∂P)-recursion β ls 0= + ∫ t in (0:ℝ)..(c:ℝ),∫ ω,finiteVerificationKernel β hβ ls b t + (extend (solution b (brownianPath W ω)) t) ∂P := by + let r := scheduleTimeRealization β hβ ls 0 le_rfl (by rw [hw];norm_num) + have hh := brownian_solution_time_generator_at hW b r.test c hc0 hc1 hc + have hsub : Ioc (0:ℝ) c⊆Ioc (0:ℝ) 1 := Ioc_subset_Ioc le_rfl (by exact_mod_cast hc1) + have hr : volume.restrict (Ioc (0:ℝ) c)≤volume.restrict (Ioc (0:ℝ) 1) := Measure.restrict_mono_set _ hsub + have hj : IntervalIntegrable (timeGeneratorC2 P W b r.test) volume 0 c := by + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le c.coe_nonneg] + have hi := timeGeneratorC2_intervalIntegrable hW b r.test hc + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] at hi + exact hi.mono_set hsub + have ht : IntervalIntegrable (timeDerivativeC2 P W b r.test) volume 0 c := by + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le c.coe_nonneg] + have hi := timeDerivativeC2_intervalIntegrable hW b r.test hc + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] at hi + exact hi.mono_set hsub + have h0 : r.test.val 0 0=recursion β ls 0 := by rw [r.val_eq,finiteTimeField_start] + simp_rw [r.val_eq] at hh + rw [finiteTimeField_start] at hh + rw [hh,←intervalIntegral.integral_add hj ht] + apply intervalIntegral.integral_congr_Ioo_of_le c.coe_nonneg + intro t ht + change (∫ ω,generatorC2 (r.test.slice t) b t (extend (solution b (brownianPath W ω)) t) ∂P)+ + (∫ ω,r.test.dt t (extend (solution b (brownianPath W ω)) t) ∂P)=_ + rw [←integral_add (generatorC2_integrable hW b _ t) (timeDerivativeC2_integrable_inner hW b r.test t)] + apply integral_congr_ae + filter_upwards [] with ω + simp only [generatorC2,TimeQuadraticTest.slice,r.d1_eq,r.d2_eq,r.dt_eq,finiteVerificationKernel] + rw [finiteTimeField_PDE β hβ ls 0 t _ ht.1.le + (by simpa only [hw,zero_add] using (ht.2.trans_le (show (c:ℝ)≤1 by exact_mod_cast hc1)))] + ring + +lemma expected_global_dyadic_field_tendsto (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (b : Drift K M) (c : ℝ≥0) (hc : c<1) : + Tendsto (fun n => ∫ ω,(finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).val + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩) ∂P) atTop + (𝓝 (∫ ω,field β γ c (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩) ∂P)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let X (ω : Ω) := solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩ + have hx : Integrable X P := brownian_solution_integrable hW b _ + have hf : Integrable (fun ω => field β γ c (X ω)) P := (canonicalSpatialTest β hβ hγ hb c).integrable_comp hx + apply tendsto_integral_of_dominated_convergence (fun ω => ‖field β γ c (X ω)‖+(β:ℝ)) + (fun n => ((finiteTimeField β hβ _ 0 c).lipschitz.continuous.measurable.comp_aemeasurable hx.aemeasurable).aestronglyMeasurable) + (hf.norm.add (integrable_const _)) (fun n => ae_of_all _ fun ω => ?_) + (ae_of_all _ fun ω => (global_dyadic_field_tendstoUniformly β hβ hγ hb c hc).tendsto_at (X ω)) + have he := global_dyadic_field_error β hβ hγ hb c hc n (X ω) + have hm : (dyadicMesh 1 n:ℝ)≤1 := by + exact_mod_cast dyadicMesh_le 1 n + have hn := norm_le_norm_add_norm_sub (field β γ c (X ω)) ((finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).val (X ω)) + simp only [Real.norm_eq_abs] at hn + rw [abs_sub_comm (field β γ c (X ω))] at hn + have ht := mul_le_mul_of_nonneg_left hm β.coe_nonneg + simp only [Function.comp_apply,Real.norm_eq_abs] + linarith + +theorem canonical_verification_at (hW : IsBrownianReal W P) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (c : ℝ≥0) (hc0 : c≠0) (hc1 : c<1) : + (∫ ω,field β γ c + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1.le⟩) ∂P)- + field β γ 0 0= + ∫ t in (0:ℝ)..(c:ℝ),∫ ω,verificationKernel β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P := by + have hsub : Ioc (0:ℝ) c⊆Ioc (0:ℝ) 1 := Ioc_subset_Ioc le_rfl (by exact_mod_cast hc1.le) + have hi : Tendsto (fun n => ∫ t in (0:ℝ)..(c:ℝ),∫ ω, + finiteVerificationKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) atTop + (𝓝 (∫ t in (0:ℝ)..(c:ℝ),∫ ω,verificationKernel β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P)) := by + have hmeas (n : ℕ) : AEStronglyMeasurable + (fun t => ∫ ω,finiteVerificationKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) (volume.restrict (uIoc (0:ℝ) c)) := by + rw [uIoc_of_le c.coe_nonneg] + exact (expected_finiteVerificationKernel_aestronglyMeasurable hW β hβ _ + (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) b hc).mono_measure + (Measure.restrict_mono_set _ hsub) + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (M:ℝ)+(β:ℝ)/2) (Eventually.of_forall hmeas) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => + expected_finiteVerificationKernel_bound hW β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t) + intervalIntegrable_const + filter_upwards [global_dyadic_coefficient_tendsto_ae hγ] with t ht hmem + rw [uIoc_of_le c.coe_nonneg] at hmem + have hti : t∈Ioo (0:ℝ) 1 := ⟨hmem.1,hmem.2.trans_lt (by exact_mod_cast hc1)⟩ + exact expected_global_dyadic_verificationKernel_tendsto hW β hβ hγ hb b t hti (ht hti) + have h0 : Tendsto (fun n => recursion β (dyadicSchedule γ false 0 1 n) 0) atTop (𝓝 (field β γ 0 0)) := by + have hh := (global_dyadic_field_tendstoUniformly β hβ hγ hb 0 (by norm_num)).tendsto_at 0 + simpa only [NNReal.coe_zero,finiteTimeField_start] using hh + have he : (fun n => (∫ ω,(finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).val + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1.le⟩) ∂P)- + recursion β (dyadicSchedule γ false 0 1 n) 0)= + (fun n => ∫ t in (0:ℝ)..(c:ℝ),∫ ω,finiteVerificationKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) := by + funext n + exact finite_schedule_verification_at hW b hc β hβ _ + (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) c hc0 hc1.le + exact tendsto_nhds_unique + ((expected_global_dyadic_field_tendsto hW β hβ hγ hb b c hc1).sub h0) (he ▸ hi) + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + +lemma minimizingParisi_potential_average_eq (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hq : q∈(ρ:Measure OrderPoint).support) : + (∫ x,variationalPotential P W hβ (ofMeasure β ρ) x ∂(ρ:Measure OrderPoint))= + variationalPotential P W hβ (ofMeasure β ρ) q := by + calc + _ = ∫ _ : OrderPoint,variationalPotential P W hβ (ofMeasure β ρ) q ∂(ρ:Measure OrderPoint) := by + apply integral_congr_ae + filter_upwards [(ρ:Measure OrderPoint).support_mem_ae] with x hx + exact le_antisymm (minimizingParisi_support_potential hW hβ hρ hx q) + (minimizingParisi_support_potential hW hβ hρ hq x) + _ = _ := by simp + +lemma ofMeasure_real_after_support (ρ : ProbabilityMeasure OrderPoint) (β : ℝ≥0) + (q : OrderPoint) (hq : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) + (r : ℝ) (hr : (q:ℝ)≤r) : (ofMeasure β ρ).real r=β := by + change (measureCoefficient ρ β (Real.toNNReal r):ℝ)=β + rw [measureCoefficient_after_support ρ β q hq] + rw [Real.coe_toNNReal r (q.property.1.trans hr)] + exact hr + +lemma minimizingParisi_weighted_deviation (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hq : q∈(ρ:Measure OrderPoint).support) + (hqmax : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) : + (∫ t in (0:ℝ)..(q:ℝ),(ofMeasure β ρ).real t*deviation P W hβ (ofMeasure β ρ) t)=0 := by + let c := ofMeasure β ρ + have hd := continuous_deviation hW hβ c + have hit (a b : ℝ) : IntervalIntegrable (fun t => c.real t*deviation P W hβ c t) volume a b := + (c.real_intervalIntegrable a b).mul_continuousOn hd.continuousOn + have hall : (∫ t in (0:ℝ)..1,c.real t*deviation P W hβ c t)= + (β:ℝ)*variationalPotential P W hβ c q := by + calc + _ = (β:ℝ)*(∫ t in (0:ℝ)..1,(ρ:Measure OrderPoint).real {x | (x:ℝ)≤t}*deviation P W hβ c t) := by + rw [←intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le zero_le_one] at ht + dsimp only [c] + rw [ofMeasure_real β ρ t ht.1] + ring + _ = (β:ℝ)*(∫ x,variationalPotential P W hβ c x ∂(ρ:Measure OrderPoint)) := by + rw [integral_cdf_mul ρ hd (by norm_num) (norm_deviation_le hW hβ c)] + rfl + _ = _ := by rw [minimizingParisi_potential_average_eq hW hβ hρ hq] + have htail : (∫ t in (q:ℝ)..1,c.real t*deviation P W hβ c t)= + (β:ℝ)*variationalPotential P W hβ c q := by + rw [variationalPotential,←intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le q.property.2] at ht + dsimp only + rw [show c.real t=(β:ℝ) from ofMeasure_real_after_support ρ β q hqmax t ht.1] + have he := intervalIntegral.integral_add_adjacent_intervals (hit 0 q) (hit q 1) + rw [hall,htail] at he + exact add_right_cancel (he.trans (zero_add _).symm) + +lemma minimizingParisi_weighted_consistency (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hq : q∈(ρ:Measure OrderPoint).support) + (hqmax : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) : + (∫ t in (0:ℝ)..(q:ℝ),(ofMeasure β ρ).real t* + expectedProduct P W (ofMeasure β ρ) (ofMeasure β ρ) ((ofMeasure β ρ).driftData hβ) t)= + ∫ t in (0:ℝ)..(q:ℝ),t*(ofMeasure β ρ).real t := by + let c := ofMeasure β ρ + have hi : IntervalIntegrable (fun t => c.real t*expectedProduct P W c c (c.driftData hβ) t) volume 0 q := + (c.real_intervalIntegrable 0 q).mul_continuousOn (expectedProduct_continuous hW c c hβ _).continuousOn + have hj : IntervalIntegrable (fun t => t*c.real t) volume 0 q := + (c.real_intervalIntegrable 0 q).continuousOn_mul continuous_id.continuousOn + apply sub_eq_zero.mp + rw [←intervalIntegral.integral_sub hi hj] + convert minimizingParisi_weighted_deviation hW hβ hρ hq hqmax using 1 + apply intervalIntegral.integral_congr + intro t ht + dsimp only [deviation,c] + ring + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +namespace BoundedCoefficient +variable {β : ℝ≥0} +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {K M : ℝ≥0} + +lemma curvature_integrable (hW : IsBrownianReal W P) (c : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) (t : ℝ) : + Integrable (fun ω => c.curvature (solution b (brownianPath W ω)) t) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact Integrable.of_bound (c.curvature_aestronglyMeasurable hW hβ b t) (β:ℝ) + (ae_of_all _ fun ω => c.norm_curvature_le hβ _ t) + +def expectedCurvature (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (c : BoundedCoefficient β) (hβ : 0<β) (t : ℝ) : ℝ := + ∫ ω,c.curvature (solution (c.driftData hβ) (brownianPath W ω)) t ∂P + +lemma expectedCurvature_continuous (hW : IsBrownianReal W P) + (c : BoundedCoefficient β) (hβ : 0<β) : Continuous (c.expectedCurvature P W hβ) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact continuous_of_dominated (bound := fun _ => (β:ℝ)) + (fun t => (curvature_integrable hW c hβ _ t).aestronglyMeasurable) + (fun t => ae_of_all _ fun ω => c.norm_curvature_le hβ _ t) (integrable_const _) + (ae_of_all _ fun ω => c.continuous_curvature hβ _) + +lemma expectedCurvature_nonneg (c : BoundedCoefficient β) (hβ : 0<β) (t : ℝ) : + 0≤c.expectedCurvature P W hβ t := integral_nonneg fun _ => (c.curvature_pos hβ _ t).le + +lemma expectedCurvature_bound (hW : IsBrownianReal W P) + (c : BoundedCoefficient β) (hβ : 0<β) (t : ℝ) : ‖c.expectedCurvature P W hβ t‖≤β := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (μ:=P) (ae_of_all _ fun ω => c.norm_curvature_le hβ _ t)).trans_eq (by simp) + +lemma position_spin (hW : IsBrownianReal W P) (c : BoundedCoefficient β) (hβ : 0<β) + (q : OrderPoint) (hq0 : 0<(q:ℝ)) (hq1 : (q:ℝ)<1) : + (∫ ω,(solution (c.driftData hβ) (brownianPath W ω) q)* + c.spin (solution (c.driftData hβ) (brownianPath W ω)) q ∂P)= + (∫ t in (0:ℝ)..(q:ℝ),c.expectedCurvature P W hβ t)+ + ∫ t in (0:ℝ)..(q:ℝ),c.real t*expectedProduct P W c c (c.driftData hβ) t := by + let r : ℝ≥0 := ⟨q,q.property.1⟩ + have hr0 : r≠0 := ne_of_gt (show 0 c.real t*expectedProduct P W c c (c.driftData hβ) t) volume 0 q := + (c.real_intervalIntegrable 0 q).mul_continuousOn (expectedProduct_continuous hW c c hβ _).continuousOn + rw [←intervalIntegral.integral_add hi hj] + apply intervalIntegral.integral_congr + intro t ht + change t∈uIcc (0:ℝ) (q:ℝ) at ht + rw [uIcc_of_le q.property.1] at ht + have ht' : t∈Icc (0:ℝ) 1 := ⟨ht.1,ht.2.trans q.property.2⟩ + change (∫ ω,fieldCurvature β c.val (Real.toNNReal t) _+c.real t*(fieldGradient β c.val (Real.toNNReal t) _)^2 ∂P)=_ + dsimp only + rw [expectedCurvature,expectedProduct,←integral_const_mul,←integral_add + (c.curvature_integrable hW hβ _ t) ((c.spin_product_integrable hW c hβ _ t).const_mul _)] + apply integral_congr_ae + filter_upwards [] with ω + rw [curvature_eq _ _ _ ht',spin_eq _ _ _ ht'] + ring + +lemma field_value_at (hW : IsBrownianReal W P) (c : BoundedCoefficient β) (hβ : 0<β) + (q : OrderPoint) (hq0 : 0<(q:ℝ)) (hq1 : (q:ℝ)<1) : + (∫ ω,field β c.val ⟨q,q.property.1⟩ (solution (c.driftData hβ) (brownianPath W ω) q) ∂P)= + field β c.val 0 0+(∫ t in (0:ℝ)..(q:ℝ),c.real t*expectedProduct P W c c (c.driftData hβ) t)/2 := by + let r : ℝ≥0 := ⟨q,q.property.1⟩ + have hr0 : r≠0 := ne_of_gt (show 0.trans (add_comm _ _) + +end BoundedCoefficient +open BoundedCoefficient +variable {β : ℝ≥0} +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma minimizingParisi_position_spin (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hq : q∈(ρ:Measure OrderPoint).support) + (hqmax : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) (hq0 : 0<(q:ℝ)) (hq1 : (q:ℝ)<1) : + (∫ ω,(solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω) q)* + (ofMeasure β ρ).spin (solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω)) q ∂P)= + (∫ t in (0:ℝ)..(q:ℝ),(ofMeasure β ρ).expectedCurvature P W hβ t)+ + ∫ t in (0:ℝ)..(q:ℝ),t*(ofMeasure β ρ).real t := by + rw [(ofMeasure β ρ).position_spin hW hβ q hq0 hq1, + minimizingParisi_weighted_consistency hW hβ hρ hq hqmax] + +lemma minimizingParisi_field_value_at (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hq : q∈(ρ:Measure OrderPoint).support) + (hqmax : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) (hq0 : 0<(q:ℝ)) (hq1 : (q:ℝ)<1) : + (∫ ω,field β (measureCoefficient ρ β) ⟨q,q.property.1⟩ + (solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω) q) ∂P)= + field β (measureCoefficient ρ β) 0 0+(∫ t in (0:ℝ)..(q:ℝ),t*(ofMeasure β ρ).real t)/2 := by + have hh := (ofMeasure β ρ).field_value_at hW hβ q hq0 hq1 + rw [minimizingParisi_weighted_consistency hW hβ hρ hq hqmax] at hh + exact hh + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +lemma terminal_entropy_loss {β : ℝ} (hβ : 0<β) (x : ℝ) : + terminal β x-Real.log 2/β≤x*Real.tanh (β*x) := by + let g (x : ℝ) := x*Real.tanh (β*x)-terminal β x + have hd (x : ℝ) : HasDerivAt g (x*(β/(Real.cosh (β*x))^2)) x := by + convert ((hasDerivAt_id x).mul (hasDerivAt_tanh_scaled β x)).sub (hasDerivAt_terminal hβ x) using 1 <;> first | rfl | (dsimp only [g,id_eq];ring) + have hm : MonotoneOn g (Ici (0:ℝ)) := by + apply monotoneOn_of_deriv_nonneg (convex_Ici 0) + (fun x _ => (hd x).continuousAt.continuousWithinAt) + (fun x _ => (hd x).differentiableAt.differentiableWithinAt) + intro x hx + rw [(hd x).deriv] + have hx' : 0≤x := interior_subset hx + positivity + have he (x : ℝ) : g (-x)=g x := by + dsimp only [g,terminal] + rw [mul_neg,Real.tanh_neg,Real.cosh_neg,neg_mul_neg] + have hz : g 0= -(Real.log 2/β) := by simp [g] + have hg : g 0≤g x := by + by_cases hx : 0≤x + · exact hm (by simp) hx hx + · have hh := hm (by simp) (show -x∈Ici (0:ℝ) by simp;linarith) (by linarith : (0:ℝ)≤ -x) + simpa only [he] using hh + rw [hz] at hg + dsimp only [g] at hg + linarith + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient +variable {β : ℝ≥0} + +lemma measureFunctional_eq_field_penalty (ρ : ProbabilityMeasure OrderPoint) : + measureFunctional β ρ=field β (measureCoefficient ρ β) 0 0- + (∫ t in (0:ℝ)..1,t*(ofMeasure β ρ).real t)/2 := by + simp only [measureFunctional,orderParameterFunctional,field,tsub_zero, + coefficientPenalty,zero_add,NNReal.coe_zero,NNReal.coe_one, + intervalIntegral.integral_div,BoundedCoefficient.real,ofMeasure] + +lemma minimizingParisi_value_eq_pressure (hβ : 0<β) {ρ : ProbabilityMeasure OrderPoint} + (hρ : IsMinimizingParisiMeasure β ρ) : measureFunctional β ρ=SKQAOA.limitingFreeEnergy β := by + obtain ⟨ν,hν,he⟩ := exists_minimizing_Parisi_measure hβ + exact le_antisymm ((hρ ν).trans_eq he) (pressure_le_measureFunctional hβ ρ) + +lemma measureCoefficient_penalty_split (ρ : ProbabilityMeasure OrderPoint) + (q : OrderPoint) (hqmax : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) : + (∫ t in (0:ℝ)..1,t*(ofMeasure β ρ).real t)= + (∫ t in (0:ℝ)..(q:ℝ),t*(ofMeasure β ρ).real t)+(β:ℝ)*(1-(q:ℝ)^2)/2 := by + let c := ofMeasure β ρ + have hi (a b : ℝ) : IntervalIntegrable (fun t => t*c.real t) volume a b := + (c.real_intervalIntegrable a b).continuousOn_mul continuous_id.continuousOn + rw [←intervalIntegral.integral_add_adjacent_intervals (hi 0 q) (hi q 1)] + congr 1 + calc + _ = ∫ t in (q:ℝ)..1,t*(β:ℝ) := by + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le q.property.2] at ht + dsimp only + rw [ofMeasure_real_after_support ρ β q hqmax t ht.1] + _ = _ := by rw [intervalIntegral.integral_mul_const,integral_id];ring + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma minimizingParisi_value_at_endpoint_raw (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hq : q∈(ρ:Measure OrderPoint).support) + (hqmax : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) (hq0 : 0<(q:ℝ)) (hq1 : (q:ℝ)<1) : + SKQAOA.limitingFreeEnergy β-(β:ℝ)*(1-(q:ℝ))^2/4-Real.log 2/(β:ℝ)≤ + ∫ t in (0:ℝ)..(q:ℝ),(ofMeasure β ρ).expectedCurvature P W hβ t := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let c := ofMeasure β ρ + let X (ω : Ω) := solution (c.driftData hβ) (brownianPath W ω) + let r : ℝ≥0 := ⟨q,q.property.1⟩ + have hr : r≤1 := by exact_mod_cast q.property.2 + have hp : ∀ s : ℝ≥0,r ≤ s → c.val s=β := by + intro s hs + exact measureCoefficient_after_support ρ β q hqmax s (NNReal.coe_le_coe.mpr hs) + have hsm (ω : Ω) : c.spin (X ω) q=fieldGradient β c.val r (X ω q) := by + rw [spin_eq _ _ _ q.property,extend_of_mem _ q.property] + congr 1 + apply NNReal.coe_injective + exact Real.coe_toNNReal _ q.property.1 + have hh (ω : Ω) : field β c.val r (X ω q)-(β:ℝ)*(1-(q:ℝ))/2-Real.log 2/(β:ℝ)≤ + (X ω q)*c.spin (X ω) q := by + rw [hsm,field_final_plateau β hβ r hr hp,fieldGradient_final_plateau β hβ r hr hp] + change terminal β (X ω q)+(β:ℝ)*(1-(q:ℝ))/2- + (β:ℝ)*(1-(q:ℝ))/2-Real.log 2/(β:ℝ)≤(X ω q)*Real.tanh ((β:ℝ)*(X ω q)) + linarith [terminal_entropy_loss (show (0:ℝ)<β from hβ) (X ω q)] + have hx : Integrable (fun ω => X ω q) P := brownian_solution_integrable hW _ q + have hf : Integrable (fun ω => field β c.val r (X ω q)) P := + (canonicalSpatialTest β hβ c.mono c.bound r).integrable_comp hx + have hm : Integrable (fun ω => (X ω q)*c.spin (X ω) q) P := hx.mul_bdd + (c.spin_aestronglyMeasurable hW hβ _ q) (ae_of_all _ fun ω => c.norm_spin_le hβ (X ω) q) + have hle := integral_mono ((hf.sub (integrable_const _)).sub (integrable_const _)) hm hh + dsimp only [Pi.sub_apply] at hle + have hsplit := integral_sub (hf.sub (integrable_const ((β:ℝ)*(1-(q:ℝ))/2))) + (integrable_const (Real.log 2/(β:ℝ))) + dsimp only [Pi.sub_apply] at hsplit + rw [hsplit,integral_sub hf (integrable_const _)] at hle + simp only [integral_const,probReal_univ,one_smul] at hle + have hpos := minimizingParisi_position_spin hW hβ hρ hq hqmax hq0 hq1 + have hfield := minimizingParisi_field_value_at hW hβ hρ hq hqmax hq0 hq1 + change (∫ ω,field β (measureCoefficient ρ β) ⟨q,q.property.1⟩ + (solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω) q) ∂P)- + (β:ℝ)*(1-(q:ℝ))/2-Real.log 2/(β:ℝ)≤ + (∫ ω,(solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω) q)* + (ofMeasure β ρ).spin (solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω)) q ∂P) at hle + rw [hpos,hfield] at hle + have hval := measureFunctional_eq_field_penalty (β:=β) ρ + rw [minimizingParisi_value_eq_pressure hβ hρ,measureCoefficient_penalty_split ρ q hqmax] at hval + nlinarith + + + +theorem minimizingParisi_value_at_endpoint (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hq : q∈(ρ:Measure OrderPoint).support) + (hqmax : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) (hq0 : 0<(q:ℝ)) (hq1 : (q:ℝ)<1) : + SKQAOA.Pstar-(1/4+Real.log 2)/(β:ℝ)≤ + ∫ t in (0:ℝ)..(q:ℝ),(ofMeasure β ρ).expectedCurvature P W hβ t := by + have hb : (0:ℝ)<β := hβ + have hqbd := minimizingParisi_endpoint_bound hW hβ hρ hq hqmax hq0 hq1 + have hsmall : (β:ℝ)*(1-(q:ℝ))^2/4≤(1/4)/(β:ℝ) := by + calc + _ ≤ (β:ℝ)*(1/(β:ℝ))^2/4 := by gcongr + _ = _ := by field_simp + have hv := minimizingParisi_value_at_endpoint_raw hW hβ hρ hq hqmax hq0 hq1 + have hf := (SKQAOA.limitingFreeEnergy_bounds hb).1 + have he : (1/4+Real.log 2)/(β:ℝ)=(1/4)/(β:ℝ)+Real.log 2/(β:ℝ) := add_div _ _ _ + rw [he] + linarith + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient BrownianConstruction + + + +theorem minimizingParisi_zero_in_support {β : ℝ≥0} (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) : + (⟨0,by simp⟩ : OrderPoint)∈(ρ:Measure OrderPoint).support := + minimizingParisi_zero_mem_support brownianMotion_isBrownian hβ hρ + + + +theorem minimizingParisi_support_boundary {β : ℝ≥0} (hβ : (1:ℝ)<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) : + ∃ q : OrderPoint, 0<(q:ℝ) ∧ (q:ℝ)<1 ∧ + q∈(ρ:Measure OrderPoint).support ∧ + (∀ t∈(ρ:Measure OrderPoint).support,t≤q) ∧ 1-(q:ℝ)≤1/(β:ℝ) := by + have hbp : 0<β := by exact_mod_cast (zero_lt_one.trans hβ) + obtain ⟨q,hq0,hq1,hq,hqmax⟩ := + minimizingParisi_support_endpoint brownianMotion_isBrownian hβ hρ + exact ⟨q,hq0,hq1,hq,hqmax, + minimizingParisi_endpoint_bound brownianMotion_isBrownian hbp hρ hq hqmax hq0 hq1⟩ + + + +theorem exists_minimizingParisi_endpoint_value {β : ℝ≥0} (hβ : (1:ℝ)<β) : + ∃ (ρ : ProbabilityMeasure OrderPoint) (q : OrderPoint) (hbp : 0<β), + IsMinimizingParisiMeasure β ρ ∧ + measureFunctional β ρ=SKQAOA.limitingFreeEnergy β ∧ + (⟨0,by simp⟩ : OrderPoint)∈(ρ:Measure OrderPoint).support ∧ + 0<(q:ℝ) ∧ (q:ℝ)<1 ∧ + q∈(ρ:Measure OrderPoint).support ∧ + (∀ t∈(ρ:Measure OrderPoint).support,t≤q) ∧ + 1-(q:ℝ)≤1/(β:ℝ) ∧ + SKQAOA.Pstar-(1/4+Real.log 2)/(β:ℝ)≤ + ∫ t in (0:ℝ)..(q:ℝ), + (ofMeasure β ρ).expectedCurvature brownianMeasure brownianMotion hbp t := by + have hbp : 0<β := by exact_mod_cast (zero_lt_one.trans hβ) + obtain ⟨ρ,hρ,hval⟩ := exists_minimizing_Parisi_measure hbp + obtain ⟨q,hq0,hq1,hq,hqmax,hqbd⟩ := minimizingParisi_support_boundary hβ hρ + exact ⟨ρ,q,hbp,hρ,hval,minimizingParisi_zero_in_support hbp hρ, + hq0,hq1,hq,hqmax,hqbd, + minimizingParisi_value_at_endpoint brownianMotion_isBrownian hbp hρ hq hqmax hq0 hq1⟩ + +end ParisiFinite + + + + + + + +open MeasureTheory Set Filter +open scoped Topology +namespace ParisiGapGeometry +abbrev OrderPoint := Icc (0 : ℝ) 1 + +theorem support_gap_endpoints (μ : Measure OrderPoint) [IsProbabilityMeasure μ] + {q : OrderPoint} (hz : (⟨0, by simp⟩ : OrderPoint) ∈ μ.support) + (hq : q ∈ μ.support) (hmax : ∀ t ∈ μ.support, t ≤ q) + (hne : μ.support ≠ Iic q) : + ∃ a b : OrderPoint, a ∈ μ.support ∧ b ∈ μ.support ∧ a < b ∧ b ≤ q ∧ + ∀ x ∈ Ioo a b, x ∉ μ.support := by + classical + have hsub : μ.support ⊆ Iic q := fun t ht => hmax t ht + obtain ⟨t, htq, ht⟩ := Set.exists_of_ssubset (ssubset_iff_subset_ne.mpr ⟨hsub, hne⟩) + have hA : IsCompact (μ.support ∩ Iic t) := μ.isClosed_support.isCompact.inter_right isClosed_Iic + have hB : IsCompact (μ.support ∩ Ici t) := μ.isClosed_support.isCompact.inter_right isClosed_Ici + obtain ⟨a, ha⟩ := hA.exists_isGreatest ⟨⟨0, by simp⟩, hz, t.property.1⟩ + obtain ⟨b, hb⟩ := hB.exists_isLeast ⟨q, hq, htq⟩ + have hat : a < t := lt_of_le_of_ne ha.1.2 (by rintro rfl; exact ht ha.1.1) + have htb : t < b := lt_of_le_of_ne hb.1.2 (by rintro rfl; exact ht hb.1.1) + refine ⟨a, b, ha.1.1, hb.1.1, hat.trans htb, hmax b hb.1.1, ?_⟩ + intro x hx hs + by_cases hxt : x ≤ t + · exact (not_le.mpr hx.1) (ha.2 ⟨hs, hxt⟩) + · exact (not_le.mpr hx.2) (hb.2 ⟨hs, (not_le.mp hxt).le⟩) + +theorem cdf_constant_on_gap (μ : Measure OrderPoint) [IsProbabilityMeasure μ] + {a b : OrderPoint} (hgap : ∀ x ∈ Ioo a b, x ∉ μ.support) + {r : ℝ} (har : (a : ℝ) ≤ r) (hrb : r < (b : ℝ)) : + μ {x | (x : ℝ) ≤ r} = μ (Iic a) := by + apply measure_congr + filter_upwards [μ.support_mem_ae] with x hx + apply propext + constructor + · intro hxr + by_contra hxa + exact hgap x ⟨not_le.mp hxa, (show (x : ℝ) < (b : ℝ) from lt_of_le_of_lt hxr hrb)⟩ hx + · intro hxa + exact le_trans hxa har + +theorem cdf_pos_at_gap_left (μ : Measure OrderPoint) [IsProbabilityMeasure μ] + {a b : OrderPoint} (ha : a ∈ μ.support) (hab : a < b) + (hgap : ∀ x ∈ Ioo a b, x ∉ μ.support) : + 0 < μ (Iic a) := by + have hp : 0 < μ (Iio b) := (μ.mem_support_iff_forall a).mp ha _ (Iio_mem_nhds hab) + have he : μ (Iio b) = μ (Iic a) := by + apply measure_congr + filter_upwards [μ.support_mem_ae] with x hx + apply propext + constructor + · intro hxb + by_contra hxa + exact hgap x ⟨not_le.mp hxa, hxb⟩ hx + · intro hxa + exact lt_of_le_of_lt hxa hab + rwa [he] at hp + +end ParisiGapGeometry + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ChildMomentLimit.lean b/lean/OAI/Probability/ParisiFinite/ChildMomentLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..9398e16b3e78cd56d6eaccd0af4d005c7822ce60 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ChildMomentLimit.lean @@ -0,0 +1,644 @@ +import Mathlib +import OAI.Probability.ParisiFinite.FlipStar + +namespace OAI + +/-! Child Moment Limit. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open scoped InnerProductSpace Topology +open Filter +namespace FiniteTree +open RootTensorCLT CoherentFock + + + +theorem child_moment_limit (h : ℕ) + (ih : ∀u w : List PointedTree.Gate, + Tendsto (fun D => ⟪insertion D h u,insertion D h w⟫_ℂ) atTop + (𝓝 ⟪(PointedTree.ordinary u h).insertion,(PointedTree.ordinary w h).insertion⟫_ℂ)) + (i j : Label) : + Tendsto (fun D => ⟪vac D h,childGenerator D h i (childGenerator D h j (vac D h))⟫_ℂ) + atTop (𝓝 (-⟪childDirection h i,childDirection h j⟫_ℂ)) := by + have ht := (ih i.1 j.1).const_mul (-((i.2:ℂ)*(j.2:ℂ))) + have he : -⟪childDirection h i,childDirection h j⟫_ℂ= + -((i.2:ℂ)*(j.2:ℂ))*⟪(PointedTree.ordinary i.1 h).insertion,(PointedTree.ordinary j.1 h).insertion⟫_ℂ := by + simp only [childDirection,inner_smul_left,inner_smul_right,Complex.conj_ofReal] + ring + simpa only [child_second_moment,he] using ht + +theorem program_limit_of_child (h : ℕ) + (ih : ∀u w : List PointedTree.Gate, + Tendsto (fun D => ⟪insertion D h u,insertion D h w⟫_ℂ) atTop + (𝓝 ⟪(PointedTree.ordinary u h).insertion,(PointedTree.ordinary w h).insertion⟫_ℂ)) + (u w : List (Pulse Label)) : + Tendsto (fun D => + ⟪run (tensorPulse D (childGenerator D h)) u + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h))), + run (tensorPulse D (childGenerator D h)) w + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h)))⟫_ℂ) + atTop (𝓝 ⟪run (W ∘ childDirection h) u (PointedTree.vac (h+1)), + run (W ∘ childDirection h) w (PointedTree.vac (h+1))⟫_ℂ) := by + exact root_circuit_Gram_local_limit (fun D => Index D h) (fun D => vac D h) + (fun D => childGenerator D h) negateLabel negateLabel_involutive (childDirection h) + (fun i => |i.2|) (fun i => abs_nonneg i.2) (fun D => norm_vac D h) + (fun D i => le_of_eq ((ordinary D i.1 h).norm_generator i.2)) + (fun D i => childGenerator_neg D h i) (fun D i => childGenerator_star D h i) + (fun i => childDirection_neg h i) + (fun D i => (ordinary D i.1 h).generator_centered i.2) + (child_moment_limit h ih) u w + + + +theorem insertion_Gram_limit (h : ℕ) (u w : List PointedTree.Gate) : + Tendsto (fun D => ⟪insertion D h u,insertion D h w⟫_ℂ) atTop + (𝓝 ⟪(PointedTree.ordinary u h).insertion,(PointedTree.ordinary w h).insertion⟫_ℂ) := by + induction h generalizing u w with + | zero => + change Tendsto (fun D => ⟪insertion D 0 u,insertion D 0 w⟫_ℂ) atTop + (𝓝 ⟪((PointedTree.ordinary u 0).insertion : PointedTree.Level 0), + ((PointedTree.ordinary w 0).insertion : PointedTree.Level 0)⟫_ℂ) + simp_rw [insertion_zero] + exact tendsto_const_nhds + | succ h ih => + have hg := program_limit_of_child h ih (insertionProgram u) (insertionProgram w) + have hn (D : ℕ) : ⟪insertion D (h+1) u,insertion D (h+1) w⟫_ℂ= + ⟪run (tensorPulse D (childGenerator D h)) (insertionProgram u) + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h))), + run (tensorPulse D (childGenerator D h)) (insertionProgram w) + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h)))⟫_ℂ := by + rw [←split_insertion,←split_insertion,LinearIsometryEquiv.inner_map_map] + have hf : ⟪(PointedTree.ordinary u (h+1)).insertion,(PointedTree.ordinary w (h+1)).insertion⟫_ℂ= + ⟪run (W ∘ childDirection h) (insertionProgram u) (PointedTree.vac (h+1)), + run (W ∘ childDirection h) (insertionProgram w) (PointedTree.vac (h+1))⟫_ℂ := by + change ⟪((PointedTree.ordinary u (h+1)).insertion : PointedTree.Level (h+1)), + ((PointedTree.ordinary w (h+1)).insertion : PointedTree.Level (h+1))⟫_ℂ=_ + rw [limiting_insertion,limiting_insertion] + simpa only [hn,hf] using hg + + + +theorem program_Gram_limit (h : ℕ) (u w : List (Pulse Label)) : + Tendsto (fun D => + ⟪run (tensorPulse D (childGenerator D h)) u + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h))), + run (tensorPulse D (childGenerator D h)) w + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h)))⟫_ℂ) + atTop (𝓝 ⟪run (W ∘ childDirection h) u (PointedTree.vac (h+1)), + run (W ∘ childDirection h) w (PointedTree.vac (h+1))⟫_ℂ) := + program_limit_of_child h (insertion_Gram_limit h) u w + +end FiniteTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter ContinuousLinearMap +namespace FiniteTree +open QuantumCLT RootTensorCLT CoherentFock + + + +theorem marked_child_moment (D h : ℕ) (w : List PointedTree.Gate) (i : Label) : + ⟪vac D h,(ordinary D w h).observable (childGenerator D h i (vac D h))⟫_ℂ= + (Complex.I*(i.2:ℂ))*⟪insertion D h w,insertion D h i.1⟫_ℂ := by + simp only [childGenerator,Even.generator,smul_apply,map_smul,inner_smul_right] + congr 1 + rw [←ContinuousLinearMap.adjoint_inner_left,←ContinuousLinearMap.star_eq_adjoint, + Even.observable_star] + rfl + +theorem marked_child_limit (h : ℕ) (w : List PointedTree.Gate) (i : Label) : + Tendsto (fun D => ⟪vac D h,(ordinary D w h).observable + (childGenerator D h i (vac D h))⟫_ℂ) atTop + (𝓝 (Complex.I*⟪(PointedTree.ordinary w h).insertion,childDirection h i⟫_ℂ)) := by + have ht := (insertion_Gram_limit h w i.1).const_mul (Complex.I*(i.2:ℂ)) + simpa only [marked_child_moment,childDirection,inner_smul_right,mul_assoc] using ht + +theorem marked_child_sum_limit (h : ℕ) (w : List PointedTree.Gate) (l : List Label) : + Tendsto (fun D => ⟪vac D h,(ordinary D w h).observable + ((l.map (childGenerator D h)).sum (vac D h))⟫_ℂ) atTop + (𝓝 (Complex.I*⟪(PointedTree.ordinary w h).insertion,(l.map (childDirection h)).sum⟫_ℂ)) := by + induction l with + | nil => simp + | cons i l ih => + simp only [List.map_cons,List.sum_cons,add_apply,map_add,inner_add_right,mul_add] + exact (marked_child_limit h w i).add ih + +theorem child_sum_centered (D h : ℕ) (l : List Label) : + ⟪vac D h,(l.map (childGenerator D h)).sum (vac D h)⟫_ℂ=0 := by + induction l with + | nil => simp + | cons i l ih => + simp only [List.map_cons,List.sum_cons,add_apply,inner_add_right,ih,add_zero] + exact (ordinary D i.1 h).generator_centered i.2 + +theorem child_second_limit (h : ℕ) (l : List Label) : + Tendsto (fun D => ⟪vac D h,second (l.map (childGenerator D h)) (vac D h)⟫_ℂ) + atTop (𝓝 (secondCoefficient (fun i j => -⟪childDirection h i,childDirection h j⟫_ℂ) l)) := by + have he (D : ℕ) : ⟪vac D h,second (l.map (childGenerator D h)) (vac D h)⟫_ℂ= + secondCoefficient (fun i j => ⟪vac D h,childGenerator D h i (childGenerator D h j (vac D h))⟫_ℂ) l := + second_matrixElement l (childGenerator D h) (vacuumFunctional (vac D h)) + simp_rw [he] + exact secondCoefficient_tendsto l _ _ (fun i hi j hj => + child_moment_limit h (insertion_Gram_limit h) i j) + + + +theorem marked_tensor_limit (h : ℕ) (w : List PointedTree.Gate) (l : List Label) : + Tendsto (fun D => ⟪FiniteTensor.power D (vac D h),FiniteTensor.normalizedInsertion D + (generators (l.map (childGenerator D h)) (Real.sqrt (D:ℝ))⁻¹) + ((ordinary D w h).observable*generators (l.map (childGenerator D h)) (Real.sqrt (D:ℝ))⁻¹) + (FiniteTensor.power D (vac D h))⟫_ℂ) atTop + (𝓝 ((Complex.I*⟪(PointedTree.ordinary w h).insertion,(l.map (childDirection h)).sum⟫_ℂ)* + Complex.exp (secondCoefficient (fun i j => -⟪childDirection h i,childDirection h j⟫_ℂ) l))) := by + classical + let L : ℝ := ∑i∈l.toFinset, |i.2| + have hL : 0≤L := Finset.sum_nonneg (fun i hi => abs_nonneg i.2) + apply FiniteTensor.moving_tensor_insertion_limit (fun D => Index D h) (fun D => vac D h) + l (fun D => childGenerator D h) (fun D => (ordinary D w h).observable) L 1 hL (by norm_num) + (fun D => norm_vac D h) + · intro D i hi + exact ((ordinary D i.1 h).norm_generator i.2).le.trans + (Finset.single_le_sum (fun j hj => abs_nonneg j.2) (List.mem_toFinset.mpr hi)) + · intro D + exact (ordinary D w h).norm_observable.le + · exact fun D => child_sum_centered D h l + · exact fun D => (ordinary D w h).observable_centered + · exact child_second_limit h l + · exact marked_child_sum_limit h w l + +end FiniteTree + + + +open scoped InnerProductSpace Topology +open ContinuousLinearMap +namespace QuantumCLT +open CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem inner_creation_coherent (a e : E) : + ⟪creationVacuum a,coherent e⟫_ℂ= + Complex.I*(Real.exp (-‖e‖^2/2):ℂ)*⟪a,e⟫_ℂ := by + rw [←inner_conj_symm,creationVacuum,inner_smul_right,inner_coherent_oneParticle] + simp only [map_mul,map_neg,Complex.conj_I,neg_neg,Complex.conj_ofReal, + inner_conj_symm] + ring + + + +theorem inner_creation_weylProduct (a : E) (ds : List E) : + ⟪creationVacuum a,weylProduct ds (coherent (0:E))⟫_ℂ= + (Complex.I*⟪a,ds.sum⟫_ℂ)* + Complex.exp (secondCoefficient (fun x y : E => -⟪x,y⟫_ℂ) ds) := by + rw [weylProduct_coherent_zero,inner_smul_right,inner_creation_coherent] + have he (q : ℂ) : Complex.exp (q+Complex.ofReal (‖ds.sum‖^2/2))* + (Real.exp (-‖ds.sum‖^2/2):ℂ)=Complex.exp q := by + rw [Complex.ofReal_exp,←Complex.exp_add] + congr 1 + push_cast + ring + calc + _ = Complex.I*⟪a,ds.sum⟫_ℂ*(Complex.exp (_+Complex.ofReal (‖ds.sum‖^2/2))* + (Real.exp (-‖ds.sum‖^2/2):ℂ)) := by ring + _ = _ := by rw [he] + +end QuantumCLT + +namespace FiniteTensor +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + + + +theorem inner_excitation_power (D : ℕ) (Ω : EuclideanSpace ℂ ι) + (S G : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) (hS : star S=S) : + ⟪normalizedInsertion D 1 S (power D Ω),power D (G Ω)⟫_ℂ= + ⟪power D Ω,normalizedInsertion D G (S*G) (power D Ω)⟫_ℂ := by + rw [←inner_conj_symm (normalizedInsertion D 1 S (power D Ω)) (power D (G Ω)), + inner_normalizedInsertion,inner_normalizedInsertion] + simp only [mul_apply_eq_comp,map_mul,map_pow,Complex.conj_ofReal, + inner_conj_symm] + have hs : ⟪S Ω,G Ω⟫_ℂ=⟪Ω,S (G Ω)⟫_ℂ := by + rw [←ContinuousLinearMap.adjoint_inner_right,←ContinuousLinearMap.star_eq_adjoint,hS] + rw [hs] + rfl + +end FiniteTensor + + + +open scoped InnerProductSpace Topology +open Filter ContinuousLinearMap +namespace TensorPackets +open SpinOperators +variable {κ H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +theorem inner_plus_term (z : H) (s : List κ → H) (t : Term κ) : + ⟪PointedTree.plusEmbedding z,term s t⟫_ℂ= + (((Real.sqrt 2)⁻¹:ℝ):ℂ)*t.coeff*⟪z,s t.history⟫_ℂ := by + obtain ⟨j,c,w⟩ := t + simp only [PiLp.inner_apply,Fin.sum_univ_two,PointedTree.plusEmbedding_apply] + fin_cases j <;> simp [term_apply,inner_smul_left,inner_smul_right,mul_assoc,mul_left_comm] + + + +theorem marked_limit + (Hn : ℕ → Type*) [∀n,NormedAddCommGroup (Hn n)] [∀n,InnerProductSpace ℂ (Hn n)] + (sn : ∀n,List κ → Hn n) (s : List κ → H) (zn : ∀n,Hn n) (z : H) + (hz : ∀w,Tendsto (fun n => ⟪zn n,sn n w⟫_ℂ) atTop (𝓝 ⟪z,s w⟫_ℂ)) + (ts : List (Term κ)) : + Tendsto (fun n => ⟪PointedTree.plusEmbedding (zn n),packet (sn n) ts⟫_ℂ) + atTop (𝓝 ⟪PointedTree.plusEmbedding z,packet s ts⟫_ℂ) := by + induction ts with + | nil => simp only [packet_nil,inner_zero_right]; exact tendsto_const_nhds + | cons t ts ih => + simp only [packet_cons,inner_add_right,inner_plus_term] + exact ((hz t.history).const_mul _).add ih +end TensorPackets + +namespace FiniteTree +open QuantumCLT RootTensorCLT CoherentFock TensorPackets + + + +def excitation (D h : ℕ) (w : List PointedTree.Gate) : Tail D (h+1) := + FiniteTensor.normalizedInsertion D 1 (ordinary D w h).observable + (FiniteTensor.power D (vac D h)) + +theorem excitation_tensor_limit (h : ℕ) (w : List PointedTree.Gate) (l : List Label) : + Tendsto (fun D => ⟪excitation D h w,tensorState D (vac D h) (childGenerator D h) l⟫_ℂ) + atTop (𝓝 ⟪creationVacuum (PointedTree.ordinary w h).insertion,fockState (childDirection h) l⟫_ℂ) := by + have hn (D : ℕ) : ⟪excitation D h w,tensorState D (vac D h) (childGenerator D h) l⟫_ℂ= + ⟪FiniteTensor.power D (vac D h),FiniteTensor.normalizedInsertion D + (generators (l.map (childGenerator D h)) (Real.sqrt (D:ℝ))⁻¹) + ((ordinary D w h).observable*generators (l.map (childGenerator D h)) (Real.sqrt (D:ℝ))⁻¹) + (FiniteTensor.power D (vac D h))⟫_ℂ := + FiniteTensor.inner_excitation_power D (vac D h) _ _ (ordinary D w h).observable_star + simp only [hn,fockState,inner_creation_weylProduct,secondCoefficient_map] + exact marked_tensor_limit h w l + +theorem excitation_program_limit (h : ℕ) (w : List PointedTree.Gate) (p : List (Pulse Label)) : + Tendsto (fun D => ⟪PointedTree.plusEmbedding (excitation D h w), + run (tensorPulse D (childGenerator D h)) p (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h)))⟫_ℂ) + atTop (𝓝 ⟪PointedTree.plusEmbedding (creationVacuum (PointedTree.ordinary w h).insertion), + run (W ∘ childDirection h) p (PointedTree.vac (h+1))⟫_ℂ) := by + have ht := TensorPackets.marked_limit (fun D => Tail D (h+1)) + (fun D => tensorState D (vac D h) (childGenerator D h)) (fockState (childDirection h)) + (fun D => excitation D h w) (creationVacuum (PointedTree.ordinary w h).insertion) + (excitation_tensor_limit h w) (compile p start) + have hn (D : ℕ) : run (tensorPulse D (childGenerator D h)) p + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h)))= + packet (tensorState D (vac D h) (childGenerator D h)) (compile p start) := by + have he : tensorState D (vac D h) (childGenerator D h) []=FiniteTensor.power D (vac D h) := by + simp [tensorState,generators] + rw [←he,←start_packet,run_packet _ _ (tensor_step D (vac D h) (childGenerator D h))] + have hf : run (W ∘ childDirection h) p (PointedTree.vac (h+1))= + packet (fockState (childDirection h)) (compile p start) := by + change run (W ∘ childDirection h) p (PointedTree.plusEmbedding (fockState (childDirection h) []))=_ + rw [←start_packet] + exact run_packet _ _ (fock_step _) p start + simpa only [hn,hf] using ht + + +def rootExcitation (D h : ℕ) (w : List PointedTree.Gate) : Space D (h+1) := + (split D (h+1)).symm (PointedTree.plusEmbedding (excitation D h w)) + + + +theorem root_shift_insertion_limit (h : ℕ) (w u : List PointedTree.Gate) : + Tendsto (fun D => ⟪rootExcitation D h w,insertion D (h+1) u⟫_ℂ) atTop + (𝓝 ⟪PointedTree.rootShift h (PointedTree.ordinary w h).insertion, + (PointedTree.ordinary u (h+1)).insertion⟫_ℂ) := by + have ht := excitation_program_limit h w (insertionProgram u) + have hn (D : ℕ) : ⟪rootExcitation D h w,insertion D (h+1) u⟫_ℂ= + ⟪PointedTree.plusEmbedding (excitation D h w), + run (tensorPulse D (childGenerator D h)) (insertionProgram u) + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h)))⟫_ℂ := by + rw [←(split D (h+1)).inner_map_map,rootExcitation,LinearIsometryEquiv.apply_symm_apply,split_insertion] + have hf : ⟪PointedTree.rootShift h (PointedTree.ordinary w h).insertion, + (PointedTree.ordinary u (h+1)).insertion⟫_ℂ= + ⟪PointedTree.plusEmbedding (creationVacuum (PointedTree.ordinary w h).insertion), + run (W ∘ childDirection h) (insertionProgram u) (PointedTree.vac (h+1))⟫_ℂ := by + change ⟪(PointedTree.rootShift h (PointedTree.ordinary w h).insertion : PointedTree.Level (h+1)), + ((PointedTree.ordinary u (h+1)).insertion : PointedTree.Level (h+1))⟫_ℂ=_ + rw [PointedTree.rootShift_coe,limiting_insertion] + simpa only [hn,hf] using ht + +end FiniteTree + + + +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +namespace FiniteTensor +variable {ι : Type*} [Fintype ι] [DecidableEq ι] [Nonempty ι] + +omit [DecidableEq ι] [Nonempty ι] in +theorem norm_mixedPower (D : ℕ) (v : Fin D → EuclideanSpace ℂ ι) : + ‖mixedPower D v‖=∏i,‖v i‖ := by + have hh := inner_mixedPower D v v + simp only [inner_self_eq_norm_sq_to_K] at hh + have hs : ‖mixedPower D v‖^2=(∏i,‖v i‖)^2 := by + norm_cast at hh + simpa only [Finset.prod_pow] using hh + nlinarith [norm_nonneg (mixedPower D v),Finset.prod_nonneg (fun i (_ : i∈Finset.univ) => norm_nonneg (v i))] + + + +def vacuumComplement (Ω : EuclideanSpace ℂ ι) : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι := + 1-rankOne ℂ Ω Ω + +omit [DecidableEq ι] [Nonempty ι] in +@[simp] theorem vacuumComplement_vac (Ω : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) : + vacuumComplement Ω Ω=0 := by + simp only [vacuumComplement,sub_apply,one_apply_eq_self,rankOne_apply, + inner_self_eq_norm_sq_to_K,hΩ] + norm_num + +omit [DecidableEq ι] in +theorem vacuumComplement_norm (Ω : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) : + ‖vacuumComplement Ω‖≤2 := by + calc + _ ≤ ‖(1 : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι)‖+‖rankOne ℂ Ω Ω‖ := norm_sub_le _ _ + _ ≤ 1+1 := by simp [hΩ] + _ = _ := by norm_num + + +def excitedSlot (D : ℕ) (Ω : EuclideanSpace ℂ ι) (j : Fin D) : + EuclideanSpace ℂ (Fin D → ι) →L[ℂ] EuclideanSpace ℂ (Fin D → ι) := + mixedOperator D (fun i => if i=j then vacuumComplement Ω else 1) + +omit [Nonempty ι] in +theorem excitedSlot_power_norm (D : ℕ) (Ω v : EuclideanSpace ℂ ι) (hv : ‖v‖=1) (j : Fin D) : + ‖excitedSlot D Ω j (power D v)‖=‖vacuumComplement Ω v‖ := by + change ‖mixedOperator D _ (mixedPower D (fun _ => v))‖=_ + rw [mixedOperator_apply,norm_mixedPower] + have he (i : Fin D) : ‖(if i=j then vacuumComplement Ω else 1) v‖= + if i=j then ‖vacuumComplement Ω v‖ else 1 := by + split_ifs <;> simp_all only [one_apply_eq_self] + simp_rw [he] + simp only [Finset.prod_ite_eq',Finset.mem_univ,ite_true] + +theorem excitedSlot_power_bound (D : ℕ) (Ω v : EuclideanSpace ℂ ι) + (hΩ : ‖Ω‖=1) (hv : ‖v‖=1) (j : Fin D) : + ‖excitedSlot D Ω j (power D v)‖≤2*‖v-Ω‖ := by + rw [excitedSlot_power_norm D Ω v hv j] + have he : vacuumComplement Ω v=vacuumComplement Ω (v-Ω) := by + rw [map_sub,vacuumComplement_vac Ω hΩ,sub_zero] + rw [he] + exact ((vacuumComplement Ω).le_opNorm _).trans + (mul_le_mul_of_nonneg_right (vacuumComplement_norm Ω hΩ) (norm_nonneg _)) + +end FiniteTensor + + + +open scoped InnerProductSpace Topology BigOperators +namespace QuantumCLT +variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] [NormOneClass A] [CompleteSpace A] + + + +omit [NormOneClass A] [CompleteSpace A] in +theorem JetBound.first_bound {C : ℝ} (hC : 0≤C) + {f : ℝ → A} {a b : A} (hf : JetBound C f a b) {r : ℝ} (hr : |r|≤1) : + ‖f r-1‖≤3*C*|r| := by + have hs : |r|^2≤|r| := by nlinarith [abs_nonneg r] + have hc : |r|^3≤|r| := by + calc + |r|^3=|r|^2*|r| := by ring + _ ≤ |r| * |r| := mul_le_mul_of_nonneg_right hs (abs_nonneg r) + _ ≤ |r| := by nlinarith [abs_nonneg r] + calc + _ ≤ ‖f r-1-(r:ℂ) • a-((r:ℂ)^2) • b‖+ + ‖(r:ℂ) • a‖+‖((r:ℂ)^2) • b‖ := by + have he : f r-1=(f r-1-(r:ℂ) • a-((r:ℂ)^2) • b)+(r:ℂ) • a+((r:ℂ)^2) • b := by abel + conv_lhs => rw [he] + exact (norm_add_le _ _).trans (add_le_add (norm_add_le _ _) le_rfl) + _ ≤ C*|r|^3+|r| * C+|r|^2*C := by + simp only [norm_smul,norm_pow,Complex.norm_real,Real.norm_eq_abs] + gcongr + · exact hf.2.2 r hr + · exact hf.1 + · exact hf.2.1 + _ ≤ 3*C*|r| := by nlinarith [mul_le_mul_of_nonneg_left hs hC,mul_le_mul_of_nonneg_left hc hC] + +end QuantumCLT + +namespace FiniteTree +open QuantumCLT RootTensorCLT + +def wordBound (l : List Label) : ℝ := + orderedBound (l.map (fun i => |i.2|)).sum l.length + +theorem wordBound_nonneg (l : List Label) : 0≤wordBound l := + orderedBound_nonneg (List.sum_nonneg (by intro x hx; obtain ⟨i,hi,rfl⟩ := List.mem_map.mp hx; exact abs_nonneg _)) _ + +theorem child_word_unitary (D h : ℕ) (l : List Label) (r : ℝ) : + generators (l.map (childGenerator D h)) r ∈ unitary _ := by + induction l with + | nil => exact (unitary _).one_mem + | cons i l ih => + change NormedSpace.exp ((r:ℂ) • childGenerator D h i)* + generators (l.map (childGenerator D h)) r ∈ unitary _ + apply (unitary _).mul_mem _ ih + change NormedSpace.exp ((r:ℂ) • (ordinary D i.1 h).generator i.2) ∈ unitary _ + rw [generator_scaled] + exact (ordinary D i.1 h).exponential_unitary (r*i.2) + + + +theorem child_word_vacuum_bound (D h : ℕ) (hD : 0 |i.2|)).sum + have hL : 0≤L := List.sum_nonneg (by intro x hx; obtain ⟨i,hi,rfl⟩ := List.mem_map.mp hx; exact abs_nonneg _) + have hx : ∀X ∈ l.map (childGenerator D h),‖X‖≤L := by + intro X hX + obtain ⟨i,hi,rfl⟩ := List.mem_map.mp hX + rw [childGenerator,Even.norm_generator] + have hall : ∀j∈l.map (fun i => |i.2|),0≤j := by + intro j hj; obtain ⟨k,hk,rfl⟩ := List.mem_map.mp hj; exact abs_nonneg _ + exact List.single_le_sum hall _ (List.mem_map.mpr ⟨i,hi,rfl⟩) + let : CompleteSpace (Space D h) := PiLp.completeSpace 2 (fun _ : Index D h => ℂ) + let : CompleteSpace (Space D h →L[ℂ] Space D h) := ContinuousLinearMap.instCompleteSpace + have hj := generators_jetBound (l.map (childGenerator D h)) hL hx + have hb := hj.first_bound (orderedBound_nonneg hL _) (sqrt_inverse_bound D hD) + have ha : |(Real.sqrt (D:ℝ))⁻¹|=(Real.sqrt (D:ℝ))⁻¹ := abs_of_nonneg (by positivity) + calc + _ = ‖(generators (l.map (childGenerator D h)) (Real.sqrt (D:ℝ))⁻¹-1) (vac D h)‖ := rfl + _ ≤ ‖generators (l.map (childGenerator D h)) (Real.sqrt (D:ℝ))⁻¹-1‖*‖vac D h‖ := ContinuousLinearMap.le_opNorm _ _ + _ ≤ 3*wordBound l*(Real.sqrt (D:ℝ))⁻¹ := by + rw [norm_vac,mul_one] + simpa only [List.length_map,ha,wordBound,L] using hb + + theorem tensor_word_excited_bound (D h : ℕ) (hD : 0 A) (term s t)=term (A ∘ s) t := by + classical + ext i + simp only [diagonal_apply,term_apply,Function.comp_apply] + split_ifs + · exact map_smul A _ _ + · exact map_zero A + +theorem diagonal_constant_packet (s : List κ → H) (A : H →L[ℂ] H) + (ts : List (Term κ)) : + diagonal (fun _ => A) (packet s ts)=packet (A ∘ s) ts := by + induction ts with + | nil => exact map_zero _ + | cons t ts ih => simp only [packet_cons,map_add,diagonal_constant_term,ih] + + + +theorem packet_bound (s : List κ → H) (b : List κ → ℝ) (_ : ∀l,0≤b l) + (r : ℝ) (_ : 0≤r) (hs : ∀l,‖s l‖≤b l*r) (ts : List (Term κ)) : + ‖packet s ts‖≤(ts.map (fun t => ‖t.coeff‖*b t.history)).sum*r := by + induction ts with + | nil => simp + | cons t ts ih => + rw [packet_cons,List.map_cons,List.sum_cons,add_mul] + exact (norm_add_le _ _).trans (add_le_add + (by rw [norm_term]; exact (mul_le_mul_of_nonneg_left (hs t.history) (norm_nonneg _)).trans_eq (by ring)) ih) + +end TensorPackets + + + +open scoped InnerProductSpace BigOperators +namespace FiniteTree +open RootTensorCLT TensorPackets SpinOperators + + +def packetOccupationBound (ts : List (Term Label)) : ℝ := + (ts.map (fun t => ‖t.coeff‖*(6*wordBound t.history))).sum + +theorem packetOccupationBound_nonneg (ts : List (Term Label)) : + 0≤packetOccupationBound ts := by + apply List.sum_nonneg + intro x hx + obtain ⟨t,ht,rfl⟩ := List.mem_map.mp hx + exact mul_nonneg (norm_nonneg _) (mul_nonneg (by norm_num) (wordBound_nonneg _)) + +theorem packet_excited_bound (D h : ℕ) (hD : 0 FiniteTensor.excitedSlot D (vac D h) j) + (packet (tensorState D (vac D h) (childGenerator D h)) ts)‖≤ + packetOccupationBound ts*(Real.sqrt (D:ℝ))⁻¹ := by + rw [diagonal_constant_packet] + exact packet_bound _ (fun l => 6*wordBound l) (fun l => mul_nonneg (by norm_num) (wordBound_nonneg l)) + _ (by positivity) (fun l => by simpa only [Function.comp_apply,mul_assoc] using tensor_word_excited_bound D h hD l j) _ + + + +def rootSlot (D h : ℕ) (j : Fin D) : Space D (h+1) →L[ℂ] Space D (h+1) := + (split D (h+1)).symm.conjStarAlgEquiv + (TensorPackets.diagonal (fun _ => FiniteTensor.excitedSlot D (vac D h) j)) + +@[simp] theorem split_rootSlot (D h : ℕ) (j : Fin D) (x : Space D (h+1)) : + split D (h+1) (rootSlot D h j x)= + TensorPackets.diagonal (fun _ => FiniteTensor.excitedSlot D (vac D h) j) (split D (h+1) x) := by + simp only [rootSlot,LinearIsometryEquiv.conjStarAlgEquiv_apply_apply, + LinearIsometryEquiv.symm_symm,LinearIsometryEquiv.apply_symm_apply] + + + +def topOccupation (D h : ℕ) (x : Space D (h+1)) : ℝ := + ∑j : Fin D, ‖rootSlot D h j x‖^2 + +theorem topOccupation_nonneg (D h : ℕ) (x : Space D (h+1)) : + 0≤topOccupation D h x := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + +theorem insertion_packet (D h : ℕ) (w : List PointedTree.Gate) : + split D (h+1) (insertion D (h+1) w)= + packet (tensorState D (vac D h) (childGenerator D h)) (compile (insertionProgram w) start) := by + rw [split_insertion] + have he : tensorState D (vac D h) (childGenerator D h) []=FiniteTensor.power D (vac D h) := by + simp only [tensorState,QuantumCLT.generators,List.map_nil,List.prod_nil,one_apply_eq_self] + rw [←he,←start_packet] + exact run_packet _ _ (tensor_step D (vac D h) (childGenerator D h)) _ _ + +theorem insertion_slot_bound (D h : ℕ) (hD : 0 rfl + +theorem compatible_mixer (n : ℕ) (t : ℝ) : Compatible (mixer n t) (mixer (n+1) t) := by + intro x + cases n <;> exact spinMap_root _ _ _ + +theorem compatible_cost (n : ℕ) (d : Mode n) (e : Mode (n+1)) + (hd : (symmetry n).centered d=-d) (he : (symmetry (n+1)).centered e=-e) + (h : centeredMap (empty n) d=e) : Compatible (cost n d hd) (cost (n+1) e he) := by + intro x + change (empty (n+1)).toLinearIsometry (WZ d x)=WZ e ((empty (n+1)).toLinearIsometry x) + rw [cost_empty,h] + +end EvenUnitary + + + +inductive Gate + | mixer (beta : ℝ) + | cost (gamma : ℝ) + + +def ordinary : List Gate → (n : ℕ) → EvenUnitary n + | [], n => EvenUnitary.ident n + | Gate.mixer beta :: w, n => (ordinary w n).followedBy (EvenUnitary.mixer n beta) + | Gate.cost gamma :: w, 0 => ordinary w 0 + | Gate.cost gamma :: w, n+1 => + (ordinary w (n+1)).followedBy + (EvenUnitary.cost n ((-(gamma:ℂ)) • (ordinary w n).insertion) (by + rw [map_smul,EvenUnitary.insertion_odd,smul_neg])) + + +theorem ordinary_compatible (w : List Gate) (n : ℕ) (hn : w.length ≤ n) : + EvenUnitary.Compatible (ordinary w n) (ordinary w (n+1)) := by + induction w generalizing n with + | nil => exact EvenUnitary.compatible_ident n + | cons g w ih => + cases g with + | mixer beta => + exact (ih n (by simpa using le_trans (Nat.le_succ w.length) hn)).followedBy + (EvenUnitary.compatible_mixer n beta) + | cost gamma => + cases n with + | zero => simp at hn + | succ n => + have hn' : w.length ≤ n := by simpa using hn + apply (ih (n+1) (hn'.trans (Nat.le_succ n))).followedBy + apply EvenUnitary.compatible_cost + rw [map_smul,(ih n hn').insertion] + + +theorem ordinary_insertion_empty (w : List Gate) (n : ℕ) (hn : w.length ≤ n) : + centeredMap (empty n) (ordinary w n).insertion=(ordinary w (n+1)).insertion := + (ordinary_compatible w n hn).insertion + +end PointedTree + +namespace CoherentFock +open Complex +variable {E F : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + [SeminormedAddCommGroup F] [InnerProductSpace ℂ F] + +@[simp] theorem Gamma_expVector (T : E →ₗᵢ[ℂ] F) (d : E) : + Gamma T (expVector d)=expVector (T d) := by simp [expVector] + +@[simp] theorem Gamma_oneParticle (T : E →ₗᵢ[ℂ] F) (d : E) : + Gamma T (oneParticle d)=oneParticle (T d) := by + rw [oneParticle,map_smul,map_circleIntegral (Gamma T) (circleIntegrable_oneParticle_integrand d)] + simp only [map_smul,Gamma_expVector] + rfl + + + +def creationVacuum (d : E) : Space E := (-I) • oneParticle d + +def creationEmbedding : E →ₗᵢ[ℂ] Space E where + toFun := creationVacuum + map_add' x y := by simp [creationVacuum,oneParticle_add,smul_add] + map_smul' z x := by + change (-I) • oneParticleEmbedding (z • x)=z • ((-I) • oneParticleEmbedding x) + rw [map_smul,smul_comm] + norm_map' d := by simp [creationVacuum,norm_smul] + +@[simp] theorem norm_creationVacuum (d : E) : ‖creationVacuum d‖=‖d‖ := creationEmbedding.norm_map _ + +@[simp] theorem creationVacuum_orthogonal (d : E) : + ⟪coherent 0,creationVacuum d⟫_ℂ=0 := by simp [creationVacuum] + +@[simp] theorem Gamma_creationVacuum (T : E →ₗᵢ[ℂ] F) (d : E) : + Gamma T (creationVacuum d)=creationVacuum (T d) := by simp [creationVacuum] +end CoherentFock + +namespace PointedTree +open CoherentFock +variable {H K : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + [NormedAddCommGroup K] [InnerProductSpace ℂ K] + + +def plusEmbedding : H →ₗᵢ[ℂ] SpinOperators.Double H where + toFun x := WithLp.toLp 2 (fun _ => (((Real.sqrt 2)⁻¹:ℝ):ℂ) • x) + map_add' x y := by ext i; simp [smul_add] + map_smul' z x := by ext i; simp [smul_comm z] + norm_map' x := by + change ‖WithLp.toLp 2 (fun _ : Fin 2 => (((Real.sqrt 2)⁻¹:ℝ):ℂ) • x)‖=‖x‖ + have hs : Real.sqrt 2^2=2 := Real.sq_sqrt (by norm_num) + have he : ‖WithLp.toLp 2 (fun _ : Fin 2 => (((Real.sqrt 2)⁻¹:ℝ):ℂ) • x)‖^2=‖x‖^2 := by + rw [PiLp.norm_sq_eq_of_L2] + change (∑ _:Fin 2, ‖(((Real.sqrt 2)⁻¹:ℝ):ℂ) • x‖^2)=_ + simp only [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_inv, + abs_of_nonneg (Real.sqrt_nonneg 2),mul_pow,inv_pow,hs,Fin.sum_univ_two] + ring + nlinarith [norm_nonneg x,norm_nonneg (WithLp.toLp 2 (fun _:Fin 2 => (((Real.sqrt 2)⁻¹:ℝ):ℂ) • x))] + +@[simp] theorem plusEmbedding_apply (x : H) (i : Fin 2) : + plusEmbedding x i = (((Real.sqrt 2)⁻¹:ℝ):ℂ) • x := rfl + +@[simp] theorem plusEmbedding_coherent_zero : + plusEmbedding (coherent (0:H))=vacuum H := rfl + +@[simp] theorem spinMap_plusEmbedding (T : H →ₗᵢ[ℂ] K) (x : H) : + spinMap T (plusEmbedding x)=plusEmbedding (T x) := by ext i; simp + + +def rootShift (n : ℕ) : Mode n →ₗᵢ[ℂ] Mode (n+1) where + toFun d := ⟨plusEmbedding (creationVacuum d),by + rw [mem_centered] + change ⟪plusEmbedding (coherent (0:Mode n)),plusEmbedding (creationVacuum d)⟫_ℂ=0 + exact (plusEmbedding.inner_map_map (coherent (0:Mode n)) (creationVacuum d)).trans + (creationVacuum_orthogonal d)⟩ + map_add' d e := by + apply Subtype.ext + change plusEmbedding (creationEmbedding (d+e))=plusEmbedding (creationEmbedding d)+plusEmbedding (creationEmbedding e) + simp only [map_add] + map_smul' z d := by + apply Subtype.ext + change plusEmbedding (creationEmbedding (z • d))=z • plusEmbedding (creationEmbedding d) + simp only [map_smul] + norm_map' d := by exact (plusEmbedding.norm_map _).trans (norm_creationVacuum d) + +@[simp] theorem rootShift_coe (n : ℕ) (d : Mode n) : + (rootShift n d : Level (n+1))=plusEmbedding (creationVacuum d) := rfl + + +@[simp] theorem rootShift_empty (n : ℕ) (d : Mode n) : + centeredMap (empty (n+1)) (rootShift n d)=rootShift (n+1) (centeredMap (empty n) d) := by + apply Subtype.ext + change spinMap (gammaEmbedding (centeredMap (empty n))) (plusEmbedding (creationVacuum d))= + plusEmbedding (creationVacuum (centeredMap (empty n) d)) + rw [spinMap_plusEmbedding] + change plusEmbedding (Gamma (centeredMap (empty n)) (creationVacuum d))=_ + rw [Gamma_creationVacuum] + + + +def treeEnergy (n : ℕ) (d : Mode n) : ℝ := + (⟪centeredMap (empty n) d,rootShift n d⟫_ℂ).re + +@[simp] theorem treeEnergy_empty (n : ℕ) (d : Mode n) : + treeEnergy (n+1) (centeredMap (empty n) d)=treeEnergy n d := by + unfold treeEnergy + rw [← rootShift_empty,(centeredMap (empty (n+1))).inner_map_map] + + +theorem treeEnergy_sub_le (n : ℕ) (d e : Mode n) : + |treeEnergy n d-treeEnergy n e| ≤ (‖d‖+‖e‖)*‖d-e‖ := by + have he : ⟪centeredMap (empty n) d,rootShift n d⟫_ℂ- + ⟪centeredMap (empty n) e,rootShift n e⟫_ℂ= + ⟪centeredMap (empty n) (d-e),rootShift n d⟫_ℂ+ + ⟪centeredMap (empty n) e,rootShift n (d-e)⟫_ℂ := by + simp only [map_sub,inner_sub_left,inner_sub_right] + ring + change |(⟪centeredMap (empty n) d,rootShift n d⟫_ℂ).re- + (⟪centeredMap (empty n) e,rootShift n e⟫_ℂ).re| ≤ _ + rw [← Complex.sub_re,he] + calc + _ ≤ ‖⟪centeredMap (empty n) (d-e),rootShift n d⟫_ℂ+ + ⟪centeredMap (empty n) e,rootShift n (d-e)⟫_ℂ‖ := Complex.abs_re_le_norm _ + _ ≤ ‖⟪centeredMap (empty n) (d-e),rootShift n d⟫_ℂ‖+ + ‖⟪centeredMap (empty n) e,rootShift n (d-e)⟫_ℂ‖ := norm_add_le _ _ + _ ≤ ‖d-e‖*‖d‖+‖e‖*‖d-e‖ := by + simpa only [LinearIsometry.norm_map] using add_le_add + (norm_inner_le_norm (𝕜 := ℂ) (centeredMap (empty n) (d-e)) (rootShift n d)) + (norm_inner_le_norm (𝕜 := ℂ) (centeredMap (empty n) e) (rootShift n (d-e))) + _ = _ := by ring + +end PointedTree + +namespace ProbeProduct +variable {ι H X : Type*} [NormedAddCommGroup H] [NormedSpace ℂ H] + +def coreAct (S : ι → X → X) : List ι → X → X + | [],x => x + | j::l,x => S j (coreAct S l x) + +@[simp] theorem coreAct_nil (S : ι → X → X) (x : X) : coreAct S [] x=x := rfl +@[simp] theorem coreAct_cons (S : ι → X → X) (j : ι) (l : List ι) (x : X) : + coreAct S (j::l) x=S j (coreAct S l x) := rfl + +theorem coreAct_bound (S : ι → X → X) (G : X → ℝ) (l : List ι) (C : ℝ) + (hC : 0 ≤ C) (hS : ∀ j ∈ l, ∀x, G (S j x) ≤ C*G x) (x : X) : + G (coreAct S l x) ≤ C^l.length*G x := by + induction l with + | nil => simp + | cons j l ih => + have hi := ih (fun k hk => hS k (by simp [hk])) + calc + _ ≤ C*G (coreAct S l x) := hS j (by simp) _ + _ ≤ C*(C^l.length*G x) := mul_le_mul_of_nonneg_left hi hC + _ = _ := by simp only [List.length_cons,pow_succ]; ring + + + +theorem core_perturbation_bound (T : ι → H →L[ℂ] H) (S : ι → X → X) + (c : X → H) (G : X → ℝ) (hG : ∀x, 0 ≤ G x) (l : List ι) (C ε : ℝ) + (hC : 1 ≤ C) (hε : 0 ≤ ε) + (hT : ∀ j ∈ l, ∀x, ‖T j x‖ ≤ ‖x‖) + (hS : ∀ j ∈ l, ∀x, G (S j x) ≤ C*G x) + (hE : ∀ j ∈ l, ∀x, ‖T j (c x)-c (S j x)‖ ≤ ε*G x) (x : X) : + ‖act T l (c x)-c (coreAct S l x)‖ ≤ ε*l.length*C^l.length*G x := by + induction l with + | nil => simp + | cons j l ih => + have hTl : ∀ k ∈ l, ∀z, ‖T k z‖ ≤ ‖z‖ := fun k hk => hT k (by simp [hk]) + have hSl : ∀ k ∈ l, ∀z, G (S k z) ≤ C*G z := fun k hk => hS k (by simp [hk]) + have hEl : ∀ k ∈ l, ∀z, ‖T k (c z)-c (S k z)‖ ≤ ε*G z := fun k hk => hE k (by simp [hk]) + have hi := ih hTl hSl hEl + have hb := coreAct_bound S G l C (by linarith) hSl x + have he : act T (j::l) (c x)-c (coreAct S (j::l) x)= + T j (act T l (c x)-c (coreAct S l x))+ + (T j (c (coreAct S l x))-c (S j (coreAct S l x))) := by + simp only [act_cons,coreAct_cons,map_sub] + abel + rw [he] + calc + _ ≤ ‖T j (act T l (c x)-c (coreAct S l x))‖+ + ‖T j (c (coreAct S l x))-c (S j (coreAct S l x))‖ := norm_add_le _ _ + _ ≤ ε*l.length*C^l.length*G x+ε*G (coreAct S l x) := + add_le_add ((hT j (by simp) _).trans hi) (hE j (by simp) _) + _ ≤ ε*l.length*C^l.length*G x+ε*(C^l.length*G x) := by gcongr + _ = ε*(l.length+1)*C^l.length*G x := by ring + _ ≤ ε*(l.length+1)*C^(l.length+1)*G x := by + apply mul_le_mul_of_nonneg_right _ (hG x) + exact mul_le_mul_of_nonneg_left (pow_le_pow_right₀ hC (Nat.le_succ _)) + (mul_nonneg hε (by positivity)) + _ = _ := by simp + +end ProbeProduct + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +def prePhaseZ (θ : ℝ) (x : PreSpin E) : PreSpin E := + fun i => Complex.exp (((if i=0 then θ else -θ : ℝ):ℂ)*Complex.I) • x i + +@[simp] theorem spinCoe_prePhaseZ (θ : ℝ) (x : PreSpin E) : + spinCoe (prePhaseZ θ x)=phaseZ θ (spinCoe x) := by + ext i + simp only [spinCoe_apply,prePhaseZ,phaseZ_apply,UniformSpace.Completion.coe_smul] + +omit [InnerProductSpace ℂ E] in +@[simp] theorem spinBound_prePhaseZ (θ : ℝ) (x : PreSpin E) : + spinBound (prePhaseZ θ x)=spinBound x := by + simp only [spinBound,prePhaseZ,secondTailBound_smul,Complex.norm_exp_ofReal_mul_I,one_mul] + +def preProbePhase (A : Matrix (Fin 2) (Fin 2) ℂ) (θ : ℝ) (x : PreSpin E) : PreSpin E := + preRoot A.conjTranspose (prePhaseZ θ (preRoot A x)) + +@[simp] theorem spinCoe_preProbePhase (A : Matrix (Fin 2) (Fin 2) ℂ) (θ : ℝ) (x : PreSpin E) : + spinCoe (preProbePhase A θ x)=probePhase A θ (spinCoe x) := by + simp only [preProbePhase,spinCoe_preRoot,spinCoe_prePhaseZ,probePhase_apply] + +omit [InnerProductSpace ℂ E] in +theorem spinBound_preProbePhase (A : Matrix (Fin 2) (Fin 2) ℂ) (θ : ℝ) (x : PreSpin E) : + spinBound (preProbePhase A θ x) ≤ matrixMass A.conjTranspose*matrixMass A*spinBound x := by + unfold preProbePhase + calc + _ ≤ matrixMass A.conjTranspose*spinBound (prePhaseZ θ (preRoot A x)) := spinBound_preRoot _ _ + _ = matrixMass A.conjTranspose*spinBound (preRoot A x) := by rw [spinBound_prePhaseZ] + _ ≤ matrixMass A.conjTranspose*(matrixMass A*spinBound x) := + mul_le_mul_of_nonneg_left (spinBound_preRoot _ _) (matrixMass_nonneg _) + _ = _ := by ring + +theorem norm_probe_sub_le (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (d : E) (x : PreSpin E) : + ‖probe A d (spinCoe x)-spinCoe x‖ ≤ (‖d‖^2+‖d‖)*matrixMass A*spinBound x := by + have ht := norm_add_le (probe A d (spinCoe x)-spinCoe x-Complex.I • probeField A d x) + (Complex.I • probeField A d x) + rw [sub_add_cancel] at ht + have h1 := probe_taylor A hA d x + have h2 := norm_probeField_le A hA d x + simp only [norm_smul,Complex.norm_I,one_mul] at ht + nlinarith + +theorem coreAct_preProbePhase {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (θ : ι → ℝ) (x : PreSpin E) : + spinCoe (ProbeProduct.coreAct (fun j => preProbePhase (A j) (θ j)) l x)= + ProbeProduct.act (fun j => probePhase (A j) (θ j)) l (spinCoe x) := by + induction l with + | nil => rfl + | cons j l ih => simp only [ProbeProduct.coreAct_cons,ProbeProduct.act_cons,spinCoe_preProbePhase,ih] + + + +theorem centered_product_rotation_bound {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (D : ι → E) (e : E) (L M : ℝ) + (hL : 0 ≤ L) (hM : 1 ≤ M) (hA : ∀ j ∈ l, A j ∈ unitary _) + (hD : ∀ j ∈ l, ‖D j‖ ≤ L) + (hMass : ∀ j ∈ l, matrixMass (A j) ≤ M) + (hMassStar : ∀ j ∈ l, matrixMass (A j).conjTranspose ≤ M) (x : PreSpin E) : + ‖spinW (-e) (ProbeProduct.act (fun j => probe (A j) (D j)) l (spinW e (spinCoe x)))- + ProbeProduct.act (fun j => probePhase (A j) (-2*(⟪D j,e⟫_ℂ).im)) l (spinCoe x)‖ ≤ + ((L^2+L)*M)*l.length*(M^2)^l.length*spinBound x := by + rw [← center_probe_product,← coreAct_preProbePhase] + apply ProbeProduct.core_perturbation_bound _ _ spinCoe spinBound spinBound_nonneg l (M^2) ((L^2+L)*M) + · nlinarith + · positivity + · intro j hj z + simp only [ContinuousLinearMap.comp_apply,norm_spinW,norm_probe _ (hA j hj)] + rfl + · intro j hj z + calc + _ ≤ matrixMass (A j).conjTranspose*matrixMass (A j)*spinBound z := spinBound_preProbePhase _ _ _ + _ ≤ M*M*spinBound z := by + gcongr + · exact spinBound_nonneg _ + · exact matrixMass_nonneg _ + · exact hMassStar j hj + · exact hMass j hj + _ = _ := by ring + · intro j hj z + simp only [ContinuousLinearMap.comp_apply,spinCoe_preProbePhase] + rw [centered_toggled_probe _ (hA j hj),← map_sub,norm_probePhase _ (hA j hj)] + calc + _ ≤ (‖D j‖^2+‖D j‖)*matrixMass (A j)*spinBound z := norm_probe_sub_le _ (hA j hj) _ _ + _ ≤ ((L^2+L)*M)*spinBound z := by + gcongr + · exact spinBound_nonneg _ + · exact matrixMass_nonneg _ + · exact hD j hj + · exact hD j hj + · exact hMass j hj + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem phaseZ_add (θ φ : ℝ) (x : SpinSpace E) : + phaseZ θ (phaseZ φ x)=phaseZ (θ+φ) x := by + ext i + simp only [phaseZ_apply,smul_smul] + congr 1 + rw [← Complex.exp_add] + congr 1 + split_ifs <;> push_cast <;> ring + +theorem phaseZ_sub_phaseZ_le (θ φ : ℝ) (x : SpinSpace E) : + ‖phaseZ θ x-phaseZ φ x‖ ≤ |θ-φ| *‖x‖ := by + have he : phaseZ θ x-phaseZ φ x=phaseZ φ (phaseZ (θ-φ) x-x) := by + rw [map_sub,phaseZ_add,show φ+(θ-φ)=θ by ring] + rw [he,norm_phaseZ] + exact phaseZ_sub_le _ _ + +theorem probePhase_sub_probePhase_le (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (θ φ : ℝ) (x : SpinSpace E) : + ‖probePhase A θ x-probePhase A φ x‖ ≤ |θ-φ| *‖x‖ := by + simp only [probePhase_apply,← map_sub,SpinOperators.norm_act (root_adjoint_unitary A hA)] + simpa only [SpinOperators.norm_act hA] using phaseZ_sub_phaseZ_le θ φ (SpinOperators.act A x) + + + +theorem rotation_product_bound {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (θ φ : ι → ℝ) (α : ℝ) + (hα : 0 ≤ α) (hA : ∀ j ∈ l, A j ∈ unitary _) + (hp : ∀ j ∈ l, |θ j-φ j| ≤ α) (x : SpinSpace E) : + ‖ProbeProduct.act (fun j => probePhase (A j) (θ j)) l x- + ProbeProduct.act (fun j => probePhase (A j) (φ j)) l x‖ ≤ l.length*α*‖x‖ := by + apply ProbeProduct.perturbation_bound _ _ l α hα + · intro j hj z + exact (norm_probePhase _ (hA j hj) _ z).le + · intro j hj z + exact (norm_probePhase _ (hA j hj) _ z).le + · intro j hj z + exact (probePhase_sub_probePhase_le _ (hA j hj) _ _ z).trans + (mul_le_mul_of_nonneg_right (hp j hj) (norm_nonneg z)) + + + +theorem special_product_bound {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (D : ι → E) (e : E) (φ : ι → ℝ) + (L M α : ℝ) (hL : 0 ≤ L) (hM : 1 ≤ M) (hα : 0 ≤ α) + (hA : ∀ j ∈ l, A j ∈ unitary _) (hD : ∀ j ∈ l, ‖D j‖ ≤ L) + (hMass : ∀ j ∈ l, matrixMass (A j) ≤ M) + (hMassStar : ∀ j ∈ l, matrixMass (A j).conjTranspose ≤ M) + (hp : ∀ j ∈ l, |(-2*(⟪D j,e⟫_ℂ).im)-φ j| ≤ α) (x : PreSpin E) : + ‖spinW (-e) (ProbeProduct.act (fun j => probe (A j) (D j)) l (spinW e (spinCoe x)))- + ProbeProduct.act (fun j => probePhase (A j) (φ j)) l (spinCoe x)‖ ≤ + ((L^2+L)*M)*l.length*(M^2)^l.length*spinBound x+l.length*α*‖spinCoe x‖ := by + have h1 := centered_product_rotation_bound l A D e L M hL hM hA hD hMass hMassStar x + have h2 := rotation_product_bound l A (fun j => -2*(⟪D j,e⟫_ℂ).im) φ α hα hA hp (spinCoe x) + have ht := norm_sub_le_norm_sub_add_norm_sub + (spinW (-e) (ProbeProduct.act (fun j => probe (A j) (D j)) l (spinW e (spinCoe x)))) + (ProbeProduct.act (fun j => probePhase (A j) (-2*(⟪D j,e⟫_ℂ).im)) l (spinCoe x)) + (ProbeProduct.act (fun j => probePhase (A j) (φ j)) l (spinCoe x)) + linarith + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem scaled_translated_spin_bound (d e : E) (x y : PreSpin E) (B δ R : ℝ) + (hx : SpinRadiusLE x B) (hy : SpinRadiusLE y B) (hδ : 0 < δ) + (hsep : δ ≤ ‖d-e‖) (hR : 1 ≤ R) (hB : 4*B ≤ R*δ) : + ‖⟪spinW (R • d) (spinCoe x),spinW (R • e) (spinCoe y)⟫_ℂ‖ ≤ + spinMass x*spinMass y*Real.exp (-(δ^2/8)*R) := by + rw [PiLp.inner_apply] + calc + _ ≤ ∑ i : Fin 2, ‖⟪W (R • d) (↑(x i)),W (R • e) (↑(y i))⟫_ℂ‖ := norm_sum_le _ _ + _ ≤ ∑ i : Fin 2, mass (x i)*mass (y i)*Real.exp (-(δ^2/8)*R) := by + exact Finset.sum_le_sum (fun i _ => scaled_translated_pre_bound d e (x i) (y i) B δ R + (hx i) (hy i) hδ hsep hR hB) + _ ≤ ∑ i : Fin 2, mass (x i)*spinMass y*Real.exp (-(δ^2/8)*R) := by + apply Finset.sum_le_sum + intro i hi + gcongr + · exact mass_nonneg _ + · exact mass_le_spinMass _ _ + _ = _ := by simp only [spinMass,Finset.sum_mul] + + + +theorem scaled_spin_matrix_bound (P : Matrix (Fin 2) (Fin 2) ℂ) (d e : E) + (x y : PreSpin E) (B δ R : ℝ) + (hx : SpinRadiusLE x B) (hy : SpinRadiusLE y B) (hδ : 0 < δ) + (hsep : δ ≤ ‖d-e‖) (hR : 1 ≤ R) (hB : 4*B ≤ R*δ) : + ‖⟪SpinOperators.act P (spinW (R • d) (spinCoe x)),spinW (R • e) (spinCoe y)⟫_ℂ‖ ≤ + matrixMass P*spinMass x*spinMass y*Real.exp (-(δ^2/8)*R) := by + rw [← spinW_root,← spinCoe_preRoot] + apply (scaled_translated_spin_bound d e (preRoot P x) y B δ R + (hx.preRoot P) hy hδ hsep hR hB).trans + gcongr + · exact spinMass_nonneg _ + · exact spinMass_preRoot _ _ + + + +theorem rapid_decay_spin_matrix {α : Type*} {l : Filter α} + (R : α → ℝ) (d e : α → E) (x y : α → PreSpin E) + (P : α → Matrix (Fin 2) (Fin 2) ℂ) (hR : Tendsto R l atTop) + (B A C δ : ℝ) (hA : 0 ≤ A) (hC : 0 ≤ C) (hδ : 0 < δ) + (hx : ∀ᶠ a in l, SpinRadiusLE (x a) B ∧ spinMass (x a) ≤ A) + (hy : ∀ᶠ a in l, SpinRadiusLE (y a) B ∧ spinMass (y a) ≤ A) + (hP : ∀ᶠ a in l, matrixMass (P a) ≤ C) + (hsep : ∀ᶠ a in l, δ ≤ ‖d a-e a‖) (M : ℕ) : + Tendsto (fun a => (R a)^M * + ‖⟪SpinOperators.act (P a) (spinW (R a • d a) (spinCoe (x a))), + spinW (R a • e a) (spinCoe (y a))⟫_ℂ‖) l (𝓝 0) := by + have hR1 : ∀ᶠ a in l, 1 ≤ R a := hR.eventually (eventually_ge_atTop 1) + have hRB : ∀ᶠ a in l, 4*B ≤ R a*δ := by + filter_upwards [hR.eventually (eventually_ge_atTop (4*B/δ))] with a ha + exact (div_le_iff₀ hδ).mp ha + have he : Tendsto (fun t : ℝ => t^M*Real.exp (-(δ^2/8)*t)) atTop (𝓝 0) := by + simpa only [Real.rpow_natCast] using + tendsto_rpow_mul_exp_neg_mul_atTop_nhds_zero (M:ℝ) (δ^2/8) (by positivity) + have he' := (he.comp hR).const_mul (C*A*A) + simp only [mul_zero] at he' + apply squeeze_zero' _ _ he' + · filter_upwards [hR1] with a ha + exact mul_nonneg (pow_nonneg (by linarith) _) (norm_nonneg _) + · filter_upwards [hR1,hRB,hx,hy,hP,hsep] with a ha hba hxa hya hpa hsa + have hb := scaled_spin_matrix_bound (P a) (d a) (e a) (x a) (y a) B δ (R a) + hxa.1 hya.1 hδ hsa ha hba + calc + _ ≤ (R a)^M*(matrixMass (P a)*spinMass (x a)*spinMass (y a)*Real.exp (-(δ^2/8)*R a)) := + mul_le_mul_of_nonneg_left hb (pow_nonneg (by linarith) _) + _ ≤ (R a)^M*(C*A*A*Real.exp (-(δ^2/8)*R a)) := by + gcongr + · exact spinMass_nonneg _ + · exact spinMass_nonneg _ + · exact hxa.2 + · exact hya.2 + _ = _ := by dsimp only [Function.comp_def]; ring + +end CoherentFock + +open scoped InnerProductSpace ComplexConjugate +namespace PacketGeometry +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℂ H] + + +theorem symmetric_diagonal_im (P : H →ₗ[ℂ] H) + (hP : ∀ x y, ⟪P x,y⟫_ℂ=⟪x,P y⟫_ℂ) (x : H) : + (⟪P x,x⟫_ℂ).im=0 := by + have h := congrArg Complex.im (hP x x) + have hc := congrArg Complex.im (inner_conj_symm x (P x)) + simp only [Complex.conj_im] at hc + linarith + + + +theorem huge_center_imaginary (P : H →ₗ[ℂ] H) + (hP : ∀ x y, ⟪P x,y⟫_ℂ=⟪x,P y⟫_ℂ) + (hPN : ∀x, ‖P x‖ ≤ ‖x‖) (xp xm s z : H) : + |(⟪P (xp+xm+s),xp-xm+z⟫_ℂ).im| ≤ + 2*‖⟪P xp,xm⟫_ℂ‖ + ‖⟪P xp,z⟫_ℂ‖ + ‖⟪P xm,z⟫_ℂ‖ + + ‖⟪P s,xp⟫_ℂ‖ + ‖⟪P s,xm⟫_ℂ‖ + ‖s‖*‖z‖ := by + have hd1 := symmetric_diagonal_im P hP xp + have hd2 := symmetric_diagonal_im P hP xm + have hc : ⟪P xm,xp⟫_ℂ=conj ⟪P xp,xm⟫_ℂ := by + rw [hP] + exact (inner_conj_symm _ _).symm + have he : (⟪P (xp+xm+s),xp-xm+z⟫_ℂ).im = + (-⟪P xp,xm⟫_ℂ+⟪P xp,z⟫_ℂ+⟪P xm,xp⟫_ℂ+ + ⟪P xm,z⟫_ℂ+⟪P s,xp⟫_ℂ-⟪P s,xm⟫_ℂ+⟪P s,z⟫_ℂ).im := by + simp only [map_add,inner_add_left,inner_add_right,inner_sub_right, + Complex.add_im,Complex.sub_im,Complex.neg_im,hd1,hd2] + ring + rw [he] + have h0 := Complex.abs_im_le_norm + (-⟪P xp,xm⟫_ℂ+⟪P xp,z⟫_ℂ+⟪P xm,xp⟫_ℂ+ + ⟪P xm,z⟫_ℂ+⟪P s,xp⟫_ℂ-⟪P s,xm⟫_ℂ+⟪P s,z⟫_ℂ) + have h1 := norm_add_le + (-⟪P xp,xm⟫_ℂ+⟪P xp,z⟫_ℂ+⟪P xm,xp⟫_ℂ+ + ⟪P xm,z⟫_ℂ+⟪P s,xp⟫_ℂ-⟪P s,xm⟫_ℂ) ⟪P s,z⟫_ℂ + have h2 := norm_sub_le (-⟪P xp,xm⟫_ℂ+⟪P xp,z⟫_ℂ+⟪P xm,xp⟫_ℂ+ + ⟪P xm,z⟫_ℂ+⟪P s,xp⟫_ℂ) ⟪P s,xm⟫_ℂ + have h3 := norm_add_le (-⟪P xp,xm⟫_ℂ+⟪P xp,z⟫_ℂ+⟪P xm,xp⟫_ℂ+ + ⟪P xm,z⟫_ℂ) ⟪P s,xp⟫_ℂ + have h4 := norm_add_le (-⟪P xp,xm⟫_ℂ+⟪P xp,z⟫_ℂ+⟪P xm,xp⟫_ℂ) ⟪P xm,z⟫_ℂ + have h5 := norm_add_le (-⟪P xp,xm⟫_ℂ+⟪P xp,z⟫_ℂ) ⟪P xm,xp⟫_ℂ + have h6 := norm_add_le (-⟪P xp,xm⟫_ℂ) ⟪P xp,z⟫_ℂ + have h7 := (norm_inner_le_norm (𝕜 := ℂ) (P s) z).trans (mul_le_mul_of_nonneg_right (hPN s) (norm_nonneg z)) + rw [norm_neg] at h6 + have hcn : ‖⟪P xm,xp⟫_ℂ‖=‖⟪P xp,xm⟫_ℂ‖ := by rw [hc,Complex.norm_conj] + rw [hcn] at h5 + linarith + + + +theorem inner_remainder_bound (P : H →ₗ[ℂ] H) (hPN : ∀x, ‖P x‖ ≤ ‖x‖) + (x y ρ σ : H) (δ : ℝ) (hδ : 0 ≤ δ) + (hx : ‖x+ρ‖ ≤ 1) (hy : ‖y+σ‖ ≤ 1) (hρ : ‖ρ‖ ≤ δ) (hσ : ‖σ‖ ≤ δ) : + ‖⟪P (x+ρ),y+σ⟫_ℂ-⟪P x,y⟫_ℂ‖ ≤ δ*(2+δ) := by + have hxn : ‖x‖ ≤ 1+δ := by + have he : x=(x+ρ)-ρ := by abel + calc + ‖x‖ = ‖(x+ρ)-ρ‖ := congrArg norm he + _ ≤ ‖x+ρ‖+‖ρ‖ := norm_sub_le _ _ + _ ≤ 1+δ := add_le_add hx hρ + have he : ⟪P (x+ρ),y+σ⟫_ℂ-⟪P x,y⟫_ℂ = + ⟪P ρ,y+σ⟫_ℂ+⟪P x,σ⟫_ℂ := by + simp only [map_add,inner_add_left,inner_add_right] + ring + rw [he] + calc + _ ≤ ‖⟪P ρ,y+σ⟫_ℂ‖+‖⟪P x,σ⟫_ℂ‖ := norm_add_le _ _ + _ ≤ ‖ρ‖*‖y+σ‖+‖x‖*‖σ‖ := by + exact add_le_add ((norm_inner_le_norm (𝕜 := ℂ) _ _).trans + (mul_le_mul_of_nonneg_right (hPN _) (norm_nonneg _))) + ((norm_inner_le_norm (𝕜 := ℂ) _ _).trans + (mul_le_mul_of_nonneg_right (hPN _) (norm_nonneg _))) + _ ≤ δ*1+(1+δ)*δ := by gcongr + _ = _ := by ring + + + +theorem huge_imaginary_modulus (P : H →ₗ[ℂ] H) + (hP : ∀ x y, ⟪P x,y⟫_ℂ=⟪x,P y⟫_ℂ) + (hPN : ∀x, ‖P x‖ ≤ ‖x‖) (xp xm s z ρ σ : H) (δ ε a : ℝ) + (hδ : 0 ≤ δ) (ha : 0 ≤ a) + (hx : ‖xp+xm+s+ρ‖ ≤ 1) (hy : ‖xp-xm+z+σ‖ ≤ 1) + (hρ : ‖ρ‖ ≤ δ) (hσ : ‖σ‖ ≤ δ) (hs : ‖s‖ ≤ a) (hz : ‖z‖ ≤ a) + (h1 : ‖⟪P xp,xm⟫_ℂ‖ ≤ ε) (h2 : ‖⟪P xp,z⟫_ℂ‖ ≤ ε) + (h3 : ‖⟪P xm,z⟫_ℂ‖ ≤ ε) (h4 : ‖⟪P s,xp⟫_ℂ‖ ≤ ε) + (h5 : ‖⟪P s,xm⟫_ℂ‖ ≤ ε) : + |(⟪P (xp+xm+s+ρ),xp-xm+z+σ⟫_ℂ).im| ≤ 6*ε+a^2+δ*(2+δ) := by + have hb := huge_center_imaginary P hP hPN xp xm s z + have hr := inner_remainder_bound P hPN (xp+xm+s) (xp-xm+z) ρ σ δ hδ hx hy hρ hσ + have hd := Complex.abs_im_le_norm + (⟪P (xp+xm+s+ρ),xp-xm+z+σ⟫_ℂ-⟪P (xp+xm+s),xp-xm+z⟫_ℂ) + simp only [Complex.sub_im] at hd + have ht := abs_add_le + ((⟪P (xp+xm+s+ρ),xp-xm+z+σ⟫_ℂ).im-(⟪P (xp+xm+s),xp-xm+z⟫_ℂ).im) + (⟪P (xp+xm+s),xp-xm+z⟫_ℂ).im + have hsz : ‖s‖*‖z‖ ≤ a*a := mul_le_mul hs hz (norm_nonneg _) ha + simp only [sub_add_cancel] at ht + nlinarith + +end PacketGeometry + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ContinuousTiltedMeanJoint.lean b/lean/OAI/Probability/ParisiFinite/ContinuousTiltedMeanJoint.lean new file mode 100644 index 0000000000000000000000000000000000000000..51e17108a18ba5a71ac4a1662abf52a4e00a2eb3 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ContinuousTiltedMeanJoint.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SpinTrace + +namespace OAI + +/-! Continuous Tilted Mean Joint. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +lemma continuous_tiltedMean_joint {L : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) (hg : Continuous g) {M : ℝ≥0} + (hM : ∀ x,|g x|≤M) (a : ℝ) : + Continuous (fun p : ℝ×ℝ => tiltedMean a p.1 f g p.2) := by + have hh := continuous_parameterTilt (S := ℝ×ℝ) + (f := fun _ => f) (g := fun _ => g) (x := Prod.snd) (c := Prod.fst) + (M := fun _ => (M:ℝ)) (fun _ => hf) + (hf.continuous.comp continuous_snd) (hg.comp continuous_snd) + continuous_snd continuous_fst continuous_const (fun _ => hM) a + simpa only [tiltedMean,expMoment,expMass,ambientTilt,ambientMoment,ambientMass, + smul_eq_mul,mul_comm] using hh + +lemma continuous_transform_val (f : SmoothField) (a : ℝ) : + Continuous (fun p : ℝ×ℝ => (f.transform a p.1).val p.2) := by + have hh := continuous_parameterStep (S := ℝ×ℝ) + (f := fun _ => f.val) (x := Prod.snd) (c := Prod.fst) + (fun _ => f.lipschitz) (f.continuousVal.comp continuous_snd) + continuous_snd continuous_fst a + simpa only [SmoothField.transform,step,ambientStep,smul_eq_mul,mul_comm] using hh + +lemma continuous_transform_d1 (f : SmoothField) (a : ℝ) : + Continuous (fun p : ℝ×ℝ => (f.transform a p.1).d1 p.2) := + continuous_tiltedMean_joint f.lipschitz f.continuousD1 f.normD1 a + +lemma continuous_transform_d2 (f : SmoothField) (a : ℝ) : + Continuous (fun p : ℝ×ℝ => (f.transform a p.1).d2 p.2) := by + exact (continuous_tiltedMean_joint f.lipschitz f.continuousD2 f.normD2 a).add + (((continuous_tiltedMean_joint f.lipschitz (f.continuousD1.pow 2) + (g := fun x => f.d1 x^2) (M := f.bound1^2) (sq_bound f.normD1) a).sub + ((continuous_transform_d1 f a).pow 2)).const_mul a) + +lemma continuous_fieldOnInterval_val (f : SmoothField) (a b : ℝ) : + Continuous (fun p : ℝ×ℝ => (fieldOnInterval f a b p.1).val p.2) := by + exact (continuous_transform_val f a).comp + (((continuous_const.sub continuous_fst).sqrt).prodMk continuous_snd) + +lemma continuous_fieldOnInterval_d1 (f : SmoothField) (a b : ℝ) : + Continuous (fun p : ℝ×ℝ => (fieldOnInterval f a b p.1).d1 p.2) := by + exact (continuous_transform_d1 f a).comp + (((continuous_const.sub continuous_fst).sqrt).prodMk continuous_snd) + +lemma continuous_fieldOnInterval_d2 (f : SmoothField) (a b : ℝ) : + Continuous (fun p : ℝ×ℝ => (fieldOnInterval f a b p.1).d2 p.2) := by + exact (continuous_transform_d2 f a).comp + (((continuous_const.sub continuous_fst).sqrt).prodMk continuous_snd) + + + +def fieldOnInterval_dt (f : SmoothField) (a b t x : ℝ) : ℝ := + if t fieldOnInterval_dt f a b t x) volume u v := by + apply (intervalIntegrable_const (c := (fieldOnInterval_timeBound f a:ℝ))).mono_fun' + ((measurable_fieldOnInterval_dt f a b).comp + (measurable_id.prodMk measurable_const)).aestronglyMeasurable + exact ae_of_all _ fun t => fieldOnInterval_dt_bound f a b t x + +lemma fieldOnInterval_after (f : SmoothField) (a b t x : ℝ) (ht : b≤t) : + (fieldOnInterval f a b t).val x=f.val x := by + have hs : Real.sqrt (b-t)=0 := Real.sqrt_eq_zero_of_nonpos (sub_nonpos.mpr ht) + simpa only [fieldOnInterval,hs,sub_self,Real.sqrt_zero] using fieldOnInterval_right f a b x + +lemma fieldOnInterval_integral_before (f : SmoothField) (a b u v x : ℝ) + (huv : u≤v) (hv : v≤b) : + ∫ t in u..v,fieldOnInterval_dt f a b t x= + (fieldOnInterval f a b v).val x-(fieldOnInterval f a b u).val x := by + apply intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le huv + (((continuous_fieldOnInterval_val f a b).comp + (continuous_id.prodMk continuous_const)).continuousOn) + · intro t ht + have hb : t by + rw [uIoc_of_le huv] at ht + exact ite_eq_right (not_lt.mpr (hu.trans ht.1.le)) + +lemma fieldOnInterval_integral_time (f : SmoothField) (a b u v x : ℝ) : + ∫ t in u..v,fieldOnInterval_dt f a b t x= + (fieldOnInterval f a b v).val x-(fieldOnInterval f a b u).val x := by + wlog huv : u≤v generalizing u v + · rw [intervalIntegral.integral_symm] + rw [this v u (le_of_not_ge huv)] + ring + by_cases hv : v≤b + · exact fieldOnInterval_integral_before f a b u v x huv hv + by_cases hu : b≤u + · exact fieldOnInterval_integral_after f a b u v x huv hu + rw [←intervalIntegral.integral_add_adjacent_intervals + (integrable_fieldOnInterval_dt f a b u b x) (integrable_fieldOnInterval_dt f a b b v x), + fieldOnInterval_integral_before f a b u b x (le_of_not_ge hu) le_rfl, + fieldOnInterval_integral_after f a b b v x (le_of_not_ge hv) le_rfl] + ring + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/CoreScaleSqLeOne.lean b/lean/OAI/Probability/ParisiFinite/CoreScaleSqLeOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..37c7dbfbeba99180a00a9c4b78a3973193d15496 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/CoreScaleSqLeOne.lean @@ -0,0 +1,629 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SelectedBlock + +namespace OAI + +/-! Core Scale Sq Le One. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma coreScale_sq_le_one (n : ℕ) : coreScale n^2 ≤ 1 := by + rw [coreScale_sq] + apply (div_le_one (by positivity : (0:ℝ) N+N) atTop atTop := + tendsto_atTop_mono (fun N => Nat.le_add_right N N) tendsto_id + have h := (((tendsto_pressure_perSpin hβ).comp hN).const_mul 2).sub (tendsto_pressure_perSpin hβ) + have he : ∀ᶠ N in atTop, windowSlope β N= + 2*(pressure β (N+N)/(N+N:ℕ))-pressure β N/(N:ℝ) := by + filter_upwards [eventually_gt_atTop 0] with N hN + have hN' : (N:ℝ)≠0 := Nat.cast_ne_zero.mpr hN.ne' + dsimp [windowSlope] + push_cast + field_simp + ring + apply Tendsto.congr' (he.mono fun _ h => h.symm) + simpa only [Function.comp_def, show 2*(β*limitingFreeEnergy β)-β*limitingFreeEnergy β=β*limitingFreeEnergy β by ring] using h + +lemma cavityWindowBudget_root_bound {N m : ℕ} (hN : 0 windowSlope β N+ + (Real.pi*(8*(m+1:ℕ)+4*(∑ k,(d k:ℝ))))/(eighthRootScale N^2)+ + (ell*(m+1:ℕ)*(17+4*|β|+12*(m+1:ℕ)))/eighthRootScale N) atTop (𝓝 (β*limitingFreeEnergy β)) := by + have hi : Tendsto (fun N => (eighthRootScale N)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_eighthRootScale + have h1 := (hi.pow 2).const_mul (Real.pi*(8*(m+1:ℕ)+4*(∑ k,(d k:ℝ)))) + have h2 := hi.const_mul (ell*(m+1:ℕ)*(17+4*|β|+12*(m+1:ℕ))) + have h := ((tendsto_windowSlope hβ).add h1).add h2 + simpa only [div_eq_mul_inv,inv_pow,zero_pow (by decide : 2≠0),mul_zero,add_zero] using h + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +theorem exists_cavity_compatible {m : ℕ} (d : Fin (m+1) → ℕ) {β : ℝ} (hβ : 0<β) + (M : ℕ) {ε : ℝ} (hε : 0<ε) : + ∃ (n : ℕ) (x : Fin (m+1) → ℝ), M ≤ n ∧ 0 (eighthRootScale N)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_eighthRootScale + have hv : Tendsto (fun N => 4*(m+1:ℕ)/(eighthRootScale N^2)) atTop (𝓝 0) := by + simpa only [div_eq_mul_inv,inv_pow,zero_pow (by decide : 2≠0),mul_zero] using + (hi.pow 2).const_mul ((4:ℝ)*(m+1:ℕ)) + have hv' : ∀ᶠ N in atTop, 4*(m+1:ℕ)/(eighthRootScale N^2)<ε := + hv.eventually (eventually_lt_nhds hε) + obtain ⟨N,hN,hMN,hBN,hVN⟩ := (eventually_gt_atTop 0 |>.and ((eventually_ge_atTop M).and (hB.and hv'))).exists + have hr := one_le_eighthRootScale hN + have hrp : 0 ?_⟩ + · have hs := Finset.sum_le_sum (fun k (_ : k∈Finset.univ) => eighthRoot_amplitude_pressure_bound hN (hx k)) + rw [← Finset.sum_div] at hs + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hs + have hn' : (0:ℝ) sq_nonneg (x k)) hn' hle + apply hd.trans (hs.trans _) + have he : (m+1:ℕ)*(4/(eighthRootScale N^2))=4*(m+1:ℕ)/(eighthRootScale N^2) := by ring + rw [he] + exact hVN.le + · exact hc.trans (hbudget.trans (add_le_add_right hτε P)) + · apply (hg k r i f hf).trans + apply (div_le_iff₀ hell).mpr + have habs : P-a ≤ |P-a| := le_abs_self _ + have he : τ*ell=|P-a|+2 := by dsimp [ell]; field_simp + have hmul := mul_le_mul_of_nonneg_right hτε hell.le + change _-a ≤ ε*ell + nlinarith only [hbudget,habs,hτ1,he,hmul] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def compatibleSize {β : ℝ} (hβ : 0<β) (m : ℕ) : ℕ := + (exists_cavity_compatible (show Fin (m+1) → ℕ from Fin.val) hβ (m+1) + (by positivity : (0:ℝ)<1/(m+1:ℕ))).choose + +def compatibleAmplitude {β : ℝ} (hβ : 0<β) (m : ℕ) : Fin (m+1) → ℝ := + (exists_cavity_compatible (show Fin (m+1) → ℕ from Fin.val) hβ (m+1) + (by positivity : (0:ℝ)<1/(m+1:ℕ))).choose_spec.choose + +lemma compatible_spec {β : ℝ} (hβ : 0<β) (m : ℕ) : + m+1 ≤ compatibleSize hβ m ∧ 0 (1:ℝ)/(m+1:ℕ)) atTop (𝓝 0) := by + have h : Tendsto (fun m : ℕ => ((m+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_atTop_mono (fun m => Nat.le_succ m) tendsto_id) + simpa only [one_div,Function.comp_def] using tendsto_inv_atTop_zero.comp h + +lemma tendsto_compatibleGG {β : ℝ} (hβ : 0<β) (p r : ℕ) (i : Fin r) + (f : ∀ m, (Fin r → Configuration (compatibleSize hβ m)) → ℝ) (hf : ∀ m σ, |f m σ| ≤ 1) : + Tendsto (fun m => overlapGGDefect (compatibleCoeff hβ m) p i (f m)) atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + simp only [Real.norm_eq_abs] + exact squeeze_zero' (Eventually.of_forall fun m => abs_nonneg _) ((eventually_ge_atTop p).mono + fun m hm => compatibleGG_le hβ hm i (f m) (hf m)) tendsto_succ_reciprocal + +lemma compatible_limit_Gram {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) : + (μ : Measure _) GramArrays=1 := by + have h := ProbabilityMeasure.limsup_measure_closed_le_of_tendsto hμ isClosed_GramArrays + have he : ∀ k, (compatibleLaw hβ (φ k) : Measure _) GramArrays=(1:ℝ≥0∞) := fun k => + finiteProbability_set_of_forall _ (fieldReplicaMass_nonneg _) (sum_fieldReplicaMass (φ k+1) _) _ + (configurationOverlap_mem_Gram (compatible_spec hβ (φ k)).2.1) + simp_rw [he] at h + rw [limsup_const] at h + exact le_antisymm prob_le_one h + +lemma compatible_limit_GG {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) + (r p : ℕ) (i : Fin r) (f : C(OverlapBlock r,ℝ)) (hf : ∀ R, |f R| ≤ 1) : + arrayGGDefect μ r p i f=0 := by + have hz := (tendsto_compatibleGG hβ p r i + (fun _ σ => f (blockOfReplicas σ)) (fun _ σ => hf _)).comp hφ.tendsto_atTop + have he : ∀ᶠ k in atTop, + overlapGGDefect (compatibleCoeff hβ (φ k)) p i (fun σ => f (blockOfReplicas σ))= + arrayGGDefect (compatibleLaw hβ (φ k)) r p i f := by + filter_upwards [hφ.tendsto_atTop.eventually (eventually_ge_atTop (max r 1))] with k hk + exact (arrayGGDefect_fieldOverlapLaw (by omega) (by omega) _ p i f).symm + exact tendsto_nhds_unique ((continuous_arrayGGDefect r p i f).tendsto μ |>.comp hμ) (hz.congr' he) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma compatible_limit_GG_unbounded {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) + (r p : ℕ) (i : Fin r) (f : C(OverlapBlock r,ℝ)) : arrayGGDefect μ r p i f=0 := by + let M : ℝ := ‖f‖+1 + have hm : 0 M⁻¹*f R)=0 at h + rw [arrayGGDefect_const_mul] at h + exact (mul_eq_zero.mp h).resolve_left (inv_ne_zero hm.ne') + + +theorem compatible_limit_continuousGG {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) + (r : ℕ) (i : Fin r) (f : C(OverlapBlock r,ℝ)) (ψ : C(OverlapEntry,ℝ)) : + continuousGG μ r i f ψ=0 := by + let L := continuousGG μ r i f + have hp (p : ℕ) : L (overlapPower p)=0 := by + rw [continuousGG_power] + exact compatible_limit_GG_unbounded hβ hφ hμ r p i f + have hpoly (p : Polynomial ℝ) : L (p.toContinuousMapOn (Set.Icc (-1:ℝ) 1))=0 := by + induction p using Polynomial.induction_on' with + | add p q hp hq => + have he : (p+q).toContinuousMapOn (Set.Icc (-1:ℝ) 1)=p.toContinuousMapOn _+q.toContinuousMapOn _ := by + ext x; simp [Polynomial.toContinuousMapOn] + rw [he, map_add, hp, hq, add_zero] + | monomial p a => + have he : (Polynomial.monomial p a).toContinuousMapOn (Set.Icc (-1:ℝ) 1)=a • overlapPower p := by + ext x; simp [Polynomial.toContinuousMapOn, overlapPower] + rw [he, map_smul, hp, smul_zero] + have hs : (polynomialFunctions (Set.Icc (-1:ℝ) 1) : Set C(OverlapEntry,ℝ)) ⊆ {g | L g=0} := by + intro g hg + rw [polynomialFunctions_coe] at hg + rcases hg with ⟨p,rfl⟩ + exact hpoly p + have hc := closure_minimal hs (isClosed_eq L.continuous continuous_const) + exact hc (continuousMap_mem_polynomialFunctions_closure (-1) 1 ψ) + +lemma compatible_limit_exchangeable_integral {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) + (r : ℕ) (e : Fin r → ℕ) (he : Function.Injective e) (f : C(OverlapBlock r,ℝ)) : + (∫ R, f (selectedBlock e R) ∂(μ : Measure OverlapArray))= + ∫ R, f (blockOfArray r R) ∂(μ : Measure OverlapArray) := by + let F : C(OverlapArray,ℝ) := f.comp ⟨selectedBlock e,continuous_selectedBlock e⟩ + let G : C(OverlapArray,ℝ) := f.comp ⟨blockOfArray r,continuous_blockOfArray r⟩ + have hF := (ProbabilityMeasure.continuous_integral_continuousMap F).tendsto μ |>.comp hμ + have hG := (ProbabilityMeasure.continuous_integral_continuousMap G).tendsto μ |>.comp hμ + have ha : ∀ᶠ k in atTop, + (∫ R, F R ∂(compatibleLaw hβ (φ k) : Measure OverlapArray))= + ∫ R, G R ∂(compatibleLaw hβ (φ k) : Measure OverlapArray) := by + filter_upwards [hφ.tendsto_atTop.eventually (eventually_ge_atTop (max r (∑ i,e i)))] with k hk + have hr : r ≤ φ k+1 := by omega + have ht (i : Fin r) : e i<φ k+1 := by + have h := Finset.single_le_sum (fun j _ => Nat.zero_le (e j)) (Finset.mem_univ i) + omega + change (∫ R, f (selectedBlock e R) ∂(fieldOverlapLaw (t:=φ k) (compatibleCoeff hβ (φ k)) : Measure _))=_ + rw [integral_fieldOverlapLaw_selected hr e he ht] + exact (integral_fieldOverlapLaw_block hr _ f).symm + exact tendsto_nhds_unique (hF.congr' ha) hG + + +theorem compatible_limit_exchangeable {β : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) + (r : ℕ) (e : Fin r → ℕ) (he : Function.Injective e) : + (μ : Measure OverlapArray).map (selectedBlock e)=blockLaw μ r := by + apply ext_of_forall_integral_eq_of_IsFiniteMeasure + intro f + rw [integral_map (continuous_selectedBlock e).measurable.aemeasurable f.continuous.aestronglyMeasurable, + blockLaw, integral_map (continuous_blockOfArray r).measurable.aemeasurable f.continuous.aestronglyMeasurable] + exact compatible_limit_exchangeable_integral hβ hφ hμ r e he f.toContinuousMap + + + +theorem exists_compatible_ultrametric_limit {β : ℝ} (hβ : 0<β) : + ∃ (μ : ProbabilityMeasure OverlapArray) (φ : ℕ → ℕ), StrictMono φ ∧ + Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ) ∧ + (μ : Measure OverlapArray) GramArrays=1 ∧ GGIdentities μ ∧ FiniteExchangeable μ ∧ + (μ : Measure OverlapArray) UltrametricArrays=1 ∧ + ∀ k, compatibleValue hβ (φ k) ≤ β*limitingFreeEnergy β+1/(φ k+1:ℕ) := by + obtain ⟨μ,φ,hφ,hμ⟩ := CompactSpace.tendsto_subseq (compatibleLaw hβ) + have hG := compatible_limit_Gram hβ hμ + have hgg : GGIdentities μ := fun r i => + GG_measure_identity μ r i (compatible_limit_continuousGG hβ hφ hμ r i) + have hex : FiniteExchangeable μ := compatible_limit_exchangeable hβ hφ hμ + exact ⟨μ,φ,hφ,hμ,hG,hgg,hex,GG_ultrametric hG hgg hex,fun k => compatibleValue_le hβ (φ k)⟩ + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + +def partitionBlock {r : ℕ} (c : Fin r → ℕ) (q : ℝ) : Set (OverlapBlock r) := + {T | ∀ i j, q<(T i j:ℝ) ↔ c i=c j} + +def partitionEvent {r : ℕ} (c : Fin r → ℕ) (q : ℝ) : Set OverlapArray := + (blockOfArray r) ⁻¹' partitionBlock c q + +lemma measurableSet_partitionBlock {r : ℕ} (c : Fin r → ℕ) (q : ℝ) : + MeasurableSet (partitionBlock c q) := by + unfold partitionBlock + simp only [Set.ofPred_forall] + apply MeasurableSet.iInter + intro i + apply MeasurableSet.iInter + intro j + by_cases h : c i=c j + · simp only [h,iff_true] + exact measurableSet_lt measurable_const (by fun_prop) + · simp only [h,iff_false,not_lt] + exact measurableSet_le (by fun_prop) measurable_const + +lemma measurableSet_partitionEvent {r : ℕ} (c : Fin r → ℕ) (q : ℝ) : + MeasurableSet (partitionEvent c q) := + (measurableSet_partitionBlock c q).preimage (continuous_blockOfArray r).measurable + +def clusterCount {r : ℕ} (c : Fin r → ℕ) (i : Fin r) : ℕ := + (Finset.univ.filter (fun j => c j=c i)).card + +lemma clusterCount_pos {r : ℕ} (c : Fin r → ℕ) (i : Fin r) : 0 hR.1,fun hR => ⟨hR,(hR i j).mpr h⟩⟩ + · ext R + simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] + exact fun hR => h ((hR.1 i j).mp hR.2) + + + +theorem GG_partition_join {μ : ProbabilityMeasure OverlapArray} (hgg : GGIdentities μ) + {r : ℕ} (c : Fin r → ℕ) (q : ℝ) (i : Fin r) : + (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ q<(R i r:ℝ)}= + (μ:Measure OverlapArray).real (partitionEvent c q)* + ((clusterCount c i:ℝ)-1+(entryLaw μ 0 1).real {x | q<(x:ℝ)}) := by + have h := GG_event_identity hgg r i (partitionBlock c q) {x | q<(x:ℝ)} + (measurableSet_partitionBlock c q) (measurableSet_lt measurable_const (by fun_prop)) + change (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ q<(R i r:ℝ)}= + (μ:Measure OverlapArray).real (partitionEvent c q)*(entryLaw μ 0 1).real {x | q<(x:ℝ)}+ + ∑ l∈Finset.univ.erase i,(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ q<(R i l:ℝ)} at h + simp_rw [partition_pair_event] at h + simp only [apply_ite,measureReal_empty] at h + have hs : (∑ l∈Finset.univ.erase i,if c i=c l then (μ:Measure OverlapArray).real (partitionEvent c q) else 0)= + ((clusterCount c i:ℝ)-1)*(μ:Measure OverlapArray).real (partitionEvent c q) := by + have hj : (∑ l : Fin r,if c i=c l then (μ:Measure OverlapArray).real (partitionEvent c q) else 0)= + (clusterCount c i:ℝ)*(μ:Measure OverlapArray).real (partitionEvent c q) := by + simp only [← Finset.sum_filter] + simp only [Finset.sum_const,nsmul_eq_mul] + congr 2 + apply congrArg Finset.card + ext l + simp only [Finset.mem_filter,Finset.mem_univ,true_and,eq_comm] + have hh := Finset.sum_erase_add (s:=Finset.univ) + (f:=fun l => if c i=c l then (μ:Measure OverlapArray).real (partitionEvent c q) else 0) (Finset.mem_univ i) + simp only [ite_true] at hh + rw [hj] at hh + linarith + rw [hs] at h + nlinarith only [h] + +lemma ultrametric_partition_join_disjoint {r : ℕ} (c : Fin r → ℕ) (q : ℝ) (i j : Fin r) + (hij : c i≠c j) : + Disjoint {R | R∈UltrametricArrays ∧ R∈partitionEvent c q ∧ q<(R i r:ℝ)} + {R | R∈UltrametricArrays ∧ R∈partitionEvent c q ∧ q<(R j r:ℝ)} := by + apply Set.disjoint_left.mpr + intro R hi hj + have hu := hi.1 i j r + exact hij ((hi.2.1 i j).mp ((lt_min hi.2.2 hj.2.2).trans_le hu)) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def overlapDiscount (μ : ProbabilityMeasure OverlapArray) (q : ℝ) : ℝ := + (entryLaw μ 0 1).real {x | (x:ℝ) ≤ q} + +lemma entry_upper_mass (μ : ProbabilityMeasure OverlapArray) (q : ℝ) : + (entryLaw μ 0 1).real {x | q<(x:ℝ)}=1-overlapDiscount μ q := by + let := entryLaw_probability μ 0 1 + have h : {x : OverlapEntry | q<(x:ℝ)}={x : OverlapEntry | (x:ℝ) ≤ q}ᶜ := by ext x; simp + rw [h,probReal_compl_eq_one_sub (measurableSet_le (by fun_prop) measurable_const)] + rfl + +lemma GG_cluster_join {μ : ProbabilityMeasure OverlapArray} (hgg : GGIdentities μ) + {r : ℕ} (c : Fin r → ℕ) (q : ℝ) (i : Fin r) : + (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ q<(R i r:ℝ)}= + ((clusterCount c i:ℝ)-overlapDiscount μ q)*(μ:Measure OverlapArray).real (partitionEvent c q) := by + rw [GG_partition_join hgg,entry_upper_mass] + ring + +def ClusterReps {r : ℕ} (c : Fin r → ℕ) (S : Finset (Fin r)) : Prop := + Set.InjOn c S ∧ ∀ i, ∃ j∈S, c j=c i + +lemma exists_clusterReps {r : ℕ} (c : Fin r → ℕ) : ∃ S, ClusterReps c S := by + have h : Set.SurjOn c Set.univ (Finset.univ.image c) := by + intro i hi + obtain ⟨j,_,rfl⟩ := Finset.mem_image.mp hi + exact ⟨j,Set.mem_univ _,rfl⟩ + obtain ⟨S,_,hinj,hS⟩ := Finset.exists_subset_injOn_image_eq_of_surjOn Set.univ (Finset.univ.image c) h + refine ⟨S,hinj,fun i => ?_⟩ + have hi : c i∈S.image c := by rw [hS]; exact Finset.mem_image_of_mem _ (Finset.mem_univ i) + exact Finset.mem_image.mp hi + +lemma sum_clusterCount {r : ℕ} {c : Fin r → ℕ} {S : Finset (Fin r)} (hS : ClusterReps c S) : + (∑ i∈S, clusterCount c i)=r := by + have hc (i) : clusterCount c i=∑ j : Fin r,if c j=c i then 1 else 0 := by + simp [clusterCount] + simp_rw [hc] + rw [Finset.sum_comm] + have h1 (j : Fin r) : (∑ i∈S,if c j=c i then 1 else 0)=1 := by + obtain ⟨i,hi,hij⟩ := hS.2 j + rw [Finset.sum_eq_single i] + · simp [hij] + · intro k hk hki + have hne : c j≠c k := fun hh => hki (hS.1 hk hi (hh.symm.trans hij.symm)) + simp [hne] + · exact fun h => (h hi).elim + simp_rw [h1] + simp + +lemma ae_full_probability {X : Type*} [MeasurableSpace X] (μ : ProbabilityMeasure X) + {S : Set X} (hS : MeasurableSet S) (h : (μ:Measure X) S=1) : ∀ᵐ x ∂(μ:Measure X), x∈S := by + apply ae_iff.mpr + change (μ:Measure X) Sᶜ=0 + rw [measure_compl hS (measure_ne_top _ _),h] + simp + + + +theorem GG_cluster_innovation {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {r : ℕ} {c : Fin r → ℕ} {S : Finset (Fin r)} (hS : ClusterReps c S) (q : ℝ) : + (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈partitionEvent c q ∧ ∀ i : Fin r, (R i r:ℝ) ≤ q}= + (S.card:ℝ)*overlapDiscount μ q*(μ:Measure OverlapArray).real (partitionEvent c q) := by + let U := GramArrays∩UltrametricArrays + have hUa : ∀ᵐ R ∂(μ:Measure OverlapArray), R∈U := + (ae_full_probability μ isClosed_GramArrays.measurableSet hG).and + (ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu) + have hUr (T : Set OverlapArray) : (μ:Measure OverlapArray).real (U∩T)=(μ:Measure OverlapArray).real T := + congrArg ENNReal.toReal (Measure.measure_inter_eq_of_ae hUa) + let E := partitionEvent c q + let J (i : Fin r) : Set OverlapArray := {R | R∈E ∧ q<(R i r:ℝ)} + let A : Set OverlapArray := ⋃ i∈S, J i + have hJ (i : Fin r) : MeasurableSet (J i) := by + change MeasurableSet (partitionEvent c q ∩ {R : OverlapArray | q<(R i r:ℝ)}) + exact (measurableSet_partitionEvent c q).inter (measurableSet_lt measurable_const (by fun_prop)) + have hA : MeasurableSet A := MeasurableSet.iUnion fun i => MeasurableSet.iUnion fun _ => hJ i + have hdis : Set.PairwiseDisjoint (S:Set (Fin r)) (fun i => U∩J i) := by + intro i hi j hj hij + apply Set.disjoint_left.mpr + intro R hRi hRj + have hne : c i≠c j := fun hh => hij (hS.1 hi hj hh) + have h := hRi.1.2 i j r + exact hne ((hRi.2.1 i j).mp ((lt_min hRi.2.2 hRj.2.2).trans_le h)) + have hsum : (μ:Measure OverlapArray).real A=∑ i∈S,(μ:Measure OverlapArray).real (J i) := by + rw [← hUr A] + have he : U∩A=⋃ i∈S,U∩J i := by ext R; simp only [A,Set.mem_inter_iff,Set.mem_iUnion]; aesop + rw [he,measureReal_biUnion_finset hdis (fun i _ => + (isClosed_GramArrays.measurableSet.inter isClosed_UltrametricArrays.measurableSet).inter (hJ i))] + exact Finset.sum_congr rfl fun i _ => hUr (J i) + have hcompl : (μ:Measure OverlapArray).real {R | R∈E ∧ ∀ i : Fin r, (R i r:ℝ) ≤ q}= + (μ:Measure OverlapArray).real (E\A) := by + apply congrArg ENNReal.toReal + apply measure_congr + filter_upwards [hUa] with R hR + apply propext + constructor + · rintro ⟨hE,hnew⟩ + refine ⟨hE,?_⟩ + simp only [A,Set.mem_iUnion] + rintro ⟨i,hi,hj⟩ + exact (not_lt_of_ge (hnew i)) hj.2 + · rintro ⟨hE,hnot⟩ + refine ⟨hE,fun i => ?_⟩ + by_contra hi + have hi' : q<(R i r:ℝ) := lt_of_not_ge hi + obtain ⟨j,hj,hij⟩ := hS.2 i + have ho : q<(R j i:ℝ) := (hE j i).mpr hij + have hu' := hR.2 j r i + rw [hR.1.1 r i] at hu' + have hj' : q<(R j r:ℝ) := (lt_min ho hi').trans_le hu' + exact hnot (Set.mem_iUnion.mpr ⟨j,Set.mem_iUnion.mpr ⟨hj,⟨hE,hj'⟩⟩⟩) + rw [hcompl,measureReal_sdiff (by + intro R hR + obtain ⟨i,hR⟩ := Set.mem_iUnion.mp hR + obtain ⟨_,hR⟩ := Set.mem_iUnion.mp hR + exact hR.1) hA,hsum] + have hi := Finset.sum_congr (s₁:=S) (s₂:=S) rfl (fun i _ => GG_cluster_join hgg c q i) + rw [← Finset.mul_sum] at hi + have hc := sum_clusterCount hS + have hc' : (∑ i∈S,(clusterCount c i:ℝ))=(r:ℝ) := by exact_mod_cast hc + simp_rw [sub_mul] at hi + rw [Finset.sum_sub_distrib,← Finset.sum_mul,hc',Finset.sum_const,nsmul_eq_mul] at hi + change (r:ℝ)*(∑ i∈S,(μ:Measure OverlapArray).real (J i))=_ at hi + nlinarith only [hi] + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/CoshCone.lean b/lean/OAI/Probability/ParisiFinite/CoshCone.lean new file mode 100644 index 0000000000000000000000000000000000000000..18f9d1b86b2e0b38c2b782c3a16248c383ebdbea --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/CoshCone.lean @@ -0,0 +1,590 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ParisiFiniteTransport + +namespace OAI + +/-! Cosh Cone. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open MeasureTheory Set Real Matrix +open scoped BigOperators +open MeasureTheory Filter Set Real Finset Polynomial +open scoped Topology BigOperators +namespace ParisiSpectral + +lemma multichoose_nonneg {r : ℝ} (hr : 0 ≤ r) (n : ℕ) : + 0 ≤ Ring.multichoose r n := by + have hP : ∀ n : ℕ, 0 ≤ (ascPochhammer ℕ n).smeval r := by + intro n + induction n with + | zero => simp + | succ n ih => + rw [ascPochhammer_succ_right, Polynomial.smeval_mul] + simp only [Polynomial.smeval_add, Polynomial.smeval_X, Polynomial.smeval_natCast, + pow_one, pow_zero, nsmul_eq_mul, mul_one] + exact mul_nonneg ih (add_nonneg hr (Nat.cast_nonneg _)) + have he := Ring.factorial_nsmul_multichoose_eq_ascPochhammer r n + simp only [nsmul_eq_mul] at he + exact (mul_nonneg_iff_of_pos_left (by positivity : (0 : ℝ) < n.factorial)).mp (he.symm ▸ hP n) + +lemma PositiveDefinite.sum {ι : Type*} {f : ι → ℝ → ℝ} (s : Finset ι) + (hf : ∀ i ∈ s, PositiveDefinite (f i)) : + PositiveDefinite (fun x => ∑ i ∈ s, f i x) := by + classical + induction s using Finset.induction_on with + | empty => simpa only [sum_empty] using PositiveDefinite.constant (by norm_num : (0 : ℝ) ≤ 0) + | @insert a s ha ih => + simp only [sum_insert ha] + exact (hf a (mem_insert_self _ _)).add (ih fun i hi => hf i (mem_insert_of_mem hi)) + +lemma hasSum_one_sub_neg_rpow {r z : ℝ} (hz : ‖z‖ < 1) : + HasSum (fun n : ℕ => Ring.choose (r + n - 1) n * z^n) ((1-z)^(-r)) := by + have he : z ∈ Metric.eball (0 : ℝ) 1 := by + simp only [Metric.mem_eball, edist_zero_right, enorm_eq_nnnorm, ENNReal.coe_lt_one_iff] + exact_mod_cast hz + have hs := (Real.one_div_one_sub_rpow_hasFPowerSeriesOnBall_zero r).hasSum he + have hp : 0 ≤ 1-z := by have := le_abs_self z; rw [Real.norm_eq_abs] at hz; linarith + simpa only [FormalMultilinearSeries.ofScalars_apply_eq, smul_eq_mul, zero_add, + Real.rpow_neg hp, one_div] using hs + +lemma PositiveDefinite.one_sub_neg_rpow {g : ℝ → ℝ} (hg : PositiveDefinite g) + (hg0 : g 0 < 1) {r : ℝ} (hr : 0 ≤ r) : + PositiveDefinite (fun x => (1-g x)^(-r)) := by + refine PositiveDefinite.limit (l := atTop) + (g := fun n : ℕ => fun x => ∑ i ∈ Finset.range n, Ring.choose (r+i-1) i * (g x)^i) ?_ ?_ + · intro n + apply PositiveDefinite.sum + intro i hi + apply (hg.pow i).smul + rw [← Ring.multichoose_eq] + exact multichoose_nonneg hr i + · intro x + exact (hasSum_one_sub_neg_rpow ((hg.norm_le x).trans_lt hg0)).tendsto_sum_nat + + + +structure CoshCone (a : ℝ) (h : ℝ → ℝ) : Prop where + representation : ∃ (K : ℝ) (g : ℝ → ℝ), + 0 < K ∧ PositiveDefinite g ∧ g 0 < K ∧ + ∀ x, h x = K*cosh (a*x)-g x + +lemma cosh_neg_rpow_positiveDefinite {r : ℝ} (hr : 0 < r) (a : ℝ) : + PositiveDefinite (fun x => (cosh (a*x))^(-r)) := + (show PositiveDefinite (fun x => (cosh x)^(-r)) from cosh_neg_rpow_posSemidef hr).comp_linear a + +lemma CoshCone.pos {a : ℝ} {h : ℝ → ℝ} (hh : CoshCone a h) (x : ℝ) : 0 < h x := by + obtain ⟨K, g, hK, hg, hg0, he⟩ := hh.representation + rw [he] + have hx : g x ≤ g 0 := (le_abs_self _).trans (hg.norm_le x) + have hc := mul_le_mul_of_nonneg_left (one_le_cosh (a*x)) hK.le + nlinarith + + + +lemma CoshCone.neg_rpow_positiveDefinite {a : ℝ} {h : ℝ → ℝ} + (hh : CoshCone a h) {r : ℝ} (hr : 0 < r) : + PositiveDefinite (fun x => (h x)^(-r)) := by + obtain ⟨K, g, hK, hg, hg0, he⟩ := hh.representation + let u : ℝ → ℝ := fun x => K⁻¹ * (g x * (cosh (a*x))^(-1 : ℝ)) + have hu : PositiveDefinite u := + (hg.mul (cosh_neg_rpow_positiveDefinite (by norm_num : (0 : ℝ) < 1) a)).smul + (inv_nonneg.mpr hK.le) + have hu0 : u 0 < 1 := by + simp only [u, mul_zero, cosh_zero, one_rpow, mul_one] + rw [← div_eq_inv_mul, div_lt_one hK] + exact hg0 + have hv := hu.one_sub_neg_rpow hu0 hr.le + have hc := (cosh_neg_rpow_positiveDefinite hr a).smul (rpow_nonneg hK.le (-r)) + have heq (x : ℝ) : h x = (K*cosh (a*x)) * (1-u x) := by + rw [he] + dsimp [u] + rw [rpow_neg_one] + field_simp + have hhx (x : ℝ) : 0 ≤ 1-u x := by + have hx := (le_abs_self (u x)).trans (hu.norm_le x) + linarith + have hp := hc.mul hv + convert hp using 1 + funext x + rw [heq, mul_rpow (by positivity) (hhx x), mul_rpow hK.le (cosh_pos _).le] + +end ParisiSpectral + + + +open MeasureTheory Set Real Matrix Filter InnerProductSpace +open scoped BigOperators Topology RealInnerProductSpace +namespace ParisiSpectral + +lemma posSemidef_integral {A Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (K : Ω → Matrix A A ℝ) + (hK : ∀ᵐ z ∂μ, (K z).PosSemidef) + (hi : ∀ a b, Integrable (fun z => K z a b) μ) : + Matrix.PosSemidef (fun a b => ∫ z, K z a b ∂μ) := by + classical + refine ⟨Matrix.IsHermitian.ext (fun a b => ?_), fun c => ?_⟩ + · simp only [star_trivial] + apply integral_congr_ae + filter_upwards [hK] with z hz + exact hz.1.apply a b + · simp only [Finsupp.sum, star_trivial] + have hij (a b : A) : Integrable (fun z => c a * K z a b * c b) μ := + ((hi a b).const_mul _).mul_const _ + simp_rw [← integral_const_mul, ← integral_mul_const] + simp_rw [← integral_finsetSum _ (fun b hb => hij _ b)] + rw [← integral_finsetSum _ (fun a ha => integrable_finsetSum _ (fun b hb => hij a b))] + apply integral_nonneg_of_ae + filter_upwards [hK] with z hz + exact hz.2 c + +lemma posSemidef_cauchy {A : Type*} (u : A → ℝ) (hu : ∀ a, 0 < u a) + {t : ℝ} (ht : 0 ≤ t) : + Matrix.PosSemidef (fun a b => (t+u a+u b)⁻¹) := by + have he (a b : A) (z : ℝ) : exp (-t*z) * (exp (-u a*z)*exp (-u b*z)) = + exp (-(t+u a+u b)*z) := by + simp only [← exp_add] + congr 1 + ring + have hi (a b : A) : IntegrableOn + (fun z => exp (-t*z) * (exp (-u a*z)*exp (-u b*z))) (Ioi 0) := by + simp_rw [he] + exact integrableOn_exp_mul_Ioi (by linarith [hu a, hu b]) 0 + have hp := posSemidef_integral_gram (volume.restrict (Ioi (0 : ℝ))) + (fun a z => exp (-u a*z)) (fun z => exp (-t*z)) + (ae_of_all _ fun z => (exp_pos _).le) hi + have heq : (fun a b : A => ∫ z in Ioi (0 : ℝ), + exp (-t*z) * (exp (-u a*z)*exp (-u b*z))) = + (fun a b : A => (t+u a+u b)⁻¹) := by + funext a b + simp_rw [he] + rw [integral_exp_mul_Ioi (by linarith [hu a, hu b])] + simp only [mul_zero, exp_zero, neg_div_neg_eq, one_div] + exact (congrArg Matrix.PosSemidef heq).mp hp + +lemma fractional_integrand_gram {p t u v : ℝ} (hp : p ∈ Set.Ioo 0 1) + (ht : 0 < t) (hu : 0 < u) (hv : 0 < v) : + rpowIntegrand₀₁ p t u + rpowIntegrand₀₁ p t v - rpowIntegrand₀₁ p t (u+v) = + t^(p-1) * (u/(t+u)*(v/(t+v))) * (1+t*(t+u+v)⁻¹) := by + rw [rpowIntegrand₀₁_eq_pow_div hp ht.le hu.le, + rpowIntegrand₀₁_eq_pow_div hp ht.le hv.le, + rpowIntegrand₀₁_eq_pow_div hp ht.le (add_pos hu hv).le] + have h1 : t+u ≠ 0 := (add_pos ht hu).ne' + have h2 : t+v ≠ 0 := (add_pos ht hv).ne' + have h3 : t+(u+v) ≠ 0 := (add_pos ht (add_pos hu hv)).ne' + have h4 : t+u+v ≠ 0 := by positivity + field_simp + ring + + + +lemma posSemidef_fractional_gap {A : Type*} (u : A → ℝ) (hu : ∀ a, 0 < u a) + {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + Matrix.PosSemidef (fun a b => (u a)^p+(u b)^p-(u a+u b)^p) := by + obtain ⟨μ, hμ⟩ := exists_measure_rpow_eq_integral_rpowIntegrand₀₁ hp + let K : ℝ → Matrix A A ℝ := fun t a b => + rpowIntegrand₀₁ p t (u a) + rpowIntegrand₀₁ p t (u b) - + rpowIntegrand₀₁ p t (u a+u b) + have hi (a b : A) : Integrable (fun t => K t a b) (μ.restrict (Ioi 0)) := + ((hμ _ (hu a).le).1.add (hμ _ (hu b).le).1).sub + (hμ _ (add_pos (hu a) (hu b)).le).1 + have hK : ∀ᵐ t ∂μ.restrict (Ioi 0), (K t).PosSemidef := by + apply ae_restrict_of_forall_mem measurableSet_Ioi + intro t (ht : 0 < t) + have hc := (posSemidef_cauchy u hu ht.le).smul ht.le + have hone : Matrix.PosSemidef (fun a b : A => (1 : ℝ)) := by + simpa only [RCLike.inner_apply, map_one, mul_one, star_trivial] using + (posSemidef_inner (fun _ : A => (1 : ℝ))) + have hgr := posSemidef_inner (fun a : A => u a / (t+u a)) + have hh := (hgr.hadamard (hone.add hc)).smul (rpow_nonneg ht.le (p-1)) + have heq : (t^(p-1) • ((fun a b : A => ⟪u a/(t+u a), u b/(t+u b)⟫_ℝ) ⊙ + ((fun a b : A => (1:ℝ))+t • (fun a b : A => (t+u a+u b)⁻¹))) : Matrix A A ℝ) = K t := by + funext a b + change t^(p-1) * ((u b/(t+u b) * (u a/(t+u a))) * + (1+t*(t+u a+u b)⁻¹)) = + rpowIntegrand₀₁ p t (u a) + rpowIntegrand₀₁ p t (u b) - + rpowIntegrand₀₁ p t (u a+u b) + rw [fractional_integrand_gram hp ht (hu a) (hu b)] + ring + exact (congrArg Matrix.PosSemidef heq).mp hh + have hp' := posSemidef_integral (μ.restrict (Ioi 0)) K hK hi + have heq : (fun a b : A => ∫ t in Ioi 0, K t a b ∂μ) = + (fun a b : A => (u a)^p+(u b)^p-(u a+u b)^p) := by + funext a b + simp only [K] + have hab : Integrable (fun t => rpowIntegrand₀₁ p t (u a) + + rpowIntegrand₀₁ p t (u b)) (μ.restrict (Ioi 0)) := + (hμ _ (hu a).le).1.add (hμ _ (hu b).le).1 + rw [integral_sub hab (hμ _ (add_pos (hu a) (hu b)).le).1, + integral_add (hμ _ (hu a).le).1 (hμ _ (hu b).le).1, + ← (hμ _ (hu a).le).2, ← (hμ _ (hu b).le).2, + ← (hμ _ (add_pos (hu a) (hu b)).le).2] + exact (congrArg Matrix.PosSemidef heq).mp hp' + +lemma fractional_cosh_gap_identity (p x y : ℝ) : + (2:ℝ)^(-p) * (exp (-p*x)*exp (-p*y)) * + ((exp (2*x))^p+(exp (2*y))^p-(exp (2*x)+exp (2*y))^p) = + 2^(1-p)*cosh (p*(x-y))-(cosh (x-y))^p := by + have hsum := exp_sum_cosh x y + rw [hsum, mul_rpow (by positivity) (cosh_pos _).le, + mul_rpow (by norm_num : (0:ℝ) ≤ 2) (exp_pos _).le] + simp only [rpow_def_of_pos (exp_pos _), log_exp] + have h1 : (exp (-p*x)*exp (-p*y))*exp (2*x*p) = exp (p*(x-y)) := by + simp only [← exp_add] + congr 1 + ring + have h2 : (exp (-p*x)*exp (-p*y))*exp (2*y*p) = exp (-(p*(x-y))) := by + simp only [← exp_add] + congr 1 + ring + have h3 : (exp (-p*x)*exp (-p*y))*exp ((x+y)*p) = 1 := by + simp only [← exp_add] + rw [show -p*x+ -p*y+(x+y)*p = 0 by ring, exp_zero] + have h4 : (2:ℝ)^(-p) * 2^p = 1 := by + rw [← rpow_add (by norm_num : (0:ℝ)<2), neg_add_cancel, rpow_zero] + have h5 : (2:ℝ)^(1-p) = 2*2^(-p) := by + rw [sub_eq_add_neg, rpow_add (by norm_num : (0:ℝ)<2), rpow_one] + rw [h5] + calc + _ = 2^(-p)*(exp (p*(x-y))+exp (-(p*(x-y)))) - (cosh (x-y))^p := by + calc + _ = 2^(-p)*((exp (-p*x)*exp (-p*y))*exp (2*x*p)) + + 2^(-p)*((exp (-p*x)*exp (-p*y))*exp (2*y*p)) - + (2^(-p)*2^p)*((exp (-p*x)*exp (-p*y))*exp ((x+y)*p))* + (cosh (x-y))^p := by ring + _ = _ := by rw [h1, h2, h3, h4]; ring + _ = _ := by rw [show cosh (p*(x-y)) = + (exp (p*(x-y))+exp (-(p*(x-y))))/2 from Real.cosh_eq _]; ring + + +lemma cosh_fractional_gap_positiveDefinite {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : + PositiveDefinite (fun x => (2:ℝ)^(1-p)*cosh (p*x)-(cosh x)^p) := by + have hb := posSemidef_fractional_gap (fun x : ℝ => exp (2*x)) + (fun x => exp_pos _) hp + have hg := posSemidef_inner (fun x : ℝ => exp (-p*x)) + have hh := (hg.hadamard hb).smul (rpow_nonneg (by norm_num : (0:ℝ)≤2) (-p)) + have heq : (((2:ℝ)^(-p)) • ((fun x y : ℝ => ⟪exp (-p*x),exp (-p*y)⟫_ℝ) ⊙ + (fun x y : ℝ => (exp (2*x))^p+(exp (2*y))^p-(exp (2*x)+exp (2*y))^p)) : + Matrix ℝ ℝ ℝ) = + (fun x y : ℝ => 2^(1-p)*cosh (p*(x-y))-(cosh (x-y))^p) := by + funext x y + change 2^(-p) * ((exp (-p*y)*exp (-p*x)) * + ((exp (2*x))^p+(exp (2*y))^p-(exp (2*x)+exp (2*y))^p)) = _ + rw [mul_comm (exp (-p*y)) (exp (-p*x)), ← mul_assoc] + exact fractional_cosh_gap_identity p x y + exact (congrArg Matrix.PosSemidef heq).mp hh + +end ParisiSpectral + + + +open MeasureTheory Set Real Filter Polynomial +open Finset (range) +open scoped Topology BigOperators +namespace ParisiSpectral + +lemma fractional_coeff_identity (p : ℝ) (n : ℕ) : + -(Ring.choose p (n+1) * (-1:ℝ)^(n+1)) = + p * Ring.multichoose (1-p) n / (n+1) := by + have he := Ring.choose_smul_choose p (n := n+1) (k := 1) (by omega) + simp only [Nat.choose_one_right, nsmul_eq_mul, Nat.cast_add, Nat.cast_one, + Ring.choose_one_right, Nat.add_sub_cancel] at he + have hc := Ring.choose_neg' (1-p) n + simp only [show -(1-p) = p-1 by ring, Units.smul_def, zsmul_eq_mul, + Int.cast_negOnePow, zpow_natCast] at hc + rw [hc] at he + apply (eq_div_iff (by positivity : (n:ℝ)+1 ≠ 0)).mpr + have hpow : ((-1:ℝ)^n)^2 = 1 := by rw [← pow_mul, mul_comm n 2, pow_mul]; norm_num + rw [pow_succ] + calc + _ = ((n:ℝ)+1)*Ring.choose p (n+1)*(-1:ℝ)^n := by ring + _ = p*Ring.multichoose (1-p) n*((-1:ℝ)^n)^2 := by rw [he]; ring + _ = _ := by rw [hpow, mul_one] + +lemma fractional_coeff_nonneg {p : ℝ} (hp : p ∈ Set.Icc 0 1) (n : ℕ) : + 0 ≤ -(Ring.choose p (n+1) * (-1:ℝ)^(n+1)) := by + rw [fractional_coeff_identity] + exact div_nonneg (mul_nonneg hp.1 (multichoose_nonneg (sub_nonneg.mpr hp.2) n)) (by positivity) + +lemma hasSum_one_sub_rpow_gap {p z : ℝ} (hz : ‖z‖ < 1) : + HasSum (fun n : ℕ => -(Ring.choose p (n+1) * (-1:ℝ)^(n+1)) * z^(n+1)) + (1-(1-z)^p) := by + have he : -z ∈ Metric.eball (0:ℝ) 1 := by + simp only [Metric.mem_eball, edist_zero_right, enorm_eq_nnnorm, ENNReal.coe_lt_one_iff] + exact_mod_cast (show ‖-z‖ < 1 by simpa only [norm_neg] using hz) + have hs : HasSum (fun n : ℕ => Ring.choose p n * (-z)^n) ((1-z)^p) := by + simpa only [binomialSeries, FormalMultilinearSeries.ofScalars_apply_eq, smul_eq_mul, + zero_add, sub_eq_add_neg] using + (Real.one_add_rpow_hasFPowerSeriesOnBall_zero (a := p)).hasSum he + have ht := (hasSum_nat_add_iff' (f := fun n : ℕ => Ring.choose p n * (-z)^n) 1).mpr hs + simp only [Finset.sum_range_one, pow_zero, mul_one, Ring.choose_zero_right] at ht + have hn := ht.neg + convert! hn using 1 + · funext n + rw [neg_pow] + ring + · ring + + + +lemma coshCone_fractional_defect {a K p : ℝ} {g : ℝ → ℝ} + (hK : 0 < K) (hg : PositiveDefinite g) (hg0 : g 0 < K) + (hp : p ∈ Set.Ioo 0 1) : + PositiveDefinite (fun x => (K*cosh (a*x))^p - (K*cosh (a*x)-g x)^p) := by + let c : ℝ → ℝ := fun x => K*cosh (a*x) + let u : ℝ → ℝ := fun x => g x / c x + have hc (x : ℝ) : 0 < c x := mul_pos hK (cosh_pos _) + have hbound (x : ℝ) : ‖u x‖ < 1 := by + dsimp only [u] + rw [norm_div, Real.norm_eq_abs (c x), abs_of_pos (hc x), div_lt_one (hc x)] + have hh := mul_le_mul_of_nonneg_left (one_le_cosh (a*x)) hK.le + exact (hg.norm_le x).trans_lt (hg0.trans_le (by simpa only [mul_one, c] using hh)) + let d : ℕ → ℝ := fun n => -(Ring.choose p (n+1) * (-1:ℝ)^(n+1)) + let G : ℕ → ℝ → ℝ := fun n x => d n * (g x)^(n+1) * (c x)^(p-(n+1:ℕ)) + have hG (n : ℕ) : PositiveDefinite (G n) := by + have hr : 0 < (n+1:ℕ)-p := by exact_mod_cast (show (0:ℝ) < (n:ℝ)+1-p by linarith [Nat.cast_nonneg (α := ℝ) n, hp.2]) + have hh := ((hg.pow (n+1)).mul ((cosh_neg_rpow_positiveDefinite hr a).smul + (rpow_nonneg hK.le (-((n+1:ℕ)-p))))).smul (fractional_coeff_nonneg ⟨hp.1.le,hp.2.le⟩ n) + convert hh using 1 + funext x + dsimp only [G, d, c] + rw [show p-(n+1:ℕ) = -((n+1:ℕ)-p) by ring, mul_rpow hK.le (cosh_pos _).le] + ring + refine PositiveDefinite.limit (l := atTop) (g := fun n x => ∑ i ∈ range n, G i x) + (fun n => PositiveDefinite.sum _ (fun i _ => hG i)) ?_ + intro x + have hs := (hasSum_one_sub_rpow_gap (p := p) (hbound x)).mul_left ((c x)^p) + have he (n : ℕ) : G n x = (c x)^p * (d n * (u x)^(n+1)) := by + dsimp [G, u] + rw [rpow_sub (hc x), rpow_natCast, div_pow] + ring + have hEq : (c x)^p * (1-(1-u x)^p) = (K*cosh (a*x))^p-(K*cosh (a*x)-g x)^p := by + have hux : 0 ≤ 1-u x := by have hh := le_abs_self (u x); have := hbound x; rw [Real.norm_eq_abs] at this; linarith + rw [mul_sub, mul_one, ← mul_rpow (hc x).le hux] + congr 2 + dsimp [u, c] + field_simp + rw [hEq] at hs + exact (hs.congr_fun he).tendsto_sum_nat + +lemma CoshCone.rpow {a : ℝ} {h : ℝ → ℝ} (hh : CoshCone a h) + {p : ℝ} (hp : p ∈ Set.Ioo 0 1) : CoshCone (p*a) (fun x => (h x)^p) := by + obtain ⟨K,g,hK,hg,hg0,he⟩ := hh.representation + let D : ℝ → ℝ := fun x => K^p*((2:ℝ)^(1-p)*cosh (p*(a*x))-(cosh (a*x))^p) + let G : ℝ → ℝ := fun x => (K*cosh (a*x))^p-(K*cosh (a*x)-g x)^p + have hD : PositiveDefinite D := + ((cosh_fractional_gap_positiveDefinite hp).comp_linear a).smul (rpow_nonneg hK.le p) + have hG : PositiveDefinite G := coshCone_fractional_defect hK hg hg0 hp + refine ⟨⟨K^p*2^(1-p), (fun x => D x+G x), by positivity, hD.add hG, ?_, ?_⟩⟩ + · dsimp [D, G] + simp only [mul_zero, cosh_zero, one_rpow, mul_one] + have hpos : 0 < (K-g 0)^p := rpow_pos_of_pos (sub_pos.mpr hg0) _ + nlinarith + · intro x + rw [he] + dsimp [D, G] + rw [mul_rpow hK.le (cosh_pos _).le] + rw [mul_assoc p a x] + ring + +end ParisiSpectral + + + +open MeasureTheory ProbabilityTheory Real Filter Set +open scoped Topology NNReal +namespace ParisiSpectral + +lemma integrable_cosh_shift (a x : ℝ) (t : ℝ≥0) : + Integrable (fun z => cosh (a*(x+z))) (gaussianReal 0 t) := by + have h1 (z : ℝ) : exp (a*(x+z)) = exp (a*x)*exp (a*z) := by rw [mul_add, exp_add] + have h2 (z : ℝ) : exp (-(a*(x+z))) = exp (-a*x)*exp (-a*z) := by + rw [show -(a*(x+z)) = -a*x+ -a*z by ring, exp_add] + simp_rw [cosh_eq, h1, h2] + exact (((integrable_exp_mul_gaussianReal a).const_mul (exp (a*x))).add + ((integrable_exp_mul_gaussianReal (-a)).const_mul (exp (-a*x)))).div_const 2 + +lemma heat_cosh (a x : ℝ) (t : ℝ≥0) : + heat t (fun y => cosh (a*y)) x = exp ((t:ℝ)*a^2/2)*cosh (a*x) := by + have h1 (z : ℝ) : exp (a*(x+z)) = exp (a*x)*exp (a*z) := by rw [mul_add, exp_add] + have h2 (z : ℝ) : exp (-(a*(x+z))) = exp (-a*x)*exp (-a*z) := by + rw [show -(a*(x+z)) = -a*x+ -a*z by ring, exp_add] + have hm (b : ℝ) : (∫ z, exp (b*z) ∂gaussianReal 0 t) = exp ((t:ℝ)*b^2/2) := by + have hh := congrFun (mgf_fun_id_gaussianReal (μ := 0) (v := t)) b + simpa only [mgf, zero_mul, zero_add] using hh + dsimp only [heat] + simp_rw [cosh_eq, h1, h2] + rw [integral_div, integral_add + ((integrable_exp_mul_gaussianReal a).const_mul (exp (a*x))) + ((integrable_exp_mul_gaussianReal (-a)).const_mul (exp (-a*x))), + integral_const_mul, integral_const_mul, hm, hm] + rw [neg_sq, show -(a*x) = -a*x by ring] + ring + +lemma CoshCone.heat {a : ℝ} {h : ℝ → ℝ} + (hh : CoshCone a h) (hc : Continuous h) (t : ℝ≥0) : CoshCone a (ParisiSpectral.heat t h) := by + obtain ⟨K,g,hK,hg,hg0,he⟩ := hh.representation + have hgc : Continuous g := by + have heq : g = fun x => K*cosh (a*x)-h x := by funext x; rw [he]; ring + rw [heq] + exact (continuous_const.mul (continuous_cosh.comp (continuous_const.mul continuous_id))).sub hc + have hi (x : ℝ) : Integrable (fun z => g (x+z)) (gaussianReal 0 t) := + Integrable.of_bound (hgc.comp (continuous_const.add continuous_id)).aestronglyMeasurable + (g 0) (ae_of_all _ fun z => hg.norm_le _) + refine ⟨⟨K*exp ((t:ℝ)*a^2/2), ParisiSpectral.heat t g, by positivity, hg.heat hgc t, ?_, ?_⟩⟩ + · have hle : ParisiSpectral.heat t g 0 ≤ g 0 := by + have hd := integral_mono (hi 0) (integrable_const (g 0)) + (fun z => (le_abs_self (g (0+z))).trans (hg.norm_le _)) + simpa only [ParisiSpectral.heat, integral_const, probReal_univ, one_smul] using hd + have hex : 1 ≤ exp ((t:ℝ)*a^2/2) := one_le_exp (by positivity) + exact hle.trans_lt (hg0.trans_le (by nlinarith)) + · intro x + dsimp only [ParisiSpectral.heat] + simp_rw [he] + rw [integral_sub ((integrable_cosh_shift a x t).const_mul K) (hi x), integral_const_mul] + have hh := heat_cosh a x t + dsimp only [ParisiSpectral.heat] at hh + rw [hh] + ring + +end ParisiSpectral + + + +open MeasureTheory Filter Set Real +open scoped Topology +namespace ParisiSpectral + + + +lemma CoshCone.limit {a : ℝ} (ha : a ≠ 0) {h : ℕ → ℝ → ℝ} {H : ℝ → ℝ} + (hh : ∀ n, CoshCone a (h n)) (ht : ∀ x, Tendsto (fun n => h n x) atTop (𝓝 (H x))) + (hH : 0 < H 0) : CoshCone a H := by + classical + choose K g hK hg hg0 he using (fun n => (hh n).representation) + have hden : 0 < cosh a-1 := sub_pos.mpr (one_lt_cosh.mpr ha) + have hbound (n : ℕ) : K n ≤ (h n 1-h n 0)/(cosh a-1) := by + apply (le_div_iff₀ hden).mpr + have hgn : g n 1 ≤ g n 0 := (le_abs_self _).trans ((hg n).norm_le _) + rw [he n 1, he n 0] + simp only [mul_one, mul_zero, cosh_zero] + nlinarith + have hb := (((ht 1).sub (ht 0)).div_const (cosh a-1)).bddAbove_range + obtain ⟨M,hM⟩ := hb + have hkm (n : ℕ) : K n ∈ Icc (0:ℝ) M := + ⟨(hK n).le, (hbound n).trans (hM (mem_range_self n))⟩ + obtain ⟨k,hk,φ,hφ,hlim⟩ := isCompact_Icc.tendsto_subseq hkm + let G : ℝ → ℝ := fun x => k*cosh (a*x)-H x + have hglim (x : ℝ) : Tendsto (fun n => g (φ n) x) atTop (𝓝 (G x)) := by + have heq (n : ℕ) : g (φ n) x = K (φ n)*cosh (a*x)-h (φ n) x := by rw [he]; ring + simp_rw [heq] + exact (hlim.mul_const _).sub ((ht x).comp hφ.tendsto_atTop) + have hG : PositiveDefinite G := PositiveDefinite.limit (fun n => hg (φ n)) hglim + have hG0 : 0 ≤ k-H 0 := by simpa only [G, mul_zero, cosh_zero, mul_one] using hG.at_zero + refine ⟨⟨k,G,by linarith,hG,?_,?_⟩⟩ + · dsimp only [G] + simp only [mul_zero, cosh_zero, mul_one] + linarith + · intro x + dsimp only [G] + ring + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Filter Set Real +open scoped Topology NNReal +namespace ParisiSpectral + +lemma CoshCone.exp_lower {a b : ℝ} {φ : ℝ → ℝ} (ha : 0 < a) (hab : a ≤ b) + (hc : CoshCone b (fun x => exp (b*φ x))) : + CoshCone a (fun x => exp (a*φ x)) := by + rcases eq_or_lt_of_le hab with rfl | hab + · exact hc + have hb : 0 < b := ha.trans hab + have hp : a/b ∈ Set.Ioo 0 1 := ⟨div_pos ha hb, (div_lt_one hb).mpr hab⟩ + have hh := hc.rpow hp + rw [div_mul_cancel₀ a hb.ne'] at hh + convert hh using 1 + funext x + rw [rpow_def_of_pos (exp_pos _), log_exp] + congr 1 + field_simp + +lemma exp_step_heat {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {a : ℝ} (ha : a ≠ 0) (d : ℝ≥0) (x : ℝ) : + exp (a*ParisiFinite.step a (sqrt d) f x) = heat d (fun y => exp (a*f y)) x := by + rw [ParisiFinite.exp_step hf ha] + have hm : Measure.map (fun z : ℝ => sqrt d*z) (gaussianReal 0 1) = gaussianReal 0 d := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext + simp [sq_sqrt d.coe_nonneg] + unfold heat + rw [← hm, integral_map (by fun_prop)] + exact ((continuous_const.mul (hf.continuous.comp (continuous_const.add continuous_id))).rexp).aestronglyMeasurable + +lemma recursion_coshCone {β a : ℝ} (hβ : 0 < β) (ha : 0 < a) + (ls : ParisiFinite.Schedule) (ho : ParisiGuerra.OrderedFrom β a ls) : + CoshCone a (fun x => exp (a * ParisiFinite.recursion β ls x)) := by + induction ls generalizing a with + | nil => + apply CoshCone.exp_lower ha ho + refine ⟨⟨2, fun _ => 0, by norm_num, PositiveDefinite.constant (by norm_num), by norm_num, ?_⟩⟩ + intro x + simpa only [ParisiFinite.recursion, sub_zero] using ParisiFinite.exp_terminal hβ x + | cons l ls ih => + have hb : 0 < (l.1:ℝ) := ha.trans_le ho.1 + have hh := (ih hb ho.2).heat + ((continuous_const.mul (ParisiFinite.recursion_lipschitz hβ ls).continuous).rexp) l.2 + apply CoshCone.exp_lower ha ho.1 + convert hh using 1 + funext x + exact exp_step_heat (ParisiFinite.recursion_lipschitz hβ ls) hb.ne' l.2 x + + + +lemma field_coshCone (β : ℝ≥0) (hβ : 0 < β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t, γ t ≤ β) (t : ℝ≥0) {a : ℝ} + (ha : 0 < a) (hat : a ≤ γ t) : + CoshCone a (fun x => exp (a*ParisiFinite.field β γ t x)) := by + let ls (n : ℕ) := ParisiFinite.dyadicSchedule γ false t (1-t) n + have ho (n : ℕ) : ParisiGuerra.OrderedFrom β a (ls n) := + ParisiFinite.ordered_lower hat (ParisiFinite.ordered_upper (by exact_mod_cast hb _) + (ParisiFinite.dyadicSchedule_ordered hγ false t (1-t) n)) + apply CoshCone.limit ha.ne' (h := fun n x => exp (a*ParisiFinite.recursion β (ls n) x)) + (fun n => recursion_coshCone (by exact_mod_cast hβ) ha (ls n) (ho n)) + · intro x + have hh := ParisiFinite.dyadic_low_tendsto + (ParisiFinite.terminal_lipschitz (by exact_mod_cast hβ)) hγ t (1-t) x + simp_rw [← ParisiFinite.recursion_eq_evolve] at hh + exact Real.continuous_exp.continuousAt.tendsto.comp (hh.const_mul a) + · exact exp_pos _ + +lemma field_negative_exp_positiveDefinite (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t, γ t ≤ β) + (t : ℝ≥0) (ht : 0 < γ t) {r : ℝ} (hr : 0 < r) : + PositiveDefinite (fun x => exp (-r*ParisiFinite.field β γ t x)) := by + have ha : 0 < (γ t:ℝ) := by exact_mod_cast ht + have hh := (field_coshCone β hβ hγ hb t ha le_rfl).neg_rpow_positiveDefinite + (div_pos hr ha) + convert hh using 1 + funext x + rw [rpow_def_of_pos (exp_pos _), log_exp] + congr 1 + field_simp + +end ParisiSpectral + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/CostState.lean b/lean/OAI/Probability/ParisiFinite/CostState.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6be1b4167a572f00299786523d77544e4c88a9c --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/CostState.lean @@ -0,0 +1,674 @@ +import Mathlib +import OAI.Probability.ParisiFinite.RestrictLeft + +namespace OAI + +/-! Cost State. -/ + +noncomputable section + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ComplexConjugate +open MeasureTheory ProbabilityTheory +namespace SKQAOA + +def costState (n : ℕ) (J : Disorder n) (γ : ℝ) : State n := + (evolution γ (cost n J)).mulVec (plus n) + +theorem costState_apply (n : ℕ) (J : Disorder n) (γ : ℝ) (σ : Configuration n) : + costState n J γ σ = Complex.exp (-(γ : ℂ) * Complex.I * (hamiltonian n J σ : ℂ)) * + ((Real.sqrt ((2 : ℝ)^n))⁻¹ : ℝ) := by + simp [costState, cost_evolution_eq_diagonal, Matrix.mulVec_diagonal, plus] + +theorem plus_squared (n : ℕ) : + (((Real.sqrt ((2 : ℝ)^n))⁻¹ : ℝ) : ℂ) ^ 2 = ((2 : ℂ)^n)⁻¹ := by + have he : ((Real.sqrt ((2 : ℝ)^n))⁻¹)^2 = ((2 : ℝ)^n)⁻¹ := by + rw [inv_pow, Real.sq_sqrt (by positivity)] + rw [← Complex.ofReal_pow, he, Complex.ofReal_inv, Complex.ofReal_pow] + rfl + +def phaseCoeff (n : ℕ) (γ : ℝ) (σ τ : Configuration n) (e : Edge n) : ℂ := + (γ : ℂ) * Complex.I * ((skCoeff n σ e - skCoeff n τ e : ℝ) : ℂ) + +theorem phase_sum (n : ℕ) (J : Disorder n) (γ : ℝ) (σ τ : Configuration n) : + ∑ e, phaseCoeff n γ σ τ e * (J e : ℂ) = + (γ : ℂ) * Complex.I * ((hamiltonian n J σ : ℂ) - (hamiltonian n J τ : ℂ)) := by + simp only [hamiltonian_eq_coeff, Complex.ofReal_sum, Complex.ofReal_mul, + ← Finset.sum_sub_distrib, Finset.mul_sum, phaseCoeff, Complex.ofReal_sub] + apply Finset.sum_congr rfl + intro e _ + ring + +theorem costState_pair (n : ℕ) (J : Disorder n) (γ : ℝ) (σ τ : Configuration n) : + star (costState n J γ σ) * costState n J γ τ = + ((2 : ℂ)^n)⁻¹ * Complex.exp (∑ e, phaseCoeff n γ σ τ e * (J e : ℂ)) := by + rw [costState_apply, costState_apply, star_mul] + have hs : star (Complex.exp (-(γ : ℂ) * Complex.I * (hamiltonian n J σ : ℂ))) = + Complex.exp ((γ : ℂ) * Complex.I * (hamiltonian n J σ : ℂ)) := by + simp [← Complex.exp_conj] + rw [hs] + simp only [Complex.star_def, Complex.conj_ofReal] + rw [phase_sum, mul_sub, Complex.exp_sub] + have hm : Complex.exp (-(γ : ℂ) * Complex.I * (hamiltonian n J τ : ℂ)) = + (Complex.exp ((γ : ℂ) * Complex.I * (hamiltonian n J τ : ℂ)))⁻¹ := by + rw [neg_mul, neg_mul, Complex.exp_neg] + rw [hm, div_eq_mul_inv] + have hp := plus_squared n + calc + _ = ((((Real.sqrt ((2 : ℝ)^n))⁻¹ : ℝ) : ℂ)^2) * + (Complex.exp ((γ : ℂ) * Complex.I * (hamiltonian n J σ : ℂ)) * + (Complex.exp ((γ : ℂ) * Complex.I * (hamiltonian n J τ : ℂ)))⁻¹) := by ring + _ = _ := by rw [hp] + +theorem integrable_coord_costState_pair (n : ℕ) (γ : ℝ) (e : Edge n) (σ τ : Configuration n) : + Integrable (fun J : Disorder n => (J e : ℂ) * + (star (costState n J γ σ) * costState n J γ τ)) (disorderLaw n) := by + simp_rw [costState_pair] + have h := (GaussianFourier.integrable_coord_exp_sum (phaseCoeff n γ σ τ) e).const_mul + (((2 : ℂ)^n)⁻¹) + change Integrable _ (GaussianFourier.law (Edge n)) + convert h using 1 + funext J + ring + + +theorem integral_coord_costState_pair (n : ℕ) (γ : ℝ) (e : Edge n) (σ τ : Configuration n) : + (∫ J : Disorder n, (J e : ℂ) * + (star (costState n J γ σ) * costState n J γ τ) ∂disorderLaw n) = + ((2 : ℂ)^n)⁻¹ * phaseCoeff n γ σ τ e * + Complex.exp (∑ f, phaseCoeff n γ σ τ f ^ 2 / 2) := by + simp_rw [costState_pair] + have he : (fun J : Disorder n => (J e : ℂ) * + (((2 : ℂ)^n)⁻¹ * Complex.exp (∑ f, phaseCoeff n γ σ τ f * (J f : ℂ)))) = + fun J => ((2 : ℂ)^n)⁻¹ * ((J e : ℂ) * + Complex.exp (∑ f, phaseCoeff n γ σ τ f * (J f : ℂ))) := by + funext J + ring + rw [he, integral_const_mul] + change _ * (∫ J : Disorder n, _ ∂GaussianFourier.law (Edge n)) = _ + rw [GaussianFourier.integral_coord_exp_sum] + ring + +end SKQAOA + +namespace SKQAOA + +def flipAt {n : ℕ} (σ : Configuration n) (i : Fin n) : Configuration n := + Function.update σ i (!(σ i)) + +@[simp] theorem flipAt_self {n : ℕ} (σ : Configuration n) (i : Fin n) : + flipAt σ i i = !(σ i) := Function.update_self _ _ _ + +@[simp] theorem flipAt_ne {n : ℕ} (σ : Configuration n) (i j : Fin n) (h : j ≠ i) : + flipAt σ i j = σ j := Function.update_of_ne h _ _ + +@[simp] theorem spin_flipAt_self {n : ℕ} (σ : Configuration n) (i : Fin n) : + spin (flipAt σ i) i = -spin σ i := by + cases h : σ i <;> simp [spin, h] + +@[simp] theorem spin_flipAt_ne {n : ℕ} (σ : Configuration n) (i j : Fin n) (h : j ≠ i) : + spin (flipAt σ i) j = spin σ j := by simp [spin, flipAt_ne, h] + +@[simp] theorem pauliZ_mulVec {n : ℕ} (i : Fin n) (ψ : State n) (σ : Configuration n) : + (pauliZ i).mulVec ψ σ = (spin σ i : ℂ) * ψ σ := by + simp [pauliZ, Matrix.mulVec_diagonal] + +@[simp] theorem pauliX_mulVec {n : ℕ} (i : Fin n) (ψ : State n) (σ : Configuration n) : + (pauliX i).mulVec ψ σ = ψ (flipAt σ i) := by + have he : pauliX i σ = fun τ => if τ = flipAt σ i then (1 : ℂ) else 0 := by + funext τ + unfold pauliX + by_cases h : τ = flipAt σ i + · have h' : σ = Function.update τ i (!(τ i)) := (flip_eq_iff i σ τ).mpr h + simp only [ite_eq_left h, ite_eq_left h'] + · have h' : σ ≠ Function.update τ i (!(τ i)) := fun he => h ((flip_eq_iff i σ τ).mp he) + simp only [ite_eq_right h, ite_eq_right h'] + change (∑ τ, pauliX i σ τ * ψ τ) = _ + rw [he] + simp + +theorem pauliY_eq {n : ℕ} (i : Fin n) : + pauliY i = Complex.I • (pauliX i * pauliZ i) := by + rw [pauliY, TwoState.y, TensorMatrix.local_smul, TensorMatrix.local_mul, + ← pauliX_eq_atSite, ← pauliZ_eq_atSite] + +@[simp] theorem pauliY_mulVec {n : ℕ} (i : Fin n) (ψ : State n) (σ : Configuration n) : + (pauliY i).mulVec ψ σ = -Complex.I * (spin σ i : ℂ) * ψ (flipAt σ i) := by + rw [pauliY_eq, Matrix.smul_mulVec, ← Matrix.mulVec_mulVec] + simp only [Pi.smul_apply, smul_eq_mul, pauliX_mulVec, pauliZ_mulVec, + spin_flipAt_self, Complex.ofReal_neg] + ring + +theorem overlapSum_flipAt {n : ℕ} (σ : Configuration n) (i : Fin n) : + overlapSum σ (flipAt σ i) = (n : ℝ) - 2 := by + have hn : 1 ≤ n := Nat.succ_le_of_lt (lt_of_le_of_lt (Nat.zero_le i.val) i.isLt) + unfold overlapSum + rw [← Finset.add_sum_erase _ _ (Finset.mem_univ i)] + simp only [spin_flipAt_self, mul_neg, ← sq, spin_sq] + have he : (∑ j ∈ Finset.univ.erase i, spin σ j * spin (flipAt σ i) j) = (n : ℝ)-1 := by + calc + _ = ∑ _j ∈ Finset.univ.erase i, (1 : ℝ) := by + apply Finset.sum_congr rfl + intro j hj + rw [spin_flipAt_ne _ _ _ (Finset.ne_of_mem_erase hj), ← sq, spin_sq] + _ = _ := by + simp only [Finset.sum_const, nsmul_eq_mul, mul_one] + rw [Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ, Fintype.card_fin, + Nat.cast_sub hn, Nat.cast_one] + rw [he] + ring + +theorem phaseCoeff_flip_edge_left {n : ℕ} (γ : ℝ) (σ : Configuration n) (e : Edge n) : + phaseCoeff n γ σ (flipAt σ e.1.1) e = + 2 * (γ : ℂ) * Complex.I * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + (spin σ e.1.1 : ℂ) * (spin σ e.1.2 : ℂ) := by + unfold phaseCoeff skCoeff + rw [spin_flipAt_self, spin_flipAt_ne _ _ _ (ne_of_gt e.2)] + push_cast + ring + +theorem phaseCoeff_flip_edge_right {n : ℕ} (γ : ℝ) (σ : Configuration n) (e : Edge n) : + phaseCoeff n γ σ (flipAt σ e.1.2) e = + 2 * (γ : ℂ) * Complex.I * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + (spin σ e.1.1 : ℂ) * (spin σ e.1.2 : ℂ) := by + unfold phaseCoeff skCoeff + rw [spin_flipAt_self, spin_flipAt_ne _ _ _ (ne_of_lt e.2)] + push_cast + ring + +@[simp] theorem phaseCoeff_self (n : ℕ) (γ : ℝ) (σ : Configuration n) (e : Edge n) : + phaseCoeff n γ σ σ e = 0 := by simp [phaseCoeff] + +@[simp] theorem phaseCoeff_flip_both {n : ℕ} (γ : ℝ) (σ : Configuration n) (e : Edge n) : + phaseCoeff n γ σ (flipAt (flipAt σ e.1.1) e.1.2) e = 0 := by + unfold phaseCoeff skCoeff + rw [spin_flipAt_self, spin_flipAt_ne _ _ _ (ne_of_lt e.2), spin_flipAt_self, + spin_flipAt_ne _ _ _ (ne_of_gt e.2)] + simp + + +theorem phaseCoeff_square_sum_flip {n : ℕ} (hn : 0 < n) (γ : ℝ) + (σ : Configuration n) (i : Fin n) : + (∑ e, phaseCoeff n γ σ (flipAt σ i) e ^ 2 / 2) = + ((-2 * γ^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ) := by + have he : (∑ e, phaseCoeff n γ σ (flipAt σ i) e ^ 2 / 2) = + ((-γ^2 / 2 : ℝ) : ℂ) * + ((∑ e, (skCoeff n σ e - skCoeff n (flipAt σ i) e)^2 : ℝ) : ℂ) := by + rw [Complex.ofReal_sum, Finset.mul_sum] + apply Finset.sum_congr rfl + intro e _ + simp only [phaseCoeff, Complex.ofReal_div, Complex.ofReal_neg, Complex.ofReal_pow, + Complex.ofReal_ofNat, mul_pow, Complex.I_sq] + ring + rw [he, coeff_increment hn, overlapSum_flipAt] + push_cast + have hn0 : (n : ℂ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp + ring + +end SKQAOA + +namespace SKQAOA + + +theorem integrable_coord_quad_transition (n : ℕ) (γ : ℝ) (e : Edge n) (A : Operator n) + (a : Configuration n → ℂ) (f : Configuration n → Configuration n) + (hA : ∀ (ψ : State n) σ, A.mulVec ψ σ = a σ * ψ (f σ)) : + Integrable (fun J : Disorder n => (J e : ℂ) * quad (costState n J γ) A) (disorderLaw n) := by + have he : (fun J : Disorder n => (J e : ℂ) * quad (costState n J γ) A) = + fun J => ∑ σ, a σ * ((J e : ℂ) * + (star (costState n J γ σ) * costState n J γ (f σ))) := by + funext J + simp only [quad, dotProduct, hA, Pi.star_apply, Finset.mul_sum] + apply Finset.sum_congr rfl + intro σ _ + ring + rw [he] + exact integrable_finsetSum _ (fun σ _ => + (integrable_coord_costState_pair n γ e σ (f σ)).const_mul (a σ)) + + +theorem integral_coord_quad_transition (n : ℕ) (γ : ℝ) (e : Edge n) (A : Operator n) + (a : Configuration n → ℂ) (f : Configuration n → Configuration n) + (hA : ∀ (ψ : State n) σ, A.mulVec ψ σ = a σ * ψ (f σ)) : + (∫ J : Disorder n, (J e : ℂ) * quad (costState n J γ) A ∂disorderLaw n) = + ∑ σ, a σ * (((2 : ℂ)^n)⁻¹ * phaseCoeff n γ σ (f σ) e * + Complex.exp (∑ d, phaseCoeff n γ σ (f σ) d ^ 2 / 2)) := by + have he : (fun J : Disorder n => (J e : ℂ) * quad (costState n J γ) A) = + fun J => ∑ σ, a σ * ((J e : ℂ) * + (star (costState n J γ σ) * costState n J γ (f σ))) := by + funext J + simp only [quad, dotProduct, hA, Pi.star_apply, Finset.mul_sum] + apply Finset.sum_congr rfl + intro σ _ + ring + rw [he, integral_finsetSum _ (fun σ _ => + (integrable_coord_costState_pair n γ e σ (f σ)).const_mul (a σ))] + simp_rw [integral_const_mul, integral_coord_costState_pair] + + +theorem integral_coord_ZZ {n : ℕ} (γ : ℝ) (e : Edge n) : + (∫ J : Disorder n, (J e : ℂ) * + quad (costState n J γ) (pauliZ e.1.1 * pauliZ e.1.2) ∂disorderLaw n) = 0 := by + rw [integral_coord_quad_transition n γ e _ + (fun σ => (spin σ e.1.1 : ℂ) * (spin σ e.1.2 : ℂ)) id (by + intro ψ σ + simp only [← Matrix.mulVec_mulVec, pauliZ_mulVec, id_eq] + ring)] + simp + + +theorem integral_coord_YY {n : ℕ} (γ : ℝ) (e : Edge n) : + (∫ J : Disorder n, (J e : ℂ) * + quad (costState n J γ) (pauliY e.1.1 * pauliY e.1.2) ∂disorderLaw n) = 0 := by + rw [integral_coord_quad_transition n γ e _ + (fun σ => -(spin σ e.1.1 : ℂ) * (spin σ e.1.2 : ℂ)) + (fun σ => flipAt (flipAt σ e.1.1) e.1.2) (by + intro ψ σ + simp only [← Matrix.mulVec_mulVec, pauliY_mulVec, + spin_flipAt_ne _ _ _ (ne_of_gt e.2)] + calc + _ = Complex.I^2 * (spin σ e.1.1 : ℂ) * (spin σ e.1.2 : ℂ) * + ψ (flipAt (flipAt σ e.1.1) e.1.2) := by ring + _ = _ := by rw [Complex.I_sq]; ring)] + simp + + +theorem sum_configuration_normalized (n : ℕ) (c : ℂ) : + (∑ _σ : Configuration n, ((2 : ℂ)^n)⁻¹ * c) = c := by + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_bool, + Fintype.card_fin, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat] + rw [← mul_assoc, mul_inv_cancel₀ (pow_ne_zero _ (by norm_num : (2 : ℂ) ≠ 0)), one_mul] + +theorem integral_coord_YZ {n : ℕ} (γ : ℝ) (e : Edge n) : + (∫ J : Disorder n, (J e : ℂ) * + quad (costState n J γ) (pauliY e.1.1 * pauliZ e.1.2) ∂disorderLaw n) = + 2 * (γ : ℂ) * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + Complex.exp ((-2 * γ^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ) := by + have hn : 0 < n := lt_of_le_of_lt (Nat.zero_le e.1.1.val) e.1.1.isLt + rw [integral_coord_quad_transition n γ e _ + (fun σ => -Complex.I * (spin σ e.1.1 : ℂ) * (spin σ e.1.2 : ℂ)) + (fun σ => flipAt σ e.1.1) (by + intro ψ σ + simp only [← Matrix.mulVec_mulVec, pauliY_mulVec, pauliZ_mulVec, + spin_flipAt_ne _ _ _ (ne_of_gt e.2)] + ring)] + simp_rw [phaseCoeff_flip_edge_left, phaseCoeff_square_sum_flip hn] + calc + _ = ∑ _σ : Configuration n, ((2 : ℂ)^n)⁻¹ * + (2 * (γ : ℂ) * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + Complex.exp ((-2 * γ^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ)) := by + apply Finset.sum_congr rfl + intro σ _ + have hi : (spin σ e.1.1 : ℂ)^2 = 1 := by exact_mod_cast spin_sq σ e.1.1 + have hj : (spin σ e.1.2 : ℂ)^2 = 1 := by exact_mod_cast spin_sq σ e.1.2 + calc + _ = ((2 : ℂ)^n)⁻¹ * (2 * (γ : ℂ) * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + Complex.exp ((-2 * γ^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ)) * + (-Complex.I^2) * (spin σ e.1.1 : ℂ)^2 * (spin σ e.1.2 : ℂ)^2 := by ring + _ = _ := by rw [hi, hj, Complex.I_sq]; ring + _ = _ := sum_configuration_normalized n _ + +theorem integral_coord_ZY {n : ℕ} (γ : ℝ) (e : Edge n) : + (∫ J : Disorder n, (J e : ℂ) * + quad (costState n J γ) (pauliZ e.1.1 * pauliY e.1.2) ∂disorderLaw n) = + 2 * (γ : ℂ) * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + Complex.exp ((-2 * γ^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ) := by + have hn : 0 < n := lt_of_le_of_lt (Nat.zero_le e.1.1.val) e.1.1.isLt + rw [integral_coord_quad_transition n γ e _ + (fun σ => -Complex.I * (spin σ e.1.1 : ℂ) * (spin σ e.1.2 : ℂ)) + (fun σ => flipAt σ e.1.2) (by + intro ψ σ + simp only [← Matrix.mulVec_mulVec, pauliY_mulVec, pauliZ_mulVec] + ring)] + simp_rw [phaseCoeff_flip_edge_right, phaseCoeff_square_sum_flip hn] + calc + _ = ∑ _σ : Configuration n, ((2 : ℂ)^n)⁻¹ * + (2 * (γ : ℂ) * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + Complex.exp ((-2 * γ^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ)) := by + apply Finset.sum_congr rfl + intro σ _ + have hi : (spin σ e.1.1 : ℂ)^2 = 1 := by exact_mod_cast spin_sq σ e.1.1 + have hj : (spin σ e.1.2 : ℂ)^2 = 1 := by exact_mod_cast spin_sq σ e.1.2 + calc + _ = ((2 : ℂ)^n)⁻¹ * (2 * (γ : ℂ) * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + Complex.exp ((-2 * γ^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ)) * + (-Complex.I^2) * (spin σ e.1.1 : ℂ)^2 * (spin σ e.1.2 : ℂ)^2 := by ring + _ = _ := by rw [hi, hj, Complex.I_sq]; ring + _ = _ := sum_configuration_normalized n _ + +end SKQAOA + +namespace SKQAOA + +theorem integrable_coord_quad (n : ℕ) (γ : ℝ) (e : Edge n) (A : Operator n) : + Integrable (fun J : Disorder n => (J e : ℂ) * quad (costState n J γ) A) (disorderLaw n) := by + have he : (fun J : Disorder n => (J e : ℂ) * quad (costState n J γ) A) = + fun J => ∑ σ, ∑ τ, A σ τ * ((J e : ℂ) * + (star (costState n J γ σ) * costState n J γ τ)) := by + funext J + simp only [quad, dotProduct, Matrix.mulVec, Pi.star_apply, Finset.mul_sum] + apply Finset.sum_congr rfl + intro σ _ + apply Finset.sum_congr rfl + intro τ _ + ring + rw [he] + exact integrable_finsetSum _ (fun σ _ => integrable_finsetSum _ (fun τ _ => + (integrable_coord_costState_pair n γ e σ τ).const_mul (A σ τ))) + +theorem qaoaState_one (n : ℕ) (J : Disorder n) (γ β : Fin 1 → ℝ) : + qaoaState n 1 J γ β = (evolution (β 0) (mixer n)).mulVec (costState n J (γ 0)) := by + simp [qaoaState, circuit, costState, ← Matrix.mulVec_mulVec] + +theorem conjugate_mul {n : ℕ} (U A B : Operator n) (hU : U * Uᴴ = 1) : + Uᴴ * (A*B) * U = (Uᴴ*A*U)*(Uᴴ*B*U) := by + symm + calc + _ = Uᴴ*A*(U*Uᴴ)*B*U := by noncomm_ring + _ = _ := by rw [hU]; noncomm_ring + +theorem quad_qaoaState_one_edge (n : ℕ) (J : Disorder n) (γ β : Fin 1 → ℝ) (e : Edge n) : + quad (qaoaState n 1 J γ β) (pauliZ e.1.1 * pauliZ e.1.2) = + (Real.cos (2*β 0) : ℂ)^2 * quad (costState n J (γ 0)) (pauliZ e.1.1 * pauliZ e.1.2) + + ((Real.cos (2*β 0) : ℂ) * (Real.sin (2*β 0) : ℂ)) * + quad (costState n J (γ 0)) (pauliZ e.1.1 * pauliY e.1.2) + + ((Real.sin (2*β 0) : ℂ) * (Real.cos (2*β 0) : ℂ)) * + quad (costState n J (γ 0)) (pauliY e.1.1 * pauliZ e.1.2) + + (Real.sin (2*β 0) : ℂ)^2 * quad (costState n J (γ 0)) (pauliY e.1.1 * pauliY e.1.2) := by + rw [qaoaState_one, quad_mulVec, conjugate_mul _ _ _ + (Unitary.mul_star_self_of_mem (evolution_unitary _ _ (mixer_hermitian n))), + mixer_conjugate_pauliZ, mixer_conjugate_pauliZ] + simp only [add_mul, mul_add, smul_mul_assoc, mul_smul_comm, quad_add, quad_smul] + ring + +theorem integrable_coord_qaoaState_one_edge (n : ℕ) (γ β : Fin 1 → ℝ) (e : Edge n) : + Integrable (fun J : Disorder n => (J e : ℂ) * + quad (qaoaState n 1 J γ β) (pauliZ e.1.1 * pauliZ e.1.2)) (disorderLaw n) := by + simp_rw [quad_qaoaState_one_edge, mul_add] + simp_rw [mul_left_comm (G := ℂ) _ (↑(Real.cos (2*β 0))^2), + mul_left_comm (G := ℂ) _ (↑(Real.cos (2*β 0)) * ↑(Real.sin (2*β 0))), + mul_left_comm (G := ℂ) _ (↑(Real.sin (2*β 0)) * ↑(Real.cos (2*β 0))), + mul_left_comm (G := ℂ) _ (↑(Real.sin (2*β 0))^2)] + exact ((((integrable_coord_quad n (γ 0) e _).const_mul _).add + ((integrable_coord_quad n (γ 0) e _).const_mul _)).add + ((integrable_coord_quad n (γ 0) e _).const_mul _)).add + ((integrable_coord_quad n (γ 0) e _).const_mul _) + + +theorem integral_coord_qaoaState_one_edge (n : ℕ) (γ β : Fin 1 → ℝ) (e : Edge n) : + (∫ J : Disorder n, (J e : ℂ) * + quad (qaoaState n 1 J γ β) (pauliZ e.1.1 * pauliZ e.1.2) ∂disorderLaw n) = + 2 * (γ 0 : ℂ) * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * (Real.sin (4*β 0) : ℂ) * + Complex.exp ((-2 * (γ 0)^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ) := by + simp_rw [quad_qaoaState_one_edge, mul_add] + simp_rw [mul_left_comm (G := ℂ) _ (↑(Real.cos (2*β 0))^2), + mul_left_comm (G := ℂ) _ (↑(Real.cos (2*β 0)) * ↑(Real.sin (2*β 0))), + mul_left_comm (G := ℂ) _ (↑(Real.sin (2*β 0)) * ↑(Real.cos (2*β 0))), + mul_left_comm (G := ℂ) _ (↑(Real.sin (2*β 0))^2)] + have hZZ := (integrable_coord_quad n (γ 0) e (pauliZ e.1.1 * pauliZ e.1.2)).const_mul + ((Real.cos (2*β 0) : ℂ)^2) + have hZY := (integrable_coord_quad n (γ 0) e (pauliZ e.1.1 * pauliY e.1.2)).const_mul + ((Real.cos (2*β 0) : ℂ) * (Real.sin (2*β 0) : ℂ)) + have hYZ := (integrable_coord_quad n (γ 0) e (pauliY e.1.1 * pauliZ e.1.2)).const_mul + ((Real.sin (2*β 0) : ℂ) * (Real.cos (2*β 0) : ℂ)) + have hYY := (integrable_coord_quad n (γ 0) e (pauliY e.1.1 * pauliY e.1.2)).const_mul + ((Real.sin (2*β 0) : ℂ)^2) + have hi1 := integral_add ((hZZ.add hZY).add hYZ) hYY + have hi2 := integral_add (hZZ.add hZY) hYZ + have hi3 := integral_add hZZ hZY + simp only [Pi.add_apply] at hi1 hi2 hi3 + rw [hi1, hi2, hi3] + simp_rw [integral_const_mul] + rw [integral_coord_ZZ, integral_coord_ZY, integral_coord_YZ, integral_coord_YY] + have hs : (Real.sin (4*β 0) : ℂ) = + 2 * (Real.sin (2*β 0) : ℂ) * (Real.cos (2*β 0) : ℂ) := by + rw [show 4*β 0 = 2*(2*β 0) by ring, Real.sin_two_mul] + push_cast + rfl + rw [hs] + ring + +end SKQAOA + +namespace SKQAOA + +@[simp] theorem quad_finsetSum {n : ℕ} {ι : Type*} (s : Finset ι) + (ψ : State n) (A : ι → Operator n) : + quad ψ (∑ i ∈ s, A i) = ∑ i ∈ s, quad ψ (A i) := by + classical + induction s using Finset.induction_on with + | empty => simp [quad] + | @insert i s hi ih => simp [hi, ih] + +theorem quad_cost (n : ℕ) (J : Disorder n) (ψ : State n) : + quad ψ (cost n J) = ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * + ∑ e : Edge n, (J e : ℂ) * quad ψ (pauliZ e.1.1 * pauliZ e.1.2) := by + simp only [cost, quad_smul, quad_finsetSum] + +theorem integrable_quad_cost_one (n : ℕ) (γ β : Fin 1 → ℝ) : + Integrable (fun J : Disorder n => quad (qaoaState n 1 J γ β) (cost n J)) (disorderLaw n) := by + simp_rw [quad_cost] + exact (integrable_finsetSum _ (fun e _ => integrable_coord_qaoaState_one_edge n γ β e)).const_mul _ + +theorem integral_quad_cost_one (n : ℕ) (γ β : Fin 1 → ℝ) : + (∫ J : Disorder n, quad (qaoaState n 1 J γ β) (cost n J) ∂disorderLaw n) = + ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * (Fintype.card (Edge n) : ℂ) * + (2 * (γ 0 : ℂ) * ((Real.sqrt (n : ℝ))⁻¹ : ℂ) * (Real.sin (4*β 0) : ℂ) * + Complex.exp ((-2 * (γ 0)^2 * ((n : ℝ)-1) / (n : ℝ) : ℝ) : ℂ)) := by + simp_rw [quad_cost] + rw [integral_const_mul, integral_finsetSum _ (fun e _ => integrable_coord_qaoaState_one_edge n γ β e)] + simp_rw [integral_coord_qaoaState_one_edge] + simp [mul_assoc] + +theorem card_edges_real (n : ℕ) : + 2 * (Fintype.card (Edge n) : ℝ) = (n : ℝ) * ((n : ℝ)-1) := by + have h := sum_symmetric_pairs n (fun _ _ => 1) (by intros; rfl) + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one] at h + nlinarith + + +theorem expectedEnergy_one (n : ℕ) (γ β : Fin 1 → ℝ) : + expectedEnergy n 1 γ β = + γ 0 * ((n : ℝ)-1) / (n : ℝ) * Real.sin (4*β 0) * + Real.exp (-2 * (γ 0)^2 * ((n : ℝ)-1) / (n : ℝ)) := by + unfold expectedEnergy energyDensity + change (∫ J : Disorder n, (quad (qaoaState n 1 J γ β) (cost n J)).re / (n : ℝ) ∂disorderLaw n) = _ + have hi : (∫ J : Disorder n, (quad (qaoaState n 1 J γ β) (cost n J)).re ∂disorderLaw n) = + (∫ J : Disorder n, quad (qaoaState n 1 J γ β) (cost n J) ∂disorderLaw n).re := + integral_re (integrable_quad_cost_one n γ β) + rw [integral_div, hi, integral_quad_cost_one] + simp only [← Complex.ofReal_inv, ← Complex.ofReal_natCast, ← Complex.ofReal_ofNat, + ← Complex.ofReal_exp, ← Complex.ofReal_mul, Complex.ofReal_re] + by_cases hn : n = 0 + · subst n; simp + · have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn + have hs2 : ((Real.sqrt (n : ℝ))⁻¹)^2 = (n : ℝ)⁻¹ := by + rw [inv_pow, Real.sq_sqrt (Nat.cast_nonneg n)] + calc + _ = γ 0 * (2 * (Fintype.card (Edge n) : ℝ)) * ((Real.sqrt (n : ℝ))⁻¹)^2 * + Real.sin (4*β 0) * Real.exp (-2 * (γ 0)^2 * ((n : ℝ)-1)/(n : ℝ)) / (n : ℝ) := by ring + _ = _ := by rw [hs2, card_edges_real]; field_simp + +end SKQAOA + +namespace SKQAOA + +theorem tendsto_sizeCorrection : + Tendsto (fun n : ℕ => ((n : ℝ)-1)/(n : ℝ)) atTop (𝓝 1) := by + have h : Tendsto (fun n : ℕ => 1 - 1/(n : ℝ)) atTop (𝓝 (1-0 : ℝ)) := + tendsto_const_nhds.sub tendsto_one_div_atTop_nhds_zero_nat + simp only [sub_zero] at h + apply h.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_zero_of_lt hn) + field_simp + +theorem tendsto_expectedEnergy_one (γ β : Fin 1 → ℝ) : + Tendsto (fun n => expectedEnergy n 1 γ β) atTop + (𝓝 (γ 0 * Real.sin (4*β 0) * Real.exp (-2 * (γ 0)^2))) := by + have h := (((tendsto_const_nhds (x := γ 0)).mul tendsto_sizeCorrection).mul + (tendsto_const_nhds (x := Real.sin (4*β 0)))).mul + (Real.continuous_exp.tendsto (-2 * (γ 0)^2 * 1) |>.comp + (tendsto_const_nhds.mul tendsto_sizeCorrection)) + simp only [mul_one] at h + convert h using 1 + funext n + rw [expectedEnergy_one] + simp only [Function.comp_apply, mul_div_assoc] + +theorem value_one (γ β : Fin 1 → ℝ) : + value 1 γ β = γ 0 * Real.sin (4*β 0) * Real.exp (-2 * (γ 0)^2) := by + exact (tendsto_expectedEnergy_one γ β).limUnder_eq + + +theorem explicit_one_layer_value : + value 1 (fun _ => 1/2) (fun _ => Real.pi/8) = Real.exp (-1/2) / 2 := by + rw [value_one] + norm_num + rw [show 4*(Real.pi/8) = Real.pi/2 by ring, Real.sin_pi_div_two] + ring + +end SKQAOA + +namespace SKGaussian +variable {ι : Type*} [Fintype ι] [Nonempty ι] + + +theorem expected_field_logPartition_le_of_orthogonal {κ : Type*} [Fintype κ] + (A B : ι → κ → ℝ) + (hAB : ∀ i j, ∑ k, A i k * B j k = 0) + (hinc : ∀ i j, (∑ k, (A i k - A j k)^2) ≤ ∑ k, (B i k - B j k)^2) : + (∫ x, logPartition (field A x) ∂gaussianLaw κ) ≤ + ∫ x, logPartition (field B x) ∂gaussianLaw κ := by + rw [← integral_reindex_field A logPartition, ← integral_reindex_field B logPartition] + apply expected_logPartition_le + · intro i j + exact ((Fintype.equivFin κ).symm.sum_comp (fun k => A i k * B j k)).trans (hAB i j) + · intro i j + exact ((Fintype.equivFin κ).symm.sum_comp (fun k => (A i k - A j k)^2)).le.trans + ((hinc i j).trans ((Fintype.equivFin κ).symm.sum_comp (fun k => (B i k - B j k)^2)).symm.le) + +theorem expected_field_logPartition_le {κ κ₂ : Type*} [Fintype κ] [Fintype κ₂] + (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) + (hinc : ∀ i j, (∑ k, (A i k - A j k)^2) ≤ ∑ k, (B i k - B j k)^2) : + (∫ x, logPartition (field A x) ∂gaussianLaw κ) ≤ + ∫ x, logPartition (field B x) ∂gaussianLaw κ₂ := by + rw [← integral_field_inl (κ₂ := κ₂) A logPartition, + ← integral_field_inr (κ := κ) B logPartition] + apply expected_field_logPartition_le_of_orthogonal + · intro i j + simp [Fintype.sum_sum_type] + · intro i j + simpa only [Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr,sub_self, + sq,mul_zero,Finset.sum_const_zero,add_zero,zero_add] using hinc i j + +end SKGaussian + +namespace SKQAOA +open SKGaussian + + +def pressure (β : ℝ) (n : ℕ) : ℝ := + ∫ J, logPartition (fun σ => β * hamiltonian n J σ) ∂disorderLaw n + +def freeEnergy (β : ℝ) (n : ℕ) : ℝ := pressure β n / (n : ℝ) / β + +def limitingFreeEnergy (β : ℝ) : ℝ := limUnder atTop (freeEnergy β) + +theorem field_scale {ι κ : Type*} [Fintype κ] (β : ℝ) (A : ι → κ → ℝ) (J : κ → ℝ) : + field (fun i k => β * A i k) J = fun i => β * field A J i := by + funext i + simp only [field,mul_assoc,Finset.mul_sum] + +theorem scaled_increment {ι κ : Type*} [Fintype κ] (β : ℝ) (A : ι → κ → ℝ) (i j : ι) : + (∑ k, (β*A i k-β*A j k)^2) = β^2 * ∑ k, (A i k-A j k)^2 := by + simp_rw [← mul_sub,mul_pow] + rw [Finset.mul_sum] + +theorem field_skCoeff (n : ℕ) (J : Disorder n) : field (skCoeff n) J = hamiltonian n J := + funext fun σ => (hamiltonian_eq_coeff n J σ).symm + +theorem pressure_integrable (β : ℝ) (n : ℕ) : + Integrable (fun J => logPartition (fun σ => β * hamiltonian n J σ)) (disorderLaw n) := by + have : IsProbabilityMeasure (disorderLaw n) := by unfold disorderLaw; infer_instance + apply integrable_logPartition + intro σ + simpa only [field,← hamiltonian_eq_coeff,gaussianLaw,disorderLaw] using (integrable_field (skCoeff n) σ).const_mul β + +theorem block_partition (β : ℝ) (n m : ℕ) (J : (Edge n ⊕ Edge m) → ℝ) : + partition (fun σ => β * field (blockCoeff n m) J σ) = + partition (fun σ => β * hamiltonian n (fun e => J (Sum.inl e)) σ) * + partition (fun τ => β * hamiltonian m (fun e => J (Sum.inr e)) τ) := by + let e : (Configuration n × Configuration m) ≃ Configuration (n+m) := Fin.appendEquiv n m + rw [partition, ← e.sum_comp] + simp only [Fintype.sum_prod_type, e] + change (∑ σ : Configuration n, ∑ τ : Configuration m, + Real.exp (β * field (blockCoeff n m) J (Fin.append σ τ))) = _ + have he (σ : Configuration n) (τ : Configuration m) : + field (blockCoeff n m) J (Fin.append σ τ) = + hamiltonian n (fun e => J (Sum.inl e)) σ + hamiltonian m (fun e => J (Sum.inr e)) τ := by + simp only [field,blockCoeff,Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr, + restrictLeft_append,restrictRight_append] + rw [← field, ← field] + rw [field_skCoeff,field_skCoeff] + simp_rw [he,mul_add,Real.exp_add] + simp only [partition,Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + +theorem block_logPartition (β : ℝ) (n m : ℕ) (J : (Edge n ⊕ Edge m) → ℝ) : + logPartition (fun σ => β * field (blockCoeff n m) J σ) = + logPartition (fun σ => β * hamiltonian n (fun e => J (Sum.inl e)) σ) + + logPartition (fun τ => β * hamiltonian m (fun e => J (Sum.inr e)) τ) := by + rw [logPartition,block_partition,Real.log_mul (partition_pos _).ne' (partition_pos _).ne'] + rfl + +theorem expected_block_logPartition (β : ℝ) (n m : ℕ) : + (∫ J, logPartition (fun σ => β * field (blockCoeff n m) J σ) + ∂gaussianLaw (Edge n ⊕ Edge m)) = pressure β n + pressure β m := by + let T : ((Disorder n) × (Disorder m)) ≃ᵐ ((Edge n ⊕ Edge m) → ℝ) := + (MeasurableEquiv.sumPiEquivProdPi (fun _ : Edge n ⊕ Edge m => ℝ)).symm + have hp : MeasurePreserving T ((disorderLaw n).prod (disorderLaw m)) + (gaussianLaw (Edge n ⊕ Edge m)) := + measurePreserving_sumPiEquivProdPi_symm (fun _ => gaussianReal 0 1) + rw [← hp.integral_comp' (fun J => logPartition (fun σ => β * field (blockCoeff n m) J σ))] + simp_rw [block_logPartition] + change (∫ J, logPartition (fun σ => β * hamiltonian n J.1 σ) + + logPartition (fun τ => β * hamiltonian m J.2 τ) ∂(disorderLaw n).prod (disorderLaw m)) = _ + have : IsProbabilityMeasure (disorderLaw n) := by unfold disorderLaw; infer_instance + have : IsProbabilityMeasure (disorderLaw m) := by unfold disorderLaw; infer_instance + rw [integral_add ((pressure_integrable β n).comp_fst _) ((pressure_integrable β m).comp_snd _)] + rw [integral_fun_fst (fun J : Disorder n => logPartition (fun σ => β * hamiltonian n J σ)), + integral_fun_snd (fun J : Disorder m => logPartition (fun σ => β * hamiltonian m J σ))] + simp [pressure] + +theorem pressure_superadditive_pos (β : ℝ) {n m : ℕ} (hn : 0 < n) (hm : 0 < m) : + pressure β n + pressure β m ≤ pressure β (n+m) := by + have hinc (σ τ : Configuration (n+m)) : + (∑ k, (β*blockCoeff n m σ k-β*blockCoeff n m τ k)^2) ≤ + ∑ k, (β*skCoeff (n+m) σ k-β*skCoeff (n+m) τ k)^2 := by + rw [scaled_increment,scaled_increment] + exact mul_le_mul_of_nonneg_left (blockCoeff_increment hn hm σ τ) (sq_nonneg β) + have h := expected_field_logPartition_le (fun σ k => β*blockCoeff n m σ k) + (fun σ k => β*skCoeff (n+m) σ k) hinc + simp_rw [field_scale,field_skCoeff] at h + rw [expected_block_logPartition] at h + exact h + +@[simp] theorem pressure_zero (β : ℝ) : pressure β 0 = 0 := by + simp [pressure,logPartition,partition,hamiltonian] + +theorem pressure_superadditive (β : ℝ) (n m : ℕ) : + pressure β n + pressure β m ≤ pressure β (n+m) := by + rcases Nat.eq_zero_or_pos n with rfl | hn + · simp + rcases Nat.eq_zero_or_pos m with rfl | hm + · simp + exact pressure_superadditive_pos β hn hm + +end SKQAOA + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Count.lean b/lean/OAI/Probability/ParisiFinite/Count.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c3ccdbe8f11c8437f7d84a810d206e11ebcd652 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Count.lean @@ -0,0 +1,653 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Field +import OAI.Probability.ParisiFinite.RotateIJApply + +namespace OAI + +/-! Count. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +namespace BinaryOccupations +open scoped InnerProductSpace + + +def count (D : ℕ) (s : Finset (Fin D)) : Fin (D+1) := + ⟨s.card,Nat.lt_succ_of_le (by simpa using Finset.card_le_univ s)⟩ + +@[simp] theorem count_eq_iff (D : ℕ) (s : Finset (Fin D)) (m : Fin (D+1)) : + count D s=m ↔ s.card=m.val := Fin.ext_iff + +theorem count_surjective (D : ℕ) : Function.Surjective (count D) := by + intro m + obtain ⟨s,_,hs⟩ := Finset.exists_subset_card_eq + (show m.val≤(Finset.univ : Finset (Fin D)).card by simpa using Nat.le_of_lt_succ m.isLt) + exact ⟨s,(count_eq_iff D s m).mpr hs⟩ + + +theorem fiber_card (D : ℕ) (m : Fin (D+1)) : + Fintype.card {s : Finset (Fin D) // count D s=m}=D.choose m.val := by + calc + _ = Fintype.card {s : Finset (Fin D) // s.card=m.val} := + Fintype.card_congr (Equiv.subtypeEquivRight (fun s => count_eq_iff D s m)) + _ = _ := by simp + + + +def embedding (D : ℕ) : + EuclideanSpace ℂ (Fin (D+1)) →ₗᵢ[ℂ] EuclideanSpace ℂ (Finset (Fin D)) := + FiniteOccupations.lift (count D) (count_surjective D) + +@[simp] theorem embedding_apply (D : ℕ) (u : EuclideanSpace ℂ (Fin (D+1))) + (s : Finset (Fin D)) : + embedding D u s=(Real.sqrt (D.choose s.card : ℝ) : ℂ)⁻¹*u (count D s) := by + change FiniteOccupations.weight (count D) (count D s)*u (count D s)=_ + rw [FiniteOccupations.weight,fiber_card] + rfl + + +theorem mem_range_iff_card (D : ℕ) (u : EuclideanSpace ℂ (Finset (Fin D))) : + u∈Set.range (embedding D) ↔ ∀s t : Finset (Fin D), s.card=t.card → u s=u t := by + rw [embedding,FiniteOccupations.mem_range_iff] + simp only [count,Fin.mk.injEq] + +end BinaryOccupations + +namespace SKQAOA + + +def extendAngles {p : ℕ} (γ : Fin p → ℝ) : (k : ℕ) → Fin (p+k) → ℝ + | 0 => γ + | k+1 => Fin.snoc (extendAngles γ k) 0 + +@[simp] theorem expectedEnergy_extendAngles (n p k : ℕ) (γ β : Fin p → ℝ) : + expectedEnergy n (p+k) (extendAngles γ k) (extendAngles β k)=expectedEnergy n p γ β := by + induction k with + | zero => rfl + | succ k ih => simpa only [Nat.add_succ,extendAngles,expectedEnergy_pad] using ih + +@[simp] theorem value_extendAngles (p k : ℕ) (γ β : Fin p → ℝ) : + value (p+k) (extendAngles γ k) (extendAngles β k)=value p γ β := by + simp [value] + +end SKQAOA + +namespace SKQAOA + + + +theorem explicit_ground_lower_bound : Real.exp (-1/2)/2 ≤ Pstar := by + have ht : Tendsto (fun n => expectedEnergy n 1 (fun _ => 1/2) (fun _ => Real.pi/8)) + atTop (𝓝 (Real.exp (-1/2)/2)) := by + convert tendsto_expectedEnergy_one (fun _ => 1/2) (fun _ => Real.pi/8) using 1 + norm_num + rw [show 4*(Real.pi/8)=Real.pi/2 by ring,Real.sin_pi_div_two] + ring + exact le_of_tendsto_of_tendsto ht tendsto_expectedGround + (Filter.Eventually.of_forall fun n => expectedEnergy_le_expectedGround n 1 _ _) + +theorem Pstar_pos : 0 < Pstar := + lt_of_lt_of_le (div_pos (Real.exp_pos _) (by norm_num)) explicit_ground_lower_bound + + + +theorem exists_positive_word_every_depth (p : ℕ) (hp : 1≤p) : + ∃γ β : Fin p → ℝ, + Tendsto (fun n => expectedEnergy n p γ β) atTop (𝓝 (Real.exp (-1/2)/2)) ∧ + value p γ β=Real.exp (-1/2)/2 := by + obtain ⟨k,rfl⟩ := Nat.exists_eq_add_of_le hp + refine ⟨extendAngles (fun _ : Fin 1 => 1/2) k, + extendAngles (fun _ : Fin 1 => Real.pi/8) k,?_,?_⟩ + · simp only [expectedEnergy_extendAngles] + have ht := tendsto_expectedEnergy_one (fun _ => 1/2) (fun _ => Real.pi/8) + rw [←value_one (fun _ => 1/2) (fun _ => Real.pi/8),explicit_one_layer_value] at ht + exact ht + · simpa only [value_extendAngles] using explicit_one_layer_value + +end SKQAOA + +namespace SKQAOA + +open MeasureTheory ProbabilityTheory Filter + +@[simp] theorem hamiltonian_neg_disorder (n : ℕ) (J : Disorder n) (σ : Configuration n) : + hamiltonian n (-J) σ = -hamiltonian n J σ := by + simp [hamiltonian,Finset.sum_neg_distrib] + + + +theorem neg_energyDensity_le_groundMaximum (n p : ℕ) (J : Disorder n) + (γ β : Fin p → ℝ) : + -energyDensity n p J γ β ≤ groundMaximum n (-J)/(n : ℝ) := by + rw [energyDensity_eq,←neg_div] + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg n) + calc + -(∑σ,Complex.normSq (qaoaState n p J γ β σ)*hamiltonian n J σ) = + ∑σ,Complex.normSq (qaoaState n p J γ β σ)*hamiltonian n (-J) σ := by + simp [Finset.sum_neg_distrib] + _ ≤ ∑σ,Complex.normSq (qaoaState n p J γ β σ)*groundMaximum n (-J) := + Finset.sum_le_sum fun σ _ => mul_le_mul_of_nonneg_left + (hamiltonian_le_groundMaximum n (-J) σ) (Complex.normSq_nonneg _) + _ = groundMaximum n (-J) := by + rw [←Finset.sum_mul] + change mass (qaoaState n p J γ β)*groundMaximum n (-J)=_ + rw [qaoaState_mass,one_mul] + + + +theorem disorder_neg_preserving (n : ℕ) : + MeasurePreserving (fun J : Disorder n => -J) (disorderLaw n) (disorderLaw n) := by + refine measurePreserving_pi (fun _ : Edge n => gaussianReal 0 1) + (fun _ : Edge n => gaussianReal 0 1) (f := fun (_ : Edge n) (x : ℝ) => -x) ?_ + intro e + exact ⟨measurable_neg,by simpa using gaussianReal_map_neg (μ := 0) (v := 1)⟩ + + + +theorem abs_expectedEnergy_le_expectedGround (n p : ℕ) (γ β : Fin p → ℝ) : + |expectedEnergy n p γ β| ≤ expectedGround n := by + apply abs_le.mpr + refine ⟨?_,expectedEnergy_le_expectedGround n p γ β⟩ + have hp := disorder_neg_preserving n + have hi := hp.integrable_comp_of_integrable ((groundMaximum_integrable n).div_const (n : ℝ)) + have h := integral_mono (energyDensity_integrable n p γ β).neg hi + (fun J => neg_energyDensity_le_groundMaximum n p J γ β) + have he : (∫J : Disorder n,groundMaximum n (-J)/(n : ℝ) ∂disorderLaw n)=expectedGround n := by + calc + _ = ∫J : Disorder n,groundMaximum n J/(n : ℝ) ∂disorderLaw n := + hp.integral_comp (MeasurableEquiv.neg (Disorder n)).measurableEmbedding + (fun J => groundMaximum n J/(n : ℝ)) + _ = _ := integral_div _ _ + change (∫J : Disorder n,-energyDensity n p J γ β ∂disorderLaw n) ≤ + (∫J : Disorder n,groundMaximum n (-J)/(n : ℝ) ∂disorderLaw n) at h + rw [integral_neg,he] at h + change -(∫J : Disorder n,energyDensity n p J γ β ∂disorderLaw n) ≤ _ at h + change -expectedGround n ≤ (∫J : Disorder n,energyDensity n p J γ β ∂disorderLaw n) + linarith + + + +theorem eventually_uniform_expectedEnergy_bound {ε : ℝ} (hε : 0<ε) : + ∀ᶠ n in atTop, ∀p : ℕ, ∀γ β : Fin p → ℝ, + |expectedEnergy n p γ β| < Pstar+ε := by + have he : ∀ᶠ n in atTop, expectedGround n < Pstar+ε := + tendsto_expectedGround.eventually (eventually_lt_nhds (lt_add_of_pos_right _ hε)) + filter_upwards [he] with n hn p γ β + exact (abs_expectedEnergy_le_expectedGround n p γ β).trans_lt hn + +end SKQAOA + + + +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA.SiteHistories + + +def Bits : ℕ → Type + | 0 => Unit + | p+1 => Bool × Bits p + +instance bitsFintype : (p : ℕ) → Fintype (Bits p) + | 0 => inferInstanceAs (Fintype Unit) + | p+1 => @instFintypeProd Bool (Bits p) inferInstance (bitsFintype p) + +instance bitsDecidableEq : (p : ℕ) → DecidableEq (Bits p) + | 0 => inferInstanceAs (DecidableEq Unit) + | p+1 => @instDecidableEqProd Bool (Bits p) inferInstance (bitsDecidableEq p) + +def atVertex (n : ℕ) : (p : ℕ) → History n p → Fin n → Bits p + | 0, _, _ => () + | p+1, h, i => (h.1 i,atVertex n p h.2 i) + +def assemble (n : ℕ) : (p : ℕ) → (Fin n → Bits p) → History n p + | 0, _ => () + | p+1, h => (fun i => (h i).1,assemble n p (fun i => (h i).2)) + +@[simp] theorem atVertex_assemble (n p : ℕ) (h : Fin n → Bits p) : + atVertex n p (assemble n p h)=h := by + induction p with + | zero => funext i; change (():Unit)=h i; exact Subsingleton.elim _ _ + | succ p ih => + funext i + change ((h i).1,atVertex n p (assemble n p (fun i => (h i).2)) i)=h i + rw [ih] + exact Prod.eta _ + +@[simp] theorem assemble_atVertex (n p : ℕ) (h : History n p) : + assemble n p (atVertex n p h)=h := by + induction p with + | zero => change (():Unit)=h; exact Subsingleton.elim _ _ + | succ p ih => + change (h.1,assemble n p (atVertex n p h.2))=h + rw [ih] + exact Prod.eta _ + +def historyEquiv (n p : ℕ) : History n p ≃ (Fin n → Bits p) where + toFun := atVertex n p + invFun := assemble n p + left_inv := assemble_atVertex n p + right_inv := atVertex_assemble n p + +def step (t : ℝ) (σ τ : Bool) : ℂ := + if σ=τ then (Real.cos t:ℂ) else -(Real.sin t:ℂ)*Complex.I + +def mix : (p : ℕ) → (Fin p → ℝ) → Bool → Bits p → ℂ + | 0, _, _, _ => ((Real.sqrt 2)⁻¹:ℝ) + | p+1, β, σ, h => step (β (Fin.last p)) σ h.1 * mix p (fun i => β i.castSucc) h.1 h.2 + +lemma sqrt_nat_pow (x : ℝ) (hx : 0 ≤ x) (n : ℕ) : Real.sqrt (x^n)=(Real.sqrt x)^n := by + apply (Real.sqrt_eq_iff_mul_self_eq (pow_nonneg hx n) (pow_nonneg (Real.sqrt_nonneg x) n)).mpr + rw [←mul_pow,Real.mul_self_sqrt hx] + + +theorem historyMix_factor (n p : ℕ) (β : Fin p → ℝ) (σ : Configuration n) + (h : History n p) : + historyMix n p β σ h = ∏i, mix p β (σ i) (atVertex n p h i) := by + induction p generalizing σ with + | zero => simp [historyMix,mix,sqrt_nat_pow 2 (by norm_num)] + | succ p ih => + simp only [historyMix,mix,atVertex] + rw [mixer_evolution_apply,ih,←Finset.prod_mul_distrib] + rfl + + +abbrev Site (p : ℕ) := Bool × Bits p × Bits p + +def weight (p : ℕ) (β : Fin p → ℝ) (s : Site p) : ℂ := + star (mix p β s.1 s.2.1)*mix p β s.1 s.2.2 + +def trajectoriesEquiv (n p : ℕ) : + (Configuration n × History n p × History n p) ≃ (Fin n → Site p) where + toFun h i := (h.1 i,atVertex n p h.2.1 i,atVertex n p h.2.2 i) + invFun h := (fun i => (h i).1,assemble n p (fun i => (h i).2.1), + assemble n p (fun i => (h i).2.2)) + left_inv h := by simp + right_inv h := by funext i; simp + +@[simp] theorem trajectoriesEquiv_apply (n p : ℕ) + (h : Configuration n × History n p × History n p) (i : Fin n) : + trajectoriesEquiv n p h i=(h.1 i,atVertex n p h.2.1 i,atVertex n p h.2.2 i) := rfl + +theorem pairedMix_factor (n p : ℕ) (β : Fin p → ℝ) (σ : Configuration n) + (a b : History n p) : + pairedMix n p β σ a b = ∏i, weight p β (σ i,atVertex n p a i,atVertex n p b i) := by + rw [pairedMix,historyMix_factor,historyMix_factor] + simp only [star_prod,←Finset.prod_mul_distrib,weight] + + +theorem sum_pairedMix (n p : ℕ) (β : Fin p → ℝ) : + (∑σ : Configuration n, ∑a : History n p, ∑b : History n p, + pairedMix n p β σ a b)=1 := by + have h (σ : Configuration n) := qaoaState_pair_history n p (fun _ => 0) (fun _ => 0) β σ + simp only [Complex.ofReal_zero,mul_zero,Finset.sum_const_zero,Complex.exp_zero,mul_one] at h + simp_rw [←h] + change star (qaoaState n p (fun _ => 0) (fun _ => 0) β) ⬝ᵥ + qaoaState n p (fun _ => 0) (fun _ => 0) β = 1 + rw [←mass_eq_dot,qaoaState_mass] + norm_num + + +theorem sum_weight (p : ℕ) (β : Fin p → ℝ) : ∑s : Site p, weight p β s=1 := by + have h := sum_pairedMix 1 p β + simp_rw [pairedMix_factor] at h + have hs := (trajectoriesEquiv 1 p).sum_comp (fun f => ∏i,weight p β (f i)) + rw [Fintype.sum_prod_type] at hs + simp_rw [Fintype.sum_prod_type] at hs + simp only [trajectoriesEquiv_apply] at hs + rw [hs] at h + rw [←Fintype.prod_sum] at h + simpa using h + +lemma norm_step_le_one (t : ℝ) (σ τ : Bool) : ‖step t σ τ‖ ≤ 1 := by + unfold step + split_ifs <;> simp only [norm_mul,norm_neg,Complex.norm_real,Real.norm_eq_abs, + Complex.norm_I,mul_one] + · exact Real.abs_cos_le_one t + · exact Real.abs_sin_le_one t + +lemma norm_mix_le_one (p : ℕ) (β : Fin p → ℝ) (σ : Bool) (h : Bits p) : + ‖mix p β σ h‖ ≤ 1 := by + induction p generalizing σ with + | zero => + simp only [mix,Complex.norm_real,Real.norm_eq_abs,abs_inv,abs_of_nonneg (Real.sqrt_nonneg _)] + apply inv_le_one_of_one_le₀ + exact (Real.le_sqrt (by norm_num) (by norm_num)).mpr (by norm_num) + | succ p ih => + rw [mix,norm_mul] + exact (mul_le_of_le_one_left (norm_nonneg _) (norm_step_le_one _ _ _)).trans (ih _ _ _) + +lemma norm_weight_le_one (p : ℕ) (β : Fin p → ℝ) (s : Site p) : + ‖weight p β s‖ ≤ 1 := by + rw [weight,norm_mul,norm_star] + exact (mul_le_of_le_one_left (norm_nonneg _) (norm_mix_le_one _ _ _ _)).trans + (norm_mix_le_one _ _ _ _) + +def bitSpin (b : Bool) : ℝ := if b then -1 else 1 + +@[simp] theorem abs_bitSpin (b : Bool) : |bitSpin b|=1 := by cases b <;> norm_num [bitSpin] + +def interaction : (p : ℕ) → (Fin p → ℝ) → Bits p → Bits p → ℝ + | 0, _, _, _ => 0 + | p+1, γ, a, b => γ (Fin.last p)*bitSpin a.1*bitSpin b.1 + + interaction p (fun i => γ i.castSucc) a.2 b.2 + +def angleMass : (p : ℕ) → (Fin p → ℝ) → ℝ + | 0, _ => 0 + | p+1, γ => |γ (Fin.last p)|+angleMass p (fun i => γ i.castSucc) + +lemma angleMass_nonneg (p : ℕ) (γ : Fin p → ℝ) : 0 ≤ angleMass p γ := by + induction p with + | zero => rfl + | succ p ih => exact add_nonneg (abs_nonneg _) (ih _) + +lemma abs_interaction_le (p : ℕ) (γ : Fin p → ℝ) (a b : Bits p) : + |interaction p γ a b| ≤ angleMass p γ := by + induction p with + | zero => simp [interaction,angleMass] + | succ p ih => + calc + _ ≤ |γ (Fin.last p)*bitSpin a.1*bitSpin b.1| + + |interaction p (fun i => γ i.castSucc) a.2 b.2| := abs_add_le _ _ + _ ≤ |γ (Fin.last p)|+angleMass p (fun i => γ i.castSucc) := by + simp only [abs_mul,abs_bitSpin,mul_one] + exact add_le_add le_rfl (ih _ _ _) + _ = _ := rfl + + +def delta (p : ℕ) (γ : Fin p → ℝ) (s t : Site p) : ℝ := + interaction p γ s.2.1 t.2.1 - interaction p γ s.2.2 t.2.2 + +lemma abs_delta_le (p : ℕ) (γ : Fin p → ℝ) (s t : Site p) : + |delta p γ s t| ≤ 2*angleMass p γ := by + calc + _ ≤ |interaction p γ s.2.1 t.2.1|+|interaction p γ s.2.2 t.2.2| := abs_sub _ _ + _ ≤ angleMass p γ+angleMass p γ := add_le_add (abs_interaction_le _ _ _ _) (abs_interaction_le _ _ _ _) + _ = _ := by ring + +theorem historyPhase_local (n p : ℕ) (γ : Fin p → ℝ) (a : History n p) (e : Edge n) : + historyPhase n p γ a e = -Complex.I*((Real.sqrt (n:ℝ))⁻¹:ℂ)* + (interaction p γ (atVertex n p a e.1.1) (atVertex n p a e.1.2):ℂ) := by + induction p with + | zero => simp [historyPhase,interaction] + | succ p ih => + simp only [historyPhase,interaction,atVertex] + rw [ih] + simp only [skCoeff,spin,bitSpin,Complex.ofReal_add,Complex.ofReal_mul,Complex.ofReal_inv] + ring + +theorem pairedPhase_local (n p : ℕ) (γ : Fin p → ℝ) + (h : Configuration n × History n p × History n p) (e : Edge n) : + pairedPhase n p γ h.2.1 h.2.2 e = Complex.I*((Real.sqrt (n:ℝ))⁻¹:ℂ)* + (delta p γ (trajectoriesEquiv n p h e.1.1) (trajectoriesEquiv n p h e.1.2):ℂ) := by + rw [pairedPhase,historyPhase_local,historyPhase_local] + simp only [delta,trajectoriesEquiv_apply,star_mul,star_neg,Complex.star_def, + Complex.conj_I,neg_neg,Complex.conj_ofReal,Complex.ofReal_sub,map_inv₀] + ring + + +def edgeKernel (n p : ℕ) (γ : Fin p → ℝ) (s t : Site p) : ℝ := + Real.exp (-(delta p γ s t)^2*((n:ℝ)⁻¹)/2) + +lemma edgeKernel_pos (n p : ℕ) (γ : Fin p → ℝ) (s t : Site p) : + 0 < edgeKernel n p γ s t := Real.exp_pos _ + +lemma edgeKernel_le_one (n p : ℕ) (γ : Fin p → ℝ) (s t : Site p) : + edgeKernel n p γ s t ≤ 1 := by + apply Real.exp_le_one_iff.mpr + exact div_nonpos_of_nonpos_of_nonneg (mul_nonpos_of_nonpos_of_nonneg + (neg_nonpos.mpr (sq_nonneg _)) (inv_nonneg.mpr (Nat.cast_nonneg n))) (by norm_num) + +lemma abs_edgeKernel_sub_one_le (n p : ℕ) (γ : Fin p → ℝ) (s t : Site p) : + |edgeKernel n p γ s t-1| ≤ (2*angleMass p γ)^2*((n:ℝ)⁻¹)/2 := by + have hd := abs_delta_le p γ s t + have hsq : (delta p γ s t)^2 ≤ (2*angleMass p γ)^2 := by + nlinarith [sq_abs (delta p γ s t),abs_nonneg (delta p γ s t),angleMass_nonneg p γ] + have he := Real.add_one_le_exp (-(delta p γ s t)^2*((n:ℝ)⁻¹)/2) + rw [abs_of_nonpos (sub_nonpos.mpr (edgeKernel_le_one n p γ s t))] + have hmul := mul_le_mul_of_nonneg_right hsq (inv_nonneg.mpr (Nat.cast_nonneg n)) + change _ ≤ _ + dsimp [edgeKernel] at * + linarith + + +theorem exp_pairedPhase_sq (n p : ℕ) (γ : Fin p → ℝ) + (h : Configuration n × History n p × History n p) (e : Edge n) : + Complex.exp ((pairedPhase n p γ h.2.1 h.2.2 e)^2/2)= + (edgeKernel n p γ (trajectoriesEquiv n p h e.1.1) (trajectoriesEquiv n p h e.1.2):ℂ) := by + rw [pairedPhase_local,edgeKernel,Complex.ofReal_exp] + congr 1 + simp only [mul_pow,Complex.I_sq,←Complex.ofReal_pow,inv_pow,Real.sq_sqrt (Nat.cast_nonneg n)] + push_cast + ring + +end SKQAOA.SiteHistories + + + +open scoped BigOperators + +namespace FiniteHistory + +variable {V A : Type*} [Fintype V] [DecidableEq V] [Fintype A] + +def expectation (q : A → ℂ) (F : (V → A) → ℂ) : ℂ := + ∑a : V → A, (∏i, q (a i))*F a + + + +theorem restrict_expectation (q : A → ℂ) (hq : ∑a,q a=1) + (S : Finset V) (F : (S → A) → ℂ) : + expectation q (fun (a : V → A) => F (fun i : S => a i)) = + expectation q F := by + let e := Equiv.piEquivPiSubtypeProd (fun i : V => i∈S) (fun _ => A) + let G : ((S → A) × ({i : V // i∉S} → A)) → ℂ := + fun ab => ((∏i:S,q (ab.1 i))*F ab.1)*(∏i:{i:V // i∉S},q (ab.2 i)) + have hs := e.sum_comp G + have hg (a : V → A) : G (e a) = (∏i,q (a i))*F (fun i:S => a i) := by + simp only [G,e,Equiv.piEquivPiSubtypeProd_apply] + rw [mul_right_comm] + congr 1 + convert Fintype.prod_subtype_mul_prod_subtype (fun i : V => i∈S) (fun i => q (a i)) using 1 + congr 2 + ext x + simp + + simp_rw [hg] at hs + dsimp only [expectation] + rw [hs,Fintype.sum_prod_type] + dsimp only [G] + simp_rw [←Finset.mul_sum,←Fintype.prod_sum (fun _ : {i:V // i∉S} => q),hq] + simp + +lemma norm_expectation_le (q : A → ℂ) (F : (V → A) → ℂ) {C : ℝ} + (hC : 0 ≤ C) (hF : ∀a, ‖F a‖ ≤ C) : + ‖expectation q F‖ ≤ (∑a, ‖q a‖)^(Fintype.card V)*C := by + calc + _ ≤ ∑a:V→A, ‖(∏i,q (a i))*F a‖ := norm_sum_le _ _ + _ ≤ ∑a:V→A, (∏i,‖q (a i)‖)*C := by + apply Finset.sum_le_sum + intro a ha + rw [norm_mul] + exact (mul_le_mul_of_nonneg_left (hF a) (norm_nonneg _)).trans + (mul_le_mul_of_nonneg_right (Finset.norm_prod_le _ _) hC) + _ = (∑a, ‖q a‖)^(Fintype.card V)*C := by + rw [←Finset.sum_mul,←Fintype.prod_sum (fun _ : V => fun a:A => ‖q a‖)] + simp + +variable [Nonempty A] + +def extend (S : Finset V) (a : S → A) : V → A := + fun i => if h : i∈S then a ⟨i,h⟩ else Classical.choice (inferInstance : Nonempty A) + +omit [Fintype V] [Fintype A] in +@[simp] lemma extend_apply (S : Finset V) (a : S → A) (i : S) : extend S a i=a i := by + simp [extend,i.property] + + + +theorem norm_expectation_le_of_local (q : A → ℂ) (hq : ∑a,q a=1) + (S : Finset V) (F : (V → A) → ℂ) + (hlocal : ∀a b, (∀i∈S, a i=b i) → F a=F b) + {C : ℝ} (hC : 0 ≤ C) (hF : ∀a, ‖F a‖ ≤ C) : + ‖expectation q F‖ ≤ (∑a, ‖q a‖)^S.card*C := by + have he : F=(fun a => F (extend S (fun i:S => a i))) := by + funext a + apply hlocal + intro i hi + simp [extend,hi] + rw [he,restrict_expectation q hq S (fun a => F (extend S a))] + have hh := norm_expectation_le q (fun a:S→A => F (extend S a)) hC (fun a => hF _) + simpa using hh + +end FiniteHistory + + + +open scoped BigOperators Topology +open Filter + +namespace SKQAOA.SiteHistories + + + +lemma tendsto_scaled_exp (c : ℝ) : + Tendsto (fun n : ℕ => (n:ℝ)*(Real.exp (c/(n:ℝ))-1)) atTop (𝓝 c) := by + have hd : HasDerivAt (fun t : ℝ => Real.exp (c*t)) c 0 := by + convert ((hasDerivAt_id (0:ℝ)).const_mul c).exp using 1 <;> simp + have hi : Tendsto (fun n : ℕ => (n:ℝ)⁻¹) atTop (𝓝[≠] (0:ℝ)) := by + refine tendsto_nhdsWithin_iff.mpr ⟨tendsto_inv_atTop_nhds_zero_nat,?_⟩ + filter_upwards [eventually_ge_atTop 1] with n hn + simpa only [Set.mem_compl_iff,Set.mem_singleton_iff,inv_eq_zero] using + (show (n:ℝ)≠0 by exact_mod_cast (by omega : n≠0)) + simpa only [Function.comp_def,zero_add,mul_zero,Real.exp_zero,smul_eq_mul,inv_inv, + div_eq_mul_inv] using hd.tendsto_slope_zero.comp hi + +def kernelScaled (n p : ℕ) (γ : Fin p → ℝ) (u v : Site p) : ℝ := + (n:ℝ)*(edgeKernel n p γ u v-1) + +lemma tendsto_kernel (p : ℕ) (γ : Fin p → ℝ) (u v : Site p) : + Tendsto (fun n : ℕ => edgeKernel n p γ u v) atTop (𝓝 1) := by + have ht : Tendsto (fun n : ℕ => -(delta p γ u v)^2/(2*(n:ℝ))) atTop (𝓝 0) := by + have := (tendsto_const_nhds (x := -(delta p γ u v)^2/2)).mul + (tendsto_inv_atTop_nhds_zero_nat (𝕜 := ℝ)) + simpa only [mul_zero,zero_mul,div_eq_mul_inv,mul_inv_rev,mul_assoc,mul_left_comm,mul_comm] using this + convert Real.continuous_exp.continuousAt.tendsto.comp ht using 1 + · funext n + simp only [edgeKernel,Function.comp_def] + congr 1 + ring + · simp + +lemma tendsto_kernelScaled (p : ℕ) (γ : Fin p → ℝ) (u v : Site p) : + Tendsto (fun n : ℕ => kernelScaled n p γ u v) atTop (𝓝 (-(delta p γ u v)^2/2)) := by + have ht := tendsto_scaled_exp (-(delta p γ u v)^2/2) + convert ht using 1 + funext n + unfold kernelScaled edgeKernel + congr 3 + ring + + + +def graphCoefficient (N m p : ℕ) (γ β : Fin p → ℝ) (r : Edge m) + (H : Finset (Edge m)) : ℂ := + FiniteHistory.expectation (weight p β) (fun a : Fin m → Site p => + (bitSpin (a r.1.1).1:ℂ)*(bitSpin (a r.1.2).1:ℂ)*Complex.I* + (delta p γ (a r.1.1) (a r.1.2):ℂ)* + (edgeKernel N p γ (a r.1.1) (a r.1.2):ℂ)* + ∏e∈H,if e=r then 0 else (kernelScaled N p γ (a e.1.1) (a e.1.2):ℂ)) + +def graphCoefficientLimit (m p : ℕ) (γ β : Fin p → ℝ) (r : Edge m) + (H : Finset (Edge m)) : ℂ := + FiniteHistory.expectation (weight p β) (fun a : Fin m → Site p => + (bitSpin (a r.1.1).1:ℂ)*(bitSpin (a r.1.2).1:ℂ)*Complex.I* + (delta p γ (a r.1.1) (a r.1.2):ℂ)* + ∏e∈H,if e=r then 0 else (-(delta p γ (a e.1.1) (a e.1.2):ℂ)^2/2)) + + + +theorem tendsto_graphCoefficient (m p : ℕ) (γ β : Fin p → ℝ) (r : Edge m) + (H : Finset (Edge m)) : + Tendsto (fun N => graphCoefficient N m p γ β r H) atTop + (𝓝 (graphCoefficientLimit m p γ β r H)) := by + unfold graphCoefficient graphCoefficientLimit FiniteHistory.expectation + apply tendsto_finsetSum + intro a ha + apply Tendsto.const_mul + have hk := Complex.continuous_ofReal.continuousAt.tendsto.comp + (tendsto_kernel p γ (a r.1.1) (a r.1.2)) + have hp : Tendsto (fun N => ∏e∈H,if e=r then (0:ℂ) else + (kernelScaled N p γ (a e.1.1) (a e.1.2):ℂ)) atTop + (𝓝 (∏e∈H,if e=r then 0 else (-(delta p γ (a e.1.1) (a e.1.2):ℂ)^2/2))) := by + apply tendsto_finsetProd + intro e he + by_cases her : e=r + · simp only [her,ite_true] + exact tendsto_const_nhds + · simp only [her,ite_false] + convert Complex.continuous_ofReal.continuousAt.tendsto.comp + (tendsto_kernelScaled p γ (a e.1.1) (a e.1.2)) using 1 <;> push_cast <;> rfl + simpa only [Function.comp_def,Complex.ofReal_one,mul_one] using (hk.const_mul + ((bitSpin (a r.1.1).1:ℂ)*(bitSpin (a r.1.2).1:ℂ)*Complex.I* + (delta p γ (a r.1.1) (a r.1.2):ℂ))).mul hp + +end SKQAOA.SiteHistories + + + +open scoped BigOperators + +namespace FiniteHistory +variable {V W A : Type*} [Fintype V] [Fintype W] [Fintype A] [DecidableEq V] [DecidableEq W] + + +theorem expectation_equiv (q : A → ℂ) (e : V ≃ W) (F : (W → A) → ℂ) : + expectation q (fun a : V → A => F (a ∘ e.symm))=expectation q F := by + let ψ : (V → A) ≃ (W → A) := Equiv.arrowCongr e (Equiv.refl A) + have he (a : V → A) : (∏i:V,q (a i))*(F (a ∘ e.symm))= + (∏j:W,q (ψ a j))*F (ψ a) := by + have hp : (∏j:W,q (ψ a j))=(∏i:V,q (a i)) := by + simpa [ψ] using e.symm.prod_comp (fun i : V => q (a i)) + rw [hp] + rfl + dsimp only [expectation] + simp_rw [he] + exact ψ.sum_comp (fun a : W → A => (∏j:W,q (a j))*F a) + + + +theorem expectation_embedding (q : A → ℂ) (hq : ∑a,q a=1) + (f : W ↪ V) (F : (W → A) → ℂ) : + expectation q (fun a : V → A => F (a ∘ f))=expectation q F := by + classical + let S : Finset V := Finset.univ.image f + let e : W ≃ S := Equiv.ofBijective (fun w => ⟨f w,Finset.mem_image.mpr ⟨w,Finset.mem_univ _,rfl⟩⟩) + (by + constructor + · intro u v h + exact f.injective (congrArg Subtype.val h) + · intro v + obtain ⟨w,hw,he⟩ := Finset.mem_image.mp v.property + exact ⟨w,Subtype.ext he⟩) + have he (a : V → A) : F (a ∘ f)=F ((fun i : S => a i) ∘ e) := rfl + simp_rw [he] + rw [restrict_expectation q hq S (fun a => F (a ∘ e))] + exact expectation_equiv q e.symm F +end FiniteHistory + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/DyadicEvolutionGridBound.lean b/lean/OAI/Probability/ParisiFinite/DyadicEvolutionGridBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..6cb2d5501d1f4ed0c170401844016afaed56657d --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/DyadicEvolutionGridBound.lean @@ -0,0 +1,689 @@ +import Mathlib +import OAI.Probability.ParisiFinite.DyadicMeshTendsto + +namespace OAI + +/-! Dyadic Evolution Grid Bound. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma dyadicEvolution_grid_bound {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (t d : ℝ≥0) (n : ℕ) (x : ℝ) : + |evolve (dyadicSchedule γ false t d n) f x-dyadicEvolution γ t d f x| ≤ + 2*gaussianSmallError β (Real.sqrt (dyadicMesh d n)) := by + have hlow : evolve (dyadicSchedule γ false t d n) f x ≤ dyadicEvolution γ t d f x := + le_ciSup (dyadic_low_bddAbove hf hγ t d x) n + have hhigh : dyadicEvolution γ t d f x ≤ evolve (dyadicSchedule γ true t d n) f x := by + apply le_of_tendsto (dyadic_low_tendsto hf hγ t d x) + filter_upwards [eventually_ge_atTop n] with k hk + exact (dyadicSchedule_low_le_high hf hγ t d k x).trans (dyadic_high_antitone hf hγ t d x hk) + have he := abs_le.mp (dyadicSchedule_grid_error hb t d n hf x) + rw [abs_of_nonpos (sub_nonpos.mpr hlow)] + linarith + +lemma dyadic_low_tendstoUniformly {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (t d : ℝ≥0) : TendstoUniformly (fun n => evolve (dyadicSchedule γ false t d n) f) + (dyadicEvolution γ t d f) atTop := by + have he : Tendsto (fun n => 2*gaussianSmallError β (Real.sqrt (dyadicMesh d n))) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero] using (gaussianSmallError_dyadic_tendsto β d).const_mul 2 + rw [Metric.tendstoUniformly_iff] + intro ε hε + filter_upwards [he.eventually (gt_mem_nhds hε)] with n hn x + rw [Real.dist_eq,abs_sub_comm] + exact (dyadicEvolution_grid_bound hf hγ hb t d n x).trans_lt hn + +lemma dyadicSchedule_coeff_bound {γ : ℝ≥0 → ℝ≥0} {β : ℝ≥0} (hb : ∀ t,γ t ≤ β) + (u : Bool) (t d : ℝ≥0) (n : ℕ) : ∀ l∈dyadicSchedule γ u t d n,l.1 ≤ β := by + induction n generalizing t d with + | zero => + intro l hl + have he : l=(γ (if u then t+d else t),d) := List.mem_singleton.mp hl + rw [he] + exact hb _ + | succ n ih => + intro l hl + rcases List.mem_append.mp hl with h|h + · exact ih t (d/2) l h + · exact ih (t+d/2) (d/2) l h + + + +lemma dyadicEvolution_terminal_gradient (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t d : ℝ≥0) : + ∃ m : ℝ → ℝ, + (∀ x,HasDerivAt (dyadicEvolution γ t d (terminal β)) (m x) x) ∧ + LipschitzWith β m ∧ (∀ x,|m x| ≤ 1) ∧ + TendstoUniformly (fun n => (smoothRecursion β hβ (dyadicSchedule γ false t d n)).d1) m atTop := by + let F (n : ℕ) := smoothRecursion β hβ (dyadicSchedule γ false t d n) + have hc (n : ℕ) : HasParisiCurvature β (F n) := + smoothRecursion_hasParisiCurvature β hβ _ (dyadicSchedule_coeff_bound hb false t d n) + have ht : TendstoUniformly (fun n => (F n).val) (dyadicEvolution γ t d (terminal β)) atTop := by + have hv (n : ℕ) : (F n).val=evolve (dyadicSchedule γ false t d n) (terminal β) := by + dsimp only [F] + rw [smoothRecursion_val,recursion_eq_evolve] + simp_rw [hv] + exact dyadic_low_tendstoUniformly (terminal_lipschitz hβ) hγ (fun s => by exact_mod_cast hb s) t d + obtain ⟨m,hu,hd,hl,hn⟩ := exists_uniform_derivative_limit hc ht + exact ⟨m,hd,hl,hn,hu⟩ + +def field (β : ℝ≥0) (γ : ℝ≥0 → ℝ≥0) (t : ℝ≥0) (x : ℝ) : ℝ := + dyadicEvolution γ t (1-t) (terminal β) x + +def fieldGradient (β : ℝ≥0) (γ : ℝ≥0 → ℝ≥0) (t : ℝ≥0) : ℝ → ℝ := + deriv (field β γ t) + +lemma hasDerivAt_field (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) (x : ℝ) : + HasDerivAt (field β γ t) (fieldGradient β γ t x) x := by + obtain ⟨m,hd,_,_,_⟩ := dyadicEvolution_terminal_gradient β hβ hγ hb t (1-t) + have hx : HasDerivAt (field β γ t) (m x) x := hd x + change HasDerivAt (field β γ t) (deriv (field β γ t) x) x + rw [hx.deriv] + exact hx + +lemma fieldGradient_lipschitz (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) : + LipschitzWith β (fieldGradient β γ t) := by + obtain ⟨m,hd,hl,_,_⟩ := dyadicEvolution_terminal_gradient β hβ hγ hb t (1-t) + convert hl using 1 + funext x + exact (hd x).deriv + +lemma fieldGradient_bound (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) (x : ℝ) : + |fieldGradient β γ t x| ≤ 1 := by + obtain ⟨m,hd,_,hn,_⟩ := dyadicEvolution_terminal_gradient β hβ hγ hb t (1-t) + have hx : HasDerivAt (field β γ t) (m x) x := hd x + change |deriv (field β γ t) x| ≤ 1 + rw [hx.deriv] + exact hn x + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma gaussian_integral_neg {f : ℝ → ℝ} (hf : Measurable f) : + (∫ z,f (-z) ∂gaussianReal 0 1)=∫ z,f z ∂gaussianReal 0 1 := by + rw [← integral_map (by fun_prop : Measurable (fun z : ℝ => -z)).aemeasurable hf.aestronglyMeasurable, + gaussianReal_map_neg,neg_zero] + +lemma step_even {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (he : ∀ x,f (-x)=f x) (a s x : ℝ) : step a s f (-x)=step a s f x := by + have hpoint (z : ℝ) : f (-x+s*(-z))=f (x+s*z) := by + have hh : -x+s*(-z)=-(x+s*z) := by ring + rw [hh,he] + have hi := gaussian_integral_neg (hf.continuous.measurable.comp (by fun_prop : Measurable (fun z : ℝ => -x+s*z))) + have hie := gaussian_integral_neg (Real.measurable_exp.comp ((hf.continuous.measurable.comp + (by fun_prop : Measurable (fun z : ℝ => -x+s*z))).const_mul a)) + simp only [Function.comp_apply,hpoint] at hi hie + unfold step logMean + split_ifs + · exact hi.symm + · rw [← hie] + +lemma evolve_even {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (he : ∀ x,f (-x)=f x) (ls : Schedule) (x : ℝ) : evolve ls f (-x)=evolve ls f x := by + induction ls generalizing x with + | nil => exact he x + | cons l ls ih => + exact step_even (evolve_lipschitz hf ls) ih l.1 _ x + +lemma field_even (β : ℝ≥0) (hβ : 0<β) (γ : ℝ≥0 → ℝ≥0) (t : ℝ≥0) (x : ℝ) : + field β γ t (-x)=field β γ t x := by + unfold field dyadicEvolution + congr 1 + funext n + exact evolve_even (terminal_lipschitz hβ) (terminal_even β) _ x + +lemma fieldGradient_odd (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) (x : ℝ) : + fieldGradient β γ t (-x)= -fieldGradient β γ t x := by + have hd := (hasDerivAt_field β hβ hγ hb t (-x)).comp x (hasDerivAt_neg x) + have he : (fun y : ℝ => field β γ t (-y))=field β γ t := funext (field_even β hβ γ t) + change HasDerivAt (fun y : ℝ => field β γ t (-y)) (fieldGradient β γ t (-x)*(-1)) x at hd + rw [he] at hd + have hh := hd.unique (hasDerivAt_field β hβ hγ hb t x) + linarith + +lemma fieldGradient_zero (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) : + fieldGradient β γ t 0=0 := by + have hh := fieldGradient_odd β hβ hγ hb t 0 + rw [neg_zero] at hh + linarith + +lemma dyadicEvolution_zero_width {L : ℝ≥0} {f : ℝ → ℝ} (_hf : LipschitzWith L f) + (γ : ℝ≥0 → ℝ≥0) (t : ℝ≥0) (x : ℝ) : dyadicEvolution γ t 0 f x=f x := by + have hh (n : ℕ) : ∀ g : ℝ → ℝ,evolve (dyadicSchedule γ false t 0 n) g=g := by + induction n with + | zero => intro g; funext y; simp [dyadicSchedule,evolve] + | succ n ih => + intro g + simp only [dyadicSchedule,zero_div,add_zero,evolve_append,ih] + unfold dyadicEvolution + simp_rw [hh] + simp + +lemma field_terminal (β : ℝ≥0) (hβ : 0<β) (γ : ℝ≥0 → ℝ≥0) (x : ℝ) : + field β γ 1 x=Real.log (2*Real.cosh ((β:ℝ)*x))/β := by + unfold field + rw [tsub_self] + exact dyadicEvolution_zero_width (terminal_lipschitz hβ) γ 1 x + +lemma fieldGradient_terminal (β : ℝ≥0) (hβ : 0<β) (γ : ℝ≥0 → ℝ≥0) (x : ℝ) : + fieldGradient β γ 1 x=Real.tanh ((β:ℝ)*x) := by + have he : field β γ 1=terminal β := funext (field_terminal β hβ γ) + unfold fieldGradient + rw [he] + exact (hasDerivAt_terminal hβ x).deriv + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma curvature_gradient_monotone {β : ℝ≥0} {f : SmoothField} (hf : HasParisiCurvature β f) : + Monotone f.d1 := + monotone_of_hasDerivAt_nonneg f.hasD2 (fun x => (hf.2 x).1) + +lemma fieldGradient_monotone (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) : + Monotone (fieldGradient β γ t) := by + obtain ⟨m,hd,_,_,hu⟩ := dyadicEvolution_terminal_gradient β hβ hγ hb t (1-t) + intro x y hxy + have hm : m x ≤ m y := le_of_tendsto_of_tendsto (hu.tendsto_at x) (hu.tendsto_at y) + (Eventually.of_forall fun n => curvature_gradient_monotone + (smoothRecursion_hasParisiCurvature β hβ _ (dyadicSchedule_coeff_bound hb false t (1-t) n)) hxy) + have hx : HasDerivAt (field β γ t) (m x) x := hd x + have hy : HasDerivAt (field β γ t) (m y) y := hd y + change deriv (field β γ t) x ≤ deriv (field β γ t) y + rw [hx.deriv,hy.deriv] + exact hm + +lemma curvature_hamiltonian_bounds {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {a : ℝ} (ha : 0 ≤ a) (hab : a ≤ β) (x : ℝ) : + 0 ≤ f.d2 x+a*f.d1 x^2 ∧ f.d2 x+a*f.d1 x^2 ≤ β := by + constructor + · exact add_nonneg (hf.2 x).1 (mul_nonneg ha (sq_nonneg _)) + · have hh := (hf.2 x).2 + nlinarith [mul_nonneg (sub_nonneg.mpr hab) (sq_nonneg (f.d1 x))] + + + +lemma step_curvature_time_bound {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {a : ℝ} (ha : 0 ≤ a) (hab : a ≤ β) + (s : ℝ) (hs : 0 ≤ s) (x : ℝ) : + 0 ≤ step a s f.val x-f.val x ∧ step a s f.val x-f.val x ≤ (β:ℝ)*s^2/2 := by + let F (r : ℝ) := (f.transform a r).val x + let H (r : ℝ) := (f.transform a r).d2 x+a*((f.transform a r).d1 x)^2 + have hd (r : ℝ) : HasDerivAt F (r*H r) r := hasDerivAt_transform_scale f a r x + have hH (r : ℝ) : 0 ≤ H r ∧ H r ≤ β := + curvature_hamiltonian_bounds (transform_hasParisiCurvature hf ha hab r) ha hab x + have hF : F 0=f.val x := by + by_cases ha0 : a=0 <;> simp [F,SmoothField.transform,step,logMean,ha0] + have hlo : MonotoneOn F (Set.Ici 0) := monotoneOn_of_hasDerivWithinAt_nonneg (convex_Ici 0) + (fun r hr => (hd r).continuousAt.continuousWithinAt) + (fun r hr => (hd r).hasDerivWithinAt) + (fun r hr => mul_nonneg (show 0 ≤ r from (show 0 < r by simpa using hr).le) (hH r).1) + let G (r : ℝ) := F r-(β:ℝ)*r^2/2 + have hg (r : ℝ) : HasDerivAt G (r*H r-(β:ℝ)*r) r := by + convert (hd r).sub ((((hasDerivAt_id r).pow 2).const_mul (β:ℝ)).div_const 2) using 1 <;> + first | rfl | (simp only [Nat.cast_ofNat,mul_one,id_eq]; ring) + have hhi : AntitoneOn G (Set.Ici 0) := antitoneOn_of_hasDerivWithinAt_nonpos (convex_Ici 0) + (fun r hr => (hg r).continuousAt.continuousWithinAt) + (fun r hr => (hg r).hasDerivWithinAt) + (fun r hr => by + have hr' : 0 ≤ r := (show 0 < r by simpa using hr).le + have hh := mul_le_mul_of_nonneg_left (hH r).2 hr' + nlinarith) + have hl := hlo (by simp) (by simpa using hs) hs + have hh := hhi (by simp) (by simpa using hs) hs + dsimp [G] at hh + rw [hF] at hl hh + change f.val x ≤ step a s f.val x at hl + change step a s f.val x-(β:ℝ)*s^2/2 ≤ f.val x-(β:ℝ)*0^2/2 at hh + constructor <;> nlinarith + +lemma recursion_terminal_time_bound (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (ha : ∀ l∈ls,l.1 ≤ β) (x : ℝ) : + 0 ≤ recursion β ls x-terminal β x ∧ recursion β ls x-terminal β x ≤ (β:ℝ)*width ls/2 := by + induction ls with + | nil => simp [recursion,width] + | cons l ls ih => + have ht : ∀ k∈ls,k.1 ≤ β := fun k hk => ha k (List.mem_cons_of_mem _ hk) + have hb := step_curvature_time_bound (smoothRecursion_hasParisiCurvature β hβ ls ht) + l.1.coe_nonneg (by exact_mod_cast ha l (List.mem_cons_self)) (Real.sqrt l.2) (Real.sqrt_nonneg _) x + rw [smoothRecursion_val,Real.sq_sqrt l.2.coe_nonneg] at hb + have hh := ih ht + change 0 ≤ step l.1 (Real.sqrt l.2) (recursion β ls) x-terminal β x ∧ + step l.1 (Real.sqrt l.2) (recursion β ls) x-terminal β x ≤ (β:ℝ)*width (l::ls)/2 + have hw : width (l::ls)=(l.2:ℝ)+width ls := by simp [width] + rw [hw] + constructor <;> nlinarith [hb.1,hb.2,hh.1,hh.2] + +lemma field_terminal_time_bound (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) (x : ℝ) : + 0 ≤ field β γ t x-terminal β x ∧ field β γ t x-terminal β x ≤ (β:ℝ)*(1-t:ℝ≥0)/2 := by + have ht := (dyadic_low_tendsto (terminal_lipschitz hβ) hγ t (1-t) x).sub_const (terminal β x) + have he (n : ℕ) : 0 ≤ evolve (dyadicSchedule γ false t (1-t) n) (terminal β) x-terminal β x ∧ + evolve (dyadicSchedule γ false t (1-t) n) (terminal β) x-terminal β x ≤ (β:ℝ)*(1-t:ℝ≥0)/2 := by + have hh := recursion_terminal_time_bound β hβ _ (dyadicSchedule_coeff_bound hb false t (1-t) n) x + rwa [recursion_eq_evolve,dyadicSchedule_width] at hh + exact ⟨ge_of_tendsto ht (Eventually.of_forall fun n => (he n).1), + le_of_tendsto ht (Eventually.of_forall fun n => (he n).2)⟩ + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma dyadicEvolution_stable {L K : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) (hg : LipschitzWith K g) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (c : ℝ) + (hfg : ∀ x,|f x-g x| ≤ c) (x : ℝ) : + |dyadicEvolution γ t d f x-dyadicEvolution γ t d g x| ≤ c := by + apply le_of_tendsto (((dyadic_low_tendsto hf hγ t d x).sub (dyadic_low_tendsto hg hγ t d x)).abs) + exact Eventually.of_forall fun n => evolve_stable hf hg _ c hfg x + + + +lemma dyadicEvolution_half {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (t d : ℝ≥0) (x : ℝ) : + dyadicEvolution γ t d f x= + dyadicEvolution γ t (d/2) (dyadicEvolution γ (t+d/2) (d/2) f) x := by + let g := dyadicEvolution γ (t+d/2) (d/2) f + have hg : LipschitzWith 1 g := dyadicEvolution_lipschitz hf hγ _ _ + have hfull := (dyadic_low_tendsto hf hγ t d x).comp (tendsto_add_atTop_nat 1) + have hleft := dyadic_low_tendsto hg hγ t (d/2) x + have he : Tendsto (fun n => 2*gaussianSmallError β (Real.sqrt (dyadicMesh (d/2) n))) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero] using (gaussianSmallError_dyadic_tendsto β (d/2)).const_mul 2 + have hbnd (n : ℕ) : |evolve (dyadicSchedule γ false t d (n+1)) f x- + evolve (dyadicSchedule γ false t (d/2) n) g x| ≤ + 2*gaussianSmallError β (Real.sqrt (dyadicMesh (d/2) n)) := by + rw [dyadicSchedule,evolve_append] + exact evolve_stable (evolve_lipschitz hf _) hg _ _ + (fun y => dyadicEvolution_grid_bound hf hγ hb (t+d/2) (d/2) n y) x + have hzero : |dyadicEvolution γ t d f x-dyadicEvolution γ t (d/2) g x| ≤ 0 := + le_of_tendsto_of_tendsto ((hfull.sub hleft).abs) he (Eventually.of_forall hbnd) + exact sub_eq_zero.mp (abs_nonpos_iff.mp hzero) + +lemma field_half_DPP (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) + {t : ℝ≥0} (ht : t ≤ 1) (x : ℝ) : + field β γ t x=dyadicEvolution γ t ((1-t)/2) (field β γ (t+(1-t)/2)) x := by + have he : 1-(t+(1-t)/2)=(1-t)/2 := by + apply NNReal.coe_injective + rw [NNReal.coe_sub (by have hh : (1-t)/2 ≤ 1-t := div_le_self (show 0 ≤ 1-t from zero_le) (by norm_num); exact add_le_of_le_tsub_left_of_le ht hh), + NNReal.coe_add,NNReal.coe_div,NNReal.coe_ofNat,NNReal.coe_one,NNReal.coe_sub ht] + norm_num only [NNReal.coe_one] + ring + unfold field + rw [he] + exact dyadicEvolution_half (terminal_lipschitz hβ) hγ (fun s => by exact_mod_cast hb s) t (1-t) x + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + + + +def transitionMeasure (f : SmoothField) (a s x : ℝ) : Measure ℝ := + Measure.map (fun z : ℝ => x+s*z) ((gaussianReal 0 1).tilted (fun z => a*f.val (x+s*z))) + +instance transitionMeasure_probability (f : SmoothField) (a s x : ℝ) : + IsProbabilityMeasure (transitionMeasure f a s x) := by + let := isProbabilityMeasure_tilted (integrable_exp_shift f.lipschitz a x s) + unfold transitionMeasure + infer_instance + +lemma transition_integral (f : SmoothField) (a s x : ℝ) {g : ℝ → ℝ} (hg : Measurable g) : + ∫ y,g y ∂transitionMeasure f a s x=tiltedMean a s f.val g x := by + rw [transitionMeasure,integral_map (by fun_prop) hg.aestronglyMeasurable,integral_tilted] + simp only [smul_eq_mul,div_mul_eq_mul_div,integral_div,tiltedMean,expMoment,expMass] + + + +lemma transition_magnetization (f : SmoothField) (a s x : ℝ) : + ∫ y,f.d1 y ∂transitionMeasure f a s x=(f.transform a s).d1 x := by + exact transition_integral f a s x f.continuousD1.measurable + +lemma gaussian_density_ibp (f : SmoothField) (a s x : ℝ) : + (∫ z : ℝ,z*Real.exp (a*f.val (x+s*z)) ∂gaussianReal 0 1)=a*s*expMoment a s f.val f.d1 x := by + have hd (z : ℝ) : HasDerivAt (fun y => Real.exp (a*f.val (x+s*y))) + (a*s*(Real.exp (a*f.val (x+s*z))*f.d1 (x+s*z))) z := by + convert (((f.hasD1 (x+s*z)).comp z (((hasDerivAt_id z).const_mul s).const_add x)).const_mul a).exp using 1 <;> + first | rfl | (simp only [Function.comp_apply,id_eq,mul_one]; ring) + have hz : Integrable (fun z => z*Real.exp (a*f.val (x+s*z))) (gaussianReal 0 1) := by + simpa only [mul_one] using integrable_coord_exp_weight f.lipschitz continuous_const + (M := 1) (g := fun _ => (1:ℝ)) (by intro; norm_num) a s x + have hh := SKGaussian.integral_mul_eq_integral_deriv hd (integrable_exp_shift f.lipschitz a x s) + ((integrable_exp_weight f.lipschitz f.continuousD1 f.normD1 a s x).const_mul (a*s)) hz + rw [hh,integral_const_mul] + rfl + +lemma transition_increment_mean (f : SmoothField) (a s x : ℝ) : + (∫ y,y-x ∂transitionMeasure f a s x)=a*s^2*(f.transform a s).d1 x := by + rw [transition_integral f a s x (by fun_prop)] + unfold tiltedMean expMoment + have he (z : ℝ) : Real.exp (a*f.val (x+s*z))*((x+s*z)-x)= + s*(z*Real.exp (a*f.val (x+s*z))) := by ring + simp_rw [he] + rw [integral_const_mul,gaussian_density_ibp] + change s*(a*s*expMoment a s f.val f.d1 x)/expMass a s f.val x= + a*s^2*(expMoment a s f.val f.d1 x/expMass a s f.val x) + ring + +lemma integrable_sq_exp_shift {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (a s x : ℝ) : + Integrable (fun z : ℝ => z^2*Real.exp (a*f (x+s*z))) (gaussianReal 0 1) := by + have hc := hf.continuous + apply ((integrable_exp_abs (|a| *L*(|s|+1)+2)).const_mul (Real.exp (|a| *|f x|))).mono' (by fun_prop) + exact ae_of_all _ fun z => by + simp only [Real.norm_eq_abs,abs_mul,abs_pow,abs_of_pos (Real.exp_pos _)] + have hh := mul_le_mul_of_nonneg_left (coord_exp_scale_near_le hf a x s (s := s) (by simp) z) (abs_nonneg z) + have hh' := mul_le_mul_of_nonneg_left (abs_mul_exp_le (|a| *L*(|s|+1)+1) z) (Real.exp_pos (|a| *|f x|)).le + have e : |a| *(L:ℝ)*(|s|+1)+1+1=|a| *L*(|s|+1)+2 := by ring + rw [e] at hh' + nlinarith + +lemma gaussian_density_second_moment (f : SmoothField) (a s x : ℝ) : + (∫ z : ℝ,z^2*Real.exp (a*f.val (x+s*z)) ∂gaussianReal 0 1)= + expMass a s f.val x+a*s^2*(expMoment a s f.val f.d2 x+a*expMoment a s f.val (fun y => f.d1 y^2) x) := by + have hd (z : ℝ) : HasDerivAt (fun y => y*Real.exp (a*f.val (x+s*y))) + (Real.exp (a*f.val (x+s*z))+a*s*(z*(Real.exp (a*f.val (x+s*z))*f.d1 (x+s*z)))) z := by + have hv := (((f.hasD1 (x+s*z)).comp z + (((hasDerivAt_id z).const_mul s).const_add x)).const_mul a).exp + convert (hasDerivAt_id z).mul hv using 1 <;> + first | rfl | (simp only [Function.comp_apply,id_eq,mul_one,one_mul]; ring) + have hz : Integrable (fun z => z*Real.exp (a*f.val (x+s*z))) (gaussianReal 0 1) := by + simpa only [mul_one] using integrable_coord_exp_weight f.lipschitz continuous_const + (M := 1) (g := fun _ => (1:ℝ)) (by intro; norm_num) a s x + have hm := integrable_coord_exp_weight f.lipschitz f.continuousD1 f.normD1 a s x + have hs : Integrable (fun z => z*(z*Real.exp (a*f.val (x+s*z)))) (gaussianReal 0 1) := by + simpa only [pow_two,mul_assoc] using integrable_sq_exp_shift f.lipschitz a s x + have hh := SKGaussian.integral_mul_eq_integral_deriv hd hz + ((integrable_exp_shift f.lipschitz a x s).add (hm.const_mul (a*s))) hs + have he (z : ℝ) : z*(z*Real.exp (a*f.val (x+s*z)))=z^2*Real.exp (a*f.val (x+s*z)) := by ring + simp only [he] at hh + rw [hh,integral_add (integrable_exp_shift f.lipschitz a x s) (hm.const_mul (a*s)),integral_const_mul, + gaussian_tilt_ibp] + change expMass a s f.val x+a*s*(s*_) = _ + ring + +lemma transition_increment_second_moment (f : SmoothField) (a s x : ℝ) : + (∫ y,(y-x)^2 ∂transitionMeasure f a s x)=s^2+a*s^4* + ((f.transform a s).d2 x+a*((f.transform a s).d1 x)^2) := by + rw [transition_integral f a s x (by fun_prop)] + unfold tiltedMean expMoment + have he (z : ℝ) : Real.exp (a*f.val (x+s*z))*((x+s*z)-x)^2= + s^2*(z^2*Real.exp (a*f.val (x+s*z))) := by ring + simp_rw [he] + rw [integral_const_mul,gaussian_density_second_moment] + dsimp [SmoothField.transform,tiltedMean] + have hp := (expMass_pos f.lipschitz a s x).ne' + field_simp + ring + + + +lemma transition_increment_bounds {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {a : ℝ} (ha : 0 ≤ a) (hab : a ≤ β) (s x : ℝ) : + |∫ y,y-x ∂transitionMeasure f a s x| ≤ a*s^2 ∧ + s^2 ≤ (∫ y,(y-x)^2 ∂transitionMeasure f a s x) ∧ + (∫ y,(y-x)^2 ∂transitionMeasure f a s x) ≤ s^2+a*(β:ℝ)*s^4 := by + rw [transition_increment_mean,transition_increment_second_moment] + have hc := transform_hasParisiCurvature hf ha hab s + have hm := (f.transform a s).normD1 x + rw [hc.1,NNReal.coe_one] at hm + have hH := curvature_hamiltonian_bounds hc ha hab x + refine ⟨?_,?_,?_⟩ + · rw [abs_mul,abs_of_nonneg (mul_nonneg ha (sq_nonneg _))] + nlinarith [mul_le_mul_of_nonneg_left hm (mul_nonneg ha (sq_nonneg s))] + · exact le_add_of_nonneg_right (mul_nonneg (mul_nonneg ha (by positivity : 0 ≤ s^4)) hH.1) + · nlinarith [mul_le_mul_of_nonneg_left hH.2 (mul_nonneg ha (by positivity : 0 ≤ s^4))] + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + + +def noiseTiltKernel (f : SmoothField) (a s : ℝ) : Kernel ℝ ℝ := + (Kernel.const ℝ (gaussianReal 0 1)).withDensity + (fun x z => ENNReal.ofReal (Real.exp (a*f.val (x+s*z))/expMass a s f.val x)) + +lemma measurable_noise_density (f : SmoothField) (a s : ℝ) : + Measurable (fun p : ℝ × ℝ => ENNReal.ofReal (Real.exp (a*f.val (p.1+s*p.2))/expMass a s f.val p.1)) := by + have hm : Continuous (expMass a s f.val) := continuous_iff_continuousAt.mpr + (fun x => (hasDerivAt_expMass f a s x).continuousAt) + have hf := f.lipschitz.continuous + fun_prop + +lemma noiseTiltKernel_apply (f : SmoothField) (a s x : ℝ) : + noiseTiltKernel f a s x=(gaussianReal 0 1).tilted (fun z => a*f.val (x+s*z)) := by + rw [noiseTiltKernel,Kernel.withDensity_apply _ (measurable_noise_density f a s)] + rfl + +instance noiseTiltKernel_markov (f : SmoothField) (a s : ℝ) : IsMarkovKernel (noiseTiltKernel f a s) where + isProbabilityMeasure x := by + rw [noiseTiltKernel_apply] + exact isProbabilityMeasure_tilted (integrable_exp_shift f.lipschitz a x s) + + +def transitionKernel (f : SmoothField) (a s : ℝ) : Kernel ℝ ℝ := + (Kernel.id ×ₖ noiseTiltKernel f a s).map (fun p : ℝ × ℝ => p.1+s*p.2) + +instance transitionKernel_markov (f : SmoothField) (a s : ℝ) : IsMarkovKernel (transitionKernel f a s) := by + unfold transitionKernel + exact Kernel.IsMarkovKernel.map _ (by fun_prop) + +lemma transitionKernel_apply (f : SmoothField) (a s x : ℝ) : + transitionKernel f a s x=transitionMeasure f a s x := by + rw [transitionKernel,Kernel.map_apply _ (by fun_prop),Kernel.prod_apply,Kernel.id_apply, + noiseTiltKernel_apply,Measure.dirac_prod,Measure.map_map (by fun_prop) (by fun_prop)] + rfl + + + +def evolutionKernel (β : ℝ≥0) (hβ : 0<β) : Schedule → Kernel ℝ ℝ + | [] => Kernel.id + | l::ls => evolutionKernel β hβ ls ∘ₖ + transitionKernel (smoothRecursion β hβ ls) l.1 (Real.sqrt l.2) + +instance evolutionKernel_markov (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) : + IsMarkovKernel (evolutionKernel β hβ ls) := by + induction ls with + | nil => dsimp [evolutionKernel]; infer_instance + | cons l ls ih => + let := ih + dsimp only [evolutionKernel] + infer_instance + +lemma integrable_smooth_d1 (f : SmoothField) (μ : Measure ℝ) [IsFiniteMeasure μ] : + Integrable f.d1 μ := by + exact (integrable_const (f.bound1:ℝ)).mono' f.continuousD1.aestronglyMeasurable + (ae_of_all _ fun x => f.normD1 x) + + + +lemma evolution_magnetization (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (x : ℝ) : + (∫ y,(terminalField β hβ).d1 y ∂evolutionKernel β hβ ls x)= + (smoothRecursion β hβ ls).d1 x := by + induction ls generalizing x with + | nil => simp [evolutionKernel,smoothRecursion,Kernel.id_apply] + | cons l ls ih => + rw [evolutionKernel,Kernel.integral_comp (integrable_smooth_d1 _ _)] + simp_rw [ih] + rw [transitionKernel_apply,transition_magnetization] + rfl + +lemma evolution_tanh (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (x : ℝ) : + (∫ y,Real.tanh ((β:ℝ)*y) ∂evolutionKernel β hβ ls x)= + (smoothRecursion β hβ ls).d1 x := evolution_magnetization β hβ ls x + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + +lemma integrable_transition_sq (f : SmoothField) (a s x : ℝ) : + Integrable (fun y : ℝ => y^2) (transitionMeasure f a s x) := by + unfold transitionMeasure + rw [integrable_map_measure (by fun_prop) (by fun_prop),integrable_tilted_iff + (integrable_exp_shift f.lipschitz a x s)] + have h0 := integrable_exp_shift f.lipschitz a x s + have h1 : Integrable (fun z => z*Real.exp (a*f.val (x+s*z))) (gaussianReal 0 1) := by + simpa only [mul_one] using integrable_coord_exp_weight f.lipschitz continuous_const + (M := 1) (g := fun _ => (1:ℝ)) (by intro; norm_num) a s x + have h2 := integrable_sq_exp_shift f.lipschitz a s x + convert ((h0.const_mul (x^2)).add (h1.const_mul (2*x*s))).add (h2.const_mul (s^2)) using 1 + all_goals first | rfl | (ext z; simp only [Function.comp_apply,smul_eq_mul,Pi.add_apply]; ring) + +lemma integrable_transition_id (f : SmoothField) (a s x : ℝ) : + Integrable (fun y : ℝ => y) (transitionMeasure f a s x) := by + apply ((integrable_const (1:ℝ)).add (integrable_transition_sq f a s x)).mono' (by fun_prop) + exact ae_of_all _ fun y => by + simp only [Real.norm_eq_abs,Pi.add_apply] + nlinarith [sq_nonneg (|y|-1),sq_abs y] + +lemma integrable_transition_increment (f : SmoothField) (a s x : ℝ) : + Integrable (fun y : ℝ => y-x) (transitionMeasure f a s x) := + (integrable_transition_id f a s x).sub (integrable_const x) + +lemma integrable_transition_increment_sq (f : SmoothField) (a s x : ℝ) : + Integrable (fun y : ℝ => (y-x)^2) (transitionMeasure f a s x) := by + convert ((integrable_transition_sq f a s x).sub ((integrable_transition_id f a s x).const_mul (2*x))).add + (integrable_const (x^2)) using 1 + all_goals first | rfl | (ext y; simp only [Pi.sub_apply,Pi.add_apply]; ring) + +lemma transition_source_second_moment (f : SmoothField) (a s x : ℝ) : + (∫ y,y^2 ∂transitionMeasure f a s x)=x^2+2*x*(a*s^2*(f.transform a s).d1 x)+s^2+ + a*s^4*((f.transform a s).d2 x+a*((f.transform a s).d1 x)^2) := by + have he : (fun y : ℝ => y^2)=(fun y => x^2+2*x*(y-x)+(y-x)^2) := by funext y; ring + rw [he] + have hi : Integrable (fun y => x^2+2*x*(y-x)) (transitionMeasure f a s x) := + (integrable_const (x^2)).add ((integrable_transition_increment f a s x).const_mul (2*x)) + rw [integral_add hi (integrable_transition_increment_sq f a s x),integral_add (integrable_const (x^2)) + ((integrable_transition_increment f a s x).const_mul (2*x)),integral_const_mul, + transition_increment_mean,transition_increment_second_moment] + simp only [integral_const,Measure.real,measure_univ,ENNReal.toReal_one,one_smul] + ring + + + +lemma transition_lyapunov_bound {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {a : ℝ} (ha : 0 ≤ a) (hab : a ≤ β) + {d : ℝ≥0} (hd : d ≤ 1) (x : ℝ) : + (∫ y,1+y^2 ∂transitionMeasure f a (Real.sqrt d) x) ≤ + Real.exp ((2+2*(β:ℝ)^2)*d)*(1+x^2) := by + rw [integral_add (integrable_const (1:ℝ)) (integrable_transition_sq _ _ _ _), + integral_const,Measure.real,measure_univ,ENNReal.toReal_one,one_smul,transition_source_second_moment] + have hs : Real.sqrt (d:ℝ)^2=(d:ℝ) := Real.sq_sqrt d.coe_nonneg + have hs4 : Real.sqrt (d:ℝ)^4=(d:ℝ)^2 := by nlinarith [sq_nonneg (Real.sqrt (d:ℝ)^2-(d:ℝ))] + rw [hs,hs4] + have hc := transform_hasParisiCurvature hf ha hab (Real.sqrt d) + have hm := (f.transform a (Real.sqrt d)).normD1 x + rw [hc.1,NNReal.coe_one] at hm + have hh := curvature_hamiltonian_bounds hc ha hab x + have habsq : a^2≤(β:ℝ)^2 := by nlinarith [β.coe_nonneg] + have hmul := mul_le_mul_of_nonneg_left hh.2 (mul_nonneg ha (sq_nonneg (d:ℝ))) + have hxx : 2*x*a*(f.transform a (Real.sqrt d)).d1 x ≤ x^2+(β:ℝ)^2 := by + have hs1 : ((f.transform a (Real.sqrt d)).d1 x)^2 ≤ 1 := by + rw [abs_le] at hm + nlinarith + nlinarith [sq_nonneg (x-a*(f.transform a (Real.sqrt d)).d1 x), + mul_le_mul_of_nonneg_left hs1 (sq_nonneg a)] + have hc0 : 0≤2+2*(β:ℝ)^2 := by positivity + have hd' : (d:ℝ)≤1 := hd + have hb0 := β.coe_nonneg + have hbase : 1+x^2+2*x*(a*(d:ℝ)*(f.transform a (Real.sqrt d)).d1 x)+(d:ℝ)+ + a*(d:ℝ)^2*((f.transform a (Real.sqrt d)).d2 x+a*((f.transform a (Real.sqrt d)).d1 x)^2) ≤ + (1+(2+2*(β:ℝ)^2)*d)*(1+x^2) := by + have hhx := mul_le_mul_of_nonneg_left hxx d.coe_nonneg + have had := mul_le_mul_of_nonneg_right hab (mul_nonneg (β:ℝ≥0).coe_nonneg (sq_nonneg (d:ℝ))) + have hdd := mul_le_mul_of_nonneg_left (show (d:ℝ)^2≤d by nlinarith [d.coe_nonneg]) (sq_nonneg (β:ℝ)) + have hpos := mul_nonneg (mul_nonneg hc0 d.coe_nonneg) (sq_nonneg x) + nlinarith [mul_nonneg (sq_nonneg (β:ℝ)) d.coe_nonneg, + mul_nonneg d.coe_nonneg (sq_nonneg x)] + simpa only [add_assoc] using hbase.trans (mul_le_mul_of_nonneg_right (by simpa only [add_comm] using Real.add_one_le_exp ((2+2*(β:ℝ)^2)*d)) (by positivity)) + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/DyadicMeshTendsto.lean b/lean/OAI/Probability/ParisiFinite/DyadicMeshTendsto.lean new file mode 100644 index 0000000000000000000000000000000000000000..0e0a88bf5937cc156226bb0fe52851e8c6b5846d --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/DyadicMeshTendsto.lean @@ -0,0 +1,729 @@ +import Mathlib +import OAI.Probability.ParisiFinite.OverlapDiscountMono + +namespace OAI + +/-! Dyadic Mesh Tendsto. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma dyadicMesh_tendsto (d : ℝ≥0) : + Tendsto (fun n => (dyadicMesh d n:ℝ)) atTop (𝓝 0) := by + have hp := tendsto_pow_atTop_atTop_of_one_lt (show (1:ℝ)<2 by norm_num) + have hh := (tendsto_inv_atTop_zero.comp hp).const_mul (d:ℝ) + change Tendsto (fun n : ℕ => (d:ℝ)/(2:ℝ)^n) atTop (𝓝 0) + simpa only [Function.comp_def,div_eq_mul_inv,mul_zero] using hh + +lemma dyadicMesh_le (d : ℝ≥0) (n : ℕ) : dyadicMesh d n≤d := by + apply div_le_self (show 0≤d from zero_le) + exact one_le_pow₀ (by norm_num : (1:ℝ≥0)≤2) + +lemma gaussianSmallError_dyadic_tendsto (β : ℝ) (d : ℝ≥0) : + Tendsto (fun n => gaussianSmallError β (Real.sqrt (dyadicMesh d n))) atTop (𝓝 0) := by + let s (n : ℕ) := Real.sqrt (dyadicMesh d n) + let L : ℝ≥0 := Real.toNNReal (Real.sqrt d) + have hs (n : ℕ) : |s n|≤Real.sqrt d := by + rw [abs_of_nonneg (Real.sqrt_nonneg _)] + exact Real.sqrt_le_sqrt (by exact_mod_cast dyadicMesh_le d n) + have ht : Tendsto s atTop (𝓝 (0:ℝ)) := by + simpa only [Real.sqrt_zero,Function.comp_def,s] using Real.continuous_sqrt.continuousAt.tendsto.comp (dyadicMesh_tendsto d) + have hF (n : ℕ) : LipschitzWith L (fun z : ℝ => |s n| * |z|) := + (abs_scaled_lipschitz (s n)).weaken (Real.toNNReal_mono (hs n)) + have hf : LipschitzWith L (fun _ : ℝ => (0:ℝ)) := (LipschitzWith.const (0:ℝ)).weaken (by positivity) + have hh := step_tendsto hF hf (fun z => by simpa using (ht.abs).mul_const |z|) β 1 0 + simpa only [step,zero_add,one_mul,logMean_const,gaussianSmallError,s] using hh + + + +def dyadicEvolution (γ : ℝ≥0 → ℝ≥0) (t d : ℝ≥0) (f : ℝ → ℝ) (x : ℝ) : ℝ := + ⨆ n : ℕ,evolve (dyadicSchedule γ false t d n) f x + +lemma dyadic_low_monotone {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (x : ℝ) : + Monotone (fun n => evolve (dyadicSchedule γ false t d n) f x) := + monotone_nat_of_le_succ (fun n => dyadicSchedule_low_refine hf hγ t d n x) + +lemma dyadic_high_antitone {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (x : ℝ) : + Antitone (fun n => evolve (dyadicSchedule γ true t d n) f x) := + antitone_nat_of_succ_le (fun n => dyadicSchedule_high_refine hf hγ t d n x) + +lemma dyadic_low_bddAbove {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (x : ℝ) : + BddAbove (Set.range (fun n => evolve (dyadicSchedule γ false t d n) f x)) := by + refine ⟨evolve (dyadicSchedule γ true t d 0) f x,?_⟩ + rintro _ ⟨n,rfl⟩ + exact (dyadicSchedule_low_le_high hf hγ t d n x).trans (dyadic_high_antitone hf hγ t d x (Nat.zero_le n)) + +lemma dyadic_low_tendsto {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (x : ℝ) : + Tendsto (fun n => evolve (dyadicSchedule γ false t d n) f x) atTop + (𝓝 (dyadicEvolution γ t d f x)) := + tendsto_atTop_ciSup (dyadic_low_monotone hf hγ t d x) (dyadic_low_bddAbove hf hγ t d x) + +lemma dyadic_high_tendsto {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ)≤β) + (t d : ℝ≥0) (x : ℝ) : + Tendsto (fun n => evolve (dyadicSchedule γ true t d n) f x) atTop + (𝓝 (dyadicEvolution γ t d f x)) := by + have he : Tendsto (fun n => 2*gaussianSmallError β (Real.sqrt (dyadicMesh d n))) atTop (𝓝 (0:ℝ)) := by + simpa using (gaussianSmallError_dyadic_tendsto β d).const_mul 2 + have hl := dyadic_low_tendsto hf hγ t d x + apply tendsto_of_tendsto_of_tendsto_of_le_of_le hl + (by simpa only [add_zero] using hl.add he) + · exact fun n => dyadicSchedule_low_le_high hf hγ t d n x + · intro n + have hh := (abs_le.mp (dyadicSchedule_grid_error hb t d n hf x)).1 + linarith + +lemma dyadicEvolution_lipschitz {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) : + LipschitzWith L (dyadicEvolution γ t d f) := by + apply LipschitzWith.of_dist_le_mul + intro x y + apply le_of_tendsto ((dyadic_low_tendsto hf hγ t d x).dist (dyadic_low_tendsto hf hγ t d y)) + exact Eventually.of_forall fun n => (evolve_lipschitz hf _).dist_le_mul x y + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +def uniformLower (γ : ℝ≥0 → ℝ≥0) (t d : ℝ≥0) (N : ℕ) : Schedule := + List.ofFn (fun k : Fin N => (γ (t+d*(k.val:ℝ≥0)/N),d/N)) + +lemma dyadicSchedule_eq_uniform (γ : ℝ≥0 → ℝ≥0) (t d : ℝ≥0) (n : ℕ) : + dyadicSchedule γ false t d n=uniformLower γ t d (2^n) := by + induction n generalizing t d with + | zero => simp [dyadicSchedule,uniformLower,List.ofFn_succ] + | succ n ih => + have he : 2^(n+1)=2^n+2^n := by rw [pow_succ]; omega + rw [dyadicSchedule,ih,ih,he] + unfold uniformLower + rw [List.ofFn_add] + congr 1 + · apply congrArg List.ofFn + funext k + simp only [Fin.val_castLE,Nat.cast_add] + apply Prod.ext + · apply congrArg γ + ring + · ring + · apply congrArg List.ofFn + funext k + simp only [Fin.val_natAdd,Nat.cast_add] + apply Prod.ext + · apply congrArg γ + have hn : ((2^n:ℕ):ℝ≥0)≠0 := by positivity + field_simp + ring + · ring + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma width_append (ls rs : Schedule) : width (ls++rs)=width ls+width rs := by simp [width] +lemma width_cons (a d : ℝ≥0) (ls : Schedule) : width ((a,d)::ls)=(d:ℝ)+width ls := by simp [width] +lemma penalty_append (t : ℝ) (ls rs : Schedule) : + penalty t (ls++rs)=penalty t ls+penalty (t+width ls) rs := by + induction ls generalizing t with + | nil => simp [penalty,width] + | cons l ls ih => + rcases l with ⟨a,d⟩ + simp only [List.cons_append,penalty,ih,width_cons,add_assoc] + +lemma dyadicSchedule_width (γ : ℝ≥0 → ℝ≥0) (u : Bool) (t d : ℝ≥0) (n : ℕ) : + width (dyadicSchedule γ u t d n)=d := by + induction n generalizing t d with + | zero => simp [dyadicSchedule,width] + | succ n ih => rw [dyadicSchedule,width_append,ih,ih]; change (d:ℝ)/2+d/2=d; ring + +lemma dyadic_penalty_succ (γ : ℝ≥0 → ℝ≥0) (u : Bool) (t d : ℝ≥0) (n : ℕ) : + penalty t (dyadicSchedule γ u t d (n+1))= + penalty t (dyadicSchedule γ u t (d/2) n)+penalty (t+d/2) (dyadicSchedule γ u (t+d/2) (d/2) n) := by + rw [dyadicSchedule,penalty_append,dyadicSchedule_width] + rfl + + +def coefficientPenalty (γ : ℝ≥0 → ℝ≥0) (t d : ℝ≥0) : ℝ := + ∫ s in (t:ℝ)..(t+d:ℝ≥0), s*(γ (Real.toNNReal s):ℝ)/2 + +lemma coefficient_integrable {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (a b : ℝ) : + IntervalIntegrable (fun s => s*(γ (Real.toNNReal s):ℝ)/2) volume a b := by + have hm : Monotone (fun s : ℝ => (γ (Real.toNNReal s):ℝ)) := + fun x y hxy => by exact_mod_cast hγ (Real.toNNReal_mono hxy) + exact (hm.intervalIntegrable.continuousOn_mul continuous_id.continuousOn).div_const 2 + +lemma coefficientPenalty_split {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) : + coefficientPenalty γ t d=coefficientPenalty γ t (d/2)+coefficientPenalty γ (t+d/2) (d/2) := by + have he : t+d/2+d/2=t+d := by ring + simp only [coefficientPenalty,he] + exact (intervalIntegral.integral_add_adjacent_intervals (coefficient_integrable hγ _ _) + (coefficient_integrable hγ _ _)).symm + +lemma constant_coefficient_integral (a t d : ℝ) : + (∫ s in t..t+d,s*a/2)=a*((t+d)^2-t^2)/4 := by + rw [intervalIntegral.integral_div,intervalIntegral.integral_mul_const,integral_id] + ring + +lemma coefficientPenalty_base_bounds {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) : + (γ t:ℝ)*(((t:ℝ)+d)^2-t^2)/4≤coefficientPenalty γ t d ∧ + coefficientPenalty γ t d≤(γ (t+d):ℝ)*(((t:ℝ)+d)^2-t^2)/4 := by + have hab : (t:ℝ)≤(t+d:ℝ≥0) := by change (t:ℝ)≤t+d; linarith [d.coe_nonneg] + have hi (a : ℝ) : IntervalIntegrable (fun s : ℝ => s*a/2) volume (t:ℝ) (t+d:ℝ≥0) := + (by fun_prop : Continuous (fun s : ℝ => s*a/2)).intervalIntegrable _ _ + constructor + · rw [← constant_coefficient_integral] + exact intervalIntegral.integral_mono_on hab (hi _) (coefficient_integrable hγ _ _) (fun s hs => by + have hts : t≤Real.toNNReal s := by exact_mod_cast (show (t:ℝ)≤(Real.toNNReal s:ℝ) by rw [Real.coe_toNNReal _ (t.coe_nonneg.trans hs.1)]; exact hs.1) + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (by exact_mod_cast hγ hts) (t.coe_nonneg.trans hs.1)) (by norm_num)) + · rw [← constant_coefficient_integral] + exact intervalIntegral.integral_mono_on hab (coefficient_integrable hγ _ _) (hi _) (fun s hs => by + have hst : Real.toNNReal s≤t+d := by exact_mod_cast (show (Real.toNNReal s:ℝ)≤(t+d:ℝ≥0) by rw [Real.coe_toNNReal _ (t.coe_nonneg.trans hs.1)]; exact hs.2) + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (by exact_mod_cast hγ hst) (t.coe_nonneg.trans hs.1)) (by norm_num)) + +lemma dyadic_penalty_bounds {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (n : ℕ) : + penalty t (dyadicSchedule γ false t d n)≤coefficientPenalty γ t d ∧ + coefficientPenalty γ t d≤penalty t (dyadicSchedule γ true t d n) := by + induction n generalizing t d with + | zero => simpa [dyadicSchedule,penalty] using coefficientPenalty_base_bounds hγ t d + | succ n ih => + rw [dyadic_penalty_succ,dyadic_penalty_succ,coefficientPenalty_split hγ] + exact ⟨add_le_add (ih t (d/2)).1 (ih (t+d/2) (d/2)).1, + add_le_add (ih t (d/2)).2 (ih (t+d/2) (d/2)).2⟩ + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma dyadic_penalty_difference {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (n : ℕ) : + penalty t (dyadicSchedule γ true t d n)-penalty t (dyadicSchedule γ false t d n)≤ + ((t:ℝ)+d)*(dyadicMesh d n:ℝ)*((γ (t+d):ℝ)-γ t)/2 := by + induction n generalizing t d with + | zero => + have ha : (γ t:ℝ)≤γ (t+d) := by exact_mod_cast hγ (le_add_of_nonneg_right (show 0≤d from zero_le)) + simp [dyadicSchedule,penalty,dyadicMesh] + nlinarith [mul_nonneg (sub_nonneg.mpr ha) (sq_nonneg (d:ℝ))] + | succ n ih => + have h1 := ih t (d/2) + have h2 := ih (t+d/2) (d/2) + have ht : t+d/2+d/2=t+d := by ring + have ha : (γ t:ℝ)≤γ (t+d/2) := by exact_mod_cast hγ (le_add_of_nonneg_right (show 0≤d/2 from zero_le)) + rw [ht] at h2 + rw [dyadic_penalty_succ,dyadic_penalty_succ,dyadicMesh_succ] + have hdm : 0≤(dyadicMesh (d/2) n:ℝ) := (dyadicMesh (d/2) n).coe_nonneg + have hu : ((t:ℝ)+d/2)*(dyadicMesh (d/2) n:ℝ)*((γ (t+d/2):ℝ)-γ t)/2≤ + ((t:ℝ)+d)*(dyadicMesh (d/2) n:ℝ)*((γ (t+d/2):ℝ)-γ t)/2 := by + apply div_le_div_of_nonneg_right _ (by norm_num) + apply mul_le_mul_of_nonneg_right _ (sub_nonneg.mpr ha) + exact mul_le_mul_of_nonneg_right (by linarith [d.coe_nonneg]) hdm + have he : (t:ℝ)+(d/2:ℝ≥0)+(d/2:ℝ≥0)=(t:ℝ)+d := by change (t:ℝ)+d/2+d/2=t+d; ring + have hc : (t+d/2:ℝ≥0)=(t:ℝ)+d/2 := rfl + rw [hc] at h2 + rw [show ((d/2:ℝ≥0):ℝ)=(d:ℝ)/2 from rfl] at h1 h2 + have he' : (t:ℝ)+d/2+d/2=t+d := by ring + rw [he'] at h2 + linarith + +lemma dyadic_penalty_error {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} + (hb : ∀ s,(γ s:ℝ)≤β) (t d : ℝ≥0) (n : ℕ) : + |coefficientPenalty γ t d-penalty t (dyadicSchedule γ false t d n)|≤ + ((t:ℝ)+d)*(dyadicMesh d n:ℝ)*β/2 := by + have hbounds := dyadic_penalty_bounds hγ t d n + rw [abs_of_nonneg (sub_nonneg.mpr hbounds.1)] + have he := dyadic_penalty_difference hγ t d n + have hc : (γ (t+d):ℝ)-γ t≤β := by linarith [hb (t+d),(γ t).coe_nonneg] + have hd : ((t:ℝ)+d)*(dyadicMesh d n:ℝ)*((γ (t+d):ℝ)-γ t)/2≤ + ((t:ℝ)+d)*(dyadicMesh d n:ℝ)*β/2 := by + apply div_le_div_of_nonneg_right _ (by norm_num) + exact mul_le_mul_of_nonneg_left hc (mul_nonneg (add_nonneg t.coe_nonneg d.coe_nonneg) (dyadicMesh d n).coe_nonneg) + linarith + +lemma dyadic_penalty_tendsto {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} + (hb : ∀ s,(γ s:ℝ)≤β) (t d : ℝ≥0) : + Tendsto (fun n => penalty t (dyadicSchedule γ false t d n)) atTop (𝓝 (coefficientPenalty γ t d)) := by + have herr : Tendsto (fun n => ((t:ℝ)+d)*(dyadicMesh d n:ℝ)*β/2) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero,zero_mul,zero_div] using (((dyadicMesh_tendsto d).const_mul ((t:ℝ)+d)).mul_const β).div_const 2 + apply tendsto_of_tendsto_of_tendsto_of_le_of_le + (by simpa only [sub_zero] using tendsto_const_nhds.sub herr) tendsto_const_nhds + · intro n + have hh := (abs_le.mp (dyadic_penalty_error hγ hb t d n)).2 + linarith + · exact fun n => (dyadic_penalty_bounds hγ t d n).1 + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + + + +def orderParameterFunctional (β : ℝ) (γ : ℝ≥0 → ℝ≥0) : ℝ := + dyadicEvolution γ 0 1 (terminal β) 0-coefficientPenalty γ 0 1 + +lemma dyadic_admissible {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} + (hb : ∀ s,(γ s:ℝ)≤β) (n : ℕ) : Admissible β (dyadicSchedule γ false 0 1 n) := by + refine ⟨dyadicSchedule_width γ false 0 1 n,?_,?_⟩ + · rw [dyadicSchedule_eq_uniform] + apply List.pairwise_ofFn.mpr + intro i j hij + apply hγ + gcongr + exact_mod_cast hij.le + · rw [dyadicSchedule_eq_uniform] + intro l hl + obtain ⟨k,rfl⟩ := List.mem_ofFn.mp hl + exact hb _ + +lemma dyadic_functional_tendsto {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} + (hβ : 0<β) (hb : ∀ s,(γ s:ℝ)≤β) : + Tendsto (fun n => functional β (dyadicSchedule γ false 0 1 n)) atTop + (𝓝 (orderParameterFunctional β γ)) := by + have hr := dyadic_low_tendsto (terminal_lipschitz hβ) hγ 0 1 0 + have hp := dyadic_penalty_tendsto hγ hb 0 1 + simpa only [functional,recursion_eq_evolve,orderParameterFunctional,NNReal.coe_zero] using hr.sub hp + +lemma limitingFreeEnergy_le_orderParameterFunctional {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) + {β : ℝ} (hβ : 0<β) (hb : ∀ s,(γ s:ℝ)≤β) : + SKQAOA.limitingFreeEnergy β≤orderParameterFunctional β γ := by + apply ge_of_tendsto (dyadic_functional_tendsto hγ hβ hb) + exact Eventually.of_forall fun n => by + simpa only [Real.coe_toNNReal β hβ.le] using + ParisiGuerra.limitingFreeEnergy_le_functional (Real.toNNReal β) (Real.toNNReal_pos.mpr hβ) + (dyadicSchedule γ false 0 1 n) (by simpa only [Real.coe_toNNReal β hβ.le] using dyadic_admissible hγ hb n) + +end ParisiFinite +namespace SKCavity +open ParisiFinite SKQAOA + +def overlapCDFCoefficient (μ : ProbabilityMeasure OverlapArray) (β : ℝ≥0) (s : ℝ≥0) : ℝ≥0 := + Real.toNNReal (overlapDiscount μ s)*β + +lemma overlapCDFCoefficient_mono (μ : ProbabilityMeasure OverlapArray) (β : ℝ≥0) : + Monotone (overlapCDFCoefficient μ β) := by + intro x y hxy + exact mul_le_mul_of_nonneg_right (Real.toNNReal_mono (overlapDiscount_mono μ (by exact_mod_cast hxy))) (by positivity) + +lemma overlapCDFCoefficient_bound (μ : ProbabilityMeasure OverlapArray) (β : ℝ≥0) (s : ℝ≥0) : + (overlapCDFCoefficient μ β s:ℝ)≤β := by + change (Real.toNNReal (overlapDiscount μ s):ℝ)*(β:ℝ)≤β + rw [Real.coe_toNNReal (overlapDiscount μ s) (show 0≤overlapDiscount μ s from measureReal_nonneg)] + nlinarith [overlapDiscount_le_one μ s,β.coe_nonneg] + +lemma dyadic_CDF_schedule (μ : ProbabilityMeasure OverlapArray) (β : ℝ≥0) (n : ℕ) : + dyadicSchedule (overlapCDFCoefficient μ β) false 0 1 n=gridSchedule μ β (2^n-1) := by + have hN : 1≤2^n := one_le_pow₀ (by norm_num) + have hdim : 2^n-1+1=2^n := Nat.sub_add_cancel hN + rw [dyadicSchedule_eq_uniform,← hdim] + unfold uniformLower gridSchedule + apply congrArg List.ofFn + funext k + apply Prod.ext + · simp only [zero_add,one_mul,overlapCDFCoefficient,cavityGrid,Fin.cons_succ] + rfl + · rfl + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +abbrev OrderPoint := Set.Icc (0:ℝ) 1 + + +def measureCoefficient (ρ : ProbabilityMeasure OrderPoint) (β : ℝ≥0) (s : ℝ≥0) : ℝ≥0 := + Real.toNNReal ((ρ:Measure OrderPoint).real {x | (x:ℝ) ≤ s})*β + +def measureFunctional (β : ℝ≥0) (ρ : ProbabilityMeasure OrderPoint) : ℝ := + orderParameterFunctional β (measureCoefficient ρ β) + +lemma measureCoefficient_mono (ρ : ProbabilityMeasure OrderPoint) (β : ℝ≥0) : + Monotone (measureCoefficient ρ β) := by + intro x y hxy + apply mul_le_mul_of_nonneg_right _ (by positivity) + apply Real.toNNReal_mono + exact measureReal_mono (by + intro z hz + change (z:ℝ) ≤ (x:ℝ) at hz + change (z:ℝ) ≤ (y:ℝ) + exact hz.trans (NNReal.coe_le_coe.mpr hxy)) + +lemma measureCoefficient_bound (ρ : ProbabilityMeasure OrderPoint) (β : ℝ≥0) (s : ℝ≥0) : + (measureCoefficient ρ β s:ℝ) ≤ β := by + change (Real.toNNReal ((ρ:Measure OrderPoint).real {x | (x:ℝ) ≤ s}):ℝ)*(β:ℝ) ≤ β + rw [Real.coe_toNNReal _ measureReal_nonneg] + have hh : (ρ:Measure OrderPoint).real {x | (x:ℝ) ≤ s} ≤ 1 := measureReal_le_one + nlinarith [β.coe_nonneg] + +lemma pressure_le_measureFunctional {β : ℝ≥0} (hβ : 0<β) (ρ : ProbabilityMeasure OrderPoint) : + SKQAOA.limitingFreeEnergy β ≤ measureFunctional β ρ := + limitingFreeEnergy_le_orderParameterFunctional (measureCoefficient_mono ρ β) hβ (measureCoefficient_bound ρ β) + +end ParisiFinite +namespace SKCavity +open ParisiFinite SKQAOA + +def orderPointOfArray (R : OverlapArray) : OrderPoint := + ⟨max 0 (R 0 1:ℝ),le_max_left _ _,max_le (by norm_num) (R 0 1).property.2⟩ + +lemma orderPointOfArray_continuous : Continuous orderPointOfArray := by + apply Continuous.subtype_mk + exact continuous_const.max (continuous_subtype_val.comp (continuous_apply 1 |>.comp (continuous_apply 0))) + +def orderParameterLaw (μ : ProbabilityMeasure OverlapArray) : ProbabilityMeasure OrderPoint := + μ.map orderPointOfArray + +lemma orderParameterLaw_coefficient (μ : ProbabilityMeasure OverlapArray) (β : ℝ≥0) : + measureCoefficient (orderParameterLaw μ) β=overlapCDFCoefficient μ β := by + funext s + unfold measureCoefficient overlapCDFCoefficient + congr 2 + unfold orderParameterLaw overlapDiscount entryLaw + simp only [Measure.real] + rw [ProbabilityMeasure.toMeasure_map,Measure.map_apply orderPointOfArray_continuous.measurable + (by measurability : MeasurableSet {x : OrderPoint | (x:ℝ) ≤ s}), + Measure.map_apply (by fun_prop : Measurable (fun R : OverlapArray => R 0 1)) + (by measurability : MeasurableSet {x : OverlapEntry | (x:ℝ) ≤ s})] + congr 2 + ext R + simp only [Set.mem_preimage,Set.mem_ofPred_eq,orderPointOfArray,max_le_iff] + exact and_iff_right s.coe_nonneg + +lemma dyadic_indices_tendsto : Tendsto (fun n : ℕ => 2^n-1) atTop atTop := by + apply tendsto_atTop_mono _ tendsto_id + intro n + change n ≤ 2^n-1 + have hn : n<2^n := by + induction n with + | zero => norm_num + | succ n ih => rw [pow_succ]; omega + omega + + + +theorem exists_measure_pressure_equality {β : ℝ≥0} (hβ : 0<β) : + ∃ ρ : ProbabilityMeasure OrderPoint,measureFunctional β ρ=limitingFreeEnergy β := by + have hb : (0:ℝ)<β := hβ + obtain ⟨μ,v,hG,hgg,hex,hu,hv,hbound⟩ := exists_scalar_ultrametric_cavity hb + let γ := overlapCDFCoefficient μ β + have ht := dyadic_functional_tendsto (overlapCDFCoefficient_mono μ β) hb (overlapCDFCoefficient_bound μ β) + have hupper (n : ℕ) : functional β (dyadicSchedule γ false 0 1 n) ≤ + limitingFreeEnergy β+(β:ℝ)*Real.pi/(2^n:ℕ) := by + have hh := (abs_le.mp (gridFunctional_cavity_error hG hgg hu hex hb hv (2^n-1))).1 + have he : 2^n-1+1=2^n := Nat.sub_add_cancel (one_le_pow₀ (by norm_num)) + have hβeq : Real.toNNReal (β:ℝ)=β := Real.toNNReal_coe + rw [hβeq,he] at hh + change -((β:ℝ)^2*Real.pi/(2^n:ℕ)) ≤ v-(β:ℝ)*functional β (gridSchedule μ β (2^n-1)) at hh + rw [dyadic_CDF_schedule] + have heq : (β:ℝ)^2*Real.pi/(2^n:ℕ)=(β:ℝ)*((β:ℝ)*Real.pi/(2^n:ℕ)) := by ring + rw [heq] at hh + nlinarith + have herr : Tendsto (fun n : ℕ => (β:ℝ)*Real.pi/(2^n:ℕ)) atTop (𝓝 (0:ℝ)) := by + have hh := (dyadicMesh_tendsto 1).const_mul ((β:ℝ)*Real.pi) + change Tendsto (fun n : ℕ => (β:ℝ)*Real.pi*(1/(2:ℝ)^n)) atTop (𝓝 ((β:ℝ)*Real.pi*0)) at hh + simpa only [Nat.cast_pow,Nat.cast_ofNat,mul_zero,mul_one_div] using hh + have hlim : orderParameterFunctional β γ ≤ limitingFreeEnergy β := + le_of_tendsto_of_tendsto ht (by simpa only [add_zero] using tendsto_const_nhds.add herr) + (Eventually.of_forall hupper) + refine ⟨orderParameterLaw μ,le_antisymm ?_ (pressure_le_measureFunctional hβ _)⟩ + simpa only [measureFunctional,orderParameterLaw_coefficient,γ] using hlim + +end SKCavity +namespace ParisiFinite + + + +def IsMinimizingParisiMeasure (β : ℝ≥0) (ρ : ProbabilityMeasure OrderPoint) : Prop := + ∀ ν : ProbabilityMeasure OrderPoint,measureFunctional β ρ ≤ measureFunctional β ν + + + +theorem exists_minimizing_Parisi_measure {β : ℝ≥0} (hβ : 0<β) : + ∃ ρ : ProbabilityMeasure OrderPoint,IsMinimizingParisiMeasure β ρ ∧ + measureFunctional β ρ=SKQAOA.limitingFreeEnergy β := by + obtain ⟨ρ,hρ⟩ := SKCavity.exists_measure_pressure_equality hβ + exact ⟨ρ,(fun ν => hρ.le.trans (pressure_le_measureFunctional hβ ν)),hρ⟩ + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma tiltedMean_const {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a s x c : ℝ) : tiltedMean a s f (fun _ => c) x=c := by + unfold tiltedMean expMoment expMass + simp only [integral_mul_const] + exact mul_div_cancel_left₀ c (expMass_pos hf a s x).ne' + +lemma tiltedMean_nonneg {f g : ℝ → ℝ} (hg : ∀ x,0 ≤ g x) (a s x : ℝ) : + 0 ≤ tiltedMean a s f g x := by + unfold tiltedMean expMoment expMass + exact div_nonneg (integral_nonneg fun z => mul_nonneg (Real.exp_pos _).le (hg _)) + (integral_nonneg fun _ => (Real.exp_pos _).le) + +lemma tiltedMean_mono {L : ℝ≥0} {f g h : ℝ → ℝ} + (hf : LipschitzWith L f) (hg : Continuous g) (hh : Continuous h) {M N : ℝ} + (hM : ∀ x,|g x| ≤ M) (hN : ∀ x,|h x| ≤ N) (hgh : ∀ x,g x ≤ h x) + (a s x : ℝ) : tiltedMean a s f g x ≤ tiltedMean a s f h x := by + apply div_le_div_of_nonneg_right _ (expMass_pos hf a s x).le + exact integral_mono (integrable_exp_weight hf hg hM a s x) + (integrable_exp_weight hf hh hN a s x) (fun z => mul_le_mul_of_nonneg_left (hgh _) (Real.exp_pos _).le) + +lemma tiltedMean_variance_nonneg {L M : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) (hg : Continuous g) (hM : ∀ x,|g x| ≤ M) (a s x : ℝ) : + (tiltedMean a s f g x)^2 ≤ tiltedMean a s f (fun y => g y^2) x := by + let c := tiltedMean a s f g x + have hgi : Integrable (fun z => Real.exp (a*f (x+s*z))*g (x+s*z)) (gaussianReal 0 1) := + integrable_exp_weight hf hg hM a s x + have hgs : Integrable (fun z => Real.exp (a*f (x+s*z))*g (x+s*z)^2) (gaussianReal 0 1) := + integrable_exp_weight hf (by fun_prop) (sq_bound hM) a s x + have hi : 0 ≤ ∫ z : ℝ,Real.exp (a*f (x+s*z))*(g (x+s*z)-c)^2 ∂gaussianReal 0 1 := integral_nonneg + (fun z => mul_nonneg (Real.exp_pos (a*f (x+s*z))).le (sq_nonneg (g (x+s*z)-c))) + have he (z : ℝ) : Real.exp (a*f (x+s*z))*(g (x+s*z)-c)^2 = + Real.exp (a*f (x+s*z))*g (x+s*z)^2 - + (2*c)*(Real.exp (a*f (x+s*z))*g (x+s*z)) + c^2*Real.exp (a*f (x+s*z)) := by ring + simp_rw [he] at hi + have hadd := integral_add (hgs.sub (hgi.const_mul (2*c))) ((integrable_exp_shift hf a x s).const_mul (c^2)) + have hsub := integral_sub hgs (hgi.const_mul (2*c)) + simp only [Pi.sub_apply] at hadd hsub + rw [hadd,hsub,integral_const_mul,integral_const_mul] at hi + have hp := expMass_pos hf a s x + change 0 ≤ expMoment a s f (fun y => g y^2) x - 2*c*expMoment a s f g x + c^2*expMass a s f x at hi + have hc : expMoment a s f g x=c*expMass a s f x := by + dsimp [c,tiltedMean]; exact (div_mul_cancel₀ _ hp.ne').symm + rw [hc] at hi + dsimp [tiltedMean] + apply (le_div_iff₀ hp).mpr + change c^2*expMass a s f x ≤ _ + nlinarith + + + +def HasParisiCurvature (β : ℝ≥0) (f : SmoothField) : Prop := + f.bound1=1 ∧ ∀ x, 0 ≤ f.d2 x ∧ f.d2 x ≤ (β:ℝ)*(1-f.d1 x^2) + +lemma terminal_hasParisiCurvature (β : ℝ≥0) (hβ : 0<β) : + HasParisiCurvature β (terminalField β hβ) := by + refine ⟨rfl,fun x => ⟨by dsimp [terminalField]; positivity,?_⟩⟩ + change (β:ℝ)/Real.cosh ((β:ℝ)*x)^2 ≤ (β:ℝ)*(1-Real.tanh ((β:ℝ)*x)^2) + have hh := Real.cosh_sq_sub_sinh_sq ((β:ℝ)*x) + rw [Real.tanh_eq_sinh_div_cosh] + have hc := (Real.cosh_pos ((β:ℝ)*x)).ne' + field_simp + nlinarith [β.coe_nonneg] + +lemma transform_hasParisiCurvature {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {a : ℝ} (ha : 0 ≤ a) (hab : a ≤ β) (s : ℝ) : + HasParisiCurvature β (f.transform a s) := by + refine ⟨hf.1,fun x => ?_⟩ + have hv := tiltedMean_variance_nonneg f.lipschitz f.continuousD1 f.normD1 a s x + have hn := tiltedMean_nonneg (f := f.val) (fun y => (hf.2 y).1) a s x + have h1 : ∀ y,|f.d1 y| ≤ (1:ℝ) := by simpa only [hf.1,NNReal.coe_one] using f.normD1 + have hsum : ∀ y,|f.d2 y+(β:ℝ)*f.d1 y^2| ≤ (f.bound2:ℝ)+(β:ℝ) := by + intro y + apply (abs_add_le _ _).trans + have hh := sq_bound (L := 1) h1 y + norm_num only [NNReal.coe_one,one_pow] at hh + rw [abs_mul,abs_of_nonneg β.coe_nonneg] + nlinarith [f.normD2 y,β.coe_nonneg] + have hm := tiltedMean_mono f.lipschitz + (g := fun y => f.d2 y+(β:ℝ)*f.d1 y^2) (h := fun _ => (β:ℝ)) + (by have h₂ := f.continuousD2; have h₁ := f.continuousD1; fun_prop) + continuous_const hsum (by intro; exact abs_of_nonneg β.coe_nonneg |>.le) + (fun y => by have hh := (hf.2 y).2; linarith) a s x + rw [tiltedMean_add f.lipschitz f.continuousD2 + (by have hc := f.continuousD1; fun_prop) f.normD2 + (fun y => by rw [abs_mul,abs_of_nonneg β.coe_nonneg]; exact mul_le_mul_of_nonneg_left (sq_bound f.normD1 y) β.coe_nonneg), + tiltedMean_const_mul,tiltedMean_const f.lipschitz] at hm + change 0 ≤ tiltedMean a s f.val f.d2 x + a*(tiltedMean a s f.val (fun y => f.d1 y^2) x-(tiltedMean a s f.val f.d1 x)^2) ∧ + tiltedMean a s f.val f.d2 x + a*(tiltedMean a s f.val (fun y => f.d1 y^2) x-(tiltedMean a s f.val f.d1 x)^2) ≤ + (β:ℝ)*(1-(tiltedMean a s f.val f.d1 x)^2) + constructor + · exact add_nonneg hn (mul_nonneg ha (sub_nonneg.mpr hv)) + · nlinarith [mul_nonneg (sub_nonneg.mpr hab) (sub_nonneg.mpr hv)] + +lemma smoothRecursion_hasParisiCurvature (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (ha : ∀ l∈ls,l.1 ≤ β) : HasParisiCurvature β (smoothRecursion β hβ ls) := by + induction ls with + | nil => exact terminal_hasParisiCurvature β hβ + | cons l ls ih => + exact transform_hasParisiCurvature (ih (fun k hk => ha k (List.mem_cons_of_mem _ hk))) + l.1.coe_nonneg (by exact_mod_cast ha l (List.mem_cons_self)) _ + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma curvature_abs_d2 {β : ℝ≥0} {f : SmoothField} (hf : HasParisiCurvature β f) (x : ℝ) : + |f.d2 x| ≤ β := by + rw [abs_of_nonneg (hf.2 x).1] + have hh := (hf.2 x).2 + nlinarith [mul_nonneg β.coe_nonneg (sq_nonneg (f.d1 x))] + +lemma curvature_gradient_lipschitz {β : ℝ≥0} {f : SmoothField} (hf : HasParisiCurvature β f) : + LipschitzWith β f.d1 := by + apply lipschitzWith_of_nnnorm_deriv_le (fun x => (f.hasD2 x).differentiableAt) + intro x + rw [(f.hasD2 x).deriv] + exact_mod_cast curvature_abs_d2 hf x + +lemma curvature_taylor_error {β : ℝ≥0} {f : SmoothField} (hf : HasParisiCurvature β f) + (x : ℝ) {h : ℝ} (hh : 0 ≤ h) : + |f.val (x+h)-f.val x-h*f.d1 x| ≤ (β:ℝ)*h^2 := by + let r (y : ℝ) := f.val y-f.val x-(y-x)*f.d1 x + have hd (y : ℝ) : HasDerivAt r (f.d1 y-f.d1 x) y := by + convert (f.hasD1 y |>.sub_const (f.val x)).sub + (((hasDerivAt_id y).sub_const x).mul_const (f.d1 x)) using 1 <;> + first | rfl | simp only [one_mul] + have hb (y : ℝ) (hy : y∈Set.Ico x (x+h)) : ‖f.d1 y-f.d1 x‖ ≤ (β:ℝ)*h := by + have hl := (curvature_gradient_lipschitz hf).dist_le_mul y x + rw [Real.dist_eq,Real.dist_eq,abs_of_nonneg (sub_nonneg.mpr hy.1)] at hl + simpa only [Real.norm_eq_abs] using hl.trans (mul_le_mul_of_nonneg_left (by linarith [hy.2]) β.coe_nonneg) + have ht := norm_image_sub_le_of_norm_deriv_le_segment' + (fun y (_ : y∈Set.Icc x (x+h)) => (hd y).hasDerivWithinAt) hb (x+h) ⟨by linarith,le_rfl⟩ + simpa only [r,sub_self,zero_mul,sub_zero,add_sub_cancel_left,Real.norm_eq_abs,pow_two,mul_assoc] using ht + + + +lemma curvature_derivative_stability {β : ℝ≥0} {f g : SmoothField} + (hf : HasParisiCurvature β f) (hg : HasParisiCurvature β g) + {ε h : ℝ} (hh : 0 ≤ h) (he : ∀ y,|f.val y-g.val y| ≤ ε) (x : ℝ) : + h*|f.d1 x-g.d1 x| ≤ 2*ε+2*(β:ℝ)*h^2 := by + have hferr := abs_le.mp (curvature_taylor_error hf x hh) + have hgerr := abs_le.mp (curvature_taylor_error hg x hh) + have hx := abs_le.mp (he x) + have hx' := abs_le.mp (he (x+h)) + have ha : h*|f.d1 x-g.d1 x|=|h*(f.d1 x-g.d1 x)| := by rw [abs_mul,abs_of_nonneg hh] + rw [ha,abs_le] + constructor <;> nlinarith + +lemma uniform_derivative_cauchy {β : ℝ≥0} {F : ℕ → SmoothField} {g : ℝ → ℝ} + (hF : ∀ n,HasParisiCurvature β (F n)) + (ht : TendstoUniformly (fun n => (F n).val) g atTop) : + UniformCauchySeqOn (fun n => (F n).d1) atTop Set.univ := by + rw [Metric.uniformCauchySeqOn_iff] + intro ε hε + let h := ε/(8*((β:ℝ)+1)) + have hh : 0 ?_⟩ + have hd : ∀ y,|(F m).val y-(F n).val y| ≤ 2*(ε*h/8) := by + intro y + have h₁ := hN m hm y + have h₂ := hN n hn y + rw [Real.dist_eq] at h₁ h₂ + calc + _ ≤ |(F m).val y-g y|+|g y-(F n).val y| := abs_sub_le _ _ _ + _ ≤ 2*(ε*h/8) := by rw [abs_sub_comm] at h₁; linarith + have hbnd := curvature_derivative_stability (hF m) (hF n) hh.le hd x + rw [Real.dist_eq] + have hmul := mul_le_mul_of_nonneg_right hsmall hh.le + nlinarith + +lemma exists_uniform_derivative_limit {β : ℝ≥0} {F : ℕ → SmoothField} {g : ℝ → ℝ} + (hF : ∀ n,HasParisiCurvature β (F n)) + (ht : TendstoUniformly (fun n => (F n).val) g atTop) : + ∃ g' : ℝ → ℝ,TendstoUniformly (fun n => (F n).d1) g' atTop ∧ + (∀ x,HasDerivAt g (g' x) x) ∧ LipschitzWith β g' ∧ (∀ x,|g' x| ≤ 1) := by + have hc := uniform_derivative_cauchy hF ht + choose g' hg' using fun x : ℝ => cauchySeq_tendsto_of_complete (hc.cauchySeq (Set.mem_univ x)) + have hu : TendstoUniformly (fun n => (F n).d1) g' atTop := by + rw [← tendstoUniformlyOn_univ] + exact hc.tendstoUniformlyOn_of_tendsto (fun x _ => hg' x) + refine ⟨g',hu,fun x => hasDerivAt_of_tendstoUniformly hu (Eventually.of_forall (fun n y => (F n).hasD1 y)) (fun y => ht.tendsto_at y) x,?_,?_⟩ + · apply LipschitzWith.of_dist_le_mul + intro x y + apply le_of_tendsto ((hg' x).dist (hg' y)) + exact Eventually.of_forall fun n => (curvature_gradient_lipschitz (hF n)).dist_le_mul x y + · intro x + apply le_of_tendsto (hg' x |>.abs) + exact Eventually.of_forall fun n => by simpa only [(hF n).1,NNReal.coe_one] using (F n).normD1 x + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/EmpiricalExpLog.lean b/lean/OAI/Probability/ParisiFinite/EmpiricalExpLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..334cb6b2930874bf49fa1ef73991c772caab6fad --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/EmpiricalExpLog.lean @@ -0,0 +1,681 @@ +import Mathlib +import OAI.Probability.ParisiFinite.HierarchyNumeratorNonneg + +namespace OAI + +/-! Empirical Exp Log. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +def empiricalExpLog {r : ℕ} (u : Fin r → ℝ) : ℝ := + Real.log ((∑ i,Real.exp (u i))/(r:ℝ)) + +lemma empiricalExpLog_eq {r : ℕ} (hr : 0 Real.exp_pos _) Finset.univ_nonempty).ne' + (Nat.cast_ne_zero.mpr hr.ne')] + rfl + +lemma integrable_empiricalExpLog {Ω : Type*} [MeasurableSpace Ω] {ν : Measure Ω} + [IsFiniteMeasure ν] {r : ℕ} (hr : 0 f sample i) ν) : + Integrable (fun sample => empiricalExpLog (f sample)) ν := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + simp_rw [empiricalExpLog_eq hr] + exact (integrable_logPartition hf).sub (integrable_const _) + +lemma empiricalExpLog_error {r : ℕ} (hr : 0 Real.exp_pos _) Finset.univ_nonempty) (Nat.cast_pos.mpr hr) + have hs : (((∑ i,Real.exp (u i))/(r:ℝ))-((∑ i,Real.exp (v i))/(r:ℝ)))^2≤ + (∑ i,(Real.exp (u i)-Real.exp (v i))^2)/(r:ℝ) := by + rw [← sub_div,← Finset.sum_sub_distrib] + simpa using (sum_div_card_sq_le_sum_sq_div_card (s:=Finset.univ) + (f:=fun i : Fin r => Real.exp (u i)-Real.exp (v i))) + have hinv (w : Fin r → ℝ) : ((∑ i,Real.exp (w i))/(r:ℝ))⁻¹^2≤ + (∑ i,Real.exp (-2*w i))/(r:ℝ) := by + have hh := empiricalMean_inv_sq hr (fun i : Fin r => Real.exp (w i)) (fun i => Real.exp_pos _) id + have he (i : Fin r) : (Real.exp (w i))⁻¹^2=Real.exp (-2*w i) := by + rw [← Real.exp_neg,← Real.exp_nat_mul] + congr 1 + ring + simpa only [empiricalMean,id_eq,he] using hh + exact (log_error_young (hpos u) (hpos v) ht).trans + (add_le_add (mul_le_mul_of_nonneg_left hs ht.le) + (div_le_div_of_nonneg_right (add_le_add (hinv u) (hinv v)) (by positivity))) + +lemma integral_empiricalExpLog_error {Ω : Type*} [MeasurableSpace Ω] {ν : Measure Ω} + [IsFiniteMeasure ν] {r : ℕ} (hr : 0 f sample i) ν) + (hg : ∀ i,Integrable (fun sample => g sample i) ν) + (hd : ∀ i,Integrable (fun sample => (Real.exp (f sample i)-Real.exp (g sample i))^2) ν) + (hfi : ∀ i,Integrable (fun sample => Real.exp (-2*f sample i)) ν) + (hgi : ∀ i,Integrable (fun sample => Real.exp (-2*g sample i)) ν) + {t : ℝ} (ht : 0 empiricalExpLog (f sample)-empiricalExpLog (g sample)) (μ:=ν) + rw [Real.norm_eq_abs] at hnorm + apply hnorm.trans + have hd' := (integrable_finsetSum Finset.univ (fun i _ => hd i)).div_const (r:ℝ) + have hf' := (integrable_finsetSum Finset.univ (fun i _ => hfi i)).div_const (r:ℝ) + have hg' := (integrable_finsetSum Finset.univ (fun i _ => hgi i)).div_const (r:ℝ) + have h := integral_mono + ((integrable_empiricalExpLog hr hf).sub (integrable_empiricalExpLog hr hg)).norm + ((hd'.const_mul t).add ((hf'.add hg').div_const (2*t))) + (fun sample => by simpa only [Real.norm_eq_abs,Pi.add_apply,Pi.sub_apply] using empiricalExpLog_error hr (f sample) (g sample) ht) + simp only [Pi.add_apply,Pi.sub_apply] at h + apply h.trans_eq + rw [integral_add] + · rw [integral_const_mul,integral_div,integral_div,integral_add hf' hg',integral_div,integral_div] + simp_rw [integral_finsetSum _ (fun i _ => hd i),integral_finsetSum _ (fun i _ => hfi i), + integral_finsetSum _ (fun i _ => hgi i)] + · exact hd'.const_mul t + · exact (hf'.add hg').div_const (2*t) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +def clipField (M x : ℝ) : ℝ := max (-M) (min M x) + +lemma clipField_abs_le {M : ℝ} (hM : 0≤M) (x : ℝ) : |clipField M x|≤|x| := by + rw [abs_le] + constructor + · exact (le_min (by linarith [abs_nonneg x]) (neg_abs_le x)).trans (le_max_right _ _) + · exact max_le (by linarith [abs_nonneg x]) ((min_le_right _ _).trans (le_abs_self x)) + +lemma clipField_bounded {M : ℝ} (hM : 0≤M) (x : ℝ) : |clipField M x|≤M := by + rw [abs_le] + exact ⟨le_max_left _ _,max_le (by linarith) (min_le_left _ _)⟩ + +lemma continuous_clipField (M : ℝ) : Continuous (clipField M) := by + unfold clipField + fun_prop + +lemma exp_clip_diff_sq_le {M : ℝ} (hM : 0≤M) (x : ℝ) : + (Real.exp x-Real.exp (clipField M x))^2≤Real.exp (2* |x|) := by + have h1 := Real.exp_le_exp.mpr (le_abs_self x) + have h2 := Real.exp_le_exp.mpr ((le_abs_self (clipField M x)).trans (clipField_abs_le hM x)) + have hab : |Real.exp x-Real.exp (clipField M x)|≤Real.exp |x| := by + rw [abs_le] + constructor <;> linarith [Real.exp_pos x,Real.exp_pos (clipField M x)] + have hs := sq_le_sq₀ (abs_nonneg _) (Real.exp_pos _).le |>.mpr hab + rw [sq_abs,← Real.exp_nat_mul] at hs + simpa using hs + +lemma exp_neg_clip_le {M : ℝ} (hM : 0≤M) (x : ℝ) : + Real.exp (-2*clipField M x)≤Real.exp (2* |x|) := by + apply Real.exp_le_exp.mpr + have hh := (abs_le.mp (clipField_abs_le hM x)).1 + linarith + +lemma integrable_clip_exp_diff_sq {Ω : Type*} [MeasurableSpace Ω] {ν : Measure Ω} + {f : Ω → ℝ} (hf : Measurable f) (he : Integrable (fun sample => Real.exp (2* |f sample|)) ν) + {M : ℝ} (hM : 0≤M) : + Integrable (fun sample => (Real.exp (f sample)-Real.exp (clipField M (f sample)))^2) ν := by + apply he.mono' (by unfold clipField; exact ((Real.measurable_exp.comp hf).sub (Real.measurable_exp.comp ((measurable_const.max (measurable_const.min hf))))).pow_const 2 |>.aestronglyMeasurable) + exact ae_of_all _ fun sample => by + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + exact exp_clip_diff_sq_le hM _ + +lemma integrable_neg_clip_exp {Ω : Type*} [MeasurableSpace Ω] {ν : Measure Ω} + {f : Ω → ℝ} (hf : Measurable f) (he : Integrable (fun sample => Real.exp (2* |f sample|)) ν) + {M : ℝ} (hM : 0≤M) : + Integrable (fun sample => Real.exp (-2*clipField M (f sample))) ν := by + apply he.mono' (Real.measurable_exp.comp (((continuous_clipField M).measurable.comp hf).const_mul (-2))).aestronglyMeasurable + exact ae_of_all _ fun sample => by + simp only [Function.comp_apply] + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact exp_neg_clip_le hM _ + +lemma clipped_exp_L2_tendsto {Ω : Type*} [MeasurableSpace Ω] {ν : Measure Ω} + {f : Ω → ℝ} (hf : Measurable f) (he : Integrable (fun sample => Real.exp (2* |f sample|)) ν) : + Tendsto (fun m : ℕ => ∫ sample,(Real.exp (f sample)-Real.exp (clipField m (f sample)))^2 ∂ν) + atTop (𝓝 (0:ℝ)) := by + have ht : Tendsto (fun m : ℕ => ∫ sample,(Real.exp (f sample)-Real.exp (clipField m (f sample)))^2 ∂ν) + atTop (𝓝 (∫ _ : Ω,(0:ℝ) ∂ν)) := by + apply tendsto_integral_of_dominated_convergence (fun sample => Real.exp (2* |f sample|)) + · intro m; exact (integrable_clip_exp_diff_sq hf he (Nat.cast_nonneg m)).aestronglyMeasurable + · exact he + · intro m + exact ae_of_all _ fun sample => by + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + exact exp_clip_diff_sq_le (Nat.cast_nonneg m) _ + · exact ae_of_all _ fun sample => by + have hh := Real.continuous_exp.continuousAt.tendsto.comp (clip_tendsto (f sample)) + simpa only [Function.comp_apply,clipField,sub_self,zero_pow (by norm_num : (2:ℕ)≠0)] using ((tendsto_const_nhds (x:=Real.exp (f sample))).sub hh).pow 2 + simpa using ht + +lemma integrable_exp_abs_field {d : ℕ} (s : Fin d → ℝ) (c : ℝ) : + Integrable (fun z => Real.exp (c* |∑ k,s k*z k|)) (gaussianLaw (Fin d)) := by + let A : Unit → Fin d → ℝ := fun _ => s + apply ((integrable_exp_field A c ()).add (integrable_exp_field A (-c) ())).mono' (show Continuous (fun z : Fin d → ℝ => Real.exp (c* |∑ k,s k*z k|)) by fun_prop).aestronglyMeasurable + exact ae_of_all _ fun z => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + change _≤Real.exp (c*(∑ k,s k*z k))+Real.exp (-c*(∑ k,s k*z k)) + rcases le_total 0 (∑ k,s k*z k) with hz | hz + · rw [abs_of_nonneg hz]; exact le_add_of_nonneg_right (Real.exp_pos _).le + · rw [abs_of_nonpos hz] + have hh : c*(-(∑ k,s k*z k))= -c*(∑ k,s k*z k) := by ring + rw [hh]; exact le_add_of_nonneg_left (Real.exp_pos _).le + + + +lemma integrable_exp_abs_lipschitz_field {d : ℕ} (s : Fin d → ℝ) + {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (x c : ℝ) : + Integrable (fun z => Real.exp (c* |f (x+∑ k,s k*z k)|)) (gaussianLaw (Fin d)) := by + apply ((integrable_exp_abs_field s (|c| *(L:ℝ))).const_mul (Real.exp (|c| * |f x|))).mono' + (Real.continuous_exp.comp ((hf.continuous.comp (by fun_prop)).abs.const_mul c)).aestronglyMeasurable + exact ae_of_all _ fun z => by + simp only [Function.comp_apply] + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),← Real.exp_add] + apply Real.exp_le_exp.mpr + have hh := shift_norm_le hf x 1 (∑ k,s k*z k) + simp only [one_mul,abs_one,mul_one] at hh + have hh' := mul_le_mul_of_nonneg_right (le_abs_self c) (abs_nonneg (f (x+∑ k,s k*z k))) + nlinarith [abs_nonneg c] + +lemma integrable_lipschitz_field {d : ℕ} (s : Fin d → ℝ) + {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (x : ℝ) : + Integrable (fun z => f (x+∑ k,s k*z k)) (gaussianLaw (Fin d)) := by + let A : Unit → Fin d → ℝ := fun _ => s + have hi := (integrable_field A ()).abs.const_mul (L:ℝ) + apply ((integrable_const |f x|).add hi).mono' + (hf.continuous.comp (by fun_prop)).aestronglyMeasurable + exact ae_of_all _ fun z => by + simp only [Function.comp_apply,Real.norm_eq_abs] + have hh := shift_norm_le hf x 1 (∑ k,s k*z k) + simpa only [one_mul,abs_one,mul_one,field,A,Pi.add_apply] using hh + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma scalarHierarchy_schedule {d : ℕ} (a v : Fin d → ℝ≥0) (β x : ℝ) : + scalarHierarchy (fun k => (a k:ℝ)) (fun k => Real.sqrt (v k)) (terminal β) x= + recursion β (List.ofFn (fun k => (a k,v k))) x := by + induction d generalizing x with + | zero => simp [scalarHierarchy,recursion] + | succ d ih => + rw [List.ofFn_succ,recursion] + change step _ _ _ x=step _ _ _ x + congr 1 + funext y + exact ih (fun k => a k.succ) (fun k => v k.succ) y + +lemma gaussianHierarchy_cosh_schedule {d : ℕ} (a v : Fin d → ℝ≥0) {β : ℝ} (hβ : 0<β) (x : ℝ) : + gaussianHierarchyRisk (fun k => (a k:ℝ)) + (fun z => Real.log (2*Real.cosh (β*(x+∑ k,Real.sqrt (v k)*z k))))= + β*recursion β (List.ofFn (fun k => (a k*Real.toNNReal β,v k))) x := by + have he (y : ℝ) : Real.log (2*Real.cosh (β*y))=β*terminal β y := by + unfold terminal + field_simp + simp_rw [he] + rw [gaussianHierarchyRisk_sum _ _ (fun y => β*terminal β y),scalarHierarchy_mul_const _ _ hβ.ne'] + congr 1 + simpa only [NNReal.coe_mul,Real.coe_toNNReal β hβ.le] using scalarHierarchy_schedule (fun k => a k*Real.toNNReal β) v β x + +lemma step_affine (a s c b x : ℝ) : + step a s (fun y => c*y+b) x=c*x+b+a*c^2*s^2/2 := by + by_cases ha : a=0 + · simp only [step,ha,logMean_zero,zero_mul,zero_div,add_zero] + have he (z : ℝ) : c*(x+s*z)+b=(c*x+b)+(c*s)*z := by ring + simp_rw [he] + have hi : Integrable (fun z : ℝ => z) (gaussianReal 0 1) := + MemLp.integrable (by norm_num) (memLp_id_gaussianReal (μ:=0) (v:=1) 1) + rw [integral_add (integrable_const _) (hi.const_mul _),integral_const_mul] + simp [integral_id_gaussianReal] + · have he (z : ℝ) : a*(c*(x+s*z)+b)=a*(c*x+b)+(a*c*s)*z := by ring + simp only [step,logMean,ha,↓reduceIte] + simp_rw [he,Real.exp_add] + rw [integral_const_mul,integral_exp_linear,← Real.exp_add,Real.log_exp] + field_simp + +lemma scalarHierarchy_affine {d : ℕ} (a s : Fin d → ℝ) (c b x : ℝ) : + scalarHierarchy a s (fun y => c*y+b) x=c*x+b+c^2/2*(∑ k,a k*(s k)^2) := by + induction d generalizing b x with + | zero => simp [scalarHierarchy] + | succ d ih => + change step (a 0) (s 0) _ x=_ + have he : scalarHierarchy (fun k => a k.succ) (fun k => s k.succ) (fun y => c*y+b)= + (fun y => c*y+(b+c^2/2*(∑ k : Fin d,a k.succ*(s k.succ)^2))) := by + funext y + rw [ih] + ring + rw [he,step_affine,Fin.sum_univ_succ] + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +def hierarchyFieldValue {d : ℕ} (μ : ProbabilityMeasure OverlapArray) (q : Fin (d+2) → ℝ) + (r : ℕ) (f : (Fin (d+1) → ℝ) → ℝ) : ℝ := + ∫ sample,empiricalExpLog (fun i : Fin r => f (sample i)) ∂hierarchySampleLaw μ q r + +lemma hierarchyField_clip_error {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) {r : ℕ} (hr : 0 Real.exp (2* |f z|)) (gaussianLaw (Fin (d+1)))) + {M t : ℝ} (hM : 0≤M) (ht : 0 clipField M (f z))|≤ + t*(∫ z,(Real.exp (f z)-Real.exp (clipField M (f z)))^2 ∂gaussianLaw (Fin (d+1)))+ + (∫ z,Real.exp (2* |f z|) ∂gaussianLaw (Fin (d+1)))/t := by + let := hierarchySampleLaw_probability hG hgg hu q hq h0 h1 hr + have hgc : Measurable (fun z => clipField M (f z)) := (continuous_clipField M).measurable.comp hf + have hgi : Integrable (fun z => clipField M (f z)) (gaussianLaw (Fin (d+1))) := by + apply hfi.abs.mono' hgc.aestronglyMeasurable + exact ae_of_all _ fun z => by simpa only [Real.norm_eq_abs] using clipField_abs_le hM (f z) + have hd := integrable_clip_exp_diff_sq hf he hM + have hneg : Integrable (fun z => Real.exp (-2*f z)) (gaussianLaw (Fin (d+1))) := by + apply he.mono' (Real.measurable_exp.comp (hf.const_mul (-2))).aestronglyMeasurable + exact ae_of_all _ fun z => by + simp only [Function.comp_apply,Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (by linarith [neg_abs_le (f z)]) + have hnegg := integrable_neg_clip_exp hf he hM + have hh := integral_empiricalExpLog_error hr + (fun i => hierarchySampleLaw_integrable_coordinate hG hgg hu q hq h0 h1 i hfi) + (fun i => hierarchySampleLaw_integrable_coordinate hG hgg hu q hq h0 h1 i hgi) + (fun i => hierarchySampleLaw_integrable_coordinate hG hgg hu q hq h0 h1 i hd) + (fun i => hierarchySampleLaw_integrable_coordinate hG hgg hu q hq h0 h1 i hneg) + (fun i => hierarchySampleLaw_integrable_coordinate hG hgg hu q hq h0 h1 i hnegg) ht + have hdm : Measurable (fun z => (Real.exp (f z)-Real.exp (clipField M (f z)))^2) := + ((Real.measurable_exp.comp hf).sub (Real.measurable_exp.comp hgc)).pow_const 2 + have hc1 (i : Fin r) := hierarchySampleLaw_integral_coordinate hG hgg hu q hq h0 h1 i + (show Measurable (fun z => Real.exp (-2*f z)) from Real.measurable_exp.comp (hf.const_mul (-2))) + have hc2 (i : Fin r) := hierarchySampleLaw_integral_coordinate hG hgg hu q hq h0 h1 i + (show Measurable (fun z => Real.exp (-2*clipField M (f z))) from Real.measurable_exp.comp (hgc.const_mul (-2))) + simp only [hierarchySampleLaw_integral_coordinate hG hgg hu q hq h0 h1 _ hdm,hc1,hc2] at hh + have hr0 : (r:ℝ)≠0 := Nat.cast_ne_zero.mpr hr.ne' + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + mul_div_cancel_left₀ _ hr0] at hh + apply hh.trans + apply add_le_add le_rfl + have hn : (∫ z,Real.exp (-2*f z) ∂gaussianLaw (Fin (d+1)))≤ + ∫ z,Real.exp (2* |f z|) ∂gaussianLaw (Fin (d+1)) := by + exact integral_mono hneg he (fun z => Real.exp_le_exp.mpr (by linarith [neg_abs_le (f z)])) + have hng : (∫ z,Real.exp (-2*clipField M (f z)) ∂gaussianLaw (Fin (d+1)))≤ + ∫ z,Real.exp (2* |f z|) ∂gaussianLaw (Fin (d+1)) := + integral_mono hnegg he (fun z => exp_neg_clip_le hM (f z)) + apply (div_le_div_iff₀ (by positivity : 0<2*t) ht).mpr + nlinarith + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + + + +theorem hierarchyField_lipschitz_tendsto {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (s : Fin (d+1) → ℝ) + {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (x : ℝ) : + Tendsto (fun r => hierarchyFieldValue μ q (r+1) (fun z => f (x+∑ k,s k*z k))) atTop + (𝓝 (scalarHierarchy (fun k => overlapDiscount μ (q k.succ)) s f x)) := by + let F (z : Fin (d+1) → ℝ) := f (x+∑ k,s k*z k) + let a (k : Fin (d+1)) := overlapDiscount μ (q k.succ) + have ha (k : Fin (d+1)) : 0≤a k := measureReal_nonneg + have hF : Continuous F := hf.continuous.comp (by fun_prop) + have hFi : Integrable F (gaussianLaw (Fin (d+1))) := integrable_lipschitz_field s hf x + have hE : Integrable (fun z => Real.exp (2* |F z|)) (gaussianLaw (Fin (d+1))) := + integrable_exp_abs_lipschitz_field s hf x 2 + let D (m : ℕ) : ℝ := ∫ z,(Real.exp (F z)-Real.exp (clipField m (F z)))^2 ∂gaussianLaw (Fin (d+1)) + let K : ℝ := ∫ z,Real.exp (2* |F z|) ∂gaussianLaw (Fin (d+1)) + have hK : 0≤K := integral_nonneg fun z => (Real.exp_pos _).le + have hD : Tendsto D atTop (𝓝 (0:ℝ)) := clipped_exp_L2_tendsto hF.measurable hE + let V (m : ℕ) := scalarHierarchy a s (fun y => clipField m (f y)) x + have hV : Tendsto V atTop (𝓝 (scalarHierarchy a s f x)) := scalarHierarchy_clip_tendsto ha hf x + have hB (m : ℕ) : Tendsto (fun r => hierarchyFieldValue μ q (r+1) (fun z => clipField m (F z))) atTop + (𝓝 (V m)) := by + let y (z : Fin (d+1) → ℝ) := Real.exp (clipField m (F z)) + have hy : Continuous y := Real.continuous_exp.comp ((continuous_clipField m).comp hF) + have hl : 0 clipField m (F z))=V m := + gaussianHierarchyRisk_sum a s (fun y => clipField m (f y)) x + rw [show (fun k => overlapDiscount μ (q k.succ))=a from rfl,he] at hh + exact hh + apply Metric.tendsto_atTop.mpr + intro ε hε + let t := 4*(K+1)/ε + have ht : 0 t*D m) atTop (𝓝 (0:ℝ)) := by simpa using hD.const_mul t + obtain ⟨m₁,hm₁⟩ := Metric.tendsto_atTop.mp hDt (ε/4) (by positivity) + obtain ⟨m₂,hm₂⟩ := Metric.tendsto_atTop.mp hV (ε/4) (by positivity) + let m := max m₁ m₂ + have hdm : t*D m<ε/4 := (le_abs_self _).trans_lt (by simpa only [Real.dist_eq,sub_zero] using hm₁ m (le_max_left _ _)) + have hvm : |V m-scalarHierarchy a s f x|<ε/4 := by simpa only [Real.dist_eq] using hm₂ m (le_max_right _ _) + obtain ⟨R,hR⟩ := Metric.tendsto_atTop.mp (hB m) (ε/4) (by positivity) + refine ⟨R,fun r hr => ?_⟩ + have hb := hR r hr + simp only [Real.dist_eq] at hb ⊢ + have herr := hierarchyField_clip_error hG hgg hu q hq h0 h1 (Nat.succ_pos r) + hF.measurable hFi hE (Nat.cast_nonneg m) ht + have htri := abs_sub_le (hierarchyFieldValue μ q (r+1) F) + (hierarchyFieldValue μ q (r+1) (fun z => clipField m (F z))) (scalarHierarchy a s f x) + have htri' := abs_sub_le (hierarchyFieldValue μ q (r+1) (fun z => clipField m (F z))) + (V m) (scalarHierarchy a s f x) + change |hierarchyFieldValue μ q (r+1) F-scalarHierarchy a s f x|<ε + change |hierarchyFieldValue μ q (r+1) F-hierarchyFieldValue μ q (r+1) (fun z => clipField m (F z))|≤t*D m+K/t at herr + linarith + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma initial_segment_square {d : ℕ} (p : Fin d → Prop) [DecidablePred p] + (hp : ∀ i j,i≤j → p j → p i) : + (∑ k,if p k then (1:ℝ) else 0)^2=∑ k,if p k then 2*(k.val:ℝ)+1 else 0 := by + induction d with + | zero => simp + | succ d ih => + have hi := ih (fun k : Fin d => p k.castSucc) (fun i j hij => hp _ _ (Fin.castSucc_le_castSucc_iff.mpr hij)) + rw [Fin.sum_univ_castSucc,Fin.sum_univ_castSucc] + simp only [Fin.val_castSucc] + rw [← hi] + by_cases h : p (Fin.last d) + · have he (k : Fin d) : p k.castSucc := hp _ _ (Fin.le_last _) h + have hs : (∑ k : Fin d,if p k.castSucc then (1:ℝ) else 0)=(d:ℝ) := by simp [he] + rw [hs] + simp only [h,ite_true,Fin.val_last] + ring + · simp [h] + + + +def gridZVariance (m : ℕ) (_ : Fin (m+1)) : ℝ := 1/(m+1:ℕ) +def gridYVariance (m : ℕ) (k : Fin (m+1)) : ℝ := (2*(k.val:ℝ)+1)/(2*(m+1:ℕ)^2) + +lemma gridZVariance_nonneg (m : ℕ) (k : Fin (m+1)) : 0≤gridZVariance m k := by unfold gridZVariance; positivity +lemma gridYVariance_nonneg (m : ℕ) (k : Fin (m+1)) : 0≤gridYVariance m k := by unfold gridYVariance; positivity + +lemma grid_tree_z_kernel {m r : ℕ} (T : PartitionTree (m+1) r) (i j : Fin r) : + kernel (treeGaussianCoeff T (gridZVariance m)) i j= + ((codeGramBlock (treeCodes T) (cavityGridVariance m) + (cavityGridVariance_nonneg m) (cavityGridVariance_sum m)).val i j:ℝ) := by + rw [kernel_treeGaussianCoeff _ _ (gridZVariance_nonneg m),codeGramBlock_entry] + conv_rhs => rw [Fin.sum_univ_succ] + simp only [cavityGridVariance,Fin.cons_zero,Fin.cons_succ,ite_self,zero_add,gridZVariance] + +lemma grid_tree_y_kernel {m r : ℕ} (T : PartitionTree (m+1) r) (i j : Fin r) : + kernel (treeGaussianCoeff T (gridYVariance m)) i j= + ((codeGramBlock (treeCodes T) (cavityGridVariance m) + (cavityGridVariance_nonneg m) (cavityGridVariance_sum m)).val i j:ℝ)^2/2 := by + rw [kernel_treeGaussianCoeff _ _ (gridYVariance_nonneg m),← grid_tree_z_kernel T, + kernel_treeGaussianCoeff _ _ (gridZVariance_nonneg m)] + let p (k : Fin (m+1)) := treeCodes T k.succ i=treeCodes T k.succ j + have hp : ∀ k l : Fin (m+1),k≤l → p l → p k := by + intro k l hkl + exact treeCodes_nested T k.succ l.succ (Fin.succ_le_succ_iff.mpr hkl) i j + have he (k : Fin (m+1)) : (if p k then gridZVariance m k else 0)=(if p k then (1:ℝ) else 0)/(m+1:ℕ) := by + split <;> simp_all [gridZVariance] + have he' (k : Fin (m+1)) : (if p k then gridYVariance m k else 0)=(if p k then 2*(k.val:ℝ)+1 else 0)/(2*(m+1:ℕ)^2) := by + split <;> simp_all [gridYVariance] + change (∑ k,if p k then gridYVariance m k else 0)=(∑ k,if p k then gridZVariance m k else 0)^2/2 + simp_rw [he,he',← Finset.sum_div,div_pow,initial_segment_square p hp] + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma continuous_empiricalExpLog {r : ℕ} : Continuous (empiricalExpLog : (Fin r → ℝ) → ℝ) := by + change Continuous (fun u : Fin r → ℝ => empiricalExpLog u) + by_cases hr : 0 Real.log (2*Real.cosh (u i)))= + logPartition (fun s : Fin r×Bool => signBool s.2*u s.1)-Real.log (r:ℝ) := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + have he := empirical_log_cosh hr u id + simpa only [empiricalExpLog,empiricalMean,id_eq,Real.exp_log (by positivity : 0<2*Real.cosh _)] using he + +lemma expected_empiricalExpLog {κ : Type*} [Fintype κ] {r : ℕ} (hr : 0 Real.log (2*Real.cosh (β*field A z i))) ∂gaussianLaw κ := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + let B : Fin r×Bool → κ → ℝ := fun s k => signBool s.2*β*A s.1 k + have hk : kernel (coshGramCoeff G β)=kernel B := by + funext s t + rw [kernel_coshGramCoeff,← hA] + unfold kernel B + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + have he := integral_field_eq_of_kernel (coshGramCoeff G β) B hk logPartition continuous_logPartition.measurable + change expected (coshGramCoeff G β)=expected B at he + have hf (z : κ → ℝ) : (fun s : Fin r×Bool => signBool s.2*(β*field A z s.1))=field B z := by + funext s + simp only [field,B,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + simp_rw [empiricalExpLog_cosh hr,hf] + rw [integral_sub (integrable_logPartition (integrable_field B)) (integrable_const _)] + simp only [integral_const,probReal_univ,one_smul,coshGramPressure,expected] at he ⊢ + rw [he] + +lemma squareGramPressure_field {κ : Type*} [Fintype κ] {r : ℕ} (hr : 0 β*field A z i) ∂gaussianLaw κ := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + let B : Fin r → κ → ℝ := fun i k => β*A i k + have hk : kernel (squareGramCoeff G β)=kernel B := by + funext i j + rw [kernel_squareGramCoeff] + have hh : kernel B i j=β^2*kernel A i j := by + unfold kernel B + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + rw [hh,hA] + ring + have he := integral_field_eq_of_kernel (squareGramCoeff G β) B hk logPartition continuous_logPartition.measurable + change expected (squareGramCoeff G β)=expected B at he + have hf (z : κ → ℝ) : (fun i => β*field A z i)=field B z := by + funext i + simp only [field,B,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + simp_rw [hf] + rw [expected_empiricalExpLog hr B,squareGramPressure,he] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma hierarchyFieldValue_sum {d : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+2) → ℝ) {r : ℕ} (hr : 0 f (treePathVector T z i)) ∂gaussianLaw (TreeNode T) := by + have hi (T : PartitionTree (d+1) r) : + Integrable (fun sample => empiricalExpLog (fun i => f (sample i))) (treePathLaw T) := by + apply integrable_empiricalExpLog hr + intro i + have hh := hfi + rw [← treePathLaw_coordinate T i] at hh + exact hh.comp_measurable (by fun_prop) + have hm : Measurable (fun sample : Fin r → Fin (d+1) → ℝ => empiricalExpLog (fun i => f (sample i))) := + continuous_empiricalExpLog.measurable.comp (Measurable.of_eval (fun i => hf.comp (measurable_pi_apply i))) + unfold hierarchyFieldValue hierarchySampleLaw + rw [integral_finsetSum_measure] + · simp only [integral_smul_measure,smul_eq_mul,Measure.real,integral_treePathLaw _ _ hm] + · intro T _ + exact (hi T).smul_measure (measure_ne_top _ _) + +lemma lipschitz_log_cosh {β : ℝ} (hβ : 0<β) : + LipschitzWith (Real.toNNReal β) (fun x => Real.log (2*Real.cosh (β*x))) := by + have hm : LipschitzWith (Real.toNNReal β) (fun x : ℝ => β*x) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,← mul_sub,abs_mul,abs_of_pos hβ,Real.coe_toNNReal β hβ.le] + exact le_rfl + have hf := hm.comp (terminal_lipschitz hβ) + have he : (fun x => β*terminal β x)=(fun x => Real.log (2*Real.cosh (β*x))) := by + funext x + unfold terminal + field_simp + simp only [Function.comp_def] at hf + rw [he] at hf + simpa only [mul_one,Function.comp_def] using hf + + + +theorem gridCavityMixture_fields (μ : ProbabilityMeasure OverlapArray) (m : ℕ) + {r : ℕ} (hr : 0 Real.log (2*Real.cosh (β*(∑ k,Real.sqrt (gridZVariance m k)*z k))))- + hierarchyFieldValue μ (cavityGrid m) r + (fun z => β*(∑ k,Real.sqrt (gridYVariance m k)*z k)) := by + have hc := lipschitz_log_cosh hβ + have ha : LipschitzWith (Real.toNNReal β) (fun x : ℝ => β*x) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,← mul_sub,abs_mul,abs_of_pos hβ,Real.coe_toNNReal β hβ.le] + exact le_rfl + have hci : Integrable (fun z => Real.log (2*Real.cosh (β*(∑ k,Real.sqrt (gridZVariance m k)*z k)))) + (gaussianLaw (Fin (m+1))) := by + simpa only [zero_add] using integrable_lipschitz_field (fun k => Real.sqrt (gridZVariance m k)) hc 0 + have hai : Integrable (fun z => β*(∑ k,Real.sqrt (gridYVariance m k)*z k)) + (gaussianLaw (Fin (m+1))) := by + simpa only [zero_add] using integrable_lipschitz_field (fun k => Real.sqrt (gridYVariance m k)) ha 0 + rw [hierarchyFieldValue_sum μ (cavityGrid m) hr (by fun_prop) hci, + hierarchyFieldValue_sum μ (cavityGrid m) hr (by fun_prop) hai,← Finset.sum_sub_distrib] + unfold gridCavityMixture + apply Finset.sum_congr rfl + intro T _ + rw [← mul_sub,cavityGramObservable, + coshGramPressure_field hr _ (treeGaussianCoeff T (gridZVariance m)) (grid_tree_z_kernel T) β, + squareGramPressure_field hr _ (treeGaussianCoeff T (gridYVariance m)) (grid_tree_y_kernel T) β] + have hz (z : TreeNode T → ℝ) (i : Fin r) := field_treeGaussianCoeff T (gridZVariance m) z i + have hy (z : TreeNode T → ℝ) (i : Fin r) := field_treeGaussianCoeff T (gridYVariance m) z i + simp only [hz,hy,treePathVector] + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Energy.lean b/lean/OAI/Probability/ParisiFinite/Energy.lean new file mode 100644 index 0000000000000000000000000000000000000000..cefcdb96da8dfabbf087df8fb728aec88403ac41 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Energy.lean @@ -0,0 +1,603 @@ +import Mathlib +import OAI.Probability.ParisiFinite.NegativeFlip + +namespace OAI + +/-! Energy. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +namespace SeedInitialization.CausalFrame +open CoherentFock PointedTree GramCalculus +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + + + +theorem energy (f : CausalFrame b n κ) (i : κ) : + Tendsto (fun T => energyInfinity (f.actual T i)) atTop + (𝓝 (SeededTree.treeEnergy n (f.formal i))) := by + have hn : Tendsto (fun T => ‖f.actual T i‖) atTop + (𝓝 ‖SeededTree.endogenous n (f.formal i)‖) := by + have hh := (f.packet i).norm f.gram + simp only [modeFock.norm_map,LinearIsometry.norm_map] at hh ⊢ + exact hh + have hc := (f.packet i).creation f.gram (fun T => f.actual T i) + (SeededTree.endogenous n (f.formal i)) + (fun j => f.gram j (Sum.inr i)) hn + have hr := (Complex.continuous_re.tendsto _).comp hc + change Tendsto (fun T => energyInfinity (f.actual T i)) atTop + (𝓝 (⟪(SeededTree.empty n).toLinearIsometry (f.formal i : SeededTree.Level n), + plusEmbedding (creationVacuum (SeededTree.endogenous n (f.formal i)))⟫_ℂ).re) + simpa only [Function.comp_def,←energyInfinity_fock] using hr + +end SeedInitialization.CausalFrame + + + +open scoped InnerProductSpace Topology BigOperators +namespace GramCalculus +open CoherentFock PointedTree RootSpin + + + +inductive TraceGate (κ : Type*) + | mixer (beta : ℝ) + | seed (angles : Fin 2 → ℝ) + | cost (index : κ) (gamma : ℝ) + +namespace TraceGate +variable {κ : Type*} [Fintype κ] + +def forget : TraceGate κ → SeededTree.Gate + | .mixer b => .mixer b + | .seed a => .seed a + | .cost _ c => .cost c + +def coeffSeed (a : Fin 2 → ℝ) : Fin 2 ⊕ κ → ℂ := + Sum.elim (fun i => -(a i:ℂ)) (fun _ => 0) + +def coeffCost (i : κ) (c : ℝ) : Fin 2 ⊕ κ → ℂ := by + classical + exact Pi.single (Sum.inr i) (-(c:ℂ)) + +def encode : TraceGate κ → WeylGate (Fin 2 ⊕ κ) + | .mixer b => .root (R b) (R_unitary b) + | .seed a => .pulse (coeffSeed a) + | .cost i c => .pulse (coeffCost i c) + +@[simp] theorem combination_cost {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (d : Fin 2 ⊕ κ → E) (i : κ) (c : ℝ) : + combination d (coeffCost i c)=-(c:ℂ) • d (Sum.inr i) := by + classical + simp [combination,coeffCost,Pi.single_apply] + + theorem basis_sum (a : Fin 2 → ℂ) : + (∑i,a i • SeedInitialization.seedBasis i)=WithLp.toLp 2 a := by + ext j + fin_cases j <;> simp [Fin.sum_univ_two,SeedInitialization.seedBasis,EuclideanSpace.single] + +@[simp] theorem combination_seed (n : ℕ) (d : κ → SeededTree.TopMode n) (a : Fin 2 → ℝ) : + combination (Sum.elim (fun i => SeededTree.external n (SeedInitialization.seedBasis i)) d) + (coeffSeed a)=SeededTree.external n (WithLp.toLp 2 (fun i => -(a i:ℂ))) := by + rw [show coeffSeed (κ:=κ) a=Sum.elim (fun i => -(a i:ℂ)) 0 from rfl,combination_sum_zero] + simp only [combination,←map_smul,←map_sum,basis_sum] + +def reindex {ν : Type*} (f : κ → ν) : TraceGate κ → TraceGate ν + | .mixer b => .mixer b + | .seed a => .seed a + | .cost i c => .cost (f i) c + +end TraceGate +namespace TraceWord +variable {κ : Type*} [Fintype κ] + +def forget (w : List (TraceGate κ)) : List SeededTree.Gate := w.map TraceGate.forget + +def encode (w : List (TraceGate κ)) : List (WeylGate (Fin 2 ⊕ κ)) := w.map TraceGate.encode + + + +def Valid (history : κ → List SeededTree.Gate) : List (TraceGate κ) → Prop + | [] => True + | .mixer _::w => Valid history w + | .seed _::w => Valid history w + | .cost i _::w => history i=forget w ∧ Valid history w + + + +theorem op_model (w : List (TraceGate κ)) (history : κ → List SeededTree.Gate) + (hv : Valid history w) (n : ℕ) : + WeylWord.op + (Sum.elim (fun i => SeededTree.external (n+1) (SeedInitialization.seedBasis i)) + (fun i => SeededTree.endogenous n (SeededTree.circuit (history i) n).insertion)) + (encode w)=(SeededTree.circuit (forget w) (n+1)).op := by + induction w with + | nil => rfl + | cons g w ih => + apply LinearIsometryEquiv.ext + intro x + cases g with + | mixer beta => + have h := ih hv + change SpinOperators.act (R beta) (WeylWord.op _ (encode w) x)= + SpinOperators.act (R beta) ((SeededTree.circuit (forget w) (n+1)).op x) + rw [h] + | seed a => + have h := ih hv + change WZ (combination _ (TraceGate.coeffSeed a)) (WeylWord.op _ (encode w) x)= + WZ (SeededTree.external (n+1) (WithLp.toLp 2 (fun j => -(a j:ℂ)))) + ((SeededTree.circuit (forget w) (n+1)).op x) + rw [TraceGate.combination_seed,h] + | cost i c => + have h := ih hv.2 + change WZ (combination _ (TraceGate.coeffCost i c)) (WeylWord.op _ (encode w) x)= + WZ (-(c:ℂ) • SeededTree.endogenous n (SeededTree.circuit (forget w) n).insertion) + ((SeededTree.circuit (forget w) (n+1)).op x) + rw [TraceGate.combination_cost,h] + simp only [Sum.elim_inr,hv.1] + + +omit [Fintype κ] in +@[simp] theorem forget_reindex {ν : Type*} (f : κ → ν) (w : List (TraceGate κ)) : + forget (w.map (TraceGate.reindex f))=forget w := by + induction w with + | nil => rfl + | cons g w ih => cases g <;> simp_all [forget,TraceGate.reindex,TraceGate.forget] + +omit [Fintype κ] in + theorem valid_reindex {ν : Type*} (f : κ → ν) (w : List (TraceGate κ)) + (history : κ → List SeededTree.Gate) (history' : ν → List SeededTree.Gate) + (h : ∀i,history' (f i)=history i) (hv : Valid history w) : + Valid history' (w.map (TraceGate.reindex f)) := by + induction w with + | nil => trivial + | cons g w ih => + cases g with + | mixer b => exact ih hv + | seed a => exact ih hv + | cost i c => + exact ⟨by simpa only [forget_reindex,h] using hv.1,ih hv.2⟩ + + + +theorem op_reindex {ν E : Type*} [Fintype ν] [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (f : κ → ν) (w : List (TraceGate κ)) (s : Fin 2 → E) (z : κ → E) (z' : ν → E) + (hz : ∀i,z' (f i)=z i) : + WeylWord.op (Sum.elim s z') (encode (w.map (TraceGate.reindex f)))= + WeylWord.op (Sum.elim s z) (encode w) := by + have hs (a : Fin 2 → ℝ) : combination (Sum.elim s z') (TraceGate.coeffSeed a)= + combination (Sum.elim s z) (TraceGate.coeffSeed a) := by + rw [show TraceGate.coeffSeed (κ:=ν) a=Sum.elim (fun i => -(a i:ℂ)) 0 from rfl, + show TraceGate.coeffSeed (κ:=κ) a=Sum.elim (fun i => -(a i:ℂ)) 0 from rfl, + combination_sum_zero,combination_sum_zero] + induction w with + | nil => rfl + | cons g w ih => + apply LinearIsometryEquiv.ext + intro x + cases g with + | mixer b => + change SpinOperators.act (R b) (WeylWord.op _ (encode (w.map _)) x)= + SpinOperators.act (R b) (WeylWord.op _ (encode w) x) + rw [ih] + | seed a => + change WZ (combination _ (TraceGate.coeffSeed a)) (WeylWord.op _ (encode (w.map _)) x)= + WZ (combination _ (TraceGate.coeffSeed a)) (WeylWord.op _ (encode w) x) + rw [hs,ih] + | cost i c => + change WZ (combination _ (TraceGate.coeffCost (f i) c)) (WeylWord.op _ (encode (w.map _)) x)= + WZ (combination _ (TraceGate.coeffCost i c)) (WeylWord.op _ (encode w) x) + simp only [TraceGate.combination_cost,Sum.elim_inr,hz,ih] + +end TraceWord +end GramCalculus + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus + + + +structure TaggedFrame (b : ℝ) (n : ℕ) (κ : Type*) [Fintype κ] where + frame : CausalFrame b n κ + history : κ → List SeededTree.Gate + length : ∀i,(history i).length≤n + identifies : ∀i,frame.formal i=(SeededTree.circuit (history i) n).insertion + +namespace TaggedFrame +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + +def initial (b : ℝ) (hb : 0 PEmpty.elim + formal := PEmpty.elim + gram := by + intro i j + cases i with + | inl i => + cases j with + | inl j => simpa only [Sum.elim_inl,LinearIsometry.inner_map_map] using seedDirections_gram b hb i j + | inr j => exact j.elim + | inr i => exact i.elim + bounded := fun i => i.elim + packet := fun i => i.elim } + history := PEmpty.elim + length := fun i => i.elim + identifies := fun i => i.elim + + + +def append (f : TaggedFrame b n κ) (hb : 0 modeFock (z T))) + (hm : ApproxMatch atTop f.frame.directions f.frame.model (fun T => modeFock (z T)) + ((SeededTree.circuit w (n+1)).insertion : SeededTree.Level (n+1))) : + TaggedFrame b (n+1) (κ ⊕ Unit) where + frame := f.frame.append hb z (SeededTree.circuit w (n+1)).insertion hz hm + history := Sum.elim f.history (fun _ => w) + length i := by + cases i with + | inl i => exact (f.length i).trans (Nat.le_succ n) + | inr i => exact hw + identifies i := by + cases i with + | inl i => + change centeredMap (SeededTree.empty n) (f.frame.formal i)= + (SeededTree.circuit (f.history i) (n+1)).insertion + rw [f.identifies,SeededTree.circuit_insertion_empty _ _ (f.length i)] + | inr i => rfl + + + +theorem op_model (f : TaggedFrame b n κ) (w : List (TraceGate κ)) + (hv : TraceWord.Valid f.history w) : + WeylWord.op f.frame.model (TraceWord.encode w)= + (SeededTree.circuit (TraceWord.forget w) (n+1)).op := by + have h : f.frame.model=Sum.elim + (fun i => SeededTree.external (n+1) (seedBasis i)) + (fun i => SeededTree.endogenous n (SeededTree.circuit (f.history i) n).insertion) := by + funext i + cases i with + | inl i => rfl + | inr i => exact congrArg (SeededTree.endogenous n) (f.identifies i) + rw [h] + exact TraceWord.op_model w f.history hv n + + + +def record {ι : Type*} [Fintype ι] (f : TaggedFrame b n κ) (hb : 0 (amplitude T)⁻¹) centers spin) + (w : List (TraceGate κ)) (hv : TraceWord.Valid f.history w) + (hw : (TraceWord.forget w).length≤n+1) + (hc : PacketUnitaryFamily.LowClose st.low (WeylWord.family (TraceWord.encode w) f.frame.gram)) + (hr : Tendsto amplitude atTop (𝓝 0)) (hp : ∀ᶠ T in atTop,0 insertionInfinity (st.word T)) (TraceWord.forget w) hw + (st.insertionZ_approx hr hp) ?_ + have h := st.insertionZ_match (TraceWord.encode w) f.frame.gram hc hr hp + have he := f.op_model w hv + simp only [CausalFrame.model] at he + rw [he] at h + exact h + +end TaggedFrame +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace GramCalculus +open CoherentFock PointedTree +variable {E F α ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [Fintype ι] {l : Filter α} + +namespace PacketMatch +variable {d : α → ι → E} {d₀ : ι → F} {x y : α → SpinSpace E} {x₀ y₀ : SpinSpace F} + +theorem zero : PacketMatch l d d₀ (fun _ => 0) 0 := by + refine ⟨0,fun _ i => Fin.elim0 i,fun i => Fin.elim0 i,fun i => Fin.elim0 i,?_,?_,?_⟩ + · intro q; ext j; simp [spinPacket_apply] + · ext j; simp [spinPacket_apply] + · intro i; exact Fin.elim0 i + +theorem add (hx : PacketMatch l d d₀ x x₀) (hy : PacketMatch l d d₀ y y₀) : + PacketMatch l d d₀ (fun q => x q+y q) (x₀+y₀) := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + obtain ⟨m,b,b₀,e,hy,hy₀,hb⟩ := hy + let f : Fin (n+m) ≃ Fin n ⊕ Fin m := finSumFinEquiv.symm + refine ⟨n+m,fun q i => Sum.elim (a q) (b q) (f i),fun i => Sum.elim a₀ b₀ (f i), + fun i => Sum.elim c e (f i),?_,?_,?_⟩ + · intro q + dsimp only + have hd : (fun i => combination (d q) (Sum.elim c e i))= + Sum.elim (fun i => combination (d q) (c i)) (fun i => combination (d q) (e i)) := by + funext i; cases i <;> rfl + rw [spinPacket_reindex f (Sum.elim (a q) (b q)) (fun i => combination (d q) (Sum.elim c e i)), + hd,←spinPacket_sum,hx,hy] + · have hd : (fun i => combination d₀ (Sum.elim c e i))= + Sum.elim (fun i => combination d₀ (c i)) (fun i => combination d₀ (e i)) := by + funext i; cases i <;> rfl + rw [spinPacket_reindex f (Sum.elim a₀ b₀) (fun i => combination d₀ (Sum.elim c e i)), + hd,←spinPacket_sum,hx₀,hy₀] + · intro i j + cases h : f i with + | inl k => simpa only [h,Sum.elim_inl] using ha k j + | inr k => simpa only [h,Sum.elim_inr] using hb k j + +end PacketMatch +namespace ApproxMatch +variable {d : α → ι → E} {d₀ : ι → F} {x y : α → SpinSpace E} {x₀ y₀ : SpinSpace F} + +theorem zero : ApproxMatch l d d₀ (fun _ => 0) 0 := PacketMatch.zero.approx + +theorem add (hx : ApproxMatch l d d₀ x x₀) (hy : ApproxMatch l d d₀ y y₀) : + ApproxMatch l d d₀ (fun q => x q+y q) (x₀+y₀) := by + obtain ⟨x',hx',he⟩ := hx + obtain ⟨y',hy',hf⟩ := hy + refine ⟨fun q => x' q+y' q,hx'.add hy',?_⟩ + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [add_zero] using he.add hf) + exact Eventually.of_forall fun q => by + rw [show x q+y q-(x' q+y' q)=(x q-x' q)+(y q-y' q) by abel] + exact norm_add_le _ _ + +theorem smul (hx : ApproxMatch l d d₀ x x₀) (z : ℂ) : + ApproxMatch l d d₀ (fun q => z • x q) (z • x₀) := by + obtain ⟨y,hy,he⟩ := hx + refine ⟨fun q => z • y q,hy.smul z,?_⟩ + simpa only [←smul_sub,norm_smul,mul_zero] using he.const_mul ‖z‖ + +theorem finSum {κ : Type*} [Fintype κ] (x : κ → α → SpinSpace E) (x₀ : κ → SpinSpace F) + (hx : ∀i,ApproxMatch l d d₀ (x i) (x₀ i)) : + ApproxMatch l d d₀ (fun q => ∑i,x i q) (∑i,x₀ i) := by + classical + have h (s : Finset κ) : ApproxMatch l d d₀ (fun q => ∑i∈s,x i q) (∑i∈s,x₀ i) := by + induction s using Finset.induction_on with + | empty => simpa only [Finset.sum_empty] using (zero (l:=l) (d:=d) (d₀:=d₀)) + | @insert i s hi ih => simpa only [Finset.sum_insert hi] using (hx i).add ih + exact h Finset.univ + +end ApproxMatch +end GramCalculus + +namespace SeedInitialization.CausalFrame +open CoherentFock PointedTree GramCalculus +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + + + +theorem combination_packet (f : CausalFrame b n κ) (c : κ → ℂ) : + ApproxMatch atTop f.directions f.model + (fun T => modeFock (combination (f.actual T) c)) + ((SeededTree.empty n).toLinearIsometry + (combination (fun i => (f.formal i : SeededTree.Level n)) c)) := by + unfold CausalFrame.directions CausalFrame.model + simp only [combination,map_sum,map_smul] + exact ApproxMatch.finSum (fun i T => c i • modeFock (f.actual T i)) + (fun i => c i • (SeededTree.empty n).toLinearIsometry (f.formal i : SeededTree.Level n)) + (fun i => (f.packet i).smul (c i)) + +end SeedInitialization.CausalFrame + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus RootSpin + +@[simp] theorem amplitude_inverse (T : ℝ) : (amplitude T)⁻¹=T := inv_inv T + +theorem amplitude_zero : Tendsto amplitude atTop (𝓝 0) := tendsto_inv_atTop_zero + +theorem amplitude_eventually_pos : ∀ᶠ T : ℝ in atTop,0 amplitude_pos h + +def reciprocalInitialStage (b : ℝ) : + PacketStage (atTop : Filter ℝ) amplitude (fun T => (amplitude T)⁻¹) + (fun i : Fin 2×Fin 2 => fun _ => initialCenter b i.1) Prod.snd where + word := (initialStage b).word + ordinary := (initialStage b).ordinary + special := (initialStage b).special + split := (initialStage b).split + special_norm := (initialStage b).special_norm + low := (initialStage b).low + phase := (initialStage b).phase + phase_norm := (initialStage b).phase_norm + ordinary_low x hx := by simpa only [amplitude_inverse,id_eq] using (initialStage b).ordinary_low x hx + special_packets x hx := by + rw [show (fun T => (amplitude T)⁻¹)=id from funext amplitude_inverse] + exact (initialStage b).special_packets x hx + +def initialTrace {κ : Type*} (b : ℝ) : List (TraceGate κ) := + [.mixer (Real.pi/4),.seed (SeededTree.initializationAngles b)] + +@[simp] theorem initialTrace_forget {κ : Type*} [Fintype κ] (b : ℝ) : + TraceWord.forget (initialTrace (κ:=κ) b)=SeededTree.initializationWord b := rfl + +theorem initialTrace_valid {κ : Type*} [Fintype κ] (b : ℝ) (h : κ → List SeededTree.Gate) : + TraceWord.Valid h (initialTrace b) := by trivial + +theorem combination_initial {κ : Type*} [Fintype κ] (b T : ℝ) (z : κ → ModeInfinity) : + combination (Sum.elim (seedDirections b T) z) + (TraceGate.coeffSeed (SeededTree.initializationAngles b))= + (2*b:ℂ) • highInfinity (gamma b T) := by + rw [show TraceGate.coeffSeed (κ:=κ) (SeededTree.initializationAngles b)= + Sum.elim (fun i => -(SeededTree.initializationAngles b i:ℂ)) 0 from rfl, + combination_sum_zero] + simp [combination,Fin.sum_univ_two,SeededTree.initializationAngles,seedDirections, + -Complex.coe_smul,Complex.ofReal_mul] + + + +theorem initial_lowClose {n : ℕ} {κ : Type*} [Fintype κ] (b : ℝ) (f : CausalFrame b n κ) : + PacketUnitaryFamily.LowClose (lowInfinity b) + (WeylWord.family (TraceWord.encode (initialTrace b)) f.gram) := by + intro x hx + have he : ∀ᶠ T : ℝ in atTop,‖(2*b:ℂ) • highInfinity (gamma b T)‖≤2*|b| := by + exact Eventually.of_forall fun T => by + simp only [norm_smul,norm_highInfinity,mul_one,Complex.norm_mul,Complex.norm_ofNat, + Complex.norm_real,Real.norm_eq_abs,le_refl] + have hh := hx.pulse_close (dInfinity b) (fun T => (2*b:ℂ) • highInfinity (gamma b T)) + (2*|b|) he (by simpa only [←Complex.coe_smul,Complex.ofReal_mul,Complex.ofReal_ofNat] + using dInfinity_approx_high b) + change Tendsto (fun T => ‖SpinOperators.act (R (Real.pi/4)) (WZ (dInfinity b T) (x T))- + SpinOperators.act (R (Real.pi/4)) (WZ + (combination (Sum.elim (seedDirections b T) (f.actual T)) + (TraceGate.coeffSeed (SeededTree.initializationAngles b))) (x T))‖) atTop (𝓝 0) + simp only [combination_initial,←map_sub,SpinOperators.norm_act (R_unitary _)] + exact hh + + + +def initialRecorded (b : ℝ) (hb : 0 eInfinity) [] (by simp) ?_ ?_ + · simpa only [modeFock_eInfinity] using + (BoundedPacket.root (BoundedPacket.vacuum (l:=(atTop : Filter ℝ)) (E:=ModeInfinity)) Z).approx + · change ApproxMatch atTop f.frame.directions f.frame.model + (fun _ => modeFock eInfinity) + (SpinOperators.act Z (vacuum (SeededTree.TopMode (n+1)))) + simp only [modeFock_eInfinity] + exact (PacketMatch.vacuum.root Z).approx + +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus RootSpin + +namespace CausalFrame +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + +def centerModel (f : CausalFrame b n κ) (c : κ → ℂ) : SeededTree.Level (n+1) := + (SeededTree.empty n).toLinearIsometry + (combination (fun i => (f.formal i : SeededTree.Level n)) c) + +def visibility (f : CausalFrame b n κ) (w : List (TraceGate κ)) (c : κ → ℂ) + (P : Matrix (Fin 2) (Fin 2) ℂ) : ℝ := + -2*(⟪(WeylWord.op f.model (TraceWord.encode w)).symm + (SpinOperators.act P (WeylWord.op f.model (TraceWord.encode w) + (vacuum (SeededTree.TopMode (n+1))))),f.centerModel c⟫_ℂ).im + + + +theorem center_match (f : CausalFrame b n κ) (c : κ → ℂ) (d : ℝ → ModeInfinity) + (he : Tendsto (fun T => ‖d T-combination (f.actual T) c‖) atTop (𝓝 0)) : + ApproxMatch atTop f.directions f.model (fun T => modeFock (d T)) (f.centerModel c) := by + apply (f.combination_packet c).close + simpa only [←map_sub,modeFock.norm_map] using he + + + +theorem visibility_limit {ι : Type*} [Fintype ι] (f : CausalFrame b n κ) + {centers : ι → ℝ → ModeInfinity} {spin : ι → Fin 2} + (st : PacketStage atTop amplitude (fun T => (amplitude T)⁻¹) centers spin) + (w : List (TraceGate κ)) + (hc : PacketUnitaryFamily.LowClose st.low (WeylWord.family (TraceWord.encode w) f.gram)) + (c : κ → ℂ) (d : ℝ → ModeInfinity) + (he : Tendsto (fun T => ‖d T-combination (f.actual T) c‖) atTop (𝓝 0)) + (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) : + Tendsto (fun T => -2*(⟪(ordinaryLocal (st.word T)).symm + (SpinOperators.act P (ordinaryLocal (st.word T) (vacuum ModeInfinity))),modeFock (d T)⟫_ℂ).im) + atTop (𝓝 (f.visibility w c P)) := by + have hz := st.actual_insertion_match (TraceWord.encode w) f.gram hc + amplitude_zero amplitude_eventually_pos P hP + have hh := hz.inner (f.center_match c d he) f.gram + exact ((Complex.continuous_im.tendsto _).comp hh).const_mul (-2) + +theorem visibility_Z {ι : Type*} [Fintype ι] (f : CausalFrame b n κ) + {centers : ι → ℝ → ModeInfinity} {spin : ι → Fin 2} + (st : PacketStage atTop amplitude (fun T => (amplitude T)⁻¹) centers spin) + (w : List (TraceGate κ)) + (hc : PacketUnitaryFamily.LowClose st.low (WeylWord.family (TraceWord.encode w) f.gram)) + (c : κ → ℂ) (d : ℝ → ModeInfinity) + (he : Tendsto (fun T => ‖d T-combination (f.actual T) c‖) atTop (𝓝 0)) : + Tendsto (fun T => -2*(⟪insertionInfinity (st.word T),d T⟫_ℂ).im) + atTop (𝓝 (f.visibility w c Z)) := by + simpa only [←modeFock_insertion,modeFock.inner_map_map] using + f.visibility_limit st w hc c d he Z Z_unitary + +theorem visibility_Y {ι : Type*} [Fintype ι] (f : CausalFrame b n κ) + {centers : ι → ℝ → ModeInfinity} {spin : ι → Fin 2} + (st : PacketStage atTop amplitude (fun T => (amplitude T)⁻¹) centers spin) + (w : List (TraceGate κ)) + (hc : PacketUnitaryFamily.LowClose st.low (WeylWord.family (TraceWord.encode w) f.gram)) + (c : κ → ℂ) (d : ℝ → ModeInfinity) + (he : Tendsto (fun T => ‖d T-combination (f.actual T) c‖) atTop (𝓝 0)) : + Tendsto (fun T => -2*(⟪insertionYInfinity (st.word T),d T⟫_ℂ).im) + atTop (𝓝 (f.visibility w c Y)) := by + simpa only [←modeFock_insertionY,modeFock.inner_map_map] using + f.visibility_limit st w hc c d he Y Y_unitary + +end CausalFrame +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +theorem exists_compensated_transport + (st : PacketStage l r (fun q => (r q)⁻¹) d spin) (θ : ℝ) + (address : α → SpinSpace ModeInfinity) (ht : st.Transported address) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 -2*(⟪insertionInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (v i).1)) + (hY : ∀i,Tendsto (fun q => -2*(⟪insertionYInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (v i).2)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse) (st' : PacketStage l r (fun q => (r q)⁻¹) d spin), + (∀q,st'.word q=.mixer θ::probePrefix (r q) (st.word q) a K) ∧ + (∀q x,st'.low.op q x=SpinOperators.act (R θ) (st.low.op q x)) ∧ st'.Transported address := by + obtain ⟨K,a,ho,hs⟩ := st.exists_standard_selector (-θ) hr hp C hC hd v hv hZ hY + have hS : ∀ᶠ q in l,0≤(r q)⁻¹ := hp.mono fun _ hq => (inv_pos.mpr hq).le + let st' := st.compensated θ a K hS ho (fun x hx => hs _ (st.special_packets x hx)) + refine ⟨K,a,st',fun _ => rfl,fun _ _ => rfl,?_⟩ + exact ht.compensated θ a K hS ho (fun x hx => hs _ (st.special_packets x hx)) + (hs _ (st.special_packets _ BoundedPacket.vacuum).rootZ) + +end PacketStage +end PointedTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ExpVector.lean b/lean/OAI/Probability/ParisiFinite/ExpVector.lean new file mode 100644 index 0000000000000000000000000000000000000000..35eabe538908f53a4ff758ea987da02de48ac483 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ExpVector.lean @@ -0,0 +1,711 @@ +import Mathlib +import OAI.Probability.ParisiFinite.GramPosSemidef + +namespace OAI + +/-! Exp Vector. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +namespace CoherentFock +open scoped Interval +open Complex MeasureTheory +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +def expVector (d : E) : Space E := + (Real.exp (‖d‖^2/2) : ℂ) • coherent d + +@[simp] theorem inner_expVector (d e : E) : + ⟪expVector d,expVector e⟫_ℂ = Complex.exp ⟪d,e⟫_ℂ := by + simp only [expVector,inner_smul_left,inner_smul_right,inner_coherent, + kernel] + rw [Complex.conj_ofReal] + simp only [Complex.ofReal_exp] + rw [← Complex.exp_add,← Complex.exp_add] + congr 1 + push_cast + ring + +theorem continuous_expVector : Continuous (expVector (E := E)) := + ((Complex.continuous_ofReal.comp (Real.continuous_exp.comp + (continuous_norm.pow 2 |>.div_const 2)))).smul continuous_coherent + +@[simp] theorem expVector_zero : expVector (0 : E) = coherent 0 := by simp [expVector] + +theorem eq_of_inner_coherent {x y : Space E} + (h : ∀ d, ⟪x,coherent d⟫_ℂ = ⟪y,coherent d⟫_ℂ) : x=y := by + have he : innerSL ℂ x = innerSL ℂ y := ext_coherent h + exact ext_inner_right ℂ fun v => congrArg (fun f : Space E →L[ℂ] ℂ => f v) he + +theorem eq_of_inner_expVector {x y : Space E} + (h : ∀ d, ⟪expVector d,x⟫_ℂ = ⟪expVector d,y⟫_ℂ) : x=y := by + apply eq_of_inner_coherent + intro d + have he := h d + simp only [expVector,inner_smul_left,conj_ofReal] at he + have hz : (Real.exp (‖d‖^2/2) : ℂ) ≠ 0 := by exact_mod_cast Real.exp_ne_zero _ + have h' := mul_left_cancel₀ hz he + simpa only [inner_conj_symm] using congrArg conj h' + +theorem map_circleIntegral {F G : Type*} [NormedAddCommGroup F] [NormedSpace ℂ F] + [CompleteSpace F] [NormedAddCommGroup G] [NormedSpace ℂ G] [CompleteSpace G] + (L : F →L[ℂ] G) {f : ℂ → F} {c : ℂ} {r : ℝ} (hf : CircleIntegrable f c r) : + L (∮ z in C(c,r), f z) = ∮ z in C(c,r), L (f z) := by + simp only [circleIntegral] + rw [← L.intervalIntegral_comp_comm hf.out] + simp only [map_smul] + +def oneParticle (d : E) : Space E := + (2*(Real.pi:ℂ)*I)⁻¹ • ∮ z in C(0,1), (1/z^2) • expVector (z • d) + +theorem circleIntegrable_oneParticle_integrand (d : E) : + CircleIntegrable (fun z : ℂ => (1/z^2) • expVector (z • d)) 0 1 := by + apply ContinuousOn.circleIntegrable (by norm_num) + have hscalar : ContinuousOn (fun z : ℂ => 1/z^2) (Metric.sphere 0 1) := + continuousOn_const.div (continuousOn_id.pow 2) fun z hz => by + have h : ‖z‖ = 1 := by simpa [Metric.mem_sphere,dist_zero_right] using hz + exact pow_ne_zero _ (norm_ne_zero_iff.mp (by rw [h]; norm_num)) + exact hscalar.smul (continuous_expVector.comp (continuous_id.smul continuous_const)).continuousOn + +@[simp] theorem inner_expVector_oneParticle (e d : E) : + ⟪expVector e,oneParticle d⟫_ℂ = ⟪e,d⟫_ℂ := by + rw [oneParticle,inner_smul_right] + have hi := map_circleIntegral (innerSL ℂ (expVector e)) + (circleIntegrable_oneParticle_integrand d) + simp only [innerSL_apply_apply,inner_smul_right,inner_expVector,inner_smul_right] at hi + rw [hi] + have hdiff : Differentiable ℂ (fun z : ℂ => Complex.exp (z*⟪e,d⟫_ℂ)) := + Complex.differentiable_exp.comp (differentiable_id.mul_const _) + have hc := DifferentiableOn.deriv_eq_smul_circleIntegral (c := (0:ℂ)) + (R := (1:ℝ)) (by norm_num) hdiff.differentiableOn + have hd : deriv (fun z : ℂ => Complex.exp (z*⟪e,d⟫_ℂ)) 0 = ⟪e,d⟫_ℂ := by + have hh : HasDerivAt (fun z : ℂ => Complex.exp (z*⟪e,d⟫_ℂ)) ⟪e,d⟫_ℂ 0 := by + simpa only [id_eq,zero_mul,Complex.exp_zero,one_mul] using + (((hasDerivAt_id (0:ℂ)).mul_const ⟪e,d⟫_ℂ).cexp) + exact hh.deriv + simp only [sub_zero,smul_eq_mul,hd] at hc + rw [hc] + have hz : 2*(Real.pi:ℂ)*I ≠ 0 := by exact mul_ne_zero (mul_ne_zero (by norm_num) + (Complex.ofReal_ne_zero.mpr Real.pi_ne_zero)) I_ne_zero + exact inv_mul_cancel_left₀ hz _ + +@[simp] theorem inner_oneParticle_expVector (d e : E) : + ⟪oneParticle d,expVector e⟫_ℂ = ⟪d,e⟫_ℂ := by + rw [← inner_conj_symm,inner_expVector_oneParticle,inner_conj_symm] + +@[simp] theorem inner_oneParticle (d e : E) : + ⟪oneParticle d,oneParticle e⟫_ℂ = ⟪d,e⟫_ℂ := by + change ⟪oneParticle d,(2*(Real.pi:ℂ)*I)⁻¹ • + ∮ z in C(0,1), (1/z^2) • expVector (z • e)⟫_ℂ = _ + rw [inner_smul_right] + have hi := map_circleIntegral (innerSL ℂ (oneParticle d)) + (circleIntegrable_oneParticle_integrand e) + simp only [innerSL_apply_apply,inner_smul_right,inner_oneParticle_expVector] at hi + rw [hi] + have hc := DifferentiableOn.deriv_eq_smul_circleIntegral (c := (0:ℂ)) + (R := (1:ℝ)) (by norm_num) (differentiable_id.mul_const ⟪d,e⟫_ℂ).differentiableOn + have hd : deriv (fun z : ℂ => z*⟪d,e⟫_ℂ) 0 = ⟪d,e⟫_ℂ := by simp + simp only [id_eq,sub_zero,smul_eq_mul,hd] at hc + rw [hc] + have hz : 2*(Real.pi:ℂ)*I ≠ 0 := by exact mul_ne_zero (mul_ne_zero (by norm_num) + (Complex.ofReal_ne_zero.mpr Real.pi_ne_zero)) I_ne_zero + exact inv_mul_cancel_left₀ hz _ + + + +def oneParticleEmbedding : E →ₗᵢ[ℂ] Space E where + toFun := oneParticle + map_add' x y := by + apply eq_of_inner_expVector + intro d + simp [inner_add_right] + map_smul' z x := by + apply eq_of_inner_expVector + intro d + simp [inner_smul_right] + norm_map' d := by + change ‖oneParticle d‖=‖d‖ + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),inner_oneParticle] + exact (norm_eq_sqrt_re_inner (𝕜 := ℂ) d).symm + +@[simp] theorem oneParticle_orthogonal_vacuum (d : E) : + ⟪coherent 0,oneParticle d⟫_ℂ = 0 := by + rw [← expVector_zero,inner_expVector_oneParticle,inner_zero_left] + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +open Complex + +@[simp] theorem norm_oneParticle (d : E) : ‖oneParticle d‖ = ‖d‖ := + oneParticleEmbedding.norm_map d + +@[simp] theorem inner_coherent_oneParticle (e d : E) : + ⟪coherent e,oneParticle d⟫_ℂ = (Real.exp (-‖e‖^2/2) : ℂ) * ⟪e,d⟫_ℂ := by + have h := inner_expVector_oneParticle e d + simp only [expVector,inner_smul_left] at h + rw [Complex.conj_ofReal] at h + have hex : (Real.exp (-‖e‖^2/2) : ℂ) * (Real.exp (‖e‖^2/2) : ℂ) = 1 := by + have hs : -‖e‖^2/2+‖e‖^2/2 = 0 := by ring + rw [← Complex.ofReal_mul,← Real.exp_add,hs,Real.exp_zero,Complex.ofReal_one] + calc + _ = ((Real.exp (-‖e‖^2/2) : ℂ) * (Real.exp (‖e‖^2/2) : ℂ)) * + ⟪coherent e,oneParticle d⟫_ℂ := by rw [hex,one_mul] + _ = _ := by rw [mul_assoc,h] + +theorem W_neg_cancel (d : E) (x : Space E) : W d (W (-d) x)=x := + (weyl d).apply_symm_apply x + +theorem inner_W_right (d : E) (x y : Space E) : + ⟪x,W d y⟫_ℂ = ⟪W (-d) x,y⟫_ℂ := by + calc + _ = ⟪W d (W (-d) x),W d y⟫_ℂ := by rw [W_neg_cancel] + _ = _ := inner_W d _ _ + +theorem inner_coherent_W_oneParticle (e d v : E) : + ⟪coherent e,W d (oneParticle v)⟫_ℂ = kernel e d * ⟪e-d,v⟫_ℂ := by + rw [inner_W_right,W_coherent,inner_smul_left,inner_coherent_oneParticle] + rw [kernel_eq] + have hi := inner_im_symm (𝕜 := ℂ) d e + change (⟪d,e⟫_ℂ).im = -(⟪e,d⟫_ℂ).im at hi + have he : -d+e = e-d := by abel + rw [he] + simp only [phase,inner_neg_left,Complex.neg_im,hi,neg_neg, + ← Complex.exp_conj,Complex.ofReal_exp,map_mul,Complex.conj_ofReal, + Complex.conj_I] + rw [← mul_assoc,← Complex.exp_add] + congr 2 + push_cast + ring + + + +def fieldCoherent (v d : E) : Space E := + (-I) • W d (oneParticle v) - ((2*(⟪v,d⟫_ℂ).im : ℝ) : ℂ) • coherent d + +theorem inner_coherent_field (e v d : E) : + ⟪coherent e,fieldCoherent v d⟫_ℂ = + I * (⟪v,d⟫_ℂ-⟪e,v⟫_ℂ) * kernel e d := by + simp only [fieldCoherent,inner_sub_right,inner_smul_right, + inner_coherent_W_oneParticle,inner_coherent,inner_sub_left] + have hi : ⟪v,d⟫_ℂ-⟪d,v⟫_ℂ = (2*(⟪v,d⟫_ℂ).im : ℂ)*I := by + rw [← inner_conj_symm d v] + simpa only [Complex.ofReal_mul,Complex.ofReal_ofNat] using Complex.sub_conj ⟪v,d⟫_ℂ + calc + _ = (-I*⟪e,v⟫_ℂ+I*⟪d,v⟫_ℂ-((2*(⟪v,d⟫_ℂ).im : ℝ):ℂ))*kernel e d := by ring + _ = _ := by + congr 1 + have him : ((2*(⟪v,d⟫_ℂ).im : ℝ):ℂ) = -I*(⟪v,d⟫_ℂ-⟪d,v⟫_ℂ) := by + rw [hi] + push_cast + rw [show -I*(2*(⟪v,d⟫_ℂ).im*I) = -(2*(⟪v,d⟫_ℂ).im)*(I*I) by ring, I_mul_I] + ring + rw [him] + ring + +theorem fieldCoherent_symmetric (e v d : E) : + ⟪coherent e,fieldCoherent v d⟫_ℂ = ⟪fieldCoherent v e,coherent d⟫_ℂ := by + rw [show ⟪fieldCoherent v e,coherent d⟫_ℂ = conj ⟪coherent d,fieldCoherent v e⟫_ℂ + from (inner_conj_symm _ _).symm,inner_coherent_field,inner_coherent_field] + have hk : conj (kernel d e) = kernel e d := by + rw [← inner_coherent,← inner_coherent,inner_conj_symm] + simp only [map_mul,map_sub,Complex.conj_I,inner_conj_symm,hk] + ring + +theorem norm_fieldCoherent_le (v d : E) : + ‖fieldCoherent v d‖ ≤ ‖v‖*(1+2*‖d‖) := by + calc + _ ≤ ‖(-I) • W d (oneParticle v)‖+ + ‖((2*(⟪v,d⟫_ℂ).im : ℝ):ℂ) • coherent d‖ := norm_sub_le _ _ + _ = ‖v‖+2*|(⟪v,d⟫_ℂ).im| := by + simp [norm_smul,Complex.norm_real,Real.norm_eq_abs] + _ ≤ ‖v‖+2*(‖v‖*‖d‖) := by + have hh := (Complex.abs_im_le_norm ⟪v,d⟫_ℂ).trans (norm_inner_le_norm v d) + linarith + _ = _ := by ring + + +theorem fieldCoherent_weyl_shift (v d e : E) : + phase d e • fieldCoherent v (d+e) = + W d (fieldCoherent v e) - ((2*(⟪v,d⟫_ℂ).im : ℝ):ℂ) • W d (coherent e) := by + have hw := congrArg (fun A : Space E →L[ℂ] Space E => A (oneParticle v)) (W_mul d e) + simp only [ContinuousLinearMap.comp_apply,smul_apply] at hw + simp only [fieldCoherent,map_sub,map_smul,hw,W_coherent,inner_add_right,Complex.add_im] + push_cast + module + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +open Complex + + +def preField (v : E) : PreSpace E →ₗ[ℂ] Space E := + (Finsupp.linearCombination ℂ (fieldCoherent v)).comp toFinsupp.toLinearMap + +@[simp] theorem preField_basis (v d : E) : preField v (basis d) = fieldCoherent v d := by + classical + simp [preField,basis] + +theorem preField_eq_sum (v : E) (x : PreSpace E) : + preField v x = (toFinsupp x).sum (fun e a => a • fieldCoherent v e) := rfl + +theorem preField_symmetric (v : E) (x y : PreSpace E) : + ⟪(↑x : Space E),preField v y⟫_ℂ = ⟪preField v x,(↑y : Space E)⟫_ℂ := by + classical + simp only [coe_eq_sum,preField_eq_sum,Finsupp.sum,sum_inner,inner_sum, + inner_smul_left,inner_smul_right] + simp only [fieldCoherent_symmetric] + + + +theorem preField_ker (v : E) {x : PreSpace E} (hx : (↑x : Space E)=0) : + preField v x = 0 := by + apply eq_of_inner_coherent + intro d + rw [inner_zero_left] + have hh := preField_symmetric v x (basis d) + simpa only [hx,inner_zero_left,coe_basis] using hh.symm + +def spanEmbedding : PreSpace E →ₗ[ℂ] Space E := + UniformSpace.Completion.toComplL.toLinearMap + +def fieldDomain : Submodule ℂ (Space E) := LinearMap.range (spanEmbedding (E := E)) + +def field (v : E) : fieldDomain (E := E) →ₗ[ℂ] Space E := + ((spanEmbedding (E := E)).ker.liftQ (preField v) (fun _ hx => + preField_ker v hx)).comp (spanEmbedding (E := E)).quotKerEquivRange.symm.toLinearMap + +def inDomain (x : PreSpace E) : fieldDomain (E := E) := + (spanEmbedding (E := E)).rangeRestrict x + +@[simp] theorem coe_inDomain (x : PreSpace E) : (inDomain x : Space E) = ↑x := rfl + +@[simp] theorem field_inDomain (v : E) (x : PreSpace E) : + field v (inDomain x) = preField v x := by + change (spanEmbedding.ker.liftQ (preField v) (fun _ hx => preField_ker v hx)) + (spanEmbedding.quotKerEquivRange.symm ⟨spanEmbedding x,_⟩) = _ + rw [LinearMap.quotKerEquivRange_symm_apply_image] + rfl + +theorem field_symmetric (v : E) (x y : fieldDomain (E := E)) : + ⟪(x : Space E),field v y⟫_ℂ = ⟪field v x,(y : Space E)⟫_ℂ := by + obtain ⟨x',hx⟩ := x.property + obtain ⟨y',hy⟩ := y.property + have hx' : inDomain x'=x := Subtype.ext hx + have hy' : inDomain y'=y := Subtype.ext hy + rw [← hx',← hy',field_inDomain,field_inDomain,coe_inDomain,coe_inDomain] + exact preField_symmetric v x' y' + +theorem preField_weyl_shift (v d : E) (x : PreSpace E) : + preField v (preWLinear d x) = W d (preField v x) - + ((2*(⟪v,d⟫_ℂ).im : ℝ):ℂ) • W d (↑x) := by + classical + let A := (preField v).comp (preWLinear d) + let B := ((W d).toLinearMap.comp (preField v)) - + ((2*(⟪v,d⟫_ℂ).im : ℝ):ℂ) • ((W d).toLinearMap.comp spanEmbedding) + have hb (e : E) : A (basis e)=B (basis e) := by + change preField v (preWLinear d (basis e)) = W d (preField v (basis e)) - + ((2*(⟪v,d⟫_ℂ).im : ℝ):ℂ) • W d (↑(basis e)) + rw [preWLinear_basis,map_smul,preField_basis,preField_basis,coe_basis] + exact fieldCoherent_weyl_shift v d e + change A x=B x + rw [← sum_basis x] + simp only [Finsupp.sum,map_sum,map_smul,hb] + + + +theorem coherent_taylor_one (d : E) : + ‖coherent d-coherent 0-oneParticle d‖ ≤ ‖d‖^2 := by + have hip : ⟪coherent d,oneParticle d⟫_ℂ = + (Real.exp (-‖d‖^2/2)*‖d‖^2 : ℝ) := by + rw [inner_coherent_oneParticle,inner_self_eq_norm_sq_to_K] + push_cast + rfl + have hi0 : ⟪coherent 0,oneParticle d⟫_ℂ = 0 := oneParticle_orthogonal_vacuum d + have hk : (kernel d 0).re = Real.exp (-‖d‖^2/2) := by + unfold kernel + simp only [norm_zero,inner_zero_right,zero_pow,ne_eq,OfNat.ofNat_ne_zero,not_false_eq_true, + neg_zero,zero_div,Complex.ofReal_zero,add_zero] + rw [← Complex.ofReal_exp] + rfl + have hn : ‖coherent d-coherent 0-oneParticle d‖^2 = + 2+‖d‖^2-2*(1+‖d‖^2)*Real.exp (-‖d‖^2/2) := by + rw [norm_sub_sq (𝕜 := ℂ),norm_sub_sq (𝕜 := ℂ),inner_coherent, + norm_coherent,norm_coherent,norm_oneParticle,inner_sub_left,hip,hi0] + simp only [sub_zero,RCLike.re_to_complex,Complex.ofReal_re] + rw [hk] + ring + have he : 1-‖d‖^2/2 ≤ Real.exp (-‖d‖^2/2) := by + convert Real.add_one_le_exp (-‖d‖^2/2) using 1 + ring + have hh := mul_le_mul_of_nonneg_left he (by positivity : 0 ≤ 2*(1+‖d‖^2)) + have hsq : ‖coherent d-coherent 0-oneParticle d‖^2 ≤ (‖d‖^2)^2 := by + rw [hn] + nlinarith + nlinarith [norm_nonneg (coherent d-coherent 0-oneParticle d),sq_nonneg ‖d‖] + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +theorem coherent_sub_vacuum_le (d : E) : ‖coherent d-coherent (0:E)‖ ≤ ‖d‖ := by + have hsq : ‖coherent d-coherent (0:E)‖^2 = 2-2*Real.exp (-‖d‖^2/2) := by + rw [norm_sub_sq (𝕜 := ℂ)] + simp only [norm_coherent,one_pow,inner_coherent,kernel,inner_zero_right,norm_zero, + ne_eq,OfNat.ofNat_ne_zero,not_false_eq_true,zero_pow,neg_zero,zero_div,add_zero] + simp only [Complex.ofReal_zero,add_zero,← Complex.ofReal_exp] + change 1-2*Real.exp (-‖d‖^2/2)+1 = _ + ring + have he := Real.add_one_le_exp (-‖d‖^2/2) + nlinarith [norm_nonneg (coherent d-coherent (0:E)),norm_nonneg d] + +theorem phase_sub_one_le (d e : E) : ‖phase d e-1‖ ≤ ‖d‖*‖e‖ := by + calc + ‖phase d e-1‖ ≤ |(⟪d,e⟫_ℂ).im| := by + simpa only [phase,mul_comm,Real.norm_eq_abs,abs_neg] using + (Real.norm_exp_I_mul_ofReal_sub_one_le (x := -(⟪d,e⟫_ℂ).im)) + _ ≤ ‖⟪d,e⟫_ℂ‖ := Complex.abs_im_le_norm _ + _ ≤ ‖d‖*‖e‖ := norm_inner_le_norm d e + + + +theorem W_coherent_sub_le (d e : E) : + ‖W d (coherent e)-coherent e‖ ≤ ‖d‖*(1+2*‖e‖) := by + have heq : W d (coherent e)-coherent e = + (phase d e-phase e d) • coherent (d+e) + W e (coherent d-coherent 0) := by + simp only [map_sub,W_coherent,phase_zero_right,add_zero,one_smul] + rw [add_comm e d] + module + rw [heq] + calc + _ ≤ ‖(phase d e-phase e d) • coherent (d+e)‖ + ‖W e (coherent d-coherent 0)‖ := norm_add_le _ _ + _ = ‖phase d e-phase e d‖ + ‖coherent d-coherent (0:E)‖ := by + rw [norm_smul,norm_coherent,mul_one,norm_W] + _ ≤ (‖phase d e-1‖+‖phase e d-1‖)+‖d‖ := by + gcongr + · have ht := dist_triangle (phase d e) 1 (phase e d) + rw [dist_comm 1 (phase e d)] at ht + simpa only [dist_eq_norm] using ht + · exact coherent_sub_vacuum_le d + _ ≤ (‖d‖*‖e‖+‖e‖*‖d‖)+‖d‖ := by + gcongr + · exact phase_sub_one_le d e + · exact phase_sub_one_le e d + _ = _ := by ring + + +def tailBound (x : PreSpace E) : ℝ := + (toFinsupp x).sum (fun e a => ‖a‖*(1+2*‖e‖)) + +theorem W_coe_sub_le (d : E) (x : PreSpace E) : + ‖W d (↑x)-(↑x : Space E)‖ ≤ ‖d‖*tailBound x := by + classical + rw [coe_eq_sum] + simp only [Finsupp.sum,map_sum,map_smul,← Finset.sum_sub_distrib,← smul_sub] + calc + _ ≤ ∑ e ∈ (toFinsupp x).support, ‖(toFinsupp x) e • (W d (coherent e)-coherent e)‖ := + norm_sum_le _ _ + _ ≤ ∑ e ∈ (toFinsupp x).support, ‖(toFinsupp x) e‖*(‖d‖*(1+2*‖e‖)) := by + apply Finset.sum_le_sum + intro e he + rw [norm_smul] + exact mul_le_mul_of_nonneg_left (W_coherent_sub_le d e) (norm_nonneg _) + _ = _ := by + simp only [tailBound,Finsupp.sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he + ring + + +theorem centered_probe (d e : E) : + (W (-e)).comp ((W d).comp (W e)) = + Complex.exp (((-2*(⟪d,e⟫_ℂ).im : ℝ) : ℂ)*Complex.I) • W d := by + rw [W_mul] + rw [ContinuousLinearMap.comp_smul,W_mul] + simp only [smul_smul] + have hd : -e+(d+e)=d := by abel + rw [hd] + have hp : phase d e * phase (-e) (d+e) = + Complex.exp (((-2*(⟪d,e⟫_ℂ).im : ℝ) : ℂ)*Complex.I) := by + have hi : (⟪e,e⟫_ℂ).im=0 := inner_self_im (𝕜 := ℂ) e + have hs := inner_im_symm (𝕜 := ℂ) e d + change (⟪e,d⟫_ℂ).im = -(⟪d,e⟫_ℂ).im at hs + simp only [phase,← Complex.exp_add,inner_neg_left,inner_add_right, + Complex.neg_im,Complex.add_im,hi,hs,neg_neg] + congr 1 + push_cast + ring + rw [hp] + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +open Complex + + +theorem unitary_phase_remainder (x : ℝ) : + ‖Complex.exp ((x:ℂ)*I)-1-(x:ℂ)*I‖ ≤ 3*x^2 := by + have hn : ‖(x:ℂ)*I‖ = |x| := by simp + by_cases hx : |x| ≤ 1 + · have hh := Complex.norm_exp_sub_one_sub_id_le (by rwa [hn] : ‖(x:ℂ)*I‖ ≤ 1) + rw [hn,sq_abs] at hh + nlinarith [sq_nonneg x] + · have h := norm_sub_le (Complex.exp ((x:ℂ)*I)-1) ((x:ℂ)*I) + have h' := norm_sub_le (Complex.exp ((x:ℂ)*I)) (1:ℂ) + rw [Complex.norm_exp_ofReal_mul_I,norm_one] at h' + rw [hn] at h + have hx' : 1 ≤ |x| := le_of_not_ge hx + have ha : |x|^2=x^2 := sq_abs x + nlinarith [sq_nonneg (|x|-1)] + +theorem oneParticle_add (v w : E) : oneParticle (v+w)=oneParticle v+oneParticle w := + oneParticleEmbedding.map_add v w + +theorem oneParticle_real_smul (r : ℝ) (v : E) : + oneParticle (r • v)=r • oneParticle v := by + exact oneParticleEmbedding.map_smul_of_tower r v + +theorem coherent_hasFDerivAt_zero : + HasFDerivAt (coherent (E := E)) oneParticleEmbedding.toContinuousLinearMap 0 := by + rw [hasFDerivAt_iff_isLittleO,Asymptotics.isLittleO_iff] + intro c hc + have h : ∀ᶠ d : E in 𝓝 0, ‖d‖ ≤ c := by + filter_upwards [Metric.ball_mem_nhds (0:E) hc] with d hd + have hh : ‖d‖ < c := by simpa only [Metric.mem_ball,dist_zero_right] using hd + exact hh.le + filter_upwards [h] with d hd + simp only [sub_zero] + exact (coherent_taylor_one d).trans (by nlinarith [norm_nonneg d]) + + +theorem W_coherent_reorder (v d : E) : + W v (coherent d) = Complex.exp (((-2*(⟪v,d⟫_ℂ).im:ℝ):ℂ)*I) • + W d (coherent v) := by + rw [W_coherent,W_coherent,add_comm d v,smul_smul] + congr 1 + have hi := inner_im_symm (𝕜 := ℂ) d v + change (⟪d,v⟫_ℂ).im = -(⟪v,d⟫_ℂ).im at hi + simp only [phase,← Complex.exp_add,hi,neg_neg] + congr 1 + push_cast + ring + + +theorem W_coherent_taylor (v d : E) : + ‖W v (coherent d)-coherent d-I • fieldCoherent v d‖ ≤ + ‖v‖^2*(1+2*‖d‖+12*‖d‖^2) := by + let a : ℝ := -2*(⟪v,d⟫_ℂ).im + let c : ℂ := Complex.exp ((a:ℂ)*I) + have hc : ‖c‖=1 := Complex.norm_exp_ofReal_mul_I a + have hb : |a| ≤ 2*‖v‖*‖d‖ := by + dsimp [a] + norm_num only [abs_mul,abs_neg,abs_of_pos (by norm_num : (0:ℝ)<2)] + have hh := (Complex.abs_im_le_norm ⟪v,d⟫_ℂ).trans (norm_inner_le_norm v d) + nlinarith + have hcf : ‖c-1‖ ≤ |a| := by + simpa only [c,mul_comm,Real.norm_eq_abs] using + (Real.norm_exp_I_mul_ofReal_sub_one_le (x := a)) + have hcr : ‖c-1-(a:ℂ)*I‖ ≤ 3*a^2 := unitary_phase_remainder a + have hf : I • fieldCoherent v d = W d (oneParticle v) + ((a:ℂ)*I) • coherent d := by + simp only [fieldCoherent,smul_sub,smul_smul,a] + push_cast + rw [mul_neg,I_mul_I,neg_neg,one_smul] + module + have he : W v (coherent d)-coherent d-I • fieldCoherent v d = + c • W d (coherent v-coherent 0-oneParticle v) + + (c-1) • W d (oneParticle v) + (c-1-(a:ℂ)*I) • coherent d := by + rw [W_coherent_reorder,hf] + change c • W d (coherent v)-coherent d- + (W d (oneParticle v)+((a:ℂ)*I) • coherent d) = _ + simp only [map_sub,W_coherent,phase_zero_right,one_smul,add_zero] + module + rw [he] + calc + _ ≤ ‖c • W d (coherent v-coherent 0-oneParticle v)‖ + + ‖(c-1) • W d (oneParticle v)‖ + ‖(c-1-(a:ℂ)*I) • coherent d‖ := + (norm_add_le _ _).trans (_root_.add_le_add_left (norm_add_le _ _) _) + _ = ‖coherent v-coherent 0-oneParticle v‖ + ‖c-1‖*‖v‖ + + ‖c-1-(a:ℂ)*I‖ := by + simp only [norm_smul,hc,one_mul,norm_W,norm_oneParticle,norm_coherent,mul_one] + _ ≤ ‖v‖^2+|a| *‖v‖+3*a^2 := by gcongr; exact coherent_taylor_one v + _ ≤ ‖v‖^2*(1+2*‖d‖+12*‖d‖^2) := by + have hsq : a^2 ≤ (2*‖v‖*‖d‖)^2 := by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg a) hb 2 + have hh := mul_le_mul_of_nonneg_right hb (norm_nonneg v) + nlinarith + + +def secondTailBound (x : PreSpace E) : ℝ := + (toFinsupp x).sum (fun e a => ‖a‖*(1+2*‖e‖+12*‖e‖^2)) + +theorem W_coe_taylor (v : E) (x : PreSpace E) : + ‖W v (↑x)-(↑x : Space E)-I • preField v x‖ ≤ ‖v‖^2*secondTailBound x := by + classical + rw [coe_eq_sum,preField_eq_sum] + simp only [Finsupp.sum,map_sum,map_smul,Finset.smul_sum,smul_comm I, + ← Finset.sum_sub_distrib,← smul_sub] + calc + _ ≤ ∑ e ∈ (toFinsupp x).support, + ‖(toFinsupp x) e • (W v (coherent e)-coherent e-I • fieldCoherent v e)‖ := norm_sum_le _ _ + _ ≤ ∑ e ∈ (toFinsupp x).support, + ‖(toFinsupp x) e‖*(‖v‖^2*(1+2*‖e‖+12*‖e‖^2)) := by + apply Finset.sum_le_sum + intro e he + rw [norm_smul] + exact mul_le_mul_of_nonneg_left (W_coherent_taylor v e) (norm_nonneg _) + _ = _ := by + simp only [secondTailBound,Finsupp.sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he + ring + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +open Complex + +theorem fieldCoherent_add (v w d : E) : + fieldCoherent (v+w) d=fieldCoherent v d+fieldCoherent w d := by + simp only [fieldCoherent,oneParticle_add,map_add,inner_add_left,Complex.add_im] + push_cast + module + +theorem fieldCoherent_real_smul (r : ℝ) (v d : E) : + fieldCoherent (r • v) d=r • fieldCoherent v d := by + have hi : (⟪r • v,d⟫_ℂ).im = r*(⟪v,d⟫_ℂ).im := by + rw [← Complex.coe_smul r v,inner_smul_left] + simp + simp only [fieldCoherent,oneParticle_real_smul,ContinuousLinearMap.map_smul_of_tower,hi] + simp only [← Complex.coe_smul] + push_cast + module + +theorem preField_real_smul (r : ℝ) (v : E) (x : PreSpace E) : + preField (r • v) x=r • preField v x := by + classical + simp only [preField_eq_sum,Finsupp.sum,fieldCoherent_real_smul,Finset.smul_sum] + congr 1 + ext d + exact smul_comm _ _ _ + + +theorem hasDerivAt_W_coe_zero (v : E) (x : PreSpace E) : + HasDerivAt (fun r : ℝ => W (r • v) (↑x)) (I • preField v x) 0 := by + rw [hasDerivAt_iff_isLittleO] + apply Asymptotics.IsLittleO.of_bound + intro c hc + have hC : 0 ≤ ‖v‖^2*secondTailBound x := by + classical + simp only [secondTailBound,Finsupp.sum] + positivity + have hd : 0 < c/(‖v‖^2*secondTailBound x+1) := by positivity + filter_upwards [Metric.ball_mem_nhds (0:ℝ) hd] with r hr + have hr' : |r| < c/(‖v‖^2*secondTailBound x+1) := by + simpa only [Metric.mem_ball,Real.dist_eq,sub_zero] using hr + have hh := W_coe_taylor (r • v) x + simp only [zero_smul,W_zero,ContinuousLinearMap.id_apply,sub_zero, + preField_real_smul,smul_comm I r,norm_smul,Real.norm_eq_abs,mul_pow] at hh ⊢ + have hc' : |r| *(‖v‖^2*secondTailBound x+1) < c := (lt_div_iff₀ (by positivity)).mp hr' + have hx' := mul_le_mul_of_nonneg_right hc'.le (abs_nonneg r) + nlinarith [sq_nonneg r,abs_nonneg r] + +end CoherentFock + +namespace CoherentFock +open scoped Interval +open Complex MeasureTheory +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + +theorem inner_oneParticle_eq_deriv (x : Space E) (d : E) (f : ℂ → ℂ) + (hf : Differentiable ℂ f) + (he : ∀ z, ⟪x,expVector (z • d)⟫_ℂ = f z) : + ⟪x,oneParticle d⟫_ℂ = deriv f 0 := by + rw [oneParticle,inner_smul_right] + have hi := map_circleIntegral (innerSL ℂ x) (circleIntegrable_oneParticle_integrand d) + simp only [innerSL_apply_apply,inner_smul_right,he] at hi + rw [hi] + have hc := DifferentiableOn.deriv_eq_smul_circleIntegral (c := (0:ℂ)) + (R := (1:ℝ)) (by norm_num) hf.differentiableOn + simp only [sub_zero,smul_eq_mul] at hc + rw [hc] + have hz : 2*(Real.pi:ℂ)*I ≠ 0 := by exact mul_ne_zero (mul_ne_zero (by norm_num) + (Complex.ofReal_ne_zero.mpr Real.pi_ne_zero)) I_ne_zero + exact inv_mul_cancel_left₀ hz _ + +theorem inner_expVector_W_oneParticle (e d v : E) : + ⟪expVector e,W d (oneParticle v)⟫_ℂ = + Complex.exp ((-‖d‖^2/2 : ℝ)+⟪e,d⟫_ℂ) * ⟪e-d,v⟫_ℂ := by + rw [expVector,inner_smul_left,inner_coherent_W_oneParticle, + conj_ofReal,← mul_assoc] + congr 1 + simp only [kernel,Complex.ofReal_exp,← Complex.exp_add] + congr 1 + push_cast + ring + +theorem inner_W_oneParticle_expVector (d v e : E) : + ⟪W d (oneParticle v),expVector e⟫_ℂ = + Complex.exp ((-‖d‖^2/2 : ℝ)+⟪d,e⟫_ℂ) * ⟪v,e-d⟫_ℂ := by + rw [← inner_conj_symm,inner_expVector_W_oneParticle,map_mul, + ← Complex.exp_conj,map_add,conj_ofReal,inner_conj_symm,inner_conj_symm] + + +theorem inner_W_oneParticle_oneParticle (d v u : E) : + ⟪W d (oneParticle v),oneParticle u⟫_ℂ = + (Real.exp (-‖d‖^2/2) : ℂ) * (⟪v,u⟫_ℂ-⟪v,d⟫_ℂ*⟪d,u⟫_ℂ) := by + let f : ℂ → ℂ := fun z => Complex.exp ((-‖d‖^2/2 : ℝ)+z*⟪d,u⟫_ℂ) * + (z*⟪v,u⟫_ℂ-⟪v,d⟫_ℂ) + have hf : Differentiable ℂ f := + (Complex.differentiable_exp.comp + ((differentiable_const _).add (differentiable_id.mul_const _))).mul + ((differentiable_id.mul_const _).sub_const _) + rw [inner_oneParticle_eq_deriv (W d (oneParticle v)) u f hf (fun z => by + simp only [inner_W_oneParticle_expVector,inner_sub_right,inner_smul_right,f])] + have hd := ((((hasDerivAt_id (0:ℂ)).mul_const ⟪d,u⟫_ℂ).const_add + ((-‖d‖^2/2 : ℝ):ℂ)).cexp).mul + (((hasDerivAt_id (0:ℂ)).mul_const ⟪v,u⟫_ℂ).sub_const ⟪v,d⟫_ℂ) + rw [show deriv f 0 = _ from hd.deriv] + simp only [id_eq,zero_mul,add_zero,zero_sub,← Complex.ofReal_exp] + ring + + +theorem W_oneParticle_sub_le (d v : E) : + ‖W d (oneParticle v)-oneParticle v‖ ≤ 2*‖d‖*‖v‖ := by + have hn : ‖W d (oneParticle v)-oneParticle v‖^2 = + 2*‖v‖^2-2*Real.exp (-‖d‖^2/2)*(‖v‖^2-‖⟪d,v⟫_ℂ‖^2) := by + rw [norm_sub_sq (𝕜 := ℂ),norm_W,norm_oneParticle,inner_W_oneParticle_oneParticle, + inner_self_eq_norm_sq_to_K,← inner_conj_symm v d] + rw [← Complex.normSq_eq_conj_mul_self,Complex.normSq_eq_norm_sq] + simp only [RCLike.re_to_complex] + change ‖v‖^2-2*((Real.exp (-‖d‖^2/2):ℂ)* + ((‖v‖:ℂ)^2-(‖⟪d,v⟫_ℂ‖^2:ℝ))).re+‖v‖^2 = _ + simp only [← Complex.ofReal_pow,← Complex.ofReal_sub,← Complex.ofReal_mul,Complex.ofReal_re] + ring + have he0 := Real.exp_pos (-‖d‖^2/2) + have he1 : Real.exp (-‖d‖^2/2) ≤ 1 := Real.exp_le_one_iff.mpr (by nlinarith [sq_nonneg ‖d‖]) + have he2 : 1-‖d‖^2/2 ≤ Real.exp (-‖d‖^2/2) := by + convert Real.add_one_le_exp (-‖d‖^2/2) using 1 + ring + have hi : ‖⟪d,v⟫_ℂ‖^2 ≤ ‖d‖^2*‖v‖^2 := by + simpa only [mul_pow] using pow_le_pow_left₀ (norm_nonneg _) (norm_inner_le_norm (𝕜 := ℂ) d v) 2 + have hh1 := mul_le_mul_of_nonneg_right he2 (sq_nonneg ‖v‖) + have hh2 := mul_le_mul_of_nonneg_right he1 (sq_nonneg ‖⟪d,v⟫_ℂ‖) + have hsq : ‖W d (oneParticle v)-oneParticle v‖^2 ≤ (2*‖d‖*‖v‖)^2 := by + rw [hn] + nlinarith [sq_nonneg ‖⟪d,v⟫_ℂ‖,mul_nonneg (sq_nonneg ‖d‖) (sq_nonneg ‖v‖)] + nlinarith [norm_nonneg (W d (oneParticle v)-oneParticle v),norm_nonneg d,norm_nonneg v, + mul_nonneg (norm_nonneg d) (norm_nonneg v)] + +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ExpectedReindexStates.lean b/lean/OAI/Probability/ParisiFinite/ExpectedReindexStates.lean new file mode 100644 index 0000000000000000000000000000000000000000..659501378d2626f8128b1c964f269a6b0d63c2d7 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ExpectedReindexStates.lean @@ -0,0 +1,687 @@ +import Mathlib +import OAI.Probability.ParisiFinite.IntegrableExpField + +namespace OAI + +/-! Expected Reindex States. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma expected_reindex_states {ι ι' κ : Type*} [Fintype ι] [Fintype ι'] [Fintype κ] + (e : ι' ≃ ι) (A : ι → κ → ℝ) : expected (fun s => A (e s))=expected A := by + unfold expected logPartition partition + congr 1 + ext z + congr 1 + exact e.sum_comp (fun s => Real.exp (field A z s)) + +lemma expected_kernel_distance_le {ι κ κ' : Type*} [Fintype ι] [Nonempty ι] + [Fintype κ] [Fintype κ'] (A : ι → κ → ℝ) (B : ι → κ' → ℝ) + {M : ℝ} (hM : 0≤M) (h : ∀ i j,|kernel B i j-kernel A i j|≤M) : + |expected B-expected A|≤Real.pi*M := by + have hi (i j : ι) : |ParisiInterpolation.increment B i j-ParisiInterpolation.increment A i j|≤4*M := by + rw [increment_eq_kernel,increment_eq_kernel] + have he : kernel B i i+kernel B j j-2*kernel B i j-(kernel A i i+kernel A j j-2*kernel A i j)= + (kernel B i i-kernel A i i)+(kernel B j j-kernel A j j)-2*(kernel B i j-kernel A i j) := by ring + rw [he] + have h1 := abs_sub ((kernel B i i-kernel A i i)+(kernel B j j-kernel A j j)) (2*(kernel B i j-kernel A i j)) + have h2 := abs_add_le (kernel B i i-kernel A i i) (kernel B j j-kernel A j j) + rw [abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] at h1 + linarith [h i i,h j j,h i j] + exact (expected_difference_le A B (by positivity : 0≤4*M) hi).trans_eq (by ring) + +def idealSite (n : ℕ) (β : ℝ) : Configuration n → (Fin 1 → Fin n) → ℝ := + fun σ k => β*pSpinCoeff n 1 σ k + +def idealCorrection (n : ℕ) (β : ℝ) : Configuration n → (Fin 2 → Fin n) → ℝ := + fun σ k => (β/Real.sqrt 2)*pSpinCoeff n 2 σ k + +lemma kernel_idealSite {n : ℕ} (hn : 0 β*cavityScale n*spin σ i + +def actualCorrection (n : ℕ) (β : ℝ) : Configuration n → Edge n → ℝ := fun σ e => β*cavityScale n*skCoeff n σ e + +lemma kernel_actualSite {n : ℕ} (hn : 0 Bool)) + rw [mixedCavity_split,← expected_reindex_states e] + apply expected_logPartition_eq_of_kernel + intro s t + rw [kernel_cavityDoubledCoeff] + change kernel (independentCoeff (fun s => mixedCoeff n d (β*coreScale n) x (restrictLeft (e s))) + (fun s => siteCoeff n β (e s))) s t=_ + rw [kernel_independent] + have he (s : Configuration n × Bool) : restrictLeft (e s)=s.1 := restrictLeft_snoc s.1 s.2 + have hs (s : Configuration n × Bool) : spin (e s) (Fin.last n)= -signBool s.2 := by + change spin (Fin.snoc s.1 s.2) (Fin.last n)= -signBool s.2 + cases s.2 <;> simp [spin,signBool] + simp only [he,kernel,siteCoeff,hs,actualSite,Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro k _ + ring + +def idealCavity {n : ℕ} {κ : Type*} [Fintype κ] (A : Configuration n → κ → ℝ) (β : ℝ) : ℝ := + expected (cavityDoubledCoeff A (idealSite n β))-expected (independentCoeff A (idealCorrection n β)) + + + +omit [DecidableEq K] in +theorem mixedIncrement_ideal_error {n : ℕ} (hn : 0 Subtype.ext (overlap_symm _ _),fun i => overlap_self hn _,?_⟩ + intro c + change 0≤∑ i,∑ j,c i*c j*overlap (σ i) (σ j) + rw [overlap_quadratic] + exact div_nonneg (Finset.sum_nonneg fun _ _ => sq_nonneg _) (Nat.cast_nonneg n) + + + +def cavityObservable {r : ℕ} (hr : 0 f T) h + +lemma sample_ideal_cosh {n r : ℕ} (hn : 0 fun k => signBool s.2*idealSite n β (σ s.1) k) s t= + signBool s.2*signBool t.2*kernel (idealSite n β) (σ s.1) (σ t.1) := by + simp only [kernel,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + rw [he,kernel_idealSite hn] + simp only [blockOfReplicas,mul_assoc] + +lemma sample_ideal_square {n r : ℕ} (hn : 0 cavityObservable hr β (blockOfReplicas σ))-idealCavity A β|≤ + cavitySampleError β t r := by + simp_rw [cavityObservable_replicas hn hr] + rw [averagedReplica_sub] + have h1 := averaged_gaussian_cosh_sample_error hr A (idealSite n β) + (fun σ => by rw [kernel_idealSite hn,overlap_self hn,mul_one]) ht + have h2 := averaged_gaussian_sample_error hr A (idealCorrection n β) + (fun σ => by rw [kernel_idealCorrection hn,overlap_self hn,one_pow,mul_one]) ht + have he : ∀ a b c d z : ℝ,(a-b)-(c-d)=(a-(c-z))-(b-(d-z)) := by intros; ring + unfold idealCavity + rw [he _ _ _ _ (expected A)] + have hh := (abs_sub _ _).trans (add_le_add h1 h2) + simpa only [cavitySampleError,show 2*(β^2/2)=β^2 by ring] using hh + +variable {K : Type*} [Fintype K] [DecidableEq K] + +omit [DecidableEq K] in +theorem cavityObservable_actual_error {n r q : ℕ} (hn : 0 compatibleValue hβ (φ (ψ k))) atTop (𝓝 v) := by + let u : ℕ → Set.Icc (Real.log 2-Real.pi*β^2/2) (Real.log 2+Real.pi*β^2) := + fun k => ⟨compatibleValue hβ (φ k),compatibleValue_lower hβ _,compatibleValue_upper hβ _⟩ + obtain ⟨v,ψ,hψ,hv⟩ := CompactSpace.tendsto_subseq u + exact ⟨v.val,ψ,hψ,continuous_subtype_val.tendsto v |>.comp hv⟩ + +lemma compatibleValue_limit_le {β v : ℝ} (hβ : 0<β) {φ : ℕ → ℕ} (hφ : StrictMono φ) + (hv : Tendsto (fun k => compatibleValue hβ (φ k)) atTop (𝓝 v)) : + v≤β*limitingFreeEnergy β := by + have hh := le_of_tendsto_of_tendsto' hv + (tendsto_const_nhds.add (tendsto_succ_reciprocal.comp hφ.tendsto_atTop)) + (fun k => compatibleValue_le hβ (φ k)) + simpa only [add_zero] using hh + +lemma tendsto_compatible_correction {β : ℝ} (hβ : 0<β) {φ : ℕ → ℕ} (hφ : StrictMono φ) : + Tendsto (fun k => 2*Real.pi*β^2/((compatibleSize hβ (φ k):ℝ)+1)) atTop (𝓝 0) := by + have hn : Tendsto (fun k => compatibleSize hβ (φ k)) atTop atTop := + tendsto_atTop_mono (fun k => (Nat.le_succ _).trans (compatible_spec hβ (φ k)).1) hφ.tendsto_atTop + have hd : Tendsto (fun k => ((compatibleSize hβ (φ k)+1:ℕ):ℝ)) atTop atTop := tendsto_natCast_atTop_atTop.comp (tendsto_atTop_mono (fun k => Nat.le_succ (compatibleSize hβ (φ k))) hn) + have hi := (tendsto_inv_atTop_zero.comp hd).const_mul (2*Real.pi*β^2) + simpa only [Nat.cast_add,Nat.cast_one,div_eq_mul_inv,mul_zero,Function.comp_def] using hi + +def scalarCavitySample (μ : ProbabilityMeasure OverlapArray) {r : ℕ} (hr : 0 compatibleLaw hβ (φ k)) atTop (𝓝 μ)) + (hv : Tendsto (fun k => compatibleValue hβ (φ k)) atTop (𝓝 v)) + {r : ℕ} (hr : 0.comp hμ + have hh : ∀ᶠ k in atTop, + |(∫ R,F R ∂(compatibleLaw hβ (φ k) : Measure _))-compatibleValue hβ (φ k)|≤ + cavitySampleError β t r+2*Real.pi*β^2/((compatibleSize hβ (φ k):ℝ)+1) := by + filter_upwards [hφ.tendsto_atTop.eventually (eventually_ge_atTop r)] with k hk + exact cavityObservable_actual_error (compatible_spec hβ (φ k)).2.1 hr (by omega) _ β _ ht + have h := le_of_tendsto_of_tendsto ((hF.sub hv).abs) + (tendsto_const_nhds.add (tendsto_compatible_correction hβ hφ)) hh + simpa only [add_zero,scalarCavitySample,F,ContinuousMap.comp_apply,ContinuousMap.coe_mk] using h + +lemma cavitySampleError_square (β : ℝ) (m : ℕ) : + cavitySampleError β (m+1:ℕ) ((m+1)^2)= + (4*Real.exp (2*β^2)+1+2*Real.exp (β^2))/(m+1:ℕ) := by + have hm : ((m+1:ℕ):ℝ)≠0 := Nat.cast_ne_zero.mpr (by omega) + unfold cavitySampleError + push_cast + field_simp + ring + +def quadraticCavitySamples (μ : ProbabilityMeasure OverlapArray) (β : ℝ) (m : ℕ) : ℝ := + scalarCavitySample μ (by positivity : 0<(m+1)^2) β + +lemma tendsto_cavitySampleError_square (β : ℝ) : + Tendsto (fun m : ℕ => cavitySampleError β (m+1:ℕ) ((m+1)^2)) atTop (𝓝 0) := by + simp_rw [cavitySampleError_square] + convert tendsto_succ_reciprocal.const_mul (4*Real.exp (2*β^2)+1+2*Real.exp (β^2)) using 1 <;> + simp only [mul_zero,mul_one_div] + +lemma quadraticCavitySamples_limit {β v : ℝ} (hβ : 0<β) {μ : ProbabilityMeasure OverlapArray} + {φ : ℕ → ℕ} (hφ : StrictMono φ) + (hμ : Tendsto (fun k => compatibleLaw hβ (φ k)) atTop (𝓝 μ)) + (hv : Tendsto (fun k => compatibleValue hβ (φ k)) atTop (𝓝 v)) : + Tendsto (quadraticCavitySamples μ β) atTop (𝓝 v) := by + apply tendsto_iff_dist_tendsto_zero.mpr + simp only [Real.dist_eq] + exact squeeze_zero (fun m => abs_nonneg _) (fun m => + scalarCavitySample_limit_error hβ hφ hμ hv (by positivity) (by positivity : (0:ℝ)<(m+1:ℕ))) + (tendsto_cavitySampleError_square β) + + + +theorem exists_scalar_ultrametric_cavity {β : ℝ} (hβ : 0<β) : + ∃ (μ : ProbabilityMeasure OverlapArray) (v : ℝ), + (μ : Measure OverlapArray) GramArrays=1 ∧ GGIdentities μ ∧ FiniteExchangeable μ ∧ + (μ : Measure OverlapArray) UltrametricArrays=1 ∧ + Tendsto (quadraticCavitySamples μ β) atTop (𝓝 v) ∧ v≤β*limitingFreeEnergy β := by + obtain ⟨μ,φ,hφ,hμ,hG,hgg,hex,hu,_⟩ := exists_compatible_ultrametric_limit hβ + obtain ⟨v,ψ,hψ,hv⟩ := exists_value_subsequence hβ φ + have hφψ := hφ.comp hψ + have hμ' := hμ.comp hψ.tendsto_atTop + exact ⟨μ,v,hG,hgg,hex,hu,quadraticCavitySamples_limit hβ hφψ hμ' hv, + compatibleValue_limit_le hβ hφψ hv⟩ + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def codeLabels {r : ℕ} (c : Fin r → ℕ) : Finset ℕ := Finset.univ.image c + +def labelCount {r : ℕ} (c : Fin r → ℕ) (x : ℕ) : ℕ := + (Finset.univ.filter (fun i => c i=x)).card + +lemma codeLabels_mem {r : ℕ} (c : Fin r → ℕ) (x : ℕ) : + x∈codeLabels c ↔ ∃ i,c i=x := by simp [codeLabels] + +lemma labelCount_eq_clusterCount {r : ℕ} (c : Fin r → ℕ) (i : Fin r) : + labelCount c (c i)=clusterCount c i := rfl + +lemma labelCount_pos_iff {r : ℕ} (c : Fin r → ℕ) (x : ℕ) : + 0 ?_) i hi + · exact fun h => Or.inl h.symm + · exact fun h => Or.inr ⟨j,h⟩ + · rintro (h | ⟨i,hi⟩) + · exact ⟨Fin.last r,h.symm⟩ + · exact ⟨i.castSucc,hi⟩ + +def blockFactor (a : ℝ) (n : ℕ) : ℝ := + ∏ j∈Finset.range (n-1),((j:ℝ)+1-a) + +def tableFactor (a : ℝ) (k : ℕ) : ℝ := + ∏ j∈Finset.range (k-1),(a*((j:ℝ)+1)) + +@[simp] lemma blockFactor_one (a : ℝ) : blockFactor a 1=1 := by simp [blockFactor] +@[simp] lemma tableFactor_one (a : ℝ) : tableFactor a 1=1 := by simp [tableFactor] + +lemma blockFactor_succ (a : ℝ) {n : ℕ} (hn : 0 hx (h ▸ hy) + rw [labelCount_succ,ite_eq_right hyx,add_zero] + unfold partitionNumerator + rw [codeLabels_succ,Finset.card_insert_of_notMem hx, + tableFactor_succ a (Finset.card_pos.mpr (codeLabels_nonempty hr _)),Finset.prod_insert hx] + have hn : labelCount c x=1 := by rw [labelCount_succ,hz,ite_eq_left rfl,zero_add] + rw [hn,blockFactor_one,one_mul] + have he := Finset.prod_congr (s₁:=codeLabels (restrictCode c)) (s₂:=codeLabels (restrictCode c)) + rfl (fun y hy => congrArg (blockFactor a) (hold y hy)) + rw [he] + ring + +lemma ClusterReps.card_codeLabels {r : ℕ} {c : Fin r → ℕ} {S : Finset (Fin r)} + (hS : ClusterReps c S) : S.card=(codeLabels c).card := by + have he : S.image c=codeLabels c := by + ext x + simp only [Finset.mem_image,codeLabels_mem] + constructor + · rintro ⟨i,_,hi⟩; exact ⟨i,hi⟩ + · rintro ⟨i,rfl⟩ + exact hS.2 i + rw [← he,Finset.card_image_of_injOn hS.1] + +lemma partitionNumerator_one (a : ℝ) (c : Fin 1 → ℕ) : partitionNumerator a c=1 := by + have hc : codeLabels c={c 0} := by + ext x + simp only [codeLabels_mem,Finset.mem_singleton] + exact ⟨fun ⟨i,hi⟩ => by fin_cases i; exact hi.symm,fun h => ⟨0,h.symm⟩⟩ + have hn : labelCount c (c 0)=1 := by simp [labelCount,Finset.filter_singleton] + simp [partitionNumerator,hc,hn] + + + +theorem GG_partition_EPPF {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) {r : ℕ} (hr : 0 omega + | succ r ih => + by_cases hr0 : r=0 + · subst r + rw [partition_one_real hG c hq,partitionNumerator_one] + norm_num + have hr' : 0 (1-z*x)^a) z= + (-x)^n*fallingCoeff a n*(1-z*x)^(a-n) := by + induction n generalizing z with + | zero => simp + | succ n ih => + rw [iteratedDeriv_succ] + have he : iteratedDeriv n (fun z : ℝ => (1-z*x)^a) =ᶠ[𝓝 z] + (fun w => (-x)^n*fallingCoeff a n*(1-w*x)^(a-n)) := by + filter_upwards [(show Continuous (fun w : ℝ => 1-w*x) by fun_prop).continuousAt.eventually + (isOpen_Ioi.mem_nhds hz)] with w hw + exact ih hw + rw [he.deriv_eq] + have hlin : HasDerivAt (fun w : ℝ => 1-w*x) (-x) z := by + simpa using (((hasDerivAt_id z).mul_const x).const_sub 1) + have hd := (hlin.rpow_const (p:=a-n) (Or.inl (ne_of_gt hz))).const_mul ((-x)^n*fallingCoeff a n) + rw [hd.deriv,fallingCoeff_succ,pow_succ] + have hn : a-(n+1:ℕ)=a-n-1 := by push_cast; ring + rw [hn] + ring + +lemma iteratedDeriv_affine_rpow_zero (a x : ℝ) (n : ℕ) : + iteratedDeriv n (fun z : ℝ => (1-z*x)^a) 0=(-x)^n*fallingCoeff a n := by + simpa using iteratedDeriv_affine_rpow a x n (z:=0) (by norm_num) + +lemma fallingCoeff_blockFactor (a : ℝ) {n : ℕ} (hn : 0 omega + | succ n ih => + by_cases h : n=0 + · subst n; simp [fallingCoeff_succ] + have hn' : 0 (1-z*x)^a) 0= -a*blockFactor a n*x^n := by + rw [iteratedDeriv_affine_rpow_zero,neg_eq_neg_one_mul,mul_pow] + calc + (-1:ℝ)^n*x^n*fallingCoeff a n=((-1:ℝ)^n*fallingCoeff a n)*x^n := by ring + _ = _ := by rw [fallingCoeff_blockFactor a hn] + +variable {ι : Type*} [Fintype ι] + +def finiteMarkTransform (a : ℝ) (w x : ι → ℝ) (z : ℝ) : ℝ := + ∑ i,w i*(1-z*x i)^a + +def finiteMarkMoment (w x : ι → ℝ) (n : ℕ) : ℝ := ∑ i,w i*x i^n + +lemma contDiffAt_mark (a : ℝ) (w x : ι → ℝ) (n : ℕ∞ω) : + ContDiffAt ℝ n (finiteMarkTransform a w x) 0 := by + apply ContDiffAt.sum + intro i _ + apply contDiffAt_const.mul + apply ContDiffAt.rpow_const_of_ne + · fun_prop + · simp + +lemma finiteMarkTransform_zero (a : ℝ) (w x : ι → ℝ) (hw : ∑ i,w i=1) : + finiteMarkTransform a w x 0=1 := by simpa [finiteMarkTransform] using hw + +lemma iteratedDeriv_mark (a : ℝ) (w x : ι → ℝ) {n : ℕ} (hn : 0 (1-z*x i)^a) 0 from + (by + apply ContDiffAt.rpow_const_of_ne + · fun_prop + · simp))) + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Field.lean b/lean/OAI/Probability/ParisiFinite/Field.lean new file mode 100644 index 0000000000000000000000000000000000000000..b06125d339adb33f87e2bee06ee46d5cf8fa4ddb --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Field.lean @@ -0,0 +1,698 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Sine + +namespace OAI + +/-! Field. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +namespace ClassicalGaussian +open MeasureTheory ProbabilityTheory +open scoped RealInnerProductSpace +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + + + +def field (d : E) (g : E) : ℝ := ⟪d,g⟫ + +theorem memLp_field (d : E) : MemLp (field E d) 2 (stdGaussian E) := by + exact (innerSL ℝ d).comp_memLp' IsGaussian.memLp_two_id + +def vector (d : E) : Lp ℝ 2 (stdGaussian E) := (memLp_field E d).toLp (field E d) + +theorem vector_ae (d : E) : (vector E d : E → ℝ)=ᵐ[stdGaussian E] field E d := + (memLp_field E d).coeFn_toLp + +theorem field_covariance (d e : E) : + (∫g, field E d g*field E e g ∂stdGaussian E)=⟪d,e⟫ := by + have h := covarianceBilin_apply (μ := stdGaussian E) IsGaussian.memLp_two_id d e + rw [covarianceBilin_stdGaussian] at h + simpa only [field,id_eq,integral_id_stdGaussian,sub_zero,innerSL_apply_apply ℝ] using h.symm + +theorem inner_vector (d e : E) : ⟪vector E d,vector E e⟫=⟪d,e⟫ := by + rw [L2.inner_def,←field_covariance E d e] + apply integral_congr_ae + filter_upwards [vector_ae E d,vector_ae E e] with g hd he + rw [hd,he] + simp only [RCLike.inner_apply',starRingEnd_apply,star_trivial] + +def linearMap : E →ₗ[ℝ] Lp ℝ 2 (stdGaussian E) where + toFun := vector E + map_add' d e := by + apply Lp.ext + filter_upwards [vector_ae E (d+e),vector_ae E d,vector_ae E e, + Lp.coeFn_add (vector E d) (vector E e)] with g h1 h2 h3 h4 + rw [h1,h4] + simp only [Pi.add_apply] + rw [h2,h3] + exact inner_add_left d e g + map_smul' c d := by + apply Lp.ext + filter_upwards [vector_ae E (c • d),vector_ae E d, + Lp.coeFn_smul c (vector E d)] with g h1 h2 h3 + simp only [RingHom.id_apply] + rw [h1,h3] + simp only [Pi.smul_apply,smul_eq_mul] + rw [h2] + exact real_inner_smul_left d g c + + + +def aggregate : E →ₗᵢ[ℝ] Lp ℝ 2 (stdGaussian E) := + LinearMap.isometryOfInner (linearMap E) (inner_vector E) + +@[simp] theorem aggregate_apply (d : E) : aggregate E d=vector E d := rfl + +@[simp] theorem norm_aggregate_sub (d e : E) : + ‖aggregate E d-aggregate E e‖=‖d-e‖ := by + rw [←map_sub,(aggregate E).norm_map] + +theorem aggregate_centered (d : E) : (∫g, aggregate E d g ∂stdGaussian E)=0 := by + change (∫g, vector E d g ∂stdGaussian E)=0 + rw [integral_congr_ae (vector_ae E d)] + exact integral_strongDual_stdGaussian (innerSL ℝ d) + + + +theorem reflection : MeasurePreserving (fun g : E => -g) (stdGaussian E) (stdGaussian E) := by + refine ⟨measurable_neg,?_⟩ + exact stdGaussian_map (LinearIsometryEquiv.neg ℝ : E ≃ₗᵢ[ℝ] E) + +theorem aggregate_odd (d : E) : + ∀ᵐ g ∂stdGaussian E, aggregate E d (-g)= -aggregate E d g := by + have ha := (reflection E).quasiMeasurePreserving.ae (vector_ae E d) + filter_upwards [vector_ae E d,ha] with g h1 h2 + change vector E d (-g)= -vector E d g + rw [h1,h2] + exact inner_neg_right d g + + +theorem field_law (d : E) : + (stdGaussian E).map (field E d)=gaussianReal 0 (‖d‖₊^2) := by + change (stdGaussian E).map (innerSL ℝ d)=_ + rw [IsGaussian.map_eq_gaussianReal,integral_strongDual_stdGaussian, + variance_dual_stdGaussian] + congr 1 + simp only [innerSL_apply_norm] + apply NNReal.coe_injective + simp only [Real.coe_toNNReal' , NNReal.coe_pow,coe_nnnorm,sup_eq_left.mpr (sq_nonneg ‖d‖)] + +end ClassicalGaussian + +namespace ClassicalGaussian +open MeasureTheory ProbabilityTheory +open scoped RealInnerProductSpace +variable {V : Type*} [NormedAddCommGroup V] [InnerProductSpace ℝ V] +variable {κ : Type*} [Fintype κ] (cols : κ → V) + + +abbrev ColumnSpan := Submodule.span ℝ (Set.range cols) + +instance span_finiteDimensional : FiniteDimensional ℝ (ColumnSpan cols) := + FiniteDimensional.span_of_finite ℝ (Set.finite_range cols) + +instance span_measurableSpace : MeasurableSpace (ColumnSpan cols) := borel (ColumnSpan cols) +instance span_borelSpace : BorelSpace (ColumnSpan cols) := ⟨rfl⟩ + + +def column (k : κ) : ColumnSpan cols := ⟨cols k, Submodule.subset_span (Set.mem_range_self k)⟩ + +omit [Fintype κ] in +@[simp] theorem inner_column (j k : κ) : ⟪column cols j,column cols k⟫=⟪cols j,cols k⟫ := rfl +omit [Fintype κ] in +@[simp] theorem norm_column_sub (j k : κ) : ‖column cols j-column cols k‖=‖cols j-cols k‖ := rfl + + + +def jointColumn (k : κ) : Lp ℝ 2 (stdGaussian (ColumnSpan cols)) := + aggregate (ColumnSpan cols) (column cols k) + +theorem jointColumn_covariance (j k : κ) : + (∫g, jointColumn cols j g*jointColumn cols k g ∂stdGaussian (ColumnSpan cols))= + ⟪cols j,cols k⟫ := by + rw [←inner_column cols j k,←field_covariance (ColumnSpan cols) (column cols j) (column cols k)] + apply integral_congr_ae + filter_upwards [vector_ae (ColumnSpan cols) (column cols j), + vector_ae (ColumnSpan cols) (column cols k)] with g h1 h2 + change vector (ColumnSpan cols) (column cols j) g * + vector (ColumnSpan cols) (column cols k) g = _ + rw [h1,h2] + +theorem jointColumn_centered (k : κ) : + (∫g, jointColumn cols k g ∂stdGaussian (ColumnSpan cols))=0 := + aggregate_centered (ColumnSpan cols) (column cols k) + +theorem jointColumn_norm_sub (j k : κ) : + ‖jointColumn cols j-jointColumn cols k‖=‖cols j-cols k‖ := + norm_aggregate_sub (ColumnSpan cols) (column cols j) (column cols k) + +theorem jointColumn_odd (k : κ) : + ∀ᵐ g ∂stdGaussian (ColumnSpan cols), jointColumn cols k (-g)= -jointColumn cols k g := + aggregate_odd (ColumnSpan cols) (column cols k) + +end ClassicalGaussian + +namespace ClassicalGaussian +open MeasureTheory ProbabilityTheory +open scoped RealInnerProductSpace +variable {E F : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℝ F] [FiniteDimensional ℝ F] + [MeasurableSpace F] [BorelSpace F] + + + +theorem projection_gaussian (i : E →ₗᵢ[ℝ] F) : + (stdGaussian F).map (ContinuousLinearMap.adjoint i.toContinuousLinearMap)=stdGaussian E := by + apply Measure.ext_of_charFun + funext t + rw [charFun_apply,integral_map (by fun_prop) (by fun_prop)] + simp only [ContinuousLinearMap.adjoint_inner_left] + change charFun (stdGaussian F) (i t)=charFun (stdGaussian E) t + simp only [charFun_stdGaussian,i.norm_map] + +theorem projection_preserving (i : E →ₗᵢ[ℝ] F) : + MeasurePreserving (ContinuousLinearMap.adjoint i.toContinuousLinearMap) + (stdGaussian F) (stdGaussian E) := + ⟨by fun_prop,projection_gaussian i⟩ + + + +theorem aggregate_pullback (i : E →ₗᵢ[ℝ] F) (d : E) : + Lp.compMeasurePreserving (ContinuousLinearMap.adjoint i.toContinuousLinearMap) + (projection_preserving i) (aggregate E d)=aggregate F (i d) := by + apply Lp.ext + have h1 := (projection_preserving i).quasiMeasurePreserving.ae (vector_ae E d) + filter_upwards [Lp.coeFn_compMeasurePreserving (aggregate E d) (projection_preserving i), + h1,vector_ae F (i d)] with g h2 h3 h4 + change _=vector F (i d) g + rw [h2,h4] + change vector E d (ContinuousLinearMap.adjoint i.toContinuousLinearMap g)=_ + rw [h3] + exact ContinuousLinearMap.adjoint_inner_right i.toContinuousLinearMap d g + +end ClassicalGaussian + +namespace ClassicalGaussian +open MeasureTheory ProbabilityTheory TrigLp +open scoped Topology +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +variable {κ : Type*} [Fintype κ] + + + +theorem exists_robust_gaussian_operation (cols : κ → E) (φ : (κ → ℝ) → ℝ) + (hφ : MemLp φ 2 (inputLaw (stdGaussian E) (fun k => aggregate E (cols k)))) + (ho : ∀x, φ (-x)= -φ x) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, ∃δ : ℝ, 0<δ ∧ + ∀d : κ → E, (∀k, ‖d k-cols k‖<δ) → + ‖polynomial (stdGaussian E) s b (fun k => aggregate E (d k))- + (hφ.comp_measurePreserving (inputMap_preserving (stdGaussian E) + (fun k => aggregate E (cols k)))).toLp + (φ ∘ inputMap (stdGaussian E) (fun k => aggregate E (cols k)))‖<ε := by + obtain ⟨s,b,δ,hδ,hd⟩ := exists_robust_odd_operation (stdGaussian E) (fun g => -g) + (reflection E) (fun k => aggregate E (cols k)) (fun k => aggregate_odd E (cols k)) + φ hφ ho hε + refine ⟨s,b,δ,hδ,?_⟩ + intro d hd' + apply hd + intro k + simpa only [norm_aggregate_sub] using hd' k + + + +theorem exists_robust_gaussian_angle (cols : κ → E) (φ : (κ → ℝ) → ℝ) + (hφ : MemLp φ 2 (inputLaw (stdGaussian E) (fun k => aggregate E (cols k)))) + (ho : ∀x, φ (-x)= -φ x) (hb : ∀x, |φ x|≤1) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, ∃δ : ℝ, 0<δ ∧ + ∀d : κ → E, (∀k, ‖d k-cols k‖<δ) → + ‖readout (stdGaussian E) s b (fun k => aggregate E (d k))- + (hφ.comp_measurePreserving (inputMap_preserving (stdGaussian E) + (fun k => aggregate E (cols k)))).toLp + (φ ∘ inputMap (stdGaussian E) (fun k => aggregate E (cols k)))‖<ε := by + obtain ⟨s,b,δ,hδ,hd⟩ := exists_robust_odd_readout (stdGaussian E) (fun g => -g) + (reflection E) (fun k => aggregate E (cols k)) (fun k => aggregate_odd E (cols k)) + φ hφ ho hb hε + refine ⟨s,b,δ,hδ,?_⟩ + intro d hd' + apply hd + intro k + simpa only [norm_aggregate_sub] using hd' k + +end ClassicalGaussian + +namespace ClassicalGaussian +open MeasureTheory ProbabilityTheory +open scoped RealInnerProductSpace +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + + + +theorem covariance_field (d e : E) : + cov[field E d,field E e;stdGaussian E]=⟪d,e⟫ := by + rw [covariance_eq_sub (memLp_field E d) (memLp_field E e)] + have hd : (∫g,field E d g ∂stdGaussian E)=0 := + integral_strongDual_stdGaussian (innerSL ℝ d) + have he : (∫g,field E e g ∂stdGaussian E)=0 := + integral_strongDual_stdGaussian (innerSL ℝ e) + rw [hd,he,mul_zero,sub_zero] + exact field_covariance E d e + + + +theorem joint_gaussian {κ : Type*} [Fintype κ] (cols : κ → E) : + HasGaussianLaw (fun g k => field E (cols k) g) (stdGaussian E) := by + exact HasGaussianLaw.map_of_measurable + (ContinuousLinearMap.pi (fun k => innerSL ℝ (cols k))) + IsGaussian.hasGaussianLaw_id (by fun_prop) + + +theorem fields_independent {κ : Type*} [Fintype κ] (cols : κ → E) + (h : ∀j k, j≠k → ⟪cols j,cols k⟫=0) : + iIndepFun (fun k => field E (cols k)) (stdGaussian E) := by + apply (joint_gaussian E cols).iIndepFun_of_covariance_eq_zero + intro j k hjk + rw [covariance_field] + exact h j k hjk + + + +theorem orthogonal_families_independent {κ ι : Type*} [Fintype κ] [Fintype ι] + (d : κ → E) (e : ι → E) (h : ∀j k, ⟪d j,e k⟫=0) : + IndepFun (fun g j => field E (d j) g) (fun g k => field E (e k) g) + (stdGaussian E) := by + have hg : HasGaussianLaw (fun g => ((fun j => field E (d j) g), + (fun k => field E (e k) g))) (stdGaussian E) := by + exact HasGaussianLaw.map_of_measurable + ((ContinuousLinearMap.pi (fun j => innerSL ℝ (d j))).prod + (ContinuousLinearMap.pi (fun k => innerSL ℝ (e k)))) + IsGaussian.hasGaussianLaw_id (by fun_prop) + apply hg.indepFun_of_covariance_eval + intro j k + rw [covariance_field] + exact h j k + +end ClassicalGaussian + +namespace TrigLp +open MeasureTheory +variable {Ω Ω' : Type*} [MeasurableSpace Ω] [MeasurableSpace Ω'] +variable (μ : Measure Ω) (ν : Measure Ω') (X : Ω → Ω') +variable (hX : MeasurePreserving X μ ν) +variable {κ : Type*} [Fintype κ] + +omit [Fintype κ] in + + +theorem sine_pullback (f : Lp ℝ 2 ν) : + Lp.compMeasurePreservingₗ ℝ X hX (sine ν f)= + sine μ (Lp.compMeasurePreservingₗ ℝ X hX f) := by + apply Lp.ext + have hf := hX.quasiMeasurePreserving.ae (sine_ae ν f) + filter_upwards [Lp.coeFn_compMeasurePreserving (sine ν f) hX,hf, + sine_ae μ (Lp.compMeasurePreservingₗ ℝ X hX f), + Lp.coeFn_compMeasurePreserving f hX] with ω h1 h2 h3 h4 + change Lp.compMeasurePreserving X hX (sine ν f) ω=_ + rw [h1,Function.comp_apply,h2,h3] + congr 1 + change f (X ω)=Lp.compMeasurePreserving X hX f ω + exact h4.symm + +theorem polynomial_pullback (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) + (cols : κ → Lp ℝ 2 ν) : + Lp.compMeasurePreservingₗ ℝ X hX (polynomial ν s b cols)= + polynomial μ s b (fun k => Lp.compMeasurePreservingₗ ℝ X hX (cols k)) := by + simp only [polynomial,map_sum,map_smul,sine_pullback,linear] + +theorem readout_pullback (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) + (cols : κ → Lp ℝ 2 ν) : + Lp.compMeasurePreservingₗ ℝ X hX (readout ν s b cols)= + readout μ s b (fun k => Lp.compMeasurePreservingₗ ℝ X hX (cols k)) := by + simp only [readout,sine_pullback,map_smul,polynomial_pullback] + + + +def coefficientBound (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : ℝ := + ∑a∈s, |b a| * (∑k, |a k|) + +theorem coefficientBound_nonneg (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + 0≤coefficientBound s b := by + exact Finset.sum_nonneg (fun a ha => mul_nonneg (abs_nonneg _) (Finset.sum_nonneg fun _ _ => abs_nonneg _)) + +theorem polynomial_norm_sub_uniform (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) + (f g : κ → Lp ℝ 2 μ) {δ : ℝ} (h : ∀k, ‖f k-g k‖≤δ) : + ‖polynomial μ s b f-polynomial μ s b g‖≤coefficientBound s b*δ := by + calc + _ ≤ ∑a∈s, |b a| *(∑k, |a k| *‖f k-g k‖) := polynomial_norm_sub_le μ s b f g + _ ≤ ∑a∈s, |b a| *(∑k, |a k| *δ) := by + apply Finset.sum_le_sum + intro a ha + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + exact Finset.sum_le_sum (fun k hk => mul_le_mul_of_nonneg_left (h k) (abs_nonneg _)) + _ = coefficientBound s b*δ := by + simp only [coefficientBound,Finset.sum_mul,Finset.mul_sum,mul_assoc] + +end TrigLp + +namespace ClassicalGaussian +open MeasureTheory ProbabilityTheory TrigLp +universe u v +variable (E : Type u) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +variable {κ : Type*} [Fintype κ] + + + +def localValue (cols : κ → E) (φ : (κ → ℝ) → ℝ) + (hφ : MemLp φ 2 (inputLaw (stdGaussian E) (fun k => aggregate E (cols k)))) : + Lp ℝ 2 (stdGaussian E) := + (hφ.comp_measurePreserving (inputMap_preserving (stdGaussian E) + (fun k => aggregate E (cols k)))).toLp + (φ ∘ inputMap (stdGaussian E) (fun k => aggregate E (cols k))) + + + +theorem exists_ambient_robust_operation (cols : κ → E) (φ : (κ → ℝ) → ℝ) + (hφ : MemLp φ 2 (inputLaw (stdGaussian E) (fun k => aggregate E (cols k)))) + (ho : ∀x, φ (-x)= -φ x) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, ∃δ : ℝ, 0<δ ∧ + ∀ (F : Type v) [NormedAddCommGroup F] [InnerProductSpace ℝ F] + [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] + (i : E →ₗᵢ[ℝ] F) (d : κ → F), (∀k, ‖d k-i (cols k)‖<δ) → + ‖polynomial (stdGaussian F) s b (fun k => aggregate F (d k))- + Lp.compMeasurePreservingₗ ℝ (ContinuousLinearMap.adjoint i.toContinuousLinearMap) + (projection_preserving i) (localValue E cols φ hφ)‖<ε := by + obtain ⟨s,b,δ₀,hδ₀,ha⟩ := exists_robust_gaussian_operation E cols φ hφ ho (half_pos hε) + have hb := ha cols (fun k => by simpa only [sub_self,norm_zero] using hδ₀) + change ‖polynomial (stdGaussian E) s b (fun k => aggregate E (cols k))- + localValue E cols φ hφ‖<ε/2 at hb + let K := coefficientBound s b + have hK : 0≤K := coefficientBound_nonneg s b + have hp : 0<2*(K+1) := by positivity + let δ := ε/(2*(K+1)) + have hδ : 0<δ := div_pos hε hp + have heq : δ*(2*(K+1))=ε := div_mul_cancel₀ ε (ne_of_gt hp) + have hKδ : K*δ<ε/2 := by nlinarith + refine ⟨s,b,δ,hδ,?_⟩ + intro F inst1 inst2 inst3 inst4 inst5 i d hd + let P : Lp ℝ 2 (stdGaussian E) →ₗ[ℝ] Lp ℝ 2 (stdGaussian F) := Lp.compMeasurePreservingₗ ℝ + (ContinuousLinearMap.adjoint i.toContinuousLinearMap) (projection_preserving i) + have hid : polynomial (stdGaussian F) s b (fun k => aggregate F (i (cols k)))= + P (polynomial (stdGaussian E) s b (fun k => aggregate E (cols k))) := by + rw [polynomial_pullback] + congr 1 + funext k + exact (aggregate_pullback i (cols k)).symm + have herr : ‖polynomial (stdGaussian F) s b (fun k => aggregate F (i (cols k)))- + P (localValue E cols φ hφ)‖<ε/2 := by + rw [hid,←map_sub] + change ‖Lp.compMeasurePreserving (ContinuousLinearMap.adjoint i.toContinuousLinearMap) + (projection_preserving i) + (polynomial (stdGaussian E) s b (fun k => aggregate E (cols k))-localValue E cols φ hφ)‖<ε/2 + rwa [Lp.norm_compMeasurePreserving] + have hpert : ‖polynomial (stdGaussian F) s b (fun k => aggregate F (d k))- + polynomial (stdGaussian F) s b (fun k => aggregate F (i (cols k)))‖<ε/2 := by + apply lt_of_le_of_lt (polynomial_norm_sub_uniform (stdGaussian F) s b _ _ ?_) hKδ + intro k + rw [norm_aggregate_sub] + exact (hd k).le + calc + _ ≤ ‖polynomial (stdGaussian F) s b (fun k => aggregate F (d k))- + polynomial (stdGaussian F) s b (fun k => aggregate F (i (cols k)))‖+ + ‖polynomial (stdGaussian F) s b (fun k => aggregate F (i (cols k)))- + P (localValue E cols φ hφ)‖ := norm_sub_le_norm_sub_add_norm_sub _ _ _ + _ < ε/2+ε/2 := add_lt_add hpert herr + _ = ε := add_halves ε + +end ClassicalGaussian + +namespace ClassicalGaussian +open MeasureTheory ProbabilityTheory TrigLp +universe u v +variable (E : Type u) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +variable {κ : Type*} [Fintype κ] + + + +theorem exists_ambient_robust_angle (cols : κ → E) (φ : (κ → ℝ) → ℝ) + (hφ : MemLp φ 2 (inputLaw (stdGaussian E) (fun k => aggregate E (cols k)))) + (ho : ∀x, φ (-x)= -φ x) (hbound : ∀x, |φ x|≤1) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, ∃δ : ℝ, 0<δ ∧ + ∀ (F : Type v) [NormedAddCommGroup F] [InnerProductSpace ℝ F] + [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] + (i : E →ₗᵢ[ℝ] F) (d : κ → F), (∀k, ‖d k-i (cols k)‖<δ) → + ‖readout (stdGaussian F) s b (fun k => aggregate F (d k))- + Lp.compMeasurePreservingₗ ℝ (ContinuousLinearMap.adjoint i.toContinuousLinearMap) + (projection_preserving i) (localValue E cols φ hφ)‖<ε := by + obtain ⟨s,b,δ₀,hδ₀,ha⟩ := exists_robust_gaussian_angle E cols φ hφ ho hbound (half_pos hε) + have hb := ha cols (fun k => by simpa only [sub_self,norm_zero] using hδ₀) + change ‖readout (stdGaussian E) s b (fun k => aggregate E (cols k))- + localValue E cols φ hφ‖<ε/2 at hb + let K := coefficientBound s b + have hK : 0≤K := coefficientBound_nonneg s b + have hp : 0<4*(K+1) := by positivity + let δ := ε/(4*(K+1)) + have hδ : 0<δ := div_pos hε hp + have heq : δ*(4*(K+1))=ε := div_mul_cancel₀ ε (ne_of_gt hp) + have hKδ : 2*(K*δ)<ε/2 := by nlinarith + refine ⟨s,b,δ,hδ,?_⟩ + intro F inst1 inst2 inst3 inst4 inst5 i d hd + let P : Lp ℝ 2 (stdGaussian E) →ₗ[ℝ] Lp ℝ 2 (stdGaussian F) := Lp.compMeasurePreservingₗ ℝ + (ContinuousLinearMap.adjoint i.toContinuousLinearMap) (projection_preserving i) + have hid : readout (stdGaussian F) s b (fun k => aggregate F (i (cols k)))= + P (readout (stdGaussian E) s b (fun k => aggregate E (cols k))) := by + rw [readout_pullback] + congr 1 + funext k + exact (aggregate_pullback i (cols k)).symm + have herr : ‖readout (stdGaussian F) s b (fun k => aggregate F (i (cols k)))- + P (localValue E cols φ hφ)‖<ε/2 := by + rw [hid,←map_sub] + change ‖Lp.compMeasurePreserving (ContinuousLinearMap.adjoint i.toContinuousLinearMap) + (projection_preserving i) + (readout (stdGaussian E) s b (fun k => aggregate E (cols k))-localValue E cols φ hφ)‖<ε/2 + rwa [Lp.norm_compMeasurePreserving] + have hpert : ‖readout (stdGaussian F) s b (fun k => aggregate F (d k))- + readout (stdGaussian F) s b (fun k => aggregate F (i (cols k)))‖<ε/2 := by + apply lt_of_le_of_lt (readout_norm_sub_le (stdGaussian F) s b _ _) + apply lt_of_le_of_lt (mul_le_mul_of_nonneg_left + (polynomial_norm_sub_uniform (stdGaussian F) s b _ _ ?_) (by norm_num : (0:ℝ)≤2)) hKδ + intro k + rw [norm_aggregate_sub] + exact (hd k).le + calc + _ ≤ ‖readout (stdGaussian F) s b (fun k => aggregate F (d k))- + readout (stdGaussian F) s b (fun k => aggregate F (i (cols k)))‖+ + ‖readout (stdGaussian F) s b (fun k => aggregate F (i (cols k)))- + P (localValue E cols φ hφ)‖ := norm_sub_le_norm_sub_add_norm_sub _ _ _ + _ < ε/2+ε/2 := add_lt_add hpert herr + _ = ε := add_halves ε + +end ClassicalGaussian + +namespace FiniteOccupations +open scoped InnerProductSpace BigOperators +variable {A B : Type*} [Fintype A] [Fintype B] [DecidableEq B] +variable (f : A → B) + +def weight (b : B) : ℂ := (Real.sqrt (Fintype.card {a : A // f a=b} : ℝ) : ℂ)⁻¹ + +omit [Fintype B] in +theorem card_pos (hf : Function.Surjective f) (b : B) : 0 weight f (f a)*u (f a)) + map_add' u v := by ext a; simp [mul_add] + map_smul' c u := by ext a; simp [mul_left_comm] + +omit [Fintype B] in +@[simp] theorem liftLinear_apply (u : EuclideanSpace ℂ B) (a : A) : + liftLinear f u a=weight f (f a)*u (f a) := rfl + + +theorem inner_lift (hf : Function.Surjective f) (u v : EuclideanSpace ℂ B) : + ⟪liftLinear f u,liftLinear f v⟫_ℂ=⟪u,v⟫_ℂ := by + classical + simp only [PiLp.inner_apply,RCLike.inner_apply,liftLinear_apply,map_mul,star_weight] + rw [←Fintype.sum_fiberwise f] + apply Finset.sum_congr rfl + intro b hb + have he (a : {a : A // f a=b}) : + weight f (f a)*v (f a)*(weight f (f a)*starRingEnd ℂ (u (f a)))= + (weight f b)^2*(v b*starRingEnd ℂ (u b)) := by rw [a.property]; ring + simp_rw [he] + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + rw [←mul_assoc,card_mul_weight_sq f hf,one_mul] + + + +def lift (hf : Function.Surjective f) : EuclideanSpace ℂ B →ₗᵢ[ℂ] EuclideanSpace ℂ A := + LinearMap.isometryOfInner (liftLinear f) (inner_lift f hf) + +@[simp] theorem lift_apply (hf : Function.Surjective f) (u : EuclideanSpace ℂ B) (a : A) : + lift f hf u a=weight f (f a)*u (f a) := rfl + + +theorem mem_range_iff (hf : Function.Surjective f) (u : EuclideanSpace ℂ A) : + u∈Set.range (lift f hf) ↔ ∀a a', f a=f a' → u a=u a' := by + constructor + · rintro ⟨v,rfl⟩ a a' h + simp only [lift_apply,h] + · intro h + let rep : B → A := fun b => (hf b).choose + have hr (b : B) : f (rep b)=b := (hf b).choose_spec + refine ⟨WithLp.toLp 2 (fun b => u (rep b)/weight f b),?_⟩ + ext a + change weight f (f a)*(u (rep (f a))/weight f (f a))=u a + rw [mul_div_cancel₀ _ (weight_ne_zero f hf _)] + exact h _ _ (hr (f a)) + +end FiniteOccupations + +namespace FiniteTensorOccupations +open scoped InnerProductSpace +variable {I α : Type*} [Fintype I] [Fintype α] [DecidableEq α] +local instance : DecidableEq I := Classical.decEq _ + + +def counts (w : I → α) (a : α) : ℕ := Fintype.card {i : I // w i=a} + +omit [Fintype α] in +theorem counts_eq_iff (w z : I → α) : + counts w=counts z ↔ ∃σ : I ≃ I, ∀i, z (σ i)=w i := by + classical + constructor + · intro h + let e (a : α) : {i : I // w i=a} ≃ {i : I // z i=a} := + Fintype.equivOfCardEq (congrFun h a) + exact ⟨Equiv.ofFiberEquiv e,Equiv.ofFiberEquiv_map e⟩ + · rintro ⟨σ,hσ⟩ + funext a + apply Fintype.card_congr + exact { + toFun := fun i => ⟨σ i,by rw [hσ,i.property]⟩ + invFun := fun j => ⟨σ.symm j,by rw [←hσ,σ.apply_symm_apply,j.property]⟩ + left_inv := by intro i; ext; simp + right_inv := by intro j; ext; simp } + +def occupancySetoid : Setoid (I → α) where + r w z := counts w=counts z + iseqv := ⟨fun _ => rfl,fun h => h.symm,fun h h' => h.trans h'⟩ + + +abbrev Occupation (I α : Type*) [Fintype I] [DecidableEq α] := + Quotient (occupancySetoid (I := I) (α := α)) + +instance : Fintype (Occupation I α) := Fintype.ofFinite _ + +noncomputable instance : DecidableEq (Occupation I α) := Classical.decEq _ + +def register (w : I → α) : Occupation I α := Quotient.mk _ w + +omit [Fintype α] in +@[simp] theorem register_eq_iff (w z : I → α) : + register w=register z ↔ counts w=counts z := Quotient.eq + +omit [Fintype α] in +theorem register_surjective : Function.Surjective (register (I := I) (α := α)) := by + intro q + exact Quotient.inductionOn q (fun w => ⟨w,rfl⟩) + + + +def embedding : EuclideanSpace ℂ (Occupation I α) →ₗᵢ[ℂ] EuclideanSpace ℂ (I → α) := + FiniteOccupations.lift register register_surjective + + + +theorem mem_range_iff_symmetric (u : EuclideanSpace ℂ (I → α)) : + u∈Set.range (embedding (I := I) (α := α)) ↔ + ∀w : I → α, ∀σ : I ≃ I, u (w ∘ σ)=u w := by + rw [embedding,FiniteOccupations.mem_range_iff] + constructor + · intro h w σ + apply h + apply (register_eq_iff _ _).mpr + exact (counts_eq_iff _ _).mpr ⟨σ,fun _ => rfl⟩ + · intro h w z hwz + obtain ⟨σ,hσ⟩ := (counts_eq_iff w z).mp ((register_eq_iff _ _).mp hwz) + have he : z ∘ σ=w := funext hσ + simpa only [he] using h z σ + + +def symmetricSector : Submodule ℂ (EuclideanSpace ℂ (I → α)) where + carrier := {u | ∀w : I → α, ∀σ : I ≃ I, u (w ∘ σ)=u w} + zero_mem' := by intro w σ; rfl + add_mem' := by intro u v hu hv w σ; simp [hu w σ,hv w σ] + smul_mem' := by intro c u hu w σ; simp [hu w σ] + + +def symmetricEmbedding : + EuclideanSpace ℂ (Occupation I α) →ₗᵢ[ℂ] symmetricSector (I := I) (α := α) where + toLinearMap := (embedding (I := I) (α := α)).toLinearMap.codRestrict symmetricSector + (fun u => (mem_range_iff_symmetric _).mp ⟨u,rfl⟩) + norm_map' u := (embedding (I := I) (α := α)).norm_map u + +theorem symmetricEmbedding_surjective : + Function.Surjective (symmetricEmbedding (I := I) (α := α)) := by + intro y + obtain ⟨u,hu⟩ := (mem_range_iff_symmetric (y : EuclideanSpace ℂ (I → α))).mpr y.property + refine ⟨u,?_⟩ + apply Subtype.ext + exact hu + + + +def occupationMap : symmetricSector (I := I) (α := α) ≃ₗᵢ[ℂ] + EuclideanSpace ℂ (Occupation I α) := + (LinearIsometryEquiv.ofSurjective symmetricEmbedding symmetricEmbedding_surjective).symm + +@[simp] theorem occupationMap_symm_apply (u : EuclideanSpace ℂ (Occupation I α)) + (w : I → α) : + (occupationMap.symm u : EuclideanSpace ℂ (I → α)) w = + FiniteOccupations.weight register (register w)*u (register w) := rfl + +end FiniteTensorOccupations + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/FiniteMaxHamiltonian.lean b/lean/OAI/Probability/ParisiFinite/FiniteMaxHamiltonian.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2dafeac7462570c30db823df570b19c932d20b3 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/FiniteMaxHamiltonian.lean @@ -0,0 +1,580 @@ +import Mathlib +import OAI.Probability.ParisiFinite.CostState + +namespace OAI + +/-! Finite Max Hamiltonian. -/ + +noncomputable section + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ComplexConjugate +open MeasureTheory ProbabilityTheory +namespace SKQAOA +open SKGaussian + +theorem finiteMax_hamiltonian (n : ℕ) (J : Disorder n) : + finiteMax (hamiltonian n J) = groundMaximum n J := by + rw [groundMaximum_eq_finiteMax,field_skCoeff] + +theorem log_card_configuration (n : ℕ) : + Real.log (Fintype.card (Configuration n) : ℝ) = (n : ℝ) * Real.log 2 := by + simp [Configuration,Real.log_pow] + +theorem finite_pressure_bounds {β : ℝ} (hβ : 0 ≤ β) (n : ℕ) (J : Disorder n) : + β * groundMaximum n J ≤ logPartition (fun σ => β * hamiltonian n J σ) ∧ + logPartition (fun σ => β * hamiltonian n J σ) ≤ + β * groundMaximum n J + (n : ℝ) * Real.log 2 := by + have hm := finiteMax_const_mul (hamiltonian n J) hβ + rw [finiteMax_hamiltonian] at hm + constructor + · rw [← hm] + exact finiteMax_le_logPartition _ + · have h := logPartition_le (fun σ => β * hamiltonian n J σ) + rwa [hm,log_card_configuration] at h + +theorem pressure_bounds {β : ℝ} (hβ : 0 ≤ β) (n : ℕ) : + β * expectedMaximum n ≤ pressure β n ∧ + pressure β n ≤ β * expectedMaximum n + (n : ℝ) * Real.log 2 := by + have : IsProbabilityMeasure (disorderLaw n) := by unfold disorderLaw; infer_instance + have h1 := integral_mono ((ground_integrable n).const_mul β) (pressure_integrable β n) + (fun J => (finite_pressure_bounds hβ n J).1) + have h2 := integral_mono (pressure_integrable β n) + (((ground_integrable n).const_mul β).add (integrable_const ((n : ℝ)*Real.log 2))) + (fun J => (finite_pressure_bounds hβ n J).2) + simp only [integral_const_mul] at h1 + simp only [Pi.add_apply] at h2 + rw [integral_add ((ground_integrable n).const_mul β) (integrable_const _), + integral_const_mul,integral_const] at h2 + simpa [pressure,expectedMaximum] using And.intro h1 h2 + +theorem pressure_linear_bound {β : ℝ} (hβ : 0 ≤ β) (n : ℕ) : + pressure β n ≤ (n : ℝ) * (β * gaussianAbsoluteMean + Real.log 2) := by + have h := mul_le_mul_of_nonneg_left (expectedMaximum_le n) hβ + linarith [(pressure_bounds hβ n).2] + + + +theorem tendsto_freeEnergy {β : ℝ} (hβ : 0 < β) : + Tendsto (freeEnergy β) atTop (𝓝 (limitingFreeEnergy β)) := by + have hs : Subadditive (fun n => -pressure β n) := by + intro n m + linarith [pressure_superadditive β n m] + have hb : BddBelow (Set.range fun n => -pressure β n / (n : ℝ)) := by + refine ⟨-(β*gaussianAbsoluteMean+Real.log 2),?_⟩ + rintro _ ⟨n,rfl⟩ + rcases Nat.eq_zero_or_pos n with rfl | hn + · simp only [pressure_zero,neg_zero,Nat.cast_zero,div_zero] + have hg : 0 ≤ gaussianAbsoluteMean := integral_nonneg fun x => abs_nonneg x + have hl : 0 ≤ Real.log 2 := Real.log_nonneg (by norm_num) + exact neg_nonpos.mpr (add_nonneg (mul_nonneg hβ.le hg) hl) + · have hn' : (0 : ℝ) < n := Nat.cast_pos.mpr hn + apply (le_div_iff₀ hn').mpr + linarith [pressure_linear_bound hβ.le n] + have ht := ((hs.tendsto_lim hb).neg).div_const β + have he : (fun n => -(-pressure β n / (n : ℝ)) / β) = freeEnergy β := by + funext n + simp [freeEnergy,neg_div] + rw [he] at ht + have hp : limitingFreeEnergy β = -hs.lim / β := ht.limUnder_eq + rw [hp] + exact ht + +theorem freeEnergy_bounds {β : ℝ} (hβ : 0 < β) {n : ℕ} (hn : 0 < n) : + expectedGround n ≤ freeEnergy β n ∧ + freeEnergy β n ≤ expectedGround n + Real.log 2 / β := by + have hn' : (0 : ℝ) < n := Nat.cast_pos.mpr hn + obtain ⟨hlo,hhi⟩ := pressure_bounds hβ.le n + change expectedMaximum n / (n : ℝ) ≤ pressure β n / (n : ℝ) / β ∧ + pressure β n / (n : ℝ) / β ≤ expectedMaximum n / (n : ℝ) + Real.log 2 / β + constructor + · apply (le_div_iff₀ hβ).mpr + apply (le_div_iff₀ hn').mpr + convert! hlo using 1 + field_simp [hn'.ne'] + · apply (div_le_iff₀ hβ).mpr + apply (div_le_iff₀ hn').mpr + convert! hhi using 1 + field_simp [hn'.ne', hβ.ne'] + + + +theorem limitingFreeEnergy_bounds {β : ℝ} (hβ : 0 < β) : + Pstar ≤ limitingFreeEnergy β ∧ + limitingFreeEnergy β ≤ Pstar + Real.log 2 / β := by + constructor + · exact le_of_tendsto_of_tendsto tendsto_expectedGround (tendsto_freeEnergy hβ) + (eventually_gt_atTop 0 |>.mono fun n hn => (freeEnergy_bounds hβ hn).1) + · exact le_of_tendsto_of_tendsto (tendsto_freeEnergy hβ) + (tendsto_expectedGround.add_const (Real.log 2 / β)) + (eventually_gt_atTop 0 |>.mono fun n hn => (freeEnergy_bounds hβ hn).2) + +end SKQAOA + + + + + +open scoped Topology +open Filter + +namespace PulseControl + +section Banach +variable {A : Type*} [NormedRing A] [NormedAlgebra ℝ A] [NormedAlgebra ℚ A] [CompleteSpace A] [NormOneClass A] + +omit [NormedAlgebra ℚ A] [NormOneClass A] in +theorem exp_hasFDerivAt_zero : + HasFDerivAt (NormedSpace.exp : A → A) (ContinuousLinearMap.id ℝ A) 0 := by + convert! (NormedSpace.exp_hasFPowerSeriesAt_zero (𝕂 := ℝ) (𝔸 := A)).hasFDerivAt using 1 + ext a + simp [NormedSpace.expSeries, continuousMultilinearCurryFin1_apply] + +omit [NormedAlgebra ℚ A] [NormOneClass A] in +theorem exp_curve_deriv_zero (X : A) : + HasDerivAt (fun t : ℝ => NormedSpace.exp (t • X)) X 0 := by + have hs : HasDerivAt (fun t : ℝ => t • X) X 0 := by + simpa using ((hasDerivAt_id (0 : ℝ)).smul_const X) + have he : HasFDerivAt (NormedSpace.exp : A → A) (ContinuousLinearMap.id ℝ A) ((0 : ℝ) • X) := by + simpa using (exp_hasFDerivAt_zero (A := A)) + convert! he.comp_hasDerivAt (0 : ℝ) hs using 1 + +omit [NormedAlgebra ℝ A] [NormedAlgebra ℚ A] [CompleteSpace A] in +theorem norm_pow_sub_pow_le {U V : A} (hU : ‖U‖ ≤ 1) (hV : ‖V‖ ≤ 1) (n : ℕ) : + ‖U^n - V^n‖ ≤ (n : ℝ)*‖U-V‖ := by + induction n with + | zero => simp + | succ n ih => + have hp : ‖V^n‖ ≤ 1 := (norm_pow_le V n).trans (by simpa using pow_le_pow_left₀ (norm_nonneg V) hV n) + calc + ‖U^(n+1)-V^(n+1)‖ = ‖(U^n-V^n)*U+V^n*(U-V)‖ := by congr 1; simp only [pow_succ]; noncomm_ring + _ ≤ ‖(U^n-V^n)*U‖+‖V^n*(U-V)‖ := norm_add_le _ _ + _ ≤ ‖U^n-V^n‖*‖U‖+‖V^n‖*‖U-V‖ := add_le_add (norm_mul_le _ _) (norm_mul_le _ _) + _ ≤ (n : ℝ)*‖U-V‖+‖U-V‖ := by + apply add_le_add + · exact (mul_le_mul_of_nonneg_left hU (norm_nonneg _)).trans (by simpa using ih) + · exact (mul_le_mul_of_nonneg_right hp (norm_nonneg _)).trans_eq (one_mul _) + _ = _ := by push_cast; ring + + + +theorem tendsto_tangent_powers {f : ℝ → A} {X : A} + (hf : HasDerivAt f X 0) (hf0 : f 0 = 1) + (hfn : ∀ t, ‖f t‖ ≤ 1) (he : ∀ t : ℝ, ‖NormedSpace.exp (t • X)‖ ≤ 1) (t : ℝ) : + Tendsto (fun n : ℕ => (f (t/(n : ℝ)))^n) atTop (𝓝 (NormedSpace.exp (t • X))) := by + by_cases ht : t = 0 + · subst t + simp [hf0] + have hd := hf.sub (exp_curve_deriv_zero X) + have hh : Tendsto (fun x : ℝ => ‖x‖⁻¹ * ‖f x-NormedSpace.exp (x • X)‖) (𝓝 0) (𝓝 0) := by + simpa [hf0] using hasDerivAt_iff_tendsto.mp hd + have hinv : Tendsto (fun n : ℕ => t/(n : ℝ)) atTop (𝓝 0) := by + simpa [div_eq_mul_inv] using (tendsto_const_nhds (x := t)).mul tendsto_inv_atTop_nhds_zero_nat + have herr : Tendsto (fun n : ℕ => (n : ℝ)*‖f (t/(n : ℝ))-NormedSpace.exp ((t/(n : ℝ)) • X)‖) + atTop (𝓝 0) := by + have h := (hh.comp hinv).const_mul ‖t‖ + simp only [mul_zero] at h + apply h.congr' + filter_upwards [eventually_gt_atTop 0] with n hn + have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_zero_of_lt hn) + simp only [Function.comp_apply] + rw [norm_div, Real.norm_of_nonneg (Nat.cast_nonneg n)] + field_simp [norm_ne_zero_iff.mpr ht] + have hdist : Tendsto (fun n : ℕ => ‖(f (t/(n : ℝ)))^n-NormedSpace.exp (t • X)‖) + atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun n => norm_nonneg _)) ?_ herr + filter_upwards [eventually_gt_atTop 0] with n hn + have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr (Nat.ne_zero_of_lt hn) + have hx : NormedSpace.exp (t • X) = NormedSpace.exp ((t/(n : ℝ)) • X)^n := by + rw [← NormedSpace.exp_nsmul] + congr 1 + rw [← Nat.cast_smul_eq_nsmul ℝ, smul_smul] + congr 1 + field_simp + rw [hx] + exact norm_pow_sub_pow_le (hfn _) (he _) n + exact tendsto_iff_norm_sub_tendsto_zero.mpr hdist + +omit [NormedAlgebra ℝ A] [NormOneClass A] in +theorem exp_mul_exp_neg (X : A) : NormedSpace.exp X * NormedSpace.exp (-X) = 1 := by + rw [← NormedSpace.exp_add_of_commute (Commute.refl X).neg_right, add_neg_cancel, NormedSpace.exp_zero] + +omit [NormedAlgebra ℝ A] [NormOneClass A] in +theorem exp_neg_mul_exp (X : A) : NormedSpace.exp (-X) * NormedSpace.exp X = 1 := by + rw [← NormedSpace.exp_add_of_commute (Commute.refl X).neg_left, neg_add_cancel, NormedSpace.exp_zero] + +variable [StarRing A] [CStarRing A] [StarModule ℝ A] [Nontrivial A] + +omit [NormOneClass A] in +theorem norm_exp_smul_le {X : A} (hX : X ∈ skewAdjoint A) (t : ℝ) : + ‖NormedSpace.exp (t • X)‖ ≤ 1 := by + exact (CStarRing.norm_of_mem_unitary (NormedSpace.exp_mem_unitary_of_mem_skewAdjoint + (skewAdjoint.smul_mem t hX))).le + +theorem tangent_mem_closed_submonoid (S : Submonoid A) (hS : IsClosed (S : Set A)) + (hU : ∀ x ∈ S, x ∈ unitary A) {f : ℝ → A} {X : A} + (hf : HasDerivAt f X 0) (hf0 : f 0 = 1) (hm : ∀ t, f t ∈ S) + (hX : X ∈ skewAdjoint A) (t : ℝ) : NormedSpace.exp (t • X) ∈ S := by + apply hS.mem_of_tendsto (tendsto_tangent_powers hf hf0 + (fun t => (CStarRing.norm_of_mem_unitary (hU _ (hm t))).le) (norm_exp_smul_le hX) t) + exact Eventually.of_forall (fun n => S.pow_mem (hm _) n) + + +def tangents (S : Submonoid A) (hS : IsClosed (S : Set A)) + (hU : ∀ x ∈ S, x ∈ unitary A) : Submodule ℝ A where + carrier := {X | X ∈ skewAdjoint A ∧ ∀ t : ℝ, NormedSpace.exp (t • X) ∈ S} + zero_mem' := by simp [NormedSpace.exp_zero, S.one_mem] + add_mem' := by + intro X Y hX hY + refine ⟨(skewAdjoint A).add_mem hX.1 hY.1, fun t => ?_⟩ + have hd : HasDerivAt (fun s : ℝ => NormedSpace.exp (s • X)*NormedSpace.exp (s • Y)) (X+Y) 0 := by + convert! (exp_curve_deriv_zero X).mul (exp_curve_deriv_zero Y) using 1; simp + exact tangent_mem_closed_submonoid S hS hU hd (by simp) (fun s => S.mul_mem (hX.2 s) (hY.2 s)) + ((skewAdjoint A).add_mem hX.1 hY.1) t + smul_mem' := by + intro r X hX + refine ⟨skewAdjoint.smul_mem r hX.1,fun t => ?_⟩ + simpa [smul_smul] using hX.2 (t*r) + +theorem mem_tangents {S : Submonoid A} {hS hU} {X : A} : + X ∈ tangents S hS hU ↔ X ∈ skewAdjoint A ∧ ∀ t : ℝ, NormedSpace.exp (t • X) ∈ S := Iff.rfl + +theorem isClosed_tangents (S : Submonoid A) (hS : IsClosed (S : Set A)) + (hU : ∀ x ∈ S, x ∈ unitary A) : IsClosed (tangents S hS hU : Set A) := by + change IsClosed ({X : A | star X = -X} ∩ {X : A | ∀ t : ℝ, NormedSpace.exp (t • X) ∈ S}) + apply IsClosed.inter (isClosed_eq continuous_star continuous_neg) + simp only [Set.ofPred_forall] + exact isClosed_iInter (fun t => hS.preimage (NormedSpace.exp_continuous.comp (continuous_const_smul t))) + +omit [NormedAlgebra ℚ A] [NormOneClass A] [StarRing A] [CStarRing A] [StarModule ℝ A] [Nontrivial A] in +theorem conjugation_deriv_zero (X Y : A) : + HasDerivAt (fun t : ℝ => NormedSpace.exp (t • X)*Y*NormedSpace.exp (-t • X)) (X*Y-Y*X) 0 := by + have hn : HasDerivAt (fun t : ℝ => NormedSpace.exp (-t • X)) (-X) 0 := by + convert! exp_curve_deriv_zero (-X) using 1; simp + convert! ((exp_curve_deriv_zero X).mul_const Y).mul hn using 1; simp [sub_eq_add_neg] + +omit [NormedAlgebra ℚ A] [NormOneClass A] [Nontrivial A] [CompleteSpace A] in + +theorem star_exp_smul {X : A} (hX : X ∈ skewAdjoint A) (t : ℝ) : + star (NormedSpace.exp (t • X)) = NormedSpace.exp (-t • X) := by + rw [NormedSpace.star_exp, star_smul, star_trivial, skewAdjoint.mem_iff.mp hX, smul_neg, neg_smul] + +theorem commutator_loop_tangent_mem (S : Submonoid A) (hS : IsClosed (S : Set A)) + (hU : ∀ x ∈ S, x ∈ unitary A) {X Y : A} + (hX : X ∈ skewAdjoint A) (hY : Y ∈ skewAdjoint A) + (hloop : ∀ u v : ℝ, + NormedSpace.exp (u • X)*NormedSpace.exp (v • Y)* + NormedSpace.exp (-u • X)*NormedSpace.exp (-v • Y) ∈ S) : + X*Y-Y*X ∈ tangents S hS hU := by + have hD (u : ℝ) : + NormedSpace.exp (u • X)*Y*NormedSpace.exp (-u • X)-Y ∈ tangents S hS hU := by + let U := NormedSpace.exp (u • X) + let V := NormedSpace.exp (-u • X) + have hUV : U*V=1 := by simpa [U,V,neg_smul] using exp_mul_exp_neg (u • X) + have hUs : star U=V := star_exp_smul hX u + have hVs : star V=U := by simpa [U,V] using star_exp_smul hX (-u) + have hsk : U*Y*V-Y ∈ skewAdjoint A := by + rw [skewAdjoint.mem_iff] + simp only [star_sub, star_mul, hUs, hVs, skewAdjoint.mem_iff.mp hY] + noncomm_ring + refine ⟨hsk,fun t => ?_⟩ + have hn : HasDerivAt (fun v : ℝ => NormedSpace.exp (-v • Y)) (-Y) 0 := by + convert! exp_curve_deriv_zero (-Y) using 1; simp + have hd : HasDerivAt (fun v : ℝ => U*NormedSpace.exp (v • Y)*V*NormedSpace.exp (-v • Y)) + (U*Y*V-Y) 0 := by + convert! (((exp_curve_deriv_zero Y).const_mul U).mul_const V).mul hn using 1 + simp [hUV,sub_eq_add_neg] + exact tangent_mem_closed_submonoid S hS hU hd (by simp [hUV]) (hloop u) hsk t + apply (isClosed_tangents S hS hU).mem_of_tendsto (conjugation_deriv_zero X Y).tendsto_slope + apply Eventually.of_forall + intro u + simpa [slope, vsub_eq_sub] using (tangents S hS hU).smul_mem u⁻¹ (hD u) + +theorem normalized_bracket_mem (S : Submonoid A) (hS : IsClosed (S : Set A)) + (hU : ∀ x ∈ S, x ∈ unitary A) {X Y : A} + (hX : X ∈ skewAdjoint A) (hY : Y ∈ tangents S hS hU) + (hN : ∀ u : ℝ, ∀ V ∈ S, + NormedSpace.exp (u • X)*V*NormedSpace.exp (-u • X) ∈ S) : + X*Y-Y*X ∈ tangents S hS hU := by + apply commutator_loop_tangent_mem S hS hU hX hY.1 + intro u v + exact S.mul_mem (hN u _ (hY.2 v)) (hY.2 (-v)) + +end Banach + +section Words +variable {A κ : Type*} [NormedRing A] [NormedAlgebra ℝ A] [DecidableEq κ] + +def pulseValue (G : κ → A) (w : List (κ × ℝ)) : A := + (w.map (fun p => NormedSpace.exp (p.2 • G p.1))).prod + +def pulseClock (w : List (κ × ℝ)) : κ → ℝ := + (w.map (fun p => Pi.single p.1 p.2)).sum + +omit [DecidableEq κ] in +@[simp] theorem pulseValue_nil (G : κ → A) : pulseValue G [] = 1 := rfl + +omit [DecidableEq κ] in +@[simp] theorem pulseValue_append (G : κ → A) (w v : List (κ × ℝ)) : + pulseValue G (w++v) = pulseValue G w * pulseValue G v := by + simp [pulseValue] + +@[simp] theorem pulseClock_nil : pulseClock ([] : List (κ × ℝ)) = 0 := rfl + +@[simp] theorem pulseClock_append (w v : List (κ × ℝ)) : + pulseClock (w++v) = pulseClock w + pulseClock v := by + simp [pulseClock] + + +def zeroClockWords (G : κ → A) : Submonoid A where + carrier := {U | ∃ w : List (κ × ℝ), pulseClock w = 0 ∧ pulseValue G w = U} + one_mem' := ⟨[],rfl,rfl⟩ + mul_mem' := by + rintro U V ⟨w,hw,rfl⟩ ⟨v,hv,rfl⟩ + exact ⟨w++v,by simp [hw,hv],by simp⟩ + +theorem commutator_loop_mem (G : κ → A) (a b : κ) (u v : ℝ) : + NormedSpace.exp (u • G a)*NormedSpace.exp (v • G b)* + NormedSpace.exp (-u • G a)*NormedSpace.exp (-v • G b) ∈ zeroClockWords G := by + refine ⟨[(a,u),(b,v),(a,-u),(b,-v)],?_,?_⟩ + · ext i + simp only [pulseClock, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, + Pi.add_apply, Pi.zero_apply, Pi.single_apply] + split_ifs <;> ring + · simp [pulseValue, mul_assoc] + +theorem conjugate_word_mem (G : κ → A) (a : κ) (u : ℝ) {U : A} + (hU : U ∈ zeroClockWords G) : + NormedSpace.exp (u • G a)*U*NormedSpace.exp (-u • G a) ∈ zeroClockWords G := by + obtain ⟨w,hw,rfl⟩ := hU + refine ⟨[(a,u)]++w++[(a,-u)],?_,?_⟩ + · rw [pulseClock_append, pulseClock_append, hw] + ext i + simp [pulseClock, Pi.single_apply] + split_ifs <;> ring + · simp [pulseValue, mul_assoc] + +theorem conjugate_closure_mem (G : κ → A) (a : κ) (u : ℝ) {U : A} + (hU : U ∈ (zeroClockWords G).topologicalClosure) : + NormedSpace.exp (u • G a)*U*NormedSpace.exp (-u • G a) ∈ + (zeroClockWords G).topologicalClosure := by + have hc : Continuous (fun V : A => + NormedSpace.exp (u • G a)*V*NormedSpace.exp (-u • G a)) := by fun_prop + change U ∈ (fun V : A => NormedSpace.exp (u • G a)*V*NormedSpace.exp (-u • G a)) ⁻¹' + ((zeroClockWords G).topologicalClosure : Set A) + apply closure_minimal (s := (zeroClockWords G : Set A)) + (t := (fun V : A => NormedSpace.exp (u • G a)*V*NormedSpace.exp (-u • G a)) ⁻¹' + ((zeroClockWords G).topologicalClosure : Set A)) ?_ + ((zeroClockWords G).isClosed_topologicalClosure.preimage hc) hU + intro V hV + exact (zeroClockWords G).le_topologicalClosure (conjugate_word_mem G a u hV) + +variable [NormedAlgebra ℚ A] [CompleteSpace A] [StarRing A] [CStarRing A] [StarModule ℝ A] + +theorem zeroClockWords_le_unitary (G : κ → A) (hG : ∀ a, G a ∈ skewAdjoint A) : + zeroClockWords G ≤ unitary A := by + rintro U ⟨w,hw,rfl⟩ + apply (unitary A).list_prod_mem + intro x hx + obtain ⟨p,hp,rfl⟩ := List.mem_map.mp hx + exact NormedSpace.exp_mem_unitary_of_mem_skewAdjoint (skewAdjoint.smul_mem p.2 (hG p.1)) + +theorem closure_le_unitary (G : κ → A) (hG : ∀ a, G a ∈ skewAdjoint A) : + (zeroClockWords G).topologicalClosure ≤ unitary A := + (zeroClockWords G).topologicalClosure_minimal (zeroClockWords_le_unitary G hG) isClosed_unitary + +variable [NormOneClass A] [Nontrivial A] + +def zeroClockTangents (G : κ → A) (hG : ∀ a, G a ∈ skewAdjoint A) : Submodule ℝ A := + tangents _ (zeroClockWords G).isClosed_topologicalClosure (closure_le_unitary G hG) + +theorem bracket_mem_zeroClockTangents (G : κ → A) (hG : ∀ a, G a ∈ skewAdjoint A) (a b : κ) : + G a * G b - G b * G a ∈ zeroClockTangents G hG := by + apply commutator_loop_tangent_mem _ _ _ (hG a) (hG b) + intro u v + exact (zeroClockWords G).le_topologicalClosure (commutator_loop_mem G a b u v) + +theorem bracket_closed_zeroClockTangents (G : κ → A) (hG : ∀ a, G a ∈ skewAdjoint A) + (a : κ) {Y : A} (hY : Y ∈ zeroClockTangents G hG) : + G a * Y - Y * G a ∈ zeroClockTangents G hG := by + apply normalized_bracket_mem _ _ _ (hG a) hY + intro u U hU + exact conjugate_closure_mem G a u hU + + + +theorem approximate_zeroClock (G : κ → A) (hG : ∀ a, G a ∈ skewAdjoint A) + {X : A} (hX : X ∈ zeroClockTangents G hG) (t : ℝ) {ε : ℝ} (hε : 0 < ε) : + ∃ w : List (κ × ℝ), pulseClock w = 0 ∧ + ‖pulseValue G w - NormedSpace.exp (t • X)‖ < ε := by + obtain ⟨U,hU,hd⟩ := Metric.mem_closure_iff.mp (hX.2 t) ε hε + obtain ⟨w,hw,rfl⟩ := hU + exact ⟨w,hw,by simpa only [dist_eq_norm, norm_sub_rev] using hd⟩ + +end Words +end PulseControl + +namespace ExactPulseControl +open PulseControl + +section Tangents +variable {A κ : Type*} [NormedRing A] [NormedAlgebra ℝ A] [NormedAlgebra ℚ A] + [CompleteSpace A] [DecidableEq κ] + +omit [NormedAlgebra ℚ A] in +theorem contDiff_exp_curve (X : A) : ContDiff ℝ 1 (fun t : ℝ => NormedSpace.exp (t • X)) := by + have h : ContDiff ℝ 1 (NormedSpace.exp : A → A) := + (show AnalyticOnNhd ℝ (NormedSpace.exp : A → A) Set.univ from + fun a _ => NormedSpace.exp_analytic a).contDiff + exact h.comp (contDiff_id.smul contDiff_const) + + + +def actualTangents (G : κ → A) : Submodule ℝ A where + carrier := {X | ∃ f : ℝ → A, ContDiff ℝ 1 f ∧ f 0 = 1 ∧ + HasDerivAt f X 0 ∧ ∀ t, f t ∈ zeroClockWords G} + zero_mem' := ⟨fun _ => 1,contDiff_const,rfl,hasDerivAt_const _ _,fun _ => (zeroClockWords G).one_mem⟩ + add_mem' := by + rintro X Y ⟨f,hf,hf0,hdf,hmf⟩ ⟨g,hg,hg0,hdg,hmg⟩ + refine ⟨fun t => f t*g t,hf.mul hg,by simp [hf0,hg0],?_,fun t => (zeroClockWords G).mul_mem (hmf t) (hmg t)⟩ + convert! hdf.mul hdg using 1; simp [hf0,hg0] + smul_mem' := by + rintro r X ⟨f,hf,hf0,hdf,hmf⟩ + refine ⟨fun t => f (r*t),hf.comp (contDiff_const.mul contDiff_id),by simpa using hf0,?_,fun t => hmf _⟩ + convert! hdf.scomp_of_eq (0 : ℝ) ((hasDerivAt_id (0 : ℝ)).const_mul r) (by simp) using 1; simp + +variable [FiniteDimensional ℝ A] + +omit [NormedAlgebra ℚ A] [CompleteSpace A] in +theorem actualTangents_closed (G : κ → A) : IsClosed (actualTangents G : Set A) := + (actualTangents G).closed_of_finiteDimensional + +theorem bracket_actualTangents (G : κ → A) (a b : κ) : + G a*G b-G b*G a ∈ actualTangents G := by + have hD (u : ℝ) : NormedSpace.exp (u • G a)*G b*NormedSpace.exp (-u • G a)-G b ∈ actualTangents G := by + let U := NormedSpace.exp (u • G a) + let V := NormedSpace.exp (-u • G a) + have hUV : U*V=1 := by simpa [U,V,neg_smul] using exp_mul_exp_neg (u • G a) + have hn : HasDerivAt (fun v : ℝ => NormedSpace.exp (-v • G b)) (-G b) 0 := by + convert! exp_curve_deriv_zero (-G b) using 1; simp + refine ⟨fun v => U*NormedSpace.exp (v • G b)*V*NormedSpace.exp (-v • G b),?_,by simp [hUV],?_, + fun v => commutator_loop_mem G a b u v⟩ + · apply ContDiff.mul + · exact (contDiff_const.mul (contDiff_exp_curve (G b))).mul contDiff_const + · convert contDiff_exp_curve (-G b) using 1; funext v; simp + · convert! (((exp_curve_deriv_zero (G b)).const_mul U).mul_const V).mul hn using 1 + simp [hUV,sub_eq_add_neg] + simp [U,V,neg_smul] + apply (actualTangents_closed G).mem_of_tendsto (conjugation_deriv_zero (G a) (G b)).tendsto_slope + apply Eventually.of_forall + intro u + simpa [slope,vsub_eq_sub] using (actualTangents G).smul_mem u⁻¹ (hD u) + +theorem bracket_closed_actualTangents (G : κ → A) (a : κ) {Y : A} (hY : Y ∈ actualTangents G) : + G a*Y-Y*G a ∈ actualTangents G := by + obtain ⟨f,hf,hf0,hdf,hmf⟩ := hY + have hD (u : ℝ) : NormedSpace.exp (u • G a)*Y*NormedSpace.exp (-u • G a)-Y ∈ actualTangents G := by + let U := NormedSpace.exp (u • G a) + let V := NormedSpace.exp (-u • G a) + have hUV : U*V=1 := by simpa [U,V,neg_smul] using exp_mul_exp_neg (u • G a) + have hn : HasDerivAt (fun v : ℝ => f (-v)) (-Y) 0 := by + convert! hdf.scomp_of_eq (0 : ℝ) (hasDerivAt_neg (0 : ℝ)) (by simp) using 1; simp + refine ⟨fun v => U*f v*V*f (-v), + ((contDiff_const.mul hf).mul contDiff_const).mul (hf.comp contDiff_neg),?_,?_,?_⟩ + · simp [hf0,hUV] + · convert! ((hdf.const_mul U).mul_const V).mul hn using 1 + simp [hf0,hUV,sub_eq_add_neg] + simp [U,V,neg_smul] + · intro v + exact (zeroClockWords G).mul_mem (conjugate_word_mem G a u (hmf v)) (hmf (-v)) + apply (actualTangents_closed G).mem_of_tendsto (conjugation_deriv_zero (G a) Y).tendsto_slope + apply Eventually.of_forall + intro u + simpa [slope,vsub_eq_sub] using (actualTangents G).smul_mem u⁻¹ (hD u) + +end Tangents +end ExactPulseControl + +namespace ExactPulseControl +open PulseControl + +section Submersion +variable {A E κ ι : Type*} [NormedRing A] [NormedAlgebra ℝ A] + [NormedAddCommGroup E] [NormedSpace ℝ E] + +theorem hasStrictFDerivAt_list_prod_one (l : List ι) (f : ι → E → A) + (D : ι → E →L[ℝ] A) (x : E) (h0 : ∀ i ∈ l, f i x=1) + (hd : ∀ i ∈ l, HasStrictFDerivAt (f i) (D i) x) : + HasStrictFDerivAt (fun t => (l.map (fun i => f i t)).prod) (l.map D).sum x := by + induction l with + | nil => simpa using hasStrictFDerivAt_const (𝕜 := ℝ) (1 : A) x + | cons i l ih => + have ht := (hd i (by simp)).mul' (ih (fun j hj => h0 j (by simp [hj])) (fun j hj => hd j (by simp [hj]))) + have hp : (l.map (fun i => f i x)).prod=1 := by + rw [List.prod_eq_one]; intro y hy + obtain ⟨j,hj,rfl⟩ := List.mem_map.mp hy + exact h0 j (by simp [hj]) + convert! ht using 1; simp [h0 i (by simp),hp,add_comm] + +variable [CompleteSpace A] [DecidableEq κ] [CompleteSpace E] + +omit [CompleteSpace A] in + + +theorem projected_reachable_nhds {m : ℕ} (G : κ → A) (X : Fin m → A) + (hX : ∀ i, X i ∈ actualTangents G) (π : A →L[ℝ] E) + (hD : (π.comp (∑ i, ((ContinuousLinearMap.proj i : (Fin m → ℝ) →L[ℝ] ℝ)).smulRight (X i))).range=⊤) + (P : Set A) (hP : P ∈ 𝓝 (1 : A)) : + {y : E | ∃ x ∈ zeroClockWords G, x ∈ P ∧ π x=y} ∈ 𝓝 (π 1) := by + choose f hf hf0 hdf hmf using hX + let D (i : Fin m) : (Fin m → ℝ) →L[ℝ] A := (ContinuousLinearMap.proj i).smulRight (X i) + let F : (Fin m → ℝ) → A := fun t => (List.ofFn (fun i => f i (t i))).prod + have hF0 : F 0 = 1 := by simp [F,hf0] + have hFd : HasStrictFDerivAt F (∑ i, D i) 0 := by + have hd (i : Fin m) : HasStrictFDerivAt (fun t : Fin m → ℝ => f i (t i)) (D i) 0 := by + have hfi := ((hf i).contDiffAt.hasStrictDerivAt' (hdf i) (by norm_num : (1 : WithTop ℕ∞) ≠ 0)).hasStrictFDerivAt + convert! hfi.comp (0 : Fin m → ℝ) ((ContinuousLinearMap.proj i : (Fin m → ℝ) →L[ℝ] ℝ).hasStrictFDerivAt) using 1 + have hh := hasStrictFDerivAt_list_prod_one (List.finRange m) (fun i (t : Fin m → ℝ) => f i (t i)) D 0 + (by intro i _; exact hf0 i) (by intro i _; exact hd i) + convert! hh using 1 + · simp [F,List.ofFn_eq_map] + have hFm (t : Fin m → ℝ) : F t ∈ zeroClockWords G := by + apply (zeroClockWords G).list_prod_mem + intro x hx + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hx + exact hmf i (t i) + have hh := ((π.hasStrictFDerivAt).comp 0 hFd).map_nhds_eq_of_surj hD + rw [hF0] at hh + rw [← hh, Filter.mem_map'] + filter_upwards [hFd.continuousAt (by simpa [hF0] using hP)] with t ht + exact ⟨F t,hFm t,ht,rfl⟩ + +end Submersion +end ExactPulseControl + +namespace ExactPulseControl +open PulseControl +variable {A E κ : Type*} [NormedRing A] [NormedAlgebra ℝ A] + [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] + [CompleteSpace A] [DecidableEq κ] + +omit [CompleteSpace A] in +theorem surjective_tangents_reachable_nhds (G : κ → A) (π : A →L[ℝ] E) + (hπ : ∀ y, ∃ X ∈ actualTangents G, π X=y) + (P : Set A) (hP : P ∈ 𝓝 (1 : A)) : + {y : E | ∃ x ∈ zeroClockWords G, x ∈ P ∧ π x=y} ∈ 𝓝 (π 1) := by + let b := Module.finBasis ℝ E + choose X hX hXπ using fun i => hπ (b i) + apply projected_reachable_nhds G X hX π ?_ P hP + rw [LinearMap.range_eq_top] + intro y + refine ⟨b.repr y,?_⟩ + change π ((∑ i, ((ContinuousLinearMap.proj i : (Fin (Module.finrank ℝ E) → ℝ) →L[ℝ] ℝ)).smulRight (X i)) (b.repr y))=y + simp only [sum_apply,ContinuousLinearMap.smulRight_apply,ContinuousLinearMap.proj_apply,map_sum,map_smul,hXπ] + exact b.sum_repr y +end ExactPulseControl + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/FlipStar.lean b/lean/OAI/Probability/ParisiFinite/FlipStar.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ce210d8aa94f0169a46ed8b175783f1028f5a05 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/FlipStar.lean @@ -0,0 +1,639 @@ +import Mathlib +import OAI.Probability.ParisiFinite.MovingTensorInsertionLimit +import OAI.Probability.ParisiFinite.ReverseWord + +namespace OAI + +/-! Flip Star. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open scoped InnerProductSpace +namespace FiniteTree +open RootSpin SpinOperators + +@[simp] theorem flip_star (D h : ℕ) : star (flip D h)=flip D h := by + calc + star (flip D h)=star (flip D h)*(flip D h*flip D h) := by rw [flip_square,mul_one] + _ = (star (flip D h)*flip D h)*flip D h := (mul_assoc _ _ _).symm + _ = flip D h := by rw [(Unitary.mem_iff.mp (flip_unitary D h)).1,one_mul] + + + +structure Even (D h : ℕ) where + op : Space D h →L[ℂ] Space D h + unitary : op ∈ _root_.unitary _ + commutes : flip D h*op=op*flip D h + +namespace Even +variable {D h : ℕ} + +def ident (D h : ℕ) : Even D h where + op := 1 + unitary := (_root_.unitary _).one_mem + commutes := by simp + +def followedBy (U V : Even D h) : Even D h where + op := V.op*U.op + unitary := (_root_.unitary _).mul_mem V.unitary U.unitary + commutes := by + rw [←mul_assoc,V.commutes,mul_assoc,U.commutes,←mul_assoc] + +def mixer (D h : ℕ) (t : ℝ) : Even D h where + op := root D h (R t) + unitary := root_unitary D h (R_unitary t) + commutes := by + apply ContinuousLinearMap.ext + intro x + exact flip_rootR D h t x + +theorem star_commutes (U : Even D h) : flip D h*star U.op=star U.op*flip D h := by + have hs := congrArg star U.commutes + simpa only [star_mul,flip_star] using hs.symm + + +def observable (U : Even D h) : Space D h →L[ℂ] Space D h := + star U.op*root D h Z*U.op + +@[simp] theorem observable_star (U : Even D h) : star U.observable=U.observable := by + simp only [observable,star_mul,star_star,←root_star,Matrix.star_eq_conjTranspose,Z_star,mul_assoc] + +theorem observable_unitary (U : Even D h) : U.observable ∈ _root_.unitary _ := + (_root_.unitary _).mul_mem ((_root_.unitary _).mul_mem (Unitary.star_mem U.unitary) + (root_unitary D h Z_unitary)) U.unitary + +@[simp] theorem norm_observable (U : Even D h) : ‖U.observable‖=1 := + CStarRing.norm_of_mem_unitary U.observable_unitary + +theorem observable_odd (U : Even D h) : + flip D h*U.observable= -U.observable*flip D h := by + have hz : flip D h*root D h Z= -root D h Z*flip D h := by + apply ContinuousLinearMap.ext + intro x + exact flip_rootZ D h x + change flip D h*(star U.op*root D h Z*U.op)= -(star U.op*root D h Z*U.op)*flip D h + calc + _ = (flip D h*star U.op)*root D h Z*U.op := by simp only [mul_assoc] + _ = star U.op*(flip D h*root D h Z)*U.op := by rw [U.star_commutes]; simp only [mul_assoc] + _ = _ := by + rw [hz] + simp only [mul_assoc,U.commutes] + rw [neg_mul (root D h Z) (U.op*flip D h), + mul_neg (star U.op) (root D h Z*(U.op*flip D h)), + neg_mul (star U.op*(root D h Z*U.op)) (flip D h)] + simp only [mul_assoc] + + + +theorem observable_centered (U : Even D h) : + ⟪vac D h,U.observable (vac D h)⟫_ℂ=0 := by + have ho : flip D h (U.observable (vac D h))= -U.observable (vac D h) := by + have hh := congrArg (fun A : Space D h →L[ℂ] Space D h => A (vac D h)) U.observable_odd + simpa only [mul_apply_eq_comp,neg_apply,flip_vac] using hh + have hi := (Unitary.linearIsometryEquiv ⟨flip D h,flip_unitary D h⟩).inner_map_map + (vac D h) (U.observable (vac D h)) + change ⟪flip D h (vac D h),flip D h (U.observable (vac D h))⟫_ℂ= + ⟪vac D h,U.observable (vac D h)⟫_ℂ at hi + rw [flip_vac,ho,inner_neg_right] at hi + linear_combination -(1/2:ℂ)*hi + + + +def generator (U : Even D h) (t : ℝ) : Space D h →L[ℂ] Space D h := + (Complex.I*(t:ℂ)) • U.observable + +@[simp] theorem generator_neg (U : Even D h) (t : ℝ) : U.generator (-t)= -U.generator t := by + simp only [generator,Complex.ofReal_neg,mul_neg] + exact _root_.neg_smul (Complex.I*(t:ℂ)) U.observable + +@[simp] theorem generator_star (U : Even D h) (t : ℝ) : star (U.generator t)= -U.generator t := by + simp only [generator,star_smul,star_mul,Complex.star_def, + Complex.conj_I,Complex.conj_ofReal,U.observable_star] + rw [show (t:ℂ)* -Complex.I= -(Complex.I*(t:ℂ)) by ring] + exact _root_.neg_smul (Complex.I*(t:ℂ)) U.observable + +@[simp] theorem norm_generator (U : Even D h) (t : ℝ) : ‖U.generator t‖=|t| := by + simp [generator,norm_smul] + +@[simp] theorem generator_centered (U : Even D h) (t : ℝ) : + ⟪vac D h,U.generator t (vac D h)⟫_ℂ=0 := by + simp only [generator,smul_apply,inner_smul_right,U.observable_centered,mul_zero] + +def exponential (U : Even D h) (t : ℝ) : Space D h →L[ℂ] Space D h := + NormedSpace.exp (U.generator t) + +theorem exponential_unitary (U : Even D h) (t : ℝ) : U.exponential t ∈ _root_.unitary _ := by + let : NormedAlgebra ℚ (Space D h →L[ℂ] Space D h) := NormedAlgebra.restrictScalars ℚ ℂ _ + let : CompleteSpace (Space D h) := PiLp.completeSpace 2 (fun _ : Index D h => ℂ) + let : CompleteSpace (Space D h →L[ℂ] Space D h) := ContinuousLinearMap.instCompleteSpace + exact NormedSpace.exp_mem_unitary_of_mem_skewAdjoint (by + rw [skewAdjoint.mem_iff] + exact U.generator_star t) + +theorem generator_odd (U : Even D h) (t : ℝ) : + flip D h*U.generator t=U.generator (-t)*flip D h := by + simp only [generator,mul_smul_comm,smul_mul_assoc,U.observable_odd,Complex.ofReal_neg,mul_neg] + rw [neg_mul U.observable (flip D h), + smul_neg (Complex.I*(t:ℂ)) (U.observable*flip D h), + neg_smul (Complex.I*(t:ℂ)) (U.observable*flip D h)] + +theorem exponential_odd (U : Even D h) (t : ℝ) : + flip D h*U.exponential t=U.exponential (-t)*flip D h := by + let : NormedAlgebra ℚ (Space D h →L[ℂ] Space D h) := NormedAlgebra.restrictScalars ℚ ℂ _ + let : CompleteSpace (Space D h) := PiLp.completeSpace 2 (fun _ : Index D h => ℂ) + let : CompleteSpace (Space D h →L[ℂ] Space D h) := ContinuousLinearMap.instCompleteSpace + exact (show SemiconjBy (flip D h) (U.generator t) (U.generator (-t)) from U.generator_odd t).exp_right + +end Even +end FiniteTree + + + +open scoped InnerProductSpace +namespace FiniteTree +open SpinOperators TensorPackets + + + +theorem spinFlip_diagonal {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (T : H →L[ℂ] H) (K : Fin 2 → H →L[ℂ] H) + (hK : ∀i,T*K i=K (1-i)*T) (x : Double H) : + spinFlip T (TensorPackets.diagonal K x)=TensorPackets.diagonal K (spinFlip T x) := by + ext i + simp only [spinFlip_apply,diagonal_apply] + have hk := congrArg (fun A : H →L[ℂ] H => A (x (1-i))) (hK (1-i)) + have hi : (1-(1-i):Fin 2)=i := by omega + simpa only [mul_apply_eq_comp,hi] using hk + +theorem flip_control (D h : ℕ) (K : Fin 2 → Space D h →L[ℂ] Space D h) + (hK : ∀i,flip D h*K i=K (1-i)*flip D h) : + flip D (h+1)*control D h K=control D h K*flip D (h+1) := by + apply ContinuousLinearMap.ext + intro x + apply (split D (h+1)).injective + change split D (h+1) (flip D (h+1) (control D h K x)) = + split D (h+1) (control D h K (flip D (h+1) x)) + rw [split_flip,split_control,split_control,split_flip] + apply spinFlip_diagonal + intro i + rw [←FiniteTensor.operatorPower_mul,hK i,FiniteTensor.operatorPower_mul] + +namespace Even + +theorem cost_blocks_flip {D h : ℕ} (U : Even D h) (γ : ℝ) (i : Fin 2) : + flip D h*U.exponential (if i=0 then -γ/Real.sqrt D else γ/Real.sqrt D)= + U.exponential (if 1-i=0 then -γ/Real.sqrt D else γ/Real.sqrt D)*flip D h := by + rw [U.exponential_odd] + congr 2 + fin_cases i <;> simp <;> ring + +def cost (D h : ℕ) (U : Even D h) (γ : ℝ) : Even D (h+1) where + op := control D h (fun i => U.exponential (if i=0 then -γ/(Real.sqrt D) else γ/(Real.sqrt D))) + unitary := control_unitary D h _ (fun _ => U.exponential_unitary _) + commutes := flip_control D h _ (U.cost_blocks_flip γ) + +end Even + + + +def ordinary (D : ℕ) : List PointedTree.Gate → (h : ℕ) → Even D h + | [],h => Even.ident D h + | PointedTree.Gate.mixer β::w,h => (ordinary D w h).followedBy (Even.mixer D h β) + | PointedTree.Gate.cost _::w,0 => ordinary D w 0 + | PointedTree.Gate.cost γ::w,h+1 => + (ordinary D w (h+1)).followedBy (Even.cost D h (ordinary D w h) γ) + +@[simp] theorem ordinary_zero_level (D : ℕ) (w : List PointedTree.Gate) : + (ordinary D w 0).op=(PointedTree.ordinary w 0).op.toContinuousLinearEquiv.toContinuousLinearMap := by + induction w with + | nil => rfl + | cons g w ih => + cases g with + | mixer β => + apply ContinuousLinearMap.ext + intro x + change root D 0 (RootSpin.R β) ((ordinary D w 0).op x)= + PointedTree.rootEquiv 0 (RootSpin.R β) (RootSpin.R_unitary β) ((PointedTree.ordinary w 0).op x) + rw [ih] + rfl + | cost γ => exact ih + +end FiniteTree + + + +open scoped InnerProductSpace +namespace RootTensorCLT +open SpinOperators TensorPackets CoherentFock +variable {κ H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +@[simp] theorem run_nil (K : κ → H →L[ℂ] H) : run K []=1 := rfl +@[simp] theorem run_cons (K : κ → H →L[ℂ] H) (p : Pulse κ) (w : List (Pulse κ)) : + run K (p::w)=applyPulse K p*run K w := rfl + +theorem run_append (K : κ → H →L[ℂ] H) (u w : List (Pulse κ)) : + run K (u++w)=run K u*run K w := by + induction u with + | nil => simp + | cons p u ih => simp only [List.cons_append,run_cons,ih,mul_assoc] + +def adjointPulse (neg : κ → κ) : Pulse κ → Pulse κ + | .root A => .root A.conjTranspose + | .control a => .control (neg ∘ a) + +def adjointProgram (neg : κ → κ) : List (Pulse κ) → List (Pulse κ) + | [] => [] + | p::w => adjointProgram neg w++[adjointPulse neg p] + +variable [CompleteSpace H] + +theorem applyPulse_adjoint (K : κ → H →L[ℂ] H) (neg : κ → κ) + (hs : ∀i,K (neg i)=star (K i)) (p : Pulse κ) : + applyPulse K (adjointPulse neg p)=star (applyPulse K p) := by + cases p with + | root A => exact (act_adjoint A).symm + | control a => + change diagonal (K ∘ (neg ∘ a))=star (diagonal (K ∘ a)) + rw [←diagonal_star] + congr 1 + funext i + exact hs (a i) + +theorem run_adjoint (K : κ → H →L[ℂ] H) (neg : κ → κ) + (hs : ∀i,K (neg i)=star (K i)) (w : List (Pulse κ)) : + run K (adjointProgram neg w)=star (run K w) := by + induction w with + | nil => simp [adjointProgram] + | cons p w ih => + rw [adjointProgram,run_append,run_cons,run_nil,mul_one,ih,applyPulse_adjoint K neg hs, + run_cons,star_mul] + +theorem weyl_star {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] (d : E) : + W (-d)=star (W d) := by + apply ContinuousLinearMap.ext + intro x + apply ext_inner_right ℂ + intro y + rw [ContinuousLinearMap.star_eq_adjoint,ContinuousLinearMap.adjoint_inner_left] + exact (inner_W_right d x y).symm + +theorem tensorPulse_star {ι : Type*} [Fintype ι] [DecidableEq ι] + (D : ℕ) (X : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (neg : κ → κ) (hn : ∀i,X (neg i)= -X i) (hs : ∀i,star (X i)= -X i) (i : κ) : + tensorPulse D X (neg i)=star (tensorPulse D X i) := by + let : NormedAlgebra ℚ (EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) := + NormedAlgebra.restrictScalars ℚ ℂ _ + rw [tensorPulse,tensorPulse,←FiniteTensor.operatorPower_star] + congr 1 + rw [NormedSpace.star_exp,star_smul,hs,hn] + simp only [Complex.star_def,map_inv₀,Complex.conj_ofReal] + +end RootTensorCLT + + + +open scoped InnerProductSpace +namespace FiniteTree +open RootTensorCLT CoherentFock SpinOperators TensorPackets + +abbrev Label := List PointedTree.Gate × ℝ + +def negateLabel (i : Label) : Label := (i.1,-i.2) + +theorem negateLabel_involutive : Function.Involutive negateLabel := by + intro i + cases i + simp [negateLabel] + +def childGenerator (D h : ℕ) (i : Label) : Space D h →L[ℂ] Space D h := + (ordinary D i.1 h).generator i.2 + +def childDirection (h : ℕ) (i : Label) : PointedTree.Mode h := + (i.2:ℂ) • (PointedTree.ordinary i.1 h).insertion + + + +def program : List PointedTree.Gate → List (Pulse Label) + | [] => [] + | .mixer β::w => .root (RootSpin.R β)::program w + | .cost γ::w => .control (fun i => (w,if i=0 then -γ else γ))::program w + +theorem generator_scaled {D h : ℕ} (U : Even D h) (s t : ℝ) : + (s:ℂ) • U.generator t=U.generator (s*t) := by + simp only [Even.generator,Complex.ofReal_mul,smul_smul] + congr 1 + ring + +theorem cost_tensorPulse (D h : ℕ) (w : List PointedTree.Gate) (γ : ℝ) (i : Fin 2) : + FiniteTensor.operatorPower D ((ordinary D w h).exponential + (if i=0 then -γ/Real.sqrt D else γ/Real.sqrt D))= + tensorPulse D (childGenerator D h) (w,if i=0 then -γ else γ) := by + simp only [tensorPulse,childGenerator,Even.exponential] + rw [←Complex.ofReal_inv,generator_scaled] + congr 2 + split <;> ring_nf + + +theorem split_ordinary (D h : ℕ) (w : List PointedTree.Gate) (x : Space D (h+1)) : + split D (h+1) ((ordinary D w (h+1)).op x)= + run (tensorPulse D (childGenerator D h)) (program w) (split D (h+1) x) := by + induction w with + | nil => rfl + | cons g w ih => + cases g with + | mixer β => + change split D (h+1) (root D (h+1) (RootSpin.R β) ((ordinary D w (h+1)).op x))=_ + rw [split_root,ih] + rfl + | cost γ => + change split D (h+1) (control D h (fun i => (ordinary D w h).exponential + (if i=0 then -γ/Real.sqrt D else γ/Real.sqrt D)) ((ordinary D w (h+1)).op x))=_ + rw [split_control,ih] + change TensorPackets.diagonal _ _=TensorPackets.diagonal _ _ + congr 2 + funext i + exact cost_tensorPulse D h w γ i + +theorem weyl_cost_program (h : ℕ) (w : List PointedTree.Gate) (γ : ℝ) : + WZ (-(γ:ℂ) • (PointedTree.ordinary w h).insertion)= + applyPulse (W ∘ childDirection h) (.control (fun i => (w,if i=0 then -γ else γ))) := by + ext x i + simp only [applyPulse,diagonal_apply,Function.comp_apply,childDirection,WZ_apply] + fin_cases i <;> simp + +theorem limiting_ordinary (h : ℕ) (w : List PointedTree.Gate) : + (PointedTree.ordinary w (h+1)).op.toContinuousLinearEquiv.toContinuousLinearMap= + run (W ∘ childDirection h) (program w) := by + induction w with + | nil => rfl + | cons g w ih => + cases g with + | mixer β => + apply ContinuousLinearMap.ext + intro x + change act (RootSpin.R β) ((PointedTree.ordinary w (h+1)).op x)= + act (RootSpin.R β) (run (W ∘ childDirection h) (program w) x) + rw [show (PointedTree.ordinary w (h+1)).op x=run (W ∘ childDirection h) (program w) x from + congrArg (fun A : PointedTree.Level (h+1) →L[ℂ] PointedTree.Level (h+1) => A x) ih] + | cost γ => + apply ContinuousLinearMap.ext + intro x + change WZ (-(γ:ℂ) • (PointedTree.ordinary w h).insertion) ((PointedTree.ordinary w (h+1)).op x)=_ + rw [weyl_cost_program] + rw [show (PointedTree.ordinary w (h+1)).op x=run (W ∘ childDirection h) (program w) x from + congrArg (fun A : PointedTree.Level (h+1) →L[ℂ] PointedTree.Level (h+1) => A x) ih] + rfl + +end FiniteTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace RootTensorCLT +open CoherentFock SpinOperators + +variable {κ : Type*} + +def Pulse.labels (p : Pulse κ) : Finset κ := by + classical + exact match p with + | .root _ => ∅ + | .control a => Finset.univ.image a + +def labels (w : List (Pulse κ)) : Finset κ := by + classical + exact w.toFinset.biUnion Pulse.labels + +theorem control_mem_labels (w : List (Pulse κ)) (a : Fin 2 → κ) + (ha : Pulse.control a ∈ w) (i : Fin 2) : a i ∈ labels w := by + classical + exact Finset.mem_biUnion.mpr ⟨Pulse.control a,List.mem_toFinset.mpr ha, + Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩⟩ + +theorem labels_tail (p : Pulse κ) (w : List (Pulse κ)) : labels w ⊆ labels (p::w) := by + classical + intro i hi + obtain ⟨q,hq,hi⟩ := Finset.mem_biUnion.mp hi + exact Finset.mem_biUnion.mpr ⟨q,List.mem_toFinset.mpr (List.mem_cons_of_mem p + (List.mem_toFinset.mp hq)),hi⟩ + +theorem run_congr_labels {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (K L : κ → H →L[ℂ] H) (w : List (Pulse κ)) + (hKL : ∀i∈labels w,K i=L i) : run K w=run L w := by + induction w with + | nil => rfl + | cons p w ih => + rw [run,run,ih (fun i hi => hKL i (labels_tail p w hi))] + congr 1 + cases p with + | root A => rfl + | control a => + change TensorPackets.diagonal (K ∘ a)=TensorPackets.diagonal (L ∘ a) + congr 1 + funext i + exact hKL (a i) (control_mem_labels _ a (by simp) i) + +def negClosure [DecidableEq κ] (neg : κ → κ) (S : Finset κ) : Finset κ := + S ∪ S.image neg + +theorem mem_negClosure [DecidableEq κ] (neg : κ → κ) (hn : Function.Involutive neg) + (S : Finset κ) (i : κ) : neg i ∈ negClosure neg S ↔ i ∈ negClosure neg S := by + have step (j : κ) : j ∈ negClosure neg S → neg j ∈ negClosure neg S := by + intro hj + rcases Finset.mem_union.mp hj with hj|hj + · exact Finset.mem_union_right _ (Finset.mem_image.mpr ⟨j,hj,rfl⟩) + · obtain ⟨k,hk,rfl⟩ := Finset.mem_image.mp hj + apply Finset.mem_union_left + simpa only [hn k] using hk + constructor + · intro hi + simpa only [hn i] using step (neg i) hi + · exact step i + +def mask [DecidableEq κ] {V : Type*} [Zero V] (S : Finset κ) (f : κ → V) (i : κ) : V := + if i∈S then f i else 0 + + + +theorem root_circuit_Gram_local_limit + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (ι : ℕ → Type*) [∀n,Fintype (ι n)] [∀n,DecidableEq (ι n)] [∀n,Nonempty (ι n)] + (Ω : ∀n,EuclideanSpace ℂ (ι n)) + (X : ∀n,κ → EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + (neg : κ → κ) (hn : Function.Involutive neg) (d : κ → E) (b : κ → ℝ) + (hb : ∀i,0≤b i) (hΩ : ∀n,‖Ω n‖=1) (hX : ∀n i,‖X n i‖≤b i) + (hneg : ∀n i,X n (neg i)= -X n i) (hstar : ∀n i,star (X n i)= -X n i) + (hdneg : ∀i,d (neg i)= -d i) + (hc : ∀n i,⟪Ω n,X n i (Ω n)⟫_ℂ=0) + (hq : ∀i j,Tendsto (fun n => ⟪Ω n,X n i (X n j (Ω n))⟫_ℂ) + atTop (𝓝 (-⟪d i,d j⟫_ℂ))) (u w : List (Pulse κ)) : + Tendsto (fun n => + ⟪run (tensorPulse n (X n)) u (PointedTree.plusEmbedding (FiniteTensor.power n (Ω n))), + run (tensorPulse n (X n)) w (PointedTree.plusEmbedding (FiniteTensor.power n (Ω n)))⟫_ℂ) + atTop (𝓝 ⟪run (W ∘ d) u (PointedTree.vacuum E),run (W ∘ d) w (PointedTree.vacuum E)⟫_ℂ) := by + classical + let S := negClosure neg (labels u ∪ labels w) + let L := ∑i∈S,b i + have hL : 0≤L := Finset.sum_nonneg (fun i hi => hb i) + have hxi (n : ℕ) (i : κ) : ‖mask S (X n) i‖≤L := by + by_cases hi : i∈S + · simp only [mask,ite_eq_left hi] + exact (hX n i).trans (Finset.single_le_sum (fun j hj => hb j) hi) + · simp only [mask,ite_eq_right hi,norm_zero]; exact hL + have hmn (n : ℕ) (i : κ) : mask S (X n) (neg i)= -mask S (X n) i := by + have hs := mem_negClosure neg hn (labels u ∪ labels w) i + by_cases hi : i∈S <;> simp [mask,hi,show neg i∈S ↔ i∈S from hs,hneg] + have hms (n : ℕ) (i : κ) : star (mask S (X n) i)= -mask S (X n) i := by + by_cases hi : i∈S + · simpa only [mask,ite_eq_left hi] using hstar n i + · simp only [mask,ite_eq_right hi,neg_zero] + exact star_zero (EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + have hdn (i : κ) : mask S d (neg i)= -mask S d i := by + have hs := mem_negClosure neg hn (labels u ∪ labels w) i + by_cases hi : i∈S <;> simp [mask,hi,show neg i∈S ↔ i∈S from hs,hdneg] + have hmc (n : ℕ) (i : κ) : ⟪Ω n,mask S (X n) i (Ω n)⟫_ℂ=0 := by + by_cases hi : i∈S <;> simp [mask,hi,hc] + have hmq (i j : κ) : Tendsto (fun n => ⟪Ω n,mask S (X n) i (mask S (X n) j (Ω n))⟫_ℂ) + atTop (𝓝 (-⟪mask S d i,mask S d j⟫_ℂ)) := by + by_cases hi : i∈S <;> by_cases hj : j∈S + · simpa only [mask,ite_eq_left hi,ite_eq_left hj] using hq i j + all_goals simp [mask,hi,hj] + have hsU : labels u ⊆ S := fun i hi => Finset.mem_union_left _ (Finset.mem_union_left _ hi) + have hsW : labels w ⊆ S := fun i hi => Finset.mem_union_left _ (Finset.mem_union_right _ hi) + have hnrun (n : ℕ) (v : List (Pulse κ)) (hv : labels v ⊆ S) : + run (tensorPulse n (mask S (X n))) v=run (tensorPulse n (X n)) v := by + apply run_congr_labels + intro i hi + simp only [tensorPulse,mask,ite_eq_left (hv hi)] + have hfrun (v : List (Pulse κ)) (hv : labels v ⊆ S) : + run (W ∘ mask S d) v=run (W ∘ d) v := by + apply run_congr_labels + intro i hi + simp only [Function.comp_apply,mask,ite_eq_left (hv hi)] + simpa only [hnrun _ _ hsU,hnrun _ _ hsW,hfrun _ hsU,hfrun _ hsW] using + root_circuit_Gram_limit ι Ω (fun n => mask S (X n)) neg (mask S d) L hL hΩ hxi hmn hms hdn hmc hmq u w + +end RootTensorCLT + + + +open scoped InnerProductSpace Topology +open Filter +namespace FiniteTree +open RootTensorCLT CoherentFock SpinOperators + +def insertion (D h : ℕ) (w : List PointedTree.Gate) : Space D h := + (ordinary D w h).observable (vac D h) + +def insertionProgram (w : List PointedTree.Gate) : List (Pulse Label) := + adjointProgram negateLabel (program w)++[.root RootSpin.Z]++program w + +@[simp] theorem childGenerator_neg (D h : ℕ) (i : Label) : + childGenerator D h (negateLabel i)= -childGenerator D h i := + (ordinary D i.1 h).generator_neg i.2 + +@[simp] theorem childGenerator_star (D h : ℕ) (i : Label) : + star (childGenerator D h i)= -childGenerator D h i := + (ordinary D i.1 h).generator_star i.2 + +@[simp] theorem childDirection_neg (h : ℕ) (i : Label) : + childDirection h (negateLabel i)= -childDirection h i := by + simp only [childDirection,negateLabel,Complex.ofReal_neg,neg_smul] + +theorem conj_split_ordinary (D h : ℕ) (w : List PointedTree.Gate) : + (split D (h+1)).conjStarAlgEquiv (ordinary D w (h+1)).op= + run (tensorPulse D (childGenerator D h)) (program w) := by + apply ContinuousLinearMap.ext + intro x + change split D (h+1) ((ordinary D w (h+1)).op ((split D (h+1)).symm x))=_ + simpa only [LinearIsometryEquiv.apply_symm_apply] using + split_ordinary D h w ((split D (h+1)).symm x) + +theorem split_ordinary_star (D h : ℕ) (w : List PointedTree.Gate) (x : Space D (h+1)) : + split D (h+1) (star (ordinary D w (h+1)).op x)= + star (run (tensorPulse D (childGenerator D h)) (program w)) (split D (h+1) x) := by + have hs : (split D (h+1)).conjStarAlgEquiv (star (ordinary D w (h+1)).op)= + star ((split D (h+1)).conjStarAlgEquiv (ordinary D w (h+1)).op) := + (split D (h+1)).conjStarAlgEquiv.map_star' (ordinary D w (h+1)).op + rw [conj_split_ordinary] at hs + have hv := congrArg (fun A : Double (Tail D (h+1)) →L[ℂ] Double (Tail D (h+1)) => A (split D (h+1) x)) hs + simpa only [LinearIsometryEquiv.conjStarAlgEquiv_apply_apply, + LinearIsometryEquiv.symm_apply_apply] using hv + +theorem split_insertion (D h : ℕ) (w : List PointedTree.Gate) : + split D (h+1) (insertion D (h+1) w)= + run (tensorPulse D (childGenerator D h)) (insertionProgram w) + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h))) := by + simp only [insertion,Even.observable,mul_apply_eq_comp] + rw [split_ordinary_star,split_root,split_ordinary] + simp only [vac,LinearIsometryEquiv.apply_symm_apply] + rw [insertionProgram,run_append,run_append,run_adjoint _ negateLabel + (tensorPulse_star D _ negateLabel (childGenerator_neg D h) (childGenerator_star D h)), + run_cons,run_nil,mul_one] + rfl + +theorem limiting_insertion (h : ℕ) (w : List PointedTree.Gate) : + ((PointedTree.ordinary w (h+1)).insertion : PointedTree.Level (h+1))= + run (W ∘ childDirection h) (insertionProgram w) (PointedTree.vac (h+1)) := by + have hs (i : Label) : (W ∘ childDirection h) (negateLabel i)=star ((W ∘ childDirection h) i) := by + simp only [Function.comp_apply,childDirection_neg,weyl_star] + rw [insertionProgram,run_append,run_append,run_adjoint _ negateLabel hs, + run_cons,run_nil,mul_one,←limiting_ordinary] + change (PointedTree.ordinary w (h+1)).op.symm + (act RootSpin.Z ((PointedTree.ordinary w (h+1)).op (PointedTree.vac (h+1))))=_ + rw [ContinuousLinearMap.star_eq_adjoint,LinearIsometryEquiv.adjoint_eq_symm] + rfl + +theorem insertion_zero (D : ℕ) (w : List PointedTree.Gate) : + insertion D 0 w=((PointedTree.ordinary w 0).insertion : PointedTree.Level 0) := by + simp only [insertion,Even.observable,ordinary_zero_level,mul_apply_eq_comp] + rw [ContinuousLinearMap.star_eq_adjoint,LinearIsometryEquiv.adjoint_eq_symm] + rfl + + + +theorem child_second_moment (D h : ℕ) (i j : Label) : + ⟪vac D h,childGenerator D h i (childGenerator D h j (vac D h))⟫_ℂ= + -((i.2:ℂ)*(j.2:ℂ))*⟪insertion D h i.1,insertion D h j.1⟫_ℂ := by + simp only [childGenerator,Even.generator,smul_apply,map_smul,inner_smul_right] + have hadj : ⟪vac D h,(ordinary D i.1 h).observable ((ordinary D j.1 h).observable (vac D h))⟫_ℂ= + ⟪insertion D h i.1,insertion D h j.1⟫_ℂ := by + rw [←ContinuousLinearMap.adjoint_inner_left,←ContinuousLinearMap.star_eq_adjoint, + Even.observable_star] + rfl + rw [hadj] + have hi : Complex.I*Complex.I= -1 := Complex.I_mul_I + calc + _ = (Complex.I*Complex.I)*((i.2:ℂ)*(j.2:ℂ))*⟪insertion D h i.1,insertion D h j.1⟫_ℂ := by ring + _ = _ := by rw [hi]; ring + +end FiniteTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/GenericDegrees.lean b/lean/OAI/Probability/ParisiFinite/GenericDegrees.lean new file mode 100644 index 0000000000000000000000000000000000000000..907d3537bd106398ce6539fa3bbdb5c12a1fa87a --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/GenericDegrees.lean @@ -0,0 +1,653 @@ +import Mathlib +import OAI.Probability.ParisiFinite.MixedReplicaIdentity + +namespace OAI + +/-! Generic Degrees. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + +def genericDegrees (n : ℕ) : Fin (powerCutoff n+1) → ℕ := Fin.val + +def genericMixedAmplitude (n : ℕ) (β : ℝ) : Fin (powerCutoff n+1) → ℝ := + if hn : 0 0 + +lemma genericMixedAmplitude_mem {n : ℕ} (hn : 0 f (fun l => τ l.castSucc)* + (overlap (τ i.castSucc) (τ (Fin.last r)))^p)- + averagedReplica A f*averagedReplica A + (fun τ : Fin 2 → Configuration n => (overlap (τ 0) (τ 1))^p)- + averagedReplica A (fun σ => f σ*∑ l∈Finset.univ.erase i, (overlap (σ i) (σ l))^p) + +lemma genericMixed_defect_le {n r : ℕ} (hn : 0 overlapGGDefect (genericMixedCoeff n β) p (i n) (f n)) atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + simp only [Real.norm_eq_abs] + refine squeeze_zero' (g:=fun n => (82+8*|β|)/allPowerRoot n^2) (Eventually.of_forall fun n => abs_nonneg _) ?_ ?_ + · filter_upwards [eventually_gt_atTop 0, tendsto_powerCutoff.eventually (eventually_ge_atTop p)] with n hn hp + exact genericMixed_defect_le hn β hp (i n) (f n) (hf n) + · have hr : Tendsto (fun n => (allPowerRoot n)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_allPowerRoot + simpa only [zero_pow (by decide : 2≠0), mul_zero, inv_pow, div_eq_mul_inv] using (hr.pow 2).const_mul (82+8*|β|) + +lemma tendsto_genericMixed_variance_density (β : ℝ) : + Tendsto (fun n => (∑ k, (genericMixedAmplitude n β k)^2)/(n:ℝ)) atTop (𝓝 0) := by + have hr : Tendsto (fun n => (allPowerRoot n)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_allPowerRoot + have hlim : Tendsto (fun n => 8/(allPowerRoot n^7)) atTop (𝓝 0) := by + simpa only [zero_pow (by decide : 7≠0), mul_zero, inv_pow, div_eq_mul_inv] using (hr.pow 7).const_mul 8 + refine squeeze_zero' (Eventually.of_forall (fun n => div_nonneg (Finset.sum_nonneg fun _ _ => sq_nonneg _) (Nat.cast_nonneg n))) ?_ hlim + filter_upwards [eventually_gt_atTop 0] with n hn + exact allPower_amplitude_variance_density hn _ (genericMixedAmplitude_mem hn β) + + + +theorem tendsto_genericMixed_pressureDensity_error (β : ℝ) : + Tendsto (fun n => (expected (genericMixedCoeff n β)- + expected (fun s e => β*skCoeff n s e))/(n:ℝ)) atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + simp only [Real.norm_eq_abs] + have hlim : Tendsto (fun n => Real.pi*((∑ k, (genericMixedAmplitude n β k)^2)/(n:ℝ))) atTop (𝓝 0) := by + simpa using (tendsto_genericMixed_variance_density β).const_mul Real.pi + refine squeeze_zero' (Eventually.of_forall fun n => abs_nonneg _) ?_ hlim + filter_upwards [eventually_gt_atTop 0] with n hn + rw [abs_div]; rw [abs_of_nonneg (show (0:ℝ) ≤ (n:ℝ) from Nat.cast_nonneg n)] + have h := div_le_div_of_nonneg_right (mixed_pressure_error hn (genericDegrees n) β (genericMixedAmplitude n β)) + (Nat.cast_nonneg n) + simpa only [genericMixedCoeff, mul_div_assoc] using h + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +lemma replicaMean_prefix {r s : ℕ} (h : r ≤ s) (x : ι → ℝ) (f : (Fin r → ι) → ℝ) : + replicaMean x (fun σ : Fin s → ι => f (fun i => σ (Fin.castLE h i)))=replicaMean x f := by + induction s, h using Nat.le_induction with + | base => simp + | succ s h ih => + have he : (fun σ : Fin (s+1) → ι => f (fun i => σ (Fin.castLE (Nat.le_succ_of_le h) i)))= + fun σ => (fun τ : Fin s → ι => f (fun i => τ (Fin.castLE h i))) (fun l => σ l.castSucc) := rfl + rw [he] + exact (replicaMean_marginal x (fun τ : Fin s → ι => f (fun i => τ (Fin.castLE h i)))).trans ih + +lemma averagedReplica_prefix {r s : ℕ} (h : r ≤ s) (A : ι → κ → ℝ) (f : (Fin r → ι) → ℝ) : + averagedReplica A (fun σ : Fin s → ι => f (fun i => σ (Fin.castLE h i)))=averagedReplica A f := by + simp only [averagedReplica, replicaMean_prefix h] + + +def fieldReplicaMass {r : ℕ} (A : ι → κ → ℝ) (σ : Fin r → ι) : ℝ := + ∫ z, replicaWeight (field A z) σ ∂gaussianLaw κ + +lemma fieldReplicaMass_nonneg {r : ℕ} (A : ι → κ → ℝ) (σ : Fin r → ι) : + 0 ≤ fieldReplicaMass A σ := integral_nonneg fun _ => replicaWeight_nonneg _ _ + +lemma sum_fieldReplicaMass (r : ℕ) (A : ι → κ → ℝ) : + (∑ σ : Fin r → ι, fieldReplicaMass A σ)=1 := by + unfold fieldReplicaMass + rw [← integral_finsetSum _ (fun σ _ => integrable_field_replicaWeight A σ)] + simp only [sum_replicaWeight] + simp + +def fieldOverlapLaw {n t : ℕ} (A : Configuration n → κ → ℝ) : ProbabilityMeasure OverlapArray := + finiteProbability (fun σ : Fin (t+1) → Configuration n => fieldReplicaMass A σ) + (fieldReplicaMass_nonneg A) (sum_fieldReplicaMass (t+1) A) configurationOverlap + +lemma integral_fieldOverlapLaw {n t : ℕ} (A : Configuration n → κ → ℝ) (f : OverlapArray → ℝ) : + (∫ R, f R ∂(fieldOverlapLaw (t:=t) A : Measure _))= + averagedReplica A (fun σ : Fin (t+1) → Configuration n => f (configurationOverlap σ)) := by + rw [fieldOverlapLaw, integral_finiteProbability] + unfold averagedReplica replicaMean + rw [integral_finsetSum _ (fun σ _ => (integrable_field_replicaWeight A σ).mul_const _)] + simp only [integral_mul_const, fieldReplicaMass] + +abbrev OverlapBlock (r : ℕ) := Fin r → Fin r → OverlapEntry + +def blockOfArray (r : ℕ) (R : OverlapArray) : OverlapBlock r := fun i j => R i j + +def blockOfReplicas {n r : ℕ} (σ : Fin r → Configuration n) : OverlapBlock r := + fun i j => ⟨overlap (σ i) (σ j), abs_le.mp (abs_overlap_le_one _ _)⟩ + +lemma continuous_blockOfArray (r : ℕ) : Continuous (blockOfArray r) := by + unfold blockOfArray + fun_prop + +lemma blockOfArray_configurationOverlap {n r t : ℕ} (h : r ≤ t+1) + (σ : Fin (t+1) → Configuration n) : + blockOfArray r (configurationOverlap σ)=blockOfReplicas (fun i => σ (Fin.castLE h i)) := by + funext i j + apply Subtype.ext + change overlap (extendReplicas σ i) (extendReplicas σ j)=_ + rw [show extendReplicas σ i=σ (Fin.castLE h i) from extendReplicas_eq σ (Fin.castLE h i), + show extendReplicas σ j=σ (Fin.castLE h j) from extendReplicas_eq σ (Fin.castLE h j)] + rfl + +lemma integral_fieldOverlapLaw_block {n r t : ℕ} (h : r ≤ t+1) + (A : Configuration n → κ → ℝ) (f : OverlapBlock r → ℝ) : + (∫ R, f (blockOfArray r R) ∂(fieldOverlapLaw (t:=t) A : Measure _))= + averagedReplica A (fun σ : Fin r → Configuration n => f (blockOfReplicas σ)) := by + rw [integral_fieldOverlapLaw] + simp_rw [blockOfArray_configurationOverlap h] + exact averagedReplica_prefix h A (fun σ => f (blockOfReplicas σ)) + + + +def genericOverlapLaw (n : ℕ) (β : ℝ) : ProbabilityMeasure OverlapArray := + fieldOverlapLaw (t:=n) (genericMixedCoeff n β) + +lemma genericOverlapLaw_Gram {n : ℕ} (hn : 0 genericOverlapLaw (φ k) β) atTop (𝓝 μ)) : + (μ : Measure _) GramArrays=1 := by + have h := ProbabilityMeasure.limsup_measure_closed_le_of_tendsto hμ isClosed_GramArrays + have he : ∀ᶠ k in atTop, (genericOverlapLaw (φ k) β : Measure _) GramArrays=(1:ℝ≥0∞) := + (hφ.tendsto_atTop.eventually (eventually_gt_atTop 0)).mono (fun _ hk => genericOverlapLaw_Gram hk β) + rw [limsup_congr he, limsup_const] at h + exact le_antisymm prob_le_one h + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +def arrayGGDefect (μ : ProbabilityMeasure OverlapArray) (r p : ℕ) (i : Fin r) + (f : OverlapBlock r → ℝ) : ℝ := + (r:ℝ)*(∫ R, f (blockOfArray r R)*(R i r : ℝ)^p ∂(μ : Measure OverlapArray)) - + (∫ R, f (blockOfArray r R) ∂(μ : Measure OverlapArray)) * + (∫ R, (R 0 1 : ℝ)^p ∂(μ : Measure OverlapArray)) - + (∫ R, f (blockOfArray r R)*∑ l∈Finset.univ.erase i, (R i l : ℝ)^p ∂(μ : Measure OverlapArray)) + +lemma continuous_arrayGGDefect (r p : ℕ) (i : Fin r) (f : C(OverlapBlock r, ℝ)) : + Continuous (fun μ => arrayGGDefect μ r p i f) := by + let f₁ : C(OverlapArray, ℝ) := ⟨fun R => f (blockOfArray r R)*(R i r : ℝ)^p, by unfold blockOfArray; fun_prop⟩ + let f₂ : C(OverlapArray, ℝ) := ⟨fun R => f (blockOfArray r R), by unfold blockOfArray; fun_prop⟩ + let f₃ : C(OverlapArray, ℝ) := ⟨fun R => (R 0 1 : ℝ)^p, by fun_prop⟩ + let f₄ : C(OverlapArray, ℝ) := ⟨fun R => f (blockOfArray r R)*∑ l∈Finset.univ.erase i, (R i l : ℝ)^p, by unfold blockOfArray; fun_prop⟩ + exact ((ProbabilityMeasure.continuous_integral_continuousMap f₁).const_mul r).sub + ((ProbabilityMeasure.continuous_integral_continuousMap f₂).mul + (ProbabilityMeasure.continuous_integral_continuousMap f₃)) |>.sub + (ProbabilityMeasure.continuous_integral_continuousMap f₄) + +lemma arrayGGDefect_fieldOverlapLaw {n t r : ℕ} (hr : r+1 ≤ t+1) (h₂ : 2 ≤ t+1) + {κ : Type*} [Fintype κ] (A : Configuration n → κ → ℝ) + (p : ℕ) (i : Fin r) (f : OverlapBlock r → ℝ) : + arrayGGDefect (fieldOverlapLaw (t:=t) A) r p i f= + overlapGGDefect A p i (fun σ => f (blockOfReplicas σ)) := by + have h₁ := integral_fieldOverlapLaw_block hr A + (fun T : OverlapBlock (r+1) => f (fun a b => T a.castSucc b.castSucc)*(T i.castSucc (Fin.last r) : ℝ)^p) + have h₂' := integral_fieldOverlapLaw_block (Nat.le_trans (Nat.le_succ r) hr) A f + have h₃ := integral_fieldOverlapLaw_block h₂ A (fun T : OverlapBlock 2 => (T 0 1 : ℝ)^p) + have h₄ := integral_fieldOverlapLaw_block (Nat.le_trans (Nat.le_succ r) hr) A + (fun T : OverlapBlock r => f T*∑ l∈Finset.univ.erase i, (T i l : ℝ)^p) + change (∫ R, f (blockOfArray r R)*(R i r : ℝ)^p ∂(fieldOverlapLaw (t:=t) A : Measure OverlapArray)) = + averagedReplica A (fun σ : Fin (r+1) → Configuration n => + f (blockOfReplicas (fun l => σ l.castSucc))*(overlap (σ i.castSucc) (σ (Fin.last r)))^p) at h₁ + change (∫ R, (R 0 1 : ℝ)^p ∂(fieldOverlapLaw (t:=t) A : Measure OverlapArray)) = + averagedReplica A (fun σ : Fin 2 → Configuration n => (overlap (σ 0) (σ 1))^p) at h₃ + change (∫ R, f (blockOfArray r R)*∑ l∈Finset.univ.erase i, (R i l : ℝ)^p + ∂(fieldOverlapLaw (t:=t) A : Measure OverlapArray)) = + averagedReplica A (fun σ : Fin r → Configuration n => + f (blockOfReplicas σ)*∑ l∈Finset.univ.erase i, (overlap (σ i) (σ l))^p) at h₄ + unfold arrayGGDefect overlapGGDefect + rw [h₁, h₂', h₃, h₄] + + + +theorem genericOverlap_limit_GG (β : ℝ) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ)) + (r p : ℕ) (i : Fin r) (f : C(OverlapBlock r, ℝ)) (hf : ∀ R, |f R| ≤ 1) : + arrayGGDefect μ r p i f=0 := by + have hz := (tendsto_genericMixed_GG_defect p β (fun _ => r) (fun _ => i) + (fun _ σ => f (blockOfReplicas σ)) (fun _ σ => hf _)).comp hφ.tendsto_atTop + have he : ∀ᶠ k in atTop, + overlapGGDefect (genericMixedCoeff (φ k) β) p i (fun σ => f (blockOfReplicas σ))= + arrayGGDefect (genericOverlapLaw (φ k) β) r p i f := by + filter_upwards [hφ.tendsto_atTop.eventually (eventually_ge_atTop (max r 1))] with k hk + exact (arrayGGDefect_fieldOverlapLaw (by omega) (by omega) _ p i f).symm + have hz' := hz.congr' he + exact tendsto_nhds_unique ((continuous_arrayGGDefect r p i f).tendsto μ |>.comp hμ) hz' + + + +theorem exists_generic_GG_Gram_limit (β : ℝ) : + ∃ μ : ProbabilityMeasure OverlapArray, + (μ : Measure OverlapArray) GramArrays=1 ∧ + (∀ (r p : ℕ) (i : Fin r) (f : C(OverlapBlock r, ℝ)), + (∀ R, |f R| ≤ 1) → arrayGGDefect μ r p i f=0) ∧ + ∃ φ : ℕ → ℕ, StrictMono φ ∧ Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ) := by + obtain ⟨μ,φ,hφ,hμ⟩ := CompactSpace.tendsto_subseq (fun n => genericOverlapLaw n β) + exact ⟨μ,genericOverlap_limit_Gram β hφ hμ,fun r p i f hf => genericOverlap_limit_GG β hφ hμ r p i f hf,φ,hφ,hμ⟩ + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma integrable_continuousMap {X : Type*} [TopologicalSpace X] [MeasurableSpace X] + [OpensMeasurableSpace X] [CompactSpace X] (μ : Measure X) [IsFiniteMeasure μ] (f : C(X,ℝ)) : + Integrable f μ := + Integrable.of_bound f.continuous.aestronglyMeasurable ‖f‖ (ae_of_all _ f.norm_coe_le_norm) + + +def continuousIntegral {X : Type*} [TopologicalSpace X] [MeasurableSpace X] + [OpensMeasurableSpace X] [CompactSpace X] (μ : ProbabilityMeasure X) : C(X,ℝ) →L[ℝ] ℝ := + LinearMap.mkContinuous + { toFun := fun f => ∫ x, f x ∂(μ : Measure X) + map_add' := fun f g => integral_add (integrable_continuousMap _ f) (integrable_continuousMap _ g) + map_smul' := fun c f => integral_smul c f } 1 (by + intro f + simpa using norm_integral_le_of_norm_le_const (μ:=(μ:Measure X)) (ae_of_all _ f.norm_coe_le_norm)) + + +def overlapIntegral (μ : ProbabilityMeasure OverlapArray) (f : C(OverlapArray,ℝ)) + (i j : ℕ) : C(OverlapEntry,ℝ) →L[ℝ] ℝ := + (continuousIntegral μ).comp ((ContinuousLinearMap.mul ℝ C(OverlapArray,ℝ) f).comp + (ContinuousMap.compCLM ℝ ℝ ⟨fun R => R i j, by fun_prop⟩)) + +@[simp] lemma overlapIntegral_apply (μ : ProbabilityMeasure OverlapArray) + (f : C(OverlapArray,ℝ)) (i j : ℕ) (ψ : C(OverlapEntry,ℝ)) : + overlapIntegral μ f i j ψ=∫ R, f R*ψ (R i j) ∂(μ : Measure OverlapArray) := rfl + + + +def continuousGG (μ : ProbabilityMeasure OverlapArray) (r : ℕ) (i : Fin r) + (f : C(OverlapBlock r,ℝ)) : C(OverlapEntry,ℝ) →L[ℝ] ℝ := + let F : C(OverlapArray,ℝ) := f.comp ⟨blockOfArray r, continuous_blockOfArray r⟩ + (r:ℝ) • overlapIntegral μ F i r - continuousIntegral μ F • overlapIntegral μ 1 0 1 - + ∑ l∈Finset.univ.erase i, overlapIntegral μ F i l + +def overlapPower (p : ℕ) : C(OverlapEntry,ℝ) := ⟨fun x => (x:ℝ)^p, by fun_prop⟩ + +lemma continuousGG_power (μ : ProbabilityMeasure OverlapArray) (r p : ℕ) (i : Fin r) + (f : C(OverlapBlock r,ℝ)) : continuousGG μ r i f (overlapPower p)=arrayGGDefect μ r p i f := by + unfold continuousGG arrayGGDefect + simp only [sub_apply, smul_apply, + sum_apply, overlapIntegral_apply, ContinuousMap.one_apply, + one_mul, smul_eq_mul] + congr 1 + simp_rw [Finset.mul_sum] + exact (integral_finsetSum (Finset.univ.erase i) (fun (l : Fin r) _ => integrable_continuousMap (μ:Measure OverlapArray) + ⟨fun R => f (blockOfArray r R)*(R i l : ℝ)^p, by unfold blockOfArray; fun_prop⟩)).symm + +lemma arrayGGDefect_const_mul (μ : ProbabilityMeasure OverlapArray) (r p : ℕ) (i : Fin r) + (f : OverlapBlock r → ℝ) (c : ℝ) : + arrayGGDefect μ r p i (fun R => c*f R)=c*arrayGGDefect μ r p i f := by + unfold arrayGGDefect + simp only [mul_assoc, integral_const_mul] + ring + +lemma genericOverlap_limit_GG_unbounded (β : ℝ) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ)) + (r p : ℕ) (i : Fin r) (f : C(OverlapBlock r,ℝ)) : arrayGGDefect μ r p i f=0 := by + let M : ℝ := ‖f‖+1 + have hm : 0 M⁻¹*f R)=0 at h + rw [arrayGGDefect_const_mul] at h + exact (mul_eq_zero.mp h).resolve_left (inv_ne_zero hm.ne') + + +theorem genericOverlap_limit_continuousGG (β : ℝ) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ)) + (r : ℕ) (i : Fin r) (f : C(OverlapBlock r,ℝ)) (ψ : C(OverlapEntry,ℝ)) : + continuousGG μ r i f ψ=0 := by + let L := continuousGG μ r i f + have hp (p : ℕ) : L (overlapPower p)=0 := by + rw [continuousGG_power] + exact genericOverlap_limit_GG_unbounded β hφ hμ r p i f + have hpoly (p : Polynomial ℝ) : L (p.toContinuousMapOn (Set.Icc (-1:ℝ) 1))=0 := by + induction p using Polynomial.induction_on' with + | add p q hp hq => + have he : (p+q).toContinuousMapOn (Set.Icc (-1:ℝ) 1)=p.toContinuousMapOn _+q.toContinuousMapOn _ := by + ext x; simp [Polynomial.toContinuousMapOn] + rw [he, map_add, hp, hq, add_zero] + | monomial p a => + have he : (Polynomial.monomial p a).toContinuousMapOn (Set.Icc (-1:ℝ) 1)=a • overlapPower p := by + ext x; simp [Polynomial.toContinuousMapOn, overlapPower] + rw [he, map_smul, hp, smul_zero] + have hs : (polynomialFunctions (Set.Icc (-1:ℝ) 1) : Set C(OverlapEntry,ℝ)) ⊆ {g | L g=0} := by + intro g hg + rw [polynomialFunctions_coe] at hg + rcases hg with ⟨p,rfl⟩ + exact hpoly p + have hc := closure_minimal hs (isClosed_eq L.continuous continuous_const) + exact hc (continuousMap_mem_polynomialFunctions_closure (-1) 1 ψ) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + +def blockOverlapMap (r : ℕ) (i j : ℕ) (R : OverlapArray) : OverlapBlock r × OverlapEntry := + (blockOfArray r R, R i j) + +lemma continuous_blockOverlapMap (r : ℕ) (i j : ℕ) : Continuous (blockOverlapMap r i j) := + (continuous_blockOfArray r).prodMk (by fun_prop) + +def jointOverlapLaw (μ : ProbabilityMeasure OverlapArray) (r : ℕ) (i j : ℕ) : + Measure (OverlapBlock r × OverlapEntry) := (μ : Measure OverlapArray).map (blockOverlapMap r i j) + +instance instIsFiniteJointOverlapLaw (μ : ProbabilityMeasure OverlapArray) (r : ℕ) (i j : ℕ) : + IsFiniteMeasure (jointOverlapLaw μ r i j) := by unfold jointOverlapLaw; infer_instance + +lemma integral_jointOverlapLaw (μ : ProbabilityMeasure OverlapArray) (r : ℕ) (i j : ℕ) + (f : C(OverlapBlock r,ℝ)) (ψ : C(OverlapEntry,ℝ)) : + (∫ z, f z.1*ψ z.2 ∂jointOverlapLaw μ r i j)=overlapIntegral μ + (f.comp ⟨blockOfArray r,continuous_blockOfArray r⟩) i j ψ := by + rw [jointOverlapLaw, integral_map (continuous_blockOverlapMap r i j).measurable.aemeasurable + (show AEStronglyMeasurable (fun z : OverlapBlock r × OverlapEntry => f z.1*ψ z.2) + ((μ:Measure _).map (blockOverlapMap r i j)) from (by fun_prop : Continuous _).aestronglyMeasurable)] + rfl + +def blockLaw (μ : ProbabilityMeasure OverlapArray) (r : ℕ) : Measure (OverlapBlock r) := + (μ : Measure OverlapArray).map (blockOfArray r) + +def entryLaw (μ : ProbabilityMeasure OverlapArray) (i j : ℕ) : Measure OverlapEntry := + (μ : Measure OverlapArray).map (fun R => R i j) + +instance instIsFiniteBlockLaw (μ : ProbabilityMeasure OverlapArray) (r : ℕ) : + IsFiniteMeasure (blockLaw μ r) := by unfold blockLaw; infer_instance +instance instIsFiniteEntryLaw (μ : ProbabilityMeasure OverlapArray) (i j : ℕ) : + IsFiniteMeasure (entryLaw μ i j) := by unfold entryLaw; infer_instance + +lemma integral_blockLaw (μ : ProbabilityMeasure OverlapArray) (r : ℕ) + (f : C(OverlapBlock r,ℝ)) : + (∫ z, f z ∂blockLaw μ r)=continuousIntegral μ (f.comp ⟨blockOfArray r,continuous_blockOfArray r⟩) := by + rw [blockLaw, integral_map (continuous_blockOfArray r).measurable.aemeasurable f.continuous.aestronglyMeasurable] + rfl + +lemma integral_entryLaw (μ : ProbabilityMeasure OverlapArray) (i j : ℕ) + (ψ : C(OverlapEntry,ℝ)) : (∫ z, ψ z ∂entryLaw μ i j)=overlapIntegral μ 1 i j ψ := by + rw [entryLaw, integral_map (by fun_prop : Measurable (fun R : OverlapArray => R i j)).aemeasurable + ψ.continuous.aestronglyMeasurable, overlapIntegral_apply] + simp + + + +theorem GG_measure_identity (μ : ProbabilityMeasure OverlapArray) (r : ℕ) (i : Fin r) + (h : ∀ (f : C(OverlapBlock r,ℝ)) (ψ : C(OverlapEntry,ℝ)), continuousGG μ r i f ψ=0) : + (r:ℝ≥0∞) • jointOverlapLaw μ r i r = + (blockLaw μ r).prod (entryLaw μ 0 1)+∑ l∈Finset.univ.erase i, jointOverlapLaw μ r i l := by + let : IsFiniteMeasure ((r:ℝ≥0∞) • jointOverlapLaw μ r i r) := Measure.smul_finite _ (by finiteness) + apply Measure.ext_of_integral_mul_boundedContinuousFunction + intro f ψ + let F : C(OverlapBlock r × OverlapEntry,ℝ) := ⟨fun z => f z.1*ψ z.2, by fun_prop⟩ + have hi (ν : Measure (OverlapBlock r × OverlapEntry)) [IsFiniteMeasure ν] : + Integrable (fun z => f z.1*ψ z.2) ν := integrable_continuousMap ν F + rw [integral_smul_measure, integral_add_measure (hi _) (hi _), + integral_finsetSum_measure (fun l _ => hi _), integral_prod_mul] + have hj (j : ℕ) := integral_jointOverlapLaw μ r i j f.toContinuousMap ψ.toContinuousMap + change ∀ j, (∫ z, f z.1*ψ z.2 ∂jointOverlapLaw μ r i j)=_ at hj + have hb := integral_blockLaw μ r f.toContinuousMap + change (∫ z, f z ∂blockLaw μ r)=_ at hb + have he := integral_entryLaw μ 0 1 ψ.toContinuousMap + change (∫ z, ψ z ∂entryLaw μ 0 1)=_ at he + simp_rw [hj, hb, he] + have hz := h f.toContinuousMap ψ.toContinuousMap + unfold continuousGG at hz + simp only [sub_apply, smul_apply, + sum_apply, smul_eq_mul] at hz + simp only [ENNReal.toReal_natCast, smul_eq_mul] + linarith + + + +theorem genericOverlap_limit_measureGG (β : ℝ) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ)) + (r : ℕ) (i : Fin r) : + (r:ℝ≥0∞) • jointOverlapLaw μ r i r = + (blockLaw μ r).prod (entryLaw μ 0 1)+∑ l∈Finset.univ.erase i, jointOverlapLaw μ r i l := + GG_measure_identity μ r i (genericOverlap_limit_continuousGG β hφ hμ r i) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +omit [Nonempty ι] in +lemma replicaWeight_perm {r : ℕ} (x : ι → ℝ) (e : Equiv.Perm (Fin r)) (σ : Fin r → ι) : + replicaWeight x (fun i => σ (e i))=replicaWeight x σ := + Equiv.prod_comp e (fun i => weight x (σ i)) + +omit [Nonempty ι] in +lemma replicaMean_perm {r : ℕ} (x : ι → ℝ) (e : Equiv.Perm (Fin r)) (f : (Fin r → ι) → ℝ) : + replicaMean x (fun σ => f (fun i => σ (e i)))=replicaMean x f := by + let E : (Fin r → ι) ≃ (Fin r → ι) := Equiv.arrowCongr e.symm (Equiv.refl ι) + have he (σ : Fin r → ι) : E σ=fun i => σ (e i) := rfl + unfold replicaMean + calc + _ = ∑ σ, replicaWeight x (E σ)*f (E σ) := by + apply Finset.sum_congr rfl + intro σ _ + rw [he,replicaWeight_perm] + _ = _ := E.sum_comp (fun σ => replicaWeight x σ*f σ) + +lemma replicaMean_injection {r s : ℕ} (h : r ≤ s) (e : Fin r → Fin s) (he : Function.Injective e) + (x : ι → ℝ) (f : (Fin r → ι) → ℝ) : + replicaMean x (fun σ : Fin s → ι => f (fun i => σ (e i)))=replicaMean x f := by + obtain ⟨q,hq⟩ := Equiv.Perm.exists_extending_pair (Fin.castLE h) e (Fin.castLE_injective h) he + have hh := replicaMean_perm x q (fun σ : Fin s → ι => f (fun i => σ (Fin.castLE h i))) + simp only [hq] at hh + exact hh.trans (replicaMean_prefix h x f) + +lemma averagedReplica_injection {r s : ℕ} (h : r ≤ s) (e : Fin r → Fin s) (he : Function.Injective e) + (A : ι → κ → ℝ) (f : (Fin r → ι) → ℝ) : + averagedReplica A (fun σ : Fin s → ι => f (fun i => σ (e i)))=averagedReplica A f := by + simp only [averagedReplica, replicaMean_injection h e he] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def selectedBlock {r : ℕ} (e : Fin r → ℕ) (R : OverlapArray) : OverlapBlock r := + fun i j => R (e i) (e j) + +lemma continuous_selectedBlock {r : ℕ} (e : Fin r → ℕ) : Continuous (selectedBlock e) := by + unfold selectedBlock + fun_prop + +lemma integral_fieldOverlapLaw_selected {n t r : ℕ} (hr : r ≤ t+1) + (e : Fin r → ℕ) (he : Function.Injective e) (ht : ∀ i, e i f (blockOfReplicas σ)) := by + let e' : Fin r → Fin (t+1) := fun i => ⟨e i,ht i⟩ + have he' : Function.Injective e' := fun a b h => he (congrArg Fin.val h) + rw [integral_fieldOverlapLaw] + have hh (σ : Fin (t+1) → Configuration n) : + selectedBlock e (configurationOverlap σ)=blockOfReplicas (fun i => σ (e' i)) := by + funext i j + apply Subtype.ext + change overlap (extendReplicas σ (e' i)) (extendReplicas σ (e' j))=_ + simp only [extendReplicas_eq] + rfl + simp_rw [hh] + exact averagedReplica_injection hr e' he' A (fun σ => f (blockOfReplicas σ)) + +lemma genericOverlap_limit_exchangeable_integral (β : ℝ) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ)) + (r : ℕ) (e : Fin r → ℕ) (he : Function.Injective e) (f : C(OverlapBlock r,ℝ)) : + (∫ R, f (selectedBlock e R) ∂(μ : Measure OverlapArray))= + ∫ R, f (blockOfArray r R) ∂(μ : Measure OverlapArray) := by + let F : C(OverlapArray,ℝ) := f.comp ⟨selectedBlock e,continuous_selectedBlock e⟩ + let G : C(OverlapArray,ℝ) := f.comp ⟨blockOfArray r,continuous_blockOfArray r⟩ + have hF := (ProbabilityMeasure.continuous_integral_continuousMap F).tendsto μ |>.comp hμ + have hG := (ProbabilityMeasure.continuous_integral_continuousMap G).tendsto μ |>.comp hμ + have ha : ∀ᶠ k in atTop, + (∫ R, F R ∂(genericOverlapLaw (φ k) β : Measure OverlapArray))= + ∫ R, G R ∂(genericOverlapLaw (φ k) β : Measure OverlapArray) := by + filter_upwards [hφ.tendsto_atTop.eventually (eventually_ge_atTop (max r (∑ i,e i)))] with k hk + have hr : r ≤ φ k+1 := by omega + have ht (i : Fin r) : e i<φ k+1 := by + have h := Finset.single_le_sum (fun j _ => Nat.zero_le (e j)) (Finset.mem_univ i) + omega + change (∫ R, f (selectedBlock e R) ∂(fieldOverlapLaw (t:=φ k) (genericMixedCoeff (φ k) β) : Measure _))=_ + rw [integral_fieldOverlapLaw_selected hr e he ht] + exact (integral_fieldOverlapLaw_block hr _ f).symm + exact tendsto_nhds_unique (hF.congr' ha) hG + + +theorem genericOverlap_limit_exchangeable (β : ℝ) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ)) + (r : ℕ) (e : Fin r → ℕ) (he : Function.Injective e) : + (μ : Measure OverlapArray).map (selectedBlock e)=blockLaw μ r := by + apply ext_of_forall_integral_eq_of_IsFiniteMeasure + intro f + rw [integral_map (continuous_selectedBlock e).measurable.aemeasurable f.continuous.aestronglyMeasurable, + blockLaw, integral_map (continuous_blockOfArray r).measurable.aemeasurable f.continuous.aestronglyMeasurable] + exact genericOverlap_limit_exchangeable_integral β hφ hμ r e he f.toContinuousMap + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + +def GGIdentities (μ : ProbabilityMeasure OverlapArray) : Prop := + ∀ (r : ℕ) (i : Fin r), (r:ℝ≥0∞) • jointOverlapLaw μ r i r = + (blockLaw μ r).prod (entryLaw μ 0 1)+∑ l∈Finset.univ.erase i, jointOverlapLaw μ r i l + +theorem genericOverlap_limit_GGIdentities (β : ℝ) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ)) : GGIdentities μ := + genericOverlap_limit_measureGG β hφ hμ + +lemma GG_event_identity {μ : ProbabilityMeasure OverlapArray} (h : GGIdentities μ) + (r : ℕ) (i : Fin r) (B : Set (OverlapBlock r)) (A : Set OverlapEntry) + (hB : MeasurableSet B) (hA : MeasurableSet A) : + (r:ℝ)*(μ : Measure OverlapArray).real {R | blockOfArray r R∈B ∧ R i r∈A}= + (μ : Measure OverlapArray).real ((blockOfArray r) ⁻¹' B)*(entryLaw μ 0 1).real A+ + ∑ l∈Finset.univ.erase i, (μ : Measure OverlapArray).real {R | blockOfArray r R∈B ∧ R i l∈A} := by + have he := congrArg (fun ν : Measure (OverlapBlock r × OverlapEntry) => ν (B ×ˢ A)) (h r i) + rw [Measure.smul_apply, Measure.add_apply, Measure.prod_prod, + Measure.finsetSum_apply] at he + simp only [smul_eq_mul] at he + have hj (j : ℕ) : jointOverlapLaw μ r i j (B ×ˢ A)= + (μ : Measure OverlapArray) {R | blockOfArray r R∈B ∧ R i j∈A} := by + rw [jointOverlapLaw, Measure.map_apply (continuous_blockOverlapMap r i j).measurable (hB.prod hA)] + rfl + simp_rw [hj] at he + rw [blockLaw, Measure.map_apply (continuous_blockOfArray r).measurable hB] at he + have he' := congrArg ENNReal.toReal he + rw [ENNReal.toReal_mul, ENNReal.toReal_natCast, ENNReal.toReal_add (by finiteness) (by + exact ENNReal.sum_ne_top.mpr (fun l hl => measure_ne_top _ _)), + ENNReal.toReal_mul, ENNReal.toReal_sum (by intro l hl; finiteness)] at he' + exact he' + +lemma entryLaw_probability (μ : ProbabilityMeasure OverlapArray) (i j : ℕ) : + IsProbabilityMeasure (entryLaw μ i j) := by + unfold entryLaw + infer_instance + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/GlobalDyadicFieldError.lean b/lean/OAI/Probability/ParisiFinite/GlobalDyadicFieldError.lean new file mode 100644 index 0000000000000000000000000000000000000000..0e19ba3b83944b9f173ea6ef1de8177ceb7028de --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/GlobalDyadicFieldError.lean @@ -0,0 +1,652 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Splice + +namespace OAI + +/-! Global Dyadic Field Error. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +lemma global_dyadic_field_error (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (r : ℝ≥0) (hr : r<1) (n : ℕ) (x : ℝ) : + |(finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 r).val x-field β γ r x| ≤ + (β:ℝ)*dyadicMesh 1 n := by + have hh := dyadic_suffix_value_error β hβ hγ hb 0 1 n r hr x + rw [←zero_add (r:ℝ),finiteTimeField_suffix_val] + simpa only [zero_add,field] using hh + +lemma global_dyadic_field_tendstoUniformly (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (r : ℝ≥0) (hr : r<1) : + TendstoUniformly (fun n => (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 r).val) + (field β γ r) atTop := by + have he : Tendsto (fun n => (β:ℝ)*(dyadicMesh 1 n:ℝ)) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero] using (dyadicMesh_tendsto 1).const_mul (β:ℝ) + rw [Metric.tendstoUniformly_iff] + intro ε hε + filter_upwards [he.eventually (gt_mem_nhds hε)] with n hn x + rw [Real.dist_eq,abs_sub_comm] + exact (global_dyadic_field_error β hβ hγ hb r hr n x).trans_lt hn + +lemma global_dyadic_gradient_tendstoUniformly (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (r : ℝ≥0) (hr : r<1) : + TendstoUniformly (fun n => (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 r).d1) + (fieldGradient β γ r) atTop := by + obtain ⟨m,hu,hd,_,_⟩ := exists_uniform_derivative_limit + (fun n => finiteTimeField_curvature β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) 0 r) + (global_dyadic_field_tendstoUniformly β hβ hγ hb r hr) + have he : m=fieldGradient β γ r := funext fun x => (hd x).deriv.symm + rwa [he] at hu + +lemma finiteTimeCoefficient_scheduleValue (ls : Schedule) (s : ℝ) (r : ℝ≥0) : + finiteTimeCoefficient ls s (s+r)=(scheduleValue ls r:ℝ) := by + induction ls generalizing s r with + | nil => rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + have hc : s+(r:ℝ) + refine ⟨t,?_,le_add_of_nonneg_right zero_le,?_⟩ + · simp [dyadicSchedule,scheduleValue,hr] + · simpa only [dyadicMesh,pow_zero,div_one] using add_le_add_right hr.le t + | succ n ih => + simp only [dyadicSchedule] + by_cases hrd : r scheduleValue (dyadicSchedule γ false t d n) r) atTop (𝓝 (γ (t+r))) := by + choose y hy hlo hhi using fun n => dyadicSchedule_low_sample γ t d n r hr + have ht : Tendsto y atTop (𝓝 (t+r)) := by + rw [←NNReal.tendsto_coe] + apply tendsto_of_tendsto_of_tendsto_of_le_of_le + (by simpa only [sub_zero] using (tendsto_const_nhds.sub (dyadicMesh_tendsto d))) + tendsto_const_nhds + · intro n + have hh : (t+r:ℝ≥0) ≤ (y n:ℝ)+(dyadicMesh d n:ℝ) := by exact_mod_cast hhi n + linarith + · intro n; exact_mod_cast hlo n + simpa only [hy,Function.comp_def] using hc.tendsto.comp ht + +lemma dyadicSchedule_low_value_coe_tendsto (γ : ℝ≥0 → ℝ≥0) (t d r : ℝ≥0) + (hr : r (γ (Real.toNNReal s):ℝ)) (t+r:ℝ≥0)) : + Tendsto (fun n => (scheduleValue (dyadicSchedule γ false t d n) r:ℝ)) + atTop (𝓝 (γ (t+r):ℝ)) := by + have hc' : ContinuousAt γ (t+r) := by + change Tendsto γ (𝓝 (t+r)) (𝓝 (γ (t+r))) + rw [←NNReal.tendsto_coe] + simpa only [Function.comp_def,Real.toNNReal_coe] using + (hc.comp NNReal.continuous_coe.continuousAt).tendsto + exact NNReal.continuous_coe.continuousAt.tendsto.comp + (dyadicSchedule_low_value_tendsto γ t d r hr hc') + +lemma global_dyadic_coefficient_tendsto_ae {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) : + ∀ᵐ t ∂volume,t ∈ Ioo (0:ℝ) 1 → + Tendsto (fun n => finiteTimeCoefficient (dyadicSchedule γ false 0 1 n) 0 t) + atTop (𝓝 (γ (Real.toNNReal t):ℝ)) := by + let c (s : ℝ) : ℝ := γ (Real.toNNReal s) + have hm : Monotone c := fun s t h => + NNReal.coe_le_coe.mpr (hγ (Real.toNNReal_le_toNNReal h)) + have hc : ∀ᵐ t ∂volume,ContinuousAt c t := by + rw [ae_iff] + exact hm.countable_not_continuousAt.measure_zero volume + filter_upwards [hc] with t ht hmem + have hr : Real.toNNReal t < 1 := by + exact_mod_cast (show (Real.toNNReal t:ℝ)<1 by rw [Real.coe_toNNReal _ hmem.1.le];exact hmem.2) + have hh := dyadicSchedule_low_value_coe_tendsto γ 0 1 (Real.toNNReal t) hr + (by simpa only [zero_add,Real.coe_toNNReal _ hmem.1.le,c] using ht) + simpa only [zero_add,←finiteTimeCoefficient_scheduleValue _ (0:ℝ), + Real.coe_toNNReal _ hmem.1.le] using hh + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath + +namespace ThirdJet +variable {f : SmoothField} + +lemma continuous_transformD3_joint (j : ThirdJet f) (a : ℝ) : + Continuous (fun p : ℝ×ℝ => j.transformD3 a p.1 p.2) := by + have hb : ∀ y,|j.expThird a y|≤ + (j.bound3+3*Real.nnabs a*(f.bound1*f.bound2)+(Real.nnabs a)^2*f.bound1^3:ℝ≥0) := by + intro y + simpa only [NNReal.coe_add,NNReal.coe_mul,NNReal.coe_ofNat,Real.coe_nnabs, + NNReal.coe_pow,sq_abs] using j.expThird_bound a y + exact ((continuous_tiltedMean_joint f.lipschitz (j.continuous_expThird a) hb a).sub + (((continuous_transform_d1 f a).mul (continuous_transform_d2 f a)).const_mul (3*a))).sub + (((continuous_transform_d1 f a).pow 3).const_mul (a^2)) + +def slabD3 (j : ThirdJet f) (a b t x : ℝ) : ℝ := + j.transformD3 a (Real.sqrt (b-t)) x + +lemma continuous_slabD3 (j : ThirdJet f) (a b : ℝ) : + Continuous (uncurry (j.slabD3 a b)) := + (j.continuous_transformD3_joint a).comp + (((continuous_const.sub continuous_fst).sqrt).prodMk continuous_snd) + +lemma slabD3_bound (j : ThirdJet f) (a b t x : ℝ) : + |j.slabD3 a b t x|≤(j.transform a 0).bound3 := + (j.transform a (Real.sqrt (b-t))).normD3 x + +def gradientDt (j : ThirdJet f) (a b t x : ℝ) : ℝ := + if t first | exact (fieldOnInterval f a b t).normD1 x | exact (fieldOnInterval f a b t).normD2 x + have hh := (abs_add_le _ _).trans (add_le_add (j.slabD3_bound a b t x) hp) + simp only [gradientTimeBound,NNReal.coe_div,NNReal.coe_add,NNReal.coe_mul, + NNReal.coe_ofNat,Real.coe_nnabs] + linarith + · simp + +lemma measurable_gradientDt (j : ThirdJet f) (a b : ℝ) : + Measurable (uncurry (j.gradientDt a b)) := + Measurable.ite (measurableSet_lt measurable_fst measurable_const) + (((j.continuous_slabD3 a b).add + (((continuous_fieldOnInterval_d1 f a b).const_mul (2*a)).mul + (continuous_fieldOnInterval_d2 f a b))).const_mul (-(1/2:ℝ))).measurable + measurable_const + +lemma continuous_gradientDt (j : ThirdJet f) (a b t : ℝ) : + Continuous (j.gradientDt a b t) := by + unfold gradientDt + split_ifs + · exact (((j.continuous_slabD3 a b).comp (continuous_const.prodMk continuous_id)).add + (((fieldOnInterval f a b t).continuousD1.const_mul (2*a)).mul + (fieldOnInterval f a b t).continuousD2)).const_mul _ + · exact continuous_const + +lemma hasDerivAt_fieldOnInterval_dt (j : ThirdJet f) (a b t x : ℝ) : + HasDerivAt (fieldOnInterval_dt f a b t) (j.gradientDt a b t x) x := by + unfold fieldOnInterval_dt gradientDt + split_ifs + · convert (((j.transform a (Real.sqrt (b-t))).hasD3 x).add + (((fieldOnInterval f a b t).hasD2 x).pow 2 |>.const_mul a)).const_mul (-(1/2:ℝ)) using 1 <;> + first | rfl | (dsimp only [slabD3,transform]; ring) + · exact hasDerivAt_const x 0 + +lemma gradient_integral_time (j : ThirdJet f) (a b u v x : ℝ) : + ∫ t in u..v,j.gradientDt a b t x= + (fieldOnInterval f a b v).d1 x-(fieldOnInterval f a b u).d1 x := by + have hd := intervalIntegral.hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun x t => fieldOnInterval_dt f a b t x) + (F' := fun x t => j.gradientDt a b t x) (x₀ := x) + (s := Set.univ) (bound := fun _ => (j.gradientTimeBound a:ℝ)) + (μ := volume) (a := u) (b := v) (Filter.univ_mem) + (Eventually.of_forall fun x => ((measurable_fieldOnInterval_dt f a b).comp + (measurable_id.prodMk measurable_const)).aestronglyMeasurable) + (integrable_fieldOnInterval_dt f a b u v x) + (((j.measurable_gradientDt a b).comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable) + (ae_of_all _ fun t _ x _ => j.gradientDt_bound a b t x) + intervalIntegrable_const + (ae_of_all _ fun t _ x _ => j.hasDerivAt_fieldOnInterval_dt a b t x) + have he : (fun x => ∫ t in u..v,fieldOnInterval_dt f a b t x)= + (fun x => (fieldOnInterval f a b v).val x-(fieldOnInterval f a b u).val x) := + funext fun x => fieldOnInterval_integral_time f a b u v x + rw [he] at hd + exact hd.2.unique (((fieldOnInterval f a b v).hasD1 x).sub + ((fieldOnInterval f a b u).hasD1 x)) + +def slabGradientTest (j : ThirdJet f) (a b : ℝ) : TimeQuadraticTest where + val := fun t x => (fieldOnInterval f a b t).d1 x + d1 := fun t x => (fieldOnInterval f a b t).d2 x + d2 := j.slabD3 a b + dt := j.gradientDt a b + hasD1 := fun t => (fieldOnInterval f a b t).hasD2 + hasD2 := fun t => (j.transform a (Real.sqrt (b-t))).hasD3 + continuousD2 := fun t => (j.transform a (Real.sqrt (b-t))).continuousD3 + c1 := (f.transform a 0).bound2 + c2 := (j.transform a 0).bound3 + ct := j.gradientTimeBound a + bound1 := fun t x => by simpa only [Real.norm_eq_abs,fieldOnInterval,SmoothField.transform] using (fieldOnInterval f a b t).normD2 x + bound2 := fun t x => by simpa only [Real.norm_eq_abs] using j.slabD3_bound a b t x + boundT := j.gradientDt_bound a b + measT := j.measurable_gradientDt a b + continuousT := j.continuous_gradientDt a b + jointD1 := ae_of_all _ fun _ _ _ => (continuous_fieldOnInterval_d2 f a b).continuousAt + jointD2 := ae_of_all _ fun _ _ _ => (j.continuous_slabD3 a b).continuousAt + integralT := fun u _ v _ x => (j.gradient_integral_time a b u v x).symm + +end ThirdJet +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath + +namespace ThirdJet +variable {f : SmoothField} + +lemma intervalIntegrable_gradientDt (j : ThirdJet f) (a b u v x : ℝ) : + IntervalIntegrable (fun t => j.gradientDt a b t x) volume u v := by + apply (intervalIntegrable_const (c := (j.gradientTimeBound a:ℝ))).mono_fun' + (((j.measurable_gradientDt a b).comp (show Measurable (fun u : ℝ => (u,x)) by fun_prop)).aestronglyMeasurable) + exact ae_of_all _ fun t => j.gradientDt_bound a b t x + +lemma gradientDt_rightContinuous (j : ThirdJet f) (a b t x : ℝ) : + ContinuousWithinAt (fun u => j.gradientDt a b u x) (Ici t) t := by + by_cases ht : t (u,x)) by fun_prop) + apply hc.continuousAt.congr_of_eventuallyEq + filter_upwards [Iio_mem_nhds ht] with u hu + exact ite_eq_left hu + · have he : (fun u => j.gradientDt a b u x) =ᶠ[𝓝[Ici t] t] (fun _ => (0:ℝ)) := by + filter_upwards [self_mem_nhdsWithin] with u hu + exact ite_eq_right (not_lt.mpr ((le_of_not_gt ht).trans hu)) + exact continuousWithinAt_const.congr_of_eventuallyEq he (he.self_of_nhdsWithin (by simp)) + +lemma hasDerivWithinAt_gradient_time (j : ThirdJet f) (a b t x : ℝ) : + HasDerivWithinAt (fun u => (fieldOnInterval f a b u).d1 x) + (j.gradientDt a b t x) (Ici t) t := by + have hm := ((j.measurable_gradientDt a b).comp + (show Measurable (fun u : ℝ => (u,x)) by fun_prop)).stronglyMeasurable.stronglyMeasurableAtFilter + (l := 𝓝[Ioi t] t) (μ := volume) + have hd := intervalIntegral.integral_hasDerivWithinAt_right + (s := Ici t) (t := Ioi t) (j.intervalIntegrable_gradientDt a b 0 t x) hm + ((j.gradientDt_rightContinuous a b t x).mono Ioi_subset_Ici_self) + have he : (fun v => ∫ u in (0:ℝ)..v,j.gradientDt a b u x)= + (fun v => (fieldOnInterval f a b v).d1 x-(fieldOnInterval f a b 0).d1 x) := + funext fun v => j.gradient_integral_time a b 0 v x + rw [he] at hd + simpa only [sub_add_cancel] using hd.add_const ((fieldOnInterval f a b 0).d1 x) + +lemma gradient_square_integral_time (j : ThirdJet f) (a b u v x : ℝ) : + ∫ t in u..v,2*(fieldOnInterval f a b t).d1 x*j.gradientDt a b t x= + ((fieldOnInterval f a b v).d1 x)^2-((fieldOnInterval f a b u).d1 x)^2 := by + have hm := ((continuous_fieldOnInterval_d1 f a b).comp + (show Continuous (fun u : ℝ => (u,x)) by fun_prop)) + apply intervalIntegral.integral_eq_sub_of_hasDeriv_right (hm.pow 2).continuousOn + · intro t _ + have hd := (j.hasDerivWithinAt_gradient_time a b t x).pow 2 + convert hd.mono (Ioi_subset_Ici_self) using 1 <;> first | rfl | norm_num + · apply (intervalIntegrable_const (c := 2*(f.bound1:ℝ)*(j.gradientTimeBound a:ℝ))).mono_fun' + ((hm.measurable.const_mul 2).mul ((j.measurable_gradientDt a b).comp + (show Measurable (fun u : ℝ => (u,x)) by fun_prop))).aestronglyMeasurable + exact ae_of_all _ fun t => by + change ‖2*(fieldOnInterval f a b t).d1 x*j.gradientDt a b t x‖≤_ + rw [norm_mul,norm_mul,Real.norm_eq_abs,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + change 2*‖(fieldOnInterval f a b t).d1 x‖*‖j.gradientDt a b t x‖≤ + 2*(f.bound1:ℝ)*(j.gradientTimeBound a:ℝ) + exact mul_le_mul (mul_le_mul_of_nonneg_left + (by simpa only [Real.norm_eq_abs,fieldOnInterval,SmoothField.transform] using (fieldOnInterval f a b t).normD1 x) zero_le_two) + (j.gradientDt_bound a b t x) (norm_nonneg _) (by positivity) + +def squareGradientField (j : ThirdJet f) : SmoothField where + val := fun x => (f.d1 x)^2 + d1 := fun x => 2*f.d1 x*f.d2 x + d2 := fun x => 2*(f.d2 x)^2+2*f.d1 x*j.d3 x + hasD1 := fun x => by + convert (f.hasD2 x).pow 2 using 1 + first | rfl | norm_num + hasD2 := fun x => by + convert ((f.hasD2 x).const_mul 2).mul (j.hasD3 x) using 1 + first | rfl | ring + continuousD2 := ((f.continuousD2.pow 2).const_mul 2).add + ((f.continuousD1.const_mul 2).mul j.continuousD3) + bound1 := 2*f.bound1*f.bound2 + bound2 := 2*f.bound2^2+2*f.bound1*j.bound3 + normD1 := fun x => by + simp only [abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2),NNReal.coe_mul,NNReal.coe_ofNat] + gcongr <;> first | exact f.normD1 x | exact f.normD2 x + normD2 := fun x => by + apply (abs_add_le _ _).trans + simp only [abs_mul,abs_pow,abs_of_nonneg (by norm_num : (0:ℝ)≤2),NNReal.coe_mul, + NNReal.coe_add,NNReal.coe_ofNat,NNReal.coe_pow] + gcongr <;> first | exact f.normD1 x | exact f.normD2 x | exact j.normD3 x + +def slabSquareGradientTest (j : ThirdJet f) (a b : ℝ) : TimeQuadraticTest where + val := fun t x => ((fieldOnInterval f a b t).d1 x)^2 + d1 := fun t x => 2*(fieldOnInterval f a b t).d1 x*(fieldOnInterval f a b t).d2 x + d2 := fun t x => 2*((fieldOnInterval f a b t).d2 x)^2+ + 2*(fieldOnInterval f a b t).d1 x*j.slabD3 a b t x + dt := fun t x => 2*(fieldOnInterval f a b t).d1 x*j.gradientDt a b t x + hasD1 := fun t => (j.transform a (Real.sqrt (b-t))).squareGradientField.hasD1 + hasD2 := fun t => (j.transform a (Real.sqrt (b-t))).squareGradientField.hasD2 + continuousD2 := fun t => (j.transform a (Real.sqrt (b-t))).squareGradientField.continuousD2 + c1 := (j.transform a 0).squareGradientField.bound1 + c2 := (j.transform a 0).squareGradientField.bound2 + ct := 2*f.bound1*j.gradientTimeBound a + bound1 := fun t x => by + simpa only [Real.norm_eq_abs,fieldOnInterval,squareGradientField,transform,SmoothField.transform] + using (j.transform a (Real.sqrt (b-t))).squareGradientField.normD1 x + bound2 := fun t x => by + simpa only [Real.norm_eq_abs,fieldOnInterval,squareGradientField,transform,SmoothField.transform,slabD3] + using (j.transform a (Real.sqrt (b-t))).squareGradientField.normD2 x + boundT := fun t x => by + rw [norm_mul,norm_mul,Real.norm_eq_abs,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + simp only [NNReal.coe_mul,NNReal.coe_ofNat] + gcongr + · exact (fieldOnInterval f a b t).normD1 x + · exact j.gradientDt_bound a b t x + measT := ((continuous_fieldOnInterval_d1 f a b).measurable.const_mul 2).mul + (j.measurable_gradientDt a b) + continuousT := fun t => ((fieldOnInterval f a b t).continuousD1.const_mul 2).mul + (j.continuous_gradientDt a b t) + jointD1 := ae_of_all _ fun _ _ _ => + (((continuous_fieldOnInterval_d1 f a b).const_mul 2).mul + (continuous_fieldOnInterval_d2 f a b)).continuousAt + jointD2 := ae_of_all _ fun _ _ _ => + ((((continuous_fieldOnInterval_d2 f a b).pow 2).const_mul 2).add + (((continuous_fieldOnInterval_d1 f a b).const_mul 2).mul + (j.continuous_slabD3 a b))).continuousAt + integralT := fun u _ v _ x => (j.gradient_square_integral_time a b u v x).symm + +end ThirdJet +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath + +lemma SmoothField.d1_eq_of_val_eq {f g : SmoothField} (h : f.val=g.val) (x : ℝ) : + f.d1 x=g.d1 x := by + exact (h ▸ f.hasD1 x).unique (g.hasD1 x) + +structure ScheduleGradientSquare (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (s : ℝ) where + test : TimeQuadraticTest + val_eq : ∀ t x,test.val t x=((finiteTimeField β hβ ls s t).d1 x)^2 + d1_eq : ∀ t x,test.d1 t x=2*(finiteTimeField β hβ ls s t).d1 x* + (finiteTimeField β hβ ls s t).d2 x + cancel : ∀ t,s≤t → t + refine ⟨(terminalThird β hβ).squareGradientField.staticTimeTest, + fun _ _ => rfl,fun _ _ => rfl,?_⟩ + intro t ht ht' + simp only [width,List.map_nil,List.sum_nil,add_zero] at ht' + exact False.elim (not_lt_of_ge ht ht') + | cons l ls ih => + rcases l with ⟨a,d⟩ + let c : ℝ := s+d + have hc0 : 0≤c := add_nonneg hs d.coe_nonneg + have hend : c+width ls≤1 := by + dsimp only [c] + rw [width_cons] at he + linarith + have hc1 : c≤1 := by linarith [schedule_width_nonneg ls] + let tail := ih c hc0 hend + let slab := (recursionThird β hβ ls).slabSquareGradientTest a c + have hval : (fieldOnInterval (smoothRecursion β hβ ls) a c c).val= + (finiteTimeField β hβ ls c c).val := by + funext x + rw [fieldOnInterval_right,finiteTimeField_start,smoothRecursion_val] + have hmatch (x : ℝ) : slab.val c x=tail.test.val c x := by + change ((fieldOnInterval (smoothRecursion β hβ ls) a c c).d1 x)^2=tail.test.val c x + rw [tail.val_eq,SmoothField.d1_eq_of_val_eq hval] + refine ⟨slab.glue tail.test c ⟨hc0,hc1⟩ hmatch,?_,?_,?_⟩ + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeField, + ThirdJet.slabSquareGradientTest,slab,c] + split_ifs + · rfl + · exact tail.val_eq t x + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeField, + ThirdJet.slabSquareGradientTest,slab,c] + split_ifs + · rfl + · exact tail.d1_eq t x + · intro t ht ht' x z + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeField, + finiteTimeCoefficient,ThirdJet.slabSquareGradientTest,slab,c] + split_ifs with hcut + · rw [ThirdJet.gradientDt,ite_eq_left hcut] + ring + · exact tail.cancel t (le_of_not_gt hcut) (by rw [width_cons] at ht';dsimp only [c];linarith) x z + +lemma finiteTimeField_d1_start (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (s x : ℝ) : + (finiteTimeField β hβ ls s s).d1 x=(smoothRecursion β hβ ls).d1 x := + SmoothField.d1_eq_of_val_eq (funext fun x => + (finiteTimeField_start β hβ ls s x).trans (congrFun (smoothRecursion_val β hβ ls) x).symm) x + +lemma finiteTimeField_d1_after (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (s t x : ℝ) + (ht : s+width ls≤t) : (finiteTimeField β hβ ls s t).d1 x=(terminalField β hβ).d1 x := + SmoothField.d1_eq_of_val_eq (funext fun x => finiteTimeField_after β hβ ls s t x ht) x + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +lemma scheduleSuffix_ordered {β a : ℝ} {ls : Schedule} + (h : ParisiGuerra.OrderedFrom β a ls) (r : ℝ≥0) : + ParisiGuerra.OrderedFrom β a (scheduleSuffix ls r) := by + induction ls generalizing a r with + | nil => exact h + | cons l ls ih => + simp only [scheduleSuffix] + split_ifs + · exact h + · exact ordered_lower h.1 (ih h.2 _) + +lemma SmoothField.d2_eq_of_val_eq {f g : SmoothField} (h : f.val=g.val) (x : ℝ) : + f.d2 x=g.d2 x := by + have hd : f.d1=g.d1 := funext (SmoothField.d1_eq_of_val_eq h) + exact (hd ▸ f.hasD2 x).unique (g.hasD2 x) + +lemma finiteTimeField_suffix_d2 (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (s : ℝ) (r : ℝ≥0) : + (finiteTimeField β hβ ls s (s+r)).d2=(smoothRecursion β hβ (scheduleSuffix ls r)).d2 := by + apply funext + exact SmoothField.d2_eq_of_val_eq (funext fun x => + (finiteTimeField_suffix_val β hβ ls s r x).trans (congrFun (smoothRecursion_val β hβ _) x).symm) + +lemma finiteTimeField_curvature_lipschitz (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (h : ParisiGuerra.OrderedFrom β 0 ls) (s : ℝ) (r : ℝ≥0) : + LipschitzWith (5*β^2) (finiteTimeField β hβ ls s (s+r)).d2 := by + rw [finiteTimeField_suffix_d2] + exact recursion_curvature_lipschitz β hβ _ (scheduleSuffix_ordered h r) + +lemma global_dyadic_curvature_tendstoUniformly (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (r : ℝ≥0) (hr : r<1) : + TendstoUniformly (fun n => (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 r).d2) + (fieldCurvature β γ r) atTop := by + have hl (n : ℕ) : LipschitzWith (5*β^2) + (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 r).d2 := by + simpa only [zero_add] using finiteTimeField_curvature_lipschitz β hβ _ + (ordered_lower (γ 0).coe_nonneg (ordered_upper + (show (γ (0+1):ℝ)≤β by exact_mod_cast hb _) (dyadicSchedule_ordered hγ false 0 1 n))) 0 r + obtain ⟨g,hu,hd,hg⟩ := exists_uniform_derivative_lipschitz_limit + (fun n => (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 r).hasD2) hl + (global_dyadic_gradient_tendstoUniformly β hβ hγ hb r hr) + have he : g=fieldCurvature β γ r := funext (fun x => (hd x).deriv.symm) + rwa [he] at hu + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma generatorC2_bound (f : QuadraticTest) (b : Drift K M) (t x : ℝ) : + ‖generatorC2 f b t x‖ ≤ (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2 := by + exact le_of_tendsto (mollify_generator_tendsto b f t x).norm + (Eventually.of_forall fun n => generator_bound _ b t x) + +lemma generatorC2_integrable (hW : IsBrownianReal W P) (b : Drift K M) + (f : QuadraticTest) (t : ℝ) : + Integrable (fun ω => generatorC2 f b t (extend (solution b (brownianPath W ω)) t)) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hX := aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t) + apply Integrable.of_bound (C := (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + · exact (((f.continuous_d1.mul (b.lipschitz t).continuous).add + (continuous_const.mul f.continuousD2)).measurable.comp_aemeasurable hX).aestronglyMeasurable + · exact ae_of_all _ fun ω => generatorC2_bound f b t _ + +lemma timeDerivativeC2_integrable_inner (hW : IsBrownianReal W P) (b : Drift K M) + (f : TimeQuadraticTest) (t : ℝ) : + Integrable (fun ω => f.dt t (extend (solution b (brownianPath W ω)) t)) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hX := aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t) + exact Integrable.of_bound ((f.continuousT t).measurable.comp_aemeasurable hX).aestronglyMeasurable + (C := f.ct) (ae_of_all _ fun ω => f.boundT t _) + +lemma timeGeneratorC2_aestronglyMeasurable (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (timeGeneratorC2 P W b f) (volume.restrict (Ioc (0:ℝ) 1)) := by + exact aestronglyMeasurable_of_tendsto_ae atTop + (fun n => timeGenerator_aestronglyMeasurable hW b (f.mollify (shrinkingBump n)) hc) + (ae_of_all _ fun t => mollify_timeGenerator_tendsto hW b f t) + +lemma timeDerivativeC2_aestronglyMeasurable (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (timeDerivativeC2 P W b f) (volume.restrict (Ioc (0:ℝ) 1)) := by + exact aestronglyMeasurable_of_tendsto_ae atTop + (fun n => timeDerivative_aestronglyMeasurable hW b (f.mollify (shrinkingBump n)) hc) + (ae_of_all _ fun t => mollify_timeDerivative_tendsto hW b f t) + +lemma timeGeneratorC2_intervalIntegrable (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + IntervalIntegrable (timeGeneratorC2 P W b f) volume 0 1 := by + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] + apply Integrable.of_bound (timeGeneratorC2_aestronglyMeasurable hW b f hc) + (C := (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + exact ae_of_all _ fun t => le_of_tendsto (mollify_timeGenerator_tendsto hW b f t).norm + (Eventually.of_forall fun n => expectedGenerator_bound hW b ((f.mollify (shrinkingBump n)).slice t) t) + +lemma timeDerivativeC2_intervalIntegrable (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + IntervalIntegrable (timeDerivativeC2 P W b f) volume 0 1 := by + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] + apply Integrable.of_bound (timeDerivativeC2_aestronglyMeasurable hW b f hc) (C := f.ct) + exact ae_of_all _ fun t => le_of_tendsto (mollify_timeDerivative_tendsto hW b f t).norm + (Eventually.of_forall fun n => timeDerivative_bound hW b (f.mollify (shrinkingBump n)) t) + +end ParisiPath +namespace ParisiFinite +open ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + + + +theorem finite_schedule_verification (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (β : ℝ≥0) (hβ : 0 < β) (ls : Schedule) (hw : width ls = 1) : + (∫ ω,terminal β (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)-recursion β ls 0 = + ∫ t in (0:ℝ)..1,∫ ω, + (finiteTimeField β hβ ls 0 t).d1 (extend (solution b (brownianPath W ω)) t) * + b.val t (extend (solution b (brownianPath W ω)) t) - + (finiteTimeCoefficient ls 0 t)/2 * + ((finiteTimeField β hβ ls 0 t).d1 (extend (solution b (brownianPath W ω)) t))^2 ∂P := by + let r := scheduleTimeRealization β hβ ls 0 le_rfl (by rw [hw]; norm_num) + have hh := brownian_solution_time_generator_identity_C2 hW b r.test hc + have hj := timeGeneratorC2_intervalIntegrable hW b r.test hc + have ht := timeDerivativeC2_intervalIntegrable hW b r.test hc + have h1 (x : ℝ) : r.test.val 1 x = terminal β x := by + rw [r.val_eq,finiteTimeField_after β hβ ls 0 1 x (by rw [hw]; norm_num)] + have h0 : r.test.val 0 0 = recursion β ls 0 := by rw [r.val_eq,finiteTimeField_start] + simp_rw [h1,h0] at hh + rw [hh,←intervalIntegral.integral_add hj ht] + apply intervalIntegral.integral_congr_Ioo_of_le zero_le_one + intro t ht + change (∫ ω,generatorC2 (r.test.slice t) b t (extend (solution b (brownianPath W ω)) t) ∂P)+ + (∫ ω,r.test.dt t (extend (solution b (brownianPath W ω)) t) ∂P)=_ + rw [←integral_add (generatorC2_integrable hW b _ t) (timeDerivativeC2_integrable_inner hW b r.test t)] + apply integral_congr_ae + filter_upwards [] with ω + simp only [generatorC2,TimeQuadraticTest.slice,r.d1_eq,r.d2_eq,r.dt_eq] + rw [finiteTimeField_PDE β hβ ls 0 t _ ht.1.le (by simpa only [hw,zero_add] using ht.2)] + ring + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/GramBlock.lean b/lean/OAI/Probability/ParisiFinite/GramBlock.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5f34dca0f90aa355bcb95ecf02a0bea81e2b35b --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/GramBlock.lean @@ -0,0 +1,658 @@ +import Mathlib +import OAI.Probability.ParisiFinite.LowBlock + +namespace OAI + +/-! Gram Block. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def GramBlock (r : ℕ) : Set (OverlapBlock r) := {T | + (∀ i j, T i j=T j i) ∧ (∀ i, (T i i:ℝ)=1) ∧ + ∀ c : Fin r → ℝ, 0≤∑ i,∑ j,c i*c j*(T i j:ℝ)} + +lemma isClosed_GramBlock (r : ℕ) : IsClosed (GramBlock r) := by + unfold GramBlock + simp only [Set.ofPred_and,Set.ofPred_forall] + exact (isClosed_iInter fun i => isClosed_iInter fun j => isClosed_eq (by fun_prop) (by fun_prop)).inter + ((isClosed_iInter fun i => isClosed_eq (by fun_prop) continuous_const).inter + (isClosed_iInter fun c => isClosed_le continuous_const (by fun_prop))) + +lemma GramArrays_block {R : OverlapArray} (h : R∈GramArrays) (r : ℕ) : blockOfArray r R∈GramBlock r := + ⟨fun i j => h.1 i j,fun i => h.2.1 i,h.2.2 r⟩ + +lemma blockSupport_Gram {μ : ProbabilityMeasure OverlapArray} (hG : (μ : Measure OverlapArray) GramArrays=1) + (r : ℕ) : (blockLaw μ r).support ⊆ GramBlock r := by + apply Measure.support_subset_of_isClosed (isClosed_GramBlock r) + apply ae_iff.mpr + change blockLaw μ r (GramBlock r)ᶜ=0 + rw [blockLaw,Measure.map_apply (continuous_blockOfArray r).measurable (isClosed_GramBlock r).measurableSet.compl] + apply measure_mono_null (show (blockOfArray r) ⁻¹' (GramBlock r)ᶜ ⊆ GramArraysᶜ from + fun R hR h => hR (GramArrays_block h r)) + rw [measure_compl isClosed_GramArrays.measurableSet (measure_ne_top _ _),hG] + simp + +lemma support_event_nonempty {Ω : Type*} [TopologicalSpace Ω] [MeasurableSpace Ω] + [HereditarilyLindelofSpace Ω] (ν : Measure Ω) {E : Set Ω} (hE : 0<ν E) : (E∩ν.support).Nonempty := by + by_contra hn + have hs : E⊆ν.supportᶜ := by + intro x hx hx' + exact hn ⟨x,hx,hx'⟩ + exact (ne_of_gt hE) (measure_mono_null hs ν.measure_compl_support) + +def rowBall {r : ℕ} (x : Fin r → OverlapEntry) (ε : ℝ) : Set (Fin r → OverlapEntry) := + {y | ∀ i, |(y i:ℝ)-(x i:ℝ)|<ε} + +def blockBall {r : ℕ} (T : OverlapBlock r) (ε : ℝ) : Set (OverlapBlock r) := + {U | ∀ i j, |(U i j:ℝ)-(T i j:ℝ)|<ε} + +lemma isOpen_rowBall {r : ℕ} (x : Fin r → OverlapEntry) (ε : ℝ) : IsOpen (rowBall x ε) := by + unfold rowBall + simp only [Set.ofPred_forall] + exact isOpen_iInter_of_finite fun i => isOpen_lt (by fun_prop) continuous_const + +lemma isOpen_blockBall {r : ℕ} (T : OverlapBlock r) (ε : ℝ) : IsOpen (blockBall T ε) := by + unfold blockBall + simp only [Set.ofPred_forall] + exact isOpen_iInter_of_finite fun i => isOpen_iInter_of_finite fun j => isOpen_lt (by fun_prop) continuous_const + +lemma isOpen_patternBlock {r : ℕ} {C : Set (OverlapBlock r)} {B : Set (Fin r → OverlapEntry)} + (hC : IsOpen C) (hB : IsOpen B) : IsOpen (patternBlock r C B) := + (hC.preimage (continuous_initialBlock _)).inter (hB.preimage (continuous_newRow _)) + + + +lemma exists_supported_approx_duplication {μ : ProbabilityMeasure OverlapArray} (hG : (μ : Measure OverlapArray) GramArrays=1) + (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) {r : ℕ} (hr : 0 intro i + · intro j; simpa only [sub_self,abs_zero] using hε + · simpa only [sub_self,abs_zero] using hε + have hp := (Measure.mem_support_iff_forall A).mp hA (patternBlock r C B) + ((isOpen_patternBlock hC hB).mem_nhds ha) + have hp' : 0<(μ : Measure OverlapArray).real ((blockOfArray (r+1)) ⁻¹' patternBlock r C B) := by + rw [blockLaw,Measure.map_apply (continuous_blockOfArray _).measurable (isOpen_patternBlock hC hB).measurableSet] at hp + exact ENNReal.toReal_pos (ne_of_gt hp) (measure_ne_top _ _) + have hb : ∀ x∈B, ∀ i, (x i:ℝ)≤q+ε := by + intro x hx i + have hh := (abs_lt.mp (hx i)).2 + have hi := hrow i + change (A (Fin.last r) i.castSucc:ℝ)≤q at hi + change (x i:ℝ)-(A (Fin.last r) i.castSucc:ℝ)<ε at hh + linarith + have hd := GG_duplication_of_positive hgg hex hr hC.measurableSet hB.measurableSet (q+ε) hb hp' + have he : 0.1 + obtain ⟨T,hT,hTs⟩ := support_event_nonempty _ he + have hGT := blockSupport_Gram hG (r+2) hTs + have hGA := blockSupport_Gram hG (r+1) hA + refine ⟨T,hTs,?_,hT.2.2.1,hT.2.2.2⟩ + intro i j + refine Fin.lastCases ?_ (fun a => ?_) i + · refine Fin.lastCases ?_ (fun b => ?_) j + · rw [hGT.2.1,hGA.2.1]; simpa using hε + · exact hT.2.1 b + · refine Fin.lastCases ?_ (fun b => ?_) j + · rw [hGT.1,hGA.1]; exact hT.2.1 a + · exact hT.1 a b + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +theorem exists_supported_duplication_last {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) + {r : ℕ} (hr : 0 1/((n:ℝ)+1) + have hε (n : ℕ) : 0<ε n := by dsimp [ε]; positivity + choose T hTs hTo hTn hTq using fun n => + exists_supported_approx_duplication hG hgg hex hr hA q hrow (hε n) + obtain ⟨U,φ,hφ,hlim⟩ := CompactSpace.tendsto_subseq T + have heps : Tendsto (fun k => ε (φ k)) atTop (𝓝 0) := + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).comp hφ.tendsto_atTop + have hcoord (i j : Fin (r+2)) : Tendsto (fun k => (T (φ k) i j:ℝ)) atTop (𝓝 (U i j:ℝ)) := + (show Continuous (fun V : OverlapBlock (r+2) => (V i j:ℝ)) by fun_prop).continuousAt.tendsto.comp hlim + have heq (i j : Fin (r+2)) (a : OverlapEntry) + (h : ∀ k, |(T (φ k) i j:ℝ)-(a:ℝ)|<ε (φ k)) : U i j=a := by + apply Subtype.ext + have hh : |(U i j:ℝ)-(a:ℝ)|≤0 := + le_of_tendsto_of_tendsto' ((hcoord i j).sub_const (a:ℝ) |>.abs) heps (fun k => le_of_lt (h k)) + exact sub_eq_zero.mp (abs_nonpos_iff.mp hh) + refine ⟨U,(blockLaw μ (r+2)).isClosed_support.mem_of_tendsto hlim (Filter.Eventually.of_forall fun k => hTs (φ k)),?_,?_,?_⟩ + · intro i j + exact heq _ _ _ (fun k => hTo (φ k) i j) + · intro i + exact heq _ _ _ (fun k => hTn (φ k) i) + · have hh := le_of_tendsto_of_tendsto' (hcoord (Fin.last r).castSucc (Fin.last (r+1))) + (tendsto_const_nhds.add heps) (fun k => hTq (φ k)) + simpa only [add_zero] using hh + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def permBlock {r : ℕ} (p : Equiv.Perm (Fin r)) (T : OverlapBlock r) : OverlapBlock r := + fun i j => T (p i) (p j) + +lemma continuous_permBlock {r : ℕ} (p : Equiv.Perm (Fin r)) : Continuous (permBlock p) := by + unfold permBlock + fun_prop + +lemma blockLaw_map_perm {μ : ProbabilityMeasure OverlapArray} (hex : FiniteExchangeable μ) + {r : ℕ} (p : Equiv.Perm (Fin r)) : (blockLaw μ r).map (permBlock p)=blockLaw μ r := by + rw [blockLaw,Measure.map_map (continuous_permBlock p).measurable (continuous_blockOfArray r).measurable] + exact hex r (fun i => (p i:ℕ)) (Fin.val_injective.comp p.injective) + +lemma permBlock_support {μ : ProbabilityMeasure OverlapArray} (hex : FiniteExchangeable μ) + {r : ℕ} (p : Equiv.Perm (Fin r)) {T : OverlapBlock r} (hT : T∈(blockLaw μ r).support) : + permBlock p T∈(blockLaw μ r).support := by + rw [Measure.support_eq_forall_isOpen] at hT ⊢ + intro U hU hOpen + have hh := hT ((permBlock p) ⁻¹' U) hU (hOpen.preimage (continuous_permBlock p)) + have he := congrArg (fun ν : Measure (OverlapBlock r) => ν U) (blockLaw_map_perm hex p) + rw [Measure.map_apply (continuous_permBlock p).measurable hOpen.measurableSet] at he + rwa [he] at hh + +def headPerm {r : ℕ} (p : Equiv.Perm (Fin r)) : Equiv.Perm (Fin (r+1)) := + finSumFinEquiv.symm.trans ((Equiv.sumCongr p (Equiv.refl (Fin 1))).trans finSumFinEquiv) + +@[simp] lemma headPerm_old {r : ℕ} (p : Equiv.Perm (Fin r)) (i : Fin r) : + headPerm p i.castSucc=(p i).castSucc := by simp [headPerm]; rfl + +@[simp] lemma headPerm_last {r : ℕ} (p : Equiv.Perm (Fin r)) : + headPerm p (Fin.last r)=Fin.last r := by + change headPerm p (Fin.natAdd r (0:Fin 1))=Fin.natAdd r (0:Fin 1) + simp [headPerm] + + + +theorem exists_supported_duplication {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) + {r : ℕ} (hr : 0 if j=i then 1 else 0 + +lemma gramForm_symm {r : ℕ} {T : OverlapBlock r} (hT : T∈GramBlock r) (u v : Fin r → ℝ) : + gramForm T u v=gramForm T v u := by + unfold gramForm + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + rw [hT.1 j i] + ring + +@[simp] lemma gramForm_delta_left {r : ℕ} (T : OverlapBlock r) (i : Fin r) (v : Fin r → ℝ) : + gramForm T (gramDelta i) v=∑ j,v j*(T i j:ℝ) := by + simp [gramForm,gramDelta,ite_mul] + +@[simp] lemma gramForm_delta_delta {r : ℕ} (T : OverlapBlock r) (i j : Fin r) : + gramForm T (gramDelta i) (gramDelta j)=(T i j:ℝ) := by + simp [gramDelta,gramForm,ite_mul] + +lemma gramForm_sub_left {r : ℕ} (T : OverlapBlock r) (u v w : Fin r → ℝ) : + gramForm T (u-v) w=gramForm T u w-gramForm T v w := by + simp [gramForm,Pi.sub_apply,sub_mul,Finset.sum_sub_distrib] + +lemma gramForm_sub_right {r : ℕ} (T : OverlapBlock r) (u v w : Fin r → ℝ) : + gramForm T u (v-w)=gramForm T u v-gramForm T u w := by + simp [gramForm,Pi.sub_apply,mul_sub,sub_mul,Finset.sum_sub_distrib] + +lemma gramForm_smul_left {r : ℕ} (T : OverlapBlock r) (u v : Fin r → ℝ) (a : ℝ) : + gramForm T (a • u) v=a*gramForm T u v := by + simp only [gramForm,Pi.smul_apply,smul_eq_mul,mul_assoc,Finset.mul_sum] + +lemma gramForm_smul_right {r : ℕ} (T : OverlapBlock r) (u v : Fin r → ℝ) (a : ℝ) : + gramForm T u (a • v)=a*gramForm T u v := by + unfold gramForm + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + change u i*(a*v j)*(T i j:ℝ)=a*(u i*v j*(T i j:ℝ)) + ring + +lemma gramForm_sum_left {r : ℕ} {ι : Type*} [Fintype ι] (T : OverlapBlock r) + (u : ι → Fin r → ℝ) (v : Fin r → ℝ) : + gramForm T (∑ a,u a) v=∑ a,gramForm T (u a) v := by + simp only [gramForm,Finset.sum_apply,Finset.sum_mul] + calc + _ = ∑ i, ∑ a, ∑ j, u a i*v j*(T i j:ℝ) := by + apply Finset.sum_congr rfl + intro i _ + exact Finset.sum_comm + _ = _ := Finset.sum_comm + +lemma gramForm_sum_right {r : ℕ} {ι : Type*} [Fintype ι] (T : OverlapBlock r) + (u : Fin r → ℝ) (v : ι → Fin r → ℝ) : + gramForm T u (∑ a,v a)=∑ a,gramForm T u (v a) := by + simp only [gramForm,Finset.sum_apply,Finset.mul_sum,Finset.sum_mul] + calc + _ = ∑ i, ∑ a, ∑ j, u i*v a j*(T i j:ℝ) := by + apply Finset.sum_congr rfl + intro i _ + exact Finset.sum_comm + _ = _ := Finset.sum_comm + + + +lemma gramForm_coordinate_sq_le {r : ℕ} {T : OverlapBlock r} (hT : T∈GramBlock r) + (i : Fin r) (u : Fin r → ℝ) : (gramForm T (gramDelta i) u)^2≤gramForm T u u := by + let a := gramForm T (gramDelta i) u + have hh := hT.2.2 (u-a • gramDelta i) + change 0≤gramForm T (u-a • gramDelta i) (u-a • gramDelta i) at hh + rw [gramForm_sub_left,gramForm_sub_right,gramForm_sub_right, + gramForm_smul_right,gramForm_smul_left,gramForm_smul_left,gramForm_smul_right, + gramForm_delta_delta,hT.2.1,gramForm_symm hT u (gramDelta i)] at hh + change 0≤gramForm T u u-a*a-(a*a-a*(a*1)) at hh + nlinarith only [hh] + +def gramCluster {r m : ℕ} (e : Fin m → Fin r) : Fin r → ℝ := ∑ j,gramDelta (e j) + +lemma gramForm_clusters {r m k : ℕ} (T : OverlapBlock r) (e : Fin m → Fin r) (f : Fin k → Fin r) : + gramForm T (gramCluster e) (gramCluster f)=∑ i,∑ j,(T (e i) (f j):ℝ) := by + unfold gramCluster + simp_rw [gramForm_sum_left,gramForm_sum_right,gramForm_delta_delta] + +lemma gramForm_delta_cluster {r m : ℕ} (T : OverlapBlock r) (i : Fin r) (e : Fin m → Fin r) : + gramForm T (gramDelta i) (gramCluster e)=∑ j,(T i (e j):ℝ) := by + unfold gramCluster + simp_rw [gramForm_sum_right,gramForm_delta_delta] + +lemma gramCluster_norm_bound {r m : ℕ} {T : OverlapBlock r} (hT : T∈GramBlock r) + (hm : 0 < m) (e : Fin m → Fin r) {c : ℝ} + (he : ∀ i j, i≠j → (T (e i) (e j):ℝ)≤c) : + gramForm T (gramCluster e) (gramCluster e)≤(m:ℝ)*(1+((m:ℝ)-1)*c) := by + have hr (i : Fin m) : (∑ j,(T (e i) (e j):ℝ))≤1+((m:ℝ)-1)*c := by + calc + _ = (∑ j∈Finset.univ.erase i,(T (e i) (e j):ℝ))+(T (e i) (e i):ℝ) := + (Finset.sum_erase_add _ _ (Finset.mem_univ i)).symm + _ ≤ (∑ j∈Finset.univ.erase i,c)+1 := add_le_add + (Finset.sum_le_sum fun j hj => he i j (Finset.ne_of_mem_erase hj).symm) (le_of_eq (hT.2.1 (e i))) + _ = _ := by simp [Nat.cast_sub (show 1 ≤ m by omega)]; ring + rw [gramForm_clusters] + calc + _ ≤ ∑ _i : Fin m, (1+((m:ℝ)-1)*c) := Finset.sum_le_sum fun i _ => hr i + _ = _ := by simp; ring + + + +theorem gram_two_cluster_bound {r m : ℕ} {T : OverlapBlock r} (hT : T∈GramBlock r) + (hm : 0 < m) (i : Fin r) (e f : Fin m → Fin r) (a b c : ℝ) + (ha : ∀ j,(T i (e j):ℝ)=a) (hb : ∀ j,(T i (f j):ℝ)=b) + (hc : ∀ j k,(T (e j) (f k):ℝ)=c) + (he : ∀ j k,j≠k → (T (e j) (e k):ℝ)≤c) + (hf : ∀ j k,j≠k → (T (f j) (f k):ℝ)≤c) : + (m:ℝ)^2*(a-b)^2≤2*(m:ℝ)*(1-c) := by + have hx : gramForm T (gramCluster e) (gramCluster f)=(m:ℝ)^2*c := by + rw [gramForm_clusters] + simp_rw [hc] + simp + ring + have hpa : gramForm T (gramDelta i) (gramCluster e)=(m:ℝ)*a := by + rw [gramForm_delta_cluster] + simp_rw [ha] + simp + have hpb : gramForm T (gramDelta i) (gramCluster f)=(m:ℝ)*b := by + rw [gramForm_delta_cluster] + simp_rw [hb] + simp + have hs := gramForm_coordinate_sq_le hT i (gramCluster e-gramCluster f) + rw [gramForm_sub_right,hpa,hpb,gramForm_sub_left,gramForm_sub_right,gramForm_sub_right, + gramForm_symm hT (gramCluster f) (gramCluster e),hx] at hs + have h₁ := gramCluster_norm_bound hT hm e he + have h₂ := gramCluster_norm_bound hT hm f hf + nlinarith only [hs,h₁,h₂] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma duplication_preserves_low {r : ℕ} {A : OverlapBlock (r+1)} {T : OverlapBlock (r+2)} + (hT : T∈GramBlock (r+2)) (i : Fin (r+1)) {c : ℝ} + (hA : ∀ j k, j≠k → (A j k:ℝ)≤c) + (hold : ∀ j k : Fin (r+1), T j.castSucc k.castSucc=A j k) + (hnew : ∀ j : Fin (r+1), j≠i → T (Fin.last (r+1)) j.castSucc=A i j) + (hq : (T i.castSucc (Fin.last (r+1)):ℝ)≤c) : + ∀ j k, j≠k → (T j k:ℝ)≤c := by + intro j k + refine Fin.lastCases ?_ (fun a => ?_) j + · refine Fin.lastCases (fun h => (h rfl).elim) (fun b _ => ?_) k + by_cases hb : b=i + · subst b; rw [hT.1]; exact hq + · rw [hnew b hb]; exact hA i b (Ne.symm hb) + · refine Fin.lastCases (fun _ => ?_) (fun b hab => ?_) k + · rw [hT.1] + by_cases ha : a=i + · subst a; rw [hT.1]; exact hq + · rw [hnew a ha]; exact hA i a (Ne.symm ha) + · rw [hold] + exact hA a b (fun he => hab (congrArg Fin.castSucc he)) + +structure TwoClusters (μ : ProbabilityMeasure OverlapArray) (m k : ℕ) (a b c : ℝ) where + r : ℕ + r_pos : 0 (S.disjoint l j).symm + low := S.low + root_left := S.root_right + root_right := S.root_left + cross := fun j l => by rw [(blockSupport_Gram hG _ S.supported).1]; exact S.cross l j + + + +noncomputable def growLeft (hG : (μ : Measure OverlapArray) GramArrays=1) + (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) (hm : 0 < m) + (S : TwoClusters μ m k a b c) : TwoClusters μ (m+1) k a b c := by + let i := S.left ⟨0,hm⟩ + let h := exists_supported_duplication hG hgg hex S.r_pos S.supported i c + (fun j hj => S.low i j hj.symm) + let T := h.choose + obtain ⟨hTs,hold,hnew,hq⟩ := h.choose_spec + change T∈(blockLaw μ (S.r+2)).support at hTs + change (∀ j l, T j.castSucc l.castSucc=S.block j l) at hold + change (∀ j, j≠i → T (Fin.last (S.r+1)) j.castSucc=S.block i j) at hnew + change (T i.castSucc (Fin.last (S.r+1)):ℝ)≤c at hq + have hTG := blockSupport_Gram hG _ hTs + let e : Fin (m+1) → Fin (S.r+2) := Fin.lastCases (Fin.last (S.r+1)) (fun j => (S.left j).castSucc) + let f : Fin k → Fin (S.r+2) := fun j => (S.right j).castSucc + have eold (j : Fin m) : e j.castSucc=(S.left j).castSucc := by simp [e] + have enew : e (Fin.last m)=Fin.last (S.r+1) := by simp [e] + refine ⟨S.r+1,by omega,T,hTs,S.root.castSucc,e,f,?_,?_,?_,?_,?_, + duplication_preserves_low hTG i S.low hold hnew hq,?_,?_,?_⟩ + · intro j l + refine Fin.lastCases ?_ (fun u => ?_) j + · refine Fin.lastCases (fun _ => rfl) (fun v hv => ?_) l + rw [enew,eold] at hv + exact (Fin.castSucc_ne_last _ hv.symm).elim + · refine Fin.lastCases (fun hu => ?_) (fun v huv => ?_) l + · rw [eold,enew] at hu + exact (Fin.castSucc_ne_last _ hu).elim + · rw [eold,eold] at huv + exact congrArg Fin.castSucc (S.left_inj ((Fin.castSucc_injective _) huv)) + · exact (Fin.castSucc_injective _).comp S.right_inj + · intro j + refine Fin.lastCases ?_ (fun u => ?_) j + · rw [enew]; exact (Fin.castSucc_ne_last _).symm + · rw [eold]; exact fun he => S.left_root u ((Fin.castSucc_injective _) he) + · intro j he + exact S.right_root j ((Fin.castSucc_injective _) he) + · intro j l + refine Fin.lastCases ?_ (fun u => ?_) j + · rw [enew]; exact (Fin.castSucc_ne_last _).symm + · rw [eold]; exact fun he => S.disjoint u l ((Fin.castSucc_injective _) he) + · intro j + refine Fin.lastCases ?_ (fun u => ?_) j + · rw [enew,hTG.1,hnew S.root (S.left_root ⟨0,hm⟩).symm] + rw [(blockSupport_Gram hG _ S.supported).1] + exact S.root_left ⟨0,hm⟩ + · rw [eold,hold]; exact S.root_left u + · intro j + change (T S.root.castSucc (S.right j).castSucc:ℝ)=b + rw [hold]; exact S.root_right j + · intro j l + refine Fin.lastCases ?_ (fun u => ?_) j + · rw [enew] + change (T (Fin.last (S.r+1)) (S.right l).castSucc:ℝ)=c + rw [hnew _ (S.disjoint ⟨0,hm⟩ l).symm] + exact S.cross ⟨0,hm⟩ l + · rw [eold] + change (T (S.left u).castSucc (S.right l).castSucc:ℝ)=c + rw [hold]; exact S.cross u l + +noncomputable def growRight (hG : (μ : Measure OverlapArray) GramArrays=1) + (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) (hk : 0 < k) + (S : TwoClusters μ m k a b c) : TwoClusters μ m (k+1) a b c := + ((S.swap hG).growLeft hG hgg hex hk).swap hG + +end TwoClusters +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +namespace TwoClusters +variable {μ : ProbabilityMeasure OverlapArray} {a b c : ℝ} + +noncomputable def replicate (hG : (μ : Measure OverlapArray) GramArrays=1) + (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) + (S : TwoClusters μ 1 1 a b c) : (n : ℕ) → TwoClusters μ (n+1) (n+1) a b c + | 0 => S + | n+1 => ((replicate hG hgg hex S n).growLeft hG hgg hex (by omega)).growRight hG hgg hex (by omega) + + +theorem root_overlap_eq (hG : (μ : Measure OverlapArray) GramArrays=1) + (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) + (S : TwoClusters μ 1 1 a b c) : a=b := by + by_contra hab + have hd : 0<(a-b)^2 := sq_pos_of_ne_zero (sub_ne_zero.mpr hab) + obtain ⟨n,hn⟩ := exists_nat_gt (2*(1-c)/(a-b)^2) + have hn' : 2*(1-c)<(n:ℝ)*(a-b)^2 := (div_lt_iff₀ hd).mp hn + let V := S.replicate hG hgg hex n + have hs := gram_two_cluster_bound (blockSupport_Gram hG _ V.supported) + (show 0 < n+1 by omega) V.root V.left V.right a b c V.root_left V.root_right V.cross + (fun j k hjk => V.low _ _ (fun he => hjk (V.left_inj he))) + (fun j k hjk => V.low _ _ (fun he => hjk (V.right_inj he))) + have hm : (0:ℝ) 1 + right := fun _ => 2 + left_inj := fun _ _ _ => Subsingleton.elim _ _ + right_inj := fun _ _ _ => Subsingleton.elim _ _ + left_root := by intro j; decide + right_root := by intro j; decide + disjoint := by intro j l; decide + low := by + intro j l hjl + fin_cases j <;> fin_cases l <;> simp_all <;> exact le_trans hab hbc + root_left := fun _ => rfl + root_right := fun _ => rfl + cross := fun _ _ => rfl } + exact Subtype.ext (S.root_overlap_eq hG hgg hex) + + + +theorem supported_triangle_ultrametric {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) + {A : OverlapBlock 3} (hA : A∈(blockLaw μ 3).support) : + min (A 0 2:ℝ) (A 1 2:ℝ)≤(A 0 1:ℝ) := by + by_contra h + have hh := lt_min_iff.mp (lt_of_not_ge h) + by_cases hc : (A 0 2:ℝ)≤(A 1 2:ℝ) + · have he := supported_triangle_ordered hG hgg hex hA hh.1.le hc + exact (ne_of_lt hh.1) (congrArg Subtype.val he) + · let p : Equiv.Perm (Fin 3) := Equiv.swap 0 1 + have hp01 : permBlock p A 0 1=A 0 1 := by + simp [permBlock,p,(blockSupport_Gram hG _ hA).1 1 0] + have hp02 : permBlock p A 0 2=A 1 2 := by simp [permBlock,p,Equiv.swap_apply_def, show (2:Fin 3)≠0 by decide, show (2:Fin 3)≠1 by decide] + have hp12 : permBlock p A 1 2=A 0 2 := by simp [permBlock,p,Equiv.swap_apply_def, show (2:Fin 3)≠0 by decide, show (2:Fin 3)≠1 by decide] + have he := supported_triangle_ordered hG hgg hex (permBlock_support hex p hA) + (by rw [hp01,hp02]; exact hh.2.le) (by rw [hp02,hp12]; exact le_of_not_ge hc) + rw [hp01,hp02] at he + exact (ne_of_lt hh.2) (congrArg Subtype.val he) + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/GramPosSemidef.lean b/lean/OAI/Probability/ParisiFinite/GramPosSemidef.lean new file mode 100644 index 0000000000000000000000000000000000000000..116e3a7e4eb539caa0634b4facd9f144009ae959 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/GramPosSemidef.lean @@ -0,0 +1,645 @@ +import Mathlib + +namespace OAI + +/-! Gram Pos Semidef. -/ + +noncomputable section + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ComplexConjugate +open MeasureTheory ProbabilityTheory +open scoped Topology +open Filter +open scoped BigOperators Matrix +open scoped Matrix Matrix.Norms.L2Operator +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter + +namespace CoherentFock +variable {ι : Type*} {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem gram_posSemidef (v : ι → E) : + (Matrix.of (fun i j => ⟪v i, v j⟫_ℂ)).PosSemidef := by + refine ⟨?_, fun c => ?_⟩ + · ext i j + change conj ⟪v j,v i⟫_ℂ = ⟪v i,v j⟫_ℂ + exact inner_conj_symm _ _ + · have he : c.sum (fun i a => c.sum fun j b => star a * ⟪v i,v j⟫_ℂ * b) = + ⟪c.sum (fun i a => a • v i), c.sum (fun i a => a • v i)⟫_ℂ := by + rw [Finsupp.sum_inner] + apply Finsupp.sum_congr + intro i hi + rw [Finsupp.inner_sum] + apply Finsupp.sum_congr + intro j hj + simp only [inner_smul_left,inner_smul_right,Complex.star_def] + ring + change 0 ≤ c.sum (fun i a => c.sum fun j b => star a * ⟪v i,v j⟫_ℂ * b) + rw [he] + exact RCLike.nonneg_iff.mpr ⟨inner_self_nonneg,inner_self_im _⟩ + +theorem ones_posSemidef : (Matrix.of (fun _ _ : ι => (1 : ℂ))).PosSemidef := by + simpa using (gram_posSemidef (fun _ : ι => (1 : ℂ))) + +theorem entry_pow_posSemidef {M : Matrix ι ι ℂ} (hM : M.PosSemidef) (n : ℕ) : + (Matrix.of (fun i j => M i j ^ n)).PosSemidef := by + induction n with + | zero => simpa using (ones_posSemidef (ι := ι)) + | succ n ih => + have hh : ((Matrix.of (fun i j => M i j ^ n)).hadamard M).PosSemidef := ih.hadamard hM + convert! hh using 1 + +theorem entry_exp_posSemidef {M : Matrix ι ι ℂ} (hM : M.PosSemidef) : + (Matrix.of (fun i j => Complex.exp (M i j))).PosSemidef := by + have hp (N : ℕ) : (Matrix.of (fun i j => ∑ k ∈ Finset.range N, + (k.factorial : ℝ)⁻¹ • M i j ^ k)).PosSemidef := by + induction N with + | zero => + convert! (Matrix.PosSemidef.zero (n := ι) (R := ℂ)) using 1 + | succ N ih => + convert! + ih.add ((entry_pow_posSemidef hM N).smul (by positivity : (0:ℝ) ≤ (N.factorial : ℝ)⁻¹)) using 1 + ext i j + simp [Finset.sum_range_succ] + have ht (i j : ι) : Tendsto (fun N => ∑ k ∈ Finset.range N, + (k.factorial : ℝ)⁻¹ • M i j ^ k) atTop (𝓝 (Complex.exp (M i j))) := by + simpa [Complex.exp_eq_exp_ℂ] using + (NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) (M i j)).tendsto_sum_nat + refine ⟨?_,fun c => ?_⟩ + · ext i j + change conj (Complex.exp (M j i)) = Complex.exp (M i j) + rw [← Complex.exp_conj] + congr 1 + exact congrFun (congrFun hM.isHermitian i) j + · have hc : Tendsto (fun N => c.sum fun i a => c.sum fun j b => + star a * (∑ k ∈ Finset.range N, (k.factorial : ℝ)⁻¹ • M i j ^ k) * b) + atTop (𝓝 (c.sum fun i a => c.sum fun j b => star a * Complex.exp (M i j) * b)) := by + apply tendsto_finsetSum + intro i hi + apply tendsto_finsetSum + intro j hj + exact (tendsto_const_nhds.mul (ht i j)).mul tendsto_const_nhds + rw [Complex.nonneg_iff] + constructor + · exact ge_of_tendsto (Complex.continuous_re.tendsto _ |>.comp hc) + (.of_forall fun N => (Complex.nonneg_iff.mp ((hp N).2 c)).1) + · have hz : Tendsto (fun N => (c.sum fun i a => c.sum fun j b => + star a * (∑ k ∈ Finset.range N, (k.factorial : ℝ)⁻¹ • M i j ^ k) * b).im) + atTop (𝓝 (0 : ℝ)) := by + convert! tendsto_const_nhds using 1 + funext N + exact (Complex.nonneg_iff.mp ((hp N).2 c)).2.symm + exact (tendsto_nhds_unique hz (Complex.continuous_im.tendsto _ |>.comp hc)) + + +def kernel (d e : E) : ℂ := + Complex.exp ((-(‖d‖^2 : ℝ)/2 : ℝ) + ⟪d,e⟫_ℂ + (-(‖e‖^2 : ℝ)/2 : ℝ)) + +theorem kernel_posSemidef : (Matrix.of (kernel (E := E))).PosSemidef := by + let v : E → E := id + have h := entry_exp_posSemidef (gram_posSemidef v) + let w : E → ℂ := fun d => Complex.exp ((-(‖d‖^2 : ℝ)/2 : ℝ) : ℂ) + have hw := gram_posSemidef w + have hh : (Matrix.hadamard (Matrix.of fun i j => ⟪w i,w j⟫_ℂ) + (Matrix.of fun i j => Complex.exp ⟪v i,v j⟫_ℂ)).PosSemidef := hw.hadamard h + convert! hh using 1 + ext d e + simp only [kernel,w,v,Matrix.hadamard_apply,Matrix.of_apply,RCLike.inner_apply', + ← Complex.exp_conj,← Complex.exp_add,Complex.conj_ofReal,id_eq] + congr 1 + ring + +def PreSpace (E : Type*) := E →₀ ℂ +instance : AddCommGroup (PreSpace E) := inferInstanceAs (AddCommGroup (E →₀ ℂ)) +instance : Module ℂ (PreSpace E) := inferInstanceAs (Module ℂ (E →₀ ℂ)) + +def toFinsupp : PreSpace E ≃ₗ[ℂ] (E →₀ ℂ) := LinearEquiv.refl ℂ _ + + + +abbrev core : PreInnerProductSpace.Core ℂ (PreSpace E) where + inner x y := (toFinsupp x).sum fun d a => (toFinsupp y).sum fun e b => + conj a * kernel d e * b + conj_inner_symm x y := by + classical + simp only [Finsupp.sum,map_sum, map_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro d hd + apply Finset.sum_congr rfl + intro e he + have hk := congrFun (congrFun (kernel_posSemidef (E := E)).isHermitian d) e + simp only [Matrix.conjTranspose_apply,Matrix.of_apply,Complex.star_def] at hk + simp only [Complex.conj_conj] + rw [hk] + ring + re_inner_nonneg x := (Complex.nonneg_iff.mp ((kernel_posSemidef (E := E)).2 (toFinsupp x))).1 + add_left x y z := by + classical + simp [map_add,Finsupp.sum_add_index, add_mul,Finsupp.sum_add] + smul_left x y r := by + classical + simp [map_smul,Finsupp.sum_smul_index,map_mul,mul_assoc,Finsupp.mul_sum] + +instance : SeminormedAddCommGroup (PreSpace E) := + InnerProductSpace.Core.toSeminormedAddCommGroup (c := core (E := E)) +instance : InnerProductSpace ℂ (PreSpace E) := InnerProductSpace.ofCore (core (E := E)) + +abbrev Space (E : Type*) [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] := + UniformSpace.Completion (PreSpace E) + +def coherent (d : E) : Space E := + ↑(toFinsupp.symm (Finsupp.single d 1) : PreSpace E) + +@[simp] theorem inner_coherent (d e : E) : + ⟪coherent d, coherent e⟫_ℂ = kernel d e := by + classical + rw [coherent,coherent,UniformSpace.Completion.inner_coe] + change (Finsupp.single d (1:ℂ)).sum (fun d a => + (Finsupp.single e (1:ℂ)).sum fun e b => conj a * kernel d e * b) = _ + simp + +@[simp] theorem kernel_self (d : E) : kernel d d = 1 := by + unfold kernel + rw [inner_self_eq_norm_sq_to_K] + convert! Complex.exp_zero using 1 + congr 1 + push_cast + ring! + +@[simp] theorem norm_coherent (d : E) : ‖coherent d‖ = 1 := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),inner_coherent,kernel_self] + norm_num + +theorem kernel_eq (d e : E) : kernel d e = + Complex.exp (((-‖d-e‖^2/2 : ℝ) : ℂ) + ((⟪d,e⟫_ℂ).im : ℂ) * Complex.I) := by + unfold kernel + congr 1 + apply Complex.ext + · simp only [Complex.add_re,Complex.ofReal_re,Complex.mul_re,Complex.ofReal_im, + Complex.I_re,Complex.I_im,mul_zero,zero_mul,sub_zero] + rw [norm_sub_sq (𝕜 := ℂ)] + change _ = -(‖d‖^2 - 2*(⟪d,e⟫_ℂ).re+‖e‖^2)/2+0 + ring + · simp only [Complex.add_im,Complex.mul_im,Complex.I_re,Complex.I_im, + Complex.ofReal_re,Complex.ofReal_im,mul_zero,mul_one,zero_add,add_zero] + +theorem norm_kernel (d e : E) : ‖kernel d e‖ = Real.exp (-‖d-e‖^2/2) := by + rw [kernel_eq,Complex.norm_exp] + congr 1 + simp only [Complex.add_re,Complex.mul_re,Complex.I_re,Complex.I_im, + Complex.ofReal_re,Complex.ofReal_im,mul_zero,zero_mul,sub_zero,add_zero] + +def phase (d e : E) : ℂ := Complex.exp ((-(⟪d,e⟫_ℂ).im : ℝ) * Complex.I) + +@[simp] theorem norm_phase (d e : E) : ‖phase d e‖ = 1 := by + exact Complex.norm_exp_ofReal_mul_I _ + +@[simp] theorem phase_zero_left (e : E) : phase 0 e = 1 := by simp [phase] +@[simp] theorem phase_zero_right (d : E) : phase d 0 = 1 := by simp [phase] + + +theorem phase_cocycle (d e f : E) : + phase e f * phase d (e+f) = phase d e * phase (d+e) f := by + simp only [phase,← Complex.exp_add,inner_add_left,inner_add_right,Complex.add_im] + congr 1 + push_cast + ring + +theorem kernel_translate (d e f : E) : + conj (phase d e) * kernel (d+e) (d+f) * phase d f = kernel e f := by + simp only [phase,kernel,← Complex.exp_conj,← Complex.exp_add] + congr 1 + have hdd : ⟪d,d⟫_ℂ = ((‖d‖^2 : ℝ) : ℂ) := by + rw [inner_self_eq_norm_sq_to_K] + norm_cast + simp only [inner_add_left,inner_add_right,hdd] + apply Complex.ext + · simp only [Complex.add_re,Complex.mul_re,Complex.conj_re,Complex.ofReal_re, + Complex.ofReal_im,Complex.I_re,Complex.I_im,mul_zero,zero_mul,sub_zero] + rw [norm_add_sq (𝕜 := ℂ),norm_add_sq (𝕜 := ℂ)] + have hs := inner_re_symm (𝕜 := ℂ) d e + change (⟪d,e⟫_ℂ).re = (⟪e,d⟫_ℂ).re at hs + dsimp only [RCLike.re_to_complex] at * + linarith + · simp only [Complex.add_im,Complex.mul_im,Complex.conj_im,Complex.ofReal_re, + Complex.ofReal_im,Complex.I_re,Complex.I_im,mul_zero,mul_one,zero_add] + have hs := inner_im_symm (𝕜 := ℂ) d e + change (⟪d,e⟫_ℂ).im = -(⟪e,d⟫_ℂ).im at hs + linarith + + +def basis (e : E) : PreSpace E := toFinsupp.symm (Finsupp.single e 1) + +@[simp] theorem inner_basis (d e : E) : ⟪basis d,basis e⟫_ℂ = kernel d e := by + classical + change (Finsupp.single d (1:ℂ)).sum (fun d a => + (Finsupp.single e (1:ℂ)).sum fun e b => conj a * kernel d e * b) = _ + simp + +@[simp] theorem coe_basis (e : E) : (↑(basis e) : Space E) = coherent e := rfl + +def preWLinear (d : E) : PreSpace E →ₗ[ℂ] PreSpace E := + (Finsupp.linearCombination ℂ fun e => phase d e • basis (d+e)).comp toFinsupp.toLinearMap + +@[simp] theorem preWLinear_basis (d e : E) : + preWLinear d (basis e) = phase d e • basis (d+e) := by + classical + simp [preWLinear,basis] + +theorem inner_preW (d : E) (x y : PreSpace E) : + ⟪preWLinear d x,preWLinear d y⟫_ℂ = ⟪x,y⟫_ℂ := by + classical + change ⟪(toFinsupp x).sum (fun e a => a • phase d e • basis (d+e)), + (toFinsupp y).sum (fun f b => b • phase d f • basis (d+f))⟫_ℂ = + (toFinsupp x).sum (fun e a => (toFinsupp y).sum fun f b => conj a * kernel e f * b) + rw [Finsupp.sum_inner] + apply Finsupp.sum_congr + intro e he + rw [Finsupp.inner_sum] + apply Finsupp.sum_congr + intro f hf + simp only [inner_smul_left,inner_smul_right,inner_basis] + calc + _ = conj ((toFinsupp x) e) * + (conj (phase d e) * kernel (d+e) (d+f) * phase d f) * (toFinsupp y) f := by ring + _ = _ := by rw [kernel_translate] + +def preW (d : E) : PreSpace E →ₗᵢ[ℂ] PreSpace E where + toLinearMap := preWLinear d + norm_map' x := by rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),inner_preW, + ← norm_eq_sqrt_re_inner (𝕜 := ℂ)] + + +def W (d : E) : Space E →L[ℂ] Space E := (preW d).toContinuousLinearMap.completion + +@[simp] theorem W_coe (d : E) (x : PreSpace E) : W d ↑x = ↑(preWLinear d x) := + ContinuousLinearMap.completion_apply_coe _ _ + +@[simp] theorem W_coherent (d e : E) : W d (coherent e) = phase d e • coherent (d+e) := by + rw [← coe_basis,W_coe,preWLinear_basis,UniformSpace.Completion.coe_smul,coe_basis] + +@[simp] theorem norm_W (d : E) (x : Space E) : ‖W d x‖ = ‖x‖ := by + refine UniformSpace.Completion.induction_on x + (isClosed_eq ((W d).continuous.norm) continuous_norm) fun y => ?_ + rw [W_coe,UniformSpace.Completion.norm_coe,UniformSpace.Completion.norm_coe] + exact (preW d).norm_map y + +theorem inner_W (d : E) (x y : Space E) : ⟪W d x,W d y⟫_ℂ = ⟪x,y⟫_ℂ := by + refine UniformSpace.Completion.induction_on₂ x y + (isClosed_eq (((W d).continuous.comp continuous_fst).inner + ((W d).continuous.comp continuous_snd)) (continuous_fst.inner continuous_snd)) ?_ + intro x y + rw [W_coe,W_coe,UniformSpace.Completion.inner_coe, + UniformSpace.Completion.inner_coe,inner_preW] + +omit [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] in + +theorem sum_basis (x : PreSpace E) : + (toFinsupp x).sum (fun e a => a • basis e) = x := by + classical + apply toFinsupp.injective + simp only [Finsupp.sum,map_sum,map_smul,basis,LinearEquiv.apply_symm_apply, + Finsupp.smul_single,smul_eq_mul,mul_one] + exact Finsupp.sum_single _ + + +theorem ext_coherent {F : Type*} [NormedAddCommGroup F] [NormedSpace ℂ F] + {A B : Space E →L[ℂ] F} (h : ∀ e, A (coherent e) = B (coherent e)) : A = B := by + ext x + refine UniformSpace.Completion.induction_on x (isClosed_eq A.continuous B.continuous) fun y => ?_ + rw [← sum_basis y] + change (A.comp UniformSpace.Completion.toComplL) _ = + (B.comp UniformSpace.Completion.toComplL) _ + simp only [Finsupp.sum,map_sum,map_smul,ContinuousLinearMap.comp_apply, + UniformSpace.Completion.coe_toComplL,coe_basis] + apply Finset.sum_congr rfl + intro e he + rw [h] + +@[simp] theorem W_zero : W (0 : E) = ContinuousLinearMap.id ℂ (Space E) := by + apply ext_coherent + intro e + simp + + +theorem W_mul (d e : E) : (W d).comp (W e) = phase d e • W (d+e) := by + apply ext_coherent + intro f + simp only [ContinuousLinearMap.comp_apply,W_coherent,map_smul, + smul_apply,smul_smul,phase_cocycle,add_assoc] + +@[simp] theorem phase_neg_left (d : E) : phase (-d) d = 1 := by + have h : (⟪d,d⟫_ℂ).im = 0 := inner_self_im (𝕜 := ℂ) d + simp only [phase,inner_neg_left,Complex.neg_im,h,neg_zero, + Complex.ofReal_zero,zero_mul,Complex.exp_zero] + +@[simp] theorem phase_neg_right (d : E) : phase d (-d) = 1 := by + have h : (⟪d,d⟫_ℂ).im = 0 := inner_self_im (𝕜 := ℂ) d + simp only [phase,inner_neg_right,Complex.neg_im,h,neg_zero, + Complex.ofReal_zero,zero_mul,Complex.exp_zero] + + +def weyl (d : E) : Space E ≃ₗᵢ[ℂ] Space E where + toFun := W d + invFun := W (-d) + left_inv x := by + have h := congrArg (fun A : Space E →L[ℂ] Space E => A x) (W_mul (-d) d) + simpa using h + right_inv x := by + have h := congrArg (fun A : Space E →L[ℂ] Space E => A x) (W_mul d (-d)) + simpa using h + map_add' := (W d).map_add + map_smul' := (W d).map_smul + norm_map' := norm_W d + +@[simp] theorem weyl_apply (d : E) (x : Space E) : weyl d x = W d x := rfl + + +theorem norm_inner_translated_coherent (d e x y : E) : + ‖⟪W d (coherent x),W e (coherent y)⟫_ℂ‖ = Real.exp (-‖(d+x)-(e+y)‖^2/2) := by + simp only [W_coherent,inner_smul_left,inner_smul_right,inner_coherent, + norm_mul,RCLike.norm_conj,norm_phase,one_mul,norm_kernel] + + theorem continuous_kernel : Continuous (fun x : E × E => kernel x.1 x.2) := by + unfold kernel + fun_prop + + theorem continuous_phase : Continuous (fun x : E × E => phase x.1 x.2) := by + unfold phase + fun_prop + + theorem norm_sub_coherent (d e : E) : + ‖coherent d - coherent e‖ = Real.sqrt (2-2*(kernel d e).re) := by + rw [← Real.sqrt_sq (norm_nonneg (coherent d-coherent e)),norm_sub_sq (𝕜 := ℂ), + norm_coherent,norm_coherent,inner_coherent] + congr 1 + change (1:ℝ)^2 - 2*(kernel d e).re + 1^2 = 2 - 2*(kernel d e).re + ring + + theorem continuous_coherent : Continuous (coherent (E := E)) := by + rw [continuous_iff_continuousAt] + intro d + rw [ContinuousAt,tendsto_iff_norm_sub_tendsto_zero] + simp_rw [norm_sub_coherent] + have h : Continuous (fun x : E => kernel x d) := + continuous_kernel.comp (continuous_id.prodMk continuous_const) + have hs : Continuous (fun x : E => Real.sqrt (2-2*(kernel x d).re)) := by + fun_prop + simpa using hs.tendsto d + +section SecondQuantization +variable {E' : Type*} [SeminormedAddCommGroup E'] [InnerProductSpace ℂ E'] + + +def preGammaLinear (T : E →ₗᵢ[ℂ] E') : PreSpace E →ₗ[ℂ] PreSpace E' := + (Finsupp.linearCombination ℂ fun e => basis (T e)).comp toFinsupp.toLinearMap + +@[simp] theorem preGammaLinear_basis (T : E →ₗᵢ[ℂ] E') (e : E) : + preGammaLinear T (basis e) = basis (T e) := by + classical + simp [preGammaLinear,basis] + +@[simp] theorem kernel_map (T : E →ₗᵢ[ℂ] E') (d e : E) : kernel (T d) (T e) = kernel d e := by + simp [kernel] + +@[simp] theorem phase_map (T : E →ₗᵢ[ℂ] E') (d e : E) : phase (T d) (T e) = phase d e := by + simp [phase] + +theorem inner_preGamma (T : E →ₗᵢ[ℂ] E') (x y : PreSpace E) : + ⟪preGammaLinear T x,preGammaLinear T y⟫_ℂ = ⟪x,y⟫_ℂ := by + classical + change ⟪(toFinsupp x).sum (fun e a => a • basis (T e)), + (toFinsupp y).sum (fun f b => b • basis (T f))⟫_ℂ = + (toFinsupp x).sum (fun e a => (toFinsupp y).sum fun f b => conj a * kernel e f * b) + rw [Finsupp.sum_inner] + apply Finsupp.sum_congr + intro e he + rw [Finsupp.inner_sum] + apply Finsupp.sum_congr + intro f hf + simp only [inner_smul_left,inner_smul_right,inner_basis,kernel_map] + ring + +def preGamma (T : E →ₗᵢ[ℂ] E') : PreSpace E →ₗᵢ[ℂ] PreSpace E' where + toLinearMap := preGammaLinear T + norm_map' x := by rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),inner_preGamma, + ← norm_eq_sqrt_re_inner (𝕜 := ℂ)] + +def Gamma (T : E →ₗᵢ[ℂ] E') : Space E →L[ℂ] Space E' := + (preGamma T).toContinuousLinearMap.completion + +@[simp] theorem Gamma_coe (T : E →ₗᵢ[ℂ] E') (x : PreSpace E) : + Gamma T ↑x = ↑(preGammaLinear T x) := ContinuousLinearMap.completion_apply_coe _ _ + +@[simp] theorem Gamma_coherent (T : E →ₗᵢ[ℂ] E') (e : E) : + Gamma T (coherent e) = coherent (T e) := by + rw [← coe_basis,Gamma_coe,preGammaLinear_basis,coe_basis] + +@[simp] theorem norm_Gamma (T : E →ₗᵢ[ℂ] E') (x : Space E) : ‖Gamma T x‖ = ‖x‖ := by + refine UniformSpace.Completion.induction_on x + (isClosed_eq ((Gamma T).continuous.norm) continuous_norm) fun y => ?_ + rw [Gamma_coe,UniformSpace.Completion.norm_coe,UniformSpace.Completion.norm_coe] + exact (preGamma T).norm_map y + + +theorem Gamma_W (T : E →ₗᵢ[ℂ] E') (d : E) : + (Gamma T).comp (W d) = (W (T d)).comp (Gamma T) := by + apply ext_coherent + intro e + simp only [ContinuousLinearMap.comp_apply,W_coherent,Gamma_coherent,map_smul, + phase_map,map_add] + +end SecondQuantization + +@[simp] theorem Gamma_id : Gamma ((LinearIsometry.id : E →ₗᵢ[ℂ] E)) = ContinuousLinearMap.id ℂ (Space E) := by + apply ext_coherent + intro e + simp + +theorem Gamma_comp {E' E'' : Type*} + [SeminormedAddCommGroup E'] [InnerProductSpace ℂ E'] + [SeminormedAddCommGroup E''] [InnerProductSpace ℂ E''] + (T : E →ₗᵢ[ℂ] E') (S : E' →ₗᵢ[ℂ] E'') : + (Gamma S).comp (Gamma T) = Gamma (S.comp T) := by + apply ext_coherent + intro e + simp + + +def secondQuantization {E' : Type*} [SeminormedAddCommGroup E'] [InnerProductSpace ℂ E'] + (T : E ≃ₗᵢ[ℂ] E') : Space E ≃ₗᵢ[ℂ] Space E' where + toFun := Gamma T.toLinearIsometry + invFun := Gamma T.symm.toLinearIsometry + left_inv x := by + have h := congrArg (fun A : Space E →L[ℂ] Space E => A x) + (Gamma_comp T.toLinearIsometry T.symm.toLinearIsometry) + have hc : T.symm.toLinearIsometry.comp T.toLinearIsometry = (LinearIsometry.id : E →ₗᵢ[ℂ] E) := by + ext e + simp + simpa [hc] using h + right_inv x := by + have h := congrArg (fun A : Space E' →L[ℂ] Space E' => A x) + (Gamma_comp T.symm.toLinearIsometry T.toLinearIsometry) + have hc : T.toLinearIsometry.comp T.symm.toLinearIsometry = (LinearIsometry.id : E' →ₗᵢ[ℂ] E') := by + ext e + simp + simpa [hc] using h + map_add' := (Gamma T.toLinearIsometry).map_add + map_smul' := (Gamma T.toLinearIsometry).map_smul + norm_map' := norm_Gamma T.toLinearIsometry + + +theorem coe_eq_sum (x : PreSpace E) : (↑x : Space E) = + (toFinsupp x).sum (fun e a => a • coherent e) := by + classical + have h := congrArg (UniformSpace.Completion.toComplL : PreSpace E →L[ℂ] Space E) + (sum_basis x) + simpa only [Finsupp.sum,map_sum,map_smul,UniformSpace.Completion.coe_toComplL,coe_basis] + using h.symm + +theorem tendsto_norm_separated (d e x y : E) (hne : 0 < ‖d-e‖) : + Tendsto (fun r : ℝ => ‖(r • d+x)-(r • e+y)‖) atTop atTop := by + have h : Tendsto (fun r : ℝ => ‖d-e‖*r-‖x-y‖) atTop atTop := by + rw [tendsto_atTop] + intro b + filter_upwards [eventually_ge_atTop ((b+‖x-y‖)/‖d-e‖)] with r hr + have hh := (div_le_iff₀ hne).mp hr + linarith + refine tendsto_atTop_mono' atTop ?_ h + filter_upwards [eventually_ge_atTop (0:ℝ)] with r hr + have hl := norm_sub_norm_le (r • (d-e)) (-(x-y)) + simp only [norm_smul,Real.norm_of_nonneg hr,norm_neg,sub_neg_eq_add] at hl + have heq : r • (d-e)+(x-y) = (r • d+x)-(r • e+y) := by module + rw [heq] at hl + simpa only [mul_comm] using hl + + +theorem tendsto_inner_translated_coherent (d e x y : E) (hne : 0 < ‖d-e‖) : + Tendsto (fun r : ℝ => ⟪W (r • d) (coherent x),W (r • e) (coherent y)⟫_ℂ) + atTop (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + simp_rw [norm_inner_translated_coherent] + have ht := (tendsto_pow_atTop (by norm_num : (2:ℕ) ≠ 0)).comp + (tendsto_norm_separated d e x y hne) + have hh := ht.const_mul_atTop (by positivity : (0:ℝ) < (2:ℝ)⁻¹) + convert! Real.tendsto_exp_atBot.comp (tendsto_neg_atTop_atBot.comp hh) using 1 + funext r + congr 1 + dsimp only [Function.comp_def] + ring + + +theorem tendsto_inner_translated_pre (d e : E) (hne : 0 < ‖d-e‖) (x y : PreSpace E) : + Tendsto (fun r : ℝ => ⟪W (r • d) (↑x),W (r • e) (↑y)⟫_ℂ) atTop (𝓝 0) := by + classical + simp_rw [coe_eq_sum,Finsupp.sum,map_sum,map_smul,sum_inner,inner_sum, + inner_smul_left,inner_smul_right] + convert! (tendsto_finsetSum (toFinsupp x).support fun a ha => + tendsto_finsetSum (toFinsupp y).support fun b hb => + tendsto_const_nhds.mul (tendsto_const_nhds.mul + (tendsto_inner_translated_coherent d e a b hne))) using 1 + simp + + +theorem inner_translate_approx (d e : E) (x x' y y' : Space E) : + ‖⟪W d x,W e y⟫_ℂ‖ ≤ ‖x-x'‖ * ‖y‖ + ‖x'‖ * ‖y-y'‖ + ‖⟪W d x',W e y'⟫_ℂ‖ := by + have heq : ⟪W d x,W e y⟫_ℂ = + ⟪W d (x-x'),W e y⟫_ℂ + ⟪W d x',W e (y-y')⟫_ℂ + ⟪W d x',W e y'⟫_ℂ := by + simp only [map_sub,inner_sub_left,inner_sub_right] + ring + rw [heq] + calc + _ ≤ ‖⟪W d (x-x'),W e y⟫_ℂ‖ + ‖⟪W d x',W e (y-y')⟫_ℂ‖ + ‖⟪W d x',W e y'⟫_ℂ‖ := + (norm_add_le _ _).trans (add_le_add (norm_add_le _ _) le_rfl) + _ ≤ _ := by + gcongr + · simpa only [norm_W] using norm_inner_le_norm (W d (x-x')) (W e y) + · simpa only [norm_W] using norm_inner_le_norm (W d x') (W e (y-y')) + + + +theorem tendsto_inner_translated (d e : E) (hne : 0 < ‖d-e‖) (x y : Space E) : + Tendsto (fun r : ℝ => ⟪W (r • d) x,W (r • e) y⟫_ℂ) atTop (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero,Metric.tendsto_nhds] + intro ε hε + obtain ⟨x',hx⟩ := Metric.denseRange_iff.mp + (UniformSpace.Completion.denseRange_coe (α := PreSpace E)) x + (ε/(4*(‖y‖+1))) (by positivity) + obtain ⟨y',hy⟩ := Metric.denseRange_iff.mp + (UniformSpace.Completion.denseRange_coe (α := PreSpace E)) y + (ε/(4*(‖(↑x' : Space E)‖+1))) (by positivity) + rw [dist_eq_norm,lt_div_iff₀ (by positivity)] at hx hy + have hx' : ‖x-(↑x' : Space E)‖ * ‖y‖ < ε/4 := by + nlinarith [norm_nonneg (x-(↑x' : Space E))] + have hy' : ‖(↑x' : Space E)‖ * ‖y-(↑y' : Space E)‖ < ε/4 := by + nlinarith [norm_nonneg (y-(↑y' : Space E))] + have ht := tendsto_inner_translated_pre d e hne x' y' + have he : ∀ᶠ r : ℝ in atTop, ‖⟪W (r • d) (↑x'),W (r • e) (↑y')⟫_ℂ‖ < ε/2 := by + have ht' : Tendsto (fun r : ℝ => ‖⟪W (r • d) (↑x'),W (r • e) (↑y')⟫_ℂ‖) + atTop (𝓝 (0:ℝ)) := by simpa using ht.norm + exact ht'.eventually_lt_const (half_pos hε) + filter_upwards [he] with r hr + rw [dist_zero_right,Real.norm_of_nonneg (norm_nonneg _)] + have hb := inner_translate_approx (r • d) (r • e) x (↑x') y (↑y') + linarith + +theorem continuous_W_coherent (x : E) : Continuous (fun d : E => W d (coherent x)) := by + have hp : Continuous (fun d : E => phase d x) := + continuous_phase.comp (continuous_id.prodMk continuous_const) + have hc : Continuous (fun d : E => coherent (d+x)) := + continuous_coherent.comp (continuous_id.add continuous_const) + simp_rw [W_coherent] + convert! hp.smul hc using 1 + +theorem continuous_W_coe (x : PreSpace E) : Continuous (fun d : E => W d (↑x)) := by + classical + simp only [coe_eq_sum,Finsupp.sum,map_sum,map_smul] + apply continuous_finsetSum + intro e he + exact (continuous_const (y := (toFinsupp x) e)).smul (continuous_W_coherent e) + + +theorem continuous_W (x : Space E) : Continuous (fun d : E => W d x) := by + rw [continuous_iff_continuousAt] + intro d + rw [ContinuousAt,Metric.tendsto_nhds] + intro ε hε + obtain ⟨x',hx⟩ := Metric.denseRange_iff.mp + (UniformSpace.Completion.denseRange_coe (α := PreSpace E)) x (ε/4) (by positivity) + have he := Metric.tendsto_nhds.mp ((continuous_W_coe x').tendsto d) (ε/2) (by positivity) + filter_upwards [he] with a ha + have h1 : dist (W a x) (W a (↑x')) = dist x (↑x' : Space E) := + (weyl a).isometry.dist_eq _ _ + have h2 : dist (W d (↑x')) (W d x) = dist x (↑x' : Space E) := by + rw [← weyl_apply,← weyl_apply,(weyl d).isometry.dist_eq,dist_comm] + have ht1 := dist_triangle (W a x) (W a (↑x')) (W d x) + have ht2 := dist_triangle (W a (↑x')) (W d (↑x')) (W d x) + rw [h1] at ht1 + rw [h2] at ht2 + linarith + + +theorem tendsto_W {α : Type*} {l : Filter α} {ds : α → E} {xs : α → Space E} + {d : E} {x : Space E} (hd : Tendsto ds l (𝓝 d)) (hx : Tendsto xs l (𝓝 x)) : + Tendsto (fun a => W (ds a) (xs a)) l (𝓝 (W d x)) := by + rw [Metric.tendsto_nhds] + intro ε hε + have he1 := Metric.tendsto_nhds.mp hx (ε/2) (by positivity) + have he2 := Metric.tendsto_nhds.mp (((continuous_W x).tendsto d).comp hd) + (ε/2) (by positivity) + filter_upwards [he1,he2] with a ha hb + have heq : dist (W (ds a) (xs a)) (W (ds a) x) = dist (xs a) x := + (weyl (ds a)).isometry.dist_eq _ _ + have ht := dist_triangle (W (ds a) (xs a)) (W (ds a) x) (W d x) + rw [heq] at ht + dsimp only [Function.comp_def] at hb + linarith + +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/HasDerivAtDeviation.lean b/lean/OAI/Probability/ParisiFinite/HasDerivAtDeviation.lean new file mode 100644 index 0000000000000000000000000000000000000000..bd9f853b5ac5159b091e908ac64a2d51ad41a0cc --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/HasDerivAtDeviation.lean @@ -0,0 +1,634 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Mix + +namespace OAI + +/-! Has Deriv At Deviation. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + +lemma hasDerivAt_deviation (hW : IsBrownianReal W P) (hβ : 0<β) + (c : BoundedCoefficient β) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) : + HasDerivAt (deviation P W hβ c) (c.expectedSquareCurvature P W hβ t-1) t := + (hasDerivAt_expectedProduct_self hW hβ c t ht).sub (hasDerivAt_id t) + + + +theorem minimizingParisi_replicon (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {t : OrderPoint} (ht : t∈(ρ:Measure OrderPoint).support) + (h0 : 0<(t:ℝ)) (h1 : (t:ℝ)<1) : + (ofMeasure β ρ).expectedSquareCurvature P W hβ t≤1 := by + by_contra hn + have hp : 0<(ofMeasure β ρ).expectedSquareCurvature P W hβ t-1 := sub_pos.mpr (not_le.mp hn) + let c := ofMeasure β ρ + let g := deviation P W hβ c + have hg : Continuous g := continuous_deviation hW hβ c + have ht0 : g t=0 := minimizingParisi_deviation_interior hW hβ hρ ht h0 h1 + have hs := ((hasDerivAt_deviation hW hβ c t ⟨h0,h1⟩).tendsto_slope.mono_left + (nhdsGT_le_nhdsNE (t:ℝ))).eventually (lt_mem_nhds hp) + have hev : ∀ᶠ s in 𝓝[>] (t:ℝ),0 (hsub hs).1.le) ⟨u,⟨hu.le,le_rfl⟩,(hsub ⟨hu,le_rfl⟩).1⟩ + have hmin := minimizingParisi_support_potential hW hβ hρ ht + ⟨u,(h0.trans hu).le,hu1.le⟩ + have hadd := intervalIntegral.integral_add_adjacent_intervals + (hg.intervalIntegrable (μ := volume) (t:ℝ) u) (hg.intervalIntegrable (μ := volume) u 1) + change (∫ s in (t:ℝ)..1,g s)≤∫ s in u..1,g s at hmin + linarith + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + +theorem minimizingParisi_support_endpoint (hW : IsBrownianReal W P) (hβ : (1:ℝ)<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) : + ∃ q : OrderPoint, 0<(q:ℝ) ∧ (q:ℝ)<1 ∧ + q∈(ρ:Measure OrderPoint).support ∧ ∀ t∈(ρ:Measure OrderPoint).support,t≤q := by + have hbp : 0<β := by exact_mod_cast (zero_lt_one.trans hβ) + obtain ⟨q,hq⟩ := (ρ:Measure OrderPoint).isClosed_support.isCompact.exists_isGreatest + ((ρ:Measure OrderPoint).nonempty_support (by exact NeZero.ne _)) + have h1 : (q:ℝ)<1 := lt_of_le_of_ne q.property.2 (by + intro he + apply minimizingParisi_one_not_mem_support hW hbp hρ + simpa only [show q=(⟨1,by simp⟩ : OrderPoint) from Subtype.ext he] using hq.1) + have h0 : 0<(q:ℝ) := by + by_contra hn + have hz : (q:ℝ)=0 := le_antisymm (not_lt.mp hn) q.property.1 + have hb : ∀ᵐ t : OrderPoint ∂(ρ:Measure OrderPoint),(t:ℝ)≤(0:ℝ) := by + filter_upwards [(ρ:Measure OrderPoint).support_mem_ae] with t ht + exact le_trans (show (t:ℝ)≤q from hq.2 ht) (hz.le) + have hi : (∫ t : OrderPoint,(t:ℝ) ∂(ρ:Measure OrderPoint))≤0 := + integral_nonpos_of_ae hb + exact (not_lt_of_ge hi) (minimizingParisi_mean_pos β hβ hρ) + exact ⟨q,h0,h1,hq.1,hq.2⟩ + + + +theorem minimizingParisi_diffusion_square (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {t : OrderPoint} (ht : t∈(ρ:Measure OrderPoint).support) : + (∫ ω,(fieldGradient β (measureCoefficient ρ β) ⟨t,t.property.1⟩ + (ParisiPath.solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω) t))^2 ∂P)=(t:ℝ) := by + have hh := minimizingParisi_selfConsistency hW hβ hρ ht + change (∫ ω,((ofMeasure β ρ).spin + (solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω)) t)* + ((ofMeasure β ρ).spin (solution ((ofMeasure β ρ).driftData hβ) (brownianPath W ω)) t) ∂P)=_ at hh + convert hh using 1 + apply integral_congr_ae + filter_upwards [] with ω + rw [spin_eq _ _ _ t.property,extend_of_mem _ t.property] + have he : Real.toNNReal (t:ℝ)=(⟨t,t.property.1⟩ : ℝ≥0) := by + apply NNReal.coe_injective + exact Real.coe_toNNReal _ t.property.1 + simp only [ofMeasure,pow_two,he] + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient + +lemma measureCoefficient_after_support (ρ : ProbabilityMeasure OrderPoint) (β : ℝ≥0) + (q : OrderPoint) (hq : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) + (r : ℝ≥0) (hr : (q:ℝ)≤r) : measureCoefficient ρ β r=β := by + have he : {x : OrderPoint | (x:ℝ)≤r}=ᵐ[(ρ:Measure OrderPoint)] univ := by + filter_upwards [(ρ:Measure OrderPoint).support_mem_ae] with x hx + change ((x:ℝ)≤r) = True + exact propext (iff_true_intro ((show (x:ℝ)≤q from hq x hx).trans hr)) + have hm : (ρ:Measure OrderPoint).real {x : OrderPoint | (x:ℝ)≤r}=1 := by + rw [Measure.real,measure_congr he,measure_univ,ENNReal.toReal_one] + simp [measureCoefficient,hm] + +lemma dyadicSchedule_congr_future {γ δ : ℝ≥0 → ℝ≥0} {q : ℝ≥0} + (h : ∀ r,q≤r → γ r=δ r) (u : Bool) (t d : ℝ≥0) (ht : q≤t) (n : ℕ) : + dyadicSchedule γ u t d n=dyadicSchedule δ u t d n := by + induction n generalizing t d with + | zero => + simp only [dyadicSchedule] + rw [h _ (by split_ifs; exact ht.trans (le_add_of_nonneg_right d.2); exact ht)] + | succ n ih => + simp only [dyadicSchedule] + rw [ih t (d/2) ht,ih (t+d/2) (d/2) (ht.trans (le_add_of_nonneg_right (by positivity)))] + +lemma field_final_plateau (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (q : ℝ≥0) (hq : q≤1) (h : ∀ r,q≤r → γ r=β) (x : ℝ) : + field β γ q x=terminal β x+(β:ℝ)*(1-(q:ℝ))/2 := by + have he : field β γ q x=dyadicEvolution (fun _ => β) q (1-q) (terminal β) x := by + unfold field dyadicEvolution + apply congrArg sSup + apply congrArg Set.range + funext n + rw [dyadicSchedule_congr_future h false q (1-q) le_rfl n] + rw [he,dyadicEvolution_constant (terminal_lipschitz (β := (β:ℝ)) hβ) β q (1-q) x,step_terminal (β := (β:ℝ)) hβ, + Real.sq_sqrt (NNReal.coe_nonneg _),NNReal.coe_sub hq,NNReal.coe_one] + +lemma fieldGradient_final_plateau (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (q : ℝ≥0) (hq : q≤1) (h : ∀ r,q≤r → γ r=β) (x : ℝ) : + fieldGradient β γ q x=Real.tanh ((β:ℝ)*x) := by + unfold fieldGradient + have he : field β γ q=fun y => terminal β y+(β:ℝ)*(1-(q:ℝ))/2 := + funext (field_final_plateau β hβ q hq h) + rw [he] + exact ((hasDerivAt_terminal hβ x).add_const _).deriv + +lemma fieldCurvature_final_plateau (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (q : ℝ≥0) (hq : q≤1) (h : ∀ r,q≤r → γ r=β) (x : ℝ) : + fieldCurvature β γ q x=(β:ℝ)*(1-(fieldGradient β γ q x)^2) := by + have he : fieldGradient β γ q=fun y => Real.tanh ((β:ℝ)*y) := + funext (fieldGradient_final_plateau β hβ q hq h) + rw [fieldCurvature,he] + rw [(hasDerivAt_tanh_scaled β x).deriv] + exact terminal_curvature_identity β hβ x + +end ParisiFinite + +namespace ParisiFinite +open ParisiPath BoundedCoefficient +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + + + +theorem minimizingParisi_endpoint_bound (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hq : q∈(ρ:Measure OrderPoint).support) + (hqmax : ∀ t∈(ρ:Measure OrderPoint).support,t≤q) + (h0 : 0<(q:ℝ)) (h1 : (q:ℝ)<1) : 1-(q:ℝ)≤1/(β:ℝ) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let c := ofMeasure β ρ + let X (ω : Ω) := solution (c.driftData hβ) (brownianPath W ω) + let a (ω : Ω) := c.curvature (X ω) q + let m (ω : Ω) := c.spin (X ω) q + have ha : Integrable a P := Integrable.of_bound + (c.curvature_aestronglyMeasurable hW hβ _ q) (β:ℝ) + (ae_of_all _ fun ω => c.norm_curvature_le hβ (X ω) q) + have ha2 : Integrable (fun ω => (a ω)^2) P := c.curvature_square_integrable hW hβ _ q + have hm2 : Integrable (fun ω => (m ω)^2) P := by + simpa only [pow_two] using c.spin_product_integrable hW c hβ (c.driftData hβ) q + have hms : (∫ ω,(m ω)^2 ∂P)=(q:ℝ) := by + simpa only [expectedProduct,pow_two] using minimizingParisi_selfConsistency hW hβ hρ hq + have hp : ∀ r : ℝ≥0,Real.toNNReal (q:ℝ)≤r → measureCoefficient ρ β r=β := by + intro r hr + apply measureCoefficient_after_support ρ β q hqmax r + exact (Real.coe_toNNReal _ q.property.1).symm.le.trans (NNReal.coe_le_coe.mpr hr) + have hae (ω : Ω) : a ω=(β:ℝ)*(1-(m ω)^2) := by + dsimp only [a,m] + rw [curvature_eq _ _ _ q.property,spin_eq _ _ _ q.property] + exact fieldCurvature_final_plateau β hβ (Real.toNNReal q) + (by exact_mod_cast (show (Real.toNNReal (q:ℝ):ℝ)≤1 by rw [Real.coe_toNNReal _ q.property.1];exact q.property.2)) hp _ + have ham : (∫ ω,a ω ∂P)=(β:ℝ)*(1-(q:ℝ)) := by + simp_rw [hae] + rw [integral_const_mul,integral_sub (integrable_const (1:ℝ)) hm2, + integral_const,probReal_univ,one_smul,hms] + let A : ℝ := ∫ ω,a ω ∂P + have hv : A^2≤∫ ω,(a ω)^2 ∂P := by + have hnon : 0≤∫ ω,(a ω-A)^2 ∂P := integral_nonneg fun ω => sq_nonneg _ + have he : (fun ω => (a ω-A)^2)=(fun ω => (a ω)^2-2*A*a ω+A^2) := by funext ω;ring + have hi : Integrable (fun ω => (a ω)^2-2*A*a ω) P := ha2.sub (ha.const_mul (2*A)) + rw [he,integral_add hi (integrable_const (A^2)), + integral_sub (f := fun ω => (a ω)^2) (g := fun ω => 2*A*a ω) ha2 (ha.const_mul (2*A)), + integral_const_mul,integral_const,probReal_univ,one_smul] at hnon + change 0≤(∫ ω,(a ω)^2 ∂P)-2*A*A+A^2 at hnon + nlinarith + have hr : (∫ ω,(a ω)^2 ∂P)≤1 := minimizingParisi_replicon hW hβ hρ hq h0 h1 + have hb : (β:ℝ)*(1-(q:ℝ))≤1 := by + change (∫ ω,a ω ∂P)^2≤_ at hv + rw [ham] at hv + nlinarith + exact (le_div_iff₀ (show (0:ℝ)<β from hβ)).mpr (by simpa only [mul_comm] using hb) + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient + +lemma measureCoefficient_before_support (ρ : ProbabilityMeasure OrderPoint) (β : ℝ≥0) + (q : OrderPoint) (hq : ∀ t∈(ρ:Measure OrderPoint).support,q≤t) + (r : ℝ≥0) (hr : (r:ℝ) + simp only [dyadicSchedule,Bool.false_eq_true,↓reduceIte] + rw [h t (lt_of_lt_of_le (lt_add_of_pos_right t hd) ht)] + | succ n ih => + simp only [dyadicSchedule] + rw [ih t (d/2) (by positivity) (by nlinarith), + ih (t+d/2) (d/2) (by positivity) (by nlinarith)] + +lemma field_lipschitz (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (_ : ∀ s,γ s≤β) (t : ℝ≥0) : + LipschitzWith 1 (field β γ t) := + dyadicEvolution_lipschitz (terminal_lipschitz hβ) hγ t (1-t) + +lemma field_initial_heat (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s,γ s≤β) {q : ℝ≥0} (hq : q≤1) + (hg : ∀ s,s 0) t (q-t) (field β γ q) x := by + unfold dyadicEvolution + apply congrArg sSup + apply congrArg Set.range + funext n + rw [dyadicSchedule_congr_initial hg t (q-t) (tsub_pos_iff_lt.mpr ht) + (by rw [add_tsub_cancel_of_le ht.le]) n] + rw [he,dyadicEvolution_constant (field_lipschitz β hβ hγ hb q) 0 t (q-t) x,NNReal.coe_sub ht.le] + rfl + +lemma hasDerivAt_step_mean {L C : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) (hg : Continuous g) (hd : ∀ x,HasDerivAt f (g x) x) + (hb : ∀ x,‖g x‖≤C) (s x : ℝ) : + HasDerivAt (step 0 s f) (step 0 s g x) x := by + have he : step 0 s f=(fun y => ∫ z,f (y+s*z) ∂gaussianReal 0 1) := funext (step_mean s f) + rw [he,step_mean] + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball x 1) (bound := fun _ => (C:ℝ)) + (F' := fun y z => g (y+s*z)) + (Metric.ball_mem_nhds _ zero_lt_one) ?_ ?_ ?_ ?_ ?_ ?_).2 + · exact Eventually.of_forall fun y => + (hf.continuous.comp (continuous_const.add (continuous_const.mul continuous_id))).aestronglyMeasurable + · exact integrable_shift hf x s + · exact (hg.comp (continuous_const.add (continuous_const.mul continuous_id))).aestronglyMeasurable + · exact ae_of_all _ fun z y _ => hb _ + · exact integrable_const _ + · exact ae_of_all _ fun z y _ => by + convert! (hd (y+s*z)).comp y ((hasDerivAt_id y).add_const (s*z)) using 1 + first | rfl | simp only [mul_one] + +lemma fieldGradient_initial_heat (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s,γ s≤β) {q : ℝ≥0} (hq : q≤1) + (hg : ∀ s,s by simpa only [Real.norm_eq_abs,NNReal.coe_one] using fieldGradient_bound β hβ hγ hb q y) + (Real.sqrt (q-t)) x + +lemma fieldCurvature_initial_heat (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s,γ s≤β) {q : ℝ≥0} (hq : q≤1) + (hg : ∀ s,s by simpa only [Real.norm_eq_abs] using fieldCurvature_abs β hβ hγ hb q y) + (Real.sqrt (q-t)) x + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite + +lemma bounded_lipschitz_square {L C : ℝ≥0} {f : ℝ → ℝ} + (hf : LipschitzWith L f) (hb : ∀ x,‖f x‖≤C) : + LipschitzWith (2*C*L) (fun x => f x^2) := by + rw [lipschitzWith_iff_norm_sub_le] + intro x y + have he : f x^2-f y^2=(f x-f y)*(f x+f y) := by ring + rw [he,norm_mul] + have hu : ‖f x+f y‖≤2*(C:ℝ) := (norm_add_le _ _).trans (by linarith [hb x,hb y]) + calc + _ ≤ ((L:ℝ)*‖x-y‖)*(2*(C:ℝ)) := mul_le_mul (hf.norm_sub_le x y) hu (norm_nonneg _) (by positivity) + _ = _ := by simp only [NNReal.coe_mul,NNReal.coe_ofNat];ring + +lemma step_mean_square_le {L C : ℝ≥0} {f : ℝ → ℝ} + (hf : LipschitzWith L f) (hb : ∀ x,‖f x‖≤C) (s x : ℝ) : + (step 0 s f x)^2 ≤ step 0 s (fun y => f y^2) x := by + have hm : MemLp (fun z => f (x+s*z)) 2 (gaussianReal 0 1) := + MemLp.of_bound (hf.continuous.comp (by fun_prop)).aestronglyMeasurable (C:ℝ) + (ae_of_all _ fun z => hb _) + have hh := variance_nonneg (X := fun z => f (x+s*z)) (μ := gaussianReal 0 1) + rw [variance_eq_sub hm] at hh + simp only [Pi.pow_apply] at hh + simp only [step_mean] + linarith + +lemma fieldCurvature_square_lipschitz (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s,γ s≤β) (t : ℝ≥0) : + LipschitzWith (2*β*(5*β^2)) (fun x => fieldCurvature β γ t x^2) := + bounded_lipschitz_square (fieldCurvature_lipschitz β hβ hγ hb t) + (fun x => fieldCurvature_abs β hβ hγ hb t x) + +lemma initial_heat_curvature_square_le (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s,γ s≤β) {q : ℝ≥0} (hq : q≤1) + (hg : ∀ s,s fieldCurvature β γ t x^2) 0≤ + step 0 (Real.sqrt q) (fun x => fieldCurvature β γ q x^2) 0 := by + rcases ht.eq_or_lt with rfl|ht + · exact le_rfl + have hh (x : ℝ) : fieldCurvature β γ t x^2≤ + step 0 (Real.sqrt ((q:ℝ)-(t:ℝ))) (fun y => fieldCurvature β γ q y^2) x := by + rw [fieldCurvature_initial_heat β hβ hγ hb hq hg ht] + exact step_mean_square_le (C:=β) (fieldCurvature_lipschitz β hβ hγ hb q) + (fun y => fieldCurvature_abs β hβ hγ hb q y) _ _ + have hl := step_le_of_le (fieldCurvature_square_lipschitz β hβ hγ hb t) + (step_lipschitz (fieldCurvature_square_lipschitz β hβ hγ hb q) (le_refl 0) + (Real.sqrt ((q:ℝ)-(t:ℝ)))) (le_refl 0) (Real.sqrt t) 0 hh + rw [step_semigroup (fieldCurvature_square_lipschitz β hβ hγ hb q), + Real.sq_sqrt t.coe_nonneg,Real.sq_sqrt (sub_nonneg.mpr (NNReal.coe_le_coe.mpr ht.le)), + add_sub_cancel] at hl + exact hl + +lemma step_mean_zero_eq_gaussian_integral {f : ℝ → ℝ} (hf : Measurable f) (t : ℝ≥0) : + step 0 (Real.sqrt t) f 0=∫ x,f x ∂gaussianReal 0 t := by + have hm : (gaussianReal 0 1).map (fun z : ℝ => Real.sqrt t*z)=gaussianReal 0 t := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext + change (Real.sqrt t)^2 * 1 = (t:ℝ) + rw [Real.sq_sqrt t.coe_nonneg,mul_one] + rw [step_mean] + simp only [zero_add] + rw [←integral_map (by fun_prop) hf.aestronglyMeasurable,hm] + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath +namespace BoundedCoefficient +variable {β : ℝ≥0} + +lemma solution_initial_heat (c : BoundedCoefficient β) (hβ : 0<β) + {q : ℝ≥0} (hg : ∀ s,s fieldCurvature β c.val t x^2) 0 := by + rw [step_mean_zero_eq_gaussian_integral + (fieldCurvature_square_lipschitz β hβ c.mono c.bound t).continuous.measurable] + calc + _ = ∫ ω,(fieldCurvature β c.val t (W t ω))^2 ∂P := by + apply integral_congr_ae + filter_upwards [brownianPath_eq_ae hW] with ω hω + have ht1 : (t:ℝ)≤1 := by exact_mod_cast ht.trans hq + rw [curvature_eq _ _ _ ⟨t.coe_nonneg,ht1⟩,extend_of_mem _ ⟨t.coe_nonneg,ht1⟩, + c.solution_initial_heat hβ hg _ _ (by exact_mod_cast ht),hω] + simp only [Real.toNNReal_coe] + rfl + _ = _ := (hW.hasLaw_eval t).integral_comp + (fieldCurvature_square_lipschitz β hβ c.mono c.bound t).continuous.aestronglyMeasurable + +lemma expectedSquareCurvature_initial_le (hW : IsBrownianReal W P) + (c : BoundedCoefficient β) (hβ : 0<β) {q : ℝ≥0} (hq : q≤1) + (hg : ∀ s,s fieldCurvature β c.val 0 z^2) h0 using 1 + simp only [Real.toNNReal_zero] + rfl + _ = _ := by simp + +end BoundedCoefficient +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite + +lemma fieldCurvature_not_constant (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s,γ s≤β) (t : ℝ≥0) : + ¬∃ k : ℝ,∀ x,fieldCurvature β γ t x=k := by + rintro ⟨k,hk⟩ + have hk0 : 0 fieldGradient β γ t x-k*x + have hd (x : ℝ) : HasDerivAt f 0 x := by + convert! (hasDerivAt_fieldGradient β hβ hγ hb t x).sub + ((hasDerivAt_id x).const_mul k) using 1 + simp [hk] + have he := is_const_of_deriv_eq_zero (fun x => (hd x).differentiableAt) + (fun x => (hd x).deriv) (3/k) 0 + have hk3 : k*(3/k)=3 := by field_simp + dsimp only [f] at he + rw [hk3,mul_zero,sub_zero] at he + have hb1 := (abs_le.mp (fieldGradient_bound β hβ hγ hb t (3/k))).2 + have hb0 := (abs_le.mp (fieldGradient_bound β hβ hγ hb t 0)).1 + linarith + +lemma fieldCurvature_gaussian_variance_pos (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s,γ s≤β) (t : ℝ≥0) {q : ℝ≥0} (hq : q≠0) : + 0 fieldCurvature_abs β hβ hγ hb t x) + apply lt_of_le_of_ne (variance_nonneg _ _) (Ne.symm ?_) + intro hz + have he := ae_eq_integral_of_variance_eq_zero hm hz + let : Measure.IsOpenPosMeasure (gaussianReal 0 q) := + (gaussianReal_absolutelyContinuous' 0 hq).isOpenPosMeasure + have hf := Measure.eq_of_ae_eq he hc continuous_const + exact fieldCurvature_not_constant β hβ hγ hb t + ⟨∫ x,fieldCurvature β γ t x ∂gaussianReal 0 q,fun x => congrFun hf x⟩ + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + +lemma minimizingParisi_least_support_eq_zero (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {q : OrderPoint} (hqs : q∈(ρ:Measure OrderPoint).support) + (hqleast : ∀ t∈(ρ:Measure OrderPoint).support,q≤t) : (q:ℝ)=0 := by + by_contra hq0 + have hqp : 0<(q:ℝ) := lt_of_le_of_ne q.property.1 (Ne.symm hq0) + have hq1 : (q:ℝ)<1 := lt_of_le_of_ne q.property.2 (by + intro he + apply minimizingParisi_one_not_mem_support hW hβ hρ + simpa only [show q=(⟨1,by simp⟩ : OrderPoint) from Subtype.ext he] using hqs) + let r : ℝ≥0 := ⟨q,q.property.1⟩ + let c := ofMeasure β ρ + let f : ℝ → ℝ := c.expectedSquareCurvature P W hβ + have hr0 : 0 + measureCoefficient_before_support ρ β q hqleast s hs + have hf : Continuous f := c.expectedSquareCurvature_continuous hW hβ + have hfq_le : f q≤1 := minimizingParisi_replicon hW hβ hρ hqs hqp hq1 + have hu (t : ℝ) (ht : t∈Icc (0:ℝ) (q:ℝ)) : f t≤1 := by + have ht' : Real.toNNReal t≤r := by + apply NNReal.coe_le_coe.mp + rw [Real.coe_toNNReal _ ht.1] + exact ht.2 + have hh := c.expectedSquareCurvature_initial_le hW hβ hr1 hg ht' + rw [Real.coe_toNNReal _ ht.1] at hh + exact hh.trans hfq_le + have hi : (∫ t in (0:ℝ)..(q:ℝ),f t)=(q:ℝ) := by + rw [←c.spin_mean_square_evolution hW hβ q ⟨hqp,hq1⟩] + exact minimizingParisi_selfConsistency hW hβ hρ hqs + have he (t : ℝ) (ht : t∈Icc (0:ℝ) (q:ℝ)) : f t=1 := by + by_contra hn + have hlt : f t<1 := lt_of_le_of_ne (hu t ht) hn + have hh := intervalIntegral.integral_lt_integral_of_continuousOn_of_le_of_exists_lt + hqp hf.continuousOn (continuous_const.continuousOn : ContinuousOn (fun _ : ℝ => (1:ℝ)) _) + (fun x hx => hu x ⟨hx.1.le,hx.2⟩) ⟨t,ht,hlt⟩ + rw [hi] at hh + simp at hh + have hzero : f 0=1 := he 0 ⟨le_rfl,hqp.le⟩ + have htop : f q=1 := he q ⟨hqp.le,le_rfl⟩ + let a := fieldCurvature β c.val r + have ha := (fieldCurvature_lipschitz β hβ c.mono c.bound r).continuous + have hm : MemLp a 2 (gaussianReal 0 r) := MemLp.of_bound ha.aestronglyMeasurable (β:ℝ) + (ae_of_all _ fun x => fieldCurvature_abs β hβ c.mono c.bound r x) + have hmean : fieldCurvature β c.val 0 0=∫ x,a x ∂gaussianReal 0 r := by + have hh := fieldCurvature_initial_heat β hβ c.mono c.bound hr1 hg hr0 0 + simpa only [NNReal.coe_zero,sub_zero,step_mean_zero_eq_gaussian_integral ha.measurable] using hh + have hsq : f q=∫ x,a x^2 ∂gaussianReal 0 r := by + have hh := c.expectedSquareCurvature_initial_heat hW hβ hr1 hg le_rfl + rw [step_mean_zero_eq_gaussian_integral (f:=fun x => fieldCurvature β c.val r x^2) + (show Measurable (fun x => fieldCurvature β c.val r x^2) from (ha.pow 2).measurable)] at hh + exact hh + have hz : fieldCurvature β c.val 0 0^2=1 := by + rw [←c.expectedSquareCurvature_zero hW hβ] + exact hzero + have hv : 0 restrictCode (c k)) := by + have he : (∏ k : Fin d,edgeFactor (a k.succ) (a k.castSucc) (c k.castSucc) (c k.succ))= + ∏ k : Fin d,edgeFactor (a k.succ) (a k.castSucc) (restrictCode (c k.castSucc)) (restrictCode (c k.succ)) := by + apply Finset.prod_congr rfl + intro k _ + apply edgeFactor_existing _ _ _ _ (hc _ _ (by change (k:ℕ)≤(k:ℕ)+1; omega)) i + exact hc k.succ (Fin.last d) (Fin.le_last _) _ _ hi + unfold hierarchyNumerator + rw [he,leafFactor_existing _ _ i hi] + ring + +lemma hierarchyNumerator_fresh {d r : ℕ} (a : Fin (d+1) → ℝ) + (c : Fin (d+1) → Fin (r+1) → ℕ) (hc : NestedCodes c) + (k : Fin d) (i : Fin r) (hi : restrictCode (c k.castSucc) i=c k.castSucc (Fin.last r)) + (hn : ∀ j,restrictCode (c k.succ) j≠c k.succ (Fin.last r)) : + hierarchyNumerator a c= + (a k.succ*((childLabels (restrictCode (c k.castSucc)) (restrictCode (c k.succ)) + (restrictCode (c k.castSucc) i)).card:ℝ)-a k.castSucc)* + hierarchyNumerator a (fun l => restrictCode (c l)) := by + let e (l : Fin d) := edgeFactor (a l.succ) (a l.castSucc) (c l.castSucc) (c l.succ) + let e' (l : Fin d) := edgeFactor (a l.succ) (a l.castSucc) (restrictCode (c l.castSucc)) (restrictCode (c l.succ)) + let A := a k.succ*((childLabels (restrictCode (c k.castSucc)) (restrictCode (c k.succ)) + (restrictCode (c k.castSucc) i)).card:ℝ)-a k.castSucc + have hek : e k=A*e' k := edgeFactor_fresh_child _ _ _ _ i hi hn + have hel : ∀ l,l≠k → e l=e' l := by + intro l hl + rcases lt_or_gt_of_ne hl with hl | hl + · apply edgeFactor_existing _ _ _ _ (hc _ _ (by change (l:ℕ)≤(l:ℕ)+1; omega)) i + apply hc l.succ k.castSucc (by change (l:ℕ)+1≤(k:ℕ); exact hl) _ _ hi + · apply edgeFactor_fresh_parent + intro j hj + apply hn j + exact hc k.succ l.castSucc (by change (k:ℕ)+1≤(l:ℕ); exact hl) _ _ hj + have hprod : (∏ l,e l)=A*∏ l,e' l := by + rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ k),← Finset.mul_prod_erase _ _ (Finset.mem_univ k)] + have hh : (∏ l∈Finset.univ.erase k,e l)=∏ l∈Finset.univ.erase k,e' l := + Finset.prod_congr rfl (fun l hl => hel l (Finset.mem_erase.mp hl).1) + rw [hek,hh] + ring + have hleaf : leafFactor (a (Fin.last d)) (c (Fin.last d))= + leafFactor (a (Fin.last d)) (restrictCode (c (Fin.last d))) := by + apply leafFactor_fresh + intro j hj + exact hn j (hc k.succ (Fin.last d) (Fin.le_last _) _ _ hj) + change (∏ l,e l)*_=A*((∏ l,e' l)*_) + rw [hprod,hleaf] + ring + +lemma codeLabels_one (c : Fin 1 → ℕ) : codeLabels c={c 0} := by + ext x + simp only [codeLabels_mem,Finset.mem_singleton] + exact ⟨fun ⟨i,hi⟩ => by fin_cases i; exact hi.symm,fun h => ⟨0,h.symm⟩⟩ + +lemma childLabels_one (p c : Fin 1 → ℕ) : childLabels p c (p 0)={c 0} := by + ext y + simp only [mem_childLabels,Finset.mem_singleton] + exact ⟨fun ⟨i,_,hi⟩ => by fin_cases i; exact hi.symm,fun h => ⟨0,rfl,h.symm⟩⟩ + +lemma edgeFactor_one (a b : ℝ) (p c : Fin 1 → ℕ) : edgeFactor a b p c=1 := by + simp [edgeFactor,codeLabels_one,childLabels_one] + +lemma leafFactor_one (a : ℝ) (c : Fin 1 → ℕ) : leafFactor a c=1 := by + have hn : labelCount c (c 0)=1 := by simp [labelCount,Finset.filter_singleton] + simp [leafFactor,codeLabels_one,hn] + +lemma hierarchyNumerator_one {d : ℕ} (a : Fin (d+1) → ℝ) (c : Fin (d+1) → Fin 1 → ℕ) : + hierarchyNumerator a c=1 := by simp [hierarchyNumerator,edgeFactor_one,leafFactor_one] + +lemma exists_hierarchy_branch {d r : ℕ} (hr : 0 ∃ i,restrictCode (c k) i=c k (Fin.last r)) + have hS : S.Nonempty := ⟨0,Finset.mem_filter.mpr ⟨Finset.mem_univ _,⟨⟨0,hr⟩,hroot _ _⟩⟩⟩ + let l := S.max' hS + have hl : ∃ i,restrictCode (c l) i=c l (Fin.last r) := (Finset.mem_filter.mp (Finset.max'_mem S hS)).2 + have hne : l≠Fin.last d := by + intro hh + obtain ⟨i,hi⟩ := hl + rw [hh] at hi + exact hleaf i hi + have hlt : (l:ℕ) overlapDiscount μ (q k)) c := by + induction r with + | zero => omega + | succ r ih => + by_cases hr0 : r=0 + · subst r + rw [hierarchy_one_real hG c q (fun k => (hq (Fin.le_last _)).trans_lt h1),hierarchyNumerator_one] + norm_num + have hr' : 0 restrictCode (c k)) (nestedCodes_restrict hc) + (fun i j => hroot i.castSucc j.castSucc) + have hf : (r.factorial:ℝ)=(r:ℝ)*((r-1).factorial:ℝ) := by + exact_mod_cast (Nat.mul_factorial_pred hr0).symm + simp only [Nat.add_sub_cancel] at * + by_cases hleaf : ∃ i,restrictCode (c (Fin.last d)) i=c (Fin.last d) (Fin.last r) + · obtain ⟨i,hi⟩ := hleaf + rw [hierarchyNumerator_existing _ c hc i hi,hf] + have he := GG_hierarchy_existing hG hgg hu c hc q hq h1 i hi + linear_combination ((r-1).factorial:ℝ)*he+ + ((clusterCount (restrictCode (c (Fin.last d))) i:ℝ)-overlapDiscount μ (q (Fin.last d)))*hold + · obtain ⟨k,i,hi,hn⟩ := exists_hierarchy_branch hr' c hroot (not_exists.mp hleaf) + obtain ⟨T,hT⟩ := exists_parentReps ((nestedCodes_restrict hc) k.castSucc k.succ + (by change (k:ℕ)≤(k:ℕ)+1; omega)) i + rw [hierarchyNumerator_fresh _ c hc k i hi hn,hf] + have he := GG_hierarchy_fresh hG hgg hu c hc q hq h1 k i hi hn hT + rw [hT.card_childLabels] at he + linear_combination ((r-1).factorial:ℝ)*he+ + (overlapDiscount μ (q k.succ)* + ((childLabels (restrictCode (c k.castSucc)) (restrictCode (c k.succ)) + (restrictCode (c k.castSucc) i)).card:ℝ)-overlapDiscount μ (q k.castSucc))*hold + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def splitCode {r : ℕ} (P : OrderedFinpartition r) (c : ∀ i,Fin (P.partSize i) → ℕ) : Fin r → ℕ := + fun j => let s := P.equivSigma.symm j; Nat.pair s.1.val (c s.1 s.2) + +lemma splitCode_emb {r : ℕ} (P : OrderedFinpartition r) (c : ∀ i,Fin (P.partSize i) → ℕ) + (i : Fin P.length) (j : Fin (P.partSize i)) : splitCode P c (P.emb i j)=Nat.pair i.val (c i j) := by + change (fun s : Σ i,Fin (P.partSize i) => Nat.pair s.1.val (c s.1 s.2)) + (P.equivSigma.symm (P.equivSigma ⟨i,j⟩))=_ + rw [P.equivSigma.symm_apply_apply] + +lemma pair_left_injective (i : ℕ) : Function.Injective (Nat.pair i) := + fun _ _ h => (Nat.pair_eq_pair.mp h).2 + +lemma codeLabels_split {r : ℕ} (P : OrderedFinpartition r) (c : ∀ i,Fin (P.partSize i) → ℕ) : + codeLabels (splitCode P c)=Finset.univ.biUnion + (fun i => (codeLabels (c i)).image (Nat.pair i.val)) := by + ext y + simp only [codeLabels_mem,Finset.mem_biUnion,Finset.mem_univ,true_and,Finset.mem_image] + constructor + · rintro ⟨j,hj⟩ + obtain ⟨⟨i,k⟩,rfl⟩ := P.equivSigma.surjective j + change splitCode P c (P.emb i k)=y at hj + rw [splitCode_emb] at hj + exact ⟨i,c i k,⟨k,rfl⟩,hj⟩ + · rintro ⟨i,x,hx,hy⟩ + obtain ⟨j,hj⟩ := hx + refine ⟨P.emb i j,?_⟩ + rw [splitCode_emb,hj,hy] + +lemma prod_codeLabels_split {r : ℕ} (P : OrderedFinpartition r) (c : ∀ i,Fin (P.partSize i) → ℕ) + (F : ℕ → ℝ) : + (∏ y∈codeLabels (splitCode P c),F y)=∏ i,∏ y∈codeLabels (c i),F (Nat.pair i.val y) := by + rw [codeLabels_split,Finset.prod_biUnion] + · apply Finset.prod_congr rfl + intro i _ + exact Finset.prod_image (pair_left_injective i.val).injOn + · intro i _ j _ hij + apply Finset.disjoint_left.mpr + intro y hi hj + obtain ⟨x,_,hx⟩ := Finset.mem_image.mp hi + obtain ⟨z,_,hz⟩ := Finset.mem_image.mp hj + exact hij (Fin.ext (Nat.pair_eq_pair.mp (hx.trans hz.symm)).1) + +lemma labelCount_split {r : ℕ} (P : OrderedFinpartition r) (c : ∀ i,Fin (P.partSize i) → ℕ) + (i : Fin P.length) (x : ℕ) : labelCount (splitCode P c) (Nat.pair i.val x)=labelCount (c i) x := by + have hcnt {n : ℕ} (f : Fin n → ℕ) (y : ℕ) : labelCount f y=∑ j,if f j=y then 1 else 0 := by + simp [labelCount] + rw [hcnt,← P.sum_sigma_eq_sum] + simp only [splitCode_emb,Nat.pair_eq_pair,Fin.val_inj] + rw [Finset.sum_eq_single i] + · simp only [true_and] + exact (hcnt _ _).symm + · intro j _ hji + simp [hji] + · simp + +lemma childLabels_split {r : ℕ} (P : OrderedFinpartition r) + (p c : ∀ i,Fin (P.partSize i) → ℕ) (i : Fin P.length) (x : ℕ) : + childLabels (splitCode P p) (splitCode P c) (Nat.pair i.val x)= + (childLabels (p i) (c i) x).image (Nat.pair i.val) := by + ext y + simp only [mem_childLabels,Finset.mem_image] + constructor + · rintro ⟨j,hp,hc⟩ + obtain ⟨⟨k,l⟩,rfl⟩ := P.equivSigma.surjective j + change splitCode P p (P.emb k l)=_ at hp + change splitCode P c (P.emb k l)=_ at hc + rw [splitCode_emb] at hp hc + have hki : k=i := Fin.ext (Nat.pair_eq_pair.mp hp).1 + subst k + exact ⟨c i l,⟨l,(Nat.pair_eq_pair.mp hp).2,rfl⟩,hc⟩ + · rintro ⟨z,hz,hy⟩ + obtain ⟨j,hp,hc⟩ := hz + refine ⟨P.emb i j,?_,?_⟩ + · rw [splitCode_emb,hp] + · rw [splitCode_emb,hc,hy] + +lemma leafFactor_split {r : ℕ} (a : ℝ) (P : OrderedFinpartition r) + (c : ∀ i,Fin (P.partSize i) → ℕ) : + leafFactor a (splitCode P c)=∏ i,leafFactor a (c i) := by + unfold leafFactor + rw [prod_codeLabels_split] + simp_rw [labelCount_split] + +lemma edgeFactor_split {r : ℕ} (a b : ℝ) (P : OrderedFinpartition r) + (p c : ∀ i,Fin (P.partSize i) → ℕ) : + edgeFactor a b (splitCode P p) (splitCode P c)=∏ i,edgeFactor a b (p i) (c i) := by + unfold edgeFactor + rw [prod_codeLabels_split] + simp_rw [childLabels_split,Finset.card_image_of_injective _ (pair_left_injective _)] + +lemma codeLabels_const {r : ℕ} (hr : 0 x)={x} := by + ext y + simp only [codeLabels_mem,Finset.mem_singleton] + exact ⟨fun ⟨_,h⟩ => h.symm,fun h => ⟨⟨0,hr⟩,h.symm⟩⟩ + +lemma labelCount_const (r x : ℕ) : labelCount (fun _ : Fin r => x) x=r := by + simp [labelCount] + +lemma leafFactor_const (a : ℝ) (r x : ℕ) : leafFactor a (fun _ : Fin r => x)=blockFactor a r := by + by_cases hr : r=0 + · subst r + simp [leafFactor,codeLabels,blockFactor] + · unfold leafFactor + rw [codeLabels_const (Nat.pos_of_ne_zero hr),Finset.prod_singleton,labelCount_const] + +lemma edgeFactor_root {r : ℕ} (a b : ℝ) (P : OrderedFinpartition r) : + edgeFactor a b (fun _ : Fin r => 0) (splitCode P (fun _ _ => 0))=branchFactor a b P.length := by + by_cases hr : r=0 + · subst r + have hl : P.length=0 := Nat.eq_zero_of_not_pos fun h => by + have hh := P.length_le + omega + simp [edgeFactor,codeLabels,hl,branchFactor] + have he : codeLabels (splitCode P (fun _ _ => 0))= + Finset.univ.image (fun i : Fin P.length => Nat.pair i.val 0) := by + rw [codeLabels_split] + ext y + simp only [Finset.mem_biUnion,Finset.mem_univ,true_and,Finset.mem_image] + simp_rw [codeLabels_const (P.partSize_pos _),Finset.mem_singleton] + aesop + have hcard : (codeLabels (splitCode P (fun _ _ => 0))).card=P.length := by + rw [he,Finset.card_image_of_injective] + · simp + · intro i j hij + exact Fin.ext (Nat.pair_eq_pair.mp hij).1 + have hchild : childLabels (fun _ : Fin r => 0) (splitCode P (fun _ _ => 0)) 0= + codeLabels (splitCode P (fun _ _ => 0)) := by simp [childLabels,codeLabels] + unfold edgeFactor + rw [codeLabels_const (Nat.pos_of_ne_zero hr),Finset.prod_singleton,hchild,hcard] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +@[reducible] def PartitionTree : ℕ → ℕ → Type + | 0,_ => Unit + | d+1,r => Σ P : OrderedFinpartition r, ∀ i : Fin P.length,PartitionTree d (P.partSize i) + +instance partitionTreeFintype (d r : ℕ) : Fintype (PartitionTree d r) := by + induction d generalizing r with + | zero => exact inferInstanceAs (Fintype Unit) + | succ d ih => + letI : ∀ n,Fintype (PartitionTree d n) := ih + exact inferInstanceAs (Fintype (Σ P : OrderedFinpartition r,∀ i : Fin P.length,PartitionTree d (P.partSize i))) + +instance partitionTreeDecidableEq (d r : ℕ) : DecidableEq (PartitionTree d r) := Classical.decEq _ + +def treeCodes : {d r : ℕ} → PartitionTree d r → Fin (d+1) → Fin r → ℕ + | 0,_,_ => fun _ _ => 0 + | _+1,_,⟨P,T⟩ => Fin.cases (fun _ => 0) (fun k => splitCode P (fun i => treeCodes (T i) k)) + +@[simp] lemma treeCodes_root {d r : ℕ} (T : PartitionTree d r) : treeCodes T 0=fun _ => 0 := by + cases d with + | zero => rfl + | succ d => rcases T with ⟨P,T⟩; rfl + +@[simp] lemma treeCodes_succ {d r : ℕ} (P : OrderedFinpartition r) + (T : ∀ i,PartitionTree d (P.partSize i)) (k : Fin (d+1)) : + treeCodes (⟨P,T⟩ : PartitionTree (d+1) r) k.succ=splitCode P (fun i => treeCodes (T i) k) := rfl + +lemma splitCode_refines {r : ℕ} (P : OrderedFinpartition r) + (p c : ∀ i,Fin (P.partSize i) → ℕ) (h : ∀ i,Refines (p i) (c i)) : + Refines (splitCode P p) (splitCode P c) := by + intro j k hjk + obtain ⟨⟨i,j⟩,rfl⟩ := P.equivSigma.surjective j + obtain ⟨⟨l,k⟩,rfl⟩ := P.equivSigma.surjective k + change splitCode P c (P.emb i j)=splitCode P c (P.emb l k) at hjk + change splitCode P p (P.emb i j)=splitCode P p (P.emb l k) + simp only [splitCode_emb,Nat.pair_eq_pair] at hjk ⊢ + have hi : i=l := Fin.ext hjk.1 + subst l + exact ⟨rfl,h i j k hjk.2⟩ + +lemma treeCodes_nested {d r : ℕ} (T : PartitionTree d r) : NestedCodes (treeCodes T) := by + induction d generalizing r with + | zero => intro k l hkl i j hij; rfl + | succ d ih => + rcases T with ⟨P,T⟩ + intro k + induction k using Fin.cases with + | zero => intro l hkl i j hij; rfl + | succ k => + intro l hkl + have hl0 : l≠0 := by intro hl; subst l; have := k.isLt; change (k:ℕ)+1≤0 at hkl; omega + obtain ⟨l,rfl⟩ := Fin.exists_succ_eq.mpr hl0 + exact splitCode_refines P _ _ (fun i => ih (T i) k l (Fin.succ_le_succ_iff.mp hkl)) + +lemma hierarchyNumerator_tree_zero {r : ℕ} (a : Fin 1 → ℝ) (T : PartitionTree 0 r) : + hierarchyNumerator a (treeCodes T)=blockFactor (a 0) r := by + simp [hierarchyNumerator,treeCodes,leafFactor_const] + +lemma hierarchyNumerator_tree_succ {d r : ℕ} (a : Fin (d+2) → ℝ) + (P : OrderedFinpartition r) (T : ∀ i,PartitionTree d (P.partSize i)) : + hierarchyNumerator a (treeCodes (⟨P,T⟩ : PartitionTree (d+1) r))= + branchFactor (a 1) (a 0) P.length* + ∏ i,hierarchyNumerator (fun k => a k.succ) (treeCodes (T i)) := by + unfold hierarchyNumerator + rw [Fin.prod_univ_succ] + change (edgeFactor (a 1) (a 0) (fun _ => 0) + (splitCode P (fun i => treeCodes (T i) 0)) * + (∏ k : Fin d,edgeFactor (a k.succ.succ) (a k.castSucc.succ) + (splitCode P (fun i => treeCodes (T i) k.castSucc)) + (splitCode P (fun i => treeCodes (T i) k.succ)))) * + leafFactor (a (Fin.last d).succ) (splitCode P (fun i => treeCodes (T i) (Fin.last d))) = _ + simp_rw [treeCodes_root] + rw [edgeFactor_root] + have he : (∏ k : Fin d, + edgeFactor (a k.succ.succ) (a k.castSucc.succ) + (splitCode P (fun i => treeCodes (T i) k.castSucc)) + (splitCode P (fun i => treeCodes (T i) k.succ)))= + ∏ i,∏ k : Fin d,edgeFactor (a k.succ.succ) (a k.castSucc.succ) + (treeCodes (T i) k.castSucc) (treeCodes (T i) k.succ) := by + simp_rw [edgeFactor_split] + exact Finset.prod_comm + change branchFactor (a 1) (a 0) P.length * _ * _ = _ + rw [he,leafFactor_split,Finset.prod_mul_distrib] + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] + +def hierarchyMark (w : ι → ℝ) : (d : ℕ) → (Fin (d+1) → ℝ) → ((Fin d → ι) → ℝ) → ℝ → ℝ + | 0,a,x,z => (1-z*x (fun k => Fin.elim0 k))^(a 0) + | d+1,a,x,z => (∑ i,w i*hierarchyMark w d (fun k => a k.succ) (fun s => x (Fin.cons i s)) z)^(a 0/a 1) + +def treeMarkMoment (w : ι → ℝ) : {d r : ℕ} → ((Fin d → ι) → ℝ) → PartitionTree d r → ℝ + | 0,r,x,_ => x (fun k => Fin.elim0 k)^r + | _+1,_,x,⟨P,T⟩ => ∏ j : Fin P.length,∑ i,w i*treeMarkMoment w (fun s => x (Fin.cons i s)) (T j) + +def hierarchyCoefficient {d : ℕ} (w : ι → ℝ) (a : Fin (d+1) → ℝ) + (x : (Fin d → ι) → ℝ) (r : ℕ) : ℝ := + ∑ T : PartitionTree d r,hierarchyNumerator a (treeCodes T)*treeMarkMoment w x T + +lemma hierarchyCoefficient_zero (w : ι → ℝ) (a : Fin 1 → ℝ) (x : (Fin 0 → ι) → ℝ) (r : ℕ) : + hierarchyCoefficient w a x r=blockFactor (a 0) r*x (fun k => Fin.elim0 k)^r := by + unfold hierarchyCoefficient + simp only [hierarchyNumerator_tree_zero,treeMarkMoment] + change (∑ _ : Unit,blockFactor (a 0) r*x (fun k => Fin.elim0 k)^r)=_ + simp + +lemma hierarchyCoefficient_succ {d : ℕ} (w : ι → ℝ) (a : Fin (d+2) → ℝ) + (x : (Fin (d+1) → ι) → ℝ) (r : ℕ) : + hierarchyCoefficient w a x r= + ∑ P : OrderedFinpartition r,branchFactor (a 1) (a 0) P.length * + ∏ j,∑ i,w i*hierarchyCoefficient w (fun k => a k.succ) (fun s => x (Fin.cons i s)) (P.partSize j) := by + unfold hierarchyCoefficient + change (∑ PT : (Σ P : OrderedFinpartition r,∀ j,PartitionTree d (P.partSize j)), + hierarchyNumerator a (treeCodes (PT : PartitionTree (d+1) r))*treeMarkMoment w x PT)=_ + rw [Fintype.sum_sigma] + apply Finset.sum_congr rfl + intro P _ + simp only [hierarchyNumerator_tree_succ,treeMarkMoment] + simp_rw [Finset.mul_sum] + have he (j : Fin P.length) : + (∑ i,∑ T : PartitionTree d (P.partSize j),w i* + (hierarchyNumerator (fun k => a k.succ) (treeCodes T)*treeMarkMoment w (fun s => x (Fin.cons i s)) T))= + ∑ T : PartitionTree d (P.partSize j),hierarchyNumerator (fun k => a k.succ) (treeCodes T)* + ∑ i,w i*treeMarkMoment w (fun s => x (Fin.cons i s)) T := by + rw [Finset.sum_comm] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro T _ + apply Finset.sum_congr rfl + intro i _ + ring + simp_rw [he] + rw [Fintype.prod_sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro T _ + rw [Finset.prod_mul_distrib] + ring + +lemma hierarchyMark_zero {d : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) (x : (Fin d → ι) → ℝ) : hierarchyMark w d a x 0=1 := by + induction d with + | zero => simp [hierarchyMark] + | succ d ih => simp only [hierarchyMark,ih,mul_one,hw,Real.one_rpow] + +lemma hierarchyMark_contDiffAt_zero {d : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) (x : (Fin d → ι) → ℝ) (n : ℕ∞ω) : + ContDiffAt ℝ n (hierarchyMark w d a x) 0 := by + induction d with + | zero => + apply ContDiffAt.rpow_const_of_ne + · fun_prop + · simp + | succ d ih => + apply ContDiffAt.rpow_const_of_ne + · exact ContDiffAt.sum fun i _ => contDiffAt_const.mul (ih _ _) + · simp only [hierarchyMark_zero w hw,mul_one,hw]; norm_num + +lemma hierarchyMean_derivative {d : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) (x : ι → (Fin d → ι) → ℝ) {n : ℕ} (_hn : 0 ∑ i,w i*hierarchyMark w d a (x i) z) 0= + -a 0*∑ i,w i*hierarchyCoefficient w a (x i) n := by + rw [iteratedDeriv_fun_sum] + · simp only [iteratedDeriv_const_mul_field,h,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + · intro i _ + exact contDiffAt_const.mul (hierarchyMark_contDiffAt_zero w hw a (x i) n) + + + +theorem hierarchyMark_derivative {d : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) (ha : ∀ k : Fin d,a k.succ≠0) + (x : (Fin d → ι) → ℝ) {n : ℕ} (hn : 0 + rw [hierarchyCoefficient_zero] + simpa only [hierarchyMark,mul_assoc] using iteratedDeriv_affine_rpow_zero_pos (a 0) (x (fun k => Fin.elim0 k)) hn + | succ d ih => + let A : ℝ → ℝ := fun z => ∑ i,w i*hierarchyMark w d (fun k => a k.succ) (fun s => x (Fin.cons i s)) z + have hA : ContDiffAt ℝ n A 0 := ContDiffAt.sum fun i _ => contDiffAt_const.mul + (hierarchyMark_contDiffAt_zero w hw _ _ n) + have hAz : A 0=1 := by simp [A,hierarchyMark_zero w hw,hw] + have hg : ContDiffAt ℝ n (fun y : ℝ => y^(a 0/a 1)) (A 0) := by + apply ContDiffAt.rpow_const_of_ne + · fun_prop + · rw [hAz]; norm_num + have hf := iteratedDeriv_scomp_eq_sum_orderedFinpartition hg hA (i:=n) le_rfl + change iteratedDeriv n (hierarchyMark w (d+1) a x) 0=_ at hf + rw [hf,hierarchyCoefficient_succ,Finset.mul_sum] + apply Finset.sum_congr rfl + intro P _ + have hd (j : Fin P.length) : iteratedDeriv (P.partSize j) A 0= + -a 1*∑ i,w i*hierarchyCoefficient w (fun k => a k.succ) + (fun s => x (Fin.cons i s)) (P.partSize j) := + hierarchyMean_derivative w hw _ _ (P.partSize_pos j) + (fun y => ih _ (fun k => ha k.succ) y (P.partSize_pos j)) + simp only [hd,hAz,iteratedDeriv_rpow_one,smul_eq_mul] + rw [Finset.prod_mul_distrib] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + have hh := signed_power_factor (ha 0) (a 0) (P.length_pos hn) + simp only [Fin.succ_zero_eq_one] at hh + linear_combination (∏ j,∑ i,w i*hierarchyCoefficient w (fun k => a k.succ) + (fun s => x (Fin.cons i s)) (P.partSize j))*hh + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] + +def hierarchyLog (w : ι → ℝ) {d : ℕ} (a : Fin (d+1) → ℝ) + (x : (Fin (d+1) → ι) → ℝ) (z : ℝ) : ℝ := + (a 0)⁻¹*Real.log (∑ i,w i*hierarchyMark w d a (fun s => x (Fin.cons i s)) z) + +lemma hierarchyLog_derivative {d : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) (ha : ∀ k,a k≠0) (x : (Fin (d+1) → ι) → ℝ) + {n : ℕ} (hn : 0 ∑ i,w i*hierarchyMark w d a (fun s => x (Fin.cons i s)) z + have hA : ContDiffAt ℝ n A 0 := ContDiffAt.sum fun i _ => contDiffAt_const.mul + (hierarchyMark_contDiffAt_zero w hw _ _ n) + have hAz : A 0=1 := by simp [A,hierarchyMark_zero w hw,hw] + have hg : ContDiffAt ℝ n Real.log (A 0) := by + rw [hAz]; exact Real.contDiffAt_log.mpr (by norm_num) + have hf := iteratedDeriv_scomp_eq_sum_orderedFinpartition hg hA (i:=n) le_rfl + change iteratedDeriv n (fun z => Real.log (A z)) 0=_ at hf + change iteratedDeriv n (fun z => (a 0)⁻¹*Real.log (A z)) 0=_ + rw [iteratedDeriv_const_mul_field,hf,hierarchyCoefficient_succ,Finset.mul_sum,← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro P _ + have hd (j : Fin P.length) : iteratedDeriv (P.partSize j) A 0= + -a 0*∑ i,w i*hierarchyCoefficient w a (fun s => x (Fin.cons i s)) (P.partSize j) := + hierarchyMean_derivative w hw _ _ (P.partSize_pos j) + (fun y => hierarchyMark_derivative w hw a (fun k => ha k.succ) y (P.partSize_pos j)) + simp only [hd,hAz,iteratedDeriv_log_one (P.length_pos hn),smul_eq_mul, + Fin.cons_zero,Fin.cons_succ] + rw [Finset.prod_mul_distrib] + simp only [Finset.prod_const,Finset.card_univ,Fintype.card_fin] + have hh := signed_log_factor (ha 0) (P.length_pos hn) + rw [branchFactor_zero] + change (a 0)⁻¹*(((-a 0)^P.length * _)*_)= -(tableFactor (a 0) P.length * _) + linear_combination (∏ j,∑ i,w i*hierarchyCoefficient w a + (fun s => x (Fin.cons i s)) (P.partSize j))*hh + +def hierarchyMarkedMoment {d : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+1) → ℝ) (w : ι → ℝ) (x : (Fin d → ι) → ℝ) (r : ℕ) : ℝ := + ∑ T : PartitionTree d r,(μ:Measure OverlapArray).real (hierarchyEvent (treeCodes T) q)* + treeMarkMoment w x T + +lemma GG_hierarchy_coefficient {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+1) → ℝ) (hq : Monotone q) (h1 : q (Fin.last d)<1) + (w : ι → ℝ) (x : (Fin d → ι) → ℝ) {n : ℕ} (hn : 0 overlapDiscount μ (q k)) x n= + ((n-1).factorial:ℝ)*hierarchyMarkedMoment μ q w x n := by + unfold hierarchyCoefficient hierarchyMarkedMoment + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro T _ + rw [← GG_hierarchy_EPPF hG hgg hu hn (treeCodes T) (treeCodes_nested T) + (fun i j => by simp) q hq h1] + ring + +lemma overlapDiscount_below (μ : ProbabilityMeasure OverlapArray) {q : ℝ} (hq : q < -1) : + overlapDiscount μ q=0 := by + have he : {x : OverlapEntry | (x:ℝ)≤q}=∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro x hx + exact (not_lt_of_ge x.property.1) (hx.trans_lt hq) + simp only [overlapDiscount,he,measureReal_empty] + + + +theorem GG_hierarchy_log_derivative {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ha : ∀ k : Fin (d+1),overlapDiscount μ (q k.succ)≠0) + (w : ι → ℝ) (hw : ∑ i,w i=1) (x : (Fin (d+1) → ι) → ℝ) + {n : ℕ} (hn : 0 overlapDiscount μ (q k.succ)) x) 0= + -((n-1).factorial:ℝ)*hierarchyMarkedMoment μ q w x n := by + rw [hierarchyLog_derivative w hw _ ha x hn] + have he : Fin.cons 0 (fun k => overlapDiscount μ (q k.succ))=(fun k => overlapDiscount μ (q k)) := by + funext k + induction k using Fin.cases with + | zero => exact (overlapDiscount_below μ h0).symm + | succ k => rfl + rw [he,GG_hierarchy_coefficient hG hgg hu q hq h1 w x hn] + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma splitCode_zero_index {r : ℕ} (P : OrderedFinpartition r) (j : Fin r) : + splitCode P (fun _ _ => 0) j=Nat.pair (P.index j).val 0 := by + obtain ⟨⟨i,k⟩,rfl⟩ := P.equivSigma.surjective j + change splitCode P (fun _ _ => 0) (P.emb i k)=_ + rw [splitCode_emb] + change _=Nat.pair (P.index (P.emb i k)).val 0 + rw [orderedIndex_emb] + +lemma treeCodes_level_one_relation {d r : ℕ} (P : OrderedFinpartition r) + (T : ∀ i,PartitionTree d (P.partSize i)) (i j : Fin r) : + treeCodes (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r) 1 i= + treeCodes (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r) 1 j ↔ P.index i=P.index j := by + change splitCode P (fun k => treeCodes (T k) 0) i=splitCode P (fun k => treeCodes (T k) 0) j ↔ _ + simp [treeCodes_root,splitCode_zero_index,Nat.pair_eq_pair,Fin.val_inj] + + +theorem tree_eq_of_same_relations {d r : ℕ} (T U : PartitionTree d r) + (h : ∀ k i j,treeCodes T k i=treeCodes T k j ↔ treeCodes U k i=treeCodes U k j) : T=U := by + induction d generalizing r with + | zero => exact Subsingleton.elim _ _ + | succ d ih => + rcases T with ⟨P,T⟩ + rcases U with ⟨Q,U⟩ + have hPQ : P=Q := ordered_eq_of_same_relation P Q (fun i j => by + simpa only [treeCodes_level_one_relation] using h 1 i j) + subst Q + suffices he : T=U from congrArg (fun V => (⟨P,V⟩ : PartitionTree (d+1) r)) he + funext i + apply ih + intro k j l + have hh := h k.succ (P.emb i j) (P.emb i l) + simpa only [treeCodes_succ,splitCode_emb,Nat.pair_eq_pair,true_and] using hh + +lemma tree_hierarchy_disjoint {d r : ℕ} {T U : PartitionTree d r} (hTU : T≠U) + (q : Fin (d+1) → ℝ) : + Disjoint (hierarchyEvent (treeCodes T) q) (hierarchyEvent (treeCodes U) q) := by + apply Set.disjoint_left.mpr + intro R hT hU + apply hTU + exact tree_eq_of_same_relations T U (fun k i j => ((hT k) i j).symm.trans ((hU k) i j)) + +lemma hierarchyEvent_measurable {d r : ℕ} (c : Fin (d+1) → Fin r → ℕ) (q : Fin (d+1) → ℝ) : + MeasurableSet (hierarchyEvent c q) := by + change MeasurableSet {R | ∀ k,R∈partitionEvent (c k) (q k)} + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun k => measurableSet_partitionEvent _ _ + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/HierarchyNumeratorNonneg.lean b/lean/OAI/Probability/ParisiFinite/HierarchyNumeratorNonneg.lean new file mode 100644 index 0000000000000000000000000000000000000000..123afbfbfe963fa58cdb94e1121f7bcf756e91f3 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/HierarchyNumeratorNonneg.lean @@ -0,0 +1,682 @@ +import Mathlib +import OAI.Probability.ParisiFinite.LogSeriesTermBound + +namespace OAI + +/-! Hierarchy Numerator Nonneg. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite +variable {ι : Type*} [Fintype ι] + +lemma hierarchyNumerator_nonneg {d r : ℕ} {a : Fin (d+1) → ℝ} + (ha : ∀ k,0≤a k) (hm : Monotone a) (h1 : a (Fin.last d)≤1) + (c : Fin (d+1) → Fin r → ℕ) : 0≤hierarchyNumerator a c := by + unfold hierarchyNumerator edgeFactor leafFactor branchFactor blockFactor + apply mul_nonneg + · apply Finset.prod_nonneg + intro k _ + apply Finset.prod_nonneg + intro x _ + apply Finset.prod_nonneg + intro j _ + have hh := hm (show k.castSucc≤k.succ by exact Fin.castSucc_le_succ k) + have hj : (0:ℝ)≤j := Nat.cast_nonneg j + nlinarith [ha k.succ] + · apply Finset.prod_nonneg + intro x _ + apply Finset.prod_nonneg + intro j _ + have hj : (0:ℝ)≤j := Nat.cast_nonneg j + linarith + +def parameterHierarchyMoment {d : ℕ} (a : Fin (d+1) → ℝ) (w : ι → ℝ) + (x : (Fin (d+1) → ι) → ℝ) (n : ℕ) : ℝ := + if n=0 then 1 else hierarchyCoefficient w (Fin.cons 0 a) x n/((n-1).factorial:ℝ) + +lemma parameterHierarchyMoment_mem_unit {d : ℕ} {a : Fin (d+1) → ℝ} + (ha : ∀ k,0≤a k) (hm : Monotone a) (h1 : a (Fin.last d)≤1) + {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {x : (Fin (d+1) → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) (n : ℕ) : + 0≤parameterHierarchyMoment a w x n ∧ parameterHierarchyMoment a w x n≤1 := by + classical + by_cases hn : n=0 + · simp [parameterHierarchyMoment,hn] + have hnon : ∀ k : Fin (d+2),0≤Fin.cons (α:=fun _ => ℝ) 0 a k := by intro k; induction k using Fin.cases <;> simp [ha] + have hmono : Monotone (Fin.cons 0 a) := by + intro i j hij + induction i using Fin.cases with + | zero => simpa using hnon j + | succ i => + induction j using Fin.cases with + | zero => exact (False.elim (by exact not_le_of_gt (Fin.succ_pos i) hij)) + | succ j => exact hm (Fin.succ_le_succ_iff.mp hij) + have hn1 : Fin.cons (α:=fun _ => ℝ) 0 a (Fin.last (d+1))≤1 := by simpa using h1 + have hT (T : PartitionTree (d+1) n) := hierarchyNumerator_nonneg hnon hmono hn1 (treeCodes T) + have hmass := hierarchy_numerator_mass a ha (Nat.pos_of_ne_zero hn) + simp only [parameterHierarchyMoment,hn,↓reduceIte,hierarchyCoefficient] + constructor + · exact div_nonneg (Finset.sum_nonneg (fun T _ => mul_nonneg (hT T) + (treeMarkMoment_mem_unit hw hs hx T).1)) (Nat.cast_nonneg _) + · rw [div_le_one (by positivity)] + calc + _ ≤ ∑ T : PartitionTree (d+1) n,hierarchyNumerator (Fin.cons 0 a) (treeCodes T) := + Finset.sum_le_sum (fun T _ => mul_le_of_le_one_right (hT T) (treeMarkMoment_mem_unit hw hs hx T).2) + _ = _ := hmass + +lemma parameterHierarchyMoment_continuous {d : ℕ} (w : ι → ℝ) + (x : (Fin (d+1) → ι) → ℝ) (n : ℕ) : Continuous (fun a => parameterHierarchyMoment a w x n) := by + classical + unfold parameterHierarchyMoment + split_ifs + · exact continuous_const + · apply Continuous.div_const + unfold hierarchyCoefficient + apply continuous_finsetSum + intro T _ + apply Continuous.mul_const + apply (continuous_hierarchyNumerator (treeCodes T)).comp + exact continuous_finCons continuous_const continuous_id + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite +variable {ι : Type*} [Fintype ι] + +def parameterHierarchyLogSeries {d : ℕ} (a : Fin (d+1) → ℝ) + (w : ι → ℝ) (x : (Fin (d+1) → ι) → ℝ) : FormalMultilinearSeries ℝ ℝ ℝ := + FormalMultilinearSeries.ofScalars ℝ (fun n => -parameterHierarchyMoment a w x n/(n:ℝ)) + +lemma parameterHierarchyLogSeries_radius {d : ℕ} {a : Fin (d+1) → ℝ} + (ha : ∀ k,0≤a k) (hm : Monotone a) (h1 : a (Fin.last d)≤1) + {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {x : (Fin (d+1) → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) : + (1:ℝ≥0∞)≤(parameterHierarchyLogSeries a w x).radius := by + apply FormalMultilinearSeries.le_radius_of_bound (C:=1) (r:=1) + intro n + simp only [parameterHierarchyLogSeries,FormalMultilinearSeries.ofScalars,norm_smul, + NNReal.coe_one,one_pow,mul_one,Real.norm_eq_abs,abs_div,abs_neg] + rw [show |(n:ℝ)|=(n:ℝ) from abs_of_nonneg (Nat.cast_nonneg n)] + by_cases hn : n=0 + · simp [hn] + have hm := parameterHierarchyMoment_mem_unit ha hm h1 hw hs hx n + rw [abs_of_nonneg hm.1] + have hn1 : (1:ℝ)≤n := by exact_mod_cast Nat.pos_of_ne_zero hn + have hnorm : ‖ContinuousMultilinearMap.mkPiAlgebraFin ℝ n ℝ‖≤1 := by + apply le_trans ContinuousMultilinearMap.norm_mkPiAlgebraFin_le + norm_num + calc + _ ≤ (1:ℝ)/(n:ℝ)*1 := mul_le_mul (div_le_div_of_nonneg_right hm.2 (Nat.cast_nonneg _)) hnorm + (norm_nonneg _) (by positivity) + _ ≤ 1 := by rw [mul_one]; exact (div_le_one (by positivity)).mpr hn1 + +lemma parameterHierarchyLog_hasFPowerSeriesAt + {d : ℕ} (a : Fin (d+1) → ℝ) (ha : ∀ k,a k≠0) + (w : ι → ℝ) (hw : ∑ i,w i=1) (x : (Fin (d+1) → ι) → ℝ) : + HasFPowerSeriesAt (hierarchyLog w a x) + (parameterHierarchyLogSeries a w x) 0 := by + have hz : (∑ i,w i*hierarchyMark w d a (fun s => x (Fin.cons i s)) 0)=1 := by + simp [hierarchyMark_zero w hw,hw] + have hf : ContDiffAt ℝ ω (hierarchyLog w a x) 0 := by + apply contDiffAt_const.mul + apply (Real.contDiffAt_log.mpr _).comp 0 + (ContDiffAt.sum fun i _ => contDiffAt_const.mul (hierarchyMark_contDiffAt_zero w hw _ _ ω)) + rw [hz]; norm_num + have h := hf.analyticAt.hasFPowerSeriesAt + have he : (fun n => iteratedDeriv n (hierarchyLog w a x) 0/(n.factorial:ℝ))= + (fun n => -parameterHierarchyMoment a w x n/(n:ℝ)) := by + funext n + by_cases hn : n=0 + · subst n + simp only [iteratedDeriv_zero,hierarchyLog_zero w hw,Nat.factorial_zero,Nat.cast_one, + div_one,Nat.cast_zero,div_zero] + · have hn' := Nat.pos_of_ne_zero hn + rw [hierarchyLog_derivative w hw a ha x hn'] + simp only [parameterHierarchyMoment,hn,↓reduceIte] + have hf : (n.factorial:ℝ)=(n:ℝ)*((n-1).factorial:ℝ) := by + exact_mod_cast (Nat.mul_factorial_pred hn).symm + have hf0 : ((n-1).factorial:ℝ)≠0 := Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _) + have hn0 : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr hn + rw [hf] + field_simp + rw [he] at h + exact h + + +theorem parameterHierarchy_log_identity + {d : ℕ} {a : Fin (d+1) → ℝ} (han : ∀ k,0≤a k) (ham : Monotone a) + (ha1 : a (Fin.last d)≤1) (ha : ∀ k,a k≠0) + {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {x : (Fin (d+1) → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : + hierarchyLog w a x z= + (parameterHierarchyLogSeries a w x).sum z := by + let f := hierarchyLog w a x + let p := parameterHierarchyLogSeries a w x + have hr : (1:ℝ≥0∞)≤p.radius := parameterHierarchyLogSeries_radius han ham ha1 hw hs hx + have hf : AnalyticOnNhd ℝ f (Set.Ioo (-1) 1) := by + intro t ht + exact (hierarchyLog_contDiffAt hw hs _ hx (abs_lt.mpr ht) ω).analyticAt + have hp : AnalyticOnNhd ℝ p.sum (Set.Ioo (-1) 1) := by + intro t ht + apply p.analyticOnNhd + apply lt_of_lt_of_le _ hr + rw [edist_zero_right,← ofReal_norm] + exact ENNReal.ofReal_lt_one.mpr (abs_lt.mpr ht) + have he : f=ᶠ[𝓝 0] p.sum := by + filter_upwards [(parameterHierarchyLog_hasFPowerSeriesAt a ha w hs x).eventually_hasSum] with t ht + simpa only [zero_add,f,p,FormalMultilinearSeries.sum] using ht.tsum_eq.symm + exact hf.eqOn_of_preconnected_of_eventuallyEq hp isPreconnected_Ioo (by constructor <;> norm_num) + he (abs_lt.mp hz) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite +variable {ι : Type*} [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + + +theorem parameterHierarchy_finiteRisk_identity_all (ν : Measure ι) [IsProbabilityMeasure ν] + {d : ℕ} {a : Fin (d+1) → ℝ} (ha : ∀ k,0≤a k) (hm : Monotone a) + (h1 : a (Fin.last d)≤1) + {x : (Fin (d+1) → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : + finiteHierarchyRisk (fun i => ν.real {i}) a (fun s => Real.log (1-z*x s))= + ∑' n,-parameterHierarchyMoment a (fun i => ν.real {i}) x n/(n:ℝ)*z^n := by + let δ (m : ℕ) : ℝ := 1/(m+1:ℕ) + have hd (m : ℕ) : 0<δ m ∧ δ m≤1 := by + constructor + · positivity + · exact (div_le_one (by positivity)).mpr (by exact_mod_cast Nat.succ_le_succ (Nat.zero_le m)) + let b (m : ℕ) (k : Fin (d+1)) : ℝ := (1-δ m)*a k+δ m + have hb (m : ℕ) (k : Fin (d+1)) : 0 measureReal_nonneg + have hs : (∑ i,ν.real {i})=1 := by + simp + have he (m : ℕ) : finiteHierarchyRisk (fun i => ν.real {i}) (b m) (fun s => Real.log (1-z*x s))= + ∑' n,-parameterHierarchyMoment (b m) (fun i => ν.real {i}) x n/(n:ℝ)*z^n := by + rw [← hierarchyLog_eq_finiteHierarchyRisk hw hs (b m) (fun k => (hb m k).ne') + (fun s => affine_mark_pos (hx s) hz)] + rw [parameterHierarchy_log_identity (fun k => (hb m k).le) (hbm m) (hb1 m) + (fun k => (hb m k).ne') hw hs hx hz] + simp only [FormalMultilinearSeries.sum,parameterHierarchyLogSeries, + FormalMultilinearSeries.ofScalars_apply_eq,smul_eq_mul] + have hleft := finiteHierarchyRisk_coefficient_tendsto ν (fun m k => (hb m k).le) + (tendsto_pi_nhds.mp ht) (fun s => Real.log (1-z*x s)) + have hright : Tendsto (fun m => ∑' n,-parameterHierarchyMoment (b m) (fun i => ν.real {i}) x n/(n:ℝ)*z^n) + atTop (𝓝 (∑' n,-parameterHierarchyMoment a (fun i => ν.real {i}) x n/(n:ℝ)*z^n)) := by + apply tendsto_tsum_of_dominated_convergence (summable_geometric_of_lt_one (abs_nonneg z) hz) + · intro n + exact ((((parameterHierarchyMoment_continuous (fun i => ν.real {i}) x n).continuousAt.tendsto.comp ht).neg).div_const (n:ℝ)).mul_const (z^n) + · exact Eventually.of_forall fun m n => normalized_moment_bound + (parameterHierarchyMoment_mem_unit (fun k => (hb m k).le) (hbm m) (hb1 m) hw hs hx n) z n + simp_rw [he] at hleft + exact tendsto_nhds_unique hleft hright + + +theorem GG_finiteRisk_identity_all {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ν : Measure ι) [IsProbabilityMeasure ν] + {x : (Fin (d+1) → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : + finiteHierarchyRisk (fun i => ν.real {i}) (fun k => overlapDiscount μ (q k.succ)) + (fun s => Real.log (1-z*x s))= + ∑' n,-hierarchyMarkedMoment μ q (fun i => ν.real {i}) x n/(n:ℝ)*z^n := by + let := entryLaw_probability μ 0 1 + let a := fun k : Fin (d+1) => overlapDiscount μ (q k.succ) + have ha : ∀ k,0≤a k := fun k => measureReal_nonneg + have hm : Monotone a := by + intro i j hij + apply measureReal_mono + · exact fun u hu => le_trans hu (hq (Fin.succ_le_succ_iff.mpr hij)) + · exact measure_ne_top _ _ + have ha1 : a (Fin.last d)≤1 := measureReal_le_one + rw [parameterHierarchy_finiteRisk_identity_all ν ha hm ha1 hx hz] + apply tsum_congr + intro n + by_cases hn : n=0 + · simp [hn] + have he : Fin.cons 0 a=(fun k => overlapDiscount μ (q k)) := by + funext k + induction k using Fin.cases with + | zero => exact (overlapDiscount_below μ h0).symm + | succ k => rfl + simp only [parameterHierarchyMoment,hn,↓reduceIte,he] + rw [GG_hierarchy_coefficient hG hgg hu q hq h1 _ x (Nat.pos_of_ne_zero hn)] + rw [mul_div_cancel_left₀ _ (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _))] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + + + +theorem GG_gaussian_hierarchy_log_identity_all {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) + {x : (Fin (d+1) → ℝ) → ℝ} (hx : Continuous x) (hb : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : + gaussianHierarchyRisk (fun k => overlapDiscount μ (q k.succ)) + (fun s => Real.log (1-z*x s))= + ∑' n,-gaussianHierarchyMoment μ q x n/(n:ℝ)*z^n := by + let a : Fin (d+1) → ℝ := fun k => overlapDiscount μ (q k.succ) + let f : (Fin (d+1) → ℝ) → ℝ := fun s => Real.log (1-z*x s) + have hf : Continuous f := (continuous_const.sub (hx.const_mul z)).log + (fun s => ne_of_gt (affine_mark_pos (hb s) hz)) + have hfB (s : Fin (d+1) → ℝ) : |f s|≤|Real.log (1-|z|)|+|Real.log (1+|z|)| := + affine_log_bounded hb hz s + have hleft := quantizedHierarchyRisk_tendsto (E:=Unit) (a:=a) (f:=fun _ s => f s) + (fun k => measureReal_nonneg) (hf.comp continuous_snd) (fun _ s => hfB s) + (u:=fun _ => ()) (e:=()) tendsto_const_nhds + have heq (m : ℕ) : finiteHierarchyRisk (gaussianQuantizerWeight m) a + (fun s : Fin (d+1) → GaussianQuantizerLabel m => f (fun k => (s k).val))= + ∑' n,-hierarchyMarkedMoment μ q (gaussianQuantizerWeight m) + (fun s : Fin (d+1) → GaussianQuantizerLabel m => x (fun k => (s k).val)) n/(n:ℝ)*z^n := by + exact GG_finiteRisk_identity_all hG hgg hu q hq h0 h1 + (gaussianQuantizerLaw m) (fun s => hb _) hz + have hright : Tendsto (fun m => ∑' n,-hierarchyMarkedMoment μ q (gaussianQuantizerWeight m) + (fun s : Fin (d+1) → GaussianQuantizerLabel m => x (fun k => (s k).val)) n/(n:ℝ)*z^n) + atTop (𝓝 (∑' n,-gaussianHierarchyMoment μ q x n/(n:ℝ)*z^n)) := by + apply tendsto_tsum_of_dominated_convergence (summable_geometric_of_lt_one (abs_nonneg z) hz) + · intro n + exact (((hierarchyMarkedMoment_tendsto_gaussian μ q hx hb n).neg).div_const (n:ℝ)).mul_const (z^n) + · exact Eventually.of_forall fun m n => normalized_moment_bound + (hierarchyMarkedMoment_mem_unit μ q (gaussianQuantizerWeight_nonneg m) + (gaussianQuantizerWeight_sum m) (fun s => hb _) n) z n + simp_rw [heq] at hleft + exact tendsto_nhds_unique hleft hright + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +theorem hierarchy_empirical_log_tendsto_all {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) + {x : (Fin (d+1) → ℝ) → ℝ} (hx : Continuous x) (hb : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : + Tendsto (fun r => ∫ s,Real.log (1-z*((∑ i : Fin (r+1),x (s i))/(r+1:ℕ))) + ∂hierarchySampleLaw μ q (r+1)) atTop + (𝓝 (gaussianHierarchyRisk (fun k => overlapDiscount μ (q k.succ)) + (fun s => Real.log (1-z*x s)))) := by + let ν (r : ℕ) := hierarchySampleLaw μ q (r+1) + let (r : ℕ) : IsProbabilityMeasure (ν r) := + hierarchySampleLaw_probability hG hgg hu q hq h0 h1 (Nat.succ_pos r) + let M (k : ℕ) := if k=0 then 1 else gaussianHierarchyMoment μ q x k + have hM (k : ℕ) : 0≤M k ∧ M k≤1 := by + by_cases hk : k=0 + · simp [M,hk] + · simpa [M,hk] using gaussianHierarchyMoment_mem_unit μ q hx hb k + have he (r k : ℕ) (e : Fin k → Fin (r+1)) (he : Function.Injective e) : + (∫ s,∏ i,x (s (e i)) ∂ν r)=M k := by + by_cases hk : k=0 + · subst k + simp [M] + have hk' := Nat.pos_of_ne_zero hk + rw [hierarchySampleLaw_marginal_integral hG hgg hu hex q hq h0 h1 (Nat.succ_pos r) hk' + e he (f:=fun s => ∏ i,x (s i)) (by fun_prop) (C:=1)] + · simpa [M,hk] using hierarchySampleLaw_product μ q hx hb + · intro s + rw [abs_of_nonneg (Finset.prod_nonneg (fun i _ => (hb (s i)).1))] + exact Finset.prod_le_one₀ (fun i _ => (hb (s i)).1) (fun i _ => (hb (s i)).2) + have ht := empirical_log_limit_of_distinct_moments ν (fun _ s i => x (s i)) + (fun _ i => hx.measurable.comp (measurable_pi_apply i)) (fun _ s i => hb (s i)) M hM he hz + rw [GG_gaussian_hierarchy_log_identity_all hG hgg hu q hq h0 h1 hx hb hz] + have hs : Summable (fun n => -gaussianHierarchyMoment μ q x n/(n:ℝ)*z^n) := by + apply Summable.of_norm_bounded_eventually (summable_geometric_of_lt_one (abs_nonneg z) hz) + exact Eventually.of_forall (fun n => normalized_moment_bound (gaussianHierarchyMoment_mem_unit μ q hx hb n) z n) + rw [hs.tsum_eq_zero_add] + simp only [Nat.cast_zero,div_zero,zero_mul,zero_add] + convert ht using 2 + apply tsum_congr + intro n + simp only [M,Nat.add_one_ne_zero,↓reduceIte] + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + + + +theorem hierarchy_empirical_positive_tendsto_all {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) + {y : (Fin (d+1) → ℝ) → ℝ} (hy : Continuous y) {l b : ℝ} (hl : 0 ∫ s,Real.log ((∑ i : Fin (r+1),y (s i))/(r+1:ℕ)) + ∂hierarchySampleLaw μ q (r+1)) atTop + (𝓝 (gaussianHierarchyRisk (fun k => overlapDiscount μ (q k.succ)) (fun s => Real.log (y s)))) := by + let x (s : Fin (d+1) → ℝ) := (b-y s)/(b-l) + let z := (b-l)/b + have hbp : 0 Real.log (1-z*x s)) := + (continuous_const.sub (hx.const_mul z)).log (fun s => (affine_mark_pos (hxb s) hz).ne') + have hrisk := gaussianHierarchyRisk_add_const (a:=fun k : Fin (d+1) => overlapDiscount μ (q k.succ)) (fun k => (measureReal_nonneg : 0≤overlapDiscount μ (q k.succ))) + hlogc (affine_log_bounded hxb hz) (Real.log b) + have hleft (r : ℕ) : (∫ s,Real.log ((∑ i : Fin (r+1),y (s i))/(r+1:ℕ)) ∂hierarchySampleLaw μ q (r+1))= + (∫ s,Real.log (1-z*((∑ i : Fin (r+1),x (s i))/(r+1:ℕ))) ∂hierarchySampleLaw μ q (r+1))+Real.log b := by + let := hierarchySampleLaw_probability hG hgg hu q hq h0 h1 (Nat.succ_pos r) + have hrep : (fun s : Fin (r+1) → Fin (d+1) → ℝ => Real.log ((∑ i,y (s i))/(r+1:ℕ)))= + (fun s => Real.log ((∑ i,b*(1-z*x (s i)))/(r+1:ℕ))) := by + funext s + congr 2 + exact Finset.sum_congr rfl (fun i _ => he (s i)) + rw [hrep] + exact integral_affine_average_log _ (Nat.succ_pos r) + (fun i => hx.measurable.comp (measurable_pi_apply i)) (fun s i => hxb (s i)) hbp hz + simp_rw [hleft,hlog] + rw [hrisk] + exact ht.add_const _ + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma treePathLaw_coordinate {d r : ℕ} (T : PartitionTree d r) (i : Fin r) : + (treePathLaw T).map (fun s => s i)=gaussianLaw (Fin d) := by + classical + let A : Fin d → TreeNode T → ℝ := fun k => pathCoeff T (i,k) + let B : Fin d → Fin d → ℝ := fun k l => if k=l then 1 else 0 + have hB : field B=id := by + funext z k + simp [field,B] + have hA : field A=(fun z k => treePathVector T z i k) := by + funext z k + exact field_pathCoeff T z (i,k) + have hk : kernel A=kernel B := by + funext k l + change kernel (pathCoeff T) (i,k) (i,l)=_ + rw [kernel_pathCoeff] + have hh : treeNodePath T i k=treeNodePath T i l ↔ k=l := + ⟨fun h => treeNodePath_eq_levels T i i k l h,fun h => by rw [h]⟩ + simp only [hh] + simp [kernel,B] + have hh := field_law_eq_of_kernel A B hk + rw [hB,Measure.map_id,hA] at hh + unfold treePathLaw + rw [Measure.map_map (by fun_prop) (treePathVector_continuous T).measurable] + exact hh + + + +lemma hierarchySampleLaw_coordinate {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) {r : ℕ} (i : Fin r) : + (hierarchySampleLaw μ q r).map (fun s => s i)=gaussianLaw (Fin (d+1)) := by + have hp := hierarchySampleLaw_probability hG hgg hu q hq h0 h1 (i.pos) + have hsum : (∑ T : PartitionTree (d+1) r,(μ:Measure OverlapArray) (hierarchyEvent (treeCodes T) q))=1 := by + have hh := hp.measure_univ + simpa only [hierarchySampleLaw,Measure.finsetSum_apply,Measure.smul_apply,measure_univ,smul_eq_mul,mul_one] using hh + unfold hierarchySampleLaw + rw [Measure.map_finset_sum' ((measurable_pi_apply i).aemeasurable)] + simp_rw [Measure.map_smul _ ((measurable_pi_apply i).aemeasurable),treePathLaw_coordinate] + rw [← Finset.sum_smul,hsum,one_smul] + +lemma hierarchySampleLaw_integrable_coordinate {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) {r : ℕ} (i : Fin r) + {f : (Fin (d+1) → ℝ) → ℝ} (hf : Integrable f (gaussianLaw (Fin (d+1)))) : + Integrable (fun s => f (s i)) (hierarchySampleLaw μ q r) := by + have hh := hierarchySampleLaw_coordinate hG hgg hu q hq h0 h1 i + rw [← hh] at hf + exact hf.comp_measurable (by fun_prop) + +lemma hierarchySampleLaw_integral_coordinate {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) {r : ℕ} (i : Fin r) + {f : (Fin (d+1) → ℝ) → ℝ} (hf : Measurable f) : + (∫ s,f (s i) ∂hierarchySampleLaw μ q r)=∫ z,f z ∂gaussianLaw (Fin (d+1)) := by + rw [← integral_map (by fun_prop : Measurable (fun s : Fin r → Fin (d+1) → ℝ => s i)).aemeasurable hf.aestronglyMeasurable] + rw [hierarchySampleLaw_coordinate hG hgg hu q hq h0 h1 i] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + + + +theorem step_tendsto {L : ℝ≥0} {F : ℕ → ℝ → ℝ} {f : ℝ → ℝ} + (hF : ∀ m,LipschitzWith L (F m)) (hf : LipschitzWith L f) + (ht : ∀ x,Tendsto (fun m => F m x) atTop (𝓝 (f x))) (a s x : ℝ) : + Tendsto (fun m => step a s (F m) x) atTop (𝓝 (step a s f x)) := by + have hb : ∀ᶠ m in atTop,|F m x|≤|f x|+1 := by + have hh := (ht x).abs.eventually (gt_mem_nhds (lt_add_one |f x|)) + exact hh.mono fun m hm => hm.le + have hiabs : Integrable (fun z : ℝ => |z|) (gaussianReal 0 1) := + (MemLp.integrable (by norm_num) (memLp_id_gaussianReal (μ:=0) (v:=1) 1)).abs + by_cases ha : a=0 + · simp only [step,ha,logMean_zero] + apply tendsto_integral_filter_of_dominated_convergence + (fun z : ℝ => |f x|+1+(L:ℝ)* |s| * |z|) + · exact Eventually.of_forall fun m => ((hF m).continuous.comp (by fun_prop)).aestronglyMeasurable + · filter_upwards [hb] with m hm + exact ae_of_all _ fun z => by + rw [Real.norm_eq_abs] + exact (shift_norm_le (hF m) x s z).trans (by linarith) + · exact (integrable_const _).add (hiabs.const_mul _) + · exact ae_of_all _ fun z => ht _ + · have hi : Tendsto (fun m => ∫ z,Real.exp (a*F m (x+s*z)) ∂gaussianReal 0 1) atTop + (𝓝 (∫ z,Real.exp (a*f (x+s*z)) ∂gaussianReal 0 1)) := by + apply tendsto_integral_filter_of_dominated_convergence + (fun z : ℝ => Real.exp (|a| *(|f x|+1))*Real.exp ((|a| *(L:ℝ)* |s|)* |z|)) + · exact Eventually.of_forall fun m => (integrable_exp_shift (hF m) a x s).aestronglyMeasurable + · filter_upwards [hb] with m hm + exact ae_of_all _ fun z => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),← Real.exp_add] + apply Real.exp_le_exp.mpr + have hh := shift_norm_le (hF m) x s z + have hh' : a*F m (x+s*z)≤|a| * |F m (x+s*z)| := by + simpa only [abs_mul] using le_abs_self (a*F m (x+s*z)) + nlinarith [abs_nonneg a] + · exact (integrable_exp_abs _).const_mul _ + · exact ae_of_all _ fun z => Real.continuous_exp.continuousAt.tendsto.comp ((ht _).const_mul a) + simp only [step,logMean,ha,↓reduceIte] + exact (hi.log (integral_exp_pos (integrable_exp_shift hf a x s)).ne').div_const a + + +lemma clip_lipschitz {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (M : ℝ) : + LipschitzWith L (fun x => max (-M) (min M (f x))) := + (hf.const_min M).const_max (-M) + +lemma clip_tendsto (z : ℝ) : + Tendsto (fun m : ℕ => max (-(m:ℝ)) (min (m:ℝ) z)) atTop (𝓝 z) := by + have ht : Tendsto (fun m : ℕ => (m:ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + apply tendsto_const_nhds.congr' + filter_upwards [ht.eventually_ge_atTop |z|] with m hm + rw [min_eq_right (le_abs_self z |>.trans hm),max_eq_right] + linarith [neg_abs_le z] + +end ParisiFinite + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open ParisiFinite + + + +def scalarHierarchy : {d : ℕ} → (Fin d → ℝ) → (Fin d → ℝ) → (ℝ → ℝ) → ℝ → ℝ + | 0,_,_,f => f + | _+1,a,s,f => step (a 0) (s 0) (scalarHierarchy (fun k => a k.succ) (fun k => s k.succ) f) + +lemma scalarHierarchy_lipschitz {d : ℕ} {a s : Fin d → ℝ} (ha : ∀ k,0≤a k) + {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) : + LipschitzWith L (scalarHierarchy a s f) := by + induction d with + | zero => exact hf + | succ d ih => exact step_lipschitz (ih (fun k => ha k.succ)) (ha 0) _ + +lemma gaussianHierarchyRisk_sum {d : ℕ} (a s : Fin d → ℝ) (f : ℝ → ℝ) (x : ℝ) : + gaussianHierarchyRisk a (fun z => f (x+∑ k,s k*z k))=scalarHierarchy a s f x := by + induction d generalizing x with + | zero => simp [gaussianHierarchyRisk,scalarHierarchy] + | succ d ih => + change logMean _ _ _=logMean _ _ _ + congr 1 + funext z + rw [← ih (fun k => a k.succ) (fun k => s k.succ) (x+s 0*z)] + congr 1 + funext t + simp only [Fin.sum_univ_succ,Fin.cons_zero,Fin.cons_succ] + ring_nf + +lemma scalarHierarchy_tendsto {d : ℕ} {a s : Fin d → ℝ} (ha : ∀ k,0≤a k) + {L : ℝ≥0} {F : ℕ → ℝ → ℝ} {f : ℝ → ℝ} + (hF : ∀ m,LipschitzWith L (F m)) (hf : LipschitzWith L f) + (ht : ∀ x,Tendsto (fun m => F m x) atTop (𝓝 (f x))) (x : ℝ) : + Tendsto (fun m => scalarHierarchy a s (F m) x) atTop (𝓝 (scalarHierarchy a s f x)) := by + induction d generalizing x with + | zero => exact ht x + | succ d ih => + apply step_tendsto + · intro m; exact scalarHierarchy_lipschitz (fun k => ha k.succ) (hF m) + · exact scalarHierarchy_lipschitz (fun k => ha k.succ) hf + · intro y; exact ih (fun k => ha k.succ) y + +lemma scalarHierarchy_clip_tendsto {d : ℕ} {a s : Fin d → ℝ} (ha : ∀ k,0≤a k) + {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (x : ℝ) : + Tendsto (fun m : ℕ => scalarHierarchy a s (fun y => max (-(m:ℝ)) (min (m:ℝ) (f y))) x) + atTop (𝓝 (scalarHierarchy a s f x)) := + scalarHierarchy_tendsto ha (fun _m => clip_lipschitz hf _) hf (fun y => clip_tendsto (f y)) x + +lemma logMean_mul_const {Ω : Type*} [MeasurableSpace Ω] (ν : Measure Ω) + (a : ℝ) {c : ℝ} (hc : c≠0) (f : Ω → ℝ) : + logMean ν a (fun z => c*f z)=c*logMean ν (a*c) f := by + by_cases ha : a=0 + · simp [ha,logMean_zero,integral_const_mul] + · have hac : a*c≠0 := mul_ne_zero ha hc + simp only [logMean,ha,hac,↓reduceIte] + simp_rw [← mul_assoc] + field_simp + +lemma scalarHierarchy_mul_const {d : ℕ} (a s : Fin d → ℝ) {c : ℝ} (hc : c≠0) + (f : ℝ → ℝ) (x : ℝ) : + scalarHierarchy a s (fun y => c*f y) x=c*scalarHierarchy (fun k => a k*c) s f x := by + induction d generalizing x with + | zero => rfl + | succ d ih => + change logMean _ _ _=c*logMean _ _ _ + simp_rw [ih] + exact logMean_mul_const _ _ hc _ + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/HorizonGrid.lean b/lean/OAI/Probability/ParisiFinite/HorizonGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..79041005ec5726d08ed01bee4e1fb2b3c38bac90 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/HorizonGrid.lean @@ -0,0 +1,629 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Law +import OAI.Probability.ParisiFinite.Time + +namespace OAI + +/-! Horizon Grid. -/ + +noncomputable section + +open MeasureTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath +open ProbabilityTheory + + +def horizonGrid (T : ℝ≥0) (n k : ℕ) : ℝ≥0 := + T * ⟨grid n k, mul_nonneg (Nat.cast_nonneg _) (mesh_pos n).le⟩ + +lemma horizonGrid_coe (T : ℝ≥0) (n k : ℕ) : + (horizonGrid T n k : ℝ) = (T:ℝ)*grid n k := rfl + +lemma horizonGrid_mono (T : ℝ≥0) (n : ℕ) : Monotone (horizonGrid T n) := by + intro j k h + exact NNReal.coe_le_coe.mp (mul_le_mul_of_nonneg_left (grid_mono n h) T.coe_nonneg) + +lemma horizonGrid_nndist (T : ℝ≥0) (n k : ℕ) : + nndist (horizonGrid T n (k+1) : ℝ) (horizonGrid T n k : ℝ) = + T * NNReal.mk (mesh n) (mesh_pos n).le := by + apply NNReal.coe_injective + rw [coe_nndist,Real.dist_eq,abs_of_nonneg (sub_nonneg.mpr + (show (horizonGrid T n k:ℝ) ≤ horizonGrid T n (k+1) from + NNReal.coe_le_coe.mpr (horizonGrid_mono T n (Nat.le_succ k))))] + change (T:ℝ)*grid n (k+1)-(T:ℝ)*grid n k = (T:ℝ)*mesh n + rw [grid_succ] + ring + + + +def standardStep {Ω : Type*} (W : ℝ≥0 → Ω → ℝ) (T : ℝ≥0) (n k : ℕ) (ω : Ω) : ℝ := + (W (horizonGrid T n (k+1)) ω-W (horizonGrid T n k) ω) / + Real.sqrt ((T:ℝ)*mesh n) + +section Brownian +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma standardStep_hasLaw (hW : IsBrownianReal W P) {T : ℝ≥0} (hT : 0 x/Real.sqrt ((T:ℝ)*mesh n)) (fun _ => by fun_prop) + +lemma standardStep_jointLaw (hW : IsBrownianReal W P) {T : ℝ≥0} (hT : 0 standardStep W T n i ω) + (Measure.pi (fun _ : Fin r => gaussianReal 0 1)) P := by + exact ((standardStep_independent hW T n).precomp Fin.val_injective).hasLaw_pi + (fun i => standardStep_hasLaw hW hT n i) + +end Brownian +end ParisiPath + +namespace ParisiPath +variable {K M : ℝ≥0} + +def translatePath (W : Path) (a : ℝ) : Path := W + ContinuousMap.const Time a + +@[simp] lemma extend_translatePath (W : Path) (a t : ℝ) : + extend (translatePath W a) t = extend W t + a := rfl + +lemma euler_translate_step (b : Drift K M) (W : Path) (a : ℝ) (n k : ℕ) : + ‖euler b (translatePath W a) n (k+1)-euler b W n (k+1)‖ ≤ + (1+(K:ℝ)*mesh n)*‖euler b (translatePath W a) n k-euler b W n k‖ := by + have he : euler b (translatePath W a) n (k+1)-euler b W n (k+1) = + (euler b (translatePath W a) n k-euler b W n k)+mesh n* + (b.val (grid n k) (euler b (translatePath W a) n k)- + b.val (grid n k) (euler b W n k)) := by + simp only [euler,extend_translatePath] + ring + rw [he] + calc + _ ≤ ‖euler b (translatePath W a) n k-euler b W n k‖+ + ‖mesh n*(b.val (grid n k) (euler b (translatePath W a) n k)- + b.val (grid n k) (euler b W n k))‖ := norm_add_le _ _ + _ ≤ ‖euler b (translatePath W a) n k-euler b W n k‖+ + mesh n*((K:ℝ)*‖euler b (translatePath W a) n k-euler b W n k‖) := by + rw [norm_mul,Real.norm_of_nonneg (mesh_pos n).le] + exact add_le_add_right (mul_le_mul_of_nonneg_left + (by simpa only [dist_eq_norm] using ((b.lipschitz (grid n k)).dist_le_mul + (euler b (translatePath W a) n k) (euler b W n k))) (mesh_pos n).le) _ + _ = _ := by ring + + +lemma euler_translate_bound (b : Drift K M) (W : Path) (a : ℝ) (n k : ℕ) (hk : k≤n+1) : + ‖euler b (translatePath W a) n k-euler b W n k‖ ≤ |a| *Real.exp (K:ℝ) := by + have h := finite_discrete_gronwall (N := n+1) + (u := fun k => ‖euler b (translatePath W a) n k-euler b W n k‖) + (r := fun _ => 0) (c := (K:ℝ)*mesh n) (fun _ => norm_nonneg _) + (fun _ => le_rfl) (mul_nonneg K.coe_nonneg (mesh_pos n).le) + (fun j _ => by simpa using euler_translate_step b W a n j) hk + simp only [euler,extend_translatePath,add_sub_cancel_left,Real.norm_eq_abs, + Finset.sum_const_zero,add_zero] at h + apply h.trans + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + apply Real.exp_le_exp.mpr + have ht := (grid_mem n k hk).2 + dsimp only [grid] at ht + nlinarith [mul_le_mul_of_nonneg_left ht K.coe_nonneg] + +lemma scaled_translatePath (T : ℝ≥0) (W : Path) (a : ℝ) : + scaledPath T (translatePath W a) = translatePath (scaledPath T W) a := by + ext t + rfl + +lemma horizonEuler_translate_bound (b : Drift K M) (W : Path) (a : ℝ) + (T : ℝ≥0) (n k : ℕ) (hk : k≤n+1) : + ‖horizonEuler b (translatePath W a) T n k-horizonEuler b W T n k‖ ≤ + |a| *Real.exp (T*K:ℝ≥0) := by + simpa only [horizonEuler,scaled_translatePath] using + euler_translate_bound (scaledDrift b T) (scaledPath T W) a n k hk + + + +def sourceIndex (n : ℕ) (k : Fin (n+2)) : ℕ := if k.val=0 then n+1 else k.val-1 + +lemma sourceIndex_injective (n : ℕ) : Function.Injective (sourceIndex n) := by + intro i j h + apply Fin.ext + dsimp only [sourceIndex] at h + split_ifs at h <;> omega + +open ProbabilityTheory +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def sourceNoise (W : ℝ≥0 → Ω → ℝ) (T : ℝ≥0) (n : ℕ) (k : Fin (n+2)) (ω : Ω) : ℝ := + standardStep W T n (sourceIndex n k) ω + +lemma sourceNoise_jointLaw (hW : IsBrownianReal W P) {T : ℝ≥0} (hT : 0 sourceNoise W T n k ω) + (Measure.pi (fun _ : Fin (n+2) => gaussianReal 0 1)) P := + ((standardStep_independent hW T n).precomp (sourceIndex_injective n)).hasLaw_pi + (fun k => standardStep_hasLaw hW hT n (sourceIndex n k)) + + +def initialSeed (W : ℝ≥0 → Ω → ℝ) (T : ℝ≥0) (n : ℕ) (ω : Ω) : ℝ := + Real.sqrt ((T:ℝ)*mesh n)*standardStep W T n (n+1) ω + +lemma initialSeed_aemeasurable (hW : IsBrownianReal W P) {T : ℝ≥0} (hT : 0 (initialSeed W T n ω)^2) P := by + have h := (standardStep_hasLaw hW hT n (n+1)).hasGaussianLaw.memLp (p := 2) (by norm_num) + have hi := (h.const_mul (Real.sqrt ((T:ℝ)*mesh n))).integrable_sq + exact hi + +lemma initialSeed_integral_sq (hW : IsBrownianReal W P) {T : ℝ≥0} (hT : 0 x) (show AEMeasurable (fun x:ℝ => x) (gaussianReal 0 1) from measurable_id.aemeasurable)] at h + simpa [integral_id_gaussianReal] using h + have hn := (standardStep_hasLaw hW hT n (n+1)).integral_comp + (f := fun z:ℝ => z^2) (by fun_prop) + simp only [Function.comp_def] at hn + simp only [initialSeed,mul_pow,integral_const_mul,hn,hi,mul_one] + exact Real.sq_sqrt (mul_nonneg T.coe_nonneg (mesh_pos n).le) + +end ParisiPath + +namespace ParisiPath +open ProbabilityTheory + + + +variable {K M : ℝ≥0} + +def innovationEuler (b : Drift K M) (T : ℝ≥0) (n : ℕ) : ℕ → (ℕ → ℝ) → ℝ + | 0,_ => 0 + | k+1,z => innovationEuler b T n k z + + ((T:ℝ)*mesh n)*b.val ((T:ℝ)*grid n k) (innovationEuler b T n k z) + + Real.sqrt ((T:ℝ)*mesh n)*z k + +lemma innovationEuler_measurable (b : Drift K M) (T : ℝ≥0) (n k : ℕ) : + Measurable (innovationEuler b T n k) := by + induction k with + | zero => exact measurable_const + | succ k ih => + exact (ih.add (((b.measurable.comp (measurable_const.prodMk measurable_id)).comp ih).const_mul _)).add + ((measurable_pi_apply k).const_mul _) + +lemma innovationEuler_congr (b : Drift K M) (T : ℝ≥0) (n k : ℕ) + {z w : ℕ → ℝ} (hzw : ∀ j rfl + | succ k ih => + simp only [innovationEuler,ih (fun j hj => hzw j (by omega)),hzw k (by omega)] + +def pastExtension (k : ℕ) (z : (↑(Finset.range k)) → ℝ) (j : ℕ) : ℝ := + if h : j (0:ℝ))) + +lemma innovationEuler_past (b : Drift K M) (T : ℝ≥0) (n k : ℕ) (z : ℕ → ℝ) : + innovationEuler b T n k (pastExtension k (fun j => z j))=innovationEuler b T n k z := by + apply innovationEuler_congr + intro j hj + simp only [pastExtension,dite_eq_left hj] + +lemma innovationEuler_independent {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : ℕ → Ω → ℝ} (hZ : iIndepFun Z P) (hm : ∀ k,AEMeasurable (Z k) P) + (b : Drift K M) (T : ℝ≥0) (n k : ℕ) : + IndepFun (fun ω => innovationEuler b T n k (fun j => Z j ω)) (Z k) P := by + have hd : Disjoint (Finset.range k) {k} := by simp + have h := hZ.indepFun_finset₀ (Finset.range k) {k} hd hm + have hh : IndepFun + (fun ω => innovationEuler b T n k (pastExtension k (fun j => Z j ω))) + (Z k) P := h.comp (φ := (innovationEuler b T n k) ∘ pastExtension k) + (ψ := fun z : (↑({k} : Finset ℕ)) → ℝ => z ⟨k,by simp⟩) + ((innovationEuler_measurable b T n k).comp (pastExtension_measurable k)) + (measurable_pi_apply _) + have he : (fun ω => innovationEuler b T n k (pastExtension k (fun j => Z j ω)))= + (fun ω => innovationEuler b T n k (fun j => Z j ω)) := by + funext ω + exact innovationEuler_past b T n k (fun j => Z j ω) + rwa [he] at hh + +lemma innovationEuler_aemeasurable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : ℕ → Ω → ℝ} (hm : ∀ k,AEMeasurable (Z k) P) + (b : Drift K M) (T : ℝ≥0) (n k : ℕ) : + AEMeasurable (fun ω => innovationEuler b T n k (fun j => Z j ω)) P := + (innovationEuler_measurable b T n k).comp_aemeasurable (AEMeasurable.of_eval hm) + +lemma gaussian_standard_integral : (∫ z:ℝ,z ∂gaussianReal 0 1)=0 := by + simp [integral_id_gaussianReal] + +lemma gaussian_standard_integral_sq : (∫ z:ℝ,z^2 ∂gaussianReal 0 1)=1 := by + have h := variance_fun_id_gaussianReal (μ:=0) (v:=1) + rw [variance_eq_integral (X:= fun x:ℝ => x) + (show AEMeasurable (fun x:ℝ => x) (gaussianReal 0 1) from measurable_id.aemeasurable)] at h + simpa [integral_id_gaussianReal] using h + + +lemma innovationEuler_noise_mean {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : ℕ → Ω → ℝ} (hZ : iIndepFun Z P) + (hl : ∀ k,HasLaw (Z k) (gaussianReal 0 1) P) + (b : Drift K M) (T : ℝ≥0) (n k : ℕ) {f : ℝ → ℝ} (hf : Measurable f) : + (∫ ω,f (innovationEuler b T n k (fun j => Z j ω))*Z k ω ∂P)=0 := by + have h := (innovationEuler_independent hZ (fun k => (hl k).aemeasurable) b T n k).comp + (φ := f) (ψ := id) hf measurable_id + simp only [Function.comp_def,id_eq] at h + rw [h.integral_fun_mul_eq_mul_integral + (hf.comp_aemeasurable (innovationEuler_aemeasurable (fun k => (hl k).aemeasurable) b T n k)).aestronglyMeasurable + (hl k).aemeasurable.aestronglyMeasurable] + have hz : (∫ ω,Z k ω ∂P)=0 := by + simpa only [Function.comp_def,gaussian_standard_integral] using + (hl k).integral_comp (f := fun z:ℝ => z) (by fun_prop) + rw [hz,mul_zero] + +lemma innovationEuler_noise_sq {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : ℕ → Ω → ℝ} (hZ : iIndepFun Z P) + (hl : ∀ k,HasLaw (Z k) (gaussianReal 0 1) P) + (b : Drift K M) (T : ℝ≥0) (n k : ℕ) {f : ℝ → ℝ} (hf : Measurable f) : + (∫ ω,f (innovationEuler b T n k (fun j => Z j ω))*(Z k ω)^2 ∂P)= + ∫ ω,f (innovationEuler b T n k (fun j => Z j ω)) ∂P := by + have h := (innovationEuler_independent hZ (fun k => (hl k).aemeasurable) b T n k).comp + (φ := f) (ψ := fun z : ℝ => z^2) hf (by fun_prop) + simp only [Function.comp_def] at h + rw [h.integral_fun_mul_eq_mul_integral + (hf.comp_aemeasurable (innovationEuler_aemeasurable (fun k => (hl k).aemeasurable) b T n k)).aestronglyMeasurable + ((hl k).aemeasurable.pow_const 2).aestronglyMeasurable] + have hz : (∫ ω,(Z k ω)^2 ∂P)=1 := by + exact ((hl k).integral_comp (f := fun z:ℝ => z^2) (by fun_prop)).trans + gaussian_standard_integral_sq + rw [hz,mul_one] + +end ParisiPath + + + + + +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace ParisiPath + +lemma cubic_taylor_bound {f : ℝ → ℝ} (hf : ContDiff ℝ 3 f) {L : ℝ} + (hL : ∀ x,‖iteratedDeriv 3 f x‖ ≤ L) (x h : ℝ) : + ‖f (x+h)-f x-h*deriv f x-(h^2/2)*iteratedDeriv 2 f x‖ ≤ L*|h|^3/6 := by + by_cases hh : h=0 + · simp [hh] + have hne : x≠x+h := by intro he; apply hh; linarith + obtain ⟨y,_,hy⟩ := taylor_mean_remainder_lagrange_iteratedDeriv (n := 2) hne hf.contDiffOn + have h₁ : iteratedDerivWithin 1 f (uIcc x (x+h)) x=deriv f x := by + rw [iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_uIcc hne) + (hf.of_le (by norm_num)).contDiffAt (left_mem_uIcc),iteratedDeriv_one] + have h₂ : iteratedDerivWithin 2 f (uIcc x (x+h)) x=iteratedDeriv 2 f x := + iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_uIcc hne) + (hf.of_le (by norm_num)).contDiffAt (left_mem_uIcc) + have ht : taylorWithinEval f 2 (uIcc x (x+h)) x (x+h)= + f x+h*deriv f x+(h^2/2)*iteratedDeriv 2 f x := by + simp only [taylorWithinEval_succ,taylor_within_zero_eval,h₁,h₂,smul_eq_mul] + norm_num only [Nat.factorial, Nat.cast_one, Nat.cast_ofNat, mul_one, one_mul, inv_one, pow_one, add_sub_cancel_left] + ring + rw [ht] at hy + have he : f (x+h)-f x-h*deriv f x-(h^2/2)*iteratedDeriv 2 f x= + iteratedDeriv 3 f y*h^3/6 := by + norm_num at hy + nlinarith [hy] + rw [he,norm_div,norm_mul,Real.norm_eq_abs,norm_pow,Real.norm_eq_abs] + norm_num + gcongr + exact hL y + + + +structure CubicTest where + val : ℝ → ℝ + smooth : ContDiff ℝ 3 val + c1 : ℝ≥0 + c2 : ℝ≥0 + c3 : ℝ≥0 + bound1 : ∀ x,‖deriv val x‖≤c1 + bound2 : ∀ x,‖iteratedDeriv 2 val x‖≤c2 + bound3 : ∀ x,‖iteratedDeriv 3 val x‖≤c3 + +namespace CubicTest +lemma continuous (f : CubicTest) : Continuous f.val := f.smooth.continuous +lemma continuous_d1 (f : CubicTest) : Continuous (deriv f.val) := + f.smooth.continuous_deriv (by norm_num) +lemma continuous_d2 (f : CubicTest) : Continuous (iteratedDeriv 2 f.val) := + f.smooth.continuous_iteratedDeriv 2 (by norm_num) +lemma lipschitz (f : CubicTest) : LipschitzWith f.c1 f.val := by + apply lipschitzWith_of_nnnorm_deriv_le (f.smooth.differentiable (by norm_num)) + intro x + exact_mod_cast f.bound1 x +end CubicTest + +end ParisiPath + +namespace ParisiPath + + +def thirdMomentBound (M : ℝ≥0) : ℝ := ∫ z:ℝ,((M:ℝ)+‖z‖)^3 ∂gaussianReal 0 1 + +lemma shiftedNorm_integrable_cube {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) P) (M : ℝ≥0) : + Integrable (fun ω => ((M:ℝ)+‖Z ω‖)^3) P := by + let : IsProbabilityMeasure P := hZ.isProbabilityMeasure + have h := ((memLp_const (M:ℝ) : MemLp (fun _ : Ω => (M:ℝ)) (3:ℝ≥0∞) P).add + (hZ.hasGaussianLaw.memLp (p := 3) (by norm_num)).norm).integrable_norm_pow (by decide : (3:ℕ)≠0) + simpa only [Pi.add_apply,Real.norm_of_nonneg (add_nonneg M.coe_nonneg (norm_nonneg _))] using h + +lemma shiftedNorm_integral_cube {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) P) (M : ℝ≥0) : + (∫ ω,((M:ℝ)+‖Z ω‖)^3 ∂P)=thirdMomentBound M := + by simpa only [Function.comp_def,thirdMomentBound] using + hZ.integral_comp (f := fun z : ℝ => ((M:ℝ)+‖z‖)^3) (by fun_prop) + +lemma thirdMomentBound_nonneg (M : ℝ≥0) : 0≤thirdMomentBound M := + integral_nonneg fun _ => pow_nonneg (add_nonneg M.coe_nonneg (norm_nonneg _)) _ + +lemma scalar_euler_increment_bound (M : ℝ≥0) {δ : ℝ} (hδ0 : 0≤δ) (hδ1 : δ≤1) + {u : ℝ} (hu : ‖u‖≤M) (z : ℝ) : + ‖δ*u+Real.sqrt δ*z‖≤Real.sqrt δ*((M:ℝ)+‖z‖) := by + have hδs : δ≤Real.sqrt δ := by + apply (Real.le_sqrt hδ0 hδ0).mpr + nlinarith + calc + _ ≤ ‖δ*u‖+‖Real.sqrt δ*z‖ := norm_add_le _ _ + _ = δ*‖u‖+Real.sqrt δ*‖z‖ := by + rw [norm_mul,norm_mul,Real.norm_of_nonneg hδ0,Real.norm_of_nonneg (Real.sqrt_nonneg _)] + _ ≤ Real.sqrt δ*(M:ℝ)+Real.sqrt δ*‖z‖ := + add_le_add_left (mul_le_mul hδs hu (norm_nonneg _) (Real.sqrt_nonneg _)) _ + _ = _ := by ring + +lemma scalar_euler_increment_cube (M : ℝ≥0) {δ : ℝ} (hδ0 : 0≤δ) (hδ1 : δ≤1) + {u : ℝ} (hu : ‖u‖≤M) (z : ℝ) : + ‖δ*u+Real.sqrt δ*z‖^3≤(δ*Real.sqrt δ)*((M:ℝ)+‖z‖)^3 := by + have h := pow_le_pow_left₀ (norm_nonneg _) (scalar_euler_increment_bound M hδ0 hδ1 hu z) 3 + have he : (Real.sqrt δ)^3=δ*Real.sqrt δ := by + calc + _ = (Real.sqrt δ)^2*Real.sqrt δ := by ring + _ = _ := by rw [Real.sq_sqrt hδ0] + simpa only [mul_pow,he] using h + +lemma scalar_euler_increment_thirdMoment {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) P) (M : ℝ≥0) + {δ : ℝ} (hδ0 : 0≤δ) (hδ1 : δ≤1) {u : Ω → ℝ} (hu : ∀ ω,‖u ω‖≤M) : + (∫ ω,‖δ*u ω+Real.sqrt δ*Z ω‖^3 ∂P)≤(δ*Real.sqrt δ)*thirdMomentBound M := by + have h := integral_mono_of_nonneg (ae_of_all _ fun _ => pow_nonneg (norm_nonneg _) _) + ((shiftedNorm_integrable_cube hZ M).const_mul (δ*Real.sqrt δ)) + (ae_of_all _ fun ω => scalar_euler_increment_cube M hδ0 hδ1 (hu ω) (Z ω)) + rw [integral_const_mul,shiftedNorm_integral_cube hZ M] at h + exact h + +lemma scalar_euler_increment_memLp {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : Ω → ℝ} (hZ : HasLaw Z (gaussianReal 0 1) P) (M : ℝ≥0) + (δ : ℝ) {u : Ω → ℝ} (hum : AEMeasurable u P) (hu : ∀ ω,‖u ω‖≤M) + {p : ℝ≥0∞} (hp : p≠∞) : MemLp (fun ω => δ*u ω+Real.sqrt δ*Z ω) p P := by + let : IsProbabilityMeasure P := hZ.isProbabilityMeasure + exact ((MemLp.of_bound hum.aestronglyMeasurable (M:ℝ) (ae_of_all _ hu)).const_mul δ).add + ((hZ.hasGaussianLaw.memLp hp).const_mul (Real.sqrt δ)) + +end ParisiPath + +namespace ParisiPath +section IndependentStep +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {X Z : Ω → ℝ} (hX : AEMeasurable X P) (hZ : HasLaw Z (gaussianReal 0 1) P) + (hXZ : IndepFun X Z P) + +include hX hZ hXZ in +lemma independent_gaussian_first {g : ℝ → ℝ} (hg : Measurable g) : + (∫ ω,g (X ω)*Z ω ∂P)=0 := by + have hi : IndepFun (fun ω => g (X ω)) Z P := hXZ.comp hg measurable_id + rw [hi.integral_fun_mul_eq_mul_integral (hg.comp_aemeasurable hX).aestronglyMeasurable + hZ.aemeasurable.aestronglyMeasurable] + have hz : (∫ ω,Z ω ∂P)=0 := by + simpa only [Function.comp_def,integral_id_gaussianReal] using + hZ.integral_comp (f := fun z:ℝ => z) (by fun_prop) + rw [hz,mul_zero] + +include hX hZ hXZ in +lemma independent_gaussian_second {g : ℝ → ℝ} (hg : Measurable g) : + (∫ ω,g (X ω)*(Z ω)^2 ∂P)=∫ ω,g (X ω) ∂P := by + have hi : IndepFun (fun ω => g (X ω)) (fun ω => (Z ω)^2) P := hXZ.comp (φ := g) (ψ := fun z:ℝ => z^2) hg (by fun_prop) + rw [hi.integral_fun_mul_eq_mul_integral (hg.comp_aemeasurable hX).aestronglyMeasurable + (hZ.aemeasurable.pow_const 2).aestronglyMeasurable] + have hz : (∫ ω,(Z ω)^2 ∂P)=1 := by + have hg := variance_fun_id_gaussianReal (μ:=0) (v:=1) + rw [variance_eq_integral (X:= fun x:ℝ => x) + (show AEMeasurable (fun x:ℝ => x) (gaussianReal 0 1) from measurable_id.aemeasurable)] at hg + have hh := hZ.integral_comp (f := fun z:ℝ => z^2) (by fun_prop) + have hg' : (∫ z:ℝ,z^2 ∂gaussianReal 0 1)=1 := by + simpa [integral_id_gaussianReal] using hg + exact hh.trans hg' + rw [hz,mul_one] + +include hX hZ in +lemma integrable_bounded_comp {g : ℝ → ℝ} (hg : Measurable g) {C : ℝ} + (hC : ∀ x,‖g x‖≤C) : Integrable (fun ω => g (X ω)) P := by + let : IsProbabilityMeasure P := hZ.isProbabilityMeasure + exact (integrable_const C).mono' (hg.comp_aemeasurable hX).aestronglyMeasurable + (ae_of_all _ fun _ => hC _) + +include hX hZ hXZ in + + +lemma weak_step_polynomial (f : CubicTest) {g : ℝ → ℝ} (hg : Measurable g) + (M : ℝ≥0) (hM : ∀ x,‖g x‖≤M) {δ : ℝ} (hδ : 0≤δ) : + (∫ ω,deriv f.val (X ω)*(δ*g (X ω)+Real.sqrt δ*Z ω)+ + (1/2:ℝ)*iteratedDeriv 2 f.val (X ω)*(δ*g (X ω)+Real.sqrt δ*Z ω)^2 ∂P)= + δ*(∫ ω,deriv f.val (X ω)*g (X ω)+(1/2:ℝ)*iteratedDeriv 2 f.val (X ω) ∂P)+ + (δ^2/2)*(∫ ω,iteratedDeriv 2 f.val (X ω)*(g (X ω))^2 ∂P) := by + let : IsProbabilityMeasure P := hZ.isProbabilityMeasure + have hm1 := f.continuous_d1.measurable + have hm2 := f.continuous_d2.measurable + have ig1 := integrable_bounded_comp hX hZ (hm1.mul hg) (fun x => by + simp only [Pi.mul_apply,norm_mul]; exact mul_le_mul (f.bound1 x) (hM x) (norm_nonneg _) f.c1.coe_nonneg) + have i1Z := (hZ.hasGaussianLaw.memLp (p:=1) (by norm_num) |>.integrable le_rfl).bdd_mul + (hm1.comp_aemeasurable hX).aestronglyMeasurable (ae_of_all _ fun _ => f.bound1 _) + have ig2 := integrable_bounded_comp hX hZ (hm2.mul (hg.pow_const 2)) (fun x => by + simp only [Pi.mul_apply,norm_mul,norm_pow] + exact mul_le_mul (f.bound2 x) (pow_le_pow_left₀ (norm_nonneg _) (hM x) 2) + (pow_nonneg (norm_nonneg _) _) f.c2.coe_nonneg) + have i2gZ := (hZ.hasGaussianLaw.memLp (p:=1) (by norm_num) |>.integrable le_rfl).bdd_mul + ((hm2.mul hg).comp_aemeasurable hX).aestronglyMeasurable + (ae_of_all _ fun ω => by + change ‖iteratedDeriv 2 f.val (X ω)*g (X ω)‖≤(f.c2:ℝ)*(M:ℝ) + rw [norm_mul] + exact mul_le_mul (f.bound2 _) (hM _) (norm_nonneg _) f.c2.coe_nonneg) + have i2Z := (hZ.hasGaussianLaw.memLp (p:=2) (by norm_num) |>.integrable_sq).bdd_mul + (hm2.comp_aemeasurable hX).aestronglyMeasurable (ae_of_all _ fun _ => f.bound2 _) + have i2 := integrable_bounded_comp hX hZ hm2 f.bound2 + simp only [Function.comp_def,Pi.mul_apply] at ig1 i1Z ig2 i2gZ i2Z + have he : (fun ω => deriv f.val (X ω)*(δ*g (X ω)+Real.sqrt δ*Z ω)+ + (1/2:ℝ)*iteratedDeriv 2 f.val (X ω)*(δ*g (X ω)+Real.sqrt δ*Z ω)^2)= + (fun ω => δ*(deriv f.val (X ω)*g (X ω))+Real.sqrt δ*(deriv f.val (X ω)*Z ω)+ + (δ^2/2)*(iteratedDeriv 2 f.val (X ω)*(g (X ω))^2)+ + (δ*Real.sqrt δ)*(iteratedDeriv 2 f.val (X ω)*g (X ω)*Z ω)+ + (δ/2)*(iteratedDeriv 2 f.val (X ω)*(Z ω)^2)) := by + funext ω + simp only [add_sq,mul_pow,Real.sq_sqrt hδ] + ring + rw [he] + rw [integral_add] + · rw [integral_add] + · rw [integral_add] + · rw [integral_add (ig1.const_mul δ) (i1Z.const_mul (Real.sqrt δ))] + simp only [integral_const_mul] + have hz2 := independent_gaussian_first hX hZ hXZ (hm2.mul hg) + simp only [Pi.mul_apply] at hz2 + rw [independent_gaussian_first hX hZ hXZ hm1,hz2, + independent_gaussian_second hX hZ hXZ hm2, + integral_add ig1 (i2.const_mul (1/2)),integral_const_mul] + ring + · exact (ig1.const_mul δ).add (i1Z.const_mul (Real.sqrt δ)) + · exact ig2.const_mul (δ^2/2) + · exact ((ig1.const_mul δ).add (i1Z.const_mul (Real.sqrt δ))).add (ig2.const_mul (δ^2/2)) + · exact i2gZ.const_mul (δ*Real.sqrt δ) + · exact (((ig1.const_mul δ).add (i1Z.const_mul (Real.sqrt δ))).add + (ig2.const_mul (δ^2/2))).add (i2gZ.const_mul (δ*Real.sqrt δ)) + · exact i2Z.const_mul (δ/2) + +include hX hZ in +lemma weak_step_integrable (f : CubicTest) {g : ℝ → ℝ} (hg : Measurable g) + (M : ℝ≥0) (hM : ∀ x,‖g x‖≤M) (δ : ℝ) : + Integrable (fun ω => f.val (X ω+(δ*g (X ω)+Real.sqrt δ*Z ω))-f.val (X ω)) P := by + let : IsProbabilityMeasure P := hZ.isProbabilityMeasure + have hD := scalar_euler_increment_memLp hZ M δ (hg.comp_aemeasurable hX) + (fun ω => hM (X ω)) (p := 1) (by norm_num) + apply ((hD.integrable le_rfl).norm.const_mul (f.c1:ℝ)).mono' + ((f.continuous.measurable.comp_aemeasurable (hX.add hD.aemeasurable)).sub + (f.continuous.measurable.comp_aemeasurable hX)).aestronglyMeasurable + exact ae_of_all _ fun ω => by + simpa only [add_sub_cancel_left,Function.comp_def,Pi.add_apply,Pi.sub_apply] using f.lipschitz.norm_sub_le + (X ω+(δ*g (X ω)+Real.sqrt δ*Z ω)) (X ω) + +include hX hZ in +lemma weak_step_integrable_polynomial (f : CubicTest) {g : ℝ → ℝ} (hg : Measurable g) + (M : ℝ≥0) (hM : ∀ x,‖g x‖≤M) (δ : ℝ) : + Integrable (fun ω => deriv f.val (X ω)*(δ*g (X ω)+Real.sqrt δ*Z ω)+ + (1/2:ℝ)*iteratedDeriv 2 f.val (X ω)*(δ*g (X ω)+Real.sqrt δ*Z ω)^2) P := by + let : IsProbabilityMeasure P := hZ.isProbabilityMeasure + have hD1 := scalar_euler_increment_memLp hZ M δ (hg.comp_aemeasurable hX) + (fun ω => hM (X ω)) (p := 1) (by norm_num) + have hD2 := scalar_euler_increment_memLp hZ M δ (hg.comp_aemeasurable hX) + (fun ω => hM (X ω)) (p := 2) (by norm_num) + have h1 := (hD1.integrable le_rfl).bdd_mul + (f.continuous_d1.measurable.comp_aemeasurable hX).aestronglyMeasurable + (ae_of_all _ fun ω => f.bound1 (X ω)) + have h2 := hD2.integrable_sq.bdd_mul + (f.continuous_d2.measurable.comp_aemeasurable hX).aestronglyMeasurable + (ae_of_all _ fun ω => f.bound2 (X ω)) + convert! h1.add (h2.const_mul (1/2:ℝ)) using 1 + first | rfl | (funext ω; simp only [Function.comp_def,Pi.add_apply]; ring) + +include hX hZ in +lemma weak_step_taylor_error (f : CubicTest) {g : ℝ → ℝ} (hg : Measurable g) + (M : ℝ≥0) (hM : ∀ x,‖g x‖≤M) {δ : ℝ} (hδ0 : 0≤δ) (hδ1 : δ≤1) : + ‖(∫ ω,f.val (X ω+(δ*g (X ω)+Real.sqrt δ*Z ω))-f.val (X ω) ∂P)- + (∫ ω,deriv f.val (X ω)*(δ*g (X ω)+Real.sqrt δ*Z ω)+ + (1/2:ℝ)*iteratedDeriv 2 f.val (X ω)*(δ*g (X ω)+Real.sqrt δ*Z ω)^2 ∂P)‖≤ + ((f.c3:ℝ)/6)*(δ*Real.sqrt δ)*thirdMomentBound M := by + have hD3 := scalar_euler_increment_memLp hZ M δ (hg.comp_aemeasurable hX) + (fun ω => hM (X ω)) (p := 3) (by norm_num) + rw [←integral_sub (weak_step_integrable hX hZ f hg M hM δ) + (weak_step_integrable_polynomial hX hZ f hg M hM δ)] + calc + _ ≤ ∫ ω,((f.c3:ℝ)/6)*‖δ*g (X ω)+Real.sqrt δ*Z ω‖^3 ∂P := by + apply norm_integral_le_of_norm_le + ((hD3.integrable_norm_pow (by decide : (3:ℕ)≠0)).const_mul ((f.c3:ℝ)/6)) + exact ae_of_all _ fun ω => by + have hh := cubic_taylor_bound f.smooth f.bound3 (X ω) (δ*g (X ω)+Real.sqrt δ*Z ω) + convert hh using 1 + · congr 1; ring + · simp only [Real.norm_eq_abs,Function.comp_def] + ring + _ = ((f.c3:ℝ)/6)*(∫ ω,‖δ*g (X ω)+Real.sqrt δ*Z ω‖^3 ∂P) := integral_const_mul _ _ + _ ≤ ((f.c3:ℝ)/6)*((δ*Real.sqrt δ)*thirdMomentBound M) := + mul_le_mul_of_nonneg_left + (scalar_euler_increment_thirdMoment hZ M hδ0 hδ1 (fun ω => hM (X ω))) (by positivity) + _ = _ := by ring + +include hX hZ hXZ in + + +lemma weak_step_error (f : CubicTest) {g : ℝ → ℝ} (hg : Measurable g) + (M : ℝ≥0) (hM : ∀ x,‖g x‖≤M) {δ : ℝ} (hδ0 : 0≤δ) (hδ1 : δ≤1) : + ‖(∫ ω,f.val (X ω+(δ*g (X ω)+Real.sqrt δ*Z ω))-f.val (X ω) ∂P)- + δ*(∫ ω,deriv f.val (X ω)*g (X ω)+(1/2:ℝ)*iteratedDeriv 2 f.val (X ω) ∂P)‖≤ + (δ*Real.sqrt δ)*((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) := by + let : IsProbabilityMeasure P := hZ.isProbabilityMeasure + have he := weak_step_taylor_error hX hZ f hg M hM hδ0 hδ1 + rw [weak_step_polynomial hX hZ hXZ f hg M hM hδ0] at he + have hi : ‖∫ ω,iteratedDeriv 2 f.val (X ω)*(g (X ω))^2 ∂P‖≤(f.c2:ℝ)*(M:ℝ)^2 := by + simpa using norm_integral_le_of_norm_le_const (μ:=P) (f:=fun ω => + iteratedDeriv 2 f.val (X ω)*(g (X ω))^2) (C:=(f.c2:ℝ)*(M:ℝ)^2) + (ae_of_all _ fun ω => by + rw [norm_mul,norm_pow] + exact mul_le_mul (f.bound2 _) (pow_le_pow_left₀ (norm_nonneg _) (hM _) 2) + (pow_nonneg (norm_nonneg _) _) f.c2.coe_nonneg) + have hterm : ‖δ^2/2*(∫ ω,iteratedDeriv 2 f.val (X ω)*(g (X ω))^2 ∂P)‖≤ + δ^2/2*((f.c2:ℝ)*(M:ℝ)^2) := by + rw [norm_mul,Real.norm_of_nonneg (by positivity : 0≤δ^2/2)] + exact mul_le_mul_of_nonneg_left hi (by positivity) + have htriangle := norm_le_norm_add_norm_sub' + ((∫ ω,f.val (X ω+(δ*g (X ω)+Real.sqrt δ*Z ω))-f.val (X ω) ∂P)- + δ*(∫ ω,deriv f.val (X ω)*g (X ω)+(1/2:ℝ)*iteratedDeriv 2 f.val (X ω) ∂P)) + (δ^2/2*(∫ ω,iteratedDeriv 2 f.val (X ω)*(g (X ω))^2 ∂P)) + have hδs : δ≤Real.sqrt δ := (Real.le_sqrt hδ0 hδ0).mpr (by nlinarith) + have herr := mul_le_mul_of_nonneg_left hδs hδ0 + have hprod := mul_le_mul_of_nonneg_right herr (show 0≤(f.c2:ℝ)*(M:ℝ)^2/2 by positivity) + rw [sub_add_eq_sub_sub] at he + nlinarith [he,hterm] + +end IndependentStep +end ParisiPath + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/HugeSelectiveBounded.lean b/lean/OAI/Probability/ParisiFinite/HugeSelectiveBounded.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6eff1058c5c22aa1a57b7caea02f46f477ebf39 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/HugeSelectiveBounded.lean @@ -0,0 +1,708 @@ +import Mathlib +import OAI.Probability.ParisiFinite.RotationAccuracy + +namespace OAI + +/-! Huge Selective Bounded. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance hpsRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance hpsRealSMul : SMul ℝ ModeInfinity := hpsRealModule.toDistribMulAction.toSMul + + + +theorem huge_selective_bounded {α κ : Type*} [Fintype κ] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (t : ℝ) (ht : t≠0) + (o s xp xm : α → SpinSpace ModeInfinity) + (hxp : BoundedPacket l xp) (hxm : BoundedPacket l xm) + (d : κ → α → ModeInfinity) (spin : κ → Fin 2) + (hs : PacketExpansion (l:=l) S r d spin s) + (C : ℝ) (hC : 0≤C) (hd : ∀i,∀ᶠ q in l,‖d i q‖≤C) + (c y : κ → ℝ) (hc : ∀i,c i≠0) (θ : ℝ) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0≤r q) + (hS : Tendsto S l atTop) (hscale : ∀ᶠ q in l,S q*r q=1) + (hψ : ∀ᶠ q in l,ordinaryLocal (w q) (vacuum ModeInfinity)=o q+s q) + (ho : Tendsto (fun q => S q*‖o q-(spinW ((S q:ℂ) • ((-t) • insertionInfinity (w q))) (xp q)+ + spinW ((S q:ℂ) • (t • insertionInfinity (w q))) (xm q))‖) l (𝓝 0)) + (hop : ∀q,SpinOperators.act Z (xp q)=xp q) + (hom : ∀q,SpinOperators.act Z (xm q)= -xm q) + (hZ : ∀i,Tendsto (fun q => (⟪insertionInfinity (w q),d i q⟫_ℂ).im) l (𝓝 (c i))) + (hY : ∀i,Tendsto (fun q => -2*(⟪insertionYInfinity (w q),d i q⟫_ℂ).im) l (𝓝 (y i))) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + (∀ (b : ℝ) z,BoundedPacket l z → + Tendsto (fun q => S q*‖probeGain (r q) (w q) a K + (spinW ((S q:ℂ) • (b • insertionInfinity (w q))) (z q))- + spinW ((S q:ℂ) • (b • insertionInfinity (w q))) (z q)‖) l (𝓝 0)) ∧ + (∀ z,PacketExpansion (l:=l) S r d spin z → + Tendsto (fun q => S q*‖probeGain (r q) (w q) a K (z q)- + SpinOperators.act (R θ) (z q)‖) l (𝓝 0)) := by + classical + obtain ⟨τ,hτ,_,hsp⟩ := hs + let tails : (Fin 2 ⊕ κ) → α → SpinSpace ModeInfinity := Sum.elim (fun i => if i=0 then xp else xm) τ + have htails : ∀i,BoundedPacket l (tails i) := by + intro i + cases i with + | inl i => fin_cases i <;> simpa [tails] using (show BoundedPacket l _ from by assumption) + | inr i => exact hτ i + obtain ⟨p,B,A,hB,hA,heq,hbd⟩ := BoundedPacket.finite_uniform tails htails + let pp := p (Sum.inl 0) + let pm := p (Sum.inl 1) + let z (i : κ) := p (Sum.inr i) + have hpp : ∀q,xp q=spinCoe (pp q) := by simpa [tails,pp] using heq (Sum.inl 0) + have hpm : ∀q,xm q=spinCoe (pm q) := by simpa [tails,pm] using heq (Sum.inl 1) + have hz : ∀i q,τ i q=spinCoe (z i q) := fun i q => heq (Sum.inr i) q + let op (q : α) := actualPacket (S q) ((-t) • insertionInfinity (w q)) (pp q) + let om (q : α) := actualPacket (S q) (t • insertionInfinity (w q)) (pm q) + let xs (i : κ) (q : α) := (r q:ℂ) • z i q + let sp (q : α) := ∑i,actualPacket (S q) (d i q) (xs i q) + let ρ (q : α) := (o q-(op q+om q))+(s q-sp q) + have ho' : Tendsto (fun q => S q*‖o q-(op q+om q)‖) l (𝓝 0) := by + simpa only [op,om,actualPacket,hpp,hpm,Complex.coe_smul] using ho + have hsp' : Tendsto (fun q => S q*‖s q-sp q‖) l (𝓝 0) := by + have hh (q : α) : sp q=∑i,(r q:ℂ) • actualPacket (S q) (d i q) (z i q) := by + simp only [sp,xs,actualPacket_smul] + simpa only [hh,actualPacket,hz,Complex.coe_smul] using hsp + have hS0 : ∀ᶠ q in l,0≤S q := hS.eventually (eventually_ge_atTop 0) + have hscl : ∀ᶠ q in l,0≤S q ∧ 0≤r q ∧ S q*r q=1 := by + filter_upwards [hS0,hp,hscale] with q hq hpq he + exact ⟨hq,hpq,he⟩ + have hρ : Tendsto (fun q => S q*‖ρ q‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [add_zero] using ho'.add hsp') + · filter_upwards [hS0] with q hq + exact mul_nonneg hq (norm_nonneg _) + · filter_upwards [hS0] with q hq + simpa only [ρ,mul_add] using mul_le_mul_of_nonneg_left + (norm_add_le (o q-(op q+om q)) (s q-sp q)) hq + have hxs : ∀i,∀ᶠ q in l,SpinRadiusLE (xs i q) B ∧ spinMass (xs i q)≤A := by + intro i + filter_upwards [hbd,hp,hr.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1))] with q hq hpq hu + refine ⟨(hq (Sum.inr i)).1.smul _,?_⟩ + simp only [xs,spinMass_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hpq] + exact (mul_le_mul_of_nonneg_left (hq (Sum.inr i)).2 hpq).trans (mul_le_of_le_one_left hA hu.le) + have hnorm : ∀ᶠ q in l,‖∑i,actualPacket (S q) (d i q) (z i q)‖≤Fintype.card κ*A := by + filter_upwards [hbd] with q hq + calc + _ ≤ ∑i,‖actualPacket (S q) (d i q) (z i q)‖ := norm_sum_le _ _ + _ ≤ ∑_i : κ,A := Finset.sum_le_sum (fun i _ => (norm_actualPacket_le_mass ..).trans (hq (Sum.inr i)).2) + _ = _ := by simp + have hssq := ForwardControl.scaled_square_small_amplitude S r + (fun q => ∑i,actualPacket (S q) (d i q) (z i q)) (Fintype.card κ*A) (by positivity) hr hscl hnorm + have hvac : ∀ᶠ q in l,ordinaryLocal (w q) (vacuum ModeInfinity)=op q+om q+sp q+ρ q := by + filter_upwards [hψ] with q hq + rw [hq] + dsimp only [ρ] + abel + have hopp : ∀ᶠ q in l,SpinOperators.act Z (op q)=op q := Eventually.of_forall fun q => by + simp only [op,actualPacket,←spinW_root,←hpp,hop] + have homm : ∀ᶠ q in l,SpinOperators.act Z (om q)= -om q := Eventually.of_forall fun q => by + simp only [om,actualPacket,←spinW_root,←hpm,hom,map_neg] + obtain ⟨K,a,hoi,hsi⟩ := huge_selective_accuracy r S w t ht d pp pm xs ρ B A hB hA c y hc θ + hr hp hS hscale (hbd.mono fun _ hq => hq (Sum.inl 0)) (hbd.mono fun _ hq => hq (Sum.inl 1)) + hxs hZ hvac hopp homm hρ (by simpa only [sp,xs,actualPacket_smul,←Finset.smul_sum] using hssq) + refine ⟨K,a,?_,?_⟩ + · intro b u hu + obtain ⟨p',B',A',hB',hA',hu,hp'⟩ := hu + simpa only [hu,actualPacket,Complex.coe_smul] using hoi b p' B' A' hB' hA' hp' + · intro u hu + apply hu.rotation_accuracy (fun q => probeGain (r q) (w q) a K) θ hS0 + (by filter_upwards [hp,hscale] with q hq he; exact ⟨hq,he⟩) + intro i u' hu' + obtain ⟨p',B',A',hB',hA',hu',hp'⟩ := hu' + have hZ' : Tendsto (fun q => -2*(⟪insertionInfinity (w q),d i q⟫_ℂ).im) l (𝓝 (-2*c i)) := + (hZ i).const_mul _ + simpa only [hu',actualPacket,Complex.coe_smul] using + hsi i (d i) p' C B' A' hC hB' hA' (hd i) hp' hZ' (hY i) + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +open RootSpin +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem real_neg_div_scale (r t : ℝ) (v : E) : + -(t/r) • v = ((r⁻¹:ℝ):ℂ) • ((-t) • v) := by + rw [Complex.coe_smul,smul_smul] + congr 1 + ring + +theorem real_div_scale (r t : ℝ) (v : E) : + (t/r) • v = ((r⁻¹:ℝ):ℂ) • (t • v) := by + rw [Complex.coe_smul,smul_smul] + congr 1 + ring + +theorem complex_neg_real_smul (t : ℝ) (v : E) : -(t:ℂ) • v=(-t) • v := by + rw [←Complex.ofReal_neg,Complex.coe_smul] + +theorem WZ_split_two (v : E) (x : SpinSpace E) : + WZ v x=spinW v (projectSpin 0 x)+spinW (-v) (projectSpin 1 x) := by + conv_lhs => rw [←projectSpin_sum x,map_sum] + simp only [Fin.sum_univ_two,WZ_project,signedMode,ite_true] + rfl + +theorem rootZ_project_zero (x : SpinSpace E) : + SpinOperators.act Z (projectSpin 0 x)=projectSpin 0 x := by + ext i + fin_cases i <;> simp [SpinOperators.act_apply,Z,projectSpin_apply] + +theorem rootZ_project_one (x : SpinSpace E) : + SpinOperators.act Z (projectSpin 1 x)= -projectSpin 1 x := by + ext i + fin_cases i <;> simp [SpinOperators.act_apply,Z,projectSpin_apply] + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin +local instance hsRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance hsRealSMul : SMul ℝ ModeInfinity := hsRealModule.toDistribMulAction.toSMul + +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + +def forwardWord (st : PacketStage l r (fun q => (r q)⁻¹) d spin) (t : ℝ) (q : α) : List Gate := + .cost (t/r q)::st.word q + +def forwardVector (st : PacketStage l r (fun q => (r q)⁻¹) d spin) (t : ℝ) (q : α) : ModeInfinity := + -(t/r q) • insertionInfinity (st.word q) + +def forwardCenter (st : PacketStage l r (fun q => (r q)⁻¹) d spin) (t : ℝ) (i : κ) (q : α) : ModeInfinity := + d i q+signedMode (spin i) ((-t) • insertionInfinity (st.word q)) + +theorem forwardVector_scale (st : PacketStage l r (fun q => (r q)⁻¹) d spin) (t : ℝ) (q : α) : + st.forwardVector t q=(((r q)⁻¹:ℝ):ℂ) • ((-t) • insertionInfinity (st.word q)) := by + apply real_neg_div_scale + +theorem forward_special_packets (st : PacketStage l r (fun q => (r q)⁻¹) d spin) (t : ℝ) + (x : α → SpinSpace ModeInfinity) (hx : BoundedPacket l x) : + PacketExpansion (l:=l) (fun q => (r q)⁻¹) r (st.forwardCenter t) spin + (fun q => WZ (st.forwardVector t q) (st.special q (x q))) := by + have hh := (st.special_packets x hx).huge_cost (fun q => (-t) • insertionInfinity (st.word q)) + change PacketExpansion (l:=l) (fun q => (r q)⁻¹) r + (fun i q => d i q+signedMode (spin i) ((-t) • insertionInfinity (st.word q))) spin _ + simpa only [forwardVector_scale] using hh + + + +theorem exists_huge_selector (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (ht : t≠0) (θ : ℝ) (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 (⟪insertionInfinity (st.forwardWord t q),st.forwardCenter t i q⟫_ℂ).im) l (𝓝 (c i))) + (hY : ∀i,Tendsto (fun q => -2*(⟪insertionYInfinity (st.forwardWord t q),st.forwardCenter t i q⟫_ℂ).im) l (𝓝 (y i))) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + (∀x,BoundedPacket l x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K + (WZ (st.forwardVector t q) (x q))-WZ (st.forwardVector t q) (x q)‖) l (𝓝 0)) ∧ + (∀x,PacketExpansion (l:=l) (fun q => (r q)⁻¹) r (st.forwardCenter t) spin x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (x q)- + SpinOperators.act (R θ) (x q)‖) l (𝓝 0)) := by + let low (q : α) := st.phase q • st.low.op q (vacuum ModeInfinity) + let xp (q : α) := projectSpin 0 (low q) + let xm (q : α) := projectSpin 1 (low q) + let o (q : α) := WZ (st.forwardVector t q) (st.ordinary q (vacuum ModeInfinity)) + let s (q : α) := WZ (st.forwardVector t q) (st.special q (vacuum ModeInfinity)) + have hlow : BoundedPacket l low := st.low_bounded _ BoundedPacket.vacuum + have hfw (q : α) : insertionInfinity (st.forwardWord t q)=insertionInfinity (st.word q) := + insertionInfinity_cost _ _ + have hsplit (q : α) (x : SpinSpace ModeInfinity) : + WZ (st.forwardVector t q) x= + spinW ((((r q)⁻¹:ℝ):ℂ) • ((-t) • insertionInfinity (st.forwardWord t q))) (projectSpin 0 x)+ + spinW ((((r q)⁻¹:ℝ):ℂ) • (t • insertionInfinity (st.forwardWord t q))) (projectSpin 1 x) := by + rw [WZ_split_two,forwardVector_scale,hfw] + simp only [neg_smul,smul_neg,neg_neg] + have hψ : ∀ᶠ q in l,ordinaryLocal (st.forwardWord t q) (vacuum ModeInfinity)=o q+s q := by + exact Eventually.of_forall fun q => by + change ordinaryLocal (.cost (t/r q)::st.word q) (vacuum ModeInfinity)=_ + rw [ordinaryLocal_cost,st.split,map_add] + simp only [o,s,forwardVector,complex_neg_real_smul] + have ho : Tendsto (fun q => (r q)⁻¹*‖o q-( + spinW ((((r q)⁻¹:ℝ):ℂ) • ((-t) • insertionInfinity (st.forwardWord t q))) (xp q)+ + spinW ((((r q)⁻¹:ℝ):ℂ) • (t • insertionInfinity (st.forwardWord t q))) (xm q))‖) l (𝓝 0) := by + simpa only [xp,xm,←hsplit,o,low,←map_sub,norm_WZ] using st.ordinary_low _ BoundedPacket.vacuum + have hS : Tendsto (fun q => (r q)⁻¹) l atTop := tendsto_inv_nhdsGT_zero.comp (tendsto_nhdsWithin_iff.mpr ⟨hr,hp⟩) + obtain ⟨K,a,hord,hsp⟩ := huge_selective_bounded r (fun q => (r q)⁻¹) (st.forwardWord t) t ht + o s xp xm (hlow.project 0) (hlow.project 1) (st.forwardCenter t) spin + (st.forward_special_packets t _ BoundedPacket.vacuum) C hC hd c y hc θ hr + (hp.mono fun _ hq => hq.le) hS (hp.mono fun _ hq => inv_mul_cancel₀ hq.ne') hψ ho + (fun q => rootZ_project_zero (low q)) (fun q => rootZ_project_one (low q)) hZ hY + refine ⟨K,a,?_,hsp⟩ + intro x hx + have h1 := hord (-t) _ (hx.project 0) + have h2 := hord t _ (hx.project 1) + have hh := ForwardControl.scaled_identity_add (fun q => probeGain (r q) (st.forwardWord t q) a K) + (fun q => (r q)⁻¹) _ _ (hp.mono fun _ hq => (inv_pos.mpr hq).le) h1 h2 + simpa only [hsplit] using hh + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance heRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance heRealSMul : SMul ℝ ModeInfinity := heRealModule.toDistribMulAction.toSMul + +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + +def halfEchoWord (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) : List Gate := + .cost (-(t/r q))::probePrefix (r q) (st.forwardWord t q) a K + +def reverseVector (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) : ModeInfinity := + (t/r q) • insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K) + +def halfEchoResidual (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) : ModeInfinity := + (t/r q) • (insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K)-insertionInfinity (st.word q)) + +def halfEchoPhase (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) : ℂ := + CoherentFock.phase (st.reverseVector t a K q) (st.forwardVector t q) + +def halfEchoCenter (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (i : κ) (q : α) : ModeInfinity := + st.forwardCenter t i q+signedMode (1-spin i) + (t • insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K)) + +def halfEchoGain (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) : + SpinSpace ModeInfinity ≃ₗᵢ[ℂ] SpinSpace ModeInfinity := + wordGain (st.word q) (st.halfEchoWord t a K q) + +theorem halfEchoGain_apply (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) (x : SpinSpace ModeInfinity) : + st.halfEchoGain t a K q x=WZ (st.reverseVector t a K q) + (probeGain (r q) (st.forwardWord t q) a K (WZ (st.forwardVector t q) x)) := by + rw [halfEchoGain,wordGain_apply,halfEchoWord,ordinaryLocal_cost,←probeGain_on_local, + forwardWord,ordinaryLocal_cost] + simp only [LinearIsometryEquiv.apply_symm_apply,Complex.ofReal_neg,neg_neg] + simp only [reverseVector,forwardVector,RCLike.real_smul_eq_coe_smul (K:=ℂ),RCLike.ofReal_neg] + rfl + +theorem halfEcho_identity_exact (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) (x : SpinSpace ModeInfinity) : + WZ (st.reverseVector t a K q) (WZ (st.forwardVector t q) x)= + st.halfEchoPhase t a K q • WZ (st.halfEchoResidual t a K q) x := by + rw [←ContinuousLinearMap.comp_apply,WZ_mul] + have he : st.reverseVector t a K q+st.forwardVector t q=st.halfEchoResidual t a K q := by + simp only [reverseVector,forwardVector,halfEchoResidual,neg_smul,sub_eq_add_neg,smul_add,smul_neg] + rw [he] + rfl + +theorem reverseVector_scale (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) : + st.reverseVector t a K q=(((r q)⁻¹:ℝ):ℂ) • + (t • insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K)) := by + apply real_div_scale + + + +def halfEcho (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (G : ℝ) (hG : 0≤G) + (hg : ∀ᶠ q in l,‖st.halfEchoResidual t a K q‖≤G) + (hp : ∀ᶠ q in l,0 (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K + (WZ (st.forwardVector t q) (x q))-WZ (st.forwardVector t q) (x q)‖) l (𝓝 0)) + (hs : ∀x,BoundedPacket l x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K + (WZ (st.forwardVector t q) (st.special q (x q)))- + SpinOperators.act (R (Real.pi/2)) (WZ (st.forwardVector t q) (st.special q (x q)))‖) l (𝓝 0)) : + PacketStage l r (fun q => (r q)⁻¹) (st.halfEchoCenter t a K) (fun i => 1-spin i) where + word := st.halfEchoWord t a K + ordinary q := (st.halfEchoGain t a K q).toContinuousLinearEquiv.toContinuousLinearMap.comp (st.ordinary q) + special q := (st.halfEchoGain t a K q).toContinuousLinearEquiv.toContinuousLinearMap.comp (st.special q) + split q x := by + change ordinaryLocal (st.halfEchoWord t a K q) x=st.halfEchoGain t a K q (st.ordinary q x)+st.halfEchoGain t a K q (st.special q x) + rw [←map_add,←st.split] + simp only [halfEchoGain,wordGain_apply,LinearIsometryEquiv.symm_apply_apply] + special_norm := by + filter_upwards [st.special_norm] with q hq x + simpa only [ContinuousLinearMap.comp_apply,LinearIsometryEquiv.coe_toContinuousLinearEquiv, + ContinuousLinearEquiv.coe_coe,LinearIsometryEquiv.norm_map] using hq x + low := st.low.trans (PacketUnitaryFamily.pulse (st.halfEchoResidual t a K) G hG hg) + phase q := st.halfEchoPhase t a K q*st.phase q + phase_norm q := by rw [norm_mul,halfEchoPhase,norm_phase,st.phase_norm,mul_one] + ordinary_low x hx := by + let low (q : α) := st.phase q • st.low.op q (x q) + have hp0 : ∀ᶠ q in l,0≤(r q)⁻¹ := hp.mono fun _ hq => (inv_pos.mpr hq).le + have h1 : Tendsto (fun q => (r q)⁻¹*‖st.halfEchoGain t a K q (st.ordinary q (x q))- + st.halfEchoGain t a K q (low q)‖) l (𝓝 0) := by + simpa only [←map_sub,LinearIsometryEquiv.norm_map] using st.ordinary_low x hx + have h2 : Tendsto (fun q => (r q)⁻¹*‖st.halfEchoGain t a K q (low q)- + st.halfEchoPhase t a K q • WZ (st.halfEchoResidual t a K q) (low q)‖) l (𝓝 0) := by + simpa only [halfEchoGain_apply,←halfEcho_identity_exact,←map_sub,norm_WZ] using + ho low (st.low_bounded x hx) + have hh := ForwardControl.scaled_triangle (fun q => (r q)⁻¹) _ _ _ hp0 h1 h2 + change Tendsto (fun q => (r q)⁻¹*‖st.halfEchoGain t a K q (st.ordinary q (x q))- + (st.halfEchoPhase t a K q*st.phase q) • WZ (st.halfEchoResidual t a K q) (st.low.op q (x q))‖) l (𝓝 0) + simpa only [low,map_smul,smul_smul] using hh + special_packets x hx := by + have hS : ∀ᶠ q in l,0≤(r q)⁻¹ := hp.mono fun _ hq => (inv_pos.mpr hq).le + have hu := ((st.forward_special_packets t x hx).half_mixer).close hS (hs x hx) + have hh := hu.huge_cost (fun q => t • insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K)) + change PacketExpansion (l:=l) (fun q => (r q)⁻¹) r + (fun i q => st.forwardCenter t i q+signedMode (1-spin i) + (t • insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K))) (fun i => 1-spin i) + (fun q => st.halfEchoGain t a K q (st.special q (x q))) + simpa only [halfEchoGain_apply,reverseVector_scale] using hh + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance hcRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance hcRealSMul : SMul ℝ ModeInfinity := hcRealModule.toDistribMulAction.toSMul + +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +theorem forward_four (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t θ : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (hp : ∀ᶠ q in l,0 (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K + (WZ (st.forwardVector t q) (x q))-WZ (st.forwardVector t q) (x q)‖) l (𝓝 0)) + (hs : ∀x,PacketExpansion (l:=l) (fun q => (r q)⁻¹) r (st.forwardCenter t) spin x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (x q)- + SpinOperators.act (R θ) (x q)‖) l (𝓝 0)) : + let o := fun q => WZ (st.forwardVector t q) (st.ordinary q (vacuum ModeInfinity)) + let s := fun q => WZ (st.forwardVector t q) (st.special q (vacuum ModeInfinity)) + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (o q)-o q‖) l (𝓝 0) ∧ + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (s q)-SpinOperators.act (R θ) (s q)‖) l (𝓝 0) ∧ + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (SpinOperators.act Z (o q))- + SpinOperators.act Z (o q)‖) l (𝓝 0) ∧ + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (SpinOperators.act Z (s q))- + SpinOperators.act (R θ) (SpinOperators.act Z (s q))‖) l (𝓝 0) := by + dsimp only + let low (q : α) := st.phase q • st.low.op q (vacuum ModeInfinity) + let V (q : α) := probeGain (r q) (st.forwardWord t q) a K + have hlow : BoundedPacket l low := st.low_bounded _ BoundedPacket.vacuum + have hS : ∀ᶠ q in l,0≤(r q)⁻¹ := hp.mono fun _ hq => (inv_pos.mpr hq).le + have he : Tendsto (fun q => (r q)⁻¹*‖WZ (st.forwardVector t q) (st.ordinary q (vacuum ModeInfinity))- + WZ (st.forwardVector t q) (low q)‖) l (𝓝 0) := by + simpa only [←map_sub,norm_WZ] using st.ordinary_low _ BoundedPacket.vacuum + have h1 := ForwardControl.scaled_identity_transfer V (fun q => (r q)⁻¹) _ _ hS (ho low hlow) he + have heZ : Tendsto (fun q => (r q)⁻¹*‖SpinOperators.act Z + (WZ (st.forwardVector t q) (st.ordinary q (vacuum ModeInfinity)))- + SpinOperators.act Z (WZ (st.forwardVector t q) (low q))‖) l (𝓝 0) := by + simpa only [←map_sub,SpinOperators.norm_act Z_unitary] using he + have hZlow : Tendsto (fun q => (r q)⁻¹*‖V q (SpinOperators.act Z (WZ (st.forwardVector t q) (low q)))- + SpinOperators.act Z (WZ (st.forwardVector t q) (low q))‖) l (𝓝 0) := by + simpa only [WZ_rootZ_apply,V] using ho _ (hlow.root Z) + have h3 := ForwardControl.scaled_identity_transfer V (fun q => (r q)⁻¹) _ _ hS hZlow heZ + have hpack := st.forward_special_packets t _ BoundedPacket.vacuum + exact ⟨h1,hs _ hpack,h3,hs _ hpack.rootZ⟩ + + + +theorem halfEchoResidual_tendsto (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (address : α → ModeInfinity) (ht : st.Transported (fun q => modeFock (address q))) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (hp : ∀ᶠ q in l,0 (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K + (WZ (st.forwardVector t q) (x q))-WZ (st.forwardVector t q) (x q)‖) l (𝓝 0)) + (hs : ∀x,PacketExpansion (l:=l) (fun q => (r q)⁻¹) r (st.forwardCenter t) spin x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (x q)- + SpinOperators.act (R (Real.pi/2)) (x q)‖) l (𝓝 0)) : + Tendsto (fun q => ‖st.halfEchoResidual t a K q-(-2*t) • address q‖) l (𝓝 0) := by + let o (q : α) := WZ (st.forwardVector t q) (st.ordinary q (vacuum ModeInfinity)) + let s (q : α) := WZ (st.forwardVector t q) (st.special q (vacuum ModeInfinity)) + obtain ⟨h1,h2,h3,h4⟩ := st.forward_four t (Real.pi/2) a K hp ho hs + have hx (q : α) : ordinaryLocal (st.forwardWord t q) (vacuum ModeInfinity)=o q+s q := by + simp only [forwardWord,ordinaryLocal_cost,st.split,map_add,o,s,forwardVector,complex_neg_real_smul] + have htc : Tendsto (fun q => ‖(r q)⁻¹ • (ordinaryLocal (st.forwardWord t q)).symm + (SpinOperators.act Z (s q))-modeFock (address q)‖) l (𝓝 0) := by + have he (q : α) : (ordinaryLocal (st.forwardWord t q)).symm (SpinOperators.act Z (s q))= + (ordinaryLocal (st.word q)).symm (SpinOperators.act Z (st.special q (vacuum ModeInfinity))) := by + simpa only [forwardWord,s,forwardVector,complex_neg_real_smul] using + cost_transport_exact (st.word q) (t/r q) (st.special q (vacuum ModeInfinity)) + simpa only [he,Complex.coe_smul,Transported] using ht + have hh := actual_flip_mode_tendsto r (st.forwardWord t) a K o s address + (SpinOperators.act (R (Real.pi/2))) half_mixer_anticommutes hx t hp h1 h2 h3 h4 htc + simpa only [halfEchoResidual,forwardWord,insertionInfinity_cost] using hh + + + +theorem halfEchoResidual_bounded (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (address : α → ModeInfinity) (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) + (A : ℝ) (_hA : 0≤A) (ha : ∀ᶠ q in l,‖address q‖≤A) + (he : Tendsto (fun q => ‖st.halfEchoResidual t a K q-(-2*t) • address q‖) l (𝓝 0)) : + ∀ᶠ q in l,‖st.halfEchoResidual t a K q‖≤1+2*|t| * A := by + filter_upwards [ha,he.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1))] with q haq heq + have hn := norm_le_norm_sub_add (st.halfEchoResidual t a K q) ((-2*t) • address q) + rw [norm_smul,Real.norm_eq_abs,abs_mul,abs_neg] at hn + rw [abs_of_nonneg (by norm_num : (0:ℝ)≤2)] at hn + nlinarith [abs_nonneg t] + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +open RootSpin +variable {E α : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] {l : Filter α} + +def preProject (i : Fin 2) (x : PreSpin E) : PreSpin E := fun j => if j=i then x j else 0 + +@[simp] theorem spinCoe_preProject (i : Fin 2) (x : PreSpin E) : + spinCoe (preProject i x)=projectSpin i (spinCoe x) := by + ext j + simp only [spinCoe_apply,preProject,projectSpin_apply] + split_ifs <;> rfl + +omit [InnerProductSpace ℂ E] in +theorem preProject_radius (i : Fin 2) (x : PreSpin E) (B : ℝ) (hx : SpinRadiusLE x B) : + SpinRadiusLE (preProject i x) B := by + intro j + simp only [preProject] + split_ifs + · exact hx j + · exact RadiusLE.zero B + +omit [NormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem preProject_mass (i : Fin 2) (x : PreSpin E) : spinMass (preProject i x) ≤ spinMass x := by + apply Finset.sum_le_sum + intro j _ + simp only [preProject] + split_ifs + · exact le_rfl + · simpa only [mass_zero] using mass_nonneg (x j) + + + +theorem transverse_WZ_bounded (R : α → ℝ) (v : α → E) + (x y : α → SpinSpace E) (hx : BoundedPacket l x) (hy : BoundedPacket l y) + (hR : Tendsto R l atTop) (δ : ℝ) (hδ : 0<δ) + (hsep : ∀ᶠ q in l,δ≤‖v q-(-v q)‖) : + Tendsto (fun q => ⟪SpinOperators.act Y (WZ ((R q:ℂ) • v q) (x q)), + WZ ((R q:ℂ) • v q) (y q)⟫_ℂ) l (𝓝 0) := by + let z : Fin 2 → α → SpinSpace E := ![x,y] + have hz : ∀i,BoundedPacket l (z i) := by intro i; fin_cases i <;> assumption + obtain ⟨p,B,A,hB,hA,hp,hbd⟩ := BoundedPacket.finite_uniform z hz + let tail (i j : Fin 2) (q : α) := preProject j (p i q) + have ht (i j : Fin 2) : ∀ᶠ q in l,SpinRadiusLE (tail i j q) B ∧ spinMass (tail i j q)≤A := by + filter_upwards [hbd] with q hq + exact ⟨preProject_radius j _ B (hq i).1,(preProject_mass j _).trans (hq i).2⟩ + have hs : ∀ᶠ q in l,tail 0 0 q 1=0 ∧ tail 0 1 q 0=0 ∧ tail 1 0 q 1=0 ∧ tail 1 1 q 0=0 := + Eventually.of_forall fun q => by simp [tail,preProject] + have hh := tendsto_inner_rootY_hugePacket R v (fun q => -v q) + (tail 0 0) (tail 0 1) (tail 1 0) (tail 1 1) hR B A δ hA hδ + (ht 0 0) (ht 0 1) (ht 1 0) (ht 1 1) hs hsep + have he (i : Fin 2) (q : α) : hugePacket (R q) (v q) (-v q) (tail i 0 q) (tail i 1 q)= + WZ ((R q:ℂ) • v q) (z i q) := by + simp only [hugePacket,tail,spinCoe_preProject] + rw [←hp i q,WZ_split_two] + simp only [smul_neg,Complex.coe_smul] + simpa only [he,z,Matrix.cons_val_zero,Matrix.cons_val_one,Matrix.head_cons] using hh + +theorem unit_opposite_separation (v : E) (hv : ‖v‖=1) (t : ℝ) : + ‖(-t) • v-(-((-t) • v))‖=2*|t| := by + have hn : -((-t) • v)=t • v := by simp + rw [hn,←sub_smul,norm_smul,Real.norm_eq_abs,hv,mul_one] + have he : -t-t=-(2*t) := by ring + rw [he,abs_neg,abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin +local instance htRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance htRealSMul : SMul ℝ ModeInfinity := htRealModule.toDistribMulAction.toSMul +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r S : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +theorem actual_low_norm (st : PacketStage l r S d spin) + (hr : Tendsto r l (𝓝 0)) (hS : ∀ᶠ q in l,1≤S q) + (x : α → SpinSpace ModeInfinity) (hx : BoundedPacket l x) : + Tendsto (fun q => ‖ordinaryLocal (st.word q) (x q)-st.phase q • st.low.op q (x q)‖) l (𝓝 0) := by + have ho := PacketGeometry.tendsto_of_scaled S _ hS + (Eventually.of_forall fun q => norm_nonneg _) (st.ordinary_low x hx) + obtain ⟨C,hC,hxC⟩ := hx.norm_bounded + have hs : Tendsto (fun q => ‖st.special q (x q)‖) l (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall fun q => norm_nonneg _) _ + (by simpa only [zero_mul] using hr.mul_const C) + filter_upwards [st.special_norm,hxC] with q hq hxq + have hrq : 0≤r q := by + have hh := hq (vacuum ModeInfinity) + rw [norm_vacuum,mul_one] at hh + exact hh ▸ norm_nonneg _ + rw [hq] + exact mul_le_mul_of_nonneg_left hxq hrq + apply squeeze_zero' (Eventually.of_forall fun q => norm_nonneg _) _ + (by simpa only [add_zero] using ho.add hs) + exact Eventually.of_forall fun q => by + rw [st.split] + have he : st.ordinary q (x q)+st.special q (x q)-st.phase q • st.low.op q (x q)= + (st.ordinary q (x q)-st.phase q • st.low.op q (x q))+st.special q (x q) := by abel + rw [he] + exact norm_add_le _ _ + + + +theorem huge_transverse_bounded (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (ht : t≠0) (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 ⟪modeFock (insertionYInfinity (st.forwardWord t q)),η q⟫_ℂ) l (𝓝 0) := by + have hR : Tendsto (fun q => (r q)⁻¹) l atTop := + tendsto_inv_nhdsGT_zero.comp (tendsto_nhdsWithin_iff.mpr ⟨hr,hp⟩) + let x (q : α) := st.phase q • st.low.op q (vacuum ModeInfinity) + let y (q : α) := st.phase q • st.low.op q (η q) + let v (q : α) : ModeInfinity := (-t) • insertionInfinity (st.word q) + let U (q : α) := ordinaryLocal (st.forwardWord t q) + let P (q : α) := WZ (st.forwardVector t q) (x q) + let Q (q : α) := WZ (st.forwardVector t q) (y q) + have hδ : 0<2*|t| := mul_pos (by norm_num) (abs_pos.mpr ht) + have hsep : ∀ᶠ q in l,2*|t|≤‖v q-(-v q)‖ := Eventually.of_forall fun q => by + exact (unit_opposite_separation _ (norm_insertionInfinity _) t).ge + have hPQ : Tendsto (fun q => ⟪SpinOperators.act Y (P q),Q q⟫_ℂ) l (𝓝 0) := by + simpa only [P,Q,forwardVector_scale,v] using transverse_WZ_bounded + (fun q => (r q)⁻¹) v x y (st.low_bounded _ BoundedPacket.vacuum) + (st.low_bounded _ hη) hR (2*|t|) hδ hsep + have hΩ : Tendsto (fun q => ‖U q (vacuum ModeInfinity)-P q‖) l (𝓝 0) := by + simpa only [U,P,x,forwardWord,ordinaryLocal_cost,forwardVector,complex_neg_real_smul, + ←map_sub,norm_WZ] using st.actual_low_norm hr (hR.eventually (eventually_ge_atTop 1)) _ BoundedPacket.vacuum + have hη' : Tendsto (fun q => ‖U q (η q)-Q q‖) l (𝓝 0) := by + simpa only [U,Q,y,forwardWord,ordinaryLocal_cost,forwardVector,complex_neg_real_smul, + ←map_sub,norm_WZ] using st.actual_low_norm hr (hR.eventually (eventually_ge_atTop 1)) _ hη + obtain ⟨C,hC,hηC⟩ := hη.norm_bounded + have hPn (q : α) : ‖P q‖=1 := by + simp only [P,x,norm_WZ,norm_smul,st.phase_norm,LinearIsometryEquiv.norm_map,norm_vacuum,mul_one] + have herr : Tendsto (fun q => ⟪SpinOperators.act Y (U q (vacuum ModeInfinity)),U q (η q)⟫_ℂ- + ⟪SpinOperators.act Y (P q),Q q⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Eventually.of_forall fun q => norm_nonneg _) _ + (by simpa only [zero_mul,add_zero] using (hΩ.mul_const C).add hη') + filter_upwards [hηC] with q hq + exact (inner_rootY_error_bound _ _ _ _).trans (by + rw [LinearIsometryEquiv.norm_map,hPn,one_mul] + exact add_le_add (mul_le_mul_of_nonneg_left hq (norm_nonneg (U q (vacuum ModeInfinity)-P q))) le_rfl) + have hh := herr.add hPQ + simp only [sub_add_cancel,add_zero] at hh + apply hh.congr' + exact Eventually.of_forall fun q => by + dsimp only + rw [modeFock_insertionY] + simpa only [LinearIsometryEquiv.apply_symm_apply] using + (U q).inner_map_map ((U q).symm (SpinOperators.act Y (U q (vacuum ModeInfinity)))) (η q) + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E α : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] {l : Filter α} + + + +def ApproxPacket (l : Filter α) (x : α → SpinSpace E) : Prop := + ∃y,BoundedPacket l y ∧ Tendsto (fun q => ‖x q-y q‖) l (𝓝 0) + +theorem BoundedPacket.approx {x : α → SpinSpace E} (hx : BoundedPacket l x) : ApproxPacket l x := + ⟨x,hx,by simpa only [sub_self,norm_zero] using (tendsto_const_nhds : Tendsto (fun _ : α => (0:ℝ)) l (𝓝 0))⟩ + +namespace ApproxPacket + +theorem close {x y : α → SpinSpace E} (hy : ApproxPacket l y) + (he : Tendsto (fun q => ‖x q-y q‖) l (𝓝 0)) : ApproxPacket l x := by + obtain ⟨z,hz,hyz⟩ := hy + refine ⟨z,hz,?_⟩ + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [add_zero] using he.add hyz) + exact Eventually.of_forall fun q => by simpa only [dist_eq_norm] using dist_triangle (x q) (y q) (z q) + +theorem add {x y : α → SpinSpace E} (hx : ApproxPacket l x) (hy : ApproxPacket l y) : + ApproxPacket l (fun q => x q+y q) := by + obtain ⟨x',hx',hex⟩ := hx + obtain ⟨y',hy',hey⟩ := hy + refine ⟨fun q => x' q+y' q,hx'.add hy',?_⟩ + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [add_zero] using hex.add hey) + exact Eventually.of_forall fun q => by + have he : x q+y q-(x' q+y' q)=(x q-x' q)+(y q-y' q) := by abel + rw [he] + exact norm_add_le _ _ + +theorem smul {x : α → SpinSpace E} (hx : ApproxPacket l x) (c : ℂ) : + ApproxPacket l (fun q => c • x q) := by + obtain ⟨y,hy,he⟩ := hx + refine ⟨fun q => c • y q,hy.smul (fun _ => c) ‖c‖ (norm_nonneg _) (Eventually.of_forall fun _ => le_rfl),?_⟩ + simpa only [←smul_sub,norm_smul,mul_zero] using he.const_mul ‖c‖ + +theorem neg {x : α → SpinSpace E} (hx : ApproxPacket l x) : ApproxPacket l (fun q => -x q) := by + simpa only [neg_one_smul] using hx.smul (-1) + +theorem sub {x y : α → SpinSpace E} (hx : ApproxPacket l x) (hy : ApproxPacket l y) : + ApproxPacket l (fun q => x q-y q) := by simpa only [sub_eq_add_neg] using hx.add hy.neg + +theorem norm_bounded {x : α → SpinSpace E} (hx : ApproxPacket l x) : + ∃C : ℝ,0≤C ∧ ∀ᶠ q in l,‖x q‖≤C := by + obtain ⟨y,hy,he⟩ := hx + obtain ⟨C,hC,hCy⟩ := hy.norm_bounded + refine ⟨1+C,by linarith,?_⟩ + filter_upwards [hCy,he.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1))] with q hq heq + exact (norm_le_norm_sub_add (x q) (y q)).trans (by linarith) + +end ApproxPacket +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/IdentityErrorFinSumTendsto.lean b/lean/OAI/Probability/ParisiFinite/IdentityErrorFinSumTendsto.lean new file mode 100644 index 0000000000000000000000000000000000000000..fa7c75b6d1fd3baca8655c7878405734c4593ee3 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/IdentityErrorFinSumTendsto.lean @@ -0,0 +1,693 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ActualDisplacement + +namespace OAI + +/-! Identity Error Fin Sum Tendsto. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace ForwardControl +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + + + +theorem identity_error_finSum_tendsto {α ι : Type*} [Fintype ι] {l : Filter α} + (V : α → H ≃ₗᵢ[ℂ] H) (x : α → ι → H) + (hx : ∀j,Tendsto (fun t => ‖V t (x t j)-x t j‖) l (𝓝 0)) : + Tendsto (fun t => ‖V t (∑j,x t j)-(∑j,x t j)‖) l (𝓝 0) := by + have h := PacketGeometry.scaled_norm_sum_tendsto (fun _ : α => (1:ℝ)) + (fun t j => V t (x t j)-x t j) (Eventually.of_forall (fun _ => by norm_num)) + (by intro j; simpa only [one_mul] using hx j) + simpa only [one_mul,Finset.sum_sub_distrib,map_sum] using h + + + +theorem split_forward_tendsto {α : Type*} {l : Filter α} + (V : α → H ≃ₗᵢ[ℂ] H) (o s ρ : α → H) + (ho : Tendsto (fun t => ‖V t (o t)-o t‖) l (𝓝 0)) + (hs : Tendsto (fun t => ‖s t‖) l (𝓝 0)) (hρ : Tendsto (fun t => ‖ρ t‖) l (𝓝 0)) : + Tendsto (fun t => ‖V t (o t+s t+ρ t)-(o t+s t+ρ t)‖) l (𝓝 0) := by + have h := (ho.add (hs.const_mul 2)).add (hρ.const_mul 2) + simp only [mul_zero,add_zero] at h + exact squeeze_zero (fun _ => norm_nonneg _) (fun t => identity_error_split (V t) (o t) (s t) (ρ t)) h + +end ForwardControl + +namespace PointedTree +open CoherentFock RootSpin + + + +theorem actual_direction_from_split {α : Type*} {l : Filter α} + (r : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (o s ρ : α → SpinSpace ModeInfinity) + (hψ : ∀ᶠ t in l,ordinaryLocal (w t) (vacuum ModeInfinity)=o t+s t+ρ t) + (ho : Tendsto (fun t => ‖probeGain (r t) (w t) a k (o t)-o t‖) l (𝓝 0)) + (hoP : Tendsto (fun t => ‖probeGain (r t) (w t) a k (SpinOperators.act (rotatedZ (a k).1) (o t))- + SpinOperators.act (rotatedZ (a k).1) (o t)‖) l (𝓝 0)) + (hs : Tendsto (fun t => ‖s t‖) l (𝓝 0)) (hρ : Tendsto (fun t => ‖ρ t‖) l (𝓝 0)) : + Tendsto (fun t => ‖actualProbeDirection (r t) (w t) a k- + insertionInfinity (.mixer (a k).1::w t)‖) l (𝓝 0) := by + have h := ((ho.add hoP).add (hs.const_mul 4)).add (hρ.const_mul 4) + simp only [mul_zero,add_zero] at h + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ h + filter_upwards [hψ] with t hψt + apply (actual_direction_change_bound (r t) (w t) a k).trans + rw [hψt] + exact ForwardControl.conjugation_error_split (probeGain (r t) (w t) a k) + (SpinOperators.act (rotatedZ (a k).1)) (fun x => (SpinOperators.norm_act (rotatedZ_unitary _) x).le) + (o t) (s t) (ρ t) + +end PointedTree + + + +open scoped Topology BigOperators +open Filter +namespace FiniteError + +def envelope (k : ℕ) (f : ℕ → ℝ) : ℝ := ∑j∈Finset.range k,|f j| + +theorem envelope_nonneg (k : ℕ) (f : ℕ → ℝ) : 0≤envelope k f := + Finset.sum_nonneg (fun _ _ => abs_nonneg _) + +theorem le_envelope (k : ℕ) (f : ℕ → ℝ) (j : ℕ) (hj : j |f i|) (fun _ _ => abs_nonneg _) (Finset.mem_range.mpr hj) + +theorem envelope_tendsto_zero {α : Type*} {l : Filter α} (k : ℕ) (f : α → ℕ → ℝ) + (hf : ∀j f t j) l (𝓝 0)) : + Tendsto (fun t => envelope k (f t)) l (𝓝 0) := by + have h := tendsto_finsetSum (Finset.range k) (fun j hj => (hf j (Finset.mem_range.mp hj)).abs) + simpa only [envelope,abs_zero,Finset.sum_const_zero] using h + +theorem scaled_envelope_tendsto_zero {α : Type*} {l : Filter α} + (k : ℕ) (S : α → ℝ) (f : α → ℕ → ℝ) + (hf : ∀j S t*|f t j|) l (𝓝 0)) : + Tendsto (fun t => S t*envelope k (f t)) l (𝓝 0) := by + have h := tendsto_finsetSum (Finset.range k) (fun j hj => hf j (Finset.mem_range.mp hj)) + simpa only [envelope,Finset.mul_sum,Finset.sum_const_zero] using h + +end FiniteError + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + + + +theorem tail_bounds_of_radius_mass (x : PreSpin E) (B A : ℝ) (hB : 0≤B) + (hx : SpinRadiusLE x B ∧ spinMass x≤A) : + spinBound x≤A*(1+2*B+12*B^2) ∧ ‖spinCoe x‖≤A := by + exact ⟨(spinBound_le_mass x hB hx.1).trans + (mul_le_mul_of_nonneg_right hx.2 (by positivity)),(norm_spinCoe_le_mass x).trans hx.2⟩ + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin +local instance forwardRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance forwardRealSMul : SMul ℝ ModeInfinity := forwardRealModule.toDistribMulAction.toSMul + + + +theorem packet_forward_of_phases {α : Type*} {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (d : α → ModeInfinity) (x : α → PreSpin ModeInfinity) (B A T : ℝ) + (hB : 0≤B) (hA : 0≤A) (hT : 0≤T) (ha : ∀j -2*(⟪actualDisplacement (r t) (w t) a j,S t • d t⟫_ℂ).im) l (𝓝 0)) : + Tendsto (fun t => ‖probeGain (r t) (w t) a k (actualPacket (S t) (d t) (x t))- + actualPacket (S t) (d t) (x t)‖) l (𝓝 0) := by + let phase (t : α) := FiniteError.envelope k (fun j => -2*(⟪actualDisplacement (r t) (w t) a j,S t • d t⟫_ℂ).im) + apply actual_forward_tendsto r w a k (fun t => S t • d t) x phase T + (A*(1+2*B+12*B^2)) A hT (by positivity) hA ha hr + (FiniteError.envelope_tendsto_zero k _ hp) + (Eventually.of_forall (fun _ => FiniteError.envelope_nonneg ..)) + (Eventually.of_forall (fun t j hj => FiniteError.le_envelope k + (fun q => -2*(⟪actualDisplacement (r t) (w t) a q,S t • d t⟫_ℂ).im) j hj)) + filter_upwards [hx] with t ht + exact tail_bounds_of_radius_mass (x t) B A hB ht + + + +theorem packet_root_forward_of_phases {α : Type*} {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (d : α → ModeInfinity) (x : α → PreSpin ModeInfinity) (P : Matrix (Fin 2) (Fin 2) ℂ) + (B A T : ℝ) (hB : 0≤B) (hA : 0≤A) (hT : 0≤T) (ha : ∀j -2*(⟪actualDisplacement (r t) (w t) a j,S t • d t⟫_ℂ).im) l (𝓝 0)) : + Tendsto (fun t => ‖probeGain (r t) (w t) a k (SpinOperators.act P (actualPacket (S t) (d t) (x t)))- + SpinOperators.act P (actualPacket (S t) (d t) (x t))‖) l (𝓝 0) := by + simp only [actualPacket_root] + apply packet_forward_of_phases r S w a k d (fun t => preRoot P (x t)) B + (matrixMass P*A) T hB (mul_nonneg (matrixMass_nonneg _) hA) hT ha hr _ hp + filter_upwards [hx] with t ht + exact ⟨ht.1.preRoot P,(spinMass_preRoot P _).trans + (mul_le_mul_of_nonneg_left ht.2 (matrixMass_nonneg _))⟩ + + + +theorem packet_direction_tendsto {α ι : Type*} [Fintype ι] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (d : ι → α → ModeInfinity) (x : ι → α → PreSpin ModeInfinity) + (s ρ : α → SpinSpace ModeInfinity) (B A T : ℝ) + (hB : 0≤B) (hA : 0≤A) (hT : 0≤T) (ha : ∀j -2*(⟪actualDisplacement (r t) (w t) a j,S t • d i t⟫_ℂ).im) l (𝓝 0)) + (hψ : ∀ᶠ t in l,ordinaryLocal (w t) (vacuum ModeInfinity)= + (∑i,actualPacket (S t) (d i t) (x i t))+s t+ρ t) + (hs : Tendsto (fun t => ‖s t‖) l (𝓝 0)) (hρ : Tendsto (fun t => ‖ρ t‖) l (𝓝 0)) : + Tendsto (fun t => ‖actualProbeDirection (r t) (w t) a k- + insertionInfinity (.mixer (a k).1::w t)‖) l (𝓝 0) := by + apply actual_direction_from_split r w a k _ s ρ hψ _ _ hs hρ + · apply ForwardControl.identity_error_finSum_tendsto + intro i + exact packet_forward_of_phases r S w a k (d i) (x i) B A T hB hA hT ha hr (hx i) (hp i) + · have ht := ForwardControl.identity_error_finSum_tendsto + (fun t => probeGain (r t) (w t) a k) + (fun t i => SpinOperators.act (rotatedZ (a k).1) (actualPacket (S t) (d i t) (x i t))) + (fun i => packet_root_forward_of_phases r S w a k (d i) (x i) (rotatedZ (a k).1) + B A T hB hA hT ha hr (hx i) (hp i)) + simpa only [map_sum] using ht + +end PointedTree + + + +open scoped BigOperators +namespace List +open scoped _root_.List + + + +theorem range_map_getD_eq {α : Type*} (w : List α) (d : α) : + (List.range w.length).map (fun j => w.getD j d)=w := by + apply List.ext_getElem + · simp + · intro j hj hk + simp only [List.getElem_map,List.getElem_range] + exact (List.getElem_eq_getD d).symm + +theorem reverse_range_map_getD_eq {α β : Type*} (w : List α) (d : α) (f : α → β) : + (List.range w.length).reverse.map (fun j => f (w.getD j d))=w.reverse.map f := by + have h := congrArg (fun q : List α => q.reverse.map f) (range_map_getD_eq w d) + simpa only [List.map_reverse,List.map_map,Function.comp_def] using h + +end List + +namespace PointedTree +open CoherentFock RootSpin +local instance listclockRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance listclockRealSMul : SMul ℝ ModeInfinity := listclockRealModule.toDistribMulAction.toSMul + + + +def pulseSequence (β : Bool → ℝ) (s : List (Bool×ℝ)) (j : ℕ) : ShortPulse := + (β (s.getD j (false,0)).1,(s.getD j (false,0)).2) + +theorem pulseSequence_clocks (β : Bool → ℝ) (s : List (Bool×ℝ)) + (hs : ∀b,((s.filter (fun p => decide (p.1=b))).map Prod.snd).sum=0) + (w : List Gate) (x : PreSpin ModeInfinity) : + ((List.range s.length).reverse.map (fun j => Complex.I • + probeField (R (pulseSequence β s j).1) (startingVelocity w (pulseSequence β s) j) x)).sum=0 := by + have he : (fun j => Complex.I • probeField (R (pulseSequence β s j).1) + (startingVelocity w (pulseSequence β s) j) x)= + (fun j => (fun p : Bool×ℝ => Complex.I • probeField (R (β p.1)) + (-p.2 • insertionInfinity (.mixer (β p.1)::w)) x) (s.getD j (false,0))) := by rfl + rw [he] + have hh := List.reverse_range_map_getD_eq s (false,0) + (fun p : Bool×ℝ => Complex.I • probeField (R (β p.1)) + (-p.2 • insertionInfinity (.mixer (β p.1)::w)) x) + rw [hh,List.map_reverse,List.sum_reverse] + exact probeField_zero_two_clocks s hs (fun b => R (β b)) + (fun b => insertionInfinity (.mixer (β b)::w)) x + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance cancelRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance cancelRealSMul : SMul ℝ ModeInfinity := cancelRealModule.toDistribMulAction.toSMul + + + +theorem phase_tendsto_of_scaled {α : Type*} {l : Filter α} (S f : α → ℝ) + (hS : ∀ᶠ t in l,1≤S t) (hf : Tendsto (fun t => S t*|f t|) l (𝓝 0)) : + Tendsto f l (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + simpa only [Real.norm_eq_abs] using PacketGeometry.tendsto_of_scaled S (fun t => |f t|) + hS (Eventually.of_forall (fun _ => abs_nonneg _)) hf + + + +theorem packet_direction_envelope_tendsto {α ι : Type*} [Fintype ι] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (K : ℕ) + (d : ι → α → ModeInfinity) (x : ι → α → PreSpin ModeInfinity) + (s ρ : α → SpinSpace ModeInfinity) (B A T : ℝ) + (hB : 0≤B) (hA : 0≤A) (hT : 0≤T) (ha : ∀j S t*|-2*(⟪actualDisplacement (r t) (w t) a j,S t • d i t⟫_ℂ).im|) l (𝓝 0)) + (hψ : ∀ᶠ t in l,ordinaryLocal (w t) (vacuum ModeInfinity)= + (∑i,actualPacket (S t) (d i t) (x i t))+s t+ρ t) + (hs : Tendsto (fun t => ‖s t‖) l (𝓝 0)) (hρ : Tendsto (fun t => ‖ρ t‖) l (𝓝 0)) : + Tendsto (fun t => FiniteError.envelope K (fun j => ‖actualProbeDirection (r t) (w t) a j- + insertionInfinity (.mixer (a j).1::w t)‖)) l (𝓝 0) := by + apply FiniteError.envelope_tendsto_zero + intro j hj + apply packet_direction_tendsto r S w a j d x s ρ B A T hB hA hT + (fun k hk => ha k (hk.trans hj)) hr hx _ hψ hs hρ + intro i k hk + exact phase_tendsto_of_scaled S _ hS (hp i k (hk.trans hj)) + + + +theorem packet_zero_clock_from_vacuum {α ι : Type*} [Fintype ι] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (K : ℕ) + (d : ι → α → ModeInfinity) (x : ι → α → PreSpin ModeInfinity) + (s ρ : α → SpinSpace ModeInfinity) (B A T : ℝ) + (hB : 0≤B) (hA : 0≤A) (hT : 0≤T) (ha : ∀j S t*|-2*(⟪actualDisplacement (r t) (w t) a j,S t • d i t⟫_ℂ).im|) l (𝓝 0)) + (hψ : ∀ᶠ t in l,ordinaryLocal (w t) (vacuum ModeInfinity)= + (∑i,actualPacket (S t) (d i t) (x i t))+s t+ρ t) + (hs : Tendsto (fun t => ‖s t‖) l (𝓝 0)) (hρ : Tendsto (fun t => ‖ρ t‖) l (𝓝 0)) + (e : α → ModeInfinity) (z : α → PreSpin ModeInfinity) (B' A' : ℝ) + (hB' : 0≤B') (hA' : 0≤A') + (hz : ∀ᶠ t in l,SpinRadiusLE (z t) B' ∧ spinMass (z t)≤A') + (he : ∀j S t*|-2*(⟪actualDisplacement (r t) (w t) a j,S t • e t⟫_ℂ).im|) l (𝓝 0)) + (hclock : ∀ᶠ t in l,((List.range K).reverse.map (fun j => Complex.I • + probeField (R (a j).1) (startingVelocity (w t) a j) (z t))).sum=0) : + Tendsto (fun t => S t*‖probeGain (r t) (w t) a K (actualPacket (S t) (e t) (z t))- + actualPacket (S t) (e t) (z t)‖) l (𝓝 0) := by + let Δ (t : α) := FiniteError.envelope K (fun j => ‖actualProbeDirection (r t) (w t) a j- + insertionInfinity (.mixer (a j).1::w t)‖) + let phase (t : α) := FiniteError.envelope K + (fun j => -2*(⟪actualDisplacement (r t) (w t) a j,S t • e t⟫_ℂ).im) + have hΔ : Tendsto Δ l (𝓝 0) := packet_direction_envelope_tendsto r S w a K d x s ρ + B A T hB hA hT ha hr hS hx hp hψ hs hρ + have hd : ∀ᶠ t in l,∀j by + simpa only [abs_norm] using FiniteError.le_envelope K + (fun j => ‖actualProbeDirection (r t) (w t) a j-insertionInfinity (.mixer (a j).1::w t)‖) j hj) + have hp' : ∀ᶠ t in l,∀j FiniteError.le_envelope K + (fun j => -2*(⟪actualDisplacement (r t) (w t) a j,S t • e t⟫_ℂ).im) j hj) + have hx' : ∀ᶠ t in l,spinBound (z t)≤A'*(1+2*B'+12*B'^2) ∧ ‖spinCoe (z t)‖≤A' := by + filter_upwards [hz] with t ht + exact tail_bounds_of_radius_mass (z t) B' A' hB' ht + exact actual_zero_clock_tendsto r S w a K (fun t => S t • e t) z Δ phase T + (A'*(1+2*B'+12*B'^2)) A' hT (by positivity) hA' ha hr hΔ + (FiniteError.scaled_envelope_tendsto_zero K S _ he) hscale + (Eventually.of_forall (fun _ => ⟨FiniteError.envelope_nonneg ..,FiniteError.envelope_nonneg ..⟩)) + hd hp' hx' hclock + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace ForwardControl +variable {H α : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] {l : Filter α} + + + +theorem scaled_flip_from_limits (U V : α → H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H) + (hZ : ∀x,‖Z x‖≤‖x‖) (hanti : ∀x,Z (F x)= -F (Z x)) + (Ω : H) (o s w : α → H) (hx : ∀q,U q Ω=o q+s q) + (r : α → ℝ) (t : ℝ) (hr : ∀ᶠ q in l,0 (r q)⁻¹*‖V q (o q)-o q‖) l (𝓝 0)) + (h2 : Tendsto (fun q => (r q)⁻¹*‖V q (s q)-F (s q)‖) l (𝓝 0)) + (h3 : Tendsto (fun q => (r q)⁻¹*‖V q (Z (o q))-Z (o q)‖) l (𝓝 0)) + (h4 : Tendsto (fun q => (r q)⁻¹*‖V q (Z (s q))-F (Z (s q))‖) l (𝓝 0)) + (ht : Tendsto (fun q => ‖(r q)⁻¹ • (U q).symm (Z (s q))-w q‖) l (𝓝 0)) : + Tendsto (fun q => ‖(t/r q) • ((U q).symm ((V q).symm (Z (V q (U q Ω))))- + (U q).symm (Z (U q Ω)))-(-2*t) • w q‖) l (𝓝 0) := by + let e (q : α) := ‖V q (o q)-o q‖+‖V q (s q)-F (s q)‖+ + ‖V q (Z (o q))-Z (o q)‖+‖V q (Z (s q))-F (Z (s q))‖ + let ε (q : α) := (r q)⁻¹*e q + have he : Tendsto ε l (𝓝 0) := by + simpa only [ε,e,mul_add,add_zero] using ((h1.add h2).add h3).add h4 + have hmul : ∀ᶠ q in l,r q*ε q=e q := by + filter_upwards [hr] with q hq + simp only [ε,←mul_assoc,mul_inv_cancel₀ hq.ne',one_mul] + apply actual_scaled_flip_tendsto U V Z F hZ hanti Ω o s w hx r ε + (fun q => ‖(r q)⁻¹ • (U q).symm (Z (s q))-w q‖) t hr he ht + · filter_upwards [hmul] with q hq + rw [hq] + dsimp only [e] + linarith [norm_nonneg (V q (s q)-F (s q)),norm_nonneg (V q (Z (o q))-Z (o q)), + norm_nonneg (V q (Z (s q))-F (Z (s q)))] + · filter_upwards [hmul] with q hq + rw [hq] + dsimp only [e] + linarith [norm_nonneg (V q (o q)-o q),norm_nonneg (V q (Z (o q))-Z (o q)), + norm_nonneg (V q (Z (s q))-F (Z (s q)))] + · filter_upwards [hmul] with q hq + rw [hq] + dsimp only [e] + linarith [norm_nonneg (V q (o q)-o q),norm_nonneg (V q (s q)-F (s q)), + norm_nonneg (V q (Z (s q))-F (Z (s q)))] + · filter_upwards [hmul] with q hq + rw [hq] + dsimp only [e] + linarith [norm_nonneg (V q (o q)-o q),norm_nonneg (V q (s q)-F (s q)), + norm_nonneg (V q (Z (o q))-Z (o q))] + · exact Eventually.of_forall (fun _ => le_rfl) + +end ForwardControl + +namespace PointedTree +open CoherentFock RootSpin +local instance echoRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance echoRealSMul : SMul ℝ ModeInfinity := echoRealModule.toDistribMulAction.toSMul + + +theorem modeFock_probe_insertion (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (K : ℕ) : + modeFock (insertionInfinity (probePrefix r w a K))= + (ordinaryLocal w).symm ((probeGain r w a K).symm + (SpinOperators.act Z (probeGain r w a K (ordinaryLocal w (vacuum ModeInfinity))))) := by + rw [modeFock_insertion] + change _=(ordinaryLocal w).symm (ordinaryLocal w + ((ordinaryLocal (probePrefix r w a K)).symm (SpinOperators.act Z + (ordinaryLocal (probePrefix r w a K) ((ordinaryLocal w).symm (ordinaryLocal w (vacuum ModeInfinity))))))) + simp only [LinearIsometryEquiv.symm_apply_apply] + + + +theorem actual_flip_mode_tendsto {α : Type*} {l : Filter α} + (r : α → ℝ) (w : α → List Gate) (a : ℕ → ShortPulse) (K : ℕ) + (o s : α → SpinSpace ModeInfinity) (address : α → ModeInfinity) + (F : SpinSpace ModeInfinity →L[ℂ] SpinSpace ModeInfinity) + (hanti : ∀x,SpinOperators.act Z (F x)= -F (SpinOperators.act Z x)) + (hx : ∀q,ordinaryLocal (w q) (vacuum ModeInfinity)=o q+s q) + (t : ℝ) (hr : ∀ᶠ q in l,0 (r q)⁻¹*‖probeGain (r q) (w q) a K (o q)-o q‖) l (𝓝 0)) + (h2 : Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (w q) a K (s q)-F (s q)‖) l (𝓝 0)) + (h3 : Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (w q) a K (SpinOperators.act Z (o q))- + SpinOperators.act Z (o q)‖) l (𝓝 0)) + (h4 : Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (w q) a K (SpinOperators.act Z (s q))- + F (SpinOperators.act Z (s q))‖) l (𝓝 0)) + (ht : Tendsto (fun q => ‖(r q)⁻¹ • (ordinaryLocal (w q)).symm (SpinOperators.act Z (s q))- + modeFock (address q)‖) l (𝓝 0)) : + Tendsto (fun q => ‖(t/r q) • (insertionInfinity (probePrefix (r q) (w q) a K)-insertionInfinity (w q))- + (-2*t) • address q‖) l (𝓝 0) := by + have h := ForwardControl.scaled_flip_from_limits (fun q => ordinaryLocal (w q)) + (fun q => probeGain (r q) (w q) a K) (SpinOperators.act Z) F + (fun x => (SpinOperators.norm_act Z_unitary x).le) hanti (vacuum ModeInfinity) o s + (fun q => modeFock (address q)) hx r t hr h1 h2 h3 h4 ht + apply h.congr' + exact Eventually.of_forall (fun q => by + dsimp only + rw [←modeFock.norm_map ((t/r q) • (insertionInfinity (probePrefix (r q) (w q) a K)-insertionInfinity (w q))-(-2*t) • address q)] + simp only [map_sub, RCLike.real_smul_eq_coe_smul (K:=ℂ), map_smul] + rw [modeFock_probe_insertion,modeFock_insertion]) + +end PointedTree + + + +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +namespace RootSpin + + + +theorem exists_mixer_frame (a b : ℝ) (hab : a^2+b^2=1) : + ∃ β : ℝ,Real.cos (2*β)=a ∧ Real.sin (2*β)=b ∧ + Real.cos (2*(β+Real.pi/4))= -b ∧ Real.sin (2*(β+Real.pi/4))=a := by + let z : ℂ := ⟨a,b⟩ + have hn : ‖z‖=1 := by + have h2 : ‖z‖^2=1 := by + rw [Complex.sq_norm] + simpa only [Complex.normSq_apply,z,pow_two] using hab + nlinarith [norm_nonneg z] + refine ⟨z.arg/2,?_,?_,?_,?_⟩ + · simpa only [mul_div_cancel₀ _ (by norm_num : (2:ℝ)≠0),hn,one_mul] using Complex.norm_mul_cos_arg z + · simpa only [mul_div_cancel₀ _ (by norm_num : (2:ℝ)≠0),hn,one_mul] using Complex.norm_mul_sin_arg z + · rw [show 2*(z.arg/2+Real.pi/4)=z.arg+Real.pi/2 by ring,Real.cos_add_pi_div_two] + congr 1 + simpa only [hn,one_mul] using Complex.norm_mul_sin_arg z + · rw [show 2*(z.arg/2+Real.pi/4)=z.arg+Real.pi/2 by ring,Real.sin_add_pi_div_two] + simpa only [hn,one_mul] using Complex.norm_mul_cos_arg z + +end RootSpin + +namespace CoherentFock +open RootSpin +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + +theorem phaseZ_eq_act_exp (θ : ℝ) : + phaseZ (E:=E) θ=SpinOperators.act (NormedSpace.exp ((Complex.I*(θ:ℂ)) • Z)) := by + have hz : (Complex.I*(θ:ℂ)) • Z=Matrix.diagonal + (fun i : Fin 2 => (((if i=0 then θ else -θ : ℝ):ℂ)*Complex.I)) := by + ext i j + fin_cases i <;> fin_cases j <;> simp [Z] <;> ring + rw [hz,Matrix.exp_diagonal,Pi.exp_def] + simp only [←Complex.exp_eq_exp_ℂ,phaseZ] + +end CoherentFock + +namespace RootSpin + + + +theorem exp_rotated_Z (β θ : ℝ) : + NormedSpace.exp ((Complex.I*(θ:ℂ)) • ((R β).conjTranspose*Z*R β))= + (R β).conjTranspose*NormedSpace.exp ((Complex.I*(θ:ℂ)) • Z)*R β := by + let U : (Matrix (Fin 2) (Fin 2) ℂ)ˣ := + ⟨(R β).conjTranspose,R β,(Unitary.mem_iff.mp (R_unitary β)).1, + (Unitary.mem_iff.mp (R_unitary β)).2⟩ + have he := Matrix.exp_units_conj U ((Complex.I*(θ:ℂ)) • Z) + change NormedSpace.exp ((R β).conjTranspose*((Complex.I*(θ:ℂ)) • Z)*R β)= + (R β).conjTranspose*NormedSpace.exp ((Complex.I*(θ:ℂ)) • Z)*R β at he + rwa [Matrix.mul_smul,Matrix.smul_mul] at he + +end RootSpin + +namespace SpinOperators +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] +theorem act_conj_comp (A B C : Matrix (Fin 2) (Fin 2) ℂ) : + (act A : Double H →L[ℂ] Double H).comp ((act B).comp (act C))=act (A*B*C) := by + rw [act_mul,act_mul,ContinuousLinearMap.comp_assoc] +end SpinOperators + +namespace CoherentFock +open RootSpin +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + +theorem probePhase_eq_act_exp (β θ : ℝ) : + probePhase (E:=E) (R β) θ=SpinOperators.act + (NormedSpace.exp ((Complex.I*(θ:ℂ)) • ((R β).conjTranspose*Z*R β))) := by + calc + _ = (SpinOperators.act (R β).conjTranspose).comp + ((SpinOperators.act (NormedSpace.exp ((Complex.I*(θ:ℂ)) • Z))).comp (SpinOperators.act (R β))) := + congrArg (fun T : SpinSpace E →L[ℂ] SpinSpace E => + (SpinOperators.act (R β).conjTranspose).comp (T.comp (SpinOperators.act (R β)))) + (phaseZ_eq_act_exp θ) + _ = SpinOperators.act ((R β).conjTranspose*NormedSpace.exp ((Complex.I*(θ:ℂ)) • Z)*R β) := + SpinOperators.act_conj_comp _ _ _ + _ = _ := congrArg SpinOperators.act (exp_rotated_Z β θ).symm + +end CoherentFock + +namespace QuaternionControl +open SeedControl RootSpin + +@[simp] theorem skewX_eq : SeedControl.x=(-Complex.I) • X := by + ext i j; fin_cases i <;> fin_cases j <;> simp [SeedControl.x,X] +@[simp] theorem skewY_eq : SeedControl.y=(-Complex.I) • Y := by + ext i j; fin_cases i <;> fin_cases j <;> simp [SeedControl.y,Y] +@[simp] theorem skewZ_eq : SeedControl.z=(-Complex.I) • Z := by + ext i j; fin_cases i <;> fin_cases j <;> simp [SeedControl.z,Z] + +def axisAngle (β : ℝ) (b : Bool) : ℝ := if b then β else β+Real.pi/4 + +def axisProjection (a b : ℝ) (v : ℝ×ℝ) (e : Bool) : ℝ := + if e then a*v.1+b*v.2 else -b*v.1+a*v.2 + + + +theorem spinGen_eq_rotated {ι : Type*} (a b β : ℝ) + (hc : Real.cos (2*β)=a) (hs : Real.sin (2*β)=b) + (hc' : Real.cos (2*(β+Real.pi/4))= -b) (hs' : Real.sin (2*(β+Real.pi/4))=a) + (v : ι → ℝ×ℝ) (e : Bool) (i : ι) : + spinGen a b (fun j => a*(v j).1+b*(v j).2) + (fun j => -b*(v j).1+a*(v j).2) e i= + axisProjection a b (v i) e • ((-Complex.I) • + ((R (axisAngle β e)).conjTranspose*Z*R (axisAngle β e))) := by + cases e <;> simp only [spinGen,Bool.false_eq_true,ite_false,ite_true,axisProjection,axisAngle, + R_conjugate_Z,hc,hs,hc',hs',skewZ_eq,skewY_eq] + all_goals + ext j k + simp only [Matrix.add_apply,Matrix.smul_apply,smul_eq_mul,Complex.real_smul,Complex.ofReal_neg] + ring + +end QuaternionControl + + + +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +namespace SpinOperators +variable {H ι : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +theorem act_prod (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (s : List ι) : + (act ((s.map A).prod) : Double H →L[ℂ] Double H)=ProbeProduct.act (fun i => act (A i)) s := by + induction s with + | nil => exact act_one + | cons i s ih => + simp only [List.map_cons,List.prod_cons,act_mul,ih,ProbeProduct.act] + +end SpinOperators + +namespace QuaternionControl +open RootSpin + +theorem real_smul_skew (τ c : ℝ) (P : Matrix (Fin 2) (Fin 2) ℂ) : + τ • (c • ((-Complex.I) • P))=(Complex.I*((-τ*c:ℝ):ℂ)) • P := by + ext i j + simp only [Matrix.smul_apply,Complex.real_smul,smul_eq_mul,Complex.ofReal_mul,Complex.ofReal_neg] + ring + +theorem exp_skewX (θ : ℝ) : NormedSpace.exp (θ • SeedControl.x)=R θ := by + rw [skewX_eq,R_eq_exp] + congr 1 + ext i j + simp only [Matrix.smul_apply,smul_eq_mul,Complex.real_smul] + ring + + + +theorem phase_product_eq {ι : Type*} (v : ι → ℝ×ℝ) (a b β θ : ℝ) + (hc : Real.cos (2*β)=a) (hs : Real.sin (2*β)=b) + (hc' : Real.cos (2*(β+Real.pi/4))= -b) (hs' : Real.sin (2*(β+Real.pi/4))=a) + (s : List (Bool×ℝ)) + (hprod : ∀i,(s.reverse.map (fun p => NormedSpace.exp (p.2 • + spinGen a b (fun j => a*(v j).1+b*(v j).2) + (fun j => -b*(v j).1+a*(v j).2) p.1 i))).prod=NormedSpace.exp (θ • SeedControl.x)) + (i : ι) : + (s.reverse.map (fun p => NormedSpace.exp + ((Complex.I*((-p.2*axisProjection a b (v i) p.1:ℝ):ℂ)) • + ((R (axisAngle β p.1)).conjTranspose*Z*R (axisAngle β p.1))))).prod=R θ := by + have h := hprod i + simp only [spinGen_eq_rotated a b β hc hs hc' hs',real_smul_skew,exp_skewX] at h + exact h + +end QuaternionControl + +namespace PointedTree +open CoherentFock RootSpin QuaternionControl + + + +def projectionPhase (v : ℝ×ℝ) (p : ShortPulse) : ℝ := + -p.2*(Real.cos (2*p.1)*v.1+Real.sin (2*p.1)*v.2) + +theorem rotated_coordinate (a b β : ℝ) + (hc : Real.cos (2*β)=a) (hs : Real.sin (2*β)=b) + (hc' : Real.cos (2*(β+Real.pi/4))= -b) (hs' : Real.sin (2*(β+Real.pi/4))=a) + (v : ℝ×ℝ) (e : Bool) : + Real.cos (2*axisAngle β e)*v.1+Real.sin (2*axisAngle β e)*v.2=axisProjection a b v e := by + cases e <;> simp only [axisAngle,axisProjection,Bool.false_eq_true,ite_false,ite_true,hc,hs,hc',hs'] + + + +theorem selective_phase_control {ι : Type*} [Fintype ι] + (v : ι → ℝ×ℝ) (hv : ∀i,v i≠0) (θ : ℝ) : + ∃ (K : ℕ) (a : ℕ → ShortPulse) (T : ℝ),0≤T ∧ + (∀j Complex.I • + probeField (R (a j).1) (startingVelocity w a j) x)).sum=0) ∧ + ∀i,ProbeProduct.act (fun j => probePhase (E:=ModeInfinity) (R (a j).1) + (projectionPhase (v i) (a j))) (List.range K).reverse=SpinOperators.act (R θ) := by + obtain ⟨c,d,hcd,hs⟩ := selective_rotations_zero_clocks v hv + obtain ⟨β,hc,hd,hc',hd'⟩ := exists_mixer_frame c d hcd + obtain ⟨s,hs0,hsp⟩ := hs θ + let a := pulseSequence (axisAngle β) s + let T := FiniteError.envelope s.length (fun j => (a j).2) + refine ⟨s.length,a,T,FiniteError.envelope_nonneg ..,?_,?_,?_⟩ + · intro j hj; exact FiniteError.le_envelope s.length (fun j => (a j).2) j hj + · intro w x; exact pulseSequence_clocks (axisAngle β) s hs0 w x + · intro i + let F (p : Bool×ℝ) : Matrix (Fin 2) (Fin 2) ℂ := NormedSpace.exp + ((Complex.I*((-p.2*axisProjection c d (v i) p.1:ℝ):ℂ)) • + ((R (axisAngle β p.1)).conjTranspose*Z*R (axisAngle β p.1))) + have hprod : (s.reverse.map F).prod=R θ := phase_product_eq v c d β θ hc hd hc' hd' s hsp i + have hmat : ((List.range s.length).reverse.map (fun j => F (s.getD j (false,0)))).prod=R θ := by + rw [List.reverse_range_map_getD_eq]; exact hprod + have hf : (fun j => probePhase (E:=ModeInfinity) (R (a j).1) (projectionPhase (v i) (a j)))= + (fun j => SpinOperators.act (F (s.getD j (false,0)))) := by + funext j + dsimp only [a,pulseSequence,projectionPhase] + rw [rotated_coordinate c d β hc hd hc' hd',probePhase_eq_act_exp] + rw [hf,←SpinOperators.act_prod,hmat] + +end PointedTree + + + +open scoped InnerProductSpace Topology +open Filter +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + +theorem short_large_phase (r S τ : ℝ) (v d : E) : + -2*(⟪-((r*τ:ℝ):ℂ) • v,S • d⟫_ℂ).im=2*r*S*τ*(⟪v,d⟫_ℂ).im := by + rw [inner_smul_left] + rw [RCLike.real_smul_eq_coe_smul (K:=ℂ) S d,inner_smul_real_right] + simp only [map_neg,Complex.conj_ofReal,Complex.real_smul,Complex.mul_im,Complex.neg_re, + Complex.neg_im,Complex.ofReal_re,Complex.ofReal_im,zero_mul,add_zero] + ring + + + +theorem imaginary_projection_difference (v v' d : E) : + |(⟪v,d⟫_ℂ).im-(⟪v',d⟫_ℂ).im|≤‖v-v'‖*‖d‖ := by + calc + _ = |(⟪v-v',d⟫_ℂ).im| := by rw [inner_sub_left,Complex.sub_im] + _ ≤ ‖⟪v-v',d⟫_ℂ‖ := Complex.abs_im_le_norm _ + _ ≤ _ := norm_inner_le_norm _ _ + +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/IncrementEqKernel.lean b/lean/OAI/Probability/ParisiFinite/IncrementEqKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..85d1be35e58740731337c2f7c3e093dec107ec69 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/IncrementEqKernel.lean @@ -0,0 +1,735 @@ +import Mathlib +import OAI.Probability.ParisiFinite.VarianceProdDecomposition + +namespace OAI + +/-! Increment Eq Kernel. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma increment_eq_kernel {ι κ : Type*} [Fintype κ] (A : ι → κ → ℝ) (s t : ι) : + ParisiInterpolation.increment A s t = kernel A s s+kernel A t t-2*kernel A s t := by + simp only [ParisiInterpolation.increment, kernel, Finset.mul_sum] + rw [← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + +lemma increment_perturbed_sub {n : ℕ} (hn : 0 β*skCoeff n s e) σ τ = + 2*a^2*(1-(overlap σ τ)^p) := by + have hk (s t : Configuration n) : kernel (perturbedCoeff n p β a) s t = + kernel (fun s e => β*skCoeff n s e) s t+a^2*(overlap s t)^p := by + rw [perturbedCoeff_kernel hn, kernel_scale, kernel, coeff_covariance hn] + ring + rw [increment_eq_kernel, increment_eq_kernel, hk, hk, hk, + overlap_self hn, overlap_self hn, one_pow] + ring + +lemma abs_increment_perturbed_sub_le {n : ℕ} (hn : 0 β*skCoeff n s e) σ τ| ≤ 4*a^2 := by + rw [increment_perturbed_sub hn, abs_mul, abs_of_nonneg (by positivity : (0:ℝ)≤2*a^2)] + have h : |(overlap σ τ)^p| ≤ 1 := by + rw [abs_pow] + exact pow_le_one₀ (abs_nonneg _) (abs_overlap_le_one _ _) + have hd : |1-(overlap σ τ)^p| ≤ 2 := by + have := abs_sub_le (1:ℝ) 0 ((overlap σ τ)^p) + simp only [sub_zero, zero_sub, abs_neg, abs_one] at this + linarith + nlinarith [mul_le_mul_of_nonneg_left hd (by positivity : (0:ℝ) ≤ 2*a^2)] + + + +theorem perturbed_pressure_error {n : ℕ} (hn : 0 β*skCoeff n s e)| ≤ + Real.pi*a^2 := by + have h := expected_difference_le (fun s e => β*skCoeff n s e) (perturbedCoeff n p β a) + (show (0:ℝ)≤4*a^2 by positivity) (abs_increment_perturbed_sub_le hn p β a) + convert h using 1 + ring + + + +theorem tendsto_perturbed_pressureDensity_error (p : ℕ → ℕ) (β : ℝ) (a : ℕ → ℝ) + (ha : Tendsto (fun n => (a n)^2/(n:ℝ)) atTop (𝓝 0)) : + Tendsto (fun n => (expected (perturbedCoeff n (p n) β (a n))- + expected (fun s e => β*skCoeff n s e))/(n:ℝ)) atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + simp only [Real.norm_eq_abs] + have hlim : Tendsto (fun n : ℕ => Real.pi*((a n)^2/(n:ℝ))) atTop (𝓝 0) := by + simpa using ha.const_mul Real.pi + refine squeeze_zero' (Eventually.of_forall (fun n => abs_nonneg _)) ?_ hlim + filter_upwards [eventually_gt_atTop 0] with n hn + rw [abs_div, abs_of_nonneg (show (0:ℝ) ≤ (n:ℝ) from Nat.cast_nonneg n)] + have h := div_le_div_of_nonneg_right (perturbed_pressure_error hn (p n) β (a n)) + (Nat.cast_nonneg n) + simpa only [mul_div_assoc] using h + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +def perturbationNoise (n p : ℕ) (σ : Configuration n) : + Edge n ⊕ (Fin p → Fin n) → ℝ := Sum.elim (fun _ => 0) (pSpinCoeff n p σ) + +lemma perturbationNoise_crossCov {n : ℕ} (hn : 0 f σ*∑ l, (overlap (σ i) (σ l))^p) + ∂gaussianLaw (Edge n ⊕ (Fin p → Fin n))) - + (r:ℝ)*a*(∫ z, replicaMean (field (perturbedCoeff n p β a) z) + (fun τ : Fin (r+1) → Configuration n => + f (fun l => τ l.castSucc)*(overlap (τ i.castSucc) (τ (Fin.last r)))^p) + ∂gaussianLaw (Edge n ⊕ (Fin p → Fin n))) := by + have h := integral_field_replica_energy_covariance + (perturbedCoeff n p β a) (perturbationNoise n p) i f + simp_rw [perturbationNoise_crossCov hn] at h + simp only [replicaMean, ← Finset.mul_sum] at h ⊢ + have he₁ (σ : Fin r → Configuration n) (z) : + replicaWeight (field (perturbedCoeff n p β a) z) σ* + (f σ*(a*∑ l, overlap (σ i) (σ l)^p)) = + a*(replicaWeight (field (perturbedCoeff n p β a) z) σ* + (f σ*∑ l, overlap (σ i) (σ l)^p)) := by ring + have he₂ (τ : Fin (r+1) → Configuration n) (z) : + replicaWeight (field (perturbedCoeff n p β a) z) τ* + (f (fun l => τ l.castSucc)*(a*overlap (τ i.castSucc) (τ (Fin.last r))^p)) = + a*(replicaWeight (field (perturbedCoeff n p β a) z) τ* + (f (fun l => τ l.castSucc)*overlap (τ i.castSucc) (τ (Fin.last r))^p)) := by ring + simp_rw [he₁, he₂, ← Finset.mul_sum, integral_const_mul] at h + convert h using 1 + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal +namespace ParisiFinite +open SKGaussian +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +lemma gibbsCov_self_nonneg (β : ℝ) (x v : ι → ℝ) : 0 ≤ gibbsCov β x v v := by + have h := weighted_covariance (weight (fun j => β*x j)) v v (sum_weight _) + have hs : 0 ≤ ∑ i, ∑ j, weight (fun j => β*x j) i*weight (fun j => β*x j) j* + (v i-v j)*(v i-v j) := by + apply Finset.sum_nonneg + intro i _ + apply Finset.sum_nonneg + intro j _ + have he : weight (fun j => β*x j) i*weight (fun j => β*x j) j* + (v i-v j)*(v i-v j) = + (weight (fun j => β*x j) i*weight (fun j => β*x j) j)*(v i-v j)^2 := by ring + rw [he] + exact mul_nonneg (mul_nonneg (weight_pos _ _).le (weight_pos _ _).le) (sq_nonneg _) + rw [h] at hs + unfold gibbsCov gibbsMean + simp only [mul_assoc] at hs + linarith + + +lemma monotone_gibbsMean_line (x v : ι → ℝ) : + Monotone (fun t : ℝ => gibbsMean 1 (x+t • v) v) := by + apply monotone_of_hasDerivAt_nonneg (fun t => hasDerivAt_gibbsMean 1 v v x t) + intro t + change (0:ℝ) ≤ 1*gibbsCov 1 (x+t • v) v v + simpa only [one_mul] using gibbsCov_self_nonneg 1 (x+t • v) v + +lemma hasDerivAt_logPartition_line (x v : ι → ℝ) (t : ℝ) : + HasDerivAt (fun u : ℝ => logPartition (x+u • v)) (gibbsMean 1 (x+t • v) v) t := by + simpa only [spinTrace, one_mul, div_one] using hasDerivAt_spinTrace (by norm_num : (1:ℝ) ≠ 0) v x t + +lemma convex_logPartition_line (x v : ι → ℝ) : + ConvexOn ℝ Set.univ (fun t : ℝ => logPartition (x+t • v)) := by + have hd : deriv (fun t : ℝ => logPartition (x+t • v)) = fun t => gibbsMean 1 (x+t • v) v := by + funext t + exact (hasDerivAt_logPartition_line x v t).deriv + apply Monotone.convexOn_univ_of_deriv (fun t => (hasDerivAt_logPartition_line x v t).differentiableAt) + rw [hd] + exact monotone_gibbsMean_line x v + + + +theorem convex_derivative_deviation {f g : ℝ → ℝ} + (hf : ConvexOn ℝ Set.univ f) (hg : ConvexOn ℝ Set.univ g) + (hfd : Differentiable ℝ f) (hgd : Differentiable ℝ g) + (x : ℝ) {δ : ℝ} (hδ : 0<δ) : + |deriv f x-deriv g x| ≤ + (|f (x+δ)-g (x+δ)|+2*|f x-g x|+|f (x-δ)-g (x-δ)|)/δ+ + (deriv g (x+δ)-deriv g (x-δ)) := by + have hfL := hf.slope_le_deriv (Set.mem_univ (x-δ)) (Set.mem_univ x) (by linarith) (hfd x) + have hfR := hf.deriv_le_slope (Set.mem_univ x) (Set.mem_univ (x+δ)) (by linarith) (hfd x) + have hgL := hg.deriv_le_slope (Set.mem_univ (x-δ)) (Set.mem_univ x) (by linarith) (hgd (x-δ)) + have hgR := hg.slope_le_deriv (Set.mem_univ x) (Set.mem_univ (x+δ)) (by linarith) (hgd (x+δ)) + have hm := hg.monotoneOn_deriv (fun x _ => hgd x) + have hmgL := hm (Set.mem_univ (x-δ)) (Set.mem_univ x) (by linarith) + have hmgR := hm (Set.mem_univ x) (Set.mem_univ (x+δ)) (by linarith) + simp only [slope_def_field, show x-(x-δ)=δ by ring, show x+δ-x=δ by ring] at hfL hfR hgL hgR + have hfL' := (div_le_iff₀ hδ).mp hfL + have hfR' := (le_div_iff₀ hδ).mp hfR + have hgL' := (le_div_iff₀ hδ).mp hgL + have hgR' := (div_le_iff₀ hδ).mp hgR + have h0 := le_abs_self (f x-g x) + have h0' := neg_abs_le (f x-g x) + have hp := le_abs_self (f (x+δ)-g (x+δ)) + have hm' := le_abs_self (f (x-δ)-g (x-δ)) + rw [abs_le] + constructor + · have hq : (deriv g x-deriv f x-(deriv g (x+δ)-deriv g (x-δ)))*δ ≤ + |f (x+δ)-g (x+δ)|+2*|f x-g x|+|f (x-δ)-g (x-δ)| := by + nlinarith [abs_nonneg (f (x+δ)-g (x+δ)), mul_le_mul_of_nonneg_right hmgR hδ.le] + have h := (le_div_iff₀ hδ).mpr hq + linarith + · have hq : (deriv f x-deriv g x-(deriv g (x+δ)-deriv g (x-δ)))*δ ≤ + |f (x+δ)-g (x+δ)|+2*|f x-g x|+|f (x-δ)-g (x-δ)| := by + nlinarith [abs_nonneg (f (x-δ)-g (x-δ)), mul_le_mul_of_nonneg_right hmgL hδ.le] + have h := (le_div_iff₀ hδ).mpr hq + linarith + +end ParisiFinite + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +omit [Nonempty ι] in +lemma norm_field_le_sum (B : ι → κ → ℝ) (z : κ → ℝ) : + ‖field B z‖ ≤ ∑ s, |field B z s| := by + apply (pi_norm_le_iff_of_nonneg (by positivity)).mpr + intro s + simpa only [Real.norm_eq_abs] using Finset.single_le_sum + (fun t (_ : t ∈ (Finset.univ : Finset ι)) => abs_nonneg (field B z t)) (Finset.mem_univ s) + +omit [Nonempty ι] in +lemma integrable_norm_field (B : ι → κ → ℝ) : + Integrable (fun z => ‖field B z‖) (gaussianLaw κ) := by + apply (integrable_finsetSum Finset.univ (fun s _ => (integrable_field B s).abs)).mono' + (continuous_field B).norm.aestronglyMeasurable + filter_upwards with z + simpa only [Real.norm_of_nonneg (norm_nonneg _)] using norm_field_le_sum B z + +omit [Fintype ι] [Nonempty ι] in +lemma memLp_field_two (B : ι → κ → ℝ) (s : ι) : + MemLp (fun z => field B z s) 2 (gaussianLaw κ) := by + unfold field + apply memLp_finsetSum + intro k _ + have h : MemLp (fun z : κ → ℝ => z k) 2 (gaussianLaw κ) := by + exact (memLp_id_gaussianReal (μ:=0) (v:=1) 2).comp_measurePreserving + (measurePreserving_eval (fun _ : κ => gaussianReal 0 1) k) + exact h.const_mul _ + +omit [Nonempty ι] in +lemma memLp_norm_field_two (B : ι → κ → ℝ) : + MemLp (fun z => ‖field B z‖) 2 (gaussianLaw κ) := by + have h : MemLp (fun z => ∑ s, |field B z s|) 2 (gaussianLaw κ) := + memLp_finsetSum Finset.univ (fun s _ => (memLp_field_two B s).norm) + apply h.mono' (continuous_field B).norm.aestronglyMeasurable + filter_upwards with z + simpa only [Real.norm_of_nonneg (norm_nonneg _)] using norm_field_le_sum B z + +omit [Nonempty ι] in +lemma integrable_norm_field_sq (B : ι → κ → ℝ) : + Integrable (fun z => ‖field B z‖^2) (gaussianLaw κ) := by + exact (memLp_norm_field_two B).integrable_sq + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKGaussian ParisiFinite ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +def affineCoeff (A B : ι → κ → ℝ) (t : ℝ) (s : ι) (k : κ) : ℝ := A s k+t*B s k + +omit [Fintype ι] [Nonempty ι] in +lemma field_affineCoeff (A B : ι → κ → ℝ) (t : ℝ) (z : κ → ℝ) : + field (affineCoeff A B t) z=field A z+t • field B z := by + ext s + simp only [field, affineCoeff, add_mul, Finset.sum_add_distrib, Pi.add_apply, + Pi.smul_apply, smul_eq_mul, Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro k _ + ring + +def expectedLine (A B : ι → κ → ℝ) (t : ℝ) : ℝ := + ∫ z, logPartition (field A z+t • field B z) ∂gaussianLaw κ + +def meanLine (A B : ι → κ → ℝ) (t : ℝ) : ℝ := + ∫ z, gibbsMean 1 (field A z+t • field B z) (field B z) ∂gaussianLaw κ + +def varianceLine (A B : ι → κ → ℝ) (t : ℝ) : ℝ := + ∫ z, gibbsCov 1 (field A z+t • field B z) (field B z) (field B z) ∂gaussianLaw κ + +omit [Nonempty ι] in +lemma expectedLine_eq (A B : ι → κ → ℝ) (t : ℝ) : + expectedLine A B t=expected (affineCoeff A B t) := by + simp [expectedLine, expected, field_affineCoeff] + +lemma continuous_lineMean (A B : ι → κ → ℝ) (t : ℝ) : + Continuous (fun z => gibbsMean 1 (field A z+t • field B z) (field B z)) := by + unfold gibbsMean + apply continuous_finsetSum + intro s _ + apply Continuous.mul + · have hc : Continuous (fun z => field A z+t • field B z) := + (continuous_field A).add ((continuous_field B).const_smul t) + simp only [one_mul] + change Continuous (fun z => weight (field A z+t • field B z) s) + exact (continuous_weight s).comp hc + · exact (continuous_apply s).comp (continuous_field B) + +lemma continuous_lineVariance (A B : ι → κ → ℝ) (t : ℝ) : + Continuous (fun z => gibbsCov 1 (field A z+t • field B z) (field B z) (field B z)) := by + unfold gibbsCov + apply Continuous.sub + · unfold gibbsMean + apply continuous_finsetSum + intro s _ + apply Continuous.mul + · have hc : Continuous (fun z => field A z+t • field B z) := + (continuous_field A).add ((continuous_field B).const_smul t) + simp only [one_mul] + change Continuous (fun z => weight (field A z+t • field B z) s) + exact (continuous_weight s).comp hc + · exact ((continuous_apply s).comp (continuous_field B)).mul + ((continuous_apply s).comp (continuous_field B)) + · exact (continuous_lineMean A B t).mul (continuous_lineMean A B t) + +lemma integrable_lineMean (A B : ι → κ → ℝ) (t : ℝ) : + Integrable (fun z => gibbsMean 1 (field A z+t • field B z) (field B z)) (gaussianLaw κ) := by + apply (integrable_norm_field B).mono' (continuous_lineMean A B t).aestronglyMeasurable + filter_upwards with z + simpa only [Real.norm_eq_abs] using abs_gibbsMean_le 1 (field A z+t • field B z) (field B z) + +lemma integrable_lineVariance (A B : ι → κ → ℝ) (t : ℝ) : + Integrable (fun z => gibbsCov 1 (field A z+t • field B z) (field B z) (field B z)) (gaussianLaw κ) := by + apply ((integrable_norm_field_sq B).const_mul 2).mono' + (continuous_lineVariance A B t).aestronglyMeasurable + filter_upwards with z + have h := abs_gibbsCov_le 1 (field A z+t • field B z) (field B z) (field B z) + simpa only [Real.norm_eq_abs, sq, mul_assoc] using h + + + +theorem hasDerivAt_expectedLine (A B : ι → κ → ℝ) (t₀ : ℝ) : + HasDerivAt (expectedLine A B) (meanLine A B t₀) t₀ := by + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s:=Set.univ) (bound:=fun z => ‖field B z‖) + (F':=fun t z => gibbsMean 1 (field A z+t • field B z) (field B z)) + (Filter.univ_mem) ?_ ?_ ?_ ?_ (integrable_norm_field B) ?_).2 + · exact Eventually.of_forall fun t => (continuous_logPartition.comp + ((continuous_field A).add ((continuous_field B).const_smul t))).aestronglyMeasurable + · exact integrable_logPartition (fun s => (integrable_field A s).add ((integrable_field B s).const_mul t₀)) + · exact (continuous_lineMean A B t₀).aestronglyMeasurable + · exact ae_of_all _ fun z t _ => by + simpa only [Real.norm_eq_abs] using abs_gibbsMean_le 1 (field A z+t • field B z) (field B z) + · exact ae_of_all _ fun z t _ => hasDerivAt_logPartition_line (field A z) (field B z) t + + +theorem hasDerivAt_meanLine (A B : ι → κ → ℝ) (t₀ : ℝ) : + HasDerivAt (meanLine A B) (varianceLine A B t₀) t₀ := by + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s:=Set.univ) (bound:=fun z => 2*‖field B z‖^2) + (F':=fun t z => gibbsCov 1 (field A z+t • field B z) (field B z) (field B z)) + (Filter.univ_mem) ?_ (integrable_lineMean A B t₀) ?_ ?_ + ((integrable_norm_field_sq B).const_mul 2) ?_).2 + · exact Eventually.of_forall fun t => (continuous_lineMean A B t).aestronglyMeasurable + · exact (continuous_lineVariance A B t₀).aestronglyMeasurable + · exact ae_of_all _ fun z t _ => by + simpa only [Real.norm_eq_abs, sq, mul_assoc] using + abs_gibbsCov_le 1 (field A z+t • field B z) (field B z) (field B z) + · exact ae_of_all _ fun z t _ => by + simpa only [one_mul] using hasDerivAt_gibbsMean 1 (field B z) (field B z) (field A z) t + +lemma varianceLine_nonneg (A B : ι → κ → ℝ) (t : ℝ) : 0 ≤ varianceLine A B t := + integral_nonneg fun _ => gibbsCov_self_nonneg 1 _ _ + +lemma monotone_meanLine (A B : ι → κ → ℝ) : Monotone (meanLine A B) := by + apply monotone_of_hasDerivAt_nonneg (hasDerivAt_meanLine A B) + intro t + exact varianceLine_nonneg A B t + +lemma convex_expectedLine (A B : ι → κ → ℝ) : ConvexOn ℝ Set.univ (expectedLine A B) := by + have he : deriv (expectedLine A B)=meanLine A B := funext fun t => (hasDerivAt_expectedLine A B t).deriv + apply Monotone.convexOn_univ_of_deriv (fun t => (hasDerivAt_expectedLine A B t).differentiableAt) + rw [he] + exact monotone_meanLine A B + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + + +def averagedReplica {r : ℕ} (A : ι → κ → ℝ) (f : (Fin r → ι) → ℝ) : ℝ := + ∫ z, replicaMean (field A z) f ∂gaussianLaw κ + +lemma replicaMean_const {r : ℕ} (x : ι → ℝ) (c : ℝ) : + replicaMean x (fun _ : Fin r → ι => c)=c := by + simp [replicaMean, ← Finset.sum_mul, sum_replicaWeight] + +omit [Nonempty ι] in +lemma replicaMean_add {r : ℕ} (x : ι → ℝ) (f g : (Fin r → ι) → ℝ) : + replicaMean x (fun σ => f σ+g σ)=replicaMean x f+replicaMean x g := by + simp [replicaMean, mul_add, Finset.sum_add_distrib] + +omit [Nonempty ι] in +lemma replicaMean_sub {r : ℕ} (x : ι → ℝ) (f g : (Fin r → ι) → ℝ) : + replicaMean x (fun σ => f σ-g σ)=replicaMean x f-replicaMean x g := by + simp [replicaMean, mul_sub, Finset.sum_sub_distrib] + +omit [Nonempty ι] in +lemma replicaMean_const_mul {r : ℕ} (x : ι → ℝ) (f : (Fin r → ι) → ℝ) (c : ℝ) : + replicaMean x (fun σ => c*f σ)=c*replicaMean x f := by + simp [replicaMean, mul_left_comm _ c, Finset.mul_sum] + +lemma averagedReplica_const {r : ℕ} (A : ι → κ → ℝ) (c : ℝ) : + averagedReplica A (fun _ : Fin r → ι => c)=c := by + simp [averagedReplica, replicaMean_const] + +lemma averagedReplica_add {r : ℕ} (A : ι → κ → ℝ) (f g : (Fin r → ι) → ℝ) : + averagedReplica A (fun σ => f σ+g σ)=averagedReplica A f+averagedReplica A g := by + simp only [averagedReplica, replicaMean_add] + exact integral_add (integrable_field_replicaMean A f) (integrable_field_replicaMean A g) + +lemma averagedReplica_sub {r : ℕ} (A : ι → κ → ℝ) (f g : (Fin r → ι) → ℝ) : + averagedReplica A (fun σ => f σ-g σ)=averagedReplica A f-averagedReplica A g := by + simp only [averagedReplica, replicaMean_sub] + exact integral_sub (integrable_field_replicaMean A f) (integrable_field_replicaMean A g) + +omit [Nonempty ι] in +lemma averagedReplica_const_mul {r : ℕ} (A : ι → κ → ℝ) (f : (Fin r → ι) → ℝ) (c : ℝ) : + averagedReplica A (fun σ => c*f σ)=c*averagedReplica A f := by + simp only [averagedReplica, replicaMean_const_mul, integral_const_mul] + +lemma averagedReplica_marginal {r : ℕ} (A : ι → κ → ℝ) (f : (Fin r → ι) → ℝ) : + averagedReplica A (fun τ : Fin (r+1) → ι => f (fun l => τ l.castSucc))=averagedReplica A f := by + simp only [averagedReplica, replicaMean_marginal] + +lemma averagedReplica_sum {r : ℕ} {L : Type*} [Fintype L] (A : ι → κ → ℝ) + (f : L → (Fin r → ι) → ℝ) : + averagedReplica A (fun σ => ∑ l, f l σ)=∑ l, averagedReplica A (f l) := by + have he (z : κ → ℝ) : replicaMean (field A z) (fun σ => ∑ l, f l σ)= + ∑ l, replicaMean (field A z) (f l) := by + simp only [replicaMean, Finset.mul_sum] + rw [Finset.sum_comm] + simp only [averagedReplica, he] + exact integral_finsetSum _ (fun l _ => integrable_field_replicaMean A (f l)) + +lemma replicaMean_abs_bound {r : ℕ} (x : ι → ℝ) {f : (Fin r → ι) → ℝ} {M : ℝ} + (h : ∀ σ, |f σ|≤M) : |replicaMean x f|≤M := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ σ, replicaWeight x σ*M := by + apply Finset.sum_le_sum + intro σ _ + rw [abs_mul, abs_of_nonneg (replicaWeight_nonneg _ _)] + exact mul_le_mul_of_nonneg_left (h σ) (replicaWeight_nonneg _ _) + _=M := replicaMean_const x M + +lemma averagedReplica_abs_bound {r : ℕ} (A : ι → κ → ℝ) {f : (Fin r → ι) → ℝ} {M : ℝ} + (h : ∀ σ, |f σ|≤M) : |averagedReplica A f|≤M := by + apply abs_integral_le_integral_abs.trans + have hb := integral_mono (integrable_field_replicaMean A f).abs (integrable_const M) + (fun z => replicaMean_abs_bound (field A z) h) + simpa using hb + + +def energyMean (A B : ι → κ → ℝ) : ℝ := + ∫ z, ∑ s, weight (field A z) s*field B z s ∂gaussianLaw κ + +def energyObservation {r : ℕ} (A B : ι → κ → ℝ) (i : Fin r) (f : (Fin r → ι) → ℝ) : ℝ := + ∫ z, ∑ σ, replicaWeight (field A z) σ*(field B z (σ i)*f σ) ∂gaussianLaw κ + +lemma energyObservation_one {r : ℕ} (A B : ι → κ → ℝ) (i : Fin r) : + energyObservation A B i (fun _ => 1)=energyMean A B := by + unfold energyObservation energyMean + simp only [mul_one] + apply integral_congr_ae + exact ae_of_all _ fun z => replicaMean_single (field A z) i (field B z) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + + +def energyDeviation (A B : ι → κ → ℝ) (c : ℝ) : ℝ := + ∫ z, ∑ s, weight (field A z) s*|field B z s-c| ∂gaussianLaw κ + +lemma integrable_energyDeviation (A B : ι → κ → ℝ) (c : ℝ) : + Integrable (fun z => ∑ s, weight (field A z) s*|field B z s-c|) (gaussianLaw κ) := by + apply integrable_finsetSum + intro s _ + apply (((integrable_field B s).sub (integrable_const c)).abs).bdd_mul + ((continuous_weight s).comp (continuous_field A)).aestronglyMeasurable (c:=1) + exact ae_of_all _ fun z => by + simp only [Function.comp_apply, Real.norm_eq_abs, abs_of_pos (weight_pos _ _)] + exact weight_le_one _ _ + +lemma energyDeviation_nonneg (A B : ι → κ → ℝ) (c : ℝ) : 0 ≤ energyDeviation A B c := by + apply integral_nonneg + intro z + exact Finset.sum_nonneg (fun s _ => mul_nonneg (weight_pos _ _).le (abs_nonneg _)) + +lemma energyObservation_sub_mean {r : ℕ} (A B : ι → κ → ℝ) (c : ℝ) + (i : Fin r) (f : (Fin r → ι) → ℝ) : + energyObservation A B i f-c*averagedReplica A f = + ∫ z, replicaMean (field A z) (fun σ => (field B z (σ i)-c)*f σ) ∂gaussianLaw κ := by + have he (z : κ → ℝ) : replicaMean (field A z) (fun σ => (field B z (σ i)-c)*f σ) = + (∑ σ, replicaWeight (field A z) σ*(field B z (σ i)*f σ))- + c*replicaMean (field A z) f := by + simp only [replicaMean, sub_mul, mul_sub, Finset.sum_sub_distrib] + congr 1 + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro σ _ + ring + simp only [he] + rw [integral_sub (integrable_field_replica_energy A B i f) + ((integrable_field_replicaMean A f).const_mul c), integral_const_mul] + rfl + + + +theorem energyObservation_covariance_bound {r : ℕ} (A B : ι → κ → ℝ) + (i : Fin r) (f : (Fin r → ι) → ℝ) {M : ℝ} (_hM : 0≤M) (hf : ∀ σ, |f σ|≤M) + (c : ℝ) : + |energyObservation A B i f-c*averagedReplica A f| ≤ M*energyDeviation A B c := by + rw [energyObservation_sub_mean] + apply abs_integral_le_integral_abs.trans + have hd (z : κ → ℝ) : + |replicaMean (field A z) (fun σ => (field B z (σ i)-c)*f σ)| ≤ + M*∑ s, weight (field A z) s*|field B z s-c| := by + calc + _ ≤ ∑ σ, |replicaWeight (field A z) σ*((field B z (σ i)-c)*f σ)| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ M*replicaMean (field A z) (fun σ => |field B z (σ i)-c|) := by + simp only [replicaMean, Finset.mul_sum] + apply Finset.sum_le_sum + intro σ _ + rw [abs_mul, abs_of_nonneg (replicaWeight_nonneg _ _), abs_mul] + have h := mul_le_mul_of_nonneg_left (hf σ) + (mul_nonneg (replicaWeight_nonneg (field A z) σ) (abs_nonneg (field B z (σ i)-c))) + nlinarith only [h] + _ = _ := by rw [replicaMean_single (field A z) i (fun s => |field B z s-c|)] + have hint : Integrable (fun z => replicaMean (field A z) + (fun σ => (field B z (σ i)-c)*f σ)) (gaussianLaw κ) := by + apply (((integrable_energyDeviation A B c).const_mul M)).mono' ?_ (ae_of_all _ fun z => by + simpa only [Real.norm_eq_abs] using hd z) + unfold replicaMean + apply Continuous.aestronglyMeasurable + apply continuous_finsetSum + intro σ _ + exact ((continuous_replicaWeight σ).comp (continuous_field A)).mul + ((((continuous_apply (σ i)).comp (continuous_field B)).sub continuous_const).mul_const (f σ)) + have hb := integral_mono hint.abs ((integrable_energyDeviation A B c).const_mul M) hd + simpa only [integral_const_mul, energyDeviation] using hb + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace GaussianConcentration +open SKGaussian ParisiInterpolation SKCavity + + + +lemma integral_abs_centered_le_sqrt_variance {Ω : Type*} [MeasurableSpace Ω] + {μ : Measure Ω} [IsProbabilityMeasure μ] {f : Ω → ℝ} (hf : MemLp f 2 μ) : + (∫ z, |f z-∫ x, f x ∂μ| ∂μ) ≤ Real.sqrt (variance f μ) := by + have hc := hf.sub (memLp_const (∫ x, f x ∂μ)) + have ha : MemLp (fun z => |f z-∫ x, f x ∂μ|) 2 μ := by + simpa only [Real.norm_eq_abs, Pi.sub_apply] using hc.norm + have hv := variance_nonneg (fun z => |f z-∫ x, f x ∂μ|) μ + rw [variance_eq_sub ha] at hv + simp only [Pi.pow_apply, sq_abs] at hv + rw [← variance_eq_integral hf.aemeasurable] at hv + have hs := Real.sq_sqrt (variance_nonneg f μ) + have hsn := Real.sqrt_nonneg (variance f μ) + nlinarith + +lemma memLp_logPartition_field {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + (A : ι → κ → ℝ) : MemLp (fun z => logPartition (field A z)) 2 (gaussianLaw κ) := by + have hfield : MemLp (field A) 2 (gaussianLaw κ) := by + apply memLp_pi_iff.mpr + intro s + exact memLp_field_two A s + have hLip : LipschitzWith 1 (fun x : ι → ℝ => logPartition x-logPartition (0 : ι → ℝ)) := by + rw [lipschitzWith_iff_norm_sub_le] + intro x y + simpa only [sub_sub_sub_cancel_right] using (logPartition_lipschitz (ι:=ι)).norm_sub_le x y + have h := hLip.comp_memLp (by simp) hfield + convert h.add (memLp_const (logPartition (0 : ι → ℝ))) using 1 + ext z + simp + + + +lemma logPartition_absolute_fluctuation {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + (A : ι → κ → ℝ) (c : κ → ℝ≥0) (hA : ∀ s k, |A s k|≤c k) : + (∫ z, |logPartition (field A z)-expected A| ∂gaussianLaw κ) ≤ + Real.sqrt (∑ k, (c k:ℝ)^2) := by + exact (integral_abs_centered_le_sqrt_variance (memLp_logPartition_field A)).trans + (Real.sqrt_le_sqrt (variance_field_logPartition_le A c hA)) + +end GaussianConcentration + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma pSpin_energyMean {n : ℕ} (hn : 0 (overlap (τ 0) (τ 1))^p)) := by + have h := pSpin_replica_identity hn p β a (0 : Fin 1) (fun _ => 1) + norm_num only [Nat.cast_one, Fin.castSucc_zero] at h + change energyObservation (perturbedCoeff n p β a) (perturbationNoise n p) (0 : Fin 1) (fun _ => 1) = + a*averagedReplica (perturbedCoeff n p β a) + (fun σ : Fin 1 → Configuration n => 1*∑ l, (overlap (σ 0) (σ l))^p)- + (1:ℝ)*a*averagedReplica (perturbedCoeff n p β a) + (fun τ : Fin 2 → Configuration n => 1*(overlap (τ 0) (τ 1))^p) at h + simp only [energyObservation_one, one_mul, Fin.sum_univ_one, overlap_self hn, one_pow, + averagedReplica_const] at h + linarith + + + +def pSpinGGDefect {n r : ℕ} (p : ℕ) (β a : ℝ) (i : Fin r) + (f : (Fin r → Configuration n) → ℝ) : ℝ := + (r:ℝ)*averagedReplica (perturbedCoeff n p β a) + (fun τ : Fin (r+1) → Configuration n => f (fun l => τ l.castSucc)* + (overlap (τ i.castSucc) (τ (Fin.last r)))^p)- + averagedReplica (perturbedCoeff n p β a) f* + averagedReplica (perturbedCoeff n p β a) + (fun τ : Fin 2 → Configuration n => (overlap (τ 0) (τ 1))^p)- + averagedReplica (perturbedCoeff n p β a) + (fun σ => f σ*∑ l ∈ Finset.univ.erase i, (overlap (σ i) (σ l))^p) + + + +theorem pSpinGGDefect_identity {n r : ℕ} (hn : 0 f σ*∑ l, overlap (σ i) (σ l)^p)- + (r:ℝ)*a*averagedReplica (perturbedCoeff n p β a) + (fun τ : Fin (r+1) → Configuration n => f (fun l => τ l.castSucc)* + overlap (τ i.castSucc) (τ (Fin.last r))^p) at h + have he (σ : Fin r → Configuration n) : f σ*∑ l, overlap (σ i) (σ l)^p = + f σ+f σ*∑ l ∈ Finset.univ.erase i, overlap (σ i) (σ l)^p := by + have hs := Finset.sum_erase_add Finset.univ (fun l => overlap (σ i) (σ l)^p) (Finset.mem_univ i) + rw [overlap_self hn, one_pow] at hs + rw [← hs] + ring + simp_rw [he, averagedReplica_add] at h + rw [pSpin_energyMean hn, h] + unfold pSpinGGDefect + ring + + + +theorem pSpinGGDefect_bound {n r : ℕ} (hn : 0 ⟪SpinOperators.act Y (hugePacket (R a) (d a) (e a) (xp a) (xm a)), + hugePacket (R a) (d a) (e a) (yp a) (ym a)⟫_ℂ) l (𝓝 0) := by + have hP : ∀ᶠ a : α in l, matrixMass Y≤ matrixMass Y := Filter.Eventually.of_forall (fun _ => le_rfl) + have h1 := rapid_decay_spin_matrix R d e xp ym (fun _ => Y) hR B A (matrixMass Y) δ hA + (matrixMass_nonneg _) hδ hxp hym hP hsep 0 + have hsep' : ∀ᶠ a in l, δ≤ ‖e a-d a‖ := hsep.mono (fun a ha => by rwa [norm_sub_rev]) + have h2 := rapid_decay_spin_matrix R e d xm yp (fun _ => Y) hR B A (matrixMass Y) δ hA + (matrixMass_nonneg _) hδ hxm hyp hP hsep' 0 + simp only [pow_zero,one_mul] at h1 h2 + have h1' := tendsto_zero_iff_norm_tendsto_zero.mpr h1 + have h2' := tendsto_zero_iff_norm_tendsto_zero.mpr h2 + have hh := h1'.add h2' + simp only [add_zero] at hh + apply hh.congr' + filter_upwards [hs] with a ha + exact (inner_rootY_hugePacket (R a) (d a) (e a) (xp a) (xm a) (yp a) (ym a) + ha.1 ha.2.1 ha.2.2.1 ha.2.2.2).symm + + + +theorem inner_rootY_error_bound (x y u v : SpinSpace E) : + ‖⟪SpinOperators.act Y x,y⟫_ℂ-⟪SpinOperators.act Y u,v⟫_ℂ‖≤ + ‖x-u‖*‖y‖+‖u‖*‖y-v‖ := by + have hY (w : SpinSpace E) : ‖SpinOperators.act Y w‖=‖w‖ := + (SpinOperators.actEquiv Y Y_unitary).norm_map w + have he : ⟪SpinOperators.act Y x,y⟫_ℂ-⟪SpinOperators.act Y u,v⟫_ℂ= + ⟪SpinOperators.act Y (x-u),y⟫_ℂ+⟪SpinOperators.act Y u,y-v⟫_ℂ := by + simp only [map_sub,inner_sub_left,inner_sub_right] + ring + rw [he] + apply (norm_add_le _ _).trans + simpa only [hY] using add_le_add (norm_inner_le_norm (𝕜 := ℂ) (SpinOperators.act Y (x-u)) y) + (norm_inner_le_norm (𝕜 := ℂ) (SpinOperators.act Y u) (y-v)) + + + +theorem huge_transverse_actual {α : Type*} {l : Filter α} + (U : α → SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E) (Ω : SpinSpace E) (η : α → SpinSpace E) + (R : α → ℝ) (d e : α → E) (xp xm yp ym : α → PreSpin E) + (hR : Tendsto R l atTop) (B A δ C : ℝ) (hA : 0≤ A) (hδ : 0<δ) + (hxp : ∀ᶠ a in l, SpinRadiusLE (xp a) B ∧ spinMass (xp a)≤ A) + (hxm : ∀ᶠ a in l, SpinRadiusLE (xm a) B ∧ spinMass (xm a)≤ A) + (hyp : ∀ᶠ a in l, SpinRadiusLE (yp a) B ∧ spinMass (yp a)≤ A) + (hym : ∀ᶠ a in l, SpinRadiusLE (ym a) B ∧ spinMass (ym a)≤ A) + (hs : ∀ᶠ a in l, xp a 1=0 ∧ xm a 0=0 ∧ yp a 1=0 ∧ ym a 0=0) + (hsep : ∀ᶠ a in l, δ≤ ‖d a-e a‖) (hη : ∀ᶠ a in l, ‖η a‖≤ C) + (herrΩ : Tendsto (fun a => ‖U a Ω-hugePacket (R a) (d a) (e a) (xp a) (xm a)‖) l (𝓝 0)) + (herrη : Tendsto (fun a => ‖U a (η a)-hugePacket (R a) (d a) (e a) (yp a) (ym a)‖) l (𝓝 0)) : + Tendsto (fun a => ⟪(U a).symm (SpinOperators.act Y (U a Ω)),η a⟫_ℂ) l (𝓝 0) := by + let P a := hugePacket (R a) (d a) (e a) (xp a) (xm a) + let Q a := hugePacket (R a) (d a) (e a) (yp a) (ym a) + have hp := tendsto_inner_rootY_hugePacket R d e xp xm yp ym hR B A δ hA hδ hxp hxm hyp hym hs hsep + have he : Tendsto (fun a => + ⟪SpinOperators.act Y (U a Ω),U a (η a)⟫_ℂ-⟪SpinOperators.act Y (P a),Q a⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + have hb := (herrΩ.mul_const C).add (herrη.const_mul (2*A)) + simp only [zero_mul,mul_zero,add_zero] at hb + apply squeeze_zero' (Filter.Eventually.of_forall (fun _ => norm_nonneg _)) _ hb + filter_upwards [hxp,hxm,hη] with a hpa hma hηa + apply (inner_rootY_error_bound (U a Ω) (U a (η a)) (P a) (Q a)).trans + have hpn : ‖P a‖≤ 2*A := (norm_hugePacket_le _ _ _ _ _).trans (by linarith [hpa.2,hma.2]) + rw [(U a).norm_map] + exact add_le_add (mul_le_mul_of_nonneg_left hηa (norm_nonneg _)) + (mul_le_mul_of_nonneg_right hpn (norm_nonneg _)) + have hh := he.add hp + simp only [P,Q,sub_add_cancel,add_zero] at hh + convert hh using 1 + ext a + have hv := (U a).inner_map_map ((U a).symm (SpinOperators.act Y (U a Ω))) (η a) + simpa only [LinearIsometryEquiv.apply_symm_apply] using hv.symm + +end CoherentFock + +namespace GaussianCoherent +open MeasureTheory ProbabilityTheory Complex CoherentFock +open scoped BigOperators InnerProductSpace ComplexConjugate +variable {κ : Type*} [Fintype κ] + +abbrev Mode (κ : Type*) [Fintype κ] := EuclideanSpace ℂ κ +abbrev Hilbert (κ : Type*) [Fintype κ] := Lp ℂ 2 (GaussianFourier.law κ) + + + +def offset (d : Mode κ) : ℂ := (∑k, (d k)^2)/2-((‖d‖^2:ℝ):ℂ)/2 + +def wave (d : Mode κ) (g : κ → ℝ) : ℂ := + Complex.exp (offset d)*Complex.exp (∑k, I*d k*(g k:ℂ)) + +theorem continuous_wave (d : Mode κ) : Continuous (wave d) := by + unfold wave + fun_prop + +theorem wave_pair (d e : Mode κ) (g : κ → ℝ) : + conj (wave d g)*wave e g= + Complex.exp (conj (offset d)+offset e)* + Complex.exp (∑k, (I*(e k-conj (d k)))*(g k:ℂ)) := by + simp only [wave,map_mul,←Complex.exp_conj,map_sum,Complex.conj_I,Complex.conj_ofReal] + rw [←Complex.exp_add,←Complex.exp_add,←Complex.exp_add,←Complex.exp_add] + congr 1 + have hh : (∑k, -I*conj (d k)*(g k:ℂ))+(∑k, I*e k*(g k:ℂ))= + ∑k, I*(e k-conj (d k))*(g k:ℂ) := by + rw [←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro k hk + ring + linear_combination hh + +theorem integrable_wave_pair (d e : Mode κ) : + Integrable (fun g => conj (wave d g)*wave e g) (GaussianFourier.law κ) := by + simp_rw [wave_pair] + exact (GaussianFourier.integrable_exp_sum (fun k => I*(e k-conj (d k)))).const_mul _ + +theorem exponent_pair (d e : Mode κ) : + conj (offset d)+offset e+(∑k, (I*(e k-conj (d k)))^2/2)= + -((‖d‖^2+‖e‖^2:ℝ):ℂ)/2+⟪d,e⟫_ℂ := by + simp only [offset,map_sub,map_div₀,map_sum,map_pow,Complex.conj_ofReal, + map_ofNat,PiLp.inner_apply,RCLike.inner_apply'] + push_cast + simp_rw [←Finset.sum_div] + have hs : (∑k, (conj (d k))^2)+(∑k, (e k)^2)+ + (∑k, (I*(e k-conj (d k)))^2)=2*∑k, conj (d k)*e k := by + rw [←Finset.sum_add_distrib,←Finset.sum_add_distrib,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k hk + ring_nf + rw [Complex.I_sq] + ring + linear_combination hs/2 + + + +theorem integral_wave_pair (d e : Mode κ) : + (∫g, conj (wave d g)*wave e g ∂GaussianFourier.law κ)=kernel d e := by + simp_rw [wave_pair] + rw [integral_const_mul,GaussianFourier.integral_exp_sum,←Complex.exp_add,exponent_pair] + unfold kernel + congr 1 + push_cast + ring + +theorem memLp_wave (d : Mode κ) : MemLp (wave d) 2 (GaussianFourier.law κ) := by + apply (memLp_two_iff_integrable_sq_norm (continuous_wave d).aestronglyMeasurable).mpr + have h := (integrable_wave_pair d d).re + convert h using 1 + funext g + rw [Complex.conj_mul'] + change ‖wave d g‖^2 = ((‖wave d g‖:ℂ)^2).re + rw [←Complex.ofReal_pow,Complex.ofReal_re] + +def vector (d : Mode κ) : Hilbert κ := (memLp_wave d).toLp (wave d) + +theorem vector_ae (d : Mode κ) : (vector d : (κ → ℝ) → ℂ)=ᵐ[GaussianFourier.law κ] wave d := + (memLp_wave d).coeFn_toLp + +@[simp] theorem inner_vector (d e : Mode κ) : ⟪vector d,vector e⟫_ℂ=kernel d e := by + rw [L2.inner_def] + rw [←integral_wave_pair d e] + apply integral_congr_ae + filter_upwards [vector_ae d,vector_ae e] with g hd he + rw [hd,he] + exact RCLike.inner_apply' _ _ + + + +def preMap : PreSpace (Mode κ) →ₗᵢ[ℂ] Hilbert κ := + LinearMap.isometryOfInner + ((Finsupp.linearCombination ℂ vector).comp toFinsupp.toLinearMap) (by + intro x y + change ⟪(toFinsupp x).sum (fun d a => a • vector d), + (toFinsupp y).sum (fun e b => b • vector e)⟫_ℂ=_ + rw [Finsupp.sum_inner] + change (toFinsupp x).sum (fun d a => ⟪a • vector d, + (toFinsupp y).sum (fun e b => b • vector e)⟫_ℂ)= + (toFinsupp x).sum (fun d a => (toFinsupp y).sum (fun e b => conj a*kernel d e*b)) + apply Finsupp.sum_congr + intro d hd + rw [Finsupp.inner_sum] + apply Finsupp.sum_congr + intro e he + simp only [inner_smul_left,inner_smul_right,inner_vector] + ring) + + +def representation : Space (Mode κ) →ₗᵢ[ℂ] Hilbert κ where + toLinearMap := preMap.toContinuousLinearMap.fromCompletion.toLinearMap + norm_map' x := by + refine UniformSpace.Completion.induction_on x + (isClosed_eq (preMap.toContinuousLinearMap.fromCompletion.continuous.norm) continuous_norm) + fun y => ?_ + change ‖preMap.toContinuousLinearMap.fromCompletion (y:Space (Mode κ))‖=‖(y:Space (Mode κ))‖ + rw [ContinuousLinearMap.fromCompletion_apply_coe,UniformSpace.Completion.norm_coe] + exact preMap.norm_map y + +@[simp] theorem representation_coherent (d : Mode κ) : representation (coherent d)=vector d := by + change preMap.toContinuousLinearMap.fromCompletion + ((toFinsupp.symm (Finsupp.single d 1):PreSpace (Mode κ)):Space (Mode κ))=vector d + rw [ContinuousLinearMap.fromCompletion_apply_coe] + change Finsupp.linearCombination ℂ vector (Finsupp.single d 1)=vector d + simp + +end GaussianCoherent + +namespace GaussianCoherent +open MeasureTheory ProbabilityTheory Complex CoherentFock +open scoped BigOperators InnerProductSpace ComplexConjugate +variable {κ : Type*} [Fintype κ] + +def realMode (a : κ → ℝ) : Mode κ := WithLp.toLp 2 (fun k => (a k:ℂ)) + +@[simp] theorem realMode_apply (a : κ → ℝ) (k : κ) : realMode a k=(a k:ℂ) := rfl + +@[simp] theorem norm_realMode_sq (a : κ → ℝ) : ‖realMode a‖^2=∑k, (a k)^2 := by + rw [EuclideanSpace.norm_sq_eq] + simp [Real.norm_eq_abs,sq_abs] + +@[simp] theorem offset_realMode (a : κ → ℝ) : offset (realMode a)=0 := by + simp [offset,norm_realMode_sq,Complex.ofReal_sum] + +@[simp] theorem wave_realMode (a : κ → ℝ) (g : κ → ℝ) : + wave (realMode a) g=Complex.exp ((∑k, a k*g k:ℝ)*I) := by + simp only [wave,offset_realMode,Complex.exp_zero,one_mul,realMode_apply] + congr 1 + push_cast + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro k hk + ring + +@[simp] theorem norm_wave_realMode (a : κ → ℝ) (g : κ → ℝ) : ‖wave (realMode a) g‖=1 := by + rw [wave_realMode,Complex.norm_exp] + simp + +theorem memLp_seedPhase (a : κ → ℝ) (f : Hilbert κ) : + MemLp (fun g => wave (realMode a) g*f g) 2 (GaussianFourier.law κ) := by + apply (Lp.memLp f).congr_norm + ((continuous_wave (realMode a)).aestronglyMeasurable.mul (Lp.aestronglyMeasurable f)) + exact Filter.Eventually.of_forall fun g => by + change ‖f g‖=‖wave (realMode a) g*f g‖ + rw [norm_mul,norm_wave_realMode,one_mul] + + +def seedPhase (a : κ → ℝ) (f : Hilbert κ) : Hilbert κ := + (memLp_seedPhase a f).toLp (fun g => wave (realMode a) g*f g) + +theorem seedPhase_ae (a : κ → ℝ) (f : Hilbert κ) : + (seedPhase a f : (κ → ℝ) → ℂ)=ᵐ[GaussianFourier.law κ] fun g => wave (realMode a) g*f g := + MemLp.coeFn_toLp _ + + + +def seedPhaseIsometry (a : κ → ℝ) : Hilbert κ →ₗᵢ[ℂ] Hilbert κ where + toFun := seedPhase a + map_add' f h := by + apply Lp.ext + filter_upwards [seedPhase_ae a (f+h),Lp.coeFn_add f h, + Lp.coeFn_add (seedPhase a f) (seedPhase a h),seedPhase_ae a f,seedPhase_ae a h] with g h1 h2 h3 h4 h5 + rw [h1,h2,h3] + simp only [Pi.add_apply,h4,h5] + exact mul_add _ _ _ + map_smul' c f := by + change seedPhase a (c • f)=c • seedPhase a f + apply Lp.ext + filter_upwards [seedPhase_ae a (c • f),Lp.coeFn_smul c f, + Lp.coeFn_smul c (seedPhase a f),seedPhase_ae a f] with g h1 h2 h3 h4 + rw [h1,h2,h3] + simp only [Pi.smul_apply,h4] + simp only [smul_eq_mul] + ring + norm_map' f := by + have hh : ∀ᵐ g ∂GaussianFourier.law κ, ‖seedPhase a f g‖=‖f g‖ := by + filter_upwards [seedPhase_ae a f] with g hg + rw [hg,norm_mul,norm_wave_realMode,one_mul] + exact le_antisymm (Lp.norm_le_norm_of_ae_le (hh.mono fun _ h => h.le)) + (Lp.norm_le_norm_of_ae_le (hh.mono fun _ h => h.ge)) + +theorem offset_real_add (a : κ → ℝ) (d : Mode κ) : + offset (realMode a+d)=offset d+((⟪realMode a,d⟫_ℂ).im:ℂ)*I := by + have hs : (∑k, (realMode a k+d k)^2)= + (∑k, (realMode a k)^2)+2*⟪realMode a,d⟫_ℂ+(∑k, (d k)^2) := by + simp only [PiLp.inner_apply,RCLike.inner_apply',realMode_apply,Complex.conj_ofReal] + rw [Finset.mul_sum,←Finset.sum_add_distrib,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro k hk + ring + have ho := offset_realMode a + unfold offset at ho ⊢ + simp only [PiLp.add_apply] + rw [_root_.norm_add_sq (𝕜 := ℂ)] + rw [hs] + have hc := Complex.re_add_im ⟪realMode a,d⟫_ℂ + push_cast at ho ⊢ + linear_combination ho - hc + + + +theorem phase_wave_real_add (a : κ → ℝ) (d : Mode κ) (g : κ → ℝ) : + phase (realMode a) d*wave (realMode a+d) g=wave (realMode a) g*wave d g := by + simp only [phase,wave,offset_realMode,Complex.exp_zero,one_mul,offset_real_add] + simp only [←Complex.exp_add] + congr 1 + simp only [PiLp.add_apply,mul_add,add_mul,Finset.sum_add_distrib] + push_cast + ring + +theorem seedPhase_vector (a : κ → ℝ) (d : Mode κ) : + seedPhaseIsometry a (vector d)=phase (realMode a) d • vector (realMode a+d) := by + apply Lp.ext + filter_upwards [seedPhase_ae a (vector d),vector_ae d,vector_ae (realMode a+d), + Lp.coeFn_smul (phase (realMode a) d) (vector (realMode a+d))] with g h1 h2 h3 h4 + change seedPhase a (vector d) g = _ + rw [h1,h2,h4] + simp only [Pi.smul_apply,smul_eq_mul] + rw [h3] + exact (phase_wave_real_add a d g).symm + + +theorem representation_W_real (a : κ → ℝ) (x : Space (Mode κ)) : + representation (W (realMode a) x)=seedPhaseIsometry a (representation x) := by + have he : representation.toContinuousLinearMap.comp (W (realMode a))= + (seedPhaseIsometry a).toContinuousLinearMap.comp representation.toContinuousLinearMap := by + apply CoherentFock.ext_coherent + intro d + simp only [ContinuousLinearMap.comp_apply,LinearIsometry.coe_toContinuousLinearMap, + W_coherent,map_smul,representation_coherent,seedPhase_vector] + exact DFunLike.congr_fun he x + +end GaussianCoherent +namespace FourierDensity +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators ComplexConjugate InnerProductSpace +variable {κ : Type*} [Fintype κ] + +def character (a g : κ → ℝ) : ℂ := Complex.exp ((∑k, a k*g k:ℝ)*I) + +theorem continuous_character (a : κ → ℝ) : Continuous (character a) := by + unfold character + fun_prop + +@[simp] theorem norm_character (a g : κ → ℝ) : ‖character a g‖=1 := by + simp [character,Complex.norm_exp] + +@[simp] theorem character_neg (a g : κ → ℝ) : character (-a) g=conj (character a g) := by + simp [character,←Complex.exp_conj,Finset.sum_neg_distrib] + +variable {μ : Measure (κ → ℝ)} + +theorem integrable_character_mul {f : (κ → ℝ) → ℂ} + (hf : Integrable f μ) (a : κ → ℝ) : Integrable (fun g => character a g*f g) μ := + hf.bdd_mul (continuous_character a).aestronglyMeasurable + (Filter.Eventually.of_forall fun g => (norm_character a g).le) + +theorem dual_eq_sum [DecidableEq κ] (L : StrongDual ℝ (κ → ℝ)) (g : κ → ℝ) : + L g=∑k, L (Pi.single k 1)*g k := by + classical + have hg : g=∑k, g k • Pi.single k 1 := by + ext j + simp [Finset.sum_apply,Pi.smul_apply,Pi.single_apply] + conv_lhs => rw [hg] + simp only [map_sum,map_smul,smul_eq_mul,mul_comm] + + + +theorem ae_zero_of_real_fourier_zero [IsFiniteMeasure μ] + {f : (κ → ℝ) → ℝ} (hf : Integrable f μ) + (hF : ∀a, (∫g, character a g*(f g:ℂ) ∂μ)=0) : f=ᵐ[μ] 0 := by + classical + let fpos := fun g => max (f g) 0 + let fneg := fun g => max (-f g) 0 + have hp : Integrable fpos μ := hf.pos_part + have hn : Integrable fneg μ := hf.neg_part + let μp := μ.withDensity (fun g => ENNReal.ofReal (fpos g)) + let μn := μ.withDensity (fun g => ENNReal.ofReal (fneg g)) + have : IsFiniteMeasure μp := isFiniteMeasure_withDensity_ofReal hp.2 + have : IsFiniteMeasure μn := isFiniteMeasure_withDensity_ofReal hn.2 + have heq : μp=μn := by + apply Measure.ext_of_charFunDual + funext L + simp only [charFunDual_apply] + have hl : (fun g => Complex.exp ((L g : ℝ)*I))= + character (fun k => L (Pi.single k 1)) := by + funext g + rw [dual_eq_sum L g] + rfl + rw [hl] + change (∫g, character (fun k => L (Pi.single k 1)) g ∂μp)= + (∫g, character (fun k => L (Pi.single k 1)) g ∂μn) + dsimp only [μp,μn] + rw [integral_withDensity_eq_integral_toReal_smul₀ hp.1.aemeasurable.ennreal_ofReal + (Filter.Eventually.of_forall fun _ => ENNReal.ofReal_lt_top), + integral_withDensity_eq_integral_toReal_smul₀ hn.1.aemeasurable.ennreal_ofReal + (Filter.Eventually.of_forall fun _ => ENNReal.ofReal_lt_top)] + simp only [ENNReal.toReal_ofReal (le_max_right _ _),fpos,fneg,real_smul] + apply sub_eq_zero.mp + change (∫g, (fpos g:ℂ)*character (fun k => L (Pi.single k 1)) g ∂μ)- + (∫g, (fneg g:ℂ)*character (fun k => L (Pi.single k 1)) g ∂μ)=0 + have hpC : Integrable (fun g => (fpos g:ℂ)*character + (fun k => L (Pi.single k 1)) g) μ := + (integrable_character_mul hp.ofReal (fun k => L (Pi.single k 1))).congr + (Filter.Eventually.of_forall fun g => mul_comm _ _) + have hnC : Integrable (fun g => (fneg g:ℂ)*character + (fun k => L (Pi.single k 1)) g) μ := + (integrable_character_mul hn.ofReal (fun k => L (Pi.single k 1))).congr + (Filter.Eventually.of_forall fun g => mul_comm _ _) + rw [←integral_sub hpC hnC] + convert hF (fun k => L (Pi.single k 1)) using 1 + congr 1 + funext g + have hm : max (f g) 0-max (-f g) 0=f g := max_zero_sub_max_neg_zero_eq_self _ + dsimp only [fpos,fneg] + rw [←sub_mul,←Complex.ofReal_sub,hm,mul_comm] + have hd := (withDensity_eq_iff_of_sigmaFinite hp.1.aemeasurable.ennreal_ofReal + hn.1.aemeasurable.ennreal_ofReal).mp heq + filter_upwards [hd] with g hg + have hh := congrArg ENNReal.toReal hg + simp only [ENNReal.toReal_ofReal (le_max_right _ _),fpos,fneg] at hh + change f g=0 + have hm : max (f g) 0-max (-f g) 0=f g := max_zero_sub_max_neg_zero_eq_self _ + linarith + + +theorem ae_re_zero_of_fourier_zero [IsFiniteMeasure μ] + {f : (κ → ℝ) → ℂ} (hf : Integrable f μ) + (hF : ∀a, (∫g, character a g*f g ∂μ)=0) : + (fun g => (f g).re)=ᵐ[μ] 0 := by + have hc : ∀a, (∫g, character a g*conj (f g) ∂μ)=0 := by + intro a + have hh := congrArg conj (hF (-a)) + rw [map_zero,←integral_conj] at hh + simpa only [map_mul,character_neg,Complex.conj_conj] using hh + have hfc : Integrable (fun g => conj (f g)) μ := + (@RCLike.conjLIE ℂ _).toContinuousLinearEquiv.toContinuousLinearMap.integrable_comp hf + apply ae_zero_of_real_fourier_zero hf.re + intro a + calc + (∫g, character a g*((f g).re:ℂ) ∂μ)= + (1/2:ℂ)*(∫g, character a g*f g+character a g*conj (f g) ∂μ) := by + rw [←integral_const_mul] + apply integral_congr_ae + exact Filter.Eventually.of_forall fun g => by + have hadd := Complex.add_conj (f g) + push_cast at hadd + linear_combination -(character a g)*hadd/2 + _=0 := by + rw [integral_add (integrable_character_mul hf a) (integrable_character_mul hfc a), + hF a,hc a] + simp + + + +theorem ae_zero_of_fourier_zero [IsFiniteMeasure μ] + {f : (κ → ℝ) → ℂ} (hf : Integrable f μ) + (hF : ∀a, (∫g, character a g*f g ∂μ)=0) : f=ᵐ[μ] 0 := by + have hr := ae_re_zero_of_fourier_zero hf hF + have hi := ae_re_zero_of_fourier_zero (hf.const_mul I) (fun a => by + calc + (∫g, character a g*(I*f g) ∂μ)=I*(∫g, character a g*f g ∂μ) := by + rw [←integral_const_mul] + congr 1 + funext g + ring + _=0 := by rw [hF a,mul_zero]) + filter_upwards [hr,hi] with g hrg hig + apply Complex.ext + · exact hrg + · simpa using hig + +end FourierDensity + +namespace GaussianCoherent +open MeasureTheory ProbabilityTheory Complex CoherentFock +open scoped BigOperators InnerProductSpace ComplexConjugate +variable {κ : Type*} [Fintype κ] + + + +theorem representation_surjective : Function.Surjective (representation (κ := κ)) := by + let K := (representation (κ := κ)).toLinearMap.range + have hK : IsClosed (K : Set (Hilbert κ)) := + (representation (κ := κ)).isometry.isClosedEmbedding.isClosed_range + have hbot : Kᗮ=⊥ := by + apply (Submodule.eq_bot_iff _).mpr + intro f hf + apply Lp.ext + have hi : Integrable (fun g => f g) (GaussianFourier.law κ) := + memLp_one_iff_integrable.mp ((Lp.memLp f).mono_exponent (by norm_num)) + have hF : ∀a, (∫g, FourierDensity.character a g*f g ∂GaussianFourier.law κ)=0 := by + intro a + have hh := (Submodule.mem_orthogonal K f).mp hf (vector (realMode (-a))) + ⟨coherent (realMode (-a)),representation_coherent _⟩ + rw [L2.inner_def] at hh + convert hh using 1 + apply integral_congr_ae + filter_upwards [vector_ae (realMode (-a))] with g hg + rw [RCLike.inner_apply',hg,wave_realMode] + change FourierDensity.character a g*f g= + conj (FourierDensity.character (-a) g)*f g + rw [FourierDensity.character_neg,Complex.conj_conj] + have hz := FourierDensity.ae_zero_of_fourier_zero hi hF + exact hz.trans (Lp.coeFn_zero ℂ 2 (GaussianFourier.law κ)).symm + apply LinearMap.range_eq_top.mp + change K=⊤ + calc + K=K.topologicalClosure := hK.submodule_topologicalClosure_eq.symm + _=Kᗮᗮ := (Submodule.orthogonal_orthogonal_eq_closure K).symm + _=⊤ := by rw [hbot,Submodule.bot_orthogonal_eq_top] + + +def gaussianUnitary : Space (Mode κ) ≃ₗᵢ[ℂ] Hilbert κ := + LinearIsometryEquiv.ofSurjective representation representation_surjective + +@[simp] theorem gaussianUnitary_coherent (d : Mode κ) : + gaussianUnitary (coherent d)=vector d := representation_coherent d + +theorem gaussianUnitary_W_real (a : κ → ℝ) (x : Space (Mode κ)) : + gaussianUnitary (W (realMode a) x)=seedPhaseIsometry a (gaussianUnitary x) := + representation_W_real a x + +end GaussianCoherent + +namespace CoherentFock +open scoped InnerProductSpace ComplexConjugate +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem eq_zero_of_inner_coherent (x : Space E) (hx : ∀d, ⟪coherent d,x⟫_ℂ=0) : x=0 := by + have hh : innerSL ℂ x=0 := by + apply ext_coherent + intro d + exact inner_eq_zero_symm.mp (hx d) + have hhx := DFunLike.congr_fun hh x + exact inner_self_eq_zero.mp hhx +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/InnovationEulerMemLp.lean b/lean/OAI/Probability/ParisiFinite/InnovationEulerMemLp.lean new file mode 100644 index 0000000000000000000000000000000000000000..892fe7f21f71c4f14f313116cefdfd7fae9ee94c --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/InnovationEulerMemLp.lean @@ -0,0 +1,679 @@ +import Mathlib +import OAI.Probability.ParisiFinite.HorizonGrid + +namespace OAI + +/-! Innovation Euler Mem Lp. -/ + +noncomputable section + +open MeasureTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace ParisiPath +open ProbabilityTheory +open scoped BigOperators ENNReal +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + {Z : ℕ → Ω → ℝ} + +lemma innovationEuler_memLp (hl : ∀ k,HasLaw (Z k) (gaussianReal 0 1) P) + (b : Drift K M) (T : ℝ≥0) (n k : ℕ) {p : ℝ≥0∞} (hp : p≠∞) : + MemLp (fun ω => innovationEuler b T n k (fun j => Z j ω)) p P := by + let : IsProbabilityMeasure P := (hl 0).isProbabilityMeasure + induction k with + | zero => exact memLp_const 0 + | succ k ih => + have hi := scalar_euler_increment_memLp (hl k) M ((T:ℝ)*mesh n) + (u := fun ω => b.val ((T:ℝ)*grid n k) (innovationEuler b T n k (fun j => Z j ω))) + ((b.lipschitz ((T:ℝ)*grid n k)).continuous.measurable.comp_aemeasurable + ih.aemeasurable) (fun ω => b.bound _ _) hp + convert! ih.add hi using 1 + first | rfl | (funext ω; simp only [innovationEuler,Pi.add_apply];ring) + +lemma CubicTest.integrable_comp (f : CubicTest) {X : Ω → ℝ} + (hX : Integrable X P) [IsProbabilityMeasure P] : Integrable (fun ω => f.val (X ω)) P := by + have hLip : LipschitzWith f.c1 (fun x => f.val x-f.val 0) := by + intro x y + simpa only [edist_sub_right] using f.lipschitz x y + have h := hLip.comp_memLp (by simp) ((memLp_one_iff_integrable).mpr hX) + have hh := (h.add (memLp_const (f.val 0))).integrable (by rfl : (1:ℝ≥0∞)≤1) + convert! hh using 1 + ext ω + simp only [Function.comp_def,Pi.add_apply,sub_add_cancel] + + +def generator (f : CubicTest) (b : Drift K M) (t x : ℝ) : ℝ := + deriv f.val x*b.val t x+(1/2:ℝ)*iteratedDeriv 2 f.val x + +lemma generator_bound (f : CubicTest) (b : Drift K M) (t x : ℝ) : + ‖generator f b t x‖≤(f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2 := by + apply (norm_add_le _ _).trans + rw [norm_mul,norm_mul,Real.norm_of_nonneg (by norm_num : (0:ℝ)≤1/2)] + have h1 := mul_le_mul (f.bound1 x) (b.bound t x) (norm_nonneg _) f.c1.coe_nonneg + have h2 := mul_le_mul_of_nonneg_left (f.bound2 x) (by norm_num : (0:ℝ)≤1/2) + simp only [Real.norm_eq_abs] at h1 h2 + dsimp [generator] + nlinarith + +lemma mesh_le_one (n : ℕ) : mesh n≤1 := by + dsimp [mesh] + apply (div_le_one (by positivity)).mpr + norm_num + +lemma innovationEuler_generator_step (hZ : iIndepFun Z P) + (hl : ∀ k,HasLaw (Z k) (gaussianReal 0 1) P) + (b : Drift K M) (f : CubicTest) {T : ℝ≥0} (hT : T≤1) (n k : ℕ) : + ‖((∫ ω,f.val (innovationEuler b T n (k+1) (fun j => Z j ω)) ∂P)- + (∫ ω,f.val (innovationEuler b T n k (fun j => Z j ω)) ∂P))- + ((T:ℝ)*mesh n)*(∫ ω,generator f b ((T:ℝ)*grid n k) + (innovationEuler b T n k (fun j => Z j ω)) ∂P)‖≤ + (((T:ℝ)*mesh n)*Real.sqrt ((T:ℝ)*mesh n))* + ((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) := by + let : IsProbabilityMeasure P := (hl 0).isProbabilityMeasure + have hi (k : ℕ) := f.integrable_comp (innovationEuler_memLp hl b T n k + (p:=1) (by norm_num) |>.integrable le_rfl) + have hδ : (T:ℝ)*mesh n≤1 := by + exact (mul_le_mul (show (T:ℝ)≤1 from hT) (mesh_le_one n) (mesh_pos n).le + (by norm_num)).trans_eq (by norm_num) + have hh := weak_step_error (innovationEuler_aemeasurable (fun k => (hl k).aemeasurable) b T n k) + (hl k) (innovationEuler_independent hZ (fun k => (hl k).aemeasurable) b T n k) + f (b.lipschitz ((T:ℝ)*grid n k)).continuous.measurable M (b.bound ((T:ℝ)*grid n k)) + (mul_nonneg T.coe_nonneg (mesh_pos n).le) hδ + rw [←integral_sub (hi (k+1)) (hi k)] + simpa only [generator,innovationEuler,add_assoc] using hh + + +lemma innovationEuler_generator_sum (hZ : iIndepFun Z P) + (hl : ∀ k,HasLaw (Z k) (gaussianReal 0 1) P) + (b : Drift K M) (f : CubicTest) {T : ℝ≥0} (hT : T≤1) (n N : ℕ) : + ‖((∫ ω,f.val (innovationEuler b T n N (fun j => Z j ω)) ∂P)-f.val 0)- + ((T:ℝ)*mesh n)*(∑ k∈Finset.range N,∫ ω,generator f b ((T:ℝ)*grid n k) + (innovationEuler b T n k (fun j => Z j ω)) ∂P)‖≤ + (N:ℝ)*(((T:ℝ)*mesh n)*Real.sqrt ((T:ℝ)*mesh n))* + ((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) := by + let : IsProbabilityMeasure P := (hl 0).isProbabilityMeasure + have he : ((∫ ω,f.val (innovationEuler b T n N (fun j => Z j ω)) ∂P)-f.val 0)- + ((T:ℝ)*mesh n)*(∑ k∈Finset.range N,∫ ω,generator f b ((T:ℝ)*grid n k) + (innovationEuler b T n k (fun j => Z j ω)) ∂P)= + ∑ k∈Finset.range N, (((∫ ω,f.val (innovationEuler b T n (k+1) (fun j => Z j ω)) ∂P)- + (∫ ω,f.val (innovationEuler b T n k (fun j => Z j ω)) ∂P))- + ((T:ℝ)*mesh n)*(∫ ω,generator f b ((T:ℝ)*grid n k) + (innovationEuler b T n k (fun j => Z j ω)) ∂P)) := by + rw [Finset.sum_sub_distrib, + Finset.sum_range_sub (fun k => ∫ ω,f.val (innovationEuler b T n k (fun j => Z j ω)) ∂P), + ←Finset.mul_sum] + simp [innovationEuler] + rw [he] + exact (norm_sum_le _ _).trans ((Finset.sum_le_sum (fun k _ => + innovationEuler_generator_step hZ hl b f hT n k)).trans_eq (by simp;ring)) + +end ParisiPath + +namespace ParisiPath +open ProbabilityTheory +open scoped BigOperators ENNReal +variable {K M : ℝ≥0} + + +def frozenEuler (b : Drift K M) (W : Path) (n : ℕ) (t : ℝ) : ℝ := + euler b W n ⌊t*(n+1:ℕ)⌋₊ + +lemma freeze_index_le (n : ℕ) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : + ⌊t*(n+1:ℕ)⌋₊≤n+1 := by + exact_mod_cast (Nat.floor_le (mul_nonneg ht.1 (by positivity))).trans + (show t*(n+1:ℕ)≤(n+1:ℕ) by simpa only [one_mul] using + mul_le_mul_of_nonneg_right ht.2 (Nat.cast_nonneg (n+1))) + +lemma frozenEuler_tendsto (b : Drift K M) (W : Path) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ContinuousAt (fun s => b.val s (extend (solution b W) s)) t) + {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : + Tendsto (fun n => frozenEuler b W n t) atTop (𝓝 (extend (solution b W) t)) := by + have h0 : Tendsto (fun n => frozenEuler b W n t- + extend (solution b W) (freeze n t)) atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + apply squeeze_zero (fun _ => norm_nonneg _) + (fun n => euler_error_bound b W n _ (freeze_index_le n ht)) + simpa only [zero_mul] using (totalResidual_tendsto_zero b (solution b W) hc).mul_const + (Real.exp (K:ℝ)) + have h1 := (continuous_extend (solution b W)).continuousAt.tendsto.comp (freeze_tendsto ht.1) + simpa only [Function.comp_def,sub_add_cancel,zero_add] using h0.add h1 + +lemma reference_ae_continuous_of_joint (b : Drift K M) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ∀ x : ℝ, ContinuousAt (uncurry b.val) (t,x)) (X : Path) : + ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ContinuousAt (fun s => b.val s (extend X s)) t := by + filter_upwards [hc] with t ht hmem + exact (ht hmem (extend X t)).comp (f := fun s : ℝ => (s,extend X s)) + (continuous_id.continuousAt.prodMk + (continuous_extend X).continuousAt) + +section Brownian +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + + +def brownianPath (W : ℝ≥0 → Ω → ℝ) (ω : Ω) : Path := + ContinuousMap.mkD (fun t : Time => W ⟨t,t.property.1⟩ ω) 0 + +lemma brownianPath_eq_ae (hW : IsBrownianReal W P) : + ∀ᵐ ω ∂P, ∀ t : Time, brownianPath W ω t = W ⟨t,t.property.1⟩ ω := by + filter_upwards [hW.cont] with ω hω + have hc : Continuous (fun t : Time => W ⟨t,t.property.1⟩ ω) := + hω.comp (continuous_subtype_val.subtype_mk _) + intro t + exact ContinuousMap.mkD_apply_of_continuous hc + +lemma brownianPath_aemeasurable_eval (hW : IsBrownianReal W P) (t : Time) : + AEMeasurable (fun ω => brownianPath W ω t) P := + (hW.aemeasurable ⟨t,t.property.1⟩).congr + ((brownianPath_eq_ae hW).mono fun _ hω => (hω t).symm) + +lemma innovationEuler_eq_euler (hW : IsBrownianReal W P) (b : Drift K M) (n : ℕ) : + ∀ᵐ ω ∂P, ∀ k : ℕ,k≤n+1 → + innovationEuler b 1 n k (fun j => standardStep W 1 n j ω)= + euler b (brownianPath W ω) n k := by + filter_upwards [brownianPath_eq_ae hW,hW.eval_zero_ae_eq_zero] with ω hω h0 + intro k hk + induction k with + | zero => + simp only [innovationEuler,euler,extend_of_mem _ (show (0:ℝ)∈Icc (0:ℝ) 1 by simp)] + rw [hω] + exact h0.symm + | succ k ih => + rw [innovationEuler,euler,ih (by omega)] + have hg (j : ℕ) (hj : j≤n+1) : extend (brownianPath W ω) (grid n j)= + W (horizonGrid 1 n j) ω := by + rw [extend_of_mem _ (grid_mem n j hj),hω] + congr 1 + apply NNReal.coe_injective + change grid n j=(1:ℝ)*grid n j + ring + rw [hg _ hk,hg _ (by omega)] + simp only [NNReal.coe_one,one_mul,standardStep] + have hs : Real.sqrt (mesh n)≠0 := (Real.sqrt_pos.mpr (mesh_pos n)).ne' + field_simp + ring + +lemma brownian_solution_integrable (hW : IsBrownianReal W P) (b : Drift K M) (t : Time) : + Integrable (fun ω => solution b (brownianPath W ω) t) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hd : Integrable (fun ω => solution b (brownianPath W ω) t-brownianPath W ω t) P := + Integrable.of_bound ((aemeasurable_solution_eval b (brownianPath W) + (brownianPath_aemeasurable_eval hW) t).sub (brownianPath_aemeasurable_eval hW t)).aestronglyMeasurable + ((M:ℝ)*(t:ℝ)) (ae_of_all _ fun ω => norm_solution_sub_driver b (brownianPath W ω) t) + have hw : Integrable (fun ω => brownianPath W ω t) P := + (hW.integrable_eval ⟨t,t.property.1⟩).congr + ((brownianPath_eq_ae hW).mono fun ω hω => (hω t).symm) + convert! hd.add hw using 1 + ext ω + simp only [Pi.add_apply,sub_add_cancel] + +lemma generator_aemeasurable (hW : IsBrownianReal W P) (b : Drift K M) (f : CubicTest) + (t : ℝ) : AEMeasurable (fun ω => generator f b t (extend (solution b (brownianPath W ω)) t)) P := by + have hx := aemeasurable_solution_eval b (brownianPath W) + (brownianPath_aemeasurable_eval hW) (projIcc 0 1 zero_le_one t) + exact ((f.continuous_d1.measurable.comp_aemeasurable hx).mul + ((b.lipschitz t).continuous.measurable.comp_aemeasurable hx)).add + ((f.continuous_d2.measurable.comp_aemeasurable hx).const_mul (1/2:ℝ)) + +lemma generator_frozen_aemeasurable (hW : IsBrownianReal W P) (b : Drift K M) (f : CubicTest) + (n : ℕ) (t : ℝ) : AEMeasurable (fun ω => generator f b (freeze n t) + (frozenEuler b (brownianPath W ω) n t)) P := by + have hx := aemeasurable_euler b (brownianPath W) (brownianPath_aemeasurable_eval hW) + n ⌊t*(n+1:ℕ)⌋₊ + exact ((f.continuous_d1.measurable.comp_aemeasurable hx).mul + ((b.lipschitz _).continuous.measurable.comp_aemeasurable hx)).add + ((f.continuous_d2.measurable.comp_aemeasurable hx).const_mul (1/2:ℝ)) + + +def expectedFrozenGenerator (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : CubicTest) (n : ℕ) (t : ℝ) : ℝ := + ∫ ω,generator f b (freeze n t) (frozenEuler b (brownianPath W ω) n t) ∂P + +def expectedGenerator (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : CubicTest) (t : ℝ) : ℝ := + ∫ ω,generator f b t (extend (solution b (brownianPath W ω)) t) ∂P + +lemma expectedFrozenGenerator_measurable (b : Drift K M) (f : CubicTest) (n : ℕ) : + Measurable (expectedFrozenGenerator P W b f n) := + (measurable_of_countable (f:=fun k : ℕ => ∫ ω,generator f b (grid n k) + (euler b (brownianPath W ω) n k) ∂P)).comp (by fun_prop) + +lemma expectedGenerator_bound (hW : IsBrownianReal W P) (b : Drift K M) (f : CubicTest) (t : ℝ) : + ‖expectedGenerator P W b f t‖≤(f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2 := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (ae_of_all _ fun ω => generator_bound f b t _)).trans_eq + (by simp) + +lemma expectedFrozenGenerator_bound (hW : IsBrownianReal W P) (b : Drift K M) (f : CubicTest) (n : ℕ) (t : ℝ) : + ‖expectedFrozenGenerator P W b f n t‖≤(f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2 := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (ae_of_all _ fun ω => generator_bound f b (freeze n t) _)).trans_eq + (by simp) + +lemma expectedFrozenGenerator_tendsto (hW : IsBrownianReal W P) (b : Drift K M) (f : CubicTest) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ∀ x : ℝ, ContinuousAt (uncurry b.val) (t,x)) : + ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → Tendsto (fun n => expectedFrozenGenerator P W b f n t) + atTop (𝓝 (expectedGenerator P W b f t)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + filter_upwards [hc] with t ht hmem + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + (fun n => (generator_frozen_aemeasurable hW b f n t).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => generator_bound f b _ _) + exact ae_of_all _ fun ω => by + have hx := frozenEuler_tendsto b (brownianPath W ω) + (reference_ae_continuous_of_joint b hc _) hmem + have hd := (ht hmem _).tendsto.comp ((freeze_tendsto hmem.1).prodMk_nhds hx) + exact ((f.continuous_d1.continuousAt.tendsto.comp hx).mul hd).add + ((f.continuous_d2.continuousAt.tendsto.comp hx).const_mul (1/2:ℝ)) + +end Brownian +end ParisiPath + +namespace ParisiPath +open ProbabilityTheory +open scoped BigOperators ENNReal +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma expectedFrozenGenerator_intervalIntegrable (hW : IsBrownianReal W P) + (b : Drift K M) (f : CubicTest) (n : ℕ) (a c : ℝ) : + IntervalIntegrable (expectedFrozenGenerator P W b f n) volume a c := by + apply (intervalIntegrable_const (c := (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2)).mono_fun' + (expectedFrozenGenerator_measurable b f n).aestronglyMeasurable + exact Eventually.of_forall fun t => expectedFrozenGenerator_bound hW b f n t + +lemma expectedFrozenGenerator_integral_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : CubicTest) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ∀ x : ℝ, ContinuousAt (uncurry b.val) (t,x)) : + Tendsto (fun n => ∫ t in (0:ℝ)..1, expectedFrozenGenerator P W b f n t) + atTop (𝓝 (∫ t in (0:ℝ)..1,expectedGenerator P W b f t)) := by + refine intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + (Eventually.of_forall fun n => (expectedFrozenGenerator_measurable b f n).aestronglyMeasurable.restrict) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => expectedFrozenGenerator_bound hW b f n t) + (intervalIntegrable_const) ?_ + filter_upwards [expectedFrozenGenerator_tendsto hW b f hc] with t ht hmem + rw [uIoc_of_le zero_le_one] at hmem + exact ht ⟨hmem.1.le,hmem.2⟩ + +lemma freeze_index_on_cell (n k : ℕ) {t : ℝ} + (ht : t ∈ Ico (grid n k) (grid n (k+1))) : ⌊t*(n+1:ℕ)⌋₊=k := by + have h := freeze_on_cell n k ht + dsimp only [freeze,grid] at h + exact Nat.cast_injective (mul_right_cancel₀ (mesh_pos n).ne' h) + +lemma expectedFrozenGenerator_cell_integral (_hW : IsBrownianReal W P) + (b : Drift K M) (f : CubicTest) (n k : ℕ) : + (∫ t in (grid n k)..(grid n (k+1)),expectedFrozenGenerator P W b f n t)= + mesh n*(∫ ω,generator f b (grid n k) (euler b (brownianPath W ω) n k) ∂P) := by + have hnot : ∀ᵐ s ∂volume,s≠grid n (k+1) := by simp [ae_iff,measure_singleton] + calc + _ = ∫ _ in (grid n k)..(grid n (k+1)), + (∫ ω,generator f b (grid n k) (euler b (brownianPath W ω) n k) ∂P) := by + apply intervalIntegral.integral_congr_ae + filter_upwards [hnot] with t ht hmem + rw [uIoc_of_le (grid_mono n (Nat.le_succ k))] at hmem + have hcell : t∈Ico (grid n k) (grid n (k+1)) := ⟨hmem.1.le,hmem.2.lt_of_ne ht⟩ + simp only [expectedFrozenGenerator,frozenEuler,freeze_on_cell n k hcell, + freeze_index_on_cell n k hcell] + _ = _ := by rw [intervalIntegral.integral_const,grid_succ];simp + +lemma expectedFrozenGenerator_integral_eq_sum (hW : IsBrownianReal W P) + (b : Drift K M) (f : CubicTest) (n : ℕ) : + (∫ t in (0:ℝ)..1,expectedFrozenGenerator P W b f n t)= + mesh n*(∑ k∈Finset.range (n+1),∫ ω,generator f b (grid n k) + (euler b (brownianPath W ω) n k) ∂P) := by + rw [Finset.mul_sum] + simp_rw [← expectedFrozenGenerator_cell_integral hW b f n] + rw [intervalIntegral.sum_integral_adjacent_intervals + (fun k _ => expectedFrozenGenerator_intervalIntegrable hW b f n _ _),grid_zero,grid_end] + +lemma brownianEuler_weak_error (hW : IsBrownianReal W P) + (b : Drift K M) (f : CubicTest) (n : ℕ) : + ‖(∫ ω,f.val (euler b (brownianPath W ω) n (n+1)) ∂P)-f.val 0- + (∫ t in (0:ℝ)..1,expectedFrozenGenerator P W b f n t)‖≤ + Real.sqrt (mesh n)*((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) := by + have he := innovationEuler_eq_euler hW b n + have hh := innovationEuler_generator_sum (standardStep_independent hW 1 n) + (standardStep_hasLaw hW (by norm_num : (0:ℝ≥0)<1) n) b f (by norm_num : (1:ℝ≥0)≤1) n (n+1) + have hf : (∫ ω,f.val (innovationEuler b 1 n (n+1) (fun j => standardStep W 1 n j ω)) ∂P)= + (∫ ω,f.val (euler b (brownianPath W ω) n (n+1)) ∂P) := + integral_congr_ae (he.mono fun ω hω => congrArg f.val (hω (n+1) le_rfl)) + have hg : (∑ k∈Finset.range (n+1),∫ ω,generator f b (grid n k) + (innovationEuler b 1 n k (fun j => standardStep W 1 n j ω)) ∂P)= + ∑ k∈Finset.range (n+1),∫ ω,generator f b (grid n k) + (euler b (brownianPath W ω) n k) ∂P := by + apply Finset.sum_congr rfl + intro k hk + exact integral_congr_ae (he.mono fun ω hω => congrArg (generator f b (grid n k)) + (hω k (Finset.mem_range.mp hk).le)) + simp only [NNReal.coe_one,one_mul] at hh + rw [hf,hg,←expectedFrozenGenerator_integral_eq_sum hW b f n] at hh + have hn : (n+1:ℕ)*mesh n=1 := grid_end n + convert hh using 1 + rw [←mul_assoc,hn,one_mul] + +lemma brownianEuler_integrable (hW : IsBrownianReal W P) (b : Drift K M) (n : ℕ) : + Integrable (fun ω => euler b (brownianPath W ω) n (n+1)) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply (innovationEuler_memLp (standardStep_hasLaw hW (by norm_num : (0:ℝ≥0)<1) n) + b 1 n (n+1) (p:=1) (by norm_num) |>.integrable le_rfl).congr + exact (innovationEuler_eq_euler hW b n).mono fun ω hω => hω (n+1) le_rfl + +lemma brownianEuler_expected_test_tendsto (hW : IsBrownianReal W P) (b : Drift K M) (f : CubicTest) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ∀ x : ℝ, ContinuousAt (uncurry b.val) (t,x)) : + Tendsto (fun n => ∫ ω,f.val (euler b (brownianPath W ω) n (n+1)) ∂P) atTop + (𝓝 (∫ ω,f.val (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let X (ω : Ω) := solution b (brownianPath W ω) ⟨1,by simp⟩ + have hx : Integrable (fun ω => f.val (X ω)) P := f.integrable_comp (brownian_solution_integrable hW b _) + have hn (n : ℕ) := f.integrable_comp (brownianEuler_integrable hW b n) + have hlim : Tendsto (fun n => ∫ ω,(f.val (euler b (brownianPath W ω) n (n+1))-f.val (X ω)) ∂P) + atTop (𝓝 0) := by + have hh := tendsto_integral_of_dominated_convergence (μ:=P) + (F:=fun n ω => f.val (euler b (brownianPath W ω) n (n+1))-f.val (X ω)) (f:=fun _=> (0:ℝ)) + (fun _ => (f.c1:ℝ)*(2*(M:ℝ))) (fun n => ((hn n).sub hx).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => ?_) (ae_of_all _ fun ω => ?_) + · simpa only [integral_zero] using hh + · calc + _ ≤ (f.c1:ℝ)*‖euler b (brownianPath W ω) n (n+1)-X ω‖ := f.lipschitz.norm_sub_le _ _ + _ ≤ _ := by + apply mul_le_mul_of_nonneg_left _ f.c1.coe_nonneg + simpa only [grid_end,extend_of_mem _ (show (1:ℝ)∈Icc (0:ℝ) 1 by simp),X] using + euler_error_uniform_bound b (brownianPath W ω) n (n+1) le_rfl + · have hs := euler_terminal_tendsto b (brownianPath W ω) (reference_ae_continuous_of_joint b hc _) + have ht := (f.continuous.continuousAt.tendsto.comp hs).sub_const (f.val (X ω)) + simpa only [Function.comp_def,extend_of_mem _ (show (1:ℝ)∈Icc (0:ℝ) 1 by simp),X,sub_self] using ht + simp_rw [integral_sub (hn _) hx] at hlim + simpa only [sub_add_cancel,zero_add] using hlim.add_const (∫ ω,f.val (X ω) ∂P) + +lemma mesh_tendsto_zero : Tendsto mesh atTop (𝓝 0) := by + change Tendsto (fun n : ℕ => (1:ℝ)/(n+1:ℕ)) atTop (𝓝 0) + simpa only [Nat.cast_add,Nat.cast_one] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)) + + + +theorem brownian_solution_generator_identity (hW : IsBrownianReal W P) + (b : Drift K M) (f : CubicTest) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ∀ x : ℝ, ContinuousAt (uncurry b.val) (t,x)) : + (∫ ω,f.val (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)-f.val 0= + ∫ t in (0:ℝ)..1,expectedGenerator P W b f t := by + have he : Tendsto (fun n => (∫ ω,f.val (euler b (brownianPath W ω) n (n+1)) ∂P)-f.val 0- + (∫ t in (0:ℝ)..1,expectedFrozenGenerator P W b f n t)) atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + apply squeeze_zero (fun _ => norm_nonneg _) (brownianEuler_weak_error hW b f) + simpa only [Real.sqrt_zero,zero_mul] using (mesh_tendsto_zero.sqrt).mul_const + ((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) + exact sub_eq_zero.mp (tendsto_nhds_unique + (((brownianEuler_expected_test_tendsto hW b f hc).sub_const (f.val 0)).sub + (expectedFrozenGenerator_integral_tendsto hW b f hc)) he) + +end ParisiPath + +open ContinuousLinearMap +open scoped Convolution +namespace ParisiPath + +structure QuadraticTest where + val : ℝ → ℝ + d1 : ℝ → ℝ + d2 : ℝ → ℝ + hasD1 : ∀ x, HasDerivAt val (d1 x) x + hasD2 : ∀ x, HasDerivAt d1 (d2 x) x + continuousD2 : Continuous d2 + c1 : ℝ≥0 + c2 : ℝ≥0 + bound1 : ∀ x, ‖d1 x‖ ≤ c1 + bound2 : ∀ x, ‖d2 x‖ ≤ c2 + +namespace QuadraticTest +lemma continuous (f : QuadraticTest) : Continuous f.val := + continuous_iff_continuousAt.mpr fun x => (f.hasD1 x).continuousAt +lemma continuous_d1 (f : QuadraticTest) : Continuous f.d1 := + continuous_iff_continuousAt.mpr fun x => (f.hasD2 x).continuousAt +lemma lipschitz (f : QuadraticTest) : LipschitzWith f.c1 f.val := by + apply lipschitzWith_of_nnnorm_deriv_le (fun x => (f.hasD1 x).differentiableAt) + intro x + rw [(f.hasD1 x).deriv] + exact_mod_cast f.bound1 x +end QuadraticTest + +def smoothConvolution (φ : ContDiffBump (0:ℝ)) (f : ℝ → ℝ) : ℝ → ℝ := + φ.normed volume ⋆[lsmul ℝ ℝ,volume] f + +lemma smoothConvolution_eq (φ : ContDiffBump (0:ℝ)) (f : ℝ → ℝ) (x : ℝ) : + smoothConvolution φ f x = ∫ z,φ.normed volume z * f (x-z) := rfl + +lemma smoothConvolution_integrable (φ : ContDiffBump (0:ℝ)) {f : ℝ → ℝ} + (hf : Continuous f) (x : ℝ) : Integrable (fun z => φ.normed volume z * f (x-z)) := + φ.hasCompactSupport_normed.convolutionExists_left (lsmul ℝ ℝ) φ.continuous_normed + hf.locallyIntegrable x + +lemma hasDerivAt_smoothConvolution (φ : ContDiffBump (0:ℝ)) {f g : ℝ → ℝ} + (hf : Continuous f) (hg : Continuous g) (hd : ∀ x,HasDerivAt f (g x) x) + {C : ℝ≥0} (hb : ∀ x,‖g x‖≤C) (x₀ : ℝ) : + HasDerivAt (smoothConvolution φ f) (smoothConvolution φ g x₀) x₀ := by + change HasDerivAt (fun x => ∫ z,φ.normed volume z * f (x-z)) + (∫ z,φ.normed volume z * g (x₀-z)) x₀ + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball x₀ 1) (bound := fun z => φ.normed volume z * C) + (F' := fun x z => φ.normed volume z*g (x-z)) + (Metric.ball_mem_nhds _ zero_lt_one) ?_ ?_ ?_ ?_ ?_ ?_).2 + · exact Eventually.of_forall fun x => + (φ.continuous_normed.mul (hf.comp (continuous_const.sub continuous_id))).aestronglyMeasurable + · exact smoothConvolution_integrable φ hf x₀ + · exact (φ.continuous_normed.mul (hg.comp (continuous_const.sub continuous_id))).aestronglyMeasurable + · exact ae_of_all _ fun z x _ => by + rw [norm_mul,Real.norm_of_nonneg (φ.nonneg_normed z)] + exact mul_le_mul_of_nonneg_left (hb _) (φ.nonneg_normed z) + · exact φ.integrable_normed.mul_const _ + · exact ae_of_all _ fun z x _ => by + convert! ((hd (x-z)).comp x ((hasDerivAt_id x).sub_const z)).const_mul + (φ.normed volume z) using 1 + first | rfl | simp only [mul_one] + +lemma smoothConvolution_bound (φ : ContDiffBump (0:ℝ)) {g : ℝ → ℝ} + (hg : Continuous g) {C : ℝ≥0} (hb : ∀ x,‖g x‖≤C) (x : ℝ) : + ‖smoothConvolution φ g x‖≤C := by + rw [smoothConvolution_eq] + calc + _ ≤ ∫ z,‖φ.normed volume z*g (x-z)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ z,φ.normed volume z*C := by + apply integral_mono (smoothConvolution_integrable φ hg x).norm + (φ.integrable_normed.mul_const _) + intro z + dsimp only + rw [norm_mul,Real.norm_of_nonneg (φ.nonneg_normed z)] + exact mul_le_mul_of_nonneg_left (hb _) (φ.nonneg_normed z) + _ = C := by rw [integral_mul_const,φ.integral_normed,one_mul] + +lemma smoothConvolution_smooth (φ : ContDiffBump (0:ℝ)) {f : ℝ → ℝ} + (hf : Continuous f) : ContDiff ℝ 3 (smoothConvolution φ f) := + φ.hasCompactSupport_normed.contDiff_convolution_left (lsmul ℝ ℝ) φ.contDiff_normed + hf.locallyIntegrable + +lemma smoothConvolution_d1 (φ : ContDiffBump (0:ℝ)) (f : QuadraticTest) : + deriv (smoothConvolution φ f.val)=smoothConvolution φ f.d1 := by + funext x + exact (hasDerivAt_smoothConvolution φ f.continuous f.continuous_d1 f.hasD1 f.bound1 x).deriv + +lemma smoothConvolution_d2 (φ : ContDiffBump (0:ℝ)) (f : QuadraticTest) : + iteratedDeriv 2 (smoothConvolution φ f.val)=smoothConvolution φ f.d2 := by + rw [iteratedDeriv_succ,iteratedDeriv_one,smoothConvolution_d1] + funext x + exact (hasDerivAt_smoothConvolution φ f.continuous_d1 f.continuousD2 f.hasD2 f.bound2 x).deriv + +lemma smoothConvolution_d3 (φ : ContDiffBump (0:ℝ)) (f : QuadraticTest) : + iteratedDeriv 3 (smoothConvolution φ f.val)= + (deriv (φ.normed volume) ⋆[lsmul ℝ ℝ,volume] f.d2) := by + rw [show (3:ℕ)=2+1 by rfl,iteratedDeriv_succ,smoothConvolution_d2] + funext x + exact (φ.hasCompactSupport_normed.hasDerivAt_convolution_left (lsmul ℝ ℝ) + φ.contDiff_normed f.continuousD2.locallyIntegrable x).deriv + +lemma smoothConvolution_d3_bound (φ : ContDiffBump (0:ℝ)) (f : QuadraticTest) (x : ℝ) : + ‖iteratedDeriv 3 (smoothConvolution φ f.val) x‖≤ + (∫ z,‖deriv (φ.normed volume) z‖)*(f.c2:ℝ) := by + rw [smoothConvolution_d3] + change ‖∫ z,deriv (φ.normed volume) z*f.d2 (x-z)‖≤_ + have hkc : Continuous (deriv (φ.normed volume)) := + (φ.contDiff_normed (n:=1)).continuous_deriv (by norm_num) + have hk := (φ.hasCompactSupport_normed (μ:=volume)).deriv + calc + _ ≤ ∫ z,‖deriv (φ.normed volume) z*f.d2 (x-z)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ z,‖deriv (φ.normed volume) z‖*(f.c2:ℝ) := by + apply integral_mono + (hk.convolutionExists_left (lsmul ℝ ℝ) hkc f.continuousD2.locallyIntegrable x).norm + (hkc.integrable_of_hasCompactSupport hk |>.norm.mul_const _) + intro z + dsimp only + rw [lsmul_apply,smul_eq_mul,norm_mul] + exact mul_le_mul_of_nonneg_left (f.bound2 _) (norm_nonneg _) + _ = _ := integral_mul_const _ _ + +def QuadraticTest.mollify (f : QuadraticTest) (φ : ContDiffBump (0:ℝ)) : CubicTest where + val := smoothConvolution φ f.val + smooth := smoothConvolution_smooth φ f.continuous + c1 := f.c1 + c2 := f.c2 + c3 := ⟨(∫ z,‖deriv (φ.normed volume) z‖)*(f.c2:ℝ),by positivity⟩ + bound1 := fun x => by simpa only [smoothConvolution_d1] using + smoothConvolution_bound φ f.continuous_d1 f.bound1 x + bound2 := fun x => by simpa only [smoothConvolution_d2] using + smoothConvolution_bound φ f.continuousD2 f.bound2 x + bound3 := smoothConvolution_d3_bound φ f + + +def shrinkingBump (n : ℕ) : ContDiffBump (0:ℝ) where + rIn := (1:ℝ)/(n+1:ℕ)/2 + rOut := (1:ℝ)/(n+1:ℕ) + rIn_pos := by positivity + rIn_lt_rOut := by + have h : 0 < (1:ℝ)/(n+1:ℕ) := by positivity + linarith + +lemma shrinkingBump_tendsto : Tendsto (fun n => (shrinkingBump n).rOut) atTop (𝓝 0) := by + simpa only [shrinkingBump,Nat.cast_add,Nat.cast_one] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)) + +lemma smoothConvolution_tendsto {f : ℝ → ℝ} (hf : Continuous f) (x : ℝ) : + Tendsto (fun n => smoothConvolution (shrinkingBump n) f x) atTop (𝓝 (f x)) := + ContDiffBump.convolution_tendsto_right_of_continuous shrinkingBump_tendsto hf x + +lemma smoothConvolution_error {C : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith C f) + (φ : ContDiffBump (0:ℝ)) (x : ℝ) : + ‖smoothConvolution φ f x-f x‖≤(C:ℝ)*φ.rOut := by + rw [←dist_eq_norm] + apply φ.dist_normed_convolution_le hf.continuous.aestronglyMeasurable + intro y hy + exact (hf.dist_le_mul y x).trans + (mul_le_mul_of_nonneg_left (Metric.mem_ball.mp hy).le C.coe_nonneg) + +end ParisiPath + +namespace ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma QuadraticTest.integrable_comp (f : QuadraticTest) {X : Ω → ℝ} + (hX : Integrable X P) [IsProbabilityMeasure P] : Integrable (fun ω => f.val (X ω)) P := by + have hLip : LipschitzWith f.c1 (fun x => f.val x-f.val 0) := by + intro x y + simpa only [edist_sub_right] using f.lipschitz x y + have h := hLip.comp_memLp (by simp) ((memLp_one_iff_integrable).mpr hX) + have hh := (h.add (memLp_const (f.val 0))).integrable (by rfl : (1:ℝ≥0∞)≤1) + convert! hh using 1 + ext ω + simp only [Function.comp_def,Pi.add_apply,sub_add_cancel] + +lemma mollify_expected_test_tendsto (f : QuadraticTest) {X : Ω → ℝ} + (hX : Integrable X P) [IsProbabilityMeasure P] : + Tendsto (fun n => ∫ ω,(f.mollify (shrinkingBump n)).val (X ω) ∂P) atTop + (𝓝 (∫ ω,f.val (X ω) ∂P)) := by + have hn (n : ℕ) := (f.mollify (shrinkingBump n)).integrable_comp hX + have hh := f.integrable_comp hX + apply tendsto_iff_norm_sub_tendsto_zero.mpr + apply squeeze_zero (fun _ => norm_nonneg _) (fun n => ?_) + (show Tendsto (fun n => (f.c1:ℝ)*(shrinkingBump n).rOut) atTop (𝓝 0) from + by simpa only [mul_zero] using shrinkingBump_tendsto.const_mul (f.c1:ℝ)) + rw [←integral_sub (hn n) hh] + exact (norm_integral_le_of_norm_le_const (ae_of_all _ fun ω => + smoothConvolution_error f.lipschitz (shrinkingBump n) (X ω))).trans_eq (by simp) + +lemma expectedGenerator_aestronglyMeasurable (hW : IsBrownianReal W P) + (b : Drift K M) (f : CubicTest) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ∀ x : ℝ, ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (expectedGenerator P W b f) (volume.restrict (Ioc (0:ℝ) 1)) := by + apply aestronglyMeasurable_of_tendsto_ae atTop + (fun n => (expectedFrozenGenerator_measurable (P:=P) (W:=W) b f n).aestronglyMeasurable.restrict) + filter_upwards [ae_restrict_of_ae (expectedFrozenGenerator_tendsto hW b f hc), + ae_restrict_mem measurableSet_Ioc] with t ht hmem + exact ht ⟨hmem.1.le,hmem.2⟩ + +def generatorC2 (f : QuadraticTest) (b : Drift K M) (t x : ℝ) : ℝ := + f.d1 x*b.val t x+(1/2:ℝ)*f.d2 x + +def expectedGeneratorC2 (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : QuadraticTest) (t : ℝ) : ℝ := + ∫ ω,generatorC2 f b t (extend (solution b (brownianPath W ω)) t) ∂P + +lemma mollify_generator_tendsto (b : Drift K M) (f : QuadraticTest) (t x : ℝ) : + Tendsto (fun n => generator (f.mollify (shrinkingBump n)) b t x) atTop + (𝓝 (generatorC2 f b t x)) := by + simp only [generator,QuadraticTest.mollify,smoothConvolution_d1,smoothConvolution_d2] + exact ((smoothConvolution_tendsto f.continuous_d1 x).mul_const (b.val t x)).add + ((smoothConvolution_tendsto f.continuousD2 x).const_mul (1/2:ℝ)) + +lemma mollify_expectedGenerator_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : QuadraticTest) (t : ℝ) : + Tendsto (fun n => expectedGenerator P W b (f.mollify (shrinkingBump n)) t) atTop + (𝓝 (expectedGeneratorC2 P W b f t)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + (fun n => (generator_aemeasurable hW b (f.mollify (shrinkingBump n)) t).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => generator_bound _ b _ _) + exact ae_of_all _ fun ω => mollify_generator_tendsto b f t _ + +lemma mollify_generator_integral_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : QuadraticTest) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ∀ x : ℝ, ContinuousAt (uncurry b.val) (t,x)) : + Tendsto (fun n => ∫ t in (0:ℝ)..1,expectedGenerator P W b (f.mollify (shrinkingBump n)) t) + atTop (𝓝 (∫ t in (0:ℝ)..1,expectedGeneratorC2 P W b f t)) := by + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + (Eventually.of_forall fun n => ?_) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => expectedGenerator_bound hW b _ t) + (intervalIntegrable_const) (ae_of_all _ fun t _ => mollify_expectedGenerator_tendsto hW b f t) + rw [uIoc_of_le zero_le_one] + exact expectedGenerator_aestronglyMeasurable hW b _ hc + + + +theorem brownian_solution_generator_identity_C2 (hW : IsBrownianReal W P) + (b : Drift K M) (f : QuadraticTest) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ∀ x : ℝ, ContinuousAt (uncurry b.val) (t,x)) : + (∫ ω,f.val (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)-f.val 0= + ∫ t in (0:ℝ)..1,expectedGeneratorC2 P W b f t := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hv := mollify_expected_test_tendsto f (brownian_solution_integrable hW b ⟨1,by simp⟩) + have h0 := smoothConvolution_tendsto f.continuous 0 + have he : (fun n => (∫ ω,(f.mollify (shrinkingBump n)).val + (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)-(f.mollify (shrinkingBump n)).val 0)= + (fun n => ∫ t in (0:ℝ)..1,expectedGenerator P W b (f.mollify (shrinkingBump n)) t) := by + funext n + exact brownian_solution_generator_identity hW b _ hc + exact tendsto_nhds_unique (hv.sub h0) (he ▸ mollify_generator_integral_tendsto hW b f hc) + +end ParisiPath + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/InsertionApprox.lean b/lean/OAI/Probability/ParisiFinite/InsertionApprox.lean new file mode 100644 index 0000000000000000000000000000000000000000..b9de17f5a87350248f530f65c3e10c4e3eecc557 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/InsertionApprox.lean @@ -0,0 +1,681 @@ +import Mathlib +import OAI.Probability.ParisiFinite.HugeSelectiveBounded + +namespace OAI + +/-! Insertion Approx. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +namespace PointedTree +open CoherentFock RootSpin +local instance apRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance apRealSMul : SMul ℝ ModeInfinity := apRealModule.toDistribMulAction.toSMul +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r S : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + +theorem insertion_approx (st : PacketStage l r S d spin) (hr : Tendsto r l (𝓝 0)) + (hscale : ∀ᶠ q in l,0≤r q ∧ 0≤S q ∧ S q*r q=1) + (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) : + ApproxPacket l (fun q => (ordinaryLocal (st.word q)).symm + (SpinOperators.act P (ordinaryLocal (st.word q) (vacuum ModeInfinity)))) := by + refine ⟨fun q => (st.low.op q).symm (SpinOperators.act P (st.low.op q (vacuum ModeInfinity))), + st.low.insertion_bounded P,?_⟩ + exact low_insertion_tendsto _ st.low st.ordinary st.special st.phase r S P hP hr hscale + (Eventually.of_forall st.split) (st.special_norm.mono fun _ hq x => (hq x).le) st.ordinary_low + +theorem insertionZ_approx (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (insertionInfinity (st.word q))) := by + simpa only [modeFock_insertion] using st.insertion_approx hr + (hp.mono fun q hq => ⟨hq.le,(inv_pos.mpr hq).le,inv_mul_cancel₀ hq.ne'⟩) Z Z_unitary + +theorem insertionY_approx (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (insertionYInfinity (st.word q))) := by + simpa only [modeFock_insertionY] using st.insertion_approx hr + (hp.mono fun q hq => ⟨hq.le,(inv_pos.mpr hq).le,inv_mul_cancel₀ hq.ne'⟩) Y Y_unitary + + + +theorem huge_transverse_approx (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (ht : t≠0) (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (v q))) : + Tendsto (fun q => ⟪insertionYInfinity (st.forwardWord t q),v q⟫_ℂ) l (𝓝 0) := by + obtain ⟨η,hη,he⟩ := hv + have hh := st.huge_transverse_bounded t ht hr hp η hη + have herr : Tendsto (fun q => ⟪modeFock (insertionYInfinity (st.forwardWord t q)),modeFock (v q)⟫_ℂ- + ⟪modeFock (insertionYInfinity (st.forwardWord t q)),η q⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ he + exact Eventually.of_forall fun q => by + rw [←inner_sub_right] + have hn : ‖modeFock (insertionYInfinity (st.forwardWord t q))‖=1 := by + rw [modeFock.norm_map,insertionYInfinity,norm_insertionInfinity] + simpa only [hn,one_mul] using norm_inner_le_norm (𝕜:=ℂ) + (modeFock (insertionYInfinity (st.forwardWord t q))) (modeFock (v q)-η q) + simpa only [sub_add_cancel,add_zero,modeFock.inner_map_map] using herr.add hh + +theorem forwardCenter_approx (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (d i q))) (i : κ) : + ApproxPacket l (fun q => modeFock (st.forwardCenter t i q)) := by + have he (v : ModeInfinity) : modeFock ((-t) • v)=(((-t):ℝ):ℂ) • modeFock v := by + change modeFock ((((-t):ℝ):ℂ) • v)=_ + exact map_smul _ _ _ + have hv := (st.insertionZ_approx hr hp).smul ((-t:ℝ):ℂ) + unfold forwardCenter signedMode + split_ifs + · simpa only [map_add,he] using (hd i).add hv + · simpa only [map_add,map_neg,he] using (hd i).add hv.neg + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace GramCalculus +open CoherentFock +variable {E F α ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [Fintype ι] {l : Filter α} + + +def combination (d : ι → E) (c : ι → ℂ) : E := ∑i,c i • d i + +theorem combination_add (d : ι → E) (a b : ι → ℂ) : + combination d (a+b)=combination d a+combination d b := by + simp only [combination,Pi.add_apply,add_smul,Finset.sum_add_distrib] + +theorem combination_neg (d : ι → E) (a : ι → ℂ) : + combination d (-a)=-combination d a := by + simp only [combination,Pi.neg_apply,neg_smul,Finset.sum_neg_distrib] + +theorem combination_smul (d : ι → E) (z : ℂ) (a : ι → ℂ) : + combination d (z • a)=z • combination d a := by + simp only [combination,Pi.smul_apply,smul_eq_mul,mul_smul,Finset.smul_sum] + +@[simp] theorem combination_zero (d : ι → E) : combination d 0=0 := by + simp [combination] + +def GramConverges (l : Filter α) (d : α → ι → E) (d₀ : ι → F) : Prop := + ∀i j,Tendsto (fun q => ⟪d q i,d q j⟫_ℂ) l (𝓝 ⟪d₀ i,d₀ j⟫_ℂ) + +namespace GramConverges +variable {d : α → ι → E} {d₀ : ι → F} + +theorem combinations (hg : GramConverges l d d₀) (a b : ι → ℂ) : + Tendsto (fun q => ⟪combination (d q) a,combination (d q) b⟫_ℂ) + l (𝓝 ⟪combination d₀ a,combination d₀ b⟫_ℂ) := by + simp only [combination,sum_inner,inner_sum,inner_smul_left,inner_smul_right,Finset.mul_sum] + apply tendsto_finsetSum + intro i hi + apply tendsto_finsetSum + intro j hj + exact ((hg j i).const_mul (star (a j))).const_mul (b i) + +theorem phase (hg : GramConverges l d d₀) (a b : ι → ℂ) : + Tendsto (fun q => CoherentFock.phase (combination (d q) a) (combination (d q) b)) + l (𝓝 (CoherentFock.phase (combination d₀ a) (combination d₀ b))) := by + have hi := (Complex.continuous_im.tendsto _).comp (hg.combinations a b) + have hr := (Complex.continuous_ofReal.tendsto _).comp hi.neg + exact (Complex.continuous_exp.tendsto _).comp (hr.mul_const Complex.I) + + + +theorem norm_combination (hg : GramConverges l d d₀) (a : ι → ℂ) : + Tendsto (fun q => ‖combination (d q) a‖) l (𝓝 ‖combination d₀ a‖) := by + have hh := tendsto_norm_sq_of_inner (fun q => combination (d q) a) (combination d₀ a) + (hg.combinations a a) + have hs := Real.continuous_sqrt.continuousAt.tendsto.comp hh + simpa only [Function.comp_def,Real.sqrt_sq_eq_abs,abs_norm] using hs + +theorem combination_bounded (hg : GramConverges l d d₀) (a : ι → ℂ) : + ∀ᶠ q in l,‖combination (d q) a‖≤‖combination d₀ a‖+1 := by + exact ((hg.norm_combination a).eventually + (gt_mem_nhds (by linarith : ‖combination d₀ a‖<‖combination d₀ a‖+1))).mono fun _ h => h.le + +end GramConverges + + +theorem spinPacket_reindex {κ ν : Type*} [Fintype κ] [Fintype ν] + (e : κ ≃ ν) (a : ν → Fin 2 → ℂ) (d : ν → E) : + spinPacket (fun i => a (e i)) (fun i => d (e i))=spinPacket a d := by + ext q + simp only [spinPacket_apply] + exact e.sum_comp (fun i => a i q • coherent (d i)) + +end GramCalculus + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace GramCalculus +open CoherentFock PointedTree +variable {E F α ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [Fintype ι] {l : Filter α} + + + +def PacketMatch (l : Filter α) (d : α → ι → E) (d₀ : ι → F) + (x : α → SpinSpace E) (x₀ : SpinSpace F) : Prop := + ∃ (n : ℕ) (a : α → Fin n → Fin 2 → ℂ) (a₀ : Fin n → Fin 2 → ℂ) (c : Fin n → ι → ℂ), + (∀q,x q=spinPacket (a q) (fun i => combination (d q) (c i))) ∧ + x₀=spinPacket a₀ (fun i => combination d₀ (c i)) ∧ + (∀i j,Tendsto (fun q => a q i j) l (𝓝 (a₀ i j))) + +namespace PacketMatch +variable {d : α → ι → E} {d₀ : ι → F} {x y : α → SpinSpace E} {x₀ y₀ : SpinSpace F} + +theorem vacuum : PacketMatch l d d₀ (fun _ => PointedTree.vacuum E) (PointedTree.vacuum F) := by + refine ⟨1,fun _ _ _ => spinCoefficient,fun _ _ => spinCoefficient,fun _ => 0,?_,?_,?_⟩ + · intro q; ext i; simp [spinPacket_apply,vacuum_apply,spinCoefficient] + · ext i; simp [spinPacket_apply,vacuum_apply,spinCoefficient] + · exact fun _ _ => tendsto_const_nhds + +theorem root (hx : PacketMatch l d d₀ x x₀) (P : Matrix (Fin 2) (Fin 2) ℂ) : + PacketMatch l d d₀ (fun q => SpinOperators.act P (x q)) (SpinOperators.act P x₀) := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + refine ⟨n,fun t i q => ∑j,P q j*a t i j,fun i q => ∑j,P q j*a₀ i j,c,?_,?_,?_⟩ + · intro q; dsimp only; rw [hx,act_spinPacket] + · rw [hx₀,act_spinPacket] + · intro i q + exact tendsto_finsetSum _ fun j _ => (ha i j).const_mul (P q j) + +theorem smul (hx : PacketMatch l d d₀ x x₀) (z : ℂ) : + PacketMatch l d d₀ (fun q => z • x q) (z • x₀) := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + refine ⟨n,fun t i q => z*a t i q,fun i q => z*a₀ i q,c,?_,?_,?_⟩ + · intro q; dsimp only; rw [hx,spinPacket_smul] + · rw [hx₀,spinPacket_smul] + · exact fun i q => (ha i q).const_mul z + + + +theorem pulse (hg : GramConverges l d d₀) (hx : PacketMatch l d d₀ x x₀) (b : ι → ℂ) : + PacketMatch l d d₀ (fun q => WZ (combination (d q) b) (x q)) (WZ (combination d₀ b) x₀) := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + let e : Fin (n*2) ≃ Fin n × Fin 2 := finProdFinEquiv.symm + let bc (p : Fin n × Fin 2) : ι → ℂ := if p.2=0 then b else -b + have hbE (q : α) (p : Fin n × Fin 2) : combination (d q) (bc p)= + if p.2=0 then combination (d q) b else -combination (d q) b := by + dsimp only [bc]; split_ifs <;> simp only [combination_neg] + have hbF (p : Fin n × Fin 2) : combination d₀ (bc p)= + if p.2=0 then combination d₀ b else -combination d₀ b := by + dsimp only [bc]; split_ifs <;> simp only [combination_neg] + let aa (q : α) (p : Fin n × Fin 2) (j : Fin 2) : ℂ := + if j=p.2 then phase (combination (d q) (bc p)) (combination (d q) (c p.1))*a q p.1 j else 0 + let aa₀ (p : Fin n × Fin 2) (j : Fin 2) : ℂ := + if j=p.2 then phase (combination d₀ (bc p)) (combination d₀ (c p.1))*a₀ p.1 j else 0 + refine ⟨n*2,fun q i => aa q (e i),fun i => aa₀ (e i),fun i => bc (e i)+c (e i).1,?_,?_,?_⟩ + · intro q + simp only [combination_add] + rw [spinPacket_reindex e (aa q) (fun p => combination (d q) (bc p)+combination (d q) (c p.1))] + simp only [aa,hbE,hx q,WZ_spinPacket] + · simp only [combination_add] + rw [spinPacket_reindex e aa₀ (fun p => combination d₀ (bc p)+combination d₀ (c p.1))] + simp only [aa₀,hbF,hx₀,WZ_spinPacket] + · intro i j + dsimp only [aa,aa₀] + split_ifs + · exact (hg.phase (bc (e i)) (c (e i).1)).mul (ha (e i).1 j) + · exact tendsto_const_nhds + + + +theorem inner (hx : PacketMatch l d d₀ x x₀) (hy : PacketMatch l d d₀ y y₀) + (hg : GramConverges l d d₀) : + Tendsto (fun q => ⟪x q,y q⟫_ℂ) l (𝓝 ⟪x₀,y₀⟫_ℂ) := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + obtain ⟨m,b,b₀,e,hy,hy₀,hb⟩ := hy + simp only [hx,hy,hx₀,hy₀] + exact tendsto_inner_spinPacket a b (fun q i => combination (d q) (c i)) + (fun q i => combination (d q) (e i)) a₀ b₀ (fun i => combination d₀ (c i)) + (fun i => combination d₀ (e i)) ha hb + (fun i => hg.combinations (c i) (c i)) (fun i => hg.combinations (e i) (e i)) + (fun i j => hg.combinations (c i) (e j)) + + + +theorem creation (hx : PacketMatch l d d₀ x x₀) (hg : GramConverges l d d₀) + (h : α → E) (h₀ : F) + (hcol : ∀i,Tendsto (fun q => ⟪d q i,h q⟫_ℂ) l (𝓝 ⟪d₀ i,h₀⟫_ℂ)) : + Tendsto (fun q => ⟪x q,plusEmbedding (creationVacuum (h q))⟫_ℂ) + l (𝓝 ⟪x₀,plusEmbedding (creationVacuum h₀)⟫_ℂ) := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + simp only [hx,hx₀] + apply tendsto_inner_spinPacket_creation a (fun q i => combination (d q) (c i)) h a₀ + (fun i => combination d₀ (c i)) h₀ ha (fun i => hg.combinations (c i) (c i)) + intro i + simp only [combination,sum_inner,inner_smul_left] + exact tendsto_finsetSum _ fun j _ => (hcol j).const_mul (star (c i j)) + +end PacketMatch +end GramCalculus + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace GramCalculus +open CoherentFock PointedTree +variable {E F α ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [Fintype ι] {l : Filter α} + +namespace PacketMatch +variable {d : α → ι → E} {d₀ : ι → F} {x : α → SpinSpace E} {x₀ : SpinSpace F} + +theorem norm (hx : PacketMatch l d d₀ x x₀) (hg : GramConverges l d d₀) : + Tendsto (fun q => ‖x q‖) l (𝓝 ‖x₀‖) := by + have h := tendsto_norm_sq_of_inner x x₀ (hx.inner hx hg) + have hs := Real.continuous_sqrt.continuousAt.tendsto.comp h + simpa only [Function.comp_def,Real.sqrt_sq_eq_abs,abs_norm] using hs + +end PacketMatch + + + +def ApproxMatch (l : Filter α) (d : α → ι → E) (d₀ : ι → F) + (x : α → SpinSpace E) (x₀ : SpinSpace F) : Prop := + ∃y,PacketMatch l d d₀ y x₀ ∧ Tendsto (fun q => ‖x q-y q‖) l (𝓝 0) + +theorem PacketMatch.approx {d : α → ι → E} {d₀ : ι → F} {x : α → SpinSpace E} {x₀ : SpinSpace F} + (hx : PacketMatch l d d₀ x x₀) : ApproxMatch l d d₀ x x₀ := + ⟨x,hx,by simpa only [sub_self,norm_zero] using (tendsto_const_nhds : Tendsto (fun _ : α => (0:ℝ)) l (𝓝 0))⟩ + +namespace ApproxMatch +variable {d : α → ι → E} {d₀ : ι → F} {x y : α → SpinSpace E} {x₀ y₀ : SpinSpace F} + +theorem close (hy : ApproxMatch l d d₀ y x₀) + (he : Tendsto (fun q => ‖x q-y q‖) l (𝓝 0)) : ApproxMatch l d d₀ x x₀ := by + obtain ⟨z,hz,hyz⟩ := hy + refine ⟨z,hz,?_⟩ + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [add_zero] using he.add hyz) + exact Eventually.of_forall fun q => by simpa only [dist_eq_norm] using dist_triangle (x q) (y q) (z q) + +theorem norm (hx : ApproxMatch l d d₀ x x₀) (hg : GramConverges l d d₀) : + Tendsto (fun q => ‖x q‖) l (𝓝 ‖x₀‖) := by + obtain ⟨y,hy,he⟩ := hx + have hdiff : Tendsto (fun q => ‖x q‖-‖y q‖) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ he + exact Eventually.of_forall fun q => by simpa only [Real.norm_eq_abs] using abs_norm_sub_norm_le (x q) (y q) + simpa only [sub_add_cancel,zero_add] using hdiff.add (hy.norm hg) + +theorem norm_bounded (hx : ApproxMatch l d d₀ x x₀) (hg : GramConverges l d d₀) : + ∀ᶠ q in l,‖x q‖≤‖x₀‖+1 := + ((hx.norm hg).eventually (gt_mem_nhds (by linarith : ‖x₀‖<‖x₀‖+1))).mono fun _ h => h.le + + + +theorem inner (hx : ApproxMatch l d d₀ x x₀) (hy : ApproxMatch l d d₀ y y₀) + (hg : GramConverges l d d₀) : + Tendsto (fun q => ⟪x q,y q⟫_ℂ) l (𝓝 ⟪x₀,y₀⟫_ℂ) := by + obtain ⟨x',hx',he⟩ := hx + obtain ⟨y',hy',hf⟩ := hy + have hdiff : Tendsto (fun q => ⟪x q,y q⟫_ℂ-⟪x' q,y' q⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) + (Eventually.of_forall fun q => ?_) + (show Tendsto (fun q => ‖x q-x' q‖*‖y q‖+‖x' q‖*‖y q-y' q‖) l (𝓝 0) from by + simpa only [zero_mul,mul_zero,add_zero] using + (he.mul ((show ApproxMatch l d d₀ y y₀ from ⟨y',hy',hf⟩).norm hg)).add ((hx'.norm hg).mul hf)) + have hsplit : ⟪x q,y q⟫_ℂ-⟪x' q,y' q⟫_ℂ= + ⟪x q-x' q,y q⟫_ℂ+⟪x' q,y q-y' q⟫_ℂ := by simp only [inner_sub_left,inner_sub_right]; ring + rw [hsplit] + exact (norm_add_le _ _).trans (add_le_add (norm_inner_le_norm _ _) (norm_inner_le_norm _ _)) + simpa only [sub_add_cancel,zero_add] using hdiff.add (hx'.inner hy' hg) + + + +theorem creation (hx : ApproxMatch l d d₀ x x₀) (hg : GramConverges l d d₀) + (h : α → E) (h₀ : F) + (hcol : ∀i,Tendsto (fun q => ⟪d q i,h q⟫_ℂ) l (𝓝 ⟪d₀ i,h₀⟫_ℂ)) + (hnorm : Tendsto (fun q => ‖h q‖) l (𝓝 ‖h₀‖)) : + Tendsto (fun q => ⟪x q,plusEmbedding (creationVacuum (h q))⟫_ℂ) + l (𝓝 ⟪x₀,plusEmbedding (creationVacuum h₀)⟫_ℂ) := by + obtain ⟨y,hy,he⟩ := hx + have hdiff : Tendsto (fun q => ⟪x q,plusEmbedding (creationVacuum (h q))⟫_ℂ- + ⟪y q,plusEmbedding (creationVacuum (h q))⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [zero_mul] using he.mul hnorm) + exact Eventually.of_forall fun q => by + rw [←inner_sub_left] + simpa only [plusEmbedding.norm_map,norm_creationVacuum] using + norm_inner_le_norm (𝕜:=ℂ) (x q-y q) (plusEmbedding (creationVacuum (h q))) + simpa only [sub_add_cancel,zero_add] using hdiff.add (hy.creation hg h h₀ hcol) + +end ApproxMatch +end GramCalculus + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace GramCalculus +open CoherentFock PointedTree + + + +inductive WeylGate (ι : Type*) where + | root (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) + | pulse (c : ι → ℂ) + +namespace WeylGate +variable {E F α ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [Fintype ι] {l : Filter α} + +def op (d : ι → E) : WeylGate ι → SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E + | .root P hP => SpinOperators.actEquiv P hP + | .pulse c => costEquiv (combination d c) + +def inv : WeylGate ι → WeylGate ι + | .root P hP => .root P.conjTranspose (root_adjoint_unitary P hP) + | .pulse c => .pulse (-c) + +@[simp] theorem op_inv (d : ι → E) (g : WeylGate ι) : op d g.inv=(op d g).symm := by + cases g with + | root P hP => apply LinearIsometryEquiv.ext; intro x; exact (SpinOperators.actEquiv_symm_apply P hP x).symm + | pulse c => apply LinearIsometryEquiv.ext; intro x; simp only [inv,op,costEquiv_apply,costEquiv_symm_apply,combination_neg] + +theorem packet_match {d : α → ι → E} {d₀ : ι → F} {x : α → SpinSpace E} {x₀ : SpinSpace F} + (g : WeylGate ι) (hx : PacketMatch l d d₀ x x₀) (hg : GramConverges l d d₀) : + PacketMatch l d d₀ (fun q => op (d q) g (x q)) (op d₀ g x₀) := by + cases g with + | root P hP => exact hx.root P + | pulse c => exact hx.pulse hg c + +theorem bounded {d : α → ι → E} {d₀ : ι → F} {x : α → SpinSpace E} + (g : WeylGate ι) (hx : BoundedPacket l x) (hg : GramConverges l d d₀) : + BoundedPacket l (fun q => op (d q) g (x q)) := by + cases g with + | root P hP => exact hx.root P + | pulse c => exact hx.pulse _ (‖combination d₀ c‖+1) (by positivity) (hg.combination_bounded c) + +end WeylGate + +namespace WeylWord +variable {E F α ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [Fintype ι] {l : Filter α} + +def op (d : ι → E) : List (WeylGate ι) → SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E + | [] => LinearIsometryEquiv.refl ℂ _ + | g::w => (op d w).trans (g.op d) + +@[simp] theorem op_nil (d : ι → E) : op d []=LinearIsometryEquiv.refl ℂ _ := rfl +@[simp] theorem op_cons (d : ι → E) (g : WeylGate ι) (w : List (WeylGate ι)) (x : SpinSpace E) : + op d (g::w) x=g.op d (op d w x) := rfl + +@[simp] theorem op_append (d : ι → E) (u w : List (WeylGate ι)) (x : SpinSpace E) : + op d (u++w) x=op d u (op d w x) := by + induction u with + | nil => rfl + | cons g u ih => simp only [List.cons_append,op_cons,ih] + +def inv (w : List (WeylGate ι)) : List (WeylGate ι) := w.reverse.map WeylGate.inv + +@[simp] theorem op_inv (d : ι → E) (w : List (WeylGate ι)) : op d (inv w)=(op d w).symm := by + induction w with + | nil => rfl + | cons g w ih => + apply LinearIsometryEquiv.ext + intro x + simp only [inv,List.reverse_cons,List.map_append,List.map_singleton,op_append,op_cons, + op_nil,WeylGate.op_inv] + change op d (inv w) ((g.op d).symm x)=(op d w).symm ((g.op d).symm x) + rw [ih] + +theorem packet_match {d : α → ι → E} {d₀ : ι → F} {x : α → SpinSpace E} {x₀ : SpinSpace F} + (w : List (WeylGate ι)) (hx : PacketMatch l d d₀ x x₀) (hg : GramConverges l d d₀) : + PacketMatch l d d₀ (fun q => op (d q) w (x q)) (op d₀ w x₀) := by + induction w with + | nil => exact hx + | cons g w ih => exact g.packet_match ih hg + +theorem bounded {d : α → ι → E} {d₀ : ι → F} {x : α → SpinSpace E} + (w : List (WeylGate ι)) (hx : BoundedPacket l x) (hg : GramConverges l d d₀) : + BoundedPacket l (fun q => op (d q) w (x q)) := by + induction w with + | nil => exact hx + | cons g w ih => exact g.bounded ih hg + + + +theorem insertion_match {d : α → ι → E} {d₀ : ι → F} + (w : List (WeylGate ι)) (P : Matrix (Fin 2) (Fin 2) ℂ) (hg : GramConverges l d d₀) : + PacketMatch l d d₀ + (fun q => (op (d q) w).symm (SpinOperators.act P (op (d q) w (vacuum E)))) + ((op d₀ w).symm (SpinOperators.act P (op d₀ w (vacuum F)))) := by + simpa only [op_inv] using packet_match (inv w) ((packet_match w PacketMatch.vacuum hg).root P) hg + +end WeylWord +end GramCalculus + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E α : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] {l : Filter α} + + + +theorem BoundedPacket.pulse_close {x : α → SpinSpace E} (hx : BoundedPacket l x) + (d e : α → E) (C : ℝ) (he : ∀ᶠ q in l,‖e q‖≤C) + (hd : Tendsto (fun q => ‖d q-e q‖) l (𝓝 0)) : + Tendsto (fun q => ‖WZ (d q) (x q)-WZ (e q) (x q)‖) l (𝓝 0) := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [zero_mul] using hd.mul_const (A*(1+2*B+12*B^2)+C*A)) + filter_upwards [hbound,he] with q hq heq + rw [hp] + exact WZ_spinCoe_difference (d q) (e q) (p q) hq.1 hB hq.2 heq + +namespace PacketUnitaryFamily + + + +def LowClose (A B : PacketUnitaryFamily (E:=E) l) : Prop := + ∀x,BoundedPacket l x → Tendsto (fun q => ‖A.op q (x q)-B.op q (x q)‖) l (𝓝 0) + +namespace LowClose +variable {A B C D : PacketUnitaryFamily (E:=E) l} + +theorem refl (A : PacketUnitaryFamily (E:=E) l) : LowClose A A := by + intro x hx + simpa only [sub_self,norm_zero] using (tendsto_const_nhds : Tendsto (fun _ : α => (0:ℝ)) l (𝓝 0)) + +theorem symm (h : LowClose A B) : LowClose B A := by + intro x hx + simpa only [norm_sub_rev] using h x hx + +theorem trans (h : LowClose A B) (h' : LowClose B C) : LowClose A C := by + intro x hx + refine squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) ?_ + (by simpa only [add_zero] using (h x hx).add (h' x hx)) + exact Eventually.of_forall fun q => norm_sub_le_norm_sub_add_norm_sub _ _ _ + +theorem comp (h : LowClose A B) (h' : LowClose C D) : + LowClose (A.trans C) (B.trans D) := by + intro x hx + refine squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) ?_ + (by simpa only [add_zero] using (h x hx).add (h' _ (B.forward x hx))) + exact Eventually.of_forall fun q => by + change ‖C.op q (A.op q (x q))-D.op q (B.op q (x q))‖≤_ + have he := norm_sub_le_norm_sub_add_norm_sub (C.op q (A.op q (x q))) + (C.op q (B.op q (x q))) (D.op q (B.op q (x q))) + simpa only [←map_sub,(C.op q).norm_map] using he + +theorem inverse (h : LowClose A B) : LowClose A.symm B.symm := by + intro x hx + have hh := h (fun q => (B.op q).symm (x q)) (B.backward x hx) + apply hh.congr + intro q + symm + change ‖(A.op q).symm (x q)-(B.op q).symm (x q)‖=_ + rw [←(A.op q).norm_map,map_sub,(A.op q).apply_symm_apply,(B.op q).apply_symm_apply,norm_sub_rev] + +theorem insertion (h : LowClose A B) (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) : + Tendsto (fun q => ‖(A.op q).symm (SpinOperators.act P (A.op q (PointedTree.vacuum E)))- + (B.op q).symm (SpinOperators.act P (B.op q (PointedTree.vacuum E)))‖) l (𝓝 0) := by + refine squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) ?_ + (by simpa only [add_zero] using (h _ BoundedPacket.vacuum).add (h _ (B.insertion_bounded P))) + exact Eventually.of_forall fun q => by + simpa only [one_smul] using ForwardControl.insertion_from_forward (A.op q) (B.op q) + (SpinOperators.act P) (fun x => (SpinOperators.norm_act hP x).le) (PointedTree.vacuum E) (1:ℂ) + +end LowClose + +theorem pulse_lowClose (d e : α → E) (D C : ℝ) (hD : 0≤D) (hC : 0≤C) + (hd : ∀ᶠ q in l,‖d q‖≤D) (he : ∀ᶠ q in l,‖e q‖≤C) + (herr : Tendsto (fun q => ‖d q-e q‖) l (𝓝 0)) : + LowClose (pulse d D hD hd) (pulse e C hC he) := by + intro x hx + exact hx.pulse_close d e C he herr + +end PacketUnitaryFamily +end CoherentFock + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance htrRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance htrRealSMul : SMul ℝ ModeInfinity := htrRealModule.toDistribMulAction.toSMul + +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + +theorem halfEcho_transport_exact (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (q : α) (x : SpinSpace ModeInfinity) : + (ordinaryLocal (st.halfEchoWord t a K q)).symm + (SpinOperators.act Z (st.halfEchoGain t a K q x))= + (ordinaryLocal (st.forwardWord t q)).symm ((probeGain (r q) (st.forwardWord t q) a K).symm + (SpinOperators.act Z (probeGain (r q) (st.forwardWord t q) a K (WZ (st.forwardVector t q) x)))) := by + rw [halfEchoGain_apply] + have he := cost_transport_exact (probePrefix (r q) (st.forwardWord t q) a K) (-(t/r q)) + (probeGain (r q) (st.forwardWord t q) a K (WZ (st.forwardVector t q) x)) + simp only [Complex.ofReal_neg,neg_neg,Complex.coe_smul] at he + change (ordinaryLocal (.cost (-(t/r q))::probePrefix (r q) (st.forwardWord t q) a K)).symm + (SpinOperators.act Z (WZ ((t/r q) • insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K)) + (probeGain (r q) (st.forwardWord t q) a K (WZ (st.forwardVector t q) x))))=_ + rw [he] + apply local_symm_after_gain + exact probeGain_on_local _ _ _ _ + + + +theorem Transported.halfEcho {st : PacketStage l r (fun q => (r q)⁻¹) d spin} + {address : α → SpinSpace ModeInfinity} (ht : st.Transported address) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (G : ℝ) (hG : 0≤G) + (hg : ∀ᶠ q in l,‖st.halfEchoResidual t a K q‖≤G) (hp : ∀ᶠ q in l,0 (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K + (WZ (st.forwardVector t q) (x q))-WZ (st.forwardVector t q) (x q)‖) l (𝓝 0)) + (hs : ∀x,PacketExpansion (l:=l) (fun q => (r q)⁻¹) r (st.forwardCenter t) spin x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (x q)- + SpinOperators.act (R (Real.pi/2)) (x q)‖) l (𝓝 0)) : + (st.halfEcho t a K G hG hg hp ho (fun x hx => hs _ (st.forward_special_packets t x hx))).Transported + (fun q => -address q) := by + let s (q : α) := WZ (st.forwardVector t q) (st.special q (vacuum ModeInfinity)) + have hpack := st.forward_special_packets t _ BoundedPacket.vacuum + have h1 := hs _ hpack + have h2 := hs _ hpack.rootZ + have ht' : Tendsto (fun q => ‖(((r q)⁻¹:ℝ):ℂ) • (ordinaryLocal (st.forwardWord t q)).symm + (SpinOperators.act Z (s q))-address q‖) l (𝓝 0) := by + have he (q : α) : (ordinaryLocal (st.forwardWord t q)).symm (SpinOperators.act Z (s q))= + (ordinaryLocal (st.word q)).symm (SpinOperators.act Z (st.special q (vacuum ModeInfinity))) := by + simpa only [s,forwardWord,forwardVector,complex_neg_real_smul] using + cost_transport_exact (st.word q) (t/r q) (st.special q (vacuum ModeInfinity)) + simpa only [he,Transported] using ht + have hh := ForwardControl.scaled_special_transport (fun q => ordinaryLocal (st.forwardWord t q)) + (fun q => probeGain (r q) (st.forwardWord t q) a K) (SpinOperators.act Z) + (SpinOperators.act (R (Real.pi/2))) + (fun x : SpinSpace ModeInfinity => (SpinOperators.norm_act Z_unitary x).le) + half_mixer_anticommutes s address (fun q => (r q)⁻¹) + (hp.mono fun _ hq => (inv_pos.mpr hq).le) h1 h2 ht' + change Tendsto (fun q => ‖(((r q)⁻¹:ℝ):ℂ) • (ordinaryLocal (st.halfEchoWord t a K q)).symm + (SpinOperators.act Z (st.halfEchoGain t a K q (st.special q (vacuum ModeInfinity))))-(-address q)‖) l (𝓝 0) + simpa only [halfEcho_transport_exact,sub_neg_eq_add,s] using hh + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +open RootSpin +variable {E α κ : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [Fintype κ] + {l : Filter α} + +theorem negativeHalfMixer_sector (i : Fin 2) (x : SpinSpace E) : + projectSpin (1-i) (SpinOperators.act (R (-(Real.pi/2))) (projectSpin i x))= + SpinOperators.act (R (-(Real.pi/2))) (projectSpin i x) := by + ext j + fin_cases i <;> fin_cases j <;> + simp [projectSpin_apply,SpinOperators.act_apply,R, + Real.cos_pi_div_two,Real.sin_pi_div_two,X] + +theorem negative_half_mixer_anticommutes (x : SpinSpace E) : + SpinOperators.act Z (SpinOperators.act (R (-(Real.pi/2))) x)= + -SpinOperators.act (R (-(Real.pi/2))) (SpinOperators.act Z x) := by + ext i + fin_cases i <;> + simp [SpinOperators.act_apply,Fin.sum_univ_two,R,Z,X, + Real.cos_pi_div_two,Real.sin_pi_div_two] + +theorem PacketExpansion.negative_half_mixer {r S : α → ℝ} {d : κ → α → E} + {spin : κ → Fin 2} {u : α → SpinSpace E} (hu : PacketExpansion (l:=l) S r d spin u) : + PacketExpansion (l:=l) S r d (fun i => 1-spin i) + (fun q => SpinOperators.act (RootSpin.R (-(Real.pi/2))) (u q)) := by + obtain ⟨τ,hτ,hspin,he⟩ := hu + let A := RootSpin.R (-(Real.pi/2)) + refine ⟨fun i q => SpinOperators.act A (τ i q),fun i => (hτ i).root A,?_,?_⟩ + · intro i q + change projectSpin (1-spin i) (SpinOperators.act (RootSpin.R (-(Real.pi/2))) (τ i q))=_ + conv_lhs => rw [←hspin i q] + rw [negativeHalfMixer_sector,hspin] + · have hsum (q : α) : SpinOperators.act A (∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ i q))= + ∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (SpinOperators.act A (τ i q)) := by + simp only [map_sum,map_smul,spinW_root] + simpa only [←hsum,A,←map_sub,SpinOperators.norm_act (RootSpin.R_unitary _)] using he + +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/InsertionFromForward.lean b/lean/OAI/Probability/ParisiFinite/InsertionFromForward.lean new file mode 100644 index 0000000000000000000000000000000000000000..d86b9df971b9a0a218e30ba39c33d34bc7c75cc2 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/InsertionFromForward.lean @@ -0,0 +1,664 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Compatible + +namespace OAI + +/-! Insertion From Forward. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +namespace ForwardControl +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + + + +theorem insertion_from_forward (U A : H ≃ₗᵢ[ℂ] H) (P : H →L[ℂ] H) + (hP : ∀ x, ‖P x‖ ≤ ‖x‖) (Ω : H) (ζ : ℂ) : + ‖U.symm (P (U Ω))-A.symm (P (A Ω))‖ ≤ + ‖U Ω-ζ • A Ω‖+‖U (A.symm (P (A Ω)))-ζ • A (A.symm (P (A Ω)))‖ := by + rw [← U.norm_map (U.symm (P (U Ω))-A.symm (P (A Ω))),map_sub,U.apply_symm_apply] + calc + _ ≤ ‖P (U Ω)-ζ • P (A Ω)‖+ + ‖ζ • P (A Ω)-U (A.symm (P (A Ω)))‖ := norm_sub_le_norm_sub_add_norm_sub _ _ _ + _ ≤ ‖U Ω-ζ • A Ω‖+ + ‖U (A.symm (P (A Ω)))-ζ • A (A.symm (P (A Ω)))‖ := by + rw [A.apply_symm_apply,norm_sub_rev (ζ • P (A Ω))] + exact add_le_add (by simpa only [map_sub,map_smul] using hP (U Ω-ζ • A Ω)) le_rfl + + +theorem insertion_split_bound (U A : H ≃ₗᵢ[ℂ] H) (P : H →L[ℂ] H) + (hP : ∀x, ‖P x‖ ≤ ‖x‖) (Ω : H) (ζ : ℂ) + (O S : H →L[ℂ] H) (hsplit : ∀x, U x=O x+S x) + (r ε : ℝ) (hr : 0 ≤ r) + (hS : ∀x, ‖S x‖ ≤ r*‖x‖) + (hO₀ : ‖O Ω-ζ • A Ω‖ ≤ ε) + (hO₁ : ‖O (A.symm (P (A Ω)))-ζ • A (A.symm (P (A Ω)))‖ ≤ ε) : + ‖U.symm (P (U Ω))-A.symm (P (A Ω))‖ ≤ 2*ε+2*r*‖Ω‖ := by + have hv : ‖A.symm (P (A Ω))‖ ≤ ‖Ω‖ := by + rw [A.symm.norm_map] + exact (hP _).trans_eq (A.norm_map _) + have hb (x : H) : ‖U x-ζ • A x‖ ≤ ‖O x-ζ • A x‖+r*‖x‖ := by + rw [hsplit] + have he : O x+S x-ζ • A x=(O x-ζ • A x)+S x := by abel + rw [he] + exact (norm_add_le _ _).trans (add_le_add le_rfl (hS x)) + have h := insertion_from_forward U A P hP Ω ζ + have h0 := hb Ω + have h1 := hb (A.symm (P (A Ω))) + have hh := mul_le_mul_of_nonneg_left hv hr + linarith + + + +theorem selective_flip_bound (V : H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H) + (hZ : ∀x, ‖Z x‖ ≤ ‖x‖) (hanti : ∀x, Z (F x)=-F (Z x)) (o s : H) : + ‖V.symm (Z (V (o+s)))-(Z o-Z s)‖ ≤ + ‖V o-o‖+‖V s-F s‖+‖V (Z o)-Z o‖+‖V (Z s)-F (Z s)‖ := by + rw [← V.norm_map (V.symm (Z (V (o+s)))-(Z o-Z s)),map_sub,V.apply_symm_apply] + have he : Z (V (o+s))-V (Z o-Z s) = + Z (V o-o)+Z (V s-F s)-(V (Z o)-Z o)+(V (Z s)-F (Z s)) := by + simp only [map_add,map_sub,hanti] + abel + rw [he] + have h1 := norm_add_le (Z (V o-o)+Z (V s-F s)-(V (Z o)-Z o)) + (V (Z s)-F (Z s)) + have h2 := norm_sub_le (Z (V o-o)+Z (V s-F s)) (V (Z o)-Z o) + have h3 := norm_add_le (Z (V o-o)) (Z (V s-F s)) + have h4 := hZ (V o-o) + have h5 := hZ (V s-F s) + linarith + + + +theorem actual_flip_change (U V : H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H) + (hZ : ∀x, ‖Z x‖ ≤ ‖x‖) (hanti : ∀x, Z (F x)=-F (Z x)) + (Ω o s : H) (hx : U Ω=o+s) : + ‖U.symm (V.symm (Z (V (U Ω))))-U.symm (Z (U Ω))+ + (2:ℂ) • U.symm (Z s)‖ ≤ + ‖V o-o‖+‖V s-F s‖+‖V (Z o)-Z o‖+‖V (Z s)-F (Z s)‖ := by + have he : U.symm (V.symm (Z (V (U Ω))))-U.symm (Z (U Ω))+ + (2:ℂ) • U.symm (Z s) = + U.symm (V.symm (Z (V (o+s)))-(Z o-Z s)) := by + rw [hx] + simp only [map_sub,map_add] + module + rw [he,U.symm.norm_map] + exact selective_flip_bound V Z F hZ hanti o s + + + +theorem special_transport_bound (V : H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H) + (hZ : ∀x, ‖Z x‖ ≤ ‖x‖) (hanti : ∀x, Z (F x)=-F (Z x)) (s : H) : + ‖V.symm (Z (V s))+Z s‖ ≤ ‖V s-F s‖+‖V (Z s)-F (Z s)‖ := by + rw [← V.norm_map (V.symm (Z (V s))+Z s),map_add,V.apply_symm_apply] + have he : Z (V s)+V (Z s)=Z (V s-F s)+(V (Z s)-F (Z s)) := by + rw [map_sub,hanti] + abel + rw [he] + exact (norm_add_le _ _).trans (add_le_add (hZ _) le_rfl) + +end ForwardControl + +namespace PointedTree +open CoherentFock RootSpin + + +theorem abs_treeEnergy_le (n : ℕ) (d : Mode n) : |treeEnergy n d| ≤ ‖d‖^2 := by + calc + _ ≤ ‖⟪centeredMap (empty n) d,rootShift n d⟫_ℂ‖ := Complex.abs_re_le_norm _ + _ ≤ ‖centeredMap (empty n) d‖*‖rootShift n d‖ := norm_inner_le_norm _ _ + _ = _ := by simp [pow_two] + + + +def ordinaryValue (w : List Gate) : ℝ := treeEnergy w.length (ordinary w w.length).insertion + +theorem ordinary_energy_succ (w : List Gate) (n : ℕ) (hn : w.length ≤ n) : + treeEnergy (n+1) (ordinary w (n+1)).insertion=treeEnergy n (ordinary w n).insertion := by + rw [← ordinary_insertion_empty w n hn,treeEnergy_empty] + +theorem ordinary_energy_stable (w : List Gate) (n : ℕ) (hn : w.length ≤ n) : + treeEnergy n (ordinary w n).insertion=ordinaryValue w := by + induction n,hn using Nat.le_induction with + | base => rfl + | succ n hn ih => rw [ordinary_energy_succ w n hn,ih] + +theorem abs_ordinaryValue_le_one (w : List Gate) : |ordinaryValue w| ≤ 1 := by + simpa only [ordinaryValue,EvenUnitary.norm_insertion,one_pow] using abs_treeEnergy_le w.length (ordinary w w.length).insertion + +end PointedTree + +namespace SpinOperators +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] +@[simp] theorem actEquiv_symm_apply (A : Matrix (Fin 2) (Fin 2) ℂ) + (hA : A ∈ unitary _) (x : Double H) : + (actEquiv A hA).symm x=act A.conjTranspose x := by + apply (actEquiv A hA).injective + rw [LinearIsometryEquiv.apply_symm_apply,actEquiv_apply] + change x=(act A).comp (act A.conjTranspose) x + rw [← act_mul] + have h := (Unitary.mem_iff.mp hA).2 + change A*A.conjTranspose=1 at h + rw [h,act_one] + rfl +end SpinOperators + +namespace CoherentFock +open RootSpin +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +@[simp] theorem rootY_apply (x : SpinSpace E) (i : Fin 2) : + SpinOperators.act Y x i=if i=0 then (-Complex.I) • x 1 else Complex.I • x 0 := by + fin_cases i <;> simp [SpinOperators.act_apply,Y,Fin.sum_univ_two] + +theorem WZ_rootY (d : E) : + (WZ d).comp (SpinOperators.act Y)=(SpinOperators.act Y).comp (WZ (-d)) := by + ext x i + fin_cases i <;> simp [WZ_apply,Y] + +@[simp] theorem WZ_same (d : E) (x : SpinSpace E) : WZ d (WZ d x)=WZ (d+d) x := by + change (WZ d).comp (WZ d) x=_ + rw [WZ_mul] + have hi : (⟪d,d⟫_ℂ).im=0 := inner_self_im (𝕜 := ℂ) d + change Complex.exp ((-(⟪d,d⟫_ℂ).im:ℝ)*Complex.I) • WZ (d+d) x=WZ (d+d) x + rw [hi] + simp + + +theorem one_layer_insertion (d : E) (β : ℝ) (x : SpinSpace E) : + WZ (-d) (SpinOperators.act (R β).conjTranspose + (SpinOperators.act Z (SpinOperators.act (R β) (WZ d x))))= + (Real.cos (2*β):ℂ) • SpinOperators.act Z x+ + (Real.sin (2*β):ℂ) • SpinOperators.act Y (WZ (d+d) x) := by + change WZ (-d) ((SpinOperators.act (R β).conjTranspose).comp + ((SpinOperators.act Z).comp (SpinOperators.act (R β))) (WZ d x))=_ + rw [← ContinuousLinearMap.comp_assoc,← SpinOperators.act_mul,← SpinOperators.act_mul,R_conjugate_Z] + change WZ (-d) (SpinOperators.rep + ((Real.cos (2*β):ℂ) • Z+(Real.sin (2*β):ℂ) • Y) (WZ d x))=_ + simp only [map_add,map_smul,SpinOperators.rep_apply,add_apply,smul_apply] + congr 1 + · congr 1 + change (WZ (-d)).comp (SpinOperators.act Z) (WZ d x)=_ + rw [WZ_rootZ] + change SpinOperators.act Z (WZ (-d) (WZ d x))=_ + rw [← costEquiv_symm_apply,← costEquiv_apply,LinearIsometryEquiv.symm_apply_apply] + · congr 1 + change (WZ (-d)).comp (SpinOperators.act Y) (WZ d x)=_ + rw [WZ_rootY,neg_neg] + exact congrArg (SpinOperators.act Y) (WZ_same d x) +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin + + +def initialDirection (n : ℕ) : Mode n := (EvenUnitary.ident n).insertion + +@[simp] theorem initialDirection_coe (n : ℕ) : + (initialDirection n : Level n)=root n Z (vac n) := rfl + +@[simp] theorem initialDirection_norm (n : ℕ) : ‖initialDirection n‖=1 := + EvenUnitary.norm_insertion _ + +@[simp] theorem initialDirection_empty (n : ℕ) : + centeredMap (empty n) (initialDirection n)=initialDirection (n+1) := + (EvenUnitary.compatible_ident n).insertion + + + +theorem ordinary_one_insertion (n : ℕ) (γ β : ℝ) : + ((ordinary [.mixer β,.cost γ] (n+1)).insertion : Level (n+1))= + (Real.cos (2*β):ℂ) • (initialDirection (n+1) : Level (n+1))+ + (Real.sin (2*β):ℂ) • SpinOperators.act Y + (WZ ((-(2*γ):ℂ) • initialDirection n) (vac (n+1))) := by + change (costEquiv ((-(γ:ℂ)) • initialDirection n)).symm + ((SpinOperators.actEquiv (R β) (R_unitary β)).symm + (SpinOperators.act Z (SpinOperators.act (R β) + (costEquiv ((-(γ:ℂ)) • initialDirection n) (vac (n+1))))))=_ + rw [costEquiv_symm_apply,SpinOperators.actEquiv_symm_apply,costEquiv_apply,one_layer_insertion] + have hd : (-(γ:ℂ)) • initialDirection n+(-(γ:ℂ)) • initialDirection n= + (-(2*γ):ℂ) • initialDirection n := by module + rw [hd] + rfl + + +def initializationWord (γ δ β : ℝ) : List Gate := + [.mixer β,.cost (-γ),.mixer δ,.cost γ] + +theorem initialization_op (n : ℕ) (γ δ β : ℝ) (x : Level (n+2)) : + (ordinary (initializationWord γ δ β) (n+2)).op x= + SpinOperators.act (R β) + (WZ ((γ:ℂ) • (ordinary [.mixer δ,.cost γ] (n+1)).insertion) + (SpinOperators.act (R δ) (WZ (-(γ:ℂ) • initialDirection (n+1)) x))) := by + change SpinOperators.act (R β) + (WZ ((-((-γ:ℝ):ℂ)) • (ordinary [.mixer δ,.cost γ] (n+1)).insertion) + (SpinOperators.act (R δ) (WZ (-(γ:ℂ) • initialDirection (n+1)) x)))=_ + simp only [Complex.ofReal_neg,neg_neg] + +end PointedTree + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +@[simp] theorem W_vacuum (d : E) : W d (coherent 0)=coherent d := by simp +@[simp] theorem kernel_zero_left (d : E) : kernel 0 d=(Real.exp (-‖d‖^2/2):ℂ) := by + simp [kernel_eq,Complex.ofReal_exp] +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin Complex +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +theorem inv_sqrt_two_sq : (((Real.sqrt 2)⁻¹:ℝ):ℂ)^2=1/2 := by + rw [← Complex.ofReal_pow,inv_pow,Real.sq_sqrt (by norm_num)] + norm_num + +def spinPair (x y : H) : SpinOperators.Double H := + WithLp.toLp 2 (fun i => if i=0 then x else y) + +@[simp] theorem spinPair_zero (x y : H) : spinPair x y 0=x := by rfl +@[simp] theorem spinPair_one (x y : H) : spinPair x y 1=y := by rfl + +theorem inner_spinPair (x y u v : H) : + ⟪spinPair x y,spinPair u v⟫_ℂ=⟪x,u⟫_ℂ+⟪y,v⟫_ℂ := by + rw [PiLp.inner_apply,Fin.sum_univ_two] + rfl + +def spinCoefficient : ℂ := (((Real.sqrt 2)⁻¹:ℝ):ℂ) +@[simp] theorem spinCoefficient_conj : conj spinCoefficient=spinCoefficient := by + simp [spinCoefficient] +@[simp] theorem spinCoefficient_sq : spinCoefficient^2=1/2 := inv_sqrt_two_sq + +theorem plusEmbedding_pair (x : H) : + plusEmbedding x=spinPair (spinCoefficient • x) (spinCoefficient • x) := by + ext i + fin_cases i <;> rfl + +theorem rootZ_vac_pair : SpinOperators.act Z (vacuum H)= + spinPair (spinCoefficient • coherent (0:H)) (-(spinCoefficient • coherent (0:H))) := by + ext i + fin_cases i <;> simp [Z,spinPair,vacuum_apply,spinCoefficient] + +theorem rootY_WZ_vac_pair (d : H) : SpinOperators.act Y (WZ d (vacuum H))= + spinPair ((-I*spinCoefficient) • coherent (-d)) ((I*spinCoefficient) • coherent d) := by + ext i + fin_cases i <;> simp [Y,spinPair,WZ_apply,vacuum_apply,spinCoefficient,smul_smul] + +theorem inner_rootZ_vac_creation (v : H) : + ⟪SpinOperators.act Z (vacuum H),plusEmbedding (creationVacuum v)⟫_ℂ=0 := by + rw [rootZ_vac_pair,plusEmbedding_pair,inner_spinPair,inner_neg_left] + exact add_neg_cancel _ + +theorem inner_rootZ_vac_rootY_WZ (d : H) : + ⟪SpinOperators.act Z (vacuum H),SpinOperators.act Y (WZ d (vacuum H))⟫_ℂ= + -I*(Real.exp (-‖d‖^2/2):ℂ) := by + rw [rootZ_vac_pair,rootY_WZ_vac_pair,inner_spinPair] + simp only [inner_neg_left,inner_smul_left,inner_smul_right,spinCoefficient_conj, + inner_coherent,kernel_zero_left,norm_neg] + linear_combination -2*I*(Real.exp (-‖d‖^2/2):ℂ)*spinCoefficient_sq + +theorem inner_rootY_WZ_creation (d v : H) : + ⟪SpinOperators.act Y (WZ d (vacuum H)),plusEmbedding (creationVacuum v)⟫_ℂ= + -(Real.exp (-‖d‖^2/2):ℂ)*⟪d,v⟫_ℂ := by + rw [rootY_WZ_vac_pair,plusEmbedding_pair,inner_spinPair] + simp only [creationVacuum,inner_smul_left,inner_smul_right, + inner_coherent_oneParticle,inner_neg_left,norm_neg,map_neg,map_mul,Complex.conj_I, + spinCoefficient_conj] + linear_combination -2*(Real.exp (-‖d‖^2/2):ℂ)*⟪d,v⟫_ℂ*spinCoefficient_sq + + 2*spinCoefficient^2*(Real.exp (-‖d‖^2/2):ℂ)*⟪d,v⟫_ℂ*Complex.I_sq + +end PointedTree + +namespace PointedTree +open CoherentFock RootSpin Complex + + +def highDirection (n : ℕ) (γ : ℝ) : Mode (n+1) := + (ordinary [.mixer (Real.pi/4),.cost γ] (n+1)).insertion + +@[simp] theorem highDirection_coe (n : ℕ) (γ : ℝ) : + (highDirection n γ : Level (n+1))= + SpinOperators.act Y (WZ ((-2*γ:ℝ) • initialDirection n) (vac (n+1))) := by + unfold highDirection + rw [ordinary_one_insertion] + have hpi : 2*(Real.pi/4)=Real.pi/2 := by ring + simp only [hpi,Real.cos_pi_div_two,Real.sin_pi_div_two,Complex.ofReal_zero, + Complex.ofReal_one,zero_smul,one_smul,zero_add] + have hd : (-(2*γ):ℂ) • initialDirection n = (-2*γ:ℝ) • initialDirection n := by + rw [← Complex.coe_smul] + apply congrArg (fun z : ℂ => z • initialDirection n) + push_cast + ring + rw [hd] + +@[simp] theorem highDirection_norm (n : ℕ) (γ : ℝ) : ‖highDirection n γ‖=1 := + EvenUnitary.norm_insertion _ + +@[simp] theorem highDirection_empty (n : ℕ) (γ : ℝ) : + centeredMap (empty (n+1)) (highDirection n γ)=highDirection (n+1) γ := by + apply Subtype.ext + rw [centeredMap_coe,highDirection_coe,highDirection_coe] + change (empty (n+1)).toLinearIsometry (root (n+1) Y _) = root (n+2) Y _ + rw [root_empty,cost_empty,empty_vac] + have hd : centeredMap (empty n) ((-2*γ:ℝ) • initialDirection n)= + (-2*γ:ℝ) • initialDirection (n+1) := by + calc + _ = (-2*γ:ℝ) • centeredMap (empty n) (initialDirection n) := + (centeredMap (empty n)).map_smul_of_tower _ _ + _ = _ := by rw [initialDirection_empty] + rw [hd] + +theorem initial_inner_highDirection (n : ℕ) (γ : ℝ) : + ⟪initialDirection (n+1),highDirection n γ⟫_ℂ= + -I*(Real.exp (-2*γ^2):ℂ) := by + change ⟪(initialDirection (n+1):Level (n+1)),(highDirection n γ:Level (n+1))⟫_ℂ=_ + rw [initialDirection_coe,highDirection_coe] + change ⟪SpinOperators.act Z (vacuum (Mode n)),SpinOperators.act Y (WZ _ (vacuum (Mode n)))⟫_ℂ=_ + rw [inner_rootZ_vac_rootY_WZ] + have hn : ‖(-2*γ:ℝ) • initialDirection n‖^2=4*γ^2 := by + rw [norm_smul,initialDirection_norm,mul_one,Real.norm_eq_abs,sq_abs] + ring + rw [hn] + congr 3 + ring + +end PointedTree + +namespace PointedTree +open CoherentFock RootSpin Complex + +theorem ordinary_one_mode (n : ℕ) (γ β : ℝ) : + (ordinary [.mixer β,.cost γ] (n+1)).insertion= + (Real.cos (2*β):ℂ) • initialDirection (n+1)+ + (Real.sin (2*β):ℂ) • highDirection n γ := by + apply Subtype.ext + rw [ordinary_one_insertion] + change _ = (Real.cos (2*β):ℂ) • (initialDirection (n+1):Level (n+1))+ + (Real.sin (2*β):ℂ) • (highDirection n γ:Level (n+1)) + rw [highDirection_coe] + have hd : (-(2*γ):ℂ) • initialDirection n=(-2*γ:ℝ) • initialDirection n := by + rw [← Complex.coe_smul] + apply congrArg (fun z : ℂ => z • initialDirection n) + push_cast + ring + rw [hd] + +theorem inner_highDirection_creation (n : ℕ) (γ : ℝ) (v : Mode n) : + ⟪(highDirection n γ:Level (n+1)),plusEmbedding (creationVacuum v)⟫_ℂ= + (2*γ*Real.exp (-2*γ^2):ℂ)*⟪initialDirection n,v⟫_ℂ := by + rw [highDirection_coe] + change ⟪SpinOperators.act Y (WZ ((-2*γ:ℝ) • initialDirection n) + (vacuum (Mode n))),plusEmbedding (creationVacuum v)⟫_ℂ=_ + rw [inner_rootY_WZ_creation] + have hi : ⟪(-2*γ:ℝ) • initialDirection n,v⟫_ℂ= + ((-2*γ:ℝ):ℂ)*⟪initialDirection n,v⟫_ℂ := by + rw [← Complex.coe_smul,inner_smul_left,Complex.conj_ofReal] + rw [hi] + have hn : ‖(-2*γ:ℝ) • initialDirection n‖^2=4*γ^2 := by + rw [norm_smul,initialDirection_norm,mul_one,Real.norm_eq_abs,sq_abs] + ring + rw [hn,show -(4*γ^2)/2= -2*γ^2 by ring] + push_cast + ring + +theorem inner_initial_rootShift (n : ℕ) (v : Mode n) : + ⟪initialDirection (n+1),rootShift n v⟫_ℂ=0 := by + change ⟪(initialDirection (n+1):Level (n+1)),(rootShift n v:Level (n+1))⟫_ℂ=0 + rw [initialDirection_coe,rootShift_coe] + exact inner_rootZ_vac_creation v + +theorem inner_highDirection_rootShift (n : ℕ) (γ : ℝ) (v : Mode n) : + ⟪highDirection n γ,rootShift n v⟫_ℂ= + (2*γ*Real.exp (-2*γ^2):ℂ)*⟪initialDirection n,v⟫_ℂ := + inner_highDirection_creation n γ v + +@[simp] theorem inner_initialDirection_self (n : ℕ) : + ⟪initialDirection n,initialDirection n⟫_ℂ=1 := by + rw [inner_self_eq_norm_sq_to_K,initialDirection_norm] + norm_num + + + +theorem treeEnergy_one (n : ℕ) (γ β : ℝ) : + treeEnergy (n+1) (ordinary [.mixer β,.cost γ] (n+1)).insertion= + γ*Real.sin (4*β)*Real.exp (-2*γ^2) := by + rw [ordinary_one_mode] + unfold treeEnergy + rw [map_add,map_smul,map_smul,initialDirection_empty,highDirection_empty, + inner_add_left,inner_smul_left,inner_smul_left,inner_initial_rootShift, + inner_highDirection_rootShift,inner_add_right,inner_smul_right,inner_smul_right, + inner_initialDirection_self,initial_inner_highDirection] + simp only [Complex.conj_ofReal,mul_zero,zero_add] + have hs : Real.sin (4*β)=2*Real.sin (2*β)*Real.cos (2*β) := by + rw [show 4*β=2*(2*β) by ring] + exact Real.sin_two_mul (2*β) + rw [hs] + simp only [Complex.mul_re,Complex.add_re,Complex.ofReal_re,Complex.one_re, + Complex.neg_re,Complex.I_re,Complex.ofReal_im,Complex.add_im,Complex.mul_im, + Complex.neg_im,Complex.I_im,Complex.one_im,Complex.re_ofNat,Complex.im_ofNat] + ring + +theorem ordinaryValue_one (γ β : ℝ) : + ordinaryValue [.mixer β,.cost γ]=γ*Real.sin (4*β)*Real.exp (-2*γ^2) := by + exact treeEnergy_one 1 γ β + +end PointedTree + +open Filter Topology + +namespace SeedInitialization + +def amplitude (t : ℝ) : ℝ := t⁻¹ +def delta (t : ℝ) : ℝ := Real.arcsin (amplitude t) +def gamma (b t : ℝ) : ℝ := b*t + +theorem amplitude_pos {t : ℝ} (ht : 1 ≤ t) : 0 < amplitude t := + inv_pos.mpr (lt_of_lt_of_le zero_lt_one ht) +theorem amplitude_le_one {t : ℝ} (ht : 1 ≤ t) : amplitude t ≤ 1 := by + exact inv_le_one_of_one_le₀ ht + +theorem sin_delta {t : ℝ} (ht : 1 ≤ t) : Real.sin (delta t)=amplitude t := by + exact Real.sin_arcsin (by linarith [amplitude_pos ht]) (amplitude_le_one ht) + +theorem cos_delta (t : ℝ) : Real.cos (delta t)=Real.sqrt (1-(amplitude t)^2) := + Real.cos_arcsin _ + +theorem cos_two_delta {t : ℝ} (ht : 1 ≤ t) : + Real.cos (2*delta t)=1-2*(amplitude t)^2 := by + rw [Real.cos_two_mul',sin_delta ht] + have h := Real.sin_sq_add_cos_sq (delta t) + rw [sin_delta ht] at h + linarith + +theorem sin_two_delta {t : ℝ} (ht : 1 ≤ t) : + Real.sin (2*delta t)=2*amplitude t*Real.sqrt (1-(amplitude t)^2) := by + rw [Real.sin_two_mul,sin_delta ht,cos_delta] + +theorem gamma_cos_error {t : ℝ} (ht : 1 ≤ t) (b : ℝ) : + gamma b t*(Real.cos (2*delta t)-1)= -2*b*amplitude t := by + rw [cos_two_delta ht] + unfold gamma amplitude + field_simp + ring + +theorem gamma_sin {t : ℝ} (ht : 1 ≤ t) (b : ℝ) : + gamma b t*Real.sin (2*delta t)=2*b*Real.sqrt (1-(amplitude t)^2) := by + rw [sin_two_delta ht] + unfold gamma amplitude + have hz : t≠0 := ne_of_gt (lt_of_lt_of_le zero_lt_one ht) + field_simp + +theorem tendsto_amplitude : Tendsto amplitude atTop (𝓝 0) := tendsto_inv_atTop_zero + +theorem tendsto_delta : Tendsto delta atTop (𝓝 0) := by + change Tendsto (fun t => Real.arcsin (amplitude t)) atTop (𝓝 0) + simpa [delta,Function.comp_def] using Real.continuous_arcsin.continuousAt.tendsto.comp tendsto_amplitude + +theorem tendsto_cos_delta : Tendsto (fun t => Real.cos (delta t)) atTop (𝓝 1) := by + simpa only [Function.comp_def,Real.cos_zero,Real.sin_zero,mul_zero] using Real.continuous_cos.continuousAt.tendsto.comp tendsto_delta + +theorem tendsto_cos_two_delta : Tendsto (fun t => Real.cos (2*delta t)) atTop (𝓝 1) := by + simpa only [Function.comp_def,Real.cos_zero,Real.sin_zero,mul_zero] using Real.continuous_cos.continuousAt.tendsto.comp (tendsto_delta.const_mul 2) + +theorem tendsto_sin_two_delta : Tendsto (fun t => Real.sin (2*delta t)) atTop (𝓝 0) := by + simpa only [Function.comp_def,Real.cos_zero,Real.sin_zero,mul_zero] using Real.continuous_sin.continuousAt.tendsto.comp (tendsto_delta.const_mul 2) + +theorem tendsto_gamma_cos_error (b : ℝ) : + Tendsto (fun t => gamma b t*(Real.cos (2*delta t)-1)) atTop (𝓝 0) := by + apply Tendsto.congr' (f₁ := fun t => -2*b*amplitude t) + · filter_upwards [eventually_ge_atTop (1:ℝ)] with t ht + exact (gamma_cos_error ht b).symm + · simpa using tendsto_amplitude.const_mul (-2*b) + +theorem tendsto_gamma_sin (b : ℝ) : + Tendsto (fun t => gamma b t*Real.sin (2*delta t)) atTop (𝓝 (2*b)) := by + apply Tendsto.congr' (f₁ := fun t => 2*b*Real.cos (delta t)) + · filter_upwards [eventually_ge_atTop (1:ℝ)] with t ht + rw [gamma_sin ht,cos_delta] + · simpa using tendsto_cos_delta.const_mul (2*b) + +theorem tendsto_gamma (b : ℝ) (hb : 0 < b) : Tendsto (gamma b) atTop atTop := + tendsto_id.const_mul_atTop hb + +theorem tendsto_gamma_sq_exp (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => (gamma b t)^2*Real.exp (-2*(gamma b t)^2)) atTop (𝓝 0) := by + have hx := ((tendsto_pow_atTop (by norm_num : (2:ℕ)≠0)).comp (tendsto_gamma b hb)).const_mul_atTop + (by norm_num : (0:ℝ)<2) + have h := (Real.tendsto_pow_mul_exp_neg_atTop_nhds_zero 1).comp hx + convert! h.div_const 2 using 1 + · funext t + simp only [Function.comp_def,pow_one] + rw [show -(2*(gamma b t)^2)= -2*(gamma b t)^2 by ring] + ring + · norm_num + +def phaseAngle (b t : ℝ) : ℝ := + (gamma b t)^2 * Real.sin (2*delta t) * Real.exp (-2*(gamma b t)^2) + +theorem tendsto_phaseAngle (b : ℝ) (hb : 0 < b) : + Tendsto (phaseAngle b) atTop (𝓝 0) := by + convert! (tendsto_gamma_sq_exp b hb).mul tendsto_sin_two_delta using 1 + · funext t + unfold phaseAngle + ring + · norm_num + +end SeedInitialization + +namespace UnitarySplit +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +theorem inverse (U O S : H ≃ₗᵢ[ℂ] H) (a b : ℂ) + (h : ∀ x, U x=a • O x+b • S x) (y : H) : + U.symm y=star a • O.symm y+star b • S.symm y := by + apply ext_inner_left ℂ + intro x + have hU : ⟪x,U.symm y⟫_ℂ=⟪U x,y⟫_ℂ := by + rw [← U.inner_map_map x (U.symm y),U.apply_symm_apply] + have hO : ⟪x,O.symm y⟫_ℂ=⟪O x,y⟫_ℂ := by + rw [← O.inner_map_map x (O.symm y),O.apply_symm_apply] + have hS : ⟪x,S.symm y⟫_ℂ=⟪S x,y⟫_ℂ := by + rw [← S.inner_map_map x (S.symm y),S.apply_symm_apply] + rw [hU,h,inner_add_left,inner_smul_left,inner_smul_left, + inner_add_right,inner_smul_right,inner_smul_right,hO,hS] + rfl +end UnitarySplit + +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +def initialMap (γ δ β : ℝ) (v e : E) : SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E := + (costEquiv ((-γ) • e)).trans ((SpinOperators.actEquiv (R δ) (R_unitary δ)).trans + ((costEquiv (γ • v)).trans (SpinOperators.actEquiv (R β) (R_unitary β)))) + +def ordinaryMap (γ β : ℝ) (v e : E) : SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E := + (costEquiv (γ • (v-e))).trans (SpinOperators.actEquiv (R β) (R_unitary β)) + +def specialMap (γ β : ℝ) (v e : E) : SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E := + (costEquiv ((-γ) • (v+e))).trans ((SpinOperators.actEquiv X X_unitary).trans + (SpinOperators.actEquiv (R β) (R_unitary β))) + +def ordinaryCoefficient (γ δ : ℝ) (v e : E) : ℂ := + (Real.cos δ:ℂ)*phase (γ • v) ((-γ) • e) +def specialCoefficient (γ δ : ℝ) (v e : E) : ℂ := + (-I*(Real.sin δ:ℂ))*phase ((-γ) • v) ((-γ) • e) +def specialPhase (γ : ℝ) (v e : E) : ℂ := + -I*phase ((-γ) • v) ((-γ) • e) + +@[simp] theorem initialMap_apply (γ δ β : ℝ) (v e : E) (x : SpinSpace E) : + initialMap γ δ β v e x=SpinOperators.act (R β) + (WZ (γ • v) (SpinOperators.act (R δ) (WZ ((-γ) • e) x))) := rfl +@[simp] theorem ordinaryMap_apply (γ β : ℝ) (v e : E) (x : SpinSpace E) : + ordinaryMap γ β v e x=SpinOperators.act (R β) (WZ (γ • (v-e)) x) := rfl +@[simp] theorem specialMap_apply (γ β : ℝ) (v e : E) (x : SpinSpace E) : + specialMap γ β v e x=SpinOperators.act (R β) + (SpinOperators.act X (WZ ((-γ) • (v+e)) x)) := rfl + + +theorem exact_split (γ δ β : ℝ) (v e : E) (x : SpinSpace E) : + initialMap γ δ β v e x= + ordinaryCoefficient γ δ v e • ordinaryMap γ β v e x+ + specialCoefficient γ δ v e • specialMap γ β v e x := by + rw [initialMap_apply,ordinaryMap_apply,specialMap_apply] + have h := congrArg (fun A : SpinSpace E →L[ℂ] SpinSpace E => A x) + (CoherentFock.initialization_split γ δ v e) + change WZ (γ • v) (SpinOperators.act (R δ) (WZ ((-γ) • e) x))=_ at h + rw [h] + simp only [add_apply,smul_apply, + ContinuousLinearMap.comp_apply,map_add,map_smul] + rfl + +@[simp] theorem norm_specialPhase (γ : ℝ) (v e : E) : ‖specialPhase γ v e‖=1 := by + simp [specialPhase] + +@[simp] theorem norm_special_component (γ δ β : ℝ) (v e : E) (x : SpinSpace E) : + ‖specialCoefficient γ δ v e • specialMap γ β v e x‖=|Real.sin δ| * ‖x‖ := by + rw [norm_smul,LinearIsometryEquiv.norm_map] + simp only [specialCoefficient,norm_mul,norm_neg,Complex.norm_I,Complex.norm_real, + norm_phase,one_mul,mul_one,Real.norm_eq_abs] + + + +def address (γ δ : ℝ) (v e : E) : SpinSpace E := + (initialMap γ δ (Real.pi/4) v e).symm + (SpinOperators.act Z (specialPhase γ v e • specialMap γ (Real.pi/4) v e (vacuum E))) + +@[simp] theorem norm_address (γ δ : ℝ) (v e : E) : ‖address γ δ v e‖=1 := by + unfold address + rw [LinearIsometryEquiv.norm_map,SpinOperators.norm_act Z_unitary, + norm_smul,norm_specialPhase,LinearIsometryEquiv.norm_map,norm_vacuum] + norm_num + +theorem address_exact_normalization (γ δ : ℝ) (v e : E) : + (Real.sin δ:ℂ) • address γ δ v e= + (initialMap γ δ (Real.pi/4) v e).symm + (SpinOperators.act Z (specialCoefficient γ δ v e • + specialMap γ (Real.pi/4) v e (vacuum E))) := by + unfold address + rw [← map_smul,← map_smul,smul_smul] + congr 3 + unfold specialCoefficient specialPhase + ring + +end SeedInitialization + +namespace RootSpin +@[simp] theorem Y_mul_X : Y*X=(-Complex.I) • Z := by + ext i j + fin_cases i <;> fin_cases j <;> simp [Y,X,Z,Matrix.mul_apply,Fin.sum_univ_two] + +theorem R_quarter_conjugate_Z : (R (Real.pi/4)).conjTranspose*Z*R (Real.pi/4)=Y := by + rw [R_conjugate_Z,show 2*(Real.pi/4)=Real.pi/2 by ring] + simp only [Real.cos_pi_div_two,Real.sin_pi_div_two,Complex.ofReal_zero, + Complex.ofReal_one,zero_smul,one_smul,zero_add] +end RootSpin + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/IntegrableExpField.lean b/lean/OAI/Probability/ParisiFinite/IntegrableExpField.lean new file mode 100644 index 0000000000000000000000000000000000000000..9706ed9bd65ada685610ddac87df61300633ba0b --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/IntegrableExpField.lean @@ -0,0 +1,678 @@ +import Mathlib +import OAI.Probability.ParisiFinite.RestrictCode +import OAI.Probability.ParisiFinite.ScalarPhase + +namespace OAI + +/-! Integrable Exp Field. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +omit [Fintype ι] [Nonempty ι] in +lemma integrable_exp_field (A : ι → κ → ℝ) (a : ℝ) (s : ι) : + Integrable (fun z => Real.exp (a*field A z s)) (gaussianLaw κ) := by + have h := GaussianFourier.integrable_real_exp_dot (fun k => a*A s k) + simpa only [GaussianFourier.dot,GaussianFourier.law,gaussianLaw,field,Finset.mul_sum,mul_assoc] using h + +omit [Fintype ι] [Nonempty ι] in +lemma integral_exp_field (A : ι → κ → ℝ) (a : ℝ) (s : ι) : + (∫ z,Real.exp (a*field A z s) ∂gaussianLaw κ)=Real.exp (a^2*kernel A s s/2) := by + have h := GaussianFourier.integral_real_exp_dot (fun k => a*A s k) + convert h using 1 + · congr 1 + ext z + simp only [GaussianFourier.dot,field,Finset.mul_sum,mul_assoc] + · congr 1 + simp only [kernel,Finset.mul_sum,Finset.sum_div,pow_two] + apply Finset.sum_congr rfl + intro k _ + ring + + +def gaussianLogAverage (x : ι → ℝ) (A : ι → κ → ℝ) : ℝ := + ∫ z,Real.log (average x (fun s => Real.exp (field A z s))) ∂gaussianLaw κ + +lemma integrable_gaussianLogAverage (x : ι → ℝ) (A : ι → κ → ℝ) : + Integrable (fun z => Real.log (average x (fun s => Real.exp (field A z s)))) (gaussianLaw κ) := by + simp_rw [log_average_exp] + exact (integrable_logPartition (fun s => (integrable_const (x s)).add (integrable_field A s))).sub (integrable_const _) + +omit [Fintype ι] [Nonempty ι] in +lemma empirical_log_exp {r : ℕ} (hr : 0 Real.exp (f s)) σ)=logPartition (fun i => f (σ i))-Real.log (r:ℝ) := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + change Real.log (partition (fun i => f (σ i))/(r:ℝ))=_ + rw [Real.log_div (partition_pos (fun i => f (σ i))).ne' (Nat.cast_ne_zero.mpr hr.ne')] + rfl + +omit [Fintype ι] [Nonempty ι] in +lemma integrable_empirical_log_exp {r : ℕ} (hr : 0 Real.log (empiricalMean (fun s => Real.exp (field A z s)) σ)) (gaussianLaw κ) := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + simp_rw [empirical_log_exp hr] + exact (integrable_logPartition (fun i => integrable_field A (σ i))).sub (integrable_const _) + +def samplePressure {r : ℕ} (A : ι → κ → ℝ) (σ : Fin r → ι) : ℝ := + expected (fun i => A (σ i))-Real.log (r:ℝ) + +omit [Fintype ι] [Nonempty ι] in +lemma integral_empirical_log_exp {r : ℕ} (hr : 0 Real.exp (field A z s)) σ) ∂gaussianLaw κ)=samplePressure A σ := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + simp_rw [empirical_log_exp hr] + rw [integral_sub (integrable_logPartition (fun i => integrable_field A (σ i))) (integrable_const _)] + simp only [integral_const,probReal_univ,one_smul] + rfl + +omit [Nonempty ι] in +lemma integrable_average_exp_field (x : ι → ℝ) (A : ι → κ → ℝ) (a : ℝ) : + Integrable (fun z => average x (fun s => Real.exp (a*field A z s))) (gaussianLaw κ) := + integrable_finsetSum _ (fun s _ => (integrable_exp_field A a s).const_mul _) + +lemma integral_average_exp_field_le (x : ι → ℝ) (A : ι → κ → ℝ) {M : ℝ} + (hM : ∀ s,kernel A s s≤M) (a : ℝ) : + (∫ z,average x (fun s => Real.exp (a*field A z s)) ∂gaussianLaw κ)≤Real.exp (a^2*M/2) := by + simp only [average] + rw [integral_finsetSum _ (fun s _ => (integrable_exp_field A a s).const_mul _)] + simp only [integral_const_mul,integral_exp_field] + calc + _ ≤ ∑ s,weight x s*Real.exp (a^2*M/2) := by + apply Finset.sum_le_sum + intro s _ + apply mul_le_mul_of_nonneg_left _ (weight_pos x s).le + apply Real.exp_le_exp.mpr + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (hM s) (sq_nonneg a)) (by norm_num) + _ = _ := by rw [← Finset.sum_mul,sum_weight,one_mul] + + + +theorem gaussian_sample_error {r : ℕ} (hr : 0 + Real.log (empiricalMean (fun s => Real.exp (field A z s)) σ)) + let g (z : κ → ℝ) := Real.log (average x (fun s => Real.exp (field A z s))) + have hf : Integrable f (gaussianLaw κ) := integrable_finsetSum _ + (fun σ _ => (integrable_empirical_log_exp hr A σ).const_mul _) + have hg : Integrable g (gaussianLaw κ) := integrable_gaussianLogAverage x A + have he : (∫ z,f z ∂gaussianLaw κ)=replicaMean x (samplePressure (r:=r) A) := by + rw [show f=(fun z => ∑ σ : Fin r → ι, replicaWeight x σ*Real.log (empiricalMean (fun s => Real.exp (field A z s)) σ)) from rfl, + integral_finsetSum _ (fun σ _ => (integrable_empirical_log_exp hr A σ).const_mul _)] + simp only [integral_const_mul,integral_empirical_log_exp hr,replicaMean] + have hsq (y : ℝ) : (Real.exp y)^2=Real.exp (2*y) := by + rw [pow_two,← Real.exp_add]; congr 1; ring + have hinv (y : ℝ) : (Real.exp y)⁻¹^2=Real.exp ((-2)*y) := by + rw [← Real.exp_neg,hsq]; congr 1; ring + have hb (z : κ → ℝ) : |f z-g z|≤ + (t/(r:ℝ))*average x (fun s => Real.exp (2*field A z s))+ + t⁻¹*average x (fun s => Real.exp ((-2)*field A z s)) := by + simpa only [hsq,hinv] using empirical_log_mean_error hr x + (fun s => Real.exp (field A z s)) (fun s => Real.exp_pos _) ht + rw [← he] + change |(∫ z,f z ∂gaussianLaw κ)-(∫ z,g z ∂gaussianLaw κ)|≤_ + rw [← integral_sub hf hg] + apply abs_integral_le_integral_abs.trans + have hh := integral_mono (hf.sub hg).abs + (((integrable_average_exp_field x A 2).const_mul (t/(r:ℝ))).add + ((integrable_average_exp_field x A (-2)).const_mul t⁻¹)) hb + simp only [Pi.add_apply, Pi.sub_apply] at hh + rw [integral_add ((integrable_average_exp_field x A 2).const_mul (t/(r:ℝ))) + ((integrable_average_exp_field x A (-2)).const_mul t⁻¹),integral_const_mul,integral_const_mul] at hh + have h1 := mul_le_mul_of_nonneg_left (integral_average_exp_field_le x A hM 2) + (by positivity : 0≤t/(r:ℝ)) + have h2 := mul_le_mul_of_nonneg_left (integral_average_exp_field_le x A hM (-2)) (inv_nonneg.mpr ht.le) + refine hh.trans ((add_le_add h1 h2).trans_eq ?_) + ring_nf + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + def overlapMatrix {r : ℕ} (T : OverlapBlock r) : Matrix (Fin r) (Fin r) ℝ := fun i j => (T i j:ℝ) + +lemma gramBlock_posSemidef {r : ℕ} {T : OverlapBlock r} (hT : T∈GramBlock r) : + (overlapMatrix T).PosSemidef := by + apply Matrix.posSemidef_iff_dotProduct_mulVec.mpr + constructor + · apply Matrix.ext + intro i j + simpa [overlapMatrix,Matrix.conjTranspose_apply] using congrArg Subtype.val (hT.1 j i) + · intro c + have h := hT.2.2 c + have he : star c ⬝ᵥ (overlapMatrix T).mulVec c=∑ i,∑ j,c i*c j*(T i j:ℝ) := by + simp only [dotProduct,Matrix.mulVec,Pi.star_apply,star_trivial,overlapMatrix,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + rw [he] + exact h + +lemma exists_gramFactor {r : ℕ} {T : OverlapBlock r} (hT : T∈GramBlock r) : + ∃ A : Fin r → Fin r → ℝ, ∀ i j,kernel A i j=(T i j:ℝ) := by + obtain ⟨B,hB⟩ := CStarAlgebra.nonneg_iff_eq_star_mul_self.mp (gramBlock_posSemidef hT).nonneg + refine ⟨fun i k => B k i,fun i j => ?_⟩ + have h := congrArg (fun M : Matrix (Fin r) (Fin r) ℝ => M i j) hB + simpa only [overlapMatrix,Matrix.mul_apply,Matrix.star_apply,star_trivial,kernel] using h.symm + +def gramFactor {r : ℕ} (T : GramBlock r) : Fin r → Fin r → ℝ := + Classical.choose (exists_gramFactor T.property) + +lemma kernel_gramFactor {r : ℕ} (T : GramBlock r) (i j : Fin r) : + kernel (gramFactor T) i j=(T.val i j:ℝ) := Classical.choose_spec (exists_gramFactor T.property) i j + +lemma gramFactor_diag {r : ℕ} (T : GramBlock r) (i : Fin r) : + kernel (gramFactor T) i i=1 := (kernel_gramFactor T i i).trans (T.property.2.1 i) + + + +def gramPressure {r : ℕ} (T : GramBlock r) (β : ℝ) : ℝ := + expected (fun i k => β*gramFactor T i k)-Real.log (r:ℝ) + +lemma gramPressure_eq {r : ℕ} {κ : Type*} [Fintype κ] (T : GramBlock r) (β : ℝ) + (A : Fin r → κ → ℝ) (hA : ∀ i j,kernel A i j=β^2*(T.val i j:ℝ)) : + expected A-Real.log (r:ℝ)=gramPressure T β := by + rcases eq_or_ne r 0 with rfl | hr + · simp only [gramPressure,expected,logPartition,partition,Finset.univ_eq_empty,Finset.sum_empty,Real.log_zero,integral_zero] + · let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp (Nat.pos_of_ne_zero hr) + unfold gramPressure + congr 1 + apply expected_logPartition_eq_of_kernel + intro i j + rw [kernel_scale,kernel_gramFactor,hA] + +lemma gramEntry_dist {r : ℕ} (T S : GramBlock r) (i j : Fin r) : + |(T.val i j:ℝ)-(S.val i j:ℝ)|≤dist T S := by + change dist (T.val i j) (S.val i j)≤dist T.val S.val + exact (dist_le_pi_dist (T.val i) (S.val i) j).trans (dist_le_pi_dist T.val S.val i) + +lemma gramPressure_lipschitz_bound {r : ℕ} (hr : 0 β*gramFactor S i k + let B := fun i k => β*gramFactor T i k + have hinc (i j : Fin r) : |ParisiInterpolation.increment B i j-ParisiInterpolation.increment A i j|≤ + 2*β^2*dist T S := by + simp only [increment_eq_kernel,B,A,kernel_scale,kernel_gramFactor,T.property.2.1,S.property.2.1] + have he : β^2*1+β^2*1-2*(β^2*(T.val i j:ℝ))- + (β^2*1+β^2*1-2*(β^2*(S.val i j:ℝ)))= + -2*β^2*((T.val i j:ℝ)-(S.val i j:ℝ)) := by ring + rw [he,abs_mul,abs_mul,abs_of_nonneg (sq_nonneg β)] + norm_num only [abs_neg,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + exact mul_le_mul_of_nonneg_left (gramEntry_dist T S i j) (by positivity) + have h := expected_difference_le A B (by positivity : 0≤2*β^2*dist T S) hinc + simpa only [gramPressure,sub_sub_sub_cancel_right] using h.trans_eq (by ring) + +lemma continuous_gramPressure {r : ℕ} (hr : 0 gramPressure T β) := by + have h : LipschitzWith ⟨β^2*Real.pi/2,by positivity⟩ (fun T : GramBlock r => gramPressure T β) := by + apply LipschitzWith.of_dist_le_mul + intro T S + exact gramPressure_lipschitz_bound hr T S β + exact h.continuous + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +def signBool (b : Bool) : ℝ := if b then 1 else -1 + +lemma signBool_sq (b : Bool) : signBool b^2=1 := by cases b <;> norm_num [signBool] + +def doubled (x z : ι → ℝ) : ι × Bool → ℝ := fun s => x s.1+signBool s.2*z s.1 + +omit [Nonempty ι] in +lemma partition_doubled (x z : ι → ℝ) : + partition (doubled x z)=∑ s,Real.exp (x s)*(2*Real.cosh (z s)) := by + simp only [partition,doubled,Fintype.sum_prod_type,Fintype.sum_bool] + apply Finset.sum_congr rfl + intro s _ + simp only [signBool,Bool.false_eq_true,ite_false,ite_true,one_mul,neg_one_mul, + Real.cosh_eq,Real.exp_add] + ring + +lemma log_average_cosh (x z : ι → ℝ) : + Real.log (average x (fun s => 2*Real.cosh (z s)))=logPartition (doubled x z)-logPartition x := by + have hp : partition (doubled x z)=partition x*average x (fun s => 2*Real.cosh (z s)) := by + rw [partition_doubled,partition_mul_average] + rw [logPartition,hp,Real.log_mul (partition_pos x).ne' + (average_pos x _ (fun s => by positivity)).ne'] + simp only [logPartition,add_sub_cancel_left] + +def gaussianCoshAverage (x : ι → ℝ) (A : ι → κ → ℝ) : ℝ := + ∫ z,Real.log (average x (fun s => 2*Real.cosh (field A z s))) ∂gaussianLaw κ + +lemma integrable_gaussianCoshAverage (x : ι → ℝ) (A : ι → κ → ℝ) : + Integrable (fun z => Real.log (average x (fun s => 2*Real.cosh (field A z s)))) (gaussianLaw κ) := by + simp_rw [log_average_cosh] + exact (integrable_logPartition (fun s : ι × Bool => (integrable_const (x s.1)).add + ((integrable_field A s.1).const_mul (signBool s.2)))).sub (integrable_const _) + +omit [Fintype ι] [Nonempty ι] in +lemma empirical_log_cosh {r : ℕ} (hr : 0 2*Real.cosh (f s)) σ)= + logPartition (fun s : Fin r × Bool => signBool s.2*f (σ s.1))-Real.log (r:ℝ) := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + have he : partition (fun s : Fin r × Bool => signBool s.2*f (σ s.1))= + ∑ i,2*Real.cosh (f (σ i)) := by + have h := partition_doubled (fun _ : Fin r => 0) (fun i => f (σ i)) + change partition (fun s : Fin r × Bool => 0+signBool s.2*f (σ s.1))=∑ i,Real.exp 0*(2*Real.cosh (f (σ i))) at h + simp only [zero_add,Real.exp_zero,one_mul] at h + exact h + unfold logPartition empiricalMean + rw [← he,Real.log_div (partition_pos _).ne' (Nat.cast_ne_zero.mpr hr.ne')] + +omit [Fintype ι] [Nonempty ι] in +lemma integrable_empirical_log_cosh {r : ℕ} (hr : 0 Real.log (empiricalMean (fun s => 2*Real.cosh (field A z s)) σ)) (gaussianLaw κ) := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + simp_rw [empirical_log_cosh hr] + exact (integrable_logPartition (fun s : Fin r × Bool => (integrable_field A (σ s.1)).const_mul (signBool s.2))).sub (integrable_const _) + +def sampleCoshPressure {r : ℕ} (A : ι → κ → ℝ) (σ : Fin r → ι) : ℝ := + expected (fun s : Fin r × Bool => fun k => signBool s.2*A (σ s.1) k)-Real.log (r:ℝ) + +omit [Fintype ι] [Nonempty ι] in +lemma integral_empirical_log_cosh {r : ℕ} (hr : 0 2*Real.cosh (field A z s)) σ) ∂gaussianLaw κ)=sampleCoshPressure A σ := by + let : Nonempty (Fin r) := Fin.pos_iff_nonempty.mp hr + simp_rw [empirical_log_cosh hr] + rw [integral_sub (integrable_logPartition (fun s : Fin r × Bool => (integrable_field A (σ s.1)).const_mul (signBool s.2))) (integrable_const _)] + simp only [integral_const,probReal_univ,one_smul] + unfold sampleCoshPressure expected + congr 2 + ext z + congr 1 + ext s + change signBool s.2*(∑ k,A (σ s.1) k*z k)=∑ k,(signBool s.2*A (σ s.1) k)*z k + simp only [Finset.mul_sum,mul_assoc] + +lemma cosh_squared_bound (y : ℝ) : (2*Real.cosh y)^2≤2*(Real.exp (2*y)+Real.exp ((-2)*y)) := by + have h : 0≤(Real.exp y-Real.exp (-y))^2 := sq_nonneg _ + have he : (Real.exp y)^2=Real.exp (2*y) := by rw [pow_two,← Real.exp_add]; congr 1; ring + have he' : (Real.exp (-y))^2=Real.exp ((-2)*y) := by rw [pow_two,← Real.exp_add]; congr 1; ring + rw [Real.cosh_eq] + nlinarith [he,he'] + +lemma cosh_inv_squared_bound (y : ℝ) : (2*Real.cosh y)⁻¹^2≤1 := by + have hc := Real.one_le_cosh y + have hp : 0<2*Real.cosh y := by positivity + have h : (2*Real.cosh y)⁻¹≤1 := (inv_le_one₀ hp).mpr (by linarith) + exact (sq_le_one_iff_abs_le_one _).mpr (by rwa [abs_of_nonneg (inv_nonneg.mpr hp.le)]) + +lemma average_cosh_squared_bound (x : ι → ℝ) (f : ι → ℝ) : + average x (fun s => (2*Real.cosh (f s))^2)≤ + 2*(average x (fun s => Real.exp (2*f s))+average x (fun s => Real.exp ((-2)*f s))) := by + change (∑ s,weight x s*(2*Real.cosh (f s))^2)≤_ + calc + _ ≤ ∑ s,weight x s*(2*(Real.exp (2*f s)+Real.exp ((-2)*f s))) := by + exact Finset.sum_le_sum fun s _ => mul_le_mul_of_nonneg_left (cosh_squared_bound (f s)) (weight_pos x s).le + _ = _ := by simp only [average,Finset.mul_sum,← Finset.sum_add_distrib]; apply Finset.sum_congr rfl; intro s _; ring + +lemma average_cosh_inverse_bound (x : ι → ℝ) (f : ι → ℝ) : + average x (fun s => (2*Real.cosh (f s))⁻¹^2)≤1 := by + calc + _ ≤ ∑ s,weight x s*1 := Finset.sum_le_sum fun s _ => + mul_le_mul_of_nonneg_left (cosh_inv_squared_bound (f s)) (weight_pos x s).le + _ = _ := by simp only [mul_one,sum_weight] + +theorem gaussian_cosh_sample_error {r : ℕ} (hr : 0 + Real.log (empiricalMean (fun s => 2*Real.cosh (field A z s)) σ)) + let g (z : κ → ℝ) := Real.log (average x (fun s => 2*Real.cosh (field A z s))) + have hf : Integrable f (gaussianLaw κ) := integrable_finsetSum _ + (fun σ _ => (integrable_empirical_log_cosh hr A σ).const_mul _) + have hg : Integrable g (gaussianLaw κ) := integrable_gaussianCoshAverage x A + have he : (∫ z,f z ∂gaussianLaw κ)=replicaMean x (sampleCoshPressure (r:=r) A) := by + rw [show f=(fun z => ∑ σ : Fin r → ι, replicaWeight x σ*Real.log (empiricalMean (fun s => 2*Real.cosh (field A z s)) σ)) from rfl, + integral_finsetSum _ (fun σ _ => (integrable_empirical_log_cosh hr A σ).const_mul _)] + simp only [integral_const_mul,integral_empirical_log_cosh hr,replicaMean] + have hb (z : κ → ℝ) : |f z-g z|≤ + (2*t/(r:ℝ))*(average x (fun s => Real.exp (2*field A z s))+ + average x (fun s => Real.exp ((-2)*field A z s)))+t⁻¹ := by + have h := empirical_log_mean_error hr x (fun s => 2*Real.cosh (field A z s)) (fun s => by positivity) ht + have h1 := mul_le_mul_of_nonneg_left (average_cosh_squared_bound x (field A z)) (by positivity : 0≤t/(r:ℝ)) + have h2 := mul_le_mul_of_nonneg_left (average_cosh_inverse_bound x (field A z)) (inv_nonneg.mpr ht.le) + exact h.trans ((add_le_add h1 h2).trans_eq (by ring)) + rw [← he] + change |(∫ z,f z ∂gaussianLaw κ)-(∫ z,g z ∂gaussianLaw κ)|≤_ + rw [← integral_sub hf hg] + apply abs_integral_le_integral_abs.trans + have hh := integral_mono (hf.sub hg).abs + (((integrable_average_exp_field x A 2).add (integrable_average_exp_field x A (-2))).const_mul (2*t/(r:ℝ)) |>.add (integrable_const t⁻¹)) hb + simp only [Pi.add_apply,Pi.sub_apply] at hh + have hi : Integrable (fun z => average x (fun s => Real.exp (2*field A z s))+average x (fun s => Real.exp ((-2)*field A z s))) (gaussianLaw κ) := + (integrable_average_exp_field x A 2).add (integrable_average_exp_field x A (-2)) + rw [integral_add (hi.const_mul (2*t/(r:ℝ))) (integrable_const t⁻¹), + integral_const_mul,integral_add (integrable_average_exp_field x A 2) (integrable_average_exp_field x A (-2)), + integral_const,probReal_univ,one_smul] at hh + have h1 := integral_average_exp_field_le x A hM 2 + have h2 := integral_average_exp_field_le x A hM (-2) + have h := mul_le_mul_of_nonneg_left (add_le_add h1 h2) (by positivity : 0≤2*t/(r:ℝ)) + apply hh.trans ((add_le_add h (le_refl t⁻¹)).trans_eq _) + norm_num only [pow_two,neg_mul_neg,mul_one] + congr 1 + ring_nf + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def coshGramCoeff {r : ℕ} (T : GramBlock r) (β : ℝ) : (Fin r × Bool) → Fin r → ℝ := + fun s k => signBool s.2*β*gramFactor T s.1 k + +lemma kernel_coshGramCoeff {r : ℕ} (T : GramBlock r) (β : ℝ) (s t : Fin r × Bool) : + kernel (coshGramCoeff T β) s t=signBool s.2*signBool t.2*β^2*(T.val s.1 t.1:ℝ) := by + have he : kernel (coshGramCoeff T β) s t= + (signBool s.2*signBool t.2*β^2)*kernel (gramFactor T) s.1 t.1 := by + simp only [kernel,coshGramCoeff,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + rw [he,kernel_gramFactor] + +lemma diag_coshGramCoeff {r : ℕ} (T : GramBlock r) (β : ℝ) (s : Fin r × Bool) : + kernel (coshGramCoeff T β) s s=β^2 := by + rw [kernel_coshGramCoeff,T.property.2.1 s.1,← pow_two,signBool_sq,one_mul,mul_one] + +def squareGramCoeff {r : ℕ} (T : GramBlock r) (β : ℝ) : Fin r → (Fin r × Fin r) → ℝ := + fun i k => (β/Real.sqrt 2)*gramFactor T i k.1*gramFactor T i k.2 + +lemma kernel_squareGramCoeff {r : ℕ} (T : GramBlock r) (β : ℝ) (i j : Fin r) : + kernel (squareGramCoeff T β) i j=β^2/2*(T.val i j:ℝ)^2 := by + have he : kernel (squareGramCoeff T β) i j= + (β/Real.sqrt 2)^2*(kernel (gramFactor T) i j)^2 := by + simp only [kernel,squareGramCoeff,Fintype.sum_prod_type,pow_two,Finset.sum_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + apply Finset.sum_congr rfl + intro l _ + ring + rw [he,kernel_gramFactor,div_pow,Real.sq_sqrt (by norm_num : (0:ℝ)≤2)] + +lemma diag_squareGramCoeff {r : ℕ} (T : GramBlock r) (β : ℝ) (i : Fin r) : + kernel (squareGramCoeff T β) i i=β^2/2 := by + rw [kernel_squareGramCoeff,T.property.2.1 i,one_pow,mul_one] + +def coshGramPressure {r : ℕ} (T : GramBlock r) (β : ℝ) : ℝ := + expected (coshGramCoeff T β)-Real.log (r:ℝ) + +def squareGramPressure {r : ℕ} (T : GramBlock r) (β : ℝ) : ℝ := + expected (squareGramCoeff T β)-Real.log (r:ℝ) + +def cavityGramObservable {r : ℕ} (T : GramBlock r) (β : ℝ) : ℝ := + coshGramPressure T β-squareGramPressure T β + +lemma abs_signBool (b : Bool) : |signBool b|=1 := by cases b <;> norm_num [signBool] + +lemma cosh_kernel_dist {r : ℕ} (T S : GramBlock r) (β : ℝ) (s t : Fin r × Bool) : + |kernel (coshGramCoeff T β) s t-kernel (coshGramCoeff S β) s t|≤β^2*dist T S := by + rw [kernel_coshGramCoeff,kernel_coshGramCoeff,← mul_sub,abs_mul,abs_mul,abs_mul, + abs_signBool,abs_signBool,abs_of_nonneg (sq_nonneg β),one_mul,one_mul] + exact mul_le_mul_of_nonneg_left (gramEntry_dist T S s.1 t.1) (sq_nonneg β) + +lemma coshGramPressure_lipschitz {r : ℕ} (hr : 0 coshGramPressure T β) := by + have h : LipschitzWith ⟨β^2*Real.pi/2,by positivity⟩ (fun T : GramBlock r => coshGramPressure T β) := by + apply LipschitzWith.of_dist_le_mul + intro T S + exact coshGramPressure_lipschitz hr T S β + exact h.continuous + +lemma continuous_squareGramPressure {r : ℕ} (hr : 0 squareGramPressure T β) := by + have h : LipschitzWith ⟨β^2*Real.pi/2,by positivity⟩ (fun T : GramBlock r => squareGramPressure T β) := by + apply LipschitzWith.of_dist_le_mul + intro T S + exact squareGramPressure_lipschitz hr T S β + exact h.continuous + +lemma continuous_cavityGramObservable {r : ℕ} (hr : 0 cavityGramObservable T β) := + (continuous_coshGramPressure hr β).sub (continuous_squareGramPressure hr β) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ κ₂ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] [Fintype κ₂] + +omit [Fintype ι] [Nonempty ι] in +lemma integrable_field_prod (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) (s : ι) : + Integrable (fun p : (κ → ℝ) × (κ₂ → ℝ) => field A p.1 s+field B p.2 s) + ((gaussianLaw κ).prod (gaussianLaw κ₂)) := + ((integrable_field A s).comp_fst _).add ((integrable_field B s).comp_snd _) + +lemma expected_independent_integral (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) : + expected (independentCoeff A B)= + ∫ x,∫ y,logPartition (fun s => field A x s+field B y s) ∂gaussianLaw κ₂ ∂gaussianLaw κ := by + let T : ((κ → ℝ) × (κ₂ → ℝ)) ≃ᵐ ((κ ⊕ κ₂) → ℝ) := + (MeasurableEquiv.sumPiEquivProdPi (fun _ : κ ⊕ κ₂ => ℝ)).symm + have hp : MeasurePreserving T ((gaussianLaw κ).prod (gaussianLaw κ₂)) (gaussianLaw (κ ⊕ κ₂)) := + measurePreserving_sumPiEquivProdPi_symm (fun _ => gaussianReal 0 1) + unfold expected + rw [← hp.integral_comp'] + have he (p : (κ → ℝ) × (κ₂ → ℝ)) : field (independentCoeff A B) (T p)=fun s => field A p.1 s+field B p.2 s := by + ext s + simp only [field,independentCoeff,Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr] + rfl + simp_rw [he] + exact integral_prod _ (integrable_logPartition (integrable_field_prod A B)) + +lemma integrable_logAverage_prod (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) : + Integrable (fun p : (κ → ℝ) × (κ₂ → ℝ) => + Real.log (average (field A p.1) (fun s => Real.exp (field B p.2 s)))) + ((gaussianLaw κ).prod (gaussianLaw κ₂)) := by + simp_rw [log_average_exp] + exact (integrable_logPartition (integrable_field_prod A B)).sub + ((integrable_logPartition (integrable_field A)).comp_fst _) + +lemma integrable_gaussianLogAverage_field (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) : + Integrable (fun x => gaussianLogAverage (field A x) B) (gaussianLaw κ) := + (integrable_logAverage_prod A B).integral_prod_left + +lemma integral_gaussianLogAverage (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) : + (∫ x,gaussianLogAverage (field A x) B ∂gaussianLaw κ)= + expected (independentCoeff A B)-expected A := by + unfold gaussianLogAverage + rw [← integral_prod _ (integrable_logAverage_prod A B)] + simp_rw [log_average_exp] + rw [integral_sub (integrable_logPartition (integrable_field_prod A B)) + ((integrable_logPartition (integrable_field A)).comp_fst _), + integral_prod _ (integrable_logPartition (integrable_field_prod A B)), + ← expected_independent_integral,integral_fun_fst (fun x : κ → ℝ => logPartition (field A x))] + simp only [probReal_univ,one_smul] + rfl + +lemma integrable_coshAverage_prod (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) : + Integrable (fun p : (κ → ℝ) × (κ₂ → ℝ) => + Real.log (average (field A p.1) (fun s => 2*Real.cosh (field B p.2 s)))) + ((gaussianLaw κ).prod (gaussianLaw κ₂)) := by + simp_rw [log_average_cosh] + exact (integrable_logPartition (fun s : ι × Bool => + ((integrable_field A s.1).comp_fst _).add (((integrable_field B s.1).comp_snd _).const_mul (signBool s.2)))).sub + ((integrable_logPartition (integrable_field A)).comp_fst _) + +lemma integrable_gaussianCoshAverage_field (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) : + Integrable (fun x => gaussianCoshAverage (field A x) B) (gaussianLaw κ) := + (integrable_coshAverage_prod A B).integral_prod_left + +def cavityDoubledCoeff (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) : ι × Bool → (κ ⊕ κ₂) → ℝ := + independentCoeff (fun s => A s.1) (fun s k => signBool s.2*B s.1 k) + +lemma integral_gaussianCoshAverage (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) : + (∫ x,gaussianCoshAverage (field A x) B ∂gaussianLaw κ)= + expected (cavityDoubledCoeff A B)-expected A := by + unfold gaussianCoshAverage + rw [← integral_prod _ (integrable_coshAverage_prod A B)] + simp_rw [log_average_cosh] + have hi : Integrable (fun p : (κ → ℝ) × (κ₂ → ℝ) => + logPartition (doubled (field A p.1) (field B p.2))) + ((gaussianLaw κ).prod (gaussianLaw κ₂)) := integrable_logPartition (fun s : ι × Bool => + ((integrable_field A s.1).comp_fst (gaussianLaw κ₂)).add + (((integrable_field B s.1).comp_snd (gaussianLaw κ)).const_mul (signBool s.2))) + rw [integral_sub hi ((integrable_logPartition (integrable_field A)).comp_fst _), + integral_prod _ hi,integral_fun_fst (fun x : κ → ℝ => logPartition (field A x))] + simp only [probReal_univ,one_smul] + unfold cavityDoubledCoeff + rw [expected_independent_integral] + congr 1 + apply integral_congr_ae + filter_upwards with x + apply integral_congr_ae + filter_upwards with y + congr 1 + ext s + change field A x s.1+signBool s.2*(∑ k,B s.1 k*y k)= + field A x s.1+∑ k,(signBool s.2*B s.1 k)*y k + simp only [Finset.mul_sum,mul_assoc] + +theorem averaged_gaussian_sample_error {r : ℕ} (hr : 0 gaussian_sample_error hr (field A x) B hM ht) + simpa only [Pi.sub_apply,integral_const,probReal_univ,one_smul] using h + +theorem averaged_gaussian_cosh_sample_error {r : ℕ} (hr : 0 gaussian_cosh_sample_error hr (field A x) B hM ht) + simpa only [Pi.sub_apply,integral_const,probReal_univ,one_smul] using h + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/IntegrablePdfMul.lean b/lean/OAI/Probability/ParisiFinite/IntegrablePdfMul.lean new file mode 100644 index 0000000000000000000000000000000000000000..f5fef81e1130887db9092f09b9cd16da2ce2c7b8 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/IntegrablePdfMul.lean @@ -0,0 +1,729 @@ +import Mathlib + +namespace OAI + +/-! Integrable Pdf Mul. -/ + +noncomputable section + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter +namespace SKGaussian + + + +theorem integrable_pdf_mul {f : ℝ → ℝ} (hf : Integrable f (gaussianReal 0 1)) : + Integrable (fun x => gaussianPDFReal 0 1 x * f x) := by + rw [gaussianReal_of_var_ne_zero _ one_ne_zero] at hf + have h := (integrable_withDensity_iff_integrable_smul' + (measurable_gaussianPDF 0 1) (ae_of_all _ fun x => (gaussianPDF_lt_top (x := x)))).1 hf + simpa only [toReal_gaussianPDF, smul_eq_mul] using h + + +theorem hasDerivAt_standardDensity (x : ℝ) : + HasDerivAt (gaussianPDFReal 0 1) (-x * gaussianPDFReal 0 1 x) x := by + have hp : HasDerivAt (fun y : ℝ => -(y ^ 2) / 2) (-x) x := by + convert (((hasDerivAt_id x).fun_pow 2).fun_neg.div_const 2) using 1 <;> try rfl + norm_num + ring + simp only [gaussianPDFReal_def, NNReal.coe_one, sub_zero, mul_one] + convert hp.exp.const_mul (Real.sqrt (2 * Real.pi))⁻¹ using 1 + ring + + + +theorem integral_mul_eq_integral_deriv {f f' : ℝ → ℝ} + (hd : ∀ x, HasDerivAt f (f' x) x) + (hf : Integrable f (gaussianReal 0 1)) + (hf' : Integrable f' (gaussianReal 0 1)) + (hxf : Integrable (fun x => x * f x) (gaussianReal 0 1)) : + (∫ x, x * f x ∂gaussianReal 0 1) = ∫ x, f' x ∂gaussianReal 0 1 := by + have h := integral_mul_deriv_eq_deriv_mul_of_integrable + (u := f) (u' := f') (v := gaussianPDFReal 0 1) + (v' := fun x => -x * gaussianPDFReal 0 1 x) + (fun x _ => hd x) (fun x _ => hasDerivAt_standardDensity x) + (by convert (integrable_pdf_mul hxf).neg using 1; funext x; simp only [Pi.mul_apply, Pi.neg_apply]; ring) + (by convert integrable_pdf_mul hf' using 1; funext x; simp only [Pi.mul_apply]; ring) + (by convert integrable_pdf_mul hf using 1; funext x; simp only [Pi.mul_apply]; ring) + simp only [neg_mul, mul_neg, integral_neg] at h + rw [integral_gaussianReal_eq_integral_smul one_ne_zero, + integral_gaussianReal_eq_integral_smul one_ne_zero] + simp only [smul_eq_mul] + have heq := neg_injective h + convert heq using 1 <;> congr 1 <;> funext x <;> ring + + +def standardLaw (n : ℕ) : Measure (Fin n → ℝ) := + Measure.pi fun _ => gaussianReal 0 1 + +instance (n : ℕ) : IsProbabilityMeasure (standardLaw n) := by + unfold standardLaw + infer_instance + + + +theorem integral_coord_mul_eq {n : ℕ} (k : Fin (n + 1)) + {f g : (Fin (n + 1) → ℝ) → ℝ} + (hd : ∀ (y : Fin n → ℝ) z, + HasDerivAt (fun s => f (k.insertNth s y)) (g (k.insertNth z y)) z) + (hf : Integrable f (standardLaw (n + 1))) + (hg : Integrable g (standardLaw (n + 1))) + (hxf : Integrable (fun x => x k * f x) (standardLaw (n + 1))) : + (∫ x, x k * f x ∂standardLaw (n + 1)) = ∫ x, g x ∂standardLaw (n + 1) := by + let e : (ℝ × (Fin n → ℝ)) ≃ᵐ (Fin (n + 1) → ℝ) := + (MeasurableEquiv.piFinSuccAbove (fun _ => ℝ) k).symm + have hm : MeasurePreserving e ((gaussianReal 0 1).prod (standardLaw n)) + (standardLaw (n + 1)) := + (measurePreserving_piFinSuccAbove (fun _ => gaussianReal 0 1) k).symm + have hfp := (hm.integrable_comp hf.aestronglyMeasurable).mpr hf + have hgp := (hm.integrable_comp hg.aestronglyMeasurable).mpr hg + have hx := (hm.integrable_comp hxf.aestronglyMeasurable).mpr hxf + rw [← hm.integral_comp' (fun x => x k * f x), ← hm.integral_comp' g] + change (∫ x, ((fun x => x k * f x) ∘ e) x ∂(gaussianReal 0 1).prod (standardLaw n)) = + ∫ x, (g ∘ e) x ∂(gaussianReal 0 1).prod (standardLaw n) + rw [integral_prod_symm _ hx, integral_prod_symm _ hgp] + apply integral_congr_ae + filter_upwards [hfp.prod_left_ae, hgp.prod_left_ae, hx.prod_left_ae] with y hfy hgy hxy + have he (z : ℝ) : e (z, y) = k.insertNth z y := rfl + simp only [Function.comp_apply, he, Fin.insertNth_apply_same] at hfy hgy hxy ⊢ + exact integral_mul_eq_integral_deriv (hd y) hfy hgy hxy + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + + +def partition (x : ι → ℝ) : ℝ := ∑ i, Real.exp (x i) + +def weight (x : ι → ℝ) (i : ι) : ℝ := Real.exp (x i) / partition x + +def logPartition (x : ι → ℝ) : ℝ := Real.log (partition x) + +def finiteMax (x : ι → ℝ) : ℝ := Finset.univ.sup' Finset.univ_nonempty x + +theorem partition_pos (x : ι → ℝ) : 0 < partition x := + Finset.sum_pos (fun _ _ => Real.exp_pos _) Finset.univ_nonempty + +theorem weight_pos (x : ι → ℝ) (i : ι) : 0 < weight x i := + div_pos (Real.exp_pos _) (partition_pos x) + +theorem sum_weight (x : ι → ℝ) : ∑ i, weight x i = 1 := by + simpa only [weight, ← Finset.sum_div, partition] using div_self (partition_pos x).ne' + +theorem weight_le_one (x : ι → ℝ) (i : ι) : weight x i ≤ 1 := by + rw [weight, div_le_one (partition_pos x)] + exact Finset.single_le_sum (fun j _ => (Real.exp_pos _).le) (Finset.mem_univ i) + +omit [Nonempty ι] in +theorem continuous_partition : Continuous (@partition ι _) := by + unfold partition + fun_prop + +theorem continuous_weight (i : ι) : Continuous (fun x : ι → ℝ => weight x i) := by + unfold weight + exact (Real.continuous_exp.comp (continuous_apply i)).div continuous_partition + (fun x => (partition_pos x).ne') + +theorem continuous_logPartition : Continuous (@logPartition ι _) := + continuous_partition.log (fun x => (partition_pos x).ne') + +theorem le_finiteMax (x : ι → ℝ) (i : ι) : x i ≤ finiteMax x := + Finset.le_sup' x (Finset.mem_univ i) + +theorem le_logPartition (x : ι → ℝ) (i : ι) : x i ≤ logPartition x := by + rw [logPartition, Real.le_log_iff_exp_le (partition_pos x)] + exact Finset.single_le_sum (fun j _ => (Real.exp_pos _).le) (Finset.mem_univ i) + +theorem finiteMax_le_logPartition (x : ι → ℝ) : finiteMax x ≤ logPartition x := by + exact Finset.sup'_le Finset.univ_nonempty _ (fun i _ => le_logPartition x i) + +theorem logPartition_le (x : ι → ℝ) : + logPartition x ≤ finiteMax x + Real.log (Fintype.card ι) := by + have hc : 0 < (Fintype.card ι : ℝ) := Nat.cast_pos.mpr Fintype.card_pos + calc + logPartition x ≤ Real.log ((Fintype.card ι : ℝ) * Real.exp (finiteMax x)) := by + apply Real.log_le_log (partition_pos x) + calc + partition x ≤ ∑ _ : ι, Real.exp (finiteMax x) := + Finset.sum_le_sum fun i _ => Real.exp_le_exp.mpr (le_finiteMax x i) + _ = _ := by simp + _ = _ := by rw [Real.log_mul hc.ne' (Real.exp_pos _).ne', Real.log_exp]; ring + +theorem abs_weight_sum_le (x v : ι → ℝ) {M : ℝ} (hM : ∀ i, |v i| ≤ M) : + |∑ i, weight x i * v i| ≤ M := by + calc + |∑ i, weight x i * v i| ≤ ∑ i, |weight x i * v i| := Finset.abs_sum_le_sum_abs _ _ + _ = ∑ i, weight x i * |v i| := by + simp only [abs_mul, abs_of_pos (weight_pos _ _)] + _ ≤ ∑ i, weight x i * M := Finset.sum_le_sum fun i _ => + mul_le_mul_of_nonneg_left (hM i) (weight_pos x i).le + _ = M := by rw [← Finset.sum_mul, sum_weight, one_mul] + +theorem hasDerivAt_logPartition {f : ℝ → ι → ℝ} {v : ι → ℝ} {t : ℝ} + (hf : ∀ i, HasDerivAt (fun s => f s i) (v i) t) : + HasDerivAt (fun s => logPartition (f s)) + (∑ i, weight (f t) i * v i) t := by + have h := (HasDerivAt.fun_sum (fun i _ => (hf i).exp)).log (partition_pos (f t)).ne' + convert h using 1 <;> try rfl + simp only [weight, div_mul_eq_mul_div, ← Finset.sum_div, partition] + +theorem hasDerivAt_weight {f : ℝ → ι → ℝ} {v : ι → ℝ} {t : ℝ} + (hf : ∀ i, HasDerivAt (fun s => f s i) (v i) t) (i : ι) : + HasDerivAt (fun s => weight (f s) i) + (weight (f t) i * (v i - ∑ j, weight (f t) j * v j)) t := by + have h := (hf i).exp.div (HasDerivAt.fun_sum (fun j _ => (hf j).exp)) + (partition_pos (f t)).ne' + convert h using 1 <;> try rfl + simp only [weight, div_mul_eq_mul_div, ← Finset.sum_div, partition] + field_simp + +theorem logPartition_abs_le (x : ι → ℝ) : + |logPartition x| ≤ (∑ i, |x i|) + Real.log (Fintype.card ι) := by + have hxi (i : ι) : |x i| ≤ ∑ j, |x j| := + Finset.single_le_sum (fun j _ => abs_nonneg (x j)) (Finset.mem_univ i) + have hm : finiteMax x ≤ ∑ i, |x i| := + Finset.sup'_le Finset.univ_nonempty _ (fun i _ => (le_abs_self _).trans (hxi i)) + have hlog := Real.log_natCast_nonneg (Fintype.card ι) + have hlo : -(∑ i, |x i|) ≤ logPartition x := by + let i : ι := Classical.choice inferInstance + exact (neg_le_of_abs_le (hxi i)).trans (le_logPartition x i) + exact abs_le.mpr ⟨by linarith, (logPartition_le x).trans (add_le_add hm le_rfl)⟩ + +theorem integrable_logPartition {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {f : Ω → ι → ℝ} + (hf : ∀ i, Integrable (fun x => f x i) μ) : + Integrable (fun x => logPartition (f x)) μ := by + apply ((integrable_finsetSum _ fun i _ => (hf i).abs).add + (integrable_const (Real.log (Fintype.card ι)))).mono' + · exact continuous_logPartition.comp_aestronglyMeasurable + (integrable_pi_iff.mpr hf).aestronglyMeasurable + · exact ae_of_all _ fun x => by simpa only [Real.norm_eq_abs, Pi.add_apply] using logPartition_abs_le (f x) + + +def linearField {n : ℕ} (A : ι → Fin n → ℝ) (x : Fin n → ℝ) (i : ι) : ℝ := + ∑ k, A i k * x k + +omit [Fintype ι] [Nonempty ι] in +theorem continuous_linearField {n : ℕ} (A : ι → Fin n → ℝ) : + Continuous (linearField A) := by + unfold linearField + fun_prop + +theorem integrable_coordinate {n : ℕ} (k : Fin n) : + Integrable (fun x : Fin n → ℝ => x k) (standardLaw n) := by + apply (measurePreserving_eval (fun _ : Fin n => gaussianReal 0 1) k).integrable_comp + (measurable_id.aestronglyMeasurable) |>.mpr + exact MemLp.integrable (by norm_num) (memLp_id_gaussianReal (μ := 0) (v := 1) 1) + +omit [Fintype ι] [Nonempty ι] in +theorem integrable_linearField {n : ℕ} (A : ι → Fin n → ℝ) (i : ι) : + Integrable (fun x => linearField A x i) (standardLaw n) := + integrable_finsetSum _ fun k _ => (integrable_coordinate k).const_mul (A i k) + +theorem integrable_weight {n : ℕ} (A : ι → Fin n → ℝ) (i : ι) : + Integrable (fun x => weight (linearField A x) i) (standardLaw n) := by + apply (integrable_const (1 : ℝ)).mono' + ((continuous_weight i).comp (continuous_linearField A)).aestronglyMeasurable + exact ae_of_all _ fun x => by + simpa only [Function.comp_apply, Real.norm_eq_abs, abs_of_pos (weight_pos _ _)] using + weight_le_one (linearField A x) i + +omit [Fintype ι] [Nonempty ι] in +theorem hasDerivAt_linearField_insert {n : ℕ} (A : ι → Fin (n + 1) → ℝ) + (k : Fin (n + 1)) (y : Fin n → ℝ) (z : ℝ) (i : ι) : + HasDerivAt (fun s => linearField A (k.insertNth s y) i) (A i k) z := by + have he (s : ℝ) : linearField A (k.insertNth s y) i = + A i k * s + ∑ j : Fin n, A i (k.succAbove j) * y j := by + rw [linearField, Fin.sum_univ_succAbove _ k] + simp + simp_rw [he] + simpa using ((hasDerivAt_id z).const_mul (A i k)).add_const + (∑ j : Fin n, A i (k.succAbove j) * y j) + + +theorem integrable_weight_derivative {n : ℕ} (A : ι → Fin n → ℝ) + (i : ι) (k : Fin n) : + Integrable (fun x => weight (linearField A x) i * + (A i k - ∑ j, weight (linearField A x) j * A j k)) (standardLaw n) := by + apply ((integrable_const (A i k)).sub + (integrable_finsetSum _ fun j _ => (integrable_weight A j).mul_const (A j k))).bdd_mul + ((continuous_weight i).comp (continuous_linearField A)).aestronglyMeasurable + exact ae_of_all _ fun x => by + simpa only [Function.comp_apply, Real.norm_eq_abs, abs_of_pos (weight_pos _ _)] using + weight_le_one (linearField A x) i + +theorem integrable_coord_weight {n : ℕ} (A : ι → Fin n → ℝ) + (i : ι) (k : Fin n) : + Integrable (fun x => x k * weight (linearField A x) i) (standardLaw n) := by + apply (integrable_coordinate k).mul_bdd + ((continuous_weight i).comp (continuous_linearField A)).aestronglyMeasurable + exact ae_of_all _ fun x => by + simpa only [Function.comp_apply, Real.norm_eq_abs, abs_of_pos (weight_pos _ _)] using + weight_le_one (linearField A x) i + + +theorem integral_coord_weight {n : ℕ} (A : ι → Fin n → ℝ) (i : ι) (k : Fin n) : + (∫ x, x k * weight (linearField A x) i ∂standardLaw n) = + ∫ x, weight (linearField A x) i * + (A i k - ∑ j, weight (linearField A x) j * A j k) ∂standardLaw n := by + cases n with + | zero => exact Fin.elim0 k + | succ n => + apply integral_coord_mul_eq k + (fun y z => hasDerivAt_weight (fun j => hasDerivAt_linearField_insert A k y z j) i) + (integrable_weight A i) (integrable_weight_derivative A i k) + (integrable_coord_weight A i k) + +omit [Nonempty ι] in + +theorem weighted_covariance (w a b : ι → ℝ) (hw : ∑ i, w i = 1) : + (∑ i, ∑ j, w i * w j * (a i - a j) * (b i - b j)) = + 2 * ((∑ i, w i * a i * b i) - (∑ i, w i * a i) * (∑ j, w j * b j)) := by + have he (i j : ι) : w i * w j * (a i - a j) * (b i - b j) = + (w i * a i * b i) * w j - (w i * a i) * (w j * b j) - + (w i * b i) * (w j * a j) + w i * (w j * a j * b j) := by ring + simp_rw [he, Finset.sum_add_distrib, Finset.sum_sub_distrib] + simp only [← Finset.mul_sum, ← Finset.sum_mul, hw, one_mul, mul_one] + ring + +omit [Fintype ι] [Nonempty ι] in +theorem linearField_combo {n : ℕ} (A B : ι → Fin n → ℝ) (a b : ℝ) + (x : Fin n → ℝ) (i : ι) : + linearField (fun i k => a * A i k + b * B i k) x i = + a * linearField A x i + b * linearField B x i := by + simp only [linearField, add_mul, Finset.sum_add_distrib, ← mul_assoc, Finset.mul_sum] + +def rotateCoeff {n : ℕ} (A B : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : ℝ := + Real.cos t * A i k + Real.sin t * B i k + +def velocityCoeff {n : ℕ} (A B : ι → Fin n → ℝ) (t : ℝ) (i : ι) (k : Fin n) : ℝ := + -Real.sin t * A i k + Real.cos t * B i k + +omit [Fintype ι] [Nonempty ι] in +theorem hasDerivAt_rotatedField {n : ℕ} (A B : ι → Fin n → ℝ) + (x : Fin n → ℝ) (i : ι) (t : ℝ) : + HasDerivAt (fun s => linearField (rotateCoeff A B s) x i) + (linearField (velocityCoeff A B t) x i) t := by + change HasDerivAt (fun s => linearField (fun i k => Real.cos s * A i k + Real.sin s * B i k) x i) + (linearField (fun i k => -Real.sin t * A i k + Real.cos t * B i k) x i) t + simp_rw [linearField_combo] + exact ((Real.hasDerivAt_cos t).mul_const (linearField A x i)).add + ((Real.hasDerivAt_sin t).mul_const (linearField B x i)) + +theorem continuous_weightedMean {n : ℕ} (A D : ι → Fin n → ℝ) : + Continuous (fun x => ∑ i, weight (linearField A x) i * linearField D x i) := by + apply continuous_finsetSum + intro i _ + exact ((continuous_weight i).comp (continuous_linearField A)).mul + ((continuous_apply i).comp (continuous_linearField D)) + +theorem integrable_weightedMean {n : ℕ} (A D : ι → Fin n → ℝ) : + Integrable (fun x => ∑ i, weight (linearField A x) i * linearField D x i) + (standardLaw n) := by + apply integrable_finsetSum + intro i _ + apply (integrable_linearField D i).bdd_mul + ((continuous_weight i).comp (continuous_linearField A)).aestronglyMeasurable + exact ae_of_all _ fun x => by + simpa only [Function.comp_apply, Real.norm_eq_abs, abs_of_pos (weight_pos _ _)] using + weight_le_one (linearField A x) i + +theorem rotated_derivative_bound {n : ℕ} (A B : ι → Fin n → ℝ) + (x : Fin n → ℝ) (t : ℝ) : + |∑ i, weight (linearField (rotateCoeff A B t) x) i * + linearField (velocityCoeff A B t) x i| ≤ + ∑ i, (|linearField A x i| + |linearField B x i|) := by + apply abs_weight_sum_le + intro i + calc + |linearField (velocityCoeff A B t) x i| = + |-Real.sin t * linearField A x i + Real.cos t * linearField B x i| := by + exact congrArg abs (linearField_combo A B (-Real.sin t) (Real.cos t) x i) + _ ≤ |Real.sin t| * |linearField A x i| + |Real.cos t| * |linearField B x i| := by + simpa only [abs_mul, abs_neg] using abs_add_le + (-Real.sin t * linearField A x i) (Real.cos t * linearField B x i) + _ ≤ |linearField A x i| + |linearField B x i| := by + exact add_le_add (mul_le_of_le_one_left (abs_nonneg _) (Real.abs_sin_le_one t)) + (mul_le_of_le_one_left (abs_nonneg _) (Real.abs_cos_le_one t)) + _ ≤ ∑ j, (|linearField A x j| + |linearField B x j|) := + Finset.single_le_sum (fun j _ => add_nonneg (abs_nonneg (linearField A x j)) + (abs_nonneg (linearField B x j))) (Finset.mem_univ i) + + + +theorem hasDerivAt_expected_rotated {n : ℕ} (A B : ι → Fin n → ℝ) (t : ℝ) : + HasDerivAt (fun s => ∫ x, logPartition (linearField (rotateCoeff A B s) x) ∂standardLaw n) + (∫ x, ∑ i, weight (linearField (rotateCoeff A B t) x) i * + linearField (velocityCoeff A B t) x i ∂standardLaw n) t := by + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le (s := Set.univ) + (bound := fun x => ∑ i, (|linearField A x i| + |linearField B x i|)) + (F' := fun s x => ∑ i, weight (linearField (rotateCoeff A B s) x) i * + linearField (velocityCoeff A B s) x i) + (Filter.univ_mem) ?_ ?_ ?_ ?_ ?_ ?_).2 + · exact Filter.Eventually.of_forall fun s => + (continuous_logPartition.comp (continuous_linearField (rotateCoeff A B s))).aestronglyMeasurable + · exact integrable_logPartition (integrable_linearField (rotateCoeff A B t)) + · exact (continuous_weightedMean (rotateCoeff A B t) (velocityCoeff A B t)).aestronglyMeasurable + · exact ae_of_all _ fun x s _ => by + simpa only [Real.norm_eq_abs] using rotated_derivative_bound A B x s + · exact integrable_finsetSum _ fun i _ => + (integrable_linearField A i).abs.add (integrable_linearField B i).abs + · exact ae_of_all _ fun x s _ => + hasDerivAt_logPartition (fun i => hasDerivAt_rotatedField A B x i s) + + +theorem integral_weightedMean_eq {n : ℕ} (A D : ι → Fin n → ℝ) : + (∫ x, ∑ i, weight (linearField A x) i * linearField D x i ∂standardLaw n) = + ∫ x, ∑ i, ∑ k, D i k * (weight (linearField A x) i * + (A i k - ∑ j, weight (linearField A x) j * A j k)) ∂standardLaw n := by + have hleft (i : ι) (k : Fin n) : + Integrable (fun x => D i k * (x k * weight (linearField A x) i)) (standardLaw n) := + (integrable_coord_weight A i k).const_mul (D i k) + have hright (i : ι) (k : Fin n) : + Integrable (fun x => D i k * (weight (linearField A x) i * + (A i k - ∑ j, weight (linearField A x) j * A j k))) (standardLaw n) := + (integrable_weight_derivative A i k).const_mul (D i k) + calc + _ = ∫ x, ∑ i, ∑ k, D i k * (x k * weight (linearField A x) i) ∂standardLaw n := by + apply integral_congr_ae + exact ae_of_all _ fun x => by + apply Finset.sum_congr rfl + intro i _ + rw [linearField, Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + _ = ∑ i, ∑ k, D i k * (∫ x, x k * weight (linearField A x) i ∂standardLaw n) := by + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ (fun k _ => hleft i k))] + apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum _ (fun k _ => hleft i k)] + simp only [integral_const_mul] + _ = ∑ i, ∑ k, D i k * (∫ x, weight (linearField A x) i * + (A i k - ∑ j, weight (linearField A x) j * A j k) ∂standardLaw n) := by + simp_rw [integral_coord_weight] + _ = _ := by + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ (fun k _ => hright i k))] + apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum _ (fun k _ => hright i k)] + simp only [integral_const_mul] + +omit [Nonempty ι] in +theorem pairwise_covariance {n : ℕ} (A D : ι → Fin n → ℝ) (w : ι → ℝ) + (hw : ∑ i, w i = 1) : + (∑ i, ∑ k, D i k * (w i * (A i k - ∑ j, w j * A j k))) = + (1 / 2 : ℝ) * ∑ i, ∑ j, w i * w j * + ∑ k, (D i k - D j k) * (A i k - A j k) := by + have hk (k : Fin n) : + (∑ i, D i k * (w i * (A i k - ∑ j, w j * A j k))) = + (1 / 2 : ℝ) * ∑ i, ∑ j, w i * w j * (D i k - D j k) * (A i k - A j k) := by + have h := weighted_covariance w (fun i => D i k) (fun i => A i k) hw + have he : (∑ i, D i k * (w i * (A i k - ∑ j, w j * A j k))) = + (∑ i, w i * D i k * A i k) - (∑ i, w i * D i k) * (∑ j, w j * A j k) := by + calc + _ = ∑ i, (w i * D i k * A i k - (w i * D i k) * (∑ j, w j * A j k)) := by + apply Finset.sum_congr rfl + intro i _ + ring + _ = _ := by rw [Finset.sum_sub_distrib, ← Finset.sum_mul] + rw [he, h] + ring + rw [Finset.sum_comm] + simp_rw [hk, ← Finset.mul_sum] + congr 1 + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + + + +theorem integral_weightedMean_eq_pairwise {n : ℕ} (A D : ι → Fin n → ℝ) : + (∫ x, ∑ i, weight (linearField A x) i * linearField D x i ∂standardLaw n) = + ∫ x, (1 / 2 : ℝ) * ∑ i, ∑ j, + weight (linearField A x) i * weight (linearField A x) j * + ∑ k, (D i k - D j k) * (A i k - A j k) ∂standardLaw n := by + rw [integral_weightedMean_eq] + apply integral_congr_ae + exact ae_of_all _ fun x => pairwise_covariance A D (weight (linearField A x)) (sum_weight _) + +omit [Fintype ι] [Nonempty ι] in +theorem rotated_increment_covariance {n : ℕ} (A B : ι → Fin n → ℝ) + (hAB : ∀ i j, ∑ k, A i k * B j k = 0) (i j : ι) (t : ℝ) : + (∑ k, (velocityCoeff A B t i k - velocityCoeff A B t j k) * + (rotateCoeff A B t i k - rotateCoeff A B t j k)) = + Real.sin t * Real.cos t * + ((∑ k, (B i k - B j k) ^ 2) - ∑ k, (A i k - A j k) ^ 2) := by + have hcross : (∑ k, (A i k - A j k) * (B i k - B j k)) = 0 := by + simp_rw [sub_mul, mul_sub, Finset.sum_sub_distrib, hAB] + ring + have he (k : Fin n) : + (velocityCoeff A B t i k - velocityCoeff A B t j k) * + (rotateCoeff A B t i k - rotateCoeff A B t j k) = + Real.sin t * Real.cos t * ((B i k - B j k) ^ 2 - (A i k - A j k) ^ 2) + + (Real.cos t ^ 2 - Real.sin t ^ 2) * ((A i k - A j k) * (B i k - B j k)) := by + unfold velocityCoeff rotateCoeff + ring + simp_rw [he, Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_sub_distrib, hcross] + ring + + + +theorem expected_rotated_derivative_nonneg {n : ℕ} (A B : ι → Fin n → ℝ) + (hAB : ∀ i j, ∑ k, A i k * B j k = 0) + (hinc : ∀ i j, (∑ k, (A i k - A j k) ^ 2) ≤ ∑ k, (B i k - B j k) ^ 2) + {t : ℝ} (ht : t ∈ Set.Icc 0 (Real.pi / 2)) : + 0 ≤ ∫ x, ∑ i, weight (linearField (rotateCoeff A B t) x) i * + linearField (velocityCoeff A B t) x i ∂standardLaw n := by + rw [integral_weightedMean_eq_pairwise] + apply integral_nonneg + intro x + apply mul_nonneg (by norm_num) + apply Finset.sum_nonneg + intro i _ + apply Finset.sum_nonneg + intro j _ + apply mul_nonneg (mul_nonneg (weight_pos _ _).le (weight_pos _ _).le) + rw [rotated_increment_covariance A B hAB] + have hs : 0 ≤ Real.sin t := Real.sin_nonneg_of_nonneg_of_le_pi ht.1 + (ht.2.trans (by linarith [Real.pi_pos])) + have hc : 0 ≤ Real.cos t := Real.cos_nonneg_of_mem_Icc ⟨by linarith [ht.1, Real.pi_pos], ht.2⟩ + exact mul_nonneg (mul_nonneg hs hc) (sub_nonneg.mpr (hinc i j)) + + + +theorem expected_logPartition_le {n : ℕ} (A B : ι → Fin n → ℝ) + (hAB : ∀ i j, ∑ k, A i k * B j k = 0) + (hinc : ∀ i j, (∑ k, (A i k - A j k) ^ 2) ≤ ∑ k, (B i k - B j k) ^ 2) : + (∫ x, logPartition (linearField A x) ∂standardLaw n) ≤ + ∫ x, logPartition (linearField B x) ∂standardLaw n := by + have hc : Continuous (fun t => ∫ x, logPartition (linearField (rotateCoeff A B t) x) ∂standardLaw n) := + continuous_iff_continuousAt.mpr fun t => (hasDerivAt_expected_rotated A B t).continuousAt + have hm := monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc (0 : ℝ) (Real.pi / 2)) + hc.continuousOn (fun t _ => (hasDerivAt_expected_rotated A B t).hasDerivWithinAt) + (fun t ht => expected_rotated_derivative_nonneg A B hAB hinc (interior_subset ht)) + have hpi : 0 ≤ Real.pi / 2 := by positivity + have h := hm (show (0 : ℝ) ∈ Set.Icc 0 (Real.pi / 2) from ⟨le_rfl, hpi⟩) + (show Real.pi / 2 ∈ Set.Icc 0 (Real.pi / 2) from ⟨hpi, le_rfl⟩) hpi + have h0 : rotateCoeff A B 0 = A := by funext i k; simp [rotateCoeff] + have h1 : rotateCoeff A B (Real.pi / 2) = B := by funext i k; simp [rotateCoeff] + simpa only [h0, h1] using h + +theorem finiteMax_abs_le (x : ι → ℝ) : |finiteMax x| ≤ ∑ i, |x i| := by + obtain ⟨i, _, hi⟩ := Finset.exists_mem_eq_sup' (Finset.univ_nonempty : (Finset.univ : Finset ι).Nonempty) x + rw [finiteMax, hi] + exact Finset.single_le_sum (fun j _ => abs_nonneg (x j)) (Finset.mem_univ i) + +theorem continuous_finiteMax : Continuous (@finiteMax ι _ _) := by + exact Continuous.finset_sup'_apply Finset.univ_nonempty fun i _ => continuous_apply i + +theorem integrable_finiteMax {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {f : Ω → ι → ℝ} (hf : ∀ i, Integrable (fun x => f x i) μ) : + Integrable (fun x => finiteMax (f x)) μ := by + apply (integrable_finsetSum _ fun i _ => (hf i).abs).mono' + · exact continuous_finiteMax.comp_aestronglyMeasurable + (integrable_pi_iff.mpr hf).aestronglyMeasurable + · exact ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using finiteMax_abs_le (f x) + +theorem finiteMax_const_mul (x : ι → ℝ) {c : ℝ} (hc : 0 ≤ c) : + finiteMax (fun i => c * x i) = c * finiteMax x := by + apply le_antisymm + · exact Finset.sup'_le Finset.univ_nonempty _ fun i _ => + mul_le_mul_of_nonneg_left (le_finiteMax x i) hc + · obtain ⟨i, _, hi⟩ := Finset.exists_mem_eq_sup' + (Finset.univ_nonempty : (Finset.univ : Finset ι).Nonempty) x + change c * Finset.univ.sup' Finset.univ_nonempty x ≤ _ + rw [hi] + exact le_finiteMax (fun i => c * x i) i + +omit [Fintype ι] [Nonempty ι] in +theorem linearField_const_mul {n : ℕ} (A : ι → Fin n → ℝ) (c : ℝ) + (x : Fin n → ℝ) (i : ι) : + linearField (fun i k => c * A i k) x i = c * linearField A x i := by + simp only [linearField, mul_assoc, Finset.mul_sum] + + + +theorem expected_finiteMax_le {n : ℕ} (A B : ι → Fin n → ℝ) + (hAB : ∀ i j, ∑ k, A i k * B j k = 0) + (hinc : ∀ i j, (∑ k, (A i k - A j k) ^ 2) ≤ ∑ k, (B i k - B j k) ^ 2) : + (∫ x, finiteMax (linearField A x) ∂standardLaw n) ≤ + ∫ x, finiteMax (linearField B x) ∂standardLaw n := by + apply le_of_forall_pos_le_add + intro ε hε + let c : ℝ := (Real.log (Fintype.card ι) + 1) / ε + have hc : 0 < c := div_pos (by linarith [Real.log_natCast_nonneg (Fintype.card ι)]) hε + let A' : ι → Fin n → ℝ := fun i k => c * A i k + let B' : ι → Fin n → ℝ := fun i k => c * B i k + have hor : ∀ i j, ∑ k, A' i k * B' j k = 0 := by + intro i j + calc + _ = c ^ 2 * ∑ k, A i k * B j k := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + dsimp [A', B'] + ring + _ = 0 := by rw [hAB, mul_zero] + have hdist : ∀ i j, (∑ k, (A' i k - A' j k) ^ 2) ≤ ∑ k, (B' i k - B' j k) ^ 2 := by + intro i j + have he (C : ι → Fin n → ℝ) : + (∑ k, (c * C i k - c * C j k) ^ 2) = c ^ 2 * ∑ k, (C i k - C j k) ^ 2 := by + simp only [← mul_sub, mul_pow, Finset.mul_sum] + change (∑ k, (c * A i k - c * A j k) ^ 2) ≤ ∑ k, (c * B i k - c * B j k) ^ 2 + rw [he A, he B] + exact mul_le_mul_of_nonneg_left (hinc i j) (sq_nonneg c) + have hscaled : c * (∫ x, finiteMax (linearField A x) ∂standardLaw n) ≤ + c * (∫ x, finiteMax (linearField B x) ∂standardLaw n) + Real.log (Fintype.card ι) := by + calc + _ = ∫ x, finiteMax (linearField A' x) ∂standardLaw n := by + simp_rw [show ∀ x, linearField A' x = fun i => c * linearField A x i from + fun x => funext fun i => linearField_const_mul A c x i, + finiteMax_const_mul _ hc.le, integral_const_mul] + _ ≤ ∫ x, logPartition (linearField A' x) ∂standardLaw n := + integral_mono (integrable_finiteMax (integrable_linearField A')) + (integrable_logPartition (integrable_linearField A')) + (fun x => finiteMax_le_logPartition (linearField A' x)) + _ ≤ ∫ x, logPartition (linearField B' x) ∂standardLaw n := + expected_logPartition_le A' B' hor hdist + _ ≤ ∫ x, finiteMax (linearField B' x) + Real.log (Fintype.card ι) ∂standardLaw n := + integral_mono (integrable_logPartition (integrable_linearField B')) + ((integrable_finiteMax (integrable_linearField B')).add (integrable_const _)) + (fun x => logPartition_le (linearField B' x)) + _ = _ := by + rw [integral_add (integrable_finiteMax (integrable_linearField B')) (integrable_const _)] + simp_rw [show ∀ x, linearField B' x = fun i => c * linearField B x i from + fun x => funext fun i => linearField_const_mul B c x i, + finiteMax_const_mul _ hc.le, integral_const_mul] + simp + have heps : c * ε = Real.log (Fintype.card ι) + 1 := by + dsimp [c] + exact div_mul_cancel₀ _ hε.ne' + nlinarith + + +def gaussianLaw (κ : Type*) [Fintype κ] : Measure (κ → ℝ) := + Measure.pi fun _ => gaussianReal 0 1 + +instance (κ : Type*) [Fintype κ] : IsProbabilityMeasure (gaussianLaw κ) := by + unfold gaussianLaw + infer_instance + + +def field {κ : Type*} [Fintype κ] (A : ι → κ → ℝ) (x : κ → ℝ) (i : ι) : ℝ := + ∑ k, A i k * x k + +omit [Fintype ι] [Nonempty ι] in +theorem integrable_field {κ : Type*} [Fintype κ] (A : ι → κ → ℝ) (i : ι) : + Integrable (fun x => field A x i) (gaussianLaw κ) := by + apply integrable_finsetSum + intro k _ + apply Integrable.const_mul + change Integrable (fun x : κ → ℝ => id (x k)) (Measure.pi fun _ : κ => gaussianReal 0 1) + apply integrable_comp_eval + exact MemLp.integrable (by norm_num) (memLp_id_gaussianReal (μ := 0) (v := 1) 1) + +omit [Fintype ι] [Nonempty ι] in +theorem integral_reindex_field {κ : Type*} [Fintype κ] (A : ι → κ → ℝ) + (f : (ι → ℝ) → ℝ) : + (∫ x, f (linearField (fun i k => A i ((Fintype.equivFin κ).symm k)) x) + ∂standardLaw (Fintype.card κ)) = ∫ x, f (field A x) ∂gaussianLaw κ := by + let e : Fin (Fintype.card κ) ≃ κ := (Fintype.equivFin κ).symm + let T : (Fin (Fintype.card κ) → ℝ) ≃ᵐ (κ → ℝ) := + MeasurableEquiv.piCongrLeft (fun _ => ℝ) e + have hm : MeasurePreserving T (standardLaw (Fintype.card κ)) (gaussianLaw κ) := + measurePreserving_piCongrLeft (fun _ => gaussianReal 0 1) e + have he (x : Fin (Fintype.card κ) → ℝ) : + field A (T x) = linearField (fun i k => A i (e k)) x := by + funext i + show (∑ k, A i k * T x k) = ∑ k, A i (e k) * x k + rw [← e.sum_comp (fun k => A i k * T x k)] + apply Finset.sum_congr rfl + intro k _ + simp only [T, MeasurableEquiv.piCongrLeft_apply_apply] + have h := hm.integral_comp' (fun x => f (field A x)) + simp_rw [he] at h + exact h + + +theorem expected_field_max_le_of_orthogonal {κ : Type*} [Fintype κ] + (A B : ι → κ → ℝ) + (hAB : ∀ i j, ∑ k, A i k * B j k = 0) + (hinc : ∀ i j, (∑ k, (A i k - A j k) ^ 2) ≤ ∑ k, (B i k - B j k) ^ 2) : + (∫ x, finiteMax (field A x) ∂gaussianLaw κ) ≤ + ∫ x, finiteMax (field B x) ∂gaussianLaw κ := by + rw [← integral_reindex_field A finiteMax, ← integral_reindex_field B finiteMax] + apply expected_finiteMax_le + · intro i j + exact ((Fintype.equivFin κ).symm.sum_comp (fun k => A i k * B j k)).trans (hAB i j) + · intro i j + exact ((Fintype.equivFin κ).symm.sum_comp (fun k => (A i k - A j k) ^ 2)).le.trans + ((hinc i j).trans ((Fintype.equivFin κ).symm.sum_comp (fun k => (B i k - B j k) ^ 2)).symm.le) + +omit [Fintype ι] [Nonempty ι] in + +theorem integral_field_inl {κ κ₂ : Type*} [Fintype κ] [Fintype κ₂] (A : ι → κ → ℝ) + (f : (ι → ℝ) → ℝ) : + (∫ x, f (field (fun i => Sum.elim (A i) (fun _ : κ₂ => 0)) x) ∂gaussianLaw (κ ⊕ κ₂)) = + ∫ x, f (field A x) ∂gaussianLaw κ := by + let T : ((κ → ℝ) × (κ₂ → ℝ)) ≃ᵐ ((κ ⊕ κ₂) → ℝ) := + (MeasurableEquiv.sumPiEquivProdPi (fun _ : κ ⊕ κ₂ => ℝ)).symm + have hm : MeasurePreserving T ((gaussianLaw κ).prod (gaussianLaw κ₂)) (gaussianLaw (κ ⊕ κ₂)) := + measurePreserving_sumPiEquivProdPi_symm (fun _ => gaussianReal 0 1) + rw [← hm.integral_comp' (fun x => f (field (fun i => Sum.elim (A i) (fun _ : κ₂ => 0)) x))] + have he (x : (κ → ℝ) × (κ₂ → ℝ)) : + field (fun i => Sum.elim (A i) (fun _ : κ₂ => 0)) (T x) = field A x.1 := by + funext i + simp only [field, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, zero_mul, + Finset.sum_const_zero, add_zero] + rfl + simp_rw [he] + simpa using integral_fun_fst (μ := gaussianLaw κ) (ν := gaussianLaw κ₂) + (fun x => f (field A x)) + +omit [Fintype ι] [Nonempty ι] in +theorem integral_field_inr {κ κ₂ : Type*} [Fintype κ] [Fintype κ₂] (B : ι → κ₂ → ℝ) + (f : (ι → ℝ) → ℝ) : + (∫ x, f (field (fun i => Sum.elim (fun _ : κ => 0) (B i)) x) ∂gaussianLaw (κ ⊕ κ₂)) = + ∫ x, f (field B x) ∂gaussianLaw κ₂ := by + let T : ((κ → ℝ) × (κ₂ → ℝ)) ≃ᵐ ((κ ⊕ κ₂) → ℝ) := + (MeasurableEquiv.sumPiEquivProdPi (fun _ : κ ⊕ κ₂ => ℝ)).symm + have hm : MeasurePreserving T ((gaussianLaw κ).prod (gaussianLaw κ₂)) (gaussianLaw (κ ⊕ κ₂)) := + measurePreserving_sumPiEquivProdPi_symm (fun _ => gaussianReal 0 1) + rw [← hm.integral_comp' (fun x => f (field (fun i => Sum.elim (fun _ : κ => 0) (B i)) x))] + have he (x : (κ → ℝ) × (κ₂ → ℝ)) : + field (fun i => Sum.elim (fun _ : κ => 0) (B i)) (T x) = field B x.2 := by + funext i + simp only [field, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, zero_mul, + Finset.sum_const_zero, zero_add] + rfl + simp_rw [he] + simpa using integral_fun_snd (μ := gaussianLaw κ) (ν := gaussianLaw κ₂) + (fun x => f (field B x)) + + + +theorem expected_field_max_le {κ κ₂ : Type*} [Fintype κ] [Fintype κ₂] + (A : ι → κ → ℝ) (B : ι → κ₂ → ℝ) + (hinc : ∀ i j, (∑ k, (A i k - A j k) ^ 2) ≤ ∑ k, (B i k - B j k) ^ 2) : + (∫ x, finiteMax (field A x) ∂gaussianLaw κ) ≤ + ∫ x, finiteMax (field B x) ∂gaussianLaw κ₂ := by + rw [← integral_field_inl (κ₂ := κ₂) A finiteMax, + ← integral_field_inr (κ := κ) B finiteMax] + apply expected_field_max_le_of_orthogonal + · intro i j + simp [Fintype.sum_sum_type] + · intro i j + simpa only [Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, sub_self, + sq, mul_zero, Finset.sum_const_zero, add_zero, zero_add] using hinc i j + +end SKGaussian + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Joint.lean b/lean/OAI/Probability/ParisiFinite/Joint.lean new file mode 100644 index 0000000000000000000000000000000000000000..0248add4d00a9b71771526b9f7bc7878a3b59205 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Joint.lean @@ -0,0 +1,653 @@ +import Mathlib +import OAI.Probability.ParisiFinite.InnerRootYCoordinates +import OAI.Probability.ParisiFinite.Space + +namespace OAI + +/-! Joint. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +namespace GaussianFactorization +open MeasureTheory ProbabilityTheory Complex CoherentFock GaussianCoherent +open scoped BigOperators InnerProductSpace ComplexConjugate +variable {κ E : Type*} [Fintype κ] [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +abbrev Joint (κ E : Type*) [Fintype κ] := HilbertPair.Space (Mode κ) E +abbrev Hilbert (κ E : Type*) [Fintype κ] [NormedAddCommGroup E] [InnerProductSpace ℂ E] := + Lp (Space E) 2 (GaussianFourier.law κ) + +def wave (d : Joint κ E) (g : κ → ℝ) : Space E := + GaussianCoherent.wave d.fst g • coherent d.snd + +theorem continuous_wave (d : Joint κ E) : Continuous (wave d) := + (GaussianCoherent.continuous_wave d.fst).smul continuous_const + +@[simp] theorem norm_wave (d : Joint κ E) (g : κ → ℝ) : + ‖wave d g‖=‖GaussianCoherent.wave d.fst g‖ := by + simp [wave,norm_smul] + +theorem memLp_wave (d : Joint κ E) : MemLp (wave d) 2 (GaussianFourier.law κ) := + (GaussianCoherent.memLp_wave d.fst).congr_norm (continuous_wave d).aestronglyMeasurable + (Filter.Eventually.of_forall fun g => (norm_wave d g).symm) + +def vector (d : Joint κ E) : Hilbert κ E := (memLp_wave d).toLp (wave d) + +theorem vector_ae (d : Joint κ E) : + (vector d : (κ → ℝ) → Space E)=ᵐ[GaussianFourier.law κ] wave d := MemLp.coeFn_toLp _ + +theorem kernel_joint (d e : Joint κ E) : kernel d e=kernel d.fst e.fst*kernel d.snd e.snd := by + unfold kernel + rw [←Complex.exp_add] + congr 1 + rw [WithLp.prod_norm_sq_eq_of_L2,WithLp.prod_norm_sq_eq_of_L2] + simp only [WithLp.prod_inner_apply] + change Complex.ofReal (-(‖d.fst‖^2+‖d.snd‖^2)/2)+ + (⟪d.fst,e.fst⟫_ℂ+⟪d.snd,e.snd⟫_ℂ)+Complex.ofReal (-(‖e.fst‖^2+‖e.snd‖^2)/2)=_ + push_cast + ring + +@[simp] theorem inner_vector (d e : Joint κ E) : ⟪vector d,vector e⟫_ℂ=kernel d e := by + rw [L2.inner_def,kernel_joint,←GaussianCoherent.integral_wave_pair,←integral_mul_const] + apply integral_congr_ae + filter_upwards [vector_ae d,vector_ae e] with g hd he + rw [hd,he] + simp only [wave,inner_smul_left,inner_smul_right,inner_coherent] + ring + + + +def preMap : PreSpace (Joint κ E) →ₗᵢ[ℂ] Hilbert κ E := + LinearMap.isometryOfInner + ((Finsupp.linearCombination ℂ vector).comp toFinsupp.toLinearMap) (by + intro x y + change ⟪(toFinsupp x).sum (fun d a => a • vector d), + (toFinsupp y).sum (fun e b => b • vector e)⟫_ℂ=_ + rw [Finsupp.sum_inner] + change (toFinsupp x).sum (fun d a => ⟪a • vector d, + (toFinsupp y).sum (fun e b => b • vector e)⟫_ℂ)= + (toFinsupp x).sum (fun d a => (toFinsupp y).sum (fun e b => conj a*kernel d e*b)) + apply Finsupp.sum_congr + intro d hd + rw [Finsupp.inner_sum] + apply Finsupp.sum_congr + intro e he + simp only [inner_smul_left,inner_smul_right,inner_vector] + ring) + +def representation : Space (Joint κ E) →ₗᵢ[ℂ] Hilbert κ E where + toLinearMap := preMap.toContinuousLinearMap.fromCompletion.toLinearMap + norm_map' x := by + refine UniformSpace.Completion.induction_on x + (isClosed_eq (preMap.toContinuousLinearMap.fromCompletion.continuous.norm) continuous_norm) + fun y => ?_ + change ‖preMap.toContinuousLinearMap.fromCompletion (y:Space (Joint κ E))‖= + ‖(y:Space (Joint κ E))‖ + rw [ContinuousLinearMap.fromCompletion_apply_coe,UniformSpace.Completion.norm_coe] + exact preMap.norm_map y + +@[simp] theorem representation_coherent (d : Joint κ E) : representation (coherent d)=vector d := by + change preMap.toContinuousLinearMap.fromCompletion + ((toFinsupp.symm (Finsupp.single d 1):PreSpace (Joint κ E)):Space (Joint κ E))=vector d + rw [ContinuousLinearMap.fromCompletion_apply_coe] + change Finsupp.linearCombination ℂ vector (Finsupp.single d 1)=vector d + simp + + + +theorem representation_surjective : Function.Surjective (representation (κ := κ) (E := E)) := by + let K := (representation (κ := κ) (E := E)).toLinearMap.range + have hK : IsClosed (K : Set (Hilbert κ E)) := + (representation (κ := κ) (E := E)).isometry.isClosedEmbedding.isClosed_range + have hbot : Kᗮ=⊥ := by + apply (Submodule.eq_bot_iff _).mpr + intro f hf + apply Lp.ext + have hi : Integrable (fun g => f g) (GaussianFourier.law κ) := + memLp_one_iff_integrable.mp ((Lp.memLp f).mono_exponent (by norm_num)) + have hcoef (x : E) : (fun g => ⟪coherent x,f g⟫_ℂ)=ᵐ[GaussianFourier.law κ] 0 := by + apply FourierDensity.ae_zero_of_fourier_zero (hi.const_inner (coherent x)) + intro a + let d : Joint κ E := WithLp.toLp 2 (realMode (-a),x) + have hh := (Submodule.mem_orthogonal K f).mp hf (vector d) + ⟨coherent d,representation_coherent _⟩ + rw [L2.inner_def] at hh + convert hh using 1 + apply integral_congr_ae + filter_upwards [vector_ae d] with g hg + rw [hg] + simp only [wave,inner_smul_left] + change FourierDensity.character a g*⟪coherent x,f g⟫_ℂ= + conj (GaussianCoherent.wave (realMode (-a)) g)*⟪coherent x,f g⟫_ℂ + rw [wave_realMode] + change FourierDensity.character a g*⟪coherent x,f g⟫_ℂ= + conj (FourierDensity.character (-a) g)*⟪coherent x,f g⟫_ℂ + rw [FourierDensity.character_neg,Complex.conj_conj] + have hz : (fun g => f g)=ᵐ[GaussianFourier.law κ] 0 := by + apply hi.ae_eq_zero_of_forall_setIntegral_eq_zero + intro s hs hsm + apply CoherentFock.eq_zero_of_inner_coherent + intro x + change (innerSL ℂ (coherent x)) (∫g in s, f g ∂GaussianFourier.law κ)=0 + rw [←(innerSL ℂ (coherent x)).integral_comp_comm (hi.integrableOn (s := s))] + change (∫g in s, ⟪coherent x,f g⟫_ℂ ∂GaussianFourier.law κ)=0 + rw [integral_congr_ae (ae_restrict_of_ae (hcoef x))] + simp + exact hz.trans (Lp.coeFn_zero (Space E) 2 (GaussianFourier.law κ)).symm + apply LinearMap.range_eq_top.mp + change K=⊤ + calc + K=K.topologicalClosure := hK.submodule_topologicalClosure_eq.symm + _=Kᗮᗮ := (Submodule.orthogonal_orthogonal_eq_closure K).symm + _=⊤ := by rw [hbot,Submodule.bot_orthogonal_eq_top] + +def jointGaussianUnitary : Space (Joint κ E) ≃ₗᵢ[ℂ] Hilbert κ E := + LinearIsometryEquiv.ofSurjective representation representation_surjective + +@[simp] theorem jointGaussianUnitary_coherent (d : Joint κ E) : + jointGaussianUnitary (coherent d)=vector d := representation_coherent d + +end GaussianFactorization + +namespace GaussianFactorization +open MeasureTheory ProbabilityTheory Complex CoherentFock GaussianCoherent +open scoped BigOperators InnerProductSpace ComplexConjugate +variable {κ E : Type*} [Fintype κ] [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem memLp_seedPhase (a : κ → ℝ) (f : Hilbert κ E) : + MemLp (fun g => GaussianCoherent.wave (realMode a) g • f g) 2 (GaussianFourier.law κ) := by + apply (Lp.memLp f).congr_norm + ((GaussianCoherent.continuous_wave (realMode a)).aestronglyMeasurable.smul + (Lp.aestronglyMeasurable f)) + exact Filter.Eventually.of_forall fun g => by + change ‖f g‖=‖GaussianCoherent.wave (realMode a) g • f g‖ + rw [norm_smul,norm_wave_realMode,one_mul] + +def seedPhase (a : κ → ℝ) (f : Hilbert κ E) : Hilbert κ E := + (memLp_seedPhase a f).toLp (fun g => GaussianCoherent.wave (realMode a) g • f g) + +theorem seedPhase_ae (a : κ → ℝ) (f : Hilbert κ E) : + (seedPhase a f : (κ → ℝ) → Space E)=ᵐ[GaussianFourier.law κ] + fun g => GaussianCoherent.wave (realMode a) g • f g := MemLp.coeFn_toLp _ + +def seedPhaseIsometry (a : κ → ℝ) : Hilbert κ E →ₗᵢ[ℂ] Hilbert κ E where + toFun := seedPhase a + map_add' f h := by + apply Lp.ext + filter_upwards [seedPhase_ae a (f+h),Lp.coeFn_add f h, + Lp.coeFn_add (seedPhase a f) (seedPhase a h),seedPhase_ae a f,seedPhase_ae a h] + with g h1 h2 h3 h4 h5 + rw [h1,h2,h3] + simp only [Pi.add_apply,h4,h5,smul_add] + map_smul' c f := by + change seedPhase a (c • f)=c • seedPhase a f + apply Lp.ext + filter_upwards [seedPhase_ae a (c • f),Lp.coeFn_smul c f, + Lp.coeFn_smul c (seedPhase a f),seedPhase_ae a f] with g h1 h2 h3 h4 + rw [h1,h2,h3] + simp only [Pi.smul_apply,h4] + exact smul_comm _ _ _ + norm_map' f := by + have hh : ∀ᵐ g ∂GaussianFourier.law κ, ‖seedPhase a f g‖=‖f g‖ := by + filter_upwards [seedPhase_ae a f] with g hg + rw [hg,norm_smul,norm_wave_realMode,one_mul] + exact le_antisymm (Lp.norm_le_norm_of_ae_le (hh.mono fun _ h => h.le)) + (Lp.norm_le_norm_of_ae_le (hh.mono fun _ h => h.ge)) + +@[simp] theorem phase_inl (a : Mode κ) (d : Joint κ E) : + phase (HilbertPair.inl a) d=phase a d.fst := by + simp [phase,HilbertPair.inl_apply,WithLp.prod_inner_apply] + +@[simp] theorem phase_inr (e : E) (d : Joint κ E) : + phase (HilbertPair.inr e) d=phase e d.snd := by + simp [phase,HilbertPair.inr_apply,WithLp.prod_inner_apply] + +theorem seedPhase_vector (a : κ → ℝ) (d : Joint κ E) : + seedPhaseIsometry a (vector d)= + phase (HilbertPair.inl (realMode a)) d • vector (HilbertPair.inl (realMode a)+d) := by + apply Lp.ext + filter_upwards [seedPhase_ae a (vector d),vector_ae d,vector_ae (HilbertPair.inl (realMode a)+d), + Lp.coeFn_smul (phase (HilbertPair.inl (realMode a)) d) + (vector (HilbertPair.inl (realMode a)+d))] with g h1 h2 h3 h4 + change seedPhase a (vector d) g = _ + rw [h1,h2,h4] + change GaussianCoherent.wave (realMode a) g • wave d g = + phase (HilbertPair.inl (realMode a)) d • vector (HilbertPair.inl (realMode a)+d) g + rw [h3,phase_inl] + change GaussianCoherent.wave (realMode a) g • (GaussianCoherent.wave d.fst g • coherent d.snd)= + phase (realMode a) d.fst • (GaussianCoherent.wave (realMode a+d.fst) g • coherent (0+d.snd)) + rw [zero_add,smul_smul,smul_smul,phase_wave_real_add] + + +theorem representation_W_external (a : κ → ℝ) (x : Space (Joint κ E)) : + representation (W (HilbertPair.inl (realMode a)) x)= + seedPhaseIsometry a (representation x) := by + have he : (representation (E:=E)).toContinuousLinearMap.comp (W (HilbertPair.inl (realMode a)))= + (seedPhaseIsometry a).toContinuousLinearMap.comp representation.toContinuousLinearMap := by + apply CoherentFock.ext_coherent + intro d + simp only [ContinuousLinearMap.comp_apply,LinearIsometry.coe_toContinuousLinearMap, + W_coherent,map_smul,representation_coherent,seedPhase_vector] + exact DFunLike.congr_fun he x + +theorem endogenous_vector (e : E) (d : Joint κ E) : + (W e).compLpL 2 (GaussianFourier.law κ) (vector d)= + phase (HilbertPair.inr e) d • vector (HilbertPair.inr e+d) := by + apply Lp.ext + filter_upwards [(W e).coeFn_compLpL (vector d),vector_ae d, + vector_ae (HilbertPair.inr e+d),Lp.coeFn_smul (phase (HilbertPair.inr e) d) + (vector (HilbertPair.inr e+d))] with g h1 h2 h3 h4 + rw [h1,h2,h4] + change W e (wave d g)=phase (HilbertPair.inr e) d • vector (HilbertPair.inr e+d) g + rw [h3,phase_inr] + change W e (GaussianCoherent.wave d.fst g • coherent d.snd)= + phase e d.snd • (GaussianCoherent.wave (0+d.fst) g • coherent (e+d.snd)) + rw [zero_add,map_smul,W_coherent] + exact smul_comm _ _ _ + + + +theorem representation_W_endogenous (e : E) (x : Space (Joint κ E)) : + representation (W (HilbertPair.inr e) x)= + (W e).compLpL 2 (GaussianFourier.law κ) (representation x) := by + have he : representation.toContinuousLinearMap.comp (W (HilbertPair.inr e : Joint κ E))= + ((W e).compLpL 2 (GaussianFourier.law κ)).comp representation.toContinuousLinearMap := by + apply CoherentFock.ext_coherent + intro d + simp only [ContinuousLinearMap.comp_apply,LinearIsometry.coe_toContinuousLinearMap, + W_coherent,map_smul,representation_coherent,endogenous_vector] + exact DFunLike.congr_fun he x + +end GaussianFactorization + + + +open scoped BigOperators Topology InnerProductSpace +open Filter +namespace QuantumCLT +variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] [NormOneClass A] [CompleteSpace A] + + +theorem exp_remainder_bound (x : A) (n : ℕ) : + ‖NormedSpace.exp x-∑ k ∈ Finset.range n, ((k.factorial:ℂ)⁻¹) • x^k‖ ≤ + ‖x‖^n * Real.exp ‖x‖ := by + have hs := NormedSpace.exp_series_hasSum_exp' (𝕂 := ℂ) x + have hn := NormedSpace.norm_expSeries_summable' (𝕂 := ℂ) x + have ht : NormedSpace.exp x-∑ k ∈ Finset.range n, ((k.factorial:ℂ)⁻¹) • x^k= + ∑' k : ℕ, (((k+n).factorial:ℂ)⁻¹) • x^(k+n) := by + rw [← hs.tsum_eq,← hs.summable.sum_add_tsum_nat_add n] + abel + rw [ht] + have hb : HasSum (fun k : ℕ => ‖x‖^n * (‖x‖^k/(k.factorial:ℝ))) + (‖x‖^n*Real.exp ‖x‖) := by + simpa [smul_eq_mul,div_eq_mul_inv,mul_comm,← Real.exp_eq_exp_ℝ] using + (NormedSpace.exp_series_hasSum_exp' (𝕂 := ℝ) ‖x‖).mul_left (‖x‖^n) + calc + _ ≤ ∑' k : ℕ, ‖(((k+n).factorial:ℂ)⁻¹) • x^(k+n)‖ := + norm_tsum_le_tsum_norm ((summable_nat_add_iff n).mpr hn) + _ ≤ ∑' k : ℕ, ‖x‖^n * (‖x‖^k/(k.factorial:ℝ)) := by + apply Summable.tsum_le_tsum _ ((summable_nat_add_iff n).mpr hn) hb.summable + intro k + rw [norm_smul, norm_inv,Complex.norm_natCast] + calc + _ ≤ ((k+n).factorial:ℝ)⁻¹*(‖x‖^(k+n)) := by + gcongr + exact norm_pow_le x (k+n) + _ ≤ (k.factorial:ℝ)⁻¹*(‖x‖^(k+n)) := by + gcongr + exact Nat.le_add_right k n + _ = _ := by rw [pow_add]; ring + _ = _ := hb.tsum_eq + +theorem norm_exp_le (x : A) : ‖NormedSpace.exp x‖ ≤ Real.exp ‖x‖ := by + simpa using exp_remainder_bound x 0 + + +theorem exp_second_bound (X : A) (r L : ℝ) (hL : 0 ≤ L) (hX : ‖X‖ ≤ L) + (hr : |r| ≤ 1) : + ‖NormedSpace.exp ((r:ℂ) • X)-1-(r:ℂ) • X-((r^2/2:ℝ):ℂ) • X^2‖ ≤ + (L^3*Real.exp L)*|r|^3 := by + have h := exp_remainder_bound ((r:ℂ) • X) 3 + have he : (∑ k ∈ Finset.range 3, ((k.factorial:ℂ)⁻¹) • ((r:ℂ) • X)^k)= + 1+(r:ℂ) • X+((r^2/2:ℝ):ℂ) • X^2 := by + simp [Finset.sum_range_succ,smul_pow] + module + rw [he] at h + have hn : ‖(r:ℂ) • X‖ ≤ L := by + rw [norm_smul,Complex.norm_real,Real.norm_eq_abs] + exact (mul_le_mul_of_nonneg_left hX (abs_nonneg r)).trans (by nlinarith) + calc + _ = ‖NormedSpace.exp ((r:ℂ) • X)-(1+(r:ℂ) • X+((r^2/2:ℝ):ℂ) • X^2)‖ := by congr 1; abel + _ ≤ ‖(r:ℂ) • X‖^3*Real.exp ‖(r:ℂ) • X‖ := h + _ ≤ (|r| * L)^3*Real.exp L := by + gcongr + · simpa only [norm_smul,Complex.norm_real,Real.norm_eq_abs] using mul_le_mul_of_nonneg_left hX (abs_nonneg r) + _ = _ := by ring + +omit [NormOneClass A] [CompleteSpace A] in + +theorem product_second_bound (f g a b c d : A) (r C D K : ℝ) + (hC : 0 ≤ C) (_hD : 0 ≤ D) (hK : 0 ≤ K) (hr : |r| ≤ 1) + (hf : ‖f-1-(r:ℂ) • a-((r:ℂ)^2) • b‖ ≤ C*|r|^3) + (hg : ‖g-1-(r:ℂ) • c-((r:ℂ)^2) • d‖ ≤ D*|r|^3) + (hnf : ‖f‖ ≤ K) : + ‖f*g-1-(r:ℂ) • (a+c)-((r:ℂ)^2) • (b+d+a*c)‖ ≤ + (C+(‖b‖+C)*‖c‖+(‖a‖+‖b‖+C)*‖d‖+K*D)*|r|^3 := by + have hp : |r|^3 ≤ |r|^2 := by nlinarith [sq_nonneg |r|] + have h2 : ‖f-1-(r:ℂ) • a‖ ≤ (‖b‖+C)*|r|^2 := by + calc + _ = ‖(f-1-(r:ℂ) • a-((r:ℂ)^2) • b)+((r:ℂ)^2) • b‖ := by congr 1; abel + _ ≤ ‖f-1-(r:ℂ) • a-((r:ℂ)^2) • b‖+‖((r:ℂ)^2) • b‖ := norm_add_le _ _ + _ ≤ C*|r|^3+|r|^2*‖b‖ := by + rw [norm_smul,Complex.norm_pow,Complex.norm_real,Real.norm_eq_abs] + exact add_le_add hf le_rfl + _ ≤ C*|r|^2+|r|^2*‖b‖ := by gcongr + _ = _ := by ring + have hp' : |r|^2 ≤ |r| := by nlinarith [abs_nonneg r] + have h1 : ‖f-1‖ ≤ (‖a‖+‖b‖+C)*|r| := by + calc + _ = ‖(f-1-(r:ℂ) • a)+(r:ℂ) • a‖ := by congr 1; abel + _ ≤ ‖f-1-(r:ℂ) • a‖+‖(r:ℂ) • a‖ := norm_add_le _ _ + _ ≤ (‖b‖+C)*|r|^2+|r| *‖a‖ := by + simpa only [norm_smul,Complex.norm_real,Real.norm_eq_abs] using add_le_add h2 (le_refl ‖(r:ℂ) • a‖) + _ ≤ (‖b‖+C)*|r|+|r| *‖a‖ := by gcongr + _ = _ := by ring + have he : f*g-1-(r:ℂ) • (a+c)-((r:ℂ)^2) • (b+d+a*c)= + (f-1-(r:ℂ) • a-((r:ℂ)^2) • b)+ + (r:ℂ) • ((f-1-(r:ℂ) • a)*c)+ + ((r:ℂ)^2) • ((f-1)*d)+ + f*(g-1-(r:ℂ) • c-((r:ℂ)^2) • d) := by + simp only [mul_sub,sub_mul,one_mul,mul_one,mul_smul_comm,smul_mul_assoc] + module + rw [he] + calc + _ ≤ ‖f-1-(r:ℂ) • a-((r:ℂ)^2) • b‖+ + ‖(r:ℂ) • ((f-1-(r:ℂ) • a)*c)‖+ + ‖((r:ℂ)^2) • ((f-1)*d)‖+ + ‖f*(g-1-(r:ℂ) • c-((r:ℂ)^2) • d)‖ := + (norm_add_le _ _).trans (add_le_add + ((norm_add_le _ _).trans (add_le_add (norm_add_le _ _) le_rfl)) le_rfl) + _ ≤ C*|r|^3+|r| *((‖b‖+C)*|r|^2*‖c‖)+ + |r|^2*((‖a‖+‖b‖+C)*|r| *‖d‖)+K*(D*|r|^3) := by + simp only [norm_smul,Complex.norm_pow,Complex.norm_real,Real.norm_eq_abs] + exact add_le_add (add_le_add (add_le_add hf + (mul_le_mul_of_nonneg_left ((norm_mul_le _ _).trans + (mul_le_mul_of_nonneg_right h2 (norm_nonneg _))) (abs_nonneg r))) + (mul_le_mul_of_nonneg_left ((norm_mul_le _ _).trans + (mul_le_mul_of_nonneg_right h1 (norm_nonneg _))) (sq_nonneg |r|))) + ((norm_mul_le _ _).trans (mul_le_mul hnf hg (norm_nonneg _) hK)) + _ = _ := by ring + + +def HasSecond (f : ℝ → A) (a b : A) : Prop := + ∃ C : ℝ, 0 ≤ C ∧ ∀ r : ℝ, |r| ≤ 1 → + ‖f r-1-(r:ℂ) • a-((r:ℂ)^2) • b‖ ≤ C*|r|^3 + +omit [CompleteSpace A] in +theorem jet_norm_bound {f : ℝ → A} {a b : A} {C : ℝ} (hC : 0 ≤ C) + (hf : ∀ r : ℝ, |r| ≤ 1 → ‖f r-1-(r:ℂ) • a-((r:ℂ)^2) • b‖ ≤ C*|r|^3) + {r : ℝ} (hr : |r| ≤ 1) : ‖f r‖ ≤ 1+‖a‖+‖b‖+C := by + have he : f r=1+(r:ℂ) • a+((r:ℂ)^2) • b+ + (f r-1-(r:ℂ) • a-((r:ℂ)^2) • b) := by abel + calc + ‖f r‖ ≤ ‖1+(r:ℂ) • a+((r:ℂ)^2) • b‖+ + ‖f r-1-(r:ℂ) • a-((r:ℂ)^2) • b‖ := by nth_rw 1 [he]; exact norm_add_le _ _ + _ ≤ ‖1+(r:ℂ) • a+((r:ℂ)^2) • b‖+C*|r|^3 := add_le_add le_rfl (hf r hr) + _ ≤ (‖(1:A)‖+‖(r:ℂ) • a‖+‖((r:ℂ)^2) • b‖)+C*|r|^3 := by + exact add_le_add ((norm_add_le _ _).trans (add_le_add (norm_add_le _ _) le_rfl)) le_rfl + _ ≤ _ := by + simp only [norm_one,norm_smul,Complex.norm_pow,Complex.norm_real,Real.norm_eq_abs] + have h2 : |r|^2 ≤ 1 := by nlinarith [abs_nonneg r] + have h3 : |r|^3 ≤ 1 := (pow_le_pow_left₀ (abs_nonneg r) hr 3).trans (by norm_num) + nlinarith [norm_nonneg a,norm_nonneg b,mul_le_mul_of_nonneg_right hr (norm_nonneg a), + mul_le_mul_of_nonneg_right h2 (norm_nonneg b),mul_le_mul_of_nonneg_left h3 hC] + +omit [CompleteSpace A] in +theorem HasSecond.mul {f g : ℝ → A} {a b c d : A} + (hf : HasSecond f a b) (hg : HasSecond g c d) : + HasSecond (fun r => f r*g r) (a+c) (b+d+a*c) := by + obtain ⟨C,hC,hf⟩ := hf + obtain ⟨D,hD,hg⟩ := hg + let K := 1+‖a‖+‖b‖+C + have hK : 0 ≤ K := by dsimp [K]; positivity + refine ⟨C+(‖b‖+C)*‖c‖+(‖a‖+‖b‖+C)*‖d‖+K*D,by positivity,fun r hr => ?_⟩ + exact product_second_bound _ _ _ _ _ _ r C D K hC hD hK hr (hf r hr) (hg r hr) + (jet_norm_bound hC hf hr) + +theorem exp_hasSecond (X : A) : + HasSecond (fun r : ℝ => NormedSpace.exp ((r:ℂ) • X)) X ((2:ℂ)⁻¹ • X^2) := by + refine ⟨‖X‖^3*Real.exp ‖X‖,by positivity,fun r hr => ?_⟩ + have he : ((r:ℂ)^2) • ((2:ℂ)⁻¹ • X^2)=((r^2/2:ℝ):ℂ) • X^2 := by + rw [smul_smul] + congr 1 + push_cast + ring + rw [he] + exact exp_second_bound X r ‖X‖ (norm_nonneg _) le_rfl hr + + +def generators (xs : List A) (r : ℝ) : A := (xs.map fun X => NormedSpace.exp ((r:ℂ) • X)).prod + +def second : List A → A + | [] => 0 + | X::xs => (2:ℂ)⁻¹ • X^2+second xs+X*xs.sum + +theorem generators_hasSecond (xs : List A) : HasSecond (generators xs) xs.sum (second xs) := by + induction xs with + | nil => refine ⟨0,le_rfl,?_⟩; intro r hr; simp [generators,second] + | cons X xs ih => + change HasSecond (fun r => NormedSpace.exp ((r:ℂ) • X)*generators xs r) + (X+xs.sum) ((2:ℂ)⁻¹ • X^2+second xs+X*xs.sum) + exact HasSecond.mul (exp_hasSecond X) ih + +omit [NormOneClass A] [CompleteSpace A] in + +theorem HasSecond.matrixElement {f : ℝ → A} {a b : A} (hf : HasSecond f a b) + (φ : A →L[ℂ] ℂ) (hφ : φ 1=1) (hc : φ a=0) : + ∃ C : ℝ, 0 ≤ C ∧ ∀ r : ℝ, |r| ≤ 1 → + ‖φ (f r)-1-(r:ℂ)^2*φ b‖ ≤ C*|r|^3 := by + obtain ⟨C,hC,hf⟩ := hf + refine ⟨‖φ‖*C,by positivity,fun r hr => ?_⟩ + calc + _ = ‖φ (f r-1-(r:ℂ) • a-((r:ℂ)^2) • b)‖ := by simp [hφ,hc] + _ ≤ ‖φ‖*‖f r-1-(r:ℂ) • a-((r:ℂ)^2) • b‖ := φ.le_opNorm _ + _ ≤ _ := by simpa [mul_assoc] using mul_le_mul_of_nonneg_left (hf r hr) (norm_nonneg φ) + + +theorem scalar_scaled_limit (f : ℕ → ℂ) (b : ℕ → ℂ) (c : ℂ) + (hb : Tendsto b atTop (𝓝 c)) (C : ℝ) (_hC : 0 ≤ C) + (hf : ∀ n : ℕ, 0 < n → ‖f n-1-(n:ℂ)⁻¹*b n‖ ≤ C*(Real.sqrt (n:ℝ))⁻¹^3) : + Tendsto (fun n : ℕ => (n:ℂ)*(f n-1)) atTop (𝓝 c) := by + have hs : Tendsto (fun n : ℕ => (Real.sqrt (n:ℝ))⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp (Real.tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop) + have herror : Tendsto (fun n : ℕ => (n:ℂ)*(f n-1)-b n) atTop (𝓝 0) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + simp only [sub_zero] + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ + (by simpa using hs.const_mul C) + filter_upwards [Filter.eventually_gt_atTop (0:ℕ)] with n hn + have hnR : 0 < (n:ℝ) := by exact_mod_cast hn + have hnC : (n:ℂ) ≠ 0 := by exact_mod_cast hn.ne' + have hsq := Real.sq_sqrt hnR.le + have hsn : Real.sqrt (n:ℝ) ≠ 0 := (Real.sqrt_pos.mpr hnR).ne' + calc + _ = ‖(n:ℂ)*(f n-1-(n:ℂ)⁻¹*b n)‖ := by congr 1; field_simp + _ = (n:ℝ)*‖f n-1-(n:ℂ)⁻¹*b n‖ := by rw [norm_mul,Complex.norm_natCast] + _ ≤ (n:ℝ)*(C*(Real.sqrt (n:ℝ))⁻¹^3) := mul_le_mul_of_nonneg_left (hf n hn) hnR.le + _ = C*(Real.sqrt (n:ℝ))⁻¹ := by nth_rw 1 [← hsq]; field_simp [hsn] + have ht : Tendsto (fun n : ℕ => (n:ℂ)*(f n-1)) atTop (𝓝 c) := by + convert herror.add hb using 1 <;> simp + exact ht + + +theorem scalar_power_limit (f : ℕ → ℂ) (b : ℕ → ℂ) (c : ℂ) + (hb : Tendsto b atTop (𝓝 c)) (C : ℝ) (_hC : 0 ≤ C) + (hf : ∀ n : ℕ, 0 < n → ‖f n-1-(n:ℂ)⁻¹*b n‖ ≤ C*(Real.sqrt (n:ℝ))⁻¹^3) : + Tendsto (fun n => f n^n) atTop (𝓝 (Complex.exp c)) := by + have ht := scalar_scaled_limit f b c hb C _hC hf + simpa using Complex.tendsto_one_add_pow_exp_of_tendsto ht + + + +theorem generators_vacuum_limit (xs : List A) (φ : A →L[ℂ] ℂ) + (hφ : φ 1=1) (hc : φ xs.sum=0) : + Tendsto (fun n : ℕ => (φ (generators xs (Real.sqrt (n:ℝ))⁻¹))^n) + atTop (𝓝 (Complex.exp (φ (second xs)))) := by + obtain ⟨C,hC,hf⟩ := (generators_hasSecond xs).matrixElement φ hφ hc + apply scalar_power_limit _ (fun _ => φ (second xs)) _ tendsto_const_nhds C hC + intro n hn + have hnR : (1:ℝ) ≤ n := by exact_mod_cast hn + have hr : |(Real.sqrt (n:ℝ))⁻¹| ≤ 1 := by + rw [abs_of_nonneg (by positivity)] + exact inv_le_one_of_one_le₀ ((Real.le_sqrt (by norm_num) (by positivity)).mpr (by simpa using hnR)) + have hsq : (((Real.sqrt (n:ℝ))⁻¹:ℝ):ℂ)^2=(n:ℂ)⁻¹ := by + rw [← Complex.ofReal_pow,inv_pow,Real.sq_sqrt (by positivity),Complex.ofReal_inv,Complex.ofReal_natCast] + simpa only [hsq,abs_of_nonneg (by positivity : 0 ≤ (Real.sqrt (n:ℝ))⁻¹)] using hf _ hr + +end QuantumCLT + +namespace QuantumCLT +open scoped BigOperators Topology +open Filter +variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] [NormOneClass A] [CompleteSpace A] + + + +def JetBound (L : ℝ) (f : ℝ → A) (a b : A) : Prop := + ‖a‖ ≤ L ∧ ‖b‖ ≤ L ∧ ∀r : ℝ, |r| ≤ 1 → + ‖f r-1-(r:ℂ) • a-((r:ℂ)^2) • b‖ ≤ L*|r|^3 + +omit [CompleteSpace A] in +theorem JetBound.mul {L K : ℝ} (hL : 0 ≤ L) (hK : 0 ≤ K) + {f g : ℝ → A} {a b c d : A} (hf : JetBound L f a b) (hg : JetBound K g c d) : + JetBound (L+K+8*L*K) (fun r => f r*g r) (a+c) (b+d+a*c) := by + refine ⟨?_,?_,?_⟩ + · calc + ‖a+c‖ ≤ ‖a‖+‖c‖ := norm_add_le _ _ + _ ≤ L+K := add_le_add hf.1 hg.1 + _ ≤ L+K+8*L*K := le_add_of_nonneg_right (by positivity) + · calc + ‖b+d+a*c‖ ≤ ‖b‖+‖d‖+‖a‖*‖c‖ := + (norm_add_le _ _).trans (add_le_add (norm_add_le _ _) (norm_mul_le _ _)) + _ ≤ L+K+L*K := by gcongr; exact hf.2.1; exact hg.2.1; exact hf.1; exact hg.1 + _ ≤ L+K+8*L*K := by nlinarith [mul_nonneg hL hK] + · intro r hr + have hnorm : ‖f r‖ ≤ 1+3*L := by + exact (jet_norm_bound hL hf.2.2 hr).trans (by linarith [hf.1,hf.2.1]) + have hh := product_second_bound (f r) (g r) a b c d r L K (1+3*L) + hL hK (by positivity) hr (hf.2.2 r hr) (hg.2.2 r hr) hnorm + apply hh.trans + apply mul_le_mul_of_nonneg_right _ (by positivity) + calc + L+(‖b‖+L)*‖c‖+(‖a‖+‖b‖+L)*‖d‖+(1+3*L)*K + ≤ L+(L+L)*K+(L+L+L)*K+(1+3*L)*K := by + gcongr <;> first | exact hf.1 | exact hf.2.1 | exact hg.1 | exact hg.2.1 + _ = L+K+8*L*K := by ring + +def exponentialBound (L : ℝ) : ℝ := L+L^2+L^3*Real.exp L + +theorem exponentialBound_nonneg {L : ℝ} (hL : 0 ≤ L) : 0 ≤ exponentialBound L := by + unfold exponentialBound + positivity + +theorem exp_jetBound (X : A) {L : ℝ} (hL : 0 ≤ L) (hX : ‖X‖ ≤ L) : + JetBound (exponentialBound L) (fun r : ℝ => NormedSpace.exp ((r:ℂ) • X)) X + ((2:ℂ)⁻¹ • X^2) := by + refine ⟨?_,?_,?_⟩ + · exact hX.trans (by unfold exponentialBound; nlinarith [sq_nonneg L,mul_nonneg (pow_nonneg hL 3) (Real.exp_pos L).le]) + · calc + ‖(2:ℂ)⁻¹ • X^2‖ = (2:ℝ)⁻¹*‖X^2‖ := by simp [norm_smul] + _ ≤ (2:ℝ)⁻¹*L^2 := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact (norm_pow_le _ _).trans (pow_le_pow_left₀ (norm_nonneg _) hX _) + _ ≤ exponentialBound L := by + unfold exponentialBound + nlinarith [mul_nonneg (pow_nonneg hL 3) (Real.exp_pos L).le] + · intro r hr + have he : ((r:ℂ)^2) • ((2:ℂ)⁻¹ • X^2)=((r^2/2:ℝ):ℂ) • X^2 := by + rw [smul_smul] + congr 1 + push_cast + ring + rw [he] + exact (exp_second_bound X r L hL hX hr).trans + (mul_le_mul_of_nonneg_right (by unfold exponentialBound; nlinarith [sq_nonneg L]) (by positivity)) + +def orderedBound (L : ℝ) : ℕ → ℝ + | 0 => 0 + | n+1 => exponentialBound L+orderedBound L n+8*exponentialBound L*orderedBound L n + +theorem orderedBound_nonneg {L : ℝ} (hL : 0 ≤ L) (n : ℕ) : 0 ≤ orderedBound L n := by + induction n with + | zero => rfl + | succ n ih => + dsimp [orderedBound] + have := exponentialBound_nonneg hL + positivity + + + +theorem generators_jetBound (xs : List A) {L : ℝ} (hL : 0 ≤ L) + (hxs : ∀ X ∈ xs, ‖X‖ ≤ L) : + JetBound (orderedBound L xs.length) (generators xs) xs.sum (second xs) := by + induction xs with + | nil => refine ⟨by simp [orderedBound],by simp [second,orderedBound],?_⟩; intro r hr; simp [generators,second,orderedBound] + | cons X xs ih => + apply (exp_jetBound X hL (hxs X (by simp))).mul (exponentialBound_nonneg hL) + (orderedBound_nonneg hL xs.length) (ih (fun Y hY => hxs Y (by simp [hY]))) + + + +theorem moving_generators_vacuum_limit + {ι : Type*} (A : ℕ → Type*) [∀n, NormedRing (A n)] [∀n, NormedAlgebra ℂ (A n)] + [∀n, NormOneClass (A n)] [∀n, CompleteSpace (A n)] + (l : List ι) (X : ∀n, ι → A n) (φ : ∀n, A n →L[ℂ] ℂ) + (L K : ℝ) (hL : 0 ≤ L) (hK : 0 ≤ K) + (hX : ∀n i, i ∈ l → ‖X n i‖ ≤ L) (hφ : ∀n, ‖φ n‖ ≤ K) + (h1 : ∀n, φ n 1=1) (hc : ∀n, φ n (l.map (X n)).sum=0) + {z : ℂ} (hz : Tendsto (fun n => φ n (second (l.map (X n)))) atTop (𝓝 z)) : + Tendsto (fun n : ℕ => (φ n (generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹))^n) + atTop (𝓝 (Complex.exp z)) := by + apply scalar_power_limit _ (fun n => φ n (second (l.map (X n)))) z hz + (K*orderedBound L l.length) (mul_nonneg hK (orderedBound_nonneg hL _)) + intro n hn + have hj := generators_jetBound (l.map (X n)) hL (by + intro Y hY + obtain ⟨i,hi,rfl⟩ := List.mem_map.mp hY + exact hX n i hi) + simp only [List.length_map] at hj + have hnR : (1:ℝ) ≤ n := by exact_mod_cast hn + have hr : |(Real.sqrt (n:ℝ))⁻¹| ≤ 1 := by + rw [abs_of_nonneg (by positivity)] + exact inv_le_one_of_one_le₀ ((Real.le_sqrt (by norm_num) (by positivity)).mpr (by simpa using hnR)) + have hsq : (((Real.sqrt (n:ℝ))⁻¹:ℝ):ℂ)^2=(n:ℂ)⁻¹ := by + rw [←Complex.ofReal_pow,inv_pow,Real.sq_sqrt (by positivity),Complex.ofReal_inv,Complex.ofReal_natCast] + let r := (Real.sqrt (n:ℝ))⁻¹ + calc + _ = ‖φ n (generators (l.map (X n)) r-1-(r:ℂ) • (l.map (X n)).sum- + ((r:ℂ)^2) • second (l.map (X n)))‖ := by + simp only [map_sub,map_smul,h1,hc,smul_eq_mul,mul_zero,sub_zero] + dsimp only [r] + rw [hsq] + _ ≤ ‖φ n‖*‖generators (l.map (X n)) r-1-(r:ℂ) • (l.map (X n)).sum- + ((r:ℂ)^2) • second (l.map (X n))‖ := (φ n).le_opNorm _ + _ ≤ K*(orderedBound L l.length*|r|^3) := + mul_le_mul (hφ n) (hj.2.2 r hr) (norm_nonneg _) hK + _ = K*orderedBound L l.length*(Real.sqrt (n:ℝ))⁻¹^3 := by + dsimp [r] + rw [abs_of_nonneg (by positivity)] + ring +end QuantumCLT + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Labels.lean b/lean/OAI/Probability/ParisiFinite/Labels.lean new file mode 100644 index 0000000000000000000000000000000000000000..6498d280f08ba1422771c74ab4fc9f6029f6e84e --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Labels.lean @@ -0,0 +1,701 @@ +import Mathlib +import OAI.Probability.ParisiFinite.UsedVertices + +namespace OAI + +/-! Labels. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped BigOperators + +namespace BoundedBranch + + +def labels (n : ℕ) : (h : ℕ) → Tree n h → Multiset (Fin n) + | 0, _ => 0 + | h+1, b => ∑i, (b i).elim 0 (fun c => {i}+labels n h c) + +def links (n : ℕ) : (h : ℕ) → Fin n → Tree n h → Multiset (Fin n × Fin n) + | 0, _, _ => 0 + | h+1, i, b => ∑j, (b j).elim 0 (fun c => {(i,j)}+links n h j c) + +@[simp] theorem card_labels (n h : ℕ) (b : Tree n h) : (labels n h b).card=size n h b := by + induction h with + | zero => rfl + | succ h ih => + change (∑i, (b i).elim 0 (fun c => {i}+labels n h c)).card=_ + rw [Multiset.card_sum] + apply Finset.sum_congr rfl + intro i hi + cases hb : b i with + | none => rfl + | some c => simp [ih,add_comm] + +@[simp] theorem map_snd_links (n h : ℕ) (i : Fin n) (b : Tree n h) : + (links n h i b).map Prod.snd=labels n h b := by + induction h generalizing i with + | zero => rfl + | succ h ih => + change (∑j,(b j).elim 0 (fun c => {(i,j)}+links n h j c)).map Prod.snd=_ + rw [show (∑j,(b j).elim 0 (fun c => {(i,j)}+links n h j c)).map Prod.snd = + ∑j,((b j).elim 0 (fun c => {(i,j)}+links n h j c)).map Prod.snd from + map_sum (Multiset.mapAddMonoidHom Prod.snd) _ _] + apply Finset.sum_congr rfl + intro j hj + cases hb : b j with + | none => rfl + | some c => simp [ih] + +@[simp] theorem card_links (n h : ℕ) (i : Fin n) (b : Tree n h) : + (links n h i b).card=size n h b := by + rw [←card_labels n h b,←map_snd_links n h i b,Multiset.card_map] + + +def unfoldTree {n : ℕ} (U S : Finset (Fin n)) (parent : Fin n → Fin n) : + (h : ℕ) → Fin n → Tree n h + | 0, _ => () + | h+1, i => fun j => if j∈U\S ∧ parent j=i then some (unfoldTree U S parent h j) else none + +namespace Parent +variable {n : ℕ} (U S : Finset (Fin n)) (parent : Fin n → Fin n) (rank : Fin n → ℕ) + +def layer (k : ℕ) : Finset (Fin n) := U.filter (fun i => rank i=k) + +lemma labels_unfold (h : ℕ) (i : Fin n) : + labels n (h+1) (unfoldTree U S parent (h+1) i)= + ∑j:Fin n, if j∈U\S ∧ parent j=i then + {j}+labels n h (unfoldTree U S parent h j) else 0 := by + apply Finset.sum_congr rfl + intro j hj + simp only [unfoldTree] + split_ifs <;> rfl + +lemma links_unfold (h : ℕ) (i : Fin n) : + links n (h+1) i (unfoldTree U S parent (h+1) i)= + ∑j:Fin n, if j∈U\S ∧ parent j=i then + {(i,j)}+links n h j (unfoldTree U S parent h j) else 0 := by + apply Finset.sum_congr rfl + intro j hj + simp only [unfoldTree] + split_ifs <;> rfl + +variable (hS : S⊆U) (hzero : ∀i∈U, rank i=0 ↔ i∈S) + (hparent : ∀j∈U\S, parent j∈U ∧ rank (parent j)+1=rank j) + +include hzero hparent in +lemma child_layer_iff (k : ℕ) (j : Fin n) : + j∈U\S ∧ parent j∈layer U rank k ↔ j∈layer U rank (k+1) := by + constructor + · rintro ⟨hj,hp⟩ + rcases Finset.mem_sdiff.mp hj with ⟨hjU,hjS⟩ + rcases Finset.mem_filter.mp hp with ⟨hpU,hpk⟩ + exact Finset.mem_filter.mpr ⟨hjU,by rw [←(hparent j (by simp [hjU,hjS])).2,hpk]⟩ + · intro hj + rcases Finset.mem_filter.mp hj with ⟨hjU,hjrank⟩ + have hjS : j∉S := by + intro hjS + have := (hzero j hjU).mpr hjS + omega + have hp := hparent j (Finset.mem_sdiff.mpr ⟨hjU,hjS⟩) + refine ⟨Finset.mem_sdiff.mpr ⟨hjU,hjS⟩,Finset.mem_filter.mpr ⟨hp.1,?_⟩⟩ + omega + +include hzero hparent in + + +theorem sum_labels_layer (h k : ℕ) : + (∑i∈layer U rank k, labels n h (unfoldTree U S parent h i))= + ∑j∈U, if k + simp only [labels,Finset.sum_const_zero,Nat.add_zero] + symm + apply Finset.sum_eq_zero + intro j hj + exact ite_eq_right (by omega) + | succ h ih => + simp_rw [labels_unfold] + rw [Finset.sum_comm] + have ht (j : Fin n) : (∑i∈layer U rank k, if j∈U\S ∧ parent j=i then + ({j}:Multiset (Fin n))+labels n h (unfoldTree U S parent h j) else 0)= + if j∈layer U rank (k+1) then {j}+labels n h (unfoldTree U S parent h j) else 0 := by + by_cases hj : j∈U\S + · simp only [hj,true_and,Finset.sum_ite_eq] + congr 1 + exact propext (by simpa only [hj,true_and] using child_layer_iff U S parent rank hzero hparent k j) + · have hjL : j∉layer U rank (k+1) := by + intro hh + exact hj ((child_layer_iff U S parent rank hzero hparent k j).mpr hh).1 + simp [hj,hjL] + simp_rw [ht] + rw [←Finset.sum_filter] + simp only [Finset.filter_mem_eq_inter,Finset.univ_inter] + rw [Finset.sum_add_distrib,ih] + rw [layer,Finset.sum_filter] + rw [←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro j hj + by_cases h₁ : rank j=k+1 + · simp [h₁] + · have hr : (k hjS (hz.mp hr)),by simpa using hb⟩ + have hh : (∑j∈U, if 0 (parent j,j)) := by + induction h generalizing i with + | zero => rfl + | succ h ih => + rw [links_unfold,labels_unfold] + rw [show (∑j:Fin n,if j∈U\S ∧ parent j=i then + ({j}:Multiset (Fin n))+labels n h (unfoldTree U S parent h j) else 0).map + (fun j => (parent j,j)) = + ∑j:Fin n,(if j∈U\S ∧ parent j=i then + ({j}:Multiset (Fin n))+labels n h (unfoldTree U S parent h j) else 0).map + (fun j => (parent j,j)) from + map_sum (Multiset.mapAddMonoidHom (fun j => (parent j,j))) _ _] + apply Finset.sum_congr rfl + intro j hj + by_cases hp : j∈U\S ∧ parent j=i + · simp [hp,ih] + · rw [ite_eq_right hp,ite_eq_right hp]; rfl + +include hS hzero hparent in + +theorem sum_links_roots (h : ℕ) (hbound : ∀j∈U, rank j≤h) : + (∑i∈S,links n h i (unfoldTree U S parent h i))= + (U\S).val.map (fun j => (parent j,j)) := by + rw [←sum_labels_roots U S parent rank hS hzero hparent h hbound] + rw [show (∑i∈S, labels n h (unfoldTree U S parent h i)).map (fun j => (parent j,j))= + ∑i∈S, (labels n h (unfoldTree U S parent h i)).map (fun j => (parent j,j)) from + map_sum (Multiset.mapAddMonoidHom (fun j => (parent j,j))) _ _] + exact Finset.sum_congr rfl (fun i _ => links_eq_map_labels U S parent h i) + +end Parent +end BoundedBranch + + + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA.Locality +variable {n : ℕ} + +def ball (E : Finset (Edge n)) (S : Finset (Fin n)) : ℕ → Finset (Fin n) + | 0 => S + | h+1 => neighborhood E (ball E S h) + +lemma ball_mono (E : Finset (Edge n)) (S : Finset (Fin n)) : Monotone (ball E S) := by + apply monotone_nat_of_le_succ + intro h + exact subset_neighborhood E (ball E S h) + +lemma subset_ball (E : Finset (Edge n)) (S : Finset (Fin n)) (h : ℕ) : S⊆ball E S h := + ball_mono E S (Nat.zero_le h) + +lemma ball_succ_start (E : Finset (Edge n)) (S : Finset (Fin n)) (h : ℕ) : + ball E (neighborhood E S) h=ball E S (h+1) := by + induction h with + | zero => rfl + | succ h ih => exact congrArg (neighborhood E) ih + +lemma incident_mem_neighborhood {E : Finset (Edge n)} {S : Finset (Fin n)} {e : Edge n} + (he : e∈E) (hu : e.1.1∈S ∨ e.1.2∈S) : + e.1.1∈neighborhood E S ∧ e.1.2∈neighborhood E S := + active_endpoints (Finset.mem_filter.mpr ⟨he,hu⟩) + + +lemma new_vertex_parent {E : Finset (Edge n)} {S : Finset (Fin n)} {v : Fin n} + (hv : v∈neighborhood E S) (hvS : v∉S) : + ∃(u : Fin n) (e : Edge n), e∈E ∧ u∈S ∧ + ((e.1.1=v ∧ e.1.2=u) ∨ (e.1.1=u ∧ e.1.2=v)) := by + rcases Finset.mem_union.mp hv with hv | hv + · exact (hvS hv).elim + rcases Finset.mem_biUnion.mp hv with ⟨e,he,hve⟩ + rcases Finset.mem_filter.mp he with ⟨he,htouch⟩ + rcases Finset.mem_insert.mp hve with hve | hve + · have hv' : e.1.1=v := hve.symm + have hu : e.1.2∈S := by + rcases htouch with h|h + · exact (hvS (hv' ▸ h)).elim + · exact h + exact ⟨e.1.2,e,he,hu,Or.inl ⟨hv',rfl⟩⟩ + · have hv' : e.1.2=v := (Finset.mem_singleton.mp hve).symm + have hu : e.1.1∈S := by + rcases htouch with h|h + · exact h + · exact (hvS (hv' ▸ h)).elim + exact ⟨e.1.1,e,he,hu,Or.inr ⟨rfl,hv'⟩⟩ + + +def rank (E : Finset (Edge n)) (S : Finset (Fin n)) (v : Fin n) : ℕ := + sInf {h | v∈ball E S h} + +lemma rank_le_of_mem {E : Finset (Edge n)} {S : Finset (Fin n)} {v : Fin n} {h : ℕ} + (hv : v∈ball E S h) : rank E S v≤h := Nat.sInf_le hv + +lemma mem_ball_rank {E : Finset (Edge n)} {S : Finset (Fin n)} {v : Fin n} {h : ℕ} + (hv : v∈ball E S h) : v∈ball E S (rank E S v) := + Nat.sInf_mem (show Set.Nonempty {k | v∈ball E S k} from ⟨h,hv⟩) + +lemma rank_zero_iff {E : Finset (Edge n)} {S : Finset (Fin n)} {v : Fin n} {h : ℕ} + (hv : v∈ball E S h) : rank E S v=0 ↔ v∈S := by + constructor + · intro hr + have hh := mem_ball_rank hv + rw [hr] at hh + exact hh + · intro hvS + exact Nat.eq_zero_of_le_zero (rank_le_of_mem (h := 0) hvS) + + + +theorem exists_parent {E : Finset (Edge n)} {S : Finset (Fin n)} {v : Fin n} {h : ℕ} + (hv : v∈ball E S h) (hvS : v∉S) : + ∃(u : Fin n) (e : Edge n), e∈E ∧ u∈ball E S h ∧ + rank E S u+1=rank E S v ∧ + ((e.1.1=v ∧ e.1.2=u) ∨ (e.1.1=u ∧ e.1.2=v)) := by + have hr : rank E S v≠0 := fun hr => hvS ((rank_zero_iff hv).mp hr) + obtain ⟨k,hk⟩ := Nat.exists_eq_succ_of_ne_zero hr + have hvk : v∈neighborhood E (ball E S k) := by + have hh := mem_ball_rank hv + simpa only [hk,ball] using hh + have hvnot : v∉ball E S k := by + intro hh + have := rank_le_of_mem hh + omega + obtain ⟨u,e,he,hu,hend⟩ := new_vertex_parent hvk hvnot + have huk : rank E S u≤k := rank_le_of_mem hu + have hub : u∈ball E S (rank E S u) := mem_ball_rank hu + have hvup : v∈ball E S (rank E S u+1) := by + have ht : e.1.1∈ball E S (rank E S u) ∨ e.1.2∈ball E S (rank E S u) := by + rcases hend with ⟨_,he₂⟩|⟨he₁,_⟩ + · exact Or.inr (he₂ ▸ hub) + · exact Or.inl (he₁ ▸ hub) + have ha := incident_mem_neighborhood he ht + rcases hend with ⟨he₁,_⟩|⟨_,he₂⟩ + · exact he₁ ▸ ha.1 + · exact he₂ ▸ ha.2 + have hvr := rank_le_of_mem hvup + have hbound := rank_le_of_mem hv + refine ⟨u,e,he,ball_mono E S (by omega) hu,by omega,hend⟩ + + + +theorem relevant_endpoints_in_ball (E : Finset (Edge n)) (p : ℕ) + (γ β : Fin p → ℝ) (S : Finset (Fin n)) {e : Edge n} + (he : e∈relevantEdges E (qaoaWord p γ β) S) : + e.1.1∈ball E S p ∧ e.1.2∈ball E S p := by + induction p generalizing S with + | zero => simp [qaoaWord,relevantEdges] at he + | succ p ih => + simp only [qaoaWord,relevantEdges] at he + rcases Finset.mem_union.mp he with he|he + · have hh := active_endpoints he + exact ⟨ball_mono E S (by omega : 1≤p+1) hh.1, + ball_mono E S (by omega : 1≤p+1) hh.2⟩ + · have hh := ih _ _ _ he + simpa only [ball_succ_start] using hh + +end Locality + +namespace SiteHistories +variable {n : ℕ} + +lemma ball_subset_used (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + Locality.ball (H∪{r}) {r.1.1,r.1.2} p ⊆ usedVertices r H := by + induction p with + | zero => + intro v hv + rcases Finset.mem_insert.mp hv with rfl|hv + · exact fst_mem_usedVertices _ _ (by simp) + · have := Finset.mem_singleton.mp hv + subst v + exact snd_mem_usedVertices _ _ (by simp) + | succ p ih => + intro v hv + rcases Finset.mem_union.mp hv with hv|hv + · exact ih hv + rcases Finset.mem_biUnion.mp hv with ⟨e,he,hv⟩ + exact Finset.mem_biUnion.mpr ⟨e,(Finset.mem_filter.mp he).1,hv⟩ + + + +theorem used_eq_ball (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) + (hcone : H⊆Locality.relevantEdges (H∪{r}) (qaoaWord p γ β) {r.1.1,r.1.2}) : + usedVertices r H=Locality.ball (H∪{r}) {r.1.1,r.1.2} p := by + apply Finset.Subset.antisymm _ (ball_subset_used r H p) + intro v hv + rcases Finset.mem_biUnion.mp hv with ⟨e,he,hv⟩ + rcases Finset.mem_union.mp he with he|he + · have hh := Locality.relevant_endpoints_in_ball (H∪{r}) p γ β _ (hcone he) + rcases Finset.mem_insert.mp hv with hv|hv + · exact hv ▸ hh.1 + · exact (Finset.mem_singleton.mp hv) ▸ hh.2 + · have he' := Finset.mem_singleton.mp he + subst e + exact Locality.subset_ball _ _ p hv + +end SiteHistories +end SKQAOA + + + +open scoped BigOperators + +namespace SKQAOA +namespace FiniteGraph +variable {n : ℕ} + + + +def pairEdges (u v : Fin n) : Finset (Edge n) := + if h : u pairEdges q.1 q.2) + +lemma mem_edgesOfLinks (l : Multiset (Fin n × Fin n)) (e : Edge n) : + e∈edgesOfLinks l ↔ ∃q∈l, + ((e.1.1=q.1 ∧ e.1.2=q.2) ∨ (e.1.1=q.2 ∧ e.1.2=q.1)) := by + simp only [edgesOfLinks,Finset.mem_biUnion,Multiset.mem_toFinset,mem_pairEdges] + + + +lemma parentEdge_injective (U S : Finset (Fin n)) (parent : Fin n → Fin n) + (rank : Fin n → ℕ) (edge : Fin n → Edge n) + (hrank : ∀j∈U\S, rank (parent j)+1=rank j) + (hedge : ∀j∈U\S, (edge j∈pairEdges (parent j) j)) : + Set.InjOn edge (↑(U\S) : Set (Fin n)) := by + intro i hi j hj heq + have hi' := (mem_pairEdges (parent i) i (edge i)).mp (hedge i hi) + have hj' := (mem_pairEdges (parent j) j (edge j)).mp (hedge j hj) + rw [heq] at hi' + rcases hi' with ⟨hp,hi'⟩|⟨hi',hp⟩ <;> rcases hj' with ⟨hq,hj'⟩|⟨hj',hq⟩ + · exact hi'.symm.trans hj' + · have h1 : parent i=j := hp.symm.trans hj' + have h2 : parent j=i := hq.symm.trans hi' + have hir := hrank i hi + have hjr := hrank j hj + rw [h1] at hir + rw [h2] at hjr + omega + · have h1 : parent i=j := hp.symm.trans hj' + have h2 : parent j=i := hq.symm.trans hi' + have hir := hrank i hi + have hjr := hrank j hj + rw [h1] at hir + rw [h2] at hjr + omega + · exact hi'.symm.trans hj' + +lemma edge_unique {u v : Fin n} {e f : Edge n} + (he : e∈pairEdges u v) (hf : f∈pairEdges u v) : e=f := by + unfold pairEdges at he hf + split_ifs at he hf <;> simp_all + +lemma edgesOfLinks_parent (U S : Finset (Fin n)) (parent : Fin n → Fin n) + (edge : Fin n → Edge n) + (hedge : ∀j∈U\S, edge j∈pairEdges (parent j) j) : + edgesOfLinks ((U\S).val.map (fun j => (parent j,j)))=(U\S).image edge := by + ext e + simp only [mem_edgesOfLinks,Multiset.mem_map,Finset.mem_val,Finset.mem_image] + constructor + · rintro ⟨q,⟨j,hj,rfl⟩,he⟩ + exact ⟨j,hj,(edge_unique (hedge j hj) ((mem_pairEdges _ _ _).mpr he))⟩ + · rintro ⟨j,hj,rfl⟩ + exact ⟨(parent j,j),⟨j,hj,rfl⟩,(mem_pairEdges _ _ _).mp (hedge j hj)⟩ + +end FiniteGraph +end SKQAOA + + + +open scoped BigOperators Topology + +namespace BoundedBranch +abbrev Forest (n h : ℕ) := Tree n h × Tree n h + +def forestSize {n h : ℕ} (b : Forest n h) : ℕ := size n h b.1+size n h b.2 + +def forestLabels {n h : ℕ} (b : Forest n h) : Multiset (Fin n) := + labels n h b.1+labels n h b.2 + +def forestLinks {n h : ℕ} (r₁ r₂ : Fin n) (b : Forest n h) : Multiset (Fin n × Fin n) := + links n h r₁ b.1+links n h r₂ b.2 + +def forestWeight {n h : ℕ} (x : ℝ) (b : Forest n h) : ℝ := + weight n x h b.1*weight n x h b.2 + +@[simp] lemma card_forestLabels {n h : ℕ} (b : Forest n h) : + (forestLabels b).card=forestSize b := by simp [forestLabels,forestSize] + +@[simp] lemma card_forestLinks {n h : ℕ} (r₁ r₂ : Fin n) (b : Forest n h) : + (forestLinks r₁ r₂ b).card=forestSize b := by simp [forestLinks,forestSize] + +@[simp] lemma map_snd_forestLinks {n h : ℕ} (r₁ r₂ : Fin n) (b : Forest n h) : + (forestLinks r₁ r₂ b).map Prod.snd=forestLabels b := by + simp only [forestLinks,Multiset.map_add,map_snd_links,forestLabels] + +lemma forestWeight_eq_pow {n h : ℕ} (x : ℝ) (b : Forest n h) : + forestWeight x b=(x/(n:ℝ))^(forestSize b) := by + simp only [forestWeight,weight_eq_pow,forestSize,pow_add] + +lemma forestWeight_nonneg {n h : ℕ} {x : ℝ} (hx : 0≤x) (b : Forest n h) : + 0≤forestWeight x b := + mul_nonneg (weight_nonneg n h hx b.1) (weight_nonneg n h hx b.2) + +lemma forestWeight_scale {n h : ℕ} (x z : ℝ) (b : Forest n h) : + forestWeight (z*x) b=z^(forestSize b)*forestWeight x b := by + simp only [forestWeight_eq_pow,mul_div_assoc,mul_pow] + +lemma sum_forestWeight (n h : ℕ) (x : ℝ) : + (∑b : Forest n h,forestWeight x b)=(partition n h x)^2 := by + simp only [forestWeight,Fintype.sum_prod_type,←Finset.mul_sum,←Finset.sum_mul, + partition,pow_two] + +lemma sum_forestWeight_le_tower (n h : ℕ) {x : ℝ} (hx : 0≤x) : + (∑b : Forest n h,forestWeight x b)≤(tower x h)^2 := by + rw [sum_forestWeight] + exact pow_le_pow_left₀ (partition_nonneg n h hx) (partition_le_tower n h hx) 2 + + +lemma forest_tail_bound (n h L : ℕ) {x : ℝ} (hx : 0≤x) : + (∑b : Forest n h with L≤forestSize b,forestWeight x b)≤(tower (2*x) h)^2/(2:ℝ)^L := by + have hp : (0:ℝ)<2^L := pow_pos (by norm_num) _ + apply (le_div_iff₀ hp).mpr + rw [mul_comm,Finset.mul_sum] + calc + _ ≤ ∑b : Forest n h with L≤forestSize b,forestWeight (2*x) b := by + apply Finset.sum_le_sum + intro b hb + rw [forestWeight_scale] + exact mul_le_mul_of_nonneg_right + (pow_le_pow_right₀ (by norm_num) (Finset.mem_filter.mp hb).2) + (forestWeight_nonneg hx b) + _ ≤ ∑b : Forest n h,forestWeight (2*x) b := + Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun b _ _ => forestWeight_nonneg (by positivity) b) + _ ≤ _ := sum_forestWeight_le_tower n h (by positivity) + +end BoundedBranch + + + +open scoped BigOperators + +namespace SKQAOA.SiteHistories +open BoundedBranch Locality FiniteGraph +variable {n : ℕ} + +def roots (r : Edge n) : Finset (Fin n) := {r.1.1,r.1.2} +def reached (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : Finset (Fin n) := + ball (H∪{r}) (roots r) p + +def distance (r : Edge n) (H : Finset (Edge n)) : Fin n → ℕ := + rank (H∪{r}) (roots r) + +lemma exists_parent_pair (r : Edge n) (H : Finset (Edge n)) (p : ℕ) (v : Fin n) + (hv : v∈reached r H p\roots r) : + ∃q : Fin n × Edge n, q.2∈H∪{r} ∧ q.1∈reached r H p ∧ + distance r H q.1+1=distance r H v ∧ q.2∈pairEdges q.1 v := by + obtain ⟨u,e,he,hu,hr,hend⟩ := exists_parent (Finset.mem_sdiff.mp hv).1 + (Finset.mem_sdiff.mp hv).2 + refine ⟨(u,e),he,hu,hr,(mem_pairEdges _ _ _).mpr ?_⟩ + exact hend.symm + +def parentPair (r : Edge n) (H : Finset (Edge n)) (p : ℕ) (v : Fin n) : Fin n × Edge n := + if hv : v∈reached r H p\roots r then + Classical.choose (exists_parent_pair r H p v hv) else (v,r) + +lemma parentPair_spec (r : Edge n) (H : Finset (Edge n)) (p : ℕ) (v : Fin n) + (hv : v∈reached r H p\roots r) : + (parentPair r H p v).2∈H∪{r} ∧ (parentPair r H p v).1∈reached r H p ∧ + distance r H (parentPair r H p v).1+1=distance r H v ∧ + (parentPair r H p v).2∈pairEdges (parentPair r H p v).1 v := by + simpa only [parentPair,dite_eq_left hv] using Classical.choose_spec (exists_parent_pair r H p v hv) + +def parent (r : Edge n) (H : Finset (Edge n)) (p : ℕ) (v : Fin n) : Fin n := + (parentPair r H p v).1 + +def parentEdge (r : Edge n) (H : Finset (Edge n)) (p : ℕ) (v : Fin n) : Edge n := + (parentPair r H p v).2 + +lemma parent_spec (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + ∀v∈reached r H p\roots r, parent r H p v∈reached r H p ∧ + distance r H (parent r H p v)+1=distance r H v := by + intro v hv + exact ⟨(parentPair_spec r H p v hv).2.1,(parentPair_spec r H p v hv).2.2.1⟩ + +lemma distance_zero (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + ∀v∈reached r H p, distance r H v=0 ↔ v∈roots r := by + intro v hv + exact rank_zero_iff hv + +lemma distance_bound (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + ∀v∈reached r H p, distance r H v≤p := by + intro v hv + exact rank_le_of_mem hv + +lemma roots_subset_reached (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + roots r⊆reached r H p := subset_ball _ _ _ + +lemma parentEdge_mem (r : Edge n) (H : Finset (Edge n)) (p : ℕ) (v : Fin n) + (hv : v∈reached r H p\roots r) : parentEdge r H p v∈H := by + have hh := parentPair_spec r H p v hv + rcases Finset.mem_union.mp hh.1 with he|he + · exact he + · have he' : parentEdge r H p v=r := Finset.mem_singleton.mp he + have hvnot := (Finset.mem_sdiff.mp hv).2 + have hl : parentEdge r H p v∈pairEdges (parent r H p v) v := hh.2.2.2 + rw [he'] at hl + rcases (mem_pairEdges _ _ _).mp hl with ⟨_,hrv⟩|⟨hrv,_⟩ + · exact (hvnot (by simp [roots,←hrv])).elim + · exact (hvnot (by simp [roots,←hrv])).elim + + + +def forestCode (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : Forest n p := + (unfoldTree (reached r H p) (roots r) (parent r H p) p r.1.1, + unfoldTree (reached r H p) (roots r) (parent r H p) p r.1.2) + +lemma forestCode_labels (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + forestLabels (forestCode r H p)=(reached r H p\roots r).val := by + have he := Parent.sum_labels_roots (reached r H p) (roots r) (parent r H p) + (distance r H) (roots_subset_reached r H p) + (distance_zero r H p) (parent_spec r H p) p (distance_bound r H p) + simpa only [roots,Finset.sum_pair (ne_of_lt r.2),forestLabels,forestCode] using he + +lemma forestCode_links (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + forestLinks r.1.1 r.1.2 (forestCode r H p)= + (reached r H p\roots r).val.map (fun v => (parent r H p v,v)) := by + have he := Parent.sum_links_roots (reached r H p) (roots r) (parent r H p) + (distance r H) (roots_subset_reached r H p) + (distance_zero r H p) (parent_spec r H p) p (distance_bound r H p) + simpa only [roots,Finset.sum_pair (ne_of_lt r.2),forestLinks,forestCode] using he + +lemma forestCode_size (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + forestSize (forestCode r H p)=(reached r H p\roots r).card := by + rw [←card_forestLabels,forestCode_labels] + rfl + +def forestVertices {p : ℕ} (r : Edge n) (b : Forest n p) : Finset (Fin n) := + roots r∪(forestLabels b).toFinset + +def forestEdges {p : ℕ} (r : Edge n) (b : Forest n p) : Finset (Edge n) := + edgesOfLinks (forestLinks r.1.1 r.1.2 b) + +lemma forestCode_vertices (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + forestVertices r (forestCode r H p)=reached r H p := by + rw [forestVertices,forestCode_labels] + simp only [Finset.val_toFinset] + exact Finset.union_sdiff_of_subset (roots_subset_reached r H p) + +lemma forestCode_edges (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + forestEdges r (forestCode r H p)=(reached r H p\roots r).image (parentEdge r H p) := by + rw [forestEdges,forestCode_links] + exact edgesOfLinks_parent _ _ _ _ (fun v hv => (parentPair_spec r H p v hv).2.2.2) + +lemma forestCode_edges_subset (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + forestEdges r (forestCode r H p)⊆H := by + rw [forestCode_edges] + rintro e he + obtain ⟨v,hv,rfl⟩ := Finset.mem_image.mp he + exact parentEdge_mem r H p v hv + +lemma forestCode_edges_card (r : Edge n) (H : Finset (Edge n)) (p : ℕ) : + (forestEdges r (forestCode r H p)).card=forestSize (forestCode r H p) := by + rw [forestCode_edges,forestCode_size] + apply Finset.card_image_iff.mpr + exact parentEdge_injective _ _ _ (distance r H) _ + (fun v hv => (parent_spec r H p v hv).2) + (fun v hv => (parentPair_spec r H p v hv).2.2.2) + +end SKQAOA.SiteHistories + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Law.lean b/lean/OAI/Probability/ParisiFinite/Law.lean new file mode 100644 index 0000000000000000000000000000000000000000..83e1c9cb782c9015d79af2fd299b03f2c73ae6a7 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Law.lean @@ -0,0 +1,699 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Field + +namespace OAI + +/-! Law. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory + +namespace SKQAOA.GaussianEdge + +abbrev law : Measure ℝ := gaussianReal 0 1 + +lemma integral_sq : ∫x:ℝ, x^2 ∂law = 1 := by + have h := variance_fun_id_gaussianReal (μ:=0) (v:=1) + rw [variance_eq_integral (X:=fun x:ℝ => x) (show AEMeasurable (fun x:ℝ => x) (gaussianReal 0 1) from measurable_id.aemeasurable)] at h + simpa [integral_id_gaussianReal] using h + +lemma integrable_sq : Integrable (fun x:ℝ => x^2) law := + (memLp_id_gaussianReal (μ:=0) (v:=1) 2).integrable_sq + +lemma integral_neg_comp (f : ℝ → ℝ) : (∫x, f (-x) ∂law) = ∫x, f x ∂law := by + have h : MeasurePreserving (fun x:ℝ => -x) law law := + ⟨measurable_neg, by simpa using (gaussianReal_map_neg (μ:=0) (v:=1))⟩ + exact h.integral_comp (MeasurableEquiv.neg ℝ).measurableEmbedding f + +lemma integral_zero_of_odd (f : ℝ → ℝ) (h : ∀x, f (-x) = -f x) : + (∫x, f x ∂law)=0 := by + have he := integral_neg_comp f + simp_rw [h] at he + rw [integral_neg] at he + linarith + +lemma integral_sq_bound (f : ℝ → ℝ) (hf : Continuous f) {C : ℝ} + (_hC : 0 ≤ C) (hb : ∀x, |f x| ≤ C*x^2) : |∫x, f x ∂law| ≤ C := by + have hi : Integrable f law := (integrable_sq.const_mul C).mono' + hf.aestronglyMeasurable (Filter.Eventually.of_forall (by simpa using hb)) + calc + |∫x, f x ∂law| ≤ ∫x, |f x| ∂law := by + simpa only [Real.norm_eq_abs] using norm_integral_le_integral_norm f + _ ≤ ∫x:ℝ, C*x^2 ∂law := integral_mono hi.abs (integrable_sq.const_mul C) hb + _ = C := by rw [integral_const_mul, integral_sq, mul_one] + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + + + +def trigWord (θ : ι → ℝ) (S : Finset ι) (x : ℝ) : ℝ := + (∏i∈S, Real.sin (θ i*x)) * ∏i∈Sᶜ, Real.cos (θ i*x) + +lemma continuous_trigWord (θ : ι → ℝ) (S : Finset ι) : Continuous (trigWord θ S) := by + unfold trigWord + fun_prop + +lemma trigWord_neg (θ : ι → ℝ) (S : Finset ι) (x : ℝ) : + trigWord θ S (-x) = (-1)^S.card*trigWord θ S x := by + simp only [trigWord, mul_neg, Real.sin_neg, Real.cos_neg, Finset.prod_neg] + ring + +omit [Fintype ι] [DecidableEq ι] in +lemma abs_prod_le_one {s : Finset ι} {f : ι → ℝ} (h : ∀i∈s, |f i| ≤ 1) : + |∏i∈s, f i| ≤ 1 := by + rw [Finset.abs_prod] + exact (Finset.prod_le_one₀ (fun _ _ => abs_nonneg _) h) + +lemma abs_trigWord_le_one (θ : ι → ℝ) (S : Finset ι) (x : ℝ) : + |trigWord θ S x| ≤ 1 := by + rw [trigWord, abs_mul] + exact (mul_le_of_le_one_left (abs_nonneg _) + (abs_prod_le_one (by intros; exact Real.abs_sin_le_one _))).trans + (abs_prod_le_one (by intros; exact Real.abs_cos_le_one _)) + + +lemma abs_trigWord_le_subpattern (θ : ι → ℝ) {T S : Finset ι} + (hTS : T ⊆ S) (x : ℝ) : |trigWord θ S x| ≤ ∏i∈T, |Real.sin (θ i*x)| := by + calc + |trigWord θ S x| ≤ |∏i∈S, Real.sin (θ i*x)| := by + rw [trigWord, abs_mul] + exact mul_le_of_le_one_right (abs_nonneg _) + (abs_prod_le_one (by intros; exact Real.abs_cos_le_one _)) + _ ≤ ∏i∈T, |Real.sin (θ i*x)| := by + rw [Finset.abs_prod] + exact Finset.prod_le_prod_of_subset_of_le_one₀ hTS + (by intros; exact abs_nonneg _) (by intros; exact Real.abs_sin_le_one _) + +lemma abs_trigWord_le_one_sine (θ : ι → ℝ) {S : Finset ι} {i : ι} + (hi : i∈S) (x : ℝ) : |trigWord θ S x| ≤ |θ i| *|x| := by + calc + _ ≤ |Real.sin (θ i*x)| := by + simpa using abs_trigWord_le_subpattern θ (Finset.singleton_subset_iff.mpr hi) x + _ ≤ |θ i| *|x| := by simpa [abs_mul] using (Real.abs_sin_le_abs (x:=θ i*x)) + +lemma abs_trigWord_le_two_sines (θ : ι → ℝ) {S : Finset ι} {i j : ι} + (hi : i∈S) (hj : j∈S) (hij : i≠j) (x : ℝ) : + |trigWord θ S x| ≤ (|θ i| *|θ j|)*x^2 := by + calc + _ ≤ |Real.sin (θ i*x)| *|Real.sin (θ j*x)| := by + simpa [hij] using abs_trigWord_le_subpattern θ + (show {i,j} ⊆ S by intro k hk; rcases Finset.mem_insert.mp hk with rfl | hk; exact hi; obtain rfl := Finset.mem_singleton.mp hk; exact hj) x + _ ≤ (|θ i| *|x|) * (|θ j| *|x|) := mul_le_mul + (by simpa [abs_mul] using (Real.abs_sin_le_abs (x:=θ i*x))) + (by simpa [abs_mul] using (Real.abs_sin_le_abs (x:=θ j*x))) + (abs_nonneg _) (mul_nonneg (abs_nonneg _) (abs_nonneg _)) + _ = (|θ i| *|θ j|)*x^2 := by rw [show x^2=|x|^2 by simp]; ring + +omit [Fintype ι] in +lemma abs_prod_sub_one_le (s : Finset ι) (f : ι → ℝ) + (hf : ∀i∈s, |f i| ≤ 1) : |(∏i∈s, f i)-1| ≤ ∑i∈s, |f i-1| := by + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => + rw [Finset.prod_insert ha,Finset.sum_insert ha] + calc + |f a*(∏i∈s,f i)-1| = |f a*((∏i∈s,f i)-1)+(f a-1)| := by congr 1; ring + _ ≤ |f a*((∏i∈s,f i)-1)|+|f a-1| := abs_add_le _ _ + _ ≤ |(∏i∈s,f i)-1|+|f a-1| := by + rw [abs_mul] + exact add_le_add (mul_le_of_le_one_left (abs_nonneg _) (hf a (by simp))) le_rfl + _ ≤ (∑i∈s,|f i-1|)+|f a-1| := add_le_add (ih (by aesop)) le_rfl + _ = |f a-1|+∑i∈s,|f i-1| := add_comm _ _ + +lemma abs_cos_sub_one_le_sq (x : ℝ) : |Real.cos x-1| ≤ x^2/2 := by + have hs := Real.abs_sin_le_abs (x:=x/2) + have hs2 : (Real.sin (x/2))^2 ≤ (x/2)^2 := by + nlinarith [sq_abs (Real.sin (x/2)),sq_abs (x/2),abs_nonneg (Real.sin (x/2)),abs_nonneg (x/2)] + have hc := Real.cos_two_mul_eq_one_sub (x/2) + rw [show (2:ℝ)*(x/2)=x by ring] at hc + rw [abs_of_nonpos (sub_nonpos.mpr (Real.cos_le_one _))] + nlinarith + +lemma abs_trigWord_empty_sub_one (θ : ι → ℝ) (x : ℝ) : + |trigWord θ ∅ x-1| ≤ ((∑i, θ i^2)/2)*x^2 := by + simp only [trigWord,Finset.prod_empty,one_mul,Finset.compl_empty] + calc + _ ≤ ∑i, |Real.cos (θ i*x)-1| := + abs_prod_sub_one_le _ _ (by intros; exact Real.abs_cos_le_one _) + _ ≤ ∑i, (θ i*x)^2/2 := Finset.sum_le_sum (by intros; exact abs_cos_sub_one_le_sq _) + _ = ((∑i, θ i^2)/2)*x^2 := by + simp_rw [mul_pow,div_eq_mul_inv] + rw [←Finset.sum_mul,←Finset.sum_mul] + ring + + +lemma integral_trigWord_odd (θ : ι → ℝ) (S : Finset ι) (hS : Odd S.card) : + (∫x, trigWord θ S x ∂law)=0 := by + apply integral_zero_of_odd + intro x + rw [trigWord_neg,hS.neg_one_pow] + ring + + +lemma integral_marked_trigWord_even (θ : ι → ℝ) (S : Finset ι) (hS : Even S.card) : + (∫x, x*trigWord θ S x ∂law)=0 := by + apply integral_zero_of_odd + intro x + rw [trigWord_neg,hS.neg_one_pow] + ring + +lemma integral_trigWord_two_sines (θ : ι → ℝ) {S : Finset ι} {i j : ι} + (hi : i∈S) (hj : j∈S) (hij : i≠j) : + |∫x, trigWord θ S x ∂law| ≤ |θ i| *|θ j| := + integral_sq_bound _ (continuous_trigWord θ S) (mul_nonneg (abs_nonneg _) (abs_nonneg _)) + (abs_trigWord_le_two_sines θ hi hj hij) + +lemma integral_marked_trigWord_one_sine (θ : ι → ℝ) {S : Finset ι} {i : ι} + (hi : i∈S) : |∫x, x*trigWord θ S x ∂law| ≤ |θ i| := by + apply integral_sq_bound _ (continuous_id.mul (continuous_trigWord θ S)) (abs_nonneg _) + intro x + calc + |x*trigWord θ S x| ≤ |x| *(|θ i| *|x|) := by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (abs_trigWord_le_one_sine θ hi x) (abs_nonneg _) + _ = |θ i| *x^2 := by rw [show x^2=|x|^2 by simp]; ring + + +lemma integral_trigWord_empty_sub_one (θ : ι → ℝ) : + |∫x, (trigWord θ ∅ x-1) ∂law| ≤ (∑i, θ i^2)/2 := + integral_sq_bound _ ((continuous_trigWord θ ∅).sub continuous_const) + (div_nonneg (Finset.sum_nonneg (by intros; positivity)) (by norm_num)) + (abs_trigWord_empty_sub_one θ) + +end SKQAOA.GaussianEdge + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory + +namespace ClassicalGaussian + +theorem integrable_real_pow {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {f : Ω → ℝ} (r : ℕ) (hf : MemLp f r μ) : + Integrable (fun x => f x^r) μ := by + apply hf.integrable_norm_pow'.mono' (hf.aestronglyMeasurable.pow r) + exact Filter.Eventually.of_forall (fun x => le_of_eq (norm_pow _ _)) + +theorem integrable_standard_pow (r : ℕ) : + Integrable (fun x : ℝ => x^r) (gaussianReal 0 1) := by + apply integrable_real_pow r + exact memLp_id_gaussianReal' _ (by simp) + + + +theorem standard_fourth : (∫x : ℝ,x^4 ∂gaussianReal 0 1)=3 := by + have h := SKGaussian.integral_mul_eq_integral_deriv + (f:=fun x : ℝ=>x^3) (f':=fun x : ℝ=>3*x^2) + (fun x => by simpa using (hasDerivAt_id x).fun_pow 3) + (integrable_standard_pow 3) ((integrable_standard_pow 2).const_mul 3) + (by convert integrable_standard_pow 4 using 1; funext x; ring) + have he : (fun x : ℝ=>x*x^3)=(fun x : ℝ=>x^4) := by funext x; ring + rw [he,integral_const_mul,SKQAOA.GaussianEdge.integral_sq,mul_one] at h + exact h + +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem memLp_field_nat (d : E) (r : ℕ) : MemLp (field E d) r (stdGaussian E) := by + exact (innerSL ℝ d).comp_memLp' (IsGaussian.memLp_id (stdGaussian E) r (by simp)) + +theorem integrable_field_pow (d : E) (r : ℕ) : + Integrable (fun g => field E d g^r) (stdGaussian E) := + integrable_real_pow r (memLp_field_nat E d r) + + + +theorem field_fourth (d : E) : (∫g,field E d g^4 ∂stdGaussian E)=3*‖d‖^4 := by + have hf : HasLaw (field E d) (gaussianReal 0 (‖d‖₊^2)) (stdGaussian E) := + ⟨by unfold field; fun_prop,field_law E d⟩ + have hs : HasLaw (fun x : ℝ => ‖d‖*x) (gaussianReal 0 (‖d‖₊^2)) + (gaussianReal 0 1) := by + refine ⟨by fun_prop,?_⟩ + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · apply NNReal.coe_injective + simp [pow_two] + calc + _ = ∫x : ℝ,x^4 ∂gaussianReal 0 (‖d‖₊^2) := + hf.integral_comp (by fun_prop) + _ = ∫x : ℝ,(‖d‖*x)^4 ∂gaussianReal 0 1 := + (hs.integral_comp (by fun_prop : AEStronglyMeasurable (fun x : ℝ => x^4) + (gaussianReal 0 (‖d‖₊^2)))).symm + _ = 3*‖d‖^4 := by + simp only [mul_pow,integral_const_mul,standard_fourth] + ring + +end ClassicalGaussian + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory + +namespace ClassicalGaussian +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[simp] theorem field_add (d e : E) (g : E) : + field E (d+e) g=field E d g+field E e g := by + simp [field,inner_add_left] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[simp] theorem field_sub (d e : E) (g : E) : + field E (d-e) g=field E d g-field E e g := by + simp [field,inner_sub_left] + +theorem memLp_field_product (d e : E) : + MemLp (fun g=>field E d g*field E e g) 2 (stdGaussian E) := by + let : ENNReal.HolderTriple 4 4 2 := ⟨by + apply (ENNReal.toReal_eq_toReal_iff' (by simp) (by simp)).mp + norm_num [ENNReal.toReal_add]⟩ + exact (memLp_field_nat E d 4).fun_mul (memLp_field_nat E e 4) + +theorem integrable_field_four (a b c d : E) : + Integrable (fun g=>field E a g*field E b g*(field E c g*field E d g)) + (stdGaussian E) := + (memLp_field_product E a b).integrable_mul (memLp_field_product E c d) + +private theorem polarization (a b c d : ℝ) : + 192*(a*b*(c*d)) = + (a+b+c+d)^4-(a+b+c-d)^4-(a+b-c+d)^4+(a+b-c-d)^4 + -(a-b+c+d)^4+(a-b+c-d)^4+(a-b-c+d)^4-(a-b-c-d)^4 := by ring + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +private theorem fourth_norm (d : E) : ‖d‖^4=⟪d,d⟫^2 := by + rw [show (4:ℕ)=2*2 from rfl,pow_mul,real_inner_self_eq_norm_sq] + + + +theorem field_wick_four (a b c d : E) : + (∫g,field E a g*field E b g*(field E c g*field E d g) ∂stdGaussian E)= + ⟪a,b⟫*⟪c,d⟫+⟪a,c⟫*⟪b,d⟫+⟪a,d⟫*⟪b,c⟫ := by + have he : (fun g=>192*(field E a g*field E b g*(field E c g*field E d g))) = + (fun g=>field E (a+b+c+d) g^4-field E (a+b+c-d) g^4- + field E (a+b-c+d) g^4+field E (a+b-c-d) g^4- + field E (a-b+c+d) g^4+field E (a-b+c-d) g^4+ + field E (a-b-c+d) g^4-field E (a-b-c-d) g^4) := by + funext g + simp only [field_add,field_sub] + exact polarization _ _ _ _ + have h := congrArg (fun f : E → ℝ=>∫g,f g ∂stdGaussian E) he + rw [integral_const_mul] at h + have h2 := (integrable_field_pow E (a+b+c+d) 4).sub + (integrable_field_pow E (a+b+c-d) 4) + have h3 := h2.sub (integrable_field_pow E (a+b-c+d) 4) + have h4 := h3.add (integrable_field_pow E (a+b-c-d) 4) + have h5 := h4.sub (integrable_field_pow E (a-b+c+d) 4) + have h6 := h5.add (integrable_field_pow E (a-b+c-d) 4) + have h7 := h6.add (integrable_field_pow E (a-b-c+d) 4) + have hs8 := integral_sub h7 (integrable_field_pow E (a-b-c-d) 4) + have hs7 := integral_add h6 (integrable_field_pow E (a-b-c+d) 4) + have hs6 := integral_add h5 (integrable_field_pow E (a-b+c-d) 4) + have hs5 := integral_sub h4 (integrable_field_pow E (a-b+c+d) 4) + have hs4 := integral_add h3 (integrable_field_pow E (a+b-c-d) 4) + have hs3 := integral_sub h2 (integrable_field_pow E (a+b-c+d) 4) + have hs2 := integral_sub (integrable_field_pow E (a+b+c+d) 4) + (integrable_field_pow E (a+b+c-d) 4) + simp only [Pi.sub_apply,Pi.add_apply] at hs8 hs7 hs6 hs5 hs4 hs3 hs2 + rw [hs8,hs7,hs6,hs5,hs4,hs3,hs2] at h + simp only [field_fourth,fourth_norm] at h + simp only [inner_add_left,inner_add_right,inner_sub_left,inner_sub_right] at h + simp only [real_inner_comm] at h ⊢ + linear_combination h / 192 + +end ClassicalGaussian + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory + +namespace ClassicalGaussian +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + + + +def centeredQuadratic (d e : E) (g : E) : ℝ := + field E d g*field E e g-⟪d,e⟫ + +theorem memLp_centeredQuadratic (d e : E) : + MemLp (centeredQuadratic E d e) 2 (stdGaussian E) := + (memLp_field_product E d e).sub (memLp_const _) + +theorem integral_centeredQuadratic (d e : E) : + (∫g,centeredQuadratic E d e g ∂stdGaussian E)=0 := by + simp only [centeredQuadratic] + have hs := integral_sub ((memLp_field E d).integrable_mul + (memLp_field E e)) (integrable_const (⟪d,e⟫)) + simp only [Pi.mul_apply] at hs + rw [hs,field_covariance] + simp + +theorem covariance_centeredQuadratic (a b c d : E) : + (∫g,centeredQuadratic E a b g*centeredQuadratic E c d g ∂stdGaussian E)= + ⟪a,c⟫*⟪b,d⟫+⟪a,d⟫*⟪b,c⟫ := by + have he : (fun g=>centeredQuadratic E a b g*centeredQuadratic E c d g)= + (fun g=>field E a g*field E b g*(field E c g*field E d g)- + ⟪c,d⟫*(field E a g*field E b g)- + ⟪a,b⟫*(field E c g*field E d g)+⟪a,b⟫*⟪c,d⟫) := by + funext g + unfold centeredQuadratic + ring + rw [he] + have hab := (memLp_field E a).integrable_mul (memLp_field E b) + have hcd := (memLp_field E c).integrable_mul (memLp_field E d) + have h4 := integrable_field_four E a b c d + have hs3 := integral_add ((h4.sub (hab.const_mul ⟪c,d⟫)).sub + (hcd.const_mul ⟪a,b⟫)) (integrable_const (⟪a,b⟫*⟪c,d⟫)) + have hs2 := integral_sub (h4.sub (hab.const_mul ⟪c,d⟫)) (hcd.const_mul ⟪a,b⟫) + have hs1 := integral_sub h4 (hab.const_mul ⟪c,d⟫) + simp only [Pi.sub_apply,Pi.mul_apply] at hs3 hs2 hs1 + rw [hs3,hs2,hs1] + simp only [integral_const_mul,field_covariance,field_wick_four,integral_const, + probReal_univ,one_smul] + ring + + + +theorem quadratic_sum_variance {ι : Type*} (s : Finset ι) (d e : ι → E) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) : + (∫g,(∑i∈s,centeredQuadratic E (d i) (e i) g)^2 ∂stdGaussian E)= + ∑i∈s,(‖d i‖^2*‖e i‖^2+⟪d i,e i⟫^2) := by + have hi (i j : ι) : Integrable + (fun g=>centeredQuadratic E (d i) (e i) g* + centeredQuadratic E (d j) (e j) g) (stdGaussian E) := + (memLp_centeredQuadratic E _ _).integrable_mul (memLp_centeredQuadratic E _ _) + simp only [pow_two,Finset.sum_mul,Finset.mul_sum] + rw [integral_finsetSum] + · apply Finset.sum_congr rfl + intro i his + rw [integral_finsetSum] + · simp only [covariance_centeredQuadratic] + rw [Finset.sum_eq_single i] + · simp only [real_inner_self_eq_norm_sq,real_inner_comm (e i) (d i)] + ring + · intro j hjs hji + rcases ho j hjs i his hji with ⟨hdd,hde⟩ + simp [hdd,hde] + · simp [his] + · intro j hjs + exact hi j i + · intro i his + exact integrable_finsetSum _ (fun j hjs=>hi j i) + + + +theorem quadratic_sum_variance_le {ι : Type*} (s : Finset ι) (d e : ι → E) + (p : ι → ℝ) (C : ℝ) (hC : 0≤C) (hp : ∀i∈s,0≤p i) + (hd : ∀i∈s,‖d i‖^2≤C*p i) (he : ∀i∈s,‖e i‖^2≤C*p i) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) : + (∫g,(∑i∈s,centeredQuadratic E (d i) (e i) g)^2 ∂stdGaussian E)≤ + 2*C^2*∑i∈s,(p i)^2 := by + rw [quadratic_sum_variance E s d e ho,Finset.mul_sum] + apply Finset.sum_le_sum + intro i his + have hc : ⟪d i,e i⟫^2≤‖d i‖^2*‖e i‖^2 := by + have h := sq_le_sq₀ (abs_nonneg ⟪d i,e i⟫) + (mul_nonneg (norm_nonneg _) (norm_nonneg _)) |>.mpr (abs_real_inner_le_norm (d i) (e i)) + simpa only [sq_abs,mul_pow] using h + have hm : ‖d i‖^2*‖e i‖^2≤(C*p i)^2 := by + simpa only [pow_two] using mul_le_mul (hd i his) (he i his) + (sq_nonneg _) (mul_nonneg hC (hp i his)) + nlinarith + +end ClassicalGaussian + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory Filter + +namespace ClassicalGaussian + + + +def phaseError (t x : ℝ) : ℝ := + ‖Complex.exp (Complex.I * ((t*x : ℝ) : ℂ))-1‖^2 + +theorem phaseError_nonneg (t x : ℝ) : 0≤phaseError t x := sq_nonneg _ + +theorem continuous_phaseError (t : ℝ) : Continuous (phaseError t) := by + unfold phaseError + fun_prop + +theorem phaseError_le_sq (t x : ℝ) : phaseError t x≤t^2*x^2 := by + have h := Real.norm_exp_I_mul_ofReal_sub_one_le (x:=t*x) + have hsq := (sq_le_sq₀ (norm_nonneg _) (norm_nonneg _)).mpr h + simpa only [phaseError,Real.norm_eq_abs,sq_abs,mul_pow] using hsq + +theorem phaseError_le_four (t x : ℝ) : phaseError t x≤4 := by + have h : ‖Complex.exp (Complex.I * ((t*x : ℝ) : ℂ))-1‖≤2 := by + calc + _≤‖Complex.exp (Complex.I * ((t*x : ℝ) : ℂ))‖+‖(1:ℂ)‖ := norm_sub_le _ _ + _=2 := by rw [Complex.norm_exp_I_mul_ofReal]; norm_num + unfold phaseError + have hn := norm_nonneg (Complex.exp (Complex.I * ((t*x : ℝ) : ℂ))-1) + nlinarith + +variable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ] + +theorem integrable_phaseError {q : Ω → ℝ} (hq : MemLp q 2 μ) (t : ℝ) : + Integrable (fun g=>phaseError t (q g)) μ := by + apply ((integrable_real_pow 2 hq).const_mul (t^2)).mono' + ((continuous_phaseError t).comp_aestronglyMeasurable hq.aestronglyMeasurable) + exact Eventually.of_forall fun g=>by + rw [Real.norm_eq_abs,abs_of_nonneg (phaseError_nonneg _ _)] + exact phaseError_le_sq _ _ + + +theorem integral_phaseError_le {q : Ω → ℝ} (hq : MemLp q 2 μ) (t : ℝ) : + (∫g,phaseError t (q g) ∂μ)≤t^2*∫g,q g^2 ∂μ := by + rw [← integral_const_mul] + exact integral_mono (integrable_phaseError μ hq t) + ((integrable_real_pow 2 hq).const_mul _) (fun _=>phaseError_le_sq _ _) + +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + + + +theorem quadratic_phase_L2_le {ι : Type*} (s : Finset ι) (d e : ι → E) + (p : ι → ℝ) (C : ℝ) (hC : 0≤C) (hp : ∀i∈s,0≤p i) + (hd : ∀i∈s,‖d i‖^2≤C*p i) (he : ∀i∈s,‖e i‖^2≤C*p i) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) (t : ℝ) : + (∫g,phaseError t (∑i∈s,centeredQuadratic E (d i) (e i) g) ∂stdGaussian E)≤ + t^2*(2*C^2*∑i∈s,(p i)^2) := by + apply le_trans (integral_phaseError_le (stdGaussian E) ?_ t) + · exact mul_le_mul_of_nonneg_left (quadratic_sum_variance_le E s d e p C hC hp hd he ho) + (sq_nonneg t) + · exact memLp_finsetSum s (fun i hi=>memLp_centeredQuadratic E (d i) (e i)) + +end ClassicalGaussian + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory Filter + +namespace ClassicalGaussian +variable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ] + + + +omit [IsFiniteMeasure μ] in +theorem weighted_bounded_integral_tendsto {f : ℕ → Ω → ℝ} (B : ℝ) + (hf : ∀n,Integrable (f n) μ) (hn : ∀n x,0≤f n x) (hb : ∀n x,f n x≤B) + (ht : Tendsto (fun n=>∫x,f n x ∂μ) atTop (𝓝 0)) + (ρ : Ω → ℝ) (hρ : Integrable ρ μ) : + Tendsto (fun n=>∫x,|ρ x| *f n x ∂μ) atTop (𝓝 0) := by + have he (n : ℕ) : eLpNorm (f n-(0:Ω → ℝ)) 1 μ= + ENNReal.ofReal (∫x,f n x ∂μ) := by + simp only [sub_zero] + rw [eLpNorm_one_eq_lintegral_enorm (hf n).aestronglyMeasurable, + ← ofReal_integral_norm_eq_lintegral_enorm (hf n)] + congr 1 + apply integral_congr_ae + exact Eventually.of_forall fun x=>Real.norm_of_nonneg (hn n x) + have hp : TendstoInMeasure μ f atTop (0:Ω → ℝ) := by + apply tendstoInMeasure_of_tendsto_eLpNorm (p:=1) (by norm_num) + simp_rw [he] + simpa only [ENNReal.ofReal_zero,Function.comp_def] using (ENNReal.continuous_ofReal.tendsto 0).comp ht + apply tendsto_of_subseq_tendsto + intro ns hns + obtain ⟨ms,_,hms⟩ := (hp.comp hns).exists_seq_tendsto_ae + refine ⟨ms,?_⟩ + have hd := tendsto_integral_of_dominated_convergence + (F:=fun n x=>|ρ x| *f (ns (ms n)) x) (f:=fun _ => (0:ℝ)) + (fun x=>|ρ x| *B) + (fun n=>hρ.abs.aestronglyMeasurable.mul (hf _).aestronglyMeasurable) + (hρ.abs.mul_const B) ?_ ?_ + · simpa only [integral_zero] using hd + · intro n + exact Eventually.of_forall fun x=>by + rw [Real.norm_of_nonneg (mul_nonneg (abs_nonneg _) (hn _ _))] + exact mul_le_mul_of_nonneg_left (hb _ _) (abs_nonneg _) + · filter_upwards [hms] with x hx + simpa only [Pi.zero_apply,mul_zero,Function.comp_def] using hx.const_mul |ρ x| + + + +theorem phase_weighted_L2_tendsto {q : ℕ → Ω → ℝ} (hq : ∀n,MemLp (q n) 2 μ) + (ht : Tendsto (fun n=>∫x,q n x^2 ∂μ) atTop (𝓝 0)) (t : ℝ) + (ρ : Ω → ℝ) (hρ : Integrable ρ μ) : + Tendsto (fun n=>∫x,|ρ x| *phaseError t (q n x) ∂μ) atTop (𝓝 0) := by + apply weighted_bounded_integral_tendsto μ 4 + (fun n=>integrable_phaseError μ (hq n) t) + (fun _ _=>phaseError_nonneg _ _) (fun _ _=>phaseError_le_four _ _) + ?_ ρ hρ + apply squeeze_zero (fun n=>integral_nonneg (fun x=>phaseError_nonneg _ _)) + (fun n=>integral_phaseError_le μ (hq n) t) + simpa only [mul_zero] using ht.const_mul (t^2) + + + +theorem phase_vector_L2_tendsto {q : ℕ → Ω → ℝ} (hq : ∀n,MemLp (q n) 2 μ) + (ht : Tendsto (fun n=>∫x,q n x^2 ∂μ) atTop (𝓝 0)) (t : ℝ) + (ψ : Ω → ℂ) (hψ : MemLp ψ 2 μ) : + Tendsto (fun n=>∫x,‖Complex.exp (Complex.I*((t*q n x : ℝ):ℂ))*ψ x-ψ x‖^2 ∂μ) + atTop (𝓝 0) := by + have hw := phase_weighted_L2_tendsto μ hq ht t (fun x=>‖ψ x‖^2) + hψ.integrable_norm_pow' + have he (n : ℕ) (x : Ω) : + ‖Complex.exp (Complex.I*((t*q n x : ℝ):ℂ))*ψ x-ψ x‖^2= + |‖ψ x‖^2| *phaseError t (q n x) := by + rw [show Complex.exp (Complex.I*((t*q n x : ℝ):ℂ))*ψ x-ψ x= + (Complex.exp (Complex.I*((t*q n x : ℝ):ℂ))-1)*ψ x by ring] + rw [norm_mul,mul_pow,abs_of_nonneg (sq_nonneg _)] + exact mul_comm _ _ + simp_rw [he] + exact hw + +end ClassicalGaussian + + + +open scoped BigOperators TensorProduct + +namespace OrthogonalKernels +variable {𝕜 E F ι : Type*} [RCLike 𝕜] + [NormedAddCommGroup E] [InnerProductSpace 𝕜 E] + [NormedAddCommGroup F] [InnerProductSpace 𝕜 F] + + +theorem norm_sum_sq (s : Finset ι) (d : ι → E) + (ho : ∀i∈s,∀j∈s,i≠j → inner 𝕜 (d i) (d j)=0) : + ‖∑i∈s,d i‖^2=∑i∈s,‖d i‖^2 := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => + have hz : inner 𝕜 (d a) (∑i∈s,d i)=0 := by + rw [inner_sum] + apply Finset.sum_eq_zero + intro i hi + exact ho a (Finset.mem_insert_self _ _) i (Finset.mem_insert_of_mem hi) + (by intro h; subst i; exact ha hi) + have hh := norm_add_sq_eq_norm_sq_add_norm_sq_of_inner_eq_zero _ _ hz + simp only [←pow_two] at hh + rw [Finset.sum_insert ha,Finset.sum_insert ha,hh,ih] + intro i hi j hj hn + exact ho i (Finset.mem_insert_of_mem hi) j (Finset.mem_insert_of_mem hj) hn + + + +theorem tensor_sum_norm_sq (s : Finset ι) (d : ι → E) (e : ι → F) + (ho : ∀i∈s,∀j∈s,i≠j → inner 𝕜 (d i) (d j)=0) : + ‖∑i∈s,d i ⊗ₜ[𝕜] e i‖^2=∑i∈s,‖d i‖^2*‖e i‖^2 := by + rw [norm_sum_sq (𝕜:=𝕜)] + · simp only [TensorProduct.norm_tmul,mul_pow] + · intro i hi j hj hn + rw [TensorProduct.inner_tmul,ho i hi j hj hn,zero_mul] + + + +theorem tensor_sum_norm_sq_le (s : Finset ι) (d : ι → E) (e : ι → F) + (p : ι → ℝ) (C D : ℝ) (hC : 0≤C) (hp : ∀i∈s,0≤p i) + (hd : ∀i∈s,‖d i‖^2≤C*p i) (he : ∀i∈s,‖e i‖^2≤D*p i) + (ho : ∀i∈s,∀j∈s,i≠j → inner 𝕜 (d i) (d j)=0) : + ‖∑i∈s,d i ⊗ₜ[𝕜] e i‖^2≤C*D*∑i∈s,(p i)^2 := by + rw [tensor_sum_norm_sq s d e ho,Finset.mul_sum] + apply Finset.sum_le_sum + intro i hi + have h := mul_le_mul (hd i hi) (he i hi) (sq_nonneg ‖e i‖) + (mul_nonneg hC (hp i hi)) + nlinarith + + + +theorem rankOne_sum_apply_sq_le (s : Finset ι) (d : ι → E) (e : ι → F) + (ho : ∀i∈s,∀j∈s,i≠j → inner 𝕜 (d i) (d j)=0) (x : F) : + ‖(∑i∈s,InnerProductSpace.rankOne 𝕜 (d i) (e i)) x‖^2≤ + (∑i∈s,‖d i‖^2*‖e i‖^2)*‖x‖^2 := by + simp only [sum_apply,InnerProductSpace.rankOne_apply] + rw [norm_sum_sq (𝕜:=𝕜),Finset.sum_mul] + · apply Finset.sum_le_sum + intro i hi + rw [norm_smul,mul_pow] + have h := sq_le_sq₀ (norm_nonneg (inner 𝕜 (e i) x)) + (mul_nonneg (norm_nonneg _) (norm_nonneg _)) |>.mpr (norm_inner_le_norm (e i) x) + simp only [mul_pow] at h + nlinarith [mul_le_mul_of_nonneg_right h (sq_nonneg ‖d i‖)] + · intro i hi j hj hn + simp only [inner_smul_left,inner_smul_right,ho i hi j hj hn,mul_zero] + + + +theorem rankOne_sum_norm_le (s : Finset ι) (d : ι → E) (e : ι → F) + (ho : ∀i∈s,∀j∈s,i≠j → inner 𝕜 (d i) (d j)=0) : + ‖∑i∈s,InnerProductSpace.rankOne 𝕜 (d i) (e i)‖≤ + Real.sqrt (∑i∈s,‖d i‖^2*‖e i‖^2) := by + apply ContinuousLinearMap.opNorm_le_bound _ (Real.sqrt_nonneg _) + intro x + have h := rankOne_sum_apply_sq_le s d e ho x + have hs : 0≤∑i∈s,‖d i‖^2*‖e i‖^2 := + Finset.sum_nonneg (fun i hi=>mul_nonneg (sq_nonneg _) (sq_nonneg _)) + apply (sq_le_sq₀ (norm_nonneg _) (mul_nonneg (Real.sqrt_nonneg _) (norm_nonneg _))).mp + simpa only [mul_pow,Real.sq_sqrt hs] using h + +end OrthogonalKernels + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/LogMean.lean b/lean/OAI/Probability/ParisiFinite/LogMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce14a75e523baaede368de5fb4a56138f53ec584 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/LogMean.lean @@ -0,0 +1,688 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Shape + +namespace OAI + +/-! Log Mean. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal + +namespace ParisiFinite + + + +def logMean {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) (a : ℝ) + (f : Ω → ℝ) : ℝ := + if a = 0 then ∫ z, f z ∂μ else Real.log (∫ z, Real.exp (a * f z) ∂μ) / a + + +def step (a s : ℝ) (f : ℝ → ℝ) (x : ℝ) : ℝ := + logMean (gaussianReal 0 1) a (fun z => f (x + s * z)) + + +def terminal (β x : ℝ) : ℝ := Real.log (2 * Real.cosh (β * x)) / β + +lemma integral_exp_pos {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {f : Ω → ℝ} + (hf : Integrable (fun z => Real.exp (f z)) μ) : + 0 < ∫ z, Real.exp (f z) ∂μ := by + apply (integral_pos_iff_support_of_nonneg (fun z => (Real.exp_pos _).le) hf).2 + have h : Function.support (fun z => Real.exp (f z)) = Set.univ := by + ext z + simp [Function.mem_support, (Real.exp_pos (f z)).ne'] + rw [h, measure_univ] + exact zero_lt_one + +@[simp] lemma logMean_zero {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + (f : Ω → ℝ) : logMean μ 0 f = ∫ z, f z ∂μ := by simp [logMean] + +@[simp] lemma logMean_const {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + [IsProbabilityMeasure μ] (a c : ℝ) : logMean μ a (fun _ => c) = c := by + by_cases ha : a = 0 + · simp [ha, logMean] + · simp [logMean, ha, Real.log_exp, mul_div_cancel_left₀ _ ha] + +lemma logMean_add_const {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {a : ℝ} {f : Ω → ℝ} + (hf : Integrable f μ) (he : Integrable (fun z => Real.exp (a * f z)) μ) + (c : ℝ) : logMean μ a (fun z => f z + c) = logMean μ a f + c := by + by_cases ha : a = 0 + · simp [logMean, ha, integral_add hf (integrable_const c)] + · have hp := integral_exp_pos he + simp only [logMean, ha, ↓reduceIte] + simp_rw [mul_add, Real.exp_add] + rw [integral_mul_const, Real.log_mul hp.ne' (Real.exp_pos _).ne', Real.log_exp] + field_simp + + +lemma logMean_mono {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {a : ℝ} (ha : 0 ≤ a) {f g : Ω → ℝ} + (hf : Integrable f μ) (hg : Integrable g μ) + (hef : Integrable (fun z => Real.exp (a * f z)) μ) + (heg : Integrable (fun z => Real.exp (a * g z)) μ) + (hfg : ∀ z, f z ≤ g z) : logMean μ a f ≤ logMean μ a g := by + by_cases h0 : a = 0 + · simp only [logMean, h0, ↓reduceIte] + exact integral_mono hf hg hfg + · simp only [logMean, h0, ↓reduceIte] + apply div_le_div_of_nonneg_right _ ha + apply Real.log_le_log (integral_exp_pos hef) + exact integral_mono hef heg fun z => Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (hfg z) ha) + + +lemma integrable_exp_abs (c : ℝ) : + Integrable (fun z : ℝ => Real.exp (c * |z|)) (gaussianReal 0 1) := by + apply ((integrable_exp_mul_gaussianReal c).add + (integrable_exp_mul_gaussianReal (-c))).mono' + (by fun_prop) + filter_upwards with z + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + rcases le_total 0 z with hz | hz + · rw [abs_of_nonneg hz] + exact le_add_of_nonneg_right (Real.exp_pos _).le + · rw [abs_of_nonpos hz] + have he : c * -z = -c * z := by ring + rw [he] + exact le_add_of_nonneg_left (Real.exp_pos _).le + +lemma shift_norm_le {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (x s z : ℝ) : |f (x + s * z)| ≤ |f x| + (L : ℝ) * |s| * |z| := by + have h := hf.dist_le_mul (x + s * z) x + simp only [Real.dist_eq, add_sub_cancel_left, abs_mul] at h + have htri := abs_add_le (f (x + s * z) - f x) (f x) + rw [sub_add_cancel] at htri + nlinarith + +lemma integrable_shift {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (x s : ℝ) : Integrable (fun z => f (x + s * z)) (gaussianReal 0 1) := by + have hi : Integrable (fun z : ℝ => |z|) (gaussianReal 0 1) := + (MemLp.integrable (by norm_num) (memLp_id_gaussianReal (μ := 0) (v := 1) 1)).abs + apply ((integrable_const |f x|).add (hi.const_mul ((L : ℝ) * |s|))).mono' + (hf.continuous.comp (by fun_prop)).aestronglyMeasurable + exact ae_of_all _ fun z => by simpa [Real.norm_eq_abs] using shift_norm_le hf x s z + +lemma integrable_exp_shift {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a x s : ℝ) : Integrable (fun z => Real.exp (a * f (x + s * z))) + (gaussianReal 0 1) := by + apply ((integrable_exp_abs (|a| * (L : ℝ) * |s|)).const_mul + (Real.exp (|a| * |f x|))).mono' + (Real.continuous_exp.comp ((hf.continuous.comp (show Continuous (fun z : ℝ => x + s * z) by fun_prop)).const_mul a)).aestronglyMeasurable + filter_upwards with z + simp only [Function.comp_apply, Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have h := mul_le_mul_of_nonneg_left (shift_norm_le hf x s z) (abs_nonneg a) + have h' : a * f (x + s * z) ≤ |a| * |f (x + s * z)| := by + simpa only [abs_mul] using le_abs_self (a * f (x + s * z)) + nlinarith + + +lemma step_integrals {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a s x : ℝ) : + Integrable (fun z => f (x + s * z)) (gaussianReal 0 1) ∧ + Integrable (fun z => Real.exp (a * f (x + s * z))) (gaussianReal 0 1) ∧ + 0 < ∫ z, Real.exp (a * f (x + s * z)) ∂gaussianReal 0 1 := + ⟨integrable_shift hf x s, integrable_exp_shift hf a x s, + integral_exp_pos (integrable_exp_shift hf a x s)⟩ + +lemma logMean_le_add {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {a : ℝ} (ha : 0 ≤ a) {f g : Ω → ℝ} + (hf : Integrable f μ) (hg : Integrable g μ) + (hef : Integrable (fun z => Real.exp (a * f z)) μ) + (heg : Integrable (fun z => Real.exp (a * g z)) μ) + (c : ℝ) (hfg : ∀ z, f z ≤ g z + c) : logMean μ a f ≤ logMean μ a g + c := by + have hec : Integrable (fun z => Real.exp (a * (g z + c))) μ := by + simpa only [mul_add, Real.exp_add] using heg.mul_const (Real.exp (a * c)) + exact (logMean_mono ha hf (hg.add (integrable_const c)) hef hec hfg).trans_eq + (logMean_add_const hg heg c) + +lemma logMean_stable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {a : ℝ} (ha : 0 ≤ a) {f g : Ω → ℝ} + (hf : Integrable f μ) (hg : Integrable g μ) + (hef : Integrable (fun z => Real.exp (a * f z)) μ) + (heg : Integrable (fun z => Real.exp (a * g z)) μ) + (c : ℝ) (hfg : ∀ z, |f z - g z| ≤ c) : + |logMean μ a f - logMean μ a g| ≤ c := by + rw [abs_le] + constructor + · have h := logMean_le_add ha hg hf heg hef c (fun z => by + have hz := (abs_le.mp (hfg z)).1 + linarith) + linarith + · have h := logMean_le_add ha hf hg hef heg c (fun z => by + have hz := (abs_le.mp (hfg z)).2 + linarith) + linarith + + +lemma step_lipschitz {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {a : ℝ} (ha : 0 ≤ a) (s : ℝ) : LipschitzWith L (step a s f) := by + rw [lipschitzWith_iff_norm_sub_le] + intro x y + simp only [Real.norm_eq_abs, step] + apply logMean_stable ha (integrable_shift hf x s) (integrable_shift hf y s) + (integrable_exp_shift hf a x s) (integrable_exp_shift hf a y s) + intro z + have h := hf.dist_le_mul (x + s * z) (y + s * z) + simpa only [Real.dist_eq, add_sub_add_right_eq_sub] using h + +lemma hasDerivAt_terminal {β : ℝ} (hβ : 0 < β) (x : ℝ) : + HasDerivAt (terminal β) (Real.tanh (β * x)) x := by + have hc : HasDerivAt (fun y : ℝ => 2 * Real.cosh (β * y)) + (2 * (Real.sinh (β * x) * β)) x := by + simpa using ((Real.hasDerivAt_cosh (β * x)).comp x + ((hasDerivAt_id x).const_mul β)).const_mul (2 : ℝ) + have hh := (hc.log (mul_pos (by norm_num) (Real.cosh_pos _)).ne').div_const β + have he : (2 * (Real.sinh (β * x) * β) / (2 * Real.cosh (β * x))) / β = + Real.tanh (β * x) := by + rw [Real.tanh_eq_sinh_div_cosh] + field_simp + rw [he] at hh + exact hh + +lemma terminal_lipschitz {β : ℝ} (hβ : 0 < β) : LipschitzWith 1 (terminal β) := by + apply lipschitzWith_of_nnnorm_deriv_le (fun x => (hasDerivAt_terminal hβ x).differentiableAt) + intro x + rw [(hasDerivAt_terminal hβ x).deriv] + exact_mod_cast (Real.abs_tanh_lt_one (β * x)).le + +@[simp] lemma step_zero_width (a : ℝ) (f : ℝ → ℝ) (x : ℝ) : + step a 0 f x = f x := by + simp [step] + +@[simp] lemma terminal_zero (β : ℝ) : terminal β 0 = Real.log 2 / β := by + simp [terminal] + +lemma terminal_even (β x : ℝ) : terminal β (-x) = terminal β x := by + simp [terminal, mul_neg] + +lemma integral_exp_linear (a : ℝ) : + (∫ z : ℝ, Real.exp (a * z) ∂gaussianReal 0 1) = Real.exp (a ^ 2 / 2) := by + have h := mgf_gaussianReal (μ := 0) (v := 1) (X := fun z : ℝ => z) (p := gaussianReal 0 1) + (by simp) a + simpa [mgf] using h + +lemma exp_terminal {β : ℝ} (hβ : 0 < β) (x : ℝ) : + Real.exp (β * terminal β x) = 2 * Real.cosh (β * x) := by + unfold terminal + have he : β * (Real.log (2 * Real.cosh (β * x)) / β) = + Real.log (2 * Real.cosh (β * x)) := by field_simp + rw [he, Real.exp_log (mul_pos (by norm_num) (Real.cosh_pos _))] + +lemma exp_terminal_shift {β : ℝ} (hβ : 0 < β) (x s z : ℝ) : + Real.exp (β * terminal β (x + s * z)) = + Real.exp (β * x) * Real.exp ((β * s) * z) + + Real.exp (-(β * x)) * Real.exp ((-(β * s)) * z) := by + rw [exp_terminal hβ, Real.cosh_eq] + have h₁ : β * (x + s * z) = β * x + (β * s) * z := by ring + have h₂ : -(β * (x + s * z)) = -(β * x) + (-(β * s)) * z := by ring + rw [h₂, h₁, Real.exp_add, Real.exp_add] + ring + +lemma integral_exp_terminal {β : ℝ} (hβ : 0 < β) (x s : ℝ) : + (∫ z, Real.exp (β * terminal β (x + s * z)) ∂gaussianReal 0 1) = + (2 * Real.cosh (β * x)) * Real.exp ((β * s) ^ 2 / 2) := by + simp_rw [exp_terminal_shift hβ] + rw [integral_add ((integrable_exp_mul_gaussianReal (β * s)).const_mul _) + ((integrable_exp_mul_gaussianReal (-(β * s))).const_mul _)] + rw [integral_const_mul, integral_const_mul, integral_exp_linear, integral_exp_linear] + rw [neg_sq, Real.cosh_eq] + ring + + + +lemma step_terminal {β : ℝ} (hβ : 0 < β) (s x : ℝ) : + step β s (terminal β) x = terminal β x + β * s ^ 2 / 2 := by + unfold step logMean + rw [ite_eq_right hβ.ne', integral_exp_terminal hβ, + Real.log_mul (mul_pos (by norm_num) (Real.cosh_pos _)).ne' (Real.exp_pos _).ne', + Real.log_exp] + unfold terminal + field_simp + + + +abbrev Schedule := List (ℝ≥0 × ℝ≥0) + + +def recursion (β : ℝ) : Schedule → ℝ → ℝ + | [] => terminal β + | (a, d) :: ls => step a (Real.sqrt d) (recursion β ls) + + +def penalty (t : ℝ) : Schedule → ℝ + | [] => 0 + | (a, d) :: ls => a * ((t + d) ^ 2 - t ^ 2) / 4 + penalty (t + d) ls + +def width (ls : Schedule) : ℝ := (ls.map (fun l => (l.2 : ℝ))).sum + + +def Admissible (β : ℝ) (ls : Schedule) : Prop := + width ls = 1 ∧ ls.Pairwise (fun a b => a.1 ≤ b.1) ∧ ∀ l ∈ ls, (l.1 : ℝ) ≤ β + +def functional (β : ℝ) (ls : Schedule) : ℝ := recursion β ls 0 - penalty 0 ls + +lemma recursion_lipschitz {β : ℝ} (hβ : 0 < β) (ls : Schedule) : + LipschitzWith 1 (recursion β ls) := by + induction ls with + | nil => exact terminal_lipschitz hβ + | cons l ls ih => exact step_lipschitz ih l.1.coe_nonneg _ + +lemma recursion_integrals {β : ℝ} (hβ : 0 < β) (ls : Schedule) (a s x : ℝ) : + Integrable (fun z => recursion β ls (x + s * z)) (gaussianReal 0 1) ∧ + Integrable (fun z => Real.exp (a * recursion β ls (x + s * z))) (gaussianReal 0 1) ∧ + 0 < ∫ z, Real.exp (a * recursion β ls (x + s * z)) ∂gaussianReal 0 1 := + step_integrals (recursion_lipschitz hβ ls) a s x + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal Topology +namespace ParisiFinite + +lemma step_add_const {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a s c x : ℝ) : step a s (fun y => f y + c) x = step a s f x + c := + logMean_add_const (integrable_shift hf x s) (integrable_exp_shift hf a x s) c + +lemma step_mean (s : ℝ) (f : ℝ → ℝ) (x : ℝ) : + step 0 s f x = ∫ z, f (x + s * z) ∂gaussianReal 0 1 := by simp [step] + + +def replicaSymmetricSchedule (β : ℝ≥0) (q : ℝ≥0) : Schedule := + [(0, q), (β, 1 - q)] + +lemma replicaSymmetric_admissible (β q : ℝ≥0) (hq : q ≤ 1) : + Admissible β (replicaSymmetricSchedule β q) := by + simp [Admissible, replicaSymmetricSchedule, width, NNReal.coe_sub hq] + +lemma replicaSymmetric_recursion {β : ℝ≥0} (hβ : 0 < β) (q : ℝ≥0) (hq : q ≤ 1) (x : ℝ) : + recursion β (replicaSymmetricSchedule β q) x = + step 0 (Real.sqrt q) (terminal β) x + β * (1 - q) / 2 := by + have hβ' : (0 : ℝ) < β := hβ + have htail : (fun y => step (β : ℝ) (Real.sqrt (↑(1-q) : ℝ)) (terminal β) y) = + fun y => terminal β y + (β : ℝ) * (1 - q) / 2 := by + funext y + rw [step_terminal hβ', Real.sq_sqrt (NNReal.coe_nonneg _), NNReal.coe_sub hq] + norm_num + change step 0 (Real.sqrt q) (fun y => step (β : ℝ) + (Real.sqrt (↑(1 - q) : ℝ)) (terminal β) y) x = _ + rw [htail, step_add_const (terminal_lipschitz hβ')] + +lemma replicaSymmetric_penalty (β q : ℝ≥0) (hq : q ≤ 1) : + penalty 0 (replicaSymmetricSchedule β q) = β * (1 - (q : ℝ)^2) / 4 := by + simp [replicaSymmetricSchedule, penalty, NNReal.coe_sub hq] + + + +lemma replicaSymmetric_functional {β : ℝ≥0} (hβ : 0 < β) (q : ℝ≥0) (hq : q ≤ 1) : + functional β (replicaSymmetricSchedule β q) = + (∫ z : ℝ, terminal β (Real.sqrt q * z) ∂gaussianReal 0 1) + + β * (1 - (q : ℝ)) ^ 2 / 4 := by + rw [functional, replicaSymmetric_recursion hβ q hq, replicaSymmetric_penalty β q hq, + step_mean] + simp only [zero_add] + ring + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal +namespace ParisiInterpolation +open SKGaussian SKQAOA + +variable {κ : Type*} [Fintype κ] + +lemma memLp_coordinate (k : κ) : + MemLp (fun x : κ → ℝ => x k) 2 (gaussianLaw κ) := by + exact (memLp_id_gaussianReal (μ := 0) (v := 1) 2).comp_measurePreserving + (measurePreserving_eval (fun _ : κ => gaussianReal 0 1) k) + +lemma covariance_coordinate [DecidableEq κ] (i j : κ) : + covariance (fun x : κ → ℝ => x i) (fun x => x j) (gaussianLaw κ) = + if i = j then 1 else 0 := by + classical + by_cases hij : i = j + · subst j + rw [ite_eq_left rfl] + have hm := measurePreserving_eval (fun _ : κ => gaussianReal 0 1) i + have h := covariance_map (X := id) (Y := id) (Z := fun x : κ → ℝ => x i) + measurable_id.aestronglyMeasurable measurable_id.aestronglyMeasurable + hm.aemeasurable + rw [hm.map_eq] at h + calc + _ = covariance id id (gaussianReal 0 1) := h.symm + _ = 1 := by + rw [covariance_self measurable_id.aemeasurable, variance_id_gaussianReal] + rfl + · rw [ite_eq_right hij] + have hi : iIndepFun (fun i (x : κ → ℝ) => x i) (gaussianLaw κ) := + iIndepFun_pi (X := fun _ : κ => id) (fun _ => measurable_id.aemeasurable) + exact (hi.indepFun hij).covariance_eq_zero (memLp_coordinate i) (memLp_coordinate j) + +lemma covariance_field {ι : Type*} (A : ι → κ → ℝ) (i j : ι) : + covariance (fun x => field A x i) (fun x => field A x j) (gaussianLaw κ) = + ∑ k, A i k * A j k := by + classical + have hm (i : ι) (k : κ) : MemLp (fun x : κ → ℝ => A i k * x k) 2 (gaussianLaw κ) := + (memLp_coordinate k).const_mul (A i k) + have hf (i : ι) : (fun x => field A x i) = ∑ k, fun x => A i k * x k := by + ext x + simp [field] + have hsum (i : ι) : MemLp (∑ k, fun x : κ → ℝ => A i k * x k) 2 (gaussianLaw κ) := by + rw [← hf i] + exact memLp_finsetSum Finset.univ (fun k _ => hm i k) + rw [hf i, hf j, covariance_sum_left (hm i) (hsum j)] + apply Finset.sum_congr rfl + intro k _ + rw [covariance_sum_right (hm j) (hm i k)] + simp_rw [covariance_const_mul_left, covariance_const_mul_right, covariance_coordinate] + simp + + + +lemma hamiltonian_covariance {n : ℕ} (hn : 0 < n) (σ τ : Configuration n) : + covariance (fun J => hamiltonian n J σ) (fun J => hamiltonian n J τ) + (disorderLaw n) = (overlapSum σ τ ^ 2 - (n : ℝ)) / (2 * (n : ℝ)) := by + have h := covariance_field (skCoeff n) σ τ + simp_rw [field_skCoeff] at h + exact h.trans (coeff_covariance hn σ τ) + + +def overlap {n : ℕ} (σ τ : Configuration n) : ℝ := overlapSum σ τ / n + +lemma normalized_hamiltonian_covariance {n : ℕ} (hn : 0 < n) (σ τ : Configuration n) : + covariance (fun J => hamiltonian n J σ) (fun J => hamiltonian n J τ) + (disorderLaw n) / n = (overlap σ τ ^ 2 - 1 / (n : ℝ)) / 2 := by + rw [hamiltonian_covariance hn] + unfold overlap + have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp + +end ParisiInterpolation + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal + +namespace ParisiInterpolation +open SKGaussian +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +def rotate (A B : ι → κ → ℝ) (t : ℝ) (i : ι) (k : κ) : ℝ := + Real.cos t * A i k + Real.sin t * B i k + +def increment (A : ι → κ → ℝ) (i j : ι) : ℝ := + ∑ k, (A i k - A j k) ^ 2 + +def expected (A : ι → κ → ℝ) : ℝ := + ∫ x, logPartition (field A x) ∂gaussianLaw κ + + + +lemma hasDerivAt_expected_rotate (A B : ι → κ → ℝ) + (hAB : ∀ i j, ∑ k, A i k * B j k = 0) (t : ℝ) : + HasDerivAt (fun s => expected (rotate A B s)) + (∫ x, (1 / 2 : ℝ) * ∑ i, ∑ j, + weight (field (rotate A B t) x) i * weight (field (rotate A B t) x) j * + (Real.sin t * Real.cos t * (increment B i j - increment A i j)) + ∂gaussianLaw κ) t := by + let e : Fin (Fintype.card κ) ≃ κ := (Fintype.equivFin κ).symm + let A' : ι → Fin (Fintype.card κ) → ℝ := fun i k => A i (e k) + let B' : ι → Fin (Fintype.card κ) → ℝ := fun i k => B i (e k) + have hAB' : ∀ i j, ∑ k, A' i k * B' j k = 0 := by + intro i j + exact (e.sum_comp (fun k => A i k * B j k)).trans (hAB i j) + have h := hasDerivAt_expected_rotated A' B' t + rw [integral_weightedMean_eq_pairwise] at h + simp_rw [rotated_increment_covariance A' B' hAB'] at h + have hinc (C : ι → κ → ℝ) (i j : ι) : + (∑ k, (C i (e k) - C j (e k)) ^ 2) = increment C i j := + e.sum_comp (fun k => (C i k - C j k) ^ 2) + change HasDerivAt (fun s => ∫ x, + logPartition (linearField (fun i k => rotate A B s i (e k)) x) + ∂standardLaw (Fintype.card κ)) _ t at h + have he (s : ℝ) : (∫ x, + logPartition (linearField (fun i k => rotate A B s i (e k)) x) + ∂standardLaw (Fintype.card κ)) = expected (rotate A B s) := + integral_reindex_field (rotate A B s) logPartition + simp_rw [he] at h + convert h using 1 + symm + change (∫ x, (1 / 2 : ℝ) * ∑ i, ∑ j, + weight (linearField (fun i k => rotate A B t i (e k)) x) i * + weight (linearField (fun i k => rotate A B t i (e k)) x) j * + (Real.sin t * Real.cos t * + ((∑ k, (B i (e k) - B j (e k)) ^ 2) - + (∑ k, (A i (e k) - A j (e k)) ^ 2))) + ∂standardLaw (Fintype.card κ)) = _ + simp_rw [hinc] + exact integral_reindex_field (rotate A B t) (fun y => + (1 / 2 : ℝ) * ∑ i, ∑ j, weight y i * weight y j * + (Real.sin t * Real.cos t * (increment B i j - increment A i j))) + +omit [Fintype ι] [Nonempty ι] in +lemma continuous_field (A : ι → κ → ℝ) : Continuous (field A) := by + unfold field + fun_prop + +lemma integrable_weight_pair (A : ι → κ → ℝ) (i j : ι) : + Integrable (fun x => weight (field A x) i * weight (field A x) j) (gaussianLaw κ) := by + apply (integrable_const (1 : ℝ)).mono' + (((continuous_weight i).comp (continuous_field A)).mul + ((continuous_weight j).comp (continuous_field A))).aestronglyMeasurable + filter_upwards with x + simp only [Function.comp_apply, Pi.mul_apply, Real.norm_eq_abs] + rw [abs_of_nonneg (mul_nonneg (weight_pos _ _).le (weight_pos _ _).le)] + exact (mul_le_of_le_one_left (weight_pos _ _).le (weight_le_one _ _)).trans + (weight_le_one _ _) + + +def replicaAverage (A : ι → κ → ℝ) (K : ι → ι → ℝ) (x : κ → ℝ) : ℝ := + ∑ i, ∑ j, weight (field A x) i * weight (field A x) j * K i j + +lemma integrable_replicaAverage (A : ι → κ → ℝ) (K : ι → ι → ℝ) : + Integrable (replicaAverage A K) (gaussianLaw κ) := by + apply integrable_finsetSum + intro i _ + exact integrable_finsetSum _ fun j _ => (integrable_weight_pair A i j).mul_const (K i j) + +@[simp] lemma replicaAverage_const (A : ι → κ → ℝ) (x : κ → ℝ) (c : ℝ) : + replicaAverage A (fun _ _ => c) x = c := by + simp only [replicaAverage, mul_assoc, ← Finset.mul_sum, ← Finset.sum_mul, sum_weight, one_mul] + +omit [Nonempty ι] in +lemma replicaAverage_sub (A : ι → κ → ℝ) (K L : ι → ι → ℝ) (x : κ → ℝ) : + replicaAverage A (fun i j => K i j - L i j) x = + replicaAverage A K x - replicaAverage A L x := by + simp [replicaAverage, mul_sub, Finset.sum_sub_distrib] + +omit [Nonempty ι] in +lemma replicaAverage_const_mul (A : ι → κ → ℝ) (K : ι → ι → ℝ) (x : κ → ℝ) (c : ℝ) : + replicaAverage A (fun i j => c * K i j) x = c * replicaAverage A K x := by + simp only [replicaAverage, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + +lemma replicaAverage_nonneg (A : ι → κ → ℝ) {K : ι → ι → ℝ} + (hK : ∀ i j, 0 ≤ K i j) (x : κ → ℝ) : 0 ≤ replicaAverage A K x := by + exact Finset.sum_nonneg fun i _ => Finset.sum_nonneg fun j _ => + mul_nonneg (mul_nonneg (weight_pos _ _).le (weight_pos _ _).le) (hK i j) + +def replicaMean (A : ι → κ → ℝ) (K : ι → ι → ℝ) : ℝ := + ∫ x, replicaAverage A K x ∂gaussianLaw κ + +@[simp] lemma replicaMean_const (A : ι → κ → ℝ) (c : ℝ) : + replicaMean A (fun _ _ => c) = c := by + simp [replicaMean] + +lemma replicaMean_sub (A : ι → κ → ℝ) (K L : ι → ι → ℝ) : + replicaMean A (fun i j => K i j - L i j) = replicaMean A K - replicaMean A L := by + simp only [replicaMean, replicaAverage_sub] + exact integral_sub (integrable_replicaAverage A K) (integrable_replicaAverage A L) + +omit [Nonempty ι] in +lemma replicaMean_const_mul (A : ι → κ → ℝ) (K : ι → ι → ℝ) (c : ℝ) : + replicaMean A (fun i j => c * K i j) = c * replicaMean A K := by + simp only [replicaMean, replicaAverage_const_mul, integral_const_mul] + +lemma replicaMean_nonneg (A : ι → κ → ℝ) {K : ι → ι → ℝ} + (hK : ∀ i j, 0 ≤ K i j) : 0 ≤ replicaMean A K := + integral_nonneg (replicaAverage_nonneg A hK) + +lemma hasDerivAt_expected_rotate_mean (A B : ι → κ → ℝ) + (hAB : ∀ i j, ∑ k, A i k * B j k = 0) (t : ℝ) : + HasDerivAt (fun s => expected (rotate A B s)) + (Real.sin t * Real.cos t / 2 * + replicaMean (rotate A B t) (fun i j => increment B i j - increment A i j)) t := by + have h := hasDerivAt_expected_rotate A B hAB t + convert h using 1 + change _ = ∫ x, (1 / 2 : ℝ) * replicaAverage (rotate A B t) + (fun i j => (Real.sin t * Real.cos t) * (increment B i j - increment A i j)) x + ∂gaussianLaw κ + simp only [replicaAverage_const_mul, integral_const_mul, replicaMean] + ring + +end ParisiInterpolation + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal + +namespace ParisiInterpolation +open SKGaussian SKQAOA + + +def siteCoeff (n : ℕ) (β q : ℝ) (σ : Configuration n) (i : Fin n) : ℝ := + β * Real.sqrt q * spin σ i + + + +def siteLift (n : ℕ) (β q : ℝ) (σ : Configuration n) : Fin n ⊕ Edge n → ℝ := + Sum.elim (siteCoeff n β q σ) (fun _ => 0) + +def skLift (n : ℕ) (β : ℝ) (σ : Configuration n) : Fin n ⊕ Edge n → ℝ := + Sum.elim (fun _ => 0) (fun e => β * skCoeff n σ e) + +lemma lifts_orthogonal (n : ℕ) (β q : ℝ) (σ τ : Configuration n) : + (∑ k, siteLift n β q σ k * skLift n β τ k) = 0 := by + simp [siteLift, skLift, Fintype.sum_sum_type] + +lemma spin_increment {n : ℕ} (σ τ : Configuration n) : + (∑ i, (spin σ i - spin τ i) ^ 2) = 2 * (n : ℝ) - 2 * overlapSum σ τ := by + have he (i : Fin n) : (spin σ i - spin τ i)^2 = 2 - 2 * (spin σ i * spin τ i) := by + nlinarith [spin_sq σ i, spin_sq τ i] + simp_rw [he] + simp only [Finset.sum_sub_distrib, ← Finset.mul_sum] + simp [overlapSum, mul_comm] + +lemma siteCoeff_increment {n : ℕ} {q : ℝ} (hq : 0 ≤ q) (β : ℝ) (σ τ : Configuration n) : + increment (siteCoeff n β q) σ τ = β ^ 2 * q * (2 * (n : ℝ) - 2 * overlapSum σ τ) := by + unfold increment siteCoeff + rw [scaled_increment, spin_increment] + rw [mul_pow, Real.sq_sqrt hq] + +lemma siteLift_increment {n : ℕ} {q : ℝ} (hq : 0 ≤ q) (β : ℝ) (σ τ : Configuration n) : + increment (siteLift n β q) σ τ = β ^ 2 * q * (2 * (n : ℝ) - 2 * overlapSum σ τ) := by + simpa only [increment, siteLift, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, + sub_self, zero_pow (by norm_num : 2 ≠ 0), Finset.sum_const_zero, add_zero] using + siteCoeff_increment hq β σ τ + +lemma skLift_increment {n : ℕ} (hn : 0 < n) (β : ℝ) (σ τ : Configuration n) : + increment (skLift n β) σ τ = β ^ 2 * ((n : ℝ) - overlapSum σ τ ^ 2 / n) := by + simp only [increment, skLift, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr, + sub_self, zero_pow (by norm_num : 2 ≠ 0), Finset.sum_const_zero, zero_add] + rw [scaled_increment, coeff_increment hn] + +lemma interpolation_increment {n : ℕ} (hn : 0 < n) {q : ℝ} (hq : 0 ≤ q) + (β : ℝ) (σ τ : Configuration n) : + increment (skLift n β) σ τ - increment (siteLift n β q) σ τ = + β ^ 2 * n * ((1 - q) ^ 2 - (overlap σ τ - q) ^ 2) := by + rw [skLift_increment hn, siteLift_increment hq] + unfold overlap + have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp + ring + + + +def interpolatedPressure (n : ℕ) (β q t : ℝ) : ℝ := + expected (rotate (siteLift n β q) (skLift n β) t) + + + +def remainder (n : ℕ) (β q t : ℝ) : ℝ := + replicaMean (rotate (siteLift n β q) (skLift n β) t) + (fun σ τ => (overlap σ τ - q) ^ 2) + +lemma remainder_nonneg (n : ℕ) (β q t : ℝ) : 0 ≤ remainder n β q t := + replicaMean_nonneg _ (fun _ _ => sq_nonneg _) + +lemma hasDerivAt_interpolatedPressure {n : ℕ} (hn : 0 < n) (β : ℝ) {q : ℝ} + (hq : 0 ≤ q) (t : ℝ) : + HasDerivAt (interpolatedPressure n β q) + (β ^ 2 * n * (Real.sin t * Real.cos t) / 2 * + ((1 - q) ^ 2 - remainder n β q t)) t := by + have h := hasDerivAt_expected_rotate_mean (siteLift n β q) (skLift n β) + (lifts_orthogonal n β q) t + simp_rw [interpolation_increment hn hq] at h + rw [replicaMean_const_mul, replicaMean_sub, replicaMean_const] at h + change HasDerivAt (fun s => expected (rotate (siteLift n β q) (skLift n β) s)) _ t + convert h using 1 + simp only [remainder] + ring + +end ParisiInterpolation + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/LogSeriesTermBound.lean b/lean/OAI/Probability/ParisiFinite/LogSeriesTermBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..b114238a058651d1cfed3fb077eec7f32ac2ab2f --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/LogSeriesTermBound.lean @@ -0,0 +1,680 @@ +import Mathlib +import OAI.Probability.ParisiFinite.TreeNodeDepth + +namespace OAI + +/-! Log Series Term Bound. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma log_series_term_bound {x z : ℝ} (hx : 0≤x ∧ x≤1) (hz : |z|<1) (n : ℕ) : + ‖-(z*x)^(n+1)/(n+1:ℕ)‖≤|z|^n := by + have hn : (1:ℝ)≤(n+1:ℕ) := by exact_mod_cast Nat.succ_pos n + rw [Real.norm_eq_abs,abs_div,abs_neg,abs_pow,abs_mul,abs_of_nonneg hx.1, + abs_of_nonneg (by positivity : (0:ℝ)≤(n+1:ℕ))] + calc + (|z| * x)^(n+1)/(n+1:ℕ) ≤ |z|^(n+1)/(n+1:ℕ) := + div_le_div_of_nonneg_right (pow_le_pow_left₀ (mul_nonneg (abs_nonneg _) hx.1) + (mul_le_of_le_one_right (abs_nonneg _) hx.2) _) (by positivity) + _ ≤ |z|^(n+1) := div_le_self (pow_nonneg (abs_nonneg _) _) hn + _ ≤ |z|^n := by rw [pow_succ]; exact mul_le_of_le_one_right (pow_nonneg (abs_nonneg _) _) hz.le + +lemma integral_log_unit_series {Ω : Type*} [MeasurableSpace Ω] (ν : Measure Ω) [IsProbabilityMeasure ν] + {Y : Ω → ℝ} (hY : Measurable Y) (hb : ∀ sample,0≤Y sample ∧ Y sample≤1) {z : ℝ} (hz : |z|<1) : + (∫ sample,Real.log (1-z*Y sample) ∂ν)= + ∑' n,-(∫ sample,Y sample^(n+1) ∂ν)*z^(n+1)/(n+1:ℕ) := by + let F (n : ℕ) (sample : Ω) : ℝ := -(z*Y sample)^(n+1)/(n+1:ℕ) + have hFi (n : ℕ) : Integrable (F n) ν := + integrable_of_uniform_abs (by fun_prop) (fun sample => by + simpa only [Real.norm_eq_abs] using log_series_term_bound (hb sample) hz n) + have hs : Summable (fun n => ∫ sample,‖F n sample‖ ∂ν) := by + apply Summable.of_nonneg_of_le (fun n => integral_nonneg (fun sample => norm_nonneg _)) + (fun n => ?_) (summable_geometric_of_lt_one (abs_nonneg z) hz) + simpa using integral_mono (hFi n).norm (integrable_const (|z|^n)) + (fun sample => log_series_term_bound (hb sample) hz n) + have hseries : ∀ sample,HasSum (fun n => F n sample) (Real.log (1-z*Y sample)) := by + intro sample + have hzx : |z*Y sample|<1 := ((by + rw [abs_mul,abs_of_nonneg (hb sample).1] + exact mul_le_of_le_one_right (abs_nonneg z) (hb sample).2) : |z*Y sample|≤|z|).trans_lt hz + simpa only [F,Nat.cast_add,Nat.cast_one,neg_div,neg_neg] using (Real.hasSum_pow_div_log_of_abs_lt_one hzx).neg + have hi := hasSum_integral_of_summable_integral_norm hFi hs + simp_rw [(hseries _).tsum_eq] at hi + rw [← hi.tsum_eq] + apply tsum_congr + intro n + simp only [F,mul_pow,neg_div,integral_neg,integral_div,integral_const_mul] + ring + + + +theorem empirical_log_limit_of_distinct_moments + {Ω : ℕ → Type*} [∀ r,MeasurableSpace (Ω r)] (ν : (r : ℕ) → Measure (Ω r)) + [∀ r,IsProbabilityMeasure (ν r)] (X : (r : ℕ) → Ω r → Fin (r+1) → ℝ) + (hX : ∀ r i,Measurable (fun sample => X r sample i)) + (hb : ∀ r sample i,0≤X r sample i ∧ X r sample i≤1) + (M : ℕ → ℝ) (hM : ∀ k,0≤M k ∧ M k≤1) + (he : ∀ r k (e : Fin k → Fin (r+1)),Function.Injective e → + (∫ sample,∏ i,X r sample (e i) ∂ν r)=M k) + {z : ℝ} (hz : |z|<1) : + Tendsto (fun r => ∫ sample,Real.log (1-z*((∑ i,X r sample i)/(r+1:ℕ))) ∂ν r) atTop + (𝓝 (∑' n,-M (n+1)*z^(n+1)/(n+1:ℕ))) := by + let Y (r : ℕ) (sample : Ω r) : ℝ := (∑ i,X r sample i)/(r+1:ℕ) + have hYm (r : ℕ) : Measurable (Y r) := (Finset.measurable_sum _ (fun i _ => hX r i)).div_const _ + have hYb (r : ℕ) (sample : Ω r) : 0≤Y r sample ∧ Y r sample≤1 := by + dsimp only [Y] + constructor + · exact div_nonneg (Finset.sum_nonneg (fun i _ => (hb r sample i).1)) (by positivity) + · apply (div_le_one (by positivity)).mpr + simpa using Finset.sum_le_sum (s:=Finset.univ) (fun i _ => (hb r sample i).2) + have hprod (r k : ℕ) (e : Fin k → Fin (r+1)) (sample : Ω r) : + 0≤∏ i,X r sample (e i) ∧ (∏ i,X r sample (e i))≤1 := + ⟨Finset.prod_nonneg (fun i _ => (hb r sample (e i)).1), + Finset.prod_le_one₀ (fun i _ => (hb r sample (e i)).1) (fun i _ => (hb r sample (e i)).2)⟩ + have hprodi (r k : ℕ) (e : Fin k → Fin (r+1)) : + Integrable (fun sample => ∏ i,X r sample (e i)) (ν r) := by + apply integrable_of_uniform_abs (Finset.measurable_prod _ (fun i _ => hX r (e i))) + intro sample + rw [abs_of_nonneg (hprod r k e sample).1] + exact (hprod r k e sample).2 + have hmom (k : ℕ) : Tendsto (fun r => ∫ sample,Y r sample^k ∂ν r) atTop (𝓝 (M k)) := by + have hh (r : ℕ) : (∫ sample,Y r sample^k ∂ν r)= + (∑ e : Fin k → Fin (r+1),∫ sample,∏ i,X r sample (e i) ∂ν r)/(r+1:ℕ)^k := by + simp only [Y,div_pow,Fintype.sum_pow,integral_div] + rw [integral_finsetSum Finset.univ (fun e _ => hprodi r k e)] + simp_rw [hh] + apply replica_average_moment_tendsto k _ (hM k) + · intro r e + refine ⟨integral_nonneg (fun sample => (hprod r k e sample).1),?_⟩ + simpa using integral_mono (hprodi r k e) (integrable_const (1:ℝ)) (fun sample => (hprod r k e sample).2) + · exact fun r e h => he r k e h + have hlog (r : ℕ) := integral_log_unit_series (ν r) (hYm r) (hYb r) hz + change Tendsto (fun r => ∫ sample,Real.log (1-z*Y r sample) ∂ν r) _ _ + simp_rw [hlog] + apply tendsto_tsum_of_dominated_convergence (summable_geometric_of_lt_one (abs_nonneg z) hz) + · intro n + exact (((hmom (n+1)).neg).mul_const (z^(n+1))).div_const _ + · apply Eventually.of_forall + intro r n + have hbb : 0≤(∫ sample,Y r sample^(n+1) ∂ν r) ∧ (∫ sample,Y r sample^(n+1) ∂ν r)≤1 := by + refine ⟨integral_nonneg (fun sample => pow_nonneg (hYb r sample).1 _),?_⟩ + have hi : Integrable (fun sample => Y r sample^(n+1)) (ν r) := by + apply integrable_of_uniform_abs ((hYm r).pow_const _) + intro sample + rw [abs_of_nonneg (pow_nonneg (hYb r sample).1 _)] + exact pow_le_one₀ (hYb r sample).1 (hYb r sample).2 + simpa using integral_mono hi (integrable_const (1:ℝ)) + (fun sample => pow_le_one₀ (hYb r sample).1 (hYb r sample).2) + have hh := normalized_moment_bound hbb z (n+1) + have hzpow : |z|^(n+1)≤|z|^n := by + rw [pow_succ]; exact mul_le_of_le_one_right (pow_nonneg (abs_nonneg _) _) hz.le + convert hh.trans hzpow using 1 + congr 1 + push_cast + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +def treePathVector {d r : ℕ} (T : PartitionTree d r) (z : TreeNode T → ℝ) + (i : Fin r) (k : Fin d) : ℝ := z (treeNodePath T i k) + +lemma treePathVector_continuous {d r : ℕ} (T : PartitionTree d r) : + Continuous (treePathVector T) := by unfold treePathVector; fun_prop + +def treePathLaw {d r : ℕ} (T : PartitionTree d r) : Measure (Fin r → Fin d → ℝ) := + (gaussianLaw (TreeNode T)).map (treePathVector T) + +instance treePathLaw_probability {d r : ℕ} (T : PartitionTree d r) : + IsProbabilityMeasure (treePathLaw T) := by + unfold treePathLaw + infer_instance + +lemma integral_treePathLaw {d r : ℕ} (T : PartitionTree d r) + (f : (Fin r → Fin d → ℝ) → ℝ) (hf : Measurable f) : + (∫ s,f s ∂treePathLaw T)=∫ z,f (treePathVector T z) ∂gaussianLaw (TreeNode T) := + integral_map (treePathVector_continuous T).measurable.aemeasurable hf.aestronglyMeasurable + +def pathCoeff {d r : ℕ} (T : PartitionTree d r) (i : Fin r×Fin d) (n : TreeNode T) : ℝ := + if treeNodePath T i.1 i.2=n then 1 else 0 + +lemma field_pathCoeff {d r : ℕ} (T : PartitionTree d r) (z : TreeNode T → ℝ) (i : Fin r×Fin d) : + field (pathCoeff T) z i=treePathVector T z i.1 i.2 := by + classical + simp [field,pathCoeff,treePathVector] + +lemma kernel_pathCoeff {d r : ℕ} (T : PartitionTree d r) (i j : Fin r×Fin d) : + kernel (pathCoeff T) i j=if treeNodePath T i.1 i.2=treeNodePath T j.1 j.2 then 1 else 0 := by + classical + unfold kernel pathCoeff + rw [Finset.sum_eq_single (treeNodePath T i.1 i.2)] + · simp [eq_comm] + · intro n _ hn + simp [Ne.symm hn] + · simp + +lemma treePath_marginal_integral {d r k : ℕ} (T : PartitionTree d r) (U : PartitionTree d k) + (e : Fin k → Fin r) + (he : ∀ (l : Fin d) (i j : Fin k),treeCodes T l.succ (e i)=treeCodes T l.succ (e j) ↔ + treeCodes U l.succ i=treeCodes U l.succ j) + (f : (Fin k → Fin d → ℝ) → ℝ) (hf : Measurable f) : + (∫ s,f (fun i => s (e i)) ∂treePathLaw T)=(∫ s,f s ∂treePathLaw U) := by + have hp (i j : Fin k×Fin d) : + treeNodePath T (e i.1) i.2=treeNodePath T (e j.1) j.2 ↔ + treeNodePath U i.1 i.2=treeNodePath U j.1 j.2 := by + constructor + · intro h + have hkl := treeNodePath_eq_levels T _ _ _ _ h + obtain ⟨i,l⟩ := i + obtain ⟨j,k⟩ := j + dsimp only at hkl h ⊢ + subst k + rw [treeNodePath_eq_iff] at h ⊢ + exact (he l i j).mp h + · intro h + have hkl := treeNodePath_eq_levels U _ _ _ _ h + obtain ⟨i,l⟩ := i + obtain ⟨j,k⟩ := j + dsimp only at hkl h ⊢ + subst k + rw [treeNodePath_eq_iff] at h ⊢ + exact (he l i j).mpr h + have hk : kernel (fun i : Fin k×Fin d => pathCoeff T (e i.1,i.2))=kernel (pathCoeff U) := by + funext i j + change kernel (pathCoeff T) (e i.1,i.2) (e j.1,j.2)=_ + simp only [kernel_pathCoeff,hp] + rw [integral_treePathLaw T (fun s => f (fun i => s (e i))) (hf.comp (by fun_prop)),integral_treePathLaw U f hf] + have hh := integral_field_eq_of_kernel (fun i : Fin k×Fin d => pathCoeff T (e i.1,i.2)) + (pathCoeff U) hk (fun x => f (fun i l => x (i,l))) (hf.comp (by fun_prop)) + convert hh using 1 + · congr 1; funext z; congr 1; funext i l + exact (field_pathCoeff T z (e i,l)).symm + · congr 1; funext z; congr 1; funext i l + exact (field_pathCoeff U z (i,l)).symm + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +def hierarchySampleLaw {d : ℕ} (μ : ProbabilityMeasure OverlapArray) (q : Fin (d+1) → ℝ) + (r : ℕ) : Measure (Fin r → Fin d → ℝ) := + ∑ T : PartitionTree d r,(μ:Measure OverlapArray) (hierarchyEvent (treeCodes T) q) • treePathLaw T + +def hierarchyBlockSample {d r : ℕ} (q : Fin (d+1) → ℝ) + (f : (Fin r → Fin d → ℝ) → ℝ) (A : OverlapBlock r) : ℝ := + ∑ T : PartitionTree d r,(hierarchyBlock (treeCodes T) q).indicator + (fun _ => ∫ s,f s ∂treePathLaw T) A + +lemma hierarchyBlockSample_measurable {d r : ℕ} (q : Fin (d+1) → ℝ) + (f : (Fin r → Fin d → ℝ) → ℝ) : Measurable (hierarchyBlockSample q f) := by + apply Finset.measurable_sum + intro T _ + exact measurable_const.indicator (hierarchyBlock_measurable _ _) + +lemma hierarchyBlockSample_on_event {d r : ℕ} (q : Fin (d+1) → ℝ) + (f : (Fin r → Fin d → ℝ) → ℝ) (T : PartitionTree d r) + {A : OverlapBlock r} (hA : A∈hierarchyBlock (treeCodes T) q) : + hierarchyBlockSample q f A=∫ s,f s ∂treePathLaw T := by + unfold hierarchyBlockSample + rw [Finset.sum_eq_single T] + · exact Set.indicator_of_mem hA _ + · intro U _ hUT + apply Set.indicator_of_notMem + intro hU + apply hUT + exact tree_eq_of_same_relations U T (fun k i j => (hU k i j).symm.trans (hA k i j)) + · simp + +lemma hierarchySampleLaw_integral {d r : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+1) → ℝ) {f : (Fin r → Fin d → ℝ) → ℝ} {C : ℝ} + (hf : Measurable f) (hb : ∀ s,|f s|≤C) : + (∫ s,f s ∂hierarchySampleLaw μ q r)= + ∑ T : PartitionTree d r,(μ:Measure OverlapArray).real (hierarchyEvent (treeCodes T) q)* + ∫ s,f s ∂treePathLaw T := by + unfold hierarchySampleLaw + rw [integral_finsetSum_measure] + · simp only [integral_smul_measure,smul_eq_mul,Measure.real] + · intro T _ + exact (integrable_of_uniform_abs hf hb).smul_measure (measure_ne_top _ _) + +lemma hierarchySampleLaw_integral_block {d r : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+1) → ℝ) {f : (Fin r → Fin d → ℝ) → ℝ} {C : ℝ} + (hf : Measurable f) (hb : ∀ s,|f s|≤C) : + (∫ s,f s ∂hierarchySampleLaw μ q r)= + ∫ R,hierarchyBlockSample q f (blockOfArray r R) ∂(μ:Measure OverlapArray) := by + rw [hierarchySampleLaw_integral μ q hf hb] + have he (R : OverlapArray) : hierarchyBlockSample q f (blockOfArray r R)= + ∑ T : PartitionTree d r,(hierarchyEvent (treeCodes T) q).indicator + (fun _ => ∫ s,f s ∂treePathLaw T) R := rfl + simp_rw [he] + rw [integral_finsetSum] + · apply Finset.sum_congr rfl + intro T _ + rw [integral_indicator_const _ (hierarchyEvent_measurable _ _)] + rfl + · intro T _ + exact (integrable_const _).indicator (hierarchyEvent_measurable _ _) + +lemma hierarchySampleLaw_probability {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) {r : ℕ} (hr : 0 tree_hierarchy_disjoint htu q + · exact fun T => hierarchyEvent_measurable _ _ + + + +theorem hierarchySampleLaw_marginal_integral {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) {r k : ℕ} (hr : 0 s (e i)) ∂hierarchySampleLaw μ q r)= + ∫ s,f s ∂hierarchySampleLaw μ q k := by + let B : Set (OverlapBlock k) := ⋃ U : PartitionTree (d+1) k,hierarchyBlock (treeCodes U) q + have hBm : MeasurableSet B := MeasurableSet.iUnion fun U => hierarchyBlock_measurable _ _ + have he' : Function.Injective (fun i => (e i:ℕ)) := Fin.val_injective.comp he + have hcov : (μ:Measure OverlapArray) ((selectedBlock (fun i => (e i:ℕ))) ⁻¹' B)=1 := by + rw [exchangeable_event hex _ he' hBm] + dsimp only [B] + rw [Set.preimage_iUnion] + exact hierarchy_partition_cover_all hG hgg hu q hq h0 h1 hk + have hcovr := hierarchy_partition_cover_all hG hgg hu q hq h0 h1 hr + rw [hierarchySampleLaw_integral_block μ q (f:=fun s => f (fun i => s (e i))) + (hf.comp (by fun_prop)) (fun s => hb _),hierarchySampleLaw_integral_block μ q hf hb] + have hpoint : ∀ᵐ R ∂(μ:Measure OverlapArray), + hierarchyBlockSample q (fun s => f (fun i => s (e i))) (blockOfArray r R)= + hierarchyBlockSample q f (selectedBlock (fun i => (e i:ℕ)) R) := by + filter_upwards [ae_full_probability μ (MeasurableSet.iUnion fun T => hierarchyEvent_measurable (treeCodes T) q) hcovr, + ae_full_probability μ (hBm.preimage (continuous_selectedBlock _).measurable) hcov] with R hR hS + obtain ⟨T,hT⟩ := Set.mem_iUnion.mp hR + obtain ⟨U,hU⟩ := Set.mem_iUnion.mp hS + rw [hierarchyBlockSample_on_event q _ T hT,hierarchyBlockSample_on_event q _ U hU] + apply treePath_marginal_integral T U e + · intro l i j + exact (hT l.succ (e i) (e j)).symm.trans (hU l.succ i j) + · exact hf + rw [integral_congr_ae hpoint] + have hF := hierarchyBlockSample_measurable q f + rw [← integral_map (continuous_selectedBlock _).measurable.aemeasurable hF.aestronglyMeasurable, + hex k _ he',blockLaw,integral_map (continuous_blockOfArray k).measurable.aemeasurable hF.aestronglyMeasurable] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma hierarchySampleLaw_product {d r : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+1) → ℝ) {x : (Fin d → ℝ) → ℝ} (hx : Continuous x) + (hb : ∀ s,0≤x s ∧ x s≤1) : + (∫ s,∏ i : Fin r,x (s i) ∂hierarchySampleLaw μ q r)=gaussianHierarchyMoment μ q x r := by + rw [hierarchySampleLaw_integral μ q (by fun_prop) (C:=1)] + · apply Finset.sum_congr rfl + intro T _ + congr 1 + rw [integral_treePathLaw T _ (by fun_prop)] + rfl + · intro s + rw [abs_of_nonneg (Finset.prod_nonneg (fun i _ => (hb (s i)).1))] + exact Finset.prod_le_one₀ (fun i _ => (hb (s i)).1) (fun i _ => (hb (s i)).2) + + + +theorem hierarchy_empirical_log_tendsto {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ha : ∀ k : Fin (d+1),overlapDiscount μ (q k.succ)≠0) + {x : (Fin (d+1) → ℝ) → ℝ} (hx : Continuous x) (hb : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : + Tendsto (fun r => ∫ s,Real.log (1-z*((∑ i : Fin (r+1),x (s i))/(r+1:ℕ))) + ∂hierarchySampleLaw μ q (r+1)) atTop + (𝓝 (gaussianHierarchyRisk (fun k => overlapDiscount μ (q k.succ)) + (fun s => Real.log (1-z*x s)))) := by + let ν (r : ℕ) := hierarchySampleLaw μ q (r+1) + let (r : ℕ) : IsProbabilityMeasure (ν r) := + hierarchySampleLaw_probability hG hgg hu q hq h0 h1 (Nat.succ_pos r) + let M (k : ℕ) := if k=0 then 1 else gaussianHierarchyMoment μ q x k + have hM (k : ℕ) : 0≤M k ∧ M k≤1 := by + by_cases hk : k=0 + · simp [M,hk] + · simpa [M,hk] using gaussianHierarchyMoment_mem_unit μ q hx hb k + have he (r k : ℕ) (e : Fin k → Fin (r+1)) (he : Function.Injective e) : + (∫ s,∏ i,x (s (e i)) ∂ν r)=M k := by + by_cases hk : k=0 + · subst k + simp [M] + have hk' := Nat.pos_of_ne_zero hk + rw [hierarchySampleLaw_marginal_integral hG hgg hu hex q hq h0 h1 (Nat.succ_pos r) hk' + e he (f:=fun s => ∏ i,x (s i)) (by fun_prop) (C:=1)] + · simpa [M,hk] using hierarchySampleLaw_product μ q hx hb + · intro s + rw [abs_of_nonneg (Finset.prod_nonneg (fun i _ => (hb (s i)).1))] + exact Finset.prod_le_one₀ (fun i _ => (hb (s i)).1) (fun i _ => (hb (s i)).2) + have ht := empirical_log_limit_of_distinct_moments ν (fun _ s i => x (s i)) + (fun _ i => hx.measurable.comp (measurable_pi_apply i)) (fun _ s i => hb (s i)) M hM he hz + rw [GG_gaussian_hierarchy_log_identity hG hgg hu q hq h0 h1 ha hx hb hz] + have hs : Summable (fun n => -gaussianHierarchyMoment μ q x n/(n:ℝ)*z^n) := by + apply Summable.of_norm_bounded_eventually (summable_geometric_of_lt_one (abs_nonneg z) hz) + exact Eventually.of_forall (fun n => normalized_moment_bound (gaussianHierarchyMoment_mem_unit μ q hx hb n) z n) + rw [hs.tsum_eq_zero_add] + simp only [Nat.cast_zero,div_zero,zero_mul,zero_add] + convert ht using 2 + apply tsum_congr + intro n + simp only [M,Nat.add_one_ne_zero,↓reduceIte] + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma unit_average {r : ℕ} (hr : 0 (hx i).1)) (by positivity),?_⟩ + apply (div_le_one (by positivity)).mpr + simpa using Finset.sum_le_sum (s:=Finset.univ) (fun i _ => (hx i).2) + +lemma affine_average {r : ℕ} (hr : 0 x sample i)) (hb : ∀ sample i,0≤x sample i ∧ x sample i≤1) + {b z : ℝ} (hbp : 0 Real.log (1-z*((∑ i,x sample i)/(r:ℝ)))) := by + apply Real.measurable_log.comp + exact measurable_const.sub (((Finset.measurable_sum _ (fun i _ => hx i)).div_const _).const_mul _) + have hi : Integrable (fun sample => Real.log (1-z*((∑ i,x sample i)/(r:ℝ)))) ν := by + apply integrable_of_uniform_abs hf (C:=|Real.log (1-|z|)|+|Real.log (1+|z|)|) + intro sample + exact affine_log_bounded (x:=fun _ : Fin 0 → ℝ => (∑ i,x sample i)/(r:ℝ)) (fun _ => hav sample) hz (fun k => k.elim0) + simp_rw [affine_average hr,Real.log_mul hbp.ne' (affine_mark_pos (hav _) hz).ne'] + rw [integral_add (integrable_const _) hi] + simp [add_comm] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma gaussianHierarchyRisk_add_const {d : ℕ} {a : Fin d → ℝ} (ha : ∀ k,0≤a k) + {f : (Fin d → ℝ) → ℝ} {C : ℝ} (hf : Continuous f) (hb : ∀ s,|f s|≤C) (c : ℝ) : + gaussianHierarchyRisk a (fun s => f s+c)=gaussianHierarchyRisk a f+c := by + induction d with + | zero => rfl + | succ d ih => + simp only [gaussianHierarchyRisk] + have he (z : ℝ) := ih (fun k => ha k.succ) + (hf.comp (continuous_finCons continuous_const continuous_id)) (fun s => hb (Fin.cons z s)) + simp only [Function.comp_def,id_eq] at he + simp_rw [he] + have hh := gaussianHierarchyRisk_continuous_bound (fun k => ha k.succ) + (f:=fun z s => f (Fin.cons z s)) + (hf.comp (continuous_finCons continuous_fst continuous_snd)) (fun z s => hb (Fin.cons z s)) + exact logMean_add_const (integrable_of_uniform_abs hh.1.measurable hh.2) + (integrable_exp_of_uniform_abs (a 0) hh.1.measurable hh.2) c + + + +theorem hierarchy_empirical_positive_tendsto {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ha : ∀ k : Fin (d+1),overlapDiscount μ (q k.succ)≠0) + {y : (Fin (d+1) → ℝ) → ℝ} (hy : Continuous y) {l b : ℝ} (hl : 0 ∫ s,Real.log ((∑ i : Fin (r+1),y (s i))/(r+1:ℕ)) + ∂hierarchySampleLaw μ q (r+1)) atTop + (𝓝 (gaussianHierarchyRisk (fun k => overlapDiscount μ (q k.succ)) (fun s => Real.log (y s)))) := by + let x (s : Fin (d+1) → ℝ) := (b-y s)/(b-l) + let z := (b-l)/b + have hbp : 0 Real.log (1-z*x s)) := + (continuous_const.sub (hx.const_mul z)).log (fun s => (affine_mark_pos (hxb s) hz).ne') + have hrisk := gaussianHierarchyRisk_add_const (a:=fun k : Fin (d+1) => overlapDiscount μ (q k.succ)) (fun k => (measureReal_nonneg : 0≤overlapDiscount μ (q k.succ))) + hlogc (affine_log_bounded hxb hz) (Real.log b) + have hleft (r : ℕ) : (∫ s,Real.log ((∑ i : Fin (r+1),y (s i))/(r+1:ℕ)) ∂hierarchySampleLaw μ q (r+1))= + (∫ s,Real.log (1-z*((∑ i : Fin (r+1),x (s i))/(r+1:ℕ))) ∂hierarchySampleLaw μ q (r+1))+Real.log b := by + let := hierarchySampleLaw_probability hG hgg hu q hq h0 h1 (Nat.succ_pos r) + have hrep : (fun s : Fin (r+1) → Fin (d+1) → ℝ => Real.log ((∑ i,y (s i))/(r+1:ℕ)))= + (fun s => Real.log ((∑ i,b*(1-z*x (s i)))/(r+1:ℕ))) := by + funext s + congr 2 + exact Finset.sum_congr rfl (fun i _ => he (s i)) + rw [hrep] + exact integral_affine_average_log _ (Nat.succ_pos r) + (fun i => hx.measurable.comp (measurable_pi_apply i)) (fun s i => hxb (s i)) hbp hz + simp_rw [hleft,hlog] + rw [hrisk] + exact ht.add_const _ + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma bounded_exp_mass_derivative {Ω : Type*} [MeasurableSpace Ω] {ν : Measure Ω} + [IsProbabilityMeasure ν] {f : Ω → ℝ} {C : ℝ} (hf : Measurable f) (hb : ∀ x,|f x|≤C) : + HasDerivAt (fun a => ∫ x,Real.exp (a*f x) ∂ν) (∫ x,f x ∂ν) 0 := by + have hC : 0≤C := by + have : Nonempty Ω := nonempty_of_isProbabilityMeasure ν + obtain ⟨x⟩ := this + exact (abs_nonneg _).trans (hb x) + have h := (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s:=Set.Ioo (-1:ℝ) 1) (x₀:=0) (μ:=ν) (F:=fun a x => Real.exp (a*f x)) + (F':=fun a x => Real.exp (a*f x)*f x) (bound:=fun _ => Real.exp C*C) + (Ioo_mem_nhds (by norm_num) (by norm_num)) ?_ + (by simp) + ?_ ?_ (integrable_const _) ?_).2 + · simpa only [zero_mul,Real.exp_zero,one_mul] using h + · exact Eventually.of_forall (fun a => (integrable_exp_of_uniform_abs a hf hb).aestronglyMeasurable) + · exact ((hf.const_mul 0).exp.mul hf).aestronglyMeasurable + · filter_upwards with x a ha + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _)] + have hab : |a|≤1 := (abs_lt.mpr ha).le + have haf : a*f x≤C := (le_abs_self _).trans (by + rw [abs_mul] + exact (mul_le_mul_of_nonneg_right hab (abs_nonneg _)).trans (by simpa using hb x)) + exact mul_le_mul (Real.exp_le_exp.mpr haf) (hb x) (abs_nonneg _) (Real.exp_pos _).le + · filter_upwards with x a _ + simpa only [one_mul,id_eq] using ((hasDerivAt_id a).mul_const (f x)).exp + +lemma logMean_coefficient_continuousAt_zero {Ω : Type*} [MeasurableSpace Ω] {ν : Measure Ω} + [IsProbabilityMeasure ν] {f : Ω → ℝ} {C : ℝ} (hf : Measurable f) (hb : ∀ x,|f x|≤C) : + ContinuousAt (fun a => logMean ν a f) 0 := by + have hmass := bounded_exp_mass_derivative (ν:=ν) hf hb + have hp : (∫ x,Real.exp (0*f x) ∂ν)=(1:ℝ) := by simp + have hd := hmass.log (by rw [hp]; norm_num) + rw [hp,div_one] at hd + have hc := hd.continuousAt_div + have he : Function.update (fun a => (Real.log (∫ x,Real.exp (a*f x) ∂ν)- + Real.log (∫ x,Real.exp (0*f x) ∂ν))/(a-0)) 0 (∫ x,f x ∂ν)= + (fun a => logMean ν a f) := by + funext a + by_cases ha : a=0 + · subst a; simp [logMean] + · simp [logMean,ha] + rwa [he] at hc + +lemma logMean_coefficient_continuous {Ω : Type*} [MeasurableSpace Ω] {ν : Measure Ω} + [IsProbabilityMeasure ν] {f : Ω → ℝ} {C : ℝ} (hf : Measurable f) (hb : ∀ x,|f x|≤C) : + Continuous (fun a => logMean ν a f) := by + apply continuous_iff_continuousAt.mpr + intro a + by_cases ha : a=0 + · subst a; exact logMean_coefficient_continuousAt_zero hf hb + have hmass : ContinuousAt (fun a => ∫ x,Real.exp (a*f x) ∂ν) a := by + apply continuousAt_of_dominated (bound:=fun _ => Real.exp ((|a|+1)*C)) + · exact Eventually.of_forall fun t => ((hf.const_mul t).exp).aestronglyMeasurable + · filter_upwards [continuous_abs.continuousAt.eventually (gt_mem_nhds (lt_add_one |a|))] with t ht + filter_upwards with x + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + exact (le_abs_self _).trans (by + rw [abs_mul] + exact mul_le_mul ht.le (hb x) (abs_nonneg _) (by positivity)) + · exact integrable_const _ + · filter_upwards with x + exact (Real.continuous_exp.comp (continuous_id.mul_const (f x))).continuousAt + have hc := (hmass.log (integral_exp_pos (integrable_exp_of_uniform_abs a hf hb)).ne').div continuousAt_id ha + apply hc.congr + filter_upwards [eventually_ne_nhds ha] with t ht + simp [logMean,ht] + +end ParisiFinite + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite +variable {ι : Type*} [Fintype ι] [MeasurableSpace ι] [MeasurableSingletonClass ι] + +lemma finiteRisk_measure (ν : Measure ι) [IsFiniteMeasure ν] (a : ℝ) (f : ι → ℝ) : + finiteRisk (fun i => ν.real {i}) a f=logMean ν a f := by + unfold finiteRisk logMean + rw [integral_fintype Integrable.of_finite,integral_fintype Integrable.of_finite] + rfl + +lemma finiteRisk_coefficient_tendsto (ν : Measure ι) [IsProbabilityMeasure ν] + {a : ℕ → ℝ} {b : ℝ} (ha : ∀ m,0≤a m) (hab : Tendsto a atTop (𝓝 b)) + {f : ℕ → ι → ℝ} {g : ι → ℝ} (hfg : ∀ i,Tendsto (fun m => f m i) atTop (𝓝 (g i))) : + Tendsto (fun m => finiteRisk (fun i => ν.real {i}) (a m) (f m)) atTop + (𝓝 (finiteRisk (fun i => ν.real {i}) b g)) := by + classical + simp_rw [finiteRisk_measure] + have hgb : ∀ i,|g i|≤∑ j,|g j| := fun i => Finset.single_le_sum (fun j _ => abs_nonneg (g j)) (Finset.mem_univ i) + have hc := (logMean_coefficient_continuous (ν:=ν) (measurable_of_finite g) hgb).continuousAt.tendsto.comp hab + have hnorm : Tendsto (fun m => ‖f m-g‖) atTop (𝓝 (0:ℝ)) := by + simpa using ((tendsto_pi_nhds.mpr hfg).sub (tendsto_const_nhds (x:=g))).norm + have hd : Tendsto (fun m => logMean ν (a m) (f m)-logMean ν (a m) g) atTop (𝓝 0) := by + apply squeeze_zero_norm ?_ hnorm + intro m + rw [Real.norm_eq_abs] + apply logMean_stable (ha m) Integrable.of_finite Integrable.of_finite + Integrable.of_finite Integrable.of_finite + intro i + exact le_trans (norm_le_pi_norm (f m-g) i) (le_refl _) + have h := hd.add hc + simpa only [Function.comp_def,sub_add_cancel,zero_add] using h + +lemma finiteHierarchyRisk_coefficient_tendsto (ν : Measure ι) [IsProbabilityMeasure ν] + {d : ℕ} {a : ℕ → Fin d → ℝ} {b : Fin d → ℝ} + (ha : ∀ m k,0≤a m k) (hab : ∀ k,Tendsto (fun m => a m k) atTop (𝓝 (b k))) + (f : (Fin d → ι) → ℝ) : + Tendsto (fun m => finiteHierarchyRisk (fun i => ν.real {i}) (a m) f) atTop + (𝓝 (finiteHierarchyRisk (fun i => ν.real {i}) b f)) := by + induction d with + | zero => exact tendsto_const_nhds + | succ d ih => + apply finiteRisk_coefficient_tendsto ν (fun m => ha m 0) (hab 0) + intro i + exact ih (fun m k => ha m k.succ) (fun k => hab k.succ) (fun s => f (Fin.cons i s)) + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/LowBlock.lean b/lean/OAI/Probability/ParisiFinite/LowBlock.lean new file mode 100644 index 0000000000000000000000000000000000000000..197b036a84d5e9de386244e8879228a0beab06a3 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/LowBlock.lean @@ -0,0 +1,666 @@ +import Mathlib +import OAI.Probability.ParisiFinite.GenericDegrees + +namespace OAI + +/-! Low Block. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def lowBlock (r : ℕ) (a : ℝ) : Set (OverlapBlock r) := + {T | ∀ i j, i≠j → (T i j:ℝ)≤a} + +def lowEvent (r : ℕ) (a : ℝ) : Set OverlapArray := (blockOfArray r) ⁻¹' lowBlock r a + +def lowBad (r : ℕ) (i : Fin r) (a : ℝ) : Set OverlapArray := + {R | R∈lowEvent r a ∧ a<(R i r:ℝ)} + +lemma measurableSet_lowBlock (r : ℕ) (a : ℝ) : MeasurableSet (lowBlock r a) := by + unfold lowBlock + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun i => MeasurableSet.iInter fun j => + MeasurableSet.iInter fun _ => measurableSet_le (by fun_prop) measurable_const + +lemma lowEvent_one (a : ℝ) : lowEvent 1 a=Set.univ := by + ext R + simp [lowEvent, lowBlock] + +lemma lowBad_GG {μ : ProbabilityMeasure OverlapArray} (h : GGIdentities μ) + (r : ℕ) (i : Fin r) (a : ℝ) : + (r:ℝ)*(μ : Measure OverlapArray).real (lowBad r i a)= + (μ : Measure OverlapArray).real (lowEvent r a)*(entryLaw μ 0 1).real {x | a<(x:ℝ)} := by + have he := GG_event_identity h r i (lowBlock r a) {x | a<(x:ℝ)} + (measurableSet_lowBlock r a) (measurableSet_lt measurable_const (by fun_prop)) + have hz (l : Fin r) (hl : l∈Finset.univ.erase i) : + {R | blockOfArray r R∈lowBlock r a ∧ a<(R i l:ℝ)}=(∅ : Set OverlapArray) := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro R hR + exact (not_lt_of_ge (hR.1 i l (Finset.ne_of_mem_erase hl).symm)) hR.2 + have hs : (∑ l∈Finset.univ.erase i, (μ : Measure OverlapArray).real + {R | blockOfArray r R∈lowBlock r a ∧ a<(R i l:ℝ)})=0 := by + apply Finset.sum_eq_zero + intro l hl + rw [hz l hl,measureReal_empty] + simp only [Set.mem_ofPred_eq] at he + rw [hs,add_zero] at he + exact he + +lemma lowEvent_step_cover (r : ℕ) (a : ℝ) : + lowEvent r a ⊆ (lowEvent (r+1) a ∪ ⋃ i, lowBad r i a) ∪ GramArraysᶜ := by + classical + intro R hR + by_cases hG : R∈GramArrays + · by_cases hb : ∃ i, R∈lowBad r i a + · exact Or.inl (Or.inr (Set.mem_iUnion.mpr hb)) + · have hn (i : Fin r) : (R i r:ℝ)≤a := by + by_contra hh + exact hb ⟨i,hR,lt_of_not_ge hh⟩ + apply Or.inl ∘ Or.inl + intro i j hij + induction i using Fin.lastCases with + | last => + induction j using Fin.lastCases with + | last => exact False.elim (hij rfl) + | cast j => + change (R r j:ℝ)≤a + rw [hG.1 r j] + exact hn j + | cast i => + induction j using Fin.lastCases with + | last => exact hn i + | cast j => exact hR i j (fun h => hij (congrArg Fin.castSucc h)) + · exact Or.inr hG + +lemma lowEvent_step_bound {μ : ProbabilityMeasure OverlapArray} (hG : (μ : Measure OverlapArray) GramArrays=1) + (h : GGIdentities μ) {r : ℕ} (hr : 0 lowBad r i a) + have he : (∑ i : Fin r,ν.real (lowBad r i a))= + ν.real (lowEvent r a)*(entryLaw μ 0 1).real {x | a<(x:ℝ)} := by + apply mul_left_cancel₀ (Nat.cast_ne_zero.mpr hr.ne' : (r:ℝ)≠0) + rw [Finset.mul_sum] + simp_rw [show ∀ i : Fin r, (r:ℝ)*ν.real (lowBad r i a)= + ν.real (lowEvent r a)*(entryLaw μ 0 1).real {x | a<(x:ℝ)} from fun i => lowBad_GG h r i a] + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + have hp : (entryLaw μ 0 1).real {x : OverlapEntry | (x:ℝ)≤a}+ + (entryLaw μ 0 1).real {x : OverlapEntry | a<(x:ℝ)}=1 := by + let := entryLaw_probability μ 0 1 + have ht := measureReal_add_measureReal_compl (μ:=entryLaw μ 0 1) (s:={x : OverlapEntry | (x:ℝ)≤a}) + (measurableSet_le (by fun_prop : Measurable (fun x : OverlapEntry => (x:ℝ))) measurable_const) + simpa only [Set.compl_ofPred, not_le, measureReal_def, measure_univ, ENNReal.toReal_one] using ht + rw [he] at hs + change ν.real (lowEvent r a)*(entryLaw μ 0 1).real {x | (x:ℝ)≤a} ≤ν.real (lowEvent (r+1) a) + have hm := congrArg (fun x : ℝ => ν.real (lowEvent r a)*x) hp + simp only [mul_add,mul_one] at hm + linarith + +lemma lowEvent_positive {μ : ProbabilityMeasure OverlapArray} (hG : (μ : Measure OverlapArray) GramArrays=1) + (h : GGIdentities μ) (a : ℝ) (ha : 0<(entryLaw μ 0 1).real {x | (x:ℝ)≤a}) : + ∀ r : ℕ, 0<(μ : Measure OverlapArray).real (lowEvent (r+1) a) := by + intro r + induction r with + | zero => rw [Nat.zero_add,lowEvent_one]; simp + | succ r ih => exact lt_of_lt_of_le (mul_pos ih ha) (lowEvent_step_bound hG h (Nat.succ_pos r) a) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma gram_clique_bound {R : OverlapArray} (hG : R∈GramArrays) {r : ℕ} {a : ℝ} + (hl : R∈lowEvent (r+1) a) : 0≤1+(r:ℝ)*a := by + have hr (i : Fin (r+1)) : (∑ j : Fin (r+1), (R i j:ℝ)) ≤ 1+(r:ℝ)*a := by + calc + _ = (∑ j∈Finset.univ.erase i, (R i j:ℝ))+(R i i:ℝ) := + (Finset.sum_erase_add _ _ (Finset.mem_univ i)).symm + _ ≤ (∑ j∈Finset.univ.erase i,a)+1 := by + apply add_le_add + · exact Finset.sum_le_sum (fun j hj => hl i j (Finset.ne_of_mem_erase hj).symm) + · exact le_of_eq (hG.2.1 i) + _ = _ := by simp; ring + have hh := Finset.sum_le_sum (fun i (_ : i∈(Finset.univ : Finset (Fin (r+1)))) => hr i) + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hh + have hp := hG.2.2 (r+1) (fun _ => 1) + simp only [one_mul] at hp + have hh' : 0≤((r+1:ℕ):ℝ)*(1+(r:ℝ)*a) := hp.trans hh + have hp' : (0:ℝ)<(r+1:ℕ) := by positivity + nlinarith + + +lemma exists_negative_clique_impossible {a : ℝ} (ha : a<0) : + ∃ r : ℕ, lowEvent (r+1) a ⊆ GramArraysᶜ := by + obtain ⟨r,hr⟩ := exists_nat_gt ((-1:ℝ)/a) + refine ⟨r,fun R hl hG => ?_⟩ + have hg := gram_clique_bound hG hl + have hh := (div_lt_iff_of_neg ha).mp hr + linarith + + + +theorem GG_negative_threshold_zero {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) (h : GGIdentities μ) {a : ℝ} (ha : a<0) : + (entryLaw μ 0 1).real {x | (x:ℝ)≤a}=0 := by + by_contra hh + have hp : 0<(entryLaw μ 0 1).real {x | (x:ℝ)≤a} := lt_of_le_of_ne measureReal_nonneg (Ne.symm hh) + obtain ⟨r,hr⟩ := exists_negative_clique_impossible ha + have hc : (μ : Measure OverlapArray).real GramArraysᶜ=0 := by + rw [measureReal_compl isClosed_GramArrays.measurableSet] + simp [measureReal_def,hG] + have he := measureReal_mono (μ:=(μ:Measure OverlapArray)) hr + rw [hc] at he + exact (not_lt_of_ge he) (lowEvent_positive hG h a hp r) + +lemma GG_negative_overlap_zero {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) (h : GGIdentities μ) : + (entryLaw μ 0 1) {x | (x:ℝ)<0}=0 := by + let Q := {q : ℚ // (q:ℝ)<0} + have hz (q : Q) : (entryLaw μ 0 1) {x | (x:ℝ)≤(q.1:ℝ)}=0 := + (measureReal_eq_zero_iff).mp (GG_negative_threshold_zero hG h q.2) + have hc : {x : OverlapEntry | (x:ℝ)<0} ⊆ ⋃ q : Q, {x | (x:ℝ)≤(q.1:ℝ)} := by + intro x hx + obtain ⟨q,hxq,hq⟩ := exists_rat_btwn (show (x:ℝ)<0 from hx) + exact Set.mem_iUnion.mpr ⟨⟨q,hq⟩,le_of_lt hxq⟩ + exact measure_mono_null hc (measure_iUnion_null hz) + +lemma GG_nonnegative_overlap {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) (h : GGIdentities μ) : + ∀ᵐ R ∂(μ : Measure OverlapArray), 0≤(R 0 1:ℝ) := by + have he := GG_negative_overlap_zero hG h + rw [entryLaw, Measure.map_apply (by fun_prop) (measurableSet_lt (by fun_prop) measurable_const)] at he + apply ae_iff.mpr + simpa only [Set.preimage_ofPred_eq, not_le] using he + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity + + + +theorem urn_growth_contradiction {r : ℕ} (hr : 0 ((r+m:ℕ):ℝ)*f m + have hu0 : 0 by rw [hus]; nlinarith [hf m] + have hub' (m : ℕ) : u m≤r := by + have hh := hub m + have hr' : (1:ℝ)≤r := by exact_mod_cast hr + dsimp [u] + push_cast at hh ⊢ + have hm : (r:ℝ)*m*f m≥(m:ℝ)*f m := by + simpa only [one_mul] using mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right hr' (Nat.cast_nonneg m)) (hf m) + have hb := mul_le_mul_of_nonneg_left hh (Nat.cast_nonneg r) + nlinarith only [hm,hb] + have hs (k : ℕ) : u k=u 0+z*∑ m∈Finset.range k,f m := by + induction k with + | zero => simp + | succ k ih => rw [hus,ih,Finset.sum_range_succ]; ring + have hsum : Summable f := summable_of_sum_range_le hf (c:=(r:ℝ)/z) fun k => by + apply (le_div_iff₀ hz).mpr + have hh := hub' k + rw [hs] at hh + nlinarith + have hl (m : ℕ) : (1:ℝ)/((m+r:ℕ):ℝ)≤f m/u 0 := by + have hu := hum (Nat.zero_le m) + have hp : (0:ℝ)<((m+r:ℕ):ℝ) := by positivity + apply (div_le_div_iff₀ hp hu0).mpr + change u 0≤((r+m:ℕ):ℝ)*f m at hu + simpa only [one_mul,mul_one,Nat.add_comm,mul_comm] using hu + have htail : Summable (fun m : ℕ => (1:ℝ)/((m+r:ℕ):ℝ)) := + Summable.of_nonneg_of_le (fun _ => by positivity) hl (hsum.div_const (u 0)) + exact Real.not_summable_one_div_natCast ((summable_nat_add_iff r).mp htail) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def initialBlock {s t : ℕ} (h : s≤t) (T : OverlapBlock t) : OverlapBlock s := + fun i j => T (Fin.castLE h i) (Fin.castLE h j) + +lemma continuous_initialBlock {s t : ℕ} (h : s≤t) : Continuous (initialBlock h) := by + unfold initialBlock + fun_prop + + +def rowSurvival (r m : ℕ) (D : Set (OverlapBlock (r+1))) (q : ℝ) : Set OverlapArray := + {R | blockOfArray (r+1) R∈D ∧ ∀ j : ℕ, j rintro ⟨h₁,h₂⟩ + · exact ⟨h₁,fun j hj => h₂ j j.isLt hj⟩ + · exact ⟨h₁,fun j hj hne => h₂ ⟨j,hj⟩ hne⟩ + +lemma measurableSet_survivalBlock (r m : ℕ) {D : Set (OverlapBlock (r+1))} + (hD : MeasurableSet D) (q : ℝ) : MeasurableSet (survivalBlock r m D q) := by + change MeasurableSet ((initialBlock (show r+1≤r+m+1 by omega)) ⁻¹' D ∩ + {T | ∀ j : Fin (r+m+1), (j:ℕ)≠r → (T ⟨r,by omega⟩ j:ℝ)≤q}) + apply MeasurableSet.inter (hD.preimage (continuous_initialBlock _).measurable) + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun j => MeasurableSet.iInter fun _ => measurableSet_le (by fun_prop) measurable_const + +lemma measurableSet_rowSurvival (r m : ℕ) {D : Set (OverlapBlock (r+1))} + (hD : MeasurableSet D) (q : ℝ) : MeasurableSet (rowSurvival r m D q) := by + rw [rowSurvival_eq_preimage] + exact (measurableSet_survivalBlock r m hD q).preimage (continuous_blockOfArray _).measurable + +lemma rowSurvival_succ (r m : ℕ) (D : Set (OverlapBlock (r+1))) (q : ℝ) : + rowSurvival r (m+1) D q={R | R∈rowSurvival r m D q ∧ (R r (r+m+1):ℝ)≤q} := by + ext R + constructor + · rintro ⟨hD,h⟩ + exact ⟨⟨hD,fun j hj hne => h j (by omega) hne⟩,h (r+m+1) (by omega) (by omega)⟩ + · rintro ⟨⟨hD,h⟩,hn⟩ + refine ⟨hD,fun j hj hne => ?_⟩ + by_cases hh : j hh.mp hR.1 + · intro hR + refine ⟨hh.mpr hR, hR.2 l l.isLt ?_⟩ + intro hc + exact Finset.ne_of_mem_erase hl (Fin.ext hc) + have hs : (∑ l∈Finset.univ.erase i,(μ : Measure OverlapArray).real + {R | blockOfArray (r+m+1) R∈survivalBlock r m D q ∧ R i l∈{x : OverlapEntry | (x:ℝ)≤q}})= + ((r+m:ℕ):ℝ)*(μ : Measure OverlapArray).real (rowSurvival r m D q) := by + simp_rw [Finset.sum_congr rfl (fun l hl => congrArg (μ : Measure OverlapArray).real (hz l hl))] + simp + rw [hs,← rowSurvival_eq_preimage] at he + have heSet : {R | blockOfArray (r+m+1) R∈survivalBlock r m D q ∧ R i (r+m+1)∈{x : OverlapEntry | (x:ℝ)≤q}}= + rowSurvival r (m+1) D q := by + rw [rowSurvival_succ, rowSurvival_eq_preimage r m] + rfl + rw [heSet] at he + linarith + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def FiniteExchangeable (μ : ProbabilityMeasure OverlapArray) : Prop := + ∀ (r : ℕ) (e : Fin r → ℕ), Function.Injective e → + (μ : Measure OverlapArray).map (selectedBlock e)=blockLaw μ r + +lemma genericOverlap_limit_FiniteExchangeable (β : ℝ) {μ : ProbabilityMeasure OverlapArray} {φ : ℕ → ℕ} + (hφ : StrictMono φ) (hμ : Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ)) : + FiniteExchangeable μ := genericOverlap_limit_exchangeable β hφ hμ + +lemma exchangeable_event {μ : ProbabilityMeasure OverlapArray} (h : FiniteExchangeable μ) + {r : ℕ} (e : Fin r → ℕ) (he : Function.Injective e) {B : Set (OverlapBlock r)} (hB : MeasurableSet B) : + (μ : Measure OverlapArray) ((selectedBlock e) ⁻¹' B)=(μ : Measure OverlapArray) ((blockOfArray r) ⁻¹' B) := by + have hh := congrArg (fun ν : Measure (OverlapBlock r) => ν B) (h r e he) + rw [Measure.map_apply (continuous_selectedBlock e).measurable hB, + blockLaw, Measure.map_apply (continuous_blockOfArray r).measurable hB] at hh + exact hh + +lemma exchangeable_event_real {μ : ProbabilityMeasure OverlapArray} (h : FiniteExchangeable μ) + {r : ℕ} (e : Fin r → ℕ) (he : Function.Injective e) {B : Set (OverlapBlock r)} (hB : MeasurableSet B) : + (μ : Measure OverlapArray).real ((selectedBlock e) ⁻¹' B)= + (μ : Measure OverlapArray).real ((blockOfArray r) ⁻¹' B) := + congrArg ENNReal.toReal (exchangeable_event h e he hB) + +def tailPerm (r : ℕ) {k : ℕ} (q : Equiv.Perm (Fin k)) : Equiv.Perm (Fin (r+k)) := + finSumFinEquiv.symm.trans ((Equiv.sumCongr (Equiv.refl (Fin r)) q).trans finSumFinEquiv) + +@[simp] lemma tailPerm_old (r : ℕ) {k : ℕ} (q : Equiv.Perm (Fin k)) (i : Fin r) : + tailPerm r q (Fin.castAdd k i)=Fin.castAdd k i := by simp [tailPerm] + +@[simp] lemma tailPerm_new (r : ℕ) {k : ℕ} (q : Equiv.Perm (Fin k)) (i : Fin k) : + tailPerm r q (Fin.natAdd r i)=Fin.natAdd r (q i) := by simp [tailPerm] + +def newRow {r k : ℕ} (T : OverlapBlock (r+k)) (j : Fin k) : Fin r → OverlapEntry := + fun i => T (Fin.natAdd r j) (Fin.castAdd k i) + +lemma continuous_newRow {r k : ℕ} (j : Fin k) : Continuous (fun T : OverlapBlock (r+k) => newRow T j) := by + unfold newRow + fun_prop + + +def uniqueMark (r k : ℕ) (B : Set (Fin r → OverlapEntry)) (j : Fin k) : Set (OverlapBlock (r+k)) := + {T | newRow T j∈B ∧ ∀ l : Fin k, l≠j → newRow T l∉B} + +lemma measurableSet_uniqueMark (r k : ℕ) {B : Set (Fin r → OverlapEntry)} (hB : MeasurableSet B) (j : Fin k) : + MeasurableSet (uniqueMark r k B j) := by + change MeasurableSet ((fun T : OverlapBlock (r+k) => newRow T j) ⁻¹' B ∩ + {T | ∀ l : Fin k, l≠j → newRow T l∉B}) + apply MeasurableSet.inter (hB.preimage (continuous_newRow j).measurable) + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun l => MeasurableSet.iInter fun _ => + (hB.preimage (continuous_newRow l).measurable).compl + +lemma uniqueMark_disjoint (r k : ℕ) (B : Set (Fin r → OverlapEntry)) : + Pairwise (fun i j => Disjoint ((blockOfArray (r+k)) ⁻¹' uniqueMark r k B i) ((blockOfArray (r+k)) ⁻¹' uniqueMark r k B j)) := by + intro i j hij + apply Set.disjoint_left.mpr + intro R hi hj + exact hi.2 j hij.symm hj.1 + +lemma uniqueMark_relabel {r k : ℕ} (B : Set (Fin r → OverlapEntry)) (q : Equiv.Perm (Fin k)) (j : Fin k) : + (selectedBlock (fun i : Fin (r+k) => (tailPerm r q i:ℕ))) ⁻¹' uniqueMark r k B j= + (blockOfArray (r+k)) ⁻¹' uniqueMark r k B (q j) := by + ext R + have he (l : Fin k) : newRow (selectedBlock (fun i : Fin (r+k) => (tailPerm r q i:ℕ)) R) l= + newRow (blockOfArray (r+k) R) (q l) := by + funext i + simp only [newRow,selectedBlock,tailPerm_old,tailPerm_new,blockOfArray] + change (_ ∧ _) ↔ (_ ∧ _) + simp_rw [he] + constructor + · rintro ⟨hj,hh⟩ + refine ⟨hj,fun l hl => ?_⟩ + have hl' : q.symm l≠j := fun h => hl (by simpa using congrArg q h) + simpa only [q.apply_symm_apply] using hh (q.symm l) hl' + · rintro ⟨hj,hh⟩ + exact ⟨hj,fun l hl => hh (q l) (fun he => hl (q.injective he))⟩ + +lemma uniqueMark_equal {μ : ProbabilityMeasure OverlapArray} (h : FiniteExchangeable μ) + (r k : ℕ) {B : Set (Fin r → OverlapEntry)} (hB : MeasurableSet B) (i j : Fin k) : + (μ : Measure OverlapArray).real ((blockOfArray (r+k)) ⁻¹' uniqueMark r k B i)= + (μ : Measure OverlapArray).real ((blockOfArray (r+k)) ⁻¹' uniqueMark r k B j) := by + let q : Equiv.Perm (Fin k) := Equiv.swap j i + have hh := exchangeable_event_real h (fun l : Fin (r+k) => (tailPerm r q l:ℕ)) + (Fin.val_injective.comp (tailPerm r q).injective) (measurableSet_uniqueMark r k hB j) + rw [uniqueMark_relabel] at hh + simpa [q] using hh + +lemma uniqueMark_bound {μ : ProbabilityMeasure OverlapArray} (h : FiniteExchangeable μ) + (r k : ℕ) {B : Set (Fin r → OverlapEntry)} (hB : MeasurableSet B) (i : Fin k) : + (k:ℝ)*(μ : Measure OverlapArray).real ((blockOfArray (r+k)) ⁻¹' uniqueMark r k B i)≤1 := by + have hh := measureReal_iUnion_fintype (μ:=(μ:Measure OverlapArray)) + (uniqueMark_disjoint r k B) (fun j => (measurableSet_uniqueMark r k hB j).preimage (continuous_blockOfArray _).measurable) + have he : (∑ j : Fin k, (μ : Measure OverlapArray).real ((blockOfArray (r+k)) ⁻¹' uniqueMark r k B j))= + (k:ℝ)*(μ : Measure OverlapArray).real ((blockOfArray (r+k)) ⁻¹' uniqueMark r k B i) := by + simp_rw [uniqueMark_equal h r k hB _ i] + simp + rw [he] at hh + rw [← hh] + exact measureReal_le_one + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def arrayRow (r j : ℕ) (R : OverlapArray) : Fin r → OverlapEntry := fun i => R j i + +lemma continuous_arrayRow (r j : ℕ) : Continuous (arrayRow r j) := by + unfold arrayRow + fun_prop + +def patternBlock (r : ℕ) (C : Set (OverlapBlock r)) (B : Set (Fin r → OverlapEntry)) : + Set (OverlapBlock (r+1)) := + {T | initialBlock (Nat.le_succ r) T∈C ∧ newRow T (0 : Fin 1)∈B} + +lemma measurableSet_patternBlock {r : ℕ} {C : Set (OverlapBlock r)} {B : Set (Fin r → OverlapEntry)} + (hC : MeasurableSet C) (hB : MeasurableSet B) : MeasurableSet (patternBlock r C B) := + (hC.preimage (continuous_initialBlock _).measurable).inter + (hB.preimage (continuous_newRow _).measurable) + +@[simp] lemma patternBlock_preimage (r : ℕ) (C : Set (OverlapBlock r)) (B : Set (Fin r → OverlapEntry)) : + (blockOfArray (r+1)) ⁻¹' patternBlock r C B= + {R | blockOfArray r R∈C ∧ arrayRow r r R∈B} := by + rfl + +def doubleMarkBlock (r : ℕ) (C : Set (OverlapBlock r)) (B : Set (Fin r → OverlapEntry)) (q : ℝ) : + Set (OverlapBlock (r+2)) := + {T | initialBlock (by omega : r≤r+2) T∈C ∧ newRow T (0 : Fin 2)∈B ∧ + newRow T (1 : Fin 2)∈B ∧ (T ⟨r,by omega⟩ ⟨r+1,by omega⟩:ℝ)≤q} + +lemma measurableSet_doubleMarkBlock {r : ℕ} {C : Set (OverlapBlock r)} {B : Set (Fin r → OverlapEntry)} + (hC : MeasurableSet C) (hB : MeasurableSet B) (q : ℝ) : MeasurableSet (doubleMarkBlock r C B q) := by + exact (hC.preimage (continuous_initialBlock _).measurable).inter + ((hB.preimage (continuous_newRow _).measurable).inter + ((hB.preimage (continuous_newRow _).measurable).inter (measurableSet_le (f := fun T : OverlapBlock (r+2) => (T ⟨r,by omega⟩ ⟨r+1,by omega⟩:ℝ)) (by fun_prop) measurable_const))) + +def doubleMarkAt (r j : ℕ) (C : Set (OverlapBlock r)) (B : Set (Fin r → OverlapEntry)) (q : ℝ) : + Set OverlapArray := + {R | blockOfArray r R∈C ∧ arrayRow r r R∈B ∧ arrayRow r j R∈B ∧ (R r j:ℝ)≤q} + +lemma measurableSet_doubleMarkAt {r j : ℕ} {C : Set (OverlapBlock r)} {B : Set (Fin r → OverlapEntry)} + (hC : MeasurableSet C) (hB : MeasurableSet B) (q : ℝ) : MeasurableSet (doubleMarkAt r j C B q) := by + exact (hC.preimage (continuous_blockOfArray _).measurable).inter + ((hB.preimage (continuous_arrayRow _ _).measurable).inter + ((hB.preimage (continuous_arrayRow _ _).measurable).inter (measurableSet_le (f := fun R : OverlapArray => (R r j:ℝ)) (by fun_prop) measurable_const))) + +def prefixFresh (s j : ℕ) : Fin (s+1) → ℕ := fun i => if (i:ℕ) h.1 + · intro h + refine ⟨h,fun j hj hne => ?_⟩ + have hb : arrayRow r r R∈B := h.2 + exact hB _ hb ⟨j,by omega⟩ + + + +theorem GG_duplication {μ : ProbabilityMeasure OverlapArray} (hgg : GGIdentities μ) + (hex : FiniteExchangeable μ) {r : ℕ} (hr : 0 hR + · exact Filter.Eventually.of_forall fun _ h => (hj h).elim + let f : ℕ → ℝ := fun m => (μ : Measure OverlapArray).real (rowSurvival r m (patternBlock r C B) q) + have h₀ : 0 rowSurvival_GG hgg r m (measurableSet_patternBlock hC hB) q + have hub (m : ℕ) : ((m+1:ℕ):ℝ)*f m≤1 := by + have hs : ∀ᵐ R ∂(μ : Measure OverlapArray), R∈rowSurvival r m (patternBlock r C B) q → + R∈(blockOfArray (r+(m+1))) ⁻¹' uniqueMark r (m+1) B 0 := by + filter_upwards [hall] with R hR hsur + refine ⟨hsur.1.2,fun j hj hBj => ?_⟩ + have hj' : r+1≤r+(j:ℕ) := by + have : (j:ℕ)≠0 := fun he => hj (Fin.ext he) + omega + apply hR (r+j) hj' + exact ⟨hsur.1.1,hsur.1.2,hBj,hsur.2 (r+j) (by omega) (by omega)⟩ + have hm : f m≤(μ : Measure OverlapArray).real + ((blockOfArray (r+(m+1))) ⁻¹' uniqueMark r (m+1) B 0) := + ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono_ae hs) + exact (mul_le_mul_of_nonneg_left hm (Nat.cast_nonneg _)).trans (uniqueMark_bound hex r (m+1) hB 0) + exact urn_growth_contradiction hr hz f (fun _ => measureReal_nonneg) h₀ hrec hub + +lemma exchangeable_pair_event {μ : ProbabilityMeasure OverlapArray} (hex : FiniteExchangeable μ) + {i j : ℕ} (hij : i≠j) {A : Set OverlapEntry} (hA : MeasurableSet A) : + (μ : Measure OverlapArray).real {R | R i j∈A}=(entryLaw μ 0 1).real A := by + let e : Fin 2 → ℕ := ![i,j] + have he : Function.Injective e := by + intro a b hab + fin_cases a <;> fin_cases b + · rfl + · exact (hij hab).elim + · exact (hij hab.symm).elim + · rfl + have hh := exchangeable_event_real hex e he (hA.preimage (show Measurable (fun T : OverlapBlock 2 => T 0 1) by fun_prop)) + change (μ : Measure OverlapArray).real {R | R i j∈A}=(μ : Measure OverlapArray).real {R | R 0 1∈A} at hh + rw [hh,measureReal_def,measureReal_def,entryLaw,Measure.map_apply (by fun_prop) hA] + rfl + + +theorem GG_duplication_of_positive {μ : ProbabilityMeasure OverlapArray} (hgg : GGIdentities μ) + (hex : FiniteExchangeable μ) {r : ℕ} (hr : 0 ‖ordinaryDisplacement n b t‖) atTop (𝓝 (2*|b|)) := by + rw [tendsto_iff_norm_sub_tendsto_zero] + apply squeeze_zero (fun _ => norm_nonneg _) (fun t => ?_) + (tendsto_ordinaryDisplacement_error n b) + have h := abs_norm_sub_norm_le (ordinaryDisplacement n b t) + ((2*b:ℝ) • highDirection n (gamma b t)) + have hn : ‖(2*b:ℝ) • highDirection n (gamma b t)‖=2*|b| := by + rw [← Complex.coe_smul,norm_smul,highDirection_norm,mul_one, + Complex.norm_real,Real.norm_eq_abs,abs_mul] + norm_num + simpa only [hn,Real.norm_eq_abs] using h + + +def initializedInsertion (n : ℕ) (b t : ℝ) : Mode (n+2) := + (ordinary (initializationWord (gamma b t) (delta t) (Real.pi/4)) (n+2)).insertion + +@[simp] theorem initializedInsertion_coe (n : ℕ) (b t : ℝ) : + (initializedInsertion n b t : Level (n+2))= + (ordinary (initializationWord (gamma b t) (delta t) (Real.pi/4)) (n+2)).op.symm + (SpinOperators.act Z + ((ordinary (initializationWord (gamma b t) (delta t) (Real.pi/4)) (n+2)).op + (vac (n+2)))) := rfl + +@[simp] theorem norm_initializedInsertion (n : ℕ) (b t : ℝ) : + ‖initializedInsertion n b t‖=1 := EvenUnitary.norm_insertion _ + +theorem initializedInsertion_error (n : ℕ) (b : ℝ) {t : ℝ} (ht : 1 ≤ t) : + ‖(initializedInsertion n b t:Level (n+2))-lowVector (ordinaryDisplacement n b t)‖≤ + 2*(amplitude t^2+amplitude t) := by + have h := initial_insertion_error (E := Mode (n+1)) (gamma b t) (Real.pi/4) ht + (actualV n b t) (initialDirection (n+1)) (SpinOperators.act Z) + (fun x => (SpinOperators.norm_act Z_unitary x).le) + rw [ordinary_insertion_eq,initialMap_eq_ordinary] at h + rw [initializedInsertion_coe] + exact h + +theorem tendsto_initializedInsertion_error (n : ℕ) (b : ℝ) : + Tendsto (fun t => ‖(initializedInsertion n b t:Level (n+2))- + lowVector (ordinaryDisplacement n b t)‖) atTop (𝓝 0) := by + apply squeeze_zero' (Filter.Eventually.of_forall fun t => norm_nonneg _) ?_ + (by simpa only [zero_pow (by norm_num : (2:ℕ)≠0),add_zero,mul_zero] using + ((tendsto_amplitude.pow 2).add tendsto_amplitude).const_mul 2) + filter_upwards [eventually_ge_atTop (1:ℝ)] with t ht + exact initializedInsertion_error n b ht + +theorem tendsto_lowVector_initial (n : ℕ) (b : ℝ) : + Tendsto (fun t => ⟪lowVector (ordinaryDisplacement n b t), + (initialDirection (n+2):Level (n+2))⟫_ℂ) atTop + (𝓝 (I*(Real.exp (-8*b^2):ℂ))) := by + have he := Real.continuous_exp.continuousAt.tendsto.comp + (((tendsto_norm_ordinaryDisplacement n b).pow 2).const_mul (-2)) + have hh := (Complex.continuous_ofReal.continuousAt.tendsto.comp he).const_mul I + have hpow : -2*(2*|b|)^2= -8*b^2 := by rw [mul_pow,sq_abs]; ring + rw [hpow] at hh + have hinit : (initialDirection (n+2):Level (n+2))= + SpinOperators.act Z (vacuum (Mode (n+1))) := rfl + simpa only [hinit,inner_lowVector_initial,Function.comp_def] using hh + + + +theorem tendsto_initialized_initial (n : ℕ) (b : ℝ) : + Tendsto (fun t => ⟪(initializedInsertion n b t:Level (n+2)), + (initialDirection (n+2):Level (n+2))⟫_ℂ) atTop + (𝓝 (I*(Real.exp (-8*b^2):ℂ))) := by + have he : Tendsto (fun t => + ⟪(initializedInsertion n b t:Level (n+2)),(initialDirection (n+2):Level (n+2))⟫_ℂ- + ⟪lowVector (ordinaryDisplacement n b t),(initialDirection (n+2):Level (n+2))⟫_ℂ) + atTop (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero (fun _ => norm_nonneg _) (fun t => ?_) + (tendsto_initializedInsertion_error n b) + rw [← inner_sub_left] + have h := norm_inner_le_norm (𝕜 := ℂ) + ((initializedInsertion n b t:Level (n+2))-lowVector (ordinaryDisplacement n b t)) + (initialDirection (n+2):Level (n+2)) + have hn : ‖(initialDirection (n+2):Level (n+2))‖=1 := initialDirection_norm (n+2) + simpa only [hn,mul_one] using h + simpa only [sub_add_cancel,zero_add] using he.add (tendsto_lowVector_initial n b) + +theorem tendsto_initial_visibility (n : ℕ) (b z : ℝ) : + Tendsto (fun t => -2*(⟪(initializedInsertion n b t:Level (n+2)), + (-2*b*z:ℝ) • (initialDirection (n+2):Level (n+2))⟫_ℂ).im) atTop + (𝓝 (4*b*z*Real.exp (-8*b^2))) := by + have hc := (tendsto_initialized_initial n b).const_mul ((-2*b*z:ℝ):ℂ) + have hi := Complex.continuous_im.continuousAt.tendsto.comp hc + have h := hi.const_mul (-2) + simp only [Complex.mul_im,Complex.ofReal_im,Complex.ofReal_re,zero_mul,zero_add, + Complex.I_re,Complex.I_im,one_mul,mul_zero,add_zero,Function.comp_def] at h + convert! h using 1 + · funext t + rw [← Complex.coe_smul,inner_smul_right] + simp only [Complex.mul_im,Complex.ofReal_re,Complex.ofReal_im,zero_mul,add_zero] + · congr 1 + ring + +theorem initial_visibility_nonzero (n : ℕ) {b : ℝ} (hb : 0 < b) {z : ℝ} (hz : z≠0) : + ∀ᶠ t : ℝ in atTop, -2*(⟪(initializedInsertion n b t:Level (n+2)), + (-2*b*z:ℝ) • (initialDirection (n+2):Level (n+2))⟫_ℂ).im≠0 := by + apply (tendsto_initial_visibility n b z).eventually_ne + exact mul_ne_zero (mul_ne_zero (mul_ne_zero (by norm_num) hb.ne') hz) (Real.exp_ne_zero _) + +end SeedInitialization + +namespace SeedInitialization +open CoherentFock RootSpin PointedTree Complex +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +def preVacuum (E : Type*) [Zero E] : PreSpin E := fun _ => spinCoefficient • basis 0 + +@[simp] theorem spinCoe_preVacuum : spinCoe (preVacuum E)=vacuum E := by + ext i + simp only [spinCoe_apply,preVacuum,UniformSpace.Completion.coe_smul,coe_basis, + vacuum_apply,spinCoefficient] + +omit [InnerProductSpace ℂ E] in +@[simp] theorem spinMass_preVacuum : spinMass (preVacuum E)=2*‖spinCoefficient‖ := by + simp only [spinMass,preVacuum,mass_smul,mass_basis,mul_one,Fin.sum_univ_two] + ring + +omit [InnerProductSpace ℂ E] in +theorem radius_preVacuum : SpinRadiusLE (preVacuum E) 0 := + fun _ => (RadiusLE.basis (0:E) 0 (by simp)).smul _ + +def preLow (d : E) : PreSpin E := preRoot Y (preWZ ((2:ℝ) • d) (preVacuum E)) + +@[simp] theorem spinCoe_preLow (d : E) : spinCoe (preLow d)=lowVector d := by + simp only [preLow,spinCoe_preRoot,spinCoe_preWZ,spinCoe_preVacuum,lowVector] + +theorem mass_preLow (d : E) : spinMass (preLow d) ≤ matrixMass Y*(2*‖spinCoefficient‖) := by + have hM : 0 ≤ matrixMass Y := Finset.sum_nonneg fun i _ => + Finset.sum_nonneg fun j _ => norm_nonneg (Y i j) + exact (spinMass_preRoot _ _).trans (mul_le_mul_of_nonneg_left + ((spinMass_preWZ _ _).trans_eq spinMass_preVacuum) hM) + +theorem radius_preLow (d : E) : SpinRadiusLE (preLow d) (2*‖d‖) := by + have h := ((radius_preVacuum (E := E)).preWZ ((2:ℝ) • d)).preRoot Y + simpa only [preLow,norm_smul,Real.norm_of_nonneg (by norm_num : (0:ℝ)≤2),add_zero] using h + +theorem bounded_preLow (n : ℕ) (b : ℝ) : + ∀ᶠ t : ℝ in atTop, + SpinRadiusLE (preLow (ordinaryDisplacement n b t)) (2*(2*|b|+1)) ∧ + spinMass (preLow (ordinaryDisplacement n b t)) ≤ matrixMass Y*(2*‖spinCoefficient‖) := by + filter_upwards [ordinaryDisplacement_bounded n b] with t ht + refine ⟨fun i => (radius_preLow _ i).mono ?_,mass_preLow _⟩ + exact mul_le_mul_of_nonneg_left ht (by norm_num) + +theorem tendsto_inner_low_high (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ⟪lowVector (ordinaryDisplacement n b t), + (highDirection (n+1) (gamma b t):Level (n+2))⟫_ℂ) atTop (𝓝 0) := by + simpa only [spinCoe_preLow] using tendsto_inner_high_uniform (n+1) b hb + (fun t => preLow (ordinaryDisplacement n b t)) (2*(2*|b|+1)) + (matrixMass Y*(2*‖spinCoefficient‖)) (by positivity) (bounded_preLow n b) + +theorem tendsto_inner_low_address (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ⟪lowVector (ordinaryDisplacement n b t),actualAddress n b t⟫_ℂ) + atTop (𝓝 0) := by + simpa only [spinCoe_preLow] using tendsto_inner_address_uniform n b hb + (fun t => preLow (ordinaryDisplacement n b t)) (2*(2*|b|+1)) + (matrixMass Y*(2*‖spinCoefficient‖)) (by positivity) (bounded_preLow n b) + +variable {α : Type*} {l : Filter α} + +theorem tendsto_inner_error_unit (x y z : α → E) + (hxy : Tendsto (fun a => ‖x a-y a‖) l (𝓝 0)) (hz : ∀ a, ‖z a‖=1) : + Tendsto (fun a => ⟪x a,z a⟫_ℂ-⟪y a,z a⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero (fun _ => norm_nonneg _) (fun a => ?_) hxy + rw [← inner_sub_left] + simpa only [hz a,mul_one] using norm_inner_le_norm (𝕜 := ℂ) (x a-y a) (z a) + + +theorem tendsto_initialized_high (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ⟪(initializedInsertion n b t:Level (n+2)), + (highDirection (n+1) (gamma b t):Level (n+2))⟫_ℂ) atTop (𝓝 0) := by + have he := tendsto_inner_error_unit + (fun t => (initializedInsertion n b t:Level (n+2))) + (fun t => lowVector (ordinaryDisplacement n b t)) + (fun t => (highDirection (n+1) (gamma b t):Level (n+2))) + (tendsto_initializedInsertion_error n b) (fun _ => highDirection_norm (n+1) _) + simpa only [sub_add_cancel,zero_add] using he.add (tendsto_inner_low_high n b hb) + +theorem tendsto_initialized_address (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ⟪(initializedInsertion n b t:Level (n+2)),actualAddress n b t⟫_ℂ) + atTop (𝓝 0) := by + have he := tendsto_inner_error_unit + (fun t => (initializedInsertion n b t:Level (n+2))) + (fun t => lowVector (ordinaryDisplacement n b t)) (actualAddress n b) + (tendsto_initializedInsertion_error n b) (norm_actualAddress n b) + simpa only [sub_add_cancel,zero_add] using he.add (tendsto_inner_low_address n b hb) + +end SeedInitialization + +namespace SeedInitialization +open CoherentFock RootSpin PointedTree Complex +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem inner_lowVector_creation (d v : E) : + ⟪lowVector d,plusEmbedding (creationVacuum v)⟫_ℂ= + (-2*Real.exp (-2*‖d‖^2):ℂ)*⟪d,v⟫_ℂ := by + rw [lowVector,inner_rootY_WZ_creation] + have hi : ⟪(2:ℝ) • d,v⟫_ℂ=(2:ℂ)*⟪d,v⟫_ℂ := by + rw [← Complex.coe_smul,inner_smul_left,Complex.ofReal_ofNat,Complex.conj_ofNat] + have hn : ‖(2:ℝ) • d‖^2=4*‖d‖^2 := by + rw [norm_smul,Real.norm_of_nonneg (by norm_num : (0:ℝ)≤2)] + ring + rw [hi,hn,show -(4*‖d‖^2)/2= -2*‖d‖^2 by ring] + ring + +theorem tendsto_displacement_initialized (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ⟪ordinaryDisplacement (n+1) b t,initializedInsertion n b t⟫_ℂ) + atTop (𝓝 0) := by + have he := tendsto_inner_error_unit + (fun t => ordinaryDisplacement (n+1) b t) + (fun t => (2*b:ℝ) • highDirection (n+1) (gamma b t)) + (initializedInsertion n b) (tendsto_ordinaryDisplacement_error (n+1) b) + (norm_initializedInsertion n b) + have hh := Complex.continuous_conj.continuousAt.tendsto.comp (tendsto_initialized_high n b hb) + have hh' : Tendsto (fun t => ⟪(2*b:ℝ) • highDirection (n+1) (gamma b t), + initializedInsertion n b t⟫_ℂ) atTop (𝓝 0) := by + have h := hh.const_mul ((2*b:ℝ):ℂ) + simpa only [Function.comp_def,inner_conj_symm,map_zero,mul_zero, + ← Complex.coe_smul,inner_smul_left,Complex.conj_ofReal,Submodule.coe_inner] using h + simpa only [sub_add_cancel,zero_add] using he.add hh' + +theorem tendsto_low_rootShift (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ⟪lowVector (ordinaryDisplacement (n+1) b t), + (rootShift (n+2) (initializedInsertion n b t):Level (n+3))⟫_ℂ) + atTop (𝓝 0) := by + have hr := Real.continuous_exp.continuousAt.tendsto.comp + (((tendsto_norm_ordinaryDisplacement (n+1) b).pow 2).const_mul (-2)) + have hc := (Complex.continuous_ofReal.continuousAt.tendsto.comp hr).const_mul (-2) + have he (t : ℝ) : + ⟪lowVector (ordinaryDisplacement (n+1) b t), + (rootShift (n+2) (initializedInsertion n b t):Level (n+3))⟫_ℂ= + (-2*Real.exp (-2*‖ordinaryDisplacement (n+1) b t‖^2):ℂ)* + ⟪ordinaryDisplacement (n+1) b t,initializedInsertion n b t⟫_ℂ := + inner_lowVector_creation (ordinaryDisplacement (n+1) b t) (initializedInsertion n b t) + simp_rw [he] + simpa only [mul_zero,Function.comp_def] using + hc.mul (tendsto_displacement_initialized n b hb) + +theorem tendsto_initialized_rootShift (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ⟪(initializedInsertion (n+1) b t:Level (n+3)), + (rootShift (n+2) (initializedInsertion n b t):Level (n+3))⟫_ℂ) + atTop (𝓝 0) := by + have he := tendsto_inner_error_unit + (fun t => (initializedInsertion (n+1) b t:Level (n+3))) + (fun t => lowVector (ordinaryDisplacement (n+1) b t)) + (fun t => (rootShift (n+2) (initializedInsertion n b t):Level (n+3))) + (tendsto_initializedInsertion_error (n+1) b) + (fun t => (rootShift (n+2)).norm_map (initializedInsertion n b t) |>.trans + (norm_initializedInsertion n b t)) + simpa only [sub_add_cancel,zero_add] using he.add (tendsto_low_rootShift n b hb) + +theorem tendsto_initialized_treeEnergy (n : ℕ) (hn : 2 ≤ n) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => treeEnergy (n+2) (initializedInsertion n b t)) atTop (𝓝 0) := by + have hempty (t : ℝ) : centeredMap (empty (n+2)) (initializedInsertion n b t)= + initializedInsertion (n+1) b t := + ordinary_insertion_empty _ (n+2) (by simp [initializationWord]; omega) + have hi := Complex.continuous_re.continuousAt.tendsto.comp (tendsto_initialized_rootShift n b hb) + simpa only [treeEnergy,hempty,Submodule.coe_inner,Function.comp_def,Complex.zero_re] using hi + + + +theorem tendsto_initialization_ordinaryValue (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ordinaryValue (initializationWord (gamma b t) (delta t) (Real.pi/4))) + atTop (𝓝 0) := by + have he (n : ℕ) (hn : 2 ≤ n) (t : ℝ) : + treeEnergy (n+2) (initializedInsertion n b t)= + ordinaryValue (initializationWord (gamma b t) (delta t) (Real.pi/4)) := + ordinary_energy_stable _ (n+2) (by simp [initializationWord]; omega) + simpa only [he 2 (by omega)] using tendsto_initialized_treeEnergy 2 (by omega) b hb + +end SeedInitialization + +namespace ForwardControl +open Complex +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + + + +theorem scaled_residual_bound (r t ε η : ℝ) (hr : 0 < r) (v v' s w : H) + (hv : ‖v'-v+(2:ℂ) • s‖ ≤ r*ε) + (hs : ‖r⁻¹ • s-w‖ ≤ η) : + ‖(t/r) • (v'-v)-(-2*t) • w‖ ≤ |t| *(ε+2*η) := by + have he : (t/r) • (v'-v)-(-2*t) • w = + t • (r⁻¹ • (v'-v+(2:ℂ) • s)-(2:ℝ) • (r⁻¹ • s-w)) := by + simp only [two_smul,smul_add,smul_sub,smul_smul,div_eq_mul_inv] + module + rw [he,norm_smul,Real.norm_eq_abs] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg t) + have h1 : ‖r⁻¹ • (v'-v+(2:ℂ) • s)‖ ≤ ε := by + rw [norm_smul,Real.norm_eq_abs,abs_of_pos (inv_pos.mpr hr)] + calc + _ ≤ r⁻¹*(r*ε) := mul_le_mul_of_nonneg_left hv (le_of_lt (inv_pos.mpr hr)) + _ = ε := by field_simp + have h2 : ‖(2:ℝ) • (r⁻¹ • s-w)‖ ≤ 2*η := by + rw [norm_smul,Real.norm_of_nonneg (by norm_num : (0:ℝ)≤2)] + gcongr + exact (norm_sub_le _ _).trans (add_le_add h1 h2) + + + +theorem actual_scaled_flip_bound (U V : H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H) + (hZ : ∀x, ‖Z x‖ ≤ ‖x‖) (hanti : ∀x, Z (F x)=-F (Z x)) + (Ω o s w : H) (hx : U Ω=o+s) (r t ε η : ℝ) (hr : 0 < r) + (h1 : ‖V o-o‖ ≤ r*ε) (h2 : ‖V s-F s‖ ≤ r*ε) + (h3 : ‖V (Z o)-Z o‖ ≤ r*ε) (h4 : ‖V (Z s)-F (Z s)‖ ≤ r*ε) + (ht : ‖r⁻¹ • U.symm (Z s)-w‖ ≤ η) : + ‖(t/r) • (U.symm (V.symm (Z (V (U Ω))))-U.symm (Z (U Ω)))- + (-2*t) • w‖ ≤ |t| *(4*ε+2*η) := by + apply scaled_residual_bound r t (4*ε) η hr _ _ _ _ _ ht + have hf := actual_flip_change U V Z F hZ hanti Ω o s hx + linarith + +end ForwardControl + +namespace CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem WZ_difference_le (d e : E) (x : SpinSpace E) : + ‖WZ d x-WZ e x‖ ≤ ‖WZ (d-e) x-x‖+‖d-e‖*‖e‖*‖x‖ := by + have he : phase e (d-e) • (WZ d x-WZ e x)= + WZ e (WZ (d-e) x-x)+(1-phase e (d-e)) • WZ e x := by + have h := congrArg (fun T : SpinSpace E →L[ℂ] SpinSpace E => T x) (WZ_mul e (d-e)) + simp only [ContinuousLinearMap.comp_apply,smul_apply,show e+(d-e)=d by abel] at h + rw [map_sub,h] + module + calc + _ = ‖phase e (d-e) • (WZ d x-WZ e x)‖ := by rw [norm_smul,norm_phase,one_mul] + _ ≤ ‖WZ e (WZ (d-e) x-x)‖+‖(1-phase e (d-e)) • WZ e x‖ := by + rw [he]; exact norm_add_le _ _ + _ = ‖WZ (d-e) x-x‖+‖phase e (d-e)-1‖*‖x‖ := by + rw [norm_smul,norm_WZ,norm_WZ,norm_sub_rev (1:ℂ)] + _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_right (phase_sub_one_le e (d-e)) (norm_nonneg x)] + +omit [InnerProductSpace ℂ E] in +theorem tailBound_le_second (x : PreSpace E) : tailBound x ≤ secondTailBound x := by + classical + simp only [tailBound,secondTailBound,Finsupp.sum] + apply Finset.sum_le_sum + intro d hd + apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) + nlinarith [sq_nonneg ‖d‖] + +theorem WZ_spinCoe_sub_le (h : E) (x : PreSpin E) : + ‖WZ h (spinCoe x)-spinCoe x‖ ≤ ‖h‖*spinBound x := by + calc + _ ≤ ∑ i, ‖(WZ h (spinCoe x)-spinCoe x) i‖ := norm_spin_le_sum _ + _ ≤ ∑ i, ‖h‖*secondTailBound (x i) := by + apply Finset.sum_le_sum + intro i hi + simp only [PiLp.sub_apply,WZ_apply,spinCoe_apply] + have hb (h : E) := (W_coe_sub_le h (x i)).trans + (mul_le_mul_of_nonneg_left (tailBound_le_second (x i)) (norm_nonneg h)) + split_ifs + · exact hb h + · simpa only [norm_neg] using hb (-h) + _ = _ := by simp only [spinBound,Finset.mul_sum] + + + +theorem WZ_spinCoe_difference (d e : E) (x : PreSpin E) {A B C : ℝ} + (hx : SpinRadiusLE x B) (hB : 0 ≤ B) (hA : spinMass x ≤ A) (he : ‖e‖ ≤ C) : + ‖WZ d (spinCoe x)-WZ e (spinCoe x)‖ ≤ ‖d-e‖*(A*(1+2*B+12*B^2)+C*A) := by + have hM : ‖spinCoe x‖ ≤ A := (norm_spinCoe_le_mass x).trans hA + have hN : 0 ≤ A := (spinMass_nonneg x).trans hA + have hC : 0 ≤ C := (norm_nonneg e).trans he + calc + _ ≤ ‖WZ (d-e) (spinCoe x)-spinCoe x‖+‖d-e‖*‖e‖*‖spinCoe x‖ := WZ_difference_le _ _ _ + _ ≤ ‖d-e‖*spinBound x+‖d-e‖*C*A := by + gcongr + exact WZ_spinCoe_sub_le _ _ + _ ≤ ‖d-e‖*(A*(1+2*B+12*B^2))+‖d-e‖*C*A := by + gcongr + exact (spinBound_le_mass x hB hx).trans (by gcongr) + _ = _ := by ring + +end CoherentFock + +namespace ForwardControl +open Complex +variable {H α : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] {l : Filter α} + +theorem actual_scaled_flip_tendsto (U V : α → H ≃ₗᵢ[ℂ] H) (Z F : H →L[ℂ] H) + (hZ : ∀x, ‖Z x‖ ≤ ‖x‖) (hanti : ∀x, Z (F x)=-F (Z x)) + (Ω : H) (o s w : α → H) (hx : ∀ a, U a Ω=o a+s a) (r ε η : α → ℝ) (t : ℝ) + (hr : ∀ᶠ a in l, 0 < r a) + (he : Tendsto ε l (𝓝 0)) (hh : Tendsto η l (𝓝 0)) + (h1 : ∀ᶠ a in l, ‖V a (o a)-o a‖ ≤ r a*ε a) + (h2 : ∀ᶠ a in l, ‖V a (s a)-F (s a)‖ ≤ r a*ε a) + (h3 : ∀ᶠ a in l, ‖V a (Z (o a))-Z (o a)‖ ≤ r a*ε a) + (h4 : ∀ᶠ a in l, ‖V a (Z (s a))-F (Z (s a))‖ ≤ r a*ε a) + (ht : ∀ᶠ a in l, ‖(r a)⁻¹ • (U a).symm (Z (s a))-w a‖ ≤ η a) : + Tendsto (fun a => ‖(t/r a) • ((U a).symm ((V a).symm (Z (V a (U a Ω))))- + (U a).symm (Z (U a Ω)))-(-2*t) • w a‖) l (𝓝 0) := by + apply squeeze_zero' (Filter.Eventually.of_forall fun _ => norm_nonneg _) ?_ + (by simpa only [mul_zero,add_zero] using ((he.const_mul 4).add (hh.const_mul 2)).const_mul |t|) + filter_upwards [hr,h1,h2,h3,h4,ht] with a ha h1 h2 h3 h4 ht + exact actual_scaled_flip_bound (U a) (V a) Z F hZ hanti Ω (o a) (s a) (w a) + (hx a) (r a) t (ε a) (η a) ha h1 h2 h3 h4 ht + +end ForwardControl + +namespace CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + + + +theorem echo_ordinary_error (t r : ℝ) (v v' : E) (V₁ V₂ : SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E) + (x : SpinSpace E) : + ‖(phase ((t/r) • v') (-(t/r) • v))⁻¹ • + V₂ (WZ ((t/r) • v') (V₁ (WZ (-(t/r) • v) x)))-WZ ((t/r) • (v'-v)) x‖ ≤ + ‖V₁ (WZ (-(t/r) • v) x)-WZ (-(t/r) • v) x‖+ + ‖V₂ (WZ ((t/r) • v') (V₁ (WZ (-(t/r) • v) x)))- + WZ ((t/r) • v') (V₁ (WZ (-(t/r) • v) x))‖ := by + rw [← corrected_echo t r v v' x,← smul_sub,norm_smul,norm_inv,norm_phase,inv_one,one_mul] + have he : V₂ (WZ ((t/r) • v') (V₁ (WZ (-(t/r) • v) x)))- + WZ ((t/r) • v') (WZ (-(t/r) • v) x) = + (V₂ (WZ ((t/r) • v') (V₁ (WZ (-(t/r) • v) x)))- + WZ ((t/r) • v') (V₁ (WZ (-(t/r) • v) x)))+ + (WZ ((t/r) • v') (V₁ (WZ (-(t/r) • v) x))- + WZ ((t/r) • v') (WZ (-(t/r) • v) x)) := by abel + rw [he] + exact (norm_add_le _ _).trans (by rw [WZ_error]; exact le_of_eq (add_comm _ _)) + + + +theorem tendsto_moving_corrected_echo {α : Type*} {l : Filter α} + (t : ℝ) (r : α → ℝ) (v v' w : α → E) (x : α → PreSpin E) (A B : ℝ) + (hB : 0 ≤ B) (hx : ∀ᶠ a in l, SpinRadiusLE (x a) B ∧ spinMass (x a)≤A) + (hw : ∀ a, ‖w a‖=1) + (hg : Tendsto (fun a => ‖(t/r a) • (v' a-v a)-(-2*t) • w a‖) l (𝓝 0)) : + Tendsto (fun a => ‖(phase ((t/r a) • v' a) (-(t/r a) • v a))⁻¹ • + WZ ((t/r a) • v' a) (WZ (-(t/r a) • v a) (spinCoe (x a)))- + WZ ((-2*t) • w a) (spinCoe (x a))‖) l (𝓝 0) := by + simp_rw [corrected_echo] + apply squeeze_zero' (Filter.Eventually.of_forall fun _ => norm_nonneg _) ?_ + (by simpa only [zero_mul] using hg.mul_const (A*(1+2*B+12*B^2)+|(-2*t)| *A)) + filter_upwards [hx] with a ha + exact WZ_spinCoe_difference _ _ _ ha.1 hB ha.2 + (by rw [norm_smul,hw,mul_one,Real.norm_eq_abs]) + +end CoherentFock + +namespace CoherentFock +open PointedTree Complex +variable {E F : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + [SeminormedAddCommGroup F] [InnerProductSpace ℂ F] +variable {ι κ α : Type*} [Fintype ι] [Fintype κ] {l : Filter α} + + + +def spinPacket (a : ι → Fin 2 → ℂ) (d : ι → E) : SpinSpace E := + ∑ i, spinPair (a i 0 • coherent (d i)) (a i 1 • coherent (d i)) + +theorem inner_spinPacket (a : ι → Fin 2 → ℂ) (b : κ → Fin 2 → ℂ) + (d : ι → E) (e : κ → E) : + ⟪spinPacket a d,spinPacket b e⟫_ℂ= + ∑ i, ∑ j, (conj (a i 0)*b j 0+conj (a i 1)*b j 1)*kernel (d i) (e j) := by + simp only [spinPacket,sum_inner,inner_sum,inner_spinPair,inner_smul_left,inner_smul_right, + inner_coherent] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i hi + apply Finset.sum_congr rfl + intro j hj + ring + + + +theorem inner_spinPacket_creation (a : ι → Fin 2 → ℂ) (d : ι → E) (h : E) : + ⟪spinPacket a d,plusEmbedding (creationVacuum h)⟫_ℂ= + ∑ i, (-I)*(conj (a i 0)+conj (a i 1))*spinCoefficient* + (Real.exp (-‖d i‖^2/2):ℂ)*⟪d i,h⟫_ℂ := by + simp only [spinPacket,sum_inner,plusEmbedding_pair,inner_spinPair,creationVacuum, + inner_smul_left,inner_smul_right,inner_coherent_oneParticle] + apply Finset.sum_congr rfl + intro i hi + ring + + +theorem tendsto_norm_sq_of_inner (d : α → E) (d₀ : F) + (h : Tendsto (fun t => ⟪d t,d t⟫_ℂ) l (𝓝 ⟪d₀,d₀⟫_ℂ)) : + Tendsto (fun t => ‖d t‖^2) l (𝓝 (‖d₀‖^2)) := by + have hn (x : E) : (⟪x,x⟫_ℂ).re=‖x‖^2 := inner_self_eq_norm_sq (𝕜 := ℂ) x + have hn₀ : (⟪d₀,d₀⟫_ℂ).re=‖d₀‖^2 := inner_self_eq_norm_sq (𝕜 := ℂ) d₀ + simpa only [Function.comp_def,hn,hn₀] using + Complex.continuous_re.continuousAt.tendsto.comp h + +theorem tendsto_kernel_of_gram (d e : α → E) (d₀ e₀ : F) + (hd : Tendsto (fun t => ⟪d t,d t⟫_ℂ) l (𝓝 ⟪d₀,d₀⟫_ℂ)) + (he : Tendsto (fun t => ⟪e t,e t⟫_ℂ) l (𝓝 ⟪e₀,e₀⟫_ℂ)) + (hde : Tendsto (fun t => ⟪d t,e t⟫_ℂ) l (𝓝 ⟪d₀,e₀⟫_ℂ)) : + Tendsto (fun t => kernel (d t) (e t)) l (𝓝 (kernel d₀ e₀)) := by + have hd' := Complex.continuous_ofReal.continuousAt.tendsto.comp + ((tendsto_norm_sq_of_inner d d₀ hd).neg.div_const 2) + have he' := Complex.continuous_ofReal.continuousAt.tendsto.comp + ((tendsto_norm_sq_of_inner e e₀ he).neg.div_const 2) + exact Complex.continuous_exp.continuousAt.tendsto.comp ((hd'.add hde).add he') + + + +theorem tendsto_inner_spinPacket (a : α → ι → Fin 2 → ℂ) (b : α → κ → Fin 2 → ℂ) + (d : α → ι → E) (e : α → κ → E) (a₀ : ι → Fin 2 → ℂ) (b₀ : κ → Fin 2 → ℂ) + (d₀ : ι → F) (e₀ : κ → F) + (ha : ∀ i q, Tendsto (fun t => a t i q) l (𝓝 (a₀ i q))) + (hb : ∀ j q, Tendsto (fun t => b t j q) l (𝓝 (b₀ j q))) + (hd : ∀ i, Tendsto (fun t => ⟪d t i,d t i⟫_ℂ) l (𝓝 ⟪d₀ i,d₀ i⟫_ℂ)) + (he : ∀ j, Tendsto (fun t => ⟪e t j,e t j⟫_ℂ) l (𝓝 ⟪e₀ j,e₀ j⟫_ℂ)) + (hde : ∀ i j, Tendsto (fun t => ⟪d t i,e t j⟫_ℂ) l (𝓝 ⟪d₀ i,e₀ j⟫_ℂ)) : + Tendsto (fun t => ⟪spinPacket (a t) (d t),spinPacket (b t) (e t)⟫_ℂ) + l (𝓝 ⟪spinPacket a₀ d₀,spinPacket b₀ e₀⟫_ℂ) := by + simp_rw [inner_spinPacket] + apply tendsto_finsetSum + intro i hi + apply tendsto_finsetSum + intro j hj + have hc0 := ((Complex.continuous_conj.continuousAt.tendsto.comp (ha i 0)).mul (hb j 0)) + have hc1 := ((Complex.continuous_conj.continuousAt.tendsto.comp (ha i 1)).mul (hb j 1)) + exact (hc0.add hc1).mul (tendsto_kernel_of_gram _ _ _ _ (hd i) (he j) (hde i j)) + + + +theorem tendsto_inner_spinPacket_creation (a : α → ι → Fin 2 → ℂ) (d : α → ι → E) + (h : α → E) (a₀ : ι → Fin 2 → ℂ) (d₀ : ι → F) (h₀ : F) + (ha : ∀ i q, Tendsto (fun t => a t i q) l (𝓝 (a₀ i q))) + (hd : ∀ i, Tendsto (fun t => ⟪d t i,d t i⟫_ℂ) l (𝓝 ⟪d₀ i,d₀ i⟫_ℂ)) + (hdh : ∀ i, Tendsto (fun t => ⟪d t i,h t⟫_ℂ) l (𝓝 ⟪d₀ i,h₀⟫_ℂ)) : + Tendsto (fun t => ⟪spinPacket (a t) (d t),plusEmbedding (creationVacuum (h t))⟫_ℂ) + l (𝓝 ⟪spinPacket a₀ d₀,plusEmbedding (creationVacuum h₀)⟫_ℂ) := by + simp_rw [inner_spinPacket_creation] + apply tendsto_finsetSum + intro i hi + have hc := ((Complex.continuous_conj.continuousAt.tendsto.comp (ha i 0)).add + (Complex.continuous_conj.continuousAt.tendsto.comp (ha i 1))).const_mul (-I) + have hnorm := Real.continuous_exp.continuousAt.tendsto.comp + ((tendsto_norm_sq_of_inner _ _ (hd i)).neg.div_const 2) + exact (((hc.mul_const spinCoefficient).mul + (Complex.continuous_ofReal.continuousAt.tendsto.comp hnorm)).mul (hdh i)) + +end CoherentFock + +namespace CoherentFock +variable {E X : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup X] [NormedSpace ℝ X] {x : X} + + + +theorem analyticAt_norm_sq_of_inner (d : X → E) + (h : AnalyticAt ℝ (fun t => ⟪d t,d t⟫_ℂ) x) : + AnalyticAt ℝ (fun t => ‖d t‖^2) x := by + have hr : AnalyticAt ℝ (fun t => (⟪d t,d t⟫_ℂ).re) x := + (Complex.reCLM.analyticAt _).comp h + convert hr using 1 + ext t + exact (inner_self_eq_norm_sq (𝕜 := ℂ) (d t)).symm + +theorem analyticAt_kernel_of_gram (d e : X → E) + (hd : AnalyticAt ℝ (fun t => ⟪d t,d t⟫_ℂ) x) + (he : AnalyticAt ℝ (fun t => ⟪e t,e t⟫_ℂ) x) + (hde : AnalyticAt ℝ (fun t => ⟪d t,e t⟫_ℂ) x) : + AnalyticAt ℝ (fun t => kernel (d t) (e t)) x := by + have hd' : AnalyticAt ℝ (fun t => ((-‖d t‖^2/2:ℝ):ℂ)) x := + (Complex.ofRealCLM.analyticAt _).comp (analyticAt_norm_sq_of_inner d hd).neg.div_const + have he' : AnalyticAt ℝ (fun t => ((-‖e t‖^2/2:ℝ):ℂ)) x := + (Complex.ofRealCLM.analyticAt _).comp (analyticAt_norm_sq_of_inner e he).neg.div_const + exact (analyticAt_cexp.restrictScalars (𝕜 := ℝ)).comp ((hd'.add hde).add he') + +theorem analyticAt_phase_of_gram (d e : X → E) + (hde : AnalyticAt ℝ (fun t => ⟪d t,e t⟫_ℂ) x) : + AnalyticAt ℝ (fun t => phase (d t) (e t)) x := by + have him : AnalyticAt ℝ (fun t => (⟪d t,e t⟫_ℂ).im) x := + (Complex.imCLM.analyticAt _).comp hde + have hc : AnalyticAt ℝ (fun t => ((⟪d t,e t⟫_ℂ).im:ℂ)) x := + (Complex.ofRealCLM.analyticAt _).comp him + simpa only [phase,Complex.ofReal_neg,Function.comp_def,Pi.neg_apply,Pi.mul_apply] using + (analyticAt_cexp.restrictScalars (𝕜 := ℝ)).comp (hc.neg.mul (show AnalyticAt ℝ (fun _ : X => (Complex.I : ℂ)) x from analyticAt_const)) + + + +theorem analyticAt_inner_spinPacket {ι κ : Type*} [Fintype ι] [Fintype κ] + (a : X → ι → Fin 2 → ℂ) (b : X → κ → Fin 2 → ℂ) + (d : X → ι → E) (e : X → κ → E) + (ha : ∀i q, AnalyticAt ℝ (fun t => a t i q) x) + (hb : ∀j q, AnalyticAt ℝ (fun t => b t j q) x) + (hd : ∀i, AnalyticAt ℝ (fun t => ⟪d t i,d t i⟫_ℂ) x) + (he : ∀j, AnalyticAt ℝ (fun t => ⟪e t j,e t j⟫_ℂ) x) + (hde : ∀i j, AnalyticAt ℝ (fun t => ⟪d t i,e t j⟫_ℂ) x) : + AnalyticAt ℝ (fun t => ⟪spinPacket (a t) (d t),spinPacket (b t) (e t)⟫_ℂ) x := by + simp_rw [inner_spinPacket] + apply Finset.analyticAt_fun_sum + intro i hi + apply Finset.analyticAt_fun_sum + intro j hj + have h0 : AnalyticAt ℝ (fun t => conj (a t i 0)) x := + (Complex.conjCLE.toContinuousLinearMap.analyticAt _).comp (ha i 0) + have h1 : AnalyticAt ℝ (fun t => conj (a t i 1)) x := + (Complex.conjCLE.toContinuousLinearMap.analyticAt _).comp (ha i 1) + exact ((h0.mul (hb j 0)).add (h1.mul (hb j 1))).mul + (analyticAt_kernel_of_gram _ _ (hd i) (he j) (hde i j)) + +end CoherentFock + +namespace CoherentFock +open PointedTree Complex +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + {ι κ : Type*} [Fintype ι] [Fintype κ] + +@[simp] theorem spinPacket_apply (a : ι → Fin 2 → ℂ) (d : ι → E) (q : Fin 2) : + spinPacket a d q=∑i, a i q • coherent (d i) := by + fin_cases q <;> simp [spinPacket] + +theorem spinPacket_smul (z : ℂ) (a : ι → Fin 2 → ℂ) (d : ι → E) : + z • spinPacket a d=spinPacket (fun i q => z*a i q) d := by + ext q + simp [Finset.smul_sum,mul_smul] + +theorem spinPacket_sum (a : ι → Fin 2 → ℂ) (b : κ → Fin 2 → ℂ) + (d : ι → E) (e : κ → E) : + spinPacket a d+spinPacket b e=spinPacket (Sum.elim a b) (Sum.elim d e) := by + ext q + simp [Fintype.sum_sum_type] + +theorem act_spinPacket (A : Matrix (Fin 2) (Fin 2) ℂ) + (a : ι → Fin 2 → ℂ) (d : ι → E) : + SpinOperators.act A (spinPacket a d)=spinPacket (fun i q => ∑j, A q j*a i j) d := by + ext q + simp only [SpinOperators.act_apply,spinPacket_apply,Finset.sum_smul,Finset.smul_sum,mul_smul] + exact Finset.sum_comm + +theorem WZ_spinPacket (h : E) (a : ι → Fin 2 → ℂ) (d : ι → E) : + WZ h (spinPacket a d)=spinPacket + (fun p : ι×Fin 2 => fun q => if q=p.2 then + phase (if p.2=0 then h else -h) (d p.1)*a p.1 q else 0) + (fun p : ι×Fin 2 => (if p.2=0 then h else -h)+d p.1) := by + ext q + fin_cases q <;> + simp [WZ_apply,spinPacket_apply,Fintype.sum_prod_type, + map_sum,map_smul,W_coherent,smul_smul,mul_comm] + +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/MaskedDisorder.lean b/lean/OAI/Probability/ParisiFinite/MaskedDisorder.lean new file mode 100644 index 0000000000000000000000000000000000000000..713be5d20f9beba510f04dbcfa2b96543f67eb1e --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/MaskedDisorder.lean @@ -0,0 +1,715 @@ +import Mathlib +import OAI.Probability.ParisiFinite.PhysicalGate + +namespace OAI + +/-! Masked Disorder. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA.Locality + +variable {n : ℕ} + +def maskedDisorder (J : Disorder n) (E : Finset (Edge n)) : Disorder n := + fun e => if e ∈ E then J e else 0 + +def maskedCost (J : Disorder n) (E : Finset (Edge n)) : Operator n := + cost n (maskedDisorder J E) + +@[simp] theorem maskedCost_univ (J : Disorder n) : maskedCost J Finset.univ=cost n J := by + unfold maskedCost + congr 1 + funext e + exact ite_eq_left (Finset.mem_univ e) + +@[simp] theorem maskedCost_empty (J : Disorder n) : maskedCost J ∅=0 := by + simp [maskedCost,maskedDisorder,cost] + +theorem maskedCost_sum (J : Disorder n) (E : Finset (Edge n)) : + maskedCost J E = ((Real.sqrt (n : ℝ))⁻¹ : ℂ) • + ∑e∈E, (J e : ℂ) • (pauliZ e.1.1*pauliZ e.1.2) := by + simp [maskedCost,cost,maskedDisorder,ite_smul] + +theorem maskedCost_hermitian (J : Disorder n) (E : Finset (Edge n)) : + (maskedCost J E).IsHermitian := cost_hermitian _ _ + +theorem maskedCost_commute (J K : Disorder n) (E F : Finset (Edge n)) : + Commute (maskedCost J E) (maskedCost K F) := by + simp only [maskedCost,cost_eq_diagonal] + exact Matrix.commute_diagonal _ _ + +def touches (S : Finset (Fin n)) (e : Edge n) : Prop := e.1.1 ∈ S ∨ e.1.2 ∈ S + +instance (S : Finset (Fin n)) (e : Edge n) : Decidable (touches S e) := + inferInstanceAs (Decidable (_ ∨ _)) + +def activeEdges (E : Finset (Edge n)) (S : Finset (Fin n)) : Finset (Edge n) := + E.filter (touches S) + +def inactiveEdges (E : Finset (Edge n)) (S : Finset (Fin n)) : Finset (Edge n) := + E.filter (fun e => ¬touches S e) + +def neighborhood (E : Finset (Edge n)) (S : Finset (Fin n)) : Finset (Fin n) := + S ∪ (activeEdges E S).biUnion (fun e => {e.1.1,e.1.2}) + +theorem subset_neighborhood (E : Finset (Edge n)) (S : Finset (Fin n)) : + S ⊆ neighborhood E S := Finset.subset_union_left + +theorem active_endpoints {E : Finset (Edge n)} {S : Finset (Fin n)} {e : Edge n} + (he : e∈activeEdges E S) : + e.1.1∈neighborhood E S ∧ e.1.2∈neighborhood E S := by + constructor <;> apply Finset.mem_union.mpr <;> right <;> + apply Finset.mem_biUnion.mpr <;> exact ⟨e,he,by simp⟩ + +theorem maskedCost_active_supported (J : Disorder n) (E : Finset (Edge n)) + (S : Finset (Fin n)) : IsSupported (neighborhood E S) (maskedCost J (activeEdges E S)) := by + rw [maskedCost_sum] + apply IsSupported.smul + apply supported_finsetSum + intro e he + exact ((supported_pauliZ (active_endpoints he).1).mul + (supported_pauliZ (active_endpoints he).2)).smul _ + +theorem commute_maskedCost_inactive {S : Finset (Fin n)} {A : Operator n} + (hA : IsSupported S A) (J : Disorder n) (E : Finset (Edge n)) : + Commute A (maskedCost J (inactiveEdges E S)) := by + rw [maskedCost_sum] + apply Commute.smul_right + apply Commute.sum_right + intro e he + have ht : ¬touches S e := (Finset.mem_filter.mp he).2 + exact ((hA e.1.1 (fun h => ht (Or.inl h))).2.mul_right + (hA e.1.2 (fun h => ht (Or.inr h))).2).smul_right _ + +theorem maskedCost_split (J : Disorder n) (E : Finset (Edge n)) (S : Finset (Fin n)) : + maskedCost J E = maskedCost J (inactiveEdges E S)+maskedCost J (activeEdges E S) := by + simp only [maskedCost_sum,←smul_add] + congr 1 + rw [add_comm] + exact (Finset.sum_filter_add_sum_filter_not E (touches S) _).symm + +theorem evolution_add_of_commute (t : ℝ) {A B : Operator n} (h : Commute A B) : + evolution t (A+B)=evolution t A*evolution t B := by + unfold evolution + rw [smul_add] + exact Matrix.exp_add_of_commute _ _ ((h.smul_left _).smul_right _) + +theorem unitary_conjugate_eq_self (U A : Operator n) (hU : U∈unitary (Operator n)) + (h : Commute A U) : Uᴴ*A*U=A := by + have hl : Uᴴ*U=1 := Unitary.star_mul_self_of_mem hU + rw [mul_assoc,h.eq,←mul_assoc,hl,one_mul] + + + +theorem cost_conjugate_local {S : Finset (Fin n)} {A : Operator n} + (hA : IsSupported S A) (J : Disorder n) (E : Finset (Edge n)) (t : ℝ) : + (evolution t (maskedCost J E))ᴴ*A*evolution t (maskedCost J E) = + (evolution t (maskedCost J (activeEdges E S)))ᴴ*A* + evolution t (maskedCost J (activeEdges E S)) := by + have hc := maskedCost_commute J J (inactiveEdges E S) (activeEdges E S) + have hu := evolution_unitary t _ (maskedCost_hermitian J (inactiveEdges E S)) + have ha : Commute A (evolution t (maskedCost J (inactiveEdges E S))) := + ((commute_maskedCost_inactive hA J E).smul_right _).exp_right + conv_lhs => rw [maskedCost_split J E S, evolution_add_of_commute t hc] + rw [Matrix.conjTranspose_mul] + calc + _ = (evolution t (maskedCost J (activeEdges E S)))ᴴ * + ((evolution t (maskedCost J (inactiveEdges E S)))ᴴ*A* + evolution t (maskedCost J (inactiveEdges E S))) * + evolution t (maskedCost J (activeEdges E S)) := by noncomm_ring + _ = _ := by rw [unitary_conjugate_eq_self _ _ hu ha] + + +theorem IsSupported.cost_conjugate {S : Finset (Fin n)} {A : Operator n} + (hA : IsSupported S A) (J : Disorder n) (E : Finset (Edge n)) (t : ℝ) : + IsSupported (neighborhood E S) + ((evolution t (maskedCost J E))ᴴ*A*evolution t (maskedCost J E)) := by + rw [cost_conjugate_local hA] + exact (((maskedCost_active_supported J E S).evolve t).adjoint.mul + (hA.mono (subset_neighborhood E S))).mul + ((maskedCost_active_supported J E S).evolve t) + +end SKQAOA.Locality + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA.Locality + +variable {n : ℕ} + +theorem activeEdges_mono {E F : Finset (Edge n)} {S T : Finset (Fin n)} + (hEF : E⊆F) (hST : S⊆T) : activeEdges E S⊆activeEdges F T := by + intro e he + rcases Finset.mem_filter.mp he with ⟨he,ht⟩ + refine Finset.mem_filter.mpr ⟨hEF he,?_⟩ + exact ht.elim (fun h => Or.inl (hST h)) (fun h => Or.inr (hST h)) + +theorem neighborhood_mono {E F : Finset (Edge n)} {S T : Finset (Fin n)} + (hEF : E⊆F) (hST : S⊆T) : neighborhood E S⊆neighborhood F T := by + apply Finset.union_subset_union hST + intro i hi + rcases Finset.mem_biUnion.mp hi with ⟨e,he,hi⟩ + exact Finset.mem_biUnion.mpr ⟨e,activeEdges_mono hEF hST he,hi⟩ + + + +def relevantEdges (E : Finset (Edge n)) : + List PointedTree.Gate → Finset (Fin n) → Finset (Edge n) + | [], _ => ∅ + | .mixer _ :: w, S => relevantEdges E w S + | .cost _ :: w, S => activeEdges E S ∪ relevantEdges E w (neighborhood E S) + +theorem relevantEdges_subset (E : Finset (Edge n)) (w : List PointedTree.Gate) + (S : Finset (Fin n)) : relevantEdges E w S⊆E := by + induction w generalizing S with + | nil => exact Finset.empty_subset E + | cons g w ih => + cases g with + | mixer t => exact ih S + | cost t => exact Finset.union_subset (Finset.filter_subset _ _) (ih _) + +theorem relevantEdges_mono {E F : Finset (Edge n)} {S T : Finset (Fin n)} + (hEF : E⊆F) (hST : S⊆T) (w : List PointedTree.Gate) : + relevantEdges E w S⊆relevantEdges F w T := by + induction w generalizing S T with + | nil => exact Finset.Subset.refl _ + | cons g w ih => + cases g with + | mixer t => exact ih hST + | cost t => + exact Finset.union_subset_union (activeEdges_mono hEF hST) + (ih (neighborhood_mono hEF hST)) + + +def wordConjugate (J : Disorder n) (E : Finset (Edge n)) + (w : List PointedTree.Gate) (A : Operator n) : Operator n := + (physicalWord n (maskedDisorder J E) w)ᴴ*A*physicalWord n (maskedDisorder J E) w + +@[simp] theorem wordConjugate_nil (J : Disorder n) (E : Finset (Edge n)) + (A : Operator n) : wordConjugate J E [] A=A := by simp [wordConjugate] + +theorem wordConjugate_cons (J : Disorder n) (E : Finset (Edge n)) + (g : PointedTree.Gate) (w : List PointedTree.Gate) (A : Operator n) : + wordConjugate J E (g::w) A = wordConjugate J E w + ((physicalGate n (maskedDisorder J E) g)ᴴ*A*physicalGate n (maskedDisorder J E) g) := by + simp only [wordConjugate,physicalWord_cons,Matrix.conjTranspose_mul] + noncomm_ring + +@[simp] theorem wordConjugate_cost (J : Disorder n) (E : Finset (Edge n)) + (t : ℝ) (w : List PointedTree.Gate) (A : Operator n) : + wordConjugate J E (.cost t::w) A = wordConjugate J E w + ((evolution t (maskedCost J E))ᴴ*A*evolution t (maskedCost J E)) := + wordConjugate_cons J E _ w A + +@[simp] theorem wordConjugate_mixer (J : Disorder n) (E : Finset (Edge n)) + (t : ℝ) (w : List PointedTree.Gate) (A : Operator n) : + wordConjugate J E (.mixer t::w) A = wordConjugate J E w + ((evolution t (mixer n))ᴴ*A*evolution t (mixer n)) := + wordConjugate_cons J E _ w A + + +theorem wordConjugate_eq_of_relevant_subset (J : Disorder n) + {E F : Finset (Edge n)} (hFE : F⊆E) (w : List PointedTree.Gate) + {S : Finset (Fin n)} {A : Operator n} (hA : IsSupported S A) + (hrel : relevantEdges E w S⊆F) : + wordConjugate J E w A=wordConjugate J F w A := by + induction w generalizing S A with + | nil => simp + | cons g w ih => + cases g with + | mixer t => + simp only [wordConjugate_mixer] + exact ih (hA.mixer_conjugate t) hrel + | cost t => + have ha : activeEdges E S⊆F := Finset.union_subset_iff.mp hrel |>.1 + have hr : relevantEdges E w (neighborhood E S)⊆F := + Finset.union_subset_iff.mp hrel |>.2 + have heq : activeEdges E S=activeEdges F S := by + apply Finset.Subset.antisymm + · intro e he + exact Finset.mem_filter.mpr ⟨ha he,(Finset.mem_filter.mp he).2⟩ + · exact activeEdges_mono hFE (Finset.Subset.refl _) + have heqA : (evolution t (maskedCost J E))ᴴ*A*evolution t (maskedCost J E) = + (evolution t (maskedCost J F))ᴴ*A*evolution t (maskedCost J F) := by + rw [cost_conjugate_local hA J E,cost_conjugate_local hA J F,heq] + simp only [wordConjugate_cost] + rw [←heqA] + exact ih (hA.cost_conjugate J E t) hr + + + +theorem wordConjugate_insert_irrelevant (J : Disorder n) + {H M : Finset (Edge n)} {e : Edge n} (he : e∈H) (hM : M⊆H) + (w : List PointedTree.Gate) {S : Finset (Fin n)} {A : Operator n} + (hA : IsSupported S A) (hirr : e∉relevantEdges H w S) : + wordConjugate J (insert e M) w A=wordConjugate J M w A := by + apply wordConjugate_eq_of_relevant_subset J (Finset.subset_insert _ _) w hA + intro f hf + have hf' := relevantEdges_subset (insert e M) w S hf + rcases Finset.mem_insert.mp hf' with rfl|hf' + · exact False.elim (hirr (relevantEdges_mono (Finset.insert_subset he hM) + (Finset.Subset.refl S) w hf)) + · exact hf' + +end SKQAOA.Locality + + + +open scoped BigOperators + +namespace FiniteEdgeExpansion + +variable {E R A : Type*} [DecidableEq E] [CommRing R] + + +def mixedDifference (S : Finset E) (F : Finset E → R) : R := + ∑ T ∈ S.powerset, (-1 : R)^T.card * F (S \ T) + +@[simp] theorem mixedDifference_empty (F : Finset E → R) : + mixedDifference ∅ F = F ∅ := by simp [mixedDifference] + + + +theorem mixedDifference_insert (S : Finset E) (e : E) (he : e ∉ S) + (F : Finset E → R) : + mixedDifference (insert e S) F = + mixedDifference S (fun T => F (insert e T)) - mixedDifference S F := by + unfold mixedDifference + rw [Finset.sum_powerset_insert he] + have heT (T : Finset E) (hT : T ∈ S.powerset) : e ∉ T := by + intro h + exact he (Finset.mem_powerset.mp hT h) + have hfirst (T : Finset E) (hT : T ∈ S.powerset) : + insert e S \ T = insert e (S \ T) := by + ext x + by_cases hx : x=e <;> simp [hx, heT T hT] + have hsecond (T : Finset E) (hT : T ∈ S.powerset) : + insert e S \ insert e T = S \ T := by + ext x + by_cases hx : x=e <;> simp [hx,he] + have h₁ : (∑ T ∈ S.powerset, (-1:R)^T.card * F (insert e S \ T)) = + ∑ T ∈ S.powerset, (-1:R)^T.card * F (insert e (S \ T)) := by + apply Finset.sum_congr rfl + intro T hT + rw [hfirst T hT] + have h₂ : (∑ T ∈ S.powerset, (-1:R)^(insert e T).card * F (insert e S \ insert e T)) = + -(∑ T ∈ S.powerset, (-1:R)^T.card * F (S \ T)) := by + rw [←Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro T hT + rw [Finset.card_insert_of_notMem (heT T hT), hsecond T hT, pow_succ] + ring + rw [h₁,h₂] + ring + +theorem mixedDifference_eq_zero_of_irrelevant {S : Finset E} {e : E} + (he : e ∈ S) (F : Finset E → R) + (hF : ∀ T ⊆ S.erase e, F (insert e T) = F T) : + mixedDifference S F = 0 := by + rw [←Finset.insert_erase he, mixedDifference_insert _ _ (Finset.notMem_erase e S)] + have h : mixedDifference (S.erase e) (fun T => F (insert e T)) = + mixedDifference (S.erase e) F := by + apply Finset.sum_congr rfl + intro T hT + dsimp only + rw [hF _ (Finset.sdiff_subset)] + rw [h,sub_self] + + +theorem reconstruction (H : Finset E) (F : Finset E → R) : + (∑ S ∈ H.powerset, mixedDifference S F)=F H := by + induction H using Finset.induction_on generalizing F with + | empty => simp + | @insert e H he ih => + rw [Finset.sum_powerset_insert he] + have hs : (∑S ∈ H.powerset, mixedDifference (insert e S) F) = + (∑S ∈ H.powerset, mixedDifference S (fun T => F (insert e T))) - + ∑S ∈ H.powerset, mixedDifference S F := by + rw [←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro S hS + exact mixedDifference_insert S e + (fun h => he (Finset.mem_powerset.mp hS h)) F + rw [hs,ih,ih] + ring + +variable [Fintype A] + +def partition (q : A → R) (I : A → E → R) (S : Finset E) : R := + ∑ a, q a * ∏ e ∈ S, I a e + +def coefficient (q : A → R) (I : A → E → R) (S : Finset E) : R := + ∑ a, q a * ∏ e ∈ S, (I a e - 1) + + + +omit [DecidableEq E] in +theorem partition_expansion (q : A → R) (I : A → E → R) (S : Finset E) : + partition q I S = ∑ T ∈ S.powerset, coefficient q I T := by + unfold partition coefficient + have hp (a : A) : (∏ e ∈ S, I a e) = + ∑ T ∈ S.powerset, ∏ e ∈ T, (I a e-1) := by + simpa using (Finset.prod_one_add (f := fun e => I a e-1) S) + simp_rw [hp,Finset.mul_sum] + exact Finset.sum_comm + + + +theorem coefficient_eq_mixedDifference (q : A → R) (I : A → E → R) (S : Finset E) : + coefficient q I S = mixedDifference S (partition q I) := by + unfold coefficient mixedDifference partition + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a ha + have hp := Finset.prod_sub (fun e => I a e) (fun _ : E => (1:R)) S + simp only [Finset.prod_const_one,mul_one] at hp + rw [hp,Finset.mul_sum] + apply Finset.sum_congr rfl + intro T hT + ring + +theorem coefficient_eq_zero_of_irrelevant (q : A → R) (I : A → E → R) + {S : Finset E} {e : E} (he : e ∈ S) + (hF : ∀ T ⊆ S.erase e, partition q I (insert e T) = partition q I T) : + coefficient q I S = 0 := by + rw [coefficient_eq_mixedDifference] + exact mixedDifference_eq_zero_of_irrelevant he _ hF + +end FiniteEdgeExpansion + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA.Locality + +variable {n : ℕ} + + +def annealedObservable (μ : Measure (Disorder n)) (a : Disorder n → ℂ) + (B : Finset (Edge n)) (w : List PointedTree.Gate) (A : Disorder n → Operator n) + (E : Finset (Edge n)) : ℂ := + ∫J, a J * quad ((physicalWord n (maskedDisorder J (E∪B)) w).mulVec (plus n)) (A J) ∂μ + + + +theorem annealed_mixedDifference_eq_zero (μ : Measure (Disorder n)) (a : Disorder n → ℂ) + (B : Finset (Edge n)) (w : List PointedTree.Gate) (A : Disorder n → Operator n) + (S : Finset (Fin n)) (hA : ∀J, IsSupported S (A J)) + {H : Finset (Edge n)} {e : Edge n} (he : e∈H) + (hirr : e∉relevantEdges (H∪B) w S) : + FiniteEdgeExpansion.mixedDifference H (annealedObservable μ a B w A)=0 := by + apply FiniteEdgeExpansion.mixedDifference_eq_zero_of_irrelevant he + intro M hM + apply integral_congr_ae + filter_upwards [] with J + congr 1 + rw [quad_mulVec,quad_mulVec] + change quad (plus n) (wordConjugate J (insert e M∪B) w (A J)) = + quad (plus n) (wordConjugate J (M∪B) w (A J)) + rw [Finset.insert_union] + congr 1 + exact wordConjugate_insert_irrelevant J (Finset.mem_union_left B he) + (Finset.union_subset_union (hM.trans (Finset.erase_subset e H)) (Finset.Subset.refl B)) + w (hA J) hirr + + +def averagedMarkedWord (r : Edge n) (w : List PointedTree.Gate) + (E : Finset (Edge n)) : ℂ := + annealedObservable (disorderLaw n) (fun J => (J r:ℂ)) {r} w + (fun _ => pauliZ r.1.1*pauliZ r.1.2) E + + + +theorem marked_cluster_eq_zero (r : Edge n) (w : List PointedTree.Gate) + {H : Finset (Edge n)} {e : Edge n} (he : e∈H) + (hirr : e∉relevantEdges (H∪{r}) w {r.1.1,r.1.2}) : + FiniteEdgeExpansion.mixedDifference H (averagedMarkedWord r w)=0 := by + apply annealed_mixedDifference_eq_zero (disorderLaw n) (fun J => (J r:ℂ)) + {r} w (fun _ => pauliZ r.1.1*pauliZ r.1.2) {r.1.1,r.1.2} _ he hirr + intro J + exact (supported_pauliZ (by simp)).mul (supported_pauliZ (by simp)) + +end SKQAOA.Locality + + + +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + + +def qaoaWord : (p : ℕ) → (Fin p → ℝ) → (Fin p → ℝ) → List PointedTree.Gate + | 0, _, _ => [] + | p+1, γ, β => .mixer (β (Fin.last p)) :: .cost (γ (Fin.last p)) :: + qaoaWord p (fun i => γ i.castSucc) (fun i => β i.castSucc) + +@[simp] theorem physicalWord_qaoaWord (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) : + physicalWord n J (qaoaWord p γ β)=circuit J p γ β := by + induction p with + | zero => rfl + | succ p ih => simp only [qaoaWord,physicalWord,physicalGate,ih,circuit,mul_assoc] + +namespace SiteHistories + +instance bitsInhabited : (p : ℕ) → Inhabited (Bits p) + | 0 => inferInstanceAs (Inhabited Unit) + | p+1 => @instInhabitedProd Bool (Bits p) inferInstance (bitsInhabited p) + +def maskPhase (n p : ℕ) (γ : Fin p → ℝ) (a b : History n p) + (E : Finset (Edge n)) (e : Edge n) : ℂ := + if e∈E then pairedPhase n p γ a b e else 0 + +lemma masked_phase_sum (n p : ℕ) (J : Disorder n) (γ : Fin p → ℝ) + (a b : History n p) (E : Finset (Edge n)) : + (∑e, pairedPhase n p γ a b e*(Locality.maskedDisorder J E e:ℂ))= + ∑e, maskPhase n p γ a b E e*(J e:ℂ) := by + apply Finset.sum_congr rfl + intro e he + simp only [Locality.maskedDisorder,maskPhase] + split_ifs <;> simp + +lemma coord_masked_history (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) + (σ : Configuration n) (r : Edge n) (E : Finset (Edge n)) : + (J r:ℂ)*(star (qaoaState n p (Locality.maskedDisorder J E) γ β σ)* + qaoaState n p (Locality.maskedDisorder J E) γ β σ)= + ∑a:History n p, ∑b:History n p, pairedMix n p β σ a b * + ((J r:ℂ)*Complex.exp (∑e,maskPhase n p γ a b E e*(J e:ℂ))) := by + rw [qaoaState_pair_history] + simp only [Finset.mul_sum,masked_phase_sum] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + ring + +lemma integral_coord_masked (n p : ℕ) (γ β : Fin p → ℝ) + (σ : Configuration n) (r : Edge n) (E : Finset (Edge n)) : + (∫J:Disorder n, (J r:ℂ)* + (star (qaoaState n p (Locality.maskedDisorder J E) γ β σ)* + qaoaState n p (Locality.maskedDisorder J E) γ β σ) ∂disorderLaw n)= + ∑a:History n p, ∑b:History n p, pairedMix n p β σ a b * + maskPhase n p γ a b E r * Complex.exp (∑e,(maskPhase n p γ a b E e)^2/2) := by + simp_rw [coord_masked_history] + have hx (a b : History n p) : Integrable (fun J : Disorder n => pairedMix n p β σ a b * + ((J r:ℂ)*Complex.exp (∑e, maskPhase n p γ a b E e*(J e:ℂ)))) (disorderLaw n) := + (GaussianFourier.integrable_coord_exp_sum (maskPhase n p γ a b E) r).const_mul _ + rw [integral_finsetSum _ (fun a _ => integrable_finsetSum _ (fun b _ => hx a b))] + apply Finset.sum_congr rfl + intro a ha + rw [integral_finsetSum _ (fun b _ => hx a b)] + apply Finset.sum_congr rfl + intro b hb + rw [integral_const_mul] + change _ * (∫J:Disorder n, _ ∂GaussianFourier.law (Edge n))=_ + rw [GaussianFourier.integral_coord_exp_sum,mul_assoc] + +lemma integrable_coord_masked (n p : ℕ) (γ β : Fin p → ℝ) + (σ : Configuration n) (r : Edge n) (E : Finset (Edge n)) : + Integrable (fun J:Disorder n => (J r:ℂ)* + (star (qaoaState n p (Locality.maskedDisorder J E) γ β σ)* + qaoaState n p (Locality.maskedDisorder J E) γ β σ)) (disorderLaw n) := by + simp_rw [coord_masked_history] + exact integrable_finsetSum _ (fun a _ => integrable_finsetSum _ (fun b _ => + (GaussianFourier.integrable_coord_exp_sum (maskPhase n p γ a b E) r).const_mul _)) + +lemma quad_ZZ (n : ℕ) (ψ : State n) (r : Edge n) : + quad ψ (pauliZ r.1.1*pauliZ r.1.2)= + ∑σ:Configuration n,(spin σ r.1.1:ℂ)*(spin σ r.1.2:ℂ)*(star (ψ σ)*ψ σ) := by + simp only [pauliZ,Matrix.diagonal_mul_diagonal,quad,Matrix.mulVec_diagonal, + dotProduct,Pi.star_apply] + apply Finset.sum_congr rfl + intro σ hσ + ring + + +theorem averagedMarkedWord_history (n p : ℕ) (γ β : Fin p → ℝ) + (r : Edge n) (E : Finset (Edge n)) : + Locality.averagedMarkedWord r (qaoaWord p γ β) E= + ∑σ:Configuration n, ∑a:History n p, ∑b:History n p, + (spin σ r.1.1:ℂ)*(spin σ r.1.2:ℂ)*pairedMix n p β σ a b * + pairedPhase n p γ a b r * + Complex.exp (∑e, (maskPhase n p γ a b (E∪{r}) e)^2/2) := by + unfold Locality.averagedMarkedWord Locality.annealedObservable + simp only [physicalWord_qaoaWord] + change (∫J:Disorder n, (J r:ℂ)*quad + (qaoaState n p (Locality.maskedDisorder J (E∪{r})) γ β) + (pauliZ r.1.1*pauliZ r.1.2) ∂disorderLaw n)=_ + simp only [quad_ZZ,Finset.mul_sum] + have hi (σ : Configuration n) := + (integrable_coord_masked n p γ β σ r (E∪{r})).const_mul + ((spin σ r.1.1:ℂ)*(spin σ r.1.2:ℂ)) + have rearr (J : Disorder n) (σ : Configuration n) : + (J r:ℂ)*((spin σ r.1.1:ℂ)*(spin σ r.1.2:ℂ)* + (star (qaoaState n p (Locality.maskedDisorder J (E∪{r})) γ β σ)* + qaoaState n p (Locality.maskedDisorder J (E∪{r})) γ β σ))= + ((spin σ r.1.1:ℂ)*(spin σ r.1.2:ℂ))*((J r:ℂ)* + (star (qaoaState n p (Locality.maskedDisorder J (E∪{r})) γ β σ)* + qaoaState n p (Locality.maskedDisorder J (E∪{r})) γ β σ)) := by ring + simp_rw [rearr] + rw [integral_finsetSum _ (fun σ _ => hi σ)] + apply Finset.sum_congr rfl + intro σ hσ + rw [integral_const_mul,integral_coord_masked] + simp only [Finset.mul_sum,maskPhase,Finset.mem_union,Finset.mem_singleton, + or_true,ite_true] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + ring + +end SiteHistories +end SKQAOA + + + +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA.SiteHistories + +variable {n : ℕ} + + +def rootFactor (p : ℕ) (γ : Fin p → ℝ) (r : Edge n) (a : Fin n → Site p) : ℂ := + (bitSpin (a r.1.1).1:ℂ)*(bitSpin (a r.1.2).1:ℂ)*Complex.I* + ((Real.sqrt (n:ℝ))⁻¹:ℂ)*(delta p γ (a r.1.1) (a r.1.2):ℂ)* + (edgeKernel n p γ (a r.1.1) (a r.1.2):ℂ) + + +def factor (p : ℕ) (γ : Fin p → ℝ) (r : Edge n) + (a : Fin n → Site p) (e : Edge n) : ℂ := + if e=r then 1 else (edgeKernel n p γ (a e.1.1) (a e.1.2):ℂ) + +def partition (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) (E : Finset (Edge n)) : ℂ := + FiniteHistory.expectation (weight p β) (fun a => rootFactor p γ r a * ∏e∈E,factor p γ r a e) + +def cluster (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) (H : Finset (Edge n)) : ℂ := + FiniteHistory.expectation (weight p β) + (fun a => rootFactor p γ r a * ∏e∈H,(factor p γ r a e-1)) + +lemma exp_maskPhase_sq (p : ℕ) (γ : Fin p → ℝ) + (h : Configuration n × History n p × History n p) (E : Finset (Edge n)) : + Complex.exp (∑e,(maskPhase n p γ h.2.1 h.2.2 E e)^2/2)= + ∏e∈E,(edgeKernel n p γ (trajectoriesEquiv n p h e.1.1) + (trajectoriesEquiv n p h e.1.2):ℂ) := by + rw [Complex.exp_sum] + have he (e : Edge n) : Complex.exp ((maskPhase n p γ h.2.1 h.2.2 E e)^2/2)= + if e∈E then (edgeKernel n p γ (trajectoriesEquiv n p h e.1.1) + (trajectoriesEquiv n p h e.1.2):ℂ) else 1 := by + by_cases he : e∈E + · simp only [maskPhase,he,ite_true,exp_pairedPhase_sq] + · simp [maskPhase,he] + simp_rw [he] + rw [Finset.prod_ite_mem,Finset.univ_inter] + +lemma prod_union_root {A : Type*} [DecidableEq A] (E : Finset A) (r : A) (f : A → ℂ) : + (∏e∈E∪{r},f e)=f r*∏e∈E,if e=r then 1 else f e := by + induction E using Finset.induction_on with + | empty => simp + | @insert e E he ih => + by_cases her : e=r + · subst e + rw [Finset.insert_union,Finset.insert_eq_of_mem (by simp), + Finset.prod_insert he,ite_eq_left rfl,one_mul] + exact ih + · rw [Finset.insert_union,Finset.prod_insert (by simpa [her] using he), + Finset.prod_insert he,ite_eq_right her,ih] + ring + + + +theorem partition_eq_marked (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (E : Finset (Edge n)) : + partition p γ β r E=Locality.averagedMarkedWord r (qaoaWord p γ β) E := by + rw [averagedMarkedWord_history] + have hs := (trajectoriesEquiv n p).sum_comp (fun a => + (∏i,weight p β (a i))*(rootFactor p γ r a*∏e∈E,factor p γ r a e)) + rw [Fintype.sum_prod_type] at hs + simp_rw [Fintype.sum_prod_type] at hs + unfold partition FiniteHistory.expectation + rw [←hs] + apply Finset.sum_congr rfl + intro σ hσ + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + rw [pairedMix_factor,pairedPhase_local n p γ (σ,a,b) r, + exp_maskPhase_sq p γ (σ,a,b),prod_union_root] + simp only [rootFactor,factor,trajectoriesEquiv_apply] + change (∏i, weight p β (σ i,atVertex n p a i,atVertex n p b i))* + ((spin σ r.1.1:ℂ)*(spin σ r.1.2:ℂ)*Complex.I*((Real.sqrt (n:ℝ))⁻¹:ℂ)* + (delta p γ (σ r.1.1,atVertex n p a r.1.1,atVertex n p b r.1.1) + (σ r.1.2,atVertex n p a r.1.2,atVertex n p b r.1.2):ℂ)* + (edgeKernel n p γ (σ r.1.1,atVertex n p a r.1.1,atVertex n p b r.1.1) + (σ r.1.2,atVertex n p a r.1.2,atVertex n p b r.1.2):ℂ)* + ∏e∈E,factor p γ r (trajectoriesEquiv n p (σ,a,b)) e)=_ + ac_rfl + +theorem cluster_eq_mixedDifference (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) : + cluster p γ β r H=FiniteEdgeExpansion.mixedDifference H + (Locality.averagedMarkedWord r (qaoaWord p γ β)) := by + have hp (E : Finset (Edge n)) : + FiniteEdgeExpansion.partition (fun a : Fin n → Site p => + (∏i,weight p β (a i))*rootFactor p γ r a) (factor p γ r) E= + partition p γ β r E := by + simp only [FiniteEdgeExpansion.partition,partition,FiniteHistory.expectation,mul_assoc] + have hc : cluster p γ β r H=FiniteEdgeExpansion.coefficient + (fun a : Fin n → Site p => (∏i,weight p β (a i))*rootFactor p γ r a) + (factor p γ r) H := by + simp only [FiniteEdgeExpansion.coefficient,cluster,FiniteHistory.expectation,mul_assoc] + rw [hc,FiniteEdgeExpansion.coefficient_eq_mixedDifference] + congr 1 + funext E + rw [hp,partition_eq_marked] + + +theorem cluster_eq_zero (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + {H : Finset (Edge n)} {e : Edge n} (he : e∈H) + (hirr : e∉Locality.relevantEdges (H∪{r}) (qaoaWord p γ β) {r.1.1,r.1.2}) : + cluster p γ β r H=0 := by + rw [cluster_eq_mixedDifference] + exact Locality.marked_cluster_eq_zero r _ he hirr + + +theorem marked_eq_sum_clusters (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (E : Finset (Edge n)) : + Locality.averagedMarkedWord r (qaoaWord p γ β) E= + ∑H∈E.powerset,cluster p γ β r H := by + simp_rw [cluster_eq_mixedDifference] + exact (FiniteEdgeExpansion.reconstruction E _).symm + +end SKQAOA.SiteHistories + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/MeasurableStepParam.lean b/lean/OAI/Probability/ParisiFinite/MeasurableStepParam.lean new file mode 100644 index 0000000000000000000000000000000000000000..b17fa2140e268a78c7dba5be2442b005adf15701 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/MeasurableStepParam.lean @@ -0,0 +1,683 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ScaledTimeMem + +namespace OAI + +/-! Measurable Step Param. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function +open scoped Topology NNReal ENNReal +namespace ParisiFinite + +lemma measurable_step_param {α : Type*} [MeasurableSpace α] + {a s x : α → ℝ} {f : α → ℝ → ℝ} + (ha : Measurable a) (hs : Measurable s) (hx : Measurable x) + (hf : Measurable (uncurry f)) : + Measurable (fun p => step (a p) (s p) (f p) (x p)) := by + have hm : Measurable (fun q : α × ℝ => f q.1 (x q.1 + s q.1 * q.2)) := + hf.comp (measurable_fst.prodMk ((hx.comp measurable_fst).add + ((hs.comp measurable_fst).mul measurable_snd))) + have hi : Measurable (fun p => ∫ z, f p (x p+s p*z) ∂gaussianReal 0 1) := + hm.stronglyMeasurable.integral_prod_right'.measurable + have he : Measurable (fun p => ∫ z, Real.exp (a p*f p (x p+s p*z)) ∂gaussianReal 0 1) := + ((ha.comp measurable_fst).mul hm).exp.stronglyMeasurable.integral_prod_right'.measurable + exact Measurable.ite (measurableSet_eq_fun ha measurable_const) hi (he.log.div ha) + +lemma measurable_evolve_ofFn {α : Type*} [MeasurableSpace α] (n : ℕ) + (a d : Fin n → α → ℝ≥0) (ha : ∀ i,Measurable (a i)) (hd : ∀ i,Measurable (d i)) + {f : α → ℝ → ℝ} (hf : Measurable (uncurry f)) : + Measurable (fun q : α × ℝ => + evolve (List.ofFn fun i => (a i q.1,d i q.1)) (f q.1) q.2) := by + induction n with + | zero => simpa only [List.ofFn_zero,evolve,Function.comp_def,uncurry] using + hf.comp (measurable_fst.prodMk measurable_snd) + | succ n ih => + have ht := ih (fun i => a i.succ) (fun i => d i.succ) + (fun i => ha i.succ) (fun i => hd i.succ) + simp only [List.ofFn_succ,evolve] + refine measurable_step_param ((ha 0).coe_nnreal_real.comp measurable_fst) + (((hd 0).coe_nnreal_real.sqrt).comp measurable_fst) measurable_snd ?_ + exact ht.comp (measurable_fst.fst.prodMk measurable_snd) + + + +lemma measurable_field (β : ℝ≥0) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) : + Measurable (fun q : ℝ≥0 × ℝ => field β γ q.1 q.2) := by + have hg := hγ.measurable + have hstep (n : ℕ) : Measurable (fun q : ℝ≥0 × ℝ => + evolve (dyadicSchedule γ false q.1 (1-q.1) n) (terminal β) q.2) := by + simp_rw [dyadicSchedule_eq_uniform,uniformLower] + refine measurable_evolve_ofFn (2^n) + (fun i t => γ (t+(1-t)*(i : ℕ)/((2^n : ℕ) : ℝ≥0))) + (fun _ t => (1-t)/((2^n : ℕ) : ℝ≥0)) ?_ ?_ (f := fun _ => terminal β) ?_ + · intro i + exact hg.comp (by fun_prop) + · intro i + fun_prop + · unfold uncurry terminal + fun_prop + exact Measurable.iSup hstep + + + +lemma measurable_fieldGradient (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t, γ t ≤ β) : + Measurable (fun q : ℝ≥0 × ℝ => fieldGradient β γ q.1 q.2) := by + let ε (n : ℕ) : ℝ := 1 / (n+1 : ℕ) + have hε : Tendsto ε atTop (𝓝[≠] (0 : ℝ)) := by + refine tendsto_nhdsWithin_iff.mpr ⟨SKCavity.tendsto_succ_reciprocal, ?_⟩ + exact Filter.Eventually.of_forall fun n => by + simp only [Set.mem_compl_iff,Set.mem_singleton_iff,ε] + positivity + have hm (n : ℕ) : Measurable (fun q : ℝ≥0 × ℝ => + (ε n)⁻¹ * (field β γ q.1 (q.2+ε n) - field β γ q.1 q.2)) := by + exact (((measurable_field β hγ).comp + (measurable_fst.prodMk (measurable_snd.add_const (ε n)))).sub + (measurable_field β hγ)).const_mul _ + apply measurable_of_tendsto_metrizable hm + refine tendsto_pi_nhds.mpr fun q => ?_ + simpa only [smul_eq_mul,Function.comp_def] using + (hasDerivAt_field β hβ hγ hb q.1 q.2).tendsto_slope_zero.comp hε + + +def parisiDrift (β : ℝ≥0) (ρ : ProbabilityMeasure OrderPoint) (t x : ℝ) : ℝ := + (measureCoefficient ρ β (Real.toNNReal t) : ℝ) * + fieldGradient β (measureCoefficient ρ β) (Real.toNNReal t) x + +lemma parisiDrift_measurable (β : ℝ≥0) (hβ : 0 < β) + (ρ : ProbabilityMeasure OrderPoint) : + Measurable (uncurry (parisiDrift β ρ)) := by + have hm := measureCoefficient_mono ρ β + have hb (t : ℝ≥0) : measureCoefficient ρ β t ≤ β := + NNReal.coe_le_coe.mp (measureCoefficient_bound ρ β t) + have ht : Measurable (fun q : ℝ × ℝ => Real.toNNReal q.1) := by fun_prop + exact (hm.measurable.comp ht).coe_nnreal_real.mul + ((measurable_fieldGradient β hβ hm hb).comp (ht.prodMk measurable_snd)) + +lemma parisiDrift_bound (β : ℝ≥0) (hβ : 0 < β) + (ρ : ProbabilityMeasure OrderPoint) (t x : ℝ) : + ‖parisiDrift β ρ t x‖ ≤ β := by + have hb (s : ℝ≥0) : measureCoefficient ρ β s ≤ β := + NNReal.coe_le_coe.mp (measureCoefficient_bound ρ β s) + rw [parisiDrift,Real.norm_eq_abs,abs_mul,NNReal.abs_eq] + calc + _ ≤ (measureCoefficient ρ β (Real.toNNReal t) : ℝ) * 1 := + mul_le_mul_of_nonneg_left + (fieldGradient_bound β hβ (measureCoefficient_mono ρ β) hb _ _) (by positivity) + _ ≤ β := by simpa using measureCoefficient_bound ρ β (Real.toNNReal t) + +lemma parisiDrift_lipschitz (β : ℝ≥0) (hβ : 0 < β) + (ρ : ProbabilityMeasure OrderPoint) (t : ℝ) : + LipschitzWith (β*β) (parisiDrift β ρ t) := by + have hb (s : ℝ≥0) : measureCoefficient ρ β s ≤ β := + NNReal.coe_le_coe.mp (measureCoefficient_bound ρ β s) + apply LipschitzWith.of_dist_le_mul + intro x y + rw [Real.dist_eq,parisiDrift,parisiDrift,← mul_sub,abs_mul,NNReal.abs_eq] + calc + _ ≤ (measureCoefficient ρ β (Real.toNNReal t) : ℝ) * (β * dist x y) := + mul_le_mul_of_nonneg_left + ((fieldGradient_lipschitz β hβ (measureCoefficient_mono ρ β) hb _).dist_le_mul x y) + (by positivity) + _ ≤ (β*β : ℝ≥0) * dist x y := by + simp only [NNReal.coe_mul] + calc + _ ≤ (β : ℝ) * (β * dist x y) := + mul_le_mul_of_nonneg_right (measureCoefficient_bound ρ β _) (by positivity) + _ = _ := by ring + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath + + + +structure BoundedCoefficient (β : ℝ≥0) where + val : ℝ≥0 → ℝ≥0 + mono : Monotone val + bound : ∀ t,val t≤β + +namespace BoundedCoefficient +variable {β : ℝ≥0} + +def ofMeasure (β : ℝ≥0) (ρ : ProbabilityMeasure OrderPoint) : BoundedCoefficient β where + val := measureCoefficient ρ β + mono := measureCoefficient_mono ρ β + bound := fun t => NNReal.coe_le_coe.mp (measureCoefficient_bound ρ β t) + +def real (c : BoundedCoefficient β) (t : ℝ) : ℝ := c.val (Real.toNNReal t) + +lemma measurable_real (c : BoundedCoefficient β) : Measurable c.real := + (c.mono.measurable.comp (by fun_prop : Measurable Real.toNNReal)).coe_nnreal_real + +lemma real_nonneg (c : BoundedCoefficient β) (t : ℝ) : 0≤c.real t := (c.val _).coe_nonneg +lemma real_le (c : BoundedCoefficient β) (t : ℝ) : c.real t≤β := NNReal.coe_le_coe.mpr (c.bound _) + +def drift (c : BoundedCoefficient β) (t x : ℝ) : ℝ := + c.real t*fieldGradient β c.val (Real.toNNReal t) x + +lemma drift_measurable (c : BoundedCoefficient β) (hβ : 0<β) : Measurable (uncurry c.drift) := by + exact (c.measurable_real.comp measurable_fst).mul + ((measurable_fieldGradient β hβ c.mono c.bound).comp + ((by fun_prop : Measurable (fun q : ℝ × ℝ => Real.toNNReal q.1)).prodMk measurable_snd)) + +lemma drift_bound (c : BoundedCoefficient β) (hβ : 0<β) (t x : ℝ) : ‖c.drift t x‖≤β := by + rw [drift,Real.norm_eq_abs,abs_mul,abs_of_nonneg (c.real_nonneg t)] + exact (mul_le_mul_of_nonneg_left (fieldGradient_bound β hβ c.mono c.bound _ _) + (c.real_nonneg t)).trans (by simpa only [mul_one] using c.real_le t) + +lemma drift_lipschitz (c : BoundedCoefficient β) (hβ : 0<β) (t : ℝ) : LipschitzWith (β*β) (c.drift t) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,drift,←mul_sub,abs_mul,abs_of_nonneg (c.real_nonneg t),NNReal.coe_mul] + calc + _ ≤ c.real t*((β:ℝ)*|x-y|) := mul_le_mul_of_nonneg_left + ((fieldGradient_lipschitz β hβ c.mono c.bound _).dist_le_mul x y) (c.real_nonneg t) + _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_right (c.real_le t) (mul_nonneg β.coe_nonneg (abs_nonneg (x-y)))] + +def driftData (c : BoundedCoefficient β) (hβ : 0<β) : Drift (β*β) β where + val := c.drift + measurable := c.drift_measurable hβ + bound := c.drift_bound hβ + lipschitz := c.drift_lipschitz hβ + +lemma drift_joint_ae_continuous (c : BoundedCoefficient β) (hβ : 0<β) : + ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry c.drift) (t,x) := by + have hm : Monotone c.real := fun s t h => + NNReal.coe_le_coe.mpr (c.mono (Real.toNNReal_le_toNNReal h)) + have hc : ∀ᵐ t ∂volume,ContinuousAt c.real t := by + rw [ae_iff] + exact hm.countable_not_continuousAt.measure_zero volume + have h0 : ∀ᵐ t ∂volume,t≠(0:ℝ) := by simp [ae_iff,measure_singleton] + have h1 : ∀ᵐ t ∂volume,t≠(1:ℝ) := by simp [ae_iff,measure_singleton] + have hg := continuous_fieldGradient_joint β hβ c.mono c.bound + have hG : Continuous (fun q : ℝ × ℝ => fieldGradient β c.val + (Real.toNNReal (projIcc 0 1 zero_le_one q.1)) q.2) := + hg.comp (((show Continuous (projIcc (0:ℝ) 1 zero_le_one) from continuous_projIcc).comp + continuous_fst).prodMk continuous_snd) + filter_upwards [hc,h0,h1] with t ht ht0 ht1 hmem x + have ht' : t∈Ioo (0:ℝ) 1 := ⟨lt_of_le_of_ne hmem.1 (Ne.symm ht0),lt_of_le_of_ne hmem.2 ht1⟩ + have hG' : ContinuousAt (fun q : ℝ × ℝ => fieldGradient β c.val (Real.toNNReal q.1) q.2) (t,x) := by + apply hG.continuousAt.congr_of_eventuallyEq + filter_upwards [continuousAt_fst.preimage_mem_nhds (Ioo_mem_nhds ht'.1 ht'.2)] with q hq + rw [projIcc_of_mem zero_le_one ⟨hq.1.le,hq.2.le⟩] + exact (ht.comp continuousAt_fst).mul hG' + + + +def spin (c : BoundedCoefficient β) (X : Path) (t : ℝ) : ℝ := + fieldGradient β c.val (Real.toNNReal (projIcc 0 1 zero_le_one t)) (extend X t) + +lemma spin_eq (c : BoundedCoefficient β) (X : Path) (t : ℝ) (ht : t∈Icc (0:ℝ) 1) : + c.spin X t=fieldGradient β c.val (Real.toNNReal t) (extend X t) := by + simp only [spin,projIcc_of_mem zero_le_one ht] + +lemma continuous_spin (c : BoundedCoefficient β) (hβ : 0<β) (X : Path) : Continuous (c.spin X) := + (continuous_fieldGradient_joint β hβ c.mono c.bound).comp + ((show Continuous (projIcc (0:ℝ) 1 zero_le_one) from continuous_projIcc).prodMk (continuous_extend X)) + +lemma norm_spin_le (c : BoundedCoefficient β) (hβ : 0<β) (X : Path) (t : ℝ) : ‖c.spin X t‖≤1 := + fieldGradient_bound β hβ c.mono c.bound _ _ + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {K M : ℝ≥0} + +lemma spin_aestronglyMeasurable (hW : IsBrownianReal W P) (c : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) (t : ℝ) : + AEStronglyMeasurable (fun ω => c.spin (solution b (brownianPath W ω)) t) P := by + exact ((fieldGradient_lipschitz β hβ c.mono c.bound _).continuous.measurable.comp_aemeasurable + (aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t))).aestronglyMeasurable + +lemma spin_integrable (hW : IsBrownianReal W P) (c : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) (t : ℝ) : + Integrable (fun ω => c.spin (solution b (brownianPath W ω)) t) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact Integrable.of_bound (c.spin_aestronglyMeasurable hW hβ b t) 1 + (ae_of_all _ fun ω => c.norm_spin_le hβ _ t) + +def expectedProduct (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) (c d : BoundedCoefficient β) + (b : Drift K M) (t : ℝ) : ℝ := + ∫ ω,c.spin (solution b (brownianPath W ω)) t*d.spin (solution b (brownianPath W ω)) t ∂P + +lemma norm_spin_product_le (c d : BoundedCoefficient β) (hβ : 0<β) (X : Path) (t : ℝ) : + ‖c.spin X t*d.spin X t‖≤1 := by + rw [norm_mul] + exact (mul_le_mul (c.norm_spin_le hβ X t) (d.norm_spin_le hβ X t) (norm_nonneg _) (by norm_num)).trans_eq (one_mul _) + +lemma spin_product_integrable (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) (t : ℝ) : + Integrable (fun ω => c.spin (solution b (brownianPath W ω)) t* + d.spin (solution b (brownianPath W ω)) t) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact Integrable.of_bound ((c.spin_aestronglyMeasurable hW hβ b t).mul + (d.spin_aestronglyMeasurable hW hβ b t)) 1 (ae_of_all _ fun ω => norm_spin_product_le c d hβ _ t) + +lemma expectedProduct_continuous (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) : Continuous (expectedProduct P W c d b) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply continuous_of_dominated (bound := fun _ => (1:ℝ)) + (fun t => (spin_product_integrable hW c d hβ b t).aestronglyMeasurable) + (fun t => ae_of_all _ fun ω => norm_spin_product_le c d hβ _ t) (integrable_const _) + exact ae_of_all _ fun ω => (c.continuous_spin hβ _).mul (d.continuous_spin hβ _) + +lemma expectedProduct_bound (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) (t : ℝ) : ‖expectedProduct P W c d b t‖≤1 := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (μ := P) (ae_of_all _ fun ω => norm_spin_product_le c d hβ _ t)).trans_eq (by simp) + +lemma expectedProduct_comm (c d : BoundedCoefficient β) (b : Drift K M) (t : ℝ) : + expectedProduct P W c d b t=expectedProduct P W d c b t := by + simp only [expectedProduct,mul_comm] + +lemma real_intervalIntegrable (c : BoundedCoefficient β) (a b : ℝ) : + IntervalIntegrable c.real volume a b := by + apply (intervalIntegrable_const (c := (β:ℝ))).mono_fun' c.measurable_real.aestronglyMeasurable + exact Eventually.of_forall fun t => by simpa only [Real.norm_eq_abs,abs_of_nonneg (c.real_nonneg t)] using c.real_le t + +lemma expectedProduct_psd (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) (t : ℝ) : + 2*expectedProduct P W c d b t ≤ expectedProduct P W c c b t+expectedProduct P W d d b t := by + unfold expectedProduct + rw [←integral_const_mul,←integral_add (spin_product_integrable hW c c hβ b t) + (spin_product_integrable hW d d hβ b t)] + apply integral_mono_ae ((spin_product_integrable hW c d hβ b t).const_mul 2) + ((spin_product_integrable hW c c hβ b t).add (spin_product_integrable hW d d hβ b t)) + exact ae_of_all _ fun ω => by + dsimp only [Pi.add_apply] + nlinarith [sq_nonneg (c.spin (solution b (brownianPath W ω)) t-d.spin (solution b (brownianPath W ω)) t)] + +lemma weightedProduct_intervalIntegrable (hW : IsBrownianReal W P) (c d e : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) : + IntervalIntegrable (fun t => c.real t*expectedProduct P W d e b t) volume 0 1 := + (c.real_intervalIntegrable 0 1).mul_continuousOn (expectedProduct_continuous hW d e hβ b).continuousOn + +def feedbackKernel (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) (hβ : 0<β) + (c d : BoundedCoefficient β) (t : ℝ) : ℝ := + d.real t*expectedProduct P W c d (d.driftData hβ) t- + c.real t/2*expectedProduct P W c c (d.driftData hβ) t + +lemma feedbackKernel_intervalIntegrable (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) + (hβ : 0<β) : IntervalIntegrable (feedbackKernel P W hβ c d) volume 0 1 := by + apply (weightedProduct_intervalIntegrable hW d c d hβ _).sub + have hh := (weightedProduct_intervalIntegrable hW c c c hβ (d.driftData hβ)).div_const 2 + convert! hh using 1 + ext t + ring + +lemma expected_verificationKernel_eq_feedback (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) + (hβ : 0<β) (t : ℝ) (ht : t∈Icc (0:ℝ) 1) : + (∫ ω,verificationKernel β c.val (d.driftData hβ) t + (extend (solution (d.driftData hβ) (brownianPath W ω)) t) ∂P)=feedbackKernel P W hβ c d t := by + unfold feedbackKernel expectedProduct + rw [←integral_const_mul,←integral_const_mul,←integral_sub + ((spin_product_integrable hW c d hβ (d.driftData hβ) t).const_mul _) + ((spin_product_integrable hW c c hβ (d.driftData hβ) t).const_mul _)] + apply integral_congr_ae + filter_upwards [] with ω + simp only [spin_eq _ _ _ ht,verificationKernel,driftData,drift,real] + ring + + +theorem feedback_verification (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) (hβ : 0<β) : + (∫ ω,terminal β (solution (d.driftData hβ) (brownianPath W ω) ⟨1,by simp⟩) ∂P)-field β c.val 0 0= + ∫ t in (0:ℝ)..1,feedbackKernel P W hβ c d t := by + rw [canonical_verification hW (d.driftData hβ) (d.drift_joint_ae_continuous hβ) β hβ c.mono c.bound] + apply intervalIntegral.integral_congr_ae + filter_upwards [] with t ht + rw [uIoc_of_le zero_le_one] at ht + exact expected_verificationKernel_eq_feedback hW c d hβ t ⟨ht.1.le,ht.2⟩ + + +theorem field_comparison_lower (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) (hβ : 0<β) : + (∫ t in (0:ℝ)..1,(c.real t-d.real t)/2*expectedProduct P W c c (d.driftData hβ) t) ≤ + field β c.val 0 0-field β d.val 0 0 := by + have hi : IntervalIntegrable (fun t => (c.real t-d.real t)/2* + expectedProduct P W c c (d.driftData hβ) t) volume 0 1 := by + have hh := ((weightedProduct_intervalIntegrable hW c c c hβ (d.driftData hβ)).sub + (weightedProduct_intervalIntegrable hW d c c hβ (d.driftData hβ))).div_const 2 + convert! hh using 1 + ext t + ring + have he : field β c.val 0 0-field β d.val 0 0= + ∫ t in (0:ℝ)..1,feedbackKernel P W hβ d d t-feedbackKernel P W hβ c d t := by + rw [intervalIntegral.integral_sub (feedbackKernel_intervalIntegrable hW d d hβ) + (feedbackKernel_intervalIntegrable hW c d hβ),←feedback_verification hW d d hβ, + ←feedback_verification hW c d hβ] + ring + rw [he] + apply intervalIntegral.integral_mono zero_le_one hi + ((feedbackKernel_intervalIntegrable hW d d hβ).sub (feedbackKernel_intervalIntegrable hW c d hβ)) + intro t + have hp := expectedProduct_psd hW c d hβ (d.driftData hβ) t + have hpos := d.real_nonneg t + dsimp only [feedbackKernel] + nlinarith [mul_nonneg hpos (sub_nonneg.mpr hp)] + + +theorem field_comparison_upper (hW : IsBrownianReal W P) (c d : BoundedCoefficient β) (hβ : 0<β) : + field β c.val 0 0-field β d.val 0 0 ≤ + ∫ t in (0:ℝ)..1,(c.real t-d.real t)/2*expectedProduct P W d d (c.driftData hβ) t := by + have hh := field_comparison_lower hW d c hβ + have he : (∫ t in (0:ℝ)..1,(d.real t-c.real t)/2*expectedProduct P W d d (c.driftData hβ) t)= + -(∫ t in (0:ℝ)..1,(c.real t-d.real t)/2*expectedProduct P W d d (c.driftData hβ) t) := by + rw [←intervalIntegral.integral_neg] + congr 1 + ext t + ring + rw [he] at hh + linarith + +end BoundedCoefficient +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +lemma step_tendsto_coefficient_field {L : ℝ≥0} {F : ℕ → ℝ → ℝ} {f : ℝ → ℝ} + (hF : ∀ n,LipschitzWith L (F n)) (hf : LipschitzWith L f) + (hfn : ∀ x,Tendsto (fun n => F n x) atTop (𝓝 (f x))) + {A : ℕ → ℝ} {a : ℝ} (hA : ∀ n,0≤A n) (ha : 0≤a) + (hAn : Tendsto A atTop (𝓝 a)) (s x : ℝ) : + Tendsto (fun n => step (A n) s (F n) x) atTop (𝓝 (step a s f x)) := by + have he := SKCavity.tendsto_succ_reciprocal + have hp (k : ℕ) : 0 < (1:ℝ)/(k+1:ℕ) := by positivity + have hlo : Tendsto (fun k : ℕ => max 0 (a-1/(k+1:ℕ))) atTop (𝓝 a) := by + simpa only [sub_zero,max_eq_right ha] using (tendsto_const_nhds (x := (0:ℝ))).max ((tendsto_const_nhds (x := a)).sub he) + have hup : Tendsto (fun k : ℕ => a+1/(k+1:ℕ)) atTop (𝓝 a) := by + simpa only [add_zero] using tendsto_const_nhds.add he + have hs := (step_analyticAt_coefficient hf a s x).continuousAt + rw [tendsto_order] + constructor + · intro v hv + by_cases hz : a=0 + · subst a + filter_upwards [(step_tendsto hF hf hfn 0 s x).eventually (lt_mem_nhds hv)] with n hn + exact hn.trans_le (step_parameter_mono (hF n) le_rfl (hA n) s x) + · have hap : 0 F n x) atTop (𝓝 (f x))) + {G : ℕ → ℝ≥0 → ℝ≥0} {γ : ℝ≥0 → ℝ≥0} + (hG : ∀ t,Tendsto (fun n => G n t) atTop (𝓝 (γ t))) + (u : Bool) (t d : ℝ≥0) (k : ℕ) (x : ℝ) : + Tendsto (fun n => evolve (dyadicSchedule (G n) u t d k) (F n) x) atTop + (𝓝 (evolve (dyadicSchedule γ u t d k) f x)) := by + induction k generalizing F f t d x with + | zero => + simp only [dyadicSchedule,evolve] + exact step_tendsto_coefficient_field hF hf hfn (fun n => (G n _).coe_nonneg) + (γ _).coe_nonneg (NNReal.continuous_coe.continuousAt.tendsto.comp (hG _)) _ _ + | succ k ih => + simp only [dyadicSchedule,evolve_append] + exact ih (fun n => evolve_lipschitz (hF n) _) (evolve_lipschitz hf _) + (fun y => ih hF hf hfn (t+d/2) (d/2) y) t (d/2) x + +lemma dyadicEvolution_tendsto_coefficient {G : ℕ → ℝ≥0 → ℝ≥0} {γ : ℝ≥0 → ℝ≥0} + (hGm : ∀ n,Monotone (G n)) (hγ : Monotone γ) {β : ℝ} + (hb : ∀ t,(γ t:ℝ)≤β) (hG : ∀ t,Tendsto (fun n => G n t) atTop (𝓝 (γ t))) + {f : ℝ → ℝ} (hf : LipschitzWith 1 f) (t d : ℝ≥0) (x : ℝ) : + Tendsto (fun n => dyadicEvolution (G n) t d f x) atTop + (𝓝 (dyadicEvolution γ t d f x)) := by + rw [tendsto_order] + constructor + · intro v hv + obtain ⟨k,hk⟩ := ((dyadic_low_tendsto hf hγ t d x).eventually (lt_mem_nhds hv)).exists + filter_upwards [(dyadic_fixed_tendsto_coefficient (fun _ => hf) hf + (fun _ => tendsto_const_nhds) hG false t d k x).eventually (lt_mem_nhds hk)] with n hn + exact hn.trans_le (le_ciSup (dyadic_low_bddAbove hf (hGm n) t d x) k) + · intro v hv + obtain ⟨k,hk⟩ := ((dyadic_high_tendsto hf hγ hb t d x).eventually (gt_mem_nhds hv)).exists + filter_upwards [(dyadic_fixed_tendsto_coefficient (fun _ => hf) hf + (fun _ => tendsto_const_nhds) hG true t d k x).eventually (gt_mem_nhds hk)] with n hn + apply lt_of_le_of_lt ?_ hn + apply le_of_tendsto (dyadic_low_tendsto hf (hGm n) t d x) + filter_upwards [eventually_ge_atTop k] with j hj + exact (dyadicSchedule_low_le_high hf (hGm n) t d j x).trans + (dyadic_high_antitone hf (hGm n) t d x hj) + +lemma field_tendsto_coefficient (β : ℝ≥0) (hβ : 0<β) + {G : ℕ → ℝ≥0 → ℝ≥0} {γ : ℝ≥0 → ℝ≥0} + (hGm : ∀ n,Monotone (G n)) (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (hG : ∀ t,Tendsto (fun n => G n t) atTop (𝓝 (γ t))) (t : ℝ≥0) (x : ℝ) : + Tendsto (fun n => field β (G n) t x) atTop (𝓝 (field β γ t x)) := + dyadicEvolution_tendsto_coefficient hGm hγ (fun t => NNReal.coe_le_coe.mpr (hb t)) hG + (terminal_lipschitz (show (0:ℝ)<β from hβ)) t (1-t) x + + + +lemma fieldGradient_tendsto_coefficient (β : ℝ≥0) (hβ : 0<β) + {G : ℕ → ℝ≥0 → ℝ≥0} {γ : ℝ≥0 → ℝ≥0} + (hGm : ∀ n,Monotone (G n)) (hGb : ∀ n t,G n t≤β) + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (hG : ∀ t,Tendsto (fun n => G n t) atTop (𝓝 (γ t))) (t : ℝ≥0) (x : ℝ) : + Tendsto (fun n => fieldGradient β (G n) t x) atTop (𝓝 (fieldGradient β γ t x)) := by + let ε (k : ℕ) : ℝ := 1/(k+1:ℕ) + have hp (k : ℕ) : 0<ε k := by dsimp [ε];positivity + have he : Tendsto ε atTop (𝓝[≠] (0:ℝ)) := by + refine tendsto_nhdsWithin_iff.mpr ⟨SKCavity.tendsto_succ_reciprocal,?_⟩ + exact Eventually.of_forall fun k => (hp k).ne' + have hs : Tendsto (fun k => (field β γ t (x+ε k)-field β γ t x)/ε k) atTop + (𝓝 (fieldGradient β γ t x)) := by + simpa only [smul_eq_mul,Function.comp_def,div_eq_mul_inv,mul_comm] using + (hasDerivAt_field β hβ hγ hb t x).tendsto_slope_zero.comp he + have hh : Tendsto (fun k => (β:ℝ)*ε k) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero] using SKCavity.tendsto_succ_reciprocal.const_mul (β:ℝ) + have hfn (k : ℕ) : Tendsto (fun n => (field β (G n) t (x+ε k)-field β (G n) t x)/ε k) + atTop (𝓝 ((field β γ t (x+ε k)-field β γ t x)/ε k)) := + ((field_tendsto_coefficient β hβ hGm hγ hb hG t (x+ε k)).sub + (field_tendsto_coefficient β hβ hGm hγ hb hG t x)).div_const _ + rw [tendsto_order] + constructor + · intro v hv + have hl := hs.sub hh + rw [sub_zero] at hl + obtain ⟨k,hk⟩ := (hl.eventually (lt_mem_nhds hv)).exists + filter_upwards [((hfn k).sub_const ((β:ℝ)*ε k)).eventually (lt_mem_nhds hk)] with n hn + have hbnd := (abs_le.mp (field_slope_error β hβ (hGm n) (hGb n) t x (hp k))).2 + linarith + · intro v hv + have hl := hs.add hh + rw [add_zero] at hl + obtain ⟨k,hk⟩ := (hl.eventually (gt_mem_nhds hv)).exists + filter_upwards [((hfn k).add_const ((β:ℝ)*ε k)).eventually (gt_mem_nhds hk)] with n hn + have hbnd := (abs_le.mp (field_slope_error β hβ (hGm n) (hGb n) t x (hp k))).1 + linarith + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath +variable {K M : ℝ≥0} + +lemma drift_comp_tendsto {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ t x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) + {X : ℕ → Path} {Y : Path} (hX : Tendsto X atTop (𝓝 Y)) (t : ℝ) : + Tendsto (fun n => (B n).val t (extend (X n) t)) atTop (𝓝 (b.val t (extend Y t))) := by + have hx : Tendsto (fun n => extend (X n) t) atTop (𝓝 (extend Y t)) := + (show Continuous (fun V : Path => extend V t) by unfold extend;fun_prop).continuousAt.tendsto.comp hX + have hd : Tendsto (fun n => (B n).val t (extend (X n) t)-(B n).val t (extend Y t)) + atTop (𝓝 (0:ℝ)) := by + have hnorm (n : ℕ) : ‖(B n).val t (extend (X n) t)-(B n).val t (extend Y t)‖ ≤ + (K:ℝ)*‖extend (X n) t-extend Y t‖ := by + simpa only [←dist_eq_norm] using (B n).lipschitz t |>.dist_le_mul (extend (X n) t) (extend Y t) + exact squeeze_zero_norm hnorm + (by simpa only [sub_self,norm_zero,mul_zero] using + ((hx.sub_const (extend Y t)).norm.const_mul (K:ℝ))) + simpa only [sub_add_cancel,zero_add] using hd.add (hB t (extend Y t)) + +lemma next_tendsto_drift {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ t x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) + {X : ℕ → Path} {Y : Path} (hX : Tendsto X atTop (𝓝 Y)) (W : Path) : + Tendsto (fun n => next (B n) W (X n)) atTop (𝓝 (next b W Y)) := by + let R (n : ℕ) (t : ℝ) : ℝ := ‖(B n).val t (extend (X n) t)-b.val t (extend Y t)‖ + have hRm (n : ℕ) : Measurable (R n) := + (((B n).measurable.comp (measurable_id.prodMk (continuous_extend (X n)).measurable)).sub + (b.measurable.comp (measurable_id.prodMk (continuous_extend Y).measurable))).norm + have hRb (n : ℕ) (t : ℝ) : R n t ≤ 2*(M:ℝ) := + (norm_sub_le _ _).trans (by linarith [(B n).bound t (extend (X n) t),b.bound t (extend Y t)]) + have hRi (n : ℕ) : IntervalIntegrable (R n) volume 0 1 := + (intervalIntegrable_const (c := 2*(M:ℝ))).mono_fun' (hRm n).aestronglyMeasurable + (Eventually.of_forall fun t => by simpa only [R,norm_norm] using hRb n t) + have he : Tendsto (fun n => ∫ t in (0:ℝ)..1,R n t) atTop (𝓝 (0:ℝ)) := by + have hh := intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (a := (0:ℝ)) (b := 1) (μ := volume) (l := atTop) (F := R) (f := fun _ => (0:ℝ)) + (fun _ => 2*(M:ℝ)) (Eventually.of_forall fun n => (hRm n).aestronglyMeasurable.restrict) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => by simpa only [R,norm_norm] using hRb n t) + intervalIntegrable_const (ae_of_all _ fun t _ => by + simpa only [R,sub_self,norm_zero] using ((drift_comp_tendsto hB hX t).sub_const (b.val t (extend Y t))).norm) + simpa only [intervalIntegral.integral_zero] using hh + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun n => dist_nonneg) (fun n => ?_) he + apply (ContinuousMap.dist_le + (intervalIntegral.integral_nonneg zero_le_one (fun t _ => norm_nonneg _))).mpr + intro t + rw [dist_eq_norm,next_apply,next_apply,add_sub_add_left_eq_sub, + ←intervalIntegral.integral_sub (integrable_comp (B n) (X n) _ _) (integrable_comp b Y _ _)] + calc + _ ≤ ∫ s in (0:ℝ)..(t:ℝ),R n s := intervalIntegral.norm_integral_le_integral_norm t.property.1 + _ ≤ ∫ s in (0:ℝ)..1,R n s := intervalIntegral.integral_mono_interval le_rfl t.property.1 + t.property.2 (ae_of_all _ fun s => norm_nonneg _) (hRi n) + +lemma iterate_tendsto_drift {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ t x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) + (W X : Path) (k : ℕ) : + Tendsto (fun n => ((next (B n) W)^[k]) X) atTop (𝓝 (((next b W)^[k]) X)) := by + induction k with + | zero => exact tendsto_const_nhds + | succ k ih => simpa only [iterate_succ_apply'] using next_tendsto_drift hB ih W + + + +theorem solution_tendsto_drift {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ t x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) (W : Path) : + Tendsto (fun n => solution (B n) W) atTop (𝓝 (solution b W)) := by + obtain ⟨k,hk⟩ := (FloorSemiring.tendsto_pow_div_factorial_atTop (K:ℝ)).eventually + (gt_mem_nhds zero_lt_one) |>.exists + let C : ℝ≥0 := ⟨(K:ℝ)^k/k.factorial,by positivity⟩ + have hc (b' : Drift K M) : ContractingWith C ((next b' W)^[k]) := + ⟨hk,LipschitzWith.of_dist_le_mul fun X Y => dist_iterate b' W X Y k⟩ + have ht := iterate_tendsto_drift hB W (solution b W) k + rw [(solution_fixed b W).iterate k] at ht + have hz : Tendsto (fun n => dist (solution b W) (((next (B n) W)^[k]) (solution b W))/(1-(C:ℝ))) + atTop (𝓝 (0:ℝ)) := by + simpa only [dist_self,zero_div] using ((tendsto_const_nhds (x := solution b W)).dist ht).div_const (1-(C:ℝ)) + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun n => dist_nonneg) (fun n => ?_) hz + rw [dist_comm] + exact (hc (B n)).dist_le_of_fixedPoint _ ((solution_fixed (B n) W).iterate k) + +end ParisiPath + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +namespace BoundedCoefficient +variable {β : ℝ≥0} {C : ℕ → BoundedCoefficient β} {c : BoundedCoefficient β} + +lemma real_tendsto (hC : ∀ t,Tendsto (fun n => (C n).val t) atTop (𝓝 (c.val t))) (t : ℝ) : + Tendsto (fun n => (C n).real t) atTop (𝓝 (c.real t)) := + NNReal.continuous_coe.continuousAt.tendsto.comp (hC _) + +lemma gradient_tendsto (hβ : 0<β) + (hC : ∀ t,Tendsto (fun n => (C n).val t) atTop (𝓝 (c.val t))) (t : ℝ≥0) (x : ℝ) : + Tendsto (fun n => fieldGradient β (C n).val t x) atTop (𝓝 (fieldGradient β c.val t x)) := + fieldGradient_tendsto_coefficient β hβ (fun n => (C n).mono) (fun n => (C n).bound) + c.mono c.bound hC t x + +lemma drift_tendsto (hβ : 0<β) + (hC : ∀ t,Tendsto (fun n => (C n).val t) atTop (𝓝 (c.val t))) (t x : ℝ) : + Tendsto (fun n => (C n).drift t x) atTop (𝓝 (c.drift t x)) := + (real_tendsto hC t).mul (gradient_tendsto hβ hC _ x) + +lemma feedback_solution_tendsto (hβ : 0<β) + (hC : ∀ t,Tendsto (fun n => (C n).val t) atTop (𝓝 (c.val t))) (W : Path) : + Tendsto (fun n => solution ((C n).driftData hβ) W) atTop (𝓝 (solution (c.driftData hβ) W)) := + solution_tendsto_drift (drift_tendsto hβ hC) W + +lemma spin_tendsto (hβ : 0<β) + (hC : ∀ t,Tendsto (fun n => (C n).val t) atTop (𝓝 (c.val t))) + {X : ℕ → Path} {Y : Path} (hX : Tendsto X atTop (𝓝 Y)) (t : ℝ) : + Tendsto (fun n => (C n).spin (X n) t) atTop (𝓝 (c.spin Y t)) := by + have hx : Tendsto (fun n => ParisiPath.extend (X n) t) atTop (𝓝 (ParisiPath.extend Y t)) := + (show Continuous (fun V : Path => ParisiPath.extend V t) by unfold ParisiPath.extend;fun_prop).continuousAt.tendsto.comp hX + have hd : Tendsto (fun n => (C n).spin (X n) t-(C n).spin Y t) atTop (𝓝 (0:ℝ)) := by + have hnorm (n : ℕ) : ‖(C n).spin (X n) t-(C n).spin Y t‖ ≤ (β:ℝ)*‖ParisiPath.extend (X n) t-ParisiPath.extend Y t‖ := by + simpa only [←dist_eq_norm,spin] using + (fieldGradient_lipschitz β hβ (C n).mono (C n).bound _).dist_le_mul (ParisiPath.extend (X n) t) (ParisiPath.extend Y t) + exact squeeze_zero_norm hnorm (by simpa only [sub_self,norm_zero,mul_zero] using + (hx.sub_const (ParisiPath.extend Y t)).norm.const_mul (β:ℝ)) + have hh : Tendsto (fun n => (C n).spin Y t) atTop (𝓝 (c.spin Y t)) := + gradient_tendsto hβ hC _ (ParisiPath.extend Y t) + simpa only [sub_add_cancel,zero_add] using hd.add hh + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {K M : ℝ≥0} + +lemma expectedProduct_tendsto (hW : IsBrownianReal W P) (hβ : 0<β) + {D : ℕ → BoundedCoefficient β} {d : BoundedCoefficient β} + (hC : ∀ t,Tendsto (fun n => (C n).val t) atTop (𝓝 (c.val t))) + (hD : ∀ t,Tendsto (fun n => (D n).val t) atTop (𝓝 (d.val t))) + {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ t x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) (t : ℝ) : + Tendsto (fun n => expectedProduct P W (C n) (D n) (B n) t) atTop + (𝓝 (expectedProduct P W c d b t)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply tendsto_integral_of_dominated_convergence (fun _ => (1:ℝ)) + (fun n => (spin_product_integrable hW (C n) (D n) hβ (B n) t).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => norm_spin_product_le (C n) (D n) hβ _ t) + exact ae_of_all _ fun ω => (spin_tendsto hβ hC (solution_tendsto_drift hB (brownianPath W ω)) t).mul + (spin_tendsto hβ hD (solution_tendsto_drift hB (brownianPath W ω)) t) + +end BoundedCoefficient +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/MeasureCoefficientOnSupportGap.lean b/lean/OAI/Probability/ParisiFinite/MeasureCoefficientOnSupportGap.lean new file mode 100644 index 0000000000000000000000000000000000000000..85712bdbc5634bc8a8abb5b85def129618093f94 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/MeasureCoefficientOnSupportGap.lean @@ -0,0 +1,603 @@ +import Mathlib +import OAI.Probability.ParisiFinite.CanonicalSpatialTest + +namespace OAI + +/-! Measure Coefficient On Support Gap. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient + +lemma measureCoefficient_on_support_gap + (ρ : ProbabilityMeasure OrderPoint) (β : ℝ≥0) {a b : OrderPoint} + (hgap : ∀ x ∈ Ioo a b, x ∉ (ρ : Measure OrderPoint).support) + {r : ℝ≥0} (har : (a : ℝ) ≤ r) (hrb : (r : ℝ) < b) : + measureCoefficient ρ β r = Real.toNNReal ((ρ : Measure OrderPoint).real (Iic a)) * β := by + unfold measureCoefficient Measure.real + rw [ParisiGapGeometry.cdf_constant_on_gap _ hgap har hrb] + +lemma measureCoefficient_on_support_gap_pos + (ρ : ProbabilityMeasure OrderPoint) {β : ℝ≥0} (hβ : 0 < β) {a b : OrderPoint} + (ha : a ∈ (ρ : Measure OrderPoint).support) (hab : a < b) + (hgap : ∀ x ∈ Ioo a b, x ∉ (ρ : Measure OrderPoint).support) : + 0 < Real.toNNReal ((ρ : Measure OrderPoint).real (Iic a)) * β := by + apply mul_pos _ hβ + apply Real.toNNReal_pos.mpr + exact ENNReal.toReal_pos (ne_of_gt (ParisiGapGeometry.cdf_pos_at_gap_left _ ha hab hgap)) + (measure_ne_top _ _) + + + +theorem minimizingParisi_gap_of_not_full_support + {β : ℝ≥0} (hβ : 0 < β) {ρ : ProbabilityMeasure OrderPoint} + (hρ : IsMinimizingParisiMeasure β ρ) {q : OrderPoint} + (hq : q ∈ (ρ : Measure OrderPoint).support) + (hmax : ∀ t ∈ (ρ : Measure OrderPoint).support, t ≤ q) + (hne : (ρ : Measure OrderPoint).support ≠ Iic q) : + ∃ (a b : OrderPoint) (α : ℝ≥0), + a ∈ (ρ : Measure OrderPoint).support ∧ + b ∈ (ρ : Measure OrderPoint).support ∧ + a < b ∧ b ≤ q ∧ 0 < α ∧ + (∀ x ∈ Ioo a b, x ∉ (ρ : Measure OrderPoint).support) ∧ + ∀ r : ℝ≥0, (a : ℝ) ≤ r → (r : ℝ) < b → measureCoefficient ρ β r = α := by + obtain ⟨a, b, ha, hb, hab, hbq, hg⟩ := + ParisiGapGeometry.support_gap_endpoints (ρ : Measure OrderPoint) + (minimizingParisi_zero_in_support hβ hρ) hq hmax hne + refine ⟨a, b, _, ha, hb, hab, hbq, + measureCoefficient_on_support_gap_pos ρ hβ ha hab hg, hg, ?_⟩ + exact fun r har hrb => measureCoefficient_on_support_gap ρ β hg har hrb + + + +lemma dyadicSchedule_congr_on_Ico {γ δ : ℝ≥0 → ℝ≥0} {a b : ℝ≥0} + (h : Set.EqOn γ δ (Ico a b)) (t d : ℝ≥0) (ha : a ≤ t) + (hd : 0 < d) (ht : t + d ≤ b) (n : ℕ) : + dyadicSchedule γ false t d n = dyadicSchedule δ false t d n := by + induction n generalizing t d with + | zero => + simp only [dyadicSchedule, Bool.false_eq_true, ↓reduceIte] + rw [h ⟨ha, lt_of_lt_of_le (lt_add_of_pos_right t hd) ht⟩] + | succ n ih => + simp only [dyadicSchedule] + rw [ih t (d/2) ha (by positivity) (by nlinarith), + ih (t+d/2) (d/2) (by nlinarith) (by positivity) (by nlinarith)] + + + +lemma field_on_plateau (β : ℝ≥0) (hβ : 0 < β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s, γ s ≤ β) {a b α : ℝ≥0} + (hb1 : b ≤ 1) (hg : ∀ s ∈ Ico a b, γ s = α) + {t : ℝ≥0} (ht : t ∈ Ico a b) (x : ℝ) : + field β γ t x = step α (Real.sqrt (b-t)) (field β γ b) x := by + rw [field_DPP β hβ hγ hb ht.2.le hb1] + have he : dyadicEvolution γ t (b-t) (field β γ b) x = + dyadicEvolution (fun _ => α) t (b-t) (field β γ b) x := by + unfold dyadicEvolution + apply congrArg sSup + apply congrArg Set.range + funext n + rw [dyadicSchedule_congr_on_Ico (show Set.EqOn γ (fun _ => α) (Ico a b) from hg) + t (b-t) ht.1 (tsub_pos_iff_lt.mpr ht.2) + (by rw [add_tsub_cancel_of_le ht.2.le]) n] + rw [he, dyadicEvolution_constant (field_lipschitz β hβ hγ hb b) α t (b-t) x, + NNReal.coe_sub ht.2.le] + + + +def canonicalSmoothField (β : ℝ≥0) (hβ : 0 < β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s, γ s ≤ β) (t : ℝ≥0) : SmoothField where + val := field β γ t + d1 := fieldGradient β γ t + d2 := fieldCurvature β γ t + hasD1 := hasDerivAt_field β hβ hγ hb t + hasD2 := hasDerivAt_fieldGradient β hβ hγ hb t + continuousD2 := (fieldCurvature_lipschitz β hβ hγ hb t).continuous + bound1 := 1 + bound2 := β + normD1 := fieldGradient_bound β hβ hγ hb t + normD2 := fieldCurvature_abs β hβ hγ hb t + +lemma fieldGradient_on_plateau (β : ℝ≥0) (hβ : 0 < β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s, γ s ≤ β) {a b α : ℝ≥0} + (hb1 : b ≤ 1) (hg : ∀ s ∈ Ico a b, γ s = α) + {t : ℝ≥0} (ht : t ∈ Ico a b) (x : ℝ) : + fieldGradient β γ t x = + tiltedMean α (Real.sqrt (b-t)) (field β γ b) (fieldGradient β γ b) x := by + have he : field β γ t = step α (Real.sqrt (b-t)) (field β γ b) := + funext (field_on_plateau β hβ hγ hb hb1 hg ht) + apply (hasDerivAt_field β hβ hγ hb t x).unique + rw [he] + exact hasDerivAt_step (canonicalSmoothField β hβ hγ hb b) α (Real.sqrt (b-t)) x + + + +lemma fieldCurvature_on_plateau (β : ℝ≥0) (hβ : 0 < β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ s, γ s ≤ β) {a b α : ℝ≥0} + (hb1 : b ≤ 1) (hg : ∀ s ∈ Ico a b, γ s = α) + {t : ℝ≥0} (ht : t ∈ Ico a b) (x : ℝ) : + fieldCurvature β γ t x = + tiltedMean α (Real.sqrt (b-t)) (field β γ b) (fieldCurvature β γ b) x + + (α : ℝ) * (tiltedMean α (Real.sqrt (b-t)) (field β γ b) + (fun y => (fieldGradient β γ b y)^2) x - (fieldGradient β γ t x)^2) := by + have he : fieldGradient β γ t = + tiltedMean α (Real.sqrt (b-t)) (field β γ b) (fieldGradient β γ b) := + funext (fieldGradient_on_plateau β hβ hγ hb hb1 hg ht) + rw [congrFun he x] + apply (hasDerivAt_fieldGradient β hβ hγ hb t x).unique + rw [he] + exact hasDerivAt_tiltedMean_d1 (canonicalSmoothField β hβ hγ hb b) + α (Real.sqrt (b-t)) x + + + +lemma fieldGradient_tilted_variance_pos (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ r, γ r ≤ β) + (t : ℝ≥0) (α x : ℝ) {s : ℝ} (hs : s ≠ 0) : + 0 < tiltedMean α s (field β γ t) (fun y => (fieldGradient β γ t y)^2) x - + (tiltedMean α s (field β γ t) (fieldGradient β γ t) x)^2 := by + let f := canonicalSmoothField β hβ hγ hb t + let μ := transitionMeasure f α s x + let : Measure.IsOpenPosMeasure (gaussianReal 0 1) := + (gaussianReal_absolutelyContinuous' 0 (by norm_num : (1 : ℝ≥0) ≠ 0)).isOpenPosMeasure + let : Measure.IsOpenPosMeasure ((gaussianReal 0 1).tilted + (fun z => α*f.val (x+s*z))) := + (absolutelyContinuous_tilted (integrable_exp_shift f.lipschitz α x s)).isOpenPosMeasure + have hsur : Function.Surjective (fun z : ℝ => x+s*z) := by + intro y + refine ⟨(y-x)/s, ?_⟩ + field_simp + ring + let : Measure.IsOpenPosMeasure μ := + (show Continuous (fun z : ℝ => x+s*z) by fun_prop).isOpenPosMeasure_map hsur + have hm : MemLp f.d1 2 μ := MemLp.of_bound f.continuousD1.aestronglyMeasurable 1 + (ae_of_all _ fun y => f.normD1 y) + have hv : 0 < variance f.d1 μ := by + apply lt_of_le_of_ne (variance_nonneg _ _) (Ne.symm ?_) + intro hz + have hae := ae_eq_integral_of_variance_eq_zero hm hz + have he := Measure.eq_of_ae_eq hae f.continuousD1 continuous_const + have hd := f.hasD2 0 + rw [he] at hd + have hz2 := hd.unique (hasDerivAt_const 0 (∫ y, f.d1 y ∂μ)) + exact (fieldCurvature_bounds β hβ hγ hb t 0).1.ne' hz2 + rw [variance_eq_sub hm] at hv + change 0 < (∫ y, f.d1 y ^ 2 ∂transitionMeasure f α s x) - + (∫ y, f.d1 y ∂transitionMeasure f α s x)^2 at hv + rw [transition_integral f α s x (g := fun y => f.d1 y ^ 2) + (show Measurable (fun y => f.d1 y ^ 2) from (f.continuousD1.pow 2).measurable), + transition_integral f α s x f.continuousD1.measurable] at hv + exact hv + + + +lemma fieldCurvature_gt_tilted_mean_on_plateau (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ r, γ r ≤ β) + {a b α : ℝ≥0} (hb1 : b ≤ 1) (hα : 0 < α) + (hg : ∀ r ∈ Ico a b, γ r = α) {t : ℝ≥0} (ht : t ∈ Ico a b) (x : ℝ) : + tiltedMean α (Real.sqrt (b-t)) (field β γ b) (fieldCurvature β γ b) x < + fieldCurvature β γ t x := by + rw [fieldCurvature_on_plateau β hβ hγ hb hb1 hg ht, + fieldGradient_on_plateau β hβ hγ hb hb1 hg ht] + apply lt_add_of_pos_right + apply mul_pos (show (0 : ℝ) < α from hα) + exact fieldGradient_tilted_variance_pos β hβ hγ hb b α x + (Real.sqrt_pos.mpr (sub_pos.mpr (show (t : ℝ) < b from ht.2))).ne' + +section GapContact +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + + + +lemma minimizingParisi_squareCurvature_integral_between_support + (hW : IsBrownianReal W P) (hβ : 0 < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {a b : OrderPoint} (ha : a ∈ (ρ : Measure OrderPoint).support) + (hb : b ∈ (ρ : Measure OrderPoint).support) (hab : a ≤ b) : + (∫ t in (a : ℝ)..(b : ℝ), (ofMeasure β ρ).expectedSquareCurvature P W hβ t) = + (b : ℝ) - (a : ℝ) := by + let c := ofMeasure β ρ + have he := intervalIntegral.integral_eq_sub_of_hasDerivAt_of_le + (show (a : ℝ) ≤ (b : ℝ) from hab) + (expectedProduct_continuous hW c c hβ (c.driftData hβ)).continuousOn + (fun t ht => hasDerivAt_expectedProduct_self hW hβ c t + ⟨lt_of_le_of_lt a.property.1 ht.1, lt_of_lt_of_le ht.2 b.property.2⟩) + ((c.expectedSquareCurvature_continuous hW hβ).intervalIntegrable _ _) + rw [minimizingParisi_selfConsistency hW hβ hρ ha, + minimizingParisi_selfConsistency hW hβ hρ hb] at he + exact he + + +lemma minimizingParisi_deviation_integral_between_support + (hW : IsBrownianReal W P) (hβ : 0 < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {a b : OrderPoint} (ha : a ∈ (ρ : Measure OrderPoint).support) + (hb : b ∈ (ρ : Measure OrderPoint).support) : + (∫ t in (a : ℝ)..(b : ℝ), deviation P W hβ (ofMeasure β ρ) t) = 0 := by + have he := le_antisymm (minimizingParisi_support_potential hW hβ hρ ha b) + (minimizingParisi_support_potential hW hβ hρ hb a) + have hc := continuous_deviation hW hβ (ofMeasure β ρ) + have hadd := intervalIntegral.integral_add_adjacent_intervals + (hc.intervalIntegrable (μ := volume) (a : ℝ) b) + (hc.intervalIntegrable (μ := volume) (b : ℝ) 1) + unfold variationalPotential at he + linarith + + + +lemma minimizingParisi_deviation_integral_le_zero + (hW : IsBrownianReal W P) (hβ : 0 < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {a : OrderPoint} (ha : a ∈ (ρ : Measure OrderPoint).support) (t : OrderPoint) : + (∫ s in (a : ℝ)..(t : ℝ), deviation P W hβ (ofMeasure β ρ) s) ≤ 0 := by + have he := minimizingParisi_support_potential hW hβ hρ ha t + have hc := continuous_deviation hW hβ (ofMeasure β ρ) + have hadd := intervalIntegral.integral_add_adjacent_intervals + (hc.intervalIntegrable (μ := volume) (a : ℝ) t) + (hc.intervalIntegrable (μ := volume) (t : ℝ) 1) + unfold variationalPotential at he + linarith + + + +lemma minimizingParisi_replicon_zero (hW : IsBrownianReal W P) (hβ : 0 < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + (hz : (⟨0, by simp⟩ : OrderPoint) ∈ (ρ : Measure OrderPoint).support) : + (ofMeasure β ρ).expectedSquareCurvature P W hβ 0 ≤ 1 := by + let c := ofMeasure β ρ + let f := c.expectedSquareCurvature P W hβ + let g := deviation P W hβ c + let G := fun t : ℝ => (∫ s in (0 : ℝ)..t, f s) - t + have hf : Continuous f := c.expectedSquareCurvature_continuous hW hβ + have hg : Continuous g := continuous_deviation hW hβ c + have hG : HasDerivAt G (f 0 - 1) 0 := + (intervalIntegral.integral_hasDerivAt_right (hf.intervalIntegrable 0 0) + hf.stronglyMeasurable.stronglyMeasurableAtFilter hf.continuousAt).sub + (hasDerivAt_id (0 : ℝ)) + have hG0 : G 0 = 0 := by simp [G] + have hEq (t : ℝ) (ht : t ∈ Ioo (0 : ℝ) 1) : g t = G t := by + change expectedProduct P W c c (c.driftData hβ) t - t = _ + rw [spin_mean_square_evolution hW hβ c t ht] + by_contra hn + have hp : 0 < f 0 - 1 := sub_pos.mpr (not_le.mp hn) + have hs := (hG.tendsto_slope.mono_left (nhdsGT_le_nhdsNE (0 : ℝ))).eventually + (lt_mem_nhds hp) + have hev : ∀ᶠ t in 𝓝[>] (0 : ℝ), 0 < g t ∧ t < 1 := by + filter_upwards [hs, self_mem_nhdsWithin, + (eventually_lt_nhds (by norm_num : (0 : ℝ) < 1)).filter_mono nhdsWithin_le_nhds] + with t hs ht ht1 + refine ⟨?_, ht1⟩ + rw [slope_def_field] at hs + change 0 < (G t - G 0) / (t - 0) at hs + rw [hG0, sub_zero, sub_zero] at hs + rw [hEq t ⟨ht, ht1⟩] + exact (div_pos_iff_of_pos_right ht).mp hs + obtain ⟨u, hu, hsub⟩ := mem_nhdsGT_iff_exists_Ioc_subset.mp hev + have hu1 : u < 1 := (hsub ⟨hu, le_rfl⟩).2 + have hi : 0 < ∫ t in (0 : ℝ)..u, g t := + intervalIntegral.integral_pos hu hg.continuousOn + (fun t ht => (hsub ht).1.le) ⟨u, ⟨hu.le, le_rfl⟩, (hsub ⟨hu, le_rfl⟩).1⟩ + have hmin := minimizingParisi_deviation_integral_le_zero hW hβ hρ hz + ⟨u, hu.le, hu1.le⟩ + exact (not_lt_of_ge hmin) hi + +lemma minimizingParisi_replicon_of_lt_one (hW : IsBrownianReal W P) (hβ : 0 < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {t : OrderPoint} (ht : t ∈ (ρ : Measure OrderPoint).support) (h1 : (t : ℝ) < 1) : + (ofMeasure β ρ).expectedSquareCurvature P W hβ t ≤ 1 := by + by_cases h0 : (t : ℝ) = 0 + · have he : t = (⟨0, by simp⟩ : OrderPoint) := Subtype.ext h0 + subst t + exact minimizingParisi_replicon_zero hW hβ hρ ht + · exact minimizingParisi_replicon hW hβ hρ ht + (lt_of_le_of_ne t.property.1 (Ne.symm h0)) h1 + + + +theorem minimizingParisi_not_strictConvex_between_support + (hW : IsBrownianReal W P) (hβ : 0 < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {a b : OrderPoint} (ha : a ∈ (ρ : Measure OrderPoint).support) + (hb : b ∈ (ρ : Measure OrderPoint).support) (hab : a < b) (hb1 : (b : ℝ) < 1) : + ¬ StrictConvexOn ℝ (Icc (a : ℝ) (b : ℝ)) + ((ofMeasure β ρ).expectedSquareCurvature P W hβ) := by + intro hconv + let c := ofMeasure β ρ + let f := c.expectedSquareCurvature P W hβ + have hab' : (a : ℝ) < b := hab + have ha1 := minimizingParisi_replicon_of_lt_one hW hβ hρ ha (hab'.trans hb1) + have hb1' := minimizingParisi_replicon_of_lt_one hW hβ hρ hb hb1 + have hends : max (f a) (f b) ≤ 1 := max_le ha1 hb1' + have hac : (a : ℝ) ∈ Icc (a : ℝ) (b : ℝ) := ⟨le_rfl, hab'.le⟩ + have hbc : (b : ℝ) ∈ Icc (a : ℝ) (b : ℝ) := ⟨hab'.le, le_rfl⟩ + have hle : ∀ t ∈ Ioc (a : ℝ) (b : ℝ), f t ≤ 1 := by + intro t ht + exact (hconv.convexOn.le_on_segment hac hbc (Icc_subset_segment ⟨ht.1.le, ht.2⟩)).trans hends + have hm : ((a : ℝ) + b) / 2 ∈ Ioo (a : ℝ) (b : ℝ) := by + constructor <;> linarith + have hlt : f (((a : ℝ) + b)/2) < 1 := + (hconv.lt_on_openSegment hac hbc hab'.ne (Ioo_subset_openSegment hm)).trans_le hends + have hint := intervalIntegral.integral_lt_integral_of_continuousOn_of_le_of_exists_lt + hab' (c.expectedSquareCurvature_continuous hW hβ).continuousOn + (continuous_const (y := (1 : ℝ))).continuousOn hle + ⟨((a : ℝ) + b)/2, Ioo_subset_Icc_self hm, hlt⟩ + rw [minimizingParisi_squareCurvature_integral_between_support hW hβ hρ ha hb hab.le] at hint + simp only [intervalIntegral.integral_const, smul_eq_mul, mul_one, lt_self_iff_false] at hint + +end GapContact + + + +theorem minimizingParisi_noGap_countercase {β : ℝ≥0} (hβ : (1 : ℝ) < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + (hne : ¬ ∃ q : OrderPoint, 0 < (q : ℝ) ∧ (q : ℝ) < 1 ∧ + (ρ : Measure OrderPoint).support = Iic q) : + ∃ (hbp : 0 < β) (a b : OrderPoint) (α : ℝ≥0), + a ∈ (ρ : Measure OrderPoint).support ∧ b ∈ (ρ : Measure OrderPoint).support ∧ + a < b ∧ (b : ℝ) < 1 ∧ 0 < α ∧ + (∀ x ∈ Ioo a b, x ∉ (ρ : Measure OrderPoint).support) ∧ + (∀ r : ℝ≥0, (a : ℝ) ≤ r → (r : ℝ) < b → measureCoefficient ρ β r = α) ∧ + (∫ t in (a : ℝ)..(b : ℝ), (ofMeasure β ρ).expectedSquareCurvature + BrownianConstruction.brownianMeasure BrownianConstruction.brownianMotion hbp t) = + (b : ℝ) - (a : ℝ) ∧ + (∫ t in (a : ℝ)..(b : ℝ), deviation BrownianConstruction.brownianMeasure + BrownianConstruction.brownianMotion hbp (ofMeasure β ρ) t) = 0 ∧ + (∀ t : OrderPoint, (∫ s in (a : ℝ)..(t : ℝ), deviation + BrownianConstruction.brownianMeasure BrownianConstruction.brownianMotion + hbp (ofMeasure β ρ) s) ≤ 0) ∧ + ¬ StrictConvexOn ℝ (Icc (a : ℝ) (b : ℝ)) ((ofMeasure β ρ).expectedSquareCurvature + BrownianConstruction.brownianMeasure BrownianConstruction.brownianMotion hbp) := by + have hbp : 0 < β := by exact_mod_cast (zero_lt_one.trans hβ) + obtain ⟨q, hq0, hq1, hq, hmax, _⟩ := minimizingParisi_support_boundary hβ hρ + have hneq : (ρ : Measure OrderPoint).support ≠ Iic q := fun he => hne ⟨q, hq0, hq1, he⟩ + obtain ⟨a, b, α, ha, hb, hab, hbq, hα, hg, hc⟩ := + minimizingParisi_gap_of_not_full_support hbp hρ hq hmax hneq + have hb1 : (b : ℝ) < 1 := (show (b : ℝ) ≤ q from hbq).trans_lt hq1 + refine ⟨hbp, a, b, α, ha, hb, hab, hb1, hα, hg, hc, ?_, ?_, ?_, ?_⟩ + · exact minimizingParisi_squareCurvature_integral_between_support + BrownianConstruction.brownianMotion_isBrownian hbp hρ ha hb hab.le + · exact minimizingParisi_deviation_integral_between_support + BrownianConstruction.brownianMotion_isBrownian hbp hρ ha hb + · exact minimizingParisi_deviation_integral_le_zero + BrownianConstruction.brownianMotion_isBrownian hbp hρ ha + · exact minimizingParisi_not_strictConvex_between_support + BrownianConstruction.brownianMotion_isBrownian hbp hρ ha hb hab hb1 + +end ParisiFinite + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient + + +private lemma contact_area_has_interior_localMax {f : ℝ → ℝ} {a b : ℝ} + (hab : a < b) (hf : Continuous f) (ha : f a ≤ 1) (hb : f b ≤ 1) + (harea : (∫ t in a..b, f t) = b - a) : + ∃ t ∈ Ioo a b, 1 ≤ f t ∧ IsLocalMax f t := by + by_cases hgt : ∃ s ∈ Icc a b, 1 < f s + · obtain ⟨s, hs, hfs⟩ := hgt + obtain ⟨t, ht, hmax⟩ := isCompact_Icc.exists_isMaxOn + (nonempty_Icc.mpr hab.le) hf.continuousOn + have hft : 1 < f t := hfs.trans_le (hmax hs) + have hat : a < t := lt_of_le_of_ne ht.1 (by + intro he + subst t + exact (not_lt_of_ge ha) hft) + have htb : t < b := lt_of_le_of_ne ht.2 (by + intro he + subst t + exact (not_lt_of_ge hb) hft) + exact ⟨t, ⟨hat, htb⟩, hft.le, hmax.isLocalMax (Icc_mem_nhds hat htb)⟩ + · have hle : ∀ s ∈ Icc a b, f s ≤ 1 := by + intro s hs + exact not_lt.mp (fun h => hgt ⟨s, hs, h⟩) + let t := (a + b) / 2 + have ht : t ∈ Ioo a b := by dsimp [t]; constructor <;> linarith + have hft : 1 ≤ f t := by + by_contra hn + have hlt := intervalIntegral.integral_lt_integral_of_continuousOn_of_le_of_exists_lt + hab hf.continuousOn (continuous_const (y := (1 : ℝ))).continuousOn + (fun s hs => hle s (Ioc_subset_Icc_self hs)) + ⟨t, Ioo_subset_Icc_self ht, not_le.mp hn⟩ + rw [harea] at hlt + simp only [intervalIntegral.integral_const, smul_eq_mul, mul_one, + lt_self_iff_false] at hlt + refine ⟨t, ht, hft, ?_⟩ + apply IsMaxOn.isLocalMax (s := Icc a b) ?_ (Icc_mem_nhds ht.1 ht.2) + intro s hs + exact (hle s hs).trans hft + + + +theorem minimizingParisi_localMax_between_support + {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + {β : ℝ≥0} (hW : IsBrownianReal W P) (hβ : 0 < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {a b : OrderPoint} (ha : a ∈ (ρ : Measure OrderPoint).support) + (hb : b ∈ (ρ : Measure OrderPoint).support) (hab : a < b) (hb1 : (b : ℝ) < 1) : + ∃ t ∈ Ioo (a : ℝ) (b : ℝ), + 1 ≤ (ofMeasure β ρ).expectedSquareCurvature P W hβ t ∧ + IsLocalMax ((ofMeasure β ρ).expectedSquareCurvature P W hβ) t := by + exact contact_area_has_interior_localMax hab + ((ofMeasure β ρ).expectedSquareCurvature_continuous hW hβ) + (minimizingParisi_replicon_of_lt_one hW hβ hρ ha + ((show (a : ℝ) < b from hab).trans hb1)) + (minimizingParisi_replicon_of_lt_one hW hβ hρ hb hb1) + (minimizingParisi_squareCurvature_integral_between_support hW hβ hρ ha hb hab.le) + + + +theorem minimizingParisi_positive_plateau_localMax_countercase + {β : ℝ≥0} (hβ : (1 : ℝ) < β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + (hne : ¬ ∃ q : OrderPoint, 0 < (q : ℝ) ∧ (q : ℝ) < 1 ∧ + (ρ : Measure OrderPoint).support = Iic q) : + ∃ (hbp : 0 < β) (a b : OrderPoint) (α : ℝ≥0) (t : ℝ), + a ∈ (ρ : Measure OrderPoint).support ∧ b ∈ (ρ : Measure OrderPoint).support ∧ + a < b ∧ (b : ℝ) < 1 ∧ 0 < α ∧ + (∀ x ∈ Ioo a b, x ∉ (ρ : Measure OrderPoint).support) ∧ + (∀ r : ℝ≥0, (a : ℝ) ≤ r → (r : ℝ) < b → measureCoefficient ρ β r = α) ∧ + t ∈ Ioo (a : ℝ) (b : ℝ) ∧ + 1 ≤ (ofMeasure β ρ).expectedSquareCurvature + BrownianConstruction.brownianMeasure BrownianConstruction.brownianMotion hbp t ∧ + IsLocalMax ((ofMeasure β ρ).expectedSquareCurvature + BrownianConstruction.brownianMeasure BrownianConstruction.brownianMotion hbp) t := by + obtain ⟨hbp, a, b, α, ha, hb, hab, hb1, hα, hg, hc, _⟩ := + minimizingParisi_noGap_countercase hβ hρ hne + obtain ⟨t, ht, hft, hmax⟩ := minimizingParisi_localMax_between_support + BrownianConstruction.brownianMotion_isBrownian hbp hρ ha hb hab hb1 + exact ⟨hbp, a, b, α, t, ha, hb, hab, hb1, hα, hg, hc, ht, hft, hmax⟩ + +end ParisiFinite + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + + + +def terminalPerturbation (f g : SmoothField) (u : ℝ) : SmoothField where + val x := f.val x + Real.sin u*g.val x + d1 x := f.d1 x + Real.sin u*g.d1 x + d2 x := f.d2 x + Real.sin u*g.d2 x + hasD1 x := (f.hasD1 x).add ((g.hasD1 x).const_mul _) + hasD2 x := (f.hasD2 x).add ((g.hasD2 x).const_mul _) + continuousD2 := f.continuousD2.add (g.continuousD2.const_mul _) + bound1 := f.bound1+g.bound1 + bound2 := f.bound2+g.bound2 + normD1 x := by + apply (abs_add_le _ _).trans + rw [abs_mul] + exact add_le_add (f.normD1 x) + ((mul_le_mul (Real.abs_sin_le_one u) (g.normD1 x) (abs_nonneg _) zero_le_one).trans_eq (one_mul _)) + normD2 x := by + apply (abs_add_le _ _).trans + rw [abs_mul] + exact add_le_add (f.normD2 x) + ((mul_le_mul (Real.abs_sin_le_one u) (g.normD2 x) (abs_nonneg _) zero_le_one).trans_eq (one_mul _)) + +def SmoothField.directional (f : SmoothField) : DirectionalField ℝ where + val := f.val + first v x := v*f.d1 x + second v w x := v*w*f.d2 x + lip := f.bound1 + lipschitz := f.lipschitz + continuousFirst v := f.continuousD1.const_mul v + continuousSecond v w := f.continuousD2.const_mul (v*w) + hasFirst v x t := by + simpa only [smul_eq_mul, Function.comp_def, id_eq, one_mul, mul_one, mul_comm] using + (f.hasD1 (x+t*v)).comp t ((hasDerivAt_id t).mul_const v |>.const_add x) + hasSecond v w x t := by + simpa only [smul_eq_mul, Function.comp_def, id_eq, one_mul, mul_one, + mul_assoc, mul_comm, mul_left_comm] using + ((f.hasD2 (x+t*v)).comp t + ((hasDerivAt_id t).mul_const v |>.const_add x)).const_mul w + boundFirst v := Real.nnabs v*f.bound1 + boundSecond v w := Real.nnabs v*Real.nnabs w*f.bound2 + normFirst v x := by + simpa only [abs_mul, NNReal.coe_mul, Real.coe_nnabs] using + mul_le_mul_of_nonneg_left (f.normD1 x) (abs_nonneg v) + normSecond v w x := by + simpa only [abs_mul, NNReal.coe_mul, Real.coe_nnabs, mul_assoc] using + mul_le_mul_of_nonneg_left (f.normD2 x) (mul_nonneg (abs_nonneg v) (abs_nonneg w)) + +def terminalFamily (f g : SmoothField) (R : ℝ≥0) (hR : ∀ x, |g.val x|≤R) : FieldFamily ℝ where + field u := (terminalPerturbation f g u).directional + dot u x := Real.cos u*g.val x + continuousVal := by + change Continuous (fun p : ℝ×ℝ => f.val p.2+Real.sin p.1*g.val p.2) + exact (f.continuousVal.comp continuous_snd).add + ((Real.continuous_sin.comp continuous_fst).mul (g.continuousVal.comp continuous_snd)) + continuousFirst v := by + change Continuous (fun p : ℝ×ℝ => v*(f.d1 p.2+Real.sin p.1*g.d1 p.2)) + have hf := f.continuousD1 + have hg := g.continuousD1 + fun_prop + continuousSecond v w := by + change Continuous (fun p : ℝ×ℝ => v*w*(f.d2 p.2+Real.sin p.1*g.d2 p.2)) + have hf := f.continuousD2 + have hg := g.continuousD2 + fun_prop + continuousDot := (Real.continuous_cos.comp continuous_fst).mul (g.continuousVal.comp continuous_snd) + hasDot x u := (Real.hasDerivAt_sin u).mul_const (g.val x) |>.const_add (f.val x) + lip := f.bound1+g.bound1 + lipschitz u := (terminalPerturbation f g u).lipschitz + boundFirst v := Real.nnabs v*(f.bound1+g.bound1) + boundSecond v w := Real.nnabs v*Real.nnabs w*(f.bound2+g.bound2) + boundDot _ := R + continuousBound := continuous_const + normFirst u v x := (terminalPerturbation f g u).directional.normFirst v x + normSecond u v w x := (terminalPerturbation f g u).directional.normSecond v w x + normDot u x := by + rw [abs_mul] + exact (mul_le_mul (Real.abs_cos_le_one u) (hR x) (abs_nonneg _) zero_le_one).trans_eq (one_mul _) + + +def evolveFamily (F : FieldFamily ℝ) : Schedule → FieldFamily ℝ + | [] => F + | (a,d)::ls => (evolveFamily F ls).transform a 1 (fun _ => Real.sqrt d) (fun _ => 0) + continuous_const continuous_const (fun u => hasDerivAt_const u _) + +lemma ambientStep_real (a s : ℝ) (f : ℝ → ℝ) (x : ℝ) : + ambientStep a s f x = step a s f x := by + simp only [ambientStep, step, smul_eq_mul, mul_comm s] + +lemma ambientTilt_real (a s : ℝ) (f g : ℝ → ℝ) (x : ℝ) : + ambientTilt a s f g x = tiltedMean a s f g x := by + simp only [ambientTilt, ambientMoment, ambientMass, tiltedMean, expMoment, expMass, + smul_eq_mul, mul_comm s] + +lemma evolveFamily_val (F : FieldFamily ℝ) (ls : Schedule) (u x : ℝ) : + ((evolveFamily F ls).field u).val x = evolve ls (F.field u).val x := by + induction ls generalizing x with + | nil => rfl + | cons l ls ih => + dsimp only [evolveFamily, FieldFamily.transform, DirectionalField.transform] + simp only [smul_eq_mul, mul_one, ambientStep_real] + rw [funext ih] + rfl + + +def linearEvolve (f g : ℝ → ℝ) : Schedule → ℝ → ℝ + | [] => g + | (a,d)::ls => tiltedMean a (Real.sqrt d) (evolve ls f) (linearEvolve f g ls) + +lemma evolveFamily_dot (F : FieldFamily ℝ) (ls : Schedule) (u x : ℝ) : + (evolveFamily F ls).dot u x = linearEvolve (F.field u).val (F.dot u) ls x := by + induction ls generalizing x with + | nil => rfl + | cons l ls ih => + dsimp only [evolveFamily, FieldFamily.transform, FieldFamily.transformedDot] + simp only [mul_zero, zero_mul, add_zero, smul_eq_mul, mul_one, ambientTilt_real] + rw [funext (evolveFamily_val F ls u), funext ih] + rfl + +lemma hasDerivAt_evolve_terminal (f g : SmoothField) (R : ℝ≥0) + (hR : ∀ x, |g.val x|≤R) (ls : Schedule) (x : ℝ) : + HasDerivAt (fun u => evolve ls (terminalPerturbation f g u).val x) + (linearEvolve f.val g.val ls x) 0 := by + have hh := (evolveFamily (terminalFamily f g R hR) ls).hasDot x 0 + simp_rw [evolveFamily_val, evolveFamily_dot] at hh + simpa only [terminalFamily, SmoothField.directional, terminalPerturbation, + Real.sin_zero, Real.cos_zero, zero_mul, add_zero, one_mul] using hh + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Mix.lean b/lean/OAI/Probability/ParisiFinite/Mix.lean new file mode 100644 index 0000000000000000000000000000000000000000..072f4a2b7e48b0b7affdcc71af8b386b09139316 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Mix.lean @@ -0,0 +1,642 @@ +import Mathlib +import OAI.Probability.ParisiFinite.MeasurableStepParam + +namespace OAI + +/-! Mix. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +namespace BoundedCoefficient +variable {β : ℝ≥0} + +def mix (c d : BoundedCoefficient β) (θ : ℝ≥0) (hθ : θ≤1) : BoundedCoefficient β where + val := fun t => (1-θ)*c.val t+θ*d.val t + mono := fun s t h => add_le_add (mul_le_mul_of_nonneg_left (c.mono h) (by positivity)) + (mul_le_mul_of_nonneg_left (d.mono h) (by positivity)) + bound := fun t => (add_le_add (mul_le_mul_of_nonneg_left (c.bound t) (by positivity)) + (mul_le_mul_of_nonneg_left (d.bound t) (by positivity))).trans_eq (by rw [←add_mul,tsub_add_cancel_of_le hθ,one_mul]) + +lemma mix_real (c d : BoundedCoefficient β) (θ : ℝ≥0) (hθ : θ≤1) (t : ℝ) : + (c.mix d θ hθ).real t=(1-(θ:ℝ))*c.real t+(θ:ℝ)*d.real t := by + simp only [mix,real,NNReal.coe_add,NNReal.coe_mul,NNReal.coe_sub hθ,NNReal.coe_one] + +lemma mix_difference (c d : BoundedCoefficient β) (θ : ℝ≥0) (hθ : θ≤1) (t : ℝ) : + (c.mix d θ hθ).real t-c.real t=(θ:ℝ)*(d.real t-c.real t) := by rw [mix_real];ring + +lemma mix_tendsto (c d : BoundedCoefficient β) {Θ : ℕ → ℝ≥0} (hΘ : ∀ n,Θ n≤1) + (hθ : Tendsto Θ atTop (𝓝 0)) (t : ℝ≥0) : + Tendsto (fun n => (c.mix d (Θ n) (hΘ n)).val t) atTop (𝓝 (c.val t)) := by + apply NNReal.tendsto_coe.mp + have hθ' := NNReal.continuous_coe.continuousAt.tendsto.comp hθ + simpa only [mix,NNReal.coe_add,NNReal.coe_mul,NNReal.coe_sub (hΘ _),NNReal.coe_one, + NNReal.coe_zero,sub_zero,one_mul,zero_mul,add_zero,Function.comp_def] using + (((tendsto_const_nhds (x := (1:ℝ))).sub hθ').mul_const (c.val t:ℝ)).add (hθ'.mul_const (d.val t:ℝ)) + +lemma norm_direction_le (c d : BoundedCoefficient β) (t : ℝ) : ‖(d.real t-c.real t)/2‖≤β := by + rw [Real.norm_eq_abs,abs_div,abs_of_pos (by norm_num : (0:ℝ)<2)] + have hh : |d.real t-c.real t|≤β := abs_le.mpr ⟨by linarith [c.real_le t,d.real_nonneg t], + by linarith [d.real_le t,c.real_nonneg t]⟩ + linarith [β.coe_nonneg] + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {K M : ℝ≥0} + +def variationIntegral (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (c d e f : BoundedCoefficient β) (b : Drift K M) : ℝ := + ∫ t in (0:ℝ)..1,(d.real t-c.real t)/2*expectedProduct P W e f b t + +lemma variation_integrable (hW : IsBrownianReal W P) (hβ : 0<β) + (c d e f : BoundedCoefficient β) (b : Drift K M) : + IntervalIntegrable (fun t => (d.real t-c.real t)/2*expectedProduct P W e f b t) volume 0 1 := + (((d.real_intervalIntegrable 0 1).sub (c.real_intervalIntegrable 0 1)).div_const 2).mul_continuousOn + (expectedProduct_continuous hW e f hβ b).continuousOn + +lemma variationIntegral_tendsto (hW : IsBrownianReal W P) (hβ : 0<β) + (c d : BoundedCoefficient β) {E F : ℕ → BoundedCoefficient β} {e f : BoundedCoefficient β} + (hE : ∀ t,Tendsto (fun n => (E n).val t) atTop (𝓝 (e.val t))) + (hF : ∀ t,Tendsto (fun n => (F n).val t) atTop (𝓝 (f.val t))) + {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ t x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) : + Tendsto (fun n => variationIntegral P W c d (E n) (F n) (B n)) atTop + (𝓝 (variationIntegral P W c d e f b)) := by + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence (fun _ => (β:ℝ)) + (Eventually.of_forall fun n => by + simpa only [uIoc_of_le zero_le_one] using + (variation_integrable hW hβ c d (E n) (F n) (B n)).1.aestronglyMeasurable) + (Eventually.of_forall fun n => ?_) intervalIntegrable_const + · exact ae_of_all _ fun t _ => (expectedProduct_tendsto hW hβ hE hF hB t).const_mul _ + · exact ae_of_all _ fun t _ => by + rw [norm_mul] + exact (mul_le_mul (norm_direction_le c d t) (expectedProduct_bound hW (E n) (F n) hβ (B n) t) + (norm_nonneg _) β.coe_nonneg).trans_eq (mul_one _) + + + +theorem field_first_variation (hW : IsBrownianReal W P) (hβ : 0<β) (c d : BoundedCoefficient β) + {Θ : ℕ → ℝ≥0} (hΘ : ∀ n,Θ n≤1) (hΘpos : ∀ n,0<Θ n) (hθ : Tendsto Θ atTop (𝓝 0)) : + Tendsto (fun n => (field β (c.mix d (Θ n) (hΘ n)).val 0 0-field β c.val 0 0)/(Θ n:ℝ)) atTop + (𝓝 (variationIntegral P W c d c c (c.driftData hβ))) := by + let C (n : ℕ) := c.mix d (Θ n) (hΘ n) + have hC : ∀ t,Tendsto (fun n => (C n).val t) atTop (𝓝 (c.val t)) := mix_tendsto c d hΘ hθ + have hl := variationIntegral_tendsto hW hβ c d hC hC + (B := fun _ => c.driftData hβ) (b := c.driftData hβ) (fun _ _ => tendsto_const_nhds) + have hu := variationIntegral_tendsto hW hβ c d + (E := fun _ => c) (F := fun _ => c) (e := c) (f := c) (fun _ => tendsto_const_nhds) + (fun _ => tendsto_const_nhds) (B := fun n => (C n).driftData hβ) + (b := c.driftData hβ) (drift_tendsto hβ hC) + apply tendsto_of_tendsto_of_tendsto_of_le_of_le hl hu + · intro n + have hh := field_comparison_lower hW (C n) c hβ + have he : (∫ t in (0:ℝ)..1,((C n).real t-c.real t)/2*expectedProduct P W (C n) (C n) (c.driftData hβ) t)= + (Θ n:ℝ)*variationIntegral P W c d (C n) (C n) (c.driftData hβ) := by + rw [variationIntegral,←intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro t _ + dsimp only [C] + rw [mix_difference] + ring + rw [he] at hh + exact (le_div_iff₀ (show (0:ℝ)<Θ n from hΘpos n)).mpr (by nlinarith) + · intro n + have hh := field_comparison_upper hW (C n) c hβ + have he : (∫ t in (0:ℝ)..1,((C n).real t-c.real t)/2*expectedProduct P W c c ((C n).driftData hβ) t)= + (Θ n:ℝ)*variationIntegral P W c d c c ((C n).driftData hβ) := by + rw [variationIntegral,←intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro t _ + dsimp only [C] + rw [mix_difference] + ring + rw [he] at hh + exact (div_le_iff₀ (show (0:ℝ)<Θ n from hΘpos n)).mpr (by nlinarith) + +lemma penalty_mix_sub (c d : BoundedCoefficient β) (θ : ℝ≥0) (hθ : θ≤1) : + coefficientPenalty (c.mix d θ hθ).val 0 1-coefficientPenalty c.val 0 1= + (θ:ℝ)*(∫ t in (0:ℝ)..1,t*(d.real t-c.real t)/2) := by + simp only [coefficientPenalty,zero_add,NNReal.coe_zero,NNReal.coe_one] + change (∫ t in (0:ℝ)..1,t*(c.mix d θ hθ).real t/2)-(∫ t in (0:ℝ)..1,t*c.real t/2)=_ + have h1 : IntervalIntegrable (fun t => t*(c.mix d θ hθ).real t/2) volume 0 1 := + coefficient_integrable (c.mix d θ hθ).mono 0 1 + have h2 : IntervalIntegrable (fun t => t*c.real t/2) volume 0 1 := coefficient_integrable c.mono 0 1 + rw [←intervalIntegral.integral_sub h1 h2,←intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro t _ + dsimp only + rw [mix_real] + ring + +def firstVariation (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) (hβ : 0<β) + (c d : BoundedCoefficient β) : ℝ := + ∫ t in (0:ℝ)..1,(d.real t-c.real t)/2*(expectedProduct P W c c (c.driftData hβ) t-t) + +lemma firstVariation_eq (hW : IsBrownianReal W P) (hβ : 0<β) (c d : BoundedCoefficient β) : + firstVariation P W hβ c d=variationIntegral P W c d c c (c.driftData hβ)- + (∫ t in (0:ℝ)..1,t*(d.real t-c.real t)/2) := by + have hp : IntervalIntegrable (fun t => t*(d.real t-c.real t)/2) volume 0 1 := by + have hh := (coefficient_integrable d.mono 0 1).sub (coefficient_integrable c.mono 0 1) + convert! hh using 1 + ext t + dsimp only [real] + ring + rw [variationIntegral,←intervalIntegral.integral_sub (variation_integrable hW hβ c d c c _) hp] + apply intervalIntegral.integral_congr + intro t _ + ring + + + +theorem functional_first_variation (hW : IsBrownianReal W P) (hβ : 0<β) (c d : BoundedCoefficient β) + {Θ : ℕ → ℝ≥0} (hΘ : ∀ n,Θ n≤1) (hΘpos : ∀ n,0<Θ n) (hθ : Tendsto Θ atTop (𝓝 0)) : + Tendsto (fun n => (orderParameterFunctional β (c.mix d (Θ n) (hΘ n)).val- + orderParameterFunctional β c.val)/(Θ n:ℝ)) atTop (𝓝 (firstVariation P W hβ c d)) := by + have hh := (field_first_variation hW hβ c d hΘ hΘpos hθ).sub_const + (∫ t in (0:ℝ)..1,t*(d.real t-c.real t)/2) + rw [←firstVariation_eq hW hβ c d] at hh + convert! hh using 1 + ext n + have he := penalty_mix_sub c d (Θ n) (hΘ n) + have hne : (Θ n:ℝ)≠0 := (show (0:ℝ)<Θ n from hΘpos n).ne' + simp only [orderParameterFunctional,field,tsub_zero] + field_simp + nlinarith + +end BoundedCoefficient +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite + +def probabilityMix (ρ ν : ProbabilityMeasure OrderPoint) (θ : ℝ≥0) (hθ : θ≤1) : + ProbabilityMeasure OrderPoint := + ⟨(1-θ) • (ρ:Measure OrderPoint)+θ • (ν:Measure OrderPoint),by + apply isProbabilityMeasure_iff.mpr + simp only [Measure.add_apply,Measure.coe_nnreal_smul_apply,measure_univ,mul_one] + rw [←ENNReal.coe_add,tsub_add_cancel_of_le hθ] + rfl⟩ + +lemma probabilityMix_real (ρ ν : ProbabilityMeasure OrderPoint) (θ : ℝ≥0) (hθ : θ≤1) + (s : Set OrderPoint) : + (probabilityMix ρ ν θ hθ:Measure OrderPoint).real s= + (1-(θ:ℝ))*(ρ:Measure OrderPoint).real s+(θ:ℝ)*(ν:Measure OrderPoint).real s := by + change (((1-θ) • (ρ:Measure OrderPoint)+θ • (ν:Measure OrderPoint)) s).toReal=_ + rw [Measure.add_apply,ENNReal.toReal_add (measure_ne_top _ _) (measure_ne_top _ _)] + simp only [Measure.coe_nnreal_smul_apply,ENNReal.toReal_mul,ENNReal.coe_toReal, + NNReal.coe_sub hθ,NNReal.coe_one,Measure.real] + +lemma probabilityMix_coefficient_real (β : ℝ≥0) (ρ ν : ProbabilityMeasure OrderPoint) + (θ : ℝ≥0) (hθ : θ≤1) (t : ℝ≥0) : + (measureCoefficient (probabilityMix ρ ν θ hθ) β t:ℝ)= + (1-(θ:ℝ))*(measureCoefficient ρ β t:ℝ)+(θ:ℝ)*(measureCoefficient ν β t:ℝ) := by + simp only [measureCoefficient,NNReal.coe_mul,Real.coe_toNNReal _ measureReal_nonneg, + ] + rw [probabilityMix_real] + ring + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient + +lemma probabilityMix_coefficient (β : ℝ≥0) (ρ ν : ProbabilityMeasure OrderPoint) + (θ : ℝ≥0) (hθ : θ≤1) : + measureCoefficient (probabilityMix ρ ν θ hθ) β=((ofMeasure β ρ).mix (ofMeasure β ν) θ hθ).val := by + funext t + apply NNReal.eq + rw [probabilityMix_coefficient_real] + simp only [BoundedCoefficient.mix,ofMeasure,NNReal.coe_add,NNReal.coe_mul,NNReal.coe_sub hθ,NNReal.coe_one] + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + + + +theorem measureFunctional_first_variation (hW : IsBrownianReal W P) (hβ : 0<β) + (ρ ν : ProbabilityMeasure OrderPoint) {Θ : ℕ → ℝ≥0} (hΘ : ∀ n,Θ n≤1) + (hΘpos : ∀ n,0<Θ n) (hθ : Tendsto Θ atTop (𝓝 0)) : + Tendsto (fun n => (measureFunctional β (probabilityMix ρ ν (Θ n) (hΘ n))- + measureFunctional β ρ)/(Θ n:ℝ)) atTop + (𝓝 (firstVariation P W hβ (ofMeasure β ρ) (ofMeasure β ν))) := by + have hh := functional_first_variation hW hβ (ofMeasure β ρ) (ofMeasure β ν) hΘ hΘpos hθ + convert! hh using 1 + ext n + rw [measureFunctional,probabilityMix_coefficient] + rfl + + + +theorem minimizingParisi_firstVariation_nonneg (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + (ν : ProbabilityMeasure OrderPoint) : + 0≤firstVariation P W hβ (ofMeasure β ρ) (ofMeasure β ν) := by + let Θ (n : ℕ) : ℝ≥0 := 1/(n+1:ℕ) + have hp (n : ℕ) : 0<Θ n := by dsimp [Θ];positivity + have hb (n : ℕ) : Θ n≤1 := by + apply (div_le_one (by positivity : (0:ℝ≥0)<(n+1:ℕ))).mpr + exact_mod_cast (Nat.succ_le_succ (Nat.zero_le n)) + have ht : Tendsto Θ atTop (𝓝 0) := by + apply NNReal.tendsto_coe.mp + simpa only [Θ,NNReal.coe_div,NNReal.coe_one,NNReal.coe_natCast,NNReal.coe_zero] using + SKCavity.tendsto_succ_reciprocal + apply ge_of_tendsto (measureFunctional_first_variation hW hβ ρ ν hb hp ht) + exact Eventually.of_forall fun n => div_nonneg (sub_nonneg.mpr (hρ _)) (hp n).le + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient + +lemma integral_cdf_mul (ρ : ProbabilityMeasure OrderPoint) {f : ℝ → ℝ} + (hf : Continuous f) {B : ℝ} (hB : 0≤B) (hb : ∀ t∈Icc (0:ℝ) 1,‖f t‖≤B) : + (∫ t in (0:ℝ)..1,(ρ:Measure OrderPoint).real {x | (x:ℝ)≤t}*f t)= + ∫ x,(∫ t in (x:ℝ)..1,f t) ∂(ρ:Measure OrderPoint) := by + let k (x : OrderPoint) (t : ℝ) : ℝ := if (x:ℝ)≤t then f t else 0 + have hkm : Measurable (uncurry k) := by + apply Measurable.ite (measurableSet_le (by fun_prop) measurable_snd) + (hf.measurable.comp measurable_snd) measurable_const + have hk : Integrable (uncurry k) ((ρ:Measure OrderPoint).prod (volume.restrict (Icc (0:ℝ) 1))) := by + apply Integrable.of_bound hkm.aestronglyMeasurable B + rw [Measure.ae_prod_iff_ae_ae (measurableSet_le hkm.norm measurable_const)] + filter_upwards [] with x + filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht + dsimp only [uncurry,k] + split_ifs + · exact hb t ht + · simpa using hB + have hx (x : OrderPoint) : (∫ t,k x t ∂(volume.restrict (Icc (0:ℝ) 1)))= + ∫ t in (x:ℝ)..1,f t := by + change (∫ t,(Ici (x:ℝ)).indicator f t ∂(volume.restrict (Icc (0:ℝ) 1)))=_ + rw [integral_indicator measurableSet_Ici,Measure.restrict_restrict measurableSet_Ici] + have he : Ici (x:ℝ)∩Icc (0:ℝ) 1=Icc (x:ℝ) 1 := by + ext t + simp only [mem_inter_iff,mem_Ici,mem_Icc] + constructor + · rintro ⟨h1,h2,h3⟩; exact ⟨h1,h3⟩ + · rintro ⟨h1,h2⟩;exact ⟨h1,x.property.1.trans h1,h2⟩ + rw [he,integral_Icc_eq_integral_Ioc,intervalIntegral.integral_of_le x.property.2] + have ht (t : ℝ) : (∫ x,k x t ∂(ρ:Measure OrderPoint))= + (ρ:Measure OrderPoint).real {x | (x:ℝ)≤t}*f t := by + change (∫ x,({x : OrderPoint | (x:ℝ)≤t}).indicator (fun _ => f t) x ∂(ρ:Measure OrderPoint))=_ + rw [integral_indicator_const _ (by measurability)] + rfl + rw [intervalIntegral.integral_of_le zero_le_one,←integral_Icc_eq_integral_Ioc] + calc + _ = ∫ t,∫ x,k x t ∂(ρ:Measure OrderPoint) ∂(volume.restrict (Icc (0:ℝ) 1)) := by + apply integral_congr_ae + exact ae_of_all _ fun t => (ht t).symm + _ = ∫ x,∫ t,k x t ∂(volume.restrict (Icc (0:ℝ) 1)) ∂(ρ:Measure OrderPoint) := (integral_integral_swap hk).symm + _ = _ := integral_congr_ae (ae_of_all _ hx) + +lemma measureCDF_mono (ρ : ProbabilityMeasure OrderPoint) : + Monotone (fun t : ℝ => (ρ:Measure OrderPoint).real {x | (x:ℝ)≤t}) := by + intro s t h + apply measureReal_mono (fun x hx => hx.trans h) + +lemma ofMeasure_real (β : ℝ≥0) (ρ : ProbabilityMeasure OrderPoint) (t : ℝ) (ht : 0≤t) : + (ofMeasure β ρ).real t=(ρ:Measure OrderPoint).real {x | (x:ℝ)≤t}*(β:ℝ) := by + simp only [ofMeasure,BoundedCoefficient.real,measureCoefficient,NNReal.coe_mul, + Real.coe_toNNReal t ht,Real.coe_toNNReal _ measureReal_nonneg] + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + +def deviation (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) (hβ : 0<β) + (c : BoundedCoefficient β) (t : ℝ) : ℝ := + expectedProduct P W c c (c.driftData hβ) t-t + +def variationalPotential (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) (hβ : 0<β) + (c : BoundedCoefficient β) (t : ℝ) : ℝ := + ∫ s in t..1,deviation P W hβ c s + +lemma continuous_deviation (hW : IsBrownianReal W P) (hβ : 0<β) (c : BoundedCoefficient β) : + Continuous (deviation P W hβ c) := (expectedProduct_continuous hW c c hβ _).sub continuous_id + +lemma norm_deviation_le (hW : IsBrownianReal W P) (hβ : 0<β) (c : BoundedCoefficient β) + (t : ℝ) (ht : t∈Icc (0:ℝ) 1) : ‖deviation P W hβ c t‖≤2 := by + apply (norm_sub_le _ _).trans + have ht' : ‖t‖≤1 := by rw [Real.norm_eq_abs,abs_of_nonneg ht.1];exact ht.2 + linarith [expectedProduct_bound hW c c hβ (c.driftData hβ) t] + +lemma hasDerivAt_variationalPotential (hW : IsBrownianReal W P) (hβ : 0<β) + (c : BoundedCoefficient β) (t : ℝ) : + HasDerivAt (variationalPotential P W hβ c) (-deviation P W hβ c t) t := + intervalIntegral.integral_hasDerivAt_left ((continuous_deviation hW hβ c).intervalIntegrable _ _) + (continuous_deviation hW hβ c).stronglyMeasurable.stronglyMeasurableAtFilter + (continuous_deviation hW hβ c).continuousAt + +lemma continuous_variationalPotential (hW : IsBrownianReal W P) (hβ : 0<β) + (c : BoundedCoefficient β) : Continuous (variationalPotential P W hβ c) := + continuous_iff_continuousAt.mpr fun t => (hasDerivAt_variationalPotential hW hβ c t).continuousAt + +lemma variationalPotential_integrable (hW : IsBrownianReal W P) (hβ : 0<β) + (c : BoundedCoefficient β) (ν : ProbabilityMeasure OrderPoint) : + Integrable (fun x : OrderPoint => variationalPotential P W hβ c x) (ν:Measure OrderPoint) := by + have hc : Continuous (fun x : OrderPoint => variationalPotential P W hβ c x) := + (continuous_variationalPotential hW hβ c).comp continuous_subtype_val + simpa only [integrableOn_univ] using hc.continuousOn.integrableOn_compact (μ := (ν:Measure OrderPoint)) isCompact_univ + +lemma firstVariation_potential (hW : IsBrownianReal W P) (hβ : 0<β) + (ρ ν : ProbabilityMeasure OrderPoint) : + firstVariation P W hβ (ofMeasure β ρ) (ofMeasure β ν)=(β:ℝ)/2* + ((∫ x,variationalPotential P W hβ (ofMeasure β ρ) x ∂(ν:Measure OrderPoint))- + (∫ x,variationalPotential P W hβ (ofMeasure β ρ) x ∂(ρ:Measure OrderPoint))) := by + let c := ofMeasure β ρ + have hD := continuous_deviation hW hβ c + have hb := norm_deviation_le hW hβ c + have hi (μ : ProbabilityMeasure OrderPoint) : IntervalIntegrable + (fun t => (μ:Measure OrderPoint).real {x | (x:ℝ)≤t}*deviation P W hβ c t) volume 0 1 := + (measureCDF_mono μ).intervalIntegrable.mul_continuousOn hD.continuousOn + change (∫ t in (0:ℝ)..1,((ofMeasure β ν).real t-c.real t)/2*deviation P W hβ c t)=_ + change _=(β:ℝ)/2*((∫ x,(∫ t in (x:ℝ)..1,deviation P W hβ c t) ∂(ν:Measure OrderPoint))- + (∫ x,(∫ t in (x:ℝ)..1,deviation P W hβ c t) ∂(ρ:Measure OrderPoint))) + rw [←integral_cdf_mul ν hD (by norm_num) hb,←integral_cdf_mul ρ hD (by norm_num) hb, + ←intervalIntegral.integral_sub (hi ν) (hi ρ),←intervalIntegral.integral_const_mul] + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le zero_le_one] at ht + dsimp only [c] + rw [ofMeasure_real β ν t ht.1,ofMeasure_real β ρ t ht.1] + ring + +lemma minimizingParisi_potential_average_le (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + (ν : ProbabilityMeasure OrderPoint) : + (∫ x,variationalPotential P W hβ (ofMeasure β ρ) x ∂(ρ:Measure OrderPoint))≤ + (∫ x,variationalPotential P W hβ (ofMeasure β ρ) x ∂(ν:Measure OrderPoint)) := by + have hh := minimizingParisi_firstVariation_nonneg hW hβ hρ ν + rw [firstVariation_potential hW hβ ρ ν] at hh + have hp : (0:ℝ)<β := hβ + nlinarith + +lemma minimizingParisi_potential_average_le_point (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) (t : OrderPoint) : + (∫ x,variationalPotential P W hβ (ofMeasure β ρ) x ∂(ρ:Measure OrderPoint))≤ + variationalPotential P W hβ (ofMeasure β ρ) t := by + have hh := minimizingParisi_potential_average_le hW hβ hρ ⟨Measure.dirac t,inferInstance⟩ + change _ ≤ ∫ x,variationalPotential P W hβ (ofMeasure β ρ) x ∂Measure.dirac t at hh + simpa only [integral_dirac] using hh + + + +theorem minimizingParisi_support_potential (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {t : OrderPoint} (ht : t∈(ρ:Measure OrderPoint).support) : + ∀ s : OrderPoint,variationalPotential P W hβ (ofMeasure β ρ) t≤ + variationalPotential P W hβ (ofMeasure β ρ) s := by + let g (x : OrderPoint) := variationalPotential P W hβ (ofMeasure β ρ) x + let A := ∫ x,g x ∂(ρ:Measure OrderPoint) + have hg : Continuous g := (continuous_variationalPotential hW hβ (ofMeasure β ρ)).comp continuous_subtype_val + have hi : Integrable g (ρ:Measure OrderPoint) := variationalPotential_integrable hW hβ _ ρ + have hlow : ∀ x,A≤g x := minimizingParisi_potential_average_le_point hW hβ hρ + have hz : (fun x => g x-A)=ᵐ[(ρ:Measure OrderPoint)] 0 := by + apply (integral_eq_zero_iff_of_nonneg_ae (ae_of_all _ fun x => sub_nonneg.mpr (hlow x)) + (hi.sub (integrable_const _))).mp + rw [integral_sub hi (integrable_const _)] + simp [A] + have he : ∀ᵐ x ∂(ρ:Measure OrderPoint),g x=A := by + filter_upwards [hz] with x hx + exact sub_eq_zero.mp hx + have hsup := (ρ:Measure OrderPoint).support_subset_of_isClosed (isClosed_eq hg continuous_const) he + have ht' : g t=A := hsup ht + intro s + change g t≤g s + rw [ht'] + exact hlow s + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +namespace ParisiFinite +open ParisiPath BoundedCoefficient +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +variable {β : ℝ≥0} + +lemma expectedProduct_zero (hW : IsBrownianReal W P) (hβ : 0<β) + (c : BoundedCoefficient β) : expectedProduct P W c c (c.driftData hβ) 0=0 := by + apply integral_eq_zero_of_ae + filter_upwards [brownianPath_eq_ae hW,hW.eval_zero_ae_eq_zero] with ω hω h0 + rw [spin_eq _ _ _ (by simp),extend_of_mem _ (by simp),solution_zero,hω] + simp only [Real.toNNReal_zero,Pi.zero_apply] + change fieldGradient β c.val 0 (W 0 ω)*fieldGradient β c.val 0 (W 0 ω)=0 + rw [h0,fieldGradient_zero β hβ c.mono c.bound] + simp + +lemma expectedProduct_one_lt (hW : IsBrownianReal W P) (hβ : 0<β) + (c : BoundedCoefficient β) : expectedProduct P W c c (c.driftData hβ) 1<1 := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let Z (ω : Ω) := c.spin (solution (c.driftData hβ) (brownianPath W ω)) 1 + have hZ (ω : Ω) : Z ω*Z ω<1 := by + dsimp only [Z] + rw [spin_eq _ _ _ (by simp)] + simp only [Real.toNNReal_one,fieldGradient_terminal β hβ] + simpa only [pow_two] using Real.tanh_sq_lt_one ((β:ℝ)* + extend (solution (c.driftData hβ) (brownianPath W ω)) 1) + have hi : Integrable (fun ω => 1-Z ω*Z ω) P := + (integrable_const 1).sub (spin_product_integrable hW c c hβ _ 1) + have hp : 0<∫ ω,1-Z ω*Z ω ∂P := by + apply (integral_pos_iff_support_of_nonneg (fun ω => sub_nonneg.mpr (hZ ω).le) hi).mpr + have hs : Function.support (fun ω => 1-Z ω*Z ω)=univ := by + ext ω + simp only [Function.mem_support,mem_univ,iff_true] + exact (sub_pos.mpr (hZ ω)).ne' + rw [hs] + simp + rw [integral_sub (integrable_const _) (spin_product_integrable hW c c hβ _ 1)] at hp + simpa [expectedProduct,Z] using hp + +lemma minimizingParisi_deviation_interior (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {t : OrderPoint} (ht : t∈(ρ:Measure OrderPoint).support) + (h0 : 0<(t:ℝ)) (h1 : (t:ℝ)<1) : deviation P W hβ (ofMeasure β ρ) t=0 := by + have hl : IsLocalMin (variationalPotential P W hβ (ofMeasure β ρ)) (t:ℝ) := by + filter_upwards [Ioo_mem_nhds h0 h1] with s hs + exact minimizingParisi_support_potential hW hβ hρ ht ⟨s,hs.1.le,hs.2.le⟩ + have hh := hl.hasDerivAt_eq_zero (hasDerivAt_variationalPotential hW hβ _ t) + exact neg_eq_zero.mp hh + +lemma minimizingParisi_one_not_mem_support (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) : + (⟨1,by simp⟩ : OrderPoint)∉(ρ:Measure OrderPoint).support := by + intro ht + let c := ofMeasure β ρ + have hl : IsLocalMinOn (variationalPotential P W hβ c) (Icc (0:ℝ) 1) 1 := by + filter_upwards [self_mem_nhdsWithin] with s hs + exact minimizingParisi_support_potential hW hβ hρ ht ⟨s,hs⟩ + have htang : (-1:ℝ)∈posTangentConeAt (Icc (0:ℝ) 1) 1 := by + have hh := sub_mem_posTangentConeAt_of_segment_subset + ((convex_Icc (0:ℝ) 1).segment_subset (show (1:ℝ)∈Icc (0:ℝ) 1 by simp) + (show (0:ℝ)∈Icc (0:ℝ) 1 by simp)) + simpa using hh + have hh := hl.hasFDerivWithinAt_nonneg + (hasDerivAt_variationalPotential hW hβ c 1).hasFDerivAt.hasFDerivWithinAt htang + have he := expectedProduct_one_lt hW hβ c + have hh' : 1≤expectedProduct P W c c (c.driftData hβ) 1 := by + simpa [ContinuousLinearMap.smulRight_apply,smul_eq_mul,deviation] using hh + exact (not_lt_of_ge hh') he + + + +theorem minimizingParisi_selfConsistency (hW : IsBrownianReal W P) (hβ : 0<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) + {t : OrderPoint} (ht : t∈(ρ:Measure OrderPoint).support) : + expectedProduct P W (ofMeasure β ρ) (ofMeasure β ρ) ((ofMeasure β ρ).driftData hβ) t=t := by + by_cases h0 : (t:ℝ)=0 + · rw [h0] + exact expectedProduct_zero hW hβ _ + by_cases h1 : (t:ℝ)=1 + · have he : t=(⟨1,by simp⟩ : OrderPoint) := Subtype.ext h1 + exact (minimizingParisi_one_not_mem_support hW hβ hρ (he ▸ ht)).elim + exact sub_eq_zero.mp (minimizingParisi_deviation_interior hW hβ hρ ht + (lt_of_le_of_ne t.property.1 (Ne.symm h0)) (lt_of_le_of_ne t.property.2 h1)) + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +namespace BoundedCoefficient +variable {β : ℝ≥0} + +def curvature (c : BoundedCoefficient β) (X : Path) (t : ℝ) : ℝ := + fieldCurvature β c.val (Real.toNNReal (projIcc 0 1 zero_le_one t)) (extend X t) + +lemma curvature_eq (c : BoundedCoefficient β) (X : Path) (t : ℝ) (ht : t∈Icc (0:ℝ) 1) : + c.curvature X t=fieldCurvature β c.val (Real.toNNReal t) (extend X t) := by + simp only [curvature,projIcc_of_mem zero_le_one ht] + +lemma continuous_curvature (c : BoundedCoefficient β) (hβ : 0<β) (X : Path) : + Continuous (c.curvature X) := by + change Continuous ((fun q : OrderPoint × ℝ => fieldCurvature β c.val (Real.toNNReal q.1) q.2) ∘ + (fun t => (projIcc (0:ℝ) 1 zero_le_one t,extend X t))) + exact (continuous_fieldCurvature_joint β hβ c.mono c.bound).comp + ((show Continuous (projIcc (0:ℝ) 1 zero_le_one) from continuous_projIcc).prodMk (continuous_extend X)) + +lemma norm_curvature_le (c : BoundedCoefficient β) (hβ : 0<β) (X : Path) (t : ℝ) : + ‖c.curvature X t‖≤β := fieldCurvature_abs β hβ c.mono c.bound _ _ + +lemma curvature_pos (c : BoundedCoefficient β) (hβ : 0<β) (X : Path) (t : ℝ) : + 0 c.curvature (solution b (brownianPath W ω)) t) P := by + exact ((fieldCurvature_lipschitz β hβ c.mono c.bound _).continuous.measurable.comp_aemeasurable + (aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t))).aestronglyMeasurable + +lemma curvature_square_integrable (hW : IsBrownianReal W P) (c : BoundedCoefficient β) + (hβ : 0<β) (b : Drift K M) (t : ℝ) : + Integrable (fun ω => (c.curvature (solution b (brownianPath W ω)) t)^2) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + refine Integrable.of_bound ((c.curvature_aestronglyMeasurable hW hβ b t).pow 2) ((β:ℝ)^2) ?_ + filter_upwards [] with ω + rw [norm_pow] + exact pow_le_pow_left₀ (norm_nonneg _) (c.norm_curvature_le hβ _ t) 2 + +def expectedSquareCurvature (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (c : BoundedCoefficient β) (hβ : 0<β) (t : ℝ) : ℝ := + ∫ ω,(c.curvature (solution (c.driftData hβ) (brownianPath W ω)) t)^2 ∂P + +lemma expectedSquareCurvature_continuous (hW : IsBrownianReal W P) + (c : BoundedCoefficient β) (hβ : 0<β) : Continuous (c.expectedSquareCurvature P W hβ) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply continuous_of_dominated (bound := fun _ => (β:ℝ)^2) + (fun t => (curvature_square_integrable hW c hβ _ t).aestronglyMeasurable) + (fun t => ae_of_all _ fun ω => ?_) (integrable_const _) + (ae_of_all _ fun ω => (c.continuous_curvature hβ _).pow 2) + rw [norm_pow] + exact pow_le_pow_left₀ (norm_nonneg _) (c.norm_curvature_le hβ _ t) 2 + +lemma spin_mean_square_evolution (hW : IsBrownianReal W P) + (hβ : 0<β) (c : BoundedCoefficient β) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) : + expectedProduct P W c c (c.driftData hβ) t= + ∫ s in (0:ℝ)..t,c.expectedSquareCurvature P W hβ s := by + let r := Real.toNNReal t + have hr0 : r≠0 := ne_of_gt (Real.toNNReal_pos.mpr ht.1) + have hrt : (r:ℝ)=t := Real.coe_toNNReal _ ht.1.le + have hr1 : r<1 := by exact_mod_cast (show (r:ℝ)<1 by rw [hrt];exact ht.2) + have hh := canonical_square_verification hW (c.driftData hβ) (c.drift_joint_ae_continuous hβ) + β hβ c.mono c.bound r hr0 hr1 + rw [fieldGradient_zero β hβ c.mono c.bound,zero_pow (by norm_num : 2≠0),sub_zero] at hh + have hterm : (∫ ω,(fieldGradient β c.val r + (solution (c.driftData hβ) (brownianPath W ω) ⟨r,r.coe_nonneg,by exact_mod_cast hr1.le⟩))^2 ∂P)= + expectedProduct P W c c (c.driftData hβ) t := by + apply integral_congr_ae + filter_upwards [] with ω + rw [spin_eq _ _ _ ⟨ht.1.le,ht.2.le⟩,extend_of_mem _ ⟨ht.1.le,ht.2.le⟩] + rw [pow_two] + have he : (⟨r,r.coe_nonneg,by exact_mod_cast hr1.le⟩ : Icc (0:ℝ) 1)=⟨t,ht.1.le,ht.2.le⟩ := Subtype.ext hrt + rw [he] + rw [hterm,hrt] at hh + rw [hh] + apply intervalIntegral.integral_congr_Ioo_of_le ht.1.le + intro s hs + apply integral_congr_ae + filter_upwards [] with ω + rw [curvature_eq _ _ _ ⟨hs.1.le,hs.2.le.trans ht.2.le⟩] + dsimp only [squareKernel,driftData,drift,BoundedCoefficient.real] + ring + +lemma hasDerivAt_expectedProduct_self (hW : IsBrownianReal W P) + (hβ : 0<β) (c : BoundedCoefficient β) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) : + HasDerivAt (expectedProduct P W c c (c.driftData hβ)) + (c.expectedSquareCurvature P W hβ t) t := by + have hc := c.expectedSquareCurvature_continuous hW hβ + have hh := intervalIntegral.integral_hasDerivAt_right (hc.intervalIntegrable 0 t) + hc.stronglyMeasurable.stronglyMeasurableAtFilter hc.continuousAt + apply hh.congr_of_eventuallyEq + filter_upwards [Ioo_mem_nhds ht.1 ht.2] with s hs + exact spin_mean_square_evolution hW hβ c s hs + +end BoundedCoefficient +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/MixedMatrixOne.lean b/lean/OAI/Probability/ParisiFinite/MixedMatrixOne.lean new file mode 100644 index 0000000000000000000000000000000000000000..e80f17605fec3ebcc0bf872e194e84f8c6f47a30 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/MixedMatrixOne.lean @@ -0,0 +1,716 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ChildMomentLimit + +namespace OAI + +/-! Mixed Matrix One. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open scoped InnerProductSpace BigOperators +open ContinuousLinearMap InnerProductSpace +namespace FiniteTensor +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [Fintype ι] in + theorem mixedMatrix_one (D : ℕ) : mixedMatrix D (fun _ => (1 : Matrix ι ι ℂ))=1 := by + ext σ τ + simp only [mixedMatrix,Matrix.one_apply] + by_cases h : σ=τ + · subst τ; simp + · rw [ite_eq_right h] + obtain ⟨i,hi⟩ := Function.ne_iff.mp h + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +omit [DecidableEq ι] in + theorem mixedMatrix_mul (D : ℕ) (A B : Fin D → Matrix ι ι ℂ) : + mixedMatrix D (fun i => A i*B i)=mixedMatrix D A*mixedMatrix D B := by + ext σ τ + simp only [mixedMatrix,Matrix.mul_apply] + rw [Fintype.prod_sum] + apply Finset.sum_congr rfl + intro v hv + exact Finset.prod_mul_distrib + +omit [Fintype ι] [DecidableEq ι] in + theorem mixedMatrix_star (D : ℕ) (A : Fin D → Matrix ι ι ℂ) : + mixedMatrix D (fun i => star (A i))=star (mixedMatrix D A) := by + ext σ τ + simp only [mixedMatrix,Matrix.star_apply,star_prod] + + theorem mixedOperator_one (D : ℕ) : + mixedOperator D (fun _ => (1 : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι))=1 := by + simp only [mixedOperator,map_one,mixedMatrix_one] + + theorem mixedOperator_mul (D : ℕ) + (A B : Fin D → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + mixedOperator D (fun i => A i*B i)=mixedOperator D A*mixedOperator D B := by + simp only [mixedOperator,map_mul,mixedMatrix_mul] + + theorem mixedOperator_star (D : ℕ) + (A : Fin D → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + mixedOperator D (fun i => star (A i))=star (mixedOperator D A) := by + unfold mixedOperator + have hi (i : Fin D) : (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm (star (A i))= + star ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm (A i)) := + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm.map_star' _ + simp_rw [hi] + rw [mixedMatrix_star] + exact (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin D → ι)).map_star' _ + + theorem mixedOperator_projection (D : ℕ) + (A : Fin D → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (hA : ∀i,IsStarProjection (A i)) : IsStarProjection (mixedOperator D A) := by + constructor + · change mixedOperator D A*mixedOperator D A=mixedOperator D A + rw [←mixedOperator_mul] + congr 1 + funext i + exact (hA i).isIdempotentElem + · change star (mixedOperator D A)=mixedOperator D A + rw [←mixedOperator_star] + congr 1 + funext i + exact (hA i).isSelfAdjoint + +omit [DecidableEq ι] in + theorem vacuumComplement_projection [Nonempty ι] (Ω : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) : + IsStarProjection (vacuumComplement Ω) := (isStarProjection_rankOne_self hΩ).one_sub + + theorem excitedSlot_projection [Nonempty ι] (D : ℕ) (Ω : EuclideanSpace ℂ ι) + (hΩ : ‖Ω‖=1) (j : Fin D) : IsStarProjection (excitedSlot D Ω j) := by + apply mixedOperator_projection + intro i + split_ifs + · exact vacuumComplement_projection Ω hΩ + · exact IsStarProjection.one _ + + + +theorem excitedSlot_expectation [Nonempty ι] (D : ℕ) (Ω : EuclideanSpace ℂ ι) + (hΩ : ‖Ω‖=1) (j : Fin D) (x : EuclideanSpace ℂ (Fin D → ι)) : + ⟪x,excitedSlot D Ω j x⟫_ℂ=(‖excitedSlot D Ω j x‖^2:ℝ) := by + have h := excitedSlot_projection D Ω hΩ j + have he : ⟪excitedSlot D Ω j x,excitedSlot D Ω j x⟫_ℂ=⟪x,excitedSlot D Ω j x⟫_ℂ := by + rw [←ContinuousLinearMap.adjoint_inner_right] + rw [←ContinuousLinearMap.star_eq_adjoint,h.isSelfAdjoint] + change ⟪x,(excitedSlot D Ω j*excitedSlot D Ω j) x⟫_ℂ=_ + rw [h.isIdempotentElem] + rw [←he,inner_self_eq_norm_sq_to_K] + norm_cast + +end FiniteTensor + + + +open scoped InnerProductSpace BigOperators +namespace TensorPackets +open SpinOperators +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + +theorem diagonal_projection (A : Fin 2 → H →L[ℂ] H) (hA : ∀i,IsStarProjection (A i)) : + IsStarProjection (diagonal A) := by + constructor + · change diagonal A*diagonal A=diagonal A + rw [←diagonal_mul] + congr 1 + funext i + exact (hA i).isIdempotentElem + · change star (diagonal A)=diagonal A + rw [←diagonal_star] + congr 1 + funext i + exact (hA i).isSelfAdjoint + +end TensorPackets + +namespace FiniteTree + +theorem rootSlot_projection (D h : ℕ) (j : Fin D) : IsStarProjection (rootSlot D h j) := by + have hp := TensorPackets.diagonal_projection + (fun _ : Fin 2 => FiniteTensor.excitedSlot D (vac D h) j) + (fun _ => FiniteTensor.excitedSlot_projection D (vac D h) (norm_vac D h) j) + let f := (split D (h+1)).symm.conjStarAlgEquiv + change IsStarProjection (f _) + constructor + · change f _*f _=f _ + rw [←map_mul,hp.isIdempotentElem] + · change star (f _)=f _ + exact (f.map_star' _).symm.trans (congrArg f hp.isSelfAdjoint) + + +def numberOperator (D h : ℕ) : Space D (h+1) →L[ℂ] Space D (h+1) := + ∑j : Fin D, rootSlot D h j + +theorem rootSlot_expectation (D h : ℕ) (j : Fin D) (x : Space D (h+1)) : + ⟪x,rootSlot D h j x⟫_ℂ=(‖rootSlot D h j x‖^2:ℝ) := by + have hp := rootSlot_projection D h j + have he : ⟪rootSlot D h j x,rootSlot D h j x⟫_ℂ=⟪x,rootSlot D h j x⟫_ℂ := by + rw [←ContinuousLinearMap.adjoint_inner_right,←ContinuousLinearMap.star_eq_adjoint,hp.isSelfAdjoint] + change ⟪x,(rootSlot D h j*rootSlot D h j) x⟫_ℂ=_ + rw [hp.isIdempotentElem] + rw [←he,inner_self_eq_norm_sq_to_K] + norm_cast + +theorem numberOperator_expectation (D h : ℕ) (x : Space D (h+1)) : + ⟪x,numberOperator D h x⟫_ℂ=(topOccupation D h x:ℂ) := by + simp only [numberOperator,topOccupation,_root_.sum_apply,inner_sum,Complex.ofReal_sum] + apply Finset.sum_congr rfl + intro j hj + exact rootSlot_expectation D h j x + + + +theorem insertion_number_bound (D h : ℕ) (w : List PointedTree.Gate) : + (⟪insertion D (h+1) w,numberOperator D h (insertion D (h+1) w)⟫_ℂ).re≤ + packetOccupationBound (RootTensorCLT.compile (insertionProgram w) RootTensorCLT.start)^2 := by + rw [numberOperator_expectation,Complex.ofReal_re] + exact insertion_occupation_bound D h w + +end FiniteTree + + + +open scoped InnerProductSpace Topology +open Filter +namespace RootTensorCLT +open SpinOperators +variable {κ H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +def constantProgram (l : List κ) : List (Pulse κ) := l.map (fun i => .control (fun _ => i)) + +theorem constant_run (s : List κ → H) (K : κ → H →L[ℂ] H) + (hs : ∀i l,K i (s l)=s (i::l)) (l : List κ) : + run K (constantProgram l) (PointedTree.plusEmbedding (s []))=PointedTree.plusEmbedding (s l) := by + induction l with + | nil => rfl + | cons i l ih => + change TensorPackets.diagonal (fun _ => K i) (run K (constantProgram l) (PointedTree.plusEmbedding (s [])))=_ + rw [ih] + ext j + simp only [TensorPackets.diagonal_apply,PointedTree.plusEmbedding_apply,map_smul,hs] + +end RootTensorCLT + +namespace FiniteTree +open QuantumCLT RootTensorCLT CoherentFock + + + +theorem tensor_Gram_limit (h : ℕ) (u w : List Label) : + Tendsto (fun D => ⟪tensorState D (vac D h) (childGenerator D h) u, + tensorState D (vac D h) (childGenerator D h) w⟫_ℂ) atTop + (𝓝 ⟪fockState (childDirection h) u,fockState (childDirection h) w⟫_ℂ) := by + have ht := program_Gram_limit h (constantProgram u) (constantProgram w) + have hn (D : ℕ) (l : List Label) : + run (tensorPulse D (childGenerator D h)) (constantProgram l) + (PointedTree.plusEmbedding (FiniteTensor.power D (vac D h)))= + PointedTree.plusEmbedding (tensorState D (vac D h) (childGenerator D h) l) := by + have he : tensorState D (vac D h) (childGenerator D h) []=FiniteTensor.power D (vac D h) := by + simp [tensorState,generators] + rw [←he] + exact constant_run _ _ (tensor_step D (vac D h) (childGenerator D h)) l + have hf (l : List Label) : run (W ∘ childDirection h) (constantProgram l) (PointedTree.vac (h+1))= + PointedTree.plusEmbedding (fockState (childDirection h) l) := + constant_run _ _ (fock_step (childDirection h)) l + simpa only [hn,hf,LinearIsometry.inner_map_map] using ht + +def childState (D h : ℕ) (l : List Label) : Space D h := + generators (l.map (childGenerator D h)) (Real.sqrt (D:ℝ))⁻¹ (vac D h) + +@[simp] theorem norm_childState (D h : ℕ) (l : List Label) : ‖childState D h l‖=1 := by + exact (ContinuousLinearMap.norm_map_of_mem_unitary + (child_word_unitary D h l (Real.sqrt (D:ℝ))⁻¹) (vac D h)).trans (norm_vac D h) + +theorem child_Gram_bound (D h : ℕ) (hD : 0 ⟪childState D h u,childState D h w⟫_ℂ) atTop (𝓝 1) := by + have hr : Tendsto (fun D : ℕ => (Real.sqrt (D:ℝ))⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp (Real.tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop) + apply tendsto_iff_norm_sub_tendsto_zero.mpr + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ + (by simpa using hr.const_mul (3*(wordBound u+wordBound w))) + filter_upwards [eventually_gt_atTop (0:ℕ)] with D hD + exact child_Gram_bound D h hD u w + +end FiniteTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace FiniteTree.FullRoot +open QuantumCLT RootTensorCLT CoherentFock TensorPackets SpinOperators + + + +abbrev Tail (D h : ℕ) := EuclideanSpace ℂ (Fin (D+1) → FiniteTree.Index D h) +abbrev Space (D h : ℕ) := Double (Tail D h) + +def vac (D h : ℕ) : Space D h := + PointedTree.plusEmbedding (FiniteTensor.power (D+1) (FiniteTree.vac D h)) + +def tensorState (D h : ℕ) (l : List Label) : Tail D h := + FiniteTensor.power (D+1) (childState D h l) + +def tensorPulse (D h : ℕ) (i : Label) : Tail D h →L[ℂ] Tail D h := + FiniteTensor.operatorPower (D+1) + (NormedSpace.exp (((Real.sqrt (D:ℝ))⁻¹:ℝ) • childGenerator D h i)) + +theorem tensor_step (D h : ℕ) (i : Label) (l : List Label) : + tensorPulse D h i (tensorState D h l)=tensorState D h (i::l) := by + rw [tensorPulse,tensorState,FiniteTensor.operatorPower_apply] + congr 1 + + + +def ordinary (D h : ℕ) (w : List PointedTree.Gate) : Space D h →L[ℂ] Space D h := + run (tensorPulse D h) (program w) + +def insertion (D h : ℕ) (w : List PointedTree.Gate) : Space D h := + run (tensorPulse D h) (insertionProgram w) (vac D h) + +theorem run_packet (D h : ℕ) (p : List (Pulse Label)) : + run (tensorPulse D h) p (vac D h)=packet (tensorState D h) (compile p start) := by + have he : tensorState D h []=FiniteTensor.power (D+1) (FiniteTree.vac D h) := by + simp only [tensorState,childState,generators,List.map_nil,List.prod_nil,one_apply_eq_self] + rw [vac,←he,←start_packet] + exact RootTensorCLT.run_packet _ _ (tensor_step D h) _ _ + +theorem tensor_Gram_factor (D h : ℕ) (u w : List Label) : + ⟪tensorState D h u,tensorState D h w⟫_ℂ= + ⟪RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) u, + RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) w⟫_ℂ* + ⟪childState D h u,childState D h w⟫_ℂ := by + simp only [tensorState,RootTensorCLT.tensorState,childState,FiniteTensor.inner_power,pow_succ] + + + +theorem tensor_Gram_limit (h : ℕ) (u w : List Label) : + Tendsto (fun D => ⟪tensorState D h u,tensorState D h w⟫_ℂ) atTop + (𝓝 ⟪fockState (childDirection h) u,fockState (childDirection h) w⟫_ℂ) := by + simp only [tensor_Gram_factor] + have ht := (FiniteTree.tensor_Gram_limit h u w).mul (child_Gram_limit h u w) + simpa only [mul_one] using ht + +theorem program_Gram_limit (h : ℕ) (u w : List (Pulse Label)) : + Tendsto (fun D => ⟪run (tensorPulse D h) u (vac D h),run (tensorPulse D h) w (vac D h)⟫_ℂ) + atTop (𝓝 ⟪run (W ∘ childDirection h) u (PointedTree.vac (h+1)), + run (W ∘ childDirection h) w (PointedTree.vac (h+1))⟫_ℂ) := by + have ht := TensorPackets.Gram_limit (fun D => Tail D h) (fun D => tensorState D h) + (fockState (childDirection h)) (tensor_Gram_limit h) (compile u start) (compile w start) + have hf (p : List (Pulse Label)) : run (W ∘ childDirection h) p (PointedTree.vac (h+1))= + packet (fockState (childDirection h)) (compile p start) := by + change run (W ∘ childDirection h) p (PointedTree.plusEmbedding (fockState (childDirection h) []))=_ + rw [←start_packet] + exact RootTensorCLT.run_packet _ _ (fock_step _) _ _ + simpa only [run_packet,hf] using ht + + + +theorem insertion_Gram_limit (h : ℕ) (u w : List PointedTree.Gate) : + Tendsto (fun D => ⟪insertion D h u,insertion D h w⟫_ℂ) atTop + (𝓝 ⟪(PointedTree.ordinary u (h+1)).insertion,(PointedTree.ordinary w (h+1)).insertion⟫_ℂ) := by + have ht := program_Gram_limit h (insertionProgram u) (insertionProgram w) + change Tendsto _ atTop (𝓝 ⟪((PointedTree.ordinary u (h+1)).insertion : PointedTree.Level (h+1)), + ((PointedTree.ordinary w (h+1)).insertion : PointedTree.Level (h+1))⟫_ℂ) + simpa only [insertion,FiniteTree.limiting_insertion] using ht + +end FiniteTree.FullRoot + + + +open scoped InnerProductSpace BigOperators +namespace FiniteTree.FullRoot +open TensorPackets RootTensorCLT + + +def slot (D h : ℕ) (j : Fin (D+1)) : Space D h →L[ℂ] Space D h := + TensorPackets.diagonal (fun _ => FiniteTensor.excitedSlot (D+1) (FiniteTree.vac D h) j) + +theorem slot_projection (D h : ℕ) (j : Fin (D+1)) : IsStarProjection (slot D h j) := + TensorPackets.diagonal_projection _ (fun _ => FiniteTensor.excitedSlot_projection + (D+1) (FiniteTree.vac D h) (FiniteTree.norm_vac D h) j) + +def occupation (D h : ℕ) (x : Space D h) : ℝ := ∑j : Fin (D+1),‖slot D h j x‖^2 + +theorem tensor_slot_bound (D h : ℕ) (hD : 0 6*wordBound l) (fun l => mul_nonneg (by norm_num) (wordBound_nonneg l)) + _ (by positivity) (fun l => by simpa only [Function.comp_apply,mul_assoc] using tensor_slot_bound D h hD l j) _ + +theorem insertion_slot_bound (D h : ℕ) (hD : 0 exact (unitary _).one_mem + | cons g w ih => + cases g with + | mixer β => exact (unitary _).mul_mem (act_mem_unitary (RootSpin.R_unitary β)) ih + | cost γ => exact (unitary _).mul_mem (diagonal_unitary _ (fun i => pulse_unitary D h _)) ih + + + +theorem insertion_eq (D h : ℕ) (w : List PointedTree.Gate) : + insertion D h w=(star (ordinary D h w)*(act RootSpin.Z : Space D h →L[ℂ] Space D h)*ordinary D h w) (vac D h) := by + rw [insertion,insertionProgram,run_append,run_append,run_adjoint _ negateLabel (pulse_star D h), + run_cons,run_nil,mul_one] + rfl + +@[simp] theorem norm_vac (D h : ℕ) : ‖vac D h‖=1 := by + exact (PointedTree.plusEmbedding.norm_map _).trans + (FiniteTree.norm_power_of_norm_one (D+1) (FiniteTree.vac D h) (FiniteTree.norm_vac D h)) + +@[simp] theorem norm_insertion (D h : ℕ) (w : List PointedTree.Gate) : ‖insertion D h w‖=1 := by + rw [insertion_eq] + have hu : (star (ordinary D h w)*(act RootSpin.Z : Space D h →L[ℂ] Space D h)*ordinary D h w) ∈ unitary _ := + (unitary _).mul_mem ((unitary _).mul_mem (Unitary.star_mem (ordinary_unitary D h w)) + (act_mem_unitary RootSpin.Z_unitary)) (ordinary_unitary D h w) + exact (Unitary.linearIsometryEquiv ⟨_,hu⟩).norm_map (vac D h) |>.trans (norm_vac D h) + +def flip (D h : ℕ) : Space D h →L[ℂ] Space D h := + spinFlip (FiniteTensor.operatorPower (D+1) (FiniteTree.flip D h)) + +theorem flip_unitary (D h : ℕ) : flip D h ∈ unitary _ := + spinFlip_unitary _ (FiniteTensor.operatorPower_unitary _ _ (FiniteTree.flip_unitary D h)) + +theorem flip_square (D h : ℕ) : flip D h*flip D h=1 := by + apply spinFlip_square + rw [←FiniteTensor.operatorPower_mul,FiniteTree.flip_square,FiniteTensor.operatorPower_one] + +theorem flip_vac (D h : ℕ) : flip D h (vac D h)=vac D h := by + ext i + simp only [flip,vac,spinFlip_apply,PointedTree.plusEmbedding_apply,map_smul, + FiniteTensor.operatorPower_apply,FiniteTree.flip_vac] + +@[simp] theorem flip_star (D h : ℕ) : star (flip D h)=flip D h := by + calc + star (flip D h)=star (flip D h)*(flip D h*flip D h) := by rw [flip_square,mul_one] + _ = (star (flip D h)*flip D h)*flip D h := (mul_assoc _ _ _).symm + _ = flip D h := by rw [(Unitary.mem_iff.mp (flip_unitary D h)).1,one_mul] + +theorem flip_ordinary (D h : ℕ) (w : List PointedTree.Gate) : + flip D h*ordinary D h w=ordinary D h w*flip D h := by + induction w with + | nil => simp [ordinary,program] + | cons g w ih => + have commute_then (B : Space D h →L[ℂ] Space D h) (hh : flip D h*B=B*flip D h) : + flip D h*(B*ordinary D h w)=(B*ordinary D h w)*flip D h := by + rw [←mul_assoc,hh,mul_assoc,ih,←mul_assoc] + cases g with + | mixer β => + change flip D h*(act (RootSpin.R β)*ordinary D h w)=(act (RootSpin.R β)*ordinary D h w)*flip D h + apply commute_then + apply ContinuousLinearMap.ext + intro x + simp only [mul_apply_eq_comp,flip] + exact spinFlip_R (H := Tail D h) (FiniteTensor.operatorPower (D+1) (FiniteTree.flip D h)) β x + | cost γ => + change flip D h*(applyPulse (tensorPulse D h) (.control (fun i => (w,if i=0 then -γ else γ)))*ordinary D h w)= + (applyPulse (tensorPulse D h) (.control (fun i => (w,if i=0 then -γ else γ)))*ordinary D h w)*flip D h + apply commute_then + apply ContinuousLinearMap.ext + intro x + simp only [mul_apply_eq_comp,flip,applyPulse] + apply spinFlip_diagonal + intro i + simp only [Function.comp_apply] + rw [pulse_exp,pulse_exp,←FiniteTensor.operatorPower_mul,←FiniteTensor.operatorPower_mul] + congr 1 + have he (j : Fin 2) : (Real.sqrt (D:ℝ))⁻¹*(if j=0 then -γ else γ)= + (if j=0 then -γ/Real.sqrt D else γ/Real.sqrt D) := by split <;> ring + simp only [he] + exact (FiniteTree.ordinary D w h).cost_blocks_flip γ i + +theorem insertion_odd (D h : ℕ) (w : List PointedTree.Gate) : + flip D h (insertion D h w)= -insertion D h w := by + have hs : flip D h*star (ordinary D h w)=star (ordinary D h w)*flip D h := by + have hh := congrArg star (flip_ordinary D h w) + simpa only [star_mul,flip_star] using hh.symm + have hZ : flip D h*(act RootSpin.Z : Space D h →L[ℂ] Space D h)= -(act RootSpin.Z : Space D h →L[ℂ] Space D h)*flip D h := by + apply ContinuousLinearMap.ext + intro x + simp only [mul_apply_eq_comp,neg_apply,flip] + exact spinFlip_Z (H := Tail D h) (FiniteTensor.operatorPower (D+1) (FiniteTree.flip D h)) x + rw [insertion_eq] + change (flip D h*(star (ordinary D h w)*(act RootSpin.Z : Space D h →L[ℂ] Space D h)*ordinary D h w)) (vac D h)=_ + rw [←mul_assoc,←mul_assoc,hs,mul_assoc (star _),hZ] + simp only [mul_assoc,flip_ordinary,mul_apply_eq_comp,neg_apply,flip_vac,map_neg] + + +theorem insertion_centered (D h : ℕ) (w : List PointedTree.Gate) : + ⟪vac D h,insertion D h w⟫_ℂ=0 := by + have hi := (Unitary.linearIsometryEquiv ⟨flip D h,flip_unitary D h⟩).inner_map_map + (vac D h) (insertion D h w) + change ⟪flip D h (vac D h),flip D h (insertion D h w)⟫_ℂ=⟪vac D h,insertion D h w⟫_ℂ at hi + rw [flip_vac,insertion_odd,inner_neg_right] at hi + linear_combination -(1/2:ℂ)*hi + +end FiniteTree.FullRoot + + + +open scoped InnerProductSpace Topology +open Filter ContinuousLinearMap +namespace FiniteTree.FullRoot +open QuantumCLT CoherentFock RootTensorCLT TensorPackets + + +def excitation (D h : ℕ) (w : List PointedTree.Gate) : Tail D h := + FiniteTensor.normalizedInsertion (D+1) 1 (FiniteTree.ordinary D w h).observable + (FiniteTensor.power (D+1) (FiniteTree.vac D h)) + +theorem excitation_factor (D h : ℕ) (hD : 0 Real.sqrt ((D:ℝ)+1)/Real.sqrt (D:ℝ)) atTop (𝓝 1) := by + have hi : Tendsto (fun D : ℕ => (D:ℝ)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop + have ht := Real.continuous_sqrt.continuousAt.tendsto.comp ((tendsto_const_nhds.add hi) : + Tendsto (fun D : ℕ => 1+(D:ℝ)⁻¹) atTop (𝓝 (1+0))) + simp only [add_zero,Real.sqrt_one] at ht + apply ht.congr' + filter_upwards [eventually_gt_atTop (0:ℕ)] with D hD + have hd : (D:ℝ)≠0 := by exact_mod_cast hD.ne' + change Real.sqrt (1+(D:ℝ)⁻¹)=Real.sqrt ((D:ℝ)+1)/Real.sqrt (D:ℝ) + rw [←Real.sqrt_div (by positivity)] + congr 1 + field_simp [hd] + +theorem excitation_tensor_limit (h : ℕ) (w : List PointedTree.Gate) (l : List Label) : + Tendsto (fun D => ⟪excitation D h w,tensorState D h l⟫_ℂ) atTop + (𝓝 ⟪creationVacuum (PointedTree.ordinary w h).insertion,fockState (childDirection h) l⟫_ℂ) := by + have hg : Tendsto (fun D => ⟪FiniteTree.vac D h,childState D h l⟫_ℂ) atTop (𝓝 1) := by + have ht := child_Gram_limit h [] l + simpa only [childState,generators,List.map_nil,List.prod_nil,one_apply_eq_self] using ht + have hr := Complex.continuous_ofReal.continuousAt.tendsto.comp sqrt_ratio_limit + have ht := (hr.mul (FiniteTree.excitation_tensor_limit h w l)).mul hg + simp only [Complex.ofReal_one,one_mul,mul_one] at ht + apply ht.congr' + filter_upwards [eventually_gt_atTop (0:ℕ)] with D hD + exact (excitation_factor D h hD w l).symm + + +theorem root_shift_insertion_limit (h : ℕ) (w u : List PointedTree.Gate) : + Tendsto (fun D => ⟪PointedTree.plusEmbedding (excitation D h w),insertion D h u⟫_ℂ) atTop + (𝓝 ⟪PointedTree.rootShift h (PointedTree.ordinary w h).insertion, + (PointedTree.ordinary u (h+1)).insertion⟫_ℂ) := by + have ht := TensorPackets.marked_limit (fun D => Tail D h) (fun D => tensorState D h) + (fockState (childDirection h)) (fun D => excitation D h w) + (creationVacuum (PointedTree.ordinary w h).insertion) + (excitation_tensor_limit h w) (compile (insertionProgram u) start) + have hf : run (W ∘ childDirection h) (insertionProgram u) (PointedTree.vac (h+1))= + packet (fockState (childDirection h)) (compile (insertionProgram u) start) := by + change run (W ∘ childDirection h) (insertionProgram u) + (PointedTree.plusEmbedding (fockState (childDirection h) []))=_ + rw [←start_packet] + exact RootTensorCLT.run_packet _ _ (fock_step _) _ _ + change Tendsto _ atTop (𝓝 ⟪(PointedTree.rootShift h (PointedTree.ordinary w h).insertion : PointedTree.Level (h+1)), + ((PointedTree.ordinary u (h+1)).insertion : PointedTree.Level (h+1))⟫_ℂ) + rw [PointedTree.rootShift_coe,limiting_insertion,hf] + simpa only [insertion,run_packet] using ht + +end FiniteTree.FullRoot + + + +open scoped InnerProductSpace ComplexConjugate +namespace EdgeProjection +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + + + +theorem decomposition (S : H ≃ₗᵢ[ℂ] H) (hS : Function.Involutive S) + (P : H →L[ℂ] H) (_ : IsStarProjection P) (f : H) + (hc : ⟪P f,S (P f)⟫_ℂ=0) : + ⟪f,S f⟫_ℂ=(2:ℂ)*((⟪P f,S f⟫_ℂ).re:ℂ)+⟪f-P f,S (f-P f)⟫_ℂ := by + have hs (x y : H) : ⟪x,S y⟫_ℂ=⟪S x,y⟫_ℂ := by + have hi := S.inner_map_map (S x) y + simpa only [hS x] using hi + have hcross : ⟪f-P f,S (P f)⟫_ℂ=star ⟪P f,S f⟫_ℂ := by + rw [inner_sub_left,hc,sub_zero,hs] + simpa only [Complex.star_def] using (inner_conj_symm (𝕜 := ℂ) (S f) (P f)).symm + have hp : ⟪P f,S f⟫_ℂ=⟪P f,S (f-P f)⟫_ℂ := by + rw [map_sub,inner_sub_right,hc,sub_zero] + calc + ⟪f,S f⟫_ℂ=⟪P f+(f-P f),S (P f+(f-P f))⟫_ℂ := by rw [add_sub_cancel] + _ = ⟪P f,S (f-P f)⟫_ℂ + star ⟪P f,S f⟫_ℂ + ⟪f-P f,S (f-P f)⟫_ℂ := by + rw [map_add,inner_add_left,inner_add_right,inner_add_right,hc,zero_add,hcross] + abel + _ = _ := by rw [←hp,Complex.star_def,Complex.add_conj]; push_cast; ring + + + +omit [CompleteSpace H] in +theorem remainder_bound (S : H ≃ₗᵢ[ℂ] H) (P : H →L[ℂ] H) (f : H) : + ‖⟪f-P f,S (f-P f)⟫_ℂ‖ ≤ ‖f-P f‖^2 := by + calc + _ ≤ ‖f-P f‖*‖S (f-P f)‖ := norm_inner_le_norm _ _ + _ = _ := by rw [S.norm_map]; ring + +theorem real_decomposition (S : H ≃ₗᵢ[ℂ] H) (hS : Function.Involutive S) + (P : H →L[ℂ] H) (hP : IsStarProjection P) (f : H) + (hc : ⟪P f,S (P f)⟫_ℂ=0) : + |(⟪f,S f⟫_ℂ).re-2*(⟪P f,S f⟫_ℂ).re| ≤ ‖f-P f‖^2 := by + rw [decomposition S hS P hP f hc] + have he : ((2:ℂ)*((⟪P f,S f⟫_ℂ).re:ℂ)+⟪f-P f,S (f-P f)⟫_ℂ).re- + 2*(⟪P f,S f⟫_ℂ).re=(⟪f-P f,S (f-P f)⟫_ℂ).re := by + simp + rw [he] + exact (Complex.abs_re_le_norm ⟪f-P f,S (f-P f)⟫_ℂ).trans (remainder_bound S P f) + +end EdgeProjection + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/MixedReplicaIdentity.lean b/lean/OAI/Probability/ParisiFinite/MixedReplicaIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..6facac47ce323482b683c9b2cfd628f02aeb4e30 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/MixedReplicaIdentity.lean @@ -0,0 +1,721 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ThermalDeviation + +namespace OAI + +/-! Mixed Replica Identity. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {K : Type*} [Fintype K] [DecidableEq K] + + + +theorem mixed_replica_identity {n r : ℕ} (hn : 0 f σ*∑ l, (overlap (σ i) (σ l))^(d k)) + ∂gaussianLaw (MixedIndex n d)) - + (r:ℝ)*x k*(∫ z, replicaMean (field (mixedCoeff n d β x) z) + (fun τ : Fin (r+1) → Configuration n => + f (fun l => τ l.castSucc)*(overlap (τ i.castSucc) (τ (Fin.last r)))^(d k)) + ∂gaussianLaw (MixedIndex n d)) := by + have h := integral_field_replica_energy_covariance + (mixedCoeff n d β x) (mixedNoise n d k) i f + simp_rw [mixedNoise_crossCov hn] at h + simp only [replicaMean, ← Finset.mul_sum] at h ⊢ + have he₁ (σ : Fin r → Configuration n) (z) : + replicaWeight (field (mixedCoeff n d β x) z) σ* + (f σ*(x k*∑ l, overlap (σ i) (σ l)^(d k))) = + x k*(replicaWeight (field (mixedCoeff n d β x) z) σ* + (f σ*∑ l, overlap (σ i) (σ l)^(d k))) := by ring + have he₂ (τ : Fin (r+1) → Configuration n) (z) : + replicaWeight (field (mixedCoeff n d β x) z) τ* + (f (fun l => τ l.castSucc)*(x k*overlap (τ i.castSucc) (τ (Fin.last r))^(d k))) = + x k*(replicaWeight (field (mixedCoeff n d β x) z) τ* + (f (fun l => τ l.castSucc)*overlap (τ i.castSucc) (τ (Fin.last r))^(d k))) := by ring + simp_rw [he₁, he₂, ← Finset.mul_sum, integral_const_mul] at h + convert h using 1 + ring + +lemma mixed_energyMean {n : ℕ} (hn : 0 (overlap (τ 0) (τ 1))^(d k))) := by + have h := mixed_replica_identity hn d β x k (0 : Fin 1) (fun _ => 1) + norm_num only [Nat.cast_one, Fin.castSucc_zero] at h + change energyObservation (mixedCoeff n d β x) (mixedNoise n d k) (0 : Fin 1) (fun _ => 1) = + x k*averagedReplica (mixedCoeff n d β x) + (fun σ : Fin 1 → Configuration n => 1*∑ l, (overlap (σ 0) (σ l))^(d k))- + (1:ℝ)*x k*averagedReplica (mixedCoeff n d β x) + (fun τ : Fin 2 → Configuration n => 1*(overlap (τ 0) (τ 1))^(d k)) at h + simp only [energyObservation_one, one_mul, Fin.sum_univ_one, overlap_self hn, one_pow, + averagedReplica_const] at h + linarith + + + +def mixedGGDefect {n r : ℕ} (d : K → ℕ) (β : ℝ) (x : K → ℝ) (k : K) (i : Fin r) + (f : (Fin r → Configuration n) → ℝ) : ℝ := + (r:ℝ)*averagedReplica (mixedCoeff n d β x) + (fun τ : Fin (r+1) → Configuration n => f (fun l => τ l.castSucc)* + (overlap (τ i.castSucc) (τ (Fin.last r)))^(d k))- + averagedReplica (mixedCoeff n d β x) f* + averagedReplica (mixedCoeff n d β x) + (fun τ : Fin 2 → Configuration n => (overlap (τ 0) (τ 1))^(d k))- + averagedReplica (mixedCoeff n d β x) + (fun σ => f σ*∑ l ∈ Finset.univ.erase i, (overlap (σ i) (σ l))^(d k)) + + + +theorem mixedGGDefect_identity {n r : ℕ} (hn : 0 f σ*∑ l, overlap (σ i) (σ l)^(d k))- + (r:ℝ)*x k*averagedReplica (mixedCoeff n d β x) + (fun τ : Fin (r+1) → Configuration n => f (fun l => τ l.castSucc)* + overlap (τ i.castSucc) (τ (Fin.last r))^(d k)) at h + have he (σ : Fin r → Configuration n) : f σ*∑ l, overlap (σ i) (σ l)^(d k) = + f σ+f σ*∑ l ∈ Finset.univ.erase i, overlap (σ i) (σ l)^(d k) := by + have hs := Finset.sum_erase_add Finset.univ (fun l => overlap (σ i) (σ l)^(d k)) (Finset.mem_univ i) + rw [overlap_self hn, one_pow] at hs + rw [← hs] + ring + simp_rw [he, averagedReplica_add] at h + rw [mixed_energyMean hn, h] + unfold mixedGGDefect + ring + + + +theorem mixedGGDefect_bound {n r : ℕ} (hn : 0 (overlap (τ 0) (τ 1))^(d k))|≤1 := by + apply averagedReplica_abs_bound + intro τ + rw [abs_pow] + exact pow_le_one₀ (abs_nonneg _) (abs_overlap_le_one _ _) + rw [mixed_energyMean hn] + rw [abs_le] at hb + constructor + · exact mul_nonneg ht (by linarith) + · nlinarith [mul_le_mul_of_nonneg_left hb.1 ht] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKGaussian ParisiFinite ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +omit [Fintype ι] [Nonempty ι] in +lemma continuous_field_coeff (z : κ → ℝ) : Continuous (fun A : ι → κ → ℝ => field A z) := by + unfold field + fun_prop + +lemma continuous_gibbsMean_first (v : ι → ℝ) : Continuous (fun x => gibbsMean 1 x v) := by + unfold gibbsMean + simp only [one_mul] + exact continuous_finsetSum _ fun s _ => (continuous_weight s).mul continuous_const + +lemma continuous_gibbsCov_first (v : ι → ℝ) : Continuous (fun x => gibbsCov 1 x v v) := by + unfold gibbsCov + exact (continuous_gibbsMean_first _).sub ((continuous_gibbsMean_first v).mul (continuous_gibbsMean_first v)) + +lemma continuous_energyMean_coeff (B : ι → κ → ℝ) : Continuous (fun A => energyMean A B) := by + unfold energyMean + suffices h : Continuous (fun A => ∫ z, gibbsMean 1 (field A z) (field B z) ∂gaussianLaw κ) by + simpa only [gibbsMean, one_mul] using h + apply continuous_of_dominated (bound:=fun z => ‖field B z‖) + · intro A + simpa only [zero_smul, add_zero] using (continuous_lineMean A B 0).aestronglyMeasurable + · intro A + exact ae_of_all _ fun z => by simpa only [Real.norm_eq_abs] using abs_gibbsMean_le 1 (field A z) (field B z) + · exact integrable_norm_field B + · exact ae_of_all _ fun z => (continuous_gibbsMean_first _).comp (continuous_field_coeff z) + +lemma abs_energyMean_le (A B : ι → κ → ℝ) : + |energyMean A B| ≤ ∫ z, ‖field B z‖ ∂gaussianLaw κ := by + apply abs_integral_le_integral_abs.trans + refine integral_mono ?_ (integrable_norm_field B) (fun z => ?_) + · simpa only [gibbsMean, one_mul, zero_smul, add_zero] using (integrable_lineMean A B 0).abs + · simpa only [gibbsMean, one_mul] using abs_gibbsMean_le 1 (field A z) (field B z) + + +def energyVariance (A B : ι → κ → ℝ) : ℝ := + ∫ z, gibbsCov 1 (field A z) (field B z) (field B z) ∂gaussianLaw κ + +lemma energyVariance_nonneg (A B : ι → κ → ℝ) : 0 ≤ energyVariance A B := + integral_nonneg fun _ => gibbsCov_self_nonneg _ _ _ + +lemma continuous_energyVariance_coeff (B : ι → κ → ℝ) : Continuous (fun A => energyVariance A B) := by + apply continuous_of_dominated (bound:=fun z => 2*‖field B z‖^2) + · intro A + simpa only [zero_smul, add_zero] using (continuous_lineVariance A B 0).aestronglyMeasurable + · intro A + exact ae_of_all _ fun z => by + simpa only [Real.norm_eq_abs, sq, mul_assoc] using abs_gibbsCov_le 1 (field A z) (field B z) (field B z) + · exact (integrable_norm_field_sq B).const_mul 2 + · exact ae_of_all _ fun z => (continuous_gibbsCov_first _).comp (continuous_field_coeff z) + +lemma abs_energyVariance_le (A B : ι → κ → ℝ) : + |energyVariance A B| ≤ ∫ z, 2*‖field B z‖^2 ∂gaussianLaw κ := by + apply abs_integral_le_integral_abs.trans + refine integral_mono ?_ ((integrable_norm_field_sq B).const_mul 2) (fun z => ?_) + · simpa only [zero_smul, add_zero] using (integrable_lineVariance A B 0).abs + · simpa only [sq, mul_assoc] using abs_gibbsCov_le 1 (field A z) (field B z) (field B z) + +omit [Nonempty ι] in +lemma varianceLine_eq_energyVariance (A B : ι → κ → ℝ) (t : ℝ) : + varianceLine A B t = energyVariance (affineCoeff A B t) B := by + simp only [varianceLine, energyVariance, field_affineCoeff] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity + + + +def intervalLaw (a b : ℝ) : Measure ℝ := ProbabilityTheory.cond volume (Set.Icc a b) + +instance intervalLaw_isFiniteMeasure (a b : ℝ) : IsFiniteMeasure (intervalLaw a b) := by + unfold intervalLaw + infer_instance + +lemma intervalLaw_probability {a b : ℝ} (hab : a < b) : IsProbabilityMeasure (intervalLaw a b) := by + apply cond_isProbabilityMeasure_of_finite + · rw [Real.volume_Icc] + exact (ENNReal.ofReal_pos.mpr (sub_pos.mpr hab)).ne' + · rw [Real.volume_Icc] + exact ENNReal.ofReal_ne_top + +lemma intervalLaw_ae (a b : ℝ) : ∀ᵐ t ∂intervalLaw a b, t ∈ Set.Icc a b := + ae_cond_mem measurableSet_Icc + +lemma integral_intervalLaw {a b : ℝ} (hab : a ≤ b) (f : ℝ → ℝ) : + (∫ t, f t ∂intervalLaw a b) = (b-a)⁻¹*(∫ t in a..b, f t) := by + simp only [intervalLaw, ProbabilityTheory.cond, integral_smul_measure, Real.volume_Icc, + ENNReal.toReal_inv, ENNReal.toReal_ofReal (sub_nonneg.mpr hab), smul_eq_mul] + rw [integral_Icc_eq_integral_Ioc, intervalIntegral.integral_of_le hab] + +abbrev boxLaw (m : ℕ) (a b : ℝ) : Measure (Fin m → ℝ) := Measure.pi (fun _ => intervalLaw a b) + +lemma boxLaw_ae (m : ℕ) (a b : ℝ) : ∀ᵐ x ∂boxLaw m a b, ∀ k, x k∈Set.Icc a b := by + apply ae_all_iff.mpr + intro k + exact Measure.tendsto_eval_ae_ae.eventually (intervalLaw_ae a b) + + +lemma integral_boxLaw_coordinate {m : ℕ} {a b : ℝ} (_hab : a < b) + (k : Fin (m+1)) {F : (Fin (m+1) → ℝ) → ℝ} (hF : Integrable F (boxLaw (m+1) a b)) : + (∫ x, F x ∂boxLaw (m+1) a b) = + ∫ y : Fin m → ℝ, ∫ t : ℝ, F (k.insertNth t y) ∂intervalLaw a b ∂boxLaw m a b := by + let := intervalLaw_probability _hab + let T := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (m+1) => ℝ) k).symm + have hm : MeasurePreserving T ((intervalLaw a b).prod (boxLaw m a b)) (boxLaw (m+1) a b) := + (measurePreserving_piFinSuccAbove (fun _ : Fin (m+1) => intervalLaw a b) k).symm + have hi : Integrable (fun p => F (T p)) ((intervalLaw a b).prod (boxLaw m a b)) := + (hm.integrable_comp hF.aestronglyMeasurable).mpr hF + rw [← hm.integral_comp' F, integral_prod_symm _ hi] + rfl + + + +theorem exists_box_sum_le {m : ℕ} {a b C : ℝ} (hab : a < b) + (F : Fin (m+1) → (Fin (m+1) → ℝ) → ℝ) + (hc : ∀ k, Continuous (F k)) + (hb : ∀ k, ∃ M : ℝ, ∀ x, |F k x| ≤ M) + (hi : ∀ k (y : Fin m → ℝ), (∀ j, y j∈Set.Icc a b) → + (∫ t in a..b, F k (k.insertNth t y)) ≤ (b-a)*C) : + ∃ x : Fin (m+1) → ℝ, (∀ k, x k∈Set.Icc a b) ∧ + (∑ k, F k x) ≤ (m+1:ℕ)*C := by + let := intervalLaw_probability hab + have hI (k) : Integrable (F k) (boxLaw (m+1) a b) := by + obtain ⟨M, hM⟩ := hb k + exact Integrable.of_bound (hc k).aestronglyMeasurable M (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hM x) + have hsum : Integrable (fun x => ∑ k, F k x) (boxLaw (m+1) a b) := + integrable_finsetSum _ fun k _ => hI k + have hnull : boxLaw (m+1) a b {x | ¬∀ k, x k∈Set.Icc a b}=0 := by + exact ae_iff.mp (boxLaw_ae (m+1) a b) + obtain ⟨x, hx, hle⟩ := exists_notMem_null_le_integral hsum hnull + refine ⟨x, not_not.mp hx, hle.trans ?_⟩ + rw [integral_finsetSum _ (fun k _ => hI k)] + calc + _ ≤ ∑ _k : Fin (m+1), C := by + apply Finset.sum_le_sum + intro k _ + rw [integral_boxLaw_coordinate hab k (hI k)] + have hint : Integrable (fun y : Fin m → ℝ => ∫ t, F k (k.insertNth t y) ∂intervalLaw a b) (boxLaw m a b) := by + let T := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (m+1) => ℝ) k).symm + have hm : MeasurePreserving T ((intervalLaw a b).prod (boxLaw m a b)) (boxLaw (m+1) a b) := + (measurePreserving_piFinSuccAbove (fun _ : Fin (m+1) => intervalLaw a b) k).symm + exact ((hm.integrable_comp (hc k).aestronglyMeasurable).mpr (hI k)).integral_prod_right + have hj := integral_mono_ae hint (integrable_const C) ?_ + · simpa using hj + filter_upwards [boxLaw_ae m a b] with y hy + rw [integral_intervalLaw hab.le] + have hi' := hi k y hy + have hp : 0 < b-a := sub_pos.mpr hab + calc + _ ≤ (b-a)⁻¹*((b-a)*C) := mul_le_mul_of_nonneg_left hi' (inv_nonneg.mpr hp.le) + _ = C := by field_simp + _ = _ := by simp + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite +variable {K : Type*} [Fintype K] [DecidableEq K] + +omit [Fintype K] [DecidableEq K] in +lemma continuous_mixedCoeff (n : ℕ) (d : K → ℕ) (β : ℝ) : + Continuous (mixedCoeff n d β) := by + apply continuous_pi + intro σ + apply continuous_pi + intro u + cases u with + | inl e => exact continuous_const + | inr u => exact (continuous_apply u.1).mul continuous_const + +omit [Fintype K] in +lemma continuous_shiftCoord (k : K) (t : ℝ) : + Continuous (fun x : K → ℝ => Function.update x k (x k+t)) := by + apply continuous_pi + intro j + by_cases h : j=k + · subst j + simpa only [Function.update_self] using (continuous_apply k : Continuous (fun x : K → ℝ => x k)).add_const t + · simpa only [Function.update_of_ne h] using continuous_apply j + + + +def mixedError (n : ℕ) (d : K → ℕ) (β δ V : ℝ) (k : K) (x : K → ℝ) : ℝ := + energyVariance (mixedCoeff n d β x) (mixedNoise n d k)+(1+4*V/δ)+ + (energyMean (mixedCoeff n d β (Function.update x k (x k+δ))) (mixedNoise n d k)- + energyMean (mixedCoeff n d β (Function.update x k (x k-δ))) (mixedNoise n d k)) + +lemma continuous_mixedError (n : ℕ) (d : K → ℕ) (β δ V : ℝ) (k : K) : + Continuous (mixedError n d β δ V k) := by + apply (((continuous_energyVariance_coeff _).comp (continuous_mixedCoeff n d β)).add continuous_const).add + apply Continuous.sub + · exact (continuous_energyMean_coeff _).comp ((continuous_mixedCoeff n d β).comp (continuous_shiftCoord k δ)) + · have hc := (continuous_energyMean_coeff (mixedNoise n d k)).comp + ((continuous_mixedCoeff n d β).comp (continuous_shiftCoord k (-δ))) + change Continuous (fun x => energyMean (mixedCoeff n d β (Function.update x k (x k+(-δ)))) (mixedNoise n d k)) at hc + simpa only [sub_eq_add_neg] using hc + +lemma mixedError_bounded (n : ℕ) (d : K → ℕ) (β δ V : ℝ) (k : K) : + ∃ M : ℝ, ∀ x, |mixedError n d β δ V k x| ≤ M := by + let B := mixedNoise n d k + let U := ∫ z, ‖field B z‖ ∂gaussianLaw (MixedIndex n d) + let W := ∫ z, 2*‖field B z‖^2 ∂gaussianLaw (MixedIndex n d) + refine ⟨W+|1+4*V/δ|+2*U, fun x => ?_⟩ + have h0 := abs_energyVariance_le (mixedCoeff n d β x) B + have h1 := abs_energyMean_le (mixedCoeff n d β (Function.update x k (x k+δ))) B + have h2 := abs_energyMean_le (mixedCoeff n d β (Function.update x k (x k-δ))) B + change _ ≤ W at h0 + change _ ≤ U at h1 h2 + unfold mixedError + calc + _ ≤ |energyVariance (mixedCoeff n d β x) B+(1+4*V/δ)|+ + |energyMean (mixedCoeff n d β (Function.update x k (x k+δ))) B- + energyMean (mixedCoeff n d β (Function.update x k (x k-δ))) B| := abs_add_le _ _ + _ ≤ _ := by + linarith [abs_add_le (energyVariance (mixedCoeff n d β x) B) (1+4*V/δ), + abs_sub (energyMean (mixedCoeff n d β (Function.update x k (x k+δ))) B) + (energyMean (mixedCoeff n d β (Function.update x k (x k-δ))) B)] + +lemma mixedError_as_line (n : ℕ) (d : K → ℕ) (β δ V : ℝ) (k : K) (x : K → ℝ) (t : ℝ) : + mixedError n d β δ V k (Function.update x k t) = + varianceLine (mixedCoeff n d β (Function.update x k 0)) (mixedNoise n d k) t+(1+4*V/δ)+ + (meanLine (mixedCoeff n d β (Function.update x k 0)) (mixedNoise n d k) (t+δ)- + meanLine (mixedCoeff n d β (Function.update x k 0)) (mixedNoise n d k) (t-δ)) := by + simp only [varianceLine_eq_energyVariance, meanLine_eq_energyMean, affineCoeff_mixed_update, + mixedError, Function.update_self, Function.update_idem] + +lemma mixedError_dominates {n : ℕ} (hn : 0 linarith [hu.1, hu.2] + · rw [Function.update_of_ne h] + constructor <;> linarith [(hx j).1, (hx j).2] + nlinarith [sq_nonneg (3*s-Function.update x k u j)] + have hsum := Finset.sum_le_sum (fun j (_ : j∈Finset.univ) => hcoord j) + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] at hsum + nlinarith [sq_nonneg β] + have h := energyDeviation_amplitude_bound A B hδ (hx k) hV + rw [varianceLine_eq_energyVariance, meanLine_eq_energyMean, meanLine_eq_energyMean, + affineCoeff_mixed_update, affineCoeff_mixed_update, affineCoeff_mixed_update, + Function.update_eq_self] at h + exact h + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma mixedError_insert {m : ℕ} (n : ℕ) (d : Fin (m+1) → ℕ) (β δ V : ℝ) + (k : Fin (m+1)) (y : Fin m → ℝ) (t : ℝ) : + mixedError n d β δ V k (k.insertNth t y) = + varianceLine (mixedCoeff n d β (k.insertNth 0 y)) (mixedNoise n d k) t+(1+4*V/δ)+ + (meanLine (mixedCoeff n d β (k.insertNth 0 y)) (mixedNoise n d k) (t+δ)- + meanLine (mixedCoeff n d β (k.insertNth 0 y)) (mixedNoise n d k) (t-δ)) := by + simpa only [Fin.update_insertNth] using mixedError_as_line n d β δ V k (k.insertNth 0 y) t + +lemma integral_mixedError_le {m n : ℕ} (hn : 0 meanLine A B (t+δ)-meanLine A B (t-δ)) := + ((continuous_meanLine A B).comp (continuous_id.add_const δ)).sub + ((continuous_meanLine A B).comp (continuous_id.sub continuous_const)) + simp_rw [mixedError_insert] + change (∫ t in s..2*s, (varianceLine A B t+(1+4*V/δ))+(meanLine A B (t+δ)-meanLine A B (t-δ))) ≤ _ + have hv : Continuous (fun t => varianceLine A B t+(1+4*V/δ)) := + (continuous_varianceLine A B).add continuous_const + rw [intervalIntegral.integral_add (hv.intervalIntegrable s (2*s)) (hp.intervalIntegrable s (2*s))] + rw [intervalIntegral.integral_add ((continuous_varianceLine A B).intervalIntegrable s (2*s)) + (continuous_const.intervalIntegrable s (2*s)), integral_varianceLine, intervalIntegral.integral_const, smul_eq_mul] + have hb (t : ℝ) (ht : 0 ≤ t) : 0 ≤ meanLine A B t ∧ meanLine A B t ≤ 2*t := by + have he : affineCoeff A B t = mixedCoeff n d β (k.insertNth t y) := by + simpa only [A, B, Fin.update_insertNth] using affineCoeff_mixed_update n d β (k.insertNth 0 y) k t + rw [meanLine_eq_energyMean, he] + simpa only [Fin.insertNth_apply_same] using mixed_energyMean_bounds hn d β (k.insertNth t y) k + (by simpa only [Fin.insertNth_apply_same] using ht) + have h2 := hb (2*s) (by linarith) + have h1 := hb s hs.le + have hup := hb (2*s+δ) (by linarith) + have hlo := hb (s-δ) (by linarith) + have hi := integral_meanLine_increment_le A B s (2*s) hδ + have hh : meanLine A B (2*s+δ)-meanLine A B (s-δ) ≤ 6*s := by linarith + have hmul := mul_le_mul_of_nonneg_left hh (by positivity : (0:ℝ)≤2*δ) + nlinarith + + + +theorem exists_mixed_energy_amplitude {m n : ℕ} (hn : 0 by + simpa only [show 2*s-s=s by ring] using integral_mixedError_le hn d β V hs hδ hδs k y) + have hdom (k) := mixedError_dominates hn d β hs hδ hδs k x hx + simp only [Fintype.card_fin] at hdom + have hnon (k) : 0 ≤ mixedError n d β δ V k x := + (energyDeviation_nonneg _ _ _).trans (hdom k) + refine ⟨x, hx, fun k => (hdom k).trans ?_⟩ + apply le_trans _ hsum + exact Finset.single_le_sum (fun j _ => hnon j) (Finset.mem_univ k) + + + +theorem exists_mixed_GG_amplitude {m n : ℕ} (hn : 0 ?_⟩ + have hgg := mixedGGDefect_bound hn d β x k i f (by norm_num : (0:ℝ)≤1) hf + rw [one_mul, abs_mul, abs_of_nonneg (hs.le.trans (hx k).1)] at hgg + have hmul := mul_le_mul_of_nonneg_right (hx k).1 (abs_nonneg (mixedGGDefect d β x k i f)) + apply (le_div_iff₀ hs).mpr + nlinarith only [hgg, hmul, h k] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {K : Type*} [Fintype K] [DecidableEq K] + +omit [DecidableEq K] in +lemma increment_mixed_sub {n : ℕ} (hn : 0 β*skCoeff n s e) σ τ = + ∑ k, 2*(x k)^2*(1-(overlap σ τ)^(d k)) := by + have hk (s t : Configuration n) : kernel (mixedCoeff n d β x) s t = + kernel (fun s e => β*skCoeff n s e) s t+∑ k, (x k)^2*(overlap s t)^(d k) := by + rw [mixedCoeff_kernel hn, kernel_scale, kernel, coeff_covariance hn] + ring + rw [increment_eq_kernel, increment_eq_kernel, hk, hk, hk, overlap_self hn, overlap_self hn] + simp only [one_pow, mul_one] + have hs : (∑ k, (x k)^2)+(∑ k, (x k)^2)-2*(∑ k, (x k)^2*(overlap σ τ)^(d k))= + ∑ k, 2*(x k)^2*(1-(overlap σ τ)^(d k)) := by + rw [← Finset.sum_add_distrib, Finset.mul_sum, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + linarith only [hs] + +omit [DecidableEq K] in +lemma abs_increment_mixed_sub_le {n : ℕ} (hn : 0 β*skCoeff n s e) σ τ| ≤ 4*∑ k, (x k)^2 := by + rw [increment_mixed_sub hn, Finset.mul_sum] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro k _ + rw [abs_mul, abs_of_nonneg (by positivity : (0:ℝ)≤2*(x k)^2)] + have h : |(overlap σ τ)^(d k)| ≤ 1 := by + rw [abs_pow] + exact pow_le_one₀ (abs_nonneg _) (abs_overlap_le_one _ _) + have hd : |1-(overlap σ τ)^(d k)| ≤ 2 := by + have := abs_sub_le (1:ℝ) 0 ((overlap σ τ)^(d k)) + simp only [sub_zero, zero_sub, abs_neg, abs_one] at this + linarith + nlinarith [mul_le_mul_of_nonneg_left hd (by positivity : (0:ℝ)≤2*(x k)^2)] + + + +omit [DecidableEq K] in +theorem mixed_pressure_error {n : ℕ} (hn : 0 β*skCoeff n s e)| ≤ + Real.pi*(∑ k, (x k)^2) := by + have h := expected_difference_le (fun s e => β*skCoeff n s e) (mixedCoeff n d β x) + (show (0:ℝ)≤4*∑ k, (x k)^2 by positivity) (abs_increment_mixed_sub_le hn d β x) + convert h using 1 + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma mixed_root_pressure_bound {n L : ℕ} (hn : 0 (h k r i f hf).trans (mixed_root_GG_bound hn (Nat.succ_pos m) β)⟩ + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity + + + +def allPowerRoot (n : ℕ) : ℝ := Real.sqrt (Real.sqrt (eighthRootScale n)) +def powerCutoff (n : ℕ) : ℕ := ⌊allPowerRoot n⌋₊ + +lemma allPowerRoot_nonneg (n : ℕ) : 0 ≤ allPowerRoot n := Real.sqrt_nonneg _ +lemma allPowerRoot_pow_four (n : ℕ) : allPowerRoot n^4=eighthRootScale n := by + have h1 := Real.sq_sqrt (Real.sqrt_nonneg (eighthRootScale n)) + have h2 := Real.sq_sqrt (eighthRootScale_nonneg n) + change allPowerRoot n^2=Real.sqrt (eighthRootScale n) at h1 + calc + allPowerRoot n^4=(allPowerRoot n^2)^2 := by ring + _=eighthRootScale n := by rw [h1, h2] +lemma one_le_allPowerRoot {n : ℕ} (hn : 0 eighthRoot_amplitude_pressure_bound hn (hx k)) + rw [← Finset.sum_div] at hsum + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hsum + have hL := powerCutoff_cast_bound hn + have hm := mul_le_mul_of_nonneg_right hL (show 0 ≤ 4/(eighthRootScale n^2) by positivity) + have he : (2*q)*(4/(eighthRootScale n^2))=8/(q^7) := by + rw [← allPowerRoot_pow_four n] + change (2*q)*(4/((q^4)^2))=8/(q^7) + field_simp + ring + exact hsum.trans (hm.trans_eq he) + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Model.lean b/lean/OAI/Probability/ParisiFinite/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c8d0349b596311bcdbb2338aa70fd7db50bf63f --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Model.lean @@ -0,0 +1,636 @@ +import Mathlib + +namespace OAI + +/-! Model. -/ + +noncomputable section + + + + + + + + + + + + + +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] + +lemma l2_mean_inner (f : Lp ℝ 2 P) : + (∫ ω,f ω ∂P) = inner ℝ ((memLp_const (1:ℝ) : MemLp (fun _ : Ω => (1:ℝ)) 2 P).toLp _) f := by + rw [L2.inner_def] + apply integral_congr_ae + filter_upwards [MemLp.coeFn_toLp (memLp_const (1:ℝ) : MemLp (fun _ : Ω => (1:ℝ)) 2 P)] with ω hω + simp + +omit [IsProbabilityMeasure P] in +lemma l2_square_integral (f : Lp ℝ 2 P) : (∫ ω,f ω^2 ∂P)=‖f‖^2 := by + rw [←real_inner_self_eq_norm_sq, L2.inner_def] + apply integral_congr_ae + filter_upwards [] with ω + simp [pow_two] + +lemma l2_variance (f : Lp ℝ 2 P) : + variance f P=‖f‖^2-(∫ ω,f ω ∂P)^2 := by + rw [variance_eq_sub (Lp.memLp f)] + simpa only [Pi.pow_apply] using congrArg (fun x : ℝ => x-(∫ ω,f ω ∂P)^2) (l2_square_integral f) + +lemma continuous_l2_mean : Continuous (fun f : Lp ℝ 2 P => ∫ ω,f ω ∂P) := by + simp_rw [l2_mean_inner] + fun_prop + +lemma continuous_l2_variance : Continuous (fun f : Lp ℝ 2 P => variance f P) := by + simp_rw [l2_variance] + exact (continuous_norm.pow 2).sub (continuous_l2_mean.pow 2) + +lemma hasGaussianLaw_l2_limit {f : ℕ → Lp ℝ 2 P} {g : Lp ℝ 2 P} + (hf : ∀ n,HasGaussianLaw (f n) P) (hg : Tendsto f atTop (𝓝 g)) : + HasGaussianLaw g P := by + have hd := (tendstoInMeasure_of_tendsto_Lp hg).tendstoInDistribution + (fun n => (Lp.aestronglyMeasurable (f n)).aemeasurable) + have hc := ProbabilityMeasure.tendsto_iff_tendsto_charFun.mp hd.tendsto + have hm := continuous_l2_mean.tendsto g |>.comp hg + have hv := continuous_l2_variance.tendsto g |>.comp hg + have hmap : P.map g=gaussianReal (∫ ω,g ω ∂P) (variance g P).toNNReal := by + apply Measure.ext_of_charFun + funext t + have ht := (((hm.ofReal.const_mul (t:ℂ)).mul_const Complex.I).sub + ((hv.ofReal.mul_const ((t:ℂ)^2)).div_const 2)).cexp + have he (n : ℕ) : charFun (P.map (f n)) t = + Complex.exp ((t:ℂ)*(∫ ω,f n ω ∂P)*Complex.I-(variance (f n) P)* (t:ℂ)^2/2) := by + rw [(hf n).map_eq_gaussianReal,charFun_gaussianReal,Real.coe_toNNReal _ (variance_nonneg _ _)] + have ht' : Tendsto (fun n => charFun (P.map (f n)) t) atTop + (𝓝 (Complex.exp ((t:ℂ)*(∫ ω,g ω ∂P)*Complex.I-(variance g P)*(t:ℂ)^2/2))) := by + convert! ht using 1 + exact funext he + rw [charFun_gaussianReal,Real.coe_toNNReal _ (variance_nonneg _ _)] + exact tendsto_nhds_unique (hc t) ht' + exact ⟨(Lp.aestronglyMeasurable g).aemeasurable, by rw [hmap]; infer_instance⟩ + +lemma isClosed_gaussian_l2 : IsClosed {f : Lp ℝ 2 P | HasGaussianLaw f P} := by + apply isSeqClosed_iff_isClosed.mp + intro f g hf hg + exact hasGaussianLaw_l2_limit hf hg +end BrownianConstruction + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction +variable (ι : Type*) +def gaussianProduct : Measure (ι → ℝ) := Measure.infinitePi (fun _ : ι => gaussianReal 0 1) +instance : IsProbabilityMeasure (gaussianProduct ι) := by + unfold gaussianProduct + infer_instance +lemma gaussianCoordinate_law (i : ι) : + HasLaw (fun ω : ι → ℝ => ω i) (gaussianReal 0 1) (gaussianProduct ι) := + (measurePreserving_eval_infinitePi (fun _ : ι => gaussianReal 0 1) i).hasLaw +lemma gaussianCoordinate_gaussian (i : ι) : + HasGaussianLaw (fun ω : ι → ℝ => ω i) (gaussianProduct ι) := + (gaussianCoordinate_law ι i).hasGaussianLaw +lemma gaussianCoordinate_memLp (i : ι) : + MemLp (fun ω : ι → ℝ => ω i) 2 (gaussianProduct ι) := + (gaussianCoordinate_gaussian ι i).memLp_two +def gaussianCoordinate (i : ι) : Lp ℝ 2 (gaussianProduct ι) := + (gaussianCoordinate_memLp ι i).toLp (fun ω => ω i) +lemma gaussianCoordinate_ae (i : ι) : gaussianCoordinate ι i =ᵐ[gaussianProduct ι] (fun ω => ω i) := + MemLp.coeFn_toLp _ +lemma gaussianCoordinate_mean (i : ι) : (∫ ω,gaussianCoordinate ι i ω ∂gaussianProduct ι)=0 := by + rw [integral_congr_ae (gaussianCoordinate_ae ι i)] + exact (gaussianCoordinate_law ι i).integral_eq ▸ integral_id_gaussianReal +lemma gaussianCoordinates_independent : + iIndepFun (fun i (ω : ι → ℝ) => ω i) (gaussianProduct ι) := + iIndepFun_infinitePi (X:=fun _ : ι => id) (fun _ => measurable_id) + +lemma gaussianCoordinate_variance (i : ι) : variance (gaussianCoordinate ι i) (gaussianProduct ι)=1 := by + have hh := ((gaussianCoordinate_law ι i).congr (gaussianCoordinate_ae ι i)).variance_eq + simpa using hh + +lemma gaussianCoordinate_inner [DecidableEq ι] (i j : ι) : + inner ℝ (gaussianCoordinate ι i) (gaussianCoordinate ι j) = if i=j then 1 else 0 := by + classical + by_cases hij : i=j + · subst j + rw [ite_eq_left rfl,real_inner_self_eq_norm_sq] + have hh := l2_variance (gaussianCoordinate ι i) + rw [gaussianCoordinate_variance,gaussianCoordinate_mean] at hh + simpa using hh.symm + · rw [ite_eq_right hij,L2.inner_def] + have he : (∫ ω,inner ℝ (gaussianCoordinate ι i ω) (gaussianCoordinate ι j ω) ∂gaussianProduct ι) + =∫ ω,ω i*ω j ∂gaussianProduct ι := by + apply integral_congr_ae + filter_upwards [gaussianCoordinate_ae ι i,gaussianCoordinate_ae ι j] with ω hi hj + simp [hi,hj,mul_comm] + rw [he] + have hind := (gaussianCoordinates_independent ι).indepFun hij + have hh := hind.integral_mul_eq_mul_integral + (gaussianCoordinate_memLp ι i).aestronglyMeasurable + (gaussianCoordinate_memLp ι j).aestronglyMeasurable + change (∫ ω,ω i*ω j ∂gaussianProduct ι)=_ at hh + rw [hh] + have hm (k : ι) : (∫ ω,ω k ∂gaussianProduct ι)=0 := by + rw [←integral_congr_ae (gaussianCoordinate_ae ι k)] + exact gaussianCoordinate_mean ι k + simp [hm] + +lemma gaussianCoordinates_orthonormal : Orthonormal ℝ (gaussianCoordinate ι) := by + classical + exact orthonormal_iff_ite.mpr (gaussianCoordinate_inner ι) + +def gaussianLpIsometry : lp (fun _ : ι => ℝ) 2 →ₗᵢ[ℝ] Lp ℝ 2 (gaussianProduct ι) := + (gaussianCoordinates_orthonormal ι).orthogonalFamily.linearIsometry + +lemma hasSum_gaussianLpIsometry (f : lp (fun _ : ι => ℝ) 2) : + HasSum (fun i => f i • gaussianCoordinate ι i) (gaussianLpIsometry ι f) := by + exact (gaussianCoordinates_orthonormal ι).orthogonalFamily.hasSum_linearIsometry f + +lemma gaussianCoordinates_sum_ae (s : Finset ι) (f : ι → ℝ) : + ((∑ i∈s,f i • gaussianCoordinate ι i : Lp ℝ 2 (gaussianProduct ι)) : (ι → ℝ) → ℝ) + =ᵐ[gaussianProduct ι] (fun ω => ∑ i∈s,f i*ω i) := by + classical + have ha : ∀ᵐ ω ∂gaussianProduct ι, ∀ i∈s, + (f i • gaussianCoordinate ι i : Lp ℝ 2 (gaussianProduct ι)) ω=f i*ω i := by + apply (ae_ball_iff s.finite_toSet.countable).mpr + intro i hi + filter_upwards [Lp.coeFn_smul (f i) (gaussianCoordinate ι i),gaussianCoordinate_ae ι i] with ω hs hc + simp [hs,hc] + filter_upwards [Lp.coeFn_finsetSum s (fun i => f i • gaussianCoordinate ι i),ha] with ω hs ha + rw [hs] + simp only [Finset.sum_apply] + exact Finset.sum_congr rfl (fun i hi => ha i hi) + +lemma gaussianCoordinates_sum_gaussian (s : Finset ι) (f : ι → ℝ) : + HasGaussianLaw ((∑ i∈s,f i • gaussianCoordinate ι i : Lp ℝ 2 (gaussianProduct ι)) : (ι → ℝ) → ℝ) + (gaussianProduct ι) := by + classical + have hind := (gaussianCoordinates_independent ι).precomp (g:=(Subtype.val : s → ι)) Subtype.val_injective + have hs := hind.comp (fun i x => f i*x) (fun _ => by fun_prop) + have hg (i : s) : HasGaussianLaw (fun ω : ι → ℝ => f i*ω i) (gaussianProduct ι) := + (gaussianCoordinate_gaussian ι i).fun_smul (f i) + have hh := hs.hasGaussianLaw_fun_sum hg + have hh' : HasGaussianLaw (fun ω : ι → ℝ => ∑ i∈s,f i*ω i) (gaussianProduct ι) := by + convert! hh using 1 + funext ω + exact (Finset.sum_coe_sort s (fun i => f i*ω i)).symm + exact hh'.congr (gaussianCoordinates_sum_ae ι s f).symm + +lemma gaussianLpIsometry_gaussian (f : lp (fun _ : ι => ℝ) 2) : + HasGaussianLaw (gaussianLpIsometry ι f) (gaussianProduct ι) := by + apply isClosed_gaussian_l2.mem_of_tendsto (hasSum_gaussianLpIsometry ι f) + exact Eventually.of_forall (fun s => gaussianCoordinates_sum_gaussian ι s f) + +lemma gaussianLpIsometry_mean (f : lp (fun _ : ι => ℝ) 2) : + (∫ ω,gaussianLpIsometry ι f ω ∂gaussianProduct ι)=0 := by + have ht := continuous_l2_mean.tendsto (gaussianLpIsometry ι f) |>.comp (hasSum_gaussianLpIsometry ι f) + have hs (s : Finset ι) : (∫ ω,(∑ i∈s,f i • gaussianCoordinate ι i : Lp ℝ 2 (gaussianProduct ι)) ω + ∂gaussianProduct ι)=0 := by + rw [integral_congr_ae (gaussianCoordinates_sum_ae ι s f)] + rw [integral_finsetSum _ (fun i hi => (gaussianCoordinate_memLp ι i).integrable (by norm_num) |>.const_mul (f i))] + apply Finset.sum_eq_zero + intro i hi + rw [integral_const_mul,←integral_congr_ae (gaussianCoordinate_ae ι i),gaussianCoordinate_mean,mul_zero] + change Tendsto (fun s : Finset ι => ∫ ω,(∑ i∈s,f i • gaussianCoordinate ι i : Lp ℝ 2 (gaussianProduct ι)) ω ∂gaussianProduct ι) atTop _ at ht + simp only [hs] at ht + exact tendsto_nhds_unique ht tendsto_const_nhds +end BrownianConstruction + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℝ H] +variable {ι : Type*} +def gaussianHilbertMap (b : HilbertBasis ι ℝ H) : H →ₗᵢ[ℝ] Lp ℝ 2 (gaussianProduct ι) := + (gaussianLpIsometry ι).comp b.repr.toLinearIsometry +lemma gaussianHilbertMap_gaussian (b : HilbertBasis ι ℝ H) (x : H) : + HasGaussianLaw (gaussianHilbertMap b x) (gaussianProduct ι) := + gaussianLpIsometry_gaussian ι (b.repr x) +lemma gaussianHilbertMap_mean (b : HilbertBasis ι ℝ H) (x : H) : + (∫ ω,gaussianHilbertMap b x ω ∂gaussianProduct ι)=0 := + gaussianLpIsometry_mean ι (b.repr x) + +lemma linear_apply_pi {J : Type*} [Fintype J] [DecidableEq J] (L : (J → ℝ) →L[ℝ] ℝ) (x : J → ℝ) : + L x=∑ i,x i*L (Pi.single i 1) := by + classical + have h : (∑ i,x i • Pi.single i (1:ℝ))=x := by + ext j + simp [Finset.sum_apply,Pi.smul_apply,Pi.single_apply,smul_eq_mul] + conv_lhs => rw [←h] + rw [map_sum] + simp + +lemma gaussianHilbertMap_sum_ae {J : Type*} [Fintype J] + (b : HilbertBasis ι ℝ H) (x : J → H) (c : J → ℝ) : + gaussianHilbertMap b (∑ i,c i • x i) =ᵐ[gaussianProduct ι] + (fun ω => ∑ i,c i*gaussianHilbertMap b (x i) ω) := by + classical + rw [map_sum] + simp only [map_smul] + have he : ∀ᵐ ω ∂gaussianProduct ι,∀ i, + (c i • gaussianHilbertMap b (x i) : Lp ℝ 2 (gaussianProduct ι)) ω = + c i*gaussianHilbertMap b (x i) ω := + ae_all_iff.mpr (fun i => Lp.coeFn_smul (c i) (gaussianHilbertMap b (x i))) + filter_upwards [Lp.coeFn_finsetSum Finset.univ (fun i => c i • gaussianHilbertMap b (x i)),he] with ω hs he + rw [hs] + simp only [Finset.sum_apply] + exact Finset.sum_congr rfl (fun i _ => he i) + +lemma gaussianHilbertMap_joint_gaussian {J : Type*} [Fintype J] + (b : HilbertBasis ι ℝ H) (x : J → H) : + HasGaussianLaw (fun ω i => gaussianHilbertMap b (x i) ω) (gaussianProduct ι) := by + classical + have hm : AEMeasurable (fun ω i => gaussianHilbertMap b (x i) ω) (gaussianProduct ι) := + AEMeasurable.of_eval (fun i => (Lp.aestronglyMeasurable _).aemeasurable) + refine ⟨hm, isGaussian_of_isGaussian_map (fun L => ?_)⟩ + rw [AEMeasurable.map_map_of_aemeasurable L.measurable.aemeasurable hm] + have ha : gaussianHilbertMap b (∑ i,L (Pi.single i 1) • x i) =ᵐ[gaussianProduct ι] + L ∘ (fun ω i => gaussianHilbertMap b (x i) ω) := by + filter_upwards [gaussianHilbertMap_sum_ae b x (fun i => L (Pi.single i 1))] with ω hω + rw [hω] + change (∑ i,L (Pi.single i 1)*gaussianHilbertMap b (x i) ω) = L (fun i => gaussianHilbertMap b (x i) ω) + rw [linear_apply_pi L] + exact Finset.sum_congr rfl (fun i _ => mul_comm _ _) + exact ((gaussianHilbertMap_gaussian b _).congr ha).isGaussian_map + +lemma gaussianHilbertMap_covariance (b : HilbertBasis ι ℝ H) (x y : H) : + cov[gaussianHilbertMap b x,gaussianHilbertMap b y;gaussianProduct ι]=inner ℝ x y := by + rw [covariance_eq_sub (Lp.memLp _) (Lp.memLp _),gaussianHilbertMap_mean,gaussianHilbertMap_mean] + simp only [zero_mul,sub_zero] + rw [←(gaussianHilbertMap b).inner_map_map,L2.inner_def] + apply integral_congr_ae + filter_upwards [] with ω + simp [mul_comm] +end BrownianConstruction + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction + +def initialIndicator (t : ℝ≥0) : Lp ℝ 2 (volume : Measure ℝ) := + indicatorConstLp 2 (s:=Icc (0:ℝ) (t:ℝ)) measurableSet_Icc isCompact_Icc.measure_ne_top (1:ℝ) + +lemma initialIndicator_inner (s t : ℝ≥0) : + inner ℝ (initialIndicator s) (initialIndicator t)=(min s t : ℝ≥0) := by + rw [initialIndicator,initialIndicator,L2.real_inner_indicatorConstLp_one_indicatorConstLp_one + measurableSet_Icc measurableSet_Icc isCompact_Icc.measure_ne_top isCompact_Icc.measure_ne_top] + simp [Icc_inter_Icc,Real.volume_real_Icc_of_le (show 0 ≤ min (s:ℝ) t by positivity)] + +variable {ι : Type*} (b : HilbertBasis ι ℝ (Lp ℝ 2 (volume : Measure ℝ))) +def preBrownian (t : ℝ≥0) : (ι → ℝ) → ℝ := gaussianHilbertMap b (initialIndicator t) + +lemma preBrownian_gaussian : IsGaussianProcess (preBrownian b) (gaussianProduct ι) where + hasGaussianLaw I := gaussianHilbertMap_joint_gaussian b (fun i : I => initialIndicator i) +lemma preBrownian_mean (t : ℝ≥0) : (∫ ω,preBrownian b t ω ∂gaussianProduct ι)=0 := + gaussianHilbertMap_mean b (initialIndicator t) +lemma preBrownian_covariance (s t : ℝ≥0) : + cov[preBrownian b s,preBrownian b t;gaussianProduct ι]=(min s t : ℝ≥0) := by + rw [preBrownian,preBrownian,gaussianHilbertMap_covariance,initialIndicator_inner] +lemma preBrownian_isPreBrownian : IsPreBrownianReal (preBrownian b) (gaussianProduct ι) := + (preBrownian_gaussian b).isPreBrownianReal_of_covariance (preBrownian_mean b) + (fun s t hst => by rw [preBrownian_covariance,min_eq_left hst]) +end BrownianConstruction + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction + +def gaussianFourth : ℝ := ∫ z : ℝ,|z|^4 ∂gaussianReal 0 1 +lemma gaussianFourth_nonneg : 0≤gaussianFourth := integral_nonneg (fun _ => by positivity) +lemma gaussian_abs_fourth_integrable (v : ℝ≥0) : Integrable (fun z : ℝ => |z|^4) (gaussianReal 0 v) := by + simpa only [Real.norm_eq_abs,id_eq] using + (memLp_id_gaussianReal' (μ:=0) (v:=v) 4 (by norm_num)).integrable_norm_pow (by norm_num : (4:ℕ)≠0) +lemma gaussian_abs_fourth (v : ℝ≥0) : + (∫ z : ℝ,|z|^4 ∂gaussianReal 0 v)=gaussianFourth*(v:ℝ)^2 := by + have hm : (gaussianReal 0 1).map (fun z : ℝ => Real.sqrt v*z)=gaussianReal 0 v := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext + change (Real.sqrt v)^2 * 1 = (v:ℝ) + rw [Real.sq_sqrt v.coe_nonneg,mul_one] + rw [←hm,integral_map (by fun_prop) (by fun_prop)] + simp only [abs_mul,mul_pow,abs_of_nonneg (Real.sqrt_nonneg _),integral_const_mul] + have hv : (Real.sqrt v)^4=(v:ℝ)^2 := by rw [show (Real.sqrt v)^4=((Real.sqrt v)^2)^2 by ring,Real.sq_sqrt v.coe_nonneg] + rw [hv,mul_comm] + rfl + +lemma fourth_tail_bound {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] + {X : Ω → ℝ} {v : ℝ≥0} (hX : HasLaw X (gaussianReal 0 v) P) {ε : ℝ} (hε : 0<ε) : + P {ω | ε < |X ω|}≤ENNReal.ofReal (gaussianFourth*(v:ℝ)^2/ε^4) := by + have hi : Integrable (fun ω => |X ω|^4) P := by + simpa only [Real.norm_eq_abs] using + (hX.hasGaussianLaw.memLp (p:=4) (by norm_num)).integrable_norm_pow (by norm_num : (4:ℕ)≠0) + have he : (∫ ω,|X ω|^4 ∂P)=gaussianFourth*(v:ℝ)^2 := by + rw [←gaussian_abs_fourth] + exact hX.integral_comp (f:=fun z : ℝ => |z|^4) (by fun_prop) + have hmark := mul_meas_ge_le_integral_of_nonneg (Filter.Eventually.of_forall (fun ω => + show 0≤|X ω|^4 by positivity)) hi (ε^4) + rw [he] at hmark + have hsub : {ω | ε < |X ω|}⊆{ω | ε^4 ≤ |X ω|^4} := by + intro ω hω + exact pow_le_pow_left₀ hε.le hω.le 4 + have hr : P.real {ω | ε < |X ω|}≤gaussianFourth*(v:ℝ)^2/ε^4 := by + apply (le_div_iff₀ (by positivity)).mpr + have hm := measureReal_mono (μ:=P) hsub + nlinarith [pow_pos hε 4] + simpa only [measureReal_def,ENNReal.ofReal_toReal (measure_ne_top _ _)] using ENNReal.ofReal_le_ofReal hr +end BrownianConstruction + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction + +def dyadicPoint (n k : ℕ) : ℝ≥0 := (k:ℝ≥0)/(2:ℝ≥0)^n +def dyadicIndex (n : ℕ) (t : ℝ≥0) : ℕ := ⌊(2:ℝ≥0)^n*t⌋₊ +def dyadicRound (n : ℕ) (t : ℝ≥0) : ℝ≥0 := dyadicPoint n (dyadicIndex n t) + +lemma dyadicPoint_mono (n : ℕ) : Monotone (dyadicPoint n) := by + intro j k hjk + exact div_le_div_of_nonneg_right (by exact_mod_cast hjk) (by positivity) +lemma dyadicPoint_succ (n k : ℕ) : + (dyadicPoint n (k+1):ℝ)-(dyadicPoint n k:ℝ)=(1/2:ℝ)^n := by + simp only [dyadicPoint,NNReal.coe_div,NNReal.coe_pow,NNReal.coe_natCast,NNReal.coe_ofNat] + push_cast + rw [one_div_pow] + ring +lemma dyadicRound_le (n : ℕ) (t : ℝ≥0) : dyadicRound n t≤t := by + rw [dyadicRound,dyadicPoint,div_le_iff₀ (by positivity)] + simpa only [dyadicIndex,mul_comm] using Nat.floor_le (show 0≤(2:ℝ≥0)^n*t from bot_le) +lemma lt_dyadicRound_add (n : ℕ) (t : ℝ≥0) : + t X (dyadicRound n t)) := by + obtain ⟨N,hN⟩ := exists_nat_gt t + obtain ⟨n₀,hn₀⟩ := hg N + apply (cauchySeq_shift n₀).mp + apply cauchySeq_of_le_geometric r (r^(n₀+1)) hr1 + intro n + have hh := round_step_bound (hn₀ (n+n₀+1) (by omega)) hr hN + rw [dist_comm] + convert hh using 1 <;> simp only [Nat.add_assoc,pow_add] <;> ring_nf + +def dyadicLimit (X : ℝ≥0 → ℝ) (t : ℝ≥0) : ℝ := limUnder atTop (fun n => X (dyadicRound n t)) +lemma tendsto_dyadicLimit {r : ℝ} (hr : 0≤r) (hr1 : r<1) + {X : ℝ≥0 → ℝ} (hg : DyadicGood r X) (t : ℝ≥0) : + Tendsto (fun n => X (dyadicRound n t)) atTop (𝓝 (dyadicLimit X t)) := + (dyadicRound_cauchy hr hr1 hg t).tendsto_limUnder + +lemma dyadicLimit_error {r : ℝ} (hr : 0≤r) (hr1 : r<1) + {X : ℝ≥0 → ℝ} (hg : DyadicGood r X) {N n : ℕ} + (hn : ∀ m≥n, ∀ k by simpa only [comp_apply,dist_comm] using hs m) hlim +end BrownianConstruction + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] +variable {X : ℝ≥0 → Ω → ℝ} + +lemma dyadic_increment_tail (hX : IsPreBrownianReal X P) (n k : ℕ) {ε : ℝ} (hε : 0<ε) : + P {ω | ε < dist (X (dyadicPoint n (k+1)) ω) (X (dyadicPoint n k) ω)} ≤ + ENNReal.ofReal (gaussianFourth*((1/2:ℝ)^n)^2/ε^4) := by + have hv : nndist (dyadicPoint n (k+1)).1 (dyadicPoint n k).1=(1/2:ℝ≥0)^n := by + apply NNReal.coe_injective + rw [coe_nndist,Real.dist_eq,abs_of_nonneg] + · exact dyadicPoint_succ n k + · exact sub_nonneg.mpr (NNReal.coe_le_coe.mpr (dyadicPoint_mono n (Nat.le_succ k))) + have hl := hX.hasLaw_sub (dyadicPoint n (k+1)) (dyadicPoint n k) + rw [hv] at hl + simpa only [Pi.sub_apply,Real.dist_eq,NNReal.coe_pow,NNReal.coe_div,NNReal.coe_one, + NNReal.coe_ofNat] using fourth_tail_bound hl hε + +def dyadicBad (X : ℝ≥0 → Ω → ℝ) (N n : ℕ) : Set Ω := + {ω | ∃ k dyadic_increment_tail hX n k (by positivity)) + _ = ENNReal.ofReal (gaussianFourth*N) * ENNReal.ofReal (5000/6561:ℝ)^n := by + simp only [Finset.sum_const,Finset.card_range,nsmul_eq_mul] + rw [←ENNReal.ofReal_pow (by norm_num),←ENNReal.ofReal_mul (mul_nonneg gaussianFourth_nonneg (Nat.cast_nonneg N)), + ←ENNReal.ofReal_natCast (N*2^n),←ENNReal.ofReal_mul (by positivity)] + congr 1 + push_cast + rw [←pow_mul,←pow_mul,show n*2=2*n from Nat.mul_comm _ _, + show n*4=4*n from Nat.mul_comm _ _,pow_mul,pow_mul] + have halg (a b c d e : ℝ) : d*a^n*(c*b^n/e^n)=c*d*(a*(b/e))^n := by + rw [mul_pow,div_pow] + ring + convert halg 2 ((1/2:ℝ)^2) gaussianFourth N ((9/10:ℝ)^4) using 1; norm_num + +lemma ae_dyadicGood (hX : IsPreBrownianReal X P) : + ∀ᵐ ω ∂P, DyadicGood (9/10:ℝ) (fun t => X t ω) := by + have hN (N : ℕ) : ∀ᵐ ω ∂P, ∃ n₀ : ℕ, ∀ n≥n₀, ω∉dyadicBad X N n := by + apply (ae_eventually_notMem (s:=dyadicBad X N) ?_).mono + · intro ω hω + exact eventually_atTop.mp hω + · apply ne_top_of_le_ne_top _ (ENNReal.tsum_le_tsum (dyadicBad_measure hX N)) + rw [ENNReal.tsum_mul_left] + exact ENNReal.mul_ne_top ENNReal.ofReal_ne_top + (tsum_geometric_lt_top.mpr (by norm_num)).ne + filter_upwards [ae_all_iff.mpr hN] with ω hω + intro N + obtain ⟨n₀,hn₀⟩ := hω N + refine ⟨n₀,fun n hn k hk => ?_⟩ + exact le_of_not_gt (fun h => hn₀ n hn ⟨k,hk,h⟩) +end BrownianConstruction + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction + +lemma dyadicIndex_neighbors (n : ℕ) {s t : ℝ≥0} + (hst : dist s t<(1/2:ℝ)^n) : + dyadicIndex n s≤dyadicIndex n t+1 ∧ dyadicIndex n t≤dyadicIndex n s+1 := by + have one {s t : ℝ≥0} (h : dist s t<(1/2:ℝ)^n) : dyadicIndex n s≤dyadicIndex n t+1 := by + have ht := lt_dyadicRound_add n t + have hs : (s:ℝ)<(dyadicRound n t:ℝ)+2*(1/2:ℝ)^n := by + have hh : |(s:ℝ)-t|<(1/2:ℝ)^n := h + have ht' : (t:ℝ)<(dyadicRound n t:ℝ)+(1/2:ℝ)^n := by exact_mod_cast ht + linarith [(abs_lt.mp hh).2] + have hh : (2:ℝ≥0)^n*s < (dyadicIndex n t:ℝ≥0)+2 := by + apply NNReal.coe_lt_coe.mp + change (2:ℝ)^n*(s:ℝ)<(dyadicIndex n t:ℝ)+2 + have hp : (0:ℝ)<2^n := by positivity + have hh := mul_lt_mul_of_pos_left hs hp + have he : (2:ℝ)^n*((dyadicRound n t:ℝ)+2*(1/2:ℝ)^n)=(dyadicIndex n t:ℝ)+2 := by + simp only [dyadicRound,dyadicPoint,NNReal.coe_div,NNReal.coe_natCast,NNReal.coe_pow, + NNReal.coe_ofNat,one_div_pow] + field_simp + rwa [he] at hh + have hi : dyadicIndex n s (2/(1-r)+1)*r^n) atTop (𝓝 0) := by + simpa using (tendsto_pow_atTop_nhds_zero_of_lt_one hr hr1).const_mul (2/(1-r)+1) + obtain ⟨n,hn,he⟩ := ((eventually_ge_atTop n₀).and (hseq.eventually (gt_mem_nhds hε))).exists + refine ⟨min 1 ((1/2:ℝ)^n),lt_min (by norm_num) (by positivity),?_⟩ + intro s hs + have htN : t<(N:ℝ≥0) := by exact_mod_cast (by linarith : (t:ℝ) hn₀ m (hn.trans hm) + have h1 := dyadicLimit_error hr hr1 hg htail hsN + have h2 := dyadicLimit_error hr hr1 hg htail htN + have h3 := nearby_round_bound hr (hn₀ n hn) hsN htN (hs.trans_le (min_le_right _ _)) + have htriangle := dist_triangle4 (dyadicLimit X s) (X (dyadicRound n s)) + (X (dyadicRound n t)) (dyadicLimit X t) + rw [dist_comm (dyadicLimit X s) (X (dyadicRound n s))] at htriangle + calc + dist (dyadicLimit X s) (dyadicLimit X t) ≤ r^n/(1-r)+r^n+r^n/(1-r) := by linarith + _ = (2/(1-r)+1)*r^n := by ring + _ < ε := he +end BrownianConstruction + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/MovingTensorInsertionLimit.lean b/lean/OAI/Probability/ParisiFinite/MovingTensorInsertionLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..019243f6a58c67df0b6349dd6f009d619c5a45a4 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/MovingTensorInsertionLimit.lean @@ -0,0 +1,649 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SecondCoefficient + +namespace OAI + +/-! Moving Tensor Insertion Limit. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +namespace FiniteTensor +open scoped InnerProductSpace Topology +open Filter QuantumCLT ContinuousLinearMap + + + +theorem moving_tensor_insertion_limit + {κ : Type*} (ι : ℕ → Type*) + [∀n, Fintype (ι n)] [∀n, DecidableEq (ι n)] [∀n, Nonempty (ι n)] + (Ω : ∀n, EuclideanSpace ℂ (ι n)) (l : List κ) + (X : ∀n, κ → EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + (S : ∀n, EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + (L K : ℝ) (hL : 0 ≤ L) (hK : 0 ≤ K) + (hΩ : ∀n, ‖Ω n‖=1) (hX : ∀n i, i ∈ l → ‖X n i‖ ≤ L) (hS : ∀n, ‖S n‖ ≤ K) + (hc : ∀n, ⟪Ω n,(l.map (X n)).sum (Ω n)⟫_ℂ=0) + (hSc : ∀n, ⟪Ω n,S n (Ω n)⟫_ℂ=0) {z v : ℂ} + (hz : Tendsto (fun n => ⟪Ω n,(second (l.map (X n))) (Ω n)⟫_ℂ) atTop (𝓝 z)) + (hv : Tendsto (fun n => ⟪Ω n,S n ((l.map (X n)).sum (Ω n))⟫_ℂ) atTop (𝓝 v)) : + Tendsto (fun n => + ⟪power n (Ω n),normalizedInsertion n + (generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹) + (S n*generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹) (power n (Ω n))⟫_ℂ) + atTop (𝓝 (v*Complex.exp z)) := by + have hp (n : ℕ) : ‖vacuumFunctional (Ω n)‖ ≤ 1 := by + simpa [hΩ n] using vacuumFunctional_norm (Ω n) + have hq (n : ℕ) : ‖markedFunctional (Ω n) (S n)‖ ≤ K := by + exact (markedFunctional_norm (Ω n) (S n)).trans (by simpa [hΩ n] using hS n) + have h1 (n : ℕ) : vacuumFunctional (Ω n) 1=1 := by + change ⟪Ω n,Ω n⟫_ℂ=1 + rw [inner_self_eq_norm_sq_to_K,hΩ n] + norm_num + have hs1 (n : ℕ) : markedFunctional (Ω n) (S n) 1=0 := by + simpa using hSc n + have hh := moving_generators_inserted_limit + (fun n => EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + l X (fun n => vacuumFunctional (Ω n)) (fun n => markedFunctional (Ω n) (S n)) + L 1 K hL (by norm_num) hK hX hp hq h1 hs1 hc hz hv + simpa only [inner_normalizedInsertion,vacuumFunctional_apply,markedFunctional_apply, + mul_apply_eq_comp] using hh + +end FiniteTensor + +namespace CoherentFock +open scoped InnerProductSpace +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +def exponential (d : E) : Space E := + Complex.exp (Complex.ofReal (‖d‖^2/2)) • coherent d + +@[simp] theorem inner_exponential (d e : E) : + ⟪exponential d,exponential e⟫_ℂ=Complex.exp ⟪d,e⟫_ℂ := by + simp only [exponential,inner_smul_left,inner_smul_right,inner_coherent,kernel, + ←Complex.exp_conj,Complex.conj_ofReal] + rw [←Complex.exp_add,←Complex.exp_add] + congr 1 + push_cast + ring + +theorem W_exponential (d x : E) : + W d (exponential x)= + Complex.exp (-Complex.ofReal (‖d‖^2/2)-⟪d,x⟫_ℂ) • exponential (d+x) := by + simp only [exponential,map_smul,W_coherent,smul_smul,phase,←Complex.exp_add] + congr 2 + rw [norm_add_sq (𝕜 := ℂ)] + apply Complex.ext <;> simp <;> ring + +end CoherentFock + +namespace QuantumCLT +open scoped InnerProductSpace Topology +open CoherentFock Filter +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + + +theorem weylProduct_exponential (ds : List E) (x : E) : + weylProduct ds (exponential x)= + Complex.exp (secondCoefficient (fun d e : E => -⟪d,e⟫_ℂ) ds-⟪ds.sum,x⟫_ℂ) • + exponential (ds.sum+x) := by + induction ds with + | nil => simp [weylProduct,secondCoefficient] + | cons d ds ih => + simp only [weylProduct,ContinuousLinearMap.comp_apply,ih,map_smul,W_exponential, + smul_smul,←Complex.exp_add,List.sum_cons,secondCoefficient_gram_cons, + inner_add_left,inner_add_right] + rw [inner_self_eq_norm_sq_to_K] + have h : secondCoefficient (fun d e : E => -⟪d,e⟫_ℂ) ds-⟪ds.sum,x⟫_ℂ+ + (-Complex.ofReal (‖d‖^2/2)-(⟪d,ds.sum⟫_ℂ+⟪d,x⟫_ℂ))= + (2:ℂ)⁻¹*(-Complex.ofReal (‖d‖^2))+secondCoefficient (fun d e : E => -⟪d,e⟫_ℂ) ds- + ⟪d,ds.sum⟫_ℂ-(⟪d,x⟫_ℂ+⟪ds.sum,x⟫_ℂ) := by push_cast; ring + rw [h,add_assoc] + simp only [Complex.ofReal_pow] + rfl + + + +theorem weylProduct_exponential_pairing (ds : List E) (x z : E) : + ⟪exponential z,weylProduct ds (exponential x)⟫_ℂ= + Complex.exp (secondCoefficient (fun d e : E => -⟪d,e⟫_ℂ) ds+ + ⟪z,ds.sum⟫_ℂ+⟪z,x⟫_ℂ-⟪ds.sum,x⟫_ℂ) := by + rw [weylProduct_exponential,inner_smul_right,inner_exponential,←Complex.exp_add, + inner_add_right] + congr 1 + ring + +end QuantumCLT + +namespace FiniteTensor +open scoped InnerProductSpace Topology +open QuantumCLT CoherentFock Filter ContinuousLinearMap +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + + +theorem moving_tensor_weyl_limit + {κ : Type*} (ι : ℕ → Type*) + [∀n, Fintype (ι n)] [∀n, DecidableEq (ι n)] [∀n, Nonempty (ι n)] + (Ω xn zn : ∀n, EuclideanSpace ℂ (ι n)) (l : List κ) + (X : ∀n, κ → EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + (d : κ → E) (x z : E) (L R : ℝ) (hL : 0 ≤ L) (hR : 0 ≤ R) + (hΩ : ∀n, ‖Ω n‖=1) (hX : ∀n i, i ∈ l → ‖X n i‖ ≤ L) + (hx : ∀n, ‖xn n‖ ≤ R) (hz : ∀n, ‖zn n‖ ≤ R) + (hxc : ∀n, ⟪Ω n,xn n⟫_ℂ=0) (hzc : ∀n, ⟪zn n,Ω n⟫_ℂ=0) + (hc : ∀n, ⟪Ω n,(l.map (X n)).sum (Ω n)⟫_ℂ=0) + (hqq : ∀i ∈ l, ∀j ∈ l, + Tendsto (fun n => ⟪Ω n,X n i (X n j (Ω n))⟫_ℂ) atTop (𝓝 (-⟪d i,d j⟫_ℂ))) + (hza : Tendsto (fun n => ⟪zn n,(l.map (X n)).sum (Ω n)⟫_ℂ) + atTop (𝓝 ⟪z,(l.map d).sum⟫_ℂ)) + (hzx : Tendsto (fun n => ⟪zn n,xn n⟫_ℂ) atTop (𝓝 ⟪z,x⟫_ℂ)) + (hax : Tendsto (fun n => ⟪Ω n,(l.map (X n)).sum (xn n)⟫_ℂ) + atTop (𝓝 (-⟪(l.map d).sum,x⟫_ℂ))) : + Tendsto (fun n => + ⟪exponentialVector n (Ω n) (zn n), + operatorPower n (generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹) + (exponentialVector n (Ω n) (xn n))⟫_ℂ) + atTop (𝓝 ⟪exponential z,weylProduct (l.map d) (exponential x)⟫_ℂ) := by + have hj (n : ℕ) : JetBound (orderedBound L l.length) (generators (l.map (X n))) + (l.map (X n)).sum (second (l.map (X n))) := by + let : CompleteSpace (EuclideanSpace ℂ (ι n)) := + PiLp.completeSpace 2 (fun _ : ι n => ℂ) + let : CompleteSpace (EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) := + ContinuousLinearMap.instCompleteSpace + simpa only [List.length_map] using generators_jetBound (l.map (X n)) hL (by + intro Y hY + obtain ⟨i,hi,rfl⟩ := List.mem_map.mp hY + exact hX n i hi) + have hb : Tendsto (fun n => ⟪Ω n,(second (l.map (X n))) (Ω n)⟫_ℂ) + atTop (𝓝 (secondCoefficient (fun i j => -⟪d i,d j⟫_ℂ) l)) := by + change Tendsto (fun n => vacuumFunctional (Ω n) (second (l.map (X n)))) _ _ + simp_rw [second_matrixElement] + apply secondCoefficient_tendsto + intro i hi j hj + simpa only [vacuumFunctional_apply,mul_apply_eq_comp] using hqq i hi j hj + rw [weylProduct_exponential_pairing,secondCoefficient_map] + have ht := ((hb.add hza).add hzx).add hax + simpa only [sub_eq_add_neg] using moving_tensor_pairing_limit ι Ω xn zn + (fun n => generators (l.map (X n))) (fun n => (l.map (X n)).sum) + (fun n => second (l.map (X n))) R (orderedBound L l.length) + hR (orderedBound_nonneg hL _) hΩ hx hz hj hxc hzc hc ht + +end FiniteTensor + +namespace CoherentFock +open scoped InnerProductSpace Topology +open Filter +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + + +theorem tendsto_inner_of_coherent_tests {α : Type*} {l : Filter α} + (v : α → Space E) (v₀ : Space E) (C : ℝ) (hC : 0 ≤ C) + (hb : ∀ᶠ a in l, ‖v a‖ ≤ C) + (ht : ∀e : E, Tendsto (fun a => ⟪coherent e,v a⟫_ℂ) l (𝓝 ⟪coherent e,v₀⟫_ℂ)) + (y : Space E) : Tendsto (fun a => ⟪y,v a⟫_ℂ) l (𝓝 ⟪y,v₀⟫_ℂ) := by + classical + have hpre (x : PreSpace E) : + Tendsto (fun a => ⟪(↑x : Space E),v a⟫_ℂ) l (𝓝 ⟪(↑x : Space E),v₀⟫_ℂ) := by + simp_rw [coe_eq_sum,Finsupp.sum,sum_inner,inner_smul_left] + exact tendsto_finsetSum _ (fun e _ => tendsto_const_nhds.mul (ht e)) + rw [Metric.tendsto_nhds] + intro ε hε + obtain ⟨x,hx⟩ := Metric.denseRange_iff.mp + (UniformSpace.Completion.denseRange_coe (α := PreSpace E)) y + (ε / (2*(C+‖v₀‖+1))) (by positivity) + rw [dist_eq_norm,lt_div_iff₀ (by positivity)] at hx + have ha := Metric.tendsto_nhds.mp (hpre x) (ε/2) (half_pos hε) + filter_upwards [ha,hb] with a ha hb + rw [dist_eq_norm] at ha ⊢ + have heq : ⟪y,v a⟫_ℂ-⟪y,v₀⟫_ℂ = + ⟪y-(↑x : Space E),v a⟫_ℂ + (⟪(↑x : Space E),v a⟫_ℂ-⟪(↑x : Space E),v₀⟫_ℂ) - + ⟪y-(↑x : Space E),v₀⟫_ℂ := by simp only [inner_sub_left]; ring + rw [heq] + have h1 := norm_inner_le_norm (𝕜 := ℂ) (y-(↑x : Space E)) (v a) + have h2 := norm_inner_le_norm (𝕜 := ℂ) (y-(↑x : Space E)) v₀ + have hsum := (norm_sub_le + (⟪y-(↑x : Space E),v a⟫_ℂ + (⟪(↑x : Space E),v a⟫_ℂ-⟪(↑x : Space E),v₀⟫_ℂ)) + ⟪y-(↑x : Space E),v₀⟫_ℂ).trans + (add_le_add (norm_add_le _ _) le_rfl) + have hb' := mul_le_mul_of_nonneg_left hb (norm_nonneg (y-(↑x : Space E))) + nlinarith [norm_nonneg (y-(↑x : Space E))] + + + +theorem tendsto_of_coherent_tests_and_norm {α : Type*} {l : Filter α} + (v : α → Space E) (v₀ : Space E) + (hn : Tendsto (fun a => ‖v a‖) l (𝓝 ‖v₀‖)) + (ht : ∀e : E, Tendsto (fun a => ⟪coherent e,v a⟫_ℂ) l (𝓝 ⟪coherent e,v₀⟫_ℂ)) : + Tendsto v l (𝓝 v₀) := by + have hb : ∀ᶠ a in l, ‖v a‖ ≤ ‖v₀‖+1 := + (hn.eventually_lt_const (by linarith : ‖v₀‖ < ‖v₀‖+1)).mono (fun _ h => h.le) + have hi := tendsto_inner_of_coherent_tests v v₀ (‖v₀‖+1) (by positivity) hb ht v₀ + have hr : Tendsto (fun a => (⟪v₀,v a⟫_ℂ).re) l (𝓝 (‖v₀‖^2)) := by + have hk : (⟪v₀,v₀⟫_ℂ).re=‖v₀‖^2 := (norm_sq_eq_re_inner (𝕜 := ℂ) v₀).symm + rw [← hk] + exact (Complex.continuous_re.tendsto _).comp hi + have hs : Tendsto (fun a => ‖v₀-v a‖^2) l (𝓝 0) := by + simp_rw [norm_sub_sq (𝕜 := ℂ)] + have hh := ((tendsto_const_nhds (x := ‖v₀‖^2)).sub (hr.const_mul 2)).add (hn.pow 2) + have he0 : ‖v₀‖^2-2*‖v₀‖^2+‖v₀‖^2=(0:ℝ) := by ring + rw [he0] at hh + exact hh + have hnorm : Tendsto (fun a => ‖v a-v₀‖) l (𝓝 0) := by + have h := (Real.continuous_sqrt.tendsto 0).comp hs + simpa only [Function.comp_def,Real.sqrt_zero,Real.sqrt_sq_eq_abs,abs_norm,norm_sub_rev] using h + exact tendsto_iff_norm_sub_tendsto_zero.mpr hnorm + + + +theorem tendsto_unitary_inverse {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + {α : Type*} {l : Filter α} (U : α → H ≃ₗᵢ[ℂ] H) (U₀ : H ≃ₗᵢ[ℂ] H) + (h : ∀x : H, Tendsto (fun a => U a x) l (𝓝 (U₀ x))) (x : H) : + Tendsto (fun a => (U a).symm x) l (𝓝 (U₀.symm x)) := by + rw [tendsto_iff_norm_sub_tendsto_zero] + have ht : Tendsto (fun a => ‖x-U a (U₀.symm x)‖) l (𝓝 0) := by + simpa only [LinearIsometryEquiv.apply_symm_apply,sub_self,norm_zero] using + ((tendsto_const_nhds (x := x)).sub (h (U₀.symm x))).norm + convert! ht using 1 + funext a + rw [←(U a).norm_map, map_sub,LinearIsometryEquiv.apply_symm_apply] + +end CoherentFock + +namespace FourierDensity +open MeasureTheory Complex +open scoped InnerProductSpace Topology +variable {κ : Type*} [Fintype κ] (μ : Measure (κ → ℝ)) [IsFiniteMeasure μ] + + +theorem character_memLp (a : κ → ℝ) : MemLp (character a) 2 μ := + MemLp.of_bound (continuous_character a).aestronglyMeasurable 1 + (Filter.Eventually.of_forall fun g => (norm_character a g).le) + +def characterVector (a : κ → ℝ) : Lp ℂ 2 μ := (character_memLp μ a).toLp (character a) + +theorem characterVector_ae (a : κ → ℝ) : + (characterVector μ a : (κ → ℝ) → ℂ)=ᵐ[μ] character a := + (character_memLp μ a).coeFn_toLp + + + +theorem character_span_dense : + (Submodule.span ℂ (Set.range (characterVector μ))).topologicalClosure=⊤ := by + let K := Submodule.span ℂ (Set.range (characterVector μ)) + have hbot : Kᗮ=⊥ := by + apply (Submodule.eq_bot_iff _).mpr + intro f hf + apply Lp.ext + have hi : Integrable (fun g => f g) μ := + memLp_one_iff_integrable.mp ((Lp.memLp f).mono_exponent (by norm_num)) + have hF : ∀a, (∫g, character a g*f g ∂μ)=0 := by + intro a + have hh := (Submodule.mem_orthogonal K f).mp hf (characterVector μ (-a)) + (Submodule.subset_span (Set.mem_range_self _)) + rw [L2.inner_def] at hh + convert hh using 1 + apply integral_congr_ae + filter_upwards [characterVector_ae μ (-a)] with g hg + rw [RCLike.inner_apply',hg,character_neg,Complex.conj_conj] + exact (ae_zero_of_fourier_zero hi hF).trans (Lp.coeFn_zero ℂ 2 μ).symm + change K.topologicalClosure=⊤ + rw [←Submodule.orthogonal_orthogonal_eq_closure K,hbot,Submodule.bot_orthogonal_eq_top] + + + +theorem exists_character_approx (f : Lp ℂ 2 μ) {ε : ℝ} (hε : 0<ε) : + ∃c : (κ → ℝ) →₀ ℂ, ‖c.sum (fun a z => z • characterVector μ a)-f‖<ε := by + have hd : Dense ((Submodule.span ℂ (Set.range (characterVector μ))) : Set (Lp ℂ 2 μ)) := by + rw [dense_iff_closure_eq] + have hh := congrArg (fun S : Submodule ℂ (Lp ℂ 2 μ) => (S : Set (Lp ℂ 2 μ))) + (character_span_dense μ) + simpa only [Submodule.topologicalClosure_coe,Submodule.top_coe] using hh + obtain ⟨x,he,hx⟩ := Metric.dense_iff.mp hd f ε hε + obtain ⟨c,rfl⟩ := Finsupp.mem_span_range_iff_exists_finsupp.mp hx + exact ⟨c,by simpa only [Metric.mem_ball,dist_eq_norm] using he⟩ + +end FourierDensity + +namespace FourierDensity +open MeasureTheory Complex +open scoped InnerProductSpace Topology +variable {κ : Type*} [Fintype κ] (μ : Measure (κ → ℝ)) [IsFiniteMeasure μ] + + +def realPart : Lp ℂ 2 μ →L[ℝ] Lp ℝ 2 μ := Complex.reCLM.compLpL 2 μ + +omit [Fintype κ] [IsFiniteMeasure μ] in +theorem realPart_ae (f : Lp ℂ 2 μ) : + (realPart μ f : (κ → ℝ) → ℝ)=ᵐ[μ] fun g => (f g).re := + Complex.reCLM.coeFn_compLpL f + +omit [Fintype κ] [IsFiniteMeasure μ] in +theorem realPart_norm (f : Lp ℂ 2 μ) : ‖realPart μ f‖ ≤ ‖f‖ := by + change ‖Complex.reCLM.compLp f‖ ≤ ‖f‖ + simpa only [Complex.reCLM_norm,one_mul] using Complex.reCLM.norm_compLp_le f + + +def oddPart (hμ : MeasurePreserving (fun g : κ → ℝ => -g) μ μ) : + Lp ℝ 2 μ →L[ℝ] Lp ℝ 2 μ := + (1/2:ℝ) • (ContinuousLinearMap.id ℝ (Lp ℝ 2 μ)- + (Lp.compMeasurePreservingₗᵢ ℝ (fun g : κ → ℝ => -g) hμ).toContinuousLinearMap) + +omit [Fintype κ] [IsFiniteMeasure μ] in +theorem oddPart_ae (hμ : MeasurePreserving (fun g : κ → ℝ => -g) μ μ) + (f : Lp ℝ 2 μ) : + (oddPart μ hμ f : (κ → ℝ) → ℝ)=ᵐ[μ] fun g => (f g-f (-g))/2 := by + change (((1/2:ℝ) • (f-Lp.compMeasurePreserving (fun g : κ → ℝ => -g) hμ f) : + Lp ℝ 2 μ) : (κ → ℝ) → ℝ)=ᵐ[μ] _ + filter_upwards [Lp.coeFn_smul (1/2:ℝ) + (f-Lp.compMeasurePreserving (fun g : κ → ℝ => -g) hμ f), + Lp.coeFn_sub f (Lp.compMeasurePreserving (fun g : κ → ℝ => -g) hμ f), + Lp.coeFn_compMeasurePreserving f hμ] with g h1 h2 h3 + rw [h1] + simp only [Pi.smul_apply,smul_eq_mul] + rw [h2] + simp only [Pi.sub_apply] + rw [h3] + simp only [Function.comp_def] + ring + +omit [Fintype κ] [IsFiniteMeasure μ] in +theorem oddPart_norm (hμ : MeasurePreserving (fun g : κ → ℝ => -g) μ μ) + (f : Lp ℝ 2 μ) : ‖oddPart μ hμ f‖ ≤ ‖f‖ := by + change ‖(1/2:ℝ) • (f-Lp.compMeasurePreserving (fun g : κ → ℝ => -g) hμ f)‖ ≤ ‖f‖ + rw [norm_smul] + norm_num only [norm_div,norm_one,Real.norm_ofNat] + have h := norm_sub_le f (Lp.compMeasurePreserving (fun g : κ → ℝ => -g) hμ f) + rw [Lp.norm_compMeasurePreserving] at h + linarith + +omit [Fintype κ] [IsFiniteMeasure μ] in +theorem oddPart_eq (hμ : MeasurePreserving (fun g : κ → ℝ => -g) μ μ) + (f : Lp ℝ 2 μ) (hf : ∀ᵐ g ∂μ, f (-g)= -f g) : oddPart μ hμ f=f := by + apply Lp.ext + filter_upwards [oddPart_ae μ hμ f,hf] with g hg hfg + rw [hg,hfg] + ring + +def sine (a g : κ → ℝ) : ℝ := Real.sin (∑k, a k*g k) + +theorem sine_memLp (a : κ → ℝ) : MemLp (sine a) 2 μ := by + have hc : Continuous (sine a) := by unfold sine; fun_prop + apply MemLp.of_bound hc.aestronglyMeasurable 1 + filter_upwards [] with g + exact Real.abs_sin_le_one (∑k, a k*g k) + +def sineVector (a : κ → ℝ) : Lp ℝ 2 μ := (sine_memLp μ a).toLp (sine a) + +theorem sineVector_ae (a : κ → ℝ) : + (sineVector μ a : (κ → ℝ) → ℝ)=ᵐ[μ] sine a := + (sine_memLp μ a).coeFn_toLp + + +theorem oddPart_realPart_character (hμ : MeasurePreserving (fun g : κ → ℝ => -g) μ μ) + (a : κ → ℝ) (z : ℂ) : + oddPart μ hμ (realPart μ (z • characterVector μ a))=(-z.im) • sineVector μ a := by + apply Lp.ext + have hre := realPart_ae μ (z • characterVector μ a) + have hsm := Lp.coeFn_smul z (characterVector μ a) + have hcv := characterVector_ae μ a + have hrneg := hμ.quasiMeasurePreserving.ae (hre.and (hsm.and hcv)) + filter_upwards [oddPart_ae μ hμ (realPart μ (z • characterVector μ a)), + hre,hsm,hcv,hrneg,Lp.coeFn_smul (-z.im) (sineVector μ a),sineVector_ae μ a] + with g ho hr hs hc hn hss hsin + rw [ho,hr,hs,hn.1,hn.2.1,hss] + simp only [Pi.smul_apply,smul_eq_mul] + rw [hc,hn.2.2,hsin] + simp [character,sine,Complex.exp_re,Complex.exp_im,Finset.sum_neg_distrib] + ring + +end FourierDensity + +namespace FourierDensity +open MeasureTheory Complex +open scoped InnerProductSpace Topology +variable {κ : Type*} [Fintype κ] (μ : Measure (κ → ℝ)) [IsFiniteMeasure μ] + + + +theorem exists_odd_sine_approx + (hμ : MeasurePreserving (fun g : κ → ℝ => -g) μ μ) + (f : Lp ℝ 2 μ) (hf : ∀ᵐ g ∂μ, f (-g)= -f g) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, + ‖(∑a∈s, b a • sineVector μ a)-f‖<ε := by + classical + let fC : Lp ℂ 2 μ := Complex.ofRealCLM.compLpL 2 μ f + have hr : realPart μ fC=f := by + apply Lp.ext + filter_upwards [realPart_ae μ fC,Complex.ofRealCLM.coeFn_compLpL f] with g hg hj + rw [hg] + change (fC g).re=f g + change fC g=(f g:ℂ) at hj + rw [hj,Complex.ofReal_re] + obtain ⟨c,hc⟩ := exists_character_approx μ fC hε + have hm : oddPart μ hμ (realPart μ (c.sum (fun a z => z • characterVector μ a)))= + ∑a∈c.support, -(c a).im • sineVector μ a := by + simp only [Finsupp.sum,map_sum,oddPart_realPart_character] + refine ⟨c.support,fun a => -(c a).im,?_⟩ + calc + ‖(∑a∈c.support, -(c a).im • sineVector μ a)-f‖ = + ‖oddPart μ hμ (realPart μ (c.sum (fun a z => z • characterVector μ a)-fC))‖ := by + rw [map_sub,map_sub,hm,hr,oddPart_eq μ hμ f hf] + _ ≤ ‖c.sum (fun a z => z • characterVector μ a)-fC‖ := + (oddPart_norm μ hμ _).trans (realPart_norm μ _) + _ < ε := hc + + + +def sinePolynomial (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (g : κ → ℝ) : ℝ := + ∑a∈s, b a*sine a g + +omit [IsFiniteMeasure μ] in +theorem sinePolynomial_odd (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (g : κ → ℝ) : + sinePolynomial s b (-g)= -sinePolynomial s b g := by + simp [sinePolynomial,sine,Finset.sum_neg_distrib] + +omit [IsFiniteMeasure μ] in +theorem sinePolynomial_bounded (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (g : κ → ℝ) : + |sinePolynomial s b g| ≤ ∑a∈s, |b a| := by + unfold sinePolynomial + calc + |∑a∈s, b a*sine a g| ≤ ∑a∈s, |b a*sine a g| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑a∈s, |b a| := by + apply Finset.sum_le_sum + intro a ha + rw [abs_mul] + exact mul_le_of_le_one_right (abs_nonneg (b a)) (Real.abs_sin_le_one _) + +omit [IsFiniteMeasure μ] in +theorem sinePolynomial_contDiff (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + ContDiff ℝ ⊤ (sinePolynomial s b) := by + unfold sinePolynomial sine + fun_prop + +end FourierDensity + +namespace FourierDensity +open MeasureTheory Complex +open scoped InnerProductSpace Topology +variable {κ : Type*} [Fintype κ] (μ : Measure (κ → ℝ)) [IsFiniteMeasure μ] + +theorem sinePolynomial_ae (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + ((∑a∈s, b a • sineVector μ a : Lp ℝ 2 μ) : (κ → ℝ) → ℝ)=ᵐ[μ] + sinePolynomial s b := by + classical + unfold sinePolynomial + induction s using Finset.induction_on with + | empty => simpa only [Finset.sum_empty,Pi.zero_def] using Lp.coeFn_zero ℝ 2 μ + | @insert a s ha ih => + simp only [Finset.sum_insert ha] + filter_upwards [Lp.coeFn_add (b a • sineVector μ a) (∑j∈s, b j • sineVector μ j), + Lp.coeFn_smul (b a) (sineVector μ a),sineVector_ae μ a,ih] with g h1 h2 h3 h4 + rw [h1] + simp only [Pi.add_apply] + rw [h2] + simp only [Pi.smul_apply,smul_eq_mul] + rw [h3,h4] + +def sineOutput (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (g : κ → ℝ) : ℝ := + Real.sin (2*sinePolynomial s b g) + +theorem sineOutput_memLp (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + MemLp (sineOutput s b) 2 μ := by + have hc : Continuous (sineOutput s b) := by + exact Real.continuous_sin.comp (continuous_const.mul (sinePolynomial_contDiff s b).continuous) + exact MemLp.of_bound hc.aestronglyMeasurable 1 + (Filter.Eventually.of_forall fun g => Real.abs_sin_le_one _) + +def sineOutputVector (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : Lp ℝ 2 μ := + (sineOutput_memLp μ s b).toLp (sineOutput s b) + +theorem sineOutputVector_ae (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + (sineOutputVector μ s b : (κ → ℝ) → ℝ)=ᵐ[μ] sineOutput s b := + (sineOutput_memLp μ s b).coeFn_toLp + + + +theorem exists_sine_angle_approx + (hμ : MeasurePreserving (fun g : κ → ℝ => -g) μ μ) + (f : Lp ℝ 2 μ) (hf : ∀ᵐ g ∂μ, f (-g)= -f g) + (hb : ∀ᵐ g ∂μ, |f g|≤1) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, + ‖sineOutputVector μ s b-f‖<ε := by + classical + let θ : (κ → ℝ) → ℝ := fun g => Real.arcsin (f g)/2 + have hθ : MemLp θ 2 μ := by + apply MemLp.of_bound + ((Real.continuous_arcsin.div_const 2).comp_aestronglyMeasurable (Lp.aestronglyMeasurable f)) + (Real.pi/4) + filter_upwards [] with g + change |Real.arcsin (f g)/2|≤Real.pi/4 + rw [abs_div,abs_of_pos (by norm_num : (0:ℝ)<2)] + have hs := abs_le.mpr (Real.arcsin_mem_Icc (f g)) + linarith + let θv : Lp ℝ 2 μ := hθ.toLp θ + have hθae : (θv : (κ → ℝ) → ℝ)=ᵐ[μ] θ := hθ.coeFn_toLp + have hθn := hμ.quasiMeasurePreserving.ae hθae + have hodd : ∀ᵐ g ∂μ, θv (-g)= -θv g := by + filter_upwards [hθae,hθn,hf] with g hg hng hfg + rw [hg,hng] + change Real.arcsin (f (-g))/2= -(Real.arcsin (f g)/2) + rw [hfg,Real.arcsin_neg,neg_div] + obtain ⟨s,b,happrox⟩ := exists_odd_sine_approx μ hμ θv hodd (half_pos hε) + refine ⟨s,b,?_⟩ + have hnorm : ‖sineOutputVector μ s b-f‖ ≤ + 2*‖(∑a∈s, b a • sineVector μ a)-θv‖ := by + apply Lp.norm_le_mul_norm_of_ae_le_mul + filter_upwards [Lp.coeFn_sub (sineOutputVector μ s b) f, + Lp.coeFn_sub (∑a∈s, b a • sineVector μ a) θv,sineOutputVector_ae μ s b, + sinePolynomial_ae μ s b,hθae,hb] with g h1 h2 h3 h4 h5 h6 + rw [h1,h2] + simp only [Pi.sub_apply,Real.norm_eq_abs] + rw [h3,h4,h5] + have hs : f g=Real.sin (2*θ g) := by + dsimp [θ] + rw [mul_div_cancel₀ _ (by norm_num : (2:ℝ)≠0)] + exact (Real.sin_arcsin (abs_le.mp h6).1 (abs_le.mp h6).2).symm + change |Real.sin (2*sinePolynomial s b g)-f g|≤2*|sinePolynomial s b g-θ g| + calc + _ = |Real.sin (2*sinePolynomial s b g)-Real.sin (2*θ g)| := by rw [←hs] + _ ≤ |2*sinePolynomial s b g-2*θ g| := Real.abs_sin_sub_sin_le _ _ + _ = _ := by rw [←mul_sub,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] + exact hnorm.trans_lt (by linarith) + +end FourierDensity + +namespace FourierDensity +open MeasureTheory Complex +open scoped InnerProductSpace Topology +variable {κ : Type*} [Fintype κ] + + +def frequency (a : κ → ℝ) : (κ → ℝ) →L[ℝ] ℝ := + ∑k, a k • ContinuousLinearMap.proj k + +@[simp] theorem frequency_apply (a g : κ → ℝ) : frequency a g=∑k, a k*g k := by + simp [frequency] + +theorem sine_norm_sub_le (a g h : κ → ℝ) : + |sine a g-sine a h| ≤ ‖frequency a‖*‖g-h‖ := by + calc + _ ≤ |frequency a g-frequency a h| := by + simpa only [frequency_apply,sine] using Real.abs_sin_sub_sin_le (frequency a g) (frequency a h) + _ = ‖frequency a (g-h)‖ := by rw [map_sub,Real.norm_eq_abs] + _ ≤ _ := (frequency a).le_opNorm _ + + +theorem sinePolynomial_lipschitz_bound (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) + (g h : κ → ℝ) : + |sinePolynomial s b g-sinePolynomial s b h| ≤ + (∑a∈s, |b a| *‖frequency a‖)*‖g-h‖ := by + simp only [sinePolynomial,←Finset.sum_sub_distrib,Finset.sum_mul] + calc + |∑a∈s, (b a*sine a g-b a*sine a h)| ≤ ∑a∈s, |b a*sine a g-b a*sine a h| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑a∈s, |b a| *‖frequency a‖*‖g-h‖ := by + apply Finset.sum_le_sum + intro a ha + rw [←mul_sub,abs_mul] + simpa only [mul_assoc] using + mul_le_mul_of_nonneg_left (sine_norm_sub_le a g h) (abs_nonneg (b a)) + +omit [Fintype κ] in +theorem iterated_sine_cosine_bound (n : ℕ) (x : ℝ) : + |iteratedDeriv n Real.sin x|≤1 ∧ |iteratedDeriv n Real.cos x|≤1 := by + induction n with + | zero => exact ⟨Real.abs_sin_le_one x,Real.abs_cos_le_one x⟩ + | succ n ih => + simp only [Real.iteratedDeriv_add_one_sin,Real.iteratedDeriv_add_one_cos, + Pi.neg_apply,abs_neg] + exact ih.symm + + +theorem sine_derivative_bound (a g : κ → ℝ) (n : ℕ) : + ‖iteratedFDeriv ℝ n (sine a) g‖ ≤ ‖frequency a‖^n := by + have hf : sine a=Real.sin ∘ frequency a := by funext g; simp [sine] + rw [hf,(frequency a).iteratedFDeriv_comp_right + (Real.contDiff_sin : ContDiff ℝ ⊤ Real.sin) g (by exact le_top)] + calc + _ ≤ ‖iteratedFDeriv ℝ n Real.sin (frequency a g)‖*∏_ : Fin n, ‖frequency a‖ := + ContinuousMultilinearMap.norm_compContinuousLinearMap_le _ _ + _ ≤ 1*∏_ : Fin n, ‖frequency a‖ := by + apply mul_le_mul_of_nonneg_right _ (Finset.prod_nonneg fun _ _ => norm_nonneg _) + rw [norm_iteratedFDeriv_eq_norm_iteratedDeriv,Real.norm_eq_abs] + exact (iterated_sine_cosine_bound n _).1 + _ = _ := by simp + + + +theorem sinePolynomial_derivative_bound (s : Finset (κ → ℝ)) + (b : (κ → ℝ) → ℝ) (n : ℕ) (g : κ → ℝ) : + ‖iteratedFDeriv ℝ n (sinePolynomial s b) g‖ ≤ + ∑a∈s, |b a| *‖frequency a‖^n := by + have hc (a : κ → ℝ) : ContDiff ℝ n (sine a) := by unfold sine; fun_prop + unfold sinePolynomial + rw [iteratedFDeriv_fun_sum_apply (fun a ha => (contDiff_const.mul (hc a)).contDiffAt)] + calc + _ ≤ ∑a∈s, ‖iteratedFDeriv ℝ n (fun g => b a*sine a g) g‖ := norm_sum_le _ _ + _ ≤ ∑a∈s, |b a| *‖frequency a‖^n := by + apply Finset.sum_le_sum + intro a ha + change ‖iteratedFDeriv ℝ n (fun g => b a • sine a g) g‖ ≤ _ + rw [iteratedFDeriv_const_smul_apply' (hc a).contDiffAt,norm_smul,Real.norm_eq_abs] + exact mul_le_mul_of_nonneg_left (sine_derivative_bound a g n) (abs_nonneg (b a)) + +end FourierDensity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/NegativeFlip.lean b/lean/OAI/Probability/ParisiFinite/NegativeFlip.lean new file mode 100644 index 0000000000000000000000000000000000000000..729b000e400b7c77903e9ea4f778b3afde25c3ee --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/NegativeFlip.lean @@ -0,0 +1,705 @@ +import Mathlib +import OAI.Probability.ParisiFinite.InsertionApprox +import OAI.Probability.ParisiFinite.ParamGate + +namespace OAI + +/-! Negative Flip. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +namespace PointedTree +open CoherentFock RootSpin +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r S : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +def negativeFlip (st : PacketStage l r S d spin) (a : ℕ → ShortPulse) (K : ℕ) + (hS : ∀ᶠ q in l,0≤S q) + (ho : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K (x q)-x q‖) l (𝓝 0)) + (hs : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K (st.special q (x q))- + SpinOperators.act (R (-(Real.pi/2))) (st.special q (x q))‖) l (𝓝 0)) : + PacketStage l r S d (fun i => 1-spin i) where + word q := probePrefix (r q) (st.word q) a K + ordinary q := (probeGain (r q) (st.word q) a K).toContinuousLinearEquiv.toContinuousLinearMap.comp (st.ordinary q) + special q := (probeGain (r q) (st.word q) a K).toContinuousLinearEquiv.toContinuousLinearMap.comp (st.special q) + split q x := by + rw [←probeGain_on_local,st.split,map_add] + rfl + special_norm := by + filter_upwards [st.special_norm] with q hq x + simpa only [ContinuousLinearMap.comp_apply,LinearIsometryEquiv.coe_toContinuousLinearEquiv, + ContinuousLinearEquiv.coe_coe,LinearIsometryEquiv.norm_map] using hq x + low := st.low + phase := st.phase + phase_norm := st.phase_norm + ordinary_low x hx := by + have he := st.ordinary_low x hx + have hp := ho (fun q => st.phase q • st.low.op q (x q)) (st.low_bounded x hx) + have ht := ForwardControl.scaled_identity_transfer + (fun q => probeGain (r q) (st.word q) a K) S + (fun q => st.ordinary q (x q)) (fun q => st.phase q • st.low.op q (x q)) hS hp he + exact ForwardControl.scaled_triangle S _ _ _ hS ht he + special_packets x hx := (st.special_packets x hx).negative_half_mixer.close hS (hs x hx) + +theorem Transported.negativeFlip {st : PacketStage l r S d spin} {address : α → SpinSpace ModeInfinity} + (ht : st.Transported address) (a : ℕ → ShortPulse) (K : ℕ) (hS : ∀ᶠ q in l,0≤S q) + (ho : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K (x q)-x q‖) l (𝓝 0)) + (hs : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K (st.special q (x q))- + SpinOperators.act (R (-(Real.pi/2))) (st.special q (x q))‖) l (𝓝 0)) + (hz : Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K + (SpinOperators.act Z (st.special q (vacuum ModeInfinity)))- + SpinOperators.act (R (-(Real.pi/2))) (SpinOperators.act Z (st.special q (vacuum ModeInfinity)))‖) l (𝓝 0)) : + (st.negativeFlip a K hS ho hs).Transported (fun q => -address q) := by + have hh := ForwardControl.scaled_special_transport (fun q => ordinaryLocal (st.word q)) + (fun q => probeGain (r q) (st.word q) a K) (SpinOperators.act Z) + (SpinOperators.act (R (-(Real.pi/2)))) + (fun x : SpinSpace ModeInfinity => (SpinOperators.norm_act Z_unitary x).le) + negative_half_mixer_anticommutes (fun q => st.special q (vacuum ModeInfinity)) address S + hS (hs _ BoundedPacket.vacuum) hz ht + have he (q : α) (x : SpinSpace ModeInfinity) : + (ordinaryLocal (probePrefix (r q) (st.word q) a K)).symm x= + (ordinaryLocal (st.word q)).symm ((probeGain (r q) (st.word q) a K).symm x) := + local_symm_after_gain _ _ _ (probeGain_on_local _ _ _ _) x + change Tendsto (fun q => ‖(S q:ℂ) • (ordinaryLocal (probePrefix (r q) (st.word q) a K)).symm + (SpinOperators.act Z (probeGain (r q) (st.word q) a K (st.special q (vacuum ModeInfinity))))-(-address q)‖) l (𝓝 0) + simpa only [he,sub_neg_eq_add] using hh + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +open RootSpin +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem inner_im_signed_self (v d : E) (i : Fin 2) (t : ℝ) : + (⟪v,d+signedMode i (t • v)⟫_ℂ).im=(⟪v,d⟫_ℂ).im := by + have hi : (⟪v,v⟫_ℂ).im=0 := inner_self_im (𝕜:=ℂ) v + change (⟪v,d+signedMode i ((t:ℂ) • v)⟫_ℂ).im=_ + unfold signedMode + split_ifs <;> simp only [inner_add_right,inner_neg_right,inner_smul_right, + Complex.add_im,Complex.neg_im,Complex.mul_im,Complex.ofReal_im,Complex.ofReal_re, + hi,mul_zero,zero_mul,add_zero,neg_zero] + +end CoherentFock +namespace PointedTree +open CoherentFock RootSpin +local instance ssRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance ssRealSMul : SMul ℝ ModeInfinity := ssRealModule.toDistribMulAction.toSMul +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +theorem exists_standard_selector (st : PacketStage l r (fun q => (r q)⁻¹) d spin) (θ : ℝ) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 -2*(⟪insertionInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (v i).1)) + (hY : ∀i,Tendsto (fun q => -2*(⟪insertionYInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (v i).2)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + (∀x,BoundedPacket l x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.word q) a K (x q)-x q‖) l (𝓝 0)) ∧ + (∀x,PacketExpansion (l:=l) (fun q => (r q)⁻¹) r d spin x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.word q) a K (x q)- + SpinOperators.act (R θ) (x q)‖) l (𝓝 0)) := by + let o (q : α) := st.ordinary q (vacuum ModeInfinity) + let y (q : α) := st.phase q • st.low.op q (vacuum ModeInfinity) + let s (q : α) := st.special q (vacuum ModeInfinity) + obtain ⟨hS,hscale⟩ := reciprocal_scale_eventually r hr hp + have he : Tendsto (fun q => ‖o q-y q‖) l (𝓝 0) := + PacketGeometry.tendsto_of_scaled (fun q => (r q)⁻¹) _ hS + (Eventually.of_forall fun _ => norm_nonneg _) (st.ordinary_low _ BoundedPacket.vacuum) + have hψ : ∀ᶠ q in l,ordinaryLocal (st.word q) (vacuum ModeInfinity)=y q+s q+(o q-y q) := by + exact Eventually.of_forall fun q => by dsimp only [o,s]; rw [st.split]; abel + exact standard_selective_bounded r st.word y s (fun q => o q-y q) + (st.low_bounded _ BoundedPacket.vacuum) d spin C hC hd v hv θ hr hp hψ + (st.special_vacuum_zero hr) he hZ hY + + + +theorem exists_huge_selector_visible (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (ht : t≠0) (θ : ℝ) (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (d i q))) + (c : κ → ℝ) (hc : ∀i,c i≠0) + (hZ : ∀i,Tendsto (fun q => (⟪insertionInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (c i))) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + (∀x,BoundedPacket l x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K + (WZ (st.forwardVector t q) (x q))-WZ (st.forwardVector t q) (x q)‖) l (𝓝 0)) ∧ + (∀x,PacketExpansion (l:=l) (fun q => (r q)⁻¹) r (st.forwardCenter t) spin x → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (st.forwardWord t q) a K (x q)- + SpinOperators.act (R θ) (x q)‖) l (𝓝 0)) := by + have hbound (i : κ) : ∀ᶠ q in l,‖st.forwardCenter t i q‖≤C+|t| := by + filter_upwards [hd i] with q hq + apply (norm_add_le _ _).trans + simp only [norm_signedMode,norm_smul,Real.norm_eq_abs,abs_neg,norm_insertionInfinity,mul_one] + exact add_le_add hq le_rfl + have hz (i : κ) : Tendsto (fun q => (⟪insertionInfinity (st.forwardWord t q),st.forwardCenter t i q⟫_ℂ).im) + l (𝓝 (c i)) := by + simpa only [forwardWord,insertionInfinity_cost,forwardCenter,inner_im_signed_self] using hZ i + have hy (i : κ) : Tendsto (fun q => -2*(⟪insertionYInfinity (st.forwardWord t q),st.forwardCenter t i q⟫_ℂ).im) + l (𝓝 0) := by + have hi := (Complex.continuous_im.tendsto 0).comp + (st.huge_transverse_approx t ht hr hp (st.forwardCenter t i) (st.forwardCenter_approx t hr hp ha i)) + simpa only [Function.comp_def,Complex.zero_im,mul_zero] using hi.const_mul (-2) + exact st.exists_huge_selector t ht θ hr hp (C+|t|) (add_nonneg hC (abs_nonneg _)) hbound c (fun _ => 0) hc hz hy + + + +theorem exists_negativeFlip (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (address : α → SpinSpace ModeInfinity) (ht : st.Transported address) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 -2*(⟪insertionInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (v i).1)) + (hY : ∀i,Tendsto (fun q => -2*(⟪insertionYInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (v i).2)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse) (st' : PacketStage l r (fun q => (r q)⁻¹) d (fun i => 1-spin i)), + (∀q,st'.word q=probePrefix (r q) (st.word q) a K) ∧ + (∀q x,st'.low.op q x=st.low.op q x) ∧ st'.Transported (fun q => -address q) := by + obtain ⟨K,a,ho,hs⟩ := st.exists_standard_selector (-(Real.pi/2)) hr hp C hC hd v hv hZ hY + have hS : ∀ᶠ q in l,0≤(r q)⁻¹ := hp.mono fun _ hq => (inv_pos.mpr hq).le + let st' := st.negativeFlip a K hS ho (fun x hx => hs _ (st.special_packets x hx)) + refine ⟨K,a,st',fun _ => rfl,fun _ _ => rfl,?_⟩ + exact ht.negativeFlip a K hS ho (fun x hx => hs _ (st.special_packets x hx)) + (hs _ (st.special_packets _ BoundedPacket.vacuum).rootZ) + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance esRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance esRealSMul : SMul ℝ ModeInfinity := esRealModule.toDistribMulAction.toSMul +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +theorem halfEchoCenter_bounded (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (C : ℝ) + (hd : ∀i,∀ᶠ q in l,‖d i q‖≤C) (i : κ) : + ∀ᶠ q in l,‖st.halfEchoCenter t a K i q‖≤C+2*|t| := by + filter_upwards [hd i] with q hq + unfold halfEchoCenter forwardCenter + apply (norm_add_le _ _).trans + have hh := (norm_add_le (d i q) (signedMode (spin i) ((-t) • insertionInfinity (st.word q)))) + simp only [norm_signedMode,norm_smul,Real.norm_eq_abs,abs_neg,norm_insertionInfinity,mul_one] at hh ⊢ + calc + _ ≤ (‖d i q‖+|t|)+|t| := add_le_add hh le_rfl + _ ≤ C+2*|t| := by linarith + + + +theorem halfEchoCenter_approx (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) + (st' : PacketStage l r (fun q => (r q)⁻¹) (st.halfEchoCenter t a K) (fun i => 1-spin i)) + (hw : ∀q,st'.word q=st.halfEchoWord t a K q) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (d i q))) (i : κ) : + ApproxPacket l (fun q => modeFock (st.halfEchoCenter t a K i q)) := by + have ha : ApproxPacket l (fun q => modeFock + (insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K))) := by + simpa only [hw,halfEchoWord,insertionInfinity_cost] using st'.insertionZ_approx hr hp + have he (v : ModeInfinity) : modeFock (t • v)=(t:ℂ) • modeFock v := by + change modeFock ((t:ℂ) • v)=_ + exact map_smul _ _ _ + have hsum := st.forwardCenter_approx t hr hp hd i + have hv := ha.smul (t:ℂ) + unfold halfEchoCenter signedMode + split_ifs + · simpa only [map_add,he] using hsum.add hv + · simpa only [map_add,map_neg,he] using hsum.add hv.neg + + + +theorem exists_halfEcho (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (ht : t≠0) (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (d i q))) + (c : κ → ℝ) (hc : ∀i,c i≠0) + (hZ : ∀i,Tendsto (fun q => (⟪insertionInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (c i))) + (address : α → ModeInfinity) (htrans : st.Transported (fun q => modeFock (address q))) + (A : ℝ) (hA : 0≤A) (haddr : ∀ᶠ q in l,‖address q‖≤A) : + ∃ (K : ℕ) (a : ℕ → ShortPulse) + (st' : PacketStage l r (fun q => (r q)⁻¹) (st.halfEchoCenter t a K) (fun i => 1-spin i)), + (∀q,st'.word q=st.halfEchoWord t a K q) ∧ + (∀q x,st'.low.op q x=WZ (st.halfEchoResidual t a K q) (st.low.op q x)) ∧ + st'.Transported (fun q => -modeFock (address q)) ∧ + Tendsto (fun q => ‖st.halfEchoResidual t a K q-(-2*t) • address q‖) l (𝓝 0) ∧ + (∀i,ApproxPacket l (fun q => modeFock (st.halfEchoCenter t a K i q))) := by + obtain ⟨K,a,ho,hs⟩ := st.exists_huge_selector_visible t ht (Real.pi/2) hr hp C hC hd ha c hc hZ + have he := st.halfEchoResidual_tendsto address htrans t a K hp ho hs + let G : ℝ := 1+2*|t| *A + have hG : 0≤G := by dsimp only [G]; positivity + have hg : ∀ᶠ q in l,‖st.halfEchoResidual t a K q‖≤G := + st.halfEchoResidual_bounded address t a K A hA haddr he + let st' := st.halfEcho t a K G hG hg hp ho (fun x hx => hs _ (st.forward_special_packets t x hx)) + refine ⟨K,a,st',fun _ => rfl,fun _ _ => rfl,?_,he,?_⟩ + · exact htrans.halfEcho t a K G hG hg hp ho hs + · exact st.halfEchoCenter_approx t a K st' (fun _ => rfl) hr hp ha + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace GramCalculus +open CoherentFock PointedTree +namespace WeylWord +variable {E F α ι : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] [Fintype ι] {l : Filter α} + {d : α → ι → E} {d₀ : ι → F} + + + +def family (w : List (WeylGate ι)) (hg : GramConverges l d d₀) : PacketUnitaryFamily (E:=E) l where + op q := op (d q) w + forward x hx := bounded w hx hg + backward x hx := by simpa only [op_inv] using bounded (inv w) hx hg + +theorem low_insertion_match (w : List (WeylGate ι)) (hg : GramConverges l d d₀) + (A : PacketUnitaryFamily (E:=E) l) (hc : PacketUnitaryFamily.LowClose A (family w hg)) + (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) : + ApproxMatch l d d₀ + (fun q => (A.op q).symm (SpinOperators.act P (A.op q (vacuum E)))) + ((op d₀ w).symm (SpinOperators.act P (op d₀ w (vacuum F)))) := by + exact (insertion_match w P hg).approx.close (hc.insertion P hP) + +end WeylWord +end GramCalculus + +namespace PointedTree +open CoherentFock RootSpin GramCalculus +namespace PacketStage +variable {F α κ ι : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [Fintype κ] [Fintype ι] {l : Filter α} {r : α → ℝ} + {centers : κ → α → ModeInfinity} {spin : κ → Fin 2} + {d : α → ι → ModeInfinity} {d₀ : ι → F} + + + +theorem actual_insertion_match (st : PacketStage l r (fun q => (r q)⁻¹) centers spin) + (w : List (WeylGate ι)) (hg : GramConverges l d d₀) + (hc : PacketUnitaryFamily.LowClose st.low (WeylWord.family w hg)) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 (ordinaryLocal (st.word q)).symm + (SpinOperators.act P (ordinaryLocal (st.word q) (vacuum ModeInfinity)))) + ((WeylWord.op d₀ w).symm (SpinOperators.act P (WeylWord.op d₀ w (vacuum F)))) := by + apply (WeylWord.low_insertion_match w hg st.low hc P hP).close + exact low_insertion_tendsto _ st.low st.ordinary st.special st.phase r (fun q => (r q)⁻¹) + P hP hr (hp.mono fun q hq => ⟨hq.le,(inv_pos.mpr hq).le,inv_mul_cancel₀ hq.ne'⟩) + (Eventually.of_forall st.split) (st.special_norm.mono fun _ hq x => (hq x).le) st.ordinary_low + +theorem insertionZ_match (st : PacketStage l r (fun q => (r q)⁻¹) centers spin) + (w : List (WeylGate ι)) (hg : GramConverges l d d₀) + (hc : PacketUnitaryFamily.LowClose st.low (WeylWord.family w hg)) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (insertionInfinity (st.word q))) + ((WeylWord.op d₀ w).symm (SpinOperators.act Z (WeylWord.op d₀ w (vacuum F)))) := by + simpa only [modeFock_insertion] using st.actual_insertion_match w hg hc hr hp Z Z_unitary + +theorem insertionY_match (st : PacketStage l r (fun q => (r q)⁻¹) centers spin) + (w : List (WeylGate ι)) (hg : GramConverges l d d₀) + (hc : PacketUnitaryFamily.LowClose st.low (WeylWord.family w hg)) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 modeFock (insertionYInfinity (st.word q))) + ((WeylWord.op d₀ w).symm (SpinOperators.act Y (WeylWord.op d₀ w (vacuum F)))) := by + simpa only [modeFock_insertionY] using st.actual_insertion_match w hg hc hr hp Y Y_unitary + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E α : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] {l : Filter α} + + +theorem ApproxPacket.inner_escape {x z : α → SpinSpace E} (hx : ApproxPacket l x) + (hz : ∀q,‖z q‖=1) + (hescape : ∀y,BoundedPacket l y → Tendsto (fun q => ⟪y q,z q⟫_ℂ) l (𝓝 0)) : + Tendsto (fun q => ⟪x q,z q⟫_ℂ) l (𝓝 0) := by + obtain ⟨y,hy,he⟩ := hx + have hd : Tendsto (fun q => ⟪x q,z q⟫_ℂ-⟪y q,z q⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ he + exact Eventually.of_forall fun q => by + rw [←inner_sub_left] + simpa only [hz,mul_one] using norm_inner_le_norm (𝕜:=ℂ) (x q-y q) (z q) + simpa only [sub_add_cancel,zero_add] using hd.add (hescape y hy) + +end CoherentFock + +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus + +def seedDirections (b T : ℝ) (i : Fin 2) : ModeInfinity := + if i=0 then highInfinity (gamma b T) else addressInfinity b T + +def seedBasis (i : Fin 2) : SeededTree.External := EuclideanSpace.single i 1 + +@[simp] theorem norm_seedDirections (b T : ℝ) (i : Fin 2) : ‖seedDirections b T i‖=1 := by + unfold seedDirections + split_ifs <;> simp only [norm_highInfinity,norm_addressInfinity] + +@[simp] theorem seedBasis_inner (i j : Fin 2) : + ⟪seedBasis i,seedBasis j⟫_ℂ=if i=j then 1 else 0 := by + simp [seedBasis,EuclideanSpace.inner_single_left] + + + +theorem seedDirections_gram (b : ℝ) (hb : 0 fin_cases j <;> try contradiction + · simpa [seedDirections] using + high_addressInfinity_orthogonal b hb + · have ht := (Complex.continuous_conj.tendsto _).comp (high_addressInfinity_orthogonal b hb) + simpa [Function.comp_def,seedDirections,inner_conj_symm] using ht + + + +theorem seedDirections_escape (b : ℝ) (hb : 0 ⟪x T,modeFock (seedDirections b T i)⟫_ℂ) atTop (𝓝 0) := by + apply hx.inner_escape (fun T => by rw [modeFock.norm_map,norm_seedDirections]) + intro y hy + unfold seedDirections + split_ifs + · exact highInfinity_escapes b hb y hy + · exact addressInfinity_escapes b hb y hy + + + +theorem extend_dictionary {ι κ : Type*} [Fintype ι] [Fintype κ] + (b : ℝ) (hb : 0 modeFock (z T i))) + (hm : ∀i,ApproxMatch atTop d d₀ (fun T => modeFock (z T i)) (z₀ i : SeededTree.Level n)) : + GramConverges atTop + (fun T => Sum.elim (seedDirections b T) (z T)) + (Sum.elim (fun i => SeededTree.external (n+1) (seedBasis i)) + (fun i => SeededTree.endogenous n (z₀ i))) := by + intro i j + cases i with + | inl i => + cases j with + | inl j => + simpa only [Sum.elim_inl,LinearIsometry.inner_map_map] using seedDirections_gram b hb i j + | inr j => + simp only [Sum.elim_inl,Sum.elim_inr] + rw [SeededTree.external_inner_endogenous n (seedBasis i) (z₀ j)] + have ht := (Complex.continuous_conj.tendsto _).comp (seedDirections_escape b hb _ (hz j) i) + simpa only [Function.comp_def,map_zero,inner_conj_symm,modeFock.inner_map_map] using ht + | inr i => + cases j with + | inl j => + simp only [Sum.elim_inl,Sum.elim_inr] + have hh : ⟪SeededTree.endogenous n (z₀ i),SeededTree.external (n+1) (seedBasis j)⟫_ℂ=0 := by + rw [←inner_conj_symm,SeededTree.external_inner_endogenous,map_zero] + rw [hh] + simpa only [modeFock.inner_map_map] using seedDirections_escape b hb _ (hz i) j + | inr j => + simpa only [Sum.elim_inr,LinearIsometry.inner_map_map,Submodule.coe_inner, + modeFock.inner_map_map] using (hm i).inner (hm j) hg + +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace GramCalculus +open CoherentFock PointedTree +variable {E F G α ι κ : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] [Fintype ι] [Fintype κ] {l : Filter α} + +@[simp] theorem combination_map (T : F →ₗᵢ[ℂ] G) (d : ι → F) (c : ι → ℂ) : + combination (fun i => T (d i)) c=T (combination d c) := by + simp only [combination,map_sum,map_smul] + +@[simp] theorem combination_sum_zero (d : ι → E) (e : κ → E) (c : ι → ℂ) : + combination (Sum.elim d e) (Sum.elim c 0)=combination d c := by + simp [combination,Fintype.sum_sum_type] + +namespace PacketMatch +variable {d : α → ι → E} {d₀ : ι → F} {x : α → SpinSpace E} {x₀ : SpinSpace F} + + + +theorem model_map (hx : PacketMatch l d d₀ x x₀) (T : F →ₗᵢ[ℂ] G) : + PacketMatch l d (fun i => T (d₀ i)) x (spinMap (gammaEmbedding T) x₀) := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + refine ⟨n,a,a₀,c,hx,?_,ha⟩ + rw [hx₀,spinMap_spinPacket] + simp only [combination_map] + + + +theorem weaken (hx : PacketMatch l d d₀ x x₀) (e : α → κ → E) (e₀ : κ → F) : + PacketMatch l (fun q => Sum.elim (d q) (e q)) (Sum.elim d₀ e₀) x x₀ := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + refine ⟨n,a,a₀,fun i => Sum.elim (c i) 0,?_,?_,ha⟩ + · simpa only [combination_sum_zero] using hx + · simpa only [combination_sum_zero] using hx₀ + + +theorem reindex (hx : PacketMatch l d d₀ x x₀) (e : κ ≃ ι) : + PacketMatch l (fun q j => d q (e j)) (fun j => d₀ (e j)) x x₀ := by + obtain ⟨n,a,a₀,c,hx,hx₀,ha⟩ := hx + have hc (q : α) (i : Fin n) : combination (fun j => d q (e j)) (fun j => c i (e j))= + combination (d q) (c i) := e.sum_comp (fun j => c i j • d q j) + have hc₀ (i : Fin n) : combination (fun j => d₀ (e j)) (fun j => c i (e j))= + combination d₀ (c i) := e.sum_comp (fun j => c i j • d₀ j) + exact ⟨n,a,a₀,fun i j => c i (e j),by simpa only [hc] using hx, + by simpa only [hc₀] using hx₀,ha⟩ + +end PacketMatch +namespace ApproxMatch +variable {d : α → ι → E} {d₀ : ι → F} {x : α → SpinSpace E} {x₀ : SpinSpace F} + +theorem model_map (hx : ApproxMatch l d d₀ x x₀) (T : F →ₗᵢ[ℂ] G) : + ApproxMatch l d (fun i => T (d₀ i)) x (spinMap (gammaEmbedding T) x₀) := by + obtain ⟨y,hy,he⟩ := hx + exact ⟨y,hy.model_map T,he⟩ + +theorem weaken (hx : ApproxMatch l d d₀ x x₀) (e : α → κ → E) (e₀ : κ → F) : + ApproxMatch l (fun q => Sum.elim (d q) (e q)) (Sum.elim d₀ e₀) x x₀ := by + obtain ⟨y,hy,he⟩ := hx + exact ⟨y,hy.weaken e e₀,he⟩ + +theorem reindex (hx : ApproxMatch l d d₀ x x₀) (e : κ ≃ ι) : + ApproxMatch l (fun q j => d q (e j)) (fun j => d₀ (e j)) x x₀ := by + obtain ⟨y,hy,he⟩ := hx + exact ⟨y,hy.reindex e,he⟩ + +end ApproxMatch +namespace GramConverges +variable {d : α → ι → E} {d₀ : ι → F} + +omit [Fintype ι] in +theorem model_map (hg : GramConverges l d d₀) (T : F →ₗᵢ[ℂ] G) : + GramConverges l d (fun i => T (d₀ i)) := by + intro i j + simpa only [T.inner_map_map] using hg i j + +omit [Fintype ι] [Fintype κ] in +theorem reindex (hg : GramConverges l d d₀) (e : κ → ι) : + GramConverges l (fun q j => d q (e j)) (fun j => d₀ (e j)) := fun i j => hg (e i) (e j) + +end GramConverges +end GramCalculus + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus + + + +structure CausalFrame (b : ℝ) (n : ℕ) (κ : Type*) [Fintype κ] where + actual : ℝ → κ → ModeInfinity + formal : κ → SeededTree.Mode n + gram : GramConverges atTop + (fun T => Sum.elim (seedDirections b T) (actual T)) + (Sum.elim (fun i => SeededTree.external (n+1) (seedBasis i)) + (fun i => SeededTree.endogenous n (formal i))) + bounded : ∀i,ApproxPacket atTop (fun T => modeFock (actual T i)) + packet : ∀i,ApproxMatch atTop + (fun T => Sum.elim (seedDirections b T) (actual T)) + (Sum.elim (fun i => SeededTree.external (n+1) (seedBasis i)) + (fun i => SeededTree.endogenous n (formal i))) + (fun T => modeFock (actual T i)) + ((SeededTree.empty n).toLinearIsometry (formal i : SeededTree.Level n)) + +namespace CausalFrame +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + +def directions (f : CausalFrame b n κ) (T : ℝ) : Fin 2 ⊕ κ → ModeInfinity := + Sum.elim (seedDirections b T) (f.actual T) + +def model (f : CausalFrame b n κ) : Fin 2 ⊕ κ → SeededTree.TopMode (n+1) := + Sum.elim (fun i => SeededTree.external (n+1) (seedBasis i)) + (fun i => SeededTree.endogenous n (f.formal i)) + +def initial (b : ℝ) (hb : 0 + cases j with + | inl j => simpa only [Sum.elim_inl,LinearIsometry.inner_map_map] using seedDirections_gram b hb i j + | inr j => exact j.elim + | inr i => exact i.elim + bounded i := i.elim + packet i := i.elim + + + +def append (f : CausalFrame b n κ) (hb : 0 modeFock (z T))) + (hm : ApproxMatch atTop f.directions f.model (fun T => modeFock (z T)) + (z₀ : SeededTree.Level (n+1))) : CausalFrame b (n+1) (κ ⊕ Unit) where + actual T := Sum.elim (f.actual T) (fun _ => z T) + formal := Sum.elim (fun i => centeredMap (SeededTree.empty n) (f.formal i)) (fun _ => z₀) + gram := by + apply extend_dictionary b hb (n+1) f.directions f.model f.gram + · intro i + cases i with + | inl i => exact f.bounded i + | inr i => exact hz + · intro i + cases i with + | inl i => exact f.packet i + | inr i => exact hm + bounded i := by + cases i with + | inl i => exact f.bounded i + | inr i => exact hz + packet i := by + let old : Fin 2 ⊕ κ → SeededTree.TopMode (n+2) := fun j => SeededTree.topStep (n+1) (f.model j) + let extra : Unit → SeededTree.TopMode (n+2) := fun _ => SeededTree.endogenous (n+1) z₀ + let e : Fin 2 ⊕ (κ ⊕ Unit) ≃ (Fin 2 ⊕ κ) ⊕ Unit := (Equiv.sumAssoc _ _ _).symm + have ha (T : ℝ) : (fun j => Sum.elim (f.directions T) (fun _ : Unit => z T) (e j))= + Sum.elim (seedDirections b T) (Sum.elim (f.actual T) (fun _ => z T)) := by + funext j + rcases j with j|j + · rfl + · rcases j with j|j <;> rfl + have hf : (fun j => Sum.elim old extra (e j))= + Sum.elim (fun j => SeededTree.external (n+1+1) (seedBasis j)) + (fun j => SeededTree.endogenous (n+1) + (Sum.elim (fun i => centeredMap (SeededTree.empty n) (f.formal i)) (fun _ => z₀) j)) := by + funext j + rcases j with j|j + · exact SeededTree.topStep_external (n+1) (seedBasis j) + · rcases j with j|j + · exact SeededTree.topStep_endogenous n (f.formal j) + · rfl + have transport (x : ℝ → SpinSpace ModeInfinity) (x₀ : SeededTree.Level (n+1)) + (hx : ApproxMatch atTop f.directions f.model x x₀) : + ApproxMatch atTop + (fun T => Sum.elim (seedDirections b T) (Sum.elim (f.actual T) (fun _ : Unit => z T))) + (Sum.elim (fun j => SeededTree.external (n+1+1) (seedBasis j)) + (fun j => SeededTree.endogenous (n+1) + (Sum.elim (fun i => centeredMap (SeededTree.empty n) (f.formal i)) (fun _ : Unit => z₀) j))) + x ((SeededTree.empty (n+1)).toLinearIsometry x₀) := by + have hh := (((hx.model_map (SeededTree.topStep (n+1))).weaken + (fun T (_ : Unit) => z T) extra).reindex e) + change ApproxMatch atTop (fun T j => Sum.elim (f.directions T) (fun _ : Unit => z T) (e j)) + (fun j => Sum.elim old extra (e j)) x _ at hh + have hfun : (fun T j => Sum.elim (f.directions T) (fun _ : Unit => z T) (e j))= + (fun T => Sum.elim (seedDirections b T) (Sum.elim (f.actual T) (fun _ => z T))) := by + funext T; exact ha T + rw [hfun,hf] at hh + rw [SeededTree.empty_apply] + exact hh + cases i with + | inl i => exact transport _ _ (f.packet i) + | inr i => exact transport _ _ hm + +end CausalFrame +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock + + + +@[simp] theorem modeFock_shift (d : ModeInfinity) : + modeFock (shiftInfinity d)=plusEmbedding (creationVacuum d) := by + have hc : Continuous (fun d : ModeInfinity => plusEmbedding (creationVacuum d)) := + plusEmbedding.continuous.comp creationEmbedding.continuous + have he := (HilbertChain.denseRange_embed ModeSpace modeStep).equalizer + (modeFock.continuous.comp shiftInfinity.continuous) hc + apply congrFun (he ?_) d + funext z + rcases z with ⟨n,x⟩ + change modeFock (shiftInfinity (modeEmbed n x))=plusEmbedding (creationVacuum (modeEmbed n x)) + rw [shiftInfinity_embed] + change unfoldTree (modeInWhole (modeEmbed (n+1) (rootShift n x)))=_ + rw [modeInWhole_embed,unfoldTree_embed_succ,rootShift_coe] + change spinMap (gammaEmbedding (modeEmbed n)) (plusEmbedding (creationVacuum x))=_ + rw [spinMap_plusEmbedding] + congr 1 + exact Gamma_creationVacuum (modeEmbed n) x + + theorem energyInfinity_fock (d : ModeInfinity) : + energyInfinity d=(⟪modeFock d,plusEmbedding (creationVacuum d)⟫_ℂ).re := by + rw [←modeFock_shift,modeFock.inner_map_map] + rfl + +end PointedTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Nnwidth.lean b/lean/OAI/Probability/ParisiFinite/Nnwidth.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f2388facdd60a98929f56313ba450cbc37c2ebb --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Nnwidth.lean @@ -0,0 +1,591 @@ +import Mathlib +import OAI.Probability.ParisiFinite.TerminalThird + +namespace OAI + +/-! Nnwidth. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function +open scoped Topology NNReal ENNReal +namespace ParisiFinite + + +def nnwidth : Schedule → ℝ≥0 + | [] => 0 + | (_,d)::ls => d+nnwidth ls + +lemma coe_nnwidth (ls : Schedule) : (nnwidth ls : ℝ) = width ls := by + induction ls with + | nil => rfl + | cons l ls ih => simp [nnwidth,width,ih] + +@[simp] lemma nnwidth_append (ls rs : Schedule) : + nnwidth (ls++rs) = nnwidth ls+nnwidth rs := by + induction ls with + | nil => simp [nnwidth] + | cons l ls ih => simp [nnwidth,ih,add_assoc] + + + +def scheduleValue : Schedule → ℝ≥0 → ℝ≥0 + | [],_ => 0 + | (a,d)::ls,t => if t < d then a else scheduleValue ls (t-d) + +@[simp] lemma scheduleValue_zero_cons (a : ℝ≥0) (ls : Schedule) (t : ℝ≥0) : + scheduleValue ((a,0)::ls) t = scheduleValue ls t := by + simp [scheduleValue] + +@[simp] lemma scheduleValue_cons_shift (a d : ℝ≥0) (ls : Schedule) (t : ℝ≥0) : + scheduleValue ((a,d)::ls) (d+t) = scheduleValue ls t := by + simp [scheduleValue,not_lt.mpr (show d ≤ d+t from le_add_of_nonneg_right zero_le)] + +lemma scheduleValue_split_shift (a d e : ℝ≥0) (hde : d ≤ e) + (ls : Schedule) (t : ℝ≥0) : + scheduleValue ((a,e)::ls) (d+t) = scheduleValue ((a,e-d)::ls) t := by + have he : d+(e-d)=e := add_tsub_cancel_of_le hde + have hc : d+t < e ↔ t < e-d := by + exact lt_tsub_iff_left.symm + simp only [scheduleValue,hc] + split_ifs with ht + · rfl + · congr 1 + calc (d+t)-e = (d+t)-(d+(e-d)) := by rw [he] + _ = t-(e-d) := add_tsub_add_eq_tsub_left _ _ _ + +lemma scheduleValue_append_left (ls rs : Schedule) (t : ℝ≥0) + (ht : t < nnwidth ls) : scheduleValue (ls++rs) t = scheduleValue ls t := by + induction ls generalizing t with + | nil => simp [nnwidth] at ht + | cons l ls ih => + simp only [nnwidth] at ht + simp only [List.cons_append,scheduleValue] + split_ifs with htd + · rfl + · apply ih + exact (tsub_lt_iff_left (le_of_not_gt htd)).mpr ht + +lemma scheduleValue_append_right (ls rs : Schedule) (t : ℝ≥0) : + scheduleValue (ls++rs) (nnwidth ls+t) = scheduleValue rs t := by + induction ls with + | nil => simp [nnwidth] + | cons l ls ih => + rcases l with ⟨a,d⟩ + simp only [nnwidth,List.cons_append,add_assoc,scheduleValue_cons_shift,ih] + +@[simp] lemma evolve_zero_cons (a : ℝ≥0) (ls : Schedule) (f : ℝ → ℝ) : + evolve ((a,0)::ls) f = evolve ls f := by + funext x + simp [evolve] + +lemma evolve_of_nnwidth_zero (ls : Schedule) (hls : nnwidth ls=0) (f : ℝ → ℝ) : + evolve ls f=f := by + induction ls with + | nil => rfl + | cons l ls ih => + have hh : l.2=0 ∧ nnwidth ls=0 := add_eq_zero.mp hls + obtain ⟨a,d⟩ := l + simp only at hh + rw [hh.1,evolve_zero_cons,ih hh.2] + + + +lemma evolve_le_of_scheduleValue_le {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (ls rs : Schedule) (hw : nnwidth ls=nnwidth rs) + (hle : ∀ t, t < nnwidth ls → scheduleValue ls t ≤ scheduleValue rs t) (x : ℝ) : + evolve ls f x ≤ evolve rs f x := by + cases ls with + | nil => + rw [evolve_of_nnwidth_zero rs hw.symm f] + exact le_rfl + | cons l ls => + obtain ⟨a,d⟩ := l + cases rs with + | nil => + rw [evolve_of_nnwidth_zero ((a,d)::ls) hw f] + exact le_rfl + | cons r rs => + obtain ⟨b,e⟩ := r + by_cases hd : d=0 + · subst d + rw [evolve_zero_cons] + apply evolve_le_of_scheduleValue_le hf ls ((b,e)::rs) (by simpa [nnwidth] using hw) + intro t ht + simpa using hle t (by simpa [nnwidth] using ht) + by_cases he : e=0 + · subst e + rw [evolve_zero_cons] + apply evolve_le_of_scheduleValue_le hf ((a,d)::ls) rs (by simpa [nnwidth] using hw) + intro t ht + simpa using hle t ht + have hd' : 0 < d := pos_iff_ne_zero.mpr hd + have he' : 0 < e := pos_iff_ne_zero.mpr he + have hab : a ≤ b := by + have hh := hle 0 (by simp only [nnwidth]; positivity) + simpa only [scheduleValue,hd',he',↓reduceIte] using hh + by_cases hde : d ≤ e + · let rr : Schedule := (b,e-d)::rs + have hw' : nnwidth ls=nnwidth rr := by + dsimp only [nnwidth] at hw ⊢ + dsimp only [rr,nnwidth] + apply (add_left_cancel (a := d)) + rw [← add_assoc,add_tsub_cancel_of_le hde] + exact hw + have hm : ∀ y,evolve ls f y ≤ evolve rr f y := by + intro y + apply evolve_le_of_scheduleValue_le hf ls rr hw' + intro t ht + have ht' : d+t < nnwidth ((a,d)::ls) := by + simpa only [nnwidth] using add_lt_add_right ht d + have hh := hle (d+t) ht' + simpa only [scheduleValue_cons_shift,scheduleValue_split_shift _ _ _ hde,rr] using hh + have hs : evolve ((b,e)::rs) f = step b (Real.sqrt d) (evolve rr f) := by + have hh := evolve_split hf b d (e-d) rs + rw [add_tsub_cancel_of_le hde] at hh + exact hh.symm + rw [hs] + change step a (Real.sqrt d) (evolve ls f) x ≤ _ + exact (step_parameter_mono (evolve_lipschitz hf ls) a.coe_nonneg (by exact_mod_cast hab) + (Real.sqrt d) x).trans + (step_le_of_le (evolve_lipschitz hf ls) (evolve_lipschitz hf rr) b.coe_nonneg + (Real.sqrt d) x hm) + · have hed : e ≤ d := le_of_not_ge hde + let ll : Schedule := (a,d-e)::ls + have hw' : nnwidth ll=nnwidth rs := by + dsimp only [nnwidth] at hw + dsimp only [ll,nnwidth] + apply (add_left_cancel (a := e)) + rw [← add_assoc,add_tsub_cancel_of_le hed] + exact hw + have hm : ∀ y,evolve ll f y ≤ evolve rs f y := by + intro y + apply evolve_le_of_scheduleValue_le hf ll rs hw' + intro t ht + have ht' : e+t < nnwidth ((a,d)::ls) := by + have hh := add_lt_add_right ht e + simpa only [ll,nnwidth,← add_assoc,add_tsub_cancel_of_le hed] using hh + have hh := hle (e+t) ht' + simpa only [scheduleValue_cons_shift,scheduleValue_split_shift _ _ _ hed,ll] using hh + have hs : evolve ((a,d)::ls) f = step a (Real.sqrt e) (evolve ll f) := by + have hh := evolve_split hf a e (d-e) ls + rw [add_tsub_cancel_of_le hed] at hh + exact hh.symm + rw [hs] + change _ ≤ step b (Real.sqrt e) (evolve rs f) x + exact (step_parameter_mono (evolve_lipschitz hf ll) a.coe_nonneg (by exact_mod_cast hab) + (Real.sqrt e) x).trans + (step_le_of_le (evolve_lipschitz hf ll) (evolve_lipschitz hf rs) b.coe_nonneg + (Real.sqrt e) x hm) +termination_by ls.length+rs.length + +lemma dyadicSchedule_nnwidth (γ : ℝ≥0 → ℝ≥0) (u : Bool) (t d : ℝ≥0) (n : ℕ) : + nnwidth (dyadicSchedule γ u t d n) = d := by + apply NNReal.coe_injective + rw [coe_nnwidth,dyadicSchedule_width] + +lemma dyadicSchedule_value_bounds {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) + (t d : ℝ≥0) (n : ℕ) {s : ℝ≥0} (hs : s < d) : + scheduleValue (dyadicSchedule γ false t d n) s ≤ γ (t+s) ∧ + γ (t+s) ≤ scheduleValue (dyadicSchedule γ true t d n) s := by + induction n generalizing t d s with + | zero => + simp only [dyadicSchedule,Bool.false_eq_true,↓reduceIte,scheduleValue,hs] + exact ⟨hγ (le_add_of_nonneg_right zero_le),hγ (add_le_add_right hs.le t)⟩ + | succ n ih => + simp only [dyadicSchedule] + by_cases hsd : s < d/2 + · rw [scheduleValue_append_left _ _ s (by rwa [dyadicSchedule_nnwidth]), + scheduleValue_append_left _ _ s (by rwa [dyadicSchedule_nnwidth])] + exact ih t (d/2) hsd + · have hd : d/2 ≤ s := le_of_not_gt hsd + have he : d/2+(s-d/2)=s := add_tsub_cancel_of_le hd + have ht : s-d/2 < d/2 := by + apply (tsub_lt_iff_left hd).mpr + simpa only [add_halves] using hs + have hlo := scheduleValue_append_right + (dyadicSchedule γ false t (d/2) n) + (dyadicSchedule γ false (t+d/2) (d/2) n) (s-d/2) + have hhi := scheduleValue_append_right + (dyadicSchedule γ true t (d/2) n) + (dyadicSchedule γ true (t+d/2) (d/2) n) (s-d/2) + rw [dyadicSchedule_nnwidth,he] at hlo hhi + rw [hlo,hhi] + simpa only [add_assoc,he] using ih (t+d/2) (d/2) ht + +lemma dyadicSchedule_append_value_bounds {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) + (t d e : ℝ≥0) (n : ℕ) {s : ℝ≥0} (hs : s < d+e) : + scheduleValue (dyadicSchedule γ false t d n ++ dyadicSchedule γ false (t+d) e n) s ≤ γ (t+s) ∧ + γ (t+s) ≤ scheduleValue (dyadicSchedule γ true t d n ++ dyadicSchedule γ true (t+d) e n) s := by + by_cases hsd : s < d + · rw [scheduleValue_append_left _ _ s (by rwa [dyadicSchedule_nnwidth]), + scheduleValue_append_left _ _ s (by rwa [dyadicSchedule_nnwidth])] + exact dyadicSchedule_value_bounds hγ t d n hsd + · have hd : d ≤ s := le_of_not_gt hsd + have he : d+(s-d)=s := add_tsub_cancel_of_le hd + have ht : s-d < e := (tsub_lt_iff_left hd).mpr hs + have hlo := scheduleValue_append_right + (dyadicSchedule γ false t d n) (dyadicSchedule γ false (t+d) e n) (s-d) + have hhi := scheduleValue_append_right + (dyadicSchedule γ true t d n) (dyadicSchedule γ true (t+d) e n) (s-d) + rw [dyadicSchedule_nnwidth,he] at hlo hhi + rw [hlo,hhi] + simpa only [add_assoc,he] using dyadicSchedule_value_bounds hγ (t+d) e n ht + +lemma dyadicEvolution_high_grid_bound {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (t d : ℝ≥0) (n : ℕ) (x : ℝ) : + |evolve (dyadicSchedule γ true t d n) f x-dyadicEvolution γ t d f x| ≤ + 2*gaussianSmallError β (Real.sqrt (dyadicMesh d n)) := by + have hlo : evolve (dyadicSchedule γ false t d n) f x ≤ dyadicEvolution γ t d f x := + le_ciSup (dyadic_low_bddAbove hf hγ t d x) n + have hhi : dyadicEvolution γ t d f x ≤ evolve (dyadicSchedule γ true t d n) f x := by + apply le_of_tendsto (dyadic_high_tendsto hf hγ hb t d x) + filter_upwards [eventually_ge_atTop n] with k hk + exact dyadic_high_antitone hf hγ t d x hk + have he := abs_le.mp (dyadicSchedule_grid_error hb t d n hf x) + rw [abs_of_nonneg (sub_nonneg.mpr hhi)] + linarith + +lemma dyadicEvolution_dyadic_grid_bound {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (u : Bool) (t d : ℝ≥0) (n : ℕ) (x : ℝ) : + |evolve (dyadicSchedule γ u t d n) f x-dyadicEvolution γ t d f x| ≤ + 2*gaussianSmallError β (Real.sqrt (dyadicMesh d n)) := by + cases u + · exact dyadicEvolution_grid_bound hf hγ hb t d n x + · exact dyadicEvolution_high_grid_bound hf hγ hb t d n x + +lemma dyadic_tendsto {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (u : Bool) (t d : ℝ≥0) (x : ℝ) : + Tendsto (fun n => evolve (dyadicSchedule γ u t d n) f x) atTop + (𝓝 (dyadicEvolution γ t d f x)) := by + cases u + · exact dyadic_low_tendsto hf hγ t d x + · exact dyadic_high_tendsto hf hγ hb t d x + +lemma dyadic_append_tendsto {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (u : Bool) (t d e : ℝ≥0) (x : ℝ) : + Tendsto (fun n => evolve (dyadicSchedule γ u t d n ++ dyadicSchedule γ u (t+d) e n) f x) atTop + (𝓝 (dyadicEvolution γ t d (dyadicEvolution γ (t+d) e f) x)) := by + let g := dyadicEvolution γ (t+d) e f + have hg : LipschitzWith 1 g := dyadicEvolution_lipschitz hf hγ _ _ + have hleft := dyadic_tendsto hg hγ hb u t d x + have he : Tendsto (fun n => 2*gaussianSmallError β (Real.sqrt (dyadicMesh e n))) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero] using (gaussianSmallError_dyadic_tendsto β e).const_mul 2 + have hbnd (n : ℕ) : |evolve (dyadicSchedule γ u t d n ++ dyadicSchedule γ u (t+d) e n) f x- + evolve (dyadicSchedule γ u t d n) g x| ≤ + 2*gaussianSmallError β (Real.sqrt (dyadicMesh e n)) := by + rw [evolve_append] + exact evolve_stable (evolve_lipschitz hf _) hg _ _ + (fun y => dyadicEvolution_dyadic_grid_bound hf hγ hb u (t+d) e n y) x + apply tendsto_of_tendsto_of_tendsto_of_le_of_le + (by simpa only [sub_zero] using hleft.sub he) + (by simpa only [add_zero] using hleft.add he) + · intro n; have hh := (abs_le.mp (hbnd n)).1; linarith + · intro n; have hh := (abs_le.mp (hbnd n)).2; linarith + + + +lemma dyadicEvolution_DPP {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (t d e : ℝ≥0) (x : ℝ) : + dyadicEvolution γ t (d+e) f x = + dyadicEvolution γ t d (dyadicEvolution γ (t+d) e f) x := by + apply le_antisymm + · apply le_of_tendsto_of_tendsto (dyadic_low_tendsto hf hγ t (d+e) x) + (dyadic_append_tendsto hf hγ hb true t d e x) + apply Eventually.of_forall + intro n + apply evolve_le_of_scheduleValue_le hf + · simp only [nnwidth_append,dyadicSchedule_nnwidth] + · intro s hs + rw [dyadicSchedule_nnwidth] at hs + exact (dyadicSchedule_value_bounds hγ t (d+e) n hs).1.trans + (dyadicSchedule_append_value_bounds hγ t d e n hs).2 + · apply le_of_tendsto_of_tendsto (dyadic_append_tendsto hf hγ hb false t d e x) + (dyadic_high_tendsto hf hγ hb t (d+e) x) + apply Eventually.of_forall + intro n + apply evolve_le_of_scheduleValue_le hf + · simp only [nnwidth_append,dyadicSchedule_nnwidth] + · intro s hs + rw [nnwidth_append,dyadicSchedule_nnwidth,dyadicSchedule_nnwidth] at hs + exact (dyadicSchedule_append_value_bounds hγ t d e n hs).1.trans + (dyadicSchedule_value_bounds hγ t (d+e) n hs).2 + +lemma field_DPP (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) + {t s : ℝ≥0} (hts : t ≤ s) (hs : s ≤ 1) (x : ℝ) : + field β γ t x = dyadicEvolution γ t (s-t) (field β γ s) x := by + have he : (s-t)+(1-s)=1-t := by + rw [add_comm,tsub_add_tsub_cancel hs hts] + have hh := dyadicEvolution_DPP (terminal_lipschitz hβ) hγ + (fun u => by exact_mod_cast hb u) t (s-t) (1-s) x + rw [he,add_tsub_cancel_of_le hts] at hh + exact hh + +lemma recursion_prefix_time_bound (β : ℝ≥0) (hβ : 0 < β) (ls rs : Schedule) + (ha : ∀ l ∈ ls ++ rs,l.1 ≤ β) (x : ℝ) : + 0 ≤ recursion β (ls ++ rs) x-recursion β rs x ∧ + recursion β (ls ++ rs) x-recursion β rs x ≤ (β:ℝ)*width ls/2 := by + induction ls with + | nil => simp [width] + | cons l ls ih => + have ht : ∀ k ∈ ls ++ rs,k.1 ≤ β := fun k hk => ha k (List.mem_cons_of_mem _ hk) + have hb := step_curvature_time_bound (smoothRecursion_hasParisiCurvature β hβ (ls ++ rs) ht) + l.1.coe_nonneg (by exact_mod_cast ha l (List.mem_cons_self)) (Real.sqrt l.2) (Real.sqrt_nonneg _) x + rw [smoothRecursion_val,Real.sq_sqrt l.2.coe_nonneg] at hb + have hh := ih ht + change 0 ≤ step l.1 (Real.sqrt l.2) (recursion β (ls ++ rs)) x-recursion β rs x ∧ + step l.1 (Real.sqrt l.2) (recursion β (ls ++ rs)) x-recursion β rs x ≤ (β:ℝ)*width (l::ls)/2 + have hw : width (l::ls)=(l.2:ℝ)+width ls := by simp [width] + rw [hw] + constructor <;> nlinarith [hb.1,hb.2,hh.1,hh.2] + + + +lemma field_time_bound (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) + {t s : ℝ≥0} (hts : t ≤ s) (hs : s ≤ 1) (x : ℝ) : + 0 ≤ field β γ t x-field β γ s x ∧ + field β γ t x-field β γ s x ≤ (β:ℝ)*(s-t:ℝ≥0)/2 := by + have he : (s-t)+(1-s)=1-t := by rw [add_comm,tsub_add_tsub_cancel hs hts] + have hfull := dyadic_append_tendsto (f := terminal (β : ℝ)) (terminal_lipschitz hβ) hγ + (fun u => by exact_mod_cast hb u) false t (s-t) (1-s) x + have heq : dyadicEvolution γ t (s-t) (dyadicEvolution γ (t+(s-t)) (1-s) (terminal β)) x = + field β γ t x := by + have hh := dyadicEvolution_DPP (f := terminal (β : ℝ)) (terminal_lipschitz hβ) hγ + (fun u => by exact_mod_cast hb u) t (s-t) (1-s) x + rw [he] at hh + exact hh.symm + rw [heq,add_tsub_cancel_of_le hts] at hfull + have hr := dyadic_low_tendsto (terminal_lipschitz hβ) hγ s (1-s) x + change Tendsto _ _ (𝓝 (field β γ s x)) at hr + have hlim := hfull.sub hr + have hbounds (n : ℕ) : + 0 ≤ evolve (dyadicSchedule γ false t (s-t) n ++ dyadicSchedule γ false s (1-s) n) (terminal β) x - + evolve (dyadicSchedule γ false s (1-s) n) (terminal β) x ∧ + evolve (dyadicSchedule γ false t (s-t) n ++ dyadicSchedule γ false s (1-s) n) (terminal β) x - + evolve (dyadicSchedule γ false s (1-s) n) (terminal β) x ≤ (β:ℝ)*(s-t:ℝ≥0)/2 := by + have hh := recursion_prefix_time_bound β hβ + (dyadicSchedule γ false t (s-t) n) (dyadicSchedule γ false s (1-s) n) (by + intro l hl + rcases List.mem_append.mp hl with h|h + · exact dyadicSchedule_coeff_bound hb false t (s-t) n l h + · exact dyadicSchedule_coeff_bound hb false s (1-s) n l h) x + rwa [recursion_eq_evolve,recursion_eq_evolve,dyadicSchedule_width] at hh + exact ⟨ge_of_tendsto hlim (Eventually.of_forall fun n => (hbounds n).1), + le_of_tendsto hlim (Eventually.of_forall fun n => (hbounds n).2)⟩ + +lemma field_time_abs_bound (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) + {t s : ℝ≥0} (ht : t ≤ 1) (hs : s ≤ 1) (x : ℝ) : + |field β γ t x-field β γ s x| ≤ (β:ℝ)/2*|(t:ℝ)-s| := by + rcases le_total t s with hts|hst + · have hh := field_time_bound β hβ hγ hb hts hs x + rw [abs_of_nonneg hh.1,abs_of_nonpos (sub_nonpos.mpr (by exact_mod_cast hts))] + rw [NNReal.coe_sub hts] at hh + nlinarith [hh.2] + · have hh := field_time_bound β hβ hγ hb hst ht x + rw [abs_sub_comm,abs_of_nonneg hh.1,abs_of_nonneg (sub_nonneg.mpr (by exact_mod_cast hst))] + rw [NNReal.coe_sub hst] at hh + nlinarith [hh.2] + +lemma field_joint_lipschitz (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) : + LipschitzWith (β/2+1) (fun q : OrderPoint × ℝ => field β γ (Real.toNNReal q.1) q.2) := by + apply LipschitzWith.of_dist_le_mul + intro u v + have hut : Real.toNNReal (u.1:ℝ) ≤ 1 := Real.toNNReal_le_one.mpr u.1.property.2 + have hvt : Real.toNNReal (v.1:ℝ) ≤ 1 := Real.toNNReal_le_one.mpr v.1.property.2 + have ht := field_time_abs_bound β hβ hγ hb hut hvt u.2 + rw [Real.coe_toNNReal _ u.1.property.1,Real.coe_toNNReal _ v.1.property.1] at ht + have hx := (dyadicEvolution_lipschitz (terminal_lipschitz hβ) hγ + (Real.toNNReal v.1) (1-Real.toNNReal v.1)).dist_le_mul u.2 v.2 + change dist (field β γ _ u.2) (field β γ _ v.2) ≤ _ at hx + norm_num only [NNReal.coe_one,one_mul] at hx + rw [Real.dist_eq] at hx ⊢ + have htri := abs_sub_le (field β γ (Real.toNNReal u.1) u.2) + (field β γ (Real.toNNReal v.1) u.2) (field β γ (Real.toNNReal v.1) v.2) + have htu : |(u.1:ℝ)-v.1| ≤ dist u v := by + change dist u.1 v.1 ≤ dist u v + exact le_max_left _ _ + have hxu : dist u.2 v.2 ≤ dist u v := le_max_right _ _ + simp only [NNReal.coe_add,NNReal.coe_div,NNReal.coe_ofNat,NNReal.coe_one] + nlinarith [mul_le_mul_of_nonneg_left htu (show 0 ≤ (β:ℝ)/2 by positivity)] + +lemma continuous_field_joint (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) : + Continuous (fun q : OrderPoint × ℝ => field β γ (Real.toNNReal q.1) q.2) := + (field_joint_lipschitz β hβ hγ hb).continuous + +lemma field_taylor_error (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) + (t : ℝ≥0) (x : ℝ) {h : ℝ} (hh : 0 ≤ h) : + |field β γ t (x+h)-field β γ t x-h*fieldGradient β γ t x| ≤ (β:ℝ)*h^2 := by + have hv (y : ℝ) : Tendsto + (fun n => (smoothRecursion β hβ (dyadicSchedule γ false t (1-t) n)).val y) + atTop (𝓝 (field β γ t y)) := by + simpa only [smoothRecursion_val,recursion_eq_evolve,field,NNReal.toReal] using + dyadic_low_tendsto (terminal_lipschitz hβ) hγ t (1-t) y + have hm := fieldGradient_dyadic_tendsto β hβ hγ hb t x + apply le_of_tendsto (((hv (x+h)).sub (hv x)).sub (hm.const_mul h) |>.abs) + exact Eventually.of_forall fun n => curvature_taylor_error + (smoothRecursion_hasParisiCurvature β hβ _ (dyadicSchedule_coeff_bound hb false t (1-t) n)) x hh + +lemma field_slope_error (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) + (t : ℝ≥0) (x : ℝ) {h : ℝ} (hh : 0 < h) : + |(field β γ t (x+h)-field β γ t x)/h-fieldGradient β γ t x| ≤ (β:ℝ)*h := by + rw [div_sub' hh.ne',abs_div,abs_of_pos hh] + apply (div_le_iff₀ hh).mpr + simpa only [pow_two,mul_assoc] using field_taylor_error β hβ hγ hb t x hh.le + + + +lemma continuous_fieldGradient_joint (β : ℝ≥0) (hβ : 0 < β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) : + Continuous (fun q : OrderPoint × ℝ => fieldGradient β γ (Real.toNNReal q.1) q.2) := by + let ε (n : ℕ) : ℝ := 1/(n+1 : ℕ) + let F (n : ℕ) (q : OrderPoint × ℝ) : ℝ := + (field β γ (Real.toNNReal q.1) (q.2+ε n)-field β γ (Real.toNNReal q.1) q.2)/ε n + have he (n : ℕ) : 0 < ε n := by dsimp [ε]; positivity + have ht : Tendsto (fun n => (β:ℝ)*ε n) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero] using SKCavity.tendsto_succ_reciprocal.const_mul (β:ℝ) + have hu : TendstoUniformly F (fun q : OrderPoint × ℝ => + fieldGradient β γ (Real.toNNReal q.1) q.2) atTop := by + rw [Metric.tendstoUniformly_iff] + intro δ hδ + filter_upwards [ht.eventually (gt_mem_nhds hδ)] with n hn q + rw [Real.dist_eq,abs_sub_comm] + exact (field_slope_error β hβ hγ hb (Real.toNNReal q.1) q.2 (he n)).trans_lt hn + apply hu.continuous + apply Eventually.frequently + apply Eventually.of_forall + intro n + have hc := continuous_field_joint β hβ hγ hb + exact ((hc.comp (continuous_fst.prodMk (continuous_snd.add_const (ε n)))).sub hc).div_const (ε n) + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +def fieldCurvature (β : ℝ≥0) (γ : ℝ≥0 → ℝ≥0) (t : ℝ≥0) : ℝ → ℝ := + deriv (fieldGradient β γ t) + +lemma fieldGradient_dyadic_uniform (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) : + TendstoUniformly (fun n => (smoothRecursion β hβ (dyadicSchedule γ false t (1-t) n)).d1) + (fieldGradient β γ t) atTop := by + obtain ⟨m,hd,_,_,hu⟩ := dyadicEvolution_terminal_gradient β hβ hγ hb t (1-t) + have he : fieldGradient β γ t=m := funext (fun x => (hd x).deriv) + rw [he] + exact hu + +lemma fieldCurvature_exists (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) : + TendstoUniformly (fun n => (smoothRecursion β hβ (dyadicSchedule γ false t (1-t) n)).d2) + (fieldCurvature β γ t) atTop ∧ + (∀ x,HasDerivAt (fieldGradient β γ t) (fieldCurvature β γ t x) x) ∧ + LipschitzWith (5*β^2) (fieldCurvature β γ t) := by + have hl (n : ℕ) : LipschitzWith (5*β^2) + (smoothRecursion β hβ (dyadicSchedule γ false t (1-t) n)).d2 := + recursion_curvature_lipschitz β hβ _ (ordered_lower (γ t).coe_nonneg + (ordered_upper (show (γ (t+(1-t)):ℝ)≤β by exact_mod_cast hb _) + (dyadicSchedule_ordered hγ false t (1-t) n))) + obtain ⟨g,hu,hd,hg⟩ := exists_uniform_derivative_lipschitz_limit + (fun n => (smoothRecursion β hβ (dyadicSchedule γ false t (1-t) n)).hasD2) hl + (fieldGradient_dyadic_uniform β hβ hγ hb t) + have he : fieldCurvature β γ t=g := funext (fun x => (hd x).deriv) + rw [he] + exact ⟨hu,hd,hg⟩ + +lemma hasDerivAt_fieldGradient (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) (x : ℝ) : + HasDerivAt (fieldGradient β γ t) (fieldCurvature β γ t x) x := + (fieldCurvature_exists β hβ hγ hb t).2.1 x + +lemma fieldCurvature_lipschitz (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) : + LipschitzWith (5*β^2) (fieldCurvature β γ t) := + (fieldCurvature_exists β hβ hγ hb t).2.2 + +lemma fieldCurvature_dyadic_tendsto (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) (x : ℝ) : + Tendsto (fun n => (smoothRecursion β hβ (dyadicSchedule γ false t (1-t) n)).d2 x) + atTop (𝓝 (fieldCurvature β γ t x)) := + (fieldCurvature_exists β hβ hγ hb t).1.tendsto_at x + +lemma fieldCurvature_bounds (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) (x : ℝ) : + 0 finite_curvature_floor β hβ _ + (dyadicSchedule_coeff_bound hb false t (1-t) n) + (by rw [dyadicSchedule_width];exact_mod_cast (tsub_le_self : 1-t≤(1:ℝ≥0))) le_rfl + · apply le_of_tendsto_of_tendsto ht + (((fieldGradient_dyadic_tendsto β hβ hγ hb t x).pow 2).const_sub 1 |>.const_mul (β:ℝ)) + exact Eventually.of_forall fun n => (smoothRecursion_hasParisiCurvature β hβ _ + (dyadicSchedule_coeff_bound hb false t (1-t) n)).2 x |>.2 + +lemma fieldCurvature_abs (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) (x : ℝ) : + |fieldCurvature β γ t x|≤β := by + obtain ⟨hp,hu⟩ := fieldCurvature_bounds β hβ hγ hb t x + rw [abs_of_pos hp] + nlinarith [mul_nonneg β.coe_nonneg (sq_nonneg (fieldGradient β γ t x))] + +lemma fieldGradient_slope_error (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (t : ℝ≥0) (x : ℝ) {h : ℝ} (hh : 0 fieldCurvature β γ (Real.toNNReal q.1) q.2) := by + let ε (n : ℕ) : ℝ := 1/(n+1 : ℕ) + let F (n : ℕ) (q : OrderPoint × ℝ) : ℝ := + (fieldGradient β γ (Real.toNNReal q.1) (q.2+ε n)-fieldGradient β γ (Real.toNNReal q.1) q.2)/ε n + have he (n : ℕ) : 0<ε n := by dsimp [ε];positivity + have ht : Tendsto (fun n => 5*(β:ℝ)^2*ε n) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero] using SKCavity.tendsto_succ_reciprocal.const_mul (5*(β:ℝ)^2) + have hu : TendstoUniformly F (fun q : OrderPoint × ℝ => + fieldCurvature β γ (Real.toNNReal q.1) q.2) atTop := by + rw [Metric.tendstoUniformly_iff] + intro δ hδ + filter_upwards [ht.eventually (gt_mem_nhds hδ)] with n hn q + rw [Real.dist_eq,abs_sub_comm] + exact (fieldGradient_slope_error β hβ hγ hb (Real.toNNReal q.1) q.2 (he n)).trans_lt hn + apply hu.continuous + apply Eventually.frequently + apply Eventually.of_forall + intro n + have hc := continuous_fieldGradient_joint β hβ hγ hb + exact ((hc.comp (continuous_fst.prodMk (continuous_snd.add_const (ε n)))).sub hc).div_const (ε n) + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/OrderPointIntegrable.lean b/lean/OAI/Probability/ParisiFinite/OrderPointIntegrable.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d00f284e6874e60a9b3f38a3a710225f992f85e --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/OrderPointIntegrable.lean @@ -0,0 +1,279 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ScheduleWidthNonneg + +namespace OAI + +/-! Order Point Integrable. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + +lemma orderPoint_integrable (ρ : ProbabilityMeasure OrderPoint) : + Integrable (fun x : OrderPoint => (x:ℝ)) (ρ:Measure OrderPoint) := by + apply (integrable_const (1:ℝ)).mono' continuous_subtype_val.aestronglyMeasurable + exact ae_of_all _ fun x => by simpa only [Real.norm_eq_abs,abs_of_nonneg x.2.1] using x.2.2 + +lemma orderPoint_mean_zero_iff (ρ : ProbabilityMeasure OrderPoint) : + (∫ x : OrderPoint,(x:ℝ) ∂(ρ:Measure OrderPoint))=0 ↔ ρ=zeroOrderMeasure := by + constructor + · intro h + have hae := (integral_eq_zero_iff_of_nonneg_ae + (ae_of_all (ρ:Measure OrderPoint) fun x : OrderPoint => x.2.1) + (orderPoint_integrable ρ)).mp h + have he : (fun x : OrderPoint => x)=ᵐ[(ρ:Measure OrderPoint)] + fun _ => (⟨0,by norm_num⟩ : OrderPoint) := hae.mono fun x hx => by + apply Subtype.ext + exact hx + have hh : Measure.map (fun x : OrderPoint => x) (ρ:Measure OrderPoint)= + Measure.map (fun _ : OrderPoint => (⟨0,by norm_num⟩ : OrderPoint)) (ρ:Measure OrderPoint) := + Measure.map_congr he + change Measure.map id (ρ:Measure OrderPoint)=_ at hh + rw [Measure.map_id] at hh + apply Subtype.ext + simp only [Measure.map_const,measure_univ,one_smul] at hh + convert! hh using 1 + · rintro rfl + simp [zeroOrderMeasure] + + + +lemma minimizingParisi_mean_pos (β : ℝ≥0) (hb : (1:ℝ)<β) + {ρ : ProbabilityMeasure OrderPoint} (hρ : IsMinimizingParisiMeasure β ρ) : + 0<(∫ x : OrderPoint,(x:ℝ) ∂(ρ:Measure OrderPoint)) := by + have hn : 0≤(∫ x : OrderPoint,(x:ℝ) ∂(ρ:Measure OrderPoint)) := + integral_nonneg fun x : OrderPoint => x.2.1 + apply lt_of_le_of_ne hn + intro he + have hzero := (orderPoint_mean_zero_iff ρ).mp he.symm + subst ρ + exact zeroOrderMeasure_not_minimizing β hb hρ + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +lemma hasDerivAt_tiltedMean (f : SmoothField) {g g' : ℝ → ℝ} + (hd : ∀ x,HasDerivAt g (g' x) x) (hc : Continuous g') + {M N : ℝ≥0} (hM : ∀ x,|g x|≤M) (hN : ∀ x,|g' x|≤N) (a s x : ℝ) : + HasDerivAt (tiltedMean a s f.val g) + (tiltedMean a s f.val g' x+a*(tiltedMean a s f.val (fun y => f.d1 y*g y) x- + tiltedMean a s f.val f.d1 x*tiltedMean a s f.val g x)) x := by + have hgc : Continuous g := continuous_iff_continuousAt.mpr fun y => (hd y).continuousAt + have h := hasDerivAt_expMoment f.lipschitz f.hasD1 f.continuousD1 f.normD1 + hd hc hM hN a s x + have he (y : ℝ) : a*f.d1 y*g y+g' y=g' y+a*(f.d1 y*g y) := by ring + simp_rw [he] at h + change HasDerivAt (expMoment a s f.val g) + (expMoment a s f.val (fun y => g' y+a*(f.d1 y*g y)) x) x at h + have hp : ∀ y,|a*(f.d1 y*g y)|≤|a| *((f.bound1:ℝ)*M) := by + intro y + rw [abs_mul,abs_mul] + exact mul_le_mul_of_nonneg_left + (mul_le_mul (f.normD1 y) (hM y) (abs_nonneg _) f.bound1.coe_nonneg) (abs_nonneg a) + rw [expMoment_add (g := g') (h := fun y => a*(f.d1 y*g y)) f.lipschitz hc + (by have hh := f.continuousD1;fun_prop) hN hp,expMoment_const_mul] at h + have hh := h.div (hasDerivAt_expMass f a s x) (expMass_pos f.lipschitz a s x).ne' + convert hh using 1 <;> first | rfl | (unfold tiltedMean;field_simp;ring) + +structure ThirdJet (f : SmoothField) where + d3 : ℝ → ℝ + hasD3 : ∀ x,HasDerivAt f.d2 (d3 x) x + continuousD3 : Continuous d3 + bound3 : ℝ≥0 + normD3 : ∀ x,|d3 x|≤bound3 + +namespace ThirdJet +variable {f : SmoothField} + +def expThird (j : ThirdJet f) (a x : ℝ) : ℝ := + j.d3 x+3*a*(f.d1 x*f.d2 x)+a^2*(f.d1 x)^3 + +lemma continuous_expThird (j : ThirdJet f) (a : ℝ) : Continuous (j.expThird a) := by + have h1 := f.continuousD1 + have h2 := f.continuousD2 + have h3 := j.continuousD3 + unfold expThird + fun_prop + +lemma product_bound (x : ℝ) : |f.d1 x*f.d2 x|≤ (f.bound1:ℝ)*f.bound2 := by + rw [abs_mul] + exact mul_le_mul (f.normD1 x) (f.normD2 x) (abs_nonneg _) f.bound1.coe_nonneg + +lemma cube_bound (x : ℝ) : |f.d1 x^3|≤(f.bound1:ℝ)^3 := by + rw [abs_pow] + exact pow_le_pow_left₀ (abs_nonneg _) (f.normD1 x) 3 + +lemma expThird_bound (j : ThirdJet f) (a x : ℝ) : + |j.expThird a x|≤j.bound3+3*|a| *((f.bound1:ℝ)*f.bound2)+a^2*(f.bound1:ℝ)^3 := by + unfold expThird + apply (abs_add_le _ _).trans + apply (add_le_add (abs_add_le _ _) (le_refl _)).trans + norm_num only [abs_mul,abs_of_nonneg (sq_nonneg a)] + gcongr <;> first | exact j.normD3 x | exact f.normD1 x | exact f.normD2 x | exact cube_bound (f := f) x + + + +def transformD3 (j : ThirdJet f) (a s x : ℝ) : ℝ := + tiltedMean a s f.val (j.expThird a) x- + 3*a*((f.transform a s).d1 x*(f.transform a s).d2 x)- + a^2*((f.transform a s).d1 x)^3 + +lemma expThird_tilt (j : ThirdJet f) (a s x : ℝ) : + tiltedMean a s f.val (j.expThird a) x= + tiltedMean a s f.val j.d3 x+3*a*tiltedMean a s f.val (fun y => f.d1 y*f.d2 y) x+ + a^2*tiltedMean a s f.val (fun y => (f.d1 y)^3) x := by + have h12 : Continuous (fun y => f.d1 y*f.d2 y) := f.continuousD1.mul f.continuousD2 + have h3 : Continuous (fun y => (f.d1 y)^3) := f.continuousD1.pow 3 + unfold expThird + have hA : ∀ y,|3*a*(f.d1 y*f.d2 y)|≤|3*a| *((f.bound1:ℝ)*f.bound2) := by + intro y + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (product_bound y) (abs_nonneg _) + have hB : ∀ y,|a^2*f.d1 y^3|≤|a^2| *(f.bound1:ℝ)^3 := by + intro y + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (cube_bound y) (abs_nonneg _) + rw [tiltedMean_add (g := fun y => j.d3 y+3*a*(f.d1 y*f.d2 y)) + (h := fun y => a^2*f.d1 y^3) f.lipschitz + (j.continuousD3.add (h12.const_mul _)) (h3.const_mul _) + (fun y => (abs_add_le _ _).trans (add_le_add (j.normD3 y) (hA y))) hB, + tiltedMean_add (g := j.d3) (h := fun y => 3*a*(f.d1 y*f.d2 y)) + f.lipschitz j.continuousD3 (h12.const_mul _) j.normD3 hA, + tiltedMean_const_mul,tiltedMean_const_mul] + +lemma hasDerivAt_transformD2 (j : ThirdJet f) (a s x : ℝ) : + HasDerivAt (f.transform a s).d2 (j.transformD3 a s x) x := by + have h2 := hasDerivAt_tiltedMean f j.hasD3 j.continuousD3 f.normD2 j.normD3 a s x + have hc : Continuous (fun y => 2*(f.d1 y*f.d2 y)) := + (f.continuousD1.mul f.continuousD2).const_mul 2 + have hn : ∀ y,|2*(f.d1 y*f.d2 y)|≤(2*f.bound1*f.bound2:ℝ≥0) := by + intro y + have hh := mul_le_mul_of_nonneg_left (product_bound (f := f) y) (by norm_num : (0:ℝ)≤2) + simpa only [abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2),NNReal.coe_mul,NNReal.coe_ofNat,mul_assoc] using hh + have hd : ∀ y,HasDerivAt (fun z => (f.d1 z)^2) (2*(f.d1 y*f.d2 y)) y := by + intro y + convert (f.hasD2 y).pow 2 using 1 + first | rfl | norm_num + ring + have hs := hasDerivAt_tiltedMean f hd hc (M := f.bound1^2) + (by simpa only [NNReal.coe_pow] using sq_bound f.normD1) hn a s x + have hh := h2.add ((hs.sub ((f.transform a s).hasD2 x |>.pow 2)).const_mul a) + convert! hh using 1 + rw [transformD3,expThird_tilt] + change _= _+ a*(_-2*(f.transform a s).d1 x ^ (2-1)*(f.transform a s).d2 x) + have hcub : (fun y => f.d1 y*f.d1 y^2)=(fun y => f.d1 y^3) := by + funext y;ring + rw [hcub,tiltedMean_const_mul] + simp only [SmoothField.transform] + ring + +lemma continuous_transformD3 (j : ThirdJet f) (a s : ℝ) : Continuous (j.transformD3 a s) := by + have hb : ∀ y,|j.expThird a y|≤ + (j.bound3+3*Real.nnabs a*(f.bound1*f.bound2)+(Real.nnabs a)^2*f.bound1^3:ℝ≥0) := by + intro y + simpa only [NNReal.coe_add,NNReal.coe_mul,NNReal.coe_ofNat,Real.coe_nnabs, + NNReal.coe_pow,sq_abs] using j.expThird_bound a y + have hE := continuous_tiltedMean f.lipschitz (j.continuous_expThird a) hb a s + have h1 := (f.transform a s).continuousD1 + have h2 := (f.transform a s).continuousD2 + unfold transformD3 + fun_prop + +lemma transformD3_bound (j : ThirdJet f) (a s x : ℝ) : + |j.transformD3 a s x|≤j.bound3+3*|a| *((f.bound1:ℝ)*f.bound2)+a^2*(f.bound1:ℝ)^3+ + 3*|a| *((f.bound1:ℝ)*(f.transform a s).bound2)+a^2*(f.bound1:ℝ)^3 := by + have ht := abs_tiltedMean_le f.lipschitz (j.continuous_expThird a) (j.expThird_bound a) a s x + have h12 := product_bound (f := f.transform a s) x + have h3 := cube_bound (f := f.transform a s) x + unfold transformD3 + apply (abs_sub _ _).trans + apply (add_le_add (abs_sub _ _) (le_refl _)).trans + norm_num only [abs_mul,abs_sq] + calc + _ ≤ (j.bound3+3*|a| *((f.bound1:ℝ)*f.bound2)+a^2*(f.bound1:ℝ)^3)+ + 3*|a| *((f.bound1:ℝ)*(f.transform a s).bound2)+a^2*(f.bound1:ℝ)^3 := by + gcongr <;> first | exact ht | exact (f.transform a s).normD1 x | exact (f.transform a s).normD2 x | exact h12 | exact h3 + _ = _ := rfl + +def transform (j : ThirdJet f) (a s : ℝ) : ThirdJet (f.transform a s) where + d3 := j.transformD3 a s + hasD3 := j.hasDerivAt_transformD2 a s + continuousD3 := j.continuous_transformD3 a s + bound3 := j.bound3+3*Real.nnabs a*(f.bound1*f.bound2)+(Real.nnabs a)^2*f.bound1^3+ + 3*Real.nnabs a*(f.bound1*(f.transform a s).bound2)+(Real.nnabs a)^2*f.bound1^3 + normD3 := fun x => by + simpa only [NNReal.coe_add,NNReal.coe_mul,NNReal.coe_ofNat,Real.coe_nnabs, + NNReal.coe_pow,sq_abs] using j.transformD3_bound a s x + +lemma expThird_transform (j : ThirdJet f) (a s x : ℝ) : + (j.transform a s).expThird a x=tiltedMean a s f.val (j.expThird a) x := by + dsimp only [expThird,transform,transformD3] + ring + +end ThirdJet +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/OrderedCode.lean b/lean/OAI/Probability/ParisiFinite/OrderedCode.lean new file mode 100644 index 0000000000000000000000000000000000000000..307b359e580a44adcc1f82fc6ab63721e3a62958 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/OrderedCode.lean @@ -0,0 +1,720 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ExpectedReindexStates + +namespace OAI + +/-! Ordered Code. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def orderedCode {r : ℕ} (c : OrderedFinpartition r) : Fin r → ℕ := fun i => (c.index i).val + +lemma orderedIndex_emb {r : ℕ} (c : OrderedFinpartition r) (i : Fin c.length) (j : Fin (c.partSize i)) : + c.index (c.emb i j)=i := by + exact congrArg Sigma.fst (c.equivSigma.symm_apply_apply ⟨i,j⟩) + +lemma codeLabels_orderedCode {r : ℕ} (c : OrderedFinpartition r) : + codeLabels (orderedCode c)=Finset.range c.length := by + ext x + simp only [codeLabels_mem,Finset.mem_range] + constructor + · rintro ⟨i,rfl⟩ + exact (c.index i).isLt + · intro hx + let i : Fin c.length := ⟨x,hx⟩ + refine ⟨c.emb i ⟨0,c.partSize_pos i⟩,?_⟩ + unfold orderedCode + rw [orderedIndex_emb] + +lemma labelCount_orderedCode {r : ℕ} (c : OrderedFinpartition r) (i : Fin c.length) : + labelCount (orderedCode c) i=c.partSize i := by + have hc : labelCount (orderedCode c) i=∑ j : Fin r,if (c.index j).val=i.val then 1 else 0 := by + classical + simp [labelCount,orderedCode] + rfl + rw [hc,← c.sum_sigma_eq_sum] + simp only [orderedIndex_emb,Fin.val_inj] + simp + +lemma partitionNumerator_ordered {r : ℕ} (a : ℝ) (c : OrderedFinpartition r) : + partitionNumerator a (orderedCode c)= + tableFactor a c.length*∏ i,blockFactor a (c.partSize i) := by + unfold partitionNumerator + rw [codeLabels_orderedCode,Finset.card_range,← Fin.prod_univ_eq_prod_range] + simp_rw [labelCount_orderedCode] + +lemma tableFactor_explicit (a : ℝ) {k : ℕ} (hk : 0 omega + | succ k ih => + by_cases h : k=0 + · subst k; simp + have hk' := Nat.pos_of_ne_zero h + rw [tableFactor_succ a hk',ih hk'] + simp only [Nat.add_sub_cancel] + have hf : (k.factorial:ℝ)=(k:ℝ)*((k-1).factorial:ℝ) := by + exact_mod_cast (Nat.mul_factorial_pred h).symm + have hp : a^k=a^(k-1)*a := by rw [← pow_succ,Nat.sub_add_cancel hk'] + rw [hf,hp] + ring + + + +theorem GG_ordered_partition_probability {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) {r : ℕ} (hr : 0 simp [iteratedDeriv_one,Real.deriv_log] + | succ n ih => + rw [iteratedDeriv_succ] + have he : iteratedDeriv (n+1) Real.log =ᶠ[𝓝 x] + (fun y => (-1:ℝ)^n*(n.factorial:ℝ)*y^(-(n:ℤ)-1)) := by + filter_upwards [eventually_ne_nhds hx] with y hy + exact ih hy + rw [he.deriv_eq] + have hd := (hasDerivAt_zpow (-(n:ℤ)-1) x (Or.inl hx)).const_mul + ((-1:ℝ)^n*(n.factorial:ℝ)) + rw [hd.deriv,pow_succ,Nat.factorial_succ] + push_cast + have hz : -(n+1:ℤ)-1= -(n:ℤ)-1-1 := by omega + rw [hz] + ring + +lemma iteratedDeriv_log_one {n : ℕ} (hn : 0 a⁻¹*Real.log (finiteMarkTransform a w x z)) 0= + -∑ c : OrderedFinpartition n,tableFactor a c.length* + ∏ j,blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j) := by + rw [iteratedDeriv_const_mul_field] + have hz := finiteMarkTransform_zero a w x hw + have hg : ContDiffAt ℝ n Real.log (finiteMarkTransform a w x 0) := by + rw [hz] + exact Real.contDiffAt_log.mpr (by norm_num) + have h := iteratedDeriv_scomp_eq_sum_orderedFinpartition hg (contDiffAt_mark a w x n) (i:=n) le_rfl + change iteratedDeriv n (fun z => Real.log (finiteMarkTransform a w x z)) 0=_ at h + rw [h,Finset.mul_sum,← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro c _ + simp only [iteratedDeriv_mark a w x (c.partSize_pos _),hz, + iteratedDeriv_log_one (c.length_pos hn),smul_eq_mul] + have he : (∏ j,-a*blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j))= + (-a)^c.length*∏ j,blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j) := by + calc + _ = ∏ j : Fin c.length,(-a)*(blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j)) := by + apply Finset.prod_congr rfl + intro j _ + ring + _ = _ := by rw [Finset.prod_mul_distrib]; simp + rw [he] + have hh := signed_log_factor ha (c.length_pos hn) + linear_combination (∏ j,blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j))*hh + +def orderedMarkedMoment (μ : ProbabilityMeasure OverlapArray) (q : ℝ) + (moments : ℕ → ℝ) (r : ℕ) : ℝ := + ∑ c : OrderedFinpartition r,(μ:Measure OverlapArray).real (partitionEvent (orderedCode c) q)* + ∏ j,moments (c.partSize j) + + + +theorem GG_marked_log_derivative {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) (ha : overlapDiscount μ q≠0) + (w x : ι → ℝ) (hw : ∑ i,w i=1) {n : ℕ} (hn : 0 (overlapDiscount μ q)⁻¹* + Real.log (finiteMarkTransform (overlapDiscount μ q) w x z)) 0= + -((n-1).factorial:ℝ)*orderedMarkedMoment μ q (finiteMarkMoment w x) n := by + rw [log_mark_derivative ha w x hw hn] + unfold orderedMarkedMoment + simp only [Finset.mul_sum,← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro c _ + have he := GG_partition_EPPF hG hgg hu hq hn (orderedCode c) + rw [partitionNumerator_ordered] at he + have hp : (∏ j,blockFactor (overlapDiscount μ q) (c.partSize j)*finiteMarkMoment w x (c.partSize j))= + (∏ j,blockFactor (overlapDiscount μ q) (c.partSize j))*(∏ j,finiteMarkMoment w x (c.partSize j)) := + Finset.prod_mul_distrib + rw [hp] + linear_combination (∏ j,finiteMarkMoment w x (c.partSize j))*he + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def branchFactor (a b : ℝ) (k : ℕ) : ℝ := + ∏ j∈Finset.range (k-1),(a*((j:ℝ)+1)-b) + +@[simp] lemma branchFactor_one (a b : ℝ) : branchFactor a b 1=1 := by simp [branchFactor] +lemma branchFactor_zero (a : ℝ) (k : ℕ) : branchFactor a 0 k=tableFactor a k := by + simp [branchFactor,tableFactor] +lemma branchFactor_succ (a b : ℝ) {k : ℕ} (hk : 0 omega + | succ k ih => + by_cases hk0 : k=0 + · subst k + simp [fallingCoeff_succ] + field_simp + have hk' := Nat.pos_of_ne_zero hk0 + rw [pow_succ,fallingCoeff_succ,branchFactor_succ a b hk'] + have he := ih hk' + have hab : (-a)*(b/a-k)=a*k-b := by field_simp; ring + calc + (-a)^k*(-a)*(fallingCoeff (b/a) k*(b/a-k))= + ((-a)^k*fallingCoeff (b/a) k)*((-a)*(b/a-k)) := by ring + _ = _ := by rw [he,hab]; ring + +lemma iteratedDeriv_rpow_one (a : ℝ) (n : ℕ) : + iteratedDeriv n (fun y : ℝ => y^a) 1=fallingCoeff a n := by + have h := iteratedDeriv_affine_rpow_zero a (-1) n + have he : (fun z : ℝ => (1-z*(-1))^a)=(fun z => (fun y : ℝ => y^a) (z+1)) := by + ext z; congr 1; ring + rw [he] at h + have ht := congrFun (iteratedDeriv_comp_add_const (f:=fun y : ℝ => y^a) (n:=n) (s:=1)) 0 + rw [ht] at h + simpa using h + +variable {ι : Type*} [Fintype ι] + + + +lemma power_mark_derivative {a : ℝ} (ha : a≠0) (b : ℝ) (w x : ι → ℝ) + (hw : ∑ i,w i=1) {n : ℕ} (hn : 0 (finiteMarkTransform a w x z)^(b/a)) 0= + -b*∑ c : OrderedFinpartition n,branchFactor a b c.length* + ∏ j,blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j) := by + have hz := finiteMarkTransform_zero a w x hw + have hg : ContDiffAt ℝ n (fun y : ℝ => y^(b/a)) (finiteMarkTransform a w x 0) := by + apply ContDiffAt.rpow_const_of_ne + · fun_prop + · rw [hz]; norm_num + have h := iteratedDeriv_scomp_eq_sum_orderedFinpartition hg (contDiffAt_mark a w x n) (i:=n) le_rfl + change iteratedDeriv n (fun z => (finiteMarkTransform a w x z)^(b/a)) 0=_ at h + rw [h,Finset.mul_sum] + apply Finset.sum_congr rfl + intro c _ + simp only [iteratedDeriv_mark a w x (c.partSize_pos _),hz,iteratedDeriv_rpow_one,smul_eq_mul] + have he : (∏ j,-a*blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j))= + (-a)^c.length*∏ j,blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j) := by + calc + _ = ∏ j : Fin c.length,(-a)*(blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j)) := by + apply Finset.prod_congr rfl + intro j _ + ring + _ = _ := by rw [Finset.prod_mul_distrib]; simp + rw [he] + have hh := signed_power_factor ha b (c.length_pos hn) + linear_combination (∏ j,blockFactor a (c.partSize j)*finiteMarkMoment w x (c.partSize j))*hh + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +theorem GG_join_on_block {μ : ProbabilityMeasure OverlapArray} (hgg : GGIdentities μ) + {r : ℕ} {S : Set (OverlapBlock r)} (hS : MeasurableSet S) + (c : Fin r → ℕ) (q : ℝ) (hc : S⊆partitionBlock c q) (i : Fin r) : + (r:ℝ)*(μ:Measure OverlapArray).real {R | blockOfArray r R∈S ∧ q<(R i r:ℝ)}= + ((clusterCount c i:ℝ)-overlapDiscount μ q)* + (μ:Measure OverlapArray).real ((blockOfArray r) ⁻¹' S) := by + let E := (blockOfArray r) ⁻¹' S + have h := GG_event_identity hgg r i S {x | q<(x:ℝ)} hS + (measurableSet_lt measurable_const (by fun_prop)) + change (r:ℝ)*(μ:Measure OverlapArray).real {R | R∈E ∧ q<(R i r:ℝ)}= + (μ:Measure OverlapArray).real E*(entryLaw μ 0 1).real {x | q<(x:ℝ)}+ + ∑ l∈Finset.univ.erase i,(μ:Measure OverlapArray).real {R | R∈E ∧ q<(R i l:ℝ)} at h + have hp (l : Fin r) : {R | R∈E ∧ q<(R i l:ℝ)}=if c i=c l then E else ∅ := by + split_ifs with hh + · ext R + exact ⟨fun hR => hR.1,fun hR => ⟨hR,(hc hR i l).mpr hh⟩⟩ + · ext R + simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] + exact fun hR => hh ((hc hR.1 i l).mp hR.2) + simp_rw [hp] at h + simp only [apply_ite,measureReal_empty] at h + have hs : (∑ l∈Finset.univ.erase i,if c i=c l then (μ:Measure OverlapArray).real E else 0)= + ((clusterCount c i:ℝ)-1)*(μ:Measure OverlapArray).real E := by + have hj : (∑ l : Fin r,if c i=c l then (μ:Measure OverlapArray).real E else 0)= + (clusterCount c i:ℝ)*(μ:Measure OverlapArray).real E := by + simp only [← Finset.sum_filter,Finset.sum_const,nsmul_eq_mul] + congr 2 + apply congrArg Finset.card + ext l + simp only [Finset.mem_filter,Finset.mem_univ,true_and,eq_comm] + have hh := Finset.sum_erase_add (s:=Finset.univ) + (f:=fun l => if c i=c l then (μ:Measure OverlapArray).real E else 0) (Finset.mem_univ i) + simp only [ite_true] at hh + rw [hj] at hh + linarith + rw [hs,entry_upper_mass] at h + calc + _ = (μ:Measure OverlapArray).real E*(1-overlapDiscount μ q)+ + ((clusterCount c i:ℝ)-1)*(μ:Measure OverlapArray).real E := h + _ = _ := by dsimp only [E]; ring + +def ParentReps {r : ℕ} (p c : Fin r → ℕ) (i : Fin r) (T : Finset (Fin r)) : Prop := + Set.InjOn c T ∧ (∀ k∈T,p k=p i) ∧ (∀ j,p j=p i ↔ ∃ k∈T,c k=c j) + +lemma sum_parent_clusterCount {r : ℕ} {p c : Fin r → ℕ} {i : Fin r} + {T : Finset (Fin r)} (hT : ParentReps p c i T) : + (∑ k∈T,clusterCount c k)=clusterCount p i := by + have hc (d : Fin r → ℕ) (k) : clusterCount d k=∑ j : Fin r,if d j=d k then 1 else 0 := by + simp [clusterCount] + simp_rw [hc] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + by_cases hj : p j=p i + · obtain ⟨k,hk,hkj⟩ := (hT.2.2 j).mp hj + rw [ite_eq_left hj,Finset.sum_eq_single k] + · simp [hkj] + · intro l hl hlk + have hne : c j≠c l := fun hh => hlk (hT.1 hl hk (hh.symm.trans hkj.symm)) + simp [hne] + · exact fun hh => (hh hk).elim + · rw [ite_eq_right hj] + apply Finset.sum_eq_zero + intro k hk + have hne : c j≠c k := fun h => hj ((hT.2.2 j).mpr ⟨k,hk,h.symm⟩) + simp [hne] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +theorem GG_nested_innovation {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {r : ℕ} {S : Set (OverlapBlock r)} (hS : MeasurableSet S) + {p c : Fin r → ℕ} {q t : ℝ} (hqt : q≤t) + (hp : S⊆partitionBlock p q) (hc : S⊆partitionBlock c t) + (i : Fin r) {T : Finset (Fin r)} (hT : ParentReps p c i T) : + (r:ℝ)*(μ:Measure OverlapArray).real + {R | blockOfArray r R∈S ∧ q<(R i r:ℝ) ∧ ∀ k∈T,(R k r:ℝ)≤t}= + ((T.card:ℝ)*overlapDiscount μ t-overlapDiscount μ q)* + (μ:Measure OverlapArray).real ((blockOfArray r) ⁻¹' S) := by + let U := GramArrays∩UltrametricArrays + let E := (blockOfArray r) ⁻¹' S + let P : Set OverlapArray := {R | R∈E ∧ q<(R i r:ℝ)} + let J (k : Fin r) : Set OverlapArray := {R | R∈E ∧ t<(R k r:ℝ)} + let A : Set OverlapArray := ⋃ k∈T,J k + have hUa : ∀ᵐ R ∂(μ:Measure OverlapArray),R∈U := + (ae_full_probability μ isClosed_GramArrays.measurableSet hG).and + (ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu) + have hUr (V : Set OverlapArray) : (μ:Measure OverlapArray).real (U∩V)=(μ:Measure OverlapArray).real V := + congrArg ENNReal.toReal (Measure.measure_inter_eq_of_ae hUa) + have hE : MeasurableSet E := hS.preimage (continuous_blockOfArray r).measurable + have hJ (k : Fin r) : MeasurableSet (J k) := by + change MeasurableSet (E∩{R : OverlapArray | t<(R k r:ℝ)}) + exact hE.inter (measurableSet_lt measurable_const (by fun_prop)) + have hA : MeasurableSet A := MeasurableSet.iUnion fun k => MeasurableSet.iUnion fun _ => hJ k + have hUP : U∩A⊆U∩P := by + rintro R ⟨hR,hRA⟩ + obtain ⟨k,hRA⟩ := Set.mem_iUnion.mp hRA + obtain ⟨hk,hRk⟩ := Set.mem_iUnion.mp hRA + refine ⟨hR,hRk.1,?_⟩ + have hik : q<(R i k:ℝ) := (hp hRk.1 i k).mpr (hT.2.1 k hk).symm + have hkr : q<(R k r:ℝ) := hqt.trans_lt hRk.2 + have hh := hR.2 i r k + rw [hR.1.1 r k] at hh + exact (lt_min hik hkr).trans_le hh + have hdis : Set.PairwiseDisjoint (T:Set (Fin r)) (fun k => U∩J k) := by + intro k hk l hl hkl + apply Set.disjoint_left.mpr + intro R hRk hRl + have hne : c k≠c l := fun h => hkl (hT.1 hk hl h) + exact hne ((hc hRk.2.1 k l).mp ((lt_min hRk.2.2 hRl.2.2).trans_le (hRk.1.2 k l r))) + have hsum : (μ:Measure OverlapArray).real A=∑ k∈T,(μ:Measure OverlapArray).real (J k) := by + rw [← hUr A] + have he : U∩A=⋃ k∈T,U∩J k := by ext R; simp only [A,Set.mem_inter_iff,Set.mem_iUnion]; aesop + rw [he,measureReal_biUnion_finset hdis (fun k _ => + (isClosed_GramArrays.measurableSet.inter isClosed_UltrametricArrays.measurableSet).inter (hJ k))] + exact Finset.sum_congr rfl fun k _ => hUr (J k) + have he : {R | blockOfArray r R∈S ∧ q<(R i r:ℝ) ∧ ∀ k∈T,(R k r:ℝ)≤t}=P\A := by + ext R + simp only [P,A,J,E,Set.mem_ofPred_eq,Set.mem_sdiff,Set.mem_iUnion,Set.mem_preimage] + constructor + · rintro ⟨hE,hP,hnew⟩ + exact ⟨⟨hE,hP⟩,fun ⟨k,hk,_,hkr⟩ => (not_lt_of_ge (hnew k hk)) hkr⟩ + · rintro ⟨⟨hE,hP⟩,hnot⟩ + exact ⟨hE,hP,fun k hk => le_of_not_gt (fun h => hnot ⟨k,hk,hE,h⟩)⟩ + have hdiff : (μ:Measure OverlapArray).real (P\A)= + (μ:Measure OverlapArray).real P-(μ:Measure OverlapArray).real A := by + rw [← hUr (P\A)] + have hh : U∩(P\A)=(U∩P)\(U∩A) := by ext R; simp only [Set.mem_inter_iff,Set.mem_sdiff]; aesop + rw [hh,measureReal_sdiff hUP ((isClosed_GramArrays.measurableSet.inter + isClosed_UltrametricArrays.measurableSet).inter hA),hUr P,hUr A] + rw [he,hdiff,hsum] + have hjoin := GG_join_on_block hgg hS p q hp i + have hjoins := Finset.sum_congr (s₁:=T) (s₂:=T) rfl + (fun k _ => GG_join_on_block hgg hS c t hc k) + rw [← Finset.mul_sum] at hjoins + simp_rw [sub_mul] at hjoins + rw [Finset.sum_sub_distrib,← Finset.sum_mul,Finset.sum_const,nsmul_eq_mul] at hjoins + have hcount : (∑ k∈T,(clusterCount c k:ℝ))=(clusterCount p i:ℝ) := by + exact_mod_cast sum_parent_clusterCount hT + rw [hcount] at hjoins + change (r:ℝ)*(μ:Measure OverlapArray).real P=_ at hjoin + change (r:ℝ)*(∑ k∈T,(μ:Measure OverlapArray).real (J k))=_ at hjoins + change (r:ℝ)*((μ:Measure OverlapArray).real P-∑ k∈T,(μ:Measure OverlapArray).real (J k))=_ + linear_combination hjoin-hjoins + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma log_power_affine_derivative {a : ℝ} (ha : a≠0) {n : ℕ} (hn : 0 a⁻¹*Real.log ((1-z)^a)) 0= -((n-1).factorial:ℝ) := by + have he : (fun z : ℝ => a⁻¹*Real.log ((1-z)^a))=ᶠ[𝓝 0] (fun z => Real.log (1-z)) := by + filter_upwards [(isOpen_Iio.mem_nhds (show (0:ℝ)<1 by norm_num))] with z hz + rw [Real.log_rpow (sub_pos.mpr hz)] + field_simp + rw [he.iteratedDeriv_eq n] + have ht := congrFun (iteratedDeriv_comp_const_sub n Real.log 1) 0 + rw [ht] + simp only [sub_zero,smul_eq_mul,iteratedDeriv_log_one hn] + have hs : (-1:ℝ)^n*(-1:ℝ)^n=1 := by rw [← mul_pow]; norm_num + calc + (-1:ℝ)^n*(-(-1:ℝ)^n*((n-1).factorial:ℝ))= + -((-1:ℝ)^n*(-1:ℝ)^n)*((n-1).factorial:ℝ) := by ring + _ = _ := by rw [hs]; ring + + + +lemma ordered_partition_mass {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) (ha : overlapDiscount μ q≠0) {n : ℕ} (hn : 0 1) (fun _ => 1) + (by simp) hn + have ht : finiteMarkTransform (overlapDiscount μ q) (fun _ : Fin 1 => 1) (fun _ => 1)= + (fun z : ℝ => (1-z)^(overlapDiscount μ q)) := by + funext z + simp [finiteMarkTransform] + rw [ht,log_power_affine_derivative ha hn] at h + simp only [orderedMarkedMoment,finiteMarkMoment,one_pow,Fin.sum_univ_one, + Finset.prod_const_one,mul_one] at h + have hf : ((n-1).factorial:ℝ)≠0 := Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _) + exact (mul_left_cancel₀ (neg_ne_zero.mpr hf) (by simpa using h.symm)) + +lemma ordered_partSize_sum {n : ℕ} (c : OrderedFinpartition n) : ∑ j,c.partSize j=n := by + have h := c.sum_sigma_eq_sum (fun _ : Fin n => (1:ℕ)) + simpa using h + +variable {ι : Type*} [Fintype ι] +lemma finiteMarkMoment_nonneg (w x : ι → ℝ) (hw : ∀ i,0≤w i) (hx : ∀ i,0≤x i) (n : ℕ) : + 0≤finiteMarkMoment w x n := Finset.sum_nonneg fun i _ => mul_nonneg (hw i) (pow_nonneg (hx i) n) + +lemma finiteMarkMoment_le {w x : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {v : ℝ} (hx : ∀ i,0≤x i ∧ x i≤v) (n : ℕ) : finiteMarkMoment w x n≤v^n := by + calc + _ ≤ ∑ i,w i*v^n := Finset.sum_le_sum fun i _ => + mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (hx i).1 (hx i).2 n) (hw i) + _ = _ := by rw [← Finset.sum_mul,hs,one_mul] + +lemma orderedMarkedMoment_nonneg (μ : ProbabilityMeasure OverlapArray) (q : ℝ) + {moments : ℕ → ℝ} (hm : ∀ n,0 ≤ moments n) (n : ℕ) : + 0≤orderedMarkedMoment μ q moments n := by + apply Finset.sum_nonneg + intro c _ + exact mul_nonneg measureReal_nonneg (Finset.prod_nonneg fun _ _ => hm _) + +lemma orderedMarkedMoment_le {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) (ha : overlapDiscount μ q≠0) {n : ℕ} (hn : 0 (hm _).1) (fun j _ => (hm _).2) + _ = v^(∑ j,c.partSize j) := Finset.prod_pow_eq_pow_sum _ _ _ + _ = _ := by rw [ordered_partSize_sum] + change (∑ c : OrderedFinpartition n,_ )≤_ + calc + _ ≤ ∑ c : OrderedFinpartition n,(μ:Measure OverlapArray).real (partitionEvent (orderedCode c) q)*v^n := + Finset.sum_le_sum fun c _ => mul_le_mul_of_nonneg_left (hp c) measureReal_nonneg + _ = _ := by rw [← Finset.sum_mul,ordered_partition_mass hG hgg hu hq ha hn,one_mul] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +variable {ι : Type*} [Fintype ι] +def markedLogSeries (μ : ProbabilityMeasure OverlapArray) (q : ℝ) (w x : ι → ℝ) : + FormalMultilinearSeries ℝ ℝ ℝ := + FormalMultilinearSeries.ofScalars ℝ (fun n => -orderedMarkedMoment μ q (finiteMarkMoment w x) n/(n:ℝ)) + +lemma markedLog_hasFPowerSeriesAt {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) (ha : overlapDiscount μ q≠0) + (w x : ι → ℝ) (hw : ∑ i,w i=1) : + HasFPowerSeriesAt (fun z => (overlapDiscount μ q)⁻¹* + Real.log (finiteMarkTransform (overlapDiscount μ q) w x z)) (markedLogSeries μ q w x) 0 := by + have hz := finiteMarkTransform_zero (overlapDiscount μ q) w x hw + have hf : ContDiffAt ℝ ω (fun z => (overlapDiscount μ q)⁻¹* + Real.log (finiteMarkTransform (overlapDiscount μ q) w x z)) 0 := by + apply contDiffAt_const.mul + apply (Real.contDiffAt_log.mpr _).comp 0 (contDiffAt_mark _ w x ω) + rw [hz]; norm_num + have h := hf.analyticAt.hasFPowerSeriesAt + have he : (fun n => iteratedDeriv n (fun z => (overlapDiscount μ q)⁻¹* + Real.log (finiteMarkTransform (overlapDiscount μ q) w x z)) 0/(n.factorial:ℝ))= + (fun n => -orderedMarkedMoment μ q (finiteMarkMoment w x) n/(n:ℝ)) := by + funext n + by_cases hn : n=0 + · subst n + simp [hz] + · have hn' := Nat.pos_of_ne_zero hn + rw [GG_marked_log_derivative hG hgg hu hq ha w x hw hn'] + have hf : (n.factorial:ℝ)=(n:ℝ)*((n-1).factorial:ℝ) := by + exact_mod_cast (Nat.mul_factorial_pred hn).symm + have hf0 : ((n-1).factorial:ℝ)≠0 := Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _) + have hn0 : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr hn + rw [hf] + field_simp + rw [he] at h + exact h + +lemma markedLogSeries_radius {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) (ha : overlapDiscount μ q≠0) + {w x : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) (hx : ∀ i,0≤x i ∧ x i≤1) : + (1:ℝ≥0∞)≤(markedLogSeries μ q w x).radius := by + apply FormalMultilinearSeries.le_radius_of_bound (C:=1) (r:=1) + intro n + simp only [markedLogSeries,FormalMultilinearSeries.ofScalars,norm_smul, + NNReal.coe_one,one_pow,mul_one,Real.norm_eq_abs,abs_div,abs_neg] + rw [show |(n:ℝ)|=(n:ℝ) from abs_of_nonneg (Nat.cast_nonneg n)] + by_cases hn : n=0 + · simp [hn] + have hn' := Nat.pos_of_ne_zero hn + have hm : ∀ k,0≤finiteMarkMoment w x k ∧ finiteMarkMoment w x k≤(1:ℝ)^k := fun k => + ⟨finiteMarkMoment_nonneg w x hw (fun i => (hx i).1) k,finiteMarkMoment_le hw hs hx k⟩ + have hnon := orderedMarkedMoment_nonneg μ q (fun k => (hm k).1) n + have hle := orderedMarkedMoment_le hG hgg hu hq ha hn' hm + simp only [one_pow] at hle + rw [abs_of_nonneg hnon] + have hn1 : (1:ℝ)≤n := by exact_mod_cast hn' + have hnorm : ‖ContinuousMultilinearMap.mkPiAlgebraFin ℝ n ℝ‖≤1 := by + apply le_trans ContinuousMultilinearMap.norm_mkPiAlgebraFin_le + norm_num + calc + _ ≤ (1:ℝ)/(n:ℝ)*1 := mul_le_mul (div_le_div_of_nonneg_right hle (Nat.cast_nonneg _)) hnorm + (norm_nonneg _) (by positivity) + _ ≤ 1 := by rw [mul_one]; exact (div_le_one (by positivity)).mpr hn1 + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] + +lemma affine_mark_pos {x z : ℝ} (hx : 0≤x ∧ x≤1) (hz : |z|<1) : 0<1-z*x := by + have h : z*x≤|z| := calc + z*x ≤ |z| *x := mul_le_mul_of_nonneg_right (le_abs_self _) hx.1 + _ ≤ |z| *1 := mul_le_mul_of_nonneg_left hx.2 (abs_nonneg _) + _ = _ := mul_one _ + linarith + +lemma finiteMarkTransform_pos (a : ℝ) {w x : ι → ℝ} + (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) (hx : ∀ i,0≤x i ∧ x i≤1) + {z : ℝ} (hz : |z|<1) : 0 h i) + rw [hs] at hnon + linarith + obtain ⟨i,hi⟩ := hex + apply Finset.sum_pos' + · intro i _ + exact mul_nonneg (hw i) (Real.rpow_nonneg (le_of_lt (affine_mark_pos (hx i) hz)) a) + · exact ⟨i,Finset.mem_univ _,mul_pos hi (Real.rpow_pos_of_pos (affine_mark_pos (hx i) hz) a)⟩ + +lemma contDiffAt_mark_of_abs_lt (a : ℝ) {w x : ι → ℝ} + (hx : ∀ i,0≤x i ∧ x i≤1) {z : ℝ} (hz : |z|<1) (n : ℕ∞ω) : + ContDiffAt ℝ n (finiteMarkTransform a w x) z := by + apply ContDiffAt.sum + intro i _ + apply contDiffAt_const.mul + apply ContDiffAt.rpow_const_of_ne + · fun_prop + · exact ne_of_gt (affine_mark_pos (hx i) hz) + + + +theorem GG_marked_log_identity {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) (ha : overlapDiscount μ q≠0) + {w x : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) (hx : ∀ i,0≤x i ∧ x i≤1) + {z : ℝ} (hz : |z|<1) : + (overlapDiscount μ q)⁻¹*Real.log (finiteMarkTransform (overlapDiscount μ q) w x z)= + (markedLogSeries μ q w x).sum z := by + let f : ℝ → ℝ := fun z => (overlapDiscount μ q)⁻¹* + Real.log (finiteMarkTransform (overlapDiscount μ q) w x z) + let p := markedLogSeries μ q w x + have hr : (1:ℝ≥0∞)≤p.radius := markedLogSeries_radius hG hgg hu hq ha hw hs hx + have hf : AnalyticOnNhd ℝ f (Set.Ioo (-1) 1) := by + intro t ht + have ht' : |t|<1 := abs_lt.mpr ht + apply ContDiffAt.analyticAt + apply contDiffAt_const.mul + exact (Real.contDiffAt_log.mpr (ne_of_gt (finiteMarkTransform_pos _ hw hs hx ht'))).comp t + (contDiffAt_mark_of_abs_lt _ hx ht' ω) + have hp : AnalyticOnNhd ℝ p.sum (Set.Ioo (-1) 1) := by + intro t ht + apply p.analyticOnNhd + apply lt_of_lt_of_le _ hr + rw [edist_zero_right,← ofReal_norm] + exact ENNReal.ofReal_lt_one.mpr (abs_lt.mpr ht) + have he : f=ᶠ[𝓝 0] p.sum := by + filter_upwards [(markedLog_hasFPowerSeriesAt hG hgg hu hq ha w x hs).eventually_hasSum] with t ht + simpa only [zero_add, f, p, FormalMultilinearSeries.sum] using ht.tsum_eq.symm + exact hf.eqOn_of_preconnected_of_eventuallyEq hp isPreconnected_Ioo (by constructor <;> norm_num) + he (abs_lt.mp hz) + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/OrdinaryInverseSpecial.lean b/lean/OAI/Probability/ParisiFinite/OrdinaryInverseSpecial.lean new file mode 100644 index 0000000000000000000000000000000000000000..3052a546e0cdacb295db39f191da988b03e20eb1 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/OrdinaryInverseSpecial.lean @@ -0,0 +1,690 @@ +import Mathlib +import OAI.Probability.ParisiFinite.InsertionFromForward + +namespace OAI + +/-! Ordinary Inverse Special. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem ordinary_inverse_special (γ : ℝ) (v e : E) (x : SpinSpace E) : + (ordinaryMap γ (Real.pi/4) v e).symm + (SpinOperators.act Z (specialMap γ (Real.pi/4) v e x))= + (-I*phase (-(γ • (v-e))) ((-γ) • (v+e))) • + SpinOperators.act Z (WZ ((-2*γ) • v) x) := by + change WZ (-(γ • (v-e))) ((SpinOperators.actEquiv (R (Real.pi/4)) (R_unitary _)).symm + (SpinOperators.act Z (specialMap γ (Real.pi/4) v e x)))=_ + rw [SpinOperators.actEquiv_symm_apply,specialMap_apply] + change WZ (-(γ • (v-e))) + (((SpinOperators.act (R (Real.pi/4)).conjTranspose).comp (SpinOperators.act Z)).comp + ((SpinOperators.act (R (Real.pi/4))).comp (SpinOperators.act X)) + (WZ ((-γ) • (v+e)) x))=_ + rw [← SpinOperators.act_mul,← SpinOperators.act_mul,← SpinOperators.act_mul, + ← mul_assoc,R_quarter_conjugate_Z,Y_mul_X] + change WZ (-(γ • (v-e))) ((SpinOperators.rep ((-I) • Z)) + (WZ ((-γ) • (v+e)) x))=_ + rw [map_smul] + simp only [SpinOperators.rep_apply,smul_apply,map_smul] + change (-I) • (WZ (-(γ • (v-e)))).comp (SpinOperators.act Z) + (WZ ((-γ) • (v+e)) x)=_ + rw [WZ_rootZ] + change (-I) • SpinOperators.act Z + ((WZ (-(γ • (v-e)))).comp (WZ ((-γ) • (v+e))) x)=_ + rw [WZ_mul] + simp only [smul_apply,map_smul,smul_smul] + have hd : -(γ • (v-e))+(-γ) • (v+e)=(-2*γ) • v := by module + rw [hd] + +def leading (γ : ℝ) (v : E) : SpinSpace E := + SpinOperators.act Z (WZ ((-2*γ) • v) (vacuum E)) + +@[simp] theorem norm_leading (γ : ℝ) (v : E) : ‖leading γ v‖=1 := by + rw [leading,SpinOperators.norm_act Z_unitary,norm_WZ,norm_vacuum] + +def leadingCoefficient (γ δ : ℝ) (v e : E) : ℂ := + star (ordinaryCoefficient γ δ v e)*specialPhase γ v e* + (-I*phase (-(γ • (v-e))) ((-γ) • (v+e))) + +@[simp] theorem norm_leadingCoefficient (γ δ : ℝ) (v e : E) : + ‖leadingCoefficient γ δ v e‖=|Real.cos δ| := by + simp only [leadingCoefficient,norm_mul,norm_specialPhase,norm_neg,Complex.norm_I, + norm_phase,norm_star,ordinaryCoefficient,Complex.norm_real, + Real.norm_eq_abs,mul_one] + +theorem address_remainder_bound (γ δ : ℝ) (v e : E) : + ‖address γ δ v e-leadingCoefficient γ δ v e • leading γ v‖≤|Real.sin δ| := by + have h := UnitarySplit.inverse (initialMap γ δ (Real.pi/4) v e) + (ordinaryMap γ (Real.pi/4) v e) (specialMap γ (Real.pi/4) v e) + (ordinaryCoefficient γ δ v e) (specialCoefficient γ δ v e) + (exact_split γ δ (Real.pi/4) v e) + (SpinOperators.act Z (specialPhase γ v e • specialMap γ (Real.pi/4) v e (vacuum E))) + change address γ δ v e=_ at h + have hf : star (ordinaryCoefficient γ δ v e) • + (ordinaryMap γ (Real.pi/4) v e).symm + (SpinOperators.act Z (specialPhase γ v e • specialMap γ (Real.pi/4) v e (vacuum E)))= + leadingCoefficient γ δ v e • leading γ v := by + simp only [map_smul,ordinary_inverse_special,smul_smul,← mul_assoc,leadingCoefficient,leading] + rw [h,hf,add_sub_cancel_left,norm_smul,norm_star,LinearIsometryEquiv.norm_map, + SpinOperators.norm_act Z_unitary,norm_smul,norm_specialPhase,LinearIsometryEquiv.norm_map, + norm_vacuum,mul_one,mul_one] + simp only [specialCoefficient,norm_mul,norm_neg,Complex.norm_I,Complex.norm_real, + norm_phase,one_mul,mul_one,Real.norm_eq_abs,le_refl] + +end SeedInitialization + +namespace PointedTree +open CoherentFock RootSpin Complex +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +theorem rootZ_WZ_vac_pair (d : H) : SpinOperators.act Z (WZ d (vacuum H))= + spinPair (spinCoefficient • coherent d) (-(spinCoefficient • coherent (-d))) := by + ext i + fin_cases i <;> simp [Z,spinPair,WZ_apply,vacuum_apply,spinCoefficient] + +theorem inner_rootY_WZ_rootZ_WZ (d f : H) : + ⟪SpinOperators.act Y (WZ d (vacuum H)),SpinOperators.act Z (WZ f (vacuum H))⟫_ℂ= + I*kernel (-d) f := by + rw [rootY_WZ_vac_pair,rootZ_WZ_vac_pair,inner_spinPair] + simp only [inner_smul_left,inner_smul_right,inner_neg_right, + inner_coherent,spinCoefficient_conj,map_mul,map_neg,Complex.conj_I] + have hk : kernel d (-f)=kernel (-d) f := by + have hn : ‖-d-f‖=‖d+f‖ := by rw [show -d-f=-(d+f) by module,norm_neg] + simp [kernel_eq,inner_neg_left,inner_neg_right,hn] + rw [hk] + linear_combination 2*I*kernel (-d) f*spinCoefficient_sq + +theorem norm_inner_high_leading (γ : ℝ) (v e : H) : + ‖⟪SpinOperators.act Y (WZ ((-2*γ:ℝ) • e) (vacuum H)), + SeedInitialization.leading γ v⟫_ℂ‖= + Real.exp (-‖(2*γ:ℝ) • (e+v)‖^2/2) := by + rw [SeedInitialization.leading,inner_rootY_WZ_rootZ_WZ,norm_mul, + norm_I,one_mul,norm_kernel] + congr 3 + have h : -((-2*γ:ℝ) • e)-(-2*γ:ℝ) • v=(2*γ:ℝ) • (e+v) := by module + rw [h] + +end PointedTree + +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem norm_inner_address_bound (γ δ : ℝ) (v e : E) (x : SpinSpace E) : + ‖⟪x,address γ δ v e⟫_ℂ‖≤‖x‖*|Real.sin δ|+ + |Real.cos δ| *‖⟪x,leading γ v⟫_ℂ‖ := by + have he : address γ δ v e=(address γ δ v e-leadingCoefficient γ δ v e • leading γ v)+ + leadingCoefficient γ δ v e • leading γ v := (sub_add_cancel _ _).symm + calc + _ = ‖⟪x,address γ δ v e-leadingCoefficient γ δ v e • leading γ v⟫_ℂ+ + leadingCoefficient γ δ v e*⟪x,leading γ v⟫_ℂ‖ := by + conv_lhs => rw [he,inner_add_right,inner_smul_right] + _ ≤ _ := (norm_add_le _ _).trans (add_le_add + ((norm_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_left + (address_remainder_bound γ δ v e) (norm_nonneg _))) + (by rw [norm_mul,norm_leadingCoefficient])) + +theorem gaussian_decay {α : Type*} {l : Filter α} {f : α → ℝ} + (h : Tendsto f l atTop) : + Tendsto (fun t => Real.exp (-(f t)^2/2)) l (𝓝 0) := by + have hs := ((tendsto_pow_atTop (by norm_num : (2:ℕ)≠0)).comp h).const_mul_atTop + (by positivity : (0:ℝ)<(2:ℝ)⁻¹) + convert! Real.tendsto_exp_atBot.comp (tendsto_neg_atTop_atBot.comp hs) using 1 + funext t + congr 1 + dsimp only [Function.comp_def] + ring + +def actualV (n : ℕ) (b t : ℝ) : Mode (n+1) := + (ordinary [.mixer (delta t),.cost (gamma b t)] (n+1)).insertion + +@[simp] theorem norm_actualV (n : ℕ) (b t : ℝ) : ‖actualV n b t‖=1 := + EvenUnitary.norm_insertion _ + +theorem actualV_eq (n : ℕ) (b t : ℝ) : + actualV n b t=(Real.cos (2*delta t):ℂ) • initialDirection (n+1)+ + (Real.sin (2*delta t):ℂ) • highDirection n (gamma b t) := + ordinary_one_mode _ _ _ + +theorem norm_actualV_sub_initial_le (n : ℕ) (b t : ℝ) : + ‖actualV n b t-initialDirection (n+1)‖≤ + |Real.cos (2*delta t)-1|+|Real.sin (2*delta t)| := by + have he : actualV n b t-initialDirection (n+1)= + ((Real.cos (2*delta t)-1:ℝ):ℂ) • initialDirection (n+1)+ + (Real.sin (2*delta t):ℂ) • highDirection n (gamma b t) := by + rw [actualV_eq] + push_cast + module + rw [he] + have heN : ‖initialDirection (n+1)‖=1 := initialDirection_norm _ + have hlN : ‖highDirection n (gamma b t)‖=1 := highDirection_norm _ _ + simpa only [norm_smul,heN,hlN,mul_one, + Complex.norm_real,Real.norm_eq_abs] using norm_add_le + (((Real.cos (2*delta t)-1:ℝ):ℂ) • initialDirection (n+1)) + ((Real.sin (2*delta t):ℂ) • highDirection n (gamma b t)) + +theorem tendsto_actualV_sub_initial (n : ℕ) (b : ℝ) : + Tendsto (fun t => ‖actualV n b t-initialDirection (n+1)‖) atTop (𝓝 0) := by + apply squeeze_zero (fun _ => norm_nonneg _) (norm_actualV_sub_initial_le n b) + simpa only [sub_self,abs_zero,add_zero] using + (tendsto_cos_two_delta.sub_const 1).abs.add tendsto_sin_two_delta.abs + +theorem tendsto_center_gap (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ‖(2*gamma b t:ℝ) • (initialDirection (n+1)+actualV n b t)‖) + atTop atTop := by + have hsmall : ∀ᶠ t : ℝ in atTop, ‖actualV n b t-initialDirection (n+1)‖<1 := + (tendsto_actualV_sub_initial n b).eventually (gt_mem_nhds zero_lt_one) + refine tendsto_atTop_mono' atTop ?_ ((tendsto_gamma b hb).const_mul_atTop (by norm_num : (0:ℝ)<2)) + filter_upwards [hsmall,eventually_ge_atTop (0:ℝ)] with t ht ht0 + have hg : 0 ≤ 2*gamma b t := by unfold gamma; positivity + have hn : 1 ≤ ‖initialDirection (n+1)+actualV n b t‖ := by + have h := norm_add_le (initialDirection (n+1)+actualV n b t) + (initialDirection (n+1)-actualV n b t) + have he : (initialDirection (n+1)+actualV n b t)+ + (initialDirection (n+1)-actualV n b t)=(2:ℂ) • initialDirection (n+1) := by module + rw [he,norm_smul,initialDirection_norm,mul_one,norm_sub_rev] at h + rw [show ‖(2:ℂ)‖=(2:ℝ) by norm_num] at h + linarith + rw [← Complex.coe_smul,norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hg] + nlinarith + +def actualAddress (n : ℕ) (b t : ℝ) : Level (n+2) := + address (gamma b t) (delta t) (actualV n b t) (initialDirection (n+1)) + +@[simp] theorem norm_actualAddress (n : ℕ) (b t : ℝ) : ‖actualAddress n b t‖=1 := + norm_address _ _ _ _ + +theorem tendsto_high_address_inner (n : ℕ) (b : ℝ) (hb : 0 < b) : + Tendsto (fun t => ⟪(highDirection (n+1) (gamma b t):Level (n+2)), + actualAddress n b t⟫_ℂ) atTop (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + have hs : Tendsto (fun t => |Real.sin (delta t)|) atTop (𝓝 0) := by + simpa only [Function.comp_def,Real.sin_zero,abs_zero] using + (Real.continuous_sin.continuousAt.tendsto.comp tendsto_delta).abs + apply squeeze_zero (fun _ => norm_nonneg _) + (fun t => show ‖⟪(highDirection (n+1) (gamma b t):Level (n+2)),actualAddress n b t⟫_ℂ‖≤ + |Real.sin (delta t)|+Real.exp (-‖(2*gamma b t:ℝ) • + (initialDirection (n+1)+actualV n b t)‖^2/2) from ?_) + (by simpa only [add_zero] using hs.add (gaussian_decay (tendsto_center_gap n b hb))) + have h := norm_inner_address_bound (gamma b t) (delta t) (actualV n b t) + (initialDirection (n+1)) (highDirection (n+1) (gamma b t):Level (n+2)) + have hn : ‖(highDirection (n+1) (gamma b t):Level (n+2))‖=1 := highDirection_norm _ _ + rw [hn,one_mul] at h + have hi : ‖⟪(highDirection (n+1) (gamma b t):Level (n+2)), + leading (gamma b t) (actualV n b t)⟫_ℂ‖= + Real.exp (-‖(2*gamma b t:ℝ) • (initialDirection (n+1)+actualV n b t)‖^2/2) := by + rw [highDirection_coe] + exact norm_inner_high_leading _ _ _ + rw [hi] at h + exact h.trans (add_le_add_right (mul_le_of_le_one_left (Real.exp_pos _).le + (Real.abs_cos_le_one _)) _) + +end SeedInitialization + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +variable {α : Type*} {l : Filter α} {d : α → E} + +theorem tendsto_inner_coherent_escape (hd : Tendsto (fun a => ‖d a‖) l atTop) (x : E) : + Tendsto (fun a => ⟪coherent x,coherent (d a)⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + simp_rw [inner_coherent,norm_kernel] + have hn : Tendsto (fun a => ‖x-d a‖) l atTop := by + rw [tendsto_atTop] + intro b + filter_upwards [(tendsto_atTop.mp hd) (b+‖x‖)] with a ha + have h := norm_sub_norm_le (d a) x + rw [norm_sub_rev] at h + linarith + have hs := ((tendsto_pow_atTop (by norm_num : (2:ℕ)≠0)).comp hn).const_mul_atTop + (by positivity : (0:ℝ)<(2:ℝ)⁻¹) + convert! Real.tendsto_exp_atBot.comp (tendsto_neg_atTop_atBot.comp hs) using 1 + funext a + congr 1 + dsimp only [Function.comp_def] + ring + +theorem tendsto_inner_pre_coherent_escape (hd : Tendsto (fun a => ‖d a‖) l atTop) + (x : PreSpace E) : + Tendsto (fun a => ⟪(x:Space E),coherent (d a)⟫_ℂ) l (𝓝 0) := by + classical + simp_rw [coe_eq_sum,Finsupp.sum,sum_inner,inner_smul_left] + convert! (tendsto_finsetSum (toFinsupp x).support fun e he => + tendsto_const_nhds.mul (tendsto_inner_coherent_escape hd e)) using 1 + simp + + + +theorem tendsto_inner_coherent_escape_all (hd : Tendsto (fun a => ‖d a‖) l atTop) + (x : Space E) : + Tendsto (fun a => ⟪x,coherent (d a)⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero,Metric.tendsto_nhds] + intro ε hε + obtain ⟨x',hx⟩ := Metric.denseRange_iff.mp + (UniformSpace.Completion.denseRange_coe (α := PreSpace E)) x (ε/2) (half_pos hε) + rw [dist_eq_norm] at hx + have ht := (tendsto_inner_pre_coherent_escape hd x').norm + have he : ∀ᶠ a in l, ‖⟪(x':Space E),coherent (d a)⟫_ℂ‖<ε/2 := by + simpa using ht.eventually_lt_const (by simpa using half_pos hε) + filter_upwards [he] with a ha + rw [dist_zero_right,Real.norm_of_nonneg (norm_nonneg _)] + have hi : ⟪x,coherent (d a)⟫_ℂ= + ⟪x-(x':Space E),coherent (d a)⟫_ℂ+⟪(x':Space E),coherent (d a)⟫_ℂ := by + simp only [inner_sub_left,sub_add_cancel] + rw [hi] + calc + _ ≤ ‖⟪x-(x':Space E),coherent (d a)⟫_ℂ‖+‖⟪(x':Space E),coherent (d a)⟫_ℂ‖ := norm_add_le _ _ + _ ≤ ‖x-(x':Space E)‖+‖⟪(x':Space E),coherent (d a)⟫_ℂ‖ := by + gcongr + simpa only [norm_coherent,mul_one] using norm_inner_le_norm (x-(x':Space E)) (coherent (d a)) + _ < ε := by linarith + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin Complex +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] +variable {α : Type*} {l : Filter α} {d : α → H} + +theorem inner_spinPair_right (x : SpinOperators.Double (Space H)) (y z : Space H) : + ⟪x,spinPair y z⟫_ℂ=⟪x 0,y⟫_ℂ+⟪x 1,z⟫_ℂ := by + rw [PiLp.inner_apply,Fin.sum_univ_two] + rfl + +theorem tendsto_inner_rootZ_WZ_escape (hd : Tendsto (fun a => ‖d a‖) l atTop) + (x : SpinSpace H) : + Tendsto (fun a => ⟪x,SpinOperators.act Z (WZ (d a) (vacuum H))⟫_ℂ) l (𝓝 0) := by + have hp := tendsto_inner_coherent_escape_all hd (x 0) + have hm := tendsto_inner_coherent_escape_all (d := fun a => -d a) + (by simpa only [norm_neg] using hd) (x 1) + simp_rw [rootZ_WZ_vac_pair,inner_spinPair_right,inner_neg_right,inner_smul_right] + simpa only [mul_zero,neg_zero,add_zero] using + (hp.const_mul (spinCoefficient:ℂ)).add (hm.const_mul (spinCoefficient:ℂ)).neg + +theorem tendsto_inner_rootY_WZ_escape (hd : Tendsto (fun a => ‖d a‖) l atTop) + (x : SpinSpace H) : + Tendsto (fun a => ⟪x,SpinOperators.act Y (WZ (d a) (vacuum H))⟫_ℂ) l (𝓝 0) := by + have hm := tendsto_inner_coherent_escape_all (d := fun a => -d a) + (by simpa only [norm_neg] using hd) (x 0) + have hp := tendsto_inner_coherent_escape_all hd (x 1) + simp_rw [rootY_WZ_vac_pair,inner_spinPair_right,inner_smul_right] + simpa only [mul_zero,add_zero,neg_mul] using + (hm.const_mul (-(I*spinCoefficient))).add (hp.const_mul (I*spinCoefficient)) + +end PointedTree + +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree + +theorem tendsto_norm_scaled_unit {α : Type*} {l : Filter α} + {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + (f : α → ℝ) (v : α → E) (hf : Tendsto f l atTop) (hv : ∀a, ‖v a‖=1) : + Tendsto (fun a => ‖(-2*f a:ℝ) • v a‖) l atTop := by + apply Tendsto.congr' (f₁ := fun a => 2*f a) + · filter_upwards [hf.eventually (eventually_ge_atTop 0)] with a ha + rw [norm_smul,hv,mul_one,Real.norm_eq_abs,show -2*f a= -(2*f a) by ring, + abs_neg,abs_of_nonneg (mul_nonneg (by norm_num) ha)] + · exact hf.const_mul_atTop (by norm_num : (0:ℝ)<2) + +theorem tendsto_inner_high (n : ℕ) (b : ℝ) (hb : 0 < b) (x : Level (n+1)) : + Tendsto (fun t => ⟪x,(highDirection n (gamma b t):Level (n+1))⟫_ℂ) atTop (𝓝 0) := by + simp_rw [highDirection_coe] + exact tendsto_inner_rootY_WZ_escape + (tendsto_norm_scaled_unit (gamma b) (fun _ => initialDirection n) (tendsto_gamma b hb) + (fun _ => initialDirection_norm n)) x + +theorem tendsto_inner_actualLeading (n : ℕ) (b : ℝ) (hb : 0 < b) (x : Level (n+2)) : + Tendsto (fun t => ⟪x,leading (gamma b t) (actualV n b t)⟫_ℂ) atTop (𝓝 0) := by + exact tendsto_inner_rootZ_WZ_escape + (tendsto_norm_scaled_unit (gamma b) (actualV n b) (tendsto_gamma b hb) + (norm_actualV n b)) x + +theorem tendsto_inner_actualAddress (n : ℕ) (b : ℝ) (hb : 0 < b) (x : Level (n+2)) : + Tendsto (fun t => ⟪x,actualAddress n b t⟫_ℂ) atTop (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + have hs : Tendsto (fun t => |Real.sin (delta t)|) atTop (𝓝 0) := by + simpa only [Function.comp_def,Real.sin_zero,abs_zero] using + (Real.continuous_sin.continuousAt.tendsto.comp tendsto_delta).abs + apply squeeze_zero (fun _ => norm_nonneg _) + (fun t => show ‖⟪x,actualAddress n b t⟫_ℂ‖≤‖x‖*|Real.sin (delta t)|+ + ‖⟪x,leading (gamma b t) (actualV n b t)⟫_ℂ‖ from ?_) + (by simpa only [mul_zero,norm_zero,add_zero] using + (hs.const_mul ‖x‖).add (tendsto_inner_actualLeading n b hb x).norm) + exact (norm_inner_address_bound _ _ _ _ x).trans (add_le_add_right + (mul_le_of_le_one_left (norm_nonneg _) (Real.abs_cos_le_one _)) _) + +end SeedInitialization + +namespace CoherentFock +open PointedTree +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] +variable {α : Type*} {l : Filter α} + +theorem norm_coe_le_mass (x : PreSpace E) : ‖(↑x:Space E)‖≤ mass x := by + classical + rw [coe_eq_sum] + calc + _ ≤ ∑ a ∈ (toFinsupp x).support, ‖(toFinsupp x) a • coherent a‖ := norm_sum_le _ _ + _ = _ := by simp only [norm_smul,norm_coherent,mul_one,mass,Finsupp.sum] + +theorem norm_spinCoe_le_mass (x : PreSpin E) : ‖spinCoe x‖≤ spinMass x := by + apply (norm_spin_le_sum _).trans + exact Finset.sum_le_sum fun i _ => norm_coe_le_mass (x i) + + + +theorem tendsto_inner_coe_coherent_uniform (d : α → E) (x : α → PreSpace E) + (hd : Tendsto (fun a => ‖d a‖) l atTop) (B A : ℝ) (hB : 0 ≤ B) + (hx : ∀ᶠ a in l, RadiusLE (x a) B ∧ mass (x a)≤A) : + Tendsto (fun a => ⟪(↑(x a):Space E),coherent (d a)⟫_ℂ) l (𝓝 0) := by + rw [tendsto_zero_iff_norm_tendsto_zero] + have hs : Tendsto (fun a => ‖d a‖-2*B) l atTop := by + simpa only [sub_eq_add_neg] using tendsto_atTop_add_const_right l (-(2*B)) hd + have he := (SeedInitialization.gaussian_decay hs).const_mul A + simp only [mul_zero] at he + apply squeeze_zero' (Filter.Eventually.of_forall fun a => norm_nonneg _) ?_ he + filter_upwards [hx,hd.eventually (eventually_ge_atTop (2*B))] with a hxa hda + have hb := translated_pre_bound (0:E) (d a) (x a) (basis (0:E)) B (‖d a‖-2*B) + hxa.1 (RadiusLE.basis _ _ (by simpa only [norm_zero] using hB)) + (by linarith) (by simp only [zero_sub,norm_neg]; linarith) + simp only [coe_basis,W_zero,ContinuousLinearMap.id_apply,W_vacuum,mass_basis,mul_one] at hb + exact hb.trans (mul_le_mul_of_nonneg_right hxa.2 (Real.exp_nonneg _)) + +theorem tendsto_inner_spinCoe_rootZ_uniform (d : α → E) (x : α → PreSpin E) + (hd : Tendsto (fun a => ‖d a‖) l atTop) (B A : ℝ) (hB : 0 ≤ B) + (hx : ∀ᶠ a in l, SpinRadiusLE (x a) B ∧ spinMass (x a)≤A) : + Tendsto (fun a => ⟪spinCoe (x a),SpinOperators.act RootSpin.Z (WZ (d a) (vacuum E))⟫_ℂ) + l (𝓝 0) := by + have h₀ : ∀ᶠ a in l, RadiusLE (x a 0) B ∧ mass (x a 0)≤A := by + filter_upwards [hx] with a ha + exact ⟨ha.1 0,(mass_le_spinMass _ _).trans ha.2⟩ + have h₁ : ∀ᶠ a in l, RadiusLE (x a 1) B ∧ mass (x a 1)≤A := by + filter_upwards [hx] with a ha + exact ⟨ha.1 1,(mass_le_spinMass _ _).trans ha.2⟩ + have hp := tendsto_inner_coe_coherent_uniform d (fun a => x a 0) hd B A hB h₀ + have hm := tendsto_inner_coe_coherent_uniform (fun a => -d a) (fun a => x a 1) + (by simpa only [norm_neg] using hd) B A hB h₁ + simp_rw [rootZ_WZ_vac_pair,inner_spinPair_right,inner_neg_right,inner_smul_right,spinCoe_apply] + simpa only [mul_zero,neg_zero,add_zero] using + (hp.const_mul (spinCoefficient:ℂ)).add (hm.const_mul (spinCoefficient:ℂ)).neg + +theorem tendsto_inner_spinCoe_rootY_uniform (d : α → E) (x : α → PreSpin E) + (hd : Tendsto (fun a => ‖d a‖) l atTop) (B A : ℝ) (hB : 0 ≤ B) + (hx : ∀ᶠ a in l, SpinRadiusLE (x a) B ∧ spinMass (x a)≤A) : + Tendsto (fun a => ⟪spinCoe (x a),SpinOperators.act RootSpin.Y (WZ (d a) (vacuum E))⟫_ℂ) + l (𝓝 0) := by + have h₀ : ∀ᶠ a in l, RadiusLE (x a 0) B ∧ mass (x a 0)≤A := by + filter_upwards [hx] with a ha + exact ⟨ha.1 0,(mass_le_spinMass _ _).trans ha.2⟩ + have h₁ : ∀ᶠ a in l, RadiusLE (x a 1) B ∧ mass (x a 1)≤A := by + filter_upwards [hx] with a ha + exact ⟨ha.1 1,(mass_le_spinMass _ _).trans ha.2⟩ + have hm := tendsto_inner_coe_coherent_uniform (fun a => -d a) (fun a => x a 0) + (by simpa only [norm_neg] using hd) B A hB h₀ + have hp := tendsto_inner_coe_coherent_uniform d (fun a => x a 1) hd B A hB h₁ + simp_rw [rootY_WZ_vac_pair,inner_spinPair_right,inner_smul_right,spinCoe_apply] + simpa only [mul_zero,add_zero,neg_mul] using + (hm.const_mul (-(Complex.I*spinCoefficient))).add (hp.const_mul (Complex.I*spinCoefficient)) + +end CoherentFock + +namespace SeedInitialization +open CoherentFock PointedTree RootSpin Complex + +theorem norm_inner_spinCoe_address_bound {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] (γ δ : ℝ) (v e : E) (x : PreSpin E) : + ‖⟪spinCoe x,address γ δ v e⟫_ℂ‖ ≤ spinMass x*|Real.sin δ|+ + ‖⟪spinCoe x,leading γ v⟫_ℂ‖ := by + exact (norm_inner_address_bound γ δ v e (spinCoe x)).trans + (add_le_add (mul_le_mul_of_nonneg_right (norm_spinCoe_le_mass x) (abs_nonneg _)) + (mul_le_of_le_one_left (norm_nonneg _) (Real.abs_cos_le_one _))) + +theorem norm_inner_spinCoe_address_bound_of_mass {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℂ E] (γ δ : ℝ) (v e : E) (x : PreSpin E) (A : ℝ) + (hA : spinMass x ≤ A) : + ‖⟪spinCoe x,address γ δ v e⟫_ℂ‖ ≤ A*|Real.sin δ|+ + ‖⟪spinCoe x,leading γ v⟫_ℂ‖ := + (norm_inner_spinCoe_address_bound γ δ v e x).trans + (add_le_add_left (mul_le_mul_of_nonneg_right hA (abs_nonneg _)) _) + +theorem tendsto_inner_high_uniform (n : ℕ) (b : ℝ) (hb : 0 < b) + (x : ℝ → PreSpin (Mode n)) (B A : ℝ) (hB : 0 ≤ B) + (hx : ∀ᶠ t : ℝ in atTop, SpinRadiusLE (x t) B ∧ spinMass (x t)≤A) : + Tendsto (fun t => ⟪spinCoe (x t),(highDirection n (gamma b t):Level (n+1))⟫_ℂ) + atTop (𝓝 0) := by + simp_rw [highDirection_coe] + exact tendsto_inner_spinCoe_rootY_uniform _ x + (tendsto_norm_scaled_unit (gamma b) (fun _ => initialDirection n) (tendsto_gamma b hb) + (fun _ => initialDirection_norm n)) B A hB hx + +theorem tendsto_inner_address_uniform (n : ℕ) (b : ℝ) (hb : 0 < b) + (x : ℝ → PreSpin (Mode (n+1))) (B A : ℝ) (hB : 0 ≤ B) + (hx : ∀ᶠ t : ℝ in atTop, SpinRadiusLE (x t) B ∧ spinMass (x t)≤A) : + Tendsto (fun t => ⟪spinCoe (x t),actualAddress n b t⟫_ℂ) atTop (𝓝 0) := by + have hl : Tendsto (fun t => ⟪spinCoe (x t),leading (gamma b t) (actualV n b t)⟫_ℂ) + atTop (𝓝 0) := + tendsto_inner_spinCoe_rootZ_uniform _ x + (tendsto_norm_scaled_unit (gamma b) (actualV n b) (tendsto_gamma b hb) + (norm_actualV n b)) B A hB hx + have hs : Tendsto (fun t => |Real.sin (delta t)|) atTop (𝓝 0) := by + simpa only [Function.comp_def,Real.sin_zero,abs_zero] using + (Real.continuous_sin.continuousAt.tendsto.comp tendsto_delta).abs + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Filter.Eventually.of_forall fun t => norm_nonneg _) ?_ + (by simpa only [mul_zero,norm_zero,add_zero] using (hs.const_mul A).add hl.norm) + filter_upwards [hx] with t ht + have hm : ‖(spinCoe (x t):Level (n+2))‖ ≤ A := (norm_spinCoe_le_mass (x t)).trans ht.2 + have h := norm_inner_address_bound (gamma b t) (delta t) (actualV n b t) + (initialDirection (n+1)) (spinCoe (x t):Level (n+2)) + have h1 := mul_le_mul_of_nonneg_right hm (abs_nonneg (Real.sin (delta t))) + have h2 := mul_le_of_le_one_left + (norm_nonneg ⟪(spinCoe (x t):Level (n+2)),leading (gamma b t) (actualV n b t)⟫_ℂ) + (Real.abs_cos_le_one (delta t)) + change ‖⟪(spinCoe (x t):Level (n+2)),address (gamma b t) (delta t) (actualV n b t) + (initialDirection (n+1))⟫_ℂ‖ ≤ _ + exact h.trans (add_le_add h1 h2) + +end SeedInitialization + +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem cos_delta_error {t : ℝ} (ht : 1 ≤ t) : + |Real.cos (delta t)-1|≤(amplitude t)^2 := by + rw [abs_of_nonpos (sub_nonpos.mpr (Real.cos_le_one _))] + have hc : 0 ≤ Real.cos (delta t) := by rw [cos_delta]; positivity + have h := Real.sin_sq_add_cos_sq (delta t) + rw [sin_delta ht] at h + have hc1 := Real.cos_le_one (delta t) + nlinarith + +theorem ordinaryCoefficient_error (γ δ : ℝ) (v e : E) : + ‖ordinaryCoefficient γ δ v e-phase (γ • v) ((-γ) • e)‖=|Real.cos δ-1| := by + rw [ordinaryCoefficient,← sub_one_mul,norm_mul,norm_phase,mul_one] + rw [← Complex.ofReal_one,← Complex.ofReal_sub,Complex.norm_real,Real.norm_eq_abs] + +theorem ordinary_component_error (γ β : ℝ) {t : ℝ} (ht : 1 ≤ t) + (v e : E) (x : SpinSpace E) : + ‖ordinaryCoefficient γ (delta t) v e • ordinaryMap γ β v e x- + phase (γ • v) ((-γ) • e) • ordinaryMap γ β v e x‖≤(amplitude t)^2*‖x‖ := by + rw [← sub_smul,norm_smul,ordinaryCoefficient_error,LinearIsometryEquiv.norm_map] + exact mul_le_mul_of_nonneg_right (cos_delta_error ht) (norm_nonneg _) + +theorem initial_forward_error (γ β : ℝ) {t : ℝ} (ht : 1 ≤ t) + (v e : E) (x : SpinSpace E) : + ‖initialMap γ (delta t) β v e x- + phase (γ • v) ((-γ) • e) • ordinaryMap γ β v e x‖≤ + ((amplitude t)^2+amplitude t)*‖x‖ := by + rw [exact_split,add_sub_right_comm] + calc + _ ≤ ‖ordinaryCoefficient γ (delta t) v e • ordinaryMap γ β v e x- + phase (γ • v) ((-γ) • e) • ordinaryMap γ β v e x‖+ + ‖specialCoefficient γ (delta t) v e • specialMap γ β v e x‖ := norm_add_le _ _ + _ ≤ (amplitude t)^2*‖x‖+amplitude t*‖x‖ := by + apply add_le_add (ordinary_component_error γ β ht v e x) + rw [norm_special_component,sin_delta ht,abs_of_pos (amplitude_pos ht)] + _ = _ := (add_mul _ _ _).symm + +theorem initial_insertion_error (γ β : ℝ) {t : ℝ} (ht : 1 ≤ t) + (v e : E) (P : SpinSpace E →L[ℂ] SpinSpace E) (hP : ∀x, ‖P x‖≤‖x‖) : + ‖(initialMap γ (delta t) β v e).symm (P (initialMap γ (delta t) β v e (vacuum E)))- + (ordinaryMap γ β v e).symm (P (ordinaryMap γ β v e (vacuum E)))‖≤ + 2*((amplitude t)^2+amplitude t) := by + have h := ForwardControl.insertion_from_forward (initialMap γ (delta t) β v e) + (ordinaryMap γ β v e) P hP (vacuum E) (phase (γ • v) ((-γ) • e)) + have h₁ := initial_forward_error γ β ht v e (vacuum E) + have h₂ := initial_forward_error γ β ht v e + ((ordinaryMap γ β v e).symm (P (ordinaryMap γ β v e (vacuum E)))) + rw [norm_vacuum,mul_one] at h₁ + have hn : ‖(ordinaryMap γ β v e).symm (P (ordinaryMap γ β v e (vacuum E)))‖≤1 := by + rw [LinearIsometryEquiv.norm_map] + simpa only [LinearIsometryEquiv.norm_map,norm_vacuum] using hP + (ordinaryMap γ β v e (vacuum E)) + have hh := mul_le_mul_of_nonneg_left hn + (add_nonneg (sq_nonneg (amplitude t)) (amplitude_pos ht).le) + nlinarith + +def ordinaryDisplacement (n : ℕ) (b t : ℝ) : Mode (n+1) := + gamma b t • (actualV n b t-initialDirection (n+1)) + +theorem ordinaryDisplacement_error_eq (n : ℕ) (b t : ℝ) : + ordinaryDisplacement n b t-(2*b:ℝ) • highDirection n (gamma b t)= + ((gamma b t*(Real.cos (2*delta t)-1):ℝ):ℂ) • initialDirection (n+1)+ + ((gamma b t*Real.sin (2*delta t)-2*b:ℝ):ℂ) • highDirection n (gamma b t) := by + unfold ordinaryDisplacement + rw [actualV_eq,← Complex.coe_smul,← Complex.coe_smul] + push_cast + module + +theorem norm_ordinaryDisplacement_error (n : ℕ) (b t : ℝ) : + ‖ordinaryDisplacement n b t-(2*b:ℝ) • highDirection n (gamma b t)‖≤ + |gamma b t*(Real.cos (2*delta t)-1)|+|gamma b t*Real.sin (2*delta t)-2*b| := by + rw [ordinaryDisplacement_error_eq] + have heN : ‖initialDirection (n+1)‖=1 := initialDirection_norm _ + have hlN : ‖highDirection n (gamma b t)‖=1 := highDirection_norm _ _ + simpa only [norm_smul,heN,hlN,mul_one,Complex.norm_real,Real.norm_eq_abs] using norm_add_le + (((gamma b t*(Real.cos (2*delta t)-1):ℝ):ℂ) • initialDirection (n+1)) + (((gamma b t*Real.sin (2*delta t)-2*b:ℝ):ℂ) • highDirection n (gamma b t)) + +theorem tendsto_ordinaryDisplacement_error (n : ℕ) (b : ℝ) : + Tendsto (fun t => ‖ordinaryDisplacement n b t-(2*b:ℝ) • highDirection n (gamma b t)‖) + atTop (𝓝 0) := by + apply squeeze_zero (fun _ => norm_nonneg _) (norm_ordinaryDisplacement_error n b) + simpa only [abs_zero,sub_self,add_zero] using (tendsto_gamma_cos_error b).abs.add + ((tendsto_gamma_sin b).sub_const (2*b)).abs + +theorem ordinaryDisplacement_bounded (n : ℕ) (b : ℝ) : + ∀ᶠ t : ℝ in atTop, ‖ordinaryDisplacement n b t‖≤2*|b|+1 := by + filter_upwards [(tendsto_ordinaryDisplacement_error n b).eventually + (gt_mem_nhds zero_lt_one)] with t ht + have h := norm_le_norm_sub_add (ordinaryDisplacement n b t) + ((2*b:ℝ) • highDirection n (gamma b t)) + have hn : ‖(2*b:ℝ) • highDirection n (gamma b t)‖=2*|b| := by + rw [← Complex.coe_smul,norm_smul,highDirection_norm,mul_one, + Complex.norm_real,Real.norm_eq_abs,abs_mul] + norm_num + rw [hn] at h + linarith + +end SeedInitialization + +namespace PointedTree +open CoherentFock RootSpin + +theorem symmetry_rootX (n : ℕ) (x : Level n) : + (symmetry n).op (root n X x)=root n X ((symmetry n).op x) := by + cases n with + | zero => rfl + | succ n => + change SpinOperators.act X + (spinMap (gammaEmbedding (symmetry n).centered.toLinearIsometry) (SpinOperators.act X x))=_ + rw [spinMap_root] + rfl + +namespace EvenUnitary + +def rootX (n : ℕ) : EvenUnitary n where + op := rootEquiv n X X_unitary + commutes x := by simpa only [rootEquiv_apply] using symmetry_rootX n x + +end EvenUnitary +end PointedTree + +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree + +theorem odd_real_smul {n : ℕ} {v : Mode n} (hv : (symmetry n).centered v=-v) (a : ℝ) : + (symmetry n).centered (a • v)= -(a • v) := by + rw [← Complex.coe_smul,map_smul,hv,smul_neg] + +theorem odd_actualV (n : ℕ) (b t : ℝ) : + (symmetry (n+1)).centered (actualV n b t)= -actualV n b t := + EvenUnitary.insertion_odd _ + +theorem odd_initialDirection (n : ℕ) : + (symmetry n).centered (initialDirection n)= -initialDirection n := + EvenUnitary.insertion_odd _ + +def specialUnitary (n : ℕ) (b t : ℝ) : EvenUnitary (n+2) := + ((EvenUnitary.cost (n+1) ((-gamma b t) • (actualV n b t+initialDirection (n+1))) + (odd_real_smul (by rw [map_add,odd_actualV,odd_initialDirection,neg_add]) _)).followedBy + (EvenUnitary.rootX (n+2))).followedBy (EvenUnitary.mixer (n+2) (Real.pi/4)) + +theorem specialUnitary_apply (n : ℕ) (b t : ℝ) (x : Level (n+2)) : + (specialUnitary n b t).op x= + specialMap (gamma b t) (Real.pi/4) (actualV n b t) (initialDirection (n+1)) x := rfl + +theorem initialMap_eq_ordinary (n : ℕ) (b t β : ℝ) : + initialMap (gamma b t) (delta t) β (actualV n b t) (initialDirection (n+1))= + (ordinary (initializationWord (gamma b t) (delta t) β) (n+2)).op := by + apply LinearIsometryEquiv.ext + intro x + symm + simpa only [initialMap_apply,actualV,Complex.coe_smul,← Complex.ofReal_neg] using + initialization_op n (gamma b t) (delta t) β x + +theorem actualAddress_odd (n : ℕ) (b t : ℝ) : + (symmetry (n+2)).op (actualAddress n b t)= -actualAddress n b t := by + let z : ℂ := specialPhase (gamma b t) (actualV n b t) (initialDirection (n+1)) + let S := specialUnitary n b t + have hs : (symmetry (n+2)).op (z • S.op (vac (n+2)))=z • S.op (vac (n+2)) := by + rw [map_smul,S.commutes,symmetry_vac] + have hz := symmetry_rootZ (n+2) (z • S.op (vac (n+2))) + rw [hs] at hz + change (symmetry (n+2)).op (SpinOperators.act Z (z • S.op (vac (n+2))))= + -SpinOperators.act Z (z • S.op (vac (n+2))) at hz + have he : S.op (vac (n+2))= + specialMap (gamma b t) (Real.pi/4) (actualV n b t) (initialDirection (n+1)) + (vacuum (Mode (n+1))) := rfl + rw [he] at hz + unfold actualAddress address + rw [initialMap_eq_ordinary,EvenUnitary.symm_commutes,hz,map_neg] + + + +def addressMode (n : ℕ) (b t : ℝ) : Mode (n+2) := + ⟨actualAddress n b t,odd_centered (symmetry (n+2)) _ (actualAddress_odd n b t)⟩ + +@[simp] theorem norm_addressMode (n : ℕ) (b t : ℝ) : ‖addressMode n b t‖=1 := + norm_actualAddress n b t + +@[simp] theorem addressMode_odd (n : ℕ) (b t : ℝ) : + (symmetry (n+2)).centered (addressMode n b t)= -addressMode n b t := by + apply Subtype.ext + exact actualAddress_odd n b t + +end SeedInitialization + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/OverlapDiscountMono.lean b/lean/OAI/Probability/ParisiFinite/OverlapDiscountMono.lean new file mode 100644 index 0000000000000000000000000000000000000000..267040f4995d53ddd47d91ba99b7b0544e258dc5 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/OverlapDiscountMono.lean @@ -0,0 +1,689 @@ +import Mathlib +import OAI.Probability.ParisiFinite.EmpiricalExpLog + +namespace OAI + +/-! Overlap Discount Mono. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma overlapDiscount_mono (μ : ProbabilityMeasure OverlapArray) : Monotone (overlapDiscount μ) := by + intro x y hxy + exact measureReal_mono (fun z hz => hz.trans hxy) + +lemma overlapDiscount_le_one (μ : ProbabilityMeasure OverlapArray) (q : ℝ) : overlapDiscount μ q≤1 := by + let := entryLaw_probability μ 0 1 + exact measureReal_le_one + +lemma uniform_schedule_penalty {d : ℕ} (a : Fin d → ℝ≥0) (c : ℝ≥0) (t : ℝ) : + penalty t (List.ofFn (fun k => (a k,c)))= + ∑ k,(a k:ℝ)*((t+((k.val:ℝ)+1)*c)^2-(t+(k.val:ℝ)*c)^2)/4 := by + induction d generalizing t with + | zero => simp [penalty] + | succ d ih => + rw [List.ofFn_succ,penalty,Fin.sum_univ_succ,ih] + simp only [Fin.val_zero,Nat.cast_zero,zero_add,one_mul,zero_mul,add_zero,Fin.val_succ,Nat.cast_add,Nat.cast_one] + congr 1 + apply Finset.sum_congr rfl + intro k _ + congr 2 + ring + +def gridSchedule (μ : ProbabilityMeasure OverlapArray) (β : ℝ≥0) (m : ℕ) : Schedule := + List.ofFn (fun k : Fin (m+1) => + (Real.toNNReal (overlapDiscount μ (cavityGrid m k.succ))*β, + ⟨gridZVariance m k,gridZVariance_nonneg m k⟩)) + +lemma gridSchedule_admissible (μ : ProbabilityMeasure OverlapArray) (β : ℝ≥0) (m : ℕ) : + Admissible β (gridSchedule μ β m) := by + refine ⟨?_,?_,?_⟩ + · simp only [width,gridSchedule,List.map_ofFn,List.sum_ofFn,Function.comp_def] + change (∑ _ : Fin (m+1), (1:ℝ)/(m+1:ℕ))=1 + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + have hn : ((m+1:ℕ):ℝ)≠0 := Nat.cast_ne_zero.mpr (Nat.succ_ne_zero m) + field_simp + · apply List.pairwise_ofFn.mpr + intro i j hij + exact mul_le_mul_of_nonneg_right (Real.toNNReal_mono ((overlapDiscount_mono μ) + ((cavityGrid_mono m) (Fin.succ_le_succ_iff.mpr hij.le)))) (by positivity : 0≤β) + · intro l hl + obtain ⟨k,rfl⟩ := List.mem_ofFn.mp hl + simp only [NNReal.coe_mul] + rw [Real.coe_toNNReal _ (show 0≤overlapDiscount μ (cavityGrid m k.succ) from measureReal_nonneg)] + have ha := overlapDiscount_le_one μ (cavityGrid m k.succ) + nlinarith [β.coe_nonneg] + +lemma gridSchedule_penalty (μ : ProbabilityMeasure OverlapArray) (β : ℝ≥0) (m : ℕ) : + penalty 0 (gridSchedule μ β m)= + (β:ℝ)/2*∑ k,overlapDiscount μ (cavityGrid m k.succ)*gridYVariance m k := by + let c : ℝ≥0 := ⟨1/(m+1:ℕ),by positivity⟩ + change penalty 0 (List.ofFn (fun k : Fin (m+1) => (Real.toNNReal (overlapDiscount μ (cavityGrid m k.succ))*β,c)))=_ + rw [uniform_schedule_penalty,Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + simp only [NNReal.coe_mul,zero_add] + rw [Real.coe_toNNReal _ (show 0≤overlapDiscount μ (cavityGrid m k.succ) from measureReal_nonneg)] + change overlapDiscount μ (cavityGrid m k.succ)*(β:ℝ)* + ((((k.val:ℝ)+1)*(1/(m+1:ℕ)))^2-((k.val:ℝ)*(1/(m+1:ℕ)))^2)/4= + (β:ℝ)/2*(overlapDiscount μ (cavityGrid m k.succ)*((2*(k.val:ℝ)+1)/(2*(m+1:ℕ)^2))) + ring + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + + + +theorem gridCavityMixture_tendsto {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + (m : ℕ) {β : ℝ} (hβ : 0<β) : + Tendsto (fun r => gridCavityMixture μ m (r+1) β) atTop + (𝓝 (β*functional β (gridSchedule μ (Real.toNNReal β) m))) := by + let a (k : Fin (m+1)) := overlapDiscount μ (cavityGrid m k.succ) + let s (k : Fin (m+1)) := Real.sqrt (gridZVariance m k) + let t (k : Fin (m+1)) := Real.sqrt (gridYVariance m k) + have hc := hierarchyField_lipschitz_tendsto hG hgg hu hex (cavityGrid m) (cavityGrid_mono m) + (cavityGrid_root m) (cavityGrid_last m) s (lipschitz_log_cosh hβ) 0 + have ha : LipschitzWith (Real.toNNReal β) (fun x : ℝ => β*x) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,← mul_sub,abs_mul,abs_of_pos hβ,Real.coe_toNNReal β hβ.le] + exact le_rfl + have hy := hierarchyField_lipschitz_tendsto hG hgg hu hex (cavityGrid m) (cavityGrid_mono m) + (cavityGrid_root m) (cavityGrid_last m) t ha 0 + have hec : scalarHierarchy a s (fun x => Real.log (2*Real.cosh (β*x))) 0= + β*recursion β (gridSchedule μ (Real.toNNReal β) m) 0 := by + have hh := gaussianHierarchy_cosh_schedule (fun k => Real.toNNReal (a k)) + (fun k => (⟨gridZVariance m k,gridZVariance_nonneg m k⟩ : ℝ≥0)) hβ 0 + change gaussianHierarchyRisk (fun k => (Real.toNNReal (a k):ℝ)) + (fun z => Real.log (2*Real.cosh (β*(0+∑ k,Real.sqrt (gridZVariance m k)*z k))))= + β*recursion β (gridSchedule μ (Real.toNNReal β) m) 0 at hh + rw [gaussianHierarchyRisk_sum (fun k => (Real.toNNReal (a k):ℝ)) + (fun k => Real.sqrt (gridZVariance m k)) (fun x => Real.log (2*Real.cosh (β*x))) 0] at hh + have hm (k : Fin (m+1)) : (Real.toNNReal (a k):ℝ)=a k := Real.coe_toNNReal _ measureReal_nonneg + simpa only [hm,a,s,gridSchedule] using hh + have hey : scalarHierarchy a t (fun x => β*x) 0= + β^2/2*∑ k,a k*gridYVariance m k := by + have hh := scalarHierarchy_affine a t β 0 0 + simp only [add_zero,mul_zero,zero_add] at hh + rw [hh] + congr 1 + apply Finset.sum_congr rfl + intro k _ + rw [Real.sq_sqrt (gridYVariance_nonneg m k)] + have he : scalarHierarchy a s (fun x => Real.log (2*Real.cosh (β*x))) 0- + scalarHierarchy a t (fun x => β*x) 0=β*functional β (gridSchedule μ (Real.toNNReal β) m) := by + rw [hec,hey,functional,gridSchedule_penalty,Real.coe_toNNReal β hβ.le] + dsimp only [a] + ring + have hh := hc.sub hy + simp only [zero_add] at hh + have heq (r : ℕ) : + hierarchyFieldValue μ (cavityGrid m) (r+1) (fun z => Real.log (2*Real.cosh (β*(∑ k,s k*z k))))- + hierarchyFieldValue μ (cavityGrid m) (r+1) (fun z => β*(∑ k,t k*z k))=gridCavityMixture μ m (r+1) β := + (gridCavityMixture_fields μ m (Nat.succ_pos r) hβ).symm + simp only [heq] at hh + change Tendsto (fun r => gridCavityMixture μ m (r+1) β) atTop + (𝓝 (scalarHierarchy a s (fun x => Real.log (2*Real.cosh (β*x))) 0- + scalarHierarchy a t (fun x => β*x) 0)) at hh + rw [he] at hh + exact hh + +lemma quadratic_indices_tendsto : Tendsto (fun k : ℕ => (k+1)^2) atTop atTop := + tendsto_atTop_mono (fun k => (by nlinarith : k≤(k+1)^2)) tendsto_id + + + +theorem gridFunctional_cavity_error {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + {β v : ℝ} (hβ : 0<β) (hv : Tendsto (quadraticCavitySamples μ β) atTop (𝓝 v)) (m : ℕ) : + |v-β*functional β (gridSchedule μ (Real.toNNReal β) m)|≤β^2*Real.pi/(m+1:ℕ) := by + have hs := gridCavityMixture_tendsto (μ:=μ) hG hgg hu hex m hβ + have hg : Tendsto (fun r => gridCavityMixture μ m r β) atTop + (𝓝 (β*functional β (gridSchedule μ (Real.toNNReal β) m))) := + (tendsto_add_atTop_iff_nat 1).mp hs + have hh := hg.comp quadratic_indices_tendsto + apply le_of_tendsto (hv.sub hh).abs + exact Eventually.of_forall fun k => gridCavityMixture_error hG hgg hu hex m (by positivity : 0<(k+1)^2) β + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiGuerra +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite SKCavity + + + +theorem exists_admissible_schedule_sequence {β : ℝ} (hβ : 0<β) : + ∃ ls : ℕ → Schedule, (∀ m,Admissible β (ls m)) ∧ + Tendsto (fun m => functional β (ls m)) atTop (𝓝 (limitingFreeEnergy β)) := by + obtain ⟨μ,v,hG,hgg,hex,hu,hv,hbound⟩ := exists_scalar_ultrametric_cavity hβ + let ls (m : ℕ) := gridSchedule μ (Real.toNNReal β) m + have ha (m : ℕ) : Admissible β (ls m) := by + simpa only [Real.coe_toNNReal β hβ.le] using gridSchedule_admissible μ (Real.toNNReal β) m + have hl (m : ℕ) : limitingFreeEnergy β≤functional β (ls m) := by + simpa only [Real.coe_toNNReal β hβ.le] using + limitingFreeEnergy_le_functional (Real.toNNReal β) (Real.toNNReal_pos.mpr hβ) (ls m) + (gridSchedule_admissible μ (Real.toNNReal β) m) + have hupp (m : ℕ) : functional β (ls m)≤limitingFreeEnergy β+β*Real.pi/(m+1:ℕ) := by + have hh := (abs_le.mp (gridFunctional_cavity_error hG hgg hu hex hβ hv m)).1 + change -(β^2*Real.pi/(m+1:ℕ))≤v-β*functional β (ls m) at hh + have hdiv : β^2*Real.pi/(m+1:ℕ)=β*(β*Real.pi/(m+1:ℕ)) := by ring + rw [hdiv] at hh + nlinarith + have he : Tendsto (fun m : ℕ => β*Real.pi/(m+1:ℕ)) atTop (𝓝 (0:ℝ)) := by + convert tendsto_succ_reciprocal.const_mul (β*Real.pi) using 1 <;> simp only [mul_zero,mul_one_div] + refine ⟨ls,ha,?_⟩ + exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds + (by simpa only [add_zero] using tendsto_const_nhds.add he) hl hupp + + + +def finiteParisiValues (β : ℝ) : Set ℝ := + {x | ∃ ls : Schedule,Admissible β ls ∧ functional β ls=x} + +def finiteParisiInfimum (β : ℝ) : ℝ := sInf (finiteParisiValues β) + +lemma finiteParisiValues_nonempty {β : ℝ} (hβ : 0<β) : + (finiteParisiValues β).Nonempty := by + obtain ⟨ls,ha,_⟩ := exists_admissible_schedule_sequence hβ + exact ⟨functional β (ls 0),ls 0,ha 0,rfl⟩ + +lemma finiteParisiValues_bddBelow {β : ℝ} (hβ : 0<β) : + BddBelow (finiteParisiValues β) := by + refine ⟨limitingFreeEnergy β,?_⟩ + rintro x ⟨ls,ha,rfl⟩ + simpa only [Real.coe_toNNReal β hβ.le] using + limitingFreeEnergy_le_functional (Real.toNNReal β) (Real.toNNReal_pos.mpr hβ) ls + (by simpa only [Real.coe_toNNReal β hβ.le] using ha) + + + +theorem limitingFreeEnergy_eq_finiteParisiInfimum {β : ℝ} (hβ : 0<β) : + limitingFreeEnergy β=finiteParisiInfimum β := by + apply le_antisymm + · apply le_csInf (finiteParisiValues_nonempty hβ) + rintro x ⟨ls,ha,rfl⟩ + simpa only [Real.coe_toNNReal β hβ.le] using + limitingFreeEnergy_le_functional (Real.toNNReal β) (Real.toNNReal_pos.mpr hβ) ls + (by simpa only [Real.coe_toNNReal β hβ.le] using ha) + · obtain ⟨ls,ha,ht⟩ := exists_admissible_schedule_sequence hβ + apply ge_of_tendsto ht + exact Eventually.of_forall fun m => csInf_le (finiteParisiValues_bddBelow hβ) ⟨ls m,ha m,rfl⟩ + +lemma exists_admissible_functional_lt {β ε : ℝ} (hβ : 0<β) (hε : 0<ε) : + ∃ ls : Schedule,Admissible β ls ∧ functional β ls Real.exp (a*f z)) μ) : + (∫ z,f z ∂μ)≤logMean μ a f := by + by_cases h0 : a=0 + · simp [logMean,h0] + have hap : 0 Set.mem_univ _) (hf.const_mul a) he + simp only [integral_const_mul] at hh + have hp := integral_exp_pos he + have hl := Real.log_le_log (Real.exp_pos _) hh + rw [Real.log_exp] at hl + simpa only [logMean,h0,↓reduceIte] using (le_div_iff₀ hap).mpr (by nlinarith) + +lemma logMean_parameter_mono {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {a b : ℝ} (ha : 0≤a) (hab : a≤b) {f : Ω → ℝ} + (hf : Integrable f μ) (hea : Integrable (fun z => Real.exp (a*f z)) μ) + (heb : Integrable (fun z => Real.exp (b*f z)) μ) : + logMean μ a f≤logMean μ b f := by + by_cases h0 : a=0 + · rw [h0,logMean_zero] + exact logMean_expectation_le (ha.trans hab) hf heb + have hap : 0 x^p) ∘ (fun z => Real.exp (b*f z))) μ := by + simpa only [Function.comp_def,heq] using hea + have hh := (Real.concaveOn_rpow hp0 hp1).le_map_integral + (Real.continuous_rpow_const hp0).continuousOn isClosed_Ici + (ae_of_all _ fun z => (Real.exp_pos (b*f z)).le) heb hi + simp only [heq] at hh + have hla := integral_exp_pos hea + have hlb := integral_exp_pos heb + have hl := Real.log_le_log hla hh + rw [Real.log_rpow hlb] at hl + simp only [logMean,h0,ne_of_gt hbp,↓reduceIte] + apply (div_le_div_iff₀ hap hbp).mpr + have he : p*Real.log (∫ z,Real.exp (b*f z) ∂μ)*b= + Real.log (∫ z,Real.exp (b*f z) ∂μ)*a := by dsimp [p]; field_simp + nlinarith + +lemma step_parameter_mono {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {a b : ℝ} (ha : 0≤a) (hab : a≤b) (s x : ℝ) : + step a s f x≤ step b s f x := + logMean_parameter_mono ha hab (integrable_shift hf x s) + (integrable_exp_shift hf a x s) (integrable_exp_shift hf b x s) + +lemma step_le_of_le {L K : ℝ≥0} {f g : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : LipschitzWith K g) {a : ℝ} (ha : 0≤a) (s x : ℝ) (hfg : ∀ y,f y≤g y) : + step a s f x≤ step a s g x := + logMean_mono ha (integrable_shift hf x s) (integrable_shift hg x s) + (integrable_exp_shift hf a x s) (integrable_exp_shift hg a x s) (fun _ => hfg _) + +lemma step_stable {L K : ℝ≥0} {f g : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : LipschitzWith K g) {a : ℝ} (ha : 0≤a) (s x c : ℝ) (hfg : ∀ y,|f y-g y|≤c) : + |step a s f x-step a s g x|≤c := + logMean_stable ha (integrable_shift hf x s) (integrable_shift hg x s) + (integrable_exp_shift hf a x s) (integrable_exp_shift hg a x s) c (fun _ => hfg _) + +end ParisiFinite + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +def gaussianSmallError (β s : ℝ) : ℝ := + logMean (gaussianReal 0 1) β (fun z => |s| * |z|) + +lemma abs_scaled_lipschitz (s : ℝ) : + LipschitzWith (Real.toNNReal |s|) (fun z : ℝ => |s| * |z|) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,← mul_sub,abs_mul,abs_abs,Real.coe_toNNReal _ (abs_nonneg s)] + exact mul_le_mul_of_nonneg_left (abs_abs_sub_abs_le_abs_sub x y) (abs_nonneg s) + +lemma gaussianSmallError_nonneg {β : ℝ} (hβ : 0≤β) (s : ℝ) : + 0≤gaussianSmallError β s := by + have hi : Integrable (fun z : ℝ => |s| * |z|) (gaussianReal 0 1) := by + simpa only [zero_add,one_mul] using integrable_shift (abs_scaled_lipschitz s) 0 1 + have he : Integrable (fun z : ℝ => Real.exp (β*(|s| * |z|))) (gaussianReal 0 1) := by + simpa only [zero_add,one_mul] using integrable_exp_shift (abs_scaled_lipschitz s) β 0 1 + exact (integral_nonneg fun _ => mul_nonneg (abs_nonneg _) (abs_nonneg _)).trans + (logMean_expectation_le hβ hi he) + + + +lemma step_id_error {β a : ℝ} (ha : 0≤a) (hab : a≤β) {f : ℝ → ℝ} + (hf : LipschitzWith 1 f) (s x : ℝ) : + |step a s f x-f x|≤gaussianSmallError β s := by + let g (z : ℝ) := |s| * |z| + have hgi : Integrable g (gaussianReal 0 1) := by + simpa only [zero_add,one_mul] using integrable_shift (abs_scaled_lipschitz s) 0 1 + have hge (b : ℝ) : Integrable (fun z => Real.exp (b*g z)) (gaussianReal 0 1) := by + simpa only [zero_add,one_mul] using integrable_exp_shift (abs_scaled_lipschitz s) b 0 1 + have hpoint (z : ℝ) : |f (x+s*z)-f x|≤g z := by + simpa only [Real.dist_eq,NNReal.coe_one,one_mul,add_sub_cancel_left,abs_mul] using hf.dist_le_mul (x+s*z) x + have hupper : step a s f x≤logMean (gaussianReal 0 1) a g+f x := by + exact logMean_le_add ha (integrable_shift hf x s) hgi (integrable_exp_shift hf a x s) + (hge a) (f x) (fun z => by have hh := (abs_le.mp (hpoint z)).2; linarith) + have hmono : logMean (gaussianReal 0 1) a g≤gaussianSmallError β s := + logMean_parameter_mono ha hab hgi (hge a) (hge β) + have hexp : (∫ z,f (x+s*z) ∂gaussianReal 0 1)≤ step a s f x := + logMean_expectation_le ha (integrable_shift hf x s) (integrable_exp_shift hf a x s) + have hgexp : (∫ z,g z ∂gaussianReal 0 1)≤gaussianSmallError β s := + logMean_expectation_le (ha.trans hab) hgi (hge β) + have hlow : f x-(∫ z,g z ∂gaussianReal 0 1)≤∫ z,f (x+s*z) ∂gaussianReal 0 1 := by + have hh := integral_mono ((integrable_const (f x)).sub hgi) (integrable_shift hf x s) + (fun z => by have hp := (abs_le.mp (hpoint z)).1; simp only [Pi.sub_apply]; linarith) + simpa only [Pi.sub_apply,integral_sub (integrable_const _) hgi,integral_const,probReal_univ,one_smul] using hh + rw [abs_le] + constructor <;> linarith + +lemma gaussianSmallError_grid_tendsto (β : ℝ) : + Tendsto (fun m : ℕ => gaussianSmallError β (Real.sqrt (1/(m+1:ℕ)))) atTop (𝓝 0) := by + let s (m : ℕ) := Real.sqrt (1/(m+1:ℕ)) + have hs (m : ℕ) : 0≤ s m := Real.sqrt_nonneg _ + have hs1 (m : ℕ) : s m≤1 := by + apply Real.sqrt_le_one.mpr + exact (div_le_one (by positivity : (0:ℝ)<(m+1:ℕ))).mpr (by exact_mod_cast Nat.succ_le_succ (Nat.zero_le m)) + have ht : Tendsto s atTop (𝓝 (0:ℝ)) := by + simpa only [Real.sqrt_zero,Function.comp_def,s] using Real.continuous_sqrt.continuousAt.tendsto.comp SKCavity.tendsto_succ_reciprocal + have hF (m : ℕ) : LipschitzWith 1 (fun z : ℝ => |s m| * |z|) := + (abs_scaled_lipschitz (s m)).weaken (by simpa only [abs_of_nonneg (hs m),Real.toNNReal_le_one] using hs1 m) + have hf : LipschitzWith 1 (fun _ : ℝ => (0:ℝ)) := (LipschitzWith.const (0:ℝ)).weaken (by norm_num) + have hh := step_tendsto (fun k => hF k) hf (fun z => by simpa using (ht.abs).mul_const |z|) β 1 0 + simpa only [step,zero_add,one_mul,logMean_const,gaussianSmallError] using hh + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma gaussian_pair_sum_map (s t : ℝ) : + ((gaussianReal 0 1).prod (gaussianReal 0 1)).map (fun p : ℝ×ℝ => s*p.1+t*p.2)= + (gaussianReal 0 1).map (fun z => Real.sqrt (s^2+t^2)*z) := by + let μ := gaussianReal (0:ℝ) 1 + have hi : IndepFun (fun p : ℝ×ℝ => s*p.1) (fun p : ℝ×ℝ => t*p.2) (μ.prod μ) := + indepFun_prod (by fun_prop) (by fun_prop) + have hX : (μ.prod μ).map (fun p : ℝ×ℝ => s*p.1)=gaussianReal 0 (⟨s^2,sq_nonneg s⟩ : ℝ≥0) := by + change (μ.prod μ).map ((fun z : ℝ => s*z) ∘ Prod.fst)=_ + rw [← Measure.map_map (by fun_prop : Measurable (fun z : ℝ => s*z)) measurable_fst] + simp [μ,gaussianReal_map_const_mul,NNReal.mk] + congr 1 + ext + change s^2 * 1 = s^2 + ring + have hY : (μ.prod μ).map (fun p : ℝ×ℝ => t*p.2)=gaussianReal 0 (⟨t^2,sq_nonneg t⟩ : ℝ≥0) := by + change (μ.prod μ).map ((fun z : ℝ => t*z) ∘ Prod.snd)=_ + rw [← Measure.map_map (by fun_prop : Measurable (fun z : ℝ => t*z)) measurable_snd] + simp [μ,gaussianReal_map_const_mul,NNReal.mk] + congr 1 + ext + change t^2 * 1 = t^2 + ring + have hh := gaussianReal_add_gaussianReal_of_indepFun hi { map_eq := hX } { map_eq := hY } + change (μ.prod μ).map (fun p : ℝ×ℝ => s*p.1+t*p.2)= + gaussianReal (0+0) ((⟨s^2,sq_nonneg s⟩ : ℝ≥0)+(⟨t^2,sq_nonneg t⟩ : ℝ≥0)) at hh + simp only [zero_add] at hh + rw [hh,gaussianReal_map_const_mul] + congr 1 + · simp + · ext + change s^2+t^2 = (Real.sqrt (s^2+t^2))^2 * 1 + rw [Real.sq_sqrt (add_nonneg (sq_nonneg s) (sq_nonneg t)),mul_one] + +lemma gaussian_pair_integrable {F : ℝ → ℝ} (hF : Measurable F) (s t : ℝ) + (hi : Integrable (fun z => F (Real.sqrt (s^2+t^2)*z)) (gaussianReal 0 1)) : + Integrable (fun p : ℝ×ℝ => F (s*p.1+t*p.2)) ((gaussianReal 0 1).prod (gaussianReal 0 1)) := by + have hm : Integrable F ((gaussianReal 0 1).map (fun z => Real.sqrt (s^2+t^2)*z)) := + (integrable_map_measure hF.aestronglyMeasurable (by fun_prop)).mpr hi + rw [← gaussian_pair_sum_map s t] at hm + exact hm.comp_measurable (by fun_prop) + +lemma gaussian_pair_integral {F : ℝ → ℝ} (hF : Measurable F) (s t : ℝ) : + (∫ p : ℝ×ℝ,F (s*p.1+t*p.2) ∂(gaussianReal 0 1).prod (gaussianReal 0 1))= + ∫ z,F (Real.sqrt (s^2+t^2)*z) ∂gaussianReal 0 1 := by + rw [← integral_map (by fun_prop : Measurable (fun p : ℝ×ℝ => s*p.1+t*p.2)).aemeasurable + hF.aestronglyMeasurable,gaussian_pair_sum_map, + integral_map (by fun_prop) hF.aestronglyMeasurable] + +lemma exp_step {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) {a : ℝ} (ha : a≠0) + (s x : ℝ) : Real.exp (a*step a s f x)=∫ z,Real.exp (a*f (x+s*z)) ∂gaussianReal 0 1 := by + simp only [step,logMean,ha,↓reduceIte] + rw [mul_div_cancel₀ _ ha,Real.exp_log (integral_exp_pos (integrable_exp_shift hf a x s))] + + +lemma step_semigroup {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (a s t x : ℝ) : + step a s (step a t f) x=step a (Real.sqrt (s^2+t^2)) f x := by + by_cases ha : a=0 + · subst a + simp only [step,logMean_zero] + have hm : Measurable (fun y => f (x+y)) := hf.continuous.measurable.comp (by fun_prop) + have hi := gaussian_pair_integrable hm s t (integrable_shift hf x (Real.sqrt (s^2+t^2))) + have hh := gaussian_pair_integral hm s t + rw [integral_prod _ hi] at hh + simpa only [add_assoc] using hh + · have hm : Measurable (fun y => Real.exp (a*f (x+y))) := Real.measurable_exp.comp ((hf.continuous.measurable.comp (by fun_prop)).const_mul a) + have hi := gaussian_pair_integrable hm s t (integrable_exp_shift hf a x (Real.sqrt (s^2+t^2))) + have hh := gaussian_pair_integral hm s t + rw [integral_prod _ hi] at hh + simp only [step,logMean,ha,↓reduceIte] + have he (z : ℝ) : Real.exp (a*(Real.log (∫ y,Real.exp (a*f (x+s*z+t*y)) ∂gaussianReal 0 1)/a))= + ∫ y,Real.exp (a*f (x+s*z+t*y)) ∂gaussianReal 0 1 := by + simpa only [step,logMean,ha,↓reduceIte] using exp_step hf ha t (x+s*z) + simp_rw [he] + congr 2 + simpa only [add_assoc] using hh + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + + +def evolve : Schedule → (ℝ → ℝ) → ℝ → ℝ + | [],f => f + | (a,d)::ls,f => step a (Real.sqrt d) (evolve ls f) + +lemma evolve_lipschitz {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (ls : Schedule) : + LipschitzWith L (evolve ls f) := by + induction ls with + | nil => exact hf + | cons l ls ih => exact step_lipschitz ih l.1.coe_nonneg _ + +lemma recursion_eq_evolve (β : ℝ) (ls : Schedule) : recursion β ls=evolve ls (terminal β) := by + induction ls with + | nil => rfl + | cons l ls ih => simp only [recursion,evolve,ih] + +lemma evolve_append (ls rs : Schedule) (f : ℝ → ℝ) : + evolve (ls++rs) f=evolve ls (evolve rs f) := by + induction ls with + | nil => rfl + | cons l ls ih => simp only [List.cons_append,evolve,ih] + +lemma evolve_stable {L K : ℝ≥0} {f g : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : LipschitzWith K g) (ls : Schedule) (c : ℝ) (hfg : ∀ x,|f x-g x|≤c) : + ∀ x,|evolve ls f x-evolve ls g x|≤c := by + induction ls with + | nil => exact hfg + | cons l ls ih => + exact fun x => step_stable (evolve_lipschitz hf ls) (evolve_lipschitz hg ls) l.1.coe_nonneg _ x c ih + +lemma evolve_mono {L K : ℝ≥0} {f g : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : LipschitzWith K g) (ls : Schedule) (hfg : ∀ x,f x≤g x) : + ∀ x,evolve ls f x≤evolve ls g x := by + induction ls with + | nil => exact hfg + | cons l ls ih => + exact fun x => step_le_of_le (evolve_lipschitz hf ls) (evolve_lipschitz hg ls) l.1.coe_nonneg _ x ih + + + +lemma evolve_shift_error {β : ℝ} {a b d : ℝ≥0} (ha : (a:ℝ)≤β) (hb : (b:ℝ)≤β) + (mid : Schedule) {f : ℝ → ℝ} (hf : LipschitzWith 1 f) (x : ℝ) : + |evolve ((a,d)::mid) f x-evolve (mid++[(b,d)]) f x|≤ + 2*gaussianSmallError β (Real.sqrt d) := by + let full := (a,d)::(mid++[(b,d)]) + have hleft : |evolve full f x-evolve ((a,d)::mid) f x|≤gaussianSmallError β (Real.sqrt d) := by + have hh := evolve_stable (step_lipschitz hf b.coe_nonneg (Real.sqrt d)) hf ((a,d)::mid) + (gaussianSmallError β (Real.sqrt d)) (fun y => step_id_error b.coe_nonneg hb hf _ y) x + simpa only [full,evolve_append,evolve,List.cons_append] using hh + have hright : |evolve full f x-evolve (mid++[(b,d)]) f x|≤gaussianSmallError β (Real.sqrt d) := + step_id_error a.coe_nonneg ha (evolve_lipschitz hf _) _ x + calc + _ ≤ |evolve ((a,d)::mid) f x-evolve full f x|+|evolve full f x-evolve (mid++[(b,d)]) f x| := abs_sub_le _ _ _ + _ ≤ gaussianSmallError β (Real.sqrt d)+gaussianSmallError β (Real.sqrt d) := + add_le_add (by simpa only [abs_sub_comm] using hleft) hright + _ = _ := by ring + +lemma evolve_split {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a d e : ℝ≥0) (ls : Schedule) : + evolve ((a,d)::(a,e)::ls) f=evolve ((a,d+e)::ls) f := by + funext x + change step a (Real.sqrt d) (step a (Real.sqrt e) (evolve ls f)) x=_ + rw [step_semigroup (evolve_lipschitz hf ls),Real.sq_sqrt d.coe_nonneg,Real.sq_sqrt e.coe_nonneg] + rfl + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +def dyadicSchedule (γ : ℝ≥0 → ℝ≥0) (upper : Bool) (t d : ℝ≥0) : ℕ → Schedule + | 0 => [(γ (if upper then t+d else t),d)] + | n+1 => dyadicSchedule γ upper t (d/2) n ++ dyadicSchedule γ upper (t+d/2) (d/2) n + +def dyadicMesh (d : ℝ≥0) (n : ℕ) : ℝ≥0 := d/2^n + +lemma dyadicMesh_succ (d : ℝ≥0) (n : ℕ) : dyadicMesh d (n+1)=dyadicMesh (d/2) n := by + simp only [dyadicMesh,pow_succ,div_div] + congr 1 + exact mul_comm _ _ + +lemma dyadicSchedule_nonempty (γ : ℝ≥0 → ℝ≥0) (u : Bool) (t d : ℝ≥0) (n : ℕ) : + dyadicSchedule γ u t d n≠[] := by + induction n generalizing t d with + | zero => simp [dyadicSchedule] + | succ n ih => + intro h + exact ih t (d/2) (List.append_eq_nil_iff.mp h).1 + +lemma dyadicSchedule_shift (γ : ℝ≥0 → ℝ≥0) (t d : ℝ≥0) (n : ℕ) : + dyadicSchedule γ false t d n++[(γ (t+d),dyadicMesh d n)]= + (γ t,dyadicMesh d n)::dyadicSchedule γ true t d n := by + induction n generalizing t d with + | zero => simp [dyadicSchedule,dyadicMesh] + | succ n ih => + have he : t+d/2+d/2=t+d := by ring + simp only [dyadicSchedule,dyadicMesh_succ,List.append_assoc] + rw [← he,ih (t+d/2) (d/2)] + rw [← List.singleton_append,← List.append_assoc,ih t (d/2),List.cons_append] + +lemma dyadicSchedule_grid_error {β : ℝ} {γ : ℝ≥0 → ℝ≥0} + (hγ : ∀ t,(γ t:ℝ)≤β) (t d : ℝ≥0) (n : ℕ) {f : ℝ → ℝ} + (hf : LipschitzWith 1 f) (x : ℝ) : + |evolve (dyadicSchedule γ false t d n) f x-evolve (dyadicSchedule γ true t d n) f x|≤ + 2*gaussianSmallError β (Real.sqrt (dyadicMesh d n)) := by + have hs := dyadicSchedule_shift γ t d n + have hn := dyadicSchedule_nonempty γ false t d n + generalize he : dyadicSchedule γ false t d n=ls at hs hn ⊢ + cases ls with + | nil => exact (hn rfl).elim + | cons c mid => + simp only [List.cons_append,List.cons.injEq] at hs + rw [hs.1,← hs.2] + exact evolve_shift_error (hγ t) (hγ (t+d)) mid hf x + +lemma dyadicSchedule_low_le_high {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (n : ℕ) (x : ℝ) : + evolve (dyadicSchedule γ false t d n) f x≤evolve (dyadicSchedule γ true t d n) f x := by + induction n generalizing t d f x with + | zero => + exact step_parameter_mono hf (γ t).coe_nonneg (by exact_mod_cast hγ (le_add_of_nonneg_right (show 0≤d from zero_le))) _ x + | succ n ih => + simp only [dyadicSchedule,evolve_append] + exact (evolve_mono (evolve_lipschitz hf _) (evolve_lipschitz hf _) _ + (fun y => ih hf (t+d/2) (d/2) y) x).trans + (ih (evolve_lipschitz hf _) t (d/2) x) + +lemma dyadicSchedule_low_refine {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (n : ℕ) (x : ℝ) : + evolve (dyadicSchedule γ false t d n) f x≤evolve (dyadicSchedule γ false t d (n+1)) f x := by + induction n generalizing t d f x with + | zero => + have he : d/2+d/2=d := by ring + have hh := evolve_split hf (γ t) (d/2) (d/2) [] + rw [he] at hh + change evolve [(γ t,d)] f x≤evolve [(γ t,d/2),(γ (t+d/2),d/2)] f x + rw [← hh] + exact step_le_of_le (step_lipschitz hf (γ t).coe_nonneg _) (step_lipschitz hf (γ (t+d/2)).coe_nonneg _) + (γ t).coe_nonneg _ x (fun y => step_parameter_mono hf (γ t).coe_nonneg + (by exact_mod_cast hγ (le_add_of_nonneg_right (show 0≤d/2 from zero_le))) _ y) + | succ n ih => + change evolve (dyadicSchedule γ false t (d/2) n ++ dyadicSchedule γ false (t+d/2) (d/2) n) f x ≤ + evolve (dyadicSchedule γ false t (d/2) (n+1) ++ dyadicSchedule γ false (t+d/2) (d/2) (n+1)) f x + rw [evolve_append,evolve_append] + exact (evolve_mono (evolve_lipschitz hf _) (evolve_lipschitz hf _) _ + (fun y => ih hf (t+d/2) (d/2) y) x).trans + (ih (evolve_lipschitz hf _) t (d/2) x) + +lemma dyadicSchedule_high_refine {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (t d : ℝ≥0) (n : ℕ) (x : ℝ) : + evolve (dyadicSchedule γ true t d (n+1)) f x≤evolve (dyadicSchedule γ true t d n) f x := by + induction n generalizing t d f x with + | zero => + have he : d/2+d/2=d := by ring + have ht : t+d/2+d/2=t+d := by ring + have hh := evolve_split hf (γ (t+d)) (d/2) (d/2) [] + rw [he] at hh + simp only [dyadicSchedule,↓reduceIte,List.singleton_append,ht] + rw [← hh] + exact step_parameter_mono (step_lipschitz hf (γ (t+d)).coe_nonneg _) (γ (t+d/2)).coe_nonneg + (by exact_mod_cast hγ (show t+d/2≤t+d by gcongr; exact half_le_self (show 0≤d from zero_le))) _ x + | succ n ih => + change evolve (dyadicSchedule γ true t (d/2) (n+1) ++ dyadicSchedule γ true (t+d/2) (d/2) (n+1)) f x ≤ + evolve (dyadicSchedule γ true t (d/2) n ++ dyadicSchedule γ true (t+d/2) (d/2) n) f x + rw [evolve_append,evolve_append] + exact (evolve_mono (evolve_lipschitz hf _) (evolve_lipschitz hf _) _ + (fun y => ih hf (t+d/2) (d/2) y) x).trans + (ih (evolve_lipschitz hf _) t (d/2) x) + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/PacketLabel.lean b/lean/OAI/Probability/ParisiFinite/PacketLabel.lean new file mode 100644 index 0000000000000000000000000000000000000000..93e919895d6ecc0e66a3d517368f72a912b1f674 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/PacketLabel.lean @@ -0,0 +1,629 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Energy + +namespace OAI + +/-! Packet Label. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus RootSpin + +abbrev PacketLabel := Fin 2 × Fin 2 + + + +structure CausalStage (b : ℝ) (n : ℕ) (κ : Type*) [Fintype κ] where + frame : TaggedFrame b n κ + trace : List (TraceGate κ) + valid : TraceWord.Valid frame.history trace + depth : (TraceWord.forget trace).length≤n + centers : PacketLabel → ℝ → ModeInfinity + coefficients : PacketLabel → κ → ℂ + stage : PacketStage atTop amplitude (fun T => (amplitude T)⁻¹) centers Prod.snd + lowClose : PacketUnitaryFamily.LowClose stage.low + (WeylWord.family (TraceWord.encode trace) frame.frame.gram) + centerClose : ∀i,Tendsto (fun T => ‖centers i T- + combination (frame.frame.actual T) (coefficients i)‖) atTop (𝓝 0) + centerPacket : ∀i,ApproxPacket atTop (fun T => modeFock (centers i T)) + radius : ℝ + radius_nonneg : 0≤radius + centerBound : ∀i,∀ᶠ T in atTop,‖centers i T‖≤radius + transport : stage.Transported (fun T => modeFock (addressInfinity b T)) + +namespace CausalStage +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + +def visible (s : CausalStage b n κ) : Prop := + ∀i,s.frame.frame.visibility s.trace (s.coefficients i) Z≠0 + +def projections (s : CausalStage b n κ) (i : PacketLabel) : ℝ×ℝ := + (s.frame.frame.visibility s.trace (s.coefficients i) Z, + s.frame.frame.visibility s.trace (s.coefficients i) Y) + +theorem projections_nonzero (s : CausalStage b n κ) (hv : s.visible) (i : PacketLabel) : + s.projections i≠0 := by + intro h + exact hv i (congrArg Prod.fst h) + +theorem projections_Z (s : CausalStage b n κ) (i : PacketLabel) : + Tendsto (fun T => -2*(⟪insertionInfinity (s.stage.word T),s.centers i T⟫_ℂ).im) + atTop (𝓝 (s.projections i).1) := + s.frame.frame.visibility_Z s.stage s.trace s.lowClose (s.coefficients i) (s.centers i) (s.centerClose i) + +theorem projections_Y (s : CausalStage b n κ) (i : PacketLabel) : + Tendsto (fun T => -2*(⟪insertionYInfinity (s.stage.word T),s.centers i T⟫_ℂ).im) + atTop (𝓝 (s.projections i).2) := + s.frame.frame.visibility_Y s.stage s.trace s.lowClose (s.coefficients i) (s.centers i) (s.centerClose i) + + + +def record (s : CausalStage b n κ) (hb : 0 TraceWord.forget s.trace)) (fun _ => rfl) s.valid + depth := by simpa only [TraceWord.forget_reindex] using s.depth.trans (Nat.le_succ n) + centers := s.centers + coefficients i := Sum.elim (s.coefficients i) 0 + stage := s.stage + lowClose := by + intro x hx + have hh := s.lowClose x hx + convert hh using 1 + funext T + congr 2 + exact congrArg (fun U : SpinSpace ModeInfinity ≃ₗᵢ[ℂ] SpinSpace ModeInfinity => U (x T)) + (TraceWord.op_reindex Sum.inl s.trace (seedDirections b T) + (s.frame.frame.actual T) (Sum.elim (s.frame.frame.actual T) + (fun _ : Unit => insertionInfinity (s.stage.word T))) (fun _ => rfl)) + centerClose i := by + change Tendsto (fun T => ‖s.centers i T-combination + (Sum.elim (s.frame.frame.actual T) (fun _ : Unit => insertionInfinity (s.stage.word T))) + (Sum.elim (s.coefficients i) 0)‖) atTop (𝓝 0) + simpa only [combination_sum_zero] using s.centerClose i + centerPacket := s.centerPacket + radius := s.radius + radius_nonneg := s.radius_nonneg + centerBound := s.centerBound + transport := s.transport + + + +def cost (s : CausalStage b n κ) (hb : 0 ‖WZ (-(c:ℂ) • insertionInfinity (t.stage.word T)) (t.stage.low.op T (x T))- + WZ (combination (t.frame.frame.directions T) (TraceGate.coeffCost (Sum.inr ()) c)) + (WeylWord.op (t.frame.frame.directions T) (TraceWord.encode t.trace) (x T))‖) atTop (𝓝 0) + have he (T : ℝ) : t.frame.frame.directions T (Sum.inr (Sum.inr ()))= + insertionInfinity (t.stage.word T) := rfl + simp only [TraceGate.combination_cost,he,←map_sub,norm_WZ] + exact hh + +end CausalStage +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus RootSpin +namespace CausalStage +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + + + +theorem exists_mixer (s : CausalStage b n κ) (hb : 0 modeFock (addressInfinity b T)) s.transport amplitude_zero amplitude_eventually_pos + s.radius s.radius_nonneg s.centerBound s.projections (s.projections_nonzero hv) + s.projections_Z s.projections_Y + let t := s.record hb + have hc : PacketUnitaryFamily.LowClose st'.low + (WeylWord.family (TraceWord.encode (.mixer theta::t.trace)) t.frame.frame.gram) := by + intro x hx + have h := t.lowClose x hx + change Tendsto (fun T => ‖st'.low.op T (x T)- + SpinOperators.act (R theta) (WeylWord.op (t.frame.frame.directions T) (TraceWord.encode t.trace) (x T))‖) + atTop (𝓝 0) + simp only [hl,←map_sub,SpinOperators.norm_act (R_unitary _)] + exact h + have hd : (TraceWord.forget (.mixer theta::t.trace)).length≤n+1 := by + change (TraceWord.forget t.trace).length+1≤n+1 + dsimp only [t,record] + rw [TraceWord.forget_reindex] + exact Nat.add_le_add_right s.depth 1 + let s' : CausalStage b (n+1) (κ ⊕ Unit) := { + frame := t.frame + trace := .mixer theta::t.trace + valid := t.valid + depth := hd + centers := s.centers + coefficients := t.coefficients + stage := st' + lowClose := hc + centerClose := t.centerClose + centerPacket := s.centerPacket + radius := s.radius + radius_nonneg := s.radius_nonneg + centerBound := s.centerBound + transport := ht } + exact ⟨K,a,s',rfl,hw,rfl,(fun _ => rfl),rfl⟩ + + +def initialCoefficient (b : ℝ) (i : PacketLabel) : ℂ := + if i.1=0 then (-2*b:ℂ) else (2*b:ℂ) + +theorem initialCenter_coefficient (b : ℝ) (i : PacketLabel) : + initialCenter b i.1=initialCoefficient b i • eInfinity := by + unfold initialCenter signedMode initialCoefficient + split_ifs <;> simp [←Complex.coe_smul,Complex.ofReal_mul] + + + +def initial (b : ℝ) (hb : 0 initialCoefficient b i) + stage := reciprocalInitialStage b + lowClose := initial_lowClose b _ + centerClose i := by + have he (T : ℝ) : combination ((initialRecorded b hb 1).frame.actual T) + (Sum.elim PEmpty.elim (fun _ => initialCoefficient b i))=initialCenter b i.1 := by + change combination (Sum.elim PEmpty.elim (fun _ : Unit => eInfinity)) + (Sum.elim PEmpty.elim (fun _ => initialCoefficient b i))=_ + simp only [combination,Fintype.sum_sum_type,Fintype.sum_empty,zero_add,Fintype.sum_unique] + exact (initialCenter_coefficient b i).symm + change Tendsto (fun T => ‖initialCenter b i.1-combination + ((initialRecorded b hb 1).frame.actual T) + (Sum.elim PEmpty.elim (fun _ => initialCoefficient b i))‖) atTop (𝓝 0) + convert (tendsto_const_nhds : Tendsto (fun _ : ℝ => (0:ℝ)) atTop (𝓝 0)) using 1 + funext T + rw [he] + simp + centerPacket i := by + simp only [initialCenter_coefficient,map_smul,modeFock_eInfinity] + exact ((BoundedPacket.vacuum.root Z).approx).smul (initialCoefficient b i) + radius := 2*|b| + radius_nonneg := by positivity + centerBound i := Eventually.of_forall fun _ => (norm_initialCenter b i.1).le + transport := by + have h := initialStage_transported b + unfold PacketStage.Transported at h ⊢ + simpa only [reciprocalInitialStage,amplitude_inverse,id_eq] using h + +end CausalStage +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance ecRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance ecRealSMul : SMul ℝ ModeInfinity := ecRealModule.toDistribMulAction.toSMul +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +def echoReference (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (i : κ) (q : α) : ModeInfinity := + d i q+signedMode (spin i) ((-2*t) • insertionInfinity (st.word q)) + +theorem halfEchoCenter_sub_reference (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (i : κ) (q : α) (hr : r q≠0) : + st.halfEchoCenter t a K i q-st.echoReference t i q= + -signedMode (spin i) (r q • st.halfEchoResidual t a K q) := by + have hm : r q*(t/r q)=t := by field_simp + have he : r q • st.halfEchoResidual t a K q= + t • (insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K)- + insertionInfinity (st.word q)) := by + unfold halfEchoResidual + change (r q:ℂ) • (((t/r q:ℝ):ℂ) • + (insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K)-insertionInfinity (st.word q)))= + (t:ℂ) • (insertionInfinity (probePrefix (r q) (st.forwardWord t q) a K)-insertionInfinity (st.word q)) + rw [smul_smul,←Complex.ofReal_mul,hm] + rw [he] + have hf (j : Fin 2) (v : ModeInfinity) : signedMode (1-j) v = -signedMode j v := by + fin_cases j <;> simp [signedMode] + unfold halfEchoCenter forwardCenter echoReference + rw [hf] + unfold signedMode + split_ifs + all_goals simp only [←Complex.coe_smul,Complex.ofReal_neg,Complex.ofReal_mul, + Complex.ofReal_ofNat,neg_neg] + all_goals module + +theorem halfEchoCenter_close (st : PacketStage l r (fun q => (r q)⁻¹) d spin) + (t : ℝ) (a : ℕ → ShortPulse) (K : ℕ) (i : κ) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 ‖st.halfEchoCenter t a K i q-st.echoReference t i q‖) l (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [zero_mul] using hr.mul_const G) + filter_upwards [hp,hg] with q hq hgq + rw [st.halfEchoCenter_sub_reference t a K i q hq.ne',norm_neg,norm_signedMode, + norm_smul,Real.norm_eq_abs,abs_of_pos hq] + exact mul_le_mul_of_nonneg_left hgq hq.le + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus RootSpin +local instance ceRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance ceRealSMul : SMul ℝ ModeInfinity := ceRealModule.toDistribMulAction.toSMul +namespace CausalStage +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + +def echoAngles (t : ℝ) (i : Fin 2) : ℝ := if i=0 then 0 else 2*t + +def echoCoefficient (t : ℝ) (i : PacketLabel) : ℂ := + if i.2=0 then (-2*t:ℂ) else (2*t:ℂ) + +def echoCoefficients (s : CausalStage b n κ) (t : ℝ) (i : PacketLabel) : κ ⊕ Unit → ℂ := + Sum.elim (s.coefficients i) (fun _ => echoCoefficient t i) + +def echoTrace (s : CausalStage b n κ) (t : ℝ) : List (TraceGate (κ ⊕ Unit)) := + .seed (echoAngles t)::s.trace.map (TraceGate.reindex Sum.inl) + +def echoVisible (s : CausalStage b n κ) (hb : 0 simp [←Complex.coe_smul,Complex.ofReal_mul] + +theorem echo_combination (s : CausalStage b n κ) (hb : 0 insertionInfinity (s.stage.word T))) + (Sum.elim (s.coefficients i) (fun _ => echoCoefficient t i))=_ + simp only [combination,Fintype.sum_sum_type,Fintype.sum_unique,Sum.elim_inl,Sum.elim_inr,signed_echo] + +theorem echo_seed_combination (f : CausalFrame b n κ) (t T : ℝ) : + combination (f.directions T) (TraceGate.coeffSeed (echoAngles t))= + (-2*t) • addressInfinity b T := by + rw [show TraceGate.coeffSeed (κ:=κ) (echoAngles t)= + Sum.elim (fun i => -(echoAngles t i:ℂ)) 0 from rfl] + change combination (Sum.elim (seedDirections b T) (f.actual T)) _=_ + rw [combination_sum_zero] + simp [combination,Fin.sum_univ_two,echoAngles,seedDirections,←Complex.coe_smul,Complex.ofReal_mul] + +theorem echo_centerClose (s : CausalStage b n κ) (hb : 0 ‖s.stage.halfEchoCenter t a K i T- + combination ((s.record hb).frame.frame.actual T) (s.echoCoefficients t i)‖) atTop (𝓝 0) := by + have h1 := s.stage.halfEchoCenter_close t a K i amplitude_zero amplitude_eventually_pos G hg + have h2 : Tendsto (fun T => ‖s.stage.echoReference t i T- + combination ((s.record hb).frame.frame.actual T) (s.echoCoefficients t i)‖) atTop (𝓝 0) := by + simpa only [PacketStage.echoReference,echo_combination,add_sub_add_right_eq_sub] using s.centerClose i + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [add_zero] using h1.add h2) + exact Eventually.of_forall fun T => norm_sub_le_norm_sub_add_norm_sub _ _ _ + +theorem echo_lowClose (s : CausalStage b n κ) (hb : 0 (amplitude T)⁻¹) + (s.stage.halfEchoCenter t a K) (fun i => 1-i.2)) + (hl : ∀T x,st.low.op T x=WZ (s.stage.halfEchoResidual t a K T) (s.stage.low.op T x)) + (he : Tendsto (fun T => ‖s.stage.halfEchoResidual t a K T-(-2*t) • addressInfinity b T‖) atTop (𝓝 0)) : + PacketUnitaryFamily.LowClose st.low + (WeylWord.family (TraceWord.encode (s.echoTrace t)) (s.record hb).frame.frame.gram) := by + intro x hx + let f := (s.record hb).frame.frame + let w := (s.record hb).trace + let y (T : ℝ) := WeylWord.op (f.directions T) (TraceWord.encode w) (x T) + have hy : BoundedPacket atTop y := (WeylWord.family (TraceWord.encode w) f.gram).forward x hx + have h1 := (s.record hb).lowClose x hx + change Tendsto (fun T => ‖s.stage.low.op T (x T)-y T‖) atTop (𝓝 0) at h1 + have h2 := hy.pulse_close (s.stage.halfEchoResidual t a K) + (fun T => (-2*t) • addressInfinity b T) (2*|t|) + (Eventually.of_forall fun T => by + simp [norm_smul,Real.norm_eq_abs,norm_addressInfinity]) he + change Tendsto (fun T => ‖st.low.op T (x T)- + WZ (combination (f.directions T) (TraceGate.coeffSeed (echoAngles t))) (y T)‖) atTop (𝓝 0) + simp only [hl,echo_seed_combination] + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [add_zero] using h1.add h2) + exact Eventually.of_forall fun T => by + have h := norm_sub_le_norm_sub_add_norm_sub + (WZ (s.stage.halfEchoResidual t a K T) (s.stage.low.op T (x T))) + (WZ (s.stage.halfEchoResidual t a K T) (y T)) (WZ ((-2*t) • addressInfinity b T) (y T)) + simpa only [←map_sub,norm_WZ] using h + + + +def restoredSpin {d : PacketLabel → ℝ → ModeInfinity} + (st : PacketStage atTop amplitude (fun T => (amplitude T)⁻¹) d (fun i => 1-(1-i.2))) : + PacketStage atTop amplitude (fun T => (amplitude T)⁻¹) d Prod.snd where + word := st.word + ordinary := st.ordinary + special := st.special + split := st.split + special_norm := st.special_norm + low := st.low + phase := st.phase + phase_norm := st.phase_norm + ordinary_low := st.ordinary_low + special_packets x hx := by + have h : (fun i : PacketLabel => 1-(1-i.2))=Prod.snd := by + funext i + rcases i with ⟨i,j⟩ + fin_cases j <;> rfl + simpa only [h] using st.special_packets x hx + + + +theorem exists_echo (s : CausalStage b n κ) (hb : 0 (⟪insertionInfinity (s.stage.word T),s.centers i T⟫_ℂ).im) atTop + (𝓝 (-s.frame.frame.visibility s.trace (s.coefficients i) Z/2)) := by + have h := (s.projections_Z i).div_const (-2) + convert h using 1 + · funext T + ring + · congr 1 + dsimp only [projections] + ring + have hn (i : PacketLabel) : -s.frame.frame.visibility s.trace (s.coefficients i) Z/2≠0 := by + exact div_ne_zero (neg_ne_zero.mpr (hv i)) (by norm_num) + have hab : ∀ᶠ T in atTop,‖addressInfinity b T‖≤1 := + Eventually.of_forall fun T => (norm_addressInfinity b T).le + obtain ⟨K,a,st,hw,hl,htrans,he,hpacket⟩ := s.stage.exists_halfEcho t ht + amplitude_zero amplitude_eventually_pos s.radius s.radius_nonneg s.centerBound s.centerPacket + (fun i => -s.frame.frame.visibility s.trace (s.coefficients i) Z/2) hn hZ + (addressInfinity b) s.transport 1 (by norm_num) hab + have hg := s.stage.halfEchoResidual_bounded (addressInfinity b) t a K 1 (by norm_num) hab he + have hc := s.echo_centerClose hb t a K _ hg + have hlow := s.echo_lowClose hb t a K st hl he + let f := (s.record hb).frame.frame + let v (i : PacketLabel) : ℝ×ℝ := + (f.visibility (s.echoTrace t) (s.echoCoefficients t i) Z, + f.visibility (s.echoTrace t) (s.echoCoefficients t i) Y) + have hvv (i : PacketLabel) : v i≠0 := by + intro h + exact hv' i (congrArg Prod.fst h) + have hz (i : PacketLabel) : Tendsto + (fun T => -2*(⟪insertionInfinity (st.word T),s.stage.halfEchoCenter t a K i T⟫_ℂ).im) + atTop (𝓝 (v i).1) := + f.visibility_Z st (s.echoTrace t) hlow (s.echoCoefficients t i) _ (hc i) + have hy (i : PacketLabel) : Tendsto + (fun T => -2*(⟪insertionYInfinity (st.word T),s.stage.halfEchoCenter t a K i T⟫_ℂ).im) + atTop (𝓝 (v i).2) := + f.visibility_Y st (s.echoTrace t) hlow (s.echoCoefficients t i) _ (hc i) + have hbnd := s.stage.halfEchoCenter_bounded t a K s.radius s.centerBound + have hradius : 0 ≤ s.radius+2*|t| := add_nonneg s.radius_nonneg (by positivity) + obtain ⟨L,c,st',hw',hl',htrans'⟩ := st.exists_negativeFlip + (fun T => -modeFock (addressInfinity b T)) htrans + amplitude_zero amplitude_eventually_pos (s.radius+2*|t|) hradius hbnd v hvv hz hy + let s' : CausalStage b (n+1) (κ ⊕ Unit) := { + frame := (s.record hb).frame + trace := s.echoTrace t + valid := (s.record hb).valid + depth := by + change (TraceWord.forget (s.trace.map (TraceGate.reindex Sum.inl))).length+1≤n+1 + rw [TraceWord.forget_reindex] + exact Nat.add_le_add_right s.depth 1 + centers := s.stage.halfEchoCenter t a K + coefficients := s.echoCoefficients t + stage := restoredSpin st' + lowClose := by + intro x hx + simpa only [restoredSpin,hl'] using hlow x hx + centerClose := hc + centerPacket := hpacket + radius := s.radius+2*|t| + radius_nonneg := hradius + centerBound := hbnd + transport := by + unfold PacketStage.Transported at htrans' ⊢ + simpa only [restoredSpin,neg_neg] using htrans' } + exact ⟨K,L,a,c,s',rfl,fun T => by rw [show s'.stage.word T=st'.word T from rfl,hw',hw],rfl,rfl,rfl⟩ + +end CausalStage +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus RootSpin +namespace CausalStage +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + + + +theorem value_limit (s : CausalStage b n κ) (hb : 0 ordinaryValue (s.stage.word T)) atTop + (𝓝 (SeededTree.value (TraceWord.forget s.trace))) := by + have h := (s.record hb).frame.frame.energy (Sum.inr ()) + change Tendsto (fun T => energyInfinity (insertionInfinity (s.stage.word T))) atTop + (𝓝 (SeededTree.treeEnergy (n+1) + (SeededTree.circuit (TraceWord.forget s.trace) (n+1)).insertion)) at h + simpa only [energy_insertionInfinity,←SeededTree.value_eq_height _ _ (s.depth.trans (Nat.le_succ n))] using h + + + +theorem exists_word_close (s : CausalStage b n κ) (hb : 0 0 + | (t,w)::l => CausalStage.echoCoefficient t i • ((SeededTree.circuit w n).insertion : SeededTree.Level n)+centerTail n i l + +def center (s : ControlSignature) (b : ℝ) (n : ℕ) (i : PacketLabel) : SeededTree.Level n := + CausalStage.initialCoefficient b i • ((SeededTree.circuit [] n).insertion : SeededTree.Level n)+centerTail n i s.echoes + +def visibility (s : ControlSignature) (b : ℝ) (n : ℕ) (i : PacketLabel) : ℝ := + -2*(⟪((SeededTree.circuit s.word n).insertion : SeededTree.Level n),s.center b n i⟫_ℂ).im + +def Visible (s : ControlSignature) (b : ℝ) (n : ℕ) : Prop := ∀i,s.visibility b n i≠0 + +theorem centerTail_step (n : ℕ) (i : PacketLabel) (l : List (ℝ × List SeededTree.Gate)) + (hl : ∀p∈l,p.2.length≤n) : + (SeededTree.empty n).toLinearIsometry (centerTail n i l)=centerTail (n+1) i l := by + induction l with + | nil => simp only [centerTail,map_zero] + | cons p l ih => + have hp := hl p (by simp) + have hh : ∀q∈l,q.2.length≤n := fun q hq => hl q (by simp [hq]) + rcases p with ⟨t,w⟩ + simp only [centerTail,map_add,map_smul,ih hh] + congr 1 + exact congrArg (fun v : SeededTree.Mode (n+1) => CausalStage.echoCoefficient t i • (v : SeededTree.Level (n+1))) + (SeededTree.circuit_insertion_empty w n hp) + +theorem center_step (s : ControlSignature) (b : ℝ) (n : ℕ) + (hs : s.Causal n) (i : PacketLabel) : + (SeededTree.empty n).toLinearIsometry (s.center b n i)=s.center b (n+1) i := by + simp only [center,map_add,map_smul,centerTail_step n i s.echoes hs.2] + congr 1 + exact congrArg (fun v : SeededTree.Mode (n+1) => CausalStage.initialCoefficient b i • (v : SeededTree.Level (n+1))) + (SeededTree.circuit_insertion_empty [] n (by simp)) + +theorem causal_succ (s : ControlSignature) {n : ℕ} (hs : s.Causal n) : s.Causal (n+1) := + ⟨hs.1.trans (Nat.le_succ n),fun p hp => (hs.2 p hp).trans (Nat.le_succ n)⟩ + +theorem causal_mixer (s : ControlSignature) {n : ℕ} (hs : s.Causal n) (a : ℝ) : + (s.mixer a).Causal (n+1) := + ⟨Nat.add_le_add_right hs.1 1,fun p hp => (hs.2 p hp).trans (Nat.le_succ n)⟩ + +theorem causal_cost (s : ControlSignature) {n : ℕ} (hs : s.Causal n) (a : ℝ) : + (s.cost a).Causal (n+1) := + ⟨Nat.add_le_add_right hs.1 1,fun p hp => (hs.2 p hp).trans (Nat.le_succ n)⟩ + +theorem causal_echo (s : ControlSignature) {n : ℕ} (hs : s.Causal n) (t : ℝ) : + (s.echo t).Causal (n+1) := by + refine ⟨Nat.add_le_add_right hs.1 1,?_⟩ + intro p hp + rcases List.mem_cons.mp hp with rfl|hp + · exact hs.1.trans (Nat.le_succ n) + · exact (hs.2 p hp).trans (Nat.le_succ n) + +theorem visibility_step (s : ControlSignature) (b : ℝ) (n : ℕ) + (hs : s.Causal n) (i : PacketLabel) : + s.visibility b (n+1) i=s.visibility b n i := by + unfold visibility + rw [←s.center_step b n hs i,←SeededTree.circuit_insertion_empty s.word n hs.1] + change -2*(⟪(SeededTree.empty n).toLinearIsometry ((SeededTree.circuit s.word n).insertion : SeededTree.Level n), + (SeededTree.empty n).toLinearIsometry (s.center b n i)⟫_ℂ).im = _ + rw [LinearIsometry.inner_map_map] + +end ControlSignature +end SeedInitialization + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/PacketRegular.lean b/lean/OAI/Probability/ParisiFinite/PacketRegular.lean new file mode 100644 index 0000000000000000000000000000000000000000..42706375ec6e595ce2f5cef8831d80b840219c01 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/PacketRegular.lean @@ -0,0 +1,699 @@ +import Mathlib +import OAI.Probability.ParisiFinite.LowVector + +namespace OAI + +/-! Packet Regular. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +namespace PointedTree +open CoherentFock Complex RootSpin +variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] + + + +def PacketRegular (x : X) : (n : ℕ) → (X → Level n) → Prop + | 0,v => ∀q, AnalyticAt ℝ (fun t => v t q) x + | n+1,v => ∃ (ι : Type) (_ : Fintype ι) (a : X → ι → Fin 2 → ℂ) + (d : X → ι → Mode n), + (∀i q, AnalyticAt ℝ (fun t => a t i q) x) ∧ + (∀i, PacketRegular x n (fun t => (d t i : Level n))) ∧ + (∀t, v t=spinPacket (a t) (d t)) + +namespace PacketRegular +variable {x : X} + +theorem inner : ∀ (n : ℕ) {v w : X → Level n}, + PacketRegular x n v → PacketRegular x n w → + AnalyticAt ℝ (fun t => ⟪v t,w t⟫_ℂ) x := by + intro n + induction n with + | zero => + intro v w hv hw + change AnalyticAt ℝ (fun t => ∑q : Fin 2, ⟪v t q,w t q⟫_ℂ) x + apply Finset.analyticAt_fun_sum + intro q hq + simp only [RCLike.inner_apply] + exact (hw q).mul ((Complex.conjCLE.toContinuousLinearMap.analyticAt _).comp (hv q)) + | succ n ih => + intro v w hv hw + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + obtain ⟨κ,hk,b,e,hb,he,hw⟩ := hw + let := hi + let := hk + simp_rw [hv,hw] + apply analyticAt_inner_spinPacket a b d e ha hb + · intro i + exact ih (hd i) (hd i) + · intro j + exact ih (he j) (he j) + · intro i j + exact ih (hd i) (he j) + +theorem zero (n : ℕ) : PacketRegular x n (fun _ => 0) := by + cases n with + | zero => exact fun _ => analyticAt_const + | succ n => + refine ⟨Fin 0,inferInstance,fun _ i => Fin.elim0 i,fun _ i => Fin.elim0 i,?_,?_,?_⟩ + · intro i; exact Fin.elim0 i + · intro i; exact Fin.elim0 i + · intro t; simp [spinPacket] + +theorem add (n : ℕ) {v w : X → Level n} + (hv : PacketRegular x n v) (hw : PacketRegular x n w) : + PacketRegular x n (fun t => v t+w t) := by + cases n with + | zero => exact fun q => (hv q).add (hw q) + | succ n => + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + obtain ⟨κ,hk,b,e,hb,he,hw⟩ := hw + let := hi + let := hk + refine ⟨Sum ι κ,inferInstance,fun t => Sum.elim (a t) (b t), + fun t => Sum.elim (d t) (e t),?_,?_,?_⟩ + · intro i q; cases i with + | inl i => exact ha i q + | inr j => exact hb j q + · intro i; cases i with + | inl i => exact hd i + | inr j => exact he j + · intro t; dsimp only; rw [hv,hw,spinPacket_sum] + +theorem smul (n : ℕ) {v : X → Level n} {z : X → ℂ} + (hz : AnalyticAt ℝ z x) (hv : PacketRegular x n v) : + PacketRegular x n (fun t => z t • v t) := by + cases n with + | zero => exact fun q => hz.mul (hv q) + | succ n => + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + let := hi + refine ⟨ι,hi,fun t i q => z t*a t i q,d,fun i q => hz.mul (ha i q),hd,?_⟩ + intro t + dsimp only + rw [hv,spinPacket_smul] + +theorem neg (n : ℕ) {v : X → Level n} (hv : PacketRegular x n v) : + PacketRegular x n (fun t => -v t) := by + simpa using smul n (show AnalyticAt ℝ (fun _ : X => (-1:ℂ)) x from analyticAt_const) hv + +theorem vac (n : ℕ) : PacketRegular x n (fun _ => PointedTree.vac n) := by + cases n with + | zero => exact fun _ => analyticAt_const + | succ n => + refine ⟨Unit,inferInstance,fun _ _ _ => spinCoefficient,fun _ _ => 0, + fun _ _ => analyticAt_const,fun _ => zero n,?_⟩ + intro t + ext q + simp only [spinPacket_apply,Fintype.sum_unique] + rfl + +theorem root (n : ℕ) {v : X → Level n} {A : X → Matrix (Fin 2) (Fin 2) ℂ} + (hA : ∀i j, AnalyticAt ℝ (fun t => A t i j) x) (hv : PacketRegular x n v) : + PacketRegular x n (fun t => PointedTree.root n (A t) (v t)) := by + cases n with + | zero => + intro q + change AnalyticAt ℝ (fun t => SpinOperators.act (A t) (v t) q) x + simp only [SpinOperators.act_apply] + apply Finset.analyticAt_fun_sum + intro j hj + exact (hA q j).mul (hv j) + | succ n => + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + let := hi + refine ⟨ι,hi,fun t i q => ∑j, A t q j * a t i j,d,?_,hd,?_⟩ + · intro i q + apply Finset.analyticAt_fun_sum + intro j hj + exact (hA q j).mul (ha i j) + · intro t + change SpinOperators.act (A t) (v t)=_ + rw [hv,act_spinPacket] + +end PacketRegular +end PointedTree + +namespace PointedTree +open CoherentFock Complex RootSpin +variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] {x : X} +namespace PacketRegular + +theorem cost (n : ℕ) {v : X → Level (n+1)} {h : X → Mode n} + (hh : PacketRegular x n (fun t => (h t : Level n))) (hv : PacketRegular x (n+1) v) : + PacketRegular x (n+1) (fun t => WZ (h t) (v t)) := by + classical + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + let := hi + refine ⟨ι×Fin 2,inferInstance, + fun t p q => if q=p.2 then phase (if p.2=0 then h t else -h t) (d t p.1)*a t p.1 q else 0, + fun t p => (if p.2=0 then h t else -h t)+d t p.1,?_,?_,?_⟩ + · intro p q + by_cases hqp : q=p.2 + · simp only [hqp,ite_true] + apply AnalyticAt.mul _ (ha p.1 p.2) + apply analyticAt_phase_of_gram + have hgram : AnalyticAt ℝ (fun t => ⟪h t,d t p.1⟫_ℂ) x := by + simpa only [Submodule.coe_inner] using inner n hh (hd p.1) + by_cases hp : p.2=0 + · simpa only [hp,ite_true] using hgram + · simpa only [hp,ite_false,inner_neg_left] using hgram.fun_neg + · simp only [hqp,ite_false] + exact analyticAt_const + · intro p + by_cases hp : p.2=0 + · simpa only [hp,ite_true,Submodule.coe_add] using add n hh (hd p.1) + · simpa only [hp,ite_false,Submodule.coe_add,Submodule.coe_neg] using add n (neg n hh) (hd p.1) + · intro t + dsimp only + rw [hv,WZ_spinPacket] + +end PacketRegular + + +inductive ParamGate (X : Type*) + | mixer (beta : X → ℝ) + | cost (gamma : X → ℝ) + +def ParamGate.eval (g : ParamGate X) (t : X) : Gate := + match g with + | .mixer f => .mixer (f t) + | .cost f => .cost (f t) + +def ParamGate.regular (g : ParamGate X) (x : X) : Prop := + match g with + | .mixer f => AnalyticAt ℝ f x + | .cost f => AnalyticAt ℝ f x + +def evalWord (w : List (ParamGate X)) (t : X) : List Gate := w.map (fun g => g.eval t) + +@[simp] theorem rootEquiv_symm_apply (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) + (hA : A ∈ unitary _) (v : Level n) : + (rootEquiv n A hA).symm v=root n A.conjTranspose v := by + cases n <;> exact SpinOperators.actEquiv_symm_apply A hA v + +theorem analyticAt_R {f : X → ℝ} (hf : AnalyticAt ℝ f x) (i j : Fin 2) : + AnalyticAt ℝ (fun t => R (f t) i j) x := by + simp only [R_apply] + split_ifs with hij + · exact (Complex.ofRealCLM.analyticAt _).comp (Real.analyticAt_cos.comp hf) + · exact (show AnalyticAt ℝ (fun _ : X => -I) x from analyticAt_const).mul + ((Complex.ofRealCLM.analyticAt _).comp (Real.analyticAt_sin.comp hf)) + + + +theorem ordinary_packetRegular (w : List (ParamGate X)) + (hw : ∀g∈w, g.regular x) : ∀n, + (∀v : X → Level n, PacketRegular x n v → + PacketRegular x n (fun t => (ordinary (evalWord w t) n).op (v t))) ∧ + (∀v : X → Level n, PacketRegular x n v → + PacketRegular x n (fun t => (ordinary (evalWord w t) n).op.symm (v t))) := by + induction w with + | nil => + intro n + constructor <;> intro v hv <;> exact hv + | cons g w ih => + have hg : g.regular x := hw g (by simp) + have hw' : ∀g∈w, g.regular x := fun g hg => hw g (by simp [hg]) + have ih' := ih hw' + intro n + cases g with + | mixer f => + change AnalyticAt ℝ f x at hg + constructor + · intro v hv + change PacketRegular x n (fun t => rootEquiv n (R (f t)) _ + ((ordinary (evalWord w t) n).op (v t))) + simp only [rootEquiv_apply] + exact PacketRegular.root n (analyticAt_R hg) ((ih' n).1 v hv) + · intro v hv + change PacketRegular x n (fun t => (ordinary (evalWord w t) n).op.symm + ((rootEquiv n (R (f t)) _).symm (v t))) + simp only [rootEquiv_symm_apply,R_star] + exact (ih' n).2 _ (PacketRegular.root n (analyticAt_R hg.neg) hv) + | cost f => + change AnalyticAt ℝ f x at hg + cases n with + | zero => exact ih' 0 + | succ n => + have hins : PacketRegular x n + (fun t => ((ordinary (evalWord w t) n).insertion : Level n)) := + (ih' n).2 _ (PacketRegular.root n (fun _ _ => analyticAt_const) + ((ih' n).1 _ (PacketRegular.vac n))) + have hd : PacketRegular x n (fun t => (-(f t:ℂ)) • + ((ordinary (evalWord w t) n).insertion : Level n)) := + PacketRegular.smul n ((Complex.ofRealCLM.analyticAt _).comp hg).neg hins + constructor + · intro v hv + change PacketRegular x (n+1) (fun t => WZ + ((-(f t:ℂ)) • (ordinary (evalWord w t) n).insertion) + ((ordinary (evalWord w t) (n+1)).op (v t))) + exact PacketRegular.cost n hd ((ih' (n+1)).1 v hv) + · intro v hv + change PacketRegular x (n+1) (fun t => (ordinary (evalWord w t) (n+1)).op.symm + (WZ (-((-(f t:ℂ)) • (ordinary (evalWord w t) n).insertion)) (v t))) + exact (ih' (n+1)).2 _ (PacketRegular.cost n (PacketRegular.neg n hd) hv) + + + +theorem ordinary_insertion_packetRegular (w : List (ParamGate X)) + (hw : ∀g∈w, g.regular x) (n : ℕ) : + PacketRegular x n (fun t => ((ordinary (evalWord w t) n).insertion : Level n)) := by + have h := ordinary_packetRegular w hw n + exact h.2 _ (PacketRegular.root n (fun _ _ => analyticAt_const) + (h.1 _ (PacketRegular.vac n))) + +end PointedTree + +namespace CoherentFock +open Complex PointedTree +variable {X E : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] + [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] {x : X} + + + +theorem analyticAt_inner_spinPacket_creation {ι : Type*} [Fintype ι] + (a : X → ι → Fin 2 → ℂ) (d : X → ι → E) (h : X → E) + (ha : ∀i q, AnalyticAt ℝ (fun t => a t i q) x) + (hd : ∀i, AnalyticAt ℝ (fun t => ⟪d t i,d t i⟫_ℂ) x) + (hdh : ∀i, AnalyticAt ℝ (fun t => ⟪d t i,h t⟫_ℂ) x) : + AnalyticAt ℝ (fun t => ⟪spinPacket (a t) (d t),plusEmbedding (creationVacuum (h t))⟫_ℂ) x := by + simp_rw [inner_spinPacket_creation] + apply Finset.analyticAt_fun_sum + intro i hi + have h0 : AnalyticAt ℝ (fun t => conj (a t i 0)) x := + (Complex.conjCLE.toContinuousLinearMap.analyticAt _).comp (ha i 0) + have h1 : AnalyticAt ℝ (fun t => conj (a t i 1)) x := + (Complex.conjCLE.toContinuousLinearMap.analyticAt _).comp (ha i 1) + have hn : AnalyticAt ℝ (fun t => (Real.exp (-‖d t i‖^2/2):ℂ)) x := + (Complex.ofRealCLM.analyticAt _).comp (analyticAt_rexp.comp + (analyticAt_norm_sq_of_inner (fun t => d t i) (hd i)).neg.div_const) + exact (((show AnalyticAt ℝ (fun _ : X => -I) x from analyticAt_const).mul (h0.add h1)).mul + (show AnalyticAt ℝ (fun _ : X => spinCoefficient) x from analyticAt_const)).mul hn |>.mul (hdh i) + +end CoherentFock + +namespace PointedTree +open CoherentFock Complex +variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] {x : X} + +namespace PacketRegular + +theorem inner_creation (n : ℕ) {v : X → Level (n+1)} {h : X → Mode n} + (hv : PacketRegular x (n+1) v) (hh : PacketRegular x n (fun t => (h t : Level n))) : + AnalyticAt ℝ (fun t => ⟪v t,plusEmbedding (creationVacuum (h t))⟫_ℂ) x := by + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + let := hi + simp_rw [hv] + exact analyticAt_inner_spinPacket_creation a d h ha + (fun i => inner n (hd i) (hd i)) (fun i => inner n (hd i) hh) + +end PacketRegular + + + +theorem analyticAt_ordinary_insertion_gram (w u : List (ParamGate X)) + (hw : ∀g∈w, g.regular x) (hu : ∀g∈u, g.regular x) (n : ℕ) : + AnalyticAt ℝ (fun t => ⟪(ordinary (evalWord w t) n).insertion, + (ordinary (evalWord u t) n).insertion⟫_ℂ) x := + PacketRegular.inner n (ordinary_insertion_packetRegular w hw n) + (ordinary_insertion_packetRegular u hu n) + + + +theorem analyticAt_ordinaryValue (w : List (ParamGate X)) + (hw : ∀g∈w, g.regular x) : AnalyticAt ℝ (fun t => ordinaryValue (evalWord w t)) x := by + let n := w.length + have hl (t : X) : (evalWord w t).length=n := by simp [evalWord,n] + have h := PacketRegular.inner_creation n + (ordinary_insertion_packetRegular w hw (n+1)) (ordinary_insertion_packetRegular w hw n) + have hr := (Complex.reCLM.analyticAt _).comp h + convert hr using 1 + ext t + dsimp only [Function.comp_def,Complex.reCLM_apply] + rw [ordinaryValue,hl,treeEnergy,ordinary_insertion_empty _ n (by rw [hl])] + rfl + +end PointedTree + + + +open Filter Set Topology +namespace AnalyticVisibility +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + +theorem dense_nonzero (f : E → ℝ) (hf : AnalyticOnNhd ℝ f Set.univ) + (x₀ : E) (h₀ : f x₀ ≠ 0) : Dense {x | f x ≠ 0} := by + rw [dense_iff_inter_open] + intro U hU hne + by_contra h + have hz : ∀x ∈ U, f x=0 := by + intro x hx + by_contra hx' + apply h + exact ⟨x,hx,hx'⟩ + obtain ⟨x,hx⟩ := hne + have he : f =ᶠ[𝓝 x] (fun _ => 0) := by + filter_upwards [hU.mem_nhds hx] with y hy + exact hz y hy + have hident := hf.eq_of_eventuallyEq analyticOnNhd_const he + exact h₀ (congrFun hident x₀) + + + +theorem dense_all_nonzero {ι : Type*} [Finite ι] (f : ι → E → ℝ) + (hf : ∀i, AnalyticOnNhd ℝ (f i) Set.univ) + (hn : ∀i, ∃x, f i x ≠ 0) : Dense {x | ∀i, f i x ≠ 0} := by + have ho (i : ι) : IsOpen {x | f i x ≠ 0} := + isOpen_ne_fun ((hf i).continuous) continuous_const + have hd (i : ι) : Dense {x | f i x ≠ 0} := by + obtain ⟨x,hx⟩ := hn i + exact dense_nonzero (f i) (hf i) x hx + classical + let := Fintype.ofFinite ι + have hs (s : Finset ι) : Dense {x | ∀i ∈ s, f i x ≠ 0} := by + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => + convert (hd i).inter_of_isOpen_left ih (ho i) using 1 + ext x + simp only [Finset.mem_insert,forall_eq_or_imp,Set.mem_ofPred_eq,Set.mem_inter_iff] + simpa using hs Finset.univ + + + +theorem exists_perturbation {ι : Type*} [Finite ι] (f : ι → E → ℝ) + (hf : ∀i, AnalyticOnNhd ℝ (f i) Set.univ) + (hn : ∀i, ∃x, f i x ≠ 0) (energy : E → ℝ) (x : E) + (henergy : ContinuousAt energy x) {ε δ : ℝ} (hε : 0 < ε) (hδ : 0 < δ) : + ∃y, dist y x < δ ∧ |energy y-energy x| < ε ∧ ∀i, f i y ≠ 0 := by + have he : ∀ᶠ y in 𝓝 x, |energy y-energy x| < ε := by + simpa only [Real.dist_eq] using (Metric.tendsto_nhds.mp henergy.tendsto ε hε) + have hb : ∀ᶠ y in 𝓝 x, dist y x < δ := Metric.ball_mem_nhds x hδ + obtain ⟨y,hy,hv⟩ := (dense_all_nonzero f hf hn).inter_nhds_nonempty (he.and hb) + exact ⟨y,hv.2,hv.1,hy⟩ + +end AnalyticVisibility + + + +open scoped InnerProductSpace ComplexConjugate Topology +namespace HilbertChain +variable (H : ℕ → Type*) [∀n, NormedAddCommGroup (H n)] [∀n, InnerProductSpace ℂ (H n)] +variable (step : ∀n, H n →ₗᵢ[ℂ] H (n+1)) + +def up (n m : ℕ) (h : n ≤ m) : H n →ₗᵢ[ℂ] H m := + Nat.leRecOn h (fun {k} T => (step k).comp T) LinearIsometry.id + +@[simp] theorem up_self (n : ℕ) : up H step n n le_rfl=LinearIsometry.id := by + exact Nat.leRecOn_self _ + +@[simp] theorem up_succ (n m : ℕ) (h : n ≤ m) : + up H step n (m+1) (h.trans (Nat.le_succ m))=(step m).comp (up H step n m h) := by + exact Nat.leRecOn_succ h _ + +@[simp] theorem up_comp (n m k : ℕ) (hnm : n ≤ m) (hmk : m ≤ k) : + (up H step m k hmk).comp (up H step n m hnm)=up H step n k (hnm.trans hmk) := by + induction k, hmk using Nat.le_induction with + | base => simp + | succ k h ih => rw [up_succ H step m k h,up_succ H step n k (hnm.trans h)]; + simpa only [LinearIsometry.comp_assoc] using congrArg ((step k).comp) ih + +instance : DirectedSystem H (fun {n m} h => up H step n m h) where + map_self x := by simp + map_map := by + intro k j i hij hjk x + exact congrArg (fun T => T x) (up_comp H step i j k hij hjk) + +abbrev Algebraic := DirectLimit H (up H step) + +def incl (n : ℕ) : H n →ₗ[ℂ] Algebraic H step := + DirectLimit.Module.of ℂ ℕ H (up H step) n + +@[simp] theorem incl_up (n m : ℕ) (h : n ≤ m) (x : H n) : + incl H step m (up H step n m h x)=incl H step n x := DirectLimit.Module.of_f + +def inner (x y : Algebraic H step) : ℂ := + DirectLimit.lift₂ (up H step) (up H step) (fun _ x y => ⟪x,y⟫_ℂ) + (fun n m h x y => (up H step n m h).inner_map_map x y |>.symm) x y + +@[simp] theorem inner_incl (n : ℕ) (x y : H n) : + inner H step (incl H step n x) (incl H step n y)=⟪x,y⟫_ℂ := + DirectLimit.lift₂_def _ _ _ _ n x y + +@[elab_as_elim] theorem induction {P : Algebraic H step → Prop} + (h : ∀n x, P (incl H step n x)) (x) : P x := DirectLimit.induction _ h x + +@[elab_as_elim] theorem induction₂ {P : Algebraic H step → Algebraic H step → Prop} + (h : ∀n x y, P (incl H step n x) (incl H step n y)) (x y) : P x y := + DirectLimit.induction₂ _ h x y + +@[elab_as_elim] theorem induction₃ + {P : Algebraic H step → Algebraic H step → Algebraic H step → Prop} + (h : ∀n x y z, P (incl H step n x) (incl H step n y) (incl H step n z)) (x y z) : P x y z := + DirectLimit.induction₃ _ h x y z + +@[instance_reducible] def core : InnerProductSpace.Core ℂ (Algebraic H step) where + inner := inner H step + conj_inner_symm := induction₂ H step (fun n x y => by simp [inner_conj_symm]) + re_inner_nonneg := induction H step (fun n x => by rw [inner_incl]; exact inner_self_nonneg) + add_left := induction₃ H step (fun n x y z => by rw [←map_add,inner_incl,inner_incl,inner_incl,inner_add_left]) + smul_left x y r := induction₂ H step (fun n x y => by rw [←map_smul,inner_incl,inner_incl,inner_smul_left]) x y + definite := induction H step (fun n x hx => by + rw [inner_incl,inner_self_eq_zero] at hx + rw [hx,map_zero]) + +instance : NormedAddCommGroup (Algebraic H step) := + InnerProductSpace.Core.toNormedAddCommGroup (cd := core H step) +instance : InnerProductSpace ℂ (Algebraic H step) := + InnerProductSpace.ofCore (core H step).toCore + +@[simp] theorem inner_incl' (n : ℕ) (x y : H n) : + ⟪incl H step n x,incl H step n y⟫_ℂ=⟪x,y⟫_ℂ := inner_incl H step n x y + +def inclusion (n : ℕ) : H n →ₗᵢ[ℂ] Algebraic H step := + LinearMap.isometryOfInner (incl H step n) (inner_incl' H step n) + +abbrev Space := UniformSpace.Completion (Algebraic H step) + +def embed (n : ℕ) : H n →ₗᵢ[ℂ] Space H step := + (UniformSpace.Completion.toComplₗᵢ : Algebraic H step →ₗᵢ[ℂ] Space H step).comp (inclusion H step n) + +@[simp] theorem embed_up (n m : ℕ) (h : n ≤ m) (x : H n) : + embed H step m (up H step n m h x)=embed H step n x := by + change ((incl H step m (up H step n m h x) : Algebraic H step) : Space H step)=_ + rw [incl_up] + rfl + +@[simp] theorem embed_step (n : ℕ) (x : H n) : + embed H step (n+1) (step n x)=embed H step n x := by + simpa using embed_up H step n (n+1) (Nat.le_succ n) x + +end HilbertChain + +namespace HilbertChain +variable (H : ℕ → Type*) [∀n, NormedAddCommGroup (H n)] [∀n, InnerProductSpace ℂ (H n)] +variable (step : ∀n, H n →ₗᵢ[ℂ] H (n+1)) + + + +theorem denseRange_embed : DenseRange (fun x : Σn, H n => embed H step x.1 x.2) := by + have hr : Set.range (fun x : Σn, H n => embed H step x.1 x.2)= + Set.range (fun x : Algebraic H step => (x : Space H step)) := by + ext v + constructor + · rintro ⟨⟨n,x⟩,rfl⟩ + exact ⟨incl H step n x,rfl⟩ + · rintro ⟨x,rfl⟩ + induction x using HilbertChain.induction H step with + | h n x => exact ⟨⟨n,x⟩,rfl⟩ + change Dense _ + rw [hr] + exact UniformSpace.Completion.denseRange_coe + +variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] +variable (g : ∀n, H n →ₗᵢ[ℂ] F) +variable (hg : ∀n x, g (n+1) (step n x)=g n x) + +include hg in +theorem lift_compat (n m : ℕ) (h : n ≤ m) (x : H n) : + g m (up H step n m h x)=g n x := by + induction m,h using Nat.le_induction with + | base => simp + | succ m h ih => + rw [up_succ H step n m h] + change g (m+1) (step m (up H step n m h x)) = _ + rw [hg,ih] + +def liftAlgebraic : Algebraic H step →ₗᵢ[ℂ] F where + toLinearMap := DirectLimit.Module.lift ℂ ℕ H (up H step) (fun n => (g n).toLinearMap) + (lift_compat H step g hg) + norm_map' x := by + induction x using HilbertChain.induction H step with + | h n x => + change ‖g n x‖=‖incl H step n x‖ + rw [(g n).norm_map] + exact ((inclusion H step n).norm_map x).symm + +@[simp] theorem liftAlgebraic_incl (n : ℕ) (x : H n) : + liftAlgebraic H step g hg (incl H step n x)=g n x := rfl + +end HilbertChain + +namespace HilbertChain +variable (H : ℕ → Type*) [∀n, NormedAddCommGroup (H n)] [∀n, InnerProductSpace ℂ (H n)] +variable (step : ∀n, H n →ₗᵢ[ℂ] H (n+1)) +variable {F : Type*} [NormedAddCommGroup F] [InnerProductSpace ℂ F] [CompleteSpace F] +variable (g : ∀n, H n →ₗᵢ[ℂ] F) +variable (hg : ∀n x, g (n+1) (step n x)=g n x) + + +def lift : Space H step →ₗᵢ[ℂ] F where + toLinearMap := (liftAlgebraic H step g hg).toContinuousLinearMap.fromCompletion.toLinearMap + norm_map' x := by + refine UniformSpace.Completion.induction_on x + (isClosed_eq ((liftAlgebraic H step g hg).toContinuousLinearMap.fromCompletion.continuous.norm) + continuous_norm) fun y => ?_ + change ‖(liftAlgebraic H step g hg).toContinuousLinearMap.fromCompletion + (y : Space H step)‖ = ‖(y : Space H step)‖ + rw [ContinuousLinearMap.fromCompletion_apply_coe,UniformSpace.Completion.norm_coe] + exact (liftAlgebraic H step g hg).norm_map y + +@[simp] theorem lift_embed (n : ℕ) (x : H n) : + lift H step g hg (embed H step n x)=g n x := by + change (liftAlgebraic H step g hg).toContinuousLinearMap.fromCompletion + (incl H step n x : Algebraic H step)=g n x + rw [ContinuousLinearMap.fromCompletion_apply_coe] + rfl + +omit [CompleteSpace F] in + + +theorem ext {A B : Space H step →L[ℂ] F} (h : ∀n x, A (embed H step n x)=B (embed H step n x)) : + A=B := by + apply ContinuousLinearMap.ext + intro x + exact congrFun ((denseRange_embed H step).equalizer A.continuous B.continuous + (by funext z; exact h z.1 z.2)) x + +end HilbertChain + + +namespace PointedTree + +abbrev ModeSpace (n : ℕ) : Type := ↥(Mode n) + +abbrev wholeStep (n : ℕ) : Level n →ₗᵢ[ℂ] Level (n+1) := (empty n).toLinearIsometry +abbrev modeStep (n : ℕ) : Mode n →ₗᵢ[ℂ] Mode (n+1) := centeredMap (empty n) +abbrev WholeInfinity := HilbertChain.Space Level wholeStep +abbrev ModeInfinity := HilbertChain.Space ModeSpace modeStep +abbrev wholeEmbed (n : ℕ) : Level n →ₗᵢ[ℂ] WholeInfinity := HilbertChain.embed Level wholeStep n +abbrev modeEmbed (n : ℕ) : Mode n →ₗᵢ[ℂ] ModeInfinity := HilbertChain.embed ModeSpace modeStep n + +def vacuumInfinity : WholeInfinity := wholeEmbed 0 (vac 0) + +@[simp] theorem embed_vac (n : ℕ) : wholeEmbed n (vac n)=vacuumInfinity := by + induction n with + | zero => rfl + | succ n ih => rw [←empty_vac n]; exact (HilbertChain.embed_step Level wholeStep n _).trans ih + +@[simp] theorem norm_vacuumInfinity : ‖vacuumInfinity‖=1 := by + rw [vacuumInfinity,(wholeEmbed 0).norm_map,norm_vac] + + +def modeInWhole : ModeInfinity →ₗᵢ[ℂ] WholeInfinity := + HilbertChain.lift ModeSpace modeStep + (fun n => (wholeEmbed n).comp (Submodule.subtypeₗᵢ (Mode n))) (by + intro n x + change wholeEmbed (n+1) ((empty n).toLinearIsometry x)=wholeEmbed n x + exact HilbertChain.embed_step Level wholeStep n x) + +@[simp] theorem modeInWhole_embed (n : ℕ) (d : Mode n) : + modeInWhole (modeEmbed n d)=wholeEmbed n (d : Level n) := + HilbertChain.lift_embed ModeSpace modeStep _ _ n d + + +theorem modeInWhole_centered (x : ModeInfinity) : ⟪vacuumInfinity,modeInWhole x⟫_ℂ=0 := by + have h : ∀n (d : Mode n), ⟪vacuumInfinity,modeInWhole (modeEmbed n d)⟫_ℂ=0 := by + intro n d + rw [modeInWhole_embed,←embed_vac n,(wholeEmbed n).inner_map_map] + exact (mem_centered _ _).mp d.property + exact congrFun ((HilbertChain.denseRange_embed ModeSpace modeStep).equalizer + (continuous_const.inner modeInWhole.continuous : Continuous fun x => ⟪vacuumInfinity,modeInWhole x⟫_ℂ) + continuous_const (by funext z; exact h z.1 z.2)) x + + + +def shiftInfinity : ModeInfinity →ₗᵢ[ℂ] ModeInfinity := + HilbertChain.lift ModeSpace modeStep (fun n => (modeEmbed (n+1)).comp (rootShift n)) (by + intro n d + change modeEmbed (n+2) (rootShift (n+1) (centeredMap (empty n) d))= + modeEmbed (n+1) (rootShift n d) + rw [←rootShift_empty] + exact HilbertChain.embed_step ModeSpace modeStep (n+1) _) + +@[simp] theorem shiftInfinity_embed (n : ℕ) (d : Mode n) : + shiftInfinity (modeEmbed n d)=modeEmbed (n+1) (rootShift n d) := + HilbertChain.lift_embed ModeSpace modeStep _ _ n d + + +def energyInfinity (d : ModeInfinity) : ℝ := (⟪d,shiftInfinity d⟫_ℂ).re + +@[simp] theorem energyInfinity_embed (n : ℕ) (d : Mode n) : + energyInfinity (modeEmbed n d)=treeEnergy n d := by + rw [energyInfinity,shiftInfinity_embed] + have he := HilbertChain.embed_step ModeSpace modeStep n d + change modeEmbed (n+1) (centeredMap (empty n) d)=modeEmbed n d at he + rw [←he,(modeEmbed (n+1)).inner_map_map] + rfl + +theorem continuous_energyInfinity : Continuous energyInfinity := + Complex.continuous_re.comp (continuous_id.inner shiftInfinity.continuous : + Continuous fun d => ⟪d,shiftInfinity d⟫_ℂ) + +theorem energyInfinity_sub_le (d e : ModeInfinity) : + |energyInfinity d-energyInfinity e| ≤ (‖d‖+‖e‖)*‖d-e‖ := by + have he : ⟪d,shiftInfinity d⟫_ℂ-⟪e,shiftInfinity e⟫_ℂ= + ⟪d-e,shiftInfinity d⟫_ℂ+⟪e,shiftInfinity (d-e)⟫_ℂ := by + simp only [map_sub,inner_sub_left,inner_sub_right] + ring + change |(⟪d,shiftInfinity d⟫_ℂ).re-(⟪e,shiftInfinity e⟫_ℂ).re| ≤ _ + rw [←Complex.sub_re,he,Complex.add_re] + calc + _ ≤ |(⟪d-e,shiftInfinity d⟫_ℂ).re|+|(⟪e,shiftInfinity (d-e)⟫_ℂ).re| := abs_add_le _ _ + _ ≤ ‖d-e‖*‖shiftInfinity d‖+‖e‖*‖shiftInfinity (d-e)‖ := + add_le_add ((Complex.abs_re_le_norm _).trans (norm_inner_le_norm _ _)) + ((Complex.abs_re_le_norm _).trans (norm_inner_le_norm _ _)) + _ = _ := by rw [shiftInfinity.norm_map,shiftInfinity.norm_map]; ring + + + +def insertionInfinity (w : List Gate) : ModeInfinity := + modeEmbed w.length (ordinary w w.length).insertion + +theorem insertionInfinity_stable (w : List Gate) (n : ℕ) (hn : w.length ≤ n) : + modeEmbed n (ordinary w n).insertion=insertionInfinity w := by + induction n,hn using Nat.le_induction with + | base => rfl + | succ n hn ih => + rw [←ordinary_insertion_empty w n hn] + exact (HilbertChain.embed_step ModeSpace modeStep n _).trans ih + +@[simp] theorem norm_insertionInfinity (w : List Gate) : ‖insertionInfinity w‖=1 := by + rw [insertionInfinity,(modeEmbed _).norm_map,EvenUnitary.norm_insertion] + +@[simp] theorem energy_insertionInfinity (w : List Gate) : + energyInfinity (insertionInfinity w)=ordinaryValue w := energyInfinity_embed _ _ + +end PointedTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ParamGate.lean b/lean/OAI/Probability/ParisiFinite/ParamGate.lean new file mode 100644 index 0000000000000000000000000000000000000000..3318a36e78622ec808b932e5e64fe412eba5e072 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ParamGate.lean @@ -0,0 +1,702 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Space + +namespace OAI + +/-! Param Gate. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +namespace SeededTree +open CoherentFock Complex RootSpin PointedTree +variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] {x : X} + +inductive ParamGate (X : Type*) + | mixer (beta : X → ℝ) + | cost (gamma : X → ℝ) + | seed (angles : Fin 2 → X → ℝ) + +def ParamGate.eval (g : SeededTree.ParamGate X) (t : X) : SeededTree.Gate := + match g with + | .mixer f => .mixer (f t) + | .cost f => .cost (f t) + | .seed f => .seed (fun q => f q t) + +def ParamGate.regular (g : SeededTree.ParamGate X) (x : X) : Prop := + match g with + | .mixer f => AnalyticAt ℝ f x + | .cost f => AnalyticAt ℝ f x + | .seed f => ∀q, AnalyticAt ℝ (f q) x + +def evalWord (w : List (SeededTree.ParamGate X)) (t : X) : List SeededTree.Gate := + w.map (fun g => g.eval t) + +@[simp] theorem rootEquiv_symm_apply (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) + (hA : A ∈ unitary _) (v : Level n) : + (rootEquiv n A hA).symm v=root n A.conjTranspose v := + SpinOperators.actEquiv_symm_apply A hA v + + + +theorem seed_topRegular (n : ℕ) (f : Fin 2 → X → ℝ) (hf : ∀q, AnalyticAt ℝ (f q) x) : + TopRegular x n (fun t => external n (WithLp.toLp 2 (fun q => -(f q t:ℂ)))) := + TopRegular.external n _ (fun q => ((Complex.ofRealCLM.analyticAt _).comp (hf q)).neg) + + + +theorem circuit_packetRegular (w : List (SeededTree.ParamGate X)) + (hw : ∀g∈w, g.regular x) : ∀n, + (∀v : X → Level n, PacketRegular x n v → + PacketRegular x n (fun t => (circuit (evalWord w t) n).op (v t))) ∧ + (∀v : X → Level n, PacketRegular x n v → + PacketRegular x n (fun t => (circuit (evalWord w t) n).op.symm (v t))) := by + induction w with + | nil => + intro n + constructor <;> intro v hv <;> exact hv + | cons g w ih => + have hg : g.regular x := hw g (by simp) + have hw' : ∀g∈w, g.regular x := fun g hg => hw g (by simp [hg]) + have ih' := ih hw' + intro n + cases g with + | mixer f => + change AnalyticAt ℝ f x at hg + constructor + · intro v hv + change PacketRegular x n (fun t => rootEquiv n (R (f t)) (R_unitary (f t)) + ((circuit (evalWord w t) n).op (v t))) + simp only [SeededTree.rootEquiv_apply] + exact PacketRegular.root n (PointedTree.analyticAt_R hg) ((ih' n).1 v hv) + · intro v hv + change PacketRegular x n (fun t => (circuit (evalWord w t) n).op.symm + ((rootEquiv n (R (f t)) (R_unitary (f t))).symm (v t))) + simp only [SeededTree.rootEquiv_symm_apply,R_star] + exact (ih' n).2 _ (PacketRegular.root n (PointedTree.analyticAt_R hg.neg) hv) + | seed f => + have hseed := seed_topRegular n f hg + constructor + · intro v hv + change PacketRegular x n (fun t => WZ (external n (WithLp.toLp 2 (fun q => -(f q t:ℂ)))) + ((circuit (evalWord w t) n).op (v t))) + exact PacketRegular.pulse n hseed ((ih' n).1 v hv) + · intro v hv + change PacketRegular x n (fun t => (circuit (evalWord w t) n).op.symm + (WZ (-external n (WithLp.toLp 2 (fun q => -(f q t:ℂ)))) (v t))) + exact (ih' n).2 _ (PacketRegular.pulse n (TopRegular.neg n hseed) hv) + | cost f => + change AnalyticAt ℝ f x at hg + cases n with + | zero => exact ih' 0 + | succ n => + have hins : PacketRegular x n + (fun t => ((circuit (evalWord w t) n).insertion : Level n)) := + (ih' n).2 _ (PacketRegular.root n (fun _ _ => analyticAt_const) + ((ih' n).1 _ (PacketRegular.vac n))) + have hd : TopRegular x (n+1) (fun t => (-(f t:ℂ)) • + endogenous n (circuit (evalWord w t) n).insertion) := + TopRegular.smul (n+1) ((Complex.ofRealCLM.analyticAt _).comp hg).neg + (TopRegular.endogenous n _ hins) + constructor + · intro v hv + change PacketRegular x (n+1) (fun t => WZ + ((-(f t:ℂ)) • endogenous n (circuit (evalWord w t) n).insertion) + ((circuit (evalWord w t) (n+1)).op (v t))) + exact PacketRegular.pulse (n+1) hd ((ih' (n+1)).1 v hv) + · intro v hv + change PacketRegular x (n+1) (fun t => (circuit (evalWord w t) (n+1)).op.symm + (WZ (-((-(f t:ℂ)) • endogenous n (circuit (evalWord w t) n).insertion)) (v t))) + exact (ih' (n+1)).2 _ (PacketRegular.pulse (n+1) (TopRegular.neg (n+1) hd) hv) + +theorem circuit_insertion_packetRegular (w : List (SeededTree.ParamGate X)) + (hw : ∀g∈w, g.regular x) (n : ℕ) : + PacketRegular x n (fun t => ((circuit (evalWord w t) n).insertion : Level n)) := by + have h := circuit_packetRegular w hw n + exact h.2 _ (PacketRegular.root n (fun _ _ => analyticAt_const) + (h.1 _ (PacketRegular.vac n))) + +theorem analyticAt_insertionGram (w u : List (SeededTree.ParamGate X)) + (hw : ∀g∈w, g.regular x) (hu : ∀g∈u, g.regular x) (n : ℕ) : + AnalyticAt ℝ (fun t => ⟪(circuit (evalWord w t) n).insertion, + (circuit (evalWord u t) n).insertion⟫_ℂ) x := + PacketRegular.inner n (circuit_insertion_packetRegular w hw n) (circuit_insertion_packetRegular u hu n) + +end SeededTree + +namespace CoherentFock +open PointedTree +variable {E F X : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [NormedAddCommGroup X] [NormedSpace ℝ X] {x : X} + +@[simp] theorem spinMap_spinPacket {ι : Type*} [Fintype ι] (T : E →ₗᵢ[ℂ] F) + (a : ι → Fin 2 → ℂ) (d : ι → E) : + spinMap (gammaEmbedding T) (spinPacket a d)=spinPacket a (fun i => T (d i)) := by + ext q + simp only [spinMap_apply,spinPacket_apply,map_sum,map_smul,gammaEmbedding_coherent] + +namespace PacketForm + +theorem gamma {D : (X → E) → Prop} {D' : (X → F) → Prop} (T : E →ₗᵢ[ℂ] F) + (hT : ∀d, D d → D' (fun t => T (d t))) {v : X → SpinSpace E} + (hv : PacketForm x D v) : + PacketForm x D' (fun t => spinMap (gammaEmbedding T) (v t)) := by + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + let := hi + refine ⟨ι,hi,a,fun t i => T (d t i),ha,fun i => hT _ (hd i),?_⟩ + intro t + dsimp only + rw [hv,spinMap_spinPacket] + +end PacketForm +end CoherentFock + +namespace SeededTree +open PointedTree CoherentFock Complex RootSpin +variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] {x : X} + + + +theorem topStep_empty_regular (n : ℕ) : + (∀d : X → TopMode n, TopRegular x n d → + TopRegular x (n+1) (fun t => topStep n (d t))) ∧ + (∀v : X → Level n, PacketRegular x n v → + PacketRegular x (n+1) (fun t => (empty n).toLinearIsometry (v t))) := by + induction n with + | zero => + have ht : ∀d : X → TopMode 0, TopRegular x 0 d → + TopRegular x 1 (fun t => topStep 0 (d t)) := by + intro d hd + exact TopRegular.external 1 d hd + refine ⟨ht,?_⟩ + intro v hv + change PacketForm x (TopRegular x 1) (fun t => (SeededTree.empty 0).toLinearIsometry (v t)) + exact PacketForm.gamma (topStep 0) ht hv + | succ n ih => + have ht : ∀d : X → TopMode (n+1), TopRegular x (n+1) d → + TopRegular x (n+2) (fun t => topStep (n+1) (d t)) := by + intro d hd + refine ⟨hd.1,?_⟩ + exact ih.2 (fun t => ((d t).snd : Level n)) hd.2 + refine ⟨ht,?_⟩ + intro v hv + change PacketForm x (TopRegular x (n+2)) (fun t => (SeededTree.empty (n+1)).toLinearIsometry (v t)) + exact PacketForm.gamma (topStep (n+1)) ht hv + +namespace PacketRegular + +theorem empty (n : ℕ) {v : X → Level n} (hv : PacketRegular x n v) : + PacketRegular x (n+1) (fun t => (SeededTree.empty n).toLinearIsometry (v t)) := + (topStep_empty_regular n).2 _ hv + +theorem finsetSum {ι : Type*} (n : ℕ) (s : Finset ι) (v : ι → X → Level n) + (hv : ∀i∈s, PacketRegular x n (v i)) : + PacketRegular x n (fun t => ∑i∈s, v i t) := by + classical + induction s using Finset.induction_on with + | empty => simpa using zero (x := x) n + | @insert i s hi ih => + simp only [Finset.sum_insert hi] + exact add n (hv i (by simp)) (ih (fun j hj => hv j (by simp [hj]))) + +end PacketRegular + + + +theorem analyticAt_treeEnergy (n : ℕ) (d : X → Mode n) + (hd : PacketRegular x n (fun t => (d t:Level n))) : + AnalyticAt ℝ (fun t => treeEnergy n (d t)) x := by + have he := PacketRegular.empty n hd + obtain ⟨ι,hi,a,e,ha,he,hpres⟩ := he + let := hi + have hinner : AnalyticAt ℝ (fun t => ⟪(SeededTree.empty n).toLinearIsometry (d t), + plusEmbedding (creationVacuum (endogenous n (d t)))⟫_ℂ) x := by + simp_rw [hpres] + exact analyticAt_inner_spinPacket_creation a e (fun t => endogenous n (d t)) ha + (fun i => TopRegular.inner (n+1) (he i) (he i)) + (fun i => TopRegular.inner (n+1) (he i) (TopRegular.endogenous n d hd)) + exact (Complex.reCLM.analyticAt _).comp hinner + +theorem analyticAt_value (w : List (SeededTree.ParamGate X)) (hw : ∀g∈w, g.regular x) : + AnalyticAt ℝ (fun t => value (evalWord w t)) x := by + have h := analyticAt_treeEnergy w.length + (fun t => (circuit (evalWord w t) w.length).insertion) + (circuit_insertion_packetRegular w hw w.length) + have hl (t : X) : (evalWord w t).length=w.length := by simp [evalWord] + convert h using 1 + ext t + rw [SeededTree.value,hl t] + + +def centerAccumulator {k : ℕ} (n : ℕ) (w : Fin k → List (SeededTree.ParamGate X)) + (t : Fin k → X → ℝ) (u : X) : Mode n := + ∑j, (-2*(t j u:ℂ)) • (circuit (evalWord (w j) u) n).insertion + +theorem centerAccumulator_packetRegular {k : ℕ} (n : ℕ) + (w : Fin k → List (SeededTree.ParamGate X)) (t : Fin k → X → ℝ) + (hw : ∀j g, g∈w j → g.regular x) (ht : ∀j, AnalyticAt ℝ (t j) x) : + PacketRegular x n (fun u => (centerAccumulator n w t u : Level n)) := by + unfold centerAccumulator + simp only [Submodule.coe_sum,Submodule.coe_smul] + apply PacketRegular.finsetSum n Finset.univ + intro j hj + exact PacketRegular.smul n + ((show AnalyticAt ℝ (fun _ : X => (-2:ℂ)) x from analyticAt_const).mul + ((Complex.ofRealCLM.analyticAt _).comp (ht j))) + (circuit_insertion_packetRegular (w j) (hw j) n) + + + +def formalVisibility {k : ℕ} (n : ℕ) (b z y : ℝ) (w : List (SeededTree.ParamGate X)) + (prefixes : Fin k → List (SeededTree.ParamGate X)) (times : Fin k → X → ℝ) (u : X) : ℝ := + -2*(⟪(circuit (evalWord w u) n).insertion, + (-2*b*z:ℂ) • (EvenUnitary.ident n).insertion + + (y:ℂ) • centerAccumulator n prefixes times u⟫_ℂ).im + +theorem analyticAt_formalVisibility {k : ℕ} (n : ℕ) (b z y : ℝ) + (w : List (SeededTree.ParamGate X)) (prefixes : Fin k → List (SeededTree.ParamGate X)) + (times : Fin k → X → ℝ) (hw : ∀g∈w, g.regular x) + (hp : ∀j g, g∈prefixes j → g.regular x) (ht : ∀j, AnalyticAt ℝ (times j) x) : + AnalyticAt ℝ (formalVisibility n b z y w prefixes times) x := by + have he : PacketRegular x n (fun _ : X => ((EvenUnitary.ident n).insertion : Level n)) := + circuit_insertion_packetRegular [] (by simp) n + have hc := centerAccumulator_packetRegular n prefixes times hp ht + have hv := PacketRegular.inner n (circuit_insertion_packetRegular w hw n) + (PacketRegular.add n (PacketRegular.smul n (z := fun _ : X => (-2*b*z:ℂ)) analyticAt_const he) + (PacketRegular.smul n (z := fun _ : X => (y:ℂ)) analyticAt_const hc)) + exact (show AnalyticAt ℝ (fun _ : X => (-2:ℝ)) x from analyticAt_const).mul + ((Complex.imCLM.analyticAt _).comp hv) + +end SeededTree + +namespace SeededTree +open PointedTree CoherentFock Complex RootSpin + +@[ext] theorem EvenUnitary.ext {n : ℕ} {U V : EvenUnitary n} (h : U.op=V.op) : U=V := by + cases U + cases V + cases h + rfl + +@[simp] theorem EvenUnitary.followedBy_ident {n : ℕ} (U : EvenUnitary n) : + U.followedBy (ident n)=U := by + apply EvenUnitary.ext + ext v + rfl + +@[simp] theorem EvenUnitary.mixer_zero (n : ℕ) : mixer n 0=ident n := by + apply EvenUnitary.ext + apply LinearIsometryEquiv.ext + intro v + change SpinOperators.act (R 0) v=v + rw [R_zero,SpinOperators.act_one] + rfl + +@[simp] theorem EvenUnitary.seed_zero (n : ℕ) : seed n (fun _ => 0)=ident n := by + apply EvenUnitary.ext + apply LinearIsometryEquiv.ext + intro v + change WZ (external n (WithLp.toLp 2 (fun _ : Fin 2 => -(0:ℂ)))) v=v + have hz : WithLp.toLp 2 (fun _ : Fin 2 => -(0:ℂ))=(0:External) := by ext q; simp + rw [hz,map_zero,WZ_zero] + rfl + +@[simp] theorem EvenUnitary.cost_zero (n : ℕ) (U : EvenUnitary n) : cost n U 0=ident (n+1) := by + apply EvenUnitary.ext + apply LinearIsometryEquiv.ext + intro v + change WZ (-(0:ℂ) • endogenous n U.insertion) v=v + rw [neg_zero,zero_smul,WZ_zero] + rfl + +def Gate.IsZero : SeededTree.Gate → Prop + | .mixer b => b=0 + | .cost g => g=0 + | .seed a => ∀q, a q=0 + + + +theorem circuit_zero_prefix (w u : List SeededTree.Gate) (hw : ∀g∈w, Gate.IsZero g) (n : ℕ) : + circuit (w++u) n=circuit u n := by + induction w with + | nil => rfl + | cons g w ih => + have hg := hw g (by simp) + have hw' : ∀g∈w, Gate.IsZero g := fun g hg => hw g (by simp [hg]) + cases g with + | mixer b => + change b=0 at hg + subst b + change (circuit (w++u) n).followedBy (EvenUnitary.mixer n 0)=circuit u n + rw [EvenUnitary.mixer_zero,EvenUnitary.followedBy_ident,ih hw'] + | seed a => + have ha : a=fun _ => 0 := funext hg + subst a + change (circuit (w++u) n).followedBy (EvenUnitary.seed n (fun _ => 0))=circuit u n + rw [EvenUnitary.seed_zero,EvenUnitary.followedBy_ident,ih hw'] + | cost g => + change g=0 at hg + subst g + cases n with + | zero => exact ih hw' + | succ n => + change (circuit (w++u) (n+1)).followedBy (EvenUnitary.cost n (circuit (w++u) n) 0)=circuit u (n+1) + rw [EvenUnitary.cost_zero,EvenUnitary.followedBy_ident,ih hw'] + + +def ell : External := EuclideanSpace.single 0 1 +@[simp] theorem norm_ell : ‖ell‖=1 := by simp [ell] + +def initializationAngles (b : ℝ) : Fin 2 → ℝ := fun q => if q=0 then -2*b else 0 + +def initializationDisplacement (n : ℕ) (b : ℝ) : TopMode n := + external n (WithLp.toLp 2 (fun q => -(initializationAngles b q:ℂ))) + +theorem initializationDisplacement_eq (n : ℕ) (b : ℝ) : + initializationDisplacement n b=(2*b:ℂ) • external n ell := by + unfold initializationDisplacement + rw [←map_smul] + congr 1 + ext q + fin_cases q <;> simp [initializationAngles,ell,EuclideanSpace.single] + +theorem initializationDisplacement_norm_sq (n : ℕ) (b : ℝ) : + ‖initializationDisplacement n b‖^2=4*b^2 := by + rw [initializationDisplacement_eq,norm_smul,(external n).norm_map,norm_ell,mul_one] + norm_cast + rw [Real.norm_eq_abs,sq_abs] + ring + +def initializationWord (b : ℝ) : List SeededTree.Gate := + [.mixer (Real.pi/4),.seed (initializationAngles b)] + + +theorem initialization_insertion_coe (n : ℕ) (b : ℝ) : + ((circuit (initializationWord b) n).insertion : Level n)= + SpinOperators.act Y (WZ (initializationDisplacement n b+initializationDisplacement n b) (vac n)) := by + change (costEquiv (initializationDisplacement n b)).symm + ((SpinOperators.actEquiv (R (Real.pi/4)) (R_unitary (Real.pi/4))).symm + (SpinOperators.act Z (SpinOperators.actEquiv (R (Real.pi/4)) (R_unitary (Real.pi/4)) + (costEquiv (initializationDisplacement n b) (vac n)))))=_ + simp only [costEquiv_symm_apply,SpinOperators.actEquiv_symm_apply, + SpinOperators.actEquiv_apply,costEquiv_apply] + rw [one_layer_insertion,show 2*(Real.pi/4)=Real.pi/2 by ring] + simp only [Real.cos_pi_div_two,Real.sin_pi_div_two,Complex.ofReal_zero,Complex.ofReal_one, + zero_smul,one_smul,zero_add] + + + +theorem inner_initialization_initial (n : ℕ) (b : ℝ) : + ⟪(circuit (initializationWord b) n).insertion,(EvenUnitary.ident n).insertion⟫_ℂ= + I*(Real.exp (-8*b^2):ℂ) := by + change ⟪((circuit (initializationWord b) n).insertion:Level n),SpinOperators.act Z (vac n)⟫_ℂ=_ + rw [initialization_insertion_coe,←inner_conj_symm] + change (starRingEnd ℂ) ⟪SpinOperators.act Z (vacuum (TopMode n)), + SpinOperators.act Y (WZ (initializationDisplacement n b+initializationDisplacement n b) + (vacuum (TopMode n)))⟫_ℂ=_ + rw [inner_rootZ_vac_rootY_WZ] + simp only [map_mul,map_neg,Complex.conj_I,neg_neg,Complex.conj_ofReal] + have hn : ‖initializationDisplacement n b+initializationDisplacement n b‖^2=16*b^2 := by + rw [←two_smul ℝ (initializationDisplacement n b),norm_smul, + Real.norm_of_nonneg (by norm_num : (0:ℝ)≤2),mul_pow,initializationDisplacement_norm_sq] + ring + have he : -‖initializationDisplacement n b+initializationDisplacement n b‖^2/2= -8*b^2 := by + rw [hn] + ring + rw [he] + +end SeededTree + +namespace SeededTree +open PointedTree CoherentFock Complex RootSpin +variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] + + + +def initializationParam (b : ℝ) : List (SeededTree.ParamGate X) := + [.mixer (fun _ => Real.pi/4),.seed (fun q _ => initializationAngles b q)] + +omit [NormedAddCommGroup X] [NormedSpace ℝ X] in +@[simp] theorem eval_initializationParam (b : ℝ) (x : X) : + evalWord (initializationParam b) x=initializationWord b := rfl + +theorem initializationParam_regular (b : ℝ) (x : X) : + ∀g∈initializationParam b, g.regular x := by + intro g hg + simp only [initializationParam,List.mem_cons,List.not_mem_nil,or_false] at hg + rcases hg with rfl|rfl + · exact analyticAt_const + · exact fun _ => analyticAt_const + +omit [NormedAddCommGroup X] [NormedSpace ℝ X] in +@[simp] theorem evalWord_append (w u : List (SeededTree.ParamGate X)) (x : X) : + evalWord (w++u) x=evalWord w x++evalWord u x := List.map_append + +omit [NormedAddCommGroup X] [NormedSpace ℝ X] in +theorem centerAccumulator_zero {k : ℕ} (n : ℕ) (w : Fin k → List (SeededTree.ParamGate X)) + (times : Fin k → X → ℝ) (x : X) (ht : ∀j, times j x=0) : + centerAccumulator n w times x=0 := by + simp [centerAccumulator,ht] + +omit [NormedAddCommGroup X] [NormedSpace ℝ X] in + + +theorem formalVisibility_initialization {k : ℕ} (n : ℕ) (b z y : ℝ) + (w : List (SeededTree.ParamGate X)) (prefixes : Fin k → List (SeededTree.ParamGate X)) + (times : Fin k → X → ℝ) (x : X) + (hw : ∀g∈evalWord w x, Gate.IsZero g) (ht : ∀j, times j x=0) : + formalVisibility n b z y (w++initializationParam b) prefixes times x= + 4*b*z*Real.exp (-8*b^2) := by + unfold formalVisibility + rw [evalWord_append,eval_initializationParam,circuit_zero_prefix _ _ hw, + centerAccumulator_zero n prefixes times x ht,smul_zero,add_zero,inner_smul_right, + inner_initialization_initial] + have hc : (-2*b*z:ℂ)=((-2*b*z:ℝ):ℂ) := by simp + rw [hc] + simp only [Complex.mul_im,Complex.mul_re,Complex.I_re,Complex.I_im, + Complex.ofReal_re,Complex.ofReal_im,mul_zero,zero_mul,zero_add,add_zero] + ring + + + +inductive IndexedGate (M : ℕ) + | mixer (i : Fin M) + | cost (i : Fin M) + | seed (i : Fin M) + +def IndexedGate.param {M : ℕ} : IndexedGate M → SeededTree.ParamGate (Fin M → ℝ) + | .mixer i => .mixer (fun t => t i) + | .cost i => .cost (fun t => t i) + | .seed i => .seed (fun q t => if q=0 then 0 else t i) + +theorem IndexedGate.param_regular {M : ℕ} (g : IndexedGate M) (x : Fin M → ℝ) : + g.param.regular x := by + have h (i : Fin M) : AnalyticAt ℝ (fun t : Fin M → ℝ => t i) x := + (ContinuousLinearMap.proj i : (Fin M → ℝ) →L[ℝ] ℝ).analyticAt _ + cases g with + | mixer i => exact h i + | cost i => exact h i + | seed i => + intro q + change AnalyticAt ℝ (fun t : Fin M → ℝ => if q=0 then 0 else t i) x + split_ifs + · exact analyticAt_const + · exact h i + +theorem IndexedGate.param_zero {M : ℕ} (g : IndexedGate M) : + Gate.IsZero (g.param.eval 0) := by + cases g <;> simp [IndexedGate.param,ParamGate.eval,Gate.IsZero] + +def indexedWord {M : ℕ} (w : List (IndexedGate M)) : List (SeededTree.ParamGate (Fin M → ℝ)) := + w.map IndexedGate.param + +theorem indexedWord_regular {M : ℕ} (w : List (IndexedGate M)) (x : Fin M → ℝ) : + ∀g∈indexedWord w, g.regular x := by + intro g hg + obtain ⟨g,hg,rfl⟩ := List.mem_map.mp hg + exact g.param_regular x + +theorem indexedWord_zero {M : ℕ} (w : List (IndexedGate M)) : + ∀g∈evalWord (indexedWord w) 0, Gate.IsZero g := by + intro g hg + obtain ⟨p,hp,rfl⟩ := List.mem_map.mp hg + obtain ⟨q,hq,rfl⟩ := List.mem_map.mp hp + exact q.param_zero + + +def indexedTime {M : ℕ} (i : Fin M) (x : Fin M → ℝ) : ℝ := x i/2 + +theorem indexedTime_regular {M : ℕ} (i : Fin M) (x : Fin M → ℝ) : + AnalyticAt ℝ (indexedTime i) x := + ((ContinuousLinearMap.proj i : (Fin M → ℝ) →L[ℝ] ℝ).analyticAt _).div_const + +@[simp] theorem indexedTime_zero {M : ℕ} (i : Fin M) : indexedTime i 0=0 := by + simp [indexedTime] + + +theorem indexedVisibility_zero {M k : ℕ} (n : ℕ) (b z y : ℝ) + (w : List (IndexedGate M)) + (prefixes : Fin k → List (SeededTree.ParamGate (Fin M → ℝ))) (times : Fin k → Fin M) : + formalVisibility n b z y (indexedWord w++initializationParam b) prefixes + (fun j => indexedTime (times j)) 0=4*b*z*Real.exp (-8*b^2) := + formalVisibility_initialization n b z y (indexedWord w) prefixes _ 0 + (indexedWord_zero w) (fun j => indexedTime_zero (times j)) + +end SeededTree + +namespace SeededTree +open PointedTree CoherentFock Complex RootSpin + + + +theorem exists_visible_perturbation {M k : ℕ} {ι : Type*} [Finite ι] + (n : ℕ) (b : ℝ) (hb : 0 indexedWord (prefixes s j)++initializationParam b) + (fun j => indexedTime (times s j)) u≠0) ∧ + (∀i∈echoes, indexedTime i u≠0) := by + classical + let f : (ι ⊕ {i : Fin M // i∈echoes}) → (Fin M → ℝ) → ℝ := fun s => + match s with + | .inl s => formalVisibility n b (z s) (y s) + (indexedWord (stages s)++initializationParam b) + (fun j => indexedWord (prefixes s j)++initializationParam b) + (fun j => indexedTime (times s j)) + | .inr i => indexedTime i.1 + have hreg (w : List (IndexedGate M)) (v : Fin M → ℝ) : + ∀g∈indexedWord w++initializationParam b, g.regular v := by + intro g hg + rcases List.mem_append.mp hg with hg|hg + · exact indexedWord_regular w v g hg + · exact initializationParam_regular b v g hg + have hf : ∀s, AnalyticOnNhd ℝ (f s) Set.univ := by + intro s v hv + cases s with + | inl s => + exact analyticAt_formalVisibility (X := Fin M → ℝ) (x := v) n b (z s) (y s) _ _ _ + (hreg (stages s) v) (fun j => hreg (prefixes s j) v) + (fun j => indexedTime_regular (times s j) v) + | inr i => exact indexedTime_regular i.1 v + have hn : ∀s, ∃u, f s u≠0 := by + intro s + cases s with + | inl s => + refine ⟨0,?_⟩ + change formalVisibility _ _ _ _ _ _ _ 0≠0 + rw [indexedVisibility_zero] + exact mul_ne_zero (mul_ne_zero (mul_ne_zero (by norm_num) hb.ne') (hz s)) + (Real.exp_ne_zero _) + | inr i => + refine ⟨fun _ => 2,?_⟩ + norm_num [f,indexedTime] + have he := (analyticAt_value (indexedWord target++initializationParam b) (hreg target x)).continuousAt + obtain ⟨u,hu,he,hf⟩ := AnalyticVisibility.exists_perturbation f hf hn + (fun v => value (evalWord (indexedWord target++initializationParam b) v)) x he hε hδ + refine ⟨u,hu,he,fun s => hf (.inl s),?_⟩ + intro i hi + exact hf (.inr ⟨i,hi⟩) + +end SeededTree + +namespace SeededTree +open PointedTree CoherentFock Complex RootSpin + + + +def ordinaryLift : (n : ℕ) → PointedMap (PointedTree.level n) (SeededTree.level n) + | 0 => ⟨spinMap (scalarEmbedding (coherent (0:External)) (norm_coherent _)),rfl⟩ + | n+1 => gaussianMap ((endogenous n).comp (centeredMap (ordinaryLift n))) + +@[simp] theorem ordinaryLift_vac (n : ℕ) : + (ordinaryLift n).toLinearIsometry (PointedTree.vac n)=SeededTree.vac n := + (ordinaryLift n).map_vac + +@[simp] theorem ordinaryLift_root (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) + (v : PointedTree.Level n) : + (ordinaryLift n).toLinearIsometry (PointedTree.root n A v)= + SeededTree.root n A ((ordinaryLift n).toLinearIsometry v) := by + cases n <;> exact spinMap_root _ _ _ + +@[simp] theorem ordinaryLift_cost (n : ℕ) (d : PointedTree.Mode n) (v : PointedTree.Level (n+1)) : + (ordinaryLift (n+1)).toLinearIsometry (WZ d v)= + WZ (endogenous n (centeredMap (ordinaryLift n) d)) + ((ordinaryLift (n+1)).toLinearIsometry v) := + spinMap_cost ((endogenous n).comp (centeredMap (ordinaryLift n))) d v + + +def LiftCompatible {n : ℕ} (U : PointedTree.EvenUnitary n) (V : SeededTree.EvenUnitary n) : Prop := + ∀v, (ordinaryLift n).toLinearIsometry (U.op v)=V.op ((ordinaryLift n).toLinearIsometry v) + +theorem LiftCompatible.symm_apply {n : ℕ} {U : PointedTree.EvenUnitary n} {V : SeededTree.EvenUnitary n} + (h : LiftCompatible U V) (v : PointedTree.Level n) : + (ordinaryLift n).toLinearIsometry (U.op.symm v)=V.op.symm ((ordinaryLift n).toLinearIsometry v) := by + apply V.op.injective + rw [←h,U.op.apply_symm_apply,V.op.apply_symm_apply] + +theorem LiftCompatible.insertion {n : ℕ} {U : PointedTree.EvenUnitary n} {V : SeededTree.EvenUnitary n} + (h : LiftCompatible U V) : centeredMap (ordinaryLift n) U.insertion=V.insertion := by + apply Subtype.ext + change (ordinaryLift n).toLinearIsometry (U.op.symm + (PointedTree.root n Z (U.op (PointedTree.vac n))))= + V.op.symm (SeededTree.root n Z (V.op (SeededTree.vac n))) + rw [h.symm_apply,ordinaryLift_root,h,ordinaryLift_vac] + + +def ordinaryGate : PointedTree.Gate → SeededTree.Gate + | .mixer b => .mixer b + | .cost g => .cost g + +def ordinaryWord (w : List PointedTree.Gate) : List SeededTree.Gate := w.map ordinaryGate + +@[simp] theorem ordinaryWord_length (w : List PointedTree.Gate) : (ordinaryWord w).length=w.length := by + simp [ordinaryWord] + + + +theorem circuit_ordinaryLift (w : List PointedTree.Gate) (n : ℕ) : + LiftCompatible (PointedTree.ordinary w n) (circuit (ordinaryWord w) n) := by + induction w generalizing n with + | nil => exact fun _ => rfl + | cons g w ih => + cases g with + | mixer b => + intro v + change (ordinaryLift n).toLinearIsometry + (PointedTree.rootEquiv n (R b) (R_unitary b) ((PointedTree.ordinary w n).op v))= + SeededTree.rootEquiv n (R b) (R_unitary b) ((circuit (ordinaryWord w) n).op ((ordinaryLift n).toLinearIsometry v)) + rw [PointedTree.rootEquiv_apply,SeededTree.rootEquiv_apply,ordinaryLift_root,ih n] + | cost g => + cases n with + | zero => exact ih 0 + | succ n => + intro v + change (ordinaryLift (n+1)).toLinearIsometry + (WZ (-(g:ℂ) • (PointedTree.ordinary w n).insertion) + ((PointedTree.ordinary w (n+1)).op v))= + WZ (-(g:ℂ) • endogenous n (circuit (ordinaryWord w) n).insertion) + ((circuit (ordinaryWord w) (n+1)).op ((ordinaryLift (n+1)).toLinearIsometry v)) + rw [ordinaryLift_cost,map_smul,map_smul,(ih n).insertion,ih (n+1)] + +@[simp] theorem ordinaryLift_rootShift (n : ℕ) (d : PointedTree.Mode n) : + centeredMap (ordinaryLift (n+1)) (PointedTree.rootShift n d)= + rootShift n (centeredMap (ordinaryLift n) d) := by + apply Subtype.ext + change spinMap (gammaEmbedding ((endogenous n).comp (centeredMap (ordinaryLift n)))) + (plusEmbedding (creationVacuum d))= + plusEmbedding (creationVacuum (endogenous n (centeredMap (ordinaryLift n) d))) + rw [spinMap_plusEmbedding] + change plusEmbedding (Gamma ((endogenous n).comp (centeredMap (ordinaryLift n))) (creationVacuum d))=_ + rw [Gamma_creationVacuum] + rfl + + +theorem value_ordinaryWord (w : List PointedTree.Gate) : + value (ordinaryWord w)=PointedTree.ordinaryValue w := by + rw [value,ordinaryWord_length,PointedTree.ordinaryValue,treeEnergy,PointedTree.treeEnergy, + circuit_insertion_empty _ w.length (by simp),PointedTree.ordinary_insertion_empty _ w.length le_rfl] + rw [←(circuit_ordinaryLift w (w.length+1)).insertion, + ←(circuit_ordinaryLift w w.length).insertion,←ordinaryLift_rootShift] + exact congrArg Complex.re ((centeredMap (ordinaryLift (w.length+1))).inner_map_map _ _) + +end SeededTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ParisiCanonicalTransport.lean b/lean/OAI/Probability/ParisiFinite/ParisiCanonicalTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..b77d52e6d0aa3feb666b488ae70a0759de6719a9 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ParisiCanonicalTransport.lean @@ -0,0 +1,671 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ParisiConjugateTransport + +namespace OAI + +/-! Parisi Canonical Transport. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath + +lemma smoothEvolve_curvature {β : ℝ≥0} {f : SmoothField} (hf : HasParisiCurvature β f) + (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) : HasParisiCurvature β (smoothEvolve f ls) := by + induction ls with + | nil => exact hf + | cons l ls ih => + exact transform_hasParisiCurvature + (ih (fun k hk => ha k (List.mem_cons_of_mem _ hk))) l.1.coe_nonneg + (by exact_mod_cast ha l List.mem_cons_self) _ + +lemma scheduleField_curvature {β : ℝ≥0} {f : SmoothField} (hf : HasParisiCurvature β f) + (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) (s t : ℝ) : + HasParisiCurvature β (scheduleField f ls s t) := by + induction ls generalizing s with + | nil => exact hf + | cons l ls ih => + have htail : ∀ k∈ls,k.1≤β := fun k hk => ha k (List.mem_cons_of_mem _ hk) + simp only [scheduleField] + split_ifs + · exact transform_hasParisiCurvature (smoothEvolve_curvature hf ls htail) + l.1.coe_nonneg (by exact_mod_cast ha l List.mem_cons_self) _ + · exact ih htail _ + +abbrev genericRecursion (f : SmoothField) (ls : Schedule) : ℝ → ℝ := evolve ls f.val + +lemma scheduleField_suffix_val (β : ℝ≥0) (f : SmoothField) (_hfc : HasParisiCurvature β f) (ls : Schedule) + (s : ℝ) (r : ℝ≥0) (x : ℝ) : + (scheduleField f ls s (s+r)).val x = genericRecursion f (scheduleSuffix ls r) x := by + induction ls generalizing s r with + | nil => rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + have hc : s+(r:ℝ) simp only [scheduleSuffix,sub_self]; exact ⟨le_rfl,by positivity⟩ + | cons l ls ih => + rcases l with ⟨a,d⟩ + have ha0 : (a:ℝ) ≤ β := by exact_mod_cast ha (a,d) List.mem_cons_self + have ht : ∀ l∈ls,l.1 ≤ β := fun l hl => ha l (List.mem_cons_of_mem _ hl) + have hh := smoothEvolve_curvature hfc ls ht + rw [scheduleSuffix] + split_ifs with hrd + · let fmid := (smoothEvolve f ls).transform a (Real.sqrt (d-r:ℝ≥0)) + have hf := transform_hasParisiCurvature hh a.coe_nonneg ha0 (Real.sqrt (d-r:ℝ≥0)) + have hb := step_curvature_time_bound hf a.coe_nonneg ha0 (Real.sqrt r) (Real.sqrt_nonneg _) x + rw [Real.sq_sqrt r.coe_nonneg] at hb + have he : step a (Real.sqrt r) fmid.val x=genericRecursion f ((a,d)::ls) x := by + change step a (Real.sqrt r) (step a (Real.sqrt (d-r:ℝ≥0)) (smoothEvolve f ls).val) x=_ + rw [step_semigroup (smoothEvolve f ls).lipschitz, + Real.sq_sqrt r.coe_nonneg,Real.sq_sqrt (d-r).coe_nonneg, + ←NNReal.coe_add,add_tsub_cancel_of_le hrd.le,smoothEvolve_val] + rfl + rw [he] at hb + simpa only [SmoothField.transform,smoothEvolve_val,genericRecursion,evolve] using hb + · have hb := step_curvature_time_bound hh a.coe_nonneg ha0 (Real.sqrt d) (Real.sqrt_nonneg _) x + rw [Real.sq_sqrt d.coe_nonneg,smoothEvolve_val] at hb + have hi := ih ht (r-d) + rw [NNReal.coe_sub (le_of_not_gt hrd)] at hi + simp only [genericRecursion,evolve] + constructor <;> nlinarith [hb.1,hb.2,hi.1,hi.2] + +lemma general_shifted_schedule_suffix_error (β : ℝ≥0) (f : SmoothField) (hfc : HasParisiCurvature β f) (a b d : ℝ≥0) + (ha : a ≤ β) (hb : b ≤ β) (mid : Schedule) (hm : ∀ l∈mid,l.1 ≤ β) + (r : ℝ≥0) (hr : r ?_) + have ht := step_curvature_time_bound (hfc) + b.coe_nonneg (by exact_mod_cast hb) (Real.sqrt d) (Real.sqrt_nonneg _) y + rw [Real.sq_sqrt d.coe_nonneg] at ht + change 0 ≤ step b (Real.sqrt d) f.val y-f.val y ∧ + step b (Real.sqrt d) f.val y-f.val y ≤ (β:ℝ)*d/2 at ht + exact abs_le.mpr ⟨(neg_nonpos.mpr (by positivity)).trans ht.1,ht.2⟩ + have hright : 0 ≤ genericRecursion f (scheduleSuffix full r) x-genericRecursion f (scheduleSuffix high r) x ∧ + genericRecursion f (scheduleSuffix full r) x-genericRecursion f (scheduleSuffix high r) x ≤ (β:ℝ)*d/2 := by + rw [hfull,scheduleSuffix] + split_ifs with hrd + · have ht := step_curvature_time_bound (smoothEvolve_curvature hfc high hhi) + a.coe_nonneg (by exact_mod_cast ha) (Real.sqrt (d-r:ℝ≥0)) (Real.sqrt_nonneg _) x + rw [Real.sq_sqrt (d-r).coe_nonneg,NNReal.coe_sub hrd.le,smoothEvolve_val] at ht + have hh := evolve_suffix_time_bound β f hfc high hhi r x + simp only [genericRecursion,evolve,NNReal.coe_sub hrd.le] + constructor <;> nlinarith [ht.1,ht.2,hh.1,hh.2] + · have hh := evolve_suffix_time_bound β f hfc (scheduleSuffix high (r-d)) + (scheduleSuffix_coeff_bound high hhi (r-d)) d x + rw [scheduleSuffix_add,tsub_add_cancel_of_le (le_of_not_gt hrd)] at hh + exact hh + calc + _ ≤ |genericRecursion f (scheduleSuffix low r) x-genericRecursion f (scheduleSuffix full r) x|+ + |genericRecursion f (scheduleSuffix full r) x-genericRecursion f (scheduleSuffix high r) x| := + abs_sub_le _ _ _ + _ ≤ (β:ℝ)*d/2+(β:ℝ)*d/2 := add_le_add + (by simpa only [abs_sub_comm] using hleft) + (abs_le.mpr ⟨by linarith [hright.1],hright.2⟩) + _ = _ := by ring + +lemma general_dyadic_suffix_grid_error (β : ℝ≥0) (f : SmoothField) (hfc : HasParisiCurvature β f) {γ : ℝ≥0 → ℝ≥0} + (hb : ∀ t,γ t ≤ β) (t d : ℝ≥0) (n : ℕ) (r : ℝ≥0) (hr : r exact (hn rfl).elim + | cons c mid => + simp only [List.cons_append,List.cons.injEq] at hs + rw [hs.1] at hw hc ⊢ + rw [←hs.2] + apply general_shifted_schedule_suffix_error β f hfc _ _ _ (hb t) (hb (t+d)) mid + (fun l hl => hc l (List.mem_cons_of_mem _ hl)) r (by rwa [hw]) + +lemma general_dyadic_suffix_value_error {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t d : ℝ≥0) (n : ℕ) + (r : ℝ≥0) (hr : r by exact_mod_cast hb t) t d n r hr x + have he := abs_le.mp (general_dyadic_suffix_grid_error β f hf hb t d n r hr x) + apply abs_le.mpr + constructor + · exact he.1.trans (sub_le_sub_left hb'.2 _) + · exact (sub_nonpos.mpr hb'.1).trans (mul_nonneg β.coe_nonneg (dyadicMesh d n).coe_nonneg) + +lemma general_dyadic_field_tendstoUniformly {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (d r : ℝ≥0) (hr : r (scheduleField f (dyadicSchedule γ false 0 d n) 0 r).val) + (dyadicEvolution γ r (d-r) f.val) atTop := by + have he : Tendsto (fun n => (β:ℝ)*(dyadicMesh d n:ℝ)) atTop (𝓝 (0:ℝ)) := by + simpa only [mul_zero] using (dyadicMesh_tendsto d).const_mul (β:ℝ) + rw [Metric.tendstoUniformly_iff] + intro ε hε + filter_upwards [he.eventually (gt_mem_nhds hε)] with n hn x + rw [Real.dist_eq,abs_sub_comm] + have hh := general_dyadic_suffix_value_error hf hγ hb 0 d n r hr x + rw [←zero_add (r:ℝ),scheduleField_suffix_val β f hf] + simpa only [genericRecursion,zero_add] using hh.trans_lt hn + +lemma general_dyadic_gradient_tendstoUniformly {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (d r : ℝ≥0) (hr : r (scheduleField f (dyadicSchedule γ false 0 d n) 0 r).d1) + (deriv (dyadicEvolution γ r (d-r) f.val)) atTop := by + obtain ⟨m,hu,hd,_,_⟩ := exists_uniform_derivative_limit + (fun n => scheduleField_curvature hf _ (dyadicSchedule_coeff_bound hb false 0 d n) 0 r) + (general_dyadic_field_tendstoUniformly hf hγ hb d r hr) + have he : m=deriv (dyadicEvolution γ r (d-r) f.val) := funext fun x => (hd x).deriv.symm + rwa [he] at hu + +lemma canonicalSmoothField_curvature (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (t : ℝ≥0) : + HasParisiCurvature β (canonicalSmoothField β hβ hγ hb t) := by + refine ⟨rfl,fun x => ?_⟩ + exact ⟨(fieldCurvature_bounds β hβ hγ hb t x).1.le, + (fieldCurvature_bounds β hβ hγ hb t x).2⟩ + +lemma prefix_dyadic_gradient_tendstoUniformly (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (d r : ℝ≥0) (hd : d≤1) (hr : r + (scheduleField (canonicalSmoothField β hβ hγ hb d) (dyadicSchedule γ false 0 d n) 0 r).d1) + (fieldGradient β γ r) atTop := by + have he : dyadicEvolution γ r (d-r) (canonicalSmoothField β hβ hγ hb d).val=field β γ r := + funext fun x => (field_DPP β hβ hγ hb hr.le hd x).symm + simpa only [he,fieldGradient] using + general_dyadic_gradient_tendstoUniformly (canonicalSmoothField_curvature β hβ hγ hb d) + hγ hb d r hr + +end ParisiFinite + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath + +lemma scheduleField_measurable_d1 (f : SmoothField) (ls : Schedule) (s : ℝ) : + Measurable (fun p : ℝ×ℝ => (scheduleField f ls s p.1).d1 p.2) := by + induction ls generalizing s with + | nil => exact f.continuousD1.measurable.comp measurable_snd + | cons l ls ih => + have hh : Measurable (fun p : ℝ×ℝ => if p.1 rfl + +lemma finiteTimeCoefficient_continuous_ae (ls : Schedule) (s : ℝ) : + ∀ᵐ t ∂volume,ContinuousAt (finiteTimeCoefficient ls s) t := by + induction ls generalizing s with + | nil => exact ae_of_all _ fun t => continuousAt_const + | cons l ls ih => + filter_upwards [ih (s+l.2),volume.ae_ne (s+(l.2:ℝ))] with t ht hne + change t≠s+(l.2:ℝ) at hne + rcases lt_or_gt_of_ne hne with hlt | hgt + · apply (continuousAt_const (y := (l.1:ℝ))).congr_of_eventuallyEq + filter_upwards [Iio_mem_nhds hlt] with u hu + exact ite_eq_left hu + · apply ht.congr_of_eventuallyEq + filter_upwards [Ioi_mem_nhds hgt] with u hu + exact ite_eq_right (not_lt_of_ge hu.le) + +def scheduleDrift {β : ℝ≥0} {f : SmoothField} (hf : HasParisiCurvature β f) + (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) : Drift (β*β) β where + val := fun t x => finiteTimeCoefficient ls 0 t*(scheduleField f ls 0 t).d1 x + measurable := (finiteTimeCoefficient_measurable ls 0 |>.comp measurable_fst).mul + (scheduleField_measurable_d1 f ls 0) + bound := by + intro t x + have hc := scheduleField_curvature hf ls ha 0 t + have hg : |(scheduleField f ls 0 t).d1 x|≤(1:ℝ) := by + simpa only [hc.1,NNReal.coe_one] using (scheduleField f ls 0 t).normD1 x + rw [norm_mul,Real.norm_eq_abs,Real.norm_eq_abs] + exact (mul_le_mul_of_nonneg_left hg (abs_nonneg _)).trans + (by simpa only [mul_one] using finiteTimeCoefficient_bound β ls ha 0 t) + lipschitz := by + intro t + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,←mul_sub,abs_mul,NNReal.coe_mul] + have hh := (curvature_gradient_lipschitz (scheduleField_curvature hf ls ha 0 t)).dist_le_mul x y + rw [Real.dist_eq,Real.dist_eq] at hh + have hp := finiteTimeCoefficient_bound β ls ha 0 t + calc + _ ≤ |finiteTimeCoefficient ls 0 t| * ((β:ℝ)*|x-y|) := mul_le_mul_of_nonneg_left hh (abs_nonneg _) + _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_right hp (mul_nonneg β.coe_nonneg (abs_nonneg (x-y)))] + +lemma scheduleDrift_joint_ae_continuous {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) + (hw : width ls≤1) : + ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry (scheduleDrift hf ls ha).val) (t,x) := by + let r := generalScheduleTimeRealization f ls 0 le_rfl (by simpa only [zero_add] using hw) + filter_upwards [r.test.jointD1,finiteTimeCoefficient_continuous_ae ls 0] with t ht hc hmem x + have he : r.test.d1=fun t x => (scheduleField f ls 0 t).d1 x := funext fun t => funext fun x => r.d1_eq t x + have hh := ht hmem x + rw [he] at hh + exact (hc.comp continuousAt_fst).mul hh + +end ParisiFinite + +namespace ParisiPath +variable {K M : ℝ≥0} + +def patchDrift (u v : Drift K M) (a b : ℝ) : Drift K M where + val := fun t x => if t∈Ioo a b then u.val t x else v.val t x + measurable := Measurable.ite (measurableSet_Ioo.preimage measurable_fst) u.measurable v.measurable + bound := fun t x => by split_ifs; exact u.bound t x; exact v.bound t x + lipschitz := fun t => by split_ifs; exact u.lipschitz t; exact v.lipschitz t + +lemma continuousAt_patch_Ioo {u v : ℝ×ℝ → ℝ} {a b t x : ℝ} + (ht0 : t≠a) (ht1 : t≠b) (hu : ContinuousAt u (t,x)) (hv : ContinuousAt v (t,x)) : + ContinuousAt (fun p : ℝ×ℝ => if p.1∈Ioo a b then u p else v p) (t,x) := by + by_cases hmem : t∈Ioo a b + · apply hu.congr_of_eventuallyEq + filter_upwards [continuousAt_fst.preimage_mem_nhds (Ioo_mem_nhds hmem.1 hmem.2)] with p hp + exact ite_eq_left hp + · have hn : ∀ᶠ p : ℝ×ℝ in 𝓝 (t,x),p.1∉Ioo a b := by + rcases le_total t a with hta | hat + · have hta : t (not_lt_of_ge hp.le) hh.1 + · have hbt : b (not_lt_of_ge hp.le) hh.2 + apply hv.congr_of_eventuallyEq + filter_upwards [hn] with p hp + exact ite_eq_right hp + +lemma patchDrift_joint_ae_continuous (u v : Drift K M) (a b : ℝ) + (hu : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry u.val) (t,x)) + (hv : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry v.val) (t,x)) : + ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry (patchDrift u v a b).val) (t,x) := by + filter_upwards [hu,hv,volume.ae_ne a,volume.ae_ne b] with t ht hu ha hb hmem x + exact continuousAt_patch_Ioo ha hb (ht hmem x) (hu hmem x) + +end ParisiPath + +namespace ParisiFinite +lemma prefix_dyadic_coefficient_tendsto_ae {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (d : ℝ≥0) : + ∀ᵐ t ∂volume,t ∈ Ioo (0:ℝ) d → + Tendsto (fun n => finiteTimeCoefficient (dyadicSchedule γ false 0 d n) 0 t) + atTop (𝓝 (γ (Real.toNNReal t):ℝ)) := by + let c (s : ℝ) : ℝ := γ (Real.toNNReal s) + have hm : Monotone c := fun s t h => + NNReal.coe_le_coe.mpr (hγ (Real.toNNReal_le_toNNReal h)) + have hc : ∀ᵐ t ∂volume,ContinuousAt c t := by + rw [ae_iff] + exact hm.countable_not_continuousAt.measure_zero volume + filter_upwards [hc] with t ht hmem + have hr : Real.toNNReal t < d := by + exact_mod_cast (show (Real.toNNReal t:ℝ) (c.prefixDrift hβ d n).val t x) atTop + (𝓝 ((c.driftData hβ).val t x)) := by + filter_upwards [prefix_dyadic_coefficient_tendsto_ae c.mono d] with t ht x + by_cases hm : t∈Ioo (0:ℝ) d + · have hr : Real.toNNReal t solution (c.prefixDrift hβ d n) W) atTop (𝓝 (solution (c.driftData hβ) W)) := + solution_tendsto_drift_ae (c.prefixDrift_tendsto_ae hβ d hd) W + +end BoundedCoefficient +end ParisiFinite + +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + + + +lemma actual_conjugate_positive_continuous (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (d : ℝ≥0) (hd0 : d≠0) (hd1 : d≤1) + (ha : 0 Real.exp ((c.val d:ℝ)*field β c.val d x)*g x)) : + 0≤∫ ω,g (solution (c.driftData hβ) (brownianPath W ω) + ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩) ∂P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let f := canonicalSmoothField β hβ c.mono c.bound d + let ψ : ℝ → ℝ := fun x => Real.exp ((c.val d:ℝ)*f.val x)*g x + have hcψ : Continuous ψ := ((continuous_const.mul f.continuousVal).rexp).mul hg + let ls (n : ℕ) := dyadicSchedule c.val false 0 d n + let X (n : ℕ) (ω : Ω) := solution (c.prefixDrift hβ d n) (brownianPath W ω) + ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩ + let Y (ω : Ω) := solution (c.driftData hβ) (brownianPath W ω) + ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩ + have ht (ω : Ω) : Tendsto (fun n => X n ω) atTop (𝓝 (Y ω)) := + (show Continuous (fun Z : Path => Z ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩) from by fun_prop).continuousAt.tendsto.comp + (c.prefix_solution_tendsto hβ d hd1 (brownianPath W ω)) + have hj : Tendsto (fun n => ∫ ω,g (X n ω) ∂P) atTop (𝓝 (∫ ω,g (Y ω) ∂P)) := by + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (R:ℝ)) + · intro n + exact (hg.measurable.comp_aemeasurable + (aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) _)).aestronglyMeasurable + · exact integrable_const _ + · intro n + exact ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs] using hR (X n ω) + · exact ae_of_all _ fun ω => hg.continuousAt.tendsto.comp (ht ω) + apply ge_of_tendsto hj + filter_upwards [] with n + have ho : ParisiGuerra.OrderedFrom (c.val d) 0 (ls n) := by + simpa only [zero_add] using ordered_lower (c.val 0).coe_nonneg + (dyadicSchedule_ordered c.mono false 0 d n) + have hh := conjugate_linearEvolve_positiveDefinite f.lipschitz hψ hcψ + (by exact_mod_cast ha) (field_coshCone β hβ c.mono c.bound d (by exact_mod_cast ha) le_rfl) + (a := (0:ℝ)) le_rfl (ls n) ho + have he : (fun y => Real.exp (-(c.val d:ℝ)*f.val y)*ψ y)=g := by + funext x + dsimp only [ψ] + rw [←mul_assoc,←Real.exp_add] + ring_nf + rw [Real.exp_zero,one_mul] + change PositiveDefinite (fun x => Real.exp (0*evolve (ls n) f.val x)* + linearEvolve f.val (fun y => Real.exp (-(c.val d:ℝ)*f.val y)*ψ y) (ls n) x) at hh + rw [he] at hh + have hp := hh.at_zero + simp only [zero_mul,Real.exp_zero,one_mul] at hp + have heq := generalSchedule_actual_transport_continuous hW (c.prefixDrift hβ d n) + (c.prefixDrift_joint_ae_continuous hβ d hd1 n) f hg R hR (ls n) d hd0 hd1 + (dyadicSchedule_width c.val false 0 d n) (fun t ht x => by + simp only [prefixDrift,patchDrift,ite_eq_left ht,scheduleDrift,ls,f]) + exact heq.symm ▸ hp + +lemma conjugate_expectation_nonneg (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (d : ℝ≥0) (hd0 : d≠0) (hd1 : d≤1) + (ha : 0 Real.exp (-(c.val d:ℝ)*field β c.val d x)*ψ x + have hcg : Continuous g := ((continuous_const.mul + (field_lipschitz β hβ c.mono c.bound d).continuous).rexp).mul hcψ + have hp : PositiveDefinite g := + ((field_coshCone β hβ c.mono c.bound d (by exact_mod_cast ha) le_rfl).neg_exp_positiveDefinite + (by exact_mod_cast ha) (c.val d).coe_nonneg).mul hψ + apply c.actual_conjugate_positive_continuous hβ hW d hd0 hd1 ha hcg + (Real.toNNReal (g 0)) (fun x => by + simpa only [Real.norm_eq_abs,Real.coe_toNNReal _ hp.at_zero] using hp.norm_le x) + convert! hψ using 1 + funext x + dsimp only [g] + rw [←mul_assoc,←Real.exp_add] + have he : (c.val d:ℝ)*field β c.val d x+(-(c.val d:ℝ))*field β c.val d x=0 := by ring + rw [he,Real.exp_zero,one_mul] + +end ParisiFinite.BoundedCoefficient + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiSpectral +open ParisiFinite + +def stepWeight (a s : ℝ) (f : ℝ → ℝ) (p : ℝ × ℝ) : ℝ := + exp (a*f (p.1+s*p.2))/exp (a*step a s f p.1) + +def stepJoint (μ : Measure ℝ) (a s : ℝ) (f : ℝ → ℝ) : Measure (ℝ × ℝ) := + (μ.prod (gaussianReal 0 1)).withDensity (fun p => ENNReal.ofReal (stepWeight a s f p)) + +def stepLaw (μ : Measure ℝ) (a s : ℝ) (f : ℝ → ℝ) : Measure ℝ := + (stepJoint μ a s f).map (fun p => p.1+s*p.2) + +lemma stepWeight_pos (a s : ℝ) (f : ℝ → ℝ) (p : ℝ × ℝ) : + 0 (exp_pos _).ne') + +lemma integral_stepWeight {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a s x : ℝ) : (∫ z,stepWeight a s f (x,z) ∂gaussianReal 0 1)=1 := by + simp only [stepWeight,integral_div] + change expMass a s f x / exp (a*step a s f x)=1 + rw [←exp_step_all hf,div_self (exp_pos _).ne'] + +lemma stepJoint_probability (μ : Measure ℝ) [IsProbabilityMeasure μ] + {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) {a : ℝ} (ha : 0≤a) (s : ℝ) : + IsProbabilityMeasure (stepJoint μ a s f) := by + constructor + rw [stepJoint,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + rw [lintegral_prod _ ((continuous_stepWeight hf ha s).measurable.ennreal_ofReal.aemeasurable)] + have he (x : ℝ) : (∫⁻ z, ENNReal.ofReal (stepWeight a s f (x,z)) ∂gaussianReal 0 1)=1 := by + rw [←ofReal_integral_eq_lintegral_ofReal] + · rw [integral_stepWeight hf,ENNReal.ofReal_one] + · exact (integrable_exp_shift hf a x s).div_const (exp (a*step a s f x)) + · exact ae_of_all _ fun z => (stepWeight_pos a s f (x,z)).le + simp only [he,lintegral_const,measure_univ,mul_one] + +lemma integral_stepJoint {μ : Measure ℝ} [SFinite μ] {L : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) {a : ℝ} (ha : 0≤a) (s : ℝ) + (hi : Integrable (fun p : ℝ × ℝ => g (p.1+s*p.2)) (stepJoint μ a s f)) : + (∫ p,g (p.1+s*p.2) ∂stepJoint μ a s f)=∫ x,tiltedMean a s f g x ∂μ := by + have hm := (continuous_stepWeight hf ha s).measurable.ennreal_ofReal + have hb : ∀ᵐ p ∂μ.prod (gaussianReal 0 1), ENNReal.ofReal (stepWeight a s f p)<⊤ := + ae_of_all _ fun _ => ENNReal.ofReal_lt_top + have hi' := (integrable_withDensity_iff_integrable_smul' hm hb).mp hi + simp only [ENNReal.toReal_ofReal (stepWeight_pos a s f _).le,smul_eq_mul] at hi' + rw [stepJoint,integral_withDensity_eq_integral_toReal_smul hm hb] + simp only [ENNReal.toReal_ofReal (stepWeight_pos a s f _).le,smul_eq_mul] + rw [integral_prod _ hi'] + congr 1 + funext x + simp only [stepWeight,div_mul_eq_mul_div,integral_div,tiltedMean,expMoment,exp_step_all hf] + +lemma integral_stepLaw {μ : Measure ℝ} [SFinite μ] {L : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) {a : ℝ} (ha : 0≤a) (s : ℝ) (hg : StronglyMeasurable g) + (hi : Integrable g (stepLaw μ a s f)) : + (∫ y,g y ∂stepLaw μ a s f)=∫ x,tiltedMean a s f g x ∂μ := by + rw [stepLaw,integral_map_of_stronglyMeasurable (by fun_prop) hg] + exact integral_stepJoint hf ha s (hi.comp_aemeasurable (by fun_prop)) + +lemma measure_eq_stepLaw {μ ν : Measure ℝ} [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) {a : ℝ} (ha : 0≤a) (s : ℝ) + (h : ∀ (g : ℝ → ℝ), Continuous g → ∀ R : ℝ≥0, (∀x,|g x|≤R) → + (∫ y,g y ∂ν)=∫ x,tiltedMean a s f g x ∂μ) : ν=stepLaw μ a s f := by + have := stepJoint_probability μ hf ha s + have : IsProbabilityMeasure (stepLaw μ a s f) := by + unfold stepLaw + infer_instance + apply ext_of_forall_integral_eq_of_IsFiniteMeasure + intro g + rw [h g g.continuous ‖g‖₊ (fun x => by simpa only [Real.norm_eq_abs, coe_nnnorm] using g.norm_coe_le_norm x)] + symm + exact integral_stepLaw hf ha s g.continuous.stronglyMeasurable (g.integrable (μ := stepLaw μ a s f)) + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma actual_plateau_transport (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) {a d α : ℝ≥0} (ha0 : a≠0) (had : a solution (c.driftData hβ) (brownianPath W ω) + ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩)= + stepLaw (P.map (fun ω => solution (c.driftData hβ) (brownianPath W ω) + ⟨a,a.coe_nonneg,by exact_mod_cast had.le.trans hd1⟩)) α (Real.sqrt (d-a)) (field β c.val d) := by + have : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let X (t : Time) (ω : Ω) := solution (c.driftData hβ) (brownianPath W ω) t + have hm (t : Time) : AEMeasurable (X t) P := + aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) t + let ta : Time := ⟨a,a.coe_nonneg,by exact_mod_cast had.le.trans hd1⟩ + let td : Time := ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩ + change P.map (X td)=stepLaw (P.map (X ta)) α (Real.sqrt (d-a)) (field β c.val d) + have : IsProbabilityMeasure (P.map (X ta)) := inferInstance + have : IsProbabilityMeasure (P.map (X td)) := inferInstance + apply measure_eq_stepLaw (field_lipschitz β hβ c.mono c.bound d) α.coe_nonneg + intro g hgc R hR + rw [integral_map (hm td) hgc.aestronglyMeasurable, + integral_map (hm ta) (continuous_tiltedMean (field_lipschitz β hβ c.mono c.bound d) + hgc hR _ _).aestronglyMeasurable] + exact c.actual_plateau_transport hβ hW ha0 had hd1 hg hgc R hR + +lemma actual_plateau_transport_integrable (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) {a d α : ℝ≥0} (ha0 : a≠0) (had : a g (solution (c.driftData hβ) (brownianPath W ω) + ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩)) P) : + (∫ ω,g (solution (c.driftData hβ) (brownianPath W ω) ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩) ∂P)= + ∫ ω,tiltedMean α (Real.sqrt (d-a)) (field β c.val d) g + (solution (c.driftData hβ) (brownianPath W ω) ⟨a,a.coe_nonneg,by exact_mod_cast had.le.trans hd1⟩) ∂P := by + have : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let X (t : Time) (ω : Ω) := solution (c.driftData hβ) (brownianPath W ω) t + have hm (t : Time) : AEMeasurable (X t) P := + aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) t + let ta : Time := ⟨a,a.coe_nonneg,by exact_mod_cast had.le.trans hd1⟩ + let td : Time := ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩ + have : IsProbabilityMeasure (P.map (X ta)) := inferInstance + have he : P.map (X td)=stepLaw (P.map (X ta)) α (Real.sqrt (d-a)) (field β c.val d) := + c.actual_plateau_law hβ hW ha0 had hd1 hg + have hi' : Integrable g (P.map (X td)) := + (integrable_map_measure hgc.aestronglyMeasurable (hm td)).mpr hi + change (∫ ω,g (X td ω) ∂P)=∫ ω,tiltedMean α (Real.sqrt (d-a)) (field β c.val d) g (X ta ω) ∂P + rw [←integral_map (hm td) hgc.aestronglyMeasurable,he] + rw [integral_stepLaw (field_lipschitz β hβ c.mono c.bound d) α.coe_nonneg _ + hgc.stronglyMeasurable (he ▸ hi')] + have htc : StronglyMeasurable (tiltedMean α (Real.sqrt (d-a)) (field β c.val d) g) := by + have hnum : Continuous (fun p : ℝ × ℝ => Real.exp ((α:ℝ)*field β c.val d (p.1+Real.sqrt (d-a)*p.2))* + g (p.1+Real.sqrt (d-a)*p.2)) := by + have hf := (field_lipschitz β hβ c.mono c.bound d).continuous + exact ((continuous_const.mul (hf.comp (by fun_prop))).rexp).mul (hgc.comp (by fun_prop)) + have hden : Continuous (expMass α (Real.sqrt (d-a)) (field β c.val d)) := by + have hf := (step_lipschitz (field_lipschitz β hβ c.mono c.bound d) α.coe_nonneg (Real.sqrt (d-a))).continuous + have hh : Continuous (fun x => Real.exp ((α:ℝ)*step α (Real.sqrt (d-a)) (field β c.val d) x)) := + ((continuous_const (y := (α:ℝ))).mul hf).rexp + simp_rw [exp_step_all (field_lipschitz β hβ c.mono c.bound d)] at hh + exact hh + exact hnum.stronglyMeasurable.integral_prod_right.div hden.stronglyMeasurable + exact integral_map (hm ta) htc.aestronglyMeasurable + +end ParisiFinite.BoundedCoefficient + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ParisiConjugateTransport.lean b/lean/OAI/Probability/ParisiFinite/ParisiConjugateTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..c796a608f58f1e7ecd5698f7f933f081fe60eb55 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ParisiConjugateTransport.lean @@ -0,0 +1,548 @@ +import Mathlib +import OAI.Probability.ParisiFinite.CoshCone + +namespace OAI + +/-! Parisi Conjugate Transport. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open MeasureTheory ProbabilityTheory Filter Set Real +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Set Real +open scoped Topology NNReal +namespace ParisiSpectral +open ParisiFinite + +lemma CoshCone.neg_exp_positiveDefinite {b r : ℝ} {f : ℝ → ℝ} + (hb : 0 exp (b*f x))) (hr : 0≤r) : + PositiveDefinite (fun x => exp (-r*f x)) := by + rcases eq_or_lt_of_le hr with rfl | hr + · simpa only [neg_zero,zero_mul,exp_zero] using PositiveDefinite.constant zero_le_one + have hh := hc.neg_rpow_positiveDefinite (div_pos hr hb) + convert! hh using 1 + funext x + rw [rpow_def_of_pos (exp_pos _),log_exp] + congr 1 + field_simp + +lemma evolve_coshCone {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {b : ℝ} (_hb : 0 exp (b*f x))) + {a : ℝ} (ha : 0 exp (a*evolve ls f x)) := by + induction ls generalizing a with + | nil => exact CoshCone.exp_lower ha ho hc + | cons l ls ih => + have hp : 0<(l.1:ℝ) := ha.trans_le ho.1 + have hh := (ih hp ho.2).heat + ((continuous_const.mul (evolve_lipschitz hf ls).continuous).rexp) l.2 + apply CoshCone.exp_lower ha ho.1 + convert hh using 1 + funext x + exact exp_step_heat (evolve_lipschitz hf ls) hp.ne' l.2 x + +lemma evolve_neg_exp_positiveDefinite {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {b : ℝ} (hb : 0 exp (b*f x))) + {a r : ℝ} (_ha : 0≤a) (hr : 0≤r) (ls : Schedule) + (ho : ParisiGuerra.OrderedFrom b a ls) (hra : r≤a) : + PositiveDefinite (fun x => exp (-r*evolve ls f x)) := by + rcases eq_or_lt_of_le hr with rfl | hr + · simpa only [neg_zero,zero_mul,exp_zero] using PositiveDefinite.constant zero_le_one + have hp : 0 exact ⟨hg,hR⟩ + | cons l ls ih => + exact ⟨continuous_tiltedMean (evolve_lipschitz hf ls) ih.1 ih.2 _ _, + fun x => abs_tiltedMean_le (evolve_lipschitz hf ls) ih.1 ih.2 _ _ _⟩ + +lemma heat_eq_standard (d : ℝ≥0) {g : ℝ → ℝ} (hg : Continuous g) (x : ℝ) : + heat d g x = ∫ z,g (x+sqrt d*z) ∂gaussianReal 0 1 := by + have hm : Measure.map (fun z : ℝ => sqrt d*z) (gaussianReal 0 1)=gaussianReal 0 d := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext + simp [sq_sqrt d.coe_nonneg] + unfold heat + rw [←hm,integral_map (by fun_prop)] + exact (hg.comp (continuous_const.add continuous_id)).aestronglyMeasurable + +lemma exp_step_all {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a s x : ℝ) : exp (a*step a s f x)=expMass a s f x := by + by_cases ha : a=0 + · simp [ha,expMass] + · exact exp_step hf ha s x + +lemma conjugate_tiltedMean {L : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) (hg : Continuous g) + (a c : ℝ) (d : ℝ≥0) (x : ℝ) : + exp (a*step c (sqrt d) f x)*tiltedMean c (sqrt d) f g x = + exp (-(c-a)*step c (sqrt d) f x)* + heat d (fun y => exp (c*f y)*g y) x := by + have hc : Continuous (fun y => exp (c*f y)*g y) := + ((continuous_const.mul hf.continuous).rexp.mul hg) + rw [heat_eq_standard d hc] + change exp (a*step c (sqrt d) f x)*(expMoment c (sqrt d) f g x/expMass c (sqrt d) f x)=_ + rw [←exp_step_all hf c (sqrt d) x] + have he : exp (a*step c (sqrt d) f x)/exp (c*step c (sqrt d) f x)= + exp (-(c-a)*step c (sqrt d) f x) := by rw [←exp_sub];congr 1;ring + rw [←mul_div_assoc,mul_div_right_comm,he] + rfl + + + +lemma conjugate_linearEvolve_positiveDefinite {L : ℝ≥0} {f ψ : ℝ → ℝ} + (hf : LipschitzWith L f) (hψ : PositiveDefinite ψ) (hcψ : Continuous ψ) + {b : ℝ} (hb : 0 exp (b*f x))) + {a : ℝ} (ha : 0≤a) (ls : Schedule) (ho : ParisiGuerra.OrderedFrom b a ls) : + PositiveDefinite (fun x => exp (a*evolve ls f x)* + linearEvolve f (fun y => exp (-b*f y)*ψ y) ls x) := by + have hterm := (hcone.neg_exp_positiveDefinite hb hb.le).mul hψ + have hcterm : Continuous (fun y => exp (-b*f y)*ψ y) := + (continuous_const.mul hf.continuous).rexp.mul hcψ + have hbound : ∀ x, |exp (-b*f x)*ψ x|≤Real.toNNReal (exp (-b*f 0)*ψ 0) := by + intro x + have hh := hterm.norm_le x + simpa only [Real.norm_eq_abs,Real.coe_toNNReal _ hterm.at_zero] using hh + induction ls generalizing a with + | nil => + have hp := (hcone.neg_exp_positiveDefinite hb (sub_nonneg.mpr ho)).mul hψ + convert! hp using 1 + funext x + change exp (a*f x)*(exp (-b*f x)*ψ x)=_ + rw [←mul_assoc,←exp_add] + congr 2 + ring + | cons l ls ih => + have ht := ih l.1.coe_nonneg ho.2 + have hcont : Continuous (fun x => exp ((l.1:ℝ)*evolve ls f x)* + linearEvolve f (fun y => exp (-b*f y)*ψ y) ls x) := + (continuous_const.mul (evolve_lipschitz hf ls).continuous).rexp.mul + (linearEvolve_continuous_bound hf hcterm hbound ls).1 + have hp := ht.heat hcont l.2 + have he := evolve_neg_exp_positiveDefinite hf hb hcone l.1.coe_nonneg + (sub_nonneg.mpr ho.1) (l::ls) ⟨le_rfl,ho.2⟩ (sub_le_self _ ha) + convert! he.mul hp using 1 + funext x + exact conjugate_tiltedMean (evolve_lipschitz hf ls) + (linearEvolve_continuous_bound hf hcterm hbound ls).1 a l.1 l.2 x + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set ContinuousLinearMap +open scoped Topology NNReal Convolution +namespace ParisiFinite +open ParisiPath + +lemma compact_convolution_bound {k g : ℝ → ℝ} (hk : HasCompactSupport k) + (hkc : Continuous k) (hg : Continuous g) (R : ℝ≥0) (hR : ∀ x,|g x|≤R) (x : ℝ) : + |(k ⋆[lsmul ℝ ℝ,volume] g) x|≤(∫ z,‖k z‖)*(R:ℝ) := by + change |∫ z,k z*g (x-z)|≤_ + calc + _ ≤ ∫ z,‖k z*g (x-z)‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ z,‖k z‖*(R:ℝ) := by + apply integral_mono (hk.convolutionExists_left (lsmul ℝ ℝ) hkc hg.locallyIntegrable x).norm + (hkc.integrable_of_hasCompactSupport hk |>.norm.mul_const _) + intro z + dsimp only + rw [lsmul_apply,smul_eq_mul,norm_mul,Real.norm_eq_abs (g (x-z))] + exact mul_le_mul_of_nonneg_left (hR _) (norm_nonneg _) + _ = _ := integral_mul_const _ _ + +def boundedMollify (φ : ContDiffBump (0:ℝ)) {g : ℝ → ℝ} (hg : Continuous g) + (R : ℝ≥0) (hR : ∀ x,|g x|≤R) : SmoothField where + val := smoothConvolution φ g + d1 := deriv (φ.normed volume) ⋆[lsmul ℝ ℝ,volume] g + d2 := deriv (deriv (φ.normed volume)) ⋆[lsmul ℝ ℝ,volume] g + hasD1 := φ.hasCompactSupport_normed.hasDerivAt_convolution_left (lsmul ℝ ℝ) + φ.contDiff_normed hg.locallyIntegrable + hasD2 := φ.hasCompactSupport_normed.deriv.hasDerivAt_convolution_left (lsmul ℝ ℝ) + (ContDiff.deriv' (φ.contDiff_normed (n:=2))) hg.locallyIntegrable + continuousD2 := by + apply φ.hasCompactSupport_normed.deriv.deriv.contDiff_convolution_left (lsmul ℝ ℝ) + (ContDiff.deriv' (n:=1) (ContDiff.deriv' (n:=2) (φ.contDiff_normed (μ:=volume) (n:=3)))) hg.locallyIntegrable |>.continuous + bound1 := ⟨(∫ z,‖deriv (φ.normed volume) z‖)*(R:ℝ),by positivity⟩ + bound2 := ⟨(∫ z,‖deriv (deriv (φ.normed volume)) z‖)*(R:ℝ),by positivity⟩ + normD1 := compact_convolution_bound φ.hasCompactSupport_normed.deriv + (φ.contDiff_normed (n:=1) |>.continuous_deriv (by norm_num)) hg R hR + normD2 := compact_convolution_bound φ.hasCompactSupport_normed.deriv.deriv + (ContDiff.deriv' (n:=0) (ContDiff.deriv' (n:=1) (φ.contDiff_normed (μ:=volume) (n:=2))) |>.continuous) hg R hR + +lemma boundedMollify_bound (φ : ContDiffBump (0:ℝ)) {g : ℝ → ℝ} (hg : Continuous g) + (R : ℝ≥0) (hR : ∀ x,|g x|≤R) (x : ℝ) : |(boundedMollify φ hg R hR).val x|≤R := + by simpa only [boundedMollify,Real.norm_eq_abs] using smoothConvolution_bound φ hg hR x + +lemma tiltedMean_tendsto_terminal {L R : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) {G : ℕ → ℝ → ℝ} (hGc : ∀ n,Continuous (G n)) + (hGR : ∀ n x,|G n x|≤R) (hG : ∀ x,Tendsto (fun n => G n x) atTop (𝓝 (g x))) + (a s x : ℝ) : Tendsto (fun n => tiltedMean a s f (G n) x) atTop (𝓝 (tiltedMean a s f g x)) := by + apply Tendsto.div_const + apply tendsto_integral_of_dominated_convergence (fun z => Real.exp (a*f (x+s*z))*(R:ℝ)) + · intro n + exact (((continuous_const.mul (hf.continuous.comp (continuous_const.add (continuous_const.mul continuous_id)))).rexp).mul + ((hGc n).comp (continuous_const.add (continuous_const.mul continuous_id)))).aestronglyMeasurable + · exact (integrable_exp_shift hf a x s).mul_const _ + · intro n + exact ae_of_all _ fun z => by + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _)] + exact mul_le_mul_of_nonneg_left (hGR n _) (Real.exp_pos _).le + · exact ae_of_all _ fun z => (hG _).const_mul _ + +lemma linearEvolve_tendsto_terminal {L R : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) {G : ℕ → ℝ → ℝ} (hGc : ∀ n,Continuous (G n)) + (hGR : ∀ n x,|G n x|≤R) (hG : ∀ x,Tendsto (fun n => G n x) atTop (𝓝 (g x))) + (ls : Schedule) (x : ℝ) : + Tendsto (fun n => linearEvolve f (G n) ls x) atTop (𝓝 (linearEvolve f g ls x)) := by + induction ls generalizing x with + | nil => exact hG x + | cons l ls ih => + exact tiltedMean_tendsto_terminal (evolve_lipschitz hf ls) + (fun n => (ParisiSpectral.linearEvolve_continuous_bound hf (hGc n) (hGR n) ls).1) + (fun n => (ParisiSpectral.linearEvolve_continuous_bound hf (hGc n) (hGR n) ls).2) ih _ _ _ + +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma generalSchedule_actual_transport_continuous (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (f : SmoothField) {g : ℝ → ℝ} (hg : Continuous g) (R : ℝ≥0) (hR : ∀ x, |g x|≤R) + (ls : Schedule) (d : ℝ≥0) (hd0 : d≠0) (hd1 : d≤1) + (hw : width ls=d) + (hb : ∀ t∈Ioo (0:ℝ) d,∀ x,b.val t x=finiteTimeCoefficient ls 0 t*(scheduleField f ls 0 t).d1 x) : + (∫ ω,g (solution b (brownianPath W ω) + ⟨d,by exact ⟨d.coe_nonneg,by exact_mod_cast hd1⟩⟩) ∂P) = linearEvolve f.val g ls 0 := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let G (n : ℕ) := boundedMollify (shrinkingBump n) hg R hR + let X (ω : Ω) := solution b (brownianPath W ω) ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩ + have hGR (n : ℕ) (x : ℝ) : |(G n).val x|≤R := boundedMollify_bound _ hg R hR x + have ht (x : ℝ) : Tendsto (fun n => (G n).val x) atTop (𝓝 (g x)) := smoothConvolution_tendsto hg x + have hi : Tendsto (fun n => ∫ ω,(G n).val (X ω) ∂P) atTop (𝓝 (∫ ω,g (X ω) ∂P)) := by + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (R:ℝ)) + · intro n + exact ((G n).continuousVal.measurable.comp_aemeasurable + (aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) _)).aestronglyMeasurable + · exact integrable_const _ + · intro n + exact ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs] using hGR n (X ω) + · exact ae_of_all _ fun ω => ht (X ω) + have he (n : ℕ) : (∫ ω,(G n).val (X ω) ∂P)=linearEvolve f.val (G n).val ls 0 := + generalSchedule_actual_transport hW b hc f (G n) R (hGR n) ls d hd0 hd1 hw hb + simp_rw [he] at hi + exact tendsto_nhds_unique hi (linearEvolve_tendsto_terminal f.lipschitz + (fun n => (G n).continuousVal) hGR ht ls 0) + +end ParisiFinite + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma brownian_solution_time_generator_between (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) (a c : ℝ≥0) (ha0 : a≠0) (hac : a ∫ ω,evolve ls (terminalPerturbation f g u).val (X ω) ∂P) + (∫ ω,linearEvolve f.val g.val ls (X ω) ∂P) 0 := by + let F := evolveFamily (terminalFamily f g R hR) ls + have hd (u x : ℝ) : |F.dot u x|≤R := by + rw [evolveFamily_dot] + apply (linearEvolve_continuous_bound (terminalPerturbation f g u).lipschitz + (g.continuousVal.const_mul (Real.cos u)) _ ls).2 x + intro y + rw [abs_mul] + exact (mul_le_mul (Real.abs_cos_le_one u) (hR y) (abs_nonneg _) zero_le_one).trans_eq (one_mul _) + have hi : HasDerivAt (fun u => ∫ ω,(F.field u).val (X ω) ∂P) + (∫ ω,F.dot 0 (X ω) ∂P) 0 := by + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le (s:=univ) + (bound:=fun _ : Ω => (R:ℝ)) (F':=fun u ω => F.dot u (X ω)) (by simp) ?_ ?_ ?_ ?_ ?_ ?_).2 + · exact Eventually.of_forall fun u => ((F.field u).lipschitz.continuous.measurable.comp_aemeasurable hX.aemeasurable).aestronglyMeasurable + · rw [show (F.field 0).val = (smoothEvolve f ls).val by + funext x;rw [evolveFamily_val,smoothEvolve_val];simp only [terminalFamily,SmoothField.directional,terminalPerturbation,Real.sin_zero,zero_mul,add_zero]] + exact ((smoothEvolve f ls).staticTimeTest.slice 0).integrable_comp hX + · exact ((F.continuousDot.comp (continuous_const.prodMk continuous_id)).measurable.comp_aemeasurable hX.aemeasurable).aestronglyMeasurable + · exact ae_of_all _ fun ω u _ => by simpa only [Real.norm_eq_abs] using hd u (X ω) + · exact integrable_const _ + · exact ae_of_all _ fun ω u _ => F.hasDot (X ω) u + dsimp only [F] at hi + simp_rw [evolveFamily_val,evolveFamily_dot] at hi + simpa only [terminalFamily,SmoothField.directional,terminalPerturbation,Real.sin_zero,Real.cos_zero,zero_mul,add_zero,one_mul] using hi + +lemma generalSchedule_actual_transport_between (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (f g : SmoothField) (R : ℝ≥0) (hR : ∀ x,|g.val x|≤R) + (ls : Schedule) (a c : ℝ≥0) (ha0 : a≠0) (hac : a solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1⟩ + let Y : Ω → ℝ := fun ω => solution b (brownianPath W ω) ⟨a,a.coe_nonneg,by exact_mod_cast hac.le.trans hc1⟩ + let J := ∫ ω,g.val (X ω) ∂P + let V : ℝ → ℝ := fun u => (∫ ω,evolve ls (terminalPerturbation f g u).val (Y ω) ∂P)- + (∫ ω,evolve ls f.val (Y ω) ∂P)-Real.sin u*J + have hX : Integrable X P := brownian_solution_integrable hW b _ + have hY : Integrable Y P := brownian_solution_integrable hW b _ + have hif : Integrable (fun ω => f.val (X ω)) P := (f.staticTimeTest.slice 0).integrable_comp hX + have hig : Integrable (fun ω => g.val (X ω)) P := (g.staticTimeTest.slice 0).integrable_comp hX + have hle (u : ℝ) : 0≤V u := by + have hh := generalSchedule_terminal_comparison_between hW b hc f (terminalPerturbation f g u) + ls a c ha0 hac hc1 hw hb + change (∫ ω,f.val (X ω)+Real.sin u*g.val (X ω) ∂P)-(∫ ω,f.val (X ω) ∂P)≤_ at hh + rw [integral_add hif (hig.const_mul _),integral_const_mul] at hh + simp only [smoothEvolve_val] at hh + dsimp only [V,J] + linarith + have he : V 0=0 := by + simp only [V,terminalPerturbation,Real.sin_zero,zero_mul,add_zero,sub_self] + have hm : IsLocalMin V 0 := by + filter_upwards [] with u + rw [he] + exact hle u + have hd : HasDerivAt V ((∫ ω,linearEvolve f.val g.val ls (Y ω) ∂P)-J) 0 := by + have hh := ((hasDerivAt_expected_evolve_terminal hY f g R hR ls).sub_const + (∫ ω,evolve ls f.val (Y ω) ∂P)).sub ((Real.hasDerivAt_sin 0).mul_const J) + convert! hh using 1 + simp only [Real.cos_zero,one_mul] + have hz := hm.hasDerivAt_eq_zero hd + change J=_ + linarith + +lemma generalSchedule_actual_transport_between_continuous (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (f : SmoothField) {g : ℝ → ℝ} (hg : Continuous g) (R : ℝ≥0) (hR : ∀ x,|g x|≤R) + (ls : Schedule) (a c : ℝ≥0) (ha0 : a≠0) (hac : a solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1⟩ + let Y : Ω → ℝ := fun ω => solution b (brownianPath W ω) ⟨a,a.coe_nonneg,by exact_mod_cast hac.le.trans hc1⟩ + have hGR (n : ℕ) (x : ℝ) : |(G n).val x|≤R := boundedMollify_bound _ hg R hR x + have hGc (n : ℕ) := (G n).continuousVal + have ht (x : ℝ) : Tendsto (fun n => (G n).val x) atTop (𝓝 (g x)) := smoothConvolution_tendsto hg x + have hx : Tendsto (fun n => ∫ ω,(G n).val (X ω) ∂P) atTop (𝓝 (∫ ω,g (X ω) ∂P)) := by + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (R:ℝ)) + · intro n + exact ((hGc n).measurable.comp_aemeasurable + (aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) _)).aestronglyMeasurable + · exact integrable_const _ + · intro n + exact ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs] using hGR n (X ω) + · exact ae_of_all _ fun ω => ht (X ω) + have hy : Tendsto (fun n => ∫ ω,linearEvolve f.val (G n).val ls (Y ω) ∂P) atTop + (𝓝 (∫ ω,linearEvolve f.val g ls (Y ω) ∂P)) := by + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (R:ℝ)) + · intro n + exact ((linearEvolve_continuous_bound f.lipschitz (hGc n) (hGR n) ls).1.measurable.comp_aemeasurable + (aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) _)).aestronglyMeasurable + · exact integrable_const _ + · intro n + exact ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs] using + (linearEvolve_continuous_bound f.lipschitz (hGc n) (hGR n) ls).2 (Y ω) + · exact ae_of_all _ fun ω => linearEvolve_tendsto_terminal f.lipschitz hGc hGR ht ls (Y ω) + have he (n : ℕ) : (∫ ω,(G n).val (X ω) ∂P)=∫ ω,linearEvolve f.val (G n).val ls (Y ω) ∂P := + generalSchedule_actual_transport_between hW b hc f (G n) R (hGR n) ls a c ha0 hac hc1 hw hb + simp_rw [he] at hx + exact tendsto_nhds_unique hx hy + +end ParisiFinite + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath +variable {K M : ℝ≥0} +lemma drift_comp_tendsto_at {B : ℕ → Drift K M} {b : Drift K M} + {t : ℝ} (hB : ∀ x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) + {X : ℕ → Path} {Y : Path} (hX : Tendsto X atTop (𝓝 Y)) : + Tendsto (fun n => (B n).val t (extend (X n) t)) atTop (𝓝 (b.val t (extend Y t))) := by + have hx : Tendsto (fun n => extend (X n) t) atTop (𝓝 (extend Y t)) := + (show Continuous (fun V : Path => extend V t) by unfold extend;fun_prop).continuousAt.tendsto.comp hX + have hd : Tendsto (fun n => (B n).val t (extend (X n) t)-(B n).val t (extend Y t)) + atTop (𝓝 (0:ℝ)) := by + have hnorm (n : ℕ) : ‖(B n).val t (extend (X n) t)-(B n).val t (extend Y t)‖ ≤ + (K:ℝ)*‖extend (X n) t-extend Y t‖ := by + simpa only [←dist_eq_norm] using (B n).lipschitz t |>.dist_le_mul (extend (X n) t) (extend Y t) + exact squeeze_zero_norm hnorm + (by simpa only [sub_self,norm_zero,mul_zero] using + ((hx.sub_const (extend Y t)).norm.const_mul (K:ℝ))) + simpa only [sub_add_cancel,zero_add] using hd.add (hB (extend Y t)) + +lemma next_tendsto_drift_ae {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ᵐ t ∂volume, ∀ x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) + {X : ℕ → Path} {Y : Path} (hX : Tendsto X atTop (𝓝 Y)) (W : Path) : + Tendsto (fun n => next (B n) W (X n)) atTop (𝓝 (next b W Y)) := by + let R (n : ℕ) (t : ℝ) : ℝ := ‖(B n).val t (extend (X n) t)-b.val t (extend Y t)‖ + have hRm (n : ℕ) : Measurable (R n) := + (((B n).measurable.comp (measurable_id.prodMk (continuous_extend (X n)).measurable)).sub + (b.measurable.comp (measurable_id.prodMk (continuous_extend Y).measurable))).norm + have hRb (n : ℕ) (t : ℝ) : R n t ≤ 2*(M:ℝ) := + (norm_sub_le _ _).trans (by linarith [(B n).bound t (extend (X n) t),b.bound t (extend Y t)]) + have hRi (n : ℕ) : IntervalIntegrable (R n) volume 0 1 := + (intervalIntegrable_const (c := 2*(M:ℝ))).mono_fun' (hRm n).aestronglyMeasurable + (Eventually.of_forall fun t => by simpa only [R,norm_norm] using hRb n t) + have he : Tendsto (fun n => ∫ t in (0:ℝ)..1,R n t) atTop (𝓝 (0:ℝ)) := by + have hh := intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (a := (0:ℝ)) (b := 1) (μ := volume) (l := atTop) (F := R) (f := fun _ => (0:ℝ)) + (fun _ => 2*(M:ℝ)) (Eventually.of_forall fun n => (hRm n).aestronglyMeasurable.restrict) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => by simpa only [R,norm_norm] using hRb n t) + intervalIntegrable_const (by + filter_upwards [hB] with t ht hit + simpa only [R,sub_self,norm_zero] using ((drift_comp_tendsto_at ht hX).sub_const (b.val t (extend Y t))).norm) + simpa only [intervalIntegral.integral_zero] using hh + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun n => dist_nonneg) (fun n => ?_) he + apply (ContinuousMap.dist_le + (intervalIntegral.integral_nonneg zero_le_one (fun t _ => norm_nonneg _))).mpr + intro t + rw [dist_eq_norm,next_apply,next_apply,add_sub_add_left_eq_sub, + ←intervalIntegral.integral_sub (integrable_comp (B n) (X n) _ _) (integrable_comp b Y _ _)] + calc + _ ≤ ∫ s in (0:ℝ)..(t:ℝ),R n s := intervalIntegral.norm_integral_le_integral_norm t.property.1 + _ ≤ ∫ s in (0:ℝ)..1,R n s := intervalIntegral.integral_mono_interval le_rfl t.property.1 + t.property.2 (ae_of_all _ fun s => norm_nonneg _) (hRi n) + +lemma iterate_tendsto_drift_ae {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ᵐ t ∂volume, ∀ x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) + (W X : Path) (k : ℕ) : + Tendsto (fun n => ((next (B n) W)^[k]) X) atTop (𝓝 (((next b W)^[k]) X)) := by + induction k with + | zero => exact tendsto_const_nhds + | succ k ih => simpa only [iterate_succ_apply'] using next_tendsto_drift_ae hB ih W + + + +theorem solution_tendsto_drift_ae {B : ℕ → Drift K M} {b : Drift K M} + (hB : ∀ᵐ t ∂volume, ∀ x,Tendsto (fun n => (B n).val t x) atTop (𝓝 (b.val t x))) (W : Path) : + Tendsto (fun n => solution (B n) W) atTop (𝓝 (solution b W)) := by + obtain ⟨k,hk⟩ := (FloorSemiring.tendsto_pow_div_factorial_atTop (K:ℝ)).eventually + (gt_mem_nhds zero_lt_one) |>.exists + let C : ℝ≥0 := ⟨(K:ℝ)^k/k.factorial,by positivity⟩ + have hc (b' : Drift K M) : ContractingWith C ((next b' W)^[k]) := + ⟨hk,LipschitzWith.of_dist_le_mul fun X Y => dist_iterate b' W X Y k⟩ + have ht := iterate_tendsto_drift_ae hB W (solution b W) k + rw [(solution_fixed b W).iterate k] at ht + have hz : Tendsto (fun n => dist (solution b W) (((next (B n) W)^[k]) (solution b W))/(1-(C:ℝ))) + atTop (𝓝 (0:ℝ)) := by + simpa only [dist_self,zero_div] using ((tendsto_const_nhds (x := solution b W)).dist ht).div_const (1-(C:ℝ)) + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun n => dist_nonneg) (fun n => ?_) hz + rw [dist_comm] + exact (hc (B n)).dist_le_of_fixedPoint _ ((solution_fixed (B n) W).iterate k) + +end ParisiPath + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ParisiCoshEntropy.lean b/lean/OAI/Probability/ParisiFinite/ParisiCoshEntropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..35e8fa5b9d9fcd3327626f6bf53a417ce2dcdc0f --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ParisiCoshEntropy.lean @@ -0,0 +1,625 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ParisiHankelDerivative + +namespace OAI + +/-! Parisi Cosh Entropy. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open MeasureTheory ProbabilityTheory Set Real Matrix Filter +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Set Real Filter +open scoped Topology NNReal +namespace ParisiSpectral + +def ExpGrowth (M : ℝ) (f : ℝ → ℝ) : Prop := ∃ C : ℝ,0≤C ∧ ∀ x,|f x|≤C*exp (M*|x|) +lemma ExpGrowth.add {M : ℝ} {f g : ℝ → ℝ} (hf : ExpGrowth M f) (hg : ExpGrowth M g) : + ExpGrowth M (fun x => f x+g x) := by + obtain ⟨C,hC,hf⟩ := hf + obtain ⟨D,hD,hg⟩ := hg + refine ⟨C+D,add_nonneg hC hD,fun x => ?_⟩ + exact (abs_add_le _ _).trans (by nlinarith [hf x,hg x]) +lemma ExpGrowth.const_mul {M : ℝ} {f : ℝ → ℝ} (hf : ExpGrowth M f) (a : ℝ) : + ExpGrowth M (fun x => a*f x) := by + obtain ⟨C,hC,hf⟩ := hf + refine ⟨|a| *C,mul_nonneg (abs_nonneg a) hC,fun x => ?_⟩ + rw [abs_mul,mul_assoc] + exact mul_le_mul_of_nonneg_left (hf x) (abs_nonneg a) +lemma ExpGrowth.neg {M : ℝ} {f : ℝ → ℝ} (hf : ExpGrowth M f) : ExpGrowth M (fun x => -f x) := by + simpa only [neg_one_mul] using hf.const_mul (-1) +lemma ExpGrowth.sub {M : ℝ} {f g : ℝ → ℝ} (hf : ExpGrowth M f) (hg : ExpGrowth M g) : + ExpGrowth M (fun x => f x-g x) := by simpa only [sub_eq_add_neg] using hf.add hg.neg +lemma ExpGrowth.of_bounded {M C : ℝ} (hM : 0≤M) (hC : 0≤C) {f : ℝ → ℝ} (hf : ∀ x,|f x|≤C) : + ExpGrowth M f := ⟨C,hC,fun x => (hf x).trans (le_mul_of_one_le_right hC (one_le_exp_iff.mpr (by positivity)))⟩ +lemma ExpGrowth.mono {M N : ℝ} (hMN : M≤N) {f : ℝ → ℝ} (hf : ExpGrowth M f) : ExpGrowth N f := by + obtain ⟨C,hC,hf⟩ := hf + exact ⟨C,hC,fun x => (hf x).trans (mul_le_mul_of_nonneg_left (exp_le_exp.mpr (mul_le_mul_of_nonneg_right hMN (abs_nonneg _))) hC)⟩ + +lemma cosh_le_exp_abs (x : ℝ) : cosh x≤exp |x| := by + rw [cosh_eq] + linarith [exp_le_exp.mpr (le_abs_self x),exp_le_exp.mpr (neg_le_abs x)] +lemma sinh_abs_le_cosh (x : ℝ) : |sinh x|≤cosh x := by + rw [abs_le] + constructor <;> (rw [sinh_eq,cosh_eq]; linarith [exp_pos x,exp_pos (-x)]) +lemma cosh_ExpGrowth (α : ℝ) : ExpGrowth (|α|+1) (fun x => cosh (α*x)) := by + refine (show ExpGrowth |α| (fun x => cosh (α*x)) from ⟨1,by norm_num,fun x => ?_⟩).mono (by linarith) + simpa only [abs_of_pos (cosh_pos _),one_mul,abs_mul] using cosh_le_exp_abs (α*x) +lemma sinh_ExpGrowth (α : ℝ) : ExpGrowth (|α|+1) (fun x => sinh (α*x)) := by + obtain ⟨C,hC,hb⟩ := cosh_ExpGrowth α + exact ⟨C,hC,fun x => (sinh_abs_le_cosh _).trans (by simpa only [abs_of_pos (cosh_pos _)] using hb x)⟩ +lemma sech_ExpGrowth (α : ℝ) : ExpGrowth (|α|+1) (fun x => (cosh (α*x))⁻¹) := by + apply ExpGrowth.of_bounded (by positivity) (C := 1) (by norm_num) + intro x + rw [abs_inv,abs_of_pos (cosh_pos _)] + exact inv_le_one_of_one_le₀ (one_le_cosh _) +lemma sechCube_ExpGrowth (α : ℝ) : ExpGrowth (|α|+1) (fun x => (cosh (α*x))⁻¹^3) := by + apply ExpGrowth.of_bounded (by positivity) (C := 1) (by norm_num) + intro x + rw [abs_pow,abs_inv,abs_of_pos (cosh_pos _)] + exact pow_le_one₀ (inv_pos.mpr (cosh_pos _)).le (inv_le_one_of_one_le₀ (one_le_cosh _)) + +def coshEntropy (α x : ℝ) := cosh (α*x)*log (cosh (α*x)) +def coshEntropyD (α x : ℝ) := α*sinh (α*x)*(log (cosh (α*x))+1) +def coshEntropyU (α x : ℝ) := α^2*(2*cosh (α*x)-(cosh (α*x))⁻¹) +def coshEntropyUD (α x : ℝ) := α^3*(2*sinh (α*x)+sinh (α*x)/(cosh (α*x))^2) + +lemma coshEntropy_hasDerivAt (α x : ℝ) : HasDerivAt (coshEntropy α) (coshEntropyD α x) x := by + have hc := ((hasDerivAt_id x).const_mul α).cosh + have hl := hc.log (cosh_pos _).ne' + convert hc.mul hl using 1 <;> first | rfl | (simp only [id_eq,mul_one,coshEntropyD]; field_simp [(cosh_pos (α*x)).ne']) +lemma coshEntropyD_hasDerivAt (α x : ℝ) : + HasDerivAt (coshEntropyD α) (α^2*coshEntropy α x+coshEntropyU α x) x := by + have hc := ((hasDerivAt_id x).const_mul α).cosh + have hs := ((hasDerivAt_id x).const_mul α).sinh + have hl := hc.log (cosh_pos _).ne' + convert (hs.const_mul α).mul (hl.add_const 1) using 1 <;> first | rfl | (simp only [id_eq,mul_one,coshEntropy,coshEntropyU]; field_simp [(cosh_pos (α*x)).ne']; linear_combination α^2*(cosh_sq_sub_sinh_sq (α*x))) +lemma coshEntropyU_hasDerivAt (α x : ℝ) : HasDerivAt (coshEntropyU α) (coshEntropyUD α x) x := by + have hc := ((hasDerivAt_id x).const_mul α).cosh + convert ((hc.const_mul 2).sub (hc.inv (cosh_pos _).ne')).const_mul (α^2) using 1 <;> + first | rfl | (simp only [id_eq,mul_one,coshEntropyUD]; field_simp [(cosh_pos (α*x)).ne']; ring) +lemma coshEntropyUD_hasDerivAt (α x : ℝ) : + HasDerivAt (coshEntropyUD α) (α^2*coshEntropyU α x+2*α^4*((cosh (α*x))⁻¹^3)) x := by + have hc := ((hasDerivAt_id x).const_mul α).cosh + have hs := ((hasDerivAt_id x).const_mul α).sinh + convert ((hs.const_mul 2).add (hs.div (hc.fun_pow 2) (pow_ne_zero 2 (cosh_pos _).ne'))).const_mul (α^3) using 1 <;> + first | rfl | (simp only [id_eq,mul_one,coshEntropyU,Nat.cast_ofNat,Nat.reduceSub,pow_one]; field_simp [(cosh_pos (α*x)).ne']; linear_combination -2*α^4*(cosh_sq_sub_sinh_sq (α*x))) + +lemma coshEntropy_ExpGrowth (α : ℝ) : ExpGrowth (|α|+1) (coshEntropy α) := by + refine ⟨|α|,abs_nonneg _,fun x => ?_⟩ + rw [coshEntropy,abs_mul,abs_of_pos (cosh_pos _)] + calc + cosh (α*x)*|log (cosh (α*x))| ≤ exp (|α| *|x|)*(|α| *|x|) := + mul_le_mul (by simpa only [abs_mul] using cosh_le_exp_abs (α*x)) + (by simpa only [abs_mul] using abs_log_cosh_le (α*x)) (abs_nonneg _) (exp_pos _).le + _ = |α| *(|x| *exp (|α| *|x|)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left (ParisiFinite.abs_mul_exp_le |α| x) (abs_nonneg _) + +lemma sinh_log_ExpGrowth (α : ℝ) : + ExpGrowth (|α|+1) (fun x => sinh (α*x)*log (cosh (α*x))) := by + obtain ⟨C,hC,hf⟩ := coshEntropy_ExpGrowth α + refine ⟨C,hC,fun x => ?_⟩ + apply le_trans _ (hf x) + simp only [coshEntropy,abs_mul,abs_of_pos (cosh_pos _)] + exact mul_le_mul_of_nonneg_right (sinh_abs_le_cosh _) (abs_nonneg _) +lemma coshEntropyD_ExpGrowth (α : ℝ) : ExpGrowth (|α|+1) (coshEntropyD α) := by + convert ((sinh_log_ExpGrowth α).const_mul α).add ((sinh_ExpGrowth α).const_mul α) using 1 + ext x + dsimp only [coshEntropyD] + ring +lemma coshEntropyU_ExpGrowth (α : ℝ) : ExpGrowth (|α|+1) (coshEntropyU α) := + (((cosh_ExpGrowth α).const_mul 2).sub (sech_ExpGrowth α)).const_mul (α^2) +lemma coshEntropyUD_ExpGrowth (α : ℝ) : ExpGrowth (|α|+1) (coshEntropyUD α) := by + have hh : ExpGrowth (|α|+1) (fun x => sinh (α*x)/cosh (α*x)^2) := by + apply ExpGrowth.of_bounded (by positivity) (C := 1) (by norm_num) + intro x + rw [abs_div,abs_pow,abs_of_pos (cosh_pos _),div_le_iff₀ (sq_pos_of_pos (cosh_pos _)),one_mul] + exact (sinh_abs_le_cosh _).trans (by nlinarith [one_le_cosh (α*x)]) + exact (((sinh_ExpGrowth α).const_mul 2).add hh).const_mul (α^3) + +lemma continuous_coshEntropy (α : ℝ) : Continuous (coshEntropy α) := + (show Differentiable ℝ (coshEntropy α) from fun x => (coshEntropy_hasDerivAt α x).differentiableAt).continuous +lemma continuous_coshEntropyD (α : ℝ) : Continuous (coshEntropyD α) := + (show Differentiable ℝ (coshEntropyD α) from fun x => (coshEntropyD_hasDerivAt α x).differentiableAt).continuous +lemma continuous_coshEntropyU (α : ℝ) : Continuous (coshEntropyU α) := + (show Differentiable ℝ (coshEntropyU α) from fun x => (coshEntropyU_hasDerivAt α x).differentiableAt).continuous +lemma continuous_coshEntropyUD (α : ℝ) : Continuous (coshEntropyUD α) := + (show Differentiable ℝ (coshEntropyUD α) from fun x => (coshEntropyUD_hasDerivAt α x).differentiableAt).continuous + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Set Real Filter +open scoped Topology NNReal +namespace ParisiSpectral + +lemma heatLaw_eq_map {μ : Measure ℝ} [IsFiniteMeasure μ] {a t : ℝ} (ht : a≤t) : + heatLaw μ a t=(μ.prod (gaussianReal 0 1)).map (fun p : ℝ × ℝ => p.1+sqrt (t-a)*p.2) := by + have hg : (gaussianReal 0 1).map (fun z : ℝ => sqrt (t-a)*z)=gaussianReal 0 (toNNReal (t-a)) := by + rw [gaussianReal_map_const_mul] + congr 1 + · simp + · ext + simp [sq_sqrt (sub_nonneg.mpr ht),ht] + rw [heatLaw,Measure.conv,←hg] + have hm := Measure.map_prod_map μ (gaussianReal 0 1) measurable_id (show Measurable (fun z : ℝ => sqrt (t-a)*z) from by fun_prop) + rw [Measure.map_id] at hm + rw [hm,Measure.map_map (by fun_prop) (by fun_prop)] + rfl + +lemma heatObservation_eq_integral {μ : Measure ℝ} [IsFiniteMeasure μ] {a t : ℝ} + (ht : a≤t) {f : ℝ → ℝ} (hf : Continuous f) : + heatObservation μ a f t=∫ x,f x ∂heatLaw μ a t := by + rw [heatLaw_eq_map ht,integral_map (by fun_prop) hf.aestronglyMeasurable] + rfl + +lemma ExpGrowth.integrable_heatLaw {μ : Measure ℝ} [IsFiniteMeasure μ] {a t M : ℝ} + (ht : a≤t) (hM : 0≤M) {f : ℝ → ℝ} (hf : ExpGrowth M f) (hc : Continuous f) + (hi : Integrable (fun x => exp (M*|x|)) μ) : Integrable f (heatLaw μ a t) := by + obtain ⟨C,hC,hf⟩ := hf + rw [heatLaw_eq_map ht,integrable_map_measure hc.aestronglyMeasurable (by fun_prop)] + exact integrable_scale_prod hc hM hC hf hi _ + +lemma ExpGrowth.integrable_heatObservation {μ : Measure ℝ} [IsFiniteMeasure μ] {a t M : ℝ} + (hM : 0≤M) {f : ℝ → ℝ} (hf : ExpGrowth M f) (hc : Continuous f) + (hi : Integrable (fun x => exp (M*|x|)) μ) : + Integrable (fun p : ℝ × ℝ => f (p.1+sqrt (t-a)*p.2)) (μ.prod (gaussianReal 0 1)) := by + obtain ⟨C,hC,hf⟩ := hf + exact integrable_scale_prod hc hM hC hf hi _ + +lemma heatObservation_add {μ : Measure ℝ} [IsFiniteMeasure μ] {a t M : ℝ} + (hM : 0≤M) {f g : ℝ → ℝ} (hf : ExpGrowth M f) (hg : ExpGrowth M g) + (hc : Continuous f) (hd : Continuous g) (hi : Integrable (fun x => exp (M*|x|)) μ) : + heatObservation μ a (fun x => f x+g x) t=heatObservation μ a f t+heatObservation μ a g t := + integral_add (hf.integrable_heatObservation hM hc hi) (hg.integrable_heatObservation hM hd hi) +lemma heatObservation_const_mul (μ : Measure ℝ) (a t c : ℝ) (f : ℝ → ℝ) : + heatObservation μ a (fun x => c*f x) t=c*heatObservation μ a f t := integral_const_mul _ _ + +lemma hasDerivAt_heatObservation_growth {μ : Measure ℝ} [IsFiniteMeasure μ] {f f' f'' : ℝ → ℝ} + (hc : Continuous f) (hc' : Continuous f') (hc'' : Continuous f'') + (hd : ∀ x,HasDerivAt f (f' x) x) (hd' : ∀ x,HasDerivAt f' (f'' x) x) + {M : ℝ} (hM : 0≤M) (hf : ExpGrowth M f) (hf' : ExpGrowth M f') (hf'' : ExpGrowth M f'') + (hi : Integrable (fun x => exp (M*|x|)) μ) {a t : ℝ} (ht : a exp (M*|x|)) μ) (a : ℝ) : Continuous (heatObservation μ a f) := by + obtain ⟨C,hC,hf⟩ := hf + exact continuous_heatObservation hc hM hC hf hi a + +def weightedHeat (μ : Measure ℝ) (a d K α : ℝ) (f : ℝ → ℝ) (t : ℝ) : ℝ := + K*exp (α^2/2*(d-t))*heatObservation μ a f t + +lemma weightedHeat_hasDerivAt {μ : Measure ℝ} [IsFiniteMeasure μ] {f f' g : ℝ → ℝ} + (hc : Continuous f) (hc' : Continuous f') (hgc : Continuous g) {α : ℝ} + (hd : ∀ x,HasDerivAt f (f' x) x) (hd' : ∀ x,HasDerivAt f' (α^2*f x+g x) x) + {M : ℝ} (hM : 0≤M) (hf : ExpGrowth M f) (hf' : ExpGrowth M f') (hg : ExpGrowth M g) + (hi : Integrable (fun x => exp (M*|x|)) μ) {a t : ℝ} (ht : a α^2*f x+g x) t/2) t at hh + rw [heatObservation_add hM (hf.const_mul (α^2)) hg (continuous_const.mul hc) hgc hi, + heatObservation_const_mul] at hh + have he := ((((hasDerivAt_const t d).sub (hasDerivAt_id t)).const_mul (α^2/2)).exp).const_mul K + convert he.mul hh using 1 <;> first | rfl | (simp only [Pi.sub_apply,id_eq,zero_sub,weightedHeat]; ring) + +lemma continuous_weightedHeat {μ : Measure ℝ} [IsFiniteMeasure μ] {f : ℝ → ℝ} + (hc : Continuous f) {M : ℝ} (hM : 0≤M) (hf : ExpGrowth M f) + (hi : Integrable (fun x => exp (M*|x|)) μ) (a d K α : ℝ) : + Continuous (weightedHeat μ a d K α f) := by + exact (show Continuous (fun t => K*exp (α^2/2*(d-t))) from by fun_prop).mul + (continuous_heatObservation_growth hc hM hf hi a) + +lemma weightedHeat_cosh_hasDerivAt {μ : Measure ℝ} [IsFiniteMeasure μ] {α : ℝ} + (hi : Integrable (fun x => exp ((|α|+1)*|x|)) μ) {a t : ℝ} (ht : a cosh (α*x))) 0 t := by + have hd (x : ℝ) : HasDerivAt (fun x => cosh (α*x)) (α*sinh (α*x)) x := by + simpa only [id_eq,mul_one,mul_comm] using ((hasDerivAt_id x).const_mul α).cosh + have hd' (x : ℝ) : HasDerivAt (fun x => α*sinh (α*x)) (α^2*cosh (α*x)+0) x := by + convert (((hasDerivAt_id x).const_mul α).sinh).const_mul α using 1 <;> + first | rfl | (simp only [id_eq,mul_one]; ring) + have hh := weightedHeat_hasDerivAt (by fun_prop) (by fun_prop) continuous_const hd hd' (by positivity) + (cosh_ExpGrowth α) ((sinh_ExpGrowth α).const_mul α) + (ExpGrowth.of_bounded (M := |α|+1) (by positivity) (C := 0) le_rfl (fun x => by simp)) hi ht d K + simpa only [weightedHeat,heatObservation,integral_zero,mul_zero,zero_div] using hh + +lemma weightedHeat_G_hasDerivAt {μ : Measure ℝ} [IsFiniteMeasure μ] {α : ℝ} + (hi : Integrable (fun x => exp ((|α|+1)*|x|)) μ) {a t : ℝ} (ht : a exp ((|α|+1)*|x|)) μ) {a t : ℝ} (ht : a (cosh (α*x))⁻¹^3) t) t := by + have hh := weightedHeat_hasDerivAt (continuous_coshEntropyU α) (continuous_coshEntropyUD α) + (by exact continuous_const.mul (((continuous_cosh.comp (continuous_const.mul continuous_id)).inv₀ (fun x => (cosh_pos _).ne')).pow 3)) (coshEntropyU_hasDerivAt α) (coshEntropyUD_hasDerivAt α) + (by positivity) (coshEntropyU_ExpGrowth α) (coshEntropyUD_ExpGrowth α) + ((sechCube_ExpGrowth α).const_mul (2*α^4)) hi ht d K + convert hh using 1 + simp only [weightedHeat,heatObservation_const_mul] + ring + +def baseEntropy (μ : Measure ℝ) (a d K α t : ℝ) : ℝ := + (log K+α^2/2*(d-t))*weightedHeat μ a d K α (fun x => cosh (α*x)) t+ + weightedHeat μ a d K α (coshEntropy α) t + +def baseEntropyD (μ : Measure ℝ) (a d K α t : ℝ) : ℝ := + -(α^2/2)*weightedHeat μ a d K α (fun x => cosh (α*x)) t+ + weightedHeat μ a d K α (coshEntropyU α) t/2 + +def baseCurvature (μ : Measure ℝ) (a d K α t : ℝ) : ℝ := + α^4/2*weightedHeat μ a d K α (fun x => (cosh (α*x))⁻¹^3) t + +lemma baseEntropy_hasDerivAt {μ : Measure ℝ} [IsFiniteMeasure μ] {α : ℝ} + (hi : Integrable (fun x => exp ((|α|+1)*|x|)) μ) {a t : ℝ} (ht : a + first | rfl | (simp only [mul_zero,zero_sub,add_zero,baseEntropyD]; ring) + +lemma baseEntropyD_hasDerivAt {μ : Measure ℝ} [IsFiniteMeasure μ] {α : ℝ} + (hi : Integrable (fun x => exp ((|α|+1)*|x|)) μ) {a t : ℝ} (ht : a + first | rfl | (simp only [baseCurvature,mul_zero,zero_add]; ring) + +lemma continuous_baseCurvature {μ : Measure ℝ} [IsFiniteMeasure μ] {α : ℝ} + (hi : Integrable (fun x => exp ((|α|+1)*|x|)) μ) (a d K : ℝ) : + Continuous (baseCurvature μ a d K α) := by + exact continuous_const.mul (continuous_weightedHeat (((continuous_cosh.comp (continuous_const.mul continuous_id)).inv₀ (fun x => (cosh_pos _).ne')).pow 3) (by positivity) + (sechCube_ExpGrowth α) hi a d K α) + +lemma baseEntropy_eq_integral {μ : Measure ℝ} [IsFiniteMeasure μ] {α K a t : ℝ} + (hi : Integrable (fun x => exp ((|α|+1)*|x|)) μ) (ht : a≤t) (hK : 0 cosh (α*x)) from by fun_prop), + heatObservation_eq_integral ht (continuous_coshEntropy α)] + ring + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +lemma exp_field_backward (c : BoundedCoefficient β) (hβ : 0<β) + {a d α : ℝ≥0} (hd1 : d≤1) (ha : 0<α) (hc : ∀ u∈Icc a d,c.val u=α) + {K : ℝ} {g : ℝ → ℝ} (hg : PositiveDefinite g) (hgc : Continuous g) + (he : ∀ x,exp ((α:ℝ)*field β c.val d x)=K*cosh ((α:ℝ)*x)-g x) + {t : ℝ≥0} (ht : t∈Ico a d) (x : ℝ) : + exp ((α:ℝ)*field β c.val t x)=backwardC d K α t x-backwardG d g t x := by + rw [field_on_plateau β hβ c.mono c.bound hd1 (fun u hu => hc u ⟨hu.1,hu.2.le⟩) ht x, + ←NNReal.coe_sub ht.2.le,exp_step_heat (field_lipschitz β hβ c.mono c.bound d) (by exact_mod_cast ha.ne')] + have hi : Integrable (fun z => g (x+z)) (gaussianReal 0 (d-t)) := + Integrable.of_bound (hgc.comp (continuous_const.add continuous_id)).aestronglyMeasurable + (g 0) (ae_of_all _ fun z => hg.norm_le _) + have hδ : toNNReal ((d:ℝ)-t)=d-t := by + apply NNReal.eq + simp only [coe_toNNReal _ (sub_nonneg.mpr (show (t:ℝ)≤d from ht.2.le)),NNReal.coe_sub ht.2.le] + dsimp only [heat] + simp_rw [he] + rw [integral_sub ((integrable_cosh_shift (α:ℝ) x (d-t)).const_mul K) hi,integral_const_mul] + have hh := heat_cosh (α:ℝ) x (d-t) + dsimp only [heat] at hh + rw [hh] + simp only [backwardC,backwardG,hδ,NNReal.coe_sub ht.2.le] + congr 1 + rw [show ((d:ℝ)-t)*(α:ℝ)^2/2=(α:ℝ)^2/2*((d:ℝ)-t) by ring] + ring + +lemma plateau_backward_representation (c : BoundedCoefficient β) (hβ : 0<β) + {a d α : ℝ≥0} (had : a K*cosh ((α:ℝ)*x)-exp ((α:ℝ)*field β c.val d x) := by + funext x; calc + g x = K*cosh ((α:ℝ)*x)-(K*cosh ((α:ℝ)*x)-g x) := by ring + _ = _ := congrArg (fun v => K*cosh ((α:ℝ)*x)-v) (he x).symm + rw [heq] + exact (by fun_prop : Continuous (fun x => K*cosh ((α:ℝ)*x))).sub + ((continuous_const.mul (field_lipschitz β hβ c.mono c.bound d).continuous).rexp) + exact ⟨K,g,hK,hg,hgc,hgK,fun t ht x => c.exp_field_backward hβ hd1 ha hc hg hgc he ht x⟩ + +lemma conjugateMeasure_eq_heatLaw (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) {a d α : ℝ≥0} (ha0 : a≠0) (hd1 : d≤1) + (ha : 0<α) (hc : ∀ u∈Icc a d,c.val u=α) {t : ℝ≥0} (ht : t∈Ioc a d) : + c.conjugateMeasure P W hβ ⟨t,t.coe_nonneg,by exact_mod_cast ht.2.trans hd1⟩= + heatLaw (c.conjugateMeasure P W hβ ⟨a,a.coe_nonneg,by exact_mod_cast ht.1.le.trans ht.2|>.trans hd1⟩) a t := by + have hh := c.conjugateMeasure_plateau hβ hW ha0 ht.1 (ht.2.trans hd1) ha + (fun u hu => hc u ⟨hu.1,hu.2.le.trans ht.2⟩) (hc t ⟨ht.1.le,ht.2⟩) + rw [hh,heatLaw] + congr 2 +end ParisiFinite.BoundedCoefficient + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiSpectral +lemma integrable_gaussian_exp_abs (M : ℝ) (v : ℝ≥0) : + Integrable (fun x : ℝ => exp (M*|x|)) (gaussianReal 0 v) := by + apply ((integrable_exp_mul_gaussianReal M).add (integrable_exp_mul_gaussianReal (-M))).mono' (by fun_prop) + filter_upwards [] with x + rw [Real.norm_eq_abs,abs_of_pos (exp_pos _)] + rcases le_total 0 x with hx|hx + · rw [abs_of_nonneg hx] + exact le_add_of_nonneg_right (exp_pos _).le + · rw [abs_of_nonpos hx,show M*(-x)=(-M)*x by ring] + exact le_add_of_nonneg_left (exp_pos _).le +end ParisiSpectral +namespace ParisiPath +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} {K M : ℝ≥0} +lemma brownian_solution_exp_abs (hW : IsBrownianReal W P) (b : Drift K M) (t : Time) {A : ℝ} (hA : 0≤A) : + Integrable (fun ω => exp (A*|solution b (brownianPath W ω) t|)) P := by + have hg := ParisiSpectral.integrable_gaussian_exp_abs A ⟨t,t.property.1⟩ + have hw : Integrable (fun ω => exp (A*|W ⟨t,t.property.1⟩ ω|)) P := + by + rw [←(hW.hasLaw_eval ⟨t,t.property.1⟩).map_eq] at hg + exact (integrable_map_measure (by fun_prop) (hW.hasLaw_eval _).aemeasurable).mp hg + have hx := (aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) t).aestronglyMeasurable + apply (hw.const_mul (exp (A*((M:ℝ)*(t:ℝ))))).mono' + ((continuous_exp.comp_aestronglyMeasurable (continuous_abs.comp_aestronglyMeasurable hx |>.const_mul A))) + filter_upwards [brownianPath_eq_ae hW] with ω hω + rw [Real.norm_eq_abs,abs_of_pos (exp_pos _),←exp_add] + apply exp_le_exp.mpr + have hb := norm_solution_sub_driver b (brownianPath W ω) t + rw [Real.norm_eq_abs,hω t] at hb + have hh := abs_add_le (solution b (brownianPath W ω) t-W ⟨t,t.property.1⟩ ω) (W ⟨t,t.property.1⟩ ω) + rw [sub_add_cancel] at hh + nlinarith +end ParisiPath +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +lemma conjugateMeasure_exp_abs (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) (ha : 0 exp (A*|x|)) (conjugateMeasure P W c hβ t) := by + have he : Continuous (fun x => exp (-(c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)) := + (continuous_const.mul (field_lipschitz β hβ c.mono c.bound _).continuous).rexp + have hp := (field_coshCone β hβ c.mono c.bound ⟨t,t.property.1⟩ (by exact_mod_cast ha) le_rfl).neg_exp_positiveDefinite + (by exact_mod_cast ha) (c.val ⟨t,t.property.1⟩).coe_nonneg + rw [conjugateMeasure,integrable_withDensity_iff_integrable_smul' he.measurable.ennreal_ofReal + (ae_of_all _ fun x => ENNReal.ofReal_lt_top)] + simp only [ENNReal.toReal_ofReal (exp_pos _).le,smul_eq_mul] + have hi : Integrable (fun x : ℝ => exp (A*|x|)) + (P.map (fun ω => solution (c.driftData hβ) (brownianPath W ω) t)) := + (integrable_map_measure (by fun_prop) + (aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) t)).mpr + (brownian_solution_exp_abs hW _ t hA) + exact hi.bdd_mul he.aestronglyMeasurable (ae_of_all _ hp.norm_le) +end ParisiFinite.BoundedCoefficient + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} +lemma conjugateMeasure_ne_zero (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) : conjugateMeasure P W c hβ t≠0 := by + have : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have he : Continuous (fun x => exp (-(c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)) := + (continuous_const.mul (field_lipschitz β hβ c.mono c.bound _).continuous).rexp + intro hz + have hh := (withDensity_eq_zero_iff he.measurable.ennreal_ofReal.aemeasurable).mp hz + have hf : ∀ᵐ x ∂P.map (fun ω => solution (c.driftData hβ) (brownianPath W ω) t),False := hh.mono fun x hx => + (ENNReal.ofReal_pos.mpr (exp_pos _)).ne' hx + exact (Filter.Eventually.exists hf).elim (fun _ h => h) + + + +lemma conjugateMeasure_entropy (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) : + (∫ x,exp ((c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)* + log (exp ((c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)) + ∂conjugateMeasure P W c hβ t)= + (c.val ⟨t,t.property.1⟩:ℝ)*∫ ω,field β c.val ⟨t,t.property.1⟩ + (solution (c.driftData hβ) (brownianPath W ω) t) ∂P := by + have fc := (field_lipschitz β hβ c.mono c.bound ⟨t,t.property.1⟩).continuous + rw [c.integral_conjugateMeasure hβ hW t (by fun_prop),←integral_const_mul] + apply integral_congr_ae + filter_upwards [] with ω + rw [log_exp,←mul_assoc,←exp_add] + simp only [neg_mul,neg_add_cancel,exp_zero,one_mul] + +lemma field_along_solution_integrable (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) : + Integrable (fun ω => field β c.val ⟨t,t.property.1⟩ + (solution (c.driftData hβ) (brownianPath W ω) t)) P := by + have : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hx := brownian_solution_integrable hW (c.driftData hβ) t + exact (canonicalSpatialTest β hβ c.mono c.bound ⟨t,t.property.1⟩).integrable_comp hx + +lemma conjugateMeasure_entropy_integrable (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) : + Integrable (fun x => exp ((c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)* + log (exp ((c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x))) + (conjugateMeasure P W c hβ t) := by + have fc := (field_lipschitz β hβ c.mono c.bound ⟨t,t.property.1⟩).continuous + have he : Continuous (fun x => exp (-(c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)) := + (continuous_const.mul fc).rexp + rw [conjugateMeasure,integrable_withDensity_iff_integrable_smul' he.measurable.ennreal_ofReal + (ae_of_all _ fun x => ENNReal.ofReal_lt_top)] + simp only [ENNReal.toReal_ofReal (exp_pos _).le,smul_eq_mul,log_exp,←mul_assoc,←exp_add, + neg_mul,neg_add_cancel,exp_zero,one_mul] + rw [integrable_map_measure (by fun_prop) + (aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) t)] + exact (c.field_along_solution_integrable hβ hW t).const_mul _ +end ParisiFinite.BoundedCoefficient + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def fieldEntropy (c : BoundedCoefficient β) (hβ : 0<β) (P : Measure Ω) + (W : ℝ≥0 → Ω → ℝ) (α t : ℝ) : ℝ := + α*(field β c.val 0 0+(∫ u in (0:ℝ)..t,c.real u*expectedProduct P W c c (c.driftData hβ) u)/2) + +lemma fieldEntropy_eq (c : BoundedCoefficient β) (hβ : 0<β) (hW : IsBrownianReal W P) + (t : Time) (ht0 : 0<(t:ℝ)) (ht1 : (t:ℝ)<1) {α : ℝ≥0} + (ha : c.val ⟨t,t.property.1⟩=α) : + c.fieldEntropy hβ P W α t = + ∫ x,exp ((α:ℝ)*field β c.val ⟨t,t.property.1⟩ x)* + log (exp ((α:ℝ)*field β c.val ⟨t,t.property.1⟩ x)) ∂c.conjugateMeasure P W hβ t := by + rw [←ha,c.conjugateMeasure_entropy hβ hW,c.field_value_at hW hβ t ht0 ht1] + rfl + +lemma real_eq_on_plateau (c : BoundedCoefficient β) {a d α : ℝ≥0} + (hc : ∀ u∈Icc a d,c.val u=α) {t : ℝ} (ht : t∈Icc (a:ℝ) d) : c.real t=α := by + have hp : 0≤t := a.coe_nonneg.trans ht.1 + exact congrArg (fun u : ℝ≥0 => (u:ℝ)) (hc (toNNReal t) + ⟨by exact_mod_cast (show (a:ℝ)≤(toNNReal t:ℝ) by simpa only [coe_toNNReal _ hp] using ht.1), + by exact_mod_cast (show (toNNReal t:ℝ)≤d by simpa only [coe_toNNReal _ hp] using ht.2)⟩) + +lemma fieldEntropy_hasDerivAt (c : BoundedCoefficient β) (hβ : 0<β) (hW : IsBrownianReal W P) + {a d α : ℝ≥0} (hc : ∀ u∈Icc a d,c.val u=α) {t : ℝ} (ht : t∈Ioo (a:ℝ) d) : + HasDerivAt (c.fieldEntropy hβ P W α) + ((α:ℝ)^2/2*expectedProduct P W c c (c.driftData hβ) t) t := by + have hp := expectedProduct_continuous hW c c hβ (c.driftData hβ) + have hm : StronglyMeasurable (fun u => c.real u*expectedProduct P W c c (c.driftData hβ) u) := + (c.measurable_real.mul hp.measurable).stronglyMeasurable + have hi := (c.real_intervalIntegrable 0 t).mul_continuousOn hp.continuousOn + have he : (fun u => c.real u*expectedProduct P W c c (c.driftData hβ) u)=ᶠ[𝓝 t] + (fun u => (α:ℝ)*expectedProduct P W c c (c.driftData hβ) u) := by + filter_upwards [Ioo_mem_nhds ht.1 ht.2] with u hu + rw [c.real_eq_on_plateau hc ⟨hu.1.le,hu.2.le⟩] + have hcont := ((continuous_const.mul hp).continuousAt).congr he.symm + have hh := ((intervalIntegral.integral_hasDerivAt_right hi hm.stronglyMeasurableAtFilter hcont).div_const 2).const_add (field β c.val 0 0) + have hd := hh.const_mul (α:ℝ) + rw [c.real_eq_on_plateau hc ⟨ht.1.le,ht.2.le⟩] at hd + convert hd using 1 <;> first | rfl | ring + +lemma fieldEntropyD_hasDerivAt (c : BoundedCoefficient β) (hβ : 0<β) (hW : IsBrownianReal W P) + (α : ℝ) {t : ℝ} (ht : t∈Ioo (0:ℝ) 1) : + HasDerivAt (fun u => α^2/2*expectedProduct P W c c (c.driftData hβ) u) + (α^2/2*c.expectedSquareCurvature P W hβ t) t := + (hasDerivAt_expectedProduct_self hW hβ c t ht).const_mul _ +end ParisiFinite.BoundedCoefficient + + + + + +open MeasureTheory ProbabilityTheory Set Real Filter Matrix +open scoped Topology NNReal ContDiff +namespace ParisiSpectral +lemma contDiffOn_two_of_derivatives {f f' f'' : ℝ → ℝ} {s : Set ℝ} (hs : IsOpen s) + (hd : ∀ x∈s,HasDerivAt f (f' x) x) (hd' : ∀ x∈s,HasDerivAt f' (f'' x) x) + (hc : ContinuousOn f'' s) : ContDiffOn ℝ 2 f s := by + have he : EqOn (deriv f) f' s := fun x hx => (hd x hx).deriv + have he' : EqOn (deriv f') f'' s := fun x hx => (hd' x hx).deriv + have hg : ContDiffOn ℝ 1 f' s := by + rw [show (1 : ℕ∞ω)=0+1 by rfl,contDiffOn_succ_iff_deriv_of_isOpen hs] + refine ⟨fun x hx => (hd' x hx).differentiableAt.differentiableWithinAt,by simp,?_⟩ + exact (contDiffOn_zero.mpr hc).congr he' + rw [show (2 : ℕ∞ω)=1+1 by rfl,contDiffOn_succ_iff_deriv_of_isOpen hs] + exact ⟨fun x hx => (hd x hx).differentiableAt.differentiableWithinAt,by simp,hg.congr he⟩ + +lemma iteratedDeriv_two_of_derivatives {f f' f'' : ℝ → ℝ} {s : Set ℝ} (hs : IsOpen s) + (hd : ∀ x∈s,HasDerivAt f (f' x) x) (hd' : ∀ x∈s,HasDerivAt f' (f'' x) x) + {x : ℝ} (hx : x∈s) : iteratedDeriv 2 f x=f'' x := by + have he : deriv f =ᶠ[𝓝 x] f' := Filter.mem_of_superset (hs.mem_nhds hx) fun y hy => (hd y hy).deriv + rw [show 2=1+1 by rfl,iteratedDeriv_succ,iteratedDeriv_one] + rw [he.deriv_eq] + exact (hd' x hx).deriv + +lemma HankelPD.congr_on {f g : ℝ → ℝ} {s : Set ℝ} (hf : HankelPD f s) + (hs : Convex ℝ s) (he : EqOn f g s) : HankelPD g s := by + have hm (x y : s) : ((x:ℝ)+y)/2∈s := by + simpa only [midpoint_eq_smul_add,smul_eq_mul,invOf_eq_inv,div_eq_mul_inv,mul_comm] + using hs.midpoint_mem x.property y.property + have heq : Matrix.of (fun x y : s => f ((x+y)/2))=Matrix.of (fun x y : s => g ((x+y)/2)) := by + ext x y + exact he (hm x y) + change (Matrix.of (fun x y : s => g ((x+y)/2))).PosSemidef + rw [←heq] + exact hf + +lemma HankelCPD.congr_on {f g : ℝ → ℝ} {s : Set ℝ} (hf : HankelCPD f s) + (hs : Convex ℝ s) (he : EqOn f g s) : HankelCPD g s := by + intro z + have hm (x y : s) : ((x:ℝ)+y)/2∈s := by + simpa only [midpoint_eq_smul_add,smul_eq_mul,invOf_eq_inv,div_eq_mul_inv,mul_comm] + using hs.midpoint_mem x.property y.property + have heq : Matrix.of (fun x y : s => f ((x+y)/2)-f ((x+z)/2)-f ((z+y)/2)+f z)= + Matrix.of (fun x y : s => g ((x+y)/2)-g ((x+z)/2)-g ((z+y)/2)+g z) := by + ext x y + simp only [Matrix.of_apply,he (hm x y),he (hm x z),he (hm z y),he z.property] + change (Matrix.of (fun x y : s => g ((x+y)/2)-g ((x+z)/2)-g ((z+y)/2)+g z)).PosSemidef + rw [←heq] + exact hf z + +lemma HankelCPD.sub_const {f : ℝ → ℝ} {s : Set ℝ} (hf : HankelCPD f s) (C : ℝ) : + HankelCPD (fun x => f x-C) s := by + intro z + have he : Matrix.of (fun x y : s => (f ((x+y)/2)-C)-(f ((x+z)/2)-C)-(f ((z+y)/2)-C)+(f z-C))= + Matrix.of (fun x y : s => f ((x+y)/2)-f ((x+z)/2)-f ((z+y)/2)+f z) := by + ext x y + simp only [Matrix.of_apply] + ring + change (Matrix.of (fun x y : s => (f ((x+y)/2)-C)-(f ((x+z)/2)-C)-(f ((z+y)/2)-C)+(f z-C))).PosSemidef + rw [he] + exact hf z + +lemma HankelCPD.has_second_derivative {f f' f'' : ℝ → ℝ} {s : Set ℝ} + (hf : HankelCPD f s) (hs : Convex ℝ s) (ho : IsOpen s) (hne : s.Nonempty) + (hd : ∀ x∈s,HasDerivAt f (f' x) x) (hd' : ∀ x∈s,HasDerivAt f' (f'' x) x) + (hc : ContinuousOn f'' s) : HankelPD f'' s := by + exact (hf.secondDeriv hs ho hne (contDiffOn_two_of_derivatives ho hd hd' hc)).congr_on hs + (fun x hx => iteratedDeriv_two_of_derivatives ho hd hd' hx) +end ParisiSpectral + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ParisiEntropyDecomposition.lean b/lean/OAI/Probability/ParisiFinite/ParisiEntropyDecomposition.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f9f37750d6f8a8ec4ee20ae8ce2d3d0ac2a891f --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ParisiEntropyDecomposition.lean @@ -0,0 +1,334 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ParisiCoshEntropy + +namespace OAI + +/-! Parisi Entropy Decomposition. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open MeasureTheory ProbabilityTheory Set Real Filter Matrix +open scoped Topology NNReal ContDiff +open MeasureTheory ProbabilityTheory Set Real Filter Matrix +open scoped Topology NNReal +namespace ParisiSpectral + +lemma backwardC_entropy_integrable {μ : Measure ℝ} [IsFiniteMeasure μ] {α K a t : ℝ} + (hi : Integrable (fun x => exp ((|α|+1)*|x|)) μ) (ht : a≤t) (hK : 0 backwardC d K α t x*log (backwardC d K α t x)) (heatLaw μ a t) := by + have hc := (cosh_ExpGrowth α).integrable_heatLaw ht (by positivity) (by fun_prop) hi + have hG := (coshEntropy_ExpGrowth α).integrable_heatLaw ht (by positivity) (continuous_coshEntropy α) hi + have he (x : ℝ) : backwardC d K α t x*log (backwardC d K α t x)= + ((log K+α^2/2*(d-t))*(K*exp (α^2/2*(d-t))))*cosh (α*x)+ + (K*exp (α^2/2*(d-t)))*coshEntropy α x := by + rw [backwardC_log d K α t x hK] + dsimp only [backwardC,coshEntropy] + ring + simp_rw [he] + exact (hc.const_mul _).add (hG.const_mul _) + +lemma backwardG_log_integrable {μ : Measure ℝ} [IsFiniteMeasure μ] + (hi : Integrable (fun x : ℝ => |x|) μ) {g : ℝ → ℝ} (hg : PositiveDefinite g) (hc : Continuous g) + {K : ℝ} (hK : 0 log (backwardC d K α t x)*backwardG d g t x) μ := by + have hlog := backwardC_log_integrable hi hK d α t + have hCc : Continuous (fun x => log (backwardC d K α t x)) := + (show Continuous (backwardC d K α t) from by unfold backwardC; fun_prop).log + (fun x => (backwardC_pos hK _ _ _ _).ne') + have hlog' : Integrable (fun x => log (backwardC d K α t x)) μ := + hlog.mono' hCc.aestronglyMeasurable (ae_of_all _ fun x => by simp only [Real.norm_eq_abs]; exact le_rfl) + exact hlog'.mul_bdd (continuous_heat hc hg.norm_le _).aestronglyMeasurable + (ae_of_all _ (backwardG_bound hg hc d t)) + +lemma hankelCPD_entropy_sub_base {μ : Measure ℝ} [IsFiniteMeasure μ] + (hμ : PositiveOnPD μ) (hi : Integrable (fun x : ℝ => |x|) μ) + {g : ℝ → ℝ} (hg : PositiveDefinite g) (hc : Continuous g) + {a d K α : ℝ} (hK : 0 exp ((|α|+1)*|x|)) μ) {s : Set ℝ} + (hs : ∀ t∈s,a≤t ∧ t≤d) (hsv : Convex ℝ s) + (hEnt : ∀ t∈s,Integrable (fun x => + (backwardC d K α t x-backwardG d g t x)*log (backwardC d K α t x-backwardG d g t x)) (heatLaw μ a t)) : + HankelCPD (fun t => (∫ x, + (backwardC d K α t x-backwardG d g t x)*log (backwardC d K α t x-backwardG d g t x) ∂heatLaw μ a t)- + baseEntropy μ a d K α t) s := by + have hQ := hankelCPD_linearEntropy (α := α) hμ hi hg hc hK hs hsv + have hR := (hankelPD_entropyRemainder (α := α) hμ hg hc hK hgK hs hsv).cpd + apply ((hQ.add hR).sub_const (∫ x,heat (toNNReal (d-a)) g x ∂μ)).congr_on hsv + intro t ht + have hiG : Integrable (backwardG d g t) (heatLaw μ a t) := + Integrable.of_bound (continuous_heat hc hg.norm_le _).aestronglyMeasurable _ + (ae_of_all _ (backwardG_bound hg hc d t)) + have hiC := backwardC_entropy_integrable hExp (hs t ht).1 hK d + have hiL := backwardG_log_integrable (heatLaw_firstMoment hi a t) hg hc hK d α t + have hone : (fun x => (1+log (backwardC d K α t x))*backwardG d g t x)= + (fun x => backwardG d g t x+log (backwardC d K α t x)*backwardG d g t x) := by + funext x; ring + have hneg : (fun x => -log (backwardC d K α t x)*backwardG d g t x)= + (fun x => -(log (backwardC d K α t x)*backwardG d g t x)) := by funext x; ring + have hiO : Integrable (fun x => (1+log (backwardC d K α t x))*backwardG d g t x) (heatLaw μ a t) := by + rw [hone]; exact hiG.add hiL + have hsplit := integral_add ((hEnt t ht).sub hiC) hiO + simp only [Pi.sub_apply] at hsplit + dsimp only + rw [hneg,integral_neg,hsplit, + integral_sub (hEnt t ht) hiC,hone,integral_add hiG hiL, + backwardG_observation_constant hg hc (hs t ht).1 (hs t ht).2, + baseEntropy_eq_integral hExp (hs t ht).1 hK] + ring +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Set Real Filter Matrix +open scoped Topology NNReal +namespace ParisiSpectral + +lemma PositiveOnPD.heat_antitone {μ : Measure ℝ} [IsFiniteMeasure μ] (hμ : PositiveOnPD μ) + {f : ℝ → ℝ} (hf : PositiveDefinite f) (hc : Continuous f) {s t : ℝ≥0} (hst : s≤t) : + (∫ x,heat t f x ∂μ)≤∫ x,heat s f x ∂μ := by + have hh := hμ.heat_le (hf.heat hc s) (continuous_heat hc hf.norm_le s) (t-s) + rw [heat_heat hc hf.norm_le,tsub_add_cancel_of_le hst] at hh + exact hh + +lemma PositiveOnPD.heatObservation_antitone {μ : Measure ℝ} [IsFiniteMeasure μ] + (hμ : PositiveOnPD μ) {f : ℝ → ℝ} (hf : PositiveDefinite f) (hc : Continuous f) + {a x y : ℝ} (hax : a≤x) (hxy : x≤y) : heatObservation μ a f y≤heatObservation μ a f x := by + have hi (t : ℝ) : Integrable f (heatLaw μ a t) := + Integrable.of_bound hc.aestronglyMeasurable _ (ae_of_all _ hf.norm_le) + rw [heatObservation_eq_integral (hax.trans hxy) hc,heatObservation_eq_integral hax hc, + integral_heatLaw (hi y),integral_heatLaw (hi x)] + exact hμ.heat_antitone hf hc (toNNReal_le_toNNReal (by linarith)) + +lemma hankelPD_heatObservation {μ : Measure ℝ} [IsFiniteMeasure μ] + (hμ : PositiveOnPD μ) {f : ℝ → ℝ} (hf : PositiveDefinite f) (hc : Continuous f) + {a : ℝ} {s : Set ℝ} (hs : ∀ t∈s,a≤t) (hsv : Convex ℝ s) : + HankelPD (heatObservation μ a f) s := by + have hh := hankelPD_heatLaw hμ hs hsv (F := fun _ => f) (fun _ _ => hc) + (hf.submatrix (fun p : s × ℝ => p.2)) + have hmid (x y : s) : ((x:ℝ)+y)/2∈s := by + simpa only [midpoint_eq_smul_add,smul_eq_mul,invOf_eq_inv,div_eq_mul_inv,mul_comm] + using hsv.midpoint_mem x.property y.property + change (Matrix.of (fun x y : s => heatObservation μ a f ((x+y)/2))).PosSemidef + have he : Matrix.of (fun x y : s => heatObservation μ a f ((x+y)/2))= + Matrix.of (fun x y : s => ∫ z,f z ∂heatLaw μ a ((x+y)/2)) := by + ext x y + simp only [Matrix.of_apply,heatObservation_eq_integral (hs _ (hmid x y)) hc] + rw [he] + exact hh + +lemma heatObservation_pos {μ : Measure ℝ} [IsFiniteMeasure μ] [NeZero μ] {f : ℝ → ℝ} + (hc : Continuous f) (hp : ∀ x,0 f (p.1+sqrt (t-a)*p.2)) (μ.prod (gaussianReal 0 1)) := + Integrable.of_bound (by fun_prop) C (ae_of_all _ fun p => hb _) + rw [heatObservation,integral_pos_iff_support_of_nonneg (fun p => (hp _).le) hi] + have hs : Function.support (fun p : ℝ × ℝ => f (p.1+sqrt (t-a)*p.2))=univ := by + ext p + simp [Function.mem_support,(hp _).ne'] + rw [hs] + rw [←univ_prod_univ,Measure.prod_prod,show (gaussianReal 0 1) univ=1 from measure_univ,mul_one] + exact Measure.measure_univ_pos.mpr (NeZero.ne μ) + +lemma sechCube_PD (α : ℝ) : PositiveDefinite (fun x => (cosh (α*x))⁻¹^3) := by + have hh := cosh_neg_rpow_positiveDefinite (show (0:ℝ)<3 by norm_num) α + have he (x : ℝ) : cosh (α*x)^(-(3:ℝ))=(cosh (α*x))⁻¹^3 := by + rw [rpow_neg (cosh_pos _).le,show (3:ℝ)=(3:ℕ) by norm_num,rpow_natCast,inv_pow] + simpa only [he] using hh +lemma continuous_sechCube (α : ℝ) : Continuous (fun x => (cosh (α*x))⁻¹^3) := + ((continuous_cosh.comp (continuous_const.mul continuous_id)).inv₀ (fun _ => (cosh_pos _).ne')).pow 3 + +lemma hankelPD_baseCurvature {μ : Measure ℝ} [IsFiniteMeasure μ] + (hμ : PositiveOnPD μ) {a d K α : ℝ} (hK : 0≤K) {s : Set ℝ} + (hs : ∀ t∈s,a≤t) (hsv : Convex ℝ s) : + HankelPD (baseCurvature μ a d K α) s := by + have hh := hankelPD_heatObservation hμ (sechCube_PD α) (continuous_sechCube α) hs hsv + have hw := (posSemidef_weight hh (fun t : s => exp (α^2/4*(d-t)))).smul + (show 0≤α^4/2*K by positivity) + have he : Matrix.of (fun x y : s => baseCurvature μ a d K α ((x+y)/2))= + (α^4/2*K) • Matrix.of (fun x y : s => exp (α^2/4*(d-x))*exp (α^2/4*(d-y))* + heatObservation μ a (fun z => (cosh (α*z))⁻¹^3) ((x+y)/2)) := by + ext x y + simp only [Matrix.of_apply,Matrix.smul_apply,smul_eq_mul,baseCurvature,weightedHeat,←exp_add] + rw [show α^2/4*(d-(x:ℝ))+α^2/4*(d-(y:ℝ))=α^2/2*(d-((x:ℝ)+y)/2) by ring] + ring + change (Matrix.of (fun x y : s => baseCurvature μ a d K α ((x+y)/2))).PosSemidef + rw [he] + exact hw + +lemma baseCurvature_strictAnti {μ : Measure ℝ} [IsFiniteMeasure μ] [NeZero μ] + (hμ : PositiveOnPD μ) {a d K α : ℝ} (hK : 0 by positivity : ∀ z,0<(cosh (α*z))⁻¹^3) (sechCube_PD α).norm_le a x + have hle := hμ.heatObservation_antitone (sechCube_PD α) (continuous_sechCube α) hax hxy.le + have hn := heatObservation_pos (μ := μ) (continuous_sechCube α) + (fun z => by positivity : ∀ z,0<(cosh (α*z))⁻¹^3) (sechCube_PD α).norm_le a y + have he : exp (α^2/2*(d-y)) ht) (convex_Ici a)).midpoint_lt + hax (hax.trans hxy.le) (baseCurvature_strictAnti hμ hK hα hax hxy).ne' +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + + + +lemma expectedSquareCurvature_strict_midpoint (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) {a d α : ℝ≥0} (ha0 : 0 |z|) μ := c.conjugateMeasure_firstMoment hβ hW A hca0 + have hExp : Integrable (fun z => exp ((|(α:ℝ)|+1)*|z|)) μ := + c.conjugateMeasure_exp_abs hβ hW A hca0 (by positivity) + obtain ⟨K,g,hK,hg,hgc,hgK,he⟩ := c.plateau_backward_representation hβ had hd1.le hα hc + have hActual (t : ℝ) (ht : t∈Ioo (a:ℝ) d) : + Integrable (fun z => (backwardC d K α t z-backwardG d g t z)* + log (backwardC d K α t z-backwardG d g t z)) (heatLaw μ a t) ∧ + c.fieldEntropy hβ P W α t=(∫ z,(backwardC d K α t z-backwardG d g t z)* + log (backwardC d K α t z-backwardG d g t z) ∂heatLaw μ a t) := by + have ht0 : 0 c.fieldEntropy hβ P W α t-baseEntropy μ a d K α t) (Ioo (a:ℝ) d) := by + have hh := hankelCPD_entropy_sub_base hμ hi hg hgc hK hgK hExp + (fun t (ht : t∈Ioo (a:ℝ) d) => ⟨ht.1.le,ht.2.le⟩) (convex_Ioo (a:ℝ) d) + (fun t ht => (hActual t ht).1) + exact hh.congr_on (convex_Ioo (a:ℝ) d) (fun t ht => by dsimp only; rw [(hActual t ht).2]) + have hD : HankelPD (fun t => (α:ℝ)^2/2*c.expectedSquareCurvature P W hβ t-baseCurvature μ a d K α t) + (Ioo (a:ℝ) d) := by + apply hS.has_second_derivative (convex_Ioo (a:ℝ) d) isOpen_Ioo + (nonempty_Ioo.mpr (by exact_mod_cast had)) + (f' := fun t => (α:ℝ)^2/2*expectedProduct P W c c (c.driftData hβ) t-baseEntropyD μ a d K α t) + · intro t ht + exact (c.fieldEntropy_hasDerivAt hβ hW hc ht).sub (baseEntropy_hasDerivAt hExp ht.1 d K) + · intro t ht + exact (c.fieldEntropyD_hasDerivAt hβ hW α + ⟨lt_of_le_of_lt a.coe_nonneg ht.1,ht.2.trans (by exact_mod_cast hd1)⟩).sub + (baseEntropyD_hasDerivAt hExp ht.1 d K) + · exact ((continuous_const.mul (c.expectedSquareCurvature_continuous hW hβ)).sub + (continuous_baseCurvature hExp a d K)).continuousOn + have hmid := hD.midpoint_le hx hy + have hbase := baseCurvature_midpoint_lt (α := (α:ℝ)) (d := (d:ℝ)) hμ hK (by exact_mod_cast hα.ne') hx.1.le hxy + have ha : 0<(α:ℝ)^2/2 := by positivity + nlinarith +end ParisiFinite.BoundedCoefficient + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiSpectral +lemma not_isLocalMax_of_strict_midpoint {f : ℝ → ℝ} {a d t : ℝ} + (ht : t∈Ioo a d) + (hf : ∀ x∈Ioo a d,∀ y∈Ioo a d,x + c.expectedSquareCurvature_strict_midpoint hβ hW ha0 had hd1 hα hc hx hy hxy) +end ParisiFinite.BoundedCoefficient +namespace ParisiFinite +open BoundedCoefficient + + +theorem full_support_minimizer {β : ℝ≥0} (hβ : (1:ℝ)<β) + (ρ : ProbabilityMeasure OrderPoint) (hρ : IsMinimizingParisiMeasure β ρ) : + ∃ q : OrderPoint,0<(q:ℝ) ∧ (q:ℝ)<1 ∧ (ρ:Measure OrderPoint).support=Iic q := by + by_contra hne + obtain ⟨hbp,a,b,α,t,ha,hb,hab,hb1,hα,hg,hc,ht,hft,hmax⟩ := + minimizingParisi_positive_plateau_localMax_countercase hβ hρ hne + have ht0 : 0 linarith [ht.1,ht.2] + have hcoef : ∀ u∈Icc A D,(ofMeasure β ρ).val u=α := by + intro u hu + apply hc + · have hu' : ((a:ℝ)+t)/2≤u := hu.1 + linarith [ht.1] + · have hu' : (u:ℝ)≤((b:ℝ)+t)/2 := hu.2 + linarith [ht.2] + exact (ofMeasure β ρ).expectedSquareCurvature_not_isLocalMax hbp + BrownianConstruction.brownianMotion_isBrownian ha0 had hd1 hα hcoef htAD hmax +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ParisiFiniteTransport.lean b/lean/OAI/Probability/ParisiFinite/ParisiFiniteTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..1da57a25a718941aba6983aeacc5954e82a6cd48 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ParisiFiniteTransport.lean @@ -0,0 +1,693 @@ +import Mathlib +import OAI.Probability.ParisiFinite.MeasureCoefficientOnSupportGap + +namespace OAI + +/-! Parisi Finite Transport. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath + + + +def smoothEvolve (f : SmoothField) : Schedule → SmoothField + | [] => f + | (a,d)::ls => (smoothEvolve f ls).transform a (Real.sqrt d) + +lemma smoothEvolve_val (f : SmoothField) (ls : Schedule) : + (smoothEvolve f ls).val = evolve ls f.val := by + induction ls with + | nil => rfl + | cons l ls ih => simp only [smoothEvolve, SmoothField.transform, evolve, ih] + +def scheduleField (f : SmoothField) : Schedule → ℝ → ℝ → SmoothField + | [],_,_ => f + | (a,d)::ls,s,t => if t 0 + | (a,d)::ls,s,t,x => if t rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + by_cases hd : d=0 + · simp only [hd,NNReal.coe_zero,add_zero,scheduleField,lt_self_iff_false,ite_false, + ih,smoothEvolve,Real.sqrt_zero,SmoothField.transform,step_zero_width] + · have hp : (0:ℝ) rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + rw [width_cons] at ht + rw [scheduleField,ite_eq_right (by linarith [schedule_width_nonneg ls] : ¬ t + simp only [width,List.map_nil,List.sum_nil,add_zero] at ht + exact False.elim (not_lt_of_ge hs ht) + | cons l ls ih => + rcases l with ⟨a,d⟩ + simp only [scheduleDerivative,scheduleField,finiteTimeCoefficient] + split_ifs with hcut + · exact ite_eq_left hcut + · apply ih (s+d) (le_of_not_gt hcut) + rw [width_cons] at ht + linarith + + + +structure GeneralScheduleTimeRealization (f : SmoothField) (ls : Schedule) (s : ℝ) where + test : TimeQuadraticTest + val_eq : ∀ t x,test.val t x=(scheduleField f ls s t).val x + d1_eq : ∀ t x,test.d1 t x=(scheduleField f ls s t).d1 x + d2_eq : ∀ t x,test.d2 t x=(scheduleField f ls s t).d2 x + dt_eq : ∀ t x,test.dt t x=scheduleDerivative f ls s t x + + + +def generalScheduleTimeRealization (f : SmoothField) (ls : Schedule) + (s : ℝ) (hs : 0 ≤ s) (he : s + width ls ≤ 1) : GeneralScheduleTimeRealization f ls s := by + induction ls generalizing s with + | nil => + exact ⟨(f).staticTimeTest,fun _ _ => rfl, + fun _ _ => rfl,fun _ _ => rfl,fun _ _ => rfl⟩ + | cons l ls ih => + rcases l with ⟨a,d⟩ + let c : ℝ := s+d + have hc0 : 0≤c := add_nonneg hs d.coe_nonneg + have hend : c+width ls≤1 := by + dsimp only [c] + rw [width_cons] at he + linarith + have hc1 : c≤1 := by linarith [schedule_width_nonneg ls] + let tail := ih c hc0 hend + let slab := (smoothEvolve f ls).slabTimeTest a c + have hmatch (x : ℝ) : slab.val c x=tail.test.val c x := by + change (fieldOnInterval (smoothEvolve f ls) a c c).val x=tail.test.val c x + rw [fieldOnInterval_right,tail.val_eq,scheduleField_start,smoothEvolve_val] + refine ⟨slab.glue tail.test c ⟨hc0,hc1⟩ hmatch,?_,?_,?_,?_⟩ + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,scheduleField, + SmoothField.slabTimeTest,slab,c] + split_ifs + · rfl + · exact tail.val_eq t x + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,scheduleField, + SmoothField.slabTimeTest,slab,c] + split_ifs + · rfl + · exact tail.d1_eq t x + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,scheduleField, + SmoothField.slabTimeTest,slab,c] + split_ifs + · rfl + · exact tail.d2_eq t x + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,scheduleDerivative, + SmoothField.slabTimeTest,slab,c] + split_ifs + · rfl + · exact tail.dt_eq t x + +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma generalSchedule_verification (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (f : SmoothField) (ls : Schedule) (c : ℝ≥0) (hc0 : c≠0) (hc1 : c≤1) + (hw : width ls=c) : + (∫ ω,f.val (solution b (brownianPath W ω) + ⟨c,by exact ⟨c.coe_nonneg,by exact_mod_cast hc1⟩⟩) ∂P)-(smoothEvolve f ls).val 0 = + ∫ t in (0:ℝ)..(c:ℝ),∫ ω, + (scheduleField f ls 0 t).d1 (extend (solution b (brownianPath W ω)) t)* + b.val t (extend (solution b (brownianPath W ω)) t)- + finiteTimeCoefficient ls 0 t/2* + ((scheduleField f ls 0 t).d1 (extend (solution b (brownianPath W ω)) t))^2 ∂P := by + let r := generalScheduleTimeRealization f ls 0 le_rfl (by rw [hw,zero_add];exact_mod_cast hc1) + have hh := brownian_solution_time_generator_at hW b r.test c hc0 hc1 hc + have hsub : uIcc (0:ℝ) c⊆uIcc (0:ℝ) 1 := by + rw [uIcc_of_le c.coe_nonneg,uIcc_of_le zero_le_one] + exact Icc_subset_Icc le_rfl (by exact_mod_cast hc1) + have hj := (timeGeneratorC2_intervalIntegrable hW b r.test hc).mono_set hsub + have ht := (timeDerivativeC2_intervalIntegrable hW b r.test hc).mono_set hsub + have h1 (x : ℝ) : r.test.val c x=f.val x := by + rw [r.val_eq,scheduleField_after f ls 0 c x (by rw [hw,zero_add])] + have h0 : r.test.val 0 0=(smoothEvolve f ls).val 0 := by rw [r.val_eq,scheduleField_start] + simp_rw [h1,h0] at hh + rw [hh,←intervalIntegral.integral_add hj ht] + apply intervalIntegral.integral_congr_Ioo_of_le c.coe_nonneg + intro t ht + change (∫ ω,generatorC2 (r.test.slice t) b t (extend (solution b (brownianPath W ω)) t) ∂P)+ + (∫ ω,r.test.dt t (extend (solution b (brownianPath W ω)) t) ∂P)=_ + rw [←integral_add (generatorC2_integrable hW b _ t) (timeDerivativeC2_integrable_inner hW b r.test t)] + apply integral_congr_ae + filter_upwards [] with ω + simp only [generatorC2,TimeQuadraticTest.slice,r.d1_eq,r.d2_eq,r.dt_eq] + rw [scheduleField_PDE f ls 0 t _ ht.1.le (by simpa only [hw,zero_add] using ht.2)] + ring + +lemma finiteTimeCoefficient_nonneg (ls : Schedule) (s t : ℝ) : + 0≤finiteTimeCoefficient ls s t := by + induction ls generalizing s with + | nil => exact le_rfl + | cons l ls ih => simp only [finiteTimeCoefficient];split_ifs;exact l.1.coe_nonneg;exact ih _ + + + +lemma generalSchedule_terminal_comparison (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (f g : SmoothField) (ls : Schedule) (c : ℝ≥0) (hc0 : c≠0) (hc1 : c≤1) + (hw : width ls=c) + (hb : ∀ t∈Ioo (0:ℝ) c,∀ x,b.val t x=finiteTimeCoefficient ls 0 t*(scheduleField f ls 0 t).d1 x) : + (∫ ω,g.val (solution b (brownianPath W ω) + ⟨c,by exact ⟨c.coe_nonneg,by exact_mod_cast hc1⟩⟩) ∂P)- + (∫ ω,f.val (solution b (brownianPath W ω) + ⟨c,by exact ⟨c.coe_nonneg,by exact_mod_cast hc1⟩⟩) ∂P) ≤ + (smoothEvolve g ls).val 0-(smoothEvolve f ls).val 0 := by + let rf := generalScheduleTimeRealization f ls 0 le_rfl (by rw [hw,zero_add];exact_mod_cast hc1) + let rg := generalScheduleTimeRealization g ls 0 le_rfl (by rw [hw,zero_add];exact_mod_cast hc1) + have hf := brownian_solution_time_generator_at hW b rf.test c hc0 hc1 hc + have hg := brownian_solution_time_generator_at hW b rg.test c hc0 hc1 hc + have hsub : uIcc (0:ℝ) c⊆uIcc (0:ℝ) 1 := by + rw [uIcc_of_le c.coe_nonneg,uIcc_of_le zero_le_one] + exact Icc_subset_Icc le_rfl (by exact_mod_cast hc1) + have hif := (timeGeneratorC2_intervalIntegrable hW b rf.test hc).add + (timeDerivativeC2_intervalIntegrable hW b rf.test hc) + have hig := (timeGeneratorC2_intervalIntegrable hW b rg.test hc).add + (timeDerivativeC2_intervalIntegrable hW b rg.test hc) + have hle : (∫ t in (0:ℝ)..(c:ℝ),timeGeneratorC2 P W b rg.test t+timeDerivativeC2 P W b rg.test t) ≤ + ∫ t in (0:ℝ)..(c:ℝ),timeGeneratorC2 P W b rf.test t+timeDerivativeC2 P W b rf.test t := by + apply intervalIntegral.integral_mono_ae_restrict c.coe_nonneg (hig.mono_set hsub) (hif.mono_set hsub) + filter_upwards [ae_restrict_mem measurableSet_Icc, + ae_restrict_of_ae (show ∀ᵐ t ∂volume,t≠(0:ℝ) by simp [ae_iff,measure_singleton]), + ae_restrict_of_ae (show ∀ᵐ t ∂volume,t≠(c:ℝ) by simp [ae_iff,measure_singleton])] with t ht hn0 hne + have htt : t∈Ioo (0:ℝ) c := ⟨ht.1.lt_of_ne (Ne.symm hn0),ht.2.lt_of_ne hne⟩ + change (∫ ω,generatorC2 (rg.test.slice t) b t (extend (solution b (brownianPath W ω)) t) ∂P)+ + (∫ ω,rg.test.dt t (extend (solution b (brownianPath W ω)) t) ∂P) ≤ + (∫ ω,generatorC2 (rf.test.slice t) b t (extend (solution b (brownianPath W ω)) t) ∂P)+ + (∫ ω,rf.test.dt t (extend (solution b (brownianPath W ω)) t) ∂P) + rw [←integral_add (generatorC2_integrable hW b _ t) (timeDerivativeC2_integrable_inner hW b rg.test t), + ←integral_add (generatorC2_integrable hW b _ t) (timeDerivativeC2_integrable_inner hW b rf.test t)] + apply integral_mono ((generatorC2_integrable hW b _ t).add (timeDerivativeC2_integrable_inner hW b rg.test t)) + ((generatorC2_integrable hW b _ t).add (timeDerivativeC2_integrable_inner hW b rf.test t)) + intro ω + simp only [Pi.add_apply, generatorC2,TimeQuadraticTest.slice,rg.d1_eq,rg.d2_eq,rg.dt_eq,rf.d1_eq,rf.d2_eq,rf.dt_eq] + rw [scheduleField_PDE g ls 0 t _ ht.1 (by simpa only [hw,zero_add] using htt.2), + scheduleField_PDE f ls 0 t _ ht.1 (by simpa only [hw,zero_add] using htt.2),hb t htt] + have hsquare := mul_nonneg (finiteTimeCoefficient_nonneg ls 0 t) + (sq_nonneg ((scheduleField g ls 0 t).d1 (extend (solution b (brownianPath W ω)) t) - + (scheduleField f ls 0 t).d1 (extend (solution b (brownianPath W ω)) t))) + nlinarith [hsquare] + + rw [intervalIntegral.integral_add ((timeGeneratorC2_intervalIntegrable hW b rg.test hc).mono_set hsub) + ((timeDerivativeC2_intervalIntegrable hW b rg.test hc).mono_set hsub), + intervalIntegral.integral_add ((timeGeneratorC2_intervalIntegrable hW b rf.test hc).mono_set hsub) + ((timeDerivativeC2_intervalIntegrable hW b rf.test hc).mono_set hsub),←hg,←hf] at hle + have he (r : GeneralScheduleTimeRealization f ls 0) (x : ℝ) : r.test.val c x=f.val x := by + rw [r.val_eq,scheduleField_after f ls 0 c x (by rw [hw,zero_add])] + have heg (x : ℝ) : rg.test.val c x=g.val x := by + rw [rg.val_eq,scheduleField_after g ls 0 c x (by rw [hw,zero_add])] + simp_rw [he rf,heg,rf.val_eq,rg.val_eq,scheduleField_start] at hle + linarith + + + +lemma generalSchedule_actual_transport (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (f g : SmoothField) (R : ℝ≥0) (hR : ∀ x, |g.val x|≤R) + (ls : Schedule) (c : ℝ≥0) (hc0 : c≠0) (hc1 : c≤1) + (hw : width ls=c) + (hb : ∀ t∈Ioo (0:ℝ) c,∀ x,b.val t x=finiteTimeCoefficient ls 0 t*(scheduleField f ls 0 t).d1 x) : + (∫ ω,g.val (solution b (brownianPath W ω) + ⟨c,by exact ⟨c.coe_nonneg,by exact_mod_cast hc1⟩⟩) ∂P) = + linearEvolve f.val g.val ls 0 := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let X : Ω → ℝ := fun ω => solution b (brownianPath W ω) + ⟨c,by exact ⟨c.coe_nonneg,by exact_mod_cast hc1⟩⟩ + let J : ℝ := ∫ ω,g.val (X ω) ∂P + let V : ℝ → ℝ := fun u => evolve ls (terminalPerturbation f g u).val 0- + evolve ls f.val 0-Real.sin u*J + have hX : Integrable X P := brownian_solution_integrable hW b _ + have hif : Integrable (fun ω => f.val (X ω)) P := (f.staticTimeTest.slice 0).integrable_comp hX + have hig : Integrable (fun ω => g.val (X ω)) P := (g.staticTimeTest.slice 0).integrable_comp hX + have hle (u : ℝ) : 0≤V u := by + have hh := generalSchedule_terminal_comparison hW b hc f (terminalPerturbation f g u) + ls c hc0 hc1 hw hb + change (∫ ω,f.val (X ω)+Real.sin u*g.val (X ω) ∂P)- + (∫ ω,f.val (X ω) ∂P) ≤ _ at hh + rw [integral_add hif (hig.const_mul _),integral_const_mul] at hh + simp only [smoothEvolve_val] at hh + dsimp only [V,J] + linarith + have he : V 0=0 := by + simp only [V,terminalPerturbation,Real.sin_zero,zero_mul,add_zero,sub_self] + have hm : IsLocalMin V 0 := by + filter_upwards [] with u + rw [he] + exact hle u + have hd : HasDerivAt V (linearEvolve f.val g.val ls 0-J) 0 := by + have hh := ((hasDerivAt_evolve_terminal f g R hR ls 0).sub_const (evolve ls f.val 0)).sub + ((Real.hasDerivAt_sin 0).mul_const J) + convert! hh using 1 + simp only [Real.cos_zero,one_mul] + have hz := hm.hasDerivAt_eq_zero hd + change J=_ + linarith + +end ParisiFinite + + + + + + + +open MeasureTheory Matrix InnerProductSpace Filter +open scoped BigOperators Topology RealInnerProductSpace NNReal + +namespace ParisiSpectral + + + +def PositiveDefinite {E : Type*} [Sub E] (f : E → ℝ) : Prop := + Matrix.PosSemidef (fun x y : E => f (x-y)) + +section Kernel +variable {A : Type*} (K : Matrix A A ℝ) + +def operatorKernel : Matrix A A (ℝ →L[ℝ] ℝ) := + fun x y => K x y • ContinuousLinearMap.id ℝ ℝ + +lemma operatorKernel_posSemidef (hK : K.PosSemidef) : + (operatorKernel K).PosSemidef := by + apply (RKHS.posSemidef_tfae.out 1 3).mpr + refine ⟨?_, ?_⟩ + · apply Matrix.IsHermitian.ext + intro x y + simp only [operatorKernel, star_smul, star_trivial, ContinuousLinearMap.star_eq_adjoint, + ContinuousLinearMap.adjoint_id] + rw [show K y x = K x y from hK.1.apply x y] + · intro f + have hp := hK.2 f + simp only [operatorKernel, _root_.smul_apply, ContinuousLinearMap.id_apply, + smul_eq_mul, RCLike.re_to_real, RCLike.inner_apply, starRingEnd_apply, star_trivial] at * + have he : (f.sum fun x w => f.sum fun y z => z * (K y x * w)) = + (f.sum fun x w => f.sum fun y z => w * K x y * z) := by + apply Finsupp.sum_congr + intro x hx + apply Finsupp.sum_congr + intro y hy + rw [show K y x = K x y from hK.1.apply x y] + ring + rwa [he] + +variable [Fact K.PosSemidef] +local instance : Fact (operatorKernel K).PosSemidef := ⟨operatorKernel_posSemidef K Fact.out⟩ + +abbrev KernelHilbert := RKHS.OfKernel (operatorKernel K) + +def kernelFeature (x : A) : KernelHilbert K := + RKHS.kerFun (KernelHilbert K) x (1 : ℝ) + +lemma inner_kernelFeature (x y : A) : + ⟪kernelFeature K x, kernelFeature K y⟫_ℝ = K x y := by + have he := RKHS.kernel_inner (H := KernelHilbert K) y x (1 : ℝ) 1 + simpa only [kernelFeature, KernelHilbert, RKHS.OfKernel.kernel_ofKernel, + operatorKernel, _root_.smul_apply, ContinuousLinearMap.id_apply, + smul_eq_mul, mul_one, RCLike.inner_apply, starRingEnd_apply, star_trivial, one_mul, + show K y x = K x y from (Fact.out : K.PosSemidef).1.apply x y] using he.symm + +lemma norm_kernelFeature_sq (x : A) : + ‖kernelFeature K x‖^2 = K x x := by + rw [← real_inner_self_eq_norm_sq, inner_kernelFeature] + +lemma norm_kernelFeature_sub_sq (x y : A) : + ‖kernelFeature K x - kernelFeature K y‖^2 = K x x + K y y - 2*K x y := by + rw [norm_sub_sq_real, norm_kernelFeature_sq, norm_kernelFeature_sq, inner_kernelFeature] + ring + +lemma continuous_kernelFeature [TopologicalSpace A] + (hc : Continuous (fun p : A × A => K p.1 p.2)) : + Continuous (kernelFeature K) := by + apply continuous_iff_continuousAt.mpr + intro x + change Filter.Tendsto _ _ _ + rw [Metric.tendsto_nhds] + intro ε hε + have ht : Tendsto (fun y => K y y + K x x - 2*K y x) (𝓝 x) (𝓝 0) := by + have h1 : Continuous (fun y => K y y) := hc.comp (continuous_id.prodMk continuous_id) + have h2 : Continuous (fun y => K y x) := hc.comp (continuous_id.prodMk continuous_const) + have h3 := (h1.add (continuous_const (y := K x x)) |>.sub (h2.const_mul 2)).continuousAt (x := x) + change Tendsto (fun y => K y y + K x x - 2 * K y x) (𝓝 x) + (𝓝 (K x x + K x x - 2 * K x x)) at h3 + rwa [show K x x + K x x - 2 * K x x = 0 by ring] at h3 + filter_upwards [ht.eventually (gt_mem_nhds (sq_pos_of_pos hε))] with y hy + rw [dist_eq_norm] + have hn := norm_kernelFeature_sub_sq K y x + nlinarith [norm_nonneg (kernelFeature K y - kernelFeature K x)] + + +lemma posSemidef_inner {V : Type*} [SeminormedAddCommGroup V] + [InnerProductSpace ℝ V] {B : Type*} (v : B → V) : + Matrix.PosSemidef (fun x y => ⟪v x, v y⟫_ℝ) := by + classical + refine ⟨?_, ?_⟩ + · apply Matrix.IsHermitian.ext + intro x y + simp only [star_trivial, real_inner_comm] + · intro c + have hp : 0 ≤ ⟪∑ x ∈ c.support, c x • v x, ∑ x ∈ c.support, c x • v x⟫_ℝ := real_inner_self_nonneg + simpa only [Finsupp.sum, sum_inner, inner_sum, real_inner_smul_left, + real_inner_smul_right, star_trivial, mul_assoc, mul_left_comm, mul_comm, + real_inner_comm] using hp + +lemma posSemidef_kernel_average {B Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (T : B → Ω → A) + (hi : ∀ x, Integrable (fun z => kernelFeature K (T x z)) μ) : + Matrix.PosSemidef (fun x y => ∫ z, ∫ w, K (T x z) (T y w) ∂μ ∂μ) := by + have he (x y : B) : (∫ z, ∫ w, K (T x z) (T y w) ∂μ ∂μ) = + ⟪∫ z, kernelFeature K (T x z) ∂μ, ∫ w, kernelFeature K (T y w) ∂μ⟫_ℝ := by + simp_rw [← inner_kernelFeature K, integral_inner (hi y)] + simp_rw [real_inner_comm (∫ w, kernelFeature K (T y w) ∂μ)] + rw [integral_inner (hi x), real_inner_comm] + simpa only [he] using posSemidef_inner (fun x => ∫ z, kernelFeature K (T x z) ∂μ) + +end Kernel +namespace PositiveDefinite + +variable {f g : ℝ → ℝ} + +lemma at_zero (hf : PositiveDefinite f) : 0 ≤ f 0 := by + simpa only [sub_self] using hf.diag_nonneg (i := (0 : ℝ)) + +lemma even (hf : PositiveDefinite f) (x : ℝ) : f (-x) = f x := by + simpa only [star_trivial, zero_sub, sub_zero] using hf.1.apply x 0 + +lemma mul (hf : PositiveDefinite f) (hg : PositiveDefinite g) : + PositiveDefinite (fun x => f x * g x) := hf.hadamard hg + +lemma add (hf : PositiveDefinite f) (hg : PositiveDefinite g) : + PositiveDefinite (fun x => f x + g x) := Matrix.PosSemidef.add hf hg + +lemma smul (hf : PositiveDefinite f) {c : ℝ} (hc : 0 ≤ c) : + PositiveDefinite (fun x => c * f x) := Matrix.PosSemidef.smul hf hc + +lemma comp_linear (hf : PositiveDefinite f) (a : ℝ) : + PositiveDefinite (fun x => f (a*x)) := by + have hp := hf.submatrix (fun x => a*x) + change Matrix.PosSemidef (fun i j : ℝ => f (a*i-a*j)) at hp + simpa only [PositiveDefinite, ← mul_sub] using hp + +lemma constant {c : ℝ} (hc : 0 ≤ c) : PositiveDefinite (fun _ : ℝ => c) := by + have hp := posSemidef_inner (fun _ : ℝ => (1 : ℝ)) + have he : (fun x y : ℝ => ⟪(1 : ℝ), 1⟫_ℝ) = (fun _ _ : ℝ => (1 : ℝ)) := by + ext x y + simp only [RCLike.inner_apply, map_one, mul_one] + rw [he] at hp + have hp' := hp.smul hc + change Matrix.PosSemidef (fun x y : ℝ => c * 1) at hp' + simpa only [PositiveDefinite, mul_one] using hp' + +lemma pow (hf : PositiveDefinite f) (n : ℕ) : PositiveDefinite (fun x => (f x)^n) := by + induction n with + | zero => simpa only [pow_zero] using constant zero_le_one + | succ n ih => simpa only [pow_succ] using ih.mul hf + +lemma norm_le (hf : PositiveDefinite f) (x : ℝ) : ‖f x‖ ≤ f 0 := by + let K : Matrix ℝ ℝ ℝ := fun x y => f (x-y) + let : Fact K.PosSemidef := ⟨hf⟩ + have h1 := norm_kernelFeature_sub_sq K x 0 + have h2 := norm_add_sq_real (kernelFeature K x) (kernelFeature K 0) + rw [norm_kernelFeature_sq, norm_kernelFeature_sq, inner_kernelFeature] at h2 + simp only [K, sub_zero, sub_self] at h1 h2 + rw [Real.norm_eq_abs, abs_le] + constructor <;> nlinarith [sq_nonneg ‖kernelFeature K x - kernelFeature K 0‖, + sq_nonneg ‖kernelFeature K x + kernelFeature K 0‖] + +lemma continuous_feature (hf : PositiveDefinite f) (hc : Continuous f) : + letI : Fact (Matrix.PosSemidef (fun x y : ℝ => f (x-y))) := ⟨hf⟩ + Continuous (kernelFeature (fun x y : ℝ => f (x-y))) := by + let : Fact (Matrix.PosSemidef (fun x y : ℝ => f (x-y))) := ⟨hf⟩ + apply continuous_kernelFeature + exact hc.comp (continuous_fst.sub continuous_snd) + +lemma posSemidef_limit {B I : Type*} {l : Filter I} [l.NeBot] + {K : I → Matrix B B ℝ} {L : Matrix B B ℝ} + (hK : ∀ i, (K i).PosSemidef) + (ht : ∀ x y, Tendsto (fun i => K i x y) l (𝓝 (L x y))) : L.PosSemidef := by + classical + refine ⟨Matrix.IsHermitian.ext (fun x y => ?_), fun c => ?_⟩ + · simp only [star_trivial] + apply tendsto_nhds_unique (ht y x) + have he : (fun i => K i y x) = (fun i => K i x y) := by + funext i + exact (hK i).1.apply x y + rw [he] + exact ht x y + · apply le_of_tendsto_of_tendsto tendsto_const_nhds + (tendsto_finsetSum c.support fun x hx => + tendsto_finsetSum c.support fun y hy => + ((ht x y).const_mul (c x)).mul_const (c y)) + exact Filter.Eventually.of_forall (fun i => (hK i).2 c) + +lemma limit {I : Type*} {l : Filter I} [l.NeBot] {g : I → ℝ → ℝ} + (hg : ∀ i, PositiveDefinite (g i)) + (ht : ∀ x, Tendsto (fun i => g i x) l (𝓝 (f x))) : PositiveDefinite f := + posSemidef_limit hg (fun x y => ht (x-y)) + +end PositiveDefinite + +open ProbabilityTheory + + +def heat (t : ℝ≥0) (f : ℝ → ℝ) (x : ℝ) : ℝ := + ∫ z, f (x+z) ∂gaussianReal 0 t + +lemma gaussian_double_difference {f : ℝ → ℝ} (hc : Continuous f) + {C : ℝ} (hC : ∀ x, ‖f x‖ ≤ C) (t : ℝ≥0) (x : ℝ) : + (∫ z, ∫ w, f (x+z-w) ∂gaussianReal 0 t ∂gaussianReal 0 t) = heat (t+t) f x := by + have he (z : ℝ) : (∫ w, f (x+z-w) ∂gaussianReal 0 t) = + (∫ w, f (x+z+w) ∂gaussianReal 0 t) := by + have hh := integral_map (μ := gaussianReal 0 t) (f := fun w => f (x+z+w)) measurable_neg.aemeasurable + ((hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable) + rw [gaussianReal_map_neg, neg_zero] at hh + simpa only [sub_eq_add_neg] using hh.symm + simp_rw [he] + have hi : Integrable (fun z => f (x+z)) (gaussianReal 0 t ∗ gaussianReal 0 t) := by + rw [gaussianReal_conv_gaussianReal] + exact Integrable.of_bound (hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable C + (ae_of_all _ fun z => hC _) + have he' := integral_conv hi + rw [gaussianReal_conv_gaussianReal, zero_add] at he' + simpa only [heat, add_assoc] using he'.symm + +lemma PositiveDefinite.heat {f : ℝ → ℝ} (hf : PositiveDefinite f) + (hc : Continuous f) (t : ℝ≥0) : PositiveDefinite (heat t f) := by + let K : Matrix ℝ ℝ ℝ := fun x y => f (x-y) + let : Fact K.PosSemidef := ⟨hf⟩ + have hcont : Continuous (kernelFeature K) := hf.continuous_feature hc + have hi (x : ℝ) : Integrable (fun z => kernelFeature K (x+z)) (gaussianReal 0 (t/2)) := by + apply Integrable.of_bound (hcont.comp (continuous_const.add continuous_id)).aestronglyMeasurable + (Real.sqrt (f 0)) + filter_upwards [] with z + have hn := norm_kernelFeature_sq K (x+z) + simp only [K, sub_self] at hn + exact (Real.le_sqrt (norm_nonneg _) hf.at_zero).mpr hn.le + have hp := posSemidef_kernel_average K (gaussianReal 0 (t/2)) (fun x z : ℝ => x+z) hi + have he : (fun x y : ℝ => ∫ z, ∫ w, K (x+z) (y+w) ∂gaussianReal 0 (t/2) + ∂gaussianReal 0 (t/2)) = (fun x y : ℝ => ParisiSpectral.heat t f (x-y)) := by + funext x y + have hh := gaussian_double_difference hc hf.norm_le (t/2) (x-y) + rw [add_halves] at hh + rw [← hh] + apply integral_congr_ae + filter_upwards [] with z + apply integral_congr_ae + filter_upwards [] with w + change f ((x+z)-(y+w)) = f (x-y+z-w) + congr 1 + ring + exact (congrArg Matrix.PosSemidef he).mp hp + +end ParisiSpectral + + + +open MeasureTheory Set Real Matrix +open scoped BigOperators + +namespace ParisiSpectral + + + +lemma gamma_laplace {r b : ℝ} (hr : 0 < r) (hb : 0 < b) : + (∫ u in Ioi (0 : ℝ), u ^ (r - 1) * exp (-b * u)) = + b ^ (-r) * Gamma r := by + simpa only [rpow_one, sub_add_cancel, div_one, one_div_one, mul_one] using + (integral_rpow_mul_exp_neg_mul_rpow (p := 1) (q := r - 1) + (b := b) zero_lt_one (by linarith) hb) + +lemma gamma_laplace_integrable {r b : ℝ} (hr : 0 < r) (hb : 0 < b) : + IntegrableOn (fun u : ℝ => u ^ (r - 1) * exp (-b * u)) (Ioi 0) := by + simpa only [rpow_one] using + (integrableOn_rpow_mul_exp_neg_mul_rpow (p := 1) (s := r - 1) + (b := b) (by linarith) zero_lt_one hb) + + +def hyperbolicFeature (r x u : ℝ) : ℝ := exp (r * x - u * exp (2 * x)) + +lemma hyperbolicFeature_mul (r x y u : ℝ) : + hyperbolicFeature r x u * hyperbolicFeature r y u = + exp (r * (x + y)) * exp (-(exp (2*x) + exp (2*y)) * u) := by + simp only [hyperbolicFeature, ← exp_add] + congr 1 + ring + +lemma exp_sum_cosh (x y : ℝ) : + exp (2*x) + exp (2*y) = 2 * exp (x+y) * cosh (x-y) := by + rw [cosh_eq] + have h₁ : exp (x+y) * exp (x-y) = exp (2*x) := by + rw [← exp_add] + congr 1 + ring + have h₂ : exp (x+y) * exp (-(x-y)) = exp (2*y) := by + rw [← exp_add] + congr 1 + ring + nlinarith + +lemma hyperbolic_gram_integral {r : ℝ} (hr : 0 < r) (x y : ℝ) : + (∫ u in Ioi (0 : ℝ), u ^ (r-1) * + (hyperbolicFeature r x u * hyperbolicFeature r y u)) = + (2 : ℝ) ^ (-r) * Gamma r * (cosh (x-y)) ^ (-r) := by + simp_rw [hyperbolicFeature_mul] + have hb : 0 < exp (2*x) + exp (2*y) := add_pos (exp_pos _) (exp_pos _) + calc + _ = exp (r*(x+y)) * + ∫ u in Ioi (0 : ℝ), u ^ (r-1) * exp (-(exp (2*x)+exp (2*y))*u) := by + rw [← integral_const_mul] + congr 1 + funext u + ring + _ = exp (r*(x+y)) * ((exp (2*x)+exp (2*y)) ^ (-r) * Gamma r) := by + rw [gamma_laplace hr hb] + _ = (2 : ℝ) ^ (-r) * Gamma r * (cosh (x-y)) ^ (-r) := by + rw [exp_sum_cosh, mul_rpow (by positivity) (by positivity), + mul_rpow (by positivity) (by positivity), rpow_def_of_pos (exp_pos _), log_exp] + have he : exp (r*(x+y)) * exp ((x+y)*(-r)) = 1 := by + rw [← exp_add] + rw [show r*(x+y) + (x+y)*(-r) = 0 by ring, exp_zero] + calc + _ = (exp (r*(x+y)) * exp ((x+y)*(-r))) * + ((2 : ℝ)^(-r) * Gamma r * (cosh (x-y))^(-r)) := by ring + _ = _ := by rw [he, one_mul] + +lemma hyperbolic_gram_integrable {r : ℝ} (hr : 0 < r) (x y : ℝ) : + IntegrableOn (fun u : ℝ => u ^ (r-1) * + (hyperbolicFeature r x u * hyperbolicFeature r y u)) (Ioi 0) := by + have hi := (gamma_laplace_integrable hr + (add_pos (exp_pos (2*x)) (exp_pos (2*y)))).const_mul (exp (r*(x+y))) + apply hi.congr + filter_upwards [] with u + rw [hyperbolicFeature_mul] + ring + + + +lemma posSemidef_integral_gram {A Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) (v : A → Ω → ℝ) (w : Ω → ℝ) + (hw : ∀ᵐ z ∂μ, 0 ≤ w z) + (hi : ∀ a b, Integrable (fun z => w z * (v a z * v b z)) μ) : + Matrix.PosSemidef (fun a b => ∫ z, w z * (v a z * v b z) ∂μ) := by + classical + refine ⟨?_, ?_⟩ + · apply Matrix.IsHermitian.ext + intro a b + simp only [star_trivial] + apply integral_congr_ae + filter_upwards [] with z + ring + · intro c + simp only [Finsupp.sum, star_trivial] + have hij (a b : A) : Integrable + (fun z => c a * (w z * (v a z * v b z)) * c b) μ := + ((hi a b).const_mul (c a)).mul_const (c b) + have he : (∑ a ∈ c.support, ∑ b ∈ c.support, + c a * (∫ z, w z * (v a z * v b z) ∂μ) * c b) = + ∫ z, w z * (∑ a ∈ c.support, c a * v a z)^2 ∂μ := by + simp_rw [← integral_const_mul, ← integral_mul_const] + simp_rw [← integral_finsetSum _ (fun b hb => hij _ b)] + rw [← integral_finsetSum _ (fun a ha => integrable_finsetSum _ (fun b hb => hij a b))] + congr 1 + funext z + simp_rw [pow_two, Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + ring + rw [he] + apply integral_nonneg_of_ae + filter_upwards [hw] with z hz + exact mul_nonneg hz (sq_nonneg _) + + + +theorem cosh_neg_rpow_posSemidef {r : ℝ} (hr : 0 < r) : + Matrix.PosSemidef (fun x y : ℝ => (cosh (x-y)) ^ (-r)) := by + have hp := posSemidef_integral_gram (volume.restrict (Ioi (0 : ℝ))) + (hyperbolicFeature r) (fun u : ℝ => u ^ (r-1)) + (ae_restrict_of_forall_mem measurableSet_Ioi (fun u hu => rpow_nonneg hu.le _)) + (hyperbolic_gram_integrable hr) + have hc : 0 < (2 : ℝ)^(-r) * Gamma r := + mul_pos (rpow_pos_of_pos (by norm_num) _) (Gamma_pos_of_pos hr) + have hps := hp.smul (inv_nonneg.mpr hc.le) + have he : ((2 ^ (-r) * Gamma r)⁻¹ • + (fun a b : ℝ => ∫ z in Ioi (0 : ℝ), z ^ (r-1) * + (hyperbolicFeature r a z * hyperbolicFeature r b z)) : Matrix ℝ ℝ ℝ) = + (fun x y : ℝ => (cosh (x-y)) ^ (-r)) := by + ext x y + simp only [Pi.smul_apply, smul_eq_mul, hyperbolic_gram_integral hr] + rw [← mul_assoc, inv_mul_cancel₀ (ne_of_gt hc), one_mul] + exact (congrArg Matrix.PosSemidef he).mp hps + +end ParisiSpectral + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ParisiHankelDerivative.lean b/lean/OAI/Probability/ParisiFinite/ParisiHankelDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..161bb3214adf7c29babe2453a74613744601b601 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ParisiHankelDerivative.lean @@ -0,0 +1,680 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ParisiReflection + +namespace OAI + +/-! Parisi Hankel Derivative. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Set Real Matrix Filter InnerProductSpace +open scoped Topology NNReal RealInnerProductSpace BigOperators +namespace ParisiSpectral + +lemma posSemidef_anchor {A : Type*} {K : Matrix A A ℝ} (hK : K.PosSemidef) (z : A) : + Matrix.PosSemidef (fun x y => K x y-K x z-K z y+K z z) := by + let : Fact K.PosSemidef := ⟨hK⟩ + have hh := posSemidef_inner (fun x => kernelFeature K x-kernelFeature K z) + have he (x y : A) : ⟪kernelFeature K x-kernelFeature K z,kernelFeature K y-kernelFeature K z⟫_ℝ= + K x y-K x z-K z y+K z z := by + rw [inner_sub_left,inner_sub_right,inner_sub_right] + simp only [inner_kernelFeature] + ring + simpa only [he] using hh + +def HankelCPD (f : ℝ → ℝ) (s : Set ℝ) : Prop := + ∀ z : s,Matrix.PosSemidef (fun x y : s => f ((x+y)/2)-f ((x+z)/2)-f ((z+y)/2)+f z) + +def HankelPD (f : ℝ → ℝ) (s : Set ℝ) : Prop := + Matrix.PosSemidef (fun x y : s => f ((x+y)/2)) + +lemma HankelPD.cpd {f : ℝ → ℝ} {s : Set ℝ} (hf : HankelPD f s) : HankelCPD f s := by + intro z + convert posSemidef_anchor hf z using 1 + simp only [add_self_div_two] + +lemma scaled_taylorOn_tendsto {f : ℝ → ℝ} {s : Set ℝ} {n : ℕ} + (hs : Convex ℝ s) (hso : IsOpen s) (hf : ContDiffOn ℝ n f s) {x : ℝ} (hx : x∈s) (k : ℝ) : + Tendsto (fun e => (f (x+k*e)-taylorWithinEval f n s x (x+k*e))/e^n) (𝓝 (0:ℝ)) (𝓝 0) := by + have ht := Real.taylor_tendsto hs hx hf + rw [hso.nhdsWithin_eq hx] at ht + have hc : Tendsto (fun e : ℝ => x+k*e) (𝓝 0) (𝓝 x) := by + simpa only [mul_zero,add_zero] using + ((show Continuous (fun e : ℝ => x+k*e) from by fun_prop).tendsto (0:ℝ)) + have hh := (ht.comp hc).const_mul (k^n) + simp only [mul_zero] at hh + apply hh.congr + intro e + dsimp only [Function.comp_def] + rw [add_sub_cancel_left,mul_pow] + by_cases hk : k=0 + · simp [hk,taylorWithinEval_self] + · field_simp + +lemma secondForward_tendsto {f : ℝ → ℝ} {s : Set ℝ} + (hs : Convex ℝ s) (hso : IsOpen s) (hf : ContDiffOn ℝ 2 f s) {x : ℝ} (hx : x∈s) : + Tendsto (fun e => (f (x+e)-2*f (x+e/2)+f x)/e^2) (𝓝[≠] (0:ℝ)) + (𝓝 (iteratedDeriv 2 f x/4)) := by + have h1 := scaled_taylorOn_tendsto hs hso hf hx 1 + have h2 := (scaled_taylorOn_tendsto hs hso hf hx (1/2)).const_mul 2 + have hh := (h1.sub h2).mono_left (nhdsWithin_le_nhds : 𝓝[≠] (0:ℝ)≤𝓝 0) + simp only [sub_zero,mul_zero,one_mul] at hh + have he : (fun e : ℝ => (f (x+e)-taylorWithinEval f 2 s x (x+e))/e^2- + 2*((f (x+(1/2)*e)-taylorWithinEval f 2 s x (x+(1/2)*e))/e^2)) =ᶠ[𝓝[≠] 0] + (fun e => (f (x+e)-2*f (x+e/2)+f x)/e^2-iteratedDeriv 2 f x/4) := by + filter_upwards [self_mem_nhdsWithin] with e he + have hne : e≠0 := he + have hd (n : ℕ) : iteratedDerivWithin n f s x=iteratedDeriv n f x := + iteratedDerivWithin_of_isOpen hso hx + simp only [taylorWithinEval_succ,taylor_within_zero_eval,hd] + norm_num + field_simp + ring + have hl := hh.congr' he + have ha := hl.add_const (iteratedDeriv 2 f x/4) + simpa only [sub_add_cancel,zero_add] using ha + +lemma HankelCPD.secondDeriv {f : ℝ → ℝ} {s : Set ℝ} + (h : HankelCPD f s) (hs : Convex ℝ s) (hso : IsOpen s) + (hne : s.Nonempty) (hf : ContDiffOn ℝ 2 f s) : + HankelPD (iteratedDeriv 2 f) s := by + classical + let z : s := ⟨hne.choose,hne.choose_spec⟩ + let K : Matrix s s ℝ := fun x y => f ((x+y)/2)-f ((x+z)/2)-f ((z+y)/2)+f z + let : Fact K.PosSemidef := ⟨h z⟩ + let T (e : ℝ) (x : s) : s := if hx : (x:ℝ)+e∈s then ⟨x+e,hx⟩ else x + let G (e : ℝ) (x : s) := e⁻¹ • (kernelFeature K (T e x)-kernelFeature K x) + have hlim (x y : s) : Tendsto (fun e => ⟪G e x,G e y⟫_ℝ) (𝓝[≠] (0:ℝ)) + (𝓝 (iteratedDeriv 2 f ((x+y)/2)/4)) := by + have hxy : ((x:ℝ)+y)/2∈s := by + simpa only [midpoint_eq_smul_add,smul_eq_mul,invOf_eq_inv,div_eq_mul_inv,mul_comm] using hs.midpoint_mem x.property y.property + have hh := secondForward_tendsto hs hso hf hxy + apply hh.congr' + have hx : ∀ᶠ e in 𝓝 (0:ℝ),(x:ℝ)+e∈s := by + have hh := (show Continuous (fun e : ℝ => (x:ℝ)+e) from by fun_prop).tendsto (0:ℝ) + simp only [add_zero] at hh + exact hh.eventually (hso.mem_nhds x.property) + have hy : ∀ᶠ e in 𝓝 (0:ℝ),(y:ℝ)+e∈s := by + have hh := (show Continuous (fun e : ℝ => (y:ℝ)+e) from by fun_prop).tendsto (0:ℝ) + simp only [add_zero] at hh + exact hh.eventually (hso.mem_nhds y.property) + filter_upwards [hx.filter_mono nhdsWithin_le_nhds,hy.filter_mono nhdsWithin_le_nhds] + with e heX heY + simp only [G,real_inner_smul_left,real_inner_smul_right,inner_sub_left,inner_sub_right, + inner_kernelFeature] + simp only [T,dite_eq_left heX,dite_eq_left heY,K] + have he1 : ((x:ℝ)+e+(y+e))/2=((x:ℝ)+y)/2+e := by ring + have he2 : ((x:ℝ)+e+y)/2=((x:ℝ)+y)/2+e/2 := by ring + have he3 : ((x:ℝ)+(y+e))/2=((x:ℝ)+y)/2+e/2 := by ring + rw [he1,he2,he3] + ring + have hh := PositiveDefinite.posSemidef_limit (l := 𝓝[≠] (0:ℝ)) + (fun e => posSemidef_inner (G e)) hlim + have hp := hh.smul (show (0:ℝ)≤4 by norm_num) + have heq : Matrix.of (fun x y : s => iteratedDeriv 2 f ((x+y)/2)) = + (4:ℝ) • Matrix.of (fun x y : s => iteratedDeriv 2 f ((x+y)/2)/4) := by + ext x y + simp only [Matrix.smul_apply,Matrix.of_apply,smul_eq_mul] + ring + change (Matrix.of (fun x y : s => iteratedDeriv 2 f ((x+y)/2))).PosSemidef + rw [heq] + exact hp + +lemma HankelCPD.add {f g : ℝ → ℝ} {s : Set ℝ} + (hf : HankelCPD f s) (hg : HankelCPD g s) : HankelCPD (fun x => f x+g x) s := by + intro z + have he : Matrix.of (fun x y : s => + (f ((x+y)/2)+g ((x+y)/2))-(f ((x+z)/2)+g ((x+z)/2))- + (f ((z+y)/2)+g ((z+y)/2))+(f z+g z)) = + Matrix.of (fun x y : s => f ((x+y)/2)-f ((x+z)/2)-f ((z+y)/2)+f z)+ + Matrix.of (fun x y : s => g ((x+y)/2)-g ((x+z)/2)-g ((z+y)/2)+g z) := by + ext x y + simp only [Matrix.add_apply,Matrix.of_apply] + ring + change (Matrix.of (fun x y : s => + (f ((x+y)/2)+g ((x+y)/2))-(f ((x+z)/2)+g ((x+z)/2))- + (f ((z+y)/2)+g ((z+y)/2))+(f z+g z))).PosSemidef + rw [he] + exact (hf z).add (hg z) + +lemma HankelCPD.of_rightQuotient {F : ℝ → ℝ → ℝ} {f : ℝ → ℝ} {s : Set ℝ} {C : ℝ} + (hs : Convex ℝ s) (hF : ∀ r,0 (F r x-C)/r) (𝓝[>] (0:ℝ)) (𝓝 (f x))) : + HankelCPD f s := by + classical + intro z + let K (r : ℝ) : Matrix s s ℝ := if 0 (F r ((x+y)/2)-F r ((x+z)/2)-F r ((z+y)/2)+F r z)/r) else 0 + have hK (r : ℝ) : (K r).PosSemidef := by + dsimp only [K] + split_ifs with hr + · have he : Matrix.of (fun x y : s => (F r ((x+y)/2)-F r ((x+z)/2)-F r ((z+y)/2)+F r z)/r)= + r⁻¹ • Matrix.of (fun x y : s => F r ((x+y)/2)-F r ((x+z)/2)-F r ((z+y)/2)+F r z) := by + ext x y + simp only [Matrix.smul_apply,Matrix.of_apply,smul_eq_mul,div_eq_mul_inv,mul_comm] + rw [he] + exact ((hF r hr).cpd z).smul (inv_nonneg.mpr hr.le) + · exact Matrix.PosSemidef.zero + apply PositiveDefinite.posSemidef_limit (l := 𝓝[>] (0:ℝ)) hK + intro x y + have hm (u v : s) : ((u:ℝ)+v)/2∈s := by + simpa only [midpoint_eq_smul_add,smul_eq_mul,invOf_eq_inv,div_eq_mul_inv,mul_comm] + using hs.midpoint_mem u.property v.property + have hh := (((ht _ (hm x y)).sub (ht _ (hm x z))).sub (ht _ (hm z y))).add (ht z z.property) + apply hh.congr' + filter_upwards [self_mem_nhdsWithin] with r hr + dsimp only [K] + rw [ite_eq_left (show 0 f ((u+v)/2) + let : Fact K.PosSemidef := ⟨hf⟩ + have hh := norm_kernelFeature_sub_sq K ⟨x,hx⟩ ⟨y,hy⟩ + simp only [K,add_self_div_two] at hh + nlinarith [sq_nonneg ‖kernelFeature K ⟨x,hx⟩-kernelFeature K ⟨y,hy⟩‖] + +lemma HankelPD.midpoint_lt {f : ℝ → ℝ} {s : Set ℝ} (hf : HankelPD f s) + {x y : ℝ} (hx : x∈s) (hy : y∈s) (hne : f x≠f y) : 2*f ((x+y)/2) f ((u+v)/2) + let : Fact K.PosSemidef := ⟨hf⟩ + have hh := norm_kernelFeature_sub_sq K ⟨x,hx⟩ ⟨y,hy⟩ + simp only [K,add_self_div_two] at hh + have hn : kernelFeature K ⟨x,hx⟩≠kernelFeature K ⟨y,hy⟩ := by + intro he + apply hne + have hh := congrArg (fun v => ‖v‖^2) he + rw [norm_kernelFeature_sq K,norm_kernelFeature_sq K] at hh + simpa only [K,add_self_div_two] using hh + have hp := sq_pos_of_pos (norm_pos_iff.mpr (sub_ne_zero.mpr hn)) + linarith + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Set Real Matrix Filter InnerProductSpace +open scoped Topology NNReal RealInnerProductSpace BigOperators +namespace ParisiSpectral + +lemma posSemidef_weight {A : Type*} {K : Matrix A A ℝ} (hK : K.PosSemidef) (w : A → ℝ) : + Matrix.PosSemidef (Matrix.of (fun x y => w x*w y*K x y)) := by + let : Fact K.PosSemidef := ⟨hK⟩ + have hh := posSemidef_inner (fun x => w x • kernelFeature K x) + have he : Matrix.of (fun x y => w x*w y*K x y)= + Matrix.of (fun x y => ⟪w x • kernelFeature K x,w y • kernelFeature K y⟫_ℝ) := by + ext x y + simp only [Matrix.of_apply,real_inner_smul_left,real_inner_smul_right,inner_kernelFeature] + ring + rw [he] + exact hh + + + +lemma hankelPD_heat_observation {μ : Measure ℝ} [IsFiniteMeasure μ] (hμ : PositiveOnPD μ) + {F : ℝ → ℝ → ℝ} {a : ℝ} {s : Set ℝ} (hs : ∀ t∈s,a≤t) (hsv : Convex ℝ s) + (hc : ∀ t∈s,Continuous (F t)) + (hK : Matrix.PosSemidef (Matrix.of (fun p q : s × ℝ => F ((p.1+q.1)/2) (p.2-q.2)))) : + HankelPD (fun t => ∫ x,heat (toNNReal (t-a)) (F t) x ∂μ) s := by + let κ : s → s → ℝ → ℝ := fun t u x => F ((t+u)/2) x + have hmid (t u : s) : ((t:ℝ)+u)/2∈s := by + simpa only [midpoint_eq_smul_add,smul_eq_mul,invOf_eq_inv,div_eq_mul_inv,mul_comm] + using hsv.midpoint_mem t.property u.property + have hκc (t u : s) : Continuous (κ t u) := hc _ (hmid t u) + have hp := stationary_kernel_heat κ hK hκc (fun t => toNNReal ((t-a)/2)) + have he (t u : s) : toNNReal (((t:ℝ)-a)/2)+toNNReal (((u:ℝ)-a)/2)= + toNNReal (((t:ℝ)+u)/2-a) := by + apply NNReal.eq + rw [NNReal.coe_add,coe_toNNReal _ (by linarith [hs t t.property]), + coe_toNNReal _ (by linarith [hs u u.property]),coe_toNNReal _ (by linarith [hs t t.property,hs u u.property])] + ring + let κ' : s → s → ℝ → ℝ := fun t u x => heat (toNNReal (((t:ℝ)+u)/2-a)) (κ t u) x + have hc' (t u : s) : Continuous (κ' t u) := + continuous_heat (hκc t u) (stationary_kernel_bounded κ hK t u) _ + have hp' : Matrix.PosSemidef (Matrix.of (fun p q : s × ℝ => κ' p.1 q.1 (p.2-q.2))) := by + change (Matrix.of (fun p q : s × ℝ => heat (toNNReal (((p.1:ℝ)-a)/2)+toNNReal (((q.1:ℝ)-a)/2)) (κ p.1 q.1) (p.2-q.2))).PosSemidef at hp + simpa only [he,κ'] using hp + have hi (t u : s) : Integrable (κ' t u) μ := Integrable.of_bound (hc' t u).aestronglyMeasurable _ + (ae_of_all _ (stationary_kernel_bounded κ' hp' t u)) + exact hμ.kernel_integral κ' hp' hc' hi (fun t u => by dsimp only [κ',κ]; rw [add_comm (t:ℝ) (u:ℝ)]) + +def backwardC (d K α t x : ℝ) : ℝ := K*exp (α^2/2*(d-t))*cosh (α*x) +def backwardG (d : ℝ) (g : ℝ → ℝ) (t x : ℝ) : ℝ := heat (toNNReal (d-t)) g x + +lemma backwardG_reflection {g : ℝ → ℝ} (hg : PositiveDefinite g) (hc : Continuous g) + {d : ℝ} {s : Set ℝ} (hs : ∀ t∈s,t≤d) : + Matrix.PosSemidef (Matrix.of (fun p q : s × ℝ => backwardG d g ((p.1+q.1)/2) (p.2-q.2))) := by + have hh := (hg.heat_reflection hc).submatrix (fun p : s × ℝ => (toNNReal ((d-p.1)/2),p.2)) + have he (p q : s × ℝ) : toNNReal ((d-(p.1:ℝ))/2)+toNNReal ((d-(q.1:ℝ))/2)= + toNNReal (d-((p.1:ℝ)+q.1)/2) := by + apply NNReal.eq + rw [NNReal.coe_add,coe_toNNReal _ (by linarith [hs p.1 p.1.property]), + coe_toNNReal _ (by linarith [hs q.1 q.1.property]), + coe_toNNReal _ (by linarith [hs p.1 p.1.property,hs q.1 q.1.property])] + ring + change (Matrix.of (fun p q : s × ℝ => heat (toNNReal ((d-p.1)/2)+toNNReal ((d-q.1)/2)) g (p.2-q.2))).PosSemidef at hh + simpa only [he,backwardG] using hh + +lemma backwardC_neg_rpow {d K α r : ℝ} (hK : 0 (backwardC d K α ((p.1+q.1)/2) (p.2-q.2))^(-r))) := by + have hp := (cosh_neg_rpow_positiveDefinite hr α).submatrix (fun p : s × ℝ => p.2) + have hw := (posSemidef_weight hp (fun p : s × ℝ => exp (-r*α^2/4*(d-p.1)))).smul + (rpow_nonneg hK.le (-r)) + have he : Matrix.of (fun p q : s × ℝ => (backwardC d K α ((p.1+q.1)/2) (p.2-q.2))^(-r))= + K^(-r) • Matrix.of (fun p q : s × ℝ => exp (-r*α^2/4*(d-p.1))* + exp (-r*α^2/4*(d-q.1))*(cosh (α*(p.2-q.2)))^(-r)) := by + ext p q + simp only [Matrix.smul_apply,Matrix.of_apply,smul_eq_mul,backwardC] + rw [mul_rpow (mul_pos hK (exp_pos _)).le (cosh_pos _).le, + mul_rpow hK.le (exp_pos _).le,←exp_mul,←mul_assoc,←exp_add] + congr 2 + ring_nf + rw [he] + exact hw +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Set Real Filter +open scoped Topology NNReal +namespace ParisiSpectral + +lemma exp_abs_shift_le {M : ℝ} (hM : 0≤M) (x s z : ℝ) : + exp (M*|x+s*z|)≤exp (M*|x|)*exp (M*|s| *|z|) := by + rw [←exp_add] + apply exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_left (abs_add_le x (s*z)) hM + simpa only [abs_mul,mul_add,mul_assoc] using hh + +lemma exp_abs_shift_near_le {M : ℝ} (hM : 0≤M) (x s z : ℝ) {r : ℝ} (hr : |r-s|≤1) : + exp (M*|x+r*z|)≤exp (M*|x|)*exp (M*(|s|+1)*|z|) := by + have hb : |r|≤|s|+1 := by have := abs_add_le (r-s) s; rw [sub_add_cancel] at this; linarith + exact (exp_abs_shift_le hM x r z).trans (mul_le_mul_of_nonneg_left + (exp_le_exp.mpr (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hb hM) (abs_nonneg z))) (exp_pos _).le) + +lemma integrable_scale_prod {μ : Measure ℝ} [IsFiniteMeasure μ] {f : ℝ → ℝ} + (hc : Continuous f) {M C : ℝ} (hM : 0≤M) (hC : 0≤C) + (hf : ∀ x,|f x|≤C*exp (M*|x|)) (hi : Integrable (fun x => exp (M*|x|)) μ) (s : ℝ) : + Integrable (fun p : ℝ × ℝ => f (p.1+s*p.2)) (μ.prod (gaussianReal 0 1)) := by + have hh := (hi.const_mul C).mul_prod (ParisiFinite.integrable_exp_abs (M*|s|)) + apply hh.mono' (by fun_prop) + filter_upwards [] with p + rw [Real.norm_eq_abs] + exact (hf _).trans (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_left (exp_abs_shift_le hM p.1 s p.2) hC) + +lemma integrable_coord_scale_prod {μ : Measure ℝ} [IsFiniteMeasure μ] {f : ℝ → ℝ} + (hc : Continuous f) {M C : ℝ} (hM : 0≤M) (hC : 0≤C) + (hf : ∀ x,|f x|≤C*exp (M*|x|)) (hi : Integrable (fun x => exp (M*|x|)) μ) (s : ℝ) : + Integrable (fun p : ℝ × ℝ => p.2*f (p.1+s*p.2)) (μ.prod (gaussianReal 0 1)) := by + have hh := (hi.const_mul C).mul_prod (ParisiFinite.integrable_exp_abs (M*|s|+1)) + apply hh.mono' (by fun_prop) + filter_upwards [] with p + rw [Real.norm_eq_abs,abs_mul] + calc + |p.2| *|f (p.1+s*p.2)| ≤ |p.2| *(C*(exp (M*|p.1|) * exp (M*|s| *|p.2|))) := + mul_le_mul_of_nonneg_left ((hf _).trans (mul_le_mul_of_nonneg_left (exp_abs_shift_le hM _ _ _) hC)) (abs_nonneg _) + _ = C*exp (M*|p.1|)*(|p.2| *exp (M*|s| *|p.2|)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left (ParisiFinite.abs_mul_exp_le (M*|s|) p.2) (by positivity) + +lemma hasDerivAt_scale_prod {μ : Measure ℝ} [IsFiniteMeasure μ] {f f' : ℝ → ℝ} + (hc : Continuous f) (hc' : Continuous f') (hd : ∀ x,HasDerivAt f (f' x) x) + {M C D : ℝ} (hM : 0≤M) (hC : 0≤C) (hD : 0≤D) + (hf : ∀ x,|f x|≤C*exp (M*|x|)) (hf' : ∀ x,|f' x|≤D*exp (M*|x|)) + (hi : Integrable (fun x => exp (M*|x|)) μ) (s : ℝ) : + HasDerivAt (fun r => ∫ p : ℝ × ℝ,f (p.1+r*p.2) ∂μ.prod (gaussianReal 0 1)) + (∫ p : ℝ × ℝ,p.2*f' (p.1+s*p.2) ∂μ.prod (gaussianReal 0 1)) s := by + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball s 1) (bound := fun p : ℝ × ℝ => D*exp (M*|p.1|) * exp ((M*(|s|+1)+1)*|p.2|)) + (F' := fun r p => p.2*f' (p.1+r*p.2)) + (Metric.ball_mem_nhds _ (by norm_num)) + (Eventually.of_forall (fun r => by fun_prop)) (integrable_scale_prod hc hM hC hf hi s) + (by fun_prop) ?_ + ((hi.const_mul D).mul_prod (ParisiFinite.integrable_exp_abs (M*(|s|+1)+1))) ?_).2 + · exact ae_of_all _ fun p r hr => by + rw [Real.norm_eq_abs,abs_mul] + calc + |p.2| *|f' (p.1+r*p.2)| ≤ |p.2| *(D*(exp (M*|p.1|) * exp (M*(|s|+1)*|p.2|))) := + mul_le_mul_of_nonneg_left ((hf' _).trans (mul_le_mul_of_nonneg_left + (exp_abs_shift_near_le hM p.1 s p.2 (by simpa [Real.dist_eq] using hr.le)) hD)) (abs_nonneg _) + _ = D*exp (M*|p.1|)*(|p.2| *exp (M*(|s|+1)*|p.2|)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left (ParisiFinite.abs_mul_exp_le (M*(|s|+1)) p.2) (by positivity) + · exact ae_of_all _ fun p r _ => by + simpa only [Function.comp_def,id_eq,one_mul,mul_one,mul_comm] using (hd (p.1+r*p.2)).comp r (((hasDerivAt_id r).mul_const p.2).const_add p.1) + +lemma integrable_scale_gaussian {f : ℝ → ℝ} (hc : Continuous f) + {M C : ℝ} (hM : 0≤M) (hC : 0≤C) (hf : ∀ x,|f x|≤C*exp (M*|x|)) (x s : ℝ) : + Integrable (fun z => f (x+s*z)) (gaussianReal 0 1) := by + apply ((ParisiFinite.integrable_exp_abs (M*|s|)).const_mul (C*exp (M*|x|))).mono' (by fun_prop) + filter_upwards [] with z + rw [Real.norm_eq_abs] + exact (hf _).trans (by simpa only [mul_assoc] using mul_le_mul_of_nonneg_left (exp_abs_shift_le hM x s z) hC) + +lemma integrable_coord_scale_gaussian {f : ℝ → ℝ} (hc : Continuous f) + {M C : ℝ} (hM : 0≤M) (hC : 0≤C) (hf : ∀ x,|f x|≤C*exp (M*|x|)) (x s : ℝ) : + Integrable (fun z => z*f (x+s*z)) (gaussianReal 0 1) := by + apply ((ParisiFinite.integrable_exp_abs (M*|s|+1)).const_mul (C*exp (M*|x|))).mono' (by fun_prop) + filter_upwards [] with z + rw [Real.norm_eq_abs,abs_mul] + calc + |z| *|f (x+s*z)| ≤ |z| *(C*(exp (M*|x|)*exp (M*|s| *|z|))) := + mul_le_mul_of_nonneg_left ((hf _).trans (mul_le_mul_of_nonneg_left (exp_abs_shift_le hM _ _ _) hC)) (abs_nonneg _) + _ = C*exp (M*|x|)*(|z| *exp (M*|s| *|z|)) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left (ParisiFinite.abs_mul_exp_le (M*|s|) z) (by positivity) + +lemma scale_gaussian_ibp {f f' : ℝ → ℝ} (hc : Continuous f) (hc' : Continuous f') + (hd : ∀ x,HasDerivAt f (f' x) x) {M C D : ℝ} (hM : 0≤M) (hC : 0≤C) (hD : 0≤D) + (hf : ∀ x,|f x|≤C*exp (M*|x|)) (hf' : ∀ x,|f' x|≤D*exp (M*|x|)) (x s : ℝ) : + (∫ z,z*f (x+s*z) ∂gaussianReal 0 1)=s*∫ z,f' (x+s*z) ∂gaussianReal 0 1 := by + have hh := SKGaussian.integral_mul_eq_integral_deriv (f := fun z => f (x+s*z)) + (f' := fun z => s*f' (x+s*z)) + (fun z => by simpa only [Function.comp_def,id_eq,mul_one,mul_comm] using (hd (x+s*z)).comp z (((hasDerivAt_id z).const_mul s).const_add x)) + (integrable_scale_gaussian hc hM hC hf x s) + ((integrable_scale_gaussian hc' hM hD hf' x s).const_mul s) + (integrable_coord_scale_gaussian hc hM hC hf x s) + simpa only [integral_const_mul] using hh + +lemma hasDerivAt_scale_prod_second {μ : Measure ℝ} [IsFiniteMeasure μ] {f f' f'' : ℝ → ℝ} + (hc : Continuous f) (hc' : Continuous f') (hc'' : Continuous f'') + (hd : ∀ x,HasDerivAt f (f' x) x) (hd' : ∀ x,HasDerivAt f' (f'' x) x) + {M C D E : ℝ} (hM : 0≤M) (hC : 0≤C) (hD : 0≤D) (hE : 0≤E) + (hf : ∀ x,|f x|≤C*exp (M*|x|)) (hf' : ∀ x,|f' x|≤D*exp (M*|x|)) + (hf'' : ∀ x,|f'' x|≤E*exp (M*|x|)) + (hi : Integrable (fun x => exp (M*|x|)) μ) (s : ℝ) : + HasDerivAt (fun r => ∫ p : ℝ × ℝ,f (p.1+r*p.2) ∂μ.prod (gaussianReal 0 1)) + (s*∫ p : ℝ × ℝ,f'' (p.1+s*p.2) ∂μ.prod (gaussianReal 0 1)) s := by + have hh := hasDerivAt_scale_prod hc hc' hd hM hC hD hf hf' hi s + have he : (∫ p : ℝ × ℝ,p.2*f' (p.1+s*p.2) ∂μ.prod (gaussianReal 0 1))= + s*∫ p : ℝ × ℝ,f'' (p.1+s*p.2) ∂μ.prod (gaussianReal 0 1) := by + rw [integral_prod _ (integrable_coord_scale_prod hc' hM hD hf' hi s), + integral_prod _ (integrable_scale_prod hc'' hM hE hf'' hi s),←integral_const_mul] + apply integral_congr_ae + filter_upwards [] with x + exact scale_gaussian_ibp hc' hc'' hd' hM hD hE hf' hf'' x s + rwa [he] at hh + +def heatObservation (μ : Measure ℝ) (a : ℝ) (f : ℝ → ℝ) (t : ℝ) : ℝ := + ∫ p : ℝ × ℝ,f (p.1+sqrt (t-a)*p.2) ∂μ.prod (gaussianReal 0 1) + +lemma hasDerivAt_heatObservation {μ : Measure ℝ} [IsFiniteMeasure μ] {f f' f'' : ℝ → ℝ} + (hc : Continuous f) (hc' : Continuous f') (hc'' : Continuous f'') + (hd : ∀ x,HasDerivAt f (f' x) x) (hd' : ∀ x,HasDerivAt f' (f'' x) x) + {M C D E : ℝ} (hM : 0≤M) (hC : 0≤C) (hD : 0≤D) (hE : 0≤E) + (hf : ∀ x,|f x|≤C*exp (M*|x|)) (hf' : ∀ x,|f' x|≤D*exp (M*|x|)) + (hf'' : ∀ x,|f'' x|≤E*exp (M*|x|)) + (hi : Integrable (fun x => exp (M*|x|)) μ) {a t : ℝ} (ht : a exp (M*|x|)) μ) : + Continuous (fun s => ∫ p : ℝ × ℝ,f (p.1+s*p.2) ∂μ.prod (gaussianReal 0 1)) := by + rw [continuous_iff_continuousAt] + intro s + apply continuousAt_of_dominated (bound := fun p : ℝ × ℝ => C*exp (M*|p.1|) * exp (M*(|s|+1)*|p.2|)) + (Eventually.of_forall (fun r => by fun_prop)) ?_ + ((hi.const_mul C).mul_prod (ParisiFinite.integrable_exp_abs (M*(|s|+1)))) (ae_of_all _ fun p => by fun_prop) + filter_upwards [Metric.ball_mem_nhds s (by norm_num : (0:ℝ)<1)] with r hr + exact ae_of_all _ fun p => by + rw [Real.norm_eq_abs] + exact (hf _).trans (by simpa only [mul_assoc] using (mul_le_mul_of_nonneg_left + (exp_abs_shift_near_le hM p.1 s p.2 (by simpa [Real.dist_eq] using hr.le)) hC)) + +lemma continuous_heatObservation {μ : Measure ℝ} [IsFiniteMeasure μ] {f : ℝ → ℝ} + (hc : Continuous f) {M C : ℝ} (hM : 0≤M) (hC : 0≤C) + (hf : ∀ x,|f x|≤C*exp (M*|x|)) (hi : Integrable (fun x => exp (M*|x|)) μ) (a : ℝ) : + Continuous (heatObservation μ a f) := + (continuous_scale_prod hc hM hC hf hi).comp (by fun_prop) + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Set Real Matrix Filter +open scoped Topology NNReal +namespace ParisiSpectral + +lemma exp_neg_mul_le {L A r : ℝ} (hA : 0≤A) (hL : -A≤L) (hr : r∈Icc 0 1) : + exp (-r*L)≤exp A := by + apply exp_le_exp.mpr + calc + -r*L ≤ r*A := by nlinarith [mul_nonneg hr.1 (by linarith : 0≤L+A)] + _ ≤ A := mul_le_of_le_one_left hA hr.2 + +lemma exp_neg_quotient_bound {L A r : ℝ} (hA : 0≤A) (hL : -A≤L) (hr : r∈Ioc 0 1) : + |(exp (-r*L)-1)/r|≤exp A*|L| := by + have hd (s : ℝ) : HasDerivAt (fun u => exp (-u*L)) (exp (-s*L)*(-L)) s := by + convert (((hasDerivAt_id s).neg.mul_const L).exp) using 1 <;> first | rfl | (dsimp; ring) + have hb := norm_image_sub_le_of_norm_deriv_le_segment' + (a := 0) (b := 1) (fun s _ => (hd s).hasDerivWithinAt) + (C := exp A*|L|) (fun s hs => by + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (exp_pos _),abs_neg] + exact mul_le_mul_of_nonneg_right (exp_neg_mul_le hA hL ⟨hs.1,hs.2.le⟩) (abs_nonneg L)) r ⟨hr.1.le,hr.2⟩ + simp only [neg_zero,zero_mul,exp_zero,sub_zero,Real.norm_eq_abs] at hb + rw [abs_div,abs_of_pos hr.1,div_le_iff₀ hr.1] + exact hb + +lemma integral_exp_rightDerivative {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsFiniteMeasure μ] {L g : Ω → ℝ} (hLm : AEStronglyMeasurable L μ) + (hg : AEStronglyMeasurable g μ) {A C : ℝ} (hA : 0≤A) (hL : ∀ x,-A≤L x) + (hC : ∀ x,|g x|≤C) (hi : Integrable (fun x => |L x|) μ) : + Tendsto (fun r => ((∫ x,exp (-r*L x)*g x ∂μ)-∫ x,g x ∂μ)/r) + (𝓝[>] (0:ℝ)) (𝓝 (∫ x,-L x*g x ∂μ)) := by + have hgb : Integrable g μ := Integrable.of_bound hg C (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hC x) + have hnear : ∀ᶠ r in 𝓝[>] (0:ℝ),r∈Ioc 0 1 := by + filter_upwards [self_mem_nhdsWithin,(eventually_lt_nhds (show (0:ℝ)<1 by norm_num)).filter_mono nhdsWithin_le_nhds] + with r hr hr1 + exact ⟨hr,hr1.le⟩ + have ht := tendsto_integral_filter_of_dominated_convergence + (μ := μ) (l := 𝓝[>] (0:ℝ)) (bound := fun x => exp A*|L x| *C) + (F := fun r x => ((exp (-r*L x)-1)/r)*g x) (f := fun x => -L x*g x) + (Eventually.of_forall (fun r => ((show Continuous (fun u : ℝ => (exp (-r*u)-1)/r) from by fun_prop).comp_aestronglyMeasurable hLm).mul hg)) + (by filter_upwards [hnear] with r hr; filter_upwards [] with x + rw [Real.norm_eq_abs,abs_mul] + exact mul_le_mul (exp_neg_quotient_bound hA (hL x) hr) (hC x) (abs_nonneg _) (by positivity)) + ((hi.const_mul (exp A)).mul_const C) + (ae_of_all _ fun x => by + have hd : HasDerivAt (fun r => exp (-r*L x)) (-L x) 0 := by + convert ((hasDerivAt_id (0:ℝ)).neg.mul_const (L x)).exp using 1 <;> first | rfl | (dsimp; simp) + have hh := hd.tendsto_slope_zero_right.mul_const (g x) + simpa only [zero_add,neg_zero,zero_mul,mul_zero,exp_zero,smul_eq_mul,div_eq_mul_inv,mul_comm] using hh) + apply ht.congr' + filter_upwards [hnear] with r hr + have he : Integrable (fun x => exp (-r*L x)*g x) μ := + Integrable.of_bound ((continuous_exp.comp_aestronglyMeasurable (hLm.const_mul (-r))).mul hg) (exp A*C) (ae_of_all _ fun x => by + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (exp_pos _)] + exact mul_le_mul (exp_neg_mul_le hA (hL x) ⟨hr.1.le,hr.2⟩) (hC x) (abs_nonneg _) (exp_pos _).le) + have heq : (fun x => ((exp (-r*L x)-1)/r)*g x)= + (fun x => (exp (-r*L x)*g x-g x)/r) := by funext x; ring + rw [heq,integral_div,integral_sub he hgb] +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Set Real Matrix Filter +open scoped Topology NNReal +namespace ParisiSpectral + +def heatLaw (μ : Measure ℝ) (a t : ℝ) : Measure ℝ := μ ∗ gaussianReal 0 (toNNReal (t-a)) +instance (μ : Measure ℝ) [IsFiniteMeasure μ] (a t : ℝ) : IsFiniteMeasure (heatLaw μ a t) := by + unfold heatLaw + infer_instance + +lemma integral_heatLaw {μ : Measure ℝ} [IsFiniteMeasure μ] {f : ℝ → ℝ} {a t : ℝ} + (hf : Integrable f (heatLaw μ a t)) : + (∫ x,f x ∂heatLaw μ a t)=∫ x,heat (toNNReal (t-a)) f x ∂μ := integral_conv hf + +lemma heatLaw_firstMoment {μ : Measure ℝ} [IsFiniteMeasure μ] + (hi : Integrable (fun x : ℝ => |x|) μ) (a t : ℝ) : + Integrable (fun x : ℝ => |x|) (heatLaw μ a t) := by + rw [heatLaw,Measure.conv,integrable_map_measure (by fun_prop) (by fun_prop)] + have hz := ((memLp_id_gaussianReal (μ := 0) (v := toNNReal (t-a)) 1).integrable (by norm_num)).abs + exact ((hi.comp_fst (ν := gaussianReal 0 (toNNReal (t-a)))).add + (hz.comp_snd (μ := μ))).mono' (by fun_prop) (ae_of_all _ fun p => by + simpa [Real.norm_eq_abs] using abs_add_le p.1 p.2) + +lemma abs_log_cosh_le (x : ℝ) : |log (cosh x)|≤|x| := by + rw [abs_of_nonneg (log_nonneg (one_le_cosh x))] + have hc : cosh x≤exp |x| := by + rw [cosh_eq] + have h1 := exp_le_exp.mpr (le_abs_self x) + have h2 := exp_le_exp.mpr (neg_le_abs x) + linarith + simpa only [log_exp] using log_le_log (cosh_pos x) hc + +lemma backwardC_pos {K : ℝ} (hK : 0 |x|) μ) {K : ℝ} (hK : 0 |log (backwardC d K α t x)|) μ := by + have hc : Continuous (fun x => log (backwardC d K α t x)) := by + simp only [backwardC_log d K α t _ hK] + exact continuous_const.add ((continuous_cosh.comp (continuous_const.mul continuous_id)).log (fun x => (cosh_pos _).ne')) + refine ((integrable_const |log K+α^2/2*(d-t)|).add (hi.const_mul |α|)).mono' hc.abs.aestronglyMeasurable ?_ + filter_upwards [] with x + rw [Real.norm_eq_abs,abs_abs,backwardC_log d K α t x hK] + exact (abs_add_le _ _).trans (add_le_add_right (by simpa only [abs_mul] using abs_log_cosh_le (α*x)) _) + +lemma hankelPD_heatLaw {μ : Measure ℝ} [IsFiniteMeasure μ] (hμ : PositiveOnPD μ) + {F : ℝ → ℝ → ℝ} {a : ℝ} {s : Set ℝ} (hs : ∀ t∈s,a≤t) (hsv : Convex ℝ s) + (hc : ∀ t∈s,Continuous (F t)) + (hK : Matrix.PosSemidef (Matrix.of (fun p q : s × ℝ => F ((p.1+q.1)/2) (p.2-q.2)))) : + HankelPD (fun t => ∫ x,F t x ∂heatLaw μ a t) s := by + have hh := hankelPD_heat_observation hμ hs hsv hc hK + have he (t : ℝ) (ht : t∈s) : (∫ x,F t x ∂heatLaw μ a t)=∫ x,heat (toNNReal (t-a)) (F t) x ∂μ := by + have hb := stationary_kernel_bounded (fun u v : s => F ((u+v)/2)) hK ⟨t,ht⟩ ⟨t,ht⟩ + simp only [show (t+t)/2=t by ring] at hb + exact integral_heatLaw (Integrable.of_bound (hc t ht).aestronglyMeasurable _ (ae_of_all _ hb)) + have hm (x y : s) : ((x:ℝ)+y)/2∈s := by + simpa only [midpoint_eq_smul_add,smul_eq_mul,invOf_eq_inv,div_eq_mul_inv,mul_comm] using hsv.midpoint_mem x.property y.property + change (Matrix.of (fun x y : s => ∫ z,F ((x+y)/2) z ∂heatLaw μ a ((x+y)/2))).PosSemidef + change (Matrix.of (fun x y : s => ∫ z,heat (toNNReal (((x:ℝ)+y)/2-a)) (F ((x+y)/2)) z ∂μ)).PosSemidef at hh + simpa only [he _ (hm _ _)] using hh + +lemma backwardG_observation_constant {μ : Measure ℝ} [IsFiniteMeasure μ] + {g : ℝ → ℝ} (hg : PositiveDefinite g) (hc : Continuous g) {a d t : ℝ} + (hat : a≤t) (htd : t≤d) : + (∫ x,backwardG d g t x ∂heatLaw μ a t)=∫ x,heat (toNNReal (d-a)) g x ∂μ := by + have hh := integral_heatLaw (μ := μ) (a := a) (t := t) + (Integrable.of_bound (continuous_heat hc hg.norm_le _).aestronglyMeasurable _ + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hg.heat_abs_le hc (toNNReal (d-t)) x)) + rw [heat_heat hc hg.norm_le] at hh + have he : toNNReal (t-a)+toNNReal (d-t)=toNNReal (d-a) := by + apply NNReal.eq + rw [NNReal.coe_add,coe_toNNReal _ (sub_nonneg.mpr hat),coe_toNNReal _ (sub_nonneg.mpr htd), + coe_toNNReal _ (sub_nonneg.mpr (hat.trans htd))] + ring + simpa only [backwardG,he] using hh + +lemma backwardG_bound {g : ℝ → ℝ} (hg : PositiveDefinite g) (hc : Continuous g) + (d t x : ℝ) : |backwardG d g t x|≤g 0 := hg.heat_abs_le hc _ _ + +lemma hankelCPD_linearEntropy {μ : Measure ℝ} [IsFiniteMeasure μ] + (hμ : PositiveOnPD μ) (hi : Integrable (fun x : ℝ => |x|) μ) + {g : ℝ → ℝ} (hg : PositiveDefinite g) (hc : Continuous g) + {a d K α : ℝ} (hK : 0 ∫ x,-log (backwardC d K α t x)*backwardG d g t x ∂heatLaw μ a t) s := by + let F (r t : ℝ) := ∫ x,(backwardC d K α t x)^(-r)*backwardG d g t x ∂heatLaw μ a t + apply HankelCPD.of_rightQuotient (F := F) (C := ∫ x,heat (toNNReal (d-a)) g x ∂μ) hsv + · intro r hr + apply hankelPD_heatLaw hμ (fun t ht => (hs t ht).1) hsv + · intro t ht + have hcc : Continuous (backwardC d K α t) := by unfold backwardC; fun_prop + exact (hcc.rpow_const (fun x => Or.inl (backwardC_pos hK _ _ _ x).ne')).mul (continuous_heat hc hg.norm_le _) + · exact (backwardC_neg_rpow hK hr s).hadamard (backwardG_reflection hg hc (fun t ht => (hs t ht).2)) + · intro t ht + let L : ℝ → ℝ := fun x => log (backwardC d K α t x) + have hLc : Continuous L := by + unfold L + simp only [backwardC_log d K α t _ hK] + exact continuous_const.add ((continuous_cosh.comp (continuous_const.mul continuous_id)).log (fun x => (cosh_pos _).ne')) + have hL (x : ℝ) : -|log K+α^2/2*(d-t)|≤L x := by + dsimp only [L] + rw [backwardC_log d K α t x hK] + have := log_nonneg (one_le_cosh (α*x)) + linarith [neg_abs_le (log K+α^2/2*(d-t))] + have hh := integral_exp_rightDerivative hLc.aestronglyMeasurable + (continuous_heat hc hg.norm_le (toNNReal (d-t))).aestronglyMeasurable + (abs_nonneg (log K+α^2/2*(d-t))) hL (backwardG_bound hg hc d t) + (backwardC_log_integrable (heatLaw_firstMoment hi a t) hK d α t) + change Tendsto (fun r => ((∫ x,exp (-r*L x)*backwardG d g t x ∂heatLaw μ a t)-∫ x,backwardG d g t x ∂heatLaw μ a t)/r) (𝓝[>] (0:ℝ)) (𝓝 (∫ x,-L x*backwardG d g t x ∂heatLaw μ a t)) at hh + rw [backwardG_observation_constant hg hc (hs t ht).1 (hs t ht).2] at hh + apply hh.congr + intro r + dsimp only [F] + congr 2 + apply integral_congr_ae + filter_upwards [] with x + simp only [rpow_def_of_pos (backwardC_pos hK _ _ _ _),L,mul_comm] + +lemma hankelPD_entropyRemainder {μ : Measure ℝ} [IsFiniteMeasure μ] + (hμ : PositiveOnPD μ) {g : ℝ → ℝ} (hg : PositiveDefinite g) (hc : Continuous g) + {a d K α : ℝ} (hK : 0 ∫ x, + (backwardC d K α t x-backwardG d g t x)*log (backwardC d K α t x-backwardG d g t x)- + backwardC d K α t x*log (backwardC d K α t x)+ + (1+log (backwardC d K α t x))*backwardG d g t x ∂heatLaw μ a t) s := by + have hcb (t : ℝ) (ht : t≤d) (x : ℝ) : K≤backwardC d K α t x := by + unfold backwardC + have he : 1≤exp (α^2/2*(d-t)) := one_le_exp_iff.mpr (by positivity) + have hh : K≤K*exp (α^2/2*(d-t)) := by simpa only [mul_one] using mul_le_mul_of_nonneg_left he hK.le + exact hh.trans (le_mul_of_one_le_right (mul_pos hK (exp_pos _)).le (one_le_cosh _)) + have hd (t : ℝ) (ht : t≤d) (x : ℝ) : |backwardG d g t x| (hs t ht).1) hsv + · intro t ht + have hCc : Continuous (backwardC d K α t) := by unfold backwardC; fun_prop + have hGc := continuous_heat hc hg.norm_le (toNNReal (d-t)) + have hdc : Continuous (fun x => backwardC d K α t x-backwardG d g t x) := hCc.sub hGc + have hdp (x : ℝ) : 0 (hdp x).ne'))).sub + (hCc.mul (hCc.log (fun x => (backwardC_pos hK _ _ _ x).ne')))).add + ((continuous_const.add (hCc.log (fun x => (backwardC_pos hK _ _ _ x).ne'))).mul hGc) + · apply posSemidef_entropy_remainder + · intro p q + exact backwardC_pos hK _ _ _ _ + · exact backwardG_reflection hg hc (fun t ht => (hs t ht).2) + · intro p q + exact hd _ (by linarith [(hs p.1 p.1.property).2,(hs q.1 q.1.property).2]) _ + · intro n + exact backwardC_neg_rpow hK (by positivity) s + +end ParisiSpectral + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ParisiReflection.lean b/lean/OAI/Probability/ParisiFinite/ParisiReflection.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f4ea955fad84054bd2964bd4628c6e0b6425a80 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ParisiReflection.lean @@ -0,0 +1,652 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ParisiConjugateTransport +import OAI.Probability.ParisiFinite.ParisiCanonicalTransport + +namespace OAI + +/-! Parisi Reflection. -/ + +noncomputable section + +open MeasureTheory Set Filter +open scoped Topology +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Set Real Matrix Filter InnerProductSpace +open scoped Topology NNReal RealInnerProductSpace +namespace ParisiSpectral + +lemma posSemidef_kernel_variable_average {A B Ω : Type*} [MeasurableSpace Ω] + (K : Matrix A A ℝ) [Fact K.PosSemidef] + (μ : B → Measure Ω) (T : B → Ω → A) + (hi : ∀ b, Integrable (fun z => kernelFeature K (T b z)) (μ b)) : + Matrix.PosSemidef (fun b c => ∫ z, ∫ w, K (T b z) (T c w) ∂(μ c) ∂(μ b)) := by + have he (b c : B) : (∫ z, ∫ w, K (T b z) (T c w) ∂(μ c) ∂(μ b)) = + ⟪∫ z, kernelFeature K (T b z) ∂(μ b), ∫ w, kernelFeature K (T c w) ∂(μ c)⟫_ℝ := by + simp_rw [← inner_kernelFeature K, integral_inner (hi c)] + simp_rw [real_inner_comm (∫ w, kernelFeature K (T c w) ∂(μ c))] + rw [integral_inner (hi b), real_inner_comm] + simpa only [he] using posSemidef_inner (fun b => ∫ z, kernelFeature K (T b z) ∂(μ b)) + +lemma gaussian_double_difference_general {f : ℝ → ℝ} (hc : Continuous f) + {C : ℝ} (hC : ∀ x, ‖f x‖ ≤ C) (s t : ℝ≥0) (x : ℝ) : + (∫ z, ∫ w, f (x+z-w) ∂gaussianReal 0 t ∂gaussianReal 0 s) = heat (s+t) f x := by + have he (z : ℝ) : (∫ w, f (x+z-w) ∂gaussianReal 0 t) = + (∫ w, f (x+z+w) ∂gaussianReal 0 t) := by + have hh := integral_map (μ := gaussianReal 0 t) (f := fun w => f (x+z+w)) measurable_neg.aemeasurable + ((hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable) + rw [gaussianReal_map_neg, neg_zero] at hh + simpa only [sub_eq_add_neg] using hh.symm + simp_rw [he] + have hi : Integrable (fun z => f (x+z)) (gaussianReal 0 s ∗ gaussianReal 0 t) := by + rw [gaussianReal_conv_gaussianReal] + exact Integrable.of_bound (hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable C + (ae_of_all _ fun z => hC _) + have hh := integral_conv hi + rw [gaussianReal_conv_gaussianReal, zero_add] at hh + simpa only [heat, add_assoc] using hh.symm + + + +lemma PositiveDefinite.heat_reflection {f : ℝ → ℝ} (hf : PositiveDefinite f) + (hc : Continuous f) : + Matrix.PosSemidef (fun p q : ℝ≥0 × ℝ => ParisiSpectral.heat (p.1+q.1) f (p.2-q.2)) := by + let K : Matrix ℝ ℝ ℝ := fun x y => f (x-y) + let : Fact K.PosSemidef := ⟨hf⟩ + have hcont : Continuous (kernelFeature K) := hf.continuous_feature hc + have hi (p : ℝ≥0 × ℝ) : Integrable (fun z => kernelFeature K (p.2+z)) (gaussianReal 0 p.1) := by + apply Integrable.of_bound (hcont.comp (continuous_const.add continuous_id)).aestronglyMeasurable + (sqrt (f 0)) + filter_upwards [] with z + have hn := norm_kernelFeature_sq K (p.2+z) + simp only [K, sub_self] at hn + exact (le_sqrt (norm_nonneg _) hf.at_zero).mpr hn.le + have hp := posSemidef_kernel_variable_average K (fun p : ℝ≥0 × ℝ => gaussianReal 0 p.1) + (fun p z => p.2+z) hi + have he : (fun p q : ℝ≥0 × ℝ => ∫ z, ∫ w, K (p.2+z) (q.2+w) + ∂gaussianReal 0 q.1 ∂gaussianReal 0 p.1) = + (fun p q : ℝ≥0 × ℝ => ParisiSpectral.heat (p.1+q.1) f (p.2-q.2)) := by + funext p q + rw [← gaussian_double_difference_general hc hf.norm_le p.1 q.1 (p.2-q.2)] + apply integral_congr_ae + filter_upwards [] with z + apply integral_congr_ae + filter_upwards [] with w + change f ((p.2+z)-(q.2+w)) = f (p.2-q.2+z-w) + congr 1 + ring + exact (congrArg Matrix.PosSemidef he).mp hp + +lemma PositiveDefinite.heat_abs_le {g : ℝ → ℝ} (hg : PositiveDefinite g) + (hc : Continuous g) (t : ℝ≥0) (x : ℝ) : |ParisiSpectral.heat t g x| ≤ g 0 := by + apply abs_integral_le_integral_abs.trans + have hi : Integrable (fun z => |g (x+z)|) (gaussianReal 0 t) := + Integrable.of_bound (hc.comp (continuous_const.add continuous_id)).abs.aestronglyMeasurable + (g 0) (ae_of_all _ fun z => by simpa only [Real.norm_eq_abs, abs_abs] using hg.norm_le (x+z)) + have hh := integral_mono hi (integrable_const (g 0)) + (fun z => by simpa only [Real.norm_eq_abs] using hg.norm_le (x+z)) + simpa only [integral_const, probReal_univ, one_smul] using hh + +end ParisiSpectral + +open MeasureTheory ProbabilityTheory Set Real Matrix Filter InnerProductSpace +open scoped Topology NNReal RealInnerProductSpace BigOperators +namespace ParisiSpectral + +lemma hasSum_entropy_remainder {u : ℝ} (hu : |u| < 1) : + HasSum (fun n : ℕ => u^(n+2)/((n+1:ℝ)*(n+2))) ((1-u)*log (1-u)+u) := by + have h := hasSum_pow_div_log_of_abs_lt_one hu + have hs : HasSum (fun n : ℕ => u^(n+2)/(n+2)) (-log (1-u)-u) := by + have ht := (hasSum_nat_add_iff' (f := fun n : ℕ => u^(n+1)/(n+1)) 1).mpr h + simpa only [Finset.sum_range_one, zero_add, pow_one, Nat.cast_one, div_one, + Nat.cast_zero, Nat.cast_add, add_assoc, one_add_one_eq_two] using ht + have hm := (h.mul_left u).sub hs + convert! hm using 1 + · funext n + have hn : (n+1:ℝ) ≠ 0 := by positivity + have hn2 : (n+2:ℝ) ≠ 0 := by positivity + rw [pow_succ, pow_succ] + field_simp + ring + · ring + +lemma posSemidef_hadamard_pow {A : Type*} {K : Matrix A A ℝ} + (hK : K.PosSemidef) (n : ℕ) : Matrix.PosSemidef (fun a b => (K a b)^n) := by + induction n with + | zero => + simpa only [pow_zero, RCLike.inner_apply, map_one, star_trivial, mul_one] using + (posSemidef_inner (fun _ : A => (1:ℝ))) + | succ n ih => + have hh : Matrix.PosSemidef (fun a b => (K a b)^n * K a b) := ih.hadamard hK + simpa only [pow_succ] using hh + + + +lemma posSemidef_entropy_remainder {A : Type*} (c g : Matrix A A ℝ) + (hc : ∀ a b, 0 < c a b) (hg : g.PosSemidef) + (hgc : ∀ a b, |g a b| < c a b) + (hinv : ∀ n : ℕ, Matrix.PosSemidef (fun a b => (c a b)^(-(n+1:ℝ)))) : + Matrix.PosSemidef (fun a b => + (c a b-g a b)*log (c a b-g a b)-c a b*log (c a b)+ + (1+log (c a b))*g a b) := by + classical + let F (n : ℕ) : Matrix A A ℝ := fun a b => + (g a b)^(n+2)*(c a b)^(-(n+1:ℝ))/((n+1:ℝ)*(n+2)) + have hF (n : ℕ) : (F n).PosSemidef := by + have hh := ((posSemidef_hadamard_pow hg (n+2)).hadamard (hinv n)).smul + (show (0:ℝ) ≤ ((n+1:ℝ)*(n+2))⁻¹ by positivity) + convert! hh using 1 + funext a b + dsimp only [F] + change _ = ((n+1:ℝ)*(n+2))⁻¹*((g a b)^(n+2)*(c a b)^(-(n+1:ℝ))) + rw [div_eq_mul_inv] + ring + have hs (a b : A) : HasSum (fun n => F n a b) + ((c a b-g a b)*log (c a b-g a b)-c a b*log (c a b)+ + (1+log (c a b))*g a b) := by + have hu : |g a b/c a b| < 1 := by + rw [abs_div, abs_of_pos (hc a b), div_lt_one (hc a b)] + exact hgc a b + have hh := (hasSum_entropy_remainder hu).mul_left (c a b) + have hdiff : 0 < c a b-g a b := by have := le_abs_self (g a b); linarith [hgc a b] + have he : 1-g a b/c a b = (c a b-g a b)/c a b := by field_simp [(hc a b).ne'] + convert! hh using 1 + · funext n + dsimp only [F] + have hr : (c a b)^(-(n+1:ℝ)) = ((c a b)^(n+1))⁻¹ := by + rw [rpow_neg (hc a b).le] + norm_cast + rw [hr, div_pow] + field_simp [(hc a b).ne'] + ring + · rw [he, log_div hdiff.ne' (hc a b).ne'] + field_simp [(hc a b).ne'] + ring + apply PositiveDefinite.posSemidef_limit (l := atTop) + (K := fun N : ℕ => ∑ n ∈ Finset.range N, F n) + · intro N + exact Matrix.posSemidef_sum (Finset.range N) (fun n _ => hF n) + · intro a b + have he : (fun i : ℕ => (∑ n ∈ Finset.range i, F n) a b) = + (fun i : ℕ => ∑ n ∈ Finset.range i, F n a b) := by + funext i + exact Matrix.sum_apply a b (Finset.range i) F + rw [he] + exact (hs a b).tendsto_sum_nat + +end ParisiSpectral + + + +open MeasureTheory ProbabilityTheory Set Real Matrix Filter InnerProductSpace +open scoped Topology NNReal RealInnerProductSpace BigOperators +namespace ParisiSpectral + +lemma posSemidef_kernel_finite_combination {A B I : Type*} [Fintype I] + (K : Matrix A A ℝ) [Fact K.PosSemidef] (T : B → I → A) (c : B → I → ℝ) : + Matrix.PosSemidef (fun b d => ∑ i, ∑ j, c b i*c d j*K (T b i) (T d j)) := by + have he b d : (∑ i, ∑ j, c b i*c d j*K (T b i) (T d j)) = + ⟪∑ i, c b i • kernelFeature K (T b i),∑ j, c d j • kernelFeature K (T d j)⟫_ℝ := by + simp only [sum_inner,inner_sum,real_inner_smul_left,real_inner_smul_right,inner_kernelFeature] + conv_rhs => rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i hi + apply Finset.sum_congr rfl + intro j hj + ring + simpa only [he] using posSemidef_inner (fun b => ∑ i, c b i • kernelFeature K (T b i)) + +lemma scaled_taylor_tendsto {f : ℝ → ℝ} {n : ℕ} (hf : ContDiff ℝ n f) + (x k : ℝ) : + Tendsto (fun e => (f (x+k*e)-taylorWithinEval f n univ x (x+k*e))/e^n) + (𝓝 (0:ℝ)) (𝓝 0) := by + have ht := Real.taylor_tendsto (f := f) (n := n) convex_univ (mem_univ x) hf.contDiffOn + simp only [nhdsWithin_univ] at ht + have hc : Tendsto (fun e : ℝ => x+k*e) (𝓝 0) (𝓝 x) := by + simpa only [mul_zero,add_zero] using + ((show Continuous (fun e : ℝ => x+k*e) from by fun_prop).tendsto (0:ℝ)) + have hh := (ht.comp hc).const_mul (k^n) + simp only [mul_zero] at hh + apply hh.congr + intro e + dsimp only [Function.comp_def] + rw [add_sub_cancel_left,mul_pow] + by_cases hk : k=0 + · simp [hk,taylorWithinEval_self] + · field_simp + +def jetWeight (n i : Fin 3) : ℝ := + match n.val,i.val with + | 0,0 => 1 + | 0,_ => 0 + | 1,0 => -1 + | 1,1 => 1 + | 1,_ => 0 + | _,0 => 1 + | _,1 => -2 + | _,_ => 1 + +def differenceJet (f : ℝ → ℝ) (n m : Fin 3) (x e : ℝ) : ℝ := + (∑ i : Fin 3,∑ j : Fin 3, + (jetWeight n i)*(jetWeight m j)*f (x+((i:ℝ)-(j:ℝ))*e))/e^((n:ℕ)+(m:ℕ)) + +lemma differenceJet_tendsto {f : ℝ → ℝ} (n m : Fin 3) + (hf : ContDiff ℝ ((n:ℕ)+(m:ℕ)) f) (x : ℝ) : + Tendsto (differenceJet f n m x) (𝓝[≠] (0:ℝ)) + (𝓝 ((-1:ℝ)^(m:ℕ)*iteratedDeriv ((n:ℕ)+(m:ℕ)) f x)) := by + have hs (i j : Fin 3) := (scaled_taylor_tendsto hf x ((i:ℝ)-(j:ℝ))).const_mul + (jetWeight n i*jetWeight m j) + have ht := tendsto_finsetSum Finset.univ (fun i hi => + tendsto_finsetSum Finset.univ (fun j hj => hs i j)) + simp only [mul_zero,Finset.sum_const_zero] at ht + have ht' := ht.mono_left (nhdsWithin_le_nhds : 𝓝[≠] (0:ℝ) ≤ 𝓝 (0:ℝ)) + have he : (fun e : ℝ => ∑ i : Fin 3,∑ j : Fin 3, + jetWeight n i*jetWeight m j*((f (x+((i:ℝ)-(j:ℝ))*e)- + taylorWithinEval f ((n:ℕ)+(m:ℕ)) univ x (x+((i:ℝ)-(j:ℝ))*e))/e^((n:ℕ)+(m:ℕ)))) + =ᶠ[𝓝[≠] (0:ℝ)] (fun e => differenceJet f n m x e- + (-1:ℝ)^(m:ℕ)*iteratedDeriv ((n:ℕ)+(m:ℕ)) f x) := by + filter_upwards [self_mem_nhdsWithin] with e he + have hne : e≠0 := he + fin_cases n <;> fin_cases m <;> + norm_num [differenceJet,jetWeight,Fin.sum_univ_three,taylorWithinEval_succ, + taylor_within_zero_eval,iteratedDerivWithin_univ,smul_eq_mul,Nat.factorial] <;> + field_simp [hne] <;> norm_num <;> ring + have hh := ht'.congr' he + exact (tendsto_sub_nhds_zero_iff).mp hh + + + +lemma posSemidef_spatial_jets {T I : Type*} (F : T → T → ℝ → ℝ) + (hF : Matrix.PosSemidef (fun p q : T×ℝ => F p.1 q.1 (p.2-q.2))) + (ord : I → Fin 3) + (hc : ∀ t u i j,ContDiff ℝ ((ord i:ℕ)+(ord j:ℕ)) (F t u)) : + Matrix.PosSemidef (fun p q : T×I×ℝ => + (-1:ℝ)^(ord q.2.1:ℕ)*iteratedDeriv ((ord p.2.1:ℕ)+(ord q.2.1:ℕ)) + (F p.1 q.1) (p.2.2-q.2.2)) := by + let K : Matrix (T×ℝ) (T×ℝ) ℝ := fun p q => F p.1 q.1 (p.2-q.2) + let : Fact K.PosSemidef := ⟨hF⟩ + let B (e : ℝ) : Matrix (T×I×ℝ) (T×I×ℝ) ℝ := fun p q => + ∑ k : Fin 3,∑ l : Fin 3, + (jetWeight (ord p.2.1) k/e^(ord p.2.1:ℕ))* + (jetWeight (ord q.2.1) l/e^(ord q.2.1:ℕ))* + F p.1 q.1 ((p.2.2+(k:ℝ)*e)-(q.2.2+(l:ℝ)*e)) + have hp (e : ℝ) : (B e).PosSemidef := + posSemidef_kernel_finite_combination K + (fun (p : T×I×ℝ) (k : Fin 3) => (p.1,p.2.2+(k:ℝ)*e)) + (fun (p : T×I×ℝ) (k : Fin 3) => jetWeight (ord p.2.1) k/e^(ord p.2.1:ℕ)) + apply PositiveDefinite.posSemidef_limit (l := 𝓝[≠] (0:ℝ)) hp + intro p q + have he (e : ℝ) : B e p q = differenceJet (F p.1 q.1) (ord p.2.1) (ord q.2.1) + (p.2.2-q.2.2) e := by + dsimp only [B,differenceJet] + simp only [Finset.sum_div] + apply Finset.sum_congr rfl + intro k hk + apply Finset.sum_congr rfl + intro l hl + rw [show (p.2.2+(k:ℝ)*e)-(q.2.2+(l:ℝ)*e)= + (p.2.2-q.2.2)+((k:ℝ)-(l:ℝ))*e by ring] + rw [pow_add] + ring + simpa only [he] using differenceJet_tendsto (ord p.2.1) (ord q.2.1) + (hc p.1 q.1 p.2.1 q.2.1) (p.2.2-q.2.2) + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Set Real Matrix Filter InnerProductSpace +open scoped Topology NNReal RealInnerProductSpace BigOperators +namespace ParisiSpectral + +def PositiveOnPD (μ : Measure ℝ) : Prop := + ∀ f : ℝ → ℝ, Continuous f → PositiveDefinite f → 0≤∫ x,f x ∂μ + +lemma stationary_kernel_finsupp {A : Type*} (κ : A → A → ℝ → ℝ) + (hκ : Matrix.PosSemidef (fun p q : A × ℝ => κ p.1 q.1 (p.2-q.2))) + (c : A →₀ ℝ) : PositiveDefinite (fun x => ∑ a∈c.support,∑ b∈c.support,c a*c b*κ a b x) := by + classical + let K : Matrix (A × ℝ) (A × ℝ) ℝ := fun p q => κ p.1 q.1 (p.2-q.2) + let : Fact K.PosSemidef := ⟨hκ⟩ + have he (x y : ℝ) : (∑ a∈c.support,∑ b∈c.support,c a*c b*κ a b (x-y)) = + ⟪∑ a∈c.support,c a • kernelFeature K (a,x),∑ b∈c.support,c b • kernelFeature K (b,y)⟫_ℝ := by + simp only [sum_inner,inner_sum,real_inner_smul_left,real_inner_smul_right,inner_kernelFeature] + conv_rhs => rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + dsimp only [K] + ring + simpa only [PositiveDefinite,he] using + posSemidef_inner (fun x => ∑ a∈c.support,c a • kernelFeature K (a,x)) + +lemma PositiveOnPD.kernel_integral {A : Type*} {μ : Measure ℝ} (hμ : PositiveOnPD μ) + (κ : A → A → ℝ → ℝ) + (hκ : Matrix.PosSemidef (fun p q : A × ℝ => κ p.1 q.1 (p.2-q.2))) + (hc : ∀ a b,Continuous (κ a b)) (hi : ∀ a b,Integrable (κ a b) μ) + (hsym : ∀ a b,κ a b=κ b a) : + Matrix.PosSemidef (fun a b => ∫ x,κ a b x ∂μ) := by + classical + refine ⟨?_,?_⟩ + · apply Matrix.IsHermitian.ext + intro a b + simp only [star_trivial] + rw [hsym b a] + · intro c + have hs := stationary_kernel_finsupp κ hκ c + have hp := hμ _ (by + apply continuous_finsetSum + intro a ha + apply continuous_finsetSum + intro b hb + exact continuous_const.mul (hc a b)) hs + have hi' (a b : A) : Integrable (fun x => c a*c b*κ a b x) μ := (hi a b).const_mul _ + rw [integral_finsetSum c.support (fun a ha => + integrable_finsetSum _ (fun b hb => hi' a b))] at hp + simp_rw [integral_finsetSum c.support (fun b hb => hi' _ b),integral_const_mul] at hp + simpa only [Finsupp.sum,star_trivial,mul_assoc,mul_left_comm,mul_comm] using hp + +lemma continuous_kernelFeature_comp {A B : Type*} [TopologicalSpace B] + (K : Matrix A A ℝ) [Fact K.PosSemidef] (T : B → A) + (hc : Continuous (fun p : B × B => K (T p.1) (T p.2))) : + Continuous (fun x => kernelFeature K (T x)) := by + apply continuous_iff_continuousAt.mpr + intro x + change Filter.Tendsto _ _ _ + rw [Metric.tendsto_nhds] + intro ε hε + have ht : Tendsto (fun y => K (T y) (T y)+K (T x) (T x)-2*K (T y) (T x)) (𝓝 x) (𝓝 0) := by + have h1 : Continuous (fun y => K (T y) (T y)) := hc.comp (continuous_id.prodMk continuous_id) + have h2 : Continuous (fun y => K (T y) (T x)) := hc.comp (continuous_id.prodMk (continuous_const (y := x))) + have hh := (h1.add (continuous_const (y := K (T x) (T x))) |>.sub (h2.const_mul 2)).tendsto x + change Tendsto _ (𝓝 x) (𝓝 (K (T x) (T x)+K (T x) (T x)-2*K (T x) (T x))) at hh + rwa [show K (T x) (T x)+K (T x) (T x)-2*K (T x) (T x)=0 by ring] at hh + filter_upwards [ht.eventually (gt_mem_nhds (sq_pos_of_pos hε))] with y hy + rw [dist_eq_norm] + have hn := norm_kernelFeature_sub_sq K (T y) (T x) + nlinarith [norm_nonneg (kernelFeature K (T y)-kernelFeature K (T x))] + +lemma stationary_kernel_bounded {A : Type*} (κ : A → A → ℝ → ℝ) + (hκ : Matrix.PosSemidef (fun p q : A × ℝ => κ p.1 q.1 (p.2-q.2))) (a b : A) : + ∀ x,‖κ a b x‖ ≤ sqrt (κ a a 0)*sqrt (κ b b 0) := by + let K : Matrix (A × ℝ) (A × ℝ) ℝ := fun p q => κ p.1 q.1 (p.2-q.2) + let : Fact K.PosSemidef := ⟨hκ⟩ + have hn (d : A) (x : ℝ) : ‖kernelFeature K (d,x)‖=sqrt (κ d d 0) := by + have hh := norm_kernelFeature_sq K (d,x) + simp only [K,sub_self] at hh + rw [←hh,sqrt_sq (norm_nonneg _)] + intro x + have hh := abs_real_inner_le_norm (kernelFeature K (a,x)) (kernelFeature K (b,0)) + rwa [inner_kernelFeature,hn,hn,show K (a,x) (b,0)=κ a b x from by simp [K],←Real.norm_eq_abs] at hh + +lemma stationary_kernel_heat {A : Type*} (κ : A → A → ℝ → ℝ) + (hκ : Matrix.PosSemidef (fun p q : A × ℝ => κ p.1 q.1 (p.2-q.2))) + (hc : ∀ a b,Continuous (κ a b)) (s : A → ℝ≥0) : + Matrix.PosSemidef (fun p q : A × ℝ => heat (s p.1+s q.1) (κ p.1 q.1) (p.2-q.2)) := by + let K : Matrix (A × ℝ) (A × ℝ) ℝ := fun p q => κ p.1 q.1 (p.2-q.2) + let : Fact K.PosSemidef := ⟨hκ⟩ + have hi (p : A × ℝ) : Integrable (fun z => kernelFeature K (p.1,p.2+z)) (gaussianReal 0 (s p.1)) := by + have hct : Continuous (fun z => kernelFeature K (p.1,p.2+z)) := by + apply continuous_kernelFeature_comp + change Continuous (fun z : ℝ × ℝ => κ p.1 p.1 ((p.2+z.1)-(p.2+z.2))) + exact (hc _ _).comp (by fun_prop) + apply Integrable.of_bound hct.aestronglyMeasurable (sqrt (κ p.1 p.1 0)) + filter_upwards [] with z + have hn := norm_kernelFeature_sq K (p.1,p.2+z) + simp only [K,sub_self] at hn + have hp : 0≤κ p.1 p.1 0 := by simpa only [sub_self] using hκ.diag_nonneg (i := p) + exact (le_sqrt (norm_nonneg _) hp).mpr hn.le + have hh := posSemidef_kernel_variable_average K (fun p : A × ℝ => gaussianReal 0 (s p.1)) + (fun p z => (p.1,p.2+z)) hi + apply (congrArg Matrix.PosSemidef (show (fun p q : A × ℝ => + ∫ z,∫ w,K (p.1,p.2+z) (q.1,q.2+w) ∂gaussianReal 0 (s q.1) ∂gaussianReal 0 (s p.1))= + (fun p q : A × ℝ => heat (s p.1+s q.1) (κ p.1 q.1) (p.2-q.2)) from ?_)).mp hh + funext p q + rw [←gaussian_double_difference_general (hc _ _) (stationary_kernel_bounded κ hκ _ _) (s p.1) (s q.1)] + congr 1 + funext z + congr 1 + funext w + dsimp only [K] + congr 1 + ring + +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def conjugateMeasure (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) (c : BoundedCoefficient β) + (hβ : 0<β) (t : Time) : Measure ℝ := + (P.map (fun ω => solution (c.driftData hβ) (brownianPath W ω) t)).withDensity + (fun x => ENNReal.ofReal (exp (-(c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x))) + +lemma integral_conjugateMeasure (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) {f : ℝ → ℝ} (hf : StronglyMeasurable f) : + (∫ x,f x ∂conjugateMeasure P W c hβ t)= + ∫ ω,exp (-(c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ + (solution (c.driftData hβ) (brownianPath W ω) t))* + f (solution (c.driftData hβ) (brownianPath W ω) t) ∂P := by + have he : Continuous (fun x => exp (-(c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)) := + (continuous_const.mul (field_lipschitz β hβ c.mono c.bound _).continuous).rexp + rw [conjugateMeasure,integral_withDensity_eq_integral_toReal_smul he.measurable.ennreal_ofReal + (ae_of_all _ fun x => ENNReal.ofReal_lt_top)] + simp only [ENNReal.toReal_ofReal (exp_pos _).le,smul_eq_mul] + exact integral_map (aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) t) + (he.stronglyMeasurable.mul hf).aestronglyMeasurable + +lemma conjugateMeasure_finite (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) (ha : 0 exp (-(c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)) := + (continuous_const.mul (field_lipschitz β hβ c.mono c.bound _).continuous).rexp + exact isFiniteMeasure_withDensity_ofReal (Integrable.of_bound hc.aestronglyMeasurable _ + (ae_of_all _ hp.norm_le)).hasFiniteIntegral + +lemma conjugateMeasure_positive (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) (ht0 : 0<(t:ℝ)) + (ha : 0 (r : ℝ)) he; exact ht0.ne' hv) + (by exact_mod_cast t.property.2) ha hψ hψc + +lemma conjugateMeasure_firstMoment (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) (t : Time) (ha : 0 |x|) (conjugateMeasure P W c hβ t) := by + have he : Continuous (fun x => exp (-(c.val ⟨t,t.property.1⟩:ℝ)*field β c.val ⟨t,t.property.1⟩ x)) := + (continuous_const.mul (field_lipschitz β hβ c.mono c.bound _).continuous).rexp + have hp := (field_coshCone β hβ c.mono c.bound ⟨t,t.property.1⟩ (by exact_mod_cast ha) le_rfl).neg_exp_positiveDefinite + (by exact_mod_cast ha) (c.val ⟨t,t.property.1⟩).coe_nonneg + rw [conjugateMeasure,integrable_withDensity_iff_integrable_smul' he.measurable.ennreal_ofReal + (ae_of_all _ fun x => ENNReal.ofReal_lt_top)] + simp only [ENNReal.toReal_ofReal (exp_pos _).le,smul_eq_mul] + have hi : Integrable (fun x : ℝ => |x|) + (P.map (fun ω => solution (c.driftData hβ) (brownianPath W ω) t)) := + (integrable_map_measure continuous_abs.aestronglyMeasurable + (aemeasurable_solution_eval _ _ (brownianPath_aemeasurable_eval hW) t)).mpr + (brownian_solution_integrable hW _ t).abs + exact hi.bdd_mul he.aestronglyMeasurable (ae_of_all _ hp.norm_le) + +end ParisiFinite.BoundedCoefficient + + + + + +open MeasureTheory ProbabilityTheory Set Real Matrix Filter InnerProductSpace +open scoped Topology NNReal RealInnerProductSpace BigOperators +namespace ParisiSpectral +lemma continuous_heat {f : ℝ → ℝ} (hc : Continuous f) {C : ℝ} + (hC : ∀ x, ‖f x‖≤C) (t : ℝ≥0) : Continuous (heat t f) := by + apply continuous_of_dominated (bound := fun _ => C) + (fun x => (hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable) + (fun x => ae_of_all _ fun z => hC _) (integrable_const _) + (ae_of_all _ fun z => hc.comp (continuous_id.add continuous_const)) + +lemma heat_heat {f : ℝ → ℝ} (hc : Continuous f) {C : ℝ} + (hC : ∀ x, ‖f x‖≤C) (s t : ℝ≥0) : heat s (heat t f)=heat (s+t) f := by + funext x + have hh := gaussian_double_difference_general hc hC s t x + have he (z : ℝ) : (∫ w,f (x+z-w) ∂gaussianReal 0 t)=heat t f (x+z) := by + have hh := integral_map (μ := gaussianReal 0 t) (f := fun w => f (x+z+w)) measurable_neg.aemeasurable + ((hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable) + rw [gaussianReal_map_neg,neg_zero] at hh + simpa only [heat,sub_eq_add_neg] using hh.symm + simpa only [he,heat] using hh + +lemma PositiveDefinite.sub_heat {f : ℝ → ℝ} (hf : PositiveDefinite f) + (hc : Continuous f) (t : ℝ≥0) : PositiveDefinite (fun x => f x-ParisiSpectral.heat t f x) := by + let K : Matrix ℝ ℝ ℝ := fun x y => f (x-y) + let : Fact K.PosSemidef := ⟨hf⟩ + have hp (z : ℝ) : Matrix.PosSemidef (fun x y : ℝ => + 2*f (x-y)-f (x-y+z)-f (x-y-z)) := by + have hh := posSemidef_inner (fun x => kernelFeature K x-kernelFeature K (x+z)) + have he : (fun x y : ℝ => 2*f (x-y)-f (x-y+z)-f (x-y-z)) = + (fun x y : ℝ => ⟪kernelFeature K x-kernelFeature K (x+z),kernelFeature K y-kernelFeature K (y+z)⟫_ℝ) := by + funext x y + simp only [inner_sub_left,inner_sub_right,inner_kernelFeature] + dsimp only [K] + rw [show x-(y+z)=x-y-z by ring,show x+z-y=x-y+z by ring, + show x+z-(y+z)=x-y by ring] + ring + rw [he] + exact hh + have hi (x y : ℝ) : Integrable (fun z => 2*f (x-y)-f (x-y+z)-f (x-y-z)) (gaussianReal 0 t) := by + exact ((integrable_const _).sub (Integrable.of_bound + (hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable _ (ae_of_all _ fun z => hf.norm_le _))).sub + (Integrable.of_bound (hc.comp (continuous_const.sub continuous_id)).aestronglyMeasurable _ + (ae_of_all _ fun z => hf.norm_le _)) + have hh := posSemidef_integral (gaussianReal 0 t) (fun z x y => 2*f (x-y)-f (x-y+z)-f (x-y-z)) + (ae_of_all _ hp) hi + have hv (x : ℝ) : (∫ z,f (x-z) ∂gaussianReal 0 t) = ParisiSpectral.heat t f x := by + have h := integral_map (μ := gaussianReal 0 t) (f := fun z => f (x+z)) measurable_neg.aemeasurable + (hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable + rw [gaussianReal_map_neg,neg_zero] at h + simpa only [ParisiSpectral.heat,sub_eq_add_neg] using h.symm + have he (x y : ℝ) : (∫ z,2*f (x-y)-f (x-y+z)-f (x-y-z) ∂gaussianReal 0 t)= + 2*(f (x-y)-ParisiSpectral.heat t f (x-y)) := by + have hi1 : Integrable (fun z => f (x-y+z)) (gaussianReal 0 t) := + Integrable.of_bound (hc.comp (continuous_const.add continuous_id)).aestronglyMeasurable _ + (ae_of_all _ fun z => hf.norm_le _) + have hi2 : Integrable (fun z => f (x-y-z)) (gaussianReal 0 t) := + Integrable.of_bound (hc.comp (continuous_const.sub continuous_id)).aestronglyMeasurable _ + (ae_of_all _ fun z => hf.norm_le _) + rw [integral_sub (f := fun z => 2*f (x-y)-f (x-y+z)) + (g := fun z => f (x-y-z)) ((integrable_const (2*f (x-y))).sub hi1) hi2, + integral_sub (integrable_const (2*f (x-y))) hi1,hv] + simp only [integral_const,probReal_univ,one_smul,ParisiSpectral.heat] + ring + simp_rw [he] at hh + have hh' := hh.smul (show (0:ℝ)≤(1/2:ℝ) by norm_num) + have heq : Matrix.of (fun x y : ℝ => f (x-y)-ParisiSpectral.heat t f (x-y)) = + (1/2:ℝ) • Matrix.of (fun x y : ℝ => 2*(f (x-y)-ParisiSpectral.heat t f (x-y))) := by + ext x y + simp only [Matrix.smul_apply,Matrix.of_apply,smul_eq_mul] + ring + change (Matrix.of (fun x y : ℝ => f (x-y)-ParisiSpectral.heat t f (x-y))).PosSemidef + rw [heq] + exact hh' + +lemma PositiveOnPD.heat_le {μ : Measure ℝ} [IsFiniteMeasure μ] (hμ : PositiveOnPD μ) + {f : ℝ → ℝ} (hf : PositiveDefinite f) (hc : Continuous f) (t : ℝ≥0) : + (∫ x,heat t f x ∂μ)≤∫ x,f x ∂μ := by + have hp := hμ _ (hc.sub (continuous_heat hc hf.norm_le t)) (hf.sub_heat hc t) + have hi : Integrable f μ := Integrable.of_bound hc.aestronglyMeasurable _ (ae_of_all _ hf.norm_le) + have hi' : Integrable (heat t f) μ := Integrable.of_bound (continuous_heat hc hf.norm_le t).aestronglyMeasurable _ + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hf.heat_abs_le hc t x) + change 0≤∫ x,f x-heat t f x ∂μ at hp + rw [integral_sub hi hi'] at hp + linarith +end ParisiSpectral + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set Real +open scoped Topology NNReal +namespace ParisiFinite.BoundedCoefficient +open ParisiPath ParisiSpectral +variable {β : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma conjugateMeasure_plateau_integral (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) {a d α : ℝ≥0} (ha0 : a≠0) (had : a exp (-(α:ℝ)*field β c.val d x)) := + (continuous_const.mul (field_lipschitz β hβ c.mono c.bound d).continuous).rexp + let g : ℝ → ℝ := fun x => exp (-(α:ℝ)*field β c.val d x)*f x + have hgc : Continuous g := he.mul hfc + have hb (x : ℝ) : |g x|≤(‖exp (-(α:ℝ)*field β c.val d 0)‖₊*R:ℝ≥0) := by + have hh : |exp (-(α:ℝ)*field β c.val d x)|≤exp (-(α:ℝ)*field β c.val d 0) := hpd.norm_le x + have hm := mul_le_mul hh (hR x) (abs_nonneg (f x)) (exp_pos (-(α:ℝ)*field β c.val d 0)).le + simpa only [g,abs_mul,NNReal.coe_mul,coe_nnnorm,Real.norm_eq_abs,abs_of_pos (exp_pos _)] using hm + have ht := c.actual_plateau_transport hβ hW ha0 had hd1 hg hgc + (‖exp (-(α:ℝ)*field β c.val d 0)‖₊*R) hb + rw [c.integral_conjugateMeasure hβ hW _ hfc.stronglyMeasurable, + c.integral_conjugateMeasure hβ hW _ + (continuous_heat hfc (fun x => by simpa only [Real.norm_eq_abs] using hR x) (d-a)).stronglyMeasurable] + have heD : (⟨(⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩:Time),d.coe_nonneg⟩:ℝ≥0)=d := rfl + have heA : (⟨(⟨a,a.coe_nonneg,by exact_mod_cast had.le.trans hd1⟩:Time),a.coe_nonneg⟩:ℝ≥0)=a := rfl + simp only [heD,heA,hgd,hga] + rw [show (fun ω => exp (-(α:ℝ)*field β c.val d + (solution (c.driftData hβ) (brownianPath W ω) ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩))* + f (solution (c.driftData hβ) (brownianPath W ω) ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩))= + (fun ω => g (solution (c.driftData hβ) (brownianPath W ω) ⟨d,d.coe_nonneg,by exact_mod_cast hd1⟩)) from rfl,ht] + apply integral_congr_ae + filter_upwards [] with ω + let x : ℝ := solution (c.driftData hβ) (brownianPath W ω) + ⟨a,a.coe_nonneg,by exact_mod_cast had.le.trans hd1⟩ + have hh := conjugate_tiltedMean (field_lipschitz β hβ c.mono c.bound d) hgc 0 α (d-a) x + simp only [zero_mul,exp_zero,one_mul,sub_zero] at hh + rw [NNReal.coe_sub had.le] at hh + change tiltedMean (α:ℝ) (sqrt ((d:ℝ)-a)) (field β c.val d) g x = _ + rw [hh] + rw [field_on_plateau β hβ c.mono c.bound hd1 hg ⟨le_rfl,had⟩ x] + congr 1 + congr 1 + funext y + dsimp only [g] + rw [←mul_assoc,←exp_add] + simp only [show (α:ℝ)*field β c.val d y+ -(α:ℝ)*field β c.val d y=0 by ring,exp_zero,one_mul] + +lemma conjugateMeasure_plateau (c : BoundedCoefficient β) (hβ : 0<β) + (hW : IsBrownianReal W P) {a d α : ℝ≥0} (ha0 : a≠0) (had : a by simpa only [Real.norm_eq_abs,coe_nnnorm] using f.norm_coe_le_norm x) +end ParisiFinite.BoundedCoefficient + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/PartitionSite.lean b/lean/OAI/Probability/ParisiFinite/PartitionSite.lean new file mode 100644 index 0000000000000000000000000000000000000000..8cdf32ea3e8598af155dae42a4c2b89154ee0133 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/PartitionSite.lean @@ -0,0 +1,645 @@ +import Mathlib +import OAI.Probability.ParisiFinite.LogMean + +namespace OAI + +/-! Partition Site. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal Topology +namespace ParisiInterpolation +open SKGaussian SKQAOA ParisiFinite + +lemma partition_site (n : ℕ) (a : Fin n → ℝ) : + partition (fun σ : Configuration n => ∑ i, a i * spin σ i) = + ∏ i, (2 * Real.cosh (a i)) := by + classical + unfold partition spin + simp_rw [Real.exp_sum] + rw [← Fintype.prod_sum (fun i (b : Bool) => Real.exp (a i * (if b then -1 else 1)))] + apply Finset.prod_congr rfl + intro i _ + simp [Real.cosh_eq] + ring + +lemma logPartition_site (n : ℕ) (a : Fin n → ℝ) : + logPartition (fun σ : Configuration n => ∑ i, a i * spin σ i) = + ∑ i, Real.log (2 * Real.cosh (a i)) := by + rw [logPartition, partition_site] + exact Real.log_prod (fun _ _ => (mul_pos (by norm_num) (Real.cosh_pos _)).ne') + +lemma siteCoeff_field (n : ℕ) (β q : ℝ) (x : Fin n → ℝ) : + field (siteCoeff n β q) x = fun σ : Configuration n => ∑ i, (β * (Real.sqrt q * x i)) * spin σ i := by + funext σ + apply Finset.sum_congr rfl + intro i _ + dsimp [siteCoeff] + ring + +lemma logPartition_siteCoeff (n : ℕ) (β q : ℝ) (x : Fin n → ℝ) : + logPartition (field (siteCoeff n β q) x) = + ∑ i, Real.log (2 * Real.cosh (β * (Real.sqrt q * x i))) := by + rw [siteCoeff_field, logPartition_site] + +lemma log_cosh_integrable {β : ℝ} (hβ : 0 < β) (s : ℝ) : + Integrable (fun z => Real.log (2 * Real.cosh (β * (s * z)))) (gaussianReal 0 1) := by + have h := (integrable_shift (terminal_lipschitz hβ) 0 s).const_mul β + have he (z : ℝ) : β * terminal β (0 + s * z) = Real.log (2 * Real.cosh (β * (s * z))) := by + simp only [terminal, zero_add] + field_simp + simpa only [he] using h + +lemma expected_siteCoeff (n : ℕ) {β : ℝ} (hβ : 0 < β) (q : ℝ) : + expected (siteCoeff n β q) = + (n : ℝ) * ∫ z : ℝ, Real.log (2 * Real.cosh (β * (Real.sqrt q * z))) ∂gaussianReal 0 1 := by + have hi (i : Fin n) : Integrable (fun x : Fin n → ℝ => + Real.log (2 * Real.cosh (β * (Real.sqrt q * x i)))) (gaussianLaw (Fin n)) := + ((measurePreserving_eval (fun _ : Fin n => gaussianReal 0 1) i).integrable_comp + (log_cosh_integrable hβ (Real.sqrt q)).aestronglyMeasurable).mpr + (log_cosh_integrable hβ (Real.sqrt q)) + unfold expected + simp_rw [logPartition_siteCoeff] + rw [integral_finsetSum _ (fun i _ => hi i)] + have he (i : Fin n) : (∫ x : Fin n → ℝ, + Real.log (2 * Real.cosh (β * (Real.sqrt q * x i))) ∂gaussianLaw (Fin n)) = + ∫ z : ℝ, Real.log (2 * Real.cosh (β * (Real.sqrt q * z))) ∂gaussianReal 0 1 := by + have hm := measurePreserving_eval (fun _ : Fin n => gaussianReal 0 1) i + rw [← hm.map_eq] + exact (integral_map hm.measurable.aemeasurable + (hm.map_eq.symm ▸ (log_cosh_integrable hβ (Real.sqrt q)).aestronglyMeasurable)).symm + simp_rw [he] + simp + +lemma interpolatedPressure_zero (n : ℕ) {β : ℝ} (hβ : 0 < β) (q : ℝ) : + interpolatedPressure n β q 0 = + (n : ℝ) * ∫ z : ℝ, Real.log (2 * Real.cosh (β * (Real.sqrt q * z))) ∂gaussianReal 0 1 := by + unfold interpolatedPressure + have he : rotate (siteLift n β q) (skLift n β) 0 = siteLift n β q := by + funext σ k + simp [rotate] + rw [he] + unfold expected siteLift + rw [integral_field_inl] + exact expected_siteCoeff n hβ q + +lemma interpolatedPressure_pi_div_two (n : ℕ) (β q : ℝ) : + interpolatedPressure n β q (Real.pi / 2) = pressure β n := by + unfold interpolatedPressure + have he : rotate (siteLift n β q) (skLift n β) (Real.pi / 2) = skLift n β := by + funext σ k + simp [rotate] + rw [he] + unfold expected skLift + rw [integral_field_inr] + simp_rw [field_scale, field_skCoeff] + rfl + +end ParisiInterpolation + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal +namespace ParisiInterpolation +open SKGaussian SKQAOA ParisiFinite + +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +lemma norm_replicaAverage_le (A : ι → κ → ℝ) (K : ι → ι → ℝ) (x : κ → ℝ) : + ‖replicaAverage A K x‖ ≤ ∑ i, ∑ j, |K i j| := by + unfold replicaAverage + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro i _ + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro j _ + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg + (mul_nonneg (weight_pos _ _).le (weight_pos _ _).le)] + exact mul_le_of_le_one_left (abs_nonneg _) + ((mul_le_of_le_one_left (weight_pos _ _).le (weight_le_one _ _)).trans + (weight_le_one _ _)) + +lemma continuous_replicaMean_rotate (A B : ι → κ → ℝ) (K : ι → ι → ℝ) : + Continuous (fun t => replicaMean (rotate A B t) K) := by + apply continuous_of_dominated + (fun t => (integrable_replicaAverage (rotate A B t) K).aestronglyMeasurable) + (fun t => ae_of_all _ (norm_replicaAverage_le (rotate A B t) K)) + (integrable_const _) + exact ae_of_all _ fun x => by + unfold replicaAverage + apply continuous_finsetSum + intro i _ + apply continuous_finsetSum + intro j _ + have hf : Continuous (fun t => field (rotate A B t) x) := by + unfold field rotate + fun_prop + exact (((continuous_weight i).comp hf).mul ((continuous_weight j).comp hf)).mul_const _ + +lemma continuous_remainder (n : ℕ) (β q : ℝ) : Continuous (remainder n β q) := + continuous_replicaMean_rotate _ _ _ + + + +lemma hasDerivAt_correctedPressure {n : ℕ} (hn : 0 < n) (β : ℝ) {q : ℝ} (hq : 0 ≤ q) + (t : ℝ) : + HasDerivAt (fun s => interpolatedPressure n β q s - + β^2 * n / 4 * (Real.sin s)^2 * (1-q)^2) + (-(β^2 * n / 2) * (Real.sin t * Real.cos t * remainder n β q t)) t := by + have h := (hasDerivAt_interpolatedPressure hn β hq t).sub + (((Real.hasDerivAt_sin t).pow 2).const_mul (β^2 * n / 4) |>.mul_const ((1-q)^2)) + convert h using 1 + first | rfl | ring + + + +lemma pressure_sum_rule {n : ℕ} (hn : 0 < n) {β : ℝ} (hβ : 0 < β) {q : ℝ} (hq : 0 ≤ q) : + pressure β n = + (n : ℝ) * (∫ z : ℝ, Real.log (2 * Real.cosh (β * (Real.sqrt q * z))) ∂gaussianReal 0 1) + + β^2 * n / 4 * (1-q)^2 - β^2 * n / 2 * + ∫ t in (0 : ℝ)..(Real.pi/2), Real.sin t * Real.cos t * remainder n β q t := by + have h := intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun t _ => hasDerivAt_correctedPressure hn β hq t) + ((continuous_const.mul ((Real.continuous_sin.mul Real.continuous_cos).mul + (continuous_remainder n β q))).intervalIntegrable 0 (Real.pi/2)) + rw [intervalIntegral.integral_const_mul] at h + simp only [Real.sin_pi_div_two, one_pow, mul_one, Real.sin_zero, zero_pow (by norm_num : 2 ≠ 0), + mul_zero, interpolatedPressure_pi_div_two, interpolatedPressure_zero n hβ q] at h + linarith + +lemma integrated_remainder_nonneg (n : ℕ) (β q : ℝ) : + 0 ≤ ∫ t in (0 : ℝ)..(Real.pi/2), Real.sin t * Real.cos t * remainder n β q t := by + apply intervalIntegral.integral_nonneg (by positivity) + intro t ht + apply mul_nonneg + · apply mul_nonneg + · exact Real.sin_nonneg_of_nonneg_of_le_pi ht.1 (ht.2.trans (by linarith [Real.pi_pos])) + · exact Real.cos_nonneg_of_mem_Icc ⟨by linarith [Real.pi_pos, ht.1], ht.2⟩ + · exact remainder_nonneg n β q t + +lemma pressure_le_trial {n : ℕ} (hn : 0 < n) {β : ℝ} (hβ : 0 < β) {q : ℝ} (hq : 0 ≤ q) : + pressure β n ≤ + (n : ℝ) * (∫ z : ℝ, Real.log (2 * Real.cosh (β * (Real.sqrt q * z))) ∂gaussianReal 0 1) + + β^2 * n / 4 * (1-q)^2 := by + rw [pressure_sum_rule hn hβ hq] + exact sub_le_self _ (mul_nonneg (by positivity) (integrated_remainder_nonneg n β q)) + +end ParisiInterpolation + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal +namespace ParisiInterpolation +open SKGaussian SKQAOA ParisiFinite + + + +lemma freeEnergy_sum_rule {n : ℕ} (hn : 0 < n) {β : ℝ≥0} (hβ : 0 < β) + (q : ℝ≥0) (hq : q ≤ 1) : + freeEnergy β n = functional β (replicaSymmetricSchedule β q) - + (β : ℝ) / 2 * ∫ t in (0 : ℝ)..(Real.pi/2), + Real.sin t * Real.cos t * remainder n β q t := by + have hβ' : (0 : ℝ) < β := hβ + have hn' : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + rw [freeEnergy, pressure_sum_rule hn hβ' q.coe_nonneg, + replicaSymmetric_functional hβ q hq] + simp only [terminal, integral_div] + field_simp + +lemma freeEnergy_le_functional {n : ℕ} (hn : 0 < n) {β : ℝ≥0} (hβ : 0 < β) + (q : ℝ≥0) (hq : q ≤ 1) : + freeEnergy β n ≤ functional β (replicaSymmetricSchedule β q) := by + rw [freeEnergy_sum_rule hn hβ q hq] + exact sub_le_self _ (mul_nonneg (by positivity) (integrated_remainder_nonneg n β q)) + +lemma limitingFreeEnergy_le_functional {β : ℝ≥0} (hβ : 0 < β) + (q : ℝ≥0) (hq : q ≤ 1) : + limitingFreeEnergy β ≤ functional β (replicaSymmetricSchedule β q) := by + exact le_of_tendsto (tendsto_freeEnergy hβ) ((eventually_gt_atTop 0).mono fun n hn => + freeEnergy_le_functional hn hβ q hq) + +end ParisiInterpolation + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + + + +structure SmoothField where + val : ℝ → ℝ + d1 : ℝ → ℝ + d2 : ℝ → ℝ + hasD1 : ∀ x, HasDerivAt val (d1 x) x + hasD2 : ∀ x, HasDerivAt d1 (d2 x) x + continuousD2 : Continuous d2 + bound1 : ℝ≥0 + bound2 : ℝ≥0 + normD1 : ∀ x, |d1 x| ≤ bound1 + normD2 : ∀ x, |d2 x| ≤ bound2 + +namespace SmoothField + +lemma continuousVal (f : SmoothField) : Continuous f.val := + continuous_iff_continuousAt.mpr fun x => (f.hasD1 x).continuousAt + +lemma continuousD1 (f : SmoothField) : Continuous f.d1 := + continuous_iff_continuousAt.mpr fun x => (f.hasD2 x).continuousAt + +lemma lipschitz (f : SmoothField) : LipschitzWith f.bound1 f.val := by + apply lipschitzWith_of_nnnorm_deriv_le (fun x => (f.hasD1 x).differentiableAt) + intro x + rw [(f.hasD1 x).deriv] + exact_mod_cast f.normD1 x + +lemma lipschitzD1 (f : SmoothField) : LipschitzWith f.bound2 f.d1 := by + apply lipschitzWith_of_nnnorm_deriv_le (fun x => (f.hasD2 x).differentiableAt) + intro x + rw [(f.hasD2 x).deriv] + exact_mod_cast f.normD2 x + +end SmoothField + +lemma exp_shift_near_le {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a x₀ s : ℝ) {x : ℝ} (hx : |x-x₀| ≤ 1) (z : ℝ) : + Real.exp (a * f (x+s*z)) ≤ + Real.exp (|a| * (|f x₀| + L)) * Real.exp ((|a| * L * |s|) * |z|) := by + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have h := hf.dist_le_mul (x+s*z) (x₀+s*z) + simp only [Real.dist_eq, add_sub_add_right_eq_sub] at h + have hh : |f (x+s*z)| ≤ |f x₀| + L + (L : ℝ)*|s| * |z| := by + have ht := abs_add_le (f (x+s*z)-f (x₀+s*z)) (f (x₀+s*z)) + rw [sub_add_cancel] at ht + have hb := shift_norm_le hf x₀ s z + have hc := mul_le_mul_of_nonneg_left hx L.coe_nonneg + nlinarith + calc + a*f (x+s*z) ≤ |a*f (x+s*z)| := le_abs_self _ + _ = |a| * |f (x+s*z)| := abs_mul _ _ + _ ≤ |a| * (|f x₀|+L+(L:ℝ)*|s| * |z|) := mul_le_mul_of_nonneg_left hh (abs_nonneg _) + _ = |a| * (|f x₀|+L)+(|a| * L*|s|)*|z| := by ring + + +def expMoment (a s : ℝ) (f g : ℝ → ℝ) (x : ℝ) : ℝ := + ∫ z, Real.exp (a * f (x+s*z)) * g (x+s*z) ∂gaussianReal 0 1 + +lemma integrable_exp_weight {L : ℝ≥0} {f g : ℝ → ℝ} + (hf : LipschitzWith L f) (hg : Continuous g) {M : ℝ} (hb : ∀ x, |g x| ≤ M) + (a s x : ℝ) : + Integrable (fun z => Real.exp (a*f (x+s*z))*g (x+s*z)) (gaussianReal 0 1) := by + apply (integrable_exp_shift hf a x s).mul_bdd (by fun_prop) + exact ae_of_all _ fun z => by simpa only [Real.norm_eq_abs] using hb (x+s*z) + +lemma hasDerivAt_expMoment {L : ℝ≥0} {f f' g g' : ℝ → ℝ} + (hf : LipschitzWith L f) (hd : ∀ x, HasDerivAt f (f' x) x) + (hf' : Continuous f') (hb : ∀ x, |f' x| ≤ L) + (hg : ∀ x, HasDerivAt g (g' x) x) (hg' : Continuous g') + {M N : ℝ≥0} (hM : ∀ x, |g x| ≤ M) (hN : ∀ x, |g' x| ≤ N) + (a s x₀ : ℝ) : + HasDerivAt (expMoment a s f g) + (∫ z, Real.exp (a*f (x₀+s*z)) * + (a*f' (x₀+s*z)*g (x₀+s*z)+g' (x₀+s*z)) ∂gaussianReal 0 1) x₀ := by + have hfc := hf.continuous + have hgc : Continuous g := continuous_iff_continuousAt.mpr fun x => (hg x).continuousAt + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball x₀ 1) + (bound := fun z => (Real.exp (|a| * (|f x₀|+L)) * + Real.exp ((|a| * L*|s|)*|z|)) * (|a| * L*M+N)) + (F' := fun x z => Real.exp (a*f (x+s*z)) * (a*f' (x+s*z)*g (x+s*z)+g' (x+s*z))) + (Metric.ball_mem_nhds _ (by norm_num)) ?_ ?_ ?_ ?_ ?_ ?_).2 + · exact Eventually.of_forall fun x => by fun_prop + · exact integrable_exp_weight hf hgc hM a s x₀ + · fun_prop + · exact ae_of_all _ fun z x hx => by + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + apply mul_le_mul (exp_shift_near_le hf a x₀ s (by simpa [Real.dist_eq] using hx.le) z) + · apply (abs_add_le _ _).trans + rw [abs_mul, abs_mul] + exact add_le_add (mul_le_mul + (mul_le_mul_of_nonneg_left (hb _) (abs_nonneg a)) (hM _) + (abs_nonneg _) (by positivity)) (hN _) + · exact abs_nonneg _ + · positivity + · exact ((integrable_exp_abs _).const_mul _).mul_const _ + · exact ae_of_all _ fun z x _ => by + have hfz := (hd (x+s*z)).comp x ((hasDerivAt_id x).add_const (s*z)) + have hgz := (hg (x+s*z)).comp x ((hasDerivAt_id x).add_const (s*z)) + convert (hfz.const_mul a).exp.mul hgz using 1 <;> first | rfl | + (simp only [Function.comp_apply, id_eq, mul_one]; ring) + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + +def expMass (a s : ℝ) (f : ℝ → ℝ) (x : ℝ) : ℝ := + ∫ z, Real.exp (a * f (x+s*z)) ∂gaussianReal 0 1 + +def tiltedMean (a s : ℝ) (f g : ℝ → ℝ) (x : ℝ) : ℝ := + expMoment a s f g x / expMass a s f x + +lemma expMass_pos {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) (a s x : ℝ) : + 0 < expMass a s f x := integral_exp_pos (integrable_exp_shift hf a x s) + +@[simp] lemma tiltedMean_zero (s : ℝ) (f g : ℝ → ℝ) (x : ℝ) : + tiltedMean 0 s f g x = ∫ z, g (x+s*z) ∂gaussianReal 0 1 := by + simp [tiltedMean, expMass, expMoment] + +lemma abs_tiltedMean_le {L : ℝ≥0} {f g : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) {M : ℝ} (hM : ∀ x, |g x| ≤ M) (a s x : ℝ) : + |tiltedMean a s f g x| ≤ M := by + have hi := integrable_exp_weight hf hg hM a s x + have hp := expMass_pos hf a s x + unfold tiltedMean + rw [abs_div, abs_of_pos hp, div_le_iff₀ hp] + apply abs_integral_le_integral_abs.trans + have h := integral_mono hi.abs ((integrable_exp_shift hf a x s).const_mul M) + (fun z => by + rw [abs_mul, abs_of_pos (Real.exp_pos _), mul_comm M] + exact mul_le_mul_of_nonneg_left (hM _) (Real.exp_pos _).le) + simpa only [integral_const_mul, expMass] using h + +lemma hasDerivAt_expMass (f : SmoothField) (a s x : ℝ) : + HasDerivAt (expMass a s f.val) (a*expMoment a s f.val f.d1 x) x := by + have h := hasDerivAt_expMoment f.lipschitz f.hasD1 f.continuousD1 f.normD1 + (fun y => hasDerivAt_const y (1 : ℝ)) continuous_const + (M := 1) (N := 0) (by intro; norm_num) (by intro; norm_num) a s x + have he : expMoment a s f.val (fun _ => 1) = expMass a s f.val := by + funext y + simp [expMoment, expMass] + rw [he] at h + simpa only [one_mul, mul_one, add_zero, mul_left_comm _ a, integral_const_mul, expMoment] using h + +lemma hasDerivAt_gaussianAverage {L : ℝ≥0} {f f' : ℝ → ℝ} + (hf : LipschitzWith L f) (hd : ∀ x, HasDerivAt f (f' x) x) + (hf' : Continuous f') (hb : ∀ x, |f' x| ≤ L) (s x : ℝ) : + HasDerivAt (fun y => ∫ z, f (y+s*z) ∂gaussianReal 0 1) + (∫ z, f' (x+s*z) ∂gaussianReal 0 1) x := by + have hc := hf.continuous + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le (s := Set.univ) + (bound := fun _ => (L : ℝ)) (F' := fun y z => f' (y+s*z)) + univ_mem ?_ (integrable_shift hf x s) (by fun_prop) ?_ (integrable_const _) ?_).2 + · exact Eventually.of_forall fun _ => by fun_prop + · exact ae_of_all _ fun z y _ => by simpa only [Real.norm_eq_abs] using hb (y+s*z) + · exact ae_of_all _ fun z y _ => by + convert (hd (y+s*z)).comp y ((hasDerivAt_id y).add_const (s*z)) using 1 <;> + first | rfl | simp only [mul_one] + + + +lemma hasDerivAt_step (f : SmoothField) (a s x : ℝ) : + HasDerivAt (step a s f.val) (tiltedMean a s f.val f.d1 x) x := by + by_cases ha : a = 0 + · subst a + have hs : step 0 s f.val = fun y => ∫ z, f.val (y+s*z) ∂gaussianReal 0 1 := by + funext y + simp [step] + rw [hs, tiltedMean_zero] + exact hasDerivAt_gaussianAverage f.lipschitz f.hasD1 f.continuousD1 f.normD1 s x + · have h := ((hasDerivAt_expMass f a s x).log (expMass_pos f.lipschitz a s x).ne').div_const a + have he : (a*expMoment a s f.val f.d1 x / expMass a s f.val x) / a = + tiltedMean a s f.val f.d1 x := by unfold tiltedMean; field_simp + rw [he] at h + have hs : step a s f.val = fun y => Real.log (expMass a s f.val y) / a := by + funext y + simp [step, logMean, ha, expMass] + rw [hs] + exact h + +lemma expMoment_add {L : ℝ≥0} {f g h : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) (hh : Continuous h) {M N : ℝ} + (hM : ∀ x, |g x| ≤ M) (hN : ∀ x, |h x| ≤ N) (a s x : ℝ) : + expMoment a s f (fun y => g y+h y) x = expMoment a s f g x + expMoment a s f h x := by + simp only [expMoment, mul_add] + exact integral_add (integrable_exp_weight hf hg hM a s x) (integrable_exp_weight hf hh hN a s x) + +lemma expMoment_const_mul (a s : ℝ) (f g : ℝ → ℝ) (x c : ℝ) : + expMoment a s f (fun y => c*g y) x = c*expMoment a s f g x := by + simp only [expMoment, mul_left_comm _ c, integral_const_mul] + +lemma tiltedMean_add {L : ℝ≥0} {f g h : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) (hh : Continuous h) {M N : ℝ} + (hM : ∀ x, |g x| ≤ M) (hN : ∀ x, |h x| ≤ N) (a s x : ℝ) : + tiltedMean a s f (fun y => g y+h y) x = tiltedMean a s f g x + tiltedMean a s f h x := by + simp only [tiltedMean, expMoment_add hf hg hh hM hN, add_div] + +lemma tiltedMean_const_mul (a s : ℝ) (f g : ℝ → ℝ) (x c : ℝ) : + tiltedMean a s f (fun y => c*g y) x = c*tiltedMean a s f g x := by + simp only [tiltedMean, expMoment_const_mul, mul_div_assoc] + +lemma sq_bound {L : ℝ≥0} {g : ℝ → ℝ} (hg : ∀ x, |g x| ≤ L) (x : ℝ) : + |g x ^ 2| ≤ (L : ℝ)^2 := by + rw [abs_sq] + nlinarith [hg x, abs_nonneg (g x), sq_abs (g x)] + +lemma hasDerivAt_tiltedMean_d1 (f : SmoothField) (a s x : ℝ) : + HasDerivAt (tiltedMean a s f.val f.d1) + (tiltedMean a s f.val f.d2 x + a * + (tiltedMean a s f.val (fun y => f.d1 y ^ 2) x - (tiltedMean a s f.val f.d1 x)^2)) x := by + have h := hasDerivAt_expMoment f.lipschitz f.hasD1 f.continuousD1 f.normD1 + f.hasD2 f.continuousD2 f.normD1 f.normD2 a s x + have he (y : ℝ) : a*f.d1 y*f.d1 y+f.d2 y = f.d2 y+a*f.d1 y^2 := by ring + simp_rw [he] at h + change HasDerivAt (expMoment a s f.val f.d1) + (expMoment a s f.val (fun y => f.d2 y+a*f.d1 y^2) x) x at h + rw [expMoment_add (g := f.d2) (h := fun y => a*f.d1 y^2) f.lipschitz f.continuousD2 + (by have hc := f.continuousD1; fun_prop) f.normD2 + (fun y => by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (sq_bound f.normD1 y) (abs_nonneg a)), + expMoment_const_mul] at h + have hd := h.div (hasDerivAt_expMass f a s x) (expMass_pos f.lipschitz a s x).ne' + convert hd using 1 <;> first | rfl | (unfold tiltedMean; field_simp; ring) + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + +lemma continuous_expMoment {L : ℝ≥0} {f g : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) {M : ℝ≥0} (hM : ∀ x, |g x| ≤ M) (a s : ℝ) : + Continuous (expMoment a s f g) := by + have hfc := hf.continuous + apply continuous_iff_continuousAt.mpr + intro x₀ + apply continuousAt_of_dominated + (bound := fun z => (Real.exp (|a| * (|f x₀|+L)) * + Real.exp ((|a| * L * |s|)*|z|)) * M) + · exact Eventually.of_forall fun x => (integrable_exp_weight hf hg hM a s x).aestronglyMeasurable + · filter_upwards [Metric.ball_mem_nhds x₀ (by norm_num : (0 : ℝ) < 1)] with x hx + exact ae_of_all _ fun z => by + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + exact mul_le_mul (exp_shift_near_le hf a x₀ s (by simpa [Real.dist_eq] using hx.le) z) + (hM _) (abs_nonneg _) (by positivity) + · exact ((integrable_exp_abs _).const_mul _).mul_const _ + · exact ae_of_all _ fun z => by fun_prop + +lemma continuous_tiltedMean {L : ℝ≥0} {f g : ℝ → ℝ} (hf : LipschitzWith L f) + (hg : Continuous g) {M : ℝ≥0} (hM : ∀ x, |g x| ≤ M) (a s : ℝ) : + Continuous (tiltedMean a s f g) := by + have he : expMass a s f = expMoment a s f (fun _ => 1) := by + funext x + simp [expMass, expMoment] + have hc : Continuous (expMass a s f) := by + rw [he] + exact continuous_expMoment hf continuous_const (M := 1) (by intro; norm_num) a s + exact (continuous_expMoment hf hg hM a s).div hc (fun x => (expMass_pos hf a s x).ne') + +namespace SmoothField + + + +def transform (f : SmoothField) (a s : ℝ) : SmoothField where + val := step a s f.val + d1 := tiltedMean a s f.val f.d1 + d2 := fun x => tiltedMean a s f.val f.d2 x + a * + (tiltedMean a s f.val (fun y => f.d1 y^2) x - (tiltedMean a s f.val f.d1 x)^2) + hasD1 := hasDerivAt_step f a s + hasD2 := hasDerivAt_tiltedMean_d1 f a s + continuousD2 := by + have hc₁ := continuous_tiltedMean f.lipschitz f.continuousD1 f.normD1 a s + have hc₂ := continuous_tiltedMean f.lipschitz f.continuousD2 f.normD2 a s + have hcs := continuous_tiltedMean f.lipschitz (g := fun y => f.d1 y^2) + (by have hc := f.continuousD1; fun_prop) (M := f.bound1^2) (sq_bound f.normD1) a s + fun_prop + bound1 := f.bound1 + bound2 := f.bound2 + 2 * Real.nnabs a * f.bound1^2 + normD1 := abs_tiltedMean_le f.lipschitz f.continuousD1 f.normD1 a s + normD2 := by + intro x + have h1 := abs_tiltedMean_le f.lipschitz f.continuousD1 f.normD1 a s x + have h2 := abs_tiltedMean_le f.lipschitz f.continuousD2 f.normD2 a s x + have hs := abs_tiltedMean_le f.lipschitz (g := fun y => f.d1 y^2) + (by have hc := f.continuousD1; fun_prop) (sq_bound f.normD1) a s x + have hx : |(tiltedMean a s f.val f.d1 x)^2| ≤ (f.bound1:ℝ)^2 := + sq_bound (fun y => abs_tiltedMean_le f.lipschitz f.continuousD1 f.normD1 a s y) x + apply (abs_add_le _ _).trans + rw [abs_mul] + have hb : |tiltedMean a s f.val (fun y => f.d1 y^2) x - (tiltedMean a s f.val f.d1 x)^2| ≤ + |tiltedMean a s f.val (fun y => f.d1 y^2) x| + |(tiltedMean a s f.val f.d1 x)^2| := by + simpa only [sub_zero, zero_sub, abs_neg] using abs_sub_le (tiltedMean a s f.val (fun y => f.d1 y^2) x) 0 + ((tiltedMean a s f.val f.d1 x)^2) + simp only [NNReal.coe_add, NNReal.coe_mul, NNReal.coe_ofNat, Real.coe_nnabs, NNReal.coe_pow] + nlinarith [abs_nonneg a] + +end SmoothField + +lemma hasDerivAt_tanh_scaled (β x : ℝ) : + HasDerivAt (fun y => Real.tanh (β*y)) (β/(Real.cosh (β*x))^2) x := by + have hs := (Real.hasDerivAt_sinh (β*x)).comp x ((hasDerivAt_id x).const_mul β) + have hc := (Real.hasDerivAt_cosh (β*x)).comp x ((hasDerivAt_id x).const_mul β) + have h := hs.div hc (Real.cosh_pos (β*x)).ne' + simp only [Function.comp_apply, mul_one] at h + have he : (Real.cosh (β*x)*β*Real.cosh (β*x)-Real.sinh (β*x)*(Real.sinh (β*x)*β)) / + Real.cosh (β*x)^2 = β/Real.cosh (β*x)^2 := by + congr 1 + calc + _ = β*(Real.cosh (β*x)^2-Real.sinh (β*x)^2) := by ring + _ = β := by rw [Real.cosh_sq_sub_sinh_sq, mul_one] + rw [he] at h + have ht : (fun y => Real.tanh (β*y)) = + (fun y => Real.sinh (β*y)) / (fun y => Real.cosh (β*y)) := by + funext y + exact Real.tanh_eq_sinh_div_cosh _ + rw [ht] + exact h + + +def terminalField (β : ℝ≥0) (hβ : 0 < β) : SmoothField where + val := terminal β + d1 := fun x => Real.tanh (β*x) + d2 := fun x => (β : ℝ)/(Real.cosh (β*x))^2 + hasD1 := hasDerivAt_terminal hβ + hasD2 := hasDerivAt_tanh_scaled β + continuousD2 := continuous_const.div (by fun_prop) + (fun x => pow_ne_zero 2 (Real.cosh_pos ((β:ℝ)*x)).ne') + bound1 := 1 + bound2 := β + normD1 := fun x => (Real.abs_tanh_lt_one _).le + normD2 := by + intro x + rw [abs_of_nonneg (by positivity)] + apply div_le_self β.coe_nonneg + have hc := Real.one_le_cosh ((β:ℝ)*x) + nlinarith + + + +def smoothRecursion (β : ℝ≥0) (hβ : 0 < β) : Schedule → SmoothField + | [] => terminalField β hβ + | (a,d)::ls => (smoothRecursion β hβ ls).transform a (Real.sqrt d) + +lemma smoothRecursion_val (β : ℝ≥0) (hβ : 0 < β) (ls : Schedule) : + (smoothRecursion β hβ ls).val = recursion β ls := by + induction ls with + | nil => rfl + | cons l ls ih => + change step l.1 (Real.sqrt l.2) (smoothRecursion β hβ ls).val = _ + rw [ih] + rfl + +lemma smoothRecursion_bound1 (β : ℝ≥0) (hβ : 0 < β) (ls : Schedule) : + (smoothRecursion β hβ ls).bound1 = 1 := by + induction ls with + | nil => rfl + | cons l ls ih => exact ih + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/PhysicalGate.lean b/lean/OAI/Probability/ParisiFinite/PhysicalGate.lean new file mode 100644 index 0000000000000000000000000000000000000000..e33c13880ffc27c114fb2ac7897388b02ae78da0 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/PhysicalGate.lean @@ -0,0 +1,661 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Count + +namespace OAI + +/-! Physical Gate. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + + + +def physicalGate (n : ℕ) (J : Disorder n) : PointedTree.Gate → Operator n + | .cost t => evolution t (cost n J) + | .mixer t => evolution t (mixer n) + +def physicalWord (n : ℕ) (J : Disorder n) : List PointedTree.Gate → Operator n + | [] => 1 + | g :: w => physicalGate n J g * physicalWord n J w + +def gateGamma : PointedTree.Gate → ℝ + | .cost t => t + | .mixer _ => 0 + +def gateBeta : PointedTree.Gate → ℝ + | .cost _ => 0 + | .mixer t => t + + + +def wordGamma : (w : List PointedTree.Gate) → Fin w.length → ℝ + | [], i => Fin.elim0 i + | g :: w, i => Fin.lastCases (gateGamma g) (wordGamma w) i + +def wordBeta : (w : List PointedTree.Gate) → Fin w.length → ℝ + | [], i => Fin.elim0 i + | g :: w, i => Fin.lastCases (gateBeta g) (wordBeta w) i + +@[simp] theorem physicalWord_nil (n : ℕ) (J : Disorder n) : + physicalWord n J [] = 1 := rfl + +@[simp] theorem physicalWord_cons (n : ℕ) (J : Disorder n) + (g : PointedTree.Gate) (w : List PointedTree.Gate) : + physicalWord n J (g :: w) = physicalGate n J g * physicalWord n J w := rfl + + +theorem physicalWord_eq_circuit (w : List PointedTree.Gate) (n : ℕ) (J : Disorder n) : + physicalWord n J w = circuit J w.length (wordGamma w) (wordBeta w) := by + induction w with + | nil => rfl + | cons g w ih => + cases g <;> simp [physicalWord, physicalGate, circuit, wordGamma, wordBeta, + gateGamma, gateBeta, ih] + +@[simp] theorem physicalWord_append (n : ℕ) (J : Disorder n) + (w v : List PointedTree.Gate) : + physicalWord n J (w ++ v) = physicalWord n J w * physicalWord n J v := by + induction w with + | nil => simp + | cons g w ih => simp [ih, mul_assoc] + +theorem physicalGate_unitary (n : ℕ) (J : Disorder n) (g : PointedTree.Gate) : + physicalGate n J g ∈ unitary (Operator n) := by + cases g with + | mixer t => exact evolution_unitary t _ (mixer_hermitian n) + | cost t => exact evolution_unitary t _ (cost_hermitian n J) + +theorem physicalWord_unitary (n : ℕ) (J : Disorder n) (w : List PointedTree.Gate) : + physicalWord n J w ∈ unitary (Operator n) := by + rw [physicalWord_eq_circuit] + exact circuit_unitary J _ _ _ + + +def inverseGate : PointedTree.Gate → PointedTree.Gate + | .cost t => .cost (-t) + | .mixer t => .mixer (-t) + +def inverseWord (w : List PointedTree.Gate) : List PointedTree.Gate := + w.reverse.map inverseGate + +@[simp] theorem evolution_neg_adjoint {n : ℕ} (A : Operator n) (hA : A.IsHermitian) + (t : ℝ) : evolution (-t) A = (evolution t A)ᴴ := by + unfold evolution + rw [← Matrix.exp_conjTranspose] + congr 1 + rw [Matrix.conjTranspose_smul, hA] + simp [star_mul, mul_comm] + +@[simp] theorem physicalGate_inverse (n : ℕ) (J : Disorder n) (g : PointedTree.Gate) : + physicalGate n J (inverseGate g) = (physicalGate n J g)ᴴ := by + cases g with + | mixer t => exact evolution_neg_adjoint _ (mixer_hermitian n) t + | cost t => exact evolution_neg_adjoint _ (cost_hermitian n J) t + +@[simp] theorem physicalWord_inverse (n : ℕ) (J : Disorder n) (w : List PointedTree.Gate) : + physicalWord n J (inverseWord w) = (physicalWord n J w)ᴴ := by + induction w with + | nil => simp [inverseWord] + | cons g w ih => + simp only [inverseWord, List.reverse_cons, List.map_append, List.map_cons, + List.map_nil, physicalWord_append, physicalWord_cons, physicalWord_nil, + mul_one, physicalGate_inverse, Matrix.conjTranspose_mul] + rw [← ih] + rfl + + +def wordExpectedEnergy (n : ℕ) (w : List PointedTree.Gate) : ℝ := + ∫ J, (quad ((physicalWord n J w).mulVec (plus n)) (cost n J)).re / (n : ℝ) + ∂disorderLaw n + +theorem wordExpectedEnergy_eq (n : ℕ) (w : List PointedTree.Gate) : + wordExpectedEnergy n w = expectedEnergy n w.length (wordGamma w) (wordBeta w) := by + simp only [wordExpectedEnergy, physicalWord_eq_circuit, expectedEnergy, energyDensity, + qaoaState, quad, dotProduct, Pi.star_apply] + + + +theorem finite_word_realizable (w : List PointedTree.Gate) : + ∃ (p : ℕ) (γ β : Fin p → ℝ), + (∀ (n : ℕ) (J : Disorder n), physicalWord n J w = circuit J p γ β) ∧ + ∀ n : ℕ, wordExpectedEnergy n w = expectedEnergy n p γ β := by + exact ⟨w.length, wordGamma w, wordBeta w, physicalWord_eq_circuit w, + fun n => wordExpectedEnergy_eq n w⟩ + +end SKQAOA + + + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + + +def mixerPhase (n : ℕ) (t : ℝ) : ℂ := + ((Real.cos t : ℂ) - (Real.sin t : ℂ) * Complex.I)^n + +@[simp] theorem star_mixerPhase_mul (n : ℕ) (t : ℝ) : + star (mixerPhase n t) * mixerPhase n t = 1 := by + unfold mixerPhase + rw [star_pow, ← mul_pow] + have h : star ((Real.cos t : ℂ) - (Real.sin t : ℂ) * Complex.I) * + ((Real.cos t : ℂ) - (Real.sin t : ℂ) * Complex.I) = 1 := by + simp only [star_sub, star_mul, Complex.star_def, Complex.conj_ofReal, Complex.conj_I] + calc + _ = (((Real.cos t)^2 + (Real.sin t)^2 : ℝ) : ℂ) := by + simp only [Complex.ofReal_add, Complex.ofReal_pow] + linear_combination -(Real.sin t : ℂ)^2 * Complex.I_sq + _ = 1 := by rw [Real.cos_sq_add_sin_sq]; norm_num + rw [h, one_pow] + +theorem mixer_evolution_plus (n : ℕ) (t : ℝ) : + (evolution t (mixer n)).mulVec (plus n) = mixerPhase n t • plus n := by + funext σ + simp only [Matrix.mulVec, dotProduct, plus, mixer_evolution_apply, + ← Finset.sum_mul, Pi.smul_apply, smul_eq_mul] + congr 1 + rw [← Fintype.prod_sum (fun (i : Fin n) (b : Bool) => + if σ i = b then (Real.cos t : ℂ) else -(Real.sin t : ℂ) * Complex.I)] + have h (i : Fin n) : + (∑ b : Bool, if σ i = b then (Real.cos t : ℂ) else -(Real.sin t : ℂ) * Complex.I) = + (Real.cos t : ℂ) - (Real.sin t : ℂ) * Complex.I := by + cases σ i <;> simp [sub_eq_add_neg, add_comm] + simp_rw [h] + simp [mixerPhase] + + +theorem quad_phase {n : ℕ} (ψ : State n) (A : Operator n) (z : ℂ) + (hz : star z * z = 1) : quad (z • ψ) A = quad ψ A := by + simp only [quad, Matrix.mulVec_smul, star_smul, smul_dotProduct, + dotProduct_smul, smul_eq_mul] + rw [← mul_assoc, mul_comm z (star z), hz, one_mul] + +theorem cost_evolution_preserves_quad (n : ℕ) (J : Disorder n) (t : ℝ) (ψ : State n) : + quad ((evolution t (cost n J)).mulVec ψ) (cost n J) = quad ψ (cost n J) := by + rw [quad_mulVec] + have hc : cost n J * evolution t (cost n J) = evolution t (cost n J) * cost n J := by + rw [cost_evolution_eq_diagonal, cost_eq_diagonal] + simp only [Matrix.diagonal_mul_diagonal] + congr 1 + funext σ + exact mul_comm _ _ + have hu : (evolution t (cost n J))ᴴ * evolution t (cost n J) = 1 := + (Unitary.mem_iff.mp (evolution_unitary t _ (cost_hermitian n J))).1 + rw [mul_assoc, hc, ← mul_assoc, hu, one_mul] + + +def commutatorWord (t : ℝ) : List PointedTree.Gate := + [.cost t, .mixer t, .cost (-t), .mixer (-t)] + + + +theorem commutator_quad (n : ℕ) (J : Disorder n) (t : ℝ) : + quad ((physicalWord n J (commutatorWord t)).mulVec (plus n)) (cost n J) = + quad (qaoaState n 1 J (fun _ => -t) (fun _ => t)) (cost n J) := by + simp only [commutatorWord, physicalWord_cons, physicalWord_nil, physicalGate, mul_one, + ← Matrix.mulVec_mulVec] + rw [cost_evolution_preserves_quad, mixer_evolution_plus] + simp only [Matrix.mulVec_smul] + rw [quad_phase _ _ _ (star_mixerPhase_mul n (-t))] + rw [qaoaState_one] + rfl + + +theorem commutator_expectedEnergy (n : ℕ) (t : ℝ) : + wordExpectedEnergy n (commutatorWord t) = + -t * ((n : ℝ)-1)/(n : ℝ) * Real.sin (4*t) * + Real.exp (-2*t^2*((n : ℝ)-1)/(n : ℝ)) := by + have h : wordExpectedEnergy n (commutatorWord t) = + expectedEnergy n 1 (fun _ => -t) (fun _ => t) := by + unfold wordExpectedEnergy expectedEnergy energyDensity + apply integral_congr_ae + filter_upwards [] with J + rw [commutator_quad] + rfl + rw [h, expectedEnergy_one] + simp + + +def sizeCorrection (n : ℕ) : ℝ := ((n : ℝ)-1)/(n : ℝ) + +theorem sizeCorrection_mem (n : ℕ) : sizeCorrection n ∈ Set.Icc (0 : ℝ) 1 := by + rcases n with _ | n + · simp [sizeCorrection] + · have hn : 0 < (n+1 : ℝ) := by positivity + constructor + · unfold sizeCorrection + exact div_nonneg (by norm_num) (by positivity) + · unfold sizeCorrection + rw [div_le_one (by positivity)] + linarith + + + +theorem commutator_scalar_remainder (a t : ℝ) (ha : a ∈ Set.Icc (0 : ℝ) 1) : + |(-t*a*Real.sin (4*t)*Real.exp (-2*t^2*a)) + 4*a*t^2| ≤ 20*t^4 := by + have hexp : 0 < Real.exp (-2*t^2*a) := Real.exp_pos _ + have harg : -2*t^2*a ≤ 0 := by nlinarith [sq_nonneg t, ha.1] + have hle : Real.exp (-2*t^2*a) ≤ 1 := by + exact Real.exp_le_one_iff.mpr harg + have hlow := Real.add_one_le_exp (-2*t^2*a) + have hsin := Real.abs_sub_sin_le (4*t) + have hd : (-t*a*Real.sin (4*t)*Real.exp (-2*t^2*a)) + 4*a*t^2 = + t*a*((4*t-Real.sin (4*t))*Real.exp (-2*t^2*a) + + 4*t*(1-Real.exp (-2*t^2*a))) := by ring + rw [hd, abs_mul] + calc + _ ≤ |t*a| * (|(4*t-Real.sin (4*t))*Real.exp (-2*t^2*a)| + + |4*t*(1-Real.exp (-2*t^2*a))|) := + mul_le_mul_of_nonneg_left (abs_add_le _ _) (abs_nonneg _) + _ = |t| *a*(|4*t-Real.sin (4*t)| *Real.exp (-2*t^2*a) + + (4* |t|)*(1-Real.exp (-2*t^2*a))) := by + rw [abs_mul, abs_mul, abs_mul, abs_mul, abs_of_nonneg ha.1, + abs_of_pos hexp, abs_of_nonneg (by linarith : 0 ≤ 1-Real.exp (-2*t^2*a))] + norm_num + _ ≤ |t| *a*((|4*t|^3/6)*1 + (4* |t|)*(2*t^2*a)) := by + apply mul_le_mul_of_nonneg_left _ (mul_nonneg (abs_nonneg _) ha.1) + apply add_le_add + · exact mul_le_mul hsin hle hexp.le (by positivity) + · apply mul_le_mul_of_nonneg_left _ (by positivity) + linarith + _ ≤ 20*t^4 := by + rw [abs_mul] + norm_num + have hs : |t|^2 = t^2 := sq_abs t + have ht4 : |t|^4 = t^4 := by rw [show (4 : ℕ)=2*2 from rfl, pow_mul, hs, ← pow_mul] + have ha2 : a^2 ≤ 1 := by nlinarith [ha.1, ha.2] + have hh : 0 ≤ t^4 := by positivity + calc + _ = ((64/6 : ℝ)*a + 8*a^2)*t^4 := by + rw [← hs, ← ht4] + ring + _ ≤ 20*t^4 := by + apply mul_le_mul_of_nonneg_right _ hh + nlinarith [ha.2, ha2] + + +theorem commutator_uniform_energy_expansion (t : ℝ) (n : ℕ) : + |wordExpectedEnergy n (commutatorWord t) + 4*sizeCorrection n*t^2| ≤ 20*t^4 := by + rw [commutator_expectedEnergy] + have h := commutator_scalar_remainder (sizeCorrection n) t (sizeCorrection_mem n) + unfold sizeCorrection at h ⊢ + convert h using 1; congr 2; ring_nf + +end SKQAOA + + + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + +theorem wordExpectedEnergy_costMixer (n : ℕ) (γ β : ℝ) : + wordExpectedEnergy n [.mixer β, .cost γ] = + expectedEnergy n 1 (fun _ => γ) (fun _ => β) := by + unfold wordExpectedEnergy expectedEnergy energyDensity + apply integral_congr_ae + filter_upwards [] with J + simp only [physicalWord_cons, physicalWord_nil, physicalGate, mul_one, + ← Matrix.mulVec_mulVec, qaoaState_one, costState] + rfl + +@[simp] theorem wordExpectedEnergy_cost_only (n : ℕ) (γ : ℝ) : + wordExpectedEnergy n [.cost γ] = 0 := by + have h := wordExpectedEnergy_costMixer n γ 0 + have he : physicalWord n (by exact 0) [.cost γ] = + physicalWord n (by exact 0) [.mixer 0, .cost γ] := by simp [physicalGate] + have he' : wordExpectedEnergy n [.mixer 0, .cost γ] = + wordExpectedEnergy n [.cost γ] := by + simp only [wordExpectedEnergy, physicalWord_cons, physicalWord_nil, physicalGate, + evolution_zero, one_mul] + rw [he', expectedEnergy_one] at h + simpa using h + + + +theorem energy_only_not_a_congruence : + ∃ w v c : List PointedTree.Gate, + (∀ n : ℕ, wordExpectedEnergy n w = wordExpectedEnergy n v) ∧ + ∃ L : ℝ, 0 < L ∧ + Tendsto (fun n => wordExpectedEnergy n (c ++ w) - + wordExpectedEnergy n (c ++ v)) atTop (𝓝 L) := by + refine ⟨[.cost (1/2)], [.cost 0], [.mixer (Real.pi/8)], ?_, + Real.exp (-1/2)/2, div_pos (Real.exp_pos _) (by norm_num), ?_⟩ + · intro n + simp + · have hz (n : ℕ) : wordExpectedEnergy n [.mixer (Real.pi/8), .cost 0] = 0 := by + rw [wordExpectedEnergy_costMixer, expectedEnergy_one] + simp + have ht := tendsto_expectedEnergy_one (fun _ => (1/2 : ℝ)) (fun _ => Real.pi/8) + convert ht using 1 + · funext n + simp only [List.cons_append, List.nil_append, hz, sub_zero, + wordExpectedEnergy_costMixer] + · norm_num + rw [show 4*(Real.pi/8)=Real.pi/2 by ring, Real.sin_pi_div_two] + ring + +end SKQAOA + + + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + + + +theorem quad_mixer_pair {n : ℕ} (ψ : State n) (i j : Fin n) (t : ℝ) : + quad ((evolution t (mixer n)).mulVec ψ) (pauliZ i * pauliZ j) = + ((1 + Real.cos (4*t))/2 : ℝ) * quad ψ (pauliZ i * pauliZ j) + + ((1 - Real.cos (4*t))/2 : ℝ) * quad ψ (pauliY i * pauliY j) + + (Real.sin (4*t)/2 : ℝ) * + (quad ψ (pauliZ i * pauliY j) + quad ψ (pauliY i * pauliZ j)) := by + rw [quad_mulVec, conjugate_mul _ _ _ + (Unitary.mul_star_self_of_mem (evolution_unitary _ _ (mixer_hermitian n))), + mixer_conjugate_pauliZ, mixer_conjugate_pauliZ] + simp only [add_mul, mul_add, smul_mul_assoc, mul_smul_comm, quad_add, quad_smul] + have hcc : Real.cos (2*t)^2 = (1 + Real.cos (4*t))/2 := by + have h := Real.cos_two_mul (2*t) + have hs := Real.sin_sq_add_cos_sq (2*t) + rw [show 2*(2*t)=4*t by ring] at h + nlinarith + have hss : Real.sin (2*t)^2 = (1 - Real.cos (4*t))/2 := by + nlinarith [Real.sin_sq_add_cos_sq (2*t)] + have hsc : Real.sin (2*t)*Real.cos (2*t) = Real.sin (4*t)/2 := by + have h := Real.sin_two_mul (2*t) + rw [show 2*(2*t)=4*t by ring] at h + linarith + have hc : (Real.cos (2*t) : ℂ)^2 = (((1+Real.cos (4*t))/2 : ℝ) : ℂ) := by + exact_mod_cast hcc + have hs : (Real.sin (2*t) : ℂ)^2 = (((1-Real.cos (4*t))/2 : ℝ) : ℂ) := by + exact_mod_cast hss + have hcs : (Real.sin (2*t) : ℂ)*(Real.cos (2*t) : ℂ) = + ((Real.sin (4*t)/2 : ℝ) : ℂ) := by exact_mod_cast hsc + rw [←hc, ←hs, ←hcs] + ring + + + +theorem quad_mixer_pair_interpolation {n : ℕ} (ψ : State n) (i j : Fin n) (t : ℝ) : + quad ((evolution t (mixer n)).mulVec ψ) (pauliZ i * pauliZ j) = + ((1 + Real.cos (4*t) - Real.sin (4*t))/2 : ℝ) * + quad ψ (pauliZ i * pauliZ j) + + ((1 - Real.cos (4*t) - Real.sin (4*t))/2 : ℝ) * + quad ((evolution (Real.pi/4) (mixer n)).mulVec ψ) (pauliZ i * pauliZ j) + + (Real.sin (4*t) : ℂ) * + quad ((evolution (Real.pi/8) (mixer n)).mulVec ψ) (pauliZ i * pauliZ j) := by + simp only [quad_mixer_pair] + rw [show 4*(Real.pi/4)=Real.pi by ring, + show 4*(Real.pi/8)=Real.pi/2 by ring] + simp only [Real.sin_pi, Real.cos_pi, Real.sin_pi_div_two, Real.cos_pi_div_two] + push_cast + ring + + + +theorem quad_mixer_cost_interpolation {n : ℕ} (J : Disorder n) (ψ : State n) (t : ℝ) : + quad ((evolution t (mixer n)).mulVec ψ) (cost n J) = + ((1 + Real.cos (4*t) - Real.sin (4*t))/2 : ℝ) * quad ψ (cost n J) + + ((1 - Real.cos (4*t) - Real.sin (4*t))/2 : ℝ) * + quad ((evolution (Real.pi/4) (mixer n)).mulVec ψ) (cost n J) + + (Real.sin (4*t) : ℂ) * + quad ((evolution (Real.pi/8) (mixer n)).mulVec ψ) (cost n J) := by + simp only [quad_cost] + simp_rw [quad_mixer_pair_interpolation ψ _ _ t] + simp only [mul_add, Finset.sum_add_distrib, Finset.mul_sum] + simp only [mul_comm, mul_left_comm] + +theorem integrable_word_energy (n : ℕ) (w : List PointedTree.Gate) : + Integrable (fun J : Disorder n => + (quad ((physicalWord n J w).mulVec (plus n)) (cost n J)).re / (n : ℝ)) + (disorderLaw n) := by + simp only [physicalWord_eq_circuit] + exact energyDensity_integrable n w.length (wordGamma w) (wordBeta w) + +theorem wordExpectedEnergy_mixer_interpolation (n : ℕ) (w : List PointedTree.Gate) + (t : ℝ) : + wordExpectedEnergy n (.mixer t :: w) = + ((1 + Real.cos (4*t) - Real.sin (4*t))/2) * wordExpectedEnergy n w + + ((1 - Real.cos (4*t) - Real.sin (4*t))/2) * + wordExpectedEnergy n (.mixer (Real.pi/4) :: w) + + Real.sin (4*t) * wordExpectedEnergy n (.mixer (Real.pi/8) :: w) := by + have he (J : Disorder n) : + (quad ((physicalWord n J (.mixer t :: w)).mulVec (plus n)) (cost n J)).re / + (n : ℝ) = + ((1 + Real.cos (4*t) - Real.sin (4*t))/2) * + ((quad ((physicalWord n J w).mulVec (plus n)) (cost n J)).re / (n : ℝ)) + + ((1 - Real.cos (4*t) - Real.sin (4*t))/2) * + ((quad ((physicalWord n J (.mixer (Real.pi/4) :: w)).mulVec (plus n)) + (cost n J)).re / (n : ℝ)) + + Real.sin (4*t) * + ((quad ((physicalWord n J (.mixer (Real.pi/8) :: w)).mulVec (plus n)) + (cost n J)).re / (n : ℝ)) := by + simp only [physicalWord_cons, physicalGate, ←Matrix.mulVec_mulVec] + rw [quad_mixer_cost_interpolation J _ t] + simp only [Complex.add_re, Complex.mul_re, Complex.ofReal_re, + Complex.ofReal_im, zero_mul, sub_zero] + ring + simp only [wordExpectedEnergy] + simp_rw [he] + have ha := (integrable_word_energy n w).const_mul + ((1 + Real.cos (4*t) - Real.sin (4*t))/2) + have hb := (integrable_word_energy n (.mixer (Real.pi/4) :: w)).const_mul + ((1 - Real.cos (4*t) - Real.sin (4*t))/2) + have hc := (integrable_word_energy n (.mixer (Real.pi/8) :: w)).const_mul (Real.sin (4*t)) + have hadd := integral_add (ha.add hb) hc + simp only [Pi.add_apply] at hadd + rw [hadd, integral_add ha hb] + simp only [integral_const_mul] + + +theorem abs_wordExpectedEnergy_le (n : ℕ) (w : List PointedTree.Gate) : + |wordExpectedEnergy n w| ≤ expectedGround n := by + rw [wordExpectedEnergy_eq] + exact abs_expectedEnergy_le_expectedGround n _ _ _ + + + +theorem terminal_mixer_energy_lipschitz (n : ℕ) (w : List PointedTree.Gate) + (t s : ℝ) : + |wordExpectedEnergy n (.mixer t :: w) - wordExpectedEnergy n (.mixer s :: w)| ≤ + 12 * expectedGround n * |t-s| := by + let A := wordExpectedEnergy n w + let B := wordExpectedEnergy n (.mixer (Real.pi/4) :: w) + let D := wordExpectedEnergy n (.mixer (Real.pi/8) :: w) + have ha := abs_le.mp (abs_wordExpectedEnergy_le n w) + have hb := abs_le.mp (abs_wordExpectedEnergy_le n (.mixer (Real.pi/4) :: w)) + have hd := abs_le.mp (abs_wordExpectedEnergy_le n (.mixer (Real.pi/8) :: w)) + have hG : 0 ≤ expectedGround n := (abs_nonneg _).trans (abs_wordExpectedEnergy_le n w) + have hv : |(A-B)/2| ≤ expectedGround n := by + apply abs_le.mpr + dsimp [A,B] + constructor <;> linarith + have hz : |D-(A+B)/2| ≤ 2*expectedGround n := by + apply abs_le.mpr + dsimp [A,B,D] + constructor <;> linarith + have hdiff : + wordExpectedEnergy n (.mixer t :: w) - wordExpectedEnergy n (.mixer s :: w) = + ((A-B)/2)*(Real.cos (4*t)-Real.cos (4*s)) + + (D-(A+B)/2)*(Real.sin (4*t)-Real.sin (4*s)) := by + rw [wordExpectedEnergy_mixer_interpolation n w t, wordExpectedEnergy_mixer_interpolation n w s] + dsimp [A,B,D] + ring + have hcos : |Real.cos (4*t)-Real.cos (4*s)| ≤ 4*|t-s| := by + simpa only [←mul_sub, abs_mul, show |(4:ℝ)|=4 by norm_num] using Real.abs_cos_sub_cos_le (4*t) (4*s) + have hsin : |Real.sin (4*t)-Real.sin (4*s)| ≤ 4*|t-s| := by + simpa only [←mul_sub, abs_mul, show |(4:ℝ)|=4 by norm_num] using Real.abs_sin_sub_sin_le (4*t) (4*s) + rw [hdiff] + calc + _ ≤ |(A-B)/2*(Real.cos (4*t)-Real.cos (4*s))| + + |(D-(A+B)/2)*(Real.sin (4*t)-Real.sin (4*s))| := abs_add_le _ _ + _ = |(A-B)/2| * |Real.cos (4*t)-Real.cos (4*s)| + + |D-(A+B)/2| * |Real.sin (4*t)-Real.sin (4*s)| := by rw [abs_mul, abs_mul] + _ ≤ expectedGround n*(4*|t-s|) + (2*expectedGround n)*(4*|t-s|) := + add_le_add (mul_le_mul hv hcos (abs_nonneg _) hG) + (mul_le_mul hz hsin (abs_nonneg _) (by positivity)) + _ = 12*expectedGround n*|t-s| := by ring + +end SKQAOA + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA.Locality + + + +def IsSupported {n : ℕ} (S : Finset (Fin n)) (A : Operator n) : Prop := + ∀ i, i ∉ S → Commute A (pauliX i) ∧ Commute A (pauliZ i) + +variable {n : ℕ} {S T : Finset (Fin n)} {A B : Operator n} + +theorem IsSupported.mono (hA : IsSupported S A) (hST : S ⊆ T) : IsSupported T A := by + intro i hi + exact hA i (fun h => hi (hST h)) + +theorem supported_zero (S : Finset (Fin n)) : IsSupported S (0 : Operator n) := by + intro i hi + exact ⟨Commute.zero_left _,Commute.zero_left _⟩ + +theorem supported_one (S : Finset (Fin n)) : IsSupported S (1 : Operator n) := by + intro i hi + exact ⟨Commute.one_left _,Commute.one_left _⟩ + +theorem IsSupported.add (hA : IsSupported S A) (hB : IsSupported S B) : + IsSupported S (A+B) := by + intro i hi + exact ⟨(hA i hi).1.add_left (hB i hi).1,(hA i hi).2.add_left (hB i hi).2⟩ + +theorem IsSupported.mul (hA : IsSupported S A) (hB : IsSupported S B) : + IsSupported S (A*B) := by + intro i hi + exact ⟨(hA i hi).1.mul_left (hB i hi).1,(hA i hi).2.mul_left (hB i hi).2⟩ + +theorem IsSupported.smul (hA : IsSupported S A) (c : ℂ) : IsSupported S (c • A) := by + intro i hi + exact ⟨(hA i hi).1.smul_left c,(hA i hi).2.smul_left c⟩ + +theorem supported_atSite {i : Fin n} (hi : i ∈ S) (A : Matrix Bool Bool ℂ) : + IsSupported S (TensorMatrix.atSite i A) := by + intro j hj + have hij : i ≠ j := by rintro rfl; exact hj hi + rw [pauliX_eq_atSite,pauliZ_eq_atSite] + exact ⟨TensorMatrix.atSite_commute hij _ _,TensorMatrix.atSite_commute hij _ _⟩ + +theorem supported_pauliX {i : Fin n} (hi : i ∈ S) : IsSupported S (pauliX i) := by + rw [pauliX_eq_atSite] + exact supported_atSite hi _ + +theorem supported_pauliZ {i : Fin n} (hi : i ∈ S) : IsSupported S (pauliZ i) := by + rw [pauliZ_eq_atSite] + exact supported_atSite hi _ + +theorem pauliZ_hermitian (i : Fin n) : (pauliZ i).IsHermitian := by + apply Matrix.isHermitian_diagonal_iff.mpr + intro σ + exact Complex.conj_ofReal _ + +theorem IsSupported.adjoint (hA : IsSupported S A) : IsSupported S Aᴴ := by + intro i hi + have hx := (hA i hi).1.star_star + have hz := (hA i hi).2.star_star + have heX : (pauliX i)ᴴ=pauliX i := pauliX_hermitian i + have heZ : (pauliZ i)ᴴ=pauliZ i := pauliZ_hermitian i + simpa only [Matrix.star_eq_conjTranspose,heX,heZ] using And.intro hx hz + +theorem IsSupported.exp (hA : IsSupported S A) : IsSupported S (NormedSpace.exp A) := by + intro i hi + exact ⟨(hA i hi).1.exp_left,(hA i hi).2.exp_left⟩ + +theorem IsSupported.evolve (hA : IsSupported S A) (t : ℝ) : + IsSupported S (SKQAOA.evolution t A) := + (hA.smul _).exp + +theorem supported_finsetSum {ι : Type*} (s : Finset ι) (f : ι → Operator n) + (hf : ∀i∈s, IsSupported S (f i)) : IsSupported S (∑i∈s,f i) := by + classical + induction s using Finset.induction_on with + | empty => simpa using supported_zero S + | @insert a s ha ih => + rw [Finset.sum_insert ha] + exact (hf a (Finset.mem_insert_self a s)).add + (ih (fun i hi => hf i (Finset.mem_insert_of_mem hi))) + + +theorem commute_conjugate (U A B : Operator n) (hU : U ∈ unitary (Operator n)) + (h : Commute A (U*B*Uᴴ)) : Commute (Uᴴ*A*U) B := by + have hl : Uᴴ*U=1 := Unitary.star_mul_self_of_mem hU + have hr : U*Uᴴ=1 := Unitary.mul_star_self_of_mem hU + change (Uᴴ*A*U)*B=B*(Uᴴ*A*U) + calc + _ = Uᴴ*(A*(U*B*Uᴴ))*U := by + calc + _ = Uᴴ*A*U*B*(Uᴴ*U) := by rw [hl]; simp + _ = _ := by noncomm_ring + _ = Uᴴ*((U*B*Uᴴ)*A)*U := by rw [h.eq] + _ = (Uᴴ*U)*B*Uᴴ*A*U := by noncomm_ring + _ = _ := by rw [hl]; noncomm_ring + + +theorem IsSupported.mixer_conjugate (hA : IsSupported S A) (t : ℝ) : + IsSupported S ((evolution t (mixer n))ᴴ*A*evolution t (mixer n)) := by + intro i hi + have hX := (hA i hi).1 + have hZ := (hA i hi).2 + have hub := evolution_unitary t _ (mixer_hermitian n) + have hmix : Commute (mixer n) (pauliX i) := by + apply Commute.sum_left + intro j hj + by_cases hji : j=i + · subst j + exact Commute.refl _ + · rw [pauliX_eq_atSite,pauliX_eq_atSite] + exact TensorMatrix.atSite_commute hji _ _ + have huX : Commute (evolution t (mixer n)) (pauliX i) := + (hmix.smul_left _).exp_left + have hr : evolution t (mixer n)*(evolution t (mixer n))ᴴ=1 := + Unitary.mul_star_self_of_mem hub + have hx : evolution t (mixer n)*pauliX i*(evolution t (mixer n))ᴴ=pauliX i := by + rw [huX.eq,mul_assoc,hr,mul_one] + have hz : evolution t (mixer n)*pauliZ i*(evolution t (mixer n))ᴴ = + (Real.cos (2*(-t)) : ℂ) • pauliZ i + (Real.sin (2*(-t)) : ℂ) • pauliY i := by + have h := mixer_conjugate_pauliZ i (-t) + simpa only [evolution_neg_adjoint _ (mixer_hermitian n),Matrix.conjTranspose_conjTranspose] + using h + constructor + · apply commute_conjugate _ _ _ hub + rwa [hx] + · apply commute_conjugate _ _ _ hub + rw [hz,pauliY_eq] + exact (hZ.smul_right _).add_right (((hX.mul_right hZ).smul_right Complex.I).smul_right _) + +end SKQAOA.Locality + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/RealShiftNormSqLe.lean b/lean/OAI/Probability/ParisiFinite/RealShiftNormSqLe.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b882fb0ae673fd73d24b477d8ba234390728e78 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/RealShiftNormSqLe.lean @@ -0,0 +1,668 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ScalarPhase +import OAI.Probability.ParisiFinite.SumLeCode + +namespace OAI + +/-! Real Shift Norm Sq Le. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory Filter + +namespace GaussianCoherent +variable {κ : Type*} [Fintype κ] + +theorem realShift_norm_sq_le (v : Mode κ) : + ‖WithLp.toLp 2 (realShift v)‖^2≤4*‖v‖^2 := by + rw [PiLp.norm_sq_eq_of_L2,PiLp.norm_sq_eq_of_L2,Finset.mul_sum] + apply Finset.sum_le_sum + intro k hk + change ‖-2*(v k).im‖^2≤4*‖v k‖^2 + simp only [Real.norm_eq_abs,sq_abs] + have h := Complex.sq_norm_sub_sq_im (v k) + nlinarith [sq_nonneg (v k).re] + +namespace Quadratic +variable {ι : Type*} + +def packetConstant (R : ℝ) : ℝ := 8+32*R^2+64*R^4 + +theorem packetConstant_nonneg (R : ℝ) : 0≤packetConstant R := by + unfold packetConstant + positivity + + + +theorem coherent_error_sq_le_uniform (s : Finset ι) (d e : ι → RealMode κ) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) + (he : ∀i∈s,∀j∈s,i≠j → ⟪e i,e j⟫=0) (t R : ℝ) (hR : 0≤R) + (v : Mode κ) (hv : ‖v‖≤R) : + ‖unitary s d e t (CoherentFock.coherent v)-CoherentFock.coherent v‖^2≤ + t^2*ClassicalGaussian.Shifted.kernelSq (RealMode κ) s d e*packetConstant R := by + have hv2 := (sq_le_sq₀ (norm_nonneg v) hR).mpr hv + have hs := realShift_norm_sq_le v + have hs2 : ‖WithLp.toLp 2 (realShift v)‖^2≤4*R^2 := by nlinarith + have hs4 := pow_le_pow_left₀ (sq_nonneg ‖WithLp.toLp 2 (realShift v)‖) hs2 2 + have hp : 8+8*‖WithLp.toLp 2 (realShift v)‖^2+ + 4*‖WithLp.toLp 2 (realShift v)‖^4≤packetConstant R := by + unfold packetConstant + nlinarith + exact (coherent_error_sq_le s d e ho he t v).trans + (mul_le_mul_of_nonneg_left hp + (mul_nonneg (sq_nonneg t) (ClassicalGaussian.Shifted.kernelSq_nonneg _ s d e))) + + + +theorem packet_error_le {ρ : Type*} (s : Finset ι) (d e : ι → RealMode κ) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) + (he : ∀i∈s,∀j∈s,i≠j → ⟪e i,e j⟫=0) (t R : ℝ) (hR : 0≤R) + (u : Finset ρ) (c : ρ → ℂ) (v : ρ → Mode κ) (hv : ∀j∈u,‖v j‖≤R) : + ‖unitary s d e t (∑j∈u,c j • CoherentFock.coherent (v j))- + ∑j∈u,c j • CoherentFock.coherent (v j)‖≤ + (∑j∈u,‖c j‖)*Real.sqrt + (t^2*ClassicalGaussian.Shifted.kernelSq (RealMode κ) s d e*packetConstant R) := by + calc + _=‖∑j∈u,c j • (unitary s d e t (CoherentFock.coherent (v j))- + CoherentFock.coherent (v j))‖ := by + simp only [map_sum,map_smul,smul_sub,Finset.sum_sub_distrib] + _≤∑j∈u,‖c j‖*‖unitary s d e t (CoherentFock.coherent (v j))- + CoherentFock.coherent (v j)‖ := by + simpa only [norm_smul] using norm_sum_le u + (fun j=>c j • (unitary s d e t (CoherentFock.coherent (v j))-CoherentFock.coherent (v j))) + _≤∑j∈u,‖c j‖*Real.sqrt + (t^2*ClassicalGaussian.Shifted.kernelSq (RealMode κ) s d e*packetConstant R) := by + apply Finset.sum_le_sum + intro j hj + exact mul_le_mul_of_nonneg_left + (Real.le_sqrt_of_sq_le (coherent_error_sq_le_uniform s d e ho he t R hR (v j) (hv j hj))) + (norm_nonneg _) + _=_ := by rw [Finset.sum_mul] + +end Quadratic +end GaussianCoherent + + + +open scoped BigOperators Topology RealInnerProductSpace +open Filter + +namespace GaussianCoherent.Quadratic + + + +theorem varying_dimension_packet_limit + (κ ι ρ : ℕ → Type*) [∀n,Fintype (κ n)] + (s : ∀n,Finset (ι n)) (d e : ∀n,ι n → RealMode (κ n)) + (ho : ∀n,∀i∈s n,∀j∈s n,i≠j → ⟪d n i,d n j⟫=0 ∧ ⟪d n i,e n j⟫=0) + (he : ∀n,∀i∈s n,∀j∈s n,i≠j → ⟪e n i,e n j⟫=0) + (t R M : ℝ) (hR : 0≤R) + (u : ∀n,Finset (ρ n)) (c : ∀n,ρ n → ℂ) (v : ∀n,ρ n → Mode (κ n)) + (hv : ∀n,∀j∈u n,‖v n j‖≤R) (hc : ∀n,(∑j∈u n,‖c n j‖)≤M) + (hk : Tendsto (fun n=>ClassicalGaussian.Shifted.kernelSq (RealMode (κ n)) (s n) (d n) (e n)) + atTop (𝓝 0)) : + Tendsto (fun n=>‖unitary (s n) (d n) (e n) t + (∑j∈u n,c n j • CoherentFock.coherent (v n j))- + ∑j∈u n,c n j • CoherentFock.coherent (v n j)‖) atTop (𝓝 0) := by + have ht : Tendsto (fun n=>M*Real.sqrt + (t^2*ClassicalGaussian.Shifted.kernelSq (RealMode (κ n)) (s n) (d n) (e n)*packetConstant R)) + atTop (𝓝 0) := by + have h := ((hk.const_mul (t^2)).mul_const (packetConstant R)).sqrt.const_mul M + simpa only [mul_zero,zero_mul,Real.sqrt_zero] using h + apply squeeze_zero (fun n=>norm_nonneg _) _ ht + intro n + exact (packet_error_le (s n) (d n) (e n) (ho n) (he n) t R hR (u n) (c n) (v n) (hv n)).trans + (mul_le_mul_of_nonneg_right (hc n) (Real.sqrt_nonneg _)) + + + +theorem error_le_packet_error {κ ι : Type*} [Fintype κ] + (s : Finset ι) (d e : ι → RealMode κ) (t : ℝ) + (ψ φ : CoherentFock.Space (Mode κ)) : + ‖unitary s d e t ψ-ψ‖≤2*‖ψ-φ‖+‖unitary s d e t φ-φ‖ := by + calc + _=‖(unitary s d e t ψ-unitary s d e t φ)+(unitary s d e t φ-φ)+(φ-ψ)‖ := by + congr 1 + abel + _≤‖unitary s d e t ψ-unitary s d e t φ‖+‖unitary s d e t φ-φ‖+‖φ-ψ‖ := + (norm_add_le ((unitary s d e t ψ-unitary s d e t φ)+(unitary s d e t φ-φ)) (φ-ψ)).trans + (_root_.add_le_add (norm_add_le (unitary s d e t ψ-unitary s d e t φ) + (unitary s d e t φ-φ)) (le_refl ‖φ-ψ‖)) + _=2*‖ψ-φ‖+‖unitary s d e t φ-φ‖ := by + rw [←map_sub,(unitary s d e t).norm_map,norm_sub_rev φ ψ] + ring + +end GaussianCoherent.Quadratic + + + +open scoped BigOperators Topology RealInnerProductSpace +open Filter + +namespace ClassicalGaussian.Shifted +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +variable {ι : Type*} + + + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem kernelSq_le_mass_square (s : Finset ι) (d e : ι → E) (p : ι → ℝ) (C : ℝ) + (hd : ∀i∈s,‖d i‖^2≤C*p i) (he : ∀i∈s,‖e i‖^2≤C*p i) : + kernelSq E s d e≤C^2*∑i∈s,p i^2 := by + unfold kernelSq + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i hi + have h := mul_le_mul (hd i hi) (he i hi) (sq_nonneg ‖e i‖) + ((sq_nonneg ‖d i‖).trans (hd i hi)) + nlinarith + +theorem mass_square_le_max (s : Finset ι) (p : ι → ℝ) (δ : ℝ) (hδ : 0≤δ) + (hp : ∀i∈s,0≤p i) (hs : (∑i∈s,p i)≤1) (hm : ∀i∈s,p i≤δ) : + (∑i∈s,p i^2)≤δ := by + calc + _≤∑i∈s,δ*p i := Finset.sum_le_sum fun i hi=>by + simpa only [pow_two] using mul_le_mul_of_nonneg_right (hm i hi) (hp i hi) + _=δ*∑i∈s,p i := (Finset.mul_sum ..).symm + _≤δ := by simpa only [mul_one] using mul_le_mul_of_nonneg_left hs hδ + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem kernelSq_le_max_mass (s : Finset ι) (d e : ι → E) (p : ι → ℝ) (C δ : ℝ) + (hδ : 0≤δ) (hp : ∀i∈s,0≤p i) (hs : (∑i∈s,p i)≤1) (hm : ∀i∈s,p i≤δ) + (hd : ∀i∈s,‖d i‖^2≤C*p i) (he : ∀i∈s,‖e i‖^2≤C*p i) : + kernelSq E s d e≤C^2*δ := + (kernelSq_le_mass_square E s d e p C hd he).trans + (mul_le_mul_of_nonneg_left (mass_square_le_max s p δ hδ hp hs hm) (sq_nonneg C)) + +end ClassicalGaussian.Shifted + +namespace GaussianCoherent.Quadratic + + + +theorem sender_dilution_limit + (κ ι ρ : ℕ → Type*) [∀n,Fintype (κ n)] + (s : ∀n,Finset (ι n)) (d e : ∀n,ι n → RealMode (κ n)) + (p : ∀n,ι n → ℝ) (C : ℝ) (δ : ℕ → ℝ) + (hδ : ∀n,0≤δ n) (hp : ∀n,∀i∈s n,0≤p n i) + (hs : ∀n,(∑i∈s n,p n i)≤1) (hm : ∀n,∀i∈s n,p n i≤δ n) + (hd : ∀n,∀i∈s n,‖d n i‖^2≤C*p n i) (hde : ∀n,∀i∈s n,‖e n i‖^2≤C*p n i) + (ho : ∀n,∀i∈s n,∀j∈s n,i≠j → ⟪d n i,d n j⟫=0 ∧ ⟪d n i,e n j⟫=0) + (he : ∀n,∀i∈s n,∀j∈s n,i≠j → ⟪e n i,e n j⟫=0) + (t R M : ℝ) (hR : 0≤R) + (u : ∀n,Finset (ρ n)) (c : ∀n,ρ n → ℂ) (v : ∀n,ρ n → Mode (κ n)) + (hv : ∀n,∀j∈u n,‖v n j‖≤R) (hc : ∀n,(∑j∈u n,‖c n j‖)≤M) + (hlim : Tendsto δ atTop (𝓝 0)) : + Tendsto (fun n=>‖unitary (s n) (d n) (e n) t + (∑j∈u n,c n j • CoherentFock.coherent (v n j))- + ∑j∈u n,c n j • CoherentFock.coherent (v n j)‖) atTop (𝓝 0) := by + apply varying_dimension_packet_limit κ ι ρ s d e ho he t R M hR u c v hv hc + apply squeeze_zero (fun n=>ClassicalGaussian.Shifted.kernelSq_nonneg _ _ _ _) + (fun n=>ClassicalGaussian.Shifted.kernelSq_le_max_mass _ (s n) (d n) (e n) (p n) C (δ n) + (hδ n) (hp n) (hs n) (hm n) (hd n) (hde n)) + simpa only [mul_zero] using hlim.const_mul (C^2) + +end GaussianCoherent.Quadratic + + + +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + + + +def stateDistance {n : ℕ} (ψ φ : State n) : ℝ := Real.sqrt (mass (ψ-φ)) + +theorem normSq_sub_abs_le (z w : ℂ) : + |Complex.normSq z-Complex.normSq w| ≤ ‖z-w‖*(‖z‖+‖w‖) := by + rw [Complex.normSq_eq_norm_sq,Complex.normSq_eq_norm_sq, + show ‖z‖^2-‖w‖^2=(‖z‖-‖w‖)*(‖z‖+‖w‖) by ring,abs_mul, + abs_of_nonneg (add_nonneg (norm_nonneg _) (norm_nonneg _))] + exact mul_le_mul_of_nonneg_right (abs_norm_sub_norm_le z w) + (add_nonneg (norm_nonneg _) (norm_nonneg _)) + + + +theorem sum_abs_normSq_sub_le {n : ℕ} (ψ φ : State n) + (hψ : mass ψ=1) (hφ : mass φ=1) : + (∑σ,|Complex.normSq (ψ σ)-Complex.normSq (φ σ)|) ≤ 2*stateDistance ψ φ := by + have hm (v : State n) : (∑σ,‖v σ‖^2)=mass v := by + simp only [mass,Complex.normSq_eq_norm_sq] + calc + _ ≤ ∑σ,‖ψ σ-φ σ‖*(‖ψ σ‖+‖φ σ‖) := Finset.sum_le_sum fun σ _ => normSq_sub_abs_le _ _ + _=(∑σ,‖ψ σ-φ σ‖*‖ψ σ‖)+(∑σ,‖ψ σ-φ σ‖*‖φ σ‖) := by + simp only [mul_add,Finset.sum_add_distrib] + _ ≤ Real.sqrt (mass (ψ-φ))*Real.sqrt (mass ψ)+ + Real.sqrt (mass (ψ-φ))*Real.sqrt (mass φ) := by + apply add_le_add + · simpa only [←hm,Pi.sub_apply] using Real.sum_mul_le_sqrt_mul_sqrt Finset.univ + (fun σ=>‖ψ σ-φ σ‖) (fun σ=>‖ψ σ‖) + · simpa only [←hm,Pi.sub_apply] using Real.sum_mul_le_sqrt_mul_sqrt Finset.univ + (fun σ=>‖ψ σ-φ σ‖) (fun σ=>‖φ σ‖) + _=_ := by rw [hψ,hφ,Real.sqrt_one]; simp only [mul_one,stateDistance]; ring + + + +def spectralWidth (n : ℕ) (J : Disorder n) : ℝ := groundMaximum n J+groundMaximum n (-J) + +theorem spectralWidth_nonneg (n : ℕ) (J : Disorder n) : 0 ≤ spectralWidth n J := by + have h := hamiltonian_le_groundMaximum n J (fun _=>false) + have h' := hamiltonian_le_groundMaximum n (-J) (fun _=>false) + rw [hamiltonian_neg_disorder] at h' + dsimp [spectralWidth] + linarith + + +def stateEnergy (n : ℕ) (J : Disorder n) (ψ : State n) : ℝ := + (∑σ,Complex.normSq (ψ σ)*hamiltonian n J σ)/(n : ℝ) + +theorem stateEnergy_sub_bound (n : ℕ) (J : Disorder n) (ψ φ : State n) + (hψ : mass ψ=1) (hφ : mass φ=1) : + |stateEnergy n J ψ-stateEnergy n J φ| ≤ + 2*stateDistance ψ φ*(spectralWidth n J/(n : ℝ)) := by + have hz : (∑σ,(Complex.normSq (ψ σ)-Complex.normSq (φ σ)))=0 := by + rw [Finset.sum_sub_distrib] + change mass ψ-mass φ=0 + rw [hψ,hφ,sub_self] + have hb (σ : Configuration n) : + |hamiltonian n J σ+groundMaximum n (-J)| ≤ spectralWidth n J := by + have hn := hamiltonian_le_groundMaximum n (-J) σ + rw [hamiltonian_neg_disorder] at hn + rw [abs_of_nonneg (by linarith : 0 ≤ hamiltonian n J σ+groundMaximum n (-J))] + exact _root_.add_le_add (hamiltonian_le_groundMaximum n J σ) (le_refl (groundMaximum n (-J))) + have hs : (∑σ,Complex.normSq (ψ σ)*hamiltonian n J σ)- + (∑σ,Complex.normSq (φ σ)*hamiltonian n J σ)= + ∑σ,(Complex.normSq (ψ σ)-Complex.normSq (φ σ))* + (hamiltonian n J σ+groundMaximum n (-J)) := by + simp_rw [mul_add] + rw [Finset.sum_add_distrib, ←Finset.sum_mul, hz, zero_mul, add_zero] + simp only [sub_mul, Finset.sum_sub_distrib] + unfold stateEnergy + rw [←sub_div,abs_div,abs_of_nonneg (show (0:ℝ) ≤ (n:ℝ) from Nat.cast_nonneg n),hs] + calc + _ ≤ (∑σ,|(Complex.normSq (ψ σ)-Complex.normSq (φ σ))* + (hamiltonian n J σ+groundMaximum n (-J))|)/(n : ℝ) := + div_le_div_of_nonneg_right (Finset.abs_sum_le_sum_abs _ _) (Nat.cast_nonneg n) + _ ≤ ((∑σ,|Complex.normSq (ψ σ)-Complex.normSq (φ σ)|)*spectralWidth n J)/(n : ℝ) := by + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg n) + rw [Finset.sum_mul] + apply Finset.sum_le_sum + intro σ _ + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (hb σ) (abs_nonneg _) + _ ≤ (2*stateDistance ψ φ*spectralWidth n J)/(n : ℝ) := + div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_right (sum_abs_normSq_sub_le ψ φ hψ hφ) (spectralWidth_nonneg n J)) + (Nat.cast_nonneg n) + _=_ := by ring + +end SKQAOA + + + +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + +theorem spectralWidth_integrable (n : ℕ) : Integrable (spectralWidth n) (disorderLaw n) := + (groundMaximum_integrable n).add + ((disorder_neg_preserving n).integrable_comp_of_integrable (groundMaximum_integrable n)) + +theorem integral_spectralWidth_div (n : ℕ) : + (∫J : Disorder n,spectralWidth n J/(n : ℝ) ∂disorderLaw n)=2*expectedGround n := by + have hn : (∫J : Disorder n,groundMaximum n (-J) ∂disorderLaw n)= + ∫J : Disorder n,groundMaximum n J ∂disorderLaw n := + (disorder_neg_preserving n).integral_comp + (MeasurableEquiv.neg (Disorder n)).measurableEmbedding (groundMaximum n) + have hi : Integrable (fun J : Disorder n=>groundMaximum n (-J)) (disorderLaw n) := by + simpa only [Function.comp_def] using + (disorder_neg_preserving n).integrable_comp_of_integrable (groundMaximum_integrable n) + rw [integral_div] + unfold spectralWidth + rw [integral_add (groundMaximum_integrable n) hi,hn] + unfold expectedGround + ring + + + +theorem expectedEnergy_sub_bound_of_stateDistance (n p q : ℕ) + (γ β : Fin p → ℝ) (γ' β' : Fin q → ℝ) (δ : ℝ) + (hδ : ∀J : Disorder n,stateDistance (qaoaState n p J γ β) (qaoaState n q J γ' β') ≤ δ) : + |expectedEnergy n p γ β-expectedEnergy n q γ' β'| ≤ 4*δ*expectedGround n := by + have hi := (energyDensity_integrable n p γ β).sub (energyDensity_integrable n q γ' β') + have hb (J : Disorder n) : |energyDensity n p J γ β-energyDensity n q J γ' β'| ≤ + 2*δ*(spectralWidth n J/(n : ℝ)) := by + have h := stateEnergy_sub_bound n J (qaoaState n p J γ β) (qaoaState n q J γ' β') + (qaoaState_mass n p J γ β) (qaoaState_mass n q J γ' β') + rw [energyDensity_eq,energyDensity_eq] + exact h.trans (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_left (hδ J) (by norm_num)) + (div_nonneg (spectralWidth_nonneg n J) (Nat.cast_nonneg n))) + unfold expectedEnergy + rw [←integral_sub (energyDensity_integrable n p γ β) (energyDensity_integrable n q γ' β')] + calc + _ ≤ ∫J : Disorder n,|energyDensity n p J γ β-energyDensity n q J γ' β'| ∂disorderLaw n := + abs_integral_le_integral_abs + _ ≤ ∫J : Disorder n,2*δ*(spectralWidth n J/(n : ℝ)) ∂disorderLaw n := + integral_mono hi.abs (((spectralWidth_integrable n).div_const (n : ℝ)).const_mul (2*δ)) hb + _=4*δ*expectedGround n := by rw [integral_const_mul,integral_spectralWidth_div]; ring + + + +theorem value_sub_bound_of_stateDistance (p q : ℕ) + (γ β : Fin p → ℝ) (γ' β' : Fin q → ℝ) (δ : ℝ) + (hδ : ∀ᶠ n in atTop,∀J : Disorder n, + stateDistance (qaoaState n p J γ β) (qaoaState n q J γ' β') ≤ δ) : + |value p γ β-value q γ' β'| ≤ 4*δ*Pstar := by + apply le_of_tendsto_of_tendsto + ((tendsto_expectedEnergy_value p γ β).sub (tendsto_expectedEnergy_value q γ' β')).abs + (tendsto_expectedGround.const_mul (4*δ)) + filter_upwards [hδ] with n hn + exact expectedEnergy_sub_bound_of_stateDistance n p q γ β γ' β' δ hn + + + +theorem unitary_preserves_stateDistance {n : ℕ} {A : Operator n} + (hA : A ∈ unitary (Operator n)) (ψ φ : State n) : + stateDistance (A.mulVec ψ) (A.mulVec φ)=stateDistance ψ φ := by + unfold stateDistance + rw [←Matrix.mulVec_sub,unitary_preserves_mass hA] + +end SKQAOA + + + +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + +theorem stateDistance_nonneg {n : ℕ} (ψ φ : State n) : 0 ≤ stateDistance ψ φ := + Real.sqrt_nonneg _ + +theorem stateDistance_le_two {n : ℕ} (ψ φ : State n) + (hψ : mass ψ=1) (hφ : mass φ=1) : stateDistance ψ φ ≤ 2 := by + have hm : mass (ψ-φ) ≤ 4 := by + calc + _ ≤ ∑σ,(2*Complex.normSq (ψ σ)+2*Complex.normSq (φ σ)) := by + apply Finset.sum_le_sum + intro σ _ + rw [Pi.sub_apply,Complex.normSq_eq_norm_sq,Complex.normSq_eq_norm_sq,Complex.normSq_eq_norm_sq] + have h := norm_sub_le (ψ σ) (φ σ) + nlinarith [norm_nonneg (ψ σ-φ σ),norm_nonneg (ψ σ),norm_nonneg (φ σ), + sq_nonneg (‖ψ σ‖-‖φ σ‖)] + _=4 := by + rw [Finset.sum_add_distrib,←Finset.mul_sum,←Finset.mul_sum] + change 2*mass ψ+2*mass φ=4 + rw [hψ,hφ]; norm_num + exact Real.sqrt_le_iff.mpr ⟨by norm_num, by norm_num; exact hm⟩ + +theorem qaoaStateDistance_continuous (n p q : ℕ) (γ β : Fin p → ℝ) (γ' β' : Fin q → ℝ) : + Continuous (fun J : Disorder n=>stateDistance (qaoaState n p J γ β) (qaoaState n q J γ' β')) := by + apply Real.continuous_sqrt.comp + apply continuous_finsetSum + intro σ _ + exact Complex.continuous_normSq.comp + (((continuous_apply σ).comp (qaoaState_continuous n p γ β)).sub + ((continuous_apply σ).comp (qaoaState_continuous n q γ' β'))) + + + +def weightedStateError (n p q : ℕ) (γ β : Fin p → ℝ) (γ' β' : Fin q → ℝ) : ℝ := + ∫J : Disorder n,stateDistance (qaoaState n p J γ β) (qaoaState n q J γ' β')* + (spectralWidth n J/(n : ℝ)) ∂disorderLaw n + +theorem weightedStateError_integrable (n p q : ℕ) (γ β : Fin p → ℝ) (γ' β' : Fin q → ℝ) : + Integrable (fun J : Disorder n=>stateDistance (qaoaState n p J γ β) (qaoaState n q J γ' β')* + (spectralWidth n J/(n : ℝ))) (disorderLaw n) := by + apply (((spectralWidth_integrable n).div_const (n : ℝ)).const_mul 2).mono' + · apply Continuous.aestronglyMeasurable + apply (qaoaStateDistance_continuous n p q γ β γ' β').mul + apply Continuous.div_const + exact (groundMaximum_continuous n).add ((groundMaximum_continuous n).comp continuous_neg) + · filter_upwards [] with J + rw [Real.norm_eq_abs,abs_of_nonneg (mul_nonneg (stateDistance_nonneg _ _) + (div_nonneg (spectralWidth_nonneg n J) (Nat.cast_nonneg n)))] + exact mul_le_mul_of_nonneg_right + (stateDistance_le_two _ _ (qaoaState_mass n p J γ β) (qaoaState_mass n q J γ' β')) + (div_nonneg (spectralWidth_nonneg n J) (Nat.cast_nonneg n)) + + + +theorem expectedEnergy_sub_le_weightedStateError (n p q : ℕ) + (γ β : Fin p → ℝ) (γ' β' : Fin q → ℝ) : + |expectedEnergy n p γ β-expectedEnergy n q γ' β'| ≤ + 2*weightedStateError n p q γ β γ' β' := by + have hi := (energyDensity_integrable n p γ β).sub (energyDensity_integrable n q γ' β') + unfold expectedEnergy weightedStateError + rw [←integral_sub (energyDensity_integrable n p γ β) (energyDensity_integrable n q γ' β'), + ←integral_const_mul] + calc + _ ≤ ∫J : Disorder n,|energyDensity n p J γ β-energyDensity n q J γ' β'| ∂disorderLaw n := + abs_integral_le_integral_abs + _ ≤ _ := by + apply integral_mono hi.abs ((weightedStateError_integrable n p q γ β γ' β').const_mul 2) + intro J + dsimp only [Pi.sub_apply] + rw [energyDensity_eq,energyDensity_eq] + simpa only [stateEnergy,mul_assoc] using stateEnergy_sub_bound n J + (qaoaState n p J γ β) (qaoaState n q J γ' β') + (qaoaState_mass n p J γ β) (qaoaState_mass n q J γ' β') + + + +theorem value_eq_of_weightedStateError_tendsto_zero (p q : ℕ) + (γ β : Fin p → ℝ) (γ' β' : Fin q → ℝ) + (h : Tendsto (fun n=>weightedStateError n p q γ β γ' β') atTop (𝓝 0)) : + value p γ β=value q γ' β' := by + have hz : |value p γ β-value q γ' β'| ≤ 0 := by + apply le_of_tendsto_of_tendsto + ((tendsto_expectedEnergy_value p γ β).sub (tendsto_expectedEnergy_value q γ' β')).abs + (by simpa only [mul_zero] using h.const_mul 2) + exact Eventually.of_forall fun n=>expectedEnergy_sub_le_weightedStateError n p q γ β γ' β' + exact sub_eq_zero.mp (abs_nonpos_iff.mp hz) + +end SKQAOA + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory Filter + +namespace ClassicalGaussian +variable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsFiniteMeasure μ] + + + +theorem phase_weighted_integral_le {q ρ : Ω → ℝ} + (hq : MemLp q 2 μ) (hρ : MemLp ρ 2 μ) (hρn : ∀x,0≤ρ x) (t : ℝ) : + (∫x,ρ x*phaseError t (q x) ∂μ)≤ + Real.sqrt (∫x,ρ x^2 ∂μ)*Real.sqrt (4*t^2*∫x,q x^2 ∂μ) := by + have he : MemLp (fun x=>phaseError t (q x)) 2 μ := by + apply MemLp.of_bound ((continuous_phaseError t).comp_aestronglyMeasurable hq.aestronglyMeasurable) 4 + exact Eventually.of_forall fun x=>by + rw [Real.norm_of_nonneg (phaseError_nonneg _ _)] + exact phaseError_le_four _ _ + have hi : (∫x,phaseError t (q x)^2 ∂μ)≤4*t^2*∫x,q x^2 ∂μ := by + rw [← integral_const_mul] + apply integral_mono he.integrable_sq (hq.integrable_sq.const_mul _) + intro x + have ha := phaseError_nonneg t (q x) + have hb := phaseError_le_four t (q x) + have hc := phaseError_le_sq t (q x) + nlinarith + have h := integral_mul_le_Lp_mul_Lq_of_nonneg (μ:=μ) Real.HolderConjugate.two_two + (Eventually.of_forall hρn) (Eventually.of_forall (fun x=>phaseError_nonneg t (q x))) + (by simpa only [ENNReal.ofReal_ofNat] using hρ) + (by simpa only [ENNReal.ofReal_ofNat] using he) + have h' : (∫x,ρ x*phaseError t (q x) ∂μ)≤ + Real.sqrt (∫x,ρ x^2 ∂μ)*Real.sqrt (∫x,phaseError t (q x)^2 ∂μ) := by + simpa only [Real.rpow_two,Real.sqrt_eq_rpow,one_div] using h + exact h'.trans (mul_le_mul_of_nonneg_left (Real.sqrt_le_sqrt hi) (Real.sqrt_nonneg _)) + + + +theorem phase_varying_weight_limit + (Ω : ℕ → Type*) [∀n,MeasurableSpace (Ω n)] + (μ : ∀n,Measure (Ω n)) [∀n,IsFiniteMeasure (μ n)] + (q ρ : ∀n,Ω n → ℝ) (hq : ∀n,MemLp (q n) 2 (μ n)) + (hρ : ∀n,MemLp (ρ n) 2 (μ n)) (hρn : ∀n x,0≤ρ n x) + (C : ℝ) (hC : ∀n,(∫x,ρ n x^2 ∂μ n)≤C) + (t : ℝ) (hq0 : Tendsto (fun n=>∫x,q n x^2 ∂μ n) atTop (𝓝 0)) : + Tendsto (fun n=>∫x,ρ n x*phaseError t (q n x) ∂μ n) atTop (𝓝 0) := by + have ht := ((hq0.const_mul (4*t^2)).sqrt).const_mul (Real.sqrt C) + apply squeeze_zero (fun n=>integral_nonneg fun x=>mul_nonneg (hρn n x) (phaseError_nonneg _ _)) + (fun n=>(phase_weighted_integral_le (μ n) (hq n) (hρ n) (hρn n) t).trans + (mul_le_mul_of_nonneg_right (Real.sqrt_le_sqrt (hC n)) (Real.sqrt_nonneg _))) + (by simpa only [mul_zero,Real.sqrt_zero] using ht) + +end ClassicalGaussian + +namespace ClassicalGaussian +variable {Ω E : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem phaseMultiplier_error_integral {q : Ω → ℝ} + (hq : AEStronglyMeasurable q μ) (t : ℝ) (ψ : Lp E 2 μ) : + ‖phaseMultiplier μ hq t ψ-ψ‖^2= + ∫x,‖ψ x‖^2*phaseError t (q x) ∂μ := by + rw [L2_norm_sq_integral] + apply integral_congr_ae + filter_upwards [Lp.coeFn_sub (phaseMultiplier μ hq t ψ) ψ, + phaseMultiplier_ae μ hq t ψ] with x h1 h2 + simp only [Pi.sub_apply] at h1 + rw [h1,h2,show scalarPhase t (q x) • ψ x-ψ x= + (scalarPhase t (q x)-1) • ψ x by rw [sub_smul,one_smul]] + rw [norm_smul,mul_pow] + exact mul_comm _ _ + + + +theorem phaseMultiplier_varying_limit + (Ω E : ℕ → Type*) [∀n,MeasurableSpace (Ω n)] + [∀n,NormedAddCommGroup (E n)] [∀n,InnerProductSpace ℂ (E n)] + (μ : ∀n,Measure (Ω n)) [∀n,IsFiniteMeasure (μ n)] + (q : ∀n,Ω n → ℝ) (hq : ∀n,MemLp (q n) 2 (μ n)) + (ψ : ∀n,Lp (E n) 2 (μ n)) + (hψ : ∀n,MemLp (fun x=>‖ψ n x‖^2) 2 (μ n)) + (C : ℝ) (hC : ∀n,(∫x,(‖ψ n x‖^2)^2 ∂μ n)≤C) + (t : ℝ) (hq0 : Tendsto (fun n=>∫x,q n x^2 ∂μ n) atTop (𝓝 0)) : + Tendsto (fun n=>‖phaseMultiplier (μ n) (hq n).aestronglyMeasurable t (ψ n)-ψ n‖) + atTop (𝓝 0) := by + have h := phase_varying_weight_limit Ω μ q (fun n x=>‖ψ n x‖^2) hq hψ + (fun n x=>sq_nonneg _) C hC t hq0 + have he (n : ℕ) : (∫x,‖ψ n x‖^2*phaseError t (q n x) ∂μ n)= + ‖phaseMultiplier (μ n) (hq n).aestronglyMeasurable t (ψ n)-ψ n‖^2 := + (phaseMultiplier_error_integral (μ n) (hq n).aestronglyMeasurable t (ψ n)).symm + have hs := h.sqrt + simp only [he,Real.sqrt_sq (norm_nonneg _),Real.sqrt_zero] at hs + exact hs + +end ClassicalGaussian + +namespace GaussianCoherent.Quadratic + + + +theorem varying_dimension_L4_limit + (κ ι : ℕ → Type*) [∀n,Fintype (κ n)] + (s : ∀n,Finset (ι n)) (d e : ∀n,ι n → RealMode (κ n)) + (ho : ∀n,∀i∈s n,∀j∈s n,i≠j → ⟪d n i,d n j⟫=0 ∧ ⟪d n i,e n j⟫=0) + (hk : Tendsto (fun n=>ClassicalGaussian.Shifted.kernelSq (RealMode (κ n)) (s n) (d n) (e n)) + atTop (𝓝 0)) (t : ℝ) + (ψ : ∀n,CoherentFock.Space (Mode (κ n))) + (hψ : ∀n,MemLp (fun g=>‖gaussianUnitary (ψ n) g‖^2) 2 (GaussianFourier.law (κ n))) + (C : ℝ) (hC : ∀n,(∫g,(‖gaussianUnitary (ψ n) g‖^2)^2 ∂GaussianFourier.law (κ n))≤C) : + Tendsto (fun n=>‖unitary (s n) (d n) (e n) t (ψ n)-ψ n‖) atTop (𝓝 0) := by + have hq : Tendsto (fun n=>∫g,symbol (s n) (d n) (e n) g^2 ∂GaussianFourier.law (κ n)) + atTop (𝓝 0) := by + apply squeeze_zero (fun n=>integral_nonneg fun g=>sq_nonneg _) + (fun n=>symbol_second_moment_le (s n) (d n) (e n) (ho n)) + simpa only [mul_zero] using hk.const_mul 2 + have h := ClassicalGaussian.phaseMultiplier_varying_limit + (fun n=>κ n → ℝ) (fun _=>ℂ) (fun n=>GaussianFourier.law (κ n)) + (fun n=>symbol (s n) (d n) (e n)) (fun n=>memLp_symbol (s n) (d n) (e n)) + (fun n=>gaussianUnitary (ψ n)) hψ C hC t hq + have hn (n : ℕ) : ‖unitary (s n) (d n) (e n) t (ψ n)-ψ n‖= + ‖ClassicalGaussian.phaseMultiplier (GaussianFourier.law (κ n)) + (memLp_symbol (s n) (d n) (e n)).aestronglyMeasurable t (gaussianUnitary (ψ n))- + gaussianUnitary (ψ n)‖ := by + rw [←gaussianUnitary.norm_map (unitary (s n) (d n) (e n) t (ψ n)-ψ n)] + rw [map_sub,gaussian_unitary_apply] + simpa only [hn] using h + +end GaussianCoherent.Quadratic + + + +open scoped Topology +open MeasureTheory Filter + +namespace SKQAOA + + + +theorem tendsto_integral_groundMaximum_atTop : + Tendsto (fun n => ∫ J : Disorder n, groundMaximum n J ∂disorderLaw n) atTop atTop := by + have ht := (tendsto_natCast_atTop_atTop (R := ℝ)).atTop_mul_pos + Pstar_pos tendsto_expectedGround + apply ht.congr' + filter_upwards [eventually_ge_atTop 1] with n hn + have hne : (n : ℝ) ≠ 0 := by exact_mod_cast (Nat.ne_zero_of_lt hn) + dsimp only [expectedGround] + rw [mul_div_cancel₀ _ hne] + + + +theorem not_bddAbove_integral_groundMaximum : + ¬ BddAbove (Set.range (fun n => ∫ J : Disorder n, groundMaximum n J ∂disorderLaw n)) := + not_bddAbove_of_tendsto_atTop tendsto_integral_groundMaximum_atTop + +end SKQAOA + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/RestrictCode.lean b/lean/OAI/Probability/ParisiFinite/RestrictCode.lean new file mode 100644 index 0000000000000000000000000000000000000000..477202c479dfe06984900de2eb07e6205bcedd9f --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/RestrictCode.lean @@ -0,0 +1,646 @@ +import Mathlib +import OAI.Probability.ParisiFinite.CoreScaleSqLeOne + +namespace OAI + +/-! Restrict Code. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def restrictCode {r : ℕ} (c : Fin (r+1) → ℕ) : Fin r → ℕ := fun i => c i.castSucc + +lemma partition_restrict {r : ℕ} {c : Fin (r+1) → ℕ} {q : ℝ} {R : OverlapArray} + (h : R∈partitionEvent c q) : R∈partitionEvent (restrictCode c) q := + fun i j => h i.castSucc j.castSucc + +lemma partition_extend_iff {r : ℕ} (c : Fin (r+1) → ℕ) {q : ℝ} (hq : q<1) + {R : OverlapArray} (hG : R∈GramArrays) : R∈partitionEvent c q ↔ + R∈partitionEvent (restrictCode c) q ∧ + ∀ i : Fin r, q<(R i r:ℝ) ↔ restrictCode c i=c (Fin.last r) := by + constructor + · intro h + exact ⟨partition_restrict h,fun i => h i.castSucc (Fin.last r)⟩ + · rintro ⟨h,hrow⟩ + intro i j + refine Fin.lastCases ?_ (fun a => ?_) i + · refine Fin.lastCases ?_ (fun b => ?_) j + · change (q<(R r r:ℝ)) ↔ _ + rw [hG.2.1] + simp [hq] + · change (q<(R r b:ℝ)) ↔ c (Fin.last r)=restrictCode c b + rw [hG.1 r b] + exact (hrow b).trans eq_comm + · refine Fin.lastCases ?_ (fun b => ?_) j + · exact hrow a + · exact h a b + +lemma partition_existing_iff {r : ℕ} (c : Fin (r+1) → ℕ) {q : ℝ} (hq : q<1) + (i : Fin r) (hi : restrictCode c i=c (Fin.last r)) {R : OverlapArray} + (hG : R∈GramArrays) (hu : R∈UltrametricArrays) : + R∈partitionEvent c q ↔ R∈partitionEvent (restrictCode c) q ∧ q<(R i r:ℝ) := by + rw [partition_extend_iff c hq hG] + constructor + · exact fun h => ⟨h.1,(h.2 i).mpr hi⟩ + · rintro ⟨h,hir⟩ + refine ⟨h,fun j => ?_⟩ + constructor + · intro hjr + have hji : q<(R j i:ℝ) := (lt_min hjr hir).trans_le (hu j i r) + exact ((h j i).mp hji).trans hi + · intro hj + have hji : q<(R j i:ℝ) := (h j i).mpr (hj.trans hi.symm) + have hh := hu j r i + rw [hG.1 r i] at hh + exact (lt_min hji hir).trans_le hh + +lemma partition_fresh_iff {r : ℕ} (c : Fin (r+1) → ℕ) {q : ℝ} (hq : q<1) + (hi : ∀ i, restrictCode c i≠c (Fin.last r)) {R : OverlapArray} + (hG : R∈GramArrays) : + R∈partitionEvent c q ↔ R∈partitionEvent (restrictCode c) q ∧ ∀ i : Fin r, (R i r:ℝ) ≤ q := by + rw [partition_extend_iff c hq hG] + simp only [hi,iff_false,not_lt] + +lemma partition_zero (c : Fin 0 → ℕ) (q : ℝ) : partitionEvent c q=Set.univ := by + ext R + simp only [Set.mem_univ,iff_true] + exact fun i => Fin.elim0 i + +lemma partition_one_real {μ : ProbabilityMeasure OverlapArray} (hG : (μ:Measure OverlapArray) GramArrays=1) + (c : Fin 1 → ℕ) {q : ℝ} (hq : q<1) : (μ:Measure OverlapArray).real (partitionEvent c q)=1 := by + have he : partitionEvent c q =ᵐ[(μ:Measure OverlapArray)] Set.univ := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG] with R hR + apply propext + change (∀ i j : Fin 1, q<(R i j:ℝ) ↔ c i=c j) ↔ True + rw [iff_true] + intro i j + fin_cases i; fin_cases j + change q<(R 0 0:ℝ) ↔ _ + rw [hR.2.1] + simp [hq] + rw [measureReal_congr he,probReal_univ] + +lemma GG_partition_existing {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {r : ℕ} (c : Fin (r+1) → ℕ) {q : ℝ} (hq : q<1) (i : Fin r) + (hi : restrictCode c i=c (Fin.last r)) : + (r:ℝ)*(μ:Measure OverlapArray).real (partitionEvent c q)= + ((clusterCount (restrictCode c) i:ℝ)-overlapDiscount μ q)* + (μ:Measure OverlapArray).real (partitionEvent (restrictCode c) q) := by + have he : partitionEvent c q =ᵐ[(μ:Measure OverlapArray)] + {R | R∈partitionEvent (restrictCode c) q ∧ q<(R i r:ℝ)} := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG, + ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu] with R hg hu + exact propext (partition_existing_iff c hq i hi hg hu) + rw [measureReal_congr he] + exact GG_cluster_join hgg _ q i + +lemma GG_partition_fresh {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {r : ℕ} (c : Fin (r+1) → ℕ) {q : ℝ} (hq : q<1) + {S : Finset (Fin r)} (hS : ClusterReps (restrictCode c) S) + (hi : ∀ i, restrictCode c i≠c (Fin.last r)) : + (r:ℝ)*(μ:Measure OverlapArray).real (partitionEvent c q)= + (S.card:ℝ)*overlapDiscount μ q*(μ:Measure OverlapArray).real (partitionEvent (restrictCode c) q) := by + have he : partitionEvent c q =ᵐ[(μ:Measure OverlapArray)] + {R | R∈partitionEvent (restrictCode c) q ∧ ∀ i : Fin r,(R i r:ℝ) ≤ q} := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG] with R hg + exact propext (partition_fresh_iff c hq hi hg) + rw [measureReal_congr he] + exact GG_cluster_innovation hG hgg hu hS q + + + +theorem threshold_partition_unique {μ ν : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + (hG' : (ν:Measure OverlapArray) GramArrays=1) (hgg' : GGIdentities ν) + (hu' : (ν:Measure OverlapArray) UltrametricArrays=1) + {q : ℝ} (hq : q<1) (hz : overlapDiscount μ q=overlapDiscount ν q) + (r : ℕ) (c : Fin r → ℕ) : + (μ:Measure OverlapArray).real (partitionEvent c q)=(ν:Measure OverlapArray).real (partitionEvent c q) := by + induction r with + | zero => rw [partition_zero]; simp + | succ r ih => + by_cases hr : r=0 + · subst r + rw [partition_one_real hG c hq,partition_one_real hG' c hq] + have hr' : (r:ℝ)≠0 := Nat.cast_ne_zero.mpr hr + have hold := ih (restrictCode c) + by_cases hc : ∃ i, restrictCode c i=c (Fin.last r) + · obtain ⟨i,hi⟩ := hc + have h1 := GG_partition_existing hG hgg hu c hq i hi + have h2 := GG_partition_existing hG' hgg' hu' c hq i hi + rw [hz,hold] at h1 + exact mul_left_cancel₀ hr' (h1.trans h2.symm) + · have hc' : ∀ i, restrictCode c i≠c (Fin.last r) := not_exists.mp hc + obtain ⟨S,hS⟩ := exists_clusterReps (restrictCode c) + have h1 := GG_partition_fresh hG hgg hu c hq hS hc' + have h2 := GG_partition_fresh hG' hgg' hu' c hq hS hc' + rw [hz,hold] at h1 + exact mul_left_cancel₀ hr' (h1.trans h2.symm) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + +def oldRowCondition {r : ℕ} (S : Set (OverlapBlock r)) (t : Fin r → ℝ) (j : Fin r) : Set (OverlapBlock r) := + {T | T∈S ∧ ∀ i, t i<(T i j:ℝ)} + +lemma measurableSet_oldRowCondition {r : ℕ} {S : Set (OverlapBlock r)} + (hS : MeasurableSet S) (t : Fin r → ℝ) (j : Fin r) : MeasurableSet (oldRowCondition S t j) := by + simp only [oldRowCondition,Set.ofPred_and,Set.ofPred_forall] + exact hS.inter (MeasurableSet.iInter fun i => measurableSet_lt measurable_const (by fun_prop)) + +lemma ultra_row_event {r : ℕ} (S : Set (OverlapBlock r)) (t : Fin r → ℝ) (j : Fin r) + (hj : ∀ i, t i ≤ t j) {R : OverlapArray} (hG : R∈GramArrays) (hu : R∈UltrametricArrays) : + (blockOfArray r R∈S ∧ ∀ i : Fin r, t i<(R i r:ℝ)) ↔ + blockOfArray r R∈oldRowCondition S t j ∧ t j<(R j r:ℝ) := by + constructor + · rintro ⟨hS,hrow⟩ + exact ⟨⟨hS,fun i => (lt_min (hrow i) ((hj i).trans_lt (hrow j))).trans_le (hu i j r)⟩,hrow j⟩ + · rintro ⟨⟨hS,hrow⟩,hjr⟩ + refine ⟨hS,fun i => ?_⟩ + have hh := hu i r j + rw [hG.1 r j] at hh + exact (lt_min (hrow i) ((hj i).trans_lt hjr)).trans_le hh + +lemma blockLaw_real (μ : ProbabilityMeasure OverlapArray) (r : ℕ) {S : Set (OverlapBlock r)} + (hS : MeasurableSet S) : (blockLaw μ r).real S=(μ:Measure OverlapArray).real ((blockOfArray r) ⁻¹' S) := by + unfold Measure.real blockLaw + rw [Measure.map_apply (continuous_blockOfArray r).measurable hS] + + + +theorem GG_row_tail_identity {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {r : ℕ} {S : Set (OverlapBlock r)} (hS : MeasurableSet S) + (t : Fin r → ℝ) (j : Fin r) (hj : ∀ i, t i ≤ t j) : + (r:ℝ)*(μ:Measure OverlapArray).real {R | blockOfArray r R∈S ∧ ∀ i : Fin r, t i<(R i r:ℝ)}= + (blockLaw μ r).real (oldRowCondition S t j)*(entryLaw μ 0 1).real {x | t j<(x:ℝ)}+ + ∑ l∈Finset.univ.erase j,(blockLaw μ r).real {T | T∈oldRowCondition S t j ∧ t j<(T j l:ℝ)} := by + have he : {R | blockOfArray r R∈S ∧ ∀ i : Fin r, t i<(R i r:ℝ)} =ᵐ[(μ:Measure OverlapArray)] + {R | blockOfArray r R∈oldRowCondition S t j ∧ t j<(R j r:ℝ)} := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG, + ae_full_probability μ isClosed_UltrametricArrays.measurableSet hu] with R hR hU + exact propext (ultra_row_event S t j hj hR hU) + rw [measureReal_congr he] + have hB := measurableSet_oldRowCondition hS t j + have hg := GG_event_identity hgg r j (oldRowCondition S t j) {x : OverlapEntry | t j<(x:ℝ)} hB (measurableSet_lt measurable_const (by fun_prop)) + simp only [Set.mem_ofPred_eq] at hg + rw [hg] + rw [blockLaw_real μ r hB] + congr 1 + apply Finset.sum_congr rfl + intro l _ + exact (blockLaw_real μ r (S:={T | T∈oldRowCondition S t j ∧ t j<(T j l:ℝ)}) + (hB.inter (measurableSet_lt measurable_const + (by fun_prop : Measurable (fun T : OverlapBlock r => (T j l:ℝ)))))).symm + +lemma row_tail_unique {μ ν : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + (hG' : (ν:Measure OverlapArray) GramArrays=1) (hgg' : GGIdentities ν) + (hu' : (ν:Measure OverlapArray) UltrametricArrays=1) + (hz : entryLaw μ 0 1=entryLaw ν 0 1) (r : ℕ) (hblock : blockLaw μ r=blockLaw ν r) + {S : Set (OverlapBlock r)} (hS : MeasurableSet S) (t : Fin r → ℝ) : + (μ:Measure OverlapArray).real {R | blockOfArray r R∈S ∧ ∀ i : Fin r, t i<(R i r:ℝ)}= + (ν:Measure OverlapArray).real {R | blockOfArray r R∈S ∧ ∀ i : Fin r, t i<(R i r:ℝ)} := by + by_cases hr : r=0 + · subst r + simp only [Fin.forall_fin_zero,and_true] + exact (blockLaw_real μ 0 hS).symm.trans ((congrArg (fun ρ : Measure (OverlapBlock 0) => ρ.real S) hblock).trans (blockLaw_real ν 0 hS)) + · have : NeZero r := ⟨hr⟩ + obtain ⟨j,_,hj⟩ := Finset.exists_max_image Finset.univ t Finset.univ_nonempty + have hj' : ∀ i, t i ≤ t j := fun i => hj i (Finset.mem_univ i) + have h1 := GG_row_tail_identity hG hgg hu hS t j hj' + have h2 := GG_row_tail_identity hG' hgg' hu' hS t j hj' + rw [hblock,hz] at h1 + exact mul_left_cancel₀ (Nat.cast_ne_zero.mpr hr) (h1.trans h2.symm) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def overlapTails : Set (Set OverlapEntry) := Set.range (fun t : ℝ => {x : OverlapEntry | t<(x:ℝ)}) + +lemma overlapTails_measurable {S : Set OverlapEntry} (hS : S∈overlapTails) : MeasurableSet S := by + obtain ⟨t,rfl⟩ := hS + exact measurableSet_lt measurable_const (by fun_prop) + +lemma overlapTails_generate : MeasurableSpace.generateFrom overlapTails=(inferInstance : MeasurableSpace OverlapEntry) := by + apply le_antisymm (generateFrom_le (fun _ h => overlapTails_measurable h)) + have h : @Measurable OverlapEntry ℝ (MeasurableSpace.generateFrom overlapTails) inferInstance Subtype.val := by + apply measurable_of_Ioi + intro t + exact measurableSet_generateFrom ⟨t,rfl⟩ + have hi : @Measurable OverlapEntry OverlapEntry (MeasurableSpace.generateFrom overlapTails) inferInstance id := + h.subtype_mk + simpa only [MeasurableSpace.comap_id] using hi.comap_le + +lemma overlapTails_pi : IsPiSystem overlapTails := by + rintro A ⟨a,rfl⟩ B ⟨b,rfl⟩ _ + refine ⟨max a b,?_⟩ + ext x + change max a b <(x:ℝ) ↔ a<(x:ℝ) ∧ b<(x:ℝ) + exact max_lt_iff + +lemma overlapTails_univ : (Set.univ : Set OverlapEntry)∈overlapTails := by + refine ⟨-2,?_⟩ + ext x + simp only [Set.mem_ofPred_eq,Set.mem_univ,iff_true] + have := x.2.1 + linarith + +lemma overlapTails_spanning : IsCountablySpanning overlapTails := + ⟨fun _ : ℕ => Set.univ,fun _ => overlapTails_univ,by exact Set.iUnion_const Set.univ⟩ + +def rowTailBoxes (r : ℕ) : Set (Set (Fin r → OverlapEntry)) := + Set.pi Set.univ '' Set.pi Set.univ (fun _ : Fin r => overlapTails) + +lemma rowTailBoxes_generate (r : ℕ) : MeasurableSpace.generateFrom (rowTailBoxes r)=(inferInstance : MeasurableSpace (Fin r → OverlapEntry)) := + generateFrom_eq_pi (fun _ => overlapTails_generate) (fun _ => overlapTails_spanning) + +lemma rowTailBoxes_pi (r : ℕ) : IsPiSystem (rowTailBoxes r) := + IsPiSystem.pi (fun _ => overlapTails_pi) + +lemma rowTailBoxes_spanning (r : ℕ) : IsCountablySpanning (rowTailBoxes r) := + IsCountablySpanning.pi (fun _ => overlapTails_spanning) + +lemma rowTailBoxes_characterization {r : ℕ} {S : Set (Fin r → OverlapEntry)} (hS : S∈rowTailBoxes r) : + ∃ t : Fin r → ℝ, S={x | ∀ i, t i<(x i:ℝ)} := by + obtain ⟨s,hs,rfl⟩ := hS + have ht (i : Fin r) : ∃ t : ℝ, s i={x : OverlapEntry | t<(x:ℝ)} := by + obtain ⟨t,ht⟩ := hs i (Set.mem_univ i) + exact ⟨t,ht.symm⟩ + choose t ht using ht + refine ⟨t,?_⟩ + ext x + simp only [Set.mem_pi,Set.mem_univ,true_implies,ht,Set.mem_ofPred_eq] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def blockRowMap (r : ℕ) (R : OverlapArray) : OverlapBlock r × (Fin r → OverlapEntry) := + (blockOfArray r R,fun i => R i r) + +lemma continuous_blockRowMap (r : ℕ) : Continuous (blockRowMap r) := by + exact (continuous_blockOfArray r).prodMk (by fun_prop) + +def blockRowLaw (μ : ProbabilityMeasure OverlapArray) (r : ℕ) : Measure (OverlapBlock r × (Fin r → OverlapEntry)) := + (μ:Measure OverlapArray).map (blockRowMap r) + +instance blockRowLaw_probability (μ : ProbabilityMeasure OverlapArray) (r : ℕ) : IsProbabilityMeasure (blockRowLaw μ r) := by + unfold blockRowLaw + infer_instance + +lemma blockRowLaw_eq {μ ν : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + (hG' : (ν:Measure OverlapArray) GramArrays=1) (hgg' : GGIdentities ν) + (hu' : (ν:Measure OverlapArray) UltrametricArrays=1) + (hz : entryLaw μ 0 1=entryLaw ν 0 1) (r : ℕ) (hblock : blockLaw μ r=blockLaw ν r) : + blockRowLaw μ r=blockRowLaw ν r := by + apply ext_of_generate_finite + (Set.image2 (· ×ˢ ·) {S : Set (OverlapBlock r) | MeasurableSet S} (rowTailBoxes r)) + (generateFrom_eq_prod generateFrom_measurableSet (rowTailBoxes_generate r) + isCountablySpanning_measurableSet (rowTailBoxes_spanning r)).symm + (isPiSystem_measurableSet.prod (rowTailBoxes_pi r)) + · rintro _ ⟨S,hS,T,hT,rfl⟩ + change MeasurableSet S at hS + obtain ⟨t,rfl⟩ := rowTailBoxes_characterization hT + have hT' : MeasurableSet {x : Fin r → OverlapEntry | ∀ i, t i<(x i:ℝ)} := by + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun i => measurableSet_lt measurable_const (by fun_prop) + rw [blockRowLaw,blockRowLaw,Measure.map_apply (continuous_blockRowMap r).measurable (hS.prod hT'), + Measure.map_apply (continuous_blockRowMap r).measurable (hS.prod hT')] + have he := row_tail_unique hG hgg hu hG' hgg' hu' hz r hblock hS t + have he' := congrArg ENNReal.ofReal he + simpa only [Measure.real,ENNReal.ofReal_toReal (measure_ne_top _ _),blockRowMap,Set.preimage,Set.mem_prod,Set.mem_ofPred_eq] using he' + · simp + +def joinBlock (r : ℕ) (z : OverlapBlock r × (Fin r → OverlapEntry)) : OverlapBlock (r+1) := + fun i j => Fin.lastCases (Fin.lastCases (⟨1,by norm_num⟩ : OverlapEntry) (fun b => z.2 b) j) + (fun a => Fin.lastCases (z.2 a) (fun b => z.1 a b) j) i + +lemma continuous_joinBlock (r : ℕ) : Continuous (joinBlock r) := by + apply continuous_pi + intro i + apply continuous_pi + intro j + induction i using Fin.lastCases with + | last => + induction j using Fin.lastCases with + | last => simp only [joinBlock,Fin.lastCases_last]; exact continuous_const + | cast j => simp only [joinBlock,Fin.lastCases_last,Fin.lastCases_castSucc]; fun_prop + | cast i => + induction j using Fin.lastCases with + | last => simp only [joinBlock,Fin.lastCases_last,Fin.lastCases_castSucc]; fun_prop + | cast j => simp only [joinBlock,Fin.lastCases_castSucc]; fun_prop + +lemma joinBlock_blockRowMap {R : OverlapArray} (hG : R∈GramArrays) (r : ℕ) : + joinBlock r (blockRowMap r R)=blockOfArray (r+1) R := by + ext i j + induction i using Fin.lastCases with + | last => + induction j using Fin.lastCases with + | last => simpa only [joinBlock,Fin.lastCases_last,blockOfArray,Fin.val_last] using (hG.2.1 r).symm + | cast j => simpa only [joinBlock,Fin.lastCases_last,Fin.lastCases_castSucc,blockRowMap,blockOfArray,Fin.val_last,Fin.val_castSucc] using congrArg Subtype.val (hG.1 j r) + | cast i => + induction j using Fin.lastCases <;> simp only [joinBlock,Fin.lastCases_last,Fin.lastCases_castSucc,blockRowMap,blockOfArray,Fin.val_last,Fin.val_castSucc] + +lemma joinBlock_map_law {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (r : ℕ) : + (blockRowLaw μ r).map (joinBlock r)=blockLaw μ (r+1) := by + rw [blockRowLaw,Measure.map_map (continuous_joinBlock r).measurable (continuous_blockRowMap r).measurable] + exact Measure.map_congr ((ae_full_probability μ isClosed_GramArrays.measurableSet hG).mono + (fun R hR => joinBlock_blockRowMap hR r)) + +lemma blockLaw_zero (μ ν : ProbabilityMeasure OverlapArray) : blockLaw μ 0=blockLaw ν 0 := by + have hc : blockOfArray 0=(fun _ : OverlapArray => (fun i : Fin 0 => Fin.elim0 i : OverlapBlock 0)) := by + funext R i + exact Fin.elim0 i + simp only [blockLaw,hc,Measure.map_const,measure_univ,one_smul] + + + +theorem GG_ultrametric_blocks_unique {μ ν : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + (hG' : (ν:Measure OverlapArray) GramArrays=1) (hgg' : GGIdentities ν) + (hu' : (ν:Measure OverlapArray) UltrametricArrays=1) + (hz : entryLaw μ 0 1=entryLaw ν 0 1) (r : ℕ) : blockLaw μ r=blockLaw ν r := by + induction r with + | zero => exact blockLaw_zero μ ν + | succ r ih => + rw [← joinBlock_map_law hG r,← joinBlock_map_law hG' r, + blockRowLaw_eq hG hgg hu hG' hgg' hu' hz r ih] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +lemma abs_log_sub_le {a b : ℝ} (ha : 0 nlinarith + +omit [Nonempty ι] in +lemma inv_sq_weighted_le (p : ι → ℝ) (hp : ∀ i, 0≤p i) (hs : ∑ i,p i=1) + (u : ι → ℝ) (hu : ∀ i,0 hp i) hs (fun i _ => hu i) + simpa only [smul_eq_mul,zpow_neg,zpow_natCast,inv_pow] using! h + +lemma log_error_young {a b t : ℝ} (ha : 0 ∑ i,f i σ)=∑ i,replicaMean x (f i) := by + simp only [replicaMean,Finset.mul_sum] + exact Finset.sum_comm + +lemma replicaMean_centered_sq_sum (x f : ι → ℝ) (hf : ∑ s,weight x s*f s=0) (r : ℕ) : + replicaMean x (fun σ : Fin r → ι => (∑ i,f (σ i))^2)= + (r:ℝ)*∑ s,weight x s*(f s)^2 := by + induction r with + | zero => simp [replicaMean,replicaWeight] + | succ r ih => + rw [replicaMean_snoc] + have he (σ : Fin r → ι) : + (∑ s,weight x s*(∑ i : Fin (r+1),f ((Fin.snoc σ s : Fin (r+1) → ι) i))^2)= + (∑ i,f (σ i))^2+∑ s,weight x s*(f s)^2 := by + simp only [Fin.sum_univ_castSucc,Fin.snoc_castSucc,Fin.snoc_last] + have he' (s : ι) : weight x s*((∑ i,f (σ i))+f s)^2= + weight x s*(∑ i,f (σ i))^2 + 2*(∑ i,f (σ i))*(weight x s*f s)+weight x s*(f s)^2 := by ring + simp_rw [he'] + rw [Finset.sum_add_distrib,Finset.sum_add_distrib,← Finset.sum_mul,← Finset.mul_sum,sum_weight,hf] + ring + simp_rw [he] + change replicaMean x (fun σ : Fin r → ι => (∑ i,f (σ i))^2+∑ s,weight x s*(f s)^2)=_ + rw [replicaMean_add,ih,replicaMean_const] + push_cast + ring + +def empiricalMean {r : ℕ} (f : ι → ℝ) (σ : Fin r → ι) : ℝ := (∑ i,f (σ i))/(r:ℝ) + +omit [Fintype ι] [Nonempty ι] in +lemma empiricalMean_positive {r : ℕ} (hr : 0 hf (σ i)) Finset.univ_nonempty) (Nat.cast_pos.mpr hr) + +lemma empiricalMean_variance {r : ℕ} (hr : 0 (empiricalMean f σ-average x f)^2)= + (average x (fun s => (f s-average x f)^2))/(r:ℝ) := by + have hr' : (r:ℝ)≠0 := Nat.cast_ne_zero.mpr hr.ne' + have hcenter : ∑ s,weight x s*(f s-average x f)=0 := by + simp only [mul_sub,Finset.sum_sub_distrib,← Finset.sum_mul,sum_weight,one_mul,average] + ring + have he (σ : Fin r → ι) : (empiricalMean f σ-average x f)^2= + ((r:ℝ)^2)⁻¹*(∑ i,(f (σ i)-average x f))^2 := by + simp only [empiricalMean,Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + field_simp + simp_rw [he] + rw [replicaMean_const_mul,replicaMean_centered_sq_sum x _ hcenter] + change _=(∑ s,weight x s*(f s-average x f)^2)/(r:ℝ) + field_simp + +lemma average_variance_le (x f : ι → ℝ) : + average x (fun s => (f s-average x f)^2)≤average x (fun s => (f s)^2) := by + have he (s) : weight x s*(f s-average x f)^2=weight x s*(f s)^2- + 2*average x f*(weight x s*f s)+(average x f)^2*weight x s := by ring + simp only [average] at he ⊢ + simp_rw [he] + rw [Finset.sum_add_distrib,Finset.sum_sub_distrib,← Finset.mul_sum,← Finset.mul_sum,sum_weight,mul_one] + nlinarith [sq_nonneg (∑ s,weight x s*f s)] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +lemma replicaMean_empirical {r : ℕ} (hr : 0 (∑ i,f (σ i))/(r:ℝ))=average x f + simp only [div_eq_inv_mul,replicaMean_const_mul,replicaMean_sum_same] + change _=∑ s,weight x s*f s + field_simp + +omit [Fintype ι] [Nonempty ι] in +lemma empiricalMean_inv_sq {r : ℕ} (hr : 0 (f i)⁻¹^2) σ := by + have hr' : (r:ℝ)≠0 := Nat.cast_ne_zero.mpr hr.ne' + have h := inv_sq_weighted_le (ι:=Fin r) (fun _ => (r:ℝ)⁻¹) (fun _ => by positivity) + (by simp [hr']) (fun i => f (σ i)) (fun i => hf (σ i)) + simpa only [empiricalMean,← Finset.mul_sum,div_eq_inv_mul] using h + +lemma replicaMean_inv_sq_empirical {r : ℕ} (hr : 0 (empiricalMean f σ)⁻¹^2)≤average x (fun i => (f i)⁻¹^2) := by + exact (replicaMean_mono x (empiricalMean_inv_sq hr f hf)).trans_eq (replicaMean_empirical hr x _) + +lemma average_inv_sq (x f : ι → ℝ) (hf : ∀ i,0 (f i)⁻¹^2) := + inv_sq_weighted_le (weight x) (fun s => (weight_pos x s).le) (sum_weight x) f hf + +lemma replicaMean_abs (x : ι → ℝ) {r : ℕ} (f : (Fin r → ι) → ℝ) : + |replicaMean x f|≤replicaMean x (fun σ => |f σ|) := by + apply (Finset.abs_sum_le_sum_abs _ _).trans_eq + apply Finset.sum_congr rfl + intro σ _ + rw [abs_mul,abs_of_nonneg (replicaWeight_nonneg _ _)] + + + +theorem empirical_log_error {r : ℕ} (hr : 0 |Real.log (empiricalMean f σ)-Real.log (average x f)|) ≤ + (t/(r:ℝ))*average x (fun s => (f s)^2)+t⁻¹*average x (fun s => (f s)⁻¹^2) := by + have h := replicaMean_mono x (fun σ : Fin r → ι => + log_error_young (empiricalMean_positive hr hf σ) (average_pos x f hf) ht) + have he (σ : Fin r → ι) : + t*(empiricalMean f σ-average x f)^2+((empiricalMean f σ)⁻¹^2+(average x f)⁻¹^2)/(2*t)= + t*(empiricalMean f σ-average x f)^2+(2*t)⁻¹*(empiricalMean f σ)⁻¹^2+ + (2*t)⁻¹*(average x f)⁻¹^2 := by ring + simp_rw [he] at h + rw [replicaMean_add,replicaMean_add,replicaMean_const_mul,replicaMean_const_mul, + replicaMean_const,empiricalMean_variance hr] at h + have hv := div_le_div_of_nonneg_right (average_variance_le x f) (Nat.cast_nonneg r) + have h1 := mul_le_mul_of_nonneg_left hv ht.le + have h2 := mul_le_mul_of_nonneg_left (replicaMean_inv_sq_empirical hr x f hf) + (by positivity : 0≤(2*t)⁻¹) + have h3 := mul_le_mul_of_nonneg_left (average_inv_sq x f hf) (by positivity : 0≤(2*t)⁻¹) + have h4 : (2*t)⁻¹+(2*t)⁻¹=t⁻¹ := by field_simp; norm_num + calc + _ ≤ t*((average x (fun s => (f s)^2))/(r:ℝ))+ + (2*t)⁻¹*average x (fun s => (f s)⁻¹^2)+(2*t)⁻¹*average x (fun s => (f s)⁻¹^2) := + h.trans (add_le_add (add_le_add h1 h2) h3) + _ = _ := by rw [add_assoc,← add_mul,h4]; ring + +lemma empirical_log_mean_error {r : ℕ} (hr : 0 Real.log (empiricalMean f σ))-Real.log (average x f)| ≤ + (t/(r:ℝ))*average x (fun s => (f s)^2)+t⁻¹*average x (fun s => (f s)⁻¹^2) := by + rw [← replicaMean_const (r:=r) x (Real.log (average x f)),← replicaMean_sub] + exact (replicaMean_abs x _).trans (empirical_log_error hr x f hf ht) + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/RestrictLeft.lean b/lean/OAI/Probability/ParisiFinite/RestrictLeft.lean new file mode 100644 index 0000000000000000000000000000000000000000..700d616ca8b9a7712db12be357bb72254c5df349 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/RestrictLeft.lean @@ -0,0 +1,689 @@ +import Mathlib +import OAI.Probability.ParisiFinite.IntegrablePdfMul +import OAI.Probability.ParisiFinite.TendstoDyadicRound + +namespace OAI + +/-! Restrict Left. -/ + +noncomputable section + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter +namespace SKQAOA + +open SKGaussian + +def restrictLeft {n m : ℕ} (σ : Configuration (n + m)) : Configuration n := + fun i => σ (Fin.castAdd m i) + +def restrictRight {n m : ℕ} (σ : Configuration (n + m)) : Configuration m := + fun i => σ (Fin.natAdd n i) + +@[simp] theorem restrictLeft_append {n m : ℕ} (σ : Configuration n) (τ : Configuration m) : + restrictLeft (Fin.append σ τ) = σ := by + funext i + simp [restrictLeft] + +@[simp] theorem restrictRight_append {n m : ℕ} (σ : Configuration n) (τ : Configuration m) : + restrictRight (Fin.append σ τ) = τ := by + funext i + simp [restrictRight] + +theorem overlapSum_split {n m : ℕ} (σ τ : Configuration (n + m)) : + overlapSum σ τ = overlapSum (restrictLeft σ) (restrictLeft τ) + + overlapSum (restrictRight σ) (restrictRight τ) := by + exact Fin.sum_univ_add (fun i => spin σ i * spin τ i) + + +def blockCoeff (n m : ℕ) (σ : Configuration (n + m)) : Edge n ⊕ Edge m → ℝ := + Sum.elim (skCoeff n (restrictLeft σ)) (skCoeff m (restrictRight σ)) + +theorem blockCoeff_increment {n m : ℕ} (hn : 0 < n) (hm : 0 < m) + (σ τ : Configuration (n + m)) : + (∑ e, (blockCoeff n m σ e - blockCoeff n m τ e) ^ 2) ≤ + ∑ e, (skCoeff (n + m) σ e - skCoeff (n + m) τ e) ^ 2 := by + simp only [blockCoeff, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr] + rw [coeff_increment hn, coeff_increment hm, coeff_increment (by omega), overlapSum_split] + have hn' : (0 : ℝ) < n := Nat.cast_pos.mpr hn + have hm' : (0 : ℝ) < m := Nat.cast_pos.mpr hm + let a := overlapSum (restrictLeft σ) (restrictLeft τ) + let b := overlapSum (restrictRight σ) (restrictRight τ) + change (n : ℝ) - a^2 / n + ((m : ℝ) - b^2 / m) ≤ + (↑(n + m) : ℝ) - (a + b)^2 / ↑(n + m) + push_cast + field_simp + nlinarith [sq_nonneg ((m : ℝ) * a - (n : ℝ) * b)] + +theorem groundMaximum_eq_finiteMax (n : ℕ) (J : Disorder n) : + groundMaximum n J = finiteMax (field (skCoeff n) J) := by + have he : field (skCoeff n) J = hamiltonian n J := + funext fun σ => (hamiltonian_eq_coeff n J σ).symm + rw [he] + simp [groundMaximum, finiteMax, Finset.sup'_eq_csSup_image] + + +theorem block_finiteMax {n m : ℕ} (J : (Edge n ⊕ Edge m) → ℝ) : + finiteMax (field (blockCoeff n m) J) = + groundMaximum n (fun e => J (Sum.inl e)) + + groundMaximum m (fun e => J (Sum.inr e)) := by + have he (σ : Configuration (n + m)) : field (blockCoeff n m) J σ = + field (skCoeff n) (fun e => J (Sum.inl e)) (restrictLeft σ) + + field (skCoeff m) (fun e => J (Sum.inr e)) (restrictRight σ) := by + simp only [field, blockCoeff, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr] + rw [groundMaximum_eq_finiteMax, groundMaximum_eq_finiteMax] + apply le_antisymm + · exact Finset.sup'_le Finset.univ_nonempty _ fun σ _ => by + rw [he] + exact add_le_add (le_finiteMax _ _) (le_finiteMax _ _) + · obtain ⟨σ, _, hσ⟩ := Finset.exists_mem_eq_sup' + (Finset.univ_nonempty : (Finset.univ : Finset (Configuration n)).Nonempty) + (field (skCoeff n) (fun e => J (Sum.inl e))) + obtain ⟨τ, _, hτ⟩ := Finset.exists_mem_eq_sup' + (Finset.univ_nonempty : (Finset.univ : Finset (Configuration m)).Nonempty) + (field (skCoeff m) (fun e => J (Sum.inr e))) + have hp := le_finiteMax (field (blockCoeff n m) J) (Fin.append σ τ) + rw [he, restrictLeft_append, restrictRight_append] at hp + simpa only [finiteMax, hσ, hτ] using hp + + +def expectedMaximum (n : ℕ) : ℝ := ∫ J, groundMaximum n J ∂disorderLaw n + +theorem ground_integrable (n : ℕ) : Integrable (groundMaximum n) (disorderLaw n) := by + simp_rw [show groundMaximum n = fun J => finiteMax (field (skCoeff n) J) from + funext (groundMaximum_eq_finiteMax n)] + exact integrable_finiteMax (integrable_field (skCoeff n)) + +theorem expected_block_maximum (n m : ℕ) : + (∫ J, finiteMax (field (blockCoeff n m) J) ∂gaussianLaw (Edge n ⊕ Edge m)) = + expectedMaximum n + expectedMaximum m := by + let T : ((Disorder n) × (Disorder m)) ≃ᵐ ((Edge n ⊕ Edge m) → ℝ) := + (MeasurableEquiv.sumPiEquivProdPi (fun _ : Edge n ⊕ Edge m => ℝ)).symm + have hp : MeasurePreserving T ((disorderLaw n).prod (disorderLaw m)) + (gaussianLaw (Edge n ⊕ Edge m)) := + measurePreserving_sumPiEquivProdPi_symm (fun _ => gaussianReal 0 1) + rw [← hp.integral_comp' (fun J => finiteMax (field (blockCoeff n m) J))] + simp_rw [block_finiteMax] + change (∫ J, groundMaximum n J.1 + groundMaximum m J.2 + ∂(disorderLaw n).prod (disorderLaw m)) = _ + have : IsProbabilityMeasure (disorderLaw n) := by unfold disorderLaw; infer_instance + have : IsProbabilityMeasure (disorderLaw m) := by unfold disorderLaw; infer_instance + rw [integral_add ((ground_integrable n).comp_fst _) ((ground_integrable m).comp_snd _)] + simp [integral_fun_fst, integral_fun_snd, expectedMaximum] + + + +theorem expectedMaximum_superadditive_pos {n m : ℕ} (hn : 0 < n) (hm : 0 < m) : + expectedMaximum n + expectedMaximum m ≤ expectedMaximum (n + m) := by + have h := expected_field_max_le (blockCoeff n m) (skCoeff (n + m)) + (blockCoeff_increment hn hm) + rw [expected_block_maximum] at h + simpa only [← groundMaximum_eq_finiteMax, gaussianLaw, disorderLaw, expectedMaximum] using h + +@[simp] theorem groundMaximum_zero (J : Disorder 0) : groundMaximum 0 J = 0 := by + have he : hamiltonian 0 J = fun _ => 0 := by + funext σ + simp [hamiltonian] + rw [groundMaximum, he] + simp + +@[simp] theorem expectedMaximum_zero : expectedMaximum 0 = 0 := by + simp [expectedMaximum] + +theorem expectedMaximum_superadditive (n m : ℕ) : + expectedMaximum n + expectedMaximum m ≤ expectedMaximum (n + m) := by + rcases Nat.eq_zero_or_pos n with rfl | hn + · simp + rcases Nat.eq_zero_or_pos m with rfl | hm + · simp + exact expectedMaximum_superadditive_pos hn hm + + +def siteCoeff (n : ℕ) (σ : Configuration n) (i : Fin n) : ℝ := spin σ i + +theorem site_increment (n : ℕ) (σ τ : Configuration n) : + (∑ i, (siteCoeff n σ i - siteCoeff n τ i) ^ 2) = + 2 * (n : ℝ) - 2 * overlapSum σ τ := by + have he (i : Fin n) : (siteCoeff n σ i - siteCoeff n τ i) ^ 2 = + 2 - 2 * (spin σ i * spin τ i) := by + dsimp [siteCoeff] + nlinarith [spin_sq σ i, spin_sq τ i] + simp_rw [he] + simp [Finset.sum_sub_distrib, Finset.mul_sum, overlapSum] + ring + +theorem sk_to_site_increment {n : ℕ} (hn : 0 < n) (σ τ : Configuration n) : + (∑ e, (skCoeff n σ e - skCoeff n τ e) ^ 2) ≤ + ∑ i, (siteCoeff n σ i - siteCoeff n τ i) ^ 2 := by + rw [coeff_increment hn, site_increment] + have hn' : (0 : ℝ) < n := Nat.cast_pos.mpr hn + field_simp + nlinarith [sq_nonneg (overlapSum σ τ - (n : ℝ))] + +def gaussianAbsoluteMean : ℝ := ∫ x : ℝ, |x| ∂gaussianReal 0 1 + +theorem integrable_abs_standard : Integrable (fun x : ℝ => |x|) (gaussianReal 0 1) := + (MemLp.integrable (by norm_num) (memLp_id_gaussianReal (μ := 0) (v := 1) 1)).abs + +theorem site_maximum_le (n : ℕ) (J : Fin n → ℝ) : + finiteMax (field (siteCoeff n) J) ≤ ∑ i, |J i| := by + apply Finset.sup'_le Finset.univ_nonempty + intro σ _ + apply Finset.sum_le_sum + intro i _ + change spin σ i * J i ≤ |J i| + unfold spin + split + · simpa using neg_le_abs (J i) + · simpa using le_abs_self (J i) + + + +theorem expectedMaximum_le (n : ℕ) : expectedMaximum n ≤ (n : ℝ) * gaussianAbsoluteMean := by + rcases Nat.eq_zero_or_pos n with rfl | hn + · simp + have hcomp := expected_field_max_le (skCoeff n) (siteCoeff n) (sk_to_site_increment hn) + have hi : ∀ i : Fin n, Integrable (fun J : Fin n → ℝ => |J i|) (gaussianLaw (Fin n)) := + fun i => integrable_comp_eval (i := i) integrable_abs_standard + calc + _ ≤ ∫ J, finiteMax (field (siteCoeff n) J) ∂gaussianLaw (Fin n) := by + simpa only [← groundMaximum_eq_finiteMax, gaussianLaw, disorderLaw, expectedMaximum] using hcomp + _ ≤ ∫ J : Fin n → ℝ, ∑ i, |J i| ∂gaussianLaw (Fin n) := + integral_mono (integrable_finiteMax (integrable_field (siteCoeff n))) + (integrable_finsetSum _ fun i _ => hi i) (site_maximum_le n) + _ = _ := by + rw [integral_finsetSum _ fun i _ => hi i] + have he (i : Fin n) : (∫ J : Fin n → ℝ, |J i| ∂gaussianLaw (Fin n)) = gaussianAbsoluteMean := + integral_comp_eval integrable_abs_standard.aestronglyMeasurable + simp only [he, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + + + +theorem tendsto_expectedGround : Tendsto expectedGround atTop (𝓝 Pstar) := by + have hs : Subadditive (fun n => -expectedMaximum n) := by + intro n m + linarith [expectedMaximum_superadditive n m] + have hb : BddBelow (Set.range fun n => -expectedMaximum n / (n : ℝ)) := by + refine ⟨-gaussianAbsoluteMean, ?_⟩ + rintro _ ⟨n, rfl⟩ + rcases Nat.eq_zero_or_pos n with rfl | hn + · simp only [expectedMaximum_zero, neg_zero, Nat.cast_zero, div_zero] + exact neg_nonpos.mpr (integral_nonneg fun x => abs_nonneg x) + · have hn' : (0 : ℝ) < n := Nat.cast_pos.mpr hn + apply (le_div_iff₀ hn').mpr + linarith [expectedMaximum_le n] + have ht := (hs.tendsto_lim hb).neg + have he : (fun n => -(-expectedMaximum n / (n : ℝ))) = expectedGround := by + funext n + simp [expectedGround, expectedMaximum, neg_div] + rw [he] at ht + have hp : Pstar = -hs.lim := ht.limUnder_eq + rwa [hp] + +end SKQAOA + +namespace TensorMatrix + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +variable {κ : Type*} [Fintype κ] [DecidableEq κ] + + +def lift (A : ι → Matrix κ κ ℂ) : Matrix (ι → κ) (ι → κ) ℂ := + fun σ τ => ∏ i, A i (σ i) (τ i) + +omit [DecidableEq ι] [Fintype κ] in +@[simp] theorem lift_one : lift (fun _ : ι => (1 : Matrix κ κ ℂ)) = 1 := by + ext σ τ + by_cases h : σ = τ + · subst τ + simp [lift] + · have he : ∃ i, σ i ≠ τ i := Function.ne_iff.mp h + obtain ⟨i, hi⟩ := he + simp only [lift, Matrix.one_apply, ite_eq_right h] + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + +omit [DecidableEq κ] in +@[simp] theorem lift_mul (A B : ι → Matrix κ κ ℂ) : + lift (fun i => A i * B i) = lift A * lift B := by + ext σ τ + simp only [lift, Matrix.mul_apply] + simp_rw [← Finset.prod_mul_distrib] + exact Fintype.prod_sum _ + + +def atSite (i : ι) (A : Matrix κ κ ℂ) : Matrix (ι → κ) (ι → κ) ℂ := + lift (Function.update (fun _ => 1) i A) + +omit [Fintype κ] in +@[simp] theorem local_one (i : ι) : atSite i (1 : Matrix κ κ ℂ) = 1 := by + simp [atSite, Function.update_eq_self] + +@[simp] theorem local_mul (i : ι) (A B : Matrix κ κ ℂ) : + atSite i (A * B) = atSite i A * atSite i B := by + rw [atSite, atSite, atSite, ← lift_mul] + congr 1 + funext j + by_cases h : j = i <;> simp [Function.update, h] + +omit [Fintype κ] in +theorem atSite_apply (i : ι) (A : Matrix κ κ ℂ) (σ τ : ι → κ) : + atSite i A σ τ = A (σ i) (τ i) * + ∏ j ∈ Finset.univ.erase i, (1 : Matrix κ κ ℂ) (σ j) (τ j) := by + unfold atSite lift + rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ i)] + simp only [Function.update_self] + congr 1 + apply Finset.prod_congr rfl + intro j hj + rw [Function.update_of_ne (Finset.ne_of_mem_erase hj)] + +omit [Fintype κ] in +@[simp] theorem local_add (i : ι) (A B : Matrix κ κ ℂ) : + atSite i (A + B) = atSite i A + atSite i B := by + ext σ τ + simp only [Matrix.add_apply, atSite_apply] + exact add_mul _ _ _ + +omit [Fintype κ] in +@[simp] theorem local_zero (i : ι) : atSite i (0 : Matrix κ κ ℂ) = 0 := by + ext σ τ + simp [atSite_apply] + +omit [Fintype κ] in +@[simp] theorem local_smul (i : ι) (c : ℂ) (A : Matrix κ κ ℂ) : + atSite i (c • A) = c • atSite i A := by + ext σ τ + simp only [Matrix.smul_apply, atSite_apply, smul_eq_mul] + exact mul_assoc _ _ _ + + +def localAlgHom (i : ι) : Matrix κ κ ℂ →ₐ[ℂ] Matrix (ι → κ) (ι → κ) ℂ where + toFun := atSite i + map_one' := local_one i + map_mul' := local_mul i + map_zero' := local_zero i + map_add' := local_add i + commutes' c := by + simp only [Algebra.algebraMap_eq_smul_one, local_smul, local_one] + +open scoped Matrix.Norms.Operator in +@[simp] theorem local_exp (i : ι) (A : Matrix κ κ ℂ) : + atSite i (NormedSpace.exp A) = NormedSpace.exp (atSite i A) := by + exact NormedSpace.map_exp (localAlgHom i) + (localAlgHom (κ := κ) i).toLinearMap.continuous_of_finiteDimensional A + +theorem atSite_commute {i j : ι} (hij : i ≠ j) (A B : Matrix κ κ ℂ) : + Commute (atSite i A) (atSite j B) := by + show atSite i A * atSite j B = atSite j B * atSite i A + simp only [atSite, ← lift_mul] + congr 1 + funext k + by_cases hi : k = i + · subst k + simp [Function.update, hij] + · by_cases hj : k = j + · subst k + simp [Function.update, Ne.symm hij] + · simp [Function.update, hi, hj] + +theorem exp_sum_atSite (s : Finset ι) (A : ι → Matrix κ κ ℂ) : + NormedSpace.exp (∑ i ∈ s, atSite i (A i)) = + lift (fun i => if i ∈ s then NormedSpace.exp (A i) else 1) := by + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => + have hc : Commute (atSite a (A a)) (∑ i ∈ s, atSite i (A i)) := by + apply Commute.sum_right + intro i hi + exact atSite_commute (i := a) (j := i) (fun e => ha (e.symm ▸ hi)) _ _ + rw [Finset.sum_insert ha, Matrix.exp_add_of_commute _ _ hc, ih, ← local_exp, + atSite, ← lift_mul] + congr 1 + funext i + by_cases hi : i = a + · subst i + simp [ha] + · simp [hi] + +theorem exp_sum_atSite_univ (A : ι → Matrix κ κ ℂ) : + NormedSpace.exp (∑ i, atSite i (A i)) = lift (fun i => NormedSpace.exp (A i)) := by + simpa using exp_sum_atSite Finset.univ A + +end TensorMatrix + +namespace TwoState + +def swap : Matrix Bool Bool ℂ := fun a b => if a = !b then 1 else 0 + +def hadamard : Matrix Bool Bool ℂ := fun a b => if a && b then -1 else 1 + +def hadamardUnit : (Matrix Bool Bool ℂ)ˣ where + val := hadamard + inv := (1/2 : ℂ) • hadamard + val_inv := by + ext a b + cases a <;> cases b <;> norm_num [hadamard, Matrix.mul_apply, Fintype.sum_bool] + inv_val := by + ext a b + cases a <;> cases b <;> norm_num [hadamard, Matrix.mul_apply, Fintype.sum_bool] + +theorem conj_diagonal (z : ℂ) : + ((hadamardUnit : (Matrix Bool Bool ℂ)ˣ) : Matrix Bool Bool ℂ) * + Matrix.diagonal (fun b : Bool => if b then -z else z) * ((hadamardUnit⁻¹ : (Matrix Bool Bool ℂ)ˣ) : Matrix Bool Bool ℂ) = z • swap := by + ext a b + cases a <;> cases b <;> + simp [hadamardUnit, hadamard, swap, Matrix.mul_apply] <;> ring + + +theorem exp_swap (z : ℂ) : + NormedSpace.exp (z • swap) = + ((Complex.exp z + Complex.exp (-z))/2) • (1 : Matrix Bool Bool ℂ) + + ((Complex.exp z - Complex.exp (-z))/2) • swap := by + rw [← conj_diagonal z, Matrix.exp_units_conj, Matrix.exp_diagonal] + ext a b + cases a <;> cases b <;> + simp [hadamardUnit, hadamard, swap, Matrix.mul_apply, + ← Complex.exp_eq_exp_ℂ] <;> ring + +def rotation (t : ℝ) : Matrix Bool Bool ℂ := + (Real.cos t : ℂ) • (1 : Matrix Bool Bool ℂ) + + (-(Real.sin t : ℂ) * Complex.I) • swap + +theorem rotation_eq_exp (t : ℝ) : + rotation t = NormedSpace.exp ((-(t : ℂ) * Complex.I) • swap) := by + rw [exp_swap] + have hp : Complex.exp (-(t : ℂ) * Complex.I) = + (Real.cos t : ℂ) - (Real.sin t : ℂ) * Complex.I := by + rw [Complex.exp_mul_I] + simp [← Complex.ofReal_cos, ← Complex.ofReal_sin, sub_eq_add_neg] + have hm : Complex.exp (-(-(t : ℂ) * Complex.I)) = + (Real.cos t : ℂ) + (Real.sin t : ℂ) * Complex.I := by + rw [neg_mul, neg_neg, Complex.exp_mul_I, ← Complex.ofReal_cos, ← Complex.ofReal_sin] + rw [hp, hm] + unfold rotation + congr 1 <;> congr 1 <;> ring + +@[simp] theorem rotation_apply (t : ℝ) (a b : Bool) : + rotation t a b = if a = b then (Real.cos t : ℂ) else -(Real.sin t : ℂ) * Complex.I := by + cases a <;> cases b <;> simp [rotation, swap] + +end TwoState + +namespace SKQAOA + +theorem pauliX_eq_atSite {n : ℕ} (i : Fin n) : + pauliX i = TensorMatrix.atSite i TwoState.swap := by + ext σ τ + have he : TensorMatrix.atSite i TwoState.swap σ τ = + ∏ j, if σ j = Function.update τ i (!(τ i)) j then (1 : ℂ) else 0 := by + unfold TensorMatrix.atSite TensorMatrix.lift + apply Finset.prod_congr rfl + intro j _ + by_cases h : j = i + · subst j + simp [TwoState.swap] + · simp [Function.update_of_ne h, Matrix.one_apply] + rw [he, Fintype.prod_ite_zero] + simp only [Finset.prod_const_one, ← funext_iff, pauliX] + + +theorem cost_evolution_eq_diagonal (n : ℕ) (J : Disorder n) (t : ℝ) : + evolution t (cost n J) = Matrix.diagonal + (fun σ => Complex.exp (-(t : ℂ) * Complex.I * (hamiltonian n J σ : ℂ))) := by + simp only [evolution, cost_eq_diagonal, ← Matrix.diagonal_smul, Matrix.exp_diagonal] + congr 1 + funext σ + simp [← Complex.exp_eq_exp_ℂ] + + +theorem mixer_evolution_eq_tensor (n : ℕ) (t : ℝ) : + evolution t (mixer n) = TensorMatrix.lift (fun _ : Fin n => TwoState.rotation t) := by + unfold evolution mixer + simp_rw [Finset.smul_sum, pauliX_eq_atSite, ← TensorMatrix.local_smul] + rw [TensorMatrix.exp_sum_atSite_univ] + simp only [← TwoState.rotation_eq_exp] + + +theorem mixer_evolution_apply (n : ℕ) (t : ℝ) (σ τ : Configuration n) : + evolution t (mixer n) σ τ = + ∏ i, if σ i = τ i then (Real.cos t : ℂ) else -(Real.sin t : ℂ) * Complex.I := by + rw [mixer_evolution_eq_tensor] + simp [TensorMatrix.lift] + +end SKQAOA + +open scoped BigOperators ComplexConjugate +open MeasureTheory ProbabilityTheory + +namespace GaussianFourier +open scoped _root_.GaussianFourier + +def law (κ : Type*) [Fintype κ] : Measure (κ → ℝ) := + Measure.pi fun _ => gaussianReal 0 1 + +instance (κ : Type*) [Fintype κ] : IsProbabilityMeasure (law κ) := by + unfold law + infer_instance + + +theorem integral_exp (z : ℂ) : + (∫ x : ℝ, Complex.exp (z * x) ∂gaussianReal 0 1) = Complex.exp (z ^ 2 / 2) := by + simpa [complexMGF] using complexMGF_id_gaussianReal (μ := 0) (v := 1) z + +theorem integral_mul_exp (z : ℂ) : + (∫ x : ℝ, (x : ℂ) * Complex.exp (z * x) ∂gaussianReal 0 1) = + z * Complex.exp (z ^ 2 / 2) := by + have h := hasDerivAt_complexMGF (X := id) (μ := gaussianReal 0 1) (z := z) (by simp) + have he : complexMGF id (gaussianReal 0 1) = fun z : ℂ => Complex.exp (z ^ 2 / 2) := by + funext w + simpa using complexMGF_id_gaussianReal (μ := 0) (v := 1) w + rw [he] at h + have hd := (Complex.hasDerivAt_exp (z ^ 2 / 2)).comp z (((hasDerivAt_id z).pow 2).div_const 2) + have hg := h.unique hd + simpa [mul_comm] using hg + +theorem integrable_exp (z : ℂ) : + Integrable (fun x : ℝ => Complex.exp (z * x)) (gaussianReal 0 1) := by + simpa using integrable_pow_mul_cexp_of_re_mem_interior_integrableExpSet + (X := id) (μ := gaussianReal 0 1) (z := z) (by simp) 0 + +theorem integrable_mul_exp (z : ℂ) : + Integrable (fun x : ℝ => (x : ℂ) * Complex.exp (z * x)) (gaussianReal 0 1) := by + simpa using integrable_pow_mul_cexp_of_re_mem_interior_integrableExpSet + (X := id) (μ := gaussianReal 0 1) (z := z) (by simp) 1 + +variable {κ : Type*} [Fintype κ] [DecidableEq κ] + +omit [DecidableEq κ] in + +theorem integral_exp_sum (z : κ → ℂ) : + (∫ x : κ → ℝ, Complex.exp (∑ k, z k * x k) ∂law κ) = + Complex.exp (∑ k, z k ^ 2 / 2) := by + simp_rw [Complex.exp_sum] + rw [law, integral_fintype_prod_eq_prod (fun k (x : ℝ) => Complex.exp (z k * x))] + simp only [integral_exp] + +omit [DecidableEq κ] in +theorem integrable_exp_sum (z : κ → ℂ) : + Integrable (fun x : κ → ℝ => Complex.exp (∑ k, z k * x k)) (law κ) := by + simp_rw [Complex.exp_sum] + exact Integrable.fintype_prod (fun k => integrable_exp (z k)) + +theorem coord_mul_exp_sum (z : κ → ℂ) (i : κ) (x : κ → ℝ) : + (x i : ℂ) * Complex.exp (∑ k, z k * x k) = + ∏ k, if k = i then (x k : ℂ) * Complex.exp (z k * x k) + else Complex.exp (z k * x k) := by + rw [Complex.exp_sum, ← Finset.mul_prod_erase _ _ (Finset.mem_univ i), + ← Finset.mul_prod_erase _ _ (Finset.mem_univ i)] + simp only [ite_true] + rw [mul_assoc] + congr 1 + congr 1 + apply Finset.prod_congr rfl + intro k hk + rw [ite_eq_right (Finset.ne_of_mem_erase hk)] + +theorem integrable_coord_exp_sum (z : κ → ℂ) (i : κ) : + Integrable (fun x : κ → ℝ => (x i : ℂ) * Complex.exp (∑ k, z k * x k)) (law κ) := by + simp_rw [coord_mul_exp_sum] + apply Integrable.fintype_prod (f := fun k (x : ℝ) => + if k = i then (x : ℂ) * Complex.exp (z k * x) else Complex.exp (z k * x)) + intro k + by_cases h : k = i + · simp only [h, ite_true] + exact integrable_mul_exp (z i) + · simp only [h, ite_false] + exact integrable_exp (z k) + +theorem integral_coord_exp_sum (z : κ → ℂ) (i : κ) : + (∫ x : κ → ℝ, (x i : ℂ) * Complex.exp (∑ k, z k * x k) ∂law κ) = + z i * Complex.exp (∑ k, z k ^ 2 / 2) := by + simp_rw [coord_mul_exp_sum] + rw [law, integral_fintype_prod_eq_prod (fun k (x : ℝ) => + if k = i then (x : ℂ) * Complex.exp (z k * x) else Complex.exp (z k * x))] + have hi (k : κ) : (∫ x : ℝ, + (if k = i then (x : ℂ) * Complex.exp (z k * x) else Complex.exp (z k * x)) + ∂gaussianReal 0 1) = + if k = i then z k * Complex.exp (z k ^ 2 / 2) else Complex.exp (z k ^ 2 / 2) := by + split_ifs <;> simp only [integral_mul_exp, integral_exp] + simp_rw [hi] + rw [Complex.exp_sum, ← Finset.mul_prod_erase _ _ (Finset.mem_univ i), + ← Finset.mul_prod_erase _ _ (Finset.mem_univ i)] + simp only [ite_true] + rw [mul_assoc] + congr 1 + congr 1 + apply Finset.prod_congr rfl + intro k hk + rw [ite_eq_right (Finset.ne_of_mem_erase hk)] + +end GaussianFourier + +namespace TensorMatrix + +variable {ι : Type*} [Fintype ι] [DecidableEq ι] +variable {κ : Type*} [Fintype κ] [DecidableEq κ] + +omit [DecidableEq ι] [Fintype κ] [DecidableEq κ] in +@[simp] theorem lift_conjTranspose (A : ι → Matrix κ κ ℂ) : + (lift A)ᴴ = lift (fun i => (A i)ᴴ) := by + ext σ τ + simp [lift, Matrix.conjTranspose_apply] + +omit [DecidableEq ι] [Fintype κ] in +@[simp] theorem lift_diagonal (a : ι → κ → ℂ) : + lift (fun i => Matrix.diagonal (a i)) = Matrix.diagonal (fun σ => ∏ i, a i (σ i)) := by + ext σ τ + by_cases h : σ = τ + · subst τ + simp [lift] + · have he : ∃ i, σ i ≠ τ i := Function.ne_iff.mp h + obtain ⟨i, hi⟩ := he + simp only [lift, Matrix.diagonal_apply_ne _ h] + exact Finset.prod_eq_zero (Finset.mem_univ i) (Matrix.diagonal_apply_ne _ hi) + +omit [Fintype κ] in +@[simp] theorem local_diagonal (i : ι) (a : κ → ℂ) : + atSite i (Matrix.diagonal a) = Matrix.diagonal (fun σ => a (σ i)) := by + have he : (Function.update (fun _ : ι => (1 : Matrix κ κ ℂ)) i (Matrix.diagonal a)) = + fun j => Matrix.diagonal (Function.update (fun _ : ι => fun _ : κ => (1 : ℂ)) i a j) := by + funext j + by_cases h : j = i <;> simp [Function.update, h] + rw [atSite, he, lift_diagonal] + congr 1 + funext σ + rw [← Finset.mul_prod_erase _ _ (Finset.mem_univ i)] + simp only [Function.update_self] + have hp : (∏ j ∈ Finset.univ.erase i, + Function.update (fun _ : ι => fun _ : κ => (1 : ℂ)) i a j (σ j)) = 1 := by + apply Finset.prod_eq_one + intro j hj + rw [Function.update_of_ne (Finset.ne_of_mem_erase hj)] + rw [hp, mul_one] + +theorem conjugate_local (i : ι) (A : Matrix κ κ ℂ) (U : ι → Matrix κ κ ℂ) + (hU : ∀ j, (U j)ᴴ * U j = 1) : + (lift U)ᴴ * atSite i A * lift U = atSite i ((U i)ᴴ * A * U i) := by + simp only [lift_conjTranspose, atSite, ← lift_mul] + congr 1 + funext j + by_cases h : j = i + · subst j + simp + · simp [Function.update_of_ne h, hU] + +end TensorMatrix + +namespace TwoState + +def sign (b : Bool) : ℂ := if b then -1 else 1 + +def z : Matrix Bool Bool ℂ := Matrix.diagonal sign + +def y : Matrix Bool Bool ℂ := Complex.I • (swap * z) + +@[simp] theorem z_apply (a b : Bool) : z a b = if a = b then sign a else 0 := by + simp [z, Matrix.diagonal_apply] + +@[simp] theorem y_apply (a b : Bool) : y a b = if a = !b then -Complex.I * sign a else 0 := by + cases a <;> cases b <;> simp [y, swap, z, sign] + +theorem rotation_star_mul (t : ℝ) : (rotation t)ᴴ * rotation t = 1 := by + ext a b + cases a <;> cases b <;> apply Complex.ext <;> + simp [Matrix.mul_apply, Matrix.conjTranspose_apply, rotation_apply, -Complex.ofReal_sin, -Complex.ofReal_cos, Complex.mul_re, + Complex.mul_im] <;> nlinarith [Real.sin_sq_add_cos_sq t] + +theorem rotation_conjugate_z (t : ℝ) : + (rotation t)ᴴ * z * rotation t = + (Real.cos (2*t) : ℂ) • z + (Real.sin (2*t) : ℂ) • y := by + ext a b + cases a <;> cases b <;> apply Complex.ext <;> + simp [Matrix.mul_apply, Matrix.conjTranspose_apply, rotation_apply, z, y, swap, sign, + Real.cos_two_mul, Real.sin_two_mul, -Complex.ofReal_sin, -Complex.ofReal_cos, + Complex.mul_re, Complex.mul_im, -Complex.ofReal_pow] <;> + nlinarith [Real.sin_sq_add_cos_sq t] + +end TwoState + +namespace SKQAOA + + +def pauliY {n : ℕ} (i : Fin n) : Operator n := TensorMatrix.atSite i TwoState.y + +theorem pauliZ_eq_atSite {n : ℕ} (i : Fin n) : + pauliZ i = TensorMatrix.atSite i TwoState.z := by + simp only [TwoState.z, TensorMatrix.local_diagonal, pauliZ] + congr 1 + funext σ + cases h : σ i <;> simp [spin, TwoState.sign, h] + +theorem mixer_conjugate_pauliZ {n : ℕ} (i : Fin n) (t : ℝ) : + (evolution t (mixer n))ᴴ * pauliZ i * evolution t (mixer n) = + (Real.cos (2*t) : ℂ) • pauliZ i + (Real.sin (2*t) : ℂ) • pauliY i := by + rw [mixer_evolution_eq_tensor, pauliZ_eq_atSite, + TensorMatrix.conjugate_local _ _ _ (fun _ => TwoState.rotation_star_mul t), + TwoState.rotation_conjugate_z, TensorMatrix.local_add, + TensorMatrix.local_smul, TensorMatrix.local_smul] + rfl + +def quad {n : ℕ} (ψ : State n) (A : Operator n) : ℂ := star ψ ⬝ᵥ A.mulVec ψ + +theorem quad_mulVec {n : ℕ} (ψ : State n) (A U : Operator n) : + quad (U.mulVec ψ) A = quad ψ (Uᴴ * A * U) := by + simp only [quad, Matrix.star_mulVec, ← Matrix.dotProduct_mulVec, Matrix.mulVec_mulVec, + Matrix.mul_assoc] + +@[simp] theorem quad_add {n : ℕ} (ψ : State n) (A B : Operator n) : + quad ψ (A+B) = quad ψ A + quad ψ B := by + simp [quad, Matrix.add_mulVec, dotProduct_add] + +@[simp] theorem quad_smul {n : ℕ} (ψ : State n) (a : ℂ) (A : Operator n) : + quad ψ (a • A) = a * quad ψ A := by + simp [quad, Matrix.smul_mulVec, dotProduct_smul] + +end SKQAOA + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ReverseWord.lean b/lean/OAI/Probability/ParisiFinite/ReverseWord.lean new file mode 100644 index 0000000000000000000000000000000000000000..b765b3452c88cc6c797f1be7d10bc50fe33cb32d --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ReverseWord.lean @@ -0,0 +1,719 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SecondCoefficient + +namespace OAI + +/-! Reverse Word. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace TensorWordGram +open QuantumCLT CoherentFock + +variable {κ : Type*} +def reverseWord (neg : κ → κ) (w : List κ) : List κ := w.reverse.map neg + +variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] + [StarRing A] [ContinuousStar A] [StarModule ℂ A] + +omit [StarRing A] [ContinuousStar A] [StarModule ℂ A] in +theorem generators_append (X : κ → A) (u w : List κ) (r : ℝ) : + generators ((u++w).map X) r=generators (u.map X) r*generators (w.map X) r := by + simp [generators] + + +theorem generators_star (neg : κ → κ) (X : κ → A) + (hn : ∀i,X (neg i)= -X i) (hs : ∀i,star (X i)= -X i) (w : List κ) (r : ℝ) : + star (generators (w.map X) r)=generators ((reverseWord neg w).map X) r := by + induction w with + | nil => simp [generators,reverseWord] + | cons i w ih => + simp only [generators,List.map_cons,List.prod_cons,star_mul,NormedSpace.star_exp, + star_smul,Complex.star_def,Complex.conj_ofReal,hs] + change star (generators (w.map X) r)*NormedSpace.exp ((r:ℂ) • (-X i))=_ + rw [ih] + simp only [reverseWord,List.reverse_cons,List.map_append,List.map_singleton, + generators,List.prod_append,List.prod_cons,List.prod_nil,mul_one,hn] + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem weylProduct_append (d : κ → E) (u w : List κ) (x : Space E) : + weylProduct ((u++w).map d) x=weylProduct (u.map d) (weylProduct (w.map d) x) := by + induction u with + | nil => rfl + | cons i u ih => simpa only [List.cons_append,List.map_cons,weylProduct, + ContinuousLinearMap.comp_apply] using congrArg (W (d i)) ih + + +theorem weylProduct_inner (neg : κ → κ) (d : κ → E) + (hn : ∀i,d (neg i)= -d i) (w : List κ) (x y : Space E) : + ⟪weylProduct (w.map d) x,y⟫_ℂ= + ⟪x,weylProduct ((reverseWord neg w).map d) y⟫_ℂ := by + induction w generalizing x y with + | nil => rfl + | cons i w ih => + change ⟪W (d i) (weylProduct (w.map d) x),y⟫_ℂ=_ + have hi : ⟪W (d i) (weylProduct (w.map d) x),y⟫_ℂ= + ⟪weylProduct (w.map d) x,W (-d i) y⟫_ℂ := by + exact (weyl (d i)).inner_map_eq_flip _ _ + rw [hi,ih] + rw [show reverseWord neg (i::w)=reverseWord neg w++[neg i] by simp [reverseWord], + weylProduct_append] + simp only [List.map_singleton,weylProduct,ContinuousLinearMap.comp_apply, + ContinuousLinearMap.id_apply,hn] + + + +theorem tensor_word_gram_limit + (ι : ℕ → Type*) [∀n,Fintype (ι n)] [∀n,DecidableEq (ι n)] [∀n,Nonempty (ι n)] + (Ω : ∀n,EuclideanSpace ℂ (ι n)) + (X : ∀n,κ → EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + (neg : κ → κ) (d : κ → E) (L : ℝ) (hL : 0≤L) + (hΩ : ∀n,‖Ω n‖=1) (hX : ∀n i,‖X n i‖≤L) + (hneg : ∀n i,X n (neg i)= -X n i) (hstar : ∀n i,star (X n i)= -X n i) + (hdneg : ∀i,d (neg i)= -d i) + (hc : ∀n i,⟪Ω n,X n i (Ω n)⟫_ℂ=0) + (hq : ∀i j,Tendsto (fun n => ⟪Ω n,X n i (X n j (Ω n))⟫_ℂ) + atTop (𝓝 (-⟪d i,d j⟫_ℂ))) (u w : List κ) : + Tendsto (fun n => ⟪FiniteTensor.power n ((generators (u.map (X n)) (Real.sqrt (n:ℝ))⁻¹) (Ω n)), + FiniteTensor.power n ((generators (w.map (X n)) (Real.sqrt (n:ℝ))⁻¹) (Ω n))⟫_ℂ) + atTop (𝓝 ⟪weylProduct (u.map d) (coherent 0),weylProduct (w.map d) (coherent 0)⟫_ℂ) := by + let l := reverseWord neg u++w + have hφ (n : ℕ) : ‖vacuumFunctional (Ω n)‖≤1 := by + simpa only [hΩ n,one_pow] using vacuumFunctional_norm (Ω n) + have h1 (n : ℕ) : vacuumFunctional (Ω n) 1=1 := by + simp only [vacuumFunctional_apply,one_apply_eq_self,inner_self_eq_norm_sq_to_K,hΩ n] + norm_num + have hz (n : ℕ) : vacuumFunctional (Ω n) (l.map (X n)).sum=0 := by + unfold vacuumFunctional + change ⟪Ω n,((l.map (X n)).sum) (Ω n)⟫_ℂ=0 + induction l with + | nil => simp + | cons i l ih => + simp only [List.map_cons,List.sum_cons,add_apply,inner_add_right,hc] + simpa only [zero_add] using ih + have hh := moving_generators_weyl_limit + (fun n => EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + l X (fun n => vacuumFunctional (Ω n)) d L 1 hL (by norm_num) + (fun n i _ => hX n i) hφ h1 hz (fun i _ j _ => by + simpa only [vacuumFunctional_apply,mul_apply_eq_comp] using hq i j) + have he (n : ℕ) : + ⟪FiniteTensor.power n ((generators (u.map (X n)) (Real.sqrt (n:ℝ))⁻¹) (Ω n)), + FiniteTensor.power n ((generators (w.map (X n)) (Real.sqrt (n:ℝ))⁻¹) (Ω n))⟫_ℂ = + (vacuumFunctional (Ω n) (generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹))^n := by + rw [FiniteTensor.inner_power] + congr 1 + rw [vacuumFunctional_apply,generators_append] + rw [←generators_star neg (X n) (hneg n) (hstar n)] + exact (ContinuousLinearMap.adjoint_inner_right _ _ _).symm + simp_rw [he] + have href : ⟪weylProduct (u.map d) (coherent 0),weylProduct (w.map d) (coherent 0)⟫_ℂ= + ⟪coherent 0,weylProduct (l.map d) (coherent 0)⟫_ℂ := by + rw [weylProduct_inner neg d hdneg] + rw [weylProduct_append] + rw [href] + exact hh + +end TensorWordGram + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace TensorPackets +open QuantumCLT CoherentFock SpinOperators + +structure Term (κ : Type*) where + spin : Fin 2 + coeff : ℂ + history : List κ + +variable {κ H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +def term (s : List κ → H) (t : Term κ) : Double H := + t.coeff • PiLp.single 2 t.spin (s t.history) + +def packet (s : List κ → H) (ts : List (Term κ)) : Double H := + (ts.map (term s)).sum + +@[simp] theorem term_apply (s : List κ → H) (t : Term κ) (i : Fin 2) : + term s t i = if i=t.spin then t.coeff • s t.history else 0 := by + classical + simp only [term,PiLp.smul_apply,PiLp.single_apply] + split_ifs <;> simp_all + +theorem inner_term (s : List κ → H) (t u : Term κ) : + ⟪term s t,term s u⟫_ℂ = + if t.spin=u.spin then star t.coeff*u.coeff*⟪s t.history,s u.history⟫_ℂ else 0 := by + classical + simp only [PiLp.inner_apply,term_apply] + obtain ⟨j,c,w⟩ := t + obtain ⟨k,b,v⟩ := u + fin_cases j <;> fin_cases k <;> simp [inner_smul_left,inner_smul_right,mul_assoc,mul_left_comm] + +@[simp] theorem packet_nil (s : List κ → H) : packet s []=0 := rfl +@[simp] theorem packet_cons (s : List κ → H) (t : Term κ) (ts : List (Term κ)) : + packet s (t::ts)=term s t+packet s ts := rfl + +theorem Gram_limit + (Hn : ℕ → Type*) [∀n,NormedAddCommGroup (Hn n)] [∀n,InnerProductSpace ℂ (Hn n)] + (sn : ∀n,List κ → Hn n) (s : List κ → H) + (hg : ∀u w,Tendsto (fun n => ⟪sn n u,sn n w⟫_ℂ) atTop (𝓝 ⟪s u,s w⟫_ℂ)) + (ts us : List (Term κ)) : + Tendsto (fun n => ⟪packet (sn n) ts,packet (sn n) us⟫_ℂ) + atTop (𝓝 ⟪packet s ts,packet s us⟫_ℂ) := by + have ht (t u : Term κ) : Tendsto (fun n => ⟪term (sn n) t,term (sn n) u⟫_ℂ) + atTop (𝓝 ⟪term s t,term s u⟫_ℂ) := by + simp_rw [inner_term] + split_ifs + · exact tendsto_const_nhds.mul (hg _ _) + · exact tendsto_const_nhds + have hp (t : Term κ) (us : List (Term κ)) : + Tendsto (fun n => ⟪term (sn n) t,packet (sn n) us⟫_ℂ) + atTop (𝓝 ⟪term s t,packet s us⟫_ℂ) := by + induction us with + | nil => simp only [packet_nil,inner_zero_right]; exact tendsto_const_nhds + | cons u us ih => simp only [packet_cons,inner_add_right]; exact (ht t u).add ih + induction ts with + | nil => simp only [packet_nil,inner_zero_left]; exact tendsto_const_nhds + | cons t ts ih => simp only [packet_cons,inner_add_left]; exact (hp t us).add ih + + +def mixTerm (A : Matrix (Fin 2) (Fin 2) ℂ) (t : Term κ) : List (Term κ) := + [⟨0,A 0 t.spin*t.coeff,t.history⟩,⟨1,A 1 t.spin*t.coeff,t.history⟩] + +def mixPacket (A : Matrix (Fin 2) (Fin 2) ℂ) (ts : List (Term κ)) : List (Term κ) := + ts.flatMap (mixTerm A) + +theorem act_term (s : List κ → H) (A : Matrix (Fin 2) (Fin 2) ℂ) (t : Term κ) : + act A (term s t)=packet s (mixTerm A t) := by + classical + ext i + simp only [act_apply,term_apply] + simp only [mixTerm,packet_cons,packet_nil,PiLp.add_apply,term_apply, + Fin.sum_univ_two,add_zero] + obtain ⟨j,c,w⟩ := t + fin_cases i <;> fin_cases j <;> simp [smul_smul] + +theorem act_packet (s : List κ → H) (A : Matrix (Fin 2) (Fin 2) ℂ) (ts : List (Term κ)) : + act A (packet s ts)=packet s (mixPacket A ts) := by + induction ts with + | nil => simp [mixPacket] + | cons t ts ih => + rw [packet_cons,map_add,act_term,ih] + simp only [mixPacket,List.flatMap_cons,packet,List.map_append,List.sum_append] + + +def prefixTerm (a : Fin 2 → κ) (t : Term κ) : Term κ := + ⟨t.spin,t.coeff,a t.spin::t.history⟩ +def prefixPacket (a : Fin 2 → κ) (ts : List (Term κ)) : List (Term κ) := + ts.map (prefixTerm a) + + +def diagonal (K : Fin 2 → H →L[ℂ] H) : Double H →L[ℂ] Double H := + (PiLp.continuousLinearEquiv 2 ℂ (fun _ : Fin 2 => H)).symm.toContinuousLinearMap.comp + (ContinuousLinearMap.pi (fun i => (K i).comp (PiLp.proj 2 (fun _ : Fin 2 => H) i))) +@[simp] theorem diagonal_apply (K : Fin 2 → H →L[ℂ] H) (x : Double H) (i : Fin 2) : + diagonal K x i=K i (x i) := by simp [diagonal,PiLp.proj_apply] + +theorem diagonal_term (s : List κ → H) (K : Fin 2 → H →L[ℂ] H) (a : Fin 2 → κ) + (ha : ∀i w,K i (s w)=s (a i::w)) (t : Term κ) : + diagonal K (term s t)=term s (prefixTerm a t) := by + classical + ext i + simp only [diagonal_apply,term_apply,prefixTerm] + split_ifs with h + · rw [h,map_smul,ha] + · exact map_zero _ + +theorem diagonal_packet (s : List κ → H) (K : Fin 2 → H →L[ℂ] H) (a : Fin 2 → κ) + (ha : ∀i w,K i (s w)=s (a i::w)) (ts : List (Term κ)) : + diagonal K (packet s ts)=packet s (prefixPacket a ts) := by + induction ts with + | nil => simp [prefixPacket] + | cons t ts ih => simp only [packet_cons,map_add,diagonal_term s K a ha,ih, + prefixPacket,List.map_cons] + +end TensorPackets + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace RootTensorCLT +open QuantumCLT CoherentFock SpinOperators TensorPackets + +inductive Pulse (κ : Type*) + | root (A : Matrix (Fin 2) (Fin 2) ℂ) + | control (a : Fin 2 → κ) + +variable {κ H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +def applyPulse (K : κ → H →L[ℂ] H) : Pulse κ → Double H →L[ℂ] Double H + | .root A => act A + | .control a => diagonal (K ∘ a) + +def run (K : κ → H →L[ℂ] H) : List (Pulse κ) → Double H →L[ℂ] Double H + | [] => ContinuousLinearMap.id ℂ _ + | p::w => (applyPulse K p).comp (run K w) + +def compilePulse : Pulse κ → List (Term κ) → List (Term κ) + | .root A => mixPacket A + | .control a => prefixPacket a + +def compile : List (Pulse κ) → List (Term κ) → List (Term κ) + | [] => id + | p::w => compilePulse p ∘ compile w + +theorem applyPulse_packet (s : List κ → H) (K : κ → H →L[ℂ] H) + (hs : ∀i w,K i (s w)=s (i::w)) (p : Pulse κ) (ts : List (Term κ)) : + applyPulse K p (packet s ts)=packet s (compilePulse p ts) := by + cases p with + | root A => exact act_packet s A ts + | control a => exact diagonal_packet s (K ∘ a) a (fun i w => hs (a i) w) ts + +theorem run_packet (s : List κ → H) (K : κ → H →L[ℂ] H) + (hs : ∀i w,K i (s w)=s (i::w)) (w : List (Pulse κ)) (ts : List (Term κ)) : + run K w (packet s ts)=packet s (compile w ts) := by + induction w with + | nil => rfl + | cons p w ih => + change applyPulse K p (run K w (packet s ts))=_ + rw [ih,applyPulse_packet s K hs] + rfl + +def start : List (Term κ) := + [⟨0,(((Real.sqrt 2)⁻¹:ℝ):ℂ),[]⟩,⟨1,(((Real.sqrt 2)⁻¹:ℝ):ℂ),[]⟩] + +theorem start_packet (s : List κ → H) : packet s start=PointedTree.plusEmbedding (s []) := by + ext i + fin_cases i <;> simp [start,packet_cons,term_apply,PointedTree.plusEmbedding_apply] + + + +def tensorState {ι : Type*} [Fintype ι] + (D : ℕ) (Ω : EuclideanSpace ℂ ι) + (X : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) (w : List κ) : + EuclideanSpace ℂ (Fin D → ι) := + FiniteTensor.power D ((generators (w.map X) (Real.sqrt (D:ℝ))⁻¹) Ω) + +def tensorPulse {ι : Type*} [Fintype ι] [DecidableEq ι] + (D : ℕ) (X : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) (i : κ) : + EuclideanSpace ℂ (Fin D → ι) →L[ℂ] EuclideanSpace ℂ (Fin D → ι) := + FiniteTensor.operatorPower D (NormedSpace.exp (((Real.sqrt (D:ℝ))⁻¹:ℂ) • X i)) + +theorem tensor_step {ι : Type*} [Fintype ι] [DecidableEq ι] + (D : ℕ) (Ω : EuclideanSpace ℂ ι) + (X : κ → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) (i : κ) (w : List κ) : + tensorPulse D X i (tensorState D Ω X w)=tensorState D Ω X (i::w) := by + rw [tensorPulse,tensorState,FiniteTensor.operatorPower_apply] + simp only [tensorState,generators,List.map_cons,List.prod_cons,mul_apply_eq_comp,Complex.ofReal_inv] + +def fockState {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (d : κ → E) (w : List κ) : Space E := weylProduct (w.map d) (coherent 0) + +theorem fock_step {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (d : κ → E) (i : κ) (w : List κ) : W (d i) (fockState d w)=fockState d (i::w) := rfl + + + +theorem root_circuit_Gram_limit + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (ι : ℕ → Type*) [∀n,Fintype (ι n)] [∀n,DecidableEq (ι n)] [∀n,Nonempty (ι n)] + (Ω : ∀n,EuclideanSpace ℂ (ι n)) + (X : ∀n,κ → EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + (neg : κ → κ) (d : κ → E) (L : ℝ) (hL : 0≤L) + (hΩ : ∀n,‖Ω n‖=1) (hX : ∀n i,‖X n i‖≤L) + (hneg : ∀n i,X n (neg i)= -X n i) (hstar : ∀n i,star (X n i)= -X n i) + (hdneg : ∀i,d (neg i)= -d i) + (hc : ∀n i,⟪Ω n,X n i (Ω n)⟫_ℂ=0) + (hq : ∀i j,Tendsto (fun n => ⟪Ω n,X n i (X n j (Ω n))⟫_ℂ) + atTop (𝓝 (-⟪d i,d j⟫_ℂ))) (u w : List (Pulse κ)) : + Tendsto (fun n => + ⟪run (tensorPulse n (X n)) u (PointedTree.plusEmbedding (FiniteTensor.power n (Ω n))), + run (tensorPulse n (X n)) w (PointedTree.plusEmbedding (FiniteTensor.power n (Ω n)))⟫_ℂ) + atTop (𝓝 ⟪run (W ∘ d) u (PointedTree.vacuum E),run (W ∘ d) w (PointedTree.vacuum E)⟫_ℂ) := by + have hg := TensorWordGram.tensor_word_gram_limit ι Ω X neg d L hL hΩ hX hneg hstar hdneg hc hq + have hall := TensorPackets.Gram_limit + (fun n => EuclideanSpace ℂ (Fin n → ι n)) (fun n => tensorState n (Ω n) (X n)) + (fockState d) hg (compile u start) (compile w start) + have hn (n : ℕ) (v : List (Pulse κ)) : + run (tensorPulse n (X n)) v (PointedTree.plusEmbedding (FiniteTensor.power n (Ω n)))= + packet (tensorState n (Ω n) (X n)) (compile v start) := by + have he : tensorState n (Ω n) (X n) []=FiniteTensor.power n (Ω n) := by + simp [tensorState,generators] + rw [←he,←start_packet,run_packet _ _ (tensor_step n (Ω n) (X n))] + have hf (v : List (Pulse κ)) : + run (W ∘ d) v (PointedTree.vacuum E)=packet (fockState d) (compile v start) := by + change run (W ∘ d) v (PointedTree.plusEmbedding (fockState d []))=_ + rw [←start_packet] + exact run_packet (fockState d) (W ∘ d) (fock_step d) v start + simpa only [hn,hf] using hall + +end RootTensorCLT + + + +open scoped InnerProductSpace BigOperators +namespace FiniteTensor +open Matrix +variable {ι : Type*} [Fintype ι] [DecidableEq ι] + +omit [Fintype ι] in +theorem matrixPower_one (D : ℕ) : matrixPower D (1 : Matrix ι ι ℂ)=1 := by + classical + ext σ τ + simp only [matrixPower,Matrix.one_apply] + by_cases h : σ=τ + · subst τ; simp + · rw [ite_eq_right h] + obtain ⟨i,hi⟩ := Function.ne_iff.mp h + apply Finset.prod_eq_zero (Finset.mem_univ i) + exact ite_eq_right hi + +omit [DecidableEq ι] in +theorem matrixPower_mul (D : ℕ) (A B : Matrix ι ι ℂ) : + matrixPower D (A*B)=matrixPower D A*matrixPower D B := by + ext σ τ + simp only [matrixPower,Matrix.mul_apply] + rw [Fintype.prod_sum] + apply Finset.sum_congr rfl + intro v hv + exact Finset.prod_mul_distrib + +omit [Fintype ι] [DecidableEq ι] in +theorem matrixPower_star (D : ℕ) (A : Matrix ι ι ℂ) : + matrixPower D (star A)=star (matrixPower D A) := by + ext σ τ + simp only [matrixPower,Matrix.star_apply,star_prod] + +theorem operatorPower_one (D : ℕ) : + operatorPower D (1 : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι)=1 := by + simp [operatorPower,matrixPower_one] + +theorem operatorPower_mul (D : ℕ) (A B : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + operatorPower D (A*B)=operatorPower D A*operatorPower D B := by + simp [operatorPower,matrixPower_mul] + +theorem operatorPower_star (D : ℕ) (A : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + operatorPower D (star A)=star (operatorPower D A) := by + unfold operatorPower + have hs : (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm (star A)= + star ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm A) := + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm.map_star' A + rw [hs,matrixPower_star] + exact (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin D → ι)).map_star' _ + + + +theorem operatorPower_unitary (D : ℕ) (A : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (hA : A ∈ unitary _) : operatorPower D A ∈ unitary _ := by + rw [Unitary.mem_iff] at hA ⊢ + constructor + · rw [←operatorPower_star,←operatorPower_mul,hA.1,operatorPower_one] + · rw [←operatorPower_star,←operatorPower_mul,hA.2,operatorPower_one] + +end FiniteTensor + +namespace TensorPackets +open SpinOperators +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + +omit [CompleteSpace H] in +theorem diagonal_mul (K L : Fin 2 → H →L[ℂ] H) : + diagonal (fun i => K i*L i)=diagonal K*diagonal L := by + ext x i + simp only [diagonal_apply,mul_apply_eq_comp] + +omit [CompleteSpace H] in +theorem diagonal_one : diagonal (fun _ : Fin 2 => (1 : H →L[ℂ] H))=1 := by + ext x i + simp + +theorem diagonal_star (K : Fin 2 → H →L[ℂ] H) : + diagonal (fun i => star (K i))=star (diagonal K) := by + apply ContinuousLinearMap.ext + intro x + apply ext_inner_right ℂ + intro y + change ⟪diagonal (fun i => star (K i)) x,y⟫_ℂ= + ⟪ContinuousLinearMap.adjoint (diagonal K) x,y⟫_ℂ + rw [ContinuousLinearMap.adjoint_inner_left] + simp only [PiLp.inner_apply,diagonal_apply,ContinuousLinearMap.star_eq_adjoint, + ContinuousLinearMap.adjoint_inner_left] + +theorem diagonal_unitary (K : Fin 2 → H →L[ℂ] H) (hK : ∀i,K i ∈ unitary _) : + diagonal K ∈ unitary _ := by + rw [Unitary.mem_iff] + have hl (i : Fin 2) : star (K i)*K i=1 := (Unitary.mem_iff.mp (hK i)).1 + have hr (i : Fin 2) : K i*star (K i)=1 := (Unitary.mem_iff.mp (hK i)).2 + constructor + · rw [←diagonal_star,←diagonal_mul]; simp_rw [hl]; exact diagonal_one + · rw [←diagonal_star,←diagonal_mul]; simp_rw [hr]; exact diagonal_one + +end TensorPackets + + + +open scoped InnerProductSpace BigOperators +namespace FiniteTree +open SpinOperators PointedTree + + + +@[reducible] def Index (D : ℕ) : ℕ → Type + | 0 => Fin 2 + | h+1 => Σ _ : Fin 2, Fin D → Index D h + +@[reducible] instance indexFintype (D : ℕ) : (h : ℕ) → Fintype (Index D h) + | 0 => inferInstanceAs (Fintype (Fin 2)) + | h+1 => by + have := indexFintype D h + exact inferInstanceAs (Fintype (Σ _ : Fin 2, Fin D → Index D h)) +@[reducible] instance indexDecidableEq (D : ℕ) : (h : ℕ) → DecidableEq (Index D h) + | 0 => inferInstanceAs (DecidableEq (Fin 2)) + | h+1 => by + have := indexDecidableEq D h + exact inferInstanceAs (DecidableEq (Σ _ : Fin 2, Fin D → Index D h)) +instance indexNonempty (D : ℕ) : (h : ℕ) → Nonempty (Index D h) + | 0 => inferInstanceAs (Nonempty (Fin 2)) + | h+1 => by + exact ⟨⟨0, fun _ => Classical.choice (indexNonempty D h)⟩⟩ + +abbrev Space (D h : ℕ) := EuclideanSpace ℂ (Index D h) + +@[reducible] def Tail (D : ℕ) : ℕ → Type + | 0 => ℂ + | h+1 => EuclideanSpace ℂ (Fin D → Index D h) +@[reducible] instance tailNormed (D : ℕ) : (h : ℕ) → NormedAddCommGroup (Tail D h) + | 0 => inferInstanceAs (NormedAddCommGroup ℂ) + | h+1 => inferInstanceAs (NormedAddCommGroup (EuclideanSpace ℂ (Fin D → Index D h))) +@[reducible] instance tailInner (D : ℕ) : (h : ℕ) → InnerProductSpace ℂ (Tail D h) + | 0 => inferInstanceAs (InnerProductSpace ℂ ℂ) + | h+1 => inferInstanceAs (InnerProductSpace ℂ (EuclideanSpace ℂ (Fin D → Index D h))) +instance tailComplete (D : ℕ) : (h : ℕ) → CompleteSpace (Tail D h) + | 0 => inferInstanceAs (CompleteSpace ℂ) + | h+1 => inferInstanceAs (CompleteSpace (EuclideanSpace ℂ (Fin D → Index D h))) + + +def split (D : ℕ) : (h : ℕ) → Space D h ≃ₗᵢ[ℂ] Double (Tail D h) + | 0 => LinearIsometryEquiv.refl ℂ _ + | h+1 => LinearIsometryEquiv.piLpCurry ℂ 2 (fun (_ : Fin 2) (_ : Fin D → Index D h) => ℂ) + + +def root (D h : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) : Space D h →L[ℂ] Space D h := + (split D h).symm.conjStarAlgEquiv (act A) + +@[simp] theorem split_root (D h : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (x : Space D h) : + split D h (root D h A x)=act A (split D h x) := by simp [root] + +theorem root_one (D h : ℕ) : root D h 1=1 := by + unfold root + rw [act_one] + exact map_one _ +theorem root_mul (D h : ℕ) (A B : Matrix (Fin 2) (Fin 2) ℂ) : + root D h (A*B)=root D h A*root D h B := by + change (split D h).symm.conjStarAlgEquiv (act (A*B))=_ + rw [act_mul] + exact map_mul _ _ _ +theorem root_star (D h : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) : + root D h (star A)=star (root D h A) := by + unfold root + rw [show act (star A)=(star (act A : Double (Tail D h) →L[ℂ] Double (Tail D h))) + from (starRep (H := Tail D h)).map_star' A] + exact (split D h).symm.conjStarAlgEquiv.map_star' _ + +theorem root_unitary (D h : ℕ) {A : Matrix (Fin 2) (Fin 2) ℂ} (hA : A ∈ unitary _) : + root D h A ∈ unitary _ := + by + rw [Unitary.mem_iff] at hA ⊢ + constructor + · rw [←root_star,←root_mul,hA.1,root_one] + · rw [←root_star,←root_mul,hA.2,root_one] + + +def vac (D : ℕ) : (h : ℕ) → Space D h + | 0 => PointedTree.plus + | h+1 => (split D (h+1)).symm (plusEmbedding (FiniteTensor.power D (vac D h))) + +theorem norm_power_of_norm_one {ι : Type*} [Fintype ι] + (D : ℕ) (v : EuclideanSpace ℂ ι) (hv : ‖v‖=1) : ‖FiniteTensor.power D v‖=1 := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),FiniteTensor.inner_power, + inner_self_eq_norm_sq_to_K,hv] + norm_num + +@[simp] theorem norm_vac (D h : ℕ) : ‖vac D h‖=1 := by + induction h with + | zero => exact PointedTree.norm_plus + | succ h ih => + rw [vac,LinearIsometryEquiv.norm_map] + exact (plusEmbedding.norm_map _).trans (norm_power_of_norm_one D (vac D h) ih) + + + +def control (D h : ℕ) (K : Fin 2 → Space D h →L[ℂ] Space D h) : + Space D (h+1) →L[ℂ] Space D (h+1) := + (split D (h+1)).symm.conjStarAlgEquiv (TensorPackets.diagonal (fun i => FiniteTensor.operatorPower D (K i))) + +@[simp] theorem split_control (D h : ℕ) (K : Fin 2 → Space D h →L[ℂ] Space D h) + (x : Space D (h+1)) : + split D (h+1) (control D h K x)= + TensorPackets.diagonal (fun i => FiniteTensor.operatorPower D (K i)) (split D (h+1) x) := by + simp only [control, LinearIsometryEquiv.conjStarAlgEquiv_apply_apply, + LinearIsometryEquiv.symm_symm, LinearIsometryEquiv.apply_symm_apply] + +theorem isometry_conj_unitary {H K : Type*} + [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + [NormedAddCommGroup K] [InnerProductSpace ℂ K] [CompleteSpace K] + (e : H ≃ₗᵢ[ℂ] K) (A : H →L[ℂ] H) (hA : A ∈ unitary _) : + e.conjStarAlgEquiv A ∈ unitary _ := by + let f := e.conjStarAlgEquiv + have hs : star (f A)=f (star A) := (f.map_star' A).symm + have hm (B C : H →L[ℂ] H) : f (B*C)=f B*f C := f.map_mul' B C + have ho : f 1=1 := map_one f + change f A ∈ unitary _ + rw [Unitary.mem_iff] at hA ⊢ + constructor + · rw [hs,←hm,hA.1,ho] + · rw [hs,←hm,hA.2,ho] + +theorem control_unitary (D h : ℕ) (K : Fin 2 → Space D h →L[ℂ] Space D h) + (hK : ∀i,K i ∈ unitary _) : control D h K ∈ unitary _ := + isometry_conj_unitary (split D (h+1)).symm _ + (TensorPackets.diagonal_unitary _ (fun i => FiniteTensor.operatorPower_unitary D (K i) (hK i))) + +end FiniteTree + + + +open scoped InnerProductSpace BigOperators +namespace FiniteTree +open SpinOperators TensorPackets RootSpin + + +def spinFlip {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (T : H →L[ℂ] H) : Double H →L[ℂ] Double H := + act X*TensorPackets.diagonal (fun _ => T) + +@[simp] theorem spinFlip_apply {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (T : H →L[ℂ] H) (x : Double H) (i : Fin 2) : + spinFlip T x i=T (x (1-i)) := by + fin_cases i <;> simp [spinFlip,mul_apply_eq_comp,act_apply,X,Fin.sum_univ_two] + +theorem spinFlip_square {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (T : H →L[ℂ] H) (hT : T*T=1) : spinFlip T*spinFlip T=1 := by + ext x i + have ht (y : H) : T (T y)=y := by + simpa only [mul_apply_eq_comp,one_apply_eq_self] using congrArg (fun A : H →L[ℂ] H => A y) hT + fin_cases i <;> simp [mul_apply_eq_comp,spinFlip_apply,ht] + +theorem spinFlip_unitary {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + [CompleteSpace H] (T : H →L[ℂ] H) (hT : T ∈ unitary _) : spinFlip T ∈ unitary _ := by + exact (unitary _).mul_mem (act_mem_unitary X_unitary) (diagonal_unitary _ (fun _ => hT)) + +theorem spinFlip_Z {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (T : H →L[ℂ] H) (x : Double H) : + spinFlip T (act Z x)= -act Z (spinFlip T x) := by + ext i + fin_cases i <;> simp [spinFlip_apply,act_apply,Z,Fin.sum_univ_two] + +theorem spinFlip_R {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (T : H →L[ℂ] H) (t : ℝ) (x : Double H) : + spinFlip T (act (R t) x)=act (R t) (spinFlip T x) := by + ext i + fin_cases i <;> simp [spinFlip_apply,act_apply,R,X,Fin.sum_univ_two,map_add,map_smul,add_comm] + + +def flip (D : ℕ) : (h : ℕ) → Space D h →L[ℂ] Space D h + | 0 => root D 0 X + | h+1 => (split D (h+1)).symm.conjStarAlgEquiv + (spinFlip (FiniteTensor.operatorPower D (flip D h))) + +theorem flip_square (D h : ℕ) : flip D h*flip D h=1 := by + induction h with + | zero => rw [flip,←root_mul,X_sq,root_one] + | succ h ih => + change (split D (h+1)).symm.conjStarAlgEquiv _*(split D (h+1)).symm.conjStarAlgEquiv _=_ + rw [←map_mul,spinFlip_square _ (by rw [←FiniteTensor.operatorPower_mul,ih,FiniteTensor.operatorPower_one]),map_one] + +theorem flip_unitary (D h : ℕ) : flip D h ∈ unitary _ := by + induction h with + | zero => exact root_unitary D 0 X_unitary + | succ h ih => + exact isometry_conj_unitary (split D (h+1)).symm _ + (spinFlip_unitary _ (FiniteTensor.operatorPower_unitary D _ ih)) + +@[simp] theorem split_flip (D h : ℕ) (x : Space D (h+1)) : + split D (h+1) (flip D (h+1) x)= + spinFlip (FiniteTensor.operatorPower D (flip D h)) (split D (h+1) x) := by + simp [flip] + +theorem flip_vac (D h : ℕ) : flip D h (vac D h)=vac D h := by + induction h with + | zero => + change act X PointedTree.plus=PointedTree.plus + ext i + fin_cases i <;> simp [act_apply,X,Fin.sum_univ_two,PointedTree.plus] + | succ h ih => + apply (split D (h+1)).injective + rw [split_flip] + simp only [vac,LinearIsometryEquiv.apply_symm_apply] + ext i + simp only [spinFlip_apply,PointedTree.plusEmbedding_apply,map_smul, + FiniteTensor.operatorPower_apply,ih] + +theorem flip_rootZ (D h : ℕ) (x : Space D h) : + flip D h (root D h Z x)= -root D h Z (flip D h x) := by + cases h with + | zero => + change act X (act Z x)= -act Z (act X x) + ext i + fin_cases i <;> simp [act_apply,X,Z,Fin.sum_univ_two] + | succ h => + apply (split D (h+1)).injective + rw [split_flip,split_root,map_neg,split_root,split_flip] + exact spinFlip_Z _ _ + +theorem flip_rootR (D h : ℕ) (t : ℝ) (x : Space D h) : + flip D h (root D h (R t) x)=root D h (R t) (flip D h x) := by + cases h with + | zero => + change act X (act (R t) x)=act (R t) (act X x) + ext i + fin_cases i <;> simp [act_apply,X,R,Fin.sum_univ_two,add_comm] + | succ h => + apply (split D (h+1)).injective + rw [split_flip,split_root,split_root,split_flip] + exact spinFlip_R _ _ _ + +end FiniteTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/RotateIJApply.lean b/lean/OAI/Probability/ParisiFinite/RotateIJApply.lean new file mode 100644 index 0000000000000000000000000000000000000000..4cc73c679f29da3c603c14c3cb58fbd395b140f6 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/RotateIJApply.lean @@ -0,0 +1,375 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SpinMatrix + +namespace OAI + +/-! Rotate I J Apply. -/ + +noncomputable section + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ComplexConjugate +open MeasureTheory ProbabilityTheory +open scoped Topology +open Filter +open scoped BigOperators Matrix +open scoped Matrix Matrix.Norms.L2Operator +namespace QuaternionControl +open PulseControl SeedControl +open scoped Matrix.Norms.L2Operator + +variable {ι : Type*} [Fintype ι] +local instance rotateIJQFieldNormedAlgebra : NormedAlgebra ℚ (QField ι) := + NormedAlgebra.restrictScalars ℚ ℝ (QField ι) + +@[simp] theorem rotateIJ_apply (a b : ℝ) (h : a^2+b^2=1) (q : Quaternion ℝ) : + rotateIJ a b h q = ⟨q.re,a*q.imI-b*q.imJ,b*q.imI+a*q.imJ,q.imK⟩ := rfl + +@[simp] theorem toPauli_apply (q : Quaternion ℝ) : + toPauli q = !![(q.re:ℂ)-Complex.I*q.imI, -(q.imJ:ℂ)+Complex.I*q.imK; + (q.imJ:ℂ)+Complex.I*q.imK, (q.re:ℂ)+Complex.I*q.imI] := rfl + +def matrixMap (a b : ℝ) (hab : a^2+b^2=1) : QField ι →ₐ[ℝ] (ι → SpinMatrix) where + toFun q i := toPauli (rotateIJ a b hab (q i)) + map_zero' := by funext i; change toPauli (rotateIJ a b hab 0) = 0; simp only [map_zero] + map_one' := by funext i; change toPauli (rotateIJ a b hab 1) = 1; simp only [map_one] + map_add' q r := by funext i; change toPauli (rotateIJ a b hab (q i+r i)) = _; simp only [map_add,Pi.add_apply] + map_mul' q r := by funext i; change toPauli (rotateIJ a b hab (q i*r i)) = _; simp only [map_mul,Pi.mul_apply] + commutes' r := by + funext i + change toPauli (rotateIJ a b hab (algebraMap ℝ (Quaternion ℝ) r)) = algebraMap ℝ SpinMatrix r + rw [(rotateIJ a b hab).commutes,toPauli.commutes] + +omit [Fintype ι] in +@[simp] theorem matrixMap_apply (a b : ℝ) (hab : a^2+b^2=1) (q : QField ι) (i : ι) : + matrixMap a b hab q i = toPauli (rotateIJ a b hab (q i)) := rfl + +omit [Fintype ι] in +def spinGen (a b : ℝ) (c d : ι → ℝ) (e : Bool) : ι → SpinMatrix := + if e then fun i => c i • (a • z+b • y) else fun i => d i • ((-b) • z+a • y) + +omit [Fintype ι] in +theorem matrixMap_gen (a b : ℝ) (hab : a^2+b^2=1) (c d : ι → ℝ) : + matrixMap a b hab ∘ gen c d = spinGen a b c d := by + funext e i + cases e + · change toPauli (rotateIJ a b hab (⟨0,0,d i,0⟩ : Quaternion ℝ)) = d i • ((-b) • z+a • y) + change !![(0:ℂ)-Complex.I*((a*0-b*d i:ℝ):ℂ), -(b*0+a*d i:ℝ)+Complex.I*0; + (b*0+a*d i:ℝ)+Complex.I*0, (0:ℂ)+Complex.I*((a*0-b*d i:ℝ):ℂ)] = d i • ((-b) • z+a • y) + ext j k + fin_cases j <;> fin_cases k <;> simp [z,y] <;> ring + · change toPauli (rotateIJ a b hab (⟨0,c i,0,0⟩ : Quaternion ℝ)) = c i • (a • z+b • y) + change !![(0:ℂ)-Complex.I*((a*c i-b*0:ℝ):ℂ), -(b*c i+a*0:ℝ)+Complex.I*0; + (b*c i+a*0:ℝ)+Complex.I*0, (0:ℂ)+Complex.I*((a*c i-b*0:ℝ):ℂ)] = c i • (a • z+b • y) + ext j k + fin_cases j <;> fin_cases k <;> simp [z,y] <;> ring + +omit [Fintype ι] in +theorem matrixMap_qX (a b : ℝ) (hab : a^2+b^2=1) (t : ℝ) : + matrixMap a b hab (qX (fun _ : ι => -t)) = fun _ : ι => t • x := by + funext i + change toPauli (rotateIJ a b hab (⟨0,0,0,-t⟩ : Quaternion ℝ)) = t • x + change !![(0:ℂ)-Complex.I*((a*0-b*0:ℝ):ℂ), -(b*0+a*0:ℝ)+Complex.I*((-t:ℝ):ℂ); + (b*0+a*0:ℝ)+Complex.I*((-t:ℝ):ℂ), (0:ℂ)+Complex.I*((a*0-b*0:ℝ):ℂ)] = t • x + ext j k + fin_cases j <;> fin_cases k <;> simp [x] <;> ring + + + +theorem exact_spin_ensemble (v : ι → ℝ × ℝ) (hv : ∀ i, v i ≠ 0) : + ∃ a b : ℝ, a^2+b^2=1 ∧ ∀ t : ℝ, + NormedSpace.exp (fun _ : ι => t • x) ∈ zeroClockWords + (spinGen a b (fun i => a*(v i).1+b*(v i).2) (fun i => -b*(v i).1+a*(v i).2)) := by + obtain ⟨a,b,hab,hn,hs⟩ := exists_separating_frame v hv + refine ⟨a,b,hab,fun t => ?_⟩ + let c := fun i => a*(v i).1+b*(v i).2 + let d := fun i => -b*(v i).1+a*(v i).2 + have heq : ∀ i j, c i^2=c j^2 → (c i=c j ∧ d i=d j) ∨ (c i= -c j ∧ d i= -d j) := by + intro i j hh + rcases hs i j hh with h | h + · left; simp [c,d,h] + · right; simp only [c,d,h,Prod.fst_neg,Prod.snd_neg]; constructor <;> ring + have hr := common_X_exact c d hn heq (-t) + let F : QField ι →ₐ[ℝ] (ι → SpinMatrix) := matrixMap a b hab + have hF : Continuous F := F.toLinearMap.continuous_of_finiteDimensional + have hm := zeroClock_map F hF (gen c d) hr + rw [show F ∘ gen c d = spinGen a b c d from matrixMap_gen a b hab c d] at hm + have he : F (NormedSpace.exp (qX (fun _ : ι => -t))) = NormedSpace.exp (fun _ : ι => t • x) := by + convert! NormedSpace.map_exp F.toRingHom hF (qX (fun _ : ι => -t)) using 1 + change NormedSpace.exp (fun _ : ι => t • x) = NormedSpace.exp (matrixMap a b hab (qX (fun _ : ι => -t))) + rw [matrixMap_qX] + rwa [he] at hm + +end QuaternionControl + +namespace PulseControl +variable {κ : Type*} [DecidableEq κ] + +@[simp] theorem pulseClock_reverse (w : List (κ × ℝ)) : pulseClock w.reverse = pulseClock w := by + simp [pulseClock,List.map_reverse] + + +theorem pulseClock_eq_sum (w : List (κ × ℝ)) (e : κ) : + pulseClock w e = ((w.filter (fun p => decide (p.1=e))).map Prod.snd).sum := by + induction w with + | nil => simp [pulseClock] + | cons p w ih => + simp only [pulseClock,List.map_cons,List.sum_cons,Pi.add_apply] at ih ⊢ + by_cases h : p.1=e + · simp [h,ih] + · have h' : e ≠ p.1 := Ne.symm h + simp [h,h',ih] +end PulseControl + +namespace QuaternionControl +open PulseControl SeedControl +open scoped Matrix.Norms.L2Operator +variable {ι : Type*} [Fintype ι] +local instance rotateIJSpinFieldNormedAlgebra : NormedAlgebra ℚ (ι → SpinMatrix) := + NormedAlgebra.restrictScalars ℚ ℝ (ι → SpinMatrix) +local instance rotateIJSpinMatrixNormedAlgebra : NormedAlgebra ℚ SpinMatrix := + NormedAlgebra.restrictScalars ℚ ℝ SpinMatrix + +theorem matrix_exp_apply (A : ι → SpinMatrix) (i : ι) : + NormedSpace.exp A i = NormedSpace.exp (A i) := by + convert! NormedSpace.map_exp (Pi.evalRingHom (fun _ : ι => SpinMatrix) i) (continuous_apply i) A + +theorem spin_pulseValue_apply (G : Bool → ι → SpinMatrix) (w : List (Bool×ℝ)) (i : ι) : + pulseValue G w i = pulseValue (fun e => G e i) w := by + exact pulseValue_map (Pi.evalAlgHom ℝ (fun _ : ι => SpinMatrix) i) (continuous_apply i) G w + + +theorem selective_rotations_zero_clocks (v : ι → ℝ×ℝ) (hv : ∀ i, v i ≠ 0) : + ∃ a b : ℝ, a^2+b^2=1 ∧ ∀ t : ℝ, ∃ w : List (Bool×ℝ), + (∀ e : Bool, ((w.filter (fun p => decide (p.1=e))).map Prod.snd).sum = 0) ∧ + ∀ i : ι, + (w.reverse.map (fun p => NormedSpace.exp (p.2 • + spinGen a b (fun j => a*(v j).1+b*(v j).2) + (fun j => -b*(v j).1+a*(v j).2) p.1 i))).prod = + NormedSpace.exp (t • x) := by + obtain ⟨a,b,hab,ht⟩ := exact_spin_ensemble v hv + refine ⟨a,b,hab,fun t => ?_⟩ + obtain ⟨w,hw,he⟩ := ht t + refine ⟨w.reverse,?_,fun i => ?_⟩ + · intro e + rw [← pulseClock_eq_sum,pulseClock_reverse,hw] + rfl + · have h := congrArg (fun A : ι → SpinMatrix => A i) he + rw [spin_pulseValue_apply,matrix_exp_apply] at h + simpa only [List.reverse_reverse,pulseValue] using h +end QuaternionControl + +namespace SKQAOA +open scoped ComplexConjugate + + + +def History (n : ℕ) : ℕ → Type + | 0 => Unit + | p+1 => Configuration n × History n p + +instance historyFintype (n : ℕ) : (p : ℕ) → Fintype (History n p) + | 0 => inferInstanceAs (Fintype Unit) + | p+1 => @instFintypeProd (Configuration n) (History n p) inferInstance (historyFintype n p) + + +def historyMix (n : ℕ) : (p : ℕ) → (Fin p → ℝ) → Configuration n → History n p → ℂ + | 0, _, _, _ => ((Real.sqrt ((2:ℝ)^n))⁻¹ : ℝ) + | p+1, β, σ, h => evolution (β (Fin.last p)) (mixer n) σ h.1 * + historyMix n p (fun i => β i.castSucc) h.1 h.2 + + +def historyPhase (n : ℕ) : (p : ℕ) → (Fin p → ℝ) → History n p → Edge n → ℂ + | 0, _, _, _ => 0 + | p+1, γ, h, e => -(γ (Fin.last p) : ℂ)*Complex.I*(skCoeff n h.1 e : ℂ)+ + historyPhase n p (fun i => γ i.castSucc) h.2 e + +@[simp] theorem sum_history_zero (n : ℕ) (f : History n 0 → ℂ) : + ∑ h, f h = f () := by + let : Unique (History n 0) := inferInstanceAs (Unique Unit) + exact Fintype.sum_unique f + +theorem sum_history_succ (n p : ℕ) (f : History n (p+1) → ℂ) : + ∑ h, f h = ∑ σ : Configuration n, ∑ h : History n p, f (σ,h) := + Fintype.sum_prod_type f + +theorem historyPhase_succ_sum (n p : ℕ) (J : Disorder n) (γ : Fin (p+1) → ℝ) + (σ : Configuration n) (h : History n p) : + (∑ e, historyPhase n (p+1) γ (σ,h) e*(J e : ℂ))= + -(γ (Fin.last p):ℂ)*Complex.I*(hamiltonian n J σ : ℂ)+ + ∑ e, historyPhase n p (fun i => γ i.castSucc) h e*(J e : ℂ) := by + simp only [historyPhase,add_mul,Finset.sum_add_distrib] + congr 1 + rw [hamiltonian_eq_coeff] + push_cast + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he + ring + +theorem cost_evolution_mulVec (n : ℕ) (J : Disorder n) (γ : ℝ) (ψ : State n) : + (evolution γ (cost n J)).mulVec ψ= + fun σ => Complex.exp (-(γ:ℂ)*Complex.I*(hamiltonian n J σ : ℂ))*ψ σ := by + funext σ + simp only [cost_evolution_eq_diagonal,Matrix.mulVec_diagonal] + + +theorem qaoaState_history (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) + (σ : Configuration n) : + qaoaState n p J γ β σ = ∑ h : History n p, + historyMix n p β σ h * Complex.exp (∑ e, historyPhase n p γ h e*(J e : ℂ)) := by + induction p generalizing σ with + | zero => + rw [sum_history_zero] + simp [qaoaState,circuit,plus,historyMix,historyPhase] + | succ p ih => + have he : qaoaState n (p+1) J γ β = + (evolution (β (Fin.last p)) (mixer n)).mulVec + ((evolution (γ (Fin.last p)) (cost n J)).mulVec + (qaoaState n p J (fun i => γ i.castSucc) (fun i => β i.castSucc))) := by + simp only [qaoaState,circuit,Matrix.mulVec_mulVec,Matrix.mul_assoc] + rw [he,cost_evolution_mulVec,sum_history_succ] + change (∑ τ, evolution (β (Fin.last p)) (mixer n) σ τ * + (Complex.exp (-(γ (Fin.last p):ℂ)*Complex.I*(hamiltonian n J τ : ℂ))* + qaoaState n p J (fun i => γ i.castSucc) (fun i => β i.castSucc) τ))=_ + apply Finset.sum_congr rfl + intro τ hτ + rw [ih,Finset.mul_sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro h hh + rw [historyPhase_succ_sum,Complex.exp_add] + simp only [historyMix] + ring + + + +def pairedPhase (n p : ℕ) (γ : Fin p → ℝ) (a b : History n p) (e : Edge n) : ℂ := + star (historyPhase n p γ a e)+historyPhase n p γ b e + +def pairedMix (n p : ℕ) (β : Fin p → ℝ) (σ : Configuration n) (a b : History n p) : ℂ := + star (historyMix n p β σ a)*historyMix n p β σ b + +theorem qaoaState_pair_history (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) + (σ : Configuration n) : + star (qaoaState n p J γ β σ)*qaoaState n p J γ β σ = + ∑ a : History n p, ∑ b : History n p, pairedMix n p β σ a b * + Complex.exp (∑ e, pairedPhase n p γ a b e*(J e : ℂ)) := by + rw [qaoaState_history] + simp only [map_sum,Finset.sum_mul,Finset.mul_sum,map_mul,Complex.star_def, + ← Complex.exp_conj,Complex.conj_ofReal] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + have he : (∑ e, star (historyPhase n p γ a e)*(J e : ℂ))+ + (∑ e, historyPhase n p γ b e*(J e : ℂ)) = + ∑ e, pairedPhase n p γ a b e*(J e : ℂ) := by + simp only [pairedPhase,add_mul,Finset.sum_add_distrib] + rw [← he,Complex.exp_add] + simp only [pairedMix,Complex.star_def] + ring + + +theorem integrable_history_coordinate (n p : ℕ) (γ β : Fin p → ℝ) + (σ : Configuration n) (a b : History n p) (e : Edge n) : + Integrable (fun J : Disorder n => pairedMix n p β σ a b * + ((J e : ℂ)*Complex.exp (∑ f, pairedPhase n p γ a b f*(J f : ℂ)))) (disorderLaw n) := + (GaussianFourier.integrable_coord_exp_sum (pairedPhase n p γ a b) e).const_mul _ + +theorem integral_history_coordinate (n p : ℕ) (γ β : Fin p → ℝ) + (σ : Configuration n) (a b : History n p) (e : Edge n) : + (∫ J : Disorder n, pairedMix n p β σ a b * + ((J e : ℂ)*Complex.exp (∑ f, pairedPhase n p γ a b f*(J f : ℂ))) ∂disorderLaw n) = + pairedMix n p β σ a b * pairedPhase n p γ a b e * + Complex.exp (∑ f, (pairedPhase n p γ a b f)^2/2) := by + rw [integral_const_mul] + change _ * (∫ J : Disorder n, _ ∂GaussianFourier.law (Edge n)) = _ + rw [GaussianFourier.integral_coord_exp_sum,mul_assoc] + +end SKQAOA + +namespace SKQAOA + + +theorem quad_cost_history_basis (n : ℕ) (J : Disorder n) (ψ : State n) : + quad ψ (cost n J)=∑ σ : Configuration n, ∑ e : Edge n, + (skCoeff n σ e : ℂ)*((J e : ℂ)*(star (ψ σ)*ψ σ)) := by + simp only [quad,dotProduct,cost_eq_diagonal,Matrix.mulVec_diagonal,Pi.star_apply, + hamiltonian_eq_coeff,Complex.ofReal_sum,Complex.ofReal_mul,Finset.sum_mul,Finset.mul_sum] + apply Finset.sum_congr rfl + intro σ hσ + apply Finset.sum_congr rfl + intro e he + ring + +theorem coordinate_state_history (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) + (σ : Configuration n) (e : Edge n) : + (J e : ℂ)*(star (qaoaState n p J γ β σ)*qaoaState n p J γ β σ)= + ∑ a : History n p, ∑ b : History n p, pairedMix n p β σ a b * + ((J e : ℂ)*Complex.exp (∑ f, pairedPhase n p γ a b f*(J f : ℂ))) := by + rw [qaoaState_pair_history] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + ring + +theorem integrable_coordinate_state (n p : ℕ) (γ β : Fin p → ℝ) + (σ : Configuration n) (e : Edge n) : + Integrable (fun J : Disorder n => + (J e : ℂ)*(star (qaoaState n p J γ β σ)*qaoaState n p J γ β σ)) (disorderLaw n) := by + simp_rw [coordinate_state_history] + exact integrable_finsetSum _ (fun a _ => integrable_finsetSum _ + (fun b _ => integrable_history_coordinate n p γ β σ a b e)) + +theorem integral_coordinate_state (n p : ℕ) (γ β : Fin p → ℝ) + (σ : Configuration n) (e : Edge n) : + (∫ J : Disorder n, + (J e : ℂ)*(star (qaoaState n p J γ β σ)*qaoaState n p J γ β σ) ∂disorderLaw n)= + ∑ a : History n p, ∑ b : History n p, pairedMix n p β σ a b * + pairedPhase n p γ a b e * Complex.exp (∑ f, (pairedPhase n p γ a b f)^2/2) := by + simp_rw [coordinate_state_history] + rw [integral_finsetSum _ (fun a _ => integrable_finsetSum _ + (fun b _ => integrable_history_coordinate n p γ β σ a b e))] + apply Finset.sum_congr rfl + intro a ha + rw [integral_finsetSum _ (fun b _ => integrable_history_coordinate n p γ β σ a b e)] + simp_rw [integral_history_coordinate] + +theorem integrable_quad_cost (n p : ℕ) (γ β : Fin p → ℝ) : + Integrable (fun J : Disorder n => quad (qaoaState n p J γ β) (cost n J)) (disorderLaw n) := by + simp_rw [quad_cost_history_basis] + exact integrable_finsetSum _ (fun σ _ => integrable_finsetSum _ (fun e _ => + (integrable_coordinate_state n p γ β σ e).const_mul _)) + + + +theorem expectedEnergy_history (n p : ℕ) (γ β : Fin p → ℝ) : + expectedEnergy n p γ β = + (∑ σ : Configuration n, ∑ e : Edge n, (skCoeff n σ e : ℂ)* + (∑ a : History n p, ∑ b : History n p, pairedMix n p β σ a b * + pairedPhase n p γ a b e * Complex.exp (∑ f, (pairedPhase n p γ a b f)^2/2))).re / + (n : ℝ) := by + have he : (fun J : Disorder n => energyDensity n p J γ β)= + fun J => (quad (qaoaState n p J γ β) (cost n J)).re/(n:ℝ) := rfl + have hi : (∫ J, (quad (qaoaState n p J γ β) (cost n J)).re ∂disorderLaw n) = + (∫ J, quad (qaoaState n p J γ β) (cost n J) ∂disorderLaw n).re := + integral_re (integrable_quad_cost n p γ β) + rw [expectedEnergy,he,integral_div,hi] + congr 2 + simp_rw [quad_cost_history_basis] + rw [integral_finsetSum _ (fun σ _ => integrable_finsetSum _ (fun e _ => + (integrable_coordinate_state n p γ β σ e).const_mul _))] + apply Finset.sum_congr rfl + intro σ hσ + rw [integral_finsetSum _ (fun e _ => (integrable_coordinate_state n p γ β σ e).const_mul _)] + simp_rw [integral_const_mul,integral_coordinate_state] + +end SKQAOA + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/RotationAccuracy.lean b/lean/OAI/Probability/ParisiFinite/RotationAccuracy.lean new file mode 100644 index 0000000000000000000000000000000000000000..798bddbfb060ff5970d323202b744626bf54f05f --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/RotationAccuracy.lean @@ -0,0 +1,626 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SpinCoeAdd + +namespace OAI + +/-! Rotation Accuracy. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +open RootSpin +variable {E α κ : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [Fintype κ] + {l : Filter α} + + + +theorem PacketExpansion.rotation_accuracy + {r S : α → ℝ} {d : κ → α → E} {spin : κ → Fin 2} + {u : α → SpinSpace E} (hu : PacketExpansion (l:=l) S r d spin u) + (V : α → SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E) (θ : ℝ) + (hS : ∀ᶠ q in l,0≤S q) (hscale : ∀ᶠ q in l,0≤r q ∧ S q*r q=1) + (hv : ∀i (x : α → SpinSpace E),BoundedPacket l x → + Tendsto (fun q => ‖V q (spinW ((S q:ℂ) • d i q) (x q))- + SpinOperators.act (R θ) (spinW ((S q:ℂ) • d i q) (x q))‖) l (𝓝 0)) : + Tendsto (fun q => S q*‖V q (u q)-SpinOperators.act (R θ) (u q)‖) l (𝓝 0) := by + obtain ⟨τ,hτ,_,he⟩ := hu + let F := SpinOperators.act (R θ) (H:=Space E) + have hF : ∀x,‖F x‖≤‖x‖ := fun x => (SpinOperators.norm_act (R_unitary _) x).le + apply ForwardControl.scaled_difference_transfer V F hF S u + (fun q => ∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ i q)) hS _ he + exact ForwardControl.scaled_amplitude_finSum V F hF r S + (fun q i => spinW ((S q:ℂ) • d i q) (τ i q)) hS hscale (fun i => hv i (τ i) (hτ i)) + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin +local instance psRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance psRealSMul : SMul ℝ ModeInfinity := psRealModule.toDistribMulAction.toSMul +local instance psRealSMulZero : SMulZeroClass ℝ ModeInfinity := { smul_zero := psRealModule.toDistribMulAction.smul_zero } + + + +theorem standard_selective_bounded {α κ : Type*} [Fintype κ] {l : Filter α} + (r : α → ℝ) (w : α → List Gate) (x s ρ : α → SpinSpace ModeInfinity) + (hx : BoundedPacket l x) (d : κ → α → ModeInfinity) (spin : κ → Fin 2) + (C : ℝ) (hC : 0≤C) (hd : ∀i,∀ᶠ q in l,‖d i q‖≤C) + (v : κ → ℝ×ℝ) (hv : ∀i,v i≠0) (θ : ℝ) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 ‖s q‖) l (𝓝 0)) (hρ : Tendsto (fun q => ‖ρ q‖) l (𝓝 0)) + (hZ : ∀i,Tendsto (fun q => -2*(⟪insertionInfinity (w q),d i q⟫_ℂ).im) l (𝓝 (v i).1)) + (hY : ∀i,Tendsto (fun q => -2*(⟪insertionYInfinity (w q),d i q⟫_ℂ).im) l (𝓝 (v i).2)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + (∀z,BoundedPacket l z → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (w q) a K (z q)-z q‖) l (𝓝 0)) ∧ + (∀z,PacketExpansion (l:=l) (fun q => (r q)⁻¹) r d spin z → + Tendsto (fun q => (r q)⁻¹*‖probeGain (r q) (w q) a K (z q)- + SpinOperators.act (R θ) (z q)‖) l (𝓝 0)) := by + obtain ⟨p,B,A,hB,hA,hx,hpb⟩ := hx + have hψ' : ∀ᶠ q in l,ordinaryLocal (w q) (vacuum ModeInfinity)=spinCoe (p q)+s q+ρ q := by + simpa only [hx] using hψ + obtain ⟨K,a,ho,hsp⟩ := standard_selective_accuracy r w p s ρ B A hB hA v hv θ hr hp hpb hψ' hs hρ + obtain ⟨_,hscale⟩ := reciprocal_scale_eventually r hr hp + refine ⟨K,a,?_,?_⟩ + · intro z hz + obtain ⟨p',B',A',hB',hA',hz,hpb'⟩ := hz + simpa only [hz] using ho p' B' A' hB' hA' hpb' + · intro z hz + apply hz.rotation_accuracy (fun q => probeGain (r q) (w q) a K) θ + (hscale.mono (fun _ h => h.2.1)) (hscale.mono (fun _ h => ⟨h.1,h.2.2⟩)) + intro i τ hτ + obtain ⟨p',B',A',hB',hA',hτ,hpb'⟩ := hτ + simpa only [hτ,actualPacket,Complex.coe_smul] using + hsp i (d i) p' C B' A' hC hB' hA' (hd i) hpb' (hZ i) (hY i) + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree +local instance addressRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance addressRealSMul : SMul ℝ ModeInfinity := addressRealModule.toDistribMulAction.toSMul +local instance addressRealSMulZero : SMulZeroClass ℝ ModeInfinity := { smul_zero := addressRealModule.toDistribMulAction.smul_zero } + +section Naturality +variable {E F : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] + + theorem spinMap_initial (T : E →ₗᵢ[ℂ] F) (γ δ β : ℝ) (v e : E) (x : SpinSpace E) : + spinMap (gammaEmbedding T) (initialMap γ δ β v e x)= + initialMap γ δ β (T v) (T e) (spinMap (gammaEmbedding T) x) := by + simp only [initialMap_apply_complex,spinMap_root,spinMap_cost,map_smul] + + theorem spinMap_special (T : E →ₗᵢ[ℂ] F) (γ β : ℝ) (v e : E) (x : SpinSpace E) : + spinMap (gammaEmbedding T) (specialMap γ β v e x)= + specialMap γ β (T v) (T e) (spinMap (gammaEmbedding T) x) := by + simp only [specialMap_apply,←Complex.coe_smul,spinMap_root,spinMap_cost,map_smul,map_add] + + theorem specialPhase_map (T : E →ₗᵢ[ℂ] F) (γ : ℝ) (v e : E) : + specialPhase γ (T v) (T e)=specialPhase γ v e := by + unfold specialPhase + simp only [←Complex.coe_smul,←map_smul,phase_map] + + theorem spinMap_address (T : E →ₗᵢ[ℂ] F) (γ δ : ℝ) (v e : E) : + spinMap (gammaEmbedding T) (address γ δ v e)=address γ δ (T v) (T e) := by + apply (initialMap γ δ (Real.pi/4) (T v) (T e)).injective + rw [←spinMap_initial,address,LinearIsometryEquiv.apply_symm_apply] + rw [spinMap_root,map_smul,spinMap_special,spinMap_vacuum] + rw [address,LinearIsometryEquiv.apply_symm_apply,specialPhase_map] + +end Naturality + + + +def addressInfinity (b T : ℝ) : ModeInfinity := modeEmbed 4 (addressMode 2 b T) + +@[simp] theorem norm_addressInfinity (b T : ℝ) : ‖addressInfinity b T‖=1 := by + rw [addressInfinity,(modeEmbed 4).norm_map,norm_addressMode] + + theorem modeFock_embed_address (n : ℕ) (b T : ℝ) : + modeFock (modeEmbed (n+2) (addressMode n b T))= + address (gamma b T) (delta T) (modeEmbed (n+1) (actualV n b T)) + (modeEmbed (n+1) (initialDirection (n+1))) := by + change unfoldTree (modeInWhole (modeEmbed (n+2) (addressMode n b T)))=_ + rw [modeInWhole_embed,unfoldTree_embed_succ] + simp only [addressMode,actualAddress,topFockMap] + apply spinMap_address + + theorem modeFock_addressInfinity (b T : ℝ) : + modeFock (addressInfinity b T)=address (gamma b T) (delta T) (vInfinity b T) eInfinity := by + rw [addressInfinity,modeFock_embed_address,embed_initialDirection,←vInfinity_embed] + + theorem addressInfinity_exact (b : ℝ) {T : ℝ} (hT : 1≤T) : + (amplitude T : ℂ) • modeFock (addressInfinity b T)= + (ordinaryLocal (wordInfinity b T)).symm + (SpinOperators.act Z (specialPartInfinity b T (vacuum ModeInfinity))) := by + rw [modeFock_addressInfinity,←sin_delta hT] + have hm : ordinaryLocal (wordInfinity b T)= + initialMap (gamma b T) (delta T) (Real.pi/4) (vInfinity b T) eInfinity := + LinearIsometryEquiv.ext (ordinaryLocal_initialization b T) + rw [hm,specialPartInfinity_apply] + exact address_exact_normalization _ _ _ _ + + theorem addressInfinity_escapes (b : ℝ) (hb : 0 ⟪x T,modeFock (addressInfinity b T)⟫_ℂ) atTop (𝓝 0) := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + have hl : Tendsto (fun T => ⟪spinCoe (p T),leading (gamma b T) (vInfinity b T)⟫_ℂ) + atTop (𝓝 0) := + tendsto_inner_spinCoe_rootZ_uniform _ p + (tendsto_norm_scaled_unit (gamma b) (vInfinity b) (tendsto_gamma b hb) + (norm_vInfinity b)) B A hB hbound + have hs : Tendsto (fun T => |Real.sin (delta T)|) atTop (𝓝 0) := by + simpa only [Function.comp_def,Real.sin_zero,abs_zero] using + (Real.continuous_sin.continuousAt.tendsto.comp tendsto_delta).abs + rw [tendsto_zero_iff_norm_tendsto_zero] + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ + (by simpa only [mul_zero,norm_zero,add_zero] using (hs.const_mul A).add hl.norm) + filter_upwards [hbound] with T hT + rw [modeFock_addressInfinity,hp] + have hh := norm_inner_address_bound (gamma b T) (delta T) (vInfinity b T) eInfinity (spinCoe (p T)) + exact hh.trans (add_le_add + (mul_le_mul_of_nonneg_right ((norm_spinCoe_le_mass _).trans hT.2) (abs_nonneg _)) + (mul_le_of_le_one_left (norm_nonneg _) (Real.abs_cos_le_one _))) + + theorem highInfinity_lift (γ : ℝ) : highInfinity γ=modeEmbed 4 (highDirection 3 γ) := by + have h := modeEmbed_step 3 (highDirection 2 γ) + rw [show modeStep 3 (highDirection 2 γ)=highDirection 3 γ from highDirection_empty 2 γ] at h + exact h.symm + + theorem high_addressInfinity_orthogonal (b : ℝ) (hb : 0 ⟪highInfinity (gamma b T),addressInfinity b T⟫_ℂ) atTop (𝓝 0) := by + simp only [highInfinity_lift,addressInfinity,(modeEmbed 4).inner_map_map] + exact tendsto_high_address_inner 2 b hb + +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin + + + +structure PacketStage {α κ : Type*} [Fintype κ] (l : Filter α) + (r S : α → ℝ) (d : κ → α → ModeInfinity) (spin : κ → Fin 2) where + word : α → List Gate + ordinary : α → SpinSpace ModeInfinity →L[ℂ] SpinSpace ModeInfinity + special : α → SpinSpace ModeInfinity →L[ℂ] SpinSpace ModeInfinity + split : ∀q x,ordinaryLocal (word q) x=ordinary q x+special q x + special_norm : ∀ᶠ q in l,∀x,‖special q x‖=r q*‖x‖ + low : PacketUnitaryFamily (E:=ModeInfinity) l + phase : α → ℂ + phase_norm : ∀q,‖phase q‖=1 + ordinary_low : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖ordinary q (x q)-phase q • low.op q (x q)‖) l (𝓝 0) + special_packets : ∀x,BoundedPacket l x → + PacketExpansion (l:=l) S r d spin (fun q => special q (x q)) + +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r S : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +theorem special_vacuum_zero (st : PacketStage l r S d spin) (hr : Tendsto r l (𝓝 0)) : + Tendsto (fun q => ‖st.special q (vacuum ModeInfinity)‖) l (𝓝 0) := by + apply hr.congr' + filter_upwards [st.special_norm] with q hq + rw [hq,norm_vacuum,mul_one] + + + +theorem low_bounded (st : PacketStage l r S d spin) (x : α → SpinSpace ModeInfinity) + (hx : BoundedPacket l x) : + BoundedPacket l (fun q => st.phase q • st.low.op q (x q)) := + (st.low.forward x hx).smul st.phase 1 (by norm_num) + (Eventually.of_forall fun q => (st.phase_norm q).le) + + + +theorem insertion_bound (st : PacketStage l r S d spin) + (hscale : ∀ᶠ q in l,0≤r q ∧ 0≤S q ∧ S q*r q=1) + (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) : + ∀ᶠ q in l,S q*‖(ordinaryLocal (st.word q)).symm + (SpinOperators.act P (ordinaryLocal (st.word q) (vacuum ModeInfinity)))- + (st.low.op q).symm (SpinOperators.act P (st.low.op q (vacuum ModeInfinity)))‖≤4 := + low_insertion_scaled_bound (fun q => ordinaryLocal (st.word q)) st.low st.ordinary st.special + st.phase r S P hP hscale (Eventually.of_forall st.split) + (st.special_norm.mono fun _ hq x => (hq x).le) st.ordinary_low + + + +def cost (st : PacketStage l r S d spin) (c : ℝ) : PacketStage l r S d spin where + word q := .cost c::st.word q + ordinary q := (WZ (-(c:ℂ) • insertionInfinity (st.word q))).comp (st.ordinary q) + special q := (WZ (-(c:ℂ) • insertionInfinity (st.word q))).comp (st.special q) + split q x := by simp only [ordinaryLocal_cost,st.split,map_add,ContinuousLinearMap.comp_apply] + special_norm := by + filter_upwards [st.special_norm] with q hq x + simpa only [ContinuousLinearMap.comp_apply,norm_WZ] using hq x + low := st.low.trans (PacketUnitaryFamily.pulse + (fun q => -(c:ℂ) • insertionInfinity (st.word q)) |c| (abs_nonneg _) + (Eventually.of_forall fun q => by simp only [norm_smul,norm_neg,Complex.norm_real, + Real.norm_eq_abs,norm_insertionInfinity,mul_one,le_refl])) + phase := st.phase + phase_norm := st.phase_norm + ordinary_low x hx := by + have h := st.ordinary_low x hx + simpa only [PacketUnitaryFamily.trans,PacketUnitaryFamily.pulse,LinearIsometryEquiv.trans_apply, + costEquiv_apply,ContinuousLinearMap.comp_apply,←map_smul,←map_sub,norm_WZ] using h + special_packets x hx := (st.special_packets x hx).bounded_cost + (fun q => -(c:ℂ) • insertionInfinity (st.word q)) |c| (abs_nonneg _) + (Eventually.of_forall fun q => by simp only [norm_smul,norm_neg,Complex.norm_real, + Real.norm_eq_abs,norm_insertionInfinity,mul_one,le_refl]) + +end PacketStage +end PointedTree + +namespace SeedInitialization +open CoherentFock RootSpin PointedTree + + + +def initialStage (b : ℝ) : + PacketStage (atTop : Filter ℝ) amplitude id + (fun i : Fin 2×Fin 2 => fun _ => initialCenter b i.1) Prod.snd where + word := wordInfinity b + ordinary := ordinaryPartInfinity b + special := specialPartInfinity b + split := exact_splitInfinity b + special_norm := by + filter_upwards [eventually_ge_atTop (1:ℝ)] with T hT x + exact norm_specialPartInfinity b hT x + low := lowInfinity b + phase := phaseInfinity b + phase_norm := norm_phaseInfinity b + ordinary_low := lowInfinity_accuracy b + special_packets x hx := by + refine ⟨fun i T => initialTail b T i.1 i.2 (x T), + fun i => initialTail_bounded b x hx i.1 i.2,fun i T => initialTail_sector b T i.1 i.2 (x T),?_⟩ + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (1:ℝ)] with T hT + have h := initial_special_packets b hT (x T) + simp only [id_eq,Fintype.sum_prod_type,←Finset.smul_sum,←h,sub_self,norm_zero,mul_zero] + +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +open RootSpin +variable {E α κ : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [Fintype κ] + {l : Filter α} + +theorem projectSpin_rootZ (i : Fin 2) (x : SpinSpace E) : + projectSpin i (SpinOperators.act Z x)=SpinOperators.act Z (projectSpin i x) := by + ext j + fin_cases i <;> fin_cases j <;> + simp [projectSpin_apply,SpinOperators.act_apply,Z,Fin.sum_univ_two] + +theorem PacketExpansion.rootZ {r S : α → ℝ} {d : κ → α → E} {spin : κ → Fin 2} + {u : α → SpinSpace E} (hu : PacketExpansion (l:=l) S r d spin u) : + PacketExpansion (l:=l) S r d spin (fun q => SpinOperators.act Z (u q)) := by + obtain ⟨τ,hτ,hspin,he⟩ := hu + refine ⟨fun i q => SpinOperators.act Z (τ i q),fun i => (hτ i).root Z,?_,?_⟩ + · intro i q + rw [projectSpin_rootZ,hspin] + · have hsum (q : α) : SpinOperators.act Z (∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ i q))= + ∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (SpinOperators.act Z (τ i q)) := by + simp only [map_sum,map_smul,spinW_root] + simpa only [←hsum,←map_sub,SpinOperators.norm_act Z_unitary] using he + + + +theorem compensated_error (θ : ℝ) (x y : SpinSpace E) : + ‖SpinOperators.act (R θ) x-y‖=‖x-SpinOperators.act (R (-θ)) y‖ := by + have hcancel : SpinOperators.act (R θ) (SpinOperators.act (R (-θ)) y)=y := by + rw [←ContinuousLinearMap.comp_apply,←SpinOperators.act_mul,R_add,add_neg_cancel,R_zero,SpinOperators.act_one] + rfl + conv_lhs => rw [←hcancel] + rw [←map_sub,SpinOperators.norm_act (R_unitary _)] + +end CoherentFock + +namespace ForwardControl +variable {H α : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] {l : Filter α} + +omit [InnerProductSpace ℂ H] in +theorem scaled_triangle (S : α → ℝ) (x y z : α → H) (hS : ∀ᶠ q in l,0≤S q) + (hxy : Tendsto (fun q => S q*‖x q-y q‖) l (𝓝 0)) + (hyz : Tendsto (fun q => S q*‖y q-z q‖) l (𝓝 0)) : + Tendsto (fun q => S q*‖x q-z q‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [add_zero] using hxy.add hyz) + · filter_upwards [hS] with q hq + exact mul_nonneg hq (norm_nonneg _) + · filter_upwards [hS] with q hq + simpa only [mul_add] using mul_le_mul_of_nonneg_left (norm_sub_le_norm_sub_add_norm_sub (x q) (y q) (z q)) hq + + + +theorem preserve_transport_bound (V : H ≃ₗᵢ[ℂ] H) (Z : H →L[ℂ] H) + (hZ : ∀x,‖Z x‖≤‖x‖) (s : H) : + ‖V.symm (Z (V s))-Z s‖≤‖V s-s‖+‖V (Z s)-Z s‖ := by + rw [←V.norm_map, map_sub, V.apply_symm_apply] + have h := norm_sub_le_norm_sub_add_norm_sub (Z (V s)) (Z s) (V (Z s)) + rw [←map_sub,norm_sub_rev (Z s)] at h + exact h.trans (add_le_add (hZ _) le_rfl) + +end ForwardControl + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin + + +def compensatedGain (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (K : ℕ) (θ : ℝ) : + SpinSpace ModeInfinity ≃ₗᵢ[ℂ] SpinSpace ModeInfinity := + (probeGain r w a K).trans (SpinOperators.actEquiv (R θ) (R_unitary θ)) + +@[simp] theorem compensatedGain_apply (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (K : ℕ) + (θ : ℝ) (x : SpinSpace ModeInfinity) : + compensatedGain r w a K θ x=SpinOperators.act (R θ) (probeGain r w a K x) := rfl + +@[simp] theorem compensatedGain_local (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (K : ℕ) + (θ : ℝ) (x : SpinSpace ModeInfinity) : + compensatedGain r w a K θ (ordinaryLocal w x)=ordinaryLocal (.mixer θ::probePrefix r w a K) x := by + simp only [compensatedGain_apply,probeGain_on_local,ordinaryLocal_mixer] + +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r S : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + + +def compensated (st : PacketStage l r S d spin) (θ : ℝ) (a : ℕ → ShortPulse) (K : ℕ) + (hS : ∀ᶠ q in l,0≤S q) + (ho : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K (x q)-x q‖) l (𝓝 0)) + (hs : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K (st.special q (x q))- + SpinOperators.act (R (-θ)) (st.special q (x q))‖) l (𝓝 0)) : + PacketStage l r S d spin where + word q := .mixer θ::probePrefix (r q) (st.word q) a K + ordinary q := (compensatedGain (r q) (st.word q) a K θ).toContinuousLinearEquiv.toContinuousLinearMap.comp (st.ordinary q) + special q := (compensatedGain (r q) (st.word q) a K θ).toContinuousLinearEquiv.toContinuousLinearMap.comp (st.special q) + split q x := by + rw [←compensatedGain_local,st.split,map_add] + rfl + special_norm := by + filter_upwards [st.special_norm] with q hq x + simpa only [ContinuousLinearMap.comp_apply,LinearIsometryEquiv.coe_toContinuousLinearEquiv, + ContinuousLinearEquiv.coe_coe,LinearIsometryEquiv.norm_map] using hq x + low := st.low.trans (PacketUnitaryFamily.root (R θ) (R_unitary θ)) + phase := st.phase + phase_norm := st.phase_norm + ordinary_low x hx := by + have he := st.ordinary_low x hx + have hp := ho (fun q => st.phase q • st.low.op q (x q)) (st.low_bounded x hx) + have ht := ForwardControl.scaled_identity_transfer + (fun q => probeGain (r q) (st.word q) a K) S + (fun q => st.ordinary q (x q)) (fun q => st.phase q • st.low.op q (x q)) hS hp he + have hall := ForwardControl.scaled_triangle S + (fun q => probeGain (r q) (st.word q) a K (st.ordinary q (x q))) + (fun q => st.ordinary q (x q)) (fun q => st.phase q • st.low.op q (x q)) hS ht he + simpa only [ContinuousLinearMap.comp_apply,LinearIsometryEquiv.coe_toContinuousLinearEquiv, + ContinuousLinearEquiv.coe_coe,compensatedGain_apply,PacketUnitaryFamily.trans,PacketUnitaryFamily.root, + LinearIsometryEquiv.trans_apply,SpinOperators.actEquiv_apply,←map_smul,←map_sub, + SpinOperators.norm_act (R_unitary _)] using hall + special_packets x hx := by + apply (st.special_packets x hx).close hS + simpa only [ContinuousLinearMap.comp_apply,LinearIsometryEquiv.coe_toContinuousLinearEquiv, + ContinuousLinearEquiv.coe_coe,compensatedGain_apply,compensated_error] using hs x hx + + + +theorem exists_compensated {r : α → ℝ} + (st : PacketStage l r (fun q => (r q)⁻¹) d spin) (θ : ℝ) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0 -2*(⟪insertionInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (v i).1)) + (hY : ∀i,Tendsto (fun q => -2*(⟪insertionYInfinity (st.word q),d i q⟫_ℂ).im) l (𝓝 (v i).2)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse) (st' : PacketStage l r (fun q => (r q)⁻¹) d spin), + (∀q,st'.word q=.mixer θ::probePrefix (r q) (st.word q) a K) ∧ + (∀q x,st'.low.op q x=SpinOperators.act (R θ) (st.low.op q x)) ∧ + (∀x,BoundedPacket l x → Tendsto (fun q => (r q)⁻¹*‖ + st'.special q (x q)-st.special q (x q)‖) l (𝓝 0)) := by + let o (q : α) := st.ordinary q (vacuum ModeInfinity) + let y (q : α) := st.phase q • st.low.op q (vacuum ModeInfinity) + let s (q : α) := st.special q (vacuum ModeInfinity) + obtain ⟨hS,hscale⟩ := reciprocal_scale_eventually r hr hp + have hS0 := hscale.mono (fun _ h => h.2.1) + have he : Tendsto (fun q => ‖o q-y q‖) l (𝓝 0) := + PacketGeometry.tendsto_of_scaled (fun q => (r q)⁻¹) _ hS + (Eventually.of_forall fun _ => norm_nonneg _) (st.ordinary_low _ BoundedPacket.vacuum) + have hψ : ∀ᶠ q in l,ordinaryLocal (st.word q) (vacuum ModeInfinity)=y q+s q+(o q-y q) := by + exact Eventually.of_forall fun q => by dsimp only [o,s]; rw [st.split]; abel + obtain ⟨K,a,ho,hsp⟩ := standard_selective_bounded r st.word y s (fun q => o q-y q) + (st.low_bounded _ BoundedPacket.vacuum) d spin C hC hd v hv (-θ) hr hp hψ + (st.special_vacuum_zero hr) he hZ hY + have hs := fun x hx => hsp _ (st.special_packets x hx) + let st' := st.compensated θ a K hS0 ho hs + refine ⟨K,a,st',fun _ => rfl,fun _ _ => rfl,?_⟩ + intro x hx + change Tendsto (fun q => (r q)⁻¹*‖compensatedGain (r q) (st.word q) a K θ + (st.special q (x q))-st.special q (x q)‖) l (𝓝 0) + simpa only [compensatedGain_apply,compensated_error] using hs x hx + +end PacketStage +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace ForwardControl +variable {H α : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] {l : Filter α} + + + +theorem scaled_preserve_transport (U V : α → H ≃ₗᵢ[ℂ] H) (Z : H →L[ℂ] H) + (hZ : ∀x,‖Z x‖≤‖x‖) (s w : α → H) (S : α → ℝ) + (hS : ∀ᶠ q in l,0≤S q) + (h1 : Tendsto (fun q => S q*‖V q (s q)-s q‖) l (𝓝 0)) + (h2 : Tendsto (fun q => S q*‖V q (Z (s q))-Z (s q)‖) l (𝓝 0)) + (ht : Tendsto (fun q => ‖(S q:ℂ) • (U q).symm (Z (s q))-w q‖) l (𝓝 0)) : + Tendsto (fun q => ‖(S q:ℂ) • (U q).symm ((V q).symm (Z (V q (s q))))-w q‖) l (𝓝 0) := by + have he : Tendsto (fun q => S q*‖(V q).symm (Z (V q (s q)))-Z (s q)‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [add_zero] using h1.add h2) + · filter_upwards [hS] with q hq + exact mul_nonneg hq (norm_nonneg _) + · filter_upwards [hS] with q hq + simpa only [mul_add] using mul_le_mul_of_nonneg_left + (preserve_transport_bound (V q) Z hZ (s q)) hq + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ + (by simpa only [add_zero] using he.add ht) + filter_upwards [hS] with q hq + have heq : (S q:ℂ) • (U q).symm ((V q).symm (Z (V q (s q))))-w q= + (S q:ℂ) • (U q).symm ((V q).symm (Z (V q (s q)))-Z (s q))+ + ((S q:ℂ) • (U q).symm (Z (s q))-w q) := by + simp only [map_sub,smul_sub] + abel + rw [heq] + apply (norm_add_le _ _).trans + rw [norm_smul,(U q).symm.norm_map,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hq] + +end ForwardControl + +namespace CoherentFock +open RootSpin +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem WZ_rootZ_apply (d : E) (x : SpinSpace E) : + WZ d (SpinOperators.act Z x)=SpinOperators.act Z (WZ d x) := by + exact congrArg (fun F : SpinSpace E →L[ℂ] SpinSpace E => F x) (WZ_rootZ d) + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin + +theorem local_symm_after_gain (w u : List Gate) + (V : SpinSpace ModeInfinity ≃ₗᵢ[ℂ] SpinSpace ModeInfinity) + (h : ∀x,V (ordinaryLocal w x)=ordinaryLocal u x) (x : SpinSpace ModeInfinity) : + (ordinaryLocal u).symm x=(ordinaryLocal w).symm (V.symm x) := by + apply (ordinaryLocal u).injective + rw [LinearIsometryEquiv.apply_symm_apply,←h,LinearIsometryEquiv.apply_symm_apply, + LinearIsometryEquiv.apply_symm_apply] + + + +theorem cost_transport_exact (w : List Gate) (c : ℝ) (x : SpinSpace ModeInfinity) : + (ordinaryLocal (.cost c::w)).symm + (SpinOperators.act Z (WZ (-(c:ℂ) • insertionInfinity w) x))= + (ordinaryLocal w).symm (SpinOperators.act Z x) := by + apply (ordinaryLocal (.cost c::w)).injective + rw [LinearIsometryEquiv.apply_symm_apply,ordinaryLocal_cost,LinearIsometryEquiv.apply_symm_apply, + WZ_rootZ_apply] + +namespace PacketStage +variable {α κ : Type*} [Fintype κ] {l : Filter α} {r S : α → ℝ} + {d : κ → α → ModeInfinity} {spin : κ → Fin 2} + + +def Transported (st : PacketStage l r S d spin) (a : α → SpinSpace ModeInfinity) : Prop := + Tendsto (fun q => ‖(S q:ℂ) • (ordinaryLocal (st.word q)).symm + (SpinOperators.act Z (st.special q (vacuum ModeInfinity)))-a q‖) l (𝓝 0) + +theorem Transported.cost {st : PacketStage l r S d spin} {a : α → SpinSpace ModeInfinity} + (ht : st.Transported a) (c : ℝ) : (st.cost c).Transported a := by + unfold Transported at * + simpa only [PacketStage.cost,ContinuousLinearMap.comp_apply,cost_transport_exact] using ht + +theorem Transported.compensated {st : PacketStage l r S d spin} {address : α → SpinSpace ModeInfinity} + (ht : st.Transported address) (θ : ℝ) (a : ℕ → ShortPulse) (K : ℕ) + (hS : ∀ᶠ q in l,0≤S q) + (ho : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K (x q)-x q‖) l (𝓝 0)) + (hs : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K (st.special q (x q))- + SpinOperators.act (R (-θ)) (st.special q (x q))‖) l (𝓝 0)) + (hz : Tendsto (fun q => S q*‖probeGain (r q) (st.word q) a K + (SpinOperators.act Z (st.special q (vacuum ModeInfinity)))- + SpinOperators.act (R (-θ)) (SpinOperators.act Z (st.special q (vacuum ModeInfinity)))‖) l (𝓝 0)) : + (st.compensated θ a K hS ho hs).Transported address := by + let V (q : α) := compensatedGain (r q) (st.word q) a K θ + have h1 : Tendsto (fun q => S q*‖V q (st.special q (vacuum ModeInfinity))- + st.special q (vacuum ModeInfinity)‖) l (𝓝 0) := by + simpa only [V,compensatedGain_apply,compensated_error] using hs _ BoundedPacket.vacuum + have h2 : Tendsto (fun q => S q*‖V q (SpinOperators.act Z (st.special q (vacuum ModeInfinity)))- + SpinOperators.act Z (st.special q (vacuum ModeInfinity))‖) l (𝓝 0) := by + simpa only [V,compensatedGain_apply,compensated_error] using hz + have h := ForwardControl.scaled_preserve_transport (fun q => ordinaryLocal (st.word q)) V + (SpinOperators.act Z) (fun x => (SpinOperators.norm_act Z_unitary x).le) + (fun q => st.special q (vacuum ModeInfinity)) address S hS h1 h2 ht + unfold Transported + have he (q : α) (x : SpinSpace ModeInfinity) : + (ordinaryLocal (.mixer θ::probePrefix (r q) (st.word q) a K)).symm x= + (ordinaryLocal (st.word q)).symm ((V q).symm x) := + local_symm_after_gain _ _ (V q) (compensatedGain_local _ _ _ _ _) x + change Tendsto (fun q => ‖(S q:ℂ) • + (ordinaryLocal (.mixer θ::probePrefix (r q) (st.word q) a K)).symm + (SpinOperators.act Z (V q (st.special q (vacuum ModeInfinity))))-address q‖) l (𝓝 0) + simpa only [he] using h + +end PacketStage +end PointedTree + +namespace SeedInitialization +open CoherentFock RootSpin PointedTree + +theorem initialStage_transported (b : ℝ) : + (initialStage b).Transported (fun T => modeFock (addressInfinity b T)) := by + unfold PacketStage.Transported + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop (1:ℝ)] with T hT + change (0:ℝ)=‖(T:ℂ) • (ordinaryLocal (wordInfinity b T)).symm + (SpinOperators.act Z (specialPartInfinity b T (vacuum ModeInfinity)))-modeFock (addressInfinity b T)‖ + rw [←addressInfinity_exact b hT,smul_smul] + have hT0 : T≠0 := by linarith + simp only [amplitude,Complex.ofReal_inv,mul_inv_cancel₀ (Complex.ofReal_ne_zero.mpr hT0),one_smul, + sub_self,norm_zero] + +end SeedInitialization + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ScalarPhase.lean b/lean/OAI/Probability/ParisiFinite/ScalarPhase.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d5662adbc1302ebb3f63854f50fd62417e7eb93 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ScalarPhase.lean @@ -0,0 +1,701 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Law + +namespace OAI + +/-! Scalar Phase. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter + +namespace ClassicalGaussian +variable {Ω E : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +def scalarPhase (t x : ℝ) : ℂ := Complex.exp (Complex.I*((t*x : ℝ):ℂ)) + +@[simp] theorem norm_scalarPhase (t x : ℝ) : ‖scalarPhase t x‖=1 := by + simp [scalarPhase,Complex.norm_exp,Complex.mul_re] + +theorem continuous_scalarPhase (t : ℝ) : Continuous (scalarPhase t) := by + unfold scalarPhase + fun_prop + +theorem memLp_phase_smul {q : Ω → ℝ} (hq : AEStronglyMeasurable q μ) + (t : ℝ) (ψ : Lp E 2 μ) : + MemLp (fun x=>scalarPhase t (q x) • ψ x) 2 μ := by + apply (Lp.memLp ψ).congr_norm + (((continuous_scalarPhase t).comp_aestronglyMeasurable hq).smul (Lp.aestronglyMeasurable ψ)) + exact Eventually.of_forall fun x=>by + change ‖ψ x‖=‖scalarPhase t (q x) • ψ x‖ + simp only [norm_smul,norm_scalarPhase,one_mul] + + + +def phaseMultiplier {q : Ω → ℝ} (hq : AEStronglyMeasurable q μ) + (t : ℝ) : Lp E 2 μ →ₗᵢ[ℂ] Lp E 2 μ where + toFun ψ := (memLp_phase_smul μ hq t ψ).toLp (fun x=>scalarPhase t (q x) • ψ x) + map_add' ψ φ := by + apply Lp.ext + filter_upwards [MemLp.coeFn_toLp (memLp_phase_smul μ hq t (ψ+φ)), + Lp.coeFn_add ψ φ, + Lp.coeFn_add ((memLp_phase_smul μ hq t ψ).toLp _) ((memLp_phase_smul μ hq t φ).toLp _), + MemLp.coeFn_toLp (memLp_phase_smul μ hq t ψ), + MemLp.coeFn_toLp (memLp_phase_smul μ hq t φ)] with x h1 h2 h3 h4 h5 + simp only [Pi.add_apply] at h2 h3 + rw [h1,h2,h3,h4,h5,smul_add] + map_smul' c ψ := by + apply Lp.ext + filter_upwards [MemLp.coeFn_toLp (memLp_phase_smul μ hq t (c • ψ)), + Lp.coeFn_smul c ψ, + Lp.coeFn_smul c ((memLp_phase_smul μ hq t ψ).toLp _), + MemLp.coeFn_toLp (memLp_phase_smul μ hq t ψ)] with x h1 h2 h3 h4 + simp only [Pi.smul_apply] at h2 h3 + simp only [RingHom.id_apply] + rw [h1,h2,h3,h4,smul_comm] + norm_map' ψ := by + change ‖(memLp_phase_smul μ hq t ψ).toLp (fun x=>scalarPhase t (q x) • ψ x)‖=‖ψ‖ + rw [Lp.norm_toLp,Lp.norm_def] + congr 1 + apply eLpNorm_congr_norm_ae (memLp_phase_smul μ hq t ψ).aestronglyMeasurable + (Lp.aestronglyMeasurable ψ) + exact Eventually.of_forall fun x=>by simp only [norm_smul,norm_scalarPhase,one_mul] + +theorem phaseMultiplier_ae {q : Ω → ℝ} (hq : AEStronglyMeasurable q μ) + (t : ℝ) (ψ : Lp E 2 μ) : + (phaseMultiplier μ hq t ψ : Ω → E)=ᵐ[μ] fun x=>scalarPhase t (q x) • ψ x := + MemLp.coeFn_toLp (memLp_phase_smul μ hq t ψ) + +@[simp] theorem scalarPhase_zero (x : ℝ) : scalarPhase 0 x=1 := by + simp [scalarPhase] + +theorem scalarPhase_add (t u x : ℝ) : + scalarPhase (t+u) x=scalarPhase t x*scalarPhase u x := by + simp only [scalarPhase,add_mul,Complex.ofReal_add,mul_add,Complex.exp_add] + +@[simp] theorem phaseMultiplier_zero {q : Ω → ℝ} (hq : AEStronglyMeasurable q μ) + (ψ : Lp E 2 μ) : phaseMultiplier μ hq 0 ψ=ψ := by + apply Lp.ext + filter_upwards [phaseMultiplier_ae μ hq 0 ψ] with x hx + simpa only [scalarPhase_zero,one_smul] using hx + +theorem phaseMultiplier_add {q : Ω → ℝ} (hq : AEStronglyMeasurable q μ) + (t u : ℝ) (ψ : Lp E 2 μ) : + phaseMultiplier μ hq (t+u) ψ=phaseMultiplier μ hq t (phaseMultiplier μ hq u ψ) := by + apply Lp.ext + filter_upwards [phaseMultiplier_ae μ hq (t+u) ψ, + phaseMultiplier_ae μ hq t (phaseMultiplier μ hq u ψ), + phaseMultiplier_ae μ hq u ψ] with x h1 h2 h3 + rw [h1,h2,h3,scalarPhase_add,mul_smul] + + +def phaseUnitary {q : Ω → ℝ} (hq : AEStronglyMeasurable q μ) + (t : ℝ) : Lp E 2 μ ≃ₗᵢ[ℂ] Lp E 2 μ := + LinearIsometryEquiv.ofSurjective (phaseMultiplier μ hq t) (by + intro ψ + refine ⟨phaseMultiplier μ hq (-t) ψ,?_⟩ + rw [←phaseMultiplier_add,add_neg_cancel,phaseMultiplier_zero]) + +@[simp] theorem phaseUnitary_apply {q : Ω → ℝ} (hq : AEStronglyMeasurable q μ) + (t : ℝ) (ψ : Lp E 2 μ) : phaseUnitary μ hq t ψ=phaseMultiplier μ hq t ψ := rfl + +theorem L2_norm_sq_integral (ψ : Lp E 2 μ) : + ‖ψ‖^2=∫x,‖ψ x‖^2 ∂μ := by + rw [norm_sq_eq_re_inner (𝕜:=ℂ),L2.inner_def,←integral_re (L2.integrable_inner ψ ψ)] + apply integral_congr_ae + exact Eventually.of_forall fun x=>(norm_sq_eq_re_inner (𝕜:=ℂ) (ψ x)).symm + + + +theorem phaseMultiplier_tendsto [IsFiniteMeasure μ] + {q : ℕ → Ω → ℝ} (hq : ∀n,MemLp (q n) 2 μ) + (ht : Tendsto (fun n=>∫x,q n x^2 ∂μ) atTop (𝓝 0)) (t : ℝ) (ψ : Lp E 2 μ) : + Tendsto (fun n=>phaseMultiplier μ (hq n).aestronglyMeasurable t ψ) atTop (𝓝 ψ) := by + have hρ : Integrable (fun x=>‖ψ x‖^2) μ := (Lp.memLp ψ).integrable_norm_pow' + have h := phase_weighted_L2_tendsto μ hq ht t (fun x=>‖ψ x‖^2) hρ + have he (n : ℕ) : ‖phaseMultiplier μ (hq n).aestronglyMeasurable t ψ-ψ‖^2= + ∫x,|‖ψ x‖^2| *phaseError t (q n x) ∂μ := by + rw [L2_norm_sq_integral] + apply integral_congr_ae + filter_upwards [Lp.coeFn_sub (phaseMultiplier μ (hq n).aestronglyMeasurable t ψ) ψ, + phaseMultiplier_ae μ (hq n).aestronglyMeasurable t ψ] with x h1 h2 + simp only [Pi.sub_apply] at h1 + rw [h1,h2,show scalarPhase t (q n x) • ψ x-ψ x= + (scalarPhase t (q n x)-1) • ψ x by rw [sub_smul,one_smul]] + rw [norm_smul,mul_pow,abs_of_nonneg (sq_nonneg _)] + exact mul_comm _ _ + have hn : Tendsto (fun n=>‖phaseMultiplier μ (hq n).aestronglyMeasurable t ψ-ψ‖) + atTop (𝓝 0) := by + have hs := Real.continuous_sqrt.continuousAt.tendsto.comp h + simp only [←he,Real.sqrt_sq (norm_nonneg _),Real.sqrt_zero,Function.comp_def] at hs + exact hs + exact tendsto_iff_norm_sub_tendsto_zero.mpr hn + +end ClassicalGaussian + + + +open scoped Topology +open Filter MeasureTheory + +namespace StrongIsometryContexts +variable {α E F G ι : Type*} [NormedAddCommGroup E] [NormedSpace ℂ E] + [NormedAddCommGroup F] [NormedSpace ℂ F] + [NormedAddCommGroup G] [NormedSpace ℂ G] {l : Filter α} + + + +theorem apply_varying {U : α → E →ₗᵢ[ℂ] F} {V : E →ₗᵢ[ℂ] F} + (hU : ∀x,Tendsto (fun n=>U n x) l (𝓝 (V x))) + {x : α → E} {x₀ : E} (hx : Tendsto x l (𝓝 x₀)) : + Tendsto (fun n=>U n (x n)) l (𝓝 (V x₀)) := by + apply tendsto_iff_dist_tendsto_zero.mpr + have h := (tendsto_iff_dist_tendsto_zero.mp hx).add + (tendsto_iff_dist_tendsto_zero.mp (hU x₀)) + apply squeeze_zero (fun n=>dist_nonneg) _ (by simpa only [zero_add] using h) + intro n + calc + dist (U n (x n)) (V x₀)≤dist (U n (x n)) (U n x₀)+dist (U n x₀) (V x₀) := + dist_triangle _ _ _ + _=dist (x n) x₀+dist (U n x₀) (V x₀) := by rw [(U n).dist_map] + +theorem comp {U : α → F →ₗᵢ[ℂ] G} {V : F →ₗᵢ[ℂ] G} + (hU : ∀x,Tendsto (fun n=>U n x) l (𝓝 (V x))) + {A : α → E →ₗᵢ[ℂ] F} {B : E →ₗᵢ[ℂ] F} + (hA : ∀x,Tendsto (fun n=>A n x) l (𝓝 (B x))) (x : E) : + Tendsto (fun n=>(U n).comp (A n) x) l (𝓝 (V.comp B x)) := + apply_varying hU (hA x) + + +def word (U : ι → E →ₗᵢ[ℂ] E) : List ι → E →ₗᵢ[ℂ] E + | [] => LinearIsometry.id + | a::w => (word U w).comp (U a) + + + +theorem word_tendsto (w : List ι) {U : α → ι → E →ₗᵢ[ℂ] E} {V : ι → E →ₗᵢ[ℂ] E} + (h : ∀a x,Tendsto (fun n=>U n a x) l (𝓝 (V a x))) (x : E) : + Tendsto (fun n=>word (U n) w x) l (𝓝 (word V w x)) := by + induction w generalizing x with + | nil => exact tendsto_const_nhds + | cons a w ih => exact comp (fun y=>ih y) (h a) x + + + +theorem phase_in_context {Ω H : Type*} [MeasurableSpace Ω] + [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (μ : Measure Ω) [IsFiniteMeasure μ] + {q : ℕ → Ω → ℝ} (hq : ∀n,MemLp (q n) 2 μ) + (ht : Tendsto (fun n=>∫x,q n x^2 ∂μ) atTop (𝓝 0)) (t : ℝ) + (A B : Lp H 2 μ →ₗᵢ[ℂ] Lp H 2 μ) (ψ : Lp H 2 μ) : + Tendsto (fun n=>B (ClassicalGaussian.phaseMultiplier μ (hq n).aestronglyMeasurable t (A ψ))) + atTop (𝓝 (B (A ψ))) := + B.continuous.continuousAt.tendsto.comp + (ClassicalGaussian.phaseMultiplier_tendsto μ hq ht t (A ψ)) + +end StrongIsometryContexts + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory + +namespace ClassicalGaussian.Shifted +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +variable {ι : Type*} + +def form (s : Finset ι) (d e : ι → E) (g : E) : ℝ := + ∑i∈s,centeredQuadratic E (d i) (e i) g + +def kernel (s : Finset ι) (d e : ι → E) : E →L[ℝ] E := + ∑i∈s,InnerProductSpace.rankOne ℝ (d i) (e i) + +def kernelSq (s : Finset ι) (d e : ι → E) : ℝ := + ∑i∈s,‖d i‖^2*‖e i‖^2 + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem kernelSq_nonneg (s : Finset ι) (d e : ι → E) : 0≤kernelSq E s d e := + Finset.sum_nonneg fun _ _=>mul_nonneg (sq_nonneg _) (sq_nonneg _) + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem kernelSq_swap (s : Finset ι) (d e : ι → E) : + kernelSq E s e d=kernelSq E s d e := by + simp only [kernelSq,mul_comm] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem field_kernel (s : Finset ι) (d e : ι → E) (m g : E) : + field E (kernel E s d e m) g=∑i∈s,field E (e i) m*field E (d i) g := by + simp [kernel,field,sum_apply,InnerProductSpace.rankOne_apply,sum_inner,real_inner_smul_left] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem form_translate (s : Finset ι) (d e : ι → E) (m g : E) : + form E s d e (g+m)=form E s d e g+ + field E (kernel E s d e m) g+field E (kernel E s e d m) g+ + ⟪m,kernel E s d e m⟫ := by + rw [field_kernel,field_kernel] + have hc : ⟪m,kernel E s d e m⟫=∑i∈s,field E (d i) m*field E (e i) m := by + simp [kernel,sum_apply,InnerProductSpace.rankOne_apply,inner_sum,real_inner_smul_right,field,real_inner_comm,mul_comm] + rw [hc] + simp only [form,centeredQuadratic,field,inner_add_right,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i hi + ring + +theorem memLp_form (s : Finset ι) (d e : ι → E) : + MemLp (form E s d e) 2 (stdGaussian E) := + memLp_finsetSum s (fun i _=>memLp_centeredQuadratic E (d i) (e i)) + +theorem memLp_form_translate (s : Finset ι) (d e : ι → E) (m : E) : + MemLp (fun g=>form E s d e (g+m)) 2 (stdGaussian E) := by + have h := (((memLp_form E s d e).add (memLp_field E (kernel E s d e m))).add + (memLp_field E (kernel E s e d m))).add (memLp_const ⟪m,kernel E s d e m⟫) + exact MemLp.ae_eq (Filter.Eventually.of_forall fun g=>(form_translate E s d e m g).symm) h + +theorem form_second_moment_le (s : Finset ι) (d e : ι → E) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) : + (∫g,form E s d e g^2 ∂stdGaussian E)≤2*kernelSq E s d e := by + change (∫g,(∑i∈s,centeredQuadratic E (d i) (e i) g)^2 ∂stdGaussian E)≤_ + rw [quadratic_sum_variance E s d e ho] + simp only [kernelSq,Finset.mul_sum] + apply Finset.sum_le_sum + intro i hi + have h := sq_le_sq₀ (abs_nonneg ⟪d i,e i⟫) + (mul_nonneg (norm_nonneg _) (norm_nonneg _)) |>.mpr (abs_real_inner_le_norm (d i) (e i)) + simp only [sq_abs,mul_pow] at h + nlinarith + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem kernel_apply_sq_le (s : Finset ι) (d e : ι → E) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0) (m : E) : + ‖kernel E s d e m‖^2≤kernelSq E s d e*‖m‖^2 := + OrthogonalKernels.rankOne_sum_apply_sq_le s d e ho m + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +theorem kernel_pairing_sq_le (s : Finset ι) (d e : ι → E) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0) (m : E) : + ⟪m,kernel E s d e m⟫^2≤kernelSq E s d e*‖m‖^4 := by + have hh := sq_le_sq₀ (abs_nonneg ⟪m,kernel E s d e m⟫) + (mul_nonneg (norm_nonneg _) (norm_nonneg _)) |>.mpr + (abs_real_inner_le_norm m (kernel E s d e m)) + simp only [sq_abs,mul_pow] at hh + have hb := mul_le_mul_of_nonneg_left (kernel_apply_sq_le E s d e ho m) (sq_nonneg ‖m‖) + nlinarith + + + +theorem translated_second_moment_le (s : Finset ι) (d e : ι → E) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) + (he : ∀i∈s,∀j∈s,i≠j → ⟪e i,e j⟫=0) (m : E) : + (∫g,form E s d e (g+m)^2 ∂stdGaussian E)≤ + kernelSq E s d e*(8+8*‖m‖^2+4*‖m‖^4) := by + let A := kernel E s d e m + let B := kernel E s e d m + let c := ⟪m,A⟫ + have hQ := (memLp_form E s d e).integrable_sq + have hA := (memLp_field E A).integrable_sq + have hB := (memLp_field E B).integrable_sq + have hC : Integrable (fun _ : E=>c^2) (stdGaussian E) := integrable_const _ + have hb : (∫g,form E s d e (g+m)^2 ∂stdGaussian E)≤ + ∫g,4*(form E s d e g^2+field E A g^2+field E B g^2+c^2) ∂stdGaussian E := by + apply integral_mono ((memLp_form_translate E s d e m).integrable_sq) + (((hQ.add hA).add hB).add hC |>.const_mul 4) + intro g + dsimp only [Pi.add_apply] + rw [form_translate] + change (form E s d e g+field E A g+field E B g+c)^2≤_ + nlinarith [sq_nonneg (form E s d e g-field E A g), + sq_nonneg (form E s d e g-field E B g),sq_nonneg (form E s d e g-c), + sq_nonneg (field E A g-field E B g),sq_nonneg (field E A g-c), + sq_nonneg (field E B g-c)] + have hInt := integral_add ((hQ.add hA).add hB) hC + have hInt2 := integral_add (hQ.add hA) hB + have hInt3 := integral_add hQ hA + simp only [Pi.add_apply] at hInt hInt2 hInt3 + rw [integral_const_mul,hInt,hInt2,hInt3] at hb + have haa : (∫g,field E A g^2 ∂stdGaussian E)=‖A‖^2 := by + simpa only [pow_two,real_inner_self_eq_norm_sq] using field_covariance E A A + have hbb : (∫g,field E B g^2 ∂stdGaussian E)=‖B‖^2 := by + simpa only [pow_two,real_inner_self_eq_norm_sq] using field_covariance E B B + rw [haa,hbb,integral_const,probReal_univ,one_smul] at hb + have hsm := form_second_moment_le E s d e ho + have hao := kernel_apply_sq_le E s d e (fun i hi j hj hn=>(ho i hi j hj hn).1) m + have hbo := kernel_apply_sq_le E s e d he m + rw [kernelSq_swap] at hbo + have hco := kernel_pairing_sq_le E s d e (fun i hi j hj hn=>(ho i hi j hj hn).1) m + dsimp only [A,B,c] at hb + nlinarith + +end ClassicalGaussian.Shifted + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory Filter + +namespace GaussianCoherent.Quadratic +variable {κ ι : Type*} [Fintype κ] + +abbrev RealMode (κ : Type*) [Fintype κ] := EuclideanSpace ℝ κ + + + +theorem coordinate_preserving : MeasurePreserving (WithLp.toLp 2 : (κ → ℝ) → RealMode κ) + (GaussianFourier.law κ) (stdGaussian (RealMode κ)) := by + refine ⟨by fun_prop,?_⟩ + exact map_pi_eq_stdGaussian + +def symbol (s : Finset ι) (d e : ι → RealMode κ) (g : κ → ℝ) : ℝ := + ClassicalGaussian.Shifted.form (RealMode κ) s d e (WithLp.toLp 2 g) + +theorem memLp_symbol (s : Finset ι) (d e : ι → RealMode κ) : + MemLp (symbol s d e) 2 (GaussianFourier.law κ) := + (ClassicalGaussian.Shifted.memLp_form (RealMode κ) s d e).comp_measurePreserving + coordinate_preserving + +theorem symbol_second_moment_le (s : Finset ι) (d e : ι → RealMode κ) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) : + (∫g,symbol s d e g^2 ∂GaussianFourier.law κ)≤ + 2*ClassicalGaussian.Shifted.kernelSq (RealMode κ) s d e := by + have hl : HasLaw (WithLp.toLp 2 : (κ → ℝ) → RealMode κ) + (stdGaussian (RealMode κ)) (GaussianFourier.law κ) := + ⟨coordinate_preserving.measurable.aemeasurable,coordinate_preserving.map_eq⟩ + have he := hl.integral_comp + ((ClassicalGaussian.Shifted.memLp_form (RealMode κ) s d e).integrable_sq.aestronglyMeasurable) + rw [show (∫g,symbol s d e g^2 ∂GaussianFourier.law κ)= + ∫g,ClassicalGaussian.Shifted.form (RealMode κ) s d e g^2 ∂stdGaussian (RealMode κ) from he] + exact ClassicalGaussian.Shifted.form_second_moment_le (RealMode κ) s d e ho + + + +def unitary (s : Finset ι) (d e : ι → RealMode κ) (t : ℝ) : + CoherentFock.Space (Mode κ) ≃ₗᵢ[ℂ] CoherentFock.Space (Mode κ) := + gaussianUnitary.trans ((ClassicalGaussian.phaseUnitary (GaussianFourier.law κ) + (memLp_symbol s d e).aestronglyMeasurable t).trans gaussianUnitary.symm) + +@[simp] theorem gaussian_unitary_apply (s : Finset ι) (d e : ι → RealMode κ) + (t : ℝ) (ψ : CoherentFock.Space (Mode κ)) : + gaussianUnitary (unitary s d e t ψ)= + ClassicalGaussian.phaseMultiplier (GaussianFourier.law κ) + (memLp_symbol s d e).aestronglyMeasurable t (gaussianUnitary ψ) := by + simp only [unitary,LinearIsometryEquiv.trans_apply,LinearIsometryEquiv.apply_symm_apply, + ClassicalGaussian.phaseUnitary_apply] + + + +theorem unitary_coherent_ae (s : Finset ι) (d e : ι → RealMode κ) + (t : ℝ) (v : Mode κ) : + (gaussianUnitary (unitary s d e t (CoherentFock.coherent v)) : (κ → ℝ) → ℂ)=ᵐ[GaussianFourier.law κ] + fun g=>ClassicalGaussian.scalarPhase t (symbol s d e g)*wave v g := by + rw [gaussian_unitary_apply,gaussianUnitary_coherent] + filter_upwards [ClassicalGaussian.phaseMultiplier_ae (GaussianFourier.law κ) + (memLp_symbol s d e).aestronglyMeasurable t (vector v),vector_ae v] with g h1 h2 + rw [h1,h2,smul_eq_mul] + +@[simp] theorem unitary_zero (s : Finset ι) (d e : ι → RealMode κ) + (ψ : CoherentFock.Space (Mode κ)) : unitary s d e 0 ψ=ψ := by + apply gaussianUnitary.injective + rw [gaussian_unitary_apply,ClassicalGaussian.phaseMultiplier_zero] + +theorem unitary_add (s : Finset ι) (d e : ι → RealMode κ) (t u : ℝ) + (ψ : CoherentFock.Space (Mode κ)) : + unitary s d e (t+u) ψ=unitary s d e t (unitary s d e u ψ) := by + apply gaussianUnitary.injective + simp only [gaussian_unitary_apply,ClassicalGaussian.phaseMultiplier_add] + + + +theorem unitary_tendsto {s : ℕ → Finset ι} {d e : ℕ → ι → RealMode κ} + (ho : ∀n,∀i∈s n,∀j∈s n,i≠j → ⟪d n i,d n j⟫=0 ∧ ⟪d n i,e n j⟫=0) + (hk : Tendsto (fun n=>ClassicalGaussian.Shifted.kernelSq (RealMode κ) (s n) (d n) (e n)) + atTop (𝓝 0)) (t : ℝ) (ψ : CoherentFock.Space (Mode κ)) : + Tendsto (fun n=>unitary (s n) (d n) (e n) t ψ) atTop (𝓝 ψ) := by + have hq : Tendsto (fun n=>∫g,symbol (s n) (d n) (e n) g^2 ∂GaussianFourier.law κ) + atTop (𝓝 0) := by + apply squeeze_zero (fun n=>integral_nonneg fun g=>sq_nonneg _) + (fun n=>symbol_second_moment_le (s n) (d n) (e n) (ho n)) + simpa only [mul_zero] using hk.const_mul 2 + have hh := ClassicalGaussian.phaseMultiplier_tendsto (GaussianFourier.law κ) + (fun n=>memLp_symbol (s n) (d n) (e n)) hq t (gaussianUnitary ψ) + have hh' := gaussianUnitary.symm.continuous.continuousAt.tendsto.comp hh + simpa only [Function.comp_def,unitary,LinearIsometryEquiv.trans_apply, + ClassicalGaussian.phaseUnitary_apply,LinearIsometryEquiv.symm_apply_apply] using hh' + +end GaussianCoherent.Quadratic + + + +open scoped BigOperators Topology +open MeasureTheory ProbabilityTheory Complex + +namespace GaussianFourier +open scoped _root_.GaussianFourier +variable {κ : Type*} [Fintype κ] + +def dot (a g : κ → ℝ) : ℝ := ∑k,a k*g k + +theorem integrable_real_exp_dot (a : κ → ℝ) : + Integrable (fun g=>Real.exp (dot a g)) (law κ) := by + have h := (integrable_exp_sum (fun k=>(a k:ℂ))).re + convert h using 1 + funext g + simp only [dot,←Complex.ofReal_mul,←Complex.ofReal_sum,←Complex.ofReal_exp] + rfl + +theorem integral_real_exp_dot (a : κ → ℝ) : + (∫g,Real.exp (dot a g) ∂law κ)=Real.exp (∑k,a k^2/2) := by + have h := congrArg (RCLike.re : ℂ → ℝ) (integral_exp_sum (fun k=>(a k:ℂ))) + rw [←integral_re (integrable_exp_sum (fun k=>(a k:ℂ)))] at h + simp only [←Complex.ofReal_mul,←Complex.ofReal_sum,←Complex.ofReal_exp, + ←Complex.ofReal_pow,←Complex.ofReal_div,←Complex.ofReal_ofNat] at h + exact h + +theorem linear_eq_dot (L : (κ → ℝ) →L[ℝ] ℝ) : + ∃a : κ → ℝ,∀g,L g=dot a g := by + classical + refine ⟨fun k=>L (Pi.single k 1),fun g=>?_⟩ + have hg : g=∑k,g k • Pi.single k (1:ℝ) := by + funext j + simp [Pi.single_apply] + conv_lhs => rw [hg,map_sum] + simp only [map_smul,smul_eq_mul,dot] + apply Finset.sum_congr rfl + intro k hk + rw [mul_comm] + +theorem charFunDual_eq_dot (L : (κ → ℝ) →L[ℝ] ℝ) (b : κ → ℝ) + (hb : ∀g,L g=dot b g) : + charFunDual (law κ) L=Complex.exp (∑k,((b k:ℂ)*I)^2/2) := by + rw [charFunDual_apply] + convert integral_exp_sum (fun k=>(b k:ℂ)*I) using 1 + congr 1 + funext g + congr 1 + rw [hb] + simp only [dot,Complex.ofReal_sum,Complex.ofReal_mul,Finset.sum_mul] + apply Finset.sum_congr rfl + intro k hk + ring + + + +theorem tilted_dot_eq_map_add (a : κ → ℝ) : + (law κ).tilted (dot a)=(law κ).map (fun g=>g+a) := by + have := isProbabilityMeasure_tilted (integrable_real_exp_dot a) + apply Measure.ext_of_charFunDual + funext L + obtain ⟨b,hb⟩ := linear_eq_dot L + rw [charFunDual_map_add_const,charFunDual_eq_dot L b hb,hb] + rw [charFunDual_apply,integral_tilted,integral_real_exp_dot] + have hp (g : κ → ℝ) : + (Real.exp (dot a g)/Real.exp (∑k,a k^2/2)) • Complex.exp ((L g:ℂ)*I)= + Complex.exp (-((∑k,a k^2/2:ℝ):ℂ))* + Complex.exp (∑k,((a k:ℂ)+(b k:ℂ)*I)*(g k:ℂ)) := by + rw [←Real.exp_sub,Complex.real_smul,Complex.ofReal_exp] + simp only [←Complex.exp_add] + rw [hb] + congr 1 + simp only [Complex.ofReal_sub,Complex.ofReal_sum,Complex.ofReal_mul,dot, + Finset.sum_mul,Finset.sum_add_distrib,add_mul] + simp only [mul_comm,mul_left_comm] + ring + simp_rw [hp] + rw [integral_const_mul,integral_exp_sum,←Complex.exp_add,←Complex.exp_add] + congr 1 + simp only [dot,Complex.ofReal_sum,Complex.ofReal_mul,←Finset.sum_neg_distrib, + ←Finset.sum_add_distrib,Finset.sum_mul] + apply Finset.sum_congr rfl + intro k hk + push_cast + ring + + + +theorem integral_exp_dot_mul {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] + (a : κ → ℝ) (f : (κ → ℝ) → F) + (hf : AEStronglyMeasurable f ((law κ).map (fun g=>g+a))) : + (∫g,Real.exp (dot a g-∑k,a k^2/2) • f g ∂law κ)= + ∫g,f (g+a) ∂law κ := by + calc + _=∫g,f g ∂(law κ).tilted (dot a) := by + rw [integral_tilted,integral_real_exp_dot] + simp only [Real.exp_sub] + _=∫g,f g ∂(law κ).map (fun g=>g+a) := by rw [tilted_dot_eq_map_add] + _=_ := by rw [integral_map (by fun_prop) hf] + +end GaussianFourier + + + +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open MeasureTheory ProbabilityTheory Complex + +namespace GaussianCoherent +variable {κ : Type*} [Fintype κ] + + +def realShift (v : Mode κ) : κ → ℝ := fun k=> -2*(v k).im + +theorem realShift_complex (v : Mode κ) (k : κ) : + I*(v k-conj (v k))=(realShift v k:ℂ) := by + apply Complex.ext <;> simp [realShift,Complex.mul_re,Complex.mul_im]; ring + +theorem offset_shift (v : Mode κ) : + conj (offset v)+offset v= -((∑k,realShift v k^2/2:ℝ):ℂ) := by + have h := exponent_pair v v + simp_rw [realShift_complex] at h + rw [inner_self_eq_norm_sq_to_K] at h + push_cast at h ⊢ + linear_combination h + + + +theorem norm_wave_sq (v : Mode κ) (g : κ → ℝ) : + ‖wave v g‖^2=Real.exp (GaussianFourier.dot (realShift v) g- + ∑k,realShift v k^2/2) := by + have h := wave_pair v v g + rw [offset_shift] at h + simp_rw [realShift_complex] at h + rw [←Complex.exp_add] at h + have hx : -((∑k,realShift v k^2/2:ℝ):ℂ)+ + (∑k,(realShift v k:ℂ)*(g k:ℂ))= + ((GaussianFourier.dot (realShift v) g-∑k,realShift v k^2/2:ℝ):ℂ) := by + unfold GaussianFourier.dot + push_cast + ring + rw [hx,←Complex.ofReal_exp,Complex.conj_mul'] at h + have hh := congrArg Complex.re h + simpa only [←Complex.ofReal_pow,Complex.ofReal_re] using hh + +theorem coherent_tilt_integral {F : Type*} [NormedAddCommGroup F] [NormedSpace ℝ F] + (v : Mode κ) (f : (κ → ℝ) → F) + (hf : AEStronglyMeasurable f ((GaussianFourier.law κ).map (fun g=>g+realShift v))) : + (∫g,‖wave v g‖^2 • f g ∂GaussianFourier.law κ)= + ∫g,f (g+realShift v) ∂GaussianFourier.law κ := by + simp_rw [norm_wave_sq] + exact GaussianFourier.integral_exp_dot_mul _ _ hf + +end GaussianCoherent + + + +open scoped BigOperators Topology RealInnerProductSpace +open MeasureTheory ProbabilityTheory Filter + +namespace GaussianCoherent.Quadratic +variable {κ ι : Type*} [Fintype κ] + +theorem continuous_symbol (s : Finset ι) (d e : ι → RealMode κ) : + Continuous (symbol s d e) := by + unfold symbol ClassicalGaussian.Shifted.form ClassicalGaussian.centeredQuadratic + ClassicalGaussian.field + fun_prop + +theorem memLp_symbol_translate (s : Finset ι) (d e : ι → RealMode κ) (m : κ → ℝ) : + MemLp (fun g=>symbol s d e (g+m)) 2 (GaussianFourier.law κ) := by + simpa only [symbol,WithLp.toLp_add,Function.comp_def] using + (ClassicalGaussian.Shifted.memLp_form_translate (RealMode κ) s d e (WithLp.toLp 2 m)).comp_measurePreserving + coordinate_preserving + +theorem translated_symbol_second_moment_le (s : Finset ι) (d e : ι → RealMode κ) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) + (he : ∀i∈s,∀j∈s,i≠j → ⟪e i,e j⟫=0) (m : κ → ℝ) : + (∫g,symbol s d e (g+m)^2 ∂GaussianFourier.law κ)≤ + ClassicalGaussian.Shifted.kernelSq (RealMode κ) s d e* + (8+8*‖WithLp.toLp 2 m‖^2+4*‖WithLp.toLp 2 m‖^4) := by + have hl : HasLaw (WithLp.toLp 2 : (κ → ℝ) → RealMode κ) + (stdGaussian (RealMode κ)) (GaussianFourier.law κ) := + ⟨coordinate_preserving.measurable.aemeasurable,coordinate_preserving.map_eq⟩ + have hh := hl.integral_comp + ((ClassicalGaussian.Shifted.memLp_form_translate (RealMode κ) s d e (WithLp.toLp 2 m)).integrable_sq.aestronglyMeasurable) + calc + _=∫g,ClassicalGaussian.Shifted.form (RealMode κ) s d e (g+WithLp.toLp 2 m)^2 ∂stdGaussian (RealMode κ) := by + simpa only [symbol,WithLp.toLp_add,Function.comp_def] using hh + _≤_ := ClassicalGaussian.Shifted.translated_second_moment_le (RealMode κ) s d e ho he _ + + + +theorem coherent_error_integral (s : Finset ι) (d e : ι → RealMode κ) + (t : ℝ) (v : Mode κ) : + ‖unitary s d e t (CoherentFock.coherent v)-CoherentFock.coherent v‖^2= + ∫g,ClassicalGaussian.phaseError t (symbol s d e (g+realShift v)) ∂GaussianFourier.law κ := by + have hn := gaussianUnitary.norm_map + (unitary s d e t (CoherentFock.coherent v)-CoherentFock.coherent v) + rw [map_sub,gaussian_unitary_apply,gaussianUnitary_coherent] at hn + rw [←hn,ClassicalGaussian.L2_norm_sq_integral] + calc + _=∫g,‖wave v g‖^2 • ClassicalGaussian.phaseError t (symbol s d e g) ∂GaussianFourier.law κ := by + apply integral_congr_ae + filter_upwards [Lp.coeFn_sub + (ClassicalGaussian.phaseMultiplier (GaussianFourier.law κ) + (memLp_symbol s d e).aestronglyMeasurable t (vector v)) (vector v), + ClassicalGaussian.phaseMultiplier_ae (GaussianFourier.law κ) + (memLp_symbol s d e).aestronglyMeasurable t (vector v),vector_ae v] with g h1 h2 h3 + simp only [Pi.sub_apply] at h1 + rw [h1,h2,h3,smul_eq_mul] + rw [show ClassicalGaussian.scalarPhase t (symbol s d e g)*wave v g-wave v g= + (ClassicalGaussian.scalarPhase t (symbol s d e g)-1)*wave v g by ring] + rw [norm_mul,mul_pow,smul_eq_mul] + exact mul_comm _ _ + _=_ := coherent_tilt_integral v _ + ((ClassicalGaussian.continuous_phaseError t).comp (continuous_symbol s d e)).aestronglyMeasurable + + + +theorem coherent_error_sq_le (s : Finset ι) (d e : ι → RealMode κ) + (ho : ∀i∈s,∀j∈s,i≠j → ⟪d i,d j⟫=0 ∧ ⟪d i,e j⟫=0) + (he : ∀i∈s,∀j∈s,i≠j → ⟪e i,e j⟫=0) (t : ℝ) (v : Mode κ) : + ‖unitary s d e t (CoherentFock.coherent v)-CoherentFock.coherent v‖^2≤ + t^2*ClassicalGaussian.Shifted.kernelSq (RealMode κ) s d e* + (8+8*‖WithLp.toLp 2 (realShift v)‖^2+4*‖WithLp.toLp 2 (realShift v)‖^4) := by + rw [coherent_error_integral] + calc + _≤t^2*∫g,symbol s d e (g+realShift v)^2 ∂GaussianFourier.law κ := + ClassicalGaussian.integral_phaseError_le (GaussianFourier.law κ) + (memLp_symbol_translate s d e (realShift v)) t + _≤_ := by + have h := mul_le_mul_of_nonneg_left + (translated_symbol_second_moment_le s d e ho he (realShift v)) (sq_nonneg t) + simpa only [mul_assoc] using h + +end GaussianCoherent.Quadratic + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ScaledTimeMem.lean b/lean/OAI/Probability/ParisiFinite/ScaledTimeMem.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea6c8f71a98d0183062019bb1509caf0594afd81 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ScaledTimeMem.lean @@ -0,0 +1,688 @@ +import Mathlib +import OAI.Probability.ParisiFinite.GlobalDyadicFieldError + +namespace OAI + +/-! Scaled Time Mem. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath +variable {K M : ℝ≥0} + +lemma scaledTime_mem (c : ℝ≥0) (hc : c≤1) {t : ℝ} (ht : t∈Icc (0:ℝ) 1) : + (c:ℝ)*t∈Icc (0:ℝ) 1 := by + refine ⟨mul_nonneg c.coe_nonneg ht.1,?_⟩ + exact (mul_le_mul_of_nonneg_left ht.2 c.coe_nonneg).trans (by simpa only [mul_one,NNReal.coe_one] using (NNReal.coe_le_coe.mpr hc)) + +def rescalePath (c : ℝ≥0) (hc : c≤1) (X : Path) : Path where + toFun t := (Real.sqrt c)⁻¹*X ⟨(c:ℝ)*t,scaledTime_mem c hc t.property⟩ + continuous_toFun := continuous_const.mul (X.continuous.comp + ((continuous_const.mul continuous_subtype_val).subtype_mk _)) + +lemma extend_rescalePath (c : ℝ≥0) (hc : c≤1) (X : Path) {t : ℝ} + (ht : t∈Icc (0:ℝ) 1) : + extend (rescalePath c hc X) t=(Real.sqrt c)⁻¹*extend X ((c:ℝ)*t) := by + rw [extend_of_mem _ ht,extend_of_mem _ (scaledTime_mem c hc ht)] + rfl + +def Drift.rescale (b : Drift K M) (c : ℝ≥0) : Drift (c*K) (NNReal.sqrt c*M) where + val := fun t x => Real.sqrt c*b.val ((c:ℝ)*t) (Real.sqrt c*x) + measurable := measurable_const.mul (b.measurable.comp + ((measurable_const.mul measurable_fst).prodMk (measurable_const.mul measurable_snd))) + bound := fun t x => by + rw [norm_mul,Real.norm_of_nonneg (Real.sqrt_nonneg _)] + simpa only [NNReal.coe_mul,Real.coe_sqrt] using + mul_le_mul_of_nonneg_left (b.bound _ _) (Real.sqrt_nonneg c) + lipschitz := fun t => LipschitzWith.of_dist_le_mul fun x y => by + simp only [Real.dist_eq,←mul_sub,abs_mul,abs_of_nonneg (Real.sqrt_nonneg _),NNReal.coe_mul] + calc + _ ≤ Real.sqrt c*((K:ℝ)*|Real.sqrt c*x-Real.sqrt c*y|) := + mul_le_mul_of_nonneg_left ((b.lipschitz _).dist_le_mul _ _) (Real.sqrt_nonneg c) + _ = _ := by + rw [←mul_sub,abs_mul,abs_of_nonneg (Real.sqrt_nonneg _)] + calc + _ = (Real.sqrt c*Real.sqrt c)*K*|x-y| := by ring + _ = _ := by rw [Real.mul_self_sqrt c.coe_nonneg] + +lemma solution_rescale (b : Drift K M) (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) (W : Path) : + rescalePath c hc (solution b W)=solution (b.rescale c) (rescalePath c hc W) := by + have cr : (c:ℝ)≠0 := by exact_mod_cast hc0 + have sr : Real.sqrt c≠0 := (Real.sqrt_pos.2 (by exact_mod_cast (pos_iff_ne_zero.2 hc0))).ne' + have hs : Real.sqrt c*Real.sqrt c=(c:ℝ) := Real.mul_self_sqrt c.coe_nonneg + apply solution_unique + intro t + change (Real.sqrt c)⁻¹*solution b W ⟨(c:ℝ)*t,scaledTime_mem c hc t.property⟩= + (Real.sqrt c)⁻¹*W ⟨(c:ℝ)*t,scaledTime_mem c hc t.property⟩+ + ∫ u in (0:ℝ)..(t:ℝ), Real.sqrt c*b.val ((c:ℝ)*u) + (Real.sqrt c*extend (rescalePath c hc (solution b W)) u) + rw [solution_eq,mul_add] + congr 1 + have he : (∫ u in (0:ℝ)..(t:ℝ),Real.sqrt c*b.val ((c:ℝ)*u) + (Real.sqrt c*extend (rescalePath c hc (solution b W)) u))= + ∫ u in (0:ℝ)..(t:ℝ),Real.sqrt c*b.val ((c:ℝ)*u) + (extend (solution b W) ((c:ℝ)*u)) := by + apply intervalIntegral.integral_congr_Ioo_of_le t.property.1 + intro u hu + dsimp only + rw [extend_rescalePath c hc _ ⟨hu.1.le,hu.2.le.trans t.property.2⟩, + ←mul_assoc,mul_inv_cancel₀ sr,one_mul] + rw [he,intervalIntegral.integral_const_mul,intervalIntegral.integral_comp_mul_left (fun u => b.val u (extend (solution b W) u)) cr,mul_zero, + smul_eq_mul] + have hr : (Real.sqrt c)⁻¹=Real.sqrt c*(c:ℝ)⁻¹ := by + field_simp + nlinarith [Real.sq_sqrt c.coe_nonneg] + rw [hr] + ring + +lemma Drift.rescale_joint (b : Drift K M) (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) + (hb : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry (b.rescale c).val) (t,x) := by + have cr : (c:ℝ)≠0 := by exact_mod_cast hc0 + have hh := (volume.quasiMeasurePreserving_smul cr).ae hb + filter_upwards [hh] with t ht hmem x + have hh : ContinuousAt (fun p : ℝ×ℝ => b.val ((c:ℝ)*p.1) (Real.sqrt c*p.2)) (t,x) := + ContinuousAt.comp (g := uncurry b.val) + (f := fun p : ℝ×ℝ => ((c:ℝ)*p.1,Real.sqrt c*p.2)) + (ht (scaledTime_mem c hc hmem) (Real.sqrt c*x)) + (by fun_prop) + exact continuousAt_const.mul hh + +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma brownianPath_rescale (hW : IsBrownianReal W P) (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) : + ∀ᵐ ω ∂P,rescalePath c hc (brownianPath W ω)= + brownianPath (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) ω := by + filter_upwards [brownianPath_eq_ae hW,brownianPath_eq_ae (hW.smul hc0)] with ω hω hω' + ext t + change (Real.sqrt c)⁻¹*brownianPath W ω ⟨(c:ℝ)*t,scaledTime_mem c hc t.property⟩=_ + rw [hω,hω'] + rfl + +lemma brownian_solution_rescale (hW : IsBrownianReal W P) (b : Drift K M) + (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) : + ∀ᵐ ω ∂P,∀ t : Time, + solution (b.rescale c) (brownianPath (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) ω) t= + (Real.sqrt c)⁻¹*solution b (brownianPath W ω) ⟨(c:ℝ)*t,scaledTime_mem c hc t.property⟩ := by + filter_upwards [brownianPath_rescale hW c hc0 hc] with ω hω t + rw [←hω,←solution_rescale b c hc0 hc] + rfl + +end ParisiPath + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath + +namespace TimeQuadraticTest + +def rescale (f : TimeQuadraticTest) (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) : TimeQuadraticTest where + val := fun t x => f.val ((c:ℝ)*t) (Real.sqrt c*x) + d1 := fun t x => Real.sqrt c*f.d1 ((c:ℝ)*t) (Real.sqrt c*x) + d2 := fun t x => (c:ℝ)*f.d2 ((c:ℝ)*t) (Real.sqrt c*x) + dt := fun t x => (c:ℝ)*f.dt ((c:ℝ)*t) (Real.sqrt c*x) + hasD1 := fun t x => by + convert (f.hasD1 ((c:ℝ)*t) (Real.sqrt c*x)).comp x + ((hasDerivAt_id x).const_mul (Real.sqrt c)) using 1 <;> first | rfl | ring + hasD2 := fun t x => by + convert! ((f.hasD2 ((c:ℝ)*t) (Real.sqrt c*x)).comp x + ((hasDerivAt_id x).const_mul (Real.sqrt c))).const_mul (Real.sqrt c) using 1 + calc + _ = (Real.sqrt c*Real.sqrt c)*f.d2 ((c:ℝ)*t) (Real.sqrt c*x) := by + rw [Real.mul_self_sqrt c.coe_nonneg] + _ = _ := by ring + continuousD2 := fun t => continuous_const.mul + ((f.continuousD2 _).comp (continuous_const.mul continuous_id)) + c1 := NNReal.sqrt c*f.c1 + c2 := c*f.c2 + ct := c*f.ct + bound1 := fun t x => by + rw [norm_mul,Real.norm_of_nonneg (Real.sqrt_nonneg _)] + simpa only [NNReal.coe_mul,Real.coe_sqrt] using + mul_le_mul_of_nonneg_left (f.bound1 ((c:ℝ)*t) (Real.sqrt c*x)) (Real.sqrt_nonneg c) + bound2 := fun t x => by + rw [norm_mul,Real.norm_of_nonneg c.coe_nonneg] + exact mul_le_mul_of_nonneg_left (f.bound2 _ _) c.coe_nonneg + boundT := fun t x => by + rw [norm_mul,Real.norm_of_nonneg c.coe_nonneg] + exact mul_le_mul_of_nonneg_left (f.boundT _ _) c.coe_nonneg + measT := measurable_const.mul (f.measT.comp + ((measurable_const.mul measurable_fst).prodMk (measurable_const.mul measurable_snd))) + continuousT := fun t => continuous_const.mul + ((f.continuousT _).comp (continuous_const.mul continuous_id)) + jointD1 := by + have cr : (c:ℝ)≠0 := by exact_mod_cast hc0 + filter_upwards [(volume.quasiMeasurePreserving_smul cr).ae f.jointD1] with t ht hmem x + have hh : ContinuousAt (fun p : ℝ×ℝ => f.d1 ((c:ℝ)*p.1) (Real.sqrt c*p.2)) (t,x) := + ContinuousAt.comp (g := uncurry f.d1) + (f := fun p : ℝ×ℝ => ((c:ℝ)*p.1,Real.sqrt c*p.2)) + (ht (scaledTime_mem c hc hmem) (Real.sqrt c*x)) (by fun_prop) + exact continuousAt_const.mul hh + jointD2 := by + have cr : (c:ℝ)≠0 := by exact_mod_cast hc0 + filter_upwards [(volume.quasiMeasurePreserving_smul cr).ae f.jointD2] with t ht hmem x + have hh : ContinuousAt (fun p : ℝ×ℝ => f.d2 ((c:ℝ)*p.1) (Real.sqrt c*p.2)) (t,x) := + ContinuousAt.comp (g := uncurry f.d2) + (f := fun p : ℝ×ℝ => ((c:ℝ)*p.1,Real.sqrt c*p.2)) + (ht (scaledTime_mem c hc hmem) (Real.sqrt c*x)) (by fun_prop) + exact continuousAt_const.mul hh + integralT := fun a ha b hb x => by + rw [f.integralT _ (scaledTime_mem c hc ha) _ (scaledTime_mem c hc hb), + intervalIntegral.integral_const_mul] + exact (intervalIntegral.smul_integral_comp_mul_left (fun t => f.dt t (Real.sqrt c*x)) (c:ℝ)).symm + +end TimeQuadraticTest + +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma brownian_solution_rescale_extend (hW : IsBrownianReal W P) (b : Drift K M) + (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) : + ∀ᵐ ω ∂P,∀ t∈Icc (0:ℝ) 1, + Real.sqrt c*extend (solution (b.rescale c) + (brownianPath (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) ω)) t= + extend (solution b (brownianPath W ω)) ((c:ℝ)*t) := by + have sr : Real.sqrt c≠0 := (Real.sqrt_pos.2 (by exact_mod_cast (pos_iff_ne_zero.2 hc0))).ne' + filter_upwards [brownian_solution_rescale hW b c hc0 hc] with ω hω t ht + rw [extend_of_mem _ ht,hω,extend_of_mem _ (scaledTime_mem c hc ht), + ←mul_assoc,mul_inv_cancel₀ sr,one_mul] + +lemma timeGeneratorC2_rescale (hW : IsBrownianReal W P) (b : Drift K M) (f : TimeQuadraticTest) + (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) {t : ℝ} (ht : t∈Icc (0:ℝ) 1) : + timeGeneratorC2 P (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) + (b.rescale c) (f.rescale c hc0 hc) t=(c:ℝ)*timeGeneratorC2 P W b f ((c:ℝ)*t) := by + unfold timeGeneratorC2 expectedGeneratorC2 generatorC2 + rw [←MeasureTheory.integral_const_mul] + apply integral_congr_ae + filter_upwards [brownian_solution_rescale_extend hW b c hc0 hc] with ω hω + let x := extend (solution b (brownianPath W ω)) ((c:ℝ)*t) + let y := extend (solution (b.rescale c) + (brownianPath (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) ω)) t + have hy : Real.sqrt c*y=x := hω t ht + change Real.sqrt c*f.d1 ((c:ℝ)*t) (Real.sqrt c*y)* + (Real.sqrt c*b.val ((c:ℝ)*t) (Real.sqrt c*y))+ + 1/2*((c:ℝ)*f.d2 ((c:ℝ)*t) (Real.sqrt c*y))= + (c:ℝ)*(f.d1 ((c:ℝ)*t) x*b.val ((c:ℝ)*t) x+1/2*f.d2 ((c:ℝ)*t) x) + rw [hy] + have hs := Real.mul_self_sqrt c.coe_nonneg + calc + _ = (Real.sqrt c*Real.sqrt c)*(f.d1 ((c:ℝ)*t) x*b.val ((c:ℝ)*t) x)+ + (c:ℝ)*(1/2*f.d2 ((c:ℝ)*t) x) := by ring + _ = _ := by rw [hs]; ring + +lemma timeDerivativeC2_rescale (hW : IsBrownianReal W P) (b : Drift K M) (f : TimeQuadraticTest) + (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) {t : ℝ} (ht : t∈Icc (0:ℝ) 1) : + timeDerivativeC2 P (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) + (b.rescale c) (f.rescale c hc0 hc) t=(c:ℝ)*timeDerivativeC2 P W b f ((c:ℝ)*t) := by + unfold timeDerivativeC2 + rw [←MeasureTheory.integral_const_mul] + apply integral_congr_ae + filter_upwards [brownian_solution_rescale_extend hW b c hc0 hc] with ω hω + dsimp only [TimeQuadraticTest.rescale] + rw [hω t ht] + + +theorem brownian_solution_time_generator_at (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) (c : ℝ≥0) (hc0 : c≠0) (hc : c≤1) + (hb : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + (∫ ω,f.val c (solution b (brownianPath W ω) ⟨c,by exact ⟨c.coe_nonneg,by exact_mod_cast hc⟩⟩) ∂P)-f.val 0 0= + (∫ t in (0:ℝ)..(c:ℝ),timeGeneratorC2 P W b f t)+ + (∫ t in (0:ℝ)..(c:ℝ),timeDerivativeC2 P W b f t) := by + have hid := brownian_solution_time_generator_identity_C2 (hW.smul hc0) + (b.rescale c) (f.rescale c hc0 hc) (b.rescale_joint c hc0 hc hb) + have hterm : (∫ ω,(f.rescale c hc0 hc).val 1 + (solution (b.rescale c) (brownianPath (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) ω) ⟨1,by simp⟩) ∂P)= + ∫ ω,f.val c (solution b (brownianPath W ω) ⟨c,by exact ⟨c.coe_nonneg,by exact_mod_cast hc⟩⟩) ∂P := by + apply integral_congr_ae + filter_upwards [brownian_solution_rescale_extend hW b c hc0 hc] with ω hω + have he := hω 1 ⟨zero_le_one,le_rfl⟩ + rw [extend_of_mem _ ⟨zero_le_one,le_rfl⟩,mul_one,extend_of_mem _ + ⟨c.coe_nonneg,by exact_mod_cast hc⟩] at he + dsimp only [TimeQuadraticTest.rescale] + rw [mul_one,he] + have hgen : (∫ t in (0:ℝ)..1,timeGeneratorC2 P (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) + (b.rescale c) (f.rescale c hc0 hc) t)=∫ t in (0:ℝ)..(c:ℝ),timeGeneratorC2 P W b f t := by + calc + _ = ∫ t in (0:ℝ)..1,(c:ℝ)*timeGeneratorC2 P W b f ((c:ℝ)*t) := + intervalIntegral.integral_congr_Ioo_of_le zero_le_one fun t ht => + timeGeneratorC2_rescale hW b f c hc0 hc ⟨ht.1.le,ht.2.le⟩ + _ = _ := by + rw [intervalIntegral.integral_const_mul] + simpa only [smul_eq_mul,mul_zero,mul_one] using + intervalIntegral.smul_integral_comp_mul_left (timeGeneratorC2 P W b f) (a := 0) (b := 1) (c:ℝ) + have hdt : (∫ t in (0:ℝ)..1,timeDerivativeC2 P (fun t ω => (Real.sqrt c)⁻¹*W (c*t) ω) + (b.rescale c) (f.rescale c hc0 hc) t)=∫ t in (0:ℝ)..(c:ℝ),timeDerivativeC2 P W b f t := by + calc + _ = ∫ t in (0:ℝ)..1,(c:ℝ)*timeDerivativeC2 P W b f ((c:ℝ)*t) := + intervalIntegral.integral_congr_Ioo_of_le zero_le_one fun t ht => + timeDerivativeC2_rescale hW b f c hc0 hc ⟨ht.1.le,ht.2.le⟩ + _ = _ := by + rw [intervalIntegral.integral_const_mul] + simpa only [smul_eq_mul,mul_zero,mul_one] using + intervalIntegral.smul_integral_comp_mul_left (timeDerivativeC2 P W b f) (a := 0) (b := 1) (c:ℝ) + rw [hterm,hgen,hdt] at hid + simpa only [TimeQuadraticTest.rescale,mul_zero] using hid + +end ParisiPath + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def finiteSquareKernel (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (b : Drift K M) + (t x : ℝ) : ℝ := + ((finiteTimeField β hβ ls 0 t).d2 x)^2+ + 2*(finiteTimeField β hβ ls 0 t).d1 x*(finiteTimeField β hβ ls 0 t).d2 x* + (b.val t x-finiteTimeCoefficient ls 0 t*(finiteTimeField β hβ ls 0 t).d1 x) + +lemma finiteSquareKernel_bound (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (ha : ∀ l∈ls,l.1≤β) (b : Drift K M) (t x : ℝ) : + ‖finiteSquareKernel β hβ ls b t x‖≤(β:ℝ)^2+2*(β:ℝ)*((M:ℝ)+(β:ℝ)) := by + have hm : |(finiteTimeField β hβ ls 0 t).d1 x|≤1 := by + simpa only [(finiteTimeField_curvature β hβ ls ha 0 t).1,NNReal.coe_one] using + (finiteTimeField β hβ ls 0 t).normD1 x + have ha' := curvature_abs_d2 (finiteTimeField_curvature β hβ ls ha 0 t) x + have hc := finiteTimeCoefficient_bound β ls ha 0 t + have hbm : |b.val t x|≤(M:ℝ) := by simpa only [Real.norm_eq_abs] using b.bound t x + have he : |b.val t x-finiteTimeCoefficient ls 0 t*(finiteTimeField β hβ ls 0 t).d1 x|≤(M:ℝ)+(β:ℝ) := by + apply (abs_sub _ _).trans + rw [abs_mul] + exact add_le_add hbm ((mul_le_mul hc hm (abs_nonneg _) β.coe_nonneg).trans_eq (mul_one _)) + rw [finiteSquareKernel,Real.norm_eq_abs] + apply (abs_add_le _ _).trans + simp only [abs_pow,abs_mul,abs_of_pos (by norm_num : (0:ℝ)<2)] + calc + _ ≤ (β:ℝ)^2+2*1*(β:ℝ)*((M:ℝ)+(β:ℝ)) := by gcongr + _ = _ := by ring + +lemma finiteSquareKernel_integrable (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) + (b : Drift K M) (t : ℝ) : + Integrable (fun ω => finiteSquareKernel β hβ ls b t + (extend (solution b (brownianPath W ω)) t)) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + refine Integrable.of_bound (C := (β:ℝ)^2+2*(β:ℝ)*((M:ℝ)+(β:ℝ))) ?_ ?_ + · have hx := aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t) + have h1 := (finiteTimeField β hβ ls 0 t).continuousD1 + have h2 := (finiteTimeField β hβ ls 0 t).continuousD2 + have hc : Continuous (finiteSquareKernel β hβ ls b t) := by + unfold finiteSquareKernel + exact (h2.pow 2).add (((continuous_const.mul h1).mul h2).mul + ((b.lipschitz t).continuous.sub (continuous_const.mul h1))) + exact hc.measurable.comp_aemeasurable hx |>.aestronglyMeasurable + · exact ae_of_all _ fun ω => finiteSquareKernel_bound β hβ ls ha b t _ + +lemma expected_finiteSquareKernel_eq (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) (b : Drift K M) + (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) : + (∫ ω,finiteSquareKernel β hβ ls b t (extend (solution b (brownianPath W ω)) t) ∂P)= + timeGeneratorC2 P W b (scheduleGradientSquare β hβ ls 0 le_rfl (by rw [hw];norm_num)).test t+ + timeDerivativeC2 P W b (scheduleGradientSquare β hβ ls 0 le_rfl (by rw [hw];norm_num)).test t := by + let r := scheduleGradientSquare β hβ ls 0 le_rfl (by rw [hw];norm_num) + change _=(∫ ω,generatorC2 (r.test.slice t) b t (extend (solution b (brownianPath W ω)) t) ∂P)+ + (∫ ω,r.test.dt t (extend (solution b (brownianPath W ω)) t) ∂P) + rw [←integral_add (generatorC2_integrable hW b _ t) (timeDerivativeC2_integrable_inner hW b r.test t)] + apply integral_congr_ae + filter_upwards [] with ω + have hh := r.cancel t ht.1.le (by simpa only [hw,zero_add] using ht.2) + (extend (solution b (brownianPath W ω)) t) (b.val t (extend (solution b (brownianPath W ω)) t)) + dsimp only [generatorC2,TimeQuadraticTest.slice,finiteSquareKernel] + linarith + +lemma expected_finiteSquareKernel_aestronglyMeasurable (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (fun t => ∫ ω,finiteSquareKernel β hβ ls b t + (extend (solution b (brownianPath W ω)) t) ∂P) (volume.restrict (Ioc (0:ℝ) 1)) := by + let r := scheduleGradientSquare β hβ ls 0 le_rfl (by rw [hw];norm_num) + have hj := timeGeneratorC2_intervalIntegrable hW b r.test hc + have ht := timeDerivativeC2_intervalIntegrable hW b r.test hc + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] at hj ht + apply (hj.aestronglyMeasurable.add ht.aestronglyMeasurable).congr + have hnot : ∀ᵐ t ∂volume,t≠(1:ℝ) := by simp [ae_iff,measure_singleton] + filter_upwards [ae_restrict_mem measurableSet_Ioc,ae_restrict_of_ae hnot] with t hmem hn + exact (expected_finiteSquareKernel_eq hW β hβ ls hw b t ⟨hmem.1,hmem.2.lt_of_ne hn⟩).symm + +lemma expected_finiteSquareKernel_bound (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) (b : Drift K M) (t : ℝ) : + ‖∫ ω,finiteSquareKernel β hβ ls b t (extend (solution b (brownianPath W ω)) t) ∂P‖≤ + (β:ℝ)^2+2*(β:ℝ)*((M:ℝ)+(β:ℝ)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (μ:=P) (ae_of_all P fun ω => + finiteSquareKernel_bound β hβ ls ha b t _)).trans_eq (by simp) + + +theorem finite_schedule_square_verification (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) + (c : ℝ≥0) (hc0 : c≠0) (hc1 : c≤1) : + (∫ ω,((finiteTimeField β hβ ls 0 c).d1 + (solution b (brownianPath W ω) ⟨c,by exact ⟨c.coe_nonneg,by exact_mod_cast hc1⟩⟩))^2 ∂P)- + ((smoothRecursion β hβ ls).d1 0)^2= + ∫ t in (0:ℝ)..(c:ℝ),∫ ω,finiteSquareKernel β hβ ls b t + (extend (solution b (brownianPath W ω)) t) ∂P := by + let r := scheduleGradientSquare β hβ ls 0 le_rfl (by rw [hw];norm_num) + have hh := brownian_solution_time_generator_at hW b r.test c hc0 hc1 hc + have hsub : uIcc (0:ℝ) c⊆uIcc (0:ℝ) 1 := by + rw [uIcc_of_le c.coe_nonneg,uIcc_of_le zero_le_one] + exact Icc_subset_Icc le_rfl (by exact_mod_cast hc1) + have hj := (timeGeneratorC2_intervalIntegrable hW b r.test hc).mono_set hsub + have ht := (timeDerivativeC2_intervalIntegrable hW b r.test hc).mono_set hsub + simp_rw [r.val_eq,finiteTimeField_d1_start] at hh + rw [hh,←intervalIntegral.integral_add hj ht] + apply intervalIntegral.integral_congr_Ioo_of_le c.coe_nonneg + intro t ht + exact (expected_finiteSquareKernel_eq hW β hβ ls hw b t + ⟨ht.1,ht.2.trans_le (by exact_mod_cast hc1)⟩).symm + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def squareKernel (β : ℝ≥0) (γ : ℝ≥0 → ℝ≥0) (b : Drift K M) (t x : ℝ) : ℝ := + (fieldCurvature β γ (Real.toNNReal t) x)^2+ + 2*fieldGradient β γ (Real.toNNReal t) x*fieldCurvature β γ (Real.toNNReal t) x* + (b.val t x-(γ (Real.toNNReal t):ℝ)*fieldGradient β γ (Real.toNNReal t) x) + +lemma global_dyadic_squareKernel_tendsto (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (b : Drift K M) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) + (hc : Tendsto (fun n => finiteTimeCoefficient (dyadicSchedule γ false 0 1 n) 0 t) + atTop (𝓝 (γ (Real.toNNReal t):ℝ))) (x : ℝ) : + Tendsto (fun n => finiteSquareKernel β hβ (dyadicSchedule γ false 0 1 n) b t x) + atTop (𝓝 (squareKernel β γ b t x)) := by + have hr : Real.toNNReal t<1 := by + exact_mod_cast (show (Real.toNNReal t:ℝ)<1 by rw [Real.coe_toNNReal _ ht.1.le];exact ht.2) + have hg := (global_dyadic_gradient_tendstoUniformly β hβ hγ hb _ hr).tendsto_at x + have ha := (global_dyadic_curvature_tendstoUniformly β hβ hγ hb _ hr).tendsto_at x + rw [Real.coe_toNNReal _ ht.1.le] at hg ha + exact (ha.pow 2).add (((hg.const_mul 2).mul ha).mul (tendsto_const_nhds.sub (hc.mul hg))) + +lemma expected_global_dyadic_squareKernel_tendsto (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (b : Drift K M) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) + (hc : Tendsto (fun n => finiteTimeCoefficient (dyadicSchedule γ false 0 1 n) 0 t) + atTop (𝓝 (γ (Real.toNNReal t):ℝ))) : + Tendsto (fun n => ∫ ω,finiteSquareKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) atTop + (𝓝 (∫ ω,squareKernel β γ b t (extend (solution b (brownianPath W ω)) t) ∂P)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply tendsto_integral_of_dominated_convergence + (fun _ : Ω => (β:ℝ)^2+2*(β:ℝ)*((M:ℝ)+(β:ℝ))) + (fun n => (finiteSquareKernel_integrable hW β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => + finiteSquareKernel_bound β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t _) + exact ae_of_all _ fun ω => global_dyadic_squareKernel_tendsto β hβ hγ hb b t ht hc _ + +lemma expected_global_dyadic_gradient_square_tendsto (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (b : Drift K M) (c : ℝ≥0) (hc : c<1) : + Tendsto (fun n => ∫ ω,((finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).d1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩))^2 ∂P) atTop + (𝓝 (∫ ω,(fieldGradient β γ c + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩))^2 ∂P)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hx := aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩ + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (1:ℝ)) + · intro n + exact (((finiteTimeField β hβ _ 0 c).continuousD1.measurable.comp_aemeasurable hx).pow_const 2).aestronglyMeasurable + · exact integrable_const _ + · intro n + filter_upwards [] with ω + rw [norm_pow] + have hh := (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).normD1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩) + have hh' : ‖(finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).d1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩)‖≤1 := by + simpa only [(finiteTimeField_curvature β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) 0 c).1,NNReal.coe_one,Real.norm_eq_abs] using hh + simpa only [one_pow] using pow_le_pow_left₀ (norm_nonneg _) hh' 2 + · exact ae_of_all _ fun ω => ((global_dyadic_gradient_tendstoUniformly β hβ hγ hb c hc).tendsto_at _).pow 2 + + + +theorem canonical_square_verification (hW : IsBrownianReal W P) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (c : ℝ≥0) (hc0 : c≠0) (hc1 : c<1) : + (∫ ω,(fieldGradient β γ c + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1.le⟩))^2 ∂P)- + (fieldGradient β γ 0 0)^2= + ∫ t in (0:ℝ)..(c:ℝ),∫ ω,squareKernel β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P := by + have hsub : Ioc (0:ℝ) c⊆Ioc (0:ℝ) 1 := Ioc_subset_Ioc le_rfl (by exact_mod_cast hc1.le) + have hi : Tendsto (fun n => ∫ t in (0:ℝ)..(c:ℝ),∫ ω, + finiteSquareKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) atTop + (𝓝 (∫ t in (0:ℝ)..(c:ℝ),∫ ω,squareKernel β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P)) := by + have hmeas (n : ℕ) : AEStronglyMeasurable + (fun t => ∫ ω,finiteSquareKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) (volume.restrict (uIoc (0:ℝ) c)) := by + rw [uIoc_of_le c.coe_nonneg] + exact (expected_finiteSquareKernel_aestronglyMeasurable hW β hβ _ + (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) b hc).mono_measure + (Measure.restrict_mono_set _ hsub) + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (β:ℝ)^2+2*(β:ℝ)*((M:ℝ)+(β:ℝ))) (Eventually.of_forall hmeas) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => + expected_finiteSquareKernel_bound hW β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t) + intervalIntegrable_const + filter_upwards [global_dyadic_coefficient_tendsto_ae hγ] with t ht hmem + rw [uIoc_of_le c.coe_nonneg] at hmem + have hti : t∈Ioo (0:ℝ) 1 := ⟨hmem.1,hmem.2.trans_lt (by exact_mod_cast hc1)⟩ + exact expected_global_dyadic_squareKernel_tendsto hW β hβ hγ hb b t hti (ht hti) + have h0 : Tendsto (fun n => ((smoothRecursion β hβ (dyadicSchedule γ false 0 1 n)).d1 0)^2) + atTop (𝓝 ((fieldGradient β γ 0 0)^2)) := by + have hh := ((global_dyadic_gradient_tendstoUniformly β hβ hγ hb 0 (by norm_num)).tendsto_at 0).pow 2 + simpa only [NNReal.coe_zero,finiteTimeField_d1_start] using hh + have he : (fun n => (∫ ω,((finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).d1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1.le⟩))^2 ∂P)- + ((smoothRecursion β hβ (dyadicSchedule γ false 0 1 n)).d1 0)^2)= + (fun n => ∫ t in (0:ℝ)..(c:ℝ),∫ ω,finiteSquareKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) := by + funext n + exact finite_schedule_square_verification hW b hc β hβ _ + (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) c hc0 hc1.le + exact tendsto_nhds_unique + ((expected_global_dyadic_gradient_square_tendsto hW β hβ hγ hb b c hc1).sub h0) (he ▸ hi) + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def finiteVerificationKernel (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (b : Drift K M) + (t x : ℝ) : ℝ := + (finiteTimeField β hβ ls 0 t).d1 x*b.val t x- + finiteTimeCoefficient ls 0 t/2*((finiteTimeField β hβ ls 0 t).d1 x)^2 + +def verificationKernel (β : ℝ≥0) (γ : ℝ≥0 → ℝ≥0) (b : Drift K M) + (t x : ℝ) : ℝ := + fieldGradient β γ (Real.toNNReal t) x*b.val t x- + (γ (Real.toNNReal t):ℝ)/2*(fieldGradient β γ (Real.toNNReal t) x)^2 + +lemma finiteVerificationKernel_bound (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (ha : ∀ l∈ls,l.1≤β) (b : Drift K M) (t x : ℝ) : + ‖finiteVerificationKernel β hβ ls b t x‖ ≤ (M:ℝ)+(β:ℝ)/2 := by + have hm : |(finiteTimeField β hβ ls 0 t).d1 x|≤1 := by + simpa only [(finiteTimeField_curvature β hβ ls ha 0 t).1,NNReal.coe_one] using + (finiteTimeField β hβ ls 0 t).normD1 x + have hc := finiteTimeCoefficient_bound β ls ha 0 t + have hbm : |b.val t x|≤(M:ℝ) := by simpa only [Real.norm_eq_abs] using b.bound t x + rw [finiteVerificationKernel,Real.norm_eq_abs] + calc + _ ≤ |(finiteTimeField β hβ ls 0 t).d1 x*b.val t x|+ + |finiteTimeCoefficient ls 0 t/2*((finiteTimeField β hβ ls 0 t).d1 x)^2| := abs_sub _ _ + _ ≤ (M:ℝ)+(β:ℝ)/2 := by + rw [abs_mul,abs_mul,abs_div,abs_of_nonneg (sq_nonneg ((finiteTimeField β hβ ls 0 t).d1 x)),abs_of_pos (by norm_num : (0:ℝ)<2)] + have h1 : |(finiteTimeField β hβ ls 0 t).d1 x| *|b.val t x|≤(M:ℝ) := by + exact (mul_le_mul hm hbm (abs_nonneg _) (by norm_num)).trans_eq (one_mul _) + have hsq : ((finiteTimeField β hβ ls 0 t).d1 x)^2≤1 := by + simpa only [sq_abs, one_pow] using pow_le_pow_left₀ (abs_nonneg _) hm 2 + have h2 : |finiteTimeCoefficient ls 0 t|/2*((finiteTimeField β hβ ls 0 t).d1 x)^2≤(β:ℝ)/2 := + (mul_le_mul (div_le_div_of_nonneg_right hc (by norm_num)) hsq + (sq_nonneg _) (by positivity)).trans_eq (mul_one _) + exact add_le_add h1 h2 + +lemma finiteVerificationKernel_integrable (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) + (b : Drift K M) (t : ℝ) : + Integrable (fun ω => finiteVerificationKernel β hβ ls b t + (extend (solution b (brownianPath W ω)) t)) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply Integrable.of_bound (C := (M:ℝ)+(β:ℝ)/2) + · have hx := aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t) + exact (((finiteTimeField β hβ ls 0 t).continuousD1.mul (b.lipschitz t).continuous).sub + (continuous_const.mul ((finiteTimeField β hβ ls 0 t).continuousD1.pow 2))).measurable.comp_aemeasurable hx + |>.aestronglyMeasurable + · exact ae_of_all _ fun ω => finiteVerificationKernel_bound β hβ ls ha b t _ + +lemma expected_finiteVerificationKernel_eq (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) (b : Drift K M) + (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) : + (∫ ω,finiteVerificationKernel β hβ ls b t (extend (solution b (brownianPath W ω)) t) ∂P)= + timeGeneratorC2 P W b (scheduleTimeRealization β hβ ls 0 le_rfl (by rw [hw];norm_num)).test t+ + timeDerivativeC2 P W b (scheduleTimeRealization β hβ ls 0 le_rfl (by rw [hw];norm_num)).test t := by + let r := scheduleTimeRealization β hβ ls 0 le_rfl (by rw [hw];norm_num) + change _=(∫ ω,generatorC2 (r.test.slice t) b t (extend (solution b (brownianPath W ω)) t) ∂P)+ + (∫ ω,r.test.dt t (extend (solution b (brownianPath W ω)) t) ∂P) + rw [←integral_add (generatorC2_integrable hW b _ t) (timeDerivativeC2_integrable_inner hW b r.test t)] + apply integral_congr_ae + filter_upwards [] with ω + simp only [generatorC2,TimeQuadraticTest.slice,r.d1_eq,r.d2_eq,r.dt_eq,finiteVerificationKernel] + rw [finiteTimeField_PDE β hβ ls 0 t _ ht.1.le (by simpa only [hw,zero_add] using ht.2)] + ring + +lemma expected_finiteVerificationKernel_aestronglyMeasurable (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (fun t => ∫ ω,finiteVerificationKernel β hβ ls b t + (extend (solution b (brownianPath W ω)) t) ∂P) (volume.restrict (Ioc (0:ℝ) 1)) := by + let r := scheduleTimeRealization β hβ ls 0 le_rfl (by rw [hw];norm_num) + have hj := timeGeneratorC2_intervalIntegrable hW b r.test hc + have ht := timeDerivativeC2_intervalIntegrable hW b r.test hc + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] at hj ht + apply (hj.aestronglyMeasurable.add ht.aestronglyMeasurable).congr + have hnot : ∀ᵐ t ∂volume,t≠(1:ℝ) := by simp [ae_iff,measure_singleton] + filter_upwards [ae_restrict_mem measurableSet_Ioc,ae_restrict_of_ae hnot] with t hmem hn + exact (expected_finiteVerificationKernel_eq hW β hβ ls hw b t ⟨hmem.1,hmem.2.lt_of_ne hn⟩).symm + +lemma expected_finiteVerificationKernel_bound (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) (b : Drift K M) (t : ℝ) : + ‖∫ ω,finiteVerificationKernel β hβ ls b t (extend (solution b (brownianPath W ω)) t) ∂P‖ ≤ + (M:ℝ)+(β:ℝ)/2 := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (μ:=P) (ae_of_all P fun ω => + finiteVerificationKernel_bound β hβ ls ha b t (extend (solution b (brownianPath W ω)) t))).trans_eq (by simp) + +lemma global_dyadic_verificationKernel_tendsto (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (b : Drift K M) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) + (hc : Tendsto (fun n => finiteTimeCoefficient (dyadicSchedule γ false 0 1 n) 0 t) + atTop (𝓝 (γ (Real.toNNReal t):ℝ))) (x : ℝ) : + Tendsto (fun n => finiteVerificationKernel β hβ (dyadicSchedule γ false 0 1 n) b t x) + atTop (𝓝 (verificationKernel β γ b t x)) := by + have hr : Real.toNNReal t < 1 := by + exact_mod_cast (show (Real.toNNReal t:ℝ)<1 by rw [Real.coe_toNNReal _ ht.1.le];exact ht.2) + have hg := (global_dyadic_gradient_tendstoUniformly β hβ hγ hb _ hr).tendsto_at x + rw [Real.coe_toNNReal _ ht.1.le] at hg + exact (hg.mul_const (b.val t x)).sub ((hc.div_const 2).mul (hg.pow 2)) + +lemma expected_global_dyadic_verificationKernel_tendsto (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (b : Drift K M) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) + (hc : Tendsto (fun n => finiteTimeCoefficient (dyadicSchedule γ false 0 1 n) 0 t) + atTop (𝓝 (γ (Real.toNNReal t):ℝ))) : + Tendsto (fun n => ∫ ω,finiteVerificationKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) atTop + (𝓝 (∫ ω,verificationKernel β γ b t (extend (solution b (brownianPath W ω)) t) ∂P)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (M:ℝ)+(β:ℝ)/2) + (fun n => (finiteVerificationKernel_integrable hW β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => + finiteVerificationKernel_bound β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t _) + exact ae_of_all _ fun ω => global_dyadic_verificationKernel_tendsto β hβ hγ hb b t ht hc _ + + + +theorem canonical_verification (hW : IsBrownianReal W P) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) : + (∫ ω,terminal β (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)-field β γ 0 0 = + ∫ t in (0:ℝ)..1,∫ ω,verificationKernel β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P := by + have hi : Tendsto (fun n => ∫ t in (0:ℝ)..1,∫ ω, + finiteVerificationKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) atTop + (𝓝 (∫ t in (0:ℝ)..1,∫ ω,verificationKernel β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P)) := by + have hmeas (n : ℕ) : AEStronglyMeasurable + (fun t => ∫ ω,finiteVerificationKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) (volume.restrict (uIoc (0:ℝ) 1)) := by + rw [uIoc_of_le zero_le_one] + exact expected_finiteVerificationKernel_aestronglyMeasurable hW β hβ _ + (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) b hc + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (M:ℝ)+(β:ℝ)/2) (Eventually.of_forall hmeas) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => + expected_finiteVerificationKernel_bound hW β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t) + intervalIntegrable_const + have hn : ∀ᵐ t ∂volume,t≠(1:ℝ) := by simp [ae_iff,measure_singleton] + filter_upwards [global_dyadic_coefficient_tendsto_ae hγ,hn] with t ht hn hmem + rw [uIoc_of_le zero_le_one] at hmem + have hti : t∈Ioo (0:ℝ) 1 := ⟨hmem.1,hmem.2.lt_of_ne hn⟩ + exact expected_global_dyadic_verificationKernel_tendsto hW β hβ hγ hb b t hti (ht hti) + have hf : Tendsto (fun n => recursion β (dyadicSchedule γ false 0 1 n) 0) atTop (𝓝 (field β γ 0 0)) := by + have hh := (global_dyadic_field_tendstoUniformly β hβ hγ hb 0 (by norm_num)).tendsto_at 0 + simpa only [NNReal.coe_zero,finiteTimeField_start] using hh + have he : (fun n => (∫ ω,terminal β (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)- + recursion β (dyadicSchedule γ false 0 1 n) 0)= + (fun n => ∫ t in (0:ℝ)..1,∫ ω,finiteVerificationKernel β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) := by + funext n + exact finite_schedule_verification hW b hc β hβ _ (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) + exact tendsto_nhds_unique (tendsto_const_nhds.sub hf) (he ▸ hi) + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ScheduleWidthNonneg.lean b/lean/OAI/Probability/ParisiFinite/ScheduleWidthNonneg.lean new file mode 100644 index 0000000000000000000000000000000000000000..337a3dea29ea683cecd582e1054fca970aa00c7f --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ScheduleWidthNonneg.lean @@ -0,0 +1,733 @@ +import Mathlib +import OAI.Probability.ParisiFinite.DyadicEvolutionGridBound + +namespace OAI + +/-! Schedule Width Nonneg. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + +lemma schedule_width_nonneg (ls : Schedule) : 0 ≤ width ls := by + induction ls with + | nil => simp [width] + | cons l ls ih => simpa only [width,List.map_cons,List.sum_cons] using add_nonneg l.2.coe_nonneg ih + + + +lemma evolution_lyapunov (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (ha : ∀ l∈ls,l.1 ≤ β) (hd : width ls ≤ 1) (x : ℝ) : + Integrable (fun y : ℝ => 1+y^2) (evolutionKernel β hβ ls x) ∧ + (∫ y,1+y^2 ∂evolutionKernel β hβ ls x) ≤ + Real.exp ((2+2*(β:ℝ)^2)*width ls)*(1+x^2) := by + induction ls generalizing x with + | nil => + constructor + · exact integrable_dirac (by simp) + · simp [evolutionKernel,Kernel.id_apply,width] + | cons l ls ih => + have hw : width (l::ls)=(l.2:ℝ)+width ls := by simp [width] + have hat : ∀ k∈ls,k.1 ≤ β := fun k hk => ha k (List.mem_cons_of_mem _ hk) + have hdt : width ls ≤ 1 := by rw [hw] at hd; linarith [l.2.coe_nonneg] + have hdl : l.2 ≤ 1 := by rw [hw] at hd; exact_mod_cast (by linarith [schedule_width_nonneg ls] : (l.2:ℝ)≤1) + have hlt := smoothRecursion_hasParisiCurvature β hβ ls hat + let K := transitionKernel (smoothRecursion β hβ ls) l.1 (Real.sqrt l.2) + let C := Real.exp ((2+2*(β:ℝ)^2)*width ls) + have hi : Integrable (fun y : ℝ => 1+y^2) (K x) := by + rw [show K x=transitionMeasure (smoothRecursion β hβ ls) l.1 (Real.sqrt l.2) x from transitionKernel_apply _ _ _ x] + exact (integrable_const (1:ℝ)).add (integrable_transition_sq _ _ _ _) + have hmc : StronglyMeasurable (fun y : ℝ => ∫ z,1+z^2 ∂evolutionKernel β hβ ls y) := + (by fun_prop : StronglyMeasurable (fun z : ℝ => 1+z^2)).integral_kernel + have hib : Integrable (fun y : ℝ => ∫ z,1+z^2 ∂evolutionKernel β hβ ls y) (K x) := by + apply (hi.const_mul C).mono' hmc.aestronglyMeasurable + exact ae_of_all _ fun y => by + rw [Real.norm_eq_abs,abs_of_nonneg (integral_nonneg (fun z => by positivity))] + exact (ih hat hdt y).2 + have hI : Integrable (fun y : ℝ => 1+y^2) ((evolutionKernel β hβ ls ∘ₖ K) x) := by + apply (integrable_comp_iff (by fun_prop)).mpr + refine ⟨ae_of_all _ fun y => (ih hat hdt y).1,?_⟩ + have he (y : ℝ) : |1+y^2|=1+y^2 := abs_of_nonneg (by positivity) + simpa only [Real.norm_eq_abs,he] using hib + refine ⟨hI,?_⟩ + change (∫ y,1+y^2 ∂(evolutionKernel β hβ ls ∘ₖ K) x) ≤ _ + rw [Kernel.integral_comp hI] + have hh := integral_mono hib (hi.const_mul C) (fun y => (ih hat hdt y).2) + rw [integral_const_mul] at hh + have hb := transition_lyapunov_bound hlt l.1.coe_nonneg (by exact_mod_cast ha l (List.mem_cons_self)) hdl x + rw [←transitionKernel_apply] at hb + have hfinal := hh.trans (mul_le_mul_of_nonneg_left hb (Real.exp_pos _).le) + have he : C*(Real.exp ((2+2*(β:ℝ)^2)*l.2)*(1+x^2))= + Real.exp ((2+2*(β:ℝ)^2)*width (l::ls))*(1+x^2) := by + dsimp [C] + rw [hw,←mul_assoc,←Real.exp_add] + congr 2 + ring + rw [←he] + exact hfinal + +lemma integrable_smooth_d2 (f : SmoothField) (μ : Measure ℝ) [IsFiniteMeasure μ] : + Integrable f.d2 μ := by + exact (integrable_const (f.bound2:ℝ)).mono' f.continuousD2.aestronglyMeasurable + (ae_of_all _ fun x => f.normD2 x) + + +lemma evolution_terminal_curvature_le (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (x : ℝ) : + (∫ y,(terminalField β hβ).d2 y ∂evolutionKernel β hβ ls x) ≤ + (smoothRecursion β hβ ls).d2 x := by + induction ls generalizing x with + | nil => simp [evolutionKernel,Kernel.id_apply,smoothRecursion] + | cons l ls ih => + let K := transitionKernel (smoothRecursion β hβ ls) l.1 (Real.sqrt l.2) + have hi := integrable_smooth_d2 (terminalField β hβ) ((evolutionKernel β hβ ls ∘ₖ K) x) + change (∫ y,(terminalField β hβ).d2 y ∂(evolutionKernel β hβ ls ∘ₖ K) x) ≤ _ + rw [Kernel.integral_comp hi] + have hh := integral_mono hi.integral_comp (integrable_smooth_d2 (smoothRecursion β hβ ls) (K x)) (fun y => ih y) + have he := transition_integral (smoothRecursion β hβ ls) l.1 (Real.sqrt l.2) x + (smoothRecursion β hβ ls).continuousD2.measurable + rw [←transitionKernel_apply] at he + rw [show (∫ y,(smoothRecursion β hβ ls).d2 y ∂K x)=_ from he] at hh + apply hh.trans + change _ ≤ _+(l.1:ℝ)*_ + apply le_add_of_nonneg_right + apply mul_nonneg l.1.coe_nonneg + exact sub_nonneg.mpr (tiltedMean_variance_nonneg (smoothRecursion β hβ ls).lipschitz + (smoothRecursion β hβ ls).continuousD1 (smoothRecursion β hβ ls).normD1 _ _ _) + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + +lemma terminal_curvature_minorant (β : ℝ≥0) (hβ : 0<β) {R : ℝ} (hR : 0 y^2) μ := by + exact (hI.sub (integrable_const (1:ℝ))).congr (ae_of_all _ fun y => by simp) + have hminor : Integrable (fun y : ℝ => ((β:ℝ)/Real.cosh ((β:ℝ)*R)^2)*(1-y^2/R^2)) μ := + ((integrable_const (1:ℝ)).sub (hsq.div_const (R^2))).const_mul _ + have hle := integral_mono hminor (integrable_smooth_d2 (terminalField β hβ) μ) + (terminal_curvature_minorant β hβ hR) + rw [integral_const_mul,integral_sub (integrable_const (1:ℝ)) (hsq.div_const (R^2)),integral_div, + integral_const,probReal_univ,one_smul] at hle + have hb1 : (∫ y,y^2 ∂μ) ≤ Real.exp (2+2*(β:ℝ)^2)*(1+x^2) := by + have ht : Real.exp ((2+2*(β:ℝ)^2)*width ls) ≤ Real.exp (2+2*(β:ℝ)^2) := + Real.exp_le_exp.mpr (by nlinarith [sq_nonneg (β:ℝ)]) + have hh := hB.trans (mul_le_mul_of_nonneg_right ht (by positivity)) + rw [integral_add (integrable_const (1:ℝ)) hsq,integral_const,probReal_univ,one_smul] at hh + dsimp [μ] + exact le_trans (by linarith : (∫ y,y^2 ∂evolutionKernel β hβ ls x)≤1+(∫ y,y^2 ∂evolutionKernel β hβ ls x)) hh + have hbh : (∫ y,y^2 ∂μ)/R^2 ≤ 1/2 := (div_le_iff₀ (sq_pos_of_pos hR)).mpr (by linarith) + have hc : 0≤(β:ℝ)/Real.cosh ((β:ℝ)*R)^2 := by positivity + have hsmall : (β:ℝ)/(2*Real.cosh ((β:ℝ)*R)^2)≤ + (β:ℝ)/Real.cosh ((β:ℝ)*R)^2*(1-(∫ y,y^2 ∂μ)/R^2) := by + have he : (β:ℝ)/(2*Real.cosh ((β:ℝ)*R)^2)=((β:ℝ)/Real.cosh ((β:ℝ)*R)^2)/2 := by ring + rw [he] + nlinarith [mul_le_mul_of_nonneg_left hbh hc] + exact hsmall.trans (hle.trans (evolution_terminal_curvature_le β hβ ls x)) + + + +def curvatureFloor (β : ℝ≥0) (X : ℝ) : ℝ := + (β:ℝ)/(2*Real.cosh ((β:ℝ)*Real.sqrt (2*Real.exp (2+2*(β:ℝ)^2)*(1+X^2)))^2) + +lemma curvatureFloor_pos (β : ℝ≥0) (hβ : 0<β) (X : ℝ) : 0 f.d1 z-c*z + have hg (z : ℝ) : HasDerivAt g (f.d2 z-c) z := by + convert (f.hasD2 z).sub ((hasDerivAt_id z).const_mul c) using 1 <;> + first | rfl | (simp only [mul_one]) + have hm : MonotoneOn g (Set.Icc (-X) X) := monotoneOn_of_hasDerivWithinAt_nonneg (convex_Icc _ _) + (fun z hz => (hg z).continuousAt.continuousWithinAt) + (fun z hz => (hg z).hasDerivWithinAt) + (fun z hz => by + have hz' : z∈Set.Icc (-X) X := Set.mem_of_mem_of_subset hz interior_subset + have hX : 0≤X := (abs_nonneg x).trans hx + have hsq : z^2≤X^2 := by + have hh := mul_nonneg (sub_nonneg.mpr hz'.2) (by linarith [hz'.1] : 0≤X+z) + nlinarith + exact sub_nonneg.mpr (finite_curvature_floor β hβ ls ha hd hsq)) + have hh := hm (abs_le.mp hx) (abs_le.mp hy) hxy + dsimp [g,c,f] at hh + linarith + +lemma fieldGradient_dyadic_tendsto (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) (x : ℝ) : + Tendsto (fun n => (smoothRecursion β hβ (dyadicSchedule γ false t (1-t) n)).d1 x) + atTop (𝓝 (fieldGradient β γ t x)) := by + obtain ⟨m,hd,_,_,hu⟩ := dyadicEvolution_terminal_gradient β hβ hγ hb t (1-t) + have he : fieldGradient β γ t x=m x := (hd x).deriv + rw [he] + exact hu.tendsto_at x + + + +lemma fieldGradient_floor (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) + {x y X : ℝ} (hx : |x|≤X) (hy : |y|≤X) (hxy : x≤y) : + curvatureFloor β X*(y-x) ≤ fieldGradient β γ t y-fieldGradient β γ t x := by + apply ge_of_tendsto ((fieldGradient_dyadic_tendsto β hβ hγ hb t y).sub + (fieldGradient_dyadic_tendsto β hβ hγ hb t x)) + exact Eventually.of_forall fun n => finite_gradient_floor β hβ _ + (dyadicSchedule_coeff_bound hb false t (1-t) n) + (by rw [dyadicSchedule_width]; exact_mod_cast (tsub_le_self : 1-t≤(1:ℝ≥0))) hx hy hxy + +lemma fieldGradient_strictMono (β : ℝ≥0) (hβ : 0<β) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t ≤ β) (t : ℝ≥0) : + StrictMono (fieldGradient β γ t) := by + intro x y hxy + have hh := fieldGradient_floor β hβ hγ hb t + (show |x|≤|x|+|y| from le_add_of_nonneg_right (abs_nonneg _)) + (show |y|≤|x|+|y| from le_add_of_nonneg_left (abs_nonneg _)) hxy.le + have hp := mul_pos (curvatureFloor_pos β hβ (|x|+|y|)) (sub_pos.mpr hxy) + linarith + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + +lemma integrable_smooth_d1_sq (f : SmoothField) (μ : Measure ℝ) [IsFiniteMeasure μ] : + Integrable (fun y => f.d1 y^2) μ := by + apply (integrable_const ((f.bound1:ℝ)^2)).mono' (by have hh:=f.continuousD1; fun_prop) + exact ae_of_all _ (sq_bound f.normD1) + +lemma smooth_integral_sq_sub (f : SmoothField) (μ : Measure ℝ) [IsProbabilityMeasure μ] (c : ℝ) : + (∫ y,(f.d1 y-c)^2 ∂μ)=(∫ y,f.d1 y^2 ∂μ)-2*c*(∫ y,f.d1 y ∂μ)+c^2 := by + have he : (fun y => (f.d1 y-c)^2)=(fun y => f.d1 y^2-2*c*f.d1 y+c^2) := by + funext y; ring + have hs : Integrable (fun y => f.d1 y^2-2*c*f.d1 y) μ := + (integrable_smooth_d1_sq f μ).sub ((integrable_smooth_d1 f μ).const_mul (2*c)) + rw [he,integral_add hs (integrable_const (c^2)), + integral_sub (integrable_smooth_d1_sq f μ) ((integrable_smooth_d1 f μ).const_mul (2*c)), + integral_const_mul,integral_const,probReal_univ,one_smul] + +lemma integrable_smooth_d1_sq_sub (f : SmoothField) (μ : Measure ℝ) [IsFiniteMeasure μ] (c : ℝ) : + Integrable (fun y => (f.d1 y-c)^2) μ := by + convert ((integrable_smooth_d1_sq f μ).sub ((integrable_smooth_d1 f μ).const_mul (2*c))).add + (integrable_const (c^2)) using 1 + first | rfl | (ext y; simp only [Pi.add_apply,Pi.sub_apply]; ring) + + +lemma transition_gradient_variance (f : SmoothField) (a s x : ℝ) : + (∫ y,(f.d1 y-(f.transform a s).d1 x)^2 ∂transitionMeasure f a s x)= + (∫ y,f.d1 y^2 ∂transitionMeasure f a s x)-((f.transform a s).d1 x)^2 := by + rw [smooth_integral_sq_sub,transition_magnetization] + ring + + + +lemma transition_gradient_variance_le {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {a : ℝ} (ha : 0≤a) (hab : a≤β) (s x : ℝ) : + (∫ y,(f.d1 y-(f.transform a s).d1 x)^2 ∂transitionMeasure f a s x) ≤ + (β:ℝ)^2*(s^2+a*(β:ℝ)*s^4) := by + have hmin : (∫ y,(f.d1 y-(f.transform a s).d1 x)^2 ∂transitionMeasure f a s x) ≤ + (∫ y,(f.d1 y-f.d1 x)^2 ∂transitionMeasure f a s x) := by + rw [transition_gradient_variance,smooth_integral_sq_sub,transition_magnetization] + nlinarith [sq_nonneg (f.d1 x-(f.transform a s).d1 x)] + have hli (y : ℝ) : (f.d1 y-f.d1 x)^2 ≤ (β:ℝ)^2*(y-x)^2 := by + have hh := (curvature_gradient_lipschitz hf).dist_le_mul y x + rw [Real.dist_eq,Real.dist_eq] at hh + have hs := mul_le_mul hh hh (abs_nonneg _) (mul_nonneg β.coe_nonneg (abs_nonneg _)) + nlinarith [sq_abs (f.d1 y-f.d1 x),sq_abs (y-x)] + have hi := integral_mono (integrable_smooth_d1_sq_sub f _ (f.d1 x)) + ((integrable_transition_increment_sq f a s x).const_mul ((β:ℝ)^2)) hli + rw [integral_const_mul] at hi + exact hmin.trans (hi.trans (mul_le_mul_of_nonneg_left + (transition_increment_bounds hf ha hab s x).2.2 (sq_nonneg _))) + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + +lemma transition_d1_sq_le_time {β : ℝ≥0} {f : SmoothField} + (hf : HasParisiCurvature β f) {a : ℝ} (ha : 0≤a) (hab : a≤β) + {d : ℝ≥0} (hd : d≤1) (x : ℝ) : + (∫ y,f.d1 y^2 ∂transitionMeasure f a (Real.sqrt d) x) ≤ + ((f.transform a (Real.sqrt d)).d1 x)^2+(β:ℝ)^2*(1+(β:ℝ)^2)*d := by + have hv := transition_gradient_variance_le hf ha hab (Real.sqrt d) x + rw [transition_gradient_variance,Real.sq_sqrt d.coe_nonneg] at hv + have he : (Real.sqrt (d:ℝ))^4=(d:ℝ)^2 := by + rw [show (Real.sqrt (d:ℝ))^4=((Real.sqrt (d:ℝ))^2)^2 by ring,Real.sq_sqrt d.coe_nonneg] + rw [he] at hv + have hdd : (d:ℝ)^2≤d := by have hh : (d:ℝ)≤1 := hd; nlinarith [d.coe_nonneg] + have hfac : a*(β:ℝ)≤(β:ℝ)^2 := by nlinarith [mul_le_mul_of_nonneg_right hab β.coe_nonneg] + have hp := mul_le_mul hfac hdd (sq_nonneg _) (sq_nonneg (β:ℝ)) + nlinarith [mul_le_mul_of_nonneg_left hp (sq_nonneg (β:ℝ))] + + + +lemma evolution_d1_sq_le_time (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (ha : ∀ l∈ls,l.1≤β) (hd : width ls≤1) (x : ℝ) : + (∫ y,(terminalField β hβ).d1 y^2 ∂evolutionKernel β hβ ls x) ≤ + ((smoothRecursion β hβ ls).d1 x)^2+(β:ℝ)^2*(1+(β:ℝ)^2)*width ls := by + induction ls generalizing x with + | nil => simp [evolutionKernel,Kernel.id_apply,smoothRecursion,width] + | cons l ls ih => + have hw : width (l::ls)=(l.2:ℝ)+width ls := by simp [width] + have hat : ∀ k∈ls,k.1≤β := fun k hk => ha k (List.mem_cons_of_mem _ hk) + have hdt : width ls≤1 := by rw [hw] at hd; linarith [l.2.coe_nonneg] + have hdl : l.2≤1 := by rw [hw] at hd; exact_mod_cast (by linarith [schedule_width_nonneg ls] : (l.2:ℝ)≤1) + let f := smoothRecursion β hβ ls + let K := transitionKernel f l.1 (Real.sqrt l.2) + let C : ℝ := (β:ℝ)^2*(1+(β:ℝ)^2) + have hi : Integrable (fun y => (terminalField β hβ).d1 y^2) + ((evolutionKernel β hβ ls ∘ₖ K) x) := integrable_smooth_d1_sq _ _ + have hib : Integrable (fun y => f.d1 y^2+C*width ls) (K x) := + (integrable_smooth_d1_sq f _).add (integrable_const _) + change (∫ y,(terminalField β hβ).d1 y^2 ∂(evolutionKernel β hβ ls ∘ₖ K) x)≤_ + rw [Kernel.integral_comp hi] + have hh := integral_mono hi.integral_comp hib (fun y => ih hat hdt y) + rw [integral_add (integrable_smooth_d1_sq f _) (integrable_const _),integral_const,probReal_univ,one_smul] at hh + have hs := transition_d1_sq_le_time (smoothRecursion_hasParisiCurvature β hβ ls hat) + l.1.coe_nonneg (by exact_mod_cast ha l (List.mem_cons_self)) hdl x + rw [←transitionKernel_apply] at hs + change (∫ y,f.d1 y^2 ∂K x)≤((smoothRecursion β hβ (l::ls)).d1 x)^2+C*l.2 at hs + rw [hw] + change _≤_+C*((l.2:ℝ)+width ls) + linarith + +lemma evolution_gradient_variance_le (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (ha : ∀ l∈ls,l.1≤β) (hd : width ls≤1) (x : ℝ) : + (∫ y,((terminalField β hβ).d1 y-(smoothRecursion β hβ ls).d1 x)^2 + ∂evolutionKernel β hβ ls x) ≤ (β:ℝ)^2*(1+(β:ℝ)^2)*width ls := by + rw [smooth_integral_sq_sub,evolution_magnetization] + have hh := evolution_d1_sq_le_time β hβ ls ha hd x + nlinarith + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + +lemma terminal_gradient_scaled_deriv (β : ℝ≥0) (hβ : 0<β) (z : ℝ) : + HasDerivAt (fun s : ℝ => (terminalField β hβ).d1 (s*z)) ((β:ℝ)*z) 0 := by + have hh := ((terminalField β hβ).hasD2 (0*z)).comp 0 ((hasDerivAt_id 0).mul_const z) + convert hh using 1 <;> first | rfl | (simp [terminalField]) + +lemma terminal_gradient_ratio_tendsto (β : ℝ≥0) (hβ : 0<β) (z : ℝ) : + Tendsto (fun s : ℝ => (terminalField β hβ).d1 (s*z)/s) (𝓝[>] 0) (𝓝 ((β:ℝ)*z)) := by + have ht := (terminal_gradient_scaled_deriv β hβ z).tendsto_slope_zero_right + simpa only [zero_add,zero_mul,terminalField,Real.tanh_zero,mul_zero,sub_zero,smul_eq_mul, + div_eq_mul_inv,mul_comm] using ht + +lemma terminal_gradient_ratio_bound (β : ℝ≥0) (hβ : 0<β) {s : ℝ} (hs : s≠0) (z : ℝ) : + |(terminalField β hβ).d1 (s*z)/s| ≤ (β:ℝ)*|z| := by + have hh := (curvature_gradient_lipschitz (terminal_hasParisiCurvature β hβ)).norm_sub_le (s*z) 0 + simp only [terminalField,mul_zero,Real.tanh_zero,sub_zero,Real.norm_eq_abs,abs_mul] at hh + rw [abs_div] + apply (div_le_iff₀ (abs_pos.mpr hs)).mpr + change |Real.tanh ((β:ℝ)*(s*z))|≤_ + nlinarith + + + +lemma terminal_magnetization_ratio_second_moment (β : ℝ≥0) (hβ : 0<β) : + Tendsto (fun s : ℝ => ∫ z,((terminalField β hβ).d1 (s*z)/s)^2 ∂gaussianReal 0 1) + (𝓝[>] 0) (𝓝 ((β:ℝ)^2)) := by + have ht := tendsto_integral_filter_of_dominated_convergence + (μ := gaussianReal 0 1) (F := fun s z : ℝ => ((terminalField β hβ).d1 (s*z)/s)^2) + (f := fun z : ℝ => ((β:ℝ)*z)^2) (fun z : ℝ => (β:ℝ)^2*z^2) + (Eventually.of_forall fun s => (((terminalField β hβ).continuousD1.comp + (continuous_const.mul continuous_id)).div_const s |>.pow 2).aestronglyMeasurable) + (by + filter_upwards [self_mem_nhdsWithin] with s (hs : 0 by + have hh := terminal_gradient_ratio_bound β hβ hs.ne' z + have hsq := mul_le_mul hh hh (abs_nonneg _) (by positivity : 0≤(β:ℝ)*|z|) + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + nlinarith [sq_abs ((terminalField β hβ).d1 (s*z)/s),sq_abs z]) + (((memLp_id_gaussianReal (μ:=0) (v:=1) 2).integrable_sq).const_mul ((β:ℝ)^2)) + (ae_of_all _ fun z => (terminal_gradient_ratio_tendsto β hβ z).pow 2) + have he : (∫ z : ℝ,((β:ℝ)*z)^2 ∂gaussianReal 0 1)=(β:ℝ)^2 := by + simp only [mul_pow,integral_const_mul,GaussianConcentration.standard_second_moment,mul_one] + rw [he] at ht + exact ht + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + +def replicaTrial (β : ℝ≥0) (s : ℝ) : ℝ := + step 0 s (terminal β) 0+(β:ℝ)*(1-s^2)^2/4 + +lemma terminal_curvature_identity (β : ℝ≥0) (hβ : 0<β) (x : ℝ) : + (terminalField β hβ).d2 x=(β:ℝ)*(1-(terminalField β hβ).d1 x^2) := by + change (β:ℝ)/Real.cosh ((β:ℝ)*x)^2=(β:ℝ)*(1-Real.tanh ((β:ℝ)*x)^2) + rw [Real.tanh_eq_sinh_div_cosh] + have hc := (Real.cosh_pos ((β:ℝ)*x)).ne' + have hh := Real.cosh_sq_sub_sinh_sq ((β:ℝ)*x) + field_simp + have hmul := congrArg (fun t : ℝ => (β:ℝ)*t) hh + nlinarith [hmul] + +lemma replicaTrial_hasDerivAt (β : ℝ≥0) (hβ : 0<β) (s : ℝ) : + HasDerivAt (replicaTrial β) + ((β:ℝ)*s*(s^2-(∫ z,(terminalField β hβ).d1 (s*z)^2 ∂gaussianReal 0 1))) s := by + have hd := hasDerivAt_step_scale (terminalField β hβ) 0 s 0 + have hI : Integrable (fun z : ℝ => (terminalField β hβ).d1 (s*z)^2) (gaussianReal 0 1) := by + apply (integrable_const (1:ℝ)).mono' + (((terminalField β hβ).continuousD1.comp (continuous_const.mul continuous_id)).pow 2).aestronglyMeasurable + exact ae_of_all _ fun z => by simpa only [terminalField,NNReal.coe_one,one_pow,Real.norm_eq_abs,Pi.pow_apply,Function.comp_apply,Pi.mul_apply,id_eq] using + (sq_bound (terminalField β hβ).normD1 (s*z)) + simp only [zero_mul,add_zero,tiltedMean_zero,zero_add] at hd + have he : (∫ z,(terminalField β hβ).d2 (s*z) ∂gaussianReal 0 1)= + (β:ℝ)*(1-(∫ z,(terminalField β hβ).d1 (s*z)^2 ∂gaussianReal 0 1)) := by + simp_rw [terminal_curvature_identity] + rw [integral_const_mul,integral_sub (integrable_const (1:ℝ)) hI, + integral_const,probReal_univ,one_smul] + rw [he] at hd + have hp := ((((hasDerivAt_id s).pow 2).const_sub 1).pow 2).const_mul (β:ℝ) |>.div_const 4 + convert hd.add hp using 1 <;> first | rfl | (dsimp; ring) + +lemma replicaTrial_zero (β : ℝ≥0) : replicaTrial β 0=Real.log 2/(β:ℝ)+(β:ℝ)/4 := by + simp [replicaTrial,terminal] + +lemma exists_replicaTrial_decrease (β : ℝ≥0) (hb : (1:ℝ)<β) : + ∃ s : ℝ,0 (replicaTrial_hasDerivAt β hβ s).continuousAt)).continuousOn + · intro s hs + rw [interior_Icc] at hs + rw [(replicaTrial_hasDerivAt β hβ s).deriv] + have hratio := hprop (show s∈Set.Ioo 0 u from ⟨hs.1,hs.2.trans hdu⟩) + change 1<(∫ z,((terminalField β hβ).d1 (s*z)/s)^2 ∂gaussianReal 0 1) at hratio + simp only [div_pow,integral_div] at hratio + have hvar : s^2<(∫ z,(terminalField β hβ).d1 (s*z)^2 ∂gaussianReal 0 1) := by + simpa only [one_mul] using (lt_div_iff₀ (sq_pos_of_pos hs.1)).mp hratio + exact mul_neg_of_pos_of_neg (mul_pos hβ hs.1) (sub_neg.mpr hvar) + exact ⟨d,hd,hd1,hanti ⟨le_rfl,hd.le⟩ ⟨hd.le,le_rfl⟩ hd⟩ + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal ProbabilityTheory +namespace ParisiFinite + + + +lemma pressure_lt_annealed (β : ℝ≥0) (hb : (1:ℝ)<β) : + SKQAOA.limitingFreeEnergy β a) t d f x=step a (Real.sqrt d) f x := by + have hlo := le_ciSup (dyadic_low_bddAbove hf (γ:=fun _ => a) monotone_const t d x) 0 + have hup : dyadicEvolution (fun _ => a) t d f x≤ + evolve (dyadicSchedule (fun _ => a) true t d 0) f x := by + apply ciSup_le + intro n + exact (dyadicSchedule_low_le_high hf monotone_const t d n x).trans + (dyadic_high_antitone hf monotone_const t d x (Nat.zero_le n)) + change evolve (dyadicSchedule (fun _ => a) false t d 0) f x≤ + dyadicEvolution (fun _ => a) t d f x at hlo + simpa only [dyadicSchedule,evolve] using le_antisymm hup hlo + +def zeroOrderMeasure : ProbabilityMeasure OrderPoint := + ⟨Measure.dirac ⟨0,by norm_num⟩,inferInstance⟩ + +lemma zeroOrderMeasure_coefficient (β : ℝ≥0) : + measureCoefficient zeroOrderMeasure β=fun _ => β := by + funext s + unfold measureCoefficient zeroOrderMeasure + simp [Measure.real,s.coe_nonneg] + +lemma zeroOrderMeasure_functional (β : ℝ≥0) (hβ : 0<β) : + measureFunctional β zeroOrderMeasure=Real.log 2/(β:ℝ)+(β:ℝ)/4 := by + rw [measureFunctional,zeroOrderMeasure_coefficient] + unfold orderParameterFunctional + rw [dyadicEvolution_constant (terminal_lipschitz (β:=(β:ℝ)) hβ) β 0 1 0] + simp only [Real.sqrt_one,NNReal.coe_one] + rw [step_terminal (β:=(β:ℝ)) hβ] + have hp : coefficientPenalty (fun _ => β) 0 1=(β:ℝ)/4 := by + unfold coefficientPenalty + simpa using constant_coefficient_integral (β:ℝ) 0 1 + rw [hp] + simp only [terminal,mul_zero,Real.cosh_zero,mul_one,one_pow] + ring + + + +lemma zeroOrderMeasure_not_minimizing (β : ℝ≥0) (hb : (1:ℝ)<β) : + ¬IsMinimizingParisiMeasure β zeroOrderMeasure := by + have hβ : 0<β := by exact_mod_cast (lt_trans (by norm_num : (0:ℝ)<1) hb) + obtain ⟨ρ,_,hρ⟩ := exists_minimizing_Parisi_measure hβ + intro hmin + have hh := hmin ρ + rw [hρ,zeroOrderMeasure_functional β hβ] at hh + exact (pressure_lt_annealed β hb).not_ge hh + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + +lemma shift_integrableExpSet {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (s x : ℝ) : integrableExpSet (fun z => f (x+s*z)) (gaussianReal 0 1)=Set.univ := by + ext a + simp only [Set.mem_univ,iff_true] + exact integrable_exp_shift hf a x s + +lemma expMass_hasDerivAt_coefficient {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a s x : ℝ) : HasDerivAt (fun r => expMass r s f x) (expMoment a s f f x) a := by + have hm : a∈interior (integrableExpSet (fun z => f (x+s*z)) (gaussianReal 0 1)) := by + rw [shift_integrableExpSet hf,interior_univ] + trivial + have hd := hasDerivAt_mgf hm + change HasDerivAt (fun r => expMass r s f x) + (∫ z,f (x+s*z)*Real.exp (a*f (x+s*z)) ∂gaussianReal 0 1) a at hd + simpa only [expMoment,mul_comm] using hd + + + +lemma step_hasDerivAt_coefficient {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + {a : ℝ} (ha : a≠0) (s x : ℝ) : + HasDerivAt (fun r => step r s f x) ((tiltedMean a s f f x-step a s f x)/a) a := by + have hd := ((expMass_hasDerivAt_coefficient hf a s x).log (expMass_pos hf a s x).ne').div + (hasDerivAt_id a) ha + have heq : (fun r => step r s f x)=ᶠ[𝓝 a] fun r => Real.log (expMass r s f x)/r := by + filter_upwards [eventually_ne_nhds ha] with r hr + simp only [step,logMean,hr,↓reduceIte,expMass] + rw [heq.hasDerivAt_iff] + convert! hd using 1 + unfold tiltedMean step logMean + rw [ite_eq_right ha] + change (expMoment a s f f x / expMass a s f x-Real.log (expMass a s f x)/a)/a=_ + simp only [id_eq,mul_one] + field_simp + +lemma coefficient_cgf_second_variance {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a s x : ℝ) : + iteratedDeriv 2 (fun r => Real.log (expMass r s f x)) a= + tiltedMean a s f (fun y => f y^2) x-(tiltedMean a s f f x)^2 := by + have hm : a∈interior (integrableExpSet (fun z => f (x+s*z)) (gaussianReal 0 1)) := by + rw [shift_integrableExpSet hf,interior_univ] + trivial + have hh := iteratedDeriv_two_cgf hm + rw [deriv_cgf hm] at hh + change iteratedDeriv 2 (fun r => Real.log (expMass r s f x)) a= + (∫ z,f (x+s*z)^2*Real.exp (a*f (x+s*z)) ∂gaussianReal 0 1)/expMass a s f x- + ((∫ z,f (x+s*z)*Real.exp (a*f (x+s*z)) ∂gaussianReal 0 1)/expMass a s f x)^2 at hh + simpa only [tiltedMean,expMoment,mul_comm] using hh + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + +lemma analytic_dslope_hasDerivAt {g : ℝ → ℝ} {a : ℝ} (hg : AnalyticAt ℝ g a) : + HasDerivAt (dslope g a) (iteratedDeriv 2 g a/2) a := by + obtain ⟨p,hp⟩ := hg + have hd := hp.has_fpower_series_dslope_fslope.hasDerivAt + have he : p.fslope 1 (fun _ => 1)=iteratedDeriv 2 g a/2 := by + change p.fslope.coeff 1=iteratedDeriv 2 g a/2 + rw [FormalMultilinearSeries.coeff_fslope] + obtain ⟨r,hr⟩ := hp + have hh := hr.factorial_smul (1:ℝ) 2 + rw [← iteratedDeriv_eq_iteratedFDeriv] at hh + norm_num at hh + change p.coeff 2=_ + linarith + rwa [he] at hd + +lemma step_eq_cgf_dslope {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (s x : ℝ) : (fun a => step a s f x)=dslope (cgf (fun z => f (x+s*z)) (gaussianReal 0 1)) 0 := by + have hm : (0:ℝ)∈interior (integrableExpSet (fun z => f (x+s*z)) (gaussianReal 0 1)) := by + rw [shift_integrableExpSet hf,interior_univ] + trivial + funext a + by_cases ha : a=0 + · subst a + rw [dslope_same,deriv_cgf_zero hm] + simp [step_mean] + · rw [dslope_of_ne _ ha] + simp [step,logMean,ha,slope,cgf,mgf,div_eq_mul_inv,mul_comm] + + + +lemma step_hasDerivAt_zero_coefficient {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (s x : ℝ) : HasDerivAt (fun a => step a s f x) + (((∫ z,f (x+s*z)^2 ∂gaussianReal 0 1)- + (∫ z,f (x+s*z) ∂gaussianReal 0 1)^2)/2) 0 := by + have hm : (0:ℝ)∈interior (integrableExpSet (fun z => f (x+s*z)) (gaussianReal 0 1)) := by + rw [shift_integrableExpSet hf,interior_univ] + trivial + rw [step_eq_cgf_dslope hf] + have hd := analytic_dslope_hasDerivAt (analyticAt_cgf hm) + have hv := coefficient_cgf_second_variance hf 0 s x + change iteratedDeriv 2 (cgf (fun z => f (x+s*z)) (gaussianReal 0 1)) 0=_ at hv + rw [hv] at hd + simpa only [tiltedMean_zero] using hd + + + +lemma step_analyticAt_coefficient {L : ℝ≥0} {f : ℝ → ℝ} (hf : LipschitzWith L f) + (a s x : ℝ) : AnalyticAt ℝ (fun r => step r s f x) a := by + have hm : a∈interior (integrableExpSet (fun z => f (x+s*z)) (gaussianReal 0 1)) := by + rw [shift_integrableExpSet hf,interior_univ] + trivial + by_cases ha : a=0 + · subst a + rw [step_eq_cgf_dslope hf] + obtain ⟨p,hp⟩ := analyticAt_cgf hm + exact ⟨p.fslope,hp.has_fpower_series_dslope_fslope⟩ + · have hh := (analyticAt_cgf hm).div analyticAt_id ha + apply hh.congr + filter_upwards [eventually_ne_nhds ha] with r hr + simp only [Pi.div_apply,id_eq,cgf,mgf,step,logMean,hr,↓reduceIte] + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SecondCoefficient.lean b/lean/OAI/Probability/ParisiFinite/SecondCoefficient.lean new file mode 100644 index 0000000000000000000000000000000000000000..aab85563b9bb25003042c6de6b06b219acdeea52 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SecondCoefficient.lean @@ -0,0 +1,715 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Joint + +namespace OAI + +/-! Second Coefficient. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +namespace QuantumCLT +open scoped Topology +open Filter + + +def secondCoefficient {ι : Type*} (q : ι → ι → ℂ) : List ι → ℂ + | [] => 0 + | i::l => (2:ℂ)⁻¹*q i i+secondCoefficient q l+(l.map (q i)).sum + +theorem second_matrixElement {ι A : Type*} [NormedRing A] [NormedAlgebra ℂ A] + (l : List ι) (X : ι → A) (φ : A →L[ℂ] ℂ) : + φ (second (l.map X))=secondCoefficient (fun i j => φ (X i*X j)) l := by + induction l with + | nil => simp [second,secondCoefficient] + | cons i l ih => + simp only [List.map_cons,second,secondCoefficient,map_add,map_smul,smul_eq_mul,ih] + congr 1 + · rw [pow_two] + · have hsum : X i*(l.map X).sum=(l.map (fun j => X i*X j)).sum := by + clear ih + induction l with + | nil => simp + | cons j l ih => simp only [List.map_cons,List.sum_cons,mul_add,ih] + rw [hsum,map_list_sum,List.map_map] + rfl + +theorem secondCoefficient_tendsto {ι : Type*} (l : List ι) + (q : ℕ → ι → ι → ℂ) (q₀ : ι → ι → ℂ) + (hq : ∀i ∈ l, ∀j ∈ l, Tendsto (fun n => q n i j) atTop (𝓝 (q₀ i j))) : + Tendsto (fun n => secondCoefficient (q n) l) atTop (𝓝 (secondCoefficient q₀ l)) := by + induction l with + | nil => exact tendsto_const_nhds + | cons i l ih => + apply Tendsto.add + · apply Tendsto.add + · exact (hq i (by simp) i (by simp)).const_mul _ + · exact ih (fun a ha b hb => hq a (by simp [ha]) b (by simp [hb])) + · exact tendsto_list_sum l (fun j hj => hq i (by simp) j (by simp [hj])) + + + +theorem moving_generators_gram_limit + {ι : Type*} (A : ℕ → Type*) [∀n, NormedRing (A n)] [∀n, NormedAlgebra ℂ (A n)] + [∀n, NormOneClass (A n)] [∀n, CompleteSpace (A n)] + (l : List ι) (X : ∀n, ι → A n) (φ : ∀n, A n →L[ℂ] ℂ) + (L K : ℝ) (hL : 0 ≤ L) (hK : 0 ≤ K) + (hX : ∀n i, i ∈ l → ‖X n i‖ ≤ L) (hφ : ∀n, ‖φ n‖ ≤ K) + (h1 : ∀n, φ n 1=1) (hc : ∀n, φ n (l.map (X n)).sum=0) + (q : ι → ι → ℂ) + (hq : ∀i ∈ l, ∀j ∈ l, Tendsto (fun n => φ n (X n i*X n j)) atTop (𝓝 (q i j))) : + Tendsto (fun n : ℕ => (φ n (generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹))^n) + atTop (𝓝 (Complex.exp (secondCoefficient q l))) := by + apply moving_generators_vacuum_limit A l X φ L K hL hK hX hφ h1 hc + simp_rw [second_matrixElement] + exact secondCoefficient_tendsto l _ q hq + + + +theorem scalar_first_limit (g a : ℕ → ℂ) (v : ℂ) + (ha : Tendsto a atTop (𝓝 v)) (C : ℝ) + (hg : ∀n : ℕ, 0 (Real.sqrt (n:ℝ):ℂ)*g n) atTop (𝓝 v) := by + have hs : Tendsto (fun n : ℕ => (Real.sqrt (n:ℝ))⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp (Real.tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop) + have he : Tendsto (fun n : ℕ => (Real.sqrt (n:ℝ):ℂ)*g n-a n) atTop (𝓝 0) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + simp only [sub_zero] + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ + (by simpa using hs.const_mul C) + filter_upwards [Filter.eventually_gt_atTop (0:ℕ)] with n hn + have hnR : 0 < (n:ℝ) := by exact_mod_cast hn + have hsn : Real.sqrt (n:ℝ) ≠ 0 := (Real.sqrt_pos.mpr hnR).ne' + have hsC : (Real.sqrt (n:ℝ):ℂ) ≠ 0 := by exact_mod_cast hsn + calc + _ = ‖(Real.sqrt (n:ℝ):ℂ)*(g n-((Real.sqrt (n:ℝ))⁻¹:ℂ)*a n)‖ := by + congr 1; field_simp + _ = Real.sqrt (n:ℝ)*‖g n-((Real.sqrt (n:ℝ))⁻¹:ℂ)*a n‖ := by + rw [norm_mul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg (Real.sqrt_nonneg _)] + _ ≤ Real.sqrt (n:ℝ)*(C*(n:ℝ)⁻¹) := + mul_le_mul_of_nonneg_left (hg n hn) (Real.sqrt_nonneg _) + _ = C*(Real.sqrt (n:ℝ))⁻¹ := by + nth_rw 2 [←Real.sq_sqrt hnR.le] + field_simp + convert he.add ha using 1 <;> simp + +end QuantumCLT + +namespace QuantumCLT +open scoped Topology +open Filter + +theorem step_tendsto_one (f : ℕ → ℂ) {z : ℂ} + (hf : Tendsto (fun n : ℕ => (n:ℂ)*(f n-1)) atTop (𝓝 z)) : + Tendsto f atTop (𝓝 1) := by + have hi : Tendsto (fun n : ℕ => (n:ℂ)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_nhds_zero_nat + have hh := (hi.mul hf).add_const 1 + simp only [zero_mul,zero_add] at hh + apply hh.congr' + filter_upwards [Filter.eventually_gt_atTop (0:ℕ)] with n hn + have hnC : (n:ℂ) ≠ 0 := by exact_mod_cast hn.ne' + field_simp + ring + + +theorem scalar_power_pred_limit (f b : ℕ → ℂ) (z : ℂ) + (hb : Tendsto b atTop (𝓝 z)) (C : ℝ) (hC : 0 ≤ C) + (hf : ∀ n : ℕ, 0 < n → ‖f n-1-(n:ℂ)⁻¹*b n‖ ≤ C*(Real.sqrt (n:ℝ))⁻¹^3) : + Tendsto (fun n => f n^(n-1)) atTop (𝓝 (Complex.exp z)) := by + have hone := step_tendsto_one f (scalar_scaled_limit f b z hb C hC hf) + have hp := scalar_power_limit f b z hb C hC hf + have hd := hp.div hone one_ne_zero + simp only [div_one] at hd + apply hd.congr' + filter_upwards [hone.eventually_ne one_ne_zero,Filter.eventually_gt_atTop (0:ℕ)] with n hn hnpos + simpa [div_eq_mul_inv] using (pow_sub₀ (f n) hn hnpos).symm + + + +theorem scalar_inserted_limit (f b g a : ℕ → ℂ) (z v : ℂ) + (hb : Tendsto b atTop (𝓝 z)) (ha : Tendsto a atTop (𝓝 v)) + (C D : ℝ) (hC : 0 ≤ C) + (hf : ∀ n : ℕ, 0 < n → ‖f n-1-(n:ℂ)⁻¹*b n‖ ≤ C*(Real.sqrt (n:ℝ))⁻¹^3) + (hg : ∀n : ℕ, 0 (Real.sqrt (n:ℝ):ℂ)*g n*f n^(n-1)) + atTop (𝓝 (v*Complex.exp z)) := + (scalar_first_limit g a v ha D hg).mul (scalar_power_pred_limit f b z hb C hC hf) + +variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] [NormOneClass A] + +omit [NormOneClass A] in + + +theorem JetBound.insertion {L K : ℝ} (hL : 0 ≤ L) (hK : 0 ≤ K) + {f : ℝ → A} {a b : A} (hf : JetBound L f a b) + (ψ : A →L[ℂ] ℂ) (hψ : ‖ψ‖ ≤ K) (h1 : ψ 1=0) + (r : ℝ) (hr : |r| ≤ 1) : + ‖ψ (f r)-(r:ℂ)*ψ a‖ ≤ 2*K*L*|r|^2 := by + have hpow : |r|^3 ≤ |r|^2 := by + nlinarith [sq_nonneg |r|,abs_nonneg r] + have he : ‖f r-1-(r:ℂ) • a‖ ≤ 2*L*|r|^2 := by + calc + _ ≤ ‖f r-1-(r:ℂ) • a-((r:ℂ)^2) • b‖+‖((r:ℂ)^2) • b‖ := norm_le_norm_sub_add _ _ + _ ≤ L*|r|^3+|r|^2*L := by + apply add_le_add (hf.2.2 r hr) + simpa [norm_smul,norm_pow] using mul_le_mul_of_nonneg_left hf.2.1 (sq_nonneg |r|) + _ ≤ 2*L*|r|^2 := by nlinarith [mul_le_mul_of_nonneg_left hpow hL] + calc + _ = ‖ψ (f r-1-(r:ℂ) • a)‖ := by simp [h1] + _ ≤ ‖ψ‖*‖f r-1-(r:ℂ) • a‖ := ψ.le_opNorm _ + _ ≤ K*(2*L*|r|^2) := mul_le_mul hψ he (norm_nonneg _) hK + _ = _ := by ring + +end QuantumCLT + +namespace QuantumCLT +open scoped Topology +open Filter +variable {A : Type*} [NormedRing A] [NormedAlgebra ℂ A] + + +theorem JetBound.vacuum {L K : ℝ} (hK : 0 ≤ K) + {f : ℝ → A} {a b : A} (hf : JetBound L f a b) + (φ : A →L[ℂ] ℂ) (hφ : ‖φ‖ ≤ K) (h1 : φ 1=1) (hc : φ a=0) + (r : ℝ) (hr : |r| ≤ 1) : + ‖φ (f r)-1-(r:ℂ)^2*φ b‖ ≤ K*L*|r|^3 := by + calc + _ = ‖φ (f r-1-(r:ℂ) • a-((r:ℂ)^2) • b)‖ := by simp [h1,hc] + _ ≤ ‖φ‖*‖f r-1-(r:ℂ) • a-((r:ℂ)^2) • b‖ := φ.le_opNorm _ + _ ≤ K*(L*|r|^3) := mul_le_mul hφ (hf.2.2 r hr) (norm_nonneg _) hK + _ = _ := by ring + +theorem sqrt_inverse_bound (n : ℕ) (hn : 0 φ n (second (l.map (X n)))) atTop (𝓝 z)) + (hv : Tendsto (fun n => ψ n (l.map (X n)).sum) atTop (𝓝 v)) : + Tendsto (fun n : ℕ => (Real.sqrt (n:ℝ):ℂ)* + ψ n (generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹)* + (φ n (generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹))^(n-1)) + atTop (𝓝 (v*Complex.exp z)) := by + have hj (n : ℕ) := generators_jetBound (l.map (X n)) hL (by + intro Y hY + obtain ⟨i,hi,rfl⟩ := List.mem_map.mp hY + exact hX n i hi) + simp only [List.length_map] at hj + apply scalar_inserted_limit _ (fun n => φ n (second (l.map (X n)))) _ + (fun n => ψ n (l.map (X n)).sum) z v hz hv + (K*orderedBound L l.length) (2*M*orderedBound L l.length) + (mul_nonneg hK (orderedBound_nonneg hL _)) + · intro n hn + have hh := (hj n).vacuum hK (φ n) (hφ n) (h1 n) (hc n) + (Real.sqrt (n:ℝ))⁻¹ (sqrt_inverse_bound n hn) + simpa only [sqrt_inverse_sq,abs_of_nonneg (by positivity : 0 ≤ (Real.sqrt (n:ℝ))⁻¹)] using hh + · intro n hn + have hh := (hj n).insertion (orderedBound_nonneg hL _) hM (ψ n) (hψ n) (h0 n) + (Real.sqrt (n:ℝ))⁻¹ (sqrt_inverse_bound n hn) + rw [abs_of_nonneg (by positivity),inv_pow,Real.sq_sqrt (by positivity)] at hh + simpa only [Complex.ofReal_inv] using hh + +end QuantumCLT + +namespace QuantumCLT +open scoped InnerProductSpace Topology +open Filter +open CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + + +def weylProduct : List E → (Space E →L[ℂ] Space E) + | [] => ContinuousLinearMap.id ℂ (Space E) + | d::ds => (W d).comp (weylProduct ds) + +theorem secondCoefficient_gram_cons (d : E) (ds : List E) : + secondCoefficient (fun x y : E => -⟪x,y⟫_ℂ) (d::ds)= + (2:ℂ)⁻¹*(-⟪d,d⟫_ℂ)+secondCoefficient (fun x y : E => -⟪x,y⟫_ℂ) ds- + ⟪d,ds.sum⟫_ℂ := by + simp only [secondCoefficient] + suffices (ds.map (fun y => -⟪d,y⟫_ℂ)).sum= -⟪d,ds.sum⟫_ℂ by rw [this]; rfl + induction ds with + | nil => simp + | cons x ds ih => simp [ih,inner_add_right,add_comm] + +theorem gram_exponent (d e : E) (c : ℂ) : + c+Complex.ofReal (‖e‖^2/2)+Complex.ofReal (-(⟪d,e⟫_ℂ).im)*Complex.I = + (2:ℂ)⁻¹*(-⟪d,d⟫_ℂ)+c-⟪d,e⟫_ℂ+Complex.ofReal (‖d+e‖^2/2) := by + rw [inner_self_eq_norm_sq_to_K,norm_add_sq (𝕜 := ℂ)] + apply Complex.ext <;> simp <;> ring + + + +theorem weylProduct_coherent_zero (ds : List E) : + weylProduct ds (coherent (0:E))= + Complex.exp (secondCoefficient (fun x y : E => -⟪x,y⟫_ℂ) ds+ + Complex.ofReal (‖ds.sum‖^2/2)) • coherent ds.sum := by + induction ds with + | nil => simp [weylProduct,secondCoefficient] + | cons d ds ih => + simp only [weylProduct,ContinuousLinearMap.comp_apply,ih,map_smul,W_coherent,smul_smul, + List.sum_cons,secondCoefficient_gram_cons] + unfold phase + rw [←Complex.exp_add,gram_exponent] + +theorem weylProduct_vacuum (ds : List E) : + ⟪coherent (0:E),weylProduct ds (coherent (0:E))⟫_ℂ= + Complex.exp (secondCoefficient (fun x y : E => -⟪x,y⟫_ℂ) ds) := by + rw [weylProduct_coherent_zero,inner_smul_right,inner_coherent] + simp only [kernel,norm_zero,zero_pow (by decide : (2:ℕ) ≠ 0),neg_zero,zero_div, + Complex.ofReal_zero,inner_zero_left,zero_add] + rw [←Complex.exp_add] + congr 1 + push_cast + ring + +theorem secondCoefficient_map {ι : Type*} (l : List ι) (d : ι → E) : + secondCoefficient (fun x y : E => -⟪x,y⟫_ℂ) (l.map d)= + secondCoefficient (fun i j => -⟪d i,d j⟫_ℂ) l := by + induction l with + | nil => rfl + | cons i l ih => simp only [List.map_cons,secondCoefficient,ih,List.map_map]; rfl + + + +theorem moving_generators_weyl_limit + {ι : Type*} (A : ℕ → Type*) [∀n, NormedRing (A n)] [∀n, NormedAlgebra ℂ (A n)] + [∀n, NormOneClass (A n)] [∀n, CompleteSpace (A n)] + (l : List ι) (X : ∀n, ι → A n) (φ : ∀n, A n →L[ℂ] ℂ) (d : ι → E) + (L K : ℝ) (hL : 0 ≤ L) (hK : 0 ≤ K) + (hX : ∀n i, i ∈ l → ‖X n i‖ ≤ L) (hφ : ∀n, ‖φ n‖ ≤ K) + (h1 : ∀n, φ n 1=1) (hc : ∀n, φ n (l.map (X n)).sum=0) + (hq : ∀i ∈ l, ∀j ∈ l, + Tendsto (fun n => φ n (X n i*X n j)) atTop (𝓝 (-⟪d i,d j⟫_ℂ))) : + Tendsto (fun n : ℕ => (φ n (generators (l.map (X n)) (Real.sqrt (n:ℝ))⁻¹))^n) + atTop (𝓝 ⟪coherent (0:E),weylProduct (l.map d) (coherent (0:E))⟫_ℂ) := by + rw [weylProduct_vacuum,secondCoefficient_map] + exact moving_generators_gram_limit A l X φ L K hL hK hX hφ h1 hc _ hq + +end QuantumCLT + +open scoped BigOperators InnerProductSpace +namespace FiniteTensor +open Matrix +variable {ι : Type*} [Fintype ι] + +def power (D : ℕ) (v : EuclideanSpace ℂ ι) : EuclideanSpace ℂ (Fin D → ι) := + WithLp.toLp 2 (fun σ => ∏i, v (σ i)) + +omit [Fintype ι] in +@[simp] theorem power_apply (D : ℕ) (v : EuclideanSpace ℂ ι) (σ : Fin D → ι) : + power D v σ=∏i, v (σ i) := rfl + + + +theorem inner_power (D : ℕ) (v w : EuclideanSpace ℂ ι) : + ⟪power D v,power D w⟫_ℂ=⟪v,w⟫_ℂ^D := by + classical + simp only [PiLp.inner_apply,RCLike.inner_apply] + change (∑σ : Fin D → ι, (∏i, w (σ i))*starRingEnd ℂ (∏i, v (σ i)))= + (∑j, w j*starRingEnd ℂ (v j))^D + simp_rw [map_prod,←Finset.prod_mul_distrib] + rw [←Fintype.prod_sum (fun (_ : Fin D) (j : ι) => w j*starRingEnd ℂ (v j))] + simp + + +def matrixPower (D : ℕ) (M : Matrix ι ι ℂ) : Matrix (Fin D → ι) (Fin D → ι) ℂ := + fun σ τ => ∏i, M (σ i) (τ i) + +theorem matrixPower_mulVec (D : ℕ) (M : Matrix ι ι ℂ) (v : EuclideanSpace ℂ ι) : + matrixPower D M *ᵥ (power D v).ofLp= + (power D (WithLp.toLp 2 (M *ᵥ v.ofLp))).ofLp := by + classical + funext σ + change (∑τ : Fin D → ι, (∏i, M (σ i) (τ i))*(∏i, v (τ i)))= + ∏i, ∑j, M (σ i) j*v j + simp_rw [←Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun i j => M (σ i) j*v j)).symm + +variable [DecidableEq ι] + + +def operatorPower (D : ℕ) (T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + EuclideanSpace ℂ (Fin D → ι) →L[ℂ] EuclideanSpace ℂ (Fin D → ι) := + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin D → ι)) + (matrixPower D ((Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm T)) + +theorem operatorPower_apply (D : ℕ) (T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (v : EuclideanSpace ℂ ι) : operatorPower D T (power D v)=power D (T v) := by + apply WithLp.ofLp_injective + rw [operatorPower,Matrix.ofLp_toEuclideanCLM,matrixPower_mulVec] + congr 2 + have hh := congrArg (fun S : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι => S v) + (Matrix.toEuclideanCLM.apply_symm_apply T) + simpa only [←Matrix.toEuclideanCLM_toLp,WithLp.toLp_ofLp] using hh + + +theorem inner_operatorPower (D : ℕ) (T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (v w : EuclideanSpace ℂ ι) : + ⟪power D v,operatorPower D T (power D w)⟫_ℂ=⟪v,T w⟫_ℂ^D := by + rw [operatorPower_apply,inner_power] + +end FiniteTensor + +namespace QuantumCLT +open scoped InnerProductSpace Topology +open ContinuousLinearMap Filter InnerProductSpace +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + + +def vacuumFunctional (Ω : E) : (E →L[ℂ] E) →L[ℂ] ℂ := + (innerSL ℂ Ω).comp (ContinuousLinearMap.apply ℂ E Ω) + +@[simp] theorem vacuumFunctional_apply (Ω : E) (T : E →L[ℂ] E) : + vacuumFunctional Ω T=⟪Ω,T Ω⟫_ℂ := rfl + +theorem vacuumFunctional_norm (Ω : E) : ‖vacuumFunctional Ω‖ ≤ ‖Ω‖^2 := by + apply ContinuousLinearMap.opNorm_le_bound _ (sq_nonneg _) + intro T + calc + _ ≤ ‖Ω‖*‖T Ω‖ := norm_inner_le_norm _ _ + _ ≤ ‖Ω‖*(‖T‖*‖Ω‖) := mul_le_mul_of_nonneg_left (T.le_opNorm _) (norm_nonneg _) + _ = ‖Ω‖^2*‖T‖ := by ring + +variable [Nontrivial E] + + + +def testGate (Ω x : E) (r : ℝ) : E →L[ℂ] E := + 1+(r:ℂ) • rankOne ℂ x Ω + +omit [Nontrivial E] in +theorem testGate_jetBound (Ω x : E) (hΩ : ‖Ω‖=1) {R : ℝ} (hR : 0 ≤ R) + (hx : ‖x‖ ≤ R) : JetBound R (testGate Ω x) (rankOne ℂ x Ω) 0 := by + refine ⟨by simpa [hΩ] using hx,by simpa using hR,?_⟩ + intro r hr + simp only [testGate,smul_zero,add_sub_cancel_left,sub_self,norm_zero] + positivity + + +def testedGate (Ω x z : E) (f : ℝ → E →L[ℂ] E) (r : ℝ) : E →L[ℂ] E := + testGate z Ω r*f r*testGate Ω x r + +omit [Nontrivial E] in +theorem testedGate_pairing (Ω x z : E) (hΩ : ‖Ω‖=1) + (f : ℝ → E →L[ℂ] E) (r : ℝ) : + vacuumFunctional Ω (testedGate Ω x z f r)= + ⟪Ω+(r:ℂ) • z, f r (Ω+(r:ℂ) • x)⟫_ℂ := by + have hΩi : ⟪Ω,Ω⟫_ℂ=1 := by rw [inner_self_eq_norm_sq_to_K,hΩ]; norm_num + simp only [vacuumFunctional_apply,testedGate,testGate,mul_apply_eq_comp,add_apply,one_apply_eq_self, + smul_apply,rankOne_apply,hΩi,one_smul] + simp only [inner_add_left,inner_add_right,inner_smul_left,inner_smul_right,hΩi, + map_add,map_smul,Complex.conj_ofReal, mul_one] + ring + + +def testedBound (L R : ℝ) : ℝ := + (R+L+8*R*L)+R+8*(R+L+8*R*L)*R + +theorem testedBound_nonneg {L R : ℝ} (hL : 0 ≤ L) (hR : 0 ≤ R) : + 0 ≤ testedBound L R := by unfold testedBound; positivity + +theorem testedGate_jetBound (Ω x z : E) (hΩ : ‖Ω‖=1) + {R L : ℝ} (hR : 0 ≤ R) (hL : 0 ≤ L) (hx : ‖x‖ ≤ R) (hz : ‖z‖ ≤ R) + {f : ℝ → E →L[ℂ] E} {a b : E →L[ℂ] E} (hf : JetBound L f a b) : + JetBound (testedBound L R) (testedGate Ω x z f) + (rankOne ℂ Ω z+a+rankOne ℂ x Ω) + (b+rankOne ℂ Ω z*a+(rankOne ℂ Ω z+a)*rankOne ℂ x Ω) := by + have hzj : JetBound R (testGate z Ω) (rankOne ℂ Ω z) 0 := by + refine ⟨by simpa [hΩ] using hz,by simpa using hR,?_⟩ + intro r hr + simp only [testGate,smul_zero,add_sub_cancel_left,sub_self,norm_zero] + positivity + have hleft := hzj.mul hR hL hf + have hh := hleft.mul (by positivity : 0 ≤ R+L+8*R*L) hR (testGate_jetBound Ω x hΩ hR hx) + have he : testedGate Ω x z f=(fun r => testGate z Ω r*f r*testGate Ω x r) := rfl + rw [he] + simpa only [zero_add,add_zero,testedBound] using hh + +omit [Nontrivial E] in +theorem testedGate_first (Ω x z : E) (hΩ : ‖Ω‖=1) (a : E →L[ℂ] E) + (hx : ⟪Ω,x⟫_ℂ=0) (hz : ⟪z,Ω⟫_ℂ=0) (ha : ⟪Ω,a Ω⟫_ℂ=0) : + vacuumFunctional Ω (rankOne ℂ Ω z+a+rankOne ℂ x Ω)=0 := by + have hΩi : ⟪Ω,Ω⟫_ℂ=1 := by rw [inner_self_eq_norm_sq_to_K,hΩ]; norm_num + simp [vacuumFunctional_apply,hx,hz,ha] + +omit [Nontrivial E] in +theorem testedGate_second (Ω x z : E) (hΩ : ‖Ω‖=1) (a b : E →L[ℂ] E) : + vacuumFunctional Ω (b+rankOne ℂ Ω z*a+(rankOne ℂ Ω z+a)*rankOne ℂ x Ω)= + ⟪Ω,b Ω⟫_ℂ+⟪z,a Ω⟫_ℂ+⟪z,x⟫_ℂ+⟪Ω,a x⟫_ℂ := by + have hΩi : ⟪Ω,Ω⟫_ℂ=1 := by rw [inner_self_eq_norm_sq_to_K,hΩ]; norm_num + simp only [vacuumFunctional_apply,add_apply,mul_apply_eq_comp,rankOne_apply,hΩi,one_smul, + inner_add_right,inner_smul_right,mul_one] + ring + + + +theorem tested_pairing_bound (Ω x z : E) (hΩ : ‖Ω‖=1) + {R L : ℝ} (hR : 0 ≤ R) (hL : 0 ≤ L) (hx : ‖x‖ ≤ R) (hz : ‖z‖ ≤ R) + {f : ℝ → E →L[ℂ] E} {a b : E →L[ℂ] E} (hf : JetBound L f a b) + (hxc : ⟪Ω,x⟫_ℂ=0) (hzc : ⟪z,Ω⟫_ℂ=0) (ha : ⟪Ω,a Ω⟫_ℂ=0) + (r : ℝ) (hr : |r| ≤ 1) : + ‖⟪Ω+(r:ℂ) • z, f r (Ω+(r:ℂ) • x)⟫_ℂ-1- + (r:ℂ)^2*(⟪Ω,b Ω⟫_ℂ+⟪z,a Ω⟫_ℂ+⟪z,x⟫_ℂ+⟪Ω,a x⟫_ℂ)‖ ≤ + testedBound L R*|r|^3 := by + have hj := testedGate_jetBound Ω x z hΩ hR hL hx hz hf + have hc := testedGate_first Ω x z hΩ a hxc hzc ha + have hnorm : ‖vacuumFunctional Ω‖ ≤ 1 := by simpa [hΩ] using vacuumFunctional_norm Ω + have h1 : vacuumFunctional Ω 1=1 := by + change ⟪Ω,Ω⟫_ℂ=1 + rw [inner_self_eq_norm_sq_to_K,hΩ] + norm_num + have hh := hj.vacuum (by norm_num : (0:ℝ) ≤ 1) (vacuumFunctional Ω) hnorm h1 hc r hr + simpa only [testedGate_pairing Ω x z hΩ,testedGate_second Ω x z hΩ,one_mul] using hh + + + +theorem moving_tested_limit + (E : ℕ → Type*) [∀n, NormedAddCommGroup (E n)] [∀n, InnerProductSpace ℂ (E n)] + [∀n, Nontrivial (E n)] + (Ω x z : ∀n, E n) (f : ∀n, ℝ → E n →L[ℂ] E n) (a b : ∀n, E n →L[ℂ] E n) + (R L : ℝ) (hR : 0 ≤ R) (hL : 0 ≤ L) + (hΩ : ∀n, ‖Ω n‖=1) (hx : ∀n, ‖x n‖ ≤ R) (hz : ∀n, ‖z n‖ ≤ R) + (hf : ∀n, JetBound L (f n) (a n) (b n)) + (hxc : ∀n, ⟪Ω n,x n⟫_ℂ=0) (hzc : ∀n, ⟪z n,Ω n⟫_ℂ=0) + (ha : ∀n, ⟪Ω n,a n (Ω n)⟫_ℂ=0) {c : ℂ} + (hc : Tendsto (fun n => ⟪Ω n,b n (Ω n)⟫_ℂ+⟪z n,a n (Ω n)⟫_ℂ+ + ⟪z n,x n⟫_ℂ+⟪Ω n,a n (x n)⟫_ℂ) atTop (𝓝 c)) : + Tendsto (fun n : ℕ => + ⟪Ω n+(((Real.sqrt (n:ℝ))⁻¹:ℝ):ℂ) • z n, + f n (Real.sqrt (n:ℝ))⁻¹ (Ω n+(((Real.sqrt (n:ℝ))⁻¹:ℝ):ℂ) • x n)⟫_ℂ^n) + atTop (𝓝 (Complex.exp c)) := by + apply scalar_power_limit _ _ c hc (testedBound L R) (testedBound_nonneg hL hR) + intro n hn + have hh := tested_pairing_bound (Ω n) (x n) (z n) (hΩ n) hR hL (hx n) (hz n) + (hf n) (hxc n) (hzc n) (ha n) (Real.sqrt (n:ℝ))⁻¹ (sqrt_inverse_bound n hn) + simpa only [sqrt_inverse_sq,abs_of_nonneg (by positivity : 0 ≤ (Real.sqrt (n:ℝ))⁻¹)] using hh + +end QuantumCLT + +namespace FiniteTensor +open scoped InnerProductSpace Topology +open Filter QuantumCLT + + + +def exponentialVector {ι : Type*} [Fintype ι] (D : ℕ) + (Ω x : EuclideanSpace ℂ ι) : EuclideanSpace ℂ (Fin D → ι) := + power D (Ω+(((Real.sqrt (D:ℝ))⁻¹:ℝ):ℂ) • x) + + + +theorem moving_tensor_pairing_limit + (ι : ℕ → Type*) [∀n, Fintype (ι n)] [∀n, DecidableEq (ι n)] [∀n, Nonempty (ι n)] + (Ω x z : ∀n, EuclideanSpace ℂ (ι n)) + (f : ∀n, ℝ → EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + (a b : ∀n, EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n)) + (R L : ℝ) (hR : 0 ≤ R) (hL : 0 ≤ L) + (hΩ : ∀n, ‖Ω n‖=1) (hx : ∀n, ‖x n‖ ≤ R) (hz : ∀n, ‖z n‖ ≤ R) + (hf : ∀n, JetBound L (f n) (a n) (b n)) + (hxc : ∀n, ⟪Ω n,x n⟫_ℂ=0) (hzc : ∀n, ⟪z n,Ω n⟫_ℂ=0) + (ha : ∀n, ⟪Ω n,a n (Ω n)⟫_ℂ=0) {c : ℂ} + (hc : Tendsto (fun n => ⟪Ω n,b n (Ω n)⟫_ℂ+⟪z n,a n (Ω n)⟫_ℂ+ + ⟪z n,x n⟫_ℂ+⟪Ω n,a n (x n)⟫_ℂ) atTop (𝓝 c)) : + Tendsto (fun n => ⟪exponentialVector n (Ω n) (z n), + operatorPower n (f n (Real.sqrt (n:ℝ))⁻¹) (exponentialVector n (Ω n) (x n))⟫_ℂ) + atTop (𝓝 (Complex.exp c)) := by + simpa only [exponentialVector,inner_operatorPower] using + moving_tested_limit (fun n => EuclideanSpace ℂ (ι n)) Ω x z f a b R L hR hL + hΩ hx hz hf hxc hzc ha hc + + + +theorem moving_tensor_gram_limit + (ι : ℕ → Type*) [∀n, Fintype (ι n)] [∀n, DecidableEq (ι n)] [∀n, Nonempty (ι n)] + (Ω x z : ∀n, EuclideanSpace ℂ (ι n)) + (R : ℝ) (hR : 0 ≤ R) (hΩ : ∀n, ‖Ω n‖=1) + (hx : ∀n, ‖x n‖ ≤ R) (hz : ∀n, ‖z n‖ ≤ R) + (hxc : ∀n, ⟪Ω n,x n⟫_ℂ=0) (hzc : ∀n, ⟪z n,Ω n⟫_ℂ=0) {c : ℂ} + (hc : Tendsto (fun n => ⟪z n,x n⟫_ℂ) atTop (𝓝 c)) : + Tendsto (fun n => ⟪exponentialVector n (Ω n) (z n),exponentialVector n (Ω n) (x n)⟫_ℂ) + atTop (𝓝 (Complex.exp c)) := by + have hj (n : ℕ) : JetBound 0 (fun _ : ℝ => (1 : EuclideanSpace ℂ (ι n) →L[ℂ] EuclideanSpace ℂ (ι n))) 0 0 := by + refine ⟨by simp,by simp,?_⟩ + intro r hr + simp + have hh := moving_tensor_pairing_limit ι Ω x z (fun _ _ => 1) (fun _ => 0) (fun _ => 0) + R 0 hR le_rfl hΩ hx hz hj hxc hzc (by intro n; simp) + (by simpa using hc) + simpa [exponentialVector,operatorPower_apply] using hh + +end FiniteTensor + +namespace FiniteTensor +open scoped BigOperators InnerProductSpace +open Matrix ContinuousLinearMap +variable {ι : Type*} [Fintype ι] + + +def mixedPower (D : ℕ) (v : Fin D → EuclideanSpace ℂ ι) : + EuclideanSpace ℂ (Fin D → ι) := WithLp.toLp 2 (fun σ => ∏i, v i (σ i)) + +omit [Fintype ι] in +@[simp] theorem mixedPower_constant (D : ℕ) (v : EuclideanSpace ℂ ι) : + mixedPower D (fun _ => v)=power D v := rfl + +theorem inner_mixedPower (D : ℕ) (v w : Fin D → EuclideanSpace ℂ ι) : + ⟪mixedPower D v,mixedPower D w⟫_ℂ=∏i, ⟪v i,w i⟫_ℂ := by + classical + simp only [PiLp.inner_apply,RCLike.inner_apply] + change (∑σ : Fin D → ι, (∏i, w i (σ i))*starRingEnd ℂ (∏i, v i (σ i)))= + ∏i, ∑j, w i j*starRingEnd ℂ (v i j) + simp_rw [map_prod,←Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun i j => w i j*starRingEnd ℂ (v i j))).symm + +def mixedMatrix (D : ℕ) (M : Fin D → Matrix ι ι ℂ) : + Matrix (Fin D → ι) (Fin D → ι) ℂ := fun σ τ => ∏i, M i (σ i) (τ i) + +theorem mixedMatrix_mulVec (D : ℕ) (M : Fin D → Matrix ι ι ℂ) + (v : Fin D → EuclideanSpace ℂ ι) : + mixedMatrix D M *ᵥ (mixedPower D v).ofLp= + (mixedPower D (fun i => WithLp.toLp 2 (M i *ᵥ (v i).ofLp))).ofLp := by + classical + funext σ + change (∑τ : Fin D → ι, (∏i, M i (σ i) (τ i))*(∏i, v i (τ i)))= + ∏i, ∑j, M i (σ i) j*v i j + simp_rw [←Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun i j => M i (σ i) j*v i j)).symm + +variable [DecidableEq ι] + +def mixedOperator (D : ℕ) + (T : Fin D → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + EuclideanSpace ℂ (Fin D → ι) →L[ℂ] EuclideanSpace ℂ (Fin D → ι) := + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := Fin D → ι)) + (mixedMatrix D (fun i => (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm (T i))) + +theorem mixedOperator_apply (D : ℕ) + (T : Fin D → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (v : Fin D → EuclideanSpace ℂ ι) : + mixedOperator D T (mixedPower D v)=mixedPower D (fun i => T i (v i)) := by + apply WithLp.ofLp_injective + rw [mixedOperator,Matrix.ofLp_toEuclideanCLM,mixedMatrix_mulVec] + congr 2 + funext i + have hh := congrArg (fun S : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι => S (v i)) + (Matrix.toEuclideanCLM.apply_symm_apply (T i)) + simpa only [←Matrix.toEuclideanCLM_toLp,WithLp.toLp_ofLp] using hh + +theorem inner_mixedOperator (D : ℕ) + (T : Fin D → EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (v w : EuclideanSpace ℂ ι) : + ⟪power D v,mixedOperator D T (power D w)⟫_ℂ=∏i, ⟪v,T i w⟫_ℂ := by + change ⟪mixedPower D (fun _ => v),mixedOperator D T (mixedPower D (fun _ => w))⟫_ℂ=_ + rw [mixedOperator_apply,inner_mixedPower] + +omit [Fintype ι] [DecidableEq ι] in + theorem prod_one_marked (D : ℕ) (j : Fin D) (a b : ℂ) : + (∏i : Fin D, if i=j then a else b)=a*b^(D-1) := by + rw [←Finset.mul_prod_erase Finset.univ (fun i : Fin D => if i=j then a else b) (Finset.mem_univ j)] + simp only [ite_true] + congr 1 + calc + _ = ∏_i ∈ Finset.univ.erase j, b := by + apply Finset.prod_congr rfl + intro i hi + simp only [Finset.mem_erase] at hi + exact ite_eq_right hi.1 + _ = b^(D-1) := by simp + + +def insertionSum (D : ℕ) (K T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + EuclideanSpace ℂ (Fin D → ι) →L[ℂ] EuclideanSpace ℂ (Fin D → ι) := + ∑j : Fin D, mixedOperator D (fun i => if i=j then T else K) + +theorem inner_insertionSum (D : ℕ) + (K T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (v w : EuclideanSpace ℂ ι) : + ⟪power D v,insertionSum D K T (power D w)⟫_ℂ= + (D:ℂ)*⟪v,T w⟫_ℂ*⟪v,K w⟫_ℂ^(D-1) := by + simp only [insertionSum,_root_.sum_apply,inner_sum,inner_mixedOperator] + have ht (j : Fin D) : + (∏i : Fin D, ⟪v,(if i=j then T else K) w⟫_ℂ)=⟪v,T w⟫_ℂ*⟪v,K w⟫_ℂ^(D-1) := by + convert prod_one_marked D j ⟪v,T w⟫_ℂ ⟪v,K w⟫_ℂ using 1 + apply Finset.prod_congr rfl + intro i hi + split_ifs <;> rfl + simp only [ht,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_assoc] + + +def normalizedInsertion (D : ℕ) + (K T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + EuclideanSpace ℂ (Fin D → ι) →L[ℂ] EuclideanSpace ℂ (Fin D → ι) := + (((Real.sqrt (D:ℝ))⁻¹:ℝ):ℂ) • insertionSum D K T + +theorem inner_normalizedInsertion (D : ℕ) + (K T : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (v w : EuclideanSpace ℂ ι) : + ⟪power D v,normalizedInsertion D K T (power D w)⟫_ℂ= + (Real.sqrt (D:ℝ):ℂ)*⟪v,T w⟫_ℂ*⟪v,K w⟫_ℂ^(D-1) := by + rw [normalizedInsertion,_root_.smul_apply,inner_smul_right,inner_insertionSum] + have hh : ((Real.sqrt (D:ℝ))⁻¹:ℝ)*(D:ℝ)=Real.sqrt (D:ℝ) := by + have hs : Real.sqrt (D:ℝ)^2=(D:ℝ) := Real.sq_sqrt (Nat.cast_nonneg D) + calc + _ = ((Real.sqrt (D:ℝ))⁻¹:ℝ)*Real.sqrt (D:ℝ)^2 := by rw [hs] + _ = _ := by + rcases eq_or_ne (Real.sqrt (D:ℝ)) 0 with h|h + · simp [h] + · field_simp + have hc : (((Real.sqrt (D:ℝ))⁻¹:ℝ):ℂ)*(D:ℂ)=(Real.sqrt (D:ℝ):ℂ) := by exact_mod_cast hh + calc + _ = ((((Real.sqrt (D:ℝ))⁻¹:ℝ):ℂ)*(D:ℂ))*⟪v,T w⟫_ℂ*⟪v,K w⟫_ℂ^(D-1) := by ring + _ = _ := by rw [hc] + +end FiniteTensor + +namespace QuantumCLT +open scoped InnerProductSpace Topology +open ContinuousLinearMap Filter +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +def markedFunctional (Ω : E) (S : E →L[ℂ] E) : (E →L[ℂ] E) →L[ℂ] ℂ := + (((innerSL ℂ Ω).comp S).comp (ContinuousLinearMap.apply ℂ E Ω)) + +@[simp] theorem markedFunctional_apply (Ω : E) (S T : E →L[ℂ] E) : + markedFunctional Ω S T=⟪Ω,S (T Ω)⟫_ℂ := rfl + +theorem markedFunctional_norm (Ω : E) (S : E →L[ℂ] E) : + ‖markedFunctional Ω S‖ ≤ ‖Ω‖^2*‖S‖ := by + apply ContinuousLinearMap.opNorm_le_bound _ (by positivity) + intro T + calc + _ ≤ ‖Ω‖*‖S (T Ω)‖ := norm_inner_le_norm _ _ + _ ≤ ‖Ω‖*(‖S‖*‖T Ω‖) := mul_le_mul_of_nonneg_left (S.le_opNorm _) (norm_nonneg _) + _ ≤ ‖Ω‖*(‖S‖*(‖T‖*‖Ω‖)) := by gcongr; exact T.le_opNorm _ + _ = ‖Ω‖^2*‖S‖*‖T‖ := by ring +end QuantumCLT + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SelectedBlock.lean b/lean/OAI/Probability/ParisiFinite/SelectedBlock.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a4fe13345c15b913a9cf47eab74dcba89113c27 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SelectedBlock.lean @@ -0,0 +1,760 @@ +import Mathlib +import OAI.Probability.ParisiFinite.GramBlock + +namespace OAI + +/-! Selected Block. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma selectedBlock_support {μ : ProbabilityMeasure OverlapArray} (hex : FiniteExchangeable μ) + {r : ℕ} (e : Fin r → ℕ) (he : Function.Injective e) {R : OverlapArray} + (hR : R∈(μ : Measure OverlapArray).support) : selectedBlock e R∈(blockLaw μ r).support := by + rw [Measure.support_eq_forall_isOpen] at hR ⊢ + intro U hU hOpen + have hh := hR ((selectedBlock e) ⁻¹' U) hU (hOpen.preimage (continuous_selectedBlock e)) + have hm := congrArg (fun ν : Measure (OverlapBlock r) => ν U) (hex r e he) + rw [Measure.map_apply (continuous_selectedBlock e).measurable hOpen.measurableSet] at hm + rwa [hm] at hh + +lemma arraySupport_Gram {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) : (μ : Measure OverlapArray).support ⊆ GramArrays := by + apply Measure.support_subset_of_isClosed isClosed_GramArrays + apply ae_iff.mpr + change (μ : Measure OverlapArray) GramArraysᶜ=0 + rw [measure_compl isClosed_GramArrays.measurableSet (measure_ne_top _ _),hG] + simp + +def UltrametricArrays : Set OverlapArray := {R | ∀ i j k : ℕ, min (R i k:ℝ) (R j k:ℝ)≤(R i j:ℝ)} + +lemma isClosed_UltrametricArrays : IsClosed UltrametricArrays := by + unfold UltrametricArrays + simp only [Set.ofPred_forall] + exact isClosed_iInter fun i => isClosed_iInter fun j => isClosed_iInter fun k => isClosed_le (by fun_prop) (by fun_prop) + + + +theorem GG_support_ultrametric {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) : + (μ : Measure OverlapArray).support ⊆ UltrametricArrays := by + intro R hR i j k + have hg := arraySupport_Gram hG hR + by_cases hij : i=j + · subst j + rw [hg.2.1 i,min_self] + exact (R i k).2.2 + by_cases hik : i=k + · subst k + rw [hg.1 j i] + exact min_le_right _ _ + by_cases hjk : j=k + · subst k + exact min_le_left _ _ + let e : Fin 3 → ℕ := ![i,j,k] + have he : Function.Injective e := by + intro u v huv + fin_cases u <;> fin_cases v <;> simp_all [e] + exact supported_triangle_ultrametric hG hgg hex (selectedBlock_support hex e he hR) + + + +theorem GG_ultrametric {μ : ProbabilityMeasure OverlapArray} + (hG : (μ : Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) (hex : FiniteExchangeable μ) : + (μ : Measure OverlapArray) UltrametricArrays=1 := by + apply le_antisymm prob_le_one + calc + 1 = (μ : Measure OverlapArray) (μ : Measure OverlapArray).support := by + have hs : (μ : Measure OverlapArray).support =ᵐ[(μ : Measure OverlapArray)] Set.univ := by + filter_upwards [(μ : Measure OverlapArray).support_mem_ae] with R hR + exact propext ⟨fun _ => Set.mem_univ R,fun _ => hR⟩ + rw [measure_congr hs,measure_univ] + _ ≤ _ := measure_mono (GG_support_ultrametric hG hgg hex) + + + +theorem exists_generic_ultrametric_limit (β : ℝ) : + ∃ μ : ProbabilityMeasure OverlapArray, + (μ : Measure OverlapArray) GramArrays=1 ∧ GGIdentities μ ∧ FiniteExchangeable μ ∧ + (μ : Measure OverlapArray) UltrametricArrays=1 ∧ + ∃ φ : ℕ → ℕ, StrictMono φ ∧ Tendsto (fun k => genericOverlapLaw (φ k) β) atTop (𝓝 μ) := by + obtain ⟨μ,φ,hφ,hμ⟩ := CompactSpace.tendsto_subseq (fun n => genericOverlapLaw n β) + have hG := genericOverlap_limit_Gram β hφ hμ + have hgg := genericOverlap_limit_GGIdentities β hφ hμ + have hex := genericOverlap_limit_FiniteExchangeable β hφ hμ + exact ⟨μ,hG,hgg,hex,GG_ultrametric hG hgg hex,φ,hφ,hμ⟩ + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {K : Type*} [Fintype K] [DecidableEq K] + +lemma pow_sub_lipschitz_unit {a b : ℝ} (ha : |a|≤1) (hb : |b|≤1) (p : ℕ) : + |a^p-b^p|≤(p:ℝ)*|a-b| := by + have h := abs_pow_sub_pow_le a b p + have hm : max |a| |b|≤1 := max_le ha hb + have hp := pow_le_one₀ (le_max_of_le_left (abs_nonneg a)) hm (n:=p-1) + have hh := mul_le_mul_of_nonneg_left hp (by positivity : 0 ≤ |a-b| * (p:ℝ)) + nlinarith only [h,hh] + +lemma overlap_last_split {n : ℕ} (hn : 0 < n) (σ τ : Configuration (n+1)) : + overlap σ τ=((n:ℝ)*overlap (restrictLeft σ) (restrictLeft τ)+ + spin σ (Fin.last n)*spin τ (Fin.last n))/(n+1) := by + rw [overlap,overlapSum_last,overlap] + have hn' : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr hn.ne' + push_cast + field_simp + +lemma overlap_restrict_difference {n : ℕ} (hn : 0 < n) (σ τ : Configuration (n+1)) : + |overlap σ τ-overlap (restrictLeft σ) (restrictLeft τ)|≤2/((n:ℝ)+1) := by + rw [overlap_last_split hn] + have he : ((n:ℝ)*overlap (restrictLeft σ) (restrictLeft τ)+ + spin σ (Fin.last n)*spin τ (Fin.last n))/(n+1)-overlap (restrictLeft σ) (restrictLeft τ)= + (spin σ (Fin.last n)*spin τ (Fin.last n)-overlap (restrictLeft σ) (restrictLeft τ))/(n+1) := by + field_simp; ring + rw [he,abs_div,abs_of_pos (show (0:ℝ) β*cavityCoeff n σ u) + (fun u => x u.1*pSpinCoeff n (d u.1) (restrictLeft σ) u.2) + +omit [DecidableEq K] in +lemma mixedCavityCoeff_kernel {n : ℕ} (hn : 0 < n) (d : K → ℕ) (β : ℝ) (x : K → ℝ) + (σ τ : Configuration (n+1)) : + kernel (mixedCavityCoeff n d β x) σ τ = + kernel (fun s e => β*skCoeff (n+1) s e) σ τ+ + ∑ k,(x k)^2*(overlap (restrictLeft σ) (restrictLeft τ))^(d k) := by + change (∑ u,mixedCavityCoeff n d β x σ u*mixedCavityCoeff n d β x τ u)=_ + rw [Fintype.sum_sum_type] + simp only [mixedCavityCoeff,Sum.elim_inl,Sum.elim_inr,Fintype.sum_sigma] + change kernel (fun s u => β*cavityCoeff n s u) σ τ+ + (∑ k,kernel (fun s u => x k*pSpinCoeff n (d k) s u) (restrictLeft σ) (restrictLeft τ))=_ + simp_rw [kernel_scale,pSpinCoeff_kernel hn] + rw [cavityCoeff_kernel hn] + +omit [DecidableEq K] in +lemma mixedCoeff_kernel_add {n : ℕ} (hn : 0 < n) (d : K → ℕ) (β : ℝ) (x : K → ℝ) + (σ τ : Configuration n) : + kernel (mixedCoeff n d β x) σ τ = kernel (fun s e => β*skCoeff n s e) σ τ+ + ∑ k,(x k)^2*(overlap σ τ)^(d k) := by + rw [mixedCoeff_kernel hn,kernel_scale,kernel,coeff_covariance hn] + ring + +omit [DecidableEq K] in +lemma mixedCavity_kernel_error {n : ℕ} (hn : 0 < n) (d : K → ℕ) (β : ℝ) (x : K → ℝ) + (σ τ : Configuration (n+1)) : + |kernel (mixedCavityCoeff n d β x) σ τ-kernel (mixedCoeff (n+1) d β x) σ τ|≤ + (2/((n:ℝ)+1))*∑ k,(x k)^2*(d k:ℝ) := by + rw [mixedCavityCoeff_kernel hn,mixedCoeff_kernel_add (Nat.succ_pos n)] + rw [add_sub_add_left_eq_sub,← Finset.sum_sub_distrib,Finset.mul_sum] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro k _ + rw [← mul_sub,abs_mul,abs_of_nonneg (sq_nonneg _)] + have hp := pow_sub_lipschitz_unit (abs_overlap_le_one (restrictLeft σ) (restrictLeft τ)) + (abs_overlap_le_one σ τ) (d k) + rw [abs_sub_comm (overlap (restrictLeft σ) (restrictLeft τ))] at hp + have h := mul_le_mul_of_nonneg_left (overlap_restrict_difference hn σ τ) (Nat.cast_nonneg (d k)) + have h' := mul_le_mul_of_nonneg_left (hp.trans h) (sq_nonneg (x k)) + nlinarith only [h'] + +omit [DecidableEq K] in +lemma mixedCavity_diag {n : ℕ} (hn : 0 < n) (d : K → ℕ) (β : ℝ) (x : K → ℝ) + (σ : Configuration (n+1)) : + kernel (mixedCavityCoeff n d β x) σ σ=kernel (mixedCoeff (n+1) d β x) σ σ := by + rw [mixedCavityCoeff_kernel hn,mixedCoeff_kernel_add (Nat.succ_pos n),overlap_self hn,overlap_self (Nat.succ_pos n)] + + + +omit [DecidableEq K] in +theorem mixedCavity_pressure_error {n : ℕ} (hn : 0 < n) (d : K → ℕ) (β : ℝ) (x : K → ℝ) : + |expected (mixedCavityCoeff n d β x)-expected (mixedCoeff (n+1) d β x)|≤ + Real.pi/((n:ℝ)+1)*(∑ k,(x k)^2*(d k:ℝ)) := by + let M := (4/((n:ℝ)+1))*∑ k,(x k)^2*(d k:ℝ) + have hM : 0≤M := by dsimp [M]; positivity + have hi (σ τ : Configuration (n+1)) : + |ParisiInterpolation.increment (mixedCavityCoeff n d β x) σ τ- + ParisiInterpolation.increment (mixedCoeff (n+1) d β x) σ τ|≤M := by + rw [increment_eq_kernel,increment_eq_kernel,mixedCavity_diag hn,mixedCavity_diag hn] + have he : kernel (mixedCoeff (n+1) d β x) σ σ+kernel (mixedCoeff (n+1) d β x) τ τ- + 2*kernel (mixedCavityCoeff n d β x) σ τ- + (kernel (mixedCoeff (n+1) d β x) σ σ+kernel (mixedCoeff (n+1) d β x) τ τ- + 2*kernel (mixedCoeff (n+1) d β x) σ τ)= + -2*(kernel (mixedCavityCoeff n d β x) σ τ-kernel (mixedCoeff (n+1) d β x) σ τ) := by ring + rw [he,abs_mul] + norm_num only [abs_neg,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + have h := mul_le_mul_of_nonneg_left (mixedCavity_kernel_error hn d β x σ τ) (by norm_num : (0:ℝ)≤2) + exact h.trans_eq (by dsimp [M]; ring) + have h := expected_difference_le (mixedCoeff (n+1) d β x) (mixedCavityCoeff n d β x) hM hi + convert h using 1 + dsimp [M] + ring + + + +def mixedIncrement (n : ℕ) (d : K → ℕ) (β : ℝ) (x : K → ℝ) : ℝ := + expected (mixedCavityCoeff n d β x)-expected (mixedCoeff n d β x) + +omit [DecidableEq K] in +lemma mixedIncrement_difference {n : ℕ} (hn : 0 < n) (d : K → ℕ) (β : ℝ) (x : K → ℝ) : + |mixedIncrement n d β x-(expected (mixedCoeff (n+1) d β x)-expected (mixedCoeff n d β x))|≤ + Real.pi/((n:ℝ)+1)*(∑ k,(x k)^2*(d k:ℝ)) := by + simpa only [mixedIncrement,sub_sub_sub_cancel_right] using mixedCavity_pressure_error hn d β x + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +variable {ι κ κ' : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] [Fintype κ'] + +def independentCoeff (A : ι → κ → ℝ) (B : ι → κ' → ℝ) (s : ι) : κ ⊕ κ' → ℝ := Sum.elim (A s) (B s) + +omit [Fintype ι] [Nonempty ι] in +lemma kernel_independent (A : ι → κ → ℝ) (B : ι → κ' → ℝ) (s t : ι) : + kernel (independentCoeff A B) s t=kernel A s t+kernel B s t := by + simp [kernel,independentCoeff,Fintype.sum_sum_type] + +omit [Fintype ι] [Nonempty ι] in +lemma increment_independent (A : ι → κ → ℝ) (B : ι → κ' → ℝ) (s t : ι) : + ParisiInterpolation.increment (independentCoeff A B) s t= + ParisiInterpolation.increment A s t+ParisiInterpolation.increment B s t := by + simp only [increment_eq_kernel,kernel_independent] + ring + +lemma expected_independent_mono (A : ι → κ → ℝ) (B : ι → κ' → ℝ) : + expected A≤expected (independentCoeff A B) := by + apply expected_field_logPartition_le + intro s t + change ParisiInterpolation.increment A s t≤ParisiInterpolation.increment (independentCoeff A B) s t + rw [increment_independent] + apply le_add_of_nonneg_right + exact Finset.sum_nonneg fun _ _ => sq_nonneg _ + +lemma expected_independent_error (A : ι → κ → ℝ) (B : ι → κ' → ℝ) {M : ℝ} + (hM : 0≤M) (h : ∀ s t, ParisiInterpolation.increment B s t≤M) : + expected (independentCoeff A B)-expected A≤M*Real.pi/4 := by + have he := expected_difference_le A (independentCoeff A B) hM (fun s t => by + rw [increment_independent,add_sub_cancel_left,abs_of_nonneg (Finset.sum_nonneg fun _ _ => sq_nonneg _)] + exact h s t) + exact (le_abs_self _).trans he + +lemma average_const (x : ι → ℝ) (c : ℝ) : average x (fun _ => c)=c := by + simp [average,← Finset.sum_mul,sum_weight] + +lemma logPartition_restrictLeft {n : ℕ} (x : Configuration n → ℝ) : + logPartition (fun σ : Configuration (n+1) => x (restrictLeft σ))=logPartition x+Real.log 2 := by + have h := logPartition_extend x (fun _ => 0) + have he : SKCavity.extend x (fun _ => 0) = (fun σ : Configuration (n+1) => x (restrictLeft σ)) := by + funext σ + simp only [SKCavity.extend,mul_zero,add_zero] + rw [he] at h + simpa only [Real.cosh_zero,mul_one,average_const] using h + +def liftOld {n : ℕ} (A : Configuration n → κ → ℝ) (σ : Configuration (n+1)) : κ → ℝ := A (restrictLeft σ) + +lemma expected_liftOld {n : ℕ} (A : Configuration n → κ → ℝ) : + expected (liftOld A)=expected A+Real.log 2 := by + have hf (z : κ → ℝ) : field (liftOld A) z=fun σ => field A z (restrictLeft σ) := rfl + unfold expected + simp_rw [hf,logPartition_restrictLeft] + rw [integral_add (integrable_logPartition (fun σ => integrable_field A σ)) (integrable_const _)] + simp + + + +omit [Fintype ι] [Nonempty ι] in +lemma increment_le_four_diagonal (B : ι → κ' → ℝ) (s₀ : ι) + (hB : ∀ s k, |B s k|=|B s₀ k|) (s t : ι) : + ParisiInterpolation.increment B s t≤4*kernel B s₀ s₀ := by + unfold ParisiInterpolation.increment kernel + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro k _ + have hs := congrArg (fun x : ℝ => x^2) (hB s k) + have ht := congrArg (fun x : ℝ => x^2) (hB t k) + simp only [sq_abs] at hs ht + nlinarith [sq_nonneg (B s k+B t k)] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {K : Type*} [Fintype K] [DecidableEq K] + +def siteCoeff (n : ℕ) (β : ℝ) (σ : Configuration (n+1)) (i : Fin n) : ℝ := + β*cavityScale n*spin σ (Fin.last n)*spin (restrictLeft σ) i + +omit [DecidableEq K] in +lemma mixedCavity_split (n : ℕ) (d : K → ℕ) (β : ℝ) (x : K → ℝ) : + expected (mixedCavityCoeff n d β x)= + expected (independentCoeff (liftOld (mixedCoeff n d (β*coreScale n) x)) (siteCoeff n β)) := by + apply expected_logPartition_eq_of_kernel + intro σ τ + simp only [kernel,mixedCavityCoeff,mixedCoeff,liftOld,siteCoeff, + cavityCoeff,independentCoeff,Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr,Fintype.sum_sigma] + ac_rfl + +omit [DecidableEq K] in +lemma mixed_core_correction (n : ℕ) (d : K → ℕ) (β : ℝ) (x : K → ℝ) : + expected (mixedCoeff n d β x)=expected (independentCoeff + (mixedCoeff n d (β*coreScale n) x) (fun σ e => β*cavityScale n*skCoeff n σ e)) := by + apply expected_logPartition_eq_of_kernel + intro σ τ + have hc := scales_sum n + simp only [kernel,independentCoeff,mixedCoeff,Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr] + have hs : (∑ e, β*skCoeff n σ e*(β*skCoeff n τ e))= + (∑ e, (β*coreScale n)*skCoeff n σ e*((β*coreScale n)*skCoeff n τ e))+ + (∑ e, β*cavityScale n*skCoeff n σ e*(β*cavityScale n*skCoeff n τ e)) := by + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro e _ + nlinarith only [congrArg (fun a : ℝ => a*(β^2*skCoeff n σ e*skCoeff n τ e)) hc] + linarith only [hs] + +lemma skCoeff_abs (n : ℕ) (σ τ : Configuration n) (e : Edge n) : + |skCoeff n σ e|=|skCoeff n τ e| := by + simp [skCoeff,abs_mul,spin_abs] + +lemma correction_diagonal_le {n : ℕ} (hn : 0 < n) (β : ℝ) (σ : Configuration n) : + kernel (fun σ e => β*cavityScale n*skCoeff n σ e) σ σ ≤ β^2/2 := by + rw [kernel_scale,kernel,coeff_covariance hn,overlapSum_self] + rw [mul_pow,cavityScale_sq] + have hn' : (0:ℝ) β*cavityScale n*skCoeff n σ e) (M:=2*β^2) (by positivity) (fun s t => by + have hh := increment_le_four_diagonal (fun σ e => β*cavityScale n*skCoeff n σ e) s + (fun σ e => by simp only [abs_mul,skCoeff_abs n σ s e]) s t + exact hh.trans (by nlinarith [correction_diagonal_le hn β s])) + exact h.trans_eq (by ring) + + +omit [DecidableEq K] in +theorem mixedIncrement_lower {n : ℕ} (hn : 0 < n) (d : K → ℕ) (β : ℝ) (x : K → ℝ) : + Real.log 2-Real.pi*β^2/2 ≤ mixedIncrement n d β x := by + have hlo := expected_independent_mono (liftOld (mixedCoeff n d (β*coreScale n) x)) (siteCoeff n β) + rw [← mixedCavity_split,expected_liftOld] at hlo + have hup := core_pressure_lower hn d β x + unfold mixedIncrement + linarith + +lemma siteCoeff_abs (n : ℕ) (β : ℝ) (σ τ : Configuration (n+1)) (i : Fin n) : + |siteCoeff n β σ i|=|siteCoeff n β τ i| := by + simp only [siteCoeff,abs_mul,spin_abs,mul_one] + +lemma siteCoeff_diag_le (n : ℕ) (β : ℝ) (σ : Configuration (n+1)) : + kernel (siteCoeff n β) σ σ ≤ β^2 := by + have he (i : Fin n) : siteCoeff n β σ i*siteCoeff n β σ i=β^2*cavityScale n^2 := by + dsimp [siteCoeff] + nlinarith only [spin_sq σ (Fin.last n),spin_sq (restrictLeft σ) i, + congrArg (fun a : ℝ => β^2*cavityScale n^2*a) (spin_sq σ (Fin.last n)), + congrArg (fun a : ℝ => β^2*cavityScale n^2*spin σ (Fin.last n)^2*a) (spin_sq (restrictLeft σ) i)] + simp only [kernel,he,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,cavityScale_sq] + have hpos : (0:ℝ) β*cavityScale n*skCoeff n σ e) + rw [← mixed_core_correction] at hlo + have hup := expected_independent_error (liftOld (mixedCoeff n d (β*coreScale n) x)) + (siteCoeff n β) (M:=4*β^2) (by positivity) (fun s t => + (increment_le_four_diagonal (siteCoeff n β) s (fun σ i => siteCoeff_abs n β σ s i) s t).trans + (by nlinarith [siteCoeff_diag_le n β s])) + rw [← mixedCavity_split,expected_liftOld] at hup + unfold mixedIncrement + nlinarith only [hlo,hup] + +omit [DecidableEq K] in +lemma mixedIncrement_bounded {n : ℕ} (hn : 0 < n) (d : K → ℕ) (β : ℝ) : + ∃ M : ℝ, ∀ x, |mixedIncrement n d β x| ≤ M := by + refine ⟨|Real.log 2|+Real.pi*β^2,fun x => abs_le.mpr ⟨?_,?_⟩⟩ + · have h := mixedIncrement_lower hn d β x + nlinarith [neg_abs_le (Real.log 2),Real.pi_pos,sq_nonneg β] + · exact (mixedIncrement_upper n d β x).trans (add_le_add (le_abs_self _) le_rfl) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +lemma continuous_expected_coeff : Continuous (fun A : ι → κ → ℝ => expected A) := by + classical + apply continuous_iff_continuousAt.mpr + intro A₀ + let H (A : ι → κ → ℝ) := ∑ s, ∑ t, |ParisiInterpolation.increment A s t-ParisiInterpolation.increment A₀ s t| + have hc : Continuous H := by unfold H ParisiInterpolation.increment; fun_prop + have hH : H A₀=0 := by simp [H] + have hB (A : ι → κ → ℝ) : |expected A-expected A₀| ≤ H A*Real.pi/4 := by + apply expected_difference_le A₀ A (Finset.sum_nonneg fun _ _ => Finset.sum_nonneg fun _ _ => abs_nonneg _) + intro s t + have h1 : |ParisiInterpolation.increment A s t-ParisiInterpolation.increment A₀ s t| ≤ + ∑ j : ι, |ParisiInterpolation.increment A s j-ParisiInterpolation.increment A₀ s j| := + Finset.single_le_sum (f := fun j : ι => |ParisiInterpolation.increment A s j-ParisiInterpolation.increment A₀ s j|) (fun j _ => abs_nonneg _) (Finset.mem_univ t) + have h2 : (∑ j : ι, |ParisiInterpolation.increment A s j-ParisiInterpolation.increment A₀ s j|) ≤ H A := + Finset.single_le_sum (f := fun j : ι => ∑ t : ι, |ParisiInterpolation.increment A j t-ParisiInterpolation.increment A₀ j t|) (fun j _ => Finset.sum_nonneg fun _ _ => abs_nonneg _) (Finset.mem_univ s) + exact h1.trans h2 + have ht : Tendsto (fun A => |expected A-expected A₀|) (𝓝 A₀) (𝓝 0) := by + have hh := ((hc.continuousAt (x := A₀)).mul_const Real.pi).div_const 4 + change Tendsto (fun A => H A*Real.pi/4) (𝓝 A₀) (𝓝 (H A₀*Real.pi/4)) at hh + rw [hH,zero_mul,zero_div] at hh + exact squeeze_zero (fun _ => abs_nonneg _) hB hh + apply tendsto_sub_nhds_zero_iff.mp + apply tendsto_zero_iff_norm_tendsto_zero.mpr + simpa only [Real.norm_eq_abs] using ht + +lemma continuous_mixedIncrement (n : ℕ) {K : Type*} [Fintype K] + (d : K → ℕ) (β : ℝ) : Continuous (mixedIncrement n d β) := by + classical + unfold mixedIncrement + apply Continuous.sub + · apply continuous_expected_coeff.comp + apply continuous_pi + intro σ + apply continuous_pi + intro u + cases u <;> simp only [mixedCavityCoeff,Sum.elim_inl,Sum.elim_inr] <;> fun_prop + · exact continuous_expected_coeff.comp (continuous_mixedCoeff n d β) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {K : Type*} [Fintype K] [DecidableEq K] + +lemma sum_fin_increment (a : ℕ → ℝ) (N M : ℕ) : + (∑ i : Fin M, (a (N+i+1)-a (N+i)))=a (N+M)-a N := by + induction M with + | zero => simp + | succ M ih => + rw [Fin.sum_univ_castSucc] + simp only [Fin.val_castSucc,Fin.val_last] + rw [ih] + simp only [Nat.add_assoc] + ring + +lemma expected_sk_pressure (n : ℕ) (β : ℝ) : + expected (fun σ e => β*skCoeff n σ e)=pressure β n := by + unfold expected + simp only [field_scale,field_skCoeff] + rfl + + + +omit [DecidableEq K] in +theorem sum_mixedIncrement_window {N : ℕ} (hN : 0 < N) (d : K → ℕ) (β : ℝ) (x : K → ℝ) : + (∑ i : Fin N, mixedIncrement (N+i) d β x) ≤ pressure β (N+N)-pressure β N+ + Real.pi*(2*(∑ k,(x k)^2)+(∑ k,(x k)^2*(d k:ℝ))) := by + let S := ∑ k,(x k)^2 + let D := ∑ k,(x k)^2*(d k:ℝ) + have hD : 0 ≤ D := by dsimp [D]; positivity + have hN' : (0:ℝ) hstep i) + rw [Finset.sum_add_distrib,sum_fin_increment (fun q => expected (mixedCoeff q d β x)) N N] at hs + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hs + have he : (N:ℝ)*(Real.pi/(N:ℝ)*D)=Real.pi*D := by field_simp + rw [he] at hs + have h0 := mixed_pressure_error hN d β x + have h1 := mixed_pressure_error (show 0 hb k) + have hsum' := Finset.sum_le_sum (fun k (_ : k∈Finset.univ) => + mul_le_mul_of_nonneg_right (hb k) (Nat.cast_nonneg (d k))) + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hsum + rw [← Finset.mul_sum] at hsum' + have h := sum_mixedIncrement_window hN d β x + have hh : 2*(∑ k,(x k)^2)+(∑ k,(x k)^2*(d k:ℝ)) ≤ + (8*(m+1:ℕ)+4*(∑ k,(d k:ℝ)))*s^2 := by nlinarith only [hsum,hsum'] + have hp := mul_le_mul_of_nonneg_left hh Real.pi_pos.le + nlinarith only [h,hp] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma integrable_box_of_bounded {m : ℕ} {a b : ℝ} {F : (Fin m → ℝ) → ℝ} + (hc : Continuous F) (hb : ∃ M : ℝ, ∀ x, |F x| ≤ M) : Integrable F (boxLaw m a b) := by + obtain ⟨M,hM⟩ := hb + exact Integrable.of_bound hc.aestronglyMeasurable M (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs] using hM x) + +lemma integral_box_mixedError_le {m n : ℕ} (hn : 0 < n) (d : Fin (m+1) → ℕ) (β V : ℝ) + {s δ : ℝ} (hs : 0 ∫ t, mixedError n d β δ V k (k.insertNth t y) + ∂intervalLaw s (2*s)) (boxLaw m s (2*s)) := by + let T := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (m+1) => ℝ) k).symm + have hm : MeasurePreserving T ((intervalLaw s (2*s)).prod (boxLaw m s (2*s))) (boxLaw (m+1) s (2*s)) := + (measurePreserving_piFinSuccAbove (fun _ : Fin (m+1) => intervalLaw s (2*s)) k).symm + exact ((hm.integrable_comp (continuous_mixedError n d β δ V k).aestronglyMeasurable).mpr hI).integral_prod_right + have he := integral_mono hi (integrable_const (5+4*V/δ+12*δ)) (fun y => by + rw [integral_intervalLaw hab.le] + have h := integral_mixedError_le hn d β V hs hδ hδs k y + have hh := mul_le_mul_of_nonneg_left h (inv_nonneg.mpr hs.le) + rw [show 2*s-s=s by ring] + exact hh.trans_eq (by field_simp)) + simpa using he + + + +lemma exists_box_index_le_integrable {N m : ℕ} (hN : 0 < N) {a b B : ℝ} (hab : a ∑ i, F i x) (boxLaw m a b) := + integrable_finsetSum _ fun i _ => hint i + have hnull : boxLaw m a b {x | ¬∀ k, x k∈Set.Icc a b}=0 := ae_iff.mp (boxLaw_ae m a b) + obtain ⟨x,hx,hxle⟩ := exists_notMem_null_le_integral hI hnull + have hs := hxle.trans hi + have he : ∃ i, F i x ≤ B := by + by_contra! h + have hh := Finset.sum_lt_sum_of_nonempty (show (Finset.univ : Finset (Fin N)).Nonempty from + ⟨⟨0,hN⟩,Finset.mem_univ _⟩) (fun i (_ : i∈Finset.univ) => h i) + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hh + linarith + obtain ⟨i,hi⟩ := he + exact ⟨i,x,not_not.mp hx,hi⟩ + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + +def coreFluctuationBound (n m : ℕ) (β s : ℝ) : ℝ := + Real.sqrt ((β*coreScale n)^2*n/2+9*(m+1:ℕ)*s^2) + +def coreError {m : ℕ} (n : ℕ) (d : Fin (m+1) → ℕ) (β s δ : ℝ) (x : Fin (m+1) → ℝ) : ℝ := + ∑ k, mixedError n d (β*coreScale n) δ (coreFluctuationBound n m β s) k x + +lemma coreError_integrable {m : ℕ} (n : ℕ) (d : Fin (m+1) → ℕ) (β s δ a b : ℝ) : + Integrable (coreError n d β s δ) (boxLaw (m+1) a b) := + integrable_finsetSum _ fun k _ => integrable_box_of_bounded + (continuous_mixedError n d (β*coreScale n) δ _ k) (mixedError_bounded n d (β*coreScale n) δ _ k) + +lemma coreError_dominates {m n : ℕ} (hn : 0 < n) (d : Fin (m+1) → ℕ) (β : ℝ) + {s δ : ℝ} (hs : 0 (energyDeviation_nonneg _ _ _).trans (hdom j)) (Finset.mem_univ k) + +lemma coreError_nonneg {m n : ℕ} (hn : 0 < n) (d : Fin (m+1) → ℕ) (β : ℝ) + {s δ : ℝ} (hs : 0 integrable_box_of_bounded + (continuous_mixedError n d (β*coreScale n) δ _ k) (mixedError_bounded n d (β*coreScale n) δ _ k))] + have h := Finset.sum_le_sum (fun k (_ : k∈Finset.univ) => + integral_box_mixedError_le hn d (β*coreScale n) (coreFluctuationBound n m β s) hs hδ hδs k) + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at h + have hh := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hU (by norm_num : (0:ℝ) ≤ 4)) hδ.le + have hm := mul_le_mul_of_nonneg_left hh (Nat.cast_nonneg (m+1)) + linarith + +def cavityWindowBudget {m : ℕ} (N : ℕ) (d : Fin (m+1) → ℕ) (β s δ ell U : ℝ) : ℝ := + (pressure β (N+N)-pressure β N+Real.pi*(8*(m+1:ℕ)+4*(∑ k,(d k:ℝ)))*s^2)/(N:ℝ)+ + (ell/s)*(m+1:ℕ)*(5+4*U/δ+12*δ) + + + +theorem exists_cavity_GG_choice {N m : ℕ} (hN : 0 < N) (d : Fin (m+1) → ℕ) (β : ℝ) + {s δ ell U : ℝ} (hs : 0 ∑ j, A j x) μ := integrable_finsetSum _ fun j _ => hIA j + have hIEall : Integrable (fun x => ∑ j, E j x) μ := integrable_finsetSum _ fun j _ => hIE j + have hA : (∫ x, ∑ j, A j x ∂μ) ≤ C := by + have hh := integral_mono_ae hIAall (integrable_const C) ((boxLaw_ae (m+1) s (2*s)).mono (fun x hx => + sum_mixedIncrement_box hN d β hs x hx)) + simpa [μ] using hh + have hE : (∫ x, ∑ j, E j x ∂μ) ≤ (N:ℝ)*((m+1:ℕ)*(5+4*U/δ+12*δ)) := by + rw [integral_finsetSum _ (fun j _ => hIE j)] + have hh := Finset.sum_le_sum (fun j (_ : j∈Finset.univ) => integral_coreError_le (hn j) d β hs hδ hδs (hU j)) + simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using hh + have hF : (∫ x, ∑ j, F j x ∂μ) ≤ (N:ℝ)*cavityWindowBudget N d β s δ ell U := by + simp only [F,Finset.sum_add_distrib,← Finset.mul_sum] + rw [integral_add hIAall (hIEall.const_mul _),integral_const_mul] + have hh := mul_le_mul_of_nonneg_left hE (div_nonneg hell.le hs.le) + have he : (N:ℝ)*cavityWindowBudget N d β s δ ell U= + C+(ell/s)*((N:ℝ)*((m+1:ℕ)*(5+4*U/δ+12*δ))) := by + dsimp [cavityWindowBudget,C] + field_simp + rw [he] + linarith + obtain ⟨j,x,hx,hcost⟩ := exists_box_index_le_integrable hN hab F hIF hF + have hnon := coreError_nonneg (hn j) d β hs hδ hδs x hx + have hlo := mixedIncrement_lower (hn j) d β x + change mixedIncrement (N+j) d β x+(ell/s)*coreError (N+j) d β s δ x ≤ _ at hcost + refine ⟨j,x,hx,?_,fun k r i f hf => ?_⟩ + · nlinarith only [hcost,mul_nonneg (div_nonneg hell.le hs.le) hnon] + · have hgg := mixedGGDefect_bound (hn j) d (β*coreScale (N+j)) x k i f (by norm_num : (0:ℝ) ≤ 1) hf + rw [one_mul,abs_mul,abs_of_nonneg (hs.le.trans (hx k).1)] at hgg + have hd := coreError_dominates (hn j) d β hs hδ hδs x hx k + have hmul := mul_le_mul_of_nonneg_right (hx k).1 (abs_nonneg (mixedGGDefect d (β*coreScale (N+j)) x k i f)) + have hEs : |mixedGGDefect d (β*coreScale (N+j)) x k i f| ≤ coreError (N+j) d β s δ x/s := by + apply (le_div_iff₀ hs).mpr + nlinarith only [hgg,hd,hmul] + apply hEs.trans + apply (le_div_iff₀ hell).mpr + have he : coreError (N+j) d β s δ x/s*ell=(ell/s)*coreError (N+j) d β s δ x := by ring + rw [he] + linarith + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Shape.lean b/lean/OAI/Probability/ParisiFinite/Shape.lean new file mode 100644 index 0000000000000000000000000000000000000000..6912c405c8f4df9717cb634a7400fb389c66e2f4 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Shape.lean @@ -0,0 +1,646 @@ +import Mathlib +import OAI.Probability.ParisiFinite.PacketLabel + +namespace OAI + +/-! Shape. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus RootSpin +namespace CausalStage +variable {b : ℝ} {n : ℕ} {κ : Type*} [Fintype κ] + + + +structure Shape (s : CausalStage b n κ) (q : ControlSignature) : Prop where + word : TraceWord.forget s.trace=q.word + causal : q.Causal n + centers : ∀i,combination (fun j => (s.frame.frame.formal j : SeededTree.Level n)) + (s.coefficients i)=q.center b n i + +theorem visibility_shape (s : CausalStage b n κ) (q : ControlSignature) + (hs : s.Shape q) (i : PacketLabel) : + s.frame.frame.visibility s.trace (s.coefficients i) Z=q.visibility b n i := by + unfold CausalFrame.visibility CausalFrame.centerModel + rw [s.frame.op_model s.trace s.valid,hs.word,hs.centers i,q.center_step b n hs.causal i] + change q.visibility b (n+1) i=q.visibility b n i + exact q.visibility_step b n hs.causal i + +theorem visible_shape (s : CausalStage b n κ) (q : ControlSignature) + (hs : s.Shape q) (hv : q.Visible b n) : s.visible := by + intro i + rw [s.visibility_shape q hs i] + exact hv i + +theorem record_formal (s : CausalStage b n κ) (hb : 0 ((s.record hb).frame.frame.formal j : SeededTree.Level (n+1)))= + Sum.elim (fun j => (SeededTree.empty n).toLinearIsometry (s.frame.frame.formal j : SeededTree.Level n)) + (fun _ : Unit => ((SeededTree.circuit (TraceWord.forget s.trace) (n+1)).insertion : SeededTree.Level (n+1))) := by + funext j + cases j <;> rfl + +theorem record_combination (s : CausalStage b n κ) (hb : 0 ((s.record hb).frame.frame.formal j : SeededTree.Level (n+1))) + (Sum.elim c 0)= (SeededTree.empty n).toLinearIsometry + (combination (fun j => (s.frame.frame.formal j : SeededTree.Level n)) c) := by + rw [s.record_formal hb,combination_sum_zero] + simp only [combination,map_sum,map_smul] + +theorem shape_record (s : CausalStage b n κ) (hb : 0 ((s.record hb).frame.frame.formal j : SeededTree.Level (n+1))) + (Sum.elim (s.coefficients i) 0)=_ + rw [s.record_combination hb,hs.centers i,q.center_step b n hs.causal i] + +theorem shape_initial (b : ℝ) (hb : 0 ((SeededTree.circuit [] 2).insertion : SeededTree.Level 2))) + (Sum.elim PEmpty.elim.{_,1} (fun _ => initialCoefficient b i))=_ + simp only [combination,Fintype.sum_sum_type,Fintype.sum_empty,zero_add,Fintype.sum_unique, + Sum.elim_inr,ControlSignature.center,ControlSignature.initial,ControlSignature.centerTail,add_zero] + +theorem shape_cost (s : CausalStage b n κ) (hb : 0 ((s.record hb).frame.frame.formal j : SeededTree.Level (n+1))) + (s.echoCoefficients t i)= (SeededTree.empty n).toLinearIsometry + (combination (fun j => (s.frame.frame.formal j : SeededTree.Level n)) (s.coefficients i)) + + echoCoefficient t i • ((SeededTree.circuit (TraceWord.forget s.trace) (n+1)).insertion : SeededTree.Level (n+1)) := by + rw [s.record_formal hb] + simp only [echoCoefficients,combination,Fintype.sum_sum_type,Fintype.sum_unique,Sum.elim_inl,Sum.elim_inr, + map_sum,map_smul] + +theorem echo_center_shape (s : CausalStage b n κ) (hb : 0 ((s.record hb).frame.frame.formal j : SeededTree.Level (n+1))) + (s.echoCoefficients t i)=(q.echo t).center b (n+1) i := by + rw [s.record_echo_combination hb t i,hs.centers i,q.center_step b n hs.causal i,hs.word] + simp only [ControlSignature.center,ControlSignature.echo,ControlSignature.centerTail] + abel + +theorem echo_visible_shape (s : CausalStage b n κ) (hb : 0 2 + | _::w => depth w+1 + +def History : List (IndexedGate M) → Type + | [] => PEmpty ⊕ Unit + | _::w => History w ⊕ Unit + +instance historyFintype : (w : List (IndexedGate M)) → Fintype (History w) + | [] => inferInstanceAs (Fintype (PEmpty ⊕ Unit)) + | _::w => @instFintypeSum (History w) Unit (historyFintype w) inferInstance + +def signature (b : ℝ) (x : Fin M → ℝ) : List (IndexedGate M) → ControlSignature + | [] => .initial b + | .mixer i::w => (signature b x w).mixer (x i) + | .cost i::w => (signature b x w).cost (x i) + | .seed i::w => (signature b x w).echo (indexedTime i x) + +theorem depth_eq (w : List (IndexedGate M)) : depth w=w.length+2 := by + induction w with + | nil => rfl + | cons g w ih => simp only [depth,List.length_cons,ih] + +theorem signature_causal (b : ℝ) (x : Fin M → ℝ) (w : List (IndexedGate M)) : + (signature b x w).Causal (depth w) := by + induction w with + | nil => exact ⟨by rfl,by simp [signature,ControlSignature.initial]⟩ + | cons g w ih => + cases g with + | mixer i => exact (signature b x w).causal_mixer ih (x i) + | cost i => exact (signature b x w).causal_cost ih (x i) + | seed i => exact (signature b x w).causal_echo ih (indexedTime i x) + +theorem signature_word (b : ℝ) (x : Fin M → ℝ) (w : List (IndexedGate M)) : + (signature b x w).word=SeededTree.evalWord (indexedWord w++initializationParam b) x := by + induction w with + | nil => simp [signature,ControlSignature.initial,indexedWord,eval_initializationParam] + | cons g w ih => + cases g with + | mixer i => simpa only [signature,ControlSignature.mixer,indexedWord,List.map_cons, + List.cons_append,SeededTree.evalWord,List.map_cons,IndexedGate.param,SeededTree.ParamGate.eval] using congrArg (List.cons (.mixer (x i))) ih + | cost i => simpa only [signature,ControlSignature.cost,indexedWord,List.map_cons, + List.cons_append,SeededTree.evalWord,List.map_cons,IndexedGate.param,SeededTree.ParamGate.eval] using congrArg (List.cons (.cost (x i))) ih + | seed i => + have he : CausalStage.echoAngles (indexedTime i x)=(fun q : Fin 2 => if q=0 then 0 else x i) := by + funext q + unfold CausalStage.echoAngles indexedTime + split_ifs <;> ring + simpa only [signature,ControlSignature.echo,he,indexedWord,List.map_cons, + List.cons_append,SeededTree.evalWord,List.map_cons,IndexedGate.param,SeededTree.ParamGate.eval] using + congrArg (List.cons (.seed (fun q : Fin 2 => if q=0 then 0 else x i))) ih + +def nonzero (x : Fin M → ℝ) : IndexedGate M → Prop + | .seed i => indexedTime i x≠0 + | _ => True + +def Admissible (b : ℝ) (x : Fin M → ℝ) : List (IndexedGate M) → Prop + | [] => (signature b x []).Visible b (depth (M:=M) []) + | g::w => Admissible b x w ∧ (signature b x (g::w)).Visible b (depth (g::w)) ∧ nonzero x g + +theorem Admissible.visible {b : ℝ} {x : Fin M → ℝ} {w : List (IndexedGate M)} + (h : Admissible b x w) : (signature b x w).Visible b (depth w) := by + cases w with + | nil => exact h + | cons g w => exact h.2.1 + + + +theorem compile (b : ℝ) (hb : 0 exact ⟨CausalStage.initial b hb,CausalStage.shape_initial b hb⟩ + | cons g w ih => + obtain ⟨s,hs⟩ := ih hw.1 + cases g with + | mixer i => exact s.exists_shaped_mixer hb _ hs (x i) hw.1.visible + | cost i => exact ⟨s.cost hb (x i),s.shape_cost hb _ hs (x i)⟩ + | seed i => exact s.exists_shaped_echo hb _ hs (indexedTime i x) hw.2.2 hw.1.visible hw.2.1 + +theorem exists_word_close (b : ℝ) (hb : 0 rfl + | @succ N hN ih => + have hc : q.Causal N := ⟨hq.1.trans hN,fun p hp => (hq.2 p hp).trans hN⟩ + rw [q.visibility_step b N hc i,ih] + +end ControlSignature + +namespace IndexedControl +open SeededTree +variable {M : ℕ} + +theorem echoCoefficient_half (i : PacketLabel) (j : Fin M) (x : Fin M → ℝ) : + CausalStage.echoCoefficient (indexedTime j x) i=if i.2=0 then -(x j:ℂ) else (x j:ℂ) := by + unfold CausalStage.echoCoefficient indexedTime + split_ifs <;> push_cast <;> ring + +theorem echoCoefficient_analytic (i : PacketLabel) (j : Fin M) (x : Fin M → ℝ) : + AnalyticAt ℝ (fun u => CausalStage.echoCoefficient (indexedTime j u) i) x := by + simp only [echoCoefficient_half] + have h := (Complex.ofRealCLM.analyticAt _).comp + ((ContinuousLinearMap.proj j : (Fin M → ℝ) →L[ℝ] ℝ).analyticAt x) + split_ifs + · exact h.neg + · exact h + +theorem signature_insertion_regular (b : ℝ) (w : List (IndexedGate M)) (n : ℕ) + (x : Fin M → ℝ) : + PacketRegular x n (fun u => ((circuit (signature b u w).word n).insertion : SeededTree.Level n)) := by + simp only [signature_word] + apply circuit_insertion_packetRegular + intro g hg + rcases List.mem_append.mp hg with hg|hg + · exact indexedWord_regular w x g hg + · exact initializationParam_regular b x g hg + +theorem center_regular (b : ℝ) (w : List (IndexedGate M)) (n : ℕ) + (i : PacketLabel) (x : Fin M → ℝ) : + PacketRegular x n (fun u => (signature b u w).center b n i) := by + induction w with + | nil => + have he : PacketRegular x n (fun _ : Fin M → ℝ => ((circuit [] n).insertion : SeededTree.Level n)) := + circuit_insertion_packetRegular [] (by simp) n + simpa only [signature,ControlSignature.initial,ControlSignature.center, + ControlSignature.centerTail,add_zero] using + PacketRegular.smul n (z := fun _ : Fin M → ℝ => CausalStage.initialCoefficient b i) analyticAt_const he + | cons g w ih => + cases g with + | mixer j => exact ih + | cost j => exact ih + | seed j => + simp only [signature,ControlSignature.center_echo] + exact PacketRegular.add n ih (PacketRegular.smul n (echoCoefficient_analytic i j x) + (signature_insertion_regular b w n x)) + +theorem visibility_analytic (b : ℝ) (w : List (IndexedGate M)) (n : ℕ) + (i : PacketLabel) (x : Fin M → ℝ) : + AnalyticAt ℝ (fun u => (signature b u w).visibility b n i) x := by + have h := PacketRegular.inner n (signature_insertion_regular b w n x) (center_regular b w n i x) + exact (show AnalyticAt ℝ (fun _ : Fin M → ℝ => (-2:ℝ)) x from analyticAt_const).mul + ((Complex.imCLM.analyticAt _).comp h) + +theorem center_zero (b : ℝ) (w : List (IndexedGate M)) (n : ℕ) (i : PacketLabel) : + (signature b 0 w).center b n i=CausalStage.initialCoefficient b i • + ((circuit [] n).insertion : SeededTree.Level n) := by + induction w with + | nil => simp [signature,ControlSignature.initial,ControlSignature.center,ControlSignature.centerTail] + | cons g w ih => + cases g with + | mixer j => exact ih + | cost j => exact ih + | seed j => simpa only [signature,ControlSignature.center_echo,echoCoefficient_half,Pi.zero_apply, + Complex.ofReal_zero,neg_zero,ite_self,zero_smul,add_zero] using ih + +def sign (i : Fin 2) : ℝ := if i=0 then 1 else -1 + +theorem sign_ne_zero (i : Fin 2) : sign i≠0 := by + unfold sign + split_ifs <;> norm_num + +theorem visibility_zero (b : ℝ) (w : List (IndexedGate M)) (n : ℕ) (i : PacketLabel) : + (signature b 0 w).visibility b n i=4*b*sign i.1*Real.exp (-8*b^2) := by + unfold ControlSignature.visibility + rw [center_zero,signature_word,evalWord_append,eval_initializationParam, + circuit_zero_prefix _ _ (indexedWord_zero w),inner_smul_right] + have he : ⟪((circuit (initializationWord b) n).insertion : SeededTree.Level n), + ((circuit [] n).insertion : SeededTree.Level n)⟫_ℂ=Complex.I*(Real.exp (-8*b^2):ℂ) := + inner_initialization_initial n b + rw [he] + unfold CausalStage.initialCoefficient sign + split_ifs <;> simp only [Complex.mul_im,Complex.mul_re,Complex.I_im,Complex.I_re, + Complex.ofReal_re,Complex.ofReal_im,Complex.neg_re,Complex.neg_im,mul_zero,zero_mul, + zero_add] <;> norm_num <;> ring + +theorem visibility_zero_ne (b : ℝ) (hb : 0 [[]] + | g::w => (g::w)::stages w + +theorem mem_stages_self (w : List (IndexedGate M)) : w∈stages w := by + cases w <;> exact List.mem_cons_self + +theorem admissible_of_stages (b : ℝ) (x : Fin M → ℝ) (w : List (IndexedGate M)) + (hv : ∀u∈stages w,(signature b x u).Visible b (depth u)) + (hn : ∀i,x i≠0) : Admissible b x w := by + induction w with + | nil => exact hv [] (mem_stages_self []) + | cons g w ih => + refine ⟨ih (fun u hu => hv u (List.mem_cons_of_mem _ hu)),hv (g::w) (mem_stages_self _),?_⟩ + cases g with + | mixer i => trivial + | cost i => trivial + | seed i => exact div_ne_zero (hn i) (by norm_num) + + + +theorem exists_admissible (b : ℝ) (hb : 0 + match j with + | .inl (k,i) => fun u => (signature b u ((stages w).get k)).visibility b (depth ((stages w).get k)) i + | .inr k => fun u => u k + have hf : ∀j,AnalyticOnNhd ℝ (f j) Set.univ := by + intro j u hu + cases j with + | inl p => exact visibility_analytic b ((stages w).get p.1) _ p.2 u + | inr k => exact (ContinuousLinearMap.proj k : (Fin M → ℝ) →L[ℝ] ℝ).analyticAt u + have hn : ∀j,∃u,f j u≠0 := by + intro j + cases j with + | inl p => exact ⟨0,visibility_zero_ne b hb ((stages w).get p.1) _ p.2⟩ + | inr k => exact ⟨fun _ => 1,by norm_num [f]⟩ + have he : ContinuousAt (fun u => SeededTree.value + (SeededTree.evalWord (indexedWord w++initializationParam b) u)) x := by + apply (analyticAt_value _ _).continuousAt + intro g hg + rcases List.mem_append.mp hg with hg|hg + · exact indexedWord_regular w x g hg + · exact initializationParam_regular b x g hg + obtain ⟨u,hu,he,hf⟩ := AnalyticVisibility.exists_perturbation f hf hn _ x he hε hδ + refine ⟨u,hu,he,admissible_of_stages b u w ?_ (fun i => hf (.inr i))⟩ + intro v hv i + obtain ⟨k,hk⟩ := List.mem_iff_get.mp hv + simpa only [f,hk] using hf (.inl (k,i)) + + + +theorem exists_ordinary_approx (b : ℝ) (hb : 0 exact hu n + | cons g w ih => + cases g with + | mixer a => exact congrArg (fun U => U.followedBy (EvenUnitary.mixer n a)) (ih n) + | seed a => exact congrArg (fun U => U.followedBy (EvenUnitary.seed n a)) (ih n) + | cost a => + cases n with + | zero => exact ih 0 + | succ n => + change (circuit (w++u) (n+1)).followedBy (EvenUnitary.cost n (circuit (w++u) n) a)=_ + rw [ih (n+1),ih n] + rfl + +theorem value_congr_circuit (w u : List SeededTree.Gate) (h : ∀n,circuit w n=circuit u n) : value w=value u := by + rw [value_eq_height w (w.length+u.length) (Nat.le_add_right _ _), + value_eq_height u (w.length+u.length) (Nat.le_add_left _ _),h] + +def cancelInitialization (b : ℝ) : List SeededTree.Gate := + .mixer (-Real.pi/4)::initializationWord b + +theorem cancelInitialization_zero (n : ℕ) : circuit (cancelInitialization 0) n=EvenUnitary.ident n := by + have ha : initializationAngles 0=fun _ => 0 := by funext q; simp [initializationAngles] + unfold cancelInitialization initializationWord + rw [ha] + simp only [circuit,EvenUnitary.seed_zero,EvenUnitary.followedBy_ident] + apply EvenUnitary.ext + apply LinearIsometryEquiv.ext + intro v + change SpinOperators.act (R (-Real.pi/4)) (SpinOperators.act (R (Real.pi/4)) v)=v + change ((SpinOperators.act (R (-Real.pi/4))).comp (SpinOperators.act (R (Real.pi/4)))) v=v + rw [←SpinOperators.act_mul,R_add,show -Real.pi/4+Real.pi/4=0 by ring,R_zero,SpinOperators.act_one] + rfl + +theorem value_cancelInitialization_zero (w : List SeededTree.Gate) : + value (w++cancelInitialization 0)=value w := by + apply value_congr_circuit + intro n + simpa only [List.append_nil] using circuit_suffix_congr w (cancelInitialization 0) [] cancelInitialization_zero n + +def constantGate : SeededTree.Gate → SeededTree.ParamGate ℝ + | .mixer a => .mixer (fun _ => a) + | .cost a => .cost (fun _ => a) + | .seed a => .seed (fun q _ => a q) + +theorem constantGate_eval (g : SeededTree.Gate) (b : ℝ) : (constantGate g).eval b=g := by cases g <;> rfl + +theorem constantGate_regular (g : SeededTree.Gate) (b : ℝ) : (constantGate g).regular b := by + cases g with + | mixer a => exact analyticAt_const + | cost a => exact analyticAt_const + | seed a => exact fun _ => analyticAt_const + +def initializationCurve (w : List SeededTree.Gate) : List (SeededTree.ParamGate ℝ) := + w.map constantGate++[.mixer (fun _ => -Real.pi/4),.mixer (fun _ => Real.pi/4), + .seed (fun q b => if q=0 then -2*b else 0)] + +theorem initializationCurve_eval (w : List SeededTree.Gate) (b : ℝ) : + SeededTree.evalWord (initializationCurve w) b=w++cancelInitialization b := by + unfold initializationCurve + rw [evalWord_append] + have hm : SeededTree.evalWord (w.map constantGate) b=w := by + simp only [SeededTree.evalWord,List.map_map,Function.comp_def,constantGate_eval] + exact List.map_id w + rw [hm] + rfl + +theorem initializationCurve_regular (w : List SeededTree.Gate) (b : ℝ) : + ∀g∈initializationCurve w,g.regular b := by + intro g hg + rcases List.mem_append.mp hg with hg|hg + · obtain ⟨g,hg,rfl⟩ := List.mem_map.mp hg + exact constantGate_regular g b + · simp only [List.mem_cons,List.not_mem_nil,or_false] at hg + rcases hg with rfl|rfl|rfl + · exact analyticAt_const + · exact analyticAt_const + · intro q + change AnalyticAt ℝ (fun b : ℝ => if q=0 then -2*b else 0) b + split_ifs + · exact (analyticAt_const.mul analyticAt_id) + · exact analyticAt_const + + + +theorem exists_small_initialization (w : List SeededTree.Gate) {ε : ℝ} (hε : 0<ε) : + ∃b : ℝ,0 value (w++cancelInitialization b)) 0 := by + simpa only [initializationCurve_eval] using + (analyticAt_value (initializationCurve w) (initializationCurve_regular w 0)).continuousAt + obtain ⟨δ,hδ,hclose⟩ := Metric.continuousAt_iff.mp hc ε hε + refine ⟨δ/2,half_pos hδ,?_⟩ + have hd : dist (δ/2) (0:ℝ)<δ := by rw [Real.dist_eq,sub_zero,abs_of_pos (half_pos hδ)]; linarith + have h := hclose hd + simpa only [value_cancelInitialization_zero,Real.dist_eq] using h + +end SeededTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock PointedTree GramCalculus RootSpin +namespace IndexedControl +open SeededTree +variable {M : ℕ} + +def promote : IndexedGate M → IndexedGate (M+1) + | .mixer i => .mixer i.castSucc + | .cost i => .cost i.castSucc + | .seed i => .seed i.castSucc + +def extendedAngles (x : Fin M → ℝ) : Fin (M+1) → ℝ := Fin.lastCases (-Real.pi/4) x + +def extendedWord (w : List (IndexedGate M)) : List (IndexedGate (M+1)) := + w.map promote++[.mixer (Fin.last M)] + +theorem promote_eval (g : IndexedGate M) (x : Fin M → ℝ) : + (promote g).param.eval (extendedAngles x)=g.param.eval x := by + cases g <;> simp [promote,IndexedGate.param,SeededTree.ParamGate.eval,extendedAngles] + +theorem promote_word_eval (w : List (IndexedGate M)) (x : Fin M → ℝ) : + SeededTree.evalWord (indexedWord (w.map promote)) (extendedAngles x)= + SeededTree.evalWord (indexedWord w) x := by + simp only [indexedWord,SeededTree.evalWord,List.map_map,Function.comp_def,promote_eval] + +theorem extended_initialized_eval (w : List (IndexedGate M)) (x : Fin M → ℝ) (b : ℝ) : + SeededTree.evalWord (indexedWord (extendedWord w)++initializationParam b) (extendedAngles x)= + SeededTree.evalWord (indexedWord w) x++cancelInitialization b := by + rw [evalWord_append,eval_initializationParam] + change SeededTree.evalWord (indexedWord (w.map promote++[.mixer (Fin.last M)])) (extendedAngles x)++_=_ + rw [show indexedWord (w.map promote++[.mixer (Fin.last M)])= + indexedWord (w.map promote)++indexedWord [.mixer (Fin.last M)] from List.map_append, + evalWord_append,promote_word_eval] + simp only [indexedWord,SeededTree.evalWord,List.map_cons,List.map_nil,IndexedGate.param, + SeededTree.ParamGate.eval,extendedAngles,Fin.lastCases_last,List.append_assoc,List.cons_append, + List.nil_append,cancelInitialization] + + + +theorem seed_removal (w : List (IndexedGate M)) (x : Fin M → ℝ) {ε : ℝ} (hε : 0<ε) : + ∃v : List PointedTree.Gate, + |ordinaryValue v-SeededTree.value (SeededTree.evalWord (indexedWord w) x)|<ε := by + obtain ⟨b,hb,he⟩ := exists_small_initialization (SeededTree.evalWord (indexedWord w) x) (half_pos hε) + obtain ⟨v,hv⟩ := exists_ordinary_approx b hb (extendedWord w) (extendedAngles x) (half_pos hε) + rw [extended_initialized_eval] at hv + refine ⟨v,?_⟩ + have h := abs_sub_le (ordinaryValue v) + (SeededTree.value (SeededTree.evalWord (indexedWord w) x++cancelInitialization b)) + (SeededTree.value (SeededTree.evalWord (indexedWord w) x)) + linarith + +end IndexedControl +end SeedInitialization + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Sine.lean b/lean/OAI/Probability/ParisiFinite/Sine.lean new file mode 100644 index 0000000000000000000000000000000000000000..e8ed756010dc052d6d26c5f73f2d358ed55a5954 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Sine.lean @@ -0,0 +1,646 @@ +import Mathlib +import OAI.Probability.ParisiFinite.MovingTensorInsertionLimit + +namespace OAI + +/-! Sine. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +namespace TrigLp +open MeasureTheory +open scoped Topology +variable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) +variable {κ : Type*} [Fintype κ] + + + +def sine (f : Lp ℝ 2 μ) : Lp ℝ 2 μ := + Real.lipschitzWith_sin.compLp Real.sin_zero f + +omit [Fintype κ] in +theorem sine_ae (f : Lp ℝ 2 μ) : (sine μ f : Ω → ℝ)=ᵐ[μ] fun ω => Real.sin (f ω) := + Real.lipschitzWith_sin.coeFn_compLp Real.sin_zero f + +omit [Fintype κ] in +theorem sine_norm_sub_le (f g : Lp ℝ 2 μ) : ‖sine μ f-sine μ g‖≤‖f-g‖ := by + simpa only [sine,NNReal.coe_one,one_mul] using + Real.lipschitzWith_sin.norm_compLp_sub_le Real.sin_zero f g + +omit [Fintype κ] in +theorem sine_continuous : Continuous (sine μ) := + Real.lipschitzWith_sin.continuous_compLp Real.sin_zero + +omit [Fintype κ] in +theorem sum_ae {ι : Type*} (s : Finset ι) (f : ι → Lp ℝ 2 μ) : + ((∑i∈s, f i : Lp ℝ 2 μ) : Ω → ℝ)=ᵐ[μ] fun ω => ∑i∈s, f i ω := by + classical + induction s using Finset.induction_on with + | empty => simpa only [Finset.sum_empty,Pi.zero_def] using Lp.coeFn_zero ℝ 2 μ + | @insert i s hi ih => + simp only [Finset.sum_insert hi] + filter_upwards [Lp.coeFn_add (f i) (∑j∈s, f j),ih] with ω h1 h2 + rw [h1] + simp only [Pi.add_apply] + rw [h2] + +def linear (a : κ → ℝ) (f : κ → Lp ℝ 2 μ) : Lp ℝ 2 μ := ∑k, a k • f k + +theorem linear_ae (a : κ → ℝ) (f : κ → Lp ℝ 2 μ) : + (linear μ a f : Ω → ℝ)=ᵐ[μ] fun ω => ∑k, a k*f k ω := by + have ht : ∀ᵐ ω ∂μ, ∀k, (a k • f k : Lp ℝ 2 μ) ω=a k*f k ω := + ae_all_iff.mpr (fun k => by + filter_upwards [Lp.coeFn_smul (a k) (f k)] with ω h + simpa only [Pi.smul_apply,smul_eq_mul] using h) + filter_upwards [sum_ae μ Finset.univ (fun k => a k • f k),ht] with ω h1 h2 + change (∑k, a k • f k : Lp ℝ 2 μ) ω= _ + rw [h1] + exact Finset.sum_congr rfl (fun k hk => h2 k) + +theorem linear_norm_sub_le (a : κ → ℝ) (f g : κ → Lp ℝ 2 μ) : + ‖linear μ a f-linear μ a g‖≤∑k, |a k| *‖f k-g k‖ := by + simp only [linear,←Finset.sum_sub_distrib,←smul_sub] + simpa only [norm_smul,Real.norm_eq_abs] using norm_sum_le Finset.univ (fun k => a k • (f k-g k)) + +def polynomial (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (f : κ → Lp ℝ 2 μ) : Lp ℝ 2 μ := + ∑a∈s, b a • sine μ (linear μ a f) + +theorem polynomial_ae (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (f : κ → Lp ℝ 2 μ) : + (polynomial μ s b f : Ω → ℝ)=ᵐ[μ] fun ω => FourierDensity.sinePolynomial s b (fun k => f k ω) := by + have ht (a : κ → ℝ) : + ((b a • sine μ (linear μ a f) : Lp ℝ 2 μ) : Ω → ℝ)=ᵐ[μ] + fun ω => b a*FourierDensity.sine a (fun k => f k ω) := by + filter_upwards [Lp.coeFn_smul (b a) (sine μ (linear μ a f)), + sine_ae μ (linear μ a f),linear_ae μ a f] with ω h1 h2 h3 + rw [h1] + simp only [Pi.smul_apply,smul_eq_mul] + rw [h2,h3] + rfl + have hts := (Filter.eventually_all_finset s).mpr (fun a ha => ht a) + filter_upwards [sum_ae μ s (fun a => b a • sine μ (linear μ a f)),hts] with ω h1 h2 + change (∑a∈s, b a • sine μ (linear μ a f) : Lp ℝ 2 μ) ω= _ + rw [h1] + exact Finset.sum_congr rfl h2 + + + +theorem polynomial_norm_sub_le (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) + (f g : κ → Lp ℝ 2 μ) : + ‖polynomial μ s b f-polynomial μ s b g‖ ≤ + ∑a∈s, |b a| *(∑k, |a k| *‖f k-g k‖) := by + simp only [polynomial,←Finset.sum_sub_distrib,←smul_sub] + calc + _ ≤ ∑a∈s, ‖b a • (sine μ (linear μ a f)-sine μ (linear μ a g))‖ := norm_sum_le _ _ + _ ≤ ∑a∈s, |b a| *(∑k, |a k| *‖f k-g k‖) := by + apply Finset.sum_le_sum + intro a ha + rw [norm_smul,Real.norm_eq_abs] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg (b a)) + exact (sine_norm_sub_le μ _ _).trans (linear_norm_sub_le μ a f g) + +theorem polynomial_continuous (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + Continuous (polynomial μ s b) := by + unfold polynomial + apply continuous_finsetSum + intro a ha + have hl : Continuous (linear μ a) := by unfold linear; fun_prop + convert ((sine_continuous μ).comp hl).const_smul (b a) using 1 + ext f + rfl + +end TrigLp + +namespace GaussianCoherent +open MeasureTheory ProbabilityTheory Complex CoherentFock +open scoped BigOperators InnerProductSpace ComplexConjugate +variable {κ : Type*} [Fintype κ] + + + +def linearField (d : Mode κ) (g : κ → ℝ) : ℂ := ∑k, d k*(g k:ℂ) + +theorem memLp_linearField (d : Mode κ) : MemLp (linearField d) 2 (GaussianFourier.law κ) := by + classical + unfold linearField + apply memLp_finsetSum Finset.univ + intro k hk + have hm : MemLp (fun g : κ → ℝ => g k) 2 (GaussianFourier.law κ) := by + simpa only [Function.comp_def,id_eq,GaussianFourier.law,ENNReal.coe_ofNat] using + (memLp_id_gaussianReal (μ := 0) (v := 1) 2).comp_measurePreserving + (measurePreserving_eval (fun _ : κ => gaussianReal 0 1) k) + exact hm.ofReal.const_mul (d k) + +def fieldVector (d : Mode κ) : Hilbert κ := (memLp_linearField d).toLp (linearField d) + +theorem fieldVector_ae (d : Mode κ) : + (fieldVector d : (κ → ℝ) → ℂ)=ᵐ[GaussianFourier.law κ] linearField d := + (memLp_linearField d).coeFn_toLp + +theorem conj_wave (d : Mode κ) (g : κ → ℝ) : + conj (wave d g)=Complex.exp (conj (offset d))* + Complex.exp (∑k, (-I*conj (d k))*(g k:ℂ)) := by + simp only [wave,map_mul,←Complex.exp_conj,map_sum,Complex.conj_I,Complex.conj_ofReal] + +theorem conjugate_exponent (d : Mode κ) : + conj (offset d)+(∑k, (-I*conj (d k))^2/2)=-((‖d‖^2:ℝ):ℂ)/2 := by + have hi (z : ℂ) : (-I*conj z)^2= -(conj z)^2 := by + ring_nf + rw [Complex.I_sq] + ring + simp only [offset,map_sub,map_div₀,map_sum,map_pow,Complex.conj_ofReal,map_ofNat,hi] + simp_rw [neg_div] + rw [Finset.sum_neg_distrib,←Finset.sum_div] + ring + +theorem integrable_wave_coord (e : Mode κ) (k : κ) : + Integrable (fun g => conj (wave e g)*(g k:ℂ)) (GaussianFourier.law κ) := by + classical + convert (GaussianFourier.integrable_coord_exp_sum (fun j => -I*conj (e j)) k).const_mul + (Complex.exp (conj (offset e))) using 1 + funext g + rw [conj_wave] + ring + +theorem integral_wave_coord (e : Mode κ) (k : κ) : + (∫g, conj (wave e g)*(g k:ℂ) ∂GaussianFourier.law κ)= + (-I*conj (e k))*(Real.exp (-‖e‖^2/2):ℂ) := by + classical + calc + _=Complex.exp (conj (offset e))*(∫g, (g k:ℂ)* + Complex.exp (∑j, (-I*conj (e j))*(g j:ℂ)) ∂GaussianFourier.law κ) := by + rw [←integral_const_mul] + congr 1 + funext g + rw [conj_wave] + ring + _=(-I*conj (e k))*Complex.exp (conj (offset e)+∑j, (-I*conj (e j))^2/2) := by + rw [GaussianFourier.integral_coord_exp_sum,Complex.exp_add] + ring + _=_ := by + rw [conjugate_exponent] + congr 1 + norm_cast + +theorem inner_vector_fieldVector (e d : Mode κ) : + ⟪vector e,fieldVector d⟫_ℂ= + (-I)*(Real.exp (-‖e‖^2/2):ℂ)*⟪e,d⟫_ℂ := by + classical + rw [L2.inner_def] + calc + _=(∫g, conj (wave e g)*linearField d g ∂GaussianFourier.law κ) := by + apply integral_congr_ae + filter_upwards [vector_ae e,fieldVector_ae d] with g he hd + rw [RCLike.inner_apply',he,hd] + _=∑k, d k*(∫g, conj (wave e g)*(g k:ℂ) ∂GaussianFourier.law κ) := by + simp only [linearField,Finset.mul_sum] + have hi (k : κ) : Integrable (fun g => conj (wave e g)*(d k*(g k:ℂ))) (GaussianFourier.law κ) := by + convert (integrable_wave_coord e k).const_mul (d k) using 1 + funext g + ring + rw [integral_finsetSum Finset.univ (fun k hk => hi k)] + apply Finset.sum_congr rfl + intro k hk + rw [←integral_const_mul] + congr 1 + funext g + ring + _=_ := by + simp only [integral_wave_coord,PiLp.inner_apply,RCLike.inner_apply',Finset.mul_sum] + apply Finset.sum_congr rfl + intro k hk + ring + + + +theorem gaussianUnitary_creationVacuum (d : Mode κ) : + (gaussianUnitary (κ := κ)) (creationVacuum (E := Mode κ) d)=fieldVector d := by + apply (gaussianUnitary (κ := κ)).symm.injective + rw [LinearIsometryEquiv.symm_apply_apply] + apply CoherentFock.eq_of_inner_coherent + intro e + apply (starRingEnd ℂ).injective + simp only [inner_conj_symm] + have hm := (gaussianUnitary (κ := κ)).inner_map_map (coherent e) + ((gaussianUnitary (κ := κ)).symm (fieldVector d)) + simp only [LinearIsometryEquiv.apply_symm_apply,gaussianUnitary_coherent] at hm + rw [←hm,inner_vector_fieldVector] + simp only [creationVacuum,inner_smul_right,inner_coherent_oneParticle,mul_assoc] + + + +theorem norm_fieldVector (d : Mode κ) : ‖fieldVector d‖=‖d‖ := by + rw [←gaussianUnitary_creationVacuum] + exact ((gaussianUnitary (κ := κ)).norm_map _).trans (norm_creationVacuum d) + +theorem inner_fieldVector (d e : Mode κ) : ⟪fieldVector d,fieldVector e⟫_ℂ=⟪d,e⟫_ℂ := by + rw [←gaussianUnitary_creationVacuum,←gaussianUnitary_creationVacuum, + (gaussianUnitary (κ := κ)).inner_map_map] + exact creationEmbedding.inner_map_map d e + +end GaussianCoherent +namespace BoundedSeed +open MeasureTheory Filter +open scoped Topology + + + +def truncate (n : ℕ) (x : ℝ) : ℝ := ((n:ℝ)+1)*Real.sin (x/((n:ℝ)+1)) + +lemma scale_pos (n : ℕ) : 0<(n:ℝ)+1 := by positivity + +@[simp] theorem truncate_neg (n : ℕ) (x : ℝ) : truncate n (-x)= -truncate n x := by + simp only [truncate,neg_div,Real.sin_neg,mul_neg] + +theorem truncate_bounded (n : ℕ) (x : ℝ) : |truncate n x|≤(n:ℝ)+1 := by + rw [truncate,abs_mul,abs_of_pos (scale_pos n)] + exact (mul_le_mul_of_nonneg_left (Real.abs_sin_le_one _) (scale_pos n).le).trans_eq (mul_one _) + +theorem truncate_dominated (n : ℕ) (x : ℝ) : |truncate n x|≤|x| := by + rw [truncate,abs_mul,abs_of_pos (scale_pos n)] + calc + _≤((n:ℝ)+1)*|x/((n:ℝ)+1)| := + mul_le_mul_of_nonneg_left Real.abs_sin_le_abs (scale_pos n).le + _=|x| := by rw [abs_div,abs_of_pos (scale_pos n)]; field_simp + +theorem truncate_eq_sinc (n : ℕ) (x : ℝ) : + truncate n x=x*Real.sinc (x/((n:ℝ)+1)) := by + by_cases hx : x=0 + · simp [hx,truncate] + rw [Real.sinc_of_ne_zero (div_ne_zero hx (scale_pos n).ne')] + unfold truncate + field_simp + +theorem tendsto_truncate (x : ℝ) : Tendsto (fun n : ℕ => truncate n x) atTop (𝓝 x) := by + have ht : Tendsto (fun n : ℕ => x/((n:ℝ)+1)) atTop (𝓝 0) := by + simpa only [mul_zero,mul_one_div] using + (tendsto_const_nhds.mul (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)) : + Tendsto (fun n : ℕ => x*(1/((n:ℝ)+1))) atTop (𝓝 (x*0))) + have hh := (Real.continuous_sinc.continuousAt.tendsto.comp ht).const_mul x + simpa only [Function.comp_apply,Real.sinc_zero,mul_one,←truncate_eq_sinc] using hh + +theorem contDiff_truncate (n : ℕ) : ContDiff ℝ ⊤ (truncate n) := by + unfold truncate + fun_prop + +variable {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + +theorem memLp_truncate {p : ENNReal} {f : Ω → ℝ} (hf : MemLp f p μ) (n : ℕ) : + MemLp (fun ω => truncate n (f ω)) p μ := by + apply hf.mono ((contDiff_truncate n).continuous.comp_aestronglyMeasurable hf.aestronglyMeasurable) + exact Filter.Eventually.of_forall fun ω => by + simpa only [Real.norm_eq_abs] using truncate_dominated n (f ω) + + + +theorem tendsto_error_moment {k : ℕ} (hk : k≠0) {f : Ω → ℝ} (hf : MemLp f k μ) : + Tendsto (fun n : ℕ => ∫ω, |truncate n (f ω)-f ω|^k ∂μ) atTop (𝓝 0) := by + have hm (n : ℕ) : AEStronglyMeasurable (fun ω => |truncate n (f ω)-f ω|^k) μ := by + have hc : Continuous (fun x : ℝ => |truncate n x-x|^k) := by + exact ((contDiff_truncate n).continuous.sub continuous_id).abs.pow k + exact hc.comp_aestronglyMeasurable hf.aestronglyMeasurable + have hi : Integrable (fun ω => (2:ℝ)^k*‖f ω‖^k) μ := + (hf.integrable_norm_pow hk).const_mul _ + have hb (n : ℕ) : ∀ᵐ ω ∂μ, ‖|truncate n (f ω)-f ω|^k‖≤(2:ℝ)^k*‖f ω‖^k := by + apply Filter.Eventually.of_forall + intro ω + rw [Real.norm_eq_abs,abs_of_nonneg (pow_nonneg (abs_nonneg _) _)] + calc + _≤(2*|f ω|)^k := by + apply pow_le_pow_left₀ (abs_nonneg _) + calc + |truncate n (f ω)-f ω|≤|truncate n (f ω)|+|f ω| := abs_sub _ _ + _≤2*|f ω| := by linarith [truncate_dominated n (f ω)] + _=_ := by rw [mul_pow,Real.norm_eq_abs] + have hl : ∀ᵐ ω ∂μ, Tendsto (fun n : ℕ => |truncate n (f ω)-f ω|^k) atTop (𝓝 (0:ℝ)) := by + apply Filter.Eventually.of_forall + intro ω + simpa only [sub_self,abs_zero,zero_pow hk] using + (((tendsto_truncate (f ω)).sub (tendsto_const_nhds : Tendsto (fun _ : ℕ => f ω) atTop (𝓝 (f ω)))).abs.pow k) + simpa only [integral_zero] using + tendsto_integral_of_dominated_convergence (fun ω => (2:ℝ)^k*‖f ω‖^k) hm hi hb hl + + + +theorem tendsto_gaussian_error_moment (k : ℕ) (hk : k≠0) : + Tendsto (fun n : ℕ => ∫x : ℝ, |truncate n x-x|^k ∂ProbabilityTheory.gaussianReal 0 1) + atTop (𝓝 0) := + tendsto_error_moment hk (ProbabilityTheory.memLp_id_gaussianReal' k (by simp)) + +end BoundedSeed + +namespace TrigLp +open MeasureTheory +open scoped Topology +variable {Ω : Type*} [MeasurableSpace Ω] {κ : Type*} [Fintype κ] +variable (μ : Measure Ω) (ν : Measure (κ → ℝ)) [IsFiniteMeasure ν] +variable (X : Ω → κ → ℝ) (hX : MeasurePreserving X μ ν) +variable (cols : κ → Lp ℝ 2 μ) +variable (hcols : ∀k, (cols k : Ω → ℝ)=ᵐ[μ] fun ω => X ω k) +include hcols + + + +theorem pullback_sine (a : κ → ℝ) : + Lp.compMeasurePreserving X hX (FourierDensity.sineVector ν a)= + sine μ (linear μ a cols) := by + apply Lp.ext + have hc := ae_all_iff.mpr hcols + have hs := hX.quasiMeasurePreserving.ae (FourierDensity.sineVector_ae ν a) + filter_upwards [Lp.coeFn_compMeasurePreserving (FourierDensity.sineVector ν a) hX, + hs,sine_ae μ (linear μ a cols),linear_ae μ a cols,hc] with ω h1 h2 h3 h4 h5 + rw [h1,h3,h4] + change FourierDensity.sineVector ν a (X ω)=Real.sin (∑k, a k*cols k ω) + rw [h2] + unfold FourierDensity.sine + congr 1 + exact Finset.sum_congr rfl (fun k hk => by rw [h5 k]) + + + +theorem pullback_polynomial (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + Lp.compMeasurePreservingₗ ℝ X hX (∑a∈s, b a • FourierDensity.sineVector ν a)= + polynomial μ s b cols := by + simp only [map_sum,map_smul,polynomial] + apply Finset.sum_congr rfl + intro a ha + congr 1 + exact pullback_sine μ ν X hX cols hcols a + + + +theorem exists_local_approx + (hν : MeasurePreserving (fun g : κ → ℝ => -g) ν ν) + (f : Lp ℝ 2 ν) (hf : ∀ᵐ g ∂ν, f (-g)= -f g) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, + ‖polynomial μ s b cols-Lp.compMeasurePreserving X hX f‖<ε := by + obtain ⟨s,b,hb⟩ := FourierDensity.exists_odd_sine_approx ν hν f hf hε + refine ⟨s,b,?_⟩ + rw [←pullback_polynomial μ ν X hX cols hcols] + change ‖Lp.compMeasurePreservingₗ ℝ X hX (∑a∈s, b a • FourierDensity.sineVector ν a)- + Lp.compMeasurePreservingₗ ℝ X hX f‖<ε + rw [←map_sub] + change ‖Lp.compMeasurePreserving X hX ((∑a∈s, b a • FourierDensity.sineVector ν a)-f)‖<ε + rwa [Lp.norm_compMeasurePreserving] + + + +theorem exists_robust_local_approx + (hν : MeasurePreserving (fun g : κ → ℝ => -g) ν ν) + (f : Lp ℝ 2 ν) (hf : ∀ᵐ g ∂ν, f (-g)= -f g) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, ∃δ : ℝ, 0<δ ∧ + ∀g : κ → Lp ℝ 2 μ, (∀k, ‖g k-cols k‖<δ) → + ‖polynomial μ s b g-Lp.compMeasurePreserving X hX f‖<ε := by + obtain ⟨s,b,hb⟩ := exists_local_approx μ ν X hX cols hcols hν f hf (half_pos hε) + have hc := (polynomial_continuous μ s b).continuousAt (x := cols) + obtain ⟨δ,hδ,hdb⟩ := Metric.continuousAt_iff.mp hc (ε/2) (half_pos hε) + refine ⟨s,b,δ,hδ,?_⟩ + intro g hg + have hd : dist g cols<δ := (dist_pi_lt_iff hδ).mpr (fun k => by + simpa only [dist_eq_norm] using hg k) + have ho := hdb hd + calc + _ ≤ ‖polynomial μ s b g-polynomial μ s b cols‖+ + ‖polynomial μ s b cols-Lp.compMeasurePreserving X hX f‖ := norm_sub_le_norm_sub_add_norm_sub _ _ _ + _ < ε/2+ε/2 := add_lt_add (by simpa only [dist_eq_norm] using ho) hb + _ = ε := add_halves ε + +end TrigLp + +namespace FourierDensity +variable {κ : Type*} [Fintype κ] + +@[simp] theorem sineOutput_odd (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (g : κ → ℝ) : + sineOutput s b (-g)= -sineOutput s b g := by + simp only [sineOutput,sinePolynomial_odd,mul_neg,Real.sin_neg] + +theorem sineOutput_bounded (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (g : κ → ℝ) : + |sineOutput s b g|≤1 := Real.abs_sin_le_one _ + +theorem sineOutput_contDiff (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + ContDiff ℝ ⊤ (sineOutput s b) := by + unfold sineOutput + exact Real.contDiff_sin.comp (contDiff_const.mul (sinePolynomial_contDiff s b)) +end FourierDensity + +namespace TrigLp +open MeasureTheory +open scoped Topology +variable {Ω : Type*} [MeasurableSpace Ω] {κ : Type*} [Fintype κ] (μ : Measure Ω) + + + +def readout (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (g : κ → Lp ℝ 2 μ) : Lp ℝ 2 μ := + sine μ ((2:ℝ) • polynomial μ s b g) + +theorem readout_ae (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (g : κ → Lp ℝ 2 μ) : + (readout μ s b g : Ω → ℝ)=ᵐ[μ] + fun ω => FourierDensity.sineOutput s b (fun k => g k ω) := by + filter_upwards [sine_ae μ ((2:ℝ) • polynomial μ s b g), + Lp.coeFn_smul (2:ℝ) (polynomial μ s b g),polynomial_ae μ s b g] with ω h1 h2 h3 + change sine μ ((2:ℝ) • polynomial μ s b g) ω= _ + rw [h1,h2] + simp only [Pi.smul_apply,smul_eq_mul] + rw [h3] + rfl + +theorem readout_norm_sub_le (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) + (g h : κ → Lp ℝ 2 μ) : + ‖readout μ s b g-readout μ s b h‖≤2*‖polynomial μ s b g-polynomial μ s b h‖ := by + have hh := sine_norm_sub_le μ ((2:ℝ) • polynomial μ s b g) ((2:ℝ) • polynomial μ s b h) + simpa only [readout,←smul_sub,norm_smul,Real.norm_of_nonneg (by norm_num : (0:ℝ)≤2)] using hh + +theorem readout_continuous (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + Continuous (readout μ s b) := by + exact (sine_continuous μ).comp ((polynomial_continuous μ s b).const_smul (2:ℝ)) + +variable (ν : Measure (κ → ℝ)) [IsFiniteMeasure ν] +variable (X : Ω → κ → ℝ) (hX : MeasurePreserving X μ ν) +variable (cols : κ → Lp ℝ 2 μ) +variable (hcols : ∀k, (cols k : Ω → ℝ)=ᵐ[μ] fun ω => X ω k) +include hcols + + + +theorem pullback_readout (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) : + Lp.compMeasurePreserving X hX (FourierDensity.sineOutputVector ν s b)= + readout μ s b cols := by + apply Lp.ext + have hc := ae_all_iff.mpr hcols + have hr := hX.quasiMeasurePreserving.ae (FourierDensity.sineOutputVector_ae ν s b) + filter_upwards [Lp.coeFn_compMeasurePreserving (FourierDensity.sineOutputVector ν s b) hX, + hr,readout_ae μ s b cols,hc] with ω h1 h2 h3 h4 + rw [h1,h3] + change FourierDensity.sineOutputVector ν s b (X ω)= _ + rw [h2] + congr 1 + exact funext (fun k => (h4 k).symm) + + + +theorem exists_robust_readout + (hν : MeasurePreserving (fun g : κ → ℝ => -g) ν ν) + (f : Lp ℝ 2 ν) (hf : ∀ᵐ g ∂ν, f (-g)= -f g) + (hb : ∀ᵐ g ∂ν, |f g|≤1) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, ∃δ : ℝ, 0<δ ∧ + ∀g : κ → Lp ℝ 2 μ, (∀k, ‖g k-cols k‖<δ) → + ‖readout μ s b g-Lp.compMeasurePreserving X hX f‖<ε := by + obtain ⟨s,b,ha⟩ := FourierDensity.exists_sine_angle_approx ν hν f hf hb (half_pos hε) + have ha' : ‖readout μ s b cols-Lp.compMeasurePreserving X hX f‖<ε/2 := by + rw [←pullback_readout μ ν X hX cols hcols] + rw [←map_sub,Lp.norm_compMeasurePreserving] + exact ha + have hc := (readout_continuous μ s b).continuousAt (x := cols) + obtain ⟨δ,hδ,hdb⟩ := Metric.continuousAt_iff.mp hc (ε/2) (half_pos hε) + refine ⟨s,b,δ,hδ,?_⟩ + intro g hg + have hd : dist g cols<δ := (dist_pi_lt_iff hδ).mpr (fun k => by + simpa only [dist_eq_norm] using hg k) + calc + _ ≤ ‖readout μ s b g-readout μ s b cols‖+ + ‖readout μ s b cols-Lp.compMeasurePreserving X hX f‖ := norm_sub_le_norm_sub_add_norm_sub _ _ _ + _ < ε/2+ε/2 := add_lt_add (by simpa only [dist_eq_norm] using hdb hd) ha' + _ = ε := add_halves ε + +end TrigLp + +namespace TrigLp +open MeasureTheory +open scoped Topology +variable {Ω : Type*} [MeasurableSpace Ω] {κ : Type*} [Fintype κ] +variable (μ : Measure Ω) + + + +def inputMap (cols : κ → Lp ℝ 2 μ) (ω : Ω) : κ → ℝ := fun k => cols k ω + +omit [Fintype κ] in +theorem measurable_inputMap (cols : κ → Lp ℝ 2 μ) : Measurable (inputMap μ cols) := + Measurable.of_eval (fun k => (Lp.stronglyMeasurable (cols k)).measurable) + +def inputLaw (cols : κ → Lp ℝ 2 μ) : Measure (κ → ℝ) := μ.map (inputMap μ cols) + +instance inputLaw_finite [IsFiniteMeasure μ] (cols : κ → Lp ℝ 2 μ) : + IsFiniteMeasure (inputLaw μ cols) := inferInstanceAs (IsFiniteMeasure (μ.map _)) + +omit [Fintype κ] in +theorem inputMap_preserving (cols : κ → Lp ℝ 2 μ) : + MeasurePreserving (inputMap μ cols) μ (inputLaw μ cols) := + (measurable_inputMap μ cols).measurePreserving μ + + + +theorem inputLaw_symmetric (τ : Ω → Ω) (hτ : MeasurePreserving τ μ μ) + (cols : κ → Lp ℝ 2 μ) (hc : ∀k, ∀ᵐ ω ∂μ, cols k (τ ω)= -cols k ω) : + MeasurePreserving (fun g : κ → ℝ => -g) (inputLaw μ cols) (inputLaw μ cols) := by + refine ⟨measurable_neg,?_⟩ + change (μ.map (inputMap μ cols)).map (fun g => -g)=μ.map (inputMap μ cols) + rw [Measure.map_map measurable_neg (measurable_inputMap μ cols)] + have he : (fun g : κ → ℝ => -g) ∘ inputMap μ cols =ᵐ[μ] inputMap μ cols ∘ τ := by + filter_upwards [ae_all_iff.mpr hc] with ω hω + exact funext fun k => (hω k).symm + rw [Measure.map_congr he,←Measure.map_map (measurable_inputMap μ cols) hτ.measurable,hτ.map_eq] + + +theorem polynomial_odd (τ : Ω → Ω) (hτ : MeasurePreserving τ μ μ) + (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (cols : κ → Lp ℝ 2 μ) + (hc : ∀k, ∀ᵐ ω ∂μ, cols k (τ ω)= -cols k ω) : + ∀ᵐ ω ∂μ, polynomial μ s b cols (τ ω)= -polynomial μ s b cols ω := by + have ht := hτ.quasiMeasurePreserving.ae (polynomial_ae μ s b cols) + filter_upwards [polynomial_ae μ s b cols,ht,ae_all_iff.mpr hc] with ω h1 h2 h3 + rw [h1,h2] + have he : (fun k => cols k (τ ω))= -(fun k => cols k ω) := funext h3 + rw [he,FourierDensity.sinePolynomial_odd] + +theorem readout_odd (τ : Ω → Ω) (hτ : MeasurePreserving τ μ μ) + (s : Finset (κ → ℝ)) (b : (κ → ℝ) → ℝ) (cols : κ → Lp ℝ 2 μ) + (hc : ∀k, ∀ᵐ ω ∂μ, cols k (τ ω)= -cols k ω) : + ∀ᵐ ω ∂μ, readout μ s b cols (τ ω)= -readout μ s b cols ω := by + have ht := hτ.quasiMeasurePreserving.ae (readout_ae μ s b cols) + filter_upwards [readout_ae μ s b cols,ht,ae_all_iff.mpr hc] with ω h1 h2 h3 + rw [h1,h2] + have he : (fun k => cols k (τ ω))= -(fun k => cols k ω) := funext h3 + rw [he,FourierDensity.sineOutput_odd] + +variable [IsFiniteMeasure μ] + + + +theorem exists_robust_odd_operation (τ : Ω → Ω) (hτ : MeasurePreserving τ μ μ) + (cols : κ → Lp ℝ 2 μ) (hc : ∀k, ∀ᵐ ω ∂μ, cols k (τ ω)= -cols k ω) + (φ : (κ → ℝ) → ℝ) (hφ : MemLp φ 2 (inputLaw μ cols)) + (ho : ∀x, φ (-x)= -φ x) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, ∃δ : ℝ, 0<δ ∧ + ∀g : κ → Lp ℝ 2 μ, (∀k, ‖g k-cols k‖<δ) → + ‖polynomial μ s b g-(hφ.comp_measurePreserving (inputMap_preserving μ cols)).toLp + (φ ∘ inputMap μ cols)‖<ε := by + let ν := inputLaw μ cols + let f : Lp ℝ 2 ν := hφ.toLp φ + have hν := inputLaw_symmetric μ τ hτ cols hc + have hf : ∀ᵐ x ∂ν, f (-x)= -f x := by + have hn := hν.quasiMeasurePreserving.ae hφ.coeFn_toLp + filter_upwards [hφ.coeFn_toLp,hn] with x hx hnx + change f x=φ x at hx + change f (-x)=φ (-x) at hnx + rw [hx,hnx,ho] + have hcols (k : κ) : (cols k : Ω → ℝ)=ᵐ[μ] fun ω => inputMap μ cols ω k := + Filter.Eventually.of_forall fun _ => rfl + obtain ⟨s,b,δ,hδ,hd⟩ := exists_robust_local_approx μ ν (inputMap μ cols) + (inputMap_preserving μ cols) cols hcols hν f hf hε + refine ⟨s,b,δ,hδ,?_⟩ + intro g hg + exact hd g hg + +end TrigLp + +namespace TrigLp +open MeasureTheory +open scoped Topology +variable {Ω : Type*} [MeasurableSpace Ω] {κ : Type*} [Fintype κ] +variable (μ : Measure Ω) [IsFiniteMeasure μ] + + + +theorem exists_robust_odd_readout (τ : Ω → Ω) (hτ : MeasurePreserving τ μ μ) + (cols : κ → Lp ℝ 2 μ) (hc : ∀k, ∀ᵐ ω ∂μ, cols k (τ ω)= -cols k ω) + (φ : (κ → ℝ) → ℝ) (hφ : MemLp φ 2 (inputLaw μ cols)) + (ho : ∀x, φ (-x)= -φ x) (hb : ∀x, |φ x|≤1) {ε : ℝ} (hε : 0<ε) : + ∃s : Finset (κ → ℝ), ∃b : (κ → ℝ) → ℝ, ∃δ : ℝ, 0<δ ∧ + ∀g : κ → Lp ℝ 2 μ, (∀k, ‖g k-cols k‖<δ) → + ‖readout μ s b g-(hφ.comp_measurePreserving (inputMap_preserving μ cols)).toLp + (φ ∘ inputMap μ cols)‖<ε := by + let ν := inputLaw μ cols + let f : Lp ℝ 2 ν := hφ.toLp φ + have hν := inputLaw_symmetric μ τ hτ cols hc + have hf : ∀ᵐ x ∂ν, f (-x)= -f x := by + have hn := hν.quasiMeasurePreserving.ae hφ.coeFn_toLp + filter_upwards [hφ.coeFn_toLp,hn] with x hx hnx + change f x=φ x at hx + change f (-x)=φ (-x) at hnx + rw [hx,hnx,ho] + have hb' : ∀ᵐ x ∂ν, |f x|≤1 := by + filter_upwards [hφ.coeFn_toLp] with x hx + change f x=φ x at hx + rw [hx] + exact hb x + have hcols (k : κ) : (cols k : Ω → ℝ)=ᵐ[μ] fun ω => inputMap μ cols ω k := + Filter.Eventually.of_forall fun _ => rfl + obtain ⟨s,b,δ,hδ,hd⟩ := exists_robust_readout μ ν (inputMap μ cols) + (inputMap_preserving μ cols) cols hcols hν f hf hb' hε + exact ⟨s,b,δ,hδ,hd⟩ + +end TrigLp + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Space.lean b/lean/OAI/Probability/ParisiFinite/Space.lean new file mode 100644 index 0000000000000000000000000000000000000000..27c2bca2fb1cc6f9c15862caa7f65873c54d4b10 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Space.lean @@ -0,0 +1,710 @@ +import Mathlib +import OAI.Probability.ParisiFinite.PacketRegular + +namespace OAI + +/-! Space. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +namespace HilbertPair +variable {E F G K : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] + [NormedAddCommGroup K] [InnerProductSpace ℂ K] + +abbrev Space (E F : Type*) := WithLp 2 (E × F) + +def inl : E →ₗᵢ[ℂ] Space E F := LinearMap.isometryOfInner + ((WithLp.linearEquiv 2 ℂ (E × F)).symm.toLinearMap.comp (LinearMap.inl ℂ E F)) + (by intro x y; simp) + +def inr : F →ₗᵢ[ℂ] Space E F := LinearMap.isometryOfInner + ((WithLp.linearEquiv 2 ℂ (E × F)).symm.toLinearMap.comp (LinearMap.inr ℂ E F)) + (by intro x y; simp) + +@[simp] theorem inl_apply (x : E) : (inl x : Space E F)=WithLp.toLp 2 (x,0) := rfl +@[simp] theorem inr_apply (x : F) : (inr x : Space E F)=WithLp.toLp 2 (0,x) := rfl +@[simp] theorem inl_inner_inr (x : E) (y : F) : ⟪(inl x:Space E F),inr y⟫_ℂ=0 := by simp +@[simp] theorem inr_inner_inl (y : F) (x : E) : ⟪(inr y:Space E F),inl x⟫_ℂ=0 := by simp + +@[simp] theorem inl_add_inr (x : Space E F) : inl x.fst + inr x.snd=x := by + apply WithLp.ofLp_injective 2 + change (x.ofLp.1+0,0+x.ofLp.2)=x.ofLp + simp only [add_zero,zero_add,Prod.mk.eta] + +def map (T : E →ₗᵢ[ℂ] G) (U : F →ₗᵢ[ℂ] K) : Space E F →ₗᵢ[ℂ] Space G K := + LinearMap.isometryOfInner + (((WithLp.linearEquiv 2 ℂ (G × K)).symm.toLinearMap.comp + (T.toLinearMap.prodMap U.toLinearMap)).comp (WithLp.linearEquiv 2 ℂ (E × F)).toLinearMap) + (by intro x y; simp) + +@[simp] theorem map_apply (T : E →ₗᵢ[ℂ] G) (U : F →ₗᵢ[ℂ] K) (x : Space E F) : + map T U x=WithLp.toLp 2 (T x.fst,U x.snd) := rfl + +@[simp] theorem map_inl (T : E →ₗᵢ[ℂ] G) (U : F →ₗᵢ[ℂ] K) (x : E) : + map T U (inl x)=inl (T x) := by simp + +@[simp] theorem map_inr (T : E →ₗᵢ[ℂ] G) (U : F →ₗᵢ[ℂ] K) (x : F) : + map T U (inr x)=inr (U x) := by simp + +def congr (T : E ≃ₗᵢ[ℂ] G) (U : F ≃ₗᵢ[ℂ] K) : Space E F ≃ₗᵢ[ℂ] Space G K where + toFun := map T.toLinearIsometry U.toLinearIsometry + invFun := map T.symm.toLinearIsometry U.symm.toLinearIsometry + left_inv x := by + apply WithLp.ofLp_injective 2 + change (T.symm (T x.ofLp.1),U.symm (U x.ofLp.2))=x.ofLp + rw [T.symm_apply_apply,U.symm_apply_apply] + right_inv x := by + apply WithLp.ofLp_injective 2 + change (T (T.symm x.ofLp.1),U (U.symm x.ofLp.2))=x.ofLp + rw [T.apply_symm_apply,U.apply_symm_apply] + map_add' := (map T.toLinearIsometry U.toLinearIsometry).map_add + map_smul' := (map T.toLinearIsometry U.toLinearIsometry).map_smul + norm_map' := (map T.toLinearIsometry U.toLinearIsometry).norm_map + +@[simp] theorem congr_apply (T : E ≃ₗᵢ[ℂ] G) (U : F ≃ₗᵢ[ℂ] K) (x : Space E F) : + congr T U x=WithLp.toLp 2 (T x.fst,U x.snd) := rfl + +end HilbertPair + + + +namespace SeededTree +open PointedTree CoherentFock RootSpin + +abbrev External := EuclideanSpace ℂ (Fin 2) +abbrev gaussianNode (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℂ E] : PointedData where + Carrier := SpinSpace E + vac := vacuum E + norm_vac := norm_vacuum + +abbrev base : PointedData := gaussianNode External +abbrev next (H : PointedData) : PointedData := gaussianNode (HilbertPair.Space External (centered H)) + +abbrev centeredData (A : PointedData) : HilbertData where + Carrier := centered A + +abbrev pairData (A B : HilbertData) : HilbertData where + Carrier := HilbertPair.Space A B + +abbrev nextTop (H : HilbertData) : HilbertData := + pairData { Carrier := External } (centeredData (gaussianNode H)) + +@[reducible] def topData : ℕ → HilbertData + | 0 => { Carrier := External } + | n+1 => nextTop (topData n) +abbrev TopMode (n : ℕ) := (topData n).Carrier +abbrev level (n : ℕ) : PointedData := gaussianNode (TopMode n) +abbrev Level (n : ℕ) : Type := (level n).Carrier +abbrev Mode (n : ℕ) := centered (level n) +def vac (n : ℕ) : Level n := (level n).vac +@[simp] theorem norm_vac (n : ℕ) : ‖vac n‖=1 := (level n).norm_vac + + +def gaussianMap {E F : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] (T : E →ₗᵢ[ℂ] F) : + PointedMap (gaussianNode E) (gaussianNode F) where + toLinearIsometry := spinMap (gammaEmbedding T) + map_vac := by ext i; simp [vacuum_apply] + +def nextMap {H K : PointedData} (T : PointedMap H K) : PointedMap (next H) (next K) := + gaussianMap (HilbertPair.map LinearIsometry.id (centeredMap T)) + +def empty : (n : ℕ) → PointedMap (level n) (level (n+1)) + | 0 => gaussianMap HilbertPair.inl + | n+1 => nextMap (empty n) + +@[simp] theorem empty_vac (n : ℕ) : (empty n).toLinearIsometry (vac n)=vac (n+1) := + (empty n).map_vac + +def topStep : (n : ℕ) → TopMode n →ₗᵢ[ℂ] TopMode (n+1) + | 0 => HilbertPair.inl + | n+1 => HilbertPair.map LinearIsometry.id (centeredMap (empty n)) + +@[simp] theorem empty_apply (n : ℕ) (x : Level n) : + (empty n).toLinearIsometry x=spinMap (gammaEmbedding (topStep n)) x := by cases n <;> rfl + +def external : (n : ℕ) → External →ₗᵢ[ℂ] TopMode n + | 0 => LinearIsometry.id + | _+1 => HilbertPair.inl + +def endogenous (n : ℕ) : Mode n →ₗᵢ[ℂ] TopMode (n+1) := HilbertPair.inr + +@[simp] theorem topStep_external (n : ℕ) (e : External) : + topStep n (external n e)=external (n+1) e := by + cases n with + | zero => rfl + | succ n => exact HilbertPair.map_inl LinearIsometry.id (centeredMap (empty n)) e + +@[simp] theorem topStep_endogenous (n : ℕ) (d : Mode n) : + topStep (n+1) (endogenous n d)=endogenous (n+1) (centeredMap (empty n) d) := by + exact HilbertPair.map_inr LinearIsometry.id (centeredMap (empty n)) d + +@[simp] theorem external_inner_endogenous (n : ℕ) (e : External) (d : Mode n) : + ⟪external (n+1) e,endogenous n d⟫_ℂ=0 := HilbertPair.inl_inner_inr e d + + +def gaussianSymmetry {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (T : E ≃ₗᵢ[ℂ] E) (hT : Function.Involutive T) : Symmetry (gaussianNode E) where + op := (spinEquiv (secondQuantization T)).trans (SpinOperators.actEquiv X X_unitary) + invariant := by + change SpinOperators.act X (spinEquiv (secondQuantization T) (vacuum E))=vacuum E + ext i + fin_cases i <;> simp [vacuum_apply,secondQuantization,X] + square x := by + change SpinOperators.act X (spinMap (gammaEmbedding T.toLinearIsometry) + (SpinOperators.act X (spinMap (gammaEmbedding T.toLinearIsometry) x)))=x + apply spinFlip_twice + intro y + have hc : T.toLinearIsometry.comp T.toLinearIsometry=LinearIsometry.id := by + ext v + exact hT v + have h := congrArg (fun A => A y) (Gamma_comp T.toLinearIsometry T.toLinearIsometry) + change Gamma T.toLinearIsometry (Gamma T.toLinearIsometry y)=y + simpa [hc] using h + +def externalFlip : External ≃ₗᵢ[ℂ] External := LinearIsometryEquiv.neg ℂ +@[simp] theorem externalFlip_apply (e : External) : externalFlip e=-e := rfl + +def nextSymmetry {H : PointedData} (S : Symmetry H) : Symmetry (next H) := + gaussianSymmetry (HilbertPair.congr externalFlip S.centered) (by + intro x + apply WithLp.ofLp_injective 2 + change (-(-x.ofLp.1),S.centered (S.centered x.ofLp.2))=x.ofLp + rw [neg_neg,S.centered_square]) + +def symmetry : (n : ℕ) → Symmetry (level n) + | 0 => gaussianSymmetry externalFlip (fun e => neg_neg e) + | n+1 => nextSymmetry (symmetry n) + +def topFlip : (n : ℕ) → TopMode n ≃ₗᵢ[ℂ] TopMode n + | 0 => externalFlip + | n+1 => HilbertPair.congr externalFlip (symmetry n).centered + +@[simp] theorem symmetry_apply (n : ℕ) (x : Level n) : (symmetry n).op x= + SpinOperators.act X (spinMap (gammaEmbedding (topFlip n).toLinearIsometry) x) := by cases n <;> rfl + +@[simp] theorem topFlip_external (n : ℕ) (e : External) : + topFlip n (external n e)=-external n e := by + cases n with + | zero => rfl + | succ n => + change HilbertPair.map externalFlip.toLinearIsometry (symmetry n).centered.toLinearIsometry + (HilbertPair.inl e)=-(HilbertPair.inl e : TopMode (n+1)) + rw [HilbertPair.map_inl] + change (HilbertPair.inl (-e) : TopMode (n+1))=-HilbertPair.inl e + exact (HilbertPair.inl : External →ₗᵢ[ℂ] TopMode (n+1)).map_neg e + +@[simp] theorem topFlip_endogenous (n : ℕ) (d : Mode n) : + topFlip (n+1) (endogenous n d)=endogenous n ((symmetry n).centered d) := by + change HilbertPair.map externalFlip.toLinearIsometry (symmetry n).centered.toLinearIsometry + (HilbertPair.inr d)=HilbertPair.inr ((symmetry n).centered d) + exact HilbertPair.map_inr _ _ d + +@[simp] theorem symmetry_vac (n : ℕ) : (symmetry n).op (vac n)=vac n := (symmetry n).invariant + +def root (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) : Level n →L[ℂ] Level n := + SpinOperators.act A +@[simp] theorem root_apply (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (x : Level n) : + root n A x=SpinOperators.act A x := by cases n <;> rfl + +@[simp] theorem symmetry_rootZ (n : ℕ) (x : Level n) : + (symmetry n).op (root n Z x)=-root n Z ((symmetry n).op x) := by + rw [SeededTree.symmetry_apply,SeededTree.symmetry_apply] + change SpinOperators.act X (spinMap (gammaEmbedding (topFlip n).toLinearIsometry) (SpinOperators.act Z x))= + -SpinOperators.act Z (SpinOperators.act X (spinMap (gammaEmbedding (topFlip n).toLinearIsometry) x)) + exact flipMap_rootZ (gammaEmbedding (topFlip n).toLinearIsometry) x + +@[simp] theorem symmetry_rootR (n : ℕ) (t : ℝ) (x : Level n) : + (symmetry n).op (root n (R t) x)=root n (R t) ((symmetry n).op x) := by + rw [SeededTree.symmetry_apply,SeededTree.symmetry_apply] + change SpinOperators.act X (spinMap (gammaEmbedding (topFlip n).toLinearIsometry) (SpinOperators.act (R t) x))= + SpinOperators.act (R t) (SpinOperators.act X (spinMap (gammaEmbedding (topFlip n).toLinearIsometry) x)) + exact flipMap_rootR (gammaEmbedding (topFlip n).toLinearIsometry) t x + +def rootEquiv (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) : Level n ≃ₗᵢ[ℂ] Level n := + SpinOperators.actEquiv A hA +@[simp] theorem rootEquiv_apply (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) (x : Level n) : + rootEquiv n A hA x=root n A x := by cases n <;> rfl +@[simp] theorem norm_rootZ (n : ℕ) (x : Level n) : ‖root n Z x‖=‖x‖ := by + simpa only [rootEquiv_apply] using (rootEquiv n Z Z_unitary).norm_map x + +structure EvenUnitary (n : ℕ) where + op : Level n ≃ₗᵢ[ℂ] Level n + commutes : ∀x, (symmetry n).op (op x)=op ((symmetry n).op x) + +namespace EvenUnitary + +def ident (n : ℕ) : EvenUnitary n where + op := LinearIsometryEquiv.refl ℂ (Level n) + commutes _ := rfl + +def followedBy {n : ℕ} (U V : EvenUnitary n) : EvenUnitary n where + op := U.op.trans V.op + commutes x := by + change (symmetry n).op (V.op (U.op x))=V.op (U.op ((symmetry n).op x)) + rw [V.commutes,U.commutes] + +theorem symm_commutes {n : ℕ} (U : EvenUnitary n) (x : Level n) : + (symmetry n).op (U.op.symm x)=U.op.symm ((symmetry n).op x) := by + apply U.op.injective + rw [← U.commutes,U.op.apply_symm_apply,U.op.apply_symm_apply] + +def insertion {n : ℕ} (U : EvenUnitary n) : Mode n := + ⟨U.op.symm (root n Z (U.op (vac n))),by + apply odd_centered (symmetry n) + rw [U.symm_commutes,symmetry_rootZ,U.commutes,symmetry_vac,map_neg]⟩ +@[simp] theorem insertion_coe {n : ℕ} (U : EvenUnitary n) : + (U.insertion:Level n)=U.op.symm (root n Z (U.op (vac n))) := rfl +@[simp] theorem norm_insertion {n : ℕ} (U : EvenUnitary n) : ‖U.insertion‖=1 := by + change ‖U.op.symm (root n Z (U.op (vac n)))‖=1 + rw [U.op.symm.norm_map,norm_rootZ,U.op.norm_map,norm_vac] +@[simp] theorem insertion_odd {n : ℕ} (U : EvenUnitary n) : + (symmetry n).centered U.insertion=-U.insertion := by + apply Subtype.ext + change (symmetry n).op (U.op.symm (root n Z (U.op (vac n))))=-U.op.symm (root n Z (U.op (vac n))) + rw [U.symm_commutes,symmetry_rootZ,U.commutes,symmetry_vac,map_neg] + +def mixer (n : ℕ) (t : ℝ) : EvenUnitary n where + op := rootEquiv n (R t) (R_unitary t) + commutes x := by simpa only [rootEquiv_apply] using symmetry_rootR n t x + +def pulse (n : ℕ) (d : TopMode n) (hd : topFlip n d=-d) : EvenUnitary n where + op := costEquiv d + commutes x := by + change (symmetry n).op (WZ d x)=WZ d ((symmetry n).op x) + rw [symmetry_apply,symmetry_apply] + change (topFlip n).toLinearIsometry d=-d at hd + rw [spinMap_cost,hd] + exact congrArg (fun A : SpinSpace (TopMode n) →L[ℂ] SpinSpace (TopMode n) => + A (spinMap (gammaEmbedding (topFlip n).toLinearIsometry) x)) (WZ_rootX d).symm + +@[simp] theorem pulse_apply (n : ℕ) (d : TopMode n) (hd : topFlip n d=-d) (x : Level n) : + (pulse n d hd).op x=WZ d x := by cases n <;> rfl + + +def seed (n : ℕ) (a : Fin 2 → ℝ) : EvenUnitary n := + pulse n (external n (WithLp.toLp 2 (fun j => -(a j:ℂ)))) (topFlip_external n _) + +def cost (n : ℕ) (U : EvenUnitary n) (t : ℝ) : EvenUnitary (n+1) := + pulse (n+1) (-(t:ℂ) • endogenous n U.insertion) (by + rw [map_smul,topFlip_endogenous,U.insertion_odd,map_neg,smul_neg,neg_smul]) + +end EvenUnitary +end SeededTree + +namespace SeededTree +open PointedTree CoherentFock RootSpin + +@[simp] theorem root_empty (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (x : Level n) : + (empty n).toLinearIsometry (root n A x)=root (n+1) A ((empty n).toLinearIsometry x) := by + rw [SeededTree.empty_apply,SeededTree.empty_apply] + exact spinMap_root (gammaEmbedding (topStep n)) A x + +@[simp] theorem pulse_empty (n : ℕ) (d : TopMode n) (x : Level n) : + (empty n).toLinearIsometry (WZ d x)=WZ (topStep n d) ((empty n).toLinearIsometry x) := by + rw [SeededTree.empty_apply,SeededTree.empty_apply] + exact spinMap_cost (topStep n) d x + +namespace EvenUnitary + +def Compatible {n : ℕ} (U : SeededTree.EvenUnitary n) (V : SeededTree.EvenUnitary (n+1)) : Prop := + ∀x, (empty n).toLinearIsometry (U.op x)=V.op ((empty n).toLinearIsometry x) + +theorem Compatible.symm_apply {n : ℕ} {U : SeededTree.EvenUnitary n} {V : SeededTree.EvenUnitary (n+1)} + (h : Compatible U V) (x : Level n) : + (empty n).toLinearIsometry (U.op.symm x)=V.op.symm ((empty n).toLinearIsometry x) := by + apply V.op.injective + rw [←h,U.op.apply_symm_apply,V.op.apply_symm_apply] + +theorem Compatible.insertion {n : ℕ} {U : SeededTree.EvenUnitary n} {V : SeededTree.EvenUnitary (n+1)} + (h : Compatible U V) : centeredMap (empty n) U.insertion=V.insertion := by + apply Subtype.ext + change (empty n).toLinearIsometry (U.op.symm (root n Z (U.op (vac n))))= + V.op.symm (root (n+1) Z (V.op (vac (n+1)))) + rw [h.symm_apply,root_empty,h,empty_vac] + +theorem Compatible.followedBy {n : ℕ} {U₀ V₀ : SeededTree.EvenUnitary n} + {U₁ V₁ : SeededTree.EvenUnitary (n+1)} (hU : Compatible U₀ U₁) (hV : Compatible V₀ V₁) : + Compatible (U₀.followedBy V₀) (U₁.followedBy V₁) := by + intro x + change (empty n).toLinearIsometry (V₀.op (U₀.op x))=V₁.op (U₁.op ((empty n).toLinearIsometry x)) + rw [hV,hU] + +theorem compatible_ident (n : ℕ) : Compatible (ident n) (ident (n+1)) := fun _ => rfl + +theorem compatible_mixer (n : ℕ) (t : ℝ) : Compatible (mixer n t) (mixer (n+1) t) := by + intro x + change (empty n).toLinearIsometry (root n (R t) x)=root (n+1) (R t) ((empty n).toLinearIsometry x) + exact root_empty n _ x + +theorem compatible_pulse (n : ℕ) (d : TopMode n) (e : TopMode (n+1)) + (hd : topFlip n d=-d) (he : topFlip (n+1) e=-e) (h : topStep n d=e) : + Compatible (pulse n d hd) (pulse (n+1) e he) := by + intro x + change (empty n).toLinearIsometry (WZ d x)=WZ e ((empty n).toLinearIsometry x) + rw [SeededTree.pulse_empty,h] + +theorem compatible_seed (n : ℕ) (a : Fin 2 → ℝ) : Compatible (seed n a) (seed (n+1) a) := + compatible_pulse n _ _ _ _ (topStep_external n _) + +theorem compatible_cost (n : ℕ) (U : SeededTree.EvenUnitary n) (V : SeededTree.EvenUnitary (n+1)) + (h : Compatible U V) (t : ℝ) : Compatible (cost n U t) (cost (n+1) V t) := by + apply compatible_pulse + rw [map_smul,topStep_endogenous,h.insertion] + + +theorem pulse_insertion (n : ℕ) (U : SeededTree.EvenUnitary n) (d : TopMode n) + (hd : topFlip n d=-d) : (U.followedBy (pulse n d hd)).insertion=U.insertion := by + apply Subtype.ext + change U.op.symm ((costEquiv d).symm (SpinOperators.act Z (costEquiv d (U.op (vac n)))))= + U.op.symm (SpinOperators.act Z (U.op (vac n))) + congr 1 + apply (costEquiv d).injective + simp only [LinearIsometryEquiv.apply_symm_apply] + exact congrArg (fun A : SpinSpace (TopMode n) →L[ℂ] SpinSpace (TopMode n) => A (U.op (vac n))) + (WZ_rootZ d).symm + +end EvenUnitary + + +inductive Gate + | mixer (beta : ℝ) + | cost (gamma : ℝ) + | seed (angles : Fin 2 → ℝ) + + +def circuit : List Gate → (n : ℕ) → SeededTree.EvenUnitary n + | [], n => EvenUnitary.ident n + | Gate.mixer beta :: w, n => (circuit w n).followedBy (EvenUnitary.mixer n beta) + | Gate.seed a :: w, n => (circuit w n).followedBy (EvenUnitary.seed n a) + | Gate.cost _ :: w, 0 => circuit w 0 + | Gate.cost gamma :: w, n+1 => (circuit w (n+1)).followedBy (EvenUnitary.cost n (circuit w n) gamma) + +theorem circuit_compatible (w : List Gate) (n : ℕ) (hn : w.length ≤ n) : + EvenUnitary.Compatible (circuit w n) (circuit w (n+1)) := by + induction w generalizing n with + | nil => exact EvenUnitary.compatible_ident n + | cons g w ih => + cases g with + | mixer beta => + exact (ih n (by simpa using le_trans (Nat.le_succ w.length) hn)).followedBy + (EvenUnitary.compatible_mixer n beta) + | seed a => + exact (ih n (by simpa using le_trans (Nat.le_succ w.length) hn)).followedBy + (EvenUnitary.compatible_seed n a) + | cost gamma => + cases n with + | zero => simp at hn + | succ n => + have hn' : w.length ≤ n := by simpa using hn + exact (ih (n+1) (hn'.trans (Nat.le_succ n))).followedBy + (EvenUnitary.compatible_cost n _ _ (ih n hn') gamma) + +@[simp] theorem circuit_insertion_empty (w : List Gate) (n : ℕ) (hn : w.length ≤ n) : + centeredMap (empty n) (circuit w n).insertion=(circuit w (n+1)).insertion := + (circuit_compatible w n hn).insertion + + + +def rootShift (n : ℕ) : Mode n →ₗᵢ[ℂ] Mode (n+1) where + toFun d := ⟨plusEmbedding (creationVacuum (endogenous n d)),by + rw [mem_centered] + change ⟪plusEmbedding (coherent (0:TopMode (n+1))),plusEmbedding (creationVacuum (endogenous n d))⟫_ℂ=0 + exact (plusEmbedding.inner_map_map (coherent (0:TopMode (n+1))) + (creationVacuum (endogenous n d))).trans (creationVacuum_orthogonal (endogenous n d))⟩ + map_add' d e := by + apply Subtype.ext + change plusEmbedding (creationEmbedding (endogenous n (d+e)))= + plusEmbedding (creationEmbedding (endogenous n d))+plusEmbedding (creationEmbedding (endogenous n e)) + simp only [map_add] + map_smul' z d := by + apply Subtype.ext + change plusEmbedding (creationEmbedding (endogenous n (z • d)))= + z • plusEmbedding (creationEmbedding (endogenous n d)) + simp only [map_smul] + norm_map' d := by + exact (plusEmbedding.norm_map _).trans ((norm_creationVacuum _).trans ((endogenous n).norm_map d)) + +@[simp] theorem rootShift_coe (n : ℕ) (d : Mode n) : + (rootShift n d : Level (n+1))=plusEmbedding (creationVacuum (endogenous n d)) := rfl + +@[simp] theorem rootShift_empty (n : ℕ) (d : Mode n) : + centeredMap (empty (n+1)) (rootShift n d)=rootShift (n+1) (centeredMap (empty n) d) := by + apply Subtype.ext + change (empty (n+1)).toLinearIsometry (plusEmbedding (creationVacuum (endogenous n d)))= + plusEmbedding (creationVacuum (endogenous (n+1) (centeredMap (empty n) d))) + rw [empty_apply,spinMap_plusEmbedding] + change plusEmbedding (Gamma (topStep (n+1)) (creationVacuum (endogenous n d)))=_ + rw [Gamma_creationVacuum,topStep_endogenous] + +def treeEnergy (n : ℕ) (d : Mode n) : ℝ := (⟪centeredMap (empty n) d,rootShift n d⟫_ℂ).re + +@[simp] theorem treeEnergy_empty (n : ℕ) (d : Mode n) : + treeEnergy (n+1) (centeredMap (empty n) d)=treeEnergy n d := by + unfold treeEnergy + rw [←rootShift_empty] + exact congrArg Complex.re ((centeredMap (empty (n+1))).inner_map_map _ _) + +theorem abs_treeEnergy_le (n : ℕ) (d : Mode n) : |treeEnergy n d| ≤ ‖d‖^2 := by + calc + _ ≤ ‖⟪centeredMap (empty n) d,rootShift n d⟫_ℂ‖ := Complex.abs_re_le_norm _ + _ ≤ ‖centeredMap (empty n) d‖*‖rootShift n d‖ := norm_inner_le_norm _ _ + _ = ‖d‖^2 := by rw [(centeredMap (empty n)).norm_map,(rootShift n).norm_map]; ring + +def value (w : List Gate) : ℝ := treeEnergy w.length (circuit w w.length).insertion + +theorem value_eq_height (w : List Gate) (n : ℕ) (hn : w.length ≤ n) : + value w=treeEnergy n (circuit w n).insertion := by + induction n,hn using Nat.le_induction with + | base => rfl + | succ n hn ih => + rw [←circuit_insertion_empty w n hn,treeEnergy_empty,←ih] + +theorem abs_value_le (w : List Gate) : |value w| ≤ 1 := by + exact (abs_treeEnergy_le _ _).trans_eq (by rw [EvenUnitary.norm_insertion,one_pow]) + +end SeededTree + +namespace CoherentFock +open PointedTree Complex +variable {E X : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup X] [NormedSpace ℝ X] {x : X} + + +def PacketForm (x : X) (D : (X → E) → Prop) (v : X → SpinSpace E) : Prop := + ∃ (ι : Type) (_ : Fintype ι) (a : X → ι → Fin 2 → ℂ) (d : X → ι → E), + (∀i q, AnalyticAt ℝ (fun t => a t i q) x) ∧ + (∀i, D (fun t => d t i)) ∧ (∀t, v t=spinPacket (a t) (d t)) + +namespace PacketForm +variable {D : (X → E) → Prop} + +theorem inner (hD : ∀d e, D d → D e → AnalyticAt ℝ (fun t => ⟪d t,e t⟫_ℂ) x) + {v w : X → SpinSpace E} (hv : PacketForm x D v) (hw : PacketForm x D w) : + AnalyticAt ℝ (fun t => ⟪v t,w t⟫_ℂ) x := by + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + obtain ⟨κ,hk,b,e,hb,he,hw⟩ := hw + let := hi + let := hk + simp_rw [hv,hw] + exact analyticAt_inner_spinPacket a b d e ha hb + (fun i => hD _ _ (hd i) (hd i)) (fun j => hD _ _ (he j) (he j)) + (fun i j => hD _ _ (hd i) (he j)) + +theorem zero : PacketForm x D (fun _ => 0) := by + refine ⟨Fin 0,inferInstance,fun _ i => Fin.elim0 i,fun _ i => Fin.elim0 i,?_,?_,?_⟩ + · intro i; exact Fin.elim0 i + · intro i; exact Fin.elim0 i + · intro t; simp [spinPacket] + +theorem add {v w : X → SpinSpace E} (hv : PacketForm x D v) (hw : PacketForm x D w) : + PacketForm x D (fun t => v t+w t) := by + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + obtain ⟨κ,hk,b,e,hb,he,hw⟩ := hw + let := hi + let := hk + refine ⟨Sum ι κ,inferInstance,fun t => Sum.elim (a t) (b t), + fun t => Sum.elim (d t) (e t),?_,?_,?_⟩ + · intro i q; cases i with + | inl i => exact ha i q + | inr j => exact hb j q + · intro i; cases i with + | inl i => exact hd i + | inr j => exact he j + · intro t; dsimp only; rw [hv,hw,spinPacket_sum] + +theorem smul {v : X → SpinSpace E} {z : X → ℂ} + (hz : AnalyticAt ℝ z x) (hv : PacketForm x D v) : + PacketForm x D (fun t => z t • v t) := by + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + let := hi + refine ⟨ι,hi,fun t i q => z t*a t i q,d,fun i q => hz.mul (ha i q),hd,?_⟩ + intro t + dsimp only + rw [hv,spinPacket_smul] + +theorem neg {v : X → SpinSpace E} (hv : PacketForm x D v) : + PacketForm x D (fun t => -v t) := by + simpa using smul (show AnalyticAt ℝ (fun _ : X => (-1:ℂ)) x from analyticAt_const) hv + +theorem vacuum (h0 : D (fun _ => 0)) : PacketForm x D (fun _ => PointedTree.vacuum E) := by + refine ⟨Unit,inferInstance,fun _ _ _ => spinCoefficient,fun _ _ => 0, + fun _ _ => analyticAt_const,fun _ => h0,?_⟩ + intro t + ext q + simp only [spinPacket_apply,Fintype.sum_unique] + rfl + +theorem root {v : X → SpinSpace E} {A : X → Matrix (Fin 2) (Fin 2) ℂ} + (hA : ∀i j, AnalyticAt ℝ (fun t => A t i j) x) (hv : PacketForm x D v) : + PacketForm x D (fun t => SpinOperators.act (A t) (v t)) := by + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + let := hi + refine ⟨ι,hi,fun t i q => ∑j, A t q j * a t i j,d,?_,hd,?_⟩ + · intro i q + apply Finset.analyticAt_fun_sum + intro j hj + exact (hA q j).mul (ha i j) + · intro t + dsimp only + rw [hv,act_spinPacket] + +theorem pulse + (hD : ∀d e, D d → D e → AnalyticAt ℝ (fun t => ⟪d t,e t⟫_ℂ) x) + (hadd : ∀d e, D d → D e → D (fun t => d t+e t)) + (hneg : ∀d, D d → D (fun t => -d t)) + {v : X → SpinSpace E} {h : X → E} (hh : D h) (hv : PacketForm x D v) : + PacketForm x D (fun t => WZ (h t) (v t)) := by + classical + obtain ⟨ι,hi,a,d,ha,hd,hv⟩ := hv + let := hi + refine ⟨ι×Fin 2,inferInstance, + fun t p q => if q=p.2 then phase (if p.2=0 then h t else -h t) (d t p.1)*a t p.1 q else 0, + fun t p => (if p.2=0 then h t else -h t)+d t p.1,?_,?_,?_⟩ + · intro p q + by_cases hqp : q=p.2 + · simp only [hqp,ite_true] + apply AnalyticAt.mul _ (ha p.1 p.2) + apply analyticAt_phase_of_gram + have hgram := hD _ _ hh (hd p.1) + by_cases hp : p.2=0 + · simpa only [hp,ite_true] using hgram + · simpa only [hp,ite_false,inner_neg_left] using hgram.fun_neg + · simp only [hqp,ite_false] + exact analyticAt_const + · intro p + by_cases hp : p.2=0 + · simpa only [hp,ite_true] using hadd _ _ hh (hd p.1) + · simpa only [hp,ite_false] using hadd _ _ (hneg _ hh) (hd p.1) + · intro t + dsimp only + rw [hv,WZ_spinPacket] + +end PacketForm +end CoherentFock + +namespace SeededTree +open CoherentFock Complex RootSpin PointedTree +variable {X : Type*} [NormedAddCommGroup X] [NormedSpace ℝ X] + + + +def TopRegular (x : X) : (n : ℕ) → (X → TopMode n) → Prop + | 0,d => ∀q, AnalyticAt ℝ (fun t => d t q) x + | n+1,d => (∀q, AnalyticAt ℝ (fun t => (d t).fst q) x) ∧ + PacketForm x (TopRegular x n) (fun t => ((d t).snd : Level n)) + +def PacketRegular (x : X) (n : ℕ) (v : X → Level n) : Prop := PacketForm x (TopRegular x n) v + +namespace TopRegular +variable {x : X} + +theorem inner : ∀ (n : ℕ) {d e : X → TopMode n}, + TopRegular x n d → TopRegular x n e → + AnalyticAt ℝ (fun t => ⟪d t,e t⟫_ℂ) x := by + intro n + induction n with + | zero => + intro d e hd he + change AnalyticAt ℝ (fun t => ∑q : Fin 2, ⟪d t q,e t q⟫_ℂ) x + apply Finset.analyticAt_fun_sum + intro q hq + simp only [RCLike.inner_apply] + exact (he q).mul ((Complex.conjCLE.toContinuousLinearMap.analyticAt _).comp (hd q)) + | succ n ih => + intro d e hd he + change AnalyticAt ℝ (fun t => ⟪(d t).fst,(e t).fst⟫_ℂ+⟪(d t).snd,(e t).snd⟫_ℂ) x + apply AnalyticAt.add + · change AnalyticAt ℝ (fun t => ∑q : Fin 2, ⟪(d t).fst q,(e t).fst q⟫_ℂ) x + apply Finset.analyticAt_fun_sum + intro q hq + simp only [RCLike.inner_apply] + exact (he.1 q).mul ((Complex.conjCLE.toContinuousLinearMap.analyticAt _).comp (hd.1 q)) + · exact PacketForm.inner (fun _ _ => ih) hd.2 he.2 + +theorem zero (n : ℕ) : TopRegular x n (fun _ => 0) := by + cases n with + | zero => exact fun _ => analyticAt_const + | succ n => exact ⟨fun _ => analyticAt_const,PacketForm.zero⟩ + +theorem add (n : ℕ) {d e : X → TopMode n} (hd : TopRegular x n d) (he : TopRegular x n e) : + TopRegular x n (fun t => d t+e t) := by + cases n with + | zero => exact fun q => (hd q).add (he q) + | succ n => exact ⟨fun q => (hd.1 q).add (he.1 q),PacketForm.add hd.2 he.2⟩ + +theorem smul (n : ℕ) {d : X → TopMode n} {z : X → ℂ} + (hz : AnalyticAt ℝ z x) (hd : TopRegular x n d) : + TopRegular x n (fun t => z t • d t) := by + cases n with + | zero => exact fun q => hz.mul (hd q) + | succ n => exact ⟨fun q => hz.mul (hd.1 q),PacketForm.smul hz hd.2⟩ + +theorem neg (n : ℕ) {d : X → TopMode n} (hd : TopRegular x n d) : + TopRegular x n (fun t => -d t) := by + simpa using smul n (show AnalyticAt ℝ (fun _ : X => (-1:ℂ)) x from analyticAt_const) hd + +theorem external (n : ℕ) (e : X → External) (he : ∀q, AnalyticAt ℝ (fun t => e t q) x) : + TopRegular x n (fun t => SeededTree.external n (e t)) := by + cases n with + | zero => exact he + | succ n => exact ⟨he,PacketForm.zero⟩ + +theorem endogenous (n : ℕ) (d : X → Mode n) + (hd : PacketRegular x n (fun t => (d t:Level n))) : + TopRegular x (n+1) (fun t => SeededTree.endogenous n (d t)) := + ⟨fun _ => analyticAt_const,hd⟩ + +end TopRegular + +namespace PacketRegular +variable {x : X} + +theorem inner (n : ℕ) {v w : X → Level n} + (hv : PacketRegular x n v) (hw : PacketRegular x n w) : + AnalyticAt ℝ (fun t => ⟪v t,w t⟫_ℂ) x := + PacketForm.inner (fun _ _ => TopRegular.inner n) hv hw + +theorem zero (n : ℕ) : PacketRegular x n (fun _ => 0) := PacketForm.zero + +theorem add (n : ℕ) {v w : X → Level n} (hv : PacketRegular x n v) (hw : PacketRegular x n w) : + PacketRegular x n (fun t => v t+w t) := PacketForm.add hv hw + +theorem smul (n : ℕ) {v : X → Level n} {z : X → ℂ} + (hz : AnalyticAt ℝ z x) (hv : PacketRegular x n v) : + PacketRegular x n (fun t => z t • v t) := PacketForm.smul hz hv + +theorem neg (n : ℕ) {v : X → Level n} (hv : PacketRegular x n v) : + PacketRegular x n (fun t => -v t) := PacketForm.neg hv + +theorem vac (n : ℕ) : PacketRegular x n (fun _ => SeededTree.vac n) := + PacketForm.vacuum (TopRegular.zero n) + +theorem root (n : ℕ) {v : X → Level n} {A : X → Matrix (Fin 2) (Fin 2) ℂ} + (hA : ∀i j, AnalyticAt ℝ (fun t => A t i j) x) (hv : PacketRegular x n v) : + PacketRegular x n (fun t => SeededTree.root n (A t) (v t)) := PacketForm.root hA hv + +theorem pulse (n : ℕ) {v : X → Level n} {h : X → TopMode n} + (hh : TopRegular x n h) (hv : PacketRegular x n v) : + PacketRegular x n (fun t => WZ (h t) (v t)) := + PacketForm.pulse (fun _ _ => TopRegular.inner n) (fun _ _ => TopRegular.add n) + (fun _ => TopRegular.neg n) hh hv + +end PacketRegular +end SeededTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SpinCoeAdd.lean b/lean/OAI/Probability/ParisiFinite/SpinCoeAdd.lean new file mode 100644 index 0000000000000000000000000000000000000000..f5b7b6625a94082b29c8827f3dd485c0c5c138fb --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SpinCoeAdd.lean @@ -0,0 +1,697 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SpinWZeroApply + +namespace OAI + +/-! Spin Coe Add. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E α : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] {l : Filter α} + +@[simp] theorem spinCoe_add (x y : PreSpin E) : spinCoe (x+y)=spinCoe x+spinCoe y := by + ext i + simp only [spinCoe_apply,Pi.add_apply,UniformSpace.Completion.coe_add,PiLp.add_apply] + +@[simp] theorem spinCoe_zero : spinCoe (0:PreSpin E)=0 := by + ext i + simp only [spinCoe_apply,Pi.zero_apply,UniformSpace.Completion.coe_zero,PiLp.zero_apply] + +omit [NormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem spinMass_add (x y : PreSpin E) : spinMass (x+y)≤ spinMass x+spinMass y := by + unfold spinMass + rw [←Finset.sum_add_distrib] + exact Finset.sum_le_sum (fun i _ => mass_add_le (x i) (y i)) + +def preSpinW (d : E) (x : PreSpin E) : PreSpin E := fun i => preWLinear d (x i) + +@[simp] theorem spinCoe_preSpinW (d : E) (x : PreSpin E) : + spinCoe (preSpinW d x)=spinW d (spinCoe x) := by + ext i + simp only [spinCoe_apply,preSpinW,spinW_apply,W_coe] + +theorem spinMass_preSpinW (d : E) (x : PreSpin E) : spinMass (preSpinW d x)≤ spinMass x := + Finset.sum_le_sum (fun i _ => mass_preW_le d (x i)) + +theorem SpinRadiusLE.preSpinW {x : PreSpin E} {B : ℝ} (hx : SpinRadiusLE x B) (d : E) : + SpinRadiusLE (preSpinW d x) (‖d‖+B) := fun i => (hx i).preW d + +namespace BoundedPacket + +theorem zero : BoundedPacket l (fun _ : α => (0:SpinSpace E)) := by + refine ⟨fun _ => 0,0,0,le_rfl,le_rfl,fun _ => spinCoe_zero.symm,?_⟩ + exact Eventually.of_forall fun _ => ⟨fun _ => RadiusLE.zero _,by simp [spinMass,mass]⟩ + +theorem add {x y : α → SpinSpace E} (hx : BoundedPacket l x) (hy : BoundedPacket l y) : + BoundedPacket l (fun q => x q+y q) := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + obtain ⟨p',B',A',hB',hA',hp',hbound'⟩ := hy + refine ⟨fun q => p q+p' q,max B B',A+A',le_max_of_le_left hB,add_nonneg hA hA',?_,?_⟩ + · exact fun q => by simp only [spinCoe_add,hp,hp'] + · filter_upwards [hbound,hbound'] with q hq hq' + exact ⟨fun i => ((hq.1 i).mono (le_max_left _ _)).add ((hq'.1 i).mono (le_max_right _ _)), + (spinMass_add _ _).trans (add_le_add hq.2 hq'.2)⟩ + +theorem sum {ι : Type*} (s : Finset ι) (x : ι → α → SpinSpace E) + (hx : ∀i∈s,BoundedPacket l (x i)) : BoundedPacket l (fun q => ∑i∈s,x i q) := by + classical + induction s using Finset.induction_on with + | empty => simpa only [Finset.sum_empty] using (zero (E:=E) (α:=α) (l:=l)) + | @insert i s hi ih => + simpa only [Finset.sum_insert hi] using (hx i (Finset.mem_insert_self _ _)).add + (ih (fun j hj => hx j (Finset.mem_insert_of_mem hj))) + +theorem weyl {x : α → SpinSpace E} (hx : BoundedPacket l x) + (d : α → E) (C : ℝ) (hC : 0≤C) (hd : ∀ᶠ q in l,‖d q‖≤C) : + BoundedPacket l (fun q => spinW (d q) (x q)) := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + refine ⟨fun q => preSpinW (d q) (p q),C+B,A,add_nonneg hC hB,hA,?_,?_⟩ + · exact fun q => by simp only [spinCoe_preSpinW,hp] + · filter_upwards [hbound,hd] with q hq hdq + exact ⟨fun i => (hq.1.preSpinW (d q) i).mono (by linarith), + (spinMass_preSpinW _ _).trans hq.2⟩ + +end BoundedPacket +end CoherentFock + + + +open scoped InnerProductSpace Topology BigOperators +namespace CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +def spinSector (i : Fin 2) : Matrix (Fin 2) (Fin 2) ℂ := + Matrix.diagonal (fun j => if j=i then 1 else 0) +def projectSpin (i : Fin 2) : SpinSpace E →L[ℂ] SpinSpace E := SpinOperators.act (spinSector i) +def signedMode (i : Fin 2) (d : E) : E := if i=0 then d else -d + +@[simp] theorem projectSpin_apply (i j : Fin 2) (x : SpinSpace E) : + projectSpin i x j=if j=i then x j else 0 := by + fin_cases i <;> fin_cases j <;> + simp [projectSpin,spinSector,SpinOperators.act_apply,Matrix.diagonal] + +@[simp] theorem projectSpin_sum (x : SpinSpace E) : ∑i : Fin 2,projectSpin i x=x := by + ext j + simp only [Fin.sum_univ_two,PiLp.add_apply,projectSpin_apply] + fin_cases j <;> simp + +@[simp] theorem spinW_project (d : E) (i : Fin 2) (x : SpinSpace E) : + spinW d (projectSpin i x)=projectSpin i (spinW d x) := spinW_root _ _ _ + +@[simp] theorem projectSpin_projectSpin (i : Fin 2) (x : SpinSpace E) : + projectSpin i (projectSpin i x)=projectSpin i x := by + ext j + simp only [projectSpin_apply] + split_ifs <;> rfl + +omit [InnerProductSpace ℂ E] in +@[simp] theorem norm_signedMode (i : Fin 2) (d : E) : ‖signedMode i d‖=‖d‖ := by + unfold signedMode + split_ifs <;> simp + + theorem WZ_project (d : E) (i : Fin 2) (x : SpinSpace E) : + WZ d (projectSpin i x)=spinW (signedMode i d) (projectSpin i x) := by + ext j + simp only [WZ_apply,spinW_apply,projectSpin_apply] + by_cases hj : j=i + · subst j; simp only [ite_true]; rfl + · simp only [hj,ite_false,map_zero] + + theorem spinW_mul_apply (d e : E) (x : SpinSpace E) : + spinW d (spinW e x)=phase d e • spinW (d+e) x := by + ext i + simpa only [ContinuousLinearMap.comp_apply,smul_apply,spinW_apply,PiLp.smul_apply] + using congrArg (fun T : Space E →L[ℂ] Space E => T (x i)) (W_mul d e) + + theorem spinW_add_split (d e : E) (x : SpinSpace E) : + spinW (d+e) x=(phase d e)⁻¹ • spinW d (spinW e x) := by + rw [spinW_mul_apply,smul_smul,inv_mul_cancel₀,one_smul] + exact norm_ne_zero_iff.mp (by rw [norm_phase]; norm_num) + +omit [InnerProductSpace ℂ E] in + theorem signedMode_add (i : Fin 2) (d e : E) : + signedMode i (d+e)=signedMode i d+signedMode i e := by + unfold signedMode + split_ifs <;> abel + + theorem WZ_sector_split (d e : E) (x : SpinSpace E) : + WZ (d+e) x=∑i : Fin 2, (phase (signedMode i d) (signedMode i e))⁻¹ • + spinW (signedMode i d) (spinW (signedMode i e) (projectSpin i x)) := by + conv_lhs => rw [←projectSpin_sum x,map_sum] + apply Finset.sum_congr rfl + intro i _ + rw [WZ_project,signedMode_add,spinW_add_split] + + + + theorem rotated_WZ_sector_split (A : Matrix (Fin 2) (Fin 2) ℂ) (d e : E) (x : SpinSpace E) : + SpinOperators.act A (WZ (d+e) x)= + ∑i : Fin 2,∑j : Fin 2,spinW (signedMode i d) + ((phase (signedMode i d) (signedMode i e))⁻¹ • + projectSpin j (SpinOperators.act A (spinW (signedMode i e) (projectSpin i x)))) := by + rw [WZ_sector_split,map_sum] + apply Finset.sum_congr rfl + intro i _ + simp only [map_smul] + rw [←Finset.smul_sum,←map_sum,projectSpin_sum,spinW_root] + +namespace BoundedPacket +open Filter +variable {α : Type*} {l : Filter α} + + theorem project {x : α → SpinSpace E} (hx : BoundedPacket l x) (i : Fin 2) : + BoundedPacket l (fun q => projectSpin i (x q)) := hx.root (spinSector i) + + theorem rotated_sector_tail {x : α → SpinSpace E} (hx : BoundedPacket l x) + (A : Matrix (Fin 2) (Fin 2) ℂ) (d e : α → E) (C : ℝ) (hC : 0≤C) + (he : ∀ᶠ q in l,‖e q‖≤C) (i j : Fin 2) : + BoundedPacket l (fun q => (phase (signedMode i (d q)) (signedMode i (e q)))⁻¹ • + projectSpin j (SpinOperators.act A (spinW (signedMode i (e q)) (projectSpin i (x q))))) := by + apply ((((hx.project i).weyl (fun q => signedMode i (e q)) C hC + (by simpa only [norm_signedMode] using he)).root A).project j).smul _ 1 (by norm_num) + exact Eventually.of_forall fun q => by simp only [norm_inv,norm_phase,inv_one,le_refl] + +end BoundedPacket +end CoherentFock + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + + theorem projectSpin_spinW (i : Fin 2) (d : E) (x : SpinSpace E) : + projectSpin i (spinW d x)=spinW d (projectSpin i x) := (spinW_project _ _ _).symm + + theorem WZ_on_sector {i : Fin 2} {x : SpinSpace E} (hx : projectSpin i x=x) (d : E) : + WZ d x=spinW (signedMode i d) x := by + conv_lhs => rw [←hx] + rw [WZ_project,hx] + + + + theorem WZ_packet_bounded {i : Fin 2} {x : SpinSpace E} (hx : projectSpin i x=x) (d c : E) : + WZ d (spinW c x)= + (phase (signedMode i d) c / phase c (signedMode i d)) • + spinW c (spinW (signedMode i d) x) := by + have hs : projectSpin i (spinW c x)=spinW c x := by rw [projectSpin_spinW,hx] + rw [WZ_on_sector hs,spinW_mul_apply,spinW_mul_apply,smul_smul] + rw [div_mul_cancel₀,add_comm c] + exact norm_ne_zero_iff.mp (by rw [norm_phase]; norm_num) + + + + theorem WZ_packet_shift {i : Fin 2} {x : SpinSpace E} (hx : projectSpin i x=x) (d c : E) : + WZ d (spinW c x)=phase (signedMode i d) c • spinW (c+signedMode i d) x := by + have hs : projectSpin i (spinW c x)=spinW c x := by rw [projectSpin_spinW,hx] + rw [WZ_on_sector hs,spinW_mul_apply,add_comm c] + + theorem rootX_sector (i : Fin 2) (x : SpinSpace E) : + projectSpin (1-i) (SpinOperators.act RootSpin.X (projectSpin i x))= + SpinOperators.act RootSpin.X (projectSpin i x) := by + ext j + fin_cases i <;> fin_cases j <;> + simp [projectSpin_apply,SpinOperators.act_apply,RootSpin.X] + + theorem halfMixer_sector (i : Fin 2) (x : SpinSpace E) : + projectSpin (1-i) (SpinOperators.act (RootSpin.R (Real.pi/2)) (projectSpin i x))= + SpinOperators.act (RootSpin.R (Real.pi/2)) (projectSpin i x) := by + ext j + fin_cases i <;> fin_cases j <;> + simp [projectSpin_apply,SpinOperators.act_apply,RootSpin.R,RootSpin.X, + Real.cos_pi_div_two,Real.sin_pi_div_two] + +namespace BoundedPacket +variable {α κ : Type*} [Fintype κ] {l : Filter α} + + + + theorem finite_uniform (x : κ → α → SpinSpace E) (hx : ∀i,BoundedPacket l (x i)) : + ∃ (p : κ → α → PreSpin E) (B A : ℝ),0≤B ∧ 0≤A ∧ + (∀i q,x i q=spinCoe (p i q)) ∧ + (∀ᶠ q in l,∀i,SpinRadiusLE (p i q) B ∧ spinMass (p i q)≤A) := by + classical + choose p B A hB hA hp hbd using hx + refine ⟨p,∑i,B i,∑i,A i,Finset.sum_nonneg (fun i _ => hB i), + Finset.sum_nonneg (fun i _ => hA i),hp,?_⟩ + have hall : ∀ᶠ q in l,∀i,SpinRadiusLE (p i q) (B i) ∧ spinMass (p i q)≤A i := + eventually_all.mpr hbd + filter_upwards [hall] with q hq i + exact ⟨fun j => (hq i).1 j |>.mono (Finset.single_le_sum (fun k _ => hB k) (Finset.mem_univ i)), + (hq i).2.trans (Finset.single_le_sum (fun k _ => hA k) (Finset.mem_univ i))⟩ + + theorem cost_packet_tail {x : α → SpinSpace E} (hx : BoundedPacket l x) + (d c : α → E) (D : ℝ) (hD : 0≤D) (hd : ∀ᶠ q in l,‖d q‖≤D) (i : Fin 2) : + BoundedPacket l (fun q => (phase (signedMode i (d q)) (c q) / phase (c q) (signedMode i (d q))) • + spinW (signedMode i (d q)) (x q)) := by + apply (hx.weyl (fun q => signedMode i (d q)) D hD + (by simpa only [norm_signedMode] using hd)).smul _ 1 (by norm_num) + exact Eventually.of_forall fun q => by simp only [norm_div,norm_phase,div_self one_ne_zero,le_refl] + +end BoundedPacket +end CoherentFock + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E α : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] {l : Filter α} + + + +theorem low_insertion_scaled_bound + (U : α → SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E) (A : PacketUnitaryFamily (E:=E) l) + (O Q : α → SpinSpace E →L[ℂ] SpinSpace E) (ζ : α → ℂ) (r S : α → ℝ) + (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) + (hscale : ∀ᶠ q in l,0≤r q ∧ 0≤S q ∧ S q*r q=1) + (hsplit : ∀ᶠ q in l,∀x,U q x=O q x+Q q x) + (hQ : ∀ᶠ q in l,∀x,‖Q q x‖≤r q*‖x‖) + (hO : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖O q (x q)-ζ q • A.op q (x q)‖) l (𝓝 0)) : + ∀ᶠ q in l,S q*‖(U q).symm (SpinOperators.act P (U q (PointedTree.vacuum E)))- + (A.op q).symm (SpinOperators.act P (A.op q (PointedTree.vacuum E)))‖≤4 := by + let Ω := PointedTree.vacuum E + let test (q : α) := (A.op q).symm (SpinOperators.act P (A.op q Ω)) + let e₀ (q : α) := ‖O q Ω-ζ q • A.op q Ω‖ + let e₁ (q : α) := ‖O q (test q)-ζ q • A.op q (test q)‖ + have he : Tendsto (fun q => S q*(e₀ q+e₁ q)) l (𝓝 0) := by + simpa only [e₀,e₁,test,Ω,mul_add,add_zero] using + (hO (fun _ => Ω) BoundedPacket.vacuum).add (hO test (A.insertion_bounded P)) + filter_upwards [hscale,hsplit,hQ,he.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1))] + with q hsq hsplitq hQq heq + have hz : ∀x : SpinSpace E,‖SpinOperators.act P x‖≤‖x‖ := + fun x => (SpinOperators.norm_act hP x).le + have hi := ForwardControl.insertion_split_bound (U q) (A.op q) + (SpinOperators.act P) hz Ω (ζ q) (O q) (Q q) hsplitq (r q) (e₀ q+e₁ q) + hsq.1 hQq (by dsimp only [e₀,e₁]; linarith [norm_nonneg (O q (test q)-ζ q • A.op q (test q))]) + (by dsimp only [e₀,e₁,test]; linarith [norm_nonneg (O q Ω-ζ q • A.op q Ω)]) + have hi' := mul_le_mul_of_nonneg_left hi hsq.2.1 + change S q*‖(U q).symm ((SpinOperators.act P) (U q Ω))-test q‖≤4 + dsimp only [Ω] at hi' + rw [PointedTree.norm_vacuum] at hi' + nlinarith [hsq.2.2] + + + +theorem low_insertion_tendsto + (U : α → SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E) (A : PacketUnitaryFamily (E:=E) l) + (O Q : α → SpinSpace E →L[ℂ] SpinSpace E) (ζ : α → ℂ) (r S : α → ℝ) + (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) + (hr : Tendsto r l (𝓝 0)) + (hscale : ∀ᶠ q in l,0≤r q ∧ 0≤S q ∧ S q*r q=1) + (hsplit : ∀ᶠ q in l,∀x,U q x=O q x+Q q x) + (hQ : ∀ᶠ q in l,∀x,‖Q q x‖≤r q*‖x‖) + (hO : ∀x,BoundedPacket l x → + Tendsto (fun q => S q*‖O q (x q)-ζ q • A.op q (x q)‖) l (𝓝 0)) : + Tendsto (fun q => ‖(U q).symm (SpinOperators.act P (U q (PointedTree.vacuum E)))- + (A.op q).symm (SpinOperators.act P (A.op q (PointedTree.vacuum E)))‖) l (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun _ => norm_nonneg _)) _ + (by simpa only [mul_zero] using hr.const_mul 4) + filter_upwards [hscale,low_insertion_scaled_bound U A O Q ζ r S P hP hscale hsplit hQ hO] + with q hsq hi + have hh := mul_le_mul_of_nonneg_left hi hsq.1 + rw [←mul_assoc,mul_comm (r q) (S q),hsq.2.2,one_mul] at hh + simpa only [mul_comm] using hh + +end CoherentFock + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree +local instance initRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance initRealSMul : SMul ℝ ModeInfinity := initRealModule.toDistribMulAction.toSMul +local instance initRealSMulZero : SMulZeroClass ℝ ModeInfinity := { smul_zero := initRealModule.toDistribMulAction.smul_zero } + + + +def eInfinity : ModeInfinity := insertionInfinity [] +def vInfinity (b T : ℝ) : ModeInfinity := + insertionInfinity [.mixer (delta T),.cost (gamma b T)] +def highInfinity (γ : ℝ) : ModeInfinity := modeEmbed 3 (highDirection 2 γ) +def dInfinity (b T : ℝ) : ModeInfinity := (gamma b T : ℂ) • (vInfinity b T-eInfinity) +def wordInfinity (b T : ℝ) : List PointedTree.Gate := + PointedTree.initializationWord (gamma b T) (delta T) (Real.pi/4) + +@[simp] theorem norm_eInfinity : ‖eInfinity‖=1 := norm_insertionInfinity [] +@[simp] theorem norm_vInfinity (b T : ℝ) : ‖vInfinity b T‖=1 := norm_insertionInfinity _ +@[simp] theorem norm_highInfinity (γ : ℝ) : ‖highInfinity γ‖=1 := by + rw [highInfinity,(modeEmbed 3).norm_map,highDirection_norm] + +theorem embed_initialDirection (n : ℕ) : modeEmbed n (initialDirection n)=eInfinity := by + exact insertionInfinity_stable [] n (Nat.zero_le n) + +theorem vInfinity_embed (b T : ℝ) : + vInfinity b T=modeEmbed 3 (actualV 2 b T) := by + exact (insertionInfinity_stable _ 3 (by simp)).symm + +theorem vInfinity_eq (b T : ℝ) : + vInfinity b T=(Real.cos (2*delta T):ℂ) • eInfinity+ + (Real.sin (2*delta T):ℂ) • highInfinity (gamma b T) := by + rw [vInfinity_embed,actualV_eq,map_add,map_smul,map_smul,embed_initialDirection] + rfl + +@[simp] theorem modeFock_eInfinity : modeFock eInfinity=SpinOperators.act Z (vacuum ModeInfinity) := by + rw [eInfinity,modeFock_insertion] + apply (ordinaryLocal []).injective + simp only [LinearIsometryEquiv.apply_symm_apply,ordinaryLocal_nil] + +@[simp] theorem spinMap_vacuum {E F : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] (T : E →ₗᵢ[ℂ] F) : + spinMap (gammaEmbedding T) (vacuum E)=vacuum F := by + ext i + simp only [spinMap_apply,vacuum_apply,map_smul,gammaEmbedding_coherent,map_zero] + +theorem modeFock_highInfinity (γ : ℝ) : + modeFock (highInfinity γ)=SpinOperators.act Y + (WZ ((-2*γ:ℝ) • eInfinity) (vacuum ModeInfinity)) := by + change unfoldTree (modeInWhole (modeEmbed 3 (highDirection 2 γ)))=_ + rw [modeInWhole_embed,unfoldTree_embed_succ] + change spinMap (gammaEmbedding (modeEmbed 2)) (highDirection 2 γ : Level 3)=_ + rw [highDirection_coe,spinMap_root,spinMap_cost] + change SpinOperators.act Y (WZ (modeEmbed 2 ((-2*γ:ℝ) • initialDirection 2)) + (spinMap (gammaEmbedding (modeEmbed 2)) (vacuum (Mode 2))))=_ + rw [spinMap_vacuum] + have hm : modeEmbed 2 ((-2*γ:ℝ) • initialDirection 2)=(-2*γ:ℝ) • eInfinity := by + calc + _ = (-2*γ:ℝ) • modeEmbed 2 (initialDirection 2) := (modeEmbed 2).map_smul_of_tower _ _ + _ = _ := by rw [embed_initialDirection] + rw [hm] + +theorem initialMap_apply_complex {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (γ δ β : ℝ) (v e : E) (x : SpinSpace E) : + initialMap γ δ β v e x=SpinOperators.act (R β) + (WZ ((γ:ℂ) • v) (SpinOperators.act (R δ) (WZ (-(γ:ℂ) • e) x))) := by + simp only [initialMap_apply,←Complex.coe_smul,Complex.ofReal_neg] + +@[simp] theorem ordinaryLocal_initialization (b T : ℝ) (x : SpinSpace ModeInfinity) : + ordinaryLocal (wordInfinity b T) x= + initialMap (gamma b T) (delta T) (Real.pi/4) (vInfinity b T) eInfinity x := by + simp only [wordInfinity,PointedTree.initializationWord,ordinaryLocal_mixer, + ordinaryLocal_cost,ordinaryLocal_nil,Complex.ofReal_neg,neg_neg,initialMap_apply_complex] + rfl + +theorem dInfinity_embed (b T : ℝ) : + dInfinity b T=modeEmbed 3 (ordinaryDisplacement 2 b T) := by + unfold dInfinity ordinaryDisplacement + rw [←Complex.coe_smul,map_smul,map_sub,←vInfinity_embed,embed_initialDirection] + +theorem dInfinity_bounded (b : ℝ) : + ∀ᶠ T : ℝ in atTop,‖dInfinity b T‖≤2*|b|+1 := by + simpa only [dInfinity_embed,(modeEmbed 3).norm_map] using ordinaryDisplacement_bounded 2 b + +theorem dInfinity_approx_high (b : ℝ) : + Tendsto (fun T => ‖dInfinity b T-(2*b:ℝ) • highInfinity (gamma b T)‖) atTop (𝓝 0) := by + have he (T : ℝ) : dInfinity b T-(2*b:ℝ) • highInfinity (gamma b T)= + modeEmbed 3 (ordinaryDisplacement 2 b T-(2*b:ℝ) • highDirection 2 (gamma b T)) := by + rw [map_sub,←dInfinity_embed] + congr 1 + exact ((modeEmbed 3).map_smul_of_tower (2*b:ℝ) (highDirection 2 (gamma b T))).symm + simpa only [he,(modeEmbed 3).norm_map] using tendsto_ordinaryDisplacement_error 2 b + + +def lowInfinity (b : ℝ) : PacketUnitaryFamily (E:=ModeInfinity) (atTop : Filter ℝ) := + (PacketUnitaryFamily.pulse (dInfinity b) (2*|b|+1) (by positivity) + (dInfinity_bounded b)).trans (PacketUnitaryFamily.root (R (Real.pi/4)) (R_unitary _)) + +@[simp] theorem lowInfinity_apply (b T : ℝ) (x : SpinSpace ModeInfinity) : + (lowInfinity b).op T x= + ordinaryMap (gamma b T) (Real.pi/4) (vInfinity b T) eInfinity x := rfl + +def phaseInfinity (b T : ℝ) : ℂ := + phase (gamma b T • vInfinity b T) ((-gamma b T) • eInfinity) + +def ordinaryPartInfinity (b T : ℝ) : SpinSpace ModeInfinity →L[ℂ] SpinSpace ModeInfinity := + ordinaryCoefficient (gamma b T) (delta T) (vInfinity b T) eInfinity • + (ordinaryMap (gamma b T) (Real.pi/4) (vInfinity b T) eInfinity).toContinuousLinearEquiv.toContinuousLinearMap + +def specialPartInfinity (b T : ℝ) : SpinSpace ModeInfinity →L[ℂ] SpinSpace ModeInfinity := + specialCoefficient (gamma b T) (delta T) (vInfinity b T) eInfinity • + (specialMap (gamma b T) (Real.pi/4) (vInfinity b T) eInfinity).toContinuousLinearEquiv.toContinuousLinearMap + +@[simp] theorem ordinaryPartInfinity_apply (b T : ℝ) (x : SpinSpace ModeInfinity) : + ordinaryPartInfinity b T x=ordinaryCoefficient (gamma b T) (delta T) (vInfinity b T) eInfinity • + ordinaryMap (gamma b T) (Real.pi/4) (vInfinity b T) eInfinity x := rfl + +@[simp] theorem specialPartInfinity_apply (b T : ℝ) (x : SpinSpace ModeInfinity) : + specialPartInfinity b T x=specialCoefficient (gamma b T) (delta T) (vInfinity b T) eInfinity • + specialMap (gamma b T) (Real.pi/4) (vInfinity b T) eInfinity x := rfl + +@[simp] theorem norm_phaseInfinity (b T : ℝ) : ‖phaseInfinity b T‖=1 := norm_phase _ _ + +theorem exact_splitInfinity (b T : ℝ) (x : SpinSpace ModeInfinity) : + ordinaryLocal (wordInfinity b T) x=ordinaryPartInfinity b T x+specialPartInfinity b T x := by + rw [ordinaryLocal_initialization] + exact exact_split _ _ _ _ _ _ + +theorem norm_specialPartInfinity (b : ℝ) {T : ℝ} (hT : 1≤T) (x : SpinSpace ModeInfinity) : + ‖specialPartInfinity b T x‖=amplitude T*‖x‖ := by + change ‖specialCoefficient _ _ _ _ • specialMap _ _ _ _ x‖=_ + rw [norm_special_component,sin_delta hT,abs_of_pos (amplitude_pos hT)] + +theorem lowInfinity_accuracy (b : ℝ) (x : ℝ → SpinSpace ModeInfinity) + (hx : BoundedPacket atTop x) : + Tendsto (fun T => T*‖ordinaryPartInfinity b T (x T)-phaseInfinity b T • + (lowInfinity b).op T (x T)‖) atTop (𝓝 0) := by + obtain ⟨C,hC,hxC⟩ := hx.norm_bounded + apply squeeze_zero' _ _ (by simpa only [zero_mul] using tendsto_amplitude.mul_const C) + · filter_upwards [eventually_ge_atTop (1:ℝ)] with T hT + exact mul_nonneg (by linarith) (norm_nonneg _) + · filter_upwards [eventually_ge_atTop (1:ℝ),hxC] with T hT hxT + have hh := ordinary_component_error (gamma b T) (Real.pi/4) hT (vInfinity b T) eInfinity (x T) + have hh' : ‖ordinaryPartInfinity b T (x T)-phaseInfinity b T • (lowInfinity b).op T (x T)‖≤ + (amplitude T)^2*‖x T‖ := by + rw [ordinaryPartInfinity_apply,lowInfinity_apply] + exact hh + have hT0 : 0≤T := by linarith + calc + _ ≤ T*((amplitude T)^2*‖x T‖) := mul_le_mul_of_nonneg_left hh' hT0 + _ ≤ T*((amplitude T)^2*C) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left hxT (sq_nonneg _)) hT0 + _ = amplitude T*C := by + unfold amplitude + field_simp + + + +theorem highInfinity_escapes (b : ℝ) (hb : 0 ⟪x T,modeFock (highInfinity (gamma b T))⟫_ℂ) atTop (𝓝 0) := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + simp only [hp,modeFock_highInfinity] + exact tendsto_inner_spinCoe_rootY_uniform _ p + (tendsto_norm_scaled_unit (gamma b) (fun _ => eInfinity) (tendsto_gamma b hb) + (fun _ => norm_eInfinity)) B A hB hbound + +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace SeedInitialization +open CoherentFock RootSpin Complex PointedTree +local instance packetRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance packetRealSMul : SMul ℝ ModeInfinity := packetRealModule.toDistribMulAction.toSMul +local instance packetRealSMulZero : SMulZeroClass ℝ ModeInfinity := { smul_zero := packetRealModule.toDistribMulAction.smul_zero } + + theorem signedMode_smul {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (c : ℂ) (i : Fin 2) (d : E) : signedMode i (c • d)=c • signedMode i d := by + unfold signedMode + split_ifs <;> simp only [smul_neg] + + theorem specialCoefficient_eq (γ δ : ℝ) (v e : ModeInfinity) : + specialCoefficient γ δ v e=(Real.sin δ:ℂ)*specialPhase γ v e := by + unfold specialCoefficient specialPhase + ring + + theorem special_displacement (γ : ℝ) (v e : ModeInfinity) : + (-γ:ℝ) • (v+e)=((-2*γ:ℝ):ℂ) • e + -((γ:ℂ) • (v-e)) := by + rw [←Complex.coe_smul] + push_cast + module + + theorem specialPart_expanded (b T : ℝ) (x : SpinSpace ModeInfinity) : + specialPartInfinity b T x=(Real.sin (delta T):ℂ) • + (specialPhase (gamma b T) (vInfinity b T) eInfinity • + SpinOperators.act (R (Real.pi/4)*X) + (WZ (((-2*gamma b T:ℝ):ℂ) • eInfinity + -dInfinity b T) x)) := by + rw [specialPartInfinity_apply,specialCoefficient_eq,specialMap_apply,smul_smul] + rw [special_displacement,SpinOperators.act_mul,ContinuousLinearMap.comp_apply] + rfl + + +def initialCenter (b : ℝ) (i : Fin 2) : ModeInfinity := + signedMode i ((-2*b:ℝ) • eInfinity) + +def initialTail (b T : ℝ) (i j : Fin 2) (x : SpinSpace ModeInfinity) : SpinSpace ModeInfinity := + specialPhase (gamma b T) (vInfinity b T) eInfinity • + ((phase (signedMode i ((-2*gamma b T:ℝ) • eInfinity)) (signedMode i (-dInfinity b T)))⁻¹ • + projectSpin j (SpinOperators.act (R (Real.pi/4)*X) + (spinW (signedMode i (-dInfinity b T)) (projectSpin i x)))) + + theorem initialCenter_scale (b T : ℝ) (i : Fin 2) : + signedMode i ((-2*gamma b T:ℝ) • eInfinity)=(T:ℂ) • initialCenter b i := by + simp only [initialCenter,←Complex.coe_smul,←signedMode_smul,smul_smul,gamma] + congr 2 + push_cast + ring + + theorem initial_special_packets (b : ℝ) {T : ℝ} (hT : 1≤T) (x : SpinSpace ModeInfinity) : + specialPartInfinity b T x=(amplitude T:ℂ) • + ∑i : Fin 2,∑j : Fin 2,spinW ((T:ℂ) • initialCenter b i) (initialTail b T i j x) := by + rw [specialPart_expanded,sin_delta hT] + congr 1 + rw [Complex.coe_smul,rotated_WZ_sector_split,Finset.smul_sum] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.smul_sum] + apply Finset.sum_congr rfl + intro j _ + simp only [initialTail,initialCenter_scale,map_smul] + + theorem initialTail_bounded (b : ℝ) (x : ℝ → SpinSpace ModeInfinity) + (hx : BoundedPacket atTop x) (i j : Fin 2) : + BoundedPacket atTop (fun T => initialTail b T i j (x T)) := by + apply (hx.rotated_sector_tail (R (Real.pi/4)*X) + (fun T => (-2*gamma b T:ℝ) • eInfinity) (fun T => -dInfinity b T) + (2*|b|+1) (by positivity) + (by simpa only [norm_neg] using dInfinity_bounded b) i j).smul _ 1 (by norm_num) + exact Eventually.of_forall fun T => (norm_specialPhase _ _ _).le + + theorem initialTail_sector (b T : ℝ) (i j : Fin 2) (x : SpinSpace ModeInfinity) : + projectSpin j (initialTail b T i j x)=initialTail b T i j x := by + simp only [initialTail,map_smul,projectSpin_projectSpin] + + theorem norm_initialCenter (b : ℝ) (i : Fin 2) : ‖initialCenter b i‖=2*|b| := by + rw [initialCenter,norm_signedMode,norm_smul,norm_eInfinity,mul_one,Real.norm_eq_abs] + rw [abs_mul] + norm_num + +end SeedInitialization + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E α κ : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] [Fintype κ] + {l : Filter α} + + + +def PacketExpansion (S r : α → ℝ) (d : κ → α → E) (spin : κ → Fin 2) + (u : α → SpinSpace E) : Prop := + ∃ τ : κ → α → SpinSpace E, + (∀i,BoundedPacket l (τ i)) ∧ + (∀i q,projectSpin (spin i) (τ i q)=τ i q) ∧ + Tendsto (fun q => S q*‖u q-∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ i q)‖) l (𝓝 0) + +namespace PacketExpansion +variable {S r : α → ℝ} {d : κ → α → E} {spin : κ → Fin 2} {u v : α → SpinSpace E} + + theorem close (hu : PacketExpansion (l:=l) S r d spin u) + (hS : ∀ᶠ q in l,0≤S q) + (hv : Tendsto (fun q => S q*‖v q-u q‖) l (𝓝 0)) : + PacketExpansion (l:=l) S r d spin v := by + obtain ⟨τ,hτ,hspin,he⟩ := hu + refine ⟨τ,hτ,hspin,?_⟩ + apply squeeze_zero' _ _ (by simpa only [add_zero,mul_add] using hv.add he) + · filter_upwards [hS] with q hq + exact mul_nonneg hq (norm_nonneg _) + · filter_upwards [hS] with q hq + simpa only [mul_add] using mul_le_mul_of_nonneg_left (norm_sub_le_norm_sub_add_norm_sub (v q) (u q) (∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ i q))) hq + + theorem bounded_cost (hu : PacketExpansion (l:=l) S r d spin u) + (c : α → E) (C : ℝ) (hC : 0≤C) (hc : ∀ᶠ q in l,‖c q‖≤C) : + PacketExpansion (l:=l) S r d spin (fun q => WZ (c q) (u q)) := by + obtain ⟨τ,hτ,hspin,he⟩ := hu + let τ' (i : κ) (q : α) := + (phase (signedMode (spin i) (c q)) ((S q:ℂ) • d i q) / + phase ((S q:ℂ) • d i q) (signedMode (spin i) (c q))) • + spinW (signedMode (spin i) (c q)) (τ i q) + refine ⟨τ',fun i => (hτ i).cost_packet_tail c (fun q => (S q:ℂ) • d i q) C hC hc (spin i),?_,?_⟩ + · intro i q + simp only [τ',map_smul,projectSpin_spinW,hspin] + · have hsum (q : α) : WZ (c q) (∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ i q))= + ∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ' i q) := by + simp only [map_sum,map_smul] + apply Finset.sum_congr rfl + intro i _ + rw [WZ_packet_bounded (hspin i q)] + simp only [τ',map_smul] + simpa only [←hsum,←map_sub,norm_WZ] using he + + theorem huge_cost (hu : PacketExpansion (l:=l) S r d spin u) (c : α → E) : + PacketExpansion (l:=l) S r (fun i q => d i q+signedMode (spin i) (c q)) spin + (fun q => WZ ((S q:ℂ) • c q) (u q)) := by + obtain ⟨τ,hτ,hspin,he⟩ := hu + let τ' (i : κ) (q : α) := + phase (signedMode (spin i) ((S q:ℂ) • c q)) ((S q:ℂ) • d i q) • τ i q + refine ⟨τ',?_,?_,?_⟩ + · intro i + exact (hτ i).smul _ 1 (by norm_num) (Eventually.of_forall fun _ => (norm_phase _ _).le) + · intro i q + simp only [τ',map_smul,hspin] + · have hsum (q : α) : WZ ((S q:ℂ) • c q) (∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ i q))= + ∑i,(r q:ℂ) • spinW ((S q:ℂ) • (d i q+signedMode (spin i) (c q))) (τ' i q) := by + simp only [map_sum,map_smul] + apply Finset.sum_congr rfl + intro i _ + rw [WZ_packet_shift (hspin i q)] + simp only [τ',map_smul,smul_add,SeedInitialization.signedMode_smul] + simpa only [←hsum,←map_sub,norm_WZ] using he + + theorem half_mixer (hu : PacketExpansion (l:=l) S r d spin u) : + PacketExpansion (l:=l) S r d (fun i => 1-spin i) + (fun q => SpinOperators.act (RootSpin.R (Real.pi/2)) (u q)) := by + obtain ⟨τ,hτ,hspin,he⟩ := hu + let A := RootSpin.R (Real.pi/2) + refine ⟨fun i q => SpinOperators.act A (τ i q),fun i => (hτ i).root A,?_,?_⟩ + · intro i q + change projectSpin (1-spin i) (SpinOperators.act (RootSpin.R (Real.pi/2)) (τ i q))=_ + conv_lhs => rw [←hspin i q] + rw [halfMixer_sector,hspin] + · have hsum (q : α) : SpinOperators.act A (∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (τ i q))= + ∑i,(r q:ℂ) • spinW ((S q:ℂ) • d i q) (SpinOperators.act A (τ i q)) := by + simp only [map_sum,map_smul,spinW_root] + simpa only [←hsum,A,←map_sub,SpinOperators.norm_act (RootSpin.R_unitary _)] using he + +end PacketExpansion +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SpinFlip.lean b/lean/OAI/Probability/ParisiFinite/SpinFlip.lean new file mode 100644 index 0000000000000000000000000000000000000000..212de38e4ab90c2579be0e48c618d46a04302d71 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SpinFlip.lean @@ -0,0 +1,620 @@ +import Mathlib +import OAI.Probability.ParisiFinite.YAdd + +namespace OAI + +/-! Spin Flip. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open scoped BigOperators Matrix Topology Matrix.Norms.Operator + +namespace SKQAOA.Masks +variable {n : ℕ} {C : Type*} [Fintype C] [DecidableEq C] + + +def spinFlip (R : Fin n → C) (ε : C → Bool) : Equiv.Perm (Configuration n) where + toFun σ i := if ε (R i) then !(σ i) else σ i + invFun σ i := if ε (R i) then !(σ i) else σ i + left_inv σ := by funext i; cases h : ε (R i) <;> simp [h] + right_inv σ := by funext i; cases h : ε (R i) <;> simp [h] + +def flipGate (R : Fin n → C) (ε : C → Bool) : Operator n := (spinFlip R ε).permMatrix ℂ + +omit [Fintype C] [DecidableEq C] in +@[simp] theorem spinFlip_symm (R : Fin n → C) (ε : C → Bool) : + (spinFlip R ε).symm=spinFlip R ε := rfl + +omit [Fintype C] [DecidableEq C] in +@[simp] theorem flipGate_adjoint (R : Fin n → C) (ε : C → Bool) : + (flipGate R ε)ᴴ=flipGate R ε := by + simp only [flipGate,Matrix.conjTranspose_permMatrix] + rfl + +omit [Fintype C] [DecidableEq C] in +@[simp] theorem flipGate_square (R : Fin n → C) (ε : C → Bool) : + flipGate R ε*flipGate R ε=1 := by + change (spinFlip R ε).permMatrix ℂ*(spinFlip R ε)⁻¹.permMatrix ℂ=1 + rw [←Matrix.permMatrix_mul,inv_mul_cancel,Matrix.permMatrix_one] + +omit [Fintype C] [DecidableEq C] in +theorem flipGate_unitary (R : Fin n → C) (ε : C → Bool) : + flipGate R ε∈unitary (Operator n) := by + constructor <;> simp only [Matrix.star_eq_conjTranspose,flipGate_adjoint,flipGate_square] + +omit [Fintype C] [DecidableEq C] in +@[simp] theorem spin_spinFlip (R : Fin n → C) (ε : C → Bool) (σ : Configuration n) (i : Fin n) : + (spin (spinFlip R ε σ) i : ℂ)=MaskSign.sign ε (R i)*(spin σ i : ℂ) := by + cases h : ε (R i) <;> cases hs : σ i <;> simp [spinFlip,spin,MaskSign.sign,h,hs] + + + +omit [Fintype C] [DecidableEq C] in +theorem flipGate_conjugate_cost (R : Fin n → C) (ε : C → Bool) (J : Disorder n) : + flipGate R ε*cost n J*flipGate R ε= + ((Real.sqrt (n:ℝ))⁻¹ : ℂ) • ∑e : Edge n, + (MaskSign.sign ε (R e.1.1)*MaskSign.sign ε (R e.1.2)*(J e:ℂ)) • + (pauliZ e.1.1*pauliZ e.1.2) := by + have hd (f : Configuration n → ℂ) : + flipGate R ε*Matrix.diagonal f*flipGate R ε= + Matrix.diagonal (fun σ => f (spinFlip R ε σ)) := by + ext σ τ + simp only [flipGate,Equiv.Perm.permMatrix,PEquiv.toMatrix_toPEquiv_mul, + PEquiv.mul_toMatrix_toPEquiv,Matrix.submatrix_apply] + rw [Matrix.diagonal_apply,Matrix.diagonal_apply] + congr 1 + exact propext (Equiv.apply_eq_iff_eq (spinFlip R ε)) + rw [cost_eq_diagonal,hd] + ext σ τ + simp only [Matrix.smul_apply,Matrix.sum_apply,pauliZ,Matrix.diagonal_mul_diagonal, + Matrix.diagonal_apply,smul_eq_mul] + by_cases h : σ=τ + · subst τ + simp only [ite_true] + simp only [hamiltonian,Complex.ofReal_mul,Complex.ofReal_sum,Complex.ofReal_inv,spin_spinFlip] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he + ring + · simp [h] + +end SKQAOA.Masks + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator + +namespace MaskSign +variable {C : Type*} [Fintype C] [DecidableEq C] + + +theorem pair_projection {V : Type*} [AddCommGroup V] [Module ℂ V] + {ι : Type*} [Fintype ι] (u v : ι → C) (A : ι → V) {a b : C} (hab : a≠b) : + ((2:ℂ)^(Fintype.card C))⁻¹ • + (∑ε : C → Bool,(sign ε a*sign ε b) • + ∑i,(sign ε (u i)*sign ε (v i)) • A i)= + ∑i,if (a=u i ∧ b=v i) ∨ (a=v i ∧ b=u i) then A i else 0 := by + simp_rw [Finset.smul_sum,smul_smul,←mul_assoc] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i hi + rw [←Finset.sum_smul] + have he : (∑ε : C → Bool,((2:ℂ)^(Fintype.card C))⁻¹*sign ε a*sign ε b* + sign ε (u i)*sign ε (v i))= + ((2:ℂ)^(Fintype.card C))⁻¹* + ∑ε : C → Bool,sign ε a*sign ε b*sign ε (u i)*sign ε (v i) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro ε hε + ring + rw [he,sum_four hab] + split_ifs <;> simp + +end MaskSign + +namespace SKQAOA.Masks +variable {n : ℕ} {C : Type*} [Fintype C] [DecidableEq C] + +def pairEdges (R : Fin n → C) (a b : C) : Finset (Edge n) := + Finset.univ.filter (fun e => (a=R e.1.1 ∧ b=R e.1.2) ∨ (a=R e.1.2 ∧ b=R e.1.1)) + + + +theorem pairCost_identity (R : Fin n → C) (J : Disorder n) {a b : C} (hab : a≠b) : + Locality.maskedCost J (pairEdges R a b)= + ((2:ℂ)^(Fintype.card C))⁻¹ • + ∑ε : C → Bool,(MaskSign.sign ε a*MaskSign.sign ε b) • + (flipGate R ε*cost n J*flipGate R ε) := by + have hf (ε : C → Bool) : flipGate R ε*cost n J*flipGate R ε= + ∑e : Edge n,(MaskSign.sign ε (R e.1.1)*MaskSign.sign ε (R e.1.2)) • + (((Real.sqrt (n:ℝ))⁻¹:ℂ) • ((J e:ℂ) • (pauliZ e.1.1*pauliZ e.1.2))) := by + rw [flipGate_conjugate_cost,Finset.smul_sum] + apply Finset.sum_congr rfl + intro e he + simp only [smul_smul] + congr 1 + ring + simp_rw [hf] + rw [MaskSign.pair_projection (fun e : Edge n => R e.1.1) + (fun e : Edge n => R e.1.2) _ hab] + rw [Locality.maskedCost_sum,pairEdges,Finset.sum_filter,Finset.smul_sum] + apply Finset.sum_congr rfl + intro e he + split_ifs <;> simp + + + +omit [Fintype C] in +theorem pairEdges_distinct (R : Fin n → C) {a b : C} (hab : a≠b) + {e : Edge n} (he : e∈pairEdges R a b) : R e.1.1≠R e.1.2 := by + rcases (Finset.mem_filter.mp he).2 with ⟨ha,hb⟩ | ⟨ha,hb⟩ + · exact fun h => hab (ha.trans (h.trans hb.symm)) + · exact fun h => hab (ha.trans (h.symm.trans hb.symm)) + +end SKQAOA.Masks + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator + +namespace SKQAOA.Masks +variable {n : ℕ} {C : Type*} [Fintype C] [DecidableEq C] + +def signReal (ε : C → Bool) (a : C) : ℝ := if ε a then -1 else 1 + +omit [Fintype C] [DecidableEq C] in +@[simp] theorem signReal_cast (ε : C → Bool) (a : C) : + (signReal ε a : ℂ)=MaskSign.sign ε a := by + cases h : ε a <;> simp [signReal,MaskSign.sign,h] + +def signedDisorder (R : Fin n → C) (ε : C → Bool) (J : Disorder n) : Disorder n := + fun e => signReal ε (R e.1.1)*signReal ε (R e.1.2)*J e + +omit [Fintype C] [DecidableEq C] in +theorem flipGate_cost (R : Fin n → C) (ε : C → Bool) (J : Disorder n) : + flipGate R ε*cost n J*flipGate R ε=cost n (signedDisorder R ε J) := by + rw [flipGate_conjugate_cost] + simp only [cost,signedDisorder,Complex.ofReal_mul,signReal_cast] + +def pairWeight (a b : C) (ε : C → Bool) : ℝ := + ((2:ℝ)^(Fintype.card C))⁻¹*signReal ε a*signReal ε b + +theorem pairCost_weighted (R : Fin n → C) (J : Disorder n) {a b : C} (hab : a≠b) : + Locality.maskedCost J (pairEdges R a b)= + ∑ε : C → Bool,(pairWeight a b ε:ℂ) • cost n (signedDisorder R ε J) := by + rw [pairCost_identity R J hab,Finset.smul_sum] + apply Finset.sum_congr rfl + intro ε hε + rw [flipGate_cost] + simp only [smul_smul,pairWeight,Complex.ofReal_mul,Complex.ofReal_inv, + Complex.ofReal_pow,Complex.ofReal_ofNat,signReal_cast] + congr 1 + ring + +omit [Fintype C] [DecidableEq C] in +theorem flipGate_evolution (R : Fin n → C) (ε : C → Bool) (J : Disorder n) (t : ℝ) : + evolution t (cost n (signedDisorder R ε J))= + flipGate R ε*evolution t (cost n J)*flipGate R ε := by + let U : (Operator n)ˣ := ⟨flipGate R ε,flipGate R ε,flipGate_square R ε,flipGate_square R ε⟩ + have hr : (↑U : Operator n)=flipGate R ε := rfl + have hi : (↑(U⁻¹) : Operator n)=flipGate R ε := rfl + rw [←flipGate_cost] + unfold evolution + have he : (-(t:ℂ)*Complex.I) • (flipGate R ε*cost n J*flipGate R ε)= + (↑U : Operator n)*((-(t:ℂ)*Complex.I) • cost n J)*↑(U⁻¹) := by + rw [hr,hi,Matrix.mul_smul,Matrix.smul_mul] + rw [he,Matrix.exp_units_conj,hr,hi] + + + +theorem evolution_list_sum {ι : Type*} (A : ι → Operator n) (θ : ι → ℝ) + (hc : ∀i j,Commute (A i) (A j)) (l : List ι) : + evolution 1 ((l.map (fun i => (θ i:ℂ) • A i)).sum)= + (l.map (fun i => evolution (θ i) (A i))).prod := by + induction l with + | nil => simp [evolution] + | cons i l ih => + simp only [List.map_cons,List.sum_cons,List.prod_cons] + have hcomm : Commute ((θ i:ℂ) • A i) ((l.map (fun j => (θ j:ℂ) • A j)).sum) := by + apply Commute.list_sum_right + intro B hB + obtain ⟨j,hj,rfl⟩ := List.mem_map.mp hB + exact ((hc i j).smul_left _).smul_right _ + rw [Locality.evolution_add_of_commute 1 hcomm,ih] + congr 1 + simp only [evolution,smul_smul,Complex.ofReal_one] + congr 1 + ring_nf + + + +theorem pairCost_evolution_word (R : Fin n → C) (J : Disorder n) + {a b : C} (hab : a≠b) (t : ℝ) : + evolution t (Locality.maskedCost J (pairEdges R a b))= + (Finset.univ.toList.map (fun ε : C → Bool => + flipGate R ε*evolution (t*pairWeight a b ε) (cost n J)*flipGate R ε)).prod := by + have hs : (Finset.univ.toList.map (fun ε : C → Bool => + ((t*pairWeight a b ε:ℝ):ℂ) • cost n (signedDisorder R ε J))).sum= + (t:ℂ) • Locality.maskedCost J (pairEdges R a b) := by + rw [Finset.sum_map_toList,pairCost_weighted R J hab,Finset.smul_sum] + simp only [Complex.ofReal_mul,smul_smul] + have he : evolution t (Locality.maskedCost J (pairEdges R a b))= + evolution 1 ((t:ℂ) • Locality.maskedCost J (pairEdges R a b)) := by + simp only [evolution,smul_smul,Complex.ofReal_one] + congr 1 + ring_nf + rw [he,←hs,evolution_list_sum] + · congr 1 + apply List.map_congr_left + intro ε hε + exact flipGate_evolution R ε J _ + · intro ε δ + rw [cost_eq_diagonal,cost_eq_diagonal] + exact Matrix.commute_diagonal _ _ + +end SKQAOA.Masks + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator + +namespace SKQAOA.Masks +variable {n : ℕ} {C : Type*} [Fintype C] [DecidableEq C] + + + +omit [Fintype C] [DecidableEq C] in +theorem flipGate_tensor (R : Fin n → C) (ε : C → Bool) : + flipGate R ε=TensorMatrix.lift (fun i => if ε (R i) then TwoState.swap else 1) := by + ext σ τ + have he (i : Fin n) : + (if ε (R i) then TwoState.swap else 1) (σ i) (τ i)= + if spinFlip R ε σ i=τ i then (1:ℂ) else 0 := by + cases h : ε (R i) <;> cases hs : σ i <;> cases ht : τ i <;> + simp [spinFlip,TwoState.swap,h,hs] + simp only [flipGate,Equiv.Perm.permMatrix,PEquiv.toMatrix_apply,Equiv.toPEquiv_apply, + Option.mem_some_iff,TensorMatrix.lift,he,Fintype.prod_ite_zero,Finset.prod_const_one] + congr 1 + exact propext (show spinFlip R ε σ=τ ↔ ∀i,spinFlip R ε σ i=τ i from funext_iff) + + +theorem tensor_scalar (c : Fin n → ℂ) (A : Fin n → Matrix Bool Bool ℂ) : + TensorMatrix.lift (fun i => c i • A i)=(∏i,c i) • TensorMatrix.lift A := by + ext σ τ + simp [TensorMatrix.lift,Finset.prod_mul_distrib] + + +def maskedMixer (R : Fin n → C) (ε : C → Bool) : Operator n := + ∑i : Fin n,if ε (R i) then pauliX i else 0 + +omit [Fintype C] [DecidableEq C] in +theorem maskedMixer_evolution (R : Fin n → C) (ε : C → Bool) (t : ℝ) : + evolution t (maskedMixer R ε)= + TensorMatrix.lift (fun i => if ε (R i) then TwoState.rotation t else 1) := by + have he : (-(t:ℂ)*Complex.I) • maskedMixer R ε = + ∑i : Fin n,TensorMatrix.atSite i + (if ε (R i) then (-(t:ℂ)*Complex.I) • TwoState.swap else 0) := by + simp only [maskedMixer,Finset.smul_sum] + apply Finset.sum_congr rfl + intro i hi + split_ifs <;> simp only [smul_zero,TensorMatrix.local_zero,pauliX_eq_atSite,TensorMatrix.local_smul] + unfold evolution + rw [he,TensorMatrix.exp_sum_atSite_univ] + congr 1 + funext i + cases h : ε (R i) <;> simp [TwoState.rotation_eq_exp] + + + +omit [Fintype C] [DecidableEq C] in +theorem maskedMixer_flip (R : Fin n → C) (ε : C → Bool) : + evolution (Real.pi/2) (maskedMixer R ε)= + (∏i : Fin n,if ε (R i) then (-Complex.I) else 1) • flipGate R ε := by + rw [maskedMixer_evolution,flipGate_tensor] + have he : (fun i : Fin n => if ε (R i) then TwoState.rotation (Real.pi/2) else 1)= + fun i => (if ε (R i) then (-Complex.I) else 1) • + (if ε (R i) then TwoState.swap else 1) := by + funext i + cases h : ε (R i) <;> simp [TwoState.rotation] + rw [he,tensor_scalar] + +end SKQAOA.Masks + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +attribute [local instance] LieRing.ofAssociativeRing + +namespace SKQAOA.Helpers +variable {n : ℕ} + +theorem twoState_ZY : TwoState.z*TwoState.y-TwoState.y*TwoState.z= + (-2*Complex.I) • TwoState.swap := by + ext a b + cases a <;> cases b <;> norm_num [TwoState.z,TwoState.y,TwoState.swap, + TwoState.sign,Matrix.mul_apply,Fintype.sum_bool,Complex.I_mul_I] <;> ring + +theorem pauli_ZY (i : Fin n) : ⁅pauliZ i,pauliY i⁆=(-2*Complex.I) • pauliX i := by + have h := congrArg (TensorMatrix.localAlgHom i) twoState_ZY + simp only [map_sub,map_mul,map_smul] at h + change TensorMatrix.atSite i TwoState.z*TensorMatrix.atSite i TwoState.y- + TensorMatrix.atSite i TwoState.y*TensorMatrix.atSite i TwoState.z= + (-2*Complex.I) • TensorMatrix.atSite i TwoState.swap at h + simpa only [Ring.lie_def,pauliY,pauliX_eq_atSite,pauliZ_eq_atSite] using h + +theorem commute_pauliX (i j : Fin n) : Commute (pauliX i) (pauliX j) := by + by_cases h : i=j + · subst j; exact Commute.refl _ + · rw [pauliX_eq_atSite,pauliX_eq_atSite] + exact TensorMatrix.atSite_commute h _ _ + +theorem disjoint_ne {S T : Finset (Fin n)} (h : Disjoint S T) + {i j : Fin n} (hi : i∈S) (hj : j∈T) : i≠j := by + intro e + subst j + exact Finset.disjoint_left.mp h hi hj + + +theorem coefficient_bracket (B F : Operator n) (i : Fin n) + (hBF : Commute B F) (hZ : Commute (pauliZ i) F) + (hY : Commute (pauliY i) B) : + ⁅B*pauliZ i,F*pauliY i⁆=(-2*Complex.I) • (B*F*pauliX i) := by + rw [Ring.lie_def,hZ.mul_mul_mul_comm,hY.mul_mul_mul_comm,hBF.symm.eq, + ←mul_sub,←Ring.lie_def,pauli_ZY,Matrix.mul_smul] + + + +theorem pivot_sum_commutator (K : Finset (Fin n)) (B F : Fin n → Operator n) + (hBF : ∀i∈K,∀j∈K,Commute (B i) (F j)) + (hB : ∀i∈K,∀j∈K,Commute (B i) (pauliY j)) + (hF : ∀i∈K,∀j∈K,Commute (F i) (pauliZ j)) : + ⁅∑i∈K,B i*pauliZ i,∑i∈K,F i*pauliY i⁆= + (-2*Complex.I) • ∑i∈K,B i*F i*pauliX i := by + rw [sum_lie_sum,Finset.smul_sum] + apply Finset.sum_congr rfl + intro i hi + rw [Finset.sum_eq_single i] + · exact coefficient_bracket _ _ _ (hBF i hi i hi) (hF i hi i hi).symm (hB i hi i hi).symm + · intro j hj hji + have hZY : Commute (pauliZ i) (pauliY j) := by + rw [pauliY,pauliZ_eq_atSite] + exact TensorMatrix.atSite_commute (Ne.symm hji) _ _ + have hc : Commute (B i*pauliZ i) (F j*pauliY j) := + ((hBF i hi j hj).mul_left (hF j hj i hi).symm).mul_right + ((hB i hi j hj).mul_left hZY) + exact sub_eq_zero.mpr hc.eq + · exact fun h => (h hi).elim + + +def b (A : Fin n → Fin n → ℂ) (I : Finset (Fin n)) + (P : Matrix Bool Bool ℂ) (j : Fin n) : Operator n := + ∑i∈I,A j i • TensorMatrix.atSite i P + +def B (A : Fin n → Fin n → ℂ) (I J : Finset (Fin n)) + (P : Matrix Bool Bool ℂ) (k : Fin n) : Operator n := + ∑j∈J,A k j • (pauliX j*b A I P j) + +def F (A : Fin n → Fin n → ℂ) (J : Finset (Fin n)) (f : Fin n → ℂ) + (k : Fin n) : Operator n := + ∑j∈J,(A k j*f j) • pauliX j + +theorem b_commute_local (A : Fin n → Fin n → ℂ) (I : Finset (Fin n)) + (P Q : Matrix Bool Bool ℂ) (j k : Fin n) (hk : k∉I) : + Commute (b A I P j) (TensorMatrix.atSite k Q) := by + apply Commute.sum_left + intro i hi + exact (TensorMatrix.atSite_commute (i:=i) (j:=k) (fun h => hk (h ▸ hi)) P Q).smul_left _ + +theorem B_commute_local (A : Fin n → Fin n → ℂ) (I J : Finset (Fin n)) + (P Q : Matrix Bool Bool ℂ) (j k : Fin n) (hkI : k∉I) (hkJ : k∉J) : + Commute (B A I J P j) (TensorMatrix.atSite k Q) := by + apply Commute.sum_left + intro i hi + apply Commute.smul_left + apply Commute.mul_left + · rw [pauliX_eq_atSite] + exact TensorMatrix.atSite_commute (i:=i) (j:=k) (fun h => hkJ (h ▸ hi)) _ _ + · exact b_commute_local _ _ _ _ _ _ hkI + +theorem F_commute_local (A : Fin n → Fin n → ℂ) (J : Finset (Fin n)) + (f : Fin n → ℂ) (Q : Matrix Bool Bool ℂ) (j k : Fin n) (hk : k∉J) : + Commute (F A J f j) (TensorMatrix.atSite k Q) := by + apply Commute.sum_left + intro i hi + apply Commute.smul_left + rw [pauliX_eq_atSite] + exact TensorMatrix.atSite_commute (i:=i) (j:=k) (fun h => hk (h ▸ hi)) _ _ + +theorem B_commute_F (A : Fin n → Fin n → ℂ) (I J : Finset (Fin n)) + (P : Matrix Bool Bool ℂ) (f : Fin n → ℂ) (k l : Fin n) (hIJ : Disjoint I J) : + Commute (B A I J P k) (F A J f l) := by + apply Commute.sum_right + intro j hj + apply Commute.smul_right + apply Commute.sum_left + intro i hi + apply Commute.smul_left + apply Commute.mul_left (commute_pauliX _ _) + rw [pauliX_eq_atSite] + exact b_commute_local _ _ _ _ _ _ (fun h => Finset.disjoint_left.mp hIJ h hj) + + + +theorem helper_commutator (A : Fin n → Fin n → ℂ) (I J K : Finset (Fin n)) + (P : Matrix Bool Bool ℂ) (f : Fin n → ℂ) + (hIJ : Disjoint I J) (hIK : Disjoint I K) (hJK : Disjoint J K) : + ⁅∑k∈K,B A I J P k*pauliZ k,∑k∈K,F A J f k*pauliY k⁆= + (-2*Complex.I) • ∑k∈K,B A I J P k*F A J f k*pauliX k := by + apply pivot_sum_commutator + · intro i hi j hj + exact B_commute_F _ _ _ _ _ _ _ hIJ + · intro i hi j hj + rw [pauliY] + exact B_commute_local _ _ _ _ _ _ _ + (fun h => Finset.disjoint_left.mp hIK h hj) + (fun h => Finset.disjoint_left.mp hJK h hj) + · intro i hi j hj + rw [pauliZ_eq_atSite] + exact F_commute_local _ _ _ _ _ _ + (fun h => Finset.disjoint_left.mp hJK h hj) + +end SKQAOA.Helpers + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator + +namespace SKQAOA.Masks +variable {n : ℕ} {C : Type*} [Fintype C] [DecidableEq C] + +omit [Fintype C] [DecidableEq C] in +theorem maskedMixer_hermitian (R : Fin n → C) (ε : C → Bool) : + (maskedMixer R ε).IsHermitian := by + unfold maskedMixer Matrix.IsHermitian + rw [Matrix.conjTranspose_sum] + apply Finset.sum_congr rfl + intro i hi + cases h : ε (R i) <;> simp only [Bool.false_eq_true,ite_false,ite_true, + Matrix.conjTranspose_zero] + exact pauliX_hermitian i + + + +omit [Fintype C] [DecidableEq C] in +theorem maskedMixer_conjugate (R : Fin n → C) (ε : C → Bool) (A : Operator n) : + evolution (Real.pi/2) (maskedMixer R ε)*A* + evolution (-(Real.pi/2)) (maskedMixer R ε)=flipGate R ε*A*flipGate R ε := by + rw [evolution_neg_adjoint _ (maskedMixer_hermitian R ε),maskedMixer_flip, + Matrix.conjTranspose_smul,flipGate_adjoint,Matrix.smul_mul,Matrix.mul_smul,Matrix.smul_mul,smul_smul] + have hp : (∏i : Fin n,if ε (R i) then (-Complex.I) else 1)* + star (∏i : Fin n,if ε (R i) then (-Complex.I) else 1)=1 := by + rw [star_prod,←Finset.prod_mul_distrib] + apply Finset.prod_eq_one + intro i hi + cases h : ε (R i) <;> simp [Complex.I_mul_I] + rw [mul_comm (star _),hp,one_smul] + + + +theorem pairCost_physical_word (R : Fin n → C) (J : Disorder n) + {a b : C} (hab : a≠b) (t : ℝ) : + evolution t (Locality.maskedCost J (pairEdges R a b))= + (Finset.univ.toList.map (fun ε : C → Bool => + evolution (Real.pi/2) (maskedMixer R ε)* + evolution (t*pairWeight a b ε) (cost n J)* + evolution (-(Real.pi/2)) (maskedMixer R ε))).prod := by + rw [pairCost_evolution_word R J hab t] + congr 1 + apply List.map_congr_left + intro ε hε + exact (maskedMixer_conjugate R ε _).symm + +end SKQAOA.Masks + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator + +namespace SKQAOA.Helpers +variable {n : ℕ} + +@[simp] theorem pauliX_square (i : Fin n) : pauliX i*pauliX i=1 := by + rw [pauliX_eq_atSite,←TensorMatrix.local_mul,←TensorMatrix.local_one i] + congr 1 + ext a b + cases a <;> cases b <;> norm_num [TwoState.swap,Matrix.mul_apply,Fintype.sum_bool] + + +theorem BF_expansion (A : Fin n → Fin n → ℂ) (I J : Finset (Fin n)) + (P : Matrix Bool Bool ℂ) (f : Fin n → ℂ) (k : Fin n) : + B A I J P k*F A J f k= + ∑j∈J,∑l∈J,(A k j*(A k l*f l)) • (pauliX j*b A I P j*pauliX l) := by + unfold B F + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro j hj + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro l hl + rw [Matrix.smul_mul,Matrix.mul_smul,smul_smul] + + + +theorem diagonal_sender (A : Fin n → Fin n → ℂ) (I J : Finset (Fin n)) + (P : Matrix Bool Bool ℂ) (f : Fin n → ℂ) (k j : Fin n) + (hIJ : Disjoint I J) (hj : j∈J) : + (A k j • (pauliX j*b A I P j))*((A k j*f j) • pauliX j)= + (A k j^2*f j) • b A I P j := by + have hc : Commute (b A I P j) (pauliX j) := by + rw [pauliX_eq_atSite] + exact b_commute_local _ _ _ _ _ _ (fun h => Finset.disjoint_left.mp hIJ h hj) + rw [Matrix.smul_mul,Matrix.mul_smul,smul_smul,←hc.eq,mul_assoc,pauliX_square,mul_one] + congr 1 + ring + + + +def diagonalGenerator (A : Fin n → Fin n → ℂ) (I J K : Finset (Fin n)) + (P : Matrix Bool Bool ℂ) (f : Fin n → ℂ) : Operator n := + ∑k∈K,∑j∈J,(A k j^2*f j) • (b A I P j*pauliX k) + + + +theorem diagonalGenerator_pinned (A : Fin n → Fin n → ℂ) (I J K : Finset (Fin n)) + (P : Matrix Bool Bool ℂ) (f : Fin n → ℂ) (ψ : State n) + (hpin : ∀k∈K,(pauliX k).mulVec ψ=ψ) : + (diagonalGenerator A I J K P f).mulVec ψ= + (∑j∈J,((∑k∈K,A k j^2)*f j) • b A I P j).mulVec ψ := by + simp only [diagonalGenerator,Matrix.sum_mulVec,Matrix.smul_mulVec, + ←Matrix.mulVec_mulVec] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro j hj + rw [Finset.sum_mul,Finset.sum_smul] + apply Finset.sum_congr rfl + intro k hk + rw [hpin k hk] + + + +theorem preserve_pin (i : Fin n) (U : Operator n) (ψ : State n) + (hU : Commute (pauliX i) U) (hψ : (pauliX i).mulVec ψ=ψ) : + (pauliX i).mulVec (U.mulVec ψ)=U.mulVec ψ := by + rw [Matrix.mulVec_mulVec,hU.eq,←Matrix.mulVec_mulVec,hψ] + +end SKQAOA.Helpers + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SpinMatrix.lean b/lean/OAI/Probability/ParisiFinite/SpinMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..171b5a14eb6091f730bce7a51e500b10d48f525b --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SpinMatrix.lean @@ -0,0 +1,671 @@ +import Mathlib +import OAI.Probability.ParisiFinite.FiniteMaxHamiltonian + +namespace OAI + +/-! Spin Matrix. -/ + +noncomputable section + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators ComplexConjugate +open MeasureTheory ProbabilityTheory +open scoped Topology +open Filter +open scoped BigOperators Matrix + +namespace SeedControl + +attribute [local instance 100] LieRing.ofAssociativeRing + +abbrev SpinMatrix := Matrix (Fin 2) (Fin 2) ℂ + +def x : SpinMatrix := !![0, -Complex.I; -Complex.I, 0] +def y : SpinMatrix := !![0, -1; 1, 0] +def z : SpinMatrix := !![-Complex.I, 0; 0, Complex.I] + +theorem lie_z_y : ⁅z,y⁆ = (-2 : ℝ) • x := by + ext i j + fin_cases i <;> fin_cases j <;> simp [Ring.lie_def, x, y, z] <;> ring + +theorem lie_z_lie_z_x : ⁅z,⁅z,x⁆⁆ = (-4 : ℝ) • x := by + ext i j + fin_cases i <;> fin_cases j <;> simp [Ring.lie_def, x, z] <;> ring + +abbrev Ensemble (ι : Type*) := (ι → SpinMatrix) × (ℝ × ℝ) + +def generatorZ {ι : Type*} (c : ι → ℝ) : Ensemble ι := (fun i => c i • z, 1, 0) +def generatorY {ι : Type*} (d : ι → ℝ) : Ensemble ι := (fun i => d i • y, 0, 1) +def fieldX {ι : Type*} (f : ι → ℝ) : Ensemble ι := (fun i => f i • x, 0, 0) + +theorem generator_bracket {ι : Type*} (c d : ι → ℝ) : + ⁅generatorZ c, generatorY d⁆ = (-2 : ℝ) • fieldX (fun i => c i * d i) := by + apply Prod.ext + · funext i + change ⁅c i • z, d i • y⁆ = (-2 : ℝ) • ((c i * d i) • x) + rw [smul_lie, lie_smul, lie_z_y] + simp only [smul_smul] + congr 1 + ring + · ext <;> simp [generatorZ, generatorY, fieldX, Ring.lie_def] + +theorem generator_double_bracket {ι : Type*} (c f : ι → ℝ) : + ⁅generatorZ c, ⁅generatorZ c, fieldX f⁆⁆ = (-4 : ℝ) • fieldX (fun i => c i ^ 2 * f i) := by + apply Prod.ext + · funext i + change ⁅c i • z, ⁅c i • z, f i • x⁆⁆ = (-4 : ℝ) • ((c i ^ 2 * f i) • x) + rw [smul_lie, smul_lie, lie_smul, lie_smul, lie_smul, lie_z_lie_z_x] + simp only [smul_smul] + congr 1 + ring + · ext <;> simp [generatorZ, fieldX, Ring.lie_def] + +theorem fieldX_mul_mem {ι : Type*} (L : LieSubalgebra ℝ (Ensemble ι)) + {c d : ι → ℝ} (hc : generatorZ c ∈ L) (hd : generatorY d ∈ L) : + fieldX (fun i => c i * d i) ∈ L := by + have h := L.lie_mem hc hd + rw [generator_bracket] at h + have h' := L.smul_mem (-1/2 : ℝ) h + simpa only [smul_smul, show (-1/2:ℝ)*(-2)=1 by norm_num, one_smul] using h' + +theorem fieldX_sq_mul_mem {ι : Type*} (L : LieSubalgebra ℝ (Ensemble ι)) + {c f : ι → ℝ} (hc : generatorZ c ∈ L) (hf : fieldX f ∈ L) : + fieldX (fun i => c i ^ 2 * f i) ∈ L := by + have h := L.lie_mem hc (L.lie_mem hc hf) + rw [generator_double_bracket] at h + have h' := L.smul_mem (-1/4 : ℝ) h + simpa only [smul_smul, show (-1/4:ℝ)*(-4)=1 by norm_num, one_smul] using h' + +@[simp] theorem fieldX_add {ι : Type*} (f g : ι → ℝ) : + fieldX (fun i => f i + g i) = fieldX f + fieldX g := by + apply Prod.ext + · funext i; exact add_smul _ _ _ + · simp [fieldX] + +@[simp] theorem fieldX_const_mul {ι : Type*} (t : ℝ) (f : ι → ℝ) : + fieldX (fun i => t * f i) = t • fieldX f := by + apply Prod.ext + · funext i; exact mul_smul _ _ _ + · simp [fieldX] + +theorem weighted_power_mem {ι : Type*} (L : LieSubalgebra ℝ (Ensemble ι)) + {c d : ι → ℝ} (hc : generatorZ c ∈ L) (hd : generatorY d ∈ L) (k : ℕ) : + fieldX (fun i => c i * d i * (c i ^ 2)^k) ∈ L := by + induction k with + | zero => simpa using fieldX_mul_mem L hc hd + | succ k ih => + have h := fieldX_sq_mul_mem L hc ih + convert h using 1 + congr 1 + funext i + ring + +theorem weighted_polynomial_mem {ι : Type*} (L : LieSubalgebra ℝ (Ensemble ι)) + {c d : ι → ℝ} (hc : generatorZ c ∈ L) (hd : generatorY d ∈ L) (P : Polynomial ℝ) : + fieldX (fun i => c i * d i * P.eval (c i ^ 2)) ∈ L := by + induction P using Polynomial.induction_on' with + | add P Q hP hQ => + simpa only [Polynomial.eval_add, mul_add, fieldX_add] using L.add_mem hP hQ + | monomial k a => + have h := L.smul_mem a (weighted_power_mem L hc hd k) + rw [← fieldX_const_mul] at h + convert h using 1 + congr 1 + funext i + rw [Polynomial.eval_monomial] + ring + + +theorem interpolate_finite_fibers {ι : Type*} [Fintype ι] (a b : ι → ℝ) + (h : ∀ i j, a i = a j → b i = b j) : + ∃ P : Polynomial ℝ, ∀ i, P.eval (a i) = b i := by + classical + let f : ℝ → ℝ := fun t => if ht : ∃ i, a i = t then b ht.choose else 0 + have hf (i : ι) : f (a i) = b i := by + dsimp only [f] + rw [dite_eq_left ⟨i, rfl⟩] + exact h _ _ (Exists.choose_spec (show ∃ j, a j = a i from ⟨i, rfl⟩)) + refine ⟨Lagrange.interpolate (Finset.univ.image a) id f, fun i => ?_⟩ + calc + _ = f (a i) := Lagrange.eval_interpolate_at_node f (fun _ _ _ _ he => he) + (Finset.mem_image.mpr ⟨i, Finset.mem_univ i, rfl⟩) + _ = b i := hf i + + + +theorem common_axis_mem {ι : Type*} [Fintype ι] (L : LieSubalgebra ℝ (Ensemble ι)) + {c d : ι → ℝ} (hc : generatorZ c ∈ L) (hd : generatorY d ∈ L) + (hn : ∀ i, c i * d i ≠ 0) + (hs : ∀ i j, c i ^ 2 = c j ^ 2 → c i * d i = c j * d j) : + fieldX (fun _ => 1) ∈ L := by + obtain ⟨P, hP⟩ := interpolate_finite_fibers (fun i => c i ^ 2) + (fun i => (c i * d i)⁻¹) (fun i j he => congrArg Inv.inv (hs i j he)) + have h := weighted_polynomial_mem L hc hd P + simpa only [hP, mul_inv_cancel₀ (hn _)] using h + + +theorem exists_generic_slope (s : Finset (ℝ × ℝ)) (h : ∀ v ∈ s, v ≠ 0) : + ∃ t : ℝ, ∀ v ∈ s, v.1 + t * v.2 ≠ 0 := by + classical + obtain ⟨t, ht⟩ := (s.finite_toSet.image (fun v : ℝ × ℝ => -v.1 / v.2)).exists_notMem + refine ⟨t, fun v hv he => ?_⟩ + by_cases hv2 : v.2 = 0 + · have hv1 : v.1 = 0 := by simpa [hv2] using he + exact h v hv (Prod.ext hv1 hv2) + · apply ht + exact ⟨v, hv, (eq_div_iff hv2).mpr (by nlinarith) |>.symm⟩ + + + +theorem exists_separating_frame {ι : Type*} [Fintype ι] + (v : ι → ℝ × ℝ) (hv : ∀ i, v i ≠ 0) : + ∃ a b : ℝ, a^2+b^2=1 ∧ + (∀ i, (a*(v i).1+b*(v i).2) * (-b*(v i).1+a*(v i).2) ≠ 0) ∧ + (∀ i j, (a*(v i).1+b*(v i).2)^2 = (a*(v j).1+b*(v j).2)^2 → + v i = v j ∨ v i = -v j) := by + classical + let s : Finset (ℝ × ℝ) := + (Finset.univ.image v ∪ Finset.univ.image (fun i => ((v i).2, -(v i).1)) ∪ + (Finset.univ.product Finset.univ).image (fun ij : ι × ι => v ij.1 - v ij.2) ∪ + (Finset.univ.product Finset.univ).image (fun ij : ι × ι => v ij.1 + v ij.2)).erase 0 + obtain ⟨t, ht⟩ := exists_generic_slope s (fun w hw => (Finset.mem_erase.mp hw).1) + have hproj (i : ι) : (v i).1 + t*(v i).2 ≠ 0 := by + apply ht + simp [s, hv i] + have hperp (i : ι) : (v i).2 - t*(v i).1 ≠ 0 := by + have hn : ((v i).2, -(v i).1) ≠ (0 : ℝ×ℝ) := by + intro h + apply hv i + exact Prod.ext (neg_eq_zero.mp (congrArg Prod.snd h)) (congrArg Prod.fst h) + have hm : ((v i).2, -(v i).1) ∈ s := by + simp [s, hn] + exact Or.inr (Or.inl ⟨i,rfl,rfl⟩) + simpa only [mul_neg, ← sub_eq_add_neg] using ht _ hm + have hsep (i j : ι) : ((v i).1+t*(v i).2)^2 = ((v j).1+t*(v j).2)^2 → + v i = v j ∨ v i = -v j := by + intro he + rcases sq_eq_sq_iff_eq_or_eq_neg.mp he with he | he + · by_contra hn + have hn' : v i - v j ≠ 0 := sub_ne_zero.mpr (not_or.mp hn).1 + have hm : v i - v j ∈ s := by simp [s, hn'] + apply ht _ hm + change (v i).1-(v j).1 + t*((v i).2-(v j).2) = 0 + linarith + · by_contra hn + have hn' : v i + v j ≠ 0 := by + intro hz + exact (not_or.mp hn).2 (eq_neg_of_add_eq_zero_left hz) + have hm : v i + v j ∈ s := by simp [s, hn'] + apply ht _ hm + change (v i).1+(v j).1 + t*((v i).2+(v j).2) = 0 + linarith + let r := Real.sqrt (1+t^2) + have hr : 0 < r := Real.sqrt_pos.2 (by positivity) + have hr2 : r^2 = 1+t^2 := Real.sq_sqrt (by positivity) + refine ⟨1/r,t/r,?_,?_,?_⟩ + · field_simp + nlinarith [sq_nonneg t] + · intro i + rw [show 1/r*(v i).1+(t/r)*(v i).2 = ((v i).1+t*(v i).2)/r by ring, + show -(t/r)*(v i).1+(1/r)*(v i).2 = ((v i).2-t*(v i).1)/r by ring] + exact mul_ne_zero (div_ne_zero (hproj i) hr.ne') (div_ne_zero (hperp i) hr.ne') + · intro i j he + apply hsep i j + have he' : (((v i).1+t*(v i).2)/r)^2 = (((v j).1+t*(v j).2)/r)^2 := by + convert he using 1 <;> ring + simpa only [div_pow, div_left_inj' (pow_ne_zero 2 hr.ne')] using he' + + + +theorem common_axis_generated {ι : Type*} [Fintype ι] + (v : ι → ℝ × ℝ) (hv : ∀ i, v i ≠ 0) : + ∃ a b : ℝ, a^2+b^2=1 ∧ + fieldX (fun _ : ι => 1) ∈ LieSubalgebra.lieSpan ℝ (Ensemble ι) + {generatorZ (fun i => a*(v i).1+b*(v i).2), + generatorY (fun i => -b*(v i).1+a*(v i).2)} := by + obtain ⟨a,b,hab,hn,hs⟩ := exists_separating_frame v hv + refine ⟨a,b,hab,common_axis_mem _ ?_ ?_ hn ?_⟩ + · exact LieSubalgebra.subset_lieSpan (by simp) + · exact LieSubalgebra.subset_lieSpan (by simp) + · intro i j he + rcases hs i j he with h | h + · simp [h] + · simp only [h, Prod.fst_neg, Prod.snd_neg] + ring + +end SeedControl + +namespace QuaternionControl +open PulseControl ExactPulseControl +variable {ι : Type*} [Fintype ι] +abbrev QField (ι : Type*) := ι → Quaternion ℝ +instance quaternionStarModule : StarModule ℝ (Quaternion ℝ) where + star_smul := by intro r q; ext <;> simp + +local instance spinMatrixQFieldNormedAlgebra : NormedAlgebra ℚ (QField ι) := + NormedAlgebra.restrictScalars ℚ ℝ (QField ι) + +def qX (f : ι → ℝ) : QField ι := fun i => ⟨0,0,0,f i⟩ +def qY (f : ι → ℝ) : QField ι := fun i => ⟨0,0,f i,0⟩ +def qZ (f : ι → ℝ) : QField ι := fun i => ⟨0,f i,0,0⟩ +def gen (c d : ι → ℝ) (a : Bool) : QField ι := if a then qZ c else qY d + +def tang (c d : ι → ℝ) := actualTangents (gen c d) + +omit [Fintype ι] in +@[simp] theorem qX_add (f g : ι → ℝ) : qX (fun i => f i+g i)=qX f+qX g := by + funext i + change (⟨0,0,0,f i+g i⟩ : Quaternion ℝ) = (⟨0,0,0,f i⟩ : Quaternion ℝ) + (⟨0,0,0,g i⟩ : Quaternion ℝ) + ext <;> simp +omit [Fintype ι] in +@[simp] theorem qX_smul (t : ℝ) (f : ι → ℝ) : qX (fun i => t*f i)=t • qX f := by + funext i + change (⟨0,0,0,t*f i⟩ : Quaternion ℝ) = t • (⟨0,0,0,f i⟩ : Quaternion ℝ) + ext <;> simp +omit [Fintype ι] in +theorem bracket_zy (c d : ι → ℝ) : qZ c*qY d-qY d*qZ c=(2:ℝ) • qX (fun i => c i*d i) := by + funext i + change (⟨0,c i,0,0⟩ : Quaternion ℝ) * (⟨0,0,d i,0⟩ : Quaternion ℝ) - + (⟨0,0,d i,0⟩ : Quaternion ℝ) * (⟨0,c i,0,0⟩ : Quaternion ℝ) = + (2:ℝ) • (⟨0,0,0,c i*d i⟩ : Quaternion ℝ) + ext <;> simp; ring +omit [Fintype ι] in +theorem bracket_zx (c f : ι → ℝ) : qZ c*qX f-qX f*qZ c=qY (fun i => -2*c i*f i) := by + funext i + change (⟨0,c i,0,0⟩ : Quaternion ℝ) * (⟨0,0,0,f i⟩ : Quaternion ℝ) - + (⟨0,0,0,f i⟩ : Quaternion ℝ) * (⟨0,c i,0,0⟩ : Quaternion ℝ) = + (⟨0,0,-2*c i*f i,0⟩ : Quaternion ℝ) + ext <;> simp; ring +omit [Fintype ι] in +theorem bracket_yx (d f : ι → ℝ) : qY d*qX f-qX f*qY d=qZ (fun i => 2*d i*f i) := by + funext i + change (⟨0,0,d i,0⟩ : Quaternion ℝ) * (⟨0,0,0,f i⟩ : Quaternion ℝ) - + (⟨0,0,0,f i⟩ : Quaternion ℝ) * (⟨0,0,d i,0⟩ : Quaternion ℝ) = + (⟨0,2*d i*f i,0,0⟩ : Quaternion ℝ) + ext <;> simp; ring +omit [Fintype ι] in +theorem double_zx (c f : ι → ℝ) : + qZ c*(qZ c*qX f-qX f*qZ c)-(qZ c*qX f-qX f*qZ c)*qZ c=(-4:ℝ) • qX (fun i => c i^2*f i) := by + rw [bracket_zx,bracket_zy] + rw [← qX_smul, ← qX_smul] + congr 1 + funext i + ring + +theorem weighted_mem (c d : ι → ℝ) : qX (fun i => c i*d i) ∈ tang c d := by + have h := bracket_actualTangents (gen c d) true false + change qZ c*qY d-qY d*qZ c ∈ tang c d at h + rw [bracket_zy] at h + have hh := (tang c d).smul_mem (1/2 : ℝ) h + simpa only [smul_smul,show (1/2:ℝ)*2=1 by norm_num,one_smul] using hh + +theorem weighted_sq_mem {c d f : ι → ℝ} (hf : qX f ∈ tang c d) : + qX (fun i => c i^2*f i) ∈ tang c d := by + have h := bracket_closed_actualTangents (gen c d) true (bracket_closed_actualTangents (gen c d) true hf) + change qZ c*(qZ c*qX f-qX f*qZ c)-(qZ c*qX f-qX f*qZ c)*qZ c ∈ tang c d at h + rw [double_zx] at h + have hh := (tang c d).smul_mem (-1/4 : ℝ) h + simpa only [smul_smul,show (-1/4:ℝ)*(-4)=1 by norm_num,one_smul] using hh + +theorem weighted_power_mem (c d : ι → ℝ) (k : ℕ) : + qX (fun i => c i*d i*(c i^2)^k) ∈ tang c d := by + induction k with + | zero => simpa using weighted_mem c d + | succ k ih => + convert weighted_sq_mem ih using 1 + congr 1; funext i; ring + +theorem weighted_polynomial_mem (c d : ι → ℝ) (P : Polynomial ℝ) : + qX (fun i => c i*d i*P.eval (c i^2)) ∈ tang c d := by + induction P using Polynomial.induction_on' with + | add P Q hp hq => simpa [Polynomial.eval_add,mul_add] using (tang c d).add_mem hp hq + | monomial k r => + convert (tang c d).smul_mem r (weighted_power_mem c d k) using 1 + rw [← qX_smul] + congr 1; funext i; simp [Polynomial.eval_monomial]; ring + +theorem all_X_mem (c d : ι → ℝ) (hn : ∀ i, c i*d i ≠ 0) + (hi : Function.Injective (fun i => c i^2)) (f : ι → ℝ) : qX f ∈ tang c d := by + obtain ⟨P,hP⟩ := SeedControl.interpolate_finite_fibers (fun i => c i^2) (fun i => f i/(c i*d i)) + (fun i j h => by rw [hi h]) + convert weighted_polynomial_mem c d P using 1 + congr 1; funext i + rw [hP i] + exact (mul_div_cancel₀ _ (hn i)).symm + +theorem all_Y_mem (c d : ι → ℝ) (hn : ∀ i, c i*d i ≠ 0) + (hi : Function.Injective (fun i => c i^2)) (f : ι → ℝ) : qY f ∈ tang c d := by + have h := bracket_closed_actualTangents (gen c d) true (all_X_mem c d hn hi (fun i => f i/(-2*c i))) + change qZ c*qX _-qX _*qZ c ∈ tang c d at h + rw [bracket_zx] at h + convert h using 1 + congr 1; funext i + have hc : c i ≠ 0 := (mul_ne_zero_iff.mp (hn i)).1 + field_simp + +theorem all_Z_mem (c d : ι → ℝ) (hn : ∀ i, c i*d i ≠ 0) + (hi : Function.Injective (fun i => c i^2)) (f : ι → ℝ) : qZ f ∈ tang c d := by + have h := bracket_closed_actualTangents (gen c d) false (all_X_mem c d hn hi (fun i => f i/(2*d i))) + change qY d*qX _-qX _*qY d ∈ tang c d at h + rw [bracket_yx] at h + convert h using 1 + congr 1; funext i + have hd : d i ≠ 0 := (mul_ne_zero_iff.mp (hn i)).2 + field_simp + +end QuaternionControl + +namespace QuaternionControl +open PulseControl ExactPulseControl +variable {ι : Type*} [Fintype ι] +local instance : NormedAlgebra ℚ (QField ι) := NormedAlgebra.restrictScalars ℚ ℝ (QField ι) + + +def imagProj : QField ι →L[ℝ] (ι → Fin 3 → ℝ) := + LinearMap.toContinuousLinearMap + { toFun := fun q i => ![(q i).imI,(q i).imJ,(q i).imK] + map_add' := by intro q r; ext i j; fin_cases j <;> rfl + map_smul' := by intro t q; ext i j; fin_cases j <;> rfl } + +@[simp] theorem imagProj_apply (q : QField ι) (i : ι) : + imagProj q i = ![(q i).imI,(q i).imJ,(q i).imK] := rfl + +@[simp] theorem imagProj_one : imagProj (1 : QField ι) = 0 := by + ext i j; fin_cases j <;> rfl + +omit [Fintype ι] in +theorem gen_skew (c d : ι → ℝ) (a : Bool) : gen c d a ∈ skewAdjoint (QField ι) := by + rw [skewAdjoint.mem_iff] + funext i + change star (gen c d a i : Quaternion ℝ) = -(gen c d a i : Quaternion ℝ) + cases a <;> change star (⟨0,_,_,0⟩ : Quaternion ℝ) = -(⟨0,_,_,0⟩ : Quaternion ℝ) <;> ext <;> simp + +theorem tangent_projection_surjective (c d : ι → ℝ) (hn : ∀ i, c i*d i ≠ 0) + (hi : Function.Injective (fun i => c i^2)) (r : ι → Fin 3 → ℝ) : + ∃ X ∈ actualTangents (gen c d), imagProj X=r := by + refine ⟨qZ (fun i => r i 0)+qY (fun i => r i 1)+qX (fun i => r i 2), + (tang c d).add_mem ((tang c d).add_mem (all_Z_mem c d hn hi _) (all_Y_mem c d hn hi _)) + (all_X_mem c d hn hi _),?_⟩ + rw [map_add,map_add] + ext i j + fin_cases j <;> simp [imagProj,qZ,qY,qX] + +theorem positive_re_nhds : {q : QField ι | ∀ i, 0 < (q i).re} ∈ 𝓝 1 := by + have h (i : ι) : ∀ᶠ q : QField ι in 𝓝 1, 0 < (q i).re := + (Quaternion.continuous_re.comp (continuous_apply i)).continuousAt.eventually (eventually_gt_nhds (by change (0 : ℝ) < 1; norm_num : (0 : ℝ) < (1 : Quaternion ℝ).re)) + exact Filter.eventually_all.mpr h + +theorem normSq_of_reachable (c d : ι → ℝ) {q : QField ι} (hq : q ∈ zeroClockWords (gen c d)) (i : ι) : + Quaternion.normSq (q i)=1 := by + have hU := zeroClockWords_le_unitary (gen c d) (gen_skew c d) hq + have h := congrFun (Unitary.star_mul_self_of_mem hU) i + change star (q i)*q i=1 at h + rw [Quaternion.star_mul_self] at h + exact congrArg QuaternionAlgebra.re h + +theorem unit_positive_imag_injective {p q : Quaternion ℝ} (hp : Quaternion.normSq p=1) + (hq : Quaternion.normSq q=1) (hp0 : 0 c i^2)) : + ∀ᶠ q : QField ι in 𝓝 1, + (∀ i, Quaternion.normSq (q i)=1) → q ∈ zeroClockWords (gen c d) := by + have h := surjective_tangents_reachable_nhds (gen c d) imagProj + (tangent_projection_surjective c d hn hi) _ positive_re_nhds + have hh : ∀ᶠ q : QField ι in 𝓝 1, + ∃ r ∈ zeroClockWords (gen c d), (∀ i, 0<(r i).re) ∧ imagProj r=imagProj q := + imagProj.continuous.continuousAt h + filter_upwards [hh,positive_re_nhds (ι := ι)] with q ⟨r,hr,hr0,he⟩ hq0 hq + have hre : r=q := by + funext i + exact unit_positive_imag_injective (normSq_of_reachable c d hr i) (hq i) (hr0 i) (hq0 i) + (congrFun (congrFun he i) 0) (congrFun (congrFun he i) 1) (congrFun (congrFun he i) 2) + simpa [hre] using hr + + +theorem exact_imaginary (c d : ι → ℝ) (hn : ∀ i, c i*d i ≠ 0) + (hi : Function.Injective (fun i => c i^2)) (X : QField ι) (hX : ∀ i, (X i).re=0) : + NormedSpace.exp X ∈ zeroClockWords (gen c d) := by + have hs : Tendsto (fun n : ℕ => ((n : ℝ)⁻¹) • X) atTop (𝓝 0) := by + have ht : Tendsto (fun n : ℕ => ((n : ℝ)⁻¹)) atTop (𝓝 (0 : ℝ)) := tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop + convert! ht.smul_const X using 1 + simp + have he : Tendsto (fun n : ℕ => NormedSpace.exp (((n : ℝ)⁻¹) • X)) atTop (𝓝 1) := by + convert! NormedSpace.exp_continuous.continuousAt.tendsto.comp hs using 1 + simp + have hm := he.eventually (locally_exact c d hn hi) + obtain ⟨n,hnpos,hmem⟩ := (eventually_gt_atTop 0 |>.and hm).exists + have hnorm (i : ι) : Quaternion.normSq ((NormedSpace.exp (((n : ℝ)⁻¹) • X)) i)=1 := by + have heval : (NormedSpace.exp (((n : ℝ)⁻¹) • X)) i = + NormedSpace.exp (((n : ℝ)⁻¹) • X i) := by + convert! NormedSpace.map_exp (Pi.evalRingHom (fun _ : ι => Quaternion ℝ) i) (continuous_apply i) (((n : ℝ)⁻¹) • X) + rw [heval,Quaternion.normSq_exp,Quaternion.re_smul,hX,smul_zero] + simp + have hr := (zeroClockWords (gen c d)).pow_mem (hmem hnorm) n + convert hr using 1 + rw [← NormedSpace.exp_nsmul] + congr 1 + rw [← Nat.cast_smul_eq_nsmul ℝ,smul_smul, mul_inv_cancel₀ (Nat.cast_ne_zero.mpr (Nat.ne_of_gt hnpos)),one_smul] + +end QuaternionControl + +namespace PulseControl +variable {A B κ : Type*} [NormedRing A] [NormedAlgebra ℝ A] + [NormedRing B] [NormedAlgebra ℝ B] [DecidableEq κ] + [CompleteSpace A] [CompleteSpace B] +local instance : NormedAlgebra ℚ A := NormedAlgebra.restrictScalars ℚ ℝ A +local instance : NormedAlgebra ℚ B := NormedAlgebra.restrictScalars ℚ ℝ B + +omit [DecidableEq κ] [CompleteSpace B] in +theorem pulseValue_map (F : A →ₐ[ℝ] B) (hF : Continuous F) (G : κ → A) (w : List (κ × ℝ)) : + F (pulseValue G w) = pulseValue (F ∘ G) w := by + induction w with + | nil => simp + | cons p w ih => + simp only [pulseValue,List.map_cons,List.prod_cons] at ih ⊢ + rw [map_mul,ih] + congr 1 + convert! NormedSpace.map_exp F.toRingHom hF (p.2 • G p.1) using 1 + change NormedSpace.exp (p.2 • F (G p.1)) = NormedSpace.exp (F (p.2 • G p.1)) + rw [map_smul] + +omit [CompleteSpace B] in +theorem zeroClock_map (F : A →ₐ[ℝ] B) (hF : Continuous F) (G : κ → A) {U : A} + (hU : U ∈ zeroClockWords G) : F U ∈ zeroClockWords (F ∘ G) := by + obtain ⟨w,hw,he⟩ := hU + exact ⟨w,hw,by rw [← pulseValue_map F hF G w,he]⟩ +end PulseControl + +namespace QuaternionControl +open PulseControl +variable {ι : Type*} [Fintype ι] +local instance : NormedAlgebra ℚ (QField ι) := NormedAlgebra.restrictScalars ℚ ℝ (QField ι) + + +def flipIJ : Quaternion ℝ →ₐ[ℝ] Quaternion ℝ where + toFun q := ⟨q.re,-q.imI,-q.imJ,q.imK⟩ + map_one' := by change (⟨1, -0, -0, 0⟩ : Quaternion ℝ) = 1; ext <;> simp + map_zero' := by change (⟨0, -0, -0, 0⟩ : Quaternion ℝ) = 0; ext <;> simp + map_add' q r := by + change (⟨(q+r).re,-(q+r).imI,-(q+r).imJ,(q+r).imK⟩ : Quaternion ℝ) = + (⟨q.re,-q.imI,-q.imJ,q.imK⟩ : Quaternion ℝ)+(⟨r.re,-r.imI,-r.imJ,r.imK⟩ : Quaternion ℝ) + ext <;> simp <;> ring + map_mul' q r := by + change (⟨(q*r).re,-(q*r).imI,-(q*r).imJ,(q*r).imK⟩ : Quaternion ℝ) = + (⟨q.re,-q.imI,-q.imJ,q.imK⟩ : Quaternion ℝ)*(⟨r.re,-r.imI,-r.imJ,r.imK⟩ : Quaternion ℝ) + ext <;> simp <;> ring + commutes' r := by ext <;> simp + +theorem flipIJ_apply (q : Quaternion ℝ) : flipIJ q = ⟨q.re,-q.imI,-q.imJ,q.imK⟩ := rfl + + +def expand {κ : Type*} (key : ι → κ) (sgn : ι → Bool) : QField κ →ₐ[ℝ] QField ι where + toFun q i := if sgn i then flipIJ (q (key i)) else q (key i) + map_one' := by + funext i + change (if sgn i then flipIJ (1 : Quaternion ℝ) else (1 : Quaternion ℝ)) = 1 + split_ifs <;> simp + map_zero' := by + funext i + change (if sgn i then flipIJ (0 : Quaternion ℝ) else (0 : Quaternion ℝ)) = 0 + split_ifs <;> simp + map_add' q r := by + funext i + change (if sgn i then flipIJ (q (key i)+r (key i)) else q (key i)+r (key i)) = + (if sgn i then flipIJ (q (key i)) else q (key i))+(if sgn i then flipIJ (r (key i)) else r (key i)) + split_ifs <;> simp + map_mul' q r := by + funext i + change (if sgn i then flipIJ (q (key i)*r (key i)) else q (key i)*r (key i)) = + (if sgn i then flipIJ (q (key i)) else q (key i))*(if sgn i then flipIJ (r (key i)) else r (key i)) + split_ifs <;> simp + commutes' r := by + funext i + change (if sgn i then flipIJ (algebraMap ℝ (Quaternion ℝ) r) else algebraMap ℝ (Quaternion ℝ) r) = + algebraMap ℝ (Quaternion ℝ) r + split_ifs + · exact flipIJ.commutes r + · rfl + +omit [Fintype ι] in +theorem expand_gen {κ : Type*} (key : ι → κ) (sgn : ι → Bool) + (c d : ι → ℝ) (C D : κ → ℝ) + (hc : ∀ i, c i = if sgn i then -C (key i) else C (key i)) + (hd : ∀ i, d i = if sgn i then -D (key i) else D (key i)) : + (expand key sgn) ∘ gen C D = gen c d := by + funext a i + cases a + · change (if sgn i then flipIJ (⟨0,0,D (key i),0⟩ : Quaternion ℝ) else (⟨0,0,D (key i),0⟩ : Quaternion ℝ)) = + (⟨0,0,d i,0⟩ : Quaternion ℝ) + rw [hd i] + cases h : sgn i + · rfl + · change (⟨0,-(0:ℝ),-D (key i),0⟩ : Quaternion ℝ) = ⟨0,0,-D (key i),0⟩ + simp only [neg_zero] + · change (if sgn i then flipIJ (⟨0,C (key i),0,0⟩ : Quaternion ℝ) else (⟨0,C (key i),0,0⟩ : Quaternion ℝ)) = + (⟨0,c i,0,0⟩ : Quaternion ℝ) + rw [hc i] + cases h : sgn i + · rfl + · change (⟨0,-C (key i),-(0:ℝ),0⟩ : Quaternion ℝ) = ⟨0,-C (key i),0,0⟩ + simp only [neg_zero] + +omit [Fintype ι] in +theorem expand_qX {κ : Type*} (key : ι → κ) (sgn : ι → Bool) (t : ℝ) : + expand key sgn (qX (fun _ => t)) = qX (fun _ => t) := by + funext i + change (if sgn i then flipIJ (⟨0,0,0,t⟩ : Quaternion ℝ) else (⟨0,0,0,t⟩ : Quaternion ℝ)) = + (⟨0,0,0,t⟩ : Quaternion ℝ) + cases h : sgn i + · rfl + · change (⟨0,-(0:ℝ),-(0:ℝ),t⟩ : Quaternion ℝ) = ⟨0,0,0,t⟩ + simp only [neg_zero] + + +theorem common_X_exact (c d : ι → ℝ) (hn : ∀ i, c i*d i ≠ 0) + (heq : ∀ i j, c i^2=c j^2 → (c i=c j ∧ d i=d j) ∨ (c i= -c j ∧ d i= -d j)) + (t : ℝ) : NormedSpace.exp (qX (fun _ => t)) ∈ zeroClockWords (gen c d) := by + classical + let κ := Set.range (fun i => c i^2) + let : Fintype κ := Fintype.ofFinite κ + let key : ι → κ := fun i => ⟨c i^2,⟨i,rfl⟩⟩ + let rep : κ → ι := fun k => Classical.choose k.property + have hre (k : κ) : c (rep k)^2=k.val := Classical.choose_spec k.property + let C : κ → ℝ := c ∘ rep + let D : κ → ℝ := d ∘ rep + have hC : Function.Injective (fun k => C k^2) := by + intro k l h + apply Subtype.ext + simpa only [C,Function.comp_apply,hre] using h + have hCD (k : κ) : C k*D k≠0 := hn (rep k) + let sgn : ι → Bool := fun i => decide (c i ≠ C (key i)) + have hcases (i : ι) := heq i (rep (key i)) (hre (key i)).symm + have hc (i : ι) : c i = if sgn i then -C (key i) else C (key i) := by + simp only [sgn, decide_eq_true_eq, ne_eq,ite_not] + split_ifs with h + · exact h + · exact ((hcases i).resolve_left (fun hh => h hh.1)).1 + have hd (i : ι) : d i = if sgn i then -D (key i) else D (key i) := by + simp only [sgn, decide_eq_true_eq, ne_eq,ite_not] + split_ifs with h + · rcases hcases i with hh | hh + · exact hh.2 + · exfalso + have hz := (mul_ne_zero_iff.mp (hn i)).1 + apply hz + dsimp [C,Function.comp_apply] at h + linarith [hh.1] + · exact ((hcases i).resolve_left (fun hh => h hh.1)).2 + have hreach := exact_imaginary C D hCD hC (qX (fun _ => t)) (fun _ => rfl) + let F := expand key sgn + have hF : Continuous F := F.toLinearMap.continuous_of_finiteDimensional + have hmap := zeroClock_map F hF (gen C D) hreach + rw [show F ∘ gen C D = gen c d from expand_gen key sgn c d C D hc hd] at hmap + have hExp : F (NormedSpace.exp (qX (fun _ : κ => t))) = + NormedSpace.exp (qX (fun _ : ι => t)) := by + convert! NormedSpace.map_exp F.toRingHom hF (qX (fun _ : κ => t)) using 1 + change NormedSpace.exp (qX (fun _ : ι => t)) = NormedSpace.exp (expand key sgn (qX (fun _ : κ => t))) + rw [expand_qX] + rwa [hExp] at hmap +end QuaternionControl + +open scoped Matrix Matrix.Norms.L2Operator +namespace QuaternionControl + +def rotateIJ (a b : ℝ) (h : a^2+b^2=1) : Quaternion ℝ →ₐ[ℝ] Quaternion ℝ where + toFun q := ⟨q.re,a*q.imI-b*q.imJ,b*q.imI+a*q.imJ,q.imK⟩ + map_zero' := by + change (⟨0,a*0-b*0,b*0+a*0,0⟩ : Quaternion ℝ) = 0 + ext <;> simp + map_one' := by + change (⟨1,a*0-b*0,b*0+a*0,0⟩ : Quaternion ℝ) = 1 + ext <;> simp + map_add' q r := by + change (⟨(q+r).re,a*(q+r).imI-b*(q+r).imJ,b*(q+r).imI+a*(q+r).imJ,(q+r).imK⟩ : Quaternion ℝ) = + (⟨q.re,a*q.imI-b*q.imJ,b*q.imI+a*q.imJ,q.imK⟩ : Quaternion ℝ)+ + (⟨r.re,a*r.imI-b*r.imJ,b*r.imI+a*r.imJ,r.imK⟩ : Quaternion ℝ) + ext <;> simp <;> ring + map_mul' q r := by + change (⟨(q*r).re,a*(q*r).imI-b*(q*r).imJ,b*(q*r).imI+a*(q*r).imJ,(q*r).imK⟩ : Quaternion ℝ) = + (⟨q.re,a*q.imI-b*q.imJ,b*q.imI+a*q.imJ,q.imK⟩ : Quaternion ℝ)* + (⟨r.re,a*r.imI-b*r.imJ,b*r.imI+a*r.imJ,r.imK⟩ : Quaternion ℝ) + ext <;> simp + · nlinarith [h, congrArg (fun x => x*(q.imI*r.imI+q.imJ*r.imJ)) h] + · ring + · ring + · nlinarith [h, congrArg (fun x => x*(q.imI*r.imJ-q.imJ*r.imI)) h] + commutes' r := by + change (⟨r,a*0-b*0,b*0+a*0,0⟩ : Quaternion ℝ) = algebraMap ℝ (Quaternion ℝ) r + ext <;> simp + + +def toPauli : Quaternion ℝ →ₐ[ℝ] Matrix (Fin 2) (Fin 2) ℂ where + toFun q := !![(q.re:ℂ)-Complex.I*q.imI, -(q.imJ:ℂ)+Complex.I*q.imK; + (q.imJ:ℂ)+Complex.I*q.imK, (q.re:ℂ)+Complex.I*q.imI] + map_zero' := by + change !![(0:ℂ)-Complex.I*0,-0+Complex.I*0;0+Complex.I*0,0+Complex.I*0] = 0 + ext i j; fin_cases i <;> fin_cases j <;> simp + map_one' := by + change !![(1:ℂ)-Complex.I*0,-0+Complex.I*0;0+Complex.I*0,1+Complex.I*0] = 1 + ext i j; fin_cases i <;> fin_cases j <;> simp + map_add' q r := by ext i j; fin_cases i <;> fin_cases j <;> simp <;> ring + map_mul' q r := by + ext i j + fin_cases i <;> fin_cases j <;> simp [Matrix.mul_apply,Fin.sum_univ_two] <;> + ring_nf <;> simp [Complex.I_sq] <;> ring + commutes' r := by + change !![(r:ℂ)-Complex.I*0,-0+Complex.I*0;0+Complex.I*0,(r:ℂ)+Complex.I*0] = algebraMap ℝ (Matrix (Fin 2) (Fin 2) ℂ) r + ext i j; fin_cases i <;> fin_cases j <;> simp [Algebra.algebraMap_eq_smul_one] + +end QuaternionControl + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SpinTrace.lean b/lean/OAI/Probability/ParisiFinite/SpinTrace.lean new file mode 100644 index 0000000000000000000000000000000000000000..910c53a8ed2274386d062a291e3a2d3cd6a60284 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SpinTrace.lean @@ -0,0 +1,727 @@ +import Mathlib +import OAI.Probability.ParisiFinite.AbsMulExpLe + +namespace OAI + +/-! Spin Trace. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +open SKGaussian +variable {ι : Type*} [Fintype ι] [Nonempty ι] + + +def spinTrace (β : ℝ) (x : ι → ℝ) : ℝ := logPartition (fun i => β*x i) / β + +def gibbsMean (β : ℝ) (x v : ι → ℝ) : ℝ := ∑ i, weight (fun j => β*x j) i*v i + +def gibbsCov (β : ℝ) (x v w : ι → ℝ) : ℝ := + gibbsMean β x (fun i => v i*w i)-gibbsMean β x v*gibbsMean β x w + +lemma continuous_gibbsMean (β : ℝ) (v : ι → ℝ) : Continuous (fun x => gibbsMean β x v) := by + unfold gibbsMean + apply continuous_finsetSum + intro i _ + exact ((continuous_weight i).comp (show Continuous (fun x : ι → ℝ => fun j => β*x j) by fun_prop)).mul_const _ + +lemma continuous_gibbsCov (β : ℝ) (v w : ι → ℝ) : Continuous (fun x => gibbsCov β x v w) := + (continuous_gibbsMean β _).sub ((continuous_gibbsMean β v).mul (continuous_gibbsMean β w)) + +lemma abs_gibbsMean_le (β : ℝ) (x v : ι → ℝ) : |gibbsMean β x v| ≤ ‖v‖ := + abs_weight_sum_le _ v (fun i => by simpa only [Real.norm_eq_abs] using norm_le_pi_norm v i) + +lemma abs_gibbsCov_le (β : ℝ) (x v w : ι → ℝ) : |gibbsCov β x v w| ≤ 2*‖v‖*‖w‖ := by + have hp : |gibbsMean β x (fun i => v i*w i)| ≤ ‖v‖*‖w‖ := by + apply abs_weight_sum_le + intro i + rw [abs_mul] + exact mul_le_mul (by simpa only [Real.norm_eq_abs] using norm_le_pi_norm v i) + (by simpa only [Real.norm_eq_abs] using norm_le_pi_norm w i) (abs_nonneg _) (norm_nonneg _) + have hm := mul_le_mul (abs_gibbsMean_le β x v) (abs_gibbsMean_le β x w) (abs_nonneg _) (norm_nonneg _) + have h := abs_sub_le (gibbsMean β x (fun i => v i*w i)) 0 (gibbsMean β x v*gibbsMean β x w) + simp only [sub_zero, zero_sub, abs_neg, abs_mul] at h + unfold gibbsCov + linarith + +lemma hasDerivAt_spinTrace {β : ℝ} (hβ : β ≠ 0) (v x : ι → ℝ) (t : ℝ) : + HasDerivAt (fun u : ℝ => spinTrace β (x+u • v)) (gibbsMean β (x+t • v) v) t := by + have h : ∀ i, HasDerivAt (fun u : ℝ => β*(x+u • v) i) (β*v i) t := by + intro i + simpa only [Pi.add_apply, Pi.smul_apply, smul_eq_mul, mul_one, one_mul, id_eq] using + (((hasDerivAt_id t).mul_const (v i)).const_add (x i)).const_mul β + have hd := (hasDerivAt_logPartition h).div_const β + have he : (∑ i, weight (fun j => β*(x+t • v) j) i*(β*v i))/β = + gibbsMean β (x+t • v) v := by + unfold gibbsMean + simp only [mul_left_comm _ β, ← Finset.mul_sum, mul_div_cancel_left₀ _ hβ] + rw [he] at hd + exact hd + +lemma hasDerivAt_gibbsMean (β : ℝ) (v w x : ι → ℝ) (t : ℝ) : + HasDerivAt (fun u : ℝ => gibbsMean β (x+u • v) w) + (β*gibbsCov β (x+t • v) v w) t := by + have h : ∀ i, HasDerivAt (fun u : ℝ => β*(x+u • v) i) (β*v i) t := by + intro i + simpa only [Pi.add_apply, Pi.smul_apply, smul_eq_mul, mul_one, one_mul, id_eq] using + (((hasDerivAt_id t).mul_const (v i)).const_add (x i)).const_mul β + have hd := HasDerivAt.fun_sum (u := Finset.univ) (fun i _ => (hasDerivAt_weight h i).mul_const (w i)) + convert hd using 1 <;> try rfl + unfold gibbsCov gibbsMean + simp only [mul_sub, sub_mul, Finset.sum_sub_distrib, + mul_left_comm _ β, ← Finset.mul_sum] + simp only [mul_assoc, ← Finset.mul_sum] + have hc (i : ι) : weight (fun j => β*(x+t • v) j) i * + ((∑ j, weight (fun k => β*(x+t • v) k) j*v j)*w i) = + (∑ j, weight (fun k => β*(x+t • v) k) j*v j)* + (weight (fun j => β*(x+t • v) j) i*w i) := by ring + simp_rw [hc, ← Finset.mul_sum] + +lemma spinTrace_lipschitz {β : ℝ} (hβ : β ≠ 0) : LipschitzWith 1 (spinTrace (ι:=ι) β) := by + rw [lipschitzWith_iff_norm_sub_le] + intro x y + let F : ℝ → ℝ := fun t => spinTrace β (y+t • (x-y)) + have hLip : LipschitzWith ‖x-y‖₊ F := by + apply lipschitzWith_of_nnnorm_deriv_le (fun t => (hasDerivAt_spinTrace hβ (x-y) y t).differentiableAt) + intro t + rw [(hasDerivAt_spinTrace hβ (x-y) y t).deriv] + exact_mod_cast abs_gibbsMean_le β (y+t • (x-y)) (x-y) + have h := hLip.norm_sub_le 1 0 + simpa [F] using h + + + +def traceField (β : ℝ≥0) (hβ : 0 < β) : DirectionalField (ι → ℝ) where + val := spinTrace β + first v x := gibbsMean β x v + second v w x := (β:ℝ)*gibbsCov β x v w + lip := 1 + lipschitz := spinTrace_lipschitz (show (β:ℝ) ≠ 0 from ne_of_gt hβ) + continuousFirst := continuous_gibbsMean β + continuousSecond v w := (continuous_gibbsCov β v w).const_mul _ + hasFirst := hasDerivAt_spinTrace (show (β:ℝ) ≠ 0 from ne_of_gt hβ) + hasSecond := hasDerivAt_gibbsMean β + boundFirst v := ‖v‖₊ + boundSecond v w := 2*β*‖v‖₊*‖w‖₊ + normFirst := fun v x => abs_gibbsMean_le β x v + normSecond v w x := by + rw [abs_mul, abs_of_nonneg β.coe_nonneg] + have h := mul_le_mul_of_nonneg_left (abs_gibbsCov_le β x v w) β.coe_nonneg + simpa only [NNReal.coe_mul, NNReal.coe_ofNat, coe_nnnorm, mul_assoc, mul_left_comm] using h + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +lemma ambient_exp_bound {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) + (a : ℝ) {x c : E} {K H C : ℝ} (hf0 : |f 0| ≤ K) (hx : ‖x‖ ≤ H) + (hc : ‖c‖ ≤ C) (z : ℝ) : + Real.exp (a*f (x+z • c)) ≤ + Real.exp (|a| *(K+(L:ℝ)*H))*Real.exp ((|a| *(L:ℝ)*C)*|z|) := by + have h := ambient_exp_near_le_radius hf a 0 c (by simpa using hx) z + apply h.trans + apply mul_le_mul + · apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonneg_left (add_le_add hf0 le_rfl) (abs_nonneg _) + · apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hc (by positivity)) (abs_nonneg _) + · positivity + · positivity + + + +lemma continuous_parameterMoment {S : Type*} [TopologicalSpace S] [FirstCountableTopology S] {L : ℝ≥0} + {f g : S → E → ℝ} {x c : S → E} {M : S → ℝ} + (hf : ∀ s, LipschitzWith L (f s)) + (hfc : Continuous (fun q : S × E => f q.1 q.2)) + (hgc : Continuous (fun q : S × E => g q.1 q.2)) + (hx : Continuous x) (hc : Continuous c) (hMc : Continuous M) + (hM : ∀ s y, |g s y| ≤ M s) (a : ℝ) : + Continuous (fun s => ambientMoment a (c s) (f s) (g s) (x s)) := by + have hf0 : Continuous (fun s => f s 0) := hfc.comp (continuous_id.prodMk continuous_const) + have hg (s : S) : Continuous (g s) := hgc.comp (continuous_const.prodMk continuous_id) + apply continuous_iff_continuousAt.mpr + intro s₀ + let K := |f s₀ 0|+1 + let H := ‖x s₀‖+1 + let C := ‖c s₀‖+1 + let N := |M s₀|+1 + have hK : ∀ᶠ s in 𝓝 s₀, |f s 0| < K := hf0.abs.continuousAt.eventually (gt_mem_nhds (lt_add_one _)) + have hH : ∀ᶠ s in 𝓝 s₀, ‖x s‖ < H := hx.norm.continuousAt.eventually (gt_mem_nhds (lt_add_one _)) + have hC : ∀ᶠ s in 𝓝 s₀, ‖c s‖ < C := hc.norm.continuousAt.eventually (gt_mem_nhds (lt_add_one _)) + have hN : ∀ᶠ s in 𝓝 s₀, M s < N := hMc.continuousAt.eventually + (gt_mem_nhds (lt_of_le_of_lt (le_abs_self _) (lt_add_one _))) + apply continuousAt_of_dominated + (bound := fun z => (Real.exp (|a| *(K+(L:ℝ)*H))*Real.exp ((|a| *(L:ℝ)*C)*|z|))*N) + · exact Eventually.of_forall fun s => (integrable_ambient_weight (hf s) (hg s) (hM s) a (c s) (x s)).aestronglyMeasurable + · filter_upwards [hK,hH,hC,hN] with s hsK hsH hsC hsN + exact ae_of_all _ fun z => by + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + exact mul_le_mul (ambient_exp_bound (hf s) a hsK.le hsH.le hsC.le z) + ((hM s _).trans hsN.le) (abs_nonneg _) (by positivity) + · exact ((integrable_exp_abs _).const_mul _).mul_const _ + · exact ae_of_all _ fun z => by + have hv : Continuous (fun s => f s (x s+z • c s)) := + hfc.comp (continuous_id.prodMk (hx.add (hc.const_smul z))) + have hw : Continuous (fun s => g s (x s+z • c s)) := + hgc.comp (continuous_id.prodMk (hx.add (hc.const_smul z))) + exact ((Real.continuous_exp.comp (hv.const_mul a)).mul hw).continuousAt + +lemma continuous_parameterMass {S : Type*} [TopologicalSpace S] [FirstCountableTopology S] {L : ℝ≥0} + {f : S → E → ℝ} {x c : S → E} (hf : ∀ s, LipschitzWith L (f s)) + (hfc : Continuous (fun q : S × E => f q.1 q.2)) (hx : Continuous x) (hc : Continuous c) + (a : ℝ) : Continuous (fun s => ambientMass a (c s) (f s) (x s)) := by + have h := continuous_parameterMoment hf hfc (g := fun _ _ => 1) continuous_const hx hc + (M := fun _ => 1) continuous_const (by intro _ _; norm_num) a + simpa only [ambientMass, ambientMoment, mul_one] using h + +lemma continuous_parameterTilt {S : Type*} [TopologicalSpace S] [FirstCountableTopology S] {L : ℝ≥0} + {f g : S → E → ℝ} {x c : S → E} {M : S → ℝ} + (hf : ∀ s, LipschitzWith L (f s)) + (hfc : Continuous (fun q : S × E => f q.1 q.2)) + (hgc : Continuous (fun q : S × E => g q.1 q.2)) + (hx : Continuous x) (hc : Continuous c) (hMc : Continuous M) + (hM : ∀ s y, |g s y| ≤ M s) (a : ℝ) : + Continuous (fun s => ambientTilt a (c s) (f s) (g s) (x s)) := + (continuous_parameterMoment hf hfc hgc hx hc hMc hM a).div + (continuous_parameterMass hf hfc hx hc a) (fun s => (ambientMass_pos (hf s) a (c s) (x s)).ne') + +lemma continuous_parameterAverage {S : Type*} [TopologicalSpace S] [FirstCountableTopology S] {L : ℝ≥0} + {f : S → E → ℝ} {x c : S → E} (hf : ∀ s, LipschitzWith L (f s)) + (hfc : Continuous (fun q : S × E => f q.1 q.2)) (hx : Continuous x) (hc : Continuous c) : + Continuous (fun s => ∫ z, f s (x s+z • c s) ∂gaussianReal 0 1) := by + have hf0 : Continuous (fun s => f s 0) := hfc.comp (continuous_id.prodMk continuous_const) + apply continuous_iff_continuousAt.mpr + intro s₀ + let K := |f s₀ 0|+1 + let H := ‖x s₀‖+1 + let C := ‖c s₀‖+1 + have hK : ∀ᶠ s in 𝓝 s₀, |f s 0| < K := hf0.abs.continuousAt.eventually (gt_mem_nhds (lt_add_one _)) + have hH : ∀ᶠ s in 𝓝 s₀, ‖x s‖ < H := hx.norm.continuousAt.eventually (gt_mem_nhds (lt_add_one _)) + have hC : ∀ᶠ s in 𝓝 s₀, ‖c s‖ < C := hc.norm.continuousAt.eventually (gt_mem_nhds (lt_add_one _)) + apply continuousAt_of_dominated (bound := fun z => K+(L:ℝ)*(H+|z| *C)) + · exact Eventually.of_forall fun s => (integrable_ambient (hf s) (x s) (c s)).aestronglyMeasurable + · filter_upwards [hK,hH,hC] with s hsK hsH hsC + exact ae_of_all _ fun z => by + have hv := (hf s).norm_sub_le (x s+z • c s) 0 + have ht := norm_add_le (x s) (z • c s) + rw [norm_smul, Real.norm_eq_abs] at ht + simp only [sub_zero, Real.norm_eq_abs] at hv + have htri := abs_add_le (f s (x s+z • c s)-f s 0) (f s 0) + rw [sub_add_cancel] at htri + rw [Real.norm_eq_abs] + have hc' := mul_le_mul_of_nonneg_left hsC.le (abs_nonneg z) + nlinarith [L.coe_nonneg] + · exact (integrable_const _).add (((integrable_const _).add + ((MemLp.integrable (by norm_num) (memLp_id_gaussianReal (μ := 0) (v := 1) 1)).abs.mul_const _)).const_mul _) + · exact ae_of_all _ fun z => + (hfc.comp (continuous_id.prodMk (hx.add (hc.const_smul z)))).continuousAt + +lemma continuous_parameterStep {S : Type*} [TopologicalSpace S] [FirstCountableTopology S] {L : ℝ≥0} + {f : S → E → ℝ} {x c : S → E} (hf : ∀ s, LipschitzWith L (f s)) + (hfc : Continuous (fun q : S × E => f q.1 q.2)) (hx : Continuous x) (hc : Continuous c) + (a : ℝ) : Continuous (fun s => ambientStep a (c s) (f s) (x s)) := by + by_cases ha : a=0 + · subst a + simpa [ambientStep, logMean] using continuous_parameterAverage hf hfc hx hc + · have he : (fun s => ambientStep a (c s) (f s) (x s)) = + fun s => Real.log (ambientMass a (c s) (f s) (x s))/a := by + funext s + simp [ambientStep, logMean, ha, ambientMass] + rw [he] + exact ((continuous_parameterMass hf hfc hx hc a).log + (fun s => (ambientMass_pos (hf s) a (c s) (x s)).ne')).div_const a +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +lemma hasDerivAt_parameterMass {L : ℝ≥0} {f d : ℝ → E → ℝ} {M : ℝ → ℝ} + (hf : ∀ t, LipschitzWith L (f t)) + (hfc : Continuous (fun q : ℝ × E => f q.1 q.2)) + (hdc : Continuous (fun q : ℝ × E => d q.1 q.2)) + (hMc : Continuous M) (hM : ∀ t y, |d t y| ≤ M t) + (hd : ∀ y t, HasDerivAt (fun s => f s y) (d t y) t) + (a : ℝ) (c x : E) (t₀ : ℝ) : + HasDerivAt (fun t => ambientMass a c (f t) x) + (a*ambientMoment a c (f t₀) (d t₀) x) t₀ := by + let K := |f t₀ 0|+1 + let N := |M t₀|+1 + have hf0 : Continuous (fun t => f t 0) := hfc.comp (continuous_id.prodMk continuous_const) + have hK : ∀ᶠ t in 𝓝 t₀, |f t 0| < K := hf0.abs.continuousAt.eventually (gt_mem_nhds (lt_add_one _)) + have hN : ∀ᶠ t in 𝓝 t₀, M t < N := hMc.continuousAt.eventually + (gt_mem_nhds (lt_of_le_of_lt (le_abs_self _) (lt_add_one _))) + obtain ⟨r,hr,hs⟩ := Metric.eventually_nhds_iff.mp (hK.and hN) + have h := (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball t₀ r) (μ := gaussianReal 0 1) + (F := fun t z => Real.exp (a*f t (x+z • c))) + (bound := fun z => (Real.exp (|a| *(K+(L:ℝ)*‖x‖))* + Real.exp ((|a| *(L:ℝ)*‖c‖)*|z|))*(|a| *N)) + (F' := fun t z => Real.exp (a*f t (x+z • c))*(a*d t (x+z • c))) + (Metric.ball_mem_nhds _ hr) ?_ (integrable_exp_ambient (hf t₀) a x c) ?_ ?_ ?_ ?_).2 + · convert h using 1 <;> try rfl + simp only [ambientMoment, mul_left_comm _ a, integral_const_mul] + · exact Eventually.of_forall fun t => (integrable_exp_ambient (hf t) a x c).aestronglyMeasurable + · have hdc0 : Continuous (d t₀) := hdc.comp (continuous_const.prodMk continuous_id) + have hfc0 := (hf t₀).continuous + fun_prop + · exact ae_of_all _ fun z t ht => by + have hk := (hs ht).1.le + have hn := (hs ht).2.le + rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _), abs_mul] + apply mul_le_mul (ambient_exp_bound (hf t) a hk le_rfl le_rfl z) + · exact mul_le_mul_of_nonneg_left ((hM t _).trans hn) (abs_nonneg _) + · positivity + · positivity + · exact ((integrable_exp_abs _).const_mul _).mul_const _ + · exact ae_of_all _ fun z t _ => by + convert ((hd (x+z • c) t).const_mul a).exp using 1 + +lemma hasDerivAt_parameterAverage {L : ℝ≥0} {f d : ℝ → E → ℝ} {M : ℝ → ℝ} + (hf : ∀ t, LipschitzWith L (f t)) + (hdc : Continuous (fun q : ℝ × E => d q.1 q.2)) + (hMc : Continuous M) (hM : ∀ t y, |d t y| ≤ M t) + (hd : ∀ y t, HasDerivAt (fun s => f s y) (d t y) t) + (c x : E) (t₀ : ℝ) : + HasDerivAt (fun t => ∫ z, f t (x+z • c) ∂gaussianReal 0 1) + (∫ z, d t₀ (x+z • c) ∂gaussianReal 0 1) t₀ := by + let N := |M t₀|+1 + have hN : ∀ᶠ t in 𝓝 t₀, M t < N := hMc.continuousAt.eventually + (gt_mem_nhds (lt_of_le_of_lt (le_abs_self _) (lt_add_one _))) + obtain ⟨r,hr,hs⟩ := Metric.eventually_nhds_iff.mp hN + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball t₀ r) (bound := fun _ => N) (F' := fun t z => d t (x+z • c)) + (Metric.ball_mem_nhds _ hr) ?_ (integrable_ambient (hf t₀) x c) ?_ ?_ (integrable_const _) ?_).2 + · exact Eventually.of_forall fun t => (integrable_ambient (hf t) x c).aestronglyMeasurable + · have hdc0 : Continuous (d t₀) := hdc.comp (continuous_const.prodMk continuous_id) + fun_prop + · exact ae_of_all _ fun z t ht => by + rw [Real.norm_eq_abs] + exact (hM t _).trans (hs ht).le + · exact ae_of_all _ fun z t _ => hd _ t + + + +lemma hasDerivAt_parameterStep {L : ℝ≥0} {f d : ℝ → E → ℝ} {M : ℝ → ℝ} + (hf : ∀ t, LipschitzWith L (f t)) + (hfc : Continuous (fun q : ℝ × E => f q.1 q.2)) + (hdc : Continuous (fun q : ℝ × E => d q.1 q.2)) + (hMc : Continuous M) (hM : ∀ t y, |d t y| ≤ M t) + (hd : ∀ y t, HasDerivAt (fun s => f s y) (d t y) t) + (a : ℝ) (c x : E) (t₀ : ℝ) : + HasDerivAt (fun t => ambientStep a c (f t) x) + (ambientTilt a c (f t₀) (d t₀) x) t₀ := by + by_cases ha : a=0 + · subst a + simpa [ambientStep, logMean] using + hasDerivAt_parameterAverage hf hdc hMc hM hd c x t₀ + · have h := ((hasDerivAt_parameterMass hf hfc hdc hMc hM hd a c x t₀).log + (ambientMass_pos (hf t₀) a c x).ne').div_const a + have hv : (fun t => ambientStep a c (f t) x) = fun t => Real.log (ambientMass a c (f t) x)/a := by + funext t + simp [ambientStep, logMean, ha, ambientMass] + rw [hv] + convert h using 1 + try rfl + unfold ambientTilt + field_simp +end ParisiFinite + + + +open Filter +open scoped Topology +namespace ParisiFinite + +lemma hasDerivAt_bivariate_path {f d₁ d₂ : ℝ → ℝ → ℝ} + (hd₁ : ∀ t s, HasDerivAt (fun r => f r s) (d₁ t s) t) + (hd₂ : ∀ t s, HasDerivAt (f t) (d₂ t s) s) + (hc₁ : Continuous (fun p : ℝ × ℝ => d₁ p.1 p.2)) + (hc₂ : Continuous (fun p : ℝ × ℝ => d₂ p.1 p.2)) + {s : ℝ → ℝ} {ds t₀ : ℝ} (hs : HasDerivAt s ds t₀) : + HasDerivAt (fun t => f t (s t)) (d₁ t₀ (s t₀)+ds*d₂ t₀ (s t₀)) t₀ := by + have h := hasStrictFDerivAt_uncurry_coprod + (f := f) (u := (t₀,s t₀)) + (f₁ := fun t s => ContinuousLinearMap.toSpanSingleton ℝ (d₁ t s)) + (f₂ := fun t s => ContinuousLinearMap.toSpanSingleton ℝ (d₂ t s)) + (Eventually.of_forall fun p => (hd₁ p.1 p.2).hasFDerivAt) + (Eventually.of_forall fun p => (hd₂ p.1 p.2).hasFDerivAt) + (((ContinuousLinearMap.toSpanSingletonLIE ℝ ℝ).continuous.comp hc₁).continuousAt) + (((ContinuousLinearMap.toSpanSingletonLIE ℝ ℝ).continuous.comp hc₂).continuousAt) + have hv := h.hasFDerivAt.comp_hasDerivAt t₀ ((hasDerivAt_id t₀).prodMk hs) + convert hv using 1 <;> try rfl + change d₁ t₀ (s t₀)+ds*d₂ t₀ (s t₀) = 1*d₁ t₀ (s t₀)+ds*d₂ t₀ (s t₀) + ring + +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + + + +structure FieldFamily (E : Type*) [NormedAddCommGroup E] [NormedSpace ℝ E] where + field : ℝ → DirectionalField E + dot : ℝ → E → ℝ + continuousVal : Continuous (fun q : ℝ × E => (field q.1).val q.2) + continuousFirst : ∀ v, Continuous (fun q : ℝ × E => (field q.1).first v q.2) + continuousSecond : ∀ v w, Continuous (fun q : ℝ × E => (field q.1).second v w q.2) + continuousDot : Continuous (fun q : ℝ × E => dot q.1 q.2) + hasDot : ∀ x t, HasDerivAt (fun s => (field s).val x) (dot t x) t + lip : ℝ≥0 + lipschitz : ∀ t, LipschitzWith lip (field t).val + boundFirst : E → ℝ≥0 + boundSecond : E → E → ℝ≥0 + boundDot : ℝ → ℝ + continuousBound : Continuous boundDot + normFirst : ∀ t v x, |(field t).first v x| ≤ boundFirst v + normSecond : ∀ t v w x, |(field t).second v w x| ≤ boundSecond v w + normDot : ∀ t x, |dot t x| ≤ boundDot t + +namespace FieldFamily +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +omit [NormedAddCommGroup E] [NormedSpace ℝ E] in +lemma square_bound {g : E → ℝ} {B : ℝ≥0} (h : ∀ y, |g y| ≤ B) (x : E) : + |g x ^ 2| ≤ (B:ℝ)^2 := by + rw [abs_sq] + nlinarith [h x, abs_nonneg (g x), sq_abs (g x)] + +def constant (f : DirectionalField E) : FieldFamily E where + field _ := f + dot _ _ := 0 + continuousVal := f.lipschitz.continuous.comp continuous_snd + continuousFirst v := (f.continuousFirst v).comp continuous_snd + continuousSecond v w := (f.continuousSecond v w).comp continuous_snd + continuousDot := continuous_const + hasDot x t := hasDerivAt_const t (f.val x) + lip := f.lip + lipschitz _ := f.lipschitz + boundFirst := f.boundFirst + boundSecond := f.boundSecond + boundDot _ := 0 + continuousBound := continuous_const + normFirst _ := f.normFirst + normSecond _ := f.normSecond + normDot _ _ := by simp + +lemma continuous_mapTilt (F : FieldFamily E) {S : Type*} [TopologicalSpace S] + [FirstCountableTopology S] {t : S → ℝ} {x c : S → E} {g : ℝ → E → ℝ} {M : ℝ → ℝ} + (ht : Continuous t) (hx : Continuous x) (hc : Continuous c) + (hg : Continuous (fun q : ℝ × E => g q.1 q.2)) (hMc : Continuous M) + (hM : ∀ u y, |g u y| ≤ M u) (a : ℝ) : + Continuous (fun p => ambientTilt a (c p) (F.field (t p)).val (g (t p)) (x p)) := by + apply continuous_parameterTilt (fun p => F.lipschitz (t p)) + (F.continuousVal.comp ((ht.comp continuous_fst).prodMk continuous_snd)) + (hg.comp ((ht.comp continuous_fst).prodMk continuous_snd)) hx hc (hMc.comp ht) + (fun p y => hM (t p) y) a + +lemma continuous_mapStep (F : FieldFamily E) {S : Type*} [TopologicalSpace S] + [FirstCountableTopology S] {t : S → ℝ} {x c : S → E} + (ht : Continuous t) (hx : Continuous x) (hc : Continuous c) (a : ℝ) : + Continuous (fun p => ambientStep a (c p) (F.field (t p)).val (x p)) := + continuous_parameterStep (fun p => F.lipschitz (t p)) + (F.continuousVal.comp ((ht.comp continuous_fst).prodMk continuous_snd)) hx hc a + + + +def transformedDot (F : FieldFamily E) (a : ℝ≥0) (c : E) (s ds : ℝ → ℝ) (t : ℝ) (x : E) : ℝ := + ambientTilt a (s t • c) (F.field t).val (F.dot t) x + s t*ds t * + (ambientTilt a (s t • c) (F.field t).val ((F.field t).second c c) x + (a:ℝ)* + ambientTilt a (s t • c) (F.field t).val (fun y => ((F.field t).first c y)^2) x) + +lemma hasDerivAt_transformed (F : FieldFamily E) (a : ℝ≥0) (c x : E) + {s ds : ℝ → ℝ} (_hc : Continuous s) (hd : ∀ t, HasDerivAt s (ds t) t) (t₀ : ℝ) : + HasDerivAt (fun t => ((F.field t).transform a (s t • c)).val x) + (F.transformedDot a c s ds t₀ x) t₀ := by + let D₁ (t r : ℝ) := ambientTilt a (r • c) (F.field t).val (F.dot t) x + let D₂ (t r : ℝ) := r*(ambientTilt a (r • c) (F.field t).val ((F.field t).second c c) x+ + (a:ℝ)*ambientTilt a (r • c) (F.field t).val (fun y => ((F.field t).first c y)^2) x) + have h₁ : Continuous (fun p : ℝ × ℝ => D₁ p.1 p.2) := + F.continuous_mapTilt continuous_fst continuous_const (continuous_snd.smul continuous_const) + F.continuousDot F.continuousBound F.normDot a + have h₂a : Continuous (fun p : ℝ × ℝ => + ambientTilt a (p.2 • c) (F.field p.1).val ((F.field p.1).second c c) x) := + F.continuous_mapTilt continuous_fst continuous_const (continuous_snd.smul continuous_const) + (F.continuousSecond c c) continuous_const (fun t y => F.normSecond t c c y) a + have h₂b : Continuous (fun p : ℝ × ℝ => + ambientTilt a (p.2 • c) (F.field p.1).val (fun y => ((F.field p.1).first c y)^2) x) := + F.continuous_mapTilt continuous_fst continuous_const (continuous_snd.smul continuous_const) + ((F.continuousFirst c).pow 2) continuous_const + (fun t y => square_bound (fun z => F.normFirst t c z) y) a + have h₂ : Continuous (fun p : ℝ × ℝ => D₂ p.1 p.2) := + continuous_snd.mul (h₂a.add (h₂b.const_mul _)) + have h := hasDerivAt_bivariate_path + (fun t r => hasDerivAt_parameterStep F.lipschitz F.continuousVal F.continuousDot + F.continuousBound F.normDot F.hasDot a (r • c) x t) + (fun t r => (F.field t).hasDerivAt_transform_scale a c x r) h₁ h₂ (hd t₀) + convert h using 1 <;> first | rfl | simp only [transformedDot]; ring +end FieldFamily +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite.FieldFamily +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +lemma continuous_transformedDot (F : FieldFamily E) (a : ℝ≥0) (c : E) + {s ds : ℝ → ℝ} (hs : Continuous s) (hds : Continuous ds) : + Continuous (fun q : ℝ × E => F.transformedDot a c s ds q.1 q.2) := by + have hc : Continuous (fun q : ℝ × E => s q.1 • c) := (hs.comp continuous_fst).smul continuous_const + have h1 := F.continuous_mapTilt continuous_fst continuous_snd hc + F.continuousDot F.continuousBound F.normDot a + have h2 := F.continuous_mapTilt continuous_fst continuous_snd hc + (F.continuousSecond c c) continuous_const (fun t y => F.normSecond t c c y) a + have h3 := F.continuous_mapTilt continuous_fst continuous_snd hc + ((F.continuousFirst c).pow 2) continuous_const + (fun t y => square_bound (fun z => F.normFirst t c z) y) a + exact h1.add (((hs.comp continuous_fst).mul (hds.comp continuous_fst)).mul (h2.add (h3.const_mul _))) + +lemma bound_transformedDot (F : FieldFamily E) (a : ℝ≥0) (c : E) (s ds : ℝ → ℝ) (t : ℝ) (x : E) : + |F.transformedDot a c s ds t x| ≤ F.boundDot t + |s t*ds t| * + ((F.boundSecond c c:ℝ)+(a:ℝ)*(F.boundFirst c:ℝ)^2) := by + have h1 := abs_ambientTilt_le (F.lipschitz t) + (F.continuousDot.comp (continuous_const.prodMk continuous_id)) (F.normDot t) (a:ℝ) (s t • c) x + have hsec := abs_ambientTilt_le (F.lipschitz t) ((F.field t).continuousSecond c c) + (F.normSecond t c c) (a:ℝ) (s t • c) x + have hsq := abs_ambientTilt_le (F.lipschitz t) (((F.field t).continuousFirst c).pow 2) + (fun y => square_bound (fun z => F.normFirst t c z) y) (a:ℝ) (s t • c) x + unfold transformedDot + apply (abs_add_le _ _).trans + rw [abs_mul] + apply add_le_add h1 + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + apply (abs_add_le _ _).trans + rw [abs_mul, abs_of_nonneg a.coe_nonneg] + exact add_le_add hsec (mul_le_mul_of_nonneg_left hsq a.coe_nonneg) + + + +def transform (F : FieldFamily E) (a : ℝ≥0) (c : E) (s ds : ℝ → ℝ) + (hs : Continuous s) (hds : Continuous ds) (hd : ∀ t, HasDerivAt s (ds t) t) : FieldFamily E where + field t := (F.field t).transform a (s t • c) + dot := F.transformedDot a c s ds + continuousVal := F.continuous_mapStep continuous_fst continuous_snd + ((hs.comp continuous_fst).smul continuous_const) a + continuousFirst v := F.continuous_mapTilt continuous_fst continuous_snd + ((hs.comp continuous_fst).smul continuous_const) (F.continuousFirst v) continuous_const + (fun t y => F.normFirst t v y) a + continuousSecond v w := by + have hc : Continuous (fun q : ℝ × E => s q.1 • c) := (hs.comp continuous_fst).smul continuous_const + have h1 := F.continuous_mapTilt continuous_fst continuous_snd hc + (F.continuousFirst v) continuous_const (fun t y => F.normFirst t v y) a + have h2 := F.continuous_mapTilt continuous_fst continuous_snd hc + (F.continuousFirst w) continuous_const (fun t y => F.normFirst t w y) a + have h12 := F.continuous_mapTilt continuous_fst continuous_snd hc + (F.continuousSecond v w) continuous_const (fun t y => F.normSecond t v w y) a + have hp := F.continuous_mapTilt + (g := fun t y => (F.field t).first v y * (F.field t).first w y) + (M := fun _ => (F.boundFirst v:ℝ)*(F.boundFirst w:ℝ)) + continuous_fst continuous_snd hc + ((F.continuousFirst v).mul (F.continuousFirst w)) continuous_const + (fun t y => by + rw [abs_mul] + exact mul_le_mul (F.normFirst t v y) (F.normFirst t w y) (abs_nonneg _) (F.boundFirst v).coe_nonneg) a + exact h12.add ((hp.sub (h1.mul h2)).const_mul _) + continuousDot := F.continuous_transformedDot a c hs hds + hasDot x t := F.hasDerivAt_transformed a c x hs hd t + lip := F.lip + lipschitz t := ambientStep_lipschitz (F.lipschitz t) a.coe_nonneg (s t • c) + boundFirst := F.boundFirst + boundSecond v w := F.boundSecond v w + 2*a*F.boundFirst v*F.boundFirst w + boundDot t := F.boundDot t + |s t*ds t| *((F.boundSecond c c:ℝ)+(a:ℝ)*(F.boundFirst c:ℝ)^2) + continuousBound := F.continuousBound.add (((hs.mul hds).abs).mul_const _) + normFirst t v x := abs_ambientTilt_le (F.lipschitz t) ((F.field t).continuousFirst v) + (F.normFirst t v) a (s t • c) x + normSecond t v w x := by + have h1 := abs_ambientTilt_le (F.lipschitz t) ((F.field t).continuousFirst v) (F.normFirst t v) (a:ℝ) (s t • c) x + have h2 := abs_ambientTilt_le (F.lipschitz t) ((F.field t).continuousFirst w) (F.normFirst t w) (a:ℝ) (s t • c) x + have h12 := abs_ambientTilt_le (F.lipschitz t) ((F.field t).continuousSecond v w) (F.normSecond t v w) (a:ℝ) (s t • c) x + have hp := abs_ambientTilt_le (F.lipschitz t) (((F.field t).continuousFirst v).mul ((F.field t).continuousFirst w)) + (fun y => by + simp only [Pi.mul_apply, abs_mul] + exact mul_le_mul (F.normFirst t v y) (F.normFirst t w y) (abs_nonneg _) (F.boundFirst v).coe_nonneg) (a:ℝ) (s t • c) x + change |ambientTilt a (s t • c) (F.field t).val (fun y => (F.field t).first v y * (F.field t).first w y) x| ≤ + (F.boundFirst v:ℝ)*(F.boundFirst w:ℝ) at hp + have hprod := mul_le_mul h1 h2 (abs_nonneg _) (F.boundFirst v).coe_nonneg + have hsub := abs_sub_le + (ambientTilt a (s t • c) (F.field t).val (fun y => (F.field t).first v y*(F.field t).first w y) x) 0 + (ambientTilt a (s t • c) (F.field t).val ((F.field t).first v) x * + ambientTilt a (s t • c) (F.field t).val ((F.field t).first w) x) + simp only [sub_zero, zero_sub, abs_neg, abs_mul] at hsub + change |ambientTilt a (s t • c) (F.field t).val ((F.field t).second v w) x + (a:ℝ)* + (ambientTilt a (s t • c) (F.field t).val (fun y => (F.field t).first v y*(F.field t).first w y) x - + ambientTilt a (s t • c) (F.field t).val ((F.field t).first v) x * + ambientTilt a (s t • c) (F.field t).val ((F.field t).first w) x)| ≤ _ + apply (abs_add_le _ _).trans + rw [abs_mul, abs_of_nonneg a.coe_nonneg] + simp only [NNReal.coe_add, NNReal.coe_mul, NNReal.coe_ofNat] + nlinarith [a.coe_nonneg] + normDot := F.bound_transformedDot a c s ds +end ParisiFinite.FieldFamily + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology +namespace ParisiFinite + + + +structure MovingCoordinate (E : Type*) where + gamma : ℝ≥0 + direction : E + scale : ℝ → ℝ + velocity : ℝ → ℝ + continuousScale : Continuous scale + continuousVelocity : Continuous velocity + hasScale : ∀ t, HasDerivAt scale (velocity t) t + +namespace MovingCoordinate +variable {E : Type*} + +def sine (a : ℝ≥0) (c : E) : MovingCoordinate E where + gamma := a + direction := c + scale := Real.sin + velocity := Real.cos + continuousScale := Real.continuous_sin + continuousVelocity := Real.continuous_cos + hasScale := Real.hasDerivAt_sin + +def cosine (a : ℝ≥0) (c : E) : MovingCoordinate E where + gamma := a + direction := c + scale := Real.cos + velocity t := -Real.sin t + continuousScale := Real.continuous_cos + continuousVelocity := Real.continuous_sin.neg + hasScale := Real.hasDerivAt_cos + +def constant (a : ℝ≥0) (c : E) (s : ℝ) : MovingCoordinate E where + gamma := a + direction := c + scale _ := s + velocity _ := 0 + continuousScale := continuous_const + continuousVelocity := continuous_const + hasScale t := hasDerivAt_const t s +end MovingCoordinate + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + + + +def hierarchy (f : DirectionalField E) : List (MovingCoordinate E) → FieldFamily E + | [] => FieldFamily.constant f + | c::cs => (hierarchy f cs).transform c.gamma c.direction c.scale c.velocity + c.continuousScale c.continuousVelocity c.hasScale + +def hierarchyValue (f : E → ℝ) : List (MovingCoordinate E) → ℝ → E → ℝ + | [] => fun _ => f + | c::cs => fun t => ambientStep c.gamma (c.scale t • c.direction) (hierarchyValue f cs t) + +lemma hierarchy_val (f : DirectionalField E) (cs : List (MovingCoordinate E)) (t : ℝ) : + ((hierarchy f cs).field t).val = hierarchyValue f.val cs t := by + induction cs with + | nil => rfl + | cons c cs ih => + change ambientStep c.gamma (c.scale t • c.direction) ((hierarchy f cs).field t).val = _ + rw [ih] + rfl + + + +lemma hasDerivAt_hierarchyValue (f : DirectionalField E) (cs : List (MovingCoordinate E)) (t : ℝ) (x : E) : + HasDerivAt (fun s => hierarchyValue f.val cs s x) ((hierarchy f cs).dot t x) t := by + have h := (hierarchy f cs).hasDot x t + simpa only [hierarchy_val] using h + +lemma hierarchy_dot_cons (f : DirectionalField E) (c : MovingCoordinate E) + (cs : List (MovingCoordinate E)) (t : ℝ) (x : E) : + (hierarchy f (c::cs)).dot t x = + ambientTilt c.gamma (c.scale t • c.direction) ((hierarchy f cs).field t).val + ((hierarchy f cs).dot t) x + c.scale t*c.velocity t * + (ambientTilt c.gamma (c.scale t • c.direction) ((hierarchy f cs).field t).val + (((hierarchy f cs).field t).second c.direction c.direction) x + (c.gamma:ℝ)* + ambientTilt c.gamma (c.scale t • c.direction) ((hierarchy f cs).field t).val + (fun y => (((hierarchy f cs).field t).first c.direction y)^2) x) := rfl + +lemma ambientStep_zero_direction (a : ℝ) (f : E → ℝ) (x : E) : ambientStep a 0 f x = f x := by + by_cases ha : a=0 + · simp [ambientStep, logMean, ha] + · simp [ambientStep, logMean, ha, Real.log_exp] + +lemma hierarchyValue_zero_scales (f : E → ℝ) (cs : List (MovingCoordinate E)) (t : ℝ) + (ht : ∀ c ∈ cs, c.scale t = 0) : hierarchyValue f cs t = f := by + induction cs with + | nil => rfl + | cons c cs ih => + have hc := ht c (by simp) + have hcs : ∀ d ∈ cs, d.scale t = 0 := fun d hd => ht d (by simp [hd]) + simp only [hierarchyValue, hc, zero_smul, ih hcs] + funext x + exact ambientStep_zero_direction c.gamma f x +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SpinWInv.lean b/lean/OAI/Probability/ParisiFinite/SpinWInv.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e3db713eaaae24f3a82d5a11eeeb133bdbaedbc --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SpinWInv.lean @@ -0,0 +1,698 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Act + +namespace OAI + +/-! Spin W Inv. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +@[simp] theorem spinW_inv (e : E) (x : SpinSpace E) : spinW (-e) (spinW e x)=x := by + ext i + exact (weyl e).symm_apply_apply (x i) + +@[simp] theorem spinW_inv' (e : E) (x : SpinSpace E) : spinW e (spinW (-e) x)=x := by + simpa only [neg_neg] using spinW_inv (-e) x + + + +theorem center_probe_product {ι : Type*} (l : List ι) (A : ι → Matrix (Fin 2) (Fin 2) ℂ) + (D : ι → E) (e : E) (x : SpinSpace E) : + ProbeProduct.act (fun j => (spinW (-e)).comp ((probe (A j) (D j)).comp (spinW e))) l x = + spinW (-e) (ProbeProduct.act (fun j => probe (A j) (D j)) l (spinW e x)) := by + induction l with + | nil => simp + | cons j l ih => + simp only [ProbeProduct.act_cons,ContinuousLinearMap.comp_apply,ih,spinW_inv'] + + + +theorem centered_product_phase_bound {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (D : ι → E) (e : E) (α : ℝ) + (hα : 0 ≤ α) (hA : ∀ j ∈ l, A j ∈ unitary _) + (hp : ∀ j ∈ l, |(-2*(⟪D j,e⟫_ℂ).im)| ≤ α) (x : SpinSpace E) : + ‖spinW (-e) (ProbeProduct.act (fun j => probe (A j) (D j)) l (spinW e x))- + ProbeProduct.act (fun j => probe (A j) (D j)) l x‖ ≤ l.length*α*‖x‖ := by + rw [← center_probe_product] + apply ProbeProduct.perturbation_bound _ _ l α hα + · intro j hj z + simp only [ContinuousLinearMap.comp_apply,norm_spinW,norm_probe _ (hA j hj)] + rfl + · intro j hj z + exact (norm_probe _ (hA j hj) _ z).le + · intro j hj z + simp only [ContinuousLinearMap.comp_apply] + rw [centered_toggled_probe _ (hA j hj)] + calc + _ ≤ |(-2*(⟪D j,e⟫_ℂ).im)| *‖probe (A j) (D j) z‖ := + probePhase_sub_le _ (hA j hj) _ _ + _ ≤ α*‖z‖ := by rw [norm_probe _ (hA j hj)]; gcongr; exact hp j hj + + + +theorem centered_zero_clock_bound {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (v w : ι → E) + (r L M Δ α : ℝ) (e : E) (x : PreSpin E) + (hL : 0 ≤ L) (hM : 0 ≤ M) (hΔ : 0 ≤ Δ) (hα : 0 ≤ α) + (hA : ∀ j ∈ l, A j ∈ unitary _) + (hv : ∀ j ∈ l, ‖v j‖ ≤ L) (hw : ∀ j ∈ l, ‖w j‖ ≤ L) + (hd : ∀ j ∈ l, ‖v j-w j‖ ≤ Δ) + (hMass : ∀ j ∈ l, matrixMass (A j) ≤ M) + (hMassStar : ∀ j ∈ l, matrixMass (A j).conjTranspose ≤ M) + (hp : ∀ j ∈ l, |(-2*(⟪r • v j,e⟫_ℂ).im)| ≤ α) + (hclock : (l.map fun j => Complex.I • probeField (A j) (w j) x).sum=0) : + ‖spinW (-e) (ProbeProduct.act (fun j => probe (A j) (r • v j)) l (spinW e (spinCoe x)))-spinCoe x‖ ≤ + l.length*((r^2*L^2+|r| *Δ)*M*spinBound x)+ + l.length^2*|r| *(2*|r| *L^2*M^3*spinBound x)+l.length*α*‖spinCoe x‖ := by + have h1 := centered_product_phase_bound l A (fun j => r • v j) e α hα hA hp (spinCoe x) + have h2 := zero_clock_spin_probes l A v w r L M Δ x hL hM hΔ hA hv hw hd hMass hMassStar hclock + have htri := norm_sub_le_norm_sub_add_norm_sub + (spinW (-e) (ProbeProduct.act (fun j => probe (A j) (r • v j)) l (spinW e (spinCoe x)))) + (ProbeProduct.act (fun j => probe (A j) (r • v j)) l (spinCoe x)) (spinCoe x) + linarith + +end CoherentFock + +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +namespace RootSpin + +def X : Matrix (Fin 2) (Fin 2) ℂ := !![0,1;1,0] +def Y : Matrix (Fin 2) (Fin 2) ℂ := !![0,-Complex.I;Complex.I,0] +def Z : Matrix (Fin 2) (Fin 2) ℂ := !![1,0;0,-1] +def R (t : ℝ) : Matrix (Fin 2) (Fin 2) ℂ := + (Real.cos t : ℂ) • (1 : Matrix (Fin 2) (Fin 2) ℂ)+(-Complex.I*(Real.sin t : ℂ)) • X + +@[simp] theorem X_star : X.conjTranspose=X := by ext i j; fin_cases i <;> fin_cases j <;> simp [X] +@[simp] theorem Y_star : Y.conjTranspose=Y := by ext i j; fin_cases i <;> fin_cases j <;> simp [Y] +@[simp] theorem Z_star : Z.conjTranspose=Z := by ext i j; fin_cases i <;> fin_cases j <;> simp [Z] +@[simp] theorem X_sq : X*X=1 := by ext i j; fin_cases i <;> fin_cases j <;> simp [X,Matrix.mul_apply,Fin.sum_univ_two] +@[simp] theorem Y_sq : Y*Y=1 := by ext i j; fin_cases i <;> fin_cases j <;> simp [Y,Matrix.mul_apply,Fin.sum_univ_two] +@[simp] theorem Z_sq : Z*Z=1 := by ext i j; fin_cases i <;> fin_cases j <;> simp [Z,Matrix.mul_apply,Fin.sum_univ_two] + +theorem X_unitary : X ∈ unitary _ := by simp [Unitary.mem_iff,Matrix.star_eq_conjTranspose] +theorem Y_unitary : Y ∈ unitary _ := by simp [Unitary.mem_iff,Matrix.star_eq_conjTranspose] +theorem Z_unitary : Z ∈ unitary _ := by simp [Unitary.mem_iff,Matrix.star_eq_conjTranspose] + +@[simp] theorem R_apply (t : ℝ) (i j : Fin 2) : + R t i j=if i=j then (Real.cos t : ℂ) else -Complex.I*(Real.sin t : ℂ) := by + fin_cases i <;> fin_cases j <;> simp [R,X] + +theorem R_star (t : ℝ) : (R t).conjTranspose=R (-t) := by + ext i j + fin_cases i <;> fin_cases j <;> + simp [Matrix.conjTranspose_apply,R_apply,-Complex.ofReal_cos,-Complex.ofReal_sin] + +theorem R_add (s t : ℝ) : R s*R t=R (s+t) := by + ext i j + fin_cases i <;> fin_cases j <;> apply Complex.ext <;> + simp [Matrix.mul_apply,Fin.sum_univ_two,R_apply,Complex.mul_re,Complex.mul_im, + Real.cos_add,Real.sin_add,-Complex.ofReal_cos,-Complex.ofReal_sin] <;> ring + +@[simp] theorem R_zero : R 0=1 := by simp [R] + +theorem R_unitary (t : ℝ) : R t ∈ unitary _ := by + rw [Unitary.mem_iff] + change (R t).conjTranspose*R t=1 ∧ R t*(R t).conjTranspose=1 + simp [R_star,R_add] + +def hadamard : Matrix (Fin 2) (Fin 2) ℂ := fun i j => if i=1 ∧ j=1 then -1 else 1 + +def diagUnit : (Matrix (Fin 2) (Fin 2) ℂ)ˣ where + val := hadamard + inv := (1/2:ℂ) • hadamard + val_inv := by ext i j; fin_cases i <;> fin_cases j <;> norm_num [hadamard,Matrix.mul_apply,Fin.sum_univ_two] + inv_val := by ext i j; fin_cases i <;> fin_cases j <;> norm_num [hadamard,Matrix.mul_apply,Fin.sum_univ_two] + +theorem diagonalization (z : ℂ) : + (diagUnit : Matrix (Fin 2) (Fin 2) ℂ)*Matrix.diagonal (fun i : Fin 2 => if i=0 then z else -z)* + ((diagUnit⁻¹ : (Matrix (Fin 2) (Fin 2) ℂ)ˣ) : Matrix (Fin 2) (Fin 2) ℂ)=z • X := by + ext i j + fin_cases i <;> fin_cases j <;> simp [diagUnit,hadamard,X,Matrix.mul_apply,Fin.sum_univ_two] <;> ring + +theorem exp_X (z : ℂ) : + NormedSpace.exp (z • X)=((Complex.exp z+Complex.exp (-z))/2) • (1 : Matrix (Fin 2) (Fin 2) ℂ)+ + ((Complex.exp z-Complex.exp (-z))/2) • X := by + rw [← diagonalization z,Matrix.exp_units_conj,Matrix.exp_diagonal] + ext i j + fin_cases i <;> fin_cases j <;> + simp [diagUnit,hadamard,X,Matrix.mul_apply,Fin.sum_univ_two,← Complex.exp_eq_exp_ℂ] <;> ring + +theorem R_eq_exp (t : ℝ) : R t=NormedSpace.exp ((-Complex.I*(t:ℂ)) • X) := by + rw [exp_X] + have hp : Complex.exp (-Complex.I*(t:ℂ))=(Real.cos t:ℂ)-Complex.I*(Real.sin t:ℂ) := by + rw [show -Complex.I*(t:ℂ)=(-(t:ℂ))*Complex.I by ring,Complex.exp_mul_I] + simp [← Complex.ofReal_cos,← Complex.ofReal_sin,sub_eq_add_neg,mul_comm] + have hm : Complex.exp (-(-Complex.I*(t:ℂ)))=(Real.cos t:ℂ)+Complex.I*(Real.sin t:ℂ) := by + rw [neg_mul,neg_neg,mul_comm,Complex.exp_mul_I,← Complex.ofReal_cos,← Complex.ofReal_sin] + ring + rw [hp,hm] + unfold R + congr 1 <;> congr 1 <;> ring + +theorem R_conjugate_Z (t : ℝ) : (R t).conjTranspose*Z*R t= + (Real.cos (2*t):ℂ) • Z+(Real.sin (2*t):ℂ) • Y := by + ext i j + fin_cases i <;> fin_cases j <;> apply Complex.ext <;> + simp [Matrix.mul_apply,Fin.sum_univ_two,Matrix.conjTranspose_apply,R_apply,Z,Y, + Real.cos_two_mul,Real.sin_two_mul,-Complex.ofReal_sin,-Complex.ofReal_cos, + Complex.mul_re,Complex.mul_im,-Complex.ofReal_pow] <;> + nlinarith [Real.sin_sq_add_cos_sq t] + +end RootSpin + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] +open RootSpin + +@[simp] theorem rootX_apply (x : SpinSpace E) (i : Fin 2) : + SpinOperators.act X x i = x (1-i) := by + fin_cases i <;> simp [SpinOperators.act_apply,X,Fin.sum_univ_two] + +@[simp] theorem rootZ_apply (x : SpinSpace E) (i : Fin 2) : + SpinOperators.act Z x i = if i=0 then x i else -x i := by + fin_cases i <;> simp [SpinOperators.act_apply,Z,Fin.sum_univ_two] + + +theorem WZ_rootX (d : E) : + (WZ d).comp (SpinOperators.act X) = + (SpinOperators.act X).comp (WZ (-d)) := by + ext x i + fin_cases i <;> simp [WZ_apply,X] + + +theorem WZ_rootZ (d : E) : + (WZ d).comp (SpinOperators.act Z) = + (SpinOperators.act Z).comp (WZ d) := by + ext x i + fin_cases i <;> simp [WZ_apply,Z] + +theorem rootR (t : ℝ) : + (SpinOperators.act (R t) : SpinSpace E →L[ℂ] SpinSpace E) = + (Real.cos t:ℂ) • ContinuousLinearMap.id ℂ (SpinSpace E)+ + (-Complex.I*(Real.sin t:ℂ)) • SpinOperators.act X := by + change SpinOperators.rep (R t)=_ + simp only [R,map_add,map_smul,SpinOperators.rep_apply,SpinOperators.act_one] + + + +theorem initialization_split (γ δ : ℝ) (v e : E) : + (WZ (γ • v)).comp ((SpinOperators.act (R δ)).comp (WZ ((-γ) • e))) = + ((Real.cos δ:ℂ)*phase (γ • v) ((-γ) • e)) • WZ (γ • (v-e))+ + ((-Complex.I*(Real.sin δ:ℂ))*phase ((-γ) • v) ((-γ) • e)) • + (SpinOperators.act X).comp (WZ ((-γ) • (v+e))) := by + rw [rootR,ContinuousLinearMap.add_comp,ContinuousLinearMap.smul_comp, + ContinuousLinearMap.smul_comp,ContinuousLinearMap.id_comp, + ContinuousLinearMap.comp_add,ContinuousLinearMap.comp_smul, + ContinuousLinearMap.comp_smul,← ContinuousLinearMap.comp_assoc,WZ_rootX, + ContinuousLinearMap.comp_assoc,WZ_mul,WZ_mul, + ContinuousLinearMap.comp_smul,smul_smul,smul_smul] + have h1 : γ • v+(-γ) • e=γ • (v-e) := by module + have h2 : - (γ • v)+(-γ) • e=(-γ) • (v+e) := by module + rw [h1,h2] + simp only [neg_smul] + + + +theorem initialization_special_norm (γ δ β : ℝ) (v e : E) (x : SpinSpace E) : + ‖((-Complex.I*(Real.sin δ:ℂ))*phase ((-γ) • v) ((-γ) • e)) • + SpinOperators.act (R β) (SpinOperators.act X (WZ ((-γ) • (v+e)) x))‖ = + |Real.sin δ| *‖x‖ := by + rw [norm_smul,norm_mul,norm_mul,norm_neg,Complex.norm_I,one_mul, + Complex.norm_real,Real.norm_eq_abs,norm_phase,mul_one, + SpinOperators.norm_act (R_unitary _),SpinOperators.norm_act X_unitary,norm_WZ] + + + +theorem quarter_conjugate : (R (Real.pi/4)).conjTranspose*Z*R (Real.pi/4)=Y := by + rw [R_conjugate_Z] + have he : 2*(Real.pi/4)=Real.pi/2 := by ring + simp [he] + +end CoherentFock + + + +namespace PointedTree +universe u +structure HilbertData where + Carrier : Type u + [normed : NormedAddCommGroup Carrier] + [inner : InnerProductSpace ℂ Carrier] + [complete : CompleteSpace Carrier] +attribute [instance] HilbertData.normed HilbertData.inner HilbertData.complete +instance : CoeSort HilbertData (Type u) := ⟨HilbertData.Carrier⟩ + +abbrev doubleData (H : HilbertData) : HilbertData where + Carrier := SpinOperators.Double H + +abbrev fockData (H : HilbertData) : HilbertData where + Carrier := CoherentFock.Space H + +abbrev complexData : HilbertData where + Carrier := ℂ + +variable {H K L : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + [NormedAddCommGroup K] [InnerProductSpace ℂ K] + [NormedAddCommGroup L] [InnerProductSpace ℂ L] + +def spinMap (T : H →ₗᵢ[ℂ] K) : SpinOperators.Double H →ₗᵢ[ℂ] SpinOperators.Double K where + toFun x := WithLp.toLp 2 (fun i => T (x i)) + map_add' x y := by ext i; simp + map_smul' z x := by ext i; simp + norm_map' x := by + change ‖WithLp.toLp 2 (fun i : Fin 2 => T (x i))‖=‖x‖ + have he : ‖WithLp.toLp 2 (fun i : Fin 2 => T (x i))‖^2=‖x‖^2 := by + rw [PiLp.norm_sq_eq_of_L2,PiLp.norm_sq_eq_of_L2] + simp + nlinarith [norm_nonneg (WithLp.toLp 2 (fun i : Fin 2 => T (x i))),norm_nonneg x] + +@[simp] theorem spinMap_apply (T : H →ₗᵢ[ℂ] K) (x : SpinOperators.Double H) (i : Fin 2) : + spinMap T x i=T (x i) := rfl + +@[simp] theorem spinMap_comp (T : H →ₗᵢ[ℂ] K) (S : K →ₗᵢ[ℂ] L) : + (spinMap S).comp (spinMap T)=spinMap (S.comp T) := by ext x i; rfl + +@[simp] theorem spinMap_id : spinMap (LinearIsometry.id : H →ₗᵢ[ℂ] H)=LinearIsometry.id := by + ext x i + rfl + +theorem spinMap_root (T : H →ₗᵢ[ℂ] K) (A : Matrix (Fin 2) (Fin 2) ℂ) + (x : SpinOperators.Double H) : + spinMap T (SpinOperators.act A x)=SpinOperators.act A (spinMap T x) := by + ext i + simp [SpinOperators.act_apply] + + +def scalarEmbedding (η : H) (hη : ‖η‖=1) : ℂ →ₗᵢ[ℂ] H where + toFun z := z • η + map_add' z w := add_smul _ _ _ + map_smul' z w := by simp [mul_smul] + norm_map' z := by simp [norm_smul,hη] + +@[simp] theorem scalarEmbedding_apply (η : H) (hη : ‖η‖=1) (z : ℂ) : + scalarEmbedding η hη z=z • η := rfl + +def plus : SpinOperators.Double ℂ := WithLp.toLp 2 (fun _ => ((Real.sqrt 2)⁻¹ : ℝ)) + +theorem norm_plus : ‖plus‖=1 := by + have h : ‖plus‖^2=1 := by + rw [PiLp.norm_sq_eq_of_L2] + change ∑ _ : Fin 2, ‖(((Real.sqrt 2)⁻¹:ℝ):ℂ)‖^2=1 + simp only [Complex.norm_real,Real.norm_eq_abs, + abs_inv,abs_of_nonneg (Real.sqrt_nonneg 2),Fin.sum_univ_two] + have hs : Real.sqrt 2^2=2 := Real.sq_sqrt (by norm_num) + rw [inv_pow,hs] + norm_num + nlinarith [norm_nonneg plus] + +open CoherentFock + +def gammaEmbedding (T : H →ₗᵢ[ℂ] K) : Space H →ₗᵢ[ℂ] Space K where + toLinearMap := (Gamma T).toLinearMap + norm_map' := norm_Gamma T + +@[simp] theorem gammaEmbedding_coherent (T : H →ₗᵢ[ℂ] K) (d : H) : + gammaEmbedding T (coherent d)=coherent (T d) := Gamma_coherent T d + +def vacuum (H : Type*) [NormedAddCommGroup H] [InnerProductSpace ℂ H] : SpinSpace H := + spinMap (scalarEmbedding (coherent (0:H)) (norm_coherent _)) plus + +@[simp] theorem vacuum_apply (i : Fin 2) : + vacuum H i=(((Real.sqrt 2)⁻¹ : ℝ):ℂ) • coherent (0:H) := rfl + +@[simp] theorem norm_vacuum : ‖vacuum H‖=1 := by + unfold vacuum + rw [(spinMap _).norm_map,norm_plus] + +structure PointedData extends HilbertData where + vac : Carrier + norm_vac : ‖vac‖=1 +instance : CoeSort PointedData (Type u) := ⟨fun H => H.Carrier⟩ +instance (H : PointedData) : NormedAddCommGroup H := H.normed +instance (H : PointedData) : InnerProductSpace ℂ H := H.inner +instance (H : PointedData) : CompleteSpace H := H.complete + + + +def centered (H : PointedData) : Submodule ℂ H := (ℂ ∙ H.vac)ᗮ + +instance (H : PointedData) : CompleteSpace (centered H) := by + unfold centered + infer_instance + +@[simp] theorem mem_centered (H : PointedData) (x : H) : + x ∈ centered H ↔ ⟪H.vac,x⟫_ℂ=0 := + Submodule.mem_orthogonal_singleton_iff_inner_right + +structure PointedMap (H K : PointedData) where + toLinearIsometry : H →ₗᵢ[ℂ] K + map_vac : toLinearIsometry H.vac=K.vac + +def centeredMap {H K : PointedData} (T : PointedMap H K) : centered H →ₗᵢ[ℂ] centered K where + toFun x := ⟨T.toLinearIsometry x,by + rw [mem_centered,← T.map_vac,T.toLinearIsometry.inner_map_map] + exact (mem_centered H x).mp x.property⟩ + map_add' x y := by ext; exact T.toLinearIsometry.map_add _ _ + map_smul' z x := by ext; exact T.toLinearIsometry.map_smul _ _ + norm_map' x := T.toLinearIsometry.norm_map x + +@[simp] theorem centeredMap_coe {H K : PointedData} (T : PointedMap H K) (x : centered H) : + (centeredMap T x : K)=T.toLinearIsometry (x:H) := rfl + +abbrev base : PointedData where + toHilbertData := doubleData complexData + vac := plus + norm_vac := norm_plus + +abbrev next (H : PointedData) : PointedData where + toHilbertData := doubleData (fockData { Carrier := centered H }) + vac := vacuum (centered H) + norm_vac := norm_vacuum + +def nextMap {H K : PointedData} (T : PointedMap H K) : PointedMap (next H) (next K) where + toLinearIsometry := spinMap (gammaEmbedding (centeredMap T)) + map_vac := by + change spinMap (gammaEmbedding (centeredMap T)) (vacuum (centered H))=vacuum (centered K) + ext i + simp [vacuum_apply] + +@[reducible] def level : ℕ → PointedData + | 0 => base + | n+1 => next (level n) + +abbrev Level (n : ℕ) := (level n).Carrier +abbrev Mode (n : ℕ) := centered (level n) + +def vac (n : ℕ) : Level n := (level n).vac + +@[simp] theorem norm_vac (n : ℕ) : ‖vac n‖=1 := (level n).norm_vac + + +def empty : (n : ℕ) → PointedMap (level n) (level (n+1)) + | 0 => ⟨spinMap (scalarEmbedding (coherent (0:Mode 0)) (norm_coherent _)),rfl⟩ + | n+1 => nextMap (empty n) + +@[simp] theorem empty_vac (n : ℕ) : (empty n).toLinearIsometry (vac n)=vac (n+1) := + (empty n).map_vac + + +def root (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) : Level n →L[ℂ] Level n := + match n with + | 0 => SpinOperators.act A + | _+1 => SpinOperators.act A + +@[simp] theorem root_empty (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (x : Level n) : + (empty n).toLinearIsometry (root n A x)=root (n+1) A ((empty n).toLinearIsometry x) := by + cases n <;> exact spinMap_root _ _ _ + +theorem spinMap_cost (T : H →ₗᵢ[ℂ] K) (d : H) (x : SpinSpace H) : + spinMap (gammaEmbedding T) (WZ d x)=WZ (T d) (spinMap (gammaEmbedding T) x) := by + ext i + change Gamma T (W (if i=0 then d else -d) (x i))= + W (if i=0 then T d else -(T d)) (Gamma T (x i)) + have h := congrArg (fun A => A (x i)) (Gamma_W T (if i=0 then d else -d)) + by_cases hi : i=0 <;> simpa [hi] using h + + +theorem cost_empty (n : ℕ) (d : Mode n) (x : Level (n+1)) : + (empty (n+1)).toLinearIsometry (WZ d x)= + WZ (centeredMap (empty n) d) ((empty (n+1)).toLinearIsometry x) := + spinMap_cost (centeredMap (empty n)) d x + +end PointedTree + +namespace SpinOperators +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] [CompleteSpace H] + +def actEquiv (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) : Double H ≃ₗᵢ[ℂ] Double H := + Unitary.linearIsometryEquiv ⟨act A,act_mem_unitary hA⟩ + +@[simp] theorem actEquiv_apply (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) (x : Double H) : + actEquiv A hA x=act A x := rfl +end SpinOperators + +namespace PointedTree +open CoherentFock RootSpin +variable {H K : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + [NormedAddCommGroup K] [InnerProductSpace ℂ K] + +def spinEquiv (T : H ≃ₗᵢ[ℂ] K) : SpinOperators.Double H ≃ₗᵢ[ℂ] SpinOperators.Double K where + toFun := spinMap T.toLinearIsometry + invFun := spinMap T.symm.toLinearIsometry + left_inv x := by ext i; simp + right_inv x := by ext i; simp + map_add' := (spinMap T.toLinearIsometry).map_add + map_smul' := (spinMap T.toLinearIsometry).map_smul + norm_map' := (spinMap T.toLinearIsometry).norm_map + +@[simp] theorem spinEquiv_apply (T : H ≃ₗᵢ[ℂ] K) (x : SpinOperators.Double H) (i : Fin 2) : + spinEquiv T x i = T (x i) := rfl + +theorem spinFlip_twice (T : H →ₗᵢ[ℂ] H) (hT : Function.Involutive T) + (x : SpinOperators.Double H) : + SpinOperators.act X (spinMap T (SpinOperators.act X (spinMap T x)))=x := by + ext i + fin_cases i <;> simp [SpinOperators.act_apply,X,Fin.sum_univ_two] <;> exact hT _ + + +structure Symmetry (H : PointedData) where + op : H ≃ₗᵢ[ℂ] H + invariant : op H.vac=H.vac + square : Function.Involutive op + +namespace Symmetry +variable {A : PointedData} + +def centered (S : Symmetry A) : PointedTree.centered A ≃ₗᵢ[ℂ] PointedTree.centered A where + toFun x := ⟨S.op x,by + rw [mem_centered,← S.invariant,S.op.inner_map_map] + exact (mem_centered A x).mp x.property⟩ + invFun x := ⟨S.op x,by + rw [mem_centered,← S.invariant,S.op.inner_map_map] + exact (mem_centered A x).mp x.property⟩ + left_inv x := by ext; exact S.square x + right_inv x := by ext; exact S.square x + map_add' x y := by ext; exact S.op.map_add _ _ + map_smul' z x := by ext; exact S.op.map_smul _ _ + norm_map' x := S.op.norm_map x + +@[simp] theorem centered_coe (S : Symmetry A) (x : PointedTree.centered A) : + (S.centered x:A)=S.op x := rfl + +@[simp] theorem centered_square (S : Symmetry A) (x : PointedTree.centered A) : + S.centered (S.centered x)=x := by ext; exact S.square x + +@[simp] theorem gamma_square (S : Symmetry A) (x : Space (PointedTree.centered A)) : + Gamma S.centered.toLinearIsometry (Gamma S.centered.toLinearIsometry x)=x := by + have hc : S.centered.toLinearIsometry.comp S.centered.toLinearIsometry=LinearIsometry.id := by + apply LinearIsometry.ext + intro v + exact S.centered_square v + have h := congrArg (fun T => T x) (Gamma_comp S.centered.toLinearIsometry S.centered.toLinearIsometry) + simpa [hc] using h + + +def next (S : Symmetry A) : Symmetry (PointedTree.next A) where + op := (spinEquiv (secondQuantization S.centered)).trans + (SpinOperators.actEquiv X X_unitary) + invariant := by + change SpinOperators.act X (spinEquiv (secondQuantization S.centered) (vacuum _))=vacuum _ + ext i + fin_cases i <;> simp [vacuum_apply,secondQuantization,X] + square x := by + change SpinOperators.act X (spinMap (gammaEmbedding S.centered.toLinearIsometry) + (SpinOperators.act X (spinMap (gammaEmbedding S.centered.toLinearIsometry) x)))=x + exact spinFlip_twice (gammaEmbedding S.centered.toLinearIsometry) (fun y => S.gamma_square y) x + +end Symmetry + + +def baseSymmetry : Symmetry base where + op := SpinOperators.actEquiv X X_unitary + invariant := by + change SpinOperators.act (H := ℂ) X plus=plus + ext i + fin_cases i <;> simp [plus,SpinOperators.act_apply,X,Fin.sum_univ_two] + square x := by + change SpinOperators.act (H := ℂ) X (SpinOperators.act X x)=x + ext i + fin_cases i <;> simp [SpinOperators.act_apply,X,Fin.sum_univ_two] + + +def symmetry : (n : ℕ) → Symmetry (level n) + | 0 => baseSymmetry + | n+1 => (symmetry n).next + +@[simp] theorem symmetry_vac (n : ℕ) : (symmetry n).op (vac n)=vac n := + (symmetry n).invariant + +@[simp] theorem symmetry_square (n : ℕ) (x : Level n) : + (symmetry n).op ((symmetry n).op x)=x := (symmetry n).square x + + + +theorem odd_centered {A : PointedData} (S : Symmetry A) (x : A) (hx : S.op x=-x) : + x ∈ centered A := by + rw [mem_centered] + have h := S.op.inner_map_map A.vac x + rw [S.invariant,hx,inner_neg_right] at h + linear_combination - (1/2:ℂ) * h + +end PointedTree + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +@[simp] theorem W_neg_cancel_left (d : E) (x : Space E) : W (-d) (W d x)=x := + (weyl d).symm_apply_apply x + + +def costEquiv (d : E) : SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E where + toFun := WZ d + invFun := WZ (-d) + left_inv x := by + ext i + fin_cases i <;> simp [WZ_apply, W_neg_cancel] + right_inv x := by + ext i + fin_cases i <;> simp [WZ_apply, W_neg_cancel] + map_add' := (WZ d).map_add + map_smul' := (WZ d).map_smul + norm_map' := norm_WZ d + +@[simp] theorem costEquiv_apply (d : E) (x : SpinSpace E) : costEquiv d x=WZ d x := rfl +@[simp] theorem costEquiv_symm_apply (d : E) (x : SpinSpace E) : (costEquiv d).symm x=WZ (-d) x := rfl +end CoherentFock + +namespace PointedTree +open RootSpin CoherentFock +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + +theorem flipMap_rootZ (T : H →ₗᵢ[ℂ] H) (x : SpinOperators.Double H) : + SpinOperators.act X (spinMap T (SpinOperators.act Z x))= + -SpinOperators.act Z (SpinOperators.act X (spinMap T x)) := by + rw [spinMap_root] + ext i + fin_cases i <;> simp [SpinOperators.act_apply,X,Z,Fin.sum_univ_two] + +theorem flipMap_rootR (T : H →ₗᵢ[ℂ] H) (t : ℝ) (x : SpinOperators.Double H) : + SpinOperators.act X (spinMap T (SpinOperators.act (R t) x))= + SpinOperators.act (R t) (SpinOperators.act X (spinMap T x)) := by + rw [spinMap_root] + ext i + fin_cases i <;> simp [SpinOperators.act_apply,X,R_apply,Fin.sum_univ_two,add_comm] + + +theorem symmetry_rootZ (n : ℕ) (x : Level n) : + (symmetry n).op (root n Z x)=-root n Z ((symmetry n).op x) := by + cases n with + | zero => + change SpinOperators.act (H := ℂ) X (SpinOperators.act Z x)= -SpinOperators.act Z (SpinOperators.act X x) + simpa only [spinMap_id,LinearIsometry.id_apply] using flipMap_rootZ (LinearIsometry.id : ℂ →ₗᵢ[ℂ] ℂ) x + | succ n => exact flipMap_rootZ (gammaEmbedding (symmetry n).centered.toLinearIsometry) x + +theorem symmetry_rootR (n : ℕ) (t : ℝ) (x : Level n) : + (symmetry n).op (root n (R t) x)=root n (R t) ((symmetry n).op x) := by + cases n with + | zero => + change SpinOperators.act (H := ℂ) X (SpinOperators.act (R t) x)=SpinOperators.act (R t) (SpinOperators.act X x) + simpa only [spinMap_id,LinearIsometry.id_apply] using flipMap_rootR (LinearIsometry.id : ℂ →ₗᵢ[ℂ] ℂ) t x + | succ n => exact flipMap_rootR (gammaEmbedding (symmetry n).centered.toLinearIsometry) t x + + +def rootEquiv (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) : Level n ≃ₗᵢ[ℂ] Level n := + match n with + | 0 => SpinOperators.actEquiv A hA + | _+1 => SpinOperators.actEquiv A hA + +@[simp] theorem rootEquiv_apply (n : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) (x : Level n) : + rootEquiv n A hA x=root n A x := by cases n <;> rfl + +@[simp] theorem norm_rootZ (n : ℕ) (x : Level n) : ‖root n Z x‖=‖x‖ := + by simpa only [rootEquiv_apply] using (rootEquiv n Z Z_unitary).norm_map x + + + +structure EvenUnitary (n : ℕ) where + op : Level n ≃ₗᵢ[ℂ] Level n + commutes : ∀x, (symmetry n).op (op x)=op ((symmetry n).op x) + +namespace EvenUnitary + +def ident (n : ℕ) : EvenUnitary n where + op := LinearIsometryEquiv.refl ℂ (Level n) + commutes _ := rfl + + +def followedBy {n : ℕ} (U V : EvenUnitary n) : EvenUnitary n where + op := U.op.trans V.op + commutes x := by + change (symmetry n).op (V.op (U.op x))=V.op (U.op ((symmetry n).op x)) + rw [V.commutes,U.commutes] + +theorem symm_commutes {n : ℕ} (U : EvenUnitary n) (x : Level n) : + (symmetry n).op (U.op.symm x)=U.op.symm ((symmetry n).op x) := by + apply U.op.injective + rw [← U.commutes,U.op.apply_symm_apply,U.op.apply_symm_apply] + + +def insertion {n : ℕ} (U : EvenUnitary n) : Mode n := + ⟨U.op.symm (root n Z (U.op (vac n))),by + apply odd_centered (symmetry n) + rw [U.symm_commutes,symmetry_rootZ,U.commutes,symmetry_vac,map_neg]⟩ + +@[simp] theorem insertion_coe {n : ℕ} (U : EvenUnitary n) : + (U.insertion:Level n)=U.op.symm (root n Z (U.op (vac n))) := rfl + +@[simp] theorem norm_insertion {n : ℕ} (U : EvenUnitary n) : ‖U.insertion‖=1 := by + change ‖U.op.symm (root n Z (U.op (vac n)))‖=1 + rw [U.op.symm.norm_map,norm_rootZ,U.op.norm_map,norm_vac] + +@[simp] theorem insertion_odd {n : ℕ} (U : EvenUnitary n) : + (symmetry n).centered U.insertion=-U.insertion := by + apply Subtype.ext + change (symmetry n).op (U.op.symm (root n Z (U.op (vac n))))= + -U.op.symm (root n Z (U.op (vac n))) + rw [U.symm_commutes,symmetry_rootZ,U.commutes,symmetry_vac,map_neg] + +def mixer (n : ℕ) (t : ℝ) : EvenUnitary n where + op := rootEquiv n (R t) (R_unitary t) + commutes x := by simpa only [rootEquiv_apply] using symmetry_rootR n t x + + +def cost (n : ℕ) (d : Mode n) (hd : (symmetry n).centered d=-d) : EvenUnitary (n+1) where + op := costEquiv d + commutes x := by + change SpinOperators.act X + (spinMap (gammaEmbedding (symmetry n).centered.toLinearIsometry) (WZ d x))= + WZ d (SpinOperators.act X + (spinMap (gammaEmbedding (symmetry n).centered.toLinearIsometry) x)) + change (symmetry n).centered.toLinearIsometry d=-d at hd + rw [spinMap_cost,hd] + exact congrArg (fun A : SpinSpace (Mode n) →L[ℂ] SpinSpace (Mode n) => + A (spinMap (gammaEmbedding (symmetry n).centered.toLinearIsometry) x)) (WZ_rootX d).symm + + +theorem cost_insertion (n : ℕ) (U : EvenUnitary (n+1)) (d : Mode n) + (hd : (symmetry n).centered d=-d) : (U.followedBy (cost n d hd)).insertion=U.insertion := by + apply Subtype.ext + change U.op.symm ((costEquiv d).symm (SpinOperators.act Z (costEquiv d (U.op (vac (n+1))))))= + U.op.symm (SpinOperators.act Z (U.op (vac (n+1)))) + congr 1 + apply (costEquiv d).injective + simp only [LinearIsometryEquiv.apply_symm_apply] + exact congrArg (fun A : SpinSpace (Mode n) →L[ℂ] SpinSpace (Mode n) => A (U.op (vac (n+1)))) + (WZ_rootZ d).symm + +end EvenUnitary +end PointedTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SpinWZeroApply.lean b/lean/OAI/Probability/ParisiFinite/SpinWZeroApply.lean new file mode 100644 index 0000000000000000000000000000000000000000..c0eb84cf88489365066f70a2e73acde2b31b75d5 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SpinWZeroApply.lean @@ -0,0 +1,664 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ActualCenterPhase + +namespace OAI + +/-! Spin W Zero Apply. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +namespace PointedTree +open CoherentFock RootSpin +local instance selectionRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance selectionRealSMul : SMul ℝ ModeInfinity := selectionRealModule.toDistribMulAction.toSMul +local instance selectionRealSMulZero : SMulZeroClass ℝ ModeInfinity := { smul_zero := selectionRealModule.toDistribMulAction.smul_zero } + +theorem spinW_zero_apply (x : SpinSpace ModeInfinity) : spinW 0 x=x := by + ext i + simp only [spinW_apply,W_zero,ContinuousLinearMap.id_apply] + + + +theorem reciprocal_scale_eventually {α : Type*} {l : Filter α} (r : α → ℝ) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ t in l,0 ‖s t‖) l (𝓝 0)) (hρ : Tendsto (fun t => ‖ρ t‖) l (𝓝 0)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + (∀ (z : α → PreSpin ModeInfinity) (B' A' : ℝ),0≤B' → 0≤A' → + (∀ᶠ t in l,SpinRadiusLE (z t) B' ∧ spinMass (z t)≤A') → + Tendsto (fun t => (r t)⁻¹*‖probeGain (r t) (w t) a K (spinCoe (z t))-spinCoe (z t)‖) l (𝓝 0)) ∧ + (∀ (i : κ) (e : α → ModeInfinity) (z : α → PreSpin ModeInfinity) (C B' A' : ℝ), + 0≤C → 0≤B' → 0≤A' → (∀ᶠ t in l,‖e t‖≤C) → + (∀ᶠ t in l,SpinRadiusLE (z t) B' ∧ spinMass (z t)≤A') → + Tendsto (fun t => -2*(⟪insertionInfinity (w t),e t⟫_ℂ).im) l (𝓝 (v i).1) → + Tendsto (fun t => -2*(⟪insertionYInfinity (w t),e t⟫_ℂ).im) l (𝓝 (v i).2) → + Tendsto (fun t => ‖probeGain (r t) (w t) a K (actualPacket ((r t)⁻¹) (e t) (z t))- + SpinOperators.act (R θ) (actualPacket ((r t)⁻¹) (e t) (z t))‖) l (𝓝 0)) := by + obtain ⟨hS,hscale⟩ := reciprocal_scale_eventually r hr hp + have hvac : ∀ᶠ t in l,ordinaryLocal (w t) (vacuum ModeInfinity)= + (∑ _ : Unit,actualPacket ((r t)⁻¹) 0 (x t))+s t+ρ t := by + simpa only [actualPacket,smul_zero,spinW_zero_apply,Fintype.sum_unique] using hψ + obtain ⟨K,a,T,hT,ha,h⟩ := selective_packet_accuracy r (fun t => (r t)⁻¹) w + (fun (_ : Unit) _ => 0) (fun _ => x) s ρ B A hB hA v hv θ hr hS hscale + (fun _ => hx) hvac hs hρ + have hzphase : ∀j (r t)⁻¹*|-2*(⟪actualDisplacement (r t) (w t) a j, + (r t)⁻¹ • (0:ModeInfinity)⟫_ℂ).im|) l (𝓝 0) := by + intro j hj + simpa only [standard_center_phase] using (tendsto_const_nhds : Tendsto (fun _ : α => (0:ℝ)) l (𝓝 0)) + obtain ⟨ho,hs⟩ := h (fun _ => hzphase) + refine ⟨K,a,?_,?_⟩ + · intro z B' A' hB' hA' hz + simpa only [actualPacket,smul_zero,spinW_zero_apply] using + ho (fun _ => 0) z B' A' hB' hA' hz hzphase + · intro i e z C B' A' hC hB' hA' he hz hZ hY + have hh := hs i e z C B' A' hC hB' hA' he hz hZ hY + apply hh.congr' + exact Eventually.of_forall (fun t => by + exact centered_rotation_error ((r t)⁻¹ • e t) (R θ) + (probeGain (r t) (w t) a K).toLinearEquiv.toLinearMap (spinCoe (z t))) + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace PointedTree +open CoherentFock RootSpin +local instance selectHugeRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance selectHugeRealSMul : SMul ℝ ModeInfinity := selectHugeRealModule.toDistribMulAction.toSMul + + + +theorem huge_selective_accuracy {α κ : Type*} [Fintype κ] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (t : ℝ) (ht : t≠0) + (d : κ → α → ModeInfinity) (xp xm : α → PreSpin ModeInfinity) + (xs : κ → α → PreSpin ModeInfinity) (ρ : α → SpinSpace ModeInfinity) + (B A : ℝ) (hB : 0≤B) (hA : 0≤A) (c y : κ → ℝ) (hc : ∀i,c i≠0) (θ : ℝ) + (hr : Tendsto r l (𝓝 0)) (hpos : ∀ᶠ q in l,0≤r q) + (hS : Tendsto S l atTop) (hscale : ∀ᶠ q in l,S q*r q=1) + (hxp : ∀ᶠ q in l,SpinRadiusLE (xp q) B ∧ spinMass (xp q)≤A) + (hxm : ∀ᶠ q in l,SpinRadiusLE (xm q) B ∧ spinMass (xm q)≤A) + (hxs : ∀i,∀ᶠ q in l,SpinRadiusLE (xs i q) B ∧ spinMass (xs i q)≤A) + (hvis : ∀i,Tendsto (fun q => (⟪insertionInfinity (w q),d i q⟫_ℂ).im) l (𝓝 (c i))) + (hψ : ∀ᶠ q in l,ordinaryLocal (w q) (vacuum ModeInfinity)= + actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q)+ + actualPacket (S q) (t • insertionInfinity (w q)) (xm q)+ + (∑i,actualPacket (S q) (d i q) (xs i q))+ρ q) + (hop : ∀ᶠ q in l,SpinOperators.act Z + (actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q))= + actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q)) + (hom : ∀ᶠ q in l,SpinOperators.act Z + (actualPacket (S q) (t • insertionInfinity (w q)) (xm q))= + -actualPacket (S q) (t • insertionInfinity (w q)) (xm q)) + (hρ : Tendsto (fun q => S q*‖ρ q‖) l (𝓝 0)) + (hs : Tendsto (fun q => S q*‖∑i,actualPacket (S q) (d i q) (xs i q)‖^2) l (𝓝 0)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + (∀ (b : ℝ) (z : α → PreSpin ModeInfinity) (B' A' : ℝ),0≤B' → 0≤A' → + (∀ᶠ q in l,SpinRadiusLE (z q) B' ∧ spinMass (z q)≤A') → + Tendsto (fun q => S q*‖probeGain (r q) (w q) a K + (actualPacket (S q) (b • insertionInfinity (w q)) (z q))- + actualPacket (S q) (b • insertionInfinity (w q)) (z q)‖) l (𝓝 0)) ∧ + (∀ (i : κ) (e : α → ModeInfinity) (z : α → PreSpin ModeInfinity) (C B' A' : ℝ), + 0≤C → 0≤B' → 0≤A' → (∀ᶠ q in l,‖e q‖≤C) → + (∀ᶠ q in l,SpinRadiusLE (z q) B' ∧ spinMass (z q)≤A') → + Tendsto (fun q => -2*(⟪insertionInfinity (w q),e q⟫_ℂ).im) l (𝓝 (-2*c i)) → + Tendsto (fun q => -2*(⟪insertionYInfinity (w q),e q⟫_ℂ).im) l (𝓝 (y i)) → + Tendsto (fun q => ‖probeGain (r q) (w q) a K (actualPacket (S q) (e q) (z q))- + SpinOperators.act (R θ) (actualPacket (S q) (e q) (z q))‖) l (𝓝 0)) := by + have hS1 : ∀ᶠ q in l,1≤S q := hS.eventually (eventually_ge_atTop 1) + have hscale' : ∀ᶠ q in l,0≤r q ∧ 0≤S q ∧ S q*r q=1 := by + filter_upwards [hpos,hS1,hscale] with q hq hsq he + exact ⟨hq,by linarith,he⟩ + have hρ0 := PacketGeometry.tendsto_of_scaled S (fun q => ‖ρ q‖) hS1 + (Eventually.of_forall (fun _ => norm_nonneg _)) hρ + have hs2 := PacketGeometry.tendsto_of_scaled S + (fun q => ‖∑i,actualPacket (S q) (d i q) (xs i q)‖^2) hS1 + (Eventually.of_forall (fun _ => sq_nonneg _)) hs + have hs0 : Tendsto (fun q => ‖∑i,actualPacket (S q) (d i q) (xs i q)‖) l (𝓝 0) := by + simpa only [Function.comp_def,Real.sqrt_sq (norm_nonneg _),Real.sqrt_zero] using + Real.continuous_sqrt.continuousAt.tendsto.comp hs2 + let ds : Fin 2 → α → ModeInfinity := fun i q => if i=0 then (-t) • insertionInfinity (w q) else t • insertionInfinity (w q) + let xo : Fin 2 → α → PreSpin ModeInfinity := fun i => if i=0 then xp else xm + have hxo : ∀i,∀ᶠ q in l,SpinRadiusLE (xo i q) B ∧ spinMass (xo i q)≤A := by + intro i + fin_cases i + · simpa [xo] using hxp + · simpa [xo] using hxm + have hψ' : ∀ᶠ q in l,ordinaryLocal (w q) (vacuum ModeInfinity)= + (∑i,actualPacket (S q) (ds i q) (xo i q))+ + (∑i,actualPacket (S q) (d i q) (xs i q))+ρ q := by + simpa [Fin.sum_univ_two,ds,xo] using hψ + have hv : ∀i,(-2*c i,y i)≠(0:ℝ×ℝ) := by + intro i hi + have hi' := congrArg Prod.fst hi + change -2*c i=0 at hi' + exact hc i ((mul_eq_zero.mp hi').resolve_left (by norm_num)) + obtain ⟨K,a,T,hT,ha,hacc⟩ := selective_packet_accuracy r S w ds xo + (fun q => ∑i,actualPacket (S q) (d i q) (xs i q)) ρ B A hB hA + (fun i => (-2*c i,y i)) hv θ hr hS1 hscale' hxo hψ' hs0 hρ0 + have hr1 : ∀ᶠ q in l,|r q|≤1 := by + filter_upwards [hpos,hr.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1))] with q hq hu + simpa only [abs_of_nonneg hq] using hu.le + have hph := huge_ordinary_scaled_phases r S w a K t ht d c xp xm xs ρ hS B A T hA hT ha hr1 + (hscale.mono (fun _ h => by rwa [mul_comm])) hxp hxm hxs hc hvis hψ hop hom hρ hs + have hph' : ∀i,∀j S q*|-2*(⟪actualDisplacement (r q) (w q) a j,S q • ds i q⟫_ℂ).im|) l (𝓝 0) := by + intro i j hj + fin_cases i + · simpa [ds] using hph j hj (-t) + · simpa [ds] using hph j hj t + obtain ⟨ho,hsp⟩ := hacc hph' + refine ⟨K,a,?_,?_⟩ + · intro b z B' A' hB' hA' hz + exact ho (fun q => b • insertionInfinity (w q)) z B' A' hB' hA' hz (fun j hj => hph j hj b) + · intro i e z C B' A' hC hB' hA' he hz hZ hY + have h := hsp i e z C B' A' hC hB' hA' he hz hZ hY + apply h.congr' + exact Eventually.of_forall (fun q => centered_rotation_error (S q • e q) (R θ) + (probeGain (r q) (w q) a K).toLinearEquiv.toLinearMap (spinCoe (z q))) + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace ForwardControl +variable {H α : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] {l : Filter α} + + + +theorem scaled_difference_transfer (V : α → H ≃ₗᵢ[ℂ] H) (F : H →L[ℂ] H) + (hF : ∀x,‖F x‖≤‖x‖) (S : α → ℝ) (x y : α → H) + (hS : ∀ᶠ t in l,0≤S t) + (hy : Tendsto (fun t => S t*‖V t (y t)-F (y t)‖) l (𝓝 0)) + (hxy : Tendsto (fun t => S t*‖x t-y t‖) l (𝓝 0)) : + Tendsto (fun t => S t*‖V t (x t)-F (x t)‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [zero_mul,add_zero] using hy.add (hxy.mul_const 2)) + · filter_upwards [hS] with t ht + exact mul_nonneg ht (norm_nonneg _) + · filter_upwards [hS] with t ht + have he : V t (x t)-F (x t)=(V t (y t)-F (y t))+V t (x t-y t)-F (x t-y t) := by + simp only [map_sub] + abel + have hn : ‖V t (x t)-F (x t)‖≤‖V t (y t)-F (y t)‖+2*‖x t-y t‖ := by + rw [he] + have h := (norm_sub_le (V t (y t)-F (y t)+V t (x t-y t)) (F (x t-y t))).trans + (add_le_add (norm_add_le (V t (y t)-F (y t)) (V t (x t-y t))) (hF _)) + rw [(V t).norm_map] at h + linarith + nlinarith + + +theorem scaled_map_difference (F : H →L[ℂ] H) (hF : ∀x,‖F x‖≤‖x‖) + (S : α → ℝ) (x y : α → H) (hS : ∀ᶠ t in l,0≤S t) + (hxy : Tendsto (fun t => S t*‖x t-y t‖) l (𝓝 0)) : + Tendsto (fun t => S t*‖F (x t)-F (y t)‖) l (𝓝 0) := by + apply squeeze_zero' _ _ hxy + · filter_upwards [hS] with t ht + exact mul_nonneg ht (norm_nonneg _) + · filter_upwards [hS] with t ht + rw [←map_sub] + exact mul_le_mul_of_nonneg_left (hF _) ht + + + +theorem scaled_amplitude_finSum {ι : Type*} [Fintype ι] + (V : α → H ≃ₗᵢ[ℂ] H) (F : H →L[ℂ] H) (hF : ∀x,‖F x‖≤‖x‖) + (r S : α → ℝ) (x : α → ι → H) + (hS : ∀ᶠ t in l,0≤S t) (hscale : ∀ᶠ t in l,0≤r t ∧ S t*r t=1) + (hx : ∀i,Tendsto (fun t => ‖V t (x t i)-F (x t i)‖) l (𝓝 0)) : + Tendsto (fun t => S t*‖V t (∑i,(r t:ℂ) • x t i)-F (∑i,(r t:ℂ) • x t i)‖) l (𝓝 0) := by + have h := scaled_difference_finSum_tendsto V F hF S (fun t i => (r t:ℂ) • x t i) + (fun _ => 0) hS (fun i => scaled_amplitude_error V F r S (fun t => x t i) hscale (hx i)) + (by simpa only [norm_zero,mul_zero] using (tendsto_const_nhds : Tendsto (fun _ : α => (0:ℝ)) l (𝓝 0))) + simpa only [add_zero] using h + + +theorem four_forward_transfer (V : α → H ≃ₗᵢ[ℂ] H) (F Z : H →L[ℂ] H) + (hF : ∀x,‖F x‖≤‖x‖) (hZ : ∀x,‖Z x‖≤‖x‖) + (S : α → ℝ) (o s y q : α → H) (hS : ∀ᶠ t in l,0≤S t) + (ho : Tendsto (fun t => S t*‖o t-y t‖) l (𝓝 0)) + (hs : Tendsto (fun t => S t*‖s t-q t‖) l (𝓝 0)) + (h1 : Tendsto (fun t => S t*‖V t (y t)-y t‖) l (𝓝 0)) + (h2 : Tendsto (fun t => S t*‖V t (q t)-F (q t)‖) l (𝓝 0)) + (h3 : Tendsto (fun t => S t*‖V t (Z (y t))-Z (y t)‖) l (𝓝 0)) + (h4 : Tendsto (fun t => S t*‖V t (Z (q t))-F (Z (q t))‖) l (𝓝 0)) : + Tendsto (fun t => S t*‖V t (o t)-o t‖) l (𝓝 0) ∧ + Tendsto (fun t => S t*‖V t (s t)-F (s t)‖) l (𝓝 0) ∧ + Tendsto (fun t => S t*‖V t (Z (o t))-Z (o t)‖) l (𝓝 0) ∧ + Tendsto (fun t => S t*‖V t (Z (s t))-F (Z (s t))‖) l (𝓝 0) := by + exact ⟨scaled_identity_transfer V S o y hS h1 ho, + scaled_difference_transfer V F hF S s q hS h2 hs, + scaled_identity_transfer V S (fun t => Z (o t)) (fun t => Z (y t)) hS h3 + (scaled_map_difference Z hZ S o y hS ho), + scaled_difference_transfer V F hF S (fun t => Z (s t)) (fun t => Z (q t)) hS h4 + (scaled_map_difference Z hZ S s q hS hs)⟩ + +end ForwardControl + +namespace CoherentFock +open RootSpin +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + + +theorem half_mixer_anticommutes (x : SpinSpace E) : + SpinOperators.act Z (SpinOperators.act (R (Real.pi/2)) x)= + -SpinOperators.act (R (Real.pi/2)) (SpinOperators.act Z x) := by + ext i + fin_cases i <;> + simp [SpinOperators.act_apply,Fin.sum_univ_two,RootSpin.R,RootSpin.Z,RootSpin.X, + Real.cos_pi_div_two,Real.sin_pi_div_two] + +end CoherentFock + +namespace PointedTree +open CoherentFock RootSpin + + + +theorem standard_four_forward_errors {α κ : Type*} [Fintype κ] {l : Filter α} + (r : α → ℝ) (w : α → List Gate) + (o s : α → SpinSpace ModeInfinity) (x : α → PreSpin ModeInfinity) + (d : κ → α → ModeInfinity) (z : κ → α → PreSpin ModeInfinity) + (B A C : ℝ) (hB : 0≤B) (hA : 0≤A) (hC : 0≤C) + (v : κ → ℝ×ℝ) (hv : ∀i,v i≠0) (θ : ℝ) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ t in l,0 ‖s t‖) l (𝓝 0)) + (ho : Tendsto (fun t => (r t)⁻¹*‖o t-spinCoe (x t)‖) l (𝓝 0)) + (hsp : Tendsto (fun t => (r t)⁻¹*‖s t- + (∑i,(r t:ℂ) • actualPacket ((r t)⁻¹) (d i t) (z i t))‖) l (𝓝 0)) + (hZ : ∀i,Tendsto (fun t => -2*(⟪insertionInfinity (w t),d i t⟫_ℂ).im) l (𝓝 (v i).1)) + (hY : ∀i,Tendsto (fun t => -2*(⟪insertionYInfinity (w t),d i t⟫_ℂ).im) l (𝓝 (v i).2)) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + Tendsto (fun t => (r t)⁻¹*‖probeGain (r t) (w t) a K (o t)-o t‖) l (𝓝 0) ∧ + Tendsto (fun t => (r t)⁻¹*‖probeGain (r t) (w t) a K (s t)-SpinOperators.act (R θ) (s t)‖) l (𝓝 0) ∧ + Tendsto (fun t => (r t)⁻¹*‖probeGain (r t) (w t) a K (SpinOperators.act Z (o t))- + SpinOperators.act Z (o t)‖) l (𝓝 0) ∧ + Tendsto (fun t => (r t)⁻¹*‖probeGain (r t) (w t) a K (SpinOperators.act Z (s t))- + SpinOperators.act (R θ) (SpinOperators.act Z (s t))‖) l (𝓝 0) := by + classical + obtain ⟨hS,hscale⟩ := reciprocal_scale_eventually r hr hp + have hS0 : ∀ᶠ t in l,0≤(r t)⁻¹ := hscale.mono (fun _ h => h.2.1) + have he0 := PacketGeometry.tendsto_of_scaled (fun t => (r t)⁻¹) + (fun t => ‖o t-spinCoe (x t)‖) hS (Eventually.of_forall (fun _ => norm_nonneg _)) ho + have hvac : ∀ᶠ t in l,ordinaryLocal (w t) (vacuum ModeInfinity)= + spinCoe (x t)+s t+(o t-spinCoe (x t)) := by + filter_upwards [hψ] with t ht + rw [ht] + abel + obtain ⟨K,a,ordinary,special⟩ := standard_selective_accuracy r w x s + (fun t => o t-spinCoe (x t)) B A hB hA v hv θ hr hp hx hvac hs he0 + let V (t : α) := probeGain (r t) (w t) a K + let F := SpinOperators.act (R θ) (H:=Space ModeInfinity) + have hF : ∀q,‖F q‖≤‖q‖ := fun q => (SpinOperators.norm_act (R_unitary _) q).le + have hZc : ∀q : SpinSpace ModeInfinity,‖SpinOperators.act Z q‖≤‖q‖ := + fun q => (SpinOperators.norm_act Z_unitary q).le + have hzZ : ∀i,∀ᶠ t in l,SpinRadiusLE (preRoot Z (z i t)) B ∧ spinMass (preRoot Z (z i t))≤2*A := by + intro i + filter_upwards [hz i] with t ht + exact ⟨ht.1.preRoot Z,(spinMass_preRoot Z _).trans (by rw [matrixMass_Z]; linarith [ht.2])⟩ + have hxZ : ∀ᶠ t in l,SpinRadiusLE (preRoot Z (x t)) B ∧ spinMass (preRoot Z (x t))≤2*A := by + filter_upwards [hx] with t ht + exact ⟨ht.1.preRoot Z,(spinMass_preRoot Z _).trans (by rw [matrixMass_Z]; linarith [ht.2])⟩ + have hsum := ForwardControl.scaled_amplitude_finSum V F hF r (fun t => (r t)⁻¹) + (fun t i => actualPacket ((r t)⁻¹) (d i t) (z i t)) hS0 + (hscale.mono (fun _ h => ⟨h.1,h.2.2⟩)) + (fun i => special i (d i) (z i) C B A hC hB hA (hd i) (hz i) (hZ i) (hY i)) + have hsumZ := ForwardControl.scaled_amplitude_finSum V F hF r (fun t => (r t)⁻¹) + (fun t i => actualPacket ((r t)⁻¹) (d i t) (preRoot Z (z i t))) hS0 + (hscale.mono (fun _ h => ⟨h.1,h.2.2⟩)) + (fun i => special i (d i) (fun t => preRoot Z (z i t)) C B (2*A) hC hB (by positivity) + (hd i) (hzZ i) (hZ i) (hY i)) + refine ⟨K,a,?_⟩ + apply ForwardControl.four_forward_transfer V F (SpinOperators.act Z) hF hZc + (fun t => (r t)⁻¹) o s (fun t => spinCoe (x t)) + (fun t => ∑i,(r t:ℂ) • actualPacket ((r t)⁻¹) (d i t) (z i t)) hS0 ho hsp + (ordinary x B A hB hA hx) hsum + · simpa only [spinCoe_preRoot] using ordinary (fun t => preRoot Z (x t)) B (2*A) hB (by positivity) hxZ + · simpa only [map_sum,map_smul,actualPacket_root] using hsumZ + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +@[simp] theorem spinCoe_smul (c : ℂ) (x : PreSpin E) : spinCoe (c • x)=c • spinCoe x := by + ext i + simp only [spinCoe_apply,Pi.smul_apply,UniformSpace.Completion.coe_smul,PiLp.smul_apply] + +omit [NormedAddCommGroup E] [InnerProductSpace ℂ E] in +@[simp] theorem spinMass_smul (c : ℂ) (x : PreSpin E) : spinMass (c • x)=‖c‖*spinMass x := by + simp only [spinMass,Pi.smul_apply,mass_smul,Finset.mul_sum] + +omit [InnerProductSpace ℂ E] in +theorem SpinRadiusLE.smul {x : PreSpin E} {B : ℝ} (hx : SpinRadiusLE x B) (c : ℂ) : + SpinRadiusLE (c • x) B := fun i => (hx i).smul c + +end CoherentFock + +namespace ForwardControl +variable {H α : Type*} [NormedAddCommGroup H] [NormedSpace ℂ H] {l : Filter α} + + +theorem scaled_identity_add (V : α → H ≃ₗᵢ[ℂ] H) (S : α → ℝ) (x y : α → H) + (hS : ∀ᶠ q in l,0≤S q) + (hx : Tendsto (fun q => S q*‖V q (x q)-x q‖) l (𝓝 0)) + (hy : Tendsto (fun q => S q*‖V q (y q)-y q‖) l (𝓝 0)) : + Tendsto (fun q => S q*‖V q (x q+y q)-(x q+y q)‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [add_zero] using hx.add hy) + · filter_upwards [hS] with q hq + exact mul_nonneg hq (norm_nonneg _) + · filter_upwards [hS] with q hq + have he : V q (x q+y q)-(x q+y q)=(V q (x q)-x q)+(V q (y q)-y q) := by + rw [map_add]; abel + rw [he,←mul_add] + exact mul_le_mul_of_nonneg_left (norm_add_le _ _) hq + +theorem scaled_identity_sub (V : α → H ≃ₗᵢ[ℂ] H) (S : α → ℝ) (x y : α → H) + (hS : ∀ᶠ q in l,0≤S q) + (hx : Tendsto (fun q => S q*‖V q (x q)-x q‖) l (𝓝 0)) + (hy : Tendsto (fun q => S q*‖V q (y q)-y q‖) l (𝓝 0)) : + Tendsto (fun q => S q*‖V q (x q-y q)-(x q-y q)‖) l (𝓝 0) := by + have hn : Tendsto (fun q => S q*‖V q (-y q)-(-y q)‖) l (𝓝 0) := by + simpa only [map_neg,neg_sub_neg,norm_sub_rev] using hy + simpa only [sub_eq_add_neg] using scaled_identity_add V S x (fun q => -y q) hS hx hn + + + +theorem scaled_square_small_amplitude (S r : α → ℝ) (x : α → H) (C : ℝ) (hC : 0≤C) + (hr : Tendsto r l (𝓝 0)) (hs : ∀ᶠ q in l,0≤S q ∧ 0≤r q ∧ S q*r q=1) + (hx : ∀ᶠ q in l,‖x q‖≤C) : + Tendsto (fun q => S q*‖(r q:ℂ) • x q‖^2) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa using hr.mul_const (C^2)) + · filter_upwards [hs] with q hq + exact mul_nonneg hq.1 (sq_nonneg _) + · filter_upwards [hs,hx] with q hq hb + simp only [norm_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hq.2.1] + calc + S q*(r q*‖x q‖)^2 = (S q*r q)*r q*‖x q‖^2 := by ring + _ = r q*‖x q‖^2 := by rw [hq.2.2,one_mul] + _ ≤ r q*C^2 := mul_le_mul_of_nonneg_left (sq_le_sq₀ (norm_nonneg _) hC |>.mpr hb) hq.2.1 + +end ForwardControl + +namespace PointedTree +open CoherentFock RootSpin +local instance hugeFlipRealModule : Module ℝ ModeInfinity := (inferInstance : NormedSpace ℝ ModeInfinity).toModule +local instance hugeFlipRealSMul : SMul ℝ ModeInfinity := hugeFlipRealModule.toDistribMulAction.toSMul + +@[simp] theorem actualPacket_smul (S : ℝ) (d : ModeInfinity) (c : ℂ) (x : PreSpin ModeInfinity) : + actualPacket S d (c • x)=c • actualPacket S d x := by + simp only [actualPacket,spinCoe_smul,map_smul] + +theorem norm_actualPacket_le_mass (S : ℝ) (d : ModeInfinity) (x : PreSpin ModeInfinity) : + ‖actualPacket S d x‖ ≤ spinMass x := by + simpa only [actualPacket,norm_spinW] using norm_spinCoe_le_mass x + + + +theorem huge_four_forward_errors {α κ : Type*} [Fintype κ] {l : Filter α} + (r S : α → ℝ) (w : α → List Gate) (t : ℝ) (ht : t≠0) + (o s : α → SpinSpace ModeInfinity) (xp xm : α → PreSpin ModeInfinity) + (d : κ → α → ModeInfinity) (z : κ → α → PreSpin ModeInfinity) + (B A C : ℝ) (hB : 0≤B) (hA : 0≤A) (hC : 0≤C) + (c y : κ → ℝ) (hc : ∀i,c i≠0) (θ : ℝ) + (hr : Tendsto r l (𝓝 0)) (hp : ∀ᶠ q in l,0≤r q) + (hS : Tendsto S l atTop) (hscale : ∀ᶠ q in l,S q*r q=1) + (hxp : ∀ᶠ q in l,SpinRadiusLE (xp q) B ∧ spinMass (xp q)≤A) + (hxm : ∀ᶠ q in l,SpinRadiusLE (xm q) B ∧ spinMass (xm q)≤A) + (hz : ∀i,∀ᶠ q in l,SpinRadiusLE (z i q) B ∧ spinMass (z i q)≤A) + (hd : ∀i,∀ᶠ q in l,‖d i q‖≤C) + (hψ : ∀ᶠ q in l,ordinaryLocal (w q) (vacuum ModeInfinity)=o q+s q) + (ho : Tendsto (fun q => S q*‖o q-(actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q)+ + actualPacket (S q) (t • insertionInfinity (w q)) (xm q))‖) l (𝓝 0)) + (hsp : Tendsto (fun q => S q*‖s q-(∑i,(r q:ℂ) • actualPacket (S q) (d i q) (z i q))‖) l (𝓝 0)) + (hop : ∀ᶠ q in l,SpinOperators.act Z (actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q))= + actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q)) + (hom : ∀ᶠ q in l,SpinOperators.act Z (actualPacket (S q) (t • insertionInfinity (w q)) (xm q))= + -actualPacket (S q) (t • insertionInfinity (w q)) (xm q)) + (hZ : ∀i,Tendsto (fun q => (⟪insertionInfinity (w q),d i q⟫_ℂ).im) l (𝓝 (c i))) + (hY : ∀i,Tendsto (fun q => -2*(⟪insertionYInfinity (w q),d i q⟫_ℂ).im) l (𝓝 (y i))) : + ∃ (K : ℕ) (a : ℕ → ShortPulse), + Tendsto (fun q => S q*‖probeGain (r q) (w q) a K (o q)-o q‖) l (𝓝 0) ∧ + Tendsto (fun q => S q*‖probeGain (r q) (w q) a K (s q)-SpinOperators.act (R θ) (s q)‖) l (𝓝 0) ∧ + Tendsto (fun q => S q*‖probeGain (r q) (w q) a K (SpinOperators.act Z (o q))- + SpinOperators.act Z (o q)‖) l (𝓝 0) ∧ + Tendsto (fun q => S q*‖probeGain (r q) (w q) a K (SpinOperators.act Z (s q))- + SpinOperators.act (R θ) (SpinOperators.act Z (s q))‖) l (𝓝 0) := by + classical + let op (q : α) := actualPacket (S q) ((-t) • insertionInfinity (w q)) (xp q) + let om (q : α) := actualPacket (S q) (t • insertionInfinity (w q)) (xm q) + let xs (i : κ) (q : α) := (r q:ℂ) • z i q + let sp (q : α) := ∑i,actualPacket (S q) (d i q) (xs i q) + let ρ (q : α) := (o q-(op q+om q))+(s q-sp q) + have hS0 : ∀ᶠ q in l,0≤S q := hS.eventually (eventually_ge_atTop 0) + have hscl : ∀ᶠ q in l,0≤S q ∧ 0≤r q ∧ S q*r q=1 := by + filter_upwards [hS0,hp,hscale] with q hq hpq he + exact ⟨hq,hpq,he⟩ + have hρ : Tendsto (fun q => S q*‖ρ q‖) l (𝓝 0) := by + apply squeeze_zero' _ _ (by simpa only [add_zero] using ho.add hsp) + · filter_upwards [hS0] with q hq + exact mul_nonneg hq (norm_nonneg _) + · filter_upwards [hS0] with q hq + simpa only [ρ,op,om,sp,xs,actualPacket_smul,mul_add] using + mul_le_mul_of_nonneg_left (norm_add_le (o q-(op q+om q)) (s q-sp q)) hq + have hxs : ∀i,∀ᶠ q in l,SpinRadiusLE (xs i q) B ∧ spinMass (xs i q)≤A := by + intro i + filter_upwards [hz i,hp,hr.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1))] with q hq hpq hu + refine ⟨hq.1.smul _,?_⟩ + simp only [xs,spinMass_smul,Complex.norm_real,Real.norm_eq_abs,abs_of_nonneg hpq] + exact (mul_le_mul_of_nonneg_left hq.2 hpq).trans (mul_le_of_le_one_left hA hu.le) + have hnorm : ∀ᶠ q in l,‖∑i,actualPacket (S q) (d i q) (z i q)‖≤Fintype.card κ*A := by + filter_upwards [eventually_all.mpr hz] with q hq + calc + _ ≤ ∑i,‖actualPacket (S q) (d i q) (z i q)‖ := norm_sum_le _ _ + _ ≤ ∑_i : κ,A := Finset.sum_le_sum (fun i _ => (norm_actualPacket_le_mass ..).trans (hq i).2) + _ = _ := by simp + have hssq := ForwardControl.scaled_square_small_amplitude S r + (fun q => ∑i,actualPacket (S q) (d i q) (z i q)) (Fintype.card κ*A) (by positivity) hr hscl hnorm + have hvac : ∀ᶠ q in l,ordinaryLocal (w q) (vacuum ModeInfinity)=op q+om q+sp q+ρ q := by + filter_upwards [hψ] with q hq + rw [hq] + dsimp only [ρ] + abel + obtain ⟨K,a,ordinary,special⟩ := huge_selective_accuracy r S w t ht d xp xm xs ρ B A hB hA c y hc θ + hr hp hS hscale hxp hxm hxs hZ hvac hop hom hρ + (by simpa only [xs,actualPacket_smul,←Finset.smul_sum] using hssq) + let V (q : α) := probeGain (r q) (w q) a K + let F := SpinOperators.act (R θ) (H:=Space ModeInfinity) + have hF : ∀q,‖F q‖≤‖q‖ := fun q => (SpinOperators.norm_act (R_unitary _) q).le + have hZc : ∀q : SpinSpace ModeInfinity,‖SpinOperators.act Z q‖≤‖q‖ := + fun q => (SpinOperators.norm_act Z_unitary q).le + have hzZ : ∀i,∀ᶠ q in l,SpinRadiusLE (preRoot Z (z i q)) B ∧ spinMass (preRoot Z (z i q))≤2*A := by + intro i + filter_upwards [hz i] with q hq + exact ⟨hq.1.preRoot Z,(spinMass_preRoot Z _).trans (by rw [matrixMass_Z]; linarith [hq.2])⟩ + have hsum := ForwardControl.scaled_amplitude_finSum V F hF r S + (fun q i => actualPacket (S q) (d i q) (z i q)) hS0 + (hscl.mono (fun _ h => ⟨h.2.1,h.2.2⟩)) + (fun i => special i (d i) (z i) C B A hC hB hA (hd i) (hz i) ((hZ i).const_mul (-2)) (hY i)) + have hsumZ := ForwardControl.scaled_amplitude_finSum V F hF r S + (fun q i => actualPacket (S q) (d i q) (preRoot Z (z i q))) hS0 + (hscl.mono (fun _ h => ⟨h.2.1,h.2.2⟩)) + (fun i => special i (d i) (fun q => preRoot Z (z i q)) C B (2*A) hC hB (by positivity) + (hd i) (hzZ i) ((hZ i).const_mul (-2)) (hY i)) + have hOrd := ForwardControl.scaled_identity_add V S op om hS0 + (ordinary (-t) xp B A hB hA hxp) (ordinary t xm B A hB hA hxm) + have hOrdZ : Tendsto (fun q => S q*‖V q (SpinOperators.act Z (op q+om q))- + SpinOperators.act Z (op q+om q)‖) l (𝓝 0) := by + apply (ForwardControl.scaled_identity_sub V S op om hS0 + (ordinary (-t) xp B A hB hA hxp) (ordinary t xm B A hB hA hxm)).congr' + filter_upwards [hop,hom] with q hpq hmq + change S q*‖V q (op q-om q)-(op q-om q)‖=_ + rw [map_add,hpq,hmq,←sub_eq_add_neg] + refine ⟨K,a,?_⟩ + apply ForwardControl.four_forward_transfer V F (SpinOperators.act Z) hF hZc S o s + (fun q => op q+om q) (fun q => ∑i,(r q:ℂ) • actualPacket (S q) (d i q) (z i q)) + hS0 ho hsp hOrd hsum hOrdZ + simpa only [map_sum,map_smul,actualPacket_root] using hsumZ + +end PointedTree + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace CoherentFock +variable {E α : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] {l : Filter α} + + + +def BoundedPacket (l : Filter α) (x : α → SpinSpace E) : Prop := + ∃ (p : α → PreSpin E) (B A : ℝ), 0≤B ∧ 0≤A ∧ + (∀q,x q=spinCoe (p q)) ∧ + (∀ᶠ q in l,SpinRadiusLE (p q) B ∧ spinMass (p q)≤A) + +namespace BoundedPacket + +theorem norm_bounded {x : α → SpinSpace E} (hx : BoundedPacket l x) : + ∃C : ℝ,0≤C ∧ ∀ᶠ q in l,‖x q‖≤C := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + refine ⟨A,hA,?_⟩ + filter_upwards [hbound] with q hq + rw [hp q] + exact (norm_spinCoe_le_mass _).trans hq.2 + +theorem vacuum : BoundedPacket l (fun _ : α => PointedTree.vacuum E) := by + refine ⟨fun _ => SeedInitialization.preVacuum E,0,2*‖PointedTree.spinCoefficient‖, + le_rfl,by positivity,fun _ => SeedInitialization.spinCoe_preVacuum.symm,?_⟩ + exact Eventually.of_forall fun _ => ⟨SeedInitialization.radius_preVacuum, + SeedInitialization.spinMass_preVacuum.le⟩ + +theorem root {x : α → SpinSpace E} (hx : BoundedPacket l x) + (P : Matrix (Fin 2) (Fin 2) ℂ) : + BoundedPacket l (fun q => SpinOperators.act P (x q)) := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + refine ⟨fun q => preRoot P (p q),B,matrixMass P*A,hB, + mul_nonneg (matrixMass_nonneg _) hA,?_,?_⟩ + · exact fun q => by simp only [spinCoe_preRoot,hp] + · filter_upwards [hbound] with q hq + exact ⟨hq.1.preRoot P,(spinMass_preRoot _ _).trans + (mul_le_mul_of_nonneg_left hq.2 (matrixMass_nonneg _))⟩ + +theorem pulse {x : α → SpinSpace E} (hx : BoundedPacket l x) + (d : α → E) (C : ℝ) (hC : 0≤C) (hd : ∀ᶠ q in l,‖d q‖≤C) : + BoundedPacket l (fun q => WZ (d q) (x q)) := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + refine ⟨fun q => preWZ (d q) (p q),C+B,A,add_nonneg hC hB,hA,?_,?_⟩ + · exact fun q => by simp only [spinCoe_preWZ,hp] + · filter_upwards [hbound,hd] with q hq hdq + exact ⟨fun i => (hq.1.preWZ (d q) i).mono (by linarith), + (spinMass_preWZ _ _).trans hq.2⟩ + +theorem smul {x : α → SpinSpace E} (hx : BoundedPacket l x) + (c : α → ℂ) (C : ℝ) (hC : 0≤C) (hc : ∀ᶠ q in l,‖c q‖≤C) : + BoundedPacket l (fun q => c q • x q) := by + obtain ⟨p,B,A,hB,hA,hp,hbound⟩ := hx + refine ⟨fun q => c q • p q,B,C*A,hB,mul_nonneg hC hA,?_,?_⟩ + · exact fun q => by simp only [spinCoe_smul,hp] + · filter_upwards [hbound,hc] with q hq hcq + refine ⟨hq.1.smul _,?_⟩ + rw [spinMass_smul] + exact mul_le_mul hcq hq.2 (spinMass_nonneg _) hC + +end BoundedPacket + + + +structure PacketUnitaryFamily (l : Filter α) where + op : α → SpinSpace E ≃ₗᵢ[ℂ] SpinSpace E + forward : ∀x,BoundedPacket l x → BoundedPacket l (fun q => op q (x q)) + backward : ∀x,BoundedPacket l x → BoundedPacket l (fun q => (op q).symm (x q)) + +namespace PacketUnitaryFamily + +def ident : PacketUnitaryFamily (E:=E) l where + op _ := LinearIsometryEquiv.refl ℂ _ + forward _ hx := hx + backward _ hx := hx + +def root (P : Matrix (Fin 2) (Fin 2) ℂ) (hP : P ∈ unitary _) : PacketUnitaryFamily (E:=E) l where + op _ := SpinOperators.actEquiv P hP + forward _ hx := hx.root P + backward _ hx := by simpa only [SpinOperators.actEquiv_symm_apply] using hx.root P.conjTranspose + +def pulse (d : α → E) (C : ℝ) (hC : 0≤C) (hd : ∀ᶠ q in l,‖d q‖≤C) : + PacketUnitaryFamily (E:=E) l where + op q := costEquiv (d q) + forward _ hx := hx.pulse d C hC hd + backward _ hx := by + simpa only [costEquiv_symm_apply] using hx.pulse (fun q => -d q) C hC + (hd.mono (fun q hq => by simpa only [norm_neg] using hq)) + +def trans (A B : PacketUnitaryFamily (E:=E) l) : PacketUnitaryFamily (E:=E) l where + op q := (A.op q).trans (B.op q) + forward x hx := B.forward _ (A.forward x hx) + backward x hx := A.backward _ (B.backward x hx) + +def symm (A : PacketUnitaryFamily (E:=E) l) : PacketUnitaryFamily (E:=E) l where + op q := (A.op q).symm + forward := A.backward + backward := A.forward + + + +theorem insertion_bounded (A : PacketUnitaryFamily (E:=E) l) + (P : Matrix (Fin 2) (Fin 2) ℂ) : + BoundedPacket l (fun q => (A.op q).symm (SpinOperators.act P (A.op q (PointedTree.vacuum E)))) := + A.backward _ ((A.forward _ BoundedPacket.vacuum).root P) + +end PacketUnitaryFamily +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Splice.lean b/lean/OAI/Probability/ParisiFinite/Splice.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e12225866914f500163db0ec9283ff6b3cdaecd --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Splice.lean @@ -0,0 +1,626 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ContinuousTiltedMeanJoint +import OAI.Probability.ParisiFinite.Nnwidth +import OAI.Probability.ParisiFinite.TimeCubicTest + +namespace OAI + +/-! Splice. -/ + +noncomputable section + +open MeasureTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +open ContinuousLinearMap +open scoped Convolution +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath +namespace TimeQuadraticTest + +def splice (c : ℝ) (f g : ℝ → ℝ → ℝ) (t x : ℝ) : ℝ := if t f.dt t x) volume u v := by + apply (intervalIntegrable_const (c := (f.ct:ℝ))).mono_fun' + ((f.measT.comp (measurable_id.prodMk measurable_const)).aestronglyMeasurable) + exact ae_of_all _ fun t => f.boundT t x + +lemma measurable_splice {f g : ℝ → ℝ → ℝ} (c : ℝ) + (hf : Measurable (uncurry f)) (hg : Measurable (uncurry g)) : + Measurable (uncurry (splice c f g)) := + Measurable.ite (measurableSet_lt measurable_fst measurable_const) hf hg + +lemma bound_splice {f g : ℝ → ℝ → ℝ} {C D : ℝ≥0} (c : ℝ) + (hf : ∀ t x,‖f t x‖≤C) (hg : ∀ t x,‖g t x‖≤D) (t x : ℝ) : + ‖splice c f g t x‖≤ max C D := by + unfold splice + split_ifs + · exact (hf t x).trans (by exact_mod_cast le_max_left C D) + · exact (hg t x).trans (by exact_mod_cast le_max_right C D) + +lemma integrable_splice_dt (f g : TimeQuadraticTest) (c u v x : ℝ) : + IntervalIntegrable (fun t => splice c f.dt g.dt t x) volume u v := by + apply (intervalIntegrable_const (c := (max f.ct g.ct:ℝ))).mono_fun' + (((measurable_splice c f.measT g.measT).comp + (measurable_id.prodMk measurable_const)).aestronglyMeasurable) + exact ae_of_all _ fun t => bound_splice c f.boundT g.boundT t x + +lemma continuousAt_splice {f g : ℝ → ℝ → ℝ} {c t x : ℝ} (ht : t≠c) + (hf : ContinuousAt (uncurry f) (t,x)) (hg : ContinuousAt (uncurry g) (t,x)) : + ContinuousAt (uncurry (splice c f g)) (t,x) := by + rcases lt_or_gt_of_ne ht with ht|ht + · apply hf.congr_of_eventuallyEq + filter_upwards [continuousAt_fst.preimage_mem_nhds (Iio_mem_nhds ht)] with p hp + exact ite_eq_left hp + · apply hg.congr_of_eventuallyEq + filter_upwards [continuousAt_fst.preimage_mem_nhds (Ioi_mem_nhds ht)] with p hp + exact ite_eq_right (not_lt.mpr hp.le) + +lemma splice_integralT (f g : TimeQuadraticTest) {c : ℝ} (hc : c∈Icc (0:ℝ) 1) + (hfg : ∀ x,f.val c x=g.val c x) {u v : ℝ} + (hu : u∈Icc (0:ℝ) 1) (hv : v∈Icc (0:ℝ) 1) (x : ℝ) : + splice c f.val g.val v x-splice c f.val g.val u x= + ∫ t in u..v,splice c f.dt g.dt t x := by + have hleft (t : ℝ) (ht : t≤c) : splice c f.val g.val t x=f.val t x := by + rcases lt_or_eq_of_le ht with ht|rfl + · exact ite_eq_left ht + · simpa [splice] using (hfg x).symm + have hright (t : ℝ) (ht : c≤t) : splice c f.val g.val t x=g.val t x := + ite_eq_right (not_lt.mpr ht) + have hbefore {a b : ℝ} (ha : a∈Icc (0:ℝ) 1) (hb : b∈Icc (0:ℝ) 1) + (hab : a≤b) (hbc : b≤c) : + splice c f.val g.val b x-splice c f.val g.val a x= + ∫ t in a..b,splice c f.dt g.dt t x := by + rw [hleft b hbc,hleft a (hab.trans hbc),f.integralT a ha b hb] + apply intervalIntegral.integral_congr_Ioo_of_le hab + intro t ht + exact (ite_eq_left (ht.2.trans_le hbc)).symm + have hafter {a b : ℝ} (ha : a∈Icc (0:ℝ) 1) (hb : b∈Icc (0:ℝ) 1) + (hab : a≤b) (hca : c≤a) : + splice c f.val g.val b x-splice c f.val g.val a x= + ∫ t in a..b,splice c f.dt g.dt t x := by + rw [hright b (hca.trans hab),hright a hca,g.integralT a ha b hb] + apply intervalIntegral.integral_congr_Ioo_of_le hab + intro t ht + exact (ite_eq_right (not_lt.mpr (hca.trans ht.1.le))).symm + have hle {a b : ℝ} (ha : a∈Icc (0:ℝ) 1) (hb : b∈Icc (0:ℝ) 1) (hab : a≤b) : + splice c f.val g.val b x-splice c f.val g.val a x= + ∫ t in a..b,splice c f.dt g.dt t x := by + by_cases hbc : b≤c + · exact hbefore ha hb hab hbc + by_cases hca : c≤a + · exact hafter ha hb hab hca + rw [←intervalIntegral.integral_add_adjacent_intervals + (integrable_splice_dt f g c a c x) (integrable_splice_dt f g c c b x), + ←hbefore ha hc (le_of_not_ge hca) le_rfl, + ←hafter hc hb (le_of_not_ge hbc) le_rfl] + ring + rcases le_total u v with huv|hvu + · exact hle hu hv huv + · rw [intervalIntegral.integral_symm,←hle hv hu hvu] + ring + + + +def glue (f g : TimeQuadraticTest) (c : ℝ) (hc : c∈Icc (0:ℝ) 1) + (hfg : ∀ x,f.val c x=g.val c x) : TimeQuadraticTest where + val := splice c f.val g.val + d1 := splice c f.d1 g.d1 + d2 := splice c f.d2 g.d2 + dt := splice c f.dt g.dt + hasD1 := by intro t x; unfold splice; split_ifs; exact f.hasD1 t x; exact g.hasD1 t x + hasD2 := by intro t x; unfold splice; split_ifs; exact f.hasD2 t x; exact g.hasD2 t x + continuousD2 := by intro t; unfold splice; split_ifs; exact f.continuousD2 t; exact g.continuousD2 t + c1 := max f.c1 g.c1 + c2 := max f.c2 g.c2 + ct := max f.ct g.ct + bound1 := bound_splice c f.bound1 g.bound1 + bound2 := bound_splice c f.bound2 g.bound2 + boundT := bound_splice c f.boundT g.boundT + measT := measurable_splice c f.measT g.measT + continuousT := by intro t; unfold splice; split_ifs; exact f.continuousT t; exact g.continuousT t + jointD1 := by + filter_upwards [f.jointD1,g.jointD1,volume.ae_ne c] with t hf hg ht hmem x + exact continuousAt_splice ht (hf hmem x) (hg hmem x) + jointD2 := by + filter_upwards [f.jointD2,g.jointD2,volume.ae_ne c] with t hf hg ht hmem x + exact continuousAt_splice ht (hf hmem x) (hg hmem x) + integralT := fun _ hu _ hv x => splice_integralT f g hc hfg hu hv x + +end TimeQuadraticTest +end ParisiPath + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath + + +def SmoothField.staticTimeTest (f : SmoothField) : TimeQuadraticTest where + val := fun _ => f.val + d1 := fun _ => f.d1 + d2 := fun _ => f.d2 + dt := fun _ _ => 0 + hasD1 := fun _ => f.hasD1 + hasD2 := fun _ => f.hasD2 + continuousD2 := fun _ => f.continuousD2 + c1 := f.bound1 + c2 := f.bound2 + ct := 0 + bound1 := fun _ x => by simpa only [Real.norm_eq_abs] using f.normD1 x + bound2 := fun _ x => by simpa only [Real.norm_eq_abs] using f.normD2 x + boundT := by intros; simp + measT := measurable_const + continuousT := fun _ => continuous_const + jointD1 := ae_of_all _ fun _ _ _ => (f.continuousD1.comp continuous_snd).continuousAt + jointD2 := ae_of_all _ fun _ _ _ => (f.continuousD2.comp continuous_snd).continuousAt + integralT := by intros; simp + + +def SmoothField.slabTimeTest (f : SmoothField) (a b : ℝ) : TimeQuadraticTest where + val := fun t => (fieldOnInterval f a b t).val + d1 := fun t => (fieldOnInterval f a b t).d1 + d2 := fun t => (fieldOnInterval f a b t).d2 + dt := fieldOnInterval_dt f a b + hasD1 := fun t => (fieldOnInterval f a b t).hasD1 + hasD2 := fun t => (fieldOnInterval f a b t).hasD2 + continuousD2 := fun t => (fieldOnInterval f a b t).continuousD2 + c1 := f.bound1 + c2 := f.bound2+2*Real.nnabs a*f.bound1^2 + ct := fieldOnInterval_timeBound f a + bound1 := fun t x => by simpa only [Real.norm_eq_abs,fieldOnInterval,SmoothField.transform] using (fieldOnInterval f a b t).normD1 x + bound2 := fun t x => by simpa only [Real.norm_eq_abs,fieldOnInterval,SmoothField.transform] using (fieldOnInterval f a b t).normD2 x + boundT := fieldOnInterval_dt_bound f a b + measT := measurable_fieldOnInterval_dt f a b + continuousT := continuous_fieldOnInterval_dt f a b + jointD1 := ae_of_all _ fun _ _ _ => (continuous_fieldOnInterval_d1 f a b).continuousAt + jointD2 := ae_of_all _ fun _ _ _ => (continuous_fieldOnInterval_d2 f a b).continuousAt + integralT := fun u _ v _ x => (fieldOnInterval_integral_time f a b u v x).symm + + + +def finiteTimeField (β : ℝ≥0) (hβ : 0<β) : Schedule → ℝ → ℝ → SmoothField + | [],_,_ => terminalField β hβ + | (a,d)::ls,s,t => if t 0 + | (a,d)::ls,s,t,x => if t 0 + | (a,d)::ls,s,t => if t rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + by_cases hd : d=0 + · simp only [hd,NNReal.coe_zero,add_zero,finiteTimeField,lt_self_iff_false,ite_false, + ih,recursion,Real.sqrt_zero,step_zero_width] + · have hp : (0:ℝ) rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + rw [width_cons] at ht + rw [finiteTimeField,ite_eq_right (by linarith [schedule_width_nonneg ls] : ¬ t exact terminal_hasParisiCurvature β hβ + | cons l ls ih => + have htail : ∀ k∈ls,k.1≤β := fun k hk => ha k (List.mem_cons_of_mem _ hk) + simp only [finiteTimeField] + split_ifs + · exact transform_hasParisiCurvature (smoothRecursion_hasParisiCurvature β hβ ls htail) + l.1.coe_nonneg (by exact_mod_cast ha l List.mem_cons_self) _ + · exact ih htail _ + +lemma finiteTimeField_PDE (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (s t x : ℝ) + (hs : s≤t) (ht : t + simp only [width,List.map_nil,List.sum_nil,add_zero] at ht + exact False.elim (not_lt_of_ge hs ht) + | cons l ls ih => + rcases l with ⟨a,d⟩ + simp only [finiteTimeDerivative,finiteTimeField,finiteTimeCoefficient] + split_ifs with hcut + · exact ite_eq_left hcut + · apply ih (s+d) (le_of_not_gt hcut) + rw [width_cons] at ht + linarith + + + +structure ScheduleTimeRealization (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (s : ℝ) where + test : TimeQuadraticTest + val_eq : ∀ t x,test.val t x=(finiteTimeField β hβ ls s t).val x + d1_eq : ∀ t x,test.d1 t x=(finiteTimeField β hβ ls s t).d1 x + d2_eq : ∀ t x,test.d2 t x=(finiteTimeField β hβ ls s t).d2 x + dt_eq : ∀ t x,test.dt t x=finiteTimeDerivative β hβ ls s t x + + + +def scheduleTimeRealization (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (s : ℝ) (hs : 0 ≤ s) (he : s + width ls ≤ 1) : ScheduleTimeRealization β hβ ls s := by + induction ls generalizing s with + | nil => + exact ⟨(terminalField β hβ).staticTimeTest,fun _ _ => rfl, + fun _ _ => rfl,fun _ _ => rfl,fun _ _ => rfl⟩ + | cons l ls ih => + rcases l with ⟨a,d⟩ + let c : ℝ := s+d + have hc0 : 0≤c := add_nonneg hs d.coe_nonneg + have hend : c+width ls≤1 := by + dsimp only [c] + rw [width_cons] at he + linarith + have hc1 : c≤1 := by linarith [schedule_width_nonneg ls] + let tail := ih c hc0 hend + let slab := (smoothRecursion β hβ ls).slabTimeTest a c + have hmatch (x : ℝ) : slab.val c x=tail.test.val c x := by + change (fieldOnInterval (smoothRecursion β hβ ls) a c c).val x=tail.test.val c x + rw [fieldOnInterval_right,tail.val_eq,finiteTimeField_start,smoothRecursion_val] + refine ⟨slab.glue tail.test c ⟨hc0,hc1⟩ hmatch,?_,?_,?_,?_⟩ + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeField, + SmoothField.slabTimeTest,slab,c] + split_ifs + · rfl + · exact tail.val_eq t x + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeField, + SmoothField.slabTimeTest,slab,c] + split_ifs + · rfl + · exact tail.d1_eq t x + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeField, + SmoothField.slabTimeTest,slab,c] + split_ifs + · rfl + · exact tail.d2_eq t x + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeDerivative, + SmoothField.slabTimeTest,slab,c] + split_ifs + · rfl + · exact tail.dt_eq t x + +lemma finiteTimeCoefficient_measurable (ls : Schedule) (s : ℝ) : + Measurable (finiteTimeCoefficient ls s) := by + induction ls generalizing s with + | nil => exact measurable_const + | cons l ls ih => + exact Measurable.ite (measurableSet_lt measurable_id measurable_const) + measurable_const (ih _) + +lemma finiteTimeCoefficient_bound (β : ℝ≥0) (ls : Schedule) + (ha : ∀ l∈ls,l.1≤β) (s t : ℝ) : |finiteTimeCoefficient ls s t|≤β := by + induction ls generalizing s with + | nil => simpa only [finiteTimeCoefficient,abs_zero] using β.coe_nonneg + | cons l ls ih => + simp only [finiteTimeCoefficient] + split_ifs + · rw [abs_of_nonneg l.1.coe_nonneg] + exact_mod_cast ha l List.mem_cons_self + · exact ih (fun k hk => ha k (List.mem_cons_of_mem _ hk)) _ + +lemma finiteTimeField_measurable_d1 (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (s : ℝ) : + Measurable (fun p : ℝ×ℝ => (finiteTimeField β hβ ls s p.1).d1 p.2) := by + classical + induction ls generalizing s with + | nil => exact (terminalField β hβ).continuousD1.measurable.comp measurable_snd + | cons l ls ih => + have hh : Measurable (fun p : ℝ × ℝ => if p.1 < s + l.2 then + (fieldOnInterval (smoothRecursion β hβ ls) l.1 (s+l.2) p.1).d1 p.2 + else (finiteTimeField β hβ ls (s+l.2) p.1).d1 p.2) := + Measurable.ite (measurableSet_lt measurable_fst measurable_const) + (continuous_fieldOnInterval_d1 (smoothRecursion β hβ ls) l.1 (s+l.2)).measurable (ih _) + convert! hh using 1 + funext p + simp only [finiteTimeField] + split_ifs <;> rfl + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +def scheduleSuffix : Schedule → ℝ≥0 → Schedule + | [],_ => [] + | (a,d)::ls,r => if r simp [scheduleSuffix] + | cons l ls ih => + simp only [scheduleSuffix] + split_ifs + · intro k hk + rcases List.mem_cons.mp hk with rfl|hk + · exact ha l List.mem_cons_self + · exact ha k (List.mem_cons_of_mem _ hk) + · exact ih (fun k hk => ha k (List.mem_cons_of_mem _ hk)) _ + +lemma nnwidth_scheduleSuffix (ls : Schedule) (r : ℝ≥0) : + nnwidth (scheduleSuffix ls r) = nnwidth ls-r := by + induction ls generalizing r with + | nil => simp [scheduleSuffix,nnwidth] + | cons l ls ih => + rcases l with ⟨a,d⟩ + simp only [scheduleSuffix,nnwidth] + split_ifs with hrd + · simp only [nnwidth] + exact tsub_add_eq_add_tsub hrd.le + · rw [ih] + have hdr : d ≤ r := le_of_not_gt hrd + symm + calc d+nnwidth ls-r = d+nnwidth ls-(d+(r-d)) := by rw [add_tsub_cancel_of_le hdr] + _ = nnwidth ls-(r-d) := add_tsub_add_eq_tsub_left _ _ _ + +lemma scheduleValue_suffix (ls : Schedule) (r u : ℝ≥0) : + scheduleValue (scheduleSuffix ls r) u = scheduleValue ls (r+u) := by + induction ls generalizing r with + | nil => rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + rw [scheduleSuffix] + split_ifs with hrd + · exact (scheduleValue_split_shift a r d hrd.le ls u).symm + · have hru : ¬ r+u rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + rw [scheduleSuffix] + split_ifs with hrd + · have he : r+(d-r)=d := add_tsub_cancel_of_le hrd.le + have hc : r+u rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + by_cases hd : d=0 + · simp [scheduleSuffix,hd,ih] + · simp only [scheduleSuffix,pos_iff_ne_zero.mpr hd,ite_eq_left,tsub_zero] + +lemma scheduleSuffix_append (ls rs : Schedule) (r : ℝ≥0) (hr : r simp [nnwidth] at hr + | cons l ls ih => + simp only [List.cons_append,scheduleSuffix] + split_ifs with hrd + · rfl + · apply ih + exact (tsub_lt_iff_left (le_of_not_gt hrd)).mpr hr + +lemma finiteTimeField_suffix_val (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (s : ℝ) (r : ℝ≥0) (x : ℝ) : + (finiteTimeField β hβ ls s (s+r)).val x = recursion β (scheduleSuffix ls r) x := by + induction ls generalizing s r with + | nil => rfl + | cons l ls ih => + rcases l with ⟨a,d⟩ + have hc : s+(r:ℝ) simp only [scheduleSuffix,sub_self]; exact ⟨le_rfl,by positivity⟩ + | cons l ls ih => + rcases l with ⟨a,d⟩ + have ha0 : (a:ℝ) ≤ β := by exact_mod_cast ha (a,d) List.mem_cons_self + have ht : ∀ l∈ls,l.1 ≤ β := fun l hl => ha l (List.mem_cons_of_mem _ hl) + have hh := smoothRecursion_hasParisiCurvature β hβ ls ht + rw [scheduleSuffix] + split_ifs with hrd + · let f := (smoothRecursion β hβ ls).transform a (Real.sqrt (d-r:ℝ≥0)) + have hf := transform_hasParisiCurvature hh a.coe_nonneg ha0 (Real.sqrt (d-r:ℝ≥0)) + have hb := step_curvature_time_bound hf a.coe_nonneg ha0 (Real.sqrt r) (Real.sqrt_nonneg _) x + rw [Real.sq_sqrt r.coe_nonneg] at hb + have he : step a (Real.sqrt r) f.val x=recursion β ((a,d)::ls) x := by + change step a (Real.sqrt r) (step a (Real.sqrt (d-r:ℝ≥0)) (smoothRecursion β hβ ls).val) x=_ + rw [step_semigroup (smoothRecursion β hβ ls).lipschitz, + Real.sq_sqrt r.coe_nonneg,Real.sq_sqrt (d-r).coe_nonneg, + ←NNReal.coe_add,add_tsub_cancel_of_le hrd.le,smoothRecursion_val] + rfl + rw [he] at hb + simpa only [SmoothField.transform,smoothRecursion_val,recursion] using hb + · have hb := step_curvature_time_bound hh a.coe_nonneg ha0 (Real.sqrt d) (Real.sqrt_nonneg _) x + rw [Real.sq_sqrt d.coe_nonneg,smoothRecursion_val] at hb + have hi := ih ht (r-d) + rw [NNReal.coe_sub (le_of_not_gt hrd)] at hi + simp only [recursion] + constructor <;> nlinarith [hb.1,hb.2,hi.1,hi.2] + +lemma shifted_schedule_suffix_error (β : ℝ≥0) (hβ : 0<β) (a b d : ℝ≥0) + (ha : a ≤ β) (hb : b ≤ β) (mid : Schedule) (hm : ∀ l∈mid,l.1 ≤ β) + (r : ℝ≥0) (hr : r ?_) + have ht := step_curvature_time_bound (terminal_hasParisiCurvature β hβ) + b.coe_nonneg (by exact_mod_cast hb) (Real.sqrt d) (Real.sqrt_nonneg _) y + rw [Real.sq_sqrt d.coe_nonneg] at ht + change 0 ≤ step b (Real.sqrt d) (terminal (β:ℝ)) y-terminal (β:ℝ) y ∧ + step b (Real.sqrt d) (terminal (β:ℝ)) y-terminal (β:ℝ) y ≤ (β:ℝ)*d/2 at ht + exact abs_le.mpr ⟨(neg_nonpos.mpr (by positivity)).trans ht.1,ht.2⟩ + have hright : 0 ≤ recursion β (scheduleSuffix full r) x-recursion β (scheduleSuffix high r) x ∧ + recursion β (scheduleSuffix full r) x-recursion β (scheduleSuffix high r) x ≤ (β:ℝ)*d/2 := by + rw [hfull,scheduleSuffix] + split_ifs with hrd + · have ht := step_curvature_time_bound (smoothRecursion_hasParisiCurvature β hβ high hhi) + a.coe_nonneg (by exact_mod_cast ha) (Real.sqrt (d-r:ℝ≥0)) (Real.sqrt_nonneg _) x + rw [Real.sq_sqrt (d-r).coe_nonneg,NNReal.coe_sub hrd.le,smoothRecursion_val] at ht + have hh := recursion_suffix_time_bound β hβ high hhi r x + simp only [recursion,NNReal.coe_sub hrd.le] + constructor <;> nlinarith [ht.1,ht.2,hh.1,hh.2] + · have hh := recursion_suffix_time_bound β hβ (scheduleSuffix high (r-d)) + (scheduleSuffix_coeff_bound high hhi (r-d)) d x + rw [scheduleSuffix_add,tsub_add_cancel_of_le (le_of_not_gt hrd)] at hh + exact hh + calc + _ ≤ |recursion β (scheduleSuffix low r) x-recursion β (scheduleSuffix full r) x|+ + |recursion β (scheduleSuffix full r) x-recursion β (scheduleSuffix high r) x| := + abs_sub_le _ _ _ + _ ≤ (β:ℝ)*d/2+(β:ℝ)*d/2 := add_le_add + (by simpa only [abs_sub_comm] using hleft) + (abs_le.mpr ⟨by linarith [hright.1],hright.2⟩) + _ = _ := by ring + +lemma dyadic_suffix_grid_error (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hb : ∀ t,γ t ≤ β) (t d : ℝ≥0) (n : ℕ) (r : ℝ≥0) (hr : r exact (hn rfl).elim + | cons c mid => + simp only [List.cons_append,List.cons.injEq] at hs + rw [hs.1] at hw hc ⊢ + rw [←hs.2] + apply shifted_schedule_suffix_error β hβ _ _ _ (hb t) (hb (t+d)) mid + (fun l hl => hc l (List.mem_cons_of_mem _ hl)) r (by rwa [hw]) + +lemma dyadic_suffix_value_bounds {f : ℝ → ℝ} (hf : LipschitzWith 1 f) + {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) {β : ℝ} (hb : ∀ t,(γ t:ℝ) ≤ β) + (t d : ℝ≥0) (n : ℕ) (r : ℝ≥0) (hr : r evolve_le_of_scheduleValue_le hf _ _ + (by rw [hw,dyadicSchedule_nnwidth]) (fun u hu => by + rw [scheduleValue_suffix] + have hur : r+u evolve_le_of_scheduleValue_le hf _ _ + (by rw [hw,dyadicSchedule_nnwidth]) (fun u hu => by + rw [scheduleValue_suffix] + have hu' : u by exact_mod_cast hb t) t d n r hr x + rw [←recursion_eq_evolve,←recursion_eq_evolve] at hb' + have he := abs_le.mp (dyadic_suffix_grid_error β hβ hb t d n r hr x) + apply abs_le.mpr + constructor + · exact he.1.trans (sub_le_sub_left hb'.2 _) + · exact (sub_nonpos.mpr hb'.1).trans (mul_nonneg β.coe_nonneg (dyadicMesh d n).coe_nonneg) + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SquareKernel.lean b/lean/OAI/Probability/ParisiFinite/SquareKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..b6b8c95df659a120773b6ef8f8b10251152b13a7 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SquareKernel.lean @@ -0,0 +1,706 @@ +import Mathlib +import OAI.Probability.ParisiFinite.BoundedOf + +namespace OAI + +/-! Square Kernel. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiGuerra +open ParisiFinite SKQAOA SKGaussian ParisiInterpolation + +def squareKernel (n : ℕ) (q : ℝ) (σ τ : Configuration n) : ℝ := (overlap σ τ-q)^2 + +lemma replica_frontier (n : ℕ) (β : ℝ≥0) (hβ : 0 < β) + (cs : List (MovingCoordinate (Configuration n → ℝ))) (q t : ℝ) : + replicaObserve β hβ cs t (frontierKernel n q t) = + (Real.sin t*Real.cos t*(n:ℝ)/2) • replicaObserve β hβ cs t (squareKernel n q) - + BoundedContinuousFunction.const (Configuration n → ℝ) + (Real.sin t*Real.cos t*((n:ℝ)/2*q^2+1/2)) := by + have he : frontierKernel n q t = + (Real.sin t*Real.cos t*(n:ℝ)/2) • squareKernel n q - + (fun _ _ => Real.sin t*Real.cos t*((n:ℝ)/2*q^2+1/2)) := by + ext σ τ + simp only [frontierKernel, squareKernel, Pi.sub_apply, Pi.smul_apply, smul_eq_mul] + ring + rw [he, map_sub, map_smul, replicaObserve_const] + + + +def siteCorrection (n : ℕ) (β : ℝ≥0) (hβ : 0 < β) : + Schedule → ℝ → ℝ → ℝ → BoundedContinuousFunction (Configuration n → ℝ) ℝ + | [], q, a, t => ((β:ℝ)-a) • replicaObserve β hβ [] t (squareKernel n q) + | l::ls, q, a, t => ((l.1:ℝ)-a) • replicaObserve β hβ (siteCoordinates n (l::ls)) t (squareKernel n q) + + prefixTransport (traceField β hβ) (siteCoordinates n ls) (siteBlock n l) t + (siteCorrection n β hβ ls (q+l.2) l.1 t) + +def jumpSquares (β : ℝ) : Schedule → ℝ → ℝ → ℝ + | [], q, a => (β-a)*q^2 + | l::ls, q, a => ((l.1:ℝ)-a)*q^2 + jumpSquares β ls (q+l.2) l.1 + +lemma jumpSquares_eq (β : ℝ) (ls : Schedule) (q a : ℝ) : + jumpSquares β ls q a = β*(q+width ls)^2-a*q^2-4*penalty q ls := by + induction ls generalizing q a with + | nil => simp [jumpSquares, width, penalty]; ring + | cons l ls ih => + simp only [jumpSquares, ih, width, List.map_cons, List.sum_cons, penalty] + ring + +lemma site_remainder {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (q a t : ℝ) (vs : Noise (Configuration n → ℝ)) + (hv : kernelNoise vs = frontierKernel n q t) : + hierarchyRemainder (traceField β hβ) β (siteCoordinates n ls) t a vs = + (Real.sin t*Real.cos t*(n:ℝ)/2) • siteCorrection n β hβ ls q a t - + BoundedContinuousFunction.const (Configuration n → ℝ) + (Real.sin t*Real.cos t*((n:ℝ)/2*jumpSquares β ls q a+((β:ℝ)-a)/2)) := by + induction ls generalizing q a vs with + | nil => + change ((β:ℝ)-a) • noiseGradient (traceField β hβ) vs = _ + have hg := noiseGradient_replica β hβ [] t vs + change noiseGradient (traceField β hβ) vs = _ at hg + rw [hg, hv, replica_frontier] + simp only [siteCorrection, jumpSquares] + ext x + simp only [BoundedContinuousFunction.smul_apply, BoundedContinuousFunction.sub_apply, + BoundedContinuousFunction.const_apply, smul_eq_mul] + ring + | cons l ls ih => + have hh := remainder_nonempty_constant_prefix (traceField β hβ) β a l.1 + (dummyCoordinate l.1) (List.ofFn (fun i : Fin n => MovingCoordinate.cosine l.1 + (fun σ => Real.sqrt l.2*spin σ i))) (siteCoordinates n ls) t vs (siteBlock_gamma n l) + change hierarchyRemainder (traceField β hβ) β (siteCoordinates n (l::ls)) t a vs = + ((l.1:ℝ)-a) • noiseGradient ((hierarchy (traceField β hβ) (siteCoordinates n (l::ls))).field t) vs + + prefixTransport (traceField β hβ) (siteCoordinates n ls) (siteBlock n l) t + (hierarchyRemainder (traceField β hβ) β (siteCoordinates n ls) t l.1 (allNoise (siteBlock n l) t vs)) at hh + rw [hh, noiseGradient_replica, hv, replica_frontier] + have hv' : kernelNoise (allNoise (siteBlock n l) t vs) = frontierKernel n (q+l.2) t := by + rw [kernelNoise_allNoise, hv, frontier_add_site hn] + rw [ih (q+l.2) l.1 _ hv', map_sub, map_smul, prefixTransport_const] + simp only [siteCorrection, jumpSquares] + ext x + simp only [BoundedContinuousFunction.smul_apply, BoundedContinuousFunction.sub_apply, + BoundedContinuousFunction.add_apply, BoundedContinuousFunction.const_apply, smul_eq_mul] + ring + + + +def OrderedFrom (β a : ℝ) : Schedule → Prop + | [] => a ≤ β + | l::ls => a ≤ l.1 ∧ OrderedFrom β l.1 ls + +lemma orderedFrom_of_pairwise {β a : ℝ} {ls : Schedule} + (hp : ls.Pairwise (fun l k => l.1 ≤ k.1)) + (ha : a ≤ β) (hl : ∀ l ∈ ls, a ≤ l.1) (hb : ∀ l ∈ ls, (l.1:ℝ) ≤ β) : + OrderedFrom β a ls := by + induction ls generalizing a with + | nil => exact ha + | cons l ls ih => + rw [List.pairwise_cons] at hp + exact ⟨hl l (by simp), ih hp.2 (hb l (by simp)) + (fun k hk => by exact_mod_cast hp.1 k hk) (fun k hk => hb k (by simp [hk]))⟩ + +lemma admissible_ordered {β : ℝ≥0} {ls : Schedule} (h : Admissible β ls) : OrderedFrom β 0 ls := + orderedFrom_of_pairwise h.2.1 β.coe_nonneg (fun l _ => l.1.coe_nonneg) h.2.2 + +lemma siteCorrection_nonneg (n : ℕ) (β : ℝ≥0) (hβ : 0 < β) (ls : Schedule) + (q a t : ℝ) (h : OrderedFrom β a ls) : ∀ x, 0 ≤ siteCorrection n β hβ ls q a t x := by + induction ls generalizing q a with + | nil => + intro x + exact mul_nonneg (sub_nonneg.mpr h) (replicaObserve_nonneg β hβ [] t (fun _ _ => sq_nonneg _) x) + | cons l ls ih => + intro x + exact add_nonneg + (mul_nonneg (sub_nonneg.mpr h.1) + (replicaObserve_nonneg β hβ (siteCoordinates n (l::ls)) t (fun _ _ => sq_nonneg _) x)) + (prefixTransport_nonneg (traceField β hβ) (siteCoordinates n ls) (siteBlock n l) t + (ih (q+l.2) l.1 h.2) x) +end ParisiGuerra + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiGuerra +open ParisiFinite SKQAOA SKGaussian ParisiInterpolation + +lemma frontier_add_coordinates {n : ℕ} (hn : 0 < n) (ls : Schedule) (q t : ℝ) : + frontierKernel n q t + coordinatesKernel (siteCoordinates n ls) t = + frontierKernel n (q+width ls) t := by + induction ls generalizing q with + | nil => simp [siteCoordinates, coordinatesKernel_nil, width] + | cons l ls ih => + change frontierKernel n q t + coordinatesKernel (siteBlock n l ++ siteCoordinates n ls) t = _ + rw [coordinatesKernel_append, ← add_assoc, frontier_add_site hn, ih] + congr 1 + simp [width, add_assoc] + +lemma complete_covariance {n : ℕ} (hn : 0 < n) (ls : Schedule) (t : ℝ) : + kernelNoise (allNoise (coordinates n ls) t []) = frontierKernel n (width ls) t := by + rw [kernelNoise_allNoise] + simp only [kernelNoise, zero_add] + rw [coordinates, coordinatesKernel_append, costBlock_frontier hn, frontier_add_coordinates hn] + simp only [zero_add] + +lemma complete_diagonal {n : ℕ} (hn : 0 < n) (ls : Schedule) (hw : width ls=1) (t : ℝ) : + diagonalNoise (allNoise (coordinates n ls) t []) = + fun _ => -(Real.sin t*Real.cos t)*((n:ℝ)+1)/2 := by + ext σ + rw [← kernelNoise_diagonal, complete_covariance hn, hw] + unfold frontierKernel overlap + rw [overlapSum_self, div_self (Nat.cast_ne_zero.mpr hn.ne')] + ring + + +def correction (n : ℕ) (β : ℝ≥0) (hβ : 0 < β) (ls : Schedule) (t : ℝ) : ℝ := + prefixTransport (traceField β hβ) (siteCoordinates n ls) (costBlock n) t + (siteCorrection n β hβ ls 0 0 t) 0 + +lemma correction_nonneg (n : ℕ) (β : ℝ≥0) (hβ : 0 < β) (ls : Schedule) + (hl : Admissible β ls) (t : ℝ) : 0 ≤ correction n β hβ ls t := + prefixTransport_nonneg _ _ _ t (siteCorrection_nonneg n β hβ ls 0 0 t (admissible_ordered hl)) 0 + +lemma complete_remainder {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (hw : width ls=1) (t : ℝ) : + hierarchyRemainder (traceField β hβ) β (coordinates n ls) t 0 [] 0 = + Real.sin t*Real.cos t*(n:ℝ)/2 * correction n β hβ ls t - + Real.sin t*Real.cos t*((n:ℝ)/2*((β:ℝ)-4*penalty 0 ls)+(β:ℝ)/2) := by + have hv : kernelNoise (allNoise (costBlock n) t []) = frontierKernel n 0 t := by + rw [kernelNoise_allNoise] + simp only [kernelNoise, zero_add, costBlock_frontier hn] + have he := remainder_constant_prefix (traceField β hβ) β 0 (costBlock n) (siteCoordinates n ls) t [] (costBlock_gamma n) + change hierarchyRemainder (traceField β hβ) β (coordinates n ls) t 0 [] = _ at he + simp only [NNReal.coe_zero] at he + rw [site_remainder hn β hβ ls 0 0 t _ hv, map_sub, map_smul, prefixTransport_const] at he + rw [he, jumpSquares_eq, hw] + simp only [zero_add, one_pow, mul_one, zero_pow (by decide : 2 ≠ 0), mul_zero, sub_zero, + BoundedContinuousFunction.sub_apply, BoundedContinuousFunction.smul_apply, + BoundedContinuousFunction.const_apply, smul_eq_mul, correction] + + + +lemma hasDerivAt_pressureCurve {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (hw : width ls=1) (t : ℝ) : + HasDerivAt (pressureCurve n β ls) + (-2*(n:ℝ)*Real.sin t*Real.cos t*penalty 0 ls - + (n:ℝ)/2*Real.sin t*Real.cos t*correction n β hβ ls t) t := by + have hd := hierarchy_derivative_sum_rule β hβ (coordinates n ls) t 0 + rw [complete_diagonal hn ls hw, spinObserve_const, complete_remainder hn β hβ ls hw] at hd + convert hd using 1 + · rfl + · simp only [BoundedContinuousFunction.const_apply] + ring +end ParisiGuerra + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiGuerra +open ParisiFinite SKQAOA SKGaussian ParisiInterpolation + +lemma continuous_dot_at {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + (F : FieldFamily E) (x : E) : Continuous (fun t => F.dot t x) := + F.continuousDot.comp (continuous_id.prodMk continuous_const) + +lemma continuous_weighted_correction {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (hw : width ls=1) : + Continuous (fun t => Real.sin t*Real.cos t*correction n β hβ ls t) := by + let d := fun t => (hierarchy (traceField β hβ) (coordinates n ls)).dot t 0 + have hc : Continuous d := continuous_dot_at (hierarchy (traceField β hβ) (coordinates n ls)) 0 + have he (t : ℝ) : d t = -2*(n:ℝ)*Real.sin t*Real.cos t*penalty 0 ls - + (n:ℝ)/2*Real.sin t*Real.cos t*correction n β hβ ls t := + (hasDerivAt_hierarchyValue (traceField β hβ) (coordinates n ls) t 0).unique + (hasDerivAt_pressureCurve hn β hβ ls hw t) + have hn' : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have hf : (fun t => Real.sin t*Real.cos t*correction n β hβ ls t) = + fun t => (-2*(n:ℝ)*Real.sin t*Real.cos t*penalty 0 ls-d t)*2/(n:ℝ) := by + funext t + rw [he t] + field_simp [hn'] + ring + rw [hf] + have hh : Continuous (fun t => -2*(n:ℝ)*Real.sin t*Real.cos t*penalty 0 ls) := by fun_prop + exact ((hh.sub hc).mul_const 2).div_const _ + +lemma hasDerivAt_correctedCurve {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (hw : width ls=1) (t : ℝ) : + HasDerivAt (fun s => pressureCurve n β ls s + (n:ℝ)*penalty 0 ls*(Real.sin s)^2) + (-(n:ℝ)/2*(Real.sin t*Real.cos t*correction n β hβ ls t)) t := by + convert (hasDerivAt_pressureCurve hn β hβ ls hw t).add + (((Real.hasDerivAt_sin t).pow 2).const_mul ((n:ℝ)*penalty 0 ls)) using 1 + first | rfl | ring + + + +lemma curve_sum_rule {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (hw : width ls=1) : + pressureCurve n β ls (Real.pi/2) = pressureCurve n β ls 0 - (n:ℝ)*penalty 0 ls - + (n:ℝ)/2*∫ t in (0:ℝ)..(Real.pi/2), Real.sin t*Real.cos t*correction n β hβ ls t := by + have h := intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun t _ => hasDerivAt_correctedCurve hn β hβ ls hw t) + (((continuous_weighted_correction hn β hβ ls hw).const_mul (-(n:ℝ)/2)).intervalIntegrable 0 (Real.pi/2)) + rw [intervalIntegral.integral_const_mul] at h + simp only [Real.sin_pi_div_two, one_pow, mul_one, Real.sin_zero, zero_pow (by norm_num : 2 ≠ 0), + mul_zero, add_zero] at h + linarith + +lemma integrated_correction_nonneg (n : ℕ) (β : ℝ≥0) (hβ : 0 < β) (ls : Schedule) + (hl : Admissible β ls) : + 0 ≤ ∫ t in (0:ℝ)..(Real.pi/2), Real.sin t*Real.cos t*correction n β hβ ls t := by + apply intervalIntegral.integral_nonneg (by positivity) + intro t ht + apply mul_nonneg + · apply mul_nonneg + · exact Real.sin_nonneg_of_nonneg_of_le_pi ht.1 (ht.2.trans (by linarith [Real.pi_pos])) + · exact Real.cos_nonneg_of_mem_Icc ⟨by linarith [Real.pi_pos, ht.1], ht.2⟩ + · exact correction_nonneg n β hβ ls hl t + +lemma curve_upper_bound {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (hl : Admissible β ls) : + pressureCurve n β ls (Real.pi/2) ≤ pressureCurve n β ls 0 - (n:ℝ)*penalty 0 ls := by + rw [curve_sum_rule hn β hβ ls hl.1] + exact sub_le_self _ (mul_nonneg (by positivity) (integrated_correction_nonneg n β hβ ls hl)) +end ParisiGuerra + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] +lemma hierarchyValue_append (f : E → ℝ) (pre tail : List (MovingCoordinate E)) (t : ℝ) : + hierarchyValue f (pre++tail) t = hierarchyValue (hierarchyValue f tail t) pre t := by + induction pre with + | nil => rfl + | cons c cs ih => simp only [List.cons_append, hierarchyValue, ih] +end ParisiFinite +namespace ParisiGuerra +open ParisiFinite SKQAOA SKGaussian ParisiInterpolation + +def siteField (n : ℕ) (x : Fin n → ℝ) (σ : Configuration n) : ℝ := ∑ i, x i*spin σ i + +lemma siteField_zero (n : ℕ) : siteField n 0 = 0 := by ext σ; simp [siteField] + +lemma siteField_update (n : ℕ) (x : Fin n → ℝ) (i : Fin n) (s z : ℝ) : + siteField n x + z • (fun σ => s*spin σ i) = siteField n (Function.update x i (x i+s*z)) := by + ext σ + simp only [siteField, Pi.add_apply, Pi.smul_apply, smul_eq_mul] + rw [← Finset.add_sum_erase _ _ (Finset.mem_univ i), + ← Finset.add_sum_erase _ _ (Finset.mem_univ i)] + rw [Function.update_self] + have he : (∑ j ∈ Finset.univ.erase i, Function.update x i (x i+s*z) j*spin σ j) = + ∑ j ∈ Finset.univ.erase i, x j*spin σ j := by + apply Finset.sum_congr rfl + intro j hj + rw [Function.update_of_ne (Finset.mem_erase.mp hj).1] + rw [he] + ring + +lemma site_sum_update {n : ℕ} (fs : Fin n → ℝ → ℝ) (x : Fin n → ℝ) (i : Fin n) (y : ℝ) : + (∑ j, fs j (Function.update x i y j)) = fs i y + ∑ j ∈ Finset.univ.erase i, fs j (x j) := by + rw [← Finset.add_sum_erase _ _ (Finset.mem_univ i), Function.update_self] + congr 1 + apply Finset.sum_congr rfl + intro j hj + rw [Function.update_of_ne (Finset.mem_erase.mp hj).1] + + +lemma ambientStep_site {n : ℕ} {L : ℝ≥0} {g : ℝ → ℝ} (hg : LipschitzWith L g) + (a s : ℝ) (f : (Configuration n → ℝ) → ℝ) (fs : Fin n → ℝ → ℝ) (i : Fin n) + (hfi : fs i = g) (hf : ∀ x, f (siteField n x) = ∑ j, fs j (x j)) (x : Fin n → ℝ) : + ambientStep a (fun σ => s*spin σ i) f (siteField n x) = + step a s g (x i) + ∑ j ∈ Finset.univ.erase i, fs j (x j) := by + unfold ambientStep + have he (z : ℝ) : f (siteField n x+z • (fun σ => s*spin σ i)) = + g (x i+s*z)+∑ j ∈ Finset.univ.erase i, fs j (x j) := by + rw [siteField_update, hf, site_sum_update, hfi] + simp_rw [he] + exact logMean_add_const (integrable_shift hg (x i) s) (integrable_exp_shift hg a (x i) s) _ + +lemma siteList_endpoint {n : ℕ} {L : ℝ≥0} {g : ℝ → ℝ} (hg : LipschitzWith L g) + (a : ℝ≥0) (s : ℝ) (f : (Configuration n → ℝ) → ℝ) + (hf : ∀ x, f (siteField n x) = ∑ j, g (x j)) (is : List (Fin n)) (hi : is.Nodup) + (x : Fin n → ℝ) : + hierarchyValue f (is.map (fun i => MovingCoordinate.cosine a (fun σ => s*spin σ i))) 0 (siteField n x) = + ∑ j, (if j ∈ is then step a s g else g) (x j) := by + induction is generalizing x with + | nil => simpa only [List.map_nil, hierarchyValue, List.not_mem_nil, ite_false] using hf x + | cons i is ih => + have hi' := List.nodup_cons.mp hi + change ambientStep a ((Real.cos 0) • (fun σ => s*spin σ i)) + (hierarchyValue f (is.map (fun j => MovingCoordinate.cosine a (fun σ => s*spin σ j))) 0) + (siteField n x) = _ + rw [Real.cos_zero, one_smul] + rw [ambientStep_site hg a s _ (fun j => if j∈is then step a s g else g) i + (by simp [hi'.1]) (fun y => ih hi'.2 y)] + rw [← Finset.add_sum_erase _ _ (Finset.mem_univ i)] + simp only [List.mem_cons, true_or, ite_true] + congr 1 + apply Finset.sum_congr rfl + intro j hj + have hji := (Finset.mem_erase.mp hj).1 + simp only [hji, false_or] + +lemma siteBlock_endpoint {n : ℕ} {L : ℝ≥0} {g : ℝ → ℝ} (hg : LipschitzWith L g) + (l : ℝ≥0 × ℝ≥0) (f : (Configuration n → ℝ) → ℝ) + (hf : ∀ x, f (siteField n x) = ∑ j, g (x j)) (x : Fin n → ℝ) : + hierarchyValue f (siteBlock n l) 0 (siteField n x) = + ∑ j, step l.1 (Real.sqrt l.2) g (x j) := by + change ambientStep l.1 ((0 : ℝ) • (0 : Configuration n → ℝ)) (hierarchyValue f + (List.ofFn (fun i : Fin n => MovingCoordinate.cosine l.1 (fun σ => Real.sqrt l.2*spin σ i))) 0) (siteField n x) = _ + rw [zero_smul, ambientStep_zero_direction] + have he : (List.finRange n).map (fun i => MovingCoordinate.cosine l.1 (fun σ => Real.sqrt l.2*spin σ i)) = + List.ofFn (fun i : Fin n => MovingCoordinate.cosine l.1 (fun σ => Real.sqrt l.2*spin σ i)) := by + simp [List.finRange, List.map_ofFn, Function.comp_def] + rw [← he, siteList_endpoint hg l.1 (Real.sqrt l.2) f hf _ (List.nodup_finRange n)] + simp + +lemma spinTrace_site (n : ℕ) (β : ℝ) (x : Fin n → ℝ) : + spinTrace β (siteField n x) = ∑ i, terminal β (x i) := by + have he : (fun σ => β*siteField n x σ) = fun σ => ∑ i, (β*x i)*spin σ i := by + ext σ + simp only [siteField, Finset.mul_sum, mul_assoc] + rw [spinTrace, he, logPartition_site] + simp only [terminal, Finset.sum_div] + +lemma siteCoordinates_endpoint (n : ℕ) {β : ℝ} (hβ : 0 < β) (ls : Schedule) (x : Fin n → ℝ) : + hierarchyValue (spinTrace β) (siteCoordinates n ls) 0 (siteField n x) = + ∑ i, recursion β ls (x i) := by + induction ls generalizing x with + | nil => exact spinTrace_site n β x + | cons l ls ih => + change hierarchyValue (spinTrace β) (siteBlock n l++siteCoordinates n ls) 0 (siteField n x) = _ + rw [hierarchyValue_append, siteBlock_endpoint (recursion_lipschitz hβ ls) l _ ih] + rfl + +lemma costBlock_zero {n : ℕ} (f : (Configuration n → ℝ) → ℝ) : + hierarchyValue f (costBlock n) 0 = f := by + apply hierarchyValue_zero_scales + intro c hc + simp only [costBlock, List.mem_cons, List.mem_ofFn] at hc + rcases hc with rfl | ⟨i,rfl⟩ + · rfl + · exact Real.sin_zero + + + +lemma pressureCurve_zero (n : ℕ) {β : ℝ} (hβ : 0 < β) (ls : Schedule) : + pressureCurve n β ls 0 = (n:ℝ)*recursion β ls 0 := by + unfold pressureCurve coordinates + rw [hierarchyValue_append, costBlock_zero, ← siteField_zero n, siteCoordinates_endpoint n hβ] + simp +end ParisiGuerra + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiFinite +open SKGaussian +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + +lemma integrable_gaussian_linear {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) + {k : ℕ} (v : Fin k → E) (x : E) : + Integrable (fun z : Fin k → ℝ => f (x+∑ i, z i • v i)) (standardLaw k) := by + have hm : Integrable (fun z : Fin k → ℝ => |f x|+(L:ℝ)*∑ i, |z i| *‖v i‖) (standardLaw k) := by + apply (integrable_const _).add + apply Integrable.const_mul + apply integrable_finsetSum + intro i _ + exact (integrable_coordinate i).norm.mul_const _ + apply hm.mono' (hf.continuous.comp (by fun_prop)).aestronglyMeasurable + filter_upwards with z + have h := hf.norm_sub_le (x+∑ i, z i • v i) x + simp only [add_sub_cancel_left, Real.norm_eq_abs] at h + have hsum : ‖∑ i, z i • v i‖ ≤ ∑ i, |z i| *‖v i‖ := by + simpa only [norm_smul, Real.norm_eq_abs] using norm_sum_le (Finset.univ) (fun i => z i • v i) + have htri := abs_add_le (f (x+∑ i, z i • v i)-f x) (f x) + rw [sub_add_cancel] at htri + simp only [Real.norm_eq_abs, Function.comp_apply] + nlinarith [L.coe_nonneg] + + +lemma integral_gaussian_fin_cons {k : ℕ} {F : (Fin (k+1) → ℝ) → ℝ} + (hF : Integrable F (standardLaw (k+1))) : + (∫ z, F z ∂standardLaw (k+1)) = + ∫ s : ℝ, ∫ z : Fin k → ℝ, F (Fin.cons s z) ∂standardLaw k ∂gaussianReal 0 1 := by + let T := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (k+1) => ℝ) 0).symm + have hm : MeasurePreserving T ((gaussianReal 0 1).prod (standardLaw k)) (standardLaw (k+1)) := + (measurePreserving_piFinSuccAbove (fun _ : Fin (k+1) => gaussianReal 0 1) 0).symm + have hi : Integrable (fun p => F (T p)) ((gaussianReal 0 1).prod (standardLaw k)) := + (hm.integrable_comp hF.aestronglyMeasurable).mpr hF + have he (p : ℝ × (Fin k → ℝ)) : T p = Fin.cons p.1 p.2 := by + simp [T, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv] + rw [← hm.integral_comp' F, integral_prod _ hi] + simp_rw [he] + + + +lemma hierarchyValue_gaussian {L : ℝ≥0} {f : E → ℝ} (hf : LipschitzWith L f) + {k : ℕ} (v : Fin k → E) (x : E) : + hierarchyValue f (List.ofFn (fun i => MovingCoordinate.sine 0 (v i))) (Real.pi/2) x = + ∫ z, f (x+∑ i, z i • v i) ∂standardLaw k := by + induction k generalizing x with + | zero => simp [hierarchyValue] + | succ k ih => + rw [List.ofFn_succ] + change ambientStep 0 ((Real.sin (Real.pi/2)) • v 0) + (hierarchyValue f (List.ofFn (fun i : Fin k => MovingCoordinate.sine 0 (v i.succ))) (Real.pi/2)) x = _ + rw [Real.sin_pi_div_two, one_smul] + simp only [ambientStep, logMean_zero] + simp_rw [ih] + rw [integral_gaussian_fin_cons (integrable_gaussian_linear hf v x)] + apply integral_congr_ae + filter_upwards with s + apply integral_congr_ae + filter_upwards with z + congr 1 + rw [Fin.sum_univ_succ] + simp only [Fin.cons_zero, Fin.cons_succ] + abel +end ParisiFinite + + + +open MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology BigOperators +namespace ParisiGuerra +open ParisiFinite SKQAOA SKGaussian ParisiInterpolation + +lemma siteCoordinates_zero_width (n : ℕ) (ls : Schedule) (f : (Configuration n → ℝ) → ℝ) : + hierarchyValue f (siteCoordinates n ls) (Real.pi/2) = f := by + apply hierarchyValue_zero_scales + intro c hc + simp only [siteCoordinates, List.mem_flatMap] at hc + obtain ⟨l, _, hc⟩ := hc + simp only [siteBlock, List.mem_cons, List.mem_ofFn] at hc + rcases hc with rfl | ⟨i,rfl⟩ + · rfl + · exact Real.cos_pi_div_two + +lemma costBlock_expectation (n : ℕ) {β : ℝ} (hβ : β ≠ 0) : + hierarchyValue (spinTrace β) (costBlock n) (Real.pi/2) 0 = pressure β n / β := by + change ambientStep 0 ((0:ℝ) • (0:Configuration n → ℝ)) + (hierarchyValue (spinTrace β) (List.ofFn (fun k : Fin (Fintype.card (Edge n)) => + MovingCoordinate.sine 0 (fun σ => skCoeff n σ ((Fintype.equivFin (Edge n)).symm k)))) (Real.pi/2)) 0 = _ + rw [zero_smul, ambientStep_zero_direction, hierarchyValue_gaussian (spinTrace_lipschitz hβ)] + have he (z : Fin (Fintype.card (Edge n)) → ℝ) : + (0:Configuration n → ℝ)+∑ k, z k • (fun σ => skCoeff n σ ((Fintype.equivFin (Edge n)).symm k)) = + linearField (fun σ k => skCoeff n σ ((Fintype.equivFin (Edge n)).symm k)) z := by + ext σ + simp [linearField, mul_comm] + simp_rw [he] + rw [integral_reindex_field (skCoeff n) (spinTrace β)] + simp_rw [spinTrace, field_skCoeff] + rw [integral_div] + rfl + + + +lemma pressureCurve_pi_div_two (n : ℕ) {β : ℝ} (hβ : β ≠ 0) (ls : Schedule) : + pressureCurve n β ls (Real.pi/2) = pressure β n / β := by + unfold pressureCurve coordinates + rw [hierarchyValue_append, siteCoordinates_zero_width, costBlock_expectation n hβ] + + + +lemma freeEnergy_sum_rule {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (hw : width ls=1) : + freeEnergy β n = functional β ls - + (1/2:ℝ)*∫ t in (0:ℝ)..(Real.pi/2), Real.sin t*Real.cos t*correction n β hβ ls t := by + have hβ' : (0:ℝ) < β := hβ + have hn' : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have h := curve_sum_rule hn β hβ ls hw + rw [pressureCurve_pi_div_two n hβ'.ne', pressureCurve_zero n hβ'] at h + unfold freeEnergy functional + calc + pressure β n / (n:ℝ) / β = (pressure β n / β) / (n:ℝ) := by ring + _ = _ := by rw [h]; field_simp [hn'] + +lemma freeEnergy_le_functional {n : ℕ} (hn : 0 < n) (β : ℝ≥0) (hβ : 0 < β) + (ls : Schedule) (hl : Admissible β ls) : freeEnergy β n ≤ functional β ls := by + rw [freeEnergy_sum_rule hn β hβ ls hl.1] + exact sub_le_self _ (mul_nonneg (by norm_num) (integrated_correction_nonneg n β hβ ls hl)) + +lemma limitingFreeEnergy_le_functional (β : ℝ≥0) (hβ : 0 < β) (ls : Schedule) + (hl : Admissible β ls) : limitingFreeEnergy β ≤ functional β ls := + le_of_tendsto (tendsto_freeEnergy hβ) ((eventually_gt_atTop 0).mono fun _ hn => + freeEnergy_le_functional hn β hβ ls hl) +end ParisiGuerra + + + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal + +namespace SKCavity +open SKGaussian SKQAOA ParisiInterpolation + + +def kernel {ι κ : Type*} [Fintype κ] (A : ι → κ → ℝ) (s t : ι) : ℝ := + ∑ k, A s k * A t k + +lemma squared_increment {ι κ : Type*} [Fintype κ] (A : ι → κ → ℝ) (s t : ι) : + (∑ k, (A s k-A t k)^2) = kernel A s s+kernel A t t-2*kernel A s t := by + simp only [kernel, Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro k _ + ring + +lemma kernel_scale {ι κ : Type*} [Fintype κ] (A : ι → κ → ℝ) (a : ℝ) (s t : ι) : + kernel (fun s k => a*A s k) s t = a^2*kernel A s t := by + simp only [kernel, Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + + + +lemma expected_logPartition_eq_of_kernel {ι κ κ' : Type*} [Fintype ι] [Nonempty ι] + [Fintype κ] [Fintype κ'] (A : ι → κ → ℝ) (B : ι → κ' → ℝ) + (h : ∀ s t, kernel A s t = kernel B s t) : + (∫ z, logPartition (field A z) ∂gaussianLaw κ) = + ∫ z, logPartition (field B z) ∂gaussianLaw κ' := by + have he (s t : ι) : (∑ k, (A s k-A t k)^2) = ∑ k, (B s k-B t k)^2 := by + simp only [squared_increment, h] + exact le_antisymm (expected_field_logPartition_le A B (fun s t => (he s t).le)) + (expected_field_logPartition_le B A (fun s t => (he s t).ge)) + + +def coreScale (n : ℕ) : ℝ := Real.sqrt n / Real.sqrt (n+1) + +def cavityScale (n : ℕ) : ℝ := (Real.sqrt (n+1))⁻¹ + +lemma coreScale_sq (n : ℕ) : coreScale n ^ 2 = (n:ℝ)/(n+1) := by + unfold coreScale + rw [div_pow, Real.sq_sqrt (Nat.cast_nonneg n), Real.sq_sqrt (by positivity)] + +lemma cavityScale_sq (n : ℕ) : cavityScale n ^ 2 = 1/((n:ℝ)+1) := by + unfold cavityScale + rw [inv_pow, Real.sq_sqrt (by positivity), one_div] + +lemma scales_sum (n : ℕ) : coreScale n ^ 2+cavityScale n ^ 2=1 := by + rw [coreScale_sq, cavityScale_sq] + field_simp + + +def cavityCoeff (n : ℕ) (σ : Configuration (n+1)) : Edge n ⊕ Fin n → ℝ := + Sum.elim (fun e => coreScale n*skCoeff n (restrictLeft σ) e) + (fun i => cavityScale n*spin σ (Fin.last n)*spin (restrictLeft σ) i) + +lemma overlapSum_last (n : ℕ) (σ τ : Configuration (n+1)) : + overlapSum σ τ = overlapSum (restrictLeft σ) (restrictLeft τ)+ + spin σ (Fin.last n)*spin τ (Fin.last n) := by + unfold overlapSum + exact Fin.sum_univ_castSucc _ + +lemma cavityCoeff_kernel {n : ℕ} (hn : 0 < n) (σ τ : Configuration (n+1)) : + kernel (cavityCoeff n) σ τ = kernel (skCoeff (n+1)) σ τ := by + have hb : (∑ e : Edge n, + (coreScale n*skCoeff n (restrictLeft σ) e)*(coreScale n*skCoeff n (restrictLeft τ) e)) = + coreScale n^2 * (overlapSum (restrictLeft σ) (restrictLeft τ)^2-(n:ℝ))/(2*n) := by + change kernel (fun s e => coreScale n*skCoeff n s e) (restrictLeft σ) (restrictLeft τ) = _ + rw [kernel_scale, kernel, coeff_covariance hn] + ring + have hz : (∑ i : Fin n, + (cavityScale n*spin σ (Fin.last n)*spin (restrictLeft σ) i)* + (cavityScale n*spin τ (Fin.last n)*spin (restrictLeft τ) i)) = + cavityScale n^2*(spin σ (Fin.last n)*spin τ (Fin.last n))* + overlapSum (restrictLeft σ) (restrictLeft τ) := by + simp only [overlapSum, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + change (∑ k, cavityCoeff n σ k*cavityCoeff n τ k) = _ + simp only [cavityCoeff, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr] + rw [hb, hz, kernel, coeff_covariance (Nat.succ_pos n), overlapSum_last, + coreScale_sq, cavityScale_sq] + have hs : (spin σ (Fin.last n)*spin τ (Fin.last n))^2=1 := by + rw [mul_pow, spin_sq, spin_sq, one_mul] + have hn' : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + push_cast + field_simp [hn'] + nlinarith only [hs] + + + +def correctedCoeff (n : ℕ) (σ : Configuration n) : Edge n ⊕ Edge n → ℝ := + Sum.elim (fun e => coreScale n*skCoeff n σ e) (fun e => cavityScale n*skCoeff n σ e) + +lemma correctedCoeff_kernel (n : ℕ) (σ τ : Configuration n) : + kernel (correctedCoeff n) σ τ = kernel (skCoeff n) σ τ := by + change (∑ k, correctedCoeff n σ k*correctedCoeff n τ k)=_ + simp only [correctedCoeff, Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr] + change kernel (fun s e => coreScale n*skCoeff n s e) σ τ+ + kernel (fun s e => cavityScale n*skCoeff n s e) σ τ=_ + rw [kernel_scale, kernel_scale, ← add_mul, scales_sum, one_mul] + +lemma expected_cavity_pressure {n : ℕ} (hn : 0 < n) (β : ℝ) : + (∫ z, logPartition (fun σ => β*field (cavityCoeff n) z σ) + ∂gaussianLaw (Edge n ⊕ Fin n))=pressure β (n+1) := by + simp_rw [← field_scale] + rw [expected_logPartition_eq_of_kernel _ (fun σ e => β*skCoeff (n+1) σ e) + (fun σ τ => by rw [kernel_scale, kernel_scale, cavityCoeff_kernel hn])] + simp_rw [field_scale, field_skCoeff] + rfl + +lemma expected_corrected_pressure (n : ℕ) (β : ℝ) : + (∫ z, logPartition (fun σ => β*field (correctedCoeff n) z σ) + ∂gaussianLaw (Edge n ⊕ Edge n))=pressure β n := by + simp_rw [← field_scale] + rw [expected_logPartition_eq_of_kernel _ (fun σ e => β*skCoeff n σ e) + (fun σ τ => by rw [kernel_scale, kernel_scale, correctedCoeff_kernel])] + simp_rw [field_scale, field_skCoeff] + rfl +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SumFinLtNat.lean b/lean/OAI/Probability/ParisiFinite/SumFinLtNat.lean new file mode 100644 index 0000000000000000000000000000000000000000..9a0c4e07e5d181ae16b9124eafee842cc0808308 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SumFinLtNat.lean @@ -0,0 +1,665 @@ +import Mathlib +import OAI.Probability.ParisiFinite.WeightedSumPos + +namespace OAI + +/-! Sum Fin Lt Nat. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma sum_fin_lt_nat {N c : ℕ} (hc : c≤N) : + (∑ k : Fin N,if k.val if k k simp + simp_rw [hf] + rw [← Finset.sum_div,sum_fin_lt_nat hc] + +lemma grid_covariance_error {N : ℕ} (hN : 0 (k.val:ℝ)/(m+1:ℕ)) +def cavityGridVariance (m : ℕ) : Fin (m+2) → ℝ := Fin.cons 0 (fun _ : Fin (m+1) => (1:ℝ)/(m+1:ℕ)) + +lemma cavityGridVariance_nonneg (m : ℕ) (k : Fin (m+2)) : 0≤cavityGridVariance m k := by + induction k using Fin.cases with + | zero => exact le_rfl + | succ k => exact div_nonneg zero_le_one (Nat.cast_nonneg _) + +lemma cavityGridVariance_sum (m : ℕ) : (∑ k,cavityGridVariance m k)=1 := by + rw [Fin.sum_univ_succ] + simp only [cavityGridVariance,Fin.cons_zero,Fin.cons_succ,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,zero_add] + field_simp + +lemma cavityGrid_mono (m : ℕ) : Monotone (cavityGrid m) := by + intro i j hij + induction i using Fin.cases with + | zero => + induction j using Fin.cases with + | zero => exact le_rfl + | succ j => + change (-2:ℝ)≤(j.val:ℝ)/(m+1:ℕ) + have h : (0:ℝ)≤(j.val:ℝ)/(m+1:ℕ) := div_nonneg (Nat.cast_nonneg j.val) (Nat.cast_nonneg (m+1)) + linarith + | succ i => + induction j using Fin.cases with + | zero => simp at hij + | succ j => + change (i.val:ℝ)/(m+1:ℕ)≤(j.val:ℝ)/(m+1:ℕ) + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + exact_mod_cast (Fin.succ_le_succ_iff.mp hij) + +lemma cavityGrid_root (m : ℕ) : cavityGrid m 0 < -1 := by norm_num [cavityGrid] +lemma cavityGrid_last (m : ℕ) : cavityGrid m (Fin.last (m+1))<1 := by + change (m:ℝ)/(m+1:ℕ)<1 + apply (div_lt_one (by positivity)).mpr + exact_mod_cast Nat.lt_succ_self m + +lemma cavityGrid_error (m : ℕ) {x : ℝ} (hx0 : 0≤x) (hx1 : x≤1) : + |x-stepCovariance (cavityGrid m) (cavityGridVariance m) x|≤(1:ℝ)/(m+1:ℕ) := by + unfold stepCovariance + rw [Fin.sum_univ_succ] + simp only [cavityGrid,cavityGridVariance,Fin.cons_zero,Fin.cons_succ,ite_self,zero_add] + exact grid_covariance_error (by omega) hx0 hx1 + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def gridCavityMixture (μ : ProbabilityMeasure OverlapArray) (m r : ℕ) (β : ℝ) : ℝ := + ∑ T : PartitionTree (m+1) r, + (μ:Measure OverlapArray).real (hierarchyEvent (treeCodes T) (cavityGrid m))* + cavityGramObservable (codeGramBlock (treeCodes T) (cavityGridVariance m) + (cavityGridVariance_nonneg m) (cavityGridVariance_sum m)) β + +lemma gridCavityMixture_integral (μ : ProbabilityMeasure OverlapArray) (m r : ℕ) (β : ℝ) : + gridCavityMixture μ m r β= + ∫ R,∑ T : PartitionTree (m+1) r, + (hierarchyEvent (treeCodes T) (cavityGrid m)).indicator + (fun _ => cavityGramObservable (codeGramBlock (treeCodes T) (cavityGridVariance m) + (cavityGridVariance_nonneg m) (cavityGridVariance_sum m)) β) R ∂(μ:Measure OverlapArray) := by + rw [integral_finsetSum] + · apply Finset.sum_congr rfl + intro T _ + rw [integral_indicator_const _ (hierarchyEvent_measurable _ _)] + rfl + · intro T _ + exact (integrable_const _).indicator (hierarchyEvent_measurable _ _) + +theorem gridCavityMixture_error {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + (m : ℕ) {r : ℕ} (hr : 0 ∑ T : PartitionTree (m+1) r, (E T).indicator (fun _ => V T) R + have hFi : Integrable F (μ:Measure OverlapArray) := by + apply integrable_finsetSum + intro T _ + exact (integrable_const _).indicator (hierarchyEvent_measurable _ _) + let C : C(OverlapArray,ℝ) := (cavityObservable hr β).comp ⟨blockOfArray r,continuous_blockOfArray r⟩ + have hCi : Integrable C (μ:Measure OverlapArray) := C.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hcover := hierarchy_partition_cover_all hG hgg hu (cavityGrid m) (cavityGrid_mono m) + (cavityGrid_root m) (cavityGrid_last m) hr + have hpos := GG_nonnegative_arrays hG hgg hu hex + have hbd : ∀ᵐ R ∂(μ:Measure OverlapArray),‖C R-F R‖≤β^2*Real.pi/(m+1:ℕ) := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG, + ae_full_probability μ isClosed_NonnegativeArrays.measurableSet hpos, + ae_full_probability μ (MeasurableSet.iUnion fun T => hierarchyEvent_measurable (treeCodes T) (cavityGrid m)) hcover] with R hR hp hc + obtain ⟨T,hT⟩ := Set.mem_iUnion.mp hc + have hF : F R=V T := by + dsimp only [F] + rw [Finset.sum_eq_single T] + · exact Set.indicator_of_mem hT _ + · intro U _ hUT + apply Set.indicator_of_notMem + intro hU + exact (Set.disjoint_left.mp (tree_hierarchy_disjoint hUT (cavityGrid m))) hU hT + · simp + rw [hF,Real.norm_eq_abs] + have h := codeCavity_error hr T (cavityGrid m) (cavityGridVariance m) + (cavityGridVariance_nonneg m) (cavityGridVariance_sum m) (by positivity : (0:ℝ)≤1/(m+1:ℕ)) + (fun x hx0 hx1 => cavityGrid_error m hx0 hx1) hR hp hT β + simpa only [mul_one_div,C,V,ContinuousMap.comp_apply,ContinuousMap.coe_mk] using h + have hi := norm_integral_le_of_norm_le_const hbd + rw [integral_sub hCi hFi] at hi + simp only [Real.norm_eq_abs,Measure.real,measure_univ,ENNReal.toReal_one,mul_one] at hi + rw [gridCavityMixture_integral] + exact hi + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +def gridCavityPolynomial (m r : ℕ) (a : Fin (m+2) → ℝ) (β : ℝ) : ℝ := + ∑ T : PartitionTree (m+1) r,hierarchyNumerator a (treeCodes T)/((r-1).factorial:ℝ)* + cavityGramObservable (codeGramBlock (treeCodes T) (cavityGridVariance m) + (cavityGridVariance_nonneg m) (cavityGridVariance_sum m)) β + +lemma gridCavityPolynomial_continuous (m r : ℕ) (β : ℝ) : + Continuous (fun a => gridCavityPolynomial m r a β) := by + apply continuous_finsetSum + intro T _ + exact ((continuous_hierarchyNumerator _).div_const _).mul continuous_const + +lemma gridCavityMixture_eq_polynomial {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (m : ℕ) {r : ℕ} (hr : 0 overlapDiscount μ (cavityGrid m k)) β := by + apply Finset.sum_congr rfl + intro T _ + congr 1 + have h := GG_hierarchy_EPPF hG hgg hu hr (treeCodes T) (treeCodes_nested T) + (fun i j => by simp) (cavityGrid m) (cavityGrid_mono m) (cavityGrid_last m) + exact (eq_div_iff (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _))).mpr (by simpa only [mul_comm] using h) + +lemma gridCavityPolynomial_limit {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + (β v : ℝ) (hv : Tendsto (quadraticCavitySamples μ β) atTop (𝓝 v)) : + Tendsto (fun m => gridCavityPolynomial m ((m+1)^2) + (fun k => overlapDiscount μ (cavityGrid m k)) β) atTop (𝓝 v) := by + have he : Tendsto (fun m => gridCavityMixture μ m ((m+1)^2) β-quadraticCavitySamples μ β m) + atTop (𝓝 (0:ℝ)) := by + apply tendsto_iff_dist_tendsto_zero.mpr + simp only [Real.dist_eq,sub_zero] + refine squeeze_zero (g:=fun m : ℕ => β^2*Real.pi/(m+1:ℕ)) (fun m => abs_nonneg _) (fun m => ?_) ?_ + · simpa only [abs_sub_comm,quadraticCavitySamples] using gridCavityMixture_error hG hgg hu hex m + (by positivity : 0<(m+1)^2) β + · simpa only [mul_zero,mul_one_div] using tendsto_succ_reciprocal.const_mul (β^2*Real.pi) + have h := he.add hv + simp only [sub_add_cancel,zero_add] at h + have heq (m : ℕ) := gridCavityMixture_eq_polynomial hG hgg hu m (by positivity : 0<(m+1)^2) β + simpa only [heq] using h + + + +theorem exists_grid_cavity_pressure_bound {β : ℝ} (hβ : 0<β) : + ∃ (μ : ProbabilityMeasure OverlapArray) (v : ℝ), + (μ:Measure OverlapArray) GramArrays=1 ∧ GGIdentities μ ∧ + FiniteExchangeable μ ∧ (μ:Measure OverlapArray) UltrametricArrays=1 ∧ + (μ:Measure OverlapArray) NonnegativeArrays=1 ∧ + Tendsto (fun m => gridCavityPolynomial m ((m+1)^2) + (fun k => overlapDiscount μ (cavityGrid m k)) β) atTop (𝓝 v) ∧ + v≤β*limitingFreeEnergy β := by + obtain ⟨μ,v,hG,hgg,hex,hu,hv,hbound⟩ := exists_scalar_ultrametric_cavity hβ + exact ⟨μ,v,hG,hgg,hex,hu,GG_nonnegative_arrays hG hgg hu hex, + gridCavityPolynomial_limit hG hgg hu hex β v hv,hbound⟩ + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +lemma gaussianLaw_isGaussian : IsGaussian (gaussianLaw κ) := by + have hX (k : κ) : HasGaussianLaw (fun x : κ → ℝ => x k) (gaussianLaw κ) := by + refine { aemeasurable := (measurable_pi_apply k).aemeasurable, isGaussian_map := ?_ } + change IsGaussian ((Measure.pi fun _ : κ => gaussianReal 0 1).map fun x => x k) + rw [(measurePreserving_eval (fun _ : κ => gaussianReal 0 1) k).map_eq] + infer_instance + have hi : iIndepFun (fun k (x : κ → ℝ) => x k) (gaussianLaw κ) := + iIndepFun_pi (X:=fun _ : κ => id) (fun _ => measurable_id.aemeasurable) + have h := hi.hasGaussianLaw hX + have hh := h.isGaussian_map + change IsGaussian ((gaussianLaw κ).map id) at hh + simpa only [Measure.map_id] using hh + +def fieldCLM (A : ι → κ → ℝ) : (κ → ℝ) →L[ℝ] (ι → ℝ) := + ContinuousLinearMap.pi (fun i => ∑ k,A i k • ContinuousLinearMap.proj k) + +omit [Fintype ι] in +lemma fieldCLM_apply (A : ι → κ → ℝ) (x : κ → ℝ) : fieldCLM A x=field A x := by + ext i + simp [fieldCLM,field] + +lemma field_hasGaussianLaw (A : ι → κ → ℝ) : + HasGaussianLaw (field A) (gaussianLaw κ) := by + let := gaussianLaw_isGaussian (κ:=κ) + have he : field A=(fieldCLM A : (κ → ℝ) → (ι → ℝ)) := (funext (fieldCLM_apply A)).symm + rw [he] + exact { isGaussian_map := inferInstance } + +omit [Fintype ι] in +lemma field_mean_zero (A : ι → κ → ℝ) (i : ι) : + (∫ x,field A x i ∂gaussianLaw κ)=0 := by + unfold field + rw [integral_finsetSum] + · simp only [integral_const_mul] + have h (k : κ) : (∫ x : κ → ℝ,x k ∂gaussianLaw κ)=0 := by + have hm := measurePreserving_eval (fun _ : κ => gaussianReal 0 1) k + have he := integral_map hm.aemeasurable (f:=id) aestronglyMeasurable_id + rw [hm.map_eq] at he + simpa [gaussianLaw] using he.symm + simp [h] + · intro k _ + exact (memLp_coordinate k).integrable (by norm_num) |>.const_mul _ + +lemma dual_apply_eq_sum [DecidableEq ι] (L : StrongDual ℝ (ι → ℝ)) (x : ι → ℝ) : + L x=∑ i,L (Pi.single i 1)*x i := by + classical + nth_rw 1 [← LinearMap.sum_single_apply (fun _ : ι => ℝ) x] + rw [map_sum] + apply Finset.sum_congr rfl + intro i _ + have he : Pi.single i (x i)=x i • Pi.single i (1:ℝ) := by + ext j + by_cases h : j=i <;> simp [h] + rw [he,map_smul] + simp [mul_comm] + +lemma dual_field_mean_zero (L : StrongDual ℝ (ι → ℝ)) (A : ι → κ → ℝ) : + (∫ x,L (field A x) ∂gaussianLaw κ)=0 := by + classical + have he : (fun x => L (field A x))=fun x => ∑ i,L (Pi.single i 1)*field A x i := + funext (fun x => dual_apply_eq_sum L _) + rw [he,integral_finsetSum] + · simp [integral_const_mul,field_mean_zero] + · intro i _ + exact (integrable_field A i).const_mul _ + +lemma dual_field_variance [DecidableEq ι] (L : StrongDual ℝ (ι → ℝ)) (A : ι → κ → ℝ) : + variance (fun x => L (field A x)) (gaussianLaw κ)= + ∑ i,∑ j,L (Pi.single i 1)*L (Pi.single j 1)*kernel A i j := by + classical + have he : (fun x => L (field A x))=fun x => ∑ i,L (Pi.single i 1)*field A x i := + funext (fun x => dual_apply_eq_sum L _) + rw [he,← covariance_self] + · rw [covariance_fun_sum_fun_sum] + · simp only [covariance_const_mul_left,covariance_const_mul_right,covariance_field,kernel] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + · intro i + exact (memLp_finsetSum Finset.univ (fun k _ => (memLp_coordinate k).const_mul (A i k))).const_mul _ + · intro i + exact (memLp_finsetSum Finset.univ (fun k _ => (memLp_coordinate k).const_mul (A i k))).const_mul _ + · rw [← he] + have hf : field A=(fieldCLM A : (κ → ℝ) → (ι → ℝ)) := (funext (fieldCLM_apply A)).symm + rw [hf] + exact (L.continuous.comp (fieldCLM A).continuous).measurable.aemeasurable + + + +theorem field_law_eq_of_kernel {κ' : Type*} [Fintype κ'] + (A : ι → κ → ℝ) (B : ι → κ' → ℝ) (h : kernel A=kernel B) : + (gaussianLaw κ).map (field A)=(gaussianLaw κ').map (field B) := by + classical + apply Measure.ext_of_charFunDual + funext L + rw [(field_hasGaussianLaw A).charFunDual_map_eq_fun L, + (field_hasGaussianLaw B).charFunDual_map_eq_fun L, + dual_field_mean_zero,dual_field_mean_zero,dual_field_variance,dual_field_variance,h] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma field_continuous_any {ι κ : Type*} [Fintype ι] [Fintype κ] (A : ι → κ → ℝ) : + Continuous (field A) := by + have he : field A=(fieldCLM A : (κ → ℝ) → (ι → ℝ)) := (funext (fieldCLM_apply A)).symm + rw [he] + exact (fieldCLM A).continuous + +lemma integral_field_eq_of_kernel {ι κ κ' : Type*} [Fintype ι] [Fintype κ] [Fintype κ'] + (A : ι → κ → ℝ) (B : ι → κ' → ℝ) (h : kernel A=kernel B) + (f : (ι → ℝ) → ℝ) (hf : Measurable f) : + (∫ x,f (field A x) ∂gaussianLaw κ)=(∫ x,f (field B x) ∂gaussianLaw κ') := by + rw [← integral_map (field_continuous_any A).measurable.aemeasurable hf.aestronglyMeasurable, + ← integral_map (field_continuous_any B).measurable.aemeasurable hf.aestronglyMeasurable, + field_law_eq_of_kernel A B h] + + + +theorem codeGaussian_marginal {d r k : ℕ} (c : Fin d → Fin r → ℕ) + (v : Fin d → ℝ) (hv : ∀ j,0≤v j) (e : Fin k → Fin r) : + (gaussianLaw (Σ j : Fin d,CodeLabel (c j))).map + (fun x i => field (codeGaussianCoeff c v) x (e i))= + (gaussianLaw (Σ j : Fin d,CodeLabel (fun i => c j (e i)))).map + (field (codeGaussianCoeff (fun j i => c j (e i)) v)) := by + apply field_law_eq_of_kernel + funext i l + change kernel (codeGaussianCoeff c v) (e i) (e l)=_ + simp only [kernel_codeGaussianCoeff c v hv, + kernel_codeGaussianCoeff (fun j i => c j (e i)) v hv] + +lemma codeGaussian_integral_marginal {d r k : ℕ} (c : Fin d → Fin r → ℕ) + (v : Fin d → ℝ) (hv : ∀ j,0≤v j) (e : Fin k → Fin r) + (f : (Fin k → ℝ) → ℝ) (hf : Measurable f) : + (∫ x,f (fun i => field (codeGaussianCoeff c v) x (e i)) + ∂gaussianLaw (Σ j : Fin d,CodeLabel (c j)))= + (∫ x,f (field (codeGaussianCoeff (fun j i => c j (e i)) v) x) + ∂gaussianLaw (Σ j : Fin d,CodeLabel (fun i => c j (e i)))) := by + apply integral_field_eq_of_kernel + · funext i l + change kernel (codeGaussianCoeff c v) (e i) (e l)=_ + simp only [kernel_codeGaussianCoeff c v hv, + kernel_codeGaussianCoeff (fun j i => c j (e i)) v hv] + · exact hf + +lemma codeGaussian_law_of_same_partition {d r : ℕ} + (c b : Fin d → Fin r → ℕ) (v : Fin d → ℝ) (hv : ∀ j,0≤v j) + (he : ∀ j i l,c j i=c j l ↔ b j i=b j l) : + (gaussianLaw (Σ j : Fin d,CodeLabel (c j))).map (field (codeGaussianCoeff c v))= + (gaussianLaw (Σ j : Fin d,CodeLabel (b j))).map (field (codeGaussianCoeff b v)) := by + apply field_law_eq_of_kernel + funext i l + simp only [kernel_codeGaussianCoeff c v hv,kernel_codeGaussianCoeff b v hv,he] + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +def gaussianQuantizer (m : ℕ) : SimpleFunc ℝ ℝ := + SimpleFunc.approxOn id measurable_id Set.univ 0 (Set.mem_univ _) m + +abbrev GaussianQuantizerLabel (m : ℕ) := ↥(gaussianQuantizer m).range + +def gaussianQuantizerIndex (m : ℕ) (x : ℝ) : GaussianQuantizerLabel m := + ⟨gaussianQuantizer m x,(gaussianQuantizer m).mem_range_self x⟩ + +lemma gaussianQuantizerIndex_measurable (m : ℕ) : Measurable (gaussianQuantizerIndex m) := + (gaussianQuantizer m).measurable.subtype_mk + +lemma gaussianQuantizer_tendsto (x : ℝ) : + Tendsto (fun m => gaussianQuantizer m x) atTop (𝓝 x) := by + exact SimpleFunc.tendsto_approxOn (f:=id) (s:=(Set.univ : Set ℝ)) (y₀:=0) measurable_id (Set.mem_univ _) (by simp) + +def gaussianQuantizerLaw (m : ℕ) : Measure (GaussianQuantizerLabel m) := + (gaussianReal 0 1).map (gaussianQuantizerIndex m) + +instance gaussianQuantizerLaw_probability (m : ℕ) : IsProbabilityMeasure (gaussianQuantizerLaw m) := by + unfold gaussianQuantizerLaw + infer_instance + +def gaussianQuantizerWeight (m : ℕ) (i : GaussianQuantizerLabel m) : ℝ := + (gaussianQuantizerLaw m).real {i} + +lemma gaussianQuantizerWeight_nonneg (m : ℕ) (i : GaussianQuantizerLabel m) : + 0≤gaussianQuantizerWeight m i := measureReal_nonneg + +lemma gaussianQuantizerWeight_sum (m : ℕ) : (∑ i,gaussianQuantizerWeight m i)=1 := by + simp [gaussianQuantizerWeight] + +lemma gaussianQuantizer_quadrature {κ : Type*} [Fintype κ] [DecidableEq κ] (m : ℕ) + (F : (κ → GaussianQuantizerLabel m) → ℝ) : + (∫ z,F (fun i => gaussianQuantizerIndex m (z i)) ∂gaussianLaw κ)= + ∑ s,(∏ i,gaussianQuantizerWeight m (s i))*F s := by + classical + let ν : Measure (κ → GaussianQuantizerLabel m) := Measure.pi (fun _ => gaussianQuantizerLaw m) + have hm : Measurable (fun z : κ → ℝ => fun i => gaussianQuantizerIndex m (z i)) := + Measurable.of_eval (fun i => (gaussianQuantizerIndex_measurable m).comp (measurable_pi_apply i)) + have hmap : (gaussianLaw κ).map (fun z i => gaussianQuantizerIndex m (z i))=ν := by + exact Measure.pi_map_pi (fun _ => (gaussianQuantizerIndex_measurable m).aemeasurable) + have hF : Integrable F ν := Integrable.of_finite + rw [← integral_map hm.aemeasurable (by rw [hmap]; exact hF.aestronglyMeasurable),hmap,integral_fintype hF] + apply Finset.sum_congr rfl + intro s _ + congr 1 + simp [ν,measureReal_def,Measure.pi_singleton,ENNReal.toReal_prod,gaussianQuantizerWeight] + + + +theorem gaussianQuantizer_bounded_continuous {κ : Type*} [Fintype κ] [DecidableEq κ] + (F : (κ → ℝ) → ℝ) (hF : Continuous F) {C : ℝ} (hC : ∀ x,|F x|≤C) : + Tendsto (fun m => ∑ s : κ → GaussianQuantizerLabel m, + (∏ i,gaussianQuantizerWeight m (s i))*F (fun i => (s i).val)) atTop + (𝓝 (∫ z,F z ∂gaussianLaw κ)) := by + have he (m : ℕ) : (∑ s : κ → GaussianQuantizerLabel m, + (∏ i,gaussianQuantizerWeight m (s i))*F (fun i => (s i).val))= + ∫ z,F (fun i => gaussianQuantizer m (z i)) ∂gaussianLaw κ := + (gaussianQuantizer_quadrature m (fun s => F (fun i => (s i).val))).symm + simp_rw [he] + apply tendsto_integral_of_dominated_convergence (fun _ => C) + · intro m + exact (hF.measurable.comp (Measurable.of_eval (fun i => + (gaussianQuantizer m).measurable.comp (measurable_pi_apply i)))).aestronglyMeasurable + · exact integrable_const C + · intro m + filter_upwards with x + simpa only [Real.norm_eq_abs] using hC (fun i => gaussianQuantizer m (x i)) + · filter_upwards with x + exact hF.continuousAt.tendsto.comp (tendsto_pi_nhds.mpr (fun i => gaussianQuantizer_tendsto (x i))) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +@[reducible] def TreeNode : {d r : ℕ} → PartitionTree d r → Type + | 0,_,_ => Empty + | _+1,_,⟨P,T⟩ => Σ j : Fin P.length,Unit ⊕ TreeNode (T j) + +instance treeNodeFintype {d r : ℕ} (T : PartitionTree d r) : Fintype (TreeNode T) := by + induction d generalizing r with + | zero => exact inferInstanceAs (Fintype Empty) + | succ d ih => + rcases T with ⟨P,T⟩ + let (j : Fin P.length) : Fintype (TreeNode (T j)) := ih (T j) + exact inferInstanceAs (Fintype (Σ j : Fin P.length,Unit ⊕ TreeNode (T j))) +instance treeNodeDecidableEq {d r : ℕ} (T : PartitionTree d r) : DecidableEq (TreeNode T) := Classical.decEq _ + +def treeNodePath : {d r : ℕ} → (T : PartitionTree d r) → Fin r → Fin d → TreeNode T + | 0,_,_,_ => fun k => Fin.elim0 k + | _+1,_,⟨P,T⟩,i => + let j := P.equivSigma.symm i + Fin.cases ⟨j.1,Sum.inl ()⟩ (fun k => ⟨j.1,Sum.inr (treeNodePath (T j.1) j.2 k)⟩) + +lemma treeNodePath_emb {d r : ℕ} (P : OrderedFinpartition r) (T : ∀ j,PartitionTree d (P.partSize j)) + (j : Fin P.length) (i : Fin (P.partSize j)) (k : Fin (d+1)) : + treeNodePath (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r) (P.emb j i) k= + Fin.cases ⟨j,Sum.inl ()⟩ (fun l => ⟨j,Sum.inr (treeNodePath (T j) i l)⟩) k := by + simp only [treeNodePath] + rw [show P.equivSigma.symm (P.emb j i)=⟨j,i⟩ from P.equivSigma.symm_apply_apply ⟨j,i⟩] + +lemma treeNodePath_eq_iff {d r : ℕ} (T : PartitionTree d r) (i j : Fin r) (k : Fin d) : + treeNodePath T i k=treeNodePath T j k ↔ treeCodes T k.succ i=treeCodes T k.succ j := by + induction d generalizing r with + | zero => exact Fin.elim0 k + | succ d ih => + rcases T with ⟨P,T⟩ + obtain ⟨⟨u,i⟩,rfl⟩ := P.equivSigma.surjective i + obtain ⟨⟨v,j⟩,rfl⟩ := P.equivSigma.surjective j + change treeNodePath _ (P.emb u i) k=treeNodePath _ (P.emb v j) k ↔ + treeCodes (⟨P,T⟩ : PartitionTree (d+1) r) k.succ (P.emb u i)= + treeCodes (⟨P,T⟩ : PartitionTree (d+1) r) k.succ (P.emb v j) + rw [treeNodePath_emb,treeNodePath_emb] + simp only [treeCodes_succ,splitCode_emb,Nat.pair_eq_pair] + by_cases huv : u=v + · subst v + induction k using Fin.cases with + | zero => simp [treeCodes_root] + | succ k => simpa using ih (T u) i j k + · have hv : u.val≠v.val := fun h => huv (Fin.ext h) + constructor + · intro h + have he := congrArg Sigma.fst h + have huv' : u=v := by cases k using Fin.cases <;> simpa using he + exact False.elim (huv huv') + · intro h + exact False.elim (hv h.1) + +def treeDrawToNodes {ι : Type*} : {d r : ℕ} → (T : PartitionTree d r) → TreeDraw ι T → TreeNode T → ι + | 0,_,_,_ => fun x => Empty.elim x + | _+1,_,⟨_,T⟩,s => fun ⟨j,x⟩ => Sum.casesOn x (fun _ => (s j).1) (treeDrawToNodes (T j) (s j).2) + +def treeNodesToDraw {ι : Type*} : {d r : ℕ} → (T : PartitionTree d r) → (TreeNode T → ι) → TreeDraw ι T + | 0,_,_,_ => PUnit.unit + | _+1,_,⟨_,T⟩,s => fun j => (s ⟨j,Sum.inl ()⟩,treeNodesToDraw (T j) (fun x => s ⟨j,Sum.inr x⟩)) + +lemma treeNodesToDraw_toNodes {ι : Type*} {d r : ℕ} (T : PartitionTree d r) (s : TreeDraw ι T) : + treeNodesToDraw T (treeDrawToNodes T s)=s := by + induction d generalizing r with + | zero => exact Subsingleton.elim _ _ + | succ d ih => + rcases T with ⟨P,T⟩ + funext j + apply Prod.ext + · rfl + · exact ih (T j) (s j).2 + +lemma treeDrawToNodes_toDraw {ι : Type*} {d r : ℕ} (T : PartitionTree d r) (s : TreeNode T → ι) : + treeDrawToNodes T (treeNodesToDraw T s)=s := by + induction d generalizing r with + | zero => funext x; exact Empty.elim x + | succ d ih => + rcases T with ⟨P,T⟩ + funext ⟨j,x⟩ + cases x with + | inl x => cases x; rfl + | inr x => exact congrFun (ih (T j) (fun y => s ⟨j,Sum.inr y⟩)) x + +def treeDrawEquivNodes (ι : Type*) {d r : ℕ} (T : PartitionTree d r) : TreeDraw ι T ≃ (TreeNode T → ι) where + toFun := treeDrawToNodes T + invFun := treeNodesToDraw T + left_inv := treeNodesToDraw_toNodes T + right_inv := treeDrawToNodes_toDraw T + +lemma treeDrawToNodes_path {ι : Type*} [Fintype ι] {d r : ℕ} (T : PartitionTree d r) (s : TreeDraw ι T) + (i : Fin r) (k : Fin d) : treeDrawToNodes T s (treeNodePath T i k)=treeDrawPath T s i k := by + induction d generalizing r with + | zero => exact Fin.elim0 k + | succ d ih => + rcases T with ⟨P,T⟩ + obtain ⟨⟨j,i⟩,rfl⟩ := P.equivSigma.surjective i + change treeDrawToNodes _ s (treeNodePath _ (P.emb j i) k)=treeDrawPath _ s (P.emb j i) k + rw [treeNodePath_emb,treeDrawPath_emb] + induction k using Fin.cases with + | zero => rfl + | succ k => exact ih (T j) (s j).2 i k + +lemma treeDrawToNodes_weight {ι : Type*} [Fintype ι] {d r : ℕ} (T : PartitionTree d r) + (w : ι → ℝ) (s : TreeDraw ι T) : (∏ n,w (treeDrawToNodes T s n))=treeDrawWeight w T s := by + induction d generalizing r with + | zero => simp [treeDrawWeight] + | succ d ih => + rcases T with ⟨P,T⟩ + change (∏ n : Σ j : Fin P.length,Unit ⊕ TreeNode (T j),w (treeDrawToNodes _ s n))=_ + rw [Fintype.prod_sigma] + simp only [Fintype.prod_sum_type,treeDrawToNodes,Fintype.prod_unique,ih] + rfl + +lemma treeMarkMoment_node_sum {ι : Type*} [Fintype ι] {d r : ℕ} (T : PartitionTree d r) + (w : ι → ℝ) (x : (Fin d → ι) → ℝ) : + treeMarkMoment w x T=∑ s : TreeNode T → ι,(∏ n,w (s n))*∏ i,x (fun k => s (treeNodePath T i k)) := by + rw [← treeDraw_product w x T,← (treeDrawEquivNodes ι T).sum_comp] + apply Finset.sum_congr rfl + intro s _ + simp only [treeDrawEquivNodes,Equiv.coe_fn_mk,treeDrawToNodes_weight,treeDrawToNodes_path] + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/SumLeCode.lean b/lean/OAI/Probability/ParisiFinite/SumLeCode.lean new file mode 100644 index 0000000000000000000000000000000000000000..9418db45e9779e25df167cfa0bb3c6958252da4f --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/SumLeCode.lean @@ -0,0 +1,661 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Labels + +namespace OAI + +/-! Sum Le Code. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped BigOperators + +namespace FiniteWeightedCode +attribute [local instance] Classical.propDecidable + + + +theorem sum_le_code {A B C : Type*} [Fintype A] [Fintype B] [Fintype C] + (good : A → Prop) (first : A → B) (second : A → C) (allowed : B → Finset C) + (f : A → ℝ) (g : B → C → ℝ) + (hg : ∀b c, 0≤g b c) + (hmem : ∀a,good a → second a∈allowed (first a)) + (hinj : ∀a,good a → ∀a',good a' → first a=first a' → second a=second a' → a=a') + (hbound : ∀a,good a → f a≤g (first a) (second a)) : + (∑a : A with good a,f a)≤∑b : B,∑c∈allowed b,g b c := by + classical + let target : Finset (B × C) := Finset.univ.filter (fun z => z.2∈allowed z.1) + have htarget : (∑z∈target,g z.1 z.2)=∑b : B,∑c∈allowed b,g b c := by + simp only [target,Finset.sum_filter,Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro b hb + rw [←Finset.sum_filter] + simp + rw [←htarget] + let code (a : A) : B × C := (first a,second a) + let source : Finset A := Finset.univ.filter good + have hi : Set.InjOn code (↑source : Set A) := by + intro a ha a' ha' he + exact hinj a (Finset.mem_filter.mp ha).2 a' (Finset.mem_filter.mp ha').2 + (congrArg Prod.fst he) (congrArg Prod.snd he) + have hs : source.image code⊆target := by + intro z hz + obtain ⟨a,ha,rfl⟩ := Finset.mem_image.mp hz + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,hmem a (Finset.mem_filter.mp ha).2⟩ + calc + _ ≤ ∑a∈source,g (first a) (second a) := + Finset.sum_le_sum (fun a ha => hbound a (Finset.mem_filter.mp ha).2) + _ = ∑z∈source.image code,g z.1 z.2 := (Finset.sum_image (f := fun z : B × C => g z.1 z.2) hi).symm + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg hs (fun z _ _ => hg z.1 z.2) + +end FiniteWeightedCode + + + +open scoped BigOperators + +namespace SKQAOA.SiteHistories +open BoundedBranch Locality FiniteGraph +variable {n : ℕ} + +def internalEdges (U : Finset (Fin n)) : Finset (Edge n) := + Finset.univ.filter (fun e => e.1.1∈U ∧ e.1.2∈U) + +lemma card_internalEdges_le (U : Finset (Fin n)) : (internalEdges U).card≤U.card*n := by + calc + (internalEdges U).card = ((internalEdges U).image Subtype.val).card := + (Finset.card_image_of_injective _ Subtype.val_injective).symm + _ ≤ (U ×ˢ Finset.univ).card := by + apply Finset.card_le_card + rintro q hq + obtain ⟨e,he,rfl⟩ := Finset.mem_image.mp hq + exact Finset.mem_product.mpr ⟨(Finset.mem_filter.mp he).2.1,Finset.mem_univ _⟩ + _ = U.card*n := by simp + +lemma forestVertices_card_le {p : ℕ} (r : Edge n) (b : Forest n p) : + (forestVertices r b).card≤forestSize b+2 := by + have hr : (roots r).card=2 := by simp [roots,ne_of_lt r.2] + calc + _ ≤ (roots r).card+(forestLabels b).toFinset.card := Finset.card_union_le _ _ + _ ≤ (roots r).card+(forestLabels b).card := Nat.add_le_add_left (Multiset.toFinset_card_le _) _ + _ = _ := by rw [hr,card_forestLabels]; omega + +lemma sum_powerset_pow (E : Finset (Edge n)) (x : ℝ) : + (∑T∈E.powerset,x^T.card)=(1+x)^E.card := by + simpa only [Finset.prod_const] using (Finset.prod_one_add (f := fun _ : Edge n => x) E).symm + + + +lemma sum_extras_bound {p : ℕ} (r : Edge n) (b : Forest n p) {x : ℝ} (hx : 0≤x) : + (∑T∈(internalEdges (forestVertices r b)).powerset,(x/(n:ℝ))^T.card)≤ + Real.exp (x*(forestSize b+2)) := by + have hn : 0 H⊆relevantEdges (H∪{r}) (qaoaWord p γ β) (roots r) ∧ + L≤forestSize (forestCode r H p)) + (fun H => forestCode r H p) (fun H => H\forestEdges r (forestCode r H p)) allowed + (fun H => (x/(n:ℝ))^H.card) (fun b T => forestWeight x b*(x/(n:ℝ))^T.card) + (fun b T => mul_nonneg (forestWeight_nonneg hx b) (pow_nonneg (div_nonneg hx (Nat.cast_nonneg n)) _)) + (fun H hH => by simpa only [allowed,ite_eq_left hH.2] using + Finset.mem_powerset.mpr (extras_internal p γ β r H hH.1)) + (fun H _ K _ hb he => forest_extra_injective r p H K hb he) + (fun H _ => (code_weight r p H x).le) + calc + _ ≤ ∑b : Forest n p,∑T∈allowed b,forestWeight x b*(x/(n:ℝ))^T.card := by + convert hc using 1 + simp only [Finset.sum_filter] + apply Finset.sum_congr rfl + intro H hH + split_ifs <;> rfl + _ = ∑b : Forest n p with L≤forestSize b, + forestWeight x b*∑T∈(internalEdges (forestVertices r b)).powerset,(x/(n:ℝ))^T.card := by + rw [Finset.sum_filter] + apply Finset.sum_congr rfl + intro b hb + by_cases hL : L≤forestSize b <;> simp [allowed,hL,Finset.mul_sum] + _ ≤ ∑b : Forest n p with L≤forestSize b,Real.exp (2*x)*forestWeight (Real.exp x*x) b := + Finset.sum_le_sum (fun b _ => weighted_extras_bound r b hx) + _ ≤ Real.exp (2*x)*((tower (2*(Real.exp x*x)) p)^2/(2:ℝ)^L) := by + rw [←Finset.mul_sum] + exact mul_le_mul_of_nonneg_left (forest_tail_bound n p L (mul_nonneg (Real.exp_pos x).le hx)) + (Real.exp_pos _).le + _ = _ := (mul_div_assoc _ _ _).symm + +end SKQAOA.SiteHistories + + + +open scoped BigOperators + +namespace SKQAOA.SiteHistories +open Locality BoundedBranch +variable {n : ℕ} + +lemma roots_subset_used (r : Edge n) (H : Finset (Edge n)) : roots r⊆usedVertices r H := by + intro v hv + rcases Finset.mem_insert.mp hv with rfl|hv + · exact fst_mem_usedVertices r H (by simp) + · obtain rfl := Finset.mem_singleton.mp hv + exact snd_mem_usedVertices r H (by simp) + +lemma used_card_eq_forestSize_add_two (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) + (hc : H⊆relevantEdges (H∪{r}) (qaoaWord p γ β) (roots r)) : + (usedVertices r H).card=forestSize (forestCode r H p)+2 := by + rw [forestCode_size] + have hu := used_eq_ball p γ β r H hc + change usedVertices r H=reached r H p at hu + rw [←hu] + have hr : (roots r).card=2 := by simp [roots,ne_of_lt r.2] + simpa only [hr] using (Finset.card_sdiff_add_card_eq_card (roots_subset_used r H)).symm + +lemma cluster_zero_of_not_cone (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) + (hc : ¬H⊆relevantEdges (H∪{r}) (qaoaWord p γ β) (roots r)) : + cluster p γ β r H=0 := by + obtain ⟨e,he,he'⟩ := Finset.not_subset.mp hc + exact cluster_eq_zero p γ β r he he' + + + +lemma cluster_zero_of_edge_deficit (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) (hh : H.card+2<(usedVertices r H).card) : + cluster p γ β r H=0 := by + apply cluster_zero_of_not_cone + intro hc + have hu := used_card_eq_forestSize_add_two p γ β r H hc + have he := Finset.card_le_card (forestCode_edges_subset r H p) + rw [forestCode_edges_card] at he + omega + +def tailConstant (p : ℕ) (γ β : Fin p → ℝ) : ℝ := + markedBound p γ β*Real.exp (2*activity p γ β)* + (tower (2*(Real.exp (activity p γ β)*activity p γ β)) p)^2 + +lemma tailConstant_nonneg (p : ℕ) (γ β : Fin p → ℝ) : 0≤tailConstant p γ β := by + unfold tailConstant + exact mul_nonneg (mul_nonneg (markedBound_nonneg p γ β) (Real.exp_pos _).le) (sq_nonneg _) + + + +theorem sum_norm_cluster_tail (p L : ℕ) (γ β : Fin p → ℝ) (r : Edge n) : + (∑H : Finset (Edge n) with L+2≤(usedVertices r H).card,‖cluster p γ β r H‖)≤ + (Real.sqrt (n:ℝ))⁻¹*tailConstant p γ β/(2:ℝ)^L := by + classical + let cone (H : Finset (Edge n)) := H⊆relevantEdges (H∪{r}) (qaoaWord p γ β) (roots r) + have he : (∑H : Finset (Edge n) with L+2≤(usedVertices r H).card,‖cluster p γ β r H‖)= + ∑H : Finset (Edge n) with cone H ∧ L≤forestSize (forestCode r H p),‖cluster p γ β r H‖ := by + simp only [Finset.sum_filter] + apply Finset.sum_congr rfl + intro H hH + by_cases hc : cone H + · have hu := used_card_eq_forestSize_add_two p γ β r H hc + simp only [hu,hc,true_and,Nat.add_le_add_iff_right] + · simp only [cluster_zero_of_not_cone p γ β r H hc,norm_zero,ite_self,hc,false_and] + rw [he] + calc + _ ≤ ∑H : Finset (Edge n) with cone H ∧ L≤forestSize (forestCode r H p), + markedBound p γ β*(Real.sqrt (n:ℝ))⁻¹*(activity p γ β/(n:ℝ))^H.card := + Finset.sum_le_sum (fun H _ => norm_cluster_le p γ β r H) + _ ≤ markedBound p γ β*(Real.sqrt (n:ℝ))⁻¹* + (Real.exp (2*activity p γ β)*(tower (2*(Real.exp (activity p γ β)*activity p γ β)) p)^2/(2:ℝ)^L) := by + rw [←Finset.mul_sum] + exact mul_le_mul_of_nonneg_left (cone_graph_tail p L γ β r (activity_nonneg p γ β)) + (mul_nonneg (markedBound_nonneg p γ β) (by positivity)) + _ = _ := by unfold tailConstant; ring + +end SKQAOA.SiteHistories + + + +open scoped BigOperators + +namespace SKQAOA.SiteHistories +variable {n : ℕ} + + + +def clusterEnergy (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) (H : Finset (Edge n)) : ℂ := + (n:ℂ)⁻¹*((Real.sqrt (n:ℝ))⁻¹:ℂ)*cluster p γ β r H + +def complexEnergy (n p : ℕ) (γ β : Fin p → ℝ) : ℂ := + ∑r : Edge n,∑H : Finset (Edge n),clusterEnergy p γ β r H + + +theorem expectedEnergy_eq_complexEnergy (n p : ℕ) (γ β : Fin p → ℝ) : + expectedEnergy n p γ β=(complexEnergy n p γ β).re := by + have hm (r : Edge n) : (∑H : Finset (Edge n),cluster p γ β r H)= + Locality.averagedMarkedWord r (qaoaWord p γ β) Finset.univ := by + simpa only [Finset.powerset_univ] using (marked_eq_sum_clusters p γ β r Finset.univ).symm + have hc : complexEnergy n p γ β=(n:ℂ)⁻¹*((Real.sqrt (n:ℝ))⁻¹:ℂ)* + ∑r : Edge n, Locality.averagedMarkedWord r (qaoaWord p γ β) Finset.univ := by + simp only [complexEnergy,clusterEnergy,←Finset.mul_sum,hm] + rw [hc,expectedEnergy_history] + simp only [averagedMarkedWord_history,maskPhase,Finset.mem_union,Finset.mem_univ,true_or,ite_true] + rw [Finset.sum_comm] + have he : (∑r : Edge n,∑σ : Configuration n,(skCoeff n σ r:ℂ)* + (∑a:History n p,∑b:History n p,pairedMix n p β σ a b*pairedPhase n p γ a b r* + Complex.exp (∑e,(pairedPhase n p γ a b e)^2/2)))= + ((Real.sqrt (n:ℝ))⁻¹:ℂ)* + (∑r : Edge n,∑σ : Configuration n,∑a:History n p,∑b:History n p, + (spin σ r.1.1:ℂ)*(spin σ r.1.2:ℂ)*pairedMix n p β σ a b*pairedPhase n p γ a b r* + Complex.exp (∑e,(pairedPhase n p γ a b e)^2/2)) := by + simp only [skCoeff,Complex.ofReal_mul,Complex.ofReal_inv,Finset.mul_sum] + apply Finset.sum_congr rfl + intro r hr + apply Finset.sum_congr rfl + intro σ hσ + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + ring + rw [he] + have hn : (n:ℂ)⁻¹=(((n:ℝ)⁻¹:ℝ):ℂ) := by simp + rw [mul_assoc,hn,Complex.re_ofReal_mul] + ring + +lemma clusterEnergy_eq_scaled (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) : + clusterEnergy p γ β r H=(n:ℂ)⁻¹^(H.card+2)*graphCoefficient n n p γ β r H := by + have hn : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr + (Nat.ne_of_gt (lt_of_le_of_lt (Nat.zero_le _) r.1.2.isLt)) + have hs : ((Real.sqrt (n:ℝ))⁻¹:ℂ)^2=(n:ℂ)⁻¹ := by + rw [inv_pow,←Complex.ofReal_pow,Real.sq_sqrt (Nat.cast_nonneg n),Complex.ofReal_natCast] + rw [clusterEnergy,cluster_eq_scaled,pow_add,pow_two] + calc + _ = (((Real.sqrt (n:ℝ))⁻¹:ℂ)^2)*(n:ℂ)⁻¹*(n:ℂ)⁻¹^H.card*graphCoefficient n n p γ β r H := by ring + _ = _ := by rw [hs]; ring + +lemma norm_clusterEnergy (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) : + ‖clusterEnergy p γ β r H‖=(n:ℝ)⁻¹*(Real.sqrt (n:ℝ))⁻¹*‖cluster p γ β r H‖ := by + simp only [clusterEnergy,norm_mul,norm_inv,Complex.norm_natCast,Complex.norm_real,Real.norm_eq_abs, + abs_of_nonneg (Real.sqrt_nonneg _)] + +lemma sum_norm_clusterEnergy_tail (n p L : ℕ) (γ β : Fin p → ℝ) : + (∑r : Edge n,∑H : Finset (Edge n) with L+2≤(usedVertices r H).card, + ‖clusterEnergy p γ β r H‖)≤tailConstant p γ β/(2:ℝ)^L := by + have hi : (Real.sqrt (n:ℝ))⁻¹^2=(n:ℝ)⁻¹ := by + rw [inv_pow,Real.sq_sqrt (Nat.cast_nonneg n)] + have he (r : Edge n) : (∑H : Finset (Edge n) with L+2≤(usedVertices r H).card, + ‖clusterEnergy p γ β r H‖)≤(n:ℝ)⁻¹^2*(tailConstant p γ β/(2:ℝ)^L) := by + simp only [norm_clusterEnergy,←Finset.mul_sum] + calc + _ ≤ (n:ℝ)⁻¹*(Real.sqrt (n:ℝ))⁻¹*((Real.sqrt (n:ℝ))⁻¹*tailConstant p γ β/(2:ℝ)^L) := + mul_le_mul_of_nonneg_left (sum_norm_cluster_tail p L γ β r) (by positivity) + _ = (n:ℝ)⁻¹*(Real.sqrt (n:ℝ))⁻¹^2*(tailConstant p γ β/(2:ℝ)^L) := by ring + _ = _ := by rw [hi]; ring + calc + _ ≤ ∑r : Edge n,(n:ℝ)⁻¹^2*(tailConstant p γ β/(2:ℝ)^L) := Finset.sum_le_sum (fun r _ => he r) + _ = (Fintype.card (Edge n):ℝ)*(n:ℝ)⁻¹^2*(tailConstant p γ β/(2:ℝ)^L) := by simp; ring + _ ≤ 1*(tailConstant p γ β/(2:ℝ)^L) := by + apply mul_le_mul_of_nonneg_right _ (div_nonneg (tailConstant_nonneg p γ β) (by positivity)) + have hc : (Fintype.card (Edge n):ℝ)≤(n:ℝ)^2 := by + exact_mod_cast (show Fintype.card (Edge n)≤n^2 from + (Fintype.card_subtype_le _).trans_eq (by simp [pow_two])) + calc + _ ≤ (n:ℝ)^2*(n:ℝ)⁻¹^2 := mul_le_mul_of_nonneg_right hc (sq_nonneg _) + _ ≤ 1 := by + rw [←mul_pow] + by_cases hn : (n:ℝ)=0 <;> simp [hn] + _ = _ := one_mul _ + +end SKQAOA.SiteHistories + + + +open scoped Topology +open Filter Asymptotics + +namespace FiniteLabelCount + + +lemma tendsto_choose_inv_pow (m : ℕ) : + Tendsto (fun n : ℕ => (n.choose m:ℝ)*(n:ℝ)⁻¹^m) atTop (𝓝 ((m.factorial:ℝ)⁻¹)) := by + have hz : ∀ᶠn : ℕ in atTop,(n:ℝ)^m≠0 := by + filter_upwards [eventually_ge_atTop 1] with n hn + exact pow_ne_zero _ (Nat.cast_ne_zero.mpr (by omega)) + have ht := (isEquivalent_iff_tendsto_one hz).mp (isEquivalent_descFactorial m) + have hf : (m.factorial:ℝ)≠0 := Nat.cast_ne_zero.mpr m.factorial_ne_zero + convert ht.const_mul (m.factorial:ℝ)⁻¹ using 1 + · funext n + simp only [Pi.div_apply,Nat.descFactorial_eq_factorial_mul_choose,Nat.cast_mul,div_eq_mul_inv, + inv_pow] + simp only [←mul_assoc,inv_mul_cancel₀ hf,one_mul] + · simp + + + +lemma tendsto_choose_inv_pow_of_le (m k : ℕ) (hmk : m≤k) : + Tendsto (fun n : ℕ => (n.choose m:ℝ)*(n:ℝ)⁻¹^k) atTop + (𝓝 (if m=k then (m.factorial:ℝ)⁻¹ else 0)) := by + by_cases h : m=k + · subst k + simpa using tendsto_choose_inv_pow m + · have hk : k-m≠0 := by omega + have ht := (tendsto_choose_inv_pow m).mul + ((tendsto_inv_atTop_nhds_zero_nat (𝕜 := ℝ)).pow (k-m)) + simpa only [ite_eq_right h,zero_pow hk,mul_zero,mul_assoc,←pow_add,Nat.add_sub_of_le hmk] using ht + +lemma tendsto_choose_inv_pow_complex (m k : ℕ) (hmk : m≤k) : + Tendsto (fun n : ℕ => (n.choose m:ℂ)*(n:ℂ)⁻¹^k) atTop + (𝓝 (if m=k then (m.factorial:ℂ)⁻¹ else 0)) := by + have ht := Complex.continuous_ofReal.continuousAt.tendsto.comp + (tendsto_choose_inv_pow_of_le m k hmk) + convert ht using 1 + · simp [Function.comp_def] + · split_ifs <;> simp + +end FiniteLabelCount + + + +open scoped BigOperators Topology +open Filter + +namespace SKQAOA.SiteHistories +attribute [local instance] Classical.propDecidable + + +def energySlice (n m p : ℕ) (γ β : Fin p → ℝ) : ℂ := + ∑g : MarkedGraph n with (usedVertices g.1 g.2).card=m,clusterEnergy p γ β g.1 g.2 + +def shapeTerm (N m p : ℕ) (γ β : Fin p → ℝ) (g : FullGraph m) : ℂ := + if m≤g.1.2.card+2 then (N:ℂ)⁻¹^(g.1.2.card+2)*graphCoefficient N m p γ β g.1.1 g.1.2 else 0 + +def shapeTermLimit (m p : ℕ) (γ β : Fin p → ℝ) (g : FullGraph m) : ℂ := + if m=g.1.2.card+2 then (m.factorial:ℂ)⁻¹*graphCoefficientLimit m p γ β g.1.1 g.1.2 else 0 + + + +theorem energySlice_eq_shapes (n m p : ℕ) (γ β : Fin p → ℝ) : + energySlice n m p γ β=(n.choose m:ℂ)*∑g : FullGraph m,shapeTerm n m p γ β g := by + let F (g : MarkedGraph n) := + if m≤g.2.card+2 then clusterEnergy p γ β g.1 g.2 else 0 + have he : energySlice n m p γ β= + ∑g : MarkedGraph n with (usedVertices g.1 g.2).card=m,F g := by + apply Finset.sum_congr rfl + intro g hg + have hc := (Finset.mem_filter.mp hg).2 + by_cases h : m≤g.2.card+2 + · simp only [F,ite_eq_left h] + · have hd : g.2.card+2<(usedVertices g.1 g.2).card := by omega + simp only [F,ite_eq_right h,clusterEnergy,cluster_zero_of_edge_deficit p γ β g.1 g.2 hd,mul_zero] + rw [he,sum_full_graphs] + have hF (U : SupportSet n m) (g : FullGraph m) : + F (graphMap (U.1.orderEmbOfFin U.2) g.1)=shapeTerm n m p γ β g := by + dsimp only [F,graphMap,shapeTerm] + simp only [Finset.card_map] + split_ifs + · rw [clusterEnergy_eq_scaled,Finset.card_map,graphCoefficient_relabel] + · rfl + simp_rw [hF] + simp only [Finset.sum_const,Finset.card_univ,nsmul_eq_mul,card_supportSet] + +def energySliceLimit (m p : ℕ) (γ β : Fin p → ℝ) : ℂ := + ∑g : FullGraph m,shapeTermLimit m p γ β g + + +theorem tendsto_energySlice (m p : ℕ) (γ β : Fin p → ℝ) : + Tendsto (fun n => energySlice n m p γ β) atTop (𝓝 (energySliceLimit m p γ β)) := by + simp only [energySlice_eq_shapes,Finset.mul_sum,energySliceLimit] + apply tendsto_finsetSum + intro g hg + by_cases hm : m≤g.1.2.card+2 + · have ht := (FiniteLabelCount.tendsto_choose_inv_pow_complex m (g.1.2.card+2) hm).mul + (tendsto_graphCoefficient m p γ β g.1.1 g.1.2) + by_cases he : m=g.1.2.card+2 + · simpa only [shapeTerm,shapeTermLimit,ite_eq_left hm,ite_eq_left he,mul_assoc] using ht + · simpa only [shapeTerm,shapeTermLimit,ite_eq_left hm,ite_eq_right he,zero_mul,mul_assoc] using ht + · have he : m≠g.1.2.card+2 := by omega + simp only [shapeTerm,shapeTermLimit,ite_eq_right hm,ite_eq_right he,mul_zero] + exact tendsto_const_nhds + + +def truncatedEnergy (n p L : ℕ) (γ β : Fin p → ℝ) : ℂ := + ∑g : MarkedGraph n with (usedVertices g.1 g.2).card (usedVertices g.1 g.2).card) + (fun g => clusterEnergy p γ β g.1 g.2)).symm + +theorem tendsto_truncatedEnergy (p L : ℕ) (γ β : Fin p → ℝ) : + Tendsto (fun n => truncatedEnergy n p L γ β) atTop + (𝓝 (∑m∈Finset.range (L+2),energySliceLimit m p γ β)) := by + simp only [truncatedEnergy_eq_slices] + exact tendsto_finsetSum _ (fun m _ => tendsto_energySlice m p γ β) + +end SKQAOA.SiteHistories + + + +open scoped Topology +open Filter + +namespace UniformApproximation + + + +theorem cauchySeq_of_approximants {E : Type*} [PseudoMetricSpace E] + (f : ℕ → E) (a : ℕ → ℕ → E) (c : ℕ → E) (b : ℕ → ℝ) + (ha : ∀L,Tendsto (a L) atTop (𝓝 (c L))) + (hb : Tendsto b atTop (𝓝 0)) + (hd : ∀L n,dist (f n) (a L n)≤b L) : CauchySeq f := by + apply Metric.cauchySeq_iff.mpr + intro ε hε + have hε3 : 0<ε/3 := by positivity + obtain ⟨L,hL⟩ := (hb.eventually (gt_mem_nhds hε3)).exists + obtain ⟨N,hN⟩ := Metric.cauchySeq_iff.mp (ha L).cauchySeq (ε/3) hε3 + refine ⟨N,fun m hm n hn => ?_⟩ + have ht : dist (f m) (f n)≤dist (f m) (a L m)+dist (a L m) (a L n)+dist (a L n) (f n) := + (dist_triangle (f m) (a L m) (f n)).trans + (by linarith [dist_triangle (a L m) (a L n) (f n)]) + have hd₁ := hd L m + have hd₂ := hd L n + rw [dist_comm (f n)] at hd₂ + have hmn := hN m hm n hn + linarith + +end UniformApproximation + + + +open scoped BigOperators Topology +open Filter + +namespace SKQAOA.SiteHistories +attribute [local instance] Classical.propDecidable + +lemma norm_complexEnergy_sub_truncated (n p L : ℕ) (γ β : Fin p → ℝ) : + ‖complexEnergy n p γ β-truncatedEnergy n p L γ β‖≤tailConstant p γ β/(2:ℝ)^L := by + have he : complexEnergy n p γ β-truncatedEnergy n p L γ β= + ∑g : MarkedGraph n with L+2≤(usedVertices g.1 g.2).card,clusterEnergy p γ β g.1 g.2 := by + have h := Finset.sum_filter_add_sum_filter_not (s:=Finset.univ) + (p:=fun g : MarkedGraph n => (usedVertices g.1 g.2).card clusterEnergy p γ β g.1 g.2) + simp only [not_lt] at h + rw [complexEnergy,truncatedEnergy] + rw [Fintype.sum_prod_type] at h + exact sub_eq_iff_eq_add.mpr (h.symm.trans (add_comm _ _)) + rw [he] + calc + _ ≤ ∑g : MarkedGraph n with L+2≤(usedVertices g.1 g.2).card,‖clusterEnergy p γ β g.1 g.2‖ := norm_sum_le _ _ + _ = ∑r : Edge n,∑H : Finset (Edge n) with L+2≤(usedVertices r H).card,‖clusterEnergy p γ β r H‖ := by + simp only [Finset.sum_filter,Fintype.sum_prod_type] + _ ≤ _ := sum_norm_clusterEnergy_tail n p L γ β + +theorem exists_complexEnergy_limit (p : ℕ) (γ β : Fin p → ℝ) : + ∃ z : ℂ,Tendsto (fun n => complexEnergy n p γ β) atTop (𝓝 z) := by + apply cauchySeq_tendsto_of_complete + apply UniformApproximation.cauchySeq_of_approximants + (a:=fun L n => truncatedEnergy n p L γ β) + (c:=fun L => ∑m∈Finset.range (L+2),energySliceLimit m p γ β) + (b:=fun L => tailConstant p γ β/(2:ℝ)^L) + · exact fun L => tendsto_truncatedEnergy p L γ β + · have ht := (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : 0≤(2:ℝ)⁻¹) + (by norm_num : (2:ℝ)⁻¹<1)).const_mul (tailConstant p γ β) + simpa only [div_eq_mul_inv,inv_pow,mul_zero] using ht + · intro L n + simpa only [dist_eq_norm] using norm_complexEnergy_sub_truncated n p L γ β + +end SKQAOA.SiteHistories + +namespace SKQAOA + + + +theorem exists_expectedEnergy_limit (p : ℕ) (γ β : Fin p → ℝ) : + ∃ v : ℝ,Tendsto (fun n => expectedEnergy n p γ β) atTop (𝓝 v) := by + obtain ⟨z,hz⟩ := SiteHistories.exists_complexEnergy_limit p γ β + refine ⟨z.re,?_⟩ + simpa only [SiteHistories.expectedEnergy_eq_complexEnergy,Function.comp_def] using + Complex.continuous_re.continuousAt.tendsto.comp hz + + +theorem tendsto_expectedEnergy_value (p : ℕ) (γ β : Fin p → ℝ) : + Tendsto (fun n => expectedEnergy n p γ β) atTop (𝓝 (value p γ β)) := by + exact tendsto_nhds_limUnder (exists_expectedEnergy_limit p γ β) + +end SKQAOA + + + +open scoped Topology +open Filter + +namespace SKQAOA + +theorem abs_value_le_Pstar (p : ℕ) (γ β : Fin p → ℝ) : |value p γ β|≤Pstar := by + exact le_of_tendsto_of_tendsto (tendsto_expectedEnergy_value p γ β).abs tendsto_expectedGround + (Eventually.of_forall fun n => abs_expectedEnergy_le_expectedGround n p γ β) + +theorem value_le_Pstar (p : ℕ) (γ β : Fin p → ℝ) : value p γ β≤Pstar := + (le_abs_self _).trans (abs_value_le_Pstar p γ β) + +theorem valueSet_bddAbove (p : ℕ) : + BddAbove (Set.range fun θ : (Fin p → ℝ)×(Fin p → ℝ) => value p θ.1 θ.2) := by + refine ⟨Pstar,?_⟩ + rintro x ⟨θ,rfl⟩ + exact value_le_Pstar p θ.1 θ.2 + +theorem value_le_Q (p : ℕ) (γ β : Fin p → ℝ) : value p γ β≤Q p := + le_csSup (valueSet_bddAbove p) (Set.mem_range_self (γ,β)) + +theorem Q_le_Pstar (p : ℕ) : Q p≤Pstar := by + apply csSup_le (Set.range_nonempty _) + rintro x ⟨θ,rfl⟩ + exact value_le_Pstar p θ.1 θ.2 + +theorem monotone_Q : Monotone Q := by + intro p q hpq + obtain ⟨k,rfl⟩ := Nat.exists_eq_add_of_le hpq + apply csSup_le (Set.range_nonempty _) + rintro x ⟨⟨γ,β⟩,rfl⟩ + simpa only [value_extendAngles] using value_le_Q (p+k) (extendAngles γ k) (extendAngles β k) + + + +def attainableEnergy : ℝ := sSup (Set.range Q) + +theorem attainableEnergy_le_Pstar : attainableEnergy≤Pstar := by + apply csSup_le (Set.range_nonempty _) + rintro x ⟨p,rfl⟩ + exact Q_le_Pstar p + +theorem tendsto_Q_attainableEnergy : Tendsto Q atTop (𝓝 attainableEnergy) := by + simpa only [attainableEnergy, iSup] using tendsto_atTop_ciSup monotone_Q ⟨Pstar,fun x ⟨p,hp⟩ => hp ▸ Q_le_Pstar p⟩ + +end SKQAOA + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/TendstoDyadicRound.lean b/lean/OAI/Probability/ParisiFinite/TendstoDyadicRound.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f7114247620a381720ce5627e9a75f7b55d70d7 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/TendstoDyadicRound.lean @@ -0,0 +1,620 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Model + +namespace OAI + +/-! Tendsto Dyadic Round. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] +variable {X : ℝ≥0 → Ω → ℝ} + +lemma tendsto_dyadicRound (t : ℝ≥0) : Tendsto (fun n => dyadicRound n t) atTop (𝓝 t) := by + apply NNReal.tendsto_coe.mp + have hlim : Tendsto (fun n : ℕ => (1/2:ℝ)^n) atTop (𝓝 0) := + tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num) (by norm_num) + have hl : Tendsto (fun n : ℕ => (t:ℝ)-(1/2:ℝ)^n) atTop (𝓝 (t:ℝ)) := by + simpa using tendsto_const_nhds.sub hlim + refine tendsto_of_tendsto_of_tendsto_of_le_of_le hl tendsto_const_nhds ?_ ?_ + · intro n + have hh := lt_dyadicRound_add n t + have hh' : (t:ℝ)<(dyadicRound n t:ℝ)+(1/2:ℝ)^n := by exact_mod_cast hh + linarith + · intro n + exact NNReal.coe_le_coe.mpr (dyadicRound_le n t) + +lemma preBrownian_tendstoInMeasure (hX : IsPreBrownianReal X P) {s : ℕ → ℝ≥0} {t : ℝ≥0} + (hs : Tendsto s atTop (𝓝 t)) : TendstoInMeasure P (fun n => X (s n)) atTop (X t) := by + apply tendstoInMeasure_iff_dist.mpr + intro ε hε + have hbound (n : ℕ) : P {ω | ε≤dist (X (s n) ω) (X t ω)} ≤ + ENNReal.ofReal (gaussianFourth*(dist (s n) t)^2/(ε/2)^4) := by + have hl := hX.hasLaw_sub (s n) t + have hh := fourth_tail_bound hl (show 0<ε/2 by positivity) + apply (measure_mono (show {ω | ε≤dist (X (s n) ω) (X t ω)} ⊆ + {ω | ε/2 < |(X (s n)-X t) ω|} from fun ω hω => by + simp only [Set.mem_ofPred_eq,Pi.sub_apply] at hω ⊢ + rw [Real.dist_eq] at hω + linarith)).trans + convert hh using 1 + congr 2 + have hd : Tendsto (fun n => dist (s n) t) atTop (𝓝 0) := by + simpa using hs.dist (tendsto_const_nhds (x:=t)) + have hlim : Tendsto (fun n => ENNReal.ofReal (gaussianFourth*(dist (s n) t)^2/(ε/2)^4)) + atTop (𝓝 0) := by + simpa only [comp_def,zero_pow (by norm_num : (2:ℕ)≠0),mul_zero,zero_div,ENNReal.ofReal_zero] using ENNReal.continuous_ofReal.tendsto _ |>.comp ((hd.pow 2).const_mul gaussianFourth |>.div_const ((ε/2)^4)) + exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds hlim (fun _ => bot_le) hbound +end BrownianConstruction + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction +variable {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} [IsProbabilityMeasure P] +variable {X : ℝ≥0 → Ω → ℝ} + +def continuousModification (X : ℝ≥0 → Ω → ℝ) (t : ℝ≥0) (ω : Ω) : ℝ := + dyadicLimit (fun s => X s ω) t + +lemma continuousModification_ae_continuous (hX : IsPreBrownianReal X P) : + ∀ᵐ ω ∂P, Continuous (fun t => continuousModification X t ω) := by + filter_upwards [ae_dyadicGood hX] with ω hω + exact continuous_dyadicLimit (by norm_num) (by norm_num) hω + +lemma continuousModification_ae_eq (hX : IsPreBrownianReal X P) (t : ℝ≥0) : + X t =ᵐ[P] continuousModification X t := by + have hround := preBrownian_tendstoInMeasure hX (tendsto_dyadicRound t) + have hlim : TendstoInMeasure P (fun n => X (dyadicRound n t)) atTop (continuousModification X t) := by + apply tendstoInMeasure_of_tendsto_ae (fun n => (hX.aemeasurable _).aestronglyMeasurable) + filter_upwards [ae_dyadicGood hX] with ω hω + exact tendsto_dyadicLimit (by norm_num) (by norm_num) hω t + exact tendstoInMeasure_ae_unique hround hlim + +lemma continuousModification_isBrownian (hX : IsPreBrownianReal X P) : + IsBrownianReal (continuousModification X) P := + ⟨hX.congr (continuousModification_ae_eq hX),continuousModification_ae_continuous hX⟩ +end BrownianConstruction + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology ENNReal NNReal +namespace BrownianConstruction + +abbrev BrownianHilbert := Lp ℝ 2 (volume : Measure ℝ) +def brownianBasisIndex : Set BrownianHilbert := Classical.choose (exists_hilbertBasis ℝ BrownianHilbert) +def brownianBasis : HilbertBasis brownianBasisIndex ℝ BrownianHilbert := + Classical.choose (Classical.choose_spec (exists_hilbertBasis ℝ BrownianHilbert)) +abbrev BrownianSample := brownianBasisIndex → ℝ +def brownianMeasure : Measure BrownianSample := gaussianProduct brownianBasisIndex +instance brownianMeasure_probability : IsProbabilityMeasure brownianMeasure := by + unfold brownianMeasure + infer_instance +def brownianMotion : ℝ≥0 → BrownianSample → ℝ := + continuousModification (preBrownian brownianBasis) +theorem brownianMotion_isBrownian : IsBrownianReal brownianMotion brownianMeasure := + continuousModification_isBrownian (preBrownian_isPreBrownian brownianBasis) +end BrownianConstruction + + + + + + + +open scoped BigOperators Matrix Topology +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA + + +abbrev Configuration (n : ℕ) := Fin n → Bool + + +abbrev Edge (n : ℕ) := {e : Fin n × Fin n // e.1 < e.2} + +abbrev Disorder (n : ℕ) := Edge n → ℝ +abbrev State (n : ℕ) := Configuration n → ℂ +abbrev Operator (n : ℕ) := Matrix (Configuration n) (Configuration n) ℂ + + +def disorderLaw (n : ℕ) : Measure (Disorder n) := + Measure.pi fun _ => gaussianReal 0 1 + +def spin {n : ℕ} (σ : Configuration n) (i : Fin n) : ℝ := + if σ i then -1 else 1 + + +def hamiltonian (n : ℕ) (J : Disorder n) (σ : Configuration n) : ℝ := + (Real.sqrt (n : ℝ))⁻¹ * ∑ e : Edge n, J e * spin σ e.1.1 * spin σ e.1.2 + + +def pauliZ {n : ℕ} (i : Fin n) : Operator n := + Matrix.diagonal fun σ => (spin σ i : ℂ) + + +def pauliX {n : ℕ} (i : Fin n) : Operator n := + fun σ τ => if σ = Function.update τ i (!(τ i)) then 1 else 0 + + +def cost (n : ℕ) (J : Disorder n) : Operator n := + ((Real.sqrt (n : ℝ))⁻¹ : ℂ) • + ∑ e : Edge n, (J e : ℂ) • (pauliZ e.1.1 * pauliZ e.1.2) + +def mixer (n : ℕ) : Operator n := ∑ i : Fin n, pauliX i + + +def plus (n : ℕ) : State n := + fun _ => ((Real.sqrt ((2 : ℝ) ^ n))⁻¹ : ℝ) + + +def evolution {n : ℕ} (t : ℝ) (A : Operator n) : Operator n := + NormedSpace.exp ((-(t : ℂ) * Complex.I) • A) + + +def circuit {n : ℕ} (J : Disorder n) : + (p : ℕ) → (Fin p → ℝ) → (Fin p → ℝ) → Operator n + | 0, _, _ => 1 + | p + 1, γ, β => + evolution (β (Fin.last p)) (mixer n) * + evolution (γ (Fin.last p)) (cost n J) * + circuit J p (fun i => γ i.castSucc) (fun i => β i.castSucc) + +def qaoaState (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) : State n := + (circuit J p γ β).mulVec (plus n) + + +def energyDensity (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) : ℝ := + (∑ σ : Configuration n, + star (qaoaState n p J γ β σ) * + (cost n J).mulVec (qaoaState n p J γ β) σ).re / (n : ℝ) + +def expectedEnergy (n p : ℕ) (γ β : Fin p → ℝ) : ℝ := + ∫ J, energyDensity n p J γ β ∂disorderLaw n + + +def groundMaximum (n : ℕ) (J : Disorder n) : ℝ := + sSup (Set.range (hamiltonian n J)) + +def expectedGround (n : ℕ) : ℝ := + (∫ J, groundMaximum n J ∂disorderLaw n) / (n : ℝ) + + +def Pstar : ℝ := limUnder atTop expectedGround + + +def value (p : ℕ) (γ β : Fin p → ℝ) : ℝ := + limUnder atTop (fun n => expectedEnergy n p γ β) + +def Q (p : ℕ) : ℝ := + sSup (Set.range fun θ : (Fin p → ℝ) × (Fin p → ℝ) => value p θ.1 θ.2) + + +theorem cost_eq_diagonal (n : ℕ) (J : Disorder n) : + cost n J = Matrix.diagonal (fun σ => (hamiltonian n J σ : ℂ)) := by + classical + ext σ τ + by_cases h : σ = τ + · subst τ + simp [cost, pauliZ, Matrix.diagonal_mul_diagonal, hamiltonian, + Matrix.sum_apply, Matrix.smul_apply, smul_eq_mul, Complex.ofReal_sum, mul_assoc] + · simp [cost, pauliZ, Matrix.diagonal_mul_diagonal, h, + Matrix.sum_apply, Matrix.smul_apply, smul_eq_mul] + + +theorem flip_flip {n : ℕ} (i : Fin n) (σ : Configuration n) : + Function.update (Function.update σ i (!(σ i))) i + (!(Function.update σ i (!(σ i)) i)) = σ := by + funext j + by_cases h : j = i + · subst j + simp + · simp [h] + +theorem flip_eq_iff {n : ℕ} (i : Fin n) (σ τ : Configuration n) : + σ = Function.update τ i (!(τ i)) ↔ + τ = Function.update σ i (!(σ i)) := by + constructor <;> intro h <;> subst_vars <;> simp + +theorem cost_hermitian (n : ℕ) (J : Disorder n) : + (cost n J).IsHermitian := by + rw [cost_eq_diagonal] + ext σ τ + by_cases h : σ = τ + · subst τ + simp + · simp [Matrix.conjTranspose_apply, h, Ne.symm h] + +theorem pauliX_hermitian {n : ℕ} (i : Fin n) : + (pauliX i).IsHermitian := by + ext σ τ + simp [Matrix.conjTranspose_apply, pauliX, flip_eq_iff i τ σ] + +theorem mixer_hermitian (n : ℕ) : (mixer n).IsHermitian := by + unfold mixer Matrix.IsHermitian + rw [Matrix.conjTranspose_sum] + exact Finset.sum_congr rfl fun i _ => pauliX_hermitian i + +@[simp] theorem evolution_zero {n : ℕ} (A : Operator n) : + evolution 0 A = 1 := by + simp [evolution] + + +theorem evolution_unitary {n : ℕ} (t : ℝ) (A : Operator n) + (hA : A.IsHermitian) : evolution t A ∈ unitary (Operator n) := by + let B : Operator n := (-(t : ℂ) * Complex.I) • A + have hs : Bᴴ = -B := by + change star ((-(t : ℂ) * Complex.I) • A) = -_ + rw [star_smul, hA.star_eq] + simp [B, star_mul, mul_comm, neg_smul] + change NormedSpace.exp B ∈ unitary (Operator n) + rw [Unitary.mem_iff, Matrix.star_eq_conjTranspose, ← Matrix.exp_conjTranspose, hs] + constructor + · rw [← Matrix.exp_add_of_commute _ _ (Commute.refl B).neg_left, + neg_add_cancel, NormedSpace.exp_zero] + · rw [← Matrix.exp_add_of_commute _ _ (Commute.refl B).neg_right, + add_neg_cancel, NormedSpace.exp_zero] + + +theorem circuit_unitary {n : ℕ} (J : Disorder n) (p : ℕ) + (γ β : Fin p → ℝ) : circuit J p γ β ∈ unitary (Operator n) := by + induction p with + | zero => exact (unitary _).one_mem + | succ p ih => + exact (unitary _).mul_mem + ((unitary _).mul_mem + (evolution_unitary _ _ (mixer_hermitian n)) + (evolution_unitary _ _ (cost_hermitian n J))) + (ih _ _) + + +def mass {n : ℕ} (ψ : State n) : ℝ := ∑ σ, Complex.normSq (ψ σ) + +theorem mass_eq_dot {n : ℕ} (ψ : State n) : + (mass ψ : ℂ) = star ψ ⬝ᵥ ψ := by + simp [mass, dotProduct, Complex.normSq_eq_conj_mul_self] + +theorem unitary_preserves_mass {n : ℕ} {A : Operator n} + (hA : A ∈ unitary (Operator n)) (ψ : State n) : + mass (A.mulVec ψ) = mass ψ := by + apply Complex.ofReal_injective + rw [mass_eq_dot, mass_eq_dot, Matrix.star_mulVec, + ← Matrix.dotProduct_mulVec, Matrix.mulVec_mulVec] + have h : Aᴴ * A = 1 := Unitary.star_mul_self_of_mem hA + rw [h, Matrix.one_mulVec] + + +theorem plus_mass (n : ℕ) : mass (plus n) = 1 := by + have hp : 0 < (2 : ℝ) ^ n := pow_pos (by norm_num) n + simp only [mass, plus, Complex.normSq_ofReal, Finset.sum_const, + Finset.card_univ, Fintype.card_fun, Fintype.card_bool, Fintype.card_fin, + nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat] + rw [← sq, inv_pow, Real.sq_sqrt hp.le] + exact mul_inv_cancel₀ (ne_of_gt hp) + + +theorem qaoaState_mass (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) : + mass (qaoaState n p J γ β) = 1 := by + rw [qaoaState, unitary_preserves_mass (circuit_unitary J p γ β), plus_mass] + + + +theorem energyDensity_eq (n p : ℕ) (J : Disorder n) (γ β : Fin p → ℝ) : + energyDensity n p J γ β = + (∑ σ, Complex.normSq (qaoaState n p J γ β σ) * hamiltonian n J σ) / + (n : ℝ) := by + unfold energyDensity + rw [cost_eq_diagonal] + simp only [Matrix.mulVec_diagonal, Complex.re_sum] + congr 1 + apply Finset.sum_congr rfl + intro σ _ + simp only [Complex.mul_re, Complex.star_def, Complex.conj_re, Complex.conj_im, + Complex.ofReal_re, Complex.ofReal_im, Complex.mul_im, zero_mul, + add_zero, sub_zero, Complex.normSq_apply] + ring + +theorem hamiltonian_le_groundMaximum (n : ℕ) (J : Disorder n) + (σ : Configuration n) : hamiltonian n J σ ≤ groundMaximum n J := by + exact le_csSup (Set.finite_range _).bddAbove ⟨σ, rfl⟩ + + +theorem energyDensity_le_groundMaximum (n p : ℕ) (J : Disorder n) + (γ β : Fin p → ℝ) : + energyDensity n p J γ β ≤ groundMaximum n J / (n : ℝ) := by + rw [energyDensity_eq] + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg n) + calc + ∑ σ, Complex.normSq (qaoaState n p J γ β σ) * hamiltonian n J σ ≤ + ∑ σ, Complex.normSq (qaoaState n p J γ β σ) * groundMaximum n J := + Finset.sum_le_sum fun σ _ => mul_le_mul_of_nonneg_left + (hamiltonian_le_groundMaximum n J σ) (Complex.normSq_nonneg _) + _ = groundMaximum n J := by + rw [← Finset.sum_mul] + change mass (qaoaState n p J γ β) * groundMaximum n J = _ + rw [qaoaState_mass, one_mul] + +@[simp] theorem spin_abs {n : ℕ} (σ : Configuration n) (i : Fin n) : + |spin σ i| = 1 := by + unfold spin + split <;> norm_num + + +def couplingEnvelope (n : ℕ) (J : Disorder n) : ℝ := + (Real.sqrt (n : ℝ))⁻¹ * ∑ e, |J e| + +theorem couplingEnvelope_nonneg (n : ℕ) (J : Disorder n) : + 0 ≤ couplingEnvelope n J := + mul_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg _)) + (Finset.sum_nonneg fun _ _ => abs_nonneg _) + +theorem hamiltonian_abs_le (n : ℕ) (J : Disorder n) (σ : Configuration n) : + |hamiltonian n J σ| ≤ couplingEnvelope n J := by + unfold hamiltonian couplingEnvelope + rw [abs_mul, abs_of_nonneg (inv_nonneg.mpr (Real.sqrt_nonneg _))] + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr (Real.sqrt_nonneg _)) + calc + |∑ e : Edge n, J e * spin σ e.1.1 * spin σ e.1.2| ≤ + ∑ e : Edge n, |J e * spin σ e.1.1 * spin σ e.1.2| := + Finset.abs_sum_le_sum_abs _ _ + _ = ∑ e : Edge n, |J e| := by simp [abs_mul] + +theorem groundMaximum_abs_le (n : ℕ) (J : Disorder n) : + |groundMaximum n J| ≤ couplingEnvelope n J := by + apply abs_le.mpr + constructor + · have h := (abs_le.mp (hamiltonian_abs_le n J (fun _ => false))).1 + exact h.trans (hamiltonian_le_groundMaximum n J _) + · apply csSup_le (Set.range_nonempty _) + rintro _ ⟨σ, rfl⟩ + exact (abs_le.mp (hamiltonian_abs_le n J σ)).2 + +theorem energyDensity_abs_le (n p : ℕ) (J : Disorder n) + (γ β : Fin p → ℝ) : + |energyDensity n p J γ β| ≤ couplingEnvelope n J / (n : ℝ) := by + have hn : 0 ≤ (n : ℝ) := Nat.cast_nonneg n + rw [energyDensity_eq, abs_div, abs_of_nonneg hn] + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg n) + calc + |∑ σ, Complex.normSq (qaoaState n p J γ β σ) * hamiltonian n J σ| ≤ + ∑ σ, |Complex.normSq (qaoaState n p J γ β σ) * hamiltonian n J σ| := + Finset.abs_sum_le_sum_abs _ _ + _ = ∑ σ, Complex.normSq (qaoaState n p J γ β σ) * |hamiltonian n J σ| := by + simp only [abs_mul, abs_of_nonneg (Complex.normSq_nonneg _)] + _ ≤ ∑ σ, Complex.normSq (qaoaState n p J γ β σ) * couplingEnvelope n J := + Finset.sum_le_sum fun σ _ => mul_le_mul_of_nonneg_left + (hamiltonian_abs_le n J σ) (Complex.normSq_nonneg _) + _ = couplingEnvelope n J := by + rw [← Finset.sum_mul] + change mass (qaoaState n p J γ β) * couplingEnvelope n J = _ + rw [qaoaState_mass, one_mul] + + +theorem hamiltonian_continuous (n : ℕ) (σ : Configuration n) : + Continuous (fun J => hamiltonian n J σ) := by + unfold hamiltonian + fun_prop + +theorem cost_evolution_continuous (n : ℕ) (t : ℝ) : + Continuous (fun J => evolution t (cost n J)) := by + simp_rw [evolution, cost_eq_diagonal, ← Matrix.diagonal_smul, Matrix.exp_diagonal] + apply Continuous.matrix_diagonal + apply NormedSpace.exp_continuous.comp + apply continuous_pi + intro σ + exact continuous_const.mul (Complex.continuous_ofReal.comp (hamiltonian_continuous n σ)) + +theorem circuit_continuous (n p : ℕ) (γ β : Fin p → ℝ) : + Continuous (fun J : Disorder n => circuit J p γ β) := by + induction p with + | zero => exact continuous_const + | succ p ih => + exact (continuous_const.matrix_mul (cost_evolution_continuous n _)).matrix_mul + (ih _ _) + +theorem qaoaState_continuous (n p : ℕ) (γ β : Fin p → ℝ) : + Continuous (fun J => qaoaState n p J γ β) := + (circuit_continuous n p γ β).matrix_mulVec continuous_const + +theorem energyDensity_continuous (n p : ℕ) (γ β : Fin p → ℝ) : + Continuous (fun J => energyDensity n p J γ β) := by + simp_rw [energyDensity_eq] + apply Continuous.div_const + apply continuous_finsetSum + intro σ _ + exact (Complex.continuous_normSq.comp + ((continuous_apply σ).comp (qaoaState_continuous n p γ β))).mul + (hamiltonian_continuous n σ) + +theorem groundMaximum_continuous (n : ℕ) : Continuous (groundMaximum n) := by + have h (J : Disorder n) : groundMaximum n J = + Finset.univ.sup' Finset.univ_nonempty (hamiltonian n J) := by + simp [groundMaximum, Finset.sup'_eq_csSup_image] + simp_rw [show groundMaximum n = fun J => + Finset.univ.sup' Finset.univ_nonempty (hamiltonian n J) from funext h] + exact Continuous.finset_sup'_apply Finset.univ_nonempty fun σ _ => + hamiltonian_continuous n σ + +theorem coupling_integrable (n : ℕ) (e : Edge n) : + Integrable (fun J : Disorder n => J e) (disorderLaw n) := by + change Integrable (fun J : Disorder n => id (J e)) + (Measure.pi fun _ : Edge n => gaussianReal 0 1) + apply integrable_comp_eval + exact MemLp.integrable (by norm_num) (memLp_id_gaussianReal (μ := 0) (v := 1) 1) + +theorem couplingEnvelope_integrable (n : ℕ) : + Integrable (couplingEnvelope n) (disorderLaw n) := by + apply Integrable.const_mul + exact integrable_finsetSum _ fun e _ => (coupling_integrable n e).abs + +theorem groundMaximum_integrable (n : ℕ) : + Integrable (groundMaximum n) (disorderLaw n) := by + apply (couplingEnvelope_integrable n).mono' + (groundMaximum_continuous n).aestronglyMeasurable + exact Filter.Eventually.of_forall fun J => by + simpa only [Real.norm_eq_abs] using groundMaximum_abs_le n J + +theorem energyDensity_integrable (n p : ℕ) (γ β : Fin p → ℝ) : + Integrable (fun J => energyDensity n p J γ β) (disorderLaw n) := by + apply ((couplingEnvelope_integrable n).div_const (n : ℝ)).mono' + (energyDensity_continuous n p γ β).aestronglyMeasurable + exact Filter.Eventually.of_forall fun J => by + simpa only [Real.norm_eq_abs] using energyDensity_abs_le n p J γ β + + + +theorem expectedEnergy_le_expectedGround (n p : ℕ) (γ β : Fin p → ℝ) : + expectedEnergy n p γ β ≤ expectedGround n := by + unfold expectedEnergy expectedGround + rw [← integral_div] + exact integral_mono (energyDensity_integrable n p γ β) + ((groundMaximum_integrable n).div_const _) fun J => + energyDensity_le_groundMaximum n p J γ β + + +@[simp] theorem circuit_pad {n : ℕ} (J : Disorder n) (p : ℕ) + (γ β : Fin p → ℝ) : + circuit J (p + 1) (Fin.snoc γ 0) (Fin.snoc β 0) = circuit J p γ β := by + simp [circuit] + +@[simp] theorem expectedEnergy_pad (n p : ℕ) (γ β : Fin p → ℝ) : + expectedEnergy n (p + 1) (Fin.snoc γ 0) (Fin.snoc β 0) = + expectedEnergy n p γ β := by + simp [expectedEnergy, energyDensity, qaoaState] + +@[simp] theorem value_pad (p : ℕ) (γ β : Fin p → ℝ) : + value (p + 1) (Fin.snoc γ 0) (Fin.snoc β 0) = value p γ β := by + simp [value] + + +@[simp] theorem spin_sq {n : ℕ} (σ : Configuration n) (i : Fin n) : spin σ i ^ 2 = 1 := by + simp only [spin] + split <;> norm_num + + + +theorem sum_symmetric_pairs (n : ℕ) (F : Fin n → Fin n → ℝ) + (hF : ∀ i j, F i j = F j i) : + (∑ i, ∑ j, F i j) = (∑ i, F i i) + 2 * ∑ e : Edge n, F e.1.1 e.1.2 := by + classical + have he (i j : Fin n) : F i j = + (if i = j then F i i else 0) + + (if i < j then F i j else 0) + (if j < i then F i j else 0) := by + rcases lt_trichotomy i j with hij | heq | hji + · simp [hij, hij.ne, not_lt_of_ge hij.le] + · subst j; simp + · simp [hji, hji.ne', not_lt_of_ge hji.le] + have hedge : (∑ e : Edge n, F e.1.1 e.1.2) = ∑ i, ∑ j, if i < j then F i j else 0 := by + rw [← Finset.sum_subtype (Finset.univ.filter (fun e : Fin n × Fin n => e.1 < e.2)) + (by simp) (fun e => F e.1 e.2), Finset.sum_filter, Fintype.sum_prod_type] + have hsym : (∑ i : Fin n, ∑ j : Fin n, if j < i then F i j else 0) = + ∑ i : Fin n, ∑ j : Fin n, if i < j then F i j else 0 := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + rw [hF j i] + calc + _ = ∑ i, ∑ j, ((if i = j then F i i else 0) + + (if i < j then F i j else 0) + (if j < i then F i j else 0)) := by + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + exact he i j + _ = _ := by + simp only [Finset.sum_add_distrib] + rw [hsym, ← hedge] + simp + ring + + +def skCoeff (n : ℕ) (σ : Configuration n) (e : Edge n) : ℝ := + (Real.sqrt (n : ℝ))⁻¹ * spin σ e.1.1 * spin σ e.1.2 + +theorem hamiltonian_eq_coeff (n : ℕ) (J : Disorder n) (σ : Configuration n) : + hamiltonian n J σ = ∑ e, skCoeff n σ e * J e := by + simp only [hamiltonian, skCoeff, Finset.mul_sum] + apply Finset.sum_congr rfl + intro e _ + ring + + +def overlapSum {n : ℕ} (σ τ : Configuration n) : ℝ := ∑ i, spin σ i * spin τ i + + +theorem edge_overlap (n : ℕ) (σ τ : Configuration n) : + (2 : ℝ) * (∑ e : Edge n, (spin σ e.1.1 * spin τ e.1.1) * + (spin σ e.1.2 * spin τ e.1.2)) = overlapSum σ τ ^ 2 - (n : ℝ) := by + have h := sum_symmetric_pairs n + (fun i j => (spin σ i * spin τ i) * (spin σ j * spin τ j)) + (fun i j => mul_comm _ _) + have hdiag : (∑ i, (spin σ i * spin τ i) * (spin σ i * spin τ i)) = (n : ℝ) := by + simp_rw [← sq, mul_pow, spin_sq, one_mul] + simp + have htotal : (∑ i, ∑ j, (spin σ i * spin τ i) * (spin σ j * spin τ j)) = + overlapSum σ τ ^ 2 := by + rw [sq, overlapSum, Finset.sum_mul] + apply Finset.sum_congr rfl + intro i _ + rw [Finset.mul_sum] + rw [hdiag, htotal] at h + linarith + +@[simp] theorem overlapSum_self {n : ℕ} (σ : Configuration n) : overlapSum σ σ = (n : ℝ) := by + simp [overlapSum, ← sq] + + +theorem coeff_covariance {n : ℕ} (hn : 0 < n) (σ τ : Configuration n) : + (∑ e, skCoeff n σ e * skCoeff n τ e) = + (overlapSum σ τ ^ 2 - (n : ℝ)) / (2 * (n : ℝ)) := by + have hnr : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have he : (∑ e, skCoeff n σ e * skCoeff n τ e) = + (Real.sqrt (n : ℝ))⁻¹ ^ 2 * + ∑ e : Edge n, (spin σ e.1.1 * spin τ e.1.1) * (spin σ e.1.2 * spin τ e.1.2) := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro e _ + unfold skCoeff + ring + rw [he, inv_pow, Real.sq_sqrt (Nat.cast_nonneg n)] + have ho := edge_overlap n σ τ + field_simp + simp only [mul_assoc] at ho ⊢ + nlinarith + + +theorem coeff_increment {n : ℕ} (hn : 0 < n) (σ τ : Configuration n) : + (∑ e, (skCoeff n σ e - skCoeff n τ e) ^ 2) = + (n : ℝ) - overlapSum σ τ ^ 2 / (n : ℝ) := by + have he : (∑ e, (skCoeff n σ e - skCoeff n τ e) ^ 2) = + (∑ e, skCoeff n σ e * skCoeff n σ e) + (∑ e, skCoeff n τ e * skCoeff n τ e) - + 2 * (∑ e, skCoeff n σ e * skCoeff n τ e) := by + simp_rw [Finset.mul_sum, ← Finset.sum_add_distrib, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro e _ + ring + rw [he, coeff_covariance hn, coeff_covariance hn, coeff_covariance hn, overlapSum_self, overlapSum_self] + have hnr : (n : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp + ring + +end SKQAOA + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Tensor.lean b/lean/OAI/Probability/ParisiFinite/Tensor.lean new file mode 100644 index 0000000000000000000000000000000000000000..69443240f533cabc88cfc22a681bc26dddb9f67d --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Tensor.lean @@ -0,0 +1,696 @@ +import Mathlib +import OAI.Probability.ParisiFinite.MixedMatrixOne + +namespace OAI + +/-! Tensor. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open scoped InnerProductSpace BigOperators +open ContinuousLinearMap +namespace TwoHalfTree +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + + + +def tensor (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : EuclideanSpace ℂ (ι×κ) := + WithLp.toLp 2 (fun ij => x ij.1*y ij.2) + +omit [Fintype ι] [Fintype κ] in +@[simp] theorem tensor_apply (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) (i : ι) (j : κ) : + tensor x y (i,j)=x i*y j := rfl + +theorem inner_tensor (x u : EuclideanSpace ℂ ι) (y v : EuclideanSpace ℂ κ) : + ⟪tensor x y,tensor u v⟫_ℂ=⟪x,u⟫_ℂ*⟪y,v⟫_ℂ := by + simp only [PiLp.inner_apply,RCLike.inner_apply,tensor_apply,Fintype.sum_prod_type,map_mul] + rw [Finset.sum_mul_sum] + apply Finset.sum_congr rfl + intro i hi + apply Finset.sum_congr rfl + intro j hj + ring + +def right (Ω : EuclideanSpace ℂ κ) : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ (ι×κ) where + toFun x := tensor x Ω + map_add' x y := by ext ⟨i,j⟩; simp [tensor,add_mul] + map_smul' c x := by ext ⟨i,j⟩; simp [tensor,mul_assoc] + + +def appendVacuum (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) : + EuclideanSpace ℂ ι →ₗᵢ[ℂ] EuclideanSpace ℂ (ι×κ) where + toLinearMap := right Ω + norm_map' x := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ)] + change Real.sqrt (⟪tensor x Ω,tensor x Ω⟫_ℂ).re=‖x‖ + have he : ⟪Ω,Ω⟫_ℂ=(1:ℂ) := by + rw [inner_self_eq_norm_sq_to_K Ω,hΩ] + norm_num + rw [inner_tensor,he,mul_one] + exact (norm_eq_sqrt_re_inner (𝕜 := ℂ) x).symm + +@[simp] theorem appendVacuum_apply (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) (x : EuclideanSpace ℂ ι) : + appendVacuum Ω hΩ x=tensor x Ω := rfl + +def contract (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) : + EuclideanSpace ℂ (ι×κ) →L[ℂ] EuclideanSpace ℂ ι := + (appendVacuum Ω hΩ).toContinuousLinearMap.adjoint + +def projection (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) : + EuclideanSpace ℂ (ι×κ) →L[ℂ] EuclideanSpace ℂ (ι×κ) := + (appendVacuum (ι := ι) Ω hΩ).toContinuousLinearMap.comp (contract Ω hΩ) + +@[simp] theorem projection_apply (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) + (f : EuclideanSpace ℂ (ι×κ)) : + projection Ω hΩ f=tensor (contract Ω hΩ f) Ω := rfl + +theorem inner_contract (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) + (x : EuclideanSpace ℂ ι) (f : EuclideanSpace ℂ (ι×κ)) : + ⟪x,contract Ω hΩ f⟫_ℂ=⟪tensor x Ω,f⟫_ℂ := by + exact ContinuousLinearMap.adjoint_inner_right _ _ _ + +theorem contract_tensor_general (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) + (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : + contract Ω hΩ (tensor x y)=⟪Ω,y⟫_ℂ • x := by + apply ext_inner_left ℂ + intro z + rw [inner_contract,inner_tensor,inner_smul_right] + ring + +theorem contract_norm_le (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) + (f : EuclideanSpace ℂ (ι×κ)) : ‖contract Ω hΩ f‖≤‖f‖ := by + calc + _ ≤ ‖(appendVacuum (ι := ι) Ω hΩ).toContinuousLinearMap.adjoint‖*‖f‖ := + ContinuousLinearMap.le_opNorm _ _ + _ ≤ 1*‖f‖ := by + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + rw [ContinuousLinearMap.adjoint.norm_map] + exact (appendVacuum (ι := ι) Ω hΩ).norm_toContinuousLinearMap_le + _ = _ := one_mul _ + +theorem contract_tensor (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) + (x : EuclideanSpace ℂ ι) : contract Ω hΩ (tensor x Ω)=x := by + apply ext_inner_left ℂ + intro y + rw [inner_contract,inner_tensor,inner_self_eq_norm_sq_to_K,hΩ] + norm_num + +theorem projection_isStarProjection (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) : + IsStarProjection (projection (ι := ι) Ω hΩ) := by + constructor + · apply ContinuousLinearMap.ext + intro f + simp only [mul_apply_eq_comp,projection_apply,contract_tensor] + · change star ((appendVacuum (ι := ι) Ω hΩ).toContinuousLinearMap.comp + (appendVacuum (ι := ι) Ω hΩ).toContinuousLinearMap.adjoint)=_ + rw [star_eq_adjoint,adjoint_comp,adjoint_adjoint] + rfl + + +def swap : EuclideanSpace ℂ (ι×ι) ≃ₗᵢ[ℂ] EuclideanSpace ℂ (ι×ι) := + LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ (Equiv.prodComm ι ι) + +@[simp] theorem swap_apply (f : EuclideanSpace ℂ (ι×ι)) (i j : ι) : + swap f (i,j)=f (j,i) := rfl + +theorem swap_involutive : Function.Involutive (swap (ι := ι)) := by + intro f + ext ⟨i,j⟩ + rfl + +@[simp] theorem swap_tensor (x y : EuclideanSpace ℂ ι) : swap (tensor x y)=tensor y x := by + ext ⟨i,j⟩ + simp only [swap_apply,tensor_apply,mul_comm] + +theorem swap_selfadjoint (f g : EuclideanSpace ℂ (ι×ι)) : + ⟪f,swap g⟫_ℂ=⟪swap f,g⟫_ℂ := by + have h := (swap (ι := ι)).inner_map_map (swap f) g + simpa only [swap_involutive f] using h + + +theorem centered_cross (Ω : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) + (f : EuclideanSpace ℂ (ι×ι)) (hf : ⟪tensor Ω Ω,f⟫_ℂ=0) : + ⟪projection Ω hΩ f,swap (projection Ω hΩ f)⟫_ℂ=0 := by + rw [projection_apply,swap_tensor,inner_tensor,inner_contract,hf,mul_zero] + + + +theorem single_side_pairing (Ω : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) + (f : EuclideanSpace ℂ (ι×ι)) : + ⟪projection Ω hΩ f,swap f⟫_ℂ=⟪tensor Ω (contract Ω hΩ f),f⟫_ℂ := by + rw [swap_selfadjoint,projection_apply,swap_tensor] + + + +theorem edge_decomposition (Ω : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) + (f : EuclideanSpace ℂ (ι×ι)) (hf : ⟪tensor Ω Ω,f⟫_ℂ=0) : + |(⟪f,swap f⟫_ℂ).re-2*(⟪tensor Ω (contract Ω hΩ f),f⟫_ℂ).re|≤ + ‖f-projection Ω hΩ f‖^2 := by + have h := EdgeProjection.real_decomposition (H := EuclideanSpace ℂ (ι×ι)) + (swap (ι := ι)) (swap_involutive (ι := ι)) (projection (ι := ι) Ω hΩ) + (projection_isStarProjection (ι := ι) Ω hΩ) f (centered_cross Ω hΩ f hf) + simpa only [single_side_pairing] using h + +end TwoHalfTree + + + +open scoped InnerProductSpace BigOperators +namespace TwoHalfTree +variable {ι κ ν : Type*} [Fintype ι] [Fintype κ] [Fintype ν] + +def row (f : EuclideanSpace ℂ (ι×κ)) (i : ι) : EuclideanSpace ℂ κ := + WithLp.toLp 2 (fun j => f (i,j)) + +omit [Fintype ι] [Fintype κ] in +@[simp] theorem row_apply (f : EuclideanSpace ℂ (ι×κ)) (i : ι) (j : κ) : row f i j=f (i,j) := rfl + +def rightMapLinear (T : EuclideanSpace ℂ κ →ₗ[ℂ] EuclideanSpace ℂ ν) : + EuclideanSpace ℂ (ι×κ) →ₗ[ℂ] EuclideanSpace ℂ (ι×ν) where + toFun f := WithLp.toLp 2 (fun ij => T (row f ij.1) ij.2) + map_add' f g := by + have hr (i : ι) : row (f+g) i=row f i+row g i := rfl + ext ⟨i,j⟩ + simp only [hr,map_add,PiLp.add_apply] + map_smul' c f := by + have hr (i : ι) : row (c • f) i=c • row f i := rfl + ext ⟨i,j⟩ + simp only [hr,map_smul,PiLp.smul_apply,RingHom.id_apply] + +theorem rightMap_inner (T : EuclideanSpace ℂ κ →ₗᵢ[ℂ] EuclideanSpace ℂ ν) + (f g : EuclideanSpace ℂ (ι×κ)) : + ⟪rightMapLinear T.toLinearMap f,rightMapLinear T.toLinearMap g⟫_ℂ=⟪f,g⟫_ℂ := by + change (∑ij : ι×ν, ⟪T (row f ij.1) ij.2,T (row g ij.1) ij.2⟫_ℂ)= + ∑ij : ι×κ,⟪f ij,g ij⟫_ℂ + rw [Fintype.sum_prod_type,Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro i hi + exact T.inner_map_map (row f i) (row g i) + + + +def rightMap (T : EuclideanSpace ℂ κ →ₗᵢ[ℂ] EuclideanSpace ℂ ν) : + EuclideanSpace ℂ (ι×κ) →ₗᵢ[ℂ] EuclideanSpace ℂ (ι×ν) where + toLinearMap := rightMapLinear T.toLinearMap + norm_map' f := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),rightMap_inner] + exact (norm_eq_sqrt_re_inner (𝕜 := ℂ) f).symm + +@[simp] theorem rightMap_tensor (T : EuclideanSpace ℂ κ →ₗᵢ[ℂ] EuclideanSpace ℂ ν) + (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : + rightMap T (tensor x y)=tensor x (T y) := by + have hr (i : ι) : row (tensor x y) i=x i • y := by + ext j + rfl + ext ⟨i,j⟩ + change T (row (tensor x y) i) j=x i*T y j + rw [hr,map_smul] + rfl + + +theorem contract_rightMap (T : EuclideanSpace ℂ κ →ₗᵢ[ℂ] EuclideanSpace ℂ ν) + (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) (Ψ : EuclideanSpace ℂ ν) (hΨ : ‖Ψ‖=1) + (hT : T Ω=Ψ) (f : EuclideanSpace ℂ (ι×κ)) : + contract Ψ hΨ (rightMap T f)=contract Ω hΩ f := by + apply ext_inner_left ℂ + intro x + rw [inner_contract,inner_contract,←hT,←rightMap_tensor] + exact (rightMap (ι := ι) T).inner_map_map _ _ + +theorem projection_rightMap (T : EuclideanSpace ℂ κ →ₗᵢ[ℂ] EuclideanSpace ℂ ν) + (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) (Ψ : EuclideanSpace ℂ ν) (hΨ : ‖Ψ‖=1) + (hT : T Ω=Ψ) (f : EuclideanSpace ℂ (ι×κ)) : + projection Ψ hΨ (rightMap T f)=rightMap T (projection Ω hΩ f) := by + rw [projection_apply,contract_rightMap T Ω hΩ Ψ hΨ hT,projection_apply,rightMap_tensor,hT] + +theorem nonvacuum_rightMap_norm (T : EuclideanSpace ℂ κ →ₗᵢ[ℂ] EuclideanSpace ℂ ν) + (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) (Ψ : EuclideanSpace ℂ ν) (hΨ : ‖Ψ‖=1) + (hT : T Ω=Ψ) (f : EuclideanSpace ℂ (ι×κ)) : + ‖rightMap T f-projection Ψ hΨ (rightMap T f)‖=‖f-projection Ω hΩ f‖ := by + rw [projection_rightMap T Ω hΩ Ψ hΨ hT,←map_sub] + exact (rightMap T).norm_map _ + +end TwoHalfTree + + + +open scoped InnerProductSpace Topology BigOperators +open ContinuousLinearMap Filter +namespace FiniteTensor +variable {ι : Type*} [Fintype ι] + + +def splitChildIndex (D : ℕ) : (Fin (D+1) → ι) ≃ ((Fin D → ι)×ι) := + (Fin.consEquiv (fun _ : Fin (D+1) => ι)).symm.trans (Equiv.prodComm _ _) + +def splitChild (D : ℕ) : EuclideanSpace ℂ (Fin (D+1) → ι) ≃ₗᵢ[ℂ] + EuclideanSpace ℂ ((Fin D → ι)×ι) := + LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ (splitChildIndex D) + +@[simp] theorem splitChild_apply (D : ℕ) (f : EuclideanSpace ℂ (Fin (D+1) → ι)) + (σ : Fin D → ι) (i : ι) : splitChild D f (σ,i)=f (Fin.cons i σ) := rfl + +theorem splitChild_power (D : ℕ) (v : EuclideanSpace ℂ ι) : + splitChild D (power (D+1) v)=TwoHalfTree.tensor (power D v) v := by + ext ⟨σ,i⟩ + change (∏j : Fin (D+1),v ((Fin.cons i σ : Fin (D+1) → ι) j))=(∏j : Fin D,v (σ j))*v i + rw [Fin.prod_univ_succ] + exact mul_comm _ _ + + + +def deleteChild (D : ℕ) (Ω : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) : + EuclideanSpace ℂ (Fin (D+1) → ι) →L[ℂ] EuclideanSpace ℂ (Fin D → ι) := + (TwoHalfTree.contract Ω hΩ).comp (splitChild D).toContinuousLinearEquiv.toContinuousLinearMap + +theorem deleteChild_power (D : ℕ) (Ω v : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) : + deleteChild D Ω hΩ (power (D+1) v)=⟪Ω,v⟫_ℂ • power D v := by + change TwoHalfTree.contract Ω hΩ (splitChild D (power (D+1) v))=_ + rw [splitChild_power,TwoHalfTree.contract_tensor_general] + +theorem deleteChild_norm_le (D : ℕ) (Ω : EuclideanSpace ℂ ι) (hΩ : ‖Ω‖=1) + (f : EuclideanSpace ℂ (Fin (D+1) → ι)) : ‖deleteChild D Ω hΩ f‖≤‖f‖ := by + change ‖TwoHalfTree.contract Ω hΩ (splitChild D f)‖≤‖f‖ + exact (TwoHalfTree.contract_norm_le Ω hΩ _).trans_eq ((splitChild D).norm_map f) + +end FiniteTensor + +namespace TensorPackets +open SpinOperators +variable {H K : Type*} [NormedAddCommGroup H] [NormedAddCommGroup K] + [InnerProductSpace ℂ H] [InnerProductSpace ℂ K] + + +def liftMap (T : H →L[ℂ] K) : Double H →L[ℂ] Double K := + (PiLp.continuousLinearEquiv 2 ℂ (fun _ : Fin 2 => K)).symm.toContinuousLinearMap.comp + (ContinuousLinearMap.pi (fun i => T.comp (PiLp.proj 2 (fun _ : Fin 2 => H) i))) + +@[simp] theorem liftMap_apply (T : H →L[ℂ] K) (x : Double H) (i : Fin 2) : + liftMap T x i=T (x i) := by simp [liftMap,PiLp.proj_apply] + +theorem liftMap_term {κ : Type*} (T : H →L[ℂ] K) (s : List κ → H) (t : Term κ) : + liftMap T (term s t)=term (T ∘ s) t := by + classical + ext i + simp only [liftMap_apply,term_apply,Function.comp_apply] + split_ifs <;> simp only [map_smul,map_zero] + +theorem liftMap_packet {κ : Type*} (T : H →L[ℂ] K) (s : List κ → H) (ts : List (Term κ)) : + liftMap T (packet s ts)=packet (T ∘ s) ts := by + induction ts with + | nil => simp + | cons t ts ih => rw [packet_cons,map_add,liftMap_term,ih,packet_cons] + +end TensorPackets + + + +open scoped InnerProductSpace BigOperators +namespace TensorEmbedding +open Matrix +variable {ι κ ν : Type*} [Fintype ι] [Fintype κ] [Fintype ν] + [DecidableEq ι] [DecidableEq κ] [DecidableEq ν] + + + +def matrixPower (D : ℕ) (A : Matrix κ ι ℂ) : Matrix (Fin D → κ) (Fin D → ι) ℂ := + fun σ τ => ∏i,A (σ i) (τ i) + +omit [Fintype ι] [Fintype ν] [DecidableEq ι] [DecidableEq κ] [DecidableEq ν] in +theorem matrixPower_mul (D : ℕ) (A : Matrix ν κ ℂ) (B : Matrix κ ι ℂ) : + matrixPower D (A*B)=matrixPower D A*matrixPower D B := by + ext σ τ + simp only [matrixPower,Matrix.mul_apply] + rw [Fintype.prod_sum] + apply Finset.sum_congr rfl + intro v hv + exact Finset.prod_mul_distrib + +omit [Fintype ι] [Fintype κ] [DecidableEq ι] [DecidableEq κ] in +theorem matrixPower_adjoint (D : ℕ) (A : Matrix κ ι ℂ) : + matrixPower D A.conjTranspose=(matrixPower D A).conjTranspose := by + ext σ τ + simp only [matrixPower,conjTranspose_apply,star_prod] + +omit [Fintype ι] in +theorem matrixPower_one (D : ℕ) : matrixPower D (1 : Matrix ι ι ℂ)=1 := + FiniteTensor.matrixPower_one D + +def map (D : ℕ) (T : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ κ) : + EuclideanSpace ℂ (Fin D → ι) →ₗ[ℂ] EuclideanSpace ℂ (Fin D → κ) := + Matrix.toEuclideanLin (matrixPower D (Matrix.toEuclideanLin.symm T)) + +omit [Fintype ν] [DecidableEq ν] in +theorem map_comp (D : ℕ) (S : EuclideanSpace ℂ κ →ₗ[ℂ] EuclideanSpace ℂ ν) + (T : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ κ) : + map D (S.comp T)=(map D S).comp (map D T) := by + simp only [map,Matrix.toLpLin_symm_comp,matrixPower_mul,Matrix.toLpLin_mul_same] + +theorem map_id (D : ℕ) : map D (LinearMap.id : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ ι)=LinearMap.id := by + simp only [map,Matrix.toLpLin_symm_id,matrixPower_one,Matrix.toLpLin_one] + +theorem map_adjoint (D : ℕ) (T : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ κ) : + map D T.adjoint=(map D T).adjoint := by + have he : Matrix.toEuclideanLin.symm T.adjoint=(Matrix.toEuclideanLin.symm T).conjTranspose := by + apply Matrix.toEuclideanLin.injective + rw [Matrix.toEuclideanLin.apply_symm_apply,Matrix.toEuclideanLin_conjTranspose_eq_adjoint, + Matrix.toEuclideanLin.apply_symm_apply] + simp only [map,he,matrixPower_adjoint,Matrix.toEuclideanLin_conjTranspose_eq_adjoint] + +theorem map_inner (D : ℕ) (T : EuclideanSpace ℂ ι →ₗᵢ[ℂ] EuclideanSpace ℂ κ) + (x y : EuclideanSpace ℂ (Fin D → ι)) : + ⟪map D T.toLinearMap x,map D T.toLinearMap y⟫_ℂ=⟪x,y⟫_ℂ := by + have he : T.toLinearMap.adjoint.comp T.toLinearMap=LinearMap.id := by + apply LinearMap.ext + intro v + apply ext_inner_left ℂ + intro w + change ⟪w,T.toLinearMap.adjoint (T v)⟫_ℂ=⟪w,v⟫_ℂ + rw [LinearMap.adjoint_inner_right] + exact T.inner_map_map w v + have hm : (map D T.toLinearMap).adjoint.comp (map D T.toLinearMap)=LinearMap.id := by + rw [←map_adjoint,←map_comp,he,map_id] + rw [←LinearMap.adjoint_inner_right] + change ⟪x,((map D T.toLinearMap).adjoint.comp (map D T.toLinearMap)) y⟫_ℂ=_ + rw [hm] + rfl + +def isometry (D : ℕ) (T : EuclideanSpace ℂ ι →ₗᵢ[ℂ] EuclideanSpace ℂ κ) : + EuclideanSpace ℂ (Fin D → ι) →ₗᵢ[ℂ] EuclideanSpace ℂ (Fin D → κ) where + toLinearMap := map D T.toLinearMap + norm_map' x := by + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ),map_inner] + exact (norm_eq_sqrt_re_inner (𝕜 := ℂ) x).symm + +omit [Fintype κ] [DecidableEq κ] in +theorem map_power (D : ℕ) (T : EuclideanSpace ℂ ι →ₗ[ℂ] EuclideanSpace ℂ κ) + (v : EuclideanSpace ℂ ι) : + map D T (FiniteTensor.power D v)=FiniteTensor.power D (T v) := by + let A := Matrix.toEuclideanLin.symm T + have hT : T=Matrix.toEuclideanLin A := (Matrix.toEuclideanLin.apply_symm_apply T).symm + rw [hT] + simp only [map,Matrix.toEuclideanLin.symm_apply_apply] + ext σ + change (∑τ : Fin D → ι,(∏i,A (σ i) (τ i))*(∏i,v (τ i)))=∏i,∑j,A (σ i) j*v j + simp_rw [←Finset.prod_mul_distrib] + exact (Fintype.prod_sum (fun i j => A (σ i) j*v j)).symm + +@[simp] theorem isometry_power (D : ℕ) (T : EuclideanSpace ℂ ι →ₗᵢ[ℂ] EuclideanSpace ℂ κ) + (v : EuclideanSpace ℂ ι) : + isometry D T (FiniteTensor.power D v)=FiniteTensor.power D (T v) := + map_power D T.toLinearMap v + +end TensorEmbedding + + + +open scoped InnerProductSpace BigOperators +open ContinuousLinearMap +namespace TensorPackets +open SpinOperators +variable {H K : Type*} [NormedAddCommGroup H] [NormedAddCommGroup K] + [InnerProductSpace ℂ H] [InnerProductSpace ℂ K] + +def liftIsometry (T : H →ₗᵢ[ℂ] K) : Double H →ₗᵢ[ℂ] Double K where + toLinearMap := (liftMap T.toContinuousLinearMap).toLinearMap + norm_map' x := by + have he : ⟪liftMap T.toContinuousLinearMap x,liftMap T.toContinuousLinearMap x⟫_ℂ=⟪x,x⟫_ℂ := by + simp only [PiLp.inner_apply,liftMap_apply,LinearIsometry.coe_toContinuousLinearMap, + T.inner_map_map] + rw [norm_eq_sqrt_re_inner (𝕜 := ℂ)] + change Real.sqrt (⟪liftMap T.toContinuousLinearMap x,liftMap T.toContinuousLinearMap x⟫_ℂ).re=‖x‖ + rw [he] + exact (norm_eq_sqrt_re_inner (𝕜 := ℂ) x).symm + +@[simp] theorem liftIsometry_apply (T : H →ₗᵢ[ℂ] K) (x : Double H) (i : Fin 2) : + liftIsometry T x i=T (x i) := by + exact liftMap_apply T.toContinuousLinearMap x i + +theorem liftIsometry_plus (T : H →ₗᵢ[ℂ] K) (v : H) : + liftIsometry T (PointedTree.plusEmbedding v)=PointedTree.plusEmbedding (T v) := by + ext i + simp only [liftIsometry_apply,PointedTree.plusEmbedding_apply,map_smul] + +theorem liftIsometry_act (T : H →ₗᵢ[ℂ] K) (A : Matrix (Fin 2) (Fin 2) ℂ) (v : Double H) : + liftIsometry T (act A v)=act A (liftIsometry T v) := by + ext i + simp only [liftIsometry_apply,act_apply,map_sum,map_smul] + +def scalarVac (Ω : H) (hΩ : ‖Ω‖=1) : ℂ →ₗᵢ[ℂ] H where + toFun c := c • Ω + map_add' _ _ := add_smul _ _ _ + map_smul' _ _ := (mul_smul _ _ _).trans rfl + norm_map' c := by + change ‖c • Ω‖=‖c‖ + rw [norm_smul,hΩ,mul_one] + +theorem liftScalarVac_plus (Ω : H) (hΩ : ‖Ω‖=1) : + liftIsometry (scalarVac Ω hΩ) PointedTree.plus=PointedTree.plusEmbedding Ω := by + ext i + rw [liftIsometry_apply] + rfl + +end TensorPackets + +namespace FiniteTree +open TensorPackets SpinOperators + + +def pad (D : ℕ) : (h : ℕ) → Space D h →ₗᵢ[ℂ] Space D (h+1) + | 0 => (split D 1).symm.toLinearIsometry.comp + (liftIsometry (scalarVac (FiniteTensor.power D (vac D 0)) + (norm_power_of_norm_one D _ (norm_vac D 0)))) + | h+1 => (split D (h+2)).symm.toLinearIsometry.comp + ((liftIsometry (TensorEmbedding.isometry D (pad D h))).comp (split D (h+1)).toLinearIsometry) + +@[simp] theorem split_pad_zero (D : ℕ) (x : Space D 0) : + split D 1 (pad D 0 x)=liftIsometry (scalarVac (FiniteTensor.power D (vac D 0)) + (norm_power_of_norm_one D _ (norm_vac D 0))) x := by + change split D 1 ((split D 1).symm _)=_ + exact (split D 1).apply_symm_apply _ + +@[simp] theorem split_pad_succ (D h : ℕ) (x : Space D (h+1)) : + split D (h+2) (pad D (h+1) x)= + liftIsometry (TensorEmbedding.isometry D (pad D h)) (split D (h+1) x) := by + change split D (h+2) ((split D (h+2)).symm _)=_ + exact (split D (h+2)).apply_symm_apply _ + +@[simp] theorem pad_vac (D h : ℕ) : pad D h (vac D h)=vac D (h+1) := by + induction h with + | zero => + apply (split D 1).injective + rw [split_pad_zero] + change liftIsometry _ PointedTree.plus=_ + rw [liftScalarVac_plus] + exact ((split D 1).apply_symm_apply _).symm + | succ h ih => + apply (split D (h+2)).injective + rw [split_pad_succ] + have hv (k : ℕ) : split D (k+1) (vac D (k+1))= + PointedTree.plusEmbedding (FiniteTensor.power D (vac D k)) := + (split D (k+1)).apply_symm_apply _ + rw [hv h,hv (h+1),liftIsometry_plus,TensorEmbedding.isometry_power,ih] + +theorem pad_root (D h : ℕ) (A : Matrix (Fin 2) (Fin 2) ℂ) (x : Space D h) : + pad D h (root D h A x)=root D (h+1) A (pad D h x) := by + cases h with + | zero => + apply (split D 1).injective + rw [split_pad_zero,split_root,split_pad_zero] + exact liftIsometry_act _ A x + | succ h => + apply (split D (h+2)).injective + rw [split_pad_succ,split_root,split_root,split_pad_succ,liftIsometry_act] + +end FiniteTree + + + +namespace OperatorIntertwine +open ContinuousLinearMap +variable {H K : Type*} [NormedAddCommGroup H] [NormedAddCommGroup K] + [InnerProductSpace ℂ H] [InnerProductSpace ℂ K] [CompleteSpace H] [CompleteSpace K] + +omit [CompleteSpace H] [CompleteSpace K] in +theorem power (T : H →L[ℂ] K) (A : H →L[ℂ] H) (B : K →L[ℂ] K) + (h : ∀x,T (A x)=B (T x)) (n : ℕ) (x : H) : T ((A^n) x)=(B^n) (T x) := by + induction n with + | zero => rfl + | succ n ih => + rw [pow_succ',pow_succ'] + change T (A ((A^n) x))=B ((B^n) (T x)) + rw [h,ih] + + + +theorem exponential (T : H →L[ℂ] K) (A : H →L[ℂ] H) (B : K →L[ℂ] K) + (h : ∀x,T (A x)=B (T x)) (x : H) : + T (NormedSpace.exp A x)=NormedSpace.exp B (T x) := by + have hl := T.hasSum ((ContinuousLinearMap.apply ℂ H x).hasSum + (NormedSpace.exp_series_hasSum_exp' (𝕂 := ℂ) A)) + have hr := (ContinuousLinearMap.apply ℂ K (T x)).hasSum + (NormedSpace.exp_series_hasSum_exp' (𝕂 := ℂ) B) + have hh (n : ℕ) : T (((n.factorial:ℂ)⁻¹ • A^n) x)= + (((n.factorial:ℂ)⁻¹ • B^n) (T x)) := by + simp only [smul_apply,map_smul,power T A B h] + simp only [ContinuousLinearMap.apply_apply] at hl hr + simp_rw [hh] at hl + exact hl.unique hr + + + +theorem adjoint (T : H →L[ℂ] K) (A : H →L[ℂ] H) (B : K →L[ℂ] K) + (hA : A ∈ unitary _) (hB : B ∈ unitary _) (h : ∀x,T (A x)=B (T x)) (x : H) : + T (star A x)=star B (T x) := by + have ha : A (star A x)=x := by + change (A*star A) x=x + rw [(Unitary.mem_iff.mp hA).2] + rfl + have hh := congrArg (fun y => star B y) (h (star A x)) + rw [ha] at hh + have hb : star B (B (T (star A x)))=T (star A x) := by + change (star B*B) (T (star A x))=_ + rw [(Unitary.mem_iff.mp hB).1] + rfl + exact (hh.trans hb).symm + +end OperatorIntertwine + + + +namespace TensorEmbedding +variable {ι κ : Type*} [Fintype ι] [Fintype κ] [DecidableEq ι] [DecidableEq κ] + + + +theorem map_operator (D : ℕ) (A : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) : + map D A.toLinearMap=(FiniteTensor.operatorPower D A).toLinearMap := by + have he : Matrix.toEuclideanLin.symm A.toLinearMap=(Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).symm A := by + apply Matrix.toEuclideanLin.injective + rw [Matrix.toEuclideanLin.apply_symm_apply,←Matrix.coe_toEuclideanCLM_eq_toEuclideanLin, + (Matrix.toEuclideanCLM (𝕜 := ℂ) (n := ι)).apply_symm_apply] + unfold map FiniteTensor.operatorPower + rw [he] + exact (Matrix.coe_toEuclideanCLM_eq_toEuclideanLin _).symm + +theorem isometry_intertwine (D : ℕ) + (T : EuclideanSpace ℂ ι →ₗᵢ[ℂ] EuclideanSpace ℂ κ) + (A : EuclideanSpace ℂ ι →L[ℂ] EuclideanSpace ℂ ι) + (B : EuclideanSpace ℂ κ →L[ℂ] EuclideanSpace ℂ κ) + (h : ∀x,T (A x)=B (T x)) (v : EuclideanSpace ℂ (Fin D → ι)) : + isometry D T (FiniteTensor.operatorPower D A v)= + FiniteTensor.operatorPower D B (isometry D T v) := by + have he : T.toLinearMap.comp A.toLinearMap=B.toLinearMap.comp T.toLinearMap := by + apply LinearMap.ext + exact h + have hh := congrArg (map D) he + rw [map_comp,map_comp,map_operator,map_operator] at hh + exact congrArg (fun L => L v) hh + +end TensorEmbedding + + + +namespace FiniteTree +open SpinOperators TensorPackets ContinuousLinearMap + +theorem pad_control (D h : ℕ) + (K : Fin 2 → Space D h →L[ℂ] Space D h) + (L : Fin 2 → Space D (h+1) →L[ℂ] Space D (h+1)) + (hKL : ∀i x,pad D h (K i x)=L i (pad D h x)) (v : Space D (h+1)) : + pad D (h+1) (control D h K v)=control D (h+1) L (pad D (h+1) v) := by + apply (split D (h+2)).injective + rw [split_pad_succ,split_control,split_control,split_pad_succ] + ext i : 1 + simp only [liftIsometry_apply,diagonal_apply] + exact TensorEmbedding.isometry_intertwine D (pad D h) (K i) (L i) (hKL i) _ + +namespace Even + +theorem pad_observable {D h : ℕ} (U : Even D h) (V : Even D (h+1)) + (hUV : ∀x,pad D h (U.op x)=V.op (pad D h x)) (x : Space D h) : + pad D h (U.observable x)=V.observable (pad D h x) := by + change pad D h (star U.op (root D h RootSpin.Z (U.op x)))= + star V.op (root D (h+1) RootSpin.Z (V.op (pad D h x))) + have hs (y : Space D h) : pad D h (star U.op y)=star V.op (pad D h y) := + OperatorIntertwine.adjoint (pad D h).toContinuousLinearMap U.op V.op U.unitary V.unitary hUV y + rw [hs,pad_root,hUV] + +theorem pad_exponential {D h : ℕ} (U : Even D h) (V : Even D (h+1)) + (hUV : ∀x,pad D h (U.op x)=V.op (pad D h x)) (t : ℝ) (x : Space D h) : + pad D h (U.exponential t x)=V.exponential t (pad D h x) := by + apply OperatorIntertwine.exponential (pad D h).toContinuousLinearMap + intro y + change pad D h ((Complex.I*(t:ℂ)) • U.observable y)= + (Complex.I*(t:ℂ)) • V.observable (pad D h y) + rw [map_smul,U.pad_observable V hUV] + +end Even + + + +theorem pad_ordinary (D : ℕ) (w : List PointedTree.Gate) (h : ℕ) + (hh : w.length≤h) (x : Space D h) : + pad D h ((ordinary D w h).op x)=(ordinary D w (h+1)).op (pad D h x) := by + induction w generalizing h with + | nil => rfl + | cons g w ih => + have hw : w.length≤h := by simpa only [List.length_cons] using (Nat.le_trans (Nat.le_succ w.length) hh) + cases g with + | mixer β => + change pad D h (root D h (RootSpin.R β) ((ordinary D w h).op x))= + root D (h+1) (RootSpin.R β) ((ordinary D w (h+1)).op (pad D h x)) + rw [pad_root,ih h hw] + | cost γ => + cases h with + | zero => simp only [List.length_cons] at hh; omega + | succ h => + have hlow : w.length≤h := by simpa only [List.length_cons,Nat.succ_le_succ_iff] using hh + change pad D (h+1) (control D h + (fun i => (ordinary D w h).exponential (if i=0 then -γ/Real.sqrt D else γ/Real.sqrt D)) + ((ordinary D w (h+1)).op x))= + control D (h+1) + (fun i => (ordinary D w (h+1)).exponential (if i=0 then -γ/Real.sqrt D else γ/Real.sqrt D)) + ((ordinary D w (h+2)).op (pad D (h+1) x)) + rw [pad_control D h _ _ (fun i y => Even.pad_exponential _ _ (ih h hlow) _ y),ih (h+1) hw] + + + +theorem pad_insertion (D : ℕ) (w : List PointedTree.Gate) (h : ℕ) (hh : w.length≤h) : + pad D h ((ordinary D w h).observable (vac D h))= + (ordinary D w (h+1)).observable (vac D (h+1)) := by + rw [Even.pad_observable _ _ (pad_ordinary D w h hh),pad_vac] + +end FiniteTree + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/TermNormSub.lean b/lean/OAI/Probability/ParisiFinite/TermNormSub.lean new file mode 100644 index 0000000000000000000000000000000000000000..7a3c7fff230823ad0e839627e485f4198a431a49 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/TermNormSub.lean @@ -0,0 +1,694 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SumLeCode +import OAI.Probability.ParisiFinite.Tensor + +namespace OAI + +/-! Term Norm Sub. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open scoped InnerProductSpace Topology BigOperators +open ContinuousLinearMap Filter +namespace TensorPackets +open SpinOperators +variable {κ : Type*} + +theorem term_norm_sub {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + (s u : List κ → H) (t : Term κ) : + ‖term s t-term u t‖=‖t.coeff‖*‖s t.history-u t.history‖ := by + classical + have he : term s t-term u t=t.coeff • PiLp.single 2 t.spin (s t.history-u t.history) := by + ext i + simp only [PiLp.sub_apply,term_apply,PiLp.smul_apply,PiLp.single_apply] + split_ifs <;> simp [smul_sub] + rw [he,norm_smul,PiLp.norm_single] + +theorem packet_norm_sub_limit + (Hn : ℕ → Type*) [∀n,NormedAddCommGroup (Hn n)] [∀n,InnerProductSpace ℂ (Hn n)] + (s u : ∀n,List κ → Hn n) + (hu : ∀w,Tendsto (fun n => ‖s n w-u n w‖) atTop (𝓝 0)) (ts : List (Term κ)) : + Tendsto (fun n => ‖packet (s n) ts-packet (u n) ts‖) atTop (𝓝 0) := by + induction ts with + | nil => simpa only [packet_nil,sub_self,norm_zero] using tendsto_const_nhds + | cons t ts ih => + have ht : Tendsto (fun n => ‖term (s n) t-term (u n) t‖) atTop (𝓝 0) := by + simpa only [term_norm_sub,mul_zero] using (hu t.history).const_mul ‖t.coeff‖ + apply squeeze_zero (fun _ => norm_nonneg _) _ (by simpa only [add_zero] using ht.add ih) + intro n + simp only [packet_cons] + rw [show term (s n) t+packet (s n) ts-(term (u n) t+packet (u n) ts)= + (term (s n) t-term (u n) t)+(packet (s n) ts-packet (u n) ts) by abel] + exact norm_add_le _ _ + +end TensorPackets + +namespace FiniteTree.FullRoot +open RootTensorCLT TensorPackets SpinOperators + +def deletion (D h : ℕ) : Space D h →L[ℂ] Double (FiniteTree.Tail D (h+1)) := + liftMap (FiniteTensor.deleteChild D (FiniteTree.vac D h) (FiniteTree.norm_vac D h)) + +theorem delete_tensorState (D h : ℕ) (l : List Label) : + FiniteTensor.deleteChild D (FiniteTree.vac D h) (FiniteTree.norm_vac D h) (tensorState D h l)= + ⟪FiniteTree.vac D h,childState D h l⟫_ℂ • + RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) l := by + exact FiniteTensor.deleteChild_power D _ _ _ + +theorem delete_tensorState_error (h : ℕ) (l : List Label) : + Tendsto (fun D => ‖FiniteTensor.deleteChild D (FiniteTree.vac D h) (FiniteTree.norm_vac D h) + (tensorState D h l)-RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) l‖) + atTop (𝓝 0) := by + have hg : Tendsto (fun D => ⟪FiniteTree.vac D h,childState D h l⟫_ℂ) atTop (𝓝 1) := by + simpa only [childState,QuantumCLT.generators,List.map_nil,List.prod_nil,one_apply_eq_self] + using child_Gram_limit h [] l + apply (tendsto_iff_norm_sub_tendsto_zero.mp hg).congr + intro D + rw [delete_tensorState] + have he : ⟪FiniteTree.vac D h,childState D h l⟫_ℂ • + RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) l- + RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) l= + (⟪FiniteTree.vac D h,childState D h l⟫_ℂ-1) • + RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) l := by + rw [sub_smul,one_smul] + rw [he,norm_smul] + rw [show ‖RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) l‖=1 + from FiniteTree.norm_power_of_norm_one D (childState D h l) (norm_childState D h l)] + exact (mul_one _).symm + + + +theorem deletion_program_error (h : ℕ) (p : List (Pulse Label)) : + Tendsto (fun D => ‖deletion D h (run (tensorPulse D h) p (vac D h))- + run (RootTensorCLT.tensorPulse D (childGenerator D h)) p + (PointedTree.plusEmbedding (FiniteTensor.power D (FiniteTree.vac D h)))‖) + atTop (𝓝 0) := by + have ht := TensorPackets.packet_norm_sub_limit + (fun D => FiniteTree.Tail D (h+1)) + (fun D l => FiniteTensor.deleteChild D (FiniteTree.vac D h) (FiniteTree.norm_vac D h) + (tensorState D h l)) + (fun D => RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h)) + (delete_tensorState_error h) (compile p start) + have hc (D : ℕ) : run (RootTensorCLT.tensorPulse D (childGenerator D h)) p + (PointedTree.plusEmbedding (FiniteTensor.power D (FiniteTree.vac D h)))= + packet (RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h)) (compile p start) := by + have he : RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h) []= + FiniteTensor.power D (FiniteTree.vac D h) := by + simp [RootTensorCLT.tensorState,QuantumCLT.generators] + rw [←he,←start_packet] + exact RootTensorCLT.run_packet _ _ (RootTensorCLT.tensor_step D _ _) _ _ + simpa only [run_packet,deletion,liftMap_packet,hc,Function.comp_def] using ht + +end FiniteTree.FullRoot + + + +open scoped InnerProductSpace BigOperators +namespace FiniteTree.FullRoot +open TensorPackets SpinOperators TwoHalfTree RootTensorCLT + +def edgeIndex (D h : ℕ) : + (Σ _ : Fin 2, Fin (D+1) → FiniteTree.Index D h) ≃ + (FiniteTree.Index D (h+1) × FiniteTree.Index D h) where + toFun x := (⟨x.1,(FiniteTensor.splitChildIndex D x.2).1⟩,(FiniteTensor.splitChildIndex D x.2).2) + invFun x := ⟨x.1.1,(FiniteTensor.splitChildIndex D).symm (x.1.2,x.2)⟩ + left_inv x := by + rcases x with ⟨i,v⟩ + simp only [Prod.mk.eta,Equiv.symm_apply_apply] + right_inv x := by + rcases x with ⟨⟨i,v⟩,c⟩ + simp only [Equiv.apply_symm_apply] + + + +def edgeSplit (D h : ℕ) : Space D h ≃ₗᵢ[ℂ] + EuclideanSpace ℂ (FiniteTree.Index D (h+1) × FiniteTree.Index D h) := + (LinearIsometryEquiv.piLpCurry ℂ 2 + (fun (_ : Fin 2) (_ : Fin (D+1) → FiniteTree.Index D h) => ℂ)).symm.trans + (LinearIsometryEquiv.piLpCongrLeft 2 ℂ ℂ (edgeIndex D h)) + +@[simp] theorem edgeSplit_apply (D h : ℕ) (f : Space D h) (i : Fin 2) + (σ : Fin D → FiniteTree.Index D h) (c : FiniteTree.Index D h) : + edgeSplit D h f (⟨i,σ⟩,c)=f i (Fin.cons c σ) := rfl + + + +def edgeEmbed (D h : ℕ) : Space D h →ₗᵢ[ℂ] + EuclideanSpace ℂ (FiniteTree.Index D (h+1) × FiniteTree.Index D (h+1)) := + (rightMap (FiniteTree.pad D h)).comp (edgeSplit D h).toLinearIsometry + +theorem edgeEmbed_apply (D h : ℕ) (f : Space D h) : + edgeEmbed D h f=rightMap (FiniteTree.pad D h) (edgeSplit D h f) := rfl + +theorem edgeSplit_term (D h : ℕ) (t : Term Label) : + edgeSplit D h (term (tensorState D h) t)= + tensor ((FiniteTree.split D (h+1)).symm + (term (RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h)) t)) + (childState D h t.history) := by + ext ⟨⟨i,σ⟩,c⟩ + rw [edgeSplit_apply,tensor_apply] + change (term (tensorState D h) t i) (Fin.cons c σ)= + (term (RootTensorCLT.tensorState D (FiniteTree.vac D h) (childGenerator D h)) t i) σ* + childState D h t.history c + rw [term_apply,term_apply] + split_ifs with hi + · change t.coeff*(∏j : Fin (D+1),childState D h t.history ((Fin.cons c σ : Fin (D+1) → FiniteTree.Index D h) j))= + (t.coeff*(∏j : Fin D,childState D h t.history (σ j)))*childState D h t.history c + rw [Fin.prod_univ_succ] + simp only [Fin.cons_zero,Fin.cons_succ] + ring + · simp + +theorem edgeSplit_vac (D h : ℕ) : + edgeSplit D h (vac D h)=tensor (FiniteTree.vac D (h+1)) (FiniteTree.vac D h) := by + ext ⟨⟨i,σ⟩,c⟩ + rw [edgeSplit_apply,tensor_apply] + change (((Real.sqrt 2)⁻¹:ℝ):ℂ)*(∏j : Fin (D+1),FiniteTree.vac D h + ((Fin.cons c σ : Fin (D+1) → FiniteTree.Index D h) j))= + ((((Real.sqrt 2)⁻¹:ℝ):ℂ)*(∏j : Fin D,FiniteTree.vac D h (σ j)))*FiniteTree.vac D h c + rw [Fin.prod_univ_succ] + simp only [Fin.cons_zero,Fin.cons_succ] + ring + +theorem edgeEmbed_vac (D h : ℕ) : + edgeEmbed D h (vac D h)=tensor (FiniteTree.vac D (h+1)) (FiniteTree.vac D (h+1)) := by + rw [edgeEmbed_apply,edgeSplit_vac,rightMap_tensor,FiniteTree.pad_vac] + +theorem edgeSplit_deletion (D h : ℕ) (f : Space D h) : + contract (FiniteTree.vac D h) (FiniteTree.norm_vac D h) (edgeSplit D h f)= + (FiniteTree.split D (h+1)).symm (deletion D h f) := by + apply ext_inner_left ℂ + intro x + rw [inner_contract] + + rw [←(FiniteTree.split D (h+1)).inner_map_map x + ((FiniteTree.split D (h+1)).symm (deletion D h f)),LinearIsometryEquiv.apply_symm_apply] + have hc (u : EuclideanSpace ℂ (Fin D → FiniteTree.Index D h)) + (v : Tail D h) : + ⟪u,FiniteTensor.deleteChild D (FiniteTree.vac D h) (FiniteTree.norm_vac D h) v⟫_ℂ= + ⟪tensor u (FiniteTree.vac D h),FiniteTensor.splitChild D v⟫_ℂ := + TwoHalfTree.inner_contract _ _ u _ + conv_rhs => rw [PiLp.inner_apply] + simp only [deletion,liftMap_apply,hc] + simp only [PiLp.inner_apply,Fintype.sum_prod_type,Fintype.sum_sigma, + RCLike.inner_apply,tensor_apply,FiniteTensor.splitChild_apply] + rfl + +end FiniteTree.FullRoot + + + +open scoped InnerProductSpace +namespace TwoHalfTree +variable {ι κ : Type*} [Fintype ι] [Fintype κ] + +omit [Fintype ι] [Fintype κ] in +theorem tensor_smul_left (c : ℂ) (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : + tensor (c • x) y=c • tensor x y := by + ext ⟨i,j⟩ + simp only [tensor_apply,PiLp.smul_apply,smul_eq_mul] + ring + +omit [Fintype ι] [Fintype κ] in +theorem tensor_smul_right (c : ℂ) (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : + tensor x (c • y)=c • tensor x y := by + ext ⟨i,j⟩ + simp only [tensor_apply,PiLp.smul_apply,smul_eq_mul] + ring + +omit [Fintype ι] [Fintype κ] in +theorem tensor_sub_right (x : EuclideanSpace ℂ ι) (y z : EuclideanSpace ℂ κ) : + tensor x (y-z)=tensor x y-tensor x z := by + ext ⟨i,j⟩ + simp only [tensor_apply,PiLp.sub_apply,mul_sub] + +theorem norm_tensor (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : + ‖tensor x y‖=‖x‖*‖y‖ := by + have he := inner_tensor x x y y + simp only [inner_self_eq_norm_sq_to_K] at he + have hr : ‖tensor x y‖^2=‖x‖^2*‖y‖^2 := by exact_mod_cast he + nlinarith [norm_nonneg (tensor x y),mul_nonneg (norm_nonneg x) (norm_nonneg y)] + +theorem nonvacuum_tensor (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) + (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : + tensor x y-projection Ω hΩ (tensor x y)=tensor x (y-⟪Ω,y⟫_ℂ • Ω) := by + rw [projection_apply,contract_tensor_general,tensor_sub_right,tensor_smul_left,tensor_smul_right] + +theorem nonvacuum_tensor_norm (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) + (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : + ‖tensor x y-projection Ω hΩ (tensor x y)‖=‖x‖*‖y-⟪Ω,y⟫_ℂ • Ω‖ := by + rw [nonvacuum_tensor,norm_tensor] + +theorem vacuum_remainder_bound (Ω y : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) : + ‖y-⟪Ω,y⟫_ℂ • Ω‖≤2*‖y-Ω‖ := by + let P : EuclideanSpace ℂ κ →L[ℂ] EuclideanSpace ℂ κ := 1-InnerProductSpace.rankOne ℂ Ω Ω + have hP : P Ω=0 := by + simp only [P,sub_apply,one_apply_eq_self, + InnerProductSpace.rankOne_apply,inner_self_eq_norm_sq_to_K,hΩ] + norm_num + have hn : ‖P‖≤2 := by + calc + _ ≤ ‖(1:EuclideanSpace ℂ κ →L[ℂ] EuclideanSpace ℂ κ)‖+‖InnerProductSpace.rankOne ℂ Ω Ω‖ := + norm_sub_le _ _ + _ ≤ 1+1 := by + apply add_le_add + · exact ContinuousLinearMap.norm_id_le + · simp [hΩ] + _ = _ := by norm_num + change ‖P y‖≤_ + have he : P y=P (y-Ω) := by rw [map_sub,hP,sub_zero] + rw [he] + exact (P.le_opNorm _).trans (mul_le_mul_of_nonneg_right hn (norm_nonneg _)) + + + +theorem nonvacuum_tensor_bound (Ω : EuclideanSpace ℂ κ) (hΩ : ‖Ω‖=1) + (x : EuclideanSpace ℂ ι) (y : EuclideanSpace ℂ κ) : + ‖tensor x y-projection Ω hΩ (tensor x y)‖≤‖x‖*(2*‖y-Ω‖) := by + rw [nonvacuum_tensor_norm] + exact mul_le_mul_of_nonneg_left (vacuum_remainder_bound Ω y hΩ) (norm_nonneg _) + +end TwoHalfTree + + + +open scoped InnerProductSpace BigOperators Topology +open Filter +namespace FiniteTree.FullRoot +open TensorPackets SpinOperators TwoHalfTree RootTensorCLT + + + +def edgeVector (D h : ℕ) (w : List PointedTree.Gate) := + edgeEmbed D h (insertion D h w) + +theorem edgeVector_centered (D h : ℕ) (w : List PointedTree.Gate) : + ⟪tensor (FiniteTree.vac D (h+1)) (FiniteTree.vac D (h+1)),edgeVector D h w⟫_ℂ=0 := by + rw [←edgeEmbed_vac] + exact ((edgeEmbed D h).inner_map_map _ _).trans (insertion_centered D h w) + +theorem edgeVector_norm (D h : ℕ) (w : List PointedTree.Gate) : + ‖edgeVector D h w‖=1 := by + rw [edgeVector,(edgeEmbed D h).norm_map] + exact norm_insertion D h w + +theorem edge_contract (D h : ℕ) (w : List PointedTree.Gate) : + contract (FiniteTree.vac D (h+1)) (FiniteTree.norm_vac D (h+1)) (edgeVector D h w)= + (FiniteTree.split D (h+1)).symm (deletion D h (insertion D h w)) := by + rw [edgeVector,edgeEmbed_apply,contract_rightMap (FiniteTree.pad D h) + (FiniteTree.vac D h) (FiniteTree.norm_vac D h) _ _ (FiniteTree.pad_vac D h),edgeSplit_deletion] + + + +theorem edge_deletion_limit (h : ℕ) (w : List PointedTree.Gate) : + Tendsto (fun D => ‖contract (FiniteTree.vac D (h+1)) (FiniteTree.norm_vac D (h+1)) + (edgeVector D h w)-FiniteTree.insertion D (h+1) w‖) atTop (𝓝 0) := by + have he (D : ℕ) : ‖contract (FiniteTree.vac D (h+1)) (FiniteTree.norm_vac D (h+1)) + (edgeVector D h w)-FiniteTree.insertion D (h+1) w‖= + ‖deletion D h (insertion D h w)- + run (RootTensorCLT.tensorPulse D (childGenerator D h)) (FiniteTree.insertionProgram w) + (PointedTree.plusEmbedding (FiniteTensor.power D (FiniteTree.vac D h)))‖ := by + rw [edge_contract,←(FiniteTree.split D (h+1)).norm_map,map_sub, + LinearIsometryEquiv.apply_symm_apply,FiniteTree.split_insertion] + simpa only [he,insertion] using deletion_program_error h (FiniteTree.insertionProgram w) + +theorem edgeSplit_term_nonvacuum (D h : ℕ) (hD : 0 simp only [packet_nil,map_zero,sub_self,norm_zero,packetOccupationBound,List.map_nil,List.sum_nil,zero_mul,le_refl] + | cons t ts ih => + rw [packet_cons,map_add,map_add] + rw [show edgeSplit D h (term (tensorState D h) t)+edgeSplit D h (packet (tensorState D h) ts)- + (projection (FiniteTree.vac D h) (FiniteTree.norm_vac D h) (edgeSplit D h (term (tensorState D h) t))+ + projection (FiniteTree.vac D h) (FiniteTree.norm_vac D h) (edgeSplit D h (packet (tensorState D h) ts)))= + (edgeSplit D h (term (tensorState D h) t)- + projection (FiniteTree.vac D h) (FiniteTree.norm_vac D h) (edgeSplit D h (term (tensorState D h) t)))+ + (edgeSplit D h (packet (tensorState D h) ts)- + projection (FiniteTree.vac D h) (FiniteTree.norm_vac D h) (edgeSplit D h (packet (tensorState D h) ts))) by abel] + exact (norm_add_le _ _).trans ((add_le_add (edgeSplit_term_nonvacuum D h hD t) ih).trans_eq (by + simp only [packetOccupationBound,List.map_cons,List.sum_cons,add_mul])) + + + +theorem edge_nonvacuum_bound (D h : ℕ) (hD : 0 simp only [packet_nil,map_zero,inner_zero_right,mul_zero] + | cons t ts ih => simp only [packet_cons,map_add,inner_add_right,marked_term,ih,mul_add] + + + +theorem marked_edge (D h : ℕ) (w u : List PointedTree.Gate) (hw : w.length≤h) : + ⟪PointedTree.plusEmbedding (excitation D h w),insertion D h u⟫_ℂ= + (Real.sqrt ((D+1:ℕ):ℝ):ℂ)* + ⟪tensor (FiniteTree.vac D (h+1)) ((FiniteTree.ordinary D w (h+1)).observable (FiniteTree.vac D (h+1))), + edgeEmbed D h (insertion D h u)⟫_ℂ := by + rw [←FiniteTree.pad_insertion D w h hw,edgeEmbed_apply,←rightMap_tensor, + (rightMap (FiniteTree.pad D h)).inner_map_map] + simp only [insertion,run_packet] + exact marked_packet D h w _ + +end FiniteTree.FullRoot + + + +open scoped InnerProductSpace Topology BigOperators +open Filter +namespace FiniteTree.FullRoot +open TwoHalfTree RootTensorCLT TensorPackets + + + +def edgeValue (D h : ℕ) (w : List PointedTree.Gate) : ℝ := + Real.sqrt (D:ℝ)/2*(⟪edgeVector D h w,swap (edgeVector D h w)⟫_ℂ).re + +def sideValue (D h : ℕ) (w : List PointedTree.Gate) : ℝ := + Real.sqrt (D:ℝ)*(⟪tensor (FiniteTree.vac D (h+1)) (FiniteTree.insertion D (h+1) w), + edgeVector D h w⟫_ℂ).re + +def deletionError (D h : ℕ) (w : List PointedTree.Gate) : ℝ := + ‖contract (FiniteTree.vac D (h+1)) (FiniteTree.norm_vac D (h+1)) (edgeVector D h w)- + FiniteTree.insertion D (h+1) w‖ + +theorem edgeValue_error_bound (D h : ℕ) (hD : 0 edgeValue D h w-sideValue D h w) atTop (𝓝 0) := by + have hr : Tendsto (fun D : ℕ => (Real.sqrt (D:ℝ))⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp (Real.tendsto_sqrt_atTop.comp tendsto_natCast_atTop_atTop) + have he := edge_deletion_limit h w + let C := packetOccupationBound (compile (FiniteTree.insertionProgram w) start) + have hlim : Tendsto (fun D : ℕ => C^2/2*(Real.sqrt (D:ℝ))⁻¹+C*deletionError D h w) atTop (𝓝 0) := by + simpa only [mul_zero,add_zero,deletionError] using (hr.const_mul (C^2/2)).add (he.const_mul C) + apply tendsto_zero_iff_norm_tendsto_zero.mpr + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) _ hlim + filter_upwards [eventually_gt_atTop (0:ℕ)] with D hD + simpa only [Real.norm_eq_abs] using edgeValue_error_bound D h hD w + +theorem sideValue_marked (D h : ℕ) (w : List PointedTree.Gate) (hw : w.length≤h) : + sideValue D h w=Real.sqrt (D:ℝ)/Real.sqrt ((D:ℝ)+1)* + (⟪PointedTree.plusEmbedding (excitation D h w),insertion D h w⟫_ℂ).re := by + have hm := congrArg Complex.re (marked_edge D h w w hw) + simp only [Complex.mul_re,Complex.ofReal_re,Complex.ofReal_im,zero_mul,sub_zero, + Nat.cast_add,Nat.cast_one] at hm + rw [hm] + change Real.sqrt (D:ℝ)*_=Real.sqrt (D:ℝ)/Real.sqrt ((D:ℝ)+1)*(Real.sqrt ((D:ℝ)+1)*_) + have hs : Real.sqrt ((D:ℝ)+1)≠0 := (Real.sqrt_pos.2 (by positivity)).ne' + field_simp + rfl + +theorem sideValue_limit (h : ℕ) (w : List PointedTree.Gate) (hw : w.length≤h) : + Tendsto (fun D => sideValue D h w) atTop (𝓝 (PointedTree.ordinaryValue w)) := by + have hr : Tendsto (fun D : ℕ => Real.sqrt (D:ℝ)/Real.sqrt ((D:ℝ)+1)) atTop (𝓝 1) := by + simpa only [inv_div,inv_one] using sqrt_ratio_limit.inv₀ (by norm_num : (1:ℝ)≠0) + have hm := Complex.continuous_re.continuousAt.tendsto.comp (root_shift_insertion_limit h w w) + have hv : (⟪PointedTree.rootShift h (PointedTree.ordinary w h).insertion, + (PointedTree.ordinary w (h+1)).insertion⟫_ℂ).re=PointedTree.ordinaryValue w := by + rw [←PointedTree.ordinary_insertion_empty w h hw] + rw [←inner_conj_symm,Complex.conj_re] + exact PointedTree.ordinary_energy_stable w h hw + simpa only [Function.comp_apply,←sideValue_marked _ h w hw,one_mul,hv] using hr.mul hm + + + +theorem edgeValue_limit (h : ℕ) (w : List PointedTree.Gate) (hw : w.length≤h) : + Tendsto (fun D => edgeValue D h w) atTop (𝓝 (PointedTree.ordinaryValue w)) := by + simpa only [sub_add_cancel,zero_add] using + (edge_side_difference_limit h w).add (sideValue_limit h w hw) + +end FiniteTree.FullRoot + + + +open scoped BigOperators Topology +open Filter + +namespace SKQAOA +namespace Locality + + +theorem relevantEdges_qaoa_angles {n : ℕ} (E : Finset (Edge n)) (p : ℕ) + (γ β γ' β' : Fin p → ℝ) (S : Finset (Fin n)) : + relevantEdges E (qaoaWord p γ β) S=relevantEdges E (qaoaWord p γ' β') S := by + induction p generalizing S with + | zero => rfl + | succ p ih => + simp only [qaoaWord,relevantEdges] + rw [ih (fun i => γ i.castSucc) (fun i => β i.castSucc) + (fun i => γ' i.castSucc) (fun i => β' i.castSucc)] + +end Locality +namespace SiteHistories + +lemma interaction_scale (p : ℕ) (c : ℝ) (γ : Fin p → ℝ) (a b : Bits p) : + interaction p (fun i => c*γ i) a b=c*interaction p γ a b := by + induction p with + | zero => simp [interaction] + | succ p ih => simp only [interaction,ih]; ring + +lemma delta_scale (p : ℕ) (c : ℝ) (γ : Fin p → ℝ) (a b : Site p) : + delta p (fun i => c*γ i) a b=c*delta p γ a b := by + simp only [delta,interaction_scale] + ring + +lemma edgeKernel_scale (N m p : ℕ) (c : ℝ) (γ : Fin p → ℝ) + (hscale : c^2/(m:ℝ)=(N:ℝ)⁻¹) (a b : Site p) : + edgeKernel m p (fun i => c*γ i) a b=edgeKernel N p γ a b := by + unfold edgeKernel + rw [delta_scale] + congr 1 + calc + _ = -(delta p γ a b)^2/2*(c^2/(m:ℝ)) := by ring + _ = _ := by rw [hscale]; ring + +lemma rawGraphCoefficient_scale (N m p : ℕ) (c : ℝ) (γ β : Fin p → ℝ) + (hscale : c^2/(m:ℝ)=(N:ℝ)⁻¹) (r : Edge m) (H : Finset (Edge m)) : + rawGraphCoefficient m m p (fun i => c*γ i) β r H= + (c:ℂ)*rawGraphCoefficient N m p γ β r H := by + unfold rawGraphCoefficient FiniteHistory.expectation + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + simp only [delta_scale,edgeKernel_scale N m p c γ hscale,Complex.ofReal_mul] + ring + + + +theorem graphCoefficient_zero_of_not_cone (N m p : ℕ) (γ β : Fin p → ℝ) + (hN : 0 c*γ i) β) (roots r) := by + rw [Locality.relevantEdges_qaoa_angles (H∪{r}) p (fun i => c*γ i) β γ β] + exact hc + have hz := cluster_zero_of_not_cone p (fun i => c*γ i) β r H hcone + rw [cluster_eq_inv_sqrt_mul_raw, + rawGraphCoefficient_scale N m p c γ β hscale] at hz + have hs : ((Real.sqrt (m:ℝ):ℂ))⁻¹≠0 := by + exact inv_ne_zero (Complex.ofReal_ne_zero.mpr (ne_of_gt (Real.sqrt_pos.2 hmR))) + have hcz : (c:ℂ)≠0 := Complex.ofReal_ne_zero.mpr (ne_of_gt hcpos) + have hr := (mul_eq_zero.mp hz).resolve_left hs + have hr' := (mul_eq_zero.mp hr).resolve_left hcz + rw [graphCoefficient_eq_pow_mul_raw,hr',mul_zero] + + + +theorem graphCoefficientLimit_zero_of_not_cone (m p : ℕ) (γ β : Fin p → ℝ) + (r : Edge m) (H : Finset (Edge m)) + (hc : ¬ H⊆Locality.relevantEdges (H∪{r}) (qaoaWord p γ β) (roots r)) : + graphCoefficientLimit m p γ β r H=0 := by + apply tendsto_nhds_unique (tendsto_graphCoefficient m p γ β r H) + apply tendsto_const_nhds.congr' + filter_upwards [eventually_ge_atTop 1] with N hN + exact (graphCoefficient_zero_of_not_cone N m p γ β (by omega) r H hc).symm + +end SiteHistories +end SKQAOA + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/TerminalThird.lean b/lean/OAI/Probability/ParisiFinite/TerminalThird.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a419d0bb04b562e9598439914f3e528cce185b1 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/TerminalThird.lean @@ -0,0 +1,249 @@ +import Mathlib +import OAI.Probability.ParisiFinite.OrderPointIntegrable + +namespace OAI + +/-! Terminal Third. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ThirdJet + +def terminalThird (β : ℝ≥0) (hβ : 0<β) : ThirdJet (terminalField β hβ) where + d3 := fun x => -2*(β:ℝ)*(terminalField β hβ).d1 x*(terminalField β hβ).d2 x + hasD3 := by + intro x + have hf : (terminalField β hβ).d2 = fun y => (β:ℝ)*(1-(terminalField β hβ).d1 y^2) := + funext (terminal_curvature_identity β hβ) + rw [hf] + convert (((terminalField β hβ).hasD2 x).pow 2 |>.const_sub 1 |>.const_mul (β:ℝ)) using 1 + first | rfl | (norm_num;rw [terminal_curvature_identity];ring) + continuousD3 := by + have h1 := (terminalField β hβ).continuousD1 + have h2 := (terminalField β hβ).continuousD2 + fun_prop + bound3 := 2*β^2 + normD3 := by + intro x + have h1 := (terminalField β hβ).normD1 x + have h2 := (terminalField β hβ).normD2 x + change |(terminalField β hβ).d1 x|≤(1:ℝ) at h1 + change |(terminalField β hβ).d2 x|≤(β:ℝ) at h2 + norm_num only [abs_mul,abs_neg,abs_of_nonneg β.coe_nonneg,NNReal.coe_mul,NNReal.coe_ofNat,NNReal.coe_pow] + nlinarith [mul_le_mul h1 h2 (abs_nonneg _) (show (0:ℝ)≤1 by norm_num),β.coe_nonneg] + +lemma terminal_expThird (β : ℝ≥0) (hβ : 0<β) (x : ℝ) : + (terminalThird β hβ).expThird β x=(β:ℝ)^2*(terminalField β hβ).d1 x := by + dsimp only [ThirdJet.expThird,terminalThird] + rw [terminal_curvature_identity] + ring + +lemma expThird_change_bound {β : ℝ≥0} {f : SmoothField} (hf : HasParisiCurvature β f) + (j : ThirdJet f) {a r C : ℝ} (ha : 0≤a) (har : a≤r) + (hC : ∀ x,|j.expThird r x|≤C) (x : ℝ) : + |j.expThird a x|≤C+3*(r-a)*(β:ℝ)+(r^2-a^2) := by + have h1 : |f.d1 x|≤(1:ℝ) := by simpa only [hf.1,NNReal.coe_one] using f.normD1 x + have h2 := curvature_abs_d2 hf x + have h12 : |f.d1 x*f.d2 x|≤(β:ℝ) := by + rw [abs_mul] + simpa only [one_mul] using mul_le_mul h1 h2 (abs_nonneg _) (by norm_num : (0:ℝ)≤1) + have h3 : |f.d1 x^3|≤(1:ℝ) := by + simpa only [abs_pow,one_pow] using pow_le_pow_left₀ (abs_nonneg _) h1 3 + have har2 : 0≤r^2-a^2 := by nlinarith + have he : j.expThird a x=j.expThird r x-3*(r-a)*(f.d1 x*f.d2 x)-(r^2-a^2)*f.d1 x^3 := by + unfold ThirdJet.expThird; ring + rw [he] + apply (abs_sub _ _).trans + apply (add_le_add (abs_sub _ _) (le_refl _)).trans + norm_num only [abs_mul,abs_of_nonneg (sub_nonneg.mpr har),abs_of_nonneg har2] + calc + _ ≤ C+3*(r-a)*(β:ℝ)+(r^2-a^2)*1 := by + gcongr + · exact hC x + · simpa only [abs_mul] using h12 + _ = _ := by ring + +lemma ordered_coefficient_bounds {β a : ℝ} {ls : Schedule} + (h : ParisiGuerra.OrderedFrom β a ls) : a≤β ∧ ∀ l∈ls,(l.1:ℝ)≤β := by + induction ls generalizing a with + | nil => exact ⟨h,by simp⟩ + | cons l ls ih => + obtain ⟨hb,hls⟩ := ih h.2 + refine ⟨h.1.trans hb,?_⟩ + intro k hk + rcases List.mem_cons.mp hk with rfl|hk + · exact hb + · exact hls k hk + +def recursionThird (β : ℝ≥0) (hβ : 0<β) : (ls : Schedule) → ThirdJet (smoothRecursion β hβ ls) + | [] => terminalThird β hβ + | l::ls => (recursionThird β hβ ls).transform l.1 (Real.sqrt l.2) + +lemma recursion_expThird_bound (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) {a : ℝ} + (ha : 0≤a) (h : ParisiGuerra.OrderedFrom β a ls) (x : ℝ) : + |(recursionThird β hβ ls).expThird a x|≤(β:ℝ)^2+3*((β:ℝ)-a)*β+((β:ℝ)^2-a^2) := by + induction ls generalizing a x with + | nil => + have hb : ∀ y,|(terminalThird β hβ).expThird β y|≤(β:ℝ)^2 := by + intro y + rw [terminal_expThird,abs_mul,abs_sq] + exact mul_le_mul_of_nonneg_left (terminalField β hβ |>.normD1 y) (sq_nonneg _) |>.trans_eq (mul_one _) + exact expThird_change_bound (terminal_hasParisiCurvature β hβ) (terminalThird β hβ) ha h hb x + | cons l ls ih => + have hlb := ordered_coefficient_bounds h.2 + have hf := smoothRecursion_hasParisiCurvature β hβ (l::ls) + (fun k hk => by exact_mod_cast (ordered_coefficient_bounds h).2 k hk) + have ht : ∀ y,|(recursionThird β hβ (l::ls)).expThird l.1 y|≤ + (β:ℝ)^2+3*((β:ℝ)-l.1)*β+((β:ℝ)^2-(l.1:ℝ)^2) := by + intro y + change |((recursionThird β hβ ls).transform l.1 (Real.sqrt l.2)).expThird l.1 y|≤_ + rw [ThirdJet.expThird_transform] + exact abs_tiltedMean_le (smoothRecursion β hβ ls).lipschitz + ((recursionThird β hβ ls).continuous_expThird l.1) (fun z => ih l.1.coe_nonneg h.2 z) _ _ _ + have hh := expThird_change_bound hf (recursionThird β hβ (l::ls)) ha h.1 ht x + convert hh using 1 + ring + +lemma recursion_d3_bound (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (h : ParisiGuerra.OrderedFrom β 0 ls) (x : ℝ) : + |(recursionThird β hβ ls).d3 x|≤5*(β:ℝ)^2 := by + have hh := recursion_expThird_bound β hβ ls (by norm_num : (0:ℝ)≤0) h x + simpa only [ThirdJet.expThird,mul_zero,zero_mul,zero_pow (by norm_num : 2≠0), + add_zero,sub_zero,show (β:ℝ)^2+3*(β:ℝ)*β+(β:ℝ)^2=5*(β:ℝ)^2 by ring] using hh + +lemma ordered_lower {β a r : ℝ} {ls : Schedule} + (har : a≤r) (h : ParisiGuerra.OrderedFrom β r ls) : ParisiGuerra.OrderedFrom β a ls := by + cases ls with + | nil => exact har.trans h + | cons l ls => exact ⟨har.trans h.1,h.2⟩ + +lemma ordered_upper {β b a : ℝ} {ls : Schedule} + (hb : β≤b) (h : ParisiGuerra.OrderedFrom β a ls) : ParisiGuerra.OrderedFrom b a ls := by + induction ls generalizing a with + | nil => exact h.trans hb + | cons l ls ih => exact ⟨h.1,ih h.2⟩ + +lemma ordered_append {β r a : ℝ} {ls ks : Schedule} + (h1 : ParisiGuerra.OrderedFrom r a ls) (h2 : ParisiGuerra.OrderedFrom β r ks) : + ParisiGuerra.OrderedFrom β a (ls++ks) := by + induction ls generalizing a with + | nil => exact ordered_lower h1 h2 + | cons l ls ih => exact ⟨h1.1,ih h1.2⟩ + +lemma dyadicSchedule_ordered {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) + (u : Bool) (t d : ℝ≥0) (n : ℕ) : + ParisiGuerra.OrderedFrom (γ (t+d)) (γ t) (dyadicSchedule γ u t d n) := by + induction n generalizing t d with + | zero => + change (γ t:ℝ)≤γ (if u then t+d else t) ∧ (γ (if u then t+d else t):ℝ)≤γ (t+d) + have hh : γ t≤γ (t+d) := hγ (le_add_of_nonneg_right d.coe_nonneg) + cases u <;> simpa using hh + | succ n ih => + have hn : t+d/2+d/2=t+d := by exact_mod_cast (by ring : (t:ℝ)+(d:ℝ)/2+(d:ℝ)/2=(t:ℝ)+d) + have hh := ordered_append (ih t (d/2)) (ih (t+d/2) (d/2)) + simpa only [dyadicSchedule,hn] using hh + +lemma dyadic_recursion_d3_bound (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (u : Bool) (t d : ℝ≥0) (n : ℕ) (x : ℝ) : + |(recursionThird β hβ (dyadicSchedule γ u t d n)).d3 x|≤5*(β:ℝ)^2 := + recursion_d3_bound β hβ _ (ordered_lower (γ t).coe_nonneg + (ordered_upper (show (γ (t+d):ℝ)≤β by exact_mod_cast hb _) (dyadicSchedule_ordered hγ u t d n))) x + +lemma recursion_curvature_lipschitz (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (h : ParisiGuerra.OrderedFrom β 0 ls) : + LipschitzWith (5*β^2) (smoothRecursion β hβ ls).d2 := by + apply lipschitzWith_of_nnnorm_deriv_le (fun x => ((recursionThird β hβ ls).hasD3 x).differentiableAt) + intro x + rw [((recursionThird β hβ ls).hasD3 x).deriv] + exact_mod_cast recursion_d3_bound β hβ ls h x + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +lemma taylor_error_of_derivative_lipschitz {f g : ℝ → ℝ} {K : ℝ≥0} + (hd : ∀ x,HasDerivAt f (g x) x) (hg : LipschitzWith K g) + (x : ℝ) {h : ℝ} (hh : 0≤h) : + |f (x+h)-f x-h*g x|≤(K:ℝ)*h^2 := by + let r (y : ℝ) := f y-f x-(y-x)*g x + have hder (y : ℝ) : HasDerivAt r (g y-g x) y := by + convert (hd y |>.sub_const (f x)).sub + (((hasDerivAt_id y).sub_const x).mul_const (g x)) using 1 <;> + first | rfl | simp only [one_mul] + have hb (y : ℝ) (hy : y∈Set.Ico x (x+h)) : ‖g y-g x‖≤(K:ℝ)*h := by + have hl := hg.dist_le_mul y x + rw [Real.dist_eq,Real.dist_eq,abs_of_nonneg (sub_nonneg.mpr hy.1)] at hl + simpa only [Real.norm_eq_abs] using hl.trans (mul_le_mul_of_nonneg_left (by linarith [hy.2]) K.coe_nonneg) + have ht := norm_image_sub_le_of_norm_deriv_le_segment' + (fun y (_ : y∈Set.Icc x (x+h)) => (hder y).hasDerivWithinAt) hb (x+h) ⟨by linarith,le_rfl⟩ + simpa only [r,sub_self,zero_mul,sub_zero,add_sub_cancel_left,Real.norm_eq_abs,pow_two,mul_assoc] using ht + +lemma derivative_stability_lipschitz {f g f' g' : ℝ → ℝ} {K : ℝ≥0} + (hf : ∀ x,HasDerivAt f (f' x) x) (hg : ∀ x,HasDerivAt g (g' x) x) + (hf' : LipschitzWith K f') (hg' : LipschitzWith K g') + {ε h : ℝ} (hh : 0≤h) (he : ∀ y,|f y-g y|≤ε) (x : ℝ) : + h*|f' x-g' x|≤2*ε+2*(K:ℝ)*h^2 := by + have hferr := abs_le.mp (taylor_error_of_derivative_lipschitz hf hf' x hh) + have hgerr := abs_le.mp (taylor_error_of_derivative_lipschitz hg hg' x hh) + have hx := abs_le.mp (he x) + have hx' := abs_le.mp (he (x+h)) + have ha : h*|f' x-g' x|=|h*(f' x-g' x)| := by rw [abs_mul,abs_of_nonneg hh] + rw [ha,abs_le] + constructor <;> nlinarith + +lemma exists_uniform_derivative_lipschitz_limit {K : ℝ≥0} {F G : ℕ → ℝ → ℝ} {f : ℝ → ℝ} + (hF : ∀ n x,HasDerivAt (F n) (G n x) x) (hG : ∀ n,LipschitzWith K (G n)) + (ht : TendstoUniformly F f atTop) : + ∃ g : ℝ → ℝ,TendstoUniformly G g atTop ∧ (∀ x,HasDerivAt f (g x) x) ∧ LipschitzWith K g := by + have hc : UniformCauchySeqOn G atTop Set.univ := by + rw [Metric.uniformCauchySeqOn_iff] + intro ε hε + let h := ε/(8*((K:ℝ)+1)) + have hh : 0 ?_⟩ + have hd : ∀ y,|F m y-F n y|≤2*(ε*h/8) := by + intro y + have h1 := hN m hm y + have h2 := hN n hn y + rw [Real.dist_eq] at h1 h2 + calc + _ ≤ |F m y-f y|+|f y-F n y| := abs_sub_le _ _ _ + _ ≤ 2*(ε*h/8) := by rw [abs_sub_comm] at h1;linarith + have hb := derivative_stability_lipschitz (hF m) (hF n) (hG m) (hG n) hh.le hd x + rw [Real.dist_eq] + have hm := mul_le_mul_of_nonneg_right hsmall hh.le + nlinarith + choose g hg using fun x : ℝ => cauchySeq_tendsto_of_complete (hc.cauchySeq (Set.mem_univ x)) + have hu : TendstoUniformly G g atTop := by + rw [← tendstoUniformlyOn_univ] + exact hc.tendstoUniformlyOn_of_tendsto (fun x _ => hg x) + refine ⟨g,hu,fun x => hasDerivAt_of_tendstoUniformly hu (Eventually.of_forall hF) (fun y => ht.tendsto_at y) x,?_⟩ + apply LipschitzWith.of_dist_le_mul + intro x y + apply le_of_tendsto ((hg x).dist (hg y)) + exact Eventually.of_forall fun n => (hG n).dist_le_mul x y + +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/ThermalDeviation.lean b/lean/OAI/Probability/ParisiFinite/ThermalDeviation.lean new file mode 100644 index 0000000000000000000000000000000000000000..e4b70d716ad0b3ae72652d11d71ebca98ca34c5e --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/ThermalDeviation.lean @@ -0,0 +1,706 @@ +import Mathlib +import OAI.Probability.ParisiFinite.IncrementEqKernel + +namespace OAI + +/-! Thermal Deviation. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKGaussian ParisiInterpolation ParisiFinite +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +def thermalDeviation (x v : ι → ℝ) : ℝ := + ∑ s, weight x s*|v s-gibbsMean 1 x v| + +lemma thermalDeviation_nonneg (x v : ι → ℝ) : 0≤thermalDeviation x v := + Finset.sum_nonneg fun s _ => mul_nonneg (weight_pos x s).le (abs_nonneg _) + +lemma thermalDeviation_le (x v : ι → ℝ) : thermalDeviation x v ≤ 2*‖v‖ := by + calc + _ ≤ ∑ s, weight x s*(2*‖v‖) := by + apply Finset.sum_le_sum + intro s _ + apply mul_le_mul_of_nonneg_left _ (weight_pos x s).le + have h := (norm_le_pi_norm v s) + have h' := abs_gibbsMean_le 1 x v + have ht := abs_sub (v s) (gibbsMean 1 x v) + rw [Real.norm_eq_abs] at h + linarith + _ = _ := by rw [← Finset.sum_mul, sum_weight, one_mul] + +lemma gibbsCov_eq_centered (x v : ι → ℝ) : + gibbsCov 1 x v v=∑ s, weight x s*(v s-gibbsMean 1 x v)^2 := by + have he (s : ι) : weight x s*(v s-gibbsMean 1 x v)^2 = + weight x s*(v s*v s)-2*gibbsMean 1 x v*(weight x s*v s)+ + weight x s*(gibbsMean 1 x v)^2 := by ring + simp only [he, Finset.sum_add_distrib, Finset.sum_sub_distrib, + ← Finset.mul_sum, ← Finset.sum_mul] + rw [sum_weight] + unfold gibbsCov gibbsMean + simp only [one_mul] + ring + +lemma thermalDeviation_sq_le (x v : ι → ℝ) : + (thermalDeviation x v)^2 ≤ gibbsCov 1 x v v := by + have h := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ + (r:=fun s => weight x s*|v s-gibbsMean 1 x v|) + (f:=weight x) (g:=fun s => weight x s*(v s-gibbsMean 1 x v)^2) + (fun s _ => (weight_pos x s).le) + (fun s _ => mul_nonneg (weight_pos x s).le (sq_nonneg _)) + (fun s _ => by rw [mul_pow, sq_abs]; ring_nf; rfl) + rw [sum_weight, one_mul, ← gibbsCov_eq_centered] at h + exact h + +lemma continuous_thermalDeviation_field (A B : ι → κ → ℝ) : + Continuous (fun z => thermalDeviation (field A z) (field B z)) := by + apply continuous_finsetSum + intro s _ + apply Continuous.mul ((continuous_weight s).comp (continuous_field A)) + apply Continuous.abs + apply Continuous.sub ((continuous_apply s).comp (continuous_field B)) + unfold gibbsMean + apply continuous_finsetSum + intro t _ + simp only [one_mul] + exact ((continuous_weight t).comp (continuous_field A)).mul + ((continuous_apply t).comp (continuous_field B)) + +lemma memLp_thermalDeviation_field (A B : ι → κ → ℝ) : + MemLp (fun z => thermalDeviation (field A z) (field B z)) 2 (gaussianLaw κ) := by + apply ((memLp_norm_field_two B).const_mul 2).mono' + (continuous_thermalDeviation_field A B).aestronglyMeasurable + exact ae_of_all _ fun z => by + rw [Real.norm_of_nonneg (thermalDeviation_nonneg _ _)] + exact thermalDeviation_le _ _ + +lemma expected_thermalDeviation_le (A B : ι → κ → ℝ) (t : ℝ) : + (∫ z, thermalDeviation (field (affineCoeff A B t) z) (field B z) ∂gaussianLaw κ) ≤ + Real.sqrt (varianceLine A B t) := by + have hm := memLp_thermalDeviation_field (affineCoeff A B t) B + have hv := variance_nonneg (fun z => thermalDeviation (field (affineCoeff A B t) z) (field B z)) + (gaussianLaw κ) + rw [variance_eq_sub hm] at hv + have hi := integral_mono hm.integrable_sq (integrable_lineVariance A B t) + (fun z => by simpa only [field_affineCoeff] using + (thermalDeviation_sq_le (field (affineCoeff A B t) z) (field B z))) + have hs := Real.sq_sqrt (varianceLine_nonneg A B t) + have hn := Real.sqrt_nonneg (varianceLine A B t) + change _ ≤ varianceLine A B t at hi + simp only [Pi.pow_apply] at hv + nlinarith + + + +theorem energyDeviation_le_thermal_add (A B : ι → κ → ℝ) (t c : ℝ) : + energyDeviation (affineCoeff A B t) B c ≤ + Real.sqrt (varianceLine A B t)+ + ∫ z, |gibbsMean 1 (field A z+t • field B z) (field B z)-c| ∂gaussianLaw κ := by + have hd (z : κ → ℝ) : + (∑ s, weight (field (affineCoeff A B t) z) s*|field B z s-c|) ≤ + thermalDeviation (field (affineCoeff A B t) z) (field B z)+ + |gibbsMean 1 (field A z+t • field B z) (field B z)-c| := by + calc + _ ≤ ∑ s, weight (field (affineCoeff A B t) z) s* + (|field B z s-gibbsMean 1 (field A z+t • field B z) (field B z)|+ + |gibbsMean 1 (field A z+t • field B z) (field B z)-c|) := by + apply Finset.sum_le_sum + intro s _ + exact mul_le_mul_of_nonneg_left (abs_sub_le _ _ _) (weight_pos _ _).le + _ = _ := by + simp only [mul_add, Finset.sum_add_distrib, ← Finset.sum_mul, sum_weight, one_mul, + thermalDeviation, field_affineCoeff] + have ht := (memLp_thermalDeviation_field (affineCoeff A B t) B).integrable (by norm_num) + have hc := ((integrable_lineMean A B t).sub (integrable_const c)).abs + have h := integral_mono (integrable_energyDeviation _ _ c) (ht.add hc) hd + simp only [Pi.add_apply] at h + rw [integral_add ht hc] at h + exact h.trans (add_le_add (expected_thermalDeviation_le A B t) le_rfl) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKGaussian ParisiInterpolation ParisiFinite GaussianConcentration +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +def pressureFluctuation (A : ι → κ → ℝ) : ℝ := + ∫ z, |logPartition (field A z)-expected A| ∂gaussianLaw κ + +def disorderDeviation (A B : ι → κ → ℝ) (t : ℝ) : ℝ := + ∫ z, |gibbsMean 1 (field A z+t • field B z) (field B z)-meanLine A B t| ∂gaussianLaw κ + +lemma integrable_pressureFluctuation (A : ι → κ → ℝ) : + Integrable (fun z => |logPartition (field A z)-expected A|) (gaussianLaw κ) := by + exact (((memLp_logPartition_field A).integrable (by norm_num)).sub (integrable_const _)).abs + +lemma pressureFluctuation_le (A : ι → κ → ℝ) (c : κ → ℝ≥0) (hA : ∀ s k, |A s k|≤c k) : + pressureFluctuation A ≤ Real.sqrt (∑ k, (c k:ℝ)^2) := + logPartition_absolute_fluctuation A c hA + +omit [Nonempty ι] in +lemma disorderDeviation_nonneg (A B : ι → κ → ℝ) (t : ℝ) : 0≤disorderDeviation A B t := + integral_nonneg fun _ => abs_nonneg _ + + + +theorem disorderDeviation_le (A B : ι → κ → ℝ) (t : ℝ) {δ : ℝ} (hδ : 0<δ) : + disorderDeviation A B t ≤ + (pressureFluctuation (affineCoeff A B (t+δ))+2*pressureFluctuation (affineCoeff A B t)+ + pressureFluctuation (affineCoeff A B (t-δ)))/δ+ + (meanLine A B (t+δ)-meanLine A B (t-δ)) := by + have hd (z : κ → ℝ) := convex_derivative_deviation + (convex_logPartition_line (field A z) (field B z)) (convex_expectedLine A B) + (fun u => (hasDerivAt_logPartition_line (field A z) (field B z) u).differentiableAt) + (fun u => (hasDerivAt_expectedLine A B u).differentiableAt) t hδ + have he (z : κ → ℝ) : + |gibbsMean 1 (field A z+t • field B z) (field B z)-meanLine A B t| ≤ + (|logPartition (field (affineCoeff A B (t+δ)) z)-expected (affineCoeff A B (t+δ))|+ + 2*|logPartition (field (affineCoeff A B t) z)-expected (affineCoeff A B t)|+ + |logPartition (field (affineCoeff A B (t-δ)) z)-expected (affineCoeff A B (t-δ))|)/δ+ + (meanLine A B (t+δ)-meanLine A B (t-δ)) := by + simpa only [(hasDerivAt_logPartition_line (field A z) (field B z) t).deriv, + (hasDerivAt_expectedLine A B t).deriv, (hasDerivAt_expectedLine A B (t+δ)).deriv, + (hasDerivAt_expectedLine A B (t-δ)).deriv, expectedLine_eq, field_affineCoeff] using hd z + have hp := integrable_pressureFluctuation (affineCoeff A B (t+δ)) + have hm := integrable_pressureFluctuation (affineCoeff A B (t-δ)) + have h0 := integrable_pressureFluctuation (affineCoeff A B t) + have hleft := ((integrable_lineMean A B t).sub (integrable_const (meanLine A B t))).abs + have hright := (((hp.add (h0.const_mul 2)).add hm).div_const δ).add + (integrable_const (meanLine A B (t+δ)-meanLine A B (t-δ))) + have h := integral_mono hleft hright he + simp only [Pi.add_apply] at h + have hsum : ∫ z, (|logPartition (field (affineCoeff A B (t+δ)) z)-expected (affineCoeff A B (t+δ))|+ + 2*|logPartition (field (affineCoeff A B t) z)-expected (affineCoeff A B t)|+ + |logPartition (field (affineCoeff A B (t-δ)) z)-expected (affineCoeff A B (t-δ))|)/δ+ + (meanLine A B (t+δ)-meanLine A B (t-δ)) ∂gaussianLaw κ = + (pressureFluctuation (affineCoeff A B (t+δ))+2*pressureFluctuation (affineCoeff A B t)+ + pressureFluctuation (affineCoeff A B (t-δ)))/δ+ + (meanLine A B (t+δ)-meanLine A B (t-δ)) := by + have hh := integral_add (((hp.add (h0.const_mul 2)).add hm).div_const δ) (integrable_const + (meanLine A B (t+δ)-meanLine A B (t-δ))) + simp only [Pi.add_apply, integral_div, integral_const, probReal_univ, smul_eq_mul, one_mul] at hh + rw [hh] + congr 2 + have hhh := integral_add (hp.add (h0.const_mul 2)) hm + simp only [Pi.add_apply] at hhh + rw [hhh, integral_add hp (h0.const_mul 2), integral_const_mul] + rfl + rw [hsum] at h + exact h + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKGaussian ParisiInterpolation ParisiFinite +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +lemma continuous_meanLine (A B : ι → κ → ℝ) : Continuous (meanLine A B) := + continuous_iff_continuousAt.mpr fun t => (hasDerivAt_meanLine A B t).continuousAt + +lemma continuous_varianceLine (A B : ι → κ → ℝ) : Continuous (varianceLine A B) := by + apply continuous_of_dominated (bound:=fun z => 2*‖field B z‖^2) + (fun t => (continuous_lineVariance A B t).aestronglyMeasurable) + (fun t => ae_of_all _ fun z => by + simpa only [Real.norm_eq_abs, sq, mul_assoc] using + abs_gibbsCov_le 1 (field A z+t • field B z) (field B z) (field B z)) + ((integrable_norm_field_sq B).const_mul 2) + exact ae_of_all _ fun z => (continuous_gibbsCov 1 (field B z) (field B z)).comp + (continuous_const.add (continuous_id.smul continuous_const)) + +lemma integral_meanLine (A B : ι → κ → ℝ) (a b : ℝ) : + (∫ t in a..b, meanLine A B t)=expectedLine A B b-expectedLine A B a := + intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hasDerivAt_expectedLine A B t) + ((continuous_meanLine A B).intervalIntegrable a b) + +lemma integral_varianceLine (A B : ι → κ → ℝ) (a b : ℝ) : + (∫ t in a..b, varianceLine A B t)=meanLine A B b-meanLine A B a := + intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hasDerivAt_meanLine A B t) + ((continuous_varianceLine A B).intervalIntegrable a b) + + + +lemma integral_meanLine_increment_le (A B : ι → κ → ℝ) (a b : ℝ) {δ : ℝ} (hδ : 0<δ) : + (∫ t in a..b, (meanLine A B (t+δ)-meanLine A B (t-δ))) ≤ + 2*δ*(meanLine A B (b+δ)-meanLine A B (a-δ)) := by + have hp : Continuous (fun t => meanLine A B (t+δ)) := + (continuous_meanLine A B).comp (continuous_id.add_const δ) + have hm : Continuous (fun t => meanLine A B (t-δ)) := + (continuous_meanLine A B).comp (continuous_id.sub continuous_const) + rw [intervalIntegral.integral_sub (hp.intervalIntegrable a b) (hm.intervalIntegrable a b), + intervalIntegral.integral_comp_add_right, intervalIntegral.integral_comp_sub_right, + integral_meanLine, integral_meanLine] + have hb := (convex_expectedLine A B).slope_le_deriv (Set.mem_univ (b-δ)) + (Set.mem_univ (b+δ)) (by linarith) (hasDerivAt_expectedLine A B (b+δ)).differentiableAt + have ha := (convex_expectedLine A B).deriv_le_slope (Set.mem_univ (a-δ)) + (Set.mem_univ (a+δ)) (by linarith) (hasDerivAt_expectedLine A B (a-δ)).differentiableAt + rw [(hasDerivAt_expectedLine A B (b+δ)).deriv] at hb + rw [(hasDerivAt_expectedLine A B (a-δ)).deriv] at ha + simp only [slope_def_field, show b+δ-(b-δ)=2*δ by ring, + show a+δ-(a-δ)=2*δ by ring] at hb ha + have hb' := (div_le_iff₀ (by positivity : 0<2*δ)).mp hb + have ha' := (le_div_iff₀ (by positivity : 0<2*δ)).mp ha + nlinarith + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKGaussian ParisiInterpolation ParisiFinite +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +omit [Nonempty ι] in +lemma meanLine_eq_energyMean (A B : ι → κ → ℝ) (t : ℝ) : + meanLine A B t=energyMean (affineCoeff A B t) B := by + simp only [meanLine, energyMean, gibbsMean, one_mul, field_affineCoeff] + +lemma energyDeviation_amplitude_bound (A B : ι → κ → ℝ) {a b δ V t : ℝ} + (hδ : 0<δ) (ht : t∈Set.Icc a b) + (hV : ∀ u∈Set.Icc (a-δ) (b+δ), pressureFluctuation (affineCoeff A B u)≤V) : + energyDeviation (affineCoeff A B t) B (energyMean (affineCoeff A B t) B) ≤ + varianceLine A B t+(1+4*V/δ)+(meanLine A B (t+δ)-meanLine A B (t-δ)) := by + have h1 := energyDeviation_le_thermal_add A B t (meanLine A B t) + change energyDeviation _ _ _ ≤ Real.sqrt (varianceLine A B t)+disorderDeviation A B t at h1 + rw [meanLine_eq_energyMean] at h1 + have h2 := disorderDeviation_le A B t hδ + have hp := hV (t+δ) ⟨by linarith [ht.1], by linarith [ht.2]⟩ + have hm := hV (t-δ) ⟨by linarith [ht.1], by linarith [ht.2]⟩ + have h0 := hV t ⟨by linarith [ht.1], by linarith [ht.2]⟩ + have h3 : (pressureFluctuation (affineCoeff A B (t+δ))+2*pressureFluctuation (affineCoeff A B t)+ + pressureFluctuation (affineCoeff A B (t-δ)))/δ ≤ 4*V/δ := by + exact div_le_div_of_nonneg_right (by linarith) hδ.le + have hs : Real.sqrt (varianceLine A B t)≤varianceLine A B t+1 := by + have hh := Real.sq_sqrt (varianceLine_nonneg A B t) + nlinarith [sq_nonneg (Real.sqrt (varianceLine A B t)-1)] + linarith + + + +theorem exists_amplitude_energyDeviation (A B : ι → κ → ℝ) {a b δ V : ℝ} + (hab : a varianceLine A B t+(1+4*V/δ)+ + (meanLine A B (t+δ)-meanLine A B (t-δ)) + have hc : Continuous S := (continuous_varianceLine A B).add continuous_const |>.add + (((continuous_meanLine A B).comp (continuous_id.add_const δ)).sub + ((continuous_meanLine A B).comp (continuous_id.sub continuous_const))) + obtain ⟨t, ht, hmin⟩ := isCompact_Icc.exists_isMinOn (Set.nonempty_Icc.mpr hab.le) hc.continuousOn + refine ⟨t, ht, ?_⟩ + have hlow := intervalIntegral.integral_mono_on (μ:=volume) hab.le + (continuous_const.intervalIntegrable a b) (hc.intervalIntegrable a b) (fun u hu => hmin hu) + rw [intervalIntegral.integral_const, smul_eq_mul] at hlow + have hp : Continuous (fun t => meanLine A B (t+δ)-meanLine A B (t-δ)) := + ((continuous_meanLine A B).comp (continuous_id.add_const δ)).sub + ((continuous_meanLine A B).comp (continuous_id.sub continuous_const)) + have he : (∫ u in a..b, S u) = meanLine A B b-meanLine A B a+(b-a)*(1+4*V/δ)+ + ∫ u in a..b, (meanLine A B (u+δ)-meanLine A B (u-δ)) := by + change (∫ u in a..b, (varianceLine A B u+(1+4*V/δ))+ + (meanLine A B (u+δ)-meanLine A B (u-δ))) = _ + have hi : IntervalIntegrable (fun u => varianceLine A B u+(1+4*V/δ)) volume a b := + ((continuous_varianceLine A B).add continuous_const).intervalIntegrable a b + rw [intervalIntegral.integral_add hi (hp.intervalIntegrable a b)] + rw [intervalIntegral.integral_add ((continuous_varianceLine A B).intervalIntegrable a b) + (continuous_const.intervalIntegrable a b), integral_varianceLine, intervalIntegral.integral_const, smul_eq_mul] + have hu := integral_meanLine_increment_le A B a b hδ + have hh := mul_le_mul_of_nonneg_left (energyDeviation_amplitude_bound A B hδ ht hV) (sub_nonneg.mpr hab.le) + change (b-a)*energyDeviation _ _ _≤(b-a)*S t at hh + rw [he] at hlow + linarith + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite GaussianConcentration + +lemma affineCoeff_perturbed (n p : ℕ) (β t : ℝ) : + affineCoeff (perturbedCoeff n p β 0) (perturbationNoise n p) t=perturbedCoeff n p β t := by + funext σ k + cases k <;> simp [affineCoeff, perturbedCoeff, perturbationNoise] + +lemma pSpin_meanLine (n p : ℕ) (β t : ℝ) : + meanLine (perturbedCoeff n p β 0) (perturbationNoise n p) t= + energyMean (perturbedCoeff n p β t) (perturbationNoise n p) := by + rw [meanLine_eq_energyMean, affineCoeff_perturbed] + +lemma pSpin_energyMean_bounds {n : ℕ} (hn : 0 (overlap (τ 0) (τ 1))^p)|≤1 := by + apply averagedReplica_abs_bound + intro τ + rw [abs_pow] + exact pow_le_one₀ (abs_nonneg _) (abs_overlap_le_one _ _) + rw [pSpin_energyMean hn] + rw [abs_le] at hb + constructor + · exact mul_nonneg ht (by linarith) + · nlinarith [mul_le_mul_of_nonneg_left hb.1 ht] + +lemma pSpin_pressureFluctuation_le {n : ℕ} (hn : 0 ?_⟩ + have hgg := pSpinGGDefect_bound hn p β t i f (by norm_num : (0:ℝ)≤1) hf + rw [one_mul, abs_mul, abs_of_nonneg (le_trans hs.le ht.1)] at hgg + have ha := mul_le_mul_of_nonneg_right ht.1 (abs_nonneg (pSpinGGDefect p β t i f)) + apply (le_div_iff₀ hs).mpr + nlinarith only [ha, hgg, h] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + + + +def eighthRootScale (n : ℕ) : ℝ := Real.sqrt (Real.sqrt (Real.sqrt (n:ℝ))) + +lemma eighthRootScale_nonneg (n : ℕ) : 0≤eighthRootScale n := Real.sqrt_nonneg _ + +lemma eighthRootScale_pow_eight (n : ℕ) : (eighthRootScale n)^8=(n:ℝ) := by + have h1 := Real.sq_sqrt (Real.sqrt_nonneg (Real.sqrt (n:ℝ))) + have h2 := Real.sq_sqrt (Real.sqrt_nonneg (n:ℝ)) + have h3 := Real.sq_sqrt (Nat.cast_nonneg n) + change eighthRootScale n^2=Real.sqrt (Real.sqrt (n:ℝ)) at h1 + calc + eighthRootScale n^8=(eighthRootScale n^2)^4 := by ring + _=(Real.sqrt (Real.sqrt (n:ℝ))^2)^2 := by rw [h1]; ring + _=(n:ℝ) := by rw [h2, h3] + +lemma one_le_eighthRootScale {n : ℕ} (hn : 0 (h r i f hf).trans (eighthRoot_GG_bound hn β)⟩ + + + +def genericPSpinAmplitude (n p : ℕ) (β : ℝ) : ℝ := + if hn : 0 pSpinGGDefect (p n) β (genericPSpinAmplitude n (p n) β) (i n) (f n)) + atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + simp only [Real.norm_eq_abs] + refine squeeze_zero' (g:=fun n => (29+4*|β|)/eighthRootScale n) (Eventually.of_forall fun n => abs_nonneg _) ?_ ?_ + · filter_upwards [eventually_gt_atTop 0] with n hn + exact genericPSpinAmplitude_defect_le hn (p n) β (i n) (f n) (hf n) + · have h := (tendsto_inv_atTop_zero.comp tendsto_eighthRootScale).const_mul (29+4*|β|) + simpa only [mul_zero, div_eq_mul_inv, Function.comp_apply] using h + +lemma tendsto_genericPSpin_amplitude_squared_density (p : ℕ → ℕ) (β : ℝ) : + Tendsto (fun n => (genericPSpinAmplitude n (p n) β)^2/(n:ℝ)) atTop (𝓝 0) := by + have hr : Tendsto (fun n => (eighthRootScale n)⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp tendsto_eighthRootScale + have hlim : Tendsto (fun n => 4/(eighthRootScale n^2)) atTop (𝓝 0) := by + simpa only [zero_pow (by decide : 2≠0), mul_zero, inv_pow, div_eq_mul_inv] using (hr.pow 2).const_mul 4 + refine squeeze_zero' (Eventually.of_forall fun n => div_nonneg (sq_nonneg _) (Nat.cast_nonneg n)) ?_ hlim + filter_upwards [eventually_gt_atTop 0] with n hn + exact eighthRoot_amplitude_pressure_bound hn (genericPSpinAmplitude_mem hn (p n) β) + + + +theorem tendsto_genericPSpin_pressureDensity_error (p : ℕ → ℕ) (β : ℝ) : + Tendsto (fun n => (expected (perturbedCoeff n (p n) β (genericPSpinAmplitude n (p n) β))- + expected (fun s e => β*skCoeff n s e))/(n:ℝ)) atTop (𝓝 0) := + tendsto_perturbed_pressureDensity_error p β _ (tendsto_genericPSpin_amplitude_squared_density p β) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {K : Type*} [Fintype K] [DecidableEq K] + +abbrev MixedIndex (n : ℕ) (d : K → ℕ) := Edge n ⊕ (Σ k : K, Fin (d k) → Fin n) + + + +def mixedCoeff (n : ℕ) (d : K → ℕ) (β : ℝ) (x : K → ℝ) (σ : Configuration n) : + MixedIndex n d → ℝ := + Sum.elim (fun e => β*skCoeff n σ e) (fun u => x u.1*pSpinCoeff n (d u.1) σ u.2) + + +def mixedNoise (n : ℕ) (d : K → ℕ) (k : K) (σ : Configuration n) : MixedIndex n d → ℝ := + Sum.elim (fun _ => 0) (fun u => if u.1=k then pSpinCoeff n (d u.1) σ u.2 else 0) + +omit [DecidableEq K] in +lemma mixedCoeff_kernel {n : ℕ} (hn : 0 β*skCoeff n s e) σ τ+ + (∑ k, kernel (fun s u => x k*pSpinCoeff n (d k) s u) σ τ)=_ + simp_rw [kernel_scale, pSpinCoeff_kernel hn] + rw [kernel, coeff_covariance hn] + ring + +lemma mixedNoise_crossCov {n : ℕ} (hn : 0 simp [mixedCoeff, skCoeff, abs_mul, spin_abs] + | inr u => simp [mixedCoeff, abs_mul, pSpinCoeff_abs] + +omit [DecidableEq K] in +lemma mixedCoeff_diag {n : ℕ} (hn : 0 false) + (fun τ a => mixedCoeff_abs n d β x τ (fun _ => false) a) + rw [mixedCoeff_diag hn] at hv + exact (GaussianConcentration.integral_abs_centered_le_sqrt_variance + (GaussianConcentration.memLp_logPartition_field _)).trans (Real.sqrt_le_sqrt hv) + +omit [Fintype K] in +lemma affineCoeff_mixed_update (n : ℕ) (d : K → ℕ) (β : ℝ) (x : K → ℝ) (k : K) (t : ℝ) : + affineCoeff (mixedCoeff n d β (Function.update x k 0)) (mixedNoise n d k) t= + mixedCoeff n d β (Function.update x k t) := by + funext σ a + cases a with + | inl e => simp [affineCoeff, mixedCoeff, mixedNoise] + | inr u => + by_cases h : u.1=k + · subst k + simp [affineCoeff, mixedCoeff, mixedNoise] + · simp [affineCoeff, mixedCoeff, mixedNoise, h] + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/Time.lean b/lean/OAI/Probability/ParisiFinite/Time.lean new file mode 100644 index 0000000000000000000000000000000000000000..2d609e1d42ec7515ede0be374473a7b9b7047400 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/Time.lean @@ -0,0 +1,676 @@ +import Mathlib + +namespace OAI + +/-! Time. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiPath + +abbrev Time := Icc (0 : ℝ) 1 +abbrev Path := C(Time, ℝ) + +def extend (X : Path) (t : ℝ) : ℝ := X (projIcc 0 1 zero_le_one t) + +lemma continuous_extend (X : Path) : Continuous (extend X) := + X.continuous.comp continuous_projIcc + +lemma extend_of_mem (X : Path) {t : ℝ} (ht : t ∈ Icc 0 1) : + extend X t = X ⟨t,ht⟩ := by + simp only [extend, projIcc_of_mem zero_le_one ht] + +structure Drift (K M : ℝ≥0) where + val : ℝ → ℝ → ℝ + measurable : Measurable (uncurry val) + bound : ∀ t x, ‖val t x‖ ≤ M + lipschitz : ∀ t, LipschitzWith K (val t) + +variable {K M : ℝ≥0} + +lemma integrable_comp (b : Drift K M) (X : Path) (a c : ℝ) : + IntervalIntegrable (fun t => b.val t (extend X t)) volume a c := by + refine (intervalIntegrable_const (c := (M : ℝ))).mono_fun' ?_ ?_ + · exact (b.measurable.comp (measurable_id.prodMk + (continuous_extend X).measurable)).aestronglyMeasurable + · exact Filter.Eventually.of_forall fun t => b.bound t _ + +def next (b : Drift K M) (W X : Path) : Path where + toFun t := W t + ∫ s in (0 : ℝ)..(t : ℝ), b.val s (extend X s) + continuous_toFun := W.continuous.add <| + (intervalIntegral.continuous_primitive (integrable_comp b X) 0).comp continuous_subtype_val + +@[simp] lemma next_apply (b : Drift K M) (W X : Path) (t : Time) : + next b W X t = W t + ∫ s in (0 : ℝ)..(t : ℝ), b.val s (extend X s) := rfl + +lemma dist_iterate_apply (b : Drift K M) (W X Y : Path) (n : ℕ) (t : Time) : + dist (((next b W)^[n]) X t) (((next b W)^[n]) Y t) ≤ + (K : ℝ)^n * (t : ℝ)^n / n.factorial * dist X Y := by + induction n generalizing t with + | zero => simpa using ContinuousMap.dist_apply_le_dist (f := X) (g := Y) t + | succ n ih => + rw [iterate_succ_apply', iterate_succ_apply', dist_eq_norm, next_apply, next_apply, + add_sub_add_left_eq_sub, ← intervalIntegral.integral_sub + (integrable_comp b _ _ _) (integrable_comp b _ _ _)] + calc + _ ≤ ∫ s in (0 : ℝ)..(t : ℝ), + (K : ℝ)^(n+1) * s^n / n.factorial * dist X Y := by + apply intervalIntegral.norm_integral_le_of_norm_le t.property.1 + · exact Filter.Eventually.of_forall fun s hs => by + have hs' : s ∈ Icc (0 : ℝ) 1 := ⟨hs.1.le, hs.2.trans t.property.2⟩ + rw [← dist_eq_norm, extend_of_mem _ hs', extend_of_mem _ hs'] + calc + _ ≤ K * dist (((next b W)^[n]) X ⟨s,hs'⟩) + (((next b W)^[n]) Y ⟨s,hs'⟩) := (b.lipschitz s).dist_le_mul _ _ + _ ≤ K * ((K : ℝ)^n * s^n / n.factorial * dist X Y) := + mul_le_mul_of_nonneg_left (ih ⟨s,hs'⟩) K.coe_nonneg + _ = _ := by ring + · exact (by fun_prop : Continuous (fun s : ℝ => + (K : ℝ)^(n+1) * s^n / n.factorial * dist X Y)).intervalIntegrable _ _ + _ = (K : ℝ)^(n+1) * (t : ℝ)^(n+1) / (n+1).factorial * dist X Y := by + rw [intervalIntegral.integral_mul_const, intervalIntegral.integral_div, + intervalIntegral.integral_const_mul, integral_pow] + simp only [zero_pow (Nat.succ_ne_zero n), sub_zero, Nat.factorial_succ, + Nat.cast_mul, Nat.cast_add, Nat.cast_one] + field_simp + +lemma dist_iterate (b : Drift K M) (W X Y : Path) (n : ℕ) : + dist (((next b W)^[n]) X) (((next b W)^[n]) Y) ≤ + (K : ℝ)^n / n.factorial * dist X Y := by + apply (ContinuousMap.dist_le (by positivity)).mpr + intro t + calc + _ ≤ (K : ℝ)^n * (t : ℝ)^n / n.factorial * dist X Y := dist_iterate_apply b W X Y n t + _ ≤ (K : ℝ)^n * 1^n / n.factorial * dist X Y := by + gcongr + · exact t.property.1 + · exact t.property.2 + _ = _ := by simp + +lemma exists_contracting_iterate (b : Drift K M) : + ∃ (n : ℕ) (C : ℝ≥0), ∀ W : Path, ContractingWith C (next b W)^[n] := by + obtain ⟨n,hn⟩ := (FloorSemiring.tendsto_pow_div_factorial_atTop (K : ℝ)).eventually + (gt_mem_nhds zero_lt_one) |>.exists + refine ⟨n,⟨(K : ℝ)^n / n.factorial, by positivity⟩,fun W => ?_⟩ + exact ⟨hn, LipschitzWith.of_dist_le_mul fun X Y => dist_iterate b W X Y n⟩ + +lemma exists_solution (b : Drift K M) (W : Path) : + ∃ X : Path, ∀ t : Time, + X t = W t + ∫ s in (0 : ℝ)..(t : ℝ), b.val s (extend X s) := by + obtain ⟨n,C,h⟩ := exists_contracting_iterate b + refine ⟨(h W).fixedPoint, fun t => ?_⟩ + exact (congrArg (fun X : Path => X t) (h W).isFixedPt_fixedPoint_iterate).symm + +lemma isFixedPt_iff (b : Drift K M) (W X : Path) : + IsFixedPt (next b W) X ↔ ∀ t : Time, + X t = W t + ∫ s in (0 : ℝ)..(t : ℝ), b.val s (extend X s) := by + constructor + · intro h t + exact (congrArg (fun Y : Path => Y t) h).symm + · intro h + ext t + exact (h t).symm + +def solution (b : Drift K M) (W : Path) : Path := (exists_solution b W).choose + +lemma solution_eq (b : Drift K M) (W : Path) (t : Time) : + solution b W t = W t + ∫ s in (0 : ℝ)..(t : ℝ), + b.val s (extend (solution b W) s) := (exists_solution b W).choose_spec t + +lemma solution_fixed (b : Drift K M) (W : Path) : + IsFixedPt (next b W) (solution b W) := + (isFixedPt_iff b W _).mpr (solution_eq b W) + +lemma solution_unique (b : Drift K M) (W X : Path) + (hX : ∀ t : Time, X t = W t + ∫ s in (0 : ℝ)..(t : ℝ), b.val s (extend X s)) : + X = solution b W := by + obtain ⟨n,C,h⟩ := exists_contracting_iterate b + exact (h W).fixedPoint_unique' ((isFixedPt_iff b W X).mpr hX |>.iterate n) + ((solution_fixed b W).iterate n) + +@[simp] lemma solution_zero (b : Drift K M) (W : Path) : + solution b W ⟨0,by simp⟩ = W ⟨0,by simp⟩ := by + rw [solution_eq] + simp + +lemma dist_next_driver (b : Drift K M) (W V X : Path) : + dist (next b W X) (next b V X) ≤ dist W V := by + apply (ContinuousMap.dist_le dist_nonneg).mpr + intro t + simpa only [next_apply, dist_add_right] using + ContinuousMap.dist_apply_le_dist (f := W) (g := V) t + +lemma dist_next (b : Drift K M) (W V X Y : Path) : + dist (next b W X) (next b V Y) ≤ dist W V + K * dist X Y := by + calc + _ ≤ dist (next b W X) (next b V X) + dist (next b V X) (next b V Y) := + dist_triangle _ _ _ + _ ≤ dist W V + K * dist X Y := add_le_add (dist_next_driver b W V X) + (by simpa using dist_iterate b V X Y 1) + +def amplification (K : ℝ≥0) : ℕ → ℝ≥0 + | 0 => 0 + | n+1 => 1 + K * amplification K n + +lemma dist_iterate_drivers (b : Drift K M) (W V X : Path) (n : ℕ) : + dist ((next b W)^[n] X) ((next b V)^[n] X) ≤ + amplification K n * dist W V := by + induction n with + | zero => simp [amplification] + | succ n ih => + rw [iterate_succ_apply',iterate_succ_apply'] + calc + _ ≤ dist W V + K * dist ((next b W)^[n] X) ((next b V)^[n] X) := + dist_next b W V _ _ + _ ≤ dist W V + K * (amplification K n * dist W V) := by gcongr + _ = amplification K (n+1) * dist W V := by + simp only [amplification,NNReal.coe_add,NNReal.coe_one,NNReal.coe_mul] + ring + +lemma exists_lipschitz_solution (b : Drift K M) : + ∃ L : ℝ≥0, LipschitzWith L (solution b) := by + obtain ⟨n,C,h⟩ := exists_contracting_iterate b + have hC : (C : ℝ) < 1 := (h (0 : Path)).1 + let L : ℝ≥0 := ⟨(amplification K n : ℝ) / (1-C), by positivity⟩ + refine ⟨L, LipschitzWith.of_dist_le_mul fun W V => ?_⟩ + calc + _ ≤ dist (solution b W) ((next b V)^[n] (solution b W)) / (1-C) := + (h V).dist_le_of_fixedPoint _ ((solution_fixed b V).iterate n) + _ = dist ((next b W)^[n] (solution b W)) + ((next b V)^[n] (solution b W)) / (1-C) := by + rw [(solution_fixed b W).iterate n] + _ ≤ (amplification K n * dist W V) / (1-C) := + div_le_div_of_nonneg_right (dist_iterate_drivers b W V _ n) (by linarith) + _ = (L : ℝ) * dist W V := by + change _ = ((amplification K n : ℝ) / (1-(C : ℝ))) * dist W V + ring + +lemma continuous_solution (b : Drift K M) : Continuous (solution b) := + (exists_lipschitz_solution b).choose_spec.continuous + + +lemma iterate_agree_until (b : Drift K M) (W V X : Path) (T : ℝ) + (hWV : ∀ t : Time, (t : ℝ) ≤ T → W t = V t) (n : ℕ) + (t : Time) (ht : (t : ℝ) ≤ T) : + (next b W)^[n] X t = (next b V)^[n] X t := by + induction n generalizing t with + | zero => rfl + | succ n ih => + rw [iterate_succ_apply',iterate_succ_apply',next_apply,next_apply,hWV t ht] + congr 1 + apply intervalIntegral.integral_congr + intro s hs + rw [uIcc_of_le t.property.1] at hs + have hs' : s ∈ Icc (0 : ℝ) 1 := ⟨hs.1,hs.2.trans t.property.2⟩ + dsimp only + rw [extend_of_mem _ hs',extend_of_mem _ hs',ih ⟨s,hs'⟩ (hs.2.trans ht)] + + +lemma solution_agree_until (b : Drift K M) (W V : Path) (T : ℝ) + (hWV : ∀ t : Time, (t : ℝ) ≤ T → W t = V t) + (t : Time) (ht : (t : ℝ) ≤ T) : + solution b W t = solution b V t := by + have hh (n : ℕ) : dist (solution b W t) (solution b V t) ≤ + (K : ℝ)^n / n.factorial * dist (solution b W) (solution b V) := by + have heq : (next b W)^[n] (solution b V) t = solution b V t := by + rw [iterate_agree_until b W V _ T hWV n t ht, (solution_fixed b V).iterate n] + have h := (ContinuousMap.dist_apply_le_dist + (f := (next b W)^[n] (solution b W)) + (g := (next b W)^[n] (solution b V)) t).trans + (dist_iterate b W (solution b W) (solution b V) n) + rwa [(solution_fixed b W).iterate n,heq] at h + apply dist_le_zero.mp + have hlim := (FloorSemiring.tendsto_pow_div_factorial_atTop (K : ℝ)).mul_const + (dist (solution b W) (solution b V)) + exact ge_of_tendsto (by simpa using hlim) (Filter.Eventually.of_forall hh) + +lemma norm_solution_sub_driver (b : Drift K M) (W : Path) (t : Time) : + ‖solution b W t - W t‖ ≤ M * (t : ℝ) := by + rw [solution_eq,add_sub_cancel_left] + simpa only [sub_zero,abs_of_nonneg t.property.1] using + (intervalIntegral.norm_integral_le_of_norm_le_const (a := (0 : ℝ)) (b := (t : ℝ)) + (C := (M : ℝ)) (fun s _ => b.bound s (extend (solution b W) s))) + + + +lemma tendsto_iterate_solution (b : Drift K M) (W X : Path) : + Tendsto (fun n => (next b W)^[n] X) atTop (𝓝 (solution b W)) := by + apply tendsto_iff_dist_tendsto_zero.mpr + apply squeeze_zero (g := fun n => (K : ℝ)^n / n.factorial * dist X (solution b W)) + (fun n => dist_nonneg) + · intro n + have h := dist_iterate b W X (solution b W) n + rwa [(solution_fixed b W).iterate n] at h + · simpa using (FloorSemiring.tendsto_pow_div_factorial_atTop (K : ℝ)).mul_const + (dist X (solution b W)) + +lemma measurable_extend_family {Ω : Type*} [MeasurableSpace Ω] + (X : Ω → Path) (hX : ∀ t : Time, Measurable (fun ω => X ω t)) : + Measurable (fun q : Ω × ℝ => extend (X q.1) q.2) := by + have h := measurable_uncurry_of_continuous_of_measurable + (u := fun s ω => extend (X ω) s) (fun ω => continuous_extend (X ω)) + (fun s => hX (projIcc 0 1 zero_le_one s)) + exact h.comp measurable_swap + +lemma measurable_next_eval {Ω : Type*} [MeasurableSpace Ω] + (b : Drift K M) (W X : Ω → Path) + (hW : ∀ t : Time, Measurable (fun ω => W ω t)) + (hX : ∀ t : Time, Measurable (fun ω => X ω t)) (t : Time) : + Measurable (fun ω => next b (W ω) (X ω) t) := by + have hm : Measurable (fun q : Ω × ℝ => b.val q.2 (extend (X q.1) q.2)) := + b.measurable.comp (measurable_snd.prodMk (measurable_extend_family X hX)) + simp only [next_apply, intervalIntegral.integral_of_le t.property.1] + exact (hW t).add hm.stronglyMeasurable.integral_prod_right'.measurable + + + +lemma measurable_solution_eval {Ω : Type*} [MeasurableSpace Ω] + (b : Drift K M) (W : Ω → Path) + (hW : ∀ t : Time, Measurable (fun ω => W ω t)) (t : Time) : + Measurable (fun ω => solution b (W ω) t) := by + have hm (n : ℕ) : ∀ t : Time, Measurable (fun ω => (next b (W ω))^[n] 0 t) := by + induction n with + | zero => intro t; exact measurable_const + | succ n ih => + intro t + simp only [iterate_succ_apply'] + exact measurable_next_eval b W _ hW ih t + apply measurable_of_tendsto_metrizable (fun n => hm n t) + refine tendsto_pi_nhds.mpr fun ω => ?_ + exact (by fun_prop : Continuous (fun X : Path => X t)).continuousAt.tendsto.comp + (tendsto_iterate_solution b (W ω) 0) + +lemma measurable_solution_family {Ω : Type*} [MeasurableSpace Ω] + (b : Drift K M) (W : Ω → Path) + (hW : ∀ t : Time, Measurable (fun ω => W ω t)) : + Measurable (fun q : Ω × ℝ => extend (solution b (W q.1)) q.2) := + measurable_extend_family _ (measurable_solution_eval b W hW) + + + +lemma aemeasurable_solution_eval {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + (b : Drift K M) (W : Ω → Path) + (hW : ∀ t : Time, AEMeasurable (fun ω => W ω t) P) (t : Time) : + AEMeasurable (fun ω => solution b (W ω) t) P := by + have h : @Measurable (NullMeasurableSpace Ω P) ℝ _ _ + (fun ω => solution b (W ω) t) := + @measurable_solution_eval K M (NullMeasurableSpace Ω P) + NullMeasurableSpace.instMeasurableSpace b W + (fun t => (hW t).nullMeasurable.measurable') t + exact (show NullMeasurable (fun ω => solution b (W ω) t) P from h).aemeasurable + + + +def mesh (n : ℕ) : ℝ := 1/(n+1:ℕ) +def grid (n k : ℕ) : ℝ := (k:ℝ)*mesh n + +def euler (b : Drift K M) (W : Path) (n : ℕ) : ℕ → ℝ + | 0 => extend W 0 + | k+1 => euler b W n k + (extend W (grid n (k+1))-extend W (grid n k)) + + mesh n * b.val (grid n k) (euler b W n k) + +lemma mesh_pos (n : ℕ) : 0 < mesh n := by dsimp [mesh]; positivity +lemma grid_zero (n : ℕ) : grid n 0 = 0 := by simp [grid] +lemma grid_succ (n k : ℕ) : grid n (k+1)=grid n k+mesh n := by + simp only [grid,Nat.cast_add,Nat.cast_one]; ring +lemma grid_end (n : ℕ) : grid n (n+1)=1 := by + dsimp [grid,mesh] + field_simp +lemma grid_mono (n : ℕ) : Monotone (grid n) := by + intro k l h + exact mul_le_mul_of_nonneg_right (by exact_mod_cast h) (mesh_pos n).le +lemma grid_mem (n k : ℕ) (hk : k ≤ n+1) : grid n k ∈ Icc (0:ℝ) 1 := by + refine ⟨mul_nonneg (Nat.cast_nonneg _) (mesh_pos n).le,?_⟩ + simpa only [grid_end] using grid_mono n hk + +def freeze (n : ℕ) (t : ℝ) : ℝ := grid n ⌊t*(n+1:ℕ)⌋₊ + +lemma measurable_freeze (n : ℕ) : Measurable (freeze n) := by + unfold freeze grid + fun_prop + +lemma freeze_tendsto {t : ℝ} (ht : 0 ≤ t) : Tendsto (fun n => freeze n t) atTop (𝓝 t) := by + have h : Tendsto (fun n : ℕ => (n+1:ℕ):ℕ → ℝ) atTop atTop := by + exact tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + simpa only [freeze,grid,mesh,div_eq_mul_inv,Function.comp_def,one_mul] using + (tendsto_nat_floor_mul_div_atTop ht).comp h + +lemma freeze_on_cell (n k : ℕ) {t : ℝ} + (ht : t ∈ Ico (grid n k) (grid n (k+1))) : freeze n t = grid n k := by + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + have hk : (k:ℝ) ≤ t*(n+1:ℕ) := by + have hh := ht.1 + dsimp [grid,mesh] at hh + rw [mul_one_div,div_le_iff₀ hn] at hh + exact hh + have hk' : t*(n+1:ℕ) < (k+1:ℕ) := by + have hh := ht.2 + dsimp [grid,mesh] at hh + rwa [mul_one_div,lt_div_iff₀ hn] at hh + unfold freeze + rw [(Nat.floor_eq_iff (show 0 ≤ t*(n+1:ℕ) by linarith)).mpr ⟨hk,by simpa only [Nat.cast_add,Nat.cast_one] using hk'⟩] + + +def residual (b : Drift K M) (X : Path) (n : ℕ) (t : ℝ) : ℝ := + ‖b.val t (extend X t)-b.val (freeze n t) (extend X (freeze n t))‖ + +def totalResidual (b : Drift K M) (X : Path) (n : ℕ) : ℝ := + ∫ t in (0:ℝ)..1,residual b X n t + +lemma measurable_reference (b : Drift K M) (X : Path) : + Measurable (fun t => b.val t (extend X t)) := + b.measurable.comp (measurable_id.prodMk (continuous_extend X).measurable) + +lemma measurable_residual (b : Drift K M) (X : Path) (n : ℕ) : + Measurable (residual b X n) := + ((measurable_reference b X).sub ((measurable_reference b X).comp (measurable_freeze n))).norm + +lemma residual_bound (b : Drift K M) (X : Path) (n : ℕ) (t : ℝ) : + residual b X n t ≤ 2*(M:ℝ) := by + have h1 := b.bound t (extend X t) + have h2 := b.bound (freeze n t) (extend X (freeze n t)) + exact (norm_sub_le _ _).trans (by linarith) + +lemma integrable_residual (b : Drift K M) (X : Path) (n : ℕ) (a c : ℝ) : + IntervalIntegrable (residual b X n) volume a c := by + apply (intervalIntegrable_const (c := 2*(M:ℝ))).mono_fun' + (measurable_residual b X n).aestronglyMeasurable + exact Eventually.of_forall fun t => by simpa only [residual,norm_norm] using residual_bound b X n t + +lemma totalResidual_nonneg (b : Drift K M) (X : Path) (n : ℕ) : + 0 ≤ totalResidual b X n := + intervalIntegral.integral_nonneg zero_le_one (fun _ _ => norm_nonneg _) + + + +lemma totalResidual_tendsto_zero (b : Drift K M) (X : Path) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → ContinuousAt (fun s => b.val s (extend X s)) t) : + Tendsto (totalResidual b X) atTop (𝓝 0) := by + have h := intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (a := (0:ℝ)) (b := 1) (μ := volume) (l := atTop) (F := residual b X) (f := fun _ => (0:ℝ)) + (fun _ => 2*(M:ℝ)) + (Eventually.of_forall fun n => (measurable_residual b X n).aestronglyMeasurable.restrict) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => by + simpa only [residual,norm_norm] using residual_bound b X n t) + (intervalIntegrable_const) ?_ + · change Tendsto (fun n => ∫ t in (0:ℝ)..1, residual b X n t) atTop (𝓝 0) + simpa only [intervalIntegral.integral_zero] using h + · filter_upwards [hc] with t ht hmem + rw [uIoc_of_le zero_le_one] at hmem + have hh := (ht ⟨hmem.1.le,hmem.2⟩).tendsto.comp (freeze_tendsto hmem.1.le) + simpa only [residual,Function.comp_def,sub_self,norm_zero] using ((tendsto_const_nhds (x := b.val t (extend X t))).sub hh).norm + +lemma finite_discrete_gronwall {u r : ℕ → ℝ} {c : ℝ} {N : ℕ} + (hu0 : ∀ k,0 ≤ u k) (hr : ∀ k,0 ≤ r k) (hc : 0 ≤ c) + (hs : ∀ k hc) (fun j _ => hr j) (Nat.zero_le k) + simpa only [v,ite_eq_left hk,ite_eq_left (Nat.zero_le N),Nat.Ico_zero_eq_range, + Finset.sum_const,Finset.card_range,nsmul_eq_mul] using hh + +lemma solution_increment (b : Drift K M) (W : Path) {t s : ℝ} + (ht : t ∈ Icc (0:ℝ) 1) (hs : s ∈ Icc (0:ℝ) 1) : + extend (solution b W) s-extend (solution b W) t = + extend W s-extend W t+∫ r in t..s,b.val r (extend (solution b W) r) := by + have h0 := solution_eq b W ⟨t,ht⟩ + have h1 := solution_eq b W ⟨s,hs⟩ + have hi := intervalIntegral.integral_add_adjacent_intervals + (integrable_comp b (solution b W) 0 t) (integrable_comp b (solution b W) t s) + rw [extend_of_mem _ ht,extend_of_mem _ hs,extend_of_mem _ ht,extend_of_mem _ hs] + linarith + +def localResidual (b : Drift K M) (X : Path) (n k : ℕ) : ℝ := + ∫ s in (grid n k)..(grid n (k+1)), + ‖b.val s (extend X s)-b.val (grid n k) (extend X (grid n k))‖ + +lemma localResidual_nonneg (b : Drift K M) (X : Path) (n k : ℕ) : + 0 ≤ localResidual b X n k := + intervalIntegral.integral_nonneg (grid_mono n (Nat.le_succ k)) (fun _ _ => norm_nonneg _) + +lemma localResidual_eq_integral (b : Drift K M) (X : Path) (n k : ℕ) : + localResidual b X n k = ∫ s in (grid n k)..(grid n (k+1)),residual b X n s := by + have hnot : ∀ᵐ s ∂volume,s ≠ grid n (k+1) := by simp [ae_iff,measure_singleton] + apply intervalIntegral.integral_congr_ae + filter_upwards [hnot] with s hs hmem + rw [uIoc_of_le (grid_mono n (Nat.le_succ k))] at hmem + have hf := freeze_on_cell n k ⟨hmem.1.le,hmem.2.lt_of_ne hs⟩ + simp only [residual,hf] + +lemma sum_localResidual (b : Drift K M) (X : Path) (n : ℕ) : + (∑ k ∈ Finset.range (n+1),localResidual b X n k)=totalResidual b X n := by + simp_rw [localResidual_eq_integral] + rw [intervalIntegral.sum_integral_adjacent_intervals (fun k _ => integrable_residual b X n _ _), + grid_zero,grid_end] + rfl + +lemma euler_error_step (b : Drift K M) (W : Path) (n k : ℕ) (hk : k b.val s (extend X s)-b.val (grid n k) (extend X (grid n k))) + (μ := volume) (grid_mono n (Nat.le_succ k)) + rw [he] at hn + have hb := (b.lipschitz (grid n k)).dist_le_mul (euler b W n k) (extend X (grid n k)) + simp only [dist_eq_norm] at hb + have heq : euler b W n (k+1)-extend X (grid n (k+1)) = + (euler b W n k-extend X (grid n k))+ + mesh n*(b.val (grid n k) (euler b W n k)-b.val (grid n k) (extend X (grid n k)))- + ((∫ s in (grid n k)..(grid n (k+1)),b.val s (extend X s))- + mesh n*b.val (grid n k) (extend X (grid n k))) := by + dsimp only [euler] + dsimp only [X] at * + linarith + change _ ≤ (1+(K:ℝ)*mesh n)*‖euler b W n k-extend X (grid n k)‖+_ + rw [heq] + have hn' := norm_add_le (euler b W n k-extend X (grid n k)) + (mesh n*(b.val (grid n k) (euler b W n k)-b.val (grid n k) (extend X (grid n k)))) + have hn'' := norm_sub_le + ((euler b W n k-extend X (grid n k))+ + mesh n*(b.val (grid n k) (euler b W n k)-b.val (grid n k) (extend X (grid n k)))) + ((∫ s in (grid n k)..(grid n (k+1)),b.val s (extend X s))- + mesh n*b.val (grid n k) (extend X (grid n k))) + rw [norm_mul,Real.norm_of_nonneg (mesh_pos n).le] at hn' + change _ ≤ localResidual b X n k at hn + nlinarith [mul_le_mul_of_nonneg_left hb (mesh_pos n).le] + + + +lemma euler_error_bound (b : Drift K M) (W : Path) (n k : ℕ) (hk : k ≤ n+1) : + ‖euler b W n k-extend (solution b W) (grid n k)‖ ≤ + totalResidual b (solution b W) n * Real.exp (K:ℝ) := by + have hz : ‖euler b W n 0-extend (solution b W) (grid n 0)‖ = 0 := by + simp only [euler,grid_zero,extend_of_mem _ (show (0:ℝ) ∈ Icc (0:ℝ) 1 by simp), + solution_zero,sub_self,norm_zero] + have h := finite_discrete_gronwall (N := n+1) + (u := fun k => ‖euler b W n k-extend (solution b W) (grid n k)‖) + (r := localResidual b (solution b W) n) (c := (K:ℝ)*mesh n) + (fun _ => norm_nonneg _) (localResidual_nonneg b (solution b W) n) + (mul_nonneg K.coe_nonneg (mesh_pos n).le) (fun j hj => euler_error_step b W n j hj) hk + rw [hz,zero_add] at h + have hsum : (∑ j ∈ Finset.range k,localResidual b (solution b W) n j) ≤ + totalResidual b (solution b W) n := by + rw [← sum_localResidual] + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono hk) + (fun j _ _ => localResidual_nonneg b (solution b W) n j) + have hexp : Real.exp ((k:ℝ)*((K:ℝ)*mesh n)) ≤ Real.exp (K:ℝ) := by + apply Real.exp_le_exp.mpr + have ht := (grid_mem n k hk).2 + dsimp only [grid] at ht + nlinarith [mul_le_mul_of_nonneg_left ht K.coe_nonneg] + exact h.trans (mul_le_mul hsum hexp (Real.exp_pos _).le + (totalResidual_nonneg b (solution b W) n)) + +lemma euler_terminal_tendsto (b : Drift K M) (W : Path) + (hc : ∀ᵐ t ∂volume, t ∈ Icc (0:ℝ) 1 → + ContinuousAt (fun s => b.val s (extend (solution b W) s)) t) : + Tendsto (fun n => euler b W n (n+1)) atTop (𝓝 (extend (solution b W) 1)) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + apply squeeze_zero (fun _ => norm_nonneg _) + (fun n => by simpa only [grid_end] using euler_error_bound b W n (n+1) le_rfl) + simpa only [zero_mul] using (totalResidual_tendsto_zero b (solution b W) hc).mul_const + (Real.exp (K:ℝ)) + + +def scaledDrift (b : Drift K M) (T : ℝ≥0) : Drift (T*K) (T*M) where + val t x := (T:ℝ)*b.val ((T:ℝ)*t) x + measurable := (b.measurable.comp ((measurable_fst.const_mul (T:ℝ)).prodMk + measurable_snd)).const_mul (T:ℝ) + bound t x := by + rw [norm_mul,Real.norm_of_nonneg T.coe_nonneg,NNReal.coe_mul] + exact mul_le_mul_of_nonneg_left (b.bound _ _) T.coe_nonneg + lipschitz t := LipschitzWith.of_dist_le_mul fun x y => by + rw [dist_eq_norm,← mul_sub,norm_mul,Real.norm_of_nonneg T.coe_nonneg,NNReal.coe_mul] + simpa only [dist_eq_norm,mul_assoc] using + mul_le_mul_of_nonneg_left ((b.lipschitz ((T:ℝ)*t)).dist_le_mul x y) T.coe_nonneg + +def scaledPath (T : ℝ≥0) (X : Path) : Path where + toFun t := extend X ((T:ℝ)*(t:ℝ)) + continuous_toFun := (continuous_extend X).comp (continuous_const.mul continuous_subtype_val) + +lemma extend_scaledPath (T : ℝ≥0) (X : Path) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : + extend (scaledPath T X) t = extend X ((T:ℝ)*t) := by + rw [extend_of_mem _ ht] + rfl + +lemma scaled_time_mem {T : ℝ≥0} (hT : T ≤ 1) {t : ℝ} (ht : t ∈ Icc (0:ℝ) 1) : + (T:ℝ)*t ∈ Icc (0:ℝ) 1 := by + refine ⟨mul_nonneg T.coe_nonneg ht.1,?_⟩ + exact (mul_le_mul_of_nonneg_left ht.2 T.coe_nonneg).trans (by simpa only [mul_one] using (show (T:ℝ) ≤ 1 from NNReal.coe_le_coe.mpr hT)) + +lemma solution_scaled (b : Drift K M) (W : Path) {T : ℝ≥0} (hT : T ≤ 1) : + solution (scaledDrift b T) (scaledPath T W) = scaledPath T (solution b W) := by + symm + apply solution_unique + intro t + change extend (solution b W) ((T:ℝ)*(t:ℝ)) = extend W ((T:ℝ)*(t:ℝ)) + + ∫ s in (0:ℝ)..(t:ℝ),(T:ℝ)*b.val ((T:ℝ)*s) (extend (scaledPath T (solution b W)) s) + have he : (∫ s in (0:ℝ)..(t:ℝ),(T:ℝ)*b.val ((T:ℝ)*s) + (extend (scaledPath T (solution b W)) s)) = + ∫ s in (0:ℝ)..((T:ℝ)*(t:ℝ)),b.val s (extend (solution b W) s) := by + calc + _ = ∫ s in (0:ℝ)..(t:ℝ),(T:ℝ)*b.val ((T:ℝ)*s) + (extend (solution b W) ((T:ℝ)*s)) := by + apply intervalIntegral.integral_congr + intro s hs + rw [uIcc_of_le t.property.1] at hs + dsimp only + rw [extend_scaledPath T _ ⟨hs.1,hs.2.trans t.property.2⟩] + _ = _ := by + rw [intervalIntegral.integral_const_mul] + simpa only [smul_eq_mul,mul_zero] using + intervalIntegral.smul_integral_comp_mul_left + (fun s => b.val s (extend (solution b W) s)) (a := (0:ℝ)) (b := (t:ℝ)) (T:ℝ) + rw [he,extend_of_mem _ (scaled_time_mem hT t.property), + extend_of_mem _ (scaled_time_mem hT t.property)] + exact solution_eq b W _ + + +def horizonEuler (b : Drift K M) (W : Path) (T : ℝ≥0) (n k : ℕ) : ℝ := + euler (scaledDrift b T) (scaledPath T W) n k + +lemma horizonEuler_zero (b : Drift K M) (W : Path) (T : ℝ≥0) (n : ℕ) : + horizonEuler b W T n 0 = extend W 0 := by + simp only [horizonEuler,euler,extend_scaledPath _ _ (show (0:ℝ) ∈ Icc (0:ℝ) 1 by simp),mul_zero] + +lemma horizonEuler_succ (b : Drift K M) (W : Path) (T : ℝ≥0) (n k : ℕ) (hk : k (scaledDrift b T).val s + (extend (solution (scaledDrift b T) (scaledPath T W)) s)) t) : + Tendsto (fun n => horizonEuler b W T n (n+1)) atTop + (𝓝 (extend (solution b W) T)) := by + have h := euler_terminal_tendsto (scaledDrift b T) (scaledPath T W) hc + rw [solution_scaled b W hT,extend_scaledPath T _ (show (1:ℝ) ∈ Icc (0:ℝ) 1 by simp),mul_one] at h + exact h + +lemma norm_euler_sub_driver (b : Drift K M) (W : Path) (n k : ℕ) : + ‖euler b W n k-extend W (grid n k)‖ ≤ (k:ℝ)*mesh n*(M:ℝ) := by + induction k with + | zero => simp [euler,grid_zero] + | succ k ih => + have he : euler b W n (k+1)-extend W (grid n (k+1)) = + (euler b W n k-extend W (grid n k))+mesh n*b.val (grid n k) (euler b W n k) := by + rw [euler] + ring + rw [he] + calc + _ ≤ ‖euler b W n k-extend W (grid n k)‖+ + ‖mesh n*b.val (grid n k) (euler b W n k)‖ := norm_add_le _ _ + _ ≤ (k:ℝ)*mesh n*(M:ℝ)+mesh n*(M:ℝ) := by + rw [norm_mul,Real.norm_of_nonneg (mesh_pos n).le] + exact add_le_add ih (mul_le_mul_of_nonneg_left (b.bound _ _) (mesh_pos n).le) + _ = _ := by simp only [Nat.cast_add,Nat.cast_one]; ring + +lemma euler_error_uniform_bound (b : Drift K M) (W : Path) (n k : ℕ) (hk : k ≤ n+1) : + ‖euler b W n k-extend (solution b W) (grid n k)‖ ≤ 2*(M:ℝ) := by + have h1 := norm_euler_sub_driver b W n k + have h2 := norm_solution_sub_driver b W ⟨grid n k,grid_mem n k hk⟩ + rw [← extend_of_mem _ (grid_mem n k hk),← extend_of_mem _ (grid_mem n k hk)] at h2 + have he : euler b W n k-extend (solution b W) (grid n k) = + (euler b W n k-extend W (grid n k))- + (extend (solution b W) (grid n k)-extend W (grid n k)) := by ring + rw [he] + have ht := (grid_mem n k hk).2 + have hn := norm_sub_le (euler b W n k-extend W (grid n k)) + (extend (solution b W) (grid n k)-extend W (grid n k)) + change _ ≤ (M:ℝ)*grid n k at h2 + change _ ≤ grid n k*(M:ℝ) at h1 + nlinarith [mul_le_mul_of_nonneg_left ht M.coe_nonneg] + +lemma aemeasurable_euler {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + (b : Drift K M) (W : Ω → Path) + (hW : ∀ t : Time,AEMeasurable (fun ω => W ω t) P) (n k : ℕ) : + AEMeasurable (fun ω => euler b (W ω) n k) P := by + have hw (t : ℝ) : AEMeasurable (fun ω => extend (W ω) t) P := + hW (projIcc 0 1 zero_le_one t) + induction k with + | zero => exact hw 0 + | succ k ih => + exact (ih.add ((hw _).sub (hw _))).add + (((b.measurable.comp (measurable_const.prodMk measurable_id)).comp_aemeasurable ih).const_mul _) + +lemma aemeasurable_scaledPath_eval {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + (W : Ω → Path) (hW : ∀ t : Time,AEMeasurable (fun ω => W ω t) P) + (T : ℝ≥0) (t : Time) : AEMeasurable (fun ω => scaledPath T (W ω) t) P := + hW (projIcc 0 1 zero_le_one ((T:ℝ)*(t:ℝ))) + +end ParisiPath + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/TimeCubicTest.lean b/lean/OAI/Probability/ParisiFinite/TimeCubicTest.lean new file mode 100644 index 0000000000000000000000000000000000000000..66c7b928076823bac473f9268b2dc0d4e37f6ef9 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/TimeCubicTest.lean @@ -0,0 +1,636 @@ +import Mathlib +import OAI.Probability.ParisiFinite.InnovationEulerMemLp + +namespace OAI + +/-! Time Cubic Test. -/ + +noncomputable section + +open MeasureTheory Filter Function Set +open scoped Topology NNReal +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +open ContinuousLinearMap +open scoped Convolution +namespace ParisiPath +open ProbabilityTheory +open scoped BigOperators ENNReal +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} + + + +structure TimeCubicTest where + val : ℝ → ℝ → ℝ + dt : ℝ → ℝ → ℝ + smooth : ∀ t, ContDiff ℝ 3 (val t) + c1 : ℝ≥0 + c2 : ℝ≥0 + c3 : ℝ≥0 + ct : ℝ≥0 + bound1 : ∀ t x, ‖deriv (val t) x‖≤c1 + bound2 : ∀ t x, ‖iteratedDeriv 2 (val t) x‖≤c2 + bound3 : ∀ t x, ‖iteratedDeriv 3 (val t) x‖≤c3 + boundT : ∀ t x, ‖dt t x‖≤ct + measT : Measurable (uncurry dt) + continuousT : ∀ t,Continuous (dt t) + jointD1 : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → + ∀ x,ContinuousAt (fun p : ℝ×ℝ => deriv (val p.1) p.2) (t,x) + jointD2 : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → + ∀ x,ContinuousAt (fun p : ℝ×ℝ => iteratedDeriv 2 (val p.1) p.2) (t,x) + integralT : ∀ a∈Icc (0:ℝ) 1,∀ b∈Icc (0:ℝ) 1,∀ x, + val b x-val a x=∫ t in a..b,dt t x + +def TimeCubicTest.slice (f : TimeCubicTest) (t : ℝ) : CubicTest where + val := f.val t + smooth := f.smooth t + c1 := f.c1 + c2 := f.c2 + c3 := f.c3 + bound1 := f.bound1 t + bound2 := f.bound2 t + bound3 := f.bound3 t + +lemma expected_kernel_measurable {g : ℝ → ℝ → ℝ} + (hg : Measurable (uncurry g)) {X : Ω → ℝ} (hX : AEMeasurable X P) [SFinite P] : + Measurable (fun t => ∫ ω,g t (X ω) ∂P) := by + have hh : Measurable (fun p : ℝ×Ω => g p.1 (hX.mk X p.2)) := + hg.comp (measurable_fst.prodMk (hX.measurable_mk.comp measurable_snd)) + have he : (fun t => ∫ ω,g t (X ω) ∂P)=(fun t => ∫ ω,g t (hX.mk X ω) ∂P) := by + funext t + exact integral_congr_ae (hX.ae_eq_mk.fun_comp (g t)) + rw [he] + exact hh.stronglyMeasurable.integral_prod_right.measurable + +lemma expected_kernel_interval_swap {g : ℝ → ℝ → ℝ} + (hg : Measurable (uncurry g)) {X : Ω → ℝ} (hX : AEMeasurable X P) + [IsProbabilityMeasure P] {C : ℝ} (hb : ∀ t x,‖g t x‖≤C) + {a c : ℝ} (hac : a≤c) : + (∫ ω,(∫ t in a..c,g t (X ω)) ∂P)=∫ t in a..c,∫ ω,g t (X ω) ∂P := by + have hm : Measurable (fun p : ℝ×Ω => g p.1 (hX.mk X p.2)) := + hg.comp (measurable_fst.prodMk (hX.measurable_mk.comp measurable_snd)) + have hi : Integrable (fun p : ℝ×Ω => g p.1 (hX.mk X p.2)) + ((volume.restrict (Ioc a c)).prod P) := by + apply (integrable_const C).mono' hm.aestronglyMeasurable + exact ae_of_all _ fun p => hb _ _ + simp only [intervalIntegral.integral_of_le hac] + calc + _ = ∫ ω,(∫ t in Ioc a c,g t (hX.mk X ω)) ∂P := by + apply integral_congr_ae + filter_upwards [hX.ae_eq_mk] with ω hω + simp only [hω] + _ = ∫ t in Ioc a c,∫ ω,g t (hX.mk X ω) ∂P := (integral_integral_swap hi).symm + _ = _ := by + apply integral_congr_ae + exact ae_of_all _ fun t => integral_congr_ae (hX.ae_eq_mk.fun_comp (g t)).symm + +end ParisiPath + +namespace ParisiPath +open ProbabilityTheory +open scoped BigOperators ENNReal +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + + +def timeFrozenGenerator (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : TimeCubicTest) (n : ℕ) (t : ℝ) : ℝ := + expectedFrozenGenerator P W b (f.slice (freeze n t)) n t + +def timeGenerator (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : TimeCubicTest) (t : ℝ) : ℝ := + expectedGenerator P W b (f.slice t) t + + +def timeFrozenDerivative (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : TimeCubicTest) (n : ℕ) (t : ℝ) : ℝ := + ∫ ω,f.dt t (euler b (brownianPath W ω) n (⌊t*(n+1:ℕ)⌋₊+1)) ∂P + +def timeDerivative (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : TimeCubicTest) (t : ℝ) : ℝ := + ∫ ω,f.dt t (extend (solution b (brownianPath W ω)) t) ∂P + +lemma timeFrozenGenerator_measurable (b : Drift K M) (f : TimeCubicTest) (n : ℕ) : + Measurable (timeFrozenGenerator P W b f n) := + (measurable_of_countable (f:=fun k : ℕ => ∫ ω,generator (f.slice (grid n k)) b (grid n k) + (euler b (brownianPath W ω) n k) ∂P)).comp (by fun_prop) + +lemma timeFrozenGenerator_bound (hW : IsBrownianReal W P) (b : Drift K M) + (f : TimeCubicTest) (n : ℕ) (t : ℝ) : + ‖timeFrozenGenerator P W b f n t‖≤(f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2 := + expectedFrozenGenerator_bound hW b (f.slice (freeze n t)) n t + +lemma timeFrozenDerivative_measurable (hW : IsBrownianReal W P) (b : Drift K M) + (f : TimeCubicTest) (n : ℕ) : Measurable (timeFrozenDerivative P W b f n) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hm : Measurable (fun p : ℕ×ℝ => ∫ ω,f.dt p.2 + (euler b (brownianPath W ω) n (p.1+1)) ∂P) := by + apply measurable_from_prod_countable_right + intro k + exact expected_kernel_measurable f.measT + (aemeasurable_euler b (brownianPath W) (brownianPath_aemeasurable_eval hW) n (k+1)) + exact hm.comp ((by fun_prop : Measurable (fun t : ℝ => ⌊t*(n+1:ℕ)⌋₊)).prodMk measurable_id) + +lemma timeFrozenDerivative_bound (hW : IsBrownianReal W P) (b : Drift K M) + (f : TimeCubicTest) (n : ℕ) (t : ℝ) : ‖timeFrozenDerivative P W b f n t‖≤f.ct := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (ae_of_all _ fun ω => f.boundT t _)).trans_eq (by simp) + +lemma timeFrozenGenerator_tendsto (hW : IsBrownianReal W P) (b : Drift K M) + (f : TimeCubicTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → Tendsto (fun n => timeFrozenGenerator P W b f n t) + atTop (𝓝 (timeGenerator P W b f t)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + filter_upwards [hc,f.jointD1,f.jointD2] with t ht hd1 hd2 hmem + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + (fun n => (generator_frozen_aemeasurable hW b (f.slice (freeze n t)) n t).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => generator_bound _ b _ _) + exact ae_of_all _ fun ω => by + have hx := frozenEuler_tendsto b (brownianPath W ω) + (reference_ae_continuous_of_joint b hc _) hmem + have hp := (freeze_tendsto hmem.1).prodMk_nhds hx + have hb := (ht hmem _).tendsto.comp hp + exact (((hd1 hmem _).tendsto.comp hp).mul hb).add + (((hd2 hmem _).tendsto.comp hp).const_mul (1/2:ℝ)) + +lemma nextFrozenEuler_tendsto (b : Drift K M) (X : Path) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + {t : ℝ} (ht : t∈Ico (0:ℝ) 1) : + Tendsto (fun n => euler b X n (⌊t*(n+1:ℕ)⌋₊+1)) atTop + (𝓝 (extend (solution b X) t)) := by + have hk (n : ℕ) : ⌊t*(n+1:ℕ)⌋₊+1≤n+1 := by + apply Nat.succ_le_iff.mpr + apply (Nat.floor_lt (mul_nonneg ht.1 (by positivity))).mpr + simpa only [one_mul] using mul_lt_mul_of_pos_right ht.2 (by positivity : (0:ℝ)<(n+1:ℕ)) + have hg : Tendsto (fun n => grid n (⌊t*(n+1:ℕ)⌋₊+1)) atTop (𝓝 t) := by + simp_rw [grid_succ] + simpa only [add_zero,freeze] using (freeze_tendsto ht.1).add mesh_tendsto_zero + have h0 : Tendsto (fun n => euler b X n (⌊t*(n+1:ℕ)⌋₊+1)- + extend (solution b X) (grid n (⌊t*(n+1:ℕ)⌋₊+1))) atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + apply squeeze_zero (fun _ => norm_nonneg _) (fun n => euler_error_bound b X n _ (hk n)) + simpa only [zero_mul] using (totalResidual_tendsto_zero b (solution b X) + (reference_ae_continuous_of_joint b hc _)).mul_const (Real.exp (K:ℝ)) + have h1 := (continuous_extend (solution b X)).continuousAt.tendsto.comp hg + simpa only [Function.comp_def,sub_add_cancel,zero_add] using h0.add h1 + +lemma timeFrozenDerivative_tendsto (hW : IsBrownianReal W P) (b : Drift K M) + (f : TimeCubicTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + {t : ℝ} (ht : t∈Ico (0:ℝ) 1) : + Tendsto (fun n => timeFrozenDerivative P W b f n t) atTop (𝓝 (timeDerivative P W b f t)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (f.ct:ℝ)) + (fun n => ((f.continuousT t).measurable.comp_aemeasurable + (aemeasurable_euler b (brownianPath W) (brownianPath_aemeasurable_eval hW) + n (⌊t*(n+1:ℕ)⌋₊+1))).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => f.boundT t _) + exact ae_of_all _ fun ω => (f.continuousT t).continuousAt.tendsto.comp + (nextFrozenEuler_tendsto b (brownianPath W ω) hc ht) + +lemma timeFrozenGenerator_intervalIntegrable (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) (n : ℕ) (a c : ℝ) : + IntervalIntegrable (timeFrozenGenerator P W b f n) volume a c := by + apply (intervalIntegrable_const (c := (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2)).mono_fun' + (timeFrozenGenerator_measurable b f n).aestronglyMeasurable + exact Eventually.of_forall fun t => timeFrozenGenerator_bound hW b f n t + +lemma timeFrozenDerivative_intervalIntegrable (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) (n : ℕ) (a c : ℝ) : + IntervalIntegrable (timeFrozenDerivative P W b f n) volume a c := by + apply (intervalIntegrable_const (c := (f.ct:ℝ))).mono_fun' + (timeFrozenDerivative_measurable hW b f n).aestronglyMeasurable + exact Eventually.of_forall fun t => timeFrozenDerivative_bound hW b f n t + +lemma timeFrozenGenerator_integral_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + Tendsto (fun n => ∫ t in (0:ℝ)..1,timeFrozenGenerator P W b f n t) atTop + (𝓝 (∫ t in (0:ℝ)..1,timeGenerator P W b f t)) := by + refine intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + (Eventually.of_forall fun n => (timeFrozenGenerator_measurable b f n).aestronglyMeasurable.restrict) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => timeFrozenGenerator_bound hW b f n t) + (intervalIntegrable_const) ?_ + filter_upwards [timeFrozenGenerator_tendsto hW b f hc] with t ht hmem + rw [uIoc_of_le zero_le_one] at hmem + exact ht ⟨hmem.1.le,hmem.2⟩ + +lemma timeFrozenDerivative_integral_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + Tendsto (fun n => ∫ t in (0:ℝ)..1,timeFrozenDerivative P W b f n t) atTop + (𝓝 (∫ t in (0:ℝ)..1,timeDerivative P W b f t)) := by + refine intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (f.ct:ℝ)) + (Eventually.of_forall fun n => (timeFrozenDerivative_measurable hW b f n).aestronglyMeasurable.restrict) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => timeFrozenDerivative_bound hW b f n t) + (intervalIntegrable_const) ?_ + have hn : ∀ᵐ t ∂volume,t≠(1:ℝ) := by simp [ae_iff,measure_singleton] + filter_upwards [hn] with t ht hmem + rw [uIoc_of_le zero_le_one] at hmem + exact timeFrozenDerivative_tendsto hW b f hc ⟨hmem.1.le,hmem.2.lt_of_ne ht⟩ + +end ParisiPath + +namespace ParisiPath +open ProbabilityTheory +open scoped BigOperators ENNReal +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma brownianEuler_integrable_at (hW : IsBrownianReal W P) (b : Drift K M) + (n k : ℕ) (hk : k≤n+1) : Integrable (fun ω => euler b (brownianPath W ω) n k) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply (innovationEuler_memLp (standardStep_hasLaw hW (by norm_num : (0:ℝ≥0)<1) n) + b 1 n k (p:=1) (by norm_num) |>.integrable le_rfl).congr + exact (innovationEuler_eq_euler hW b n).mono fun ω hω => hω k hk + +lemma brownianEuler_generator_step (hW : IsBrownianReal W P) (b : Drift K M) + (f : CubicTest) (n k : ℕ) (hk : k≤n) : + ‖((∫ ω,f.val (euler b (brownianPath W ω) n (k+1)) ∂P)- + (∫ ω,f.val (euler b (brownianPath W ω) n k) ∂P))- + mesh n*(∫ ω,generator f b (grid n k) (euler b (brownianPath W ω) n k) ∂P)‖≤ + (mesh n*Real.sqrt (mesh n))* + ((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) := by + have hh := innovationEuler_generator_step (standardStep_independent hW 1 n) + (standardStep_hasLaw hW (by norm_num : (0:ℝ≥0)<1) n) b f (by norm_num : (1:ℝ≥0)≤1) n k + simp only [NNReal.coe_one,one_mul] at hh + have he (j : ℕ) (hj : j≤n+1) (g : ℝ → ℝ) : + (∫ ω,g (innovationEuler b 1 n j (fun l => standardStep W 1 n l ω)) ∂P)= + ∫ ω,g (euler b (brownianPath W ω) n j) ∂P := + integral_congr_ae ((innovationEuler_eq_euler hW b n).mono fun ω hω => congrArg g (hω j hj)) + rw [he (k+1) (by omega) f.val,he k (by omega) f.val,he k (by omega) (generator f b (grid n k))] at hh + exact hh + +lemma timeFrozenGenerator_cell_integral (_hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) (n k : ℕ) : + (∫ t in (grid n k)..(grid n (k+1)),timeFrozenGenerator P W b f n t)= + mesh n*(∫ ω,generator (f.slice (grid n k)) b (grid n k) + (euler b (brownianPath W ω) n k) ∂P) := by + have hnot : ∀ᵐ s ∂volume,s≠grid n (k+1) := by simp [ae_iff,measure_singleton] + calc + _ = ∫ _ in (grid n k)..(grid n (k+1)), + (∫ ω,generator (f.slice (grid n k)) b (grid n k) + (euler b (brownianPath W ω) n k) ∂P) := by + apply intervalIntegral.integral_congr_ae + filter_upwards [hnot] with t ht hmem + rw [uIoc_of_le (grid_mono n (Nat.le_succ k))] at hmem + have hcell : t∈Ico (grid n k) (grid n (k+1)) := ⟨hmem.1.le,hmem.2.lt_of_ne ht⟩ + simp only [timeFrozenGenerator,expectedFrozenGenerator,frozenEuler,freeze_on_cell n k hcell, + freeze_index_on_cell n k hcell] + _ = _ := by rw [intervalIntegral.integral_const,grid_succ];simp + +lemma timeFrozenDerivative_cell_integral (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) (n k : ℕ) (hk : k≤n) : + (∫ t in (grid n k)..(grid n (k+1)),timeFrozenDerivative P W b f n t)= + (∫ ω,f.val (grid n (k+1)) (euler b (brownianPath W ω) n (k+1)) ∂P)- + (∫ ω,f.val (grid n k) (euler b (brownianPath W ω) n (k+1)) ∂P) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hnot : ∀ᵐ s ∂volume,s≠grid n (k+1) := by simp [ae_iff,measure_singleton] + calc + _ = ∫ t in (grid n k)..(grid n (k+1)), + (∫ ω,f.dt t (euler b (brownianPath W ω) n (k+1)) ∂P) := by + apply intervalIntegral.integral_congr_ae + filter_upwards [hnot] with t ht hmem + rw [uIoc_of_le (grid_mono n (Nat.le_succ k))] at hmem + have hcell : t∈Ico (grid n k) (grid n (k+1)) := ⟨hmem.1.le,hmem.2.lt_of_ne ht⟩ + simp only [timeFrozenDerivative,freeze_index_on_cell n k hcell] + _ = ∫ ω,(∫ t in (grid n k)..(grid n (k+1)), + f.dt t (euler b (brownianPath W ω) n (k+1))) ∂P := + (expected_kernel_interval_swap f.measT + (aemeasurable_euler b (brownianPath W) (brownianPath_aemeasurable_eval hW) n (k+1)) + f.boundT (grid_mono n (Nat.le_succ k))).symm + _ = ∫ ω,(f.val (grid n (k+1)) (euler b (brownianPath W ω) n (k+1))- + f.val (grid n k) (euler b (brownianPath W ω) n (k+1))) ∂P := by + apply integral_congr_ae + exact ae_of_all _ fun ω => (f.integralT _ (grid_mem n k (by omega)) + _ (grid_mem n (k+1) (by omega)) _).symm + _ = _ := integral_sub ((f.slice _).integrable_comp (brownianEuler_integrable_at hW b n (k+1) (by omega))) + ((f.slice _).integrable_comp (brownianEuler_integrable_at hW b n (k+1) (by omega))) + +lemma timeEuler_weak_step (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) (n k : ℕ) (hk : k≤n) : + ‖((∫ ω,f.val (grid n (k+1)) (euler b (brownianPath W ω) n (k+1)) ∂P)- + (∫ ω,f.val (grid n k) (euler b (brownianPath W ω) n k) ∂P))- + ((∫ t in (grid n k)..(grid n (k+1)),timeFrozenGenerator P W b f n t)+ + (∫ t in (grid n k)..(grid n (k+1)),timeFrozenDerivative P W b f n t))‖≤ + (mesh n*Real.sqrt (mesh n))* + ((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) := by + rw [timeFrozenGenerator_cell_integral hW b f n k,timeFrozenDerivative_cell_integral hW b f n k hk] + convert! brownianEuler_generator_step hW b (f.slice (grid n k)) n k hk using 1 + congr 1 + dsimp only [TimeCubicTest.slice] + ring + +lemma timeEuler_weak_error (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) (n : ℕ) : + ‖(∫ ω,f.val 1 (euler b (brownianPath W ω) n (n+1)) ∂P)-f.val 0 0- + ((∫ t in (0:ℝ)..1,timeFrozenGenerator P W b f n t)+ + (∫ t in (0:ℝ)..1,timeFrozenDerivative P W b f n t))‖≤ + Real.sqrt (mesh n)*((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let A (k : ℕ) := ∫ ω,f.val (grid n k) (euler b (brownianPath W ω) n k) ∂P + let C (k : ℕ) := (∫ t in (grid n k)..(grid n (k+1)),timeFrozenGenerator P W b f n t)+ + (∫ t in (grid n k)..(grid n (k+1)),timeFrozenDerivative P W b f n t) + have h0 : A 0=f.val 0 0 := by + dsimp only [A] + rw [grid_zero] + calc + _ = ∫ _ : Ω,f.val 0 0 ∂P := by + apply integral_congr_ae + filter_upwards [innovationEuler_eq_euler hW b n] with ω hω + rw [←hω 0 (by omega)] + rfl + _ = _ := by simp + have hC : (∑ k∈Finset.range (n+1),C k)= + (∫ t in (0:ℝ)..1,timeFrozenGenerator P W b f n t)+ + (∫ t in (0:ℝ)..1,timeFrozenDerivative P W b f n t) := by + dsimp only [C] + rw [Finset.sum_add_distrib, + intervalIntegral.sum_integral_adjacent_intervals + (fun k _ => timeFrozenGenerator_intervalIntegrable hW b f n _ _), + intervalIntegral.sum_integral_adjacent_intervals + (fun k _ => timeFrozenDerivative_intervalIntegrable hW b f n _ _),grid_zero,grid_end] + have hsum : A (n+1)-A 0-(∑ k∈Finset.range (n+1),C k)= + ∑ k∈Finset.range (n+1),(A (k+1)-A k-C k) := by + rw [Finset.sum_sub_distrib,Finset.sum_range_sub A] + have hb : ‖A (n+1)-A 0-(∑ k∈Finset.range (n+1),C k)‖≤ + (n+1:ℕ)*(mesh n*Real.sqrt (mesh n))* + ((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) := by + rw [hsum] + exact (norm_sum_le _ _).trans ((Finset.sum_le_sum (fun k hk => + timeEuler_weak_step hW b f n k (by have := Finset.mem_range.mp hk;omega))).trans_eq (by simp;ring)) + rw [h0,hC] at hb + dsimp only [A] at hb + rw [grid_end] at hb + convert! hb using 1 + rw [←mul_assoc,show (n+1:ℕ)*mesh n=1 from grid_end n,one_mul] + + + +theorem brownian_solution_time_generator_identity (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + (∫ ω,f.val 1 (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)-f.val 0 0= + (∫ t in (0:ℝ)..1,timeGenerator P W b f t)+(∫ t in (0:ℝ)..1,timeDerivative P W b f t) := by + have hl := (brownianEuler_expected_test_tendsto hW b (f.slice 1) hc).sub_const (f.val 0 0) + have hr := (timeFrozenGenerator_integral_tendsto hW b f hc).add + (timeFrozenDerivative_integral_tendsto hW b f hc) + have hz : Tendsto (fun n => (∫ ω,f.val 1 (euler b (brownianPath W ω) n (n+1)) ∂P)-f.val 0 0- + ((∫ t in (0:ℝ)..1,timeFrozenGenerator P W b f n t)+ + (∫ t in (0:ℝ)..1,timeFrozenDerivative P W b f n t))) atTop (𝓝 0) := by + apply tendsto_zero_iff_norm_tendsto_zero.mpr + apply squeeze_zero (fun _ => norm_nonneg _) (timeEuler_weak_error hW b f) + simpa only [Real.sqrt_zero,zero_mul,Function.comp_def] using + (Real.continuous_sqrt.continuousAt.tendsto.comp mesh_tendsto_zero).mul_const + ((f.c3:ℝ)/6*thirdMomentBound M+(f.c2:ℝ)*(M:ℝ)^2/2) + exact sub_eq_zero.mp (tendsto_nhds_unique (hl.sub hr) hz) + +end ParisiPath + +namespace ParisiPath +open ProbabilityTheory +open scoped BigOperators ENNReal + + + +structure TimeQuadraticTest where + val : ℝ → ℝ → ℝ + d1 : ℝ → ℝ → ℝ + d2 : ℝ → ℝ → ℝ + dt : ℝ → ℝ → ℝ + hasD1 : ∀ t x,HasDerivAt (val t) (d1 t x) x + hasD2 : ∀ t x,HasDerivAt (d1 t) (d2 t x) x + continuousD2 : ∀ t,Continuous (d2 t) + c1 : ℝ≥0 + c2 : ℝ≥0 + ct : ℝ≥0 + bound1 : ∀ t x,‖d1 t x‖≤c1 + bound2 : ∀ t x,‖d2 t x‖≤c2 + boundT : ∀ t x,‖dt t x‖≤ct + measT : Measurable (uncurry dt) + continuousT : ∀ t,Continuous (dt t) + jointD1 : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry d1) (t,x) + jointD2 : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry d2) (t,x) + integralT : ∀ a∈Icc (0:ℝ) 1,∀ b∈Icc (0:ℝ) 1,∀ x, + val b x-val a x=∫ t in a..b,dt t x + +def TimeQuadraticTest.slice (f : TimeQuadraticTest) (t : ℝ) : QuadraticTest where + val := f.val t + d1 := f.d1 t + d2 := f.d2 t + hasD1 := f.hasD1 t + hasD2 := f.hasD2 t + continuousD2 := f.continuousD2 t + c1 := f.c1 + c2 := f.c2 + bound1 := f.bound1 t + bound2 := f.bound2 t + +lemma smoothConvolution_joint_continuousAt (φ : ContDiffBump (0:ℝ)) {g : ℝ → ℝ → ℝ} + (hcont : ∀ t,Continuous (g t)) {C : ℝ≥0} (hb : ∀ t x,‖g t x‖≤C) + {t x : ℝ} (ht : ∀ y,ContinuousAt (uncurry g) (t,y)) : + ContinuousAt (fun p : ℝ×ℝ => smoothConvolution φ (g p.1) p.2) (t,x) := by + change ContinuousAt (fun p : ℝ×ℝ => ∫ z,φ.normed volume z*g p.1 (p.2-z)) (t,x) + apply continuousAt_of_dominated + (F := fun p : ℝ×ℝ => fun z => φ.normed volume z*g p.1 (p.2-z)) + (bound := fun z => φ.normed volume z*(C:ℝ)) + (Eventually.of_forall fun p => (φ.continuous_normed.mul + ((hcont p.1).comp (continuous_const.sub continuous_id))).aestronglyMeasurable) + (Eventually.of_forall fun p => ae_of_all _ fun z => ?_) + (φ.integrable_normed.mul_const _) (ae_of_all _ fun z => ?_) + · rw [norm_mul,Real.norm_of_nonneg (φ.nonneg_normed z)] + exact mul_le_mul_of_nonneg_left (hb _ _) (φ.nonneg_normed z) + · have hh : ContinuousAt (fun p : ℝ×ℝ => g p.1 (p.2-z)) (t,x) := + ContinuousAt.comp (g := uncurry g) (f := fun p : ℝ×ℝ => (p.1,p.2-z)) + (ht (x-z)) + (continuous_fst.continuousAt.prodMk (continuous_snd.continuousAt.sub_const z)) + exact continuousAt_const.mul hh + +lemma smoothConvolution_joint_measurable (φ : ContDiffBump (0:ℝ)) {g : ℝ → ℝ → ℝ} + (hg : Measurable (uncurry g)) : + Measurable (fun p : ℝ×ℝ => smoothConvolution φ (g p.1) p.2) := by + have hh : Measurable (fun p : (ℝ×ℝ)×ℝ => φ.normed volume p.2*g p.1.1 (p.1.2-p.2)) := + (φ.continuous_normed.measurable.comp measurable_snd).mul + (hg.comp ((measurable_fst.comp measurable_fst).prodMk + ((measurable_snd.comp measurable_fst).sub measurable_snd))) + exact hh.stronglyMeasurable.integral_prod_right.measurable + +lemma smoothConvolution_time_integral (φ : ContDiffBump (0:ℝ)) (f : TimeQuadraticTest) + {a c : ℝ} (ha : a∈Icc (0:ℝ) 1) (hc : c∈Icc (0:ℝ) 1) (x : ℝ) : + smoothConvolution φ (f.val c) x-smoothConvolution φ (f.val a) x= + ∫ t in a..c,smoothConvolution φ (f.dt t) x := by + have hm : Measurable (fun p : ℝ×ℝ => φ.normed volume p.2*f.dt p.1 (x-p.2)) := + (φ.continuous_normed.measurable.comp measurable_snd).mul + (f.measT.comp (measurable_fst.prodMk (measurable_const.sub measurable_snd))) + let : IsFiniteMeasure (volume.restrict (uIoc a c)) := by + change IsFiniteMeasure (volume.restrict (Ioc (min a c) (max a c))) + infer_instance + have hi : Integrable (fun p : ℝ×ℝ => φ.normed volume p.2*f.dt p.1 (x-p.2)) + ((volume.restrict (uIoc a c)).prod volume) := by + apply ((integrable_const (f.ct:ℝ)).mul_prod φ.integrable_normed).mono' + hm.aestronglyMeasurable + exact ae_of_all _ fun p => by + rw [norm_mul,Real.norm_of_nonneg (φ.nonneg_normed p.2)] + exact (mul_le_mul_of_nonneg_left (f.boundT _ _) (φ.nonneg_normed p.2)).trans_eq (mul_comm _ _) + calc + _ = ∫ z,φ.normed volume z*(f.val c (x-z)-f.val a (x-z)) := by + rw [smoothConvolution_eq,smoothConvolution_eq, + ←integral_sub + (show Integrable (fun z => φ.normed volume z*f.val c (x-z)) volume from + smoothConvolution_integrable φ (f.slice c).continuous x) + (show Integrable (fun z => φ.normed volume z*f.val a (x-z)) volume from + smoothConvolution_integrable φ (f.slice a).continuous x)] + congr 1 + funext z + ring + _ = ∫ z,(∫ t in a..c,φ.normed volume z*f.dt t (x-z)) := by + apply integral_congr_ae + exact ae_of_all _ fun z => by + dsimp only + rw [f.integralT a ha c hc,intervalIntegral.integral_const_mul] + _ = _ := (intervalIntegral_integral_swap hi).symm + +def TimeQuadraticTest.mollify (f : TimeQuadraticTest) (φ : ContDiffBump (0:ℝ)) : TimeCubicTest where + val := fun t => smoothConvolution φ (f.val t) + dt := fun t => smoothConvolution φ (f.dt t) + smooth := fun t => smoothConvolution_smooth φ (f.slice t).continuous + c1 := f.c1 + c2 := f.c2 + c3 := ⟨(∫ z,‖deriv (φ.normed volume) z‖)*(f.c2:ℝ),by positivity⟩ + ct := f.ct + bound1 := fun t x => (f.slice t).mollify φ |>.bound1 x + bound2 := fun t x => (f.slice t).mollify φ |>.bound2 x + bound3 := fun t x => (f.slice t).mollify φ |>.bound3 x + boundT := fun t x => smoothConvolution_bound φ (f.continuousT t) (f.boundT t) x + measT := smoothConvolution_joint_measurable φ f.measT + continuousT := fun t => (smoothConvolution_smooth φ (f.continuousT t)).continuous + jointD1 := by + filter_upwards [f.jointD1] with t ht hmem x + have he : (fun p : ℝ×ℝ => deriv (smoothConvolution φ (f.val p.1)) p.2)= + fun p : ℝ×ℝ => smoothConvolution φ (f.d1 p.1) p.2 := by + funext p + exact congrFun (smoothConvolution_d1 φ (f.slice p.1)) p.2 + rw [he] + exact smoothConvolution_joint_continuousAt φ (fun s => (f.slice s).continuous_d1) + f.bound1 (ht hmem) + jointD2 := by + filter_upwards [f.jointD2] with t ht hmem x + have he : (fun p : ℝ×ℝ => iteratedDeriv 2 (smoothConvolution φ (f.val p.1)) p.2)= + fun p : ℝ×ℝ => smoothConvolution φ (f.d2 p.1) p.2 := by + funext p + exact congrFun (smoothConvolution_d2 φ (f.slice p.1)) p.2 + rw [he] + exact smoothConvolution_joint_continuousAt φ f.continuousD2 f.bound2 (ht hmem) + integralT := fun _ ha _ hc x => smoothConvolution_time_integral φ f ha hc x + +end ParisiPath + +namespace ParisiPath +open ProbabilityTheory +open scoped BigOperators ENNReal +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma timeGenerator_aestronglyMeasurable (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (timeGenerator P W b f) (volume.restrict (Ioc (0:ℝ) 1)) := by + apply aestronglyMeasurable_of_tendsto_ae atTop + (fun n => (timeFrozenGenerator_measurable (P:=P) (W:=W) b f n).aestronglyMeasurable.restrict) + filter_upwards [ae_restrict_of_ae (timeFrozenGenerator_tendsto hW b f hc), + ae_restrict_mem measurableSet_Ioc] with t ht hmem + exact ht ⟨hmem.1.le,hmem.2⟩ + +lemma timeDerivative_aestronglyMeasurable (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeCubicTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (timeDerivative P W b f) (volume.restrict (Ioc (0:ℝ) 1)) := by + apply aestronglyMeasurable_of_tendsto_ae atTop + (fun n => (timeFrozenDerivative_measurable hW b f n).aestronglyMeasurable.restrict) + have hn : ∀ᵐ t ∂volume,t≠(1:ℝ) := by simp [ae_iff,measure_singleton] + filter_upwards [ae_restrict_of_ae hn,ae_restrict_mem measurableSet_Ioc] with t ht hmem + exact timeFrozenDerivative_tendsto hW b f hc ⟨hmem.1.le,hmem.2.lt_of_ne ht⟩ + +lemma timeDerivative_bound (hW : IsBrownianReal W P) (b : Drift K M) + (f : TimeCubicTest) (t : ℝ) : ‖timeDerivative P W b f t‖≤f.ct := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (ae_of_all _ fun ω => f.boundT t _)).trans_eq (by simp) + +def timeGeneratorC2 (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : TimeQuadraticTest) (t : ℝ) : ℝ := + expectedGeneratorC2 P W b (f.slice t) t + +def timeDerivativeC2 (P : Measure Ω) (W : ℝ≥0 → Ω → ℝ) + (b : Drift K M) (f : TimeQuadraticTest) (t : ℝ) : ℝ := + ∫ ω,f.dt t (extend (solution b (brownianPath W ω)) t) ∂P + +lemma mollify_timeGenerator_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) (t : ℝ) : + Tendsto (fun n => timeGenerator P W b (f.mollify (shrinkingBump n)) t) atTop + (𝓝 (timeGeneratorC2 P W b f t)) := + mollify_expectedGenerator_tendsto hW b (f.slice t) t + +lemma mollify_timeDerivative_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) (t : ℝ) : + Tendsto (fun n => timeDerivative P W b (f.mollify (shrinkingBump n)) t) atTop + (𝓝 (timeDerivativeC2 P W b f t)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hX := aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t) + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (f.ct:ℝ)) + (fun n => (((f.mollify (shrinkingBump n)).continuousT t).measurable.comp_aemeasurable hX).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => (f.mollify (shrinkingBump n)).boundT t _) + exact ae_of_all _ fun ω => smoothConvolution_tendsto (f.continuousT t) _ + +lemma mollify_timeGenerator_integral_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + Tendsto (fun n => ∫ t in (0:ℝ)..1,timeGenerator P W b (f.mollify (shrinkingBump n)) t) + atTop (𝓝 (∫ t in (0:ℝ)..1,timeGeneratorC2 P W b f t)) := by + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (f.c1:ℝ)*(M:ℝ)+(f.c2:ℝ)/2) + (Eventually.of_forall fun n => ?_) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => + expectedGenerator_bound hW b ((f.mollify (shrinkingBump n)).slice t) t) + (intervalIntegrable_const) (ae_of_all _ fun t _ => mollify_timeGenerator_tendsto hW b f t) + rw [uIoc_of_le zero_le_one] + exact timeGenerator_aestronglyMeasurable hW b _ hc + +lemma mollify_timeDerivative_integral_tendsto (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + Tendsto (fun n => ∫ t in (0:ℝ)..1,timeDerivative P W b (f.mollify (shrinkingBump n)) t) + atTop (𝓝 (∫ t in (0:ℝ)..1,timeDerivativeC2 P W b f t)) := by + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (f.ct:ℝ)) + (Eventually.of_forall fun n => ?_) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => timeDerivative_bound hW b _ t) + (intervalIntegrable_const) (ae_of_all _ fun t _ => mollify_timeDerivative_tendsto hW b f t) + rw [uIoc_of_le zero_le_one] + exact timeDerivative_aestronglyMeasurable hW b _ hc + + + +theorem brownian_solution_time_generator_identity_C2 (hW : IsBrownianReal W P) + (b : Drift K M) (f : TimeQuadraticTest) + (hc : ∀ᵐ t ∂volume,t ∈ Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + (∫ ω,f.val 1 (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)-f.val 0 0= + (∫ t in (0:ℝ)..1,timeGeneratorC2 P W b f t)+(∫ t in (0:ℝ)..1,timeDerivativeC2 P W b f t) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hv := mollify_expected_test_tendsto (f.slice 1) (brownian_solution_integrable hW b ⟨1,by simp⟩) + have h0 := smoothConvolution_tendsto (f.slice 0).continuous 0 + have he : (fun n => (∫ ω,(f.mollify (shrinkingBump n)).val 1 + (solution b (brownianPath W ω) ⟨1,by simp⟩) ∂P)-(f.mollify (shrinkingBump n)).val 0 0)= + (fun n => (∫ t in (0:ℝ)..1,timeGenerator P W b (f.mollify (shrinkingBump n)) t)+ + (∫ t in (0:ℝ)..1,timeDerivative P W b (f.mollify (shrinkingBump n)) t)) := by + funext n + exact brownian_solution_time_generator_identity hW b _ hc + have hr := (mollify_timeGenerator_integral_tendsto hW b f hc).add + (mollify_timeDerivative_integral_tendsto hW b f hc) + exact tendsto_nhds_unique (hv.sub h0) (he ▸ hr) + +end ParisiPath + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/TreeNodeDepth.lean b/lean/OAI/Probability/ParisiFinite/TreeNodeDepth.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b2c188f63911ed39f5eef9142d8801479e8e9d6 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/TreeNodeDepth.lean @@ -0,0 +1,703 @@ +import Mathlib +import OAI.Probability.ParisiFinite.SumFinLtNat + +namespace OAI + +/-! Tree Node Depth. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def treeNodeDepth : {d r : ℕ} → (T : PartitionTree d r) → TreeNode T → Fin d + | 0,_,_ => Empty.elim + | _+1,_,⟨_,T⟩ => fun ⟨j,x⟩ => Sum.casesOn x (fun _ => 0) (fun n => (treeNodeDepth (T j) n).succ) + +lemma treeNodeDepth_path {d r : ℕ} (T : PartitionTree d r) (i : Fin r) (k : Fin d) : + treeNodeDepth T (treeNodePath T i k)=k := by + induction d generalizing r with + | zero => exact Fin.elim0 k + | succ d ih => + rcases T with ⟨P,T⟩ + obtain ⟨⟨j,i⟩,rfl⟩ := P.equivSigma.surjective i + change treeNodeDepth _ (treeNodePath _ (P.emb j i) k)=k + rw [treeNodePath_emb] + induction k using Fin.cases with + | zero => rfl + | succ k => exact congrArg Fin.succ (ih (T j) i k) + +lemma treeNodePath_injective {d r : ℕ} (T : PartitionTree d r) (i : Fin r) : + Function.Injective (treeNodePath T i) := by + intro k l h + simpa only [treeNodeDepth_path] using congrArg (treeNodeDepth T) h + +lemma treeNodePath_eq_levels {d r : ℕ} (T : PartitionTree d r) (i j : Fin r) (k l : Fin d) + (h : treeNodePath T i k=treeNodePath T j l) : k=l := by + simpa only [treeNodeDepth_path] using congrArg (treeNodeDepth T) h + +def treeGaussianCoeff {d r : ℕ} (T : PartitionTree d r) (v : Fin d → ℝ) + (i : Fin r) (n : TreeNode T) : ℝ := + ∑ k,if treeNodePath T i k=n then Real.sqrt (v k) else 0 + +lemma field_treeGaussianCoeff {d r : ℕ} (T : PartitionTree d r) (v : Fin d → ℝ) + (z : TreeNode T → ℝ) (i : Fin r) : + field (treeGaussianCoeff T v) z i=∑ k,Real.sqrt (v k)*z (treeNodePath T i k) := by + simp only [field,treeGaussianCoeff,Finset.sum_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + rw [Finset.sum_eq_single (treeNodePath T i k)] + · simp + · intro n hn hne + simp [Ne.symm hne] + · simp + +lemma treeGaussianCoeff_at_path {d r : ℕ} (T : PartitionTree d r) (v : Fin d → ℝ) + (i j : Fin r) (k : Fin d) : + treeGaussianCoeff T v j (treeNodePath T i k)= + if treeNodePath T j k=treeNodePath T i k then Real.sqrt (v k) else 0 := by + unfold treeGaussianCoeff + rw [Finset.sum_eq_single k] + · intro l hl hne + have he : treeNodePath T j l≠treeNodePath T i k := fun h => hne (treeNodePath_eq_levels T j i l k h) + simp [he] + · simp + +lemma kernel_treeGaussianCoeff {d r : ℕ} (T : PartitionTree d r) (v : Fin d → ℝ) + (hv : ∀ k,0≤v k) (i j : Fin r) : + kernel (treeGaussianCoeff T v) i j= + ∑ k,if treeCodes T k.succ i=treeCodes T k.succ j then v k else 0 := by + change field (treeGaussianCoeff T v) (treeGaussianCoeff T v j) i=_ + rw [field_treeGaussianCoeff] + simp only [treeGaussianCoeff_at_path,treeNodePath_eq_iff] + apply Finset.sum_congr rfl + intro k _ + by_cases h : treeCodes T k.succ i=treeCodes T k.succ j + · simp [h,← pow_two,Real.sq_sqrt (hv k)] + · simp [h,Ne.symm h] + +lemma tree_code_gaussian_law {d r : ℕ} (T : PartitionTree d r) (v : Fin d → ℝ) + (hv : ∀ k,0≤v k) : + (gaussianLaw (TreeNode T)).map (field (treeGaussianCoeff T v))= + (gaussianLaw (Σ k : Fin (d+1),CodeLabel (treeCodes T k))).map + (field (codeGaussianCoeff (treeCodes T) (Fin.cons 0 v))) := by + apply field_law_eq_of_kernel + funext i j + rw [kernel_treeGaussianCoeff T v hv] + have hv' : ∀ k : Fin (d+1),0≤(Fin.cons (0:ℝ) v : Fin (d+1) → ℝ) k := by intro k; cases k using Fin.cases <;> simp [hv] + rw [kernel_codeGaussianCoeff _ _ hv',Fin.sum_univ_succ] + simp + +def treeGaussianMoment {d r : ℕ} (T : PartitionTree d r) (x : (Fin d → ℝ) → ℝ) : ℝ := + ∫ z,∏ i,x (fun k => z (treeNodePath T i k)) ∂gaussianLaw (TreeNode T) + +lemma treeGaussianMoment_mem_unit {d r : ℕ} (T : PartitionTree d r) + {x : (Fin d → ℝ) → ℝ} (hx : Continuous x) (hb : ∀ s,0≤x s ∧ x s≤1) : + 0≤treeGaussianMoment T x ∧ treeGaussianMoment T x≤1 := by + have hm : Continuous (fun z : TreeNode T → ℝ => ∏ i,x (fun k => z (treeNodePath T i k))) := by + apply continuous_finsetProd + intro i _ + exact hx.comp (continuous_pi fun k => continuous_apply _) + have hb' (z : TreeNode T → ℝ) : 0≤(∏ i,x (fun k => z (treeNodePath T i k))) ∧ + (∏ i,x (fun k => z (treeNodePath T i k)))≤1 := + ⟨Finset.prod_nonneg (fun i _ => (hb _).1),Finset.prod_le_one₀ (fun i _ => (hb _).1) (fun i _ => (hb _).2)⟩ + have hi : Integrable (fun z : TreeNode T → ℝ => ∏ i,x (fun k => z (treeNodePath T i k))) + (gaussianLaw (TreeNode T)) := + (integrable_const (1:ℝ)).mono' hm.aestronglyMeasurable (ae_of_all _ fun z => by + simpa only [Real.norm_eq_abs,abs_of_nonneg (hb' z).1] using (hb' z).2) + refine ⟨integral_nonneg (fun z => (hb' z).1),?_⟩ + simpa [treeGaussianMoment] using + integral_mono hi (integrable_const (1:ℝ)) (fun z => (hb' z).2) + + + +lemma treeMarkMoment_tendsto_gaussian {d r : ℕ} (T : PartitionTree d r) + {x : (Fin d → ℝ) → ℝ} (hx : Continuous x) (hb : ∀ s,0≤x s ∧ x s≤1) : + Tendsto (fun m => treeMarkMoment (gaussianQuantizerWeight m) + (fun s : Fin d → GaussianQuantizerLabel m => x (fun k => (s k).val)) T) atTop + (𝓝 (treeGaussianMoment T x)) := by + simp_rw [treeMarkMoment_node_sum] + apply gaussianQuantizer_bounded_continuous + · apply continuous_finsetProd + intro i _ + exact hx.comp (continuous_pi fun k => continuous_apply _) + · intro z + rw [abs_of_nonneg (Finset.prod_nonneg (fun i _ => (hb _).1))] + exact Finset.prod_le_one₀ (fun i _ => (hb _).1) (fun i _ => (hb _).2) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiFinite + +lemma integrable_of_uniform_abs {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {f : Ω → ℝ} {C : ℝ} + (hf : Measurable f) (hb : ∀ x,|f x|≤C) : Integrable f μ := by + exact (integrable_const C).mono' hf.aestronglyMeasurable + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hb x) + +lemma integrable_exp_of_uniform_abs {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {f : Ω → ℝ} {C : ℝ} (a : ℝ) + (hf : Measurable f) (hb : ∀ x,|f x|≤C) : + Integrable (fun x => Real.exp (a*f x)) μ := by + apply integrable_of_uniform_abs (C:=Real.exp (|a| * C)) (by fun_prop) + intro x + rw [abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + exact le_trans (le_abs_self _) (by simpa only [abs_mul] using mul_le_mul_of_nonneg_left (hb x) (abs_nonneg a)) + +lemma logMean_uniform_abs {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {f : Ω → ℝ} {C a : ℝ} + (ha : 0≤a) (hf : Measurable f) (hb : ∀ x,|f x|≤C) : |logMean μ a f|≤C := by + have hi := integrable_of_uniform_abs (μ:=μ) hf hb + have he := integrable_exp_of_uniform_abs (μ:=μ) a hf hb + rw [abs_le] + constructor + · have h := logMean_mono ha (integrable_const (-C)) hi + (integrable_const (Real.exp (a*(-C)))) he (fun x => (abs_le.mp (hb x)).1) + simpa only [logMean_const] using h + · have h := logMean_mono ha hi (integrable_const C) he + (integrable_const (Real.exp (a*C))) (fun x => (abs_le.mp (hb x)).2) + simpa only [logMean_const] using h + + + +lemma tendsto_logMean_of_uniform_abs {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] (a : ℝ) {f : ℕ → Ω → ℝ} {g : Ω → ℝ} {C : ℝ} + (hf : ∀ m,Measurable (f m)) (hg : Measurable g) + (hb : ∀ m x,|f m x|≤C) (hbg : ∀ x,|g x|≤C) + (ht : ∀ x,Tendsto (fun m => f m x) atTop (𝓝 (g x))) : + Tendsto (fun m => logMean μ a (f m)) atTop (𝓝 (logMean μ a g)) := by + by_cases ha : a=0 + · simp only [ha,logMean_zero] + exact tendsto_integral_of_dominated_convergence (fun _ => C) + (fun m => (hf m).aestronglyMeasurable) (integrable_const C) + (fun m => ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hb m x) (ae_of_all _ ht) + · simp only [logMean,ha,↓reduceIte] + have hi : Tendsto (fun m => ∫ x,Real.exp (a*f m x) ∂μ) atTop + (𝓝 (∫ x,Real.exp (a*g x) ∂μ)) := by + apply tendsto_integral_of_dominated_convergence (fun _ => Real.exp (|a| * C)) + · intro m; exact (by fun_prop : Measurable (fun x => Real.exp (a*f m x))).aestronglyMeasurable + · exact integrable_const _ + · intro m + filter_upwards with x + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + exact (le_abs_self _).trans (by simpa only [abs_mul] using mul_le_mul_of_nonneg_left (hb m x) (abs_nonneg a)) + · filter_upwards with x + exact Real.continuous_exp.continuousAt.tendsto.comp ((ht x).const_mul a) + exact (hi.log (ne_of_gt (integral_exp_pos (integrable_exp_of_uniform_abs a hg hbg)))).div_const a + +end ParisiFinite +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +lemma gaussianQuantizer_logMean (m : ℕ) (a : ℝ) (f : GaussianQuantizerLabel m → ℝ) : + logMean (gaussianQuantizerLaw m) a f= + logMean (gaussianReal 0 1) a (fun z => f (gaussianQuantizerIndex m z)) := by + unfold logMean gaussianQuantizerLaw + rw [integral_map (gaussianQuantizerIndex_measurable m).aemeasurable + (Integrable.of_finite (μ:=(gaussianReal 0 1).map (gaussianQuantizerIndex m))).aestronglyMeasurable] + rw [integral_map (gaussianQuantizerIndex_measurable m).aemeasurable + (Integrable.of_finite (μ:=(gaussianReal 0 1).map (gaussianQuantizerIndex m))).aestronglyMeasurable] + +lemma gaussianQuantizer_logMean_tendsto (a : ℝ) {f : ℝ → ℝ} {C : ℝ} + (hf : Continuous f) (hb : ∀ x,|f x|≤C) : + Tendsto (fun m => logMean (gaussianQuantizerLaw m) a (fun z => f z.val)) atTop + (𝓝 (logMean (gaussianReal 0 1) a f)) := by + simp_rw [gaussianQuantizer_logMean] + apply tendsto_logMean_of_uniform_abs a + · intro m; exact hf.measurable.comp (gaussianQuantizer m).measurable + · exact hf.measurable + · intro m x; exact hb _ + · exact hb + · intro x + exact hf.continuousAt.tendsto.comp (gaussianQuantizer_tendsto x) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite +variable {ι : Type*} [Fintype ι] + +def finiteRisk (w : ι → ℝ) (a : ℝ) (f : ι → ℝ) : ℝ := + if a=0 then ∑ i,w i*f i else Real.log (∑ i,w i*Real.exp (a*f i))/a + +def finiteHierarchyRisk (w : ι → ℝ) : {d : ℕ} → (Fin d → ℝ) → ((Fin d → ι) → ℝ) → ℝ + | 0,_,f => f (fun k => Fin.elim0 k) + | _+1,a,f => finiteRisk w (a 0) (fun i => finiteHierarchyRisk w (fun k => a k.succ) (fun s => f (Fin.cons i s))) + +lemma finiteRisk_const (w : ι → ℝ) (hw : ∑ i,w i=1) (a c : ℝ) : finiteRisk w a (fun _ => c)=c := by + unfold finiteRisk + simp only [← Finset.sum_mul,hw,one_mul,Real.log_exp] + split_ifs with h + · rfl + · exact mul_div_cancel_left₀ c h + +lemma finiteRisk_exp {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {a : ℝ} (ha : a≠0) (f : ι → ℝ) : + Real.exp (a*finiteRisk w a f)=∑ i,w i*Real.exp (a*f i) := by + have hp := weighted_sum_pos hw hs (fun i => Real.exp_pos (a*f i)) + simp only [finiteRisk,ha,↓reduceIte] + rw [mul_div_cancel₀ _ ha,Real.exp_log hp] + +lemma hierarchyMark_eq_finiteRisk {d : ℕ} {w : ι → ℝ} + (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) (a : Fin (d+1) → ℝ) + (ha : ∀ k : Fin d,a k.succ≠0) {x : (Fin d → ι) → ℝ} + {z : ℝ} (hp : ∀ s,0<1-z*x s) : + hierarchyMark w d a x z=Real.exp (a 0*finiteHierarchyRisk w (fun k => a k.succ) + (fun s => Real.log (1-z*x s))) := by + induction d with + | zero => + simp only [hierarchyMark,finiteHierarchyRisk,Real.rpow_def_of_pos (hp _)] + congr 1 + ring + | succ d ih => + change (∑ i,w i*hierarchyMark w d (fun k => a k.succ) (fun s => x (Fin.cons i s)) z)^(a 0/a 1)=_ + simp_rw [ih (fun k => a k.succ) (fun k => ha k.succ) (fun s => hp _)] + let F : ι → ℝ := fun i => finiteHierarchyRisk w (fun k : Fin d => a k.succ.succ) + (fun s => Real.log (1-z*x (Fin.cons i s))) + change (∑ i,w i*Real.exp (a 1*F i))^(a 0/a 1)=Real.exp (a 0*finiteRisk w (a 1) F) + have h1 : a 1≠0 := ha 0 + have hp' := weighted_sum_pos hw hs (fun i => Real.exp_pos (a 1*F i)) + rw [Real.rpow_def_of_pos hp'] + simp only [finiteRisk,h1,↓reduceIte] + congr 1 + ring + + + +lemma hierarchyLog_eq_finiteHierarchyRisk {d : ℕ} {w : ι → ℝ} + (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) (a : Fin (d+1) → ℝ) + (ha : ∀ k,a k≠0) {x : (Fin (d+1) → ι) → ℝ} + {z : ℝ} (hp : ∀ s,0<1-z*x s) : + hierarchyLog w a x z=finiteHierarchyRisk w a (fun s => Real.log (1-z*x s)) := by + unfold hierarchyLog + simp_rw [hierarchyMark_eq_finiteRisk hw hs a (fun k => ha k.succ) (fun s => hp _)] + change (a 0)⁻¹*Real.log (∑ i,w i*Real.exp (a 0*finiteHierarchyRisk w (fun k => a k.succ) + (fun s => Real.log (1-z*x (Fin.cons i s)))))=_ + simp only [finiteHierarchyRisk,finiteRisk,ha 0,↓reduceIte,div_eq_mul_inv,mul_comm] + +lemma finiteRisk_eq_logMean (m : ℕ) (a : ℝ) (f : GaussianQuantizerLabel m → ℝ) : + finiteRisk (gaussianQuantizerWeight m) a f=logMean (gaussianQuantizerLaw m) a f := by + unfold finiteRisk logMean + rw [integral_fintype Integrable.of_finite,integral_fintype Integrable.of_finite] + rfl + +lemma finiteRisk_uniform_abs {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {a C : ℝ} (ha : 0≤a) {f : ι → ℝ} (hb : ∀ i,|f i|≤C) : |finiteRisk w a f|≤C := by + have havg (g : ι → ℝ) {D : ℝ} (hg : ∀ i,g i≤D) : (∑ i,w i*g i)≤D := by + calc + _ ≤ ∑ i,w i*D := Finset.sum_le_sum fun i _ => mul_le_mul_of_nonneg_left (hg i) (hw i) + _ = D := by rw [← Finset.sum_mul,hs,one_mul] + have hlow (g : ι → ℝ) {D : ℝ} (hg : ∀ i,D≤g i) : D≤(∑ i,w i*g i) := by + calc + _ = ∑ i,w i*D := by rw [← Finset.sum_mul,hs,one_mul] + _ ≤ _ := Finset.sum_le_sum fun i _ => mul_le_mul_of_nonneg_left (hg i) (hw i) + unfold finiteRisk + split_ifs with h0 + · rw [abs_le] + exact ⟨hlow f (fun i => (abs_le.mp (hb i)).1),havg f (fun i => (abs_le.mp (hb i)).2)⟩ + · have hap : 0 Real.exp_pos (a*f i)) + have hlu : Real.exp (a*(-C))≤∑ i,w i*Real.exp (a*f i) := + hlow _ (fun i => Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (abs_le.mp (hb i)).1 ha)) + have huu : (∑ i,w i*Real.exp (a*f i))≤Real.exp (a*C) := + havg _ (fun i => Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (abs_le.mp (hb i)).2 ha)) + have hl := Real.log_le_log (Real.exp_pos (a*(-C))) hlu + have hu := Real.log_le_log hp huu + rw [Real.log_exp] at hl hu + rw [abs_le,le_div_iff₀ hap,div_le_iff₀ hap] + constructor <;> nlinarith + +lemma finiteHierarchyRisk_uniform_abs {d : ℕ} {w : ι → ℝ} + (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) {a : Fin d → ℝ} (ha : ∀ k,0≤a k) + {f : (Fin d → ι) → ℝ} {C : ℝ} (hb : ∀ s,|f s|≤C) : |finiteHierarchyRisk w a f|≤C := by + induction d with + | zero => exact hb _ + | succ d ih => + exact finiteRisk_uniform_abs hw hs (ha 0) + (fun i => ih (fun k => ha k.succ) (fun s => hb _)) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +def gaussianHierarchyRisk : {d : ℕ} → (Fin d → ℝ) → ((Fin d → ℝ) → ℝ) → ℝ + | 0,_,f => f (fun k => Fin.elim0 k) + | _+1,a,f => logMean (gaussianReal 0 1) (a 0) + (fun z => gaussianHierarchyRisk (fun k => a k.succ) (fun s => f (Fin.cons z s))) + +lemma continuous_gaussianLogMean {E : Type*} [TopologicalSpace E] [FirstCountableTopology E] + {f : E → ℝ → ℝ} {C : ℝ} (a : ℝ) + (hf : Continuous (Function.uncurry f)) (hb : ∀ e z,|f e z|≤C) : + Continuous (fun e => logMean (gaussianReal 0 1) a (f e)) := by + have hc (e : E) : Continuous (f e) := hf.comp (continuous_const.prodMk continuous_id) + by_cases ha : a=0 + · simp only [ha,logMean_zero] + apply continuous_of_dominated (bound:=fun _ => C) + · intro e; exact (hc e).aestronglyMeasurable + · intro e; exact ae_of_all _ fun z => by simpa only [Real.norm_eq_abs] using hb e z + · exact integrable_const C + · filter_upwards with z + exact hf.comp (continuous_id.prodMk continuous_const) + · simp only [logMean,ha,↓reduceIte] + have hi : Continuous (fun e => ∫ z,Real.exp (a*f e z) ∂gaussianReal 0 1) := by + apply continuous_of_dominated (bound:=fun _ => Real.exp (|a| * C)) + · intro e; exact (Real.continuous_exp.comp ((hc e).const_mul a)).aestronglyMeasurable + · intro e + filter_upwards with z + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + exact (le_abs_self _).trans (by simpa only [abs_mul] using mul_le_mul_of_nonneg_left (hb e z) (abs_nonneg a)) + · exact integrable_const _ + · filter_upwards with z + exact Real.continuous_exp.comp ((hf.comp (continuous_id.prodMk continuous_const)).const_mul a) + exact (hi.log (fun e => ne_of_gt (ParisiFinite.integral_exp_pos + (integrable_exp_of_uniform_abs a (hc e).measurable (hb e))))).div_const a + +lemma continuous_finCons {E : Type*} [TopologicalSpace E] {d : ℕ} + {x : E → ℝ} {y : E → Fin d → ℝ} (hx : Continuous x) (hy : Continuous y) : + Continuous (fun e => (Fin.cons (x e) (y e) : Fin (d+1) → ℝ)) := by + apply continuous_pi + intro k + cases k using Fin.cases with + | zero => exact hx + | succ k => exact (continuous_apply k).comp hy + +lemma gaussianHierarchyRisk_continuous_bound {d : ℕ} {E : Type*} + [TopologicalSpace E] [FirstCountableTopology E] {a : Fin d → ℝ} (ha : ∀ k,0≤a k) + {f : E → (Fin d → ℝ) → ℝ} {C : ℝ} (hf : Continuous (Function.uncurry f)) + (hb : ∀ e s,|f e s|≤C) : + Continuous (fun e => gaussianHierarchyRisk a (f e)) ∧ + ∀ e,|gaussianHierarchyRisk a (f e)|≤C := by + induction d generalizing E with + | zero => + exact ⟨hf.comp (continuous_id.prodMk continuous_const),fun e => hb e _⟩ + | succ d ih => + let g : (E×ℝ) → (Fin d → ℝ) → ℝ := fun e s => f e.1 (Fin.cons e.2 s) + have hg : Continuous (Function.uncurry g) := by + exact hf.comp ((continuous_fst.fst).prodMk (continuous_finCons continuous_fst.snd continuous_snd)) + have hh := ih (fun k => ha k.succ) hg (fun e s => hb e.1 _) + have hlog := continuous_gaussianLogMean (a 0) hh.1 (fun e z => hh.2 (e,z)) + refine ⟨hlog,?_⟩ + intro e + apply logMean_uniform_abs (ha 0) + · exact (hh.1.comp (continuous_const.prodMk continuous_id)).measurable + · intro z; exact hh.2 (e,z) + +lemma gaussianHierarchyRisk_uniform_abs {d : ℕ} {a : Fin d → ℝ} (ha : ∀ k,0≤a k) + {f : (Fin d → ℝ) → ℝ} {C : ℝ} (hf : Continuous f) (hb : ∀ s,|f s|≤C) : + |gaussianHierarchyRisk a f|≤C := + (gaussianHierarchyRisk_continuous_bound (E:=Unit) (f:=fun _ s => f s) ha (hf.comp continuous_snd) (fun _ s => hb s)).2 () + + + +theorem quantizedHierarchyRisk_tendsto {d : ℕ} {E : Type*} + [TopologicalSpace E] [FirstCountableTopology E] {a : Fin d → ℝ} (ha : ∀ k,0≤a k) + {f : E → (Fin d → ℝ) → ℝ} {C : ℝ} (hf : Continuous (Function.uncurry f)) + (hb : ∀ e s,|f e s|≤C) {u : ℕ → E} {e : E} (hu : Tendsto u atTop (𝓝 e)) : + Tendsto (fun m => finiteHierarchyRisk (gaussianQuantizerWeight m) a + (fun s : Fin d → GaussianQuantizerLabel m => f (u m) (fun k => (s k).val))) atTop + (𝓝 (gaussianHierarchyRisk a (f e))) := by + induction d generalizing E with + | zero => + simp only [finiteHierarchyRisk,gaussianHierarchyRisk] + have he (m : ℕ) : (fun k : Fin 0 => ((Fin.elim0 k : GaussianQuantizerLabel m)).val)= + (fun k : Fin 0 => (Fin.elim0 k : ℝ)) := Subsingleton.elim _ _ + simp_rw [he] + exact hf.continuousAt.tendsto.comp (hu.prodMk_nhds tendsto_const_nhds) + | succ d ih => + let g : (E×ℝ) → (Fin d → ℝ) → ℝ := fun e s => f e.1 (Fin.cons e.2 s) + have hg : Continuous (Function.uncurry g) := by + exact hf.comp ((continuous_fst.fst).prodMk (continuous_finCons continuous_fst.snd continuous_snd)) + let H (m : ℕ) (i : GaussianQuantizerLabel m) := + finiteHierarchyRisk (gaussianQuantizerWeight m) (fun k => a k.succ) + (fun s : Fin d → GaussianQuantizerLabel m => f (u m) (Fin.cons i.val (fun k => (s k).val))) + let G (z : ℝ) := gaussianHierarchyRisk (fun k => a k.succ) (fun s => f e (Fin.cons z s)) + have heq (m : ℕ) : finiteHierarchyRisk (gaussianQuantizerWeight m) a + (fun s : Fin (d+1) → GaussianQuantizerLabel m => f (u m) (fun k => (s k).val))= + logMean (gaussianReal 0 1) (a 0) (fun z => H m (gaussianQuantizerIndex m z)) := by + change finiteRisk _ _ _=_ + rw [finiteRisk_eq_logMean,gaussianQuantizer_logMean] + congr 1 + funext z + congr 1 + funext s + change f (u m) (fun k => ((Fin.cons (gaussianQuantizerIndex m z) s : Fin (d+1) → GaussianQuantizerLabel m) k).val)= + f (u m) (Fin.cons (gaussianQuantizerIndex m z).val (fun k => (s k).val)) + congr 1 + funext k + cases k using Fin.cases <;> rfl + simp_rw [heq] + change Tendsto _ _ (𝓝 (logMean (gaussianReal 0 1) (a 0) G)) + apply tendsto_logMean_of_uniform_abs (a 0) (C:=C) + · intro m + exact (measurable_of_finite (H m)).comp (gaussianQuantizerIndex_measurable m) + · have hh := gaussianHierarchyRisk_continuous_bound (fun k => ha k.succ) hg (fun e s => hb e.1 _) + exact (hh.1.comp (continuous_const.prodMk continuous_id)).measurable + · intro m z + exact finiteHierarchyRisk_uniform_abs (gaussianQuantizerWeight_nonneg m) (gaussianQuantizerWeight_sum m) + (fun k => ha k.succ) (fun s => hb (u m) _) + · intro z + exact gaussianHierarchyRisk_uniform_abs (fun k => ha k.succ) + (hf.comp (continuous_const.prodMk (continuous_finCons continuous_const continuous_id))) (fun s => hb e _) + · intro z + exact ih (fun k => ha k.succ) hg (fun e s => hb e.1 _) + (hu.prodMk_nhds (gaussianQuantizer_tendsto z)) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation ParisiFinite + +def gaussianHierarchyMoment {d : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+1) → ℝ) (x : (Fin d → ℝ) → ℝ) (n : ℕ) : ℝ := + ∑ T : PartitionTree d n,(μ:Measure OverlapArray).real (hierarchyEvent (treeCodes T) q)*treeGaussianMoment T x + +lemma hierarchyMarkedMoment_tendsto_gaussian {d : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+1) → ℝ) {x : (Fin d → ℝ) → ℝ} (hx : Continuous x) + (hb : ∀ s,0≤x s ∧ x s≤1) (n : ℕ) : + Tendsto (fun m => hierarchyMarkedMoment μ q (gaussianQuantizerWeight m) + (fun s : Fin d → GaussianQuantizerLabel m => x (fun k => (s k).val)) n) atTop + (𝓝 (gaussianHierarchyMoment μ q x n)) := by + unfold hierarchyMarkedMoment gaussianHierarchyMoment + apply tendsto_finsetSum + intro T _ + exact (treeMarkMoment_tendsto_gaussian T hx hb).const_mul _ + +lemma gaussianHierarchyMoment_mem_unit {d : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+1) → ℝ) {x : (Fin d → ℝ) → ℝ} (hx : Continuous x) + (hb : ∀ s,0≤x s ∧ x s≤1) (n : ℕ) : + 0≤gaussianHierarchyMoment μ q x n ∧ gaussianHierarchyMoment μ q x n≤1 := by + have ht := hierarchyMarkedMoment_tendsto_gaussian μ q hx hb n + have h (m : ℕ) := hierarchyMarkedMoment_mem_unit μ q (gaussianQuantizerWeight_nonneg m) + (gaussianQuantizerWeight_sum m) (fun s : Fin d → GaussianQuantizerLabel m => hb (fun k => (s k).val)) n + exact ⟨ge_of_tendsto ht (Eventually.of_forall (fun m => (h m).1)), + le_of_tendsto ht (Eventually.of_forall (fun m => (h m).2))⟩ + +lemma normalized_moment_bound {M : ℝ} (hM : 0≤M ∧ M≤1) (z : ℝ) (n : ℕ) : + ‖-M/(n:ℝ)*z^n‖≤|z|^n := by + by_cases hn : n=0 + · simp [hn] + have hn1 : (1:ℝ)≤n := by exact_mod_cast Nat.pos_of_ne_zero hn + simp only [Real.norm_eq_abs,abs_mul,abs_div,abs_neg,abs_of_nonneg hM.1, + abs_of_nonneg (Nat.cast_nonneg n : (0:ℝ)≤n),abs_pow] + exact mul_le_of_le_one_left (pow_nonneg (abs_nonneg z) n) + ((div_le_one (by positivity)).mpr (hM.2.trans hn1)) + +lemma affine_log_bounded {d : ℕ} {x : (Fin d → ℝ) → ℝ} + (hb : ∀ s,0≤x s ∧ x s≤1) {z : ℝ} (hz : |z|<1) (s : Fin d → ℝ) : + |Real.log (1-z*x s)|≤|Real.log (1-|z|)|+|Real.log (1+|z|)| := by + have hp : 0<1-|z| := by linarith + have hb' : |z*x s|≤|z| := by + rw [abs_mul,abs_of_nonneg (hb s).1] + exact mul_le_of_le_one_right (abs_nonneg z) (hb s).2 + have hl : 1-|z|≤1-z*x s := by linarith [(abs_le.mp hb').2] + have hu : 1-z*x s≤1+|z| := by linarith [(abs_le.mp hb').1] + have hlogl := Real.log_le_log hp hl + have hlogu := Real.log_le_log (hp.trans_le hl) hu + rw [abs_le] + constructor + · linarith [neg_abs_le (Real.log (1-|z|)),abs_nonneg (Real.log (1+|z|))] + · linarith [le_abs_self (Real.log (1+|z|)),abs_nonneg (Real.log (1-|z|))] + + + +theorem GG_gaussian_hierarchy_log_identity {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ha : ∀ k : Fin (d+1),overlapDiscount μ (q k.succ)≠0) + {x : (Fin (d+1) → ℝ) → ℝ} (hx : Continuous x) (hb : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : + gaussianHierarchyRisk (fun k => overlapDiscount μ (q k.succ)) + (fun s => Real.log (1-z*x s))= + ∑' n,-gaussianHierarchyMoment μ q x n/(n:ℝ)*z^n := by + let a : Fin (d+1) → ℝ := fun k => overlapDiscount μ (q k.succ) + let f : (Fin (d+1) → ℝ) → ℝ := fun s => Real.log (1-z*x s) + have hf : Continuous f := (continuous_const.sub (hx.const_mul z)).log + (fun s => ne_of_gt (affine_mark_pos (hb s) hz)) + have hfB (s : Fin (d+1) → ℝ) : |f s|≤|Real.log (1-|z|)|+|Real.log (1+|z|)| := + affine_log_bounded hb hz s + have hleft := quantizedHierarchyRisk_tendsto (E:=Unit) (a:=a) (f:=fun _ s => f s) + (fun k => measureReal_nonneg) (hf.comp continuous_snd) (fun _ s => hfB s) + (u:=fun _ => ()) (e:=()) tendsto_const_nhds + have heq (m : ℕ) : finiteHierarchyRisk (gaussianQuantizerWeight m) a + (fun s : Fin (d+1) → GaussianQuantizerLabel m => f (fun k => (s k).val))= + ∑' n,-hierarchyMarkedMoment μ q (gaussianQuantizerWeight m) + (fun s : Fin (d+1) → GaussianQuantizerLabel m => x (fun k => (s k).val)) n/(n:ℝ)*z^n := by + rw [← hierarchyLog_eq_finiteHierarchyRisk (gaussianQuantizerWeight_nonneg m) + (gaussianQuantizerWeight_sum m) a ha (fun s => affine_mark_pos (hb _) hz)] + rw [GG_hierarchy_log_identity hG hgg hu q hq h0 h1 ha + (gaussianQuantizerWeight_nonneg m) (gaussianQuantizerWeight_sum m) (fun s => hb _) hz] + simp only [FormalMultilinearSeries.sum,hierarchyLogSeries,FormalMultilinearSeries.ofScalars_apply_eq,smul_eq_mul] + have hright : Tendsto (fun m => ∑' n,-hierarchyMarkedMoment μ q (gaussianQuantizerWeight m) + (fun s : Fin (d+1) → GaussianQuantizerLabel m => x (fun k => (s k).val)) n/(n:ℝ)*z^n) + atTop (𝓝 (∑' n,-gaussianHierarchyMoment μ q x n/(n:ℝ)*z^n)) := by + apply tendsto_tsum_of_dominated_convergence (summable_geometric_of_lt_one (abs_nonneg z) hz) + · intro n + exact (((hierarchyMarkedMoment_tendsto_gaussian μ q hx hb n).neg).div_const (n:ℝ)).mul_const (z^n) + · exact Eventually.of_forall fun m n => normalized_moment_bound + (hierarchyMarkedMoment_mem_unit μ q (gaussianQuantizerWeight_nonneg m) + (gaussianQuantizerWeight_sum m) (fun s => hb _) n) z n + simp_rw [heq] at hleft + exact tendsto_nhds_unique hleft hright + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma card_injective_replica_maps (r k : ℕ) : + (Finset.univ.filter (fun e : Fin k → Fin r => Function.Injective e)).card=r.descFactorial k := by + classical + let I := Finset.univ.filter (fun e : Fin k → Fin r => Function.Injective e) + let e : ↥I ≃ (Fin k ↪ Fin r) := + { toFun := fun e => ⟨e.val,(Finset.mem_filter.mp e.property).2⟩ + invFun := fun e => ⟨e,Finset.mem_filter.mpr ⟨Finset.mem_univ _,e.injective⟩⟩ + left_inv := fun e => rfl + right_inv := fun e => rfl } + change I.card=_ + rw [← Fintype.card_coe] + exact (Fintype.card_congr e).trans (by simp) + +lemma descFactorial_ratio_tendsto (k : ℕ) : + Tendsto (fun r : ℕ => ((r+1).descFactorial k:ℝ)/(r+1:ℕ)^k) atTop (𝓝 1) := by + have he : ∀ᶠ r : ℕ in atTop, + ((r+1).descFactorial k:ℝ)/(r+1:ℕ)^k= + ∏ i : Fin k,(1-(i:ℕ)/(r+1:ℝ)) := by + filter_upwards [eventually_ge_atTop k] with r hr + rw [Nat.descFactorial_eq_prod_range] + push_cast + rw [← Fin.prod_univ_eq_prod_range] + have hd : (r+1:ℝ)^k=∏ i:Fin k,(r+1:ℝ) := by simp + rw [hd,← Finset.prod_div_distrib] + apply Finset.prod_congr rfl + intro i _ + rw [Nat.cast_sub (by omega)] + have h : (r+1:ℝ)≠0 := by positivity + push_cast + field_simp + apply Tendsto.congr' (he.mono (fun r h => h.symm)) + have hi (i : Fin k) : Tendsto (fun r : ℕ => 1-(i:ℕ)/(r+1:ℝ)) atTop (𝓝 (1:ℝ)) := by + have h := tendsto_succ_reciprocal.const_mul (i:ℝ) + simpa only [mul_zero,sub_zero,mul_one_div,Nat.cast_add,Nat.cast_one] using tendsto_const_nhds.sub h + simpa using tendsto_finsetProd Finset.univ (fun i _ => hi i) + + + +theorem replica_average_moment_tendsto (k : ℕ) + (H : (r : ℕ) → (Fin k → Fin (r+1)) → ℝ) {M : ℝ} (_hM : 0≤M ∧ M≤1) + (hH : ∀ r e,0≤H r e ∧ H r e≤1) + (he : ∀ r e,Function.Injective e → H r e=M) : + Tendsto (fun r => (∑ e,H r e)/(r+1:ℕ)^k) atTop (𝓝 M) := by + classical + let C (r : ℕ) : ℝ := ((r+1).descFactorial k:ℝ)/(r+1:ℕ)^k + have hb (r : ℕ) : C r*M≤(∑ e,H r e)/(r+1:ℕ)^k ∧ + (∑ e,H r e)/(r+1:ℕ)^k≤C r*M+(1-C r) := by + let I : Finset (Fin k → Fin (r+1)) := Finset.univ.filter Function.Injective + have hsum : (∑ e∈I,H r e)=I.card*M := by + rw [Finset.sum_congr rfl (fun e he' => he r e ((Finset.mem_filter.mp he').2))] + simp only [Finset.sum_const,nsmul_eq_mul] + rfl + have hall : (∑ e,H r e)=(∑ e∈I,H r e)+∑ e∈Finset.univ\I,H r e := by + exact (Finset.sum_add_sum_compl I (fun e => H r e)).symm + have hlow : 0≤∑ e∈Finset.univ\I,H r e := Finset.sum_nonneg (fun e _ => (hH r e).1) + have hup : (∑ e∈Finset.univ\I,H r e)≤(Finset.univ\I).card := by + simpa using Finset.sum_le_sum (s:=Finset.univ\I) (fun e _ => (hH r e).2) + have hcard : I.card=(r+1).descFactorial k := card_injective_replica_maps _ _ + have hcc : (I.card:ℝ)+((Finset.univ\I).card:ℝ)=(r+1:ℕ)^k := by + have hh := Finset.card_sdiff_add_card_eq_card (Finset.subset_univ I) + have hh' : (Finset.univ\I).card+I.card=(r+1)^k := by simpa using hh + have hh'' : ((Finset.univ\I).card:ℝ)+(I.card:ℝ)=(r+1:ℕ)^k := by exact_mod_cast hh' + linarith + have hD : (0:ℝ)<(r+1:ℕ)^k := by positivity + rw [hall,hsum] + dsimp only [C] + rw [← hcard] + constructor + · rw [div_mul_eq_mul_div] + exact (div_le_div_iff_of_pos_right hD).mpr (by linarith) + · rw [div_mul_eq_mul_div] + apply (div_le_iff₀ hD).mpr + field_simp + nlinarith + have hC : Tendsto C atTop (𝓝 1) := descFactorial_ratio_tendsto k + have hl := hC.mul_const M + have hu : Tendsto (fun r => C r*M+(1-C r)) atTop (𝓝 M) := by + simpa using (hC.mul_const M).add ((tendsto_const_nhds : Tendsto (fun _ : ℕ => (1:ℝ)) atTop (𝓝 1)).sub hC) + apply tendsto_of_tendsto_of_tendsto_of_le_of_le (by simpa using hl) (by simpa using hu) + (fun r => (hb r).1) (fun r => (hb r).2) + +end SKCavity + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/UnitaryUp.lean b/lean/OAI/Probability/ParisiFinite/UnitaryUp.lean new file mode 100644 index 0000000000000000000000000000000000000000..4eb227d183f62b843401637c33046392e8d96aa9 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/UnitaryUp.lean @@ -0,0 +1,717 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Labels + +namespace OAI + +/-! Unitary Up. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology + +namespace HilbertChain +variable (H : ℕ → Type*) [∀n, NormedAddCommGroup (H n)] [∀n, InnerProductSpace ℂ (H n)] +variable (step : ∀n, H n →ₗᵢ[ℂ] H (n+1)) +variable (U : ∀n, H n ≃ₗᵢ[ℂ] H n) (N : ℕ) +variable (hU : ∀n, N ≤ n → ∀x, step n (U n x)=U (n+1) (step n x)) + +include hU in +lemma unitary_up (n m : ℕ) (hn : N ≤ n) (hnm : n ≤ m) (x : H n) : + up H step n m hnm (U n x)=U m (up H step n m hnm x) := by + induction m,hnm using Nat.le_induction with + | base => simp + | succ m h ih => + rw [up_succ H step n m h] + change step m (up H step n m h (U n x))=U (m+1) (step m (up H step n m h x)) + rw [ih,hU m (hn.trans h)] + +include hU in +lemma embed_unitary_up (n m : ℕ) (hn : N ≤ n) (hnm : n ≤ m) (x : H n) : + embed H step m (U m (up H step n m hnm x))=embed H step n (U n x) := by + rw [←unitary_up H step U N hU n m hn hnm,embed_up] + + + +def unitaryStage (n : ℕ) : H n →ₗᵢ[ℂ] Space H step := + (embed H step (n+N)).comp ((U (n+N)).toLinearIsometry.comp + (up H step n (n+N) (Nat.le_add_right n N))) + +include hU in +lemma unitaryStage_eq (n k : ℕ) (hnk : n ≤ k) (hk : N ≤ k) (x : H n) : + unitaryStage H step U N n x=embed H step k (U k (up H step n k hnk x)) := by + let m := n+N+k + have hnm : n+N ≤ m := Nat.le_add_right _ _ + have hkm : k ≤ m := by dsimp [m]; omega + have hN : N ≤ n+N := Nat.le_add_left _ _ + have he₁ := embed_unitary_up H step U N hU (n+N) m hN hnm + (up H step n (n+N) (Nat.le_add_right _ _) x) + have he₂ := embed_unitary_up H step U N hU k m hk hkm (up H step n k hnk x) + have hc₁ := congrArg (fun T => T x) + (up_comp H step n (n+N) m (Nat.le_add_right _ _) hnm) + have hc₂ := congrArg (fun T => T x) (up_comp H step n k m hnk hkm) + change up H step (n+N) m hnm (up H step n (n+N) _ x)=_ at hc₁ + change up H step k m hkm (up H step n k hnk x)=_ at hc₂ + rw [hc₁] at he₁ + rw [hc₂] at he₂ + exact he₁.symm.trans he₂ + +include hU in +lemma unitaryStage_compat (n : ℕ) (x : H n) : + unitaryStage H step U N (n+1) (step n x)=unitaryStage H step U N n x := by + let k := n+1+N + have hnk : n+1 ≤ k := Nat.le_add_right _ _ + have hk : N ≤ k := Nat.le_add_left _ _ + rw [unitaryStage_eq H step U N hU (n+1) k hnk hk, + unitaryStage_eq H step U N hU n k ((Nat.le_succ n).trans hnk) hk] + congr 2 + have h := congrArg (fun T => T x) (up_comp H step n (n+1) k (Nat.le_succ n) hnk) + simpa using h + +def limitIsometry : Space H step →ₗᵢ[ℂ] Space H step := + lift H step (unitaryStage H step U N) (unitaryStage_compat H step U N hU) + +@[simp] lemma limitIsometry_embed (n : ℕ) (hn : N ≤ n) (x : H n) : + limitIsometry H step U N hU (embed H step n x)=embed H step n (U n x) := by + rw [limitIsometry,lift_embed,unitaryStage_eq H step U N hU n n le_rfl hn] + simp + +include hU in +lemma symm_compat (n : ℕ) (hn : N ≤ n) (x : H n) : + step n ((U n).symm x)=(U (n+1)).symm (step n x) := by + apply (U (n+1)).injective + rw [←hU n hn,(U n).apply_symm_apply,(U (n+1)).apply_symm_apply] + +lemma limitIsometry_inverse (x : Space H step) : + limitIsometry H step (fun n => (U n).symm) N (symm_compat H step U N hU) + (limitIsometry H step U N hU x)=x := by + apply congrFun ((denseRange_embed H step).equalizer + ((limitIsometry H step (fun n => (U n).symm) N (symm_compat H step U N hU)).continuous.comp + (limitIsometry H step U N hU).continuous) continuous_id ?_) x + funext ⟨n,y⟩ + simp only [Function.comp_apply, id_eq] + have he := embed_up H step n (n+N) (Nat.le_add_right n N) y + rw [←he,limitIsometry_embed _ _ _ _ _ _ (Nat.le_add_left N n), + limitIsometry_embed _ _ _ _ _ _ (Nat.le_add_left N n),(U (n+N)).symm_apply_apply] + + + +def limitUnitary : Space H step ≃ₗᵢ[ℂ] Space H step where + toFun := limitIsometry H step U N hU + map_add' := (limitIsometry H step U N hU).map_add + map_smul' := (limitIsometry H step U N hU).map_smul + norm_map' := (limitIsometry H step U N hU).norm_map + invFun := limitIsometry H step (fun n => (U n).symm) N (symm_compat H step U N hU) + left_inv := limitIsometry_inverse H step U N hU + right_inv x := by + have h := limitIsometry_inverse H step (fun n => (U n).symm) N + (symm_compat H step U N hU) x + simpa only [LinearIsometryEquiv.symm_symm] using h + +@[simp] lemma limitUnitary_embed (n : ℕ) (hn : N ≤ n) (x : H n) : + limitUnitary H step U N hU (embed H step n x)=embed H step n (U n x) := + limitIsometry_embed H step U N hU n hn x + +@[simp] lemma limitUnitary_symm_embed (n : ℕ) (hn : N ≤ n) (x : H n) : + (limitUnitary H step U N hU).symm (embed H step n x)=embed H step n ((U n).symm x) := + limitIsometry_embed H step (fun n => (U n).symm) N (symm_compat H step U N hU) n hn x +end HilbertChain + +namespace PointedTree + +def ordinaryInfinity (w : List Gate) : WholeInfinity ≃ₗᵢ[ℂ] WholeInfinity := + HilbertChain.limitUnitary Level wholeStep (fun n => (ordinary w n).op) w.length + (ordinary_compatible w) + +@[simp] theorem ordinaryInfinity_embed (w : List Gate) (n : ℕ) (hn : w.length ≤ n) (x : Level n) : + ordinaryInfinity w (wholeEmbed n x)=wholeEmbed n ((ordinary w n).op x) := + HilbertChain.limitUnitary_embed _ _ _ _ _ _ hn x + +@[simp] theorem ordinaryInfinity_symm_embed (w : List Gate) (n : ℕ) (hn : w.length ≤ n) (x : Level n) : + (ordinaryInfinity w).symm (wholeEmbed n x)=wholeEmbed n ((ordinary w n).op.symm x) := + HilbertChain.limitUnitary_symm_embed _ _ _ _ _ _ hn x +end PointedTree + + + +open scoped InnerProductSpace Topology + +namespace PointedTree +open CoherentFock + +theorem gammaEmbedding_comp {E F G : Type*} + [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] + [NormedAddCommGroup G] [InnerProductSpace ℂ G] + (T : E →ₗᵢ[ℂ] F) (S : F →ₗᵢ[ℂ] G) : + (gammaEmbedding S).comp (gammaEmbedding T)=gammaEmbedding (S.comp T) := by + ext x + exact congrArg (fun A => A x) (Gamma_comp T S) + +@[simp] theorem modeEmbed_step (n : ℕ) (x : Mode n) : + modeEmbed (n+1) (modeStep n x)=modeEmbed n x := + HilbertChain.embed_step ModeSpace modeStep n x + + +def topFockMap (n : ℕ) : Level (n+1) →ₗᵢ[ℂ] SpinSpace ModeInfinity := + spinMap (gammaEmbedding (modeEmbed n)) + +@[simp] theorem topFockMap_step (n : ℕ) (x : Level (n+1)) : + topFockMap (n+1) (wholeStep (n+1) x)=topFockMap n x := by + change spinMap (gammaEmbedding (modeEmbed (n+1))) + (spinMap (gammaEmbedding (modeStep n)) x)=spinMap (gammaEmbedding (modeEmbed n)) x + have hm : (modeEmbed (n+1)).comp (modeStep n)=modeEmbed n := by + ext d + exact modeEmbed_step n d + ext i + change gammaEmbedding (modeEmbed (n+1)) (gammaEmbedding (modeStep n) (x i)) = + gammaEmbedding (modeEmbed n) (x i) + have h := gammaEmbedding_comp (modeStep n) (modeEmbed (n+1)) + rw [hm] at h + exact congrArg (fun T => T (x i)) h + +def unfoldStage (n : ℕ) : Level n →ₗᵢ[ℂ] SpinSpace ModeInfinity := + (topFockMap n).comp (wholeStep n) + +@[simp] theorem unfoldStage_compat (n : ℕ) (x : Level n) : + unfoldStage (n+1) (wholeStep n x)=unfoldStage n x := + topFockMap_step n (wholeStep n x) + + +def unfoldTree : WholeInfinity →ₗᵢ[ℂ] SpinSpace ModeInfinity := + HilbertChain.lift Level wholeStep unfoldStage unfoldStage_compat + +@[simp] theorem unfoldTree_embed_succ (n : ℕ) (x : Level (n+1)) : + unfoldTree (wholeEmbed (n+1) x)=topFockMap n x := by + rw [unfoldTree,HilbertChain.lift_embed] + exact topFockMap_step n x + +@[simp] theorem unfoldTree_vacuum : unfoldTree vacuumInfinity=vacuum ModeInfinity := by + rw [←embed_vac 1,unfoldTree_embed_succ] + ext i + change gammaEmbedding (modeEmbed 0) (vacuum (Mode 0) i)=vacuum ModeInfinity i + simp only [vacuum_apply,map_smul,gammaEmbedding_coherent,map_zero] + + +def spinSingleAux {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + (i : Fin 2) : E →ₗᵢ[ℂ] SpinOperators.Double E where + toFun x := PiLp.single 2 i x + map_add' x y := PiLp.single_add 2 i + map_smul' z x := by + apply WithLp.ofLp_injective + exact Pi.single_smul (f := fun _ : Fin 2 => E) i z x + norm_map' x := PiLp.norm_single 2 (fun _ : Fin 2 => E) i x + +def spinSingle (i : Fin 2) : Space ModeInfinity →ₗᵢ[ℂ] SpinSpace ModeInfinity := + spinSingleAux i + +@[simp] theorem spinSingle_apply (i : Fin 2) (x : Space ModeInfinity) : + spinSingle i x=PiLp.single 2 i x := rfl + +lemma spinMap_single {E F : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + [NormedAddCommGroup F] [InnerProductSpace ℂ F] (T : E →ₗᵢ[ℂ] F) + (i : Fin 2) (x : E) : spinMap T (PiLp.single 2 i x)=PiLp.single 2 i (T x) := by + ext j + by_cases h : j=i + · subst j; simp [spinMap_apply] + · simp [spinMap_apply,h] + +lemma coherent_in_unfoldTree_range (i : Fin 2) (d : ModeInfinity) : + spinSingle i (coherent d) ∈ Set.range unfoldTree := by + have hclosed : IsClosed (Set.range unfoldTree) := + unfoldTree.isometry.antilipschitzWith.isClosed_range unfoldTree.isometry.uniformContinuous + refine (HilbertChain.denseRange_embed ModeSpace modeStep).induction_on + (p := fun d => spinSingle i (coherent d) ∈ Set.range unfoldTree) d + (hclosed.preimage ((spinSingle i).continuous.comp continuous_coherent)) ?_ + rintro ⟨n,e⟩ + refine ⟨wholeEmbed (n+1) (PiLp.single 2 i (coherent e)),?_⟩ + rw [unfoldTree_embed_succ] + change spinMap (gammaEmbedding (modeEmbed n)) (PiLp.single 2 i (coherent e))=_ + rw [spinMap_single,gammaEmbedding_coherent] + rfl + +lemma spinSingle_in_unfoldTree_range (i : Fin 2) (x : Space ModeInfinity) : + spinSingle i x ∈ Set.range unfoldTree := by + have hclosed : IsClosed (Set.range unfoldTree) := + unfoldTree.isometry.antilipschitzWith.isClosed_range unfoldTree.isometry.uniformContinuous + let R := unfoldTree.toLinearMap.range + change spinSingle i x ∈ R + refine UniformSpace.Completion.induction_on x + (hclosed.preimage (spinSingle i).continuous) fun y => ?_ + rw [coe_eq_sum] + simp only [Finsupp.sum,map_sum,map_smul] + exact Submodule.sum_mem R fun e he => Submodule.smul_mem R _ (coherent_in_unfoldTree_range i e) + + + +theorem unfoldTree_surjective : Function.Surjective unfoldTree := by + intro x + let R := unfoldTree.toLinearMap.range + have h : (∑i : Fin 2,spinSingle i (x i)) ∈ R := + Submodule.sum_mem R fun i hi => spinSingle_in_unfoldTree_range i (x i) + have he : (∑i : Fin 2,spinSingle i (x i))=x := by + ext j + fin_cases j <;> simp [Fin.sum_univ_two] + rwa [he] at h + + +def treeFockEquiv : WholeInfinity ≃ₗᵢ[ℂ] SpinSpace ModeInfinity := + LinearIsometryEquiv.ofSurjective unfoldTree unfoldTree_surjective + +@[simp] lemma treeFockEquiv_apply (x : WholeInfinity) : treeFockEquiv x=unfoldTree x := rfl +end PointedTree + + + +open scoped InnerProductSpace Topology +namespace HilbertChain +variable (H : ℕ → Type*) [∀n, NormedAddCommGroup (H n)] [∀n, InnerProductSpace ℂ (H n)] +variable (step : ∀n, H n →ₗᵢ[ℂ] H (n+1)) +variable {F : Type*} [TopologicalSpace F] [T2Space F] + +theorem continuous_ext_above (N : ℕ) {f g : Space H step → F} + (hf : Continuous f) (hg : Continuous g) + (h : ∀n, N ≤ n → ∀x, f (embed H step n x)=g (embed H step n x)) : f=g := by + apply (denseRange_embed H step).equalizer hf hg + funext ⟨n,x⟩ + simp only [Function.comp_apply] + rw [←embed_up H step n (n+N) (Nat.le_add_right n N) x] + exact h (n+N) (Nat.le_add_left N n) _ +end HilbertChain + +namespace PointedTree +open CoherentFock RootSpin + + +def rootInfinity (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) : + WholeInfinity ≃ₗᵢ[ℂ] WholeInfinity := + HilbertChain.limitUnitary Level wholeStep (fun n => rootEquiv n A hA) 0 (by + intro n hn x + exact (congrArg (wholeStep n) (rootEquiv_apply n A hA x)).trans + ((root_empty n A x).trans (rootEquiv_apply (n+1) A hA (wholeStep n x)).symm)) + +@[simp] theorem rootInfinity_embed (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (n : ℕ) (x : Level n) : + rootInfinity A hA (wholeEmbed n x)=wholeEmbed n (root n A x) := by + exact (HilbertChain.limitUnitary_embed _ _ _ _ _ n (Nat.zero_le n) x).trans + (congrArg (wholeEmbed n) (rootEquiv_apply n A hA x)) + +@[simp] theorem rootInfinity_unfold (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (x : WholeInfinity) : + unfoldTree (rootInfinity A hA x)=SpinOperators.act A (unfoldTree x) := by + apply congrFun (HilbertChain.continuous_ext_above Level wholeStep 1 + (unfoldTree.continuous.comp (rootInfinity A hA).continuous) + ((SpinOperators.act A).continuous.comp unfoldTree.continuous) ?_) x + intro n hn y + obtain ⟨k,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : n≠0) + simp only [Function.comp_apply] + rw [rootInfinity_embed,unfoldTree_embed_succ,unfoldTree_embed_succ] + exact spinMap_root (gammaEmbedding (modeEmbed k)) A y + + + +theorem actual_insertionInfinity (w : List Gate) : + modeInWhole (insertionInfinity w)= + (ordinaryInfinity w).symm (rootInfinity Z Z_unitary (ordinaryInfinity w vacuumInfinity)) := by + rw [insertionInfinity,modeInWhole_embed,←embed_vac w.length, + ordinaryInfinity_embed w w.length le_rfl,rootInfinity_embed, + ordinaryInfinity_symm_embed w w.length le_rfl] + rfl + + +theorem ordinaryInfinity_cost (w : List Gate) (γ : ℝ) (x : WholeInfinity) : + unfoldTree (ordinaryInfinity (.cost γ::w) x)= + WZ (-(γ:ℂ) • insertionInfinity w) (unfoldTree (ordinaryInfinity w x)) := by + apply congrFun (HilbertChain.continuous_ext_above Level wholeStep (w.length+1) + (unfoldTree.continuous.comp (ordinaryInfinity (.cost γ::w)).continuous) + ((WZ (-(γ:ℂ) • insertionInfinity w)).continuous.comp (unfoldTree.continuous.comp (ordinaryInfinity w).continuous)) ?_) x + intro n hn y + obtain ⟨k,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : n≠0) + have hw : w.length ≤ k := by omega + simp only [Function.comp_apply] + rw [ordinaryInfinity_embed (.cost γ::w) _ (by simpa using hn), + ordinaryInfinity_embed w _ (by omega),unfoldTree_embed_succ,unfoldTree_embed_succ] + change spinMap (gammaEmbedding (modeEmbed k)) + (WZ (-(γ:ℂ) • (ordinary w k).insertion) ((ordinary w (k+1)).op y))=_ + rw [spinMap_cost,map_smul,insertionInfinity_stable w k hw] + rfl + +theorem ordinaryInfinity_mixer (w : List Gate) (β : ℝ) (x : WholeInfinity) : + unfoldTree (ordinaryInfinity (.mixer β::w) x)= + SpinOperators.act (R β) (unfoldTree (ordinaryInfinity w x)) := by + apply congrFun (HilbertChain.continuous_ext_above Level wholeStep (w.length+1) + (unfoldTree.continuous.comp (ordinaryInfinity (.mixer β::w)).continuous) + ((SpinOperators.act (R β)).continuous.comp (unfoldTree.continuous.comp (ordinaryInfinity w).continuous)) ?_) x + intro n hn y + obtain ⟨k,rfl⟩ := Nat.exists_eq_succ_of_ne_zero (by omega : n≠0) + simp only [Function.comp_apply] + rw [ordinaryInfinity_embed (.mixer β::w) _ (by simpa using hn), + ordinaryInfinity_embed w _ (by omega),unfoldTree_embed_succ,unfoldTree_embed_succ] + exact spinMap_root (gammaEmbedding (modeEmbed k)) (R β) ((ordinary w (k+1)).op y) + +end PointedTree + + + +open scoped InnerProductSpace Topology +namespace PointedTree +open CoherentFock RootSpin + + +def modeFock : ModeInfinity →ₗᵢ[ℂ] SpinSpace ModeInfinity := unfoldTree.comp modeInWhole + + +def ordinaryLocal (w : List Gate) : SpinSpace ModeInfinity ≃ₗᵢ[ℂ] SpinSpace ModeInfinity := + (treeFockEquiv.symm.trans (ordinaryInfinity w)).trans treeFockEquiv + +@[simp] theorem ordinaryLocal_apply (w : List Gate) (x : SpinSpace ModeInfinity) : + ordinaryLocal w x=unfoldTree (ordinaryInfinity w (treeFockEquiv.symm x)) := rfl + +@[simp] theorem ordinaryLocal_unfold (w : List Gate) (x : WholeInfinity) : + ordinaryLocal w (unfoldTree x)=unfoldTree (ordinaryInfinity w x) := by + change unfoldTree (ordinaryInfinity w (treeFockEquiv.symm (treeFockEquiv x)))=_ + rw [LinearIsometryEquiv.symm_apply_apply] + +@[simp] theorem ordinaryLocal_nil (x : SpinSpace ModeInfinity) : ordinaryLocal [] x=x := by + obtain ⟨y,rfl⟩ := unfoldTree_surjective x + rw [ordinaryLocal_unfold] + congr 1 + apply congrFun (HilbertChain.continuous_ext_above Level wholeStep 0 + (ordinaryInfinity []).continuous continuous_id ?_) y + intro n hn z + simp only [ordinaryInfinity_embed [] n (Nat.zero_le n),ordinary,EvenUnitary.ident] + rfl + +@[simp] theorem ordinaryLocal_cost (w : List Gate) (γ : ℝ) (x : SpinSpace ModeInfinity) : + ordinaryLocal (.cost γ::w) x=WZ (-(γ:ℂ) • insertionInfinity w) (ordinaryLocal w x) := by + exact ordinaryInfinity_cost w γ (treeFockEquiv.symm x) + +@[simp] theorem ordinaryLocal_mixer (w : List Gate) (β : ℝ) (x : SpinSpace ModeInfinity) : + ordinaryLocal (.mixer β::w) x=SpinOperators.act (R β) (ordinaryLocal w x) := by + exact ordinaryInfinity_mixer w β (treeFockEquiv.symm x) + +@[simp] theorem modeFock_insertion (w : List Gate) : + modeFock (insertionInfinity w)= + (ordinaryLocal w).symm (SpinOperators.act Z (ordinaryLocal w (vacuum ModeInfinity))) := by + apply (ordinaryLocal w).injective + rw [LinearIsometryEquiv.apply_symm_apply] + change ordinaryLocal w (unfoldTree (modeInWhole (insertionInfinity w)))=_ + rw [ordinaryLocal_unfold,actual_insertionInfinity,LinearIsometryEquiv.apply_symm_apply, + rootInfinity_unfold,←unfoldTree_vacuum,ordinaryLocal_unfold] + + +@[simp] theorem insertionInfinity_cost (w : List Gate) (γ : ℝ) : + insertionInfinity (.cost γ::w)=insertionInfinity w := by + rw [←insertionInfinity_stable w (w.length+1) (by omega)] + change modeEmbed (w.length+1) (ordinary (.cost γ::w) (w.length+1)).insertion=_ + congr 1 + exact EvenUnitary.cost_insertion _ _ _ _ + + +def toggledProbe (β τ : ℝ) (w : List Gate) : List Gate := + .mixer (-β):: .cost τ:: .mixer β::w + +@[simp] theorem ordinaryLocal_toggledProbe (w : List Gate) (β τ : ℝ) + (x : SpinSpace ModeInfinity) : + ordinaryLocal (toggledProbe β τ w) x= + probe (R β) (-(τ:ℂ) • insertionInfinity (.mixer β::w)) (ordinaryLocal w x) := by + simp only [toggledProbe,ordinaryLocal_mixer,ordinaryLocal_cost,probe_apply,R_star] + + + +theorem modeFock_rotated_insertion (w : List Gate) (β : ℝ) : + modeFock (insertionInfinity (.mixer β::w))= + (ordinaryLocal w).symm + (SpinOperators.act ((R β).conjTranspose*Z*R β) (ordinaryLocal w (vacuum ModeInfinity))) := by + rw [modeFock_insertion] + apply (ordinaryLocal (.mixer β::w)).injective + rw [LinearIsometryEquiv.apply_symm_apply] + simp only [ordinaryLocal_mixer,SpinOperators.act_mul,ContinuousLinearMap.comp_apply, + LinearIsometryEquiv.apply_symm_apply] + exact (root_right_inverse (R β) (R_unitary β) _).symm + + +def insertionYInfinity (w : List Gate) : ModeInfinity := insertionInfinity (.mixer (Real.pi/4)::w) + +@[simp] theorem modeFock_insertionY (w : List Gate) : + modeFock (insertionYInfinity w)= + (ordinaryLocal w).symm (SpinOperators.act Y (ordinaryLocal w (vacuum ModeInfinity))) := by + rw [insertionYInfinity,modeFock_rotated_insertion,R_quarter_conjugate_Z] + + +theorem rotated_insertion_eq (w : List Gate) (β : ℝ) : + insertionInfinity (.mixer β::w)= + (Real.cos (2*β):ℂ) • insertionInfinity w+ + (Real.sin (2*β):ℂ) • insertionYInfinity w := by + apply modeFock.injective + rw [map_add,map_smul,map_smul,modeFock_rotated_insertion,modeFock_insertion, + modeFock_insertionY,R_conjugate_Z] + change (ordinaryLocal w).symm (SpinOperators.rep (_) (_))=_ + simp only [map_add,map_smul,SpinOperators.rep_apply,add_apply,smul_apply] + +end PointedTree + + + +open scoped InnerProductSpace Topology +namespace PointedTree +open CoherentFock RootSpin + + +abbrev ShortPulse := ℝ × ℝ + + +def probePrefix (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) : ℕ → List Gate + | 0 => w + | k+1 => toggledProbe (a k).1 (r*(a k).2) (probePrefix r w a k) + +def actualProbeDirection (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : ModeInfinity := + insertionInfinity (.mixer (a k).1::probePrefix r w a k) + +def actualProbe (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : + SpinSpace ModeInfinity →L[ℂ] SpinSpace ModeInfinity := + probe (R (a k).1) (-((r*(a k).2 : ℝ):ℂ) • actualProbeDirection r w a k) + + +def probeGain (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : + SpinSpace ModeInfinity ≃ₗᵢ[ℂ] SpinSpace ModeInfinity := + (ordinaryLocal w).symm.trans (ordinaryLocal (probePrefix r w a k)) + +@[simp] theorem norm_actualProbeDirection (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : + ‖actualProbeDirection r w a k‖=1 := norm_insertionInfinity _ + +@[simp] theorem probeGain_apply (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (x : SpinSpace ModeInfinity) : + probeGain r w a k x=ordinaryLocal (probePrefix r w a k) ((ordinaryLocal w).symm x) := rfl + +@[simp] theorem probeGain_zero (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) + (x : SpinSpace ModeInfinity) : probeGain r w a 0 x=x := by + exact (ordinaryLocal w).apply_symm_apply x + +@[simp] theorem probeGain_succ (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (x : SpinSpace ModeInfinity) : + probeGain r w a (k+1) x=actualProbe r w a k (probeGain r w a k x) := by + exact ordinaryLocal_toggledProbe (probePrefix r w a k) (a k).1 (r*(a k).2) + ((ordinaryLocal w).symm x) + + + +theorem probeGain_product (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) + (x : SpinSpace ModeInfinity) : + probeGain r w a k x=ProbeProduct.act (actualProbe r w a) (List.range k).reverse x := by + induction k with + | zero => simpa only [List.range_zero,List.reverse_nil,ProbeProduct.act_nil] using probeGain_zero r w a x + | succ k ih => + rw [probeGain_succ,ih,List.range_succ,List.reverse_append] + rfl + + +theorem actual_hermitian_diagonal (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : + ⟪actualProbeDirection r w a k,insertionInfinity w⟫_ℂ= + ⟪SpinOperators.act ((R (a k).1).conjTranspose*Z*R (a k).1) + (probeGain r w a k (ordinaryLocal w (vacuum ModeInfinity))), + probeGain r w a k (SpinOperators.act Z (ordinaryLocal w (vacuum ModeInfinity)))⟫_ℂ := by + rw [←modeFock.inner_map_map] + change ⟪modeFock (insertionInfinity (.mixer (a k).1::probePrefix r w a k)), + modeFock (insertionInfinity w)⟫_ℂ=_ + rw [modeFock_rotated_insertion,modeFock_insertion] + rw [←(ordinaryLocal (probePrefix r w a k)).inner_map_map] + simp only [LinearIsometryEquiv.apply_symm_apply,probeGain_apply,LinearIsometryEquiv.symm_apply_apply] + + + +theorem actual_direction_change_bound (r : ℝ) (w : List Gate) (a : ℕ → ShortPulse) (k : ℕ) : + ‖actualProbeDirection r w a k-insertionInfinity (.mixer (a k).1::w)‖≤ + ‖probeGain r w a k (ordinaryLocal w (vacuum ModeInfinity))- + ordinaryLocal w (vacuum ModeInfinity)‖+ + ‖probeGain r w a k (SpinOperators.act ((R (a k).1).conjTranspose*Z*R (a k).1) + (ordinaryLocal w (vacuum ModeInfinity)))- + SpinOperators.act ((R (a k).1).conjTranspose*Z*R (a k).1) + (ordinaryLocal w (vacuum ModeInfinity))‖ := by + let P := (R (a k).1).conjTranspose*Z*R (a k).1 + have hPu : P ∈ unitary _ := mul_mem (mul_mem (root_adjoint_unitary _ (R_unitary _)) Z_unitary) (R_unitary _) + have h := ForwardControl.insertion_from_forward + (ordinaryLocal (probePrefix r w a k)) (ordinaryLocal w) (SpinOperators.act P) + (fun x => (SpinOperators.norm_act hPu x).le) (vacuum ModeInfinity) 1 + rw [←modeFock.norm_map (actualProbeDirection r w a k-insertionInfinity (.mixer (a k).1::w)),map_sub] + change ‖modeFock (insertionInfinity (.mixer (a k).1::probePrefix r w a k))- + modeFock (insertionInfinity (.mixer (a k).1::w))‖≤_ + rw [modeFock_rotated_insertion,modeFock_rotated_insertion] + simpa only [one_smul,LinearIsometryEquiv.apply_symm_apply,probeGain_apply, + LinearIsometryEquiv.symm_apply_apply] using h + +end PointedTree + +namespace ForwardControl +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] + + +theorem identity_error_split (V : H ≃ₗᵢ[ℂ] H) (o s ρ : H) : + ‖V (o+s+ρ)-(o+s+ρ)‖≤‖V o-o‖+2*‖s‖+2*‖ρ‖ := by + have he : V (o+s+ρ)-(o+s+ρ)=(V o-o)+(V s-s)+(V ρ-ρ) := by + simp only [map_add] + abel + rw [he] + have h1 := norm_add_le (V o-o) (V s-s) + have h2 := norm_add_le ((V o-o)+(V s-s)) (V ρ-ρ) + have h3 := norm_sub_le (V s) s + have h4 := norm_sub_le (V ρ) ρ + simp only [V.norm_map] at h3 h4 + linarith + + + +theorem conjugation_error_split (V : H ≃ₗᵢ[ℂ] H) (P : H →L[ℂ] H) + (hP : ∀x,‖P x‖≤‖x‖) (o s ρ : H) : + ‖V (o+s+ρ)-(o+s+ρ)‖+‖V (P (o+s+ρ))-P (o+s+ρ)‖≤ + ‖V o-o‖+‖V (P o)-P o‖+4*‖s‖+4*‖ρ‖ := by + have h1 := identity_error_split V o s ρ + have h2 := identity_error_split V (P o) (P s) (P ρ) + simp only [map_add] at * + have h3 := hP s + have h4 := hP ρ + linarith + +end ForwardControl + + + +open scoped InnerProductSpace +namespace CoherentFock +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℂ E] + +omit [NormedAddCommGroup E] [InnerProductSpace ℂ E] in +@[simp] theorem spinMass_prePhaseZ (θ : ℝ) (x : PreSpin E) : + spinMass (prePhaseZ θ x)=spinMass x := by + simp only [spinMass,prePhaseZ,mass_smul,Complex.norm_exp_ofReal_mul_I,one_mul] + +omit [InnerProductSpace ℂ E] in +theorem SpinRadiusLE.prePhaseZ {x : PreSpin E} {B : ℝ} (hx : SpinRadiusLE x B) (θ : ℝ) : + SpinRadiusLE (prePhaseZ θ x) B := fun i => (hx i).smul _ + +omit [NormedAddCommGroup E] [InnerProductSpace ℂ E] in +theorem spinMass_preProbePhase (A : Matrix (Fin 2) (Fin 2) ℂ) (θ : ℝ) (x : PreSpin E) : + spinMass (preProbePhase A θ x)≤ matrixMass A.conjTranspose*matrixMass A*spinMass x := by + unfold preProbePhase + calc + _ ≤ matrixMass A.conjTranspose*spinMass (prePhaseZ θ (preRoot A x)) := spinMass_preRoot _ _ + _ = matrixMass A.conjTranspose*spinMass (preRoot A x) := by rw [spinMass_prePhaseZ] + _ ≤ matrixMass A.conjTranspose*(matrixMass A*spinMass x) := + mul_le_mul_of_nonneg_left (spinMass_preRoot _ _) (matrixMass_nonneg _) + _ = _ := by ring + +omit [InnerProductSpace ℂ E] in +theorem SpinRadiusLE.preProbePhase {x : PreSpin E} {B : ℝ} (hx : SpinRadiusLE x B) + (A : Matrix (Fin 2) (Fin 2) ℂ) (θ : ℝ) : SpinRadiusLE (preProbePhase A θ x) B := + ((hx.preRoot A).prePhaseZ θ).preRoot A.conjTranspose + + + +def preCenteredProbe (A : Matrix (Fin 2) (Fin 2) ℂ) (D e : E) (x : PreSpin E) : PreSpin E := + preProbePhase A (-2*(⟪D,e⟫_ℂ).im) (preProbe A D x) + +@[simp] theorem spinCoe_preCenteredProbe (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (D e : E) (x : PreSpin E) : + spinCoe (preCenteredProbe A D e x)=spinW (-e) (probe A D (spinW e (spinCoe x))) := by + rw [preCenteredProbe,spinCoe_preProbePhase,spinCoe_preProbe,centered_toggled_probe A hA] + +theorem spinMass_preCenteredProbe (A : Matrix (Fin 2) (Fin 2) ℂ) (D e : E) (x : PreSpin E) + (M : ℝ) (hM : 0≤M) (hA : matrixMass A≤M) (hAs : matrixMass A.conjTranspose≤M) : + spinMass (preCenteredProbe A D e x)≤M^4*spinMass x := by + have h1 := spinMass_preProbePhase A (-2*(⟪D,e⟫_ℂ).im) (preProbe A D x) + have h2 := spinMass_preProbe A D x + calc + _ ≤ matrixMass A.conjTranspose*matrixMass A*spinMass (preProbe A D x) := h1 + _ ≤ M*M*(M*M*spinMass x) := by + have hm : matrixMass A.conjTranspose*matrixMass A≤M*M := + mul_le_mul hAs hA (matrixMass_nonneg _) hM + exact mul_le_mul hm (h2.trans (mul_le_mul_of_nonneg_right hm (spinMass_nonneg _))) + (spinMass_nonneg _) (mul_nonneg hM hM) + _ = _ := by ring + +theorem SpinRadiusLE.preCenteredProbe {x : PreSpin E} {B : ℝ} (hx : SpinRadiusLE x B) + (A : Matrix (Fin 2) (Fin 2) ℂ) (D e : E) : + SpinRadiusLE (preCenteredProbe A D e x) (‖D‖+B) := + (hx.preProbe A D).preProbePhase A _ + + + +theorem spinCoe_coreCentered {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (D : ι → E) (e : E) + (hA : ∀j∈l,A j∈unitary _) (x : PreSpin E) : + spinCoe (ProbeProduct.coreAct (fun j => preCenteredProbe (A j) (D j) e) l x)= + spinW (-e) (ProbeProduct.act (fun j => probe (A j) (D j)) l (spinW e (spinCoe x))) := by + induction l with + | nil => simp [ProbeProduct.coreAct,ProbeProduct.act] + | cons j l ih => + rw [ProbeProduct.coreAct_cons,spinCoe_preCenteredProbe _ (hA j (by simp)), + ih (fun k hk => hA k (by simp [hk])),spinW_inv',ProbeProduct.act_cons] + + +theorem spinMass_coreCentered {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (D : ι → E) (e : E) (M : ℝ) + (hM : 0≤M) (hA : ∀j∈l,matrixMass (A j)≤M) + (hAs : ∀j∈l,matrixMass (A j).conjTranspose≤M) (x : PreSpin E) : + spinMass (ProbeProduct.coreAct (fun j => preCenteredProbe (A j) (D j) e) l x)≤ + (M^4)^l.length*spinMass x := by + induction l with + | nil => simp [ProbeProduct.coreAct] + | cons j l ih => + rw [ProbeProduct.coreAct_cons] + apply (spinMass_preCenteredProbe _ _ _ _ M hM (hA j (by simp)) (hAs j (by simp))).trans + calc + _ ≤ M^4*((M^4)^l.length*spinMass x) := mul_le_mul_of_nonneg_left + (ih (fun k hk => hA k (by simp [hk])) (fun k hk => hAs k (by simp [hk]))) (by positivity) + _ = _ := by simp only [List.length_cons,pow_succ]; ring + + +theorem radius_coreCentered {ι : Type*} (l : List ι) + (A : ι → Matrix (Fin 2) (Fin 2) ℂ) (D : ι → E) (e : E) (B L : ℝ) + (hD : ∀j∈l,‖D j‖≤L) (x : PreSpin E) (hx : SpinRadiusLE x B) : + SpinRadiusLE (ProbeProduct.coreAct (fun j => preCenteredProbe (A j) (D j) e) l x) + (B+l.length*L) := by + induction l with + | nil => simpa [ProbeProduct.coreAct] using hx + | cons j l ih => + rw [ProbeProduct.coreAct_cons] + have hh := (ih (fun k hk => hD k (by simp [hk]))).preCenteredProbe (A j) (D j) e + intro i + apply (hh i).mono + simp only [List.length_cons,Nat.cast_add,Nat.cast_one] + have h := hD j (by simp) + linarith + +end CoherentFock + +namespace RootSpin +open CoherentFock + +theorem matrixMass_R_le (β : ℝ) : matrixMass (R β)≤4 := by + have hc : |Real.cos β|≤1 := abs_le.mpr ⟨Real.neg_one_le_cos _,Real.cos_le_one _⟩ + have hs : |Real.sin β|≤1 := abs_le.mpr ⟨Real.neg_one_le_sin _,Real.sin_le_one _⟩ + simp only [matrixMass,Fin.sum_univ_two,R_apply] + norm_num [norm_mul,Real.norm_eq_abs,-Complex.ofReal_cos,-Complex.ofReal_sin] + linarith + +end RootSpin + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/UsedVertices.lean b/lean/OAI/Probability/ParisiFinite/UsedVertices.lean new file mode 100644 index 0000000000000000000000000000000000000000..63497e19635d83564a93e570cbfc760138fd873c --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/UsedVertices.lean @@ -0,0 +1,534 @@ +import Mathlib +import OAI.Probability.ParisiFinite.MaskedDisorder + +namespace OAI + +/-! Used Vertices. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter + +namespace SKQAOA.SiteHistories +variable {n : ℕ} + +def usedVertices (r : Edge n) (H : Finset (Edge n)) : Finset (Fin n) := + (H∪{r}).biUnion (fun e => {e.1.1,e.1.2}) + +lemma fst_mem_usedVertices (r : Edge n) (H : Finset (Edge n)) {e : Edge n} + (he : e∈H∪{r}) : e.1.1∈usedVertices r H := + Finset.mem_biUnion.mpr ⟨e,he,by simp⟩ + +lemma snd_mem_usedVertices (r : Edge n) (H : Finset (Edge n)) {e : Edge n} + (he : e∈H∪{r}) : e.1.2∈usedVertices r H := + Finset.mem_biUnion.mpr ⟨e,he,by simp⟩ + +lemma card_usedVertices_le (r : Edge n) (H : Finset (Edge n)) : + (usedVertices r H).card ≤ 2*H.card+2 := by + calc + _ ≤ ∑e∈H∪{r}, ({e.1.1,e.1.2}:Finset (Fin n)).card := Finset.card_biUnion_le + _ ≤ ∑e∈H∪{r}, 2 := by + apply Finset.sum_le_sum + intro e he + exact (Finset.card_insert_le _ _).trans (by simp) + _ ≤ 2*H.card+2 := by + simp only [Finset.sum_const,smul_eq_mul] + have h := Finset.card_union_le H ({r}:Finset (Edge n)) + simp only [Finset.card_singleton] at h + omega + +lemma rootFactor_local (p : ℕ) (γ : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) (a b : Fin n → Site p) + (hab : ∀i∈usedVertices r H, a i=b i) : rootFactor p γ r a=rootFactor p γ r b := by + unfold rootFactor + rw [hab _ (fst_mem_usedVertices r H (by simp)),hab _ (snd_mem_usedVertices r H (by simp))] + +lemma cluster_integrand_local (p : ℕ) (γ : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) (a b : Fin n → Site p) + (hab : ∀i∈usedVertices r H, a i=b i) : + rootFactor p γ r a*(∏e∈H,(factor p γ r a e-1))= + rootFactor p γ r b*(∏e∈H,(factor p γ r b e-1)) := by + rw [rootFactor_local p γ r H a b hab] + congr 1 + apply Finset.prod_congr rfl + intro e he + unfold factor + rw [hab _ (fst_mem_usedVertices r H (Finset.mem_union_left _ he)), + hab _ (snd_mem_usedVertices r H (Finset.mem_union_left _ he))] + +lemma norm_rootFactor_le (p : ℕ) (γ : Fin p → ℝ) (r : Edge n) (a : Fin n → Site p) : + ‖rootFactor p γ r a‖ ≤ (2*angleMass p γ)*(Real.sqrt (n:ℝ))⁻¹ := by + have hD := angleMass_nonneg p γ + simp only [rootFactor,norm_mul,norm_inv,Complex.norm_real,Real.norm_eq_abs,abs_bitSpin, + Complex.norm_I,one_mul,abs_of_nonneg (Real.sqrt_nonneg _), + abs_of_pos (edgeKernel_pos _ _ _ _ _)] + calc + _ ≤ (Real.sqrt (n:ℝ))⁻¹*(2*angleMass p γ)*1 := by + apply mul_le_mul + · exact mul_le_mul_of_nonneg_left (abs_delta_le _ _ _ _) (by positivity) + · exact edgeKernel_le_one _ _ _ _ _ + · exact le_of_lt (edgeKernel_pos _ _ _ _ _) + · positivity + _ = _ := by ring + +lemma norm_factor_sub_one_le (p : ℕ) (γ : Fin p → ℝ) (r : Edge n) + (a : Fin n → Site p) (e : Edge n) : + ‖factor p γ r a e-1‖ ≤ (2*angleMass p γ)^2*((n:ℝ)⁻¹)/2 := by + by_cases he : e=r + · simp only [factor,he,ite_true,sub_self,norm_zero] + positivity + · simp only [factor,he,ite_false,←Complex.ofReal_one,←Complex.ofReal_sub, + Complex.norm_real,Real.norm_eq_abs] + exact abs_edgeKernel_sub_one_le _ _ _ _ _ + + +theorem norm_cluster_le_local (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) : + ‖cluster p γ β r H‖ ≤ (∑s:Site p,‖weight p β s‖)^(usedVertices r H).card * + ((2*angleMass p γ)*(Real.sqrt (n:ℝ))⁻¹ * + ((2*angleMass p γ)^2*((n:ℝ)⁻¹)/2)^H.card) := by + have hD := angleMass_nonneg p γ + apply FiniteHistory.norm_expectation_le_of_local (weight p β) (sum_weight p β) + (usedVertices r H) _ (cluster_integrand_local p γ r H) + · positivity + · intro a + rw [norm_mul,norm_prod] + apply mul_le_mul (norm_rootFactor_le p γ r a) + · calc + _ ≤ ∏e∈H,((2*angleMass p γ)^2*((n:ℝ)⁻¹)/2) := + Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) (fun _ _ => norm_factor_sub_one_le _ _ _ _ _) + _ = _ := by rw [Finset.prod_const] + · exact Finset.prod_nonneg fun _ _ => norm_nonneg _ + · positivity + + +def variation (p : ℕ) (β : Fin p → ℝ) : ℝ := 1+∑s:Site p,‖weight p β s‖ + +lemma one_le_variation (p : ℕ) (β : Fin p → ℝ) : 1≤variation p β := by + unfold variation + exact le_add_of_nonneg_right (Finset.sum_nonneg fun _ _ => norm_nonneg _) + +def activity (p : ℕ) (γ β : Fin p → ℝ) : ℝ := + (variation p β)^2*(2*angleMass p γ)^2/2 + +def markedBound (p : ℕ) (γ β : Fin p → ℝ) : ℝ := + (variation p β)^2*(2*angleMass p γ) + +lemma activity_nonneg (p : ℕ) (γ β : Fin p → ℝ) : 0≤activity p γ β := by + unfold activity + positivity + +lemma markedBound_nonneg (p : ℕ) (γ β : Fin p → ℝ) : 0 ≤ markedBound p γ β := by + unfold markedBound + exact mul_nonneg (sq_nonneg _) (mul_nonneg (by norm_num) (angleMass_nonneg p γ)) + + + +theorem norm_cluster_le (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) : + ‖cluster p γ β r H‖ ≤ markedBound p γ β*(Real.sqrt (n:ℝ))⁻¹ * + (activity p γ β/(n:ℝ))^H.card := by + have hD := angleMass_nonneg p γ + have hV : 0≤variation p β := (by norm_num : (0:ℝ)≤1).trans (one_le_variation p β) + have hW : 0≤∑s:Site p,‖weight p β s‖ := Finset.sum_nonneg fun _ _ => norm_nonneg _ + calc + _ ≤ (∑s:Site p,‖weight p β s‖)^(usedVertices r H).card * + ((2*angleMass p γ)*(Real.sqrt (n:ℝ))⁻¹ * + ((2*angleMass p γ)^2*((n:ℝ)⁻¹)/2)^H.card) := norm_cluster_le_local p γ β r H + _ ≤ (variation p β)^(2*H.card+2) * + ((2*angleMass p γ)*(Real.sqrt (n:ℝ))⁻¹ * + ((2*angleMass p γ)^2*((n:ℝ)⁻¹)/2)^H.card) := by + apply mul_le_mul_of_nonneg_right _ (by positivity) + exact (pow_le_pow_left₀ hW (show (∑s:Site p,‖weight p β s‖) ≤ variation p β by + unfold variation; linarith) _).trans + (pow_le_pow_right₀ (one_le_variation p β) (card_usedVertices_le r H)) + _ = _ := by + simp only [markedBound,activity,pow_add,pow_mul,mul_pow,div_eq_mul_inv] + ring + +end SKQAOA.SiteHistories + + + +open scoped BigOperators + +namespace SKQAOA.SiteHistories +variable {m n N p : ℕ} + + +def edgeMap (f : Fin m ↪o Fin n) : Edge m ↪ Edge n where + toFun e := ⟨(f e.1.1,f e.1.2),f.strictMono e.2⟩ + inj' := by + intro e e' h + apply Subtype.ext + exact Prod.ext (f.injective (congrArg (fun z : Edge n => z.1.1) h)) + (f.injective (congrArg (fun z : Edge n => z.1.2) h)) + +@[simp] lemma edgeMap_fst (f : Fin m ↪o Fin n) (e : Edge m) : + (edgeMap f e).1.1=f e.1.1 := rfl +@[simp] lemma edgeMap_snd (f : Fin m ↪o Fin n) (e : Edge m) : + (edgeMap f e).1.2=f e.1.2 := rfl + +lemma usedVertices_map (f : Fin m ↪o Fin n) (r : Edge m) (H : Finset (Edge m)) : + usedVertices (edgeMap f r) (H.map (edgeMap f))=(usedVertices r H).map f.toEmbedding := by + classical + have hu : H.map (edgeMap f)∪{edgeMap f r}=(H∪{r}).map (edgeMap f) := by simp + unfold usedVertices + rw [hu] + simp only [Finset.map_eq_image,Finset.biUnion_image,Finset.image_biUnion] + apply Finset.biUnion_congr rfl + intro e he + simp only [edgeMap_fst,edgeMap_snd,Finset.image_insert,Finset.image_singleton] + rfl + + + +theorem graphCoefficient_relabel (N p : ℕ) (γ β : Fin p → ℝ) + (f : Fin m ↪o Fin n) (r : Edge m) (H : Finset (Edge m)) : + graphCoefficient N n p γ β (edgeMap f r) (H.map (edgeMap f))= + graphCoefficient N m p γ β r H := by + unfold graphCoefficient + have he (a : Fin n → Site p) : + (∏e∈H.map (edgeMap f),if e=edgeMap f r then (0:ℂ) else + (kernelScaled N p γ (a e.1.1) (a e.1.2):ℂ))= + ∏e∈H,if e=r then (0:ℂ) else + (kernelScaled N p γ ((a ∘ f) e.1.1) ((a ∘ f) e.1.2):ℂ) := by + simp only [Finset.prod_map,Function.Embedding.apply_eq_iff_eq,edgeMap_fst,edgeMap_snd,Function.comp_def] + simp_rw [he] + exact FiniteHistory.expectation_embedding (weight p β) (sum_weight p β) f.toEmbedding + (fun a : Fin m → Site p => + (bitSpin (a r.1.1).1:ℂ)*(bitSpin (a r.1.2).1:ℂ)*Complex.I* + (delta p γ (a r.1.1) (a r.1.2):ℂ)* + (edgeKernel N p γ (a r.1.1) (a r.1.2):ℂ)* + ∏e∈H,if e=r then 0 else (kernelScaled N p γ (a e.1.1) (a e.1.2):ℂ)) + +def rawGraphCoefficient (N m p : ℕ) (γ β : Fin p → ℝ) (r : Edge m) + (H : Finset (Edge m)) : ℂ := + FiniteHistory.expectation (weight p β) (fun a : Fin m → Site p => + (bitSpin (a r.1.1).1:ℂ)*(bitSpin (a r.1.2).1:ℂ)*Complex.I* + (delta p γ (a r.1.1) (a r.1.2):ℂ)* + (edgeKernel N p γ (a r.1.1) (a r.1.2):ℂ)* + ∏e∈H,if e=r then 0 else ((edgeKernel N p γ (a e.1.1) (a e.1.2):ℂ)-1)) + +lemma graphCoefficient_eq_pow_mul_raw (N m p : ℕ) (γ β : Fin p → ℝ) (r : Edge m) + (H : Finset (Edge m)) : + graphCoefficient N m p γ β r H=(N:ℂ)^H.card*rawGraphCoefficient N m p γ β r H := by + unfold graphCoefficient rawGraphCoefficient FiniteHistory.expectation + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + have he (e : Edge m) : (if e=r then (0:ℂ) else (kernelScaled N p γ (a e.1.1) (a e.1.2):ℂ))= + (N:ℂ)*(if e=r then (0:ℂ) else (edgeKernel N p γ (a e.1.1) (a e.1.2):ℂ)-1) := by + split_ifs <;> simp [kernelScaled] + simp_rw [he] + rw [Finset.prod_mul_distrib,Finset.prod_const] + ring + +lemma cluster_eq_inv_sqrt_mul_raw (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) : + cluster p γ β r H=((Real.sqrt (n:ℝ))⁻¹:ℂ)*rawGraphCoefficient n n p γ β r H := by + unfold cluster rawGraphCoefficient FiniteHistory.expectation + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro a ha + have he (e : Edge n) : factor p γ r a e-1= + if e=r then (0:ℂ) else (edgeKernel n p γ (a e.1.1) (a e.1.2):ℂ)-1 := by + split_ifs with h <;> simp [factor,h] + simp_rw [he] + unfold rootFactor + ring + +lemma cluster_eq_scaled (p : ℕ) (γ β : Fin p → ℝ) (r : Edge n) + (H : Finset (Edge n)) : + cluster p γ β r H=((Real.sqrt (n:ℝ))⁻¹:ℂ)* + (n:ℂ)⁻¹^H.card*graphCoefficient n n p γ β r H := by + have hn : n≠0 := Nat.ne_of_gt (lt_of_le_of_lt (Nat.zero_le _) r.1.2.isLt) + have hnC : (n:ℂ)≠0 := Nat.cast_ne_zero.mpr hn + rw [cluster_eq_inv_sqrt_mul_raw,graphCoefficient_eq_pow_mul_raw] + rw [←mul_assoc, mul_assoc ((Real.sqrt (n:ℝ))⁻¹:ℂ),←mul_pow,inv_mul_cancel₀ hnC,one_pow,mul_one] + +end SKQAOA.SiteHistories + + + +open scoped BigOperators + +namespace SKQAOA.SiteHistories +attribute [local instance] Classical.propDecidable +variable {m n : ℕ} + +abbrev MarkedGraph (n : ℕ) := Edge n × Finset (Edge n) +abbrev FullGraph (m : ℕ) := {g : MarkedGraph m // usedVertices g.1 g.2=Finset.univ} +abbrev SupportSet (n m : ℕ) := {U : Finset (Fin n) // U.card=m} + +def graphMap (f : Fin m ↪o Fin n) (g : MarkedGraph m) : MarkedGraph n := + (edgeMap f g.1,g.2.map (edgeMap f)) + +lemma graphMap_injective (f : Fin m ↪o Fin n) : Function.Injective (graphMap f) := by + intro g h he + apply Prod.ext + · exact (edgeMap f).injective (congrArg Prod.fst he) + · exact Finset.map_injective (edgeMap f) (congrArg Prod.snd he) + +lemma graphMap_support (f : Fin m ↪o Fin n) (g : MarkedGraph m) : + usedVertices (graphMap f g).1 (graphMap f g).2=(usedVertices g.1 g.2).map f.toEmbedding := + usedVertices_map f g.1 g.2 + +lemma edgeMap_surjective_on (U : SupportSet n m) (e : Edge n) + (h₁ : e.1.1∈U.1) (h₂ : e.1.2∈U.1) : + ∃d : Edge m,edgeMap (U.1.orderEmbOfFin U.2) d=e := by + let i : Fin m := (U.1.orderIsoOfFin U.2).symm ⟨e.1.1,h₁⟩ + let j : Fin m := (U.1.orderIsoOfFin U.2).symm ⟨e.1.2,h₂⟩ + have hi : U.1.orderEmbOfFin U.2 i=e.1.1 := by + exact congrArg Subtype.val ((U.1.orderIsoOfFin U.2).apply_symm_apply ⟨e.1.1,h₁⟩) + have hj : U.1.orderEmbOfFin U.2 j=e.1.2 := by + exact congrArg Subtype.val ((U.1.orderIsoOfFin U.2).apply_symm_apply ⟨e.1.2,h₂⟩) + have hij : i edgeMap f e∈g.2) + have hH : H.map (edgeMap f)=g.2 := by + ext e + constructor + · intro he + obtain ⟨d,hd,rfl⟩ := Finset.mem_map.mp he + exact (Finset.mem_filter.mp hd).2 + · intro he + obtain ⟨d,hd⟩ := edgeMap_surjective_on U e + (hg ▸ fst_mem_usedVertices g.1 g.2 (Finset.mem_union_left _ he)) + (hg ▸ snd_mem_usedVertices g.1 g.2 (Finset.mem_union_left _ he)) + exact Finset.mem_map.mpr ⟨d,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hd ▸ he⟩,hd⟩ + have hs : usedVertices r H=Finset.univ := by + apply Finset.map_injective f.toEmbedding + rw [←usedVertices_map,hr,hH,hg] + exact (Finset.map_orderEmbOfFin_univ U.1 U.2).symm + exact ⟨⟨(r,H),hs⟩,Prod.ext hr hH⟩ + + + +def embedFullGraph (z : SupportSet n m × FullGraph m) : + {g : MarkedGraph n // (usedVertices g.1 g.2).card=m} := + ⟨graphMap (z.1.1.orderEmbOfFin z.1.2) z.2.1,by + rw [graphMap_support,z.2.2,Finset.map_orderEmbOfFin_univ] + exact z.1.2⟩ + +lemma embedFullGraph_support (z : SupportSet n m × FullGraph m) : + usedVertices (embedFullGraph z).1.1 (embedFullGraph z).1.2=z.1.1 := by + change usedVertices (graphMap _ _).1 (graphMap _ _).2=_ + rw [graphMap_support,z.2.2,Finset.map_orderEmbOfFin_univ] + +lemma embedFullGraph_bijective : Function.Bijective (embedFullGraph (n := n) (m := m)) := by + constructor + · rintro ⟨U,g⟩ ⟨V,h⟩ he + have hU : U=V := by + apply Subtype.ext + rw [←embedFullGraph_support (U,g),←embedFullGraph_support (V,h),he] + subst V + have hgh : g=h := Subtype.ext (graphMap_injective (U.1.orderEmbOfFin U.2) + (congrArg Subtype.val he)) + exact Prod.ext rfl hgh + · intro g + let U : SupportSet n m := ⟨usedVertices g.1.1 g.1.2,g.2⟩ + obtain ⟨h,hh⟩ := graphMap_surjective_on U g.1 rfl + exact ⟨(U,h),Subtype.ext hh⟩ + +def supportGraphEquiv (n m : ℕ) : SupportSet n m × FullGraph m ≃ + {g : MarkedGraph n // (usedVertices g.1 g.2).card=m} := + Equiv.ofBijective embedFullGraph embedFullGraph_bijective + +lemma card_supportSet (n m : ℕ) : Fintype.card (SupportSet n m)=n.choose m := by + have he : (Finset.univ.filter (fun U : Finset (Fin n) => U.card=m))= + Finset.univ.powersetCard m := by + ext U + simp + rw [Fintype.card_subtype,he,Finset.card_powersetCard,Finset.card_univ,Fintype.card_fin] + + + +theorem sum_full_graphs {R : Type*} [AddCommMonoid R] + (F : MarkedGraph n → R) : + (∑g : MarkedGraph n with (usedVertices g.1 g.2).card=m,F g)= + ∑U : SupportSet n m,∑h : FullGraph m,F (graphMap (U.1.orderEmbOfFin U.2) h.1) := by + calc + _ = ∑g : {g : MarkedGraph n // (usedVertices g.1 g.2).card=m},F g.1 := + Finset.sum_subtype _ (by simp) F + _ = ∑z : SupportSet n m × FullGraph m,F ((supportGraphEquiv n m) z).1 := + ((supportGraphEquiv n m).sum_comp (fun g => F g.1)).symm + _ = _ := Fintype.sum_prod_type _ + +end SKQAOA.SiteHistories + + + +open scoped BigOperators Topology + +namespace BoundedBranch + + + +def Tree (n : ℕ) : ℕ → Type + | 0 => Unit + | h+1 => Fin n → Option (Tree n h) + +instance treeFintype (n : ℕ) : (h : ℕ) → Fintype (Tree n h) + | 0 => inferInstanceAs (Fintype Unit) + | h+1 => letI := treeFintype n h + inferInstanceAs (Fintype (Fin n → Option (Tree n h))) + +def size (n : ℕ) : (h : ℕ) → Tree n h → ℕ + | 0, _ => 0 + | h+1, b => ∑i, (b i).elim 0 (fun c => 1+size n h c) + +def weight (n : ℕ) (x : ℝ) : (h : ℕ) → Tree n h → ℝ + | 0, _ => 1 + | h+1, b => ∏i, (b i).elim 1 (fun c => (x/(n:ℝ))*weight n x h c) + +def partition (n h : ℕ) (x : ℝ) : ℝ := ∑b : Tree n h, weight n x h b + +@[simp] theorem partition_zero (n : ℕ) (x : ℝ) : partition n 0 x=1 := by + change (∑_ : Unit, (1:ℝ))=1 + simp + +theorem weight_nonneg (n h : ℕ) {x : ℝ} (hx : 0≤x) (b : Tree n h) : + 0≤weight n x h b := by + induction h with + | zero => exact zero_le_one + | succ h ih => + apply Finset.prod_nonneg + intro i hi + cases hb : b i with + | none => exact zero_le_one + | some c => exact mul_nonneg (div_nonneg hx (Nat.cast_nonneg n)) (ih c) + +theorem partition_nonneg (n h : ℕ) {x : ℝ} (hx : 0≤x) : 0≤partition n h x := + Finset.sum_nonneg fun b _ => weight_nonneg n h hx b + + +theorem partition_succ (n h : ℕ) (x : ℝ) : + partition n (h+1) x=(1+x/(n:ℝ)*partition n h x)^n := by + classical + change (∑b : Fin n → Option (Tree n h), ∏i, + (b i).elim 1 (fun c => (x/(n:ℝ))*weight n x h c)) = _ + rw [← Fintype.prod_sum (fun (_ : Fin n) (c : Option (Tree n h)) => + c.elim 1 (fun b => (x/(n:ℝ))*weight n x h b))] + simp [← Finset.mul_sum,partition] + + +def tower (x : ℝ) : ℕ → ℝ + | 0 => 1 + | h+1 => Real.exp (x*tower x h) + +theorem tower_pos (x : ℝ) (h : ℕ) : 0 exact zero_lt_one + | succ h => exact Real.exp_pos _ + +theorem partition_step_bound (n h : ℕ) {x : ℝ} (hx : 0≤x) : + partition n (h+1) x ≤ Real.exp (x*partition n h x) := by + rw [partition_succ] + rcases n.eq_zero_or_pos with rfl|hn + · simp only [pow_zero] + exact Real.one_le_exp_iff.mpr (mul_nonneg hx (partition_nonneg 0 h hx)) + have hp := partition_nonneg n h hx + have hnR : (n:ℝ)≠0 := by exact_mod_cast hn.ne' + calc + (1+x/(n:ℝ)*partition n h x)^n ≤ (Real.exp (x/(n:ℝ)*partition n h x))^n := by + apply pow_le_pow_left₀ (by positivity) + simpa only [add_comm] using Real.add_one_le_exp (x/(n:ℝ)*partition n h x) + _ = Real.exp (x*partition n h x) := by + rw [←Real.exp_nat_mul] + congr 1 + field_simp [hnR] + +theorem partition_le_tower (n h : ℕ) {x : ℝ} (hx : 0≤x) : + partition n h x ≤ tower x h := by + induction h with + | zero => simp [tower] + | succ h ih => + exact (partition_step_bound n h hx).trans + (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left ih hx)) + +theorem weight_eq_pow (n h : ℕ) (x : ℝ) (b : Tree n h) : + weight n x h b=(x/(n:ℝ))^(size n h b) := by + induction h with + | zero => rfl + | succ h ih => + change (∏i, (b i).elim 1 (fun c => (x/(n:ℝ))*weight n x h c)) = + (x/(n:ℝ))^(∑i, (b i).elim 0 (fun c => 1+size n h c)) + rw [←Finset.prod_pow_eq_pow_sum] + apply Finset.prod_congr rfl + intro i hi + cases hb : b i with + | none => simp + | some c => simp [ih,pow_add] + +theorem weight_scale (n h : ℕ) (x z : ℝ) (b : Tree n h) : + weight n (z*x) h b=z^(size n h b)*weight n x h b := by + simp only [weight_eq_pow,mul_div_assoc,mul_pow] + +def tail (n h L : ℕ) (x : ℝ) : ℝ := + ∑b : Tree n h with L ≤ size n h b, weight n x h b + + + +theorem tail_bound (n h L : ℕ) {x : ℝ} (hx : 0≤x) : + tail n h L x ≤ tower (2*x) h/(2:ℝ)^L := by + have htwo : (0:ℝ)<2^L := pow_pos (by norm_num) _ + have hbound : (2:ℝ)^L*tail n h L x ≤ partition n h (2*x) := by + classical + unfold tail partition + rw [Finset.mul_sum] + calc + _ ≤ ∑b : Tree n h with L ≤ size n h b, weight n (2*x) h b := by + apply Finset.sum_le_sum + intro b hb + rw [weight_scale] + exact mul_le_mul_of_nonneg_right + (pow_le_pow_right₀ (by norm_num) (Finset.mem_filter.mp hb).2) + (weight_nonneg n h hx b) + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) + (fun b _ _ => weight_nonneg n h (by positivity) b) + apply (le_div_iff₀ htwo).mpr + rw [mul_comm] + exact hbound.trans (partition_le_tower n h (by positivity)) + +theorem uniform_tail {h : ℕ} {x ε : ℝ} (hx : 0≤x) (hε : 0<ε) : + ∃L : ℕ, ∀n : ℕ, tail n h L x<ε := by + open Filter in + have ht : Tendsto (fun L : ℕ => tower (2*x) h/(2:ℝ)^L) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop (tendsto_pow_atTop_atTop_of_one_lt (r := (2:ℝ)) (by norm_num)) + obtain ⟨L,hL⟩ := Filter.eventually_atTop.mp (ht.eventually (gt_mem_nhds hε)) + exact ⟨L,fun n => (tail_bound n h L hx).trans_lt (hL L le_rfl)⟩ + +end BoundedBranch + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/VarianceProdDecomposition.lean b/lean/OAI/Probability/ParisiFinite/VarianceProdDecomposition.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac02b20e7702784ff7713648e7d3a1f45e798ddb --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/VarianceProdDecomposition.lean @@ -0,0 +1,717 @@ +import Mathlib +import OAI.Probability.ParisiFinite.Average + +namespace OAI + +/-! Variance Prod Decomposition. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace GaussianConcentration +open SKGaussian ParisiInterpolation + + +lemma variance_prod_decomposition {E F : Type*} [MeasurableSpace E] [MeasurableSpace F] + {μ : Measure E} {ν : Measure F} [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + {f : E × F → ℝ} (hf : MemLp f 2 (μ.prod ν)) + (hs : ∀ y, MemLp (fun x => f (x,y)) 2 μ) + (hm : MemLp (fun y => ∫ x, f (x,y) ∂μ) 2 ν) : + variance f (μ.prod ν) = (∫ y, variance (fun x => f (x,y)) μ ∂ν)+ + variance (fun y => ∫ x, f (x,y) ∂μ) ν := by + have he (y : F) : variance (fun x => f (x,y)) μ= + (∫ x, f (x,y)^2 ∂μ)-(∫ x, f (x,y) ∂μ)^2 := variance_eq_sub (hs y) + simp_rw [he] + rw [variance_eq_sub hf, variance_eq_sub hm, + integral_sub hf.integrable_sq.integral_prod_right hm.integrable_sq] + simp only [Pi.pow_apply] + rw [integral_prod_symm _ hf.integrable_sq, + integral_prod_symm _ (hf.integrable (by norm_num))] + ring + +def firstMean {n : ℕ} (f : (Fin (n+1) → ℝ) → ℝ) (y : Fin n → ℝ) : ℝ := + ∫ z, f (Fin.cons z y) ∂gaussianReal 0 1 + +lemma CoordinateLipschitz.first_slice {n : ℕ} {c : Fin (n+1) → ℝ≥0} + {f : (Fin (n+1) → ℝ) → ℝ} (hf : CoordinateLipschitz c f) (y : Fin n → ℝ) : + LipschitzWith (c 0) (fun z => f (Fin.cons z y)) := by + rw [lipschitzWith_iff_norm_sub_le] + intro z w + simpa [Fin.sum_univ_succ, Real.norm_eq_abs] using hf (Fin.cons z y) (Fin.cons w y) + +lemma CoordinateLipschitz.firstMean {n : ℕ} {c : Fin (n+1) → ℝ≥0} + {f : (Fin (n+1) → ℝ) → ℝ} (hf : CoordinateLipschitz c f) : + CoordinateLipschitz (fun i => c i.succ) (firstMean f) := by + intro x y + have hmx := memLp_lipschitz (hf.first_slice x) (memLp_id_gaussianReal (μ:=0) (v:=1) 2) + have hmy := memLp_lipschitz (hf.first_slice y) (memLp_id_gaussianReal (μ:=0) (v:=1) 2) + have hix := hmx.integrable (by norm_num) + have hiy := hmy.integrable (by norm_num) + unfold GaussianConcentration.firstMean + rw [← integral_sub hix hiy] + apply abs_integral_le_integral_abs.trans + have h := integral_mono (hix.sub hiy).abs + (integrable_const (∑ i, (c i.succ:ℝ)*|x i-y i|) : Integrable _ (gaussianReal 0 1)) + (fun z => by simpa [Fin.sum_univ_succ] using hf (Fin.cons z x) (Fin.cons z y)) + simpa using h + + + +theorem CoordinateLipschitz.variance_le {n : ℕ} {c : Fin n → ℝ≥0} + {f : (Fin n → ℝ) → ℝ} (hf : CoordinateLipschitz c f) : + variance f (standardLaw n) ≤ ∑ i, (c i:ℝ)^2 := by + induction n with + | zero => + have he : f=fun _ => f 0 := funext (fun x => congrArg f (Subsingleton.elim x 0)) + rw [he] + simp [variance, evariance] + | succ n ih => + let e : (ℝ × (Fin n → ℝ)) ≃ᵐ (Fin (n+1) → ℝ) := + (MeasurableEquiv.piFinSuccAbove (fun _ => ℝ) 0).symm + have hpres : MeasurePreserving e ((gaussianReal 0 1).prod (standardLaw n)) (standardLaw (n+1)) := + (measurePreserving_piFinSuccAbove (fun _ => gaussianReal 0 1) 0).symm + have he (z : ℝ) (y : Fin n → ℝ) : e (z,y)=Fin.cons z y := by + simp [e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv] + have hfull : MemLp (fun p => f (e p)) 2 ((gaussianReal 0 1).prod (standardLaw n)) := + hf.memLp.comp_measurePreserving hpres + have hs (y : Fin n → ℝ) : MemLp (fun z => f (e (z,y))) 2 (gaussianReal 0 1) := by + simp_rw [he] + exact memLp_lipschitz (hf.first_slice y) (memLp_id_gaussianReal (μ:=0) (v:=1) 2) + have htotal := variance_prod_decomposition hfull hs (by + simp only [he] + change MemLp (GaussianConcentration.firstMean f) 2 (standardLaw n) + exact hf.firstMean.memLp) + have hv : variance (fun p => f (e p)) ((gaussianReal 0 1).prod (standardLaw n))= + variance f (standardLaw (n+1)) := hpres.variance_fun_comp hf.memLp.aemeasurable + rw [hv] at htotal + simp only [he] at htotal + rw [htotal, Fin.sum_univ_succ] + apply add_le_add _ (ih hf.firstMean) + have hmvar : Integrable (fun y => variance (fun z => f (Fin.cons z y)) (gaussianReal 0 1)) + (standardLaw n) := by + have hv' (y : Fin n → ℝ) := variance_eq_sub (hs y) + simp only [he] at hv' + simp_rw [hv'] + have hin : Integrable (fun y => ∫ z, f (Fin.cons z y)^2 ∂gaussianReal 0 1) (standardLaw n) := by + simpa only [he] using hfull.integrable_sq.integral_prod_right + exact hin.sub hf.firstMean.memLp.integrable_sq + have hle := integral_mono hmvar (integrable_const ((c 0:ℝ)^2)) + (fun y => variance_lipschitz_real (hf.first_slice y)) + simpa using hle +end GaussianConcentration + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace GaussianConcentration +open SKGaussian SKQAOA ParisiInterpolation ParisiFinite + +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +lemma logPartition_lipschitz : LipschitzWith 1 (@logPartition ι _) := by + have he : spinTrace (ι:=ι) 1 = logPartition := by funext x; simp [spinTrace] + rw [← he] + exact spinTrace_lipschitz one_ne_zero + +lemma logPartition_coordinate {d : ℕ} (A : ι → Fin d → ℝ) (c : Fin d → ℝ≥0) + (hA : ∀ s k, |A s k| ≤ c k) : + CoordinateLipschitz c (fun z => logPartition (linearField A z)) := by + intro x y + have h := logPartition_lipschitz.norm_sub_le (linearField A x) (linearField A y) + simp only [NNReal.coe_one, one_mul, Real.norm_eq_abs] at h + apply h.trans + apply (pi_norm_le_iff_of_nonneg (by positivity)).mpr + intro s + calc + ‖linearField A x s-linearField A y s‖ = |∑ k, A s k*(x k-y k)| := by + simp only [linearField, Real.norm_eq_abs, mul_sub, Finset.sum_sub_distrib] + _ ≤ ∑ k, |A s k*(x k-y k)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ _ := Finset.sum_le_sum (fun k _ => by + rw [abs_mul] + exact mul_le_mul_of_nonneg_right (hA s k) (abs_nonneg _)) + +omit [Fintype ι] [Nonempty ι] in +lemma variance_reindex_field {κ : Type*} [Fintype κ] (A : ι → κ → ℝ) + (f : (ι → ℝ) → ℝ) : + variance (fun z => f (linearField (fun s k => A s ((Fintype.equivFin κ).symm k)) z)) + (standardLaw (Fintype.card κ)) = variance (fun z => f (field A z)) (gaussianLaw κ) := by + let e : Fin (Fintype.card κ) ≃ κ := (Fintype.equivFin κ).symm + let T : (Fin (Fintype.card κ) → ℝ) ≃ᵐ (κ → ℝ) := MeasurableEquiv.piCongrLeft (fun _ => ℝ) e + have hm : MeasurePreserving T (standardLaw (Fintype.card κ)) (gaussianLaw κ) := + measurePreserving_piCongrLeft (fun _ => gaussianReal 0 1) e + have he (x : Fin (Fintype.card κ) → ℝ) : + field A (T x) = linearField (fun s k => A s (e k)) x := by + funext s + change (∑ k, A s k*T x k)=∑ k, A s (e k)*x k + rw [← e.sum_comp (fun k => A s k*T x k)] + simp [T, MeasurableEquiv.piCongrLeft_apply_apply] + rw [← hm.map_eq, variance_map_equiv] + change _ = variance (fun z => f (field A (T z))) _ + simp_rw [he] + rfl + + + +lemma variance_field_logPartition_le {κ : Type*} [Fintype κ] + (A : ι → κ → ℝ) (c : κ → ℝ≥0) (hA : ∀ s k, |A s k| ≤ c k) : + variance (fun z => logPartition (field A z)) (gaussianLaw κ) ≤ ∑ k, (c k:ℝ)^2 := by + rw [← variance_reindex_field] + have h := (logPartition_coordinate (fun s k => A s ((Fintype.equivFin κ).symm k)) + (fun k => c ((Fintype.equivFin κ).symm k)) (fun s k => hA s _)).variance_le + rw [(Fintype.equivFin κ).symm.sum_comp (fun k => (c k:ℝ)^2)] at h + exact h + + + +theorem sk_logPartition_variance_le {n : ℕ} (hn : 0 < n) (β : ℝ) : + variance (fun J => logPartition (fun σ => β*hamiltonian n J σ)) (disorderLaw n) ≤ + β^2*((n:ℝ)-1)/2 := by + let b : ℝ≥0 := ⟨|β| *(Real.sqrt (n:ℝ))⁻¹, by positivity⟩ + have hb (σ : Configuration n) (e : Edge n) : |β*skCoeff n σ e| ≤ b := by + change |β*skCoeff n σ e| ≤ |β| * (Real.sqrt (n:ℝ))⁻¹ + simp [skCoeff, abs_mul, abs_inv, abs_of_nonneg (Real.sqrt_nonneg _), spin_abs] + have h := variance_field_logPartition_le (fun σ e => β*skCoeff n σ e) (fun _ => b) hb + simp only [field_scale, field_skCoeff] at h + change variance (fun J => logPartition (fun σ => β*hamiltonian n J σ)) (disorderLaw n) ≤ _ at h + apply h.trans_eq + change (∑ _ : Edge n, (|β| * (Real.sqrt (n:ℝ))⁻¹)^2) = _ + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_pow, sq_abs, + inv_pow, Real.sq_sqrt (Nat.cast_nonneg n)] + have hn' : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + have hc := card_edges_real n + field_simp [hn'] + nlinarith only [hc] + +lemma sk_pressureDensity_variance_le {n : ℕ} (hn : 0 < n) (β : ℝ) : + variance (fun J => logPartition (fun σ => β*hamiltonian n J σ)/(n:ℝ)) (disorderLaw n) ≤ + β^2/(2*(n:ℝ)) := by + simp only [div_eq_mul_inv] + rw [variance_mul_const] + have h := mul_le_mul_of_nonneg_right (sk_logPartition_variance_le hn β) (sq_nonneg ((n:ℝ)⁻¹)) + apply h.trans + have hn' : (0:ℝ) < n := Nat.cast_pos.mpr hn + field_simp + nlinarith [sq_nonneg β] + + + +theorem tendsto_sk_pressureDensity_variance (β : ℝ) : + Tendsto (fun n : ℕ => variance + (fun J => logPartition (fun σ => β*hamiltonian n J σ)/(n:ℝ)) (disorderLaw n)) atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall (fun n => variance_nonneg _ _)) + ((eventually_gt_atTop 0).mono fun n hn => sk_pressureDensity_variance_le hn β) + have h := (tendsto_const_nhds (x := β^2/2) (f := atTop)).mul + (tendsto_inv_atTop_zero.comp (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop)) + convert h using 1 <;> simp [div_eq_mul_inv, mul_left_comm, mul_comm] + +end GaussianConcentration + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] [Nonempty ι] + + +def replicaMean {r : ℕ} (x : ι → ℝ) (f : (Fin r → ι) → ℝ) : ℝ := + ∑ σ, replicaWeight x σ*f σ + +lemma replicaMean_single {r : ℕ} (x : ι → ℝ) (i : Fin r) (f : ι → ℝ) : + replicaMean x (fun σ => f (σ i)) = ∑ s, weight x s*f s := by + classical + have h := Fintype.prod_sum (fun (j : Fin r) (s : ι) => weight x s * if j=i then f s else 1) + have he (σ : Fin r → ι) : + (∏ j, weight x (σ j)*(if j=i then f (σ j) else 1))=replicaWeight x σ*f (σ i) := by + rw [Finset.prod_mul_distrib] + simp [replicaWeight] + simp_rw [he] at h + unfold replicaMean + rw [← h] + have he' (j : Fin r) : (∑ s, weight x s*(if j=i then f s else 1))= + if j=i then ∑ s, weight x s*f s else 1 := by + split <;> simp_all [sum_weight] + simp_rw [he'] + simp + +lemma replicaMean_sum {r : ℕ} (x : ι → ℝ) (f : Fin r → ι → ℝ) : + replicaMean x (fun σ => ∑ l, f l (σ l))=∑ l, ∑ s, weight x s*f l s := by + simp only [replicaMean, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro l _ + exact replicaMean_single x l (f l) + +lemma replicaMean_sum_same {r : ℕ} (x : ι → ℝ) (f : ι → ℝ) : + replicaMean x (fun σ : Fin r → ι => ∑ l, f (σ l))=(r:ℝ)*∑ s, weight x s*f s := by + rw [replicaMean_sum] + simp + +omit [Nonempty ι] in +lemma replicaWeight_snoc {r : ℕ} (x : ι → ℝ) (σ : Fin r → ι) (s : ι) : + replicaWeight x (Fin.snoc σ s)=replicaWeight x σ*weight x s := by + simp [replicaWeight, Fin.prod_univ_castSucc] + +omit [Nonempty ι] in +lemma sum_tuples_snoc {r : ℕ} (f : (Fin (r+1) → ι) → ℝ) : + (∑ τ, f τ) = ∑ σ : Fin r → ι, ∑ s, f (Fin.snoc σ s) := by + rw [← (Fin.snocEquiv (fun _ : Fin (r+1) => ι)).sum_comp f, Fintype.sum_prod_type, Finset.sum_comm] + rfl + +omit [Nonempty ι] in +lemma replicaMean_snoc {r : ℕ} (x : ι → ℝ) (f : (Fin (r+1) → ι) → ℝ) : + replicaMean x f = ∑ σ : Fin r → ι, replicaWeight x σ*∑ s, weight x s*f (Fin.snoc σ s) := by + unfold replicaMean + rw [sum_tuples_snoc] + simp only [replicaWeight_snoc, Finset.mul_sum, mul_assoc] + +lemma replicaMean_marginal {r : ℕ} (x : ι → ℝ) (f : (Fin r → ι) → ℝ) : + replicaMean x (fun τ : Fin (r+1) → ι => f (fun l => τ l.castSucc))=replicaMean x f := by + rw [replicaMean_snoc] + simp [replicaMean, ← Finset.sum_mul, sum_weight] + +lemma integrable_replicaMean {d r : ℕ} (A : ι → Fin d → ℝ) (f : (Fin r → ι) → ℝ) : + Integrable (fun z => replicaMean (linearField A z) f) (standardLaw d) := by + exact integrable_finsetSum _ (fun σ _ => (integrable_linear_replicaWeight A σ).mul_const (f σ)) + + + +lemma integrable_replica_energy {d r : ℕ} (A : ι → Fin d → ℝ) + (i : Fin r) (f : (Fin r → ι) → ℝ) : + Integrable (fun z => ∑ σ, replicaWeight (linearField A z) σ* + (linearField A z (σ i)*f σ)) (standardLaw d) := by + apply integrable_finsetSum + intro σ _ + have he (z : Fin d → ℝ) : replicaWeight (linearField A z) σ*(linearField A z (σ i)*f σ)= + ∑ k, (A (σ i) k*f σ)*(z k*replicaWeight (linearField A z) σ) := by + simp only [linearField, Finset.sum_mul, Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + simp_rw [he] + exact integrable_finsetSum _ (fun k _ => (integrable_coord_replicaWeight A σ k).const_mul _) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] [Nonempty ι] + +lemma integrable_replicaWeight_derivative {d r : ℕ} (A : ι → Fin d → ℝ) + (σ : Fin r → ι) (k : Fin d) : + Integrable (fun z => replicaWeight (linearField A z) σ * + ((∑ l, A (σ l) k) - (∑ τ : Fin r → ι, + replicaWeight (linearField A z) τ * ∑ l, A (τ l) k))) (standardLaw d) := by + have h := integrable_weight_derivative (tupleCoeff A) σ k + simp only [replicaWeight_tupleCoeff, tupleCoeff] at h + exact h + + +def crossKernel {d : ℕ} (B A : ι → Fin d → ℝ) (s t : ι) : ℝ := + ∑ k, B s k*A t k + +lemma replica_covariance_algebra {d r : ℕ} (A B : ι → Fin d → ℝ) + (x : ι → ℝ) (σ : Fin r → ι) (s : ι) : + (∑ k, B s k*((∑ l, A (σ l) k)-(∑ τ : Fin r → ι, + replicaWeight x τ*∑ l, A (τ l) k))) = + (∑ l, crossKernel B A s (σ l))-(r:ℝ)*∑ t, weight x t*crossKernel B A s t := by + have he (k : Fin d) : (∑ τ : Fin r → ι, replicaWeight x τ*∑ l, A (τ l) k)= + (r:ℝ)*∑ t, weight x t*A t k := replicaMean_sum_same x (fun t => A t k) + simp_rw [he] + simp only [mul_sub, Finset.mul_sum, Finset.sum_sub_distrib] + congr 1 + · rw [Finset.sum_comm] + rfl + · simp only [crossKernel, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro t _ + apply Finset.sum_congr rfl + intro k _ + ring + +lemma integral_replica_linear {d r : ℕ} (A B : ι → Fin d → ℝ) + (σ : Fin r → ι) (s : ι) : + (∫ z, linearField B z s * replicaWeight (linearField A z) σ ∂standardLaw d) = + ∫ z, replicaWeight (linearField A z) σ * + ((∑ l, crossKernel B A s (σ l))-(r:ℝ)*∑ t, weight (linearField A z) t*crossKernel B A s t) + ∂standardLaw d := by + have hleft (z : Fin d → ℝ) : linearField B z s*replicaWeight (linearField A z) σ= + ∑ k, B s k*(z k*replicaWeight (linearField A z) σ) := by + simp [linearField, Finset.sum_mul, mul_assoc] + simp_rw [hleft] + rw [integral_finsetSum _ (fun k _ => (integrable_coord_replicaWeight A σ k).const_mul _)] + simp_rw [integral_const_mul, integral_coord_replicaWeight] + simp_rw [← integral_const_mul] + rw [← integral_finsetSum _ (fun k _ => (integrable_replicaWeight_derivative A σ k).const_mul _)] + apply integral_congr_ae + filter_upwards with z + rw [← replica_covariance_algebra A B] + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + +omit [Nonempty ι] in +lemma replica_covariance_snoc {d r : ℕ} (A B : ι → Fin d → ℝ) (x : ι → ℝ) + (i : Fin r) (f : (Fin r → ι) → ℝ) : + replicaMean x (fun τ : Fin (r+1) → ι => + f (fun l => τ l.castSucc)*crossKernel B A (τ i.castSucc) (τ (Fin.last r))) = + ∑ σ : Fin r → ι, replicaWeight x σ*f σ*∑ t, weight x t*crossKernel B A (σ i) t := by + rw [replicaMean_snoc] + apply Finset.sum_congr rfl + intro σ _ + simp only [Fin.snoc_castSucc, Fin.snoc_last] + rw [Finset.mul_sum] + simp only [mul_comm (weight x _), mul_assoc, ← Finset.mul_sum] + + + +theorem integral_replica_energy_covariance {d r : ℕ} (A B : ι → Fin d → ℝ) + (i : Fin r) (f : (Fin r → ι) → ℝ) : + (∫ z, ∑ σ, replicaWeight (linearField A z) σ*(linearField B z (σ i)*f σ) + ∂standardLaw d) = + (∫ z, replicaMean (linearField A z) (fun σ => f σ*∑ l, crossKernel B A (σ i) (σ l)) + ∂standardLaw d) - (r:ℝ)* + (∫ z, replicaMean (linearField A z) (fun τ : Fin (r+1) → ι => + f (fun l => τ l.castSucc)*crossKernel B A (τ i.castSucc) (τ (Fin.last r))) ∂standardLaw d) := by + have hi (σ : Fin r → ι) : Integrable (fun z => linearField B z (σ i)* + replicaWeight (linearField A z) σ) (standardLaw d) := by + have he (z : Fin d → ℝ) : linearField B z (σ i)*replicaWeight (linearField A z) σ= + ∑ k, B (σ i) k*(z k*replicaWeight (linearField A z) σ) := by + simp [linearField, Finset.sum_mul, mul_assoc] + simp_rw [he] + exact integrable_finsetSum _ (fun k _ => (integrable_coord_replicaWeight A σ k).const_mul _) + have hir (σ : Fin r → ι) : Integrable (fun z => replicaWeight (linearField A z) σ * + ((∑ l, crossKernel B A (σ i) (σ l))-(r:ℝ)*∑ t, weight (linearField A z) t*crossKernel B A (σ i) t)) + (standardLaw d) := by + simp_rw [← replica_covariance_algebra A B] + have he (z : Fin d → ℝ) : replicaWeight (linearField A z) σ * + (∑ k, B (σ i) k*((∑ l, A (σ l) k)-(∑ τ : Fin r → ι, + replicaWeight (linearField A z) τ*∑ l, A (τ l) k)))= + ∑ k, B (σ i) k*(replicaWeight (linearField A z) σ * + ((∑ l, A (σ l) k)-(∑ τ : Fin r → ι, + replicaWeight (linearField A z) τ*∑ l, A (τ l) k))) := by + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro k _ + ring + simp_rw [he] + exact integrable_finsetSum _ (fun k _ => (integrable_replicaWeight_derivative A σ k).const_mul _) + have he (z : Fin d → ℝ) (σ : Fin r → ι) : + replicaWeight (linearField A z) σ*(linearField B z (σ i)*f σ)= + (linearField B z (σ i)*replicaWeight (linearField A z) σ)*f σ := by ring + simp_rw [he] + rw [integral_finsetSum _ (fun σ _ => (hi σ).mul_const (f σ))] + simp_rw [integral_mul_const, integral_replica_linear, ← integral_mul_const] + rw [← integral_finsetSum _ (fun σ _ => (hir σ).mul_const (f σ))] + rw [← integral_const_mul, ← integral_sub (integrable_replicaMean A _) + ((integrable_replicaMean A _).const_mul _)] + apply integral_congr_ae + filter_upwards with z + rw [replica_covariance_snoc] + simp only [replicaMean, Finset.mul_sum, ← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro σ _ + simp [mul_sub, Finset.mul_sum, mul_assoc, mul_left_comm, mul_comm] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + + +def crossCov (B A : ι → κ → ℝ) (s t : ι) : ℝ := ∑ k, B s k*A t k + +omit [Fintype ι] [Nonempty ι] in +lemma crossCov_reindex (B A : ι → κ → ℝ) (s t : ι) : + crossKernel (fun s k => B s ((Fintype.equivFin κ).symm k)) + (fun s k => A s ((Fintype.equivFin κ).symm k)) s t = crossCov B A s t := + (Fintype.equivFin κ).symm.sum_comp (fun k => B s k*A t k) + + + +omit [Fintype ι] [Nonempty ι] in +lemma integral_reindex_pair (A B : ι → κ → ℝ) (f : (ι → ℝ) → (ι → ℝ) → ℝ) : + (∫ z, f (linearField (fun s k => A s ((Fintype.equivFin κ).symm k)) z) + (linearField (fun s k => B s ((Fintype.equivFin κ).symm k)) z) + ∂standardLaw (Fintype.card κ)) = ∫ z, f (field A z) (field B z) ∂gaussianLaw κ := by + let e : Fin (Fintype.card κ) ≃ κ := (Fintype.equivFin κ).symm + let T : (Fin (Fintype.card κ) → ℝ) ≃ᵐ (κ → ℝ) := MeasurableEquiv.piCongrLeft (fun _ => ℝ) e + have hm : MeasurePreserving T (standardLaw (Fintype.card κ)) (gaussianLaw κ) := + measurePreserving_piCongrLeft (fun _ => gaussianReal 0 1) e + have he (C : ι → κ → ℝ) (z : Fin (Fintype.card κ) → ℝ) : + field C (T z) = linearField (fun s k => C s (e k)) z := by + funext s + change (∑ k, C s k*T z k)=∑ k, C s (e k)*z k + rw [← e.sum_comp (fun k => C s k*T z k)] + simp [T, MeasurableEquiv.piCongrLeft_apply_apply] + have h := hm.integral_comp' (fun z => f (field A z) (field B z)) + simp_rw [he] at h + exact h + +lemma integrable_field_replicaWeight {r : ℕ} (A : ι → κ → ℝ) (σ : Fin r → ι) : + Integrable (fun z => replicaWeight (field A z) σ) (gaussianLaw κ) := by + apply (integrable_const (1:ℝ)).mono' + ((continuous_replicaWeight σ).comp (continuous_field A)).aestronglyMeasurable + filter_upwards with z + simpa only [Function.comp_apply, Real.norm_eq_abs, abs_of_nonneg (replicaWeight_nonneg _ _)] using replicaWeight_le_one (field A z) σ + +lemma integrable_field_replicaMean {r : ℕ} (A : ι → κ → ℝ) (f : (Fin r → ι) → ℝ) : + Integrable (fun z => replicaMean (field A z) f) (gaussianLaw κ) := by + exact integrable_finsetSum _ (fun σ _ => (integrable_field_replicaWeight A σ).mul_const (f σ)) + +lemma integrable_field_replica_energy {r : ℕ} (A B : ι → κ → ℝ) + (i : Fin r) (f : (Fin r → ι) → ℝ) : + Integrable (fun z => ∑ σ, replicaWeight (field A z) σ*(field B z (σ i)*f σ)) (gaussianLaw κ) := by + apply integrable_finsetSum + intro σ _ + have h := ((integrable_field B (σ i)).mul_const (f σ)).bdd_mul + ((continuous_replicaWeight σ).comp (continuous_field A)).aestronglyMeasurable + (c:=1) (Eventually.of_forall fun z => by + simpa only [Function.comp_apply, Real.norm_eq_abs, abs_of_nonneg (replicaWeight_nonneg _ _)] using replicaWeight_le_one (field A z) σ) + exact h + + + +theorem integral_field_replica_energy_covariance {r : ℕ} (A B : ι → κ → ℝ) + (i : Fin r) (f : (Fin r → ι) → ℝ) : + (∫ z, ∑ σ, replicaWeight (field A z) σ*(field B z (σ i)*f σ) ∂gaussianLaw κ) = + (∫ z, replicaMean (field A z) (fun σ => f σ*∑ l, crossCov B A (σ i) (σ l)) ∂gaussianLaw κ) - + (r:ℝ)*(∫ z, replicaMean (field A z) (fun τ : Fin (r+1) → ι => + f (fun l => τ l.castSucc)*crossCov B A (τ i.castSucc) (τ (Fin.last r))) ∂gaussianLaw κ) := by + have h := integral_replica_energy_covariance + (fun s k => A s ((Fintype.equivFin κ).symm k)) + (fun s k => B s ((Fintype.equivFin κ).symm k)) i f + simp only [crossCov_reindex] at h + rw [integral_reindex_pair A B + (fun x y => ∑ σ, replicaWeight x σ*(y (σ i)*f σ))] at h + rw [integral_reindex_pair A A (fun x _ => replicaMean x (fun σ => f σ*∑ l, crossCov B A (σ i) (σ l))), + integral_reindex_pair A A (fun x _ => replicaMean x (fun τ : Fin (r+1) → ι => + f (fun l => τ l.castSucc)*crossCov B A (τ i.castSucc) (τ (Fin.last r))))] at h + exact h + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation GaussianConcentration + + + +def pSpinCoeff (n p : ℕ) (σ : Configuration n) (a : Fin p → Fin n) : ℝ := + ∏ l, (Real.sqrt (n:ℝ))⁻¹*spin σ (a l) + +lemma pSpinCoeff_abs (n p : ℕ) (σ : Configuration n) (a : Fin p → Fin n) : + |pSpinCoeff n p σ a|=((Real.sqrt (n:ℝ))⁻¹)^p := by + simp [pSpinCoeff, Finset.abs_prod, abs_mul, spin_abs, abs_inv, + abs_of_nonneg (Real.sqrt_nonneg _)] + + +lemma pSpinCoeff_kernel {n : ℕ} (_hn : 0 < n) (p : ℕ) (σ τ : Configuration n) : + kernel (pSpinCoeff n p) σ τ=(overlap σ τ)^p := by + have he (a : Fin p → Fin n) : pSpinCoeff n p σ a*pSpinCoeff n p τ a= + ∏ l, ((Real.sqrt (n:ℝ))⁻¹*spin σ (a l))*((Real.sqrt (n:ℝ))⁻¹*spin τ (a l)) := by + simp only [pSpinCoeff, Finset.prod_mul_distrib] + unfold kernel + simp_rw [he] + rw [← Fintype.prod_sum (fun (_ : Fin p) (i : Fin n) => + ((Real.sqrt (n:ℝ))⁻¹*spin σ i)*((Real.sqrt (n:ℝ))⁻¹*spin τ i))] + have he' : (∑ i : Fin n, ((Real.sqrt (n:ℝ))⁻¹*spin σ i)* + ((Real.sqrt (n:ℝ))⁻¹*spin τ i))=overlap σ τ := by + calc + _ = ((Real.sqrt (n:ℝ))⁻¹)^2*overlapSum σ τ := by + simp only [overlapSum, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + _ = _ := by rw [inv_pow, Real.sq_sqrt (Nat.cast_nonneg n)]; simp [overlap, div_eq_mul_inv, mul_comm] + simp_rw [he'] + simp + +lemma pSpinCoeff_diag {n : ℕ} (hn : 0 < n) (p : ℕ) (σ : Configuration n) : + kernel (pSpinCoeff n p) σ σ=1 := by rw [pSpinCoeff_kernel hn, overlap_self hn, one_pow] + + + +def perturbedCoeff (n p : ℕ) (β a : ℝ) (σ : Configuration n) : + Edge n ⊕ (Fin p → Fin n) → ℝ := + Sum.elim (fun e => β*skCoeff n σ e) (fun u => a*pSpinCoeff n p σ u) + +lemma perturbedCoeff_kernel {n : ℕ} (hn : 0 < n) (p : ℕ) (β a : ℝ) + (σ τ : Configuration n) : + kernel (perturbedCoeff n p β a) σ τ = + β^2*((overlapSum σ τ)^2-(n:ℝ))/(2*n)+a^2*(overlap σ τ)^p := by + unfold kernel perturbedCoeff + simp only [Fintype.sum_sum_type, Sum.elim_inl, Sum.elim_inr] + change kernel (fun s e => β*skCoeff n s e) σ τ+ + kernel (fun s u => a*pSpinCoeff n p s u) σ τ=_ + rw [kernel_scale, kernel_scale, kernel, coeff_covariance hn, pSpinCoeff_kernel hn] + ring + + + +lemma variance_logPartition_le_diagonal {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + (A : ι → κ → ℝ) (s : ι) (hA : ∀ t k, |A t k|=|A s k|) : + variance (fun z => logPartition (field A z)) (gaussianLaw κ) ≤ kernel A s s := by + have h := variance_field_logPartition_le A (fun k => ‖A s k‖₊) (fun t k => by + simpa only [coe_nnnorm, Real.norm_eq_abs] using (hA t k).le) + apply h.trans_eq + simp only [coe_nnnorm, Real.norm_eq_abs, sq_abs] + simp only [kernel, sq] + +lemma perturbedCoeff_abs (n p : ℕ) (β a : ℝ) (σ τ : Configuration n) + (k : Edge n ⊕ (Fin p → Fin n)) : + |perturbedCoeff n p β a σ k|=|perturbedCoeff n p β a τ k| := by + cases k with + | inl e => simp [perturbedCoeff, skCoeff, abs_mul, spin_abs] + | inr u => simp [perturbedCoeff, abs_mul, pSpinCoeff_abs] + + + +lemma perturbed_logPartition_variance_le {n : ℕ} (hn : 0 < n) (p : ℕ) (β a : ℝ) : + variance (fun z => logPartition (field (perturbedCoeff n p β a) z)) + (gaussianLaw (Edge n ⊕ (Fin p → Fin n))) ≤ β^2*((n:ℝ)-1)/2+a^2 := by + let σ : Configuration n := fun _ => false + apply (variance_logPartition_le_diagonal (perturbedCoeff n p β a) σ + (fun τ k => perturbedCoeff_abs n p β a τ σ k)).trans_eq + rw [perturbedCoeff_kernel hn, overlap_self hn, one_pow, mul_one] + have hs : overlapSum σ σ=(n:ℝ) := by + simp [overlapSum, ← sq, spin_sq] + rw [hs] + have hn' : (n:ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hn.ne' + field_simp [hn'] + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace ParisiInterpolation +open SKGaussian +variable {ι κ : Type*} [Fintype ι] [Nonempty ι] [Fintype κ] + +lemma replicaAverage_abs_le (A : ι → κ → ℝ) {K : ι → ι → ℝ} {M : ℝ} + (hK : ∀ s t, |K s t| ≤ M) (z : κ → ℝ) : |replicaAverage A K z| ≤ M := by + calc + _ ≤ ∑ i, ∑ j, |weight (field A z) i*weight (field A z) j*K i j| := by + exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun i _ => Finset.abs_sum_le_sum_abs _ _)) + _ ≤ ∑ i, ∑ j, weight (field A z) i*weight (field A z) j*M := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + rw [abs_mul, abs_of_nonneg (mul_nonneg (weight_pos _ _).le (weight_pos _ _).le)] + exact mul_le_mul_of_nonneg_left (hK i j) (mul_nonneg (weight_pos _ _).le (weight_pos _ _).le) + _ = M := replicaAverage_const A z M + +lemma replicaMean_abs_le (A : ι → κ → ℝ) {K : ι → ι → ℝ} {M : ℝ} + (hK : ∀ s t, |K s t| ≤ M) : |replicaMean A K| ≤ M := by + apply abs_integral_le_integral_abs.trans + have h := integral_mono (integrable_replicaAverage A K).abs (integrable_const M) + (replicaAverage_abs_le A hK) + simpa using h + + + +lemma expected_difference_le_orthogonal (A B : ι → κ → ℝ) + (hAB : ∀ i j, ∑ k, A i k*B j k=0) {M : ℝ} (hM : 0 ≤ M) + (hinc : ∀ s t, |increment B s t-increment A s t| ≤ M) : + |expected B-expected A| ≤ M*Real.pi/4 := by + let L : ℝ≥0 := ⟨M/2, by positivity⟩ + have hLip : LipschitzWith L (fun t => expected (rotate A B t)) := by + apply lipschitzWith_of_nnnorm_deriv_le (fun t => (hasDerivAt_expected_rotate_mean A B hAB t).differentiableAt) + intro t + rw [(hasDerivAt_expected_rotate_mean A B hAB t).deriv] + have hr := replicaMean_abs_le (rotate A B t) hinc + have htrig : |Real.sin t*Real.cos t| ≤ 1 := by + rw [abs_mul] + calc + |Real.sin t| * |Real.cos t| ≤ 1 * |Real.cos t| := + mul_le_mul_of_nonneg_right (Real.abs_sin_le_one t) (abs_nonneg _) + _ ≤ 1 := by simpa using Real.abs_cos_le_one t + have hnorm : ‖Real.sin t*Real.cos t/2* + replicaMean (rotate A B t) (fun i j => increment B i j-increment A i j)‖ ≤ M/2 := by + rw [Real.norm_eq_abs, abs_mul, abs_div, abs_of_pos (by norm_num : (0:ℝ)<2)] + have h1 := mul_le_mul (div_le_div_of_nonneg_right htrig (by norm_num)) hr + (abs_nonneg _) (by positivity : 0 ≤ (1:ℝ)/2) + nlinarith only [h1] + exact_mod_cast hnorm + have he0 : rotate A B 0=A := by ext i k; simp [rotate] + have he1 : rotate A B (Real.pi/2)=B := by ext i k; simp [rotate] + have h := hLip.norm_sub_le (Real.pi/2) 0 + rw [he0, he1] at h + change |expected B-expected A| ≤ (M/2)*|Real.pi/2-0| at h + simpa only [sub_zero, abs_of_nonneg (by positivity : 0 ≤ Real.pi/2), div_mul_div_comm, show (2:ℝ)*2=4 by norm_num] using h + +lemma expected_difference_le {κ' : Type*} [Fintype κ'] (A : ι → κ → ℝ) (B : ι → κ' → ℝ) + {M : ℝ} (hM : 0 ≤ M) (hinc : ∀ s t, |increment B s t-increment A s t| ≤ M) : + |expected B-expected A| ≤ M*Real.pi/4 := by + let A' : ι → κ ⊕ κ' → ℝ := fun s => Sum.elim (A s) (fun _ => 0) + let B' : ι → κ ⊕ κ' → ℝ := fun s => Sum.elim (fun _ => 0) (B s) + have ha (s t : ι) : increment A' s t=increment A s t := by + simp [increment, A', Fintype.sum_sum_type] + have hb (s t : ι) : increment B' s t=increment B s t := by + simp [increment, B', Fintype.sum_sum_type] + have h := expected_difference_le_orthogonal A' B' + (fun s t => by simp [A', B', Fintype.sum_sum_type]) hM (fun s t => by simpa only [ha,hb] using hinc s t) + have hea : expected A'=expected A := integral_field_inl A logPartition + have heb : expected B'=expected B := integral_field_inr B logPartition + rwa [hea,heb] at h + +end ParisiInterpolation + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/WComm.lean b/lean/OAI/Probability/ParisiFinite/WComm.lean new file mode 100644 index 0000000000000000000000000000000000000000..66f3a72c4ab3cb7aef4e8b3473a1565d3d41bebf --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/WComm.lean @@ -0,0 +1,634 @@ +import Mathlib +import OAI.Probability.ParisiFinite.ExpVector + +namespace OAI + +/-! W Comm. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +namespace CoherentFock +open Complex +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +theorem W_comm (v d : E) : + (W v).comp (W d) = Complex.exp (((-2*(⟪v,d⟫_ℂ).im:ℝ):ℂ)*I) • + (W d).comp (W v) := by + rw [W_mul,W_mul,add_comm d v,smul_smul] + congr 1 + have hi := inner_im_symm (𝕜 := ℂ) d v + change (⟪d,v⟫_ℂ).im = -(⟪v,d⟫_ℂ).im at hi + simp only [phase,← Complex.exp_add,hi,neg_neg] + congr 1 + push_cast + ring + + +theorem W_centered_difference_le (v d : E) (x : Space E) : + ‖W v (W d x)-W d x‖ ≤ ‖W v x-x‖+2*‖v‖*‖d‖*‖x‖ := by + let c := Complex.exp (((-2*(⟪v,d⟫_ℂ).im:ℝ):ℂ)*I) + have hc : ‖c‖=1 := Complex.norm_exp_ofReal_mul_I _ + have hs : ‖c-1‖ ≤ 2*‖v‖*‖d‖ := by + have hh := Real.norm_exp_I_mul_ofReal_sub_one_le (x := -2*(⟪v,d⟫_ℂ).im) + have hb := (Complex.abs_im_le_norm ⟪v,d⟫_ℂ).trans (norm_inner_le_norm v d) + have he : |(-2:ℝ)*(⟪v,d⟫_ℂ).im|=2*|(⟪v,d⟫_ℂ).im| := by simp + change ‖c-1‖ ≤ _ + have hh' : ‖c-1‖ ≤ 2*|(⟪v,d⟫_ℂ).im| := by + simpa only [c,mul_comm I,Real.norm_eq_abs,he] using hh + nlinarith + have he : W v (W d x)-W d x = c • W d (W v x-x)+(c-1) • W d x := by + have hw := congrArg (fun A : Space E →L[ℂ] Space E => A x) (W_comm v d) + simp only [ContinuousLinearMap.comp_apply,smul_apply] at hw + rw [hw,map_sub] + change c • W d (W v x)-W d x = _ + module + rw [he] + calc + _ ≤ ‖c • W d (W v x-x)‖+‖(c-1) • W d x‖ := norm_add_le _ _ + _ = ‖W v x-x‖+‖c-1‖*‖x‖ := by simp only [norm_smul,hc,one_mul,norm_W] + _ ≤ _ := by gcongr + + +theorem W_fieldCoherent_sub_le (h v d : E) : + ‖W h (fieldCoherent v d)-fieldCoherent v d‖ ≤ + 2*‖h‖*‖v‖*(1+2*‖d‖+2*‖d‖^2) := by + have h1 : ‖W h (W d (oneParticle v))-W d (oneParticle v)‖ ≤ + 2*‖h‖*‖v‖+2*‖h‖*‖d‖*‖v‖ := by + exact (W_centered_difference_le h d (oneParticle v)).trans (by + rw [norm_oneParticle] + exact add_le_add_left (W_oneParticle_sub_le h v) _) + have h2 := W_coherent_sub_le h d + have hb : ‖((2*(⟪v,d⟫_ℂ).im:ℝ):ℂ)‖ ≤ 2*‖v‖*‖d‖ := by + simp only [Complex.norm_real,Real.norm_eq_abs,abs_mul] + have hh := (Complex.abs_im_le_norm ⟪v,d⟫_ℂ).trans (norm_inner_le_norm v d) + norm_num only [abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + nlinarith + have he : W h (fieldCoherent v d)-fieldCoherent v d = + (-I) • (W h (W d (oneParticle v))-W d (oneParticle v))- + ((2*(⟪v,d⟫_ℂ).im:ℝ):ℂ) • (W h (coherent d)-coherent d) := by + simp only [fieldCoherent,map_sub,map_smul] + module + rw [he] + calc + _ ≤ ‖(-I) • (W h (W d (oneParticle v))-W d (oneParticle v))‖+ + ‖((2*(⟪v,d⟫_ℂ).im:ℝ):ℂ) • (W h (coherent d)-coherent d)‖ := norm_sub_le _ _ + _ = ‖W h (W d (oneParticle v))-W d (oneParticle v)‖+ + ‖((2*(⟪v,d⟫_ℂ).im:ℝ):ℂ)‖*‖W h (coherent d)-coherent d‖ := by + simp only [norm_smul,norm_neg,Complex.norm_I,one_mul] + _ ≤ (2*‖h‖*‖v‖+2*‖h‖*‖d‖*‖v‖)+(2*‖v‖*‖d‖)*(‖h‖*(1+2*‖d‖)) := by + gcongr + _ = _ := by ring + +theorem W_preField_sub_le (h v : E) (x : PreSpace E) : + ‖W h (preField v x)-preField v x‖ ≤ 2*‖h‖*‖v‖*secondTailBound x := by + classical + simp only [preField_eq_sum,Finsupp.sum,map_sum,map_smul,← Finset.sum_sub_distrib,← smul_sub] + calc + _ ≤ ∑ e ∈ (toFinsupp x).support, + ‖(toFinsupp x) e • (W h (fieldCoherent v e)-fieldCoherent v e)‖ := norm_sum_le _ _ + _ ≤ ∑ e ∈ (toFinsupp x).support, + ‖(toFinsupp x) e‖*(2*‖h‖*‖v‖*(1+2*‖e‖+12*‖e‖^2)) := by + apply Finset.sum_le_sum + intro e he + rw [norm_smul] + apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) + exact (W_fieldCoherent_sub_le h v e).trans (by gcongr; norm_num) + _ = _ := by + simp only [secondTailBound,Finsupp.sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro d hd + ring + +end CoherentFock + +namespace CoherentFock +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +abbrev SpinSpace (E : Type*) [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] := + PiLp 2 (fun _ : Fin 2 => Space E) + + +def WZ (d : E) : SpinSpace E →L[ℂ] SpinSpace E := + (PiLp.continuousLinearEquiv 2 ℂ (fun _ : Fin 2 => Space E)).symm.toContinuousLinearMap.comp + (ContinuousLinearMap.pi fun i => + (W (if i = 0 then d else -d)).comp (PiLp.proj 2 (fun _ : Fin 2 => Space E) i)) + +@[simp] theorem WZ_apply (d : E) (x : SpinSpace E) (i : Fin 2) : + WZ d x i = W (if i = 0 then d else -d) (x i) := by rfl + +@[simp] theorem norm_WZ (d : E) (x : SpinSpace E) : ‖WZ d x‖ = ‖x‖ := by + have h : ‖WZ d x‖^2 = ‖x‖^2 := by + rw [PiLp.norm_sq_eq_of_L2,PiLp.norm_sq_eq_of_L2] + simp + nlinarith [norm_nonneg (WZ d x),norm_nonneg x] + +@[simp] theorem phase_neg_neg (d e : E) : phase (-d) (-e) = phase d e := by + simp [phase] + +@[simp] theorem WZ_zero : WZ (0 : E) = ContinuousLinearMap.id ℂ (SpinSpace E) := by + ext x i + simp [WZ_apply] + +theorem WZ_mul (d e : E) : (WZ d).comp (WZ e) = phase d e • WZ (d+e) := by + ext x i + simp only [ContinuousLinearMap.comp_apply,smul_apply, + PiLp.smul_apply,WZ_apply] + split_ifs with hi + · exact congrArg (fun T : Space E →L[ℂ] Space E => T (x i)) (W_mul d e) + · simpa only [neg_add,phase_neg_neg,ContinuousLinearMap.comp_apply,smul_apply] using + congrArg (fun T : Space E →L[ℂ] Space E => T (x i)) (W_mul (-d) (-e)) + + + +theorem exact_echo (t r : ℝ) (v v' : E) : + (WZ ((t/r) • v')).comp (WZ (-(t/r) • v)) = + phase ((t/r) • v') (-(t/r) • v) • WZ ((t/r) • (v'-v)) := by + rw [WZ_mul] + have heq : (t/r) • v' + (-(t/r)) • v = (t/r) • (v'-v) := by + rw [smul_sub,neg_smul,sub_eq_add_neg] + rw [heq] + + +theorem exact_echo_unimodular (t r : ℝ) (v v' : E) : + ∃ ξ : ℂ, ‖ξ‖ = 1 ∧ + (WZ ((t/r) • v')).comp (WZ (-(t/r) • v)) = ξ • WZ ((t/r) • (v'-v)) := + ⟨_,norm_phase _ _,exact_echo t r v v'⟩ + +theorem continuous_WZ (x : SpinSpace E) : Continuous (fun d : E => WZ d x) := by + rw [← (PiLp.continuousLinearEquiv 2 ℂ (fun _ : Fin 2 => Space E)).toHomeomorph.comp_continuous_iff] + apply continuous_pi + intro i + change Continuous (fun d : E => W (if i = 0 then d else -d) (x i)) + split_ifs with hi + · exact continuous_W (x i) + · exact (continuous_W (x i)).comp continuous_neg + +theorem tendsto_WZ {α : Type*} {l : Filter α} {ds : α → E} {xs : α → SpinSpace E} + {d : E} {x : SpinSpace E} (hd : Tendsto ds l (𝓝 d)) (hx : Tendsto xs l (𝓝 x)) : + Tendsto (fun a => WZ (ds a) (xs a)) l (𝓝 (WZ d x)) := by + rw [Metric.tendsto_nhds] + intro ε hε + have he1 := Metric.tendsto_nhds.mp hx (ε/2) (by positivity) + have he2 := Metric.tendsto_nhds.mp (((continuous_WZ x).tendsto d).comp hd) + (ε/2) (by positivity) + filter_upwards [he1,he2] with a ha hb + have heq : dist (WZ (ds a) (xs a)) (WZ (ds a) x) = dist (xs a) x := by + simp only [dist_eq_norm,← map_sub,norm_WZ] + have ht := dist_triangle (WZ (ds a) (xs a)) (WZ (ds a) x) (WZ d x) + rw [heq] at ht + dsimp only [Function.comp_def] at hb + linarith + + +@[simp] theorem WZ_error (d : E) (x y : SpinSpace E) : + ‖WZ d x-WZ d y‖=‖x-y‖ := by rw [← map_sub,norm_WZ] + + + +theorem corrected_echo (t r : ℝ) (v v' : E) (x : SpinSpace E) : + (phase ((t/r) • v') (-(t/r) • v))⁻¹ • + WZ ((t/r) • v') (WZ (-(t/r) • v) x) = WZ ((t/r) • (v'-v)) x := by + have hp : phase ((t/r) • v') (-(t/r) • v) ≠ 0 := by + intro hz + have h := norm_phase ((t/r) • v') (-(t/r) • v) + rw [hz,norm_zero] at h + norm_num at h + have h := congrArg (fun T : SpinSpace E →L[ℂ] SpinSpace E => T x) (exact_echo t r v v') + simp only [ContinuousLinearMap.comp_apply,smul_apply] at h + rw [h,smul_smul,inv_mul_cancel₀ hp,one_smul] + + + +theorem tendsto_corrected_echo {α : Type*} {l : Filter α} + (t : ℝ) (r : α → ℝ) (v v' : α → E) (xs : α → SpinSpace E) + (w : E) (x : SpinSpace E) + (hd : Tendsto (fun a => (r a)⁻¹ • (v' a-v a)) l (𝓝 ((-2:ℝ) • w))) + (hx : Tendsto xs l (𝓝 x)) : + Tendsto (fun a => (phase ((t/r a) • v' a) (-(t/r a) • v a))⁻¹ • + WZ ((t/r a) • v' a) (WZ (-(t/r a) • v a) (xs a))) + l (𝓝 (WZ ((-2*t) • w) x)) := by + simp_rw [corrected_echo] + have hd' : Tendsto (fun a => (t/r a) • (v' a-v a)) l (𝓝 ((-2*t) • w)) := by + convert! (tendsto_const_nhds (x := t)).smul hd using 1 + · ext a + rw [smul_smul,div_eq_mul_inv] + · simp only [smul_smul,mul_comm t (-2)] + exact tendsto_WZ hd' hx + +end CoherentFock + +namespace SpinOperators +open scoped Matrix.Norms.L2Operator +local instance : NormedAlgebra ℚ (Matrix (Fin 2) (Fin 2) ℂ) := + NormedAlgebra.restrictScalars ℚ ℝ _ +variable {H : Type*} [NormedAddCommGroup H] [InnerProductSpace ℂ H] +abbrev Double (H : Type*) [NormedAddCommGroup H] [InnerProductSpace ℂ H] := + PiLp 2 (fun _ : Fin 2 => H) + +def act (A : Matrix (Fin 2) (Fin 2) ℂ) : Double H →L[ℂ] Double H := + (PiLp.continuousLinearEquiv 2 ℂ (fun _ : Fin 2 => H)).symm.toContinuousLinearMap.comp + (ContinuousLinearMap.pi fun i => ∑ j : Fin 2, A i j • PiLp.proj 2 (fun _ : Fin 2 => H) j) + +@[simp] theorem act_apply (A : Matrix (Fin 2) (Fin 2) ℂ) (x : Double H) (i : Fin 2) : + act A x i = ∑ j : Fin 2, A i j • x j := by + simp [act,PiLp.proj_apply] + +@[simp] theorem act_one : act (1 : Matrix (Fin 2) (Fin 2) ℂ) = ContinuousLinearMap.id ℂ (Double H) := by + ext x i + simp [act_apply,Matrix.one_apply] + + theorem act_mul (A B : Matrix (Fin 2) (Fin 2) ℂ) : + act (A*B) = (act A : Double H →L[ℂ] Double H).comp (act B) := by + ext x i + simp only [act_apply,ContinuousLinearMap.comp_apply,Matrix.mul_apply, + Finset.sum_smul,Finset.smul_sum,smul_smul] + rw [Finset.sum_comm] + + theorem act_add (A B : Matrix (Fin 2) (Fin 2) ℂ) : + act (A+B) = (act A : Double H →L[ℂ] Double H)+act B := by + ext x i + simp [act_apply,add_smul,Finset.sum_add_distrib] + + theorem act_scalar (z : ℂ) : + act (algebraMap ℂ (Matrix (Fin 2) (Fin 2) ℂ) z) = + algebraMap ℂ (Double H →L[ℂ] Double H) z := by + ext x i + simp [act_apply,Matrix.algebraMap_eq_diagonal,Matrix.diagonal_apply,Pi.algebraMap_apply] + +def rep : Matrix (Fin 2) (Fin 2) ℂ →ₐ[ℂ] (Double H →L[ℂ] Double H) where + toFun := act + map_zero' := by ext x i; simp [act_apply] + map_one' := act_one + map_add' := act_add + map_mul' := act_mul + commutes' := act_scalar + +@[simp] theorem rep_apply (A : Matrix (Fin 2) (Fin 2) ℂ) : + rep (H := H) A = act A := rfl + +variable [CompleteSpace H] + +theorem act_adjoint (A : Matrix (Fin 2) (Fin 2) ℂ) : + (act A : Double H →L[ℂ] Double H).adjoint = act A.conjTranspose := by + symm + apply (ContinuousLinearMap.eq_adjoint_iff _ _).mpr + intro x y + simp only [PiLp.inner_apply,act_apply,sum_inner,inner_sum,inner_smul_left, + inner_smul_right,Matrix.conjTranspose_apply,Complex.star_def,Complex.conj_conj] + rw [Finset.sum_comm] + +def starRep : Matrix (Fin 2) (Fin 2) ℂ →⋆ₐ[ℂ] (Double H →L[ℂ] Double H) where + toAlgHom := rep + map_star' A := by + change act A.conjTranspose = star (act A : Double H →L[ℂ] Double H) + rw [ContinuousLinearMap.star_eq_adjoint,act_adjoint] + +omit [CompleteSpace H] in + theorem continuous_rep : Continuous (rep (H := H)) := + (rep (H := H)).toLinearMap.continuous_of_finiteDimensional + +local instance : NormedAlgebra ℚ (Double H →L[ℂ] Double H) := + NormedAlgebra.restrictScalars ℚ ℂ _ + + theorem act_exp (A : Matrix (Fin 2) (Fin 2) ℂ) : + act (NormedSpace.exp A) = NormedSpace.exp (act A : Double H →L[ℂ] Double H) := + NormedSpace.map_exp (rep (H := H)) continuous_rep A + + theorem act_mem_unitary {A : Matrix (Fin 2) (Fin 2) ℂ} (hA : A ∈ unitary _) : + (act A : Double H →L[ℂ] Double H) ∈ unitary _ := by + exact Unitary.map_mem (starRep (H := H)) hA + + theorem norm_act {A : Matrix (Fin 2) (Fin 2) ℂ} (hA : A ∈ unitary _) (x : Double H) : + ‖act A x‖=‖x‖ := ContinuousLinearMap.norm_map_of_mem_unitary (act_mem_unitary hA) x + +end SpinOperators + +open scoped BigOperators +namespace WeightedMass +variable {ι : Type*} +def mass (w : ι → ℝ) (x : ι →₀ ℂ) := x.sum (fun i a => ‖a‖*w i) + +theorem nonneg (w : ι → ℝ) (hw : ∀ i, 0 ≤ w i) (x : ι →₀ ℂ) : 0 ≤ mass w x := by + exact Finset.sum_nonneg (fun i _ => mul_nonneg (norm_nonneg _) (hw i)) + +theorem add_le (w : ι → ℝ) (hw : ∀ i, 0 ≤ w i) (x y : ι →₀ ℂ) : + mass w (x+y) ≤ mass w x+mass w y := by + classical + let s := x.support ∪ y.support + have hx : x.support ⊆ s := Finset.subset_union_left + have hy : y.support ⊆ s := Finset.subset_union_right + have hxy : (x+y).support ⊆ s := Finsupp.support_add + unfold mass + rw [Finsupp.sum_of_support_subset (x+y) hxy _ (fun i hi => by simp), + Finsupp.sum_of_support_subset x hx _ (fun i hi => by simp), + Finsupp.sum_of_support_subset y hy _ (fun i hi => by simp),← Finset.sum_add_distrib] + apply Finset.sum_le_sum + intro i hi + simp only [Finsupp.add_apply] + nlinarith [mul_le_mul_of_nonneg_right (norm_add_le (x i) (y i)) (hw i)] + +@[simp] theorem zero (w : ι → ℝ) : mass w 0=0 := by simp [mass] + +theorem smul (w : ι → ℝ) (c : ℂ) (x : ι →₀ ℂ) : + mass w (c • x) = ‖c‖*mass w x := by + classical + by_cases hc : c=0 + · simp [hc] + unfold mass + simp only [Finsupp.sum,Finset.mul_sum] + rw [Finsupp.support_smul_eq hc] + apply Finset.sum_congr rfl + intro i hi + simp only [Finsupp.smul_apply,norm_smul] + ring + +theorem sum_le {κ : Type*} (w : ι → ℝ) (hw : ∀ i, 0 ≤ w i) + (s : Finset κ) (x : κ → ι →₀ ℂ) : mass w (∑ j ∈ s, x j) ≤ ∑ j ∈ s, mass w (x j) := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert a s ha ih => + simp only [Finset.sum_insert ha] + exact (add_le w hw _ _).trans (add_le_add_right ih _) + +end WeightedMass + +namespace CoherentFock +open Complex +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +omit [InnerProductSpace ℂ E] in +theorem secondTailBound_nonneg (x : PreSpace E) : 0 ≤ secondTailBound x := + WeightedMass.nonneg _ (fun d => by positivity) (toFinsupp x) + +omit [InnerProductSpace ℂ E] in +theorem secondTailBound_smul (c : ℂ) (x : PreSpace E) : + secondTailBound (c • x)=‖c‖*secondTailBound x := by + exact WeightedMass.smul _ c (toFinsupp x) + +omit [InnerProductSpace ℂ E] in +theorem secondTailBound_add (x y : PreSpace E) : + secondTailBound (x+y) ≤ secondTailBound x+secondTailBound y := + WeightedMass.add_le _ (fun d => by positivity) (toFinsupp x) (toFinsupp y) + +omit [InnerProductSpace ℂ E] in +theorem secondTailBound_sum {κ : Type*} (s : Finset κ) (x : κ → PreSpace E) : + secondTailBound (∑ j ∈ s, x j) ≤ ∑ j ∈ s, secondTailBound (x j) := by + simpa only [secondTailBound,WeightedMass.mass,map_sum] using + WeightedMass.sum_le _ (fun d : E => by positivity) s (fun j => toFinsupp (x j)) + +theorem norm_preField_le (v : E) (x : PreSpace E) : + ‖preField v x‖ ≤ ‖v‖*secondTailBound x := by + classical + simp only [preField_eq_sum,Finsupp.sum] + calc + _ ≤ ∑ e ∈ (toFinsupp x).support, ‖(toFinsupp x) e‖*‖fieldCoherent v e‖ := by + simpa only [norm_smul] using norm_sum_le (toFinsupp x).support + (fun e => (toFinsupp x) e • fieldCoherent v e) + _ ≤ ∑ e ∈ (toFinsupp x).support, ‖(toFinsupp x) e‖*(‖v‖*(1+2*‖e‖+12*‖e‖^2)) := by + apply Finset.sum_le_sum + intro e he + apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) + exact (norm_fieldCoherent_le v e).trans (mul_le_mul_of_nonneg_left + (by nlinarith [sq_nonneg ‖e‖]) (norm_nonneg v)) + _ = _ := by + simp only [secondTailBound,Finsupp.sum,Finset.mul_sum] + apply Finset.sum_congr rfl + intro e he + ring + +theorem preField_add (v w : E) (x : PreSpace E) : + preField (v+w) x=preField v x+preField w x := by + classical + simp only [preField_eq_sum,Finsupp.sum,fieldCoherent_add,smul_add,Finset.sum_add_distrib] + +theorem preField_neg (v : E) (x : PreSpace E) : preField (-v) x= -preField v x := by + simpa only [neg_one_smul] using preField_real_smul (-1) v x + +theorem preField_sub (v w : E) (x : PreSpace E) : + preField (v-w) x=preField v x-preField w x := by + simp only [sub_eq_add_neg,preField_add,preField_neg] + +abbrev PreSpin (E : Type*) := Fin 2 → PreSpace E + +def spinCoe (x : PreSpin E) : SpinSpace E := WithLp.toLp 2 (fun i => (x i : Space E)) +@[simp] theorem spinCoe_apply (x : PreSpin E) (i : Fin 2) : spinCoe x i=(↑(x i) : Space E) := rfl + +def preRoot (A : Matrix (Fin 2) (Fin 2) ℂ) (x : PreSpin E) : PreSpin E := + fun i => ∑ j, A i j • x j + +def spinBound (x : PreSpin E) : ℝ := ∑ i, secondTailBound (x i) + +def matrixMass (A : Matrix (Fin 2) (Fin 2) ℂ) : ℝ := ∑ i, ∑ j, ‖A i j‖ + +omit [InnerProductSpace ℂ E] in +theorem spinBound_nonneg (x : PreSpin E) : 0 ≤ spinBound x := + Finset.sum_nonneg (fun i _ => secondTailBound_nonneg (x i)) + +omit [InnerProductSpace ℂ E] in +theorem secondTailBound_le_spinBound (x : PreSpin E) (i : Fin 2) : + secondTailBound (x i) ≤ spinBound x := + Finset.single_le_sum (fun j _ => secondTailBound_nonneg (x j)) (Finset.mem_univ i) + +omit [InnerProductSpace ℂ E] in +theorem spinBound_preRoot (A : Matrix (Fin 2) (Fin 2) ℂ) (x : PreSpin E) : + spinBound (preRoot A x) ≤ matrixMass A * spinBound x := by + classical + unfold spinBound preRoot + calc + _ ≤ ∑ i : Fin 2, ∑ j : Fin 2, ‖A i j‖*secondTailBound (x j) := by + apply Finset.sum_le_sum + intro i hi + simpa only [secondTailBound_smul] using secondTailBound_sum Finset.univ (fun j => A i j • x j) + _ ≤ ∑ i : Fin 2, ∑ j : Fin 2, ‖A i j‖*spinBound x := by + apply Finset.sum_le_sum + intro i hi + apply Finset.sum_le_sum + intro j hj + exact mul_le_mul_of_nonneg_left (secondTailBound_le_spinBound x j) (norm_nonneg _) + _ = _ := by simp only [matrixMass,Finset.sum_mul,spinBound] + +@[simp] theorem spinCoe_preRoot (A : Matrix (Fin 2) (Fin 2) ℂ) (x : PreSpin E) : + spinCoe (preRoot A x)=SpinOperators.act A (spinCoe x) := by + ext i + simp only [spinCoe_apply,preRoot,SpinOperators.act_apply,Fin.sum_univ_two,UniformSpace.Completion.coe_add, + UniformSpace.Completion.coe_smul] + +theorem norm_spin_le_sum (x : SpinSpace E) : ‖x‖ ≤ ∑ i, ‖x i‖ := by + have he : ‖x‖^2 = ‖x 0‖^2+‖x 1‖^2 := by + rw [PiLp.norm_sq_eq_of_L2,Fin.sum_univ_two] + rw [Fin.sum_univ_two] + nlinarith [norm_nonneg x,norm_nonneg (x 0),norm_nonneg (x 1), + mul_nonneg (norm_nonneg (x 0)) (norm_nonneg (x 1))] + +def spinField (v : E) (x : PreSpin E) : SpinSpace E := + WithLp.toLp 2 (fun i => preField v (x i)) +@[simp] theorem spinField_apply (v : E) (x : PreSpin E) (i : Fin 2) : + spinField v x i=preField v (x i) := rfl + +@[simp] theorem spinField_preRoot (A : Matrix (Fin 2) (Fin 2) ℂ) (v : E) (x : PreSpin E) : + spinField v (preRoot A x)=SpinOperators.act A (spinField v x) := by + ext i + simp only [spinField_apply,preRoot,SpinOperators.act_apply,map_sum,map_smul] + +theorem WZ_spinField_sub_le (h v : E) (x : PreSpin E) : + ‖WZ h (spinField v x)-spinField v x‖ ≤ 2*‖h‖*‖v‖*spinBound x := by + calc + _ ≤ ∑ i, ‖(WZ h (spinField v x)-spinField v x) i‖ := norm_spin_le_sum _ + _ ≤ ∑ i, 2*‖h‖*‖v‖*secondTailBound (x i) := by + apply Finset.sum_le_sum + intro i hi + simp only [PiLp.sub_apply,WZ_apply,spinField_apply] + split_ifs + · exact W_preField_sub_le h v (x i) + · simpa only [norm_neg] using W_preField_sub_le (-h) v (x i) + _ = _ := by simp only [spinBound,Finset.mul_sum] + +end CoherentFock + +namespace CoherentFock +open Complex +variable {E : Type*} [SeminormedAddCommGroup E] [InnerProductSpace ℂ E] + +def preZ (x : PreSpin E) : PreSpin E := fun i => if i=0 then x i else -x i + +def zField (v : E) (x : PreSpin E) : SpinSpace E := spinField v (preZ x) + +@[simp] theorem zField_apply (v : E) (x : PreSpin E) (i : Fin 2) : + zField v x i=if i=0 then preField v (x i) else -preField v (x i) := by + simp only [zField,spinField_apply,preZ] + split_ifs <;> simp + +omit [InnerProductSpace ℂ E] in +theorem spinBound_preZ (x : PreSpin E) : spinBound (preZ x)=spinBound x := by + unfold spinBound + apply Finset.sum_congr rfl + intro i hi + simp only [preZ] + split_ifs + · rfl + · simpa only [neg_one_smul,norm_neg,norm_one,one_mul] using secondTailBound_smul (-1) (x i) + +theorem norm_spinField_le (v : E) (x : PreSpin E) : + ‖spinField v x‖ ≤ ‖v‖*spinBound x := by + calc + _ ≤ ∑ i, ‖spinField v x i‖ := norm_spin_le_sum _ + _ ≤ ∑ i, ‖v‖*secondTailBound (x i) := + Finset.sum_le_sum (fun i _ => norm_preField_le v (x i)) + _ = _ := by simp only [spinBound,Finset.mul_sum] + +theorem norm_zField_le (v : E) (x : PreSpin E) : + ‖zField v x‖ ≤ ‖v‖*spinBound x := by + simpa only [zField,spinBound_preZ] using norm_spinField_le v (preZ x) + +theorem zField_real_smul (r : ℝ) (v : E) (x : PreSpin E) : + zField (r • v) x=r • zField v x := by + ext i + simp only [zField,spinField_apply,PiLp.smul_apply,preField_real_smul] + +theorem zField_sub (v w : E) (x : PreSpin E) : + zField (v-w) x=zField v x-zField w x := by + ext i + simp only [zField,spinField_apply,PiLp.sub_apply,preField_sub] + +theorem WZ_taylor (v : E) (x : PreSpin E) : + ‖WZ v (spinCoe x)-spinCoe x-I • zField v x‖ ≤ ‖v‖^2*spinBound x := by + calc + _ ≤ ∑ i, ‖(WZ v (spinCoe x)-spinCoe x-I • zField v x) i‖ := norm_spin_le_sum _ + _ ≤ ∑ i, ‖v‖^2*secondTailBound (x i) := by + apply Finset.sum_le_sum + intro i hi + simp only [PiLp.sub_apply,PiLp.smul_apply,WZ_apply,spinCoe_apply,zField_apply] + split_ifs + · exact W_coe_taylor v (x i) + · simpa only [preField_neg,norm_neg] using W_coe_taylor (-v) (x i) + _ = _ := by simp only [spinBound,Finset.mul_sum] + +def probe (A : Matrix (Fin 2) (Fin 2) ℂ) (v : E) : SpinSpace E →L[ℂ] SpinSpace E := + (SpinOperators.act A.conjTranspose).comp ((WZ v).comp (SpinOperators.act A)) + +def probeField (A : Matrix (Fin 2) (Fin 2) ℂ) (v : E) (x : PreSpin E) : SpinSpace E := + SpinOperators.act A.conjTranspose (zField v (preRoot A x)) + +@[simp] theorem probe_apply (A : Matrix (Fin 2) (Fin 2) ℂ) (v : E) (x : SpinSpace E) : + probe A v x=SpinOperators.act A.conjTranspose (WZ v (SpinOperators.act A x)) := rfl + +theorem root_left_inverse (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (x : SpinSpace E) : SpinOperators.act A.conjTranspose (SpinOperators.act A x)=x := by + have hh : A.conjTranspose*A=1 := (Unitary.mem_iff.mp hA).1 + have h := congrArg (fun B : Matrix (Fin 2) (Fin 2) ℂ => SpinOperators.act (H := Space E) B x) hh + simpa only [SpinOperators.act_mul,ContinuousLinearMap.comp_apply,SpinOperators.act_one, + ContinuousLinearMap.id_apply] using h + +theorem root_adjoint_unitary (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) : + A.conjTranspose ∈ unitary _ := by + exact Unitary.star_mem hA + +@[simp] theorem norm_probe (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (v : E) (x : SpinSpace E) : ‖probe A v x‖=‖x‖ := by + rw [probe_apply,SpinOperators.norm_act (root_adjoint_unitary A hA),norm_WZ,SpinOperators.norm_act hA] + +theorem probe_taylor (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (v : E) (x : PreSpin E) : + ‖probe A v (spinCoe x)-spinCoe x-I • probeField A v x‖ ≤ + ‖v‖^2*matrixMass A*spinBound x := by + have he : probe A v (spinCoe x)-spinCoe x-I • probeField A v x = + SpinOperators.act A.conjTranspose + (WZ v (spinCoe (preRoot A x))-spinCoe (preRoot A x)-I • zField v (preRoot A x)) := by + simp only [map_sub,map_smul,spinCoe_preRoot,root_left_inverse A hA,probe_apply,probeField] + rw [he,SpinOperators.norm_act (root_adjoint_unitary A hA)] + exact (WZ_taylor v (preRoot A x)).trans (by + have hh := mul_le_mul_of_nonneg_left (spinBound_preRoot A x) (sq_nonneg ‖v‖) + simpa only [mul_assoc] using hh) + +theorem probeField_eq_spinField (A : Matrix (Fin 2) (Fin 2) ℂ) (v : E) (x : PreSpin E) : + probeField A v x=spinField v (preRoot A.conjTranspose (preZ (preRoot A x))) := by + simp only [probeField,zField,spinField_preRoot] + +theorem probeField_real_smul (A : Matrix (Fin 2) (Fin 2) ℂ) (r : ℝ) (v : E) (x : PreSpin E) : + probeField A (r • v) x=r • probeField A v x := by + simp only [probeField,zField_real_smul,ContinuousLinearMap.map_smul_of_tower] + +theorem probeField_sub (A : Matrix (Fin 2) (Fin 2) ℂ) (v w : E) (x : PreSpin E) : + probeField A (v-w) x=probeField A v x-probeField A w x := by + simp only [probeField,zField_sub,map_sub] + +theorem norm_probeField_le (A : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (v : E) (x : PreSpin E) : ‖probeField A v x‖ ≤ ‖v‖*matrixMass A*spinBound x := by + rw [probeField,SpinOperators.norm_act (root_adjoint_unitary A hA)] + exact (norm_zField_le v (preRoot A x)).trans (by + have hh := mul_le_mul_of_nonneg_left (spinBound_preRoot A x) (norm_nonneg v) + simpa only [mul_assoc] using hh) + +theorem probe_cross (A B : Matrix (Fin 2) (Fin 2) ℂ) (hA : A ∈ unitary _) + (h v : E) (x : PreSpin E) : + ‖probe A h (probeField B v x)-probeField B v x‖ ≤ + 2*‖h‖*‖v‖*matrixMass A*matrixMass B.conjTranspose*matrixMass B*spinBound x := by + have he : probe A h (probeField B v x)-probeField B v x = + SpinOperators.act A.conjTranspose + (WZ h (SpinOperators.act A (probeField B v x))-SpinOperators.act A (probeField B v x)) := by + simp only [map_sub,root_left_inverse A hA,probe_apply] + rw [he,SpinOperators.norm_act (root_adjoint_unitary A hA),probeField_eq_spinField, + ← spinField_preRoot] + have hM (C : Matrix (Fin 2) (Fin 2) ℂ) : 0 ≤ matrixMass C := + Finset.sum_nonneg (fun _ _ => Finset.sum_nonneg (fun _ _ => norm_nonneg _)) + have ht : spinBound (preRoot A (preRoot B.conjTranspose (preZ (preRoot B x)))) ≤ + matrixMass A*(matrixMass B.conjTranspose*(matrixMass B*spinBound x)) := by + calc + _ ≤ matrixMass A*spinBound (preRoot B.conjTranspose (preZ (preRoot B x))) := spinBound_preRoot _ _ + _ ≤ matrixMass A*(matrixMass B.conjTranspose*spinBound (preZ (preRoot B x))) := by + exact mul_le_mul_of_nonneg_left (spinBound_preRoot B.conjTranspose _) (hM A) + _ = matrixMass A*(matrixMass B.conjTranspose*spinBound (preRoot B x)) := by rw [spinBound_preZ] + _ ≤ _ := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left (spinBound_preRoot B x) (hM B.conjTranspose)) (hM A) + exact (WZ_spinField_sub_le h v _).trans (by + have hh := mul_le_mul_of_nonneg_left ht (by positivity : 0 ≤ 2*‖h‖*‖v‖) + simpa only [mul_assoc] using hh) + +end CoherentFock + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/WeightedGradientField.lean b/lean/OAI/Probability/ParisiFinite/WeightedGradientField.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9948c223e5d34174269967dd1b3fd4f075069a8 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/WeightedGradientField.lean @@ -0,0 +1,636 @@ +import Mathlib +import OAI.Probability.ParisiFinite.MeasurableStepParam + +namespace OAI + +/-! Weighted Gradient Field. -/ + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +namespace ThirdJet +variable {f : SmoothField} + +def weightedGradientField (j : ThirdJet f) (r : SmoothField) (R : ℝ≥0) + (hr : ∀ x,|r.val x|≤R) : SmoothField where + val := fun x => r.val x*f.d1 x + d1 := fun x => r.d1 x*f.d1 x+r.val x*f.d2 x + d2 := fun x => r.d2 x*f.d1 x+2*r.d1 x*f.d2 x+r.val x*j.d3 x + hasD1 := fun x => (r.hasD1 x).mul (f.hasD2 x) + hasD2 := fun x => by + convert ((r.hasD2 x).mul (f.hasD2 x)).add ((r.hasD1 x).mul (j.hasD3 x)) using 1 + first | rfl | ring + continuousD2 := ((r.continuousD2.mul f.continuousD1).add + ((r.continuousD1.const_mul 2).mul f.continuousD2)).add (r.lipschitz.continuous.mul j.continuousD3) + bound1 := r.bound1*f.bound1+R*f.bound2 + bound2 := r.bound2*f.bound1+2*r.bound1*f.bound2+R*j.bound3 + normD1 := fun x => by + apply (abs_add_le _ _).trans + simp only [abs_mul,NNReal.coe_add,NNReal.coe_mul] + gcongr <;> first | exact r.normD1 x | exact f.normD1 x | exact hr x | exact f.normD2 x + normD2 := fun x => by + change _ ≤ (r.bound2:ℝ)*f.bound1+2*r.bound1*f.bound2+(R:ℝ)*j.bound3 + apply (abs_add_le _ _).trans + apply add_le_add ((abs_add_le _ _).trans ?_) ?_ + · simp only [abs_mul,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] + gcongr <;> first | exact r.normD2 x | exact r.normD1 x | exact f.normD1 x | exact f.normD2 x + · simp only [abs_mul] + exact mul_le_mul (hr x) (j.normD3 x) (abs_nonneg _) R.coe_nonneg + +def slabWeightedGradientTest (j : ThirdJet f) (r : SmoothField) (R : ℝ≥0) + (hr : ∀ x,|r.val x|≤R) (a b : ℝ) : TimeQuadraticTest where + val := fun t x => r.val x*(fieldOnInterval f a b t).d1 x + d1 := fun t x => r.d1 x*(fieldOnInterval f a b t).d1 x+r.val x*(fieldOnInterval f a b t).d2 x + d2 := fun t x => r.d2 x*(fieldOnInterval f a b t).d1 x+ + 2*r.d1 x*(fieldOnInterval f a b t).d2 x+r.val x*j.slabD3 a b t x + dt := fun t x => r.val x*j.gradientDt a b t x + hasD1 := fun t => ((j.transform a (Real.sqrt (b-t))).weightedGradientField r R hr).hasD1 + hasD2 := fun t => ((j.transform a (Real.sqrt (b-t))).weightedGradientField r R hr).hasD2 + continuousD2 := fun t => ((j.transform a (Real.sqrt (b-t))).weightedGradientField r R hr).continuousD2 + c1 := ((j.transform a 0).weightedGradientField r R hr).bound1 + c2 := ((j.transform a 0).weightedGradientField r R hr).bound2 + ct := R*j.gradientTimeBound a + bound1 := fun t x => by + simpa only [Real.norm_eq_abs,fieldOnInterval,weightedGradientField,transform,SmoothField.transform] + using ((j.transform a (Real.sqrt (b-t))).weightedGradientField r R hr).normD1 x + bound2 := fun t x => by + simpa only [Real.norm_eq_abs,fieldOnInterval,weightedGradientField,transform,SmoothField.transform,slabD3] + using ((j.transform a (Real.sqrt (b-t))).weightedGradientField r R hr).normD2 x + boundT := fun t x => by + simp only [norm_mul,NNReal.coe_mul] + exact mul_le_mul (by simpa only [Real.norm_eq_abs] using hr x) + (j.gradientDt_bound a b t x) (norm_nonneg _) R.coe_nonneg + measT := (r.lipschitz.continuous.measurable.comp measurable_snd).mul (j.measurable_gradientDt a b) + continuousT := fun t => r.lipschitz.continuous.mul (j.continuous_gradientDt a b t) + jointD1 := ae_of_all _ fun _ _ _ => + (((r.continuousD1.comp continuous_snd).mul (continuous_fieldOnInterval_d1 f a b)).add + ((r.lipschitz.continuous.comp continuous_snd).mul (continuous_fieldOnInterval_d2 f a b))).continuousAt + jointD2 := ae_of_all _ fun _ _ _ => + ((((r.continuousD2.comp continuous_snd).mul (continuous_fieldOnInterval_d1 f a b)).add + (((r.continuousD1.comp continuous_snd).const_mul 2).mul (continuous_fieldOnInterval_d2 f a b))).add + ((r.lipschitz.continuous.comp continuous_snd).mul (j.continuous_slabD3 a b))).continuousAt + integralT := fun u _ v _ x => by + rw [intervalIntegral.integral_const_mul,j.gradient_integral_time] + ring + +end ThirdJet + +structure ScheduleWeightedGradient (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (s : ℝ) (r : SmoothField) where + test : TimeQuadraticTest + val_eq : ∀ t x,test.val t x=r.val x*(finiteTimeField β hβ ls s t).d1 x + cancel : ∀ t,s≤t → t + refine ⟨((terminalThird β hβ).weightedGradientField r R hr).staticTimeTest,fun _ _ => rfl,?_⟩ + intro t ht ht' x z + simp only [width,List.map_nil,List.sum_nil,add_zero] at ht' + exact False.elim (not_lt_of_ge ht ht') + | cons l ls ih => + rcases l with ⟨a,d⟩ + let c : ℝ := s+d + have hc0 : 0≤c := add_nonneg hs d.coe_nonneg + have hend : c+width ls≤1 := by dsimp only [c];rw [width_cons] at he;linarith + have hc1 : c≤1 := by linarith [schedule_width_nonneg ls] + let tail := ih c hc0 hend + let slab := (recursionThird β hβ ls).slabWeightedGradientTest r R hr a c + have hval : (fieldOnInterval (smoothRecursion β hβ ls) a c c).val=(finiteTimeField β hβ ls c c).val := by + funext x + rw [fieldOnInterval_right,finiteTimeField_start,smoothRecursion_val] + have hmatch (x : ℝ) : slab.val c x=tail.test.val c x := by + change r.val x*(fieldOnInterval (smoothRecursion β hβ ls) a c c).d1 x=tail.test.val c x + rw [tail.val_eq,SmoothField.d1_eq_of_val_eq hval] + refine ⟨slab.glue tail.test c ⟨hc0,hc1⟩ hmatch,?_,?_⟩ + · intro t x + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeField,ThirdJet.slabWeightedGradientTest,slab,c] + split_ifs + · rfl + · exact tail.val_eq t x + · intro t ht ht' x z + simp only [TimeQuadraticTest.glue,TimeQuadraticTest.splice,finiteTimeField,finiteTimeCoefficient, + ThirdJet.slabWeightedGradientTest,slab,c] + split_ifs with hcut + · rw [ThirdJet.gradientDt,ite_eq_left hcut] + ring + · exact tail.cancel t (le_of_not_gt hcut) (by rw [width_cons] at ht';dsimp only [c];linarith) x z + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def finiteWeightedKernel (w : SmoothField) (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (b : Drift K M) + (t x : ℝ) : ℝ := + w.d2 x/2*(finiteTimeField β hβ ls 0 t).d1 x+ + w.d1 x*(finiteTimeField β hβ ls 0 t).d2 x+ + w.d1 x*(finiteTimeField β hβ ls 0 t).d1 x*b.val t x+ + w.val x*(finiteTimeField β hβ ls 0 t).d2 x* + (b.val t x-finiteTimeCoefficient ls 0 t*(finiteTimeField β hβ ls 0 t).d1 x) + +lemma finiteWeightedKernel_bound (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) + (ha : ∀ l∈ls,l.1≤β) (b : Drift K M) (t x : ℝ) : + ‖finiteWeightedKernel w β hβ ls b t x‖≤(w.bound2:ℝ)/2+w.bound1*(β:ℝ)+w.bound1*(M:ℝ)+(R:ℝ)*(β:ℝ)*((M:ℝ)+(β:ℝ)) := by + have hm : |(finiteTimeField β hβ ls 0 t).d1 x|≤1 := by + simpa only [(finiteTimeField_curvature β hβ ls ha 0 t).1,NNReal.coe_one] using + (finiteTimeField β hβ ls 0 t).normD1 x + have ha' := curvature_abs_d2 (finiteTimeField_curvature β hβ ls ha 0 t) x + have hc := finiteTimeCoefficient_bound β ls ha 0 t + have hbm : |b.val t x|≤(M:ℝ) := by simpa only [Real.norm_eq_abs] using b.bound t x + have he : |b.val t x-finiteTimeCoefficient ls 0 t*(finiteTimeField β hβ ls 0 t).d1 x|≤(M:ℝ)+(β:ℝ) := by + apply (abs_sub _ _).trans + rw [abs_mul] + exact add_le_add hbm ((mul_le_mul hc hm (abs_nonneg _) β.coe_nonneg).trans_eq (mul_one _)) + rw [finiteWeightedKernel,Real.norm_eq_abs] + calc + _ ≤ |w.d2 x/2*(finiteTimeField β hβ ls 0 t).d1 x|+ + |w.d1 x*(finiteTimeField β hβ ls 0 t).d2 x|+ + |w.d1 x*(finiteTimeField β hβ ls 0 t).d1 x*b.val t x|+ + |w.val x*(finiteTimeField β hβ ls 0 t).d2 x* + (b.val t x-finiteTimeCoefficient ls 0 t*(finiteTimeField β hβ ls 0 t).d1 x)| := by + exact (abs_add_le _ _).trans (add_le_add + ((abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl)) le_rfl) + _ ≤ (w.bound2:ℝ)/2*1+w.bound1*(β:ℝ)+w.bound1*1*(M:ℝ)+(R:ℝ)*(β:ℝ)*((M:ℝ)+(β:ℝ)) := by + simp only [abs_mul,abs_div,abs_of_pos (by norm_num : (0:ℝ)<2)] + gcongr <;> first | exact w.normD2 x | exact w.normD1 x | exact hR x + _ = _ := by ring + +lemma finiteWeightedKernel_integrable (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) + (b : Drift K M) (t : ℝ) : + Integrable (fun ω => finiteWeightedKernel w β hβ ls b t + (extend (solution b (brownianPath W ω)) t)) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + refine Integrable.of_bound (C := (w.bound2:ℝ)/2+w.bound1*(β:ℝ)+w.bound1*(M:ℝ)+(R:ℝ)*(β:ℝ)*((M:ℝ)+(β:ℝ))) ?_ ?_ + · have hx := aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t) + have h1 := (finiteTimeField β hβ ls 0 t).continuousD1 + have h2 := (finiteTimeField β hβ ls 0 t).continuousD2 + have hc : Continuous (finiteWeightedKernel w β hβ ls b t) := by + unfold finiteWeightedKernel + exact ((((w.continuousD2.div_const 2).mul h1).add + (w.continuousD1.mul h2)).add ((w.continuousD1.mul h1).mul (b.lipschitz t).continuous)).add + ((w.lipschitz.continuous.mul h2).mul ((b.lipschitz t).continuous.sub (continuous_const.mul h1))) + exact hc.measurable.comp_aemeasurable hx |>.aestronglyMeasurable + · exact ae_of_all _ fun ω => finiteWeightedKernel_bound w R hR β hβ ls ha b t _ + +lemma expected_finiteWeightedKernel_eq (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) (b : Drift K M) + (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) : + (∫ ω,finiteWeightedKernel w β hβ ls b t (extend (solution b (brownianPath W ω)) t) ∂P)= + timeGeneratorC2 P W b (scheduleWeightedGradient β hβ ls 0 le_rfl (by rw [hw];norm_num) w R hR).test t+ + timeDerivativeC2 P W b (scheduleWeightedGradient β hβ ls 0 le_rfl (by rw [hw];norm_num) w R hR).test t := by + let r := scheduleWeightedGradient β hβ ls 0 le_rfl (by rw [hw];norm_num) w R hR + change _=(∫ ω,generatorC2 (r.test.slice t) b t (extend (solution b (brownianPath W ω)) t) ∂P)+ + (∫ ω,r.test.dt t (extend (solution b (brownianPath W ω)) t) ∂P) + rw [←integral_add (generatorC2_integrable hW b _ t) (timeDerivativeC2_integrable_inner hW b r.test t)] + apply integral_congr_ae + filter_upwards [] with ω + have hh := r.cancel t ht.1.le (by simpa only [hw,zero_add] using ht.2) + (extend (solution b (brownianPath W ω)) t) (b.val t (extend (solution b (brownianPath W ω)) t)) + dsimp only [generatorC2,TimeQuadraticTest.slice,finiteWeightedKernel] + linarith + +lemma expected_finiteWeightedKernel_aestronglyMeasurable (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (fun t => ∫ ω,finiteWeightedKernel w β hβ ls b t + (extend (solution b (brownianPath W ω)) t) ∂P) (volume.restrict (Ioc (0:ℝ) 1)) := by + let r := scheduleWeightedGradient β hβ ls 0 le_rfl (by rw [hw];norm_num) w R hR + have hj := timeGeneratorC2_intervalIntegrable hW b r.test hc + have ht := timeDerivativeC2_intervalIntegrable hW b r.test hc + rw [intervalIntegrable_iff_integrableOn_Ioc_of_le zero_le_one] at hj ht + apply (hj.aestronglyMeasurable.add ht.aestronglyMeasurable).congr + have hnot : ∀ᵐ t ∂volume,t≠(1:ℝ) := by simp [ae_iff,measure_singleton] + filter_upwards [ae_restrict_mem measurableSet_Ioc,ae_restrict_of_ae hnot] with t hmem hn + exact (expected_finiteWeightedKernel_eq w R hR hW β hβ ls hw b t ⟨hmem.1,hmem.2.lt_of_ne hn⟩).symm + +lemma expected_finiteWeightedKernel_bound (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (ha : ∀ l∈ls,l.1≤β) (b : Drift K M) (t : ℝ) : + ‖∫ ω,finiteWeightedKernel w β hβ ls b t (extend (solution b (brownianPath W ω)) t) ∂P‖≤ + (w.bound2:ℝ)/2+w.bound1*(β:ℝ)+w.bound1*(M:ℝ)+(R:ℝ)*(β:ℝ)*((M:ℝ)+(β:ℝ)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + exact (norm_integral_le_of_norm_le_const (μ:=P) (ae_of_all P fun ω => + finiteWeightedKernel_bound w R hR β hβ ls ha b t _)).trans_eq (by simp) + + +theorem finite_schedule_weighted_verification (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (hW : IsBrownianReal W P) + (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (β : ℝ≥0) (hβ : 0<β) (ls : Schedule) (hw : width ls=1) + (c : ℝ≥0) (hc0 : c≠0) (hc1 : c≤1) : + (∫ ω,w.val (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1⟩)* + (finiteTimeField β hβ ls 0 c).d1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1⟩) ∂P)- + w.val 0*(smoothRecursion β hβ ls).d1 0= + ∫ t in (0:ℝ)..(c:ℝ),∫ ω,finiteWeightedKernel w β hβ ls b t + (extend (solution b (brownianPath W ω)) t) ∂P := by + let r := scheduleWeightedGradient β hβ ls 0 le_rfl (by rw [hw];norm_num) w R hR + have hh := brownian_solution_time_generator_at hW b r.test c hc0 hc1 hc + have hsub : uIcc (0:ℝ) c⊆uIcc (0:ℝ) 1 := by + rw [uIcc_of_le c.coe_nonneg,uIcc_of_le zero_le_one] + exact Icc_subset_Icc le_rfl (by exact_mod_cast hc1) + have hj := (timeGeneratorC2_intervalIntegrable hW b r.test hc).mono_set hsub + have ht := (timeDerivativeC2_intervalIntegrable hW b r.test hc).mono_set hsub + simp_rw [r.val_eq,finiteTimeField_d1_start] at hh + rw [hh,←intervalIntegral.integral_add hj ht] + apply intervalIntegral.integral_congr_Ioo_of_le c.coe_nonneg + intro t ht + exact (expected_finiteWeightedKernel_eq w R hR hW β hβ ls hw b t + ⟨ht.1,ht.2.trans_le (by exact_mod_cast hc1)⟩).symm + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +def weightedKernel (w : SmoothField) (β : ℝ≥0) (γ : ℝ≥0 → ℝ≥0) (b : Drift K M) (t x : ℝ) : ℝ := + w.d2 x/2*fieldGradient β γ (Real.toNNReal t) x+ + w.d1 x*fieldCurvature β γ (Real.toNNReal t) x+ + w.d1 x*fieldGradient β γ (Real.toNNReal t) x*b.val t x+ + w.val x*fieldCurvature β γ (Real.toNNReal t) x* + (b.val t x-(γ (Real.toNNReal t):ℝ)*fieldGradient β γ (Real.toNNReal t) x) + +lemma global_dyadic_weightedKernel_tendsto (w : SmoothField) (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (b : Drift K M) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) + (hc : Tendsto (fun n => finiteTimeCoefficient (dyadicSchedule γ false 0 1 n) 0 t) + atTop (𝓝 (γ (Real.toNNReal t):ℝ))) (x : ℝ) : + Tendsto (fun n => finiteWeightedKernel w β hβ (dyadicSchedule γ false 0 1 n) b t x) + atTop (𝓝 (weightedKernel w β γ b t x)) := by + have hr : Real.toNNReal t<1 := by + exact_mod_cast (show (Real.toNNReal t:ℝ)<1 by rw [Real.coe_toNNReal _ ht.1.le];exact ht.2) + have hg := (global_dyadic_gradient_tendstoUniformly β hβ hγ hb _ hr).tendsto_at x + have ha := (global_dyadic_curvature_tendstoUniformly β hβ hγ hb _ hr).tendsto_at x + rw [Real.coe_toNNReal _ ht.1.le] at hg ha + exact (((hg.const_mul (w.d2 x/2)).add (ha.const_mul (w.d1 x))).add + ((hg.const_mul (w.d1 x)).mul_const (b.val t x))).add + ((ha.const_mul (w.val x)).mul (tendsto_const_nhds.sub (hc.mul hg))) + +lemma expected_global_dyadic_weightedKernel_tendsto (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (b : Drift K M) (t : ℝ) (ht : t∈Ioo (0:ℝ) 1) + (hc : Tendsto (fun n => finiteTimeCoefficient (dyadicSchedule γ false 0 1 n) 0 t) + atTop (𝓝 (γ (Real.toNNReal t):ℝ))) : + Tendsto (fun n => ∫ ω,finiteWeightedKernel w β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) atTop + (𝓝 (∫ ω,weightedKernel w β γ b t (extend (solution b (brownianPath W ω)) t) ∂P)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + apply tendsto_integral_of_dominated_convergence + (fun _ : Ω => (w.bound2:ℝ)/2+w.bound1*(β:ℝ)+w.bound1*(M:ℝ)+(R:ℝ)*(β:ℝ)*((M:ℝ)+(β:ℝ))) + (fun n => (finiteWeightedKernel_integrable w R hR hW β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => + finiteWeightedKernel_bound w R hR β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t _) + exact ae_of_all _ fun ω => global_dyadic_weightedKernel_tendsto w β hβ hγ hb b t ht hc _ + +lemma expected_global_dyadic_gradient_weighted_tendsto (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (hW : IsBrownianReal W P) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (b : Drift K M) (c : ℝ≥0) (hc : c<1) : + Tendsto (fun n => ∫ ω,w.val (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩)* + (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).d1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩) ∂P) atTop + (𝓝 (∫ ω,w.val (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩)*fieldGradient β γ c + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩) ∂P)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hx := aemeasurable_solution_eval b (brownianPath W) (brownianPath_aemeasurable_eval hW) + ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩ + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => (R:ℝ)) + · intro n + exact ((w.lipschitz.continuous.mul (finiteTimeField β hβ _ 0 c).continuousD1).measurable.comp_aemeasurable hx).aestronglyMeasurable + · exact integrable_const _ + · intro n + filter_upwards [] with ω + rw [Real.norm_eq_abs,abs_mul] + have hh := (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).normD1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩) + have hh' : |(finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).d1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc.le⟩)|≤1 := by + simpa only [(finiteTimeField_curvature β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) 0 c).1,NNReal.coe_one] using hh + exact (mul_le_mul (hR _) hh' (abs_nonneg _) R.coe_nonneg).trans_eq (mul_one _) + · exact ae_of_all _ fun ω => ((global_dyadic_gradient_tendstoUniformly β hβ hγ hb c hc).tendsto_at _).const_mul _ + + + +theorem canonical_weighted_verification (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) (hW : IsBrownianReal W P) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) + (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} (hγ : Monotone γ) (hb : ∀ t,γ t≤β) + (c : ℝ≥0) (hc0 : c≠0) (hc1 : c<1) : + (∫ ω,w.val (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1.le⟩)* + fieldGradient β γ c (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1.le⟩) ∂P)- + w.val 0*fieldGradient β γ 0 0= + ∫ t in (0:ℝ)..(c:ℝ),∫ ω,weightedKernel w β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P := by + have hsub : Ioc (0:ℝ) c⊆Ioc (0:ℝ) 1 := Ioc_subset_Ioc le_rfl (by exact_mod_cast hc1.le) + have hi : Tendsto (fun n => ∫ t in (0:ℝ)..(c:ℝ),∫ ω, + finiteWeightedKernel w β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) atTop + (𝓝 (∫ t in (0:ℝ)..(c:ℝ),∫ ω,weightedKernel w β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P)) := by + have hmeas (n : ℕ) : AEStronglyMeasurable + (fun t => ∫ ω,finiteWeightedKernel w β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) (volume.restrict (uIoc (0:ℝ) c)) := by + rw [uIoc_of_le c.coe_nonneg] + exact (expected_finiteWeightedKernel_aestronglyMeasurable w R hR hW β hβ _ + (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) b hc).mono_measure + (Measure.restrict_mono_set _ hsub) + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => (w.bound2:ℝ)/2+w.bound1*(β:ℝ)+w.bound1*(M:ℝ)+(R:ℝ)*(β:ℝ)*((M:ℝ)+(β:ℝ))) (Eventually.of_forall hmeas) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => + expected_finiteWeightedKernel_bound w R hR hW β hβ _ (dyadicSchedule_coeff_bound hb false 0 1 n) b t) + intervalIntegrable_const + filter_upwards [global_dyadic_coefficient_tendsto_ae hγ] with t ht hmem + rw [uIoc_of_le c.coe_nonneg] at hmem + have hti : t∈Ioo (0:ℝ) 1 := ⟨hmem.1,hmem.2.trans_lt (by exact_mod_cast hc1)⟩ + exact expected_global_dyadic_weightedKernel_tendsto w R hR hW β hβ hγ hb b t hti (ht hti) + have h0 : Tendsto (fun n => w.val 0*(smoothRecursion β hβ (dyadicSchedule γ false 0 1 n)).d1 0) + atTop (𝓝 (w.val 0*fieldGradient β γ 0 0)) := by + have hh := ((global_dyadic_gradient_tendstoUniformly β hβ hγ hb 0 (by norm_num)).tendsto_at 0).const_mul (w.val 0) + simpa only [NNReal.coe_zero,finiteTimeField_d1_start] using hh + have he : (fun n => (∫ ω,w.val (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1.le⟩)* + (finiteTimeField β hβ (dyadicSchedule γ false 0 1 n) 0 c).d1 + (solution b (brownianPath W ω) ⟨c,c.coe_nonneg,by exact_mod_cast hc1.le⟩) ∂P)- + w.val 0*(smoothRecursion β hβ (dyadicSchedule γ false 0 1 n)).d1 0)= + (fun n => ∫ t in (0:ℝ)..(c:ℝ),∫ ω,finiteWeightedKernel w β hβ (dyadicSchedule γ false 0 1 n) b t + (extend (solution b (brownianPath W ω)) t) ∂P) := by + funext n + exact finite_schedule_weighted_verification w R hR hW b hc β hβ _ + (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) c hc0 hc1.le + exact tendsto_nhds_unique + ((expected_global_dyadic_gradient_weighted_tendsto w R hR hW β hβ hγ hb b c hc1).sub h0) (he ▸ hi) + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite + +def sineWeight (L : ℝ≥0) (hL : 0 (L:ℝ)*Real.sin (x/L) + d1 := fun x => Real.cos (x/L) + d2 := fun x => -Real.sin (x/L)/L + hasD1 := fun x => by + have hp : (L:ℝ)≠0 := by exact_mod_cast hL.ne' + convert (((hasDerivAt_id x).div_const (L:ℝ)).sin).const_mul (L:ℝ) using 1 <;> first | rfl | simp [id_eq,div_eq_mul_inv,mul_comm,hp] + hasD2 := fun x => by + convert ((hasDerivAt_id x).div_const (L:ℝ)).cos using 1 <;> simp [div_eq_mul_inv] + continuousD2 := by fun_prop + bound1 := 1 + bound2 := 1/L + normD1 := fun x => by simpa only [NNReal.coe_one] using Real.abs_cos_le_one (x/L) + normD2 := fun x => by + simp only [abs_div,abs_neg,abs_of_nonneg L.coe_nonneg,NNReal.coe_div,NNReal.coe_one] + exact div_le_div_of_nonneg_right (Real.abs_sin_le_one _) L.coe_nonneg + +lemma sineWeight_bound (L : ℝ≥0) (hL : 0 (sineWeight (n+1) (by positivity)).val x) atTop (𝓝 x) := by + have h : Tendsto (fun n : ℕ => x/((n:ℝ)+1)) atTop (𝓝 0) := by + simpa only [div_eq_mul_inv,mul_zero,one_div,one_mul] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul x + have hh := (Real.continuous_sinc.tendsto 0).comp h + simp only [Real.sinc_zero] at hh + have he (n : ℕ) : (sineWeight (n+1) (by positivity)).val x=x*Real.sinc (x/((n:ℝ)+1)) := by + by_cases hx : x=0 + · simp [hx,sineWeight] + · have hn : (n:ℝ)+1≠0 := by positivity + simp only [sineWeight,NNReal.coe_add,NNReal.coe_natCast,NNReal.coe_one, + Real.sinc_of_ne_zero (div_ne_zero hx hn)] + field_simp + simp_rw [he] + simpa only [mul_one,Function.comp_def] using hh.const_mul x + +lemma sineWeight_d1_tendsto (x : ℝ) : + Tendsto (fun n : ℕ => (sineWeight (n+1) (by positivity)).d1 x) atTop (𝓝 1) := by + have h : Tendsto (fun n : ℕ => x/((n:ℝ)+1)) atTop (𝓝 0) := by + simpa only [div_eq_mul_inv,mul_zero,one_div,one_mul] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul x + simpa only [sineWeight,NNReal.coe_add,NNReal.coe_natCast,NNReal.coe_one,Real.cos_zero,Function.comp_def] + using (Real.continuous_cos.tendsto 0).comp h + +lemma sineWeight_d2_tendsto (x : ℝ) : + Tendsto (fun n : ℕ => (sineWeight (n+1) (by positivity)).d2 x) atTop (𝓝 0) := by + have h : Tendsto (fun n : ℕ => x/((n:ℝ)+1)) atTop (𝓝 0) := by + simpa only [div_eq_mul_inv,mul_zero,one_div,one_mul] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul x + have hh := (((Real.continuous_sin.tendsto 0).comp h).neg).mul + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)) + simpa only [sineWeight,NNReal.coe_add,NNReal.coe_natCast,NNReal.coe_one,Real.sin_zero,neg_zero,mul_zero, + one_div,div_eq_mul_inv,one_mul,Function.comp_def] using hh + +lemma sineWeight_bound2_le (n : ℕ) : ((sineWeight (n+1) (by positivity)).bound2:ℝ)≤1 := by + simp only [sineWeight,NNReal.coe_div,NNReal.coe_one,NNReal.coe_add,NNReal.coe_natCast] + exact (div_le_one (by positivity)).mpr (by linarith [Nat.cast_nonneg (α:=ℝ) n]) + +end ParisiFinite + + + + + + + +open MeasureTheory ProbabilityTheory Filter Function Set +open scoped Topology NNReal +namespace ParisiFinite +open ParisiPath +variable {K M : ℝ≥0} {Ω : Type*} [MeasurableSpace Ω] {P : Measure Ω} {W : ℝ≥0 → Ω → ℝ} + +lemma expected_weightedKernel_aestronglyMeasurable (w : SmoothField) (R : ℝ≥0) (hR : ∀ x,|w.val x|≤R) + (hW : IsBrownianReal W P) (β : ℝ≥0) (hβ : 0<β) {γ : ℝ≥0 → ℝ≥0} + (hγ : Monotone γ) (hb : ∀ t,γ t≤β) (b : Drift K M) + (hc : ∀ᵐ t ∂volume,t∈Icc (0:ℝ) 1 → ∀ x,ContinuousAt (uncurry b.val) (t,x)) : + AEStronglyMeasurable (fun t => ∫ ω,weightedKernel w β γ b t + (extend (solution b (brownianPath W ω)) t) ∂P) (volume.restrict (Ioc (0:ℝ) 1)) := by + apply aestronglyMeasurable_of_tendsto_ae atTop + (fun n => expected_finiteWeightedKernel_aestronglyMeasurable w R hR hW β hβ _ + (by simpa only [NNReal.coe_one] using dyadicSchedule_width γ false 0 1 n) b hc) + have hn : ∀ᵐ t ∂volume,t≠(1:ℝ) := by simp [ae_iff,measure_singleton] + filter_upwards [ae_restrict_mem measurableSet_Ioc,ae_restrict_of_ae hn, + ae_restrict_of_ae (global_dyadic_coefficient_tendsto_ae hγ)] with t ht hn hc + have hti : t∈Ioo (0:ℝ) 1 := ⟨ht.1,ht.2.lt_of_ne hn⟩ + exact expected_global_dyadic_weightedKernel_tendsto w R hR hW β hβ hγ hb b t hti (hc hti) + +namespace BoundedCoefficient +variable {β : ℝ≥0} + +def weightedFeedback (c : BoundedCoefficient β) (w : SmoothField) (t x : ℝ) : ℝ := + w.d2 x/2*fieldGradient β c.val (Real.toNNReal t) x+ + w.d1 x*fieldCurvature β c.val (Real.toNNReal t) x+ + c.real t*w.d1 x*(fieldGradient β c.val (Real.toNNReal t) x)^2 + +lemma weightedKernel_feedback (c : BoundedCoefficient β) (hβ : 0<β) (w : SmoothField) (t x : ℝ) : + weightedKernel w β c.val (c.driftData hβ) t x=c.weightedFeedback w t x := by + simp only [weightedKernel,weightedFeedback,driftData,drift,BoundedCoefficient.real] + ring + +lemma weightedFeedback_bound (c : BoundedCoefficient β) (hβ : 0<β) (w : SmoothField) + (h1 : ∀ x,|w.d1 x|≤1) (h2 : ∀ x,|w.d2 x|≤1) (t x : ℝ) : + ‖c.weightedFeedback w t x‖≤1/2+2*(β:ℝ) := by + have hm := fieldGradient_bound β hβ c.mono c.bound (Real.toNNReal t) x + have ha := fieldCurvature_abs β hβ c.mono c.bound (Real.toNNReal t) x + have hc : |c.real t|≤β := by rw [abs_of_nonneg (c.real_nonneg t)];exact c.real_le t + change |w.d2 x/2*fieldGradient β c.val (Real.toNNReal t) x+ + w.d1 x*fieldCurvature β c.val (Real.toNNReal t) x+ + c.real t*w.d1 x*(fieldGradient β c.val (Real.toNNReal t) x)^2|≤_ + have hA : |w.d2 x/2*fieldGradient β c.val (Real.toNNReal t) x|≤1/2 := by + rw [abs_mul,abs_div,abs_of_pos (by norm_num : (0:ℝ)<2)] + calc + _ ≤ 1/2*1 := mul_le_mul (div_le_div_of_nonneg_right (h2 x) (by norm_num)) hm + (abs_nonneg _) (by norm_num) + _ = _ := mul_one _ + have hB : |w.d1 x*fieldCurvature β c.val (Real.toNNReal t) x|≤β := by + rw [abs_mul] + exact (mul_le_mul (h1 x) ha (abs_nonneg _) (by norm_num)).trans_eq (one_mul _) + have hC : |c.real t*w.d1 x*(fieldGradient β c.val (Real.toNNReal t) x)^2|≤β := by + rw [abs_mul,abs_mul,abs_pow] + exact (mul_le_mul (mul_le_mul hc (h1 x) (abs_nonneg _) β.coe_nonneg) + (pow_le_pow_left₀ (abs_nonneg _) hm 2) (by positivity) (by positivity)).trans_eq (by ring) + have hh := (abs_add_three (w.d2 x/2*fieldGradient β c.val (Real.toNNReal t) x) + (w.d1 x*fieldCurvature β c.val (Real.toNNReal t) x) + (c.real t*w.d1 x*(fieldGradient β c.val (Real.toNNReal t) x)^2)).trans + (add_le_add (add_le_add hA hB) hC) + linarith + +lemma weightedFeedback_integrable (hW : IsBrownianReal W P) (c : BoundedCoefficient β) (hβ : 0<β) + (w : SmoothField) (h1 : ∀ x,|w.d1 x|≤1) (h2 : ∀ x,|w.d2 x|≤1) (t : ℝ) : + Integrable (fun ω => c.weightedFeedback w t + (extend (solution (c.driftData hβ) (brownianPath W ω)) t)) P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hx := aemeasurable_solution_eval (c.driftData hβ) (brownianPath W) (brownianPath_aemeasurable_eval hW) + (projIcc 0 1 zero_le_one t) + have hm := (fieldGradient_lipschitz β hβ c.mono c.bound (Real.toNNReal t)).continuous + have ha := (fieldCurvature_lipschitz β hβ c.mono c.bound (Real.toNNReal t)).continuous + have hh : Continuous (c.weightedFeedback w t) := + (((w.continuousD2.div_const 2).mul hm).add (w.continuousD1.mul ha)).add + ((continuous_const.mul w.continuousD1).mul (hm.pow 2)) + exact Integrable.of_bound (hh.measurable.comp_aemeasurable hx).aestronglyMeasurable _ + (ae_of_all _ fun ω => c.weightedFeedback_bound hβ w h1 h2 t _) + +lemma expected_feedback_sine_tendsto (hW : IsBrownianReal W P) (c : BoundedCoefficient β) (hβ : 0<β) (t : ℝ) : + Tendsto (fun n : ℕ => ∫ ω,c.weightedFeedback (sineWeight (n+1) (by positivity)) t + (extend (solution (c.driftData hβ) (brownianPath W ω)) t) ∂P) atTop + (𝓝 (∫ ω,fieldCurvature β c.val (Real.toNNReal t) + (extend (solution (c.driftData hβ) (brownianPath W ω)) t)+c.real t* + (fieldGradient β c.val (Real.toNNReal t) (extend (solution (c.driftData hβ) (brownianPath W ω)) t))^2 ∂P)) := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + have hb1 (n : ℕ) (x : ℝ) : |(sineWeight (n+1) (by positivity)).d1 x|≤1 := + Real.abs_cos_le_one _ + have hb2 (n : ℕ) (x : ℝ) : |(sineWeight (n+1) (by positivity)).d2 x|≤1 := + ((sineWeight (n+1) (by positivity)).normD2 x).trans (sineWeight_bound2_le n) + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => 1/2+2*(β:ℝ)) + (fun n => (c.weightedFeedback_integrable hW hβ _ (hb1 n) (hb2 n) t).aestronglyMeasurable) + (integrable_const _) (fun n => ae_of_all _ fun ω => c.weightedFeedback_bound hβ _ (hb1 n) (hb2 n) t _) + filter_upwards [] with ω + let x := extend (solution (c.driftData hβ) (brownianPath W ω)) t + have hh := (((sineWeight_d2_tendsto x).div_const 2).mul_const (fieldGradient β c.val (Real.toNNReal t) x)).add + ((sineWeight_d1_tendsto x).mul_const (fieldCurvature β c.val (Real.toNNReal t) x)) + have hh' := hh.add (((sineWeight_d1_tendsto x).const_mul (c.real t)).mul_const + ((fieldGradient β c.val (Real.toNNReal t) x)^2)) + simpa only [weightedFeedback,x,zero_div,zero_mul,one_mul,mul_one,zero_add] using hh' + +theorem position_spin_raw (hW : IsBrownianReal W P) (c : BoundedCoefficient β) (hβ : 0<β) + (q : ℝ≥0) (hq0 : q≠0) (hq1 : q<1) : + (∫ ω,(solution (c.driftData hβ) (brownianPath W ω) ⟨q,q.coe_nonneg,by exact_mod_cast hq1.le⟩)* + fieldGradient β c.val q (solution (c.driftData hβ) (brownianPath W ω) ⟨q,q.coe_nonneg,by exact_mod_cast hq1.le⟩) ∂P)= + ∫ t in (0:ℝ)..(q:ℝ),∫ ω,fieldCurvature β c.val (Real.toNNReal t) + (extend (solution (c.driftData hβ) (brownianPath W ω)) t)+c.real t* + (fieldGradient β c.val (Real.toNNReal t) (extend (solution (c.driftData hβ) (brownianPath W ω)) t))^2 ∂P := by + let : IsProbabilityMeasure P := (hW.hasLaw_eval 0).isProbabilityMeasure + let X (ω : Ω) := solution (c.driftData hβ) (brownianPath W ω) + let Q : Icc (0:ℝ) 1 := ⟨q,q.coe_nonneg,by exact_mod_cast hq1.le⟩ + let wn (n : ℕ) := sineWeight (n+1) (by positivity) + have hb1 (n : ℕ) (x : ℝ) : |(wn n).d1 x|≤1 := Real.abs_cos_le_one _ + have hb2 (n : ℕ) (x : ℝ) : |(wn n).d2 x|≤1 := + ((wn n).normD2 x).trans (sineWeight_bound2_le n) + have hx : Integrable (fun ω => X ω Q) P := brownian_solution_integrable hW _ Q + have hleft : Tendsto (fun n => ∫ ω,(wn n).val (X ω Q)*fieldGradient β c.val q (X ω Q) ∂P) atTop + (𝓝 (∫ ω,(X ω Q)*fieldGradient β c.val q (X ω Q) ∂P)) := by + apply tendsto_integral_of_dominated_convergence (fun ω => ‖X ω Q‖) + (fun n => (((wn n).lipschitz.continuous.mul (fieldGradient_lipschitz β hβ c.mono c.bound q).continuous).measurable.comp_aemeasurable hx.aemeasurable).aestronglyMeasurable) + hx.norm + · intro n + filter_upwards [] with ω + change ‖(wn n).val (X ω Q)*fieldGradient β c.val q (X ω Q)‖≤‖X ω Q‖ + rw [norm_mul,Real.norm_eq_abs,Real.norm_eq_abs,Real.norm_eq_abs] + exact (mul_le_mul (sineWeight_bound_abs _ _ _) (fieldGradient_bound β hβ c.mono c.bound q _) + (abs_nonneg _) (abs_nonneg _)).trans_eq (mul_one _) + · exact ae_of_all _ fun ω => (sineWeight_tendsto (X ω Q)).mul_const _ + have hsub : Ioc (0:ℝ) q⊆Ioc (0:ℝ) 1 := Ioc_subset_Ioc le_rfl (by exact_mod_cast hq1.le) + have hright : Tendsto (fun n => ∫ t in (0:ℝ)..(q:ℝ),∫ ω,c.weightedFeedback (wn n) t (extend (X ω) t) ∂P) atTop + (𝓝 (∫ t in (0:ℝ)..(q:ℝ),∫ ω,fieldCurvature β c.val (Real.toNNReal t) (extend (X ω) t)+ + c.real t*(fieldGradient β c.val (Real.toNNReal t) (extend (X ω) t))^2 ∂P)) := by + have hmeas (n : ℕ) : AEStronglyMeasurable (fun t => ∫ ω,c.weightedFeedback (wn n) t (extend (X ω) t) ∂P) + (volume.restrict (uIoc (0:ℝ) q)) := by + have hh := expected_weightedKernel_aestronglyMeasurable (wn n) (n+1) (sineWeight_bound _ _) + hW β hβ c.mono c.bound (c.driftData hβ) (c.drift_joint_ae_continuous hβ) + simp_rw [c.weightedKernel_feedback hβ] at hh + rw [uIoc_of_le q.coe_nonneg] + exact hh.mono_measure (Measure.restrict_mono_set _ hsub) + apply intervalIntegral.tendsto_integral_filter_of_dominated_convergence + (fun _ => 1/2+2*(β:ℝ)) (Eventually.of_forall hmeas) + (Eventually.of_forall fun n => ae_of_all _ fun t _ => ?_) intervalIntegrable_const + (ae_of_all _ fun t _ => c.expected_feedback_sine_tendsto hW hβ t) + exact (norm_integral_le_of_norm_le_const (μ:=P) (ae_of_all P fun ω => + c.weightedFeedback_bound hβ (wn n) (hb1 n) (hb2 n) t _)).trans_eq (by simp) + have he : (fun n => ∫ ω,(wn n).val (X ω Q)*fieldGradient β c.val q (X ω Q) ∂P)= + (fun n => ∫ t in (0:ℝ)..(q:ℝ),∫ ω,c.weightedFeedback (wn n) t (extend (X ω) t) ∂P) := by + funext n + have hh := canonical_weighted_verification (wn n) (n+1) (sineWeight_bound _ _) hW (c.driftData hβ) + (c.drift_joint_ae_continuous hβ) β hβ c.mono c.bound q hq0 hq1 + simp_rw [c.weightedKernel_feedback hβ] at hh + simpa only [wn,sineWeight_zero,zero_mul,sub_zero] using hh + exact tendsto_nhds_unique hleft (he ▸ hright) + +end BoundedCoefficient +end ParisiFinite + +end + +end OAI diff --git a/lean/OAI/Probability/ParisiFinite/WeightedSumPos.lean b/lean/OAI/Probability/ParisiFinite/WeightedSumPos.lean new file mode 100644 index 0000000000000000000000000000000000000000..b55c2f9975d42a8608db74b82c290b5945294764 --- /dev/null +++ b/lean/OAI/Probability/ParisiFinite/WeightedSumPos.lean @@ -0,0 +1,698 @@ +import Mathlib +import OAI.Probability.ParisiFinite.HierarchyNumerator + +namespace OAI + +/-! Weighted Sum Pos. -/ + +noncomputable section + +open scoped BigOperators ComplexConjugate InnerProductSpace Topology ComplexOrder +open Filter +open scoped BigOperators +open scoped Matrix Matrix.Norms.L2Operator ComplexConjugate +open scoped InnerProductSpace ComplexConjugate +open Filter Topology +open Filter Set Topology +open scoped InnerProductSpace ComplexConjugate Topology +open scoped InnerProductSpace +open scoped BigOperators Topology InnerProductSpace +open scoped BigOperators InnerProductSpace +open scoped BigOperators Matrix Topology ComplexConjugate +open MeasureTheory ProbabilityTheory Filter +open scoped BigOperators Topology +open scoped BigOperators Matrix Topology +open scoped BigOperators Matrix Topology Matrix.Norms.Operator +open scoped Topology +open Filter Asymptotics +open scoped InnerProductSpace Topology +open scoped InnerProductSpace BigOperators +open scoped InnerProductSpace Topology BigOperators +open scoped Topology BigOperators +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace +open scoped Matrix Matrix.Norms.L2Operator InnerProductSpace BigOperators +open Filter ContinuousLinearMap +open ContinuousLinearMap +open scoped InnerProductSpace BigOperators Topology +open ContinuousLinearMap InnerProductSpace +open ContinuousLinearMap Filter +open Filter MeasureTheory +open scoped Topology ENNReal +open MeasureTheory ProbabilityTheory +open scoped BigOperators Topology RealInnerProductSpace +open scoped BigOperators TensorProduct +open scoped Topology InnerProductSpace +open MeasureTheory Filter +open MeasureTheory ProbabilityTheory Complex +open scoped BigOperators Topology InnerProductSpace ComplexConjugate +open scoped BigOperators Topology NNReal +open scoped BigOperators NNReal Topology +open scoped BigOperators NNReal +open scoped NNReal Topology +open scoped NNReal Topology BigOperators +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +open MeasureTheory ProbabilityTheory Filter Set MeasurableSpace +open MeasureTheory ProbabilityTheory Filter TopologicalSpace Set MeasurableSpace +open scoped BigOperators Topology NNReal ENNReal MatrixOrder +open scoped BigOperators Topology NNReal ENNReal ContDiff +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] + +lemma weighted_sum_pos {w f : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) (hf : ∀ i,0 h i) + rw [hs] at hnon + linarith + obtain ⟨i,hi⟩ := hex + exact Finset.sum_pos' (fun j _ => mul_nonneg (hw j) (le_of_lt (hf j))) + ⟨i,Finset.mem_univ _,mul_pos hi (hf i)⟩ + +lemma hierarchyMark_pos {d : ℕ} {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) {x : (Fin d → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : 0 exact Real.rpow_pos_of_pos (affine_mark_pos (hx _) hz) _ + | succ d ih => + exact Real.rpow_pos_of_pos (weighted_sum_pos hw hs (fun i => ih _ (fun s => hx _) )) _ + +lemma hierarchyMark_contDiffAt {d : ℕ} {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) {x : (Fin d → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) (n : ℕ∞ω) : ContDiffAt ℝ n (hierarchyMark w d a x) z := by + induction d with + | zero => + apply ContDiffAt.rpow_const_of_ne + · fun_prop + · exact ne_of_gt (affine_mark_pos (hx _) hz) + | succ d ih => + apply ContDiffAt.rpow_const_of_ne + · exact ContDiffAt.sum fun i _ => contDiffAt_const.mul (ih _ (fun s => hx _)) + · exact ne_of_gt (weighted_sum_pos hw hs (fun i => hierarchyMark_pos hw hs _ (fun s => hx _) hz)) + +lemma hierarchyLog_contDiffAt {d : ℕ} {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) {x : (Fin (d+1) → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) (n : ℕ∞ω) : ContDiffAt ℝ n (hierarchyLog w a x) z := by + apply contDiffAt_const.mul + apply (Real.contDiffAt_log.mpr _).comp z + (ContDiffAt.sum fun i _ => contDiffAt_const.mul (hierarchyMark_contDiffAt hw hs a (fun s => hx _) hz n)) + exact ne_of_gt (weighted_sum_pos hw hs (fun i => hierarchyMark_pos hw hs a (fun s => hx _) hz)) + +lemma treeMarkMoment_mem_unit {d r : ℕ} {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {x : (Fin d → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) (T : PartitionTree d r) : + 0≤treeMarkMoment w x T ∧ treeMarkMoment w x T≤1 := by + induction d generalizing r with + | zero => exact ⟨pow_nonneg (hx _).1 _,pow_le_one₀ (hx _).1 (hx _).2⟩ + | succ d ih => + rcases T with ⟨P,T⟩ + have hb (j : Fin P.length) : 0≤(∑ i,w i*treeMarkMoment w (fun s => x (Fin.cons i s)) (T j)) ∧ + (∑ i,w i*treeMarkMoment w (fun s => x (Fin.cons i s)) (T j))≤1 := by + refine ⟨Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (ih (fun s => hx _) (T j)).1),?_⟩ + calc + _ ≤ ∑ i,w i*1 := Finset.sum_le_sum fun i _ => mul_le_mul_of_nonneg_left + (ih (fun s => hx _) (T j)).2 (hw i) + _ = 1 := by simp [hs] + exact ⟨Finset.prod_nonneg (fun j _ => (hb j).1),Finset.prod_le_one₀ (fun j _ => (hb j).1) (fun j _ => (hb j).2)⟩ + +lemma hierarchyMarkedMoment_mem_unit {d : ℕ} (μ : ProbabilityMeasure OverlapArray) + (q : Fin (d+1) → ℝ) {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {x : (Fin d → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) (n : ℕ) : + 0≤hierarchyMarkedMoment μ q w x n ∧ hierarchyMarkedMoment μ q w x n≤1 := by + have hs1 : (∑ T : PartitionTree d n,(μ:Measure OverlapArray).real (hierarchyEvent (treeCodes T) q))≤1 := by + simpa using sum_measureReal_le_measureReal_univ (μ:=(μ:Measure OverlapArray)) + (s:=Finset.univ) (fun T _ => hierarchyEvent_measurable (treeCodes T) q) + (fun T _ U _ hTU => tree_hierarchy_disjoint hTU q) + refine ⟨Finset.sum_nonneg (fun T _ => mul_nonneg measureReal_nonneg + (treeMarkMoment_mem_unit hw hs hx T).1),?_⟩ + exact le_trans (Finset.sum_le_sum fun T _ => mul_le_of_le_one_right measureReal_nonneg + (treeMarkMoment_mem_unit hw hs hx T).2) hs1 + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] + +def hierarchyLogSeries {d : ℕ} (μ : ProbabilityMeasure OverlapArray) (q : Fin (d+1) → ℝ) + (w : ι → ℝ) (x : (Fin d → ι) → ℝ) : FormalMultilinearSeries ℝ ℝ ℝ := + FormalMultilinearSeries.ofScalars ℝ (fun n => -hierarchyMarkedMoment μ q w x n/(n:ℝ)) + +lemma hierarchyLog_zero {d : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) (x : (Fin (d+1) → ι) → ℝ) : hierarchyLog w a x 0=0 := by + simp [hierarchyLog,hierarchyMark_zero w hw,hw] + +lemma hierarchyLogSeries_radius {d : ℕ} (μ : ProbabilityMeasure OverlapArray) (q : Fin (d+1) → ℝ) + {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {x : (Fin d → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) : + (1:ℝ≥0∞)≤(hierarchyLogSeries μ q w x).radius := by + apply FormalMultilinearSeries.le_radius_of_bound (C:=1) (r:=1) + intro n + simp only [hierarchyLogSeries,FormalMultilinearSeries.ofScalars,norm_smul, + NNReal.coe_one,one_pow,mul_one,Real.norm_eq_abs,abs_div,abs_neg] + rw [show |(n:ℝ)|=(n:ℝ) from abs_of_nonneg (Nat.cast_nonneg n)] + by_cases hn : n=0 + · simp [hn] + have hm := hierarchyMarkedMoment_mem_unit μ q hw hs hx n + rw [abs_of_nonneg hm.1] + have hn1 : (1:ℝ)≤n := by exact_mod_cast Nat.pos_of_ne_zero hn + have hnorm : ‖ContinuousMultilinearMap.mkPiAlgebraFin ℝ n ℝ‖≤1 := by + apply le_trans ContinuousMultilinearMap.norm_mkPiAlgebraFin_le + norm_num + calc + _ ≤ (1:ℝ)/(n:ℝ)*1 := mul_le_mul (div_le_div_of_nonneg_right hm.2 (Nat.cast_nonneg _)) hnorm + (norm_nonneg _) (by positivity) + _ ≤ 1 := by rw [mul_one]; exact (div_le_one (by positivity)).mpr hn1 + +lemma GG_hierarchyLog_hasFPowerSeriesAt {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ha : ∀ k : Fin (d+1),overlapDiscount μ (q k.succ)≠0) + (w : ι → ℝ) (hw : ∑ i,w i=1) (x : (Fin (d+1) → ι) → ℝ) : + HasFPowerSeriesAt (hierarchyLog w (fun k => overlapDiscount μ (q k.succ)) x) + (hierarchyLogSeries μ q w x) 0 := by + let a := fun k : Fin (d+1) => overlapDiscount μ (q k.succ) + have hz : (∑ i,w i*hierarchyMark w d a (fun s => x (Fin.cons i s)) 0)=1 := by + simp [hierarchyMark_zero w hw,hw] + have hf : ContDiffAt ℝ ω (hierarchyLog w a x) 0 := by + apply contDiffAt_const.mul + apply (Real.contDiffAt_log.mpr _).comp 0 + (ContDiffAt.sum fun i _ => contDiffAt_const.mul (hierarchyMark_contDiffAt_zero w hw _ _ ω)) + rw [hz]; norm_num + have h := hf.analyticAt.hasFPowerSeriesAt + have he : (fun n => iteratedDeriv n (hierarchyLog w a x) 0/(n.factorial:ℝ))= + (fun n => -hierarchyMarkedMoment μ q w x n/(n:ℝ)) := by + funext n + by_cases hn : n=0 + · subst n + simp only [iteratedDeriv_zero,hierarchyLog_zero w hw,Nat.factorial_zero,Nat.cast_one, + div_one,Nat.cast_zero,div_zero] + · have hn' := Nat.pos_of_ne_zero hn + rw [GG_hierarchy_log_derivative hG hgg hu q hq h0 h1 ha w hw x hn'] + have hf : (n.factorial:ℝ)=(n:ℝ)*((n-1).factorial:ℝ) := by + exact_mod_cast (Nat.mul_factorial_pred hn).symm + have hf0 : ((n-1).factorial:ℝ)≠0 := Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _) + have hn0 : (n:ℝ)≠0 := Nat.cast_ne_zero.mpr hn + rw [hf] + field_simp + rw [he] at h + exact h + + + +theorem GG_hierarchy_log_identity {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ha : ∀ k : Fin (d+1),overlapDiscount μ (q k.succ)≠0) + {w : ι → ℝ} (hw : ∀ i,0≤w i) (hs : ∑ i,w i=1) + {x : (Fin (d+1) → ι) → ℝ} (hx : ∀ s,0≤x s ∧ x s≤1) + {z : ℝ} (hz : |z|<1) : + hierarchyLog w (fun k => overlapDiscount μ (q k.succ)) x z= + (hierarchyLogSeries μ q w x).sum z := by + let f := hierarchyLog w (fun k => overlapDiscount μ (q k.succ)) x + let p := hierarchyLogSeries μ q w x + have hr : (1:ℝ≥0∞)≤p.radius := hierarchyLogSeries_radius μ q hw hs hx + have hf : AnalyticOnNhd ℝ f (Set.Ioo (-1) 1) := by + intro t ht + exact (hierarchyLog_contDiffAt hw hs _ hx (abs_lt.mpr ht) ω).analyticAt + have hp : AnalyticOnNhd ℝ p.sum (Set.Ioo (-1) 1) := by + intro t ht + apply p.analyticOnNhd + apply lt_of_lt_of_le _ hr + rw [edist_zero_right,← ofReal_norm] + exact ENNReal.ofReal_lt_one.mpr (abs_lt.mpr ht) + have he : f=ᶠ[𝓝 0] p.sum := by + filter_upwards [(GG_hierarchyLog_hasFPowerSeriesAt hG hgg hu q hq h0 h1 ha w hs x).eventually_hasSum] with t ht + simpa only [zero_add,f,p,FormalMultilinearSeries.sum] using ht.tsum_eq.symm + exact hf.eqOn_of_preconnected_of_eventuallyEq hp isPreconnected_Ioo (by constructor <;> norm_num) + he (abs_lt.mp hz) + +end SKCavity + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +variable {ι : Type*} [Fintype ι] + +lemma hierarchyMark_one {d : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) (ha : ∀ k : Fin d,a k.succ≠0) {z : ℝ} (hz : z<1) : + hierarchyMark w d a (fun _ => 1) z=(1-z)^(a 0) := by + induction d with + | zero => simp [hierarchyMark] + | succ d ih => + change (∑ i,w i*hierarchyMark w d (fun k => a k.succ) (fun _ => 1) z)^(a 0/a 1)=_ + simp_rw [ih (fun k : Fin (d+1) => a k.succ) (fun k => ha k.succ)] + rw [← Finset.sum_mul,hw,one_mul,← Real.rpow_mul (sub_pos.mpr hz).le] + congr 1 + have h := ha 0 + change a 1≠0 at h + simp only [Fin.succ_zero_eq_one] + field_simp + +lemma hierarchyLog_one {d : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) + (a : Fin (d+1) → ℝ) (ha : ∀ k,a k≠0) {z : ℝ} (hz : z<1) : + hierarchyLog w a (fun _ => 1) z=Real.log (1-z) := by + unfold hierarchyLog + simp_rw [hierarchyMark_one w hw a (fun k => ha k.succ) hz] + rw [← Finset.sum_mul,hw,one_mul,Real.log_rpow (sub_pos.mpr hz)] + field_simp [ha 0] + +lemma treeMarkMoment_one {d r : ℕ} (w : ι → ℝ) (hw : ∑ i,w i=1) (T : PartitionTree d r) : + treeMarkMoment w (fun _ => 1) T=1 := by + induction d generalizing r with + | zero => exact one_pow r + | succ d ih => + rcases T with ⟨P,T⟩ + simp [treeMarkMoment,ih,hw] + +lemma hierarchy_partition_mass {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ha : ∀ k : Fin (d+1),overlapDiscount μ (q k.succ)≠0) + {n : ℕ} (hn : 0 1 + have hw : ∑ i,w i=1 := by simp [w] + let a := fun k : Fin (d+1) => overlapDiscount μ (q k.succ) + have he : hierarchyLog w a (fun _ => 1)=ᶠ[𝓝 (0:ℝ)] (fun z => Real.log (1-z)) := by + filter_upwards [isOpen_Iio.mem_nhds (show (0:ℝ)<1 by norm_num)] with z hz + exact hierarchyLog_one w hw a ha hz + have hd := GG_hierarchy_log_derivative hG hgg hu q hq h0 h1 ha w hw (fun _ => 1) hn + change iteratedDeriv n (hierarchyLog w a (fun _ => 1)) 0=_ at hd + rw [he.iteratedDeriv_eq n] at hd + have hf : iteratedDeriv n (fun z : ℝ => Real.log (1-z)) 0= -((n-1).factorial:ℝ) := by + have hh := log_power_affine_derivative (a:=1) (by norm_num) hn + simpa only [inv_one,Real.rpow_one,one_mul] using hh + rw [hf] at hd + simp only [hierarchyMarkedMoment,treeMarkMoment_one w hw,mul_one] at hd + have hf0 : -((n-1).factorial:ℝ)≠0 := neg_ne_zero.mpr (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)) + exact mul_left_cancel₀ hf0 (by simpa using hd.symm) + +lemma hierarchy_partition_cover {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) (ha : ∀ k : Fin (d+1),overlapDiscount μ (q k.succ)≠0) + {n : ℕ} (hn : 0 tree_hierarchy_disjoint hTU q) (fun T => hierarchyEvent_measurable (treeCodes T) q) + rw [hierarchy_partition_mass hG hgg hu q hq h0 h1 ha hn] at h + apply (ENNReal.toReal_eq_one_iff _).mp + exact h + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation +universe u +variable {ι : Type u} [Fintype ι] + + +@[reducible] def TreeDraw (ι : Type u) : {d r : ℕ} → PartitionTree d r → Type u + | 0,_,_ => PUnit.{u+1} + | _+1,_,⟨P,T⟩ => ∀ j : Fin P.length,ι × TreeDraw ι (T j) + +instance treeDrawFintype {d r : ℕ} (T : PartitionTree d r) : Fintype (TreeDraw ι T) := by + induction d generalizing r with + | zero => exact inferInstanceAs (Fintype PUnit.{u+1}) + | succ d ih => + rcases T with ⟨P,T⟩ + letI (j : Fin P.length) : Fintype (TreeDraw ι (T j)) := ih (T j) + exact inferInstanceAs (Fintype (∀ j : Fin P.length,ι × TreeDraw ι (T j))) + +def treeDrawWeight (w : ι → ℝ) : {d r : ℕ} → (T : PartitionTree d r) → TreeDraw ι T → ℝ + | 0,_,_,_ => 1 + | _+1,_,⟨_,T⟩,s => ∏ j,w (s j).1*treeDrawWeight w (T j) (s j).2 + +def treeDrawPath : {d r : ℕ} → (T : PartitionTree d r) → TreeDraw ι T → Fin r → (Fin d → ι) + | 0,_,_,_,_ => fun k => Fin.elim0 k + | _+1,_,⟨P,T⟩,s,i => + let j := P.equivSigma.symm i + Fin.cons (s j.1).1 (treeDrawPath (T j.1) (s j.1).2 j.2) + +omit [Fintype ι] in +lemma treeDrawPath_emb {d r : ℕ} (P : OrderedFinpartition r) (T : ∀ j,PartitionTree d (P.partSize j)) + (s : TreeDraw ι (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r)) (j : Fin P.length) (i : Fin (P.partSize j)) : + treeDrawPath (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r) s (P.emb j i)= + Fin.cons (s j).1 (treeDrawPath (T j) (s j).2 i) := by + simp only [treeDrawPath] + rw [show P.equivSigma.symm (P.emb j i)=⟨j,i⟩ from P.equivSigma.symm_apply_apply ⟨j,i⟩] + +omit [Fintype ι] in +lemma treeDrawWeight_nonneg (w : ι → ℝ) (hw : ∀ i,0≤w i) {d r : ℕ} (T : PartitionTree d r) + (s : TreeDraw ι T) : 0≤treeDrawWeight w T s := by + induction d generalizing r with + | zero => exact zero_le_one + | succ d ih => + rcases T with ⟨P,T⟩ + exact Finset.prod_nonneg fun j _ => mul_nonneg (hw _) (ih _ _) + +lemma treeDrawWeight_sum (w : ι → ℝ) (hw : ∑ i,w i=1) {d r : ℕ} (T : PartitionTree d r) : + (∑ s : TreeDraw ι T,treeDrawWeight w T s)=1 := by + induction d generalizing r with + | zero => change (∑ _ : PUnit.{u+1},(1:ℝ))=1; simp + | succ d ih => + rcases T with ⟨P,T⟩ + change (∑ s : ∀ j,ι × TreeDraw ι (T j),∏ j,w (s j).1*treeDrawWeight w (T j) (s j).2)=1 + rw [← Fintype.prod_sum (fun j (s : ι × TreeDraw ι (T j)) => w s.1*treeDrawWeight w (T j) s.2)] + simp only [Fintype.sum_prod_type,← Finset.mul_sum,ih,mul_one,hw,Finset.prod_const_one] + +lemma treeDraw_product {d r : ℕ} (w : ι → ℝ) (x : (Fin d → ι) → ℝ) (T : PartitionTree d r) : + (∑ s : TreeDraw ι T,treeDrawWeight w T s*∏ j,x (treeDrawPath T s j))=treeMarkMoment w x T := by + induction d generalizing r with + | zero => + change (∑ _ : PUnit.{u+1},(1:ℝ)*∏ _ : Fin r,x (fun i => Fin.elim0 i))=x (fun i => Fin.elim0 i)^r + simp + | succ d ih => + rcases T with ⟨P,T⟩ + change (∑ s : ∀ j,ι × TreeDraw ι (T j),(∏ j,w (s j).1*treeDrawWeight w (T j) (s j).2)* + ∏ k,x (treeDrawPath (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r) s k))=_ + have he (s : TreeDraw ι (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r)) : + (∏ k,x (treeDrawPath (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r) s k))= + ∏ j,∏ i,x (Fin.cons (s j).1 (treeDrawPath (T j) (s j).2 i)) := by + rw [← P.equivSigma.prod_comp,Fintype.prod_sigma] + change (∏ j,∏ i,x (treeDrawPath (d:=d+1) (⟨P,T⟩ : PartitionTree (d+1) r) s (P.emb j i)))=_ + simp only [treeDrawPath_emb] + simp_rw [he,← Finset.prod_mul_distrib,mul_assoc] + rw [← Fintype.prod_sum (fun j (s : ι × TreeDraw ι (T j)) => w s.1*(treeDrawWeight w (T j) s.2*∏ i,x (Fin.cons s.1 (treeDrawPath (T j) s.2 i))))] + change (∏ j,∑ si : ι × TreeDraw ι (T j),w si.1*(treeDrawWeight w (T j) si.2* + ∏ i,x (Fin.cons si.1 (treeDrawPath (T j) si.2 i))))=_ + simp only [Fintype.sum_prod_type,← Finset.mul_sum,treeMarkMoment] + apply Finset.prod_congr rfl + intro j _ + apply Finset.sum_congr rfl + intro i _ + congr 1 + exact ih (fun s => x (Fin.cons i s)) (T j) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal ContDiff +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +lemma hierarchy_numerator_mass_nz {d : ℕ} (a : Fin (d+1) → ℝ) (ha : ∀ k,a k≠0) + {n : ℕ} (hn : 0 1 + have hw : ∑ i,w i=1 := by simp [w] + have he : hierarchyLog w a (fun _ => 1)=ᶠ[𝓝 (0:ℝ)] (fun z => Real.log (1-z)) := by + filter_upwards [isOpen_Iio.mem_nhds (show (0:ℝ)<1 by norm_num)] with z hz + exact hierarchyLog_one w hw a ha hz + have hd := hierarchyLog_derivative w hw a ha (fun _ => 1) hn + rw [he.iteratedDeriv_eq n] at hd + have hf : iteratedDeriv n (fun z : ℝ => Real.log (1-z)) 0= -((n-1).factorial:ℝ) := by + have hh := log_power_affine_derivative (a:=1) (by norm_num) hn + simpa only [inv_one,Real.rpow_one,one_mul] using hh + rw [hf] at hd + simp only [hierarchyCoefficient,treeMarkMoment_one w hw,mul_one] at hd + linarith + +lemma continuous_hierarchyNumerator {d r : ℕ} (c : Fin (d+1) → Fin r → ℕ) : + Continuous (fun a : Fin (d+1) → ℝ => hierarchyNumerator a c) := by + unfold hierarchyNumerator edgeFactor leafFactor branchFactor blockFactor + fun_prop + +lemma hierarchy_numerator_mass {d : ℕ} (a : Fin (d+1) → ℝ) (ha : ∀ k,0≤a k) + {n : ℕ} (hn : 0 a k+1/(m+1:ℕ) + have hb : ∀ m k,b m k≠0 := by + intro m k + have hh : (0:ℝ)<1/(m+1:ℕ) := by positivity + exact ne_of_gt (add_pos_of_nonneg_of_pos (ha k) hh) + have hlim : Tendsto b atTop (𝓝 a) := by + apply tendsto_pi_nhds.mpr + intro k + simpa only [add_zero] using tendsto_const_nhds.add tendsto_succ_reciprocal + have hc : Continuous (fun a : Fin (d+1) → ℝ => ∑ T : PartitionTree (d+1) n, + hierarchyNumerator (Fin.cons 0 a) (treeCodes T)) := by + apply continuous_finsetSum + intro T _ + apply (continuous_hierarchyNumerator (treeCodes T)).comp + apply continuous_pi + intro k + induction k using Fin.cases with + | zero => exact continuous_const + | succ k => exact continuous_apply k + have h := hc.continuousAt.tendsto.comp hlim + have he : (fun m => ∑ T : PartitionTree (d+1) n,hierarchyNumerator (Fin.cons 0 (b m)) (treeCodes T))= + (fun _ : ℕ => ((n-1).factorial:ℝ)) := by + funext m + exact hierarchy_numerator_mass_nz (b m) (hb m) hn + simp only [Function.comp_def] at h + rw [he] at h + exact tendsto_nhds_unique h tendsto_const_nhds + +lemma hierarchy_partition_mass_all {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) {n : ℕ} (hn : 0 ENNReal.toReal_nonneg + have he : Fin.cons 0 (fun k : Fin (d+1) => overlapDiscount μ (q k.succ))=(fun k => overlapDiscount μ (q k)) := by + funext k + induction k using Fin.cases with + | zero => exact (overlapDiscount_below μ h0).symm + | succ k => rfl + have hh := hierarchy_numerator_mass (fun k : Fin (d+1) => overlapDiscount μ (q k.succ)) ha hn + rw [he] at hh + have ht (T : PartitionTree (d+1) n) : hierarchyNumerator (fun k => overlapDiscount μ (q k)) (treeCodes T)= + ((n-1).factorial:ℝ)*(μ:Measure OverlapArray).real (hierarchyEvent (treeCodes T) q) := + (GG_hierarchy_EPPF hG hgg hu hn (treeCodes T) (treeCodes_nested T) (fun i j => by simp) q hq h1).symm + simp_rw [ht] at hh + rw [← Finset.mul_sum] at hh + exact mul_left_cancel₀ (Nat.cast_ne_zero.mpr (Nat.factorial_ne_zero _)) (by simpa using hh) + +lemma hierarchy_partition_cover_all {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) + {d : ℕ} (q : Fin (d+2) → ℝ) (hq : Monotone q) (h0 : q 0 < -1) + (h1 : q (Fin.last (d+1))<1) {n : ℕ} (hn : 0 tree_hierarchy_disjoint hTU q) (fun T => hierarchyEvent_measurable (treeCodes T) q) + rw [hierarchy_partition_mass_all hG hgg hu q hq h0 h1 hn] at h + exact (ENNReal.toReal_eq_one_iff _).mp h + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +def NonnegativeArrays : Set OverlapArray := {R | ∀ i j,0≤(R i j:ℝ)} + +lemma isClosed_NonnegativeArrays : IsClosed NonnegativeArrays := by + unfold NonnegativeArrays + simp only [Set.ofPred_forall] + exact isClosed_iInter fun i => isClosed_iInter fun j => isClosed_le continuous_const (by fun_prop) + +lemma negative_pair_event_zero {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (_hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) + (i j : ℕ) {q : ℝ} (hq : q<0) : + (μ:Measure OverlapArray) {R | (R i j:ℝ)≤q}=0 := by + by_cases hij : i=j + · subst j + have h : ∀ᵐ R ∂(μ:Measure OverlapArray),¬(R i i:ℝ)≤q := by + filter_upwards [ae_full_probability μ isClosed_GramArrays.measurableSet hG] with R hR + rw [hR.2.1] + linarith + simpa only [not_not] using ae_iff.mp h + let e : Fin 2 → ℕ := ![i,j] + have he : Function.Injective e := by + intro a b hab + fin_cases a <;> fin_cases b <;> simp_all [e] + have hB : MeasurableSet {T : OverlapBlock 2 | (T 0 1:ℝ)≤q} := measurableSet_le (by fun_prop) measurable_const + have heq := exchangeable_event hex e he hB + change (μ:Measure OverlapArray) {R | (R i j:ℝ)≤q}=(μ:Measure OverlapArray) {R | (R 0 1:ℝ)≤q} at heq + rw [heq] + have hh := GG_negative_threshold_zero hG hgg hq + unfold Measure.real at hh + have hz : (entryLaw μ 0 1) {x | (x:ℝ)≤q}=0 := ((ENNReal.toReal_eq_zero_iff _).mp hh).resolve_right (measure_ne_top _ _) + unfold entryLaw at hz + rw [Measure.map_apply (by fun_prop) (measurableSet_le (by fun_prop) measurable_const)] at hz + exact hz + +theorem GG_nonnegative_arrays {μ : ProbabilityMeasure OverlapArray} + (hG : (μ:Measure OverlapArray) GramArrays=1) (hgg : GGIdentities μ) + (hu : (μ:Measure OverlapArray) UltrametricArrays=1) (hex : FiniteExchangeable μ) : + (μ:Measure OverlapArray) NonnegativeArrays=1 := by + have h (i j m : ℕ) : ∀ᵐ R ∂(μ:Measure OverlapArray), (-1:ℝ)/(m+1:ℕ)<(R i j:ℝ) := by + apply ae_iff.mpr + simp only [not_lt] + exact negative_pair_event_zero hG hgg hu hex i j (div_neg_of_neg_of_pos (by norm_num) (by positivity)) + have hh : ∀ᵐ R ∂(μ:Measure OverlapArray),R∈NonnegativeArrays := by + simp only [NonnegativeArrays,Set.mem_ofPred_eq] + apply ae_all_iff.mpr + intro i + apply ae_all_iff.mpr + intro j + filter_upwards [ae_all_iff.mpr (h i j)] with R hR + have ht : Tendsto (fun m : ℕ => (-1:ℝ)/(m+1:ℕ)) atTop (𝓝 (0:ℝ)) := by + simpa only [neg_div,neg_zero] using tendsto_succ_reciprocal.neg + exact le_of_tendsto ht (Filter.Eventually.of_forall fun m => (hR m).le) + have hz : (μ:Measure OverlapArray) NonnegativeArraysᶜ=0 := ae_iff.mp hh + rw [measure_compl isClosed_NonnegativeArrays.measurableSet (measure_ne_top _ _)] at hz + apply le_antisymm (by simpa only [measure_univ] using (measure_mono (Set.subset_univ NonnegativeArrays) : (μ:Measure OverlapArray) NonnegativeArrays≤(μ:Measure OverlapArray) Set.univ)) + exact tsub_eq_zero_iff_le.mp (by simpa only [measure_univ] using hz) + +end SKCavity + + + +open MeasureTheory ProbabilityTheory Filter TopologicalSpace +open scoped BigOperators Topology NNReal ENNReal +namespace SKCavity +open SKQAOA SKGaussian ParisiInterpolation + +abbrev CodeLabel {r : ℕ} (c : Fin r → ℕ) := {l : ℕ // l∈Finset.univ.image c} + +def codeGaussianCoeff {d r : ℕ} (c : Fin d → Fin r → ℕ) (v : Fin d → ℝ) + (i : Fin r) (k : Σ k : Fin d,CodeLabel (c k)) : ℝ := + if c k.1 i=k.2.val then Real.sqrt (v k.1) else 0 + +lemma kernel_codeGaussianCoeff {d r : ℕ} (c : Fin d → Fin r → ℕ) (v : Fin d → ℝ) + (hv : ∀ k,0≤v k) (i j : Fin r) : + kernel (codeGaussianCoeff c v) i j=∑ k,if c k i=c k j then v k else 0 := by + unfold kernel + rw [Fintype.sum_sigma] + apply Finset.sum_congr rfl + intro k _ + let l : CodeLabel (c k) := ⟨c k i,Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩⟩ + rw [Fintype.sum_eq_single l] + · dsimp [codeGaussianCoeff,l] + by_cases h : c k i=c k j + · simp [h,← pow_two,Real.sq_sqrt (hv k)] + · simp [h,Ne.symm h] + · intro t ht + have h : c k i≠t.val := by + intro he + apply ht + exact Subtype.ext he.symm + simp [codeGaussianCoeff,h] + +lemma codeKernel_nonneg {d r : ℕ} (c : Fin d → Fin r → ℕ) (v : Fin d → ℝ) + (hv : ∀ k,0≤v k) (i j : Fin r) : + 0≤∑ k,if c k i=c k j then v k else 0 := + Finset.sum_nonneg fun k _ => by split_ifs <;> simp_all + +lemma codeKernel_le_one {d r : ℕ} (c : Fin d → Fin r → ℕ) (v : Fin d → ℝ) + (hv : ∀ k,0≤v k) (hs : ∑ k,v k=1) (i j : Fin r) : + (∑ k,if c k i=c k j then v k else 0)≤1 := by + rw [← hs] + exact Finset.sum_le_sum fun k _ => by split_ifs <;> simp_all + +lemma kernel_quadratic_nonneg {r : ℕ} {κ : Type*} [Fintype κ] + (A : Fin r → κ → ℝ) (x : Fin r → ℝ) : + 0≤∑ i,∑ j,x i*x j*kernel A i j := by + have he : (∑ i,∑ j,x i*x j*kernel A i j)=(∑ k,(∑ i,x i*A i k)^2) := by + simp only [kernel,Finset.mul_sum,pow_two,Finset.sum_mul] + rw [Finset.sum_comm] + conv_lhs => arg 2; ext j; rw [Finset.sum_comm] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro k _ + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + rw [he] + exact Finset.sum_nonneg fun k _ => sq_nonneg _ + +def codeGramBlock {d r : ℕ} (c : Fin d → Fin r → ℕ) (v : Fin d → ℝ) + (hv : ∀ k,0≤v k) (hs : ∑ k,v k=1) : GramBlock r := by + let R : OverlapBlock r := fun i j => ⟨∑ k,if c k i=c k j then v k else 0, + ⟨(by linarith [codeKernel_nonneg c v hv i j]),codeKernel_le_one c v hv hs i j⟩⟩ + refine ⟨R,?_,?_,?_⟩ + · intro i j + apply Subtype.ext + change (∑ k,if c k i=c k j then v k else 0) = ∑ k,if c k j=c k i then v k else 0 + simp only [eq_comm] + · intro i + simpa [R] using hs + · intro x + have h := kernel_quadratic_nonneg (codeGaussianCoeff c v) x + simpa only [kernel_codeGaussianCoeff c v hv,R] using h + +lemma codeGramBlock_entry {d r : ℕ} (c : Fin d → Fin r → ℕ) (v : Fin d → ℝ) + (hv : ∀ k,0≤v k) (hs : ∑ k,v k=1) (i j : Fin r) : + ((codeGramBlock c v hv hs).val i j:ℝ)=∑ k,if c k i=c k j then v k else 0 := rfl + +lemma cavityGramObservable_lipschitz {r : ℕ} (hr : 0 + rw [oddEval_add,Y_add,Z_add] + exact ⟨(available s).add_mem hP.1 hQ.1,(available s).add_mem hP.2 hQ.2⟩ + | monomial k a => + obtain ⟨m,hm|hm⟩ := Nat.even_or_odd' k + · subst k + simp + · subst k + rw [oddEval_monomial_odd,Y_smul,Z_smul] + exact ⟨(available s).smul_mem a (Y_seed_mul_mem s _ (X_even_power_mem s m)), + (available s).smul_mem a (Z_seed_mul_mem s _ (X_even_power_mem s m))⟩ + + +theorem odd_continuous_mem (s : C(S,ℝ)) (f : C(ℝ,ℝ)) (hf : Function.Odd f) : + Y (f.comp s)∈available s ∧ Z (f.comp s)∈available s := by + let I := Set.Icc (-‖s‖) ‖s‖ + let η : C(S,I) := ⟨fun t => ⟨s t,⟨s.neg_norm_le_apply t,s.apply_le_norm t⟩⟩, + by fun_prop⟩ + let ν : C(S,I) := ⟨fun t => ⟨-s t,by + constructor <;> linarith [s.neg_norm_le_apply t,s.apply_le_norm t]⟩, + by fun_prop⟩ + let T (g : C(I,ℝ)) : C(S,ℝ) := (1/2:ℝ) • (g.comp η-g.comp ν) + have hT : Continuous T := by + change Continuous (fun g : C(I,ℝ) => (1/2:ℝ) • (g.comp η-g.comp ν)) + exact (continuous_const : Continuous (fun _ : C(I,ℝ) => (1/2:ℝ))).smul ((ContinuousMap.compRightAlgHom_continuous ℝ ℝ η).sub + (ContinuousMap.compRightAlgHom_continuous ℝ ℝ ν)) + have hz : IsClosed {g : C(I,ℝ) | Y (T g)∈available s ∧ Z (T g)∈available s} := + ((RawPulseControl.closed_directions (generator s) (generator_skew s)).preimage + (continuous_Y.comp hT)).inter + ((RawPulseControl.closed_directions (generator s) (generator_skew s)).preimage + (continuous_Z.comp hT)) + have hp : (polynomialFunctions I : Set C(I,ℝ)) ⊆ + {g : C(I,ℝ) | Y (T g)∈available s ∧ Z (T g)∈available s} := by + intro g hg + rw [polynomialFunctions_coe] at hg + obtain ⟨P,rfl⟩ := hg + have he : T (P.toContinuousMapOn I)=oddEval s P := by + ext t + simp [T,η,ν,oddEval,Polynomial.toContinuousMapOn,Polynomial.toContinuousMap] + change Y (T (P.toContinuousMapOn I))∈available s ∧ Z (T (P.toContinuousMapOn I))∈available s + rw [he] + exact odd_polynomial_mem s P + have ht : f.restrict I ∈ closure (polynomialFunctions I : Set C(I,ℝ)) := + continuousMap_mem_polynomialFunctions_closure (-‖s‖) ‖s‖ _ + have hh := closure_minimal hp hz ht + have he : T (f.restrict I)=f.comp s := by + ext t + change (1/2:ℝ)*(f (s t)-f (-s t))=f (s t) + rw [hf] + ring + change Y (T (f.restrict I))∈available s ∧ Z (T (f.restrict I))∈available s at hh + rwa [he] at hh + + +theorem odd_continuous_pulse_approximation (s : C(S,ℝ)) (f : C(ℝ,ℝ)) + (hf : Function.Odd f) (t : ℝ) {ε : ℝ} (hε : 0<ε) : + (∃w : List (Bool×ℝ),‖PulseControl.pulseValue (generator s) w- + NormedSpace.exp (t•Y (f.comp s))‖<ε) ∧ + (∃w : List (Bool×ℝ),‖PulseControl.pulseValue (generator s) w- + NormedSpace.exp (t•Z (f.comp s))‖<ε) := + ⟨RawPulseControl.approximate (generator s) (generator_skew s) (odd_continuous_mem s f hf).1 t hε, + RawPulseControl.approximate (generator s) (generator_skew s) (odd_continuous_mem s f hf).2 t hε⟩ + +end CompactSeedControl + + + +open scoped Topology +open Filter + +namespace CompactSeedControl +local instance yAddQuaternionNormedAlgebraRatOne : NormedAlgebra ℚ (Quaternion ℝ) := NormedAlgebra.restrictScalars ℚ ℝ (Quaternion ℝ) + +def axisX : Quaternion ℝ := ⟨0,0,0,1⟩ +def axisY : Quaternion ℝ := ⟨0,0,1,0⟩ +def axisZ : Quaternion ℝ := ⟨0,1,0,0⟩ + +theorem axisX_skew : axisX∈skewAdjoint (Quaternion ℝ) := by + rw [skewAdjoint.mem_iff] + exact Quaternion.star_eq_neg.mpr rfl +theorem axisY_skew : axisY∈skewAdjoint (Quaternion ℝ) := by + rw [skewAdjoint.mem_iff] + exact Quaternion.star_eq_neg.mpr rfl +theorem axisZ_skew : axisZ∈skewAdjoint (Quaternion ℝ) := by + rw [skewAdjoint.mem_iff] + exact Quaternion.star_eq_neg.mpr rfl + +def rawGenerator (r : ℝ) (a : Bool) : Quaternion ℝ := if a then r•axisZ else axisX + +theorem rawGenerator_skew (r : ℝ) (a : Bool) : rawGenerator r a∈skewAdjoint (Quaternion ℝ) := by + cases a + · exact axisX_skew + · exact skewAdjoint.smul_mem r axisZ_skew + +theorem rawGenerator_continuous (a : Bool) : Continuous (fun r => rawGenerator r a) := by + cases a + · exact continuous_const + · exact continuous_id.smul continuous_const + + +def localWord (w : List (Bool×ℝ)) (s : ℝ) : Quaternion ℝ := + PulseControl.pulseValue (rawGenerator s) w + +theorem localWord_unitary (w : List (Bool×ℝ)) (s : ℝ) : localWord w s∈unitary (Quaternion ℝ) := + RawPulseControl.words_unitary (rawGenerator s) (rawGenerator_skew s) ⟨w,rfl⟩ + +theorem localWord_continuous (w : List (Bool×ℝ)) : Continuous (localWord w) := by + induction w with + | nil => exact continuous_const + | cons p w ih => + change Continuous (fun r => NormedSpace.exp (p.2 • rawGenerator r p.1)*localWord w r) + exact (NormedSpace.exp_continuous.comp + ((continuous_const : Continuous (fun _ : ℝ => p.2)).smul (rawGenerator_continuous p.1))).mul ih + +section Compact +variable {S : Type*} [TopologicalSpace S] [CompactSpace S] [Nonempty S] +local instance yAddCompactSpinFieldNormedAlgebraRat : NormedAlgebra ℚ (SpinField S) := NormedAlgebra.restrictScalars ℚ ℝ (SpinField S) + +def fieldEval (s : S) : SpinField S →+* Quaternion ℝ where + toFun f := f s + map_zero' := rfl + map_one' := rfl + map_add' _ _ := rfl + map_mul' _ _ := rfl + +omit [CompactSpace S] [Nonempty S] in +theorem fieldEval_continuous (s : S) : Continuous (fieldEval s) := by + exact continuous_eval_const s + +omit [Nonempty S] in +@[simp] theorem field_exp_apply (f : SpinField S) (s : S) : + (NormedSpace.exp f) s=NormedSpace.exp (f s) := + NormedSpace.map_exp (fieldEval s) (fieldEval_continuous s) f + +omit [Nonempty S] in +@[simp] theorem field_pulse_apply (s : C(S,ℝ)) (w : List (Bool×ℝ)) (r : S) : + PulseControl.pulseValue (generator s) w r=localWord w (s r) := by + induction w with + | nil => rfl + | cons p w ih => + change (NormedSpace.exp (p.2 • generator s p.1)) r * + PulseControl.pulseValue (generator s) w r = + NormedSpace.exp (p.2 • rawGenerator (s r) p.1)*localWord w (s r) + rw [field_exp_apply,ih] + congr 2 + cases p.1 <;> simp only [generator,rawGenerator,ContinuousMap.smul_apply] + · change p.2 • ((1:ℝ)•axisX)=p.2•axisX + rw [one_smul] + · rfl + +end Compact + + + +theorem even_localWord_compact (f : C(ℝ,ℝ)) (hf : Function.Even f) (t R : ℝ) + (hR : 0≤R) {ε : ℝ} (hε : 0<ε) : + ∃w : List (Bool×ℝ),∀r : ℝ,|r|≤R → + ‖localWord w r-NormedSpace.exp ((t*f r)•axisX)‖<ε := by + let I := Set.Icc (-R) R + let : Nonempty I := ⟨⟨0,by constructor <;> linarith⟩⟩ + let s : C(I,ℝ) := ⟨Subtype.val,continuous_subtype_val⟩ + obtain ⟨w,hw⟩ := even_continuous_pulse_approximation s f hf t hε + refine ⟨w,fun r hr => ?_⟩ + have hi : r∈I := abs_le.mp hr + have he := (ContinuousMap.norm_lt_iff _ hε).mp hw ⟨r,hi⟩ + simp only [ContinuousMap.sub_apply,field_pulse_apply,field_exp_apply,ContinuousMap.smul_apply] at he + change ‖localWord w r-NormedSpace.exp (t•(f r•axisX))‖<ε at he + simpa only [smul_smul] using he + + +theorem odd_localWord_compact (f : C(ℝ,ℝ)) (hf : Function.Odd f) (t R : ℝ) + (hR : 0≤R) {ε : ℝ} (hε : 0<ε) : + (∃w : List (Bool×ℝ),∀r : ℝ,|r|≤R → + ‖localWord w r-NormedSpace.exp ((t*f r)•axisY)‖<ε) ∧ + (∃w : List (Bool×ℝ),∀r : ℝ,|r|≤R → + ‖localWord w r-NormedSpace.exp ((t*f r)•axisZ)‖<ε) := by + let I := Set.Icc (-R) R + let : Nonempty I := ⟨⟨0,by constructor <;> linarith⟩⟩ + let s : C(I,ℝ) := ⟨Subtype.val,continuous_subtype_val⟩ + obtain ⟨⟨u,hu⟩,⟨v,hv⟩⟩ := odd_continuous_pulse_approximation s f hf t hε + constructor + · refine ⟨u,fun r hr => ?_⟩ + have hi : r∈I := abs_le.mp hr + have he := (ContinuousMap.norm_lt_iff _ hε).mp hu ⟨r,hi⟩ + simp only [ContinuousMap.sub_apply,field_pulse_apply,field_exp_apply,ContinuousMap.smul_apply] at he + change ‖localWord u r-NormedSpace.exp (t•(f r•axisY))‖<ε at he + simpa only [smul_smul] using he + · refine ⟨v,fun r hr => ?_⟩ + have hi : r∈I := abs_le.mp hr + have he := (ContinuousMap.norm_lt_iff _ hε).mp hv ⟨r,hi⟩ + simp only [ContinuousMap.sub_apply,field_pulse_apply,field_exp_apply,ContinuousMap.smul_apply] at he + change ‖localWord v r-NormedSpace.exp (t•(f r•axisZ))‖<ε at he + simpa only [smul_smul] using he + +end CompactSeedControl + + + +open scoped Topology +open Filter MeasureTheory + +namespace CompactSeedControl +local instance yAddQuaternionNormedAlgebraRatTwo : NormedAlgebra ℚ (Quaternion ℝ) := NormedAlgebra.restrictScalars ℚ ℝ (Quaternion ℝ) + + + +theorem localWord_sequence {g : ℝ → Quaternion ℝ} + (hg : ∀R : ℝ,0≤R → ∀ε : ℝ,0<ε → ∃w : List (Bool×ℝ), + ∀r : ℝ,|r|≤R → ‖localWord w r-g r‖<ε) : + ∃w : ℕ → List (Bool×ℝ),∀r : ℝ,Tendsto (fun n => localWord (w n) r) atTop (𝓝 (g r)) := by + have he (n : ℕ) : 0<(1:ℝ)/((n:ℝ)+1) := by positivity + choose w hw using fun n : ℕ => hg n (Nat.cast_nonneg n) (1/(n+1)) (he n) + refine ⟨w,fun r => ?_⟩ + apply tendsto_iff_norm_sub_tendsto_zero.mpr + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) + · have hn : ∀ᶠ n : ℕ in atTop,|r|≤(n:ℝ) := + (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop).eventually + (eventually_ge_atTop |r|) + exact hn.mono fun n hn => le_of_lt (hw n r hn) + · exact tendsto_one_div_add_atTop_nhds_zero_nat + + + +theorem localWord_weighted_L2 {g : ℝ → Quaternion ℝ} (hg : Continuous g) + (hgu : ∀r,g r∈unitary (Quaternion ℝ)) (w : ℕ → List (Bool×ℝ)) + (hw : ∀r,Tendsto (fun n => localWord (w n) r) atTop (𝓝 (g r))) + (μ : Measure ℝ) (ρ : ℝ → ℝ) (hρ : Integrable ρ μ) : + Tendsto (fun n => ∫r,|ρ r| *‖localWord (w n) r-g r‖^2 ∂μ) atTop (𝓝 0) := by + have hd (n : ℕ) (r : ℝ) : ‖localWord (w n) r-g r‖≤2 := by + calc + ‖localWord (w n) r-g r‖≤‖localWord (w n) r‖+‖g r‖ := norm_sub_le _ _ + _=2 := by rw [CStarRing.norm_of_mem_unitary (localWord_unitary _ _), + CStarRing.norm_of_mem_unitary (hgu _)]; norm_num + have ht := tendsto_integral_of_dominated_convergence + (F:=fun n r => |ρ r| *‖localWord (w n) r-g r‖^2) (f:=fun _ => (0:ℝ)) + (fun r => 4*|ρ r|) + (fun n => hρ.abs.aestronglyMeasurable.mul + (((localWord_continuous (w n)).sub hg).norm.pow 2).aestronglyMeasurable) + (hρ.abs.const_mul 4) ?_ ?_ + · simpa only [integral_zero] using ht + · intro n + exact Eventually.of_forall fun r => by + rw [Real.norm_eq_abs,abs_of_nonneg (mul_nonneg (abs_nonneg _) (sq_nonneg _))] + have hb := hd n r + have hn := norm_nonneg (localWord (w n) r-g r) + have hs : ‖localWord (w n) r-g r‖^2≤4 := by nlinarith + nlinarith [mul_le_mul_of_nonneg_left hs (abs_nonneg (ρ r))] + · exact Eventually.of_forall fun r => by + have hl := (hw r).sub (tendsto_const_nhds (x:=g r)) + have hl' := ((hl.norm).pow 2).const_mul |ρ r| + simpa using hl' + + + +theorem even_localWord_moment (f : C(ℝ,ℝ)) (hf : Function.Even f) (t : ℝ) : + ∃w : ℕ → List (Bool×ℝ), + (∀r,Tendsto (fun n => localWord (w n) r) atTop + (𝓝 (NormedSpace.exp ((t*f r)•axisX)))) ∧ + (∀(μ : Measure ℝ) (ρ : ℝ → ℝ),Integrable ρ μ → + Tendsto (fun n => ∫r,|ρ r| *‖localWord (w n) r- + NormedSpace.exp ((t*f r)•axisX)‖^2 ∂μ) atTop (𝓝 0)) := by + obtain ⟨w,hw⟩ := localWord_sequence (fun R hR ε hε => even_localWord_compact f hf t R hR hε) + refine ⟨w,hw,fun μ ρ hρ => localWord_weighted_L2 ?_ ?_ w hw μ ρ hρ⟩ + · exact NormedSpace.exp_continuous.comp ((continuous_const.mul f.continuous).smul continuous_const) + · intro r + exact NormedSpace.exp_mem_unitary_of_mem_skewAdjoint (skewAdjoint.smul_mem _ axisX_skew) + + + +theorem odd_localWord_moment (f : C(ℝ,ℝ)) (hf : Function.Odd f) (t : ℝ) : + ∀a∈({axisY,axisZ} : Set (Quaternion ℝ)), + ∃w : ℕ → List (Bool×ℝ), + (∀r,Tendsto (fun n => localWord (w n) r) atTop + (𝓝 (NormedSpace.exp ((t*f r)•a)))) ∧ + (∀(μ : Measure ℝ) (ρ : ℝ → ℝ),Integrable ρ μ → + Tendsto (fun n => ∫r,|ρ r| *‖localWord (w n) r- + NormedSpace.exp ((t*f r)•a)‖^2 ∂μ) atTop (𝓝 0)) := by + intro a ha + have hs : a∈skewAdjoint (Quaternion ℝ) := by + rcases ha with rfl | ha + · exact axisY_skew + · have : a=axisZ := ha + subst a + exact axisZ_skew + have hc : ∀R : ℝ,0≤R → ∀ε : ℝ,0<ε → ∃w : List (Bool×ℝ), + ∀r : ℝ,|r|≤R → ‖localWord w r-NormedSpace.exp ((t*f r)•a)‖<ε := by + intro R hR ε hε + rcases ha with rfl | ha + · exact (odd_localWord_compact f hf t R hR hε).1 + · have : a=axisZ := ha + subst a + exact (odd_localWord_compact f hf t R hR hε).2 + obtain ⟨w,hw⟩ := localWord_sequence hc + refine ⟨w,hw,fun μ ρ hρ => localWord_weighted_L2 ?_ ?_ w hw μ ρ hρ⟩ + · exact NormedSpace.exp_continuous.comp ((continuous_const.mul f.continuous).smul continuous_const) + · intro r + exact NormedSpace.exp_mem_unitary_of_mem_skewAdjoint (skewAdjoint.smul_mem _ hs) + +end CompactSeedControl + + + +open scoped Topology ENNReal +open Filter MeasureTheory + +namespace CompactSeedControl + + + +theorem continuous_sequence_ae (μ : Measure ℝ) [μ.WeaklyRegular] + {f : ℝ → ℝ} (hf : MemLp f 1 μ) : + ∃g : ℕ → C(ℝ,ℝ),∀ᵐ r ∂μ,Tendsto (fun n => g n r) atTop (𝓝 (f r)) := by + have he (n : ℕ) : ENNReal.ofReal ((1:ℝ)/(n+1))≠0 := + ne_of_gt (ENNReal.ofReal_pos.mpr (by positivity)) + choose g hg hm using fun n : ℕ => hf.exists_boundedContinuous_eLpNorm_sub_le + ENNReal.one_ne_top (he n) + have ht : Tendsto (fun n => eLpNorm ((g n : ℝ → ℝ)-f) 1 μ) atTop (𝓝 0) := by + have ht0 : Tendsto (fun n : ℕ => ENNReal.ofReal ((1:ℝ)/(n+1))) atTop (𝓝 0) := by + simpa only [Function.comp_def,ENNReal.ofReal_zero] using + (ENNReal.tendsto_ofReal tendsto_one_div_add_atTop_nhds_zero_nat) + apply tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds ht0 + (fun _ => bot_le) + intro n + simpa only [eLpNorm_sub_comm] using hg n + obtain ⟨u,hu,hu'⟩ := (tendstoInMeasure_of_tendsto_eLpNorm + (by norm_num : (1:ℝ≥0∞)≠0) ht).exists_seq_tendsto_ae + exact ⟨fun n => (g (u n)).toContinuousMap,hu'⟩ + + + +theorem even_continuous_sequence_ae (μ : Measure ℝ) [μ.WeaklyRegular] + (hμ : MeasurePreserving (fun r : ℝ => -r) μ μ) + {f : ℝ → ℝ} (hf : MemLp f 1 μ) (he : Function.Even f) : + ∃g : ℕ → C(ℝ,ℝ),(∀n,Function.Even (g n)) ∧ + ∀ᵐ r ∂μ,Tendsto (fun n => g n r) atTop (𝓝 (f r)) := by + obtain ⟨g,hg⟩ := continuous_sequence_ae μ hf + let b (n : ℕ) : C(ℝ,ℝ) := ⟨fun r => (g n r+g n (-r))/2,by fun_prop⟩ + refine ⟨b,fun n r => ?_,?_⟩ + · change (g n (-r)+g n (-(-r)))/2=(g n r+g n (-r))/2 + simp only [neg_neg] + ring + · have hgn := hμ.quasiMeasurePreserving.ae hg + filter_upwards [hg,hgn] with r hr hnr + have ht := (hr.add hnr).div_const 2 + rw [he r,add_self_div_two] at ht + exact ht + +theorem odd_continuous_sequence_ae (μ : Measure ℝ) [μ.WeaklyRegular] + (hμ : MeasurePreserving (fun r : ℝ => -r) μ μ) + {f : ℝ → ℝ} (hf : MemLp f 1 μ) (he : Function.Odd f) : + ∃g : ℕ → C(ℝ,ℝ),(∀n,Function.Odd (g n)) ∧ + ∀ᵐ r ∂μ,Tendsto (fun n => g n r) atTop (𝓝 (f r)) := by + obtain ⟨g,hg⟩ := continuous_sequence_ae μ hf + let b (n : ℕ) : C(ℝ,ℝ) := ⟨fun r => (g n r-g n (-r))/2,by fun_prop⟩ + refine ⟨b,fun n r => ?_,?_⟩ + · change (g n (-r)-g n (-(-r)))/2= -((g n r-g n (-r))/2) + simp only [neg_neg] + ring + · have hgn := hμ.quasiMeasurePreserving.ae hg + filter_upwards [hg,hgn] with r hr hnr + have ht := (hr.sub hnr).div_const 2 + rw [he r,sub_neg_eq_add,add_self_div_two] at ht + exact ht + +end CompactSeedControl + + + +open scoped Topology +open Filter MeasureTheory + +namespace CompactSeedControl +local instance yAddQuaternionNormedAlgebraRatThree : NormedAlgebra ℚ (Quaternion ℝ) := NormedAlgebra.restrictScalars ℚ ℝ (Quaternion ℝ) + + + +theorem localWord_diagonal {g : ℕ → ℝ → Quaternion ℝ} + (hg : ∀n : ℕ,∀R : ℝ,0≤R → ∀ε : ℝ,0<ε → ∃w : List (Bool×ℝ), + ∀r : ℝ,|r|≤R → ‖localWord w r-g n r‖<ε) : + ∃w : ℕ → List (Bool×ℝ),∀r : ℝ, + Tendsto (fun n => localWord (w n) r-g n r) atTop (𝓝 0) := by + have he (n : ℕ) : 0<(1:ℝ)/((n:ℝ)+1) := by positivity + choose w hw using fun n : ℕ => hg n n (Nat.cast_nonneg n) (1/(n+1)) (he n) + refine ⟨w,fun r => ?_⟩ + apply tendsto_zero_iff_norm_tendsto_zero.mpr + apply squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) + · have hn : ∀ᶠ n : ℕ in atTop,|r|≤(n:ℝ) := + (tendsto_natCast_atTop_atTop : Tendsto (fun n : ℕ => (n:ℝ)) atTop atTop).eventually + (eventually_ge_atTop |r|) + exact hn.mono fun n hn => le_of_lt (hw n r hn) + · exact tendsto_one_div_add_atTop_nhds_zero_nat + + + +theorem localWord_weighted_L2_ae {g : ℝ → Quaternion ℝ} (μ : Measure ℝ) + (hg : AEStronglyMeasurable g μ) (hgu : ∀r,g r∈unitary (Quaternion ℝ)) + (w : ℕ → List (Bool×ℝ)) + (hw : ∀ᵐ r ∂μ,Tendsto (fun n => localWord (w n) r) atTop (𝓝 (g r))) + (ρ : ℝ → ℝ) (hρ : Integrable ρ μ) : + Tendsto (fun n => ∫r,|ρ r| *‖localWord (w n) r-g r‖^2 ∂μ) atTop (𝓝 0) := by + have hd (n : ℕ) (r : ℝ) : ‖localWord (w n) r-g r‖≤2 := by + calc + ‖localWord (w n) r-g r‖≤‖localWord (w n) r‖+‖g r‖ := norm_sub_le _ _ + _=2 := by rw [CStarRing.norm_of_mem_unitary (localWord_unitary _ _), + CStarRing.norm_of_mem_unitary (hgu _)]; norm_num + have ht := tendsto_integral_of_dominated_convergence + (F:=fun n r => |ρ r| *‖localWord (w n) r-g r‖^2) (f:=fun _ => (0:ℝ)) + (fun r => 4*|ρ r|) + (fun n => hρ.abs.aestronglyMeasurable.mul + ((((localWord_continuous (w n)).aestronglyMeasurable.sub hg).norm).pow 2)) + (hρ.abs.const_mul 4) ?_ ?_ + · simpa only [integral_zero] using ht + · intro n + exact Eventually.of_forall fun r => by + rw [Real.norm_eq_abs,abs_of_nonneg (mul_nonneg (abs_nonneg _) (sq_nonneg _))] + have hb := hd n r + have hn := norm_nonneg (localWord (w n) r-g r) + have hs : ‖localWord (w n) r-g r‖^2≤4 := by nlinarith + nlinarith [mul_le_mul_of_nonneg_left hs (abs_nonneg (ρ r))] + · filter_upwards [hw] with r hr + have hl := hr.sub (tendsto_const_nhds (x:=g r)) + have hl' := ((hl.norm).pow 2).const_mul |ρ r| + simpa using hl' + + + +theorem even_measurable_localWord (μ : Measure ℝ) [μ.WeaklyRegular] + (hμ : MeasurePreserving (fun r : ℝ => -r) μ μ) + {f : ℝ → ℝ} (hf : MemLp f 1 μ) (he : Function.Even f) (t : ℝ) : + ∃w : ℕ → List (Bool×ℝ), + (∀ᵐ r ∂μ,Tendsto (fun n => localWord (w n) r) atTop + (𝓝 (NormedSpace.exp ((t*f r)•axisX)))) ∧ + (∀ρ : ℝ → ℝ,Integrable ρ μ → + Tendsto (fun n => ∫r,|ρ r| *‖localWord (w n) r- + NormedSpace.exp ((t*f r)•axisX)‖^2 ∂μ) atTop (𝓝 0)) := by + obtain ⟨g,hge,hg⟩ := even_continuous_sequence_ae μ hμ hf he + obtain ⟨w,hw⟩ := localWord_diagonal (fun n R hR ε hε => + even_localWord_compact (g n) (hge n) t R hR hε) + have ha : ∀ᵐ r ∂μ,Tendsto (fun n => localWord (w n) r) atTop + (𝓝 (NormedSpace.exp ((t*f r)•axisX))) := by + filter_upwards [hg] with r hr + have ht := NormedSpace.exp_continuous.continuousAt.tendsto.comp + ((hr.const_mul t).smul_const axisX) + simpa only [Function.comp_def,sub_add_cancel,zero_add] using (hw r).add ht + refine ⟨w,ha,fun ρ hρ => localWord_weighted_L2_ae μ ?_ ?_ w ha ρ hρ⟩ + · exact NormedSpace.exp_continuous.comp_aestronglyMeasurable + ((hf.aestronglyMeasurable.const_mul t).smul_const axisX) + · intro r + exact NormedSpace.exp_mem_unitary_of_mem_skewAdjoint (skewAdjoint.smul_mem _ axisX_skew) + + + +theorem odd_measurable_localWord (μ : Measure ℝ) [μ.WeaklyRegular] + (hμ : MeasurePreserving (fun r : ℝ => -r) μ μ) + {f : ℝ → ℝ} (hf : MemLp f 1 μ) (he : Function.Odd f) (t : ℝ) : + ∀a∈({axisY,axisZ} : Set (Quaternion ℝ)), + ∃w : ℕ → List (Bool×ℝ), + (∀ᵐ r ∂μ,Tendsto (fun n => localWord (w n) r) atTop + (𝓝 (NormedSpace.exp ((t*f r)•a)))) ∧ + (∀ρ : ℝ → ℝ,Integrable ρ μ → + Tendsto (fun n => ∫r,|ρ r| *‖localWord (w n) r- + NormedSpace.exp ((t*f r)•a)‖^2 ∂μ) atTop (𝓝 0)) := by + intro a ha + have hs : a∈skewAdjoint (Quaternion ℝ) := by + rcases ha with rfl | ha + · exact axisY_skew + · have : a=axisZ := ha + subst a + exact axisZ_skew + obtain ⟨g,hge,hg⟩ := odd_continuous_sequence_ae μ hμ hf he + have hgc : ∀n : ℕ,∀R : ℝ,0≤R → ∀ε : ℝ,0<ε → ∃w : List (Bool×ℝ), + ∀r : ℝ,|r|≤R → ‖localWord w r-NormedSpace.exp ((t*g n r)•a)‖<ε := by + intro n R hR ε hε + rcases ha with rfl | ha + · exact (odd_localWord_compact (g n) (hge n) t R hR hε).1 + · have : a=axisZ := ha + subst a + exact (odd_localWord_compact (g n) (hge n) t R hR hε).2 + obtain ⟨w,hw⟩ := localWord_diagonal hgc + have ha : ∀ᵐ r ∂μ,Tendsto (fun n => localWord (w n) r) atTop + (𝓝 (NormedSpace.exp ((t*f r)•a))) := by + filter_upwards [hg] with r hr + have ht := NormedSpace.exp_continuous.continuousAt.tendsto.comp + ((hr.const_mul t).smul_const a) + simpa only [Function.comp_def,sub_add_cancel,zero_add] using (hw r).add ht + refine ⟨w,ha,fun ρ hρ => localWord_weighted_L2_ae μ ?_ ?_ w ha ρ hρ⟩ + · exact NormedSpace.exp_continuous.comp_aestronglyMeasurable + ((hf.aestronglyMeasurable.const_mul t).smul_const a) + · intro r + exact NormedSpace.exp_mem_unitary_of_mem_skewAdjoint (skewAdjoint.smul_mem _ hs) + +end CompactSeedControl + + + +open scoped BigOperators Matrix Topology Matrix.Norms.Operator + +namespace MaskSign +variable {C : Type*} [Fintype C] [DecidableEq C] + +def sign (ε : C → Bool) (a : C) : ℂ := if ε a then -1 else 1 + +omit [Fintype C] [DecidableEq C] in +@[simp] theorem sign_sq (ε : C → Bool) (a : C) : sign ε a*sign ε a=1 := by + cases h : ε a <;> simp [sign,h] + +def flipEquiv (a : C) : (C → Bool) ≃ (C → Bool) where + toFun ε := Function.update ε a (!(ε a)) + invFun ε := Function.update ε a (!(ε a)) + left_inv ε := by funext b; by_cases h : b=a <;> simp [h,Function.update] + right_inv ε := by funext b; by_cases h : b=a <;> simp [h,Function.update] + +omit [Fintype C] in +@[simp] theorem sign_flip_same (ε : C → Bool) (a : C) : + sign (flipEquiv a ε) a= -sign ε a := by + cases h : ε a <;> simp [sign,flipEquiv,h] + +omit [Fintype C] in +@[simp] theorem sign_flip_ne (ε : C → Bool) (a b : C) (h : b≠a) : + sign (flipEquiv a ε) b=sign ε b := by + simp [sign,flipEquiv,Function.update_of_ne h] + + +theorem sum_character (S : Finset C) : + (∑ε : C → Bool,∏a∈S,sign ε a)=if S=∅ then (2:ℂ)^(Fintype.card C) else 0 := by + by_cases hs : S=∅ + · subst S + simp + · obtain ⟨a,ha⟩ := Finset.nonempty_iff_ne_empty.mpr hs + have hf (ε : C → Bool) : + (∏b∈S,sign (flipEquiv a ε) b)= -(∏b∈S,sign ε b) := by + rw [←Finset.mul_prod_erase S _ ha,←Finset.mul_prod_erase S _ ha,sign_flip_same] + have he : (∏b∈S.erase a,sign (flipEquiv a ε) b)=∏b∈S.erase a,sign ε b := by + apply Finset.prod_congr rfl + intro b hb + exact sign_flip_ne _ _ _ (Finset.ne_of_mem_erase hb) + rw [he,neg_mul] + have he := Equiv.sum_comp (flipEquiv a) (fun ε => ∏b∈S,sign ε b) + simp_rw [hf,Finset.sum_neg_distrib] at he + rw [ite_eq_right hs] + have : (2:ℂ)*(∑ε : C → Bool,∏b∈S,sign ε b)=0 := by linear_combination -he + exact (mul_eq_zero.mp this).resolve_left (by norm_num) + + +theorem sum_two {a b : C} (h : a≠b) : (∑ε : C → Bool,sign ε a*sign ε b)=0 := by + simpa [Finset.prod_pair h] using sum_character ({a,b} : Finset C) + +theorem sum_flip_zero (a : C) (f : (C → Bool) → ℂ) + (hf : ∀ε,f (flipEquiv a ε)= -f ε) : (∑ε,f ε)=0 := by + have he := Equiv.sum_comp (flipEquiv a) f + simp_rw [hf,Finset.sum_neg_distrib] at he + have : (2:ℂ)*(∑ε,f ε)=0 := by linear_combination -he + exact (mul_eq_zero.mp this).resolve_left (by norm_num) + + + +theorem sum_four {a b : C} (hab : a≠b) (c d : C) : + (∑ε : C → Bool,sign ε a*sign ε b*sign ε c*sign ε d)= + if (a=c ∧ b=d) ∨ (a=d ∧ b=c) then (2:ℂ)^(Fintype.card C) else 0 := by + by_cases hac : a=c + · subst c + have he (ε : C → Bool) : sign ε a*sign ε b*sign ε a*sign ε d=sign ε b*sign ε d := by + calc + _=(sign ε a*sign ε a)*(sign ε b*sign ε d) := by ring + _=_ := by rw [sign_sq,one_mul] + simp_rw [he] + by_cases hbd : b=d + · subst d + simp [sign_sq,hab] + · rw [sum_two hbd] + simp [hbd,Ne.symm hab] + · by_cases had : a=d + · subst d + have he (ε : C → Bool) : sign ε a*sign ε b*sign ε c*sign ε a=sign ε b*sign ε c := by + calc + _=(sign ε a*sign ε a)*(sign ε b*sign ε c) := by ring + _=_ := by rw [sign_sq,one_mul] + simp_rw [he] + by_cases hbc : b=c + · subst c + simp [sign_sq,hab] + · rw [sum_two hbc] + simp [hac,hbc] + · rw [ite_eq_right (by simp [hac,had])] + apply sum_flip_zero a + intro ε + rw [sign_flip_same,sign_flip_ne ε a b (Ne.symm hab), + sign_flip_ne ε a c (Ne.symm hac),sign_flip_ne ε a d (Ne.symm had)] + ring + +end MaskSign + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Brownian/CavityGaussianFields.lean b/lean/OAI/Probability/Perceptron/Brownian/CavityGaussianFields.lean new file mode 100644 index 0000000000000000000000000000000000000000..45c1660ca2a8392ca63abba301709138bad1427f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Brownian/CavityGaussianFields.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereHeat +import OAI.Probability.Perceptron.Cavity.CavityGaussianQuadratic + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +lemma gaussian_inner_preserving (L : ℕ) (z : Spin L) : + MeasurePreserving (fun y : Spin L=>inner ℝ z y) (stdGaussian (Spin L)) + (gaussianReal 0 (‖z‖₊^2)) := by + refine ⟨by fun_prop,?_⟩ + have h := IsGaussian.map_eq_gaussianReal (μ:=stdGaussian (Spin L)) (innerSL ℝ z) + simp only [integral_strongDual_stdGaussian,variance_dual_stdGaussian,innerSL_apply_norm] at h + have he : (‖z‖^2).toNNReal = (‖z‖₊^2) := by + ext; simp + simpa only [he,coe_innerSL_apply] using h + +lemma gaussian_cavity_projection (M L : ℕ) (z : Spin L) : + MeasurePreserving (fun y : Fin M→Spin L=>fun i=>inner ℝ z (y i)) + (Measure.pi (fun _=>stdGaussian (Spin L))) + (Measure.pi (fun _ : Fin M=>gaussianReal 0 (‖z‖₊^2))) := by + have (_index : Fin M) : SigmaFinite (gaussianReal 0 (‖z‖₊^2)) := inferInstance + exact measurePreserving_pi _ _ (fun _=>gaussian_inner_preserving L z) + +def cavityQuadraticField (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) (y : Fin M→Spin L) : ℝ := + t*∑ i,a i*((inner ℝ z (y i))^2-‖z‖^2) + +lemma cavityQuadraticField_memLp (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) : + MemLp (cavityQuadraticField M L a t z) 2 (Measure.pi (fun _=>stdGaussian (Spin L))) := by + have h := (cavityQuadraticScalar_memLp M a t (‖z‖₊^2)).comp_measurePreserving + (gaussian_cavity_projection M L z) + change MemLp (fun y : Fin M→Spin L=>t*∑ i,a i*((inner ℝ z (y i))^2-‖z‖^2)) 2 _ + simpa only [Function.comp_def,cavityQuadraticScalar,NNReal.coe_pow,coe_nnnorm] using h + +lemma cavityQuadraticField_second_moment (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) : + (∫ y,(cavityQuadraticField M L a t z y)^2 ∂Measure.pi (fun _=>stdGaussian (Spin L)))= + t^2*‖z‖^4*squareGaussianVariance*∑ i,(a i)^2 := by + have hm := gaussian_cavity_projection M L z + have he := (integral_map hm.aemeasurable (f:=fun y=>(cavityQuadraticScalar M a t (‖z‖₊^2) y)^2) (show AEStronglyMeasurable (fun y : Fin M→ℝ=>(cavityQuadraticScalar M a t (‖z‖₊^2) y)^2) _ from (show Continuous (fun y : Fin M→ℝ=>(cavityQuadraticScalar M a t (‖z‖₊^2) y)^2) from by unfold cavityQuadraticScalar; fun_prop).aestronglyMeasurable)).symm + rw [hm.map_eq] at he + rw [cavityQuadraticScalar_second_moment] at he + simp only [cavityQuadraticScalar,NNReal.coe_pow,coe_nnnorm] at he + calc + _ = ∫ y : Fin M→Spin L,(t*∑ i,a i*((inner ℝ z (y i))^2-‖z‖^2))^2 ∂Measure.pi (fun _=>stdGaussian (Spin L)) := rfl + _ = _ := he + _ = t^2*‖z‖^4*squareGaussianVariance*∑ i,(a i)^2 := by ring + +lemma cavityQuadraticField_second_bound (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) + {C D : ℝ} (hC : 0≤C) (_hD : 0≤D) (ha : ∀ i,|a i|≤C) (hz : ‖z‖^2≤D) : + (∫ y,(cavityQuadraticField M L a t z y)^2 ∂Measure.pi (fun _=>stdGaussian (Spin L)))≤ + t^2*D^2*squareGaussianVariance*M*C^2 := by + have hm := gaussian_cavity_projection M L z + have he := (integral_map hm.aemeasurable (f:=fun y=>(cavityQuadraticScalar M a t (‖z‖₊^2) y)^2) (show AEStronglyMeasurable (fun y : Fin M→ℝ=>(cavityQuadraticScalar M a t (‖z‖₊^2) y)^2) _ from (show Continuous (fun y : Fin M→ℝ=>(cavityQuadraticScalar M a t (‖z‖₊^2) y)^2) from by unfold cavityQuadraticScalar; fun_prop).aestronglyMeasurable)).symm + rw [hm.map_eq] at he + have hf : (fun y : Fin M→Spin L=>(cavityQuadraticScalar M a t (‖z‖₊^2) (fun i=>inner ℝ z (y i)))^2)= + (fun y=>(cavityQuadraticField M L a t z y)^2) := by + ext y; simp only [cavityQuadraticScalar,cavityQuadraticField,NNReal.coe_pow,coe_nnnorm] + rw [hf] at he + rw [he] + apply (cavityQuadraticScalar_second_moment_bound M a t (‖z‖₊^2) hC ha).trans + apply mul_le_mul_of_nonneg_right _ (sq_nonneg C) + apply mul_le_mul_of_nonneg_right _ (Nat.cast_nonneg M) + apply mul_le_mul_of_nonneg_right _ squareGaussianVariance_nonneg + exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (sq_nonneg ‖z‖) hz 2) (sq_nonneg t) + +def cavityLinearField (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) (y : Fin M→Spin L) : ℝ := + t*∑ i,a i*inner ℝ z (y i) + +lemma cavityLinearField_exp_moment (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) (p : ℝ) : + (∫ y,Real.exp (p*cavityLinearField M L a t z y) ∂Measure.pi (fun _=>stdGaussian (Spin L)))= + Real.exp (p^2*t^2*‖z‖^2/2*∑ i,(a i)^2) := by + have he y : Real.exp (p*cavityLinearField M L a t z y)= + ∏ i,Real.exp ((p*t*a i)*inner ℝ z (y i)) := by + unfold cavityLinearField + rw [←mul_assoc,Finset.mul_sum,Real.exp_sum] + congr 1 + ext i + congr 1 + ring + simp_rw [he] + rw [integral_fintype_prod_eq_prod (fun i (x : Spin L)=>Real.exp ((p*t*a i)*inner ℝ z x))] + simp_rw [integral_exp_inner_stdGaussian] + rw [←Real.exp_sum] + congr 1 + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Brownian/CountableGaussianField.lean b/lean/OAI/Probability/Perceptron/Brownian/CountableGaussianField.lean new file mode 100644 index 0000000000000000000000000000000000000000..e113289385231db1a2305deac9a8147f3535cf50 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Brownian/CountableGaussianField.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +def countableGaussianLaw : Measure (ℕ → ℝ) := + Measure.infinitePi fun _ : ℕ => gaussianReal 0 1 + +instance : IsProbabilityMeasure countableGaussianLaw := by + unfold countableGaussianLaw + infer_instance + +def gaussianCoordinatePrefix (n : ℕ) (g : ℕ → ℝ) : Fin n → ℝ := fun i => g i.val + +lemma gaussianCoordinatePrefix_measurePreserving (n : ℕ) : + MeasurePreserving (gaussianCoordinatePrefix n) countableGaussianLaw + (Measure.pi fun _ : Fin n => gaussianReal 0 1) := by + refine ⟨by unfold gaussianCoordinatePrefix; fun_prop,?_⟩ + change Measure.map (fun g : ℕ → ℝ => fun i : Fin n => g i.val) + (Measure.infinitePi fun _ : ℕ => gaussianReal 0 1)=_ + rw [Measure.map_infinitePi_infinitePi_of_inj Fin.val_injective,Measure.infinitePi_eq_pi] + +variable {S : Type*} + +def gaussianPrefixField (v : ℕ → S → ℝ) (n : ℕ) (g : ℕ → ℝ) (x : S) : ℝ := + ∑ i : Fin n, g i.val*v i.val x + +def countableGaussianField (v : ℕ → S → ℝ) (L : S → ℕ) (g : ℕ → ℝ) (x : S) : ℝ := + gaussianPrefixField v (L x) g x + +lemma gaussianPrefixField_measurable [MeasurableSpace S] {v : ℕ → S → ℝ} + (hv : ∀ i, Measurable (v i)) (n : ℕ) : + Measurable (Function.uncurry (gaussianPrefixField v n)) := by + unfold gaussianPrefixField Function.uncurry + exact Finset.measurable_sum _ fun i _ => + ((measurable_pi_apply i.val).comp measurable_fst).mul ((hv i.val).comp measurable_snd) + +lemma countableGaussianField_measurable [MeasurableSpace S] {v : ℕ → S → ℝ} {L : S → ℕ} + (hv : ∀ i, Measurable (v i)) (hL : Measurable L) : + Measurable (Function.uncurry (countableGaussianField v L)) := by + have hm : Measurable (fun p : ℕ × ((ℕ → ℝ) × S) => + gaussianPrefixField v p.1 p.2.1 p.2.2) := by + apply measurable_from_prod_countable_right + intro n + exact gaussianPrefixField_measurable hv n + exact hm.comp ((hL.comp measurable_snd).prodMk measurable_id) + +lemma finiteGaussian_exp_integrable (n : ℕ) (a : Fin n → ℝ) (t : ℝ) : + Integrable (fun g : Fin n → ℝ => Real.exp (t*∑ i, g i*a i)) + (Measure.pi fun _ : Fin n => gaussianReal 0 1) := by + have h := Integrable.fintype_prod (fun i : Fin n => + integrable_exp_mul_gaussianReal (μ := 0) (v := 1) (t*a i)) + convert h using 1 + ext g + rw [Finset.mul_sum,Real.exp_sum] + congr 1 + ext i + congr 1 + ring + +lemma finiteGaussian_exp_integral (n : ℕ) (a : Fin n → ℝ) (t : ℝ) : + (∫ g : Fin n → ℝ, Real.exp (t*∑ i, g i*a i) + ∂Measure.pi (fun _ : Fin n => gaussianReal 0 1)) = + Real.exp (t^2*(∑ i, a i^2)/2) := by + have he : (fun g : Fin n → ℝ => Real.exp (t*∑ i, g i*a i))= + fun g => ∏ i, Real.exp ((t*a i)*g i) := by + funext g + rw [Finset.mul_sum,Real.exp_sum] + congr 1 + ext i + congr 1 + ring + rw [he,integral_fintype_prod_eq_prod (fun i : Fin n => fun x => Real.exp ((t*a i)*x))] + have hi (i : Fin n) : (∫ x, Real.exp ((t*a i)*x) ∂gaussianReal 0 1)= + Real.exp ((t*a i)^2/2) := by + have hh := mgf_gaussianReal (X := fun x : ℝ => x) (p := gaussianReal 0 1) + (μ := 0) (v := 1) (by simp) (t*a i) + simpa only [mgf,zero_mul,NNReal.coe_one,one_mul,zero_add] using hh + simp_rw [hi] + rw [← Real.exp_sum,Finset.mul_sum,Finset.sum_div] + congr 1 + apply Finset.sum_congr rfl + intro i _ + ring + +lemma gaussianPrefixField_exp_integrable (v : ℕ → S → ℝ) (n : ℕ) (x : S) (t : ℝ) : + Integrable (fun g => Real.exp (t*gaussianPrefixField v n g x)) countableGaussianLaw := by + exact (gaussianCoordinatePrefix_measurePreserving n).integrable_comp_of_integrable + (finiteGaussian_exp_integrable n (fun i => v i.val x) t) + +lemma gaussianPrefixField_exp_integral (v : ℕ → S → ℝ) (n : ℕ) (x : S) (t : ℝ) : + (∫ g, Real.exp (t*gaussianPrefixField v n g x) ∂countableGaussianLaw)= + Real.exp (t^2*(∑ i : Fin n, v i.val x^2)/2) := by + rw [← finiteGaussian_exp_integral n (fun i => v i.val x) t] + have hm := gaussianCoordinatePrefix_measurePreserving n + conv_rhs => rw [← hm.map_eq] + rw [integral_map hm.measurable.aemeasurable (by + rw [hm.map_eq] + exact (finiteGaussian_exp_integrable n (fun i => v i.val x) t).aestronglyMeasurable)] + rfl + +lemma countableGaussianField_exp_integrable (v : ℕ → S → ℝ) (L : S → ℕ) (x : S) (t : ℝ) : + Integrable (fun g => Real.exp (t*countableGaussianField v L g x)) countableGaussianLaw := + gaussianPrefixField_exp_integrable v (L x) x t + +lemma countableGaussianField_exp_integral (v : ℕ → S → ℝ) (L : S → ℕ) (x : S) (t : ℝ) : + (∫ g, Real.exp (t*countableGaussianField v L g x) ∂countableGaussianLaw)= + Real.exp (t^2*(∑ i : Fin (L x), v i.val x^2)/2) := + gaussianPrefixField_exp_integral v (L x) x t + +def maskedGaussianCoefficient (v : ℕ → S → ℝ) (L : S → ℕ) (i : ℕ) (x : S) : ℝ := + if i simp + | succ n ih => + rw [Finset.sum_range_succ,ih] + by_cases h : n < m + · have hn : min n m=n := min_eq_left (by omega) + have hn' : min (n+1) m=n+1 := min_eq_left (by omega) + rw [hn,hn',ite_eq_left h,Finset.sum_range_succ] + · have hn : min n m=m := min_eq_right (by omega) + have hn' : min (n+1) m=m := min_eq_right (by omega) + rw [hn,hn',ite_eq_right h,add_zero] + +def truncatedCountableGaussianField (v : ℕ → S → ℝ) (L : S → ℕ) (n : ℕ) := + gaussianPrefixField (maskedGaussianCoefficient v L) n + +lemma truncatedCountableGaussianField_eq (v : ℕ → S → ℝ) (L : S → ℕ) + (n : ℕ) (g : ℕ → ℝ) (x : S) : + truncatedCountableGaussianField v L n g x=gaussianPrefixField v (min n (L x)) g x := by + unfold truncatedCountableGaussianField gaussianPrefixField + rw [Fin.sum_univ_eq_sum_range (fun i => g i * maskedGaussianCoefficient v L i x) n, + Fin.sum_univ_eq_sum_range (fun i => g i * v i x) (min n (L x))] + have he (i : ℕ) : g i*maskedGaussianCoefficient v L i x= + if i simp_all + simp_rw [he] + exact sum_range_cutoff _ n (L x) + +lemma truncatedCountableGaussianField_eventually_eq (v : ℕ → S → ℝ) (L : S → ℕ) + (x : S) : ∀ᶠ n in atTop, ∀ g, + truncatedCountableGaussianField v L n g x=countableGaussianField v L g x := by + filter_upwards [eventually_ge_atTop (L x)] with n hn g + rw [truncatedCountableGaussianField_eq,min_eq_right hn] + rfl + +lemma truncatedCountableGaussianField_measurable [MeasurableSpace S] {v : ℕ → S → ℝ} {L : S → ℕ} + (hv : ∀ i, Measurable (v i)) (hL : Measurable L) (n : ℕ) : + Measurable (Function.uncurry (truncatedCountableGaussianField v L n)) := + gaussianPrefixField_measurable (maskedGaussianCoefficient_measurable hv hL) n + +lemma gaussianCoefficient_prefix_sq_le (v : ℕ → S → ℝ) (L : S → ℕ) (n : ℕ) (x : S) : + (∑ i : Fin (min n (L x)), v i.val x^2) ≤ ∑ i : Fin (L x), v i.val x^2 := by + rw [Fin.sum_univ_eq_sum_range (fun i => v i x ^ 2) (min n (L x)), + Fin.sum_univ_eq_sum_range (fun i => v i x ^ 2) (L x)] + exact Finset.sum_le_sum_of_subset_of_nonneg + (Finset.range_mono (min_le_right n (L x))) (fun _ _ _ => sq_nonneg _) + +lemma truncatedCountableGaussianField_exp_integral_le (v : ℕ → S → ℝ) (L : S → ℕ) + {D : ℝ} (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) (n : ℕ) (x : S) (t : ℝ) : + (∫ g, Real.exp (t*truncatedCountableGaussianField v L n g x) ∂countableGaussianLaw) ≤ + Real.exp (t^2*D/2) := by + simp_rw [truncatedCountableGaussianField_eq] + rw [gaussianPrefixField_exp_integral] + exact Real.exp_le_exp.mpr (div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left ((gaussianCoefficient_prefix_sq_le v L n x).trans (hD x)) + (sq_nonneg t)) (by norm_num)) + +lemma countableGaussianField_exp_integral_le (v : ℕ → S → ℝ) (L : S → ℕ) + {D : ℝ} (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) (x : S) (t : ℝ) : + (∫ g, Real.exp (t*countableGaussianField v L g x) ∂countableGaussianLaw) ≤ + Real.exp (t^2*D/2) := by + rw [countableGaussianField_exp_integral] + exact Real.exp_le_exp.mpr (div_le_div_of_nonneg_right + (mul_le_mul_of_nonneg_left (hD x) (sq_nonneg t)) (by norm_num)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Brownian/GaussianField.lean b/lean/OAI/Probability/Perceptron/Brownian/GaussianField.lean new file mode 100644 index 0000000000000000000000000000000000000000..f5098e1a04aa07753ed2aeb9c3f341a256340332 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Brownian/GaussianField.lean @@ -0,0 +1,419 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StableLaplaceConstant + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] +section Replicas +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma gaussian_replica_integrationByParts {v : S → ℝ} {n : ℕ} {F : (Fin n → S) → ℝ} + (hv : Measurable v) (hF : Measurable F) {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) : + (∫ t, t * tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) F t + ∂gaussianReal 0 1) = + ∫ t, tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) + (fun x => replicaPotential v n x * F x) t - n * + tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) F t * + tiltMean μ v v t ∂gaussianReal 0 1 := by + rw [gaussian_tilt_integrationByParts _ (replicaPotential_measurable hv n) hF + (mul_nonneg (Nat.cast_nonneg n) hC) hD (replicaPotential_bound hvC n) hFD] + apply integral_congr_ae + exact ae_of_all _ fun t => by + dsimp only + rw [replica_mean_potential μ hv hC hvC n t] + ring + +end Replicas + +section GibbsProducts +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma tilt_law_apply {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (t : ℝ) + {s : Set S} (hs : MeasurableSet s) : + tiltLaw μ v t s = (ENNReal.ofReal (tiltPartition μ v t))⁻¹ * + ENNReal.ofReal (∫ x in s, Real.exp (t * v x) ∂μ) := by + have hi : Integrable (fun x => Real.exp (t * v x)) μ := by + simpa only [mul_one] using tilt_integrable μ (F := fun _ => 1) hv measurable_const hC + (by norm_num : (0:ℝ) ≤ 1) hvC (fun _ => by norm_num) t + rw [tiltLaw,Measure.smul_apply,smul_eq_mul,withDensity_apply _ hs, + ← ofReal_integral_eq_lintegral_ofReal hi.integrableOn (ae_of_all _ fun x => (Real.exp_pos _).le)] + +lemma tilt_law_pi {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (n : ℕ) (t : ℝ) : + tiltLaw (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) t = + Measure.pi (fun _ : Fin n => tiltLaw μ v t) := by + have := tilt_law_probability μ hv hC hvC t + symm + apply Measure.pi_eq + intro s hs + rw [tilt_law_apply _ (replicaPotential_measurable hv n) + (mul_nonneg (Nat.cast_nonneg n) hC) (replicaPotential_bound hvC n) t (MeasurableSet.univ_pi hs), + replica_partition μ hv n,ENNReal.ofReal_pow (tilt_partition_pos μ hv hC hvC t).le, + Measure.restrict_pi_pi] + have he (x : Fin n → S) : Real.exp (t * replicaPotential v n x) = + ∏ i, Real.exp (t * v (x i)) := by + simp only [replicaPotential,Finset.mul_sum,Real.exp_sum] + simp_rw [he] + rw [integral_fintype_prod_eq_prod (f := fun (_ : Fin n) x => Real.exp (t * v x)), + ENNReal.ofReal_prod_of_nonneg (fun i _ => integral_nonneg (fun _ => (Real.exp_pos _).le))] + simp_rw [tilt_law_apply μ hv hC hvC t (hs _)] + rw [Finset.prod_mul_distrib,Finset.prod_const,Finset.card_univ,Fintype.card_fin,ENNReal.inv_pow] + +lemma tilt_mean_twice {v w F : S → ℝ} (hw : Measurable w) + {D : ℝ} (hD : 0 ≤ D) (hwD : ∀ x, |w x| ≤ D) (s t : ℝ) : + tiltMean (tiltLaw μ w s) v F t = tiltMean μ (fun x => s*w x+t*v x) F 1 := by + have := tilt_law_probability μ hw hD hwD s + have hp := (tilt_partition_pos μ hw hD hwD s).ne' + unfold tiltMean tiltIntegral tiltPartition + rw [tilt_law_integral μ hw hD hwD s,tilt_law_integral μ hw hD hwD s] + simp only [tiltMean,tiltIntegral,one_mul,Real.exp_add] + have he (x : S) : Real.exp (s*w x) * (Real.exp (t*v x)*F x) = + Real.exp (s*w x) * Real.exp (t*v x) * F x := by ring + simp_rw [he] + change ((∫ x, Real.exp (s*w x) * Real.exp (t*v x) * F x ∂μ) / tiltPartition μ w s) / + ((∫ x, Real.exp (s*w x) * Real.exp (t*v x) ∂μ) / tiltPartition μ w s) = _ + rw [div_div_div_cancel_right₀ hp] + +end GibbsProducts + +lemma gaussian_pi_coordinate_integrationByParts (n : ℕ) (i : Fin (n+1)) + {F D : (Fin (n+1) → ℝ) → ℝ} (hF : Measurable F) (hD : Measurable D) + {C B : ℝ} (hFC : ∀ g, |F g| ≤ C) (hDB : ∀ g, |D g| ≤ B) + (hd : ∀ (g : Fin n → ℝ) (t : ℝ), + HasDerivAt (fun u => F (i.insertNth u g)) (D (i.insertNth t g)) t) : + (∫ g, g i * F g ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ g, D g ∂Measure.pi (fun _ => gaussianReal 0 1) := by + let ν : Measure (Fin n → ℝ) := Measure.pi fun _ => gaussianReal 0 1 + let e := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => ℝ) i).symm + have he := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => gaussianReal 0 1) i).symm + have hmF : Measurable (fun p : ℝ × (Fin n → ℝ) => F (i.insertNth p.1 p.2)) := + hF.comp e.measurable + have hmD : Measurable (fun p : ℝ × (Fin n → ℝ) => D (i.insertNth p.1 p.2)) := + hD.comp e.measurable + have hiF : Integrable (fun p : ℝ × (Fin n → ℝ) => p.1 * F (i.insertNth p.1 p.2)) + ((gaussianReal 0 1).prod ν) := by + apply ((memLp_id_gaussianReal (μ := 0) (v := 1) 1).integrable (by norm_num)).comp_fst ν |>.mul_bdd + hmF.aestronglyMeasurable + exact ae_of_all _ fun p => by simpa only [Real.norm_eq_abs] using hFC (i.insertNth p.1 p.2) + have hiD : Integrable (fun p : ℝ × (Fin n → ℝ) => D (i.insertNth p.1 p.2)) + ((gaussianReal 0 1).prod ν) := + Integrable.of_bound hmD.aestronglyMeasurable B + (ae_of_all _ fun p => by simpa only [Real.norm_eq_abs] using hDB (i.insertNth p.1 p.2)) + rw [← he.integral_comp e.measurableEmbedding (fun g => g i * F g), + ← he.integral_comp e.measurableEmbedding D] + change (∫ p : ℝ × (Fin n → ℝ), ((i.insertNth p.1 p.2 : Fin (n+1) → ℝ) i) * + F (i.insertNth p.1 p.2) ∂(gaussianReal 0 1).prod ν) = + ∫ p : ℝ × (Fin n → ℝ), D (i.insertNth p.1 p.2) ∂(gaussianReal 0 1).prod ν + simp only [Fin.insertNth_apply_same] + rw [integral_prod_symm _ hiF,integral_prod_symm _ hiD] + apply integral_congr_ae + exact ae_of_all _ fun g => standardGaussian_integrationByParts (hd g) + (hmD.comp (measurable_id.prodMk measurable_const)) + (fun t => hFC (i.insertNth t g)) (fun t => hDB (i.insertNth t g)) + +section GaussianField +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma measurable_tiltMean {Ω : Type*} [MeasurableSpace Ω] + {v : Ω → S → ℝ} {F : S → ℝ} (hv : Measurable (Function.uncurry v)) + (hF : Measurable F) : Measurable (fun g => tiltMean μ (v g) F 1) := by + simp only [tiltMean,tiltIntegral,tiltPartition,one_mul] + exact ((hv.exp.mul (hF.comp measurable_snd)).stronglyMeasurable.integral_prod_right'.measurable).div + hv.exp.stronglyMeasurable.integral_prod_right'.measurable + +def gaussianField (n : ℕ) (v : Fin n → S → ℝ) (g : Fin n → ℝ) (x : S) : ℝ := + ∑ i, g i * v i x + +lemma gaussianField_measurable {n : ℕ} {v : Fin n → S → ℝ} + (hv : ∀ i, Measurable (v i)) : + Measurable (fun p : (Fin n → ℝ) × S => gaussianField n v p.1 p.2) := by + unfold gaussianField + fun_prop + +omit [MeasurableSpace S] in +lemma gaussianField_bound {n : ℕ} {v : Fin n → S → ℝ} {C : ℝ} + (hvC : ∀ i x, |v i x| ≤ C) (g : Fin n → ℝ) (x : S) : + |gaussianField n v g x| ≤ (∑ i, |g i|) * C := by + unfold gaussianField + calc + _ ≤ ∑ i, |g i * v i x| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i, |g i| * C := Finset.sum_le_sum fun i _ => by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hvC i x) (abs_nonneg _) + _ = _ := (Finset.sum_mul ..).symm + +omit [MeasurableSpace S] in +lemma gaussianField_insertNth {n : ℕ} (i : Fin (n+1)) (v : Fin (n+1) → S → ℝ) + (g : Fin n → ℝ) (t : ℝ) (x : S) : + gaussianField (n+1) v (i.insertNth t g) x = + t*v i x + gaussianField n (fun j => v (i.succAbove j)) g x := by + classical + rw [gaussianField,Fin.sum_univ_succAbove _ i] + simp [gaussianField] + +omit [IsProbabilityMeasure μ] in +lemma tilt_mean_mulObservable {v F : S → ℝ} (c t : ℝ) : + tiltMean μ v (fun x => c*F x) t = c * tiltMean μ v F t := by + unfold tiltMean tiltIntegral + simp_rw [show ∀ x, Real.exp (t*v x)*(c*F x) = c*(Real.exp (t*v x)*F x) by intro; ring] + rw [integral_const_mul] + ring + +lemma gaussian_field_coordinate_ibp {n : ℕ} (i : Fin (n+1)) + {v : Fin (n+1) → S → ℝ} {h F : S → ℝ} + (hv : ∀ j, Measurable (v j)) (hh : Measurable h) (hF : Measurable F) + {C A D : ℝ} (hC : 0 ≤ C) (hA : 0 ≤ A) (hD : 0 ≤ D) + (hvC : ∀ j x, |v j x| ≤ C) (hhA : ∀ x, |h x| ≤ A) (hFD : ∀ x, |F x| ≤ D) + (s : ℝ) : + (∫ g, g i * tiltMean μ (fun x => h x + s*gaussianField (n+1) v g x) F 1 + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + s * ∫ g, tiltMean μ (fun x => h x + s*gaussianField (n+1) v g x) (fun x => v i x * F x) 1 - + tiltMean μ (fun x => h x + s*gaussianField (n+1) v g x) F 1 * + tiltMean μ (fun x => h x + s*gaussianField (n+1) v g x) (v i) 1 + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + let H (g : Fin (n+1) → ℝ) (x : S) := h x + s*gaussianField (n+1) v g x + have hHm : Measurable (Function.uncurry H) := hh.comp measurable_snd |>.add + ((gaussianField_measurable hv).const_mul s) + have hHb (g : Fin (n+1) → ℝ) (x : S) : |H g x| ≤ A + |s| * ((∑ j, |g j|)*C) := by + dsimp [H] + exact (abs_add_le _ _).trans (add_le_add (hhA x) (by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (gaussianField_bound hvC g x) (abs_nonneg s))) + have hm (K : S → ℝ) (hK : Measurable K) := measurable_tiltMean μ hHm hK + have hb (K : S → ℝ) (hK : Measurable K) {B : ℝ} (hB : 0 ≤ B) + (hKB : ∀ x, |K x| ≤ B) (g : Fin (n+1) → ℝ) : |tiltMean μ (H g) K 1| ≤ B := + tilt_mean_bound μ (hHm.comp (measurable_const.prodMk measurable_id)) hK + (by positivity) hB (hHb g) hKB 1 + have hvF (x : S) : |v i x * F x| ≤ C * D := by + rw [abs_mul]; exact mul_le_mul (hvC i x) (hFD x) (abs_nonneg _) hC + rw [← integral_const_mul] + apply gaussian_pi_coordinate_integrationByParts n i (hm F hF) + (measurable_const.mul ((hm _ ((hv i).mul hF)).sub ((hm F hF).mul (hm _ (hv i))))) + (hb F hF hD hFD) (B := |s| *(2*C*D)) + · intro g + dsimp only [Pi.mul_apply,Pi.sub_apply] + rw [abs_mul] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg s) + exact (abs_sub _ _).trans (by + have h1 := hb _ ((hv i).mul hF) (mul_nonneg hC hD) hvF g + have h2 := mul_le_mul (hb F hF hD hFD g) (hb _ (hv i) hC (hvC i) g) (abs_nonneg _) hD + rw [← abs_mul] at h2 + nlinarith) + · intro g t + let w (x : S) := h x + s*gaussianField n (fun j => v (i.succAbove j)) g x + have hwm : Measurable w := hh.add (((gaussianField_measurable (fun j => hv (i.succAbove j))).comp + (measurable_const.prodMk measurable_id)).const_mul s) + have hwb (x : S) : |w x| ≤ A+|s| *((∑ j, |g j|)*C) := by + exact (abs_add_le _ _).trans (add_le_add (hhA x) (by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (gaussianField_bound (fun j => hvC (i.succAbove j)) g x) + (abs_nonneg s))) + have := tilt_law_probability μ hwm (by positivity) hwb 1 + have hsc (x : S) : |s*v i x| ≤ |s| *C := by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hvC i x) (abs_nonneg s) + have he (K : S → ℝ) (u : ℝ) : tiltMean (tiltLaw μ w 1) (fun x => s*v i x) K u = + tiltMean μ (H (i.insertNth u g)) K 1 := by + rw [tilt_mean_twice μ hwm (by positivity) hwb] + congr 2 + funext x + dsimp [w,H] + rw [gaussianField_insertNth] + ring + have hd := tilt_mean_deriv (tiltLaw μ w 1) ((hv i).const_mul s) hF + (mul_nonneg (abs_nonneg s) hC) hD hsc hFD t + rw [show tiltMean (tiltLaw μ w 1) (fun x => s*v i x) F = + (fun u => tiltMean μ (H (i.insertNth u g)) F 1) from funext (he F)] at hd + simp_rw [he] at hd + convert! hd using 1 + rw [show (fun x => s*v i x * F x) = (fun x => s*(v i x*F x)) by funext x; ring, + tilt_mean_mulObservable,tilt_mean_mulObservable] + dsimp only [Pi.mul_apply,Pi.sub_apply] + rw [show v i * F = (fun x => v i x * F x) from rfl] + ring + +end GaussianField + +lemma ennreal_rpow_sum_le {ι : Type*} (s : Finset ι) (f : ι → ℝ≥0∞) + {a : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) : (∑ i ∈ s, f i)^a ≤ ∑ i ∈ s, (f i)^a := by + classical + induction s using Finset.induction_on with + | empty => simp [ha] + | @insert i s his ih => + simp only [Finset.sum_insert his] + exact (ENNReal.rpow_add_le_add_rpow _ _ ha.le ha1).trans (add_le_add le_rfl ih) + +lemma ennreal_rpow_tsum_le (f : ℕ → ℝ≥0∞) {a : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) : + (∑' i, f i)^a ≤ ∑' i, (f i)^a := by + apply le_of_tendsto_of_tendsto + ((ENNReal.continuous_rpow_const).continuousAt.tendsto.comp + (ENNReal.summable.hasSum.tendsto_sum_nat (f := f))) + (ENNReal.summable.hasSum.tendsto_sum_nat (f := fun i => (f i)^a)) + exact Filter.Eventually.of_forall fun n => ennreal_rpow_sum_le _ _ ha ha1 + +lemma finitePoissonLaw_rpow_lintegral_le {S : Type*} [MeasurableSpace S] + (r : ℝ≥0) (ν : Measure S) {f : S → ℝ≥0∞} (hf : Measurable f) + {a : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) : + ∀ᵐ η ∂finitePoissonLaw r ν, (∫⁻ x, f x ∂η)^a ≤ ∫⁻ x, (f x)^a ∂η := by + rw [finitePoissonLaw,Measure.ae_sum_iff] + intro n + apply Measure.ae_smul_measure + rw [ae_map_iff (finitePointMeasure_measurable n).aemeasurable + (measurableSet_le ((Measure.measurable_lintegral hf).pow_const a) + (Measure.measurable_lintegral (hf.pow_const a)))] + apply ae_of_all + intro y + simp only [finitePointMeasure,lintegral_finsetSum_measure] + simp_rw [lintegral_dirac' _ hf,lintegral_dirac' _ (hf.pow_const a)] + exact ennreal_rpow_sum_le _ _ ha ha1 + +lemma countablePoissonLaw_rpow_lintegral_le {S : Type*} [MeasurableSpace S] + (r : ℕ → ℝ≥0) (ν : ℕ → Measure S) [∀ i, IsProbabilityMeasure (ν i)] + {f : S → ℝ≥0∞} (hf : Measurable f) {a : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) : + ∀ᵐ η ∂countablePoissonLaw r ν, (∫⁻ x, f x ∂η)^a ≤ ∫⁻ x, (f x)^a ∂η := by + rw [countablePoissonLaw,ae_map_iff measureSum_measurable.aemeasurable + (measurableSet_le ((Measure.measurable_lintegral hf).pow_const a) + (Measure.measurable_lintegral (hf.pow_const a)))] + have hi (i : ℕ) : ∀ᵐ η ∂Measure.infinitePi (fun j => finitePoissonLaw (r j) (ν j)), + (∫⁻ x, f x ∂η i)^a ≤ ∫⁻ x, (f x)^a ∂η i := + (measurePreserving_eval_infinitePi (fun j => finitePoissonLaw (r j) (ν j)) i).quasiMeasurePreserving.ae + (finitePoissonLaw_rpow_lintegral_le (r i) (ν i) hf ha ha1) + filter_upwards [ae_all_iff.mpr hi] with η hη + simp only [lintegral_sum_measure] + exact (ennreal_rpow_tsum_le _ ha ha1).trans (ENNReal.tsum_le_tsum hη) + +lemma poissonRandomMeasureLaw_rpow_lintegral_le {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {f : S → ℝ≥0∞} (hf : Measurable f) + {a : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) : + ∀ᵐ η ∂poissonRandomMeasureLaw κ, (∫⁻ x, f x ∂η)^a ≤ ∫⁻ x, (f x)^a ∂η := + countablePoissonLaw_rpow_lintegral_le _ _ hf ha ha1 + +lemma ennreal_rpow_le_one_add {a : ℝ} (ha0 : 0 ≤ a) (ha1 : a ≤ 1) (u : ℝ≥0∞) : + u^a ≤ 1+u := by + by_cases h : u ≤ 1 + · exact (ENNReal.rpow_le_one h ha0).trans (le_add_right le_rfl) + · have hu : u^a ≤ u := by simpa using ENNReal.rpow_le_rpow_of_exponent_le (le_of_not_ge h) ha1 + exact hu.trans (le_add_left le_rfl) + +lemma poissonRandomMeasureLaw_fractional_moment {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {f g : S → ℝ≥0∞} (hf : Measurable f) (hg : Measurable g) + {a : ℝ} (ha : 0 < a) (ha1 : a ≤ 1) + (hfin : ∫⁻ x, f x ∂κ ≠ ⊤) (hgin : ∫⁻ x, (g x)^a ∂κ ≠ ⊤) : + (∫⁻ η, (∫⁻ x, f x+g x ∂η)^a ∂poissonRandomMeasureLaw κ) ≠ ⊤ := by + have hbound : ∀ᵐ η ∂poissonRandomMeasureLaw κ, + (∫⁻ x, f x+g x ∂η)^a ≤ 1+(∫⁻ x, f x ∂η)+(∫⁻ x, (g x)^a ∂η) := by + filter_upwards [poissonRandomMeasureLaw_rpow_lintegral_le κ hg ha ha1] with η hη + rw [lintegral_add_left hf] + exact (ENNReal.rpow_add_le_add_rpow _ _ ha.le ha1).trans + (add_le_add (ennreal_rpow_le_one_add ha.le ha1 _) hη) + apply ne_top_of_le_ne_top _ (lintegral_mono_ae hbound) + rw [lintegral_add_left (f := fun η => 1+(∫⁻ x, f x ∂η)) (measurable_const.add (Measure.measurable_lintegral hf)), + lintegral_add_left (f := fun _ => (1 : ℝ≥0∞)) measurable_const,lintegral_const,measure_univ,one_mul, + poissonRandomMeasureLaw_campbell κ hf,poissonRandomMeasureLaw_campbell κ (hg.pow_const a)] + exact ENNReal.add_ne_top.mpr ⟨ENNReal.add_ne_top.mpr ⟨by simp,hfin⟩,hgin⟩ + +lemma stableLogIntensity_of_integrable {b : ℝ} (hb : 0 ≤ b) {f : ℝ → ℝ} + (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) + (hi : Integrable (fun x => b * Real.exp (-b*x) * f x)) : + (∫⁻ x, ENNReal.ofReal (f x) ∂stableLogIntensity b) ≠ ⊤ := by + unfold stableLogIntensity + rw [lintegral_withDensity_eq_lintegral_mul volume (by fun_prop) hf.ennreal_ofReal] + have he (x : ℝ) : ENNReal.ofReal (b * Real.exp (-b*x)) * ENNReal.ofReal (f x) = + ENNReal.ofReal (b * Real.exp (-b*x) * f x) := + (ENNReal.ofReal_mul (mul_nonneg hb (Real.exp_pos _).le)).symm + simp only [Pi.mul_apply] + simp_rw [he] + exact ((hasFiniteIntegral_iff_ofReal (ae_of_all _ fun x => + mul_nonneg (mul_nonneg hb (Real.exp_pos _).le) (hf0 x))).mp hi.hasFiniteIntegral).ne + +lemma stableLogIntensity_small_moment {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) : + (∫⁻ x, (Iic 0).indicator (fun y => ENNReal.ofReal (Real.exp y)) x + ∂stableLogIntensity b) ≠ ⊤ := by + have hi := ((integrableOn_exp_mul_Iic (a := 1-b) (by linarith) 0).integrable_indicator + measurableSet_Iic).const_mul b + have he (x : ℝ) : b*Real.exp (-b*x) * (Iic 0).indicator Real.exp x = + b * (Iic 0).indicator (fun y => Real.exp ((1-b)*y)) x := by + by_cases hx : x ∈ Iic 0 + · simp only [indicator_of_mem hx] + rw [mul_assoc,← Real.exp_add] + congr 2 + ring + · simp [indicator_of_notMem hx] + have hh := stableLogIntensity_of_integrable (f := (Iic (0 : ℝ)).indicator Real.exp) hb0.le (Real.measurable_exp.indicator measurableSet_Iic) + (fun x => indicator_nonneg (fun _ _ => (Real.exp_pos _).le) x) (by simpa only [he] using hi) + convert hh using 1 + congr 1 + funext x + by_cases hx : x ∈ Iic 0 <;> simp [hx] + +lemma stableLogIntensity_large_moment {b a : ℝ} (hb : 0 ≤ b) (hab : a < b) : + (∫⁻ x, (Ioi 0).indicator (fun y => ENNReal.ofReal (Real.exp (a*y))) x + ∂stableLogIntensity b) ≠ ⊤ := by + have hi := ((integrableOn_exp_mul_Ioi (a := a-b) (by linarith) 0).integrable_indicator + measurableSet_Ioi).const_mul b + have he (x : ℝ) : b*Real.exp (-b*x) * (Ioi 0).indicator (fun y => Real.exp (a*y)) x = + b * (Ioi 0).indicator (fun y => Real.exp ((a-b)*y)) x := by + by_cases hx : x ∈ Ioi 0 + · simp only [indicator_of_mem hx] + rw [mul_assoc,← Real.exp_add] + congr 2 + ring + · simp [indicator_of_notMem hx] + have hh := stableLogIntensity_of_integrable (f := (Ioi (0 : ℝ)).indicator (fun y => Real.exp (a*y))) hb ((measurable_const.mul measurable_id).exp.indicator measurableSet_Ioi) + (fun x => indicator_nonneg (fun _ _ => (Real.exp_pos _).le) x) (by simpa only [he] using hi) + convert hh using 1 + congr 1 + funext x + by_cases hx : x ∈ Ioi 0 <;> simp [hx] + +lemma stablePoissonTotal_fractional_integrable {b a : ℝ} (hb0 : 0 < b) (hb1 : b < 1) + (ha0 : 0 ≤ a) (hab : a < b) : + Integrable (fun η => (stablePoissonTotal η)^a) (poissonRandomMeasureLaw (stableLogIntensity b)) := by + rcases ha0.eq_or_lt with h | ha + · rw [← h] + simp only [Real.rpow_zero] + exact integrable_const 1 + have hh := poissonRandomMeasureLaw_fractional_moment (stableLogIntensity b) + (f := (Iic (0 : ℝ)).indicator (fun y => ENNReal.ofReal (Real.exp y))) + (g := (Ioi (0 : ℝ)).indicator (fun y => ENNReal.ofReal (Real.exp y))) + ((Real.measurable_exp.ennreal_ofReal).indicator measurableSet_Iic) + ((Real.measurable_exp.ennreal_ofReal).indicator measurableSet_Ioi) + ha (hab.trans hb1).le (stableLogIntensity_small_moment hb0 hb1) + have he (x : ℝ) : ((Ioi 0).indicator (fun y => ENNReal.ofReal (Real.exp y)) x)^a = + (Ioi 0).indicator (fun y => ENNReal.ofReal (Real.exp (a*y))) x := by + by_cases hx : x ∈ Ioi 0 + · simp only [indicator_of_mem hx] + rw [ENNReal.ofReal_rpow_of_pos (Real.exp_pos _),Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp,mul_comm x a] + · simp [indicator_of_notMem hx,ha] + simp_rw [he] at hh + specialize hh (stableLogIntensity_large_moment hb0.le hab) + have he' (x : ℝ) : (Iic 0).indicator (fun y => ENNReal.ofReal (Real.exp y)) x + + (Ioi 0).indicator (fun y => ENNReal.ofReal (Real.exp y)) x = ENNReal.ofReal (Real.exp x) := by + by_cases hx : x ≤ 0 <;> simp [hx,not_lt.mpr,lt_of_not_ge] + simp_rw [he'] at hh + apply Integrable.mono' (integrable_toReal_of_lintegral_ne_top + ((Measure.measurable_lintegral Real.measurable_exp.ennreal_ofReal).pow_const a).aemeasurable hh) + ((stablePoissonTotal_measurable.pow_const a).aestronglyMeasurable) + exact ae_of_all _ fun η => by + simp only [stablePoissonTotal,Real.norm_eq_abs,ENNReal.toReal_rpow] + rw [abs_of_nonneg ENNReal.toReal_nonneg] + +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma tilt_replica_integral {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (n : ℕ) (t : ℝ) + (F : (Fin n → S) → ℝ) : + tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) F t = + ∫ x, F x ∂Measure.pi (fun _ : Fin n => tiltLaw μ v t) := by + rw [← tilt_law_pi μ hv hC hvC n t,tilt_law_integral _ + (replicaPotential_measurable hv n) (mul_nonneg (Nat.cast_nonneg n) hC) + (replicaPotential_bound hvC n)] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Brownian/GaussianFieldAlgebra.lean b/lean/OAI/Probability/Perceptron/Brownian/GaussianFieldAlgebra.lean new file mode 100644 index 0000000000000000000000000000000000000000..e1ace5a376280a0aa7a0f5023ef68288a80ef440 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Brownian/GaussianFieldAlgebra.lean @@ -0,0 +1,81 @@ +import Mathlib +import OAI.Probability.Perceptron.Brownian.CountableGaussianField + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} + +def gaussianTailCoefficient (w : ℕ → S → ℝ) (n : ℕ) (i : ℕ) (x : S) : ℝ := + if n ≤ i then w i x else 0 + +lemma gaussianTailCoefficient_measurable [MeasurableSpace S] {w : ℕ → S → ℝ} + (hw : ∀ i, Measurable (w i)) (n i : ℕ) : + Measurable (gaussianTailCoefficient w n i) := by + unfold gaussianTailCoefficient + split_ifs <;> fun_prop + +lemma countableGaussianField_add (v w : ℕ → S → ℝ) (L : S → ℕ) (g : ℕ → ℝ) (x : S) : + countableGaussianField (fun i x => v i x+w i x) L g x = + countableGaussianField v L g x+countableGaussianField w L g x := by + simp only [countableGaussianField,gaussianPrefixField,mul_add,Finset.sum_add_distrib] + +lemma countableGaussianField_smul (a : ℝ) (v : ℕ → S → ℝ) (L : S → ℕ) + (g : ℕ → ℝ) (x : S) : + countableGaussianField (fun i x => a*v i x) L g x = a*countableGaussianField v L g x := by + simp only [countableGaussianField,gaussianPrefixField,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + +lemma countableGaussianField_tail (w : ℕ → S → ℝ) (L : S → ℕ) (n : ℕ) + (g : ℕ → ℝ) (x : S) : + countableGaussianField (gaussianTailCoefficient w n) L g x = + countableGaussianField w L g x-truncatedCountableGaussianField w L n g x := by + rw [truncatedCountableGaussianField_eq] + unfold countableGaussianField gaussianPrefixField + rw [Fin.sum_univ_eq_sum_range (fun i => g i*gaussianTailCoefficient w n i x) (L x), + Fin.sum_univ_eq_sum_range (fun i => g i*w i x) (L x), + Fin.sum_univ_eq_sum_range (fun i => g i*w i x) (min n (L x))] + have he (i : ℕ) : g i*gaussianTailCoefficient w n i x = + g i*w i x-(if i simp [sq_nonneg] + +lemma gaussianCombinedCoefficient_sq_bound (v w : ℕ → S → ℝ) (L : S → ℕ) + {D E : ℝ} (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) + (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) + (a b : ℝ) (n : ℕ) (x : S) : + (∑ i : Fin (L x), (a*v i.val x+b*gaussianTailCoefficient w n i.val x)^2) ≤ + 2*a^2*D+2*b^2*E := by + calc + _ ≤ ∑ i : Fin (L x), (2*a^2*v i.val x^2+2*b^2*w i.val x^2) := by + apply Finset.sum_le_sum + intro i _ + have h := gaussianTailCoefficient_sq_le w n i.val x + have hm := mul_le_mul_of_nonneg_left h (by positivity : 0 ≤ 2*b^2) + nlinarith [sq_nonneg (a*v i.val x-b*gaussianTailCoefficient w n i.val x)] + _ = 2*a^2*(∑ i : Fin (L x), v i.val x^2)+ + 2*b^2*(∑ i : Fin (L x), w i.val x^2) := by + rw [Finset.sum_add_distrib,Finset.mul_sum,Finset.mul_sum] + _ ≤ _ := add_le_add (mul_le_mul_of_nonneg_left (hD x) (by positivity)) + (mul_le_mul_of_nonneg_left (hE x) (by positivity)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/BulkRPCCoupling.lean b/lean/OAI/Probability/Perceptron/Cascade/BulkRPCCoupling.lean new file mode 100644 index 0000000000000000000000000000000000000000..1cb5124b14136a8033253ca150d8fe3fb59895e4 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/BulkRPCCoupling.lean @@ -0,0 +1,68 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkDiagonalLimit +import OAI.Probability.Perceptron.Variational.MarkedGraphLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +theorem bulk_marked_rpc_coupling (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) + (hv : ∀ n p,1≤v n p) {C : ℝ} (hC : 0≤C) (hvC : ∀ n p,|v n (p+1)|≤C) + (hdO : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n) g.f p (v n)) atTop (𝓝 0)) + (hdF : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n+2) g.f p (v n)) atTop (𝓝 0)) + (s : ℕ→ℕ) (hs : StrictMono s) (α : ℝ) (hα : 0≤α) + (hd : Tendsto (fun n=>((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (ho : Tendsto (fun n=>bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (K : ℝ) (hK0 : 0≤K) (hK : ∀ n,((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)*‖g.d1‖^2≤K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hf : Tendsto (fun n=>bulkMarkedArrayLaw (s n) (M (s n)+2) g (v (s n)) K (hK n)) atTop (𝓝 μ)) : + ∃ d : ℝ, ∃ hd0 : 0 ≤ d, ∃ hdK : d ≤ K, + d ≤ α*‖g.d1‖^2 ∧ + let η := markedTimePair K μ + let q := boundedQuantile η + let hq := boundedQuantile_monotone η + let B := (α*‖g.d1‖^2)/(1+α*‖g.d1‖^2) + Tendsto (fun j => cavityLabelMarkedLaw + (fun i => continuousCavityProfile η B hd0 hdK (roundTimeValue (unitQuantileField q hq) j i)) + (cavityTrueDiagonal hd0 hdK) + (stepCumulative (strictRoundModel (unitQuantileField q hq) j).weight)) atTop (𝓝 μ) := by + obtain ⟨a,ham,hab,hag,hsc,hbound⟩ := + bulk_marked_self_consistency M g v hv hC hvC hdO hdF s hs α hα hd ν ho K hK0 hK μ hf + obtain ⟨d,hd0,hdK,hdA,hD2,hBd⟩ := + bulkMarkedArray_diagonal_producer M g v (Eventually.of_forall hv) hdO s hs α hα hd ν ho K hK μ hf + refine ⟨d,hd0,hdK,hdA,?_⟩ + let η := markedTimePair K μ + let q := boundedQuantile η + let hq := boundedQuantile_monotone η + let B := (α*‖g.d1‖^2)/(1+α*‖g.d1‖^2) + have hA : 0 ≤ α*‖g.d1‖^2 := mul_nonneg hα (sq_nonneg _) + have hB : B < 1 := (div_lt_one (by linarith : 0 < 1+α*‖g.d1‖^2)).mpr (by linarith) + have he e := compact_exchangeability_limit hf e + (fun n => bulkMarkedArray_exchangeable (s n) (M (s n)+2) g (v (s n)) K (hK n) e) + have hp := bulkMarkedArray_limit_overlap (fun n => M n+2) g v s K hK hf + have hg := bulk_limit_geometry (fun n => M n+2) g.f v (Eventually.of_forall hv) hdF hs hp + have hgeom := marked_overlap_geometry K μ he hg.1 hg.2.1 + have hD1 := ae_of_ae_map (compactMapArray_continuous (show Continuous + (Prod.fst : BulkPairRange K → CompactOverlap) from continuous_fst)).measurable.aemeasurable + (bulkGibbsArray_limit_diagonal g.f (fun n => M n+2) v s hp) + have hgraph := marked_graph_law μ hB hd0 hdK he hgeom.2.2 hD1 hD2 hBd a + (fun r => (hab r).1) hag hsc hbound + obtain ⟨hGG,hGe,hEx⟩ := bulk_marked_time_inputs (fun n => M n+2) g v + (Eventually.of_forall hv) hdF s hs K hK μ hf + have hpair : (markedTimeLaw K μ : Measure (CompactArray Time)).map (fun Q => Q 0 1) = timeLaw.map q := + (boundedQuantile_law η).symm + have ht := cavityLabelMarkedLaw_tendsto_graph (markedTimeLaw K μ) q hq hpair hGG hGe hEx + (continuousCavityProfile η B hd0 hdK) (continuousCavityProfile_continuous η hB hd0 hdK) + (cavityTrueDiagonal hd0 hdK) + rw [hgraph] at ht + exact ht + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/CascadeConstant.lean b/lean/OAI/Probability/Perceptron/Cascade/CascadeConstant.lean new file mode 100644 index 0000000000000000000000000000000000000000..c948470d8afe6406cc2669b4c5677537f41e089e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/CascadeConstant.lean @@ -0,0 +1,37 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.DecoratedWeightedTotal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory +namespace SphericalPerceptronFreeEnergy +lemma finiteCascadeLogRecursion_add_constant {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S→X) (H : X→ℝ) (k : ℕ) (z : Fin k→ℝ) + (hz : ∀ i,0c+H x) x= + c+finiteCascadeLogRecursion ν step k z H x := by + induction k generalizing x with + | zero => rfl + | succ k ih => + simp only [finiteCascadeLogRecursion,ih _ (fun i=>hz i.succ) hi.2,fractionalLogMoment] + simp_rw [mul_add,Real.exp_add] + rw [integral_const_mul,Real.log_mul (Real.exp_ne_zero _) (integral_exp_pos (hi.1 x)).ne',Real.log_exp] + field_simp [(hz 0).ne'] + +lemma finiteCascadeFractionalIntegrable_add_constant {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S→X) (H : X→ℝ) (k : ℕ) (z : Fin k→ℝ) + (hz : ∀ i,0c+H x) k z := by + induction k with + | zero => trivial + | succ k ih => + refine ⟨?_,ih _ (fun i=>hz i.succ) hi.2⟩ + intro x + simp only [finiteCascadeLogRecursion_add_constant ν step H k _ (fun i=>hz i.succ) hi.2 c,mul_add,Real.exp_add] + exact (hi.1 x).const_mul _ +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/CascadeHeat.lean b/lean/OAI/Probability/Perceptron/Cascade/CascadeHeat.lean new file mode 100644 index 0000000000000000000000000000000000000000..9642fb67879d9faff997eced606d19b87180e06b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/CascadeHeat.lean @@ -0,0 +1,133 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereHeat +import OAI.Probability.Perceptron.Variational.GaussianBackward +import OAI.Probability.Perceptron.Variational.AmplitudeConvex + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +def cascadeHeatWord (σ : ℕ → ℝ) : (k : ℕ) → (Fin k → ℝ) → List (ℝ×ℝ) + | 0, _ => [] + | k+1, z => (z 0,σ k)::cascadeHeatWord σ k (fun i => z i.succ) + +lemma cascadeHeatWord_nonneg (σ : ℕ → ℝ) (k : ℕ) (z : Fin k → ℝ) + (hz : ∀ i, 0 ≤ z i) : ∀ c ∈ cascadeHeatWord σ k z, 0 ≤ c.1 := by + induction k with + | zero => simp [cascadeHeatWord] + | succ k ih => + intro c hc + rcases List.mem_cons.mp hc with rfl | hc + · exact hz 0 + · exact ih (fun i => z i.succ) (fun i => hz i.succ) c hc + +def coordinateDepthField (d j : ℕ) (x : Fin d → ℕ → ℝ) : Spin d := + WithLp.toLp 2 (fun i => x i j) + +lemma coordinateDepthField_step (d j : ℕ) (σ : ℕ → ℝ) + (x : Fin d → ℕ → ℝ) (g : Fin d → ℝ) : + coordinateDepthField d j (canonicalCoordinateStep d σ (x,g))= + coordinateDepthField d (j+1) x+σ j • WithLp.toLp 2 g := by + rfl + +lemma integral_pi_standardGaussian (d : ℕ) {F : Spin d → ℝ} (hF : Continuous F) : + (∫ g, F (WithLp.toLp 2 g) ∂(piMarkLaw (fun _ : Fin d => standardGaussianMark) : Measure (Fin d → ℝ)))= + ∫ y, F y ∂stdGaussian (Spin d) := by + rw [← map_pi_eq_stdGaussian] + rw [integral_map (by fun_prop) hF.aestronglyMeasurable] + rfl + +lemma integrable_pi_standardGaussian (d : ℕ) {F : Spin d → ℝ} (hF : Continuous F) + (hI : Integrable F (stdGaussian (Spin d))) : + Integrable (fun g => F (WithLp.toLp 2 g)) + (piMarkLaw (fun _ : Fin d => standardGaussianMark)) := by + rw [← map_pi_eq_stdGaussian] at hI + exact (integrable_map_measure hF.aestronglyMeasurable (by fun_prop)).mp hI + +lemma coordinateRecursion_eq_backward (d : ℕ) (σ : ℕ → ℝ) + {f : Spin d → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (k : ℕ) (z : Fin k → ℝ) (hz : ∀ i, 0 < z i) : + (∀ x, finiteCascadeLogRecursion (piMarkLaw (fun _ : Fin d => standardGaussianMark)) + (canonicalCoordinateStep d σ) k z (fun x => f (coordinateLeafField d x)) x= + gaussianBackward (stdGaussian (Spin d)) (cascadeHeatWord σ k z) f (coordinateDepthField d k x)) ∧ + finiteCascadeFractionalIntegrable (piMarkLaw (fun _ : Fin d => standardGaussianMark)) + (canonicalCoordinateStep d σ) (fun x => f (coordinateLeafField d x)) k z := by + induction k with + | zero => exact ⟨fun _ => rfl,trivial⟩ + | succ k ih => + have H := ih (fun i => z i.succ) (fun i => hz i.succ) + have hl := gaussianBackward_lipschitz (stdGaussian (Spin d)) hf + (cascadeHeatWord σ k (fun i => z i.succ)) + (cascadeHeatWord_nonneg σ k _ (fun i => (hz i.succ).le)) + let g := gaussianBackward (stdGaussian (Spin d)) (cascadeHeatWord σ k (fun i => z i.succ)) f + have hg : LipschitzWith L g := hl + have hcont (x : Fin d → ℕ → ℝ) : Continuous (fun y : Spin d => + Real.exp (z 0*g (coordinateDepthField d (k+1) x+σ k • y))) := by + exact Real.continuous_exp.comp (continuous_const.mul (hg.continuous.comp + (continuous_const.add (continuous_id.const_smul (σ k))))) + constructor + · intro x + simp only [finiteCascadeLogRecursion,fractionalLogMoment,H.1,coordinateDepthField_step, + cascadeHeatWord,gaussianBackward] + rw [gaussianEntropic_pos _ hg (hz 0).ne'] + exact congrArg (fun t : ℝ => Real.log t / z 0) (integral_pi_standardGaussian d (hcont x)) + · constructor + · intro x + simp only [H.1,coordinateDepthField_step] + exact integrable_pi_standardGaussian d (hcont x) + (gaussian_integrable_exp_lipschitz (stdGaussian (Spin d)) hg (z 0) (σ k) + (coordinateDepthField d (k+1) x)) + · exact H.2 + +lemma decoratedAngularFactor_eq_terminal_log (n k : ℕ) (σ : ℕ → ℝ) (R : ℝ) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : + (decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p R).toReal= + decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) + (fun x => logSphericalExp n R (coordinateLeafField (n+1) x)) k p := by + rw [decoratedAngularFactor_eq n _ (canonicalCoordinateStep_measurable (n+1) σ) _ + (coordinateLeafField_measurable (n+1))] + unfold decoratedTerminalTotal + rw [← decoratedLeafIntegral_exp] + congr 2 + funext x + rw [logSphericalExp,Real.exp_log (lt_of_lt_of_le zero_lt_one (one_le_sphericalExp n _ R))] + +lemma coordinateAngularLog_conditional_expectation (n k : ℕ) (σ : ℕ → ℝ) (R : ℝ) + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (x : Fin (n+1) → ℕ → ℝ) : + (∫ η, coordinateAngularLog n k σ R (x,η) + ∂decoratedCascadeLaw (piMarkLaw (fun _ : Fin (n+1) => standardGaussianMark)) k z)= + gaussianBackward (stdGaussian (Spin (n+1))) (cascadeHeatWord σ k z) + (logSphericalExp n R) (coordinateDepthField (n+1) k x) := by + have H := coordinateRecursion_eq_backward (n+1) σ (logSphericalExp_lipschitz n R) k z hz0 + simp only [coordinateAngularLog,decoratedAngularFactor_eq_terminal_log] + exact (finiteCascade_terminal_log_recursion_of_fractional _ _ + (canonicalCoordinateStep_measurable (n+1) σ) k z hz hz0 hz1 + ((logSphericalExp_lipschitz n R).continuous.measurable.comp + (coordinateLeafField_measurable (n+1))) H.2 x).trans (H.1 x) + +lemma amplitudeSphereValue_eq_backward (n k : ℕ) (σ : ℕ → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (r : ℝ) : + amplitudeSphereValue n k σ z r= + gaussianBackward (stdGaussian (Spin (n+1))) ((0,r)::cascadeHeatWord σ k z) + (logSphericalExp n (Real.sqrt (n+1:ℕ))) 0/(n+1:ℕ) := by + have hl := gaussianBackward_lipschitz (stdGaussian (Spin (n+1))) + (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) (cascadeHeatWord σ k z) + (cascadeHeatWord_nonneg σ k z (fun i => (hz0 i).le)) + unfold amplitudeSphereValue coordinateCascadeLaw + rw [integral_prod _ (amplitudeSphereLog_integrable n k σ z hz hz0 hz1 r)] + simp only [amplitudeSphereLog,integral_div,coordinateAngularLog_conditional_expectation n k σ + (Real.sqrt (n+1:ℕ)) z hz hz0 hz1] + rw [gaussianBackward,gaussianEntropic_zero _ hl] + simp only [zero_add] + congr 1 + exact integral_pi_standardGaussian (n+1) (hl.continuous.comp (continuous_id.const_smul r)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/CascadeIndependentTilt.lean b/lean/OAI/Probability/Perceptron/Cascade/CascadeIndependentTilt.lean new file mode 100644 index 0000000000000000000000000000000000000000..d4140332b2bbd1399e4fc446d8e46433f191b6d3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/CascadeIndependentTilt.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ProductMarkLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +lemma decoratedTerminalTotal_pos_ae {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) + (hz1 : ∀ i, z i < 1) {H : X → ℝ} (hH : Measurable H) + (hI : finiteCascadeFractionalIntegrable ν step H n z) (x : X) : + ∀ᵐ η ∂(decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)), + 0 < decoratedTerminalTotal step H n (x,η) := by + have hid := decoratedWeightedTotal_identDistrib ν step hs n z hz0 hz1 + (finiteCascadeShifts ν step n z H) + (finiteCascadeShifts_measurable ν step hs n z hH) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z + (fun j => (hz0 j).ne') H hI i y).1) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z + (fun j => (hz0 j).ne') H hI i y).2) x + have hp := hid.symm.ae_snd measurableSet_Ioi (cascadeTotal_regular n z hz hz0 hz1).1 + filter_upwards [hp] with η hη + rw [decoratedTerminalTotal_telescoping ν step H n z] + exact mul_pos (Real.exp_pos _) hη + +lemma decoratedTerminalLogRatio_integrable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) + (hz1 : ∀ i, z i < 1) {H : X → ℝ} (hH : Measurable H) + (hI : finiteCascadeFractionalIntegrable ν step H n z) (x : X) : + Integrable (fun η => Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step (fun _ => 0) n (x,η))) + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) := by + simp_rw [decoratedTerminalTotal_zero,decoratedTerminalTotal_telescoping ν step H n z] + exact (decoratedCascade_log_second_moment_bound ν step hs n z hz hz0 hz1 + (finiteCascadeShifts ν step n z H) + (finiteCascadeShifts_measurable ν step hs n z hH) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z + (fun j => (hz0 j).ne') H hI i y).1) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z + (fun j => (hz0 j).ne') H hI i y).2) x + (finiteCascadeLogRecursion ν step n z H x)).1.integrable (by norm_num) + +theorem finiteCascade_terminal_log_ratio {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) + (hz1 : ∀ i, z i < 1) {H G : X → ℝ} (hH : Measurable H) (hG : Measurable G) + (hIH : finiteCascadeFractionalIntegrable ν step H n z) + (hIG : finiteCascadeFractionalIntegrable ν step G n z) (x : X) : + (∫ η, Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step G n (x,η)) ∂decoratedCascadeLaw ν n z) = + finiteCascadeLogRecursion ν step n z H x-finiteCascadeLogRecursion ν step n z G x := by + have h0 := finiteCascadeFractionalIntegrable_of_bounded ν step hs n z hz0 + (measurable_const : Measurable (fun _ : X => (0:ℝ))) (C := 0) (by simp) + have he : (fun η => Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step G n (x,η))) =ᵐ[(decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n))] + (fun η => Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step (fun _ => 0) n (x,η)) - + Real.log (decoratedTerminalTotal step G n (x,η) / + decoratedTerminalTotal step (fun _ => 0) n (x,η))) := by + filter_upwards [decoratedTerminalTotal_pos_ae ν step hs n z hz hz0 hz1 hH hIH x, + decoratedTerminalTotal_pos_ae ν step hs n z hz hz0 hz1 hG hIG x, + decoratedTerminalTotal_pos_ae ν step hs n z hz hz0 hz1 measurable_const h0 x] + with η hηH hηG hη0 + rw [Real.log_div hηH.ne' hηG.ne',Real.log_div hηH.ne' hη0.ne', + Real.log_div hηG.ne' hη0.ne'] + ring + rw [integral_congr_ae he,integral_sub + (decoratedTerminalLogRatio_integrable ν step hs n z hz hz0 hz1 hH hIH x) + (decoratedTerminalLogRatio_integrable ν step hs n z hz hz0 hz1 hG hIG x), + finiteCascade_terminal_log_recursion_of_fractional ν step hs n z hz hz0 hz1 hH hIH x, + finiteCascade_terminal_log_recursion_of_fractional ν step hs n z hz hz0 hz1 hG hIG x] + +lemma finiteCascadeFractionalIntegrable_add_product {X Y S T : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace S] [MeasurableSpace T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S → X) (step₂ : Y×T → Y) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, 0 < z i) {H : X → ℝ} {G : Y → ℝ} + (hIH : finiteCascadeFractionalIntegrable ν step₁ H n z) + (hIG : finiteCascadeFractionalIntegrable ρ step₂ G n z) : + finiteCascadeFractionalIntegrable (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) + (fun q => H q.1+G q.2) n z := by + induction n with + | zero => trivial + | succ n ih => + rcases hIH with ⟨hHroot,hHtail⟩ + rcases hIG with ⟨hGroot,hGtail⟩ + constructor + · intro x + simp_rw [finiteCascadeLogRecursion_add_product ν ρ step₁ step₂ n + (fun i => z i.succ) (fun i => hz i.succ) hHtail hGtail,mul_add,Real.exp_add] + exact (hHroot x.1).mul_prod (hGroot x.2) + · exact ih (fun i => z i.succ) (fun i => hz i.succ) hHtail hGtail + +theorem finiteCascade_independent_tilt_log {X Y S T : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace S] [MeasurableSpace T] + [Nonempty S] [Nonempty T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S → X) (step₂ : Y×T → Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) + (hz1 : ∀ i, z i < 1) {H : X → ℝ} {G : Y → ℝ} (hH : Measurable H) (hG : Measurable G) + (hIH : finiteCascadeFractionalIntegrable ν step₁ H n z) + (hIG : finiteCascadeFractionalIntegrable ρ step₂ G n z) (x : X) (y : Y) : + (∫ η, Real.log (decoratedTerminalTotal + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) + (fun q => H q.1+G q.2) n ((x,y),η) / + decoratedTerminalTotal + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) + (fun q => G q.2) n ((x,y),η)) ∂decoratedCascadeLaw (productMarkLaw ν ρ) n z) = + finiteCascadeLogRecursion ν step₁ n z H x := by + have h0 := finiteCascadeFractionalIntegrable_of_bounded ν step₁ hs₁ n z hz0 + (measurable_const : Measurable (fun _ : X => (0:ℝ))) (C := 0) (by simp) + have hprod0 := finiteCascadeFractionalIntegrable_add_product ν ρ step₁ step₂ n z hz0 h0 hIG + simp only [zero_add] at hprod0 + refine (finiteCascade_terminal_log_ratio (productMarkLaw ν ρ) _ (by fun_prop) n z hz hz0 hz1 + ((hH.comp measurable_fst).add (hG.comp measurable_snd)) (hG.comp measurable_snd) + (finiteCascadeFractionalIntegrable_add_product ν ρ step₁ step₂ n z hz0 hIH hIG) hprod0 (x,y)).trans ?_ + change finiteCascadeLogRecursion (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) n z + (fun q => H q.1+G q.2) (x,y) - + finiteCascadeLogRecursion (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) n z + (fun q => G q.2) (x,y) = _ + rw [finiteCascadeLogRecursion_add_product ν ρ step₁ step₂ n z hz0 hIH hIG] + have hzero := finiteCascadeLogRecursion_add_product ν ρ step₁ step₂ n z hz0 h0 hIG x y + simp only [zero_add] at hzero + rw [hzero] + have hzrec : finiteCascadeLogRecursion ν step₁ n z (fun _ => 0) x=0 := by + have hb := finiteCascadeLogRecursion_abs_le ν step₁ hs₁ n z hz0 + (measurable_const : Measurable (fun _ : X => (0:ℝ))) (C := 0) (by simp) x + exact abs_nonpos_iff.mp hb + rw [hzrec] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/CascadeParameters.lean b/lean/OAI/Probability/Perceptron/Cascade/CascadeParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e424870f0128196e9b81fe89975953c386af99e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/CascadeParameters.lean @@ -0,0 +1,79 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianMarkRecursion + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +section +variable {P X S : Type} [MeasurableSpace P] [MeasurableSpace X] [MeasurableSpace S] + +def parameterMarkStep (step : X×S → X) : (P×X)×S → P×X := + fun a => (a.1.1,step (a.1.2,a.2)) + +lemma parameterMarkStep_measurable {step : X×S → X} (hs : Measurable step) : + Measurable (parameterMarkStep (P := P) step) := + (measurable_fst.comp measurable_fst).prodMk + (hs.comp ((measurable_snd.comp measurable_fst).prodMk measurable_snd)) + +lemma decoratedTerminalTotalE_parameter (step : X×S → X) (H : P → X → ℝ) + (n : ℕ) (p : P) (x : X) (η : DecoratedCascade S n) : + decoratedTerminalTotalE (parameterMarkStep step) (Function.uncurry H) n ((p,x),η)= + decoratedTerminalTotalE step (H p) n (x,η) := by + induction n generalizing x with + | zero => rfl + | succ n ih => + apply lintegral_congr + intro q + congr 1 + exact ih (step (x,q.2.1)) q.2.2 + +lemma decoratedTerminalTotal_parameter (step : X×S → X) (H : P → X → ℝ) + (n : ℕ) (p : P) (x : X) (η : DecoratedCascade S n) : + decoratedTerminalTotal (parameterMarkStep step) (Function.uncurry H) n ((p,x),η)= + decoratedTerminalTotal step (H p) n (x,η) := + congrArg ENNReal.toReal (decoratedTerminalTotalE_parameter step H n p x η) + +end + +variable {P E : Type} [MeasurableSpace P] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] + +lemma gaussianLinearCascadeLog_parameter_measurable + (A : ℕ → E →L[ℝ] E) (R : E →L[ℝ] E) + {H : P → E → ℝ} (hH : Measurable (Function.uncurry H)) (k : ℕ) (z : Fin k → ℝ) : + Measurable (fun a : P × (E×DecoratedCascade E k) => + gaussianLinearCascadeLog A R (H a.1) k a.2) := by + let step := gaussianLinearMarkStep A + let V := fun p : P => fun x : ℕ → E => H p (x 0) + have hV : Measurable (Function.uncurry V) := hH.comp + (measurable_fst.prodMk ((measurable_pi_apply 0).comp measurable_snd)) + let T := fun a : P × (E×DecoratedCascade E k) => + ((a.1,fun _ : ℕ => R a.2.1),a.2.2) + have hT : Measurable T := + (measurable_fst.prodMk (Measurable.of_eval (fun _ => + R.measurable.comp (measurable_fst.comp measurable_snd)))).prodMk + (measurable_snd.comp measurable_snd) + let ν : ProbabilityMeasure E := gaussianMarkLaw + have hs : Measurable step := gaussianLinearMarkStep_measurable A + have h1 := (decoratedTerminalTotal_measurable ν (parameterMarkStep step) + (parameterMarkStep_measurable hs) hV k z).comp hT + have h0 := (decoratedTerminalTotal_measurable ν (parameterMarkStep step) + (parameterMarkStep_measurable hs) (H := Function.uncurry (fun (_ : P) (_ : ℕ → E) => (0:ℝ))) + measurable_const k z).comp hT + have he (a : P × (E×DecoratedCascade E k)) : + gaussianLinearCascadeLog A R (H a.1) k a.2= + Real.log (decoratedTerminalTotal (parameterMarkStep step) (Function.uncurry V) k (T a)/ + decoratedTerminalTotal (parameterMarkStep step) (Function.uncurry (fun (_ : P) (_ : ℕ → E) => (0:ℝ))) k (T a)) := by + rw [decoratedTerminalTotal_parameter,decoratedTerminalTotal_parameter] + rfl + simp_rw [he] + exact (h1.div h0).log +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/CascadeTransport.lean b/lean/OAI/Probability/Perceptron/Cascade/CascadeTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d6fc79959d926020bfcdfeea8653444ba8f1865 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/CascadeTransport.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.DecoratedWeightedTotal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma finiteCascadeLogRecursion_transport {X Y S T : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace S] [MeasurableSpace T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (a : X×S→X) (b : Y×T→Y) (hb : Measurable b) + (φ : X→Y) (r : S→T) (hr : MeasurePreserving r (ν:Measure S) (ρ:Measure T)) + (he : ∀ x s,φ (a (x,s))=b (φ x,r s)) + (H : Y→ℝ) (hH : Measurable H) (k : ℕ) (z : Fin k→ℝ) (x : X) : + finiteCascadeLogRecursion ν a k z (H ∘ φ) x= + finiteCascadeLogRecursion ρ b k z H (φ x) := by + induction k generalizing x with + | zero => rfl + | succ k ih => + simp only [finiteCascadeLogRecursion,fractionalLogMoment,ih,he] + congr 2 + have hm : Measurable (fun t=>Real.exp (z 0 * finiteCascadeLogRecursion ρ b k (fun i=>z i.succ) H (b (φ x,t)))) := (((finiteCascadeLogRecursion_measurable ρ b hb k (fun i=>z i.succ) hH).comp + (hb.comp (measurable_const.prodMk measurable_id))).const_mul (z 0)).exp + rw [←hr.map_eq,integral_map hr.measurable.aemeasurable hm.aestronglyMeasurable] + +lemma finiteCascadeFractionalIntegrable_transport {X Y S T : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace S] [MeasurableSpace T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (a : X×S→X) (b : Y×T→Y) (hb : Measurable b) + (φ : X→Y) (r : S→T) (hr : MeasurePreserving r (ν:Measure S) (ρ:Measure T)) + (he : ∀ x s,φ (a (x,s))=b (φ x,r s)) + (H : Y→ℝ) (hH : Measurable H) (k : ℕ) (z : Fin k→ℝ) + (hi : finiteCascadeFractionalIntegrable ρ b H k z) : + finiteCascadeFractionalIntegrable ν a (H ∘ φ) k z := by + induction k with + | zero => trivial + | succ k ih => + refine ⟨?_,ih _ hi.2⟩ + intro x + simp only [finiteCascadeLogRecursion_transport ν ρ a b hb φ r hr he H hH,he] + exact (hr.integrable_comp (hi.1 (φ x)).aestronglyMeasurable).mpr (hi.1 (φ x)) +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/CavityCappedRPC.lean b/lean/OAI/Probability/Perceptron/Cascade/CavityCappedRPC.lean new file mode 100644 index 0000000000000000000000000000000000000000..5223d9d28de0aa7c5813771aa834ba445f46bd6e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/CavityCappedRPC.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityDiagonalKernel +import OAI.Probability.Perceptron.Cavity.CavityIndexedLog + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavityDiagonalAverage_bounds {I : Type} [Fintype I] [DecidableEq I] + (σ : I→ℝ) (Ψ : EuclideanSpace ℝ I→ᵇℝ) {a b : ℝ} + (ha : ∀ z,a≤Ψ z) (hb : ∀ z,Ψ z≤b) (x : EuclideanSpace ℝ I) : + a≤cavityDiagonalAverage σ Ψ x ∧ cavityDiagonalAverage σ Ψ x≤b := by + have hm : Measurable (fun z : EuclideanSpace ℝ I=>Ψ (WithLp.toLp 2 (fun i=>x i+σ i*z i))) := by fun_prop + have hi : Integrable (fun z : EuclideanSpace ℝ I=>Ψ (WithLp.toLp 2 (fun i=>x i+σ i*z i))) + (stdGaussian (EuclideanSpace ℝ I)) := + Integrable.of_bound hm.aestronglyMeasurable ‖Ψ‖ (ae_of_all _ fun z=>Ψ.norm_coe_le_norm _) + change a≤∫ z,Ψ (WithLp.toLp 2 (fun i=>x i+σ i*z i)) ∂stdGaussian (EuclideanSpace ℝ I) ∧ + (∫ z,Ψ (WithLp.toLp 2 (fun i=>x i+σ i*z i)) ∂stdGaussian (EuclideanSpace ℝ I))≤b + constructor + · simpa only [integral_const,probReal_univ,one_smul] using + integral_mono (integrable_const a) hi (fun z=>ha _) + · simpa only [integral_const,probReal_univ,one_smul] using + integral_mono hi (integrable_const b) (fun z=>hb _) + +lemma cavityResidualCapped_bounds (n d : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (x : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + Real.exp (-(d:ℝ)*‖f‖)≤cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) x ∧ + cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) x≤Λ*Real.exp ((d:ℝ)*‖f‖) := + cavityDiagonalAverage_bounds σ _ (fun z=>(cavitySingleTest_bounds n d f Λ hΛ z).1) + (fun z=>(cavitySingleTest_bounds n d f Λ hΛ z).2) x + +lemma cavityResidualCapped_pos (n d : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (x : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + 0Real.log (cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) (s 0))) x := by + have hm : Measurable (fun s : ℕ→EuclideanSpace ℝ (Fin (n+1)⊕Fin d)=> + Real.log (cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) (s 0))) := + ((cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ)).measurable.comp (measurable_pi_apply 0)).log + have hh:=cavity_indexed_log_recursion (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + (gaussianLinearMarkStep A) (gaussianLinearMarkStep_measurable A) + (fun s=>Real.log (cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) (s 0))) hm + (fun s=>cavityResidualCapped_log_bound n d f Λ hΛ σ (s 0)) k z hz hz0 hz1 x + simpa only [Real.exp_log (cavityResidualCapped_pos n d f Λ hΛ σ _)] using hh + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/CavityFiniteRPC.lean b/lean/OAI/Probability/Perceptron/Cascade/CavityFiniteRPC.lean new file mode 100644 index 0000000000000000000000000000000000000000..d6e9b4d8f4f7ec1c576ee4d8a780ebf4c97ac34c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/CavityFiniteRPC.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.CascadeIndependentTilt +import OAI.Probability.Perceptron.Cascade.CascadeHeat + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev CavityRPCState (n d : ℕ) := (Fin (n+1)→ℕ→ℝ)×(Fin d→ℕ→ℝ) +abbrev CavityRPCMark (n d : ℕ) := (Fin (n+1)→ℝ)×(Fin d→ℝ) +def cavityRPCMarkLaw (n d : ℕ) : ProbabilityMeasure (CavityRPCMark n d) := + productMarkLaw (piMarkLaw (fun _ : Fin (n+1)=>standardGaussianMark)) + (piMarkLaw (fun _ : Fin d=>standardGaussianMark)) +def cavityRPCStep (n d : ℕ) (σ τ : ℕ→ℝ) : CavityRPCState n d×CavityRPCMark n d→CavityRPCState n d := + fun p=>(canonicalCoordinateStep (n+1) σ (p.1.1,p.2.1), + canonicalCoordinateStep d τ (p.1.2,p.2.2)) +def cavityRPCTerminal (n d : ℕ) (F : ℝ→ᵇℝ) (x : CavityRPCState n d) : ℝ := + logSphericalExp n (Real.sqrt (n+1:ℕ)) (coordinateLeafField (n+1) x.1)+∑ i,F (x.2 i 0) + +lemma cavityRPCStep_measurable (n d : ℕ) (σ τ : ℕ→ℝ) : Measurable (cavityRPCStep n d σ τ) := + ((canonicalCoordinateStep_measurable (n+1) σ).comp (measurable_fst.fst.prodMk measurable_snd.fst)).prodMk + ((canonicalCoordinateStep_measurable d τ).comp (measurable_fst.snd.prodMk measurable_snd.snd)) +lemma cavityRPCTerminal_measurable (n d : ℕ) (F : ℝ→ᵇℝ) : Measurable (cavityRPCTerminal n d F) := by + have hv : Measurable (fun x : CavityRPCState n d=>logSphericalExp n (Real.sqrt (n+1:ℕ)) + (coordinateLeafField (n+1) x.1)) := (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))).continuous.measurable.comp + ((coordinateLeafField_measurable (n+1)).comp measurable_fst) + apply hv.add + exact Finset.measurable_sum _ fun i _=>F.measurable.comp ((measurable_pi_apply 0).comp + ((measurable_pi_apply i).comp measurable_snd)) + +theorem cavity_finiteRPC_conditional (n d k : ℕ) (σ τ : ℕ→ℝ) (F : ℝ→ᵇℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0Real.log (decoratedTerminalTotal (cavityRPCStep n d σ τ) + (cavityRPCTerminal n d F) k (x,η)/ + decoratedTerminalTotal (cavityRPCStep n d σ τ) (fun _=>0) k (x,η))) + (decoratedCascadeLaw (cavityRPCMarkLaw n d) k z) ∧ + (∫ η,Real.log (decoratedTerminalTotal (cavityRPCStep n d σ τ) + (cavityRPCTerminal n d F) k (x,η)/ + decoratedTerminalTotal (cavityRPCStep n d σ τ) (fun _=>0) k (x,η)) + ∂decoratedCascadeLaw (cavityRPCMarkLaw n d) k z)= + gaussianBackward (stdGaussian (Spin (n+1))) (cascadeHeatWord σ k z) + (logSphericalExp n (Real.sqrt (n+1:ℕ))) (coordinateDepthField (n+1) k x.1)+ + ∑ i,finiteCascadeLogRecursion standardGaussianMark (gaussianShiftStep τ) k z + (fun a=>F (a 0)) (x.2 i) := by + have hF : Measurable (fun a : ℕ→ℝ=>F (a 0)) := F.measurable.comp (measurable_pi_apply 0) + have hFI := finiteCascadeFractionalIntegrable_of_bounded standardGaussianMark + (gaussianShiftStep τ) (gaussianShiftStep_measurable τ) k z hz0 hF + (fun a=>F.norm_coe_le_norm (a 0)) + have hs := finiteCascade_sum_pi (fun _ : Fin d=>standardGaussianMark) + (fun _=>gaussianShiftStep τ) k z (fun _ a=>F (a 0)) (fun _=>hFI) + have hv := coordinateRecursion_eq_backward (n+1) σ + (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) k z hz0 + have hi := finiteCascadeFractionalIntegrable_add_product + (piMarkLaw (fun _ : Fin (n+1)=>standardGaussianMark)) + (piMarkLaw (fun _ : Fin d=>standardGaussianMark)) + (canonicalCoordinateStep (n+1) σ) (canonicalCoordinateStep d τ) k z hz0 hv.2 hs.2 + constructor + · exact decoratedTerminalLogRatio_integrable (cavityRPCMarkLaw n d) (cavityRPCStep n d σ τ) + (cavityRPCStep_measurable n d σ τ) k z hz hz0 hz1 + (cavityRPCTerminal_measurable n d F) hi x + · rw [finiteCascade_terminal_log_recursion_of_fractional (cavityRPCMarkLaw n d) + (cavityRPCStep n d σ τ) (cavityRPCStep_measurable n d σ τ) k z hz hz0 hz1 + (cavityRPCTerminal_measurable n d F) hi x] + exact (finiteCascadeLogRecursion_add_product + (piMarkLaw (fun _ : Fin (n+1)=>standardGaussianMark)) + (piMarkLaw (fun _ : Fin d=>standardGaussianMark)) + (canonicalCoordinateStep (n+1) σ) (canonicalCoordinateStep d τ) k z hz0 hv.2 hs.2 x.1 x.2).trans + (congrArg₂ (fun a b : ℝ=>a+b) (hv.1 x.1) (hs.1 x.2)) + + +def cavityScalarRootValue (k : ℕ) (τ : ℕ→ℝ) (z : Fin k→ℝ) (t : ℝ) (F : ℝ→ᵇℝ) : ℝ := + ∫ b, finiteCascadeLogRecursion standardGaussianMark (gaussianShiftStep τ) k z + (fun x=>F (x 0)) (fun _=>t*b) ∂(standardGaussianMark : Measure ℝ) + +def cavityRPCRootState (n d : ℕ) (r t : ℝ) (b : CavityRPCMark n d) : CavityRPCState n d := + (fun i _=>r*b.1 i,fun i _=>t*b.2 i) + +lemma cavity_scalar_recursion_bound (k : ℕ) (τ : ℕ→ℝ) (z : Fin k→ℝ) + (hz0 : ∀ i,0F (x 0)) x|≤‖F‖ := + finiteCascadeLogRecursion_abs_le standardGaussianMark (gaussianShiftStep τ) + (gaussianShiftStep_measurable τ) k z hz0 + (F.measurable.comp (measurable_pi_apply 0)) (fun a=>F.norm_coe_le_norm (a 0)) x + +lemma cavity_scalar_root_pi_mean (d k : ℕ) (τ : ℕ→ℝ) (z : Fin k→ℝ) + (hz0 : ∀ i,0F (x 0)) (fun _=>t*b i)) + ∂(piMarkLaw (fun _ : Fin d=>standardGaussianMark) : Measure (Fin d→ℝ)))= + d*cavityScalarRootValue k τ z t F := by + have hm := finiteCascadeLogRecursion_measurable standardGaussianMark (gaussianShiftStep τ) + (gaussianShiftStep_measurable τ) k z (F.measurable.comp (measurable_pi_apply 0)) + have hi (i : Fin d) : Integrable (fun b : Fin d→ℝ=>finiteCascadeLogRecursion + standardGaussianMark (gaussianShiftStep τ) k z (fun x=>F (x 0)) (fun _=>t*b i)) + (piMarkLaw (fun _ : Fin d=>standardGaussianMark)) := by + apply Integrable.of_bound (hm.comp (Measurable.of_eval (fun _=>measurable_const.mul + (measurable_pi_apply i)))).aestronglyMeasurable ‖F‖ + exact ae_of_all _ fun b=>by + change |finiteCascadeLogRecursion standardGaussianMark (gaussianShiftStep τ) k z + (fun x=>F (x 0)) (fun _=>t*b i)|≤‖F‖ + exact cavity_scalar_recursion_bound k τ z hz0 F _ + rw [integral_finsetSum _ (fun index _=>hi index)] + have he (i : Fin d) : (∫ b : Fin d→ℝ,finiteCascadeLogRecursion standardGaussianMark + (gaussianShiftStep τ) k z (fun x=>F (x 0)) (fun _=>t*b i) + ∂(piMarkLaw (fun _ : Fin d=>standardGaussianMark) : Measure (Fin d→ℝ)))= + cavityScalarRootValue k τ z t F := by + have hmp := measurePreserving_eval (fun _ : Fin d=>(standardGaussianMark : Measure ℝ)) i + unfold cavityScalarRootValue + rw [←hmp.map_eq] + exact (integral_map hmp.measurable.aemeasurable + ((hm.comp (Measurable.of_eval (fun _=>measurable_const.mul measurable_id))).aestronglyMeasurable)).symm + simp_rw [he] + simp + +theorem cavity_finiteRPC_roots (n d k : ℕ) (σ τ : ℕ→ℝ) (F : ℝ→ᵇℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,00) k + (cavityRPCRootState n d r t b,η)) + ∂decoratedCascadeLaw (cavityRPCMarkLaw n d) k z) + ∂(cavityRPCMarkLaw n d : Measure (CavityRPCMark n d)))= + (n+1:ℕ)*amplitudeSphereValue n k σ z r+d*cavityScalarRootValue k τ z t F := by + have hl := gaussianBackward_lipschitz (stdGaussian (Spin (n+1))) + (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) (cascadeHeatWord σ k z) + (cascadeHeatWord_nonneg σ k z (fun i=>(hz0 i).le)) + let V := fun b : Fin (n+1)→ℝ=>gaussianBackward (stdGaussian (Spin (n+1))) + (cascadeHeatWord σ k z) (logSphericalExp n (Real.sqrt (n+1:ℕ))) + (r • WithLp.toLp 2 b) + let W := fun b : Fin d→ℝ=>∑ i,finiteCascadeLogRecursion standardGaussianMark + (gaussianShiftStep τ) k z (fun x=>F (x 0)) (fun _=>t*b i) + have hV : Integrable V (piMarkLaw (fun _ : Fin (n+1)=>standardGaussianMark)) := + integrable_pi_standardGaussian (n+1) (hl.continuous.comp (continuous_id.const_smul r)) + (by simpa only [zero_add,Function.comp_def,Pi.smul_apply,id_eq] using (gaussian_integrable_lipschitz + (stdGaussian (Spin (n+1))) hl r (0 : Spin (n+1)))) + have hW : Integrable W (piMarkLaw (fun _ : Fin d=>standardGaussianMark)) := by + apply integrable_finsetSum + intro i _ + have hm := finiteCascadeLogRecursion_measurable standardGaussianMark (gaussianShiftStep τ) + (gaussianShiftStep_measurable τ) k z (F.measurable.comp (measurable_pi_apply 0)) + apply Integrable.of_bound (hm.comp (Measurable.of_eval (fun _=>measurable_const.mul + (measurable_pi_apply i)))).aestronglyMeasurable ‖F‖ + exact ae_of_all _ fun b=>by + change |finiteCascadeLogRecursion standardGaussianMark (gaussianShiftStep τ) k z + (fun x=>F (x 0)) (fun _=>t*b i)|≤‖F‖ + exact cavity_scalar_recursion_bound k τ z hz0 F _ + simp_rw [(cavity_finiteRPC_conditional n d k σ τ F z hz hz0 hz1 _).2] + change (∫ b,V b.1+W b.2 ∂(piMarkLaw (fun _ : Fin (n+1)=>standardGaussianMark) : Measure _).prod + (piMarkLaw (fun _ : Fin d=>standardGaussianMark)))=_ + rw [integral_add (hV.comp_fst _) (hW.comp_snd _),integral_fun_fst,integral_fun_snd] + simp only [probReal_univ,one_smul] + rw [show (∫ b,W b ∂(piMarkLaw (fun _ : Fin d=>standardGaussianMark) : Measure _))= + d*cavityScalarRootValue k τ z t F from cavity_scalar_root_pi_mean d k τ z hz0 t F] + congr 1 + have he := amplitudeSphereValue_eq_backward n k σ z hz hz0 hz1 r + rw [gaussianBackward,gaussianEntropic_zero _ hl] at he + simp only [zero_add] at he + have hpi : (∫ b,V b ∂(piMarkLaw (fun _ : Fin (n+1)=>standardGaussianMark) : Measure _))= + ∫ y,gaussianBackward (stdGaussian (Spin (n+1))) (cascadeHeatWord σ k z) + (logSphericalExp n (Real.sqrt (n+1:ℕ))) (r • y) ∂stdGaussian (Spin (n+1)) := + integral_pi_standardGaussian (n+1) (show Continuous (fun y : Spin (n+1)=> + gaussianBackward (stdGaussian (Spin (n+1))) (cascadeHeatWord σ k z) + (logSphericalExp n (Real.sqrt (n+1:ℕ))) (r • y)) from + hl.continuous.comp (continuous_id.const_smul r)) + rw [hpi,he] + field_simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/CavityRPCControl.lean b/lean/OAI/Probability/Perceptron/Cascade/CavityRPCControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..297f22aedebcc2dd2329b21e64e7ddc344147d84 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/CavityRPCControl.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.Perceptron.Control.LabelProfileControl +import OAI.Probability.Perceptron.Cascade.CavityFiniteRPC + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_scalar_vector_recursion (τ : ℕ→ℝ) (F : ℝ→ᵇℝ) + (k : ℕ) (z : Fin k→ℝ) (x : ℕ→Spin 1) : + finiteCascadeLogRecursion (gaussianMarkLaw : ProbabilityMeasure (Spin 1)) + (gaussianLinearMarkStep (fun j=>diagonalMark (fun _ : Fin 1=>τ j))) k z + (fun x=>F (x 0 0)) x= + finiteCascadeLogRecursion standardGaussianMark (gaussianShiftStep τ) k z + (fun x=>F (x 0)) (fun j=>x j 0) := by + induction k generalizing x with + | zero => rfl + | succ k ih => + simp only [finiteCascadeLogRecursion,fractionalLogMoment,ih] + congr 2 + let G := fun b : ℝ=>Real.exp (z 0*finiteCascadeLogRecursion standardGaussianMark + (gaussianShiftStep τ) k (fun i=>z i.succ) (fun x=>F (x 0)) + (gaussianShiftStep τ ((fun j=>x j 0),b))) + have hm := finiteCascadeLogRecursion_measurable standardGaussianMark (gaussianShiftStep τ) + (gaussianShiftStep_measurable τ) k (fun i=>z i.succ) + (F.measurable.comp (measurable_pi_apply 0)) + have hG : Measurable G := Real.measurable_exp.comp (measurable_const.mul + (hm.comp ((gaussianShiftStep_measurable τ).comp (measurable_const.prodMk measurable_id)))) + have he := integral_map (μ:=stdGaussian (Spin 1)) (show Measurable (fun v : Spin 1=>v 0) from by fun_prop).aemeasurable + hG.aestronglyMeasurable + rw [stdGaussian_coordinate_law] at he + exact he.symm + +lemma cavityScalarRootValue_eq_label (k : ℕ) (z : Fin k→ℝ) (hz0 : ∀ i,0profileGaussianStep (fun l (_ : Fin 1)=>q l) j 0) + z (Real.sqrt (q 0)) (g.heatLog ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩ 1).f= + labelProfileValue k z q hq1 g := by + let s : ℝ≥0 := ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩ + let τ := fun j=>profileGaussianStep (fun l (_ : Fin 1)=>q l) j 0 + let A := fun j=>diagonalMark (profileGaussianStep (fun l (_ : Fin 1)=>q l) j) + have hA : (fun j=>diagonalMark (fun _ : Fin 1=>τ j))=A := by + rfl + have hF : (fun v : Spin 1=>(g.heatLog s 1).f (v 0))=labelProfileTerminal g s := by + funext v + rw [labelProfileTerminal,oneDim_inner,Jet3.heatLog_f] + rfl + let : IsGaussian (gaussianMarkLaw (E:=Spin 1) : Measure (Spin 1)) := + (inferInstance : IsGaussian (stdGaussian (Spin 1))) + have hr := (gaussianLinearRecursion_realization (gaussianMarkLaw (E:=Spin 1)) A + (labelProfileTerminal_lipschitz g s) k z hz0).1 + have hs (v : Spin 1) : + finiteCascadeLogRecursion standardGaussianMark (gaussianShiftStep τ) k z + (fun x=>(g.heatLog s 1).f (x 0)) (fun _=>Real.sqrt (q 0)*v 0)= + gaussianLinearBackward (stdGaussian (Spin 1)) (linearCascadeWord A k z) + (labelProfileTerminal g s) (diagonalMark (profileGaussianRoot (fun l (_ : Fin 1)=>q l)) v) := by + have H := cavity_scalar_vector_recursion τ (g.heatLog s 1).f k z + (fun _=>diagonalMark (profileGaussianRoot (fun l (_ : Fin 1)=>q l)) v) + rw [hA] at H + have ht : (fun x : ℕ→Spin 1=>(g.heatLog s 1).f (x 0 0))= + fun x=>labelProfileTerminal g s (x 0) := funext (fun x=>congrFun hF (x 0)) + rw [ht,hr] at H + exact H.symm + unfold cavityScalarRootValue labelProfileValue + change (∫ b,finiteCascadeLogRecursion standardGaussianMark (gaussianShiftStep τ) k z + (fun x=>(g.heatLog s 1).f (x 0)) (fun _=>Real.sqrt (q 0)*b) + ∂(standardGaussianMark : Measure ℝ))=_ + have hm := finiteCascadeLogRecursion_measurable standardGaussianMark (gaussianShiftStep τ) + (gaussianShiftStep_measurable τ) k z ((g.heatLog s 1).f.measurable.comp (measurable_pi_apply 0)) + have hroot : Measurable (fun b : ℝ=>finiteCascadeLogRecursion standardGaussianMark + (gaussianShiftStep τ) k z (fun x=>(g.heatLog s 1).f (x 0)) + (fun _=>Real.sqrt (q 0)*b)) := + hm.comp (Measurable.of_eval (fun _=>measurable_const.mul measurable_id)) + have he := integral_map (μ:=stdGaussian (Spin 1)) (show Measurable (fun v : Spin 1=>v 0) from by fun_prop).aemeasurable + hroot.aestronglyMeasurable + rw [stdGaussian_coordinate_law] at he + exact he.trans (integral_congr_ae (ae_of_all _ hs)) + +theorem cavityScalarRootValue_control (k : ℕ) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i,0≤w i) (hw1 : ∑ i,w i=1) (hq : Monotone q) + (hz0 : ∀ i,0profileGaussianStep (fun l (_ : Fin 1)=>(q l:ℝ)) j 0) + (stepCumulative w) (Real.sqrt (q 0 : ℝ)) + (g.heatLog ⟨1-(q (Fin.last k):ℝ),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ 1).f= + controlValue P g.f (weightedStepTrial w q hw hw1) := by + rw [cavityScalarRootValue_eq_label k (stepCumulative w) hz0] + exact labelProfileValue_control k w q hw hw1 hq g P hB + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/DecoratedWeightedTotal.lean b/lean/OAI/Probability/Perceptron/Cascade/DecoratedWeightedTotal.lean new file mode 100644 index 0000000000000000000000000000000000000000..2aef50c07d2cd8f5cc0356bf29e56b92739e589e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/DecoratedWeightedTotal.lean @@ -0,0 +1,427 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FocusedShapeProbability + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy + +lemma decoratedWeightedTotalE_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (hstep : Measurable step) (n : ℕ) (F : Fin n → X×S → ℝ) + (hF : ∀ i, Measurable (F i)) : Measurable (decoratedWeightedTotalE step n F) := by + have he : decoratedWeightedTotalE step n F = cascadeTotalE n ∘ decoratedCascadeTransform step n F := by + funext p + exact (decoratedWeightedTotalE_transform step hstep n F hF p).symm + rw [he] + exact (cascadeTotalE_measurable n).comp (decoratedCascadeTransform_measurable step hstep n F hF) + +lemma decoratedWeightedTotalE_counting {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin (n+1) → ℝ) (hz0 : 0 < z 0) (hz1 : z 0 < 1) + (F : Fin (n+1) → X×S → ℝ) (x : X) : + ∀ᵐ η ∂(decoratedCascadeLaw ν (n+1) z : Measure (DecoratedCascade S (n+1))), + decoratedWeightedTotalE step (n+1) F (x,η) = + ∫⁻ q : ℝ×(S×DecoratedCascade S n), ENNReal.ofReal (Real.exp (q.1+F 0 (x,q.2.1))) * + decoratedWeightedTotalE step n (fun i => F i.succ) (step (x,q.2.1),q.2.2) ∂η := by + have hreg := markedStableCountKernel_ae_eq + ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ) : Measure (DecoratedCascade S n))) hz0 hz1 + apply hreg.mono + intro η hη + conv_lhs => rw [decoratedWeightedTotalE] + rw [hη] + +def decoratedWeightedTotal {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) (p : X×DecoratedCascade S n) : ℝ := + (decoratedWeightedTotalE step n F p).toReal + +lemma decoratedWeightedTotal_transform {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (hstep : Measurable step) (n : ℕ) (F : Fin n → X×S → ℝ) + (hF : ∀ i, Measurable (F i)) (p : X×DecoratedCascade S n) : + decoratedWeightedTotal step n F p = cascadeTotal n (decoratedCascadeTransform step n F p) := + congrArg ENNReal.toReal (decoratedWeightedTotalE_transform step hstep n F hF p).symm + +lemma decoratedWeightedTotal_identDistrib {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hstep : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + IdentDistrib (fun η => decoratedWeightedTotal step n F (x,η)) (cascadeTotal n) + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) (cascadeLaw n z) := by + have hT : Measurable (fun η => decoratedCascadeTransform step n F (x,η)) := + (decoratedCascadeTransform_measurable step hstep n F hF).comp (measurable_const.prodMk measurable_id) + have he : (fun η => decoratedWeightedTotal step n F (x,η)) = + cascadeTotal n ∘ (fun η => decoratedCascadeTransform step n F (x,η)) := by + funext η + exact decoratedWeightedTotal_transform step hstep n F hF (x,η) + rw [he] + refine ⟨((cascadeTotal_measurable n).comp hT).aemeasurable,(cascadeTotal_measurable n).aemeasurable,?_⟩ + rw [← Measure.map_map (cascadeTotal_measurable n) hT,decoratedCascadeTransform_law ν step hstep n z hz0 hz1 F hF hI hM] + +theorem decoratedCascade_log_identity {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hstep : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) (c : ℝ) : + (∫ η, Real.log (Real.exp c*decoratedWeightedTotal step n F (x,η) / + decoratedWeightedTotal step n (fun _ _ => 0) (x,η)) ∂(decoratedCascadeLaw ν n z)) = c := by + have hid := decoratedWeightedTotal_identDistrib ν step hstep n z hz0 hz1 F hF hI hM x + have hiz := decoratedWeightedTotal_identDistrib ν step hstep n z hz0 hz1 (fun _ _ => 0) + (fun _ => measurable_const) (by intro i y; simp only [mul_zero,Real.exp_zero]; exact integrable_const 1) + (by intro i y; simp) x + have hld := hid.comp Real.measurable_log + have hlz := hiz.comp Real.measurable_log + have hL := cascadeTotal_log_memLp_two n z hz hz0 hz1 + have hId := MemLp.integrable (by norm_num : (1:ℝ≥0∞) ≤ 2) (hld.memLp_iff.mpr hL) + have hIz := MemLp.integrable (by norm_num : (1:ℝ≥0∞) ≤ 2) (hlz.memLp_iff.mpr hL) + have hp := (cascadeTotal_regular n z hz hz0 hz1).1 + have hdpos := hid.symm.ae_snd measurableSet_Ioi hp + have hzpos := hiz.symm.ae_snd measurableSet_Ioi hp + have he : (fun η => Real.log (Real.exp c*decoratedWeightedTotal step n F (x,η) / + decoratedWeightedTotal step n (fun _ _ => 0) (x,η))) =ᵐ[(decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n))] + (fun η => c+Real.log (decoratedWeightedTotal step n F (x,η))- + Real.log (decoratedWeightedTotal step n (fun _ _ => 0) (x,η))) := by + filter_upwards [hdpos,hzpos] with η hη hg + rw [Real.log_div (mul_ne_zero (Real.exp_ne_zero _) hη.ne') hg.ne', + Real.log_mul (Real.exp_ne_zero _) hη.ne',Real.log_exp] + have hsplit := integral_sub ((integrable_const c).add hId) hIz + have hadd := integral_add (integrable_const c) hId + have hdint := hld.integral_eq + have hzint := hlz.integral_eq + simp only [Pi.add_apply,Function.comp_apply] at hsplit hadd hdint hzint + rw [integral_congr_ae he,hsplit,hadd,hdint,hzint] + simp + +lemma decoratedCascade_log_difference_memLp {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hstep : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + MemLp (fun η => Real.log (decoratedWeightedTotal step n F (x,η))- + Real.log (decoratedWeightedTotal step n (fun _ _ => 0) (x,η))) 2 + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) := by + have hid := decoratedWeightedTotal_identDistrib ν step hstep n z hz0 hz1 F hF hI hM x + have hiz := decoratedWeightedTotal_identDistrib ν step hstep n z hz0 hz1 (fun _ _ => 0) + (fun _ => measurable_const) (by intro i y; simp only [mul_zero,Real.exp_zero]; exact integrable_const 1) + (by intro i y; simp) x + have hld := hid.comp Real.measurable_log + have hlz := hiz.comp Real.measurable_log + have hL := cascadeTotal_log_memLp_two n z hz hz0 hz1 + exact (hld.memLp_iff.mpr hL).sub (hlz.memLp_iff.mpr hL) + +def fractionalLogMoment {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (b : ℝ) (f : X×S → ℝ) (x : X) : ℝ := + Real.log (∫ s, Real.exp (b*f (x,s)) ∂ν)/b + +lemma fractionalLogMoment_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (b : ℝ) {f : X×S → ℝ} (hf : Measurable f) : + Measurable (fractionalLogMoment ν b f) := by + exact (((hf.const_mul b).exp.stronglyMeasurable.integral_prod_right').measurable.log).div_const b + +lemma bounded_fractional_exp_integrable {S : Type} [MeasurableSpace S] + (ν : ProbabilityMeasure S) {b C : ℝ} (hb : 0 ≤ b) {f : S → ℝ} + (hf : Measurable f) (hC : ∀ s, |f s| ≤ C) : + Integrable (fun s => Real.exp (b*f s)) ν := by + apply (integrable_const (Real.exp (b*C))).mono' ((hf.const_mul b).exp).aestronglyMeasurable + exact ae_of_all _ fun s => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (le_trans (le_abs_self _) (hC s)) hb) + +lemma fractionalLogMoment_abs_le {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) {b C : ℝ} (hb : 0 < b) {f : X×S → ℝ} + (hf : Measurable f) (hC : ∀ p, |f p| ≤ C) (x : X) : + |fractionalLogMoment ν b f x| ≤ C := by + have hI := bounded_fractional_exp_integrable ν hb.le + (hf.comp (measurable_const.prodMk measurable_id)) (fun s => hC (x,s)) + have hp : 0 < ∫ s, Real.exp (b*f (x,s)) ∂ν := by + apply integral_pos_iff_support_of_nonneg (fun _ => (Real.exp_pos _).le) hI |>.mpr + simp [Function.support,Real.exp_ne_zero] + have hlo : Real.exp (b*(-C)) ≤ ∫ s, Real.exp (b*f (x,s)) ∂ν := by + have h := integral_mono (integrable_const (Real.exp (b*(-C)))) hI + (fun s => Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (abs_le.mp (hC (x,s))).1 hb.le)) + simpa using h + have hup : (∫ s, Real.exp (b*f (x,s)) ∂ν) ≤ Real.exp (b*C) := by + have h := integral_mono hI (integrable_const (Real.exp (b*C))) + (fun s => Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (abs_le.mp (hC (x,s))).2 hb.le)) + simpa using h + have hl := Real.log_le_log (Real.exp_pos _) hlo + have hu := Real.log_le_log hp hup + rw [Real.log_exp] at hl hu + apply abs_le.mpr + change -C ≤ Real.log _/b ∧ Real.log _/b ≤ C + constructor + · apply (le_div_iff₀ hb).mpr + nlinarith + · apply (div_le_iff₀ hb).mpr + nlinarith + +lemma fractionalLogMoment_centered {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) {b : ℝ} (hb : b ≠ 0) {f : X×S → ℝ} (x : X) + (hI : Integrable (fun s => Real.exp (b*f (x,s))) ν) : + Integrable (fun s => Real.exp (b*(f (x,s)-fractionalLogMoment ν b f x))) ν ∧ + (∫ s, Real.exp (b*(f (x,s)-fractionalLogMoment ν b f x)) ∂ν) = 1 := by + have hp : 0 < ∫ s, Real.exp (b*f (x,s)) ∂ν := by + apply integral_pos_iff_support_of_nonneg (fun _ => (Real.exp_pos _).le) hI |>.mpr + simp [Function.support,Real.exp_ne_zero] + have hfac (s : S) : Real.exp (b*(f (x,s)-fractionalLogMoment ν b f x)) = + Real.exp (-(Real.log (∫ t, Real.exp (b*f (x,t)) ∂ν)))*Real.exp (b*f (x,s)) := by + rw [← Real.exp_add] + congr 1 + unfold fractionalLogMoment + field_simp + ring + constructor + · simp_rw [hfac] + exact hI.const_mul _ + · simp_rw [hfac] + rw [integral_const_mul,Real.exp_neg,Real.exp_log hp,inv_mul_cancel₀ hp.ne'] + +def finiteCascadeLogRecursion {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) : + (n : ℕ) → (Fin n → ℝ) → (X → ℝ) → X → ℝ + | 0, _, H => H + | n+1, z, H => fractionalLogMoment ν (z 0) + (fun p => finiteCascadeLogRecursion ν step n (fun i => z i.succ) H (step p)) + +lemma finiteCascadeLogRecursion_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) {H : X → ℝ} (hH : Measurable H) : + Measurable (finiteCascadeLogRecursion ν step n z H) := by + induction n with + | zero => exact hH + | succ n ih => exact fractionalLogMoment_measurable ν (z 0) ((ih (fun i => z i.succ)).comp hs) + +lemma finiteCascadeLogRecursion_abs_le {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, 0 < z i) {H : X → ℝ} (hH : Measurable H) + {C : ℝ} (hC : ∀ x, |H x| ≤ C) : ∀ x, |finiteCascadeLogRecursion ν step n z H x| ≤ C := by + induction n with + | zero => exact hC + | succ n ih => + exact fractionalLogMoment_abs_le ν (hz 0) + ((finiteCascadeLogRecursion_measurable ν step hs n (fun i => z i.succ) hH).comp hs) + (fun p => ih (fun i => z i.succ) (fun i => hz i.succ) (step p)) + +def finiteCascadeShifts {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) : + (n : ℕ) → (Fin n → ℝ) → (X → ℝ) → Fin n → X×S → ℝ + | 0, _, _ => Fin.elim0 + | n+1, z, H => Fin.cases + (fun p => finiteCascadeLogRecursion ν step n (fun i => z i.succ) H (step p) - + finiteCascadeLogRecursion ν step (n+1) z H p.1) + (finiteCascadeShifts ν step n (fun i => z i.succ) H) + +lemma finiteCascadeShifts_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) {H : X → ℝ} (hH : Measurable H) : + ∀ i, Measurable (finiteCascadeShifts ν step n z H i) := by + induction n with + | zero => intro i; exact i.elim0 + | succ n ih => + intro i + refine Fin.cases ?_ (fun j => ih (fun k => z k.succ) j) i + exact ((finiteCascadeLogRecursion_measurable ν step hs n (fun j => z j.succ) hH).comp hs).sub + ((finiteCascadeLogRecursion_measurable ν step hs (n+1) z hH).comp measurable_fst) + +lemma finiteCascadeShifts_normalized {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, 0 < z i) {H : X → ℝ} (hH : Measurable H) + {C : ℝ} (hC : ∀ x, |H x| ≤ C) : ∀ i x, + Integrable (fun s => Real.exp (z i*finiteCascadeShifts ν step n z H i (x,s))) ν ∧ + (∫ s, Real.exp (z i*finiteCascadeShifts ν step n z H i (x,s)) ∂ν) = 1 := by + induction n with + | zero => intro i; exact i.elim0 + | succ n ih => + intro i + refine Fin.cases ?_ (fun j => ih (fun k => z k.succ) (fun k => hz k.succ) j) i + intro x + apply fractionalLogMoment_centered ν (hz 0).ne' (f := fun p => finiteCascadeLogRecursion ν step n (fun j => z j.succ) H (step p)) x + apply bounded_fractional_exp_integrable ν (hz 0).le + (((finiteCascadeLogRecursion_measurable ν step hs n (fun j => z j.succ) hH).comp hs).comp + (measurable_const.prodMk measurable_id)) + exact fun s => finiteCascadeLogRecursion_abs_le ν step hs n (fun j => z j.succ) + (fun j => hz j.succ) hH hC (step (x,s)) + +def decoratedTerminalTotalE {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (H : X → ℝ) : (n : ℕ) → X×DecoratedCascade S n → ℝ≥0∞ + | 0, p => ENNReal.ofReal (Real.exp (H p.1)) + | n+1, p => ∫⁻ q : ℝ×(S×DecoratedCascade S n), ENNReal.ofReal (Real.exp q.1) * + decoratedTerminalTotalE step H n (step (p.1,q.2.1),q.2.2) ∂markedStableCountKernel p.2 + +lemma decoratedTerminalTotalE_telescoping {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (H : X → ℝ) + (n : ℕ) (z : Fin n → ℝ) (p : X×DecoratedCascade S n) : + decoratedTerminalTotalE step H n p = + ENNReal.ofReal (Real.exp (finiteCascadeLogRecursion ν step n z H p.1)) * + decoratedWeightedTotalE step n (finiteCascadeShifts ν step n z H) p := by + induction n with + | zero => simp [decoratedTerminalTotalE,finiteCascadeLogRecursion,decoratedWeightedTotalE] + | succ n ih => + conv_lhs => rw [decoratedTerminalTotalE] + conv_rhs => arg 2; rw [decoratedWeightedTotalE] + rw [← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro q + rw [ih (fun i => z i.succ)] + simp only [finiteCascadeShifts,Fin.cases_zero,Fin.cases_succ] + have he : ENNReal.ofReal (Real.exp q.1) * + ENNReal.ofReal (Real.exp (finiteCascadeLogRecursion ν step n (fun i => z i.succ) H (step (p.1,q.2.1)))) = + ENNReal.ofReal (Real.exp (finiteCascadeLogRecursion ν step (n+1) z H p.1)) * + ENNReal.ofReal (Real.exp (q.1 + (finiteCascadeLogRecursion ν step n (fun i => z i.succ) H (step (p.1,q.2.1)) - + finiteCascadeLogRecursion ν step (n+1) z H p.1))) := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le,← ENNReal.ofReal_mul (Real.exp_pos _).le, + ← Real.exp_add,← Real.exp_add] + congr 2 + ring + rw [← mul_assoc,he,mul_assoc] + +lemma decoratedTerminalTotalE_zero {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (n : ℕ) (p : X×DecoratedCascade S n) : + decoratedTerminalTotalE step (fun _ => 0) n p = decoratedWeightedTotalE step n (fun _ _ => 0) p := by + induction n with + | zero => simp [decoratedTerminalTotalE,decoratedWeightedTotalE] + | succ n ih => + conv_lhs => rw [decoratedTerminalTotalE] + conv_rhs => rw [decoratedWeightedTotalE] + apply lintegral_congr + intro q + rw [ih] + simp + +def decoratedTerminalTotal {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (H : X → ℝ) (n : ℕ) (p : X×DecoratedCascade S n) : ℝ := + (decoratedTerminalTotalE step H n p).toReal + +lemma decoratedTerminalTotal_telescoping {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (H : X → ℝ) + (n : ℕ) (z : Fin n → ℝ) (p : X×DecoratedCascade S n) : + decoratedTerminalTotal step H n p = + Real.exp (finiteCascadeLogRecursion ν step n z H p.1) * + decoratedWeightedTotal step n (finiteCascadeShifts ν step n z H) p := by + exact (congrArg ENNReal.toReal (decoratedTerminalTotalE_telescoping ν step H n z p)).trans + (by rw [ENNReal.toReal_mul,ENNReal.toReal_ofReal (Real.exp_pos _).le]; rfl) + +lemma decoratedTerminalTotal_zero {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (n : ℕ) (p : X×DecoratedCascade S n) : + decoratedTerminalTotal step (fun _ => 0) n p = decoratedWeightedTotal step n (fun _ _ => 0) p := + congrArg ENNReal.toReal (decoratedTerminalTotalE_zero step n p) + +theorem finiteCascade_terminal_log_recursion {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + {H : X → ℝ} (hH : Measurable H) {C : ℝ} (hC : ∀ x, |H x| ≤ C) (x : X) : + (∫ η, Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step (fun _ => 0) n (x,η)) ∂decoratedCascadeLaw ν n z) = + finiteCascadeLogRecursion ν step n z H x := by + simp_rw [decoratedTerminalTotal_zero,decoratedTerminalTotal_telescoping ν step H n z] + exact decoratedCascade_log_identity ν step hs n z hz hz0 hz1 _ + (finiteCascadeShifts_measurable ν step hs n z hH) + (fun i y => (finiteCascadeShifts_normalized ν step hs n z hz0 hH hC i y).1) + (fun i y => (finiteCascadeShifts_normalized ν step hs n z hz0 hH hC i y).2) x + (finiteCascadeLogRecursion ν step n z H x) + +def finiteCascadeFractionalIntegrable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (H : X → ℝ) : + (n : ℕ) → (Fin n → ℝ) → Prop + | 0, _ => True + | n+1, z => (∀ x, Integrable (fun s => Real.exp (z 0* + finiteCascadeLogRecursion ν step n (fun i => z i.succ) H (step (x,s)))) ν) ∧ + finiteCascadeFractionalIntegrable ν step H n (fun i => z i.succ) + +lemma finiteCascadeFractionalIntegrable_of_bounded {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, 0 < z i) {H : X → ℝ} (hH : Measurable H) + {C : ℝ} (hC : ∀ x, |H x| ≤ C) : finiteCascadeFractionalIntegrable ν step H n z := by + induction n with + | zero => trivial + | succ n ih => + constructor + · intro x + apply bounded_fractional_exp_integrable ν (hz 0).le + (((finiteCascadeLogRecursion_measurable ν step hs n (fun j => z j.succ) hH).comp hs).comp + (measurable_const.prodMk measurable_id)) + exact fun s => finiteCascadeLogRecursion_abs_le ν step hs n (fun j => z j.succ) + (fun j => hz j.succ) hH hC (step (x,s)) + · exact ih (fun i => z i.succ) (fun i => hz i.succ) + +lemma finiteCascadeShifts_normalized_of_fractional {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, z i ≠ 0) (H : X → ℝ) + (hI : finiteCascadeFractionalIntegrable ν step H n z) : ∀ i x, + Integrable (fun s => Real.exp (z i*finiteCascadeShifts ν step n z H i (x,s))) ν ∧ + (∫ s, Real.exp (z i*finiteCascadeShifts ν step n z H i (x,s)) ∂ν) = 1 := by + induction n with + | zero => intro i; exact i.elim0 + | succ n ih => + rcases hI with ⟨hroot,htail⟩ + intro i + refine Fin.cases ?_ (fun j => ih (fun k => z k.succ) (fun k => hz k.succ) htail j) i + intro x + exact fractionalLogMoment_centered ν (hz 0) + (f := fun p => finiteCascadeLogRecursion ν step n (fun j => z j.succ) H (step p)) x (hroot x) + +theorem finiteCascade_terminal_log_recursion_of_fractional {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + {H : X → ℝ} (hH : Measurable H) (hI : finiteCascadeFractionalIntegrable ν step H n z) (x : X) : + (∫ η, Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step (fun _ => 0) n (x,η)) ∂decoratedCascadeLaw ν n z) = + finiteCascadeLogRecursion ν step n z H x := by + simp_rw [decoratedTerminalTotal_zero,decoratedTerminalTotal_telescoping ν step H n z] + exact decoratedCascade_log_identity ν step hs n z hz hz0 hz1 _ + (finiteCascadeShifts_measurable ν step hs n z hH) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z (fun j => (hz0 j).ne') H hI i y).1) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z (fun j => (hz0 j).ne') H hI i y).2) x + (finiteCascadeLogRecursion ν step n z H x) + +lemma stableIntensity_descendant_transform_marked {S C D : Type*} + [MeasurableSpace S] [MeasurableSpace C] [MeasurableSpace D] + (ν : Measure S) (ρ : Measure C) (θ : Measure D) + [IsProbabilityMeasure ν] [IsProbabilityMeasure ρ] [IsProbabilityMeasure θ] + {b : ℝ} (hb : 0 ≤ b) (T : S×C → D) (hT : Measurable T) + (hLaw : ∀ s, ρ.map (fun c => T (s,c)) = θ) {F : S → ℝ} (hF : Measurable F) : + ((stableLogIntensity b).prod (ν.prod ρ)).map + (fun p : ℝ×(S×C) => (p.1+F p.2.1,(p.2.1,T p.2))) = + (stableLogIntensity b).prod ((ν.withDensity (fun s => ENNReal.ofReal (Real.exp (b*F s)))).prod θ) := by + have hmark : MeasurePreserving (fun p : S×C => (p.1,T p)) (ν.prod ρ) (ν.prod θ) := + ⟨measurable_fst.prodMk hT,descendant_transform_independent ν ρ θ T hT hLaw⟩ + have hbase := (MeasurePreserving.id (stableLogIntensity b)).prod hmark + have hshift : MeasurePreserving (logMarkShift (fun p : S×D => F p.1)) + ((stableLogIntensity b).prod (ν.prod θ)) + ((stableLogIntensity b).prod ((ν.withDensity (fun s => ENNReal.ofReal (Real.exp (b*F s)))).prod θ)) := by + refine ⟨logMarkShift_measurable (hF.comp measurable_fst),?_⟩ + calc + _ = (stableLogIntensity b).prod ((ν.prod θ).withDensity + (fun p : S×D => ENNReal.ofReal (Real.exp (b*F p.1)))) := by + exact stableLogIntensity_mark_shift (ν.prod θ) hb (F := fun p : S×D => F p.1) (by fun_prop) + _ = _ := by rw [← prod_withDensity_left ((hF.const_mul b).exp.ennreal_ofReal)] + exact (hshift.comp hbase).map_eq + +lemma stablePoisson_descendant_transform_marked {S C D : Type*} + [MeasurableSpace S] [MeasurableSpace C] [MeasurableSpace D] + [Nonempty S] [Nonempty C] [Nonempty D] + (ν : Measure S) (ρ : Measure C) (θ : Measure D) + [IsProbabilityMeasure ν] [IsProbabilityMeasure ρ] [IsProbabilityMeasure θ] + {b : ℝ} (hb : 0 ≤ b) (T : S×C → D) (hT : Measurable T) + (hLaw : ∀ s, ρ.map (fun c => T (s,c)) = θ) {F : S → ℝ} (hF : Measurable F) : + (poissonRandomMeasureLaw ((stableLogIntensity b).prod (ν.prod ρ))).map + (Measure.map (fun p : ℝ×(S×C) => (p.1+F p.2.1,(p.2.1,T p.2)))) = + poissonRandomMeasureLaw ((stableLogIntensity b).prod + ((ν.withDensity (fun s => ENNReal.ofReal (Real.exp (b*F s)))).prod θ)) := by + rw [poissonRandomMeasureLaw_map _ (by fun_prop)] + congr 1 + exact stableIntensity_descendant_transform_marked ν ρ θ hb T hT hLaw hF + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/DepthWeights.lean b/lean/OAI/Probability/Perceptron/Cascade/DepthWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..977f0316cef757caf1dc3d6ded108632926f9a2b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/DepthWeights.lean @@ -0,0 +1,78 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DepthBlock + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology +namespace SphericalPerceptronFreeEnergy + +lemma indexedDepthLaw_weight_tail (k : ℕ) (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i = 1) (d : ℕ) : + (indexedDepthLaw k (stepCumulative w) : Measure (FiniteOverlap (Fin (k+1)))).real + {R | d ≤ (R 0 1).val} = ∑ i, if d ≤ i.val then w i else 0 := by + by_cases hdk : d ≤ k + · have hh := congrArg ENNReal.toReal (indexedDepthLaw_pair_tail k (stepCumulative w) + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) + (stepCumulative_lt_one w hw hw1) d hdk) + have hb : (if h : d = 0 then (0:ℝ) else stepCumulative w ⟨d-1,by omega⟩) ≤ 1 := by + split_ifs + · norm_num + · exact (stepCumulative_lt_one w hw hw1 _).le + have he : (indexedDepthLaw k (stepCumulative w) : Measure (FiniteOverlap (Fin (k+1)))).real + {R | d ≤ (R 0 1).val} = + 1 - (if h : d = 0 then 0 else stepCumulative w ⟨d-1,by omega⟩) := by + simpa only [measureReal_def,ENNReal.toReal_ofReal (sub_nonneg.mpr hb)] using hh + rw [he] + by_cases hd0 : d = 0 + · subst d + simpa only [dite_true,Nat.zero_le,ite_true,sub_zero] using hw1.symm + · rw [dite_eq_right hd0,←hw1] + unfold stepCumulative + rw [←Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + have hiff : i ≤ (⟨d-1,by omega⟩ : Fin k).castSucc ↔ ¬ d ≤ i.val := by + change i.val ≤ d-1 ↔ ¬ d ≤ i.val + omega + by_cases hi : d ≤ i.val + · simp only [ite_eq_left hi,ite_eq_right (fun h => (hiff.mp h) hi),sub_zero] + · simp only [ite_eq_right hi,ite_eq_left (hiff.mpr hi),sub_self] + · have hf (l : Fin (k+1)) : ¬ d ≤ l.val := by omega + have he : {R : FiniteOverlap (Fin (k+1)) | d ≤ (R 0 1).val} = ∅ := by + ext R + simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false] + exact hf _ + rw [he] + simp only [measureReal_empty,hf,ite_false,Finset.sum_const_zero] + +theorem indexedDepthLaw_pair_weights (k : ℕ) (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i = 1) (c : Fin (k+1)) : + (indexedDepthLaw k (stepCumulative w) : Measure (FiniteOverlap (Fin (k+1)))).real + {R | R 0 1 = c} = w c := by + have h := measureReal_fin_atom_from_tails + (indexedDepthLaw k (stepCumulative w) : Measure (FiniteOverlap (Fin (k+1)))) + k (fun R => R 0 1) (by fun_prop) univ MeasurableSet.univ c + simp only [Set.mem_univ,true_and] at h + rw [h,indexedDepthLaw_weight_tail k w hw hw1,indexedDepthLaw_weight_tail k w hw hw1, + ←Finset.sum_sub_distrib] + calc + _ = ∑ i, if i = c then w c else 0 := by + apply Finset.sum_congr rfl + intro i _ + rcases lt_trichotomy i c with hi | rfl | hi + · have h1 : ¬ c.val ≤ i.val := by exact not_le.mpr hi + have h2 : ¬ c.val+1 ≤ i.val := by omega + simp only [ite_eq_right h1,ite_eq_right h2,ite_eq_right (ne_of_lt hi),sub_self] + · simp + · have h1 : c.val ≤ i.val := le_of_lt hi + have h2 : c.val+1 ≤ i.val := hi + simp only [ite_eq_left h1,ite_eq_left h2,ite_eq_right (ne_of_gt hi),sub_self] + _ = w c := by simp + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/EnrichedPoissonVariance.lean b/lean/OAI/Probability/Perceptron/Cascade/EnrichedPoissonVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d33c90a0afd6d6e3dc9db9039ba9833590ad7e1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/EnrichedPoissonVariance.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.EnrichedPatternVariance +import OAI.Probability.Perceptron.Cascade.PoissonCountMoments +import OAI.Probability.Perceptron.Variational.CountMixtureVariance + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def infinitePatternRowsLaw (N : ℕ) : Measure (ℕ → Fin N → ℝ) := + Measure.infinitePi fun _ : ℕ => Measure.pi fun _ : Fin N => gaussianReal 0 1 + +instance (N : ℕ) : IsProbabilityMeasure (infinitePatternRowsLaw N) := by + unfold infinitePatternRowsLaw + infer_instance + +def patternPrefix (N M : ℕ) (g : ℕ → Fin N → ℝ) : Fin M → Fin N → ℝ := + fun a => g a.val + +lemma patternPrefix_measurable (N M : ℕ) : Measurable (patternPrefix N M) := by + unfold patternPrefix + fun_prop + +lemma patternPrefix_measurePreserving (N M : ℕ) : MeasurePreserving (patternPrefix N M) + (infinitePatternRowsLaw N) (finitePatternRowsLaw N M) := by + refine ⟨patternPrefix_measurable N M,?_⟩ + change Measure.map (fun g : ℕ → Fin N → ℝ => fun a : Fin M => g a.val) + (Measure.infinitePi fun _ : ℕ => Measure.pi fun _ : Fin N => gaussianReal 0 1)= + Measure.pi fun _ : Fin M => Measure.pi fun _ : Fin N => gaussianReal 0 1 + rw [Measure.map_infinitePi_infinitePi_of_inj Fin.val_injective,Measure.infinitePi_eq_pi] + +lemma normalizedPatternEnergy_prefix_succ (N M : ℕ) (f : ℝ →ᵇ ℝ) + (g : ℕ → Fin N → ℝ) (x : NormalizedSpin N) : + |normalizedPatternEnergy N (M+1) f (patternPrefix N (M+1) g) x- + normalizedPatternEnergy N M f (patternPrefix N M g) x| ≤ ‖f‖ := by + unfold normalizedPatternEnergy + rw [Fin.sum_univ_castSucc] + simp only [patternPrefix,Fin.val_castSucc,Fin.val_last,add_sub_cancel_left] + simpa only [Real.norm_eq_abs] using f.norm_coe_le_norm (∑ i, g M i*x.val i) + +def enrichedPoissonLog (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) + (a : ℕ × ((ℕ → Fin (n+1) → ℝ) × + (EnrichedMark (n+1) (n+1) p × DecoratedCascade (EnrichedMark (n+1) (n+1) p) k))) : ℝ := + enrichedCascadeLog n a.1 k f (patternPrefix (n+1) a.1 a.2.1) p d u h a.2.2 + +def enrichedRowsDisorderLaw (n k : ℕ) (p : Fin (n+1) → ℕ) (z : Fin k → ℝ) := + (infinitePatternRowsLaw (n+1)).prod (enrichedDisorderLaw n k p z) + +instance (n k : ℕ) (p : Fin (n+1) → ℕ) (z : Fin k → ℝ) : + IsProbabilityMeasure (enrichedRowsDisorderLaw n k p z) := by + unfold enrichedRowsDisorderLaw + infer_instance + +lemma enrichedPoissonLog_measurable (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) : + Measurable (enrichedPoissonLog n k f p d u h) := by + apply measurable_from_prod_countable_right + intro M + have hh := (enrichedCascadeLog_parameters_measurable n M k f p d u h z).comp + (((patternPrefix_measurable (n+1) M).comp + (measurable_fst (α := ℕ → Fin (n+1) → ℝ) + (β := EnrichedMark (n+1) (n+1) p × DecoratedCascade (EnrichedMark (n+1) (n+1) p) k))).prodMk measurable_snd) + simpa only [enrichedPoissonLog,Function.comp_def] using hh + +lemma enrichedPoissonLog_section_variance (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 enrichedPoissonLog n k f p d u h (M,a)) 2 (enrichedRowsDisorderLaw n k p z) ∧ + variance (fun a => enrichedPoissonLog n k f p d u h (M,a)) (enrichedRowsDisorderLaw n k p z) ≤ + cascadeLogFluctuationConstant k z+(Real.pi^2/8)* + ((enrichedFeatureBound (n+1) u:ℝ)*‖enrichedRootMap p d h‖)^2+(M:ℝ)*(2*‖f‖)^2 := by + let E := EnrichedMark (n+1) (n+1) p + let D := E × DecoratedCascade E k + have hp : MeasurePreserving (fun a : (ℕ → Fin (n+1) → ℝ) × D => + (patternPrefix (n+1) M a.1,a.2)) + ((infinitePatternRowsLaw (n+1)).prod (enrichedDisorderLaw n k p z)) + ((finitePatternRowsLaw (n+1) M).prod (enrichedDisorderLaw n k p z)) := + (patternPrefix_measurePreserving (n+1) M).prod + (MeasurePreserving.id (enrichedDisorderLaw n k p z)) + have hs := enrichedFixedCountLog_variance n M k f p d u h z hz hz0 hz1 + have hl := hs.1.comp_measurePreserving hp + have hv := (hp.variance_fun_comp hs.1.aestronglyMeasurable.aemeasurable).trans_le hs.2 + constructor + · simpa only [Function.comp_def,enrichedFixedCountLog,enrichedPoissonLog,enrichedRowsDisorderLaw] using hl + · simpa only [enrichedFixedCountLog,enrichedPoissonLog,enrichedRowsDisorderLaw] using hv + +lemma enrichedPoissonLog_mean_succ (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 enrichedExpectedLog n M k f p d u h z (patternPrefix (n+1) M g) + have hG (M : ℕ) : MemLp (G M) 2 μ := + (enrichedExpectedLog_memLp n M k f p d u h z hz hz0 hz1).comp_measurePreserving + (patternPrefix_measurePreserving (n+1) M) + have he (M : ℕ) : (∫ a, enrichedPoissonLog n k f p d u h (M,a) ∂enrichedRowsDisorderLaw n k p z)= + ∫ g, G M g ∂μ := + integral_prod _ ((enrichedPoissonLog_section_variance n M k f p d u h z hz hz0 hz1).1.integrable (by norm_num)) + rw [he,he,← integral_sub ((hG (M+1)).integrable (by norm_num)) ((hG M).integrable (by norm_num))] + have hh (g) : |G (M+1) g-G M g| ≤ ‖f‖ := + enrichedExpectedLog_pattern_change n (M+1) M k f _ _ p d u h z hz hz0 hz1 + (normalizedPatternEnergy_prefix_succ (n+1) M f g) + simpa using norm_integral_le_of_norm_le_const (μ := μ) (f := fun g => G (M+1) g-G M g) + (ae_of_all _ hh) + +lemma enrichedPoissonLog_variance (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 ∫ a, F (M,a) ∂ν + let K := cascadeLogFluctuationConstant k z+(Real.pi^2/8)* + ((enrichedFeatureBound (n+1) u:ℝ)*‖enrichedRootMap p d h‖)^2 + let A := fun M : ℕ => K+(M:ℝ)*(2*‖f‖)^2 + have hGdiff := enrichedPoissonLog_mean_succ n k f p d u h z hz hz0 hz1 + have hG : MemLp G 2 (poissonMeasure r) := poisson_bounded_increment_memLp r (norm_nonneg f) hGdiff + have hAi : Integrable A (poissonMeasure r) := + (integrable_const K).add ((poisson_nat_memLp r).integrable (by norm_num) |>.mul_const _) + have hs (M) := enrichedPoissonLog_section_variance n M k f p d u h z hz hz0 hz1 + have hp : MemLp F 2 ((poissonMeasure r).prod ν) := + memLp_prod_of_conditional_square_function (poissonMeasure r) ν + (enrichedPoissonLog_measurable n k f p d u h z) hG hAi (fun M => (hs M).1) + (fun M => by + have hv := (hs M).2 + rw [variance_eq_integral (hs M).1.aestronglyMeasurable.aemeasurable] at hv + exact hv) + refine ⟨hp,?_⟩ + have hv := variance_prod_le_integral (poissonMeasure r) ν hp (fun M => (hs M).1) hG hAi + (fun M => (hs M).2) (poisson_bounded_increment_variance r (norm_nonneg f) hGdiff) + have he : (∫ M, A M ∂poissonMeasure r)=K+(r:ℝ)*(2*‖f‖)^2 := by + rw [integral_add (integrable_const K) ((poisson_nat_memLp r).integrable (by norm_num) |>.mul_const _)] + simp only [integral_const,integral_mul_const,poisson_nat_mean] + simp + rw [he] at hv + exact hv + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/IndexedCascadeRegular.lean b/lean/OAI/Probability/Perceptron/Cascade/IndexedCascadeRegular.lean new file mode 100644 index 0000000000000000000000000000000000000000..ffab10b6c4414872d00dd876c0adc0dbe0edddbc --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/IndexedCascadeRegular.lean @@ -0,0 +1,207 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.IndexedMarkedPoisson + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +lemma indexedPoissonMeasure_lintegral {A : Type*} [MeasurableSpace A] + (a : ℕ → ℕ × (ℕ → A)) {f : A → ℝ≥0∞} (hf : Measurable f) : + (∫⁻ x, f x ∂indexedPoissonMeasure a) = + ∑' i, ∑ j : Fin ((a i).1), f ((a i).2 j.val) := by + simp only [indexedPoissonMeasure,indexedFiniteCloud,finitePointMeasure, + lintegral_sum_measure,lintegral_finsetSum_measure,lintegral_dirac' _ hf] + +def indexedCascadeRootMass {n : ℕ} (b : IndexedCascadeBase (n+1)) : ℝ≥0∞ := + markedStableTotalE (indexedPoissonMeasure b) + +lemma indexedCascadeRootMass_measurable (n : ℕ) : + Measurable (indexedCascadeRootMass (n := n)) := + markedStableTotalE_measurable.comp indexedPoissonMeasure_measurable + +lemma indexedCascadeRealize_rootMass {S : Type} [MeasurableSpace S] (n : ℕ) + (b : IndexedCascadeBase (n+1)) (m : IndexedCascadeMarks S (n+1)) : + markedStableTotalE (indexedCascadeRealize (n+1) (b,m)) = indexedCascadeRootMass b := by + unfold indexedCascadeRealize indexedCascadeRootMass markedStableTotalE + rw [indexedPoissonMeasure_lintegral _ (by fun_prop),indexedPoissonMeasure_lintegral _ (by fun_prop)] + +def IndexedCascadeGood : (n : ℕ) → IndexedCascadeBase n → Prop + | 0,_ => True + | n+1,b => 0 < (indexedCascadeRootMass b).toReal ∧ + ∀ i j : ℕ, IndexedCascadeGood n (((b i).2 j).2) + +lemma indexedCascadeBase_child_law (n : ℕ) (z : Fin (n+1) → ℝ) (i j : ℕ) : + MeasurePreserving (fun b : IndexedCascadeBase (n+1) => (((b i).2 j).2)) + (indexedCascadeBaseLaw (n+1) z) (indexedCascadeBaseLaw n (fun l => z l.succ)) := by + let B := (indexedCascadeBaseLaw n (fun l => z l.succ) : Measure (IndexedCascadeBase n)) + let ρ := fun i => finiteIntensityMarks (sfiniteSeq (stableLogIntensity (z 0)) i) + let r := fun i => ((sfiniteSeq (stableLogIntensity (z 0)) i) univ).toNNReal + exact (measurePreserving_snd (μ := ρ i) (ν := B)).comp + ((measurePreserving_eval_infinitePi (fun _ : ℕ => (ρ i).prod B) j).comp + ((measurePreserving_snd (μ := poissonMeasure (r i)) + (ν := Measure.infinitePi (fun _ : ℕ => (ρ i).prod B))).comp + (measurePreserving_eval_infinitePi (fun i => (poissonMeasure (r i)).prod + (Measure.infinitePi (fun _ : ℕ => (ρ i).prod B))) i))) + +lemma indexedCascadeRootMass_pos (n : ℕ) (z : Fin (n+1) → ℝ) + (hz0 : 0 < z 0) (hz1 : z 0 < 1) : + ∀ᵐ b ∂(indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))), + 0 < (indexedCascadeRootMass b).toReal := by + let B := (indexedCascadeBaseLaw n (fun l => z l.succ) : Measure (IndexedCascadeBase n)) + let κ := stableLogIntensity (z 0) + have hl : (indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))).map + indexedPoissonMeasure = poissonRandomMeasureLaw (κ.prod B) := by + change (Measure.infinitePi (fun i => (poissonMeasure (((sfiniteSeq κ i) univ).toNNReal)).prod + (Measure.infinitePi (fun _ : ℕ => (finiteIntensityMarks (sfiniteSeq κ i)).prod B)))).map + indexedPoissonMeasure = _ + rw [indexedPoissonMeasure_law,countablePoissonLaw_product_intensity] + have hreg := (markedStable_regular B hz0 hz1).mono fun η hη => hη.2 + rw [← hl] at hreg + exact (ae_map_iff indexedPoissonMeasure_measurable.aemeasurable + (measurableSet_lt measurable_const markedStableTotal_measurable)).mp hreg + +lemma indexedCascadeGood_ae (n : ℕ) (z : Fin n → ℝ) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) : + ∀ᵐ b ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)), IndexedCascadeGood n b := by + induction n with + | zero => exact ae_of_all _ fun _ => trivial + | succ n ih => + have ht (i j : ℕ) : ∀ᵐ b ∂(indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))), + IndexedCascadeGood n (((b i).2 j).2) := + (indexedCascadeBase_child_law n z i j).quasiMeasurePreserving.ae + (ih (fun l => z l.succ) (fun l => hz0 l.succ) (fun l => hz1 l.succ)) + filter_upwards [indexedCascadeRootMass_pos n z (hz0 0) (hz1 0), + ae_all_iff.mpr (fun i => ae_all_iff.mpr (ht i))] with b hb ht + exact ⟨hb,ht⟩ + +lemma indexedCascadeGood_countKernel {S : Type} [MeasurableSpace S] {n : ℕ} + {b : IndexedCascadeBase (n+1)} (hb : IndexedCascadeGood (n+1) b) + (m : IndexedCascadeMarks S (n+1)) : + markedStableCountKernel (indexedCascadeRealize (n+1) (b,m)) = + indexedCascadeRealize (n+1) (b,m) := by + apply markedStableCountKernel_eq + · rw [indexedCascadeRealize_rootMass] + exact (ENNReal.toReal_pos_iff.mp hb.1).2.ne + · change 0 < (markedStableTotalE (indexedCascadeRealize (n+1) (b,m))).toReal + rw [indexedCascadeRealize_rootMass] + exact hb.1 + +@[reducible] def IndexedLeaf : ℕ → MeasCat + | 0 => MeasCat.of Unit + | n+1 => MeasCat.of (ℕ × ℕ × IndexedLeaf n) + +instance indexedLeaf_countable (n : ℕ) : Countable (IndexedLeaf n) := by + induction n with + | zero => dsimp [IndexedLeaf]; infer_instance + | succ n ih => dsimp [IndexedLeaf]; infer_instance + +instance indexedLeaf_nonempty (n : ℕ) : Nonempty (IndexedLeaf n) := by + induction n with + | zero => exact ⟨()⟩ + | succ n ih => dsimp [IndexedLeaf]; infer_instance + +instance indexedLeaf_measurableSingleton (n : ℕ) : MeasurableSingletonClass (IndexedLeaf n) := by + induction n with + | zero => dsimp [IndexedLeaf]; infer_instance + | succ n ih => dsimp [IndexedLeaf]; infer_instance + +def indexedLeafWeight : (n : ℕ) → IndexedCascadeBase n → IndexedLeaf n → ℝ≥0 + | 0,_,_ => 1 + | n+1,b,l => if l.2.1 < (b l.1).1 then + (Real.exp (((b l.1).2 l.2.1).1)).toNNReal * + indexedLeafWeight n (((b l.1).2 l.2.1).2) l.2.2 else 0 + +lemma indexedLeafWeight_measurable (n : ℕ) : + Measurable (Function.uncurry (indexedLeafWeight n)) := by + induction n with + | zero => exact measurable_const + | succ n ih => + apply measurable_from_prod_countable_left + intro l + change Measurable (fun b : ℕ → ℕ × (ℕ → ℝ × IndexedCascadeBase n) => + if l.2.1 < (b l.1).1 then (Real.exp (((b l.1).2 l.2.1).1)).toNNReal * + indexedLeafWeight n (((b l.1).2 l.2.1).2) l.2.2 else 0) + apply Measurable.ite (measurableSet_lt measurable_const (by fun_prop)) + · exact (by fun_prop : Measurable (fun b : ℕ → ℕ × (ℕ → ℝ × IndexedCascadeBase n) => + (Real.exp (((b l.1).2 l.2.1).1)).toNNReal)).mul + (ih.comp (show Measurable (fun b : ℕ → ℕ × (ℕ → ℝ × IndexedCascadeBase n) => + ((((b l.1).2 l.2.1).2),l.2.2)) from by fun_prop)) + · exact measurable_const + +def indexedLeafMeasure (n : ℕ) (b : IndexedCascadeBase n) : Measure (IndexedLeaf n) := + Measure.sum (fun l => (indexedLeafWeight n b l : ℝ≥0∞) • Measure.dirac l) + +instance indexedLeafMeasure_sfinite (n : ℕ) (b : IndexedCascadeBase n) : + SFinite (indexedLeafMeasure n b) := by + unfold indexedLeafMeasure + infer_instance + +lemma indexedLeafMeasure_measurable (n : ℕ) : Measurable (indexedLeafMeasure n) := by + apply Measure.measurable_of_measurable_coe + intro s hs + simp only [indexedLeafMeasure,Measure.sum_apply _ hs,Measure.smul_apply] + apply Measurable.tsum + intro l + exact (((indexedLeafWeight_measurable n).comp (measurable_id.prodMk measurable_const)).coe_nnreal_ennreal).mul_const _ + +lemma indexedLeafMeasure_lintegral (n : ℕ) (b : IndexedCascadeBase n) (f : IndexedLeaf n → ℝ≥0∞) : + (∫⁻ l, f l ∂indexedLeafMeasure n b) = ∑' l, (indexedLeafWeight n b l : ℝ≥0∞)*f l := by + simp only [indexedLeafMeasure,lintegral_sum_measure,lintegral_smul_measure,lintegral_dirac,smul_eq_mul] + +lemma indexedLeafMeasure_lintegral_succ (n : ℕ) (b : IndexedCascadeBase (n+1)) + (f : IndexedLeaf (n+1) → ℝ≥0∞) : + (∫⁻ l, f l ∂indexedLeafMeasure (n+1) b) = + ∑' i, ∑ j : Fin ((b i).1), ENNReal.ofReal (Real.exp (((b i).2 j.val).1))* + ∫⁻ l, f (i,j.val,l) ∂indexedLeafMeasure n (((b i).2 j.val).2) := by + rw [indexedLeafMeasure_lintegral] + change (∑' l : ℕ × ℕ × IndexedLeaf n, (indexedLeafWeight (n+1) b l : ℝ≥0∞)*f l) = _ + rw [ENNReal.tsum_prod'] + apply tsum_congr + intro i + rw [ENNReal.tsum_prod'] + have he (j : ℕ) : (∑' l : IndexedLeaf n, + (indexedLeafWeight (n+1) b (i,j,l) : ℝ≥0∞)*f (i,j,l)) = + if j < (b i).1 then ENNReal.ofReal (Real.exp (((b i).2 j).1))* + (∫⁻ l, f (i,j,l) ∂indexedLeafMeasure n (((b i).2 j).2)) else 0 := by + by_cases hj : j < (b i).1 + · simp only [indexedLeafWeight,ite_eq_left hj,ENNReal.coe_mul] + change (∑' l : IndexedLeaf n, ENNReal.ofReal (Real.exp (((b i).2 j).1)) * + (indexedLeafWeight n (((b i).2 j).2) l : ℝ≥0∞)*f (i,j,l)) = _ + rw [indexedLeafMeasure_lintegral,← ENNReal.tsum_mul_left] + exact tsum_congr (fun l => mul_assoc _ _ _) + · simp [indexedLeafWeight,hj] + simp_rw [he] + rw [tsum_eq_sum (s := Finset.range ((b i).1)) (fun j hj => by simp [Finset.mem_range.not.mp hj])] + rw [Fin.sum_univ_eq_sum_range (fun j => ENNReal.ofReal (Real.exp (((b i).2 j).1)) * + ∫⁻ l, f (i,j,l) ∂indexedLeafMeasure n (((b i).2 j).2))] + apply Finset.sum_congr rfl + intro j hj + rw [ite_eq_left (Finset.mem_range.mp hj)] + +def indexedLeafState {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X × S → X) : (n : ℕ) → X × IndexedCascadeMarks S n → IndexedLeaf n → X + | 0,p,_ => p.1 + | n+1,p,l => indexedLeafState step n (step (p.1,(p.2 l.1 l.2.1).1), + (p.2 l.1 l.2.1).2) l.2.2 + +lemma indexedLeafState_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + {step : X × S → X} (hs : Measurable step) (n : ℕ) : + Measurable (Function.uncurry (indexedLeafState step n)) := by + induction n with + | zero => exact measurable_fst.fst + | succ n ih => + apply measurable_from_prod_countable_left + intro l + change Measurable (fun p : X × (ℕ → ℕ → S × IndexedCascadeMarks S n) => + indexedLeafState step n (step (p.1,(p.2 l.1 l.2.1).1),(p.2 l.1 l.2.1).2) l.2.2) + exact ih.comp (show Measurable (fun p : X × (ℕ → ℕ → S × IndexedCascadeMarks S n) => + ((step (p.1,(p.2 l.1 l.2.1).1),(p.2 l.1 l.2.1).2),l.2.2)) from by fun_prop) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/IndexedMarkedPoisson.lean b/lean/OAI/Probability/Perceptron/Cascade/IndexedMarkedPoisson.lean new file mode 100644 index 0000000000000000000000000000000000000000..e12450b04f4ed3a44e63d1fcd38f6a460be390fb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/IndexedMarkedPoisson.lean @@ -0,0 +1,250 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FocusedShapeProbability +import OAI.Probability.Perceptron.Cascade.IndexedPoisson +import OAI.Probability.Perceptron.Variational.InfinitePiSplit + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +lemma law_count_iid_zip {A B : Type*} [MeasurableSpace A] [MeasurableSpace B] + (r : ℝ≥0) (ρ : Measure A) (ν : Measure B) + [IsProbabilityMeasure ρ] [IsProbabilityMeasure ν] : + (((poissonMeasure r).prod (Measure.infinitePi (fun _ : ℕ => ρ))).prod + (Measure.infinitePi (fun _ : ℕ => ν))).map + (fun p => (p.1.1, fun j => (p.1.2 j,p.2 j))) = + (poissonMeasure r).prod (Measure.infinitePi (fun _ : ℕ => ρ.prod ν)) := by + let z : ((ℕ → A) × (ℕ → B)) → ℕ → A × B := fun p j => (p.1 j,p.2 j) + have hz : Measurable z := by fun_prop + calc + _ = ((((poissonMeasure r).prod (Measure.infinitePi (fun _ : ℕ => ρ))).prod + (Measure.infinitePi (fun _ : ℕ => ν))).map + (MeasurableEquiv.prodAssoc : ((ℕ × (ℕ → A)) × (ℕ → B)) ≃ᵐ (ℕ × ((ℕ → A) × (ℕ → B))))).map (Prod.map id z) := by + rw [Measure.map_map (by fun_prop) (by fun_prop)] + rfl + _ = _ := by + rw [Measure.prodAssoc_prod, ← Measure.map_prod_map _ _ measurable_id hz, + Measure.map_id, infinitePi_zip] + +lemma indexedMarkedPoisson_law {A B : Type*} [MeasurableSpace A] [MeasurableSpace B] + (r : ℕ → ℝ≥0) (ρ : ℕ → Measure A) (ν : Measure B) + [∀ i, IsProbabilityMeasure (ρ i)] [IsProbabilityMeasure ν] : + ((Measure.infinitePi (fun i => (poissonMeasure (r i)).prod + (Measure.infinitePi (fun _ : ℕ => ρ i)))).prod + (Measure.infinitePi (fun _ : ℕ => Measure.infinitePi (fun _ : ℕ => ν)))).map + (fun p => indexedPoissonMeasure (fun i => (p.1 i |>.1, + fun j => ((p.1 i).2 j,p.2 i j)))) = + countablePoissonLaw r (fun i => (ρ i).prod ν) := by + let z : (ℕ × (ℕ → A)) × (ℕ → B) → ℕ × (ℕ → A × B) := + fun p => (p.1.1,fun j => (p.1.2 j,p.2 j)) + have hz : Measurable z := by fun_prop + let L := Measure.infinitePi (fun i => (poissonMeasure (r i)).prod + (Measure.infinitePi (fun _ : ℕ => ρ i))) + let M := Measure.infinitePi (fun _ : ℕ => Measure.infinitePi (fun _ : ℕ => ν)) + have hp : (L.prod M).map (fun p i => z (p.1 i,p.2 i)) = + Measure.infinitePi (fun i => (poissonMeasure (r i)).prod + (Measure.infinitePi (fun _ : ℕ => (ρ i).prod ν))) := by + calc + _ = ((L.prod M).map (fun p i => (p.1 i,p.2 i))).map (fun p i => z (p i)) := by + rw [Measure.map_map (by fun_prop) (by fun_prop)] + rfl + _ = _ := by + dsimp [L,M] + rw [infinitePi_zip, Measure.infinitePi_map_pi] + simp_rw [show ∀ i, ((poissonMeasure (r i)).prod + (Measure.infinitePi (fun _ : ℕ => ρ i)) |>.prod + (Measure.infinitePi (fun _ : ℕ => ν))).map z = + (poissonMeasure (r i)).prod (Measure.infinitePi (fun _ : ℕ => (ρ i).prod ν)) + from fun i => law_count_iid_zip (r i) (ρ i) ν] + exact fun _ => hz + change (L.prod M).map (indexedPoissonMeasure ∘ (fun p i => z (p.1 i,p.2 i))) = _ + rw [← Measure.map_map indexedPoissonMeasure_measurable (by fun_prop),hp, + indexedPoissonMeasure_law] + +lemma countablePoissonLaw_product_intensity {A B : Type*} + [MeasurableSpace A] [MeasurableSpace B] [Nonempty A] [Nonempty B] + (κ : Measure A) [SFinite κ] (ν : Measure B) [IsProbabilityMeasure ν] : + countablePoissonLaw (fun i => ((sfiniteSeq κ i) univ).toNNReal) + (fun i => (finiteIntensityMarks (sfiniteSeq κ i)).prod ν) = + poissonRandomMeasureLaw (κ.prod ν) := by + apply measureLaw_eq_of_laplace + intro f hf hf0 + rw [countablePoissonLaw_laplace_intensity _ _ hf hf0, + poissonRandomMeasureLaw_laplace _ hf hf0] + congr 2 + have he : countablePoissonIntensity (fun i => ((sfiniteSeq κ i) univ).toNNReal) + (fun i => (finiteIntensityMarks (sfiniteSeq κ i)).prod ν) = κ.prod ν := by + unfold countablePoissonIntensity + simp_rw [← Measure.prod_smul_left, finiteIntensityMarks_smul] + rw [← Measure.prod_sum_left,sum_sfiniteSeq] + rw [he] + +lemma indexedMarkedPoisson_canonical_law {A B : Type*} + [MeasurableSpace A] [MeasurableSpace B] [Nonempty A] [Nonempty B] + (κ : Measure A) [SFinite κ] (ν : Measure B) [IsProbabilityMeasure ν] : + ((Measure.infinitePi (fun i => + (poissonMeasure (((sfiniteSeq κ i) univ).toNNReal)).prod + (Measure.infinitePi (fun _ : ℕ => finiteIntensityMarks (sfiniteSeq κ i))))).prod + (Measure.infinitePi (fun _ : ℕ => Measure.infinitePi (fun _ : ℕ => ν)))).map + (fun p => indexedPoissonMeasure (fun i => ((p.1 i).1, + fun j => ((p.1 i).2 j,p.2 i j)))) = + poissonRandomMeasureLaw (κ.prod ν) := by + rw [indexedMarkedPoisson_law,countablePoissonLaw_product_intensity] + +@[reducible] def IndexedCascadeBase : ℕ → MeasCat + | 0 => MeasCat.of Unit + | n+1 => MeasCat.of (ℕ → ℕ × (ℕ → ℝ × IndexedCascadeBase n)) + +@[reducible] def IndexedCascadeMarks (S : Type) [MeasurableSpace S] : ℕ → MeasCat + | 0 => MeasCat.of Unit + | n+1 => MeasCat.of (ℕ → ℕ → S × IndexedCascadeMarks S n) + +instance indexedCascadeBase_nonempty (n : ℕ) : Nonempty (IndexedCascadeBase n) := by + induction n with + | zero => exact ⟨()⟩ + | succ n ih => dsimp [IndexedCascadeBase]; infer_instance + +instance indexedCascadeMarks_nonempty (S : Type) [MeasurableSpace S] [Nonempty S] (n : ℕ) : + Nonempty (IndexedCascadeMarks S n) := by + induction n with + | zero => exact ⟨()⟩ + | succ n ih => dsimp [IndexedCascadeMarks]; infer_instance + +def indexedCascadeBaseLaw : (n : ℕ) → (Fin n → ℝ) → ProbabilityMeasure (IndexedCascadeBase n) + | 0,_ => ⟨Measure.dirac (),inferInstance⟩ + | n+1,z => ⟨Measure.infinitePi (fun i => + (poissonMeasure (((sfiniteSeq (stableLogIntensity (z 0)) i) univ).toNNReal)).prod + (Measure.infinitePi (fun _ : ℕ => + (finiteIntensityMarks (sfiniteSeq (stableLogIntensity (z 0)) i)).prod + (indexedCascadeBaseLaw n (fun j => z j.succ))))),by infer_instance⟩ + +def indexedCascadeMarksLaw {S : Type} [MeasurableSpace S] (ν : ProbabilityMeasure S) : + (n : ℕ) → ProbabilityMeasure (IndexedCascadeMarks S n) + | 0 => ⟨Measure.dirac (),inferInstance⟩ + | n+1 => ⟨Measure.infinitePi (fun _ : ℕ => Measure.infinitePi (fun _ : ℕ => + (ν : Measure S).prod (indexedCascadeMarksLaw ν n))),by infer_instance⟩ + +def indexedCascadeRealize {S : Type} [MeasurableSpace S] : (n : ℕ) → + IndexedCascadeBase n × IndexedCascadeMarks S n → DecoratedCascade S n + | 0,_ => () + | n+1,p => indexedPoissonMeasure (fun i => ((p.1 i).1,fun j => + (((p.1 i).2 j).1,((p.2 i j).1, + indexedCascadeRealize n (((p.1 i).2 j).2,(p.2 i j).2))))) + +lemma indexedCascadeRealize_measurable {S : Type} [MeasurableSpace S] (n : ℕ) : + Measurable (indexedCascadeRealize (S := S) n) := by + induction n with + | zero => exact measurable_const + | succ n ih => + dsimp only [indexedCascadeRealize] + apply indexedPoissonMeasure_measurable.comp + fun_prop + +instance countablePoissonIntensity_sfinite {A : Type*} [MeasurableSpace A] + (r : ℕ → ℝ≥0) (ρ : ℕ → Measure A) [∀ i, IsProbabilityMeasure (ρ i)] : + SFinite (countablePoissonIntensity r ρ) := by + unfold countablePoissonIntensity + infer_instance + +lemma countablePoissonLaw_eq_canonical {A : Type*} [MeasurableSpace A] [Nonempty A] + (r : ℕ → ℝ≥0) (ρ : ℕ → Measure A) [∀ i, IsProbabilityMeasure (ρ i)] : + countablePoissonLaw r ρ = poissonRandomMeasureLaw (countablePoissonIntensity r ρ) := by + apply measureLaw_eq_of_laplace + intro f hf hf0 + rw [countablePoissonLaw_laplace_intensity _ _ hf hf0, + poissonRandomMeasureLaw_laplace _ hf hf0] + +lemma prod_rotate_front {A B C : Type*} [MeasurableSpace A] [MeasurableSpace B] + [MeasurableSpace C] (μ : Measure A) (ν : Measure B) (τ : Measure C) + [SFinite μ] [SFinite ν] [SFinite τ] : + (μ.prod (ν.prod τ)).map (fun p => (p.2.1,(p.1,p.2.2))) = ν.prod (μ.prod τ) := by + have h := (measurePreserving_prodAssoc ν μ τ).comp + (((Measure.measurePreserving_swap (μ := μ) (ν := ν)).prod (MeasurePreserving.id τ)).comp + (measurePreserving_prodAssoc μ ν τ).symm) + exact h.map_eq + +lemma indexedPoissonMeasure_map {A B : Type*} [MeasurableSpace A] [MeasurableSpace B] + {g : A → B} (hg : Measurable g) (a : ℕ → ℕ × (ℕ → A)) : + (indexedPoissonMeasure a).map g = + indexedPoissonMeasure (fun i => ((a i).1,fun j => g ((a i).2 j))) := by + unfold indexedPoissonMeasure indexedFiniteCloud finitePointMeasure + rw [Measure.map_sum hg.aemeasurable] + simp_rw [Measure.map_finset_sum hg.aemeasurable,Measure.map_dirac' hg] + +lemma prod_interlace_law {A B C D E : Type*} [MeasurableSpace A] [MeasurableSpace B] + [MeasurableSpace C] [MeasurableSpace D] [MeasurableSpace E] + (α : Measure A) (β : Measure B) (γ : Measure C) (δ : Measure D) (ε : Measure E) + [SFinite α] [SFinite β] [SFinite γ] [SFinite δ] [SFinite ε] + {g : B × D → E} (hg : MeasurePreserving g (β.prod δ) ε) : + ((α.prod β).prod (γ.prod δ)).map + (fun p => (p.1.1,(p.2.1,g (p.1.2,p.2.2)))) = α.prod (γ.prod ε) := by + have h₁ := measurePreserving_prodAssoc α β (γ.prod δ) + have h₂ : MeasurePreserving (fun p : B × (C × D) => (p.2.1,(p.1,p.2.2))) + (β.prod (γ.prod δ)) (γ.prod (β.prod δ)) := + ⟨by fun_prop,prod_rotate_front β γ δ⟩ + exact (((MeasurePreserving.id α).prod ((MeasurePreserving.id γ).prod hg)).comp + (((MeasurePreserving.id α).prod h₂).comp h₁)).map_eq + +lemma indexedCascadeRealize_law {S : Type} [MeasurableSpace S] [Nonempty S] + (ν : ProbabilityMeasure S) (n : ℕ) (z : Fin n → ℝ) : + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n)).map (indexedCascadeRealize n) = + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) := by + induction n with + | zero => simp [indexedCascadeBaseLaw,indexedCascadeMarksLaw,indexedCascadeRealize,decoratedCascadeLaw] + | succ n ih => + let κ := stableLogIntensity (z 0) + let r : ℕ → ℝ≥0 := fun i => ((sfiniteSeq κ i) univ).toNNReal + let ρ := fun i => finiteIntensityMarks (sfiniteSeq κ i) + let B := (indexedCascadeBaseLaw n (fun j => z j.succ) : Measure (IndexedCascadeBase n)) + let M := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)) + let D := (decoratedCascadeLaw ν n (fun j => z j.succ) : Measure (DecoratedCascade S n)) + let f : ((ℝ × IndexedCascadeBase n) × (S × IndexedCascadeMarks S n)) → + ℝ × (S × DecoratedCascade S n) := + fun p => (p.1.1,(p.2.1,indexedCascadeRealize n (p.1.2,p.2.2))) + have hf : Measurable f := by + exact measurable_fst.fst.prodMk (measurable_snd.fst.prodMk + ((indexedCascadeRealize_measurable n).comp (measurable_fst.snd.prodMk measurable_snd.snd))) + have hR : MeasurePreserving (indexedCascadeRealize (S := S) n) (B.prod M) D := + ⟨indexedCascadeRealize_measurable n,ih (fun j => z j.succ)⟩ + have hi : (countablePoissonIntensity r (fun i => (ρ i).prod B |>.prod ((ν : Measure S).prod M))).map f = + κ.prod ((ν : Measure S).prod D) := by + unfold countablePoissonIntensity + rw [Measure.map_sum hf.aemeasurable] + simp_rw [Measure.map_smul _ hf.aemeasurable] + have hfi (i : ℕ) : (((ρ i).prod B).prod ((ν : Measure S).prod M)).map f = + (ρ i).prod ((ν : Measure S).prod D) := + prod_interlace_law (ρ i) B (ν : Measure S) M D hR + simp_rw [hfi] + dsimp only [r,ρ] + simp_rw [← Measure.prod_smul_left,finiteIntensityMarks_smul] + rw [← Measure.prod_sum_left,sum_sfiniteSeq] + let P := Measure.infinitePi (fun i => (poissonMeasure (r i)).prod + (Measure.infinitePi (fun _ : ℕ => (ρ i).prod B))) + let Q := Measure.infinitePi (fun _ : ℕ => Measure.infinitePi (fun _ : ℕ => (ν : Measure S).prod M)) + let a : ((ℕ → ℕ × (ℕ → ℝ × IndexedCascadeBase n)) × + (ℕ → ℕ → S × IndexedCascadeMarks S n)) → + ℕ → ℕ × (ℕ → (ℝ × IndexedCascadeBase n) × (S × IndexedCascadeMarks S n)) := + fun p i => ((p.1 i).1,fun j => ((p.1 i).2 j,p.2 i j)) + have ha : Measurable a := by fun_prop + have he : indexedCascadeRealize (S := S) (n+1) = + Measure.map f ∘ (indexedPoissonMeasure ∘ a) := by + funext p + exact (indexedPoissonMeasure_map hf (a p)).symm + change (P.prod Q).map (indexedCascadeRealize (S := S) (n+1)) = + poissonRandomMeasureLaw (κ.prod ((ν : Measure S).prod D)) + rw [he,← Measure.map_map (Measure.measurable_map f hf) + (indexedPoissonMeasure_measurable.comp ha)] + have hP := indexedMarkedPoisson_law r (fun i => (ρ i).prod B) ((ν : Measure S).prod M) + change (P.prod Q).map (indexedPoissonMeasure ∘ a) = _ at hP + rw [hP,countablePoissonLaw_eq_canonical,poissonRandomMeasureLaw_map _ hf] + congr 1 + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/IndexedPoisson.lean b/lean/OAI/Probability/Perceptron/Cascade/IndexedPoisson.lean new file mode 100644 index 0000000000000000000000000000000000000000..dda5d8424371be16e71a9243a12ba9a22c73bad7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/IndexedPoisson.lean @@ -0,0 +1,75 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.PoissonLaplace + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +variable {S : Type*} [MeasurableSpace S] + +def indexedFiniteCloud (a : ℕ × (ℕ → S)) : Measure S := + finitePointMeasure a.1 (fun i => a.2 i.val) + +lemma indexedFiniteCloud_measurable : Measurable (indexedFiniteCloud (S := S)) := by + have h : Measurable (fun a : (ℕ → S) × ℕ => indexedFiniteCloud (a.2,a.1)) := by + apply measurable_from_prod_countable_left + intro n + exact (finitePointMeasure_measurable n).comp (Measurable.of_eval fun index => measurable_pi_apply index.val) + exact h.comp measurable_swap + +lemma iid_prefix_law (ν : Measure S) [IsProbabilityMeasure ν] (n : ℕ) : + (Measure.infinitePi (fun _ : ℕ => ν)).map (fun x (i : Fin n) => x i.val) = + Measure.pi (fun _ : Fin n => ν) := by + rw [Measure.map_infinitePi_infinitePi_of_inj (f := Fin.val) Fin.val_injective, + Measure.infinitePi_eq_pi] + +lemma indexedFiniteCloud_law (r : ℝ≥0) (ν : Measure S) [IsProbabilityMeasure ν] : + ((poissonMeasure r).prod (Measure.infinitePi (fun _ : ℕ => ν))).map indexedFiniteCloud = + finitePoissonLaw r ν := by + rw [← Measure.sum_smul_dirac (poissonMeasure r),Measure.prod_sum_left, + Measure.map_sum indexedFiniteCloud_measurable.aemeasurable] + simp_rw [Measure.prod_smul_left,Measure.map_smul _ indexedFiniteCloud_measurable.aemeasurable,Measure.dirac_prod, + Measure.map_map indexedFiniteCloud_measurable measurable_prodMk_left] + unfold finitePoissonLaw + congr 1 + funext n + congr 1 + rw [← iid_prefix_law ν n,Measure.map_map (finitePointMeasure_measurable n) (by fun_prop)] + rfl + +def indexedPoissonMeasure (a : ℕ → ℕ × (ℕ → S)) : Measure S := + Measure.sum (fun i => indexedFiniteCloud (a i)) + +lemma indexedPoissonMeasure_measurable : Measurable (indexedPoissonMeasure (S := S)) := + measureSum_measurable.comp (Measurable.of_eval fun index => + indexedFiniteCloud_measurable.comp (measurable_pi_apply index)) + +lemma indexedPoissonMeasure_law (r : ℕ → ℝ≥0) (ν : ℕ → Measure S) + [∀ i, IsProbabilityMeasure (ν i)] : + (Measure.infinitePi (fun i => (poissonMeasure (r i)).prod + (Measure.infinitePi (fun _ : ℕ => ν i)))).map indexedPoissonMeasure = + countablePoissonLaw r ν := by + unfold indexedPoissonMeasure countablePoissonLaw + have hm : Measurable (fun a : ℕ → ℕ × (ℕ → S) => fun i => indexedFiniteCloud (a i)) := + Measurable.of_eval fun index => indexedFiniteCloud_measurable.comp (measurable_pi_apply index) + change (Measure.infinitePi (fun i => (poissonMeasure (r i)).prod + (Measure.infinitePi (fun _ : ℕ => ν i)))).map + ((fun η : ℕ → Measure S => Measure.sum η) ∘ (fun a : ℕ → ℕ × (ℕ → S) => fun i => indexedFiniteCloud (a i))) = _ + rw [← Measure.map_map measureSum_measurable hm,Measure.infinitePi_map_pi] + · simp_rw [indexedFiniteCloud_law] + · exact fun _ => indexedFiniteCloud_measurable + +lemma indexedPoissonMeasure_canonical_law [Nonempty S] (κ : Measure S) [SFinite κ] : + (Measure.infinitePi (fun i => + (poissonMeasure (((sfiniteSeq κ i) univ).toNNReal)).prod + (Measure.infinitePi (fun _ : ℕ => finiteIntensityMarks (sfiniteSeq κ i))))).map + indexedPoissonMeasure = poissonRandomMeasureLaw κ := + indexedPoissonMeasure_law _ _ + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/IndexedReplicaWeights.lean b/lean/OAI/Probability/Perceptron/Cascade/IndexedReplicaWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b5d74f4fd73aebabbfa2e631bfe5078ed919bb6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/IndexedReplicaWeights.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.IndexedTiltedWeights + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma indexedLeaf_tsum_active (n : ℕ) (b : IndexedCascadeBase (n+1)) + (f : IndexedLeaf (n+1) → ℝ≥0∞) + (hf : ∀ i j, ¬j<(b i).1 → ∀ l : IndexedLeaf n, f (i,j,l)=0) : + (∑' l, f l) = ∑' a : Σ i, Fin ((b i).1), ∑' l : IndexedLeaf n, f (a.1,a.2.val,l) := by + change (∑' l : ℕ×ℕ×IndexedLeaf n, f l) = _ + rw [ENNReal.tsum_prod',ENNReal.tsum_sigma'] + apply tsum_congr + intro i + rw [ENNReal.tsum_prod'] + conv_rhs => rw [tsum_fintype] + rw [tsum_eq_sum (s := Finset.range ((b i).1)) (fun j hj => by + simp only [hf i j (Finset.mem_range.not.mp hj),tsum_zero])] + exact (Fin.sum_univ_eq_sum_range (fun j => ∑' l : IndexedLeaf n, f (i,j,l)) _).symm + +variable {X S : Type} [MeasurableSpace S] + +lemma indexedTiltedProbability_active (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (a : Σ i, Fin ((p.2.1 i).1)) + (hc : 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p a.1 a.2.val)).toReal) (l : IndexedLeaf n) : + indexedTiltedProbability step (n+1) F p (a.1,a.2.val,l) = + indexedBranchProbability step n F p a * indexedTiltedProbability step n (fun i => F i.succ) + (indexedChildPoint step n p a.1 a.2.val) l := by + rw [indexedTiltedProbability,indexedTiltedWeight_succ,ite_eq_left a.2.isLt] + simp only [indexedBranchProbability,indexedBranchWeight,indexedTiltedProbability] + rw [show (indexedTiltedTotal step (n+1) F p)⁻¹ * + (ENNReal.ofReal (Real.exp (((p.2.1 a.1).2 a.2.val).1+F 0 (p.1,(p.2.2 a.1 a.2.val).1)))* + indexedTiltedTotal step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val)) * + ((indexedTiltedTotal step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val))⁻¹ * + indexedTiltedWeight step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val) l) = + (indexedTiltedTotal step (n+1) F p)⁻¹ * + (ENNReal.ofReal (Real.exp (((p.2.1 a.1).2 a.2.val).1+F 0 (p.1,(p.2.2 a.1 a.2.val).1)))* + ((indexedTiltedTotal step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val))* + (indexedTiltedTotal step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val))⁻¹)* + indexedTiltedWeight step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val) l) by ac_rfl, + ENNReal.mul_inv_cancel (ENNReal.toReal_pos_iff.mp hc).1.ne' (ENNReal.toReal_pos_iff.mp hc).2.ne, + mul_one] + rfl + +lemma indexedTiltedProbability_inactive (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (i j : ℕ) (hj : ¬j<(p.2.1 i).1) (l : IndexedLeaf n) : + indexedTiltedProbability step (n+1) F p (i,j,l) = 0 := by + simp [indexedTiltedProbability,indexedTiltedWeight_succ,hj] + +lemma indexedTiltedProbability_tsum_succ (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) (f : IndexedLeaf (n+1) → ℝ≥0∞) : + (∑' l, indexedTiltedProbability step (n+1) F p l*f l) = + ∑' a : Σ i, Fin ((p.2.1 i).1), indexedBranchProbability step n F p a * + ∑' l, indexedTiltedProbability step n (fun i => F i.succ) + (indexedChildPoint step n p a.1 a.2.val) l * f (a.1,a.2.val,l) := by + rw [indexedLeaf_tsum_active n p.2.1 _ (by + intro i j hj l; rw [indexedTiltedProbability_inactive step n F p i j hj l,zero_mul])] + apply tsum_congr + intro a + simp_rw [indexedTiltedProbability_active step n F p a (hc a.1 a.2.val),mul_assoc,ENNReal.tsum_mul_left] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/IndexedTiltedLeaves.lean b/lean/OAI/Probability/Perceptron/Cascade/IndexedTiltedLeaves.lean new file mode 100644 index 0000000000000000000000000000000000000000..f890ed3b7bb3352c9eecf23cd161f676e9177a03 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/IndexedTiltedLeaves.lean @@ -0,0 +1,117 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.DecoratedWeightedTotal +import OAI.Probability.Perceptron.Cascade.IndexedCascadeRegular + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + +def indexedShiftSum (step : X×S → X) : (n : ℕ) → (Fin n → X×S → ℝ) → + X×IndexedCascadeMarks S n → IndexedLeaf n → ℝ + | 0,_,_,_ => 0 + | n+1,F,p,l => F 0 (p.1,(p.2 l.1 l.2.1).1)+ + indexedShiftSum step n (fun i => F i.succ) + (step (p.1,(p.2 l.1 l.2.1).1),(p.2 l.1 l.2.1).2) l.2.2 + +lemma indexedShiftSum_measurable {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) : + Measurable (Function.uncurry (indexedShiftSum step n F)) := by + induction n with + | zero => exact measurable_const + | succ n ih => + apply measurable_from_prod_countable_left + intro l + change Measurable (fun p : X×(ℕ → ℕ → S×IndexedCascadeMarks S n) => + F 0 (p.1,(p.2 l.1 l.2.1).1)+indexedShiftSum step n (fun i => F i.succ) + (step (p.1,(p.2 l.1 l.2.1).1),(p.2 l.1 l.2.1).2) l.2.2) + exact ((hF 0).comp (by fun_prop)).add + ((ih _ (fun i => hF i.succ)).comp (show Measurable + (fun p : X×(ℕ → ℕ → S×IndexedCascadeMarks S n) => + ((step (p.1,(p.2 l.1 l.2.1).1),(p.2 l.1 l.2.1).2),l.2.2)) from by fun_prop)) + +lemma indexedShiftSum_telescoping (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin n → ℝ) (H : X → ℝ) (p : X×IndexedCascadeMarks S n) + (l : IndexedLeaf n) : + indexedShiftSum step n (finiteCascadeShifts ν step n z H) p l = + H (indexedLeafState step n p l)-finiteCascadeLogRecursion ν step n z H p.1 := by + induction n with + | zero => simp [indexedShiftSum,indexedLeafState,finiteCascadeLogRecursion] + | succ n ih => + simp only [indexedShiftSum,finiteCascadeShifts,Fin.cases_zero,Fin.cases_succ] + rw [ih] + change _ = H (indexedLeafState step n (step (p.1,(p.2 l.1 l.2.1).1), + (p.2 l.1 l.2.1).2) l.2.2)-_ + ring + +def indexedTiltedLeafMeasure (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (x : X) (b : IndexedCascadeBase n) (m : IndexedCascadeMarks S n) : + Measure (IndexedLeaf n) := + (indexedLeafMeasure n b).withDensity + (fun l => ENNReal.ofReal (Real.exp (indexedShiftSum step n F (x,m) l))) + +lemma indexedLeafMeasure_shift_identity {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (b : IndexedCascadeBase n) (hb : IndexedCascadeGood n b) + (m : IndexedCascadeMarks S n) (x : X) : + decoratedWeightedTotalE step n F (x,indexedCascadeRealize n (b,m)) = + ∫⁻ l, ENNReal.ofReal (Real.exp (indexedShiftSum step n F (x,m) l)) + ∂indexedLeafMeasure n b := by + induction n generalizing x with + | zero => + rw [indexedLeafMeasure_lintegral] + simp [decoratedWeightedTotalE,indexedShiftSum,indexedLeafWeight,IndexedLeaf] + | succ n ih => + rw [decoratedWeightedTotalE,indexedCascadeGood_countKernel hb] + unfold indexedCascadeRealize + dsimp only [Prod.fst,Prod.snd] + have hm : Measurable (fun q : ℝ×(S×DecoratedCascade S n) => + ENNReal.ofReal (Real.exp (q.1+F 0 (x,q.2.1))) * + decoratedWeightedTotalE step n (fun i => F i.succ) (step (x,q.2.1),q.2.2)) := + ((measurable_fst.add ((hF 0).comp (by fun_prop))).exp.ennreal_ofReal).mul + ((decoratedWeightedTotalE_measurable step hs n _ (fun i => hF i.succ)).comp (by fun_prop)) + rw [indexedPoissonMeasure_lintegral _ hm,indexedLeafMeasure_lintegral_succ] + apply tsum_congr + intro i + apply Finset.sum_congr rfl + intro j hj + rw [ih _ (fun i => hF i.succ) _ (hb.2 i j.val) (m i j.val).2 (step (x,(m i j.val).1))] + simp only [indexedShiftSum,Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos _).le] + rw [lintegral_const_mul' _ _ (ENNReal.ofReal_ne_top)] + exact mul_assoc _ _ _ + +lemma indexedTiltedLeafMeasure_total {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (b : IndexedCascadeBase n) (hb : IndexedCascadeGood n b) + (m : IndexedCascadeMarks S n) (x : X) : + (indexedTiltedLeafMeasure step n F x b m) univ = + decoratedWeightedTotalE step n F (x,indexedCascadeRealize n (b,m)) := by + rw [indexedTiltedLeafMeasure,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + exact (indexedLeafMeasure_shift_identity hs n F hF b hb m x).symm + +lemma indexedTiltedLeafMeasure_normalized_terminal (ν : ProbabilityMeasure S) + (step : X×S → X) (n : ℕ) (z : Fin n → ℝ) (H : X → ℝ) + (x : X) (b : IndexedCascadeBase n) (m : IndexedCascadeMarks S n) : + normalizedMeasure (indexedTiltedLeafMeasure step n (finiteCascadeShifts ν step n z H) x b m) = + normalizedMeasure ((indexedLeafMeasure n b).withDensity (fun l => + ENNReal.ofReal (Real.exp (H (indexedLeafState step n (x,m) l))))) := by + have he : indexedTiltedLeafMeasure step n (finiteCascadeShifts ν step n z H) x b m = + ENNReal.ofReal (Real.exp (-finiteCascadeLogRecursion ν step n z H x)) • + ((indexedLeafMeasure n b).withDensity (fun l => + ENNReal.ofReal (Real.exp (H (indexedLeafState step n (x,m) l))))) := by + unfold indexedTiltedLeafMeasure + rw [← withDensity_smul _ (measurable_of_countable _)] + apply withDensity_congr_ae + filter_upwards [] with l + simp only [indexedShiftSum_telescoping,sub_eq_add_neg,Real.exp_add, + ENNReal.ofReal_mul (Real.exp_pos _).le] + exact mul_comm _ _ + rw [he,normalizedMeasure_smul _ (by positivity) ENNReal.ofReal_ne_top] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/IndexedTiltedWeights.lean b/lean/OAI/Probability/Perceptron/Cascade/IndexedTiltedWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..11805bc5a77b3d429bfbec273738b57d59b5d109 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/IndexedTiltedWeights.lean @@ -0,0 +1,236 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.MarkedBlockParameter +import OAI.Probability.Perceptron.Cascade.IndexedTiltedLeaves + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +section +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + +def indexedTiltedWeight (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) (l : IndexedLeaf n) : ℝ≥0∞ := + (indexedLeafWeight n p.2.1 l : ℝ≥0∞)* + ENNReal.ofReal (Real.exp (indexedShiftSum step n F (p.1,p.2.2) l)) + +def indexedTiltedTotal (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : ℝ≥0∞ := + ∑' l, indexedTiltedWeight step n F p l + +def indexedTiltedProbability (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) (l : IndexedLeaf n) : ℝ≥0∞ := + (indexedTiltedTotal step n F p)⁻¹ * indexedTiltedWeight step n F p l + +lemma indexedTiltedWeight_measurable {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) : + Measurable (Function.uncurry (indexedTiltedWeight step n F)) := by + exact (((indexedLeafWeight_measurable n).comp (show Measurable + (fun q : (X×(IndexedCascadeBase n×IndexedCascadeMarks S n))×IndexedLeaf n => + (q.1.2.1,q.2)) from by fun_prop)).coe_nnreal_ennreal).mul + (((indexedShiftSum_measurable hs n F hF).comp (show Measurable + (fun q : (X×(IndexedCascadeBase n×IndexedCascadeMarks S n))×IndexedLeaf n => + ((q.1.1,q.1.2.2),q.2)) from by fun_prop)).exp.ennreal_ofReal) + +lemma indexedTiltedTotal_measurable {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) : + Measurable (indexedTiltedTotal step n F) := + Measurable.tsum fun _ => (indexedTiltedWeight_measurable hs n F hF).comp + (measurable_id.prodMk measurable_const) + +lemma indexedTiltedProbability_measurable {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) : + Measurable (Function.uncurry (indexedTiltedProbability step n F)) := + (((indexedTiltedTotal_measurable hs n F hF).comp measurable_fst).inv).mul + (indexedTiltedWeight_measurable hs n F hF) + +lemma indexedTiltedTotal_eq {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) (hb : IndexedCascadeGood n p.2.1) : + indexedTiltedTotal step n F p = + decoratedWeightedTotalE step n F (p.1,indexedCascadeRealize n p.2) := by + rw [indexedLeafMeasure_shift_identity hs n F hF p.2.1 hb p.2.2 p.1, + indexedLeafMeasure_lintegral] + rfl + +omit [MeasurableSpace X] in +lemma indexedTiltedProbability_mass (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) + (hp : 0 < (indexedTiltedTotal step n F p).toReal) : + ∑' l, indexedTiltedProbability step n F p l = 1 := by + simp only [indexedTiltedProbability,ENNReal.tsum_mul_left] + exact ENNReal.inv_mul_cancel (ENNReal.toReal_pos_iff.mp hp).1.ne' + (ENNReal.toReal_pos_iff.mp hp).2.ne + +omit [MeasurableSpace X] in +lemma indexedTiltedProbability_lintegral (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) (f : IndexedLeaf n → ℝ≥0∞) : + (∫⁻ l, f l ∂normalizedMeasure (indexedTiltedLeafMeasure step n F p.1 p.2.1 p.2.2)) = + ∑' l, indexedTiltedProbability step n F p l*f l := by + rw [normalizedMeasure,lintegral_smul_measure,smul_eq_mul,indexedTiltedLeafMeasure, + withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + lintegral_withDensity_eq_lintegral_mul _ (measurable_of_countable _) (measurable_of_countable _), + indexedLeafMeasure_lintegral,indexedLeafMeasure_lintegral,← ENNReal.tsum_mul_left] + apply tsum_congr + intro l + change (∑' l, (indexedLeafWeight n p.2.1 l : ℝ≥0∞)* + ENNReal.ofReal (Real.exp (indexedShiftSum step n F (p.1,p.2.2) l)))⁻¹ * + ((indexedLeafWeight n p.2.1 l : ℝ≥0∞)* + (ENNReal.ofReal (Real.exp (indexedShiftSum step n F (p.1,p.2.2) l))*f l)) = _ + simp only [indexedTiltedProbability,indexedTiltedTotal,indexedTiltedWeight,mul_assoc] + +omit [MeasurableSpace X] in +lemma indexedTiltedWeight_succ (step : X×S → X) (n : ℕ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (i j : ℕ) (l : IndexedLeaf n) : + indexedTiltedWeight step (n+1) F p (i,j,l) = + if j < (p.2.1 i).1 then ENNReal.ofReal (Real.exp (((p.2.1 i).2 j).1+F 0 (p.1,(p.2.2 i j).1)))* + indexedTiltedWeight step n (fun a => F a.succ) + (step (p.1,(p.2.2 i j).1),(((p.2.1 i).2 j).2,(p.2.2 i j).2)) l else 0 := by + by_cases hj : j<(p.2.1 i).1 + · simp only [indexedTiltedWeight,indexedLeafWeight,indexedShiftSum,ite_eq_left hj, + ENNReal.coe_mul,Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos _).le] + change (ENNReal.ofReal (Real.exp (((p.2.1 i).2 j).1))*_)*(_*_) = _ + ac_rfl + · simp [indexedTiltedWeight,indexedLeafWeight,indexedShiftSum,hj] + +omit [MeasurableSpace X] in +lemma indexedTiltedWeight_tsum_succ (step : X×S → X) (n : ℕ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (f : IndexedLeaf (n+1) → ℝ≥0∞) : + (∑' l, indexedTiltedWeight step (n+1) F p l*f l) = + ∑' i, ∑ j : Fin ((p.2.1 i).1), + ENNReal.ofReal (Real.exp (((p.2.1 i).2 j.val).1+F 0 (p.1,(p.2.2 i j.val).1)))* + ∑' l, indexedTiltedWeight step n (fun a => F a.succ) + (step (p.1,(p.2.2 i j.val).1),(((p.2.1 i).2 j.val).2,(p.2.2 i j.val).2)) l * f (i,j.val,l) := by + change (∑' l : ℕ×ℕ×IndexedLeaf n, _) = _ + rw [ENNReal.tsum_prod'] + apply tsum_congr + intro i + rw [ENNReal.tsum_prod'] + simp_rw [indexedTiltedWeight_succ] + have he (j : ℕ) : (∑' l : IndexedLeaf n, + (if j<(p.2.1 i).1 then ENNReal.ofReal (Real.exp (((p.2.1 i).2 j).1+F 0 (p.1,(p.2.2 i j).1)))* + indexedTiltedWeight step n (fun a => F a.succ) + (step (p.1,(p.2.2 i j).1),(((p.2.1 i).2 j).2,(p.2.2 i j).2)) l else 0)*f (i,j,l)) = + if j<(p.2.1 i).1 then ENNReal.ofReal (Real.exp (((p.2.1 i).2 j).1+F 0 (p.1,(p.2.2 i j).1)))* + ∑' l, indexedTiltedWeight step n (fun a => F a.succ) + (step (p.1,(p.2.2 i j).1),(((p.2.1 i).2 j).2,(p.2.2 i j).2)) l*f (i,j,l) else 0 := by + split_ifs with h + · simp_rw [mul_assoc,ENNReal.tsum_mul_left] + · simp + simp_rw [he] + rw [tsum_eq_sum (s := Finset.range ((p.2.1 i).1)) (fun j hj => by simp [Finset.mem_range.not.mp hj])] + rw [Fin.sum_univ_eq_sum_range (fun j => + ENNReal.ofReal (Real.exp (((p.2.1 i).2 j).1+F 0 (p.1,(p.2.2 i j).1)))* + ∑' l, indexedTiltedWeight step n (fun a => F a.succ) + (step (p.1,(p.2.2 i j).1),(((p.2.1 i).2 j).2,(p.2.2 i j).2)) l * f (i,j,l))] + apply Finset.sum_congr rfl + intro j hj + rw [ite_eq_left (Finset.mem_range.mp hj)] + +omit [MeasurableSpace X] in +lemma indexedTiltedTotal_succ (step : X×S → X) (n : ℕ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) : + indexedTiltedTotal step (n+1) F p = + ∑' i, ∑ j : Fin ((p.2.1 i).1), + ENNReal.ofReal (Real.exp (((p.2.1 i).2 j.val).1+F 0 (p.1,(p.2.2 i j.val).1)))* + indexedTiltedTotal step n (fun a => F a.succ) + (step (p.1,(p.2.2 i j.val).1),(((p.2.1 i).2 j.val).2,(p.2.2 i j.val).2)) := by + simpa only [mul_one,indexedTiltedTotal] using indexedTiltedWeight_tsum_succ step n F p (fun _ => 1) + +end +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +def indexedChildPoint (step : X×S → X) (n : ℕ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) (i j : ℕ) : + X×(IndexedCascadeBase n×IndexedCascadeMarks S n) := + (step (p.1,(p.2.2 i j).1),(((p.2.1 i).2 j).2,(p.2.2 i j).2)) + +def indexedRootPoint (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin (n+1) → ℝ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (a : Σ i, Fin ((p.2.1 i).1)) : ℝ×(S×DecoratedCascade S n) := + let t := ((p.2.2 a.1 a.2.val).1, + indexedCascadeRealize n ((((p.2.1 a.1).2 a.2.val).2,(p.2.2 a.1 a.2.val).2))) + ((((p.2.1 a.1).2 a.2.val).1 + decoratedCenteredRoot ν step n z F (p.1,t)),t) + +def indexedBranchWeight (step : X×S → X) (n : ℕ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (a : Σ i, Fin ((p.2.1 i).1)) : ℝ≥0∞ := + ENNReal.ofReal (Real.exp (((p.2.1 a.1).2 a.2.val).1+F 0 (p.1,(p.2.2 a.1 a.2.val).1)))* + indexedTiltedTotal step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val) + +def indexedBranchProbability (step : X×S → X) (n : ℕ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (a : Σ i, Fin ((p.2.1 i).1)) : ℝ≥0∞ := + (indexedTiltedTotal step (n+1) F p)⁻¹*indexedBranchWeight step n F p a + +omit [MeasurableSpace X] [Nonempty S] in +lemma indexedBranchWeight_tsum (step : X×S → X) (n : ℕ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) : + (∑' a, indexedBranchWeight step n F p a) = indexedTiltedTotal step (n+1) F p := by + rw [ENNReal.tsum_sigma'] + simp only [tsum_fintype,indexedBranchWeight,indexedChildPoint] + exact (indexedTiltedTotal_succ step n F p).symm + +lemma indexedRootPoint_weight (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (a : Σ i, Fin ((p.2.1 i).1)) : + ENNReal.ofReal (Real.exp (indexedRootPoint ν step n z F p a).1) = + ENNReal.ofReal (Real.exp (-(Real.log (∫ t : S×DecoratedCascade S n, + Real.exp (z 0*decoratedRootPotential step n F (p.1,t)) + ∂((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ))))/z 0)))* + indexedBranchWeight step n F p a := by + have he := indexedTiltedTotal_eq hs n (fun i => F i.succ) (fun i => hF i.succ) + (indexedChildPoint step n p a.1 a.2.val) (hb.2 a.1 a.2.val) + dsimp only [indexedChildPoint] at he + have hpos := hc a.1 a.2.val + have hfinite := (ENNReal.toReal_pos_iff.mp hpos).2.ne + simp only [indexedRootPoint,decoratedCenteredRoot,centeredLogMark,decoratedRootPotential, + decoratedWeightedTotal,← he,indexedBranchWeight] + let A := (((p.2.1 a.1).2 a.2.val).1) + let B := F 0 (p.1,(p.2.2 a.1 a.2.val).1) + let C := Real.log (∫ t : S×DecoratedCascade S n, + Real.exp (z 0*decoratedRootPotential step n F (p.1,t)) + ∂((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ)))) / z 0 + let T := indexedTiltedTotal step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val) + change ENNReal.ofReal (Real.exp (A + (B + Real.log T.toReal - C))) = + ENNReal.ofReal (Real.exp (-C))*(ENNReal.ofReal (Real.exp (A+B))*T) + rw [show A+(B+Real.log T.toReal-C) = -C+((A+B)+Real.log T.toReal) by ring, + Real.exp_add,Real.exp_add,Real.exp_log hpos, + ENNReal.ofReal_mul (Real.exp_pos _).le,ENNReal.ofReal_mul (Real.exp_pos _).le, + ENNReal.ofReal_toReal hfinite] + +lemma indexedRootPoint_probability (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (a : Σ i, Fin ((p.2.1 i).1)) : + ((∑' b, ENNReal.ofReal (Real.exp (indexedRootPoint ν step n z F p b).1))⁻¹)* + ENNReal.ofReal (Real.exp (indexedRootPoint ν step n z F p a).1) = + indexedBranchProbability step n F p a := by + simp_rw [indexedRootPoint_weight ν step hs n z F hF p hb hc, + ENNReal.tsum_mul_left,indexedBranchWeight_tsum] + rw [ENNReal.mul_inv (Or.inl (ENNReal.ofReal_ne_zero_iff.mpr (Real.exp_pos _))) + (Or.inl ENNReal.ofReal_ne_top)] + simp only [indexedBranchProbability] + rw [mul_mul_mul_comm,ENNReal.inv_mul_cancel (ENNReal.ofReal_ne_zero_iff.mpr (Real.exp_pos _)) + ENNReal.ofReal_ne_top,one_mul] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/IndexedVertices.lean b/lean/OAI/Probability/Perceptron/Cascade/IndexedVertices.lean new file mode 100644 index 0000000000000000000000000000000000000000..704e92c11c234374177407197e9a4dcae3a3d2d7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/IndexedVertices.lean @@ -0,0 +1,113 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.IndexedCascadeRegular + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +@[reducible] def IndexedVertex : ℕ → Type + | 0 => Empty + | n+1 => ℕ × ℕ × (Unit ⊕ IndexedVertex n) + +instance indexedVertex_countable (n : ℕ) : Countable (IndexedVertex n) := by + induction n with + | zero => dsimp [IndexedVertex]; infer_instance + | succ n ih => dsimp [IndexedVertex]; infer_instance + +def indexedMarksFromVertices {S : Type} [MeasurableSpace S] : (n : ℕ) → + (IndexedVertex n → S) → IndexedCascadeMarks S n + | 0,_ => () + | n+1,f => fun i j => (f (i,j,.inl ()), + indexedMarksFromVertices n (fun v => f (i,j,.inr v))) + +lemma indexedMarksFromVertices_measurable {S : Type} [MeasurableSpace S] (n : ℕ) : + Measurable (indexedMarksFromVertices (S := S) n) := by + induction n with + | zero => exact measurable_const + | succ n ih => + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + exact (measurable_pi_apply (i,j,Sum.inl ())).prodMk + (ih.comp (Measurable.of_eval fun vertex => measurable_pi_apply (i,j,Sum.inr vertex))) + +lemma infinitePi_sumPiEquivProdPi {ι κ : Type*} {X : ι ⊕ κ → Type*} + [∀ i, MeasurableSpace (X i)] (μ : ∀ i, Measure (X i)) + [∀ i, IsProbabilityMeasure (μ i)] : + (Measure.infinitePi μ).map (MeasurableEquiv.sumPiEquivProdPi X) = + (Measure.infinitePi fun i => μ (.inl i)).prod + (Measure.infinitePi fun i => μ (.inr i)) := by + rw [MeasurableEquiv.map_apply_eq_iff_map_symm_apply_eq] + exact (infinitePi_sumPiEquivProdPi_symm μ).symm + +lemma indexedMarksFromVertices_law {S : Type} [MeasurableSpace S] + (ν : ProbabilityMeasure S) (n : ℕ) : + (Measure.infinitePi (fun _ : IndexedVertex n => (ν : Measure S))).map + (indexedMarksFromVertices n) = indexedCascadeMarksLaw ν n := by + induction n with + | zero => simp [indexedMarksFromVertices,indexedCascadeMarksLaw,Measure.map_const] + | succ n ih => + let Q := Measure.infinitePi (fun _ : Unit ⊕ IndexedVertex n => (ν : Measure S)) + let M := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)) + let a : (Unit ⊕ IndexedVertex n → S) → S×IndexedCascadeMarks S n := fun f => + (f (.inl ()),indexedMarksFromVertices n (fun v => f (.inr v))) + have ha : Measurable a := (measurable_pi_apply _).prodMk + ((indexedMarksFromVertices_measurable n).comp (Measurable.of_eval fun vertex => measurable_pi_apply (Sum.inr vertex))) + have haQ : Q.map a = (ν : Measure S).prod M := by + let e := MeasurableEquiv.sumPiEquivProdPi (fun _ : Unit ⊕ IndexedVertex n => S) + have he : a = (Prod.map (fun f : Unit → S => f ()) (indexedMarksFromVertices n)) ∘ e := rfl + rw [he,← Measure.map_map ((measurable_pi_apply ()).prodMap (indexedMarksFromVertices_measurable n)) e.measurable,infinitePi_sumPiEquivProdPi] + rw [← Measure.map_prod_map _ _ (by fun_prop) (indexedMarksFromVertices_measurable n),ih] + rw [(measurePreserving_eval_infinitePi (fun _ : Unit => (ν : Measure S)) ()).map_eq] + let e := MeasurableEquiv.curry ℕ (ℕ × (Unit ⊕ IndexedVertex n)) S + let r := MeasurableEquiv.curry ℕ (Unit ⊕ IndexedVertex n) S + let c : (IndexedVertex (n+1) → S) → ℕ → ℕ → Unit ⊕ IndexedVertex n → S := + fun f i j v => f (i,j,v) + have hc : Measurable c := by fun_prop + have hcQ : (Measure.infinitePi (fun _ : IndexedVertex (n+1) => (ν : Measure S))).map c = + Measure.infinitePi (fun _ : ℕ => Measure.infinitePi (fun _ : ℕ => Q)) := by + have he : c = (fun f i => r (f i)) ∘ e := rfl + rw [he,← Measure.map_map (by fun_prop) e.measurable] + dsimp only [e, IndexedVertex] + rw [Measure.infinitePi_map_curry (fun _ _ => (ν : Measure S)), + Measure.infinitePi_map_pi _ (fun _ => r.measurable)] + dsimp only [r] + simp_rw [Measure.infinitePi_map_curry (fun _ _ => (ν : Measure S))] + rfl + have he : indexedMarksFromVertices (S := S) (n+1) = (fun f i j => a (f i j)) ∘ c := rfl + rw [he,← Measure.map_map (by fun_prop) hc,hcQ] + rw [Measure.infinitePi_map_pi _ (f := fun _ (f : ℕ → Unit ⊕ IndexedVertex n → S) => fun j => a (f j)) + (fun _ => Measurable.of_eval fun column => ha.comp (measurable_pi_apply column))] + simp_rw [Measure.infinitePi_map_pi _ (fun _ => ha),haQ] + rfl + +def indexedLeafVertex : (n : ℕ) → IndexedLeaf n → Fin n → IndexedVertex n + | 0,_,i => i.elim0 + | n+1,l,i => Fin.cases (l.1,l.2.1,Sum.inl ()) + (fun j => (l.1,l.2.1,Sum.inr (indexedLeafVertex n l.2.2 j))) i + +lemma indexedLeafVertex_injective (n : ℕ) (l : IndexedLeaf n) : + Function.Injective (indexedLeafVertex n l) := by + induction n with + | zero => intro i; exact i.elim0 + | succ n ih => + intro i j hij + induction i using Fin.cases with + | zero => + induction j using Fin.cases with + | zero => rfl + | succ j => simp [indexedLeafVertex] at hij + | succ i => + induction j using Fin.cases with + | zero => simp [indexedLeafVertex] at hij + | succ j => + simpa only [Fin.succ_inj] using ih l.2.2 (by simpa [indexedLeafVertex] using hij) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/PoissonCountMoments.lean b/lean/OAI/Probability/Perceptron/Cascade/PoissonCountMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..3692ef82a788dd4deb0b2973e9897000e4949f6d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/PoissonCountMoments.lean @@ -0,0 +1,130 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StableLogIntensity + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +lemma poisson_nat_lintegral (r : ℝ≥0) : + (∫⁻ m : ℕ, ENNReal.ofReal (m:ℝ) ∂poissonMeasure r)=r := by + simp_rw [ENNReal.ofReal_natCast] + rw [lintegral_countable'] + simpa only [mul_comm] using poissonMeasure_mean r + +lemma poisson_natSquare_lintegral (r : ℝ≥0) : + (∫⁻ m : ℕ, ENNReal.ofReal ((m:ℝ)^2) ∂poissonMeasure r)=(r:ℝ≥0∞)^2+r := by + have hmass : (∑' m : ℕ, poissonMeasure r {m})=1 := by + simpa using (lintegral_countable' (μ := poissonMeasure r) (fun _ => (1:ℝ≥0∞))).symm + simp_rw [ENNReal.ofReal_pow (Nat.cast_nonneg _),ENNReal.ofReal_natCast] + rw [lintegral_countable'] + simp_rw [mul_comm ((_:ℝ≥0∞)^2)] + rw [tsum_eq_zero_add' ENNReal.summable] + simp only [Nat.cast_zero,zero_pow (by norm_num : (2:ℕ)≠0),mul_zero,zero_add] + have hterm (m : ℕ) : poissonMeasure r {m+1} * ((m+1:ℕ):ℝ≥0∞)^2= + (r:ℝ≥0∞)*(poissonMeasure r {m}*(m:ℝ≥0∞))+(r:ℝ≥0∞)*poissonMeasure r {m} := by + rw [pow_two,← mul_assoc] + simp only [Nat.cast_add,Nat.cast_one] + rw [poissonMeasure_atom_succ] + ring + simp_rw [hterm] + rw [ENNReal.tsum_add,ENNReal.tsum_mul_left,ENNReal.tsum_mul_left, + poissonMeasure_mean,hmass,mul_one,pow_two] + +lemma poisson_nat_memLp (r : ℝ≥0) : MemLp (fun m : ℕ => (m:ℝ)) 2 (poissonMeasure r) := by + apply (memLp_two_iff_integrable_sq (by fun_prop)).mpr + refine ⟨by fun_prop,(hasFiniteIntegral_iff_norm _).mpr ?_⟩ + simp only [Real.norm_eq_abs,abs_sq] + rw [poisson_natSquare_lintegral] + finiteness + +lemma poisson_nat_mean (r : ℝ≥0) : (∫ m : ℕ, (m:ℝ) ∂poissonMeasure r)=r := by + rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun m => Nat.cast_nonneg m) (by fun_prop), + poisson_nat_lintegral,ENNReal.coe_toReal] + +lemma poisson_nat_square_mean (r : ℝ≥0) : + (∫ m : ℕ, (m:ℝ)^2 ∂poissonMeasure r)=(r:ℝ)^2+r := by + rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun m : ℕ => sq_nonneg (m:ℝ)) (by fun_prop), + poisson_natSquare_lintegral,ENNReal.toReal_add (by finiteness) (by finiteness), + ENNReal.toReal_pow,ENNReal.coe_toReal] + +lemma poisson_nat_variance (r : ℝ≥0) : variance (fun m : ℕ => (m:ℝ)) (poissonMeasure r)=r := by + rw [variance_eq_sub (poisson_nat_memLp r)] + simp only [Pi.pow_apply,poisson_nat_mean,poisson_nat_square_mean] + ring + +lemma poisson_nat_center_square (r : ℝ≥0) (a : ℝ) : + (∫ m : ℕ, ((m:ℝ)-a)^2 ∂poissonMeasure r)=(r:ℝ)+((r:ℝ)-a)^2 := by + have hi := (poisson_nat_memLp r).integrable (by norm_num) + have hs := (poisson_nat_memLp r).integrable_sq + have he (m : ℕ) : ((m:ℝ)-a)^2=(m:ℝ)^2-2*a*(m:ℝ)+a^2 := by ring + simp_rw [he] + rw [integral_add (f := fun m : ℕ => (m:ℝ)^2-2*a*(m:ℝ)) + (g := fun _ : ℕ => a^2) (hs.sub (hi.const_mul (2*a))) (integrable_const _), + integral_sub (f := fun m : ℕ => (m:ℝ)^2) (g := fun m : ℕ => 2*a*(m:ℝ)) + hs (hi.const_mul (2*a)),integral_const_mul] + simp only [poisson_nat_mean,poisson_nat_square_mean] + simp + ring + +lemma nat_bounded_increment_difference {F : ℕ → ℝ} {C : ℝ} (hC : 0 ≤ C) + (hF : ∀ m, |F (m+1)-F m| ≤ C) (m n : ℕ) : + |F m-F n| ≤ C*|(m:ℝ)-(n:ℝ)| := by + have hle (m n : ℕ) (hmn : m ≤ n) : |F n-F m| ≤ C*((n:ℝ)-(m:ℝ)) := by + induction n,hmn using Nat.le_induction with + | base => simp + | succ n hmn ih => + have ht := abs_sub_le (F (n+1)) (F n) (F m) + have hh := hF n + push_cast + linarith + rcases le_total m n with hmn|hnm + · rw [abs_sub_comm (F m),abs_sub_comm (m:ℝ)] + exact (hle m n hmn).trans (mul_le_mul_of_nonneg_left (le_abs_self _) hC) + · exact (hle n m hnm).trans (mul_le_mul_of_nonneg_left (le_abs_self _) hC) + +lemma poisson_bounded_increment_memLp (r : ℝ≥0) {F : ℕ → ℝ} {C : ℝ} (hC : 0 ≤ C) + (hF : ∀ m, |F (m+1)-F m| ≤ C) : MemLp F 2 (poissonMeasure r) := by + have hi : MemLp (fun m : ℕ => |F 0|+C*(m:ℝ)) 2 (poissonMeasure r) := + (memLp_const (μ := poissonMeasure r) |F 0|).add ((poisson_nat_memLp r).const_mul C) + refine hi.mono (measurable_of_countable F).aestronglyMeasurable (ae_of_all _ fun m => ?_) + simp only [Real.norm_eq_abs] + rw [abs_of_nonneg (show (0:ℝ) ≤ |F 0|+C*(m:ℝ) by positivity)] + have hh := nat_bounded_increment_difference hC hF m 0 + simp only [Nat.cast_zero,sub_zero,abs_of_nonneg (show (0:ℝ) ≤ (m:ℝ) from Nat.cast_nonneg m)] at hh + have ht := abs_sub_le (F m) (F 0) 0 + simp only [sub_zero] at ht + linarith + +lemma poisson_bounded_increment_variance (r : ℝ≥0) {F : ℕ → ℝ} {C : ℝ} (hC : 0 ≤ C) + (hF : ∀ m, |F (m+1)-F m| ≤ C) : + variance F (poissonMeasure r) ≤ C^2*((r:ℝ)+1) := by + let a : ℕ := ⌊(r:ℝ)⌋₊ + have hp := poisson_bounded_increment_memLp r hC hF + have hv := variance_le_expectation_sq ((hp.sub (memLp_const (F a))).aestronglyMeasurable) + change variance (fun m => F m-F a) (poissonMeasure r) ≤ + ∫ m, (F m-F a)^2 ∂poissonMeasure r at hv + rw [variance_sub_const hp.aestronglyMeasurable] at hv + have hc : Integrable (fun m : ℕ => C^2*((m:ℝ)-(a:ℝ))^2) (poissonMeasure r) := + ((poisson_nat_memLp r).sub (memLp_const (a:ℝ))).integrable_sq.const_mul _ + have hd : (∫ m, (F m-F a)^2 ∂poissonMeasure r) ≤ + C^2*((r:ℝ)+((r:ℝ)-(a:ℝ))^2) := by + calc + _ ≤ ∫ m : ℕ, C^2*((m:ℝ)-(a:ℝ))^2 ∂poissonMeasure r := by + apply integral_mono (hp.sub (memLp_const (F a))).integrable_sq hc + intro m + have hh := nat_bounded_increment_difference hC hF m a + have hs := pow_le_pow_left₀ (abs_nonneg _) hh 2 + simpa only [sq_abs,mul_pow,Pi.sub_apply] using hs + _ = _ := by rw [integral_const_mul,poisson_nat_center_square] + have hfloor : (a:ℝ) ≤ (r:ℝ) := Nat.floor_le r.coe_nonneg + have hceil : (r:ℝ) < (a:ℝ)+1 := Nat.lt_floor_add_one (r:ℝ) + have hsq : ((r:ℝ)-(a:ℝ))^2 ≤ 1 := by nlinarith + exact hv.trans (hd.trans (mul_le_mul_of_nonneg_left (by linarith) (sq_nonneg C))) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/PoissonDensityDerivative.lean b/lean/OAI/Probability/Perceptron/Cascade/PoissonDensityDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..4a009c2e2bbbbc0cd68581f245cdb5198226acce --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/PoissonDensityDerivative.lean @@ -0,0 +1,113 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.PoissonCountMoments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +lemma summable_nat_mul_pow_div_factorial (r : ℝ) : + Summable (fun n : ℕ => (n:ℝ)*r^n/(n.factorial:ℝ)) := by + apply (summable_nat_add_iff 1).mp + have hs := (Real.summable_pow_div_factorial r).mul_left r + apply hs.congr + intro n + simp only [Nat.factorial_succ,Nat.cast_mul,Nat.cast_add,Nat.cast_one,pow_succ] + field_simp + +lemma summable_linear_pow_div_factorial (A C r : ℝ) : + Summable (fun n : ℕ => (A+C*(n:ℝ))*r^n/(n.factorial:ℝ)) := by + have h := ((Real.summable_pow_div_factorial r).mul_left A).add + ((summable_nat_mul_pow_div_factorial r).mul_left C) + apply h.congr + intro n + ring + +lemma bounded_increment_linear_bound {F : ℕ→ℝ} {C : ℝ} (hC : 0≤C) + (hF : ∀ n, |F (n+1)-F n|≤C) (n : ℕ) : |F n|≤|F 0|+C*(n:ℝ) := by + have h := nat_bounded_increment_difference hC hF n 0 + simp only [Nat.cast_zero,sub_zero,Nat.abs_cast] at h + calc |F n| ≤ |F n-F 0|+|F 0| := by simpa using abs_sub_le (F n) (F 0) 0 + _ ≤ |F 0|+C*(n:ℝ) := by linarith + +lemma bounded_increment_factorial_summable {F : ℕ→ℝ} {C : ℝ} (hC : 0≤C) + (hF : ∀ n, |F (n+1)-F n|≤C) (t : ℝ) : + Summable (fun n => t^n/(n.factorial:ℝ)*F n) := by + refine Summable.of_norm_bounded (summable_linear_pow_div_factorial |F 0| C |t|) fun n => ?_ + simp only [Real.norm_eq_abs,abs_mul,abs_div,abs_pow,Nat.abs_cast] + simpa only [div_eq_mul_inv,mul_comm,mul_left_comm,mul_assoc] using + mul_le_mul_of_nonneg_left (bounded_increment_linear_bound hC hF n) + (show 0≤|t|^n/(n.factorial:ℝ) by positivity) + +lemma hasDerivAt_factorial_series {F : ℕ→ℝ} {C : ℝ} (hC : 0≤C) + (hF : ∀ n, |F (n+1)-F n|≤C) (t : ℝ) : + HasDerivAt (fun s => ∑' n, s^n/(n.factorial:ℝ)*F n) + (∑' n, t^n/(n.factorial:ℝ)*F (n+1)) t := by + let R := |t|+1 + let g := fun n : ℕ => fun s : ℝ => s^(n+1)/((n+1).factorial:ℝ)*F (n+1) + let g' := fun n : ℕ => fun s : ℝ => s^n/(n.factorial:ℝ)*F (n+1) + let b := fun n : ℕ => (|F 0|+C+C*(n:ℝ))*R^n/(n.factorial:ℝ) + have hb : Summable b := summable_linear_pow_div_factorial (|F 0|+C) C R + have hg : ∀ n s, s∈Ioo (-R) R → HasDerivAt (g n) (g' n s) s := by + intro n s _ + unfold g g' + apply HasDerivAt.congr_deriv ((((hasDerivAt_id s).pow (n+1)).div_const ((n+1).factorial:ℝ)).mul_const (F (n+1))) + simp only [Nat.add_sub_cancel,Nat.factorial_succ,Nat.cast_mul,Nat.cast_add,Nat.cast_one,mul_one] + field_simp + simp [id_eq,mul_comm] + have hbound : ∀ n s, s∈Ioo (-R) R → ‖g' n s‖≤b n := by + intro n s hs + have ha : |s|≤R := (abs_le.mpr ⟨hs.1.le,hs.2.le⟩) + have hf := bounded_increment_linear_bound hC hF (n+1) + simp only [Nat.cast_add,Nat.cast_one] at hf + simp only [g',b,Real.norm_eq_abs,abs_mul,abs_div,abs_pow,Nat.abs_cast] + calc _ ≤ (R^n/(n.factorial:ℝ))*(|F 0|+C+C*(n:ℝ)) := by + apply mul_le_mul + · exact div_le_div_of_nonneg_right (pow_le_pow_left₀ (abs_nonneg _) ha _) (by positivity) + · linarith + · positivity + · positivity + _ = _ := by ring + have hz : (0:ℝ)∈Ioo (-R) R := by dsimp [R]; constructor <;> linarith [abs_nonneg t] + have ht : t∈Ioo (-R) R := by dsimp [R]; constructor <;> linarith [le_abs_self t,neg_abs_le t] + have hzero : Summable (fun n => g n 0) := by simp [g] + have hd := hasDerivAt_tsum_of_isPreconnected hb isOpen_Ioo (convex_Ioo (-R) R).isPreconnected + hg hbound hz hzero ht + have he : ∀ s : ℝ, (F 0+(∑' n, g n s))=(∑' n, s^n/(n.factorial:ℝ)*F n) := by + intro s + rw [tsum_eq_zero_add' ((summable_nat_add_iff 1).mpr (bounded_increment_factorial_summable hC hF s))] + simp [g] + have hh := hd.const_add (F 0) + simp_rw [he] at hh + exact hh + +def poissonRealMean (F : ℕ→ℝ) (t : ℝ) : ℝ := + Real.exp (-t)*(∑' n, t^n/(n.factorial:ℝ)*F n) + +lemma poissonRealMean_eq_integral {F : ℕ→ℝ} {C : ℝ} (hC : 0≤C) + (hF : ∀ n, |F (n+1)-F n|≤C) (t : ℝ≥0) : + poissonRealMean F t = ∫ n, F n ∂poissonMeasure t := by + rw [integral_countable ((poisson_bounded_increment_memLp t hC hF).integrable (by norm_num))] + simp only [poissonMeasure_real_singleton,smul_eq_mul,poissonRealMean] + rw [← tsum_mul_left] + congr 1 + ext n + ring + +lemma hasDerivAt_poissonRealMean {F : ℕ→ℝ} {C : ℝ} (hC : 0≤C) + (hF : ∀ n, |F (n+1)-F n|≤C) (t : ℝ) : + HasDerivAt (poissonRealMean F) + (poissonRealMean (fun n => F (n+1)-F n) t) t := by + have hs := bounded_increment_factorial_summable hC hF t + have hs' := bounded_increment_factorial_summable (F := fun n => F (n+1)) hC (fun n => hF (n+1)) t + have hd := (((hasDerivAt_id t).neg).exp).mul (hasDerivAt_factorial_series hC hF t) + apply hd.congr_deriv + simp only [poissonRealMean,mul_sub,hs'.tsum_sub hs,Pi.neg_apply,id_eq] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/PoissonLaplace.lean b/lean/OAI/Probability/Perceptron/Cascade/PoissonLaplace.lean new file mode 100644 index 0000000000000000000000000000000000000000..74bf79061a1ee757c8bc6dbf40ef725df8c17d4b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/PoissonLaplace.lean @@ -0,0 +1,418 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.FiniteOverlap + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma expNegENNReal_finite {u : ℝ≥0∞} (hu : u ≠ ⊤) : + expNegENNReal u = Real.exp (-u.toReal) := by + unfold expNegENNReal + rw [← EReal.coe_ennreal_toReal hu,← EReal.coe_neg,EReal.exp_coe, + ENNReal.toReal_ofReal (Real.exp_pos _).le] + +@[simp] lemma expNegENNReal_top : expNegENNReal ⊤ = 0 := by simp [expNegENNReal] + +def poissonLaplace {S : Type*} [MeasurableSpace S] (f : S → ℝ) (η : Measure S) : ℝ := + expNegENNReal (∫⁻ x, ENNReal.ofReal (f x) ∂η) + +lemma poissonLaplace_measurable {S : Type*} [MeasurableSpace S] + {f : S → ℝ} (hf : Measurable f) : Measurable (poissonLaplace f) := + expNegENNReal_continuous.measurable.comp (Measure.measurable_lintegral hf.ennreal_ofReal) + +lemma poissonLaplace_bounds {S : Type*} [MeasurableSpace S] + (f : S → ℝ) (η : Measure S) : 0 ≤ poissonLaplace f η ∧ poissonLaplace f η ≤ 1 := + expNegENNReal_bound _ + +lemma poissonLaplace_finitePointMeasure {S : Type*} [MeasurableSpace S] + {f : S → ℝ} (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) + (n : ℕ) (x : Fin n → S) : + poissonLaplace f (finitePointMeasure n x) = ∏ i : Fin n, Real.exp (-f (x i)) := by + simp only [poissonLaplace,finitePointMeasure,lintegral_finsetSum_measure] + simp_rw [lintegral_dirac' _ hf.ennreal_ofReal] + rw [expNegENNReal_finite (ENNReal.sum_ne_top.mpr (fun _ _ => ENNReal.ofReal_ne_top)),ENNReal.toReal_sum (fun _ _ => ENNReal.ofReal_ne_top)] + simp_rw [ENNReal.toReal_ofReal (hf0 _)] + rw [← Finset.sum_neg_distrib,Real.exp_sum] + +lemma finitePoissonLaw_laplace {S : Type*} [MeasurableSpace S] + (r : ℝ≥0) (ν : Measure S) [IsProbabilityMeasure ν] + {f : S → ℝ} (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) : + ∫ η, poissonLaplace f η ∂finitePoissonLaw r ν = + Real.exp ((r : ℝ) * ((∫ x, Real.exp (-f x) ∂ν) - 1)) := by + have hi : Integrable (poissonLaplace f) (finitePoissonLaw r ν) := by + apply Integrable.of_bound (poissonLaplace_measurable hf).aestronglyMeasurable 1 + exact ae_of_all _ fun η => by + rw [Real.norm_eq_abs,abs_of_nonneg (poissonLaplace_bounds f η).1] + exact (poissonLaplace_bounds f η).2 + rw [finitePoissonLaw,integral_sum_measure hi] + simp_rw [integral_smul_measure] + have hlocal (n : ℕ) : + ∫ η, poissonLaplace f η ∂((Measure.pi fun _ : Fin n => ν).map (finitePointMeasure n)) = + (∫ x, Real.exp (-f x) ∂ν)^n := by + rw [integral_map (finitePointMeasure_measurable n).aemeasurable + (poissonLaplace_measurable hf).aestronglyMeasurable] + simp_rw [poissonLaplace_finitePointMeasure hf hf0] + rw [integral_fintype_prod_eq_prod (fun (_ : Fin n) (x : S) => Real.exp (-f x))] + simp + simp_rw [hlocal,smul_eq_mul] + have hp := poisson_power_integral r (∫ x, Real.exp (-f x) ∂ν) + rw [integral_poissonMeasure] at hp + simpa only [measureReal_def,← poissonMeasure_real_singleton,smul_eq_mul] using hp + +@[simp] lemma expNegENNReal_zero : expNegENNReal 0 = 1 := by simp [expNegENNReal] + +lemma expNegENNReal_add (u v : ℝ≥0∞) : + expNegENNReal (u+v) = expNegENNReal u * expNegENNReal v := by + by_cases hu : u = ⊤ + · simp [hu] + by_cases hv : v = ⊤ + · simp [hv] + rw [expNegENNReal_finite (ENNReal.add_ne_top.mpr ⟨hu,hv⟩), + expNegENNReal_finite hu,expNegENNReal_finite hv,ENNReal.toReal_add hu hv, + neg_add,Real.exp_add] + +lemma expNegENNReal_sum {ι : Type*} (s : Finset ι) (a : ι → ℝ≥0∞) : + expNegENNReal (∑ i ∈ s, a i) = ∏ i ∈ s, expNegENNReal (a i) := by + classical + induction s using Finset.induction_on with + | empty => simp + | @insert i s hi ih => simp [hi,expNegENNReal_add,ih] + +lemma measureSum_measurable {S : Type*} [MeasurableSpace S] : + Measurable (fun η : ℕ → Measure S => Measure.sum η) := by + apply Measure.measurable_of_measurable_coe + intro s hs + simp only [Measure.sum_apply _ hs] + exact Measurable.tsum fun i => (Measure.measurable_coe hs).comp (measurable_pi_apply i) + +lemma poissonLaplace_finsetSum {S : Type*} [MeasurableSpace S] + (f : S → ℝ) (s : Finset ℕ) (η : ℕ → Measure S) : + poissonLaplace f (∑ i ∈ s, η i) = ∏ i ∈ s, poissonLaplace f (η i) := by + simp only [poissonLaplace,lintegral_finsetSum_measure,expNegENNReal_sum] + +lemma poissonLaplace_sum_tendsto {S : Type*} [MeasurableSpace S] + (f : S → ℝ) (η : ℕ → Measure S) : + Tendsto (fun n => poissonLaplace f (∑ i ∈ Finset.range n, η i)) atTop + (𝓝 (poissonLaplace f (Measure.sum η))) := by + simp only [poissonLaplace,lintegral_sum_measure,lintegral_finsetSum_measure] + exact expNegENNReal_continuous.continuousAt.tendsto.comp + (ENNReal.summable.hasSum.tendsto_sum_nat) + +def countablePoissonLaw {S : Type*} [MeasurableSpace S] + (r : ℕ → ℝ≥0) (ν : ℕ → Measure S) : Measure (Measure S) := + (Measure.infinitePi fun i => finitePoissonLaw (r i) (ν i)).map Measure.sum + +instance countablePoissonLaw_probability {S : Type*} [MeasurableSpace S] + (r : ℕ → ℝ≥0) (ν : ℕ → Measure S) [∀ i, IsProbabilityMeasure (ν i)] : + IsProbabilityMeasure (countablePoissonLaw r ν) := by + unfold countablePoissonLaw + infer_instance + +lemma finitePoissonLaw_laplace_nonneg {S : Type*} [MeasurableSpace S] + (r : ℝ≥0) (ν : Measure S) [IsProbabilityMeasure ν] + {f : S → ℝ} (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) : + ∫ η, poissonLaplace f η ∂finitePoissonLaw r ν = + expNegENNReal (ENNReal.ofReal ((r : ℝ) * ∫ x, 1 - Real.exp (-f x) ∂ν)) := by + have hib : Integrable (fun x => Real.exp (-f x)) ν := by + apply Integrable.of_bound (hf.neg.exp.aestronglyMeasurable) 1 + exact ae_of_all _ fun x => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_one_iff.mpr (neg_nonpos.mpr (hf0 x)) + have hn : 0 ≤ (r : ℝ) * ∫ x, 1 - Real.exp (-f x) ∂ν := by + apply mul_nonneg r.coe_nonneg + apply integral_nonneg + intro x + exact sub_nonneg.mpr (Real.exp_le_one_iff.mpr (neg_nonpos.mpr (hf0 x))) + rw [finitePoissonLaw_laplace r ν hf hf0,expNegENNReal_finite ENNReal.ofReal_ne_top, + ENNReal.toReal_ofReal hn,integral_sub (integrable_const 1) hib] + simp only [integral_const,probReal_univ,one_smul] + congr 1 + ring + +lemma countablePoissonLaw_laplace {S : Type*} [MeasurableSpace S] + (r : ℕ → ℝ≥0) (ν : ℕ → Measure S) [∀ i, IsProbabilityMeasure (ν i)] + {f : S → ℝ} (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) : + ∫ η, poissonLaplace f η ∂countablePoissonLaw r ν = + expNegENNReal (∑' i, ENNReal.ofReal ((r i : ℝ) * ∫ x, 1 - Real.exp (-f x) ∂ν i)) := by + let Q := Measure.infinitePi fun i => finitePoissonLaw (r i) (ν i) + let a (i : ℕ) := ENNReal.ofReal ((r i : ℝ) * ∫ x, 1 - Real.exp (-f x) ∂ν i) + have hm (n : ℕ) : Measurable (fun η : ℕ → Measure S => + poissonLaplace f (∑ i ∈ Finset.range n, η i)) := by + apply (poissonLaplace_measurable hf).comp + fun_prop + have he (n : ℕ) : + ∫ η, poissonLaplace f (∑ i ∈ Finset.range n, η i) ∂Q = + expNegENNReal (∑ i ∈ Finset.range n, a i) := by + simp_rw [poissonLaplace_finsetSum] + have he' : (fun η : ℕ → Measure S => ∏ i ∈ Finset.range n, poissonLaplace f (η i)) = + (fun η : ℕ → Measure S => ∏ i : (Finset.range n), + poissonLaplace f ((Finset.range n).restrict η i)) := by + funext η + exact (Finset.prod_coe_sort (Finset.range n) (fun i => poissonLaplace f (η i))).symm + rw [he'] + rw [integral_restrict_infinitePi (μ := fun i => finitePoissonLaw (r i) (ν i)) + (f := fun η : (i : Finset.range n) → Measure S => ∏ i, poissonLaplace f (η i)) + (by exact (Finset.measurable_prod _ (fun i _ => (poissonLaplace_measurable hf).comp + (measurable_pi_apply i))).aestronglyMeasurable)] + rw [integral_fintype_prod_eq_prod (fun (i : Finset.range n) (η : Measure S) => + poissonLaplace f η)] + simp_rw [finitePoissonLaw_laplace_nonneg _ _ hf hf0] + rw [expNegENNReal_sum] + exact Finset.prod_coe_sort (Finset.range n) (fun i => expNegENNReal (a i)) + have ht : Tendsto (fun n => ∫ η, poissonLaplace f (∑ i ∈ Finset.range n, η i) ∂Q) + atTop (𝓝 (∫ η, poissonLaplace f (Measure.sum η) ∂Q)) := by + apply tendsto_integral_of_dominated_convergence (fun _ => 1) + (fun n => (hm n).aestronglyMeasurable) (integrable_const 1) + · intro n + exact ae_of_all _ fun η => by + rw [Real.norm_eq_abs,abs_of_nonneg (poissonLaplace_bounds _ _).1] + exact (poissonLaplace_bounds _ _).2 + · exact ae_of_all _ (poissonLaplace_sum_tendsto f) + simp_rw [he] at ht + have ht' : Tendsto (fun n => expNegENNReal (∑ i ∈ Finset.range n, a i)) atTop + (𝓝 (expNegENNReal (∑' i, a i))) := + expNegENNReal_continuous.continuousAt.tendsto.comp ENNReal.summable.hasSum.tendsto_sum_nat + rw [countablePoissonLaw, integral_map measureSum_measurable.aemeasurable + (poissonLaplace_measurable hf).aestronglyMeasurable] + exact tendsto_nhds_unique ht ht' + +lemma measure_eq_of_additive_test_family {X M : Type*} + [TopologicalSpace X] [PolishSpace X] [MeasurableSpace X] [BorelSpace X] + [AddMonoid M] (g : M → X →ᵇ ℝ) + (g0 : g 0 = 1) (gadd : ∀ a b, g (a+b) = g a * g b) + (gsep : ∀ x y : X, x ≠ y → ∃ a, g a x ≠ g a y) + (P Q : Measure X) [IsFiniteMeasure P] [IsFiniteMeasure Q] + (heq : ∀ a, ∫ x, g a x ∂P = ∫ x, g a x ∂Q) : P = Q := by + let K : Submonoid (X →ᵇ ℝ) := + { carrier := Set.range g + one_mem' := ⟨0,g0⟩ + mul_mem' := by + rintro _ _ ⟨a,rfl⟩ ⟨b,rfl⟩ + exact ⟨a+b,gadd a b⟩ } + let A : StarSubalgebra ℝ (X →ᵇ ℝ) := + { toSubalgebra := Algebra.adjoin ℝ (K : Set (X →ᵇ ℝ)) + star_mem' := fun {f} hf => by + have hstar : star f = f := by ext x; simp + rwa [hstar] } + have hsep : (A.map (BoundedContinuousFunction.toContinuousMapStarₐ ℝ)).SeparatesPoints := by + intro x y hxy + obtain ⟨a,ha⟩ := gsep x y hxy + use g a + simp only [StarSubalgebra.coe_toSubalgebra, StarSubalgebra.coe_map, Set.mem_image, + SetLike.mem_coe, exists_exists_and_eq_and, ne_eq] + refine ⟨⟨g a,?_,rfl⟩,ha⟩ + exact Algebra.subset_adjoin (show g a ∈ K from ⟨a,rfl⟩) + apply ext_of_forall_mem_subalgebra_integral_eq_of_polish hsep + intro f hf + let V : Submodule ℝ (X →ᵇ ℝ) := + { carrier := {f | ∫ x, f x ∂P = ∫ x, f x ∂Q} + zero_mem' := by simp + add_mem' := by + intro a b ha hb + change ∫ x, a x + b x ∂P = ∫ x, a x + b x ∂Q + rw [integral_add (a.integrable P) (b.integrable P), + integral_add (a.integrable Q) (b.integrable Q),ha,hb] + smul_mem' := by + intro c f hf + change ∫ x, c * f x ∂P = ∫ x, c * f x ∂Q + rw [integral_const_mul,integral_const_mul,hf] } + have hspan : Submodule.span ℝ (K : Set (X →ᵇ ℝ)) ≤ V := by + apply Submodule.span_le.mpr + rintro _ ⟨a,rfl⟩ + exact heq a + apply hspan + change f ∈ (Algebra.adjoin ℝ (K : Set (X →ᵇ ℝ))).toSubmodule at hf + rw [Algebra.adjoin_eq_span,Submonoid.closure_eq] at hf + exact hf + +lemma expNegENNReal_injective : Function.Injective expNegENNReal := by + intro u v huv + have hfinite (w : ℝ≥0∞) : EReal.exp (-(w : EReal)) ≠ ⊤ := + ne_of_lt (lt_of_le_of_lt (EReal.exp_le_one_iff.mpr + (EReal.neg_le_zero.mpr (EReal.coe_ennreal_nonneg w))) ENNReal.one_lt_top) + have he := (ENNReal.toReal_eq_toReal_iff' (hfinite u) (hfinite v)).mp huv + have hn := EReal.expOrderIso.injective he + exact EReal.coe_ennreal_injective (by simpa using congrArg Neg.neg hn) + +def laplaceTest {ι : Type*} [Fintype ι] (a : ι → ℝ≥0) : (ι → ℝ≥0∞) →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact + ⟨fun x => expNegENNReal (∑ i, (a i : ℝ≥0∞) * x i), by + apply expNegENNReal_continuous.comp + exact continuous_finsetSum _ fun i _ => + (ENNReal.continuous_const_mul ENNReal.coe_ne_top).comp (continuous_apply i)⟩ + +@[simp] lemma laplaceTest_zero {ι : Type*} [Fintype ι] : + laplaceTest (0 : ι → ℝ≥0) = 1 := by + ext x + simp [laplaceTest] + +lemma laplaceTest_add {ι : Type*} [Fintype ι] (a b : ι → ℝ≥0) : + laplaceTest (a+b) = laplaceTest a * laplaceTest b := by + ext x + simp only [laplaceTest,BoundedContinuousFunction.mkOfCompact_apply, + ContinuousMap.coe_mk,Pi.add_apply,ENNReal.coe_add,add_mul, + Finset.sum_add_distrib,expNegENNReal_add,BoundedContinuousFunction.mul_apply] + +lemma laplaceTest_separates {ι : Type*} [Fintype ι] (x y : ι → ℝ≥0∞) (hxy : x ≠ y) : + ∃ a : ι → ℝ≥0, laplaceTest a x ≠ laplaceTest a y := by + classical + obtain ⟨i,hi⟩ : ∃ i, x i ≠ y i := by + by_contra! h + exact hxy (funext h) + refine ⟨Pi.single i 1,?_⟩ + simpa [laplaceTest,Pi.single_apply,apply_ite,ite_mul] using expNegENNReal_injective.ne hi + +lemma measure_eq_of_laplace_tests {ι : Type*} [Fintype ι] + (P Q : Measure (ι → ℝ≥0∞)) [IsFiniteMeasure P] [IsFiniteMeasure Q] + (heq : ∀ a : ι → ℝ≥0, ∫ x, laplaceTest a x ∂P = ∫ x, laplaceTest a x ∂Q) : P = Q := + measure_eq_of_additive_test_family laplaceTest laplaceTest_zero laplaceTest_add + laplaceTest_separates P Q heq + +lemma measure_eq_of_map_eq_comap {X Y : Type*} [mX : MeasurableSpace X] + [mY : MeasurableSpace Y] (f : X → Y) (h : mX = mY.comap f) + (P Q : Measure X) (heq : P.map f = Q.map f) : P = Q := by + have hf : Measurable f := Measurable.of_comap_le h.ge + ext s hs + rw [h] at hs + obtain ⟨t,ht,rfl⟩ := MeasurableSpace.measurableSet_comap.mp hs + rw [← Measure.map_apply hf ht,← Measure.map_apply hf ht,heq] + +lemma measureLaw_eval_comap {S : Type*} [MeasurableSpace S] : + (inferInstance : MeasurableSpace (Measure S)) = MeasurableSpace.comap + (fun η : Measure S => fun s : {s : Set S // MeasurableSet s} => η s.val) + inferInstance := by + apply le_antisymm + · change (⨆ (s : Set S) (hs : MeasurableSet s), + MeasurableSpace.comap (fun η : Measure S => η s) (borel ℝ≥0∞)) ≤ _ + apply iSup₂_le + intro s hs + exact MeasurableSpace.comap_le_comap_pi (g := fun t : {s : Set S // MeasurableSet s} => + fun η : Measure S => η t.val) ⟨s,hs⟩ + · apply Measurable.comap_le + apply Measurable.of_eval + intro s + exact Measure.measurable_coe s.property + +lemma laplaceTest_eval_eq {S ι : Type*} [MeasurableSpace S] [Fintype ι] + (s : ι → Set S) (hs : ∀ i, MeasurableSet (s i)) (a : ι → ℝ≥0) (η : Measure S) : + laplaceTest a (fun i => η (s i)) = + poissonLaplace (fun x => ∑ i, (s i).indicator (fun _ => (a i : ℝ)) x) η := by + classical + have h0 (i : ι) (x : S) : 0 ≤ (s i).indicator (fun _ => (a i : ℝ)) x := + Set.indicator_nonneg (fun _ _ => (a i).coe_nonneg) x + have he (x : S) : ENNReal.ofReal (∑ i, (s i).indicator (fun _ => (a i : ℝ)) x) = + ∑ i, (s i).indicator (fun _ => (a i : ℝ≥0∞)) x := by + rw [ENNReal.ofReal_sum_of_nonneg (fun i _ => h0 i x)] + apply Finset.sum_congr rfl + intro i _ + by_cases hx : x ∈ s i <;> simp [hx] + change expNegENNReal (∑ i, (a i : ℝ≥0∞) * η (s i)) = _ + simp only [poissonLaplace,he] + rw [lintegral_finsetSum _ (fun i _ => measurable_const.indicator (hs i))] + simp_rw [lintegral_indicator (hs _),setLIntegral_const] + +lemma measureLaw_eq_of_laplace {S : Type*} [MeasurableSpace S] + (P Q : Measure (Measure S)) [IsFiniteMeasure P] [IsFiniteMeasure Q] + (heq : ∀ f : S → ℝ, Measurable f → (∀ x, 0 ≤ f x) → + ∫ η, poissonLaplace f η ∂P = ∫ η, poissonLaplace f η ∂Q) : P = Q := by + classical + let J := {s : Set S // MeasurableSet s} + let E (η : Measure S) (s : J) : ℝ≥0∞ := η s.val + have hE : Measurable E := Measurable.of_eval fun event => Measure.measurable_coe event.property + apply measure_eq_of_map_eq_comap E measureLaw_eval_comap + apply IsProjectiveLimit.unique (P := fun I : Finset J => (Q.map E).map I.restrict) + (hν := fun _ => rfl) + intro I + have hI : Measurable (I.restrict (π := fun _ => ℝ≥0∞)) := + Measurable.of_eval fun index => measurable_pi_apply index.val + change (P.map E).map I.restrict = (Q.map E).map I.restrict + rw [Measure.map_map hI hE,Measure.map_map hI hE] + apply measure_eq_of_laplace_tests + intro a + have hm : Measurable (I.restrict ∘ E) := hI.comp hE + rw [integral_map hm.aemeasurable (laplaceTest a).continuous.measurable.aestronglyMeasurable, + integral_map hm.aemeasurable (laplaceTest a).continuous.measurable.aestronglyMeasurable] + have hid (η : Measure S) : laplaceTest a ((I.restrict ∘ E) η) = + poissonLaplace (fun x => ∑ i : I, i.val.val.indicator (fun _ => (a i : ℝ)) x) η := + laplaceTest_eval_eq (fun i : I => i.val.val) (fun i => i.val.property) a η + simp_rw [hid] + apply heq + · exact Finset.measurable_sum _ fun i _ => measurable_const.indicator i.val.property + · intro x + exact Finset.sum_nonneg fun i _ => Set.indicator_nonneg (fun _ _ => (a i).coe_nonneg) x + +def countablePoissonIntensity {S : Type*} [MeasurableSpace S] + (r : ℕ → ℝ≥0) (ν : ℕ → Measure S) : Measure S := + Measure.sum fun i => (r i : ℝ≥0∞) • ν i + +lemma countablePoissonLaw_laplace_intensity {S : Type*} [MeasurableSpace S] + (r : ℕ → ℝ≥0) (ν : ℕ → Measure S) [∀ i, IsProbabilityMeasure (ν i)] + {f : S → ℝ} (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) : + ∫ η, poissonLaplace f η ∂countablePoissonLaw r ν = + expNegENNReal (∫⁻ x, ENNReal.ofReal (1 - Real.exp (-f x)) ∂countablePoissonIntensity r ν) := by + rw [countablePoissonLaw_laplace r ν hf hf0] + congr 1 + rw [countablePoissonIntensity,lintegral_sum_measure] + apply tsum_congr + intro i + rw [lintegral_smul_measure,ENNReal.ofReal_mul (r i).coe_nonneg,ENNReal.ofReal_coe_nnreal] + congr 1 + apply ofReal_integral_eq_lintegral_ofReal + · apply Integrable.of_bound (measurable_const.sub hf.neg.exp).aestronglyMeasurable 1 + exact ae_of_all _ fun x => by + have h0 := Real.exp_pos (-f x) + have h1 := Real.exp_le_one_iff.mpr (neg_nonpos.mpr (hf0 x)) + change |1 - Real.exp (-f x)| ≤ 1 + rw [abs_of_nonneg (sub_nonneg.mpr h1)] + linarith + · exact ae_of_all _ fun x => sub_nonneg.mpr + (Real.exp_le_one_iff.mpr (neg_nonpos.mpr (hf0 x))) + +def finiteIntensityMarks {S : Type*} [MeasurableSpace S] [Nonempty S] (κ : Measure S) : Measure S := + if κ univ = 0 then Measure.dirac (Classical.choice ‹Nonempty S›) else (κ univ)⁻¹ • κ + +instance finiteIntensityMarks_probability {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [IsFiniteMeasure κ] : IsProbabilityMeasure (finiteIntensityMarks κ) := by + by_cases hκ : κ univ = 0 + · simp only [finiteIntensityMarks,ite_eq_left hκ] + infer_instance + · constructor + simp [finiteIntensityMarks,hκ,ENNReal.inv_mul_cancel hκ (measure_ne_top _ _)] + +lemma finiteIntensityMarks_smul {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [IsFiniteMeasure κ] : + ((κ univ).toNNReal : ℝ≥0∞) • finiteIntensityMarks κ = κ := by + rw [ENNReal.coe_toNNReal (measure_ne_top _ _)] + by_cases hκ : κ univ = 0 + · have he : κ = 0 := Measure.measure_univ_eq_zero.mp hκ + simp [he] + · rw [finiteIntensityMarks,ite_eq_right hκ,smul_smul,ENNReal.mul_inv_cancel hκ (measure_ne_top _ _),one_smul] + +def poissonRandomMeasureLaw {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] : Measure (Measure S) := + countablePoissonLaw (fun i => ((sfiniteSeq κ i) univ).toNNReal) + (fun i => finiteIntensityMarks (sfiniteSeq κ i)) + +instance poissonRandomMeasureLaw_probability {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] : IsProbabilityMeasure (poissonRandomMeasureLaw κ) := by + unfold poissonRandomMeasureLaw + infer_instance + +lemma poissonRandomMeasureLaw_laplace {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {f : S → ℝ} (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) : + ∫ η, poissonLaplace f η ∂poissonRandomMeasureLaw κ = + expNegENNReal (∫⁻ x, ENNReal.ofReal (1 - Real.exp (-f x)) ∂κ) := by + rw [poissonRandomMeasureLaw,countablePoissonLaw_laplace_intensity _ _ hf hf0] + congr 2 + simp only [countablePoissonIntensity,finiteIntensityMarks_smul,sum_sfiniteSeq] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/PoissonWeightedTotal.lean b/lean/OAI/Probability/Perceptron/Cascade/PoissonWeightedTotal.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e6eab3018a0317e3301b3646e375827b88bc920 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/PoissonWeightedTotal.lean @@ -0,0 +1,279 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.StablePoissonTotalLogMemLpTwo + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +@[fun_prop] lemma measurable_measure_restrict {S : Type*} [MeasurableSpace S] + {E : Set S} (hE : MeasurableSet E) : Measurable (fun η : Measure S => η.restrict E) := by + apply Measure.measurable_of_measurable_coe + intro t ht + simp only [Measure.restrict_apply ht] + exact Measure.measurable_coe (ht.inter hE) + +lemma poissonRandomMeasureLaw_mecke_finite {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [IsFiniteMeasure κ] + {H : Measure S × S → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ η, ∫⁻ x, H (η,x) ∂η ∂poissonRandomMeasureLaw κ) = + ∫⁻ x, ∫⁻ η, H (Measure.dirac x + η,x) ∂poissonRandomMeasureLaw κ ∂κ := by + rw [poissonRandomMeasureLaw_of_finite κ,finitePoissonLaw_mecke _ _ hH] + calc + _ = ∫⁻ x, ∫⁻ η, H (Measure.dirac x+η,x) + ∂finitePoissonLaw (κ univ).toNNReal (finiteIntensityMarks κ) + ∂((κ univ).toNNReal : ℝ≥0∞) • finiteIntensityMarks κ := by + rw [lintegral_smul_measure]; rfl + _ = _ := by rw [finiteIntensityMarks_smul κ] + +lemma poissonRandomMeasureLaw_mecke_restrict {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {E : Set S} (hE : MeasurableSet E) (hκ : κ E < ⊤) + {H : Measure S × S → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ η, ∫⁻ x in E, H (η,x) ∂η ∂poissonRandomMeasureLaw κ) = + ∫⁻ x in E, ∫⁻ η, H (Measure.dirac x + η,x) ∂poissonRandomMeasureLaw κ ∂κ := by + let ν := κ.restrict E + let ζ := κ.restrict Eᶜ + let P := poissonRandomMeasureLaw ν + let Q := poissonRandomMeasureLaw ζ + have : IsFiniteMeasure ν := ⟨by simpa [ν] using hκ⟩ + have hsum : ν+ζ = κ := Measure.restrict_add_restrict_compl hE + have hadd : Measurable (fun p : Measure S × Measure S => p.1+p.2) := by fun_prop + have hPQ : (P.prod Q).map (fun p => p.1+p.2) = poissonRandomMeasureLaw κ := by + dsimp [P,Q] + rw [poissonRandomMeasureLaw_superposition] + simp only [hsum] + have hm : AEMeasurable (fun η : Measure S => ∫⁻ x in E, H (η,x) ∂η) + (poissonRandomMeasureLaw κ) := + aemeasurable_randomMeasure_lintegral_of_finite (measurable_measure_restrict hE) + (poissonRandomMeasureLaw_ae_restrict_finite κ hE hκ) hH + have hPnull : ∀ᵐ η ∂P, η Eᶜ = 0 := by + apply poissonRandomMeasureLaw_ae_null ν hE.compl + simp [ν,Measure.restrict_apply,hE.compl] + have hQnull : ∀ᵐ η ∂Q, η E = 0 := by + apply poissonRandomMeasureLaw_ae_null ζ hE + simp [ζ,Measure.restrict_apply,hE] + have hPQnull : ∀ᵐ p : Measure S × Measure S ∂P.prod Q, + p.1 Eᶜ = 0 ∧ p.2 E = 0 := by + apply (Measure.ae_prod_iff_ae_ae + ((measurableSet_eq_fun ((Measure.measurable_coe hE.compl).comp measurable_fst) measurable_const).inter + (measurableSet_eq_fun ((Measure.measurable_coe hE).comp measurable_snd) measurable_const))).mpr + filter_upwards [hPnull] with η hη + filter_upwards [hQnull] with ξ hξ + exact ⟨hη,hξ⟩ + have hrestrict (η ξ : Measure S) (hη : η Eᶜ = 0) (hξ : ξ E = 0) : + (η+ξ).restrict E = η := by + rw [Measure.restrict_add,Measure.restrict_eq_zero.mpr hξ,add_zero] + have hh := Measure.restrict_add_restrict_compl (μ := η) hE + rwa [Measure.restrict_eq_zero.mpr hη,add_zero] at hh + have haefin : ∀ᵐ p : Measure S × Measure S ∂P.prod Q, p.1 univ < ⊤ := by + apply (Measure.ae_prod_iff_ae_ae + (measurableSet_lt ((Measure.measurable_coe MeasurableSet.univ).comp measurable_fst) measurable_const)).mpr + filter_upwards [poissonRandomMeasureLaw_ae_restrict_finite ν MeasurableSet.univ + (measure_lt_top ν univ)] with η hη + exact ae_of_all _ fun _ => by simpa using hη + have hmeas : AEMeasurable (fun p : Measure S × Measure S => + ∫⁻ x, H (p.1+p.2,x) ∂p.1) (P.prod Q) := + aemeasurable_randomMeasure_lintegral_of_finite measurable_fst haefin + (hH.comp (by fun_prop : Measurable (fun p : (Measure S × Measure S) × S => (p.1.1+p.1.2,p.2)))) + calc + _ = ∫⁻ p : Measure S × Measure S, ∫⁻ x in E, H (p.1+p.2,x) ∂(p.1+p.2) ∂P.prod Q := by + rw [← hPQ] at hm ⊢ + exact lintegral_map' hm hadd.aemeasurable + _ = ∫⁻ p : Measure S × Measure S, ∫⁻ x, H (p.1+p.2,x) ∂p.1 ∂P.prod Q := by + apply lintegral_congr_ae + filter_upwards [hPQnull] with p hp + rw [hrestrict p.1 p.2 hp.1 hp.2] + _ = ∫⁻ ξ, ∫⁻ η, ∫⁻ x, H (η+ξ,x) ∂η ∂P ∂Q := lintegral_prod_symm _ hmeas + _ = ∫⁻ ξ, ∫⁻ x, ∫⁻ η, H (Measure.dirac x+η+ξ,x) ∂P ∂ν ∂Q := by + apply lintegral_congr + intro ξ + exact poissonRandomMeasureLaw_mecke_finite ν (hH.comp + (by fun_prop : Measurable (fun p : Measure S × S => (p.1+ξ,p.2)))) + _ = ∫⁻ x, ∫⁻ ξ, ∫⁻ η, H (Measure.dirac x+η+ξ,x) ∂P ∂Q ∂ν := by + apply lintegral_lintegral_swap + exact (hH.comp (by fun_prop : Measurable (fun p : (Measure S × S) × Measure S => + (Measure.dirac p.1.2+p.2+p.1.1,p.1.2)))).lintegral_prod_right'.aemeasurable + _ = _ := by + apply lintegral_congr + intro x + rw [← lintegral_prod_symm (μ := P) (ν := Q) + (fun p : Measure S × Measure S => H (Measure.dirac x+p.1+p.2,x)) (hH.comp (by fun_prop : Measurable + (fun p : Measure S × Measure S => (Measure.dirac x+p.1+p.2,x)))).aemeasurable] + rw [← hPQ,lintegral_map (f := fun η : Measure S => H (Measure.dirac x+η,x)) (hH.comp (by fun_prop : Measurable + (fun η : Measure S => (Measure.dirac x+η,x)))) hadd] + apply lintegral_congr + intro p + rw [add_assoc] + +lemma poissonRandomMeasureLaw_mecke {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SigmaFinite κ] {H : Measure S × S → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ η, ∫⁻ x, H (η,x) ∂η ∂poissonRandomMeasureLaw κ) = + ∫⁻ x, ∫⁻ η, H (Measure.dirac x + η,x) ∂poissonRandomMeasureLaw κ ∂κ := by + have hset (η : Measure S) : (∫⁻ x, H (η,x) ∂η) = + ⨆ n : ℕ, ∫⁻ x in spanningSets κ n, H (η,x) ∂η := by + rw [← setLIntegral_iUnion_of_directed _ (monotone_spanningSets κ).directed_le, + iUnion_spanningSets,Measure.restrict_univ] + simp_rw [hset] + rw [lintegral_iSup'] + · simp_rw [poissonRandomMeasureLaw_mecke_restrict κ (measurableSet_spanningSets κ _) + (measure_spanningSets_lt_top κ _) hH] + rw [← setLIntegral_iUnion_of_directed _ (monotone_spanningSets κ).directed_le, + iUnion_spanningSets,Measure.restrict_univ] + · intro n + exact aemeasurable_randomMeasure_lintegral_of_finite (measurable_measure_restrict (measurableSet_spanningSets κ n)) + (poissonRandomMeasureLaw_ae_restrict_finite κ (measurableSet_spanningSets κ n) + (measure_spanningSets_lt_top κ n)) hH + · exact ae_of_all _ fun η n m hnm => lintegral_mono_set (monotone_spanningSets κ hnm) + +def poissonWeightedTotal {S : Type*} [MeasurableSpace S] (F : S → ℝ) + (η : Measure (ℝ × S)) : ℝ := + (∫⁻ p, ENNReal.ofReal (Real.exp (p.1+F p.2)) ∂η).toReal + +lemma poissonWeightedTotal_measurable {S : Type*} [MeasurableSpace S] + {F : S → ℝ} (hF : Measurable F) : Measurable (poissonWeightedTotal F) := + (Measure.measurable_lintegral ((measurable_fst.add (hF.comp measurable_snd)).exp.ennreal_ofReal)).ennreal_toReal + +lemma poissonWeightedTotal_eq {S : Type*} [MeasurableSpace S] + {F : S → ℝ} (hF : Measurable F) (η : Measure (ℝ × S)) : + poissonWeightedTotal F η = stablePoissonTotal (η.map (fun p => p.1+F p.2)) := by + unfold poissonWeightedTotal stablePoissonTotal + rw [lintegral_map (by fun_prop) (by fun_prop)] + +lemma poissonWeightedTotal_add_const {S : Type*} [MeasurableSpace S] + {F : S → ℝ} (_hF : Measurable F) (c : ℝ) (η : Measure (ℝ × S)) : + poissonWeightedTotal (fun x => F x+c) η = Real.exp c * poissonWeightedTotal F η := by + unfold poissonWeightedTotal + simp_rw [show ∀ p : ℝ × S, p.1+(F p.2+c) = c+(p.1+F p.2) by intro p; ring, + Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos c).le] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top,ENNReal.toReal_mul, + ENNReal.toReal_ofReal (Real.exp_pos c).le] + +lemma normalized_mark_density_probability {S : Type*} [MeasurableSpace S] + (ν : Measure S) {b : ℝ} {F : S → ℝ} + (hI : Integrable (fun x => Real.exp (b*F x)) ν) + (hM : (∫ x, Real.exp (b*F x) ∂ν) = 1) : + IsProbabilityMeasure (ν.withDensity (fun x => ENNReal.ofReal (Real.exp (b*F x)))) := by + constructor + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal hI (ae_of_all _ fun x => (Real.exp_pos _).le),hM] + simp + +lemma stablePoisson_normalized_mark_projection {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb : 0 ≤ b) + {F : S → ℝ} (hF : Measurable F) + (hI : Integrable (fun x => Real.exp (b*F x)) ν) + (hM : (∫ x, Real.exp (b*F x) ∂ν) = 1) : + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).map + (Measure.map (fun p : ℝ × S => p.1+F p.2)) = + poissonRandomMeasureLaw (stableLogIntensity b) := by + have : IsProbabilityMeasure (ν.withDensity (fun x => ENNReal.ofReal (Real.exp (b*F x)))) := + normalized_mark_density_probability ν hI hM + have hm : Measurable (fun p : ℝ × S => p.1+F p.2) := measurable_fst.add (hF.comp measurable_snd) + have he : (((stableLogIntensity b).prod ν).map (fun p : ℝ × S => p.1+F p.2)) = + stableLogIntensity b := by + change Measure.map (Prod.fst ∘ logMarkShift F) ((stableLogIntensity b).prod ν) = _ + rw [← Measure.map_map measurable_fst (logMarkShift_measurable hF),stableLogIntensity_mark_shift ν hb hF, + Measure.map_fst_prod,measure_univ,one_smul] + rw [poissonRandomMeasureLaw_map _ hm] + simp only [he] + +lemma poissonWeightedTotal_normalized_log_memLp {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) + {F : S → ℝ} (hF : Measurable F) + (hI : Integrable (fun x => Real.exp (b*F x)) ν) + (hM : (∫ x, Real.exp (b*F x) ∂ν) = 1) : + MemLp (fun η => Real.log (poissonWeightedTotal F η)) 2 + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) := by + have hpres : MeasurePreserving (Measure.map (fun p : ℝ × S => p.1+F p.2)) + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) + (poissonRandomMeasureLaw (stableLogIntensity b)) := + ⟨Measure.measurable_map _ (measurable_fst.add (hF.comp measurable_snd)), + stablePoisson_normalized_mark_projection ν hb0.le hF hI hM⟩ + simpa only [Function.comp_def,poissonWeightedTotal_eq hF] using + (stablePoissonTotal_log_memLp_two hb0 hb1).comp_measurePreserving hpres + +lemma poissonWeightedTotal_normalized_pos {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) + {F : S → ℝ} (hF : Measurable F) + (hI : Integrable (fun x => Real.exp (b*F x)) ν) + (hM : (∫ x, Real.exp (b*F x) ∂ν) = 1) : + ∀ᵐ η ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν), 0 < poissonWeightedTotal F η := by + have he := stablePoisson_normalized_mark_projection ν hb0.le hF hI hM + have hh := stablePoissonTotal_pos hb0 hb1 + rw [← he] at hh + have hh' := (ae_map_iff (Measure.measurable_map _ + (measurable_fst.add (hF.comp measurable_snd))).aemeasurable + (measurableSet_lt measurable_const stablePoissonTotal_measurable)).mp hh + simpa only [poissonWeightedTotal_eq hF, Pi.add_def, Function.comp_def] using hh' + +lemma poissonWeightedTotal_normalized_log_mean {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb : 0 ≤ b) + {F : S → ℝ} (hF : Measurable F) + (hI : Integrable (fun x => Real.exp (b*F x)) ν) + (hM : (∫ x, Real.exp (b*F x) ∂ν) = 1) : + (∫ η, Real.log (poissonWeightedTotal F η) + ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) = + ∫ η, Real.log (stablePoissonTotal η) ∂poissonRandomMeasureLaw (stableLogIntensity b) := by + rw [← stablePoisson_normalized_mark_projection ν hb hF hI hM] + have h := integral_map (μ := poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) + (Measure.measurable_map _ (measurable_fst.add (hF.comp measurable_snd))).aemeasurable + stablePoissonTotal_measurable.log.aestronglyMeasurable + simp only [Pi.add_def, Function.comp_def] at h + rw [h] + simp only [poissonWeightedTotal_eq hF] + +lemma stablePoisson_log_recursion {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) + {X : S → ℝ} (hX : Measurable X) + (hI : Integrable (fun x => Real.exp (b*X x)) ν) : + (∫ η, Real.log (poissonWeightedTotal X η / poissonWeightedTotal (fun _ => 0) η) + ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) = + Real.log (∫ x, Real.exp (b*X x) ∂ν)/b := by + let c := Real.log (∫ x, Real.exp (b*X x) ∂ν)/b + let F := fun x => X x-c + have hF : Measurable F := hX.sub_const c + have hMpos := integral_exp_pos hI + have hfac (x : S) : Real.exp (b*F x) = Real.exp (-b*c)*Real.exp (b*X x) := by + dsimp [F] + rw [← Real.exp_add] + congr 1 + ring + have hFI : Integrable (fun x => Real.exp (b*F x)) ν := by + simp_rw [hfac] + exact hI.const_mul _ + have hFM : (∫ x, Real.exp (b*F x) ∂ν) = 1 := by + simp_rw [hfac] + rw [integral_const_mul,show -b*c = -Real.log (∫ x, Real.exp (b*X x) ∂ν) by dsimp [c]; field_simp, + Real.exp_neg,Real.exp_log hMpos,inv_mul_cancel₀ hMpos.ne'] + have h0I : Integrable (fun _ : S => Real.exp (b*0)) ν := by simp + have h0M : (∫ _ : S, Real.exp (b*0) ∂ν) = 1 := by simp + have hlogF := poissonWeightedTotal_normalized_log_memLp ν hb0 hb1 hF hFI hFM + have hlog0 := poissonWeightedTotal_normalized_log_memLp ν hb0 hb1 measurable_const h0I h0M + have hEq : (fun η => Real.log (poissonWeightedTotal X η / poissonWeightedTotal (fun _ => 0) η)) =ᵐ[ + poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)] + (fun η => c+Real.log (poissonWeightedTotal F η)-Real.log (poissonWeightedTotal (fun _ => 0) η)) := by + filter_upwards [poissonWeightedTotal_normalized_pos ν hb0 hb1 hF hFI hFM, + poissonWeightedTotal_normalized_pos ν hb0 hb1 measurable_const h0I h0M] with η hηF hη0 + have hs : poissonWeightedTotal X η = Real.exp c*poissonWeightedTotal F η := by + convert poissonWeightedTotal_add_const hF c η using 1 + congr 1 + funext x + dsimp [F] + ring + rw [Real.log_div (by rw [hs]; positivity) hη0.ne',hs, + Real.log_mul (Real.exp_pos _).ne' hηF.ne',Real.log_exp] + have he := integral_sub ((integrable_const c).add (hlogF.integrable (by norm_num))) + (hlog0.integrable (by norm_num)) + have he' := integral_add (integrable_const c) (hlogF.integrable (by norm_num)) + simp only [Pi.add_apply] at he he' + rw [integral_congr_ae hEq,he,he', + poissonWeightedTotal_normalized_log_mean ν hb0.le hF hFI hFM, + poissonWeightedTotal_normalized_log_mean ν hb0.le measurable_const h0I h0M] + simp [c] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/Poissonization.lean b/lean/OAI/Probability/Perceptron/Cascade/Poissonization.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b2343367f25572d9b62af365aa6506f6136c1c6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/Poissonization.lean @@ -0,0 +1,73 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DensityDerivative + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma poisson_abs_count_difference (r : ℝ≥0) (M : ℕ) : + (∫ j : ℕ, |(j:ℝ)-(M:ℝ)| ∂poissonMeasure r) ≤ Real.sqrt r+|(r:ℝ)-(M:ℝ)| := by + have hi := (poisson_nat_memLp r).integrable (by norm_num) + have hc := integral_centered_abs_le_sqrt_variance (poissonMeasure r) (poisson_nat_memLp r) + rw [poisson_nat_mean,poisson_nat_variance] at hc + calc + _ ≤ ∫ j : ℕ, |(j:ℝ)-(r:ℝ)|+|(r:ℝ)-(M:ℝ)| ∂poissonMeasure r := by + apply integral_mono (hi.sub (integrable_const _)).abs + ((hi.sub (integrable_const _)).abs.add (integrable_const _)) + intro j + exact abs_sub_le _ _ _ + _ = (∫ j : ℕ, |(j:ℝ)-(r:ℝ)| ∂poissonMeasure r)+|(r:ℝ)-(M:ℝ)| := by + rw [integral_add (f := fun j : ℕ => |(j:ℝ)-(r:ℝ)|) + (g := fun _ : ℕ => |(r:ℝ)-(M:ℝ)|) (hi.sub (integrable_const _)).abs (integrable_const _)] + simp + _ ≤ _ := add_le_add hc le_rfl + +lemma poisson_bounded_increment_mean_compare (r : ℝ≥0) {F : ℕ→ℝ} {C : ℝ} + (hC : 0≤C) (hF : ∀ m, |F (m+1)-F m|≤C) (M : ℕ) : + |(∫ j, F j ∂poissonMeasure r)-F M|≤C*(Real.sqrt r+|(r:ℝ)-(M:ℝ)|) := by + have hi := (poisson_bounded_increment_memLp r hC hF).integrable (by norm_num) + have hj := (poisson_nat_memLp r).integrable (by norm_num) + calc + _ = |∫ j, F j-F M ∂poissonMeasure r| := by rw [integral_sub hi (integrable_const _)]; simp + _ ≤ ∫ j, |F j-F M| ∂poissonMeasure r := abs_integral_le_integral_abs + _ ≤ ∫ j : ℕ, C*|(j:ℝ)-(M:ℝ)| ∂poissonMeasure r := + integral_mono (hi.sub (integrable_const _)).abs + ((hj.sub (integrable_const _)).abs.const_mul C) + (fun j => nat_bounded_increment_difference hC hF j M) + _ ≤ _ := by rw [integral_const_mul]; exact mul_le_mul_of_nonneg_left (poisson_abs_count_difference r M) hC + +lemma sourceExpectedPressure_fixed_count_compare (n k M : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 (∫ x, A n x*(Z n x).val^k ∂μ n)- + ∫ x, A' n x*(Z' n x).val^k ∂ν n) atTop (𝓝 0)) (f : C(Icc a b,ℝ)) : + Tendsto (fun n => (∫ x, A n x*f (Z n x) ∂μ n)-∫ x, A' n x*f (Z' n x) ∂ν n) atTop (𝓝 0) := by + have hpi (n : ℕ) (p : ℝ[X]) : Integrable (fun x => A n x*p.eval (Z n x).val) (μ n) := + weighted_compact_integrable (μ n) (A n) (hA n) (Z n) (hZ n) C hC (hb n) (p.toContinuousMapOn _) + have hpi' (n : ℕ) (p : ℝ[X]) : Integrable (fun x => A' n x*p.eval (Z' n x).val) (ν n) := + weighted_compact_integrable (ν n) (A' n) (hA' n) (Z' n) (hZ' n) C hC (hb' n) (p.toContinuousMapOn _) + have hp (p : ℝ[X]) : Tendsto (fun n => (∫ x, A n x*p.eval (Z n x).val ∂μ n)- + ∫ x, A' n x*p.eval (Z' n x).val ∂ν n) atTop (𝓝 0) := by + induction p using Polynomial.induction_on' with + | add p q hp hq => + have he n : (∫ x, A n x*(p+q).eval (Z n x).val ∂μ n)- + ∫ x, A' n x*(p+q).eval (Z' n x).val ∂ν n = + ((∫ x, A n x*p.eval (Z n x).val ∂μ n)-∫ x, A' n x*p.eval (Z' n x).val ∂ν n)+ + ((∫ x, A n x*q.eval (Z n x).val ∂μ n)-∫ x, A' n x*q.eval (Z' n x).val ∂ν n) := by + simp_rw [Polynomial.eval_add,mul_add] + rw [integral_add (hpi n p) (hpi n q),integral_add (hpi' n p) (hpi' n q)] + ring + simp_rw [he] + simpa only [add_zero] using hp.add hq + | monomial k c => + simpa only [Polynomial.eval_monomial,mul_left_comm _ c,integral_const_mul,←mul_sub,mul_zero] + using (hm k).const_mul c + rw [Metric.tendsto_atTop] + intro ε hε + let δ := ε/(3*(C+1)) + have hδ : 0<δ := div_pos hε (by positivity) + obtain ⟨p,hpδ⟩ := exists_polynomial_near_continuousMap a b f δ hδ + obtain ⟨N,hN⟩ := Metric.tendsto_atTop.mp (hp p) (ε/3) (by positivity) + refine ⟨N,fun n hn => ?_⟩ + have h₁ := weighted_compact_error (μ n) (A n) (hA n) (Z n) (hZ n) C hC (hb n) (p.toContinuousMapOn _) f + have h₂ := weighted_compact_error (ν n) (A' n) (hA' n) (Z' n) (hZ' n) C hC (hb' n) (p.toContinuousMapOn _) f + have hs : C*‖p.toContinuousMapOn (Icc a b)-f‖<ε/3 := by + calc + _ ≤ C*δ := mul_le_mul_of_nonneg_left hpδ.le hC + _ < (C+1)*δ := mul_lt_mul_of_pos_right (by linarith) hδ + _ = ε/3 := by dsimp [δ]; field_simp + have ht := hN n hn + simp only [Real.dist_eq,sub_zero] at ht ⊢ + simp only [Polynomial.toContinuousMapOn_apply,Polynomial.toContinuousMap_apply] at h₁ h₂ + have ha := abs_sub_le (∫ x, A n x*f (Z n x) ∂μ n) + (∫ x, A n x*p.eval (Z n x).val ∂μ n) (∫ x, A' n x*f (Z' n x) ∂ν n) + have hb₂ := abs_sub_le (∫ x, A n x*p.eval (Z n x).val ∂μ n) + (∫ x, A' n x*p.eval (Z' n x).val ∂ν n) (∫ x, A' n x*f (Z' n x) ∂ν n) + rw [abs_sub_comm] at h₁ + linarith +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/ReweightedMomentLimit.lean b/lean/OAI/Probability/Perceptron/Cascade/ReweightedMomentLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..16988b9ba9f0b97ff8e01c023bf2c404396fc0e3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/ReweightedMomentLimit.lean @@ -0,0 +1,88 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal BigOperators Polynomial +namespace SphericalPerceptronFreeEnergy + +lemma weighted_compact_integrable {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsFiniteMeasure μ] {a b : ℝ} + (A : Ω → ℝ) (hA : Measurable A) (Z : Ω → Icc a b) (hZ : Measurable Z) + (C : ℝ) (hC : 0 ≤ C) (hB : ∀ x, |A x| ≤ C) (f : C(Icc a b,ℝ)) : + Integrable (fun x => A x*f (Z x)) μ := by + apply Integrable.of_bound (hA.mul (f.continuous.measurable.comp hZ)).aestronglyMeasurable (C*‖f‖) + exact ae_of_all _ fun x => by + change |A x*f (Z x)| ≤ C*‖f‖ + rw [abs_mul] + exact mul_le_mul (hB x) (f.norm_coe_le_norm (Z x)) (abs_nonneg _) hC + +lemma weighted_compact_error {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] {a b : ℝ} + (A : Ω → ℝ) (hA : Measurable A) (Z : Ω → Icc a b) (hZ : Measurable Z) + (C : ℝ) (hC : 0 ≤ C) (hB : ∀ x, |A x| ≤ C) (f g : C(Icc a b,ℝ)) : + |(∫ x, A x*f (Z x) ∂μ)-(∫ x, A x*g (Z x) ∂μ)| ≤ C*‖f-g‖ := by + rw [← integral_sub (weighted_compact_integrable μ A hA Z hZ C hC hB f) + (weighted_compact_integrable μ A hA Z hZ C hC hB g)] + have hb : ∀ x, ‖A x*f (Z x)-A x*g (Z x)‖ ≤ C*‖f-g‖ := fun x => by + rw [←mul_sub,Real.norm_eq_abs,abs_mul] + exact mul_le_mul (hB x) ((f-g).norm_coe_le_norm (Z x)) (abs_nonneg _) hC + simpa only [Real.norm_eq_abs,Measure.real,measure_univ,ENNReal.toReal_one,mul_one] using + norm_integral_le_of_norm_le_const (μ := μ) (ae_of_all _ hb) + +lemma bounded_weighted_moment_limit {Ω : ℕ → Type*} {Ω' : Type*} + [∀ n, MeasurableSpace (Ω n)] [MeasurableSpace Ω'] + (μ : (n : ℕ) → Measure (Ω n)) (ν : Measure Ω') + [∀ n, IsProbabilityMeasure (μ n)] [IsProbabilityMeasure ν] {a b : ℝ} + (A : (n : ℕ) → Ω n → ℝ) (A' : Ω' → ℝ) + (Z : (n : ℕ) → Ω n → Icc a b) (Z' : Ω' → Icc a b) + (hA : ∀ n, Measurable (A n)) (hA' : Measurable A') + (hZ : ∀ n, Measurable (Z n)) (hZ' : Measurable Z') + (C : ℝ) (hC : 0 ≤ C) (hB : ∀ n x, |A n x| ≤ C) (hB' : ∀ x, |A' x| ≤ C) + (hm : ∀ k : ℕ, Tendsto (fun n => ∫ x, A n x*(Z n x).val^k ∂μ n) atTop + (𝓝 (∫ x, A' x*(Z' x).val^k ∂ν))) (f : C(Icc a b,ℝ)) : + Tendsto (fun n => ∫ x, A n x*f (Z n x) ∂μ n) atTop + (𝓝 (∫ x, A' x*f (Z' x) ∂ν)) := by + have hpn (n : ℕ) (p : ℝ[X]) : Integrable (fun x => A n x*p.eval (Z n x).val) (μ n) := + weighted_compact_integrable (μ n) (A n) (hA n) (Z n) (hZ n) C hC (hB n) (p.toContinuousMapOn _) + have hpl (p : ℝ[X]) : Integrable (fun x => A' x*p.eval (Z' x).val) ν := + weighted_compact_integrable ν A' hA' Z' hZ' C hC hB' (p.toContinuousMapOn _) + have hp (p : ℝ[X]) : Tendsto (fun n => ∫ x, A n x*p.eval (Z n x).val ∂μ n) atTop + (𝓝 (∫ x, A' x*p.eval (Z' x).val ∂ν)) := by + induction p using Polynomial.induction_on' with + | add p q hp hq => + simpa only [Polynomial.eval_add,mul_add,integral_add (hpn _ p) (hpn _ q), + integral_add (hpl p) (hpl q)] using hp.add hq + | monomial k c => + simpa only [Polynomial.eval_monomial,mul_left_comm _ c,integral_const_mul] + using (hm k).const_mul c + rw [Metric.tendsto_atTop] + intro ε hε + let δ := ε/(3*(C+1)) + have hδ : 0 < δ := div_pos hε (by positivity) + obtain ⟨p,hpδ⟩ := exists_polynomial_near_continuousMap a b f δ hδ + obtain ⟨N,hN⟩ := Metric.tendsto_atTop.mp (hp p) (ε/3) (by positivity) + refine ⟨N,fun n hn => ?_⟩ + have h₁ := weighted_compact_error (μ n) (A n) (hA n) (Z n) (hZ n) C hC (hB n) + (p.toContinuousMapOn _) f + have h₂ := weighted_compact_error ν A' hA' Z' hZ' C hC hB' (p.toContinuousMapOn _) f + have hsmall : C*‖p.toContinuousMapOn (Icc a b)-f‖ < ε/3 := by + calc + _ ≤ C*δ := mul_le_mul_of_nonneg_left hpδ.le hC + _ < ε/3 := by dsimp [δ]; rw [← mul_div_assoc]; apply (div_lt_iff₀ (by positivity)).mpr; nlinarith + have h₃ := hN n hn + rw [Real.dist_eq] at h₃ ⊢ + have ht := abs_sub_le (∫ x, A n x*f (Z n x) ∂μ n) + (∫ x, A n x*p.eval (Z n x).val ∂μ n) (∫ x, A' x*f (Z' x) ∂ν) + have ht' := abs_sub_le (∫ x, A n x*p.eval (Z n x).val ∂μ n) + (∫ x, A' x*p.eval (Z' x).val ∂ν) (∫ x, A' x*f (Z' x) ∂ν) + simp only [Polynomial.toContinuousMapOn_apply,Polynomial.toContinuousMap_apply] at h₁ h₂ + rw [abs_sub_comm] at h₁ + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/StableCascade.lean b/lean/OAI/Probability/Perceptron/Cascade/StableCascade.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f82e5a56089529b3ebceceed72b4eff78882bd3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/StableCascade.lean @@ -0,0 +1,428 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.BoundedC1 + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff + +def StableCascade : ℕ → MeasCat + | 0 => MeasCat.of Unit + | n+1 => MeasCat.of (Measure (ℝ×StableCascade n)) + +instance stableCascadeNonempty (n : ℕ) : Nonempty (StableCascade n) := by + cases n with + | zero => exact ⟨()⟩ + | succ n => exact ⟨(0 : Measure (ℝ×StableCascade n))⟩ + +def cascadeTotalE : (n : ℕ) → StableCascade n → ℝ≥0∞ + | 0, _ => 1 + | n+1, η => ∫⁻ p : ℝ×StableCascade n, + ENNReal.ofReal (Real.exp p.1)*cascadeTotalE n p.2 ∂η + +lemma cascadeTotalE_measurable (n : ℕ) : Measurable (cascadeTotalE n) := by + induction n with + | zero => exact measurable_const + | succ n ih => + exact Measure.measurable_lintegral + ((Real.measurable_exp.comp measurable_fst).ennreal_ofReal.mul (ih.comp measurable_snd)) + +def cascadeTotal (n : ℕ) (η : StableCascade n) : ℝ := (cascadeTotalE n η).toReal + +lemma cascadeTotal_measurable (n : ℕ) : Measurable (cascadeTotal n) := + (cascadeTotalE_measurable n).ennreal_toReal + +def cascadeLaw : (n : ℕ) → (Fin n → ℝ) → ProbabilityMeasure (StableCascade n) + | 0, _ => ⟨Measure.dirac (),by exact Measure.dirac.isProbabilityMeasure⟩ + | n+1, z => ⟨poissonRandomMeasureLaw ((stableLogIntensity (z 0)).prod + (cascadeLaw n (fun i => z i.succ) : Measure (StableCascade n))),by exact poissonRandomMeasureLaw_probability _⟩ + +lemma poissonWeightedTotal_identDistrib {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb : 0 < b) + {X : S → ℝ} (hX : Measurable X) + (hI : Integrable (fun x => Real.exp (b*X x)) ν) : + IdentDistrib (poissonWeightedTotal X) + (fun η => Real.exp (Real.log (∫ x, Real.exp (b*X x) ∂ν)/b)*stablePoissonTotal η) + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) + (poissonRandomMeasureLaw (stableLogIntensity b)) := + ⟨(poissonWeightedTotal_measurable hX).aemeasurable, + (stablePoissonTotal_measurable.const_mul _).aemeasurable, + poissonWeightedTotal_law ν hb hX hI⟩ + +lemma poissonWeightedTotal_pos {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb : 0 < b) (hb1 : b < 1) + {X : S → ℝ} (hX : Measurable X) + (hI : Integrable (fun x => Real.exp (b*X x)) ν) : + ∀ᵐ η ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν), 0 < poissonWeightedTotal X η := by + apply (poissonWeightedTotal_identDistrib ν hb hX hI).symm.ae_snd measurableSet_Ioi + filter_upwards [stablePoissonTotal_pos hb hb1] with η hη + exact mul_pos (Real.exp_pos _) hη + +lemma poissonWeightedTotal_rpow_integrable {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b a : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) + {X : S → ℝ} (hX : Measurable X) + (hI : Integrable (fun x => Real.exp (b*X x)) ν) : + Integrable (fun η => (poissonWeightedTotal X η)^a) + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) := by + have hid := (poissonWeightedTotal_identDistrib ν hb hX hI).comp + (measurable_id.pow_const a : Measurable (fun x : ℝ => x^a)) + apply hid.integrable_iff.mpr + have he (η : Measure ℝ) : (Real.exp (Real.log (∫ x, Real.exp (b*X x) ∂ν)/b)*stablePoissonTotal η)^a = + (Real.exp (Real.log (∫ x, Real.exp (b*X x) ∂ν)/b))^a*(stablePoissonTotal η)^a := + Real.mul_rpow (Real.exp_pos _).le ENNReal.toReal_nonneg + simpa only [Function.comp_def,id_eq,he] using (stablePoissonTotal_rpow_integrable hb hb1 ha).const_mul + ((Real.exp (Real.log (∫ x, Real.exp (b*X x) ∂ν)/b))^a) + +lemma poissonRandomMeasureLaw_ae_ae {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {p : S → Prop} (hp : MeasurableSet {x | p x}) + (h : ∀ᵐ x ∂κ, p x) : ∀ᵐ η ∂poissonRandomMeasureLaw κ, ∀ᵐ x ∂η, p x := by + have hh := poissonRandomMeasureLaw_ae_null κ hp.compl (ae_iff.mp h) + exact hh.mono fun η hη => ae_iff.mpr hη + +lemma cascadeTotal_succ_eq {n : ℕ} (z : Fin (n+1) → ℝ) + (hp : ∀ᵐ η ∂(cascadeLaw n (fun i => z i.succ) : Measure (StableCascade n)), + 0 < cascadeTotal n η) : + ∀ᵐ η ∂(cascadeLaw (n+1) z : Measure (StableCascade (n+1))), + cascadeTotal (n+1) η = poissonWeightedTotal (fun C => Real.log (cascadeTotal n C)) η := by + let ν : Measure (StableCascade n) := cascadeLaw n (fun i => z i.succ) + have hpκ : ∀ᵐ p ∂(stableLogIntensity (z 0)).prod ν, 0 < cascadeTotal n p.2 := + (Measure.ae_prod_iff_ae_ae (measurableSet_lt measurable_const ((cascadeTotal_measurable n).comp measurable_snd))).mpr + (ae_of_all _ fun _ => hp) + have he := poissonRandomMeasureLaw_ae_ae ((stableLogIntensity (z 0)).prod ν) + (measurableSet_lt measurable_const ((cascadeTotal_measurable n).comp measurable_snd)) hpκ + change ∀ᵐ η ∂poissonRandomMeasureLaw ((stableLogIntensity (z 0)).prod ν), _ + filter_upwards [he] with η hη + unfold cascadeTotal poissonWeightedTotal + congr 1 + apply lintegral_congr_ae + filter_upwards [hη] with p hp + change ENNReal.ofReal (Real.exp p.1)*cascadeTotalE n p.2 = + ENNReal.ofReal (Real.exp (p.1+Real.log (cascadeTotal n p.2))) + change 0 < cascadeTotal n p.2 at hp + rw [Real.exp_add,Real.exp_log hp,ENNReal.ofReal_mul (Real.exp_pos _).le,cascadeTotal, + ENNReal.ofReal_toReal (ENNReal.toReal_pos_iff.mp hp).2.ne] + +theorem cascadeTotal_regular (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) : + (∀ᵐ η ∂(cascadeLaw n z : Measure (StableCascade n)), 0 < cascadeTotal n η) ∧ + ∀ a : ℝ, (∀ i, a < z i) → Integrable (fun η => (cascadeTotal n η)^a) + (cascadeLaw n z : Measure (StableCascade n)) := by + induction n with + | zero => + constructor + · exact ae_of_all _ fun _ => by simp [cascadeTotal,cascadeTotalE] + · intro a _; simpa only [cascadeTotal,cascadeTotalE,ENNReal.toReal_one,Real.one_rpow] using + (integrable_const (1:ℝ) : Integrable (fun _ : StableCascade 0 => (1:ℝ)) (cascadeLaw 0 z : Measure (StableCascade 0))) + | succ n ih => + let ν : Measure (StableCascade n) := cascadeLaw n (fun i => z i.succ) + have htail : StrictMono (fun i : Fin n => z i.succ) := fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij) + obtain ⟨hpos,hint⟩ := ih (fun i => z i.succ) htail (fun i => hz0 i.succ) (fun i => hz1 i.succ) + have hM : Integrable (fun C => Real.exp (z 0*Real.log (cascadeTotal n C))) ν := by + have hh := hint (z 0) (fun i => hz (by simp)) + apply hh.congr + filter_upwards [hpos] with C hC + rw [Real.rpow_def_of_pos hC] + congr 1 + ring + have hEq := cascadeTotal_succ_eq z hpos + have hlog : Measurable (fun C : StableCascade n => Real.log (cascadeTotal n C)) := + (cascadeTotal_measurable n).log + constructor + · have hp := poissonWeightedTotal_pos ν (hz0 0) (hz1 0) hlog hM + filter_upwards [hp,hEq] with η hp he + rwa [he] + · intro a ha + have hI := poissonWeightedTotal_rpow_integrable ν (hz0 0) (hz1 0) (ha 0) hlog hM + exact hI.congr (hEq.mono fun η he => congrArg (fun t : ℝ => t^a) he.symm) + +lemma lintegral_comp_exp_all (g : ℝ → ℝ≥0∞) : + (∫⁻ x : ℝ, ENNReal.ofReal (Real.exp x)*g (Real.exp x)) = ∫⁻ y : ℝ in Ioi 0, g y := by + have h := lintegral_image_eq_lintegral_abs_deriv_mul MeasurableSet.univ + (fun x (_ : x ∈ (univ : Set ℝ)) => (Real.hasDerivAt_exp x).hasDerivWithinAt) + (fun x _ y _ hxy => Real.exp_injective hxy) g + simpa only [image_univ,Real.range_exp,Measure.restrict_univ,abs_of_pos (Real.exp_pos _)] using h.symm + +lemma stableLogIntensity_laplace_moment {b r t : ℝ} (hb : 0 ≤ b) (hr : b < r) (ht : 0 < t) : + (∫⁻ x : ℝ, ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*Real.exp x)) ∂stableLogIntensity b) = + ENNReal.ofReal (b*t^(b-r)*Real.Gamma (r-b)) := by + unfold stableLogIntensity + rw [lintegral_withDensity_eq_lintegral_mul₀ (by fun_prop) (by fun_prop)] + have he (x : ℝ) : + ENNReal.ofReal (b*Real.exp (-b*x))*ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*Real.exp x)) = + ENNReal.ofReal b*(ENNReal.ofReal (Real.exp x)* + ENNReal.ofReal ((Real.exp x)^(r-b-1)*Real.exp (-t*Real.exp x))) := by + rw [← ENNReal.ofReal_mul (mul_nonneg hb (Real.exp_pos _).le), + ← ENNReal.ofReal_mul (Real.exp_pos _).le,← ENNReal.ofReal_mul hb] + congr 1 + rw [← Real.exp_mul] + have hx : Real.exp (-b*x)*Real.exp (r*x) = Real.exp x*Real.exp (x*(r-b-1)) := by + rw [← Real.exp_add,← Real.exp_add] + congr 1 + ring + calc + b*Real.exp (-b*x)*(Real.exp (r*x)*Real.exp (-t*Real.exp x)) = + b*(Real.exp (-b*x)*Real.exp (r*x))*Real.exp (-t*Real.exp x) := by ring + _ = _ := by rw [hx]; ring + change (∫⁻ x : ℝ, ENNReal.ofReal (b*Real.exp (-b*x))*ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*Real.exp x))) = _ + simp_rw [he] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + lintegral_comp_exp_all (fun y : ℝ => ENNReal.ofReal (y^(r-b-1)*Real.exp (-t*y))), + show (∫⁻ y : ℝ in Ioi 0, ENNReal.ofReal (y^(r-b-1)*Real.exp (-t*y))) = + ENNReal.ofReal (t^(-(r-b))*Real.Gamma (r-b)) from by + simpa only [neg_mul,mul_comm t] using gamma_lintegral_positive_scale (sub_pos.mpr hr) ht, + ← ENNReal.ofReal_mul hb] + congr 1 + rw [neg_sub] + ring + +lemma one_sub_exp_neg_lintegral {u : ℝ} (hu : 0 < u) : + ENNReal.ofReal (1-Real.exp (-u)) = + ∫⁻ t : ℝ in Ioc 0 1, ENNReal.ofReal (u*Real.exp (-t*u)) := by + have hi : IntegrableOn (fun t : ℝ => u*Real.exp (-t*u)) (Ioc 0 1) := + (show Continuous (fun t : ℝ => u*Real.exp (-t*u)) by fun_prop).integrableOn_Icc.mono_set Ioc_subset_Icc_self + rw [← ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ fun _ => mul_nonneg hu.le (Real.exp_pos _).le)] + congr 1 + rw [← intervalIntegral.integral_of_le (by norm_num : (0:ℝ) ≤ 1)] + have hd (t : ℝ) : HasDerivAt (fun s : ℝ => -Real.exp (-s*u)) (u*Real.exp (-t*u)) t := by + convert! (((hasDerivAt_id t).neg.mul_const u).exp).neg using 1 + simp only [Pi.neg_apply,id_eq,one_mul,neg_mul,mul_neg,neg_neg] + ring + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt (fun t _ => hd t) + ((show Continuous (fun t : ℝ => u*Real.exp (-t*u)) by fun_prop).intervalIntegrable 0 1)] + simp only [neg_mul,zero_mul,neg_zero,Real.exp_zero] + ring_nf + +lemma lintegral_rpow_unit {b : ℝ} (hb : 0 < b) : + (∫⁻ t : ℝ in Ioc 0 1, ENNReal.ofReal (t^(b-1))) = ENNReal.ofReal b⁻¹ := by + have hi : IntegrableOn (fun t : ℝ => t^(b-1)) (Ioc 0 1) := + (intervalIntegral.intervalIntegrable_rpow' (a := 0) (b := 1) (by linarith : -1 < b-1)).1 + rw [← ofReal_integral_eq_lintegral_ofReal hi (by + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht + exact Real.rpow_nonneg ht.1.le _),← intervalIntegral.integral_of_le (by norm_num : (0:ℝ) ≤ 1), + integral_rpow (Or.inl (by linarith : -1 < b-1))] + simp [Real.zero_rpow hb.ne'] + +lemma stableLaplaceConstant_eq_gamma {b : ℝ} (hb : 0 < b) (hb1 : b < 1) : + stableLaplaceConstant b = ENNReal.ofReal (Real.Gamma (1-b)) := by + unfold stableLaplaceConstant + simp_rw [one_sub_exp_neg_lintegral (Real.exp_pos _)] + rw [lintegral_lintegral_swap (by fun_prop : Measurable (fun p : ℝ×ℝ => + ENNReal.ofReal (Real.exp p.1*Real.exp (-p.2*Real.exp p.1)))).aemeasurable] + have he : (∫⁻ t : ℝ in Ioc 0 1, ∫⁻ x : ℝ, + ENNReal.ofReal (Real.exp x*Real.exp (-t*Real.exp x)) ∂stableLogIntensity b) = + ∫⁻ t : ℝ in Ioc 0 1, ENNReal.ofReal (b*t^(b-1)*Real.Gamma (1-b)) := by + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioc] with t ht + simpa only [one_mul] using stableLogIntensity_laplace_moment hb.le hb1 ht.1 + rw [he] + have hG : 0 ≤ Real.Gamma (1-b) := (Real.Gamma_pos_of_pos (by linarith)).le + have hf (t : ℝ) : ENNReal.ofReal (b*t^(b-1)*Real.Gamma (1-b)) = + ENNReal.ofReal (b*Real.Gamma (1-b))*ENNReal.ofReal (t^(b-1)) := by + rw [← ENNReal.ofReal_mul (mul_nonneg hb.le hG)] + congr 1 + ring + simp_rw [hf] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top,lintegral_rpow_unit hb, + ← ENNReal.ofReal_mul (mul_nonneg hb.le hG)] + congr 1 + field_simp + +attribute [fun_prop] stablePoissonTotal_measurable + +lemma stablePoissonTotal_add_dirac (x : ℝ) (η : Measure ℝ) + (hη : (∫⁻ y, ENNReal.ofReal (Real.exp y) ∂η) ≠ ⊤) : + stablePoissonTotal (Measure.dirac x+η) = Real.exp x+stablePoissonTotal η := by + unfold stablePoissonTotal + rw [lintegral_add_measure,lintegral_dirac, + ENNReal.toReal_add ENNReal.ofReal_ne_top hη,ENNReal.toReal_ofReal (Real.exp_pos _).le] + +lemma stablePoissonTotal_laplace_lintegral {b t : ℝ} + (hb : 0 < b) (hb1 : b < 1) (ht : 0 < t) : + (∫⁻ η, ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η)) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + ENNReal.ofReal (Real.exp (-Real.Gamma (1-b)*t^b)) := by + have hi : Integrable (fun η => Real.exp (-t*stablePoissonTotal η)) + (poissonRandomMeasureLaw (stableLogIntensity b)) := by + apply Integrable.of_bound (by fun_prop) 1 + exact ae_of_all _ fun η => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr ht.le) + ENNReal.toReal_nonneg) + rw [← ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ fun _ => (Real.exp_pos _).le), + stablePoissonTotal_laplace hb hb1 ht,stableLaplaceConstant_eq_gamma hb hb1, + ENNReal.toReal_ofReal (Real.Gamma_pos_of_pos (by linarith)).le] + +lemma stablePoisson_palm_laplace {b r t : ℝ} (hb : 0 < b) (hb1 : b < 1) + (hr : b < r) (ht : 0 < t) : + (∫⁻ η, ∫⁻ x : ℝ, ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*stablePoissonTotal η)) + ∂η ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + ENNReal.ofReal (b*t^(b-r)*Real.Gamma (r-b)*Real.exp (-Real.Gamma (1-b)*t^b)) := by + rw [poissonRandomMeasureLaw_mecke (stableLogIntensity b) (by fun_prop : Measurable + (fun p : Measure ℝ×ℝ => ENNReal.ofReal (Real.exp (r*p.2)*Real.exp (-t*stablePoissonTotal p.1))))] + have he (x : ℝ) : + (∫⁻ η, ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*stablePoissonTotal (Measure.dirac x+η))) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*Real.exp x))* + ENNReal.ofReal (Real.exp (-Real.Gamma (1-b)*t^b)) := by + calc + _ = ∫⁻ η, ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*Real.exp x))* + ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η)) + ∂poissonRandomMeasureLaw (stableLogIntensity b) := by + apply lintegral_congr_ae + filter_upwards [stablePoisson_total_finite hb hb1] with η hη + rw [stablePoissonTotal_add_dirac x η hη,mul_add,Real.exp_add, + ← ENNReal.ofReal_mul (mul_nonneg (Real.exp_pos _).le (Real.exp_pos _).le)] + congr 1 + ring + _ = _ := by + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top,stablePoissonTotal_laplace_lintegral hb hb1 ht] + change (∫⁻ x, ∫⁻ η, ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*stablePoissonTotal (Measure.dirac x+η))) + ∂poissonRandomMeasureLaw (stableLogIntensity b) ∂stableLogIntensity b) = _ + simp_rw [he] + rw [lintegral_mul_const' _ _ ENNReal.ofReal_ne_top,stableLogIntensity_laplace_moment hb.le hr ht, + ← ENNReal.ofReal_mul (mul_nonneg (mul_nonneg hb.le (Real.rpow_nonneg ht.le _)) + (Real.Gamma_pos_of_pos (sub_pos.mpr hr)).le)] + +lemma gamma_lintegral_rpow_scale {q b c : ℝ} (hq : -1 < q) (hb : 0 < b) (hc : 0 < c) : + (∫⁻ t : ℝ in Ioi 0, ENNReal.ofReal (t^q*Real.exp (-c*t^b))) = + ENNReal.ofReal (c^(-(q+1)/b)*(1/b)*Real.Gamma ((q+1)/b)) := by + rw [← ofReal_integral_eq_lintegral_ofReal (integrableOn_rpow_mul_exp_neg_mul_rpow hq hb hc) (by + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + exact mul_nonneg (Real.rpow_nonneg ht.le _) (Real.exp_pos _).le), + integral_rpow_mul_exp_neg_mul_rpow hb hq hc] + +def stableJumpMomentE (r : ℝ) (η : Measure ℝ) : ℝ≥0∞ := + ∫⁻ x, ENNReal.ofReal (Real.exp (r*x)) ∂η + +@[fun_prop] lemma stableJumpMomentE_measurable (r : ℝ) : Measurable (stableJumpMomentE r) := + Measure.measurable_lintegral (by fun_prop) + +lemma stablePoisson_palm_laplace' {b r t : ℝ} (hb : 0 < b) (hb1 : b < 1) + (hr : b < r) (ht : 0 < t) : + (∫⁻ η, stableJumpMomentE r η*ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η)) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + ENNReal.ofReal (b*t^(b-r)*Real.Gamma (r-b)*Real.exp (-Real.Gamma (1-b)*t^b)) := by + have hh := stablePoisson_palm_laplace hb hb1 hr ht + simp_rw [ENNReal.ofReal_mul (Real.exp_pos _).le, + lintegral_mul_const' _ _ ENNReal.ofReal_ne_top] at hh + exact hh + +lemma stablePoisson_palm_mellin_mul {a b r : ℝ} (hb : 0 < b) (hb1 : b < 1) + (ha : a < b) (hr : b < r) : + (∫⁻ η, stableJumpMomentE r η*ENNReal.ofReal (stablePoissonTotal η^(a-r)) + ∂poissonRandomMeasureLaw (stableLogIntensity b))*ENNReal.ofReal (Real.Gamma (r-a)) = + ENNReal.ofReal (Real.Gamma (r-b)*Real.Gamma (1-a/b)* + (Real.Gamma (1-b))^(a/b-1)) := by + let P := poissonRandomMeasureLaw (stableLogIntensity b) + let c := Real.Gamma (1-b) + have hc : 0 < c := Real.Gamma_pos_of_pos (by linarith) + have hra : 0 < r-a := by linarith + let K := fun (η : Measure ℝ) (t : ℝ) => stableJumpMomentE r η* + ENNReal.ofReal (t^(r-a-1)*Real.exp (-t*stablePoissonTotal η)) + have hm : Measurable (Function.uncurry K) := by dsimp [K]; fun_prop + have hgamma : ∀ᵐ η ∂P, + stableJumpMomentE r η*ENNReal.ofReal (stablePoissonTotal η^(a-r))*ENNReal.ofReal (Real.Gamma (r-a)) = + ∫⁻ t : ℝ in Ioi 0, K η t := by + filter_upwards [stablePoissonTotal_pos hb hb1] with η hη + dsimp [K] + rw [lintegral_const_mul _ (by fun_prop),gamma_lintegral_positive_scale hra hη, + show -(r-a) = a-r by ring,ENNReal.ofReal_mul (Real.rpow_nonneg hη.le _),mul_assoc] + have hinner (t : ℝ) (ht : 0 < t) : (∫⁻ η, K η t ∂P) = + ENNReal.ofReal (b*Real.Gamma (r-b))*ENNReal.ofReal (t^(b-a-1)*Real.exp (-c*t^b)) := by + have hfac (η : Measure ℝ) : K η t = ENNReal.ofReal (t^(r-a-1))* + (stableJumpMomentE r η*ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η))) := by + dsimp [K] + rw [ENNReal.ofReal_mul (Real.rpow_nonneg ht.le _)] + ring + simp_rw [hfac] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top,stablePoisson_palm_laplace' hb hb1 hr ht, + ← ENNReal.ofReal_mul (Real.rpow_nonneg ht.le _), + ← ENNReal.ofReal_mul (mul_nonneg hb.le (Real.Gamma_pos_of_pos (sub_pos.mpr hr)).le)] + congr 1 + have hp : t^(r-a-1)*t^(b-r) = t^(b-a-1) := by rw [← Real.rpow_add ht]; congr 1; ring + calc + _ = b*Real.Gamma (r-b)*(t^(r-a-1)*t^(b-r))*Real.exp (-c*t^b) := by dsimp [c]; ring + _ = _ := by rw [hp]; ring + calc + _ = ∫⁻ η, stableJumpMomentE r η*ENNReal.ofReal (stablePoissonTotal η^(a-r))* + ENNReal.ofReal (Real.Gamma (r-a)) ∂P := + (lintegral_mul_const' _ _ ENNReal.ofReal_ne_top).symm + _ = ∫⁻ η, (∫⁻ t : ℝ in Ioi 0, K η t) ∂P := lintegral_congr_ae hgamma + _ = ∫⁻ t : ℝ in Ioi 0, ∫⁻ η, K η t ∂P := lintegral_lintegral_swap hm.aemeasurable + _ = ∫⁻ t : ℝ in Ioi 0, + ENNReal.ofReal (b*Real.Gamma (r-b))*ENNReal.ofReal (t^(b-a-1)*Real.exp (-c*t^b)) := by + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + exact hinner t ht + _ = ENNReal.ofReal (b*Real.Gamma (r-b))* + ENNReal.ofReal (c^(-((b-a-1)+1)/b)*(1/b)*Real.Gamma (((b-a-1)+1)/b)) := by + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top,gamma_lintegral_rpow_scale (by linarith) hb hc] + _ = _ := by + rw [← ENNReal.ofReal_mul (mul_nonneg hb.le (Real.Gamma_pos_of_pos (sub_pos.mpr hr)).le)] + congr 1 + rw [show -((b-a-1)+1)/b = a/b-1 by field_simp; ring, + show ((b-a-1)+1)/b = 1-a/b by field_simp; ring] + dsimp [c] + field_simp + +lemma stablePoissonTotal_rpow_lintegral_mul {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) + (ha : a < b) : + (∫⁻ η, ENNReal.ofReal (stablePoissonTotal η^a) + ∂poissonRandomMeasureLaw (stableLogIntensity b))*ENNReal.ofReal (Real.Gamma (1-a)) = + ENNReal.ofReal (Real.Gamma (1-a/b)*(Real.Gamma (1-b))^(a/b)) := by + have he := stablePoisson_palm_mellin_mul hb hb1 ha hb1 + have hrew : (fun η => stableJumpMomentE 1 η*ENNReal.ofReal (stablePoissonTotal η^(a-1))) =ᵐ[ + poissonRandomMeasureLaw (stableLogIntensity b)] (fun η => ENNReal.ofReal (stablePoissonTotal η^a)) := by + filter_upwards [stablePoisson_total_finite hb hb1,stablePoissonTotal_pos hb hb1] with η hη hpos + have hJ : stableJumpMomentE 1 η = ENNReal.ofReal (stablePoissonTotal η) := by + simp only [stableJumpMomentE,one_mul,stablePoissonTotal] + exact (ENNReal.ofReal_toReal hη).symm + rw [hJ,← ENNReal.ofReal_mul hpos.le] + congr 1 + calc + _ = stablePoissonTotal η^((1:ℝ)+(a-1)) := by rw [Real.rpow_add hpos,Real.rpow_one] + _ = _ := by congr 1; ring + rw [lintegral_congr_ae hrew] at he + rw [he] + congr 1 + have hc : 0 < Real.Gamma (1-b) := Real.Gamma_pos_of_pos (by linarith) + calc + _ = Real.Gamma (1-a/b)*((Real.Gamma (1-b))^((1:ℝ)+(a/b-1))) := by + rw [Real.rpow_add hc,Real.rpow_one]; ring + _ = _ := by congr 2; ring + +lemma stablePoissonTotal_rpow_integral {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) + (ha : a < b) : + (∫ η, stablePoissonTotal η^a ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + Real.Gamma (1-a/b)*(Real.Gamma (1-b))^(a/b)/Real.Gamma (1-a) := by + have hga : 0 < Real.Gamma (1-a) := Real.Gamma_pos_of_pos (by linarith) + have hgab : 0 < Real.Gamma (1-a/b) := Real.Gamma_pos_of_pos (by + have : a/b < 1 := (div_lt_one hb).mpr ha + linarith) + have hi := stablePoissonTotal_rpow_integrable hb hb1 ha + have hn : ∀ η : Measure ℝ, 0 ≤ stablePoissonTotal η^a := fun η => + Real.rpow_nonneg ENNReal.toReal_nonneg _ + have he := stablePoissonTotal_rpow_lintegral_mul hb hb1 ha + rw [← ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ hn)] at he + have her := congrArg ENNReal.toReal he + simp only [ENNReal.toReal_mul,ENNReal.toReal_ofReal (integral_nonneg hn), + ENNReal.toReal_ofReal hga.le,ENNReal.toReal_ofReal + (mul_nonneg hgab.le (Real.rpow_nonneg (Real.Gamma_pos_of_pos (by linarith : 0 < 1-b)).le _))] at her + exact (eq_div_iff hga.ne').mpr her + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/StablePoissonTotalLogMemLpTwo.lean b/lean/OAI/Probability/Perceptron/Cascade/StablePoissonTotalLogMemLpTwo.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a7f8fdda38f7b7167b8e46ed6f5a73a920f050c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/StablePoissonTotalLogMemLpTwo.lean @@ -0,0 +1,25 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.TiltReplicaCoordinate + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma stablePoissonTotal_log_memLp_two {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) : + MemLp (fun η => Real.log (stablePoissonTotal η)) 2 + (poissonRandomMeasureLaw (stableLogIntensity b)) := by + apply (memLp_two_iff_integrable_sq stablePoissonTotal_measurable.log.aestronglyMeasurable).mpr + simpa only [Real.rpow_zero,one_mul] using + stablePoissonTotal_weighted_log_sq_integrable (a := 0) hb0 hb1 hb0 + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/TwoVisitWeights.lean b/lean/OAI/Probability/Perceptron/Cascade/TwoVisitWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..14481e90989fe1571ed24472c3265196fdec1192 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/TwoVisitWeights.lean @@ -0,0 +1,116 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StepEntropy +import OAI.Probability.Perceptron.Variational.AtomicPairVisitLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +def depthMassIncrement : (n : ℕ) → (Fin n→ℝ) → ℝ → Fin (n+1) → ℝ + | 0,_,a,_ => 1-a + | n+1,z,a,d => Fin.cases (z 0-a) (fun i => depthMassIncrement n (fun j => z j.succ) (z 0) i) d + +lemma depthMassIncrement_nonneg (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) + (hz1 : ∀ i,z i<1) (a : ℝ) (ha : a<1) (haz : ∀ i,a exact sub_nonneg.mpr ha.le + | succ n ih => + induction d using Fin.cases with + | zero => exact sub_nonneg.mpr (haz 0).le + | succ d => + exact ih _ (fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij)) + (fun i => hz1 i.succ) (z 0) (hz1 0) (fun i => hz (Fin.succ_pos i)) d + +lemma twoDecoratedVisit_likelihood (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) + (hz1 : ∀ i,z i<1) (a : ℝ) (ha : a<1) (haz : ∀ i,a 1) (fun _ => 1) n d).bare n)= + ENNReal.ofReal (depthMassIncrement n z a d/(1-a)) := by + induction n generalizing a with + | zero => simp [cascadeShapeLikelihood,depthMassIncrement,(sub_pos.mpr ha).ne'] + | succ n ih => + induction d using Fin.cases with + | zero => + simp only [twoDecoratedVisit,Fin.cases_zero,DecoratedVisitShape.bare,cascadeShapeLikelihood, + List.map_cons,List.map_nil,List.prod_cons,List.prod_nil,oneDecoratedVisit_count,Nat.cast_one, + oneDecoratedVisit_likelihood _ _ _ (fun i => hz1 i.succ) _ (hz1 0),one_mul] + have he := stableEppfValue_new (hz1 0) [1] (by simp) (by simpa using sub_pos.mpr ha) + simp only [List.length_cons,List.length_nil,List.sum_cons,List.sum_nil,add_zero, + stableEppfValue_singleton_one ha (hz1 0),mul_one] at he + rw [he] + simp [depthMassIncrement] + | succ d => + simp only [twoDecoratedVisit,Fin.cases_succ,DecoratedVisitShape.bare,cascadeShapeLikelihood, + List.map_cons,List.map_nil,List.prod_cons,List.prod_nil,mul_one,twoDecoratedVisit_count,Nat.cast_ofNat] + rw [ih _ (fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij)) (fun i => hz1 i.succ) + (z 0) (hz1 0) (fun i => hz (Fin.succ_pos i)) d] + have he := stableEppfValue_join (hz1 0) ([] : List ℝ) (by simpa using sub_pos.mpr ha) + simp only [List.sum_nil,add_zero,stableEppfValue_singleton_one ha (hz1 0),mul_one] at he + rw [show (1:ℝ)+1=2 by norm_num] at he + rw [he,←ENNReal.ofReal_mul (div_nonneg + (depthMassIncrement_nonneg n _ (fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij)) + (fun i => hz1 i.succ) (z 0) (hz1 0) (fun i => hz (Fin.succ_pos i)) d) + (sub_pos.mpr (hz1 0)).le)] + congr 1 + change _=depthMassIncrement n (fun i => z i.succ) (z 0) d/(1-a) + field_simp [(sub_pos.mpr (hz1 0)).ne'] + +lemma depthMassIncrement_eq (n : ℕ) (z : Fin n→ℝ) (a : ℝ) (d : Fin (n+1)) : + depthMassIncrement n z a d=(Fin.snoc z 1 : Fin (n+1) → ℝ) d-(Fin.cons a z : Fin (n+1) → ℝ) d := by + induction n generalizing a with + | zero => simp [depthMassIncrement,Fin.snoc_zero,Fin.cons_zero,Fin.eq_zero d] + | succ n ih => + induction d using Fin.cases with + | zero => simp [depthMassIncrement] + | succ d => + change depthMassIncrement n (fun i => z i.succ) (z 0) d=_ + rw [ih,Fin.cons_succ] + have h1 : (Fin.cons (z 0) (fun i => z i.succ) : Fin (n+1) → ℝ) d=z d := congrFun (Fin.cons_self_tail z) d + rw [h1] + congr 1 + induction d using Fin.lastCases with + | last => simp + | cast d => simp only [Fin.succ_castSucc,Fin.snoc_castSucc] + +lemma depthMassIncrement_stepCumulative {n : ℕ} (w : Fin (n+1)→ℝ) (hw1 : ∑ i,w i=1) + (d : Fin (n+1)) : depthMassIncrement n (stepCumulative w) 0 d=w d := by + rw [depthMassIncrement_eq] + have hu : (Fin.snoc (stepCumulative w) 1 : Fin (n+1) → ℝ) d=∑ i,if i≤d then w i else 0 := by + induction d using Fin.lastCases with + | last => simpa only [Fin.snoc_last,Fin.le_last,ite_true] using hw1.symm + | cast d => simp only [Fin.snoc_castSucc,stepCumulative] + have hl : (Fin.cons 0 (stepCumulative w) : Fin (n+1) → ℝ) d=∑ i,if i simp + | succ d => + simp only [Fin.cons_succ,stepCumulative] + apply Finset.sum_congr rfl + intro i _ + congr 1 + exact propext (by change i.val≤d.val ↔ i.val a p.2) (ν.prod μ) := by + simpa using (integrable_const (1 : ℝ) (μ := ν)).mul_prod ha + have hi := hbase.indicator hmeas + have hleft (t : ℝ) : + (∫ s : Time, {p : ℝ × Time | (p.2 : ℝ) ≤ p.1}.indicator + (fun p => a p.2) (t, s) ∂μ) = weightedCDF μ a t := by + change (∫ s : Time, {s : Time | (s : ℝ) ≤ t}.indicator a s ∂μ) = _ + rw [integral_indicator (measurableSet_le (by fun_prop) measurable_const)] + rfl + have hright (s : Time) : + (∫ t, {p : ℝ × Time | (p.2 : ℝ) ≤ p.1}.indicator + (fun p => a p.2) (t, s) ∂ν) = max (r - s) 0 * a s := by + change (∫ t, (Ici (s : ℝ)).indicator (fun _ => a s) t ∂ν) = _ + rw [integral_indicator measurableSet_Ici] + have hset : Icc 0 r ∩ Ici (s : ℝ) = Icc (s : ℝ) r := by + ext t + simp only [mem_inter_iff, mem_Icc, mem_Ici] + constructor + · intro h; exact ⟨h.2, h.1.2⟩ + · intro h; exact ⟨⟨s.property.1.trans h.1, h.2⟩, h.1⟩ + dsimp only [ν] + rw [Measure.restrict_restrict measurableSet_Ici, inter_comm, hset, + setIntegral_const] + simp only [Measure.real, Real.volume_Icc, ENNReal.toReal_ofReal', smul_eq_mul] + have hl : (∫ t, weightedCDF μ a t ∂ν) = ∫ t in 0..r, weightedCDF μ a t := by + dsimp only [ν] + rw [integral_Icc_eq_integral_Ioc, intervalIntegral.integral_of_le hr] + constructor + · apply (intervalIntegrable_iff_integrableOn_Icc_of_le hr).mpr + have hi' : Integrable (weightedCDF μ a) ν := by + simpa only [Function.uncurry_apply_pair, hleft] using hi.integral_prod_left + change Integrable (weightedCDF μ a) ν + exact hi' + · have hs := integral_integral_swap (μ := ν) (ν := μ) + (f := fun t s => {p : ℝ × Time | (p.2 : ℝ) ≤ p.1}.indicator (fun p => a p.2) (t,s)) hi + simpa only [Function.uncurry_apply_pair, hleft, hright, hl] using hs + +lemma realTail_inv_formula (μ : Measure Time) [IsProbabilityMeasure μ] {B r : ℝ} + (hB : B < 1) (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) (hr : 0 ≤ r) (hrB : r ≤ B) : + (realTail μ r)⁻¹ - (realTail μ 0)⁻¹ = + realCDF μ r * cappedA μ B r - weightedCDF μ (fun s => cappedA μ B s) r := by + rw [realTail_inv_integral μ hB hμ hr hrB, + integral_cdf_mul μ hr ((cappedDensity_continuous μ hB).intervalIntegrable 0 r)] + have hm : MeasurableSet {s : Time | (s : ℝ) ≤ r} := + measurableSet_le (by fun_prop) measurable_const + have hA : Integrable (fun s : Time => cappedA μ B s) μ := + continuous_time_integrable μ ((cappedA_continuous μ hB).comp continuous_subtype_val) + have he (s : Time) : + (if (s : ℝ) ≤ r then ∫ t in (s : ℝ)..r, cappedDensity μ B t else 0) = + {s : Time | (s : ℝ) ≤ r}.indicator (fun _ => cappedA μ B r) s - + {s : Time | (s : ℝ) ≤ r}.indicator (fun s => cappedA μ B s) s := by + by_cases hs : (s : ℝ) ≤ r + · simp only [hs, ite_true, mem_ofPred_eq, indicator_of_mem] + have h := intervalIntegral.integral_add_adjacent_intervals + ((cappedDensity_continuous μ hB).intervalIntegrable (μ := volume) 0 (s : ℝ)) + ((cappedDensity_continuous μ hB).intervalIntegrable (μ := volume) (s : ℝ) r) + change _ = _ - _ + exact eq_sub_of_add_eq' h + · simp [hs] + simp_rw [he] + rw [integral_sub ((integrable_const _).indicator hm) (hA.indicator hm), + integral_indicator_const _ hm, integral_indicator hm] + rfl + +@[simp] lemma cappedA_zero (μ : Measure Time) (B : ℝ) : cappedA μ B 0 = 0 := by + simp [cappedA] + +lemma realTail_mul_A (μ : Measure Time) [IsProbabilityMeasure μ] {B r : ℝ} + (hB : B < 1) (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) (hr : 0 ≤ r) (hrB : r ≤ B) : + realTail μ r * cappedA μ B r = r * (realTail μ 0)⁻¹ - + ∫ s : Time, max (r - s) 0 * cappedA μ B s ∂μ := by + have hA := cappedA_continuous μ hB + have hAi : Integrable (fun s : Time => cappedA μ B s) μ := + continuous_time_integrable μ (hA.comp continuous_subtype_val) + have hG := weightedCDF_fubini μ hAi hr + have hd (x : ℝ) (hx : x ∈ Ioo 0 r) : + HasDerivWithinAt (fun t => realTail μ t * cappedA μ B t) + ((realTail μ 0)⁻¹ - weightedCDF μ (fun s => cappedA μ B s) x) (Ioi x) x := by + have hn : realTail μ x ≠ 0 := + ne_of_gt ((sub_pos.mpr hB).trans_le (realTail_lower μ hμ (hx.2.le.trans hrB))) + have he := realTail_inv_formula μ hB hμ hx.1.le (hx.2.le.trans hrB) + have hp := (realTail_right_derivative μ x).mul (cappedA_hasDerivAt μ hB x).hasDerivWithinAt + convert! hp using 1 + rw [cappedDensity_eq μ hμ (hx.2.le.trans hrB)] + have hm : realTail μ x * ((realTail μ x)⁻¹ ^ 2) = (realTail μ x)⁻¹ := by + field_simp + rw [hm] + linarith + have h := intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le + (f := fun t => realTail μ t * cappedA μ B t) + (f' := fun t => (realTail μ 0)⁻¹ - weightedCDF μ (fun s => cappedA μ B s) t) + hr ((realTail_continuous μ).mul hA).continuousOn hd + (intervalIntegrable_const.sub hG.1) + rw [intervalIntegral.integral_sub (f := fun _ => (realTail μ 0)⁻¹) + intervalIntegrable_const hG.1, hG.2] at h + simpa using h.symm + +lemma realTail_at_top (μ : Measure Time) [IsProbabilityMeasure μ] {B : ℝ} + (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) : realTail μ B = 1 - B := by + calc + _ = ∫ _ : Time, 1 - B ∂μ := integral_congr_ae (by + filter_upwards [hμ] with s hs + rw [max_eq_left hs]) + _ = _ := by simp + +lemma realCDF_at_top (μ : Measure Time) [IsProbabilityMeasure μ] {B : ℝ} + (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) : realCDF μ B = 1 := by + unfold realCDF Measure.real + have h : {s : Time | (s : ℝ) ≤ B} =ᵐ[μ] univ := by + filter_upwards [hμ] with s hs + change ((s : ℝ) ≤ B) = True + simp [hs] + rw [measure_congr h] + simp + +lemma weightedCDF_at_top (μ : Measure Time) {B : ℝ} + (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) (a : Time → ℝ) : + weightedCDF μ a B = ∫ s, a s ∂μ := by + unfold weightedCDF + have h : {s : Time | (s : ℝ) ≤ B} =ᵐ[μ] univ := by + filter_upwards [hμ] with s hs + change ((s : ℝ) ≤ B) = True + simp [hs] + rw [setIntegral_congr_set h, setIntegral_univ] + +lemma realTail_inv_zero_formula (μ : Measure Time) [IsProbabilityMeasure μ] {B : ℝ} + (hB : B < 1) (hB0 : 0 ≤ B) (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) : + (realTail μ 0)⁻¹ = 1 + ∫ s : Time, (1 - (s : ℝ)) * cappedA μ B s ∂μ := by + have hA : Continuous (fun s : Time => cappedA μ B s) := + (cappedA_continuous μ hB).comp continuous_subtype_val + have hAi := continuous_time_integrable μ hA + have hSAi : Integrable (fun s : Time => (s : ℝ) * cappedA μ B s) μ := + continuous_time_integrable μ (continuous_subtype_val.mul hA) + have htop := realTail_inv_formula μ hB hμ hB0 le_rfl + rw [realTail_at_top μ hμ, realCDF_at_top μ hμ, one_mul, + weightedCDF_at_top μ hμ] at htop + have hproduct := realTail_mul_A μ hB hμ hB0 le_rfl + rw [realTail_at_top μ hμ] at hproduct + have hi : (∫ s : Time, max (B - s) 0 * cappedA μ B s ∂μ) = + B * (∫ s : Time, cappedA μ B s ∂μ) - ∫ s : Time, (s : ℝ) * cappedA μ B s ∂μ := by + calc + _ = ∫ s : Time, B * cappedA μ B s - (s : ℝ) * cappedA μ B s ∂μ := + integral_congr_ae (by + filter_upwards [hμ] with s hs + rw [max_eq_left (sub_nonneg.mpr hs)] + ring) + _ = _ := by rw [integral_sub (hAi.const_mul B) hSAi, integral_const_mul] + rw [hi] at hproduct + have hc : (realTail μ 0)⁻¹ = 1 + (∫ s : Time, cappedA μ B s ∂μ) - + ∫ s : Time, (s : ℝ) * cappedA μ B s ∂μ := by + have htop' := congrArg (fun z : ℝ => (1 - B) * z) htop + have hinv : (1 - B) * (1 - B)⁻¹ = 1 := mul_inv_cancel₀ (ne_of_gt (sub_pos.mpr hB)) + nlinarith + rw [hc] + have hi' : (∫ s : Time, (1 - (s : ℝ)) * cappedA μ B s ∂μ) = + (∫ s : Time, cappedA μ B s ∂μ) - ∫ s : Time, (s : ℝ) * cappedA μ B s ∂μ := by + simp_rw [sub_mul, one_mul] + exact integral_sub hAi hSAi + rw [hi'] + ring + +theorem cappedA_sphere_equation (μ : Measure Time) [IsProbabilityMeasure μ] {B r : ℝ} + (hB : B < 1) (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) (hr : 0 ≤ r) (hrB : r ≤ B) : + cappedA μ B r * realTail μ r = r + + ∫ s : Time, (min r (s : ℝ) - r * (s : ℝ)) * cappedA μ B s ∂μ := by + have hA : Continuous (fun s : Time => cappedA μ B s) := + (cappedA_continuous μ hB).comp continuous_subtype_val + have ht := realTail_mul_A μ hB hμ hr hrB + rw [realTail_inv_zero_formula μ hB (hr.trans hrB) hμ] at ht + have hk (s : Time) : + (min r (s : ℝ) - r * (s : ℝ)) * cappedA μ B s = + r * ((1 - (s : ℝ)) * cappedA μ B s) - max (r - s) 0 * cappedA μ B s := by + rcases le_total r (s : ℝ) with hs | hs + · rw [min_eq_left hs, max_eq_right (sub_nonpos.mpr hs)] + ring + · rw [min_eq_right hs, max_eq_left (sub_nonneg.mpr hs)] + ring + simp_rw [hk] + rw [integral_sub (continuous_time_integrable μ (by fun_prop)) + (continuous_time_integrable μ (by fun_prop)), integral_const_mul] + nlinarith [ht] + +lemma cappedA_eq_integral (μ : Measure Time) [IsProbabilityMeasure μ] {B r : ℝ} + (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) (hr : 0 ≤ r) (hrB : r ≤ B) : + cappedA μ B r = ∫ t in 0..r, (realTail μ t)⁻¹ ^ 2 := by + apply intervalIntegral.integral_congr + intro x hx + rw [uIcc_of_le hr] at hx + exact cappedDensity_eq μ hμ (hx.2.trans hrB) + +theorem sphere_self_consistency (μ : Measure Time) [IsProbabilityMeasure μ] + {a : Time → ℝ} {A : ℝ} (hA : 0 ≤ A) (ha : AEStronglyMeasurable a μ) + (haNonneg : ∀ᵐ r ∂μ, 0 ≤ a r) (haBound : ∀ᵐ r ∂μ, a r ≤ A) + (haEq : ∀ᵐ r ∂μ, a r * sphereTail μ r = (r : ℝ) + ∫ s, sphereKernel r s * a s ∂μ) : + (∀ᵐ r : Time ∂μ, a r = ∫ t in 0..(r : ℝ), (realTail μ t)⁻¹ ^ 2) ∧ + ∀ᵐ r : Time ∂μ, (r : ℝ) ≤ A / (1 + A) := by + have hμ := sphere_equation_support_bound μ hA haNonneg haBound haEq + have hB : A / (1 + A) < 1 := (div_lt_one (by linarith)).mpr (by linarith) + let B := A / (1 + A) + have hb : Continuous (fun s : Time => cappedA μ B s) := + (cappedA_continuous μ hB).comp continuous_subtype_val + obtain ⟨C, hC⟩ := (isCompact_range hb.abs).bddAbove + have hident := sphere_equation_unique μ hB hμ ha hb.aestronglyMeasurable + ⟨A, by + filter_upwards [haNonneg, haBound] with s hs hsA + simpa only [abs_of_nonneg hs] using hsA⟩ + ⟨C, Eventually.of_forall fun s => hC (mem_range_self s)⟩ haEq + (by + filter_upwards [hμ] with r hr + exact cappedA_sphere_equation μ hB hμ r.property.1 hr) + refine ⟨?_, hμ⟩ + filter_upwards [hident, hμ] with r hr hrB + rw [hr, cappedA_eq_integral μ hμ r.property.1 hrB] + +def boundedCDF (μ : Measure Time) (r : Time) : ℝ := μ.real (Iic r) + +lemma boundedCDF_eq (μ : Measure Time) [IsProbabilityMeasure μ] (r : Time) : + boundedCDF μ r = cdf (μ.map fun s : Time => (s : ℝ)) r := by + rw [cdf_eq_real, map_measureReal_apply measurable_subtype_coe measurableSet_Iic] + rfl + +lemma boundedCDF_monotone (μ : Measure Time) [IsProbabilityMeasure μ] : + Monotone (boundedCDF μ) := by + intro r s hrs + exact measureReal_mono (Iic_subset_Iic.mpr hrs) + +lemma boundedCDF_top (μ : Measure Time) [IsProbabilityMeasure μ] : + boundedCDF μ 1 = 1 := by + have h : Iic (1 : Time) = univ := by + ext r + simp only [mem_Iic, mem_univ, iff_true] + exact r.property.2 + simp [boundedCDF, h] + +lemma boundedCDF_nonneg (μ : Measure Time) (r : Time) : 0 ≤ boundedCDF μ r := + measureReal_nonneg + +lemma boundedCDF_le_one (μ : Measure Time) [IsProbabilityMeasure μ] (r : Time) : + boundedCDF μ r ≤ 1 := by + rw [boundedCDF_eq] + exact cdf_le_one _ _ + +lemma boundedCDF_right_continuous (μ : Measure Time) [IsProbabilityMeasure μ] (r : Time) : + ContinuousWithinAt (boundedCDF μ) (Ici r) r := by + have hc := (cdf (μ.map fun s : Time => (s : ℝ))).right_continuous (r : ℝ) + have hmap : MapsTo (Subtype.val : Time → ℝ) (Ici r) (Ici (r : ℝ)) := fun _ hs => hs + have hcomp := hc.comp continuous_subtype_val.continuousWithinAt hmap + simpa only [Function.comp_def, ← boundedCDF_eq] using hcomp + +def boundedQuantile (μ : Measure Time) (u : Time) : Time := + sInf {r : Time | (u : ℝ) ≤ boundedCDF μ r} + +lemma boundedQuantile_le_iff (μ : Measure Time) [IsProbabilityMeasure μ] (u r : Time) : + boundedQuantile μ u ≤ r ↔ (u : ℝ) ≤ boundedCDF μ r := by + let A : Set Time := {r | (u : ℝ) ≤ boundedCDF μ r} + have hA : A.Nonempty := ⟨1, by simpa [A, boundedCDF_top] using u.property.2⟩ + have hcont : ContinuousWithinAt (boundedCDF μ) A (sInf A) := + (boundedCDF_right_continuous μ _).mono (fun x hx => sInf_le hx) + have hmin : (u : ℝ) ≤ boundedCDF μ (sInf A) := by + rw [MonotoneOn.map_csInf_of_continuousWithinAt hcont ((boundedCDF_monotone μ).monotoneOn A) hA] + apply le_csInf (hA.image _) + rintro _ ⟨s, hs, rfl⟩ + exact hs + constructor + · intro h + exact hmin.trans (boundedCDF_monotone μ h) + · exact fun h => sInf_le h + +lemma boundedQuantile_monotone (μ : Measure Time) [IsProbabilityMeasure μ] : + Monotone (boundedQuantile μ) := by + intro u v huv + rw [boundedQuantile_le_iff] + exact (show (u : ℝ) ≤ v from huv).trans ((boundedQuantile_le_iff μ v _).mp le_rfl) + +lemma boundedQuantile_measurable (μ : Measure Time) [IsProbabilityMeasure μ] : + Measurable (boundedQuantile μ) := (boundedQuantile_monotone μ).measurable + +theorem boundedQuantile_law (μ : Measure Time) [IsProbabilityMeasure μ] : + (volume : Measure Time).map (boundedQuantile μ) = μ := by + apply Measure.ext_of_Iic + intro r + rw [Measure.map_apply (boundedQuantile_measurable μ) measurableSet_Iic] + have hpre : boundedQuantile μ ⁻¹' Iic r = + Iic (⟨boundedCDF μ r, boundedCDF_nonneg μ r, boundedCDF_le_one μ r⟩ : Time) := by + ext u + exact boundedQuantile_le_iff μ u r + rw [hpre, unitInterval.volume_Iic] + exact ENNReal.ofReal_toReal (measure_ne_top μ _) + +lemma map_snd_restrict_prod (μ : Measure (Time × Time)) (s t : Set Time) + (ht : MeasurableSet t) : + ((μ.restrict (s ×ˢ univ)).map Prod.snd) t = μ (s ×ˢ t) := by + rw [Measure.map_apply measurable_snd ht, + Measure.restrict_apply (ht.preimage measurable_snd)] + congr 1 + ext x + simp only [mem_inter_iff, mem_preimage, mem_prod, mem_univ, and_true] + exact and_comm + +lemma map_fst_restrict_prod (μ : Measure (Time × Time)) (s t : Set Time) + (hs : MeasurableSet s) : + ((μ.restrict (univ ×ˢ t)).map Prod.fst) s = μ (s ×ˢ t) := by + rw [Measure.map_apply measurable_fst hs, + Measure.restrict_apply (hs.preimage measurable_fst)] + congr 1 + ext x + simp + +lemma measure_prod_ext_Iic (μ ν : Measure (Time × Time)) [IsFiniteMeasure μ] + [IsFiniteMeasure ν] + (h : ∀ r t, μ (Iic r ×ˢ Iic t) = ν (Iic r ×ˢ Iic t)) : μ = ν := by + have hrow (r : Time) : (μ.restrict (Iic r ×ˢ univ)).map Prod.snd = + (ν.restrict (Iic r ×ˢ univ)).map Prod.snd := by + apply Measure.ext_of_Iic + intro t + rw [map_snd_restrict_prod μ _ _ measurableSet_Iic, + map_snd_restrict_prod ν _ _ measurableSet_Iic] + exact h r t + apply Measure.ext_prod + intro s t hs ht + have hcol : (μ.restrict (univ ×ˢ t)).map Prod.fst = + (ν.restrict (univ ×ˢ t)).map Prod.fst := by + apply Measure.ext_of_Iic + intro r + rw [map_fst_restrict_prod μ _ _ measurableSet_Iic, + map_fst_restrict_prod ν _ _ measurableSet_Iic] + have hr := congrArg (fun ζ : Measure Time => ζ t) (hrow r) + simpa only [map_snd_restrict_prod μ _ _ ht, map_snd_restrict_prod ν _ _ ht] using hr + have hc := congrArg (fun ζ : Measure Time => ζ s) hcol + simpa only [map_fst_restrict_prod μ _ _ hs, map_fst_restrict_prod ν _ _ hs] using hc + +theorem no_crossing_lower_orthant (μ : Measure (Time × Time)) + (hNo : ∀ r t : Time, μ (Iic r ×ˢ Ioi t) = 0 ∨ μ (Ioi r ×ˢ Iic t) = 0) + (r t : Time) : + μ (Iic r ×ˢ Iic t) = min (μ (Iic r ×ˢ univ)) (μ (univ ×ˢ Iic t)) := by + have h₁ : Iic r ×ˢ univ ∩ univ ×ˢ Iic t = Iic r ×ˢ Iic t := by + ext x + simp only [mem_inter_iff, mem_prod, mem_Iic, mem_univ, and_true, true_and] + have h₂ : (Iic r ×ˢ univ) \ (univ ×ˢ Iic t) = Iic r ×ˢ Ioi t := by ext x; simp + have h₃ : (univ ×ˢ Iic t) \ (Iic r ×ˢ univ) = Ioi r ×ˢ Iic t := by ext x; simp [and_comm] + have ha := measure_inter_add_sdiff (μ := μ) (t := univ ×ˢ Iic t) (Iic r ×ˢ univ) + (MeasurableSet.univ.prod measurableSet_Iic) + have hb := measure_inter_add_sdiff (μ := μ) (t := Iic r ×ˢ univ) (univ ×ˢ Iic t) + (measurableSet_Iic.prod MeasurableSet.univ) + rw [h₁, h₂] at ha + rw [inter_comm, h₁, h₃] at hb + rcases hNo r t with h | h + · rw [h, add_zero] at ha + rw [← ha, min_eq_left (measure_mono (by intro x hx; exact ⟨mem_univ _, hx.2⟩))] + · rw [h, add_zero] at hb + rw [← hb, min_eq_right (measure_mono (by intro x hx; exact ⟨hx.1, mem_univ _⟩))] + +theorem no_crossing_quantile_coupling (μ : Measure (Time × Time)) [IsProbabilityMeasure μ] + (hNo : ∀ r t : Time, μ (Iic r ×ˢ Ioi t) = 0 ∨ μ (Ioi r ×ˢ Iic t) = 0) : + (volume : Measure Time).map + (fun u => (boundedQuantile (μ.map Prod.fst) u, boundedQuantile (μ.map Prod.snd) u)) = μ := by + apply measure_prod_ext_Iic + intro r t + rw [Measure.map_apply ((boundedQuantile_measurable _).prodMk (boundedQuantile_measurable _)) + (measurableSet_Iic.prod measurableSet_Iic), no_crossing_lower_orthant μ hNo] + let a : Time := ⟨boundedCDF (μ.map Prod.fst) r, + boundedCDF_nonneg _ _, boundedCDF_le_one _ _⟩ + let b : Time := ⟨boundedCDF (μ.map Prod.snd) t, + boundedCDF_nonneg _ _, boundedCDF_le_one _ _⟩ + have hp : (fun u => (boundedQuantile (μ.map Prod.fst) u, + boundedQuantile (μ.map Prod.snd) u)) ⁻¹' (Iic r ×ˢ Iic t) = Iic (min a b) := by + ext u + simp only [mem_preimage, mem_prod, mem_Iic, le_min_iff, boundedQuantile_le_iff] + rfl + rw [hp, unitInterval.volume_Iic] + change ENNReal.ofReal (min (boundedCDF (μ.map Prod.fst) r) + (boundedCDF (μ.map Prod.snd) t)) = _ + rw [ENNReal.ofReal_min, boundedCDF, boundedCDF, measureReal_def, measureReal_def, + ENNReal.ofReal_toReal (measure_ne_top _ _), ENNReal.ofReal_toReal (measure_ne_top _ _), + Measure.map_apply measurable_fst measurableSet_Iic, + Measure.map_apply measurable_snd measurableSet_Iic] + congr 2 <;> ext x <;> simp + +theorem no_crossing_quantile_bin_integral (μ : Measure (Time × Time)) [IsProbabilityMeasure μ] + (hNo : ∀ r t : Time, μ (Iic r ×ˢ Ioi t) = 0 ∨ μ (Ioi r ×ˢ Iic t) = 0) + (a b : Time) : + (∫ x in (univ ×ˢ Ioc a b), (x.1 : ℝ) ∂μ) = + ∫ u in (Ioc (⟨boundedCDF (μ.map Prod.snd) a, + boundedCDF_nonneg _ _, boundedCDF_le_one _ _⟩ : Time) + (⟨boundedCDF (μ.map Prod.snd) b, + boundedCDF_nonneg _ _, boundedCDF_le_one _ _⟩ : Time)), + (boundedQuantile (μ.map Prod.fst) u : ℝ) := by + let g : Time → Time × Time := fun u => + (boundedQuantile (μ.map Prod.fst) u, boundedQuantile (μ.map Prod.snd) u) + have hg : Measurable g := (boundedQuantile_measurable _).prodMk (boundedQuantile_measurable _) + have hmap : (volume : Measure Time).map g = μ := no_crossing_quantile_coupling μ hNo + have hi := setIntegral_map (μ := (volume : Measure Time)) + (f := fun x : Time × Time => (x.1 : ℝ)) + (MeasurableSet.univ.prod (measurableSet_Ioc (a := a) (b := b))) + (by fun_prop) hg.aemeasurable + rw [hmap] at hi + rw [hi] + have hs : g ⁻¹' (univ ×ˢ Ioc a b) = + Ioc (⟨boundedCDF (μ.map Prod.snd) a, + boundedCDF_nonneg _ _, boundedCDF_le_one _ _⟩ : Time) + (⟨boundedCDF (μ.map Prod.snd) b, + boundedCDF_nonneg _ _, boundedCDF_le_one _ _⟩ : Time) := by + ext u + simp only [mem_preimage, g, mem_prod, mem_univ, true_and, mem_Ioc, + lt_iff_not_ge, boundedQuantile_le_iff] + rfl + rw [hs] + +instance (α : ℝ) (N : ℕ) : IsProbabilityMeasure (patternLaw α N) := by + unfold patternLaw + infer_instance + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/WeightedTotalBiasedLaw.lean b/lean/OAI/Probability/Perceptron/Cascade/WeightedTotalBiasedLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..8029f77a9b377b4a180dad10618037de8284a28a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/WeightedTotalBiasedLaw.lean @@ -0,0 +1,300 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.MarkedTotalBiasedLaw + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff +attribute [fun_prop] stablePoissonTotal_measurable +section MarkedStable +variable {S : Type*} [MeasurableSpace S] +variable [Nonempty S] + +def weightedTotalBiasedLaw (ν : Measure S) [IsProbabilityMeasure ν] (a b : ℝ) (F : S → ℝ) : + Measure (Measure (ℝ × S)) := + normalizedMeasure ((poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).withDensity + (fun η => ENNReal.ofReal (poissonWeightedTotal F η^a))) + +lemma weightedTotalBiasedLaw_shift (ν : Measure S) [IsProbabilityMeasure ν] + {a b : ℝ} (hb : 0 ≤ b) {F : S → ℝ} (hF : Measurable F) + [IsProbabilityMeasure (ν.withDensity (fun c => ENNReal.ofReal (Real.exp (b*F c))))] : + (weightedTotalBiasedLaw ν a b F).map (Measure.map (logMarkShift F)) = + markedTotalBiasedLaw (ν.withDensity (fun c => ENNReal.ofReal (Real.exp (b*F c)))) a b := by + let Φ := Measure.map (logMarkShift F) + have hΦ : Measurable Φ := Measure.measurable_map _ (logMarkShift_measurable hF) + have hpow : Measurable (fun η : Measure (ℝ × S) => ENNReal.ofReal (markedStableTotal η^a)) := by fun_prop + unfold weightedTotalBiasedLaw markedTotalBiasedLaw + rw [normalizedMeasure_map _ hΦ] + congr 1 + have hd := map_withDensity_comp (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) hΦ hpow + dsimp [Function.comp_def,Φ] at hd + simp_rw [markedStableTotal_map_shift _ hF] at hd + rw [stablePoisson_mark_shift ν hb hF] at hd + exact hd.symm + +lemma weightedTotalBiasedLaw_add_const (ν : Measure S) [IsProbabilityMeasure ν] + (a b : ℝ) {F : S → ℝ} (hF : Measurable F) (c : ℝ) : + weightedTotalBiasedLaw ν a b (fun x => F x+c) = weightedTotalBiasedLaw ν a b F := by + have hpw (η : Measure (ℝ × S)) : poissonWeightedTotal (fun x => F x+c) η^a = + (Real.exp c)^a*(poissonWeightedTotal F η)^a := by + rw [poissonWeightedTotal_add_const hF c η] + exact Real.mul_rpow (Real.exp_pos c).le (show 0 ≤ poissonWeightedTotal F η from ENNReal.toReal_nonneg) + unfold weightedTotalBiasedLaw + simp_rw [hpw,ENNReal.ofReal_mul (Real.rpow_nonneg (Real.exp_pos c).le a)] + have he := withDensity_smul' (μ := poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) + (ENNReal.ofReal ((Real.exp c)^a)) (fun η => ENNReal.ofReal (poissonWeightedTotal F η^a)) ENNReal.ofReal_ne_top + simp only [Pi.smul_def,smul_eq_mul] at he + rw [he,normalizedMeasure_smul _ + (ENNReal.ofReal_ne_zero_iff.mpr (Real.rpow_pos_of_pos (Real.exp_pos c) a)) ENNReal.ofReal_ne_top] + +omit [Nonempty S] in + +lemma weightedBranchMass_map (η : Measure (ℝ × S)) {F : S → ℝ} (hF : Measurable F) : + (normalizedMeasure (η.withDensity (fun p : ℝ × S => ENNReal.ofReal (Real.exp (p.1+F p.2))))).map (logMarkShift F) = + markedStableMassKernel (η.map (logMarkShift F)) := by + rw [normalizedMeasure_map _ (logMarkShift_measurable hF)] + change normalizedMeasure _ = normalizedMeasure ((η.map (logMarkShift F)).withDensity + (fun p : ℝ × S => ENNReal.ofReal (Real.exp p.1))) + rw [map_withDensity_comp η (logMarkShift_measurable hF) (by fun_prop)] + rfl + +def exponentialMarkTilt (ν : Measure S) (b : ℝ) (X : S → ℝ) : Measure S := + normalizedMeasure (ν.withDensity (fun x => ENNReal.ofReal (Real.exp (b*X x)))) + +def centeredLogMark (ν : Measure S) (b : ℝ) (X : S → ℝ) : S → ℝ := + fun x => X x-Real.log (∫ y, Real.exp (b*X y) ∂ν)/b + +omit [Nonempty S] in +lemma centeredLogMark_measurable (ν : Measure S) (b : ℝ) {X : S → ℝ} (hX : Measurable X) : + Measurable (centeredLogMark ν b X) := hX.sub_const _ + +omit [Nonempty S] in +lemma exponentialMarkTilt_probability (ν : Measure S) [IsProbabilityMeasure ν] + {b : ℝ} {X : S → ℝ} (hI : Integrable (fun x => Real.exp (b*X x)) ν) : + IsProbabilityMeasure (exponentialMarkTilt ν b X) := by + have hMpos := integral_exp_pos hI + apply normalizedMeasure_probability + all_goals rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal hI (ae_of_all _ fun x => (Real.exp_pos _).le)] + · exact ENNReal.ofReal_ne_zero_iff.mpr hMpos + · exact ENNReal.ofReal_ne_top + +omit [Nonempty S] in +lemma centeredLogMark_density (ν : Measure S) [IsProbabilityMeasure ν] + {b : ℝ} (hb : b ≠ 0) {X : S → ℝ} (hI : Integrable (fun x => Real.exp (b*X x)) ν) : + ν.withDensity (fun x => ENNReal.ofReal (Real.exp (b*centeredLogMark ν b X x))) = + exponentialMarkTilt ν b X := by + let M := ∫ y, Real.exp (b*X y) ∂ν + have hMpos : 0 < M := integral_exp_pos hI + have hd (x : S) : ENNReal.ofReal (Real.exp (b*centeredLogMark ν b X x)) = + (ENNReal.ofReal M)⁻¹*ENNReal.ofReal (Real.exp (b*X x)) := by + unfold centeredLogMark + rw [mul_sub,show b*(Real.log (∫ y, Real.exp (b*X y) ∂ν)/b) = Real.log M by dsimp [M]; field_simp, + Real.exp_sub,Real.exp_log hMpos,ENNReal.ofReal_div_of_pos hMpos,div_eq_mul_inv,mul_comm] + simp_rw [hd] + have he := withDensity_smul' (μ := ν) (ENNReal.ofReal M)⁻¹ + (fun x => ENNReal.ofReal (Real.exp (b*X x))) + (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr hMpos)) + simp only [Pi.smul_def,smul_eq_mul] at he + rw [he] + unfold exponentialMarkTilt normalizedMeasure + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal hI (ae_of_all _ fun x => (Real.exp_pos _).le)] + +lemma weightedTotalBiasedLaw_centered (ν : Measure S) [IsProbabilityMeasure ν] + (a b : ℝ) {X : S → ℝ} (hX : Measurable X) : + weightedTotalBiasedLaw ν a b (centeredLogMark ν b X) = weightedTotalBiasedLaw ν a b X := by + change weightedTotalBiasedLaw ν a b (fun x => X x-Real.log (∫ y, Real.exp (b*X y) ∂ν)/b) = _ + simpa only [sub_eq_add_neg] using + weightedTotalBiasedLaw_add_const ν a b hX (-(Real.log (∫ y, Real.exp (b*X y) ∂ν)/b)) + +lemma weightedRootBlock_factor (ν : Measure S) [IsProbabilityMeasure ν] + {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) + {X : S → ℝ} (hX : Measurable X) (hI : Integrable (fun x => Real.exp (b*X x)) ν) + (ns : List (ℕ × (S → ℝ≥0∞))) (hne : ns ≠ []) (hn : ∀ nf ∈ ns, 1 ≤ nf.1) + (hm : ∀ nf ∈ ns, Measurable nf.2) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, markedBlockProbability ns (η.map (logMarkShift (centeredLogMark ν b X))) z + ∂weightedTotalBiasedLaw ν a b X) = + (ns.map (fun nf => ∫⁻ c, nf.2 c ∂exponentialMarkTilt ν b X)).prod* + (∫⁻ η, stableBlockProbability (ns.map Prod.fst) η z ∂stableTotalBiasedLaw a b) := by + let F := centeredLogMark ν b X + have hF : Measurable F := centeredLogMark_measurable ν b hX + have : IsProbabilityMeasure (exponentialMarkTilt ν b X) := exponentialMarkTilt_probability ν hI + have hd := centeredLogMark_density ν hb.ne' hI + have : IsProbabilityMeasure (ν.withDensity (fun x => ENNReal.ofReal (Real.exp (b*F x)))) := by + simpa only [F,hd] using (exponentialMarkTilt_probability ν hI) + have he := weightedTotalBiasedLaw_shift (a := a) ν hb.le hF + rw [weightedTotalBiasedLaw_centered ν a b hX] at he + have hD : Measurable (fun η : Measure (ℝ × S) => markedBlockProbability ns η z) := + (markedBlockProbability_measurable ns hm m).comp (measurable_id.prodMk measurable_const) + rw [← lintegral_map hD (Measure.measurable_map _ (logMarkShift_measurable hF)),he, + markedBlockProbability_factor _ hb hb1 ha ns hne hn hm] + simp only [F,hd] + +end MarkedStable + +def cascadeBiasedLaw (n : ℕ) (z : Fin n → ℝ) (a : ℝ) : Measure (StableCascade n) := + normalizedMeasure ((cascadeLaw n z : Measure (StableCascade n)).withDensity + (fun η => ENNReal.ofReal (cascadeTotal n η^a))) + +lemma cascadeLogTotalMoment_integrable (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (a : ℝ) (ha : ∀ i, a < z i) : + Integrable (fun η => Real.exp (a*Real.log (cascadeTotal n η))) + (cascadeLaw n z : Measure (StableCascade n)) := by + obtain ⟨hp,hi⟩ := cascadeTotal_regular n z hz hz0 hz1 + apply (hi a ha).congr + filter_upwards [hp] with η hη + rw [Real.rpow_def_of_pos hη,mul_comm] + +lemma cascadeBiasedLaw_eq_exponentialTilt (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (a : ℝ) : + cascadeBiasedLaw n z a = exponentialMarkTilt (cascadeLaw n z) a + (fun C => Real.log (cascadeTotal n C)) := by + unfold cascadeBiasedLaw exponentialMarkTilt + congr 1 + apply withDensity_congr_ae + filter_upwards [(cascadeTotal_regular n z hz hz0 hz1).1] with C hC + rw [Real.rpow_def_of_pos hC,mul_comm] + +lemma cascadeBiasedLaw_probability (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (a : ℝ) (ha : ∀ i, a < z i) : + IsProbabilityMeasure (cascadeBiasedLaw n z a) := by + rw [cascadeBiasedLaw_eq_exponentialTilt n z hz hz0 hz1 a] + exact exponentialMarkTilt_probability _ (cascadeLogTotalMoment_integrable n z hz hz0 hz1 a ha) + +lemma cascadeBiasedLaw_succ_eq_weighted {n : ℕ} (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (a : ℝ) : + cascadeBiasedLaw (n+1) z a = weightedTotalBiasedLaw + (cascadeLaw n (fun i => z i.succ)) a (z 0) (fun C => Real.log (cascadeTotal n C)) := by + have htail : StrictMono (fun i : Fin n => z i.succ) := fun i j h => hz (Fin.succ_lt_succ_iff.mpr h) + have hp := (cascadeTotal_regular n (fun i => z i.succ) htail + (fun i => hz0 i.succ) (fun i => hz1 i.succ)).1 + unfold cascadeBiasedLaw weightedTotalBiasedLaw + congr 1 + apply withDensity_congr_ae + filter_upwards [cascadeTotal_succ_eq z hp] with C hC + rw [hC] + +lemma cascadeRootBlock_factor {n : ℕ} (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) {a : ℝ} (ha : a < z 0) + (ns : List (ℕ × (StableCascade n → ℝ≥0∞))) (hne : ns ≠ []) + (hn : ∀ nf ∈ ns, 1 ≤ nf.1) (hm : ∀ nf ∈ ns, Measurable nf.2) : + (∫⁻ η, markedBlockProbability ns + (η.map (logMarkShift (centeredLogMark (cascadeLaw n (fun i => z i.succ)) (z 0) + (fun C => Real.log (cascadeTotal n C))))) (Fin.elim0 : Fin 0 → ℝ) + ∂cascadeBiasedLaw (n+1) z a) = + (ns.map (fun nf => ∫⁻ C, nf.2 C ∂cascadeBiasedLaw n (fun i => z i.succ) (z 0))).prod * + (∫⁻ η, stableBlockProbability (ns.map Prod.fst) η (Fin.elim0 : Fin 0 → ℝ) + ∂stableTotalBiasedLaw a (z 0)) := by + have htail : StrictMono (fun i : Fin n => z i.succ) := fun i j h => hz (Fin.succ_lt_succ_iff.mpr h) + have hM := cascadeLogTotalMoment_integrable n (fun i => z i.succ) htail + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (z 0) (fun i => hz (by simp)) + have he := weightedRootBlock_factor _ (hz0 0) (hz1 0) ha (cascadeTotal_measurable n).log hM ns hne hn hm (z := (Fin.elim0 : Fin 0 → ℝ)) + rw [← cascadeBiasedLaw_eq_exponentialTilt n (fun i => z i.succ) htail + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (z 0)] at he + rw [cascadeBiasedLaw_succ_eq_weighted z hz hz0 hz1 a] + exact he + +@[reducible] def CascadeVisitShape : ℕ → Type + | 0 => ℕ + | n+1 => List (CascadeVisitShape n) + +def cascadeVisitCount : (n : ℕ) → CascadeVisitShape n → ℕ + | 0, r => r + | n+1, ss => (ss.map (cascadeVisitCount n)).sum + +def CascadeVisitShape.Valid : (n : ℕ) → CascadeVisitShape n → Prop + | 0, r => 1 ≤ r + | n+1, ss => ss ≠ [] ∧ ∀ s ∈ ss, CascadeVisitShape.Valid n s + +lemma cascadeVisitCount_pos (n : ℕ) (s : CascadeVisitShape n) (hs : CascadeVisitShape.Valid n s) : + 1 ≤ cascadeVisitCount n s := by + induction n with + | zero => exact hs + | succ n ih => + obtain ⟨hne,hs⟩ := hs + change (s.map (cascadeVisitCount n)).sum ≥ 1 + cases s with + | nil => exact (hne rfl).elim + | cons h t => + simp only [List.map_cons,List.sum_cons] + have := ih h (hs h (by simp)) + omega + +def cascadeShapeProbability : (n : ℕ) → (Fin n → ℝ) → CascadeVisitShape n → StableCascade n → ℝ≥0∞ + | 0, _, _, _ => 1 + | n+1, z, ss, η => markedBlockProbability + (ss.map (fun s => (cascadeVisitCount n s,cascadeShapeProbability n (fun i => z i.succ) s))) + (η.map (logMarkShift (centeredLogMark (cascadeLaw n (fun i => z i.succ)) (z 0) + (fun C => Real.log (cascadeTotal n C))))) (Fin.elim0 : Fin 0 → ℝ) + +lemma cascadeShapeProbability_measurable (n : ℕ) (z : Fin n → ℝ) (s : CascadeVisitShape n) : + Measurable (cascadeShapeProbability n z s) := by + induction n with + | zero => exact measurable_const + | succ n ih => + have hm : ∀ nf ∈ s.map (fun s => (cascadeVisitCount n s,cascadeShapeProbability n (fun i => z i.succ) s)), + Measurable nf.2 := by + intro nf hnf + obtain ⟨s',_,rfl⟩ := List.mem_map.mp hnf + exact ih (fun i => z i.succ) s' + have hF := logMarkShift_measurable (centeredLogMark_measurable + (cascadeLaw n (fun i => z i.succ)) (z 0) (cascadeTotal_measurable n).log) + exact (markedBlockProbability_measurable _ hm 0).comp + ((Measure.measurable_map _ hF).prodMk measurable_const) + +def cascadeShapeLikelihood : (n : ℕ) → (Fin n → ℝ) → ℝ → CascadeVisitShape n → ℝ≥0∞ + | 0, _, _, _ => 1 + | n+1, z, a, ss => + (ss.map (cascadeShapeLikelihood n (fun i => z i.succ) (z 0))).prod * + ENNReal.ofReal (stableEppfValue a (z 0) (ss.map (fun s => (cascadeVisitCount n s : ℝ)))) + +theorem cascadeShapeProbability_integral (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (a : ℝ) (ha : ∀ i, a < z i) + (s : CascadeVisitShape n) (hs : CascadeVisitShape.Valid n s) : + (∫⁻ η, cascadeShapeProbability n z s η ∂cascadeBiasedLaw n z a) = + cascadeShapeLikelihood n z a s := by + induction n generalizing a with + | zero => + have := cascadeBiasedLaw_probability 0 z hz hz0 hz1 a ha + simp only [cascadeShapeProbability,cascadeShapeLikelihood,lintegral_const,measure_univ,mul_one] + | succ n ih => + obtain ⟨hne,hs⟩ := hs + let ns := s.map (fun s => (cascadeVisitCount n s,cascadeShapeProbability n (fun i => z i.succ) s)) + have hns : ns ≠ [] := by + intro he + apply hne + exact List.map_eq_nil_iff.mp he + have hn : ∀ nf ∈ ns, 1 ≤ nf.1 := by + intro nf hnf; obtain ⟨s',hmem,rfl⟩ := List.mem_map.mp hnf + exact cascadeVisitCount_pos n s' (hs s' hmem) + have hm : ∀ nf ∈ ns, Measurable nf.2 := by + intro nf hnf; obtain ⟨s',_,rfl⟩ := List.mem_map.mp hnf + exact cascadeShapeProbability_measurable n (fun i => z i.succ) s' + change (∫⁻ η, markedBlockProbability ns _ _ ∂cascadeBiasedLaw (n+1) z a) = _ + rw [cascadeRootBlock_factor z hz hz0 hz1 (ha 0) ns hns hn hm, + stableBlockProbability_eppf (hz0 0) (hz1 0) (ha 0) (ns.map Prod.fst) + (by simpa using hns) (by intro r hr; obtain ⟨nf,hmem,rfl⟩ := List.mem_map.mp hr; exact hn nf hmem)] + simp only [ns,List.map_map,Function.comp_def,cascadeShapeLikelihood,stableEppfValue,List.length_map] + congr 2 + apply List.map_congr_left + intro s' hmem + exact ih (fun i => z i.succ) (fun i j h => hz (Fin.succ_lt_succ_iff.mpr h)) + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (z 0) (fun i => hz (by simp)) s' (hs s' hmem) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cascade/WeightedTrialLaw.lean b/lean/OAI/Probability/Perceptron/Cascade/WeightedTrialLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..2135400700ed77d8bafceb3bb29811ce87b09b6e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cascade/WeightedTrialLaw.lean @@ -0,0 +1,59 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.WeightedCDF +import OAI.Probability.Perceptron.Variational.FieldRounding + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +def weightedTrialLaw {I : Type*} [Fintype I] (w : I→ℝ) (q : I→Time) : Measure Time := + ∑ i, ENNReal.ofReal (w i) • Measure.dirac (q i) + +lemma weightedTrialLaw_probability {I : Type*} [Fintype I] (w : I→ℝ) (q : I→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) : IsProbabilityMeasure (weightedTrialLaw w q) := by + constructor + simp only [weightedTrialLaw,Measure.finsetSum_apply,Measure.smul_apply,Measure.dirac_apply_of_mem + (mem_univ _),smul_eq_mul,mul_one] + rw [← ENNReal.ofReal_sum_of_nonneg (fun i _ => hw i),hw1,ENNReal.ofReal_one] + +lemma weightedTrialLaw_integral {I : Type*} [Fintype I] (w : I→ℝ) (q : I→Time) + (hw : ∀ i, 0≤w i) (g : Time→ℝ) : + (∫ x, g x ∂weightedTrialLaw w q)=∑ i, w i*g (q i) := by + unfold weightedTrialLaw + rw [integral_finsetSum_measure] + · simp only [integral_smul_measure,integral_dirac,ENNReal.toReal_ofReal (hw _),smul_eq_mul] + · intro i _ + exact (integrable_dirac (by finiteness)).smul_measure ENNReal.ofReal_ne_top + +lemma weightedTrialLaw_Iic {I : Type*} [Fintype I] (w : I→ℝ) (q : I→Time) + (hw : ∀ i, 0≤w i) (t : Time) : + (weightedTrialLaw w q).real (Iic t)=∑ i, if q i≤t then w i else 0 := by + simp only [weightedTrialLaw,Measure.real,Measure.finsetSum_apply,Measure.smul_apply, + Measure.dirac_apply' _ measurableSet_Iic,smul_eq_mul,Set.indicator_apply,mem_Iic,Pi.one_apply] + rw [ENNReal.toReal_sum] + · apply Finset.sum_congr rfl + intro i _ + split_ifs <;> simp [ENNReal.toReal_ofReal (hw i)] + · intro i _ + split_ifs <;> simp + +lemma quantileTrial_weightedTrialLaw {I : Type*} [Fintype I] (w : I→ℝ) (q : I→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) : + quantileTrial (boundedQuantile (weightedTrialLaw w q))=weightedStepTrial w q hw hw1 := by + have := weightedTrialLaw_probability w q hw hw1 + apply Trial.ext_fun + intro t + change (timeLaw {u | boundedQuantile (weightedTrialLaw w q) u≤t}).toReal=_ + have he := congrArg (fun μ : Measure Time => μ (Iic t)) (boundedQuantile_law (weightedTrialLaw w q)) + rw [Measure.map_apply (boundedQuantile_measurable _) measurableSet_Iic] at he + change (timeLaw {u | boundedQuantile (weightedTrialLaw w q) u≤t})=_ at he + rw [he] + exact weightedTrialLaw_Iic w q hw t + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/AmbientBulkFeature.lean b/lean/OAI/Probability/Perceptron/Cavity/AmbientBulkFeature.lean new file mode 100644 index 0000000000000000000000000000000000000000..59f0bf792dd4b215f7843b3a5035860c1ec383a7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/AmbientBulkFeature.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkModel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal Topology BigOperators ContDiff +namespace SphericalPerceptronFreeEnergy + +def ambientTensorFeature (N p : ℕ) (x : Spin N) : EuclideanSpace ℝ (SpinTensorIndex N p) := + WithLp.toLp 2 (fun i => ∏ j, x (i j)) + +lemma ambientTensorFeature_contDiff (N p : ℕ) : ContDiff ℝ ∞ (ambientTensorFeature N p) := by + apply (PiLp.contDiff_toLp).comp + apply contDiff_pi.mpr + intro i + exact contDiff_prod (fun j _ => (EuclideanSpace.proj (i j) : Spin N →L[ℝ] ℝ).contDiff) + +lemma ambientTensorFeature_inner (N p : ℕ) (x y : Spin N) : + inner ℝ (ambientTensorFeature N p x) (ambientTensorFeature N p y) = inner ℝ x y ^ p := by + change (∑ i : SpinTensorIndex N p, (∏ j, y (i j))*(∏ j, x (i j))) = _ + simp_rw [← Finset.prod_mul_distrib] + rw [← Fintype.prod_sum (fun (_ : Fin p) (i : Fin N) => y i*x i)] + change (∏ _ : Fin p, inner ℝ x y)=inner ℝ x y^p + simp + +def ambientBulkFeature (N : ℕ) (v : ℕ→ℝ) (x : Spin N) : BulkMark N := + WithLp.toLp 2 fun i => match i with + | .inl _ => 0 + | .inr ⟨j,t⟩ => bulkAmplitude N v j*ambientTensorFeature N (bulkDegree j) x t + +lemma ambientBulkFeature_eq (N : ℕ) (v : ℕ→ℝ) (x : NormalizedSpin N) : + ambientBulkFeature N v x.val=bulkFeature N v x := by + ext i + cases i <;> simp [ambientBulkFeature,bulkFeature,enrichedFeature,ambientTensorFeature,spinTensorFeature] + +lemma ambientBulkFeature_contDiff (N : ℕ) (v : ℕ→ℝ) : ContDiff ℝ ∞ (ambientBulkFeature N v) := by + apply (PiLp.contDiff_toLp).comp + apply contDiff_pi.mpr + intro i + cases i with + | inl i => exact contDiff_const + | inr i => exact contDiff_const.mul ((EuclideanSpace.proj i.2).contDiff.comp (ambientTensorFeature_contDiff _ _)) + +lemma ambientBulkFeature_inner (N : ℕ) (v : ℕ→ℝ) (x y : Spin N) : + inner ℝ (ambientBulkFeature N v x) (ambientBulkFeature N v y)= + ∑ j : Fin N, bulkAmplitude N v j^2*inner ℝ x y^(j.val+1) := by + change (∑ i : EnrichedIndex N N bulkDegree, + ambientBulkFeature N v y i*ambientBulkFeature N v x i)=_ + rw [Fintype.sum_sum_type,Fintype.sum_sigma] + simp only [ambientBulkFeature,mul_zero,Finset.sum_const_zero,zero_add] + apply Finset.sum_congr rfl + intro j _ + rw [← ambientTensorFeature_inner N (j.val+1) x y] + change (∑ i, bulkAmplitude N v j*ambientTensorFeature N _ y i* + (bulkAmplitude N v j*ambientTensorFeature N _ x i)) = + bulkAmplitude N v j^2*(∑ i, ambientTensorFeature N _ y i*ambientTensorFeature N _ x i) + rw [Finset.mul_sum] + exact Finset.sum_congr rfl fun _ _ => by dsimp [bulkDegree]; ring + +def bulkCovarianceDerivative (N : ℕ) (v : ℕ→ℝ) (r : ℝ) : ℝ := + ∑ j : Fin N, bulkAmplitude N v j^2*(j.val+1)*r^j.val + +lemma ambientBulkFeature_deriv_inner (N : ℕ) (v : ℕ→ℝ) (x y z : Spin N) : + inner ℝ (fderiv ℝ (ambientBulkFeature N v) x z) (ambientBulkFeature N v y)= + bulkCovarianceDerivative N v (inner ℝ x y)*inner ℝ z y := by + have hd := ((innerSL ℝ (ambientBulkFeature N v y)).hasFDerivAt.comp x + ((ambientBulkFeature_contDiff N v).differentiable (by norm_num) x).hasFDerivAt).fderiv + have he : (fun x => inner ℝ (ambientBulkFeature N v y) (ambientBulkFeature N v x))= + (fun x => ∑ j : Fin N, bulkAmplitude N v j^2*inner ℝ y x^(j.val+1)) := by + funext x; exact ambientBulkFeature_inner N v y x + have hh : HasFDerivAt (fun x : Spin N => ∑ j : Fin N, bulkAmplitude N v j^2*inner ℝ y x^(j.val+1)) + (∑ j : Fin N, (bulkAmplitude N v j^2*((j.val+1:ℕ):ℝ)*inner ℝ y x^j.val) • innerSL ℝ y) x := by + have ht (j : Fin N) : HasFDerivAt (fun x : Spin N => bulkAmplitude N v j^2*inner ℝ y x^(j.val+1)) + ((bulkAmplitude N v j^2*((j.val+1:ℕ):ℝ)*inner ℝ y x^j.val) • innerSL ℝ y) x := by + simpa only [Nat.add_sub_cancel,nsmul_eq_mul,smul_smul,smul_eq_mul,coe_innerSL_apply,mul_assoc] using + (((innerSL ℝ y).hasFDerivAt (x:=x)).pow (j.val+1)).const_mul (bulkAmplitude N v j^2) + exact HasFDerivAt.fun_sum (fun j (_ : j ∈ (Finset.univ : Finset (Fin N))) => ht j) + simp only [Function.comp_def,coe_innerSL_apply] at hd + rw [he,hh.fderiv] at hd + have hx := congrArg (fun L : Spin N→L[ℝ]ℝ => L z) hd + simpa only [sum_apply,smul_apply,smul_eq_mul, + ContinuousLinearMap.comp_apply,coe_innerSL_apply,bulkCovarianceDerivative,Finset.sum_mul, + real_inner_comm y x,real_inner_comm y z,real_inner_comm (ambientBulkFeature N v y),Nat.cast_add,Nat.cast_one] using hx.symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkAnnealedTangent.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkAnnealedTangent.lean new file mode 100644 index 0000000000000000000000000000000000000000..b616e206581ec7825801c85bcd366342dff90044 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkAnnealedTangent.lean @@ -0,0 +1,164 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkTangentError +import OAI.Probability.Perceptron.Cavity.BulkReplicaDominated + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators BoundedContinuousFunction ContDiff + +lemma bulkReplicaMean_add_dominated (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + {F G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ} + (hF : Measurable (Function.uncurry F)) (hG : Measurable (Function.uncurry G)) + {D E : BulkDisorder (n+1) M→ℝ} + (hD : Integrable D (bulkDisorderLaw (n+1) M)) (hE : Integrable E (bulkDisorderLaw (n+1) M)) + (hD0 : ∀ a,0≤D a) (hE0 : ∀ a,0≤E a) + (hbF : ∀ a x,|F a x|≤D a) (hbG : ∀ a x,|G a x|≤E a) : + bulkReplicaMean n M f v r (fun a x => F a x+G a x)= + bulkReplicaMean n M f v r F+bulkReplicaMean n M f v r G := by + have he (a : BulkDisorder (n+1) M) : + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r (fun x => F a x+G a x)= + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r (F a)+ + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r (G a) := by + let := tilt_law_probability_of_integrable (unitSphereLaw (n+1)) + (show Integrable (fun x => Real.exp (1*bulkHamiltonian (n+1) M f v a.1 a.2 x)) (unitSphereLaw (n+1)) from + by simpa only [one_mul] using bulkHamiltonian_exp_integrable n M f v a) + simp_rw [gibbsReplicaMean_integral_of_integrable (unitSphereLaw (n+1)) + (bulkHamiltonian_section_measurable _ _ _ _ a) (bulkHamiltonian_exp_integrable n M f v a)] + exact integral_add + (Integrable.of_bound hF.of_uncurry_left.aestronglyMeasurable (D a) (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hbF a x)) + (Integrable.of_bound hG.of_uncurry_left.aestronglyMeasurable (E a) (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hbG a x)) + unfold bulkReplicaMean + simp_rw [he] + exact integral_add + (replicaMean_param_integrable_dominated _ _ r (bulkHamiltonian_continuous _ _ _ _).measurable hF hD hD0 hbF) + (replicaMean_param_integrable_dominated _ _ r (bulkHamiltonian_continuous _ _ _ _).measurable hG hE hE0 hbG) + +lemma bulkTangentDirection_bounded (N : ℕ) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) : + ∃ D : ℝ,0≤D ∧ ∀ x,‖bulkTangentDirection N v G x‖≤D := by + obtain ⟨D,hD⟩ := (isCompact_univ : IsCompact (univ : Set (Fin 2→NormalizedSpin N))).bddAbove_image + (bulkTangentDirection_continuous N v G).norm.continuousOn + exact ⟨max D 0,le_max_right _ _,fun x => (hD (mem_image_of_mem _ (mem_univ x))).trans (le_max_left _ _)⟩ + +def bulkTangentPerturbation {N M : ℕ} (v : ℕ→ℝ) (G : ℝ→ᵇℝ) + (a : BulkDisorder N M) (x : Fin 2→NormalizedSpin N) : ℝ := + inner ℝ (bulkTangentDirection N v G x) a.2 + +lemma bulkTangentPerturbation_measurable (N M : ℕ) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) : + Measurable (Function.uncurry (bulkTangentPerturbation (N:=N) (M:=M) v G)) := + (((bulkTangentDirection_continuous N v G).comp continuous_snd).inner continuous_fst.snd).measurable + +lemma bulkTangentPerturbation_bound {N M : ℕ} (v : ℕ→ℝ) (G : ℝ→ᵇℝ) + {D : ℝ} (hb : ∀ x,‖bulkTangentDirection N v G x‖≤D) + (a : BulkDisorder N M) (x : Fin 2→NormalizedSpin N) : + |bulkTangentPerturbation v G a x|≤D*‖a.2‖ := + (abs_real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right (hb x) (norm_nonneg _)) + +lemma bulkMarkNorm_integrable (N M : ℕ) : + Integrable (fun a : BulkDisorder N M => ‖a.2‖) (bulkDisorderLaw N M) := + ((((IsGaussian.memLp_id (stdGaussian (BulkMark N)) 2 (by simp)).norm).integrable (by norm_num))).comp_snd _ + +lemma bulkTangentPerturbation_integrable (n M : ℕ) (f G : ℝ→ᵇℝ) (v : ℕ→ℝ) : + Integrable (fun a : BulkDisorder (n+1) M => gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) 2 (bulkTangentPerturbation v G a)) (bulkDisorderLaw (n+1) M) := by + obtain ⟨D,hD,hb⟩ := bulkTangentDirection_bounded (n+1) v G + exact replicaMean_param_integrable_dominated _ _ 2 (bulkHamiltonian_continuous _ _ _ _).measurable + (bulkTangentPerturbation_measurable _ _ _ _) ((bulkMarkNorm_integrable (n+1) M).const_mul D) + (fun a => mul_nonneg hD (norm_nonneg _)) (bulkTangentPerturbation_bound v G hb) + +lemma bulk_tangent_annealed_perturbation_bound (n M : ℕ) (f G : ℝ→ᵇℝ) (v : ℕ→ℝ) + {C : ℝ} (hC : 0≤C) (hv : ∀ j,|v (j+1)|≤C) : + |bulkReplicaMean n M f v 2 (bulkTangentPerturbation v G)|≤8*‖G‖*C^2*bulkScale (n+1)^2 := by + unfold bulkReplicaMean + rw [show bulkDisorderLaw (n+1) M = + (Measure.pi fun _ : Fin M => Measure.pi fun _ : Fin (n+1) => gaussianReal 0 1).prod (stdGaussian (BulkMark (n+1))) from rfl] + rw [integral_prod _ (bulkTangentPerturbation_integrable n M f G v)] + have hb : ∀ a : Fin M→Fin (n+1)→ℝ, + ‖∫ b : BulkMark (n+1), gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a b) 2 (bulkTangentPerturbation v G (a,b)) + ∂stdGaussian (BulkMark (n+1))‖≤8*‖G‖*C^2*bulkScale (n+1)^2 := by + intro a + rw [Real.norm_eq_abs] + change |∫ b : BulkMark (n+1), gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a b) 2 (fun x => inner ℝ (bulkTangentDirection (n+1) v G x) b) + ∂stdGaussian (BulkMark (n+1))|≤_ + exact bulk_tangent_perturbation_bound n M f G v a hC hv + simpa only [Real.norm_eq_abs,Measure.real,measure_univ,ENNReal.toReal_one,mul_one] using + norm_integral_le_of_norm_le_const (ae_of_all (Measure.pi fun _ : Fin M => Measure.pi fun _ : Fin (n+1) => gaussianReal 0 1) hb) + +lemma continuous_real_compact_bound {X : Type*} [TopologicalSpace X] [CompactSpace X] + {F : X→ℝ} (hF : Continuous F) : ∃ D : ℝ,0≤D ∧ ∀ x,|F x|≤D := by + obtain ⟨D,hD⟩ := (isCompact_univ : IsCompact (univ : Set X)).bddAbove_image hF.abs.continuousOn + exact ⟨max D 0,le_max_right _ _,fun x => (hD (mem_image_of_mem _ (mem_univ x))).trans (le_max_left _ _)⟩ + +def tangentDerivTest (N : ℕ) (G : ℝ→ᵇℝ) (x : Fin 2→NormalizedSpin N) : ℝ := + deriv (G : ℝ→ℝ) (spinOverlap (x 0) (x 1))*(1-spinOverlap (x 0) (x 1)^2) + +lemma tangentDerivTest_continuous (N : ℕ) (G : ℝ→ᵇℝ) (hG : ContDiff ℝ 1 (G : ℝ→ℝ)) : + Continuous (tangentDerivTest N G) := by + have hr : Continuous (fun x : Fin 2→NormalizedSpin N => spinOverlap (x 0) (x 1)) := by + unfold spinOverlap; fun_prop + exact ((hG.continuous_deriv (by norm_num)).comp hr).mul (continuous_const.sub (hr.pow 2)) + +lemma bulk_tangent_row_ibp_any (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) (j : Fin M) : + bulkReplicaMean n M f.f v 2 (bulkTangentPattern f G j) = + bulkReplicaMean n M f.f v 2 (fun a => freshTangentPair (n+1) f G (WithLp.toLp 2 (a.1 j)))- + 2*bulkReplicaMean n M f.f v 3 (fun a => freshTangentTriple (n+1) f G (WithLp.toLp 2 (a.1 j))) := by + cases M with + | zero => exact Fin.elim0 j + | succ M => exact bulk_tangent_row_ibp n M f v G j + +lemma bulk_tangent_annealed (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) + (hG : ContDiff ℝ 1 (G : ℝ→ℝ)) {C : ℝ} (hC : 0≤C) (hv : ∀ j,|v (j+1)|≤C) : + |(n:ℝ)*bulkReplicaMean n M f.f v 2 (fun _ x => spinOverlap (x 0) (x 1)*G (spinOverlap (x 0) (x 1)))- + bulkReplicaMean n M f.f v 2 (fun _ => tangentDerivTest (n+1) G)- + ∑ j : Fin M, (bulkReplicaMean n M f.f v 2 (fun a => freshTangentPair (n+1) f G (WithLp.toLp 2 (a.1 j)))- + 2*bulkReplicaMean n M f.f v 3 (fun a => freshTangentTriple (n+1) f G (WithLp.toLp 2 (a.1 j))))|≤ + 8*‖G‖*C^2*bulkScale (n+1)^2 := by + let T := fun a : BulkDisorder (n+1) M => fun x : Fin 2→NormalizedSpin (n+1) => ∑ j,bulkTangentPattern f G j a x + let D := fun a : BulkDisorder (n+1) M => ∑ j : Fin M,2*‖G‖*‖f.d1‖*bulkPatternSize j a + have hT : Measurable (Function.uncurry T) := Finset.measurable_sum _ fun j _ => bulkTangentPattern_measurable _ _ _ _ j + have hD : Integrable D (bulkDisorderLaw (n+1) M) := integrable_finsetSum _ fun j _ => + (bulkPatternSize_integrable (n+1) M j).const_mul (2*‖G‖*‖f.d1‖) + have hD0 (a : BulkDisorder (n+1) M) : 0≤D a := by + exact Finset.sum_nonneg fun j _ => mul_nonneg (by positivity) (Finset.sum_nonneg fun i _ => abs_nonneg _) + have hbT (a : BulkDisorder (n+1) M) (x : Fin 2→NormalizedSpin (n+1)) : |T a x|≤D a := + (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum fun j _ => bulkTangentPattern_bound f G j a x) + obtain ⟨E,hE,hbE⟩ := continuous_real_compact_bound (tangentDerivTest_continuous (n+1) G hG) + have hEme : Measurable (Function.uncurry (fun _ : BulkDisorder (n+1) M => tangentDerivTest (n+1) G)) := + (tangentDerivTest_continuous (n+1) G hG).measurable.comp measurable_snd + obtain ⟨K,hK,hbK⟩ := bulkTangentDirection_bounded (n+1) v G + have hP := bulkTangentPerturbation_measurable (n+1) M v G + have hbP := bulkTangentPerturbation_bound (M:=M) v G hbK + have hiP := (bulkMarkNorm_integrable (n+1) M).const_mul K + have he : (n:ℝ)*bulkReplicaMean n M f.f v 2 (fun _ x => spinOverlap (x 0) (x 1)*G (spinOverlap (x 0) (x 1)))= + bulkReplicaMean n M f.f v 2 (fun a x => tangentDerivTest (n+1) G x+T a x+bulkTangentPerturbation v G a x) := by + unfold bulkReplicaMean + rw [←integral_const_mul] + exact integral_congr_ae (ae_of_all _ fun a => bulk_gibbs_replica_tangent n M f v a.1 a.2 G hG) + have hET : Measurable (Function.uncurry (fun a x => tangentDerivTest (n+1) G x+T a x)) := hEme.add hT + have hadd := bulkReplicaMean_add_dominated n M 2 f.f v hET hP + ((integrable_const E).add hD) hiP (fun a => add_nonneg hE (hD0 a)) (fun a => mul_nonneg hK (norm_nonneg _)) + (fun a x => (abs_add_le _ _).trans (add_le_add (hbE x) (hbT a x))) hbP + have hadd' := bulkReplicaMean_add_dominated n M 2 f.f v hEme hT (integrable_const E) hD + (fun _ => hE) hD0 (fun _ x => hbE x) hbT + rw [he,hadd,hadd'] + have hsum : bulkReplicaMean n M f.f v 2 T=∑ j : Fin M,bulkReplicaMean n M f.f v 2 (bulkTangentPattern f G j) := + bulkReplicaMean_sum_dominated n M 2 f.f v Finset.univ _ + (fun j _ => bulkTangentPattern_measurable _ _ _ _ j) + (fun j a => 2*‖G‖*‖f.d1‖*bulkPatternSize j a) + (fun j _ => (bulkPatternSize_integrable (n+1) M j).const_mul (2*‖G‖*‖f.d1‖)) + (fun j _ a => mul_nonneg (by positivity) (Finset.sum_nonneg fun i _ => abs_nonneg _)) + (fun j _ => bulkTangentPattern_bound f G j) + rw [hsum] + simp_rw [bulk_tangent_row_ibp_any n M f v G] + convert bulk_tangent_annealed_perturbation_bound n M f.f G v hC hv using 1 + congr 1 + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkCavityData.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkCavityData.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d275d9a981db63300f818dea8780fb3e62ea04c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkCavityData.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityRoundedLower + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators NNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +structure BulkCavityData (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (α K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) where + a : ℝ + c : ℝ + a_nonneg : 0≤a + a_le_K : a≤K + a_le : a≤α*‖g.d1‖^2 + c_bound : |c|≤α*‖g.dilationMark hg‖ + a_L2 : Tendsto (fun j=>bulkReplicaMean (s j) (M (s j)+2) g.f (v (s j)) 1 + (fun b x=>(bulkB (s j+1) (M (s j)+2) g b.1 (x 0) (x 0)-a)^2)) atTop (𝓝 0) + c_L2 : Tendsto (fun j=>bulkReplicaMean (s j) (M (s j)+2) g.f (v (s j)) 1 + (fun b x=>(bulkC (s j+1) (M (s j)+2) g b.1 (x 0)-c)^2)) atTop (𝓝 0) + support : ∀ᵐ r : Time ∂markedTimePair K μ,(r:ℝ)≤(α*‖g.d1‖^2)/(1+α*‖g.d1‖^2) + field_bound : ∀ᵐ r : Time ∂markedTimePair K μ, + cappedA (markedTimePair K μ) ((α*‖g.d1‖^2)/(1+α*‖g.d1‖^2)) r≤a + radial : (c+a)/2=cavityProfileMoment (markedTimePair K μ) ((α*‖g.d1‖^2)/(1+α*‖g.d1‖^2)) + capped : ∀ n d (Λ : ℝ) (hΛ : 1≤Λ), + Tendsto (fun j=>cavityBulkLog n d (s j) (M (s j)+2) g (v (s j)) Λ hΛ- + roundedCavityLog n d g.f Λ hΛ (markedTimePair K μ) + ((α*‖g.d1‖^2)/(1+α*‖g.d1‖^2)) a_nonneg a_le_K j) atTop (𝓝 0) + +theorem bulk_cavity_data (M : ℕ→ℕ) (g : Jet3) (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) + (v : ℕ→ℕ→ℝ) (hv : ∀ n p,1≤v n p) {C : ℝ} (hC : 0≤C) (hvC : ∀ n p,|v n (p+1)|≤C) + (hdO : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n) g.f p (v n)) atTop (𝓝 0)) + (hdF : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n+2) g.f p (v n)) atTop (𝓝 0)) + (s : ℕ→ℕ) (hs : StrictMono s) (α : ℝ) (hα : 0≤α) + (hd : Tendsto (fun n=>((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (ho : Tendsto (fun n=>bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (K : ℝ) (hK0 : 0≤K) (hK : ∀ n,((M n+2:ℕ):ℝ)/(n+1:ℕ)*‖g.d1‖^2≤K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hf : Tendsto (fun n=>bulkMarkedArrayLaw (s n) (M (s n)+2) g (v (s n)) K (hK (s n))) atTop (𝓝 μ)) : + Nonempty (BulkCavityData M g v s α K μ hg) := by + have hOm:=bulk_limit_geometry M g.f v (Eventually.of_forall hv) hdO hs ho + obtain ⟨⟨a,ha,hLa⟩,⟨c,hc,hLc⟩⟩:=bulk_diagonal_C_concentration M g hg v s hs.tendsto_atTop α hd ho + hOm.2.2 hOm.1 hOm.2.1 + rw [abs_of_nonneg hα] at ha hc + have hD2:=bulkMarkedArray_limit_diagonal_const (fun n=>M n+2) g v s K (fun j=>hK (s j)) μ hf a hLa + have hmg:=bulkMarkedArray_limit_mark_geometry (fun n=>M n+2) g v s K (fun j=>hK (s j)) hf + obtain ⟨Q,hQ,hpos⟩:=(hD2.and hmg.1).exists + have ha0 : 0≤a:=by simpa only [hQ 0] using hpos 0 + have haK : a≤K:=by simpa only [hQ 0] using (Q 0 0).2.prop.2 + have haA : a≤α*‖g.d1‖^2:=(le_abs_self a).trans ha + have hBd : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,(Q i j).2.val≤a := by + filter_upwards [hD2,hmg.2] with Q hD hG + intro i j + have h:=hG i j + rw [hD i,hD j] at h + linarith + obtain ⟨f,_hfm,hfb,hfg,hsc,hbound⟩:=bulk_marked_self_consistency M g v hv hC hvC hdO hdF s hs α hα hd ν ho + K hK0 (fun j=>hK (s j)) μ hf + let η:=markedTimePair K μ + let B:=(α*‖g.d1‖^2)/(1+α*‖g.d1‖^2) + have hA0 : 0≤α*‖g.d1‖^2:=mul_nonneg hα (sq_nonneg _) + have hB : B<1:=(div_lt_one (by linarith : 0<1+α*‖g.d1‖^2)).mpr (by linarith) + have he e:=compact_exchangeability_limit hf e + (fun j=>bulkMarkedArray_exchangeable (s j) (M (s j)+2) g (v (s j)) K (hK (s j)) e) + have hp:=bulkMarkedArray_limit_overlap (fun n=>M n+2) g v s K (fun j=>hK (s j)) hf + have hgF:=bulk_limit_geometry (fun n=>M n+2) g.f v (Eventually.of_forall hv) hdF hs hp + have hgeom:=marked_overlap_geometry K μ he hgF.1 hgF.2.1 + have hm:=marked_cappedA_identification μ hB (hgeom.2.2.mono fun _array hQ=>hQ 0 1) + (hBd.mono fun _array hQ=>hQ 0 1) f (hfg.mono fun _array hQ=>hQ 0 1 (by omega)) hsc hbound + have hrad : (c+a)/2=cavityProfileMoment η B := by + have ht:=ProbabilityMeasure.tendsto_map_of_tendsto_of_continuous _ _ hf + (by fun_prop : Continuous (fun Q : CompactArray (BulkPairRange K)=>Q 1 0)) + simp_rw [bulkMarkedArray_pair] at ht + have hr:=bulk_radial_limit_relation s (fun j=>M (s j)+2) g hg (fun j=>v (s j)) c a hLc hLa K + (fun j=>hK (s j)) _ ht + rw [ProbabilityMeasure.toMeasure_map,integral_map (by fun_prop : Measurable + (fun Q : CompactArray (BulkPairRange K)=>Q 1 0)).aemeasurable (by fun_prop)] at hr + have hs:=integral_map (he (Equiv.swap 0 1)).measurable.aemeasurable + (show AEStronglyMeasurable (fun Q : CompactArray (BulkPairRange K)=>(Q 0 1).1.val*(Q 0 1).2.val) + ((μ : Measure _).map (compactRelabel (Equiv.swap 0 1))) from by fun_prop) + rw [(he (Equiv.swap 0 1)).map_eq] at hs + simp only [compactRelabel,Equiv.swap_apply_left,Equiv.swap_apply_right] at hs + rw [hm.2,hr,hs] + have hD1:=ae_of_ae_map (compactMapArray_continuous (show Continuous + (Prod.fst : BulkPairRange K → CompactOverlap) from continuous_fst)).measurable.aemeasurable + (bulkGibbsArray_limit_diagonal g.f (fun n=>M n+2) v s hp) + have hgraph:=marked_graph_law μ hB ha0 haK he hgeom.2.2 hD1 hD2 hBd f + (fun r=>(hfb r).1) hfg hsc hbound + obtain ⟨hGG,hGe,hEx⟩:=bulk_marked_time_inputs (fun n=>M n+2) g v (Eventually.of_forall hv) hdF s hs K + (fun j=>hK (s j)) μ hf + let q:=boundedQuantile η + let hq:=boundedQuantile_monotone η + let F:=unitQuantileField q hq + have hpair : (markedTimeLaw K μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1)=timeLaw.map q := + (boundedQuantile_law η).symm + have hrpc:=cavityLabelMarkedLaw_tendsto_graph (markedTimeLaw K μ) q hq hpair hGG hGe hEx + (continuousCavityProfile η B ha0 haK) (continuousCavityProfile_continuous η hB ha0 haK) + (cavityTrueDiagonal ha0 haK) + rw [hgraph] at hrpc + refine ⟨⟨a,c,ha0,haK,haA,hc,hLa,hLc,hbound,hm.1,hrad,?_⟩⟩ + intro n d Λ hΛ + have hprof j:=roundedCavityPair_conditions n d η hB ha0 haK j + exact cavity_joint_array_recursion_limit n d (fun m=>M m+2) g v Λ hΛ K hK s hf + (fun j=>(strictRoundModel F j).depth) (roundedCavityPair η B ha0 haK) + (fun _=>cavityTrueDiagonal ha0 haK) (fun j=>stepCumulative (strictRoundModel F j).weight) + (fun j=>(hprof j).1) (fun j=>(hprof j).2.1) (fun j=>(hprof j).2.2) + (fun j=>stepCumulative_strictMono _ (strictRoundModel F j).weight_pos) + (fun j=>stepCumulative_pos _ (strictRoundModel F j).weight_pos) + (fun j=>stepCumulative_lt_one _ (strictRoundModel F j).weight_pos (strictRoundModel F j).weight_sum) hrpc +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkCavityRecursion.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkCavityRecursion.lean new file mode 100644 index 0000000000000000000000000000000000000000..cbfdfd7b5752f1459c38e2861a2b09dfa8b11578 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkCavityRecursion.lean @@ -0,0 +1,139 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityFullEvaluation +import OAI.Probability.Perceptron.Cascade.BulkRPCCoupling + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def roundedCavityPair (η : Measure Time) [IsProbabilityMeasure η] (B : ℝ) + {K a : ℝ} (ha0 : 0 ≤ a) (haK : a ≤ K) (j : ℕ) : + Fin ((strictRoundModel (unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η)) j).depth+1) → BulkPairRange K := + fun i => continuousCavityProfile η B ha0 haK + (roundTimeValue (unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η)) j i) + +lemma roundedCavityPair_conditions (n d : ℕ) (η : Measure Time) [IsProbabilityMeasure η] + {B K a : ℝ} (hB : B < 1) (ha0 : 0 ≤ a) (haK : a ≤ K) (j : ℕ) : + (∀ i, 0 ≤ cavityPairProfile n d (roundedCavityPair η B ha0 haK j) 0 i) ∧ + (∀ i, Monotone (fun l => cavityPairProfile n d (roundedCavityPair η B ha0 haK j) l i)) ∧ + (∀ i, cavityPairProfile n d (roundedCavityPair η B ha0 haK j) + (Fin.last _) i ≤ cavityPairDiagonal n d (cavityTrueDiagonal ha0 haK) i) := by + have h0 := fun l => continuousCavityProfile_nonneg η B ha0 haK + (roundTimeValue (unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η)) j l) + have hD := fun l => continuousCavityProfile_le_diagonal η B ha0 haK + (roundTimeValue (unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η)) j l) + refine ⟨?_,?_,?_⟩ + · intro i; cases i with + | inl i => exact (h0 0).2 + | inr i => exact (h0 0).1 + · intro i; cases i with + | inl i => exact (continuousCavityProfile_mono η hB ha0 haK).comp (roundTimeValue_mono _ j) + | inr i => exact fun l m h => roundTimeValue_mono _ j h + · intro i; cases i with + | inl i => exact (hD (Fin.last _)).2 + | inr i => exact (hD (Fin.last _)).1 + +def roundedCavityLog (n d : ℕ) (f : ℝ →ᵇ ℝ) (Λ : ℝ) (hΛ : 1 ≤ Λ) + (η : Measure Time) [IsProbabilityMeasure η] (B : ℝ) {K a : ℝ} + (ha0 : 0 ≤ a) (haK : a ≤ K) (j : ℕ) : ℝ := + let F := unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + let k := (strictRoundModel F j).depth + let p := roundedCavityPair η B ha0 haK j + let D := cavityTrueDiagonal ha0 haK + ∫ y,finiteCascadeLogRecursion (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + (gaussianLinearMarkStep (fun l=>diagonalMark (profileGaussianStep (cavityPairProfile n d p) l))) k + (stepCumulative (strictRoundModel F j).weight) + (fun t=>Real.log (cavityDiagonalAverage + (fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i)) + (cavitySingleTest n d f Λ hΛ) (t 0))) + (fun _=>diagonalMark (profileGaussianRoot (cavityPairProfile n d p)) y) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) + +theorem bulk_cavity_rounded_recursion (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) + (hv : ∀ n p,1≤v n p) {C : ℝ} (hC : 0≤C) (hvC : ∀ n p,|v n (p+1)|≤C) + (hdO : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n) g.f p (v n)) atTop (𝓝 0)) + (hdF : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n+2) g.f p (v n)) atTop (𝓝 0)) + (s : ℕ→ℕ) (hs : StrictMono s) (α : ℝ) (hα : 0≤α) + (hd : Tendsto (fun n=>((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (ho : Tendsto (fun n=>bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (K : ℝ) (hK0 : 0≤K) (hK : ∀ n,((M n+2:ℕ):ℝ)/(n+1:ℕ)*‖g.d1‖^2≤K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hf : Tendsto (fun n=>bulkMarkedArrayLaw (s n) (M (s n)+2) g (v (s n)) K (hK (s n))) atTop (𝓝 μ)) : + ∃ a : ℝ, ∃ ha0 : 0 ≤ a, ∃ haK : a ≤ K, a ≤ α*‖g.d1‖^2 ∧ + ∀ n d (Λ : ℝ) (hΛ : 1 ≤ Λ), + Tendsto (fun j => cavityBulkLog n d (s j) (M (s j)+2) g (v (s j)) Λ hΛ - + roundedCavityLog n d g.f Λ hΛ (markedTimePair K μ) + ((α*‖g.d1‖^2)/(1+α*‖g.d1‖^2)) ha0 haK j) atTop (𝓝 0) := by + obtain ⟨a,ha0,haK,haA,hrpc⟩ := bulk_marked_rpc_coupling M g v hv hC hvC hdO hdF s hs + α hα hd ν ho K hK0 (fun j => hK (s j)) μ hf + refine ⟨a,ha0,haK,haA,?_⟩ + intro n d Λ hΛ + let η := markedTimePair K μ + let F := unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + let B := (α*‖g.d1‖^2)/(1+α*‖g.d1‖^2) + have hA := mul_nonneg hα (sq_nonneg ‖g.d1‖) + have hB : B < 1 := (div_lt_one (by linarith : 0 < 1+α*‖g.d1‖^2)).mpr (by linarith) + have hp j := roundedCavityPair_conditions n d η hB ha0 haK j + exact cavity_joint_array_recursion_limit n d (fun m => M m+2) g v Λ hΛ K hK s hf + (fun j => (strictRoundModel F j).depth) (roundedCavityPair η B ha0 haK) + (fun _ => cavityTrueDiagonal ha0 haK) (fun j => stepCumulative (strictRoundModel F j).weight) + (fun j => (hp j).1) (fun j => (hp j).2.1) (fun j => (hp j).2.2) + (fun j => stepCumulative_strictMono _ (strictRoundModel F j).weight_pos) + (fun j => stepCumulative_pos _ (strictRoundModel F j).weight_pos) + (fun j => stepCumulative_lt_one _ (strictRoundModel F j).weight_pos (strictRoundModel F j).weight_sum) hrpc + + + +def roundedCavityValue (n d : ℕ) (g : Jet3) (P : Measure BrownianPath) + (η : Measure Time) [IsProbabilityMeasure η] (B : ℝ) {K a : ℝ} + (ha0 : 0≤a) (haK : a≤K) (j : ℕ) : ℝ := + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + let M:=strictRoundModel F j + (n+1:ℕ)*(a/2+finiteSphericalFieldValue n M.depth M.weight + (fun l=>(roundedCavityPair η B ha0 haK j l).2.val/2))+ + d*controlValue P g.f (weightedStepTrial M.weight (roundTimeValue F j) + (fun l=>(M.weight_pos l).le) M.weight_sum) + +theorem roundedCavity_uncap (n d : ℕ) (g : Jet3) (P : Measure BrownianPath) + [IsProbabilityMeasure P] (hBrow : IsBrownianReal brownianEval P) + (η : Measure Time) [IsProbabilityMeasure η] {B K a : ℝ} (hB : B<1) + (ha0 : 0≤a) (haK : a≤K) (j : ℕ) {Λ : ℝ} (hΛ : 1≤Λ) : + 0≤roundedCavityValue n d g P η B ha0 haK j-roundedCavityLog n d g.f Λ hΛ η B ha0 haK j ∧ + roundedCavityValue n d g P η B ha0 haK j-roundedCavityLog n d g.f Λ hΛ η B ha0 haK j≤ + Real.exp (2*((d:ℝ)*‖g.f‖))/Λ*Real.exp (2*(n+1:ℕ)*a) := by + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + let M:=strictRoundModel F j + let p:=roundedCavityPair η B ha0 haK j + let D:=cavityTrueDiagonal ha0 haK + let Q:=cavityPairProfile n d p + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-Q (Fin.last M.depth) i) + let z:=stepCumulative M.weight + have hp:=roundedCavityPair_conditions n d η hB ha0 haK j + have hfull:=cavityLabel_full_value n d p D hp.1 hp.2.1 hp.2.2 + (roundTimeValue F j) (fun l=>rfl) rfl M.weight M.weight_pos M.weight_sum + (roundTimeValue_mono F j) g P hBrow + have hcap:=cavityLabelPartitionLaw_log_recursion n d M.depth g.f Λ hΛ σ Q z + (stepCumulative_strictMono M.weight M.weight_pos) + (stepCumulative_pos M.weight M.weight_pos) + (stepCumulative_lt_one M.weight M.weight_pos M.weight_sum) + rw [cavityLabelPartitionLaw_integral _ _ _ _ _ _ _ _ _ Real.log Real.measurable_log] at hcap + have he:=cavityLabel_uncap_annealed n d p D hp.1 hp.2.1 hp.2.2 g.f z hΛ + have hi:=cavityLabel_full_log_integrable n d p D hp.1 hp.2.1 hp.2.2 g.f z + have hc:=cavityLabel_capped_log_integrable n d M.depth g.f Λ hΛ σ Q z + have hint : (∫ t,Real.log (cavityLabelFullPartition n d M.depth g.f σ Q t)- + Real.log (cavityLabelPartition n d M.depth g.f Λ hΛ σ Q t) + ∂(indexedCascadeBaseLaw M.depth z : Measure (IndexedCascadeBase M.depth)).prod countableGaussianLaw)= + roundedCavityValue n d g P η B ha0 haK j-roundedCavityLog n d g.f Λ hΛ η B ha0 haK j := by + rw [integral_sub hi hc,hfull,hcap] + rfl + change _ ∧ _ at he + exact ⟨by rw [←hint]; exact he.2.1,by rw [←hint]; exact he.2.2⟩ +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkCompactGG.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkCompactGG.lean new file mode 100644 index 0000000000000000000000000000000000000000..c9744939dc5b3abc6208805404f83768c63b97ac --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkCompactGG.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkGoodParameters +import OAI.Probability.Perceptron.Variational.CompactScalarGG + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma bulkOverlap_continuous (N : ℕ) : Continuous (Function.uncurry (bulkOverlap (N:=N))) := by + apply Continuous.subtype_mk + exact continuous_fst.subtype_val.inner continuous_snd.subtype_val + +lemma bulkBlockTest_measurable (N r : ℕ) (F : CompactBlock CompactOverlap r →ᵇ ℝ) : + Measurable (fun x : Fin r→NormalizedSpin N => F (fun i j => bulkOverlap (x i) (x j))) := by + apply F.continuous.measurable.comp + refine Measurable.of_eval fun first => Measurable.of_eval fun second => ?_ + have hm : Measurable (fun x : Fin r → NormalizedSpin N => (x first, x second)) := + (measurable_pi_apply first).prodMk (measurable_pi_apply second) + exact (bulkOverlap_measurable N).comp hm + +lemma bulk_compact_gg_defect (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p r : ℕ) (j : Fin r) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) : + compactGGDefect (bulkGibbsArrayLaw n M f v) r j F (compactScalarMonomial p) = + -bulkGGDefect n M f v p r j (fun x => F (fun i l => bulkOverlap (x i) (x l))) := by + have hh := compactGGDefect_gibbsOverlapArray (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (fun a x => bulkHamiltonian (n+1) M f v a.1 a.2 x) + (bulkHamiltonian_continuous _ _ _ _).measurable bulkOverlap (bulkOverlap_measurable (n+1)) + (ae_of_all _ (bulkHamiltonian_exp_integrable n M f v)) r j F (compactScalarMonomial p) 1 + (fun x => by simp only [compactScalarMonomial_apply,bulkOverlap,spinOverlap_self,one_pow]) + (fun x y => by simp only [compactScalarMonomial_apply,bulkOverlap,spinOverlap,real_inner_comm]) + simpa only [bulkGibbsArrayLaw,kernelGGDefect,bulkGGDefect,bulkMoment,bulkSpinKernel, + Kernel.const_apply,compactScalarMonomial_apply,bulkOverlap,one_mul] using hh + +lemma bulk_compact_gg_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (hv : 1≤v (p.val+1)) : + |compactGGDefect (bulkGibbsArrayLaw n M f v) r j F (compactScalarMonomial (p.val+1))| ≤ + ‖F‖/(2:ℝ)^(-((p.val+1:ℕ):ℤ))*bulkNormalizedDeviation n M f p v := by + rw [bulk_compact_gg_defect,abs_neg] + exact bulkGG_bound n M f v p r j (bulkBlockTest_measurable (n+1) r F) (norm_nonneg _) + (fun x => by simpa only [Real.norm_eq_abs] using F.norm_coe_le_norm (fun i l => bulkOverlap (x i) (x l))) hv + +lemma omitted_bulk_monomial_tendsto (α : ℝ) (f : ℝ→ᵇℝ) (v : ℕ→ℕ→ℝ) + (hv : ∀ᶠ n in atTop, ∀ p, 1≤v n p) + (hd : ∀ p, Tendsto (fun n => omittedBulkDeviation α f n p (v n)) atTop (𝓝 0)) + (p r : ℕ) (j : Fin r) (F : CompactBlock CompactOverlap r →ᵇ ℝ) : + Tendsto (fun n => compactGGDefect (bulkGibbsArrayLaw n (patternCount α (n+1)-2) f (v n)) + r j F (compactScalarMonomial (p+1))) atTop (𝓝 0) := by + apply squeeze_zero_norm' (a:=fun n => ‖F‖/(2:ℝ)^(-((p+1:ℕ):ℤ))*omittedBulkDeviation α f n p (v n)) + · filter_upwards [hv,eventually_ge_atTop p] with n hn hp + have hpn : p omittedBulkDeviation α f n p (v n)) atTop (𝓝 0)) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} {s : ℕ→ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (patternCount α (s n+1)-2) f (v (s n))) atTop (𝓝 ν)) + (r : ℕ) (j : Fin r) (F : CompactBlock CompactOverlap r →ᵇ ℝ) (g : CompactOverlap →ᵇ ℝ) : + compactGGDefect ν r j F g=0 := by + apply compactGG_of_scalar_monomials + intro p + cases p with + | zero => exact compactScalarGG_zero ν r j F + | succ p => + apply compactGGDefect_limit hlim + exact (omitted_bulk_monomial_tendsto α f v hv hd p r j F).comp hs.tendsto_atTop + + +lemma bulk_monomial_tendsto (M : ℕ→ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℕ→ℝ) + (hv : ∀ᶠ n in atTop, ∀ p, 1≤v n p) + (hd : ∀ p, Tendsto (fun n => bulkDeviationAt n (M n) f p (v n)) atTop (𝓝 0)) + (p r : ℕ) (j : Fin r) (F : CompactBlock CompactOverlap r →ᵇ ℝ) : + Tendsto (fun n => compactGGDefect (bulkGibbsArrayLaw n (M n) f (v n)) + r j F (compactScalarMonomial (p+1))) atTop (𝓝 0) := by + apply squeeze_zero_norm' (a:=fun n => ‖F‖/(2:ℝ)^(-((p+1:ℕ):ℤ))*bulkDeviationAt n (M n) f p (v n)) + · filter_upwards [hv,eventually_ge_atTop p] with n hn hp + have hpn : p bulkDeviationAt n (M n) f p (v n)) atTop (𝓝 0)) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} {s : ℕ→ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) f (v (s n))) atTop (𝓝 ν)) + (r : ℕ) (j : Fin r) (F : CompactBlock CompactOverlap r →ᵇ ℝ) (g : CompactOverlap →ᵇ ℝ) : + compactGGDefect ν r j F g=0 := by + apply compactGG_of_scalar_monomials + intro p + cases p with + | zero => exact compactScalarGG_zero ν r j F + | succ p => + apply compactGGDefect_limit hlim + exact (bulk_monomial_tendsto M f v hv hd p r j F).comp hs.tendsto_atTop + +def bulkJointDeviation (α : ℝ) (f : ℝ→ᵇℝ) (n p : ℕ) (v : ℕ→ℝ) : ℝ := + bulkDeviationAt n (patternCount α (n+1)) f p v + omittedBulkDeviation α f n p v + +lemma bulkJointDeviation_nonneg (α : ℝ) (f : ℝ→ᵇℝ) (n p : ℕ) (v : ℕ→ℝ) : + 0≤bulkJointDeviation α f n p v := + add_nonneg (bulkDeviationAt_nonneg _ _ _ _ _) (bulkDeviationAt_nonneg _ _ _ _ _) +lemma bulkJointDeviation_measurable (α : ℝ) (f : ℝ→ᵇℝ) (n p : ℕ) : + Measurable (bulkJointDeviation α f n p) := + (bulkDeviationAt_measurable _ _ _ _).add (bulkDeviationAt_measurable _ _ _ _) +lemma bulkJointDeviation_integrable (α : ℝ) (f : ℝ→ᵇℝ) (n p : ℕ) : + Integrable (bulkJointDeviation α f n p) bulkParameterLaw := + (bulkDeviationAt_integrable _ _ _ _).add (bulkDeviationAt_integrable _ _ _ _) + +lemma bulkJointDeviation_integral_tendsto {α : ℝ} (hα : 0≤α) (f : ℝ→ᵇℝ) (p : ℕ) : + Tendsto (fun n => ∫ v, bulkJointDeviation α f n p v ∂bulkParameterLaw) atTop (𝓝 0) := by + have h₁ := bulkDeviationAt_integral_tendsto (fun n => patternCount α (n+1)) f hα + (fun n => Nat.floor_le (mul_nonneg hα (Nat.cast_nonneg _))) p + have h₂ := omittedBulkDeviation_integral_tendsto hα f p + have he (n : ℕ) : (∫ v, bulkJointDeviation α f n p v ∂bulkParameterLaw) = + (∫ v, bulkDeviationAt n (patternCount α (n+1)) f p v ∂bulkParameterLaw) + + ∫ v, omittedBulkDeviation α f n p v ∂bulkParameterLaw := + integral_add (bulkDeviationAt_integrable _ _ _ _) (bulkDeviationAt_integrable _ _ _ _) + simp_rw [he] + simpa only [add_zero] using h₁.add h₂ + +def bulkJointGoodSet (α : ℝ) (f : ℝ→ᵇℝ) (J : ℕ→ℕ) (n : ℕ) : Set (ℕ→ℝ) := + diagonalGoodSet bulkParameterLaw (bulkJointDeviation α f) J n ∩ {v | ∀ p, v p∈Icc (1:ℝ) 2} + +lemma bulkJointGoodSet_measurable (α : ℝ) (f : ℝ→ᵇℝ) (J : ℕ→ℕ) (n : ℕ) : + MeasurableSet (bulkJointGoodSet α f J n) := by + refine (diagonalGoodSet_measurable _ _ (bulkJointDeviation_measurable α f) J n).inter ?_ + simp only [ofPred_forall] + exact MeasurableSet.iInter fun p => (measurable_pi_apply p) measurableSet_Icc + +lemma bulkJointGoodSet_compl_measure (α : ℝ) (f : ℝ→ᵇℝ) (J : ℕ→ℕ) (n : ℕ) : + bulkParameterLaw.real (bulkJointGoodSet α f J n)ᶜ = + bulkParameterLaw.real (diagonalGoodSet bulkParameterLaw (bulkJointDeviation α f) J n)ᶜ := by + simp only [measureReal_def] + congr 1 + apply measure_congr + filter_upwards [bulkParameterLaw_ae] with v hv + apply propext + change ¬(v∈diagonalGoodSet bulkParameterLaw (bulkJointDeviation α f) J n ∧ ∀ p, v p∈Icc (1:ℝ) 2) ↔ _ + exact not_congr ⟨fun h => h.1, fun h => ⟨h,hv⟩⟩ + +theorem exists_bulkJointGoodParameters {α : ℝ} (hα : 0≤α) (f : ℝ→ᵇℝ) : + ∃ J : ℕ→ℕ, Monotone J ∧ (∀ n, J n≤n) ∧ Tendsto J atTop atTop ∧ + (∀ n, MeasurableSet (bulkJointGoodSet α f J n)) ∧ + Tendsto (fun n => bulkParameterLaw.real (bulkJointGoodSet α f J n)ᶜ) atTop (𝓝 0) ∧ + (∀ v : ℕ→(ℕ→ℝ), (∀ᶠ n in atTop, v n∈bulkJointGoodSet α f J n) → + ∀ p, Tendsto (fun n => bulkDeviationAt n (patternCount α (n+1)) f p (v n)) atTop (𝓝 0) ∧ + Tendsto (fun n => omittedBulkDeviation α f n p (v n)) atTop (𝓝 0)) := by + have hn := bulkJointDeviation_nonneg α f + have hi := bulkJointDeviation_integrable α f + obtain ⟨J,hmon,hbound,hlim,hmass⟩ := exists_slow_diagonal + (fun n p => integral_nonneg (hn n p)) (bulkJointDeviation_integral_tendsto hα f) + refine ⟨J,hmon,hbound,hlim,bulkJointGoodSet_measurable α f J,?_,?_⟩ + · simpa only [bulkJointGoodSet_compl_measure] using + diagonalGoodSet_compl_tendsto bulkParameterLaw (bulkJointDeviation α f) hn hi J hmass + · intro v hv p + have hd := diagonalGoodSet_deviation_tendsto bulkParameterLaw (bulkJointDeviation α f) hn J hlim hmass v + (hv.mono fun n h => h.1) p + constructor + · exact squeeze_zero (fun n => bulkDeviationAt_nonneg _ _ _ _ _) + (fun n => le_add_of_nonneg_right (bulkDeviationAt_nonneg _ _ _ _ _)) hd + · exact squeeze_zero (fun n => bulkDeviationAt_nonneg _ _ _ _ _) + (fun n => le_add_of_nonneg_left (bulkDeviationAt_nonneg _ _ _ _ _)) hd + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkConcentration.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkConcentration.lean new file mode 100644 index 0000000000000000000000000000000000000000..94042ee1491d40d481009be2660848910f68a40e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkConcentration.lean @@ -0,0 +1,183 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkModel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma bulkFeatureBound_sq (N : ℕ) (v : ℕ→ℝ) : + bulkFeatureBound N v^2 = ∑ p, bulkAmplitude N v p^2 := + Real.sq_sqrt (Finset.sum_nonneg fun _ _ => sq_nonneg _) + +lemma bulkFeatureBound_sq_le (N : ℕ) (v : ℕ→ℝ) {C : ℝ} (hC : 0≤C) + (hv : ∀ p, |v (p+1)|≤C) : bulkFeatureBound N v^2 ≤ C^2*bulkScale N^2 := by + rw [bulkFeatureBound_sq] + have hi (p : Fin N) : bulkAmplitude N v p^2 ≤ C^2*bulkScale N^2*(1/2:ℝ)^(p.val+1) := by + let w : ℝ := (1/2:ℝ)^(p.val+1) + have hw0 : 0≤w := pow_nonneg (by norm_num) _ + have hw1 : w≤1 := pow_le_one₀ (by norm_num) (by norm_num) + have hv2 : v (p.val+1)^2 ≤ C^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg (v (p.val+1))) hC).2 (hv p.val) + unfold bulkAmplitude + rw [perturbationWeight_eq] + change (bulkScale N*w*v (p.val+1))^2 ≤ _ + calc + _ ≤ bulkScale N^2*w^2*C^2 := by + rw [mul_pow,mul_pow]; exact mul_le_mul_of_nonneg_left hv2 (by positivity) + _ ≤ C^2*bulkScale N^2*w := by + nlinarith [mul_le_mul_of_nonneg_left (show w^2≤w by nlinarith) (mul_nonneg (sq_nonneg C) (sq_nonneg (bulkScale N)))] + calc + _ ≤ ∑ p : Fin N, C^2*bulkScale N^2*(1/2:ℝ)^(p.val+1) := Finset.sum_le_sum fun p _ => hi p + _ = C^2*bulkScale N^2*(∑ p : Fin N, (1/2:ℝ)^(p.val+1)) := (Finset.mul_sum _ _ _).symm + _ ≤ C^2*bulkScale N^2*1 := mul_le_mul_of_nonneg_left (half_power_sum_le_one N) (by positivity) + _ = _ := mul_one _ + +lemma bulkLogPartition_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + Measurable (fun a : BulkDisorder (n+1) M => bulkLogPartition n M f v a.1 a.2) := by + simp_rw [bulkLogPartition_eq] + change Measurable (fun a : BulkDisorder (n+1) M => Real.log (∫ x, + Real.exp (1*bulkHamiltonian (n+1) M f v a.1 a.2 x) ∂unitSphereLaw (n+1))) + simp only [one_mul] + exact (bulkHamiltonian_continuous (n+1) M f v).measurable.exp.stronglyMeasurable.integral_prod_right'.measurable.log + +lemma bulkLogPartition_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) M) : + |bulkLogPartition n M f v a.1 a.2| ≤ M*‖f‖+bulkFeatureBound (n+1) v*‖a.2‖ := by + apply vectorLogPartition_bound (unitSphereLaw (n+1)) + ((normalizedPatternEnergy_continuous (n+1) M f).measurable.comp (measurable_const.prodMk measurable_id)) + (((innerSL ℝ).continuous.comp (bulkFeature_continuous (n+1) v)).measurable) + (normalizedPatternEnergy_bound (n+1) M f a.1) + intro x + simp only [Function.comp_apply,innerSL_apply_norm,bulkFeature_norm,bulkFeatureBound,le_refl] + +lemma bulkLogPartition_memLp (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + MemLp (fun a : BulkDisorder (n+1) M => bulkLogPartition n M f v a.1 a.2) 2 + (bulkDisorderLaw (n+1) M) := by + have hi : MemLp (id : BulkMark (n+1) → BulkMark (n+1)) 2 (stdGaussian (BulkMark (n+1))) := + IsGaussian.memLp_id (stdGaussian (BulkMark (n+1))) 2 (by simp) + have hn : MemLp (fun g : BulkMark (n+1) => ‖g‖) 2 (stdGaussian (BulkMark (n+1))) := hi.norm + have hc : MemLp (fun _ : BulkMark (n+1) => (M:ℝ)*‖f‖) 2 (stdGaussian (BulkMark (n+1))) := memLp_const _ + have hg : MemLp (fun g : BulkMark (n+1) => M*‖f‖+bulkFeatureBound (n+1) v*‖g‖) 2 + (stdGaussian (BulkMark (n+1))) := hc.add (hn.const_mul (bulkFeatureBound (n+1) v)) + apply (hg.comp_snd (Measure.pi (fun _ : Fin M => Measure.pi (fun _ : Fin (n+1) => gaussianReal 0 1)))).mono' + (bulkLogPartition_measurable n M f v).aestronglyMeasurable + exact ae_of_all _ fun a => by simpa only [Real.norm_eq_abs] using bulkLogPartition_bound n M f v a + +lemma bulkLogPartition_variance (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + variance (fun a : BulkDisorder (n+1) M => bulkLogPartition n M f v a.1 a.2) + (bulkDisorderLaw (n+1) M) ≤ Real.pi^2/8*bulkFeatureBound (n+1) v^2+M*(2*‖f‖)^2 := by + apply vectorLogPartition_mixed_variance (unitSphereLaw (n+1)) + (Measure.pi (fun _ : Fin (n+1) => gaussianReal 0 1)) M + (W := normalizedPatternEnergy (n+1) M f) + (V := fun x => innerSL ℝ (bulkFeature (n+1) v x)) + (normalizedPatternEnergy_continuous (n+1) M f).measurable + (fun x => (normalizedPatternEnergy_continuous (n+1) M f).comp (continuous_id.prodMk continuous_const)) + (((innerSL ℝ).continuous.comp (bulkFeature_continuous (n+1) v)).measurable) + (Real.sqrt_nonneg _) (normalizedPatternEnergy_bound (n+1) M f) + (fun x => by simp only [innerSL_apply_norm,bulkFeature_norm,bulkFeatureBound,le_refl]) + (normalizedPatternEnergy_update (n+1) M f) + + +lemma enrichedFeature_cross_inner (N J : ℕ) (p : Fin J→ℕ) (c d : Fin J→ℝ) + (x y : NormalizedSpin N) : + inner ℝ (enrichedFeature N J p 0 c x) (enrichedFeature N J p 0 d y)= + ∑ j, c j*d j*spinOverlap x y^(p j) := by + change (∑ i : EnrichedIndex N J p, + enrichedFeature N J p 0 d y i * enrichedFeature N J p 0 c x i)=_ + rw [Fintype.sum_sum_type,Fintype.sum_sigma] + simp only [enrichedFeature,zero_mul,Finset.sum_const_zero,zero_add] + apply Finset.sum_congr rfl + intro j _ + rw [← spinTensorFeature_inner N (p j) x y] + change (∑ i, d j*spinTensorFeature N (p j) y i*(c j*spinTensorFeature N (p j) x i))= + c j*d j*(∑ i, spinTensorFeature N (p j) y i*spinTensorFeature N (p j) x i) + rw [Finset.mul_sum] + exact Finset.sum_congr rfl fun _ _ => by ring + +def bulkDirection (N : ℕ) (p : Fin N) : NormalizedSpin N→BulkMark N := + enrichedFeature N N bulkDegree 0 (Pi.single (M := fun _ : Fin N => ℝ) p 1) + +def bulkCoefficient (N : ℕ) (p : Fin N) : ℝ := bulkScale N*(2:ℝ)^(-((p.val+1:ℕ):ℤ)) + +def bulkY (N : ℕ) (p : Fin N) (g : BulkMark N) (x : NormalizedSpin N) : ℝ := + inner ℝ (bulkDirection N p x) g + +lemma bulkDirection_continuous (N : ℕ) (p : Fin N) : Continuous (bulkDirection N p) := + enrichedFeature_continuous _ _ _ _ _ + +lemma bulkDirection_norm (N : ℕ) (p : Fin N) (x : NormalizedSpin N) : ‖bulkDirection N p x‖=1 := by + rw [bulkDirection,enrichedFeature_norm] + have he : (∑ j : Fin N, (Pi.single (M := fun _ : Fin N => ℝ) p (1:ℝ) j)^2)=1 := by + classical + simp [Pi.single_apply] + rw [he] + norm_num + +lemma bulkDirection_inner (N : ℕ) (p : Fin N) (x y : NormalizedSpin N) : + inner ℝ (bulkDirection N p x) (bulkDirection N p y)=spinOverlap x y^(p.val+1) := by + simp only [bulkDirection] + rw [enrichedFeature_cross_inner] + classical + simp [Pi.single_apply,bulkDegree] + +lemma bulkFeature_direction_inner (N : ℕ) (v : ℕ→ℝ) (p : Fin N) (x y : NormalizedSpin N) : + inner ℝ (bulkDirection N p x) (bulkFeature N v y)= + bulkAmplitude N v p*spinOverlap x y^(p.val+1) := by + rw [bulkDirection,bulkFeature,enrichedFeature_cross_inner] + classical + simp [Pi.single_apply,bulkDegree] + +lemma bulkY_bound (N : ℕ) (p : Fin N) (g : BulkMark N) (x : NormalizedSpin N) : |bulkY N p g x|≤‖g‖ := by + exact (abs_real_inner_le_norm _ _).trans_eq (by rw [bulkDirection_norm,one_mul]) + +lemma bulkY_measurable (N : ℕ) (p : Fin N) : Measurable (Function.uncurry (bulkY N p)) := + ((bulkDirection_continuous N p).measurable.comp measurable_snd).inner measurable_fst + +lemma bulkAmplitude_update (N : ℕ) (v : ℕ→ℝ) (p j : Fin N) (u : ℝ) : + bulkAmplitude N (Function.update v (p.val+1) u) j= + bulkAmplitude N (Function.update v (p.val+1) 0) j+u*bulkCoefficient N p*Pi.single (M := fun _ : Fin N => ℝ) p 1 j := by + classical + by_cases hj : j=p + · subst j; simp [bulkAmplitude,bulkCoefficient]; ring + · have h : j.val+1≠p.val+1 := fun h => hj (Fin.ext (Nat.add_right_cancel h)) + simp [bulkAmplitude,Function.update_of_ne h,Pi.single_eq_of_ne hj] + +lemma bulkFeature_update (N : ℕ) (v : ℕ→ℝ) (p : Fin N) (u : ℝ) (x : NormalizedSpin N) : + bulkFeature N (Function.update v (p.val+1) u) x= + bulkFeature N (Function.update v (p.val+1) 0) x+(u*bulkCoefficient N p) • bulkDirection N p x := by + ext i + cases i with + | inl i => simp [bulkFeature,bulkDirection,enrichedFeature] + | inr j => + change bulkAmplitude N (Function.update v (p.val+1) u) j.1*spinTensorFeature N _ x j.2 = + bulkAmplitude N (Function.update v (p.val+1) 0) j.1*spinTensorFeature N _ x j.2 + + (u*bulkCoefficient N p)*(Pi.single (M := fun _ : Fin N => ℝ) p 1 j.1*spinTensorFeature N _ x j.2) + rw [bulkAmplitude_update] + ring + +lemma bulkHamiltonian_update (N M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin N) (u : ℝ) + (a : BulkDisorder N M) (x : NormalizedSpin N) : + bulkHamiltonian N M f (Function.update v (p.val+1) u) a.1 a.2 x = + bulkHamiltonian N M f (Function.update v (p.val+1) 0) a.1 a.2 x+u*(bulkCoefficient N p*bulkY N p a.2 x) := by + simp only [bulkHamiltonian] + rw [bulkFeature_update N v p u x] + simp only [inner_add_left,inner_smul_left,starRingEnd_apply,star_trivial,bulkY] + ring + +lemma bulkCoefficient_pos (n : ℕ) (p : Fin (n+1)) : 0 bulkY N p a.1.2 a.2) := + (bulkY_measurable N p).comp (measurable_fst.snd.prodMk measurable_snd) + +def bulkCouplingSlope (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (u : ℝ) (a : BulkDisorder (n+1) M) : ℝ := + bulkCoefficient (n+1) p*tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2) + (bulkY (n+1) p a.2) 1 + +lemma bulkCouplingSlope_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + Measurable (bulkCouplingSlope n M f v p u) := by + apply Measurable.const_mul + exact kernel_tiltMean_measurable (bulkSpinKernel n M) + (H := fun a x => bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2 x) + (Y := fun a x => bulkY (n+1) p a.2 x) + (bulkHamiltonian_continuous _ _ _ _).measurable (bulkY_joint_measurable _ _ _) + +lemma bulkCoupling_regular (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (a : BulkDisorder (n+1) M) : + ContDiff ℝ 2 (fun u => bulkLogPartition n M f (Function.update v (p.val+1) u) a.1 a.2) ∧ + ConvexOn ℝ univ (fun u => bulkLogPartition n M f (Function.update v (p.val+1) u) a.1 a.2) ∧ + ∀ u, HasDerivAt (fun u => bulkLogPartition n M f (Function.update v (p.val+1) u) a.1 a.2) + (bulkCouplingSlope n M f v p u a) u := by + let H := bulkHamiltonian (n+1) M f (Function.update v (p.val+1) 0) a.1 a.2 + let Y := fun x => bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x + have hH : Measurable H := bulkHamiltonian_section_measurable _ _ _ _ a + have hY : Measurable Y := (bulkY_measurable _ _).of_uncurry_left.const_mul _ + have he (u : ℝ) : Integrable (fun x => Real.exp (H x+u*Y x)) (unitSphereLaw (n+1)) := by + have hi := bulkHamiltonian_exp_integrable n M f (Function.update v (p.val+1) u) a + convert hi using 1 + funext x + congr 1 + exact (bulkHamiltonian_update _ _ _ _ _ _ _ _).symm + have hf : (fun u => bulkLogPartition n M f (Function.update v (p.val+1) u) a.1 a.2)= + (fun u => Real.log (tiltPartition (unitSphereLaw (n+1)) (fun x => H x+u*Y x) 1)) := by + funext u + rw [bulkLogPartition_eq] + congr 2 + funext x + exact bulkHamiltonian_update _ _ _ _ _ _ _ _ + rw [hf] + refine ⟨coupling_log_contDiff _ hH hY he,coupling_log_convex _ hH hY he,?_⟩ + intro u + convert coupling_log_hasDerivAt (unitSphereLaw (n+1)) hH hY he u using 1 + dsimp only [bulkCouplingSlope,Y] + rw [tiltMean_const_mul_general] + congr 2 + funext x + exact bulkHamiltonian_update _ _ _ _ _ _ _ _ + +lemma bulkExpectedLog_hasDerivAt (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + Integrable (bulkCouplingSlope n M f v p u) (bulkDisorderLaw (n+1) M) ∧ + HasDerivAt (fun t => bulkExpectedLog n M f (Function.update v (p.val+1) t)) + (∫ a, bulkCouplingSlope n M f v p u a ∂bulkDisorderLaw (n+1) M) u := by + apply annealed_convex_hasDerivAt (bulkDisorderLaw (n+1) M) + (fun t => (bulkLogPartition_measurable n M f _).aestronglyMeasurable) + (fun t => (bulkCouplingSlope_measurable n M f v p t).aestronglyMeasurable) + (fun t => (bulkLogPartition_memLp n M f _).integrable (by norm_num)) + exact ae_of_all _ fun a => (bulkCoupling_regular n M f v p a).2 + +lemma bulkExpectedLog_convex (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + ConvexOn ℝ univ (fun t => bulkExpectedLog n M f (Function.update v (p.val+1) t)) := by + refine ⟨convex_univ,?_⟩ + intro x _ y _ a b ha hb hab + let F := fun t (d : BulkDisorder (n+1) M) => bulkLogPartition n M f (Function.update v (p.val+1) t) d.1 d.2 + have hi (t : ℝ) : Integrable (F t) (bulkDisorderLaw (n+1) M) := + (bulkLogPartition_memLp n M f _).integrable (by norm_num) + have hi1 : Integrable (fun d => a*F x d) (bulkDisorderLaw (n+1) M) := (hi x).const_mul a + have hi2 : Integrable (fun d => b*F y d) (bulkDisorderLaw (n+1) M) := (hi y).const_mul b + change (∫ d, F (a*x+b*y) d ∂bulkDisorderLaw (n+1) M) ≤ + a*(∫ d, F x d ∂bulkDisorderLaw (n+1) M)+b*(∫ d, F y d ∂bulkDisorderLaw (n+1) M) + calc + _ ≤ ∫ d, a*F x d+b*F y d ∂bulkDisorderLaw (n+1) M := by + apply integral_mono (hi _) (hi1.add hi2) + intro d + exact (bulkCoupling_regular n M f v p d).2.1.2 (mem_univ x) (mem_univ y) ha hb hab + _ = _ := by rw [integral_add hi1 hi2,integral_const_mul,integral_const_mul] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkDeviation.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkDeviation.lean new file mode 100644 index 0000000000000000000000000000000000000000..12b5cdf142d52cf25e1d6a0fb053457128a33b5c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkDeviation.lean @@ -0,0 +1,131 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkThermal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma bulkCouplingSlope_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (u : ℝ) (a : BulkDisorder (n+1) M) : + |bulkCouplingSlope n M f v p u a|≤bulkCoefficient (n+1) p*‖a.2‖ := by + unfold bulkCouplingSlope + rw [abs_mul,abs_of_pos (bulkCoefficient_pos n p)] + apply mul_le_mul_of_nonneg_left _ (bulkCoefficient_pos n p).le + exact tiltMean_bound_of_integrable (unitSphereLaw (n+1)) + (bulkHamiltonian_section_measurable _ _ _ _ a) (bulkY_measurable _ _).of_uncurry_left + (by simpa only [one_mul] using bulkHamiltonian_exp_integrable n M f (Function.update v (p.val+1) u) a) (bulkY_bound _ _ _) + +lemma bulkCouplingSlope_joint_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + Measurable (Function.uncurry (bulkCouplingSlope n M f v p)) := by + let H := fun a : ℝ × BulkDisorder (n+1) M => fun x : NormalizedSpin (n+1) => + bulkHamiltonian (n+1) M f (Function.update v (p.val+1) 0) a.2.1 a.2.2 x+ + a.1*(bulkCoefficient (n+1) p*bulkY (n+1) p a.2.2 x) + let Y := fun a : ℝ × BulkDisorder (n+1) M => bulkY (n+1) p a.2.2 + have hYc : Continuous (Function.uncurry Y) := + ((bulkDirection_continuous (n+1) p).comp continuous_snd).inner continuous_fst.snd.snd + have hY : Measurable (Function.uncurry Y) := hYc.measurable + have hH : Measurable (Function.uncurry H) := by + have hb : Continuous (fun a : (ℝ × BulkDisorder (n+1) M) × NormalizedSpin (n+1) => + bulkHamiltonian (n+1) M f (Function.update v (p.val+1) 0) a.1.2.1 a.1.2.2 a.2) := + (bulkHamiltonian_continuous (n+1) M f (Function.update v (p.val+1) 0)).comp + (continuous_fst.snd.prodMk continuous_snd) + exact (hb.add (continuous_fst.fst.mul (hYc.const_mul _))).measurable + have hm := (kernel_tiltMean_measurable (Kernel.const (ℝ × BulkDisorder (n+1) M) (unitSphereLaw (n+1))) hH hY).const_mul (bulkCoefficient (n+1) p) + convert hm using 1 + funext a + unfold Function.uncurry bulkCouplingSlope + congr 2 + funext x + exact bulkHamiltonian_update _ _ _ _ _ _ _ _ + +def bulkSlopeDeviation (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : ℝ := + ∫ a, |bulkCouplingSlope n M f v p u a- + ∫ b, bulkCouplingSlope n M f v p u b ∂bulkDisorderLaw (n+1) M| ∂bulkDisorderLaw (n+1) M + +lemma bulkSlopeDeviation_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + Measurable (bulkSlopeDeviation n M f v p) := by + have hd := bulkCouplingSlope_joint_measurable n M f v p + have hm := (hd.stronglyMeasurable.integral_prod_right' (ν:=bulkDisorderLaw (n+1) M)).measurable + exact ((hd.sub (hm.comp measurable_fst)).abs).stronglyMeasurable.integral_prod_right'.measurable + +lemma bulkSlopeDeviation_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + bulkSlopeDeviation n M f v p u ≤ + 2*bulkCoefficient (n+1) p*(∫ a : BulkDisorder (n+1) M, ‖a.2‖ ∂bulkDisorderLaw (n+1) M) := by + have hi := (bulkExpectedLog_hasDerivAt n M f v p u).1 + have hn := (bulkMarkNorm_memLp n M).integrable (by norm_num) + have hB : |∫ a, bulkCouplingSlope n M f v p u a ∂bulkDisorderLaw (n+1) M|≤ + bulkCoefficient (n+1) p*(∫ a : BulkDisorder (n+1) M, ‖a.2‖ ∂bulkDisorderLaw (n+1) M) := by + calc + _ ≤ ∫ a, |bulkCouplingSlope n M f v p u a| ∂bulkDisorderLaw (n+1) M := abs_integral_le_integral_abs + _ ≤ ∫ a : BulkDisorder (n+1) M, bulkCoefficient (n+1) p*‖a.2‖ ∂bulkDisorderLaw (n+1) M := + integral_mono hi.abs (hn.const_mul _) (bulkCouplingSlope_bound n M f v p u) + _ = _ := integral_const_mul _ _ + calc + _ ≤ ∫ a, bulkCoefficient (n+1) p*‖a.2‖+ + |∫ b, bulkCouplingSlope n M f v p u b ∂bulkDisorderLaw (n+1) M| ∂bulkDisorderLaw (n+1) M := by + apply integral_mono (hi.sub (integrable_const _)).abs ((hn.const_mul _).add (integrable_const _)) + intro a + exact (abs_sub _ _).trans (add_le_add (bulkCouplingSlope_bound n M f v p u a) (le_refl _)) + _ ≤ _ := by + rw [integral_add (hn.const_mul _) (integrable_const _),integral_const_mul] + simp only [integral_const,Measure.real,measure_univ,ENNReal.toReal_one,one_smul] + linarith + +lemma bulkSlopeDeviation_intervalIntegrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (a b : ℝ) : + IntervalIntegrable (bulkSlopeDeviation n M f v p) volume a b := by + apply IntegrableOn.intervalIntegrable + apply IntegrableOn.of_bound isCompact_uIcc.measure_lt_top + (bulkSlopeDeviation_measurable n M f v p).aestronglyMeasurable.restrict + (2*bulkCoefficient (n+1) p*(∫ a : BulkDisorder (n+1) M, ‖a.2‖ ∂bulkDisorderLaw (n+1) M)) + exact ae_of_all _ fun u => by + rw [Real.norm_eq_abs,abs_of_nonneg (show 0≤bulkSlopeDeviation n M f v p u from integral_nonneg fun _ => abs_nonneg _)] + exact bulkSlopeDeviation_bound n M f v p u + +lemma bulkLogPartition_fluctuation (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) {C : ℝ} + (hC : 0≤C) (hv : ∀ p, |v p|≤C) : + (∫ a : BulkDisorder (n+1) M, |bulkLogPartition n M f v a.1 a.2-bulkExpectedLog n M f v| ∂bulkDisorderLaw (n+1) M) ≤ + Real.sqrt (Real.pi^2/8*C^2*bulkScale (n+1)^2+M*(2*‖f‖)^2) := by + apply (integral_centered_abs_le_sqrt_variance _ (bulkLogPartition_memLp n M f v)).trans + apply Real.sqrt_le_sqrt + apply (bulkLogPartition_variance n M f v).trans + have hh := mul_le_mul_of_nonneg_left (bulkFeatureBound_sq_le (n+1) v hC (fun j => hv (j+1))) (by positivity : 0≤Real.pi^2/8) + nlinarith + +lemma bulkSlopeDeviation_integrated_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + {s C : ℝ} (hs : 0 (bulkExpectedLog_hasDerivAt n M f v p u).2) hs + (K:=6*bulkCoefficient (n+1) p^2) + · intro u hu + calc + _ ≤ 2*bulkCoefficient (n+1) p^2*|u| := bulk_expected_slope_bound n M f v p u + _ ≤ _ := by + have hh : |u|≤3 := abs_le.mpr ⟨by linarith [hu.1],by linarith [hu.2]⟩ + nlinarith [mul_le_mul_of_nonneg_left hh (by positivity : 0≤2*bulkCoefficient (n+1) p^2)] + · exact bulkSlopeDeviation_intervalIntegrable n M f v p 1 2 + · intro u hu + apply integral_convex_derivative_fluctuation (bulkDisorderLaw (n+1) M) hs + (bulkCouplingSlope_measurable n M f v p u).aestronglyMeasurable + (ae_of_all _ fun a => ⟨(bulkCoupling_regular n M f v p a).2.1,(bulkCoupling_regular n M f v p a).2.2 u⟩) + (bulkExpectedLog_convex n M f v p) (fun t => (bulkExpectedLog_hasDerivAt n M f v p t).2) + (fun t _ => (bulkLogPartition_memLp n M f _).integrable (by norm_num)) + intro t ht + apply bulkLogPartition_fluctuation n M f _ (by linarith : 0≤C) + intro j + by_cases hj : j=p.val+1 + · subst j + simp only [Function.update_self] + exact abs_le.mpr ⟨by linarith [ht.1,hu.1],by linarith [ht.2,hu.2]⟩ + · rw [Function.update_of_ne hj] + exact hv j + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkDiagonalLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkDiagonalLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..57ca23eded6b19669656fa15c8ba45fd895fab27 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkDiagonalLimit.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkSingleEmpiricalLimit +import OAI.Probability.Perceptron.Cavity.BulkTimeLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma bulkMarkedArray_limit_diagonal_const (M : ℕ → ℕ) (g : Jet3) (v : ℕ → ℕ → ℝ) + (s : ℕ → ℕ) (K : ℝ) (hK : ∀ n, (M (s n):ℝ)/(s n+1:ℕ)*‖g.d1‖^2 ≤ K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hlim : Tendsto (fun n => bulkMarkedArrayLaw (s n) (M (s n)) g (v (s n)) K (hK n)) atTop (𝓝 μ)) + (d : ℝ) (hL2 : Tendsto (fun n => bulkReplicaMean (s n) (M (s n)) g.f (v (s n)) 1 + (fun a x => (bulkB (s n+1) (M (s n)) g a.1 (x 0) (x 0)-d)^2)) atTop (𝓝 0)) : + ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i, (Q i i).2.val = d := by + let F : CompactBlock (BulkPairRange K) 1 →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun Q => ((Q 0 0).2.val-d)^2,by fun_prop⟩ + let G : CompactArray (BulkPairRange K) →ᵇ ℝ := F.compContinuous ⟨compactBlock 1,compactBlock_continuous 1⟩ + have hzero : (∫ Q, G Q ∂(μ : Measure (CompactArray (BulkPairRange K)))) = 0 := by + have ht := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction G).continuousAt.tendsto.comp hlim + have hfn n : (∫ Q, G Q ∂(bulkMarkedArrayLaw (s n) (M (s n)) g (v (s n)) K (hK n) : Measure _)) = + bulkReplicaMean (s n) (M (s n)) g.f (v (s n)) 1 + (fun a x => (bulkB (s n+1) (M (s n)) g a.1 (x 0) (x 0)-d)^2) := + bulkMarkedArray_block (s n) (M (s n)) g (v (s n)) K (hK n) 1 F + exact tendsto_nhds_unique (by simpa only [Function.comp_def,hfn] using ht) hL2 + have hz : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), (Q 0 0).2.val = d := by + have ha := (integral_eq_zero_iff_of_nonneg + (fun Q => show 0 ≤ G Q from sq_nonneg _) (G.integrable _)).mp hzero + filter_upwards [ha] with Q hQ + exact sub_eq_zero.mp (sq_eq_zero_iff.mp hQ) + apply ae_all_iff.mpr + intro i + have he := compact_exchangeability_limit hlim (Equiv.swap 0 i) + (fun n => bulkMarkedArray_exchangeable (s n) (M (s n)) g (v (s n)) K (hK n) _) + simpa only [compactRelabel,Equiv.swap_apply_left] using he.quasiMeasurePreserving.ae hz + +theorem bulkMarkedArray_diagonal_producer (M : ℕ → ℕ) (g : Jet3) (v : ℕ → ℕ → ℝ) + (hv : ∀ᶠ n in atTop, ∀ p, 1 ≤ v n p) + (hdO : ∀ p, Tendsto (fun n => bulkDeviationAt n (M n) g.f p (v n)) atTop (𝓝 0)) + (s : ℕ → ℕ) (hs : StrictMono s) (α : ℝ) (hα : 0 ≤ α) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (ho : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (K : ℝ) (hK : ∀ n, ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)*‖g.d1‖^2 ≤ K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hf : Tendsto (fun n => bulkMarkedArrayLaw (s n) (M (s n)+2) g (v (s n)) K (hK n)) atTop (𝓝 μ)) : + ∃ d : ℝ, 0 ≤ d ∧ d ≤ K ∧ d ≤ α*‖g.d1‖^2 ∧ + (∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i, (Q i i).2.val = d) ∧ + (∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i j, (Q i j).2.val ≤ d) := by + have hg := bulk_limit_geometry M g.f v hv hdO hs ho + obtain ⟨c,hc,hL2⟩ := bulk_single_L2_concentration M g v s hs.tendsto_atTop α hd ho + hg.2.2 hg.1 hg.2.1 (g.d1*g.d1) + let d := α*c + have hdia := bulkMarkedArray_limit_diagonal_const (fun n => M n+2) g v s K hK μ hf d hL2 + have hmg := bulkMarkedArray_limit_mark_geometry (fun n => M n+2) g v s K hK hf + obtain ⟨Q,hQ,hpos⟩ := (hdia.and hmg.1).exists + have hd0 : 0 ≤ d := by simpa only [hQ 0] using hpos 0 + have hdK : d ≤ K := by simpa only [hQ 0] using (Q 0 0).2.property.2 + have hdA : d ≤ α*‖g.d1‖^2 := by + exact mul_le_mul_of_nonneg_left ((le_abs_self c).trans (hc.trans + ((norm_mul_le _ _).trans_eq (by ring)))) hα + refine ⟨d,hd0,hdK,hdA,hdia,?_⟩ + filter_upwards [hdia,hmg.2] with Q hD hB + intro i j + have h := hB i j + rw [hD i,hD j] at h + linarith + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkEmpiricalLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkEmpiricalLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..2700c9759acd1094e4e4fa795d7ebd4404ed56a3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkEmpiricalLimit.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkMarkedPairLimit + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BoundedContinuousFunction NNReal ENNReal BigOperators + +lemma bulk_density_factors (M s : ℕ→ℕ) (hs : Tendsto s atTop atTop) (α : ℝ) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) : + Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)^2) atTop (𝓝 0) ∧ + Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)*((M (s n)+1:ℕ):ℝ)/(s n+1:ℕ)^2) + atTop (𝓝 (α^2)) := by + have hn : Tendsto (fun n => ((s n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp ((tendsto_add_atTop_nat 1).comp hs) + have hi : Tendsto (fun n => (((s n+1:ℕ):ℝ))⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp hn + have hfirst := hd.mul hi + have hsecond := hd.mul (hd.sub hi) + constructor + · convert hfirst using 1 <;> try simp + funext n + field_simp + · convert hsecond using 1 <;> try ring_nf + funext n + push_cast + field_simp + ring + +lemma bulkPairAverage_first_limit (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (α : ℝ) (w : ℝ→ᵇℝ) (a : ℝ→ℝ) (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ht : ∀ F : CompactOverlap→ᵇℝ, + Tendsto (fun n => ∫ p,bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) + (compactPairTest F) (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>(1:ℝ→ᵇℝ))) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^2 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ Q : CompactArray CompactOverlap,F (Q 0 1)*a (Q 0 1).val ∂(ν : Measure _)))) + (F : CompactOverlap→ᵇℝ) : + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 2 + (fun d x => bulkPairOverlapTest (s n) F x*bulkPairAverage (s n) (M (s n)+2) w d x)) + atTop (𝓝 (α*(∫ Q : CompactArray CompactOverlap,F (Q 0 1)*a (Q 0 1).val ∂(ν : Measure _)))) := by + simp_rw [bulkPairAverage_first] + exact hd.mul (ht F) + +lemma bulkPairAverage_second_limit (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (hs : Tendsto s atTop atTop) (α : ℝ) (w : ℝ→ᵇℝ) (a : ℝ→ℝ) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ht : ∀ F : CompactOverlap→ᵇℝ, + Tendsto (fun n => ∫ p,bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) + (compactPairTest F) (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>w)) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^2 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ Q : CompactArray CompactOverlap,F (Q 0 1)*(a (Q 0 1).val)^2 ∂(ν : Measure _)))) + (F : CompactOverlap→ᵇℝ) : + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 2 + (fun d x => bulkPairOverlapTest (s n) F x*(bulkPairAverage (s n) (M (s n)+2) w d x)^2)) + atTop (𝓝 (α^2*(∫ Q : CompactArray CompactOverlap,F (Q 0 1)*(a (Q 0 1).val)^2 ∂(ν : Measure _)))) := by + have hfac := bulk_density_factors M s hs α hd + have herr : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)^2* + bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 2 (fun d x => bulkPairOverlapTest (s n) F x* + (pairFieldMark w (bulkPatternFields ((Fin.last (M (s n))).castSucc) d x))^2)) atTop (𝓝 0) := by + apply squeeze_zero_norm (fun n => ?_) (by simpa only [zero_mul] using hfac.1.mul_const (‖F‖*‖w‖^4)) + rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (by positivity : 0≤((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)^2)] + exact mul_le_mul_of_nonneg_left (bulkPairAverage_diagonal_bound (s n) (M (s n)) g.f w (v (s n)) F) (by positivity : 0≤((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)^2) + simp_rw [bulkPairAverage_second] + simpa using herr.add (hfac.2.mul (ht F)) + +theorem bulk_marked_empirical_limits (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (hs : Tendsto s atTop atTop) (α : ℝ) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (w : ℝ→ᵇℝ) : ∃ a : ℝ→ℝ, Monotone a ∧ (∀ r,0≤a r ∧ a r≤‖w‖^2) ∧ + ∀ F : CompactOverlap→ᵇℝ, + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 2 + (fun d x => bulkPairOverlapTest (s n) F x*bulkPairAverage (s n) (M (s n)+2) w d x)) + atTop (𝓝 (α*(∫ Q : CompactArray CompactOverlap,F (Q 0 1)*a (Q 0 1).val ∂(ν : Measure _)))) ∧ + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 2 + (fun d x => bulkPairOverlapTest (s n) F x*(bulkPairAverage (s n) (M (s n)+2) w d x)^2)) + atTop (𝓝 (α^2*(∫ Q : CompactArray CompactOverlap,F (Q 0 1)*(a (Q 0 1).val)^2 ∂(ν : Measure _)))) := by + obtain ⟨a,ham,hab,ht⟩ := bulk_marked_pair_limit_exists M g v s hlim hGG hgeo hn w + refine ⟨a,ham,hab,fun F => ⟨?_,?_⟩⟩ + · apply bulkPairAverage_first_limit M g v s α w a ν hd _ F + intro F + simpa [secondPairMark,pairMarkPower] using ht F false + · apply bulkPairAverage_second_limit M g v s hs α w a ν hd _ F + intro F + simpa [secondPairMark,pairMarkPower] using ht F true + +lemma bulk_pair_restoration_exact (n M : ℕ) (g : Jet3) (v : ℕ→ℝ) + (F : CompactOverlap →ᵇ ℝ) : + (∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(bulkGibbsArrayLaw n (M+2) g.f v : Measure _))= + ∫ p,bulkFreshNumerator n M 2 g.f v (compactPairTest F) + (gaussianMixedTest (fun _=>1)) (gaussianMixedTest (fun _=>1)) p / + bulkFreshDenominator n M g.f v p^2 ∂twoFreshDisorderLaw (n+1) M := by + have he := bulkFresh_annealed_restoration n M 2 g.f v (compactPairTest F) + (gaussianMixedTest (fun _=>1)) (gaussianMixedTest (fun _=>1)) + let A : CompactBlock CompactOverlap 2 →ᵇ ℝ := F.compContinuous ⟨fun Q=>Q 0 1,by fun_prop⟩ + have hb := bulkGibbsArray_block n (M+2) g.f v 2 A + change (∫ Q,A (compactBlock 2 Q) ∂(bulkGibbsArrayLaw n (M+2) g.f v : Measure _))=_ + rw [hb,←he] + apply integral_congr_ae + filter_upwards [] with a + congr 1 + funext x + simp only [bulkMarkedTest,gaussianMixedTest_apply,BoundedContinuousFunction.coe_one,Pi.one_apply,Finset.prod_const_one,mul_one] + change F (bulkOverlap (x 0) (x 1))=F (bulkOverlap (x 1) (x 0)) + congr 1 + apply Subtype.ext + exact real_inner_comm _ _ + +lemma bulk_full_pair_tendsto (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (F : CompactOverlap →ᵇ ℝ) : + Tendsto (fun n => ∫ Q : CompactArray CompactOverlap,F (Q 0 1) + ∂(bulkGibbsArrayLaw (s n) (M (s n)+2) g.f (v (s n)) : Measure _)) atTop + (𝓝 (∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(ν : Measure _))) := by + simp_rw [bulk_pair_restoration_exact] + exact bulk_pair_restoration_ratio_tendsto M g v s hlim hGG hgeo hn F + +lemma bulk_limit_geometry (M : ℕ→ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℕ→ℝ) + (hv : ∀ᶠ n in atTop, ∀ p, 1≤v n p) + (hd : ∀ p, Tendsto (fun n => bulkDeviationAt n (M n) f p (v n)) atTop (𝓝 0)) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} {s : ℕ→ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) f (v (s n))) atTop (𝓝 ν)) : + (∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) ∧ + (∀ᵐ Q : CompactArray CompactJointOverlap ∂(bulkJointLaw ν : Measure _), 0≤(Q 0 1).1.val) ∧ + (∀ r (i : Fin r) (F : CompactBlock CompactJointOverlap r→ᵇℝ) (g : CompactJointOverlap→ᵇℝ), + compactGGDefect (bulkJointLaw ν) r i F g=0) := by + have hGG := compactMapLaw_gg bulkJointEmbedding bulkJointEmbedding_continuous ν + (bulk_limit_gg M f v hv hd hs hlim) + have hR := bulkJointLaw_gram (bulkGibbsArray_limit_gram f M v s hlim) + have hD := bulkJointLaw_diagonal (bulkGibbsArray_limit_diagonal f M v s hlim) + have hEx (e : Equiv.Perm ℕ) := compactMapLaw_exchangeable bulkJointEmbedding bulkJointEmbedding_continuous ν e + (compact_exchangeability_limit hlim e (fun n => bulkGibbsArray_exchangeable (s n) (M (s n)) f (v (s n)) e)) + exact ⟨compact_gg_spin_geometry _ hEx hGG hR hD, + compact_spin_nonnegative _ (compactRealLaw_gg _ hGG) hR,hGG⟩ + +lemma bulk_full_omitted_pair_integral (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {μ ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (homit : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 μ)) + (hfull : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)+2) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw μ) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw μ : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw μ : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (F : CompactOverlap →ᵇ ℝ) : + (∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(μ : Measure _))= + ∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(ν : Measure _) := by + let A : CompactArray CompactOverlap →ᵇ ℝ := F.compContinuous ⟨fun Q=>Q 0 1,by fun_prop⟩ + exact tendsto_nhds_unique (bulk_full_pair_tendsto M g v s homit hGG hgeo hn F) + ((ProbabilityMeasure.continuous_integral_boundedContinuousFunction A).continuousAt.tendsto.comp hfull) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkEnergyDeviation.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkEnergyDeviation.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2bbceddf5cf195ffa6af7b224fffefcf10fb573 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkEnergyDeviation.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkDeviation +import OAI.Probability.Perceptron.Variational.IntegratedThermal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma bulkCouplingSlope_eq_mean (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) + (a : BulkDisorder (n+1) M) : + bulkCouplingSlope n M f v p u a = tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2) + (fun x => bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x) 1 := by + rw [tiltMean_const_mul_general]; rfl + +lemma bulkCoupledHamiltonian_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + Measurable (fun a : (ℝ × BulkDisorder (n+1) M) × NormalizedSpin (n+1) => + bulkHamiltonian (n+1) M f (Function.update v (p.val+1) a.1.1) a.1.2.1 a.1.2.2 a.2) := by + have hb : Continuous (fun a : (ℝ × BulkDisorder (n+1) M) × NormalizedSpin (n+1) => + bulkHamiltonian (n+1) M f (Function.update v (p.val+1) 0) a.1.2.1 a.1.2.2 a.2) := + (bulkHamiltonian_continuous (n+1) M f (Function.update v (p.val+1) 0)).comp + (continuous_fst.snd.prodMk continuous_snd) + have hy : Continuous (fun a : (ℝ × BulkDisorder (n+1) M) × NormalizedSpin (n+1) => + bulkY (n+1) p a.1.2.2 a.2) := + ((bulkDirection_continuous (n+1) p).comp continuous_snd).inner continuous_fst.snd.snd + convert (hb.add (continuous_fst.fst.mul (hy.const_mul (bulkCoefficient (n+1) p)))).measurable using 1 + funext a + exact bulkHamiltonian_update _ _ _ _ _ _ _ _ + +def bulkEnergyDeviation (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : ℝ := + ∫ a, tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2) + (fun x => |bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x- + ∫ b, bulkCouplingSlope n M f v p u b ∂bulkDisorderLaw (n+1) M|) 1 ∂bulkDisorderLaw (n+1) M + +lemma bulkEnergyDeviation_nonneg (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + 0≤bulkEnergyDeviation n M f v p u := + integral_nonneg fun _ => tiltMean_nonneg _ (fun _ => abs_nonneg _) _ + +lemma bulkEnergyDeviation_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + Measurable (bulkEnergyDeviation n M f v p) := by + have hE := (bulkCouplingSlope_joint_measurable n M f v p).stronglyMeasurable.integral_prod_right' + (ν:=bulkDisorderLaw (n+1) M) + have hY : Measurable (fun a : (ℝ × BulkDisorder (n+1) M) × NormalizedSpin (n+1) => + bulkCoefficient (n+1) p*bulkY (n+1) p a.1.2.2 a.2) := + ((bulkY_measurable (n+1) p).comp (measurable_fst.snd.snd.prodMk measurable_snd)).const_mul _ + have hm := kernel_tiltMean_measurable (Kernel.const (ℝ × BulkDisorder (n+1) M) (unitSphereLaw (n+1))) + (H:=fun a x => bulkHamiltonian (n+1) M f (Function.update v (p.val+1) a.1) a.2.1 a.2.2 x) + (Y:=fun a x => |bulkCoefficient (n+1) p*bulkY (n+1) p a.2.2 x- + ∫ b, bulkCouplingSlope n M f v p a.1 b ∂bulkDisorderLaw (n+1) M|) + (bulkCoupledHamiltonian_measurable n M f v p) (hY.sub (hE.measurable.comp measurable_fst.fst)).abs + exact hm.stronglyMeasurable.integral_prod_right'.measurable + +lemma bulkEnergyDeviation_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + bulkEnergyDeviation n M f v p u ≤ + 2*bulkCoefficient (n+1) p*(∫ a : BulkDisorder (n+1) M, ‖a.2‖ ∂bulkDisorderLaw (n+1) M) := by + let E := ∫ b, bulkCouplingSlope n M f v p u b ∂bulkDisorderLaw (n+1) M + have hn := (bulkMarkNorm_memLp n M).integrable (by norm_num) + have hE : |E|≤bulkCoefficient (n+1) p*(∫ a : BulkDisorder (n+1) M, ‖a.2‖ ∂bulkDisorderLaw (n+1) M) := by + apply abs_integral_le_integral_abs.trans + calc + _ ≤ ∫ a : BulkDisorder (n+1) M, bulkCoefficient (n+1) p*‖a.2‖ ∂bulkDisorderLaw (n+1) M := + integral_mono (bulkExpectedLog_hasDerivAt n M f v p u).1.abs (hn.const_mul _) (bulkCouplingSlope_bound n M f v p u) + _ = _ := integral_const_mul _ _ + have hb (a : BulkDisorder (n+1) M) : + tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2) + (fun x => |bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x-E|) 1 ≤ + bulkCoefficient (n+1) p*‖a.2‖+|E| := by + have ht := tiltMean_bound_of_integrable (unitSphereLaw (n+1)) + (t:=1) (bulkHamiltonian_section_measurable _ _ _ _ a) + (((bulkY_measurable _ _).of_uncurry_left.const_mul (bulkCoefficient (n+1) p)).sub_const E).abs + (by simpa only [one_mul] using bulkHamiltonian_exp_integrable n M f (Function.update v (p.val+1) u) a) + (fun x => show abs (abs (bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x-E))≤bulkCoefficient (n+1) p*‖a.2‖+|E| from by + rw [abs_abs] + apply (abs_sub _ _).trans + rw [abs_mul,abs_of_pos (bulkCoefficient_pos n p)] + exact add_le_add (mul_le_mul_of_nonneg_left (bulkY_bound _ _ _ _) (bulkCoefficient_pos n p).le) le_rfl) + exact (le_abs_self _).trans ht + calc + _ ≤ ∫ a : BulkDisorder (n+1) M, bulkCoefficient (n+1) p*‖a.2‖+|E| ∂bulkDisorderLaw (n+1) M := + integral_mono_of_nonneg (ae_of_all _ fun a => tiltMean_nonneg _ (fun _ => abs_nonneg _) _) + ((hn.const_mul _).add (integrable_const |E|)) (ae_of_all _ hb) + _ ≤ _ := by + rw [integral_add (hn.const_mul _) (integrable_const _),integral_const_mul] + simp only [integral_const,Measure.real,measure_univ,ENNReal.toReal_one,one_smul] + linarith + +lemma bulkEnergyDeviation_intervalIntegrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (a b : ℝ) : + IntervalIntegrable (bulkEnergyDeviation n M f v p) volume a b := by + apply IntegrableOn.intervalIntegrable + apply IntegrableOn.of_bound isCompact_uIcc.measure_lt_top + (bulkEnergyDeviation_measurable n M f v p).aestronglyMeasurable.restrict + (2*bulkCoefficient (n+1) p*(∫ a : BulkDisorder (n+1) M, ‖a.2‖ ∂bulkDisorderLaw (n+1) M)) + exact ae_of_all _ fun u => by + rw [Real.norm_eq_abs,abs_of_nonneg (bulkEnergyDeviation_nonneg n M f v p u)] + exact bulkEnergyDeviation_bound n M f v p u + +lemma bulkEnergyDeviation_thermal_disorder (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + bulkEnergyDeviation n M f v p u ≤ + Real.sqrt (∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M)+ + bulkSlopeDeviation n M f v p u := by + have he := annealed_centered_energy_bound (unitSphereLaw (n+1)) (bulkDisorderLaw (n+1) M) + (H:=fun a x => bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2 x) + (Y:=fun a x => bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x) + (bulkHamiltonian_continuous (n+1) M f (Function.update v (p.val+1) u)).measurable + ((bulkY_joint_measurable (n+1) M p).const_mul (bulkCoefficient (n+1) p)) + (B:=fun a => bulkCoefficient (n+1) p*‖a.2‖) + (fun a => by unfold bulkFeatureBound; positivity) + (fun a => mul_nonneg (bulkCoefficient_pos n p).le (norm_nonneg _)) + (bulkHamiltonian_bound (n+1) M f (Function.update v (p.val+1) u)) + (fun a x => by rw [abs_mul,abs_of_pos (bulkCoefficient_pos n p)]; exact mul_le_mul_of_nonneg_left (bulkY_bound _ _ _ _) (bulkCoefficient_pos n p).le) + ((bulkMarkNorm_memLp n M).const_mul _) + simp_rw [← bulkCouplingSlope_eq_mean] at he + change bulkEnergyDeviation n M f v p u ≤ _ at he + apply he.trans_eq + unfold bulkSlopeDeviation + congr 2 + apply integral_congr_ae + exact ae_of_all _ fun a => by + have hh : (fun x => bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2 x)= + (fun x => bulkHamiltonian (n+1) M f (Function.update v (p.val+1) 0) a.1 a.2 x+ + u*(bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x)) := + funext fun x => bulkHamiltonian_update _ _ _ _ _ _ _ _ + unfold bulkThermalVar thermalVar + simp only [zero_mul,add_zero,hh] + +lemma bulkEnergyDeviation_integrated_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + {s C : ℝ} (hs : 0 Real.sqrt (∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M)) volume 1 2 := + bulkThermalSqrt_intervalIntegrable n M f v p 1 2 + calc + _ ≤ ∫ u in (1:ℝ)..2, Real.sqrt (∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M)+bulkSlopeDeviation n M f v p u := + intervalIntegral.integral_mono (by norm_num) (bulkEnergyDeviation_intervalIntegrable n M f v p 1 2) + (hsq.add (bulkSlopeDeviation_intervalIntegrable n M f v p 1 2)) + (fun u => bulkEnergyDeviation_thermal_disorder n M f v p u) + _ = (∫ u in (1:ℝ)..2, Real.sqrt (∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M))+ + ∫ u in (1:ℝ)..2, bulkSlopeDeviation n M f v p u := intervalIntegral.integral_add hsq (bulkSlopeDeviation_intervalIntegrable n M f v p 1 2) + _ ≤ _ := by have h1 := bulkThermalSqrt_integrated_bound n M f v p; have h2 := bulkSlopeDeviation_integrated_bound n M f v p hs hs1 hC hv; linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkFreshRestore.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkFreshRestore.lean new file mode 100644 index 0000000000000000000000000000000000000000..0231a865911f5f3ac6fd020b36236d268f419f74 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkFreshRestore.lean @@ -0,0 +1,220 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkModel +import OAI.Probability.Perceptron.Variational.GibbsRestoration + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction + +def bulkSeparateLast (N M : ℕ) (a : BulkDisorder N (M+1)) : + BulkDisorder N M × EuclideanSpace ℝ (Fin N) := + ((fun i => a.1 i.castSucc,a.2),WithLp.toLp 2 (a.1 (Fin.last M))) + +lemma bulkSeparateLast_preserving (N M : ℕ) : + MeasurePreserving (bulkSeparateLast N M) (bulkDisorderLaw N (M+1)) + ((bulkDisorderLaw N M).prod (stdGaussian (EuclideanSpace ℝ (Fin N)))) := by + let ρ : Measure (Fin N→ℝ) := Measure.pi fun _ => gaussianReal 0 1 + let R := finitePatternRowsLaw N M + let G := stdGaussian (EuclideanSpace ℝ (Fin N)) + let B := stdGaussian (BulkMark N) + have hrow : MeasurePreserving (WithLp.toLp 2 : (Fin N→ℝ)→EuclideanSpace ℝ (Fin N)) ρ G := + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + have hp := (((MeasurePreserving.id R).prod hrow).comp + (Measure.measurePreserving_swap (μ:=ρ) (ν:=R))).comp + (measurePreserving_piFinSuccAbove (fun _ : Fin (M+1) => ρ) (Fin.last M)) + have hr : MeasurePreserving (fun a : ((Fin M→Fin N→ℝ)×EuclideanSpace ℝ (Fin N))×BulkMark N => + ((a.1.1,a.2),a.1.2)) ((R.prod G).prod B) ((R.prod B).prod G) := + (measurePreserving_prodAssoc R B G).symm.comp + (((MeasurePreserving.id R).prod (Measure.measurePreserving_swap (μ:=G) (ν:=B))).comp + (measurePreserving_prodAssoc R G B)) + convert hr.comp (hp.prod (MeasurePreserving.id B)) using 1 + · funext a + simp only [bulkSeparateLast,Function.comp_def,MeasurableEquiv.piFinSuccAbove_apply] + apply Prod.ext + · apply Prod.ext + · funext i j; simp [Fin.init] + · rfl + · rfl + · rfl + · rfl + +lemma bulkHamiltonian_last (N M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder N (M+1)) (x : NormalizedSpin N) : + bulkHamiltonian N (M+1) f v a.1 a.2 x = + bulkHamiltonian N M f v (bulkSeparateLast N M a).1.1 (bulkSeparateLast N M a).1.2 x+ + f (inner ℝ x.val (bulkSeparateLast N M a).2) := by + unfold bulkHamiltonian normalizedPatternEnergy + rw [Fin.sum_univ_castSucc] + simp only [bulkSeparateLast,EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial] + ring + +lemma bulk_replica_restore_last (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) (M+1)) (r : ℕ) (F : (Fin r→NormalizedSpin (n+1))→ℝ) : + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) (M+1) f v a.1 a.2) r F = + gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v (bulkSeparateLast (n+1) M a).1.1 (bulkSeparateLast (n+1) M a).1.2) r + (fun x => (∏ i, Real.exp (f (inner ℝ (x i).val (bulkSeparateLast (n+1) M a).2)))*F x) / + (tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v (bulkSeparateLast (n+1) M a).1.1 (bulkSeparateLast (n+1) M a).1.2) + (fun x => Real.exp (f (inner ℝ x.val (bulkSeparateLast (n+1) M a).2))) 1)^r := by + rw [show bulkHamiltonian (n+1) (M+1) f v a.1 a.2 = _ from + funext (bulkHamiltonian_last (n+1) M f v a)] + exact gibbsReplicaMean_restore _ + ((bulkHamiltonian_continuous _ _ _ _).measurable.comp (measurable_const.prodMk measurable_id)) + (bulkHamiltonian_exp_integrable n M f v _) r F + +lemma bulk_restoration_denominator_bounds (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) M) (z : EuclideanSpace ℝ (Fin (n+1))) : + Real.exp (-‖f‖) ≤ tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) + (fun x => Real.exp (f (inner ℝ x.val z))) 1 ∧ + tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) + (fun x => Real.exp (f (inner ℝ x.val z))) 1 ≤ Real.exp ‖f‖ := + tiltMean_exp_bounds _ + ((bulkHamiltonian_continuous _ _ _ _).measurable.comp (measurable_const.prodMk measurable_id)) + (f.measurable.comp (measurable_subtype_coe.inner measurable_const)) + (bulkHamiltonian_exp_integrable n M f v a) (norm_nonneg _) (fun _ => f.norm_coe_le_norm _) + +def bulkSeparateTwo (N M : ℕ) (a : BulkDisorder N (M+2)) : + BulkDisorder N M × (EuclideanSpace ℝ (Fin N) × EuclideanSpace ℝ (Fin N)) := + let b := bulkSeparateLast N (M+1) a + let c := bulkSeparateLast N M b.1 + (c.1,(c.2,b.2)) + +lemma bulkSeparateTwo_preserving (N M : ℕ) : + MeasurePreserving (bulkSeparateTwo N M) (bulkDisorderLaw N (M+2)) + ((bulkDisorderLaw N M).prod + ((stdGaussian (EuclideanSpace ℝ (Fin N))).prod (stdGaussian (EuclideanSpace ℝ (Fin N))))) := by + exact (measurePreserving_prodAssoc _ _ _).comp + (((bulkSeparateLast_preserving N M).prod (MeasurePreserving.id _)).comp + (bulkSeparateLast_preserving N (M+1))) + +lemma bulkHamiltonian_two (N M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder N (M+2)) (x : NormalizedSpin N) : + bulkHamiltonian N (M+2) f v a.1 a.2 x = + bulkHamiltonian N M f v (bulkSeparateTwo N M a).1.1 (bulkSeparateTwo N M a).1.2 x+ + (f (inner ℝ x.val (bulkSeparateTwo N M a).2.1)+ + f (inner ℝ x.val (bulkSeparateTwo N M a).2.2)) := by + rw [bulkHamiltonian_last N (M+1),bulkHamiltonian_last N M] + exact add_assoc _ _ _ + +lemma bulk_replica_restore_two (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) (M+2)) (r : ℕ) (F : (Fin r→NormalizedSpin (n+1))→ℝ) : + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) (M+2) f v a.1 a.2) r F = + gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v (bulkSeparateTwo (n+1) M a).1.1 (bulkSeparateTwo (n+1) M a).1.2) r + (fun x => (∏ i, Real.exp (f (inner ℝ (x i).val (bulkSeparateTwo (n+1) M a).2.1)+ + f (inner ℝ (x i).val (bulkSeparateTwo (n+1) M a).2.2)))*F x) / + (tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v (bulkSeparateTwo (n+1) M a).1.1 (bulkSeparateTwo (n+1) M a).1.2) + (fun x => Real.exp (f (inner ℝ x.val (bulkSeparateTwo (n+1) M a).2.1)+ + f (inner ℝ x.val (bulkSeparateTwo (n+1) M a).2.2))) 1)^r := by + rw [show bulkHamiltonian (n+1) (M+2) f v a.1 a.2 = _ from + funext (bulkHamiltonian_two (n+1) M f v a)] + exact gibbsReplicaMean_restore _ + ((bulkHamiltonian_continuous _ _ _ _).measurable.comp (measurable_const.prodMk measurable_id)) + (bulkHamiltonian_exp_integrable n M f v _) r F + +lemma bulk_two_denominator_bounds (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) M) (z t : EuclideanSpace ℝ (Fin (n+1))) : + Real.exp (-(2*‖f‖)) ≤ tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) + (fun x => Real.exp (f (inner ℝ x.val z)+f (inner ℝ x.val t))) 1 ∧ + tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) + (fun x => Real.exp (f (inner ℝ x.val z)+f (inner ℝ x.val t))) 1 ≤ Real.exp (2*‖f‖) := by + apply tiltMean_exp_bounds _ + ((bulkHamiltonian_continuous _ _ _ _).measurable.comp (measurable_const.prodMk measurable_id)) + ((f.measurable.comp (measurable_subtype_coe.inner measurable_const)).add + (f.measurable.comp (measurable_subtype_coe.inner measurable_const))) + (bulkHamiltonian_exp_integrable n M f v a) (by positivity) + intro x + exact (abs_add_le _ _).trans ((add_le_add (f.norm_coe_le_norm _) (f.norm_coe_le_norm _)).trans_eq + (two_mul ‖f‖).symm) + +def bulkPermutePatterns (N M : ℕ) (e : Equiv.Perm (Fin M)) + (a : BulkDisorder N M) : BulkDisorder N M := (fun i => a.1 (e i),a.2) + +lemma bulkPermutePatterns_preserving (N M : ℕ) (e : Equiv.Perm (Fin M)) : + MeasurePreserving (bulkPermutePatterns N M e) (bulkDisorderLaw N M) (bulkDisorderLaw N M) := by + have h := (measurePreserving_piCongrLeft + (fun _ : Fin M => Measure.pi (fun _ : Fin N => gaussianReal 0 1)) e.symm).prod + (MeasurePreserving.id (stdGaussian (BulkMark N))) + convert h using 1 + · funext a + apply Prod.ext + · funext i + have he := MeasurableEquiv.piCongrLeft_apply_apply (β:=fun _ : Fin M => Fin N→ℝ) e.symm a.1 (e i) + change a.1 (e i) = (MeasurableEquiv.piCongrLeft (fun _ : Fin M => Fin N→ℝ) e.symm) a.1 i + simpa only [Equiv.symm_apply_apply] using he.symm + · rfl + · rfl + · rfl + +lemma bulkHamiltonian_permute (N M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (e : Equiv.Perm (Fin M)) (a : BulkDisorder N M) : + bulkHamiltonian N M f v (bulkPermutePatterns N M e a).1 (bulkPermutePatterns N M e a).2 = + bulkHamiltonian N M f v a.1 a.2 := by + funext x + unfold bulkHamiltonian normalizedPatternEnergy bulkPermutePatterns + congr 1 + exact Equiv.sum_comp e (fun j => f (∑ i, a.1 j i*x.val i)) + +def bulkReplicaMean (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + (F : BulkDisorder (n+1) M → (Fin r→NormalizedSpin (n+1))→ℝ) : ℝ := + ∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r (F a) + ∂bulkDisorderLaw (n+1) M + +lemma bulkReplicaMean_permute (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + (e : Equiv.Perm (Fin M)) + (F : BulkDisorder (n+1) M → (Fin r→NormalizedSpin (n+1))→ℝ) + (hF : Measurable (Function.uncurry F)) : + bulkReplicaMean n M f v r (fun a => F (bulkPermutePatterns (n+1) M e a)) = + bulkReplicaMean n M f v r F := by + have hm := kernel_replicaMean_measurable (bulkSpinKernel n M) + (H:=fun a x => bulkHamiltonian (n+1) M f v a.1 a.2 x) + (bulkHamiltonian_continuous (n+1) M f v).measurable hF + have h := integral_map (μ:=bulkDisorderLaw (n+1) M) (bulkPermutePatterns_preserving (n+1) M e).measurable.aemeasurable + hm.aestronglyMeasurable + rw [(bulkPermutePatterns_preserving (n+1) M e).map_eq] at h + change (∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r (F a) ∂bulkDisorderLaw (n+1) M) = _ at h + unfold bulkReplicaMean + rw [h] + apply integral_congr_ae + exact ae_of_all _ fun a => by + change gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r _ = + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v (bulkPermutePatterns (n+1) M e a).1 (bulkPermutePatterns (n+1) M e a).2) r _ + rw [bulkHamiltonian_permute] + +def bulkPatternFields {N M r : ℕ} (j : Fin M) (a : BulkDisorder N M) + (x : Fin r→NormalizedSpin N) : Fin r→ℝ := fun i => ∑ t, a.1 j t*(x i).val t + +lemma bulkPatternFields_measurable (N M r : ℕ) (j : Fin M) : + Measurable (Function.uncurry (bulkPatternFields (N:=N) (r:=r) j)) := by + have hc : Continuous (Function.uncurry (bulkPatternFields (N:=N) (r:=r) j)) := by + unfold bulkPatternFields Function.uncurry + fun_prop + exact hc.measurable + +lemma bulk_row_exchange (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + (G : (Fin r→NormalizedSpin (n+1))→ℝ) (hG : Measurable G) + (T : (Fin r→ℝ)→ℝ) (hT : Measurable T) (i j : Fin M) : + bulkReplicaMean n M f v r (fun a x => G x*T (bulkPatternFields i a x)) = + bulkReplicaMean n M f v r (fun a x => G x*T (bulkPatternFields j a x)) := by + classical + have hm : Measurable (Function.uncurry (fun a x => G x*T (bulkPatternFields j a x))) := + (hG.comp measurable_snd).mul (hT.comp (bulkPatternFields_measurable _ _ _ _)) + have h := bulkReplicaMean_permute n M f v r (Equiv.swap i j) _ hm + have hf : (fun a x => G x*T (bulkPatternFields j (bulkPermutePatterns (n+1) M (Equiv.swap i j) a) x)) = + (fun a x => G x*T (bulkPatternFields i a x)) := by + funext a x + change G x*T (fun l => ∑ t, a.1 ((Equiv.swap i j) j) t*(x l).val t) = + G x*T (fun l => ∑ t, a.1 i t*(x l).val t) + rw [Equiv.swap_apply_right] + rw [hf] at h + exact h + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkGoodParameters.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkGoodParameters.lean new file mode 100644 index 0000000000000000000000000000000000000000..05443bca648e70ce6ea64a4dae26b38450992c62 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkGoodParameters.lean @@ -0,0 +1,195 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkReplicaStein +import OAI.Probability.Perceptron.Variational.DiagonalDeviation + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def bulkDeviationAt (n M : ℕ) (f : ℝ→ᵇℝ) (p : ℕ) (v : ℕ→ℝ) : ℝ := + if hp : p ∫ v, bulkDeviationAt n (M n) f p v ∂bulkParameterLaw) atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall fun n => integral_nonneg (bulkDeviationAt_nonneg n (M n) f p)) _ + (bulkDeviationRate_tendsto A f p) + filter_upwards [eventually_ge_atTop p] with n hn + have hp : p ∫ v, omittedBulkDeviation α f n p v ∂bulkParameterLaw) atTop (𝓝 0) := by + apply bulkDeviationAt_integral_tendsto _ f hα _ p + intro n + calc + _ ≤ (patternCount α (n+1):ℝ) := by exact_mod_cast Nat.sub_le (patternCount α (n+1)) 2 + _ ≤ α*(n+1:ℕ) := Nat.floor_le (mul_nonneg hα (Nat.cast_nonneg _)) + +def bulkGoodSet (α : ℝ) (f : ℝ→ᵇℝ) (J : ℕ→ℕ) (n : ℕ) : Set (ℕ→ℝ) := + diagonalGoodSet bulkParameterLaw (omittedBulkDeviation α f) J n ∩ {v | ∀ p, v p∈Icc (1:ℝ) 2} + +lemma bulkGoodSet_measurable (α : ℝ) (f : ℝ→ᵇℝ) (J : ℕ→ℕ) (n : ℕ) : + MeasurableSet (bulkGoodSet α f J n) := by + refine (diagonalGoodSet_measurable _ _ (fun n p => bulkDeviationAt_measurable _ _ _ _) J n).inter ?_ + simp only [ofPred_forall] + exact MeasurableSet.iInter fun p => (measurable_pi_apply p) measurableSet_Icc + +lemma bulkGoodSet_compl_measure (α : ℝ) (f : ℝ→ᵇℝ) (J : ℕ→ℕ) (n : ℕ) : + bulkParameterLaw.real (bulkGoodSet α f J n)ᶜ = + bulkParameterLaw.real (diagonalGoodSet bulkParameterLaw (omittedBulkDeviation α f) J n)ᶜ := by + simp only [measureReal_def] + congr 1 + apply measure_congr + filter_upwards [bulkParameterLaw_ae] with v hv + apply propext + change ¬(v∈diagonalGoodSet bulkParameterLaw (omittedBulkDeviation α f) J n ∧ ∀ p, v p∈Icc (1:ℝ) 2) ↔ _ + exact not_congr ⟨fun h => h.1, fun h => ⟨h,hv⟩⟩ + +theorem exists_bulkGoodParameters {α : ℝ} (hα : 0≤α) (f : ℝ→ᵇℝ) : + ∃ J : ℕ→ℕ, Monotone J ∧ (∀ n, J n≤n) ∧ Tendsto J atTop atTop ∧ + (∀ n, MeasurableSet (bulkGoodSet α f J n)) ∧ + Tendsto (fun n => bulkParameterLaw.real (bulkGoodSet α f J n)ᶜ) atTop (𝓝 0) ∧ + (∀ v : ℕ→(ℕ→ℝ), (∀ᶠ n in atTop, v n∈bulkGoodSet α f J n) → + ∀ p, Tendsto (fun n => omittedBulkDeviation α f n p (v n)) atTop (𝓝 0)) := by + have hn : ∀ n p v, 0≤omittedBulkDeviation α f n p v := fun n p v => bulkDeviationAt_nonneg _ _ _ _ _ + have hi : ∀ n p, Integrable (omittedBulkDeviation α f n p) bulkParameterLaw := + fun n p => bulkDeviationAt_integrable _ _ _ _ + obtain ⟨J,hmon,hbound,hlim,hmass⟩ := exists_slow_diagonal + (fun n p => integral_nonneg (hn n p)) (omittedBulkDeviation_integral_tendsto hα f) + refine ⟨J,hmon,hbound,hlim,bulkGoodSet_measurable α f J,?_,?_⟩ + · simpa only [bulkGoodSet_compl_measure] using + diagonalGoodSet_compl_tendsto bulkParameterLaw (omittedBulkDeviation α f) hn hi J hmass + · intro v hv p + exact diagonalGoodSet_deviation_tendsto bulkParameterLaw (omittedBulkDeviation α f) hn J hlim hmass v + (hv.mono fun n h => h.1) p + + +lemma bulk_pairTest_measurable (n r : ℕ) (p : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) : + Measurable (fun x : Fin (r+1)→NormalizedSpin (n+1) => + G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^p) := + (hG.comp (Measurable.of_eval (fun replica => measurable_pi_apply replica.succ))).mul (bulkPowerPair_measurable _ _ _ _ _) + +lemma bulk_pairTest_bound (n r : ℕ) (p : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) + (x : Fin (r+1)→NormalizedSpin (n+1)) : + |G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^p|≤B := by + rw [abs_mul] + exact (mul_le_mul (hGB _) (bulkPowerPair_bound _ _ _ _ _ x) (abs_nonneg _) hB).trans_eq (mul_one B) + +lemma bulk_replica_ibp (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) : + (∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r + (fun x => bulkY (n+1) p a.2 (x j)*G x) ∂bulkDisorderLaw (n+1) M) = + bulkAmplitude (n+1) v p*( + bulkMoment n M f v r (fun x => G x*∑ l, spinOverlap (x j) (x l)^(p.val+1))- + r*bulkMoment n M f v (r+1) (fun x => G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^(p.val+1))) := by + have hUm : Measurable (fun x : Fin r→NormalizedSpin (n+1) => G x*∑ l, spinOverlap (x j) (x l)^(p.val+1)) := + hG.mul (Finset.measurable_sum _ fun l _ => bulkPowerPair_measurable _ _ _ _ _) + have hUI := bulkReplicaMean_integrable n M f v r hUm (mul_nonneg hB (Nat.cast_nonneg r)) + (bulkReplicaSum_bound (n+1) r (p.val+1) j hGB) + have hWI := bulkReplicaMean_integrable n M f v (r+1) (bulk_pairTest_measurable n r (p.val+1) j hG) hB + (bulk_pairTest_bound n r (p.val+1) j hB hGB) + rw [bulkDisorderLaw,integral_prod _ (bulkReplicaY_integrable n M f v p r j hG hB hGB)] + simp_rw [bulk_fixed_replica_ibp n M f v p r j hG hB hGB] + rw [integral_const_mul, integral_sub hUI.integral_prod_left (hWI.integral_prod_left.const_mul r),integral_const_mul] + rw [←integral_prod _ hUI,←integral_prod _ hWI] + rfl + +lemma bulk_energy_factorization (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) : + |bulkCoefficient (n+1) p*(∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) r (fun x => bulkY (n+1) p a.2 (x j)*G x) ∂bulkDisorderLaw (n+1) M)- + (∫ a, bulkCouplingSlope n M f v p (v (p.val+1)) a ∂bulkDisorderLaw (n+1) M)*bulkMoment n M f v r G|≤ + B*bulkDegreeDeviation n M f p v := by + have hc := (bulkCoefficient_pos n p).le + have hi : Integrable (fun a : BulkDisorder (n+1) M => bulkCoefficient (n+1) p*‖a.2‖) (bulkDisorderLaw (n+1) M) := + ((bulkMarkNorm_memLp n M).integrable (by norm_num)).const_mul _ + have hf := annealed_replica_energy_factorization_bound (unitSphereLaw (n+1)) (bulkDisorderLaw (n+1) M) + (H:=fun a x => bulkHamiltonian (n+1) M f v a.1 a.2 x) + (Y:=fun a x => bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x) + (bulkHamiltonian_continuous _ _ _ _).measurable ((bulkY_joint_measurable _ _ _).const_mul _) + (A:=fun a => M*‖f‖+bulkFeatureBound (n+1) v*‖a.2‖) + (B:=fun a => bulkCoefficient (n+1) p*‖a.2‖) + (fun a => by unfold bulkFeatureBound; positivity) (fun a => mul_nonneg hc (norm_nonneg _)) + (bulkHamiltonian_bound _ _ _ _) (fun a x => by + rw [abs_mul,abs_of_nonneg hc] + exact mul_le_mul_of_nonneg_left (bulkY_bound _ _ _ _) hc) hi j hG hB hGB + (∫ a, bulkCouplingSlope n M f v p (v (p.val+1)) a ∂bulkDisorderLaw (n+1) M) + simp only [mul_assoc,gibbsReplicaMean,tiltMean_const_mul_general,integral_const_mul] at hf + simpa only [bulkDegreeDeviation,bulkEnergyDeviation,Function.update_eq_self,bulkMoment,gibbsReplicaMean] using hf + +def bulkGGDefect (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p r : ℕ) (j : Fin r) + (G : (Fin r→NormalizedSpin (n+1))→ℝ) : ℝ := + bulkMoment n M f v r (fun x => G x*∑ l, spinOverlap (x j) (x l)^p)-bulkMoment n M f v r G+ + bulkMoment n M f v r G*bulkMoment n M f v 2 (fun x => spinOverlap (x 1) (x 0)^p)- + r*bulkMoment n M f v (r+1) (fun x => G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^p) + +lemma bulkGG_weighted_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) : + |bulkCoefficient (n+1) p^2*v (p.val+1)*bulkGGDefect n M f v (p.val+1) r j G|≤B*bulkDegreeDeviation n M f p v := by + have hf := bulk_energy_factorization n M f v p r j hG hB hGB + rw [bulk_replica_ibp n M f v p r j hG hB hGB,bulk_expected_slope_eq] at hf + simp only [Function.update_eq_self] at hf + convert hf using 1 + congr 1 + unfold bulkGGDefect bulkMoment bulkAmplitude bulkCoefficient + ring + +lemma bulkGG_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) + (hv : 1≤v (p.val+1)) : + |bulkGGDefect n M f v (p.val+1) r j G|≤B/(2:ℝ)^(-((p.val+1:ℕ):ℤ))*bulkNormalizedDeviation n M f p v := by + let c := bulkCoefficient (n+1) p + let θ : ℝ := (2:ℝ)^(-((p.val+1:ℕ):ℤ)) + have hc : 0 (Q i j).val)} := + (isClosed_matrix_posSemidef r).preimage (by fun_prop) + +lemma bulkGibbsArray_limit_gram (f : ℝ→ᵇℝ) (M : ℕ→ℕ) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) f (v (s n))) atTop (𝓝 ν)) : + ∀ᵐ Q : CompactArray CompactOverlap ∂(ν : Measure _), ∀ r, + Matrix.PosSemidef (fun i j : Fin r => (Q i j).val) := by + rw [ae_all_iff] + intro r + apply (mem_ae_iff_prob_eq_one (compact_scalar_gram_closed r).measurableSet).mpr + have hv := weak_limit_closed_full hlim (compact_scalar_gram_closed r) + (fun n => bulkGibbsArray_closed_full (s n) (M (s n)) f (v (s n)) + (compact_scalar_gram_closed r) (fun x => Matrix.posSemidef_gram ℝ (fun i : Fin r => (x i).val))) + simp only [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + +lemma bulkGibbsArray_limit_diagonal (f : ℝ→ᵇℝ) (M : ℕ→ℕ) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) f (v (s n))) atTop (𝓝 ν)) : + ∀ᵐ Q : CompactArray CompactOverlap ∂(ν : Measure _), ∀ i, (Q i i).val=1 := by + rw [ae_all_iff] + intro i + have hc : IsClosed {Q : CompactArray CompactOverlap | (Q i i).val=1} := + isClosed_eq (by fun_prop) continuous_const + apply (mem_ae_iff_prob_eq_one hc.measurableSet).mpr + have hv := weak_limit_closed_full hlim hc + (fun n => bulkGibbsArray_closed_full (s n) (M (s n)) f (v (s n)) hc + (fun x => spinOverlap_self (x i))) + simp only [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + +lemma bulkJointLaw_gram {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hR : ∀ᵐ Q : CompactArray CompactOverlap ∂(ν : Measure _), ∀ r, + Matrix.PosSemidef (fun i j : Fin r => (Q i j).val)) : + ∀ᵐ Q : CompactArray CompactJointOverlap ∂(bulkJointLaw ν : Measure _), ∀ r, + Matrix.PosSemidef (fun i j : Fin r => (Q i j).1.val) := by + apply (ae_map_iff (compactMapArray_continuous bulkJointEmbedding_continuous).measurable.aemeasurable + (show MeasurableSet {Q : CompactArray CompactJointOverlap | ∀ r, + Matrix.PosSemidef (fun i j : Fin r => (Q i j).1.val)} by + simp only [ofPred_forall] + exact MeasurableSet.iInter fun r => (compact_spin_gram_closed r).measurableSet)).mpr + exact hR + +lemma bulkJointLaw_diagonal {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hd : ∀ᵐ Q : CompactArray CompactOverlap ∂(ν : Measure _), ∀ i, (Q i i).val=1) : + ∀ᵐ Q : CompactArray CompactJointOverlap ∂(bulkJointLaw ν : Measure _), ∀ i, (Q i i).1.val=1 := by + apply (ae_map_iff (compactMapArray_continuous bulkJointEmbedding_continuous).measurable.aemeasurable + (show MeasurableSet {Q : CompactArray CompactJointOverlap | ∀ i, (Q i i).1.val=1} by + simp only [ofPred_forall] + exact MeasurableSet.iInter fun i => measurableSet_eq_fun (by fun_prop) measurable_const)).mpr + exact hd + +lemma omitted_bulk_limit_geometry (α : ℝ) (f : ℝ→ᵇℝ) (v : ℕ→ℕ→ℝ) + (hv : ∀ᶠ n in atTop, ∀ p, 1≤v n p) + (hd : ∀ p, Tendsto (fun n => omittedBulkDeviation α f n p (v n)) atTop (𝓝 0)) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} {s : ℕ→ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (patternCount α (s n+1)-2) f (v (s n))) atTop (𝓝 ν)) : + (∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) ∧ + (∀ᵐ Q : CompactArray CompactJointOverlap ∂(bulkJointLaw ν : Measure _), 0≤(Q 0 1).1.val) ∧ + (∀ r (i : Fin r) (F : CompactBlock CompactJointOverlap r→ᵇℝ) (g : CompactJointOverlap→ᵇℝ), + compactGGDefect (bulkJointLaw ν) r i F g=0) := by + have hGG := compactMapLaw_gg bulkJointEmbedding bulkJointEmbedding_continuous ν + (omitted_bulk_limit_gg α f v hv hd hs hlim) + have hR := bulkJointLaw_gram (bulkGibbsArray_limit_gram f (fun n => patternCount α (n+1)-2) v s hlim) + have hD := bulkJointLaw_diagonal (bulkGibbsArray_limit_diagonal f (fun n => patternCount α (n+1)-2) v s hlim) + have hEx (e : Equiv.Perm ℕ) := compactMapLaw_exchangeable bulkJointEmbedding bulkJointEmbedding_continuous ν e + (compact_exchangeability_limit hlim e (fun n => bulkGibbsArray_exchangeable (s n) + (patternCount α (s n+1)-2) f (v (s n)) e)) + exact ⟨compact_gg_spin_geometry _ hEx hGG hR hD, + compact_spin_nonnegative _ (compactRealLaw_gg _ hGG) hR,hGG⟩ + +lemma bulkJointLaw_scalarGram_integral (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (r : ℕ) (F : Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ) : + (∫ Q : CompactArray CompactJointOverlap, F (fun i j => (Q i j).1.val) ∂(bulkJointLaw ν : Measure _))= + ∫ Q : CompactArray CompactOverlap, F (fun i j => (Q i j).val) ∂(ν : Measure _) := by + exact compactMapLaw_integral bulkJointEmbedding bulkJointEmbedding_continuous ν + (fun Q => F (fun i j => (Q i j).1.val)) (F.continuous.comp (by fun_prop)).measurable + +lemma bulk_pair_restoration_ratio_tendsto (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (F : CompactOverlap →ᵇ ℝ) : + Tendsto (fun n => ∫ p, bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) + (compactPairTest F) (gaussianMixedTest (fun _ => 1)) (gaussianMixedTest (fun _ => 1)) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^2 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ Q : CompactArray CompactOverlap, F (Q 0 1) ∂(ν : Measure _))) := by + let q := boundedQuantile ((compactPositivePairLaw (bulkJointLaw ν)).map Prod.fst) + obtain ⟨ρ,η,hG,hge,hp,hm,hl⟩ := quantile_pair_reference_exists q (boundedQuantile_monotone _) g F + have hpair := (compactPositivePairLaw_spin_quantile (bulkJointLaw ν) hn).trans hp.symm + have he (j : ℕ) : (∫ x, x.1.val*x.2.val^j + ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))= + ∫ Q : CompactArray CompactOverlap, scalarRestorationPairMoment g.f 1 1 F j + (fun i l => (Q i l).val) ∂(ν : Measure _) := by + rw [hm j,←scalarGram_eq_of_pair_law (bulkJointLaw ν) ρ hGG hG hgeo hge hpair] + exact bulkJointLaw_scalarGram_integral ν _ _ + let Ψ : EuclideanSpace ℝ (Fin 2) →ᵇ ℝ := gaussianMixedTest (fun _ => (1 : ℝ →ᵇ ℝ)) + let C := ‖compactPairTest F‖*‖restorationMarkTest 2 g.f Ψ 0‖*‖restorationMarkTest 2 g.f Ψ 0‖+ + pairRestorationBound g.f 1 1 F + have hC : 0≤C := add_nonneg (by positivity) (pairRestorationBound_nonneg _ _ _ _) + have hηB (x : WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F)) : |x.1.val|≤C := + (abs_le.mpr x.1.prop).trans (le_add_of_nonneg_left (by positivity)) + have hb (n : ℕ) (p : TwoFreshDisorder (s n+1) (M (s n))) : + |bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) (compactPairTest F) Ψ Ψ p|≤C := + (bulkFreshNumerator_bound _ _ _ _ _ _ _ _ _).trans + (le_add_of_nonneg_right (pairRestorationBound_nonneg _ _ _ _)) + have hmoment j : Tendsto (fun n => ∫ p, + bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) (compactPairTest F) Ψ Ψ p * + (bulkFreshCompactDenominator (s n) (M (s n)) g.f (v (s n)) p).val^j + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))) := by + rw [he j] + simp_rw [scalarRestorationPairMoment_compact] + exact bulkFresh_moment_tendsto M g.f v s hlim 2 (compactPairTest F) Ψ Ψ j + have ht := restoration_ratio_tendsto + (fun n => twoFreshDisorderLaw (s n+1) (M (s n))) + (η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))) + (Real.exp_pos _) + (fun n => bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) (compactPairTest F) Ψ Ψ) + (fun x => x.1.val) + (fun n => bulkFreshCompactDenominator (s n) (M (s n)) g.f (v (s n))) (fun x => x.2) + (fun n => bulkFreshNumerator_measurable _ _ _ _ _ _ _ _) (by fun_prop) + (fun n => bulkFreshCompactDenominator_measurable _ _ _ _) (by fun_prop) + hC hb hηB hmoment 2 + have hvalue : (∫ x,x.1.val/x.2.val^2 + ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))= + ∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(ν : Measure _) := by + simp only [div_eq_mul_inv] + change (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))=_ + rw [hl,←compactPositivePairLaw_spin_quantile (bulkJointLaw ν) hn] + have hi := integral_map (μ := (bulkJointLaw ν : Measure (CompactArray CompactJointOverlap))) + (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) + from by fun_prop).aemeasurable + (show Measurable (fun z : CompactOverlap => F z) from F.continuous.measurable).aestronglyMeasurable + refine hi.trans ?_ + exact compactMapLaw_integral bulkJointEmbedding bulkJointEmbedding_continuous ν + (fun Q => F (Q 0 1).1) (by fun_prop) + rw [hvalue] at ht + exact ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedArray.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedArray.lean new file mode 100644 index 0000000000000000000000000000000000000000..baa71e4732ceb1b7032d62c53b86c8657b7de4ca --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedArray.lean @@ -0,0 +1,230 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkAnnealedTangent +import OAI.Probability.Perceptron.Cavity.BulkPairLaw +import OAI.Probability.Perceptron.Interpolation.AnnealedMarkedReplica + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction ContDiff + +lemma bulkB_measurable (N M : ℕ) (f : Jet3) : + Measurable (fun p : BulkDisorder N M×(NormalizedSpin N×NormalizedSpin N) => + bulkB N M f p.1.1 p.2.1 p.2.2) := by + unfold bulkB + fun_prop + +lemma bulkB_pairAverage (n M : ℕ) (f : Jet3) (a : BulkDisorder (n+1) M) + (x : Fin 2→NormalizedSpin (n+1)) : + bulkB (n+1) M f a.1 (x 0) (x 1)=bulkPairAverage n M f.d1 a x := by + simp only [bulkB,bulkPairAverage,pairFieldMark,Fin.prod_univ_two,bulkPatternFields] + +lemma bulkB_symm (N M : ℕ) (f : Jet3) (a : Fin M→Fin N→ℝ) (x y : NormalizedSpin N) : + bulkB N M f a x y=bulkB N M f a y x := by + unfold bulkB + simp_rw [mul_comm (f.d1 _) (f.d1 _)] + +def bulkMarkedEntry (n M : ℕ) (f : Jet3) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) (a : BulkDisorder (n+1) M) + (x y : NormalizedSpin (n+1)) : BulkPairRange K := + (bulkOverlap x y,⟨bulkB (n+1) M f a.1 x y,abs_le.mp ((bulkB_bound _ _ _ _ _ _).trans hK)⟩) + +def bulkMarkedArray (n M : ℕ) (f : Jet3) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) + (p : BulkDisorder (n+1) M×(ℕ→NormalizedSpin (n+1))) : CompactArray (BulkPairRange K) := + fun i j => bulkMarkedEntry n M f K hK p.1 (p.2 i) (p.2 j) + +lemma bulkMarkedArray_measurable (n M : ℕ) (f : Jet3) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) : Measurable (bulkMarkedArray n M f K hK) := by + refine Measurable.of_eval fun i => Measurable.of_eval fun j => ?_ + have hm : Measurable (fun p : BulkDisorder (n+1) M×(ℕ→NormalizedSpin (n+1)) => (p.2 i,p.2 j)) := by fun_prop + exact ((bulkOverlap_measurable _).comp hm).prodMk + (((bulkB_measurable _ _ _).comp (measurable_fst.prodMk hm)).subtype_mk) + +def bulkGibbsHamiltonian (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + BulkDisorder (n+1) M→NormalizedSpin (n+1)→ℝ := + fun a => bulkHamiltonian (n+1) M f v a.1 a.2 + +lemma bulkGibbsHamiltonian_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + Measurable (Function.uncurry (bulkGibbsHamiltonian n M f v)) := + (bulkHamiltonian_continuous (n+1) M f v).measurable + +def bulkMarkedArrayLaw (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) : ProbabilityMeasure (CompactArray (BulkPairRange K)) := + ⟨(annealedInfiniteReplicaMeasure (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (bulkGibbsHamiltonian n M f.f v) (bulkGibbsHamiltonian_measurable n M f.f v)).map + (bulkMarkedArray n M f K hK), + (Measure.isProbabilityMeasure_map_iff (bulkMarkedArray_measurable _ _ _ _ _).aemeasurable).2 inferInstance⟩ + +lemma bulkMarkedArray_block (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) (r : ℕ) (F : CompactBlock (BulkPairRange K) r→ᵇℝ) : + (∫ Q,F (compactBlock r Q) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _))= + bulkReplicaMean n M f.f v r (fun a x => F (fun i j => bulkMarkedEntry n M f K hK a (x i) (x j))) := by + change (∫ Q,F (compactBlock r Q) ∂Measure.map (bulkMarkedArray n M f K hK) + (annealedInfiniteReplicaMeasure (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (bulkGibbsHamiltonian n M f.f v) (bulkGibbsHamiltonian_measurable n M f.f v)))=_ + have hm : Measurable (fun Q : CompactArray (BulkPairRange K) => F (compactBlock r Q)) := + F.measurable.comp (compactBlock_continuous r).measurable + rw [integral_map (bulkMarkedArray_measurable n M f K hK).aemeasurable hm.aestronglyMeasurable] + unfold bulkReplicaMean + apply annealedInfiniteReplica_marked_prefix (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (bulkGibbsHamiltonian n M f.f v) (bulkGibbsHamiltonian_measurable n M f.f v) + (ae_of_all _ (bulkHamiltonian_exp_integrable n M f.f v)) r + (G := fun a x => F (fun i j => bulkMarkedEntry n M f K hK a (x i) (x j))) + · apply F.measurable.comp + refine Measurable.of_eval fun i => Measurable.of_eval fun j => ?_ + have hm : Measurable (fun p : BulkDisorder (n+1) M×(Fin r→NormalizedSpin (n+1)) => (p.2 i,p.2 j)) := by fun_prop + exact ((bulkOverlap_measurable _).comp hm).prodMk + (((bulkB_measurable _ _ _).comp (measurable_fst.prodMk hm)).subtype_mk) + · intro a x + exact F.norm_coe_le_norm _ + +lemma bulkMarkedArray_exchangeable (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) (e : Equiv.Perm ℕ) : + MeasurePreserving (compactRelabel (K:=BulkPairRange K) e) + (bulkMarkedArrayLaw n M f v K hK : Measure _) (bulkMarkedArrayLaw n M f v K hK : Measure _) := by + have hr := annealedInfiniteReplica_reindex (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (bulkGibbsHamiltonian n M f.f v) (bulkGibbsHamiltonian_measurable n M f.f v) e + have hm := bulkMarkedArray_measurable n M f K hK + refine ⟨(compactRelabel_continuous e).measurable,?_⟩ + change Measure.map _ (Measure.map (bulkMarkedArray n M f K hK) _)=_ + rw [Measure.map_map (compactRelabel_continuous e).measurable hm] + change Measure.map ((bulkMarkedArray n M f K hK) ∘ + (fun a : BulkDisorder (n+1) M×(ℕ→NormalizedSpin (n+1)) => (a.1,fun i => a.2 (e i)))) _=_ + rw [←Measure.map_map hm hr.measurable,hr.map_eq] + rfl + +lemma bulkMarkedArray_overlap (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) : + compactMapLaw Prod.fst continuous_fst (bulkMarkedArrayLaw n M f v K hK)=bulkGibbsArrayLaw n M f.f v := by + apply Subtype.ext + change Measure.map (fun Q : CompactArray (BulkPairRange K) => fun i j => (Q i j).1) + (Measure.map (bulkMarkedArray n M f K hK) _) = _ + rw [Measure.map_map (by fun_prop) (bulkMarkedArray_measurable _ _ _ _ _)] + rfl + +lemma bulkMarkedArray_pair (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) : + (bulkMarkedArrayLaw n M f v K hK).map (fun Q => Q 1 0)= + bulkPairLaw n M f.f f.d1 v K hK := by + apply ProbabilityMeasure.toMeasure_injective + apply ext_of_forall_integral_eq_of_IsFiniteMeasure + intro F + rw [ProbabilityMeasure.toMeasure_map,integral_map (by fun_prop : Measurable (fun Q : CompactArray (BulkPairRange K)=>Q 1 0)).aemeasurable F.continuous.aestronglyMeasurable, + bulkPairLaw_integral] + let T : CompactBlock (BulkPairRange K) 2→ᵇℝ := F.compContinuous ⟨fun Q=>Q 1 0,by fun_prop⟩ + have he := bulkMarkedArray_block n M f v K hK 2 T + change (∫ Q : CompactArray (BulkPairRange K),F (Q 1 0) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _))=_ at he + rw [he] + unfold bulkReplicaMean + apply integral_congr_ae + exact ae_of_all _ fun a => by + apply congrArg (gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f.f v a.1 a.2) 2) + funext x + apply congrArg F + change bulkMarkedEntry n M f K hK a (x 1) (x 0) = bulkCompactPair n M f.d1 K hK (a,x) + apply Prod.ext + · rfl + · apply Subtype.ext + exact (bulkB_symm _ _ _ _ _ _).trans (bulkB_pairAverage _ _ _ a x) + +def markedTangentR (K : ℝ) (G : ℝ→ᵇℝ) : CompactBlock (BulkPairRange K) 2→ᵇℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun Q => (Q 0 1).1.val*G (Q 0 1).1.val,by fun_prop⟩ +def markedTangentPair (K : ℝ) (G : ℝ→ᵇℝ) : CompactBlock (BulkPairRange K) 2→ᵇℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun Q => G (Q 0 1).1.val*(Q 0 1).2.val*(1-(Q 0 1).1.val^2),by fun_prop⟩ +def markedTangentTriple (K : ℝ) (G : ℝ→ᵇℝ) : CompactBlock (BulkPairRange K) 3→ᵇℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun Q => G (Q 1 2).1.val*(Q 1 0).2.val*((Q 2 0).1.val-(Q 1 2).1.val*(Q 1 0).1.val),by fun_prop⟩ + +lemma bulk_tangent_pair_sum (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) : + (∑ j : Fin M,bulkReplicaMean n M f.f v 2 (fun a => freshTangentPair (n+1) f G (WithLp.toLp 2 (a.1 j))))= + (n+1:ℕ)*(∫ Q,markedTangentPair K G (compactBlock 2 Q) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _)) := by + have hm (j : Fin M) : Measurable (Function.uncurry (fun a : BulkDisorder (n+1) M => freshTangentPair (n+1) f G (WithLp.toLp 2 (a.1 j)))) := by + have hc : Continuous (Function.uncurry (fun a : BulkDisorder (n+1) M => freshTangentPair (n+1) f G (WithLp.toLp 2 (a.1 j)))) := by + unfold Function.uncurry freshTangentPair spinOverlap + fun_prop + exact hc.measurable + have hs := bulkReplicaMean_sum n M 2 f.f v Finset.univ + (fun j a => freshTangentPair (n+1) f G (WithLp.toLp 2 (a.1 j))) + (fun j _ => hm j) + (fun _ => 2*‖G‖*‖f.d1‖^2) (by intros; positivity) + (fun j _ a x => freshTangentPair_bound _ _ _ _ x) + rw [←hs,bulkMarkedArray_block,←bulkReplicaMean_const_mul] + apply congrArg (bulkReplicaMean n M f.f v 2) + funext a x + change (∑ j : Fin M,G (spinOverlap (x 0) (x 1))*f.d1 (inner ℝ (x 0).val (WithLp.toLp 2 (a.1 j)))* + f.d1 (inner ℝ (x 1).val (WithLp.toLp 2 (a.1 j)))*(1-spinOverlap (x 0) (x 1)^2))= + ((n+1:ℕ):ℝ)*(G (spinOverlap (x 0) (x 1))*bulkB (n+1) M f a.1 (x 0) (x 1)*(1-spinOverlap (x 0) (x 1)^2)) + have he (z : NormalizedSpin (n+1)) (j : Fin M) : inner ℝ z.val (WithLp.toLp 2 (a.1 j))=∑ i,a.1 j i*z.val i := by + simp only [EuclideanSpace.inner_eq_star_dotProduct,star_trivial,dotProduct] + simp_rw [he] + unfold bulkB + have hn : ((n+1:ℕ):ℝ)≠0 := by positivity + simp_rw [mul_assoc (G _)] + rw [←Finset.mul_sum,←Finset.sum_mul] + field_simp + +lemma bulk_tangent_triple_sum (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) : + (∑ j : Fin M,bulkReplicaMean n M f.f v 3 (fun a => freshTangentTriple (n+1) f G (WithLp.toLp 2 (a.1 j))))= + (n+1:ℕ)*(∫ Q,markedTangentTriple K G (compactBlock 3 Q) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _)) := by + have hm (j : Fin M) : Measurable (Function.uncurry (fun a : BulkDisorder (n+1) M => freshTangentTriple (n+1) f G (WithLp.toLp 2 (a.1 j)))) := by + have hc : Continuous (Function.uncurry (fun a : BulkDisorder (n+1) M => freshTangentTriple (n+1) f G (WithLp.toLp 2 (a.1 j)))) := by + unfold Function.uncurry freshTangentTriple spinOverlap + fun_prop + exact hc.measurable + have hs := bulkReplicaMean_sum n M 3 f.f v Finset.univ + (fun j a => freshTangentTriple (n+1) f G (WithLp.toLp 2 (a.1 j))) + (fun j _ => hm j) + (fun _ => 2*‖G‖*‖f.d1‖^2) (by intros; positivity) + (fun j _ a x => freshTangentTriple_bound _ _ _ _ x) + rw [←hs,bulkMarkedArray_block,←bulkReplicaMean_const_mul] + apply congrArg (bulkReplicaMean n M f.f v 3) + funext a x + change (∑ j : Fin M,G (spinOverlap (x 1) (x 2))*f.d1 (inner ℝ (x 1).val (WithLp.toLp 2 (a.1 j)))* + f.d1 (inner ℝ (x 0).val (WithLp.toLp 2 (a.1 j)))*(spinOverlap (x 2) (x 0)-spinOverlap (x 1) (x 2)*spinOverlap (x 1) (x 0)))= + ((n+1:ℕ):ℝ)*(G (spinOverlap (x 1) (x 2))*bulkB (n+1) M f a.1 (x 1) (x 0)*(spinOverlap (x 2) (x 0)-spinOverlap (x 1) (x 2)*spinOverlap (x 1) (x 0))) + have he (z : NormalizedSpin (n+1)) (j : Fin M) : inner ℝ z.val (WithLp.toLp 2 (a.1 j))=∑ i,a.1 j i*z.val i := by + simp only [EuclideanSpace.inner_eq_star_dotProduct,star_trivial,dotProduct] + simp_rw [he] + unfold bulkB + have hn : ((n+1:ℕ):ℝ)≠0 := by positivity + simp_rw [mul_assoc (G _)] + rw [←Finset.mul_sum,←Finset.sum_mul] + field_simp + +lemma bulk_marked_tangent_bound (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) + (hG : ContDiff ℝ 1 (G : ℝ→ℝ)) {C : ℝ} (hC : 0≤C) (hv : ∀ j,|v (j+1)|≤C) + (K : ℝ) (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) + {D : ℝ} (hD : 0≤D) (hbD : ∀ r : CompactOverlap,|deriv (G : ℝ→ℝ) r.val*(1-r.val^2)|≤D) : + |(∫ Q,markedTangentR K G (compactBlock 2 Q) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _))- + (∫ Q,markedTangentPair K G (compactBlock 2 Q) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _))+ + 2*(∫ Q,markedTangentTriple K G (compactBlock 3 Q) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _))|≤ + (‖G‖+D+8*‖G‖*C^2*bulkScale (n+1)^2)/(n+1:ℕ) := by + have ht := bulk_tangent_annealed n M f v G hG hC hv + rw [Finset.sum_sub_distrib,←Finset.mul_sum,bulk_tangent_pair_sum n M f v G K hK,bulk_tangent_triple_sum n M f v G K hK] at ht + have hr := bulkMarkedArray_block n M f v K hK 2 (markedTangentR K G) + change (∫ Q,markedTangentR K G (compactBlock 2 Q) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _))= + bulkReplicaMean n M f.f v 2 (fun _ x => spinOverlap (x 0) (x 1)*G (spinOverlap (x 0) (x 1))) at hr + rw [←hr] at ht + have hdb := bulkReplicaMean_bound n M 2 f.f v (fun _ => tangentDerivTest (n+1) G) + ((tangentDerivTest_continuous (n+1) G hG).measurable.comp measurable_snd) hD (fun _ x => hbD (bulkOverlap (x 0) (x 1))) + have hrb : |∫ Q,markedTangentR K G (compactBlock 2 Q) ∂(bulkMarkedArrayLaw n M f v K hK : Measure _)|≤‖G‖ := by + have hb : ∀ Q : CompactArray (BulkPairRange K),‖markedTangentR K G (compactBlock 2 Q)‖≤‖G‖ := by + intro Q + change |(Q 0 1).1.val*G (Q 0 1).1.val|≤‖G‖ + rw [abs_mul] + exact (mul_le_mul (abs_le.mpr (Q 0 1).1.property) (G.norm_coe_le_norm _) (abs_nonneg _) (by norm_num : (0:ℝ)≤1)).trans (by simp) + simpa [Real.norm_eq_abs,Measure.real] using norm_integral_le_of_norm_le_const (ae_of_all (bulkMarkedArrayLaw n M f v K hK : Measure _) hb) + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + rw [le_div_iff₀ hn,←abs_of_pos hn,←abs_mul] + have halg (X Y Z W : ℝ) : (X-Y+2*Z)*(n+1:ℕ)=X+W+((n:ℝ)*X-W-((n+1:ℕ)*Y-2*((n+1:ℕ)*Z))) := by push_cast; ring + rw [halg] + exact (abs_add_le _ _).trans (add_le_add ((abs_add_le _ _).trans (add_le_add hrb hdb)) ht) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedMoments.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..dea64a4c83024f04b4cf68898a2dac0f6539b98d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedMoments.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkModel +import OAI.Probability.Perceptron.Interpolation.GaussianReplicaFubini + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def freshMarkedCompactBlockKernel {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r)→ᵇℝ) : + CompactBlock CompactOverlap r→ᵇℝ := + (freshMarkedMatrixKernel Ψ).compContinuous ⟨fun Q => fun i j => (Q i j).val,by fun_prop⟩ + +lemma freshMarkedCompactBlockKernel_spin {N r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r)→ᵇℝ) + (x : Fin r→NormalizedSpin N) : + freshMarkedCompactBlockKernel Ψ (fun i j => bulkOverlap (x i) (x j)) = + freshMarkedMatrixKernel Ψ (Matrix.gram ℝ (fun i => (x i).val)) := rfl + +lemma bulk_twoFresh_block (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (F : CompactBlock CompactOverlap r→ᵇℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r)→ᵇℝ) : + (∫ a, ∫ z, gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) r + (fun x => F (fun i j => bulkOverlap (x i) (x j))* + Ψ (gaussianRows (fun i => (x i).val) z.1)*Φ (gaussianRows (fun i => (x i).val) z.2)) + ∂(stdGaussian (EuclideanSpace ℝ (Fin (n+1)))).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)))) + ∂bulkDisorderLaw (n+1) M) = + ∫ Q, (F*freshMarkedCompactBlockKernel Ψ*freshMarkedCompactBlockKernel Φ) (compactBlock r Q) + ∂bulkGibbsArrayLaw n M f v := by + rw [bulkGibbsArray_block] + apply integral_congr_ae + refine ae_of_all _ fun a => ?_ + have hc : Continuous (fun x : Fin r→NormalizedSpin (n+1) => F (fun i j => bulkOverlap (x i) (x j))) := by + apply F.continuous.comp + unfold bulkOverlap spinOverlap + fun_prop + have hG := hc.measurable + have h := gibbs_twoFreshReplica_fubini (unitSphereLaw (n+1)) + ((bulkHamiltonian_continuous (n+1) M f v).measurable.comp (measurable_const.prodMk measurable_id)) + (bulkHamiltonian_exp_integrable n M f v a) (fun x : NormalizedSpin (n+1) => x.val) + continuous_subtype_val (fun x => F (fun i j => bulkOverlap (x i) (x j))) hG + (norm_nonneg F) (fun x => F.norm_coe_le_norm _) Ψ Φ + simpa only [Function.comp_def,id_eq,BoundedContinuousFunction.mul_apply,freshMarkedCompactBlockKernel_spin] using h + +lemma bulk_twoFresh_block_tendsto (M : ℕ→ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hν : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) f (v (s n))) atTop (𝓝 ν)) + (r : ℕ) (F : CompactBlock CompactOverlap r→ᵇℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r)→ᵇℝ) : + Tendsto (fun n => ∫ a, ∫ z, gibbsReplicaMean (unitSphereLaw (s n+1)) + (bulkHamiltonian (s n+1) (M (s n)) f (v (s n)) a.1 a.2) r + (fun x => F (fun i j => bulkOverlap (x i) (x j))* + Ψ (gaussianRows (fun i => (x i).val) z.1)*Φ (gaussianRows (fun i => (x i).val) z.2)) + ∂(stdGaussian (EuclideanSpace ℝ (Fin (s n+1)))).prod (stdGaussian (EuclideanSpace ℝ (Fin (s n+1)))) + ∂bulkDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ Q, (F*freshMarkedCompactBlockKernel Ψ*freshMarkedCompactBlockKernel Φ) (compactBlock r Q) ∂ν)) := by + simp_rw [bulk_twoFresh_block] + exact (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + ((F*freshMarkedCompactBlockKernel Ψ*freshMarkedCompactBlockKernel Φ).compContinuous + ⟨compactBlock r,compactBlock_continuous r⟩)).continuousAt.tendsto.comp hν + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedPairLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedPairLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6854d91378169008d34d129cadb3709d363b0d6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedPairLimit.lean @@ -0,0 +1,212 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkLimitGeometry +import OAI.Probability.Perceptron.Variational.RoundedMarkedReference + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma bulk_marked_ratio_tendsto_of_reference (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (w w' : ℝ→ᵇℝ) (F : CompactOverlap→ᵇℝ) + (η : ProbabilityMeasure (WeightedRestorationRange g.f (pairRestorationBound g.f w w' F))) + (hm : ∀ j,(∫ x,x.1.val*x.2.val^j + ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f w w' F))))= + ∫ Q : CompactArray CompactOverlap,scalarRestorationPairMoment g.f w w' F j + (fun i l => (Q i l).val) ∂(ν : Measure _)) : + Tendsto (fun n => ∫ p,bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) + (compactPairTest F) (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>w')) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^2 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 + ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f w w' F))))) := by + let Ψ : EuclideanSpace ℝ (Fin 2) →ᵇ ℝ := gaussianMixedTest (fun _ => w) + let Φ : EuclideanSpace ℝ (Fin 2) →ᵇ ℝ := gaussianMixedTest (fun _ => w') + let C := ‖compactPairTest F‖*‖restorationMarkTest 2 g.f Ψ 0‖*‖restorationMarkTest 2 g.f Φ 0‖+ + pairRestorationBound g.f w w' F + have hC : 0≤C := add_nonneg (by positivity) (pairRestorationBound_nonneg _ _ _ _) + have hηB (x : WeightedRestorationRange g.f (pairRestorationBound g.f w w' F)) : |x.1.val|≤C := + (abs_le.mpr x.1.prop).trans (le_add_of_nonneg_left (by positivity)) + have hb (n : ℕ) (p : TwoFreshDisorder (s n+1) (M (s n))) : + |bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) (compactPairTest F) Ψ Φ p|≤C := + (bulkFreshNumerator_bound _ _ _ _ _ _ _ _ _).trans + (le_add_of_nonneg_right (pairRestorationBound_nonneg _ _ _ _)) + have hmoment j : Tendsto (fun n => ∫ p, + bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) (compactPairTest F) Ψ Φ p * + (bulkFreshCompactDenominator (s n) (M (s n)) g.f (v (s n)) p).val^j + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f w w' F))))) := by + rw [hm j] + simp_rw [scalarRestorationPairMoment_compact] + exact bulkFresh_moment_tendsto M g.f v s hlim 2 (compactPairTest F) Ψ Φ j + have ht := restoration_ratio_tendsto + (fun n => twoFreshDisorderLaw (s n+1) (M (s n))) + (η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f w w' F))) + (Real.exp_pos _) + (fun n => bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) (compactPairTest F) Ψ Φ) + (fun x => x.1.val) + (fun n => bulkFreshCompactDenominator (s n) (M (s n)) g.f (v (s n))) (fun x => x.2) + (fun n => bulkFreshNumerator_measurable _ _ _ _ _ _ _ _) (by fun_prop) + (fun n => bulkFreshCompactDenominator_measurable _ _ _ _) (by fun_prop) + hC hb hηB hmoment 2 + simpa only [div_eq_mul_inv, restorationReciprocal, ContinuousMap.coe_mk, bulkFreshCompactDenominator, Ψ, Φ] using ht + +theorem bulk_marked_pair_limit_exists (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (w : ℝ→ᵇℝ) : ∃ a : ℝ→ℝ, Monotone a ∧ (∀ r,0≤a r ∧ a r≤‖w‖^2) ∧ + ∀ (F : CompactOverlap→ᵇℝ) (b : Bool), + Tendsto (fun n => ∫ p,bulkFreshNumerator (s n) (M (s n)) 2 g.f (v (s n)) + (compactPairTest F) (gaussianMixedTest (fun _=>w)) + (gaussianMixedTest (fun _=>secondPairMark w b)) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^2 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ Q : CompactArray CompactOverlap,F (Q 0 1)*(a (Q 0 1).val)^(pairMarkPower b) ∂(ν : Measure _))) := by + let q := boundedQuantile ((compactPositivePairLaw (bulkJointLaw ν)).map Prod.fst) + have hq : Monotone q := boundedQuantile_monotone _ + obtain ⟨a,ham,hab,href⟩ := quantile_marked_pair_reference_exists q hq g w + refine ⟨a,ham,hab,fun F b => ?_⟩ + obtain ⟨ρ,η,hG,hge,hp,hm,hl⟩ := href F b + have hpair := (compactPositivePairLaw_spin_quantile (bulkJointLaw ν) hn).trans hp.symm + have he (j : ℕ) : (∫ x,x.1.val*x.2.val^j + ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f w (secondPairMark w b) F))))= + ∫ Q : CompactArray CompactOverlap,scalarRestorationPairMoment g.f w (secondPairMark w b) F j + (fun i l => (Q i l).val) ∂(ν : Measure _) := by + rw [hm j,←scalarGram_eq_of_pair_law (bulkJointLaw ν) ρ hGG hG hgeo hge hpair] + exact bulkJointLaw_scalarGram_integral ν _ _ + have ht := bulk_marked_ratio_tendsto_of_reference M g v s hlim w (secondPairMark w b) F η he + rw [hl] at ht + have hmG : Measurable (fun z : CompactOverlap => F z*(a z.val)^(pairMarkPower b)) := + F.measurable.mul ((ham.measurable.comp measurable_subtype_coe).pow_const _) + have hvalue : (∫ u,F (timeSpin (q u))*(a (q u))^(pairMarkPower b) ∂timeLaw)= + ∫ Q : CompactArray CompactOverlap,F (Q 0 1)*(a (Q 0 1).val)^(pairMarkPower b) ∂(ν : Measure _) := by + change (∫ u,F (timeSpin (q u))*(a (timeSpin (q u)).val)^(pairMarkPower b) ∂timeLaw)=_ + rw [←quantileSpinLaw_integral q hq.measurable (fun z => F z*(a z.val)^(pairMarkPower b)) hmG, + ←compactPositivePairLaw_spin_quantile (bulkJointLaw ν) hn] + have hi := integral_map (μ := (bulkJointLaw ν : Measure (CompactArray CompactJointOverlap))) + (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) + from by fun_prop).aemeasurable hmG.aestronglyMeasurable + refine hi.trans ?_ + exact compactMapLaw_integral bulkJointEmbedding bulkJointEmbedding_continuous ν + (fun Q => F (Q 0 1).1*(a (Q 0 1).1.val)^(pairMarkPower b)) + (F.measurable.comp (by fun_prop) |>.mul ((ham.measurable.comp (by fun_prop)).pow_const _)) + rwa [hvalue] at ht + +def pairFieldMark (w : ℝ→ᵇℝ) (z : Fin 2→ℝ) : ℝ := ∏ i,w (z i) +lemma pairFieldMark_measurable (w : ℝ→ᵇℝ) : Measurable (pairFieldMark w) := by + unfold pairFieldMark + fun_prop +lemma pairFieldMark_bound (w : ℝ→ᵇℝ) (z : Fin 2→ℝ) : |pairFieldMark w z|≤‖w‖^2 := by + simp only [pairFieldMark,Fin.prod_univ_two,abs_mul,pow_two] + exact mul_le_mul (w.norm_coe_le_norm _) (w.norm_coe_le_norm _) (abs_nonneg _) (norm_nonneg _) + +def bulkPairAverage (n M : ℕ) (w : ℝ→ᵇℝ) (a : BulkDisorder (n+1) M) + (x : Fin 2→NormalizedSpin (n+1)) : ℝ := + ((n+1:ℕ):ℝ)⁻¹*∑ i,pairFieldMark w (bulkPatternFields i a x) + +lemma bulkPairAverage_measurable (n M : ℕ) (w : ℝ→ᵇℝ) : + Measurable (Function.uncurry (bulkPairAverage n M w)) := by + apply Measurable.const_mul + exact Finset.measurable_sum _ fun i _ => (pairFieldMark_measurable w).comp (bulkPatternFields_measurable _ _ _ _) + +lemma bulkPairAverage_bound (n M : ℕ) (w : ℝ→ᵇℝ) (a : BulkDisorder (n+1) M) + (x : Fin 2→NormalizedSpin (n+1)) : |bulkPairAverage n M w a x|≤M/(n+1:ℕ)*‖w‖^2 := by + unfold bulkPairAverage + rw [abs_mul,abs_of_nonneg (by positivity : 0≤(((n+1:ℕ):ℝ)⁻¹))] + have h : |∑ i : Fin M,pairFieldMark w (bulkPatternFields i a x)|≤M*‖w‖^2 := + (Finset.abs_sum_le_sum_abs _ _).trans ((Finset.sum_le_sum fun i _ => pairFieldMark_bound w _).trans_eq (by simp)) + exact (mul_le_mul_of_nonneg_left h (by positivity)).trans_eq (by ring) + +def bulkPairOverlapTest (n : ℕ) (F : CompactOverlap→ᵇℝ) (x : Fin 2→NormalizedSpin (n+1)) : ℝ := + F (bulkOverlap (x 1) (x 0)) +lemma bulkPairOverlapTest_measurable (n : ℕ) (F : CompactOverlap→ᵇℝ) : Measurable (bulkPairOverlapTest n F) := by + unfold bulkPairOverlapTest bulkOverlap spinOverlap + fun_prop + +lemma bulk_last_two_fields (n M : ℕ) (a : BulkDisorder (n+1) (M+2)) + (x : Fin 2→NormalizedSpin (n+1)) : + (fun i => gaussianRows (fun i => (x i).val) (bulkSeparateTwo (n+1) M a).2.1 i)= + bulkPatternFields ((Fin.last M).castSucc) a x ∧ + (fun i => gaussianRows (fun i => (x i).val) (bulkSeparateTwo (n+1) M a).2.2 i)= + bulkPatternFields (Fin.last (M+1)) a x := by + constructor <;> funext i <;> + simp only [gaussianRows_apply,bulkSeparateTwo,bulkSeparateLast,bulkPatternFields, + EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial] + +lemma bulk_marked_last_pair (n M : ℕ) (f w w' : ℝ→ᵇℝ) (v : ℕ→ℝ) + (F : CompactOverlap→ᵇℝ) : + bulkReplicaMean n (M+2) f v 2 (fun a x => bulkPairOverlapTest n F x* + pairFieldMark w (bulkPatternFields ((Fin.last M).castSucc) a x)* + pairFieldMark w' (bulkPatternFields (Fin.last (M+1)) a x))= + ∫ p,bulkFreshNumerator n M 2 f v (compactPairTest F) + (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>w')) p / + bulkFreshDenominator n M f v p^2 ∂twoFreshDisorderLaw (n+1) M := by + rw [←bulkFresh_annealed_restoration] + unfold bulkReplicaMean + apply integral_congr_ae + exact ae_of_all _ fun a => by + congr 1 + +lemma bulkPairAverage_first (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) (F : CompactOverlap→ᵇℝ) : + bulkReplicaMean n (M+2) f v 2 (fun a x => bulkPairOverlapTest n F x*bulkPairAverage n (M+2) w a x)= + ((M+2:ℕ):ℝ)/(n+1:ℕ)*(∫ p,bulkFreshNumerator n M 2 f v (compactPairTest F) + (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>(1:ℝ→ᵇℝ))) p / + bulkFreshDenominator n M f v p^2 ∂twoFreshDisorderLaw (n+1) M) := by + have hf : (fun a x => bulkPairOverlapTest n F x*bulkPairAverage n (M+2) w a x)= + (fun a x => ((n+1:ℕ):ℝ)⁻¹*(bulkPairOverlapTest n F x*∑ i,pairFieldMark w (bulkPatternFields i a x))) := by + funext a x; unfold bulkPairAverage; ring + rw [hf,bulkReplicaMean_const_mul,bulk_pattern_sum_first n (M+2) 2 f v _ (bulkPairOverlapTest_measurable n F) + _ (pairFieldMark_measurable w) (norm_nonneg F) (sq_nonneg ‖w‖) + (fun x => F.norm_coe_le_norm _) (pairFieldMark_bound w) ((Fin.last M).castSucc)] + rw [←bulk_marked_last_pair n M f w 1 v F] + simp only [pairFieldMark,BoundedContinuousFunction.coe_one,Pi.one_apply,Finset.prod_const_one,mul_one] + ring + +lemma bulkPairAverage_second (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) (F : CompactOverlap→ᵇℝ) : + bulkReplicaMean n (M+2) f v 2 (fun a x => bulkPairOverlapTest n F x*(bulkPairAverage n (M+2) w a x)^2)= + ((M+2:ℕ):ℝ)/(n+1:ℕ)^2* + bulkReplicaMean n (M+2) f v 2 (fun a x => bulkPairOverlapTest n F x* + (pairFieldMark w (bulkPatternFields ((Fin.last M).castSucc) a x))^2)+ + (((M+2:ℕ):ℝ)*((M+1:ℕ):ℝ)/(n+1:ℕ)^2)*(∫ p,bulkFreshNumerator n M 2 f v (compactPairTest F) + (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>w)) p / + bulkFreshDenominator n M f v p^2 ∂twoFreshDisorderLaw (n+1) M) := by + have hf : (fun a x => bulkPairOverlapTest n F x*(bulkPairAverage n (M+2) w a x)^2)= + (fun a x => (((n+1:ℕ):ℝ)⁻¹)^2*(bulkPairOverlapTest n F x*(∑ i,pairFieldMark w (bulkPatternFields i a x))^2)) := by + funext a x; unfold bulkPairAverage; ring + have hkl : (Fin.last M).castSucc≠Fin.last (M+1) := by + intro h + have := congrArg Fin.val h + simp only [Fin.val_castSucc,Fin.val_last] at this + omega + rw [hf,bulkReplicaMean_const_mul,bulk_pattern_sum_second n (M+2) 2 f v _ (bulkPairOverlapTest_measurable n F) + _ (pairFieldMark_measurable w) (norm_nonneg F) (sq_nonneg ‖w‖) + (fun x => F.norm_coe_le_norm _) (pairFieldMark_bound w) ((Fin.last M).castSucc) (Fin.last (M+1)) hkl, + bulk_marked_last_pair n M f w w v F] + simp only [div_eq_mul_inv,inv_pow] + push_cast + ring + +lemma bulkPairAverage_diagonal_bound (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) (F : CompactOverlap→ᵇℝ) : + |bulkReplicaMean n (M+2) f v 2 (fun a x => bulkPairOverlapTest n F x* + (pairFieldMark w (bulkPatternFields ((Fin.last M).castSucc) a x))^2)|≤‖F‖*‖w‖^4 := by + apply bulkReplicaMean_bound _ _ _ _ _ _ + ((bulkPairOverlapTest_measurable n F |>.comp measurable_snd).mul + (((pairFieldMark_measurable w).comp (bulkPatternFields_measurable _ _ _ _)).pow_const 2)) (by positivity) + intro a x + rw [abs_mul,abs_pow] + apply (mul_le_mul (F.norm_coe_le_norm _) (pow_le_pow_left₀ (abs_nonneg _) (pairFieldMark_bound w _) 2) + (by positivity) (norm_nonneg _)).trans_eq + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedSelfConsistency.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedSelfConsistency.lean new file mode 100644 index 0000000000000000000000000000000000000000..dbc20608be407cb8ad5e4931e5fc11ff315416ed --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedSelfConsistency.lean @@ -0,0 +1,73 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkMarkedTangentLimit +import OAI.Probability.Perceptron.Variational.MarkedTangentCanonical + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BoundedContinuousFunction ContDiff +namespace SphericalPerceptronFreeEnergy + +lemma marked_overlap_geometry (K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (he : ∀ e : Equiv.Perm ℕ,MeasurePreserving (compactRelabel (K:=BulkPairRange K) e) (μ : Measure _) (μ : Measure _)) + (hg : ∀ᵐ Q ∂(bulkJointLaw (compactMapLaw Prod.fst continuous_fst μ) : Measure (CompactArray CompactJointOverlap)),CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw (compactMapLaw Prod.fst continuous_fst μ) : Measure (CompactArray CompactJointOverlap)),0≤(Q 0 1).1.val) : + (∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,(Q i j).1=(Q j i).1) ∧ + (∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j k,min (Q i j).1.val (Q i k).1.val≤(Q j k).1.val) ∧ + (∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,0≤(Q i j).1.val) := by + have h1 := ae_of_ae_map (compactMapArray_continuous bulkJointEmbedding_continuous).measurable.aemeasurable hg + have h2 := ae_of_ae_map (compactMapArray_continuous (show Continuous (Prod.fst : BulkPairRange K → CompactOverlap) from continuous_fst)).measurable.aemeasurable h1 + have h3 := ae_of_ae_map (compactMapArray_continuous bulkJointEmbedding_continuous).measurable.aemeasurable hn + have h4 := ae_of_ae_map (compactMapArray_continuous (show Continuous (Prod.fst : BulkPairRange K → CompactOverlap) from continuous_fst)).measurable.aemeasurable h3 + have hsy : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,(Q i j).1=(Q j i).1 := + h2.mono fun Q hQ i j=>Subtype.ext (hQ.1 i j) + refine ⟨hsy,h2.mono (fun Q hQ=>hQ.2.2),?_⟩ + have h10 : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),0≤(Q 1 0).1.val := by + filter_upwards [hsy,h4] with Q hQ hN + change 0≤(Q 0 1).1.val at hN + simpa only [hQ 1 0] using hN + have ha := compact_exchangeable_offdiag_ae μ he (fun p=>0≤p.1.val) h10 + filter_upwards [ha,h2] with Q hQ hG + intro i j + by_cases hij : i=j + · subst j + have hd : (Q i i).1.val=1 := hG.2.1 i + rw [hd]; norm_num + · exact hQ i j hij + +theorem bulk_marked_self_consistency (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) + (hv : ∀ n p,1≤v n p) {C : ℝ} (hC : 0≤C) (hvC : ∀ n p,|v n (p+1)|≤C) + (hdO : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n) g.f p (v n)) atTop (𝓝 0)) + (hdF : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n+2) g.f p (v n)) atTop (𝓝 0)) + (s : ℕ→ℕ) (hs : StrictMono s) (α : ℝ) (hα : 0≤α) + (hd : Tendsto (fun n=>((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (ho : Tendsto (fun n=>bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (K : ℝ) (hK0 : 0≤K) (hK : ∀ n,((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)*‖g.d1‖^2≤K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hf : Tendsto (fun n=>bulkMarkedArrayLaw (s n) (M (s n)+2) g (v (s n)) K (hK n)) atTop (𝓝 μ)) : + ∃ a : ℝ→ℝ,Monotone a ∧ (∀ r,0≤a r ∧ a r≤α*‖g.d1‖^2) ∧ + (∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,i≠j→(Q i j).2.val=a (Q i j).1.val) ∧ + (∀ᵐ x : Time ∂((markedTimeLaw K μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1)), + a x=∫ y in 0..(x:ℝ),(realTail ((markedTimeLaw K μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1)) y)⁻¹^2) ∧ + ∀ᵐ x : Time ∂((markedTimeLaw K μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1)), + (x:ℝ)≤(α*‖g.d1‖^2)/(1+α*‖g.d1‖^2) := by + have hOm := bulk_limit_geometry M g.f v (Eventually.of_forall hv) hdO hs ho + obtain ⟨a,ham,hab,_,hag⟩ := bulkMarkedArray_identification M g v s hs.tendsto_atTop α hα hd ν ho + hOm.2.2 hOm.1 hOm.2.1 K hK0 hK μ hf + have hf' := bulkMarkedArray_limit_overlap (fun n=>M n+2) g v s K hK hf + have hFm := bulk_limit_geometry (fun n=>M n+2) g.f v (Eventually.of_forall hv) hdF hs hf' + have he (e : Equiv.Perm ℕ) := compact_exchangeability_limit hf e + (fun n=>bulkMarkedArray_exchangeable (s n) (M (s n)+2) g (v (s n)) K (hK n) e) + have hGm := marked_overlap_geometry K μ he hFm.1 hFm.2.1 + have hsc := marked_time_self_consistency K μ he + (bulk_limit_gg (fun n=>M n+2) g.f v (Eventually.of_forall hv) hdF hs hf') + hGm.1 hGm.2.1 hGm.2.2 a ham.measurable (mul_nonneg hα (sq_nonneg _)) hab hag + (fun G hG=>bulk_marked_tangent_limit (fun n=>M n+2) g v hC hvC K hs hK μ hf G hG) + exact ⟨a,ham,hab,hag,hsc.1,hsc.2⟩ + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedTangentLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedTangentLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..b540d45fe127e20304885f924b135e5af7643853 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkMarkedTangentLimit.lean @@ -0,0 +1,143 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkMarkedArray + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped BigOperators Topology BoundedContinuousFunction ContDiff + +lemma bulkScale_sq_div (n : ℕ) : bulkScale (n+1)^2/(n+1:ℕ)=((n+1:ℕ):ℝ)^(-(1:ℝ)/4) := by + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + unfold bulkScale + rw [←Real.rpow_mul_natCast hn.le] + calc + _ = ((n+1:ℕ):ℝ)^((3:ℝ)/8*(2:ℕ))/((n+1:ℕ):ℝ)^(1:ℝ) := by rw [Real.rpow_one] + _ = _ := by rw [←Real.rpow_sub hn]; norm_num + +lemma bulk_tangent_error_tendsto (A D C : ℝ) : + Tendsto (fun n : ℕ => (A+D+8*A*C^2*bulkScale (n+1)^2)/(n+1:ℕ)) atTop (𝓝 0) := by + have hN : Tendsto (fun n : ℕ => ((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have hi := tendsto_inv_atTop_zero.comp hN + have hp := (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1/4)).comp hN + have he (n : ℕ) : (A+D+8*A*C^2*bulkScale (n+1)^2)/(n+1:ℕ)= + (A+D)*((n+1:ℕ):ℝ)⁻¹+8*A*C^2*((n+1:ℕ):ℝ)^(-(1:ℝ)/4) := by + rw [add_div,mul_div_assoc,bulkScale_sq_div,div_eq_mul_inv] + simp_rw [he] + convert (hi.const_mul (A+D)).add (hp.const_mul (8*A*C^2)) using 1 <;> + simp only [mul_zero,add_zero,Function.comp_def,neg_div] + +lemma marked_tangent_continuous (K : ℝ) (G : ℝ→ᵇℝ) : + Continuous (fun μ : ProbabilityMeasure (CompactArray (BulkPairRange K)) => + (∫ Q,markedTangentR K G (compactBlock 2 Q) ∂(μ : Measure _))- + (∫ Q,markedTangentPair K G (compactBlock 2 Q) ∂(μ : Measure _))+ + 2*(∫ Q,markedTangentTriple K G (compactBlock 3 Q) ∂(μ : Measure _))) := by + have hh (r : ℕ) (F : CompactBlock (BulkPairRange K) r→ᵇℝ) := + ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (F.compContinuous ⟨compactBlock r,compactBlock_continuous r⟩) + exact ((hh 2 (markedTangentR K G)).sub (hh 2 (markedTangentPair K G))).add + (continuous_const.mul (hh 3 (markedTangentTriple K G))) + +lemma bulk_marked_tangent_limit (M : ℕ→ℕ) (f : Jet3) (v : ℕ→ℕ→ℝ) + {C : ℝ} (hC : 0≤C) (hv : ∀ n j,|v n (j+1)|≤C) + (K : ℝ) {s : ℕ→ℕ} (hs : StrictMono s) + (hK : ∀ n,M (s n)/(s n+1:ℕ)*‖f.d1‖^2≤K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hlim : Tendsto (fun n => bulkMarkedArrayLaw (s n) (M (s n)) f (v (s n)) K (hK n)) atTop (𝓝 μ)) + (G : ℝ→ᵇℝ) (hG : ContDiff ℝ 1 (G : ℝ→ℝ)) : + (∫ Q,markedTangentR K G (compactBlock 2 Q) ∂(μ : Measure _))- + (∫ Q,markedTangentPair K G (compactBlock 2 Q) ∂(μ : Measure _))+ + 2*(∫ Q,markedTangentTriple K G (compactBlock 3 Q) ∂(μ : Measure _))=0 := by + have hc : Continuous (fun r : CompactOverlap=>deriv (G : ℝ→ℝ) r.val*(1-r.val^2)) := + ((hG.continuous_deriv (by norm_num)).comp continuous_subtype_val).mul + (continuous_const.sub (continuous_subtype_val.pow 2)) + obtain ⟨D,hD,hbD⟩ := continuous_real_compact_bound hc + have hzero : Tendsto (fun n => + (∫ Q,markedTangentR K G (compactBlock 2 Q) ∂(bulkMarkedArrayLaw (s n) (M (s n)) f (v (s n)) K (hK n) : Measure _))- + (∫ Q,markedTangentPair K G (compactBlock 2 Q) ∂(bulkMarkedArrayLaw (s n) (M (s n)) f (v (s n)) K (hK n) : Measure _))+ + 2*(∫ Q,markedTangentTriple K G (compactBlock 3 Q) ∂(bulkMarkedArrayLaw (s n) (M (s n)) f (v (s n)) K (hK n) : Measure _))) atTop (𝓝 0) := by + apply squeeze_zero_norm (a:=fun n => (‖G‖+D+8*‖G‖*C^2*bulkScale (s n+1)^2)/(s n+1:ℕ)) + · intro n + simpa only [Real.norm_eq_abs] using bulk_marked_tangent_bound (s n) (M (s n)) f (v (s n)) G hG hC (hv (s n)) K (hK n) hD hbD + · exact (bulk_tangent_error_tendsto ‖G‖ D C).comp hs.tendsto_atTop + exact tendsto_nhds_unique ((marked_tangent_continuous K G).continuousAt.tendsto.comp hlim) hzero + +lemma exists_nat_perm_pair (i j : ℕ) (hij : i≠j) : + ∃ e : Equiv.Perm ℕ,e 1=i ∧ e 0=j := by + classical + let u := Equiv.swap 1 i + have hu : u 0≠i := by + intro h + have he : u 0=u 1 := by simpa [u] using h + have := u.injective he + omega + refine ⟨u.trans (Equiv.swap (u 0) j),?_,?_⟩ + · change Equiv.swap (u 0) j (u 1)=i + simp only [u,Equiv.swap_apply_left] + exact Equiv.swap_apply_of_ne_of_ne hu.symm hij + · change Equiv.swap (u 0) j (u 0)=j + exact Equiv.swap_apply_left _ _ + +lemma compact_exchangeable_offdiag_ae {K : Type*} [TopologicalSpace K] + [MeasurableSpace K] [BorelSpace K] [SecondCountableTopology K] + (μ : ProbabilityMeasure (CompactArray K)) + (he : ∀ e : Equiv.Perm ℕ,MeasurePreserving (compactRelabel (K:=K) e) (μ : Measure _) (μ : Measure _)) + (P : K→Prop) (hP : ∀ᵐ Q ∂(μ : Measure (CompactArray K)),P (Q 1 0)) : + ∀ᵐ Q ∂(μ : Measure (CompactArray K)),∀ i j,i≠j→P (Q i j) := by + apply ae_all_iff.mpr + intro i + apply ae_all_iff.mpr + intro j + by_cases hij : i=j + · exact ae_of_all _ fun Q h => (h hij).elim + · obtain ⟨e,he1,he0⟩ := exists_nat_perm_pair i j hij + have h := (he e).quasiMeasurePreserving.ae hP + simpa only [compactRelabel,he1,he0] using h.mono (fun Q h _ => h) + +lemma bulkMarkedArray_limit_overlap (M : ℕ→ℕ) (f : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (K : ℝ) (hK : ∀ n,(M (s n):ℝ)/(s n+1:ℕ)*‖f.d1‖^2≤K) + {μ : ProbabilityMeasure (CompactArray (BulkPairRange K))} + (hlim : Tendsto (fun n => bulkMarkedArrayLaw (s n) (M (s n)) f (v (s n)) K (hK n)) atTop (𝓝 μ)) : + Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) f.f (v (s n))) atTop + (𝓝 (compactMapLaw Prod.fst continuous_fst μ)) := by + have ht := ProbabilityMeasure.tendsto_map_of_tendsto_of_continuous _ _ hlim + (compactMapArray_continuous (show Continuous (Prod.fst : BulkPairRange K → CompactOverlap) from continuous_fst)) + change Tendsto (fun n => compactMapLaw Prod.fst continuous_fst (bulkMarkedArrayLaw (s n) (M (s n)) f (v (s n)) K (hK n))) atTop (𝓝 (compactMapLaw Prod.fst continuous_fst μ)) at ht + simpa only [bulkMarkedArray_overlap] using ht + +theorem bulkMarkedArray_identification (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (hs : Tendsto s atTop atTop) (α : ℝ) (hα : 0≤α) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (K : ℝ) (hK0 : 0≤K) (hK : ∀ n,((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)*‖g.d1‖^2≤K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hmarked : Tendsto (fun n => bulkMarkedArrayLaw (s n) (M (s n)+2) g (v (s n)) K (hK n)) atTop (𝓝 μ)) : + ∃ a : ℝ→ℝ,Monotone a ∧ (∀ r,0≤a r ∧ a r≤α*‖g.d1‖^2) ∧ + (μ : Measure (CompactArray (BulkPairRange K))).map (fun Q => (Q 1 0).1)= + (compactPairMarginal ν : Measure CompactOverlap) ∧ + ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,i≠j→(Q i j).2.val=a (Q i j).1.val := by + have hc : Continuous (fun Q : CompactArray (BulkPairRange K)=>Q 1 0) := by fun_prop + let ρ := μ.map (fun Q => Q 1 0) + have ht := ProbabilityMeasure.tendsto_map_of_tendsto_of_continuous _ _ hmarked hc + change Tendsto (fun n => (bulkMarkedArrayLaw (s n) (M (s n)+2) g (v (s n)) K (hK n)).map (fun Q => Q 1 0)) atTop (𝓝 ρ) at ht + simp_rw [bulkMarkedArray_pair] at ht + obtain ⟨a,ham,hab,hmarg,hgraph⟩ := bulkPairLaw_identification M g v s hs α hα hd ν hlim hGG hgeo hn g.d1 K hK0 hK ρ ht + refine ⟨a,ham,hab,?_,?_⟩ + · change (Measure.map Prod.fst (Measure.map (fun Q : CompactArray (BulkPairRange K)=>Q 1 0) (μ : Measure _)))=_ at hmarg + rwa [Measure.map_map measurable_fst hc.measurable] at hmarg + · apply compact_exchangeable_offdiag_ae μ + (fun e => compact_exchangeability_limit hmarked e (fun n => bulkMarkedArray_exchangeable (s n) (M (s n)+2) g (v (s n)) K (hK n) e)) + (fun p => p.2.val=a p.1.val) + exact ae_of_ae_map hc.measurable.aemeasurable hgraph + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkModel.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..a562104fb5e6b0b1bec2df72fc7c4ae5f1038dc6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkModel.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.GibbsOverlapArray + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +def bulkScale (N : ℕ) : ℝ := (N:ℝ)^((3:ℝ)/8) +def bulkDegree {N : ℕ} (p : Fin N) : ℕ := p.val+1 +abbrev BulkMark (N : ℕ) := EnrichedMark N N bulkDegree + +def bulkAmplitude (N : ℕ) (v : ℕ → ℝ) (p : Fin N) : ℝ := + bulkScale N * (2:ℝ)^(-((p.val+1:ℕ):ℤ))*v (p.val+1) + +def bulkFeature (N : ℕ) (v : ℕ → ℝ) : NormalizedSpin N → BulkMark N := + enrichedFeature N N bulkDegree 0 (bulkAmplitude N v) + +def bulkCovariance (N : ℕ) (v : ℕ → ℝ) (r : ℝ) : ℝ := + ∑ p : Fin N, ((2:ℝ)^(-((p.val+1:ℕ):ℤ)))^2 * (v (p.val+1))^2 * r^(p.val+1) + +def bulkHamiltonian (N M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (a : Fin M → Fin N → ℝ) (g : BulkMark N) (x : NormalizedSpin N) : ℝ := + normalizedPatternEnergy N M f a x + inner ℝ (bulkFeature N v x) g + +def bulkLogPartition (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (a : Fin M → Fin (n+1) → ℝ) (g : BulkMark (n+1)) : ℝ := + vectorLogPartition (unitSphereLaw (n+1)) (normalizedPatternEnergy (n+1) M f a) + (fun x => innerSL ℝ (bulkFeature (n+1) v x)) g + +def bulkDisorderLaw (N M : ℕ) : Measure ((Fin M → Fin N → ℝ) × BulkMark N) := + (Measure.pi (fun _ => Measure.pi (fun _ => gaussianReal 0 1))).prod (stdGaussian (BulkMark N)) + +instance bulkDisorderLaw_probability (N M : ℕ) : IsProbabilityMeasure (bulkDisorderLaw N M) := by + unfold bulkDisorderLaw + infer_instance + +def bulkExpectedLog (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) : ℝ := + ∫ a, bulkLogPartition n M f v a.1 a.2 ∂bulkDisorderLaw (n+1) M + +def bulkB (N M : ℕ) (f : Jet3) (a : Fin M → Fin N → ℝ) + (x y : NormalizedSpin N) : ℝ := + (N:ℝ)⁻¹ * ∑ j, f.d1 (∑ i, a j i*x.val i) * f.d1 (∑ i, a j i*y.val i) + +def bulkC (N M : ℕ) (f : Jet3) (a : Fin M → Fin N → ℝ) + (x : NormalizedSpin N) : ℝ := + (N:ℝ)⁻¹ * ∑ j, (f.d2 (∑ i, a j i*x.val i) - + (∑ i, a j i*x.val i)*f.d1 (∑ i, a j i*x.val i)) + +lemma bulkFeature_continuous (N : ℕ) (v : ℕ → ℝ) : Continuous (bulkFeature N v) := + enrichedFeature_continuous N N bulkDegree 0 (bulkAmplitude N v) + +lemma bulkFeature_inner (N : ℕ) (v : ℕ → ℝ) (x y : NormalizedSpin N) : + inner ℝ (bulkFeature N v x) (bulkFeature N v y) = + bulkScale N ^ 2 * bulkCovariance N v (spinOverlap x y) := by + rw [bulkFeature, enrichedFeature_inner] + simp only [zero_pow two_ne_zero, zero_mul, zero_add, bulkCovariance, Finset.mul_sum, + bulkAmplitude, bulkDegree] + apply Finset.sum_congr rfl + intro i _ + ring + +lemma bulkFeature_norm_sq (N : ℕ) (v : ℕ → ℝ) (x : NormalizedSpin N) : + ‖bulkFeature N v x‖^2 = ∑ p, bulkAmplitude N v p^2 := by + rw [bulkFeature, enrichedFeature_norm_sq] + simp + +lemma bulkLogPartition_eq (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (a : Fin M → Fin (n+1) → ℝ) (g : BulkMark (n+1)) : + bulkLogPartition n M f v a g = + Real.log (tiltPartition (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) 1) := by + simp only [bulkLogPartition, vectorLogPartition, vectorPartition, tiltPartition, one_mul, bulkHamiltonian, + innerSL_apply_apply] + +lemma bulkB_bound (N M : ℕ) (f : Jet3) (a : Fin M → Fin N → ℝ) + (x y : NormalizedSpin N) : |bulkB N M f a x y| ≤ (M:ℝ)/(N:ℝ)*‖f.d1‖^2 := by + unfold bulkB + rw [abs_mul, abs_of_nonneg (inv_nonneg.mpr (Nat.cast_nonneg N))] + calc + _ ≤ (N:ℝ)⁻¹ * ∑ _ : Fin M, ‖f.d1‖^2 := by + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr (Nat.cast_nonneg N)) + exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum fun j _ => by + rw [abs_mul, pow_two] + exact mul_le_mul (f.d1.norm_coe_le_norm _) (f.d1.norm_coe_le_norm _) + (abs_nonneg _) (norm_nonneg _)) + _ = _ := by simp; ring + +abbrev BulkDisorder (N M : ℕ) := (Fin M→Fin N→ℝ) × BulkMark N + +def bulkFeatureBound (N : ℕ) (v : ℕ→ℝ) : ℝ := Real.sqrt (∑ p, bulkAmplitude N v p^2) + +lemma bulkFeature_norm (N : ℕ) (v : ℕ→ℝ) (x : NormalizedSpin N) : + ‖bulkFeature N v x‖=bulkFeatureBound N v := by + rw [bulkFeature, enrichedFeature_norm] + simp [bulkFeatureBound] + +lemma bulkHamiltonian_continuous (N M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + Continuous (fun p : BulkDisorder N M × NormalizedSpin N => + bulkHamiltonian N M f v p.1.1 p.1.2 p.2) := by + unfold bulkHamiltonian + exact ((normalizedPatternEnergy_continuous N M f).comp + (continuous_fst.fst.prodMk continuous_snd)).add + (((bulkFeature_continuous N v).comp continuous_snd).inner continuous_fst.snd) + +lemma bulkHamiltonian_bound (N M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (a : BulkDisorder N M) + (x : NormalizedSpin N) : + |bulkHamiltonian N M f v a.1 a.2 x| ≤ M*‖f‖+bulkFeatureBound N v*‖a.2‖ := by + apply (abs_add_le _ _).trans + exact add_le_add (normalizedPatternEnergy_bound _ _ _ _ _) (by + simpa only [bulkFeature_norm] using abs_real_inner_le_norm (bulkFeature N v x) a.2) + +lemma bulkHamiltonian_exp_integrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) M) : + Integrable (fun x => Real.exp (bulkHamiltonian (n+1) M f v a.1 a.2 x)) (unitSphereLaw (n+1)) := by + apply Integrable.of_bound + ((bulkHamiltonian_continuous (n+1) M f v).measurable.comp + (measurable_const.prodMk measurable_id)).exp.aestronglyMeasurable + (Real.exp (M*‖f‖+bulkFeatureBound (n+1) v*‖a.2‖)) + exact ae_of_all _ fun x => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans (bulkHamiltonian_bound (n+1) M f v a x)) + +def bulkSpinKernel (n M : ℕ) : Kernel (BulkDisorder (n+1) M) (NormalizedSpin (n+1)) := + Kernel.const _ (unitSphereLaw (n+1)) + +instance bulkSpinKernel_markov (n M : ℕ) : IsMarkovKernel (bulkSpinKernel n M) := by + unfold bulkSpinKernel; infer_instance + +def bulkOverlap {N : ℕ} (x y : NormalizedSpin N) : CompactOverlap := + ⟨spinOverlap x y,abs_le.mp (spinOverlap_abs_le x y)⟩ + +lemma bulkOverlap_measurable (N : ℕ) : Measurable (Function.uncurry (bulkOverlap (N:=N))) := by + apply Measurable.subtype_mk + exact measurable_fst.subtype_val.inner measurable_snd.subtype_val + +def bulkGibbsArrayLaw (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + ProbabilityMeasure (CompactArray CompactOverlap) := + gibbsOverlapArrayLaw (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (fun a x => bulkHamiltonian (n+1) M f v a.1 a.2 x) + (bulkHamiltonian_continuous (n+1) M f v).measurable bulkOverlap (bulkOverlap_measurable (n+1)) + +lemma bulkGibbsArray_block (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) : + (∫ R, F (compactBlock r R) ∂bulkGibbsArrayLaw n M f v) = + ∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r + (fun x => F (fun i j => bulkOverlap (x i) (x j))) ∂bulkDisorderLaw (n+1) M := by + exact gibbsOverlapArray_block (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (fun a x => bulkHamiltonian (n+1) M f v a.1 a.2 x) + (bulkHamiltonian_continuous (n+1) M f v).measurable _ (bulkOverlap_measurable (n+1)) + (ae_of_all _ (bulkHamiltonian_exp_integrable n M f v)) r F + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkPairLaw.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkPairLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..e574705da9339ab80a129660c71bc5943c7465c7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkPairLaw.lean @@ -0,0 +1,214 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.MarkedVariance +import OAI.Probability.Perceptron.Cavity.BulkEmpiricalLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev BulkPairRange (K : ℝ) := CompactOverlap × Icc (-K) K + +def bulkFiniteReplicaLaw (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + Measure (BulkDisorder (n+1) M × (Fin r→NormalizedSpin (n+1))) := by + letI := gibbsProbabilityKernel_markov (bulkSpinKernel n M) + (fun a => bulkHamiltonian (n+1) M f v a.1 a.2) (bulkHamiltonian_continuous _ _ _ _).measurable + exact (bulkDisorderLaw (n+1) M) ⊗ₘ kernelReplica + (gibbsProbabilityKernel (bulkSpinKernel n M) + (fun a => bulkHamiltonian (n+1) M f v a.1 a.2)) r + +instance bulkFiniteReplicaLaw_probability (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + IsProbabilityMeasure (bulkFiniteReplicaLaw n M r f v) := by + let := gibbsProbabilityKernel_markov (bulkSpinKernel n M) + (fun a => bulkHamiltonian (n+1) M f v a.1 a.2) (bulkHamiltonian_continuous _ _ _ _).measurable + unfold bulkFiniteReplicaLaw + infer_instance + +lemma bulkFiniteReplicaLaw_integral (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hG : Measurable (Function.uncurry G)) {C : ℝ} (hb : ∀ a x,|G a x|≤C) : + (∫ p,G p.1 p.2 ∂bulkFiniteReplicaLaw n M r f v)=bulkReplicaMean n M f v r G := by + have hi : Integrable (Function.uncurry G) (bulkFiniteReplicaLaw n M r f v) := + Integrable.of_bound hG.aestronglyMeasurable C (ae_of_all _ fun p => by + simpa only [Real.norm_eq_abs, Function.uncurry] using hb p.1 p.2) + change (∫ p,Function.uncurry G p ∂bulkFiniteReplicaLaw n M r f v)=_ + rw [bulkFiniteReplicaLaw,Measure.integral_compProd hi] + apply integral_congr_ae + exact ae_of_all _ fun a => gibbsProbabilityKernel_replica_integral (bulkSpinKernel n M) + (fun a => bulkHamiltonian (n+1) M f v a.1 a.2) (bulkHamiltonian_continuous _ _ _ _).measurable + a (bulkHamiltonian_exp_integrable n M f v a) r (G a) + +def bulkCompactPair (n M : ℕ) (w : ℝ→ᵇℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖w‖^2≤K) + (p : BulkDisorder (n+1) M × (Fin 2→NormalizedSpin (n+1))) : BulkPairRange K := + (bulkOverlap (p.2 1) (p.2 0),⟨bulkPairAverage n M w p.1 p.2, + abs_le.mp ((bulkPairAverage_bound n M w p.1 p.2).trans hK)⟩) + +lemma bulkCompactPair_measurable (n M : ℕ) (w : ℝ→ᵇℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖w‖^2≤K) : Measurable (bulkCompactPair n M w K hK) := by + have hp : Measurable (fun p : BulkDisorder (n+1) M × (Fin 2→NormalizedSpin (n+1)) => + (p.2 1,p.2 0)) := + ((measurable_pi_apply 1).comp measurable_snd).prodMk + ((measurable_pi_apply 0).comp measurable_snd) + exact ((bulkOverlap_measurable (n+1)).comp hp).prodMk + (bulkPairAverage_measurable n M w |>.subtype_mk) + +def bulkPairLaw (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖w‖^2≤K) : ProbabilityMeasure (BulkPairRange K) := + ⟨(bulkFiniteReplicaLaw n M 2 f v).map (bulkCompactPair n M w K hK), + inferInstance⟩ + +lemma bulkPairLaw_integral (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖w‖^2≤K) (F : BulkPairRange K→ᵇℝ) : + (∫ p,F p ∂(bulkPairLaw n M f w v K hK : Measure (BulkPairRange K)))= + bulkReplicaMean n M f v 2 (fun a x => F (bulkCompactPair n M w K hK (a,x))) := by + change (∫ p,F p ∂(bulkFiniteReplicaLaw n M 2 f v).map (bulkCompactPair n M w K hK))=_ + have he := integral_map (μ:=bulkFiniteReplicaLaw n M 2 f v) + (bulkCompactPair_measurable n M w K hK).aemeasurable F.measurable.aestronglyMeasurable + change (∫ p,F p ∂(bulkFiniteReplicaLaw n M 2 f v).map (bulkCompactPair n M w K hK))= + (∫ p,F (bulkCompactPair n M w K hK p) ∂bulkFiniteReplicaLaw n M 2 f v) at he + rw [he] + exact bulkFiniteReplicaLaw_integral n M 2 f v + (fun a x => F (bulkCompactPair n M w K hK (a,x))) + (F.measurable.comp (bulkCompactPair_measurable n M w K hK)) + (fun a x => by simpa only [Real.norm_eq_abs] using F.norm_coe_le_norm (bulkCompactPair n M w K hK (a,x))) + +lemma bulkPairLaw_overlap (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖w‖^2≤K) (F : CompactOverlap→ᵇℝ) : + (∫ p,F p.1 ∂(bulkPairLaw n M f w v K hK : Measure (BulkPairRange K)))= + ∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(bulkGibbsArrayLaw n M f v : Measure _) := by + let A : BulkPairRange K→ᵇℝ := F.compContinuous ⟨Prod.fst,continuous_fst⟩ + rw [show (∫ p,F p.1 ∂(bulkPairLaw n M f w v K hK : Measure (BulkPairRange K)))=(∫ p,A p ∂(bulkPairLaw n M f w v K hK : Measure (BulkPairRange K))) from rfl, + bulkPairLaw_integral] + let G : CompactBlock CompactOverlap 2→ᵇℝ := F.compContinuous ⟨fun Q=>Q 0 1,by fun_prop⟩ + have he := bulkGibbsArray_block n M f v 2 G + change (∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(bulkGibbsArrayLaw n M f v : Measure _))=_ at he + rw [he] + unfold bulkReplicaMean + apply integral_congr_ae + exact ae_of_all _ fun a => by + apply congrArg (gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) 2) + funext x + change F (bulkOverlap (x 1) (x 0))=F (bulkOverlap (x 0) (x 1)) + congr 1 + apply Subtype.ext + exact real_inner_comm _ _ + +lemma compact_pair_zero_variance (K : ℝ) (hK : 0≤K) + (μ : ProbabilityMeasure (BulkPairRange K)) (ν : ProbabilityMeasure CompactOverlap) + (a : ℝ→ℝ) (ha : Measurable a) (A : ℝ) (hA : 0≤A) (hb : ∀ r,|a r|≤A) + (hmarg : (μ : Measure (BulkPairRange K)).map Prod.fst=(ν : Measure CompactOverlap)) + (hfirst : ∀ F : CompactOverlap→ᵇℝ,(∫ p,F p.1*p.2.val ∂(μ : Measure (BulkPairRange K)))= + ∫ q,F q*a q.val ∂(ν : Measure CompactOverlap)) + (hsecond : (∫ p,p.2.val^2 ∂(μ : Measure (BulkPairRange K)))=(∫ q,(a q.val)^2 ∂(ν : Measure CompactOverlap))) : + ∀ᵐ p ∂(μ : Measure (BulkPairRange K)),p.2.val=a p.1.val := by + have hi (G : CompactOverlap→ℝ) (hG : Measurable G) : + (∫ q,G q ∂(ν : Measure CompactOverlap))=(∫ p,G p.1 ∂(μ : Measure (BulkPairRange K))) := by + rw [←hmarg] + exact integral_map measurable_fst.aemeasurable hG.aestronglyMeasurable + apply marked_zero_variance (μ : Measure (BulkPairRange K)) Prod.fst measurable_fst (fun p => p.2.val) + (by fun_prop) (fun q => a q.val) (ha.comp measurable_subtype_coe) hA hK + (fun r => hb r.val) (fun p => abs_le.mpr p.2.prop) + · intro F + rw [hfirst F] + exact hi (fun q => F q*a q.val) (F.measurable.mul (ha.comp measurable_subtype_coe)) + · rw [hsecond] + exact hi (fun q => (a q.val)^2) ((ha.comp measurable_subtype_coe).pow_const 2) + + +def compactPairMarginal (ν : ProbabilityMeasure (CompactArray CompactOverlap)) : + ProbabilityMeasure CompactOverlap := + ν.map (fun Q : CompactArray CompactOverlap => Q 0 1) + +lemma compactPairMarginal_integral (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (F : CompactOverlap→ℝ) (hF : Measurable F) : + (∫ r,F r ∂(compactPairMarginal ν : Measure CompactOverlap))= + ∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(ν : Measure _) := + integral_map (by exact (by fun_prop : Measurable (fun Q : CompactArray CompactOverlap => Q 0 1)).aemeasurable) hF.aestronglyMeasurable + +lemma bulkPairLaw_limit_marginal (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (w : ℝ→ᵇℝ) (K : ℝ) + (hK : ∀ n,((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)*‖w‖^2≤K) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) (μ : ProbabilityMeasure (BulkPairRange K)) + (hpair : Tendsto (fun n => bulkPairLaw (s n) (M (s n)+2) g.f w (v (s n)) K (hK n)) atTop (𝓝 μ)) + (hover : ∀ F : CompactOverlap→ᵇℝ, + Tendsto (fun n => ∫ Q : CompactArray CompactOverlap,F (Q 0 1) + ∂(bulkGibbsArrayLaw (s n) (M (s n)+2) g.f (v (s n)) : Measure _)) atTop + (𝓝 (∫ Q : CompactArray CompactOverlap,F (Q 0 1) ∂(ν : Measure _)))) : + (μ : Measure (BulkPairRange K)).map Prod.fst=(compactPairMarginal ν : Measure CompactOverlap) := by + apply ext_of_forall_integral_eq_of_IsFiniteMeasure + intro F + let A : BulkPairRange K→ᵇℝ := F.compContinuous ⟨Prod.fst,continuous_fst⟩ + have he := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction A).continuousAt.tendsto.comp hpair + change Tendsto (fun n => ∫ p,F p.1 ∂(bulkPairLaw (s n) (M (s n)+2) g.f w (v (s n)) K (hK n) : Measure (BulkPairRange K))) + atTop (𝓝 (∫ p,F p.1 ∂(μ : Measure (BulkPairRange K)))) at he + simp_rw [bulkPairLaw_overlap] at he + have hi := integral_map (μ:=(μ : Measure (BulkPairRange K))) measurable_fst.aemeasurable F.measurable.aestronglyMeasurable + change (∫ r,F r ∂(μ : Measure (BulkPairRange K)).map Prod.fst)=(∫ p,F p.1 ∂(μ : Measure (BulkPairRange K))) at hi + rw [hi,compactPairMarginal_integral ν F F.measurable] + exact tendsto_nhds_unique he (hover F) + +theorem bulkPairLaw_identification (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (hs : Tendsto s atTop atTop) (α : ℝ) (hα : 0≤α) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ν : ProbabilityMeasure (CompactArray CompactOverlap)) + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (w : ℝ→ᵇℝ) (K : ℝ) (hK0 : 0≤K) + (hK : ∀ n,((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)*‖w‖^2≤K) + (μ : ProbabilityMeasure (BulkPairRange K)) + (hpair : Tendsto (fun n => bulkPairLaw (s n) (M (s n)+2) g.f w (v (s n)) K (hK n)) atTop (𝓝 μ)) : + ∃ a : ℝ→ℝ, Monotone a ∧ (∀ r,0≤a r ∧ a r≤α*‖w‖^2) ∧ + (μ : Measure (BulkPairRange K)).map Prod.fst=(compactPairMarginal ν : Measure CompactOverlap) ∧ + ∀ᵐ p ∂(μ : Measure (BulkPairRange K)),p.2.val=a p.1.val := by + obtain ⟨a,ham,hab,ht⟩ := bulk_marked_empirical_limits M g v s hs α hd hlim hGG hgeo hn w + have hmarg := bulkPairLaw_limit_marginal M g v s w K hK ν μ hpair + (bulk_full_pair_tendsto M g v s hlim hGG hgeo hn) + have htμ (F : C(BulkPairRange K,ℝ)) : + Tendsto (fun n => ∫ p,F p ∂(bulkPairLaw (s n) (M (s n)+2) g.f w (v (s n)) K (hK n) : Measure (BulkPairRange K))) + atTop (𝓝 (∫ p,F p ∂(μ : Measure (BulkPairRange K)))) := + (ProbabilityMeasure.continuous_integral_boundedContinuousFunction (BoundedContinuousFunction.mkOfCompact F)).continuousAt.tendsto.comp hpair + refine ⟨fun r => α*a r,ham.const_mul hα,fun r => + ⟨mul_nonneg hα (hab r).1,mul_le_mul_of_nonneg_left (hab r).2 hα⟩,hmarg,?_⟩ + apply compact_pair_zero_variance K hK0 μ (compactPairMarginal ν) (fun r => α*a r) + (ham.measurable.const_mul α) (α*‖w‖^2) (mul_nonneg hα (sq_nonneg _)) + (fun r => by rw [abs_of_nonneg (mul_nonneg hα (hab r).1)]; exact mul_le_mul_of_nonneg_left (hab r).2 hα) hmarg + · intro F + let A : C(BulkPairRange K,ℝ) := ⟨fun p => F p.1*p.2.val,by fun_prop⟩ + have he := htμ A + have htest n : (∫ p,A p ∂(bulkPairLaw (s n) (M (s n)+2) g.f w (v (s n)) K (hK n) : Measure (BulkPairRange K)))= + bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 2 + (fun d x => bulkPairOverlapTest (s n) F x*bulkPairAverage (s n) (M (s n)+2) w d x) := + bulkPairLaw_integral _ _ _ _ _ _ _ (BoundedContinuousFunction.mkOfCompact A) + simp_rw [htest] at he + have hvalue := tendsto_nhds_unique he (ht F).1 + change (∫ p,A p ∂(μ : Measure (BulkPairRange K)))=_ + rw [hvalue,compactPairMarginal_integral ν (fun q => F q*(α*a q.val)) (F.measurable.mul (ham.measurable.comp measurable_subtype_coe |>.const_mul α)),←integral_const_mul] + apply integral_congr_ae + exact ae_of_all _ fun Q => by ring + · let A : C(BulkPairRange K,ℝ) := ⟨fun p => p.2.val^2,by fun_prop⟩ + have he := htμ A + have htest n : (∫ p,A p ∂(bulkPairLaw (s n) (M (s n)+2) g.f w (v (s n)) K (hK n) : Measure (BulkPairRange K)))= + bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 2 + (fun d x => bulkPairOverlapTest (s n) 1 x*(bulkPairAverage (s n) (M (s n)+2) w d x)^2) := by + have hi := bulkPairLaw_integral (s n) (M (s n)+2) g.f w (v (s n)) K (hK n) (BoundedContinuousFunction.mkOfCompact A) + change (∫ p,A p ∂(bulkPairLaw (s n) (M (s n)+2) g.f w (v (s n)) K (hK n) : Measure (BulkPairRange K)))= + bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 2 + (fun d x => (bulkPairAverage (s n) (M (s n)+2) w d x)^2) at hi + simpa only [bulkPairOverlapTest,BoundedContinuousFunction.coe_one,Pi.one_apply,one_mul] using hi + simp_rw [htest] at he + have hvalue := tendsto_nhds_unique he (ht 1).2 + change (∫ p,A p ∂(μ : Measure (BulkPairRange K)))=_ + rw [hvalue,compactPairMarginal_integral ν (fun q => (α*a q.val)^2) ((ham.measurable.comp measurable_subtype_coe |>.const_mul α).pow_const 2),←integral_const_mul] + apply integral_congr_ae + exact ae_of_all _ fun Q => by simp; ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkParameterDeviation.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkParameterDeviation.lean new file mode 100644 index 0000000000000000000000000000000000000000..1206992241941c76137b4bd7a4e6412a79bb282e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkParameterDeviation.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkEnergyDeviation +import OAI.Probability.Perceptron.Variational.ParameterResampling + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma bulkFeature_joint_continuous (N : ℕ) : + Continuous (fun a : (ℕ→ℝ) × NormalizedSpin N => bulkFeature N a.1 a.2) := by + apply (PiLp.continuous_toLp 2 _).comp + apply continuous_pi + intro i + cases i with + | inl i => fun_prop + | inr i => + change Continuous (fun a : (ℕ→ℝ) × NormalizedSpin N => + bulkAmplitude N a.1 i.1*spinTensorFeature N (bulkDegree i.1) a.2 i.2) + apply Continuous.mul + · unfold bulkAmplitude; fun_prop + · exact ((EuclideanSpace.proj i.2).continuous.comp (spinTensorFeature_continuous N (bulkDegree i.1))).comp continuous_snd + +lemma bulkHamiltonian_parameter_continuous (N M : ℕ) (f : ℝ→ᵇℝ) : + Continuous (fun a : ((ℕ→ℝ) × BulkDisorder N M) × NormalizedSpin N => + bulkHamiltonian N M f a.1.1 a.1.2.1 a.1.2.2 a.2) := by + unfold bulkHamiltonian + exact ((normalizedPatternEnergy_continuous N M f).comp + (continuous_fst.snd.fst.prodMk continuous_snd)).add + (((bulkFeature_joint_continuous N).comp (continuous_fst.fst.prodMk continuous_snd)).inner continuous_fst.snd.snd) + +def bulkDegreeDeviation (n M : ℕ) (f : ℝ→ᵇℝ) (p : Fin (n+1)) (v : ℕ→ℝ) : ℝ := + bulkEnergyDeviation n M f v p (v (p.val+1)) + +lemma bulkDegreeDeviation_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (p : Fin (n+1)) : + Measurable (bulkDegreeDeviation n M f p) := by + let H := fun a : (ℕ→ℝ) × BulkDisorder (n+1) M => + bulkHamiltonian (n+1) M f a.1 a.2.1 a.2.2 + let Y := fun a : (ℕ→ℝ) × BulkDisorder (n+1) M => + fun x => bulkCoefficient (n+1) p*bulkY (n+1) p a.2.2 x + have hH : Measurable (Function.uncurry H) := (bulkHamiltonian_parameter_continuous (n+1) M f).measurable + have hY : Measurable (Function.uncurry Y) := + ((bulkY_measurable (n+1) p).comp (measurable_fst.snd.snd.prodMk measurable_snd)).const_mul _ + have hE := (measurable_tiltMean_param (unitSphereLaw (n+1)) hH hY).stronglyMeasurable.integral_prod_right' + (ν:=bulkDisorderLaw (n+1) M) + have he := (measurable_tiltMean_param (unitSphereLaw (n+1)) hH + (show Measurable (Function.uncurry (fun a x => |Y a x-∫ b, tiltMean (unitSphereLaw (n+1)) (H (a.1,b)) (Y (a.1,b)) 1 ∂bulkDisorderLaw (n+1) M|)) from + (hY.sub (hE.measurable.comp measurable_fst.fst)).abs)).stronglyMeasurable.integral_prod_right' + (ν:=bulkDisorderLaw (n+1) M) |>.measurable + convert he using 1 + funext v + unfold bulkDegreeDeviation bulkEnergyDeviation + simp_rw [bulkCouplingSlope_eq_mean,Function.update_eq_self] + rfl + +lemma bulkDegreeDeviation_nonneg (n M : ℕ) (f : ℝ→ᵇℝ) (p : Fin (n+1)) (v : ℕ→ℝ) : + 0≤bulkDegreeDeviation n M f p v := bulkEnergyDeviation_nonneg n M f v p _ + +lemma bulkDegreeDeviation_integrable (n M : ℕ) (f : ℝ→ᵇℝ) (p : Fin (n+1)) : + Integrable (bulkDegreeDeviation n M f p) bulkParameterLaw := by + apply Integrable.of_bound (bulkDegreeDeviation_measurable n M f p).aestronglyMeasurable + (2*bulkCoefficient (n+1) p*(∫ a : BulkDisorder (n+1) M, ‖a.2‖ ∂bulkDisorderLaw (n+1) M)) + exact ae_of_all _ fun v => by + rw [Real.norm_eq_abs,abs_of_nonneg (bulkDegreeDeviation_nonneg n M f p v)] + exact bulkEnergyDeviation_bound n M f v p _ + +lemma bulkDegreeDeviation_update (n M : ℕ) (f : ℝ→ᵇℝ) (p : Fin (n+1)) (v : ℕ→ℝ) (u : ℝ) : + bulkDegreeDeviation n M f p (Function.update v (p.val+1) u)=bulkEnergyDeviation n M f v p u := by + simp only [bulkDegreeDeviation,Function.update_self,bulkEnergyDeviation,bulkCouplingSlope,Function.update_idem] + +lemma bulkDegreeDeviation_integral_bound (n M : ℕ) (f : ℝ→ᵇℝ) (p : Fin (n+1)) + {s : ℝ} (hs : 0 intervalIntegral.integral_nonneg (by norm_num) + (fun u _ => bulkEnergyDeviation_nonneg n M f v p u)) (integrable_const _) + filter_upwards [bulkParameterLaw_ae] with v hv + exact bulkEnergyDeviation_integrated_bound n M f v p hs hs1 (by norm_num) (fun j => + abs_le.mpr ⟨by linarith [(hv j).1],by linarith [(hv j).2]⟩) + _ = _ := by simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkRadialIBP.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkRadialIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..e24c09061319084fbf545b2b8cc99495099d866c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkRadialIBP.lean @@ -0,0 +1,117 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkReplicaDominated +import OAI.Probability.Perceptron.Pressure.SphericalPatternRadial + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def freshRadial (N : ℕ) (f : Jet3) (b : Spin N) (x : Fin 1→NormalizedSpin N) : ℝ := + inner ℝ (x 0).val b*f.d1 (inner ℝ (x 0).val b) +def freshSecond (N : ℕ) (f : Jet3) (b : Spin N) (x : Fin 1→NormalizedSpin N) : ℝ := + f.d2 (inner ℝ (x 0).val b)+f.d1 (inner ℝ (x 0).val b)^2 +def freshRadialPair (N : ℕ) (f : Jet3) (b : Spin N) (x : Fin 2→NormalizedSpin N) : ℝ := + spinOverlap (x 0) (x 1)*f.d1 (inner ℝ (x 0).val b)*f.d1 (inner ℝ (x 1).val b) + +lemma freshRadial_measurable (N : ℕ) (f : Jet3) : Measurable (Function.uncurry (freshRadial N f)) := by + have hc : Continuous (Function.uncurry (freshRadial N f)) := by unfold freshRadial Function.uncurry; fun_prop + exact hc.measurable +lemma freshSecond_measurable (N : ℕ) (f : Jet3) : Measurable (Function.uncurry (freshSecond N f)) := by + have hc : Continuous (Function.uncurry (freshSecond N f)) := by unfold freshSecond Function.uncurry; fun_prop + exact hc.measurable +lemma freshRadialPair_measurable (N : ℕ) (f : Jet3) : Measurable (Function.uncurry (freshRadialPair N f)) := by + have hc : Continuous (Function.uncurry (freshRadialPair N f)) := by unfold freshRadialPair spinOverlap Function.uncurry; fun_prop + exact hc.measurable + +lemma freshRadial_bound (N : ℕ) (f : Jet3) (b : Spin N) (x : Fin 1→NormalizedSpin N) : + |freshRadial N f b x|≤‖f.d1‖*‖b‖ := by + unfold freshRadial + rw [abs_mul,mul_comm] + exact mul_le_mul (f.d1.norm_coe_le_norm _) (normalizedSpin_inner_bound (x 0) b) (abs_nonneg _) (norm_nonneg _) +lemma freshSecond_bound (N : ℕ) (f : Jet3) (b : Spin N) (x : Fin 1→NormalizedSpin N) : + |freshSecond N f b x|≤‖f.d2‖+‖f.d1‖^2 := by + apply (abs_add_le _ _).trans + apply add_le_add (f.d2.norm_coe_le_norm _) + rw [abs_pow] + exact pow_le_pow_left₀ (abs_nonneg _) (f.d1.norm_coe_le_norm _) 2 +lemma freshRadialPair_bound (N : ℕ) (f : Jet3) (b : Spin N) (x : Fin 2→NormalizedSpin N) : + |freshRadialPair N f b x|≤‖f.d1‖^2 := by + unfold freshRadialPair + rw [abs_mul,abs_mul] + apply (mul_le_mul (mul_le_mul (spinOverlap_abs_le (x 0) (x 1)) + (f.d1.norm_coe_le_norm (inner ℝ (x 0).val b)) (abs_nonneg _) (by norm_num : (0:ℝ)≤1)) + (f.d1.norm_coe_le_norm (inner ℝ (x 1).val b)) (abs_nonneg _) (by positivity)).trans_eq + ring + +lemma fresh_radial_ibp (n : ℕ) (f : Jet3) + {h : NormalizedSpin (n+1)→ℝ} (hh : Measurable h) {A : ℝ} (hA : 0≤A) (hb : ∀ x,|h x|≤A) : + (∫ b : Spin (n+1), gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => h x+f.f (inner ℝ x.val b)) 1 (freshRadial (n+1) f b) ∂stdGaussian (Spin (n+1))) = + ∫ b : Spin (n+1), gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => h x+f.f (inner ℝ x.val b)) 1 (freshSecond (n+1) f b)- + gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => h x+f.f (inner ℝ x.val b)) 2 (freshRadialPair (n+1) f b) ∂stdGaussian (Spin (n+1)) := by + have hH : Measurable (Function.uncurry (fun b : Spin (n+1) => fun x : NormalizedSpin (n+1) => h x+f.f (inner ℝ x.val b))) := + (hh.comp measurable_snd).add (f.f.measurable.comp (measurable_snd.subtype_val.inner measurable_fst)) + have h1 := measurable_replicaMean_param (unitSphereLaw (n+1)) hH (freshRadial_measurable (n+1) f) + have h2 := measurable_replicaMean_param (unitSphereLaw (n+1)) hH (freshSecond_measurable (n+1) f) + have h3 := measurable_replicaMean_param (unitSphereLaw (n+1)) hH (freshRadialPair_measurable (n+1) f) + have h23 : AEStronglyMeasurable (fun b : Spin (n+1) => + gibbsReplicaMean (unitSphereLaw (n+1)) (fun x => h x+f.f (inner ℝ x.val b)) 1 (freshSecond (n+1) f b)- + gibbsReplicaMean (unitSphereLaw (n+1)) (fun x => h x+f.f (inner ℝ x.val b)) 2 (freshRadialPair (n+1) f b)) + (Measure.map (WithLp.toLp 2) (Measure.pi fun _ : Fin (n+1) => gaussianReal 0 1)) := + (h2.sub h3).aestronglyMeasurable + rw [←map_pi_eq_stdGaussian,integral_map (PiLp.continuous_toLp 2 _).measurable.aemeasurable h1.aestronglyMeasurable, + integral_map (PiLp.continuous_toLp 2 _).measurable.aemeasurable h23] + have he := spherical_pattern_radial_ibp (unitSphereLaw (n+1)) f hh hA hb + unfold freshRadial freshSecond freshRadialPair + convert he using 1 <;> + simp only [gaussianField,EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial] + +lemma bulk_radial_last_ibp (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) : + bulkReplicaMean n (M+1) f.f v 1 (fun a => freshRadial (n+1) f (bulkSeparateLast (n+1) M a).2) = + bulkReplicaMean n (M+1) f.f v 1 (fun a => freshSecond (n+1) f (bulkSeparateLast (n+1) M a).2)- + bulkReplicaMean n (M+1) f.f v 2 (fun a => freshRadialPair (n+1) f (bulkSeparateLast (n+1) M a).2) := by + have hD : Integrable (fun b : Spin (n+1) => ‖f.d1‖*‖b‖) (stdGaussian (Spin (n+1))) := + ((((IsGaussian.memLp_id (stdGaussian (Spin (n+1))) 2 (by simp)).norm).integrable (by norm_num))).const_mul _ + rw [bulkReplicaMean_last_integral n M 1 f.f v _ (freshRadial_measurable _ _) hD (fun _ => by positivity) (freshRadial_bound _ _), + bulkReplicaMean_last_integral n M 1 f.f v _ (freshSecond_measurable _ _) (integrable_const _) (fun _ => by positivity) (freshSecond_bound _ _), + bulkReplicaMean_last_integral n M 2 f.f v _ (freshRadialPair_measurable _ _) (integrable_const _) (fun _ => by positivity) (freshRadialPair_bound _ _)] + let P := fun p : BulkDisorder (n+1) M×Spin (n+1) => gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => bulkHamiltonian (n+1) M f.f v p.1.1 p.1.2 x+f.f (inner ℝ x.val p.2)) 1 (freshSecond (n+1) f p.2) + let T := fun p : BulkDisorder (n+1) M×Spin (n+1) => gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => bulkHamiltonian (n+1) M f.f v p.1.1 p.1.2 x+f.f (inner ℝ x.val p.2)) 2 (freshRadialPair (n+1) f p.2) + have hiP : Integrable P ((bulkDisorderLaw (n+1) M).prod (stdGaussian (Spin (n+1)))) := + bulkFreshReplicaMean_integrable n M 1 f.f v _ (freshSecond_measurable _ _) + (integrable_const _) (fun _ => by positivity) (freshSecond_bound _ _) + have hiT : Integrable T ((bulkDisorderLaw (n+1) M).prod (stdGaussian (Spin (n+1)))) := + bulkFreshReplicaMean_integrable n M 2 f.f v _ (freshRadialPair_measurable _ _) + (integrable_const _) (fun _ => by positivity) (freshRadialPair_bound _ _) + calc + _ = ∫ a : BulkDisorder (n+1) M, ∫ b : Spin (n+1), P (a,b)-T (a,b) + ∂stdGaussian (Spin (n+1)) ∂bulkDisorderLaw (n+1) M := by + apply integral_congr_ae + exact ae_of_all _ fun a => fresh_radial_ibp n f + (bulkHamiltonian_section_measurable _ _ _ _ a) + (show 0≤M*‖f.f‖+bulkFeatureBound (n+1) v*‖a.2‖ by unfold bulkFeatureBound; positivity) + (bulkHamiltonian_bound (n+1) M f.f v a) + _ = _ := by + have hiPT : Integrable (fun p => P p-T p) ((bulkDisorderLaw (n+1) M).prod (stdGaussian (Spin (n+1)))) := hiP.sub hiT + rw [←integral_prod _ hiPT,integral_sub hiP hiT,integral_prod _ hiP,integral_prod _ hiT] + +lemma bulk_radial_row_ibp (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (j : Fin (M+1)) : + bulkReplicaMean n (M+1) f.f v 1 (fun a => freshRadial (n+1) f (WithLp.toLp 2 (a.1 j))) = + bulkReplicaMean n (M+1) f.f v 1 (fun a => freshSecond (n+1) f (WithLp.toLp 2 (a.1 j)))- + bulkReplicaMean n (M+1) f.f v 2 (fun a => freshRadialPair (n+1) f (WithLp.toLp 2 (a.1 j))) := by + rw [bulkReplicaMean_row_eq_last _ _ _ _ _ _ _ (freshRadial_measurable _ _), + bulkReplicaMean_row_eq_last _ _ _ _ _ _ _ (freshSecond_measurable _ _), + bulkReplicaMean_row_eq_last _ _ _ _ _ _ _ (freshRadialPair_measurable _ _)] + exact bulk_radial_last_ibp n M f v + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkRadialIdentity.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkRadialIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..017c228f8c79e9b793d898eedc5c10b814fd299c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkRadialIdentity.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkRadialIBP +import OAI.Probability.Perceptron.Cavity.BulkSingleEmpiricalLimit + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped BigOperators BoundedContinuousFunction Topology + +lemma bulkReplicaMean_sub_bounded (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (F G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hF : Measurable (Function.uncurry F)) (hG : Measurable (Function.uncurry G)) + (A B : ℝ) (hA : ∀ a x,|F a x|≤A) (hB : ∀ a x,|G a x|≤B) : + bulkReplicaMean n M f v r (fun a x => F a x-G a x)= + bulkReplicaMean n M f v r F-bulkReplicaMean n M f v r G := by + rw [bulkReplicaMean_annealed _ _ _ _ _ _ (hF.sub hG) (A+B) + (fun a x => (abs_sub _ _).trans (add_le_add (hA a x) (hB a x))), + bulkReplicaMean_annealed _ _ _ _ _ _ hF A hA, + bulkReplicaMean_annealed _ _ _ _ _ _ hG B hB] + exact integral_sub (bulkReplicaPrefix_integrable _ _ _ _ _ F hF A hA) + (bulkReplicaPrefix_integrable _ _ _ _ _ G hG B hB) + +def bulkRadialRow (n M : ℕ) (f : Jet3) (j : Fin M) (a : BulkDisorder (n+1) M) := freshRadial (n+1) f (WithLp.toLp 2 (a.1 j)) +def bulkSecondRow (n M : ℕ) (f : Jet3) (j : Fin M) (a : BulkDisorder (n+1) M) := freshSecond (n+1) f (WithLp.toLp 2 (a.1 j)) +def bulkRadialPairRow (n M : ℕ) (f : Jet3) (j : Fin M) (a : BulkDisorder (n+1) M) := freshRadialPair (n+1) f (WithLp.toLp 2 (a.1 j)) + +lemma bulkFreshRow_measurable (n M r : ℕ) (j : Fin M) : + Measurable (fun p : BulkDisorder (n+1) M×(Fin r→NormalizedSpin (n+1)) => (WithLp.toLp 2 (p.1.1 j),p.2)) := + (((PiLp.continuous_toLp 2 _).measurable.comp ((measurable_pi_apply j).comp + (measurable_fst.comp measurable_fst))).prodMk measurable_snd) + +lemma bulkRadialRow_measurable (n M : ℕ) (f : Jet3) (j : Fin M) : + Measurable (Function.uncurry (bulkRadialRow n M f j)) := + (freshRadial_measurable (n+1) f).comp (bulkFreshRow_measurable n M 1 j) +lemma bulkSecondRow_measurable (n M : ℕ) (f : Jet3) (j : Fin M) : + Measurable (Function.uncurry (bulkSecondRow n M f j)) := + by unfold bulkSecondRow freshSecond Function.uncurry; fun_prop +lemma bulkRadialPairRow_measurable (n M : ℕ) (f : Jet3) (j : Fin M) : + Measurable (Function.uncurry (bulkRadialPairRow n M f j)) := + by unfold bulkRadialPairRow freshRadialPair spinOverlap Function.uncurry; fun_prop + +def Jet3.radialMark (f : Jet3) (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) : ℝ→ᵇℝ := + ofCompactSupport (fun z => z*f.d1 z) (continuous_id.mul f.d1.continuous) hf.mul_left + +lemma bulkRadialRow_bound (n M : ℕ) (f : Jet3) (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) + (j : Fin M) (a : BulkDisorder (n+1) M) (x : Fin 1→NormalizedSpin (n+1)) : + |bulkRadialRow n M f j a x|≤‖f.radialMark hf‖ := (f.radialMark hf).norm_coe_le_norm _ + +lemma bulk_radial_difference (n M : ℕ) (f : Jet3) (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℝ) (j : Fin M) : + bulkReplicaMean n M f.f v 1 (fun a x => bulkSecondRow n M f j a x-bulkRadialRow n M f j a x)= + bulkReplicaMean n M f.f v 2 (bulkRadialPairRow n M f j) := by + rw [bulkReplicaMean_sub_bounded n M 1 f.f v _ _ (bulkSecondRow_measurable n M f j) + (bulkRadialRow_measurable n M f j) (‖f.d2‖+‖f.d1‖^2) ‖f.radialMark hf‖ + (fun a x => freshSecond_bound _ _ _ _) (bulkRadialRow_bound n M f hf j)] + have hi : bulkReplicaMean n M f.f v 1 (bulkRadialRow n M f j)= + bulkReplicaMean n M f.f v 1 (bulkSecondRow n M f j)-bulkReplicaMean n M f.f v 2 (bulkRadialPairRow n M f j) := by + cases M with + | zero => exact Fin.elim0 j + | succ M => exact bulk_radial_row_ibp n M f v j + linarith + +lemma bulk_radial_sum_eq (n M : ℕ) (f : Jet3) (a : BulkDisorder (n+1) M) (x : Fin 1→NormalizedSpin (n+1)) : + bulkC (n+1) M f a.1 (x 0)+bulkB (n+1) M f a.1 (x 0) (x 0)= + ((n+1:ℕ):ℝ)⁻¹*∑ j : Fin M,(bulkSecondRow n M f j a x-bulkRadialRow n M f j a x) := by + simp only [bulkC,bulkB,bulkSecondRow,bulkRadialRow,freshSecond,freshRadial, + EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial] + rw [←mul_add,←Finset.sum_add_distrib] + congr 1 + apply Finset.sum_congr rfl + intro j _ + ring + +lemma bulk_radial_pair_sum_eq (n M : ℕ) (f : Jet3) (a : BulkDisorder (n+1) M) (x : Fin 2→NormalizedSpin (n+1)) : + spinOverlap (x 0) (x 1)*bulkB (n+1) M f a.1 (x 0) (x 1)= + ((n+1:ℕ):ℝ)⁻¹*∑ j : Fin M,bulkRadialPairRow n M f j a x := by + simp only [bulkB,bulkRadialPairRow,freshRadialPair,EuclideanSpace.inner_eq_star_dotProduct, + dotProduct,star_trivial] + rw [mul_left_comm,Finset.mul_sum] + congr 1 + apply Finset.sum_congr rfl + intro j _ + ring + +lemma bulk_radial_sum_identity (n M : ℕ) (f : Jet3) + (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℝ) : + bulkReplicaMean n M f.f v 1 (fun a x => bulkC (n+1) M f a.1 (x 0)+ + bulkB (n+1) M f a.1 (x 0) (x 0))= + bulkReplicaMean n M f.f v 2 (fun a x => spinOverlap (x 0) (x 1)* + bulkB (n+1) M f a.1 (x 0) (x 1)) := by + simp_rw [bulk_radial_sum_eq,bulk_radial_pair_sum_eq] + rw [bulkReplicaMean_const_mul,bulkReplicaMean_const_mul] + congr 1 + rw [bulkReplicaMean_sum n M 1 f.f v Finset.univ (fun j a x => bulkSecondRow n M f j a x-bulkRadialRow n M f j a x) + (fun j _ => (bulkSecondRow_measurable n M f j).sub (bulkRadialRow_measurable n M f j)) + (fun _ => ‖f.d2‖+‖f.d1‖^2+‖f.radialMark hf‖) + (fun _ _ => by positivity) (fun j _ a x => (abs_sub _ _).trans + (add_le_add (freshSecond_bound _ _ _ _) (bulkRadialRow_bound n M f hf j a x))), + bulkReplicaMean_sum n M 2 f.f v Finset.univ (bulkRadialPairRow n M f) + (fun j _ => bulkRadialPairRow_measurable n M f j) (fun _ => ‖f.d1‖^2) + (fun _ _ => by positivity) (fun j _ a x => freshRadialPair_bound _ _ _ _)] + exact Finset.sum_congr rfl fun j _ => bulk_radial_difference n M f hf v j + +lemma bulkReplicaMean_add_bounded (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (F G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hF : Measurable (Function.uncurry F)) (hG : Measurable (Function.uncurry G)) + (A B : ℝ) (hA : ∀ a x,|F a x|≤A) (hB : ∀ a x,|G a x|≤B) : + bulkReplicaMean n M f v r (fun a x => F a x+G a x)= + bulkReplicaMean n M f v r F+bulkReplicaMean n M f v r G := by + rw [bulkReplicaMean_annealed _ _ _ _ _ _ (hF.add hG) (A+B) + (fun a x => (abs_add_le _ _).trans (add_le_add (hA a x) (hB a x))), + bulkReplicaMean_annealed _ _ _ _ _ _ hF A hA, + bulkReplicaMean_annealed _ _ _ _ _ _ hG B hB] + exact integral_add (bulkReplicaPrefix_integrable _ _ _ _ _ F hF A hA) + (bulkReplicaPrefix_integrable _ _ _ _ _ G hG B hB) + +lemma bulkReplicaMean_mean_square_le (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (F : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hF : Measurable (Function.uncurry F)) (A : ℝ) (hA : 0≤A) (hb : ∀ a x,|F a x|≤A) (c : ℝ) : + (bulkReplicaMean n M f v r F-c)^2≤ + bulkReplicaMean n M f v r (fun a x => (F a x-c)^2) := by + rw [bulkReplicaMean_centered_square n M f v r F hF A hA hb c] + have hme : Measurable (fun p : BulkDisorder (n+1) M×(ℕ→NormalizedSpin (n+1)) => F p.1 (fun i : Fin r=>p.2 i.val)) := + hF.comp (measurable_fst.prodMk (Measurable.of_eval fun coordinate => + (measurable_pi_apply coordinate.val).comp measurable_snd)) + have hp : MemLp (fun p => F p.1 (fun i : Fin r=>p.2 i.val)) 2 (bulkAnnealedReplicaLaw n M f v) := + MemLp.of_bound hme.aestronglyMeasurable A (ae_of_all _ fun p=>by simpa only [Real.norm_eq_abs] using hb p.1 (fun i=>p.2 i.val)) + have hvv := variance_nonneg (fun p => F p.1 (fun i : Fin r=>p.2 i.val)) (bulkAnnealedReplicaLaw n M f v) + rw [variance_eq_sub hp] at hvv + rw [bulkReplicaMean_annealed n M f v r F hF A hb, + bulkReplicaMean_annealed n M f v r (fun a x => (F a x)^2) (hF.pow_const 2) (A^2) + (fun a x => by rw [abs_pow]; exact pow_le_pow_left₀ (abs_nonneg _) (hb a x) 2)] + simp only [Pi.pow_apply] at hvv + nlinarith + +lemma bulkReplicaMean_L2_tendsto (N M : ℕ→ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℕ→ℝ) (r : ℕ) + (F : (n : ℕ)→BulkDisorder (N n+1) (M n)→(Fin r→NormalizedSpin (N n+1))→ℝ) + (hF : ∀ n,Measurable (Function.uncurry (F n))) (A : ℕ→ℝ) (hA : ∀ n,0≤A n) + (hb : ∀ n a x,|F n a x|≤A n) (c : ℝ) + (hl : Tendsto (fun n=>bulkReplicaMean (N n) (M n) f (v n) r (fun a x => (F n a x-c)^2)) atTop (𝓝 0)) : + Tendsto (fun n=>bulkReplicaMean (N n) (M n) f (v n) r (F n)) atTop (𝓝 c) := by + have hb' n : |bulkReplicaMean (N n) (M n) f (v n) r (F n)-c|≤ + Real.sqrt (bulkReplicaMean (N n) (M n) f (v n) r (fun a x => (F n a x-c)^2)) := by + have he := bulkReplicaMean_mean_square_le (N n) (M n) r f (v n) (F n) (hF n) (A n) (hA n) (hb n) c + exact Real.abs_le_sqrt he + apply tendsto_iff_norm_sub_tendsto_zero.mpr + simp only [Real.norm_eq_abs] + exact squeeze_zero (fun n=>abs_nonneg _) hb' (by simpa only [Real.sqrt_zero] using hl.sqrt) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkRadialLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkRadialLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..99c73bb84eb0f3085b5a063d3ff154a26c8d99b8 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkRadialLimit.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkRadialIdentity + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BoundedContinuousFunction BigOperators Matrix + +lemma bulk_single_mean_of_L2 (N M : ℕ→ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℕ→ℝ) (c : ℝ) + (hl : Tendsto (fun n=>bulkReplicaMean (N n) (M n) f (v n) 1 + (fun a x=>(bulkSingleAverage (N n) (M n) w a x-c)^2)) atTop (𝓝 0)) : + Tendsto (fun n=>bulkReplicaMean (N n) (M n) f (v n) 1 + (bulkSingleAverage (N n) (M n) w)) atTop (𝓝 c) := + bulkReplicaMean_L2_tendsto N M f v 1 (fun n=>bulkSingleAverage (N n) (M n) w) + (fun n=>bulkSingleAverage_measurable _ _ _) (fun n=>(M n:ℝ)/(N n+1:ℕ)*‖w‖) + (fun n=>by positivity) (fun n=>bulkSingleAverage_bound _ _ _) c hl + +lemma bulk_diagonal_mean_add (n M : ℕ) (f : Jet3) + (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℝ) : + bulkReplicaMean n M f.f v 1 (fun a x=>bulkC (n+1) M f a.1 (x 0)+ + bulkB (n+1) M f a.1 (x 0) (x 0))= + bulkReplicaMean n M f.f v 1 (bulkSingleAverage n M (f.dilationMark hf))+ + bulkReplicaMean n M f.f v 1 (bulkSingleAverage n M (f.d1*f.d1)) := by + change bulkReplicaMean n M f.f v 1 (fun a x=>bulkSingleAverage n M (f.dilationMark hf) a x+ + bulkSingleAverage n M (f.d1*f.d1) a x)=_ + exact bulkReplicaMean_add_bounded n M 1 f.f v _ _ + (bulkSingleAverage_measurable _ _ _) (bulkSingleAverage_measurable _ _ _) _ _ + (bulkSingleAverage_bound _ _ _) (bulkSingleAverage_bound _ _ _) + +lemma bulk_radial_limit_relation (N M : ℕ→ℕ) (f : Jet3) + (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℕ→ℝ) (c d : ℝ) + (hc : Tendsto (fun n=>bulkReplicaMean (N n) (M n) f.f (v n) 1 + (fun a x=>(bulkC (N n+1) (M n) f a.1 (x 0)-c)^2)) atTop (𝓝 0)) + (hd : Tendsto (fun n=>bulkReplicaMean (N n) (M n) f.f (v n) 1 + (fun a x=>(bulkB (N n+1) (M n) f a.1 (x 0) (x 0)-d)^2)) atTop (𝓝 0)) + (K : ℝ) (hK : ∀ n,(M n:ℝ)/(N n+1:ℕ)*‖f.d1‖^2≤K) + (μ : ProbabilityMeasure (BulkPairRange K)) + (hl : Tendsto (fun n=>bulkPairLaw (N n) (M n) f.f f.d1 (v n) K (hK n)) atTop (𝓝 μ)) : + c+d=∫ p,p.1.val*p.2.val ∂(μ : Measure (BulkPairRange K)) := by + have hcm := bulk_single_mean_of_L2 N M f.f (f.dilationMark hf) v c hc + have hdm := bulk_single_mean_of_L2 N M f.f (f.d1*f.d1) v d hd + have hs := hcm.add hdm + have he n := bulk_diagonal_mean_add (N n) (M n) f hf (v n) + simp_rw [←he,bulk_radial_sum_identity _ _ f hf] at hs + let F : BulkPairRange K→ᵇℝ := BoundedContinuousFunction.mkOfCompact ⟨fun p=>p.1.val*p.2.val,by fun_prop⟩ + have ht := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction F).continuousAt.tendsto.comp hl + have htest n : (∫ p,F p ∂(bulkPairLaw (N n) (M n) f.f f.d1 (v n) K (hK n) : Measure _))= + bulkReplicaMean (N n) (M n) f.f (v n) 2 + (fun a x=>spinOverlap (x 0) (x 1)*bulkB (N n+1) (M n) f a.1 (x 0) (x 1)) := by + rw [bulkPairLaw_integral] + congr 1 + funext a x + change spinOverlap (x 1) (x 0)*bulkPairAverage (N n) (M n) f.d1 a x=_ + rw [←bulkB_pairAverage] + congr 1 + exact real_inner_comm _ _ + change Tendsto (fun n=>∫ p,F p ∂(bulkPairLaw (N n) (M n) f.f f.d1 (v n) K (hK n) : Measure _)) atTop _ at ht + simp_rw [htest] at ht + exact tendsto_nhds_unique hs ht + +lemma isClosed_covarianceMatrix {I : Type*} [Fintype I] [DecidableEq I] : + IsClosed {M : Matrix I I ℝ | M.PosSemidef} := by + have he : {M : Matrix I I ℝ | M.PosSemidef} = + {M : Matrix I I ℝ | ∀ i j, M j i=M i j} ∩ ⋂ x : I → ℝ, + {M : Matrix I I ℝ | 0 ≤ star x ⬝ᵥ (M *ᵥ x)} := by + ext M + simp only [mem_ofPred_eq,mem_inter_iff,mem_iInter,Matrix.posSemidef_iff_dotProduct_mulVec, + Matrix.IsHermitian.ext_iff,star_trivial] + rw [he] + apply IsClosed.inter + · simp only [ofPred_forall] + exact isClosed_iInter fun i => isClosed_iInter fun j => isClosed_eq (by fun_prop) (by fun_prop) + · exact isClosed_iInter fun x => isClosed_le continuous_const (by + unfold dotProduct Matrix.mulVec + fun_prop) + +private lemma cavity_extension_exists {I : Type*} [Fintype I] [DecidableEq I] + (Ψ : EuclideanSpace ℝ I →ᵇ ℝ) : + ∃ F : Matrix I I ℝ →ᵇ ℝ, + ‖F‖=‖gaussianCovarianceKernel Ψ‖ ∧ + ∀ C : CovarianceMatrix I, F C.val=gaussianCovarianceKernel Ψ C := by + let : NormalSpace (Matrix I I ℝ) := inferInstanceAs (NormalSpace (I→I→ℝ)) + obtain ⟨F,hF,he⟩ := (gaussianCovarianceKernel Ψ).exists_extension_norm_eq_of_isClosedEmbedding + isClosed_covarianceMatrix.isClosedEmbedding_subtypeVal + exact ⟨F,hF,fun C => congrFun he C⟩ + +def cavityMatrixKernel {I : Type*} [Fintype I] [DecidableEq I] + (Ψ : EuclideanSpace ℝ I →ᵇ ℝ) : Matrix I I ℝ →ᵇ ℝ := + Classical.choose (cavity_extension_exists Ψ) + +lemma cavityMatrixKernel_posSemidef {I : Type*} [Fintype I] [DecidableEq I] + (Ψ : EuclideanSpace ℝ I →ᵇ ℝ) (C : Matrix I I ℝ) (hC : C.PosSemidef) : + cavityMatrixKernel Ψ C=∫ z,Ψ z ∂multivariateGaussian 0 C := + (Classical.choose_spec (cavity_extension_exists Ψ)).2 ⟨C,hC⟩ + +lemma sphericalExp_continuous (n : ℕ) (R : ℝ) : Continuous (fun x => sphericalExp n x R) := by + have h : (fun x => sphericalExp n x R) = fun x => Real.exp (logSphericalExp n R x) := by + ext x + exact (Real.exp_log ((by norm_num : (0:ℝ)<1).trans_le (one_le_sphericalExp n x R))).symm + rw [h] + exact (logSphericalExp_lipschitz n R).continuous.rexp + +def cappedSphericalExp (n : ℕ) (R Λ : ℝ) (hΛ : 1≤Λ) : Spin (n+1) →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound + ⟨fun x => min (sphericalExp n x R) Λ,(sphericalExp_continuous n R).min continuous_const⟩ + (2*Λ) (by + intro x y + have hx : 1 ≤ min (sphericalExp n x R) Λ := le_min (one_le_sphericalExp n x R) hΛ + have hy : 1 ≤ min (sphericalExp n y R) Λ := le_min (one_le_sphericalExp n y R) hΛ + change |min (sphericalExp n x R) Λ-min (sphericalExp n y R) Λ|≤2*Λ + exact abs_le.mpr ⟨by linarith [min_le_right (sphericalExp n y R) Λ], + by linarith [min_le_right (sphericalExp n x R) Λ]⟩) + +abbrev CavityReplicaIndex (n d r : ℕ) := (Fin (n+1) ⊕ Fin d) × Fin r + +def cavityVectorProjection (n d r : ℕ) (j : Fin r) : + C(EuclideanSpace ℝ (CavityReplicaIndex n d r),Spin (n+1)) := + ⟨fun z => WithLp.toLp 2 (fun i => z (Sum.inl i,j)),by fun_prop⟩ + +def cavityReplicaTest (n d r : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) : + EuclideanSpace ℝ (CavityReplicaIndex n d r) →ᵇ ℝ := + ∏ j : Fin r, + (cappedSphericalExp n (Real.sqrt (n+1:ℕ)) Λ hΛ).compContinuous (cavityVectorProjection n d r j) * + ∏ t : Fin d,(expBCF 1 f).compContinuous ⟨fun z => z (Sum.inr t,j),by fun_prop⟩ + +lemma cavityReplicaTest_apply (n d r : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (z : EuclideanSpace ℝ (CavityReplicaIndex n d r)) : + cavityReplicaTest n d r f Λ hΛ z = + ∏ j : Fin r, min (sphericalExp n (WithLp.toLp 2 (fun i => z (Sum.inl i,j))) + (Real.sqrt (n+1:ℕ))) Λ * ∏ t : Fin d,Real.exp (f (z (Sum.inr t,j))) := by + simp [cavityReplicaTest,cappedSphericalExp,cavityVectorProjection,expBCF] + +def cavityBlockCovariance (n d r : ℕ) {K : ℝ} (Q : CompactArray (BulkPairRange K)) : + Matrix (CavityReplicaIndex n d r) (CavityReplicaIndex n d r) ℝ := + fun i j => if i.1=j.1 then + Sum.elim (fun _ => (Q i.2 j.2).2.val) (fun _ => (Q i.2 j.2).1.val) i.1 else 0 + +lemma cavityBlockCovariance_continuous (n d r : ℕ) (K : ℝ) : + Continuous (cavityBlockCovariance n d r (K:=K)) := by + classical + apply continuous_pi + intro i + apply continuous_pi + intro j + unfold cavityBlockCovariance + split_ifs + · cases i.1 <;> dsimp only [Sum.elim] <;> fun_prop + · exact continuous_const + +def cavityArrayKernel (n d r : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) (K : ℝ) : + CompactArray (BulkPairRange K) →ᵇ ℝ := + (cavityMatrixKernel (cavityReplicaTest n d r f Λ hΛ)).compContinuous + ⟨cavityBlockCovariance n d r,cavityBlockCovariance_continuous n d r K⟩ + +lemma cavityArrayKernel_tendsto (n d r : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) (K : ℝ) + {ν : ℕ→ProbabilityMeasure (CompactArray (BulkPairRange K))} + {ν₀ : ProbabilityMeasure (CompactArray (BulkPairRange K))} + (hν : Tendsto ν atTop (𝓝 ν₀)) : + Tendsto (fun j => ∫ Q,cavityArrayKernel n d r f Λ hΛ K Q ∂ν j) atTop + (𝓝 (∫ Q,cavityArrayKernel n d r f Λ hΛ K Q ∂ν₀)) := + (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (cavityArrayKernel n d r f Λ hΛ K)).continuousAt.tendsto.comp hν + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkReplicaDominated.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkReplicaDominated.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d1cb76930dd21cb2d6815e8eb26e179af4af18e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkReplicaDominated.lean @@ -0,0 +1,316 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkConcentration +import OAI.Probability.Perceptron.Pressure.SphericalPatternDirection +import OAI.Probability.Perceptron.Cavity.BulkFreshRestore + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma replicaMean_param_integrable_dominated {S Ω : Type*} [MeasurableSpace S] [MeasurableSpace Ω] + (μ : Measure S) [IsProbabilityMeasure μ] (ν : Measure Ω) (r : ℕ) + {H : Ω→S→ℝ} {F : Ω→(Fin r→S)→ℝ} + (hH : Measurable (Function.uncurry H)) (hF : Measurable (Function.uncurry F)) + {D : Ω→ℝ} (hD : Integrable D ν) (hD0 : ∀ a,0≤D a) (hb : ∀ a x,|F a x|≤D a) : + Integrable (fun a => gibbsReplicaMean μ (H a) r (F a)) ν := by + apply hD.mono' (measurable_replicaMean_param μ hH hF).aestronglyMeasurable + exact ae_of_all _ fun a => by + rw [Real.norm_eq_abs] + exact tiltMean_bound_general _ (replicaPotential_measurable hH.of_uncurry_left r) + hF.of_uncurry_left (hD0 a) (hb a) + +lemma bulkReplicaMean_sum_dominated (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + {ι : Type*} (s : Finset ι) + (F : ι→BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hF : ∀ i∈s,Measurable (Function.uncurry (F i))) + (D : ι→BulkDisorder (n+1) M→ℝ) (hD : ∀ i∈s,Integrable (D i) (bulkDisorderLaw (n+1) M)) + (hD0 : ∀ i∈s,∀ a,0≤D i a) (hb : ∀ i∈s,∀ a x,|F i a x|≤D i a) : + bulkReplicaMean n M f v r (fun a x => ∑ i∈s,F i a x)= + ∑ i∈s,bulkReplicaMean n M f v r (F i) := by + have hH := (bulkHamiltonian_continuous (n+1) M f v).measurable + unfold bulkReplicaMean + have he (a : BulkDisorder (n+1) M) := gibbsReplicaMean_sum_of_integrable + (unitSphereLaw (n+1)) s (bulkHamiltonian_section_measurable _ _ _ _ a) (bulkHamiltonian_exp_integrable n M f v a) + (fun i hi => (hF i hi).of_uncurry_left) (fun i hi x => hb i hi a x) + simp_rw [he] + exact integral_finsetSum s fun i hi => replicaMean_param_integrable_dominated _ _ r hH + (hF i hi) (hD i hi) (hD0 i hi) (hb i hi) + +def bulkPatternSize {N M : ℕ} (j : Fin M) (a : BulkDisorder N M) : ℝ := ∑ i,|a.1 j i| + +lemma bulkPatternSize_integrable (N M : ℕ) (j : Fin M) : + Integrable (bulkPatternSize (N:=N) j) (bulkDisorderLaw N M) := by + apply (integrable_finsetSum _ fun i _ => ?_) + have hr : Integrable (fun b : Fin N→ℝ => |b i|) (Measure.pi fun _ => gaussianReal 0 1) := + ((measurePreserving_eval (fun _ : Fin N => gaussianReal 0 1) i).integrable_comp + measurable_id.norm.aestronglyMeasurable).mpr + (((memLp_id_gaussianReal (μ:=0) (v:=1) 1).integrable (by norm_num)).norm) + have ha := ((measurePreserving_eval (fun _ : Fin M => Measure.pi fun _ : Fin N => gaussianReal 0 1) j).integrable_comp + ((measurable_pi_apply i).norm.aestronglyMeasurable)).mpr hr + exact ha.comp_fst _ + +lemma bulkPatternFields_bound {N M r : ℕ} (j : Fin M) (a : BulkDisorder N M) + (x : Fin r→NormalizedSpin N) (i : Fin r) : |bulkPatternFields j a x i|≤bulkPatternSize j a := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro t _ + rw [abs_mul] + simpa only [mul_one] using mul_le_mul_of_nonneg_left (normalizedSpin_coord_bound (x i) t) (abs_nonneg (a.1 j t)) + +def bulkTangentPattern {N M : ℕ} (f : Jet3) (G : ℝ→ᵇℝ) (j : Fin M) + (a : BulkDisorder N M) (x : Fin 2→NormalizedSpin N) : ℝ := + G (spinOverlap (x 0) (x 1))*f.d1 (bulkPatternFields j a x 0)* + (bulkPatternFields j a x 1-spinOverlap (x 0) (x 1)*bulkPatternFields j a x 0) + +lemma bulkTangentPattern_measurable (N M : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) (j : Fin M) : + Measurable (Function.uncurry (bulkTangentPattern (N:=N) f G j)) := by + have hc : Continuous (Function.uncurry (bulkTangentPattern (N:=N) f G j)) := by + unfold bulkTangentPattern bulkPatternFields spinOverlap Function.uncurry + fun_prop + exact hc.measurable + +lemma bulkTangentPattern_bound {N M : ℕ} (f : Jet3) (G : ℝ→ᵇℝ) (j : Fin M) + (a : BulkDisorder N M) (x : Fin 2→NormalizedSpin N) : + |bulkTangentPattern f G j a x|≤2*‖G‖*‖f.d1‖*bulkPatternSize j a := by + have hD : 0≤bulkPatternSize j a := Finset.sum_nonneg fun i _ => abs_nonneg _ + have hd : |bulkPatternFields j a x 1-spinOverlap (x 0) (x 1)*bulkPatternFields j a x 0|≤2*bulkPatternSize j a := by + apply (abs_sub _ _).trans + rw [abs_mul] + have hm := mul_le_mul (spinOverlap_abs_le (x 0) (x 1)) (bulkPatternFields_bound j a x 0) (abs_nonneg _) (by norm_num : (0:ℝ)≤1) + linarith [bulkPatternFields_bound j a x 1] + unfold bulkTangentPattern + rw [abs_mul,abs_mul] + apply (mul_le_mul (mul_le_mul (G.norm_coe_le_norm _) (f.d1.norm_coe_le_norm _) (abs_nonneg _) (norm_nonneg _)) hd (abs_nonneg _) (by positivity)).trans_eq + ring + +lemma bulkTangentPattern_integrable (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) (j : Fin M) : + Integrable (fun a : BulkDisorder (n+1) M => gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f.f v a.1 a.2) 2 (bulkTangentPattern f G j a)) (bulkDisorderLaw (n+1) M) := by + exact replicaMean_param_integrable_dominated _ _ 2 (bulkHamiltonian_continuous _ _ _ _).measurable + (bulkTangentPattern_measurable _ _ _ _ _) ((bulkPatternSize_integrable (n+1) M j).const_mul (2*‖G‖*‖f.d1‖)) + (fun a => mul_nonneg (by positivity) (Finset.sum_nonneg fun i _ => abs_nonneg _)) + (bulkTangentPattern_bound f G j) + + +def freshTangent (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) + (b : Spin N) (x : Fin 2→NormalizedSpin N) : ℝ := + G (spinOverlap (x 0) (x 1))*f.d1 (inner ℝ (x 0).val b)* + (inner ℝ (x 1).val b-spinOverlap (x 0) (x 1)*inner ℝ (x 0).val b) + +def freshTangentPair (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) + (b : Spin N) (x : Fin 2→NormalizedSpin N) : ℝ := + G (spinOverlap (x 0) (x 1))*f.d1 (inner ℝ (x 0).val b)*f.d1 (inner ℝ (x 1).val b)* + (1-spinOverlap (x 0) (x 1)^2) + +def freshTangentTriple (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) + (b : Spin N) (x : Fin 3→NormalizedSpin N) : ℝ := + G (spinOverlap (x 1) (x 2))*f.d1 (inner ℝ (x 1).val b)*f.d1 (inner ℝ (x 0).val b)* + (spinOverlap (x 2) (x 0)-spinOverlap (x 1) (x 2)*spinOverlap (x 1) (x 0)) + +lemma freshTangent_measurable (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) : + Measurable (Function.uncurry (freshTangent N f G)) := by + have hc : Continuous (Function.uncurry (freshTangent N f G)) := by + unfold freshTangent spinOverlap Function.uncurry; fun_prop + exact hc.measurable + +lemma freshTangentPair_measurable (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) : + Measurable (Function.uncurry (freshTangentPair N f G)) := by + have hc : Continuous (Function.uncurry (freshTangentPair N f G)) := by + unfold freshTangentPair spinOverlap Function.uncurry; fun_prop + exact hc.measurable + +lemma freshTangentTriple_measurable (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) : + Measurable (Function.uncurry (freshTangentTriple N f G)) := by + have hc : Continuous (Function.uncurry (freshTangentTriple N f G)) := by + unfold freshTangentTriple spinOverlap Function.uncurry; fun_prop + exact hc.measurable + +lemma normalizedSpin_inner_bound {N : ℕ} (x : NormalizedSpin N) (b : Spin N) : + |inner ℝ x.val b|≤‖b‖ := by + have hx : ‖x.val‖=1 := by simp + simpa only [hx,one_mul] using abs_real_inner_le_norm x.val b + +lemma freshTangent_bound (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) (b : Spin N) (x : Fin 2→NormalizedSpin N) : + |freshTangent N f G b x|≤2*‖G‖*‖f.d1‖*‖b‖ := by + have hd : |inner ℝ (x 1).val b-spinOverlap (x 0) (x 1)*inner ℝ (x 0).val b|≤2*‖b‖ := by + apply (abs_sub _ _).trans + rw [abs_mul] + have hm := mul_le_mul (spinOverlap_abs_le (x 0) (x 1)) (normalizedSpin_inner_bound (x 0) b) + (abs_nonneg _) (by norm_num : (0:ℝ)≤1) + linarith [normalizedSpin_inner_bound (x 1) b] + unfold freshTangent + rw [abs_mul,abs_mul] + apply (mul_le_mul (mul_le_mul (G.norm_coe_le_norm _) (f.d1.norm_coe_le_norm _) (abs_nonneg _) (norm_nonneg _)) hd (abs_nonneg _) (by positivity)).trans_eq + ring + +lemma freshTangentPair_bound (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) (b : Spin N) (x : Fin 2→NormalizedSpin N) : + |freshTangentPair N f G b x|≤2*‖G‖*‖f.d1‖^2 := by + have hd : |1-spinOverlap (x 0) (x 1)^2|≤2 := by + apply (abs_sub _ _).trans + have := pow_le_pow_left₀ (abs_nonneg _) (spinOverlap_abs_le (x 0) (x 1)) 2 + simp only [abs_one,abs_pow,one_pow] at this ⊢ + linarith + unfold freshTangentPair + rw [abs_mul,abs_mul,abs_mul] + apply (mul_le_mul (mul_le_mul (mul_le_mul (G.norm_coe_le_norm _) (f.d1.norm_coe_le_norm _) (abs_nonneg _) (norm_nonneg _)) + (f.d1.norm_coe_le_norm _) (abs_nonneg _) (by positivity)) hd (abs_nonneg _) (by positivity)).trans_eq + ring + +lemma freshTangentTriple_bound (N : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) (b : Spin N) (x : Fin 3→NormalizedSpin N) : + |freshTangentTriple N f G b x|≤2*‖G‖*‖f.d1‖^2 := by + have hd : |spinOverlap (x 2) (x 0)-spinOverlap (x 1) (x 2)*spinOverlap (x 1) (x 0)|≤2 := by + apply (abs_sub _ _).trans + rw [abs_mul] + have hm := mul_le_mul (spinOverlap_abs_le (x 1) (x 2)) (spinOverlap_abs_le (x 1) (x 0)) + (abs_nonneg _) (by norm_num : (0:ℝ)≤1) + linarith [spinOverlap_abs_le (x 2) (x 0)] + unfold freshTangentTriple + rw [abs_mul,abs_mul,abs_mul] + apply (mul_le_mul (mul_le_mul (mul_le_mul (G.norm_coe_le_norm _) (f.d1.norm_coe_le_norm _) (abs_nonneg _) (norm_nonneg _)) + (f.d1.norm_coe_le_norm _) (abs_nonneg _) (by positivity)) hd (abs_nonneg _) (by positivity)).trans_eq + ring + +lemma bulkFreshReplicaMean_integrable (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (F : Spin (n+1)→(Fin r→NormalizedSpin (n+1))→ℝ) + (hF : Measurable (Function.uncurry F)) {D : Spin (n+1)→ℝ} + (hD : Integrable D (stdGaussian (Spin (n+1)))) (hD0 : ∀ b,0≤D b) (hb : ∀ b x,|F b x|≤D b) : + Integrable (fun p : BulkDisorder (n+1) M×Spin (n+1) => + gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => bulkHamiltonian (n+1) M f v p.1.1 p.1.2 x+f (inner ℝ x.val p.2)) r (F p.2)) + ((bulkDisorderLaw (n+1) M).prod (stdGaussian (Spin (n+1)))) := by + apply replicaMean_param_integrable_dominated _ _ r _ _ (hD.comp_snd _) (fun p => hD0 p.2) (fun p x => hb p.2 x) + · exact ((bulkHamiltonian_continuous (n+1) M f v).measurable.comp (measurable_fst.fst.prodMk measurable_snd)).add + (f.continuous.measurable.comp (measurable_snd.subtype_val.inner measurable_fst.snd)) + · exact hF.comp (measurable_fst.snd.prodMk measurable_snd) + +lemma bulkReplicaMean_last_integral (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (F : Spin (n+1)→(Fin r→NormalizedSpin (n+1))→ℝ) + (hF : Measurable (Function.uncurry F)) {D : Spin (n+1)→ℝ} + (hD : Integrable D (stdGaussian (Spin (n+1)))) (hD0 : ∀ b,0≤D b) (hb : ∀ b x,|F b x|≤D b) : + bulkReplicaMean n (M+1) f v r (fun a x => F (bulkSeparateLast (n+1) M a).2 x)= + ∫ a : BulkDisorder (n+1) M, ∫ b : Spin (n+1), + gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => bulkHamiltonian (n+1) M f v a.1 a.2 x+f (inner ℝ x.val b)) r (F b) + ∂stdGaussian (Spin (n+1)) ∂bulkDisorderLaw (n+1) M := by + let H := fun p : BulkDisorder (n+1) M×Spin (n+1) => + fun x : NormalizedSpin (n+1) => bulkHamiltonian (n+1) M f v p.1.1 p.1.2 x+f (inner ℝ x.val p.2) + have hH : Measurable (Function.uncurry H) := by + exact ((bulkHamiltonian_continuous (n+1) M f v).measurable.comp (measurable_fst.fst.prodMk measurable_snd)).add + (f.continuous.measurable.comp (measurable_snd.subtype_val.inner measurable_fst.snd)) + have hFm : Measurable (Function.uncurry (fun p : BulkDisorder (n+1) M×Spin (n+1) => F p.2)) := + hF.comp (measurable_fst.snd.prodMk measurable_snd) + have hm := measurable_replicaMean_param (unitSphereLaw (n+1)) hH hFm + have hi := bulkFreshReplicaMean_integrable n M r f v F hF hD hD0 hb + have he := integral_map (μ := bulkDisorderLaw (n+1) (M+1)) (bulkSeparateLast_preserving (n+1) M).measurable.aemeasurable hm.aestronglyMeasurable + rw [(bulkSeparateLast_preserving (n+1) M).map_eq] at he + change (∫ a : BulkDisorder (n+1) (M+1), + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) (M+1) f v a.1 a.2) r + (F (bulkSeparateLast (n+1) M a).2) ∂bulkDisorderLaw (n+1) (M+1))=_ + calc + _ = ∫ a : BulkDisorder (n+1) (M+1), + gibbsReplicaMean (unitSphereLaw (n+1)) (H (bulkSeparateLast (n+1) M a)) r + (F (bulkSeparateLast (n+1) M a).2) ∂bulkDisorderLaw (n+1) (M+1) := by + apply integral_congr_ae + exact ae_of_all _ fun a => by + have hham : bulkHamiltonian (n+1) (M+1) f v a.1 a.2 = H (bulkSeparateLast (n+1) M a) := by + funext x + exact bulkHamiltonian_last (n+1) M f v a x + exact congrArg (fun h => gibbsReplicaMean (unitSphereLaw (n+1)) h r (F (bulkSeparateLast (n+1) M a).2)) hham + _ = ∫ p : BulkDisorder (n+1) M×Spin (n+1), + gibbsReplicaMean (unitSphereLaw (n+1)) (H p) r (F p.2) + ∂(bulkDisorderLaw (n+1) M).prod (stdGaussian (Spin (n+1))) := he.symm + _ = _ := integral_prod _ hi + +lemma fresh_tangent_ibp (n : ℕ) (f : Jet3) (G : ℝ→ᵇℝ) + {h : NormalizedSpin (n+1)→ℝ} (hh : Measurable h) {A : ℝ} (hA : 0≤A) (hb : ∀ x,|h x|≤A) : + (∫ b : Spin (n+1), gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => h x+f.f (inner ℝ x.val b)) 2 (freshTangent (n+1) f G b) ∂stdGaussian (Spin (n+1))) = + ∫ b : Spin (n+1), gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => h x+f.f (inner ℝ x.val b)) 2 (freshTangentPair (n+1) f G b)- + 2*gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => h x+f.f (inner ℝ x.val b)) 3 (freshTangentTriple (n+1) f G b) ∂stdGaussian (Spin (n+1)) := by + have hH : Measurable (Function.uncurry (fun b : Spin (n+1) => fun x : NormalizedSpin (n+1) => h x+f.f (inner ℝ x.val b))) := + (hh.comp measurable_snd).add (f.f.measurable.comp (measurable_snd.subtype_val.inner measurable_fst)) + have h1 := measurable_replicaMean_param (unitSphereLaw (n+1)) hH (freshTangent_measurable (n+1) f G) + have h2 := measurable_replicaMean_param (unitSphereLaw (n+1)) hH (freshTangentPair_measurable (n+1) f G) + have h3 := measurable_replicaMean_param (unitSphereLaw (n+1)) hH (freshTangentTriple_measurable (n+1) f G) + have h23 : AEStronglyMeasurable (fun b : Spin (n+1) => + gibbsReplicaMean (unitSphereLaw (n+1)) (fun x => h x+f.f (inner ℝ x.val b)) 2 (freshTangentPair (n+1) f G b)- + 2*gibbsReplicaMean (unitSphereLaw (n+1)) (fun x => h x+f.f (inner ℝ x.val b)) 3 (freshTangentTriple (n+1) f G b)) + (Measure.map (WithLp.toLp 2) (Measure.pi fun _ : Fin (n+1) => gaussianReal 0 1)) := + (h2.sub (h3.const_mul 2)).aestronglyMeasurable + rw [←map_pi_eq_stdGaussian,integral_map (PiLp.continuous_toLp 2 _).measurable.aemeasurable h1.aestronglyMeasurable, + integral_map (PiLp.continuous_toLp 2 _).measurable.aemeasurable h23] + have he := spherical_pattern_direction_ibp (unitSphereLaw (n+1)) f G hh hA hb + unfold freshTangent freshTangentPair freshTangentTriple + convert he using 1 <;> + simp only [gaussianField,EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial,mul_comm] + +lemma bulk_tangent_last_ibp (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) : + bulkReplicaMean n (M+1) f.f v 2 (fun a => freshTangent (n+1) f G (bulkSeparateLast (n+1) M a).2) = + bulkReplicaMean n (M+1) f.f v 2 (fun a => freshTangentPair (n+1) f G (bulkSeparateLast (n+1) M a).2)- + 2*bulkReplicaMean n (M+1) f.f v 3 (fun a => freshTangentTriple (n+1) f G (bulkSeparateLast (n+1) M a).2) := by + have hD : Integrable (fun b : Spin (n+1) => 2*‖G‖*‖f.d1‖*‖b‖) (stdGaussian (Spin (n+1))) := + ((((IsGaussian.memLp_id (stdGaussian (Spin (n+1))) 2 (by simp)).norm).integrable (by norm_num))).const_mul _ + have hC : (0:ℝ)≤2*‖G‖*‖f.d1‖^2 := by positivity + rw [bulkReplicaMean_last_integral n M 2 f.f v _ (freshTangent_measurable _ _ _) hD (fun _ => by positivity) (freshTangent_bound _ _ _), + bulkReplicaMean_last_integral n M 2 f.f v _ (freshTangentPair_measurable _ _ _) (integrable_const _) (fun _ => hC) (freshTangentPair_bound _ _ _), + bulkReplicaMean_last_integral n M 3 f.f v _ (freshTangentTriple_measurable _ _ _) (integrable_const _) (fun _ => hC) (freshTangentTriple_bound _ _ _)] + let P := fun p : BulkDisorder (n+1) M×Spin (n+1) => gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => bulkHamiltonian (n+1) M f.f v p.1.1 p.1.2 x+f.f (inner ℝ x.val p.2)) 2 + (freshTangentPair (n+1) f G p.2) + let T := fun p : BulkDisorder (n+1) M×Spin (n+1) => gibbsReplicaMean (unitSphereLaw (n+1)) + (fun x => bulkHamiltonian (n+1) M f.f v p.1.1 p.1.2 x+f.f (inner ℝ x.val p.2)) 3 + (freshTangentTriple (n+1) f G p.2) + have hiP : Integrable P ((bulkDisorderLaw (n+1) M).prod (stdGaussian (Spin (n+1)))) := + bulkFreshReplicaMean_integrable n M 2 f.f v _ (freshTangentPair_measurable _ _ _) + (integrable_const _) (fun _ => hC) (freshTangentPair_bound _ _ _) + have hiT : Integrable T ((bulkDisorderLaw (n+1) M).prod (stdGaussian (Spin (n+1)))) := + bulkFreshReplicaMean_integrable n M 3 f.f v _ (freshTangentTriple_measurable _ _ _) + (integrable_const _) (fun _ => hC) (freshTangentTriple_bound _ _ _) + calc + _ = ∫ a : BulkDisorder (n+1) M, ∫ b : Spin (n+1), P (a,b)-2*T (a,b) + ∂stdGaussian (Spin (n+1)) ∂bulkDisorderLaw (n+1) M := by + apply integral_congr_ae + exact ae_of_all _ fun a => fresh_tangent_ibp n f G + (bulkHamiltonian_section_measurable _ _ _ _ a) + (show 0≤M*‖f.f‖+bulkFeatureBound (n+1) v*‖a.2‖ by unfold bulkFeatureBound; positivity) + (bulkHamiltonian_bound (n+1) M f.f v a) + _ = _ := by + have hiPT : Integrable (fun p => P p-2*T p) ((bulkDisorderLaw (n+1) M).prod (stdGaussian (Spin (n+1)))) := + hiP.sub (hiT.const_mul 2) + rw [←integral_prod _ hiPT,integral_sub hiP (hiT.const_mul 2),integral_const_mul, + integral_prod _ hiP,integral_prod _ hiT] + +lemma bulkReplicaMean_row_eq_last (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (j : Fin (M+1)) + (F : Spin (n+1)→(Fin r→NormalizedSpin (n+1))→ℝ) (hF : Measurable (Function.uncurry F)) : + bulkReplicaMean n (M+1) f v r (fun a => F (WithLp.toLp 2 (a.1 j))) = + bulkReplicaMean n (M+1) f v r (fun a => F (bulkSeparateLast (n+1) M a).2) := by + classical + have hm : Measurable (Function.uncurry (fun a : BulkDisorder (n+1) (M+1) => F (bulkSeparateLast (n+1) M a).2)) := + hF.comp (((bulkSeparateLast_preserving (n+1) M).measurable.snd.comp measurable_fst).prodMk measurable_snd) + have he := bulkReplicaMean_permute n (M+1) f v r (Equiv.swap j (Fin.last M)) + (fun a => F (bulkSeparateLast (n+1) M a).2) hm + simpa only [bulkSeparateLast,bulkPermutePatterns,Equiv.swap_apply_right] using he + +lemma bulk_tangent_row_ibp (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) (j : Fin (M+1)) : + bulkReplicaMean n (M+1) f.f v 2 (bulkTangentPattern f G j) = + bulkReplicaMean n (M+1) f.f v 2 (fun a => freshTangentPair (n+1) f G (WithLp.toLp 2 (a.1 j)))- + 2*bulkReplicaMean n (M+1) f.f v 3 (fun a => freshTangentTriple (n+1) f G (WithLp.toLp 2 (a.1 j))) := by + have he : (bulkTangentPattern (N:=n+1) f G j)= + (fun a : BulkDisorder (n+1) (M+1) => freshTangent (n+1) f G (WithLp.toLp 2 (a.1 j))) := by + funext a x + simp only [bulkTangentPattern,bulkPatternFields,freshTangent, + EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial] + rw [he,bulkReplicaMean_row_eq_last _ _ _ _ _ _ _ (freshTangent_measurable _ _ _), + bulkReplicaMean_row_eq_last _ _ _ _ _ _ _ (freshTangentPair_measurable _ _ _), + bulkReplicaMean_row_eq_last _ _ _ _ _ _ _ (freshTangentTriple_measurable _ _ _)] + exact bulk_tangent_last_ibp n M f v G + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkReplicaStein.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkReplicaStein.lean new file mode 100644 index 0000000000000000000000000000000000000000..4de5b5cbe41b5df51df78b3c2cb4e120cecc4235 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkReplicaStein.lean @@ -0,0 +1,221 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkParameterDeviation +import OAI.Probability.Perceptron.Interpolation.FiniteVectorReplica + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def bulkMoment (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) (G : (Fin r→NormalizedSpin (n+1))→ℝ) : ℝ := + ∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r G ∂bulkDisorderLaw (n+1) M + +lemma bulkReplicaMean_integrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) : + Integrable (fun a : BulkDisorder (n+1) M => gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) r G) (bulkDisorderLaw (n+1) M) := + kernel_replicaMean_bounded_integrable (bulkSpinKernel n M) _ + (H := fun a x => bulkHamiltonian (n+1) M f v a.1 a.2 x) (G := fun _ x => G x) + (bulkHamiltonian_continuous _ _ _ _).measurable (hG.comp measurable_snd) hB (fun _ x => hGB x) + +lemma bulkReplicaY_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) : + Measurable (fun a : BulkDisorder (n+1) M => gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) r (fun x => bulkY (n+1) p a.2 (x j)*G x)) := by + have hH : Measurable (Function.uncurry (fun (a : BulkDisorder (n+1) M) x => + bulkHamiltonian (n+1) M f v a.1 a.2 x)) := (bulkHamiltonian_continuous _ _ _ _).measurable + have hY : Measurable (Function.uncurry (fun (a : BulkDisorder (n+1) M) (x : Fin r→NormalizedSpin (n+1)) => + bulkY (n+1) p a.2 (x j)*G x)) := + (((bulkY_joint_measurable (n+1) M p).comp + (measurable_fst.prodMk ((measurable_pi_apply j).comp measurable_snd))).mul (hG.comp measurable_snd)) + exact measurable_replicaMean_param (unitSphereLaw (n+1)) hH hY + +lemma bulkReplicaY_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) + (a : BulkDisorder (n+1) M) : + |gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r + (fun x => bulkY (n+1) p a.2 (x j)*G x)|≤‖a.2‖*B := by + apply tiltMean_bound_general _ + (replicaPotential_measurable (bulkHamiltonian_section_measurable _ _ _ _ a) r) + (((bulkY_measurable (n+1) p).of_uncurry_left.comp (measurable_pi_apply j)).mul hG) + (mul_nonneg (norm_nonneg _) hB) + intro x + change |bulkY (n+1) p a.2 (x j)*G x|≤_ + rw [abs_mul] + exact mul_le_mul (bulkY_bound _ _ _ _) (hGB x) (abs_nonneg _) (norm_nonneg _) + +lemma bulkReplicaY_integrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) : + Integrable (fun a : BulkDisorder (n+1) M => gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) r (fun x => bulkY (n+1) p a.2 (x j)*G x)) + (bulkDisorderLaw (n+1) M) := by + have hi : Integrable (fun a : BulkDisorder (n+1) M => ‖a.2‖) (bulkDisorderLaw (n+1) M) := + (((IsGaussian.memLp_id (stdGaussian (BulkMark (n+1))) 2 (by simp)).norm).integrable (by norm_num)).comp_snd _ + apply (hi.mul_const B).mono' (bulkReplicaY_measurable n M f v p r j hG).aestronglyMeasurable + exact ae_of_all _ fun a => by + rw [Real.norm_eq_abs] + exact bulkReplicaY_bound n M f v p r j hG hB hGB a + +lemma bulkPowerPair_measurable (N r p : ℕ) (j l : Fin r) : + Measurable (fun x : Fin r→NormalizedSpin N => spinOverlap (x j) (x l)^p) := + (((measurable_pi_apply j).subtype_val).inner ((measurable_pi_apply l).subtype_val)).pow_const p + +lemma bulkPowerPair_bound (N r p : ℕ) (j l : Fin r) (x : Fin r→NormalizedSpin N) : + |spinOverlap (x j) (x l)^p|≤1 := by + rw [abs_pow] + exact (pow_le_pow_left₀ (abs_nonneg _) (spinOverlap_abs_le _ _) p).trans_eq (one_pow p) + +lemma bulkReplicaSum_bound (N r p : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin N)→ℝ} {B : ℝ} (hGB : ∀ x, |G x|≤B) (x : Fin r→NormalizedSpin N) : + |G x*∑ l, spinOverlap (x j) (x l)^p|≤B*r := by + rw [abs_mul] + apply mul_le_mul (hGB x) _ (abs_nonneg _) (le_trans (abs_nonneg (G x)) (hGB x)) + calc + _ ≤ ∑ l, |spinOverlap (x j) (x l)^p| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _ : Fin r, (1:ℝ) := Finset.sum_le_sum fun l _ => bulkPowerPair_bound N r p j l x + _ = _ := by simp + +lemma bulk_fixed_replica_ibp (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (r : ℕ) (j : Fin r) + {G : (Fin r→NormalizedSpin (n+1))→ℝ} (hG : Measurable G) {B : ℝ} (hB : 0≤B) (hGB : ∀ x, |G x|≤B) + (a : Fin M→Fin (n+1)→ℝ) : + (∫ g, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) r + (fun x => bulkY (n+1) p g (x j)*G x) ∂stdGaussian (BulkMark (n+1))) = + bulkAmplitude (n+1) v p*( + (∫ g, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) r + (fun x => G x*∑ l, spinOverlap (x j) (x l)^(p.val+1)) ∂stdGaussian (BulkMark (n+1)))- + r*(∫ g, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) (r+1) + (fun x => G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^(p.val+1)) ∂stdGaussian (BulkMark (n+1)))) := by + have he := euclideanGaussian_replica_ibp (unitSphereLaw (n+1)) r j + (((normalizedPatternEnergy_continuous (n+1) M f).comp (continuous_const.prodMk continuous_id)).measurable) + (bulkFeature_continuous (n+1) v).measurable (bulkDirection_continuous (n+1) p).measurable hG + (normalizedPatternEnergy_bound (n+1) M f a) + (fun x => le_of_eq (bulkFeature_norm_sq (n+1) v x)) + (fun x => by rw [bulkDirection_norm]; norm_num : ∀ x, ‖bulkDirection (n+1) p x‖^2≤(1:ℝ)) hB hGB + have hUm : Measurable (fun x : Fin r→NormalizedSpin (n+1) => G x*∑ l, spinOverlap (x j) (x l)^(p.val+1)) := + hG.mul (Finset.measurable_sum _ fun l _ => bulkPowerPair_measurable _ _ _ _ _) + have hWm : Measurable (fun x : Fin (r+1)→NormalizedSpin (n+1) => + G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^(p.val+1)) := + (hG.comp (Measurable.of_eval (fun replica => measurable_pi_apply replica.succ))).mul (bulkPowerPair_measurable _ _ _ _ _) + + have hUIf := kernel_replicaMean_bounded_integrable (Kernel.const (BulkMark (n+1)) (unitSphereLaw (n+1))) + (stdGaussian (BulkMark (n+1))) (H:=fun g x => bulkHamiltonian (n+1) M f v a g x) + (G:=fun _ x => G x*∑ l,spinOverlap (x j) (x l)^(p.val+1)) + (((bulkHamiltonian_continuous _ _ _ _).comp + ((continuous_const.prodMk continuous_fst).prodMk continuous_snd)).measurable) + (hUm.comp measurable_snd) (mul_nonneg hB (Nat.cast_nonneg r)) + (fun _ x => bulkReplicaSum_bound (n+1) r (p.val+1) j hGB x) + have hWIf := kernel_replicaMean_bounded_integrable (Kernel.const (BulkMark (n+1)) (unitSphereLaw (n+1))) + (stdGaussian (BulkMark (n+1))) (H:=fun g x => bulkHamiltonian (n+1) M f v a g x) + (G:=fun _ x => G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^(p.val+1)) + (((bulkHamiltonian_continuous _ _ _ _).comp + ((continuous_const.prodMk continuous_fst).prodMk continuous_snd)).measurable) + (hWm.comp measurable_snd) hB (fun _ x => by + rw [abs_mul] + exact (mul_le_mul (hGB _) (bulkPowerPair_bound _ _ _ _ _ x) (abs_nonneg _) hB).trans_eq (mul_one B)) + simp only [bulkFeature_direction_inner,←Finset.mul_sum] at he + have heU : (fun x : Fin r→NormalizedSpin (n+1) => G x*(bulkAmplitude (n+1) v p*∑ l, spinOverlap (x j) (x l)^(p.val+1))) = + (fun x => bulkAmplitude (n+1) v p*(G x*∑ l, spinOverlap (x j) (x l)^(p.val+1))) := by funext x; ring + have heW : (fun x : Fin (r+1)→NormalizedSpin (n+1) => G (fun l => x l.succ)*(bulkAmplitude (n+1) v p*spinOverlap (x j.succ) (x 0)^(p.val+1))) = + (fun x => bulkAmplitude (n+1) v p*(G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^(p.val+1))) := by funext x; ring + rw [heU,heW] at he + simp only [gibbsReplicaMean,tiltMean_const_mul_general] at he + change (∫ g, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) r + (fun x => bulkY (n+1) p g (x j)*G x) ∂stdGaussian (BulkMark (n+1))) = + ∫ g, bulkAmplitude (n+1) v p*gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) r + (fun x => G x*∑ l,spinOverlap (x j) (x l)^(p.val+1)) - + r*(bulkAmplitude (n+1) v p*gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) (r+1) + (fun x => G (fun l => x l.succ)*spinOverlap (x j.succ) (x 0)^(p.val+1))) ∂stdGaussian (BulkMark (n+1)) at he + simp only [Kernel.const_apply] at hUIf hWIf + rw [integral_sub (hUIf.const_mul _) ((hWIf.const_mul _).const_mul _),integral_const_mul,integral_const_mul,integral_const_mul] at he + rw [he] + ring + + +lemma bulk_rate_identity {x θ C : ℝ} (hx : 0 bulkDeviationRate A f p (n+1:ℕ)) atTop (𝓝 0) := by + have hN : Tendsto (fun n : ℕ => (n+1:ℕ) : ℕ→ℝ) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have h3 := (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<3/8)).comp hN + have h1 := (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1/8)).comp hN + unfold bulkDeviationRate + convert (h3.const_mul (Real.sqrt 6)).add (h1.const_mul (24*(2:ℝ)^(-((p+1:ℕ):ℤ))+ + 4*Real.sqrt (Real.pi^2/8*3^2+A*(2*‖f‖)^2)/(2:ℝ)^(-((p+1:ℕ):ℤ)))) using 1 <;> norm_num + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkRestorationLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkRestorationLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..8e373698f3d24d75e3aa7745fc1168d53c4fae25 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkRestorationLimit.lean @@ -0,0 +1,254 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkMarkedMoments +import OAI.Probability.Perceptron.Cavity.BulkRestoredObservables + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction + +def twoFreshDisorderLaw (N M : ℕ) : Measure (TwoFreshDisorder N M) := + (bulkDisorderLaw N M).prod ((stdGaussian (EuclideanSpace ℝ (Fin N))).prod + (stdGaussian (EuclideanSpace ℝ (Fin N)))) +instance (N M : ℕ) : IsProbabilityMeasure (twoFreshDisorderLaw N M) := by + unfold twoFreshDisorderLaw + infer_instance + +def bulkFreshCompactDenominator (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (p : TwoFreshDisorder (n+1) M) : Icc (Real.exp (-(2*‖f‖))) (Real.exp (2*‖f‖)) := + ⟨bulkFreshDenominator n M f v p,bulkFreshDenominator_mem n M f v p⟩ +lemma bulkFreshCompactDenominator_measurable (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) : + Measurable (bulkFreshCompactDenominator n M f v) := + (bulkFreshDenominator_measurable n M f v).subtype_mk + +lemma bulkFreshNumerator_integrable (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (P : Measure (TwoFreshDisorder (n+1) M)) [IsFiniteMeasure P] : + Integrable (bulkFreshNumerator n M r f v F Ψ Φ) P := by + apply Integrable.of_bound (bulkFreshNumerator_measurable n M r f v F Ψ Φ).aestronglyMeasurable + (‖F‖*‖restorationMarkTest r f Ψ 0‖*‖restorationMarkTest r f Φ 0‖) + exact ae_of_all _ fun p => by + simpa only [Real.norm_eq_abs] using bulkFreshNumerator_bound n M r f v F Ψ Φ p + +lemma bulkFresh_weighted_integrable (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (k : ℕ) : + Integrable (fun p => bulkFreshNumerator n M r f v F Ψ Φ p * bulkFreshDenominator n M f v p^k) + (twoFreshDisorderLaw (n+1) M) := by + let T : C(Icc (Real.exp (-(2*‖f‖))) (Real.exp (2*‖f‖)),ℝ) := + ⟨fun z => z.val^k,continuous_subtype_val.pow k⟩ + exact weighted_compact_integrable (twoFreshDisorderLaw (n+1) M) + (bulkFreshNumerator n M r f v F Ψ Φ) (bulkFreshNumerator_measurable n M r f v F Ψ Φ) + (bulkFreshCompactDenominator n M f v) (bulkFreshCompactDenominator_measurable n M f v) + _ (by positivity) (bulkFreshNumerator_bound n M r f v F Ψ Φ) T + +lemma bulkFresh_annealed_polynomial (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) (k : ℕ) : + (∫ p, bulkFreshNumerator n M r f v F Ψ Φ p * bulkFreshDenominator n M f v p^k + ∂twoFreshDisorderLaw (n+1) M) = + ∫ Q, (restorationBlockTest r F k * freshMarkedCompactBlockKernel (restorationMarkTest r f Ψ k) * + freshMarkedCompactBlockKernel (restorationMarkTest r f Φ k)) (compactBlock (r+k) Q) + ∂bulkGibbsArrayLaw n M f v := by + rw [twoFreshDisorderLaw,integral_prod _ (bulkFresh_weighted_integrable n M r f v F Ψ Φ k)] + simp_rw [mul_comm (bulkFreshNumerator n M r f v F Ψ Φ _),bulkFresh_polynomial_moment] + exact bulk_twoFresh_block n M (r+k) f v (restorationBlockTest r F k) + (restorationMarkTest r f Ψ k) (restorationMarkTest r f Φ k) + +lemma bulkFresh_moment_tendsto (M : ℕ → ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℕ → ℝ) (s : ℕ → ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hν : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) f (v (s n))) atTop (𝓝 ν)) + (r : ℕ) (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) (k : ℕ) : + Tendsto (fun n => ∫ p, bulkFreshNumerator (s n) (M (s n)) r f (v (s n)) F Ψ Φ p * + bulkFreshDenominator (s n) (M (s n)) f (v (s n)) p^k ∂twoFreshDisorderLaw (s n+1) (M (s n))) + atTop (𝓝 (∫ Q, (restorationBlockTest r F k * freshMarkedCompactBlockKernel (restorationMarkTest r f Ψ k) * + freshMarkedCompactBlockKernel (restorationMarkTest r f Φ k)) (compactBlock (r+k) Q) ∂ν)) := by + simp_rw [bulkFresh_annealed_polynomial] + exact (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + ((restorationBlockTest r F k * freshMarkedCompactBlockKernel (restorationMarkTest r f Ψ k) * + freshMarkedCompactBlockKernel (restorationMarkTest r f Φ k)).compContinuous + ⟨compactBlock (r+k), compactBlock_continuous (r+k)⟩)).continuousAt.tendsto.comp hν + +lemma bulkFresh_exact_restoration (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (a : BulkDisorder (n+1) (M+2)) : + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) (M+2) f v a.1 a.2) r + (bulkMarkedTest (n+1) r F Ψ Φ (bulkSeparateTwo (n+1) M a).2) = + bulkFreshNumerator n M r f v F Ψ Φ (bulkSeparateTwo (n+1) M a) / + bulkFreshDenominator n M f v (bulkSeparateTwo (n+1) M a)^r := by + rw [bulk_replica_restore_two] + congr 1 + apply congrArg (gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v (bulkSeparateTwo (n+1) M a).1.1 (bulkSeparateTwo (n+1) M a).1.2) r) + funext x + have h := restorationReplicaTest_twoMarks f F Ψ Φ (bulkSeparateTwo (n+1) M a).2.1 + (bulkSeparateTwo (n+1) M a).2.2 0 x + simp only [restorationReplicaTest,restorationBlockTest,mul_assoc,bulkMarkedTest] at h ⊢ + convert h using 1 + +lemma bulkFresh_annealed_restoration (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + (∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) (M+2) f v a.1 a.2) r + (bulkMarkedTest (n+1) r F Ψ Φ (bulkSeparateTwo (n+1) M a).2) ∂bulkDisorderLaw (n+1) (M+2)) = + ∫ p, bulkFreshNumerator n M r f v F Ψ Φ p / bulkFreshDenominator n M f v p^r + ∂twoFreshDisorderLaw (n+1) M := by + simp_rw [bulkFresh_exact_restoration] + have hp := bulkSeparateTwo_preserving (n+1) M + let g : TwoFreshDisorder (n+1) M → ℝ := fun p => + bulkFreshNumerator n M r f v F Ψ Φ p / bulkFreshDenominator n M f v p^r + have hg : AEStronglyMeasurable g (twoFreshDisorderLaw (n+1) M) := + (((bulkFreshNumerator_measurable n M r f v F Ψ Φ).div + ((bulkFreshDenominator_measurable n M f v).pow_const r)).aestronglyMeasurable) + change (∫ a, g (bulkSeparateTwo (n+1) M a) ∂bulkDisorderLaw (n+1) (M+2)) = + ∫ p, g p ∂twoFreshDisorderLaw (n+1) M + have hg' : AEStronglyMeasurable g + ((bulkDisorderLaw (n+1) (M+2)).map (bulkSeparateTwo (n+1) M)) := by + rw [hp.map_eq] + exact hg + have he := integral_map hp.measurable.aemeasurable hg' + exact he.symm.trans (by rw [hp.map_eq]; rfl) + +lemma bulkReplicaMean_sum (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + {ι : Type*} (s : Finset ι) + (G : ι→BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hG : ∀ i∈s,Measurable (Function.uncurry (G i))) + (D : ι→ℝ) (hD : ∀ i∈s,0≤D i) (hb : ∀ i∈s,∀ a x,|G i a x|≤D i) : + bulkReplicaMean n M f v r (fun a x => ∑ i∈s,G i a x)= + ∑ i∈s,bulkReplicaMean n M f v r (G i) := by + unfold bulkReplicaMean + have hH : Measurable (Function.uncurry (fun a : BulkDisorder (n+1) M => bulkHamiltonian (n+1) M f v a.1 a.2)) := + (bulkHamiltonian_continuous (n+1) M f v).measurable + have he (a : BulkDisorder (n+1) M) : + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r + (fun x => ∑ i∈s,G i a x)= + ∑ i∈s,gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r (G i a) := + gibbsReplicaMean_sum_of_integrable (unitSphereLaw (n+1)) s + (show Measurable (fun x => bulkHamiltonian (n+1) M f v a.1 a.2 x) from hH.of_uncurry_left) + (bulkHamiltonian_exp_integrable n M f v a) (fun i hi => (hG i hi).of_uncurry_left) + (fun i hi x => hb i hi a x) + simp_rw [he] + exact integral_finsetSum s fun i hi => kernel_replicaMean_bounded_integrable (bulkSpinKernel n M) + (bulkDisorderLaw (n+1) M) hH (hG i hi) (hD i hi) (hb i hi) + +lemma bulkReplicaMean_const_mul (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) (c : ℝ) : + bulkReplicaMean n M f v r (fun a x => c*G a x)=c*bulkReplicaMean n M f v r G := by + unfold bulkReplicaMean + simp_rw [replicaMean_const_mul] + exact integral_const_mul _ _ + +lemma bulkReplicaMean_bound (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hG : Measurable (Function.uncurry G)) {C : ℝ} (_hC : 0≤C) (hb : ∀ a x,|G a x|≤C) : + |bulkReplicaMean n M f v r G|≤C := by + have hb' : ∀ᵐ a ∂bulkDisorderLaw (n+1) M, + ‖gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) r (G a)‖≤C := by + refine ae_of_all _ fun a => ?_ + rw [Real.norm_eq_abs] + exact gibbsReplicaMean_bound_of_integrable (unitSphereLaw (n+1)) + ((bulkHamiltonian_continuous _ _ _ _).measurable.comp (measurable_const.prodMk measurable_id)) + hG.of_uncurry_left (bulkHamiltonian_exp_integrable n M f v a) (hb a) + simpa [bulkReplicaMean] using + norm_integral_le_of_norm_le_const hb' + +lemma bulk_two_row_exchange (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + (G : (Fin r→NormalizedSpin (n+1))→ℝ) (hG : Measurable G) + (T U : (Fin r→ℝ)→ℝ) (hT : Measurable T) (hU : Measurable U) + (i j k l : Fin M) (hij : i≠j) (hkl : k≠l) : + bulkReplicaMean n M f v r (fun a x => G x*T (bulkPatternFields i a x)*U (bulkPatternFields j a x))= + bulkReplicaMean n M f v r (fun a x => G x*T (bulkPatternFields k a x)*U (bulkPatternFields l a x)) := by + classical + let p : Bool→Fin M := fun b => if b then k else l + let q : Bool→Fin M := fun b => if b then i else j + have hp : Function.Injective p := by + intro b c h + cases b <;> cases c <;> simp_all [p,Ne.symm hkl] + have hq : Function.Injective q := by + intro b c h + cases b <;> cases c <;> simp_all [q,Ne.symm hij] + obtain ⟨e,he⟩ := Equiv.Perm.exists_extending_pair p q hp hq + have hek : e k=i := by simpa [p,q] using he true + have hel : e l=j := by simpa [p,q] using he false + have hm : Measurable (Function.uncurry (fun a x => G x*T (bulkPatternFields k a x)*U (bulkPatternFields l a x))) := + ((hG.comp measurable_snd).mul (hT.comp (bulkPatternFields_measurable _ _ _ _))).mul + (hU.comp (bulkPatternFields_measurable _ _ _ _)) + have ht := bulkReplicaMean_permute n M f v r e _ hm + change bulkReplicaMean n M f v r (fun a x => + G x*T (fun i => ∑ t,a.1 (e k) t*(x i).val t)*U (fun i => ∑ t,a.1 (e l) t*(x i).val t))=_ at ht + rw [hek,hel] at ht + exact ht + +lemma bulk_pattern_sum_first (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (G : (Fin r→NormalizedSpin (n+1))→ℝ) (hG : Measurable G) + (T : (Fin r→ℝ)→ℝ) (hT : Measurable T) + {C D : ℝ} (hC : 0≤C) (hD : 0≤D) (hGC : ∀ x,|G x|≤C) (hTD : ∀ z,|T z|≤D) + (j : Fin M) : + bulkReplicaMean n M f v r (fun a x => G x*∑ i,T (bulkPatternFields i a x))= + M*bulkReplicaMean n M f v r (fun a x => G x*T (bulkPatternFields j a x)) := by + simp_rw [Finset.mul_sum] + rw [bulkReplicaMean_sum n M r f v Finset.univ _ + (fun i _ => (hG.comp measurable_snd).mul (hT.comp (bulkPatternFields_measurable _ _ _ _))) + (fun _=>C*D) (fun _ _ => mul_nonneg hC hD) + (fun _ _ a x => by simpa only [abs_mul] using mul_le_mul (hGC x) (hTD _) (abs_nonneg _) hC)] + simp_rw [bulk_row_exchange n M f v r G hG T hT _ j] + simp + +lemma bulk_pattern_sum_second (n M r : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (G : (Fin r→NormalizedSpin (n+1))→ℝ) (hG : Measurable G) + (T : (Fin r→ℝ)→ℝ) (hT : Measurable T) + {C D : ℝ} (hC : 0≤C) (hD : 0≤D) (hGC : ∀ x,|G x|≤C) (hTD : ∀ z,|T z|≤D) + (k l : Fin M) (hkl : k≠l) : + bulkReplicaMean n M f v r (fun a x => G x*(∑ i,T (bulkPatternFields i a x))^2)= + M*bulkReplicaMean n M f v r (fun a x => G x*(T (bulkPatternFields k a x))^2)+ + M*((M:ℝ)-1)*bulkReplicaMean n M f v r + (fun a x => G x*T (bulkPatternFields k a x)*T (bulkPatternFields l a x)) := by + classical + let W := fun i j (a : BulkDisorder (n+1) M) (x : Fin r→NormalizedSpin (n+1)) => + G x*T (bulkPatternFields i a x)*T (bulkPatternFields j a x) + have hm (i j) : Measurable (Function.uncurry (W i j)) := + ((hG.comp measurable_snd).mul (hT.comp (bulkPatternFields_measurable _ _ _ _))).mul + (hT.comp (bulkPatternFields_measurable _ _ _ _)) + have hb (i j) (a : BulkDisorder (n+1) M) (x : Fin r→NormalizedSpin (n+1)) : + |W i j a x|≤C*D*D := by + dsimp [W]; rw [abs_mul,abs_mul] + exact mul_le_mul (mul_le_mul (hGC x) (hTD _) (abs_nonneg _) hC) + (hTD _) (abs_nonneg _) (mul_nonneg hC hD) + have hf : (fun a x => G x*(∑ i,T (bulkPatternFields i a x))^2)= + (fun a x => ∑ i : Fin M,∑ j : Fin M,W i j a x) := by + funext a x + simp only [sq,Finset.sum_mul,Finset.mul_sum,W,mul_assoc] + rw [Finset.sum_comm] + rw [hf] + rw [bulkReplicaMean_sum n M r f v Finset.univ (fun i a x => ∑ j,W i j a x) + (fun i _ => Finset.measurable_sum _ fun j _ => hm i j) + (fun _ => M*(C*D*D)) (fun _ _ => by positivity) + (fun i _ a x => (Finset.abs_sum_le_sum_abs _ _).trans + ((Finset.sum_le_sum fun j _ => hb i j a x).trans_eq (by simp)))] + simp_rw [bulkReplicaMean_sum n M r f v Finset.univ (W _) + (fun j _ => hm _ j) (fun _=>C*D*D) (fun _ _ => by positivity) (fun j _ a x => hb _ j a x)] + let d := bulkReplicaMean n M f v r (fun a x => G x*(T (bulkPatternFields k a x))^2) + let o := bulkReplicaMean n M f v r (W k l) + have he (i j : Fin M) : bulkReplicaMean n M f v r (W i j)= + o+if i=j then d-o else 0 := by + by_cases hij : i=j + · subst j + rw [ite_eq_left rfl] + have h := bulk_row_exchange n M f v r G hG (fun z => (T z)^2) (hT.pow_const 2) i k + dsimp [W] + simp only [sq,mul_assoc] at h ⊢ + change _=o+(d-o) + rw [show o+(d-o)=d by ring] + simpa only [d,sq,mul_assoc] using h + · rw [ite_eq_right hij,add_zero] + exact bulk_two_row_exchange n M f v r G hG T T hT hT i j k l hij hkl + simp_rw [he] + simp only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul, + Finset.sum_ite_eq,Finset.mem_univ,ite_true] + dsimp [d,o,W] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkRestoredObservables.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkRestoredObservables.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a1880358de8246e78c2d8573083d697276327af --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkRestoredObservables.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkFreshRestore +import OAI.Probability.Perceptron.Interpolation.GaussianReplicaFubini +import OAI.Probability.Perceptron.Interpolation.RestorationReplicaBlocks + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev TwoFreshDisorder (N M : ℕ) := BulkDisorder N M × + (EuclideanSpace ℝ (Fin N) × EuclideanSpace ℝ (Fin N)) + +def bulkMarkedTest (N r : ℕ) (F : CompactBlock CompactOverlap r →ᵇ ℝ) + (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (z : EuclideanSpace ℝ (Fin N) × EuclideanSpace ℝ (Fin N)) + (x : Fin r → NormalizedSpin N) : ℝ := + F (fun i j => bulkOverlap (x i) (x j))* + Ψ (gaussianRows (fun i => (x i).val) z.1)*Φ (gaussianRows (fun i => (x i).val) z.2) + +lemma bulkMarkedTest_continuous (N r : ℕ) (F : CompactBlock CompactOverlap r →ᵇ ℝ) + (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + Continuous (Function.uncurry (bulkMarkedTest N r F Ψ Φ)) := by + have hF : Continuous (fun x : Fin r → NormalizedSpin N => F (fun i j => bulkOverlap (x i) (x j))) := by + apply F.continuous.comp + unfold bulkOverlap spinOverlap + fun_prop + have hv : Continuous (fun x : NormalizedSpin N => x.val) := continuous_subtype_val + have hg : Continuous (fun p : EuclideanSpace ℝ (Fin N) × (Fin r → NormalizedSpin N) => + gaussianRows (fun i => (p.2 i).val) p.1) := + gaussianRows_joint_continuous hv + have hp₁ : Continuous (fun p : (EuclideanSpace ℝ (Fin N) × EuclideanSpace ℝ (Fin N)) × + (Fin r → NormalizedSpin N) => (p.1.1,p.2)) := + continuous_fst.fst.prodMk continuous_snd + have hp₂ : Continuous (fun p : (EuclideanSpace ℝ (Fin N) × EuclideanSpace ℝ (Fin N)) × + (Fin r → NormalizedSpin N) => (p.1.2,p.2)) := + continuous_fst.snd.prodMk continuous_snd + have h₁ := Ψ.continuous.comp (hg.comp hp₁) + have h₂ := Φ.continuous.comp (hg.comp hp₂) + exact ((hF.comp continuous_snd).mul h₁).mul h₂ + +lemma bulkMarkedTest_bound (N r : ℕ) (F : CompactBlock CompactOverlap r →ᵇ ℝ) + (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (z : EuclideanSpace ℝ (Fin N) × EuclideanSpace ℝ (Fin N)) (x : Fin r → NormalizedSpin N) : + |bulkMarkedTest N r F Ψ Φ z x| ≤ ‖F‖*‖Ψ‖*‖Φ‖ := by + unfold bulkMarkedTest + simp only [abs_mul] + exact mul_le_mul (mul_le_mul (F.norm_coe_le_norm _) (Ψ.norm_coe_le_norm _) + (abs_nonneg _) (norm_nonneg _)) (Φ.norm_coe_le_norm _) (abs_nonneg _) (by positivity) + +def bulkFreshNumerator (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (p : TwoFreshDisorder (n+1) M) : ℝ := + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v p.1.1 p.1.2) r + (bulkMarkedTest (n+1) r F (restorationMarkTest r f Ψ 0) (restorationMarkTest r f Φ 0) p.2) + +def bulkFreshDenominator (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (p : TwoFreshDisorder (n+1) M) : ℝ := + tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v p.1.1 p.1.2) + (fun x => Real.exp (f (inner ℝ x.val p.2.1)+f (inner ℝ x.val p.2.2))) 1 + +lemma twoFreshHamiltonian_measurable (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) : + Measurable (fun p : TwoFreshDisorder (n+1) M × NormalizedSpin (n+1) => + bulkHamiltonian (n+1) M f v p.1.1.1 p.1.1.2 p.2) := by + have hp : Continuous (fun p : TwoFreshDisorder (n+1) M × NormalizedSpin (n+1) => + (p.1.1,p.2)) := continuous_fst.fst.prodMk continuous_snd + exact ((bulkHamiltonian_continuous (n+1) M f v).comp hp).measurable + +lemma twoFreshMarkedTest_measurable (n M r : ℕ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + Measurable (fun p : TwoFreshDisorder (n+1) M × (Fin r → NormalizedSpin (n+1)) => + bulkMarkedTest (n+1) r F Ψ Φ p.1.2 p.2) := by + have hp : Continuous (fun p : TwoFreshDisorder (n+1) M × (Fin r → NormalizedSpin (n+1)) => + (p.1.2,p.2)) := continuous_fst.snd.prodMk continuous_snd + exact ((bulkMarkedTest_continuous (n+1) r F Ψ Φ).comp hp).measurable + +lemma bulkFreshNumerator_measurable (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + Measurable (bulkFreshNumerator n M r f v F Ψ Φ) := by + let H := fun (p : TwoFreshDisorder (n+1) M) (x : NormalizedSpin (n+1)) => + bulkHamiltonian (n+1) M f v p.1.1 p.1.2 x + let G := fun (p : TwoFreshDisorder (n+1) M) (x : Fin r → NormalizedSpin (n+1)) => + bulkMarkedTest (n+1) r F (restorationMarkTest r f Ψ 0) (restorationMarkTest r f Φ 0) p.2 x + change Measurable (fun p => gibbsReplicaMean (unitSphereLaw (n+1)) (H p) r (G p)) + exact kernel_replicaMean_measurable (Kernel.const (TwoFreshDisorder (n+1) M) (unitSphereLaw (n+1))) + (H:=H) (G:=G) (twoFreshHamiltonian_measurable n M f v) + (twoFreshMarkedTest_measurable n M r F (restorationMarkTest r f Ψ 0) (restorationMarkTest r f Φ 0)) + +lemma bulkFreshDenominator_measurable (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) : + Measurable (bulkFreshDenominator n M f v) := by + apply kernel_tiltMean_measurable (Kernel.const (TwoFreshDisorder (n+1) M) (unitSphereLaw (n+1))) + (H:=fun p x => bulkHamiltonian (n+1) M f v p.1.1 p.1.2 x) + (twoFreshHamiltonian_measurable n M f v) + change Measurable (fun p : TwoFreshDisorder (n+1) M × NormalizedSpin (n+1) => + Real.exp (f (inner ℝ p.2.val p.1.2.1)+f (inner ℝ p.2.val p.1.2.2))) + exact (((f.measurable.comp (measurable_snd.subtype_val.inner measurable_fst.snd.fst)).add + (f.measurable.comp (measurable_snd.subtype_val.inner measurable_fst.snd.snd))).exp) + +lemma bulkFreshNumerator_bound (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) (p : TwoFreshDisorder (n+1) M) : + |bulkFreshNumerator n M r f v F Ψ Φ p| ≤ + ‖F‖*‖restorationMarkTest r f Ψ 0‖*‖restorationMarkTest r f Φ 0‖ := by + apply gibbsReplicaMean_bound_of_integrable (unitSphereLaw (n+1)) + ((bulkHamiltonian_continuous (n+1) M f v).measurable.comp (measurable_const.prodMk measurable_id)) + ((bulkMarkedTest_continuous (n+1) r F (restorationMarkTest r f Ψ 0) + (restorationMarkTest r f Φ 0)).measurable.comp (measurable_const.prodMk measurable_id)) + (bulkHamiltonian_exp_integrable n M f v p.1) + exact bulkMarkedTest_bound _ _ _ _ _ _ + +lemma bulkFreshDenominator_mem (n M : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) (p : TwoFreshDisorder (n+1) M) : + bulkFreshDenominator n M f v p ∈ Icc (Real.exp (-(2*‖f‖))) (Real.exp (2*‖f‖)) := by + change Real.exp (-(2*‖f‖)) ≤ tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v p.1.1 p.1.2) + (fun x => Real.exp (f (inner ℝ x.val p.2.1)+f (inner ℝ x.val p.2.2))) 1 ∧ + tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v p.1.1 p.1.2) + (fun x => Real.exp (f (inner ℝ x.val p.2.1)+f (inner ℝ x.val p.2.2))) 1 ≤ Real.exp (2*‖f‖) + exact bulk_two_denominator_bounds n M f v p.1 p.2.1 p.2.2 + +lemma bulkMarked_replica_moment (N r : ℕ) (μ : Measure (NormalizedSpin N)) [IsProbabilityMeasure μ] + {H : NormalizedSpin N → ℝ} (hH : Measurable H) (he : Integrable (fun x => Real.exp (H x)) μ) + (f : ℝ →ᵇ ℝ) (F : CompactBlock CompactOverlap r →ᵇ ℝ) + (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (k : ℕ) (z : EuclideanSpace ℝ (Fin N) × EuclideanSpace ℝ (Fin N)) : + (tiltMean μ H (fun x => Real.exp (f (inner ℝ x.val z.1)+f (inner ℝ x.val z.2))) 1)^k * + gibbsReplicaMean μ H r (bulkMarkedTest N r F (restorationMarkTest r f Ψ 0) + (restorationMarkTest r f Φ 0) z) = + gibbsReplicaMean μ H (r+k) (bulkMarkedTest N (r+k) (restorationBlockTest r F k) + (restorationMarkTest r f Ψ k) (restorationMarkTest r f Φ k) z) := by + let W := fun x : NormalizedSpin N => Real.exp (f (inner ℝ x.val z.1)+f (inner ℝ x.val z.2)) + let A := bulkMarkedTest N r F (restorationMarkTest r f Ψ 0) (restorationMarkTest r f Φ 0) z + have hW : Measurable W := ((f.measurable.comp (measurable_subtype_coe.inner measurable_const)).add + (f.measurable.comp (measurable_subtype_coe.inner measurable_const))).exp + have hpA : Continuous (fun x : Fin r → NormalizedSpin N => (z,x)) := + continuous_const.prodMk continuous_id + have hA : Measurable A := ((bulkMarkedTest_continuous N r F (restorationMarkTest r f Ψ 0) + (restorationMarkTest r f Φ 0)).comp hpA).measurable + have hWb (x) : |W x|≤Real.exp (2*‖f‖) := by + rw [abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + have := (le_abs_self (f (inner ℝ x.val z.1))).trans (f.norm_coe_le_norm _) + have := (le_abs_self (f (inner ℝ x.val z.2))).trans (f.norm_coe_le_norm _) + linarith + have h := restoration_replica_moment μ hH hW hA he (Real.exp_pos _).le (by positivity) + hWb (bulkMarkedTest_bound N r F (restorationMarkTest r f Ψ 0) (restorationMarkTest r f Φ 0) z) k + change _ = _ at h + rw [←h] + congr 1 + funext x + have h₀ := funext (restorationReplicaTest_twoMarks f F Ψ Φ z.1 z.2 0) + change _ = A at h₀ + rw [←h₀] + exact restorationReplicaTest_twoMarks f F Ψ Φ z.1 z.2 k x + +lemma bulkFresh_polynomial_moment (n M r : ℕ) (f : ℝ →ᵇ ℝ) (v : ℕ → ℝ) + (F : CompactBlock CompactOverlap r →ᵇ ℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (k : ℕ) (p : TwoFreshDisorder (n+1) M) : + bulkFreshDenominator n M f v p^k*bulkFreshNumerator n M r f v F Ψ Φ p = + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v p.1.1 p.1.2) + (r+k) (bulkMarkedTest (n+1) (r+k) (restorationBlockTest r F k) + (restorationMarkTest r f Ψ k) (restorationMarkTest r f Φ k) p.2) := by + exact bulkMarked_replica_moment (n+1) r (unitSphereLaw (n+1)) + ((bulkHamiltonian_continuous (n+1) M f v).measurable.comp (measurable_const.prodMk measurable_id)) + (bulkHamiltonian_exp_integrable n M f v p.1) f F Ψ Φ k p.2 + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkSingleEmpiricalLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkSingleEmpiricalLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..51d25a4e836d89b814b8dd4aeffba42970e8a374 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkSingleEmpiricalLimit.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkMarkedArray +import OAI.Probability.Perceptron.Cavity.BulkSingleLimit + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BoundedContinuousFunction + +lemma bulkSingleAverage_first_limit (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (α c : ℝ) (w : ℝ→ᵇℝ) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ht : Tendsto (fun n => ∫ p,bulkFreshNumerator (s n) (M (s n)) 1 g.f (v (s n)) + 1 (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>(1:ℝ→ᵇℝ))) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^1 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop (𝓝 c)) : + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 1 + (bulkSingleAverage (s n) (M (s n)+2) w)) atTop (𝓝 (α*c)) := by + simp_rw [bulkSingleAverage_first] + exact hd.mul ht + +lemma bulkSingleAverage_second_limit (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (hs : Tendsto s atTop atTop) (α c : ℝ) (w : ℝ→ᵇℝ) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + (ht : Tendsto (fun n => ∫ p,bulkFreshNumerator (s n) (M (s n)) 1 g.f (v (s n)) + 1 (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>w)) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^1 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop (𝓝 (c^2))) : + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 1 + (fun a x => (bulkSingleAverage (s n) (M (s n)+2) w a x)^2)) atTop (𝓝 ((α*c)^2)) := by + have hfac := bulk_density_factors M s hs α hd + have herr : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)^2* + bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 1 (fun a x => + (singleFieldMark w (bulkPatternFields ((Fin.last (M (s n))).castSucc) a x))^2)) atTop (𝓝 0) := by + apply squeeze_zero_norm (fun n => ?_) (by simpa only [zero_mul] using hfac.1.mul_const (‖w‖^2)) + rw [Real.norm_eq_abs,abs_mul,abs_of_nonneg (by positivity : 0≤((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)^2)] + exact mul_le_mul_of_nonneg_left (bulkSingleAverage_diagonal_bound (s n) (M (s n)) g.f w (v (s n))) (by positivity) + simp_rw [bulkSingleAverage_second] + simpa only [zero_add,mul_pow] using herr.add (hfac.2.mul ht) + +theorem bulk_single_empirical_limits (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (hs : Tendsto s atTop atTop) (α : ℝ) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (w : ℝ→ᵇℝ) : ∃ c : ℝ, |c|≤‖w‖ ∧ + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 1 + (bulkSingleAverage (s n) (M (s n)+2) w)) atTop (𝓝 (α*c)) ∧ + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 1 + (fun a x => (bulkSingleAverage (s n) (M (s n)+2) w a x)^2)) atTop (𝓝 ((α*c)^2)) := by + obtain ⟨c,hc,ht⟩ := bulk_single_limit_exists M g v s hlim hGG hgeo hn w + refine ⟨c,hc,?_,?_⟩ + · apply bulkSingleAverage_first_limit M g v s α c w hd + simpa [secondPairMark,pairMarkPower] using ht false + · apply bulkSingleAverage_second_limit M g v s hs α c w hd + simpa [secondPairMark,pairMarkPower] using ht true + +abbrev bulkAnnealedReplicaLaw (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) := + annealedInfiniteReplicaMeasure (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (bulkGibbsHamiltonian n M f v) (bulkGibbsHamiltonian_measurable n M f v) + +lemma bulkReplicaMean_annealed (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + (G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hG : Measurable (Function.uncurry G)) (C : ℝ) (hb : ∀ a x,|G a x|≤C) : + bulkReplicaMean n M f v r G = + ∫ p,G p.1 (fun i => p.2 i.val) ∂bulkAnnealedReplicaLaw n M f v := by + symm + exact annealedInfiniteReplica_marked_prefix (bulkSpinKernel n M) (bulkDisorderLaw (n+1) M) + (bulkGibbsHamiltonian n M f v) (bulkGibbsHamiltonian_measurable n M f v) + (ae_of_all _ (bulkHamiltonian_exp_integrable n M f v)) r hG hb + +lemma bulkReplicaPrefix_integrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + (G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hG : Measurable (Function.uncurry G)) (C : ℝ) (hb : ∀ a x,|G a x|≤C) : + Integrable (fun p => G p.1 (fun i => p.2 i.val)) (bulkAnnealedReplicaLaw n M f v) := by + have hm : Measurable (fun p : BulkDisorder (n+1) M×(ℕ→NormalizedSpin (n+1)) => G p.1 (fun i => p.2 i.val)) := + hG.comp (measurable_fst.prodMk (Measurable.of_eval fun coordinate => + (measurable_pi_apply coordinate.val).comp measurable_snd)) + apply Integrable.of_bound hm.aestronglyMeasurable C + exact ae_of_all _ fun p => by simpa only [Real.norm_eq_abs] using hb p.1 (fun i => p.2 i.val) + +lemma bulkReplicaMean_centered_square (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) + (G : BulkDisorder (n+1) M→(Fin r→NormalizedSpin (n+1))→ℝ) + (hG : Measurable (Function.uncurry G)) (C : ℝ) (hC : 0≤C) (hb : ∀ a x,|G a x|≤C) (c : ℝ) : + bulkReplicaMean n M f v r (fun a x => (G a x-c)^2)= + bulkReplicaMean n M f v r (fun a x => (G a x)^2)-2*c*bulkReplicaMean n M f v r G+c^2 := by + have hsq : ∀ a x,|(G a x)^2|≤C^2 := fun a x => by + rw [abs_pow]; exact (sq_le_sq₀ (abs_nonneg _) hC).mpr (hb a x) + have hcent : ∀ a x,|(G a x-c)^2|≤(C+|c|)^2 := fun a x => by + rw [abs_pow] + exact pow_le_pow_left₀ (abs_nonneg _) ((abs_sub (G a x) c).trans (add_le_add (hb a x) le_rfl)) 2 + rw [bulkReplicaMean_annealed _ _ _ _ _ _ ((hG.sub_const c).pow_const 2) _ hcent, + bulkReplicaMean_annealed _ _ _ _ _ _ (hG.pow_const 2) _ hsq, + bulkReplicaMean_annealed _ _ _ _ _ _ hG _ hb] + have hg := bulkReplicaPrefix_integrable n M f v r G hG C hb + have hg2 := bulkReplicaPrefix_integrable n M f v r (fun a x => (G a x)^2) (hG.pow_const 2) (C^2) hsq + simp_rw [sub_sq] + have h₁ : Integrable (fun p => (G p.1 (fun i => p.2 i.val))^2-2*G p.1 (fun i => p.2 i.val)*c) + (bulkAnnealedReplicaLaw n M f v) := hg2.sub ((hg.const_mul 2).mul_const c) + have h₂ : Integrable (fun p => 2*G p.1 (fun i => p.2 i.val)*c) + (bulkAnnealedReplicaLaw n M f v) := (hg.const_mul 2).mul_const c + rw [integral_add h₁ (integrable_const (μ:=bulkAnnealedReplicaLaw n M f v) (c^2)), + integral_sub hg2 h₂,integral_mul_const,integral_const_mul] + simp + ring + +def Jet3.dilationMark (g : Jet3) (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) : ℝ→ᵇℝ := + g.d2-ofCompactSupport (fun z => z*g.d1 z) + (continuous_id.mul g.d1.continuous) hg.mul_left + +@[simp] lemma Jet3.dilationMark_apply (g : Jet3) (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) (z : ℝ) : + g.dilationMark hg z=g.d2 z-z*g.d1 z := rfl + +lemma bulkC_singleAverage (n M : ℕ) (g : Jet3) (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) + (a : BulkDisorder (n+1) M) (x : Fin 1→NormalizedSpin (n+1)) : + bulkC (n+1) M g a.1 (x 0)=bulkSingleAverage n M (g.dilationMark hg) a x := by + rfl + +lemma bulkB_diagonal_singleAverage (n M : ℕ) (g : Jet3) + (a : BulkDisorder (n+1) M) (x : Fin 1→NormalizedSpin (n+1)) : + bulkB (n+1) M g a.1 (x 0) (x 0)=bulkSingleAverage n M (g.d1*g.d1) a x := by + rfl + +theorem bulk_single_L2_concentration (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (hs : Tendsto s atTop atTop) (α : ℝ) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (w : ℝ→ᵇℝ) : ∃ c : ℝ, |c|≤‖w‖ ∧ + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 1 + (fun a x => (bulkSingleAverage (s n) (M (s n)+2) w a x-α*c)^2)) atTop (𝓝 0) := by + obtain ⟨c,hc,h1,h2⟩ := bulk_single_empirical_limits M g v s hs α hd hlim hGG hgeo hn w + refine ⟨c,hc,?_⟩ + have he n := bulkReplicaMean_centered_square (s n) (M (s n)+2) g.f (v (s n)) 1 + (bulkSingleAverage (s n) (M (s n)+2) w) (bulkSingleAverage_measurable _ _ _) _ + (by positivity : 0≤((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)*‖w‖) + (bulkSingleAverage_bound _ _ _) (α*c) + simp_rw [he] + convert (h2.sub (h1.const_mul (2*(α*c)))).add_const ((α*c)^2) using 1 + ring_nf + +theorem bulk_diagonal_C_concentration (M : ℕ→ℕ) (g : Jet3) + (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (hs : Tendsto s atTop atTop) (α : ℝ) + (hd : Tendsto (fun n => ((M (s n)+2:ℕ):ℝ)/(s n+1:ℕ)) atTop (𝓝 α)) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) : + (∃ d : ℝ, |d|≤|α| * ‖g.d1‖^2 ∧ + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 1 + (fun a x => (bulkB (s n+1) (M (s n)+2) g a.1 (x 0) (x 0)-d)^2)) atTop (𝓝 0)) ∧ + (∃ c : ℝ, |c|≤|α| * ‖g.dilationMark hg‖ ∧ + Tendsto (fun n => bulkReplicaMean (s n) (M (s n)+2) g.f (v (s n)) 1 + (fun a x => (bulkC (s n+1) (M (s n)+2) g a.1 (x 0)-c)^2)) atTop (𝓝 0)) := by + constructor + · obtain ⟨c,hc,ht⟩ := bulk_single_L2_concentration M g v s hs α hd hlim hGG hgeo hn (g.d1*g.d1) + refine ⟨α*c,?_,?_⟩ + · rw [abs_mul] + exact (mul_le_mul_of_nonneg_left (hc.trans (norm_mul_le _ _)) (abs_nonneg α)).trans_eq (by ring) + · exact ht + · obtain ⟨c,hc,ht⟩ := bulk_single_L2_concentration M g v s hs α hd hlim hGG hgeo hn (g.dilationMark hg) + refine ⟨α*c,?_,?_⟩ + · rw [abs_mul]; exact mul_le_mul_of_nonneg_left hc (abs_nonneg α) + · exact ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkSingleLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkSingleLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..d427ec6160ec0e305a4c837c27986f5495ce2083 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkSingleLimit.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkLimitGeometry +import OAI.Probability.Perceptron.Variational.QuantileSingleReference + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma bulk_single_ratio_tendsto_of_reference (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (w w' : ℝ→ᵇℝ) + (η : ProbabilityMeasure (WeightedRestorationRange g.f (singleRestorationBound g.f w w'))) + (hm : ∀ j,(∫ x,x.1.val*x.2.val^j + ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f w w'))))= + ∫ Q : CompactArray CompactOverlap,scalarRestorationSingleMoment g.f w w' j + (fun i l => (Q i l).val) ∂(ν : Measure _)) : + Tendsto (fun n => ∫ p,bulkFreshNumerator (s n) (M (s n)) 1 g.f (v (s n)) + 1 (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>w')) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^1 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ x,x.1.val*restorationReciprocal g.f 1 x.2 + ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f w w'))))) := by + let Ψ : EuclideanSpace ℝ (Fin 1) →ᵇ ℝ := gaussianMixedTest (fun _ => w) + let Φ : EuclideanSpace ℝ (Fin 1) →ᵇ ℝ := gaussianMixedTest (fun _ => w') + let C := ‖(1 : CompactBlock CompactOverlap 1 →ᵇ ℝ)‖*‖restorationMarkTest 1 g.f Ψ 0‖*‖restorationMarkTest 1 g.f Φ 0‖+ + singleRestorationBound g.f w w' + have hC : 0≤C := add_nonneg (by positivity) (singleRestorationBound_nonneg _ _ _) + have hηB (x : WeightedRestorationRange g.f (singleRestorationBound g.f w w')) : |x.1.val|≤C := + (abs_le.mpr x.1.prop).trans (le_add_of_nonneg_left (by positivity)) + have hb (n : ℕ) (p : TwoFreshDisorder (s n+1) (M (s n))) : + |bulkFreshNumerator (s n) (M (s n)) 1 g.f (v (s n)) 1 Ψ Φ p|≤C := + (bulkFreshNumerator_bound _ _ _ _ _ _ _ _ _).trans + (le_add_of_nonneg_right (singleRestorationBound_nonneg _ _ _)) + have hmoment j : Tendsto (fun n => ∫ p, + bulkFreshNumerator (s n) (M (s n)) 1 g.f (v (s n)) 1 Ψ Φ p * + (bulkFreshCompactDenominator (s n) (M (s n)) g.f (v (s n)) p).val^j + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop + (𝓝 (∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f w w'))))) := by + rw [hm j] + simp_rw [scalarRestorationSingleMoment_compact] + exact bulkFresh_moment_tendsto M g.f v s hlim 1 1 Ψ Φ j + have ht := restoration_ratio_tendsto + (fun n => twoFreshDisorderLaw (s n+1) (M (s n))) + (η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f w w'))) + (Real.exp_pos _) + (fun n => bulkFreshNumerator (s n) (M (s n)) 1 g.f (v (s n)) 1 Ψ Φ) + (fun x => x.1.val) + (fun n => bulkFreshCompactDenominator (s n) (M (s n)) g.f (v (s n))) (fun x => x.2) + (fun n => bulkFreshNumerator_measurable _ _ _ _ _ _ _ _) (by fun_prop) + (fun n => bulkFreshCompactDenominator_measurable _ _ _ _) (by fun_prop) + hC hb hηB hmoment 1 + simpa only [div_eq_mul_inv, restorationReciprocal, ContinuousMap.coe_mk, bulkFreshCompactDenominator, Ψ, Φ] using ht + +theorem bulk_single_limit_exists (M : ℕ→ℕ) (g : Jet3) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactOverlap)} + (hlim : Tendsto (fun n => bulkGibbsArrayLaw (s n) (M (s n)) g.f (v (s n))) atTop (𝓝 ν)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect (bulkJointLaw ν) r i G a=0) + (hgeo : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(bulkJointLaw ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (w : ℝ→ᵇℝ) : ∃ c : ℝ, |c|≤‖w‖ ∧ ∀ b : Bool, + Tendsto (fun n => ∫ p,bulkFreshNumerator (s n) (M (s n)) 1 g.f (v (s n)) + 1 (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>secondPairMark w b)) p / + bulkFreshDenominator (s n) (M (s n)) g.f (v (s n)) p^1 + ∂twoFreshDisorderLaw (s n+1) (M (s n))) atTop (𝓝 (c^(pairMarkPower b))) := by + let q := boundedQuantile ((compactPositivePairLaw (bulkJointLaw ν)).map Prod.fst) + have hq : Monotone q := boundedQuantile_monotone _ + obtain ⟨c,hc,href⟩ := quantile_single_reference_exists q hq g w + refine ⟨c,hc,fun b => ?_⟩ + obtain ⟨ρ,η,hG,hge,hp,hm,hl⟩ := href b + have hpair := (compactPositivePairLaw_spin_quantile (bulkJointLaw ν) hn).trans hp.symm + have he (j : ℕ) : (∫ x,x.1.val*x.2.val^j + ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f w (secondPairMark w b)))))= + ∫ Q : CompactArray CompactOverlap,scalarRestorationSingleMoment g.f w (secondPairMark w b) j + (fun i l => (Q i l).val) ∂(ν : Measure _) := by + rw [hm j,←scalarGram_eq_of_pair_law (bulkJointLaw ν) ρ hGG hG hgeo hge hpair] + exact bulkJointLaw_scalarGram_integral ν _ _ + have ht := bulk_single_ratio_tendsto_of_reference M g v s hlim w (secondPairMark w b) η he + rwa [hl] at ht + +def singleFieldMark (w : ℝ→ᵇℝ) (z : Fin 1→ℝ) : ℝ := w (z 0) +lemma singleFieldMark_measurable (w : ℝ→ᵇℝ) : Measurable (singleFieldMark w) := by + unfold singleFieldMark; fun_prop +lemma singleFieldMark_bound (w : ℝ→ᵇℝ) (z : Fin 1→ℝ) : |singleFieldMark w z|≤‖w‖ := w.norm_coe_le_norm _ + +def bulkSingleAverage (n M : ℕ) (w : ℝ→ᵇℝ) (a : BulkDisorder (n+1) M) + (x : Fin 1→NormalizedSpin (n+1)) : ℝ := + ((n+1:ℕ):ℝ)⁻¹*∑ i,singleFieldMark w (bulkPatternFields i a x) + +lemma bulkSingleAverage_measurable (n M : ℕ) (w : ℝ→ᵇℝ) : + Measurable (Function.uncurry (bulkSingleAverage n M w)) := by + apply Measurable.const_mul + exact Finset.measurable_sum _ fun i _ => (singleFieldMark_measurable w).comp (bulkPatternFields_measurable _ _ _ _) + +lemma bulkSingleAverage_bound (n M : ℕ) (w : ℝ→ᵇℝ) (a : BulkDisorder (n+1) M) + (x : Fin 1→NormalizedSpin (n+1)) : |bulkSingleAverage n M w a x|≤M/(n+1:ℕ)*‖w‖ := by + unfold bulkSingleAverage + rw [abs_mul,abs_of_nonneg (by positivity : 0≤(((n+1:ℕ):ℝ)⁻¹))] + have h : |∑ i : Fin M,singleFieldMark w (bulkPatternFields i a x)|≤M*‖w‖ := + (Finset.abs_sum_le_sum_abs _ _).trans ((Finset.sum_le_sum fun i _ => singleFieldMark_bound w _).trans_eq (by simp)) + exact (mul_le_mul_of_nonneg_left h (by positivity)).trans_eq (by ring) + +lemma bulk_marked_last_single (n M : ℕ) (f w w' : ℝ→ᵇℝ) (v : ℕ→ℝ) : + bulkReplicaMean n (M+2) f v 1 (fun a x => + singleFieldMark w (bulkPatternFields ((Fin.last M).castSucc) a x)* + singleFieldMark w' (bulkPatternFields (Fin.last (M+1)) a x))= + ∫ p,bulkFreshNumerator n M 1 f v 1 + (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>w')) p / + bulkFreshDenominator n M f v p^1 ∂twoFreshDisorderLaw (n+1) M := by + rw [←bulkFresh_annealed_restoration] + unfold bulkReplicaMean + apply integral_congr_ae + exact ae_of_all _ fun a => by + apply congrArg (gibbsReplicaMean _ _ 1) + funext x + simp only [BoundedContinuousFunction.coe_one,Pi.one_apply,bulkMarkedTest,one_mul,gaussianMixedTest_apply,Fin.prod_univ_one, + singleFieldMark] + rfl + +lemma bulkSingleAverage_first (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) : + bulkReplicaMean n (M+2) f v 1 (bulkSingleAverage n (M+2) w)= + ((M+2:ℕ):ℝ)/(n+1:ℕ)*(∫ p,bulkFreshNumerator n M 1 f v 1 + (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>(1:ℝ→ᵇℝ))) p / + bulkFreshDenominator n M f v p^1 ∂twoFreshDisorderLaw (n+1) M) := by + unfold bulkSingleAverage + rw [bulkReplicaMean_const_mul] + have h := bulk_pattern_sum_first n (M+2) 1 f v (fun _=>1) measurable_const + _ (singleFieldMark_measurable w) (by norm_num : (0:ℝ)≤1) (norm_nonneg w) + (fun _=>by norm_num) (singleFieldMark_bound w) ((Fin.last M).castSucc) + simp only [one_mul] at h + rw [h,←bulk_marked_last_single n M f w 1 v] + simp only [singleFieldMark,BoundedContinuousFunction.coe_one,Pi.one_apply,mul_one] + ring + +lemma bulkSingleAverage_second (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) : + bulkReplicaMean n (M+2) f v 1 (fun a x => (bulkSingleAverage n (M+2) w a x)^2)= + ((M+2:ℕ):ℝ)/(n+1:ℕ)^2* + bulkReplicaMean n (M+2) f v 1 (fun a x => + (singleFieldMark w (bulkPatternFields ((Fin.last M).castSucc) a x))^2)+ + (((M+2:ℕ):ℝ)*((M+1:ℕ):ℝ)/(n+1:ℕ)^2)*(∫ p,bulkFreshNumerator n M 1 f v 1 + (gaussianMixedTest (fun _=>w)) (gaussianMixedTest (fun _=>w)) p / + bulkFreshDenominator n M f v p^1 ∂twoFreshDisorderLaw (n+1) M) := by + have hf : (fun a x => (bulkSingleAverage n (M+2) w a x)^2)= + (fun a x => (((n+1:ℕ):ℝ)⁻¹)^2*((∑ i,singleFieldMark w (bulkPatternFields i a x))^2)) := by + funext a x; unfold bulkSingleAverage; ring + have hkl : (Fin.last M).castSucc≠Fin.last (M+1) := by + intro h + have := congrArg Fin.val h + simp only [Fin.val_castSucc,Fin.val_last] at this + omega + rw [hf,bulkReplicaMean_const_mul] + have h := bulk_pattern_sum_second n (M+2) 1 f v (fun _=>1) measurable_const + _ (singleFieldMark_measurable w) (by norm_num : (0:ℝ)≤1) (norm_nonneg w) + (fun _=>by norm_num) (singleFieldMark_bound w) _ _ hkl + simp only [one_mul] at h + rw [h,bulk_marked_last_single] + simp only [div_eq_mul_inv,inv_pow] + push_cast + ring + +lemma bulkSingleAverage_diagonal_bound (n M : ℕ) (f w : ℝ→ᵇℝ) (v : ℕ→ℝ) : + |bulkReplicaMean n (M+2) f v 1 (fun a x => + (singleFieldMark w (bulkPatternFields ((Fin.last M).castSucc) a x))^2)|≤‖w‖^2 := by + apply bulkReplicaMean_bound _ _ _ _ _ _ + (((singleFieldMark_measurable w).comp (bulkPatternFields_measurable _ _ _ _)).pow_const 2) (by positivity) + intro a x + rw [abs_pow] + exact pow_le_pow_left₀ (abs_nonneg _) (singleFieldMark_bound w _) 2 + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkStein.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkStein.lean new file mode 100644 index 0000000000000000000000000000000000000000..61eb6a3c88069699c8a42e9189691f326d01dc06 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkStein.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FieldDerivative +import OAI.Probability.Perceptron.Variational.IntegratedConvex +import OAI.Probability.Perceptron.Cavity.BulkCoupling +import OAI.Probability.Perceptron.Pressure.SphericalPatternDirection + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma bulkOverlapPower_measurable (N r : ℕ) : + Measurable (fun x : Fin 2→NormalizedSpin N => spinOverlap (x 1) (x 0)^r) := by + exact (((measurable_pi_apply 1).subtype_val).inner ((measurable_pi_apply 0).subtype_val)).pow_const r + +lemma bulkOverlapPower_bound (N r : ℕ) (x : Fin 2→NormalizedSpin N) : + |spinOverlap (x 1) (x 0)^r|≤1 := by + rw [abs_pow] + exact (pow_le_pow_left₀ (abs_nonneg _) (spinOverlap_abs_le _ _) r).trans_eq (one_pow r) + +lemma bulk_fixed_patterns_ibp_raw (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (a : Fin M→Fin (n+1)→ℝ) : + (∫ g, tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) + (bulkY (n+1) p g) 1 ∂stdGaussian (BulkMark (n+1))) = + ∫ g, tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) + (fun x => inner ℝ (bulkDirection (n+1) p x) (bulkFeature (n+1) v x)) 1 - + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) 2 + (fun x => inner ℝ (bulkDirection (n+1) p (x 1)) (bulkFeature (n+1) v (x 0))) + ∂stdGaussian (BulkMark (n+1)) := by + have hW : Measurable (normalizedPatternEnergy (n+1) M f a) := + ((normalizedPatternEnergy_continuous (n+1) M f).comp + (continuous_const.prodMk continuous_id)).measurable + exact euclideanGaussian_tiltMean_ibp (unitSphereLaw (n+1)) hW + (bulkFeature_continuous (n+1) v).measurable (bulkDirection_continuous (n+1) p).measurable + (normalizedPatternEnergy_bound (n+1) M f a) + (fun x => le_of_eq (bulkFeature_norm_sq (n+1) v x)) + (fun x => by rw [bulkDirection_norm]; norm_num : ∀ x, ‖bulkDirection (n+1) p x‖^2≤(1:ℝ)) + +lemma bulk_fixed_integrand_eq (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (a : Fin M→Fin (n+1)→ℝ) (g : BulkMark (n+1)) : + tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) + (fun x => inner ℝ (bulkDirection (n+1) p x) (bulkFeature (n+1) v x)) 1 - + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) 2 + (fun x => inner ℝ (bulkDirection (n+1) p (x 1)) (bulkFeature (n+1) v (x 0))) = + bulkAmplitude (n+1) v p*(1-gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a g) 2 (fun x => spinOverlap (x 1) (x 0)^(p.val+1))) := by + have h1 : (fun x : NormalizedSpin (n+1) => inner ℝ (bulkDirection (n+1) p x) (bulkFeature (n+1) v x))= + (fun _ => bulkAmplitude (n+1) v p) := by + funext x + rw [bulkFeature_direction_inner,spinOverlap_self,one_pow,mul_one] + have h2 : (fun x : Fin 2→NormalizedSpin (n+1) => inner ℝ (bulkDirection (n+1) p (x 1)) (bulkFeature (n+1) v (x 0)))= + (fun x => bulkAmplitude (n+1) v p*spinOverlap (x 1) (x 0)^(p.val+1)) := by + funext x + exact bulkFeature_direction_inner _ _ _ _ _ + have hp : 0 gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) 2 + (fun x => spinOverlap (x 1) (x 0)^r)) (stdGaussian (BulkMark (n+1))) := by + exact kernel_replicaMean_bounded_integrable (Kernel.const (BulkMark (n+1)) (unitSphereLaw (n+1))) + (stdGaussian (BulkMark (n+1))) + (H := fun g x => bulkHamiltonian (n+1) M f v a g x) + (G := fun _ x => spinOverlap (x 1) (x 0)^r) + (((bulkHamiltonian_continuous (n+1) M f v).comp + ((continuous_const.prodMk continuous_fst).prodMk continuous_snd)).measurable) + ((bulkOverlapPower_measurable (n+1) r).comp measurable_snd) + zero_le_one (fun _ x => bulkOverlapPower_bound _ _ x) + +lemma bulk_fixed_patterns_ibp (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (a : Fin M→Fin (n+1)→ℝ) : + (∫ g, tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a g) + (bulkY (n+1) p g) 1 ∂stdGaussian (BulkMark (n+1))) = + bulkAmplitude (n+1) v p*(1-∫ g, gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a g) 2 + (fun x => spinOverlap (x 1) (x 0)^(p.val+1)) ∂stdGaussian (BulkMark (n+1))) := by + rw [bulk_fixed_patterns_ibp_raw] + simp_rw [bulk_fixed_integrand_eq] + rw [integral_const_mul,integral_sub (integrable_const _) (bulk_replicaPower_integrable_fixed n M f v (p.val+1) a)] + simp + +lemma bulk_meanY_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + Measurable (fun a : BulkDisorder (n+1) M => tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) (bulkY (n+1) p a.2) 1) := + kernel_tiltMean_measurable (bulkSpinKernel n M) + (H := fun a x => bulkHamiltonian (n+1) M f v a.1 a.2 x) + (Y := fun a x => bulkY (n+1) p a.2 x) + (bulkHamiltonian_continuous _ _ _ _).measurable (bulkY_joint_measurable _ _ _) + +lemma bulk_meanY_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (a : BulkDisorder (n+1) M) : + |tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) + (bulkY (n+1) p a.2) 1|≤‖a.2‖ := by + exact tiltMean_bound_of_integrable _ (bulkHamiltonian_section_measurable _ _ _ _ a) + (bulkY_measurable _ _).of_uncurry_left + (by simpa only [one_mul] using bulkHamiltonian_exp_integrable n M f v a) + (bulkY_bound _ _ _) + +lemma bulk_meanY_integrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + Integrable (fun a : BulkDisorder (n+1) M => tiltMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) (bulkY (n+1) p a.2) 1) (bulkDisorderLaw (n+1) M) := by + have hi : Integrable (fun g : BulkMark (n+1) => ‖g‖) (stdGaussian (BulkMark (n+1))) := + ((IsGaussian.memLp_id (stdGaussian (BulkMark (n+1))) 2 (by simp)).norm).integrable (by norm_num) + apply (hi.comp_snd (Measure.pi (fun _ : Fin M => Measure.pi (fun _ : Fin (n+1) => gaussianReal 0 1)))).mono' + (bulk_meanY_measurable n M f v p).aestronglyMeasurable + exact ae_of_all _ fun a => by simpa only [Real.norm_eq_abs] using bulk_meanY_bound n M f v p a + +lemma bulk_replicaPower_integrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (r : ℕ) : + Integrable (fun a : BulkDisorder (n+1) M => gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) 2 (fun x => spinOverlap (x 1) (x 0)^r)) + (bulkDisorderLaw (n+1) M) := + kernel_replicaMean_bounded_integrable (bulkSpinKernel n M) _ + (H := fun a x => bulkHamiltonian (n+1) M f v a.1 a.2 x) + (G := fun _ x => spinOverlap (x 1) (x 0)^r) + (bulkHamiltonian_continuous _ _ _ _).measurable + ((bulkOverlapPower_measurable _ _).comp measurable_snd) zero_le_one + (fun _ x => bulkOverlapPower_bound _ _ x) + +lemma bulk_annealed_ibp (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + (∫ a, tiltMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a.1 a.2) + (bulkY (n+1) p a.2) 1 ∂bulkDisorderLaw (n+1) M) = + bulkAmplitude (n+1) v p*(1-∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) 2 + (fun x => spinOverlap (x 1) (x 0)^(p.val+1)) ∂bulkDisorderLaw (n+1) M) := by + rw [bulkDisorderLaw,integral_prod _ (bulk_meanY_integrable n M f v p)] + simp_rw [bulk_fixed_patterns_ibp] + rw [integral_const_mul,integral_sub (integrable_const _) + (bulk_replicaPower_integrable n M f v (p.val+1)).integral_prod_left] + rw [integral_const] + simp only [Measure.real,measure_univ,ENNReal.toReal_one,one_smul] + rw [← integral_prod _ (bulk_replicaPower_integrable n M f v (p.val+1))] + +lemma bulk_expected_slope_eq (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + (∫ a, bulkCouplingSlope n M f v p u a ∂bulkDisorderLaw (n+1) M) = + bulkCoefficient (n+1) p^2*u*(1-∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2) 2 + (fun x => spinOverlap (x 1) (x 0)^(p.val+1)) ∂bulkDisorderLaw (n+1) M) := by + unfold bulkCouplingSlope + rw [integral_const_mul,bulk_annealed_ibp] + simp only [bulkAmplitude,Function.update_self,bulkCoefficient] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkTangentError.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkTangentError.lean new file mode 100644 index 0000000000000000000000000000000000000000..00b11cbf989916afa848d176ad4a81d90c949e5f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkTangentError.lean @@ -0,0 +1,183 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.TerminalReplicaRestoration +import OAI.Probability.Perceptron.Cavity.AmbientBulkFeature +import OAI.Probability.Perceptron.Interpolation.VectorReplicaDirectionBound + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction ContDiff + +lemma bulkCovarianceDerivative_bound (N : ℕ) (v : ℕ→ℝ) {C r : ℝ} + (hC : 0≤C) (hv : ∀ j, |v (j+1)|≤C) (hr : |r|≤1) : + |bulkCovarianceDerivative N v r|≤C^2*bulkScale N^2 := by + have hb (j : Fin N) : bulkAmplitude N v j^2*(j.val+1)≤C^2*bulkScale N^2*(1/2:ℝ)^(j.val+1) := by + let w : ℝ := (1/2:ℝ)^(j.val+1) + have hw : 0≤w := by dsimp [w]; positivity + have hwp : w*(j.val+1)≤1 := by + have hk : (j.val+1:ℝ)≤(2:ℝ)^(j.val+1) := by exact_mod_cast (Nat.lt_two_pow_self (n:=j.val+1)).le + dsimp [w] + rw [div_pow,one_pow,one_div_mul_eq_div] + exact (div_le_one (by positivity)).mpr (by simpa only [Nat.cast_add,Nat.cast_one] using hk) + have hv2 : v (j.val+1)^2≤C^2 := by simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg _) (hv j.val) 2 + unfold bulkAmplitude + rw [perturbationWeight_eq] + change (bulkScale N*w*v (j.val+1))^2*(j.val+1)≤C^2*bulkScale N^2*w + calc + _ = bulkScale N^2*w^2*(j.val+1)*v (j.val+1)^2 := by ring + _ ≤ bulkScale N^2*w^2*(j.val+1)*C^2 := mul_le_mul_of_nonneg_left hv2 (by positivity) + _ = C^2*bulkScale N^2*w*(w*(j.val+1)) := by ring + _ ≤ C^2*bulkScale N^2*w*1 := mul_le_mul_of_nonneg_left hwp (by positivity) + _ = _ := mul_one _ + unfold bulkCovarianceDerivative + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ j : Fin N, C^2*bulkScale N^2*(1/2:ℝ)^(j.val+1) := by + apply Finset.sum_le_sum + intro j _ + rw [abs_mul,abs_mul,abs_sq,abs_of_nonneg (by positivity : (0:ℝ)≤j.val+1),abs_pow] + exact (mul_le_mul_of_nonneg_left (pow_le_one₀ (abs_nonneg r) hr) (by positivity)).trans (by simpa only [mul_one] using hb j) + _ = C^2*bulkScale N^2*(∑ j : Fin N, (1/2:ℝ)^(j.val+1)) := (Finset.mul_sum _ _ _).symm + _ ≤ C^2*bulkScale N^2*1 := mul_le_mul_of_nonneg_left (half_power_sum_le_one N) + (mul_nonneg (pow_nonneg hC 2) (sq_nonneg _)) + _ = _ := mul_one _ + +def bulkTangentDirection (N : ℕ) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) (x : Fin 2→NormalizedSpin N) : BulkMark N := + G (spinOverlap (x 0) (x 1)) • + fderiv ℝ (ambientBulkFeature N v) (x 0).val + ((x 1).val-spinOverlap (x 0) (x 1) • (x 0).val) + +lemma bulkTangentDirection_continuous (N : ℕ) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) : + Continuous (bulkTangentDirection N v G) := by + have hr : Continuous (fun x : Fin 2→NormalizedSpin N => spinOverlap (x 0) (x 1)) := by + unfold spinOverlap; fun_prop + apply (G.continuous.comp hr).smul + have h0 : Continuous (fun x : Fin 2→NormalizedSpin N => (x 0).val) := by fun_prop + have h1 : Continuous (fun x : Fin 2→NormalizedSpin N => (x 1).val) := by fun_prop + exact (((ambientBulkFeature_contDiff N v).continuous_fderiv (by norm_num)).comp h0).clm_apply + (h1.sub (hr.smul h0)) + +lemma bulkTangentDirection_cross (N : ℕ) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) + (x : Fin 2→NormalizedSpin N) (y : NormalizedSpin N) : + inner ℝ (bulkTangentDirection N v G x) (bulkFeature N v y)= + G (spinOverlap (x 0) (x 1))*bulkCovarianceDerivative N v (spinOverlap (x 0) y)* + (spinOverlap (x 1) y-spinOverlap (x 0) (x 1)*spinOverlap (x 0) y) := by + unfold bulkTangentDirection + rw [← ambientBulkFeature_eq,inner_smul_left,starRingEnd_apply,star_trivial,ambientBulkFeature_deriv_inner] + simp only [inner_sub_left,inner_smul_left,starRingEnd_apply,star_trivial,spinOverlap] + ring + +lemma bulkTangentDirection_cross_bound (N : ℕ) (v : ℕ→ℝ) (G : ℝ→ᵇℝ) {C : ℝ} + (hC : 0≤C) (hv : ∀ j, |v (j+1)|≤C) + (x : Fin 2→NormalizedSpin N) (y : NormalizedSpin N) : + |inner ℝ (bulkTangentDirection N v G x) (bulkFeature N v y)|≤2*‖G‖*C^2*bulkScale N^2 := by + rw [bulkTangentDirection_cross,abs_mul,abs_mul] + have hb : |spinOverlap (x 1) y-spinOverlap (x 0) (x 1)*spinOverlap (x 0) y|≤2 := by + apply (abs_sub _ _).trans + rw [abs_mul] + have hm := mul_le_mul (spinOverlap_abs_le (x 0) (x 1)) (spinOverlap_abs_le (x 0) y) (abs_nonneg _) (by norm_num : (0:ℝ)≤1) + linarith [spinOverlap_abs_le (x 1) y] + have hc := bulkCovarianceDerivative_bound N v hC hv (spinOverlap_abs_le (x 0) y) + calc + _ ≤ (‖G‖*(C^2*bulkScale N^2))*2 := + mul_le_mul (mul_le_mul (G.norm_coe_le_norm _) hc (abs_nonneg _) (norm_nonneg _)) hb (abs_nonneg _) (by positivity) + _ = _ := by ring + +lemma bulk_tangent_perturbation_bound (n M : ℕ) (f G : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : Fin M→Fin (n+1)→ℝ) {C : ℝ} (hC : 0≤C) (hv : ∀ j, |v (j+1)|≤C) : + |∫ g, gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a g) 2 + (fun x => inner ℝ (bulkTangentDirection (n+1) v G x) g) ∂stdGaussian (BulkMark (n+1))|≤ + 8*‖G‖*C^2*bulkScale (n+1)^2 := by + obtain ⟨D,hD⟩ := (isCompact_univ : IsCompact (univ : Set (Fin 2→NormalizedSpin (n+1)))).bddAbove_image + (bulkTangentDirection_continuous (n+1) v G).norm.continuousOn + have hWD (x : Fin 2→NormalizedSpin (n+1)) : ‖bulkTangentDirection (n+1) v G x‖≤ max D 0 := + (hD (mem_image_of_mem _ (mem_univ x))).trans (le_max_left _ _) + have he := euclideanGaussian_replica_direction_bound (unitSphereLaw (n+1)) 2 + ((normalizedPatternEnergy_continuous (n+1) M f).measurable.comp (measurable_const.prodMk measurable_id)) + (bulkFeature_continuous (n+1) v).measurable + (bulkTangentDirection_continuous (n+1) v G).measurable + (Real.sqrt_nonneg _) (le_max_right D 0) (by positivity : 0≤2*‖G‖*C^2*bulkScale (n+1)^2) + (normalizedPatternEnergy_bound (n+1) M f a) + (fun x => le_of_eq (by simpa only [bulkFeatureBound] using bulkFeature_norm (n+1) v x)) + hWD (bulkTangentDirection_cross_bound (n+1) v G hC hv) + apply he.trans_eq + norm_num + ring + +def bulkPatternLinear {N : ℕ} (a : Fin N→ℝ) : Spin N→L[ℝ]ℝ := + ∑ i, a i • EuclideanSpace.proj i + +lemma bulkPatternLinear_apply {N : ℕ} (a : Fin N→ℝ) (x : Spin N) : + bulkPatternLinear a x=∑ i,a i*x i := by + simp only [bulkPatternLinear,sum_apply,smul_apply, + smul_eq_mul] + rfl + +def ambientBulkHamiltonian (N M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : Fin M→Fin N→ℝ) (g : BulkMark N) (x : Spin N) : ℝ := + (∑ j,f.f (bulkPatternLinear (a j) x))+inner ℝ g (ambientBulkFeature N v x) + +lemma ambientBulkHamiltonian_eq (N M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : Fin M→Fin N→ℝ) (g : BulkMark N) (x : NormalizedSpin N) : + ambientBulkHamiltonian N M f v a g x.val=bulkHamiltonian N M f.f v a g x := by + simp only [ambientBulkHamiltonian,bulkHamiltonian,normalizedPatternEnergy, + bulkPatternLinear_apply,ambientBulkFeature_eq,real_inner_comm g] + +lemma ambientBulkHamiltonian_contDiff (N M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : Fin M→Fin N→ℝ) (g : BulkMark N) : + ContDiff ℝ 1 (ambientBulkHamiltonian N M f v a g) := by + apply (ContDiff.sum (fun j _ => (f.contDiff.of_le (by norm_num)).comp (bulkPatternLinear (a j)).contDiff)).add + exact (innerSL ℝ g).contDiff.comp ((ambientBulkFeature_contDiff N v).of_le (by norm_num)) + +lemma ambientBulkHamiltonian_deriv (N M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : Fin M→Fin N→ℝ) (g : BulkMark N) (x z : Spin N) : + fderiv ℝ (ambientBulkHamiltonian N M f v a g) x z = + (∑ j,f.d1 (bulkPatternLinear (a j) x)*bulkPatternLinear (a j) z)+ + inner ℝ (fderiv ℝ (ambientBulkFeature N v) x z) g := by + have hd := HasFDerivAt.fun_sum (fun j (_ : j∈(Finset.univ : Finset (Fin M))) => + (f.has1 (bulkPatternLinear (a j) x)).comp_hasFDerivAt x (bulkPatternLinear (a j)).hasFDerivAt) + have hg := (innerSL ℝ g).hasFDerivAt.comp x + (((ambientBulkFeature_contDiff N v).differentiable (by norm_num)) x).hasFDerivAt + have he := (hd.add hg).fderiv + change fderiv ℝ (ambientBulkHamiltonian N M f v a g) x z=_ + rw [show fderiv ℝ (ambientBulkHamiltonian N M f v a g) x = _ from he] + simp only [add_apply,sum_apply, + smul_apply,smul_eq_mul,ContinuousLinearMap.comp_apply,coe_innerSL_apply] + rw [real_inner_comm g] + +lemma bulk_gibbs_replica_tangent (n M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : Fin M→Fin (n+1)→ℝ) (g : BulkMark (n+1)) + (G : ℝ→ᵇℝ) (hG : ContDiff ℝ 1 (G : ℝ→ℝ)) : + (n:ℝ)*gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f.f v a g) 2 + (fun x => spinOverlap (x 0) (x 1)*G (spinOverlap (x 0) (x 1))) = + gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f.f v a g) 2 + (fun x => deriv (G : ℝ→ℝ) (spinOverlap (x 0) (x 1))*(1-spinOverlap (x 0) (x 1)^2)+ + (∑ j,G (spinOverlap (x 0) (x 1))*f.d1 (∑ i,a j i*(x 0).val i)* + ((∑ i,a j i*(x 1).val i)-spinOverlap (x 0) (x 1)*(∑ i,a j i*(x 0).val i)))+ + inner ℝ (bulkTangentDirection (n+1) v G x) g) := by + have he := unitSphere_gibbs_replica_tangent n (ambientBulkHamiltonian_contDiff (n+1) M f v a g) hG + simp only [ambientBulkHamiltonian_eq] at he + rw [he] + apply congrArg (gibbsReplicaMean (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f.f v a g) 2) + funext x + rw [ambientBulkHamiltonian_deriv] + have hs : (∑ j,G (spinOverlap (x 0) (x 1))* + (f.d1 (bulkPatternLinear (a j) (x 0).val)* + bulkPatternLinear (a j) ((x 1).val-spinOverlap (x 0) (x 1) • (x 0).val))) = + ∑ j,G (spinOverlap (x 0) (x 1))*f.d1 (∑ i,a j i*(x 0).val i)* + ((∑ i,a j i*(x 1).val i)-spinOverlap (x 0) (x 1)*(∑ i,a j i*(x 0).val i)) := by + apply Finset.sum_congr rfl + intro j _ + simp only [map_sub,map_smul,smul_eq_mul,bulkPatternLinear_apply] + ring + simp only [bulkTangentDirection,inner_smul_left,starRingEnd_apply,star_trivial] + rw [mul_add,Finset.mul_sum,hs] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkThermal.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkThermal.lean new file mode 100644 index 0000000000000000000000000000000000000000..c5febb9d5cbf4b60b9a21b60a9abdbad28758948 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkThermal.lean @@ -0,0 +1,145 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkStein + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma bulkMarkNorm_memLp (n M : ℕ) : + MemLp (fun a : BulkDisorder (n+1) M => ‖a.2‖) 2 (bulkDisorderLaw (n+1) M) := by + exact ((IsGaussian.memLp_id (stdGaussian (BulkMark (n+1))) 2 (by simp)).norm).comp_snd + (Measure.pi (fun _ : Fin M => Measure.pi (fun _ : Fin (n+1) => gaussianReal 0 1))) + +def bulkThermalVar (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (u : ℝ) (a : BulkDisorder (n+1) M) : ℝ := + thermalVar (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f (Function.update v (p.val+1) 0) a.1 a.2) + (fun x => bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x) u + +lemma bulkThermalVar_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + Measurable (bulkThermalVar n M f v p u) := + measurable_thermalVar (unitSphereLaw (n+1)) + (bulkHamiltonian_continuous _ _ _ _).measurable + ((bulkY_joint_measurable _ _ _).const_mul _) u + +lemma bulkThermalVar_nonneg (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (u : ℝ) (a : BulkDisorder (n+1) M) : 0≤bulkThermalVar n M f v p u a := by + apply thermalVar_nonneg (unitSphereLaw (n+1)) + (bulkHamiltonian_section_measurable _ _ _ _ a) + ((bulkY_measurable _ _).of_uncurry_left.const_mul _) + (by unfold bulkFeatureBound; positivity : 0≤(M:ℝ)*‖f‖+bulkFeatureBound (n+1) (Function.update v (p.val+1) 0)*‖a.2‖) + (mul_nonneg (bulkCoefficient_pos n p).le (norm_nonneg a.2)) + (bulkHamiltonian_bound _ _ _ _ a) + intro x + rw [abs_mul,abs_of_pos (bulkCoefficient_pos n p)] + exact mul_le_mul_of_nonneg_left (bulkY_bound _ _ _ _) (bulkCoefficient_pos n p).le + +lemma bulkThermalVar_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) + (u : ℝ) (a : BulkDisorder (n+1) M) : + |bulkThermalVar n M f v p u a|≤2*(bulkCoefficient (n+1) p*‖a.2‖)^2 := by + apply thermalVar_bound (unitSphereLaw (n+1)) + (bulkHamiltonian_section_measurable _ _ _ _ a) + ((bulkY_measurable _ _).of_uncurry_left.const_mul _) + (by unfold bulkFeatureBound; positivity : 0≤(M:ℝ)*‖f‖+bulkFeatureBound (n+1) (Function.update v (p.val+1) 0)*‖a.2‖) + (mul_nonneg (bulkCoefficient_pos n p).le (norm_nonneg a.2)) + (bulkHamiltonian_bound _ _ _ _ a) + intro x + rw [abs_mul,abs_of_pos (bulkCoefficient_pos n p)] + exact mul_le_mul_of_nonneg_left (bulkY_bound _ _ _ _) (bulkCoefficient_pos n p).le + +lemma bulkThermalVar_integrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + Integrable (bulkThermalVar n M f v p u) (bulkDisorderLaw (n+1) M) := by + have hb := (bulkMarkNorm_memLp n M).const_mul (bulkCoefficient (n+1) p) + apply (((memLp_two_iff_integrable_sq hb.aestronglyMeasurable).mp hb).const_mul 2).mono' + (bulkThermalVar_measurable n M f v p u).aestronglyMeasurable + exact ae_of_all _ fun a => by simpa only [Real.norm_eq_abs] using bulkThermalVar_bound n M f v p u a + +lemma bulkExpectedSlope_hasDerivAt (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + HasDerivAt (fun t => ∫ a, bulkCouplingSlope n M f v p t a ∂bulkDisorderLaw (n+1) M) + (∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M) u := by + have hb := (bulkMarkNorm_memLp n M).const_mul (bulkCoefficient (n+1) p) + have hd := annealedAffineMean_deriv (unitSphereLaw (n+1)) (bulkDisorderLaw (n+1) M) + (H := fun a x => bulkHamiltonian (n+1) M f (Function.update v (p.val+1) 0) a.1 a.2 x) + (Y := fun a x => bulkCoefficient (n+1) p*bulkY (n+1) p a.2 x) + (A := fun a => M*‖f‖+bulkFeatureBound (n+1) (Function.update v (p.val+1) 0)*‖a.2‖) + (B := fun a => bulkCoefficient (n+1) p*‖a.2‖) + (bulkHamiltonian_continuous _ _ _ _).measurable ((bulkY_joint_measurable _ _ _).const_mul _) + (fun _ => by unfold bulkFeatureBound; positivity) (fun _ => mul_nonneg (bulkCoefficient_pos n p).le (norm_nonneg _)) + (bulkHamiltonian_bound _ _ _ _) (fun a x => by + rw [abs_mul,abs_of_pos (bulkCoefficient_pos n p)] + exact mul_le_mul_of_nonneg_left (bulkY_bound _ _ _ _) (bulkCoefficient_pos n p).le) + (hb.integrable (by norm_num)) ((memLp_two_iff_integrable_sq hb.aestronglyMeasurable).mp hb) u + convert hd using 1 + · funext t + apply integral_congr_ae + exact ae_of_all _ fun a => by + unfold bulkCouplingSlope + rw [← tiltMean_const_mul_general] + congr 2 + funext x + exact bulkHamiltonian_update _ _ _ _ _ _ _ _ + · rfl + +lemma bulk_expected_slope_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (u : ℝ) : + |∫ a, bulkCouplingSlope n M f v p u a ∂bulkDisorderLaw (n+1) M|≤ + 2*bulkCoefficient (n+1) p^2*|u| := by + rw [bulk_expected_slope_eq,abs_mul,abs_mul,abs_sq] + have hh : |∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2) 2 + (fun x => spinOverlap (x 1) (x 0)^(p.val+1)) ∂bulkDisorderLaw (n+1) M|≤1 := by + apply abs_integral_le_integral_abs.trans + calc + _ ≤ ∫ _ : BulkDisorder (n+1) M, (1:ℝ) ∂bulkDisorderLaw (n+1) M := by + apply integral_mono_of_nonneg (ae_of_all _ fun _ => abs_nonneg _) (integrable_const _) + exact ae_of_all _ fun a => gibbsReplicaMean_bound_of_integrable (unitSphereLaw (n+1)) + (bulkHamiltonian_section_measurable _ _ _ _ a) (bulkOverlapPower_measurable _ _) + (bulkHamiltonian_exp_integrable n M f _ a) (bulkOverlapPower_bound _ _) + _ = 1 := by simp + have he : |1-∫ a, gibbsReplicaMean (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f (Function.update v (p.val+1) u) a.1 a.2) 2 + (fun x => spinOverlap (x 1) (x 0)^(p.val+1)) ∂bulkDisorderLaw (n+1) M|≤2 := by + simpa only [abs_one,one_add_one_eq_two] using (abs_sub _ _).trans (add_le_add (le_refl |(1:ℝ)|) hh) + nlinarith [mul_le_mul_of_nonneg_left he (mul_nonneg (sq_nonneg (bulkCoefficient (n+1) p)) (abs_nonneg u))] + +lemma bulkExpectedThermalVar_measurable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + Measurable (fun u => ∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M) := by + have he : (fun u => ∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M)= + deriv (fun u => ∫ a, bulkCouplingSlope n M f v p u a ∂bulkDisorderLaw (n+1) M) := by + funext u + exact (bulkExpectedSlope_hasDerivAt n M f v p u).deriv.symm + rw [he] + exact measurable_deriv _ + +lemma bulkExpectedThermalVar_intervalIntegrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (a b : ℝ) : + IntervalIntegrable (fun u => ∫ x, bulkThermalVar n M f v p u x ∂bulkDisorderLaw (n+1) M) volume a b := by + have hb := (bulkMarkNorm_memLp n M).const_mul (bulkCoefficient (n+1) p) + have hi := ((memLp_two_iff_integrable_sq hb.aestronglyMeasurable).mp hb).const_mul 2 + apply IntegrableOn.intervalIntegrable + apply IntegrableOn.of_bound (isCompact_uIcc.measure_lt_top) + (bulkExpectedThermalVar_measurable n M f v p).aestronglyMeasurable.restrict + (∫ x : BulkDisorder (n+1) M, 2*(bulkCoefficient (n+1) p*‖x.2‖)^2 ∂bulkDisorderLaw (n+1) M) + apply ae_of_all + intro u + rw [Real.norm_eq_abs] + exact abs_integral_le_integral_abs.trans (integral_mono (bulkThermalVar_integrable n M f v p u).abs hi + (bulkThermalVar_bound n M f v p u)) + +lemma bulkThermalVar_integrated_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + (∫ u in (1:ℝ)..2, ∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M) ≤ + 6*bulkCoefficient (n+1) p^2 := by + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun u _ => bulkExpectedSlope_hasDerivAt n M f v p u) + (bulkExpectedThermalVar_intervalIntegrable n M f v p 1 2)] + have h1 := bulk_expected_slope_bound n M f v p 1 + have h2 := bulk_expected_slope_bound n M f v p 2 + norm_num only [abs_one,abs_of_nonneg (by norm_num : (0:ℝ)≤2)] at h1 h2 + linarith [le_abs_self (∫ a, bulkCouplingSlope n M f v p 2 a ∂bulkDisorderLaw (n+1) M), + neg_abs_le (∫ a, bulkCouplingSlope n M f v p 1 a ∂bulkDisorderLaw (n+1) M)] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/BulkTimeLaw.lean b/lean/OAI/Probability/Perceptron/Cavity/BulkTimeLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..a3c2c780f2b82e3d7801aaf7201ead62d53b397a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/BulkTimeLaw.lean @@ -0,0 +1,140 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkMarkedSelfConsistency + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma markedTimeLaw_geometry {K : ℝ} (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hs : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i j, (Q i j).1 = (Q j i).1) + (hd : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i, (Q i i).1.val = 1) + (hu : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i j l, + min (Q i j).1.val (Q i l).1.val ≤ (Q j l).1.val) : + ∀ᵐ Q ∂(markedTimeLaw K μ : Measure (CompactArray Time)), + (∀ i j, Q i j = Q j i) ∧ (∀ i, Q i i = 1) ∧ + ∀ i j l, min (Q i j) (Q i l) ≤ Q j l := by + let e : BulkPairRange K → Time := fun p => nonnegativeSpinTime p.1 + have hc : Continuous e := nonnegativeSpinTime_continuous.comp continuous_fst + have hmeas : MeasurableSet {Q : CompactArray Time | + (∀ i j, Q i j = Q j i) ∧ (∀ i, Q i i = 1) ∧ + ∀ i j l, min (Q i j) (Q i l) ≤ Q j l} := by + simp only [Set.ofPred_and,Set.ofPred_forall] + exact (MeasurableSet.iInter fun i => MeasurableSet.iInter fun j => + measurableSet_eq_fun (by fun_prop) (by fun_prop)).inter + ((MeasurableSet.iInter fun i => measurableSet_eq_fun (by fun_prop) measurable_const).inter + (MeasurableSet.iInter fun i => MeasurableSet.iInter fun j => MeasurableSet.iInter fun l => + measurableSet_le (by fun_prop) (by fun_prop))) + exact (ae_map_iff (compactMapArray_continuous hc).measurable.aemeasurable hmeas).mpr (by + filter_upwards [hs,hd,hu] with Q hS hD hU + refine ⟨fun i j => congrArg nonnegativeSpinTime (hS i j),?_,?_⟩ + · intro i + apply Subtype.ext + change max (Q i i).1.val 0 = 1 + rw [hD i]; norm_num + · intro i j l + change min (max (Q i j).1.val 0) (max (Q i l).1.val 0) ≤ max (Q j l).1.val 0 + rw [←max_min_distrib_right] + exact max_le_max (hU i j l) le_rfl) + +theorem bulk_marked_time_inputs (M : ℕ → ℕ) (g : Jet3) (v : ℕ → ℕ → ℝ) + (hv : ∀ᶠ n in atTop, ∀ p, 1 ≤ v n p) + (hd : ∀ p, Tendsto (fun n => bulkDeviationAt n (M n) g.f p (v n)) atTop (𝓝 0)) + (s : ℕ → ℕ) (hs : StrictMono s) (K : ℝ) + (hK : ∀ n, (M (s n) : ℝ) / (s n+1 : ℕ) * ‖g.d1‖^2 ≤ K) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hlim : Tendsto (fun n => bulkMarkedArrayLaw (s n) (M (s n)) g (v (s n)) K (hK n)) atTop (𝓝 μ)) : + (∀ n (i : Fin n) (F : CompactBlock Time n →ᵇ ℝ) (a : Time →ᵇ ℝ), + compactGGDefect (markedTimeLaw K μ) n i F a = 0) ∧ + (∀ᵐ Q ∂(markedTimeLaw K μ : Measure (CompactArray Time)), + (∀ i j, Q i j = Q j i) ∧ (∀ i, Q i i = 1) ∧ + ∀ i j l, min (Q i j) (Q i l) ≤ Q j l) ∧ + (∀ e : Equiv.Perm ℕ, MeasurePreserving (compactRelabel (K:=Time) e) + (markedTimeLaw K μ : Measure _) (markedTimeLaw K μ : Measure _)) := by + have hp := bulkMarkedArray_limit_overlap M g v s K hK hlim + have hgeom := bulk_limit_geometry M g.f v hv hd hs hp + have hex e := compact_exchangeability_limit hlim e + (fun n => bulkMarkedArray_exchangeable (s n) (M (s n)) g (v (s n)) K (hK n) e) + have hmarked := marked_overlap_geometry K μ hex hgeom.1 hgeom.2.1 + refine ⟨?_,?_,?_⟩ + · rw [markedTimeLaw_factor] + exact compactMapLaw_gg nonnegativeSpinTime nonnegativeSpinTime_continuous _ + (bulk_limit_gg M g.f v hv hd hs hp) + · apply markedTimeLaw_geometry μ hmarked.1 _ hmarked.2.1 + exact ae_of_ae_map (compactMapArray_continuous (show Continuous + (Prod.fst : BulkPairRange K → CompactOverlap) from continuous_fst)).measurable.aemeasurable + (bulkGibbsArray_limit_diagonal g.f M v s hp) + · exact fun e => compactMapLaw_exchangeable _ _ μ e (hex e) + + + +lemma bulkB_diagonal_nonneg (N M : ℕ) (f : Jet3) (a : Fin M → Fin N → ℝ) + (x : NormalizedSpin N) : 0 ≤ bulkB N M f a x x := by + unfold bulkB + exact mul_nonneg (by positivity) (Finset.sum_nonneg fun _index _ => mul_self_nonneg _) + +lemma bulkB_add_diagonal_bound (N M : ℕ) (f : Jet3) (a : Fin M → Fin N → ℝ) + (x y : NormalizedSpin N) : + 2 * bulkB N M f a x y ≤ bulkB N M f a x x + bulkB N M f a y y := by + let u j := f.d1 (∑ i, a j i * x.val i) + let v j := f.d1 (∑ i, a j i * y.val i) + have h : ∑ j, (2 * (u j * v j)) ≤ ∑ j, (u j * u j + v j * v j) := by + apply Finset.sum_le_sum + intro j _ + nlinarith [sq_nonneg (u j - v j)] + have hh := mul_le_mul_of_nonneg_left h (by positivity : (0:ℝ) ≤ (N:ℝ)⁻¹) + simpa only [Finset.mul_sum,Finset.sum_add_distrib,mul_add,mul_assoc,mul_left_comm, + u,v,bulkB] using hh + +lemma bulkMarkedArray_closed_full (n M : ℕ) (f : Jet3) (v : ℕ → ℝ) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2 ≤ K) {F : Set (CompactArray (BulkPairRange K))} + (hF : IsClosed F) + (hfull : ∀ a : BulkDisorder (n+1) M, ∀ x : ℕ → NormalizedSpin (n+1), + bulkMarkedArray n M f K hK (a,x) ∈ F) : + bulkMarkedArrayLaw n M f v K hK F = 1 := by + have hp : bulkMarkedArray n M f K hK ⁻¹' F = univ := by + ext a + simp only [mem_preimage,mem_univ,iff_true] + exact hfull a.1 a.2 + apply ENNReal.coe_injective + rw [ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure] + change (Measure.map (bulkMarkedArray n M f K hK) _) F = 1 + rw [Measure.map_apply (bulkMarkedArray_measurable _ _ _ _ _) hF.measurableSet,hp] + exact measure_univ + +theorem bulkMarkedArray_limit_mark_geometry (M : ℕ → ℕ) (f : Jet3) (v : ℕ → ℕ → ℝ) + (s : ℕ → ℕ) (K : ℝ) (hK : ∀ n, (M (s n):ℝ)/(s n+1:ℕ)*‖f.d1‖^2 ≤ K) + {μ : ProbabilityMeasure (CompactArray (BulkPairRange K))} + (hlim : Tendsto (fun n => bulkMarkedArrayLaw (s n) (M (s n)) f (v (s n)) K (hK n)) atTop (𝓝 μ)) : + (∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i, 0 ≤ (Q i i).2.val) ∧ + (∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i j, + 2*(Q i j).2.val ≤ (Q i i).2.val + (Q j j).2.val) := by + constructor + · apply ae_all_iff.mpr + intro i + have hc : IsClosed {Q : CompactArray (BulkPairRange K) | 0 ≤ (Q i i).2.val} := + isClosed_le continuous_const (by fun_prop) + apply (mem_ae_iff_prob_eq_one hc.measurableSet).mpr + have h := weak_limit_closed_full hlim hc (fun n => bulkMarkedArray_closed_full + (s n) (M (s n)) f (v (s n)) K (hK n) hc + (fun _disorder _spins => bulkB_diagonal_nonneg _ _ _ _ _)) + simp only [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,h,ENNReal.coe_one] + · apply ae_all_iff.mpr + intro i + apply ae_all_iff.mpr + intro j + have hc : IsClosed {Q : CompactArray (BulkPairRange K) | + 2*(Q i j).2.val ≤ (Q i i).2.val + (Q j j).2.val} := isClosed_le (by fun_prop) (by fun_prop) + apply (mem_ae_iff_prob_eq_one hc.measurableSet).mpr + have h := weak_limit_closed_full hlim hc (fun n => bulkMarkedArray_closed_full + (s n) (M (s n)) f (v (s n)) K (hK n) hc + (fun _disorder _spins => bulkB_add_diagonal_bound _ _ _ _ _ _)) + simp only [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,h,ENNReal.coe_one] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityAnnealedUncap.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityAnnealedUncap.lean new file mode 100644 index 0000000000000000000000000000000000000000..ab3ff6c080da80c0e7f6bc651d5034194062e009 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityAnnealedUncap.lean @@ -0,0 +1,101 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityMeanCap + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_comp_partition_unbounded_measurable {A S J E : Type*} + [MeasurableSpace A] [MeasurableSpace S] [Fintype J] [DecidableEq J] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (μ : Measure S) [SFinite μ] + (v : A→S→J→E) (hv : Measurable (Function.uncurry v)) + (H C : A→S→ℝ) (hH : Measurable (Function.uncurry H)) + (hC : Measurable (Function.uncurry C)) (t : ℝ) (Ψ : EuclideanSpace ℝ J→ℝ) + (hΨ : Measurable Ψ) : + Measurable (fun p : A×E=>tiltMean μ (H p.1) + (fun x=>Real.exp (t*C p.1 x)*Ψ (gaussianRows (v p.1 x) p.2)) 1) := by + let κ : Kernel (A×E) S := Kernel.const _ μ + have hproj : Measurable (fun p : (A×E)×S=>(p.1.1,p.2)) := + measurable_fst.fst.prodMk measurable_snd + apply kernel_tiltMean_measurable κ (H := fun p x=>H p.1 x) + (Y := fun p x=>Real.exp (t*C p.1 x)*Ψ (gaussianRows (v p.1 x) p.2)) (hH.comp hproj) + exact ((hC.comp hproj).const_mul t).exp.mul + (hΨ.comp (cavity_rows_joint_measurable (hv.comp hproj) measurable_fst.snd)) + +lemma cavityFullSingleTest_measurable (n d : ℕ) (f : ℝ→ᵇℝ) : + Measurable (fun z : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)=> + Real.exp (∑ t,f (z (Sum.inr t)))* + sphericalExp n (WithLp.toLp 2 (fun i=>z (Sum.inl i))) (Real.sqrt (n+1:ℕ))) := by + apply Measurable.mul (by fun_prop) + apply (sphericalExp_continuous n _).measurable.comp + fun_prop + +lemma cavityBulkFullCompPartition_measurable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) : + Measurable (cavityBulkFullCompPartition n d m M f v) := by + have h:=cavity_comp_partition_unbounded_measurable (unitSphereLaw (m+1)) + (cavityBulkFeature n d m M f) (cavityBulkFeature_measurable n d m M f) + (bulkGibbsHamiltonian m M f.f v) (fun a x=>bulkC (m+1) M f a.1 x) + (bulkGibbsHamiltonian_measurable m M f.f v) (bulkC_measurable m M f) ((n+1:ℕ)/2) + _ (cavityFullSingleTest_measurable n d f.f) + convert h using 1 + funext p + unfold cavityBulkFullCompPartition + congr 1 + funext x + simp only [Real.exp_add,gaussianRows_apply] + rw [mul_assoc] + rfl + +def cavityBulkUncapError (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : ℝ := + Real.log (cavityBulkFullCompPartition n d m M f v p)- + Real.log (cavityBulkCompPartition n d m M f v Λ hΛ p) + +lemma cavityBulkUncapError_measurable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) : Measurable (cavityBulkUncapError n d m M f v Λ hΛ) := + (cavityBulkFullCompPartition_measurable n d m M f v).log.sub + (cavityBulkCompPartition_measurable n d m M f v Λ hΛ).log + +theorem cavityBulk_uncap_annealed (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (K KC : ℝ) + (hK : M/(m+1:ℕ)*‖f.d1‖^2≤K) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤KC) : + let D:=cavityBulkUncapError n d m M f v Λ hΛ + let P:=(bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))) + Integrable D P ∧ 0≤∫ p,D p ∂P ∧ (∫ p,D p ∂P)≤ + Real.exp (2*((n+1:ℕ)/2*KC+(d:ℝ)*‖f.f‖)+2*(n+1:ℕ)*K)/Λ := by + let D:=cavityBulkUncapError n d m M f v Λ hΛ + let E:=EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M) + let B:=Real.exp (2*((n+1:ℕ)/2*KC+(d:ℝ)*‖f.f‖)+2*(n+1:ℕ)*K)/Λ + have hsec a:=cavityBulk_unclipped_cap n d m M f v Λ hΛ K KC hK hC a + have hD : Measurable D:=cavityBulkUncapError_measurable n d m M f v Λ hΛ + have hnorm a : (∫ y,‖D (a,y)‖ ∂stdGaussian E)=∫ y,D (a,y) ∂stdGaussian E := by + apply integral_congr_ae + exact ae_of_all _ fun y=>by + change ‖D (a,y)‖=D (a,y) + exact Real.norm_of_nonneg ((hsec a).2.1 y) + have hi : Integrable D ((bulkDisorderLaw (m+1) M).prod (stdGaussian E)) := by + apply (integrable_prod_iff hD.aestronglyMeasurable).mpr + constructor + · exact ae_of_all _ fun a=>(hsec a).1 + · apply Integrable.of_bound (hD.norm.stronglyMeasurable.integral_prod_right).aestronglyMeasurable B + filter_upwards [] with a + rw [hnorm,Real.norm_eq_abs] + have hp : 0≤∫ y,D (a,y) ∂stdGaussian E := (hsec a).2.2.1 + rw [abs_of_nonneg hp] + exact (hsec a).2.2.2 + refine ⟨hi,integral_nonneg (fun p=>(hsec p.1).2.1 p.2),?_⟩ + rw [integral_prod _ hi] + calc + _≤∫ _ : BulkDisorder (m+1) M,B ∂bulkDisorderLaw (m+1) M := + integral_mono hi.integral_prod_left (integrable_const B) (fun a=>(hsec a).2.2.2) + _=B := by simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityApproxStationary.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityApproxStationary.lean new file mode 100644 index 0000000000000000000000000000000000000000..8e36c41a98b1145721eaf7ca01e49337fb1ec41b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityApproxStationary.lean @@ -0,0 +1,87 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CoupledDual + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators NNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma finiteSphericalDual_approx_stationary {k : ℕ} (w h g : Fin (k+1)→ℝ) + (q : Fin (k+1)→Time) (hw : ∀ i,0(q j:ℝ)) (q i)) + {δ : ℝ} (_hδ : 0≤δ) (hd : ∀ i,|h i-g i|≤δ) : + (entropy (weightedStepTrial w q (fun i=>(hw i).le) hw1)).toReal- + (∑ i,w i*h i*(q i:ℝ))-2*δ ≤ + sInf (finiteSphericalDualValues w h (fun i=>(hw i).le) hw1) := by + have hsum : (∑ i,w i*|h i-g i|)≤δ := by + calc + _≤∑ i,w i*δ:=Finset.sum_le_sum fun i _=>mul_le_mul_of_nonneg_left (hd i) (hw i).le + _=δ:=by rw [←Finset.sum_mul,hw1,one_mul] + have hD:=finiteSphericalDual_abs_sub_le w h g hw hw1 hh hh0 hg hg0 + rw [finiteSphericalDual_eq_stationary w g q (fun i=>(hw i).le) hw1 hq hq1 hs] at hD + unfold finiteSphericalDualObjective at hD + have hterm : (∑ i,w i*g i*(q i:ℝ))-(∑ i,w i*h i*(q i:ℝ))≤δ := by + calc + _=∑ i,w i*((g i-h i)*(q i:ℝ)):=by rw [←Finset.sum_sub_distrib]; apply Finset.sum_congr rfl; intro i _; ring + _≤∑ i,w i*|h i-g i|:=by + apply Finset.sum_le_sum + intro i _ + apply mul_le_mul_of_nonneg_left _ (hw i).le + calc + (g i-h i)*(q i:ℝ)≤|g i-h i| *(q i:ℝ):=mul_le_mul_of_nonneg_right (le_abs_self _) (q i).prop.1 + _≤|g i-h i| *1:=mul_le_mul_of_nonneg_left (q i).prop.2 (abs_nonneg _) + _=|h i-g i|:=by rw [mul_one,abs_sub_comm] + _≤δ:=hsum + linarith [(abs_le.mp (hD.trans hsum)).1] + + +lemma terminalVariational_le_trial (P : Measure BrownianPath) [IsProbabilityMeasure P] + {α : ℝ} (hα : 0≤α) (f : ℝ→ᵇℝ) (m : Trial) (hm : entropy m≠⊤) : + (terminalVariational P α f).toReal ≤ α*controlValue P f m+(entropy m).toReal := by + apply EReal.coe_le_coe_iff.mp + rw [terminalVariational_coe_toReal P α hα f,EReal.coe_add, + EReal.coe_ennreal_toReal hm] + exact iInf_le _ m + +lemma finiteCavity_trial_lower (P : Measure BrownianPath) [IsProbabilityMeasure P] + {α : ℝ} (hα : 0≤α) (f : ℝ→ᵇℝ) (n d : ℕ) {k : ℕ} + (w h g : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i,0(q j:ℝ)) (q i)) + {δ ε a : ℝ} (hδ : 0≤δ) (hd : ∀ i,|h i-g i|≤δ) + (hdim : |finiteSphericalFieldValue n k w h- + sInf (finiteSphericalDualValues w h (fun i=>(hw i).le) hw1)|<ε) + (hdα : |(d:ℝ)-(n+1:ℕ)*α|≤1) : + (n+1:ℕ)*(a/2+(terminalVariational P α f).toReal- + (∑ i,w i*h i*(q i:ℝ))-2*δ-ε)-‖f‖ ≤ + (n+1:ℕ)*(a/2+finiteSphericalFieldValue n k w h)+ + d*controlValue P f (weightedStepTrial w q (fun i=>(hw i).le) hw1) := by + let m:=weightedStepTrial w q (fun i=>(hw i).le) hw1 + have hm : entropy m≠⊤ := by + rw [entropy_weightedStepTrial w q (fun i=>(hw i).le) hw1 (q (Fin.last k)) + (q (Fin.last k)).prop.1 hq1 (fun i=>hq (Fin.le_last i))] + exact ENNReal.ofReal_ne_top + have hv:=terminalVariational_le_trial P hα f m hm + have hstat:=finiteSphericalDual_approx_stationary w h g q hw hw1 hh hh0 hg hg0 hq hq1 hs hδ hd + have hcv : |controlValue P f m|≤‖f‖ := + abs_le.mpr ⟨neg_norm_le_controlValue P f m,controlValue_le_norm P f m⟩ + have he : |((d:ℝ)-(n+1:ℕ)*α)*controlValue P f m|≤‖f‖ := by + rw [abs_mul] + exact (mul_le_mul hdα hcv (abs_nonneg _) (by norm_num)).trans_eq (one_mul _) + have hL : (0:ℝ)≤(n+1:ℕ):=by positivity + have hlo := mul_le_mul_of_nonneg_left (le_of_lt (abs_lt.mp hdim).1) hL + have hslo := mul_le_mul_of_nonneg_left hstat hL + have hvlo := mul_le_mul_of_nonneg_left hv hL + dsimp only [m] at hvlo he + nlinarith [(abs_le.mp he).1] +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityBlockProduct.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityBlockProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..39dbfc2aebb88c538030b4d130bd6c5a0ba4a33b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityBlockProduct.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityShellLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology ENNReal NNReal +namespace SphericalPerceptronFreeEnergy + +def cavityRadialUnit (_n L : ℕ) (p : Ioi (0:ℝ)×Spin L) : Spin L := + (Real.sqrt (p.1.val^2+‖p.2‖^2))⁻¹ •p.2 + +lemma cavityRadialUnit_measurable (n L : ℕ) : Measurable (cavityRadialUnit n L) := by + unfold cavityRadialUnit + fun_prop + +def cavityUnitEmbed (n L : ℕ) (p : Metric.sphere (0:Spin (n+1)) 1×Spin L) : Spin (n+1)×Spin L := + (Real.sqrt (1-‖p.2‖^2) •p.1.val,p.2) + +lemma cavityUnitEmbed_measurable (n L : ℕ) : Measurable (cavityUnitEmbed n L) := by + unfold cavityUnitEmbed + fun_prop + +lemma cavity_radial_rho {r b : ℝ} (hr : 0(p.1.2,(p.1.1,p.2))) + (((gaussianRadiusLaw n).prod (unitSphereLaw (n+1))).prod (stdGaussian (Spin L))) + ((unitSphereLaw (n+1)).prod ((gaussianRadiusLaw n).prod (stdGaussian (Spin L)))) := + by + let : IsProbabilityMeasure (unitSphereLaw (n+1)) := inferInstance + have hs : MeasurePreserving (Prod.swap : Ioi (0:ℝ)×Metric.sphere (0:Spin (n+1)) 1 → + Metric.sphere (0:Spin (n+1)) 1×Ioi (0:ℝ)) + ((gaussianRadiusLaw n).prod (unitSphereLaw (n+1))) + ((unitSphereLaw (n+1)).prod (gaussianRadiusLaw n)) := Measure.measurePreserving_swap + exact (measurePreserving_prodAssoc (unitSphereLaw (n+1)) (gaussianRadiusLaw n) (stdGaussian (Spin L))).comp + (hs.prod (MeasurePreserving.id (stdGaussian (Spin L)))) + +def cavityUnitLaw (n L : ℕ) : ProbabilityMeasure (Spin L) := + ⟨((gaussianRadiusLaw n).prod (stdGaussian (Spin L))).map (cavityRadialUnit n L), + inferInstance⟩ + +lemma cavityUnitPair_preserving (n L : ℕ) : + MeasurePreserving (fun p : (Ioi (0:ℝ)×Metric.sphere (0:Spin (n+1)) 1)×Spin L=> + (p.1.2,cavityRadialUnit n L (p.1.1,p.2))) + (((gaussianRadiusLaw n).prod (unitSphereLaw (n+1))).prod (stdGaussian (Spin L))) + ((unitSphereLaw (n+1)).prod (cavityUnitLaw n L)) := + by + have h1 := MeasurePreserving.id (unitSphereLaw (n+1)) + have h2 : MeasurePreserving (cavityRadialUnit n L) + ((gaussianRadiusLaw n).prod (stdGaussian (Spin L))) (cavityUnitLaw n L) := + ⟨cavityRadialUnit_measurable n L,rfl⟩ + exact (h1.prod h2).comp (cavityRadial_reorder_preserving n L) + +theorem sphereBlock_product_law (n L : ℕ) : + (unitSphereLaw (n+1+L)).map (fun u=>gaussianBlockSplit (n+1) L u.val)= + ((unitSphereLaw (n+1)).prod (cavityUnitLaw n L)).map (cavityUnitEmbed n L) := by + rw [sphereBlock_radial_law,←(cavityUnitPair_preserving n L).map_eq, + Measure.map_map (cavityUnitEmbed_measurable n L) (cavityUnitPair_preserving n L).measurable] + congr 1 + funext p + exact cavityRadialBlock_unitEmbed n L p + +lemma cavityUnitLaw_actual (n L : ℕ) : + (cavityUnitLaw n L : Measure (Spin L))= + (unitSphereLaw (n+1+L)).map (fun u=>(gaussianBlockSplit (n+1) L u.val).2) := by + have he:=congrArg (fun μ : Measure (Spin (n+1)×Spin L)=>μ.map Prod.snd) (sphereBlock_product_law n L) + have hm : Measurable (fun u : Metric.sphere (0:Spin (n+1+L)) 1=>gaussianBlockSplit (n+1) L u.val) := + (gaussianBlockSplit_measurable (n+1) L).comp measurable_subtype_coe + rw [Measure.map_map measurable_snd hm, + Measure.map_map measurable_snd (cavityUnitEmbed_measurable n L)] at he + change _=((unitSphereLaw (n+1)).prod (cavityUnitLaw n L : Measure (Spin L))).map Prod.snd at he + rw [Measure.map_snd_prod,measure_univ,one_smul] at he + exact he.symm + +lemma cavitySphereLaw_unit (n L : ℕ) : + (cavitySphereLaw n L : Measure (Spin L))= + (cavityUnitLaw n L : Measure (Spin L)).map (fun z=>Real.sqrt (n+1+L:ℕ) •z) := by + have hm : Measurable (fun u : Metric.sphere (0:Spin (n+1+L)) 1 => + (gaussianBlockSplit (n+1) L u.val).2) := + (((gaussianBlockSplit_measurable (n+1) L).comp measurable_subtype_coe).snd) + rw [cavityUnitLaw_actual,Measure.map_map (by fun_prop) hm] + rfl + +def cavitySphereBlockEmbed (n L : ℕ) (p : Metric.sphere (0:Spin (n+1)) 1×Spin L) : Spin (n+1)×Spin L := + cavityUnitEmbed n L (p.1,(Real.sqrt (n+1+L:ℕ))⁻¹ •p.2) + +lemma cavitySphereBlockEmbed_measurable (n L : ℕ) : Measurable (cavitySphereBlockEmbed n L) := by + unfold cavitySphereBlockEmbed + apply (cavityUnitEmbed_measurable n L).comp + fun_prop + +lemma cavitySphereBlockEmbed_scaled (n L : ℕ) (x : Metric.sphere (0:Spin (n+1)) 1) (z : Spin L) : + cavitySphereBlockEmbed n L (x,Real.sqrt (n+1+L:ℕ) •z)=cavityUnitEmbed n L (x,z) := by + have hp : 0gaussianBlockSplit (n+1) L u.val)= + ((unitSphereLaw (n+1)).prod (cavitySphereLaw n L)).map (cavitySphereBlockEmbed n L) := by + have hs : MeasurePreserving (fun z : Spin L=>Real.sqrt (n+1+L:ℕ) •z) + (cavityUnitLaw n L) (cavitySphereLaw n L) := + ⟨by fun_prop,(cavitySphereLaw_unit n L).symm⟩ + let : IsProbabilityMeasure (unitSphereLaw (n+1)) := inferInstance + have hp : MeasurePreserving (fun p : Metric.sphere (0:Spin (n+1)) 1×Spin L => + (p.1,Real.sqrt (n+1+L:ℕ) •p.2)) + ((unitSphereLaw (n+1)).prod (cavityUnitLaw n L : Measure (Spin L))) + ((unitSphereLaw (n+1)).prod (cavitySphereLaw n L : Measure (Spin L))) := + (MeasurePreserving.id (unitSphereLaw (n+1))).prod hs + rw [sphereBlock_product_law,←hp.map_eq, + Measure.map_map (cavitySphereBlockEmbed_measurable n L) hp.measurable] + congr 1 + funext p + exact (cavitySphereBlockEmbed_scaled n L p.1 p.2).symm + +lemma cavityRadialUnit_norm_lt (n L : ℕ) (p : Ioi (0:ℝ)×Spin L) : + ‖cavityRadialUnit n L p‖^2<1 := by + have hr : 0expectedPressure α 1 f (n+1)) atTop + (𝓝 (terminalVariational P α f).toReal) := by + obtain ⟨g,gs,gn,gl,gc⟩:=exists_smooth_lower_sequence f + obtain ⟨h,hs,hn,hl,hc⟩:=exists_smooth_upper_sequence f + have gV:=controlValue_uniform_of_compact P hB f (fun n=>(g n).f) (‖f‖+1) + (by positivity) (by linarith) gn gc + have hV:=controlValue_uniform_of_compact P hB f (fun n=>(h n).f) (‖f‖+1) + (by positivity) (by linarith) hn hc + apply Metric.tendsto_nhds.2 + intro ε hε + have hδ : 0<ε/(4*α):=by positivity + obtain ⟨G,hG⟩:=gV _ hδ + obtain ⟨H,hH⟩:=hV _ hδ + have hGV:=terminalVariational_abs_sub_le P α hα.le (g G).f f (ε/(4*α)) + (fun m=>(hG G le_rfl m).le) + have hHV:=terminalVariational_abs_sub_le P α hα.le (h H).f f (ε/(4*α)) + (fun m=>(hH H le_rfl m).le) + have he : α*(ε/(4*α))=ε/4 := by field_simp + rw [he] at hGV hHV + have hg:=expectedPressure_limit_smooth P hB hα (g G) (gs G).1 (gs G).2.1 (gs G).2.2 + have hh:=expectedPressure_limit_smooth P hB hα (h H) (hs H).1 (hs H).2.1 (hs H).2.2 + filter_upwards [Metric.tendsto_nhds.1 hg (ε/4) (by positivity), + Metric.tendsto_nhds.1 hh (ε/4) (by positivity)] with n hgn hhn + have hlo:=expectedPressure_mono_terminal α (g G).f f (gl G) n + have hhi:=expectedPressure_mono_terminal α f (h H).f (hl H) n + rw [Real.dist_eq] at hgn hhn ⊢ + rcases abs_le.mp hGV with ⟨glo,ghi⟩ + rcases abs_le.mp hHV with ⟨hlo',hhi'⟩ + rcases abs_lt.mp hgn with ⟨gln,ghn⟩ + rcases abs_lt.mp hhn with ⟨hln,hhn⟩ + exact abs_lt.mpr ⟨by linarith,by linarith⟩ +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityBulkCoefficients.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityBulkCoefficients.lean new file mode 100644 index 0000000000000000000000000000000000000000..e261fbe6421b52d15146bbdf3b846e5ff75dbc23 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityBulkCoefficients.lean @@ -0,0 +1,207 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityGaussianReplica + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction + +abbrev CavityBulkNoiseIndex (n d m M : ℕ) := + (Fin (n+1) ⊕ Fin d) × (Fin M ⊕ Fin (m+1)) + +def cavityBulkBase (n d m M : ℕ) (f : Jet3) (a : BulkDisorder (m+1) M) + (x : NormalizedSpin (m+1)) (j : Fin (n+1)⊕Fin d) (k : Fin M⊕Fin (m+1)) : ℝ := + match j,k with + | Sum.inl _,Sum.inl t => (Real.sqrt (m+1:ℕ))⁻¹*f.d1 (inner ℝ x.val (WithLp.toLp 2 (a.1 t))) + | Sum.inr _,Sum.inr t => x.val t + | _,_ => 0 + +def cavityBulkFeature (n d m M : ℕ) (f : Jet3) (a : BulkDisorder (m+1) M) + (x : NormalizedSpin (m+1)) (j : Fin (n+1)⊕Fin d) : + EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M) := + WithLp.toLp 2 (fun p=>if p.1=j then cavityBulkBase n d m M f a x j p.2 else 0) + +lemma cavityBulkFeature_measurable (n d m M : ℕ) (f : Jet3) : + Measurable (fun p : BulkDisorder (m+1) M×NormalizedSpin (m+1)=> + cavityBulkFeature n d m M f p.1 p.2) := by + apply Measurable.of_eval + intro j + unfold cavityBulkFeature + apply (MeasurableEquiv.toLp 2 (CavityBulkNoiseIndex n d m M→ℝ)).measurable.comp + apply Measurable.of_eval + intro p + split_ifs + · cases j <;> cases p.2 <;> dsimp [cavityBulkBase] <;> fun_prop + · exact measurable_const + +lemma cavityBulkFeature_inner (n d m M : ℕ) (f : Jet3) (a : BulkDisorder (m+1) M) + (x y : NormalizedSpin (m+1)) (j k : Fin (n+1)⊕Fin d) : + inner ℝ (cavityBulkFeature n d m M f a x j) (cavityBulkFeature n d m M f a y k)= + if j=k then Sum.elim (fun _=>bulkB (m+1) M f a.1 x y) + (fun _=>inner ℝ x.val y.val) j else 0 := by + classical + rw [EuclideanSpace.inner_eq_star_dotProduct] + simp only [dotProduct,star_trivial,cavityBulkFeature] + rw [Fintype.sum_prod_type] + by_cases hjk : j=k + · subst k + simp only [ite_true] + have he (p : Fin (n+1)⊕Fin d) : + (∑ t : Fin M⊕Fin (m+1), + (if p=j then cavityBulkBase n d m M f a y j t else 0)* + (if p=j then cavityBulkBase n d m M f a x j t else 0))= + if p=j then ∑ t : Fin M⊕Fin (m+1), + cavityBulkBase n d m M f a y j t*cavityBulkBase n d m M f a x j t else 0 := by + split_ifs <;> simp_all + simp_rw [he] + rw [Finset.sum_ite_eq'] + simp only [Finset.mem_univ,ite_true] + cases j with + | inl _index => + simp only [Fintype.sum_sum_type,cavityBulkBase,Sum.elim_inl,mul_zero,Finset.sum_const_zero,add_zero] + unfold bulkB + rw [Finset.mul_sum] + simp only [EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial] + apply Finset.sum_congr rfl + intro i _hi + have hn : (0:ℝ)<(m+1:ℕ) := by positivity + have hs : Real.sqrt ((m+1:ℕ):ℝ)^2=(m+1:ℕ) := Real.sq_sqrt hn.le + have hp : Real.sqrt ((m+1:ℕ):ℝ)≠0 := ne_of_gt (Real.sqrt_pos.mpr hn) + field_simp + rw [hs] + ring + | inr _index => + simp only [Fintype.sum_sum_type,cavityBulkBase,Sum.elim_inr,mul_zero,Finset.sum_const_zero,zero_add] + rw [EuclideanSpace.inner_eq_star_dotProduct] + rfl + · rw [ite_eq_right hjk] + apply Finset.sum_eq_zero + intro p _hp + apply Finset.sum_eq_zero + intro t _ht + by_cases hpj : p=j + · subst p + simp [hjk] + · simp [hpj] + +lemma cavityBulkFeature_gram (n d r m M : ℕ) (f : Jet3) (a : BulkDisorder (m+1) M) + (x : Fin r→NormalizedSpin (m+1)) (K : ℝ) (hK : M/(m+1:ℕ)*‖f.d1‖^2≤K) : + Matrix.gram ℝ (fun p : CavityReplicaIndex n d r=>cavityBulkFeature n d m M f a (x p.2) p.1)= + fun i j=> if i.1=j.1 then + Sum.elim (fun _=>(bulkMarkedEntry m M f K hK a (x i.2) (x j.2)).2.val) + (fun _=>(bulkMarkedEntry m M f K hK a (x i.2) (x j.2)).1.val) i.1 else 0 := by + ext i j + exact cavityBulkFeature_inner n d m M f a (x i.2) (x j.2) i.1 j.1 + +lemma cavity_gibbs_moment {S J E : Type*} [MeasurableSpace S] + [Fintype J] [DecidableEq J] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (μ : Measure S) [IsProbabilityMeasure μ] + (v : S→J→E) (hv : Measurable v) (H : S→ℝ) (hH : Measurable H) + (he : Integrable (fun x=>Real.exp (H x)) μ) (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) : + (∫ y,(tiltMean μ H (fun x=>Ψ (gaussianRows (v x) y)) 1)^r ∂stdGaussian E)= + gibbsReplicaMean μ H r (fun xs=>cavityMatrixKernel (cavityTestReplica Ψ r) + (Matrix.gram ℝ (fun p : J×Fin r=>v (xs p.2) p.1))) := by + have he1 : Integrable (fun x=>Real.exp (1*H x)) μ := by simpa only [one_mul] using he + let := tilt_law_probability_of_integrable μ he1 + simp_rw [←tilt_law_integral_of_integrable μ hH he1] + rw [gibbsReplicaMean_integral_of_integrable μ hH he] + simpa only [Real.exp_zero,one_mul,Finset.prod_const_one] using + cavity_marked_moment (tiltLaw μ H 1) v hv (fun _=>0) measurable_const + (C:=0) (fun _=>by simp) Ψ r + +def cavityBulkPartition (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : ℝ := + tiltMean (unitSphereLaw (m+1)) (bulkGibbsHamiltonian m M f.f v p.1) + (fun x=>cavitySingleTest n d f.f Λ hΛ (gaussianRows (cavityBulkFeature n d m M f p.1 x) p.2)) 1 + +lemma cavity_rows_joint_measurable {A J E : Type*} [MeasurableSpace A] + [Fintype J] [DecidableEq J] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] {v : A→J→E} {y : A→E} + (hv : Measurable v) (hy : Measurable y) : + Measurable (fun a=>gaussianRows (v a) (y a)) := by + change Measurable (fun a=>WithLp.toLp 2 (fun j=>inner ℝ (v a j) (y a))) + apply (MeasurableEquiv.toLp 2 (J→ℝ)).measurable.comp + apply Measurable.of_eval + intro j + exact ((measurable_pi_apply j).comp hv).inner hy + +lemma cavity_partition_joint_measurable {A S J E : Type*} + [MeasurableSpace A] [MeasurableSpace S] [Fintype J] [DecidableEq J] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (μ : Measure S) [SFinite μ] + (v : A→S→J→E) (hv : Measurable (Function.uncurry v)) + (H : A→S→ℝ) (hH : Measurable (Function.uncurry H)) (Ψ : EuclideanSpace ℝ J→ᵇℝ) : + Measurable (fun p : A×E=>tiltMean μ (H p.1) + (fun x=>Ψ (gaussianRows (v p.1 x) p.2)) 1) := by + let κ : Kernel (A×E) S := Kernel.const _ μ + have hproj : Measurable (fun p : (A×E)×S=>(p.1.1,p.2)) := + measurable_fst.fst.prodMk measurable_snd + apply kernel_tiltMean_measurable κ (H:=fun p x=>H p.1 x) + (Y:=fun p x=>Ψ (gaussianRows (v p.1 x) p.2)) (hH.comp hproj) + exact Ψ.measurable.comp (cavity_rows_joint_measurable (hv.comp hproj) measurable_fst.snd) + +lemma cavityBulkPartition_measurable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) : Measurable (cavityBulkPartition n d m M f v Λ hΛ) := by + exact cavity_partition_joint_measurable (unitSphereLaw (m+1)) + (cavityBulkFeature n d m M f) (cavityBulkFeature_measurable n d m M f) + (bulkGibbsHamiltonian m M f.f v) (bulkGibbsHamiltonian_measurable m M f.f v) + (cavitySingleTest n d f.f Λ hΛ) + +def cavityBulkMoment (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) (r : ℕ) : ℝ := + ∫ a,∫ y,(cavityBulkPartition n d m M f v Λ hΛ (a,y))^r + ∂stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) ∂bulkDisorderLaw (m+1) M + +lemma cavityBulkMoment_array (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (K : ℝ) (hK : M/(m+1:ℕ)*‖f.d1‖^2≤K) (r : ℕ) : + cavityBulkMoment n d m M f v Λ hΛ r= + ∫ Q,cavityArrayKernel n d r f.f Λ hΛ K Q ∂bulkMarkedArrayLaw m M f v K hK := by + let F : CompactBlock (BulkPairRange K) r→ᵇℝ := + (cavityMatrixKernel (cavityReplicaTest n d r f.f Λ hΛ)).compContinuous + ⟨fun Q=>fun i j : CavityReplicaIndex n d r=>if i.1=j.1 then + Sum.elim (fun _=>(Q i.2 j.2).2.val) (fun _=>(Q i.2 j.2).1.val) i.1 else 0,by + apply continuous_pi + intro i + apply continuous_pi + intro j + split_ifs + · cases i.1 <;> dsimp only [Sum.elim] <;> fun_prop + · exact continuous_const⟩ + have hb := bulkMarkedArray_block m M f v K hK r F + change (∫ Q,cavityArrayKernel n d r f.f Λ hΛ K Q ∂bulkMarkedArrayLaw m M f v K hK)=_ at hb + rw [hb] + unfold cavityBulkMoment bulkReplicaMean + apply integral_congr_ae + filter_upwards [] with a + have he := bulkHamiltonian_exp_integrable m M f.f v a + have hv : Measurable (cavityBulkFeature n d m M f a) := + (cavityBulkFeature_measurable n d m M f).of_uncurry_left + rw [show (∫ y,cavityBulkPartition n d m M f v Λ hΛ (a,y)^r ∂stdGaussian _)= + gibbsReplicaMean (unitSphereLaw (m+1)) (bulkGibbsHamiltonian m M f.f v a) r + (fun xs=>cavityMatrixKernel (cavityTestReplica (cavitySingleTest n d f.f Λ hΛ) r) + (Matrix.gram ℝ (fun p : (Fin (n+1)⊕Fin d)×Fin r=> + cavityBulkFeature n d m M f a (xs p.2) p.1))) from + cavity_gibbs_moment _ _ hv _ (bulkGibbsHamiltonian_measurable m M f.f v).of_uncurry_left he _ r] + rw [cavitySingleTest_replica] + apply congrArg (gibbsReplicaMean _ _ r) + funext xs + rw [cavityBulkFeature_gram n d r m M f a xs K hK] + rfl + +theorem cavityBulkMoment_tendsto (n d : ℕ) (M : ℕ→ℕ) (f : Jet3) (v : ℕ→ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (K : ℝ) (hK : ∀ m,M m/(m+1:ℕ)*‖f.d1‖^2≤K) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray (BulkPairRange K))} + (hlim : Tendsto (fun j=>bulkMarkedArrayLaw (s j) (M (s j)) f (v (s j)) K (hK (s j))) atTop (𝓝 ν)) + (r : ℕ) : + Tendsto (fun j=>cavityBulkMoment n d (s j) (M (s j)) f (v (s j)) Λ hΛ r) atTop + (𝓝 (∫ Q,cavityArrayKernel n d r f.f Λ hΛ K Q ∂ν)) := by + simp_rw [cavityBulkMoment_array n d _ _ f _ Λ hΛ K (hK _)] + exact cavityArrayKernel_tendsto n d r f.f Λ hΛ K hlim + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityBulkLog.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityBulkLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ff1c5ce51cbb7743ebf026663d90b6d05e7e5fb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityBulkLog.lean @@ -0,0 +1,221 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityBulkCoefficients + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction + +lemma cavitySingleTest_bounds (n d : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (z : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + Real.exp (-(d:ℝ)*‖f‖)≤cavitySingleTest n d f Λ hΛ z ∧ + cavitySingleTest n d f Λ hΛ z≤Λ*Real.exp ((d:ℝ)*‖f‖) := by + rw [cavitySingleTest_apply,←Real.exp_sum] + have hs : |∑ t : Fin d,f (z (Sum.inr t))|≤(d:ℝ)*‖f‖ := by + calc + _≤∑ t : Fin d,|f (z (Sum.inr t))| := Finset.abs_sum_le_sum_abs _ _ + _≤∑ _ : Fin d,‖f‖ := Finset.sum_le_sum fun t ht=>f.norm_coe_le_norm _ + _=_ := by simp + have hF := le_min (one_le_sphericalExp n (WithLp.toLp 2 (fun i=>z (Sum.inl i))) + (Real.sqrt (n+1:ℕ))) hΛ + constructor + · calc + _≤Real.exp (∑ t : Fin d,f (z (Sum.inr t))) := Real.exp_le_exp.mpr (by linarith [(abs_le.mp hs).1]) + _≤_ := by nlinarith [Real.exp_pos (∑ t : Fin d,f (z (Sum.inr t)))] + · exact mul_le_mul (min_le_right _ _) (Real.exp_le_exp.mpr (abs_le.mp hs).2) + (Real.exp_pos _).le ((by norm_num : (0:ℝ)≤1).trans hΛ) + +abbrev CavityPartitionRange (d : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) := + Icc (Real.exp (-(d:ℝ)*‖f‖)) (Λ*Real.exp ((d:ℝ)*‖f‖)) + +lemma cavityBulkPartition_mem (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : + cavityBulkPartition n d m M f v Λ hΛ p∈CavityPartitionRange d f.f Λ := by + let H:=bulkGibbsHamiltonian m M f.f v p.1 + have hmH : Measurable H := (bulkGibbsHamiltonian_measurable m M f.f v).of_uncurry_left + have he : Integrable (fun x=>Real.exp (1*H x)) (unitSphereLaw (m+1)) := by + simpa only [one_mul,H,bulkGibbsHamiltonian] using bulkHamiltonian_exp_integrable m M f.f v p.1 + let := tilt_law_probability_of_integrable (unitSphereLaw (m+1)) he + let μ:=tiltLaw (unitSphereLaw (m+1)) H 1 + have hv : Measurable (cavityBulkFeature n d m M f p.1) := + (cavityBulkFeature_measurable n d m M f).of_uncurry_left + have hm : Measurable (fun x=>cavitySingleTest n d f.f Λ hΛ + (gaussianRows (cavityBulkFeature n d m M f p.1 x) p.2)) := by + apply (cavitySingleTest n d f.f Λ hΛ).measurable.comp + exact cavity_rows_joint_measurable hv measurable_const + have hi : Integrable (fun x=>cavitySingleTest n d f.f Λ hΛ + (gaussianRows (cavityBulkFeature n d m M f p.1 x) p.2)) μ := by + apply Integrable.of_bound hm.aestronglyMeasurable (Λ*Real.exp ((d:ℝ)*‖f.f‖)) + filter_upwards [] with x + have hb:=cavitySingleTest_bounds n d f.f Λ hΛ (gaussianRows (cavityBulkFeature n d m M f p.1 x) p.2) + rw [Real.norm_eq_abs,abs_of_pos ((Real.exp_pos _).trans_le hb.1)] + exact hb.2 + unfold cavityBulkPartition + rw [←tilt_law_integral_of_integrable (unitSphereLaw (m+1)) hmH he] + constructor + · simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono (integrable_const (Real.exp (-(d:ℝ)*‖f.f‖))) hi + (fun x=>(cavitySingleTest_bounds n d f.f Λ hΛ _).1) + · simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono hi (integrable_const (Λ*Real.exp ((d:ℝ)*‖f.f‖))) + (fun x=>(cavitySingleTest_bounds n d f.f Λ hΛ _).2) + +def cavityBulkPartitionLaw (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) : + ProbabilityMeasure (CavityPartitionRange d f.f Λ) := + ⟨((bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)))).map + (fun p=>⟨cavityBulkPartition n d m M f v Λ hΛ p,cavityBulkPartition_mem n d m M f v Λ hΛ p⟩), + (Measure.isProbabilityMeasure_map_iff + ((cavityBulkPartition_measurable n d m M f v Λ hΛ).subtype_mk).aemeasurable).2 inferInstance⟩ + +lemma cavityBulkPartitionLaw_integral (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (F : ℝ→ℝ) (hF : Measurable F) : + (∫ x,F x.val ∂(cavityBulkPartitionLaw n d m M f v Λ hΛ : Measure (CavityPartitionRange d f.f Λ)))= + ∫ p,F (cavityBulkPartition n d m M f v Λ hΛ p) + ∂(bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))) := + integral_map ((cavityBulkPartition_measurable n d m M f v Λ hΛ).subtype_mk).aemeasurable + (hF.comp measurable_subtype_coe).aestronglyMeasurable + +lemma cavityBulkPartition_power_integrable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (r : ℕ) : + Integrable (fun p=>cavityBulkPartition n d m M f v Λ hΛ p^r) + ((bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)))) := by + apply Integrable.of_bound ((cavityBulkPartition_measurable n d m M f v Λ hΛ).pow_const r).aestronglyMeasurable + ((Λ*Real.exp ((d:ℝ)*‖f.f‖))^r) + filter_upwards [] with p + have hb:=cavityBulkPartition_mem n d m M f v Λ hΛ p + rw [norm_pow,Real.norm_eq_abs,abs_of_pos ((Real.exp_pos _).trans_le hb.1)] + exact pow_le_pow_left₀ ((Real.exp_pos _).trans_le hb.1).le hb.2 r + +lemma cavityBulkPartitionLaw_moment (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (r : ℕ) : + (∫ x,x.val^r ∂(cavityBulkPartitionLaw n d m M f v Λ hΛ : Measure (CavityPartitionRange d f.f Λ)))= + cavityBulkMoment n d m M f v Λ hΛ r := by + rw [cavityBulkPartitionLaw_integral n d m M f v Λ hΛ (fun x : ℝ=>x^r) (by fun_prop), + integral_prod _ (cavityBulkPartition_power_integrable n d m M f v Λ hΛ r)] + rfl + +def cavityPartitionLogTest (d : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) : CavityPartitionRange d f Λ→ᵇℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x=>Real.log x.val, + continuous_subtype_val.log (fun x=>ne_of_gt ((Real.exp_pos _).trans_le x.prop.1))⟩ + +def cavityBulkLog (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) : ℝ := + ∫ a,∫ y,Real.log (cavityBulkPartition n d m M f v Λ hΛ (a,y)) + ∂stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) ∂bulkDisorderLaw (m+1) M + +lemma cavityBulkPartitionLaw_log (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) : + (∫ x,Real.log x.val ∂(cavityBulkPartitionLaw n d m M f v Λ hΛ : Measure (CavityPartitionRange d f.f Λ)))= + cavityBulkLog n d m M f v Λ hΛ := by + rw [cavityBulkPartitionLaw_integral _ _ _ _ _ _ _ _ _ Real.measurable_log] + change _=∫ a,∫ y,Real.log (cavityBulkPartition n d m M f v Λ hΛ (a,y)) ∂stdGaussian _ ∂_ + apply integral_prod + apply Integrable.of_bound ((cavityBulkPartition_measurable n d m M f v Λ hΛ).log).aestronglyMeasurable + ‖cavityPartitionLogTest d f.f Λ‖ + filter_upwards [] with p + exact (cavityPartitionLogTest d f.f Λ).norm_coe_le_norm + ⟨cavityBulkPartition n d m M f v Λ hΛ p,cavityBulkPartition_mem n d m M f v Λ hΛ p⟩ + +theorem cavityBulkLog_tendsto (n d : ℕ) (M : ℕ→ℕ) (f : Jet3) (v : ℕ→ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (K : ℝ) (hK : ∀ m,M m/(m+1:ℕ)*‖f.d1‖^2≤K) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray (BulkPairRange K))} + (hlim : Tendsto (fun j=>bulkMarkedArrayLaw (s j) (M (s j)) f (v (s j)) K (hK (s j))) atTop (𝓝 ν)) : + ∃ η : ProbabilityMeasure (CavityPartitionRange d f.f Λ), + Tendsto (fun j=>cavityBulkPartitionLaw n d (s j) (M (s j)) f (v (s j)) Λ hΛ) atTop (𝓝 η) ∧ + (∀ r,(∫ x,x.val^r ∂(η : Measure (CavityPartitionRange d f.f Λ)))=∫ Q,cavityArrayKernel n d r f.f Λ hΛ K Q ∂ν) ∧ + Tendsto (fun j=>cavityBulkLog n d (s j) (M (s j)) f (v (s j)) Λ hΛ) atTop + (𝓝 (∫ x,Real.log x.val ∂(η : Measure (CavityPartitionRange d f.f Λ)))) := by + have hmom r := cavityBulkMoment_tendsto n d M f v Λ hΛ K hK s hlim r + simp_rw [←cavityBulkPartitionLaw_moment] at hmom + obtain ⟨η,hη,hm⟩:=compact_moment_limit _ _ hmom + refine ⟨η,hη,hm,?_⟩ + have ht := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (cavityPartitionLogTest d f.f Λ)).continuousAt.tendsto.comp hη + simpa only [Function.comp_def,cavityPartitionLogTest,BoundedContinuousFunction.mkOfCompact_apply,ContinuousMap.coe_mk, + cavityBulkPartitionLaw_log] using ht + +lemma log_sub_le_div_sub {a b : ℝ} (ha : 0min (F x) Λ + have hFp x : 0≤F x := (by norm_num : (0:ℝ)≤1).trans (hF1 x) + have hGp x : 1≤G x := le_min (hF1 x) hΛ + have hGb x : ‖G x‖≤Λ := by + rw [Real.norm_eq_abs,abs_of_nonneg ((by norm_num : (0:ℝ)≤1).trans (hGp x))] + exact min_le_right _ _ + have hGm : AEStronglyMeasurable G μ := (hF.aestronglyMeasurable.aemeasurable.min aemeasurable_const).aestronglyMeasurable + have hGi : Integrable G μ := Integrable.of_bound hGm Λ (ae_of_all _ hGb) + have hFi := hF.integrable (by norm_num) + have hF2 : Integrable (fun x=>(F x)^2) μ := (memLp_two_iff_integrable_sq hF.aestronglyMeasurable).mp hF + have hWF : Integrable (fun x=>Real.exp (W x)*F x) μ := by + apply (hFi.const_mul (Real.exp C)).mono' (hW.exp.aestronglyMeasurable.mul hF.aestronglyMeasurable) + filter_upwards [] with x + simp only [Pi.mul_apply] + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _),abs_of_nonneg (hFp x)] + exact mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr (abs_le.mp (hWC x)).2) (hFp x) + have hWG : Integrable (fun x=>Real.exp (W x)*G x) μ := by + apply (hGi.const_mul (Real.exp C)).mono' (hW.exp.aestronglyMeasurable.mul hGm) + filter_upwards [] with x + simp only [Pi.mul_apply] + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _),abs_of_nonneg ((by norm_num : (0:ℝ)≤1).trans (hGp x))] + exact mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr (abs_le.mp (hWC x)).2) + ((by norm_num : (0:ℝ)≤1).trans (hGp x)) + have hBlo : Real.exp (-C)≤∫ x,Real.exp (W x)*G x ∂μ := by + calc + _=∫ _ : S,Real.exp (-C) ∂μ := by simp + _≤_ := integral_mono (integrable_const _) hWG fun x=>by + calc + Real.exp (-C)≤Real.exp (W x) := Real.exp_le_exp.mpr (abs_le.mp (hWC x)).1 + _≤Real.exp (W x)*G x := by nlinarith [Real.exp_pos (W x),hGp x] + have hBA : (∫ x,Real.exp (W x)*G x ∂μ)≤∫ x,Real.exp (W x)*F x ∂μ := + integral_mono hWG hWF fun x=>mul_le_mul_of_nonneg_left (min_le_left _ _) (Real.exp_pos _).le + have hBp: 0<∫ x,Real.exp (W x)*G x ∂μ := (Real.exp_pos _).trans_le hBlo + have hAp:=hBp.trans_le hBA + have htail : (∫ x,Real.exp (W x)*F x ∂μ)-(∫ x,Real.exp (W x)*G x ∂μ)≤ + Real.exp C/Λ*(∫ x,(F x)^2 ∂μ) := by + rw [←integral_sub hWF hWG,←integral_const_mul] + apply integral_mono (hWF.sub hWG) (hF2.const_mul _) + intro x + have ht:=cavity_cap_tail (hFp x) ((by norm_num : (0:ℝ)<1).trans_le hΛ) + calc + _=Real.exp (W x)*(F x-G x) := by simp only [Pi.sub_apply]; ring + _≤Real.exp C*(F x-G x) := mul_le_mul_of_nonneg_right + (Real.exp_le_exp.mpr (abs_le.mp (hWC x)).2) ht.1 + _≤Real.exp C*((F x)^2/Λ) := mul_le_mul_of_nonneg_left ht.2 (Real.exp_pos _).le + _=_ := by ring + refine ⟨sub_nonneg.mpr (Real.log_le_log hBp hBA),?_⟩ + calc + _≤((∫ x,Real.exp (W x)*F x ∂μ)-(∫ x,Real.exp (W x)*G x ∂μ))/ + (∫ x,Real.exp (W x)*G x ∂μ) := log_sub_le_div_sub hAp hBp + _≤(Real.exp C/Λ*(∫ x,(F x)^2 ∂μ))/(Real.exp (-C)) := + (div_le_div_of_nonneg_right htail hBp.le).trans + (div_le_div_of_nonneg_left (mul_nonneg (div_nonneg (Real.exp_pos _).le (le_trans (by norm_num) hΛ)) + (integral_nonneg fun x=>sq_nonneg _)) (Real.exp_pos _) hBlo) + _=_ := by rw [Real.exp_neg,div_inv_eq_mul,show 2*C=C+C by ring,Real.exp_add]; ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityBulkUncappedLog.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityBulkUncappedLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..a489100aa548a2b4abebc62f77dffaf930750bda --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityBulkUncappedLog.lean @@ -0,0 +1,160 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityExpectedCompensator +import OAI.Probability.Perceptron.Cavity.CavityAnnealedUncap +import OAI.Probability.Perceptron.Sphere.GaussianCoordinateProjection + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter +open scoped Topology BigOperators BoundedContinuousFunction + +def cavityBulkFullLog (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) : ℝ := + ∫ p,Real.log (cavityBulkFullCompPartition n d m M f v p) + ∂(bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))) + +lemma cavityBulk_log_integrable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) : + Integrable (fun p=>Real.log (cavityBulkPartition n d m M f v Λ hΛ p)) + ((bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)))) := by + apply Integrable.of_bound (cavityBulkPartition_measurable n d m M f v Λ hΛ).log.aestronglyMeasurable + ‖cavityPartitionLogTest d f.f Λ‖ + exact ae_of_all _ fun p=>(cavityPartitionLogTest d f.f Λ).norm_coe_le_norm + ⟨cavityBulkPartition n d m M f v Λ hΛ p,cavityBulkPartition_mem n d m M f v Λ hΛ p⟩ + +lemma cavityBulk_comp_log_integrable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (K : ℝ) (hK : 0≤K) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤K) : + Integrable (fun p=>Real.log (cavityBulkCompPartition n d m M f v Λ hΛ p)) + ((bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)))) := by + have he:=cavityBulkCompError_integrable n d m M f v Λ hΛ 0 K (by simpa using hK) hC + have hb:=cavityBulk_log_integrable n d m M f v Λ hΛ + exact (he.add hb).congr (ae_of_all _ fun p=>by dsimp [cavityBulkCompError]; ring) + +lemma cavityBulk_full_log_integrable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (K KC : ℝ) (hK : M/(m+1:ℕ)*‖f.d1‖^2≤K) (hKC : 0≤KC) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤KC) : + Integrable (fun p=>Real.log (cavityBulkFullCompPartition n d m M f v p)) + ((bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)))) := by + have he:=(cavityBulk_uncap_annealed n d m M f v 1 le_rfl K KC hK hC).1 + have hb:=cavityBulk_comp_log_integrable n d m M f v 1 le_rfl KC hKC hC + exact (he.add hb).congr (ae_of_all _ fun p=>by dsimp [cavityBulkUncapError]; ring) + +lemma cavityBulkFullLog_decomposition (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (c K KC : ℝ) (hc : |c|≤KC) + (hK : M/(m+1:ℕ)*‖f.d1‖^2≤K) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤KC) : + let Q:=(bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))) + cavityBulkFullLog n d m M f v= + (∫ p,cavityBulkUncapError n d m M f v Λ hΛ p ∂Q)+ + (∫ p,cavityBulkCompError n d m M f v Λ hΛ c p ∂Q)+ + ((n+1:ℕ)/2*c+cavityBulkLog n d m M f v Λ hΛ) := by + have hKC : 0≤KC:=(abs_nonneg c).trans hc + have hi:=cavityBulk_full_log_integrable n d m M f v K KC hK hKC hC + have hj:=cavityBulk_comp_log_integrable n d m M f v Λ hΛ KC hKC hC + have hk:=cavityBulk_log_integrable n d m M f v Λ hΛ + dsimp only + unfold cavityBulkUncapError cavityBulkCompError + have hs:=integral_sub hj ((integrable_const ((n+1:ℕ)/2*c)).add hk) + have ha:=integral_add (integrable_const ((n+1:ℕ)/2*c)) hk + simp only [Pi.add_apply] at hs ha + rw [integral_sub hi hj,hs,ha,integral_const,probReal_univ,one_smul,integral_prod _ hk] + unfold cavityBulkFullLog cavityBulkLog + ring + +def cavityBulkNoiseJoin (n d m M : ℕ) + (p : (Fin M→Spin (n+1))×(Fin d→Fin (m+1)→ℝ)) : + EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M) := + WithLp.toLp 2 (fun j=> match j with + | (Sum.inl i,Sum.inl t)=>p.1 t i + | (Sum.inr t,Sum.inr i)=>p.2 t i + | _=>0) + +lemma cavityBulkNoiseJoin_measurable (n d m M : ℕ) : + Measurable (cavityBulkNoiseJoin n d m M) := by + apply (MeasurableEquiv.toLp 2 _).measurable.comp + apply Measurable.of_eval + intro j + rcases j with ⟨i,t⟩ + cases i <;> cases t <;> dsimp [cavityBulkNoiseJoin] <;> fun_prop + +lemma cavityBulkNoiseSplit_join (n d m M : ℕ) + (p : (Fin M→Spin (n+1))×(Fin d→Fin (m+1)→ℝ)) : + cavityBulkNoiseSplit n d m M (cavityBulkNoiseJoin n d m M p)=p := by + rfl + +def cavitySplitPartition (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (p : BulkDisorder (m+1) M×((Fin M→Spin (n+1))×(Fin d→Fin (m+1)→ℝ))) : ℝ := + ∫ x,Real.exp (normalizedPatternEnergy (m+1) d f.f p.2.2 x+ + (n+1:ℕ)*bulkC (m+1) M f p.1.1 x/2)* + sphericalExp n (cavityVectorField M (n+1) (fun t=>f.d1 (∑ i,p.1.1 t i*x.val i)) + (Real.sqrt (m+1:ℕ))⁻¹ p.2.1) (Real.sqrt (n+1:ℕ)) + ∂tiltLaw (unitSphereLaw (m+1)) (bulkHamiltonian (m+1) M f.f v p.1.1 p.1.2) 1 + +lemma cavitySplitPartition_identity (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : BulkDisorder (m+1) M) (y : EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : + cavityBulkFullCompPartition n d m M f v (a,y)= + cavitySplitPartition n d m M f v (a,cavityBulkNoiseSplit n d m M y) := by + unfold cavitySplitPartition + rw [tilt_law_integral _ (bulkHamiltonian_section_measurable (m+1) M f.f v a) + (show 0≤M*‖f.f‖+bulkFeatureBound (m+1) v*‖a.2‖ from by + unfold bulkFeatureBound; positivity) (bulkHamiltonian_bound (m+1) M f.f v a) 1] + unfold cavityBulkFullCompPartition + congr 1 + funext x + rw [cavityBulkNoiseSplit_vector] + simp_rw [cavityBulkNoiseSplit_scalar] + congr 2 + unfold normalizedPatternEnergy + ring + +lemma cavitySplitPartition_measurable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) : + Measurable (cavitySplitPartition n d m M f v) := by + have hm:=(cavityBulkFullCompPartition_measurable n d m M f v).comp + (measurable_fst.prodMk ((cavityBulkNoiseJoin_measurable n d m M).comp measurable_snd)) + simpa only [Function.comp_def,cavitySplitPartition_identity,cavityBulkNoiseSplit_join] using hm + +lemma cavitySplitLog_integrable (n d m M : ℕ) (f : Jet3) + (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℝ) : + Integrable (fun p=>Real.log (cavitySplitPartition n d m M f v p)) + ((bulkDisorderLaw (m+1) M).prod ((Measure.pi fun _ : Fin M=>stdGaussian (Spin (n+1))).prod + (finitePatternRowsLaw (m+1) d))) := by + have hp:=(MeasurePreserving.id (bulkDisorderLaw (m+1) M)).prod (cavityBulkNoiseSplit_preserving n d m M) + apply (hp.integrable_comp (cavitySplitPartition_measurable n d m M f v).log.aestronglyMeasurable).mp + have hi:=cavityBulk_full_log_integrable n d m M f v + (M/(m+1:ℕ)*‖f.d1‖^2) (M/(m+1:ℕ)*‖f.dilationMark hf‖) le_rfl (by positivity) + (bulkC_bound m M f hf) + convert hi using 1 + funext p + exact congrArg Real.log (cavitySplitPartition_identity n d m M f v p.1 p.2).symm + +lemma cavityBulkFullLog_split (n d m M : ℕ) (f : Jet3) + (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℝ) : + cavityBulkFullLog n d m M f v= + ∫ a,∫ b,∫ y,Real.log (cavitySplitPartition n d m M f v (a,y,b)) + ∂Measure.pi (fun _ : Fin M=>stdGaussian (Spin (n+1))) + ∂finitePatternRowsLaw (m+1) d ∂bulkDisorderLaw (m+1) M := by + have hp:=(MeasurePreserving.id (bulkDisorderLaw (m+1) M)).prod (cavityBulkNoiseSplit_preserving n d m M) + have h : (∫ p,Real.log (cavitySplitPartition n d m M f v (Prod.map id (cavityBulkNoiseSplit n d m M) p)) + ∂(bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))))= + ∫ p,Real.log (cavitySplitPartition n d m M f v p) + ∂(bulkDisorderLaw (m+1) M).prod ((Measure.pi fun _ : Fin M=>stdGaussian (Spin (n+1))).prod + (finitePatternRowsLaw (m+1) d)) := by + rw [←hp.map_eq] + exact (integral_map hp.measurable.aemeasurable + (cavitySplitPartition_measurable n d m M f v).log.aestronglyMeasurable).symm + unfold cavityBulkFullLog + have he : (fun p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)=> + Real.log (cavityBulkFullCompPartition n d m M f v p))= + (fun p=>Real.log (cavitySplitPartition n d m M f v (Prod.map id (cavityBulkNoiseSplit n d m M) p))) := by + funext p + exact congrArg Real.log (cavitySplitPartition_identity n d m M f v p.1 p.2) + rw [he,h,integral_prod _ (cavitySplitLog_integrable n d m M f hf v)] + apply integral_congr_ae + filter_upwards [(cavitySplitLog_integrable n d m M f hf v).prod_right_ae] with a ha + exact integral_prod_symm _ ha + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityCompensator.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityCompensator.lean new file mode 100644 index 0000000000000000000000000000000000000000..7be7eda58022d783c1445d705875d0949fa8a4c1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityCompensator.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityBulkLog + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_exp_local_lipschitz {a b K : ℝ} (ha : a≤K) (hb : b≤K) : + |Real.exp a-Real.exp b|≤Real.exp K*|a-b| := by + have h:=Convex.norm_image_sub_le_of_norm_deriv_le + (f:=Real.exp) (s:=Iic K) (C:=Real.exp K) + (fun x _hx=>Real.differentiableAt_exp) + (fun x hx=>by simpa only [Real.deriv_exp,Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] using Real.exp_le_exp.mpr hx) + (convex_Iic K) hb ha + simpa only [Real.norm_eq_abs] using h + +lemma cavity_log_local_lipschitz {a b m : ℝ} (hm : 0 < m) (ha : m ≤ a) (hb : m ≤ b) : + |Real.log a-Real.log b|≤|a-b|/m := by + have h:=Convex.norm_image_sub_le_of_norm_deriv_le + (f:=Real.log) (s:=Ici m) (C:=m⁻¹) + (fun x hx=>Real.differentiableAt_log (hm.trans_le hx).ne') + (fun x hx=>by + rw [Real.deriv_log,Real.norm_eq_abs,abs_of_pos (inv_pos.mpr (hm.trans_le hx))] + exact inv_anti₀ hm hx) + (convex_Ici m) hb ha + simpa only [Real.norm_eq_abs,div_eq_mul_inv,mul_comm] using h + +lemma cavity_compensator_bound {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {W C : S→ℝ} {a b K c t : ℝ} + (hW : Measurable W) (hC : Measurable C) (ha : 0not_le.mpr (ha.trans_le ((hw x).1.trans (hw x).2)) (le_of_not_ge hh) + have he : (univ : Set S)=∅ := Set.ext (fun x=>⟨fun _=>(hfalse x).elim,fun h=>h.elim⟩) + have hμ := measure_univ (μ:=μ) + rw [he,measure_empty] at hμ + exact zero_ne_one hμ + have hK : 0≤K := (abs_nonneg c).trans hc + have hWi : Integrable W μ := Integrable.of_bound hW.aestronglyMeasurable b + (ae_of_all _ fun x=>by rw [Real.norm_eq_abs,abs_of_pos (ha.trans_le (hw x).1)]; exact (hw x).2) + have hEi : Integrable (fun x=>Real.exp (t*C x)*W x) μ := + Integrable.of_bound (hC.const_mul t |>.exp |>.aestronglyMeasurable |>.mul hW.aestronglyMeasurable) + (Real.exp (t*K)*b) (ae_of_all _ fun x=>by + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _),abs_of_pos (ha.trans_le (hw x).1)] + exact mul_le_mul (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (abs_le.mp (hcb x)).2 ht)) + (hw x).2 (ha.trans_le (hw x).1).le (Real.exp_pos _).le) + have hBi := hWi.const_mul (Real.exp (t*c)) + have hlo : Real.exp (-(t*K))*a≤∫ x,Real.exp (t*C x)*W x ∂μ := by + calc + _=∫ _ : S,Real.exp (-(t*K))*a ∂μ := by simp + _≤_ := integral_mono (integrable_const _) hEi fun x=>by + apply mul_le_mul _ (hw x).1 ha.le (Real.exp_pos _).le + apply Real.exp_le_exp.mpr + nlinarith [(abs_le.mp (hcb x)).1] + have hWlo : a≤∫ x,W x ∂μ := by + simpa using integral_mono (integrable_const a) hWi fun x=>(hw x).1 + have hbLo : Real.exp (-(t*K))*a≤Real.exp (t*c)*(∫ x,W x ∂μ) := by + apply mul_le_mul _ hWlo ha.le (Real.exp_pos _).le + exact Real.exp_le_exp.mpr (by nlinarith [(abs_le.mp hc).1]) + have hCi : Integrable (fun x=>|C x-c|) μ := + Integrable.of_bound (hC.sub_const c).abs.aestronglyMeasurable (K+|c|) + (ae_of_all _ fun x=>by simpa only [Real.norm_eq_abs,abs_abs] using + (abs_sub (C x) c).trans (add_le_add (hcb x) (le_refl |c|))) + have hdiff : |(∫ x,Real.exp (t*C x)*W x ∂μ)-Real.exp (t*c)*(∫ x,W x ∂μ)|≤ + Real.exp (t*K)*b*t*(∫ x,|C x-c| ∂μ) := by + rw [←integral_const_mul,←integral_sub hEi hBi] + apply (abs_integral_le_integral_abs).trans + rw [←integral_const_mul] + apply integral_mono (hEi.sub hBi).abs (hCi.const_mul _) + intro x + simp only [Pi.sub_apply] + rw [←sub_mul,abs_mul,abs_of_pos (ha.trans_le (hw x).1)] + have hex:=cavity_exp_local_lipschitz + (mul_le_mul_of_nonneg_left (abs_le.mp (hcb x)).2 ht) + (mul_le_mul_of_nonneg_left (abs_le.mp hc).2 ht) + rw [←mul_sub,abs_mul,abs_of_nonneg ht] at hex + calc + _≤(Real.exp (t*K)*(t*|C x-c|))*b := mul_le_mul hex (hw x).2 (ha.trans_le (hw x).1).le (by positivity) + _=_ := by ring + have hlog:=cavity_log_local_lipschitz (mul_pos (Real.exp_pos _) ha) hlo hbLo + rw [Real.log_mul (Real.exp_pos _).ne' (ha.trans_le hWlo).ne',Real.log_exp] at hlog + exact hlog.trans (by + apply (div_le_div_of_nonneg_right hdiff (mul_pos (Real.exp_pos _) ha).le).trans + apply le_of_eq + ring) + + +lemma bulkC_measurable (m M : ℕ) (f : Jet3) : + Measurable (fun p : BulkDisorder (m+1) M×NormalizedSpin (m+1)=>bulkC (m+1) M f p.1.1 p.2) := by + unfold bulkC + fun_prop + +lemma bulkC_bound (m M : ℕ) (f : Jet3) (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) + (a : BulkDisorder (m+1) M) (x : NormalizedSpin (m+1)) : + |bulkC (m+1) M f a.1 x|≤M/(m+1:ℕ)*‖f.dilationMark hf‖ := by + exact bulkSingleAverage_bound m M (f.dilationMark hf) a (fun _=>x) + +def cavityBulkCompPartition (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : ℝ := + tiltMean (unitSphereLaw (m+1)) (bulkGibbsHamiltonian m M f.f v p.1) + (fun x=>Real.exp ((n+1:ℕ)/2*bulkC (m+1) M f p.1.1 x)* + cavitySingleTest n d f.f Λ hΛ (gaussianRows (cavityBulkFeature n d m M f p.1 x) p.2)) 1 + +lemma cavity_comp_partition_joint_measurable {A S J E : Type*} + [MeasurableSpace A] [MeasurableSpace S] [Fintype J] [DecidableEq J] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (μ : Measure S) [SFinite μ] + (v : A→S→J→E) (hv : Measurable (Function.uncurry v)) + (H C : A→S→ℝ) (hH : Measurable (Function.uncurry H)) + (hC : Measurable (Function.uncurry C)) (t : ℝ) (Ψ : EuclideanSpace ℝ J→ᵇℝ) : + Measurable (fun p : A×E=>tiltMean μ (H p.1) + (fun x=>Real.exp (t*C p.1 x)*Ψ (gaussianRows (v p.1 x) p.2)) 1) := by + let κ : Kernel (A×E) S := Kernel.const _ μ + have hproj : Measurable (fun p : (A×E)×S=>(p.1.1,p.2)) := + measurable_fst.fst.prodMk measurable_snd + apply kernel_tiltMean_measurable κ (H:=fun p x=>H p.1 x) + (Y:=fun p x=>Real.exp (t*C p.1 x)*Ψ (gaussianRows (v p.1 x) p.2)) (hH.comp hproj) + exact ((hC.comp hproj).const_mul t).exp.mul + (Ψ.measurable.comp (cavity_rows_joint_measurable (hv.comp hproj) measurable_fst.snd)) + +lemma cavityBulkCompPartition_measurable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) : Measurable (cavityBulkCompPartition n d m M f v Λ hΛ) := by + exact cavity_comp_partition_joint_measurable (unitSphereLaw (m+1)) + (cavityBulkFeature n d m M f) (cavityBulkFeature_measurable n d m M f) + (bulkGibbsHamiltonian m M f.f v) (fun a x=>bulkC (m+1) M f a.1 x) + (bulkGibbsHamiltonian_measurable m M f.f v) (bulkC_measurable m M f) _ _ + +def cavityCompensatorConstant (n d : ℕ) (f : ℝ→ᵇℝ) (Λ K : ℝ) : ℝ := + (Real.exp ((n+1:ℕ)/2*K)*(Λ*Real.exp ((d:ℝ)*‖f‖))/ + (Real.exp (-((n+1:ℕ)/2*K))*Real.exp (-(d:ℝ)*‖f‖)))*((n+1:ℕ)/2) + +lemma cavityCompensatorConstant_nonneg (n d : ℕ) (f : ℝ→ᵇℝ) {Λ K : ℝ} (hΛ : 1≤Λ) : + 0≤cavityCompensatorConstant n d f Λ K := by + unfold cavityCompensatorConstant + have : 0≤Λ := (by norm_num : (0:ℝ)≤1).trans hΛ + positivity + +lemma tilt_cavity_compensator_bound {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {H W C : S→ℝ} {a b K c t : ℝ} + (hH : Measurable H) (he : Integrable (fun x=>Real.exp (1*H x)) μ) + (hW : Measurable W) (hC : Measurable C) (ha : 0Real.exp (t*C x)*W x) 1)- + (t*c+Real.log (tiltMean μ H W 1))|≤ + (Real.exp (t*K)*b/(Real.exp (-(t*K))*a))*t*(tiltMean μ H (fun x=>|C x-c|) 1) := by + have := tilt_law_probability_of_integrable μ he + simp_rw [←tilt_law_integral_of_integrable μ hH he] + exact cavity_compensator_bound _ hW hC ha ht hw hc hcb + +lemma cavityBulkSingleWeight_measurable (n d m M : ℕ) (f : Jet3) + (Λ : ℝ) (hΛ : 1≤Λ) + (p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : + Measurable (fun x=>cavitySingleTest n d f.f Λ hΛ + (gaussianRows (cavityBulkFeature n d m M f p.1 x) p.2)) := by + exact (cavitySingleTest n d f.f Λ hΛ).measurable.comp + (cavity_rows_joint_measurable ((cavityBulkFeature_measurable n d m M f).of_uncurry_left) measurable_const) + +lemma cavityBulkCompPartition_error (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (c K : ℝ) (hc : |c|≤K) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤K) + (p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : + |Real.log (cavityBulkCompPartition n d m M f v Λ hΛ p)- + ((n+1:ℕ)/2*c+Real.log (cavityBulkPartition n d m M f v Λ hΛ p))|≤ + cavityCompensatorConstant n d f.f Λ K* + tiltMean (unitSphereLaw (m+1)) (bulkGibbsHamiltonian m M f.f v p.1) + (fun x=>|bulkC (m+1) M f p.1.1 x-c|) 1 := by + apply tilt_cavity_compensator_bound (unitSphereLaw (m+1)) + ((bulkGibbsHamiltonian_measurable m M f.f v).of_uncurry_left) + (by simpa only [one_mul,bulkGibbsHamiltonian] using bulkHamiltonian_exp_integrable m M f.f v p.1) + (cavityBulkSingleWeight_measurable n d m M f Λ hΛ p) + ((bulkC_measurable m M f).comp (measurable_const.prodMk measurable_id)) + (Real.exp_pos _) (by positivity) (fun x=>cavitySingleTest_bounds n d f.f Λ hΛ _) hc (hC p.1) + +lemma bulkC_L1_of_L2 (N M : ℕ→ℕ) (f : Jet3) (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) + (v : ℕ→ℕ→ℝ) (c : ℝ) + (hc : Tendsto (fun j=>bulkReplicaMean (N j) (M j) f.f (v j) 1 + (fun a x=>(bulkC (N j+1) (M j) f a.1 (x 0)-c)^2)) atTop (𝓝 0)) : + Tendsto (fun j=>bulkReplicaMean (N j) (M j) f.f (v j) 1 + (fun a x=>|bulkC (N j+1) (M j) f a.1 (x 0)-c|)) atTop (𝓝 0) := by + apply bulkReplicaMean_L2_tendsto N M f.f v 1 + (fun j a x=>|bulkC (N j+1) (M j) f a.1 (x 0)-c|) + (fun j=>?_) (fun j=>(M j:ℝ)/(N j+1:ℕ)*‖f.dilationMark hf‖+|c|) + (fun j=>by positivity) (fun j a x=>?_) 0 + · simpa only [sub_zero,sq_abs] using hc + · exact (((bulkC_measurable (N j) (M j) f).comp + (measurable_fst.prodMk ((measurable_pi_apply 0).comp measurable_snd))).sub_const c).abs + · rw [abs_abs] + exact (abs_sub _ _).trans (add_le_add (bulkC_bound (N j) (M j) f hf a (x 0)) le_rfl) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityConditionalIncrement.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityConditionalIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..4cd44279aa5d2370ccbecf3e3a40e1b5fc9bfb81 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityConditionalIncrement.lean @@ -0,0 +1,146 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityCompensator +import OAI.Probability.Perceptron.Cavity.CavityFiniteEvaluation +import OAI.Probability.Perceptron.Cavity.CavityTrueShellLower + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def cavityOldIncrement (n L M : ℕ) (f : Jet3) (a : Fin M→Fin (n+1)→ℝ) + (W : NormalizedSpin (n+1)→ℝ) (y : Fin M→Spin L) (p : CavityShellSpin n L) : ℝ := + cavityShellPatternEnergy n L M f.f (cavityJoinedPatterns (n+1) L M a y) p- + normalizedPatternEnergy (n+1) M f.f a p.1+W p.1 + +lemma cavityOldIncrement_measurable (n L M : ℕ) (f : Jet3) (a : Fin M→Fin (n+1)→ℝ) + (W : NormalizedSpin (n+1)→ℝ) (hW : Measurable W) : + Measurable (fun p : CavityShellSpin n L×(Fin M→Spin L)=>cavityOldIncrement n L M f a W p.2 p.1) := by + have hj : Measurable (fun p : CavityShellSpin n L×(Fin M→Spin L)=> + cavityJoinedPatterns (n+1) L M a p.2) := by + unfold cavityJoinedPatterns + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + refine Fin.addCases (fun j=>?_) (fun j=>?_) j + · simpa only [Fin.addCases_left] using (measurable_const : Measurable (fun _ : CavityShellSpin n L×(Fin M→Spin L)=>a i j)) + · simp only [Fin.addCases_right] + fun_prop + have he := (normalizedPatternEnergy_continuous (n+1+L) M f.f).measurable.comp + (hj.prodMk ((cavityShellSpinEmbedding_measurable n L).comp measurable_fst)) + have hb : Measurable (fun p : CavityShellSpin n L×(Fin M→Spin L)=> + normalizedPatternEnergy (n+1) M f.f a p.1.1) := (normalizedPatternEnergy_continuous (n+1) M f.f).measurable.comp + (f:=fun p : CavityShellSpin n L×(Fin M→Spin L)=>(a,p.1.1)) + (measurable_const.prodMk measurable_fst.fst) + exact (he.sub hb).add (hW.comp measurable_fst.fst) + +lemma cavityOldIncrement_bound (n L M : ℕ) (f : Jet3) (a : Fin M→Fin (n+1)→ℝ) + (W : NormalizedSpin (n+1)→ℝ) {E : ℝ} (hW : ∀ x,|W x|≤E) + (y : Fin M→Spin L) (p : CavityShellSpin n L) : + |cavityOldIncrement n L M f a W y p|≤2*M*‖f.f‖+E := by + apply (abs_add_le _ _).trans + apply (add_le_add ((abs_sub _ _).trans (add_le_add + (cavityShellPatternEnergy_bound n L M f.f _ p) + (normalizedPatternEnergy_bound (n+1) M f.f a p.1))) (hW p.1)).trans_eq + ring + +theorem cavity_conditional_old_increment_lower (n k M : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (hn : 2*((k+1)+1)≤n+1) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (μ : Measure (NormalizedSpin (n+1))) [IsProbabilityMeasure μ] + (a : Fin M→Fin (n+1)→ℝ) (W : NormalizedSpin (n+1)→ℝ) + (hW : Measurable W) {E : ℝ} (hE : 0≤E) (hWE : ∀ x,|W x|≤E) : + let K : ℝ:=M/(n+1:ℕ)*‖f.dilationMark h1‖ + let A : NormalizedSpin (n+1)→Fin M→ℝ:=fun x i=>f.d1 (∑ j,a i j*x.val j) + (∫ y : Fin M→Spin (k+1),Real.log (∫ p,Real.exp (cavityOldIncrement n (k+1) M f a W y p) + ∂μ.prod (cavityShellProbability n (k+1))) ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))≥ + (∫ y : Fin M→Spin (k+1),Real.log (∫ x,Real.exp (W x+(k+1:ℕ)*bulkC (n+1) M f a x/2)* + sphericalExp k (cavityVectorField M (k+1) (A x) (Real.sqrt (n+1:ℕ))⁻¹ y) + (Real.sqrt (k+1:ℕ)) ∂μ) ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))-K/2- + Real.exp (2*(E+((k+1:ℕ)+1)*K/2)+(Real.sqrt (n+1:ℕ))⁻¹^2*((k+1:ℕ)+1)^2*M*‖f.d1‖^2)* + Real.sqrt ((1/(2*(n+1:ℕ)))^2*(((k+1:ℕ)+1)^2)^2*squareGaussianVariance*M*‖f.d2‖^2)- + (∫ y : Fin M→Spin (k+1),∑ i,cavityRemainderMajorant + (cavityRemainderCoefficients f h1 h2 h3 (k+1) ((k+1)+1)) (n+1:ℕ) ‖y i‖ + ∂Measure.pi (fun _=>stdGaussian (Spin (k+1)))) := by + dsimp only + have := cavityShellProbability_probability n (k+1) hp + let A : NormalizedSpin (n+1)→Fin M→ℝ:=fun x i=>f.d1 (∑ j,a i j*x.val j) + let B : NormalizedSpin (n+1)→Fin M→ℝ:=fun x i=>f.d2 (∑ j,a i j*x.val j) + let C : NormalizedSpin (n+1)→ℝ:=fun x=>bulkC (n+1) M f a x + let K : ℝ:=M/(n+1:ℕ)*‖f.dilationMark h1‖ + have hK : 0≤K := by dsimp [K]; positivity + have hA : Measurable A := by have hm:=f.d1.continuous.measurable; unfold A; fun_prop + have hB : Measurable B := by have hm:=f.d2.continuous.measurable; unfold B; fun_prop + have hC : Measurable C := (bulkC_measurable n M f).comp + (f:=fun x : NormalizedSpin (n+1)=>((a,0),x)) (measurable_const.prodMk measurable_id) + have hAB (x) (i) : |A x i|≤‖f.d1‖ := f.d1.norm_coe_le_norm _ + have hBB (x) (i) : |B x i|≤‖f.d2‖ := f.d2.norm_coe_le_norm _ + have hCK (x) : |C x|≤K := bulkC_bound n M f h1 (a,0) x + let U : CavityShellSpin n (k+1)→ℝ:=fun p=>W p.1+‖p.2.val‖^2*C p.1/2 + let V : (Fin M→Spin (k+1))→CavityShellSpin n (k+1)→ℝ:=fun y p=>U p+ + cavityLinearField M (k+1) (A p.1) (Real.sqrt (n+1:ℕ))⁻¹ p.2.val y+ + cavityQuadraticField M (k+1) (B p.1) (1/(2*(n+1:ℕ))) p.2.val y + have hU : Measurable U := by + have hw : Measurable (fun p : CavityShellSpin n (k+1)=>W p.1) := hW.comp measurable_fst + have hc : Measurable (fun p : CavityShellSpin n (k+1)=>C p.1) := hC.comp measurable_fst + unfold U + fun_prop + have hUB (p) : |U p|≤E+((k+1:ℕ)+1)*K/2 := + cavity_shell_compensator_bound k _ _ _ _ hK (hCK p.1) (hWE p.1) p.2 + have hVi : Integrable (fun y=>Real.log (∫ p,Real.exp (V y p) + ∂μ.prod (cavityShellProbability n (k+1)))) (Measure.pi (fun _=>stdGaussian (Spin (k+1)))) := + cavity_quadratic_log_integrable (μ.prod (cavityShellProbability n (k+1))) M (k+1) + (fun p=>A p.1) (fun p=>B p.1) (fun p=>p.2.val) U + (hA.comp measurable_fst) (hB.comp measurable_fst) measurable_snd.subtype_val hU _ _ + (norm_nonneg _) (norm_nonneg _) (by positivity) (by positivity) + (fun p=>hAB p.1) (fun p=>hBB p.1) (fun p=>cavity_shell_norm_bound (k+1) p.2) hUB + have hFi := cavity_log_integrable_of_bound (μ.prod (cavityShellProbability n (k+1))) + (Measure.pi (fun _ : Fin M=>stdGaussian (Spin (k+1)))) + (fun p=>cavityOldIncrement n (k+1) M f a W p.2 p.1) + (cavityOldIncrement_measurable n (k+1) M f a W hW) + (fun _=>2*M*‖f.f‖+E) (integrable_const _) (fun _=>by positivity) + (fun p y=>cavityOldIncrement_bound n (k+1) M f a W hWE y p) + let R : (Fin M→Spin (k+1))→ℝ:=fun y=>∑ i,cavityRemainderMajorant + (cavityRemainderCoefficients f h1 h2 h3 (k+1) ((k+1)+1)) (n+1:ℕ) ‖y i‖ + have hRi : Integrable R (Measure.pi (fun _=>stdGaussian (Spin (k+1)))) := by + apply integrable_finsetSum + intro i _ + exact ((measurePreserving_eval (fun _ : Fin M=>stdGaussian (Spin (k+1))) i).integrable_comp + (cavityRemainderMajorant_integrable _ _ _).aestronglyMeasurable).mpr + (cavityRemainderMajorant_integrable _ _ _) + have hpoint (y : Fin M→Spin (k+1)) : Real.log (∫ p,Real.exp (V y p) + ∂μ.prod (cavityShellProbability n (k+1)))-R y≤ + Real.log (∫ p,Real.exp (cavityOldIncrement n (k+1) M f a W y p) + ∂μ.prod (cavityShellProbability n (k+1))) := by + have hv : Measurable (V y) := by + dsimp [V] + unfold cavityLinearField cavityQuadraticField + fun_prop + have herr (p : CavityShellSpin n (k+1)) : + |cavityOldIncrement n (k+1) M f a W y p-V y p|≤R y := by + have hh:=cavity_true_shell_expansion n (k+1) M f h1 h2 h3 hn a y p + convert hh using 1 <;> try dsimp [cavityOldIncrement,V,U,A,B,C,cavityShellTaylorModel] + · congr 1 + ring + · simp only [R,Nat.cast_add,Nat.cast_one] + have hh:=cavity_log_uniform_change (μ.prod (cavityShellProbability n (k+1))) + ((cavityOldIncrement_measurable n (k+1) M f a W hW).comp + (measurable_id.prodMk measurable_const)) hv (A:=2*M*‖f.f‖+E) (by positivity) + (cavityOldIncrement_bound n (k+1) M f a W hWE y) herr + simp only [Function.comp_def,id_eq] at hh + linarith [(abs_le.mp hh).1] + have hi := integral_mono (hVi.sub hRi) hFi hpoint + simp only [Pi.sub_apply] at hi + rw [integral_sub hVi hRi] at hi + have hs := cavity_expected_shell_lower μ n k M hp A B W C hA hB hW hC + (Real.sqrt (n+1:ℕ))⁻¹ (1/(2*(n+1:ℕ))) (norm_nonneg _) (norm_nonneg _) hE hK hAB hBB hWE hCK + exact (sub_le_sub_right hs _).trans hi + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityCountableIsotropic.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityCountableIsotropic.lean new file mode 100644 index 0000000000000000000000000000000000000000..2cfbdc47950cda7806ceeda383c8513866fddd96 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityCountableIsotropic.lean @@ -0,0 +1,162 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityLabelArray + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction + +section + +variable {S : Type} [MeasurableSpace S] + +def cavityCompletedCountableVector (n : ℕ) (v : ℕ→S→ℝ) (L : S→ℕ) + (σ : Fin (n+1)→ℝ) (xs : Fin (n+1)→S) + (p : (ℕ→ℝ)×Spin (n+1)) : Spin (n+1) := + WithLp.toLp 2 (fun i=>countableGaussianField v L p.1 (xs i)+σ i*p.2 i) + +omit [MeasurableSpace S] in +lemma cavityCompletedCountableVector_measurable (n : ℕ) (v : ℕ→S→ℝ) (L : S→ℕ) + (σ : Fin (n+1)→ℝ) (xs : Fin (n+1)→S) : + Measurable (cavityCompletedCountableVector n v L σ xs) := by + apply (MeasurableEquiv.toLp 2 (Fin (n+1)→ℝ)).measurable.comp + apply Measurable.of_eval + intro i + dsimp [cavityCompletedCountableVector,countableGaussianField,gaussianPrefixField] + fun_prop + +lemma cavityCompletedCountableVector_law (n : ℕ) (v : ℕ→S→ℝ) (L : S→ℕ) + (σ : Fin (n+1)→ℝ) (xs : Fin (n+1)→S) + (w : Fin (n+1)→Spin (n+1)) + (hc : ∀ i j,countableGaussianCovariance v v L (xs i) (xs j)+ + (if i=j then σ i^2 else 0)=inner ℝ (w i) (w j)) : + (countableGaussianLaw.prod (stdGaussian (Spin (n+1)))).map + (cavityCompletedCountableVector n v L σ xs)= + (stdGaussian (Spin (n+1))).map (gaussianRows w) := by + apply ext_of_forall_integral_eq_of_IsFiniteMeasure + intro Ψ + have hm := cavityCompletedCountableVector_measurable n v L σ xs + rw [integral_map hm.aemeasurable Ψ.continuous.aestronglyMeasurable, + integral_map (gaussianRows w).measurable.aemeasurable Ψ.continuous.aestronglyMeasurable] + have hi : Integrable (fun p=>Ψ (cavityCompletedCountableVector n v L σ xs p)) + (countableGaussianLaw.prod (stdGaussian (Spin (n+1)))) := + Integrable.of_bound (Ψ.measurable.comp hm).aestronglyMeasurable ‖Ψ‖ + (ae_of_all _ fun p=>Ψ.norm_coe_le_norm _) + rw [integral_prod _ hi] + change (∫ g,cavityDiagonalAverage σ Ψ + (WithLp.toLp 2 (fun i=>countableGaussianField v L g (xs i))) ∂countableGaussianLaw)=_ + rw [cavity_countable_kernel_diagonal_noise] + have he : (fun i j=>countableGaussianCovariance v v L (xs i) (xs j)+ + if i=j then σ i^2 else 0)=Matrix.gram ℝ w := by + ext i j + exact hc i j + rw [he,cavityMatrixKernel_posSemidef _ _ (Matrix.posSemidef_gram ℝ w), + ←gaussianRows_map_stdGaussian, + integral_map (gaussianRows w).measurable.aemeasurable Ψ.continuous.aestronglyMeasurable] + +lemma cavityCompletedCountableVector_isotropic (n : ℕ) (v : ℕ→S→ℝ) (L : S→ℕ) + (σ : Fin (n+1)→ℝ) (xs : Fin (n+1)→S) {b : ℝ} (hb : 0≤b) + (hc : ∀ i j,countableGaussianCovariance v v L (xs i) (xs j)+ + (if i=j then σ i^2 else 0)=if i=j then b else 0) : + (countableGaussianLaw.prod (stdGaussian (Spin (n+1)))).map + (cavityCompletedCountableVector n v L σ xs)= + (stdGaussian (Spin (n+1))).map (fun z=>Real.sqrt b •z) := by + let w : Fin (n+1)→Spin (n+1):=fun i=>Real.sqrt b •EuclideanSpace.single i (1:ℝ) + have hw : ∀ i j,inner ℝ (w i) (w j)=if i=j then b else 0 := by + intro i j + dsimp only [w] + simp only [inner_smul_left,inner_smul_right,conj_trivial] + by_cases h : i=j + · subst j + simp [Real.sq_sqrt hb,←pow_two] + · simp [EuclideanSpace.inner_single_left,h] + rw [cavityCompletedCountableVector_law n v L σ xs w (fun i j=>(hc i j).trans (hw i j).symm)] + exact gaussianRows_isotropic_law n w hb hw + +lemma cavityCompletedCountableVector_spherical_average (n : ℕ) (v : ℕ→S→ℝ) (L : S→ℕ) + (σ : Fin (n+1)→ℝ) (xs : Fin (n+1)→S) {b : ℝ} (hb : 0≤b) + (hc : ∀ i j,countableGaussianCovariance v v L (xs i) (xs j)+ + (if i=j then σ i^2 else 0)=if i=j then b else 0) (R : ℝ) : + (∫ p,sphericalExp n (cavityCompletedCountableVector n v L σ xs p) R + ∂countableGaussianLaw.prod (stdGaussian (Spin (n+1))))=Real.exp (R^2*b/2) := by + rw [←integral_map (cavityCompletedCountableVector_measurable n v L σ xs).aemeasurable + (sphericalExp_continuous n R).aestronglyMeasurable, + cavityCompletedCountableVector_isotropic n v L σ xs hb hc, + integral_map (by fun_prop) (sphericalExp_continuous n R).aestronglyMeasurable] + have h:=sphericalExp_gaussian_average n R (Real.sqrt b) 0 + have hz : sphericalExp n 0 R=1 := by simp [sphericalExp] + simpa only [zero_add,Real.sq_sqrt hb,hz,mul_one] using h + +lemma cavityCompletedCountableVector_spherical_memLp (n : ℕ) (v : ℕ→S→ℝ) (L : S→ℕ) + (σ : Fin (n+1)→ℝ) (xs : Fin (n+1)→S) {b : ℝ} (hb : 0≤b) + (hc : ∀ i j,countableGaussianCovariance v v L (xs i) (xs j)+ + (if i=j then σ i^2 else 0)=if i=j then b else 0) (R : ℝ) : + MemLp (fun p=>sphericalExp n (cavityCompletedCountableVector n v L σ xs p) R) 2 + (countableGaussianLaw.prod (stdGaussian (Spin (n+1)))) := by + have hm := (sphericalExp_continuous n R).measurable.comp + (cavityCompletedCountableVector_measurable n v L σ xs) + apply (memLp_two_iff_integrable_sq hm.aestronglyMeasurable).mpr + have hi : Integrable (fun p=>sphericalExp n (cavityCompletedCountableVector n v L σ xs p) (2*R)) + (countableGaussianLaw.prod (stdGaussian (Spin (n+1)))) := by + by_contra hn + have h:=cavityCompletedCountableVector_spherical_average n v L σ xs hb hc (2*R) + rw [integral_undef hn] at h + exact (Real.exp_pos _).ne' h.symm + apply hi.mono' (hm.pow_const 2).aestronglyMeasurable + filter_upwards [] with p + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + exact sphericalExp_square_le n R _ + +lemma cavityCompletedCountableVector_spherical_second (n : ℕ) (v : ℕ→S→ℝ) (L : S→ℕ) + (σ : Fin (n+1)→ℝ) (xs : Fin (n+1)→S) {b : ℝ} (hb : 0≤b) + (hc : ∀ i j,countableGaussianCovariance v v L (xs i) (xs j)+ + (if i=j then σ i^2 else 0)=if i=j then b else 0) (R : ℝ) : + (∫ p,sphericalExp n (cavityCompletedCountableVector n v L σ xs p) R^2 + ∂countableGaussianLaw.prod (stdGaussian (Spin (n+1))))≤Real.exp (2*R^2*b) := by + have hs := (memLp_two_iff_integrable_sq + (cavityCompletedCountableVector_spherical_memLp n v L σ xs hb hc R).aestronglyMeasurable).mp + (cavityCompletedCountableVector_spherical_memLp n v L σ xs hb hc R) + have hi := (cavityCompletedCountableVector_spherical_memLp n v L σ xs hb hc (2*R)).integrable (by norm_num) + apply (integral_mono hs hi (fun p=>sphericalExp_square_le n R _)).trans_eq + rw [cavityCompletedCountableVector_spherical_average n v L σ xs hb hc] + congr 1 + ring + +end + +lemma cavityLabelVector_second_moment (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (x : IndexedLeaf k) (R : ℝ) : + let V:=cavityCompletedCountableVector n (cavityLabelRow (cavityPairProfile n d p)) + (cavityLabelLength k) (fun _=>Real.sqrt (D.2.val-(p (Fin.last k)).2.val)) + (fun i=>(x,Sum.inl i)) + let P:=countableGaussianLaw.prod (stdGaussian (Spin (n+1))) + MemLp (fun y=>sphericalExp n (V y) R) 2 P ∧ + (∫ y,sphericalExp n (V y) R^2 ∂P)≤Real.exp (2*R^2*D.2.val) := by + have htop : (p (Fin.last k)).2.val≤D.2.val := hpD (Sum.inl 0) + have hb : 0≤D.2.val := (hp0 (Sum.inl 0)).trans + (((hpm (Sum.inl 0)) (Fin.zero_le (Fin.last k))).trans (hpD (Sum.inl 0))) + have hc (i j : Fin (n+1)) : + countableGaussianCovariance (cavityLabelRow (cavityPairProfile n d p)) + (cavityLabelRow (cavityPairProfile n d p)) (cavityLabelLength k) + (x,Sum.inl i) (x,Sum.inl j)+ + (if i=j then (Real.sqrt (D.2.val-(p (Fin.last k)).2.val))^2 else 0)= + if i=j then D.2.val else 0 := by + rw [cavityLabel_covariance _ hp0 hpm] + simp only [Sum.inl.injEq,indexedCommonDepth_self] + by_cases h : i=j + · simp only [h,ite_true,Real.sq_sqrt (sub_nonneg.mpr htop),cavityPairProfile,Sum.elim_inl] + ring + · simp [h] + exact ⟨cavityCompletedCountableVector_spherical_memLp n _ _ _ _ hb hc R, + cavityCompletedCountableVector_spherical_second n _ _ _ _ hb hc R⟩ + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityCounts.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..082c489ffc0a8eea34a273415f1b6e7f5c7085ba --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityCounts.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkCompactGG + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def cavityOmittedCount (α : ℝ) (n : ℕ) : ℕ := patternCount α (n+1)-2 + +def cavityFreshCount (α : ℝ) (n L : ℕ) : ℕ := patternCount α (n+1+L)-patternCount α (n+1) + +lemma cavity_count_bounds {α : ℝ} (hα : 0≤α) (N : ℕ) : + α*N-1≤(patternCount α N:ℝ) ∧ (patternCount α N:ℝ)≤α*N := by + constructor + · have h:=Nat.lt_floor_add_one (α*(N:ℝ)) + dsimp only [patternCount] + linarith + · exact Nat.floor_le (mul_nonneg hα (Nat.cast_nonneg N)) + +lemma cavity_count_density {α : ℝ} (hα : 0≤α) : + Tendsto (fun n=>(patternCount α (n+1):ℝ)/(n+1:ℕ)) atTop (𝓝 α) := by + have hN : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have hi:=tendsto_inv_atTop_zero.comp hN + have hl: Tendsto (fun n : ℕ=>α-((n+1:ℕ):ℝ)⁻¹) atTop (𝓝 α) := by + simpa only [sub_zero,Function.comp_def] using tendsto_const_nhds.sub hi + apply tendsto_of_tendsto_of_tendsto_of_le_of_le hl tendsto_const_nhds + · intro n + have h:=(cavity_count_bounds hα (n+1)).1 + apply (le_div_iff₀ (by positivity : (0:ℝ)<(n+1:ℕ))).mpr + calc + _ = α*(n+1:ℕ)-1 := by field_simp + _ ≤ _ := h + · intro n + exact (div_le_iff₀ (by positivity : (0:ℝ)<(n+1:ℕ))).mpr (cavity_count_bounds hα (n+1)).2 + +lemma cavity_count_eventually_two {α : ℝ} (hα : 0<α) : + ∀ᶠ n : ℕ in atTop,2≤patternCount α (n+1) := by + have hN : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have h:= (hN.const_mul_atTop hα).eventually_ge_atTop 3 + filter_upwards [h] with n hn + have hb:=(cavity_count_bounds hα.le (n+1)).1 + have hc : (2:ℝ)≤patternCount α (n+1) := by linarith + exact_mod_cast hc + +lemma cavity_omitted_full {α : ℝ} (hα : 0<α) : + ∀ᶠ n : ℕ in atTop,cavityOmittedCount α n+2=patternCount α (n+1) := by + filter_upwards [cavity_count_eventually_two hα] with n hn + exact Nat.sub_add_cancel hn + +lemma cavity_omitted_density {α : ℝ} (hα : 0<α) : + Tendsto (fun n=>((cavityOmittedCount α n+2:ℕ):ℝ)/(n+1:ℕ)) atTop (𝓝 α) := by + apply (cavity_count_density hα.le).congr' + filter_upwards [cavity_omitted_full hα] with n hn + rw [hn] + +lemma cavity_omitted_bound {α : ℝ} (hα : 0≤α) (n : ℕ) : + ((cavityOmittedCount α n+2:ℕ):ℝ)/(n+1:ℕ)≤α+2 := by + have h: ((cavityOmittedCount α n+2:ℕ):ℝ)≤(patternCount α (n+1):ℝ)+2 := by + exact_mod_cast Nat.add_le_add_right (Nat.sub_le _ 2) 2 + have hb:=(cavity_count_bounds hα (n+1)).2 + apply (div_le_iff₀ (by positivity : (0:ℝ)<(n+1:ℕ))).mpr + have hN : (1:ℝ)≤(n+1:ℕ) := by exact_mod_cast Nat.succ_le_succ (Nat.zero_le n) + nlinarith + +lemma cavity_fresh_count {α : ℝ} (hα : 0≤α) (n L : ℕ) : + patternCount α (n+1)+cavityFreshCount α n L=patternCount α (n+1+L) ∧ + |(cavityFreshCount α n L:ℝ)-(L:ℝ)*α|≤1 ∧ + cavityFreshCount α n L≤⌈(L:ℝ)*α+1⌉₊ := by + have hm : patternCount α (n+1)≤patternCount α (n+1+L) := + Nat.floor_mono (mul_le_mul_of_nonneg_left (by exact_mod_cast Nat.le_add_right (n+1) L) hα) + have he : (cavityFreshCount α n L:ℝ)=(patternCount α (n+1+L):ℝ)-(patternCount α (n+1):ℝ) := by + exact Nat.cast_sub hm + refine ⟨Nat.add_sub_of_le hm,?_,?_⟩ + · rw [he,abs_le] + have h0:=cavity_count_bounds hα (n+1) + have h1:=cavity_count_bounds hα (n+1+L) + push_cast at h0 h1 + constructor <;> nlinarith [h0.1,h0.2,h1.1,h1.2] + · have h0:=cavity_count_bounds hα (n+1) + have h1:=cavity_count_bounds hα (n+1+L) + push_cast at h0 h1 + have hh : (cavityFreshCount α n L:ℝ)≤(L:ℝ)*α+1 := by rw [he]; nlinarith [h0.1,h1.2] + exact_mod_cast hh.trans (Nat.le_ceil ((L:ℝ)*α+1)) + + +structure CavityGoodParameters (α : ℝ) (f : ℝ→ᵇℝ) where + J : ℕ→ℕ + monotone : Monotone J + le : ∀ n,J n≤n + tendsto : Tendsto J atTop atTop + measurable : ∀ n,MeasurableSet (bulkJointGoodSet α f J n) + mass : Tendsto (fun n=>bulkParameterLaw.real (bulkJointGoodSet α f J n)ᶜ) atTop (𝓝 0) + deviation : ∀ v : ℕ→ℕ→ℝ,(∀ᶠ n in atTop,v n∈bulkJointGoodSet α f J n)→ + ∀ p,Tendsto (fun n=>bulkDeviationAt n (patternCount α (n+1)) f p (v n)) atTop (𝓝 0) ∧ + Tendsto (fun n=>omittedBulkDeviation α f n p (v n)) atTop (𝓝 0) + +lemma exists_cavityGoodParameters {α : ℝ} (hα : 0≤α) (f : ℝ→ᵇℝ) : + Nonempty (CavityGoodParameters α f) := by + obtain ⟨J,hm,hl,ht,hms,hma,hd⟩:=exists_bulkJointGoodParameters hα f + exact ⟨⟨J,hm,hl,ht,hms,hma,hd⟩⟩ + +lemma CavityGoodParameters.nonempty {α : ℝ} {f : ℝ→ᵇℝ} (G : CavityGoodParameters α f) : + ∀ᶠ n in atTop,(bulkJointGoodSet α f G.J n).Nonempty := by + filter_upwards [G.mass.eventually (Iio_mem_nhds (by norm_num : (0:ℝ)<1))] with n hn + by_contra h + have he : bulkJointGoodSet α f G.J n=∅:=Set.not_nonempty_iff_eq_empty.mp h + simp only [he,compl_empty,probReal_univ] at hn + exact lt_irrefl _ hn + +lemma cavity_eventually_uniform {X : Type*} (S : ℕ→Set X) (T : Set X) (x0 : X) + (hx0 : x0∈T) (hST : ∀ n,S n⊆T) (hS : ∀ᶠ n in atTop,(S n).Nonempty) + (R : ℕ→X→Prop) + (hR : ∀ v : ℕ→X,(∀ n,v n∈T)→(∀ᶠ n in atTop,v n∈S n)→∀ᶠ n in atTop,R n (v n)) : + ∀ᶠ n in atTop,∀ x∈S n,R n x := by + classical + let v : ℕ→X:=fun n=>if h : ∃ x∈S n,¬R n x then h.choose + else if h' : (S n).Nonempty then h'.choose else x0 + have hvT : ∀ n,v n∈T := by + intro n + dsimp only [v] + split_ifs with h h' + · exact hST n h.choose_spec.1 + · exact hST n h'.choose_spec + · exact hx0 + have hvS : ∀ᶠ n in atTop,v n∈S n := by + filter_upwards [hS] with n hn + by_cases h : ∃ x∈S n,¬R n x + · simpa only [v,dite_eq_left h] using h.choose_spec.1 + · simpa only [v,dite_eq_right h,dite_eq_left hn] using hn.choose_spec + filter_upwards [hR v hvT hvS] with n hn + intro x hx + by_contra hbad + have he : ∃ x∈S n,¬R n x:=⟨x,hx,hbad⟩ + have hneg : ¬R n (v n) := by + dsimp only [v] + rw [dite_eq_left he] + exact he.choose_spec.2 + exact hneg hn +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityCovarianceComparison.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityCovarianceComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d40fe979eb6cfd200f2878c5125096d8ae51f1b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityCovarianceComparison.lean @@ -0,0 +1,215 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IntegratedConvex + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma bounded_log_partition_path_derivative {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (H D : ℝ→S→ℝ) + (hH : ∀ t,Measurable (H t)) (hD : ∀ t,Measurable (D t)) + {A B : ℝ} (hA : ∀ t s,|H t s|≤A) (hB : ∀ t s,|D t s|≤B) + (hd : ∀ t s,HasDerivAt (fun u=>H u s) (D t s) t) (t : ℝ) : + HasDerivAt (fun u=>Real.log (tiltPartition μ (H u) 1)) + (tiltMean μ (H t) (D t) 1) t := by + have hi (u : ℝ) : Integrable (fun s=>Real.exp (H u s)) μ := + Integrable.of_bound (hH u).exp.aestronglyMeasurable (Real.exp A) + (ae_of_all _ fun s=>by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (le_abs_self _ |>.trans (hA u s))) + have hp (u : ℝ) : 0<∫ s,Real.exp (H u s) ∂μ := by + apply integral_pos_iff_support_of_nonneg (fun s=>(Real.exp_pos _).le) (hi u) |>.mpr + simp [Function.support,Real.exp_ne_zero] + have hh := hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F:=fun u s=>Real.exp (H u s)) (F':=fun u s=>Real.exp (H u s)*D u s) + (s:=univ) (bound:=fun _ : S=>Real.exp A*B) (x₀:=t) + (by simp : univ∈𝓝 t) (Eventually.of_forall fun u=>(hH u).exp.aestronglyMeasurable) + (hi t) (((hH t).exp.mul (hD t)).aestronglyMeasurable) + (ae_of_all _ fun s u _=>by + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _)] + exact mul_le_mul (Real.exp_le_exp.mpr (le_abs_self _ |>.trans (hA u s))) + (hB u s) (abs_nonneg _) (Real.exp_pos _).le) + (integrable_const _) (ae_of_all _ fun s u _=>(hd u s).exp) + simpa only [tiltMean,tiltIntegral,tiltPartition,one_mul] using hh.2.log (hp t).ne' + +variable {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + +def cavityGaussianRotation (V W : S→EuclideanSpace ℝ I) (t : ℝ) (s : S) : EuclideanSpace ℝ I := + Real.cos t •V s+Real.sin t •W s + +def cavityGaussianRotationVelocity (V W : S→EuclideanSpace ℝ I) (t : ℝ) (s : S) : EuclideanSpace ℝ I := + (-Real.sin t) •V s+Real.cos t •W s + +lemma cavityGaussianRotation_norm {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + {V W : S→EuclideanSpace ℝ I} {C : ℝ} (_hC : 0≤C) + (hV : ∀ s,‖V s‖≤C) (hW : ∀ s,‖W s‖≤C) (t : ℝ) (s : S) : + ‖cavityGaussianRotation V W t s‖≤2*C := by + apply (norm_add_le _ _).trans + simp only [norm_smul,Real.norm_eq_abs] + have h1 := mul_le_mul (Real.abs_cos_le_one t) (hV s) (norm_nonneg _) (by norm_num : (0:ℝ)≤1) + have h2 := mul_le_mul (Real.abs_sin_le_one t) (hW s) (norm_nonneg _) (by norm_num : (0:ℝ)≤1) + linarith + +lemma cavityGaussianRotationVelocity_norm {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + {V W : S→EuclideanSpace ℝ I} {C : ℝ} (_hC : 0≤C) + (hV : ∀ s,‖V s‖≤C) (hW : ∀ s,‖W s‖≤C) (t : ℝ) (s : S) : + ‖cavityGaussianRotationVelocity V W t s‖≤2*C := by + apply (norm_add_le _ _).trans + simp only [norm_smul,Real.norm_eq_abs,abs_neg] + have h1 := mul_le_mul (Real.abs_sin_le_one t) (hV s) (norm_nonneg _) (by norm_num : (0:ℝ)≤1) + have h2 := mul_le_mul (Real.abs_cos_le_one t) (hW s) (norm_nonneg _) (by norm_num : (0:ℝ)≤1) + linarith + +variable (μ : Measure S) [IsProbabilityMeasure μ] {H : S→ℝ} {V W : S→EuclideanSpace ℝ I} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) + {A C : ℝ} (hA : 0≤A) (hC : 0≤C) (hHA : ∀ s,|H s|≤A) + (hVC : ∀ s,‖V s‖≤C) (hWC : ∀ s,‖W s‖≤C) + +include hH hV hW hA hC hHA hVC hWC + +omit hH hV hW hA hC hHA hVC hWC in +lemma cavityGaussianRotation_log_derivative + {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {H : S→ℝ} {V W : S→EuclideanSpace ℝ I} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) + {A C : ℝ} (_hA : 0≤A) (hC : 0≤C) (hHA : ∀ s,|H s|≤A) + (hVC : ∀ s,‖V s‖≤C) (hWC : ∀ s,‖W s‖≤C) + (g : EuclideanSpace ℝ I) (t : ℝ) : + HasDerivAt (fun u=>Real.log (tiltPartition μ + (fun s=>H s+inner ℝ (cavityGaussianRotation V W u s) g) 1)) + (tiltMean μ (fun s=>H s+inner ℝ (cavityGaussianRotation V W t s) g) + (fun s=>inner ℝ (cavityGaussianRotationVelocity V W t s) g) 1) t := by + have hv (u : ℝ) : Measurable (cavityGaussianRotation V W u) := by unfold cavityGaussianRotation; fun_prop + have hw (u : ℝ) : Measurable (cavityGaussianRotationVelocity V W u) := by unfold cavityGaussianRotationVelocity; fun_prop + apply bounded_log_partition_path_derivative μ _ _ + (fun u=>hH.add ((hv u).inner measurable_const)) + (fun u=>(hw u).inner measurable_const) + (A:=A+2*C*‖g‖) (B:=2*C*‖g‖) + · intro u s + exact (abs_add_le _ _).trans (add_le_add (hHA s) + ((abs_real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right + (cavityGaussianRotation_norm hC hVC hWC u s) (norm_nonneg g)))) + · intro u s + exact (abs_real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right + (cavityGaussianRotationVelocity_norm hC hVC hWC u s) (norm_nonneg g)) + · intro u s + simpa [cavityGaussianRotation,cavityGaussianRotationVelocity,inner_add_left,inner_smul_left] using + ((((Real.hasDerivAt_cos u).mul_const (inner ℝ (V s) g)).add + ((Real.hasDerivAt_sin u).mul_const (inner ℝ (W s) g))).const_add (H s)) + +lemma cavityGaussianRotation_mean_derivative (t : ℝ) : + HasDerivAt (fun u=>∫ g,Real.log (tiltPartition μ + (fun s=>H s+inner ℝ (cavityGaussianRotation V W u s) g) 1) ∂stdGaussian (EuclideanSpace ℝ I)) + (∫ g,tiltMean μ (fun s=>H s+inner ℝ (cavityGaussianRotation V W t s) g) + (fun s=>inner ℝ (cavityGaussianRotationVelocity V W t s) g) 1 + ∂stdGaussian (EuclideanSpace ℝ I)) t := by + have hv (u : ℝ) : Measurable (cavityGaussianRotation V W u) := by unfold cavityGaussianRotation; fun_prop + have hw (u : ℝ) : Measurable (cavityGaussianRotationVelocity V W u) := by unfold cavityGaussianRotationVelocity; fun_prop + have hh (u : ℝ) : Measurable (fun p : EuclideanSpace ℝ I×S=> + H p.2+inner ℝ (cavityGaussianRotation V W u p.2) p.1) := + (hH.comp measurable_snd).add (((hv u).comp measurable_snd).inner measurable_fst) + have hd (u : ℝ) : Measurable (fun p : EuclideanSpace ℝ I×S=> + inner ℝ (cavityGaussianRotationVelocity V W u p.2) p.1) := + ((hw u).comp measurable_snd).inner measurable_fst + have hm (u : ℝ) : Measurable (fun g=>Real.log (tiltPartition μ + (fun s=>H s+inner ℝ (cavityGaussianRotation V W u s) g) 1)) := + (kernel_tiltPartition_measurable (Kernel.const _ μ) (hh u)).log + have hmd (u : ℝ) : Measurable (fun g=>tiltMean μ + (fun s=>H s+inner ℝ (cavityGaussianRotation V W u s) g) + (fun s=>inner ℝ (cavityGaussianRotationVelocity V W u s) g) 1) := + kernel_tiltMean_measurable (Kernel.const _ μ) (hh u) (hd u) + have hn : Integrable (fun g : EuclideanSpace ℝ I=>‖g‖) (stdGaussian (EuclideanSpace ℝ I)) := + ((IsGaussian.memLp_two_id (μ:=stdGaussian (EuclideanSpace ℝ I))).integrable (by norm_num)).norm + have hb (u : ℝ) (g : EuclideanSpace ℝ I) : + |Real.log (tiltPartition μ (fun s=>H s+inner ℝ (cavityGaussianRotation V W u s) g) 1)|≤A+2*C*‖g‖ := + tilt_log_partition_bound μ (hH.add ((hv u).inner measurable_const)) (A:=A+2*C*‖g‖) (by positivity) (fun s=> + (abs_add_le _ _).trans (add_le_add (hHA s) ((abs_real_inner_le_norm _ _).trans + (mul_le_mul_of_nonneg_right (cavityGaussianRotation_norm hC hVC hWC u s) (norm_nonneg g))))) + have hi (u : ℝ) : Integrable (fun g=>Real.log (tiltPartition μ + (fun s=>H s+inner ℝ (cavityGaussianRotation V W u s) g) 1)) (stdGaussian (EuclideanSpace ℝ I)) := + ((integrable_const A).add (hn.const_mul (2*C))).mono' (hm u).aestronglyMeasurable + (ae_of_all _ fun g=>by simpa only [Real.norm_eq_abs,Pi.add_apply] using hb u g) + have ht := hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F:=fun u g=>Real.log (tiltPartition μ (fun s=>H s+inner ℝ (cavityGaussianRotation V W u s) g) 1)) + (F':=fun u g=>tiltMean μ (fun s=>H s+inner ℝ (cavityGaussianRotation V W u s) g) + (fun s=>inner ℝ (cavityGaussianRotationVelocity V W u s) g) 1) + (s:=univ) (bound:=fun g : EuclideanSpace ℝ I=>2*C*‖g‖) (x₀:=t) + (by simp : univ∈𝓝 t) (Eventually.of_forall fun u=>(hm u).aestronglyMeasurable) + (hi t) (hmd t).aestronglyMeasurable + (ae_of_all _ fun g u _=>by + rw [Real.norm_eq_abs] + exact tiltMean_bound_general μ (hH.add ((hv u).inner measurable_const)) + ((hw u).inner measurable_const) (C:=2*C*‖g‖) (by positivity) (fun s=>(abs_real_inner_le_norm _ _).trans + (mul_le_mul_of_nonneg_right (cavityGaussianRotationVelocity_norm hC hVC hWC u s) (norm_nonneg g)))) + (hn.const_mul (2*C)) (ae_of_all _ fun g u _=> + cavityGaussianRotation_log_derivative μ hH hV hW hA hC hHA hVC hWC g u) + exact ht.2 +omit hH hV hW hA hC hHA hVC hWC in +lemma cavityGaussianRotation_cross_covariance_bound + {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + {V W : S→EuclideanSpace ℝ I} {ε : ℝ} (_hε : 0≤ε) + (horth : ∀ x y,inner ℝ (V x) (W y)=0) + (hcov : ∀ x y,|inner ℝ (W x) (W y)-inner ℝ (V x) (V y)|≤ε) + (t : ℝ) (x y : S) : + |inner ℝ (cavityGaussianRotationVelocity V W t x) (cavityGaussianRotation V W t y)|≤ε := by + have hr : inner ℝ (W x) (V y)=0 := by rw [real_inner_comm,horth] + have he : inner ℝ (cavityGaussianRotationVelocity V W t x) (cavityGaussianRotation V W t y)= + Real.sin t*Real.cos t*(inner ℝ (W x) (W y)-inner ℝ (V x) (V y)) := by + simp only [cavityGaussianRotation,cavityGaussianRotationVelocity,inner_add_left,inner_add_right, + inner_smul_left,inner_smul_right,conj_trivial,horth,hr] + ring + rw [he,abs_mul,abs_mul] + have h1 : |Real.sin t| * |Real.cos t| ≤ 1 := by + nlinarith [Real.abs_sin_le_one t,Real.abs_cos_le_one t,abs_nonneg (Real.sin t),abs_nonneg (Real.cos t)] + exact (mul_le_mul h1 (hcov x y) (abs_nonneg _) (by norm_num : (0:ℝ)≤1)).trans_eq (one_mul ε) + +theorem euclideanGaussian_covariance_comparison {ε : ℝ} (hε : 0≤ε) + (horth : ∀ x y,inner ℝ (V x) (W y)=0) + (hcov : ∀ x y,|inner ℝ (W x) (W y)-inner ℝ (V x) (V y)|≤ε) : + |(∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (W s) g) 1) + ∂stdGaussian (EuclideanSpace ℝ I))- + ∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (V s) g) 1) + ∂stdGaussian (EuclideanSpace ℝ I)|≤Real.pi*ε := by + let F : ℝ→ℝ:=fun t=>∫ g,Real.log (tiltPartition μ + (fun s=>H s+inner ℝ (cavityGaussianRotation V W t s) g) 1) ∂stdGaussian (EuclideanSpace ℝ I) + let D : ℝ→ℝ:=fun t=>∫ g,tiltMean μ + (fun s=>H s+inner ℝ (cavityGaussianRotation V W t s) g) + (fun s=>inner ℝ (cavityGaussianRotationVelocity V W t s) g) 1 ∂stdGaussian (EuclideanSpace ℝ I) + have hd (t : ℝ) : HasDerivAt F (D t) t := + cavityGaussianRotation_mean_derivative μ hH hV hW hA hC hHA hVC hWC t + have hb (t : ℝ) : ‖D t‖≤2*ε := by + have hv : Measurable (cavityGaussianRotation V W t) := by unfold cavityGaussianRotation; fun_prop + have hw : Measurable (cavityGaussianRotationVelocity V W t) := by unfold cavityGaussianRotationVelocity; fun_prop + have hc := cavityGaussianRotation_cross_covariance_bound (V:=V) (W:=W) hε horth hcov t + change ‖∫ g,tiltMean μ _ _ 1 ∂stdGaussian (EuclideanSpace ℝ I)‖≤_ + rw [euclideanGaussian_tiltMean_ibp μ hH hv hw hHA + (fun x=>pow_le_pow_left₀ (norm_nonneg _) (cavityGaussianRotation_norm hC hVC hWC t x) 2) + (fun x=>pow_le_pow_left₀ (norm_nonneg _) (cavityGaussianRotationVelocity_norm hC hVC hWC t x) 2)] + simpa only [probReal_univ,mul_one] using norm_integral_le_of_norm_le_const + (μ:=stdGaussian (EuclideanSpace ℝ I)) (C:=2*ε) (ae_of_all _ fun g=>by + have hh : Measurable (fun s=>H s+inner ℝ (cavityGaussianRotation V W t s) g) := + hH.add (hv.inner measurable_const) + have h1 := tiltMean_bound_general μ (t:=1) hh (hw.inner hv) hε (fun x=>hc x x) + have h2 := tiltMean_bound_general (Measure.pi (fun _ : Fin 2=>μ)) (t:=1) + (replicaPotential_measurable hh 2) + ((hw.comp (measurable_pi_apply 1)).inner (hv.comp (measurable_pi_apply 0))) hε + (fun xs=>hc (xs 1) (xs 0)) + rw [Real.norm_eq_abs] + apply (abs_sub _ _).trans + exact (add_le_add h1 h2).trans_eq (by ring)) + have hm := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun t (_ : t∈Icc (0:ℝ) (Real.pi/2))=>(hd t).hasDerivWithinAt) + (fun t _=>hb t) (convex_Icc (0:ℝ) (Real.pi/2)) + (show (0:ℝ)∈Icc (0:ℝ) (Real.pi/2) by constructor; rfl; positivity) + (show Real.pi/2∈Icc (0:ℝ) (Real.pi/2) by constructor; positivity; rfl) + simp only [Real.norm_eq_abs,sub_zero,abs_of_nonneg (by positivity : 0≤Real.pi/2)] at hm + convert hm using 1 + · simp [F,cavityGaussianRotation] + · ring +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityDiagonalKernel.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityDiagonalKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1ae6a7ed025b91da1e697653bd2d3b20c138fdb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityDiagonalKernel.lean @@ -0,0 +1,189 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityNormalizedIncrement + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction + +section + +variable {I : Type} [Fintype I] [DecidableEq I] + +def cavityDiagonalAverage (σ : I→ℝ) (Ψ : EuclideanSpace ℝ I→ᵇℝ) : EuclideanSpace ℝ I→ᵇℝ := + BoundedContinuousFunction.mkOfBound + ⟨fun x=>∫ z,Ψ (WithLp.toLp 2 (fun i=>x i+σ i*z i)) ∂stdGaussian (EuclideanSpace ℝ I),by + apply continuous_of_dominated (bound:=fun _=>‖Ψ‖) + · intro x + have hm : Measurable (fun z : EuclideanSpace ℝ I=>Ψ (WithLp.toLp 2 (fun i=>x i+σ i*z i))) := by fun_prop + exact (Integrable.of_bound hm.aestronglyMeasurable ‖Ψ‖ (ae_of_all _ fun z=>Ψ.norm_coe_le_norm _)).aestronglyMeasurable + · intro x + exact ae_of_all _ fun z=>Ψ.norm_coe_le_norm _ + · exact integrable_const _ + · exact ae_of_all _ fun z=>by fun_prop⟩ + (2*‖Ψ‖) (by + intro x y + have hx : ‖∫ z,Ψ (WithLp.toLp 2 (fun i=>x i+σ i*z i)) ∂stdGaussian (EuclideanSpace ℝ I)‖≤‖Ψ‖ := + by simpa using (norm_integral_le_of_norm_le_const (μ:=stdGaussian (EuclideanSpace ℝ I)) + (ae_of_all _ fun z=>Ψ.norm_coe_le_norm (WithLp.toLp 2 (fun i=>x i+σ i*z i)))) + have hy : ‖∫ z,Ψ (WithLp.toLp 2 (fun i=>y i+σ i*z i)) ∂stdGaussian (EuclideanSpace ℝ I)‖≤‖Ψ‖ := + by simpa using (norm_integral_le_of_norm_le_const (μ:=stdGaussian (EuclideanSpace ℝ I)) + (ae_of_all _ fun z=>Ψ.norm_coe_le_norm (WithLp.toLp 2 (fun i=>y i+σ i*z i)))) + rw [dist_eq_norm] + exact (norm_sub_le _ _).trans (by dsimp only [ContinuousMap.coe_mk]; linarith)) + +def cavityNoiseRows {n : ℕ} (v : I→EuclideanSpace ℝ (Fin n)) (σ : I→ℝ) (i : I) : + EuclideanSpace ℝ (Fin n⊕I) := + WithLp.toLp 2 (Sum.elim (fun j=>v i j) (fun j=>if j=i then σ i else 0)) + +lemma cavityNoiseRows_gram {n : ℕ} (v : I→EuclideanSpace ℝ (Fin n)) (σ : I→ℝ) : + Matrix.gram ℝ (cavityNoiseRows v σ)=fun i j=>Matrix.gram ℝ v i j+if i=j then σ i^2 else 0 := by + ext i j + change (∑ t : Fin n⊕I,Sum.elim (fun t=>v j t) (fun t=>if t=j then σ j else 0) t* + Sum.elim (fun t=>v i t) (fun t=>if t=i then σ i else 0) t)=_ + rw [Fintype.sum_sum_type] + simp only [Sum.elim_inl,Sum.elim_inr,mul_ite,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + by_cases h : i=j + · subst j + simp only [ite_true] + simp [Matrix.gram,PiLp.inner_apply,pow_two] + · simp only [ite_eq_right h,zero_mul] + rfl + +lemma cavityNoiseRows_apply {n : ℕ} (v : I→EuclideanSpace ℝ (Fin n)) (σ : I→ℝ) + (y : EuclideanSpace ℝ (Fin n⊕I)) (i : I) : + inner ℝ (cavityNoiseRows v σ i) y= + inner ℝ (v i) (gaussianSumSplit y).1+σ i*(gaussianSumSplit y).2 i := by + change (∑ t : Fin n⊕I,y t*Sum.elim (fun j=>v i j) (fun j=>if j=i then σ i else 0) t)=_ + rw [Fintype.sum_sum_type] + simp only [Sum.elim_inl,Sum.elim_inr,mul_ite,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + change (∑ t : Fin n,y (Sum.inl t)*v i t)+y (Sum.inr i)*σ i= + (∑ t : Fin n,y (Sum.inl t)*v i t)+σ i*y (Sum.inr i) + ring + +theorem cavityMatrixKernel_diagonal_noise {n : ℕ} + (v : I→EuclideanSpace ℝ (Fin n)) (σ : I→ℝ) (Ψ : EuclideanSpace ℝ I→ᵇℝ) : + cavityMatrixKernel Ψ (fun i j=>Matrix.gram ℝ v i j+if i=j then σ i^2 else 0)= + cavityMatrixKernel (cavityDiagonalAverage σ Ψ) (Matrix.gram ℝ v) := by + rw [←cavityNoiseRows_gram v σ, + cavityMatrixKernel_posSemidef _ _ (Matrix.posSemidef_gram ℝ _), + ←gaussianRows_map_stdGaussian, + integral_map (by fun_prop) Ψ.continuous.aestronglyMeasurable] + let F : EuclideanSpace ℝ (Fin n)×EuclideanSpace ℝ I→ℝ:=fun p=> + Ψ (WithLp.toLp 2 (fun i=>inner ℝ (v i) p.1+σ i*p.2 i)) + have hm : Measurable F := by fun_prop + have hi : Integrable F ((stdGaussian (EuclideanSpace ℝ (Fin n))).prod (stdGaussian (EuclideanSpace ℝ I))) := + Integrable.of_bound hm.aestronglyMeasurable ‖Ψ‖ (ae_of_all _ fun p=>Ψ.norm_coe_le_norm _) + have hp:=gaussianSumSplit_preserving (I:=Fin n) (J:=I) + have he (y : EuclideanSpace ℝ (Fin n⊕I)) : Ψ (gaussianRows (cavityNoiseRows v σ) y)=F (gaussianSumSplit y) := by + congr 1 + ext i + exact cavityNoiseRows_apply v σ y i + simp_rw [he] + have hmap : (∫ y,F (gaussianSumSplit y) ∂stdGaussian (EuclideanSpace ℝ (Fin n⊕I)))= + ∫ p,F p ∂(stdGaussian (EuclideanSpace ℝ (Fin n))).prod (stdGaussian (EuclideanSpace ℝ I)) := by + rw [←hp.map_eq,integral_map hp.measurable.aemeasurable hm.aestronglyMeasurable] + rw [hmap,integral_prod _ hi, + cavityMatrixKernel_posSemidef _ _ (Matrix.posSemidef_gram ℝ _), + ←gaussianRows_map_stdGaussian, + integral_map (by fun_prop) (cavityDiagonalAverage σ Ψ).continuous.aestronglyMeasurable] + rfl + +theorem cavity_countable_kernel_diagonal_noise {S : Type} [MeasurableSpace S] + (v : ℕ→S→ℝ) (L : S→ℕ) (σ : I→ℝ) (Ψ : EuclideanSpace ℝ I→ᵇℝ) (xs : I→S) : + (∫ g,cavityDiagonalAverage σ Ψ (WithLp.toLp 2 (fun i=>countableGaussianField v L g (xs i))) + ∂countableGaussianLaw)= + cavityMatrixKernel Ψ (fun i j=>countableGaussianCovariance v v L (xs i) (xs j)+if i=j then σ i^2 else 0) := by + rw [cavity_countable_kernel] + have hc : ∀ᶠ n : ℕ in atTop,∀ i j : I, + gaussianPrefixCovariance v v L n (xs i) (xs j)=countableGaussianCovariance v v L (xs i) (xs j) := + Filter.eventually_all.mpr (fun i=>Filter.eventually_all.mpr (fun j=> + gaussianPrefixCovariance_eventually_eq v v L (xs i) (xs j))) + obtain ⟨n,hn⟩:=hc.exists + let rows : I→EuclideanSpace ℝ (Fin n):=fun i=>WithLp.toLp 2 (fun j=>maskedGaussianCoefficient v L j.val (xs i)) + have hg : Matrix.gram ℝ rows=(fun i j=>countableGaussianCovariance v v L (xs i) (xs j)) := by + ext i j + rw [←hn i j] + change (∑ l : Fin n,maskedGaussianCoefficient v L l.val (xs j)* + maskedGaussianCoefficient v L l.val (xs i))=_ + exact Finset.sum_congr rfl fun l _=>mul_comm _ _ + have hh:=cavityMatrixKernel_diagonal_noise rows σ Ψ + rw [hg] at hh + exact hh.symm + +end + +variable {J : Type} [Fintype J] [DecidableEq J] + +def cavityReplicaSplit (r : ℕ) (z : EuclideanSpace ℝ (J×Fin r)) : + Fin r→EuclideanSpace ℝ J := fun i=>WithLp.toLp 2 (fun j=>z (j,i)) + +omit [DecidableEq J] in +lemma cavityReplicaSplit_preserving [DecidableEq J] (r : ℕ) : + MeasurePreserving (cavityReplicaSplit (J:=J) r) + (stdGaussian (EuclideanSpace ℝ (J×Fin r))) + (Measure.pi fun _ : Fin r=>stdGaussian (EuclideanSpace ℝ J)) := by + have ho : MeasurePreserving (WithLp.ofLp : EuclideanSpace ℝ (J×Fin r)→(J×Fin r→ℝ)) + (stdGaussian (EuclideanSpace ℝ (J×Fin r))) + (Measure.pi fun _ : J×Fin r=>gaussianReal 0 1) := by + refine ⟨(PiLp.continuous_ofLp 2 _).measurable,?_⟩ + rw [←map_pi_eq_stdGaussian,Measure.map_map (PiLp.continuous_ofLp 2 _).measurable + (PiLp.continuous_toLp 2 _).measurable] + exact Measure.map_id + have hs:=measurePreserving_piCongrLeft (fun _ : Fin r×J=>gaussianReal 0 1) (Equiv.prodComm J (Fin r)) + have hc : MeasurePreserving (MeasurableEquiv.curry (Fin r) J ℝ) + (Measure.pi fun _ : Fin r×J=>gaussianReal 0 1) + (Measure.pi fun _ : Fin r=>Measure.pi fun _ : J=>gaussianReal 0 1) := by + refine ⟨(MeasurableEquiv.curry _ _ _).measurable,?_⟩ + simpa only [Measure.infinitePi_eq_pi] using + Measure.infinitePi_map_curry (fun (_ : Fin r) (_ : J)=>gaussianReal 0 1) + have ht : MeasurePreserving (WithLp.toLp 2 : (J→ℝ)→EuclideanSpace ℝ J) + (Measure.pi fun _ : J=>gaussianReal 0 1) (stdGaussian (EuclideanSpace ℝ J)) := + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + have hp:=measurePreserving_pi (fun _ : Fin r=>Measure.pi fun _ : J=>gaussianReal 0 1) + (fun _ : Fin r=>stdGaussian (EuclideanSpace ℝ J)) (fun _=>ht) + convert hp.comp (hc.comp (hs.comp ho)) using 1 + rfl + +lemma cavityDiagonalAverage_replica (σ : J→ℝ) (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) : + cavityDiagonalAverage (fun p : J×Fin r=>σ p.1) (cavityTestReplica Ψ r)= + cavityTestReplica (cavityDiagonalAverage σ Ψ) r := by + ext x + let F : (Fin r→EuclideanSpace ℝ J)→ℝ := fun y=> + ∏ i : Fin r,Ψ (WithLp.toLp 2 (fun j=>x (j,i)+σ j*y i j)) + have hm : Measurable F := by fun_prop + have hp:=cavityReplicaSplit_preserving (J:=J) r + change (∫ z,cavityTestReplica Ψ r (WithLp.toLp 2 (fun p=>x p+σ p.1*z p)) + ∂stdGaussian (EuclideanSpace ℝ (J×Fin r)))=_ + simp only [cavityTestReplica_apply] + have he (z : EuclideanSpace ℝ (J×Fin r)) : + (∏ i : Fin r,Ψ (WithLp.toLp 2 (fun j=>(WithLp.toLp 2 (fun p : J×Fin r=>x p+σ p.1*z p)) (j,i))))= + F (cavityReplicaSplit r z) := rfl + simp_rw [he] + rw [←integral_map hp.measurable.aemeasurable hm.aestronglyMeasurable,hp.map_eq] + exact integral_fintype_prod_eq_prod (fun (i : Fin r) (y : EuclideanSpace ℝ J)=>Ψ (WithLp.toLp 2 (fun j=>x (j,i)+σ j*y j))) + +theorem cavity_countable_residual_moment {S : Type} [MeasurableSpace S] + [MeasurableSpace J] (μ : Measure S) [IsProbabilityMeasure μ] + (v : ℕ→S×J→ℝ) (L : S×J→ℕ) + (hv : ∀ i,Measurable (v i)) (hL : Measurable L) + (σ : J→ℝ) (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) : + (∫ g,(∫ x,cavityDiagonalAverage σ Ψ (cavityCountableField v L g x) ∂μ)^r + ∂countableGaussianLaw)= + ∫ xs : Fin r→S,cavityMatrixKernel (cavityTestReplica Ψ r) + (fun p q : J×Fin r=>countableGaussianCovariance v v L (xs p.2,p.1) (xs q.2,q.1)+ + if p=q then σ p.1^2 else 0) ∂Measure.pi (fun _=>μ) := by + rw [cavity_countable_moment μ v L hv hL,←cavityDiagonalAverage_replica] + apply integral_congr_ae + exact ae_of_all _ fun xs=>by + dsimp only + rw [←cavity_countable_kernel v L (cavityDiagonalAverage (fun p : J×Fin r=>σ p.1) (cavityTestReplica Ψ r)) (fun p : J×Fin r=>(xs p.2,p.1))] + exact cavity_countable_kernel_diagonal_noise v L (fun p : J×Fin r=>σ p.1) + (cavityTestReplica Ψ r) (fun p : J×Fin r=>(xs p.2,p.1)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityDisintegration.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityDisintegration.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d84f3e6308c462ccd9dcb24aedbf46a8de94f52 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityDisintegration.lean @@ -0,0 +1,137 @@ +import Mathlib +import OAI.Probability.Perceptron.Brownian.CountableGaussianField +import OAI.Probability.Perceptron.Variational.GaussianBlock + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal BigOperators + +lemma stdGaussian_radial_preserving (n : ℕ) : + MeasurePreserving (fun p : Ioi (0:ℝ)×Metric.sphere (0:Spin (n+1)) 1 => p.1.val •p.2.val) + ((gaussianRadiusLaw n).prod (unitSphereLaw (n+1))) (stdGaussian (Spin (n+1))) := by + refine ⟨by fun_prop,?_⟩ + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (by fun_prop),lintegral_prod _ (by fun_prop)] + exact (stdGaussian_polar_lintegral n F hF).symm + +def cavityBlockNormalize (N L : ℕ) (p : Spin N×Spin L) : Spin N×Spin L := + let a := (Real.sqrt (‖p.1‖^2+‖p.2‖^2))⁻¹ + (a •p.1,a •p.2) + +lemma cavityBlockNormalize_measurable (N L : ℕ) : Measurable (cavityBlockNormalize N L) := by + unfold cavityBlockNormalize + fun_prop + +lemma gaussianBlockSplit_normalize (N L : ℕ) (x : Spin (N+L)) : + gaussianBlockSplit N L (‖x‖⁻¹ •x)=cavityBlockNormalize N L (gaussianBlockSplit N L x) := by + unfold cavityBlockNormalize + rw [←gaussianBlockSplit_norm_sq,Real.sqrt_sq (norm_nonneg x)] + apply Prod.ext <;> ext i <;> rfl + +lemma sphereBlock_gaussian_law (n L : ℕ) : + (unitSphereLaw (n+1+L)).map (fun u => gaussianBlockSplit (n+1) L u.val)= + ((stdGaussian (Spin (n+1))).prod (stdGaussian (Spin L))).map (cavityBlockNormalize (n+1) L) := by + have hd : (stdGaussian (Spin (n+1+L))).map (fun x => ‖x‖⁻¹ •x)= + (unitSphereLaw (n+1+L)).map Subtype.val := by + have he : n+1+L=(n+L)+1 := by omega + rw [he] + exact stdGaussian_direction_law (n+L) + have h := congrArg (fun μ : Measure (Spin (n+1+L)) => μ.map (gaussianBlockSplit (n+1) L)) hd + rw [Measure.map_map (gaussianBlockSplit_measurable _ _) (by fun_prop), + Measure.map_map (gaussianBlockSplit_measurable _ _) measurable_subtype_coe] at h + simp only [Function.comp_def] at h + rw [←h,←(gaussianBlockSplit_preserving (n+1) L).map_eq, + Measure.map_map (cavityBlockNormalize_measurable _ _) (gaussianBlockSplit_measurable _ _)] + congr 1 + funext x + exact gaussianBlockSplit_normalize (n+1) L x + +def cavityRadialBlock (n L : ℕ) (p : (Ioi (0:ℝ)×Metric.sphere (0:Spin (n+1)) 1)×Spin L) : Spin (n+1)×Spin L := + let a := (Real.sqrt (p.1.1.val^2+‖p.2‖^2))⁻¹ + ((a*p.1.1.val) •p.1.2.val,a •p.2) + +lemma cavityRadialBlock_measurable (n L : ℕ) : Measurable (cavityRadialBlock n L) := by + unfold cavityRadialBlock + fun_prop + +lemma cavityRadialBlock_eq (n L : ℕ) (p : (Ioi (0:ℝ)×Metric.sphere (0:Spin (n+1)) 1)×Spin L) : + cavityRadialBlock n L p=cavityBlockNormalize (n+1) L (p.1.1.val •p.1.2.val,p.2) := by + have hn : ‖p.1.2.val‖=1 := by simpa only [Metric.mem_sphere,dist_zero_right] using p.1.2.prop + simp only [cavityRadialBlock,cavityBlockNormalize,norm_smul,Real.norm_eq_abs, + abs_of_pos (show (0:ℝ) gaussianBlockSplit (n+1) L u.val)= + (((gaussianRadiusLaw n).prod (unitSphereLaw (n+1))).prod (stdGaussian (Spin L))).map + (cavityRadialBlock n L) := by + rw [sphereBlock_gaussian_law] + have hp := (stdGaussian_radial_preserving n).prod (MeasurePreserving.id (stdGaussian (Spin L))) + rw [←hp.map_eq,Measure.map_map (cavityBlockNormalize_measurable _ _) hp.measurable] + congr 1 + funext p + exact (cavityRadialBlock_eq n L p).symm + +lemma countableGaussian_eval_preserving (i : ℕ) : + MeasurePreserving (fun g : ℕ→ℝ=>g i) countableGaussianLaw (gaussianReal 0 1) := + ⟨measurable_pi_apply i,Measure.infinitePi_map_eval _ i⟩ + +lemma countableGaussian_square_strongLaw : + ∀ᵐ g ∂countableGaussianLaw, + Tendsto (fun n : ℕ=>(∑ i∈Finset.range n,(g i)^2)/(n:ℝ)) atTop (𝓝 1) := by + have hi (i : ℕ) : IdentDistrib (fun g : ℕ→ℝ=>g i) (fun x : ℝ=>x) + countableGaussianLaw (gaussianReal 0 1) := + ⟨(measurable_pi_apply i).aemeasurable,measurable_id.aemeasurable,by + change Measure.map _ _ = Measure.map id _ + rw [Measure.map_id]; exact (countableGaussian_eval_preserving i).map_eq⟩ + have hint : Integrable (fun g : ℕ→ℝ=>(g 0)^2) countableGaussianLaw := + ((gaussian_square_memLp_two 1).comp_measurePreserving + (countableGaussian_eval_preserving 0)).integrable (by norm_num) + have hind := iIndepFun_infinitePi (P:=fun _ : ℕ=>gaussianReal 0 1) + (X:=fun _ : ℕ=>fun x : ℝ=>x^2) (fun _=>by fun_prop) + have h := strong_law_ae_real (fun i (g : ℕ→ℝ)=>(g i)^2) hint + (fun i j hij=>hind.indepFun hij) (fun i=>(hi i).sq.trans (hi 0).sq.symm) + have hm : (∫ g,(g 0)^2 ∂countableGaussianLaw)=1 := by + rw [(hi 0).sq.integral_eq,gaussian_square_mean]; rfl + rwa [hm] at h + +def cavityCoupledScale (n L : ℕ) (g : ℕ→ℝ) (z : Spin L) : ℝ := + Real.sqrt ((n+1+L:ℕ):ℝ) / Real.sqrt ((∑ i∈Finset.range (n+1),(g i)^2)+‖z‖^2) + +lemma cavityCoupledScale_measurable (n L : ℕ) : + Measurable (Function.uncurry (cavityCoupledScale n L)) := by + unfold cavityCoupledScale Function.uncurry + fun_prop + +lemma cavityCoupledScale_tendsto (L : ℕ) (g : ℕ→ℝ) (z : Spin L) + (hg : Tendsto (fun n : ℕ=>(∑ i∈Finset.range n,(g i)^2)/(n:ℝ)) atTop (𝓝 1)) : + Tendsto (fun n=>cavityCoupledScale n L g z) atTop (𝓝 1) := by + have hs := hg.comp (tendsto_add_atTop_nat 1) + have hi : Tendsto (fun n : ℕ=> (n+1:ℕ)⁻¹ : ℕ→ℝ) atTop (𝓝 0) := by + exact tendsto_inv_atTop_zero.comp (tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1)) + have hnum : Tendsto (fun n : ℕ=> ((n+1+L:ℕ):ℝ)/(n+1:ℕ)) atTop (𝓝 1) := by + have ht := (tendsto_const_nhds (x:=(1:ℝ))).add (hi.const_mul (L:ℝ)) + convert ht using 1 + · funext n + push_cast + field_simp + · simp + have hden : Tendsto (fun n : ℕ=> ((∑ i∈Finset.range (n+1),(g i)^2)+‖z‖^2)/(n+1:ℕ)) atTop (𝓝 1) := by + simpa only [Function.comp_apply,div_eq_mul_inv,add_mul,mul_zero,add_zero] using hs.add (hi.const_mul (‖z‖^2)) + have ht := hnum.sqrt.div hden.sqrt (by norm_num : Real.sqrt (1:ℝ)≠0) + simp only [Real.sqrt_one,div_one] at ht + apply ht.congr' + filter_upwards [] with n + change Real.sqrt (_/_)/Real.sqrt (_/_) = _ + unfold cavityCoupledScale + rw [Real.sqrt_div (by positivity),Real.sqrt_div (by positivity)] + have hn : Real.sqrt ((n+1:ℕ):ℝ)≠0 := ne_of_gt (Real.sqrt_pos.mpr (by positivity)) + field_simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityExpectedCompensator.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityExpectedCompensator.lean new file mode 100644 index 0000000000000000000000000000000000000000..59bdd20d9ad075170a5a36b361e2c4fca98dc619 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityExpectedCompensator.lean @@ -0,0 +1,110 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityCompensator + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def bulkCDefect (m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (c : ℝ) + (a : BulkDisorder (m+1) M) : ℝ := + tiltMean (unitSphereLaw (m+1)) (bulkGibbsHamiltonian m M f.f v a) + (fun x=>|bulkC (m+1) M f a.1 x-c|) 1 + +lemma bulkCDefect_measurable (m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (c : ℝ) : + Measurable (bulkCDefect m M f v c) := by + exact kernel_tiltMean_measurable (bulkSpinKernel m M) + (bulkGibbsHamiltonian_measurable m M f.f v) ((bulkC_measurable m M f).sub_const c).abs + +lemma bulkCDefect_bound (m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (c K : ℝ) (hK : 0≤K) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤K) + (a : BulkDisorder (m+1) M) : |bulkCDefect m M f v c a|≤K+|c| := by + apply tiltMean_bound_general (unitSphereLaw (m+1)) + ((bulkGibbsHamiltonian_measurable m M f.f v).of_uncurry_left) + ((((bulkC_measurable m M f).comp (measurable_const.prodMk measurable_id)).sub_const c).abs) + (by positivity) + intro x + rw [abs_abs] + exact (abs_sub _ _).trans (add_le_add (hC a x) le_rfl) + +lemma bulkCDefect_integral (m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (c : ℝ) : + (∫ a,bulkCDefect m M f v c a ∂bulkDisorderLaw (m+1) M)= + bulkReplicaMean m M f.f v 1 (fun a x=>|bulkC (m+1) M f a.1 (x 0)-c|) := by + unfold bulkReplicaMean + apply integral_congr_ae + filter_upwards [] with a + symm + exact gibbsReplicaMean_coordinate_of_integrable (unitSphereLaw (m+1)) + ((bulkGibbsHamiltonian_measurable m M f.f v).of_uncurry_left) + ((((bulkC_measurable m M f).comp (measurable_const.prodMk measurable_id)).sub_const c).abs) + (bulkHamiltonian_exp_integrable m M f.f v a) 1 0 + +def cavityBulkCompError (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) (Λ : ℝ) (hΛ : 1≤Λ) (c : ℝ) + (p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : ℝ := + Real.log (cavityBulkCompPartition n d m M f v Λ hΛ p)- + ((n+1:ℕ)/2*c+Real.log (cavityBulkPartition n d m M f v Λ hΛ p)) + +lemma cavityBulkCompError_measurable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (c : ℝ) : Measurable (cavityBulkCompError n d m M f v Λ hΛ c) := + (cavityBulkCompPartition_measurable n d m M f v Λ hΛ).log.sub + ((cavityBulkPartition_measurable n d m M f v Λ hΛ).log.const_add _) + +lemma cavityBulkCompError_integrable (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (c K : ℝ) (hc : |c|≤K) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤K) : + Integrable (cavityBulkCompError n d m M f v Λ hΛ c) + ((bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)))) := by + apply Integrable.of_bound (cavityBulkCompError_measurable n d m M f v Λ hΛ c).aestronglyMeasurable + (cavityCompensatorConstant n d f.f Λ K*(K+|c|)) + filter_upwards [] with p + rw [Real.norm_eq_abs] + refine (cavityBulkCompPartition_error n d m M f v Λ hΛ c K hc hC p).trans ?_ + exact mul_le_mul_of_nonneg_left + ((le_abs_self _).trans (bulkCDefect_bound m M f v c K ((abs_nonneg _).trans hc) hC p.1)) + (cavityCompensatorConstant_nonneg n d f.f hΛ) + +lemma cavityBulkCompError_mean_bound (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (c K : ℝ) (hc : |c|≤K) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤K) : + |∫ p,cavityBulkCompError n d m M f v Λ hΛ c p + ∂((bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))))|≤ + cavityCompensatorConstant n d f.f Λ K* + bulkReplicaMean m M f.f v 1 (fun a x=>|bulkC (m+1) M f a.1 (x 0)-c|) := by + have hE:=cavityBulkCompError_integrable n d m M f v Λ hΛ c K hc hC + let P:=(bulkDisorderLaw (m+1) M).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))) + have hD : Integrable (fun p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)=> + bulkCDefect m M f v c p.1) P := by + apply Integrable.of_bound ((bulkCDefect_measurable m M f v c).comp measurable_fst).aestronglyMeasurable (K+|c|) + exact ae_of_all _ fun p=>by + simpa only [Real.norm_eq_abs,Function.comp_apply] using bulkCDefect_bound m M f v c K ((abs_nonneg _).trans hc) hC p.1 + refine (abs_integral_le_integral_abs).trans ?_ + calc + _≤∫ p,cavityCompensatorConstant n d f.f Λ K*bulkCDefect m M f v c p.1 ∂P := + integral_mono hE.abs (hD.const_mul _) (fun p=>cavityBulkCompPartition_error n d m M f v Λ hΛ c K hc hC p) + _=_ := by rw [integral_const_mul,integral_fun_fst]; simp only [probReal_univ,one_smul,bulkCDefect_integral] + +theorem cavityBulkCompError_tendsto_zero (n d : ℕ) (N M : ℕ→ℕ) (f : Jet3) + (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (c K : ℝ) (hc : |c|≤K) + (hC : ∀ j (a : BulkDisorder (N j+1) (M j)) x,|bulkC (N j+1) (M j) f a.1 x|≤K) + (hL2 : Tendsto (fun j=>bulkReplicaMean (N j) (M j) f.f (v j) 1 + (fun a x=>(bulkC (N j+1) (M j) f a.1 (x 0)-c)^2)) atTop (𝓝 0)) : + Tendsto (fun j=>∫ p,cavityBulkCompError n d (N j) (M j) f (v j) Λ hΛ c p + ∂((bulkDisorderLaw (N j+1) (M j)).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d (N j) (M j)))))) + atTop (𝓝 0) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le + (g:=fun j=> -(cavityCompensatorConstant n d f.f Λ K* + bulkReplicaMean (N j) (M j) f.f (v j) 1 (fun a x=>|bulkC (N j+1) (M j) f a.1 (x 0)-c|))) + (h:=fun j=>cavityCompensatorConstant n d f.f Λ K* + bulkReplicaMean (N j) (M j) f.f (v j) 1 (fun a x=>|bulkC (N j+1) (M j) f a.1 (x 0)-c|)) + · simpa using ((bulkC_L1_of_L2 N M f hf v c hL2).const_mul (cavityCompensatorConstant n d f.f Λ K)).neg + · simpa using (bulkC_L1_of_L2 N M f hf v c hL2).const_mul (cavityCompensatorConstant n d f.f Λ K) + · intro j; exact (abs_le.mp (cavityBulkCompError_mean_bound n d (N j) (M j) f (v j) Λ hΛ c K hc (hC j))).1 + · intro j; exact (abs_le.mp (cavityBulkCompError_mean_bound n d (N j) (M j) f (v j) Λ hΛ c K hc (hC j))).2 + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityExpectedQDrop.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityExpectedQDrop.lean new file mode 100644 index 0000000000000000000000000000000000000000..155a65182b68c87ae6ba0668c67b87babec4b5fc --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityExpectedQDrop.lean @@ -0,0 +1,218 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityUniformRemainder +import OAI.Probability.Perceptron.Cavity.CavitySphericalMoments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma cavityQuadraticField_abs_bound (M L : ℕ) (b : Fin M→ℝ) (u : ℝ) + (z : Spin L) (y : Fin M→Spin L) {B D : ℝ} (hB : 0≤B) (hD : 0≤D) + (hb : ∀ i,|b i|≤B) (hz : ‖z‖≤D) : + |cavityQuadraticField M L b u z y|≤|u| * ∑ i,B*D^2*(‖y i‖^2+1) := by + unfold cavityQuadraticField + rw [abs_mul] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro i hi + rw [abs_mul] + have hkeep : |(inner ℝ z (y i))^2-‖z‖^2|≤D^2*(‖y i‖^2+1) := by + have hp : (inner ℝ z (y i))^2≤(D*‖y i‖)^2 := by + apply sq_le_sq.mpr + simpa only [abs_mul,abs_of_nonneg hD,abs_norm] using + (abs_real_inner_le_norm z (y i)).trans (mul_le_mul_of_nonneg_right hz (norm_nonneg _)) + have hq : ‖z‖^2≤D^2 := sq_le_sq₀ (norm_nonneg _) hD |>.mpr hz + calc + _≤|(inner ℝ z (y i))^2|+|‖z‖^2| := abs_sub _ _ + _=(inner ℝ z (y i))^2+‖z‖^2 := by rw [abs_of_nonneg (sq_nonneg _),abs_of_nonneg (sq_nonneg _)] + _≤D^2*(‖y i‖^2+1) := by nlinarith + exact (mul_le_mul (hb i) hkeep (abs_nonneg _) hB).trans_eq (by ring) + +lemma cavity_log_integrable_of_bound {S Y : Type*} [MeasurableSpace S] [MeasurableSpace Y] + (μ : Measure S) [IsProbabilityMeasure μ] (P : Measure Y) (H : S×Y→ℝ) + (hH : Measurable H) (K : Y→ℝ) (hK : Integrable K P) + (hK0 : ∀ y,0≤K y) (hB : ∀ s y,|H (s,y)|≤K y) : + Integrable (fun y=>Real.log (∫ s,Real.exp (H (s,y)) ∂μ)) P := by + have hm : Measurable (fun y=>Real.log (∫ s,Real.exp (H (s,y)) ∂μ)) := + hH.exp.stronglyMeasurable.integral_prod_left'.measurable.log + apply hK.mono' hm.aestronglyMeasurable + exact ae_of_all _ fun y=>by + rw [Real.norm_eq_abs] + simpa only [tiltPartition,one_mul,Function.comp_def,id_eq] using tilt_log_partition_bound μ + (hH.comp (measurable_id.prodMk measurable_const)) (hK0 y) (fun s=>hB s y) + +lemma cavity_quadratic_log_integrable {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M L : ℕ) + (a b : S→Fin M→ℝ) (z : S→Spin L) (W : S→ℝ) + (ha : Measurable a) (hb : Measurable b) (hz : Measurable z) (hW : Measurable W) + (t u : ℝ) {A B C D : ℝ} (hA : 0≤A) (hB : 0≤B) (hC : 0≤C) (hD : 0≤D) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) + (hzB : ∀ s,‖z s‖≤D) (hWB : ∀ s,|W s|≤C) : + Integrable (fun y : Fin M→Spin L=>Real.log (∫ s,Real.exp + (W s+cavityLinearField M L (a s) t (z s) y+cavityQuadraticField M L (b s) u (z s) y) ∂μ)) + (Measure.pi (fun _=>stdGaussian (Spin L))) := by + let P:=Measure.pi (fun _ : Fin M=>stdGaussian (Spin L)) + let K:=fun y : Fin M→Spin L=>C+|t| *(∑ i,A*D*‖y i‖)+|u| *(∑ i,B*D^2*(‖y i‖^2+1)) + have hi (i : Fin M) (p : ℕ) : Integrable (fun y : Fin M→Spin L=>‖y i‖^p) P := + ((measurePreserving_eval (fun _ : Fin M=>stdGaussian (Spin L)) i).integrable_comp + (cavityNormMoment_integrable L p).aestronglyMeasurable).mpr (cavityNormMoment_integrable L p) + have hK : Integrable K P := by + apply Integrable.add + · apply (integrable_const C).add + apply Integrable.const_mul + apply integrable_finsetSum + intro i _ + simpa only [pow_one] using (hi i 1).const_mul (A*D) + · apply Integrable.const_mul + apply integrable_finsetSum + intro i _ + exact ((hi i 2).add (integrable_const 1)).const_mul (B*D^2) + apply cavity_log_integrable_of_bound μ P _ + (((hW.comp measurable_fst).add (cavityLinearField_measurable M L a z ha hz t)).add + (cavityQuadraticField_measurable M L b z hb hz u)) K hK + (fun y=>by dsimp [K]; positivity) + intro s y + apply (abs_add_le _ _).trans + apply add_le_add _ (cavityQuadraticField_abs_bound M L (b s) u (z s) y hB hD (hbB s) (hzB s)) + exact (abs_add_le _ _).trans (add_le_add (hWB s) + (cavityLinearField_abs_bound M L (a s) t (z s) y hA (haB s) (hzB s))) + +lemma cavity_Q_ratio_integrable {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M L : ℕ) + (a b : S→Fin M→ℝ) (z : S→Spin L) (W : S→ℝ) + (ha : Measurable a) (hb : Measurable b) (hz : Measurable z) (hW : Measurable W) + (t u : ℝ) {A B C D : ℝ} (hA : 0≤A) (hB : 0≤B) (hD : 0≤D) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) + (hzB : ∀ s,‖z s‖^2≤D) (hWB : ∀ s,|W s|≤C) + (hden : ∀ y,Real.exp (-C)≤∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y) ∂μ) : + Integrable (fun y=>(∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y)* + |cavityQuadraticField M L (b s) u (z s) y| ∂μ)/(∫ s,Real.exp (W s+ + cavityLinearField M L (a s) t (z s) y) ∂μ)) + (Measure.pi (fun _=>stdGaussian (Spin L))) := by + have hi:=cavity_Q_product_integrable μ M L a b z W ha hb hz hW t u hA hB hD haB hbB hzB hWB + have hZ : Measurable (fun y=>∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y) ∂μ) := + ((hW.comp measurable_fst).add (cavityLinearField_measurable M L a z ha hz t)).exp.stronglyMeasurable.integral_prod_left'.measurable + apply (hi.integral_prod_right.const_mul (Real.exp C)).mono' + (hi.integral_prod_right.aestronglyMeasurable.div₀ hZ.aestronglyMeasurable) + exact ae_of_all _ fun y=>by + have hn : 0≤∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y)* + |cavityQuadraticField M L (b s) u (z s) y| ∂μ := + integral_nonneg fun _=>mul_nonneg (Real.exp_pos _).le (abs_nonneg _) + dsimp only [Pi.div_apply,Pi.mul_apply,Prod.fst,Prod.snd,Function.comp_def] + rw [Real.norm_eq_abs,abs_of_nonneg (div_nonneg hn ((Real.exp_pos _).le.trans (hden y))), + div_eq_mul_inv,mul_comm (Real.exp C)] + apply mul_le_mul_of_nonneg_left _ hn + calc + _≤(Real.exp (-C))⁻¹ := inv_anti₀ (Real.exp_pos _) (hden y) + _=Real.exp C := by rw [Real.exp_neg,inv_inv] + +theorem cavity_expected_log_drop_quadratic {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M L : ℕ) + (a b : S→Fin M→ℝ) (z : S→Spin L) (W : S→ℝ) + (ha : Measurable a) (hb : Measurable b) (hz : Measurable z) (hW : Measurable W) + (t u : ℝ) {A B C D : ℝ} (hA : 0≤A) (hB : 0≤B) (hC : 0≤C) (hD : 0≤D) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) + (hzB : ∀ s,‖z s‖≤D) (hWB : ∀ s,|W s|≤C) + (hden : ∀ y,Real.exp (-C)≤∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y) ∂μ) : + (∫ y : Fin M→Spin L,Real.log (∫ s,Real.exp + (W s+cavityLinearField M L (a s) t (z s) y+cavityQuadraticField M L (b s) u (z s) y) ∂μ) + ∂Measure.pi (fun _=>stdGaussian (Spin L)))≥ + (∫ y : Fin M→Spin L,Real.log (∫ s,Real.exp + (W s+cavityLinearField M L (a s) t (z s) y) ∂μ) + ∂Measure.pi (fun _=>stdGaussian (Spin L)))- + Real.exp (2*C+t^2*D^2*M*A^2)* + Real.sqrt (u^2*(D^2)^2*squareGaussianVariance*M*B^2) := by + let P:=Measure.pi (fun _ : Fin M=>stdGaussian (Spin L)) + let H : S×(Fin M→Spin L)→ℝ:=fun p=>W p.1+cavityLinearField M L (a p.1) t (z p.1) p.2 + let Q : S×(Fin M→Spin L)→ℝ:=fun p=>cavityQuadraticField M L (b p.1) u (z p.1) p.2 + let Z:=fun y=>∫ s,Real.exp (H (s,y)) ∂μ + let ZQ:=fun y=>∫ s,Real.exp (H (s,y)+Q (s,y)) ∂μ + let R:=fun y=>(∫ s,Real.exp (H (s,y))*|Q (s,y)| ∂μ)/Z y + have hsq (s : S) : ‖z s‖^2≤D^2 := pow_le_pow_left₀ (norm_nonneg _) (hzB s) 2 + have hqi : Integrable (fun y=>Real.log (ZQ y)) P := + cavity_quadratic_log_integrable μ M L a b z W ha hb hz hW t u hA hB hC hD haB hbB hzB hWB + have hzi : Integrable (fun y=>Real.log (Z y)) P := by + simpa only [cavityQuadraticField,zero_mul,add_zero] using + cavity_quadratic_log_integrable μ M L a b z W ha hb hz hW t 0 hA hB hC hD haB hbB hzB hWB + have hri : Integrable R P := cavity_Q_ratio_integrable μ M L a b z W ha hb hz hW + t u hA hB (sq_nonneg D) haB hbB hsq hWB hden + have hpoint (y : Fin M→Spin L) : Real.log (Z y)-R y≤Real.log (ZQ y) := by + have hHm : Measurable (fun s=>H (s,y)) := + ((hW.comp measurable_fst).add (cavityLinearField_measurable M L a z ha hz t)).comp + (measurable_id.prodMk measurable_const) + have hQm : Measurable (fun s=>Q (s,y)) := + (cavityQuadraticField_measurable M L b z hb hz u).comp (measurable_id.prodMk measurable_const) + apply cavity_log_drop_quadratic μ hHm hQm + (show 0≤C+|t| *∑ i,A*D*‖y i‖ by positivity) + (show 0≤|u| *∑ i,B*D^2*(‖y i‖^2+1) by positivity) + · intro s + exact (abs_add_le _ _).trans (add_le_add (hWB s) + (cavityLinearField_abs_bound M L (a s) t (z s) y hA (haB s) (hzB s))) + · intro s + exact cavityQuadraticField_abs_bound M L (b s) u (z s) y hB hD (hbB s) (hzB s) + have hmean := integral_mono (hzi.sub hri) hqi hpoint + simp only [Pi.sub_apply] at hmean + rw [integral_sub hzi hri] at hmean + have hcost:=cavity_Q_normalized_bound μ M L a b z W ha hb hz hW t u hA hB + (sq_nonneg D) haB hbB hsq hWB hden + exact (sub_le_sub_left hcost _).trans hmean + +theorem cavity_angular_expected_log_drop {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M n : ℕ) + (a b : S→Fin M→ℝ) (R W : S→ℝ) (ha : Measurable a) (hb : Measurable b) + (hR : Measurable R) (hW : Measurable W) (t u : ℝ) + {A B C D : ℝ} (hA : 0≤A) (hB : 0≤B) (hC : 0≤C) (hD : 0≤D) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) + (hRB : ∀ s,|R s|≤D) (hWB : ∀ s,|W s|≤C) : + (∫ y : Fin M→Spin (n+1),Real.log (∫ p : S×NormalizedSpin (n+1),Real.exp + (W p.1+cavityLinearField M (n+1) (a p.1) t (R p.1 •p.2.val) y+ + cavityQuadraticField M (n+1) (b p.1) u (R p.1 •p.2.val) y) + ∂μ.prod (unitSphereLaw (n+1))) ∂Measure.pi (fun _=>stdGaussian (Spin (n+1))))≥ + (∫ y : Fin M→Spin (n+1),Real.log (∫ p : S×NormalizedSpin (n+1),Real.exp + (W p.1+cavityLinearField M (n+1) (a p.1) t (R p.1 •p.2.val) y) + ∂μ.prod (unitSphereLaw (n+1))) ∂Measure.pi (fun _=>stdGaussian (Spin (n+1))))- + Real.exp (2*C+t^2*D^2*M*A^2)* + Real.sqrt (u^2*(D^2)^2*squareGaussianVariance*M*B^2) := by + have hz : Measurable (fun p : S×NormalizedSpin (n+1)=>R p.1 •p.2.val) := by + have hRm : Measurable (fun p : S×NormalizedSpin (n+1)=>R p.1) := hR.comp measurable_fst + fun_prop + have hzB (p : S×NormalizedSpin (n+1)) : ‖R p.1 •p.2.val‖≤D := by + have hu : ‖p.2.val‖=1 := by simp + simpa only [norm_smul,Real.norm_eq_abs,hu,mul_one] using hRB p.1 + exact cavity_expected_log_drop_quadratic (μ.prod (unitSphereLaw (n+1))) M (n+1) + (fun p=>a p.1) (fun p=>b p.1) (fun p=>R p.1 •p.2.val) (fun p=>W p.1) + (ha.comp measurable_fst) (hb.comp measurable_fst) hz (hW.comp measurable_fst) + t u hA hB hC hD (fun p=>haB p.1) (fun p=>hbB p.1) hzB (fun p=>hWB p.1) + (cavity_angular_denominator μ M n a R W ha hR hW t hA haB hRB hWB) + +lemma cavity_quadratic_cost_tendsto_zero (M : ℕ→ℕ) (A B C D α : ℝ) + (hM : Tendsto (fun n=>(M n:ℝ)/(n+1:ℕ)) atTop (𝓝 α)) : + Tendsto (fun n=>Real.exp (2*C+(1/Real.sqrt (n+1:ℕ))^2*D^2*M n*A^2)* + Real.sqrt ((1/(2*(n+1:ℕ)))^2*(D^2)^2*squareGaussianVariance*M n*B^2)) + atTop (𝓝 0) := by + have hN : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have hi : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero.comp hN + have he := ((hM.mul_const (D^2*A^2)).const_add (2*C)).rexp + have hq := (((hM.mul hi).mul_const ((D^2)^2*squareGaussianVariance*B^2/4))).sqrt + have ht := he.mul hq + simp only [mul_zero,zero_mul,Real.sqrt_zero] at ht + apply ht.congr' + filter_upwards [] with n + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + have hs : Real.sqrt (n+1:ℕ)≠0 := (Real.sqrt_pos.mpr hn).ne' + have hs2 := Real.sq_sqrt hn.le + congr 2 + · rw [div_pow,one_pow,hs2] + field_simp + · field_simp + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityFiniteEvaluation.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityFiniteEvaluation.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc598d423ae247a5b14ba4673ed6c4278cf8ac19 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityFiniteEvaluation.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityShellExpansion +import OAI.Probability.Perceptron.Cascade.CavityRPCControl + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma cavity_vector_residual (n : ℕ) (a h : ℝ) (hh : 2*h≤a) (x : Spin (n+1)) : + (∫ y,sphericalExp n (x+Real.sqrt (a-2*h) •y) (Real.sqrt (n+1:ℕ)) + ∂stdGaussian (Spin (n+1)))= + Real.exp ((n+1:ℕ)*(a-2*h)/2)*sphericalExp n x (Real.sqrt (n+1:ℕ)) := by + rw [sphericalExp_gaussian_average,Real.sq_sqrt (by positivity : 0≤((n+1:ℕ):ℝ)), + Real.sq_sqrt (sub_nonneg.mpr hh)] + +theorem cavity_finiteRPC_value (n d k : ℕ) (w h : Fin (k+1)→ℝ) + (q : Fin (k+1)→Time) (hw : ∀ i,0profileGaussianStep (fun l (_ : Fin 1)=>(q l:ℝ)) j 0)) + (cavityRPCTerminal n d + (g.heatLog ⟨1-(q (Fin.last k):ℝ),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ 1).f) k + (cavityRPCRootState n d (Real.sqrt (2*h 0)) (Real.sqrt (q 0:ℝ)) b,η)/ + decoratedTerminalTotal + (cavityRPCStep n d (stepFieldIncrement k h) + (fun j=>profileGaussianStep (fun l (_ : Fin 1)=>(q l:ℝ)) j 0)) + (fun _=>0) k + (cavityRPCRootState n d (Real.sqrt (2*h 0)) (Real.sqrt (q 0:ℝ)) b,η)) + ∂decoratedCascadeLaw (cavityRPCMarkLaw n d) k (stepCumulative w)) + ∂(cavityRPCMarkLaw n d : Measure (CavityRPCMark n d)))= + (n+1:ℕ)*((c+a)/2+finiteSphericalFieldValue n k w h)+ + d*controlValue P g.f (weightedStepTrial w q (fun i=>(hw i).le) hw1) := by + rw [cavity_finiteRPC_roots n d k _ _ _ _ (stepCumulative_strictMono w hw) + (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1)] + rw [cavityScalarRootValue_control k w q (fun i=>(hw i).le) hw1 hq + (stepCumulative_pos w hw) g P hB] + have he:=finiteAmplitudeSphereValue_fieldAmplitudes n k w h hh0 + unfold finiteAmplitudeSphereValue at he + rw [fieldAmplitudes_increment,fieldAmplitudes_last] at he + rw [he] + ring + +lemma gaussianBlockJoin_preserving (N L : ℕ) : + MeasurePreserving (gaussianBlockJoin N L) + ((stdGaussian (Spin N)).prod (stdGaussian (Spin L))) + (stdGaussian (Spin (N+L))) := by + refine ⟨gaussianBlockJoin_measurable N L,?_⟩ + rw [←(gaussianBlockSplit_preserving N L).map_eq, + Measure.map_map (gaussianBlockJoin_measurable N L) (gaussianBlockSplit_measurable N L)] + simp only [Function.comp_def,gaussianBlockJoin_split] + exact Measure.map_id + +lemma stdGaussian_ofLp_preserving (N : ℕ) : + MeasurePreserving (WithLp.ofLp : Spin N→Fin N→ℝ) (stdGaussian (Spin N)) + (Measure.pi fun _=>gaussianReal 0 1) := by + refine ⟨(PiLp.continuous_ofLp 2 _).measurable,?_⟩ + rw [←map_pi_eq_stdGaussian, + Measure.map_map (PiLp.continuous_ofLp 2 _).measurable (PiLp.continuous_toLp 2 _).measurable] + exact Measure.map_id + +lemma cavityJoinedPatterns_preserving (N L M : ℕ) : + MeasurePreserving (fun p : (Fin M→Fin N→ℝ)×(Fin M→Spin L)=> + cavityJoinedPatterns N L M p.1 p.2) + ((Measure.pi fun _ : Fin M=>Measure.pi fun _ : Fin N=>gaussianReal 0 1).prod + (Measure.pi fun _ : Fin M=>stdGaussian (Spin L))) + (Measure.pi fun _ : Fin M=>Measure.pi fun _ : Fin (N+L)=>gaussianReal 0 1) := by + have ht : MeasurePreserving (WithLp.toLp 2 : (Fin N→ℝ)→Spin N) + (Measure.pi fun _=>gaussianReal 0 1) (stdGaussian (Spin N)) := + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + have hj := (stdGaussian_ofLp_preserving (N+L)).comp + ((gaussianBlockJoin_preserving N L).comp (ht.prod (MeasurePreserving.id _))) + have hp := measurePreserving_pi (fun _ : Fin M=>(Measure.pi fun _ : Fin N=>gaussianReal 0 1).prod + (stdGaussian (Spin L))) (fun _ : Fin M=>Measure.pi fun _ : Fin (N+L)=>gaussianReal 0 1) + (fun _=>hj) + have hr := (measurePreserving_arrowProdEquivProdArrow (Fin N→ℝ) (Spin L) (Fin M) + (fun _=>Measure.pi fun _=>gaussianReal 0 1) (fun _=>stdGaussian (Spin L))).symm + convert hp.comp hr using 1 + funext p i j + rfl + +lemma cavity_log_uniform_change {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {F G : S→ℝ} + (hF : Measurable F) (hG : Measurable G) {A E : ℝ} (hA : 0≤A) + (hFA : ∀ s,|F s|≤A) (hE : ∀ s,|F s-G s|≤E) : + |Real.log (∫ s,Real.exp (F s) ∂μ)-Real.log (∫ s,Real.exp (G s) ∂μ)|≤E := by + have hGA (s : S) : |G s|≤A+|E| := by + calc + _=|G s-F s+F s| := by ring_nf + _≤|G s-F s|+|F s| := abs_add_le _ _ + _≤|E|+A := add_le_add ((show |G s-F s|≤E by simpa only [abs_sub_comm] using hE s).trans (le_abs_self E)) (hFA s) + _=A+|E| := add_comm _ _ + have hFi : Integrable (fun s=>Real.exp (F s)) μ := by + apply Integrable.of_bound hF.exp.aestronglyMeasurable (Real.exp A) + exact ae_of_all _ fun s=>by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans (hFA s)) + have hGi : Integrable (fun s=>Real.exp (G s)) μ := by + apply Integrable.of_bound hG.exp.aestronglyMeasurable (Real.exp (A+|E|)) + exact ae_of_all _ fun s=>by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans (hGA s)) + exact abs_log_integral_exp_sub_le μ hFi hGi + (by simpa only [tiltPartition,one_mul] using tilt_partition_pos μ hF hA hFA 1) + (by simpa only [tiltPartition,one_mul] using tilt_partition_pos μ hG (by positivity) hGA 1) hE + +lemma cavityShellTaylorModel_measurable (n L M : ℕ) (f : Jet3) + (a : Fin M→Fin (n+1)→ℝ) (y : Fin M→Spin L) : + Measurable (cavityShellTaylorModel n L M f a y) := by + have h0 := f.f.continuous.measurable + have h1 := f.d1.continuous.measurable + have h2 := f.d2.continuous.measurable + unfold cavityShellTaylorModel normalizedPatternEnergy cavityLinearField cavityQuadraticField bulkC + fun_prop + +theorem cavity_true_shell_log_expansion (n L M : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (hn : 2*(L+1)≤n+1) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) + (a : Fin M→Fin (n+1)→ℝ) (y : Fin M→Spin L) (v : ℕ→ℝ) (g : BulkMark (n+1)) : + |Real.log (∫ s,Real.exp (cavityShellPatternEnergy n L M f.f + (cavityJoinedPatterns (n+1) L M a y) s+inner ℝ (bulkFeature (n+1) v s.1) g) + ∂cavityShellBaseLaw n L)- + Real.log (∫ s,Real.exp (cavityShellTaylorModel n L M f a y s+ + inner ℝ (bulkFeature (n+1) v s.1) g) ∂cavityShellBaseLaw n L)|≤ + ∑ i,cavityRemainderMajorant (cavityRemainderCoefficients f h1 h2 h3 L (L+1)) (n+1:ℕ) ‖y i‖ := by + let := cavityShellBaseLaw_probability n L hp + have hm : Measurable (fun s : CavityShellSpin n L=>inner ℝ (bulkFeature (n+1) v s.1) g) := + (((bulkFeature_continuous (n+1) v).measurable.comp measurable_fst).inner measurable_const) + apply cavity_log_uniform_change (cavityShellBaseLaw n L) + ((cavityShellPatternEnergy_measurable n L M f.f _).add hm) + ((cavityShellTaylorModel_measurable n L M f a y).add hm) + (A:=M*‖f.f‖+bulkFeatureBound (n+1) v*‖g‖) + (add_nonneg (by positivity) (mul_nonneg (by unfold bulkFeatureBound; positivity) (norm_nonneg _))) + · intro s + apply (abs_add_le _ _).trans + apply add_le_add (cavityShellPatternEnergy_bound n L M f.f _ s) + simpa only [bulkFeature_norm] using abs_real_inner_le_norm (bulkFeature (n+1) v s.1) g + · intro s + simpa only [Pi.add_apply,add_sub_add_right_eq_sub] using cavity_true_shell_expansion n L M f h1 h2 h3 hn a y s + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityFiniteIncrement.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityFiniteIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..9171cfab19fceb00734816f5d62d5a7d3a6bfefb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityFiniteIncrement.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityOldExpectation + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +theorem cavity_finite_increment_lower (n k M d : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (hn : 2*((k+1)+1)≤n+1) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (v : ℕ→ℝ) {C : ℝ} (hC : 0≤C) (hv : ∀ j,|v (j+1)|≤C) : + Real.log ((cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1)))- + Real.pi*cavityBulkCovarianceError n (k+1) C (3*((k+1:ℕ)+1))- + cavityOldError n k M d f h1 h2 h3- + ‖f.d1‖*d*((k+1:ℕ)+1)*(1+Real.sqrt (k+1))/Real.sqrt (n+1:ℕ)+ + cavityBulkFullLog k d n M f v ≤ + bulkExpectedLog (n+(k+1)) (M+d) f.f v-bulkExpectedLog n M f.f v := by + have hs:=cavity_expected_shell_restriction n (k+1) (M+d) f.f v hC hv hp + have hf:=cavity_fresh_expected_lower n (k+1) M d f v hp + have ho:=cavity_proxy_expected_lower n k M d f h1 h2 h3 hn hp v + simp only [Nat.cast_add,Nat.cast_one] at * + linarith + +def cavityUniformError (n k M D : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (C KC : ℝ) : ℝ := + Real.pi*cavityBulkCovarianceError n (k+1) C (3*((k+1:ℕ)+1))+ + Real.exp (2*(D*‖f.f‖+((k+1:ℕ)+1)*KC/2)+(Real.sqrt (n+1:ℕ))⁻¹^2*((k+1:ℕ)+1)^2*M*‖f.d1‖^2)* + Real.sqrt ((1/(2*(n+1:ℕ)))^2*(((k+1:ℕ)+1)^2)^2*squareGaussianVariance*M*‖f.d2‖^2)+ + (∫ y : Fin M→Spin (k+1),∑ i,cavityRemainderMajorant + (cavityRemainderCoefficients f h1 h2 h3 (k+1) ((k+1)+1)) (n+1:ℕ) ‖y i‖ + ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))+ + ‖f.d1‖*D*((k+1:ℕ)+1)*(1+Real.sqrt (k+1))/Real.sqrt (n+1:ℕ) + +lemma cavityUniformError_tendsto (k D : ℕ) (M : ℕ→ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (C KC : ℝ) {α : ℝ} + (hM : Tendsto (fun n=>(M n:ℝ)/(n+1:ℕ)) atTop (𝓝 α)) : + Tendsto (fun n=>cavityUniformError n k (M n) D f h1 h2 h3 C KC) atTop (𝓝 0) := by + have hc:=(cavityBulkCovarianceError_tendsto (k+1) C (by positivity : (0:ℝ)≤3*((k+1:ℕ)+1))).const_mul Real.pi + have hq:=cavity_quadratic_cost_tendsto_zero M ‖f.d1‖ ‖f.d2‖ + (D*‖f.f‖+((k+1:ℕ)+1)*KC/2) ((k+1:ℕ)+1) α hM + have hr:=cavityRemainderMajorant_row_tendsto M (k+1) + (cavityRemainderCoefficients f h1 h2 h3 (k+1) ((k+1)+1)) hM + have hN : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have hf:=(tendsto_inv_atTop_zero.comp (Real.tendsto_sqrt_atTop.comp hN)).const_mul + (‖f.d1‖*D*((k+1:ℕ)+1)*(1+Real.sqrt (k+1))) + convert ((hc.add hq).add hr).add hf using 1 <;> + simp [cavityUniformError,div_eq_mul_inv] + +lemma cavity_finite_increment_uniform (n k M d D : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (hn : 2*((k+1)+1)≤n+1) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (v : ℕ→ℝ) {C KC : ℝ} (hC : 0≤C) (hv : ∀ j,|v (j+1)|≤C) + (hd : d≤D) (hK : M/(n+1:ℕ)*‖f.dilationMark h1‖≤KC) : + Real.log ((cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1)))-KC/2- + cavityUniformError n k M D f h1 h2 h3 C KC+cavityBulkFullLog k d n M f v ≤ + bulkExpectedLog (n+(k+1)) (M+d) f.f v-bulkExpectedLog n M f.f v := by + have hinc:=cavity_finite_increment_lower n k M d f h1 h2 h3 hn hp v hC hv + have hd' : (d:ℝ)≤D:=by exact_mod_cast hd + have hE : d*‖f.f‖+((k+1:ℕ)+1)*(M/(n+1:ℕ)*‖f.dilationMark h1‖)/2≤ + D*‖f.f‖+((k+1:ℕ)+1)*KC/2 := by gcongr + have hq : + Real.exp (2*(d*‖f.f‖+((k+1:ℕ)+1)*(M/(n+1:ℕ)*‖f.dilationMark h1‖)/2)+(Real.sqrt (n+1:ℕ))⁻¹^2*((k+1:ℕ)+1)^2*M*‖f.d1‖^2)* + Real.sqrt ((1/(2*(n+1:ℕ)))^2*(((k+1:ℕ)+1)^2)^2*squareGaussianVariance*M*‖f.d2‖^2) ≤ + Real.exp (2*(D*‖f.f‖+((k+1:ℕ)+1)*KC/2)+(Real.sqrt (n+1:ℕ))⁻¹^2*((k+1:ℕ)+1)^2*M*‖f.d1‖^2)* + Real.sqrt ((1/(2*(n+1:ℕ)))^2*(((k+1:ℕ)+1)^2)^2*squareGaussianVariance*M*‖f.d2‖^2) := by + gcongr + have hf : ‖f.d1‖*d*((k+1:ℕ)+1)*(1+Real.sqrt (k+1))/Real.sqrt (n+1:ℕ)≤ + ‖f.d1‖*D*((k+1:ℕ)+1)*(1+Real.sqrt (k+1))/Real.sqrt (n+1:ℕ) := by gcongr + dsimp only [cavityOldError] at hinc + dsimp only [cavityUniformError] + simp only [Nat.cast_add,Nat.cast_one] at * + linarith + + +lemma cavitySplitPartition_lower (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : BulkDisorder (m+1) M) (y : Fin M→Spin (n+1)) (b : Fin d→Fin (m+1)→ℝ) + {KC : ℝ} (hC : ∀ x,|bulkC (m+1) M f a.1 x|≤KC) : + Real.exp (-(d:ℝ)*‖f.f‖-(n+1:ℕ)*KC/2) ≤ cavitySplitPartition n d m M f v (a,y,b) := by + let μ:=tiltLaw (unitSphereLaw (m+1)) (bulkHamiltonian (m+1) M f.f v a.1 a.2) 1 + have : IsProbabilityMeasure μ := tilt_law_probability_of_integrable _ + (by simpa only [one_mul] using bulkHamiltonian_exp_integrable m M f.f v a) + let F:=fun x : NormalizedSpin (m+1)=>Real.exp (normalizedPatternEnergy (m+1) d f.f b x+ + (n+1:ℕ)*bulkC (m+1) M f a.1 x/2)* + sphericalExp n (cavityVectorField M (n+1) (fun t=>f.d1 (∑ i,a.1 t i*x.val i)) + (Real.sqrt (m+1:ℕ))⁻¹ y) (Real.sqrt (n+1:ℕ)) + have hw : Continuous (normalizedPatternEnergy (m+1) d f.f b) := + (normalizedPatternEnergy_continuous (m+1) d f.f).comp (continuous_const.prodMk continuous_id) + have hc : Continuous (bulkC (m+1) M f a.1) := by unfold bulkC; fun_prop + have hv : Continuous (fun x : NormalizedSpin (m+1)=>cavityVectorField M (n+1) + (fun t=>f.d1 (∑ i,a.1 t i*x.val i)) (Real.sqrt (m+1:ℕ))⁻¹ y) := by + unfold cavityVectorField + fun_prop + have hi : Integrable F μ := ((hw.add ((continuous_const.mul hc).div_const 2)).rexp.mul + ((sphericalExp_continuous n _).comp hv)).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + change _≤∫ x,F x ∂μ + calc + _=(∫ _ : NormalizedSpin (m+1),Real.exp (-(d:ℝ)*‖f.f‖-(n+1:ℕ)*KC/2) ∂μ) := by simp + _≤_ := integral_mono (integrable_const _) hi (fun x=>by + have hb:=(abs_le.mp (normalizedPatternEnergy_bound (m+1) d f.f b x)).1 + have hc':=(abs_le.mp (hC x)).1 + have hs := mul_le_mul_of_nonneg_left hc' (show (0:ℝ)≤(n+1:ℕ) from by positivity) + dsimp only [F] + calc + _≤Real.exp (normalizedPatternEnergy (m+1) d f.f b x+(n+1:ℕ)*bulkC (m+1) M f a.1 x/2) := + Real.exp_le_exp.mpr (by nlinarith) + _≤_ := le_mul_of_one_le_right (Real.exp_pos _).le (one_le_sphericalExp n _ _)) + +lemma cavitySplitLog_lower (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : BulkDisorder (m+1) M) (y : Fin M→Spin (n+1)) (b : Fin d→Fin (m+1)→ℝ) + {KC : ℝ} (hC : ∀ x,|bulkC (m+1) M f a.1 x|≤KC) : + -(d:ℝ)*‖f.f‖-(n+1:ℕ)*KC/2 ≤ Real.log (cavitySplitPartition n d m M f v (a,y,b)) := by + have h:=cavitySplitPartition_lower n d m M f v a y b hC + simpa only [Real.log_exp] using Real.log_le_log (Real.exp_pos _) h + +lemma cavityBulkFullLog_lower (n d m M : ℕ) (f : Jet3) + (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℝ) + {KC : ℝ} (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤KC) : + -(d:ℝ)*‖f.f‖-(n+1:ℕ)*KC/2 ≤ cavityBulkFullLog n d m M f v := by + let G:=fun p : CavityProxyRandom m (n+1) M d=>Real.log (cavitySplitPartition n d m M f v (p.1,p.2.2,p.2.1)) + have hi : Integrable G (cavityProxyLaw m (n+1) M d):=cavitySplitLog_proxy_integrable m n M d f hf v + have he: (∫ p,G p ∂cavityProxyLaw m (n+1) M d)=cavityBulkFullLog n d m M f v := by + unfold cavityProxyLaw + rw [cavity_three_integral _ _ _ G hi,cavityBulkFullLog_split n d m M f hf v] + rw [←he] + calc + _=(∫ _ : CavityProxyRandom m (n+1) M d,-(d:ℝ)*‖f.f‖-(n+1:ℕ)*KC/2 ∂cavityProxyLaw m (n+1) M d) := by simp + _≤_ := integral_mono (integrable_const _) hi (fun p=>cavitySplitLog_lower n d m M f v p.1 p.2.2 p.2.1 (hC p.1)) +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityFreshReplacement.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityFreshReplacement.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb647f205dfc7d7ab926502d48b7ca3731a00692 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityFreshReplacement.lean @@ -0,0 +1,206 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityFiniteEvaluation + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavityNormMoment_two (N : ℕ) : cavityNormMoment N 2=N := by + unfold cavityNormMoment + rw [←map_pi_eq_stdGaussian,integral_map (by fun_prop) (by fun_prop)] + simp only [EuclideanSpace.real_norm_sq_eq] + rw [integral_finsetSum] + · simp_rw [integral_comp_eval (μ:=fun _ : Fin N=>gaussianReal 0 1) + (f:=fun y : ℝ=>y^2) (by fun_prop),gaussian_square_mean] + simp + · intro i _ + exact ((gaussian_square_memLp_two 1).comp_measurePreserving + (measurePreserving_eval _ i)).integrable (by norm_num) + +lemma cavityNormMoment_one_le (N : ℕ) : cavityNormMoment N 1≤Real.sqrt N := by + have h := cavity_exp_abs_cauchy (stdGaussian (Spin N)) + (H:=fun _=>0) (Q:=fun y=>‖y‖) + (by simpa using (memLp_const (1:ℝ) : MemLp (fun _ : Spin N=>(1:ℝ)) 2 (stdGaussian (Spin N)))) + ((IsGaussian.memLp_id (stdGaussian (Spin N)) 2 (by norm_num)).norm) + simp only [Real.exp_zero,one_mul,abs_of_nonneg (norm_nonneg _),mul_zero, + integral_const,probReal_univ,smul_eq_mul,Real.sqrt_one] at h + have he : (∫ y : Spin N,‖y‖^2 ∂stdGaussian (Spin N))=N := cavityNormMoment_two N + rw [he] at h + simpa only [cavityNormMoment,pow_one] using h + +def cavityFreshMajorant (N L d : ℕ) (f : Jet3) + (a : Fin d→Fin N→ℝ) (y : Fin d→Spin L) : ℝ := + ‖f.d1‖*∑ i,(((L:ℝ)+1)/(N+L:ℕ)*‖WithLp.toLp 2 (a i)‖+ + ((L:ℝ)+1)/Real.sqrt (N+L:ℕ)*‖y i‖) + +lemma cavity_fresh_pattern_error (n L : ℕ) (f : Jet3) (a : Fin (n+1)→ℝ) + (y : Spin L) (s : CavityShellSpin n L) : + |f.f (cavityRho (n+1) L s.2.val*(∑ j,a j*s.1.val j)+ + inner ℝ s.2.val y/Real.sqrt (n+1+L:ℕ))-f.f (∑ j,a j*s.1.val j)|≤ + ‖f.d1‖*(((L:ℝ)+1)/(n+1+L:ℕ)*‖WithLp.toLp 2 a‖+ + ((L:ℝ)+1)/Real.sqrt (n+1+L:ℕ)*‖y‖) := by + have hp : (0:ℝ)<(n+1+L:ℕ) := by positivity + have hz := s.2.prop.2 + have hD : ‖s.2.val‖^2≤(n+1+L:ℕ) := by + simp only [Nat.cast_add,Nat.cast_one] at * + nlinarith [Nat.cast_nonneg (α:=ℝ) n] + have hr := cavityRho_bounds (n+1) L s.2.val (by omega) hD + have hz1 : ‖s.2.val‖≤(L:ℝ)+1 := by + nlinarith [sq_nonneg (‖s.2.val‖-1),Nat.cast_nonneg (α:=ℝ) L] + have hx : ‖s.1.val‖=1 := by + simpa only [Metric.mem_sphere,dist_zero_right] using s.1.prop + have ha : |∑ j,a j*s.1.val j|≤‖WithLp.toLp 2 a‖ := by + have hi := abs_real_inner_le_norm s.1.val (WithLp.toLp 2 a) + simpa only [EuclideanSpace.inner_eq_star_dotProduct,dotProduct, + starRingEnd_apply,star_trivial,PiLp.toLp_apply,hx,one_mul] using hi + have hi : |inner ℝ s.2.val y|≤((L:ℝ)+1)*‖y‖ := + (abs_real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right hz1 (norm_nonneg _)) + have hl := f.lipschitz.dist_le_mul + (cavityRho (n+1) L s.2.val*(∑ j,a j*s.1.val j)+inner ℝ s.2.val y/Real.sqrt (n+1+L:ℕ)) + (∑ j,a j*s.1.val j) + simp only [Real.dist_eq,coe_nnnorm] at hl + apply hl.trans + apply mul_le_mul_of_nonneg_left _ (norm_nonneg _) + rw [show cavityRho (n+1) L s.2.val*(∑ j,a j*s.1.val j)+inner ℝ s.2.val y/Real.sqrt (n+1+L:ℕ)- + (∑ j,a j*s.1.val j)=(cavityRho (n+1) L s.2.val-1)*(∑ j,a j*s.1.val j)+ + inner ℝ s.2.val y/Real.sqrt (n+1+L:ℕ) by ring] + apply (abs_add_le _ _).trans + rw [abs_mul,abs_div,abs_of_pos (Real.sqrt_pos.mpr hp),abs_of_nonpos (sub_nonpos.mpr hr.2.1)] + apply add_le_add + · have hb := hr.2.2.trans (div_le_div_of_nonneg_right hz hp.le) + exact mul_le_mul (by simpa only [neg_sub] using hb) ha (abs_nonneg _) (by positivity) + · simpa only [div_mul_eq_mul_div] using div_le_div_of_nonneg_right hi (Real.sqrt_nonneg _) + +lemma cavity_fresh_pattern_sum_error (n L d : ℕ) (f : Jet3) + (a : Fin d→Fin (n+1)→ℝ) (y : Fin d→Spin L) (s : CavityShellSpin n L) : + |cavityShellPatternEnergy n L d f.f (cavityJoinedPatterns (n+1) L d a y) s- + normalizedPatternEnergy (n+1) d f.f a s.1|≤cavityFreshMajorant (n+1) L d f a y := by + rw [cavityShellPatternEnergy_join] + unfold normalizedPatternEnergy cavityFreshMajorant + rw [←Finset.sum_sub_distrib,Finset.mul_sum] + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro i hi + simpa only [cavityRho,Nat.cast_add,Nat.cast_one] using cavity_fresh_pattern_error n L f (a i) (y i) s + +lemma cavity_fresh_log_replacement (n L d : ℕ) (f : Jet3) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) + (H : CavityShellSpin n L→ℝ) (hH : Measurable H) {A : ℝ} + (hA : 0≤A) (hHA : ∀ s,|H s|≤A) + (a : Fin d→Fin (n+1)→ℝ) (y : Fin d→Spin L) : + |Real.log (∫ s,Real.exp (H s+cavityShellPatternEnergy n L d f.f + (cavityJoinedPatterns (n+1) L d a y) s) ∂cavityShellBaseLaw n L)- + Real.log (∫ s,Real.exp (H s+normalizedPatternEnergy (n+1) d f.f a s.1) + ∂cavityShellBaseLaw n L)|≤cavityFreshMajorant (n+1) L d f a y := by + let := cavityShellBaseLaw_probability n L hp + have hnew := cavityShellPatternEnergy_measurable n L d f.f + (cavityJoinedPatterns (n+1) L d a y) + have hold : Measurable (fun s : CavityShellSpin n L=>normalizedPatternEnergy (n+1) d f.f a s.1) := by + unfold normalizedPatternEnergy + have hc := f.f.continuous.measurable + fun_prop + apply cavity_log_uniform_change (cavityShellBaseLaw n L) (hH.add hnew) (hH.add hold) + (A:=A+d*‖f.f‖) (add_nonneg hA (by positivity)) + · intro s + exact (abs_add_le _ _).trans (add_le_add (hHA s) (cavityShellPatternEnergy_bound n L d f.f _ s)) + · intro s + simpa only [Pi.add_apply,add_sub_add_left_eq_sub] using cavity_fresh_pattern_sum_error n L d f a y s + +lemma cavity_row_norm_integrable (d L : ℕ) : + Integrable (fun y : Fin d→Spin L=>∑ i,‖y i‖) (Measure.pi (fun _=>stdGaussian (Spin L))) := by + apply integrable_finsetSum + intro i hi + simpa only [pow_one,Function.comp_def,Function.eval] using ((measurePreserving_eval (fun _ : Fin d=>stdGaussian (Spin L)) i).integrable_comp_of_integrable + (cavityNormMoment_integrable L 1)) + +lemma cavity_row_norm_mean (d L : ℕ) : + (∫ y : Fin d→Spin L,∑ i,‖y i‖ ∂Measure.pi (fun _=>stdGaussian (Spin L)))= + d*cavityNormMoment L 1 := by + rw [integral_finsetSum] + · simp_rw [integral_comp_eval (μ:=fun _ : Fin d=>stdGaussian (Spin L)) + (f:=fun y : Spin L=>‖y‖) (by fun_prop)] + simp [cavityNormMoment] + · intro i hi + simpa only [pow_one,Function.comp_def,Function.eval] using ((measurePreserving_eval (fun _ : Fin d=>stdGaussian (Spin L)) i).integrable_comp_of_integrable + (cavityNormMoment_integrable L 1)) + +lemma cavityFreshMajorant_integrable (N L d : ℕ) (f : Jet3) : + Integrable (fun p : (Fin d→Spin N)×(Fin d→Spin L)=> + cavityFreshMajorant N L d f (fun i=>WithLp.ofLp (p.1 i)) p.2) + ((Measure.pi (fun _=>stdGaussian (Spin N))).prod (Measure.pi (fun _=>stdGaussian (Spin L)))) := by + simp only [cavityFreshMajorant,WithLp.toLp_ofLp,Finset.sum_add_distrib,←Finset.mul_sum] + exact ((((cavity_row_norm_integrable d N).comp_fst (Measure.pi (fun _ : Fin d=>stdGaussian (Spin L)))).const_mul _).add + (((cavity_row_norm_integrable d L).comp_snd (Measure.pi (fun _ : Fin d=>stdGaussian (Spin N)))).const_mul _)).const_mul _ + +lemma cavityFreshMajorant_mean (N L d : ℕ) (f : Jet3) : + (∫ p : (Fin d→Spin N)×(Fin d→Spin L), + cavityFreshMajorant N L d f (fun i=>WithLp.ofLp (p.1 i)) p.2 + ∂(Measure.pi (fun _=>stdGaussian (Spin N))).prod (Measure.pi (fun _=>stdGaussian (Spin L))))= + ‖f.d1‖*d*(((L:ℝ)+1)/(N+L:ℕ)*cavityNormMoment N 1+ + ((L:ℝ)+1)/Real.sqrt (N+L:ℕ)*cavityNormMoment L 1) := by + simp only [cavityFreshMajorant,WithLp.toLp_ofLp,Finset.sum_add_distrib,←Finset.mul_sum] + rw [integral_const_mul,integral_add + (((cavity_row_norm_integrable d N).comp_fst (Measure.pi (fun _ : Fin d=>stdGaussian (Spin L)))).const_mul _) + (((cavity_row_norm_integrable d L).comp_snd (Measure.pi (fun _ : Fin d=>stdGaussian (Spin N)))).const_mul _)] + simp only [integral_const_mul] + rw [integral_fun_fst (fun a : Fin d→Spin N=>∑ i,‖a i‖), + integral_fun_snd (fun y : Fin d→Spin L=>∑ i,‖y i‖)] + simp only [probReal_univ,one_smul,cavity_row_norm_mean] + ring + +lemma cavityFreshMajorant_mean_bound (n L d : ℕ) (f : Jet3) : + (∫ p : (Fin d→Spin (n+1))×(Fin d→Spin L), + cavityFreshMajorant (n+1) L d f (fun i=>WithLp.ofLp (p.1 i)) p.2 + ∂(Measure.pi (fun _=>stdGaussian (Spin (n+1)))).prod (Measure.pi (fun _=>stdGaussian (Spin L))))≤ + ‖f.d1‖*d*((L:ℝ)+1)*(1+Real.sqrt L)/Real.sqrt (n+1:ℕ) := by + rw [cavityFreshMajorant_mean] + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + have hnL : ((n+1:ℕ):ℝ)≤(n+1+L:ℕ) := by exact_mod_cast Nat.le_add_right (n+1) L + have ha : ((L:ℝ)+1)/(n+1+L:ℕ)*cavityNormMoment (n+1) 1≤ + ((L:ℝ)+1)/Real.sqrt (n+1:ℕ) := by + calc + _≤((L:ℝ)+1)/(n+1+L:ℕ)*Real.sqrt (n+1:ℕ) := + mul_le_mul_of_nonneg_left (cavityNormMoment_one_le _) (by positivity) + _≤((L:ℝ)+1)/(n+1:ℕ)*Real.sqrt (n+1:ℕ) := + mul_le_mul_of_nonneg_right (div_le_div_of_nonneg_left (by positivity) hn hnL) (Real.sqrt_nonneg _) + _=((L:ℝ)+1)/Real.sqrt (n+1:ℕ) := by + rw [div_mul_eq_mul_div,mul_div_assoc,Real.sqrt_div_self'] + ring + have hb : ((L:ℝ)+1)/Real.sqrt (n+1+L:ℕ)*cavityNormMoment L 1≤ + ((L:ℝ)+1)/Real.sqrt (n+1:ℕ)*Real.sqrt L := by + exact (mul_le_mul_of_nonneg_left (cavityNormMoment_one_le L) (by positivity)).trans + (mul_le_mul_of_nonneg_right + (div_le_div_of_nonneg_left (by positivity) (Real.sqrt_pos.mpr hn) (Real.sqrt_le_sqrt hnL)) + (Real.sqrt_nonneg _)) + apply (mul_le_mul_of_nonneg_left (add_le_add ha hb) (by positivity : 0≤‖f.d1‖*(d:ℝ))).trans_eq + ring + +lemma cavityFreshMajorant_mean_tendsto (D L : ℕ) (d : ℕ→ℕ) (hd : ∀ n,d n≤D) (f : Jet3) : + Tendsto (fun n=>∫ p : (Fin (d n)→Spin (n+1))×(Fin (d n)→Spin L), + cavityFreshMajorant (n+1) L (d n) f (fun i=>WithLp.ofLp (p.1 i)) p.2 + ∂(Measure.pi (fun _=>stdGaussian (Spin (n+1)))).prod (Measure.pi (fun _=>stdGaussian (Spin L)))) + atTop (𝓝 0) := by + have hN : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have hs := tendsto_inv_atTop_zero.comp (Real.tendsto_sqrt_atTop.comp hN) + have ht := hs.const_mul (‖f.d1‖*D*((L:ℝ)+1)*(1+Real.sqrt L)) + simp only [mul_zero] at ht + apply squeeze_zero (fun n=>?_) (fun n=>?_) ht + · apply integral_nonneg + intro p + unfold cavityFreshMajorant + positivity + · apply (cavityFreshMajorant_mean_bound n L (d n) f).trans + rw [div_eq_mul_inv] + apply mul_le_mul_of_nonneg_right _ (inv_nonneg.mpr (Real.sqrt_nonneg _)) + apply mul_le_mul_of_nonneg_right _ (by positivity) + apply mul_le_mul_of_nonneg_right _ (by positivity) + exact mul_le_mul_of_nonneg_left (by exact_mod_cast hd n) (norm_nonneg _) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityFullEvaluation.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityFullEvaluation.lean new file mode 100644 index 0000000000000000000000000000000000000000..45dba29238c11529218d02201b9a505edfd2b4b1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityFullEvaluation.lean @@ -0,0 +1,140 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityFullLog +import OAI.Probability.Perceptron.Cavity.CavityGaussianTransport +import OAI.Probability.Perceptron.Cascade.CascadeConstant + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction NNReal + +theorem cavityLabel_full_evaluation (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (f : ℝ→ᵇℝ) (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0Real.sqrt (cavityPairDiagonal n d D i-q (Fin.last k) i) + (∫ t,Real.log (cavityLabelFullPartition n d k f σ q t) + ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw)= + (n+1:ℕ)*a/2+∫ b,finiteCascadeLogRecursion (cavityRPCMarkLaw n d) + (cavityRPCStep n d (stepFieldIncrement k (fun l=>(p l).2.val/2)) + (fun j=>profileGaussianStep (fun l (_ : Fin 1)=>(p l).1.val) j 0)) k z + (cavityRPCTerminal n d (heatLogBCF s 1 f)) + (cavityRPCRootState n d (Real.sqrt (p 0).2.val) (Real.sqrt (p 0).1.val) b) + ∂(cavityRPCMarkLaw n d : Measure (CavityRPCMark n d)) := by + let c : ℝ:=(n+1:ℕ)*a/2 + let σ:=stepFieldIncrement k (fun l=>(p l).2.val/2) + let τ:=fun j=>profileGaussianStep (fun l (_ : Fin 1)=>(p l).1.val) j 0 + let F:=heatLogBCF s 1 f + let G:=cavityRPCTerminal n d F ∘ cavityGaussianState n d + let step:=gaussianLinearMarkStep (fun j=>diagonalMark (Sum.elim (fun _ : Fin (n+1)=>σ j) (fun _ : Fin d=>τ j))) + let H:=fun v : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)=> + c+logSphericalExp n (Real.sqrt (n+1:ℕ)) (gaussianSumSplit v).1+∑ i,heatLog s 1 f (v (Sum.inr i)) + have hH : Measurable H := by + apply (measurable_const.add ((logSphericalExp_lipschitz n _).continuous.measurable.comp + gaussianSumSplit_measurable.fst)).add + apply Finset.measurable_sum + intro i _hi + exact (heatLog_continuous s 1 f).measurable.comp + ((measurable_pi_apply (Sum.inr i)).comp (MeasurableEquiv.toLp 2 _).symm.measurable) + have hterm : (fun x : ℕ→EuclideanSpace ℝ (Fin (n+1)⊕Fin d)=>H (x 0))=(fun x=>c+G x) := + funext (cavityGaussian_terminal n d f a s) + have hstep : (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep (cavityPairProfile n d p) j)))=step := by + simp only [cavityPairProfile_step] + rfl + have hf0 : finiteCascadeFractionalIntegrable (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) step G k z := + cavityGaussian_fractional n d k σ τ F z hz0 + have hf : finiteCascadeFractionalIntegrable (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep (cavityPairProfile n d p) j))) + (fun x=>H (x 0)) k z := by + rw [hterm,hstep] + exact finiteCascadeFractionalIntegrable_add_constant _ step G k z hz0 hf0 c + have hc:=cavityLabel_full_log_recursion n d p D hp0 hpm hpD f z hz hz0 hz1 H hH + (cavityPair_residual_formula n d p D f a s ha hs) hf + let R:=fun b=>finiteCascadeLogRecursion (cavityRPCMarkLaw n d) (cavityRPCStep n d σ τ) k z + (cavityRPCTerminal n d F) (cavityRPCRootState n d (Real.sqrt (p 0).2.val) (Real.sqrt (p 0).1.val) b) + have hR : Measurable R := by + apply (finiteCascadeLogRecursion_measurable _ _ (cavityRPCStep_measurable n d σ τ) k z + (cavityRPCTerminal_measurable n d F)).comp + unfold cavityRPCRootState + fun_prop + have he y : finiteCascadeLogRecursion (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep (cavityPairProfile n d p) j))) k z + (fun x=>H (x 0)) (fun _=>diagonalMark (profileGaussianRoot (cavityPairProfile n d p)) y)= + c+R (cavityGaussianMark n d y) := by + rw [hterm,hstep,finiteCascadeLogRecursion_add_constant _ step G k z hz0 hf0 c] + rw [finiteCascadeLogRecursion_transport (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) (cavityRPCMarkLaw n d) step (cavityRPCStep n d σ τ) + (cavityRPCStep_measurable n d σ τ) (cavityGaussianState n d) (cavityGaussianMark n d) + (cavityGaussianMark_preserving n d) (cavityGaussianState_step n d σ τ) + (cavityRPCTerminal n d F) (cavityRPCTerminal_measurable n d F) k z] + rw [cavityGaussianState_root] + have hri : Integrable (fun y=>R (cavityGaussianMark n d y)) + (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) := by + apply (hc.1.sub (integrable_const c)).congr + exact ae_of_all _ fun y=>by dsimp only [Pi.sub_apply]; rw [he]; ring + dsimp only + rw [hc.2] + simp_rw [he] + rw [integral_add (integrable_const c) hri] + simp only [integral_const,probReal_univ,one_smul] + have ht:=cavityGaussianMark_preserving n d + rw [←integral_map ht.measurable.aemeasurable hR.aestronglyMeasurable,ht.map_eq] + +theorem cavityLabel_full_value (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (q : Fin (k+1)→Time) (hpR : ∀ l,(p l).1.val=(q l:ℝ)) (hDR : D.1.val=1) + (w : Fin (k+1)→ℝ) (hw : ∀ l,0Real.sqrt (cavityPairDiagonal n d D i-Q (Fin.last k) i) + (∫ t,Real.log (cavityLabelFullPartition n d k g.f σ Q t) + ∂(indexedCascadeBaseLaw k (stepCumulative w) : Measure (IndexedCascadeBase k)).prod countableGaussianLaw)= + (n+1:ℕ)*(D.2.val/2+finiteSphericalFieldValue n k w (fun l=>(p l).2.val/2))+ + d*controlValue P g.f (weightedStepTrial w q (fun l=>(hw l).le) hw1) := by + have hpB : (p (Fin.last k)).2.val≤D.2.val := hpD (Sum.inl 0) + let a : ℝ≥0:=⟨D.2.val-(p (Fin.last k)).2.val,sub_nonneg.mpr hpB⟩ + let s : ℝ≥0:=⟨1-(q (Fin.last k):ℝ),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ + have hs : (s:ℝ)=D.1.val-(p (Fin.last k)).1.val := by dsimp [s]; rw [hDR,hpR]; rfl + have hr:=cavityLabel_full_evaluation n d p D hp0 hpm hpD g.f (stepCumulative w) + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1) + a s rfl hs + have hh0 : 0≤(p 0).2.val/2:=div_nonneg (hp0 (Sum.inl 0)) (by norm_num) + have hv:=cavity_finiteRPC_value n d k w (fun l=>(p l).2.val/2) q hw hw1 hh0 hq g P hB 0 D.2.val + have hb l : 2*((p l).2.val/2)=(p l).2.val := by ring + have hqf : (fun l (_ : Fin 1)=>(p l).1.val)=(fun l (_ : Fin 1)=>(q l:ℝ)) := by + funext l i; exact hpR l + have hval : (n+1:ℕ)*a/2+ + (∫ b,finiteCascadeLogRecursion (cavityRPCMarkLaw n d) + (cavityRPCStep n d (stepFieldIncrement k (fun l=>(p l).2.val/2)) + (fun j=>profileGaussianStep (fun l (_ : Fin 1)=>(p l).1.val) j 0)) k (stepCumulative w) + (cavityRPCTerminal n d (heatLogBCF s 1 g.f)) + (cavityRPCRootState n d (Real.sqrt (p 0).2.val) (Real.sqrt (p 0).1.val) b) + ∂(cavityRPCMarkLaw n d : Measure (CavityRPCMark n d)))= + (n+1:ℕ)*(D.2.val/2+finiteSphericalFieldValue n k w (fun l=>(p l).2.val/2))+ + d*controlValue P g.f (weightedStepTrial w q (fun l=>(hw l).le) hw1) := by + simp only [zero_add,hb] at hv + simp_rw [finiteCascade_terminal_log_recursion_of_fractional (cavityRPCMarkLaw n d) + (cavityRPCStep n d (stepFieldIncrement k (fun l=>(p l).2.val/2)) + (fun j=>profileGaussianStep (fun l (_ : Fin 1)=>(q l:ℝ)) j 0)) + (cavityRPCStep_measurable n d _ _) k (stepCumulative w) + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1) + (cavityRPCTerminal_measurable n d _) (cavityRPC_fractional n d k _ _ _ _ (stepCumulative_pos w hw))] at hv + erw [Jet3.heatLog_f] at hv + have ha : (a:ℝ)=D.2.val-(p (Fin.last k)).2.val := rfl + rw [ha,hqf,hpR] + exact hv + exact hr.trans hval + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityFullLog.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityFullLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..55671b4722d8b4f4ca207d7616e51c91ce571ad9 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityFullLog.lean @@ -0,0 +1,146 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityLabelAnnealed +import OAI.Probability.Perceptron.Cavity.CavityResidualFormula +import OAI.Probability.Perceptron.Variational.IndexedFractionalLog + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction ENNReal +namespace SphericalPerceptronFreeEnergy + +lemma cavityLabel_full_integrable_ae (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (f : ℝ→ᵇℝ) (b : IndexedCascadeBase k) : + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i) + let q:=cavityPairProfile n d p + ∀ᵐ g ∂countableGaussianLaw,Integrable + (fun x=>Real.exp (cavityLabelWeight n d k f σ q (g,x))*cavityLabelSpherical n d k σ q (g,x)) + ((indexedLeafProbability k b).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))) := by + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i) + let q:=cavityPairProfile n d p + let F:=cavityLabelSpherical n d k σ q + let W:=cavityLabelWeight n d k f σ q + have hL2 := (cavity_residual_square_integrable (indexedLeafProbability k b) countableGaussianLaw + (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) F + (cavityLabelSpherical_measurable n d k σ q) (Real.exp (2*(n+1:ℕ)*D.2.val)) + (fun x=>(cavityLabelSpherical_second n d p D hp0 hpm hpD x).1) + (fun x=>(cavityLabelSpherical_second n d p D hp0 hpm hpD x).2)).1 + filter_upwards [hL2.prod_right_ae] with g hg + have hF : MemLp (fun x=>F (g,x)) 2 + ((indexedLeafProbability k b).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))) := + (memLp_two_iff_integrable_sq ((cavityLabelSpherical_measurable n d k σ q).comp + (measurable_const.prodMk measurable_id)).aestronglyMeasurable).mpr hg + apply ((MemLp.integrable (by norm_num : (1:ℝ≥0∞)≤2) hF).const_mul (Real.exp ((d:ℝ)*‖f‖))).mono' + (((cavityLabelWeight_measurable n d k f σ q).exp.mul + (cavityLabelSpherical_measurable n d k σ q)).comp + (measurable_const.prodMk measurable_id)).aestronglyMeasurable + exact ae_of_all _ fun x=>by + have h0 : 0≤F (g,x) := (by norm_num : (0:ℝ)≤1).trans (cavityLabelSpherical_one n d k σ q (g,x)) + change ‖Real.exp (W (g,x))*F (g,x)‖≤_ + rw [Real.norm_of_nonneg (mul_nonneg (Real.exp_nonneg _) h0)] + exact mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr + ((le_abs_self _).trans (cavityLabelWeight_bound n d k f σ q (g,x)))) h0 + +lemma cavityLabelFullPartition_ae_root (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (f : ℝ→ᵇℝ) (z : Fin k→ℝ) + (H : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)→ℝ) (hH : Measurable H) + (hres : ∀ v,(∫ y,cavityFullSingle n d f (WithLp.toLp 2 (fun i=>v i+ + Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i)*y i)) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))=Real.exp (H v)) : + let q:=cavityPairProfile n d p + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-q (Fin.last k) i) + let step:=gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j)) + let root:=fun y _=>diagonalMark (profileGaussianRoot q) y + (cavityLabelFullPartition n d k f σ q)=ᵐ[ + (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw] + (fun t=>indexedRootTerminalPartition step (fun s=>H (s 0)) root k + ((indexedGaussianDisorder k (Fin (n+1)⊕Fin d) t.2).1, + (t.1,(indexedGaussianDisorder k (Fin (n+1)⊕Fin d) t.2).2))) := by + let q:=cavityPairProfile n d p + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-q (Fin.last k) i) + let step:=gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j)) + let root:=fun y (_ : ℕ)=>diagonalMark (profileGaussianRoot q) y + have hr : Measurable root := Measurable.of_eval fun _=>(diagonalMark (profileGaussianRoot q)).measurable + have hm:=indexedRootTerminalPartition_measurable step (gaussianLinearMarkStep_measurable _) _ + (hH.comp (measurable_pi_apply 0)) root hr k + have ht:=cavityIndexedRoot_disorder_preserving k (Fin (n+1)⊕Fin d) z + apply (Measure.ae_prod_iff_ae_ae (measurableSet_eq_fun + (cavityLabelFullPartition_measurable n d k f σ q) (hm.comp ht.measurable))).mpr + exact ae_of_all _ fun b=>by + filter_upwards [cavityLabel_full_integrable_ae n d p D hp0 hpm hpD f b] with g hg + unfold cavityLabelFullPartition + rw [integral_prod _ hg] + unfold indexedRootTerminalPartition + apply integral_congr_ae + exact ae_of_all _ fun l=>by + have he y : Real.exp (cavityLabelWeight n d k f σ q (g,l,y))* + cavityLabelSpherical n d k σ q (g,l,y)= + cavityFullSingle n d f (WithLp.toLp 2 (fun i=> + cavityCountableField (cavityLabelRow q) (cavityLabelLength k) g l i+σ i*y i)) := by + exact mul_comm _ _ + change (∫ y,Real.exp (cavityLabelWeight n d k f σ q (g,l,y))* + cavityLabelSpherical n d k σ q (g,l,y) ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))=_ + simp_rw [he] + rw [hres,cavity_label_field_state] + rfl + +lemma cavityLabel_full_log_recursion (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (f : ℝ→ᵇℝ) (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0v i+ + Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i)*y i)) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))=Real.exp (H v)) + (hfrac : finiteCascadeFractionalIntegrable (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep (cavityPairProfile n d p) j))) + (fun s=>H (s 0)) k z) : + let q:=cavityPairProfile n d p + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-q (Fin.last k) i) + let R:=fun y=>finiteCascadeLogRecursion (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j))) k z (fun s=>H (s 0)) + (fun _=>diagonalMark (profileGaussianRoot q) y) + Integrable R (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) ∧ + (∫ t,Real.log (cavityLabelFullPartition n d k f σ q t) + ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw)= + ∫ y,R y ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) := by + let q:=cavityPairProfile n d p + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-q (Fin.last k) i) + let step:=gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j)) + let root:=fun y (_ : ℕ)=>diagonalMark (profileGaussianRoot q) y + let F:=fun t=>Real.log (indexedRootTerminalPartition step (fun s=>H (s 0)) root k t) + have hr : Measurable root := Measurable.of_eval fun _=>(diagonalMark (profileGaussianRoot q)).measurable + have hm : Measurable F := (indexedRootTerminalPartition_measurable step + (gaussianLinearMarkStep_measurable _) _ (hH.comp (measurable_pi_apply 0)) root hr k).log + have ht:=cavityIndexedRoot_disorder_preserving k (Fin (n+1)⊕Fin d) z + have he:=cavityLabelFullPartition_ae_root n d p D hp0 hpm hpD f z H hH hres + have he' : (fun t=>Real.log (cavityLabelFullPartition n d k f σ q t))=ᵐ[_] F ∘ _ := + he.mono fun t h=>congrArg Real.log h + have hi:=((ht.integrable_comp hm.aestronglyMeasurable).mp + ((cavityLabel_full_log_integrable n d p D hp0 hpm hpD f z).congr he')) + dsimp only + constructor + · apply hi.integral_prod_left.congr + exact ae_of_all _ fun y=>cavity_indexed_log_recursion_fractional _ step + (gaussianLinearMarkStep_measurable _) _ (hH.comp (measurable_pi_apply 0)) k z hfrac hz hz0 hz1 (root y) + rw [integral_congr_ae he'] + simp only [Function.comp_def] + rw [←integral_map ht.measurable.aemeasurable hm.aestronglyMeasurable,ht.map_eq] + exact indexed_root_log_fractional _ _ step (gaussianLinearMarkStep_measurable _) _ + (hH.comp (measurable_pi_apply 0)) root k z hz hz0 hz1 hfrac hi +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianQuadratic.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianQuadratic.lean new file mode 100644 index 0000000000000000000000000000000000000000..b4ab3c74443c7f00e2f162c82295ec304a1da6a5 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianQuadratic.lean @@ -0,0 +1,81 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.PiMarkLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +def squareGaussianVariance : ℝ := variance (fun y : ℝ=>y^2) (gaussianReal 0 1) + +lemma squareGaussianVariance_nonneg : 0 ≤ squareGaussianVariance := variance_nonneg _ _ + +lemma gaussian_square_variance_scale (r : ℝ≥0) : + variance (fun y : ℝ=>y^2) (gaussianReal 0 r)=(r:ℝ)^2*squareGaussianVariance := by + have hg : (gaussianReal 0 1).map (fun y : ℝ=>Real.sqrt (r:ℝ)*y)=gaussianReal 0 r := by + convert gaussianReal_map_const_mul (μ:=0) (v:=1) (Real.sqrt (r:ℝ)) using 1 + simp only [mul_zero,mul_one] + congr 1 + exact NNReal.coe_injective (Real.sq_sqrt r.coe_nonneg).symm + rw [←hg,variance_map (by fun_prop) (by fun_prop)] + simp only [Function.comp_def,mul_pow,Real.sq_sqrt r.coe_nonneg] + exact variance_const_mul (r:ℝ) (fun y : ℝ=>y^2) _ + +def cavityQuadraticScalar (M : ℕ) (a : Fin M→ℝ) (t : ℝ) (r : ℝ≥0) (y : Fin M→ℝ) : ℝ := + t*∑ i,a i*((y i)^2-r) + +lemma cavityQuadraticScalar_memLp (M : ℕ) (a : Fin M→ℝ) (t : ℝ) (r : ℝ≥0) : + MemLp (cavityQuadraticScalar M a t r) 2 (Measure.pi (fun _=>gaussianReal 0 r)) := by + exact (memLp_finsetSum _ (fun i _=> + (((gaussian_square_memLp_two r).comp_measurePreserving (measurePreserving_eval _ i)).sub + (memLp_const (r:ℝ))).const_mul (a i))).const_mul t + +lemma cavityQuadraticScalar_mean (M : ℕ) (a : Fin M→ℝ) (t : ℝ) (r : ℝ≥0) : + (∫ y,cavityQuadraticScalar M a t r y ∂Measure.pi (fun _=>gaussianReal 0 r))=0 := by + unfold cavityQuadraticScalar + rw [integral_const_mul,integral_finsetSum] + · have he i : (∫ y : Fin M→ℝ,a i*((y i)^2-r) ∂Measure.pi (fun _=>gaussianReal 0 r))=0 := by + rw [integral_const_mul,integral_comp_eval (μ:=fun _ : Fin M=>gaussianReal 0 r) (i:=i) (f:=fun y : ℝ=>y^2-r) (by fun_prop)] + rw [integral_sub ((gaussian_square_memLp_two r).integrable (by norm_num)) (integrable_const _),gaussian_square_mean] + simp + simp_rw [he] + simp + · intro i _ + exact ((((gaussian_square_memLp_two r).comp_measurePreserving (measurePreserving_eval _ i)).sub + (memLp_const (r:ℝ))).const_mul (a i)).integrable (by norm_num) + +lemma cavityQuadraticScalar_second_moment (M : ℕ) (a : Fin M→ℝ) (t : ℝ) (r : ℝ≥0) : + (∫ y,(cavityQuadraticScalar M a t r y)^2 ∂Measure.pi (fun _=>gaussianReal 0 r))= + t^2*(r:ℝ)^2*squareGaussianVariance*∑ i,(a i)^2 := by + have hv := variance_eq_sub (cavityQuadraticScalar_memLp M a t r) + rw [cavityQuadraticScalar_mean] at hv + simp only [Pi.pow_apply,zero_pow (by norm_num : (2:ℕ)≠0),sub_zero] at hv + rw [←hv] + unfold cavityQuadraticScalar + rw [variance_const_mul] + have hs := variance_sum_pi (μ:=fun _ : Fin M=>gaussianReal 0 r) + (X:=fun i y=>a i*(y^2-r)) (fun i=>((gaussian_square_memLp_two r).sub (memLp_const (r:ℝ))).const_mul (a i)) + have he : (∑ i : Fin M,fun y : Fin M→ℝ=>a i*((y i)^2-r))=(fun y=>∑ i,a i*((y i)^2-r)) := by ext y; simp + rw [he] at hs + rw [hs] + simp_rw [variance_const_mul,variance_sub_const (show AEStronglyMeasurable (fun y : ℝ=>y^2) (gaussianReal 0 r) from by fun_prop),gaussian_square_variance_scale] + rw [←Finset.sum_mul] + ring + +lemma cavityQuadraticScalar_second_moment_bound (M : ℕ) (a : Fin M→ℝ) (t : ℝ) (r : ℝ≥0) + {C : ℝ} (_hC : 0≤C) (ha : ∀ i,|a i|≤C) : + (∫ y,(cavityQuadraticScalar M a t r y)^2 ∂Measure.pi (fun _=>gaussianReal 0 r))≤ + t^2*(r:ℝ)^2*squareGaussianVariance*M*C^2 := by + rw [cavityQuadraticScalar_second_moment,mul_assoc _ (M:ℝ) (C^2)] + apply mul_le_mul_of_nonneg_left _ (mul_nonneg (mul_nonneg (sq_nonneg _) (sq_nonneg _)) squareGaussianVariance_nonneg) + calc + (∑ i,(a i)^2)≤∑ _ : Fin M,C^2 := Finset.sum_le_sum fun i _=>by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (a i)) (ha i) 2 + _=M*C^2 := by simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianReplica.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianReplica.lean new file mode 100644 index 0000000000000000000000000000000000000000..5057385bef215158357685067c90eb471e128835 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianReplica.lean @@ -0,0 +1,173 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkRadialLimit + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction Matrix + +section + +variable {J E : Type*} [Fintype J] [DecidableEq J] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] + +def cavityTestReplica (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) : + EuclideanSpace ℝ (J×Fin r)→ᵇℝ := + ∏ i : Fin r, Ψ.compContinuous ⟨fun z=>WithLp.toLp 2 (fun j=>z (j,i)),by fun_prop⟩ + +omit [Fintype J] [DecidableEq J] in +lemma cavityTestReplica_apply (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) + (z : EuclideanSpace ℝ (J×Fin r)) : + cavityTestReplica Ψ r z=∏ i : Fin r, Ψ (WithLp.toLp 2 (fun j=>z (j,i))) := by + simp [cavityTestReplica] + +theorem cavity_marked_moment {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (v : S→J→E) + (hv : Measurable v) (W : S→ℝ) (hW : Measurable W) {C : ℝ} + (hWB : ∀ s,|W s|≤C) (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) : + (∫ y,(∫ s,Real.exp (W s)*Ψ (gaussianRows (v s) y) ∂μ)^r ∂stdGaussian E)= + ∫ xs : Fin r→S,(∏ i,Real.exp (W (xs i)))* + cavityMatrixKernel (cavityTestReplica Ψ r) + (Matrix.gram ℝ (fun p : J×Fin r=>v (xs p.2) p.1)) + ∂Measure.pi (fun _=>μ) := by + let P:=Measure.pi (fun _ : Fin r=>μ) + let F : E×(Fin r→S)→ℝ:=fun p=> + ∏ i : Fin r,Real.exp (W (p.2 i))*Ψ (gaussianRows (v (p.2 i)) p.1) + have hm : Measurable F := by + apply Finset.measurable_prod + intro i hi + have hvi : Measurable (fun p : E×(Fin r→S)=>v (p.2 i)) := + hv.comp ((measurable_pi_apply i).comp measurable_snd) + have hwi : Measurable (fun p : E×(Fin r→S)=>W (p.2 i)) := + hW.comp ((measurable_pi_apply i).comp measurable_snd) + apply hwi.exp.mul + apply Ψ.measurable.comp + change Measurable (fun p : E×(Fin r→S)=>WithLp.toLp 2 + (fun j=>inner ℝ (v (p.2 i) j) p.1)) + fun_prop + have hb p : ‖F p‖≤(Real.exp C*‖Ψ‖)^r := by + simp only [F,norm_prod,norm_mul] + calc + _ ≤ ∏ i : Fin r, Real.exp C * ‖Ψ‖ := by + apply Finset.prod_le_prod₀ (fun _ _=>mul_nonneg (norm_nonneg _) (norm_nonneg _)) + intro i hi + apply mul_le_mul _ (Ψ.norm_coe_le_norm _) (norm_nonneg _) (Real.exp_pos C).le + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (abs_le.mp (hWB _)).2 + _ = _ := by simp + have hi : Integrable F ((stdGaussian E).prod P) := + Integrable.of_bound hm.aestronglyMeasurable _ (ae_of_all _ hb) + calc + _=∫ y,∫ xs : Fin r→S,F (y,xs) ∂P ∂stdGaussian E := by + apply integral_congr_ae + filter_upwards [] with y + simpa only [F,P,Fintype.card_fin] using + (integral_fintype_prod_eq_pow (ι:=Fin r) + (fun s=>Real.exp (W s)*Ψ (gaussianRows (v s) y)) (μ:=μ)).symm + _=∫ xs : Fin r→S,∫ y,F (y,xs) ∂stdGaussian E ∂P := integral_integral_swap hi + _=_ := by + apply integral_congr_ae + filter_upwards [] with xs + have he y : F (y,xs)=(∏ i,Real.exp (W (xs i)))* + cavityTestReplica Ψ r (gaussianRows (fun p : J×Fin r=>v (xs p.2) p.1) y) := by + simp only [F,Finset.prod_mul_distrib,cavityTestReplica_apply] + congr 1 + simp_rw [he] + rw [integral_const_mul,cavityMatrixKernel_posSemidef _ _ (Matrix.posSemidef_gram ℝ _), + ←gaussianRows_map_stdGaussian, + integral_map (gaussianRows _).continuous.measurable.aemeasurable + (cavityTestReplica Ψ r).continuous.aestronglyMeasurable] + +def cavitySingleTest (n d : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) : + EuclideanSpace ℝ (Fin (n+1)⊕Fin d)→ᵇℝ := + (cappedSphericalExp n (Real.sqrt (n+1:ℕ)) Λ hΛ).compContinuous + ⟨fun z=>WithLp.toLp 2 (fun i=>z (Sum.inl i)),by fun_prop⟩ * + ∏ i : Fin d,(expBCF 1 f).compContinuous ⟨fun z=>z (Sum.inr i),by fun_prop⟩ + +lemma cavitySingleTest_apply (n d : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (z : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + cavitySingleTest n d f Λ hΛ z = + min (sphericalExp n (WithLp.toLp 2 (fun i=>z (Sum.inl i))) (Real.sqrt (n+1:ℕ))) Λ * + ∏ i : Fin d,Real.exp (f (z (Sum.inr i))) := by + simp [cavitySingleTest,cappedSphericalExp,expBCF] + +lemma cavitySingleTest_replica (n d r : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) : + cavityTestReplica (cavitySingleTest n d f Λ hΛ) r=cavityReplicaTest n d r f Λ hΛ := by + ext z + simp only [cavityTestReplica_apply,cavitySingleTest_apply,cavityReplicaTest_apply] + +end + +lemma posSemidef_independent_blocks {J I : Type*} [Fintype J] [Fintype I] + [DecidableEq J] [DecidableEq I] (C : J → I → I → ℝ) + (hC : ∀ j,(Matrix.of (C j)).PosSemidef) : + (Matrix.of (fun (p q : J×I) => if p.1=q.1 then C p.1 p.2 q.2 else 0)).PosSemidef := by + rw [Matrix.posSemidef_iff_dotProduct_mulVec] + constructor + · rw [Matrix.IsHermitian.ext_iff] + intro p q + change (if q.1=p.1 then C q.1 q.2 p.2 else 0) = (if p.1=q.1 then C p.1 p.2 q.2 else 0) + by_cases h : p.1=q.1 + · simp only [h] + exact (Matrix.IsHermitian.ext_iff.mp (hC q.1).isHermitian p.2 q.2) + · simp [h,Ne.symm h] + · intro x + have he : star x ⬝ᵥ ((fun (p q : J×I) => if p.1=q.1 then C p.1 p.2 q.2 else 0) *ᵥ x) = + ∑ j : J, star (fun i : I=>x (j,i)) ⬝ᵥ (C j *ᵥ (fun i=>x (j,i))) := by + simp [dotProduct,Matrix.mulVec,Fintype.sum_prod_type,Finset.mul_sum] + change 0 ≤ star x ⬝ᵥ ((fun (p q : J×I) => if p.1=q.1 then C p.1 p.2 q.2 else 0) *ᵥ x) + rw [he] + exact Finset.sum_nonneg fun j _ => (Matrix.posSemidef_iff_dotProduct_mulVec.mp (hC j)).2 _ + +lemma cavityBlockCovariance_posSemidef (n d r : ℕ) {K : ℝ} + (Q : CompactArray (BulkPairRange K)) + (hB : Matrix.PosSemidef (fun i j : Fin r=>(Q i j).2.val)) + (hR : Matrix.PosSemidef (fun i j : Fin r=>(Q i j).1.val)) : + (cavityBlockCovariance n d r Q).PosSemidef := by + let C : (Fin (n+1) ⊕ Fin d) → Fin r → Fin r → ℝ := + fun c i j => Sum.elim (fun _ => (Q i j).2.val) (fun _ => (Q i j).1.val) c + have hC : ∀ c,Matrix.PosSemidef (C c) := by + intro c + cases c + · exact hB + · exact hR + exact posSemidef_independent_blocks C hC + +lemma bulkMarkedEntry_B_posSemidef (n M : ℕ) (f : Jet3) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) (a : BulkDisorder (n+1) M) + (r : ℕ) (x : Fin r→NormalizedSpin (n+1)) : + Matrix.PosSemidef (fun i j => (bulkMarkedEntry n M f K hK a (x i) (x j)).2.val) := by + let v : Fin r→Spin M:=fun i=> WithLp.toLp 2 (fun t=>f.d1 (∑ j,a.1 t j*(x i).val j)) + have h:= (Matrix.posSemidef_gram ℝ v).smul (by positivity : (0:ℝ)≤((n+1:ℕ):ℝ)⁻¹) + have he : (fun i j => (bulkMarkedEntry n M f K hK a (x i) (x j)).2.val : Matrix (Fin r) (Fin r) ℝ)= + ((n+1:ℕ):ℝ)⁻¹ • Matrix.gram ℝ v := by + ext i j + simp [bulkMarkedEntry,bulkB,v,Matrix.gram,EuclideanSpace.inner_eq_star_dotProduct,dotProduct, + mul_comm] + rw [he] + exact h + +lemma bulkMarkedEntry_R_posSemidef (n M : ℕ) (f : Jet3) (K : ℝ) + (hK : M/(n+1:ℕ)*‖f.d1‖^2≤K) (a : BulkDisorder (n+1) M) + (r : ℕ) (x : Fin r→NormalizedSpin (n+1)) : + Matrix.PosSemidef (fun i j => (bulkMarkedEntry n M f K hK a (x i) (x j)).1.val) := by + exact Matrix.posSemidef_gram ℝ (fun i=> (x i).val) + +lemma cavityArrayKernel_actual (n d r m M : ℕ) (g : Jet3) (Λ : ℝ) (hΛ : 1≤Λ) + (K : ℝ) (hK : M/(m+1:ℕ)*‖g.d1‖^2≤K) + (p : BulkDisorder (m+1) M×(ℕ→NormalizedSpin (m+1))) : + cavityArrayKernel n d r g.f Λ hΛ K (bulkMarkedArray m M g K hK p)= + ∫ z,cavityReplicaTest n d r g.f Λ hΛ z ∂multivariateGaussian 0 + (cavityBlockCovariance n d r (bulkMarkedArray m M g K hK p)) := by + apply cavityMatrixKernel_posSemidef + apply cavityBlockCovariance_posSemidef + · exact bulkMarkedEntry_B_posSemidef m M g K hK p.1 r (fun i=>p.2 i) + · exact bulkMarkedEntry_R_posSemidef m M g K hK p.1 r (fun i=>p.2 i) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianTransport.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..8fa06c9ac907938c15b553d921b4c96a8a99099e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityGaussianTransport.lean @@ -0,0 +1,129 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityLabelArray +import OAI.Probability.Perceptron.Cavity.CavityResidualFormula +import OAI.Probability.Perceptron.Cascade.CascadeTransport + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory +open scoped Topology BigOperators BoundedContinuousFunction NNReal + +def cavityGaussianMark (n d : ℕ) (y : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : CavityRPCMark n d := + (fun i=>y (Sum.inl i),fun i=>y (Sum.inr i)) + +def cavityGaussianState (n d : ℕ) (x : ℕ→EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : CavityRPCState n d := + (fun i j=>x j (Sum.inl i),fun i j=>x j (Sum.inr i)) + +lemma cavityGaussianMark_preserving (n d : ℕ) : + MeasurePreserving (cavityGaussianMark n d) + (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) (cavityRPCMarkLaw n d : Measure (CavityRPCMark n d)) := by + have hp : MeasurePreserving (fun p : Spin (n+1)×Spin d=>(WithLp.ofLp p.1,WithLp.ofLp p.2)) + ((stdGaussian (Spin (n+1))).prod (stdGaussian (Spin d))) + ((Measure.pi fun _ : Fin (n+1)=>gaussianReal 0 1).prod (Measure.pi fun _ : Fin d=>gaussianReal 0 1)) := + (stdGaussian_ofLp_preserving (n+1)).prod (stdGaussian_ofLp_preserving d) + exact hp.comp (gaussianSumSplit_preserving (I:=Fin (n+1)) (J:=Fin d)) + +lemma cavityGaussianState_measurable (n d : ℕ) : Measurable (cavityGaussianState n d) := by + unfold cavityGaussianState + apply Measurable.prodMk <;> apply Measurable.of_eval <;> intro i <;> apply Measurable.of_eval <;> intro j + · exact (measurable_pi_apply (Sum.inl i)).comp ((MeasurableEquiv.toLp 2 _).symm.measurable.comp (measurable_pi_apply j)) + · exact (measurable_pi_apply (Sum.inr i)).comp ((MeasurableEquiv.toLp 2 _).symm.measurable.comp (measurable_pi_apply j)) + +lemma cavityGaussianState_step (n d : ℕ) (σ τ : ℕ→ℝ) (x : ℕ→EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) + (y : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + cavityGaussianState n d (gaussianLinearMarkStep (fun j=>diagonalMark (Sum.elim (fun _=>σ j) (fun _=>τ j))) (x,y))= + cavityRPCStep n d σ τ (cavityGaussianState n d x,cavityGaussianMark n d y) := by + rfl + +lemma cavityRPC_fractional (n d k : ℕ) (σ τ : ℕ→ℝ) (F : ℝ→ᵇℝ) + (z : Fin k→ℝ) (hz0 : ∀ i,0F (a 0)) := F.measurable.comp (measurable_pi_apply 0) + have hFI := finiteCascadeFractionalIntegrable_of_bounded standardGaussianMark + (gaussianShiftStep τ) (gaussianShiftStep_measurable τ) k z hz0 hF + (fun a=>F.norm_coe_le_norm (a 0)) + have hs := finiteCascade_sum_pi (fun _ : Fin d=>standardGaussianMark) + (fun _=>gaussianShiftStep τ) k z (fun _ a=>F (a 0)) (fun _=>hFI) + have hv := coordinateRecursion_eq_backward (n+1) σ + (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) k z hz0 + exact finiteCascadeFractionalIntegrable_add_product + (piMarkLaw (fun _ : Fin (n+1)=>standardGaussianMark)) + (piMarkLaw (fun _ : Fin d=>standardGaussianMark)) + (canonicalCoordinateStep (n+1) σ) (canonicalCoordinateStep d τ) k z hz0 hv.2 hs.2 + +lemma cavityGaussian_fractional (n d k : ℕ) (σ τ : ℕ→ℝ) (F : ℝ→ᵇℝ) + (z : Fin k→ℝ) (hz0 : ∀ i,0diagonalMark (Sum.elim (fun _=>σ j) (fun _=>τ j)))) + (cavityRPCTerminal n d F ∘ cavityGaussianState n d) k z := + finiteCascadeFractionalIntegrable_transport + (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) (cavityRPCMarkLaw n d) _ _ + (cavityRPCStep_measurable n d σ τ) + (cavityGaussianState n d) (cavityGaussianMark n d) (cavityGaussianMark_preserving n d) + (cavityGaussianState_step n d σ τ) _ (cavityRPCTerminal_measurable n d F) k z + (cavityRPC_fractional n d k σ τ F z hz0) + +lemma cavityPairProfile_root (n d : ℕ) {K : ℝ} {k : ℕ} (p : Fin (k+1)→BulkPairRange K) : + profileGaussianRoot (cavityPairProfile n d p)= + Sum.elim (fun _=>Real.sqrt (p 0).2.val) (fun _=>Real.sqrt (p 0).1.val) := by + funext i; cases i <;> rfl + +lemma cavityPairProfile_step (n d : ℕ) {K : ℝ} {k : ℕ} (p : Fin (k+1)→BulkPairRange K) (j : ℕ) : + profileGaussianStep (cavityPairProfile n d p) j= + Sum.elim (fun _=>stepFieldIncrement k (fun l=>(p l).2.val/2) j) + (fun _=>profileGaussianStep (fun l (_ : Fin 1)=>(p l).1.val) j 0) := by + funext i + cases i with + | inl _index => + unfold profileGaussianStep stepFieldIncrement + split_ifs with hj + · have h₁ : (⟨k-j,by omega⟩ : Fin (k+1))=(Fin.rev (⟨j,hj⟩ : Fin k)).succ := by + ext; simp only [Fin.val_rev,Fin.val_succ]; omega + have h₂ : (⟨k-j-1,by omega⟩ : Fin (k+1))=(Fin.rev (⟨j,hj⟩ : Fin k)).castSucc := by + ext; simp only [Fin.val_rev,Fin.val_castSucc]; omega + simp only [cavityPairProfile,Sum.elim_inl,h₁,h₂] + congr 1; ring + · rfl + | inr _index => + unfold profileGaussianStep + split_ifs <;> rfl + +lemma cavityGaussianState_root (n d : ℕ) {K : ℝ} {k : ℕ} (p : Fin (k+1)→BulkPairRange K) + (y : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + cavityGaussianState n d (fun _=>diagonalMark (profileGaussianRoot (cavityPairProfile n d p)) y)= + cavityRPCRootState n d (Real.sqrt (p 0).2.val) (Real.sqrt (p 0).1.val) (cavityGaussianMark n d y) := by + rfl + +lemma cavityPair_residual_formula (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (f : ℝ→ᵇℝ) (a s : ℝ≥0) + (ha : (a:ℝ)=D.2.val-(p (Fin.last k)).2.val) + (hs : (s:ℝ)=D.1.val-(p (Fin.last k)).1.val) + (v : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + (∫ y,cavityFullSingle n d f (WithLp.toLp 2 (fun i=>v i+ + Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i)*y i)) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))= + Real.exp ((n+1:ℕ)*a/2+logSphericalExp n (Real.sqrt (n+1:ℕ)) (gaussianSumSplit v).1+ + ∑ i,heatLog s 1 f (v (Sum.inr i))) := by + have he : (fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i))= + Sum.elim (fun _=>Real.sqrt a) (fun _=>Real.sqrt s) := by + funext i; cases i <;> simp only [cavityPairDiagonal,cavityPairProfile,Sum.elim_inl,Sum.elim_inr,ha,hs] + simp_rw [show ∀ i,Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i)= + Sum.elim (fun _=>Real.sqrt a) (fun _=>Real.sqrt s) i from congrFun he] + exact cavity_full_residual n d f a s v + +lemma cavityGaussian_terminal (n d : ℕ) (f : ℝ→ᵇℝ) (a s : ℝ≥0) + (x : ℕ→EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + (n+1:ℕ)*a/2+logSphericalExp n (Real.sqrt (n+1:ℕ)) (gaussianSumSplit (x 0)).1+ + ∑ i,heatLog s 1 f (x 0 (Sum.inr i)) = + (n+1:ℕ)*a/2+(cavityRPCTerminal n d (heatLogBCF s 1 f) ∘ cavityGaussianState n d) x := by + change _=_+(_+_) + exact add_assoc _ _ _ + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityGeometry.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc082995aba54e62c42b4fc4970e653d342d86d0 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityGeometry.lean @@ -0,0 +1,276 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityCovarianceComparison +import OAI.Probability.Perceptron.Cavity.CavityPerturbationCovariance +import OAI.Probability.Perceptron.Variational.GaussianBlock + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +def gaussianBlockJoin (N L : ℕ) (p : Spin N×Spin L) : Spin (N+L) := + WithLp.toLp 2 (Fin.addCases (fun i=>p.1 i) (fun j=>p.2 j)) + +lemma gaussianBlockJoin_measurable (N L : ℕ) : Measurable (gaussianBlockJoin N L) := by + apply (PiLp.continuous_toLp 2 _).measurable.comp + apply Measurable.of_eval + intro i + induction i using Fin.addCases <;> simp only [Fin.addCases_left,Fin.addCases_right] <;> fun_prop + +lemma gaussianBlockSplit_join (N L : ℕ) (p : Spin N×Spin L) : + gaussianBlockSplit N L (gaussianBlockJoin N L p)=p := by + apply Prod.ext <;> ext i <;> simp [gaussianBlockSplit,gaussianBlockJoin] + +lemma gaussianBlockJoin_split (N L : ℕ) (x : Spin (N+L)) : + gaussianBlockJoin N L (gaussianBlockSplit N L x)=x := by + ext i + induction i using Fin.addCases <;> simp [gaussianBlockSplit,gaussianBlockJoin] + +lemma gaussianBlockJoin_norm_sq (N L : ℕ) (p : Spin N×Spin L) : + ‖gaussianBlockJoin N L p‖^2=‖p.1‖^2+‖p.2‖^2 := by + simpa only [gaussianBlockSplit_join] using gaussianBlockSplit_norm_sq N L (gaussianBlockJoin N L p) + +lemma gaussianBlockJoin_inner (N L : ℕ) (p q : Spin N×Spin L) : + inner ℝ (gaussianBlockJoin N L p) (gaussianBlockJoin N L q)= + inner ℝ p.1 q.1+inner ℝ p.2 q.2 := by + change (∑ i : Fin (N+L),gaussianBlockJoin N L q i*gaussianBlockJoin N L p i)=_ + rw [Fin.sum_univ_add] + simp only [gaussianBlockJoin,PiLp.toLp_apply,Fin.addCases_left,Fin.addCases_right] + rfl + +def cavityRho (N L : ℕ) (z : Spin L) : ℝ := Real.sqrt (1-‖z‖^2/(N+L:ℕ)) + +def cavityNormalizedVec (N L : ℕ) (x : NormalizedSpin N) (z : Spin L) : Spin (N+L) := + gaussianBlockJoin N L (cavityRho N L z •x.val,(Real.sqrt (N+L:ℕ))⁻¹ •z) + +lemma cavityRho_bounds (N L : ℕ) (z : Spin L) (hD : 0<(N+L:ℕ)) + (hz : ‖z‖^2≤(N+L:ℕ)) : + 0≤cavityRho N L z ∧ cavityRho N L z≤1 ∧ + 1-cavityRho N L z≤‖z‖^2/(N+L:ℕ) := by + have hDp : (0:ℝ)<(N+L:ℕ) := by exact_mod_cast hD + have hq : 0≤‖z‖^2/(N+L:ℕ) := by positivity + have hq1 : ‖z‖^2/(N+L:ℕ)≤1 := (div_le_one hDp).mpr hz + have hsq := Real.sq_sqrt (show 0≤1-‖z‖^2/(N+L:ℕ) by linarith) + have hp := Real.sqrt_nonneg (1-‖z‖^2/(N+L:ℕ)) + have hu : Real.sqrt (1-‖z‖^2/(N+L:ℕ))≤1 := by nlinarith + refine ⟨hp,hu,?_⟩ + dsimp [cavityRho] + nlinarith [mul_nonneg hp (sub_nonneg.mpr hu)] + +lemma cavityNormalizedVec_norm (N L : ℕ) (x : NormalizedSpin N) (z : Spin L) + (hD : 0<(N+L:ℕ)) (hz : ‖z‖^2≤(N+L:ℕ)) : + ‖cavityNormalizedVec N L x z‖=1 := by + have hDp : (0:ℝ)<(N+L:ℕ) := by exact_mod_cast hD + have hx : ‖x.val‖=1 := by simpa only [Metric.mem_sphere,dist_zero_right] using x.prop + have hr : 0≤1-‖z‖^2/(N+L:ℕ) := sub_nonneg.mpr ((div_le_one hDp).mpr hz) + have hsq : ‖cavityNormalizedVec N L x z‖^2=1 := by + rw [cavityNormalizedVec,gaussianBlockJoin_norm_sq] + simp only [norm_smul,Real.norm_eq_abs,hx,mul_one,mul_pow,sq_abs,cavityRho, + Real.sq_sqrt hr,inv_pow,Real.sq_sqrt hDp.le] + rw [←div_eq_inv_mul] + ring + nlinarith [norm_nonneg (cavityNormalizedVec N L x z)] + +lemma cavityNormalizedVec_inner (N L : ℕ) (x x' : NormalizedSpin N) (z z' : Spin L) + (hD : 0<(N+L:ℕ)) : + inner ℝ (cavityNormalizedVec N L x z) (cavityNormalizedVec N L x' z')= + cavityRho N L z*cavityRho N L z'*spinOverlap x x'+inner ℝ z z'/(N+L:ℕ) := by + have hDp : (0:ℝ)<(N+L:ℕ) := by exact_mod_cast hD + simp only [cavityNormalizedVec,gaussianBlockJoin_inner,inner_smul_left,inner_smul_right, + conj_trivial,spinOverlap] + rw [show (Real.sqrt (N+L:ℕ))⁻¹*((Real.sqrt (N+L:ℕ))⁻¹*inner ℝ z z')= + inner ℝ z z'/(N+L:ℕ) by + rw [←mul_assoc,←pow_two,inv_pow,Real.sq_sqrt hDp.le,div_eq_mul_inv,mul_comm]] + ring + +lemma cavityNormalizedVec_overlap_error (n L : ℕ) (x x' : NormalizedSpin (n+1)) + (z z' : Spin L) {D : ℝ} (hz : ‖z‖^2≤D) (hz' : ‖z'‖^2≤D) + (hD : D≤(n+1+L:ℕ)) : + |inner ℝ (cavityNormalizedVec (n+1) L x z) (cavityNormalizedVec (n+1) L x' z')- + spinOverlap x x'|≤3*D/(n+1:ℕ) := by + have hp : 0<(n+1+L:ℕ) := by omega + have hpr : (0:ℝ)<(n+1+L:ℕ) := by positivity + have hD0 : 0≤D := (sq_nonneg ‖z‖).trans hz + have hr := cavityRho_bounds (n+1) L z hp (hz.trans hD) + have hr' := cavityRho_bounds (n+1) L z' hp (hz'.trans hD) + have hrlo : 0≤cavityRho (n+1) L z*cavityRho (n+1) L z' := mul_nonneg hr.1 hr'.1 + have hrhi : cavityRho (n+1) L z*cavityRho (n+1) L z'≤1 := by nlinarith + have hrerr : |cavityRho (n+1) L z*cavityRho (n+1) L z'-1|≤2*D/(n+1+L:ℕ) := by + rw [abs_of_nonpos (sub_nonpos.mpr hrhi)] + have ha := (hr.2.2.trans (div_le_div_of_nonneg_right hz hpr.le)) + have hb := (hr'.2.2.trans (div_le_div_of_nonneg_right hz' hpr.le)) + rw [mul_div_assoc] + nlinarith [mul_nonneg (sub_nonneg.mpr hr.2.1) (sub_nonneg.mpr hr'.2.1)] + have hi : |inner ℝ z z'|≤D := by + apply (abs_real_inner_le_norm z z').trans + nlinarith [sq_nonneg (‖z‖-‖z'‖)] + rw [cavityNormalizedVec_inner _ _ _ _ _ _ hp] + have he : cavityRho (n+1) L z*cavityRho (n+1) L z'*spinOverlap x x'+inner ℝ z z'/(n+1+L:ℕ)-spinOverlap x x'= + (cavityRho (n+1) L z*cavityRho (n+1) L z'-1)*spinOverlap x x'+inner ℝ z z'/(n+1+L:ℕ) := by ring + rw [he] + apply (abs_add_le _ _).trans + rw [abs_mul,abs_div,abs_of_pos hpr] + have hspin : |spinOverlap x x'|≤1 := spinOverlap_abs_le x x' + calc + _≤2*D/(n+1+L:ℕ)*1+D/(n+1+L:ℕ) := + add_le_add (mul_le_mul hrerr hspin (abs_nonneg _) (by positivity)) + (div_le_div_of_nonneg_right hi hpr.le) + _=3*D/(n+1+L:ℕ) := by ring + _≤3*D/(n+1:ℕ) := div_le_div_of_nonneg_left (by positivity) (by positivity) (by norm_cast; omega) + +lemma cavityNormalizedVec_covariance (n L : ℕ) (v : ℕ→ℝ) (C : ℝ) (hC : 0≤C) + (hv : ∀ j,|v (j+1)|≤C) (x x' : NormalizedSpin (n+1)) (z z' : Spin L) + (hz : ‖z‖^2≤(L:ℝ)+1) (hz' : ‖z'‖^2≤(L:ℝ)+1) : + |inner ℝ (ambientBulkFeature (n+1+L) v (cavityNormalizedVec (n+1) L x z)) + (ambientBulkFeature (n+1+L) v (cavityNormalizedVec (n+1) L x' z'))- + inner ℝ (bulkFeature (n+1) v x) (bulkFeature (n+1) v x')|≤ + cavityBulkCovarianceError n L C (3*((L:ℝ)+1)) := by + have hD : (L:ℝ)+1≤(n+1+L:ℕ) := by push_cast; linarith [Nat.cast_nonneg (α:=ℝ) n] + have hp : 0<(n+1+L:ℕ) := by omega + let u : NormalizedSpin (n+1+L):=⟨cavityNormalizedVec (n+1) L x z,by + simpa only [Metric.mem_sphere,dist_zero_right] using cavityNormalizedVec_norm _ _ x z hp (hz.trans hD)⟩ + let u' : NormalizedSpin (n+1+L):=⟨cavityNormalizedVec (n+1) L x' z',by + simpa only [Metric.mem_sphere,dist_zero_right] using cavityNormalizedVec_norm _ _ x' z' hp (hz'.trans hD)⟩ + change |inner ℝ (ambientBulkFeature _ v u.val) (ambientBulkFeature _ v u'.val)-_|≤_ + rw [ambientBulkFeature_eq,ambientBulkFeature_eq,bulkFeature_inner,bulkFeature_inner] + apply cavity_bulk_covariance_shell n L v hC (by positivity) hv (spinOverlap_abs_le x x') (spinOverlap_abs_le u u') + exact cavityNormalizedVec_overlap_error n L x x' z z' hz hz' hD + +section Sum +variable {I J : Type} [Fintype I] [Fintype J] +def gaussianSumSplit (x : EuclideanSpace ℝ (I⊕J)) : EuclideanSpace ℝ I×EuclideanSpace ℝ J := + (WithLp.toLp 2 (fun i=>x (.inl i)),WithLp.toLp 2 (fun j=>x (.inr j))) +def gaussianInl (x : EuclideanSpace ℝ I) : EuclideanSpace ℝ (I⊕J) := + WithLp.toLp 2 (Sum.elim (fun i=>x i) (fun _=>0)) +def gaussianInr (x : EuclideanSpace ℝ J) : EuclideanSpace ℝ (I⊕J) := + WithLp.toLp 2 (Sum.elim (fun _=>0) (fun j=>x j)) +omit [Fintype I] [Fintype J] in +lemma gaussianSumSplit_measurable : Measurable (gaussianSumSplit (I:=I) (J:=J)) := by + unfold gaussianSumSplit + fun_prop +lemma gaussianInl_measurable : Measurable (gaussianInl (I:=I) (J:=J)) := by + apply (PiLp.continuous_toLp 2 _).measurable.comp + apply Measurable.of_eval + intro i + cases i <;> simp only [Sum.elim_inl,Sum.elim_inr] <;> fun_prop +lemma gaussianInr_measurable : Measurable (gaussianInr (I:=I) (J:=J)) := by + apply (PiLp.continuous_toLp 2 _).measurable.comp + apply Measurable.of_eval + intro i + cases i <;> simp only [Sum.elim_inl,Sum.elim_inr] <;> fun_prop +lemma gaussianSumSplit_preserving : + MeasurePreserving (gaussianSumSplit (I:=I) (J:=J)) (stdGaussian (EuclideanSpace ℝ (I⊕J))) + ((stdGaussian (EuclideanSpace ℝ I)).prod (stdGaussian (EuclideanSpace ℝ J))) := by + have hI : MeasurePreserving (WithLp.toLp 2 : (I→ℝ)→EuclideanSpace ℝ I) + (Measure.pi fun _=>gaussianReal 0 1) (stdGaussian (EuclideanSpace ℝ I)) := + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + have hJ : MeasurePreserving (WithLp.toLp 2 : (J→ℝ)→EuclideanSpace ℝ J) + (Measure.pi fun _=>gaussianReal 0 1) (stdGaussian (EuclideanSpace ℝ J)) := + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + refine ⟨gaussianSumSplit_measurable,?_⟩ + rw [←map_pi_eq_stdGaussian,Measure.map_map gaussianSumSplit_measurable (PiLp.continuous_toLp 2 _).measurable] + convert ((hI.prod hJ).comp (measurePreserving_sumPiEquivProdPi (fun _ : I⊕J=>gaussianReal 0 1))).map_eq using 1 + rfl +lemma gaussianInl_inner (x y : EuclideanSpace ℝ I) : + inner ℝ (gaussianInl (J:=J) x) (gaussianInl y)=inner ℝ x y := by + change (∑ i, gaussianInl (J:=J) y i*gaussianInl x i)=_ + simp only [Fintype.sum_sum_type,gaussianInl,PiLp.toLp_apply,Sum.elim_inl,Sum.elim_inr, + mul_zero,Finset.sum_const_zero,add_zero] + rfl +lemma gaussianInr_inner (x y : EuclideanSpace ℝ J) : + inner ℝ (gaussianInr (I:=I) x) (gaussianInr y)=inner ℝ x y := by + change (∑ i, gaussianInr (I:=I) y i*gaussianInr x i)=_ + simp only [Fintype.sum_sum_type,gaussianInr,PiLp.toLp_apply,Sum.elim_inl,Sum.elim_inr, + mul_zero,Finset.sum_const_zero,zero_add] + rfl +lemma gaussianInl_Inr_inner (x : EuclideanSpace ℝ I) (y : EuclideanSpace ℝ J) : + inner ℝ (gaussianInl x) (gaussianInr y)=0 := by + change (∑ i, gaussianInr (I:=I) y i*gaussianInl x i)=_ + simp [Fintype.sum_sum_type,gaussianInl,gaussianInr] +lemma gaussianInl_norm (x : EuclideanSpace ℝ I) : ‖gaussianInl (J:=J) x‖=‖x‖ := by + have h:=gaussianInl_inner (J:=J) x x + simp only [real_inner_self_eq_norm_sq] at h + nlinarith [norm_nonneg x,norm_nonneg (gaussianInl (J:=J) x)] +lemma gaussianInr_norm (x : EuclideanSpace ℝ J) : ‖gaussianInr (I:=I) x‖=‖x‖ := by + have h:=gaussianInr_inner (I:=I) x x + simp only [real_inner_self_eq_norm_sq] at h + nlinarith [norm_nonneg x,norm_nonneg (gaussianInr (I:=I) x)] +lemma gaussianInl_linear (x : EuclideanSpace ℝ I) (g : EuclideanSpace ℝ (I⊕J)) : + inner ℝ (gaussianInl x) g=inner ℝ x (gaussianSumSplit g).1 := by + change (∑ i,g i*gaussianInl x i)=_ + simp only [Fintype.sum_sum_type,gaussianInl,PiLp.toLp_apply,Sum.elim_inl,Sum.elim_inr, + mul_zero,Finset.sum_const_zero,add_zero] + rfl +lemma gaussianInr_linear (x : EuclideanSpace ℝ J) (g : EuclideanSpace ℝ (I⊕J)) : + inner ℝ (gaussianInr x) g=inner ℝ x (gaussianSumSplit g).2 := by + change (∑ i,g i*gaussianInr x i)=_ + simp only [Fintype.sum_sum_type,gaussianInr,PiLp.toLp_apply,Sum.elim_inl,Sum.elim_inr, + mul_zero,Finset.sum_const_zero,zero_add] + rfl +end Sum + +lemma gaussianLogPartition_measurable_finite {I S : Type*} [Fintype I] [MeasurableSpace S] + (μ : Measure S) [SFinite μ] {H : S→ℝ} {V : S→EuclideanSpace ℝ I} + (hH : Measurable H) (hV : Measurable V) : + Measurable (fun g=>Real.log (tiltPartition μ (fun s=>H s+inner ℝ (V s) g) 1)) := by + apply Measurable.log + have hm : Measurable (fun p : EuclideanSpace ℝ I×S=>H p.2+inner ℝ (V p.2) p.1) := + (hH.comp measurable_snd).add ((hV.comp measurable_snd).inner measurable_fst) + simpa only [tiltPartition,one_mul] using hm.exp.stronglyMeasurable.integral_prod_right'.measurable + +lemma gaussianInl_log_integral {I J S : Type} [Fintype I] [Fintype J] [MeasurableSpace S] + (μ : Measure S) [SFinite μ] {H : S→ℝ} {V : S→EuclideanSpace ℝ I} + (hH : Measurable H) (hV : Measurable V) : + (∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (gaussianInl (J:=J) (V s)) g) 1) + ∂stdGaussian (EuclideanSpace ℝ (I⊕J)))= + ∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (V s) g) 1) + ∂stdGaussian (EuclideanSpace ℝ I) := by + simp_rw [gaussianInl_linear] + have hp : MeasurePreserving (fun g : EuclideanSpace ℝ (I⊕J)=>(gaussianSumSplit g).1) + (stdGaussian (EuclideanSpace ℝ (I⊕J))) (stdGaussian (EuclideanSpace ℝ I)) := + measurePreserving_fst.comp gaussianSumSplit_preserving + have he:=integral_map (μ:=stdGaussian (EuclideanSpace ℝ (I⊕J))) hp.measurable.aemeasurable (gaussianLogPartition_measurable_finite μ hH hV).aestronglyMeasurable + rw [hp.map_eq] at he + exact he.symm + +lemma gaussianInr_log_integral {I J S : Type} [Fintype I] [Fintype J] [MeasurableSpace S] + (μ : Measure S) [SFinite μ] {H : S→ℝ} {V : S→EuclideanSpace ℝ J} + (hH : Measurable H) (hV : Measurable V) : + (∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (gaussianInr (I:=I) (V s)) g) 1) + ∂stdGaussian (EuclideanSpace ℝ (I⊕J)))= + ∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (V s) g) 1) + ∂stdGaussian (EuclideanSpace ℝ J) := by + simp_rw [gaussianInr_linear] + have hp : MeasurePreserving (fun g : EuclideanSpace ℝ (I⊕J)=>(gaussianSumSplit g).2) + (stdGaussian (EuclideanSpace ℝ (I⊕J))) (stdGaussian (EuclideanSpace ℝ J)) := + measurePreserving_snd.comp gaussianSumSplit_preserving + have he:=integral_map (μ:=stdGaussian (EuclideanSpace ℝ (I⊕J))) hp.measurable.aemeasurable (gaussianLogPartition_measurable_finite μ hH hV).aestronglyMeasurable + rw [hp.map_eq] at he + exact he.symm + +theorem independentGaussian_covariance_comparison {I J S : Type} [Fintype I] [Fintype J] + [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + {H : S→ℝ} {V : S→EuclideanSpace ℝ I} {W : S→EuclideanSpace ℝ J} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) + {A C ε : ℝ} (hA : 0≤A) (hC : 0≤C) (hHA : ∀ s,|H s|≤A) + (hVC : ∀ s,‖V s‖≤C) (hWC : ∀ s,‖W s‖≤C) (hε : 0≤ε) + (hcov : ∀ x y,|inner ℝ (W x) (W y)-inner ℝ (V x) (V y)|≤ε) : + |(∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (W s) g) 1) + ∂stdGaussian (EuclideanSpace ℝ J))- + ∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (V s) g) 1) + ∂stdGaussian (EuclideanSpace ℝ I)|≤Real.pi*ε := by + have hv : Measurable (fun s=>gaussianInl (J:=J) (V s)) := gaussianInl_measurable.comp hV + have hw : Measurable (fun s=>gaussianInr (I:=I) (W s)) := gaussianInr_measurable.comp hW + have ht:=euclideanGaussian_covariance_comparison μ hH hv hw hA hC hHA + (fun s=>by simpa only [gaussianInl_norm] using hVC s) + (fun s=>by simpa only [gaussianInr_norm] using hWC s) hε + (fun x y=>gaussianInl_Inr_inner (V x) (W y)) + (fun x y=>by simpa only [gaussianInr_inner,gaussianInl_inner] using hcov x y) + rwa [gaussianInl_log_integral μ hH hV,gaussianInr_log_integral μ hH hW] at ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityGoodFreshLower.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityGoodFreshLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..e19cdf9855e7cecae43c91afad22b45bfb6d5edf --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityGoodFreshLower.lean @@ -0,0 +1,212 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityFiniteIncrement +import OAI.Probability.Perceptron.Cavity.CavityUncappedLimit + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy + +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction + +lemma cavity_good_fresh_fullLog_lower (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) {α : ℝ} (hα : 0<α) + (g : Jet3) (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) + (G : CavityGoodParameters α g.f) (ε : ℝ) (hε : 0<ε) : + ∀ᶠ k : ℕ in atTop,∀ δ : ℝ,0<δ→∀ᶠ n : ℕ in atTop, + ∀ v∈bulkJointGoodSet α g.f G.J n, + (k+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖-δ≤ + cavityBulkFullLog k (cavityFreshCount α n (k+1)) n (patternCount α (n+1)) g v := by + filter_upwards [cavity_good_fullLog_lower P hB hα g hg G ε hε] with k hk + intro δ hδ + let D:=⌈((k+1:ℕ):ℝ)*α+1⌉₊ + have h : ∀ᶠ n : ℕ in atTop,∀ d∈Finset.range (D+1), + |(d:ℝ)-(k+1:ℕ)*α|≤1→∀ v∈bulkJointGoodSet α g.f G.J n, + (k+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖-δ≤ + cavityBulkFullLog k d n (patternCount α (n+1)) g v := by + apply (eventually_all_finset _).mpr + intro d _ + by_cases hd : |(d:ℝ)-(k+1:ℕ)*α|≤1 + · exact (hk d hd δ hδ).mono (fun _n hn _=>hn) + · exact Eventually.of_forall (fun _ h=>False.elim (hd h)) + filter_upwards [h] with n hn + exact hn _ (Finset.mem_range.mpr (Nat.lt_succ_of_le (cavity_fresh_count hα.le n (k+1)).2.2)) + (cavity_fresh_count hα.le n (k+1)).2.1 + + +def cavityOriginalIncrement (α : ℝ) (f : ℝ→ᵇℝ) (n k : ℕ) (v : ℕ→ℝ) : ℝ := + bulkExpectedLog (n+(k+1)) (patternCount α (n+(k+1)+1)) f v- + bulkExpectedLog n (patternCount α (n+1)) f v + +lemma cavity_original_increment_error {α : ℝ} (hα : 0≤α) (k : ℕ) (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) {δ : ℝ} (hδ : 0<δ) : + ∀ᶠ n : ℕ in atTop,∀ v : ℕ→ℝ,(∀ p,|v (p+1)|≤2)→ + Real.log (cavityShellMass k)-α*‖g.dilationMark h1‖/2-δ+ + cavityBulkFullLog k (cavityFreshCount α n (k+1)) n (patternCount α (n+1)) g v≤ + cavityOriginalIncrement α g.f n k v := by + let KC:=α*‖g.dilationMark h1‖ + let D:=⌈((k+1:ℕ):ℝ)*α+1⌉₊ + let E:=fun n=>cavityUniformError n k (patternCount α (n+1)) D g h1 h2 h3 2 KC + have hE : Tendsto E atTop (𝓝 0):=cavityUniformError_tendsto k D _ g h1 h2 h3 2 KC (cavity_count_density hα) + have he:=((cavitySphereLaw_shell_log_tendsto k).sub_const (KC/2)).sub hE + simp only [sub_zero] at he + have hev:=he.eventually (Ioi_mem_nhds (show Real.log (cavityShellMass k)-KC/2-δ< + Real.log (cavityShellMass k)-KC/2 by linarith)) + filter_upwards [hev,cavityShell_probability_eventually k,eventually_ge_atTop (2*((k+1)+1))] with n hn hp hN + intro v hv + have hK : (patternCount α (n+1):ℝ)/(n+1:ℕ)*‖g.dilationMark h1‖≤KC := by + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + exact (div_le_iff₀ (by positivity : (0:ℝ)<(n+1:ℕ))).mpr (cavity_count_bounds hα (n+1)).2 + have hinc:=cavity_finite_increment_uniform n k (patternCount α (n+1)) (cavityFreshCount α n (k+1)) D + g h1 h2 h3 (by omega) hp v (by norm_num : (0:ℝ)≤2) hv (cavity_fresh_count hα n (k+1)).2.2 hK + rw [(cavity_fresh_count hα n (k+1)).1] at hinc + have heq : n+1+(k+1)=n+(k+1)+1:=by omega + rw [heq] at hinc + change _≤cavityOriginalIncrement α g.f n k v at hinc + dsimp only [E,KC] at hn hinc + linarith + +lemma cavity_original_increment_background {α : ℝ} (hα : 0≤α) (k : ℕ) (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) : + ∃ A : ℝ,∀ᶠ n : ℕ in atTop,∀ v : ℕ→ℝ,(∀ p,|v (p+1)|≤2)→ + A≤cavityOriginalIncrement α g.f n k v := by + let KC:=α*‖g.dilationMark h1‖ + let D:=⌈((k+1:ℕ):ℝ)*α+1⌉₊ + refine ⟨Real.log (cavityShellMass k)-KC/2-1-D*‖g.f‖-(k+1:ℕ)*KC/2,?_⟩ + filter_upwards [cavity_original_increment_error hα k g h1 h2 h3 (by norm_num : (0:ℝ)<1)] with n hn + intro v hv + have hC : ∀ (a : BulkDisorder (n+1) (patternCount α (n+1))) x, + |bulkC (n+1) (patternCount α (n+1)) g a.1 x|≤KC := by + intro a x + apply (bulkC_bound n _ g h1 a x).trans + apply mul_le_mul_of_nonneg_right _ (norm_nonneg _) + exact (div_le_iff₀ (by positivity : (0:ℝ)<(n+1:ℕ))).mpr (cavity_count_bounds hα (n+1)).2 + have hlow:=cavityBulkFullLog_lower k (cavityFreshCount α n (k+1)) n _ g h1 v hC + have hd : (cavityFreshCount α n (k+1):ℝ)≤D := by exact_mod_cast (cavity_fresh_count hα n (k+1)).2.2 + have hdn:=mul_le_mul_of_nonneg_right hd (norm_nonneg g.f) + have hi:=hn v hv + dsimp only [KC] at * + linarith + +lemma cavity_original_increment_good (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) {α : ℝ} (hα : 0<α) (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) (G : CavityGoodParameters α g.f) + {ε : ℝ} (hε : 0<ε) : + ∀ᶠ k : ℕ in atTop,∀ δ : ℝ,0<δ→∀ᶠ n : ℕ in atTop,∀ v∈bulkJointGoodSet α g.f G.J n, + Real.log (cavityShellMass k)-α*‖g.dilationMark h1‖/2+ + (k+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖-δ≤ + cavityOriginalIncrement α g.f n k v := by + filter_upwards [cavity_good_fresh_fullLog_lower P hB hα g h1 G ε hε] with k hk + intro δ hδ + filter_upwards [hk (δ/2) (by positivity),cavity_original_increment_error hα.le k g h1 h2 h3 + (show 0<δ/2 by positivity)] with n hn he + intro v hv + have hv2 : ∀ p,|v (p+1)|≤(2:ℝ) := by + intro p + exact abs_le.mpr ⟨by linarith [(hv.2 (p+1)).1],(hv.2 (p+1)).2⟩ + have hlo:=hn v hv + have hi:=he v hv2 + linarith + + +lemma bulkExpectedLog_parameter_measurable (n M : ℕ) (f : ℝ→ᵇℝ) : + Measurable (bulkExpectedLog n M f) := by + have hm : Measurable (fun p : (ℕ→ℝ)×BulkDisorder (n+1) M=> + bulkLogPartition n M f p.1 p.2.1 p.2.2) := by + simp_rw [bulkLogPartition_eq] + simpa only [tiltPartition,one_mul] using + (bulkHamiltonian_parameter_continuous (n+1) M f).measurable.exp.stronglyMeasurable.integral_prod_right'.measurable.log + exact hm.stronglyMeasurable.integral_prod_right'.measurable + +lemma bulkExpectedLog_box_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (hv : ∀ p,|v (p+1)|≤2) : + |bulkExpectedLog n M f v|≤M*‖f‖+2*|bulkScale (n+1)| * + ∫ a : BulkDisorder (n+1) M,‖a.2‖ ∂bulkDisorderLaw (n+1) M := by + have hb : bulkFeatureBound (n+1) v≤2*|bulkScale (n+1)| := by + have hh:=bulkFeatureBound_sq_le (n+1) v (by norm_num : (0:ℝ)≤2) hv + have hs:=sq_abs (bulkScale (n+1)) + nlinarith [Real.sqrt_nonneg (∑ p,bulkAmplitude (n+1) v p^2),abs_nonneg (bulkScale (n+1))] + let Q:=bulkDisorderLaw (n+1) M + have hi : Integrable (fun a : BulkDisorder (n+1) M=> + M*‖f‖+2*|bulkScale (n+1)| *‖a.2‖) Q := + (integrable_const _).add ((bulkMarkNorm_integrable (n+1) M).const_mul _) + calc + _≤∫ a : BulkDisorder (n+1) M,|bulkLogPartition n M f v a.1 a.2| ∂Q := abs_integral_le_integral_abs + _≤∫ a : BulkDisorder (n+1) M,M*‖f‖+2*|bulkScale (n+1)| *‖a.2‖ ∂Q := by + apply integral_mono ((bulkLogPartition_memLp n M f v).integrable (by norm_num)).abs hi + intro a + exact (bulkLogPartition_bound n M f v a).trans + (add_le_add le_rfl (mul_le_mul_of_nonneg_right hb (norm_nonneg a.2))) + _=_ := by rw [integral_add (integrable_const _) ((bulkMarkNorm_integrable (n+1) M).const_mul _),integral_const_mul]; simp [integral_const_mul] + +lemma bulkExpectedLog_parameter_integrable (n M : ℕ) (f : ℝ→ᵇℝ) : + Integrable (bulkExpectedLog n M f) bulkParameterLaw := by + apply Integrable.of_bound (bulkExpectedLog_parameter_measurable n M f).aestronglyMeasurable + (M*‖f‖+2*|bulkScale (n+1)| *∫ a : BulkDisorder (n+1) M,‖a.2‖ ∂bulkDisorderLaw (n+1) M) + filter_upwards [bulkParameterLaw_ae] with v hv + rw [Real.norm_eq_abs] + exact bulkExpectedLog_box_bound n M f v (fun p=>abs_le.mpr ⟨by linarith [(hv (p+1)).1],(hv (p+1)).2⟩) + +def cavityAveragedLog (α : ℝ) (f : ℝ→ᵇℝ) (n : ℕ) : ℝ := + ∫ v,bulkExpectedLog n (patternCount α (n+1)) f v ∂bulkParameterLaw + +lemma cavityAveragedLog_sub (α : ℝ) (f : ℝ→ᵇℝ) (n k : ℕ) : + cavityAveragedLog α f (n+(k+1))-cavityAveragedLog α f n= + ∫ v,cavityOriginalIncrement α f n k v ∂bulkParameterLaw := + (integral_sub (bulkExpectedLog_parameter_integrable _ _ f) + (bulkExpectedLog_parameter_integrable _ _ f)).symm + +lemma integral_good_bad_lower {X : Type*} [MeasurableSpace X] (μ : Measure X) + [IsProbabilityMeasure μ] {F : X→ℝ} (hF : Integrable F μ) + {s : Set X} (hs : MeasurableSet s) {A B : ℝ} + (hA : ∀ᵐ x ∂μ,A≤F x) (hB : ∀ x∈s,B≤F x) : + B+(A-B)*μ.real sᶜ≤∫ x,F x ∂μ := by + have hi : Integrable (fun x=>B+sᶜ.indicator (fun _=>A-B) x) μ := + (integrable_const _).add ((integrable_const _).indicator hs.compl) + have he : (∫ x,B+sᶜ.indicator (fun _=>A-B) x ∂μ)=B+(A-B)*μ.real sᶜ := by + rw [integral_add (integrable_const _) ((integrable_const _).indicator hs.compl)] + simp [integral_indicator_const,hs.compl,smul_eq_mul,mul_comm] + rw [←he] + apply integral_mono_ae hi hF + filter_upwards [hA] with x hx + by_cases hxs : x∈s + · simpa [hxs] using hB x hxs + · simpa [hxs] using hx + +lemma cavity_averaged_increment_good (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) {α : ℝ} (hα : 0<α) (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) (G : CavityGoodParameters α g.f) + {ε : ℝ} (hε : 0<ε) : + ∀ᶠ k : ℕ in atTop,∀ δ : ℝ,0<δ→∀ᶠ n : ℕ in atTop, + Real.log (cavityShellMass k)-α*‖g.dilationMark h1‖/2+ + (k+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖-δ≤ + cavityAveragedLog α g.f (n+(k+1))-cavityAveragedLog α g.f n := by + filter_upwards [cavity_original_increment_good P hB hα g h1 h2 h3 G hε] with k hk + intro δ hδ + obtain ⟨A,hA⟩:=cavity_original_increment_background hα.le k g h1 h2 h3 + let B:=Real.log (cavityShellMass k)-α*‖g.dilationMark h1‖/2+ + (k+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖-δ/2 + have ht : Tendsto (fun n=>(A-B)*bulkParameterLaw.real (bulkJointGoodSet α g.f G.J n)ᶜ) atTop (𝓝 0) := by + simpa only [mul_zero] using G.mass.const_mul (A-B) + have he:=ht.eventually (Ioi_mem_nhds (show -δ/2<0 by linarith)) + filter_upwards [hk (δ/2) (by positivity),hA,he] with n hn ha he + have hl:=integral_good_bad_lower bulkParameterLaw + ((bulkExpectedLog_parameter_integrable _ _ g.f).sub (bulkExpectedLog_parameter_integrable _ _ g.f)) + (G.measurable n) (A:=A) (B:=B) (F:=cavityOriginalIncrement α g.f n k) + (by + filter_upwards [bulkParameterLaw_ae] with v hv + exact ha v (fun p=>abs_le.mpr ⟨by linarith [(hv (p+1)).1],(hv (p+1)).2⟩)) hn + rw [←cavityAveragedLog_sub] at hl + dsimp only [B] at hl he + linarith + + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityIncrementLaw.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityIncrementLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..208550f984e07546b19489e996989797dc81f7bb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityIncrementLaw.lean @@ -0,0 +1,220 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityFreshReplacement +import OAI.Probability.Perceptron.Cavity.CavityNormalizedIncrement +import OAI.Probability.Perceptron.Cavity.CavityProductLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev CavityIncrementRandom (n L M d : ℕ) := + BulkDisorder (n+1) M×(Fin d→Fin (n+1)→ℝ)×(Fin M→Spin L)×(Fin d→Spin L) + +def cavityIncrementLaw (n L M d : ℕ) : Measure (CavityIncrementRandom n L M d) := + (bulkDisorderLaw (n+1) M).prod ((finitePatternRowsLaw (n+1) d).prod + ((Measure.pi fun _ : Fin M=>stdGaussian (Spin L)).prod (Measure.pi fun _ : Fin d=>stdGaussian (Spin L)))) + +instance (n L M d : ℕ) : IsProbabilityMeasure (cavityIncrementLaw n L M d) := by + unfold cavityIncrementLaw + infer_instance + +def cavityIncrementFullRows (n L M d : ℕ) (p : CavityIncrementRandom n L M d) : + Fin (M+d)→Fin (n+1+L)→ℝ := + cavityRowsAppend (n+1+L) M d (cavityJoinedPatterns (n+1) L M p.1.1 p.2.2.1) + (cavityJoinedPatterns (n+1) L d p.2.1 p.2.2.2) + +lemma cavityIncrementFullRows_preserving (n L M d : ℕ) : + MeasurePreserving (fun p : CavityIncrementRandom n L M d=>(cavityIncrementFullRows n L M d p,p.1.2)) + (cavityIncrementLaw n L M d) + ((finitePatternRowsLaw (n+1+L) (M+d)).prod (stdGaussian (BulkMark (n+1)))) := by + let : IsProbabilityMeasure (stdGaussian (BulkMark (n+1))) := inferInstance + let : IsProbabilityMeasure (finitePatternRowsLaw (n+1) M) := inferInstance + let : IsProbabilityMeasure (finitePatternRowsLaw (n+1) d) := inferInstance + let : IsProbabilityMeasure (Measure.pi fun _ : Fin M=>stdGaussian (Spin L)) := inferInstance + let : IsProbabilityMeasure (Measure.pi fun _ : Fin d=>stdGaussian (Spin L)) := inferInstance + let : IsProbabilityMeasure (finitePatternRowsLaw (n+1+L) M) := inferInstance + let : IsProbabilityMeasure (finitePatternRowsLaw (n+1+L) d) := inferInstance + let : SFinite (stdGaussian (BulkMark (n+1))) := inferInstance + let : SFinite (finitePatternRowsLaw (n+1) d) := inferInstance + have h1 := cavity_product_shuffle (finitePatternRowsLaw (n+1) M) (stdGaussian (BulkMark (n+1))) + (finitePatternRowsLaw (n+1) d) (Measure.pi fun _ : Fin M=>stdGaussian (Spin L)) + (Measure.pi fun _ : Fin d=>stdGaussian (Spin L)) + let : SFinite ((finitePatternRowsLaw (n+1) M).prod (Measure.pi fun _ : Fin M=>stdGaussian (Spin L))) := inferInstance + let : SFinite ((finitePatternRowsLaw (n+1) d).prod (Measure.pi fun _ : Fin d=>stdGaussian (Spin L))) := inferInstance + have hOld : MeasurePreserving (fun p=>(cavityJoinedPatterns (n+1) L M p.1 p.2)) + ((finitePatternRowsLaw (n+1) M).prod (Measure.pi fun _ : Fin M=>stdGaussian (Spin L))) + (finitePatternRowsLaw (n+1+L) M) := cavityJoinedPatterns_preserving (n+1) L M + have hNew : MeasurePreserving (fun p=>(cavityJoinedPatterns (n+1) L d p.1 p.2)) + ((finitePatternRowsLaw (n+1) d).prod (Measure.pi fun _ : Fin d=>stdGaussian (Spin L))) + (finitePatternRowsLaw (n+1+L) d) := cavityJoinedPatterns_preserving (n+1) L d + have h2 := hOld.prod hNew + have h3 := h2.prod (MeasurePreserving.id (stdGaussian (BulkMark (n+1)))) + have h4 := (cavityRowsAppend_preserving (n+1+L) M d).prod + (MeasurePreserving.id (stdGaussian (BulkMark (n+1)))) + exact h4.comp (h3.comp h1) + +lemma cavityShellLowLog_measurable (n L M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + Measurable (cavityShellLowLog n L M f v) := by + let :=cavityShellBaseLaw_probability n L hp + have hH : Measurable (fun p : ((Fin M→Fin (n+1+L)→ℝ)×BulkMark (n+1))×CavityShellSpin n L=> + cavityShellPatternEnergy n L M f p.1.1 p.2+inner ℝ (bulkFeature (n+1) v p.2.1) p.1.2) := + ((cavityShellPatternEnergy_joint_measurable n L M f).comp + (measurable_fst.fst.prodMk measurable_snd)).add + (((bulkFeature_continuous (n+1) v).measurable.comp measurable_snd.fst).inner measurable_fst.snd) + unfold cavityShellLowLog tiltPartition + simpa only [one_mul] using + (hH.exp.stronglyMeasurable.integral_prod_right' (ν:=cavityShellBaseLaw n L)).measurable.log + +lemma cavityIncrement_actual_integrable (n L M d : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + Integrable (fun p : CavityIncrementRandom n L M d=> + cavityShellLowLog n L (M+d) f v (cavityIncrementFullRows n L M d p,p.1.2)) + (cavityIncrementLaw n L M d) := + ((cavityIncrementFullRows_preserving n L M d).integrable_comp + (cavityShellLowLog_measurable n L (M+d) f v hp).aestronglyMeasurable).mpr + (cavityShellLowLog_integrable n L (M+d) f v hp) + +lemma cavityIncrement_actual_expectation (n L M d : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + (∫ p : CavityIncrementRandom n L M d, + cavityShellLowLog n L (M+d) f v (cavityIncrementFullRows n L M d p,p.1.2) + ∂cavityIncrementLaw n L M d)= + ∫ p,cavityShellLowLog n L (M+d) f v p + ∂(finitePatternRowsLaw (n+1+L) (M+d)).prod (stdGaussian (BulkMark (n+1))) := + cavity_integral_preserving _ _ _ (cavityIncrementFullRows_preserving n L M d) _ + (cavityShellLowLog_measurable n L (M+d) f v hp).aestronglyMeasurable + +lemma finiteRows_toLp_preserving (N d : ℕ) : + MeasurePreserving (fun a : Fin d→Fin N→ℝ=>fun i=>WithLp.toLp 2 (a i)) + (finitePatternRowsLaw N d) (Measure.pi fun _ : Fin d=>stdGaussian (Spin N)) := by + apply measurePreserving_pi + intro i + exact ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + +lemma cavityFreshMajorant_rows_integrable (N L d : ℕ) (f : Jet3) : + Integrable (fun p : (Fin d→Fin N→ℝ)×(Fin d→Spin L)=>cavityFreshMajorant N L d f p.1 p.2) + ((finitePatternRowsLaw N d).prod (Measure.pi fun _ : Fin d=>stdGaussian (Spin L))) := by + have hi:=cavityFreshMajorant_integrable N L d f + have hp:=(finiteRows_toLp_preserving N d).prod (MeasurePreserving.id (Measure.pi fun _ : Fin d=>stdGaussian (Spin L))) + convert (hp.integrable_comp hi.aestronglyMeasurable).mpr hi using 1 + rfl + +lemma cavityFreshMajorant_rows_mean_bound (n L d : ℕ) (f : Jet3) : + (∫ p : (Fin d→Fin (n+1)→ℝ)×(Fin d→Spin L),cavityFreshMajorant (n+1) L d f p.1 p.2 + ∂(finitePatternRowsLaw (n+1) d).prod (Measure.pi fun _ : Fin d=>stdGaussian (Spin L)))≤ + ‖f.d1‖*d*((L:ℝ)+1)*(1+Real.sqrt L)/Real.sqrt (n+1:ℕ) := by + let : IsProbabilityMeasure (finitePatternRowsLaw (n+1) d) := inferInstance + let : IsProbabilityMeasure (Measure.pi fun _ : Fin d=>stdGaussian (Spin L)) := inferInstance + let : SFinite (finitePatternRowsLaw (n+1) d) := inferInstance + have hi:=cavityFreshMajorant_integrable (n+1) L d f + have hp:=(finiteRows_toLp_preserving (n+1) d).prod (MeasurePreserving.id (Measure.pi fun _ : Fin d=>stdGaussian (Spin L))) + have h:=cavity_integral_preserving _ _ _ hp _ hi.aestronglyMeasurable + exact (Eq.trans (by rfl) h).le.trans (cavityFreshMajorant_mean_bound n L d f) + +abbrev CavityProxyRandom (n L M d : ℕ) := BulkDisorder (n+1) M×(Fin d→Fin (n+1)→ℝ)×(Fin M→Spin L) +def cavityProxyLaw (n L M d : ℕ) : Measure (CavityProxyRandom n L M d) := + (bulkDisorderLaw (n+1) M).prod ((finitePatternRowsLaw (n+1) d).prod (Measure.pi fun _ : Fin M=>stdGaussian (Spin L))) +instance (n L M d : ℕ) : IsProbabilityMeasure (cavityProxyLaw n L M d) := by + unfold cavityProxyLaw; infer_instance + +def cavityProxyProjection (n L M d : ℕ) (p : CavityIncrementRandom n L M d) : CavityProxyRandom n L M d := + (p.1,p.2.1,p.2.2.1) +lemma cavityProxyProjection_preserving (n L M d : ℕ) : + MeasurePreserving (cavityProxyProjection n L M d) (cavityIncrementLaw n L M d) (cavityProxyLaw n L M d) := + (MeasurePreserving.id _).prod ((MeasurePreserving.id _).prod measurePreserving_fst) + +def cavityProxyHamiltonian (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) + (p : CavityProxyRandom n L M d) (s : CavityShellSpin n L) : ℝ := + cavityOldJoinedHamiltonian n L M f v p.1 (normalizedPatternEnergy (n+1) d f.f p.2.1) p.2.2 s + +def cavityProxyLog (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) (p : CavityProxyRandom n L M d) : ℝ := + Real.log (∫ s,Real.exp (cavityProxyHamiltonian n L M d f v p s) ∂cavityShellBaseLaw n L) + +lemma cavityProxyHamiltonian_measurable (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) : + Measurable (fun p : CavityProxyRandom n L M d×CavityShellSpin n L=>cavityProxyHamiltonian n L M d f v p.1 p.2) := by + have hj : Measurable (fun p : CavityProxyRandom n L M d×CavityShellSpin n L=> + cavityJoinedPatterns (n+1) L M p.1.1.1 p.1.2.2) := + (cavityJoinedPatterns_preserving (n+1) L M).measurable.comp + (f:=fun p : CavityProxyRandom n L M d×CavityShellSpin n L=>(p.1.1.1,p.1.2.2)) + (measurable_fst.fst.fst.prodMk measurable_fst.snd.snd) + have hs : Measurable (fun p : CavityProxyRandom n L M d×CavityShellSpin n L=> + cavityShellPatternEnergy n L M f.f (cavityJoinedPatterns (n+1) L M p.1.1.1 p.1.2.2) p.2) := + (cavityShellPatternEnergy_joint_measurable n L M f.f).comp + (f:=fun p : CavityProxyRandom n L M d×CavityShellSpin n L=>(cavityJoinedPatterns (n+1) L M p.1.1.1 p.1.2.2,p.2)) + (hj.prodMk measurable_snd) + have hm : Measurable (fun p : CavityProxyRandom n L M d×CavityShellSpin n L=> + inner ℝ (bulkFeature (n+1) v p.2.1) p.1.1.2) := + (((bulkFeature_continuous (n+1) v).measurable.comp + (f:=fun p : CavityProxyRandom n L M d×CavityShellSpin n L=>p.2.1) measurable_snd.fst).inner measurable_fst.fst.snd) + have hn : Measurable (fun p : CavityProxyRandom n L M d×CavityShellSpin n L=> + normalizedPatternEnergy (n+1) d f.f p.1.2.1 p.2.1) := + (normalizedPatternEnergy_continuous (n+1) d f.f).measurable.comp + (f:=fun p : CavityProxyRandom n L M d×CavityShellSpin n L=>(p.1.2.1,p.2.1)) + (measurable_fst.snd.fst.prodMk measurable_snd.fst) + unfold cavityProxyHamiltonian cavityOldJoinedHamiltonian + exact (hs.add hm).add hn + +lemma cavityProxyLog_measurable (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + Measurable (cavityProxyLog n L M d f v) := by + let :=cavityShellBaseLaw_probability n L hp + exact (cavityProxyHamiltonian_measurable n L M d f v).exp.stronglyMeasurable.integral_prod_right'.measurable.log + +lemma cavityProxyHamiltonian_bound (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) + (p : CavityProxyRandom n L M d) (s : CavityShellSpin n L) : + |cavityProxyHamiltonian n L M d f v p s|≤(M+d)*‖f.f‖+bulkFeatureBound (n+1) v*‖p.1.2‖ := by + unfold cavityProxyHamiltonian cavityOldJoinedHamiltonian + exact ((abs_add_le _ _).trans (add_le_add ((abs_add_le _ _).trans + (add_le_add (cavityShellPatternEnergy_bound n L M f.f _ s) + (by simpa only [bulkFeature_norm] using abs_real_inner_le_norm (bulkFeature (n+1) v s.1) p.1.2))) + (normalizedPatternEnergy_bound (n+1) d f.f _ _))).trans_eq (by ring) + +lemma cavityProxyLog_integrable (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + Integrable (cavityProxyLog n L M d f v) (cavityProxyLaw n L M d) := by + let :=cavityShellBaseLaw_probability n L hp + have hb : Integrable (fun p : BulkDisorder (n+1) M=>‖p.2‖) (bulkDisorderLaw (n+1) M) := + (IsGaussian.integrable_id (μ:=stdGaussian (BulkMark (n+1)))).norm.comp_snd (finitePatternRowsLaw (n+1) M) + have hg : Integrable (fun p : CavityProxyRandom n L M d=>‖p.1.2‖) (cavityProxyLaw n L M d) := + hb.comp_fst ((finitePatternRowsLaw (n+1) d).prod (Measure.pi fun _ : Fin M=>stdGaussian (Spin L))) + have hm : Measurable (fun p : CavityShellSpin n L×CavityProxyRandom n L M d=> + cavityProxyHamiltonian n L M d f v p.2 p.1) := + (cavityProxyHamiltonian_measurable n L M d f v).comp + (f:=fun p : CavityShellSpin n L×CavityProxyRandom n L M d=>(p.2,p.1)) measurable_swap + unfold cavityProxyLog + apply cavity_log_integrable_of_bound (cavityShellBaseLaw n L) (cavityProxyLaw n L M d) + (fun p=>cavityProxyHamiltonian n L M d f v p.2 p.1) + hm + (fun p=>(M+d)*‖f.f‖+bulkFeatureBound (n+1) v*‖p.1.2‖) + ((integrable_const _).add (hg.const_mul _)) + (fun p=>by unfold bulkFeatureBound; positivity) + intro s p + exact cavityProxyHamiltonian_bound n L M d f v p s + +lemma cavityProxyLog_section_integrable (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) + (a : BulkDisorder (n+1) M) (b : Fin d→Fin (n+1)→ℝ) : + Integrable (fun y=>cavityProxyLog n L M d f v (a,b,y)) (Measure.pi fun _ : Fin M=>stdGaussian (Spin L)) := by + let :=cavityShellBaseLaw_probability n L hp + have hm : Measurable (fun p : CavityShellSpin n L×(Fin M→Spin L)=> + cavityProxyHamiltonian n L M d f v (a,b,p.2) p.1) := + (cavityProxyHamiltonian_measurable n L M d f v).comp + (f:=fun p : CavityShellSpin n L×(Fin M→Spin L)=>((a,b,p.2),p.1)) + ((measurable_const.prodMk (measurable_const.prodMk measurable_snd)).prodMk measurable_fst) + unfold cavityProxyLog + apply cavity_log_integrable_of_bound (cavityShellBaseLaw n L) (Measure.pi fun _ : Fin M=>stdGaussian (Spin L)) + (fun p=>cavityProxyHamiltonian n L M d f v (a,b,p.2) p.1) + hm + (fun _=>(M+d)*‖f.f‖+bulkFeatureBound (n+1) v*‖a.2‖) (integrable_const _) + (fun _=>by unfold bulkFeatureBound; positivity) + intro s y + exact cavityProxyHamiltonian_bound n L M d f v (a,b,y) s +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityIndexedLog.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityIndexedLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6ce223893e0a7833ac29cf30f9e51a3f0a44bdb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityIndexedLog.lean @@ -0,0 +1,56 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.IndexedGibbsPartition + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_indexed_log_recursion {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S→X) (hs : Measurable step) + (H : X→ℝ) (hH : Measurable H) {C : ℝ} (hC : ∀ x,|H x|≤C) + (k : ℕ) (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0 + Real.log (∫ l,Real.exp (H (indexedLeafState step k (x,p.2) l)) + ∂indexedLeafProbability k p.1))=ᵐ[B.prod M] + (fun p=>Real.log (decoratedTerminalTotal step H k (x,indexedCascadeRealize k p)/ + decoratedTerminalTotal step (fun _=>0) k (x,indexedCascadeRealize k p))) := by + filter_upwards [hb,hr] with p hp hpr + rw [indexedLeafProbability_terminal_integral ν hs hH k p.1 hp hpr p.2 x] + have hm : Measurable (fun η : DecoratedCascade S k=> + Real.log (decoratedTerminalTotal step H k (x,η)/decoratedTerminalTotal step (fun _=>0) k (x,η))) := + (((decoratedTerminalTotal_measurable ν step hs hH k z).comp (measurable_const.prodMk measurable_id)).div + ((decoratedTerminalTotal_measurable ν step hs measurable_const k z).comp + (measurable_const.prodMk measurable_id))).log + change (∫ p,Real.log (∫ l,Real.exp (H (indexedLeafState step k (x,p.2) l)) + ∂indexedLeafProbability k p.1) ∂B.prod M)=_ + rw [integral_congr_ae he,←integral_map (indexedCascadeRealize_measurable k).aemeasurable hm.aestronglyMeasurable] + change (∫ η,Real.log (decoratedTerminalTotal step H k (x,η)/ + decoratedTerminalTotal step (fun _=>0) k (x,η)) + ∂(((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + (indexedCascadeMarksLaw ν k)).map (indexedCascadeRealize k)))=_ + rw [indexedCascadeRealize_law ν k z] + exact finiteCascade_terminal_log_recursion_of_fractional ν step hs k z hz hz0 hz1 hH + (finiteCascadeFractionalIntegrable_of_bounded ν step hs k z hz0 hH hC) x + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityLabelAnnealed.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelAnnealed.lean new file mode 100644 index 0000000000000000000000000000000000000000..de401a01519b68132ea6517104c145d6f8a2f4ab --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelAnnealed.lean @@ -0,0 +1,152 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityResidualUncap +import OAI.Probability.Perceptron.Variational.KernelProductIntegral + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def cavityLabelFullPartition (n d k : ℕ) (f : ℝ→ᵇℝ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (p : IndexedCascadeBase k×(ℕ→ℝ)) : ℝ := + ∫ x,Real.exp (cavityLabelWeight n d k f σ q (p.2,x))*cavityLabelSpherical n d k σ q (p.2,x) + ∂(indexedLeafProbability k p.1).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + +lemma cavityLabelFullPartition_measurable (n d k : ℕ) (f : ℝ→ᵇℝ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) : + Measurable (cavityLabelFullPartition n d k f σ q) := by + have hf := (cavityLabelWeight_measurable n d k f σ q).exp.mul + (cavityLabelSpherical_measurable n d k σ q) + have hp : Measurable (fun t : (IndexedCascadeBase k×(ℕ→ℝ))×(IndexedLeaf k×EuclideanSpace ℝ (Fin (n+1)⊕Fin d))=> + (t.1.2,t.2)) := measurable_fst.snd.prodMk measurable_snd + exact measurable_kernel_product_integral (indexedLeafKernel k) + (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) Prod.fst measurable_fst + (fun t=>Real.exp (cavityLabelWeight n d k f σ q (t.1.2,t.2))* + cavityLabelSpherical n d k σ q (t.1.2,t.2)) (hf.comp hp) + +lemma cavityLabelPartition_eq_product (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (p : IndexedCascadeBase k×(ℕ→ℝ)) : + cavityLabelPartition n d k f Λ hΛ σ q p= + ∫ x,Real.exp (cavityLabelWeight n d k f σ q (p.2,x))*min (cavityLabelSpherical n d k σ q (p.2,x)) Λ + ∂(indexedLeafProbability k p.1).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) := by + let Ψ:=cavitySingleTest n d f Λ hΛ + let G:=fun x : IndexedLeaf k×EuclideanSpace ℝ (Fin (n+1)⊕Fin d)=> + Ψ (cavityLabelCompletedMark n d k σ q (p.2,x)) + have hm : Measurable G := Ψ.measurable.comp + ((cavityLabelCompletedMark_measurable n d k σ q).comp (measurable_const.prodMk measurable_id)) + have hi : Integrable G ((indexedLeafProbability k p.1).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))) := + Integrable.of_bound hm.aestronglyMeasurable ‖Ψ‖ (ae_of_all _ fun x=>Ψ.norm_coe_le_norm _) + have he x : G x=Real.exp (cavityLabelWeight n d k f σ q (p.2,x))* + min (cavityLabelSpherical n d k σ q (p.2,x)) Λ := by + simp only [G,Ψ,cavitySingleTest_apply,cavityLabelWeight,cavityLabelSpherical,Real.exp_sum,gaussianSumSplit] + rw [mul_comm] + rw [show (fun x=>Real.exp (cavityLabelWeight n d k f σ q (p.2,x))* + min (cavityLabelSpherical n d k σ q (p.2,x)) Λ)=G from funext fun x=>(he x).symm, + integral_prod _ hi] + rfl + +lemma integrable_product_of_nonneg_conditional {B G : Type*} + [MeasurableSpace B] [MeasurableSpace G] (μ : Measure B) (P : Measure G) + [IsProbabilityMeasure μ] [IsProbabilityMeasure P] + (D : B×G→ℝ) (hD : Measurable D) (K : ℝ) + (hi : ∀ b,Integrable (fun g=>D (b,g)) P) + (h0 : ∀ b,∀ᵐ g ∂P,0≤D (b,g)) (hK : ∀ b,(∫ g,D (b,g) ∂P)≤K) : + Integrable D (μ.prod P) ∧ 0≤∫ p,D p ∂μ.prod P ∧ (∫ p,D p ∂μ.prod P)≤K := by + have hn b : (∫ g,‖D (b,g)‖ ∂P)=∫ g,D (b,g) ∂P := by + apply integral_congr_ae + filter_upwards [h0 b] with g hg + exact Real.norm_of_nonneg hg + have hI : Integrable D (μ.prod P) := by + apply (integrable_prod_iff hD.aestronglyMeasurable).mpr + refine ⟨ae_of_all _ hi,?_⟩ + apply Integrable.of_bound (hD.norm.stronglyMeasurable.integral_prod_right).aestronglyMeasurable K + filter_upwards [] with b + rw [hn,Real.norm_eq_abs,abs_of_nonneg (integral_nonneg_of_ae (h0 b))] + exact hK b + refine ⟨hI,?_,?_⟩ + · rw [integral_prod _ hI] + exact integral_nonneg fun b=>integral_nonneg_of_ae (h0 b) + · rw [integral_prod _ hI] + calc + _≤∫ _ : B,K ∂μ := integral_mono hI.integral_prod_left (integrable_const K) hK + _=K := by simp + +theorem cavityLabel_uncap_annealed (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (f : ℝ→ᵇℝ) (z : Fin k→ℝ) {Λ : ℝ} (hΛ : 1≤Λ) : + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i) + let E:=fun t=>Real.log (cavityLabelFullPartition n d k f σ (cavityPairProfile n d p) t)- + Real.log (cavityLabelPartition n d k f Λ hΛ σ (cavityPairProfile n d p) t) + let P:=(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw + Integrable E P ∧ 0≤∫ t,E t ∂P ∧ (∫ t,E t ∂P)≤ + Real.exp (2*((d:ℝ)*‖f‖))/Λ*Real.exp (2*(n+1:ℕ)*D.2.val) := by + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i) + let q:=cavityPairProfile n d p + let F:=cavityLabelSpherical n d k σ q + let W:=cavityLabelWeight n d k f σ q + let E:=fun t=>Real.log (cavityLabelFullPartition n d k f σ q t)- + Real.log (cavityLabelPartition n d k f Λ hΛ σ q t) + have hm : Measurable E := (cavityLabelFullPartition_measurable n d k f σ q).log.sub + (cavityLabelPartition_measurable n d k f Λ hΛ σ q).log + have he b g : E (b,g)=Real.log (∫ x,Real.exp (W (g,x))*F (g,x) + ∂(indexedLeafProbability k b).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))))- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ + ∂(indexedLeafProbability k b).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))) := by + dsimp only [E] + rw [cavityLabelPartition_eq_product] + rfl + have hc b := cavityLabel_cap_error n d p D hp0 hpm hpD f b hΛ + have hi b : Integrable (fun g=>E (b,g)) countableGaussianLaw := by simpa only [he] using (hc b).1 + have hbound b : (∫ g,E (b,g) ∂countableGaussianLaw)≤ + Real.exp (2*((d:ℝ)*‖f‖))/Λ*Real.exp (2*(n+1:ℕ)*D.2.val) := by simpa only [he] using (hc b).2.2 + have h0 b : ∀ᵐ g ∂countableGaussianLaw,0≤E (b,g) := by + have hL2 := (cavity_residual_square_integrable (indexedLeafProbability k b) countableGaussianLaw + (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) F + (cavityLabelSpherical_measurable n d k σ q) (Real.exp (2*(n+1:ℕ)*D.2.val)) + (fun x=>(cavityLabelSpherical_second n d p D hp0 hpm hpD x).1) + (fun x=>(cavityLabelSpherical_second n d p D hp0 hpm hpD x).2)).1 + filter_upwards [hL2.prod_right_ae] with g hg + have hF : MemLp (fun x=>F (g,x)) 2 + ((indexedLeafProbability k b).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))) := + (memLp_two_iff_integrable_sq ((cavityLabelSpherical_measurable n d k σ q).comp + (measurable_const.prodMk measurable_id)).aestronglyMeasurable).mpr hg + rw [he] + exact (cavity_capped_log_bound _ ((cavityLabelWeight_measurable n d k f σ q).comp + (measurable_const.prodMk measurable_id)) (fun x=>cavityLabelWeight_bound n d k f σ q (g,x)) + hF (fun x=>cavityLabelSpherical_one n d k σ q (g,x)) hΛ).1 + exact integrable_product_of_nonneg_conditional (indexedCascadeBaseLaw k z) countableGaussianLaw E hm _ hi h0 hbound + +lemma cavityLabel_capped_log_integrable (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) (z : Fin k→ℝ) : + Integrable (fun t=>Real.log (cavityLabelPartition n d k f Λ hΛ σ q t)) + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw) := by + apply Integrable.of_bound (cavityLabelPartition_measurable n d k f Λ hΛ σ q).log.aestronglyMeasurable + ‖cavityPartitionLogTest d f Λ‖ + exact ae_of_all _ fun t=>(cavityPartitionLogTest d f Λ).norm_coe_le_norm + ⟨cavityLabelPartition n d k f Λ hΛ σ q t,cavityLabelPartition_mem n d k f Λ hΛ σ q t⟩ + +lemma cavityLabel_full_log_integrable (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (f : ℝ→ᵇℝ) (z : Fin k→ℝ) : + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i) + Integrable (fun t=>Real.log (cavityLabelFullPartition n d k f σ (cavityPairProfile n d p) t)) + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw) := by + have h := (cavityLabel_uncap_annealed n d p D hp0 hpm hpD f z (Λ:=1) le_rfl).1 + have hb := cavityLabel_capped_log_integrable n d k f 1 le_rfl (fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i)) (cavityPairProfile n d p) z + exact (h.add hb).congr (ae_of_all _ fun t=>sub_add_cancel _ _) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityLabelArray.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelArray.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8ea79e407943b472d1154e2bcad325e8fcadffb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelArray.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityLabelPartition + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + + def cavityLabelMarkedArray {K : ℝ} {k : ℕ} (p : Fin (k+1)→BulkPairRange K) + (D : BulkPairRange K) (xs : ℕ→IndexedLeaf k) : CompactArray (BulkPairRange K) := + fun i j=>if i=j then D else p (indexedCommonDepth k (xs j) (xs i)) + +lemma cavityLabelMarkedArray_measurable {K : ℝ} {k : ℕ} (p : Fin (k+1)→BulkPairRange K) + (D : BulkPairRange K) : Measurable (cavityLabelMarkedArray p D) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + unfold cavityLabelMarkedArray + split_ifs + · exact measurable_const + · have hf : Measurable (fun x : IndexedLeaf k×IndexedLeaf k=>p (indexedCommonDepth k x.1 x.2)) := + measurable_of_countable _ + have hg : Measurable (fun xs : ℕ→IndexedLeaf k=>(xs j,xs i)) := + (measurable_pi_apply j).prodMk (measurable_pi_apply i) + exact hf.comp hg + +lemma cavityLabelZero_measurable (k : ℕ) : + Measurable (Function.uncurry (fun _ : IndexedCascadeBase k=>fun _ : IndexedLeaf k=>(0:ℝ))) := + measurable_const + +def cavityLabelMarkedLaw {K : ℝ} {k : ℕ} (p : Fin (k+1)→BulkPairRange K) + (D : BulkPairRange K) (z : Fin k→ℝ) : ProbabilityMeasure (CompactArray (BulkPairRange K)) := by + let μ : Measure (IndexedCascadeBase k×(ℕ→IndexedLeaf k)) := + annealedInfiniteReplicaMeasure (indexedLeafKernel k) + (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) (fun _ _=>0) (cavityLabelZero_measurable k) + have : IsProbabilityMeasure μ := by + have : IsMarkovKernel (gibbsProbabilityKernel (indexedLeafKernel k) (fun _ _=>0)) := + gibbsProbabilityKernel_markov (indexedLeafKernel k) (fun _ _=>0) (cavityLabelZero_measurable k) + dsimp [μ] + unfold annealedInfiniteReplicaMeasure + infer_instance + have hm : Measurable (fun a : IndexedCascadeBase k×(ℕ→IndexedLeaf k)=>cavityLabelMarkedArray p D a.2) := + (cavityLabelMarkedArray_measurable p D).comp measurable_snd + exact ⟨μ.map (fun a=>cavityLabelMarkedArray p D a.2), + (Measure.isProbabilityMeasure_map_iff hm.aemeasurable).2 inferInstance⟩ + +lemma cavityLabelMarkedLaw_block {K : ℝ} {k : ℕ} (p : Fin (k+1)→BulkPairRange K) + (D : BulkPairRange K) (z : Fin k→ℝ) (r : ℕ) (F : CompactBlock (BulkPairRange K) r→ᵇℝ) : + (∫ Q,F (compactBlock r Q) ∂(cavityLabelMarkedLaw p D z : Measure (CompactArray (BulkPairRange K))))= + ∫ b,∫ xs : Fin r→IndexedLeaf k,F (fun i j=>if i=j then D else + p (indexedCommonDepth k (xs j) (xs i))) + ∂Measure.pi (fun _=>indexedLeafProbability k b) ∂indexedCascadeBaseLaw k z := by + let G : (Fin r→IndexedLeaf k)→ℝ:=fun xs=>F (fun i j=>if i=j then D else + p (indexedCommonDepth k (xs j) (xs i))) + have hG : Measurable G:=measurable_of_countable _ + have hGB (xs : Fin r→IndexedLeaf k) : |G xs|≤‖F‖:=F.norm_coe_le_norm _ + have he : ∀ᵐ b ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)), + Integrable (fun _ : IndexedLeaf k=>Real.exp 0) (indexedLeafKernel k b) := + ae_of_all _ fun _=>integrable_const _ + have hh:=annealedInfiniteReplica_gibbs_prefix (indexedLeafKernel k) + (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) (fun _ _=>0) (cavityLabelZero_measurable k) he r hG hGB + change (∫ Q,F (compactBlock r Q) ∂Measure.map + (fun a : IndexedCascadeBase k×(ℕ→IndexedLeaf k)=>cavityLabelMarkedArray p D a.2) + (annealedInfiniteReplicaMeasure (indexedLeafKernel k) + (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) (fun _ _=>0) (cavityLabelZero_measurable k)))=_ + erw [integral_map + ((cavityLabelMarkedArray_measurable p D).comp measurable_snd).aemeasurable + (F.measurable.comp (compactBlock_continuous r).measurable).aestronglyMeasurable] + have hf : (fun a : IndexedCascadeBase k×(ℕ→IndexedLeaf k)=>F (compactBlock r (cavityLabelMarkedArray p D a.2)))= + fun a=>G (fun i=>a.2 i.val) := by + funext a + apply congrArg F + funext i j + simp only [compactBlock,cavityLabelMarkedArray,Fin.val_inj] + change (∫ a : IndexedCascadeBase k×(ℕ→IndexedLeaf k), + F (compactBlock r (cavityLabelMarkedArray p D a.2)) + ∂annealedInfiniteReplicaMeasure (indexedLeafKernel k) + (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) (fun _ _=>0) (cavityLabelZero_measurable k))=_ + rw [hf,hh] + apply integral_congr_ae + exact ae_of_all _ fun b=>by + simp only [gibbsReplicaMean,tiltMean,tiltIntegral,tiltPartition,replicaPotential, + Finset.sum_const_zero,mul_zero,Real.exp_zero,one_mul,integral_const,probReal_univ,one_smul,div_one, + indexedLeafKernel,Kernel.coe_mk] + rfl + +def cavityPairProfile (n d : ℕ) {K : ℝ} {k : ℕ} (p : Fin (k+1)→BulkPairRange K) : + Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ := + fun l=>Sum.elim (fun _=>(p l).2.val) (fun _=>(p l).1.val) + +def cavityPairDiagonal (n d : ℕ) {K : ℝ} (D : BulkPairRange K) : + (Fin (n+1)⊕Fin d)→ℝ := Sum.elim (fun _=>D.2.val) (fun _=>D.1.val) + +lemma cavityPair_block_covariance (n d r : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) (xs : Fin r→IndexedLeaf k) : + (fun i j : CavityReplicaIndex n d r=>if i.1=j.1 then Sum.elim + (fun _=>(if i.2=j.2 then D else p (indexedCommonDepth k (xs j.2) (xs i.2))).2.val) + (fun _=>(if i.2=j.2 then D else p (indexedCommonDepth k (xs j.2) (xs i.2))).1.val) i.1 else 0)= + (fun i j=>if i=j then cavityPairDiagonal n d D i.1 else + if i.1=j.1 then cavityPairProfile n d p (indexedCommonDepth k (xs j.2) (xs i.2)) i.1 else 0) := by + funext i j + by_cases h1 : i.1=j.1 + · by_cases h2 : i.2=j.2 + · have h : i=j:=Prod.ext h1 h2 + simp only [h,ite_true,cavityPairDiagonal] + · have h : i≠j:=fun hh=>h2 (congrArg Prod.snd hh) + simp only [h1,h2,h,ite_false,ite_true,cavityPairProfile] + · have h : i≠j:=fun hh=>h1 (congrArg Prod.fst hh) + simp only [h1,h,ite_false] + +theorem cavityLabelMarkedLaw_cavity_moment (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) (z : Fin k→ℝ) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) (r : ℕ) : + (∫ x,x.val^r ∂(cavityLabelPartitionLaw n d k f Λ hΛ + (fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i)) + (cavityPairProfile n d p) z : Measure (CavityPartitionRange d f Λ)))= + ∫ Q,cavityArrayKernel n d r f Λ hΛ K Q ∂cavityLabelMarkedLaw p D z := by + rw [cavityLabelPartitionLaw_moment n d k f Λ hΛ _ hp0 hpm _ hpD z r] + let F : CompactBlock (BulkPairRange K) r→ᵇℝ := + (cavityMatrixKernel (cavityReplicaTest n d r f Λ hΛ)).compContinuous + ⟨fun Q=>fun i j : CavityReplicaIndex n d r=>if i.1=j.1 then + Sum.elim (fun _=>(Q i.2 j.2).2.val) (fun _=>(Q i.2 j.2).1.val) i.1 else 0,by + apply continuous_pi + intro i + apply continuous_pi + intro j + split_ifs + · cases i.1 <;> dsimp only [Sum.elim] <;> fun_prop + · exact continuous_const⟩ + change _=∫ Q,F (compactBlock r Q) ∂cavityLabelMarkedLaw p D z + rw [cavityLabelMarkedLaw_block] + apply integral_congr_ae + exact ae_of_all _ fun b=>integral_congr_ae (ae_of_all _ fun xs=>by + change _=cavityMatrixKernel (cavityReplicaTest n d r f Λ hΛ) _ + rw [cavitySingleTest_replica] + apply congrArg (cavityMatrixKernel (cavityReplicaTest n d r f Λ hΛ)) + exact (cavityPair_block_covariance n d r p D xs).symm) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityLabelLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..09054d80cf1c495f11540f4b89b6ef7798013293 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelLimit.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityLabelArray + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction + +theorem cavity_joint_array_log_limit (n d : ℕ) (M : ℕ→ℕ) (f : Jet3) (v : ℕ→ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (K : ℝ) (hK : ∀ m,M m/(m+1:ℕ)*‖f.d1‖^2≤K) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray (BulkPairRange K))} + (hbulk : Tendsto (fun j=>bulkMarkedArrayLaw (s j) (M (s j)) f (v (s j)) K (hK (s j))) atTop (𝓝 ν)) + (k : ℕ→ℕ) (p : (j : ℕ)→Fin (k j+1)→BulkPairRange K) + (D : ℕ→BulkPairRange K) (z : (j : ℕ)→Fin (k j)→ℝ) + (hp0 : ∀ j i,0≤cavityPairProfile n d (p j) 0 i) + (hpm : ∀ j i,Monotone (fun l=>cavityPairProfile n d (p j) l i)) + (hpD : ∀ j i,cavityPairProfile n d (p j) (Fin.last (k j)) i≤cavityPairDiagonal n d (D j) i) + (hrpc : Tendsto (fun j=>cavityLabelMarkedLaw (p j) (D j) (z j)) atTop (𝓝 ν)) : + Tendsto (fun j=>cavityBulkLog n d (s j) (M (s j)) f (v (s j)) Λ hΛ- + ∫ x,Real.log x.val ∂(cavityLabelPartitionLaw n d (k j) f.f Λ hΛ + (fun i=>Real.sqrt (cavityPairDiagonal n d (D j) i-cavityPairProfile n d (p j) (Fin.last (k j)) i)) + (cavityPairProfile n d (p j)) (z j) : Measure (CavityPartitionRange d f.f Λ))) atTop (𝓝 0) := by + obtain ⟨η,_hη,hm,hlog⟩:=cavityBulkLog_tendsto n d M f v Λ hΛ K hK s hbulk + let ρ : ℕ→ProbabilityMeasure (CavityPartitionRange d f.f Λ):=fun j=> + cavityLabelPartitionLaw n d (k j) f.f Λ hΛ + (fun i=>Real.sqrt (cavityPairDiagonal n d (D j) i-cavityPairProfile n d (p j) (Fin.last (k j)) i)) + (cavityPairProfile n d (p j)) (z j) + have hr : Tendsto ρ atTop (𝓝 η) := by + apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr + intro F + apply integral_continuous_tendsto_of_moments (fun j=>(ρ j : Measure (CavityPartitionRange d f.f Λ))) + (η : Measure (CavityPartitionRange d f.f Λ)) (fun r=>?_) F.toContinuousMap + rw [hm r] + have ht:=cavityArrayKernel_tendsto n d r f.f Λ hΛ K hrpc + have he j : (∫ x,x.val^r ∂(ρ j : Measure (CavityPartitionRange d f.f Λ)))= + ∫ Q,cavityArrayKernel n d r f.f Λ hΛ K Q ∂cavityLabelMarkedLaw (p j) (D j) (z j) := + cavityLabelMarkedLaw_cavity_moment n d (p j) (D j) (z j) (hp0 j) (hpm j) (hpD j) f.f Λ hΛ r + simp_rw [he] + exact ht + have hl := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (cavityPartitionLogTest d f.f Λ)).continuousAt.tendsto.comp hr + have hd:=hlog.sub hl + simpa only [Function.comp_def,cavityPartitionLogTest,BoundedContinuousFunction.mkOfCompact_apply, + ContinuousMap.coe_mk,sub_self,ρ] using hd + +theorem cavity_joint_array_recursion_limit (n d : ℕ) (M : ℕ→ℕ) (f : Jet3) (v : ℕ→ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (K : ℝ) (hK : ∀ m,M m/(m+1:ℕ)*‖f.d1‖^2≤K) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray (BulkPairRange K))} + (hbulk : Tendsto (fun j=>bulkMarkedArrayLaw (s j) (M (s j)) f (v (s j)) K (hK (s j))) atTop (𝓝 ν)) + (k : ℕ→ℕ) (p : (j : ℕ)→Fin (k j+1)→BulkPairRange K) + (D : ℕ→BulkPairRange K) (z : (j : ℕ)→Fin (k j)→ℝ) + (hp0 : ∀ j i,0≤cavityPairProfile n d (p j) 0 i) + (hpm : ∀ j i,Monotone (fun l=>cavityPairProfile n d (p j) l i)) + (hpD : ∀ j i,cavityPairProfile n d (p j) (Fin.last (k j)) i≤cavityPairDiagonal n d (D j) i) + (hz : ∀ j,StrictMono (z j)) (hz0 : ∀ j i,0cavityLabelMarkedLaw (p j) (D j) (z j)) atTop (𝓝 ν)) : + Tendsto (fun j=>cavityBulkLog n d (s j) (M (s j)) f (v (s j)) Λ hΛ- + ∫ y,finiteCascadeLogRecursion (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + (gaussianLinearMarkStep (fun l=>diagonalMark (profileGaussianStep (cavityPairProfile n d (p j)) l))) (k j) (z j) + (fun t=>Real.log (cavityDiagonalAverage + (fun i=>Real.sqrt (cavityPairDiagonal n d (D j) i-cavityPairProfile n d (p j) (Fin.last (k j)) i)) + (cavitySingleTest n d f.f Λ hΛ) (t 0))) + (fun _=>diagonalMark (profileGaussianRoot (cavityPairProfile n d (p j))) y) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) atTop (𝓝 0) := by + have ht:=cavity_joint_array_log_limit n d M f v Λ hΛ K hK s hbulk k p D z hp0 hpm hpD hrpc + simpa only [cavityLabelPartitionLaw_log_recursion n d _ f.f Λ hΛ _ _ _ (hz _) (hz0 _) (hz1 _)] using ht + +lemma cavity_expected_cap_ae {S G : Type*} [MeasurableSpace S] [MeasurableSpace G] + (μ : Measure S) (P : Measure G) [IsProbabilityMeasure μ] [IsProbabilityMeasure P] + (W F : G×S→ℝ) (hW : Measurable W) (hF : Measurable F) {C Λ K : ℝ} + (hWC : ∀ p,|W p|≤C) (hF1 : ∀ p,1≤F p) (hΛ : 1≤Λ) + (hFg : ∀ x,MemLp (fun g=>F (g,x)) 2 P) + (h2 : ∀ x,(∫ g,F (g,x)^2 ∂P)≤K) : + let D:=fun g=>Real.log (∫ x,Real.exp (W (g,x))*F (g,x) ∂μ)- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ ∂μ) + Integrable D P ∧ 0≤∫ g,D g ∂P ∧ + (∫ g,D g ∂P)≤Real.exp (2*C)/Λ*K := by + let Q : S×G→ℝ := fun p=>F (p.2,p.1)^2 + have hQ : Measurable Q := (hF.comp measurable_swap).pow_const 2 + have hi : Integrable Q (μ.prod P) := by + apply (integrable_prod_iff hQ.aestronglyMeasurable).mpr + constructor + · exact ae_of_all _ fun x=>(memLp_two_iff_integrable_sq (hFg x).aestronglyMeasurable).mp (hFg x) + · apply Integrable.of_bound (hQ.norm.stronglyMeasurable.integral_prod_right).aestronglyMeasurable K + filter_upwards [] with x + have he : (∫ g,‖Q (x,g)‖ ∂P)=(∫ g,F (g,x)^2 ∂P) := by + simp only [Q,Real.norm_eq_abs,abs_sq] + rw [he,Real.norm_eq_abs,abs_of_nonneg (integral_nonneg fun g=>sq_nonneg _)] + exact h2 x + have hS : Integrable (fun g=>∫ x,F (g,x)^2 ∂μ) P := hi.integral_prod_right + have hB : (∫ g,∫ x,F (g,x)^2 ∂μ ∂P)≤K := by + rw [←integral_integral_swap hi] + calc + _≤∫ _ : S,K ∂μ := integral_mono hi.integral_prod_left (integrable_const _) h2 + _=K := by simp + let D:=fun g=>Real.log (∫ x,Real.exp (W (g,x))*F (g,x) ∂μ)- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ ∂μ) + have hD : Measurable D := by + exact ((hW.exp.mul hF).stronglyMeasurable.integral_prod_right.measurable.log).sub + ((hW.exp.mul (hF.min measurable_const)).stronglyMeasurable.integral_prod_right.measurable.log) + have hFx : ∀ᵐ g ∂P,MemLp (fun x=>F (g,x)) 2 μ := by + filter_upwards [hi.prod_left_ae] with g hg + apply (memLp_two_iff_integrable_sq + ((hF.comp (measurable_const.prodMk measurable_id)).aestronglyMeasurable)).mpr + exact hg + have hp : ∀ᵐ g ∂P,0≤D g ∧ D g≤Real.exp (2*C)/Λ*(∫ x,F (g,x)^2 ∂μ) := by + filter_upwards [hFx] with g hg + exact cavity_capped_log_bound μ (hW.comp (measurable_const.prodMk measurable_id)) + (fun x=>hWC (g,x)) hg (fun x=>hF1 (g,x)) hΛ + have hc : 0≤Real.exp (2*C)/Λ := div_nonneg (Real.exp_pos _).le ((by norm_num : (0:ℝ)≤1).trans hΛ) + have hDi : Integrable D P := by + apply (hS.const_mul (Real.exp (2*C)/Λ)).mono' hD.aestronglyMeasurable + filter_upwards [hp] with g hg + simpa only [Real.norm_eq_abs,abs_of_nonneg hg.1] using hg.2 + refine ⟨hDi,integral_nonneg_of_ae (hp.mono fun _point hg=>hg.1),?_⟩ + calc + _≤∫ g,Real.exp (2*C)/Λ*(∫ x,F (g,x)^2 ∂μ) ∂P := + integral_mono_ae hDi (hS.const_mul _) (hp.mono fun _point hg=>hg.2) + _=Real.exp (2*C)/Λ*(∫ g,∫ x,F (g,x)^2 ∂μ ∂P) := integral_const_mul _ _ + _≤_ := mul_le_mul_of_nonneg_left hB hc + +lemma cavity_expected_cap_integrated {S G : Type*} [MeasurableSpace S] [MeasurableSpace G] + (μ : Measure S) (P : Measure G) [IsProbabilityMeasure μ] [IsProbabilityMeasure P] + (W F : G×S→ℝ) (hW : Measurable W) (hF : Measurable F) {C Λ K : ℝ} + (hWC : ∀ p,|W p|≤C) (hF1 : ∀ p,1≤F p) (hΛ : 1≤Λ) + (hF2 : Integrable (fun p : G×S=>F p^2) (P.prod μ)) + (h2 : (∫ g,∫ x,F (g,x)^2 ∂μ ∂P)≤K) : + let D:=fun g=>Real.log (∫ x,Real.exp (W (g,x))*F (g,x) ∂μ)- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ ∂μ) + Integrable D P ∧ 0≤∫ g,D g ∂P ∧ + (∫ g,D g ∂P)≤Real.exp (2*C)/Λ*K := by + have hS : Integrable (fun g=>∫ x,F (g,x)^2 ∂μ) P := hF2.integral_prod_left + let D:=fun g=>Real.log (∫ x,Real.exp (W (g,x))*F (g,x) ∂μ)- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ ∂μ) + have hD : Measurable D := by + exact ((hW.exp.mul hF).stronglyMeasurable.integral_prod_right.measurable.log).sub + ((hW.exp.mul (hF.min measurable_const)).stronglyMeasurable.integral_prod_right.measurable.log) + have hFx : ∀ᵐ g ∂P,MemLp (fun x=>F (g,x)) 2 μ := by + filter_upwards [hF2.prod_right_ae] with g hg + exact (memLp_two_iff_integrable_sq + ((hF.comp (measurable_const.prodMk measurable_id)).aestronglyMeasurable)).mpr hg + have hp : ∀ᵐ g ∂P,0≤D g ∧ D g≤Real.exp (2*C)/Λ*(∫ x,F (g,x)^2 ∂μ) := by + filter_upwards [hFx] with g hg + exact cavity_capped_log_bound μ (hW.comp (measurable_const.prodMk measurable_id)) + (fun x=>hWC (g,x)) hg (fun x=>hF1 (g,x)) hΛ + have hc : 0≤Real.exp (2*C)/Λ := div_nonneg (Real.exp_pos _).le ((by norm_num : (0:ℝ)≤1).trans hΛ) + have hDi : Integrable D P := by + apply (hS.const_mul (Real.exp (2*C)/Λ)).mono' hD.aestronglyMeasurable + filter_upwards [hp] with g hg + simpa only [Real.norm_eq_abs,abs_of_nonneg hg.1] using hg.2 + refine ⟨hDi,integral_nonneg_of_ae (hp.mono fun _point hg=>hg.1),?_⟩ + calc + _≤∫ g,Real.exp (2*C)/Λ*(∫ x,F (g,x)^2 ∂μ) ∂P := + integral_mono_ae hDi (hS.const_mul _) (hp.mono fun _point hg=>hg.2) + _=Real.exp (2*C)/Λ*(∫ g,∫ x,F (g,x)^2 ∂μ ∂P) := integral_const_mul _ _ + _≤_ := mul_le_mul_of_nonneg_left h2 hc + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityLabelMoment.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..912993f663720a8de9b9e5fd661dc9d6c30c830d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelMoment.lean @@ -0,0 +1,120 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityDiagonalKernel + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy + +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction + +variable {J : Type} [Fintype J] [DecidableEq J] [MeasurableSpace J] + [MeasurableSingletonClass J] {k : ℕ} + +def cavityLabelBasis (j : J) : EuclideanSpace ℝ J := + WithLp.toLp 2 (fun i=>if i=j then (1:ℝ) else 0) + +def cavityLabelRow (q : Fin (k+1)→J→ℝ) (i : ℕ) (x : IndexedLeaf k×J) : ℝ := + indexedGaussianRow k (hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q)) + cavityLabelBasis i (x.2,x.1) + +def cavityLabelLength (k : ℕ) (x : IndexedLeaf k×J) : ℕ := + indexedGaussianRowLength (I:=J) k (x.2,x.1) + +lemma cavityLabelRow_measurable (q : Fin (k+1)→J→ℝ) (i : ℕ) : + Measurable (cavityLabelRow q i) := + (indexedGaussianRow_measurable k _ (measurable_of_countable cavityLabelBasis) i).comp + (measurable_snd.prodMk measurable_fst) + +omit [Fintype J] [DecidableEq J] [MeasurableSpace J] [MeasurableSingletonClass J] in +lemma cavityLabelLength_measurable [Fintype J] [DecidableEq J] [MeasurableSpace J] + [MeasurableSingletonClass J] (k : ℕ) : Measurable (cavityLabelLength (J:=J) k) := + (indexedGaussianRowLength_measurable k).comp (measurable_snd.prodMk measurable_fst) + +omit [MeasurableSingletonClass J] in +lemma cavityLabel_covariance [MeasurableSingletonClass J] (q : Fin (k+1)→J→ℝ) (h0 : ∀ i,0≤q 0 i) + (hq : ∀ i,Monotone (fun l=>q l i)) (x y : IndexedLeaf k×J) : + countableGaussianCovariance (cavityLabelRow q) (cavityLabelRow q) (cavityLabelLength k) x y= + if x.2=y.2 then q (indexedCommonDepth k y.1 x.1) x.2 else 0 := by + change countableGaussianCovariance + (indexedGaussianRow k (hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q)) cavityLabelBasis) + (indexedGaussianRow k (hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q)) cavityLabelBasis) + (indexedGaussianRowLength (I:=J) k) (x.2,x.1) (y.2,y.1)=_ + rw [profileGaussianRow_covariance q h0 hq] + simp only [cavityLabelBasis,PiLp.toLp_apply,mul_ite,mul_one,mul_zero, + Finset.sum_ite_eq',Finset.mem_univ,ite_true] + by_cases h : x.2=y.2 + · simp [h] + · simp [h,Ne.symm h] + +theorem cavity_label_moment (q : Fin (k+1)→J→ℝ) (h0 : ∀ i,0≤q 0 i) + (hq : ∀ i,Monotone (fun l=>q l i)) + (μ : Measure (IndexedLeaf k)) [IsProbabilityMeasure μ] + (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) : + (∫ g,(∫ x,Ψ (cavityCountableField (cavityLabelRow q) (cavityLabelLength k) g x) ∂μ)^r + ∂countableGaussianLaw)= + ∫ xs : Fin r→IndexedLeaf k,cavityMatrixKernel (cavityTestReplica Ψ r) + (fun i j : J×Fin r=>if i.1=j.1 then q (indexedCommonDepth k (xs j.2) (xs i.2)) i.1 else 0) + ∂Measure.pi (fun _=>μ) := by + simpa only [cavityLabel_covariance q h0 hq] using + cavity_countable_moment μ (cavityLabelRow q) (cavityLabelLength k) + (cavityLabelRow_measurable q) (cavityLabelLength_measurable k) Ψ r + + +lemma cavity_label_completed_covariance (q : Fin (k+1)→J→ℝ) + (h0 : ∀ i,0≤q 0 i) (hq : ∀ i,Monotone (fun l=>q l i)) + (D : J→ℝ) (hD : ∀ i,q (Fin.last k) i≤D i) + (r : ℕ) (xs : Fin r→IndexedLeaf k) (p t : J×Fin r) : + countableGaussianCovariance (cavityLabelRow q) (cavityLabelRow q) (cavityLabelLength k) + (xs p.2,p.1) (xs t.2,t.1)+ + (if p=t then (Real.sqrt (D p.1-q (Fin.last k) p.1))^2 else 0)= + if p=t then D p.1 else + if p.1=t.1 then q (indexedCommonDepth k (xs t.2) (xs p.2)) p.1 else 0 := by + rw [cavityLabel_covariance q h0 hq] + by_cases h : p=t + · subst t + simp only [ite_true,indexedCommonDepth_self,Real.sq_sqrt (sub_nonneg.mpr (hD _))] + ring + · simp only [ite_eq_right h,add_zero] + +theorem cavity_label_true_diagonal_moment (q : Fin (k+1)→J→ℝ) + (h0 : ∀ i,0≤q 0 i) (hq : ∀ i,Monotone (fun l=>q l i)) + (D : J→ℝ) (hD : ∀ i,q (Fin.last k) i≤D i) + (μ : Measure (IndexedLeaf k)) [IsProbabilityMeasure μ] + (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) : + (∫ g,(∫ x,cavityDiagonalAverage (fun j=>Real.sqrt (D j-q (Fin.last k) j)) Ψ + (cavityCountableField (cavityLabelRow q) (cavityLabelLength k) g x) ∂μ)^r + ∂countableGaussianLaw)= + ∫ xs : Fin r→IndexedLeaf k,cavityMatrixKernel (cavityTestReplica Ψ r) + (fun p t : J×Fin r=>if p=t then D p.1 else + if p.1=t.1 then q (indexedCommonDepth k (xs t.2) (xs p.2)) p.1 else 0) + ∂Measure.pi (fun _=>μ) := by + simpa only [cavity_label_completed_covariance q h0 hq D hD r] using + cavity_countable_residual_moment μ (cavityLabelRow q) (cavityLabelLength k) + (cavityLabelRow_measurable q) (cavityLabelLength_measurable k) + (fun j=>Real.sqrt (D j-q (Fin.last k) j)) Ψ r + + +omit [MeasurableSpace J] [MeasurableSingletonClass J] in +lemma cavityLabelBasis_inner [MeasurableSpace J] [MeasurableSingletonClass J] + (j : J) (x : EuclideanSpace ℝ J) : + inner ℝ (cavityLabelBasis j) x=x j := by + simp [cavityLabelBasis,PiLp.inner_apply] + +lemma cavity_label_field_state (q : Fin (k+1)→J→ℝ) (g : ℕ→ℝ) (x : IndexedLeaf k) : + cavityCountableField (cavityLabelRow q) (cavityLabelLength k) g x= + indexedLeafState (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j))) k + ((fun _=>diagonalMark (profileGaussianRoot q) (indexedGaussianDisorder k J g).1), + (indexedGaussianDisorder k J g).2) x 0 := by + ext j + change countableGaussianField (indexedGaussianRow k + (hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q)) cavityLabelBasis) + (indexedGaussianRowLength (I:=J) k) g (j,x)=_ + rw [indexedGaussianRow_diagonal_identity,cavityLabelBasis_inner] + + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityLabelPartition.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..c7a68827fc6fa96ea14516b78c628ee6fbdf3907 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityLabelPartition.lean @@ -0,0 +1,208 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityLabelMoment +import OAI.Probability.Perceptron.Cascade.CavityCappedRPC + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +instance cavityIndexMeasurableSingleton (n d : ℕ) : MeasurableSingletonClass (Fin (n+1)⊕Fin d) where + measurableSet_singleton x := by + cases x with + | inl x => simpa only [Set.image_singleton] using (measurableSet_singleton x).inl_image (β:=Fin d) + | inr x => simpa only [Set.image_singleton] using (measurableSet_singleton x).inr_image (α:=Fin (n+1)) + +def cavityLabelPartition (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (p : IndexedCascadeBase k×(ℕ→ℝ)) : ℝ := + ∫ l,cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) + (cavityCountableField (cavityLabelRow q) (cavityLabelLength k) p.2 l) + ∂indexedLeafProbability k p.1 + +lemma cavityLabelPartition_measurable (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) : + Measurable (cavityLabelPartition n d k f Λ hΛ σ q) := by + let κ : Kernel (IndexedCascadeBase k×(ℕ→ℝ)) (IndexedLeaf k):= + (indexedLeafKernel k).comap Prod.fst measurable_fst + have hf : Measurable (fun p : (ℕ→ℝ)×IndexedLeaf k=> + cavityCountableField (cavityLabelRow q) (cavityLabelLength k) p.1 p.2) := + cavityCountableField_measurable (cavityLabelRow q) (cavityLabelLength k) + (cavityLabelRow_measurable q) (cavityLabelLength_measurable k) + have hp : Measurable (fun p : (IndexedCascadeBase k×(ℕ→ℝ))×IndexedLeaf k=>(p.1.2,p.2)) := + measurable_fst.snd.prodMk measurable_snd + have hg:=hf.comp hp + have hm : Measurable (fun p : (IndexedCascadeBase k×(ℕ→ℝ))×IndexedLeaf k=> + cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) + (cavityCountableField (cavityLabelRow q) (cavityLabelLength k) p.1.2 p.2)) := + (cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ)).measurable.comp hg + exact (hm.stronglyMeasurable.integral_kernel_prod_right (κ:=κ) + (f:=fun p l=>cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) + (cavityCountableField (cavityLabelRow q) (cavityLabelLength k) p.2 l))).measurable + +lemma cavityLabelPartition_mem (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (p : IndexedCascadeBase k×(ℕ→ℝ)) : + cavityLabelPartition n d k f Λ hΛ σ q p∈CavityPartitionRange d f Λ := by + let Ψ:=cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) + have hm : Measurable (fun l=>Ψ (cavityCountableField (cavityLabelRow q) (cavityLabelLength k) p.2 l)) := + measurable_of_countable _ + have hi : Integrable (fun l=>Ψ (cavityCountableField (cavityLabelRow q) (cavityLabelLength k) p.2 l)) + (indexedLeafProbability k p.1) := + Integrable.of_bound hm.aestronglyMeasurable ‖Ψ‖ (ae_of_all _ fun l=>Ψ.norm_coe_le_norm _) + unfold cavityLabelPartition + constructor + · simpa only [integral_const,probReal_univ,one_smul] using + integral_mono (integrable_const (Real.exp (-(d:ℝ)*‖f‖))) hi + (fun l=>(cavityResidualCapped_bounds n d f Λ hΛ σ _).1) + · simpa only [integral_const,probReal_univ,one_smul] using + integral_mono hi (integrable_const (Λ*Real.exp ((d:ℝ)*‖f‖))) + (fun l=>(cavityResidualCapped_bounds n d f Λ hΛ σ _).2) + +def cavityLabelPartitionLaw (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) (z : Fin k→ℝ) : + ProbabilityMeasure (CavityPartitionRange d f Λ) := + ⟨((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw).map + (fun p=>⟨cavityLabelPartition n d k f Λ hΛ σ q p,cavityLabelPartition_mem n d k f Λ hΛ σ q p⟩), + inferInstance⟩ + +lemma cavityLabelPartitionLaw_integral (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) (z : Fin k→ℝ) + (F : ℝ→ℝ) (hF : Measurable F) : + (∫ x,F x.val ∂(cavityLabelPartitionLaw n d k f Λ hΛ σ q z : Measure (CavityPartitionRange d f Λ)))= + ∫ p,F (cavityLabelPartition n d k f Λ hΛ σ q p) + ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw := by + exact integral_map ((cavityLabelPartition_measurable n d k f Λ hΛ σ q).subtype_mk).aemeasurable + (hF.comp measurable_subtype_coe).aestronglyMeasurable + +theorem cavityLabelPartitionLaw_moment (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (h0 : ∀ i,0≤q 0 i) (hq : ∀ i,Monotone (fun l=>q l i)) + (D : Fin (n+1)⊕Fin d→ℝ) (hD : ∀ i,q (Fin.last k) i≤D i) (z : Fin k→ℝ) (r : ℕ) : + (∫ x,x.val^r ∂(cavityLabelPartitionLaw n d k f Λ hΛ + (fun j=>Real.sqrt (D j-q (Fin.last k) j)) q z : Measure (CavityPartitionRange d f Λ)))= + ∫ b,∫ xs : Fin r→IndexedLeaf k,cavityMatrixKernel (cavityTestReplica (cavitySingleTest n d f Λ hΛ) r) + (fun p t : (Fin (n+1)⊕Fin d)×Fin r=>if p=t then D p.1 else + if p.1=t.1 then q (indexedCommonDepth k (xs t.2) (xs p.2)) p.1 else 0) + ∂Measure.pi (fun _=>indexedLeafProbability k b) ∂indexedCascadeBaseLaw k z := by + let σ:=fun j=>Real.sqrt (D j-q (Fin.last k) j) + let P:=cavityLabelPartition n d k f Λ hΛ σ q + have hb (p : IndexedCascadeBase k×(ℕ→ℝ)) : ‖P p‖≤Λ*Real.exp ((d:ℝ)*‖f‖) := by + have hh:=cavityLabelPartition_mem n d k f Λ hΛ σ q p + rw [Real.norm_eq_abs,abs_of_pos ((Real.exp_pos _).trans_le hh.1)] + exact hh.2 + have hi : Integrable (fun p=>P p^r) ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw) := + Integrable.of_bound ((cavityLabelPartition_measurable n d k f Λ hΛ σ q).pow_const r).aestronglyMeasurable + ((Λ*Real.exp ((d:ℝ)*‖f‖))^r) (ae_of_all _ fun p=>by + rw [norm_pow] + exact pow_le_pow_left₀ (norm_nonneg _) (hb p) r) + rw [cavityLabelPartitionLaw_integral _ _ _ _ _ _ _ _ _ (fun x : ℝ=>x^r) (by fun_prop),integral_prod _ hi] + apply integral_congr_ae + exact ae_of_all _ fun b=>cavity_label_true_diagonal_moment q h0 hq D hD + (indexedLeafProbability k b) (cavitySingleTest n d f Λ hΛ) r + + +def cavityIndexedRootPartition (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (p : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)× + (IndexedCascadeBase k×IndexedCascadeMarks (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) k)) : ℝ := + ∫ l,cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) + (indexedLeafState (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j))) k + ((fun _=>diagonalMark (profileGaussianRoot q) p.1),p.2.2) l 0) + ∂indexedLeafProbability k p.2.1 + +lemma cavityIndexedRootPartition_measurable (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) : + Measurable (cavityIndexedRootPartition n d k f Λ hΛ σ q) := by + let E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d) + let X:=E×(IndexedCascadeBase k×IndexedCascadeMarks E k) + let κ : Kernel X (IndexedLeaf k):=(indexedLeafKernel k).comap (fun p=>p.2.1) measurable_snd.fst + have hm0 : Measurable (fun p : X×IndexedLeaf k=> + indexedLeafState (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j))) k + ((fun _=>diagonalMark (profileGaussianRoot q) p.1.1),p.1.2.2) p.2) := by + have hs := indexedLeafState_measurable + (gaussianLinearMarkStep_measurable (fun j=>diagonalMark (profileGaussianStep q j))) k + have hp : Measurable (fun p : X×IndexedLeaf k=> + (((fun _ : ℕ=>diagonalMark (profileGaussianRoot q) p.1.1),p.1.2.2),p.2)) := by + have hr : Measurable (fun p : X×IndexedLeaf k=> + (fun _ : ℕ=>diagonalMark (profileGaussianRoot q) p.1.1)) := + Measurable.of_eval fun _=> + (diagonalMark (profileGaussianRoot q)).measurable.comp measurable_fst.fst + exact (hr.prodMk measurable_fst.snd.snd).prodMk measurable_snd + exact hs.comp hp + have hm : Measurable (fun p : X×IndexedLeaf k=> + cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) + (indexedLeafState (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j))) k + ((fun _=>diagonalMark (profileGaussianRoot q) p.1.1),p.1.2.2) p.2 0)) := + (cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ)).measurable.comp + ((measurable_pi_apply 0).comp hm0) + exact (hm.stronglyMeasurable.integral_kernel_prod_right (κ:=κ) + (f:=fun p l=>cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) + (indexedLeafState (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j))) k + ((fun _=>diagonalMark (profileGaussianRoot q) p.1),p.2.2) l 0))).measurable + +lemma cavityIndexedRootPartition_log_bound (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (p : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)× + (IndexedCascadeBase k×IndexedCascadeMarks (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) k)) : + |Real.log (cavityIndexedRootPartition n d k f Λ hΛ σ q p)|≤Real.log Λ+d*‖f‖ := by + let V : IndexedLeaf k→_:=fun l=>indexedLeafState + (gaussianLinearMarkStep (fun j=>diagonalMark (profileGaussianStep q j))) k + ((fun _=>diagonalMark (profileGaussianRoot q) p.1),p.2.2) l 0 + have hh:=tilt_log_partition_bound (indexedLeafProbability k p.2.1) + (H:=fun l=>Real.log (cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) (V l))) + (measurable_of_countable _) (add_nonneg (Real.log_nonneg hΛ) (by positivity)) + (fun l=>cavityResidualCapped_log_bound n d f Λ hΛ σ (V l)) + simpa only [tiltPartition,one_mul,Real.exp_log (cavityResidualCapped_pos n d f Λ hΛ σ _), + cavityIndexedRootPartition,V] using hh + +lemma cavityIndexedRoot_disorder_preserving (k : ℕ) (J : Type) [Fintype J] (z : Fin k→ℝ) : + MeasurePreserving + (fun p : IndexedCascadeBase k×(ℕ→ℝ)=> + ((indexedGaussianDisorder k J p.2).1,(p.1,(indexedGaussianDisorder k J p.2).2))) + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw) + ((stdGaussian (EuclideanSpace ℝ J)).prod + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) k))) := by + have hg : MeasurePreserving (indexedGaussianDisorder k J) countableGaussianLaw + ((stdGaussian (EuclideanSpace ℝ J)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) k)) := + ⟨indexedGaussianDisorder_measurable k J,indexedGaussianDisorder_law k J⟩ + exact (freshRoot_swap_nested _ _ _).comp ((MeasurePreserving.id _).prod hg) + +theorem cavityLabelPartitionLaw_log_recursion (n d k : ℕ) (f : ℝ→ᵇℝ) (Λ : ℝ) (hΛ : 1≤Λ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0diagonalMark (profileGaussianStep q j))) k z + (fun s=>Real.log (cavityDiagonalAverage σ (cavitySingleTest n d f Λ hΛ) (s 0))) + (fun _=>diagonalMark (profileGaussianRoot q) y) ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) := by + let F:=fun p=>Real.log (cavityIndexedRootPartition n d k f Λ hΛ σ q p) + have hm : Measurable F := (cavityIndexedRootPartition_measurable n d k f Λ hΛ σ q).log + have hp:=cavityIndexedRoot_disorder_preserving k (Fin (n+1)⊕Fin d) z + have hi : Integrable F ((stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))).prod + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) k))) := + Integrable.of_bound hm.aestronglyMeasurable (Real.log Λ+d*‖f‖) (ae_of_all _ fun p=>by + simpa only [Real.norm_eq_abs] using cavityIndexedRootPartition_log_bound n d k f Λ hΛ σ q p) + rw [cavityLabelPartitionLaw_integral _ _ _ _ _ _ _ _ _ Real.log Real.measurable_log] + have he (p : IndexedCascadeBase k×(ℕ→ℝ)) : + Real.log (cavityLabelPartition n d k f Λ hΛ σ q p)= + F ((indexedGaussianDisorder k (Fin (n+1)⊕Fin d) p.2).1, + (p.1,(indexedGaussianDisorder k (Fin (n+1)⊕Fin d) p.2).2)) := by + unfold cavityLabelPartition F cavityIndexedRootPartition + simp_rw [cavity_label_field_state] + simp_rw [he] + rw [←integral_map hp.measurable.aemeasurable hm.aestronglyMeasurable,hp.map_eq,integral_prod _ hi] + apply integral_congr_ae + exact ae_of_all _ fun y=>cavity_capped_indexed_log_recursion n d k f Λ hΛ σ + (fun j=>diagonalMark (profileGaussianStep q j)) z hz hz0 hz1 + (fun _=>diagonalMark (profileGaussianRoot q) y) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityMeanCap.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityMeanCap.lean new file mode 100644 index 0000000000000000000000000000000000000000..71328e5874403a954039342c428474b97c91748a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityMeanCap.lean @@ -0,0 +1,179 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityCompensator +import OAI.Probability.Perceptron.Cavity.CavityShellExpansion + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction + +lemma cavity_expected_cap {S G : Type*} [MeasurableSpace S] [MeasurableSpace G] + (μ : Measure S) (P : Measure G) [IsProbabilityMeasure μ] [IsProbabilityMeasure P] + (W F : G×S→ℝ) (hW : Measurable W) (hF : Measurable F) {C Λ K : ℝ} + (hWC : ∀ p,|W p|≤C) (hF1 : ∀ p,1≤F p) (hΛ : 1≤Λ) + (hFx : ∀ g,MemLp (fun x=>F (g,x)) 2 μ) + (hFg : ∀ x,MemLp (fun g=>F (g,x)) 2 P) + (h2 : ∀ x,(∫ g,F (g,x)^2 ∂P)≤K) : + let D:=fun g=>Real.log (∫ x,Real.exp (W (g,x))*F (g,x) ∂μ)- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ ∂μ) + Integrable D P ∧ 0≤∫ g,D g ∂P ∧ + (∫ g,D g ∂P)≤Real.exp (2*C)/Λ*K := by + let Q : S×G→ℝ := fun p=>F (p.2,p.1)^2 + have hQ : Measurable Q := (hF.comp measurable_swap).pow_const 2 + have hi : Integrable Q (μ.prod P) := by + apply (integrable_prod_iff hQ.aestronglyMeasurable).mpr + constructor + · exact ae_of_all _ fun x=>(memLp_two_iff_integrable_sq (hFg x).aestronglyMeasurable).mp (hFg x) + · apply Integrable.of_bound (hQ.norm.stronglyMeasurable.integral_prod_right).aestronglyMeasurable K + filter_upwards [] with x + have he : (∫ g,‖Q (x,g)‖ ∂P)=(∫ g,F (g,x)^2 ∂P) := by + simp only [Q,Real.norm_eq_abs,abs_sq] + rw [he,Real.norm_eq_abs,abs_of_nonneg (integral_nonneg fun g=>sq_nonneg _)] + exact h2 x + have hS : Integrable (fun g=>∫ x,F (g,x)^2 ∂μ) P := hi.integral_prod_right + have hB : (∫ g,∫ x,F (g,x)^2 ∂μ ∂P)≤K := by + rw [←integral_integral_swap hi] + calc + _≤∫ _ : S,K ∂μ := integral_mono hi.integral_prod_left (integrable_const _) h2 + _=K := by simp + let D:=fun g=>Real.log (∫ x,Real.exp (W (g,x))*F (g,x) ∂μ)- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ ∂μ) + have hD : Measurable D := by + exact ((hW.exp.mul hF).stronglyMeasurable.integral_prod_right.measurable.log).sub + ((hW.exp.mul (hF.min measurable_const)).stronglyMeasurable.integral_prod_right.measurable.log) + have hp g : 0≤D g ∧ D g≤Real.exp (2*C)/Λ*(∫ x,F (g,x)^2 ∂μ) := + cavity_capped_log_bound μ (hW.comp (measurable_const.prodMk measurable_id)) (fun x=>hWC (g,x)) (hFx g) (fun x=>hF1 (g,x)) hΛ + have hc : 0≤Real.exp (2*C)/Λ := div_nonneg (Real.exp_pos _).le ((by norm_num : (0:ℝ)≤1).trans hΛ) + have hDi : Integrable D P := by + apply (hS.const_mul (Real.exp (2*C)/Λ)).mono' hD.aestronglyMeasurable + exact ae_of_all _ fun g=>by simpa only [Real.norm_eq_abs,abs_of_nonneg (hp g).1] using (hp g).2 + refine ⟨hDi,integral_nonneg (fun g=>(hp g).1),?_⟩ + calc + _≤∫ g,Real.exp (2*C)/Λ*(∫ x,F (g,x)^2 ∂μ) ∂P := + integral_mono hDi (hS.const_mul _) (fun g=>(hp g).2) + _=Real.exp (2*C)/Λ*(∫ g,∫ x,F (g,x)^2 ∂μ ∂P) := integral_const_mul _ _ + _≤_ := mul_le_mul_of_nonneg_left hB hc + +lemma cavity_rows_joint_continuous {A J E : Type*} [TopologicalSpace A] + [Fintype J] [DecidableEq J] [NormedAddCommGroup E] [InnerProductSpace ℝ E] + {v : A→J→E} {y : A→E} (hv : Continuous v) (hy : Continuous y) : + Continuous (fun a=>gaussianRows (v a) (y a)) := by + change Continuous (fun a=>WithLp.toLp 2 (fun i=>inner ℝ (v a i) (y a))) + apply (PiLp.continuous_toLp 2 _).comp + exact continuous_pi fun i=>((continuous_apply i).comp hv).inner hy + +lemma cavityBulkFeature_continuous (n d m M : ℕ) (f : Jet3) (a : BulkDisorder (m+1) M) : + Continuous (cavityBulkFeature n d m M f a) := by + apply continuous_pi + intro j + unfold cavityBulkFeature + apply (PiLp.continuous_toLp 2 _).comp + apply continuous_pi + intro p + split_ifs + · cases j <;> cases p.2 <;> dsimp [cavityBulkBase] <;> fun_prop + · exact continuous_const + +def cavityBulkFullCompPartition (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (p : BulkDisorder (m+1) M×EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : ℝ := + tiltMean (unitSphereLaw (m+1)) (bulkGibbsHamiltonian m M f.f v p.1) + (fun x=>Real.exp ((n+1:ℕ)/2*bulkC (m+1) M f p.1.1 x+ + ∑ t : Fin d,f.f (inner ℝ (cavityBulkFeature n d m M f p.1 x (Sum.inr t)) p.2))* + sphericalExp n (gaussianRows (fun i=>cavityBulkFeature n d m M f p.1 x (Sum.inl i)) p.2) + (Real.sqrt (n+1:ℕ))) 1 + +lemma cavityBulk_full_vector_second (n d m M : ℕ) (f : Jet3) (a : BulkDisorder (m+1) M) + (x : NormalizedSpin (m+1)) (K : ℝ) (hK : M/(m+1:ℕ)*‖f.d1‖^2≤K) : + MemLp (fun y=>sphericalExp n + (gaussianRows (fun i=>cavityBulkFeature n d m M f a x (Sum.inl i)) y) + (Real.sqrt (n+1:ℕ))) 2 (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))) ∧ + (∫ y,sphericalExp n + (gaussianRows (fun i=>cavityBulkFeature n d m M f a x (Sum.inl i)) y) + (Real.sqrt (n+1:ℕ))^2 ∂stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)))≤ + Real.exp (2*(n+1:ℕ)*K) := by + let w := fun i : Fin (n+1)=>cavityBulkFeature n d m M f a x (Sum.inl i) + have hw i j : inner ℝ (w i) (w j)=if i=j then bulkB (m+1) M f a.1 x x else 0 := by + simp only [w,cavityBulkFeature_inner,Sum.inl.injEq,Sum.elim_inl] + have hb : 0≤bulkB (m+1) M f a.1 x x := by + have hh : 0 ≤ inner ℝ (w 0) (w 0) := real_inner_self_nonneg + rwa [hw,ite_eq_left rfl] at hh + refine ⟨gaussianRows_spherical_memLp n w hb hw _,?_⟩ + apply (gaussianRows_spherical_second n w hb hw _).trans + apply Real.exp_le_exp.mpr + rw [Real.sq_sqrt (by positivity : 0≤((n+1:ℕ):ℝ))] + exact mul_le_mul_of_nonneg_left + ((le_abs_self _).trans ((bulkB_bound _ _ _ _ _ _).trans hK)) (by positivity) + +lemma cavityBulk_unclipped_cap (n d m M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (Λ : ℝ) (hΛ : 1≤Λ) (K KC : ℝ) + (hK : M/(m+1:ℕ)*‖f.d1‖^2≤K) + (hC : ∀ (a : BulkDisorder (m+1) M) x,|bulkC (m+1) M f a.1 x|≤KC) + (a : BulkDisorder (m+1) M) : + let D:=fun y=>Real.log (cavityBulkFullCompPartition n d m M f v (a,y))- + Real.log (cavityBulkCompPartition n d m M f v Λ hΛ (a,y)) + Integrable D (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))) ∧ + (∀ y,0≤D y) ∧ 0≤∫ y,D y ∂stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) ∧ + (∫ y,D y ∂stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)))≤ + Real.exp (2*((n+1:ℕ)/2*KC+(d:ℝ)*‖f.f‖)+2*(n+1:ℕ)*K)/Λ := by + let E:=EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M) + let μ:=tiltLaw (unitSphereLaw (m+1)) (bulkGibbsHamiltonian m M f.f v a) 1 + have he : Integrable (fun x=>Real.exp (1*bulkGibbsHamiltonian m M f.f v a x)) (unitSphereLaw (m+1)) := by + simpa only [one_mul,bulkGibbsHamiltonian] using bulkHamiltonian_exp_integrable m M f.f v a + let : IsProbabilityMeasure μ := tilt_law_probability_of_integrable _ he + let w:=fun x i=>cavityBulkFeature n d m M f a x (Sum.inl i) + let F : E×NormalizedSpin (m+1)→ℝ:=fun p=>sphericalExp n (gaussianRows (w p.2) p.1) (Real.sqrt (n+1:ℕ)) + let W : E×NormalizedSpin (m+1)→ℝ:=fun p=>(n+1:ℕ)/2*bulkC (m+1) M f a.1 p.2+ + ∑ t : Fin d,f.f (inner ℝ (cavityBulkFeature n d m M f a p.2 (Sum.inr t)) p.1) + have hw : Continuous w := by + apply continuous_pi + intro i + exact (continuous_apply (Sum.inl i)).comp (cavityBulkFeature_continuous n d m M f a) + have hFr : Continuous (fun p : E×NormalizedSpin (m+1)=>gaussianRows (w p.2) p.1) := + cavity_rows_joint_continuous (hw.comp continuous_snd) continuous_fst + have hF : Continuous F := (sphericalExp_continuous n _).comp hFr + have hW : Measurable W := by + unfold W bulkC + have hc:=cavityBulkFeature_continuous n d m M f a + fun_prop + have hWC p : |W p|≤(n+1:ℕ)/2*KC+(d:ℝ)*‖f.f‖ := by + calc + _≤|(n+1:ℕ)/2*bulkC (m+1) M f a.1 p.2|+ + |∑ t : Fin d,f.f (inner ℝ (cavityBulkFeature n d m M f a p.2 (Sum.inr t)) p.1)| := abs_add_le _ _ + _≤(n+1:ℕ)/2*KC+∑ _ : Fin d,‖f.f‖ := by + apply add_le_add + · rw [abs_mul,abs_of_nonneg (by positivity : 0≤((n+1:ℕ):ℝ)/2)] + exact mul_le_mul_of_nonneg_left (hC a p.2) (by positivity) + · exact (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum fun t ht=>f.f.norm_coe_le_norm _) + _=_ := by simp + have hFx y : MemLp (fun x=>F (y,x)) 2 μ := + (hF.comp (continuous_const.prodMk continuous_id)).memLp_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hfg x:=cavityBulk_full_vector_second n d m M f a x K hK + have hc:=cavity_expected_cap μ (stdGaussian E) W F hW hF.measurable hWC + (fun p=>one_le_sphericalExp n _ _) hΛ hFx (fun x=>(hfg x).1) (fun x=>(hfg x).2) + have hH:=(bulkGibbsHamiltonian_measurable m M f.f v).of_uncurry_left (x:=a) + have hfull y : (∫ x,Real.exp (W (y,x))*F (y,x) ∂μ)=cavityBulkFullCompPartition n d m M f v (a,y) := + tilt_law_integral_of_integrable _ hH he + have hcap y : (∫ x,Real.exp (W (y,x))*min (F (y,x)) Λ ∂μ)=cavityBulkCompPartition n d m M f v Λ hΛ (a,y) := by + rw [tilt_law_integral_of_integrable _ hH he] + unfold cavityBulkCompPartition + congr 1 + funext x + simp only [W,F,w,cavitySingleTest_apply,gaussianRows_apply,Real.exp_add,Real.exp_sum] + change Real.exp _ * (∏ t, _) * min (sphericalExp n (WithLp.toLp 2 _) _) Λ = _ + ring_nf + rfl + have hp y:=cavity_capped_log_bound μ + (hW.comp (measurable_const.prodMk measurable_id)) (fun x=>hWC (y,x)) + (hFx y) (fun x=>one_le_sphericalExp n _ _) hΛ + dsimp only [Function.comp_apply,id_eq] at hc hp ⊢ + simp_rw [hfull,hcap] at hc hp + refine ⟨hc.1,fun y=>(hp y).1,hc.2.1,hc.2.2.trans_eq ?_⟩ + rw [Real.exp_add] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityNormalizedIncrement.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityNormalizedIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8cdb7fc0d3af19abf2efc1ca805f259cbafe502 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityNormalizedIncrement.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityConditionalIncrement + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction + +def cavityOldJoinedHamiltonian (n L M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) M) (W : NormalizedSpin (n+1)→ℝ) + (y : Fin M→Spin L) (p : CavityShellSpin n L) : ℝ := + cavityShellPatternEnergy n L M f.f (cavityJoinedPatterns (n+1) L M a.1 y) p+ + inner ℝ (bulkFeature (n+1) v p.1) a.2+W p.1 + +lemma cavity_actual_old_log_identity (n L M : ℕ) (f : Jet3) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) M) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) + (W : NormalizedSpin (n+1)→ℝ) (hW : Measurable W) + {E : ℝ} (hE : 0≤E) (hWE : ∀ x,|W x|≤E) (y : Fin M→Spin L) : + Real.log (∫ p,Real.exp (cavityOldJoinedHamiltonian n L M f v a W y p) + ∂cavityShellBaseLaw n L)-bulkLogPartition n M f.f v a.1 a.2= + Real.log (∫ p,Real.exp (cavityOldIncrement n L M f a.1 W y p) + ∂(tiltLaw (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f.f v a.1 a.2) 1).prod + (cavityShellProbability n L)) := by + have hm : Measurable (cavityOldIncrement n L M f a.1 W y) := by + have hm0 := cavityOldIncrement_measurable n L M f a.1 W hW + exact Measurable.of_uncurry_right + (f:=fun p y=>cavityOldIncrement n L M f a.1 W y p) hm0 + have hB : 0≤2*M*‖f.f‖+E := by positivity + have hVB : ∀ p,|cavityOldIncrement n L M f a.1 W y p|≤2*M*‖f.f‖+E := + cavityOldIncrement_bound n L M f a.1 W hWE y + have hh:=cavity_actual_bulk_log_factorization n L M f.f v a hp + (cavityOldIncrement n L M f a.1 W y) hm hB hVB + apply Eq.trans _ hh + congr 3 + funext p + congr 1 + unfold cavityOldJoinedHamiltonian bulkHamiltonian cavityOldIncrement + ring + +theorem cavity_normalized_old_increment_lower (n k M : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (hn : 2*((k+1)+1)≤n+1) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (v : ℕ→ℝ) (a : BulkDisorder (n+1) M) (W : NormalizedSpin (n+1)→ℝ) + (hW : Measurable W) {E : ℝ} (hE : 0≤E) (hWE : ∀ x,|W x|≤E) : + let μ := tiltLaw (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f.f v a.1 a.2) 1 + let K : ℝ:=M/(n+1:ℕ)*‖f.dilationMark h1‖ + let A : NormalizedSpin (n+1)→Fin M→ℝ:=fun x i=>f.d1 (∑ j,a.1 i j*x.val j) + (∫ y : Fin M→Spin (k+1),(Real.log (∫ p,Real.exp (cavityOldJoinedHamiltonian n (k+1) M f v a W y p) + ∂cavityShellBaseLaw n (k+1))-bulkLogPartition n M f.f v a.1 a.2) ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))≥ + (∫ y : Fin M→Spin (k+1),Real.log (∫ x,Real.exp (W x+(k+1:ℕ)*bulkC (n+1) M f a.1 x/2)* + sphericalExp k (cavityVectorField M (k+1) (A x) (Real.sqrt (n+1:ℕ))⁻¹ y) + (Real.sqrt (k+1:ℕ)) ∂μ) ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))-K/2- + Real.exp (2*(E+((k+1:ℕ)+1)*K/2)+(Real.sqrt (n+1:ℕ))⁻¹^2*((k+1:ℕ)+1)^2*M*‖f.d1‖^2)* + Real.sqrt ((1/(2*(n+1:ℕ)))^2*(((k+1:ℕ)+1)^2)^2*squareGaussianVariance*M*‖f.d2‖^2)- + (∫ y : Fin M→Spin (k+1),∑ i,cavityRemainderMajorant + (cavityRemainderCoefficients f h1 h2 h3 (k+1) ((k+1)+1)) (n+1:ℕ) ‖y i‖ + ∂Measure.pi (fun _=>stdGaussian (Spin (k+1)))) := by + have := tilt_law_probability (unitSphereLaw (n+1)) + (bulkHamiltonian_section_measurable (n+1) M f.f v a) + (show 0≤M*‖f.f‖+bulkFeatureBound (n+1) v*‖a.2‖ from by + apply add_nonneg (by positivity) + apply mul_nonneg + · unfold bulkFeatureBound + positivity + · positivity) + (bulkHamiltonian_bound (n+1) M f.f v a) 1 + dsimp only + simp_rw [cavity_actual_old_log_identity n (k+1) M f v a hp W hW hE hWE] + exact cavity_conditional_old_increment_lower n k M f h1 h2 h3 hn hp + (tiltLaw (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f.f v a.1 a.2) 1) + a.1 W hW hE hWE + +lemma cavity_truncated_countable_kernel {S I : Type*} [MeasurableSpace S] + [Fintype I] [DecidableEq I] (v : ℕ→S→ℝ) (L : S→ℕ) + (Ψ : EuclideanSpace ℝ I→ᵇℝ) (n : ℕ) (xs : I→S) : + (∫ g, Ψ (WithLp.toLp 2 (fun i=>truncatedCountableGaussianField v L n g (xs i))) + ∂countableGaussianLaw)= + cavityMatrixKernel Ψ (fun i j=>gaussianPrefixCovariance v v L n (xs i) (xs j)) := by + let rows : I→EuclideanSpace ℝ (Fin n):=fun i=> + WithLp.toLp 2 (fun j=>maskedGaussianCoefficient v L j.val (xs i)) + have hg : Matrix.gram ℝ rows=(fun i j=>gaussianPrefixCovariance v v L n (xs i) (xs j)) := by + ext i j + change (∑ l : Fin n,maskedGaussianCoefficient v L l.val (xs j)* + maskedGaussianCoefficient v L l.val (xs i))=_ + exact Finset.sum_congr rfl fun l _=>mul_comm _ _ + rw [←hg,cavityMatrixKernel_posSemidef _ _ (Matrix.posSemidef_gram ℝ rows), + ←gaussianRows_map_stdGaussian rows, + integral_map (gaussianRows rows).continuous.measurable.aemeasurable Ψ.continuous.aestronglyMeasurable, + ←map_pi_eq_stdGaussian,integral_map (by fun_prop) (by fun_prop)] + have hp:=gaussianCoordinatePrefix_measurePreserving n + have hm : AEStronglyMeasurable (fun y : Fin n→ℝ=>Ψ (gaussianRows rows (WithLp.toLp 2 y))) + (Measure.pi fun _ : Fin n=>gaussianReal 0 1) := by fun_prop + rw [←hp.map_eq] at hm ⊢ + rw [integral_map hp.measurable.aemeasurable hm] + apply integral_congr_ae + exact ae_of_all _ fun g=>rfl + +lemma cavity_countable_kernel {S I : Type*} [MeasurableSpace S] + [Fintype I] [DecidableEq I] (v : ℕ→S→ℝ) (L : S→ℕ) + (Ψ : EuclideanSpace ℝ I→ᵇℝ) (xs : I→S) : + (∫ g, Ψ (WithLp.toLp 2 (fun i=>countableGaussianField v L g (xs i))) + ∂countableGaussianLaw)= + cavityMatrixKernel Ψ (fun i j=>countableGaussianCovariance v v L (xs i) (xs j)) := by + have he : ∀ᶠ n : ℕ in atTop,∀ i : I,∀ g, + truncatedCountableGaussianField v L n g (xs i)=countableGaussianField v L g (xs i) := + Filter.eventually_all.mpr (fun i=>truncatedCountableGaussianField_eventually_eq v L (xs i)) + have hc : ∀ᶠ n : ℕ in atTop,∀ i j : I, + gaussianPrefixCovariance v v L n (xs i) (xs j)=countableGaussianCovariance v v L (xs i) (xs j) := + Filter.eventually_all.mpr (fun i=>Filter.eventually_all.mpr (fun j=> + gaussianPrefixCovariance_eventually_eq v v L (xs i) (xs j))) + obtain ⟨n,hn,hc⟩:=(he.and hc).exists + have hh:=cavity_truncated_countable_kernel v L Ψ n xs + simp_rw [hn,hc] at hh + exact hh + +def cavityCountableField {S J : Type*} [Fintype J] (v : ℕ→S×J→ℝ) (L : S×J→ℕ) + (g : ℕ→ℝ) (x : S) : EuclideanSpace ℝ J := + WithLp.toLp 2 (fun j=>countableGaussianField v L g (x,j)) + +lemma cavityCountableField_measurable {S J : Type*} [MeasurableSpace S] + [Fintype J] [MeasurableSpace J] (v : ℕ→S×J→ℝ) (L : S×J→ℕ) + (hv : ∀ i,Measurable (v i)) (hL : Measurable L) : + Measurable (fun p : (ℕ→ℝ)×S=>cavityCountableField v L p.1 p.2) := by + apply (MeasurableEquiv.toLp 2 (J→ℝ)).measurable.comp + apply Measurable.of_eval + intro j + exact (countableGaussianField_measurable hv hL).comp + (measurable_fst.prodMk (measurable_snd.prodMk measurable_const)) + +theorem cavity_countable_moment {S J : Type*} [MeasurableSpace S] + [Fintype J] [DecidableEq J] [MeasurableSpace J] + (μ : Measure S) [IsProbabilityMeasure μ] + (v : ℕ→S×J→ℝ) (L : S×J→ℕ) + (hv : ∀ i,Measurable (v i)) (hL : Measurable L) + (Ψ : EuclideanSpace ℝ J→ᵇℝ) (r : ℕ) : + (∫ g, (∫ x, Ψ (cavityCountableField v L g x) ∂μ)^r ∂countableGaussianLaw)= + ∫ xs : Fin r→S,cavityMatrixKernel (cavityTestReplica Ψ r) + (fun i j : J×Fin r=>countableGaussianCovariance v v L (xs i.2,i.1) (xs j.2,j.1)) + ∂Measure.pi (fun _=>μ) := by + let F : (ℕ→ℝ)×(Fin r→S)→ℝ:=fun p=>∏ i,Ψ (cavityCountableField v L p.1 (p.2 i)) + have hm : Measurable F := Finset.measurable_prod _ fun i _=> + Ψ.measurable.comp ((cavityCountableField_measurable v L hv hL).comp + (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd))) + have hb p : ‖F p‖≤‖Ψ‖^r := by + simp only [F,norm_prod] + exact (Finset.prod_le_prod₀ (fun _ _=>norm_nonneg _) (fun _ _=>Ψ.norm_coe_le_norm _)).trans_eq (by simp) + have hi : Integrable F (countableGaussianLaw.prod (Measure.pi fun _ : Fin r=>μ)) := + Integrable.of_bound hm.aestronglyMeasurable _ (ae_of_all _ hb) + calc + _=∫ g,∫ xs : Fin r→S,F (g,xs) ∂Measure.pi (fun _=>μ) ∂countableGaussianLaw := by + apply integral_congr_ae + exact ae_of_all _ fun g=>by + simpa only [F,Fintype.card_fin] using + (integral_fintype_prod_eq_pow (ι:=Fin r) (fun x=>Ψ (cavityCountableField v L g x)) (μ:=μ)).symm + _=∫ xs : Fin r→S,∫ g,F (g,xs) ∂countableGaussianLaw ∂Measure.pi (fun _=>μ) := integral_integral_swap hi + _=_ := by + apply integral_congr_ae + exact ae_of_all _ fun xs=>by + simpa only [cavityTestReplica_apply,cavityCountableField,F] using + cavity_countable_kernel v L (cavityTestReplica Ψ r) (fun p : J×Fin r=>(xs p.2,p.1)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityOldExpectation.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityOldExpectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..a0f06f21b5fbe869ae2451592bd5f6b547b73393 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityOldExpectation.lean @@ -0,0 +1,193 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityIncrementLaw +import OAI.Probability.Perceptron.Cavity.CavityBulkUncappedLog + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_three_integral {A B C : Type*} [MeasurableSpace A] [MeasurableSpace B] + [MeasurableSpace C] (μ : Measure A) (ν : Measure B) (ρ : Measure C) + [SFinite μ] [SFinite ν] [SFinite ρ] (F : A×B×C→ℝ) + (hF : Integrable F (μ.prod (ν.prod ρ))) : + (∫ p,F p ∂μ.prod (ν.prod ρ))=∫ a,∫ b,∫ c,F (a,b,c) ∂ρ ∂ν ∂μ := by + rw [integral_prod _ hF] + apply integral_congr_ae + filter_upwards [hF.prod_right_ae] with a ha + exact integral_prod _ ha + +lemma cavity_three_integral_compare {A B C : Type*} [MeasurableSpace A] [MeasurableSpace B] + [MeasurableSpace C] (μ : Measure A) (ν : Measure B) (ρ : Measure C) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] [IsProbabilityMeasure ρ] + (F G : A×B×C→ℝ) (H : A→ℝ) (e : ℝ) + (hF : Integrable F (μ.prod (ν.prod ρ))) (hG : Integrable G (μ.prod (ν.prod ρ))) + (hH : Integrable H μ) + (h : ∀ a b,(∫ c,G (a,b,c) ∂ρ)-H a-e≤∫ c,F (a,b,c) ∂ρ) : + (∫ p,G p ∂μ.prod (ν.prod ρ))-(∫ a,H a ∂μ)-e≤∫ p,F p ∂μ.prod (ν.prod ρ) := by + have hp:=measurePreserving_prodAssoc μ ν ρ + have hFi:= (hp.integrable_comp hF.aestronglyMeasurable).mpr hF + have hGi:= (hp.integrable_comp hG.aestronglyMeasurable).mpr hG + have hHi:=hH.comp_fst ν + have hi:=integral_mono ((hGi.integral_prod_left.sub hHi).sub (integrable_const e)) + hFi.integral_prod_left (fun p=>h p.1 p.2) + erw [integral_sub (hGi.integral_prod_left.sub hHi) (integrable_const e), + integral_sub hGi.integral_prod_left hHi,integral_const,probReal_univ,one_smul, + integral_fun_fst,probReal_univ,one_smul,←integral_prod _ hGi,←integral_prod _ hFi] at hi + have hfe:=cavity_integral_preserving _ _ _ hp F hF.aestronglyMeasurable + have hge:=cavity_integral_preserving _ _ _ hp G hG.aestronglyMeasurable + simp only [Function.comp_def] at hi + rw [hfe,hge] at hi + exact hi + +def cavityOldError (n k M d : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) : ℝ := + let K : ℝ:=M/(n+1:ℕ)*‖f.dilationMark h1‖ + K/2+ + Real.exp (2*(d*‖f.f‖+((k+1:ℕ)+1)*K/2)+(Real.sqrt (n+1:ℕ))⁻¹^2*((k+1:ℕ)+1)^2*M*‖f.d1‖^2)* + Real.sqrt ((1/(2*(n+1:ℕ)))^2*(((k+1:ℕ)+1)^2)^2*squareGaussianVariance*M*‖f.d2‖^2)+ + (∫ y : Fin M→Spin (k+1),∑ i,cavityRemainderMajorant + (cavityRemainderCoefficients f h1 h2 h3 (k+1) ((k+1)+1)) (n+1:ℕ) ‖y i‖ + ∂Measure.pi (fun _=>stdGaussian (Spin (k+1)))) + +lemma cavitySplitLog_proxy_integrable (n k M d : ℕ) (f : Jet3) + (hf : HasCompactSupport (f.d1 : ℝ→ℝ)) (v : ℕ→ℝ) : + Integrable (fun p : CavityProxyRandom n (k+1) M d=>Real.log (cavitySplitPartition k d n M f v (p.1,p.2.2,p.2.1))) + (cavityProxyLaw n (k+1) M d) := by + have : IsProbabilityMeasure (finitePatternRowsLaw (n+1) d) := inferInstance + have : IsProbabilityMeasure (Measure.pi fun _ : Fin M=>stdGaussian (Spin (k+1))) := inferInstance + have : SFinite (finitePatternRowsLaw (n+1) d) := inferInstance + have : SFinite (Measure.pi fun _ : Fin M=>stdGaussian (Spin (k+1))) := inferInstance + have hp:=(MeasurePreserving.id (bulkDisorderLaw (n+1) M)).prod + (Measure.measurePreserving_swap (μ:=finitePatternRowsLaw (n+1) d) + (ν:=Measure.pi fun _ : Fin M=>stdGaussian (Spin (k+1)))) + exact (hp.integrable_comp (cavitySplitPartition_measurable k d n M f v).log.aestronglyMeasurable).mpr + (cavitySplitLog_integrable k d n M f hf v) + +lemma cavity_proxy_conditional_lower (n k M d : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (hn : 2*((k+1)+1)≤n+1) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) M) (b : Fin d→Fin (n+1)→ℝ) : + (∫ y, Real.log (cavitySplitPartition k d n M f v (a,y,b)) ∂Measure.pi (fun _ : Fin M=>stdGaussian (Spin (k+1)))) + -(-bulkLogPartition n M f.f v a.1 a.2)-cavityOldError n k M d f h1 h2 h3≤ + ∫ y,cavityProxyLog n (k+1) M d f v (a,b,y) ∂Measure.pi (fun _ : Fin M=>stdGaussian (Spin (k+1))) := by + have hw : Measurable (normalizedPatternEnergy (n+1) d f.f b) := + (normalizedPatternEnergy_continuous (n+1) d f.f).measurable.comp (f:=fun x : NormalizedSpin (n+1)=>(b,x)) (measurable_const.prodMk measurable_id) + have hi:= cavity_normalized_old_increment_lower n k M f h1 h2 h3 hn hp v a + (normalizedPatternEnergy (n+1) d f.f b) hw (by positivity : 0≤d*‖f.f‖) + (normalizedPatternEnergy_bound (n+1) d f.f b) + dsimp only at hi + have hsec:=cavityProxyLog_section_integrable n (k+1) M d f v hp a b + change _≤∫ y,cavityProxyLog n (k+1) M d f v (a,b,y)-bulkLogPartition n M f.f v a.1 a.2 ∂Measure.pi (fun _ : Fin M=>stdGaussian (Spin (k+1))) at hi + rw [integral_sub hsec (integrable_const _),integral_const,probReal_univ,one_smul] at hi + dsimp only [cavityOldError] + change (∫ y,Real.log (cavitySplitPartition k d n M f v (a,y,b)) ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))-_-_-_≤_ at hi + linarith + +lemma cavity_proxy_expected_lower (n k M d : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (hn : 2*((k+1)+1)≤n+1) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) (v : ℕ→ℝ) : + cavityBulkFullLog k d n M f v+bulkExpectedLog n M f.f v-cavityOldError n k M d f h1 h2 h3≤ + ∫ p,cavityProxyLog n (k+1) M d f v p ∂cavityProxyLaw n (k+1) M d := by + let F:=cavityProxyLog n (k+1) M d f v + let G:=fun p : CavityProxyRandom n (k+1) M d=>Real.log (cavitySplitPartition k d n M f v (p.1,p.2.2,p.2.1)) + let H:=fun a : BulkDisorder (n+1) M=> -bulkLogPartition n M f.f v a.1 a.2 + have hFi:=cavityProxyLog_integrable n (k+1) M d f v hp + have hGi:=cavitySplitLog_proxy_integrable n k M d f h1 v + have hHi:=((bulkLogPartition_memLp n M f.f v).integrable (by norm_num)).neg + have hi:=cavity_three_integral_compare (bulkDisorderLaw (n+1) M) (finitePatternRowsLaw (n+1) d) + (Measure.pi fun _ : Fin M=>stdGaussian (Spin (k+1))) F G H (cavityOldError n k M d f h1 h2 h3) + hFi hGi hHi (fun a b=>?_) + · have he: (∫ p,G p ∂cavityProxyLaw n (k+1) M d)=cavityBulkFullLog k d n M f v := by + unfold cavityProxyLaw + rw [cavity_three_integral _ _ _ G hGi,cavityBulkFullLog_split k d n M f h1 v] + have hh: (∫ a,H a ∂bulkDisorderLaw (n+1) M)= -bulkExpectedLog n M f.f v := integral_neg _ + change (∫ p,G p ∂cavityProxyLaw n (k+1) M d)-(∫ a,H a ∂bulkDisorderLaw (n+1) M)-_≤_ at hi + rw [he,hh,sub_neg_eq_add] at hi + exact hi + · exact cavity_proxy_conditional_lower n k M d f h1 h2 h3 hn hp v a b + + +lemma cavity_actual_proxy_log_bound (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) + (p : CavityIncrementRandom n L M d) : + |cavityShellLowLog n L (M+d) f.f v (cavityIncrementFullRows n L M d p,p.1.2)- + cavityProxyLog n L M d f v (cavityProxyProjection n L M d p)|≤ + cavityFreshMajorant (n+1) L d f p.2.1 p.2.2.2 := by + let H:=fun s : CavityShellSpin n L=>cavityShellPatternEnergy n L M f.f + (cavityJoinedPatterns (n+1) L M p.1.1 p.2.2.1) s+inner ℝ (bulkFeature (n+1) v s.1) p.1.2 + have hm : Measurable H := (cavityShellPatternEnergy_measurable n L M f.f _).add + (((bulkFeature_continuous (n+1) v).measurable.comp measurable_fst).inner measurable_const) + have hb : ∀ s,|H s|≤M*‖f.f‖+bulkFeatureBound (n+1) v*‖p.1.2‖ := by + intro s + exact (abs_add_le _ _).trans (add_le_add (cavityShellPatternEnergy_bound n L M f.f _ s) + (by simpa only [bulkFeature_norm] using abs_real_inner_le_norm (bulkFeature (n+1) v s.1) p.1.2)) + have hh:=cavity_fresh_log_replacement n L d f hp H hm + (show 0≤M*‖f.f‖+bulkFeatureBound (n+1) v*‖p.1.2‖ from by unfold bulkFeatureBound; positivity) + hb p.2.1 p.2.2.2 + convert hh using 1 + congr 2 + unfold cavityShellLowLog tiltPartition cavityIncrementFullRows + simp_rw [one_mul,cavityShellPatternEnergy_append] + congr 2 + funext s + congr 1 + dsimp only [H] + ring + +lemma cavityFreshProjection_preserving (n L M d : ℕ) : + MeasurePreserving (fun p : CavityIncrementRandom n L M d=>(p.2.1,p.2.2.2)) + (cavityIncrementLaw n L M d) + ((finitePatternRowsLaw (n+1) d).prod (Measure.pi fun _ : Fin d=>stdGaussian (Spin L))) := by + have : IsProbabilityMeasure (finitePatternRowsLaw (n+1) d) := inferInstance + have : SFinite (finitePatternRowsLaw (n+1) d) := inferInstance + have h1 : MeasurePreserving Prod.snd (cavityIncrementLaw n L M d) + ((finitePatternRowsLaw (n+1) d).prod ((Measure.pi fun _ : Fin M=>stdGaussian (Spin L)).prod + (Measure.pi fun _ : Fin d=>stdGaussian (Spin L)))) := measurePreserving_snd + have h2 : MeasurePreserving Prod.snd + ((Measure.pi fun _ : Fin M=>stdGaussian (Spin L)).prod (Measure.pi fun _ : Fin d=>stdGaussian (Spin L))) + (Measure.pi fun _ : Fin d=>stdGaussian (Spin L)) := measurePreserving_snd + exact ((MeasurePreserving.id (finitePatternRowsLaw (n+1) d)).prod h2).comp h1 + +lemma cavity_fresh_expected_lower (n L M d : ℕ) (f : Jet3) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + (∫ p,cavityProxyLog n L M d f v p ∂cavityProxyLaw n L M d)- + ‖f.d1‖*d*((L:ℝ)+1)*(1+Real.sqrt L)/Real.sqrt (n+1:ℕ)≤ + ∫ p,cavityShellLowLog n L (M+d) f.f v p + ∂(finitePatternRowsLaw (n+1+L) (M+d)).prod (stdGaussian (BulkMark (n+1))) := by + let F:=fun p : CavityIncrementRandom n L M d=> + cavityShellLowLog n L (M+d) f.f v (cavityIncrementFullRows n L M d p,p.1.2) + let G:=fun p : CavityIncrementRandom n L M d=>cavityProxyLog n L M d f v (cavityProxyProjection n L M d p) + let R:=fun p : CavityIncrementRandom n L M d=>cavityFreshMajorant (n+1) L d f p.2.1 p.2.2.2 + have hF:=cavityIncrement_actual_integrable n L M d f.f v hp + have hG : Integrable G (cavityIncrementLaw n L M d) := (cavityProxyProjection_preserving n L M d).integrable_comp_of_integrable + (cavityProxyLog_integrable n L M d f v hp) + have hr:=cavityFreshMajorant_rows_integrable (n+1) L d f + have hR : Integrable R (cavityIncrementLaw n L M d) := (cavityFreshProjection_preserving n L M d).integrable_comp_of_integrable hr + have hi:=integral_mono (hG.sub hR) hF (fun p=>by + have hb:=(abs_le.mp (cavity_actual_proxy_log_bound n L M d f v hp p)).1 + change G p-R p≤F p + dsimp only [F,G,R] + linarith) + change (∫ p,G p-R p ∂cavityIncrementLaw n L M d)≤∫ p,F p ∂cavityIncrementLaw n L M d at hi + rw [integral_sub hG hR] at hi + have heG:=cavity_integral_preserving _ _ _ (cavityProxyProjection_preserving n L M d) _ + (cavityProxyLog_measurable n L M d f v hp).aestronglyMeasurable + have heR:=cavity_integral_preserving _ _ _ (cavityFreshProjection_preserving n L M d) _ hr.aestronglyMeasurable + change (∫ p,G p ∂cavityIncrementLaw n L M d)=_ at heG + change (∫ p,R p ∂cavityIncrementLaw n L M d)=_ at heR + rw [heG,heR] at hi + have heF:=cavityIncrement_actual_expectation n L M d f.f v hp + change (∫ p,F p ∂cavityIncrementLaw n L M d)=_ at heF + rw [heF] at hi + exact (sub_le_sub_left (cavityFreshMajorant_rows_mean_bound n L d f) _).trans hi +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityPerturbationCovariance.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityPerturbationCovariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9c8b083a7b71101c7c4c8ede4e9a1e7bff02a48 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityPerturbationCovariance.lean @@ -0,0 +1,226 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkTangentError + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma bulkCovariance_bound (N : ℕ) (v : ℕ→ℝ) {C r : ℝ} + (hC : 0≤C) (hv : ∀ j, |v (j+1)|≤C) (hr : |r|≤1) : + |bulkCovariance N v r|≤C^2 := by + have ht (j : Fin N) : + |((2:ℝ)^(-((j.val+1:ℕ):ℤ)))^2*v (j.val+1)^2*r^(j.val+1)|≤C^2*(1/2:ℝ)^(j.val+1) := by + rw [perturbationWeight_eq,abs_mul,abs_mul,abs_sq,abs_sq,abs_pow] + have hw0 : 0≤(1/2:ℝ)^(j.val+1) := by positivity + have hw1 : (1/2:ℝ)^(j.val+1)≤1 := pow_le_one₀ (by norm_num) (by norm_num) + have hv2 : v (j.val+1)^2≤C^2 := by + exact sq_le_sq.mpr (by simpa only [abs_of_nonneg hC] using hv j.val) + calc + _ ≤ ((1/2:ℝ)^(j.val+1))^2*C^2*1 := + mul_le_mul (mul_le_mul_of_nonneg_left hv2 (sq_nonneg _)) + (pow_le_one₀ (abs_nonneg r) hr) (by positivity) (by positivity) + _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_left (show ((1/2:ℝ)^(j.val+1))^2≤(1/2:ℝ)^(j.val+1) by nlinarith) (sq_nonneg C)] + unfold bulkCovariance + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ j : Fin N,C^2*(1/2:ℝ)^(j.val+1) := Finset.sum_le_sum fun j _=>ht j + _ = C^2*(∑ j : Fin N,(1/2:ℝ)^(j.val+1)) := (Finset.mul_sum _ _ _).symm + _ ≤ C^2*1 := mul_le_mul_of_nonneg_left (half_power_sum_le_one N) (sq_nonneg C) + _ = _ := mul_one _ + +lemma bulkCovariance_scaled_hasDerivAt (N : ℕ) (v : ℕ→ℝ) (r : ℝ) : + HasDerivAt (fun t=>bulkScale N^2*bulkCovariance N v t) + (bulkCovarianceDerivative N v r) r := by + have he (t : ℝ) : bulkScale N^2*bulkCovariance N v t= + ∑ j : Fin N,bulkAmplitude N v j^2*t^(j.val+1) := by + simp only [bulkCovariance,bulkAmplitude,Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + simp_rw [he] + simpa [bulkCovarianceDerivative,mul_assoc] using HasDerivAt.fun_sum + (u:=Finset.univ) (fun j (_ : j∈(Finset.univ : Finset (Fin N)))=> + ((hasDerivAt_id r).pow (j.val+1)).const_mul (bulkAmplitude N v j^2)) + +lemma bulkCovariance_scaled_lipschitz (N : ℕ) (v : ℕ→ℝ) {C r s : ℝ} + (hC : 0≤C) (hv : ∀ j, |v (j+1)|≤C) (hr : |r|≤1) (hs : |s|≤1) : + |bulkScale N^2*bulkCovariance N v s-bulkScale N^2*bulkCovariance N v r|≤ + C^2*bulkScale N^2*|s-r| := by + have hh := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun t (_ : t∈Icc (-1:ℝ) 1)=>(bulkCovariance_scaled_hasDerivAt N v t).hasDerivWithinAt) + (fun t ht=>show ‖bulkCovarianceDerivative N v t‖≤C^2*bulkScale N^2 by + simpa only [Real.norm_eq_abs] using bulkCovarianceDerivative_bound N v hC hv (abs_le.mpr ht)) + (convex_Icc (-1:ℝ) 1) (abs_le.mp hr) (abs_le.mp hs) + simpa only [Real.norm_eq_abs] using hh + +lemma bulkCovariance_dimension_tail (N L : ℕ) (v : ℕ→ℝ) {C r : ℝ} + (hC : 0≤C) (hv : ∀ j, |v (j+1)|≤C) (hr : |r|≤1) : + |bulkCovariance (N+L) v r-bulkCovariance N v r|≤ + (L:ℝ)*C^2*(1/2:ℝ)^(N+1) := by + have he : bulkCovariance (N+L) v r-bulkCovariance N v r= + ∑ j : Fin L,((2:ℝ)^(-((N+j.val+1:ℕ):ℤ)))^2*v (N+j.val+1)^2*r^(N+j.val+1) := by + unfold bulkCovariance + rw [Fin.sum_univ_add] + simp only [Fin.val_castAdd,Fin.val_natAdd,add_sub_cancel_left] + rw [he] + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _ : Fin L,C^2*(1/2:ℝ)^(N+1) := by + apply Finset.sum_le_sum + intro j _ + rw [perturbationWeight_eq,abs_mul,abs_mul,abs_sq,abs_sq,abs_pow] + have hw0 : 0≤(1/2:ℝ)^(N+j.val+1) := by positivity + have hw1 : (1/2:ℝ)^(N+j.val+1)≤1 := pow_le_one₀ (by norm_num) (by norm_num) + have hwt : (1/2:ℝ)^(N+j.val+1)≤(1/2:ℝ)^(N+1) := by + have he : N+j.val+1=(N+1)+j.val := by omega + rw [he,pow_add] + exact (mul_le_mul_of_nonneg_left (pow_le_one₀ (by norm_num : (0:ℝ)≤1/2) (by norm_num) : (1/2:ℝ)^j.val≤1) (by positivity)).trans_eq (mul_one _) + have hv2 : v (N+j.val+1)^2≤C^2 := by + exact sq_le_sq.mpr (by simpa only [abs_of_nonneg hC] using hv (N+j.val)) + calc + _ ≤ ((1/2:ℝ)^(N+j.val+1))^2*C^2*1 := + mul_le_mul (mul_le_mul_of_nonneg_left hv2 (sq_nonneg _)) + (pow_le_one₀ (abs_nonneg r) hr) (by positivity) (by positivity) + _ ≤ C^2*(1/2:ℝ)^(N+j.val+1) := by + nlinarith [mul_le_mul_of_nonneg_left (show ((1/2:ℝ)^(N+j.val+1))^2≤(1/2:ℝ)^(N+j.val+1) by nlinarith) (sq_nonneg C)] + _ ≤ _ := mul_le_mul_of_nonneg_left hwt (sq_nonneg C) + _ = _ := by simp; ring + +theorem cavity_bulk_covariance_bound (N L : ℕ) (v : ℕ→ℝ) {C r s : ℝ} + (hC : 0≤C) (hv : ∀ j, |v (j+1)|≤C) (hr : |r|≤1) (hs : |s|≤1) : + |bulkScale (N+L)^2*bulkCovariance (N+L) v s-bulkScale N^2*bulkCovariance N v r|≤ + C^2*bulkScale (N+L)^2*|s-r|+ + bulkScale (N+L)^2*((L:ℝ)*C^2*(1/2:ℝ)^(N+1))+ + |bulkScale (N+L)^2-bulkScale N^2| * C^2 := by + calc + _ ≤ |bulkScale (N+L)^2*bulkCovariance (N+L) v s-bulkScale (N+L)^2*bulkCovariance (N+L) v r|+ + |bulkScale (N+L)^2*bulkCovariance (N+L) v r-bulkScale N^2*bulkCovariance N v r| := abs_sub_le _ _ _ + _ ≤ C^2*bulkScale (N+L)^2*|s-r|+ + (bulkScale (N+L)^2*((L:ℝ)*C^2*(1/2:ℝ)^(N+1))+|bulkScale (N+L)^2-bulkScale N^2| * C^2) := by + apply add_le_add (bulkCovariance_scaled_lipschitz (N+L) v hC hv hr hs) + calc + _ ≤ |bulkScale (N+L)^2*(bulkCovariance (N+L) v r-bulkCovariance N v r)|+ + |(bulkScale (N+L)^2-bulkScale N^2)*bulkCovariance N v r| := by + convert abs_add_le (bulkScale (N+L)^2*(bulkCovariance (N+L) v r-bulkCovariance N v r)) + ((bulkScale (N+L)^2-bulkScale N^2)*bulkCovariance N v r) using 1 + congr 1 + ring + _ ≤ _ := by + rw [abs_mul,abs_sq,abs_mul] + exact add_le_add (mul_le_mul_of_nonneg_left (bulkCovariance_dimension_tail N L v hC hv hr) (sq_nonneg _)) + (mul_le_mul_of_nonneg_left (bulkCovariance_bound N v hC hv hr) (abs_nonneg _)) + _ = _ := by ring + +lemma bulkScale_sq_eq_rpow (N : ℕ) : bulkScale N^2=(N:ℝ)^((3:ℝ)/4) := by + unfold bulkScale + rw [←Real.rpow_mul_natCast (Nat.cast_nonneg N)] + norm_num + +lemma bulkScale_sq_shift_bound (n L : ℕ) : + |bulkScale (n+1+L)^2-bulkScale (n+1)^2|≤ + (3/4:ℝ)*(L:ℝ)*((n+1:ℕ):ℝ)^(-(1:ℝ)/4) := by + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + have hd (x : ℝ) (hx : x∈Icc ((n+1:ℕ):ℝ) ((n+1+L:ℕ):ℝ)) : + HasDerivWithinAt (fun x : ℝ=>x^((3:ℝ)/4)) + ((3/4:ℝ)*x^(-(1:ℝ)/4)) (Icc ((n+1:ℕ):ℝ) ((n+1+L:ℕ):ℝ)) x := by + simpa only [show (3:ℝ)/4-1=-(1:ℝ)/4 by norm_num] using + (Real.hasDerivAt_rpow_const (p:=(3:ℝ)/4) (Or.inl (ne_of_gt (hn.trans_le hx.1)))).hasDerivWithinAt + have hh := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le hd + (fun x hx=>show ‖(3/4:ℝ)*x^(-(1:ℝ)/4)‖≤(3/4:ℝ)*((n+1:ℕ):ℝ)^(-(1:ℝ)/4) by + rw [Real.norm_eq_abs,abs_of_nonneg (mul_nonneg (by norm_num) (Real.rpow_nonneg (hn.trans_le hx.1).le _))] + exact mul_le_mul_of_nonneg_left (Real.rpow_le_rpow_of_nonpos hn hx.1 (by norm_num)) (by norm_num)) + (convex_Icc _ _) + (show ((n+1:ℕ):ℝ)∈Icc ((n+1:ℕ):ℝ) ((n+1+L:ℕ):ℝ) by constructor; rfl; exact_mod_cast Nat.le_add_right (n+1) L) + (show ((n+1+L:ℕ):ℝ)∈Icc ((n+1:ℕ):ℝ) ((n+1+L:ℕ):ℝ) by constructor; exact_mod_cast Nat.le_add_right (n+1) L; rfl) + rw [bulkScale_sq_eq_rpow,bulkScale_sq_eq_rpow] + simpa only [Real.norm_eq_abs,Nat.cast_add,add_sub_cancel_left, + abs_of_nonneg (Nat.cast_nonneg L : (0:ℝ)≤L),mul_assoc,mul_comm,mul_left_comm] using hh + +lemma bulkScale_sq_div_shift_bound (n L : ℕ) : + bulkScale (n+1+L)^2/(n+1:ℕ)≤ + (L+1:ℝ)*((n+1:ℕ):ℝ)^(-(1:ℝ)/4) := by + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + have hNL : (0:ℝ)<(n+1+L:ℕ) := by positivity + have he : bulkScale (n+1+L)^2=(n+1+L:ℕ)*((n+1+L:ℕ):ℝ)^(-(1:ℝ)/4) := by + rw [bulkScale_sq_eq_rpow] + calc + _ = ((n+1+L:ℕ):ℝ)^((1:ℝ)+(-(1:ℝ)/4)) := by norm_num + _ = _ := by rw [Real.rpow_add hNL,Real.rpow_one] + rw [he] + apply (div_le_iff₀ hn).mpr + calc + _ ≤ ((n+1+L:ℕ):ℝ)*((n+1:ℕ):ℝ)^(-(1:ℝ)/4) := + mul_le_mul_of_nonneg_left (Real.rpow_le_rpow_of_nonpos hn (by exact_mod_cast Nat.le_add_right (n+1) L) (by norm_num)) hNL.le + _ ≤ _ := by + have hb : ((n+1+L:ℕ):ℝ)≤(L+1:ℝ)*(n+1:ℕ) := by + have h1 : (1:ℝ)≤(n+1:ℕ) := by exact_mod_cast Nat.succ_pos n + push_cast + nlinarith [mul_nonneg (Nat.cast_nonneg L) (show (0:ℝ)≤(n+1:ℕ)-1 by linarith)] + nlinarith [mul_le_mul_of_nonneg_right hb (Real.rpow_nonneg hn.le (-(1:ℝ)/4))] + +def cavityBulkCovarianceError (n L : ℕ) (C D : ℝ) : ℝ := + C^2*D*(bulkScale (n+1+L)^2/(n+1:ℕ))+ + bulkScale (n+1+L)^2*((L:ℝ)*C^2*(1/2:ℝ)^(n+1+1))+ + |bulkScale (n+1+L)^2-bulkScale (n+1)^2| * C^2 + +lemma cavityBulkCovarianceError_nonneg (n L : ℕ) (C : ℝ) {D : ℝ} (hD : 0≤D) : + 0≤cavityBulkCovarianceError n L C D := by unfold cavityBulkCovarianceError; positivity + +lemma cavity_bulk_covariance_shell (n L : ℕ) (v : ℕ→ℝ) {C D r s : ℝ} + (hC : 0≤C) (hD : 0≤D) (hv : ∀ j, |v (j+1)|≤C) + (hr : |r|≤1) (hs : |s|≤1) (hδ : |s-r|≤D/(n+1:ℕ)) : + |bulkScale (n+1+L)^2*bulkCovariance (n+1+L) v s- + bulkScale (n+1)^2*bulkCovariance (n+1) v r|≤cavityBulkCovarianceError n L C D := by + apply (cavity_bulk_covariance_bound (n+1) L v hC hv hr hs).trans + unfold cavityBulkCovarianceError + have ht : C^2*bulkScale (n+1+L)^2*|s-r|≤C^2*D*(bulkScale (n+1+L)^2/(n+1:ℕ)) := by + simpa only [div_eq_mul_inv, mul_assoc, mul_comm, mul_left_comm] using + mul_le_mul hδ (le_refl (C^2*bulkScale (n+1+L)^2)) (by positivity) + (div_nonneg hD (by positivity)) + exact add_le_add (add_le_add ht le_rfl) le_rfl + +lemma cavityBulkCovarianceError_tendsto (L : ℕ) (C : ℝ) {D : ℝ} (hD : 0≤D) : + Tendsto (fun n=>cavityBulkCovarianceError n L C D) atTop (𝓝 0) := by + have hN : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have hp : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)^(-(1:ℝ)/4)) atTop (𝓝 0) := by + simpa only [neg_div,Function.comp_def] using (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1/4)).comp hN + have hd : Tendsto (fun n=>C^2*D*(bulkScale (n+1+L)^2/(n+1:ℕ))) atTop (𝓝 0) := + squeeze_zero (fun n=>mul_nonneg (mul_nonneg (sq_nonneg C) hD) (by positivity)) + (fun n=>mul_le_mul_of_nonneg_left (bulkScale_sq_div_shift_bound n L) + (mul_nonneg (sq_nonneg C) hD)) + (by simpa using (hp.const_mul (L+1:ℝ)).const_mul (C^2*D)) + have hs : Tendsto (fun n=>|bulkScale (n+1+L)^2-bulkScale (n+1)^2|) atTop (𝓝 0) := + squeeze_zero (fun n=>abs_nonneg _) (fun n=>bulkScale_sq_shift_bound n L) + (by simpa using hp.const_mul ((3/4:ℝ)*(L:ℝ))) + have hg : Tendsto (fun n : ℕ=>(1/2:ℝ)^(n+1+1)) atTop (𝓝 0) := + (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : (0:ℝ)≤1/2) (by norm_num)).comp + ((tendsto_add_atTop_nat 1).comp (tendsto_add_atTop_nat 1)) + have hng : Tendsto (fun n : ℕ=>(n+1+1:ℕ)*(1/2:ℝ)^(n+1+1)) atTop (𝓝 0) := by + simpa only [pow_one,Function.comp_def] using + (tendsto_pow_const_mul_const_pow_of_lt_one 1 (by norm_num : (0:ℝ)≤1/2) (by norm_num)).comp + ((tendsto_add_atTop_nat 1).comp (tendsto_add_atTop_nat 1)) + have hng' : Tendsto (fun n : ℕ=>(n+1+L:ℕ)*(1/2:ℝ)^(n+1+1)) atTop (𝓝 0) := by + convert hng.add (hg.const_mul (L-1:ℝ)) using 1 + · ext n + push_cast + ring + · simp + have ht : Tendsto (fun n=>bulkScale (n+1+L)^2*(1/2:ℝ)^(n+1+1)) atTop (𝓝 0) := by + apply squeeze_zero (fun n=>by positivity) (fun n=>show _≤(n+1+L:ℕ)*(1/2:ℝ)^(n+1+1) from + mul_le_mul_of_nonneg_right ?_ (by positivity)) hng' + have hx : (1:ℝ)≤(n+1+L:ℕ) := by exact_mod_cast (by omega : 1≤n+1+L) + rw [bulkScale_sq_eq_rpow] + simpa using Real.rpow_le_rpow_of_exponent_le hx (by norm_num : (3:ℝ)/4≤1) + convert (hd.add (ht.const_mul ((L:ℝ)*C^2))).add (hs.mul_const (C^2)) using 1 + · ext n + unfold cavityBulkCovarianceError + ring + · simp +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityProductLaw.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityProductLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..6eb353176e4f91c91181ad9fa3d7b762f6a7fe15 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityProductLaw.lean @@ -0,0 +1,186 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityShellRestriction + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_integral_preserving {A B E : Type*} [MeasurableSpace A] [MeasurableSpace B] + [NormedAddCommGroup E] [NormedSpace ℝ E] (μ : Measure A) (ν : Measure B) + (F : A→B) (hF : MeasurePreserving F μ ν) (g : B→E) (hg : AEStronglyMeasurable g ν) : + (∫ a,g (F a) ∂μ)=∫ b,g b ∂ν := by + rw [←hF.map_eq] at hg ⊢ + exact (integral_map hF.measurable.aemeasurable hg).symm + +lemma cavity_prod_front_swap {A B C : Type*} [MeasurableSpace A] [MeasurableSpace B] + [MeasurableSpace C] (μ : Measure A) (ν : Measure B) (ρ : Measure C) + [SFinite μ] [SFinite ν] [SFinite ρ] : + MeasurePreserving (fun p : A×B×C=>(p.2.1,p.1,p.2.2)) + (μ.prod (ν.prod ρ)) (ν.prod (μ.prod ρ)) := by + exact (measurePreserving_prodAssoc ν μ ρ).comp + ((Measure.measurePreserving_swap.prod (MeasurePreserving.id ρ)).comp + (measurePreserving_prodAssoc μ ν ρ).symm) + +lemma cavity_product_shuffle {A G B Y Z : Type*} [MeasurableSpace A] [MeasurableSpace G] + [MeasurableSpace B] [MeasurableSpace Y] [MeasurableSpace Z] + (μ : Measure A) (γ : Measure G) (ν : Measure B) (η : Measure Y) (ζ : Measure Z) + [SFinite μ] [SFinite γ] [SFinite ν] [SFinite η] [SFinite ζ] : + MeasurePreserving (fun p : (A×G)×B×Y×Z=>(((p.1.1,p.2.2.1),(p.2.1,p.2.2.2)),p.1.2)) + ((μ.prod γ).prod (ν.prod (η.prod ζ))) (((μ.prod η).prod (ν.prod ζ)).prod γ) := by + have h1:=(MeasurePreserving.id (μ.prod γ)).prod (cavity_prod_front_swap ν η ζ) + have h2:=measurePreserving_prodAssoc μ γ (η.prod (ν.prod ζ)) + have h3:=(MeasurePreserving.id μ).prod (Measure.measurePreserving_swap (μ:=γ) (ν:=η.prod (ν.prod ζ))) + have h4:=(measurePreserving_prodAssoc μ (η.prod (ν.prod ζ)) γ).symm + have h5:=((measurePreserving_prodAssoc μ η (ν.prod ζ)).symm).prod (MeasurePreserving.id γ) + exact h5.comp (h4.comp (h3.comp (h2.comp h1))) + +def cavityRowsAppend (N M d : ℕ) (a : Fin M→Fin N→ℝ) (b : Fin d→Fin N→ℝ) : + Fin (M+d)→Fin N→ℝ := fun i=>Sum.elim a b (finSumFinEquiv.symm i) + +lemma cavityRowsAppend_preserving (N M d : ℕ) : + MeasurePreserving (fun p=>cavityRowsAppend N M d p.1 p.2) + ((finitePatternRowsLaw N M).prod (finitePatternRowsLaw N d)) + (finitePatternRowsLaw N (M+d)) := by + convert (measurePreserving_piCongrLeft (fun _ : Fin (M+d)=>Measure.pi fun _ : Fin N=>gaussianReal 0 1) + finSumFinEquiv).comp (measurePreserving_sumPiEquivProdPi_symm + (fun _ : Fin M⊕Fin d=>Measure.pi fun _ : Fin N=>gaussianReal 0 1)) using 1 + · funext p i + simp only [Function.comp_apply,MeasurableEquiv.coe_piCongrLeft,MeasurableEquiv.coe_sumPiEquivProdPi_symm] + rcases h : finSumFinEquiv.symm i with j | j <;> simp [cavityRowsAppend,Equiv.piCongrLeft_apply,h,Equiv.sumPiEquivProdPi] + · rfl + · rfl + +lemma normalizedPatternEnergy_append (N M d : ℕ) (f : ℝ→ᵇℝ) + (a : Fin M→Fin N→ℝ) (b : Fin d→Fin N→ℝ) (x : NormalizedSpin N) : + normalizedPatternEnergy N (M+d) f (cavityRowsAppend N M d a b) x= + normalizedPatternEnergy N M f a x+normalizedPatternEnergy N d f b x := by + unfold normalizedPatternEnergy + rw [←finSumFinEquiv.sum_comp] + simp only [cavityRowsAppend,Equiv.symm_apply_apply,Fintype.sum_sum_type,Sum.elim_inl,Sum.elim_inr] + +lemma cavityShellPatternEnergy_append (n L M d : ℕ) (f : ℝ→ᵇℝ) + (a : Fin M→Fin (n+1+L)→ℝ) (b : Fin d→Fin (n+1+L)→ℝ) (x : CavityShellSpin n L) : + cavityShellPatternEnergy n L (M+d) f (cavityRowsAppend (n+1+L) M d a b) x= + cavityShellPatternEnergy n L M f a x+cavityShellPatternEnergy n L d f b x := by + exact normalizedPatternEnergy_append _ _ _ _ _ _ _ + + +lemma cavity_gaussian_joint_log_integrable {A S I : Type*} [MeasurableSpace A] + [MeasurableSpace S] [Fintype I] (Q : Measure A) [IsProbabilityMeasure Q] + (μ : Measure S) [IsProbabilityMeasure μ] (H : A→S→ℝ) (V : S→EuclideanSpace ℝ I) + (hH : Measurable (Function.uncurry H)) (hV : Measurable V) + {C B : ℝ} (hC : 0≤C) (hB : 0≤B) (hHC : ∀ a x,|H a x|≤C) (hVB : ∀ x,‖V x‖≤B) : + Integrable (fun p : A×EuclideanSpace ℝ I=>Real.log (tiltPartition μ + (fun x=>H p.1 x+inner ℝ (V x) p.2) 1)) (Q.prod (stdGaussian (EuclideanSpace ℝ I))) := by + have hi:=((integrable_const C).add + ((IsGaussian.integrable_id (μ:=stdGaussian (EuclideanSpace ℝ I))).norm.const_mul B)).comp_snd Q + have hm : Measurable (fun p : (A×EuclideanSpace ℝ I)×S=>H p.1.1 p.2+inner ℝ (V p.2) p.1.2) := + (hH.comp (measurable_fst.fst.prodMk measurable_snd)).add + ((hV.comp measurable_snd).inner measurable_fst.snd) + apply hi.mono' (by + simpa only [tiltPartition,one_mul] using hm.exp.stronglyMeasurable.integral_prod_right'.measurable.log.aestronglyMeasurable) + filter_upwards [] with p + rw [Real.norm_eq_abs] + apply tilt_log_partition_bound μ + ((hH.comp (measurable_const.prodMk measurable_id)).add (hV.inner measurable_const)) + (add_nonneg hC (mul_nonneg hB (norm_nonneg _))) + intro x + exact (abs_add_le _ _).trans (add_le_add (hHC p.1 x) + ((abs_real_inner_le_norm _ _).trans (mul_le_mul_of_nonneg_right (hVB x) (norm_nonneg _)))) + +def cavityShellLowLog (n L M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (p : (Fin M→Fin (n+1+L)→ℝ)×BulkMark (n+1)) : ℝ := + Real.log (tiltPartition (cavityShellBaseLaw n L) + (fun x=>cavityShellPatternEnergy n L M f p.1 x+inner ℝ (bulkFeature (n+1) v x.1) p.2) 1) + +lemma cavityShellPatternEnergy_joint_measurable (n L M : ℕ) (f : ℝ→ᵇℝ) : + Measurable (fun p : (Fin M→Fin (n+1+L)→ℝ)×CavityShellSpin n L=> + cavityShellPatternEnergy n L M f p.1 p.2) := by + change Measurable (fun p : (Fin M→Fin (n+1+L)→ℝ)×CavityShellSpin n L=>normalizedPatternEnergy (n+1+L) M f p.1 (cavityShellSpinEmbedding n L p.2)) + exact (normalizedPatternEnergy_continuous (n+1+L) M f).measurable.comp + (f:=fun p : (Fin M→Fin (n+1+L)→ℝ)×CavityShellSpin n L=>(p.1,cavityShellSpinEmbedding n L p.2)) + (measurable_fst.prodMk ((cavityShellSpinEmbedding_measurable n L).comp measurable_snd)) + +lemma cavityShellLowLog_integrable (n L M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + Integrable (cavityShellLowLog n L M f v) + ((finitePatternRowsLaw (n+1+L) M).prod (stdGaussian (BulkMark (n+1)))) := by + let := cavityShellBaseLaw_probability n L hp + apply cavity_gaussian_joint_log_integrable _ _ _ _ + (cavityShellPatternEnergy_joint_measurable n L M f) + ((bulkFeature_continuous (n+1) v).measurable.comp measurable_fst) + (by positivity : 0≤M*‖f‖) (Real.sqrt_nonneg _) + (cavityShellPatternEnergy_bound n L M f) + intro x + exact (bulkFeature_norm _ _ _).le + +lemma bulkExpectedLog_nested (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + bulkExpectedLog n M f v=∫ a,∫ g,Real.log (tiltPartition (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a g) 1) ∂stdGaussian (BulkMark (n+1)) + ∂finitePatternRowsLaw (n+1) M := by + unfold bulkExpectedLog bulkDisorderLaw + rw [integral_prod _ ((bulkLogPartition_memLp n M f v).integrable (by norm_num))] + simp_rw [bulkLogPartition_eq] + rfl + +theorem cavity_expected_shell_restriction (n L M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + {C : ℝ} (hC : 0≤C) (hv : ∀ j,|v (j+1)|≤C) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + Real.log ((cavitySphereLaw n L : Measure (Spin L)).real (cavityShell L))- + Real.pi*cavityBulkCovarianceError n L C (3*((L:ℝ)+1))+ + (∫ p,cavityShellLowLog n L M f v p + ∂(finitePatternRowsLaw (n+1+L) M).prod (stdGaussian (BulkMark (n+1))))≤ + bulkExpectedLog (n+L) M f v := by + let := cavityShellBaseLaw_probability n L hp + have hlo:=cavityShellLowLog_integrable n L M f v hp + have hhi:=cavity_gaussian_joint_log_integrable (finitePatternRowsLaw (n+1+L) M) + (cavityShellBaseLaw n L) (cavityShellPatternEnergy n L M f) (cavityShellFeature n L v) + (cavityShellPatternEnergy_joint_measurable n L M f) (cavityShellFeature_measurable n L v) + (by positivity : 0≤M*‖f‖) (Real.sqrt_nonneg _) (cavityShellPatternEnergy_bound n L M f) + (fun x=>(cavityShellFeature_norm n L v x).le) + rw [integral_prod _ hlo,bulkExpectedLog_nested] + rw [show n+L+1=n+1+L by omega] + let : IsProbabilityMeasure (unitSphereLaw (n+1+L)) := by + rw [show n+1+L=(n+L)+1 by omega]; infer_instance + have hb:=cavity_gaussian_joint_log_integrable (finitePatternRowsLaw (n+1+L) M) + (unitSphereLaw (n+1+L)) (normalizedPatternEnergy (n+1+L) M f) (bulkFeature (n+1+L) v) + (normalizedPatternEnergy_continuous (n+1+L) M f).measurable (bulkFeature_continuous _ _).measurable + (by positivity : 0≤M*‖f‖) (Real.sqrt_nonneg _) (normalizedPatternEnergy_bound _ _ _) + (fun x=>(bulkFeature_norm _ _ _).le) + have hpoint : ∀ a,Real.log ((cavitySphereLaw n L : Measure (Spin L)).real (cavityShell L))- + Real.pi*cavityBulkCovarianceError n L C (3*((L:ℝ)+1))+ + (∫ g,cavityShellLowLog n L M f v (a,g) ∂stdGaussian (BulkMark (n+1)))≤ + ∫ g,Real.log (tiltPartition (unitSphereLaw (n+1+L)) + (bulkHamiltonian (n+1+L) M f v a g) 1) ∂stdGaussian (BulkMark (n+1+L)) := by + intro a + have hr:=cavity_gaussian_log_integrable (cavityShellBaseLaw n L) + (cavityShellPatternEnergy_measurable n L M f a) (cavityShellFeature_measurable n L v) + (by positivity : 0≤M*‖f‖) (Real.sqrt_nonneg _) (cavityShellPatternEnergy_bound n L M f a) + (fun x=>(cavityShellFeature_norm n L v x).le) + have hb':=cavity_gaussian_log_integrable (unitSphereLaw (n+1+L)) + ((normalizedPatternEnergy_continuous (n+1+L) M f).measurable.comp (measurable_const.prodMk measurable_id)) + (bulkFeature_continuous (n+1+L) v).measurable (by positivity : 0≤M*‖f‖) (Real.sqrt_nonneg _) + (normalizedPatternEnergy_bound _ _ _ a) (fun x=>(bulkFeature_norm _ _ _).le) + have hc:=cavity_true_shell_perturbation n L M f a v hC hv hp + have hh:=integral_mono ((integrable_const _).add hr) hb' + (cavity_actual_shell_log_restriction n L M f v a · hp) + simp only [Pi.add_apply,Function.comp_def,id_eq] at hh + rw [integral_add (integrable_const _) hr,integral_const,probReal_univ,one_smul] at hh + dsimp [cavityShellLowLog] at ⊢ + change _≤∫ g,Real.log (tiltPartition (unitSphereLaw (n+1+L)) + (fun s=>normalizedPatternEnergy (n+1+L) M f a s+inner ℝ (bulkFeature (n+1+L) v s) g) 1) ∂_ + linarith [(abs_le.mp hc).1] + have hi:=integral_mono ((integrable_const _).add hlo.integral_prod_left) hb.integral_prod_left hpoint + simp only [Pi.add_apply] at hi + change _≤∫ a,∫ g,Real.log (tiltPartition (unitSphereLaw (n+1+L)) + (fun s=>normalizedPatternEnergy (n+1+L) M f a s+inner ℝ (bulkFeature (n+1+L) v s) g) 1) + ∂stdGaussian (BulkMark (n+1+L)) ∂finitePatternRowsLaw (n+1+L) M + simpa only [integral_add (integrable_const _) hlo.integral_prod_left,integral_const,probReal_univ,one_smul,bulkHamiltonian] using hi +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityQuadraticDrop.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityQuadraticDrop.lean new file mode 100644 index 0000000000000000000000000000000000000000..07160a4db13da0a9ccd96d4264c90db1a523f9e2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityQuadraticDrop.lean @@ -0,0 +1,239 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LocalMaxSecondDerivNonpos +import OAI.Probability.Perceptron.Brownian.CavityGaussianFields + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators + +lemma cavity_log_drop_quadratic {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {H Q : S→ℝ} + (hH : Measurable H) (hQ : Measurable Q) {A B : ℝ} + (hA : 0≤A) (hB : 0≤B) (hHA : ∀ x,|H x|≤A) (hQB : ∀ x,|Q x|≤B) : + Real.log (∫ x,Real.exp (H x+Q x) ∂μ)≥ + Real.log (∫ x,Real.exp (H x) ∂μ)- + (∫ x,Real.exp (H x)*|Q x| ∂μ)/(∫ x,Real.exp (H x) ∂μ) := by + have hc := affineLogRoot_convex μ hH hQ hA hB hHA hQB + have hd := affineLogRoot_deriv μ hH hQ hA hB hHA hQB 0 + have hs := hc.le_slope_of_hasDerivAt (mem_univ 0) (mem_univ 1) (by norm_num : (0:ℝ)<1) hd + simp only [affineLogRoot,tiltPartition,slope,zero_mul,add_zero,one_mul,sub_zero,inv_one,one_smul,vsub_eq_sub] at hs + have hqq : -(∫ x,Real.exp (H x)*|Q x| ∂μ)≤∫ x,Real.exp (H x)*Q x ∂μ := by + rw [←integral_neg] + apply integral_mono + · have hi : Integrable (fun x=>Real.exp (H x)*|Q x|) μ := by + simpa only [one_mul] using tilt_integrable μ hH hQ.abs hA hB hHA (fun x=>by simpa only [abs_abs] using hQB x) 1 + exact hi.neg + · simpa only [one_mul] using tilt_integrable μ hH hQ hA hB hHA hQB 1 + · intro x + have := mul_le_mul_of_nonneg_left (neg_abs_le (Q x)) (Real.exp_pos (H x)).le + simpa only [mul_neg] using this + have hp : 0<∫ x,Real.exp (H x) ∂μ := by + simpa only [tiltPartition,one_mul] using tilt_partition_pos μ hH hA hHA 1 + have hdiv := (div_le_div_of_nonneg_right hqq hp.le) + simp only [tiltMean,tiltIntegral,tiltPartition,one_mul] at hs + rw [neg_div] at hdiv + linarith + +lemma cavity_exp_abs_cauchy {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) + {H Q : Ω→ℝ} (hE : MemLp (fun y=>Real.exp (H y)) 2 P) (hQ : MemLp Q 2 P) : + (∫ y,Real.exp (H y)*|Q y| ∂P)≤ + Real.sqrt (∫ y,Real.exp (2*H y) ∂P)*Real.sqrt (∫ y,(Q y)^2 ∂P) := by + have hp : Real.HolderConjugate 2 2 := by norm_num [Real.holderConjugate_iff] + have he := integral_mul_norm_le_Lp_mul_Lq hp (by simpa using hE) (by simpa using hQ) + simp only [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),Real.rpow_two, sq_abs] at he + simp_rw [←Real.exp_nat_mul] at he + norm_num only [Nat.cast_ofNat] at he + simpa only [Real.sqrt_eq_rpow,one_div] using he + +lemma cavityLinearField_exp_integrable (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) (p : ℝ) : + Integrable (fun y=>Real.exp (p*cavityLinearField M L a t z y)) + (Measure.pi (fun _=>stdGaussian (Spin L))) := by + by_contra hi + have h:=cavityLinearField_exp_moment M L a t z p + rw [integral_undef hi] at h + exact (Real.exp_pos _).ne' h.symm + +lemma cavityLinearField_exp_memLp (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) (p : ℝ) : + MemLp (fun y=>Real.exp (p*cavityLinearField M L a t z y)) 2 + (Measure.pi (fun _=>stdGaussian (Spin L))) := by + apply (memLp_two_iff_integrable_sq (show AEStronglyMeasurable + (fun y=>Real.exp (p*cavityLinearField M L a t z y)) _ from + (show Continuous (fun y=>Real.exp (p*cavityLinearField M L a t z y)) from by + unfold cavityLinearField; fun_prop).aestronglyMeasurable)).mpr + have hi:=cavityLinearField_exp_integrable M L a t z (2*p) + convert hi using 1 + ext y + rw [←Real.exp_nat_mul] + congr 1 + norm_num only [Nat.cast_ofNat] + ring + +lemma cavity_tilted_Q_conditional (M L : ℕ) (a b : Fin M→ℝ) (t u : ℝ) (z : Spin L) : + (∫ y,Real.exp (cavityLinearField M L a t z y)*|cavityQuadraticField M L b u z y| + ∂Measure.pi (fun _=>stdGaussian (Spin L)))≤ + Real.exp (t^2*‖z‖^2*∑ i,(a i)^2)* + Real.sqrt (u^2*‖z‖^4*squareGaussianVariance*∑ i,(b i)^2) := by + have he : MemLp (fun y=>Real.exp (cavityLinearField M L a t z y)) 2 + (Measure.pi (fun _=>stdGaussian (Spin L))) := by + simpa only [one_mul] using cavityLinearField_exp_memLp M L a t z 1 + have h:=cavity_exp_abs_cauchy _ he (cavityQuadraticField_memLp M L b u z) + rw [cavityLinearField_exp_moment,cavityQuadraticField_second_moment] at h + have hx : (2:ℝ)^2*t^2*‖z‖^2/2*(∑ i,(a i)^2)=2*(t^2*‖z‖^2*∑ i,(a i)^2) := by ring + have he2 (r : ℝ) : Real.exp (2*r)=(Real.exp r)^2 := Real.exp_nat_mul r 2 + rw [hx,he2,Real.sqrt_sq (Real.exp_pos _).le] at h + exact h + +lemma cavity_tilted_Q_uniform (M L : ℕ) (a b : Fin M→ℝ) (t u : ℝ) (z : Spin L) + {A B D : ℝ} (_hA : 0≤A) (_hB : 0≤B) (hD : 0≤D) + (ha : ∀ i,|a i|≤A) (hb : ∀ i,|b i|≤B) (hz : ‖z‖^2≤D) : + (∫ y,Real.exp (cavityLinearField M L a t z y)*|cavityQuadraticField M L b u z y| + ∂Measure.pi (fun _=>stdGaussian (Spin L)))≤ + Real.exp (t^2*D*M*A^2)*Real.sqrt (u^2*D^2*squareGaussianVariance*M*B^2) := by + have hs {c : Fin M→ℝ} {C : ℝ} (hc : ∀ i, |c i|≤C) : ∑ i,(c i)^2≤M*C^2 := by + calc + _≤∑ _ : Fin M,C^2 := Finset.sum_le_sum fun i _=>by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (c i)) (hc i) 2 + _=_ := by simp + apply (cavity_tilted_Q_conditional M L a b t u z).trans + apply mul_le_mul + · apply Real.exp_le_exp.mpr + calc + _≤t^2*D*(M*A^2) := mul_le_mul + (mul_le_mul_of_nonneg_left hz (sq_nonneg t)) (hs ha) + (Finset.sum_nonneg fun _ _=>sq_nonneg _) (mul_nonneg (sq_nonneg t) hD) + _=_ := by ring + · apply Real.sqrt_le_sqrt + calc + _=u^2*(‖z‖^2)^2*squareGaussianVariance*(∑ i,(b i)^2) := by ring + _≤u^2*D^2*squareGaussianVariance*(M*B^2) := mul_le_mul + (mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left + (pow_le_pow_left₀ (sq_nonneg _) hz 2) (sq_nonneg _)) squareGaussianVariance_nonneg) + (hs hb) (Finset.sum_nonneg fun _ _=>sq_nonneg _) + (mul_nonneg (mul_nonneg (sq_nonneg _) (sq_nonneg _)) squareGaussianVariance_nonneg) + _=_ := by ring + · exact Real.sqrt_nonneg _ + · exact (Real.exp_pos _).le + +lemma cavity_tilted_Q_integrable (M L : ℕ) (a b : Fin M→ℝ) (t u : ℝ) (z : Spin L) : + Integrable (fun y=>Real.exp (cavityLinearField M L a t z y)*|cavityQuadraticField M L b u z y|) + (Measure.pi (fun _=>stdGaussian (Spin L))) := by + have he : MemLp (fun y=>Real.exp (cavityLinearField M L a t z y)) 2 + (Measure.pi (fun _=>stdGaussian (Spin L))) := by + simpa only [one_mul] using cavityLinearField_exp_memLp M L a t z 1 + exact he.integrable_mul (cavityQuadraticField_memLp M L b u z).abs + +lemma cavityLinearField_measurable {S : Type*} [MeasurableSpace S] (M L : ℕ) + (a : S→Fin M→ℝ) (z : S→Spin L) (ha : Measurable a) (hz : Measurable z) (t : ℝ) : + Measurable (fun p : S×(Fin M→Spin L)=>cavityLinearField M L (a p.1) t (z p.1) p.2) := by + unfold cavityLinearField + have hac : Measurable (fun p : S×(Fin M→Spin L)=>a p.1) := ha.comp measurable_fst + have hzc : Measurable (fun p : S×(Fin M→Spin L)=>z p.1) := hz.comp measurable_fst + fun_prop + +lemma cavityQuadraticField_measurable {S : Type*} [MeasurableSpace S] (M L : ℕ) + (b : S→Fin M→ℝ) (z : S→Spin L) (hb : Measurable b) (hz : Measurable z) (u : ℝ) : + Measurable (fun p : S×(Fin M→Spin L)=>cavityQuadraticField M L (b p.1) u (z p.1) p.2) := by + unfold cavityQuadraticField + have hbc : Measurable (fun p : S×(Fin M→Spin L)=>b p.1) := hb.comp measurable_fst + have hzc : Measurable (fun p : S×(Fin M→Spin L)=>z p.1) := hz.comp measurable_fst + fun_prop + +lemma cavity_Q_product_integrable {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M L : ℕ) + (a b : S→Fin M→ℝ) (z : S→Spin L) (W : S→ℝ) + (ha : Measurable a) (hb : Measurable b) (hz : Measurable z) (hW : Measurable W) + (t u : ℝ) {A B C D : ℝ} (hA : 0≤A) (hB : 0≤B) (hD : 0≤D) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) + (hzB : ∀ s,‖z s‖^2≤D) (hWB : ∀ s,|W s|≤C) : + Integrable (fun p : S×(Fin M→Spin L)=>Real.exp (W p.1+cavityLinearField M L (a p.1) t (z p.1) p.2)* + |cavityQuadraticField M L (b p.1) u (z p.1) p.2|) + (μ.prod (Measure.pi (fun _=>stdGaussian (Spin L)))) := by + let P:=Measure.pi (fun _ : Fin M=>stdGaussian (Spin L)) + let F : S×(Fin M→Spin L)→ℝ:=fun p=> + Real.exp (W p.1+cavityLinearField M L (a p.1) t (z p.1) p.2)* + |cavityQuadraticField M L (b p.1) u (z p.1) p.2| + have hm : Measurable F := + ((hW.comp measurable_fst).add (cavityLinearField_measurable M L a z ha hz t)).exp.mul + (cavityQuadraticField_measurable M L b z hb hz u).abs + have hf s : Integrable (fun y=>F (s,y)) P := by + simpa only [F,Real.exp_add,mul_assoc] using + (cavity_tilted_Q_integrable M L (a s) (b s) t u (z s)).const_mul (Real.exp (W s)) + have hbound s : (∫ y,F (s,y) ∂P)≤Real.exp C* + (Real.exp (t^2*D*M*A^2)*Real.sqrt (u^2*D^2*squareGaussianVariance*M*B^2)) := by + conv_lhs => simp only [F,Real.exp_add,mul_assoc,integral_const_mul] + exact mul_le_mul (Real.exp_le_exp.mpr (abs_le.mp (hWB s)).2) + (cavity_tilted_Q_uniform M L (a s) (b s) t u (z s) hA hB hD (haB s) (hbB s) (hzB s)) + (integral_nonneg fun _=>mul_nonneg (Real.exp_pos _).le (abs_nonneg _)) (Real.exp_pos _).le + apply (integrable_prod_iff hm.aestronglyMeasurable).mpr + refine ⟨ae_of_all _ hf,?_⟩ + apply Integrable.of_bound (hm.aestronglyMeasurable.norm.integral_prod_right') + (Real.exp C*(Real.exp (t^2*D*M*A^2)*Real.sqrt (u^2*D^2*squareGaussianVariance*M*B^2))) + filter_upwards [] with s + have hp : ∀ y,0≤F (s,y) := fun y=>mul_nonneg (Real.exp_pos _).le (abs_nonneg _) + simp only [Real.norm_eq_abs] + simp_rw [abs_of_nonneg (hp _)] + rw [abs_of_nonneg (integral_nonneg hp)] + exact hbound s + +lemma cavity_Q_normalized_bound {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M L : ℕ) + (a b : S→Fin M→ℝ) (z : S→Spin L) (W : S→ℝ) + (ha : Measurable a) (hb : Measurable b) (hz : Measurable z) (hW : Measurable W) + (t u : ℝ) {A B C D : ℝ} (hA : 0≤A) (hB : 0≤B) (hD : 0≤D) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) + (hzB : ∀ s,‖z s‖^2≤D) (hWB : ∀ s,|W s|≤C) + (hden : ∀ y,Real.exp (-C)≤∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y) ∂μ) : + (∫ y,(∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y)* + |cavityQuadraticField M L (b s) u (z s) y| ∂μ)/ + (∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y) ∂μ) + ∂Measure.pi (fun _=>stdGaussian (Spin L)))≤ + Real.exp (2*C+t^2*D*M*A^2)*Real.sqrt (u^2*D^2*squareGaussianVariance*M*B^2) := by + let P:=Measure.pi (fun _ : Fin M=>stdGaussian (Spin L)) + let F : S×(Fin M→Spin L)→ℝ:=fun p=> + Real.exp (W p.1+cavityLinearField M L (a p.1) t (z p.1) p.2)* + |cavityQuadraticField M L (b p.1) u (z p.1) p.2| + let Z : (Fin M→Spin L)→ℝ:=fun y=>∫ s,Real.exp (W s+cavityLinearField M L (a s) t (z s) y) ∂μ + have hi : Integrable F (μ.prod P) := cavity_Q_product_integrable μ M L a b z W ha hb hz hW t u hA hB hD haB hbB hzB hWB + have hZm : AEStronglyMeasurable Z P := by + exact (((hW.comp measurable_fst).add (cavityLinearField_measurable M L a z ha hz t)).exp.stronglyMeasurable).integral_prod_left'.aestronglyMeasurable + have hnorm y : 0≤∫ s,F (s,y) ∂μ := integral_nonneg fun _=>mul_nonneg (Real.exp_pos _).le (abs_nonneg _) + have hratio y : (∫ s,F (s,y) ∂μ)/Z y≤Real.exp C*(∫ s,F (s,y) ∂μ) := by + rw [div_eq_mul_inv,mul_comm (Real.exp C)] + apply mul_le_mul_of_nonneg_left _ (hnorm y) + calc + (Z y)⁻¹≤(Real.exp (-C))⁻¹ := inv_anti₀ (Real.exp_pos _) (hden y) + _=Real.exp C := by rw [Real.exp_neg,inv_inv] + have hrI : Integrable (fun y=>(∫ s,F (s,y) ∂μ)/Z y) P := by + apply (hi.integral_prod_right.const_mul (Real.exp C)).mono' + (hi.integral_prod_right.aestronglyMeasurable.div₀ hZm) + filter_upwards [] with y + change ‖(∫ s,F (s,y) ∂μ)/Z y‖≤_ + rw [Real.norm_eq_abs,abs_of_nonneg (div_nonneg (hnorm y) ((Real.exp_pos _).le.trans (hden y)))] + exact hratio y + calc + _≤∫ y,Real.exp C*(∫ s,F (s,y) ∂μ) ∂P := integral_mono hrI (hi.integral_prod_right.const_mul _) hratio + _=Real.exp C*(∫ s,∫ y,F (s,y) ∂P ∂μ) := by + rw [integral_const_mul,←integral_integral_swap hi] + _≤Real.exp C*(Real.exp C*(Real.exp (t^2*D*M*A^2)*Real.sqrt (u^2*D^2*squareGaussianVariance*M*B^2))) := by + apply mul_le_mul_of_nonneg_left _ (Real.exp_pos _).le + calc + _≤∫ _ : S,Real.exp C*(Real.exp (t^2*D*M*A^2)*Real.sqrt (u^2*D^2*squareGaussianVariance*M*B^2)) ∂μ := by + apply integral_mono hi.integral_prod_left (integrable_const _) + intro s + conv_lhs => simp only [F,Real.exp_add,mul_assoc,integral_const_mul] + exact mul_le_mul (Real.exp_le_exp.mpr (abs_le.mp (hWB s)).2) + (cavity_tilted_Q_uniform M L (a s) (b s) t u (z s) hA hB hD (haB s) (hbB s) (hzB s)) + (integral_nonneg fun _=>mul_nonneg (Real.exp_pos _).le (abs_nonneg _)) (Real.exp_pos _).le + _=_ := by simp + _=_ := by + have he : Real.exp (2*C)=(Real.exp C)^2 := Real.exp_nat_mul C 2 + rw [Real.exp_add,he] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityResidualFormula.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityResidualFormula.lean new file mode 100644 index 0000000000000000000000000000000000000000..0e910a184632fa02aeab55b1b5e40e590e73fb26 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityResidualFormula.lean @@ -0,0 +1,66 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityFiniteEvaluation + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory +open scoped NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +lemma cavity_scalar_residual (d : ℕ) (f : ℝ→ᵇℝ) (s : ℝ≥0) (x : Fin d→ℝ) : + (∫ y : Spin d,Real.exp (∑ i,f (x i+Real.sqrt s*y i)) ∂stdGaussian (Spin d))= + Real.exp (∑ i,heatLog s 1 f (x i)) := by + let G : (Fin d→ℝ)→ℝ := fun y=>∏ i,Real.exp (f (x i+Real.sqrt s*y i)) + have hm : Measurable G := by unfold G; fun_prop + have hp:=stdGaussian_ofLp_preserving d + simp only [Real.exp_sum] + change (∫ y,G (WithLp.ofLp y) ∂stdGaussian (Spin d))=_ + rw [←integral_map hp.measurable.aemeasurable hm.aestronglyMeasurable,hp.map_eq] + dsimp only [G] + rw [integral_fintype_prod_eq_prod (fun i t=>Real.exp (f (x i+Real.sqrt s*t)))] + apply Finset.prod_congr rfl + intro i hi + have he:=exp_heatLog s 1 (by norm_num) f (x i) + rw [gaussianAverage_scaling] at he + simpa only [NNReal.coe_one,one_mul,expBCF_apply] using he.symm + +def cavityFullSingle (n d : ℕ) (f : ℝ→ᵇℝ) + (v : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : ℝ := + sphericalExp n (gaussianSumSplit v).1 (Real.sqrt (n+1:ℕ))*Real.exp (∑ i,f (v (Sum.inr i))) + +lemma cavityFullSingle_measurable (n d : ℕ) (f : ℝ→ᵇℝ) : Measurable (cavityFullSingle n d f) := by + apply ((sphericalExp_continuous n _).measurable.comp gaussianSumSplit_measurable.fst).mul + apply Measurable.exp + apply Finset.measurable_sum + intro i hi + exact f.measurable.comp ((measurable_pi_apply (Sum.inr i)).comp (MeasurableEquiv.toLp 2 _).symm.measurable) + +lemma cavity_full_residual (n d : ℕ) (f : ℝ→ᵇℝ) (a s : ℝ≥0) + (v : EuclideanSpace ℝ (Fin (n+1)⊕Fin d)) : + (∫ y,cavityFullSingle n d f (WithLp.toLp 2 (fun i=>v i+ + Sum.elim (fun _=>Real.sqrt a) (fun _=>Real.sqrt s) i*y i)) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))= + Real.exp ((n+1:ℕ)*a/2+logSphericalExp n (Real.sqrt (n+1:ℕ)) (gaussianSumSplit v).1+ + ∑ i,heatLog s 1 f (v (Sum.inr i))) := by + let G : Spin (n+1)×Spin d→ℝ:=fun y=> + sphericalExp n ((gaussianSumSplit v).1+Real.sqrt a • y.1) (Real.sqrt (n+1:ℕ))* + Real.exp (∑ i,f (v (Sum.inr i)+Real.sqrt s*y.2 i)) + have hm : Measurable G := by + apply ((sphericalExp_continuous n _).measurable.comp (by fun_prop)).mul + fun_prop + have he y : cavityFullSingle n d f (WithLp.toLp 2 (fun i=>v i+ + Sum.elim (fun _=>Real.sqrt a) (fun _=>Real.sqrt s) i*y i))=G (gaussianSumSplit y) := rfl + simp_rw [he] + have hp:=gaussianSumSplit_preserving (I:=Fin (n+1)) (J:=Fin d) + rw [←integral_map hp.measurable.aemeasurable hm.aestronglyMeasurable,hp.map_eq] + dsimp only [G] + rw [integral_prod_mul (fun y=>sphericalExp n ((gaussianSumSplit v).1+Real.sqrt a • y) (Real.sqrt (n+1:ℕ))) + (fun y : Spin d=>Real.exp (∑ i,f (v (Sum.inr i)+Real.sqrt s*y i))), + sphericalExp_gaussian_average,Real.sq_sqrt (by positivity : 0≤((n+1:ℕ):ℝ)), + Real.sq_sqrt a.coe_nonneg,cavity_scalar_residual] + simp only [Real.exp_add,logSphericalExp,Real.exp_log (lt_of_lt_of_le zero_lt_one (one_le_sphericalExp n _ _))] +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityResidualUncap.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityResidualUncap.lean new file mode 100644 index 0000000000000000000000000000000000000000..9e0162bd62a721e0ceda28c9bd5dff088118a9b2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityResidualUncap.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityLabelLimit +import OAI.Probability.Perceptron.Cavity.CavityCountableIsotropic + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_residual_square_integrable {S G T : Type*} + [MeasurableSpace S] [MeasurableSpace G] [MeasurableSpace T] + (μ : Measure S) (P : Measure G) (Q : Measure T) + [IsProbabilityMeasure μ] [IsProbabilityMeasure P] [IsProbabilityMeasure Q] + (F : G×(S×T)→ℝ) (hF : Measurable F) (K : ℝ) + (hL2 : ∀ x, MemLp (fun p : G×T=>F (p.1,(x,p.2))) 2 (P.prod Q)) + (h2 : ∀ x, (∫ p : G×T,F (p.1,(x,p.2))^2 ∂P.prod Q)≤K) : + Integrable (fun p=>F p^2) (P.prod (μ.prod Q)) ∧ + (∫ g,∫ x,F (g,x)^2 ∂μ.prod Q ∂P)≤K := by + let H : S×(G×T)→ℝ := fun p=>F (p.2.1,(p.1,p.2.2))^2 + have hm : Measurable H := (hF.comp + (measurable_snd.fst.prodMk (measurable_fst.prodMk measurable_snd.snd))).pow_const 2 + have hi : Integrable H (μ.prod (P.prod Q)) := by + apply (integrable_prod_iff hm.aestronglyMeasurable).mpr + constructor + · exact ae_of_all _ fun x=>(memLp_two_iff_integrable_sq (hL2 x).aestronglyMeasurable).mp (hL2 x) + · apply Integrable.of_bound (hm.norm.stronglyMeasurable.integral_prod_right).aestronglyMeasurable K + filter_upwards [] with x + have he : (∫ p : G×T,‖H (x,p)‖ ∂P.prod Q)=(∫ p : G×T,F (p.1,(x,p.2))^2 ∂P.prod Q) := by + simp only [H,Real.norm_eq_abs,abs_sq] + rw [he,Real.norm_eq_abs,abs_of_nonneg (integral_nonneg fun _=>sq_nonneg _)] + exact h2 x + have hp : MeasurePreserving (fun p : G×(S×T)=>(p.2.1,(p.1,p.2.2))) + (P.prod (μ.prod Q)) (μ.prod (P.prod Q)) := + (measurePreserving_prodAssoc μ P Q).comp + ((Measure.measurePreserving_swap.prod (MeasurePreserving.id Q)).comp + ((measurePreserving_prodAssoc P μ Q).symm _)) + have hi' : Integrable (fun p=>F p^2) (P.prod (μ.prod Q)) := + (hp.integrable_comp hm.aestronglyMeasurable).mpr hi + refine ⟨hi',?_⟩ + rw [←integral_prod _ hi'] + have he : (∫ p : G×(S×T),F p^2 ∂P.prod (μ.prod Q)) = + ∫ p,H p ∂μ.prod (P.prod Q) := by + rw [←hp.map_eq,integral_map hp.measurable.aemeasurable hm.aestronglyMeasurable] + rw [he,integral_prod _ hi] + calc + _ ≤ ∫ _ : S,K ∂μ := integral_mono hi.integral_prod_left (integrable_const K) h2 + _ = K := by simp + +lemma cavity_expected_cap_residual {S G T : Type*} + [MeasurableSpace S] [MeasurableSpace G] [MeasurableSpace T] + (μ : Measure S) (P : Measure G) (Q : Measure T) + [IsProbabilityMeasure μ] [IsProbabilityMeasure P] [IsProbabilityMeasure Q] + (W F : G×(S×T)→ℝ) (hW : Measurable W) (hF : Measurable F) {C Λ K : ℝ} + (hWC : ∀ p,|W p|≤C) (hF1 : ∀ p,1≤F p) (hΛ : 1≤Λ) + (hL2 : ∀ x, MemLp (fun p : G×T=>F (p.1,(x,p.2))) 2 (P.prod Q)) + (h2 : ∀ x, (∫ p : G×T,F (p.1,(x,p.2))^2 ∂P.prod Q)≤K) : + let D:=fun g=>Real.log (∫ x,Real.exp (W (g,x))*F (g,x) ∂μ.prod Q)- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ ∂μ.prod Q) + Integrable D P ∧ 0≤∫ g,D g ∂P ∧ + (∫ g,D g ∂P)≤Real.exp (2*C)/Λ*K := by + have h := cavity_residual_square_integrable μ P Q F hF K hL2 h2 + exact cavity_expected_cap_integrated (μ.prod Q) P W F hW hF hWC hF1 hΛ h.1 h.2 + + + +def cavityLabelCompletedMark (n d k : ℕ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) + (p : (ℕ→ℝ)×(IndexedLeaf k×EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) : + EuclideanSpace ℝ (Fin (n+1)⊕Fin d) := + WithLp.toLp 2 (fun i=>cavityCountableField (cavityLabelRow q) (cavityLabelLength k) p.1 p.2.1 i+σ i*p.2.2 i) + +lemma cavityLabelCompletedMark_measurable (n d k : ℕ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) : + Measurable (cavityLabelCompletedMark n d k σ q) := by + have hf : Measurable (fun p : (ℕ→ℝ)×IndexedLeaf k=> + cavityCountableField (cavityLabelRow q) (cavityLabelLength k) p.1 p.2) := + cavityCountableField_measurable (cavityLabelRow q) (cavityLabelLength k) + (cavityLabelRow_measurable q) (cavityLabelLength_measurable k) + have hp : Measurable (fun p : (ℕ→ℝ)×(IndexedLeaf k×EuclideanSpace ℝ (Fin (n+1)⊕Fin d))=> + (p.1,p.2.1)) := measurable_fst.prodMk measurable_snd.fst + have h := hf.comp hp + unfold cavityLabelCompletedMark + apply (MeasurableEquiv.toLp 2 _).measurable.comp + exact Measurable.of_eval fun coordinate=> ((measurable_pi_apply coordinate).comp + ((MeasurableEquiv.toLp 2 _).symm.measurable.comp h)).add + (measurable_const.mul ((measurable_pi_apply coordinate).comp + ((MeasurableEquiv.toLp 2 _).symm.measurable.comp measurable_snd.snd))) + +def cavityLabelSpherical (n d k : ℕ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) := + fun p=>sphericalExp n ((gaussianSumSplit (cavityLabelCompletedMark n d k σ q p)).1) (Real.sqrt (n+1:ℕ)) + +def cavityLabelWeight (n d k : ℕ) (f : ℝ→ᵇℝ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) := + fun p=>∑ i : Fin d,f (cavityLabelCompletedMark n d k σ q p (Sum.inr i)) + +lemma cavityLabelSpherical_measurable (n d k : ℕ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) : + Measurable (cavityLabelSpherical n d k σ q) := + (sphericalExp_continuous n _).measurable.comp + (gaussianSumSplit_measurable.fst.comp (cavityLabelCompletedMark_measurable n d k σ q)) + +lemma cavityLabelWeight_measurable (n d k : ℕ) (f : ℝ→ᵇℝ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) : + Measurable (cavityLabelWeight n d k f σ q) := by + apply Finset.measurable_sum + intro i hi + exact f.measurable.comp ((measurable_pi_apply (Sum.inr i)).comp + ((MeasurableEquiv.toLp 2 _).symm.measurable.comp (cavityLabelCompletedMark_measurable n d k σ q))) + +lemma cavityLabelWeight_bound (n d k : ℕ) (f : ℝ→ᵇℝ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) (p) : + |cavityLabelWeight n d k f σ q p|≤(d:ℝ)*‖f‖ := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ i : Fin d,‖f‖ := Finset.sum_le_sum fun _ _=>f.norm_coe_le_norm _ + _ = _ := by simp + +lemma cavityLabelSpherical_one (n d k : ℕ) + (σ : Fin (n+1)⊕Fin d→ℝ) (q : Fin (k+1)→(Fin (n+1)⊕Fin d)→ℝ) (p) : + 1≤cavityLabelSpherical n d k σ q p := one_le_sphericalExp n _ _ + +lemma cavityLabelSpherical_second (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (x : IndexedLeaf k) : + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i) + let F:=cavityLabelSpherical n d k σ (cavityPairProfile n d p) + let P:=countableGaussianLaw.prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + MemLp (fun y=>F (y.1,(x,y.2))) 2 P ∧ + (∫ y,F (y.1,(x,y.2))^2 ∂P)≤Real.exp (2*(n+1:ℕ)*D.2.val) := by + let V:=cavityCompletedCountableVector n (cavityLabelRow (cavityPairProfile n d p)) + (cavityLabelLength k) (fun _=>Real.sqrt (D.2.val-(p (Fin.last k)).2.val)) + (fun i=>(x,Sum.inl i)) + let R:=Real.sqrt (n+1:ℕ) + have h := cavityLabelVector_second_moment n d p D hp0 hpm hpD x R + let T : (ℕ→ℝ)×EuclideanSpace ℝ (Fin (n+1)⊕Fin d)→(ℕ→ℝ)×Spin (n+1) := + fun y=>(y.1,(gaussianSumSplit y.2).1) + have hp : MeasurePreserving T + (countableGaussianLaw.prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d)))) + (countableGaussianLaw.prod (stdGaussian (Spin (n+1)))) := + (MeasurePreserving.id _).prod (measurePreserving_fst.comp gaussianSumSplit_preserving) + change MemLp ((fun y=>sphericalExp n (V y) R) ∘ T) 2 _ ∧ _ + refine ⟨h.1.comp_measurePreserving hp,?_⟩ + have hm : Measurable (fun y=>sphericalExp n (V y) R^2) := + ((sphericalExp_continuous n R).measurable.comp + (cavityCompletedCountableVector_measurable n _ _ _ _)).pow_const 2 + change (∫ y,(sphericalExp n (V (T y)) R)^2 ∂_)≤_ + rw [←integral_map hp.measurable.aemeasurable hm.aestronglyMeasurable,hp.map_eq] + simpa only [R,Real.sq_sqrt (by positivity : 0≤((n+1:ℕ):ℝ))] using h.2 + +theorem cavityLabel_cap_error (n d : ℕ) {K : ℝ} {k : ℕ} + (p : Fin (k+1)→BulkPairRange K) (D : BulkPairRange K) + (hp0 : ∀ i,0≤cavityPairProfile n d p 0 i) + (hpm : ∀ i,Monotone (fun l=>cavityPairProfile n d p l i)) + (hpD : ∀ i,cavityPairProfile n d p (Fin.last k) i≤cavityPairDiagonal n d D i) + (f : ℝ→ᵇℝ) (b : IndexedCascadeBase k) {Λ : ℝ} (hΛ : 1≤Λ) : + let σ:=fun i=>Real.sqrt (cavityPairDiagonal n d D i-cavityPairProfile n d p (Fin.last k) i) + let F:=cavityLabelSpherical n d k σ (cavityPairProfile n d p) + let W:=cavityLabelWeight n d k f σ (cavityPairProfile n d p) + let Q:=(indexedLeafProbability k b).prod (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) + let E:=fun g=>Real.log (∫ x,Real.exp (W (g,x))*F (g,x) ∂Q)- + Real.log (∫ x,Real.exp (W (g,x))*min (F (g,x)) Λ ∂Q) + Integrable E countableGaussianLaw ∧ 0≤∫ g,E g ∂countableGaussianLaw ∧ + (∫ g,E g ∂countableGaussianLaw)≤ + Real.exp (2*((d:ℝ)*‖f‖))/Λ*Real.exp (2*(n+1:ℕ)*D.2.val) := by + dsimp only + exact cavity_expected_cap_residual (indexedLeafProbability k b) countableGaussianLaw + (stdGaussian (EuclideanSpace ℝ (Fin (n+1)⊕Fin d))) _ _ + (cavityLabelWeight_measurable n d k f _ _) (cavityLabelSpherical_measurable n d k _ _) + (cavityLabelWeight_bound n d k f _ _) (cavityLabelSpherical_one n d k _ _) hΛ + (fun x=>(cavityLabelSpherical_second n d p D hp0 hpm hpD x).1) + (fun x=>(cavityLabelSpherical_second n d p D hp0 hpm hpD x).2) +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityRoundedLower.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityRoundedLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..afb892edc7d032ef5eecf1f9f427245ecee00879 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityRoundedLower.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityApproxStationary +import OAI.Probability.Perceptron.Variational.CappedAContinuity +import OAI.Probability.Perceptron.Cavity.BulkCavityRecursion + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators NNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def cavityProfileMoment (η : Measure Time) (B : ℝ) : ℝ := + ∫ r : Time,(r:ℝ)*cappedA η B r/2 ∂η + +def roundedProfileMoment (η : Measure Time) [IsProbabilityMeasure η] (B : ℝ) (j : ℕ) : ℝ := + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + let M:=strictRoundModel F j + ∑ i,M.weight i*(cappedA η B (roundTimeValue F j i)/2)*(roundTimeValue F j i:ℝ) + +lemma roundedProfileMoment_tendsto (η : Measure Time) [IsProbabilityMeasure η] + {B : ℝ} (hB : B<1) : + Tendsto (roundedProfileMoment η B) atTop (𝓝 (cavityProfileMoment η B)) := by + let G : Time→ᵇℝ:=ContinuousMap.equivBoundedOfCompact Time ℝ + ⟨fun r=>(r:ℝ)*cappedA η B r/2,by exact + (continuous_subtype_val.mul ((cappedA_continuous η hB).comp continuous_subtype_val)).div_const 2⟩ + have h:=ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mp (quantileRoundLaw_tendsto η) G + have he j : (∫ r,G r ∂(quantileRoundLaw η j : Measure Time))=roundedProfileMoment η B j := by + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + change (∫ r : Time,(r:ℝ)*cappedA η B r/2 ∂timeLaw.map (roundTime F j))=_ + rw [integral_map (roundTime_mono F j).measurable.aemeasurable (by + exact ((continuous_subtype_val.mul ((cappedA_continuous η hB).comp continuous_subtype_val)).div_const 2).measurable.aestronglyMeasurable)] + change (∫ u,(roundTime F j u:ℝ)*cappedA η B (roundTime F j u)/2 ∂timeLaw)=_ + have hv:=(strictRoundModel F j).integral (fun r=>r*cappedA η B r/2) + change (∫ u,(roundTime F j u:ℝ)*cappedA η B (roundTime F j u)/2 ∂timeLaw)=_ at hv + rw [hv] + apply Finset.sum_congr rfl + intro i _ + dsimp [roundedProfileMoment,roundTimeValue,F] + ring + simp_rw [he] at h + convert h using 1 + rfl + +lemma roundedCavityValue_lower (P : Measure BrownianPath) [IsProbabilityMeasure P] + {α : ℝ} (hα : 0≤α) (g : Jet3) (n d : ℕ) + (η : Measure Time) [IsProbabilityMeasure η] {B K a ε : ℝ} + (hB : B<1) (ha0 : 0≤a) (haK : a≤K) + (hη : ∀ᵐ r : Time ∂η,(r:ℝ)≤B) (hA : ∀ᵐ r : Time ∂η,cappedA η B r≤a) + (hdα : |(d:ℝ)-(n+1:ℕ)*α|≤1) + (hdim : ∀ k (w h : Fin (k+1)→ℝ) (hw : ∀ i,0(hw i).le) hw1)|<ε) + (j : ℕ) : + (n+1:ℕ)*(a/2+(terminalVariational P α g.f).toReal-roundedProfileMoment η B j- + cappedAError (quantileRoundLaw η j) η B-ε)-‖g.f‖ ≤ + roundedCavityValue n d g P η B ha0 haK j := by + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + let M:=strictRoundModel F j + let q:=roundTimeValue F j + let h:=fun i=>cappedA η B (q i)/2 + let h':=fun i=>cappedA (quantileRoundLaw η j) B (q i)/2 + have hh : Monotone h:=fun i l hil=>div_le_div_of_nonneg_right + ((cappedA_monotone η hB) (roundTimeValue_mono F j hil)) (by norm_num) + have hh' : Monotone h':=fun i l hil=>div_le_div_of_nonneg_right + ((cappedA_monotone (quantileRoundLaw η j) hB) (roundTimeValue_mono F j hil)) (by norm_num) + have hh0 : 0≤h 0:=div_nonneg (cappedA_nonneg η B (q 0).prop.1) (by norm_num) + have hh'0 : 0≤h' 0:=div_nonneg (cappedA_nonneg (quantileRoundLaw η j) B (q 0).prop.1) (by norm_num) + have hp i : (roundedCavityPair η B ha0 haK j i).2.val=cappedA η B (q i) := + roundTimeValue_profile_exact η hB ha0 haK hA j i + have htop : h (Fin.last M.depth)≤K/2 := by + apply div_le_div_of_nonneg_right _ (by norm_num) + rw [←hp] + exact ((roundedCavityPair η B ha0 haK j _).2.prop.2) + have hq1 : (q (Fin.last M.depth):ℝ)<1:= + (roundTimeValue_support η hη j _).trans_lt hB + have hs i : 2*h' i=weightedStepA M.weight (fun l=>(q l:ℝ)) (q i) := by + dsimp [h']; rw [mul_div_cancel₀ _ (by norm_num : (2:ℝ)≠0)] + exact quantileRoundLaw_stationary η hη j i + have hd i : |h i-h' i|≤cappedAError (quantileRoundLaw η j) η B/2 := by + dsimp [h,h'] + rw [←sub_div,abs_div,abs_of_pos (by norm_num : (0:ℝ)<2),abs_sub_comm] + exact div_le_div_of_nonneg_right (cappedA_sub_bound (quantileRoundLaw η j) η hB (q i)) (by norm_num) + have hlow:=finiteCavity_trial_lower P hα g.f n d M.weight h h' q M.weight_pos M.weight_sum hh hh0 hh' hh'0 + (roundTimeValue_mono F j) hq1 hs + (div_nonneg (cappedAError_nonneg _ _ _) (by norm_num)) hd + (hdim _ _ _ M.weight_pos M.weight_sum hh hh0 htop) hdα (a:=a) + have herr : 2*(cappedAError (quantileRoundLaw η j) η B/2)=cappedAError (quantileRoundLaw η j) η B:=by ring + rw [herr] at hlow + unfold roundedCavityValue + simp_rw [hp] + exact hlow + + +lemma markedTimePair_eq_map (K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) : + markedTimePair K μ=(μ : Measure (CompactArray (BulkPairRange K))).map + (fun Q=>nonnegativeSpinTime (Q 0 1).1) := by + change Measure.map (fun Q : CompactArray Time=>Q 0 1) + (Measure.map (compactMapArray (fun p : BulkPairRange K=>nonnegativeSpinTime p.1)) (μ : Measure _))=_ + rw [Measure.map_map (by fun_prop) (by + exact (compactMapArray_continuous (nonnegativeSpinTime_continuous.comp continuous_fst)).measurable)] + rfl + +lemma marked_cappedA_identification {K B a : ℝ} + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hB : B<1) + (hn : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),0≤(Q 0 1).1.val) + (hBd : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),(Q 0 1).2.val≤a) + (f : ℝ→ℝ) + (hg : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),(Q 0 1).2.val=f (Q 0 1).1.val) + (hsc : ∀ᵐ r : Time ∂markedTimePair K μ,f r=∫ t in 0..(r:ℝ),(realTail (markedTimePair K μ) t)⁻¹^2) + (hbound : ∀ᵐ r : Time ∂markedTimePair K μ,(r:ℝ)≤B) : + (∀ᵐ r : Time ∂markedTimePair K μ,cappedA (markedTimePair K μ) B r≤a) ∧ + cavityProfileMoment (markedTimePair K μ) B= + (∫ Q,(Q 0 1).1.val*(Q 0 1).2.val ∂(μ : Measure (CompactArray (BulkPairRange K))))/2 := by + let e:=fun Q : CompactArray (BulkPairRange K)=>nonnegativeSpinTime (Q 0 1).1 + have he : Measurable e:=(nonnegativeSpinTime_continuous.comp (by fun_prop)).measurable + have hid : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), + cappedA (markedTimePair K μ) B (e Q)=(Q 0 1).2.val := by + filter_upwards [markedTimePair_ae μ hsc,markedTimePair_ae μ hbound,hn,hg] with Q hS hBd hN hG + rw [cappedA_eq_integral (markedTimePair K μ) hbound (e Q).prop.1 hBd,←hS] + rw [nonnegativeSpinTime_val hN] + exact hG.symm + have hmap : (μ : Measure (CompactArray (BulkPairRange K))).map e=markedTimePair K μ := + (markedTimePair_eq_map K μ).symm + constructor + · have hh : ∀ᵐ r : Time ∂(μ : Measure _).map e,cappedA (markedTimePair K μ) B r≤a := by + apply (ae_map_iff he.aemeasurable (measurableSet_le + (((cappedA_continuous (markedTimePair K μ) hB).comp continuous_subtype_val).measurable) + measurable_const)).mpr + filter_upwards [hid,hBd] with Q hQ hBnd + change cappedA (markedTimePair K μ) B (e Q)≤a + rwa [hQ] + rwa [hmap] at hh + · have hi:=integral_map he.aemeasurable + (show AEStronglyMeasurable (fun r : Time=>(r:ℝ)*cappedA (markedTimePair K μ) B r/2) + ((μ : Measure _).map e) from + ((continuous_subtype_val.mul ((cappedA_continuous (markedTimePair K μ) hB).comp + continuous_subtype_val)).div_const 2).measurable.aestronglyMeasurable) + rw [hmap] at hi + unfold cavityProfileMoment + rw [hi,←integral_div] + apply integral_congr_ae + filter_upwards [hid,hn] with Q hQ hN + rw [hQ,nonnegativeSpinTime_val hN] +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityShellExpansion.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityShellExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..02cce5640ac35b5d4e7827ce5b2c0789b36452e3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityShellExpansion.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityUniformRemainder +import OAI.Probability.Perceptron.Cavity.CavitySphericalMoments +import OAI.Probability.Perceptron.Cavity.CavityShellPerturbation + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction + +def cavityJoinedPatterns (N L M : ℕ) (a : Fin M→Fin N→ℝ) (y : Fin M→Spin L) : + Fin M→Fin (N+L)→ℝ := fun i=>Fin.addCases (a i) (fun j=>y i j) + +lemma cavityJoinedPatterns_projection (N L M : ℕ) (a : Fin M→Fin N→ℝ) + (y : Fin M→Spin L) (x : NormalizedSpin N) (z : Spin L) (i : Fin M) : + (∑ j,cavityJoinedPatterns N L M a y i j*cavityNormalizedVec N L x z j)= + cavityRho N L z*(∑ j,a i j*x.val j)+inner ℝ z (y i)/Real.sqrt (N+L:ℕ) := by + rw [Fin.sum_univ_add] + simp only [cavityJoinedPatterns,cavityNormalizedVec,gaussianBlockJoin,PiLp.toLp_apply, + Fin.addCases_left,Fin.addCases_right,PiLp.smul_apply,smul_eq_mul] + simp only [EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial] + rw [Finset.mul_sum,Finset.sum_div] + apply congrArg₂ (·+·) + · apply Finset.sum_congr rfl + intro j _hj + ring + · apply Finset.sum_congr rfl + intro j _hj + ring + +lemma cavityShellPatternEnergy_join (n L M : ℕ) (f : ℝ→ᵇℝ) + (a : Fin M→Fin (n+1)→ℝ) (y : Fin M→Spin L) (s : CavityShellSpin n L) : + cavityShellPatternEnergy n L M f (cavityJoinedPatterns (n+1) L M a y) s= + ∑ i,f (Real.sqrt (1-‖s.2.val‖^2/((n+1:ℕ)+L))*(∑ j,a i j*s.1.val j)+ + inner ℝ s.2.val (y i)/Real.sqrt ((n+1:ℕ)+L)) := by + unfold cavityShellPatternEnergy normalizedPatternEnergy + apply Finset.sum_congr rfl + intro i _hi + congr 1 + change (∑ j,cavityJoinedPatterns (n+1) L M a y i j*cavityNormalizedVec (n+1) L s.1 s.2.val j)=_ + rw [cavityJoinedPatterns_projection] + simp only [cavityRho,Nat.cast_add] + +def cavityShellTaylorModel (n L M : ℕ) (f : Jet3) (a : Fin M→Fin (n+1)→ℝ) + (y : Fin M→Spin L) (s : CavityShellSpin n L) : ℝ := + normalizedPatternEnergy (n+1) M f.f a s.1+ + (cavityLinearField M L (fun i=>f.d1 (∑ j,a i j*s.1.val j)) + (Real.sqrt (n+1:ℕ))⁻¹ s.2.val y+ + ‖s.2.val‖^2/2*bulkC (n+1) M f a s.1+ + cavityQuadraticField M L (fun i=>f.d2 (∑ j,a i j*s.1.val j)) + (1/(2*(n+1:ℕ))) s.2.val y) + +theorem cavity_true_shell_expansion (n L M : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) (hn : 2*(L+1)≤n+1) + (a : Fin M→Fin (n+1)→ℝ) (y : Fin M→Spin L) (s : CavityShellSpin n L) : + |cavityShellPatternEnergy n L M f.f (cavityJoinedPatterns (n+1) L M a y) s- + cavityShellTaylorModel n L M f a y s|≤ + ∑ i,cavityRemainderMajorant (cavityRemainderCoefficients f h1 h2 h3 L (L+1)) (n+1:ℕ) ‖y i‖ := by + have hnR : (2:ℝ)*((L:ℝ)+1)≤(n+1:ℕ) := by exact_mod_cast hn + have hz : ‖s.2.val‖^2≤(L:ℝ)+1:=s.2.prop.2 + have hρ : ‖s.2.val‖^2<(n+1:ℕ)+L := by nlinarith [Nat.cast_nonneg (α:=ℝ) L] + rw [cavityShellPatternEnergy_join] + change |(∑ i,_) - (_+_)|≤_ + rw [←sub_sub] + exact (cavity_pattern_sum_expansion n M L f h1 h2 h3 a s.1 s.2.val y hρ).trans + (Finset.sum_le_sum fun i _hi=>cavityTaylorError_inner_le f h1 h2 h3 L (by positivity) + (by positivity) hnR s.2.val (y i) hz) + +lemma cavity_true_shell_error_tendsto (M : ℕ→ℕ) (L : ℕ) (f : Jet3) + (h1 : HasCompactSupport (f.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (f.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (f.d3 : ℝ→ℝ)) {α : ℝ} + (hM : Tendsto (fun n=>(M n:ℝ)/(n+1:ℕ)) atTop (𝓝 α)) : + Tendsto (fun n=>∫ y : Fin (M n)→Spin L, + ∑ i,cavityRemainderMajorant (cavityRemainderCoefficients f h1 h2 h3 L (L+1)) (n+1:ℕ) ‖y i‖ + ∂Measure.pi (fun _=>stdGaussian (Spin L))) atTop (𝓝 0) := + cavityRemainderMajorant_row_tendsto M L _ hM + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussianRows_basis (n : ℕ) (σ : ℝ) (y : Spin (n+1)) : + gaussianRows (fun i : Fin (n+1)=>σ • EuclideanSpace.single i (1:ℝ)) y=σ •y := by + ext i + simp [gaussianRows_apply,real_inner_smul_left,EuclideanSpace.inner_single_left] + +lemma gaussianRows_isotropic_law (n : ℕ) (v : Fin (n+1)→E) {b : ℝ} (hb : 0≤b) + (hv : ∀ i j,inner ℝ (v i) (v j)=if i=j then b else 0) : + (stdGaussian E).map (gaussianRows v)= + (stdGaussian (Spin (n+1))).map (fun y=>Real.sqrt b •y) := by + have hg : Matrix.gram ℝ v=Matrix.gram ℝ (fun i : Fin (n+1)=>Real.sqrt b • EuclideanSpace.single i (1:ℝ)) := by + ext i j + simp only [Matrix.gram_apply,hv,inner_smul_left,inner_smul_right,conj_trivial] + by_cases h : i=j + · subst j + simp [Real.sq_sqrt hb,←pow_two] + · simp [EuclideanSpace.inner_single_left,h] + rw [gaussianRows_map_stdGaussian,hg,←gaussianRows_map_stdGaussian] + congr 1 + funext y + exact gaussianRows_basis n (Real.sqrt b) y + +lemma gaussianRows_spherical_average (n : ℕ) (v : Fin (n+1)→E) {b : ℝ} (hb : 0≤b) + (hv : ∀ i j,inner ℝ (v i) (v j)=if i=j then b else 0) (R : ℝ) : + (∫ g,sphericalExp n (gaussianRows v g) R ∂stdGaussian E)=Real.exp (R^2*b/2) := by + rw [←integral_map (gaussianRows v).measurable.aemeasurable + (sphericalExp_continuous n R).aestronglyMeasurable,gaussianRows_isotropic_law n v hb hv, + integral_map (by fun_prop) (sphericalExp_continuous n R).aestronglyMeasurable] + have h:=sphericalExp_gaussian_average n R (Real.sqrt b) 0 + have hz : sphericalExp n 0 R=1 := by simp [sphericalExp] + simpa only [zero_add,Real.sq_sqrt hb,hz,mul_one] using h + +lemma gaussianRows_spherical_memLp (n : ℕ) (v : Fin (n+1)→E) {b : ℝ} (hb : 0≤b) + (hv : ∀ i j,inner ℝ (v i) (v j)=if i=j then b else 0) (R : ℝ) : + MemLp (fun g=>sphericalExp n (gaussianRows v g) R) 2 (stdGaussian E) := by + have hm := (sphericalExp_continuous n R).comp (gaussianRows v).continuous + apply (memLp_two_iff_integrable_sq hm.aestronglyMeasurable).mpr + have hi : Integrable (fun g=>sphericalExp n (gaussianRows v g) (2*R)) (stdGaussian E) := by + by_contra hn + have h:=gaussianRows_spherical_average n v hb hv (2*R) + rw [integral_undef hn] at h + exact (Real.exp_pos _).ne' h.symm + apply hi.mono' (hm.pow 2).aestronglyMeasurable + filter_upwards [] with g + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + exact sphericalExp_square_le n R _ + +lemma gaussianRows_spherical_second (n : ℕ) (v : Fin (n+1)→E) {b : ℝ} (hb : 0≤b) + (hv : ∀ i j,inner ℝ (v i) (v j)=if i=j then b else 0) (R : ℝ) : + (∫ g,sphericalExp n (gaussianRows v g) R^2 ∂stdGaussian E)≤Real.exp (2*R^2*b) := by + have hs := (memLp_two_iff_integrable_sq + ((gaussianRows_spherical_memLp n v hb hv R).aestronglyMeasurable)).mp + (gaussianRows_spherical_memLp n v hb hv R) + have hi := (gaussianRows_spherical_memLp n v hb hv (2*R)).integrable (by norm_num) + apply (integral_mono hs hi (fun g=>sphericalExp_square_le n R _)).trans_eq + rw [gaussianRows_spherical_average n v hb hv] + congr 1 + ring +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityShellLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityShellLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..a4e2b707eacbf48f3fbcf939f14d90e5ebdde364 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityShellLimit.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityDisintegration + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction + +lemma countableGaussian_prefix_preserving (n : ℕ) : + MeasurePreserving (fun g=>WithLp.toLp 2 (gaussianCoordinatePrefix n g)) + countableGaussianLaw (stdGaussian (Spin n)) := + (show MeasurePreserving (WithLp.toLp 2 : (Fin n→ℝ)→Spin n) + (Measure.pi fun _=>gaussianReal 0 1) (stdGaussian (Spin n)) from + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩).comp + (gaussianCoordinatePrefix_measurePreserving n) + +lemma countableGaussian_prefix_norm (n : ℕ) (g : ℕ→ℝ) : + ‖WithLp.toLp 2 (gaussianCoordinatePrefix n g)‖^2=∑ i∈Finset.range n,(g i)^2 := by + simp only [EuclideanSpace.norm_sq_eq,gaussianCoordinatePrefix,Real.norm_eq_abs,sq_abs] + exact Fin.sum_univ_eq_sum_range (fun i=>(g i)^2) n + +def cavitySphereLaw (n L : ℕ) : ProbabilityMeasure (Spin L) := by + let : IsProbabilityMeasure (unitSphereLaw (n+1+L)) := by + have he : n+1+L=(n+L)+1 := by omega + rw [he] + infer_instance + exact ⟨(unitSphereLaw (n+1+L)).map (fun u=>Real.sqrt (n+1+L:ℕ) • + (gaussianBlockSplit (n+1) L u.val).2), inferInstance⟩ + +def cavityCoupledBlock (n L : ℕ) (p : (ℕ→ℝ)×Spin L) : Spin L := + cavityCoupledScale n L p.1 p.2 •p.2 + +lemma cavityCoupledBlock_measurable (n L : ℕ) : Measurable (cavityCoupledBlock n L) := + (cavityCoupledScale_measurable n L).smul measurable_snd + +lemma cavitySphereLaw_coupled (n L : ℕ) : + (cavitySphereLaw n L : Measure (Spin L))= + (countableGaussianLaw.prod (stdGaussian (Spin L))).map (cavityCoupledBlock n L) := by + have hp := (countableGaussian_prefix_preserving (n+1)).prod + (MeasurePreserving.id (stdGaussian (Spin L))) + have h := congrArg (fun μ : Measure (Spin (n+1)×Spin L)=> + μ.map (fun p=>Real.sqrt (n+1+L:ℕ) •p.2)) (sphereBlock_gaussian_law n L) + rw [Measure.map_map (by fun_prop) (show Measurable (fun u : Metric.sphere (0 : Spin (n+1+L)) 1 => gaussianBlockSplit (n+1) L u.val) from (gaussianBlockSplit_measurable (n+1) L).comp measurable_subtype_coe), + Measure.map_map (by fun_prop) (cavityBlockNormalize_measurable _ _)] at h + simp only [Function.comp_def] at h + change (unitSphereLaw (n+1+L)).map _ = _ + rw [h,←hp.map_eq,Measure.map_map (by unfold cavityBlockNormalize; fun_prop) hp.measurable] + congr 1 + funext p + simp only [Function.comp_def,cavityBlockNormalize,cavityCoupledBlock,cavityCoupledScale, + smul_smul,div_eq_mul_inv,Prod.map_fst,Prod.map_snd,id_eq] + rw [countableGaussian_prefix_norm] + +lemma cavityCoupledBlock_tendsto_ae (L : ℕ) : + ∀ᵐ p ∂countableGaussianLaw.prod (stdGaussian (Spin L)), + Tendsto (fun n=>cavityCoupledBlock n L p) atTop (𝓝 p.2) := by + have hf : ∀ᵐ p ∂countableGaussianLaw.prod (stdGaussian (Spin L)), + Tendsto (fun n : ℕ=>(∑ i∈Finset.range n,(p.1 i)^2)/(n:ℝ)) atTop (𝓝 1) := + (measurePreserving_fst (μ:=countableGaussianLaw) (ν:=stdGaussian (Spin L))).quasiMeasurePreserving.ae + countableGaussian_square_strongLaw + filter_upwards [hf] with p hp + simpa only [one_smul,cavityCoupledBlock] using (cavityCoupledScale_tendsto L p.1 p.2 hp).smul + (tendsto_const_nhds (x:=p.2)) + +def cavityGaussianLaw (L : ℕ) : ProbabilityMeasure (Spin L) := ⟨stdGaussian (Spin L),inferInstance⟩ + +theorem cavitySphereLaw_tendsto (L : ℕ) : + Tendsto (fun n=>cavitySphereLaw n L) atTop (𝓝 (cavityGaussianLaw L)) := by + apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr + intro F + have he n : (∫ z,F z ∂(cavitySphereLaw n L : Measure (Spin L)))= + ∫ p,F (cavityCoupledBlock n L p) ∂countableGaussianLaw.prod (stdGaussian (Spin L)) := by + rw [cavitySphereLaw_coupled,integral_map (cavityCoupledBlock_measurable n L).aemeasurable F.continuous.aestronglyMeasurable] + have he0 : (∫ z,F z ∂(cavityGaussianLaw L : Measure (Spin L)))= + ∫ p : (ℕ→ℝ)×Spin L,F p.2 ∂countableGaussianLaw.prod (stdGaussian (Spin L)) := by + symm + rw [←integral_map measurable_snd.aemeasurable F.continuous.aestronglyMeasurable, + Measure.map_snd_prod,measure_univ,one_smul] + rfl + simp_rw [he,he0] + apply tendsto_integral_of_dominated_convergence (fun _=>‖F‖) + (fun n=>(F.measurable.comp (cavityCoupledBlock_measurable n L)).aestronglyMeasurable) + (integrable_const ‖F‖) + · intro n + exact ae_of_all _ fun p=>F.norm_coe_le_norm _ + · filter_upwards [cavityCoupledBlock_tendsto_ae L] with p hp + exact F.continuous.continuousAt.tendsto.comp hp + +def cavityShell (L : ℕ) : Set (Spin L) := {z | (L:ℝ)≤‖z‖^2 ∧ ‖z‖^2≤L+1} + +lemma cavityShell_measurable (L : ℕ) : MeasurableSet (cavityShell L) := by + exact (isClosed_Icc.preimage (show Continuous (fun z : Spin L=>‖z‖^2) from continuous_norm.pow 2)).measurableSet + +lemma stdGaussian_sphere_null (k : ℕ) (r : ℝ) : + stdGaussian (Spin (k+1)) (Metric.sphere 0 r)=0 := by + rw [←canonicalRadialMass_eq_stdGaussian] + exact withDensity_absolutelyContinuous _ _ (Measure.addHaar_sphere volume 0 r) + +lemma cavityShell_frontier_null (k : ℕ) : + stdGaussian (Spin (k+1)) (frontier (cavityShell (k+1)))=0 := by + have hs : frontier (cavityShell (k+1)) ⊆ + Metric.sphere 0 (Real.sqrt (k+1:ℕ)) ∪ Metric.sphere 0 (Real.sqrt ((k+1:ℕ)+1)) := by + intro z hz + have h := (continuous_norm.pow 2).frontier_preimage_subset (Icc ((k+1:ℕ):ℝ) ((k+1:ℕ)+1)) hz + rw [frontier_Icc (by linarith)] at h + simp only [mem_preimage,mem_insert_iff,mem_singleton_iff,Pi.pow_apply] at h + rcases h with h|h + · left + simp only [Metric.mem_sphere,dist_zero_right,←h,Real.sqrt_sq (norm_nonneg z)] + · right + simp only [Metric.mem_sphere,dist_zero_right,←h,Real.sqrt_sq (norm_nonneg z)] + apply measure_mono_null hs + rw [measure_union_null (stdGaussian_sphere_null k _) (stdGaussian_sphere_null k _)] + +lemma stdGaussian_open_pos (k : ℕ) {U : Set (Spin (k+1))} (ho : IsOpen U) (hn : U.Nonempty) : + 0ne_of_gt (ENNReal.ofReal_pos.mpr (canonicalRadialDensity_pos k 1 x)) + exact pos_iff_ne_zero.mpr (fun h=>ne_of_gt (ho.measure_pos volume hn) (ha h)) + +def cavityShellMass (k : ℕ) : ℝ := (stdGaussian (Spin (k+1))).real (cavityShell (k+1)) + +lemma cavityShellMass_pos (k : ℕ) : 0 linarith⟩ + have ho : IsOpen {z : Spin (k+1) | (k+1:ℕ)<‖z‖^2 ∧ ‖z‖^2<(k+1:ℕ)+1} := + (isOpen_lt continuous_const (continuous_norm.pow 2)).inter (isOpen_lt (continuous_norm.pow 2) continuous_const) + have hp := (stdGaussian_open_pos k ho hu).trans_le (measure_mono (show + {z : Spin (k+1) | (k+1:ℕ)<‖z‖^2 ∧ ‖z‖^2<(k+1:ℕ)+1} ⊆ cavityShell (k+1) from fun z hz=>⟨hz.1.le,hz.2.le⟩)) + exact ENNReal.toReal_pos hp.ne' (measure_ne_top _ _) + +lemma cavityShellMass_le_one (k : ℕ) : cavityShellMass k≤1 := by + exact measureReal_le_one + +lemma cavitySphereLaw_shell_tendsto (k : ℕ) : + Tendsto (fun n=>(cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1))) atTop (𝓝 (cavityShellMass k)) := by + exact (ENNReal.tendsto_toReal (measure_ne_top _ _)).comp + (ProbabilityMeasure.tendsto_measure_of_null_frontier_of_tendsto' + (cavitySphereLaw_tendsto (k+1)) (cavityShell_frontier_null k)) + +lemma cavitySphereLaw_shell_log_tendsto (k : ℕ) : + Tendsto (fun n=>Real.log ((cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1)))) atTop (𝓝 (Real.log (cavityShellMass k))) := + (cavitySphereLaw_shell_tendsto k).log (cavityShellMass_pos k).ne' + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityShellPerturbation.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityShellPerturbation.lean new file mode 100644 index 0000000000000000000000000000000000000000..8597c6bdbc541e12b12ee3e3b9befdd33c7c72e3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityShellPerturbation.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityShellLimit +import OAI.Probability.Perceptron.Cavity.CavityGeometry + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators ENNReal BoundedContinuousFunction + +abbrev CavityShellSpin (n L : ℕ) := NormalizedSpin (n+1) × {z : Spin L // z∈cavityShell L} + +def cavityShellFeature (n L : ℕ) (v : ℕ→ℝ) (s : CavityShellSpin n L) : BulkMark (n+1+L) := + ambientBulkFeature (n+1+L) v (cavityNormalizedVec (n+1) L s.1 s.2.val) + +lemma cavityRho_measurable (N L : ℕ) : Measurable (cavityRho N L) := by + unfold cavityRho + fun_prop + +lemma cavityNormalizedVec_measurable (N L : ℕ) : + Measurable (fun p : NormalizedSpin N×Spin L=>cavityNormalizedVec N L p.1 p.2) := by + unfold cavityNormalizedVec + apply (gaussianBlockJoin_measurable N L).comp + exact (((cavityRho_measurable N L).comp measurable_snd).smul measurable_fst.subtype_val).prodMk + (measurable_snd.const_smul ((Real.sqrt (N+L:ℕ))⁻¹)) + +lemma ambientBulkFeature_measurable_comp {S : Type*} [MeasurableSpace S] + (N : ℕ) (v : ℕ→ℝ) {u : S→Spin N} (hu : Measurable u) : + Measurable (fun s=>ambientBulkFeature N v (u s)) := + (ambientBulkFeature_contDiff N v).continuous.measurable.comp hu + +lemma cavityShellFeature_measurable (n L : ℕ) (v : ℕ→ℝ) : + Measurable (cavityShellFeature n L v) := by + unfold cavityShellFeature + apply ambientBulkFeature_measurable_comp + exact (cavityNormalizedVec_measurable (n+1) L).comp + (f:=fun s : CavityShellSpin n L=>(s.1,s.2.val)) + (measurable_fst.prodMk measurable_snd.subtype_val) + +lemma cavityShellFeature_norm (n L : ℕ) (v : ℕ→ℝ) (s : CavityShellSpin n L) : + ‖cavityShellFeature n L v s‖=bulkFeatureBound (n+1+L) v := by + have hz : ‖s.2.val‖^2≤(n+1+L:ℕ) := s.2.prop.2.trans (by + push_cast + linarith [Nat.cast_nonneg (α:=ℝ) n]) + let u : NormalizedSpin (n+1+L) := ⟨cavityNormalizedVec (n+1) L s.1 s.2.val,by + simpa only [Metric.mem_sphere,dist_zero_right] using + cavityNormalizedVec_norm _ _ s.1 s.2.val (by omega) hz⟩ + change ‖ambientBulkFeature _ v u.val‖=_ + rw [ambientBulkFeature_eq,bulkFeature_norm] + +theorem cavity_shell_perturbation_comparison (n L : ℕ) (v : ℕ→ℝ) + (μ : Measure (CavityShellSpin n L)) [IsProbabilityMeasure μ] + {H : CavityShellSpin n L→ℝ} (hH : Measurable H) + {A C : ℝ} (hA : 0≤A) (hC : 0≤C) (hHA : ∀ s,|H s|≤A) + (hv : ∀ j,|v (j+1)|≤C) : + |(∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (cavityShellFeature n L v s) g) 1) + ∂stdGaussian (BulkMark (n+1+L)))- + ∫ g,Real.log (tiltPartition μ (fun s=>H s+inner ℝ (bulkFeature (n+1) v s.1) g) 1) + ∂stdGaussian (BulkMark (n+1))|≤ + Real.pi*cavityBulkCovarianceError n L C (3*((L:ℝ)+1)) := by + let B := bulkFeatureBound (n+1) v+bulkFeatureBound (n+1+L) v + have hB1 : 0≤bulkFeatureBound (n+1) v := Real.sqrt_nonneg _ + have hB2 : 0≤bulkFeatureBound (n+1+L) v := Real.sqrt_nonneg _ + apply independentGaussian_covariance_comparison μ hH + ((bulkFeature_continuous (n+1) v).measurable.comp measurable_fst) + (cavityShellFeature_measurable n L v) hA + (C:=B) (by dsimp [B]; positivity) hHA + · intro s + simp only [Function.comp_apply,bulkFeature_norm] + exact le_add_of_nonneg_right hB2 + · intro s + rw [cavityShellFeature_norm] + exact le_add_of_nonneg_left hB1 + · exact cavityBulkCovarianceError_nonneg _ _ _ (by positivity) + · intro x y + exact cavityNormalizedVec_covariance n L v C hC hv x.1 y.1 x.2.val y.2.val x.2.prop.2 y.2.prop.2 + +lemma cavity_shell_perturbation_error_tendsto (L : ℕ) (C : ℝ) : + Tendsto (fun n=>Real.pi*cavityBulkCovarianceError n L C (3*((L:ℝ)+1))) atTop (𝓝 0) := by + simpa only [mul_zero] using + (cavityBulkCovarianceError_tendsto L C (by positivity : 0≤3*((L:ℝ)+1))).const_mul Real.pi + +def cavityShellProbability (n L : ℕ) : Measure {z : Spin L // z∈cavityShell L} := + (cond (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)).comap Subtype.val + +lemma cavityShellProbability_probability (n L : ℕ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + IsProbabilityMeasure (cavityShellProbability n L) := by + let ν := (cavitySphereLaw n L : Measure (Spin L)) + let := cond_isProbabilityMeasure (μ:=ν) hp + apply (MeasurableEmbedding.subtype_coe (cavityShell_measurable L)).isProbabilityMeasure_comap + simp only [Subtype.range_coe] + apply (mem_ae_iff_prob_eq_one (cavityShell_measurable L)).mpr + exact cond_apply_self hp (measure_ne_top _ _) + +def cavityShellBaseLaw (n L : ℕ) : Measure (CavityShellSpin n L) := + (unitSphereLaw (n+1)).prod (cavityShellProbability n L) + +lemma cavityShellBaseLaw_probability (n L : ℕ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + IsProbabilityMeasure (cavityShellBaseLaw n L) := by + let := cavityShellProbability_probability n L hp + unfold cavityShellBaseLaw + infer_instance + +lemma cavityShell_probability_eventually (k : ℕ) : + ∀ᶠ n in atTop, (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0 := by + have he := (cavitySphereLaw_shell_tendsto k).eventually (lt_mem_nhds (cavityShellMass_pos k)) + filter_upwards [he] with n hn + exact ne_of_gt (ENNReal.toReal_pos_iff.mp hn).1 + +def cavityShellSpinEmbedding (n L : ℕ) (s : CavityShellSpin n L) : NormalizedSpin (n+1+L) := + ⟨cavityNormalizedVec (n+1) L s.1 s.2.val,by + have hz : ‖s.2.val‖^2≤(n+1+L:ℕ) := s.2.prop.2.trans (by + push_cast + linarith [Nat.cast_nonneg (α:=ℝ) n]) + simpa only [Metric.mem_sphere,dist_zero_right] using + cavityNormalizedVec_norm _ _ s.1 s.2.val (by omega) hz⟩ + +lemma cavityShellSpinEmbedding_measurable (n L : ℕ) : Measurable (cavityShellSpinEmbedding n L) := by + apply Measurable.subtype_mk + exact (cavityNormalizedVec_measurable (n+1) L).comp + (f:=fun s : CavityShellSpin n L=>(s.1,s.2.val)) + (measurable_fst.prodMk measurable_snd.subtype_val) + +def cavityShellPatternEnergy (n L M : ℕ) (f : ℝ→ᵇℝ) (a : Fin M→Fin (n+1+L)→ℝ) + (s : CavityShellSpin n L) : ℝ := + normalizedPatternEnergy (n+1+L) M f a (cavityShellSpinEmbedding n L s) + +lemma cavityShellPatternEnergy_measurable (n L M : ℕ) (f : ℝ→ᵇℝ) + (a : Fin M→Fin (n+1+L)→ℝ) : Measurable (cavityShellPatternEnergy n L M f a) := by + exact (normalizedPatternEnergy_continuous (n+1+L) M f).measurable.comp + (f:=fun s : CavityShellSpin n L=>(a,cavityShellSpinEmbedding n L s)) + (measurable_const.prodMk (cavityShellSpinEmbedding_measurable n L)) + +lemma cavityShellPatternEnergy_bound (n L M : ℕ) (f : ℝ→ᵇℝ) + (a : Fin M→Fin (n+1+L)→ℝ) (s : CavityShellSpin n L) : + |cavityShellPatternEnergy n L M f a s|≤M*‖f‖ := + normalizedPatternEnergy_bound _ _ _ _ _ + +theorem cavity_true_shell_perturbation (n L M : ℕ) (f : ℝ→ᵇℝ) + (a : Fin M→Fin (n+1+L)→ℝ) (v : ℕ→ℝ) {C : ℝ} (hC : 0≤C) + (hv : ∀ j,|v (j+1)|≤C) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + |(∫ g,Real.log (tiltPartition (cavityShellBaseLaw n L) + (fun s=>cavityShellPatternEnergy n L M f a s+inner ℝ (cavityShellFeature n L v s) g) 1) + ∂stdGaussian (BulkMark (n+1+L)))- + ∫ g,Real.log (tiltPartition (cavityShellBaseLaw n L) + (fun s=>cavityShellPatternEnergy n L M f a s+inner ℝ (bulkFeature (n+1) v s.1) g) 1) + ∂stdGaussian (BulkMark (n+1))|≤ + Real.pi*cavityBulkCovarianceError n L C (3*((L:ℝ)+1)) := by + let := cavityShellBaseLaw_probability n L hp + exact cavity_shell_perturbation_comparison n L v (cavityShellBaseLaw n L) + (cavityShellPatternEnergy_measurable n L M f a) (by positivity) hC + (cavityShellPatternEnergy_bound n L M f a) hv + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityShellPolar.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityShellPolar.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a9ea9a79df982ec7d1c64caee04a6c7bf6320a5 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityShellPolar.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityBlockProduct + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology ENNReal NNReal +namespace SphericalPerceptronFreeEnergy + +abbrev PositiveRadius : Type := ↥(Ioi (0:ℝ)) + +def cavityPolarRadius (n k : ℕ) (p : PositiveRadius×PositiveRadius) : PositiveRadius := + ⟨Real.sqrt (n+1+(k+1):ℕ) * (Real.sqrt (p.1.val^2+p.2.val^2))⁻¹*p.2.val,by + change 0 < Real.sqrt (n+1+(k+1):ℕ) * (Real.sqrt (p.1.val^2+p.2.val^2))⁻¹*p.2.val + have hr : 0 + (p.1.1,p.1.2.val •p.2.val)) + (((gaussianRadiusLaw n).prod (gaussianRadiusLaw k)).prod (unitSphereLaw (k+1))) + ((gaussianRadiusLaw n).prod (stdGaussian (Spin (k+1)))) := by + have h : MeasurePreserving (fun p : PositiveRadius×(PositiveRadius×Metric.sphere (0:Spin (k+1)) 1)=> + (p.1,p.2.1.val •p.2.2.val)) + ((gaussianRadiusLaw n).prod ((gaussianRadiusLaw k).prod (unitSphereLaw (k+1)))) + ((gaussianRadiusLaw n).prod (stdGaussian (Spin (k+1)))) := + (MeasurePreserving.id (gaussianRadiusLaw n)).prod (stdGaussian_radial_preserving k) + exact h.comp (measurePreserving_prodAssoc (gaussianRadiusLaw n) (gaussianRadiusLaw k) (unitSphereLaw (k+1))) + +lemma cavity_polar_radius_preserving (n k : ℕ) : + MeasurePreserving (fun p : (PositiveRadius×PositiveRadius)×Metric.sphere (0:Spin (k+1)) 1=> + (cavityPolarRadius n k p.1,p.2)) + (((gaussianRadiusLaw n).prod (gaussianRadiusLaw k)).prod (unitSphereLaw (k+1))) + ((cavityRadiusLaw n k : Measure PositiveRadius).prod (unitSphereLaw (k+1))) := by + have h : MeasurePreserving (cavityPolarRadius n k) + ((gaussianRadiusLaw n).prod (gaussianRadiusLaw k)) (cavityRadiusLaw n k) := + ⟨cavityPolarRadius_measurable n k,rfl⟩ + exact h.prod (MeasurePreserving.id (unitSphereLaw (k+1))) + +theorem cavitySphereLaw_polar (n k : ℕ) : + (cavitySphereLaw n (k+1) : Measure (Spin (k+1)))= + ((cavityRadiusLaw n k : Measure PositiveRadius).prod (unitSphereLaw (k+1))).map + (fun p=>p.1.val •p.2.val) := by + rw [cavitySphereLaw_unit] + change (Measure.map (cavityRadialUnit n (k+1)) + ((gaussianRadiusLaw n).prod (stdGaussian (Spin (k+1))))).map _=_ + have hm : Measurable ((fun z : Spin (k+1)=>Real.sqrt (n+1+(k+1):ℕ) •z) ∘ + cavityRadialUnit n (k+1)) := + (by fun_prop : Measurable (fun z : Spin (k+1)=>Real.sqrt (n+1+(k+1):ℕ) •z)).comp + (cavityRadialUnit_measurable n (k+1)) + rw [Measure.map_map (by fun_prop) (cavityRadialUnit_measurable _ _), + ←(cavity_polar_data_preserving n k).map_eq, + Measure.map_map hm (cavity_polar_data_preserving n k).measurable, + ←(cavity_polar_radius_preserving n k).map_eq, + Measure.map_map (by fun_prop) (cavity_polar_radius_preserving n k).measurable] + congr 1 + funext p + have hu : ‖p.2.val‖=1 := by simpa only [Metric.mem_sphere,dist_zero_right] using p.2.prop + simp only [Function.comp_def,cavityRadialUnit,cavityPolarRadius,norm_smul,Real.norm_eq_abs, + abs_of_pos (show 0p.1.val •p.2.val) ⁻¹' + cavityShell (k+1)=cavityRadiusShell k×ˢuniv := by + ext p + simp [cavityShell,cavityRadiusShell,norm_smul] + +theorem cavitySphereLaw_shell_polar (n k : ℕ) : + (cavitySphereLaw n (k+1) : Measure (Spin (k+1))).restrict (cavityShell (k+1))= + (((cavityRadiusLaw n k : Measure PositiveRadius).restrict (cavityRadiusShell k)).prod + (unitSphereLaw (k+1))).map (fun p=>p.1.val •p.2.val) := by + rw [cavitySphereLaw_polar,Measure.restrict_map (by fun_prop) (cavityShell_measurable _), + cavityShell_smul_preimage,←Measure.prod_restrict,Measure.restrict_univ] + + +lemma cavityRadiusShell_bounds (k : ℕ) {r : PositiveRadius} (hr : r∈cavityRadiusShell k) : + Real.sqrt (k+1:ℕ)≤r.val ∧ r.val≤(k:ℝ)+3 := by + have hp : 0 + Real.exp (W+p.1.val^2*C/2+p.1.val*inner ℝ Y p.2.val)) + (((cavityRadiusLaw n k : Measure PositiveRadius).restrict (cavityRadiusShell k)).prod + (unitSphereLaw (k+1))) := by + let μ:=(cavityRadiusLaw n k : Measure PositiveRadius).restrict (cavityRadiusShell k) + have hae : ∀ᵐ p : PositiveRadius×Metric.sphere (0:Spin (k+1)) 1 + ∂μ.prod (unitSphereLaw (k+1)),p.1∈cavityRadiusShell k := by + apply (Measure.ae_prod_iff_ae_ae (measurable_fst (cavityRadiusShell_measurable k))).mpr + filter_upwards [ae_restrict_mem (cavityRadiusShell_measurable k)] with r hr + exact ae_of_all _ fun _=>hr + apply Integrable.of_bound (by fun_prop) + (Real.exp (|W|+((k+1:ℕ)+1)*|C|/2+((k:ℝ)+3)*‖Y‖)) + filter_upwards [hae] with p hp + have hr : 0 + Real.exp (W+‖p.1.val •p.2.val‖^2*C/2+inner ℝ Y (p.1.val •p.2.val)))= + (fun p=>Real.exp (W+p.1.val^2*C/2+p.1.val*inner ℝ Y p.2.val)) := by + funext p + have hu : ‖p.2.val‖=1 := by simpa only [Metric.mem_sphere,dist_zero_right] using p.2.prop + simp only [norm_smul,Real.norm_eq_abs,hu,mul_one,sq_abs,real_inner_smul_right] + rw [he,integral_prod _ (cavity_shell_angular_integrable n k W C Y)] + apply integral_congr_ae + filter_upwards [] with r + simp only [Real.exp_add,integral_const_mul,sphericalExp] + +lemma cavitySphereLaw_shell_mass_polar (n k : ℕ) : + (cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1))= + (cavityRadiusLaw n k : Measure PositiveRadius).real (cavityRadiusShell k) := by + have h:=cavitySphereLaw_shell_integral n k 0 0 0 + simpa [sphericalExp] using h + +theorem cavitySphereLaw_shell_lower (n k : ℕ) (W C : ℝ) (Y : Spin (k+1)) + {K : ℝ} (hC : |C|≤K) : + (cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1))* + (Real.exp (-K/2)*Real.exp (W+(k+1:ℕ)*C/2)*sphericalExp k Y (Real.sqrt (k+1:ℕ)))≤ + ∫ z in cavityShell (k+1),Real.exp (W+‖z‖^2*C/2+inner ℝ Y z) + ∂(cavitySphereLaw n (k+1) : Measure (Spin (k+1))) := by + rw [cavitySphereLaw_shell_integral,cavitySphereLaw_shell_mass_polar] + have hi := (cavity_shell_angular_integrable n k W C Y).integral_prod_left + have he : (fun r : PositiveRadius=>∫ u : Metric.sphere (0:Spin (k+1)) 1, + Real.exp (W+r.val^2*C/2+r.val*inner ℝ Y u.val) ∂unitSphereLaw (k+1))= + (fun r=>Real.exp (W+r.val^2*C/2)*sphericalExp k Y r.val) := by + funext r + simp only [Real.exp_add,integral_const_mul,sphericalExp] + rw [he] at hi + calc + _ = ∫ _ in cavityRadiusShell k, + Real.exp (-K/2)*Real.exp (W+(k+1:ℕ)*C/2)*sphericalExp k Y (Real.sqrt (k+1:ℕ)) + ∂(cavityRadiusLaw n k : Measure PositiveRadius) := by simp [mul_comm] + _ ≤ _ := by + apply integral_mono_ae (integrable_const _) hi + filter_upwards [ae_restrict_mem (cavityRadiusShell_measurable k)] with r hr + have hD : |(r.val^2-(k+1:ℕ))*C|≤K := by + rw [abs_mul,abs_of_nonneg (sub_nonneg.mpr hr.1)] + have hK : 0≤K := (abs_nonneg C).trans hC + calc + _≤1*K := mul_le_mul (by linarith [hr.2]) hC (abs_nonneg C) (by norm_num) + _=K := one_mul K + have hexp : Real.exp (-K/2)*Real.exp (W+(k+1:ℕ)*C/2)≤Real.exp (W+r.val^2*C/2) := by + rw [←Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith [(abs_le.mp hD).1] + exact mul_le_mul hexp + (sphericalExp_mono k Y (Real.sqrt_nonneg _) (cavityRadiusShell_bounds k hr).1) + ((by norm_num : (0:ℝ)≤1).trans (one_le_sphericalExp _ _ _)) (Real.exp_pos _).le + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityShellRestriction.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityShellRestriction.lean new file mode 100644 index 0000000000000000000000000000000000000000..facd663890f4b62a8b7dd8e5c8730266ba4df68f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityShellRestriction.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkConcentration +import OAI.Probability.Perceptron.Cavity.CavityBlockProduct +import OAI.Probability.Perceptron.Cavity.CavityShellPerturbation + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology ENNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma unitSphere_cavityAmbient_law (n L : ℕ) : + (unitSphereLaw (n+1+L)).map Subtype.val= + ((unitSphereLaw (n+1)).prod (cavitySphereLaw n L)).map + (fun p=>cavityNormalizedVec (n+1) L p.1 p.2) := by + have h:=congrArg (fun μ : Measure (Spin (n+1)×Spin L)=>μ.map (gaussianBlockJoin (n+1) L)) + (sphereBlock_scaled_product_law n L) + have hm : Measurable (fun u : NormalizedSpin (n+1+L)=>gaussianBlockSplit (n+1) L u.val) := + (gaussianBlockSplit_measurable (n+1) L).comp measurable_subtype_coe + rw [Measure.map_map (gaussianBlockJoin_measurable (n+1) L) hm, + Measure.map_map (gaussianBlockJoin_measurable (n+1) L) (cavitySphereBlockEmbed_measurable n L)] at h + simpa only [Function.comp_def,gaussianBlockJoin_split,cavitySphereBlockEmbed_formula, + cavityNormalizedVec,cavityRho] using h + +lemma cavityShellProbability_integral (n L : ℕ) (F : Spin L→ℝ) : + (∫ z : {z : Spin L // z∈cavityShell L},F z.val ∂cavityShellProbability n L)= + ((cavitySphereLaw n L : Measure (Spin L)).real (cavityShell L))⁻¹* + ∫ z in cavityShell L,F z ∂(cavitySphereLaw n L : Measure (Spin L)) := by + unfold cavityShellProbability + rw [integral_subtype_comap (cavityShell_measurable L)] + simp only [ProbabilityTheory.cond,Measure.restrict_smul,Measure.restrict_restrict (cavityShell_measurable L), + inter_self,integral_smul_measure,ENNReal.toReal_inv,smul_eq_mul,Measure.real] + +theorem cavity_actual_shell_restriction (n L : ℕ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) + (F : NormalizedSpin (n+1+L)→ℝ) (hF : Measurable F) {A : ℝ} (hA : 0≤A) + (hF0 : ∀ x,0≤F x) (hFA : ∀ x,F x≤A) : + (cavitySphereLaw n L : Measure (Spin L)).real (cavityShell L)* + (∫ s,F (cavityShellSpinEmbedding n L s) ∂cavityShellBaseLaw n L)≤ + ∫ x,F x ∂unitSphereLaw (n+1+L) := by + let := cavityShellBaseLaw_probability n L hp + let := cavityShellProbability_probability n L hp + obtain ⟨E,hE,hEF⟩ := (MeasurableEmbedding.subtype_coe (Metric.isClosed_sphere.measurableSet : + MeasurableSet (Metric.sphere (0:Spin (n+1+L)) 1))).exists_measurable_extend hF (fun _=>inferInstance) + let W : Spin (n+1+L)→ℝ:=fun x=>max 0 (min A (E x)) + have hW : Measurable W:=measurable_const.max (measurable_const.min hE) + have hW0 (x) : 0≤W x := le_max_left _ _ + have hWA (x) : W x≤A := max_le hA (min_le_left _ _) + have hWF (x : NormalizedSpin (n+1+L)) : W x.val=F x := by + have he : E x.val=F x := congrFun hEF x + simp only [W,he,min_eq_right (hFA x),max_eq_right (hF0 x)] + let G : NormalizedSpin (n+1)×Spin L→ℝ:=fun p=>W (cavityNormalizedVec (n+1) L p.1 p.2) + have hG : Measurable G:=hW.comp (cavityNormalizedVec_measurable (n+1) L) + have hi : Integrable G ((unitSphereLaw (n+1)).prod (cavitySphereLaw n L)) := by + apply Integrable.of_bound hG.aestronglyMeasurable A + exact ae_of_all _ fun p=>by + change ‖W (cavityNormalizedVec (n+1) L p.1 p.2)‖≤A + simpa only [Real.norm_eq_abs,abs_of_nonneg (hW0 _)] using hWA (cavityNormalizedVec (n+1) L p.1 p.2) + have heq : (∫ x,F x ∂unitSphereLaw (n+1+L))= + ∫ p,G p ∂(unitSphereLaw (n+1)).prod (cavitySphereLaw n L) := by + calc + _=∫ x,W x.val ∂unitSphereLaw (n+1+L) := integral_congr_ae (ae_of_all _ fun x=>(hWF x).symm) + _=∫ x,W x ∂(unitSphereLaw (n+1+L)).map Subtype.val := + (integral_map measurable_subtype_coe.aemeasurable hW.aestronglyMeasurable).symm + _=_ := by rw [unitSphere_cavityAmbient_law,integral_map (cavityNormalizedVec_measurable (n+1) L).aemeasurable hW.aestronglyMeasurable] + rw [heq,integral_prod _ hi] + have hsi : Integrable (fun s : CavityShellSpin n L=>F (cavityShellSpinEmbedding n L s)) + (cavityShellBaseLaw n L) := by + apply Integrable.of_bound (hF.comp (cavityShellSpinEmbedding_measurable n L)).aestronglyMeasurable A + exact ae_of_all _ fun s=>by + change ‖F (cavityShellSpinEmbedding n L s)‖≤A + simpa only [Real.norm_eq_abs,abs_of_nonneg (hF0 _)] using hFA (cavityShellSpinEmbedding n L s) + rw [cavityShellBaseLaw,integral_prod _ hsi,←integral_const_mul] + apply integral_mono_ae + · exact hsi.integral_prod_left.const_mul _ + · exact hi.integral_prod_left + filter_upwards [hi.prod_right_ae] with x hx + have hs : (fun z : {z : Spin L // z∈cavityShell L}=>F (cavityShellSpinEmbedding n L (x,z)))= + (fun z=>G (x,z.val)) := by + funext z + exact (hWF (cavityShellSpinEmbedding n L (x,z))).symm + rw [hs] + have hc:=cavityShellProbability_integral n L (fun z=>G (x,z)) + rw [hc] + have hm : (cavitySphereLaw n L : Measure (Spin L)).real (cavityShell L)≠0 := + ne_of_gt (ENNReal.toReal_pos hp (measure_ne_top _ _)) + rw [←mul_assoc,mul_inv_cancel₀ hm,one_mul] + exact setIntegral_le_integral hx (ae_of_all _ fun z=>hW0 _) + + +lemma cavityShell_bulkHamiltonian (n L M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : Fin M→Fin (n+1+L)→ℝ) (g : BulkMark (n+1+L)) (s : CavityShellSpin n L) : + bulkHamiltonian (n+1+L) M f v a g (cavityShellSpinEmbedding n L s)= + cavityShellPatternEnergy n L M f a s+inner ℝ (cavityShellFeature n L v s) g := by + unfold bulkHamiltonian cavityShellPatternEnergy cavityShellFeature + exact congrArg (fun y=> (∑ i, f (∑ j, a i j * (cavityShellSpinEmbedding n L s).val j))+ + inner ℝ y g) (ambientBulkFeature_eq (n+1+L) v (cavityShellSpinEmbedding n L s)).symm + +lemma cavity_restriction_log_of_bounded (n L : ℕ) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) + (H : NormalizedSpin (n+1+L)→ℝ) (hH : Measurable H) {A : ℝ} + (hA : 0≤A) (hB : ∀ x,|H x|≤A) : + Real.log ((cavitySphereLaw n L : Measure (Spin L)).real (cavityShell L))+ + Real.log (tiltPartition (cavityShellBaseLaw n L) + (fun s=>H (cavityShellSpinEmbedding n L s)) 1)≤ + Real.log (tiltPartition (unitSphereLaw (n+1+L)) H 1) := by + let := cavityShellBaseLaw_probability n L hp + have hR := cavity_actual_shell_restriction n L hp + (fun x=>Real.exp (H x)) hH.exp + (Real.exp_pos A).le (fun _=>(Real.exp_pos _).le) + (fun x=>Real.exp_le_exp.mpr ((le_abs_self _).trans (hB x))) + have hm : 0<(cavitySphereLaw n L : Measure (Spin L)).real (cavityShell L) := + ENNReal.toReal_pos hp (measure_ne_top _ _) + have hs := tilt_partition_pos (cavityShellBaseLaw n L) + (hH.comp (cavityShellSpinEmbedding_measurable n L)) hA + (fun s=>hB (cavityShellSpinEmbedding n L s)) 1 + simp only [tiltPartition,one_mul,Function.comp_apply] at hs + have hh := Real.log_le_log (mul_pos hm hs) hR + rw [Real.log_mul (ne_of_gt hm) (ne_of_gt hs)] at hh + simpa only [tiltPartition,one_mul] using hh + +lemma cavity_actual_shell_log_restriction (n L M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : Fin M→Fin (n+1+L)→ℝ) (g : BulkMark (n+1+L)) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) : + Real.log ((cavitySphereLaw n L : Measure (Spin L)).real (cavityShell L))+ + Real.log (tiltPartition (cavityShellBaseLaw n L) + (fun s=>cavityShellPatternEnergy n L M f a s+inner ℝ (cavityShellFeature n L v s) g) 1)≤ + Real.log (tiltPartition (unitSphereLaw (n+1+L)) + (bulkHamiltonian (n+1+L) M f v a g) 1) := by + have hH : Measurable (bulkHamiltonian (n+1+L) M f v a g) := + (bulkHamiltonian_section_measurable (n+1+L) M f v (a,g)) + have h := cavity_restriction_log_of_bounded n L hp + (bulkHamiltonian (n+1+L) M f v a g) hH + (add_nonneg (mul_nonneg (Nat.cast_nonneg M) (norm_nonneg f)) + (mul_nonneg (by unfold bulkFeatureBound; positivity) (norm_nonneg g))) + (bulkHamiltonian_bound (n+1+L) M f v (a,g)) + simpa only [cavityShell_bulkHamiltonian] using h + +lemma cavity_gaussian_log_integrable {I S : Type} [Fintype I] [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {H : S→ℝ} {V : S→EuclideanSpace ℝ I} + (hH : Measurable H) (hV : Measurable V) {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hHA : ∀ s,|H s|≤A) (hVB : ∀ s,‖V s‖≤B) : + Integrable (fun g=>Real.log (tiltPartition μ (fun s=>H s+inner ℝ (V s) g) 1)) + (stdGaussian (EuclideanSpace ℝ I)) := by + apply Integrable.mono' ((integrable_const A).add + ((IsGaussian.integrable_id (μ:=stdGaussian (EuclideanSpace ℝ I))).norm.const_mul B)) + (gaussianLogPartition_measurable_finite μ hH hV).aestronglyMeasurable + exact ae_of_all _ fun g=>by + rw [Real.norm_eq_abs] + apply tilt_log_partition_bound μ (hH.add (hV.inner measurable_const)) + (add_nonneg hA (mul_nonneg hB (norm_nonneg _))) + intro s + apply (abs_add_le _ _).trans + exact add_le_add (hHA s) ((abs_real_inner_le_norm (V s) g).trans + (mul_le_mul_of_nonneg_right (hVB s) (norm_nonneg _))) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityShellSubexp.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityShellSubexp.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d0893c4d4a23c43f2b9f763f7e37e300f4319a9 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityShellSubexp.lean @@ -0,0 +1,222 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityShellLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal +namespace SphericalPerceptronFreeEnergy + +lemma cavityShell_subset_closedBall (k : ℕ) : + cavityShell (k+1) ⊆ Metric.closedBall 0 (Real.sqrt ((k+1:ℕ)+1)) := by + intro z hz + simpa only [Metric.mem_closedBall,dist_zero_right] using + (Real.le_sqrt (norm_nonneg z) (by positivity)).mpr hz.2 + +lemma cavityShell_volume_ne_top (k : ℕ) : + (volume : Measure (Spin (k+1))) (cavityShell (k+1))≠⊤ := + ne_of_lt ((measure_mono (cavityShell_subset_closedBall k)).trans_lt + (isCompact_closedBall _ _).measure_lt_top) + +lemma cavity_sqrt_power_gap (k : ℕ) : + (Real.sqrt (k+1:ℕ))^(k+1)/(2*((k+1:ℕ)+1)) ≤ + (Real.sqrt ((k+1:ℕ)+1))^(k+1)-(Real.sqrt (k+1:ℕ))^(k+1) := by + let a:=Real.sqrt (k+1:ℕ) + let b:=Real.sqrt ((k+1:ℕ)+1) + have ha : 0show radialNormalizer k*Real.exp (-((k+1:ℕ)+1)/2)≤canonicalRadialDensity k 1 z from by + unfold canonicalRadialDensity + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr ?_) (radialNormalizer_pos k).le + have hh:=hz.2 + change ‖z‖^2≤(k+1:ℕ)+1 at hh + nlinarith) + simpa only [integral_const,measureReal_restrict_apply MeasurableSet.univ,univ_inter,smul_eq_mul,mul_comm] using h + +lemma cavity_band_density_upper (k : ℕ) {ε : ℝ} (hε : 0≤ε) : + (canonicalRadialMass k 1).real (normSquareBand k ε)≤ + radialNormalizer k * Real.exp (-((k+1:ℕ)*(1-ε))/2) * + (Real.sqrt ((k+1:ℕ)*(1+ε)))^(k+1) * + (volume : Measure (Spin (k+1))).real (Metric.closedBall 0 1) := by + have hs : normSquareBand k ε ⊆ Metric.closedBall (0:Spin (k+1)) (Real.sqrt ((k+1:ℕ)*(1+ε))) := by + intro z hz + simpa only [Metric.mem_closedBall,dist_zero_right] using + (Real.le_sqrt (norm_nonneg z) (by positivity)).mpr hz.2 + have hf : (volume : Measure (Spin (k+1))) (normSquareBand k ε)≠⊤ := + ne_of_lt ((measure_mono hs).trans_lt (isCompact_closedBall _ _).measure_lt_top) + rw [canonicalRadialMass_real_apply (by norm_num : (0:ℝ)<1) (normSquareBand_measurable _ _)] + have hi := setIntegral_mono_on (canonicalRadialDensity_integrable k (by norm_num : (0:ℝ)<1)).integrableOn + (integrableOn_const hf (C:=radialNormalizer k * Real.exp (-((k+1:ℕ)*(1-ε))/2))) (normSquareBand_measurable k ε) + (fun z hz=>show canonicalRadialDensity k 1 z≤radialNormalizer k*Real.exp (-((k+1:ℕ)*(1-ε))/2) from by + unfold canonicalRadialDensity + apply mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr ?_) (radialNormalizer_pos k).le + have hh:=hz.1 + change (k+1:ℕ)*(1-ε)≤‖z‖^2 at hh + nlinarith) + simp only [integral_const,measureReal_restrict_apply MeasurableSet.univ,univ_inter,smul_eq_mul] at hi + apply hi.trans + have hm := measureReal_mono (μ:=(volume : Measure (Spin (k+1)))) hs (isCompact_closedBall _ _).measure_ne_top + rw [Measure.addHaar_real_closedBall' (volume : Measure (Spin (k+1))) 0 (Real.sqrt_nonneg _),finrank_euclideanSpace,Fintype.card_fin] at hm + convert mul_le_mul_of_nonneg_left hm (mul_pos (radialNormalizer_pos k) (Real.exp_pos (-((k+1:ℕ)*(1-ε))/2))).le using 1 <;> ring + +lemma cavity_sqrt_pow_exp (k : ℕ) {ε : ℝ} (_hε : 0≤ε) : + (Real.sqrt (1+ε))^(k+1)≤Real.exp (ε*(k+1:ℕ)/2) := by + have hh : Real.sqrt (1+ε)≤Real.exp (ε/2) := by + apply (Real.sqrt_le_iff).mpr + refine ⟨(Real.exp_pos _).le,?_⟩ + rw [←Real.exp_nat_mul] + convert Real.add_one_le_exp ε using 1 <;> ring_nf + have hp:=pow_le_pow_left₀ (Real.sqrt_nonneg _) hh (k+1) + rw [←Real.exp_nat_mul] at hp + convert hp using 1 + congr 1 + ring + +lemma cavityShell_band_comparison (k : ℕ) {ε : ℝ} (hε : 0≤ε) : + (canonicalRadialMass k 1).real (normSquareBand k ε)≤ + cavityShellMass k * (2*((k+1:ℕ)+1))*Real.exp (ε*(k+1:ℕ)+1/2) := by + let D:=radialNormalizer k * (Real.sqrt (k+1:ℕ))^(k+1) * + (volume : Measure (Spin (k+1))).real (Metric.closedBall 0 1) + have hD : 0≤D := by + exact mul_nonneg (mul_nonneg (radialNormalizer_pos k).le + (pow_nonneg (Real.sqrt_nonneg _) _)) measureReal_nonneg + have hl : D*Real.exp (-((k+1:ℕ)+1)/2)/(2*((k+1:ℕ)+1))≤cavityShellMass k := by + have hv:=mul_le_mul_of_nonneg_left (cavityShell_volume_lower k) + (mul_pos (radialNormalizer_pos k) (Real.exp_pos (-((k+1:ℕ)+1)/2))).le + apply le_trans _ (cavityShell_density_lower k) + convert hv using 1 + dsimp only [D] + ring + have hb : (canonicalRadialMass k 1).real (normSquareBand k ε)≤ + D*Real.exp (-((k+1:ℕ)*(1-ε))/2)*Real.exp (ε*(k+1:ℕ)/2) := by + apply (cavity_band_density_upper k hε).trans + rw [Real.sqrt_mul (by positivity),mul_pow] + have hh := mul_le_mul_of_nonneg_left (cavity_sqrt_pow_exp k hε) + (show 0≤D*Real.exp (-((k+1:ℕ)*(1-ε))/2) by positivity) + convert hh using 1 + dsimp only [D] + ring + apply hb.trans + have hh := mul_le_mul_of_nonneg_right hl + (show 0≤(2*((k+1:ℕ)+1))*Real.exp (ε*(k+1:ℕ)+1/2) by positivity) + convert hh using 1 + · rw [mul_assoc D,←Real.exp_add] + rw [div_mul_eq_mul_div,eq_div_iff (by positivity : (2*((k+1:ℕ)+1):ℝ)≠0)] + rw [show D*Real.exp (-((k+1:ℕ)+1)/2)*((2*((k+1:ℕ)+1))*Real.exp (ε*(k+1:ℕ)+1/2))= + D*(Real.exp (-((k+1:ℕ)+1)/2)*Real.exp (ε*(k+1:ℕ)+1/2))*(2*((k+1:ℕ)+1)) by ring,←Real.exp_add] + congr 2 + ring_nf + · ring + +lemma cavityShell_log_lower (k : ℕ) {ε : ℝ} (hε : 0≤ε) + (hb : (1/2:ℝ)≤(canonicalRadialMass k 1).real (normSquareBand k ε)) : + -ε*(k+1:ℕ)-1/2-Real.log (4*((k+1:ℕ)+1))≤Real.log (cavityShellMass k) := by + have h := Real.log_le_log (by norm_num : (0:ℝ)<1/2) (hb.trans (cavityShell_band_comparison k hε)) + rw [Real.log_mul (mul_pos (cavityShellMass_pos k) (by positivity)).ne' (Real.exp_pos _).ne', + Real.log_mul (cavityShellMass_pos k).ne' (by positivity : (2*((k+1:ℕ)+1):ℝ)≠0),Real.log_exp, + Real.log_div (by norm_num : (1:ℝ)≠0) (by norm_num : (2:ℝ)≠0),Real.log_one] at h + have he : Real.log (4*((k+1:ℕ)+1))=Real.log 2+Real.log (2*((k+1:ℕ)+1)) := by + rw [←Real.log_mul (by norm_num : (2:ℝ)≠0) (by positivity : (2*((k+1:ℕ)+1):ℝ)≠0)] + congr 1 + ring + rw [he] + linarith + +lemma cavityShell_log_error_tendsto : + Tendsto (fun k : ℕ=>(1/2+Real.log (4*((k+1:ℕ)+1)))/(k+1:ℕ)) atTop (𝓝 (0:ℝ)) := by + have hN : Tendsto (fun k : ℕ=>((k+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have ht := (Real.tendsto_pow_log_div_mul_add_atTop (1/4) (-1) 1 (by norm_num)).comp + ((tendsto_atTop_add_const_right _ 1 hN).const_mul_atTop (by norm_num : (0:ℝ)<4)) + have ht' : Tendsto (fun k : ℕ=>Real.log (4*((k+1:ℕ)+1))/(k+1:ℕ)) atTop (𝓝 (0:ℝ)) := by + convert ht using 1 + funext k + dsimp only [Function.comp_def] + rw [pow_one] + congr 1 + ring + have hi := (tendsto_const_nhds : Tendsto (fun _ : ℕ=>(1/2:ℝ)) atTop (𝓝 (1/2))).mul + (tendsto_inv_atTop_zero.comp hN) + convert hi.add ht' using 1 <;> simp only [mul_zero,zero_add,div_eq_mul_inv,add_mul,Function.comp_def] + +theorem cavityShell_log_sublinear : + Tendsto (fun k : ℕ=>Real.log (cavityShellMass k)/(k+1:ℕ)) atTop (𝓝 (0:ℝ)) := by + apply tendsto_order.2 + constructor + · intro a ha + let ε : ℝ:=min (-a/2) (1/2) + have he : 0<ε := lt_min (by linarith) (by norm_num) + have he1 : ε<1 := (min_le_right _ _).trans_lt (by norm_num) + have hae : a < -ε := by + have hh : ε≤-a/2 := min_le_left _ _ + dsimp only [ε] at hh ⊢ + linarith + have ht : Tendsto (fun k : ℕ=>-ε-(1/2+Real.log (4*((k+1:ℕ)+1)))/(k+1:ℕ)) atTop (𝓝 (-ε)) := by + simpa only [sub_zero] using tendsto_const_nhds.sub cavityShell_log_error_tendsto + filter_upwards [ht.eventually (lt_mem_nhds hae),canonicalRadial_band_eventually_half he he1] with k hk hb + apply hk.trans_le + have hh:=div_le_div_of_nonneg_right (cavityShell_log_lower k he.le hb) + (by positivity : (0:ℝ)≤(k+1:ℕ)) + convert hh using 1 + field_simp + ring + · intro b hb + filter_upwards [] with k + have hh := Real.log_nonpos (cavityShellMass_pos k).le (cavityShellMass_le_one k) + exact (div_nonpos_of_nonpos_of_nonneg hh (by positivity)).trans_lt hb + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavitySmoothLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/CavitySmoothLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..ba3744a9244c1e2c70b0beafbdb18f981aefdf60 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavitySmoothLimit.lean @@ -0,0 +1,39 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LevelTrialApprox +import OAI.Probability.Perceptron.Cavity.CavityTelescoping + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma expectedPressure_lower_smooth (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) {α : ℝ} (hα : 0<α) (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) {ε : ℝ} (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop,(terminalVariational P α g.f).toReal-ε≤expectedPressure α 1 g.f (n+1) := by + filter_upwards [cavity_averaged_log_lower P hB hα g h1 h2 h3 (show 0<ε/2 by positivity), + bulkScale_per_coordinate_tendsto.eventually (Iio_mem_nhds (show 0<ε/2 by positivity))] with n hn he + have hb:=cavityAveragedLog_unperturbed_bound hα.le g.f n + linarith [(abs_le.mp hb).2] + +theorem expectedPressure_limit_smooth (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) {α : ℝ} (hα : 0<α) (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) : + Tendsto (fun n : ℕ=>expectedPressure α 1 g.f (n+1)) atTop + (𝓝 (terminalVariational P α g.f).toReal) := by + apply Metric.tendsto_nhds.2 + intro ε hε + filter_upwards [expectedPressure_lower_smooth P hB hα g h1 h2 h3 (show 0<ε/2 by positivity), + expectedPressure_upper_variational P hB g ⟨α,hα.le⟩ (show 0<ε/2 by positivity)] with n hn hu + change expectedPressure α 1 g.f (n+1) ≤ (terminalVariational P α g.f).toReal + ε/2 at hu + rw [Real.dist_eq] + exact abs_lt.mpr ⟨by linarith,by linarith⟩ +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavitySphericalGrid.lean b/lean/OAI/Probability/Perceptron/Cavity/CavitySphericalGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..2c920af5c94e5ef7a82a3b8f91a61eb1c7375f78 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavitySphericalGrid.lean @@ -0,0 +1,165 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.UniformQuantileCells + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] +lemma gaussianBackward_label_mono_parameters {I : Type*} {f : E→ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (l : List (I×ℝ)) (a b : I→ℝ) + (ha : ∀ c∈l,0≤a c.1) (hab : ∀ c∈l,a c.1≤b c.1) : + ∀ x,gaussianBackward μ (l.map fun c=>(a c.1,c.2)) f x≤ + gaussianBackward μ (l.map fun c=>(b c.1,c.2)) f x := by + have hb : ∀ c∈l,0≤b c.1:=fun c hc=>(ha c hc).trans (hab c hc) + induction l with + | nil => intro x; rfl + | cons c l ih => + have ha':=fun d hd=>ha d (List.mem_cons_of_mem c hd) + have hb':=fun d hd=>hb d (List.mem_cons_of_mem c hd) + have hab':=fun d hd=>hab d (List.mem_cons_of_mem c hd) + have hla : LipschitzWith L (gaussianBackward μ (l.map fun d=>(a d.1,d.2)) f) := by + apply gaussianBackward_lipschitz μ hf + intro d hd + obtain ⟨e,he,rfl⟩:=List.mem_map.mp hd + exact ha' e he + have hlb : LipschitzWith L (gaussianBackward μ (l.map fun d=>(b d.1,d.2)) f) := by + apply gaussianBackward_lipschitz μ hf + intro d hd + obtain ⟨e,he,rfl⟩:=List.mem_map.mp hd + exact hb' e he + intro x + simp only [List.map_cons,gaussianBackward] + exact (gaussianEntropic_mono_parameter μ hla c.2 x (hab c List.mem_cons_self)).trans + (gaussianEntropic_mono μ hla hlb (hb c List.mem_cons_self) c.2 (ih ha' hab' hb') x) +end + +lemma sphericalHeatValue_ofFn_mono_parameters (n N : ℕ) (a b σ : Fin N→ℝ) + (ha : ∀ i,0≤a i) (hab : ∀ i,a i≤b i) : + sphericalHeatValue n (List.ofFn fun i=>(a i,σ i))≤ + sphericalHeatValue n (List.ofFn fun i=>(b i,σ i)) := by + have hm:=gaussianBackward_label_mono_parameters (stdGaussian (Spin (n+1))) + (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) + (List.ofFn fun i=>(i,σ i)) a b + (by intro c hc; obtain ⟨i,rfl⟩:=List.mem_ofFn.mp hc; exact ha i) + (by intro c hc; obtain ⟨i,rfl⟩:=List.mem_ofFn.mp hc; exact hab i) 0 + simp only [List.map_ofFn,Function.comp_def] at hm + unfold sphericalHeatValue + simp only [List.map_ofFn,Function.comp_def] + exact sub_le_sub_right (div_le_div_of_nonneg_right hm (by positivity)) _ + +theorem finiteSphericalFieldValue_grid_bracket {d : ℕ} (w h : Fin (d+1)→ℝ) + (hw : ∀ i,00) (fun _=>2*H) ∧ u∈Icc (fun _=>0) (fun _=>2*H) ∧ + (∀ n,sphericalGridValue n k v≤finiteSphericalFieldValue n d w h ∧ + finiteSphericalFieldValue n d w h≤ sphericalGridValue n k u) ∧ + |sphericalGridDual k v-sphericalGridDual k u|≤H/(k+1:ℕ) := by + let e : Fin (d+1)→Time:=fun i=>⟨fieldExponents w i,fieldExponents_nonneg w hw i, + (fieldExponents_lt_one w hw hw1 i).le⟩ + let A : Fin (d+1)→Fin (k+2):=fun i=>(uniformQuantileCell k (e i)).castSucc + let B : Fin (d+1)→Fin (k+2):=fun i=>(uniformQuantileCell k (e i)).succ + let V:=fieldVariances d h + let v:=gridVariance (List.ofFn fun i=>(A i,V i)) + let u:=gridVariance (List.ofFn fun i=>(B i,V i)) + have hV : ∀ i,0≤V i:=fieldVariances_nonneg d h hh hh0 + have he : Monotone e:=(fieldExponents_strictMono w hw).monotone + have hA : Monotone A:=fun i j hij=>Fin.castSucc_le_castSucc_iff.mpr (uniformQuantileCell_mono k (he hij)) + have hB : Monotone B:=fun i j hij=>Fin.succ_le_succ_iff.mpr (uniformQuantileCell_mono k (he hij)) + have hvn : ∀ i,0≤v i:=fun i=>gridVariance_nonneg _ (by + intro c hc; obtain ⟨j,rfl⟩:=List.mem_ofFn.mp hc; exact hV j) i + have hun : ∀ i,0≤u i:=fun i=>gridVariance_nonneg _ (by + intro c hc; obtain ⟨j,rfl⟩:=List.mem_ofFn.mp hc; exact hV j) i + have hvsum : (∑ i,v i)=2*h (Fin.last d) := by + rw [gridVariance_sum,List.map_ofFn,List.sum_ofFn]; exact fieldVariances_sum d h + have husum : (∑ i,u i)=2*h (Fin.last d) := by + rw [gridVariance_sum,List.map_ofFn,List.sum_ofFn]; exact fieldVariances_sum d h + refine ⟨v,u,⟨hvn,?_⟩,⟨hun,?_⟩,?_,?_⟩ + · intro i + calc + v i≤∑ j,v j:=Finset.single_le_sum (fun j _=>hvn j) (Finset.mem_univ i) + _≤2*H:=by rw [hvsum]; linarith + · intro i + calc + u i≤∑ j,u j:=Finset.single_le_sum (fun j _=>hun j) (Finset.mem_univ i) + _≤2*H:=by rw [husum]; linarith + · intro n + have hlo:=sphericalGridValue_compress n k (List.ofFn fun i=>(A i,V i)) + (List.pairwise_ofFn.mpr (fun i j hij=>hA hij.le)) + (by intro c hc; obtain ⟨i,rfl⟩:=List.mem_ofFn.mp hc; exact hV i) + have hup:=sphericalGridValue_compress n k (List.ofFn fun i=>(B i,V i)) + (List.pairwise_ofFn.mpr (fun i j hij=>hB hij.le)) + (by intro c hc; obtain ⟨i,rfl⟩:=List.mem_ofFn.mp hc; exact hV i) + simp only [List.map_ofFn,Function.comp_def] at hlo hup + rw [←hlo,←hup,finiteSphericalFieldValue_eq_heat w h hw hw1 hh hh0] + constructor + · apply sphericalHeatValue_ofFn_mono_parameters + · intro i; exact uniformExponents_nonneg k (A i) + · intro i + have hi:=(uniformQuantileCell_bounds k (e i)).1 + change (uniformExponents k (A i))≤fieldExponents w i + simpa only [uniformExponents,uniformQuantileGrid,Nat.cast_add,Nat.cast_one] using (show (uniformQuantileGrid k (uniformQuantileCell k (e i)).castSucc : ℝ) ≤ (e i : ℝ) from hi) + · apply sphericalHeatValue_ofFn_mono_parameters + · exact fieldExponents_nonneg w hw + · intro i + have hi:=(uniformQuantileCell_bounds k (e i)).2 + change fieldExponents w i≤uniformExponents k (B i) + simpa only [uniformExponents,uniformQuantileGrid,Nat.cast_add,Nat.cast_one] using (show (e i : ℝ) ≤ (uniformQuantileGrid k (uniformQuantileCell k (e i)).succ : ℝ) from hi) + · have hg:=sphericalGridDual_step_gap A B V hV (fun i=>Fin.castSucc_le_succ _) + (fun i=>by dsimp [A,B]; simp) + refine hg.trans ?_ + rw [fieldVariances_sum] + have hk : (0:ℝ)<(k+1:ℕ):=by positivity + apply (div_le_iff₀ (by positivity : (0:ℝ)<2*(k+1:ℕ))).mpr + field_simp + nlinarith + + +theorem finiteSphericalFieldValue_depth_uniform (H : ℝ) (hH : 0≤H) + (ε : ℝ) (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, ∀ d (w h : Fin (d+1)→ℝ) + (hw : ∀ i,0(hw i).le) hw1)|<ε := by + obtain ⟨k,hk⟩:=exists_nat_gt (2*H/ε) + have hk0 : (0:ℝ)<(k+1:ℕ):=by + exact lt_of_le_of_lt (div_nonneg (mul_nonneg (by norm_num) hH) hε.le) + (hk.trans (by push_cast; linarith)) + have hgap : H/(k+1:ℕ)<ε/2 := by + apply (div_lt_iff₀ hk0).mpr + have hek : 2*H<ε*(k+1:ℕ):=by + have h:= (div_lt_iff₀ hε).mp hk + push_cast + nlinarith + linarith + have hu:=sphericalGridValue_compact_uniform k (2*H) + rw [Metric.tendstoUniformlyOn_iff] at hu + filter_upwards [hu (ε/2) (by positivity)] with n hn + intro d w h hw hw1 hh hh0 hhH + obtain ⟨v,u,hv,hu,hbr,hgap'⟩:=finiteSphericalFieldValue_grid_bracket w h hw hw1 hh hh0 H hhH k + have hf:=(finiteSphericalFieldValue_pointwise_dual w h hw hw1 hh hh0).choose_spec.2.2.2 + have hvl:=(sphericalGridValue_compact_uniform k (2*H)).tendsto_at hv + have hul:=(sphericalGridValue_compact_uniform k (2*H)).tendsto_at hu + have hBD : sphericalGridDual k v≤ sInf (finiteSphericalDualValues w h (fun i=>(hw i).le) hw1) := + le_of_tendsto_of_tendsto hvl hf (Eventually.of_forall fun m=>(hbr m).1) + have hDU : sInf (finiteSphericalDualValues w h (fun i=>(hw i).le) hw1)≤ sphericalGridDual k u := + le_of_tendsto_of_tendsto hf hul (Eventually.of_forall fun m=>(hbr m).2) + have hnv:=hn v hv + have hnu:=hn u hu + rw [Real.dist_eq] at hnv hnu + have hGU : sphericalGridDual k u-sphericalGridDual k v≤H/(k+1:ℕ) := by + linarith [(abs_le.mp hgap').1] + exact abs_lt.mpr ⟨by linarith [(abs_lt.mp hnv).2,(hbr n).1], + by linarith [(abs_lt.mp hnu).1,(hbr n).2]⟩ +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavitySphericalMoments.lean b/lean/OAI/Probability/Perceptron/Cavity/CavitySphericalMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..627884d73735834a269ddb745f8c49f87fa5d4ee --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavitySphericalMoments.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkRadialLimit +import OAI.Probability.Perceptron.Cavity.CavityQuadraticDrop + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +def cavityVectorField (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (y : Fin M→Spin L) : Spin L := + t • ∑ i,a i • y i + +lemma cavityLinearField_inner (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) (z : Spin L) (y : Fin M→Spin L) : + cavityLinearField M L a t z y=inner ℝ (cavityVectorField M L a t y) z := by + simp only [cavityLinearField,cavityVectorField,real_inner_smul_left, sum_inner, Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + rw [real_inner_comm z (y i)] + +lemma sphericalExp_square_le (n : ℕ) (R : ℝ) (x : Spin (n+1)) : + sphericalExp n x R ^2 ≤ sphericalExp n x (2*R) := by + let F : NormalizedSpin (n+1)→ℝ:=fun u=>Real.exp (R*inner ℝ x u.val) + have hm : MemLp F 2 (unitSphereLaw (n+1)) := by + apply (memLp_two_iff_integrable_sq (show AEStronglyMeasurable F _ from + (show Continuous F from by unfold F; fun_prop).aestronglyMeasurable)).mpr + exact unitSphere_continuous_integrable (by unfold F; fun_prop) + have hv:=variance_nonneg F (unitSphereLaw (n+1)) + rw [variance_eq_sub hm] at hv + have he : (∫ u,F u^2 ∂unitSphereLaw (n+1))=sphericalExp n x (2*R) := by + apply integral_congr_ae + filter_upwards [] with u + dsimp [F] + rw [←Real.exp_nat_mul] + congr 1 + norm_num only [Nat.cast_ofNat] + ring + change 0≤(∫ u,F u^2 ∂unitSphereLaw (n+1))-(∫ u,F u ∂unitSphereLaw (n+1))^2 at hv + rw [he] at hv + exact sub_nonneg.mp hv + +lemma cavitySphericalExp_average (M n : ℕ) (a : Fin M→ℝ) (t R : ℝ) : + (∫ y,sphericalExp n (cavityVectorField M (n+1) a t y) R + ∂Measure.pi (fun _=>stdGaussian (Spin (n+1))))= + Real.exp (R^2*t^2/2*∑ i,(a i)^2) := by + let μ:=unitSphereLaw (n+1) + let P:=Measure.pi (fun _ : Fin M=>stdGaussian (Spin (n+1))) + let F : NormalizedSpin (n+1)×(Fin M→Spin (n+1))→ℝ:= + fun p=>Real.exp (cavityLinearField M (n+1) a t (R • p.1.val) p.2) + have hF : Continuous F := by unfold F cavityLinearField; fun_prop + have he u : (∫ y,F (u,y) ∂P)=Real.exp (R^2*t^2/2*∑ i,(a i)^2) := by + have hh:=cavityLinearField_exp_moment M (n+1) a t (R • u.val) 1 + have hu : ‖u.val‖=1 := by simp + simpa [F,P,hu,norm_smul,Real.norm_eq_abs,sq_abs,mul_comm,mul_left_comm,mul_assoc] using hh + have hi : Integrable F (μ.prod P) := by + apply (integrable_prod_iff hF.aestronglyMeasurable).mpr + constructor + · exact ae_of_all _ fun u=>by + simpa [F,P] using cavityLinearField_exp_integrable M (n+1) a t (R • u.val) 1 + · have hn : (fun u=>∫ y,‖F (u,y)‖ ∂P)=fun _ : NormalizedSpin (n+1)=> + Real.exp (R^2*t^2/2*∑ i,(a i)^2) := by + ext u + simp only [F,Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact he u + rw [hn] + exact integrable_const _ + calc + _ = ∫ y,∫ u,F (u,y) ∂μ ∂P := by + apply integral_congr_ae + filter_upwards [] with y + apply integral_congr_ae + filter_upwards [] with u + simp only [F,cavityLinearField_inner,real_inner_smul_right] + _ = ∫ u,∫ y,F (u,y) ∂P ∂μ := (integral_integral_swap hi).symm + _ = _ := by simp only [he]; simp [μ] + +lemma cavitySphericalExp_second_moment (M n : ℕ) (a : Fin M→ℝ) (t R : ℝ) : + (∫ y,sphericalExp n (cavityVectorField M (n+1) a t y) R ^2 + ∂Measure.pi (fun _=>stdGaussian (Spin (n+1))))≤ + Real.exp (2*R^2*t^2*∑ i,(a i)^2) := by + let P:=Measure.pi (fun _ : Fin M=>stdGaussian (Spin (n+1))) + have hi : Integrable (fun y=>sphericalExp n (cavityVectorField M (n+1) a t y) (2*R)) P := by + by_contra he + have hh:=cavitySphericalExp_average M n a t (2*R) + rw [integral_undef he] at hh + exact (Real.exp_pos _).ne' hh.symm + have hm : Continuous (fun y=>sphericalExp n (cavityVectorField M (n+1) a t y) R) := + (sphericalExp_continuous n R).comp (by unfold cavityVectorField; fun_prop) + have hs : Integrable (fun y=>sphericalExp n (cavityVectorField M (n+1) a t y) R ^2) P := + hi.mono' (hm.pow 2).aestronglyMeasurable (ae_of_all _ fun y => by + rw [Real.norm_eq_abs,abs_of_nonneg (sq_nonneg _)] + exact sphericalExp_square_le n R _) + have hb:=integral_mono hs hi (fun y=>sphericalExp_square_le n R (cavityVectorField M (n+1) a t y)) + rw [cavitySphericalExp_average] at hb + convert hb using 1 + congr 1 + ring + + +lemma cavityLinearField_abs_bound (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) + (z : Spin L) (y : Fin M→Spin L) {A D : ℝ} (hA : 0≤A) + (ha : ∀ i,|a i|≤A) (hz : ‖z‖≤D) : + |cavityLinearField M L a t z y|≤|t| * ∑ i,A*D*‖y i‖ := by + unfold cavityLinearField + rw [abs_mul] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro i hi + rw [abs_mul] + calc + _≤A*(‖z‖*‖y i‖) := mul_le_mul (ha i) (abs_real_inner_le_norm z (y i)) + (abs_nonneg _) hA + _≤A*(D*‖y i‖) := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_right hz (norm_nonneg _)) hA + _=_ := by ring + +lemma cavity_angular_denominator {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M n : ℕ) + (a : S→Fin M→ℝ) (R W : S→ℝ) (ha : Measurable a) (hR : Measurable R) + (hW : Measurable W) (t : ℝ) {A C D : ℝ} (hA : 0≤A) + (haB : ∀ s i,|a s i|≤A) (hRB : ∀ s,|R s|≤D) (hWB : ∀ s,|W s|≤C) + (y : Fin M→Spin (n+1)) : + Real.exp (-C)≤∫ p : S×NormalizedSpin (n+1), + Real.exp (W p.1+cavityLinearField M (n+1) (a p.1) t (R p.1 •p.2.val) y) + ∂μ.prod (unitSphereLaw (n+1)) := by + let F : S×NormalizedSpin (n+1)→ℝ:=fun p=> + Real.exp (W p.1+cavityLinearField M (n+1) (a p.1) t (R p.1 •p.2.val) y) + have hm : Measurable F := by + have ham : Measurable (fun p : S×NormalizedSpin (n+1)=>a p.1) := ha.comp measurable_fst + have hRm : Measurable (fun p : S×NormalizedSpin (n+1)=>R p.1) := hR.comp measurable_fst + have hWm : Measurable (fun p : S×NormalizedSpin (n+1)=>W p.1) := hW.comp measurable_fst + unfold F cavityLinearField + fun_prop + have hi : Integrable F (μ.prod (unitSphereLaw (n+1))) := by + apply Integrable.of_bound hm.aestronglyMeasurable + (Real.exp (C+|t| * ∑ i,A*D*‖y i‖)) + filter_upwards [] with p + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + apply add_le_add (abs_le.mp (hWB p.1)).2 + have hu : ‖p.2.val‖=1 := by simp + exact (le_abs_self _).trans (cavityLinearField_abs_bound M (n+1) (a p.1) t _ y hA + (haB p.1) (by simpa [norm_smul,hu,Real.norm_eq_abs] using hRB p.1)) + change Real.exp (-C)≤∫ p,F p ∂μ.prod (unitSphereLaw (n+1)) + rw [integral_prod _ hi] + apply (show Real.exp (-C)=∫ _ : S,Real.exp (-C) ∂μ by simp).trans_le + apply integral_mono (integrable_const _) hi.integral_prod_left + intro s + have he : (∫ v,F (s,v) ∂unitSphereLaw (n+1))= + Real.exp (W s)*sphericalExp n (cavityVectorField M (n+1) (a s) t y) (R s) := by + simp only [F,cavityLinearField_inner,real_inner_smul_right,Real.exp_add,integral_const_mul] + rfl + change Real.exp (-C)≤∫ v,F (s,v) ∂unitSphereLaw (n+1) + rw [he] + calc + _≤Real.exp (W s) := Real.exp_le_exp.mpr (abs_le.mp (hWB s)).1 + _≤_ := le_mul_of_one_le_right (Real.exp_pos _).le (one_le_sphericalExp n _ _) + +theorem cavity_angular_Q_bound {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M n : ℕ) + (a b : S→Fin M→ℝ) (R W : S→ℝ) (ha : Measurable a) (hb : Measurable b) + (hR : Measurable R) (hW : Measurable W) (t u : ℝ) + {A B C D : ℝ} (hA : 0≤A) (hB : 0≤B) (hD : 0≤D) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) + (hRB : ∀ s,|R s|≤D) (hWB : ∀ s,|W s|≤C) : + (∫ y,(∫ p : S×NormalizedSpin (n+1), + Real.exp (W p.1+cavityLinearField M (n+1) (a p.1) t (R p.1 •p.2.val) y)* + |cavityQuadraticField M (n+1) (b p.1) u (R p.1 •p.2.val) y| + ∂μ.prod (unitSphereLaw (n+1)))/ + (∫ p : S×NormalizedSpin (n+1), + Real.exp (W p.1+cavityLinearField M (n+1) (a p.1) t (R p.1 •p.2.val) y) + ∂μ.prod (unitSphereLaw (n+1))) + ∂Measure.pi (fun _=>stdGaussian (Spin (n+1))))≤ + Real.exp (2*C+t^2*D^2*M*A^2)* + Real.sqrt (u^2*(D^2)^2*squareGaussianVariance*M*B^2) := by + have hz : Measurable (fun p : S×NormalizedSpin (n+1)=>R p.1 •p.2.val) := by + have hRm : Measurable (fun p : S×NormalizedSpin (n+1)=>R p.1) := hR.comp measurable_fst + fun_prop + have hzB (p : S×NormalizedSpin (n+1)) : ‖R p.1 •p.2.val‖^2≤D^2 := by + have hu : ‖p.2.val‖=1 := by simp + simp only [norm_smul,Real.norm_eq_abs,hu,mul_one] + exact (sq_le_sq₀ (abs_nonneg _) hD).2 (hRB p.1) + exact cavity_Q_normalized_bound (μ.prod (unitSphereLaw (n+1))) M (n+1) + (fun p=>a p.1) (fun p=>b p.1) (fun p=>R p.1 •p.2.val) (fun p=>W p.1) + (ha.comp measurable_fst) (hb.comp measurable_fst) hz (hW.comp measurable_fst) + t u hA hB (sq_nonneg D) (fun p=>haB p.1) (fun p=>hbB p.1) hzB (fun p=>hWB p.1) + (cavity_angular_denominator μ M n a R W ha hR hW t hA haB hRB hWB) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityTaylorFinite.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityTaylorFinite.lean new file mode 100644 index 0000000000000000000000000000000000000000..31a165b30d3b57da0dbd0c923d6f4aba87cfa340 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityTaylorFinite.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkModel +import OAI.Probability.Perceptron.Variational.DilationExpansion +import OAI.Probability.Perceptron.Brownian.CavityGaussianFields + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped Topology NNReal ENNReal BigOperators + +def cavityTaylorError (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) (N L q v : ℝ) : ℝ := + let t:=Real.log (Real.sqrt (1-q/(N+L))) + let u:=v/Real.sqrt (N+L) + (‖weightedDerivative g.d1 h1 1‖+‖weightedDerivative g.d2 h2 2‖)*t^2/2+ + ‖weightedDerivative g.d2 h2 1‖*|t| * |u|+ + ‖weightedDerivative g.d3 h3 1‖*|t| * u^2/2+‖g.d3‖*|u| ^3/6+ + |t+q/(2*N)| * ‖weightedDerivative g.d1 h1 1‖+ + |v/Real.sqrt (N+L)-v/Real.sqrt N| * ‖g.d1‖+ + |(v/Real.sqrt (N+L))^2/2-v^2/(2*N)| * ‖g.d2‖ + +lemma Jet3.cavity_finite_expansion (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) (N L q s v : ℝ) + (hρ : 0<1-q/(N+L)) : + |g.f (Real.sqrt (1-q/(N+L))*s+v/Real.sqrt (N+L))-g.f s- + (v/Real.sqrt N*g.d1 s+q/(2*N)*(g.d2 s-s*g.d1 s)+ + 1/(2*N)*g.d2 s*(v^2-q))|≤cavityTaylorError g h1 h2 h3 N L q v := by + let t:=Real.log (Real.sqrt (1-q/(N+L))) + let u:=v/Real.sqrt (N+L) + have he : Real.exp t=Real.sqrt (1-q/(N+L)) := Real.exp_log (Real.sqrt_pos.mpr hρ) + have ht:=g.cavity_log_dilation_expansion h1 h2 h3 s t u + rw [he] at ht + have hlin : |(t+q/(2*N))*(s*g.d1 s)|≤|t+q/(2*N)| * ‖weightedDerivative g.d1 h1 1‖ := by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (by simpa using weightedDerivative_bound g.d1 h1 1 s) (abs_nonneg _) + have hshift : |(u-v/Real.sqrt N)*g.d1 s|≤|u-v/Real.sqrt N| * ‖g.d1‖ := by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (g.d1.norm_coe_le_norm s) (abs_nonneg _) + have hquad : |(u^2/2-v^2/(2*N))*g.d2 s|≤|u^2/2-v^2/(2*N)| * ‖g.d2‖ := by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (g.d2.norm_coe_le_norm s) (abs_nonneg _) + calc + _=|(g.f (Real.sqrt (1-q/(N+L))*s+u)-g.f s-t*s*g.d1 s-u*g.d1 s-u^2/2*g.d2 s)+ + (t+q/(2*N))*(s*g.d1 s)+(u-v/Real.sqrt N)*g.d1 s+ + (u^2/2-v^2/(2*N))*g.d2 s| := by dsimp [u]; congr 1; ring + _≤|g.f (Real.sqrt (1-q/(N+L))*s+u)-g.f s-t*s*g.d1 s-u*g.d1 s-u^2/2*g.d2 s|+ + |(t+q/(2*N))*(s*g.d1 s)|+|(u-v/Real.sqrt N)*g.d1 s|+ + |(u^2/2-v^2/(2*N))*g.d2 s| := by + exact (abs_add_le _ _).trans (add_le_add ((abs_add_le _ _).trans + (add_le_add (abs_add_le _ _) le_rfl)) le_rfl) + _≤_ := add_le_add (add_le_add (add_le_add ht hlin) hshift) hquad + +theorem cavity_pattern_sum_expansion (n M L : ℕ) (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) + (a : Fin M→Fin (n+1)→ℝ) (x : NormalizedSpin (n+1)) (z : Spin L) + (y : Fin M→Spin L) (hρ : ‖z‖^2<(n+1:ℕ)+L) : + |(∑ i,g.f (Real.sqrt (1-‖z‖^2/((n+1:ℕ)+L))*(∑ j,a i j*x.val j)+ + inner ℝ z (y i)/Real.sqrt ((n+1:ℕ)+L)))- + normalizedPatternEnergy (n+1) M g.f a x- + (cavityLinearField M L (fun i=>g.d1 (∑ j,a i j*x.val j)) + (Real.sqrt (n+1:ℕ))⁻¹ z y+ + ‖z‖^2/2*bulkC (n+1) M g a x+ + cavityQuadraticField M L (fun i=>g.d2 (∑ j,a i j*x.val j)) + (1/(2*(n+1:ℕ))) z y)|≤ + ∑ i,cavityTaylorError g h1 h2 h3 (n+1:ℕ) L (‖z‖^2) (inner ℝ z (y i)) := by + have hp : (0:ℝ)<((n+1:ℕ):ℝ)+L := by positivity + have hr : 0<1-‖z‖^2/((n+1:ℕ)+L) := sub_pos.mpr ((div_lt_one hp).mpr hρ) + have hs:=Finset.sum_le_sum (s:=Finset.univ) (fun i _=> + g.cavity_finite_expansion h1 h2 h3 (n+1:ℕ) L (‖z‖^2) + (∑ j,a i j*x.val j) (inner ℝ z (y i)) hr) + have he : cavityLinearField M L (fun i=>g.d1 (∑ j,a i j*x.val j)) + (Real.sqrt (n+1:ℕ))⁻¹ z y+ + ‖z‖^2/2*bulkC (n+1) M g a x+ + cavityQuadraticField M L (fun i=>g.d2 (∑ j,a i j*x.val j)) + (1/(2*(n+1:ℕ))) z y = + ∑ i, (inner ℝ z (y i)/Real.sqrt (n+1:ℕ)*g.d1 (∑ j,a i j*x.val j)+ + ‖z‖^2/(2*(n+1:ℕ))*(g.d2 (∑ j,a i j*x.val j)- + (∑ j,a i j*x.val j)*g.d1 (∑ j,a i j*x.val j))+ + 1/(2*(n+1:ℕ))*g.d2 (∑ j,a i j*x.val j)*((inner ℝ z (y i))^2-‖z‖^2)) := by + unfold cavityLinearField cavityQuadraticField bulkC + simp only [←mul_assoc,Finset.mul_sum,←Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i hi + ring + rw [he] + unfold normalizedPatternEnergy + rw [←Finset.sum_sub_distrib,←Finset.sum_sub_distrib] + exact (Finset.abs_sum_le_sum_abs _ _).trans hs + +lemma cavity_log_small {x : ℝ} (hx : 0≤x) (hx' : x≤1/2) : + |Real.log (1-x)|≤2*x ∧ |Real.log (1-x)+x|≤2*x^2 := by + have ha : |x|<1 := by rw [abs_of_nonneg hx]; linarith + have h₀:=Real.abs_log_sub_add_sum_range_le ha 0 + have h₁:=Real.abs_log_sub_add_sum_range_le ha 1 + simp only [Finset.range_zero,Finset.sum_empty,zero_add,pow_one,abs_of_nonneg hx] at h₀ + simp only [Finset.sum_range_succ,Finset.range_zero,Finset.sum_empty, + zero_add,Nat.cast_zero,pow_one,div_one,abs_of_nonneg hx] at h₁ + constructor + · apply h₀.trans + apply (div_le_iff₀ (by linarith : 0<1-x)).mpr + nlinarith + · apply (by simpa only [add_comm] using h₁ : |Real.log (1-x)+x|≤x^2/(1-x)).trans + apply (div_le_iff₀ (by linarith : 0<1-x)).mpr + nlinarith [mul_nonneg (sq_nonneg x) (show 0≤1-2*x by linarith)] + +lemma cavity_scale_log_bounds {N L D q : ℝ} (hN : 0(i.val:ℝ)*(q/L)-F i.val)) := + (Set.finite_range _).bddAbove + obtain ⟨C,hC⟩:=hb + refine ⟨C,?_⟩ + intro n + induction n using Nat.strong_induction_on with + | h n ih => + by_cases hn : n(C+q/L)/(n+1:ℕ)) atTop (𝓝 0) := by + simpa only [Nat.cast_add,Nat.cast_one,div_eq_mul_inv,one_mul,mul_zero] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul (C+q/L) + filter_upwards [ht.eventually (Iio_mem_nhds hδ)] with n hn + have hp : (0:ℝ)<(n+1:ℕ) := by positivity + apply (le_div_iff₀ hp).mpr + have he : (C+q/L)<δ*(n+1:ℕ) := (div_lt_iff₀ hp).mp hn + have hh:=hC n + push_cast at * + nlinarith + +lemma cavity_averaged_log_lower (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) {α : ℝ} (hα : 0<α) (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) {ε : ℝ} (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop,(terminalVariational P α g.f).toReal-ε≤ + cavityAveragedLog α g.f n/(n+1:ℕ) := by + obtain ⟨G⟩:=exists_cavityGoodParameters hα.le g.f + let V:=(terminalVariational P α g.f).toReal + let C:=α*‖g.dilationMark h1‖/2+‖g.f‖+1 + have ht : Tendsto (fun k : ℕ=>Real.log (cavityShellMass k)/(k+1:ℕ)-C/(k+1:ℕ)) atTop (𝓝 0) := by + have hc : Tendsto (fun k : ℕ=>C/(k+1:ℕ)) atTop (𝓝 0) := by + simpa only [Nat.cast_add,Nat.cast_one,div_eq_mul_inv,one_mul,mul_zero] using + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul C + simpa only [sub_zero] using cavityShell_log_sublinear.sub hc + obtain ⟨k,hk,hc⟩:=((cavity_averaged_increment_good P hB hα g h1 h2 h3 G + (show 0<ε/3 by positivity)).and + (ht.eventually (Ioi_mem_nhds (show -ε/3<0 by linarith)))).exists + have hi:=hk 1 (by norm_num) + let q:=Real.log (cavityShellMass k)-α*‖g.dilationMark h1‖/2+ + (k+1:ℕ)*(V-ε/3)-‖g.f‖-1 + have hq : q/(k+1:ℕ)>V-2*ε/3 := by + have hp : (0:ℝ)<(k+1:ℕ):=by positivity + have he : q/(k+1:ℕ)=V-ε/3+ + (Real.log (cavityShellMass k)/(k+1:ℕ)-C/(k+1:ℕ)) := by + dsimp [q,C] + field_simp + ring + rw [he] + linarith + filter_upwards [block_increment_asymptotic_lower (cavityAveragedLog α g.f) + (Nat.succ_pos k) (q:=q) hi (show 0<ε/3 by positivity)] with n hn + change V-ε≤_ + linarith + + +lemma normalizedPatternLog_integrable (n M : ℕ) (f : ℝ→ᵇℝ) : + Integrable (normalizedPatternLog n M f) (finitePatternRowsLaw (n+1) M) := by + apply Integrable.of_bound (normalizedPatternLog_measurable n M f).aestronglyMeasurable (M*‖f‖) + filter_upwards [] with a + rw [Real.norm_eq_abs] + simpa only [normalizedPatternLog,tiltPartition,one_mul,Function.comp_apply,id_eq] using + tilt_log_partition_bound (unitSphereLaw (n+1)) + ((normalizedPatternEnergy_continuous (n+1) M f).measurable.comp (measurable_const.prodMk measurable_id)) + (by positivity : 0≤M*‖f‖) (normalizedPatternEnergy_bound _ _ _ a) + +lemma bulkExpectedLog_unperturbed_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) : + |bulkExpectedLog n M f v-∫ a,normalizedPatternLog n M f a ∂finitePatternRowsLaw (n+1) M|≤ + Real.pi*bulkFeatureBound (n+1) v^2 := by + have hj:=cavity_gaussian_joint_log_integrable (finitePatternRowsLaw (n+1) M) + (unitSphereLaw (n+1)) (normalizedPatternEnergy (n+1) M f) (bulkFeature (n+1) v) + (normalizedPatternEnergy_continuous (n+1) M f).measurable + (bulkFeature_continuous (n+1) v).measurable + (by positivity : 0≤M*‖f‖) (Real.sqrt_nonneg _) + (normalizedPatternEnergy_bound _ _ _) + (fun x=>(bulkFeature_norm _ _ _).le) + have hp (a : Fin M→Fin (n+1)→ℝ) : + |(∫ z,Real.log (tiltPartition (unitSphereLaw (n+1)) + (fun x=>normalizedPatternEnergy (n+1) M f a x+inner ℝ (bulkFeature (n+1) v x) z) 1) + ∂stdGaussian (BulkMark (n+1)))-normalizedPatternLog n M f a|≤ + Real.pi*bulkFeatureBound (n+1) v^2 := by + have h:=independentGaussian_covariance_comparison (unitSphereLaw (n+1)) + (V:=fun _=>(0:BulkMark (n+1))) + ((normalizedPatternEnergy_continuous (n+1) M f).measurable.comp (measurable_const.prodMk measurable_id)) + measurable_const (bulkFeature_continuous (n+1) v).measurable + (by positivity : 0≤M*‖f‖) (Real.sqrt_nonneg _) + (normalizedPatternEnergy_bound _ _ _ a) + (fun _=>by simp) (fun x=>(bulkFeature_norm _ _ _).le) + (sq_nonneg (bulkFeatureBound (n+1) v)) (fun x y=>by + simp only [inner_zero_left,sub_zero] + simpa only [bulkFeature_norm,pow_two] using abs_real_inner_le_norm (bulkFeature (n+1) v x) (bulkFeature (n+1) v y)) + simpa only [inner_zero_left,add_zero,integral_const,probReal_univ,one_smul, + tiltPartition,one_mul,normalizedPatternLog,Function.comp_apply,id_eq] using h + have hJ : Integrable (fun a : Fin M→Fin (n+1)→ℝ=>∫ z,Real.log + (tiltPartition (unitSphereLaw (n+1)) (bulkHamiltonian (n+1) M f v a z) 1) + ∂stdGaussian (BulkMark (n+1))) (finitePatternRowsLaw (n+1) M) := hj.integral_prod_left + rw [bulkExpectedLog_nested,←integral_sub hJ (normalizedPatternLog_integrable n M f)] + apply (abs_integral_le_integral_abs).trans + calc + (∫ a,|((∫ z,Real.log (tiltPartition (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a z) 1) ∂stdGaussian (BulkMark (n+1)))- + normalizedPatternLog n M f a)| ∂finitePatternRowsLaw (n+1) M)≤ + ∫ _ : Fin M→Fin (n+1)→ℝ,Real.pi*bulkFeatureBound (n+1) v^2 ∂finitePatternRowsLaw (n+1) M := + integral_mono (hj.integral_prod_left.sub (normalizedPatternLog_integrable n M f)).abs (integrable_const _) hp + _=_ := by simp + +lemma cavityAveragedLog_unperturbed_bound {α : ℝ} (_hα : 0≤α) (f : ℝ→ᵇℝ) (n : ℕ) : + |cavityAveragedLog α f n/(n+1:ℕ)-expectedPressure α 1 f (n+1)|≤ + 4*Real.pi*bulkScale (n+1)^2/(n+1:ℕ) := by + let A:=∫ a,normalizedPatternLog n (patternCount α (n+1)) f a ∂finitePatternRowsLaw (n+1) (patternCount α (n+1)) + have he : expectedPressure α 1 f (n+1)=A/(n+1:ℕ) := by + unfold expectedPressure + simp_rw [←normalizedPatternLog_source α 1 f n,one_smul] + rw [integral_const_mul] + change (1/(n+1:ℕ))*A=A/(n+1:ℕ) + ring + have hv : ∀ᵐ v ∂bulkParameterLaw,|bulkExpectedLog n (patternCount α (n+1)) f v-A|≤ + 4*Real.pi*bulkScale (n+1)^2 := by + filter_upwards [bulkParameterLaw_ae] with v hv + have hb:=bulkFeatureBound_sq_le (n+1) v (by norm_num : (0:ℝ)≤2) + (fun p=>abs_le.mpr ⟨by linarith [(hv (p+1)).1],(hv (p+1)).2⟩) + have hi:=bulkExpectedLog_unperturbed_bound n (patternCount α (n+1)) f v + change |bulkExpectedLog n (patternCount α (n+1)) f v-A|≤_ at hi + nlinarith [Real.pi_pos] + have ha : |cavityAveragedLog α f n-A|≤4*Real.pi*bulkScale (n+1)^2 := by + have hi:=(bulkExpectedLog_parameter_integrable n (patternCount α (n+1)) f).sub (integrable_const A) + have hh:=integral_mono_ae hi.abs (integrable_const (4*Real.pi*bulkScale (n+1)^2)) hv + have hh':=abs_integral_le_integral_abs (f:=fun v=>bulkExpectedLog n (patternCount α (n+1)) f v-A) (μ:=bulkParameterLaw) + simp only [integral_sub (bulkExpectedLog_parameter_integrable _ _ f) (integrable_const A), + integral_const,probReal_univ,one_smul] at hh hh' + exact hh'.trans hh + rw [he,←sub_div,abs_div,abs_of_pos (by positivity : (0:ℝ)<(n+1:ℕ))] + exact div_le_div_of_nonneg_right ha (by positivity) + +lemma bulkScale_per_coordinate_tendsto : + Tendsto (fun n : ℕ=>4*Real.pi*bulkScale (n+1)^2/(n+1:ℕ)) atTop (𝓝 0) := by + have hN : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)) atTop atTop := by + exact tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have ht:=(tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1/4)).comp hN + have he (n : ℕ) : bulkScale (n+1)^2/(n+1:ℕ)=((n+1:ℕ):ℝ)^(-(1:ℝ)/4) := by + rw [bulkScale_sq_eq_rpow] + have hs:=Real.rpow_sub (by positivity : (0:ℝ)<(n+1:ℕ)) ((3:ℝ)/4) 1 + norm_num at hs + simpa only [Nat.cast_add,Nat.cast_one,neg_div] using hs.symm + convert ht.const_mul (4*Real.pi) using 1 + · funext n + rw [mul_div_assoc,he] + simp only [Function.comp_apply,neg_div] + · simp +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityTrueShellLower.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityTrueShellLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..a89153820155aa32ac407aee4b7215a108898c8e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityTrueShellLower.lean @@ -0,0 +1,224 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityTrueShellQ + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_sphericalExp_bound (k : ℕ) (Y : Spin (k+1)) (R : ℝ) : + sphericalExp k Y R≤Real.exp (|R| *‖Y‖) := by + simpa [sphericalExp] using sphericalExp_le_mul k R Y 0 + +lemma cavity_shell_compensator_bound (k : ℕ) (W C K A : ℝ) + (hK : 0≤K) (hC : |C|≤K) (hW : |W|≤A) + (z : {z : Spin (k+1) // z∈cavityShell (k+1)}) : + |W+‖z.val‖^2*C/2|≤A+((k+1:ℕ)+1)*K/2 := by + apply (abs_add_le _ _).trans + apply add_le_add hW + rw [abs_div,abs_mul,abs_of_nonneg (sq_nonneg _)] + norm_num + apply div_le_div_of_nonneg_right _ (by norm_num) + simpa only [Nat.cast_add,Nat.cast_one] using + ((mul_le_mul_of_nonneg_left hC (sq_nonneg _)).trans + (mul_le_mul_of_nonneg_right z.prop.2 hK)) + +theorem cavity_true_shell_linear_lower {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (n k : ℕ) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (W C : S→ℝ) (Y : S→Spin (k+1)) + (hW : Measurable W) (hC : Measurable C) (hY : Measurable Y) + {A K D : ℝ} (hA : 0≤A) (hK : 0≤K) (hD : 0≤D) + (hWA : ∀ s,|W s|≤A) (hCK : ∀ s,|C s|≤K) (hYD : ∀ s,‖Y s‖≤D) : + Real.log (∫ s,Real.exp (W s+(k+1:ℕ)*C s/2)* + sphericalExp k (Y s) (Real.sqrt (k+1:ℕ)) ∂μ)-K/2≤ + Real.log (∫ p : S×{z : Spin (k+1) // z∈cavityShell (k+1)}, + Real.exp (W p.1+‖p.2.val‖^2*C p.1/2+inner ℝ (Y p.1) p.2.val) + ∂μ.prod (cavityShellProbability n (k+1))) := by + have := cavityShellProbability_probability n (k+1) hp + let R : ℝ:=Real.sqrt (k+1:ℕ) + let G : S→ℝ:=fun s=>Real.exp (W s+(k+1:ℕ)*C s/2)*sphericalExp k (Y s) R + let F : S×{z : Spin (k+1) // z∈cavityShell (k+1)}→ℝ:=fun p=> + Real.exp (W p.1+‖p.2.val‖^2*C p.1/2+inner ℝ (Y p.1) p.2.val) + have hbase (s : S) : |W s+(k+1:ℕ)*C s/2|≤A+(k+1:ℕ)*K/2 := by + apply (abs_add_le _ _).trans + apply add_le_add (hWA s) + rw [abs_div,abs_mul,abs_of_nonneg (Nat.cast_nonneg _),abs_of_pos (by norm_num : (0:ℝ)<2)] + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (hCK s) (by positivity)) (by norm_num) + have hgm : Measurable G := + ((hW.add ((hC.const_mul _).div_const _)).exp).mul + ((sphericalExp_continuous k R).measurable.comp hY) + have hgi : Integrable G μ := by + apply Integrable.of_bound hgm.aestronglyMeasurable (Real.exp (A+(k+1:ℕ)*K/2+R*D)) + exact ae_of_all _ fun s=>by + dsimp [G] + rw [abs_mul,abs_of_pos (Real.exp_pos _), + abs_of_nonneg ((show (0:ℝ)≤1 by norm_num).trans (one_le_sphericalExp _ _ _)),Real.exp_add (A+(k+1:ℕ)*K/2) (R*D)] + apply mul_le_mul + (Real.exp_le_exp.mpr ((le_abs_self _).trans (hbase s))) + ((cavity_sphericalExp_bound k (Y s) R).trans (Real.exp_le_exp.mpr _)) + ((by norm_num : (0:ℝ)≤1).trans (one_le_sphericalExp _ _ _)) (Real.exp_pos _).le + rw [abs_of_nonneg (Real.sqrt_nonneg _)] + exact mul_le_mul_of_nonneg_left (hYD s) (Real.sqrt_nonneg _) + have hfm : Measurable F := by + dsimp [F] + fun_prop + have hfb (p : S×{z : Spin (k+1) // z∈cavityShell (k+1)}) : + |W p.1+‖p.2.val‖^2*C p.1/2+inner ℝ (Y p.1) p.2.val|≤ + A+((k+1:ℕ)+1)*K/2+D*((k+1:ℕ)+1) := by + apply (abs_add_le _ _).trans + apply add_le_add (cavity_shell_compensator_bound k _ _ _ _ hK (hCK p.1) (hWA p.1) p.2) + exact (abs_real_inner_le_norm _ _).trans + (mul_le_mul (hYD p.1) (cavity_shell_norm_bound (k+1) p.2) (norm_nonneg _) hD) + have hfi : Integrable F (μ.prod (cavityShellProbability n (k+1))) := + cavity_exp_integrable_bound _ (by fun_prop) hfb + have hgp : 0<∫ s,G s ∂μ := by + have hbi := cavity_exp_integrable_bound μ (by fun_prop) hbase + have hpos : 0<∫ s,Real.exp (W s+(k+1:ℕ)*C s/2) ∂μ := by + simpa only [tiltPartition,one_mul] using tilt_partition_pos μ (v:=fun s=>W s+(k+1:ℕ)*C s/2) + (hW.add ((hC.const_mul _).div_const _)) (by positivity) hbase 1 + apply hpos.trans_le (integral_mono hbi hgi _) + intro s + exact le_mul_of_one_le_right (Real.exp_pos _).le (one_le_sphericalExp _ _ _) + have hpoint (s : S) : Real.exp (-K/2)*G s≤ + ∫ z,F (s,z) ∂cavityShellProbability n (k+1) := by + rw [show (∫ z,F (s,z) ∂cavityShellProbability n (k+1))= + ((cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1)))⁻¹* + ∫ z in cavityShell (k+1),Real.exp (W s+‖z‖^2*C s/2+inner ℝ (Y s) z) + ∂(cavitySphereLaw n (k+1) : Measure (Spin (k+1))) from + cavityShellProbability_integral n (k+1) (fun z=>Real.exp (W s+‖z‖^2*C s/2+inner ℝ (Y s) z))] + have hm : 0<(cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1)) := + ENNReal.toReal_pos hp (measure_ne_top _ _) + have hh:=mul_le_mul_of_nonneg_left + (cavitySphereLaw_shell_lower n k (W s) (C s) (Y s) (hCK s)) (inv_nonneg.mpr hm.le) + simpa only [G,R,←mul_assoc,inv_mul_cancel₀ hm.ne',one_mul] using hh + have hcompare : Real.exp (-K/2)*(∫ s,G s ∂μ)≤∫ p,F p ∂μ.prod (cavityShellProbability n (k+1)) := by + rw [←integral_const_mul,integral_prod _ hfi] + exact integral_mono (hgi.const_mul _) hfi.integral_prod_left hpoint + have hlog:=Real.log_le_log (mul_pos (Real.exp_pos _) hgp) hcompare + rw [Real.log_mul (Real.exp_pos _).ne' hgp.ne',Real.log_exp] at hlog + change Real.log (∫ s,G s ∂μ)-K/2≤Real.log (∫ p,F p ∂μ.prod (cavityShellProbability n (k+1))) + linarith + + +lemma cavityVectorField_norm_le (M L : ℕ) (a : Fin M→ℝ) (t : ℝ) + (y : Fin M→Spin L) {A : ℝ} (hA : 0≤A) (ha : ∀ i,|a i|≤A) : + ‖cavityVectorField M L a t y‖≤|t| *∑ i,A*‖y i‖ := by + unfold cavityVectorField + rw [norm_smul,Real.norm_eq_abs] + apply mul_le_mul_of_nonneg_left _ (abs_nonneg _) + apply (norm_sum_le _ _).trans + apply Finset.sum_le_sum + intro i hi + rw [norm_smul,Real.norm_eq_abs] + exact mul_le_mul (ha i) le_rfl (norm_nonneg _) hA + +lemma cavity_angular_partition {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M k : ℕ) + (a : S→Fin M→ℝ) (V : S→ℝ) (ha : Measurable a) (hV : Measurable V) + (t R : ℝ) {A C : ℝ} (hA : 0≤A) (hC : 0≤C) + (haB : ∀ s i,|a s i|≤A) (hVB : ∀ s,|V s|≤C) (y : Fin M→Spin (k+1)) : + (∫ p : S×NormalizedSpin (k+1),Real.exp (V p.1+ + cavityLinearField M (k+1) (a p.1) t (R •p.2.val) y) ∂μ.prod (unitSphereLaw (k+1)))= + ∫ s,Real.exp (V s)*sphericalExp k (cavityVectorField M (k+1) (a s) t y) R ∂μ := by + have hm : Measurable (fun p : S×NormalizedSpin (k+1)=>V p.1+ + cavityLinearField M (k+1) (a p.1) t (R •p.2.val) y) := by + have ham : Measurable (fun p : S×NormalizedSpin (k+1)=>a p.1) := ha.comp measurable_fst + have hVm : Measurable (fun p : S×NormalizedSpin (k+1)=>V p.1) := hV.comp measurable_fst + unfold cavityLinearField + fun_prop + have hi := cavity_exp_integrable_bound (μ.prod (unitSphereLaw (k+1))) hm + (C:=|C|+|t| *∑ i,A*|R| *‖y i‖) (fun p=>by + rw [abs_of_nonneg hC] + apply (abs_add_le _ _).trans + apply add_le_add (hVB p.1) + apply cavityLinearField_abs_bound M (k+1) (a p.1) t _ y hA (haB p.1) + have hu : ‖p.2.val‖=1 := by simp + simp only [norm_smul,Real.norm_eq_abs,hu,mul_one,le_refl]) + rw [integral_prod _ hi] + apply integral_congr_ae + exact ae_of_all _ fun s=>by + simp only [cavityLinearField_inner,real_inner_smul_right,Real.exp_add,integral_const_mul,sphericalExp] + +lemma cavity_angular_log_integrable {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (M k : ℕ) + (a : S→Fin M→ℝ) (V : S→ℝ) (ha : Measurable a) (hV : Measurable V) + (t R : ℝ) {A C : ℝ} (hA : 0≤A) (hC : 0≤C) + (haB : ∀ s i,|a s i|≤A) (hVB : ∀ s,|V s|≤C) : + Integrable (fun y : Fin M→Spin (k+1)=>Real.log (∫ s,Real.exp (V s)* + sphericalExp k (cavityVectorField M (k+1) (a s) t y) R ∂μ)) + (Measure.pi (fun _=>stdGaussian (Spin (k+1)))) := by + have hz : Measurable (fun p : S×NormalizedSpin (k+1)=>R •p.2.val) := by fun_prop + have hzB (p : S×NormalizedSpin (k+1)) : ‖R •p.2.val‖≤|R| := by + have hu : ‖p.2.val‖=1 := by simp + simp only [norm_smul,Real.norm_eq_abs,hu,mul_one,le_refl] + have h:=cavity_quadratic_log_integrable (μ.prod (unitSphereLaw (k+1))) M (k+1) + (fun p=>a p.1) (fun _ _=>0) (fun p=>R •p.2.val) (fun p=>V p.1) + (ha.comp measurable_fst) measurable_const hz (hV.comp measurable_fst) t 0 + hA (B:=0) (by norm_num) hC (abs_nonneg R) + (fun p=>haB p.1) (fun _ _=>by simp) hzB (fun p=>hVB p.1) + simp only [cavityQuadraticField,zero_mul,add_zero] at h + simpa only [cavity_angular_partition μ M k a V ha hV t R hA hC haB hVB] using h + +theorem cavity_expected_shell_lower {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (n k M : ℕ) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (a b : S→Fin M→ℝ) (W C : S→ℝ) + (ha : Measurable a) (hb : Measurable b) (hW : Measurable W) (hC : Measurable C) + (t u : ℝ) {A B E K : ℝ} (hA : 0≤A) (hB : 0≤B) (hE : 0≤E) (hK : 0≤K) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) + (hWE : ∀ s,|W s|≤E) (hCK : ∀ s,|C s|≤K) : + (∫ y : Fin M→Spin (k+1),Real.log (∫ p : S×{z : Spin (k+1) // z∈cavityShell (k+1)}, + Real.exp (W p.1+‖p.2.val‖^2*C p.1/2+cavityLinearField M (k+1) (a p.1) t p.2.val y+ + cavityQuadraticField M (k+1) (b p.1) u p.2.val y) + ∂μ.prod (cavityShellProbability n (k+1))) ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))≥ + (∫ y : Fin M→Spin (k+1),Real.log (∫ s,Real.exp (W s+(k+1:ℕ)*C s/2)* + sphericalExp k (cavityVectorField M (k+1) (a s) t y) (Real.sqrt (k+1:ℕ)) ∂μ) + ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))-K/2- + Real.exp (2*(E+((k+1:ℕ)+1)*K/2)+t^2*((k+1:ℕ)+1)^2*M*A^2)* + Real.sqrt (u^2*(((k+1:ℕ)+1)^2)^2*squareGaussianVariance*M*B^2) := by + have := cavityShellProbability_probability n (k+1) hp + let U : S×{z : Spin (k+1) // z∈cavityShell (k+1)}→ℝ := fun p=>W p.1+‖p.2.val‖^2*C p.1/2 + have hU : Measurable U := by + have hmW : Measurable (fun p : S×{z : Spin (k+1) // z∈cavityShell (k+1)}=>W p.1) := hW.comp measurable_fst + have hmC : Measurable (fun p : S×{z : Spin (k+1) // z∈cavityShell (k+1)}=>C p.1) := hC.comp measurable_fst + dsimp [U] + fun_prop + have hUB (p) : |U p|≤E+((k+1:ℕ)+1)*K/2 := + cavity_shell_compensator_bound k _ _ _ _ hK (hCK p.1) (hWE p.1) p.2 + have hdrop:=cavity_true_shell_expected_drop μ n k M hp a b U ha hb hU t u + hA hB (by positivity) haB hbB hUB + have hlin : Integrable (fun y : Fin M→Spin (k+1)=>Real.log (∫ p, + Real.exp (U p+cavityLinearField M (k+1) (a p.1) t p.2.val y) + ∂μ.prod (cavityShellProbability n (k+1)))) (Measure.pi (fun _=>stdGaussian (Spin (k+1)))) := by + simpa only [cavityQuadraticField,zero_mul,add_zero] using + cavity_quadratic_log_integrable (μ.prod (cavityShellProbability n (k+1))) M (k+1) + (fun p=>a p.1) (fun p=>b p.1) (fun p=>p.2.val) U + (ha.comp measurable_fst) (hb.comp measurable_fst) measurable_snd.subtype_val hU t 0 + hA hB (by positivity) (by positivity) (fun p=>haB p.1) (fun p=>hbB p.1) + (fun p=>cavity_shell_norm_bound (k+1) p.2) hUB + have hVB (s) : |W s+(k+1:ℕ)*C s/2|≤E+(k+1:ℕ)*K/2 := by + apply (abs_add_le _ _).trans + apply add_le_add (hWE s) + rw [abs_div,abs_mul,abs_of_nonneg (Nat.cast_nonneg _),abs_of_pos (by norm_num : (0:ℝ)<2)] + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left (hCK s) (by positivity)) (by norm_num) + have hsph:=cavity_angular_log_integrable μ M k a (fun s=>W s+(k+1:ℕ)*C s/2) + ha (hW.add ((hC.const_mul _).div_const _)) t (Real.sqrt (k+1:ℕ)) hA (by positivity) haB hVB + have hcomp:=integral_mono (hsph.sub (integrable_const (K/2))) hlin (fun y=>by + have hym : Measurable (fun s=>cavityVectorField M (k+1) (a s) t y) := by + unfold cavityVectorField + fun_prop + have h:=cavity_true_shell_linear_lower μ n k hp W C _ hW hC hym hE hK + (D:=|t| *∑ i,A*‖y i‖) (by positivity) hWE hCK + (fun s=>cavityVectorField_norm_le M (k+1) (a s) t y hA (haB s)) + simpa only [Pi.sub_apply,U,cavityLinearField_inner] using h) + simp only [Pi.sub_apply] at hcomp + rw [integral_sub hsph (integrable_const (K/2)),integral_const,probReal_univ,smul_eq_mul,one_mul] at hcomp + exact (sub_le_sub_right hcomp _).trans hdrop + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityTrueShellQ.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityTrueShellQ.lean new file mode 100644 index 0000000000000000000000000000000000000000..95485f76677348843b9c97d159d491cb2b9d81df --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityTrueShellQ.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityShellPolar +import OAI.Probability.Perceptron.Cavity.CavityShellRestriction +import OAI.Probability.Perceptron.Cavity.CavityExpectedQDrop + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cavity_shell_norm_bound (L : ℕ) (z : {z : Spin L // z∈cavityShell L}) : + ‖z.val‖≤(L:ℝ)+1 := by + have hz := z.prop.2 + nlinarith [sq_nonneg (‖z.val‖-1),Nat.cast_nonneg (α:=ℝ) L] + +lemma cavityShellProbability_linear_one_le (n k : ℕ) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (Y : Spin (k+1)) : + 1≤∫ z : {z : Spin (k+1) // z∈cavityShell (k+1)},Real.exp (inner ℝ Y z.val) + ∂cavityShellProbability n (k+1) := by + have hm : 0<(cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1)) := + ENNReal.toReal_pos hp (measure_ne_top _ _) + have h := cavitySphereLaw_shell_lower n k 0 0 Y (K:=0) (by simp) + simp only [neg_zero,zero_div,Real.exp_zero,Nat.cast_add,Nat.cast_one,mul_zero, + add_zero,zero_add,one_mul] at h + have h1 : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))).real (cavityShell (k+1))≤ + ∫ z in cavityShell (k+1),Real.exp (inner ℝ Y z) ∂(cavitySphereLaw n (k+1) : Measure (Spin (k+1))) := by + exact (le_mul_of_one_le_right hm.le (one_le_sphericalExp _ _ _)).trans h + rw [cavityShellProbability_integral n (k+1) (fun z=>Real.exp (inner ℝ Y z))] + have hh := mul_le_mul_of_nonneg_left h1 (inv_nonneg.mpr hm.le) + simpa only [inv_mul_cancel₀ hm.ne'] using hh + +lemma cavity_true_shell_denominator {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (n k M : ℕ) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (a : S→Fin M→ℝ) (W : S×{z : Spin (k+1) // z∈cavityShell (k+1)}→ℝ) + (ha : Measurable a) (hW : Measurable W) (t : ℝ) {A C : ℝ} + (hA : 0≤A) (haB : ∀ s i,|a s i|≤A) (hWB : ∀ p,|W p|≤C) + (y : Fin M→Spin (k+1)) : + Real.exp (-C)≤∫ p : S×{z : Spin (k+1) // z∈cavityShell (k+1)}, + Real.exp (W p+cavityLinearField M (k+1) (a p.1) t p.2.val y) + ∂μ.prod (cavityShellProbability n (k+1)) := by + have := cavityShellProbability_probability n (k+1) hp + let F : S×{z : Spin (k+1) // z∈cavityShell (k+1)}→ℝ := fun p=> + Real.exp (W p+cavityLinearField M (k+1) (a p.1) t p.2.val y) + have hm : Measurable F := by + have ha' : Measurable (fun p : S×{z : Spin (k+1) // z∈cavityShell (k+1)} => a p.1) := ha.comp measurable_fst + unfold F cavityLinearField + fun_prop + have hi : Integrable F (μ.prod (cavityShellProbability n (k+1))) := by + apply Integrable.of_bound hm.aestronglyMeasurable + (Real.exp (C+|t| *∑ i,A*((k+1:ℕ)+1)*‖y i‖)) + exact ae_of_all _ fun p=>by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + exact add_le_add (abs_le.mp (hWB p)).2 ((le_abs_self _).trans + (cavityLinearField_abs_bound M (k+1) (a p.1) t p.2.val y hA (haB p.1) + (cavity_shell_norm_bound (k+1) p.2))) + change Real.exp (-C)≤∫ p,F p ∂μ.prod (cavityShellProbability n (k+1)) + rw [integral_prod _ hi] + apply (show Real.exp (-C)=∫ _ : S,Real.exp (-C) ∂μ by simp).trans_le + apply integral_mono_ae (integrable_const _) hi.integral_prod_left + filter_upwards [hi.prod_right_ae] with s hs + have hlin : Integrable (fun z : {z : Spin (k+1) // z∈cavityShell (k+1)}=> + Real.exp (cavityLinearField M (k+1) (a s) t z.val y)) (cavityShellProbability n (k+1)) := by + apply Integrable.of_bound (by unfold cavityLinearField; fun_prop) + (Real.exp (|t| *∑ i,A*((k+1:ℕ)+1)*‖y i‖)) + exact ae_of_all _ fun z=>by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans + (cavityLinearField_abs_bound M (k+1) (a s) t z.val y hA (haB s) + (cavity_shell_norm_bound (k+1) z))) + calc + _≤Real.exp (-C)*(∫ z : {z : Spin (k+1) // z∈cavityShell (k+1)}, + Real.exp (cavityLinearField M (k+1) (a s) t z.val y) ∂cavityShellProbability n (k+1)) := by + apply le_mul_of_one_le_right (Real.exp_pos _).le + simpa only [cavityLinearField_inner] using + cavityShellProbability_linear_one_le n k hp (cavityVectorField M (k+1) (a s) t y) + _≤∫ z,F (s,z) ∂cavityShellProbability n (k+1) := by + rw [←integral_const_mul] + apply integral_mono (hlin.const_mul _) hs + intro z + dsimp only [F] + rw [←Real.exp_add] + exact Real.exp_le_exp.mpr (add_le_add (abs_le.mp (hWB (s,z))).1 le_rfl) + +theorem cavity_true_shell_expected_drop {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (n k M : ℕ) + (hp : (cavitySphereLaw n (k+1) : Measure (Spin (k+1))) (cavityShell (k+1))≠0) + (a b : S→Fin M→ℝ) (W : S×{z : Spin (k+1) // z∈cavityShell (k+1)}→ℝ) + (ha : Measurable a) (hb : Measurable b) (hW : Measurable W) (t u : ℝ) + {A B C : ℝ} (hA : 0≤A) (hB : 0≤B) (hC : 0≤C) + (haB : ∀ s i,|a s i|≤A) (hbB : ∀ s i,|b s i|≤B) (hWB : ∀ p,|W p|≤C) : + (∫ y : Fin M→Spin (k+1),Real.log (∫ p : S×{z : Spin (k+1) // z∈cavityShell (k+1)}, + Real.exp (W p+cavityLinearField M (k+1) (a p.1) t p.2.val y+ + cavityQuadraticField M (k+1) (b p.1) u p.2.val y) + ∂μ.prod (cavityShellProbability n (k+1))) ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))≥ + (∫ y : Fin M→Spin (k+1),Real.log (∫ p : S×{z : Spin (k+1) // z∈cavityShell (k+1)}, + Real.exp (W p+cavityLinearField M (k+1) (a p.1) t p.2.val y) + ∂μ.prod (cavityShellProbability n (k+1))) ∂Measure.pi (fun _=>stdGaussian (Spin (k+1))))- + Real.exp (2*C+t^2*((k+1:ℕ)+1)^2*M*A^2)* + Real.sqrt (u^2*(((k+1:ℕ)+1)^2)^2*squareGaussianVariance*M*B^2) := by + have := cavityShellProbability_probability n (k+1) hp + exact cavity_expected_log_drop_quadratic (μ.prod (cavityShellProbability n (k+1))) M (k+1) + (fun p=>a p.1) (fun p=>b p.1) (fun p=>p.2.val) W + (ha.comp measurable_fst) (hb.comp measurable_fst) (measurable_snd.subtype_val) hW t u + hA hB hC (by positivity) (fun p=>haB p.1) (fun p=>hbB p.1) + (fun p=>cavity_shell_norm_bound (k+1) p.2) hWB + (cavity_true_shell_denominator μ n k M hp a W ha hW t hA haB hWB) + + +lemma cavity_exp_integrable_bound {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsFiniteMeasure μ] {H : S→ℝ} (hH : Measurable H) + {C : ℝ} (hB : ∀ s,|H s|≤C) : Integrable (fun s=>Real.exp (H s)) μ := by + apply Integrable.of_bound hH.exp.aestronglyMeasurable (Real.exp C) + exact ae_of_all _ fun s=>by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans (hB s)) + +lemma cavity_gibbs_log_factorization {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + (μ : Measure S) (ν : Measure T) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (H : S→ℝ) (V : S×T→ℝ) (hH : Measurable H) (hV : Measurable V) + {A B : ℝ} (hA : 0≤A) (hB : 0≤B) + (hHA : ∀ s,|H s|≤A) (hVB : ∀ p,|V p|≤B) : + Real.log (∫ p,Real.exp (H p.1+V p) ∂μ.prod ν)-Real.log (∫ s,Real.exp (H s) ∂μ)= + Real.log (∫ p,Real.exp (V p) ∂(tiltLaw μ H 1).prod ν) := by + have := tilt_law_probability μ hH hA hHA 1 + have hi : Integrable (fun p : S×T=>Real.exp (H p.1+V p)) (μ.prod ν) := cavity_exp_integrable_bound (μ.prod ν) ((hH.comp measurable_fst).add hV) + (fun p=>(abs_add_le _ _).trans (add_le_add (hHA p.1) (hVB p))) + have hj := cavity_exp_integrable_bound ((tiltLaw μ H 1).prod ν) hV hVB + have hp : 0<∫ s,Real.exp (H s) ∂μ := by + simpa only [tiltPartition,one_mul] using tilt_partition_pos μ hH hA hHA 1 + have hq : 0<∫ p,Real.exp (V p) ∂(tiltLaw μ H 1).prod ν := by + simpa only [tiltPartition,one_mul] using tilt_partition_pos ((tiltLaw μ H 1).prod ν) hV hB hVB 1 + have he : (∫ s,Real.exp (H s) ∂μ)*(∫ p,Real.exp (V p) ∂(tiltLaw μ H 1).prod ν)= + ∫ p,Real.exp (H p.1+V p) ∂μ.prod ν := by + rw [integral_prod _ hj,tilt_law_integral μ hH hA hHA 1] + simp only [tiltMean,tiltIntegral,tiltPartition,one_mul] + rw [mul_div_cancel₀ _ hp.ne',integral_prod _ hi] + apply integral_congr_ae + exact ae_of_all _ fun s=>by simp only [Real.exp_add,integral_const_mul] + rw [←he,Real.log_mul hp.ne' hq.ne'] + ring + +theorem cavity_actual_bulk_log_factorization (n L M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) + (a : BulkDisorder (n+1) M) + (hp : (cavitySphereLaw n L : Measure (Spin L)) (cavityShell L)≠0) + (V : CavityShellSpin n L→ℝ) (hV : Measurable V) {B : ℝ} + (hB : 0≤B) (hVB : ∀ p,|V p|≤B) : + Real.log (∫ p,Real.exp (bulkHamiltonian (n+1) M f v a.1 a.2 p.1+V p) + ∂cavityShellBaseLaw n L)- + bulkLogPartition n M f v a.1 a.2= + Real.log (∫ p,Real.exp (V p) ∂(tiltLaw (unitSphereLaw (n+1)) + (bulkHamiltonian (n+1) M f v a.1 a.2) 1).prod (cavityShellProbability n L)) := by + have := cavityShellProbability_probability n L hp + exact cavity_gibbs_log_factorization (unitSphereLaw (n+1)) (cavityShellProbability n L) + (bulkHamiltonian (n+1) M f v a.1 a.2) V + (bulkHamiltonian_section_measurable (n+1) M f v a) hV + (A:=M*‖f‖+bulkFeatureBound (n+1) v*‖a.2‖) + (by apply add_nonneg (by positivity); apply mul_nonneg; unfold bulkFeatureBound; positivity; positivity) + hB (bulkHamiltonian_bound (n+1) M f v a) hVB + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityUncappedLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityUncappedLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..9dfe22471d263a15f201bb090c0fec43ba4fee90 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityUncappedLimit.lean @@ -0,0 +1,175 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityBulkUncappedLog +import OAI.Probability.Perceptron.Cavity.CavityCounts +import OAI.Probability.Perceptron.Cavity.CavitySphericalGrid +import OAI.Probability.Perceptron.Cavity.BulkCavityData +import OAI.Probability.Perceptron.Variational.UniformUncapLimit + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open Filter MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction NNReal + +theorem cavityBulkFullLog_rounded_tendsto (n d : ℕ) (N M : ℕ→ℕ) (g : Jet3) + (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) (v : ℕ→ℕ→ℝ) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hBrow : IsBrownianReal brownianEval P) + (η : Measure Time) [IsProbabilityMeasure η] {B K a c KC : ℝ} (hB : B<1) + (ha0 : 0≤a) (haK : a≤K) (hc : |c|≤KC) + (hK : ∀ j,M j/(N j+1:ℕ)*‖g.d1‖^2≤K) + (hC : ∀ j (b : BulkDisorder (N j+1) (M j)) x,|bulkC (N j+1) (M j) g b.1 x|≤KC) + (hL2 : Tendsto (fun j=>bulkReplicaMean (N j) (M j) g.f (v j) 1 + (fun b x=>(bulkC (N j+1) (M j) g b.1 (x 0)-c)^2)) atTop (𝓝 0)) + (hcap : ∀ (Λ : ℝ) (hΛ : 1≤Λ),Tendsto (fun j=>cavityBulkLog n d (N j) (M j) g (v j) Λ hΛ- + roundedCavityLog n d g.f Λ hΛ η B ha0 haK j) atTop (𝓝 0)) : + Tendsto (fun j=>cavityBulkFullLog n d (N j) (M j) g (v j)- + ((n+1:ℕ)/2*c+roundedCavityValue n d g P η B ha0 haK j)) atTop (𝓝 0) := by + let U:=Real.exp (2*((n+1:ℕ)/2*KC+(d:ℝ)*‖g.f‖)+2*(n+1:ℕ)*K) + let V:=Real.exp (2*((d:ℝ)*‖g.f‖))*Real.exp (2*(n+1:ℕ)*a) + let F:=fun j=>cavityBulkFullLog n d (N j) (M j) g (v j)- + ((n+1:ℕ)/2*c+roundedCavityValue n d g P η B ha0 haK j) + let G:=fun Λ j=>if hΛ : 1≤Λ then + (∫ b,cavityBulkCompError n d (N j) (M j) g (v j) Λ hΛ c b + ∂(bulkDisorderLaw (N j+1) (M j)).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d (N j) (M j)))))+ + (cavityBulkLog n d (N j) (M j) g (v j) Λ hΛ-roundedCavityLog n d g.f Λ hΛ η B ha0 haK j) + else 0 + apply tendsto_zero_of_uniform_inverse_cap F G (C:=U+V) (by dsimp [U,V]; positivity) + · intro Λ hΛ j + have hb:=cavityBulk_uncap_annealed n d (N j) (M j) g (v j) Λ hΛ K KC (hK j) (hC j) + have hr:=roundedCavity_uncap n d g P hBrow η hB ha0 haK j hΛ + have he:=cavityBulkFullLog_decomposition n d (N j) (M j) g (v j) Λ hΛ c K KC hc (hK j) (hC j) + dsimp only at he hb + have hid : F j-G Λ j= + (∫ b,cavityBulkUncapError n d (N j) (M j) g (v j) Λ hΛ b + ∂(bulkDisorderLaw (N j+1) (M j)).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d (N j) (M j)))))- + (roundedCavityValue n d g P η B ha0 haK j-roundedCavityLog n d g.f Λ hΛ η B ha0 haK j) := by + dsimp [F,G]; rw [dite_eq_left hΛ,he]; ring + rw [hid] + have hV : roundedCavityValue n d g P η B ha0 haK j-roundedCavityLog n d g.f Λ hΛ η B ha0 haK j≤V/Λ := by + exact hr.2.trans_eq (by dsimp [V]; ring) + have hU : (∫ b,cavityBulkUncapError n d (N j) (M j) g (v j) Λ hΛ b + ∂(bulkDisorderLaw (N j+1) (M j)).prod (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d (N j) (M j)))))≤U/Λ := hb.2.2 + have hU0 : 0≤U/Λ:=by dsimp [U]; positivity + have hV0 : 0≤V/Λ:=by dsimp [V]; positivity + rw [add_div] + exact abs_le.mpr ⟨by linarith [hb.2.1,hr.1],by linarith [hb.2.1,hr.1]⟩ + · intro Λ hΛ + have hcomp:=cavityBulkCompError_tendsto_zero n d N M g hg v Λ hΛ c KC hc hC hL2 + simpa only [G,dite_eq_left hΛ,zero_add] using hcomp.add (hcap Λ hΛ) + +theorem bulk_cavity_uniform_lower (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hBrow : IsBrownianReal brownianEval P) {α : ℝ} (hα : 0≤α) + (g : Jet3) (hg : HasCompactSupport (g.d1 : ℝ→ℝ)) {K : ℝ} (hK0 : 0≤K) + (ε : ℝ) (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, ∀ (M : ℕ→ℕ) (v : ℕ→ℕ→ℝ) (s : ℕ→ℕ) + (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (D : BulkCavityData M g v s α K μ hg) + (KC : ℝ) (_hDc : |D.c|≤KC) + (_hK : ∀ j,((M (s j)+2:ℕ):ℝ)/(s j+1:ℕ)*‖g.d1‖^2≤K) + (_hC : ∀ j (b : BulkDisorder (s j+1) (M (s j)+2)) x, + |bulkC (s j+1) (M (s j)+2) g b.1 x|≤KC) + (d : ℕ), |(d:ℝ)-(n+1:ℕ)*α|≤1 → + ∀ δ : ℝ,0<δ → ∀ᶠ j : ℕ in atTop, + (n+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖-δ ≤ + cavityBulkFullLog n d (s j) (M (s j)+2) g (v (s j)) := by + filter_upwards [finiteSphericalFieldValue_depth_uniform (K/2) (by positivity) ε hε] with n hn + intro M v s μ D KC hDc hK hC d hd δ hδ + let η:=markedTimePair K μ + let B:=(α*‖g.d1‖^2)/(1+α*‖g.d1‖^2) + have hA0 : 0≤α*‖g.d1‖^2:=mul_nonneg hα (sq_nonneg _) + have hB : B<1:=(div_lt_one (by linarith : 0<1+α*‖g.d1‖^2)).mpr (by linarith) + let V:=roundedCavityValue n d g P η B D.a_nonneg D.a_le_K + let U:=fun j=>cavityBulkFullLog n d (s j) (M (s j)+2) g (v (s j)) + have hfull : Tendsto (fun j=>U j-((n+1:ℕ)/2*D.c+V j)) atTop (𝓝 0) := + cavityBulkFullLog_rounded_tendsto n d s (fun j=>M (s j)+2) g hg (fun j=>v (s j)) P hBrow + η hB D.a_nonneg D.a_le_K hDc hK hC D.c_L2 (D.capped n d) + have hm:=roundedProfileMoment_tendsto η hB + have he:=cappedAError_tendsto (quantileRoundLaw η) (⟨η,inferInstance⟩ : ProbabilityMeasure Time) + (quantileRoundLaw_tendsto η) hB + let R:=fun j=>(n+1:ℕ)*((D.c+D.a)/2+(terminalVariational P α g.f).toReal-roundedProfileMoment η B j- + cappedAError (quantileRoundLaw η j) η B-ε)-‖g.f‖ + have hR : Tendsto R atTop (𝓝 ((n+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖)) := by + have h:=((((tendsto_const_nhds (x:=(D.c+D.a)/2+(terminalVariational P α g.f).toReal)).sub hm).sub he).sub_const ε).const_mul ((n+1:ℕ):ℝ) + have h':=h.sub_const ‖g.f‖ + have heq : (n+1:ℕ)*((D.c+D.a)/2+(terminalVariational P α g.f).toReal- + cavityProfileMoment η B-0-ε)-‖g.f‖ = + (n+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖ := by + rw [show (D.c+D.a)/2=cavityProfileMoment η B from D.radial] + ring + rw [heq] at h' + exact h' + have ht:=hR.add hfull + simp only [add_zero] at ht + have hev:=ht.eventually (Ioi_mem_nhds (show + (n+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖-δ < + (n+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖ from by linarith)) + filter_upwards [hev] with j hj + have hlo:=roundedCavityValue_lower P hα g n d η hB D.a_nonneg D.a_le_K D.support D.field_bound hd hn j + change _ + mul_le_mul_of_nonneg_right (cavity_omitted_bound hα.le n) (sq_nonneg _) + have hC : ∀ n (b : BulkDisorder (n+1) (M n+2)) x,|bulkC (n+1) (M n+2) g b.1 x|≤KC := by + intro n b x + exact (bulkC_bound n (M n+2) g hg b x).trans + (mul_le_mul_of_nonneg_right (cavity_omitted_bound hα.le n) (norm_nonneg _)) + filter_upwards [bulk_cavity_uniform_lower P hB hα.le g hg hK0 ε hε] with k hk + intro d hd δ hδ + apply cavity_eventually_uniform (bulkJointGoodSet α g.f G.J) + {v : ℕ→ℝ | ∀ p,v p∈Icc (1:ℝ) 2} (fun _=>1) (by intro p; constructor <;> norm_num) + (fun _ _ h=>h.2) G.nonempty + intro v hv hvG + have hdO : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n) g.f p (v n)) atTop (𝓝 0) := + fun p=>(G.deviation v hvG p).2 + have hdF : ∀ p,Tendsto (fun n=>bulkDeviationAt n (M n+2) g.f p (v n)) atTop (𝓝 0) := by + intro p + apply (G.deviation v hvG p).1.congr' + filter_upwards [cavity_omitted_full hα] with n hn + rw [show M n+2=patternCount α (n+1) from hn] + have hv1 : ∀ n p,1≤v n p:=fun n p=>(hv n p).1 + have hv2 : ∀ n p,|v n (p+1)|≤(2:ℝ) := by + intro n p + rw [abs_of_nonneg (by linarith [(hv n (p+1)).1])] + exact (hv n (p+1)).2 + by_contra hnot + have hbad : ∃ᶠ n : ℕ in atTop,cavityBulkFullLog k d n (patternCount α (n+1)) g (v n)< + (k+1:ℕ)*((terminalVariational P α g.f).toReal-ε)-‖g.f‖-δ := by + simpa only [not_eventually,not_le] using hnot + obtain ⟨q,hq,hqbad⟩:=extraction_of_frequently_atTop hbad + obtain ⟨ν,t,ht,ho⟩:=compact_array_law_subsequence (fun j=>bulkGibbsArrayLaw (q j) (M (q j)) g.f (v (q j))) + let b:=q∘t + have hb : StrictMono b:=hq.comp ht + obtain ⟨μ,u,hu,hf⟩:=compact_array_law_subsequence (fun j=>bulkMarkedArrayLaw (b j) (M (b j)+2) g (v (b j)) K (hK (b j))) + let s:=b∘u + have hs : StrictMono s:=hb.comp hu + have ho' : Tendsto (fun j=>bulkGibbsArrayLaw (s j) (M (s j)) g.f (v (s j))) atTop (𝓝 ν):= + ho.comp hu.tendsto_atTop + have hf' : Tendsto (fun j=>bulkMarkedArrayLaw (s j) (M (s j)+2) g (v (s j)) K (hK (s j))) atTop (𝓝 μ):=hf + obtain ⟨D⟩:=bulk_cavity_data M g hg v hv1 (by norm_num : (0:ℝ)≤2) hv2 hdO hdF s hs α hα.le + ((cavity_omitted_density hα).comp hs.tendsto_atTop) ν ho' K hK0 hK μ hf' + have hDc : |D.c|≤KC := D.c_bound.trans (by dsimp [KC]; nlinarith [norm_nonneg (g.dilationMark hg)]) + have hlow:=hk M v s μ D KC hDc (fun j=>hK (s j)) (fun j=>hC (s j)) d hd δ hδ + obtain ⟨j,hj,hje⟩:=(hlow.and (hs.tendsto_atTop.eventually (cavity_omitted_full hα))).exists + rw [show M (s j)+2=patternCount α (s j+1) from hje] at hj + exact (not_lt_of_ge hj) (hqbad (t (u j))) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CavityUniformRemainder.lean b/lean/OAI/Probability/Perceptron/Cavity/CavityUniformRemainder.lean new file mode 100644 index 0000000000000000000000000000000000000000..52957b03010510f6aa0df263549d027735697c45 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CavityUniformRemainder.lean @@ -0,0 +1,187 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityTaylorFinite + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +def cavityRemainderCoefficients (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) (L D : ℝ) : Fin 4→ℝ := ![ + (‖weightedDerivative g.d1 h1 1‖+‖weightedDerivative g.d2 h2 2‖)*D^2/2+ + (D^2+D*L/2)*‖weightedDerivative g.d1 h1 1‖, + ‖weightedDerivative g.d2 h2 1‖*D*Real.sqrt D+Real.sqrt D*L*‖g.d1‖, + ‖weightedDerivative g.d3 h3 1‖*D^2/2+D*L*‖g.d2‖/2, + ‖g.d3‖*(Real.sqrt D)^3/6] + +def cavityRemainderMajorant (c : Fin 4→ℝ) (N u : ℝ) : ℝ := + c 0/N^2+c 1*u/(N*Real.sqrt N)+c 2*u^2/N^2+c 3*u^3/(N*Real.sqrt N) + +lemma cavityRemainderMajorant_nonneg (c : Fin 4→ℝ) (hc : ∀ i,0≤c i) + {N u : ℝ} (hN : 0≤N) (hu : 0≤u) : 0≤cavityRemainderMajorant c N u := by + have h0:=hc 0 + have h1:=hc 1 + have h2:=hc 2 + have h3:=hc 3 + unfold cavityRemainderMajorant + positivity + +lemma cavityRemainderCoefficients_nonneg (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) {L D : ℝ} (hL : 0≤L) (hD : 0≤D) : + ∀ i,0≤cavityRemainderCoefficients g h1 h2 h3 L D i := by + intro i + fin_cases i <;> dsimp [cavityRemainderCoefficients] <;> positivity + +lemma cavityTaylorError_le_majorant (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) {N L D q v u : ℝ} + (hN : 0‖y‖^p) (stdGaussian (Spin L)) := by + simpa only [id_eq] using + (IsGaussian.memLp_id (stdGaussian (Spin L)) (p:ℝ≥0∞) (by simp)).integrable_norm_pow' + +lemma cavityRemainderMajorant_integrable (L : ℕ) (c : Fin 4→ℝ) (N : ℝ) : + Integrable (fun y : Spin L=>cavityRemainderMajorant c N ‖y‖) (stdGaussian (Spin L)) := by + have h1 : Integrable (fun y : Spin L=>‖y‖) (stdGaussian (Spin L)) := by + simpa using cavityNormMoment_integrable L 1 + exact (((integrable_const (c 0/N^2)).add ((h1.const_mul (c 1)).div_const _)).add + (((cavityNormMoment_integrable L 2).const_mul (c 2)).div_const _)).add + (((cavityNormMoment_integrable L 3).const_mul (c 3)).div_const _) + +lemma cavityRemainderMajorant_mean (L : ℕ) (c : Fin 4→ℝ) (N : ℝ) : + (∫ y : Spin L,cavityRemainderMajorant c N ‖y‖ ∂stdGaussian (Spin L))= + c 0/N^2+c 1*cavityNormMoment L 1/(N*Real.sqrt N)+ + c 2*cavityNormMoment L 2/N^2+c 3*cavityNormMoment L 3/(N*Real.sqrt N) := by + have h1 : Integrable (fun y : Spin L=>‖y‖) (stdGaussian (Spin L)) := by + simpa using cavityNormMoment_integrable L 1 + have h2:=cavityNormMoment_integrable L 2 + have h3:=cavityNormMoment_integrable L 3 + unfold cavityRemainderMajorant cavityNormMoment + have hi0 : Integrable (fun _ : Spin L=>c 0/N^2) (stdGaussian (Spin L)) := integrable_const _ + have hi1 : Integrable (fun y : Spin L=>c 1*‖y‖/(N*Real.sqrt N)) (stdGaussian (Spin L)) := + (h1.const_mul _).div_const _ + have hi2 : Integrable (fun y : Spin L=>c 2*‖y‖^2/N^2) (stdGaussian (Spin L)) := + (h2.const_mul _).div_const _ + have hi3 : Integrable (fun y : Spin L=>c 3*‖y‖^3/(N*Real.sqrt N)) (stdGaussian (Spin L)) := + (h3.const_mul _).div_const _ + have ha := integral_add ((hi0.add hi1).add hi2) hi3 + have hb := integral_add (hi0.add hi1) hi2 + have hd := integral_add hi0 hi1 + simp only [Pi.add_apply] at ha hb hd + rw [ha,hb,hd] + simp only [integral_div,integral_const_mul,integral_const,probReal_univ,smul_eq_mul,one_mul,pow_one] + +lemma cavityRemainderMajorant_row_mean (M L : ℕ) (c : Fin 4→ℝ) (N : ℝ) : + (∫ y : Fin M→Spin L,∑ i,cavityRemainderMajorant c N ‖y i‖ + ∂Measure.pi (fun _=>stdGaussian (Spin L)))= + M*(c 0/N^2+c 1*cavityNormMoment L 1/(N*Real.sqrt N)+ + c 2*cavityNormMoment L 2/N^2+c 3*cavityNormMoment L 3/(N*Real.sqrt N)) := by + have hi (i : Fin M) : Integrable + (fun y : Fin M→Spin L=>cavityRemainderMajorant c N ‖y i‖) + (Measure.pi (fun _=>stdGaussian (Spin L))) := + ((measurePreserving_eval (fun _ : Fin M=>stdGaussian (Spin L)) i).integrable_comp + (cavityRemainderMajorant_integrable L c N).aestronglyMeasurable).mpr + (cavityRemainderMajorant_integrable L c N) + rw [integral_finsetSum _ (fun i _=>hi i)] + have he (i : Fin M) : + (∫ y : Fin M→Spin L,cavityRemainderMajorant c N ‖y i‖ + ∂Measure.pi (fun _=>stdGaussian (Spin L))) = + ∫ y : Spin L,cavityRemainderMajorant c N ‖y‖ ∂stdGaussian (Spin L) := by + have hp := measurePreserving_eval (fun _ : Fin M=>stdGaussian (Spin L)) i + have hh := (integral_map hp.measurable.aemeasurable + (hp.map_eq ▸ (cavityRemainderMajorant_integrable L c N).aestronglyMeasurable)).symm + simpa only [hp.map_eq,Function.eval] using hh + simp_rw [he,cavityRemainderMajorant_mean] + simp + ring + +lemma cavityRemainderMajorant_row_tendsto (M : ℕ→ℕ) (L : ℕ) (c : Fin 4→ℝ) + {α : ℝ} (hM : Tendsto (fun n=>(M n:ℝ)/(n+1:ℕ)) atTop (𝓝 α)) : + Tendsto (fun n=>∫ y : Fin (M n)→Spin L,∑ i,cavityRemainderMajorant c (n+1:ℕ) ‖y i‖ + ∂Measure.pi (fun _=>stdGaussian (Spin L))) atTop (𝓝 0) := by + have hN : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have hi : Tendsto (fun n : ℕ=>((n+1:ℕ):ℝ)⁻¹) atTop (𝓝 0) := tendsto_inv_atTop_zero.comp hN + have hs : Tendsto (fun n : ℕ=>(Real.sqrt (n+1:ℕ))⁻¹) atTop (𝓝 0) := + tendsto_inv_atTop_zero.comp (Real.tendsto_sqrt_atTop.comp hN) + have ht:=hM.mul (((hi.const_mul (c 0)).add (hs.const_mul (c 1*cavityNormMoment L 1))).add + (hi.const_mul (c 2*cavityNormMoment L 2)) |>.add (hs.const_mul (c 3*cavityNormMoment L 3))) + simp only [mul_zero,add_zero] at ht + apply ht.congr' + filter_upwards [] with n + rw [cavityRemainderMajorant_row_mean] + field_simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/ContinuousCavityProfile.lean b/lean/OAI/Probability/Perceptron/Cavity/ContinuousCavityProfile.lean new file mode 100644 index 0000000000000000000000000000000000000000..88abf4ccf7867cda18d6372ce53cc2bc6a85620e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/ContinuousCavityProfile.lean @@ -0,0 +1,66 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkPairLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma cappedA_monotone (μ : Measure Time) [IsProbabilityMeasure μ] {B : ℝ} (hB : B < 1) : + Monotone (cappedA μ B) := + monotone_of_hasDerivAt_nonneg (cappedA_hasDerivAt μ hB) (fun _ => sq_nonneg _) + +def continuousCavityProfile (μ : Measure Time) (B : ℝ) {K d : ℝ} + (hd0 : 0 ≤ d) (hdK : d ≤ K) (r : Time) : BulkPairRange K := + (⟨r.val, (by linarith [r.prop.1]), r.prop.2⟩, + ⟨min d (max 0 (cappedA μ B r)), by + constructor + · have hm := le_min hd0 (le_max_left 0 (cappedA μ B r)) + linarith + · exact (min_le_left _ _).trans hdK⟩) + +def cavityTrueDiagonal {K d : ℝ} (hd0 : 0 ≤ d) (hdK : d ≤ K) : BulkPairRange K := + (⟨1,by norm_num⟩,⟨d,by constructor <;> linarith⟩) + +lemma continuousCavityProfile_continuous (μ : Measure Time) [IsProbabilityMeasure μ] + {B K d : ℝ} (hB : B < 1) (hd0 : 0 ≤ d) (hdK : d ≤ K) : + Continuous (continuousCavityProfile μ B hd0 hdK) := by + have hc : Continuous (fun r : Time => cappedA μ B r.val) := + (cappedA_continuous μ hB).comp continuous_subtype_val + exact (continuous_subtype_val.subtype_mk _).prodMk + ((continuous_const.min (continuous_const.max hc)).subtype_mk _) + +lemma continuousCavityProfile_mono (μ : Measure Time) [IsProbabilityMeasure μ] + {B K d : ℝ} (hB : B < 1) (hd0 : 0 ≤ d) (hdK : d ≤ K) : + Monotone (fun r => (continuousCavityProfile μ B hd0 hdK r).2.val) := by + exact monotone_const.min (monotone_const.max + ((cappedA_monotone μ hB).comp (Subtype.mono_coe _))) + +lemma continuousCavityProfile_nonneg (μ : Measure Time) (B : ℝ) {K d : ℝ} + (hd0 : 0 ≤ d) (hdK : d ≤ K) (r : Time) : + 0 ≤ (continuousCavityProfile μ B hd0 hdK r).1.val ∧ + 0 ≤ (continuousCavityProfile μ B hd0 hdK r).2.val := + ⟨r.prop.1,le_min hd0 (le_max_left _ _)⟩ + +lemma continuousCavityProfile_le_diagonal (μ : Measure Time) (B : ℝ) {K d : ℝ} + (hd0 : 0 ≤ d) (hdK : d ≤ K) (r : Time) : + (continuousCavityProfile μ B hd0 hdK r).1.val ≤ (cavityTrueDiagonal hd0 hdK).1.val ∧ + (continuousCavityProfile μ B hd0 hdK r).2.val ≤ (cavityTrueDiagonal hd0 hdK).2.val := + ⟨r.prop.2,min_le_left _ _⟩ + +lemma continuousCavityProfile_eq (μ : Measure Time) [IsProbabilityMeasure μ] + {B K d : ℝ} (hd0 : 0 ≤ d) (hdK : d ≤ K) + (hμ : ∀ᵐ r : Time ∂μ, r.val ≤ B) {r : Time} {a : ℝ} + (hr : r.val ≤ B) (ha0 : 0 ≤ a) (had : a ≤ d) + (ha : a = ∫ t in 0..r.val, (realTail μ t)⁻¹^2) : + (continuousCavityProfile μ B hd0 hdK r).2.val = a := by + change min d (max 0 (cappedA μ B r.val)) = a + rw [cappedA_eq_integral μ hμ r.prop.1 hr,←ha,max_eq_right ha0,min_eq_right had] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/CountableFreshMoment.lean b/lean/OAI/Probability/Perceptron/Cavity/CountableFreshMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..1dda88418ffb80cdfe5b2fdb290433f47e671fb7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/CountableFreshMoment.lean @@ -0,0 +1,129 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshReplicaKernel + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma truncatedFreshKernel {S : Type*} [MeasurableSpace S] + (v : ℕ→S→ℝ) (L : S→ℕ) (f : ℝ →ᵇ ℝ) (r n : ℕ) (xs : Fin r→S) : + (∫ g, ∏ i, f (truncatedCountableGaussianField v L n g (xs i)) ∂countableGaussianLaw)= + freshReplicaMatrixKernel f r (fun i j => gaussianPrefixCovariance v v L n (xs i) (xs j)) := by + let rows : Fin r→EuclideanSpace ℝ (Fin n) := fun i => + WithLp.toLp 2 (fun j => maskedGaussianCoefficient v L j.val (xs i)) + have hg : Matrix.gram ℝ rows=(fun i j => gaussianPrefixCovariance v v L n (xs i) (xs j)) := by + ext i j + change (∑ l : Fin n, maskedGaussianCoefficient v L l.val (xs j)* + maskedGaussianCoefficient v L l.val (xs i)) = _ + unfold gaussianPrefixCovariance + exact Finset.sum_congr rfl fun l _ => mul_comm _ _ + rw [← hg,freshReplicaMatrixKernel_gram,← gaussianRows_map_stdGaussian rows, + integral_map (gaussianRows rows).continuous.measurable.aemeasurable + (gaussianReplicaTest f).continuous.aestronglyMeasurable] + rw [← map_pi_eq_stdGaussian] + rw [integral_map (by fun_prop) (by fun_prop)] + have hp := gaussianCoordinatePrefix_measurePreserving n + have hmeas : AEStronglyMeasurable (fun y : Fin n→ℝ => + gaussianReplicaTest f (gaussianRows rows (WithLp.toLp 2 y))) + (Measure.pi fun _ : Fin n => gaussianReal 0 1) := by fun_prop + rw [← hp.map_eq] at hmeas ⊢ + rw [integral_map hp.measurable.aemeasurable hmeas] + apply integral_congr_ae + exact ae_of_all _ fun g => by + simp only [gaussianReplicaTest_apply,gaussianRows_apply] + congr 1 + +lemma countableFreshKernel {S : Type*} [MeasurableSpace S] + (v : ℕ→S→ℝ) (L : S→ℕ) (f : ℝ →ᵇ ℝ) (r : ℕ) (xs : Fin r→S) : + (∫ g, ∏ i, f (countableGaussianField v L g (xs i)) ∂countableGaussianLaw)= + freshReplicaMatrixKernel f r (fun i j => countableGaussianCovariance v v L (xs i) (xs j)) := by + have he : ∀ᶠ n : ℕ in atTop, ∀ i : Fin r, ∀ g, + truncatedCountableGaussianField v L n g (xs i)=countableGaussianField v L g (xs i) := + Filter.eventually_all.mpr (fun i => truncatedCountableGaussianField_eventually_eq v L (xs i)) + have hc : ∀ᶠ n : ℕ in atTop, ∀ i j : Fin r, + gaussianPrefixCovariance v v L n (xs i) (xs j)=countableGaussianCovariance v v L (xs i) (xs j) := + Filter.eventually_all.mpr (fun i => Filter.eventually_all.mpr (fun j => + gaussianPrefixCovariance_eventually_eq v v L (xs i) (xs j))) + obtain ⟨n,hn,hc⟩ := (he.and hc).exists + have h := truncatedFreshKernel v L f r n xs + simp_rw [hn] at h + have hm : (fun i j => gaussianPrefixCovariance v v L n (xs i) (xs j))= + (fun i j => countableGaussianCovariance v v L (xs i) (xs j)) := by + funext i j; exact hc i j + exact h.trans (congrArg (freshReplicaMatrixKernel f r) hm) + +theorem countableFresh_moment {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (v : ℕ→S→ℝ) (L : S→ℕ) + (hv : ∀ i, Measurable (v i)) (hL : Measurable L) (f : ℝ →ᵇ ℝ) (r : ℕ) : + (∫ g, (∫ x, f (countableGaussianField v L g x) ∂μ)^r ∂countableGaussianLaw)= + ∫ xs : Fin r→S, freshReplicaMatrixKernel f r + (fun i j => countableGaussianCovariance v v L (xs i) (xs j)) ∂Measure.pi (fun _ => μ) := by + let F : (ℕ→ℝ)×(Fin r→S)→ℝ := fun p => ∏ i, f (countableGaussianField v L p.1 (p.2 i)) + have hm : Measurable F := Finset.measurable_prod _ fun i _ => + f.measurable.comp ((countableGaussianField_measurable hv hL).comp + (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd))) + have hb (p : (ℕ→ℝ)×(Fin r→S)) : ‖F p‖≤‖f‖^r := by + simp only [F,norm_prod] + exact (Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) (fun _ _ => f.norm_coe_le_norm _)).trans_eq + (by simp) + have hi : Integrable F (countableGaussianLaw.prod (Measure.pi fun _ : Fin r => μ)) := + Integrable.of_bound hm.aestronglyMeasurable _ (ae_of_all _ hb) + calc + _ = ∫ g, ∫ xs : Fin r→S, F (g,xs) ∂Measure.pi (fun _ => μ) ∂countableGaussianLaw := by + apply integral_congr_ae + exact ae_of_all _ fun g => by + simpa only [F,Fintype.card_fin] using + (integral_fintype_prod_eq_pow (ι := Fin r) (fun x : S => f (countableGaussianField v L g x)) (μ := μ)).symm + _ = ∫ xs : Fin r→S, ∫ g, F (g,xs) ∂countableGaussianLaw ∂Measure.pi (fun _ => μ) := + integral_integral_swap hi + _ = _ := integral_congr_ae (ae_of_all _ fun xs => countableFreshKernel v L f r xs) + +variable {S : Type} [MeasurableSpace S] {k : ℕ} + +def labelProfileRow (q : Fin (k+1)→ℝ) : ℕ→S×IndexedLeaf k→ℝ := + indexedGaussianRow k (hierarchyRowCoefficients k + (profileGaussianRoot (fun l (_ : Fin 1) => q l)) + (profileGaussianStep (fun l (_ : Fin 1) => q l))) + (fun _ : S => WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) + +def labelProfileField (q : Fin (k+1)→ℝ) (g : ℕ→ℝ) : S×IndexedLeaf k→ℝ := + countableGaussianField (labelProfileRow q) (indexedGaussianRowLength (I := Fin 1) k) g + +lemma labelProfile_covariance (q : Fin (k+1)→ℝ) (h0 : 0≤q 0) (hq : Monotone q) + (x y : S×IndexedLeaf k) : + countableGaussianCovariance (labelProfileRow q) (labelProfileRow q) + (indexedGaussianRowLength (I := Fin 1) k) x y = q (indexedCommonDepth k y.2 x.2) := by + simpa only [labelProfileRow,Fin.sum_univ_one,mul_one] using + profileGaussianRow_covariance (fun l (_ : Fin 1) => q l) (fun _ => h0) (fun _ => hq) + (fun _ : S => WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) + (fun _ : S => WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) x y + +theorem labelProfile_fresh_moment (q : Fin (k+1)→ℝ) (h0 : 0≤q 0) (hq : Monotone q) + (μ : Measure (S×IndexedLeaf k)) [IsProbabilityMeasure μ] (f : ℝ →ᵇ ℝ) (r : ℕ) : + (∫ g, (∫ x, f (labelProfileField q g x) ∂μ)^r ∂countableGaussianLaw)= + ∫ xs : Fin r→S×IndexedLeaf k, freshReplicaMatrixKernel f r + (fun i j => q (indexedCommonDepth k (xs j).2 (xs i).2)) ∂Measure.pi (fun _ => μ) := by + have h := countableFresh_moment μ (labelProfileRow q) + (indexedGaussianRowLength (I := Fin 1) k) + (indexedGaussianRow_measurable _ _ measurable_const) + (indexedGaussianRowLength_measurable k) f r + simpa only [labelProfileField,labelProfile_covariance q h0 hq] using h + +lemma labelProfileField_marked_state {S : Type} [MeasurableSpace S] {k : ℕ} + (q : Fin (k+1)→ℝ) (g : ℕ→ℝ) (x : S×IndexedLeaf k) : + labelProfileField q g x = + inner ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) + (indexedLeafState (gaussianLinearMarkStep (fun j => diagonalMark + (profileGaussianStep (fun l (_ : Fin 1) => q l) j))) k + ((fun _ => diagonalMark (profileGaussianRoot (fun l (_ : Fin 1) => q l)) + (indexedGaussianDisorder k (Fin 1) g).1), + (indexedGaussianDisorder k (Fin 1) g).2) x.2 0) := + indexedGaussianRow_diagonal_identity k _ _ _ g x + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshDensity.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..fbaf9d3e1daf5b74792d37ff56ea6f257dd6c916 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshDensity.lean @@ -0,0 +1,67 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshMomentLimit +import OAI.Probability.Perceptron.Variational.FixedCount + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def sourceDisorderUnassoc (n k : ℕ) (a : SourceIndexedDisorder n k) : SourceBaseData n k × (ℕ→ℝ) := + ((a.1,(a.2.1,a.2.2.1)),a.2.2.2) + +lemma sourceDisorderUnassoc_preserving (n k : ℕ) (z : Fin k→ℝ) (t : ℝ≥0) : + MeasurePreserving (sourceDisorderUnassoc n k) (sourceIndexedDisorderLaw n k z t) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) := by + let K := poissonMeasure ((n+1:ℕ)*t) + let R := infinitePatternRowsLaw (n+1) + let B := (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) + exact (measurePreserving_prodAssoc K (R.prod B) countableGaussianLaw).symm.comp + ((MeasurePreserving.id K).prod (measurePreserving_prodAssoc R B countableGaussianLaw).symm) + +theorem sourceDensityIncrement_eq_fresh (n k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 + ∫ g, Real.log (freshThermalPartition (sourceFullSpinLeafKernel n k) + (sourceCouplingHamiltonian n k f p d h u) (fun x => x.1.val) f (a,g)) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1))) + have hi := freshThermalPartition_log_integrable (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) (sourceCouplingHamiltonian_measurable n k f p d h u) + (fun x => x.1.val) (measurable_subtype_coe.comp measurable_fst) f + (sourceFresh_exp_ae n k f p d h hh0 hh u z t) + have hj : Integrable J ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) := + hi.integral_prod_left + have hp := sourceDisorderUnassoc_preserving n k z t + have he (M : ℕ) (a : SourceCountData n k) : J (sourceDisorderUnassoc n k (M,a))= + ∫ g, Real.log (freshThermalPartition (sourceCountKernel n k) + (sourceCountHamiltonian n M k f p d h u) (fun x => x.1.val) f (a,g)) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1))) := by + apply integral_congr_ae + exact ae_of_all _ fun g => by + simp only [freshThermalPartition,sourceFullSpinLeafKernel,Kernel.comap_apply, + sourceSpinLeafKernel_apply,sourceCountKernel_apply] + rfl + rw [sourceDensityIncrement] + simp_rw [sourceCountExpectedLog_fresh n _ k f p d h hh0 hh u z hz hz0 hz1,← he] + change (∫ M, ∫ a, J (sourceDisorderUnassoc n k (M,a)) ∂sourceCountLaw n k z + ∂poissonMeasure ((n+1:ℕ)*t))=_ + calc + _=(∫ a, J (sourceDisorderUnassoc n k a) ∂sourceIndexedDisorderLaw n k z t) := by + simpa only [Function.comp_def,sourceCountLaw,sourceIndexedDisorderLaw] using + (integral_prod _ (hp.integrable_comp_of_integrable hj)).symm + _=sourceFreshLog n k f p d h u z t := ?_ + have hmap := integral_map (φ := sourceDisorderUnassoc n k) (f := J) hp.measurable.aemeasurable + (by rw [hp.map_eq]; exact hj.aestronglyMeasurable) + rw [hp.map_eq] at hmap + exact hmap.symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshDiagonalNoise.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshDiagonalNoise.lean new file mode 100644 index 0000000000000000000000000000000000000000..ecbe5e18f7ce90338667e0553e4bd8ebb412ea05 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshDiagonalNoise.lean @@ -0,0 +1,159 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CountableFreshMoment + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators NNReal BoundedContinuousFunction ENNReal + +section + +variable {n r : ℕ} + +def freshNoiseRows (v : Fin r→EuclideanSpace ℝ (Fin n)) (s : ℝ≥0) (i : Fin r) : + EuclideanSpace ℝ (Fin n ⊕ Fin r) := + WithLp.toLp 2 (Sum.elim (fun j => v i j) (fun j => if j=i then Real.sqrt s else 0)) + +lemma freshNoiseRows_apply (v : Fin r→EuclideanSpace ℝ (Fin n)) (s : ℝ≥0) + (x : Fin n→ℝ) (y : Fin r→ℝ) (i : Fin r) : + inner ℝ (freshNoiseRows v s i) (WithLp.toLp 2 (Sum.elim x y)) = + inner ℝ (v i) (WithLp.toLp 2 x) + Real.sqrt s*y i := by + classical + change (∑ j : Fin n ⊕ Fin r, Sum.elim x y j * + Sum.elim (fun j => v i j) (fun j => if j=i then Real.sqrt s else 0) j) = _ + rw [Fintype.sum_sum_type] + simp only [Sum.elim_inl,Sum.elim_inr] + rw [show (∑ j : Fin r, y j * if j=i then Real.sqrt s else 0)=Real.sqrt s*y i by + simp only [mul_ite,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true]; ring] + rfl + +lemma freshNoiseRows_gram (v : Fin r→EuclideanSpace ℝ (Fin n)) (s : ℝ≥0) : + Matrix.gram ℝ (freshNoiseRows v s)=fun i j => Matrix.gram ℝ v i j + if i=j then (s:ℝ) else 0 := by + classical + ext i j + change (∑ l : Fin n ⊕ Fin r, + Sum.elim (fun l => v j l) (fun l => if l=j then Real.sqrt s else 0) l * + Sum.elim (fun l => v i l) (fun l => if l=i then Real.sqrt s else 0) l)=_ + rw [Fintype.sum_sum_type] + simp only [Sum.elim_inl,Sum.elim_inr,mul_ite,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] + by_cases h : i=j + · subst j + simp only [ite_true,← sq,Real.sq_sqrt s.coe_nonneg] + simp [Matrix.gram,PiLp.inner_apply,pow_two] + · simp only [ite_eq_right h,zero_mul] + rfl + +theorem freshReplicaMatrixKernel_diagonal_noise (f : ℝ →ᵇ ℝ) + (v : Fin r→EuclideanSpace ℝ (Fin n)) (s : ℝ≥0) : + freshReplicaMatrixKernel f r (fun i j => Matrix.gram ℝ v i j + if i=j then (s:ℝ) else 0)= + freshReplicaMatrixKernel (gaussianAverageBCF s f) r (Matrix.gram ℝ v) := by + classical + rw [← freshNoiseRows_gram v s,freshReplicaMatrixKernel_gram, + ← gaussianRows_map_stdGaussian,integral_map (by fun_prop) (by fun_prop), + ← map_pi_eq_stdGaussian,integral_map (by fun_prop) (by fun_prop)] + let F : (Fin n→ℝ)×(Fin r→ℝ)→ℝ := fun p => + ∏ i : Fin r, f (inner ℝ (v i) (WithLp.toLp 2 p.1)+Real.sqrt s*p.2 i) + have hF : Integrable F ((Measure.pi fun _ : Fin n => gaussianReal 0 1).prod + (Measure.pi fun _ : Fin r => gaussianReal 0 1)) := by + apply Integrable.of_bound (by fun_prop) (‖f‖^r) + exact ae_of_all _ fun p => by + simp only [F,norm_prod] + exact (Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) (fun _ _ => f.norm_coe_le_norm _)).trans_eq + (by simp) + have hp := measurePreserving_sumPiEquivProdPi_symm (fun _ : Fin n⊕Fin r => gaussianReal 0 1) + have hm : AEStronglyMeasurable (fun z : Fin n⊕Fin r→ℝ => + gaussianReplicaTest f (gaussianRows (freshNoiseRows v s) (WithLp.toLp 2 z))) + (Measure.pi fun _ => gaussianReal 0 1) := by fun_prop + rw [← hp.map_eq] at hm ⊢ + rw [integral_map hp.measurable.aemeasurable hm] + have he : (fun p : (Fin n→ℝ)×(Fin r→ℝ) => + gaussianReplicaTest f (gaussianRows (freshNoiseRows v s) + (WithLp.toLp 2 ((MeasurableEquiv.sumPiEquivProdPi (fun _ : Fin n⊕Fin r => ℝ)).symm p))))=F := by + funext p + simp only [gaussianReplicaTest_apply,gaussianRows_apply] + apply Finset.prod_congr rfl + intro i hi + exact congrArg f (freshNoiseRows_apply v s p.1 p.2 i) + rw [he,integral_prod _ hF] + have hi (x : Fin n→ℝ) : (∫ y : Fin r→ℝ, F (x,y) ∂Measure.pi (fun _ => gaussianReal 0 1))= + gaussianReplicaTest (gaussianAverageBCF s f) (gaussianRows v (WithLp.toLp 2 x)) := by + rw [gaussianReplicaTest_apply] + change (∫ y : Fin r→ℝ, ∏ i, f (inner ℝ (v i) (WithLp.toLp 2 x)+Real.sqrt s*y i) + ∂Measure.pi (fun _ => gaussianReal 0 1))=_ + rw [integral_fintype_prod_eq_prod (f := fun i y => f (inner ℝ (v i) (WithLp.toLp 2 x)+Real.sqrt s*y))] + apply Finset.prod_congr rfl + intro i hi + exact (gaussianAverage_scaling s f _).symm + simp_rw [hi] + rw [freshReplicaMatrixKernel_gram,← gaussianRows_map_stdGaussian, + integral_map (by fun_prop) (by fun_prop),← map_pi_eq_stdGaussian, + integral_map (by fun_prop) (by fun_prop)] + +lemma countableGaussianCovariance_finite_gram {S : Type*} [MeasurableSpace S] + (v : ℕ→S→ℝ) (L : S→ℕ) (r : ℕ) (xs : Fin r→S) : + ∃ n : ℕ, ∃ w : Fin r→EuclideanSpace ℝ (Fin n), + Matrix.gram ℝ w=(fun i j => countableGaussianCovariance v v L (xs i) (xs j)) := by + have hc : ∀ᶠ n : ℕ in Filter.atTop, ∀ i j : Fin r, + gaussianPrefixCovariance v v L n (xs i) (xs j)=countableGaussianCovariance v v L (xs i) (xs j) := + Filter.eventually_all.mpr (fun i => Filter.eventually_all.mpr (fun j => + gaussianPrefixCovariance_eventually_eq v v L (xs i) (xs j))) + obtain ⟨n,hn⟩ := hc.exists + refine ⟨n,fun i => WithLp.toLp 2 (fun j : Fin n => maskedGaussianCoefficient v L j.val (xs i)),?_⟩ + ext i j + rw [← hn i j] + change (∑ l : Fin n, maskedGaussianCoefficient v L l.val (xs j)* + maskedGaussianCoefficient v L l.val (xs i))=_ + exact Finset.sum_congr rfl fun l _ => mul_comm _ _ + +theorem countableFresh_moment_diagonal_noise {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (v : ℕ→S→ℝ) (L : S→ℕ) + (hv : ∀ i, Measurable (v i)) (hL : Measurable L) (f : ℝ →ᵇ ℝ) (s : ℝ≥0) (r : ℕ) : + (∫ g, (∫ x, gaussianAverageBCF s f (countableGaussianField v L g x) ∂μ)^r ∂countableGaussianLaw)= + ∫ xs : Fin r→S, freshReplicaMatrixKernel f r + (fun i j => countableGaussianCovariance v v L (xs i) (xs j) + if i=j then (s:ℝ) else 0) + ∂Measure.pi (fun _ => μ) := by + rw [countableFresh_moment μ v L hv hL] + apply integral_congr_ae + exact ae_of_all _ fun xs => by + obtain ⟨n,w,hw⟩ := countableGaussianCovariance_finite_gram v L r xs + change freshReplicaMatrixKernel (gaussianAverageBCF s f) r + (fun i j => countableGaussianCovariance v v L (xs i) (xs j)) = + freshReplicaMatrixKernel f r + (fun i j => countableGaussianCovariance v v L (xs i) (xs j) + if i=j then (s:ℝ) else 0) + have he (i j : Fin r) := congrFun (congrFun hw i) j + simp_rw [← he] + exact (freshReplicaMatrixKernel_diagonal_noise f w s).symm + +end + +theorem labelProfile_diagonal_one_moment {S : Type} [MeasurableSpace S] {k : ℕ} + (q : Fin (k+1)→ℝ) (h0 : 0≤q 0) (hq : Monotone q) (h1 : q (Fin.last k)≤1) + (μ : Measure (S×IndexedLeaf k)) [IsProbabilityMeasure μ] (f : ℝ →ᵇ ℝ) (r : ℕ) : + (∫ g, (∫ x, gaussianAverageBCF ⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ f + (labelProfileField q g x) ∂μ)^r ∂countableGaussianLaw)= + ∫ xs : Fin r→S×IndexedLeaf k, freshReplicaMatrixKernel f r + (fun i j => if i=j then 1 else q (indexedCommonDepth k (xs j).2 (xs i).2)) + ∂Measure.pi (fun _ => μ) := by + have hh := countableFresh_moment_diagonal_noise μ (labelProfileRow q) + (indexedGaussianRowLength (I := Fin 1) k) + (indexedGaussianRow_measurable _ _ measurable_const) + (indexedGaussianRowLength_measurable k) f ⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ r + exact hh.trans (by + apply integral_congr_ae + exact ae_of_all _ fun xs => by + apply congrArg (freshReplicaMatrixKernel f r) + funext i j + rw [labelProfile_covariance q h0 hq] + by_cases hij : i=j + · subst j + simp only [ite_true,indexedCommonDepth_self] + change q (Fin.last k)+(1-q (Fin.last k))=1 + ring + · simp only [ite_eq_right hij,add_zero]) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshGGLogUniqueness.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshGGLogUniqueness.lean new file mode 100644 index 0000000000000000000000000000000000000000..157ff1df6fb90990dd23553a8e950383f4f8add6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshGGLogUniqueness.lean @@ -0,0 +1,55 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshThermalLaw +import OAI.Probability.Perceptron.Cavity.FreshGGUniqueness + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma probability_Icc_eq_of_moments {a b : ℝ} (μ ν : ProbabilityMeasure (Icc a b)) + (hm : ∀ r : ℕ, (∫ x, x.val^r ∂(μ : Measure (Icc a b)))= + ∫ x, x.val^r ∂(ν : Measure (Icc a b))) : μ=ν := by + have h : Tendsto (fun _ : ℕ => μ) atTop (𝓝 ν) := by + apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr + intro F + apply integral_continuous_tendsto_of_moments (fun _ : ℕ => (μ : Measure (Icc a b))) + (ν : Measure (Icc a b)) (fun r => ?_) F.toContinuousMap + rw [hm r] + exact tendsto_const_nhds + exact tendsto_nhds_unique tendsto_const_nhds h + +variable (μ ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) +variable (hGGμ : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect μ n i f g=0) +variable (hGGν : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν n i f g=0) +variable (hμ : ∀ᵐ Q ∂(μ : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) +variable (hν : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) +variable (hpair : (μ : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)) +variable (f : ℝ →ᵇ ℝ) (η ξ : ProbabilityMeasure (FreshPartitionRange f)) +variable (hη : ∀ r, (∫ x, x.val^r ∂(η : Measure (FreshPartitionRange f)))= + ∫ Q, freshReplicaArrayKernel (expBCF 1 f) r Q ∂(μ : Measure (CompactArray CompactJointOverlap))) +variable (hξ : ∀ r, (∫ x, x.val^r ∂(ξ : Measure (FreshPartitionRange f)))= + ∫ Q, freshReplicaArrayKernel (expBCF 1 f) r Q ∂(ν : Measure (CompactArray CompactJointOverlap))) + +include hGGμ hGGν hμ hν hpair hη hξ in +theorem freshPartitionLaw_eq_of_pair_law : η=ξ := by + apply probability_Icc_eq_of_moments + intro r + rw [hη r,hξ r] + exact freshReplicaKernel_eq_of_pair_law μ ν hGGμ hGGν hμ hν hpair (expBCF 1 f) r + +include hGGμ hGGν hμ hν hpair hη hξ in +theorem freshLog_eq_of_pair_law : + (∫ x, Real.log x.val ∂(η : Measure (FreshPartitionRange f)))= + ∫ x, Real.log x.val ∂(ξ : Measure (FreshPartitionRange f)) := by + rw [freshPartitionLaw_eq_of_pair_law μ ν hGGμ hGGν hμ hν hpair f η ξ hη hξ] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshGGUniqueness.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshGGUniqueness.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3f3379abb743fd70ebd9a01ad34d0f3b0313a7a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshGGUniqueness.lean @@ -0,0 +1,146 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshReplicaKernel +import OAI.Probability.Perceptron.Variational.UniformQuantileCells + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def CompactSpinGeometry (Q : CompactArray CompactJointOverlap) : Prop := + (∀ i j, (Q i j).1.val=(Q j i).1.val) ∧ (∀ i, (Q i i).1.val=1) ∧ + ∀ i j k, min (Q i j).1.val (Q i k).1.val ≤ (Q j k).1.val + +def compactSpinTop : CompactOverlap := ⟨1,by norm_num⟩ + +lemma compactSpinCode_geometry (n : ℕ) {Q : CompactArray CompactJointOverlap} + (hQ : CompactSpinGeometry Q) : + (∀ i j, compactSpinCode n (Q i j)=compactSpinCode n (Q j i)) ∧ + (∀ i, compactSpinCode n (Q i i)=compactSpinCode n (compactSpinTop,0)) ∧ + ∀ i j k, min (compactSpinCode n (Q i j)) (compactSpinCode n (Q i k)) ≤ compactSpinCode n (Q j k) := by + refine ⟨?_,?_,?_⟩ + · intro i j + exact le_antisymm (compactSpinCode_mono n (hQ.1 i j).le) (compactSpinCode_mono n (hQ.1 i j).ge) + · intro i + exact le_antisymm (compactSpinCode_mono n (hQ.2.1 i).le) (compactSpinCode_mono n (hQ.2.1 i).ge) + · intro i j k + rcases le_total (Q i j).1.val (Q i k).1.val with h|h + · apply (min_le_left _ _).trans + apply compactSpinCode_mono n + simpa only [min_eq_left h] using hQ.2.2 i j k + · apply (min_le_right _ _).trans + apply compactSpinCode_mono n + simpa only [min_eq_right h] using hQ.2.2 i j k + +variable (μ ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) +variable (hGGμ : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect μ n i f g=0) +variable (hGGν : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν n i f g=0) +variable (hμ : ∀ᵐ Q ∂(μ : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) +variable (hν : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) +variable (hpair : (μ : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)) + +include hGGμ hGGν hμ hν hpair in +lemma compactSpinCode_block_law_unique (n r : ℕ) : + (μ : Measure (CompactArray CompactJointOverlap)).map + (fun Q => compactCodeBlock (n:=r+1) (compactSpinCode n) (compactBlock (r+1) Q))= + (ν : Measure (CompactArray CompactJointOverlap)).map + (fun Q => compactCodeBlock (n:=r+1) (compactSpinCode n) (compactBlock (r+1) Q)) := by + apply compact_finite_code_block_unique μ ν hGGμ hGGν (compactSpinCode_measurable n) + (compactSpinCode n (compactSpinTop,0)) + (hμ.mono fun Q hQ => compactSpinCode_geometry n hQ) + (hν.mono fun Q hQ => compactSpinCode_geometry n hQ) _ r + have he := congrArg (fun ρ : Measure CompactOverlap => + ρ.map (fun x => uniformQuantileCell n (compactSpinTime x))) hpair + have hm : Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) := by fun_prop + have hc : Measurable (fun x => uniformQuantileCell n (compactSpinTime x)) := + (uniformQuantileCell_measurable n).comp compactSpinTime_continuous.measurable + rw [Measure.map_map hc hm,Measure.map_map hc hm] at he + exact he + +include hGGμ hGGν hμ hν hpair in +lemma compactSpinCode_integral_unique (n r : ℕ) (F : Matrix (Fin (r+1)) (Fin (r+1)) ℝ →ᵇ ℝ) : + (∫ Q, F (fun i j => compactSpinDecode n (compactSpinCode n (Q i j))) ∂(μ : Measure (CompactArray CompactJointOverlap)))= + ∫ Q, F (fun i j => compactSpinDecode n (compactSpinCode n (Q i j))) ∂(ν : Measure (CompactArray CompactJointOverlap)) := by + let D : FiniteBlock (Fin (n+1)) (r+1) → ℝ := fun A => F (fun i j => compactSpinDecode n (A i j)) + have hD : Measurable D := measurable_of_countable _ + have hm : Measurable (fun Q : CompactArray CompactJointOverlap => + compactCodeBlock (n:=r+1) (compactSpinCode n) (compactBlock (r+1) Q)) := + (compactCodeBlock_measurable (compactSpinCode_measurable n) (r+1)).comp (compactBlock_continuous (r+1)).measurable + have he := congrArg (fun ρ : Measure (FiniteBlock (Fin (n+1)) (r+1)) => ∫ A, D A ∂ρ) + (compactSpinCode_block_law_unique μ ν hGGμ hGGν hμ hν hpair n r) + rw [integral_map hm.aemeasurable hD.aestronglyMeasurable, + integral_map hm.aemeasurable hD.aestronglyMeasurable] at he + exact he + +lemma compactSpinCode_integral_tendsto (ρ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (r : ℕ) (F : Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ) : + Tendsto (fun n => ∫ Q, F (fun i j => compactSpinDecode n (compactSpinCode n (Q i j))) + ∂(ρ : Measure (CompactArray CompactJointOverlap))) atTop + (𝓝 (∫ Q, F (fun i j => (Q i j).1.val) ∂(ρ : Measure (CompactArray CompactJointOverlap)))) := by + let : MeasurableSpace (Matrix (Fin r) (Fin r) ℝ) := inferInstanceAs (MeasurableSpace (Fin r → Fin r → ℝ)) + let : BorelSpace (Matrix (Fin r) (Fin r) ℝ) := inferInstanceAs (BorelSpace (Fin r → Fin r → ℝ)) + apply tendsto_integral_of_dominated_convergence (fun _ => ‖F‖) + · intro n + apply (F.continuous.measurable.comp _).aestronglyMeasurable + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + exact (measurable_of_countable (compactSpinDecode n)).comp ((compactSpinCode_measurable n).comp (by fun_prop)) + · exact integrable_const _ + · intro n + exact ae_of_all _ fun Q => F.norm_coe_le_norm _ + · exact ae_of_all _ fun Q => F.continuous.continuousAt.tendsto.comp + (tendsto_pi_nhds.mpr fun i => tendsto_pi_nhds.mpr fun j => compactSpinDecode_tendsto (Q i j)) + +include hGGμ hGGν hμ hν hpair in + +theorem scalarGram_eq_of_pair_law (r : ℕ) (F : Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ) : + (∫ Q, F (fun i j => (Q i j).1.val) ∂(μ : Measure (CompactArray CompactJointOverlap)))= + ∫ Q, F (fun i j => (Q i j).1.val) ∂(ν : Measure (CompactArray CompactJointOverlap)) := by + cases r with + | zero => + have he : ∀ Q : CompactArray CompactJointOverlap, + F (fun i j : Fin 0 => (Q i j).1.val)=F (fun _ _ => 0) := by + intro Q + congr 1 + exact Subsingleton.elim _ _ + simp only [he,integral_const,probReal_univ,one_smul] + | succ r => + have h1 := compactSpinCode_integral_tendsto μ (r+1) F + have h2 := compactSpinCode_integral_tendsto ν (r+1) F + have he := compactSpinCode_integral_unique μ ν hGGμ hGGν hμ hν hpair + simp_rw [he] at h1 + exact tendsto_nhds_unique h1 h2 + +include hGGμ hGGν hμ hν hpair in + +theorem freshReplicaKernel_eq_of_pair_law (f : ℝ →ᵇ ℝ) (r : ℕ) : + (∫ Q, freshReplicaArrayKernel f r Q ∂(μ : Measure (CompactArray CompactJointOverlap)))= + ∫ Q, freshReplicaArrayKernel f r Q ∂(ν : Measure (CompactArray CompactJointOverlap)) := by + cases r with + | zero => + have he : ∀ Q : CompactArray CompactJointOverlap, + freshReplicaArrayKernel f 0 Q=freshReplicaMatrixKernel f 0 (fun _ _ => 0) := by + intro Q + change freshReplicaMatrixKernel f 0 _=_ + congr 1 + exact Subsingleton.elim _ _ + simp only [he,integral_const,probReal_univ,one_smul] + | succ r => + let F := freshReplicaMatrixKernel f (r+1) + have h1 := compactSpinCode_integral_tendsto μ (r+1) F + have h2 := compactSpinCode_integral_tendsto ν (r+1) F + have he := compactSpinCode_integral_unique μ ν hGGμ hGGν hμ hν hpair + simp_rw [he] at h1 + exact tendsto_nhds_unique h1 h2 + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshGeometry.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..919bc488701a6ad907ab67a00e6f6190b8e94ade --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshGeometry.lean @@ -0,0 +1,106 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.SynchronizedLimit +import OAI.Probability.Perceptron.Cavity.FreshGGUniqueness + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma compact_gg_spin_geometry (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hEx : ∀ e : Equiv.Perm ℕ, MeasurePreserving (compactRelabel (K:=CompactJointOverlap) e) (μ : Measure _) (μ : Measure _)) + (hGG : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect μ n i f g=0) + (hR : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), ∀ n, Matrix.PosSemidef (fun i j : Fin n => (Q i j).1.val)) + (hdiag : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), ∀ i, (Q i i).1.val=1) : + ∀ᵐ Q ∂(μ : Measure _), CompactSpinGeometry Q := by + have hg : ∀ᵐ Q ∂compactRealLaw μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray Prod.fst Q)) := + (ae_map_iff compactArrayReal_measurable.aemeasurable (measurableSet_gram_arrays.preimage + (scalarArray_measurable measurable_fst))).mpr hR + have hu := scalarArray_ultrametric (compactRealLaw μ) (compactRealLaw_exchangeable μ hEx) + (compactRealLaw_gg μ hGG) measurable_fst hg (compactRealLaw_diagonals μ).1 + have hbase : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), + min (Q 0 1).1.val (Q 0 2).1.val ≤ (Q 1 2).1.val := + (ae_map_iff compactArrayReal_measurable.aemeasurable (by measurability)).mp hu + have hdistinct (i j k : ℕ) (hij : i≠j) (hik : i≠k) (hjk : j≠k) : + ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), + min (Q i j).1.val (Q i k).1.val ≤ (Q j k).1.val := by + let g : Fin 3 → ℕ := ![i,j,k] + have hg : Function.Injective g := by + intro a b hab + fin_cases a <;> fin_cases b <;> simp_all [g] + obtain ⟨e,he⟩ := Equiv.Perm.exists_extending_pair (fun a : Fin 3 => a.val) g Fin.val_injective hg + have h0 := he 0 + have h1 := he 1 + have h2 := he 2 + change e 0=i at h0 + change e 1=j at h1 + change e 2=k at h2 + have hh := (hEx e).quasiMeasurePreserving.ae hbase + simpa only [compactRelabel,h0,h1,h2] using hh + have hall : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), + ∀ i j k, i≠j → i≠k → j≠k → min (Q i j).1.val (Q i k).1.val ≤ (Q j k).1.val := by + simp only [ae_all_iff] + exact hdistinct + filter_upwards [hR,hdiag,hall] with Q hQ hd hu + have hs : ∀ i j, (Q i j).1.val=(Q j i).1.val := + gram_array_symmetric (fun i j => (Q i j).1.val) hQ + refine ⟨hs,hd,?_⟩ + intro i j k + by_cases hij : i=j + · subst j + exact min_le_right _ _ + by_cases hik : i=k + · subst k + rw [hs j i] + exact min_le_left _ _ + by_cases hjk : j=k + · subst k + rw [hd j,min_self] + exact (Q i j).1.property.2 + exact hu i j k hij hik hjk + +lemma sourceGibbsArray_limit_spin_diagonal (k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : (n : ℕ) → Fin (n+1) → ℕ) (h : ℕ → Fin (k+1) → ℝ) + (u : (n : ℕ) → Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℕ → ℝ≥0) + (s : ℕ→ℕ) {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), ∀ i, (Q i i).1.val=1 := by + rw [ae_all_iff] + intro i + have hc : IsClosed {Q : CompactArray CompactJointOverlap | (Q i i).1.val=1} := + isClosed_eq (by fun_prop) continuous_const + apply (mem_ae_iff_prob_eq_one hc.measurableSet).mpr + have hv := weak_limit_closed_full hlim hc + (fun n => sourceGibbsArray_closed_full (s n) k f (p (s n)) (d (s n)) (h (s n)) (u (s n)) z (t (s n)) + hc (fun x => sourceJointArray_diagonal x i)) + simp only [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + +lemma source_contact_limit_spin_geometry (k : ℕ) (f : ℝ →ᵇ ℝ) (p d : ℕ → ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 1) (fun _ => 2)) + (hmin : ∀ n, IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k f (fun j => p j.val) (fun j => d j.val) (h n) z (t n) v) + (Icc (fun _ : Fin (n+1) => 1) (fun _ => 2)) (u n)) + {H T : ℝ} (hH : 0≤H) (hhH : ∀ n, h n 0≤H) (ht : ∀ n, (t n:ℝ)≤T) + (hcover : ∀ a b : ℕ, 1≤a+b → ∃ j, p j=a ∧ d j=b) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} {s : ℕ → ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f + (fun a => p a.val) (fun a => d a.val) (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q := by + apply compact_gg_spin_geometry ν + (source_contact_limit_exchangeable k f (fun _ a => p a.val) (fun _ a => d a.val) h u z t s hlim) + (source_contact_limit_joint_gg k f p d z hz hz0 hz1 t h hh0 hh u hu hmin hH hhH ht hs hlim hcover) + (sourceGibbsArray_limit_gram k f (fun _ a => p a.val) (fun _ a => d a.val) h u z t s hlim).1 + (sourceGibbsArray_limit_spin_diagonal k f (fun _ a => p a.val) (fun _ a => d a.val) h u z t s hlim) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshLogRatio.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshLogRatio.lean new file mode 100644 index 0000000000000000000000000000000000000000..685d8407e3d2326ab5526cec194d387b7a973fc6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshLogRatio.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IntegrableGibbs +import OAI.Probability.Perceptron.Cascade.EnrichedPoissonVariance + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma tilt_log_add_bounded {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (H F : S→ℝ) + (hH : Measurable H) (hF : Measurable F) {C : ℝ} (hC : ∀ x, |F x|≤C) + (he : Integrable (fun x => Real.exp (H x)) μ) : + Real.log (tiltPartition μ (fun x => H x+F x) 1)-Real.log (tiltPartition μ H 1)= + Real.log (tiltMean μ H (fun x => Real.exp (F x)) 1) := by + have he1 : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using he + have hi : Integrable (fun x => Real.exp (H x+F x)) μ := by + apply (he.mul_const (Real.exp C)).mono' ((hH.add hF).exp.aestronglyMeasurable) + exact ae_of_all _ fun x => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),Pi.add_apply,Real.exp_add] + exact mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr ((abs_le.mp (hC x)).2)) (Real.exp_pos _).le + have hi1 : Integrable (fun x => Real.exp (1*(H x+F x))) μ := by simpa only [one_mul] using hi + have hp := tilt_partition_pos_of_integrable μ he1 + have hp' := tilt_partition_pos_of_integrable μ hi1 + have heq : tiltMean μ H (fun x => Real.exp (F x)) 1= + tiltPartition μ (fun x => H x+F x) 1/tiltPartition μ H 1 := by + simp only [tiltMean,tiltIntegral,tiltPartition,one_mul,Real.exp_add] + rw [heq,Real.log_div hp'.ne' hp.ne'] + + +lemma patternPrefix_fresh_preserving (N M : ℕ) : + MeasurePreserving (fun g : ℕ→Fin N→ℝ => + (patternPrefix N M g,WithLp.toLp 2 (g M))) + (infinitePatternRowsLaw N) + ((finitePatternRowsLaw N M).prod (stdGaussian (EuclideanSpace ℝ (Fin N)))) := by + let ρ : Measure (Fin N→ℝ) := Measure.pi fun _ => gaussianReal 0 1 + have hfinite := measurePreserving_piFinSuccAbove (fun _ : Fin (M+1) => ρ) (Fin.last M) + have hp := hfinite.comp (patternPrefix_measurePreserving N (M+1)) + have hrow : MeasurePreserving (WithLp.toLp 2 : (Fin N→ℝ)→EuclideanSpace ℝ (Fin N)) + ρ (stdGaussian (EuclideanSpace ℝ (Fin N))) := by + exact ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + have h := (((MeasurePreserving.id (finitePatternRowsLaw N M)).prod hrow).comp + (Measure.measurePreserving_swap (μ := ρ) (ν := finitePatternRowsLaw N M))).comp hp + convert h using 1 + funext g + simp only [Function.comp_def,MeasurableEquiv.piFinSuccAbove_apply] + apply Prod.ext + · funext i j + simp [Fin.init, patternPrefix] + · rfl + +lemma normalizedPatternEnergy_prefix_exact (N M : ℕ) (f : ℝ →ᵇℝ) + (g : ℕ→Fin N→ℝ) (x : NormalizedSpin N) : + normalizedPatternEnergy N (M+1) f (patternPrefix N (M+1) g) x= + normalizedPatternEnergy N M f (patternPrefix N M g) x+ + f (inner ℝ x.val (WithLp.toLp 2 (g M))) := by + unfold normalizedPatternEnergy + rw [Fin.sum_univ_castSucc] + congr 1 + +def patternExtend (N M : ℕ) (a : Fin M→Fin N→ℝ) : ℕ→Fin N→ℝ := + fun i => if hi : i (0 : Fin N→ℝ))) + +lemma patternPrefix_extend (N M : ℕ) (a : Fin M→Fin N→ℝ) : + patternPrefix N M (patternExtend N M a)=a := by + funext i + simp [patternPrefix,patternExtend,i.isLt] + +lemma patternPrefix_fresh_integral (N M : ℕ) + (F : (Fin M→Fin N→ℝ) × EuclideanSpace ℝ (Fin N) → ℝ) (hF : Measurable F) + (hi : Integrable (fun a => F (patternPrefix N M a,WithLp.toLp 2 (a M))) (infinitePatternRowsLaw N)) : + (∫ a, F (patternPrefix N M a,WithLp.toLp 2 (a M)) ∂infinitePatternRowsLaw N)= + ∫ a, ∫ g, F (patternPrefix N M a,g) ∂stdGaussian (EuclideanSpace ℝ (Fin N)) + ∂infinitePatternRowsLaw N := by + have hp := patternPrefix_fresh_preserving N M + have hfi : Integrable F ((finitePatternRowsLaw N M).prod (stdGaussian (EuclideanSpace ℝ (Fin N)))) := by + rw [← hp.map_eq] + exact (integrable_map_measure hF.aestronglyMeasurable hp.measurable.aemeasurable).mpr hi + have hmap := integral_map (μ := infinitePatternRowsLaw N) (φ := fun a => + (patternPrefix N M a,WithLp.toLp 2 (a M))) (f := F) hp.measurable.aemeasurable + (by rw [hp.map_eq]; exact hF.aestronglyMeasurable) + rw [hp.map_eq] at hmap + rw [← hmap,integral_prod _ hfi] + have hm : Measurable (fun a => ∫ g, F (a,g) ∂stdGaussian (EuclideanSpace ℝ (Fin N))) := + (StronglyMeasurable.integral_prod_right (f := fun a g => F (a,g)) hF.stronglyMeasurable).measurable + have hprefix := patternPrefix_measurePreserving N M + have hi' := integral_map (μ := infinitePatternRowsLaw N) (φ := patternPrefix N M) + (f := fun a => ∫ g, F (a,g) ∂stdGaussian (EuclideanSpace ℝ (Fin N))) + hprefix.measurable.aemeasurable hm.aestronglyMeasurable + rwa [hprefix.map_eq] at hi' + +lemma patternPrefix_fresh_product_integral {B : Type*} [MeasurableSpace B] + (ν : Measure B) [IsProbabilityMeasure ν] (N M : ℕ) + (F : ((Fin M→Fin N→ℝ) × EuclideanSpace ℝ (Fin N)) × B → ℝ) (hF : Measurable F) + (hi : Integrable (fun a => F ((patternPrefix N M a.1,WithLp.toLp 2 (a.1 M)),a.2)) + ((infinitePatternRowsLaw N).prod ν)) : + (∫ a, F ((patternPrefix N M a.1,WithLp.toLp 2 (a.1 M)),a.2) + ∂(infinitePatternRowsLaw N).prod ν)= + ∫ a, ∫ g, F ((patternPrefix N M a.1,g),a.2) ∂stdGaussian (EuclideanSpace ℝ (Fin N)) + ∂(infinitePatternRowsLaw N).prod ν := by + let R := infinitePatternRowsLaw N + let G := stdGaussian (EuclideanSpace ℝ (Fin N)) + let T := ((finitePatternRowsLaw N M).prod G).prod ν + have hp : MeasurePreserving (fun a : (ℕ→Fin N→ℝ) × B => + ((patternPrefix N M a.1,WithLp.toLp 2 (a.1 M)),a.2)) (R.prod ν) T := + (patternPrefix_fresh_preserving N M).prod (MeasurePreserving.id ν) + have hfi : Integrable F T := by + rw [← hp.map_eq] + exact (integrable_map_measure hF.aestronglyMeasurable hp.measurable.aemeasurable).mpr hi + have hrotate : MeasurePreserving (fun a : ((ℕ→Fin N→ℝ) × B) × EuclideanSpace ℝ (Fin N) => + ((a.1.1,a.2),a.1.2)) ((R.prod ν).prod G) ((R.prod G).prod ν) := + (measurePreserving_prodAssoc R G ν).symm.comp + (((MeasurePreserving.id R).prod (Measure.measurePreserving_swap (μ := ν) (ν := G))).comp + (measurePreserving_prodAssoc R ν G)) + have hq : MeasurePreserving (fun a : ((ℕ→Fin N→ℝ) × B) × EuclideanSpace ℝ (Fin N) => + ((patternPrefix N M a.1.1,a.2),a.1.2)) ((R.prod ν).prod G) T := + (((patternPrefix_measurePreserving N M).prod (MeasurePreserving.id G)).prod (MeasurePreserving.id ν)).comp hrotate + have hiq := hq.integrable_comp_of_integrable hfi + have hpint := integral_map (φ := fun a : (ℕ→Fin N→ℝ) × B => + ((patternPrefix N M a.1,WithLp.toLp 2 (a.1 M)),a.2)) (f := F) + hp.measurable.aemeasurable (by rw [hp.map_eq]; exact hfi.aestronglyMeasurable) + have hqint := integral_map (φ := fun a : ((ℕ→Fin N→ℝ) × B) × EuclideanSpace ℝ (Fin N) => + ((patternPrefix N M a.1.1,a.2),a.1.2)) (f := F) + hq.measurable.aemeasurable (by rw [hq.map_eq]; exact hfi.aestronglyMeasurable) + rw [hp.map_eq] at hpint + rw [hq.map_eq] at hqint + rw [← hpint,hqint] + exact integral_prod _ hiq + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshMarkedKernel.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshMarkedKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..0289d7f8a44c3382d0a72deafcc5ab15da668638 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshMarkedKernel.lean @@ -0,0 +1,79 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ArrayGeometry + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +private lemma freshMarked_extension_exists {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + ∃ F : Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ, + ‖F‖=‖gaussianCovarianceKernel Ψ‖ ∧ + ∀ C : CovarianceMatrix (Fin r), F C.val=gaussianCovarianceKernel Ψ C := by + let : NormalSpace (Matrix (Fin r) (Fin r) ℝ) := inferInstanceAs (NormalSpace (Fin r→Fin r→ℝ)) + obtain ⟨F,hF,he⟩ := (gaussianCovarianceKernel Ψ).exists_extension_norm_eq_of_isClosedEmbedding + (isClosed_matrix_posSemidef r).isClosedEmbedding_subtypeVal + exact ⟨F,hF,fun C => congrFun he C⟩ + +def freshMarkedMatrixKernel {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ := Classical.choose (freshMarked_extension_exists Ψ) + +lemma freshMarkedMatrixKernel_gram {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] (v : Fin r→E) : + freshMarkedMatrixKernel Ψ (Matrix.gram ℝ v)= + ∫ z, Ψ z ∂multivariateGaussian 0 (Matrix.gram ℝ v) := + (Classical.choose_spec (freshMarked_extension_exists Ψ)).2 (gramCovariance v) + +def freshMarkedArrayKernel {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + CompactArray CompactJointOverlap →ᵇ ℝ := + (freshMarkedMatrixKernel Ψ).compContinuous + ⟨fun Q => fun i j : Fin r => (Q i j).1.val,by fun_prop⟩ + +lemma freshMarkedArrayKernel_source {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + {N k : ℕ} (x : ℕ→NormalizedSpin N×IndexedLeaf k) : + freshMarkedArrayKernel Ψ (sourceJointArray x)= + ∫ z, Ψ z ∂multivariateGaussian 0 + (Matrix.gram ℝ (fun i : Fin r => (x i).1.val)) := by + change freshMarkedMatrixKernel Ψ _=_ + convert freshMarkedMatrixKernel_gram Ψ (fun i : Fin r => (x i).1.val) using 1 + congr 1 + +lemma freshMarkedArrayKernel_tendsto {ν : ℕ→ProbabilityMeasure (CompactArray CompactJointOverlap)} + {ν₀ : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hν : Tendsto ν atTop (𝓝 ν₀)) {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + Tendsto (fun n => ∫ Q, freshMarkedArrayKernel Ψ Q ∂ν n) atTop + (𝓝 (∫ Q, freshMarkedArrayKernel Ψ Q ∂ν₀)) := + (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (freshMarkedArrayKernel Ψ)).continuousAt.tendsto.comp hν + +lemma freshMarkedMatrixKernel_gaussian {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (v : Fin r→E) : + (∫ g, Ψ (gaussianRows v g) ∂stdGaussian E) = freshMarkedMatrixKernel Ψ (Matrix.gram ℝ v) := by + rw [freshMarkedMatrixKernel_gram,←gaussianRows_map_stdGaussian v, + integral_map (gaussianRows v).continuous.measurable.aemeasurable Ψ.continuous.aestronglyMeasurable] + +lemma freshMarkedMatrixKernel_two {r : ℕ} (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (v : Fin r→E) : + (∫ g, Ψ (gaussianRows v g.1)*Φ (gaussianRows v g.2) + ∂(stdGaussian E).prod (stdGaussian E)) = + freshMarkedMatrixKernel Ψ (Matrix.gram ℝ v)*freshMarkedMatrixKernel Φ (Matrix.gram ℝ v) := by + rw [integral_prod_mul (fun g => Ψ (gaussianRows v g)) (fun g => Φ (gaussianRows v g))] + rw [freshMarkedMatrixKernel_gaussian,freshMarkedMatrixKernel_gaussian] + +lemma twoMarkedArrayKernel_tendsto {ν : ℕ→ProbabilityMeasure (CompactArray CompactJointOverlap)} + {ν₀ : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hν : Tendsto ν atTop (𝓝 ν₀)) {r : ℕ} (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (G : CompactArray CompactJointOverlap →ᵇ ℝ) : + Tendsto (fun n => ∫ Q, G Q*freshMarkedArrayKernel Ψ Q*freshMarkedArrayKernel Φ Q ∂ν n) atTop + (𝓝 (∫ Q, G Q*freshMarkedArrayKernel Ψ Q*freshMarkedArrayKernel Φ Q ∂ν₀)) := by + exact (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (G*freshMarkedArrayKernel Ψ*freshMarkedArrayKernel Φ)).continuousAt.tendsto.comp hν + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshMomentLimit.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshMomentLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..124c1b1932c115d9a0cef31f5b5939f61dfa62f2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshMomentLimit.lean @@ -0,0 +1,102 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshReplicaKernel +import OAI.Probability.Perceptron.Cavity.FreshThermalLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma compact_moment_limit {a b : ℝ} (μ : ℕ→ProbabilityMeasure (Icc a b)) + (mom : ℕ→ℝ) + (hmom : ∀ r, Tendsto (fun n => ∫ x, x.val^r ∂(μ n : Measure (Icc a b))) atTop (𝓝 (mom r))) : + ∃ ν : ProbabilityMeasure (Icc a b), Tendsto μ atTop (𝓝 ν) ∧ + ∀ r, (∫ x, x.val^r ∂(ν : Measure (Icc a b)))=mom r := by + obtain ⟨ν, -, s, hs, hsub⟩ := isCompact_univ.isSeqCompact (fun n => mem_univ (μ n)) + have hm r : (∫ x, x.val^r ∂(ν : Measure (Icc a b)))=mom r := by + let F : Icc a b→ᵇℝ := BoundedContinuousFunction.mkOfCompact ⟨fun x => x.val^r,by fun_prop⟩ + have h₁ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction F).continuousAt.tendsto.comp hsub + have h₂ := (hmom r).comp hs.tendsto_atTop + exact tendsto_nhds_unique h₁ h₂ + refine ⟨ν,?_,hm⟩ + apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr + intro F + apply integral_continuous_tendsto_of_moments (fun n => (μ n : Measure (Icc a b))) + (ν : Measure (Icc a b)) (fun r => ?_) F.toContinuousMap + rw [hm] + exact hmom r + + +lemma sourceFresh_exp_ae (n k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) : + ∀ᵐ a ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw, + Integrable (fun x => Real.exp (sourceCouplingHamiltonian n k f p d h u a x)) + (sourceFullSpinLeafKernel n k a) := by + filter_upwards [sourceCoupling_all_exp_ae n k f p d h hh0 hh u 0 z t] with a ha + simpa only [sourceFullSpinLeafKernel,Kernel.comap_apply,zero_mul,add_zero] using ha 0 + +def sourceFreshPartitionLaw (n k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) : + ProbabilityMeasure (FreshPartitionRange f) := + freshThermalLaw (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) + (sourceCouplingHamiltonian_measurable n k f p d h u) + (fun x => x.1.val) (measurable_subtype_coe.comp measurable_fst) f + +def sourceFreshLog (n k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) : ℝ := + ∫ a, ∫ g, Real.log (tiltMean (sourceFullSpinLeafKernel n k a) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => Real.exp (f (inner ℝ x.1.val g))) 1) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1))) + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw + +lemma sourceFreshPartitionLaw_moment (n k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) (r : ℕ) : + (∫ x, x.val^r ∂(sourceFreshPartitionLaw n k f p d h u z t : Measure (FreshPartitionRange f)))= + sourceFreshMoment n k f (expBCF 1 f) p d h u z t r := + freshThermalLaw_moment _ _ _ _ _ _ _ (sourceFresh_exp_ae n k f p d h hh0 hh u z t) r + +lemma sourceFreshPartitionLaw_log (n k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) : + (∫ x, Real.log x.val ∂(sourceFreshPartitionLaw n k f p d h u z t : Measure (FreshPartitionRange f)))= + sourceFreshLog n k f p d h u z t := + freshThermalLaw_log _ _ _ _ _ _ _ (sourceFresh_exp_ae n k f p d h hh0 hh u z t) + +theorem sourceFreshLog_tendsto (k : ℕ) (f : ℝ →ᵇℝ) + (p d : (n : ℕ)→Fin (n+1)→ℕ) (h : ℕ→Fin (k+1)→ℝ) + (hh0 : ∀ n i, 0≤h n i) (hh : ∀ n, Monotone (h n)) + (u : (n : ℕ)→Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℕ→ℝ≥0) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∃ η : ProbabilityMeasure (FreshPartitionRange f), + Tendsto (fun n => sourceFreshPartitionLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 η) ∧ + (∀ r, (∫ x, x.val^r ∂(η : Measure (FreshPartitionRange f)))= + ∫ Q, freshReplicaArrayKernel (expBCF 1 f) r Q ∂ν) ∧ + Tendsto (fun n => sourceFreshLog (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop + (𝓝 (∫ x, Real.log x.val ∂(η : Measure (FreshPartitionRange f)))) := by + have hmom r := sourceFreshMoment_tendsto k f (expBCF 1 f) p d h hh0 hh u z t s hlim r + simp_rw [← sourceFreshPartitionLaw_moment _ _ _ _ _ _ (hh0 _) (hh _)] at hmom + obtain ⟨η,hη,hm⟩ := compact_moment_limit _ _ hmom + refine ⟨η,hη,hm,?_⟩ + have hlog : Continuous (fun x : FreshPartitionRange f => Real.log x.val) := + continuous_subtype_val.log fun x => ne_of_gt ((Real.exp_pos _).trans_le x.prop.1) + let F : FreshPartitionRange f→ᵇℝ := BoundedContinuousFunction.mkOfCompact ⟨_,hlog⟩ + have ht := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction F).continuousAt.tendsto.comp hη + change Tendsto (fun n => ∫ x, Real.log x.val ∂(sourceFreshPartitionLaw (s n) k f (p (s n)) + (d (s n)) (h (s n)) (u (s n)) z (t (s n)) : Measure (FreshPartitionRange f))) atTop _ at ht + simpa only [F,BoundedContinuousFunction.mkOfCompact_apply,ContinuousMap.coe_mk,sourceFreshPartitionLaw_log _ _ _ _ _ _ (hh0 _) (hh _)] using ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshReference.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..28a2b91651d59436bb5b0e8260d3cb928ae4719a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshReference.lean @@ -0,0 +1,114 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshThermalLaw +import OAI.Probability.Perceptron.Cavity.LeafFreshLog + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev SourceFreshReferenceData (n k : ℕ) (p : Fin (n+1)→ℕ) := + (EuclideanSpace ℝ (Fin 1)×EnrichedMark (n+1) (n+1) p)× + (IndexedCascadeBase k×(IndexedCascadeMarks (EuclideanSpace ℝ (Fin 1)) k× + IndexedCascadeMarks (EnrichedMark (n+1) (n+1) p) k)) + +def sourceFreshReferenceLog (n M k : ℕ) (f : ℝ →ᵇ ℝ) (a : Fin M→Fin (n+1)→ℝ) + (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (A : ℕ→EuclideanSpace ℝ (Fin 1) →L[ℝ] EuclideanSpace ℝ (Fin 1)) + (R : EuclideanSpace ℝ (Fin 1) →L[ℝ] EuclideanSpace ℝ (Fin 1)) + (F : EuclideanSpace ℝ (Fin 1)→ℝ) (v : SourceFreshReferenceData n k p) : ℝ := + Real.log (tiltMean (indexedLeafProbability k v.2.1) + (fun l => enrichedTerminal n M f a p u (h (Fin.last k)) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h v.1.2),v.2.2.2) l 0)) + (fun l => Real.exp (F (indexedLeafState (gaussianLinearMarkStep A) k + ((fun _ => R v.1.1),v.2.2.1) l 0))) 1) + +lemma sourceFreshReferenceLog_measurable (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (A : ℕ→EuclideanSpace ℝ (Fin 1) →L[ℝ] EuclideanSpace ℝ (Fin 1)) + (R : EuclideanSpace ℝ (Fin 1) →L[ℝ] EuclideanSpace ℝ (Fin 1)) + {F : EuclideanSpace ℝ (Fin 1)→ℝ} (hF : Measurable F) : + Measurable (sourceFreshReferenceLog n M k f a p d h u A R F) := by + let κ : Kernel (SourceFreshReferenceData n k p) (IndexedLeaf k) := + (indexedLeafKernel k).comap (fun v => v.2.1) measurable_snd.fst + have hs₁ : Measurable (fun t : SourceFreshReferenceData n k p×IndexedLeaf k => + indexedLeafState (gaussianLinearMarkStep A) k + ((fun _ => R t.1.1.1),t.1.2.2.1) t.2) := + (indexedLeafState_measurable (gaussianLinearMarkStep_measurable A) k).comp + (show Measurable (fun t : SourceFreshReferenceData n k p×IndexedLeaf k => + (((fun _ => R t.1.1.1),t.1.2.2.1),t.2)) from by fun_prop) + have hs₂ : Measurable (fun t : SourceFreshReferenceData n k p×IndexedLeaf k => + indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h t.1.1.2),t.1.2.2.2) t.2) := + (indexedLeafState_measurable + (gaussianLinearMarkStep_measurable (enrichedIncrementMap p d h)) k).comp + (show Measurable (fun t : SourceFreshReferenceData n k p×IndexedLeaf k => + (((fun _ => enrichedRootMap p d h t.1.1.2),t.1.2.2.2),t.2)) from by fun_prop) + exact (kernel_tiltMean_measurable κ + (H := fun v l => enrichedTerminal n M f a p u (h (Fin.last k)) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h v.1.2),v.2.2.2) l 0)) + (Y := fun v l => Real.exp (F (indexedLeafState (gaussianLinearMarkStep A) k + ((fun _ => R v.1.1),v.2.2.1) l 0))) + ((enrichedTerminal_lipschitz n M f a p u (h (Fin.last k))).continuous.measurable.comp + ((measurable_pi_apply 0).comp hs₂)) + (hF.comp ((measurable_pi_apply 0).comp hs₁) |>.exp)).log + +lemma sourceFreshReferenceLog_bound (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (A : ℕ→EuclideanSpace ℝ (Fin 1) →L[ℝ] EuclideanSpace ℝ (Fin 1)) + (R : EuclideanSpace ℝ (Fin 1) →L[ℝ] EuclideanSpace ℝ (Fin 1)) + {F : EuclideanSpace ℝ (Fin 1)→ℝ} {C : ℝ} (hC : 0≤C) (hFC : ∀ x, |F x|≤C) + (v : SourceFreshReferenceData n k p) : + |sourceFreshReferenceLog n M k f a p d h u A R F v|≤C := by + exact log_tiltMean_exp_bound_general _ (measurable_of_countable _) + (measurable_of_countable _) hC (fun _ => hFC _) + +theorem source_countable_fresh_reference_value (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 by + simpa only [Real.norm_eq_abs] using sourceFreshReferenceLog_bound n M k f a p d h u A R hC hFC v + rw [integral_prod _ hi] + exact source_leaf_independent_fresh_log_roots n M k f a p d h u z hz hz0 hz1 A R hF + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshReplicaKernel.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshReplicaKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..b6258f77906ce541304bebf992ab023a0078f628 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshReplicaKernel.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ArrayGeometry + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction NNReal + +private lemma freshKernel_extension_exists (f : ℝ →ᵇ ℝ) (r : ℕ) : + ∃ F : Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ, + ‖F‖=‖gaussianCovarianceKernel (gaussianReplicaTest (ι := Fin r) f)‖ ∧ + ∀ C : CovarianceMatrix (Fin r), F C.val=gaussianCovarianceKernel (gaussianReplicaTest f) C := by + let : NormalSpace (Matrix (Fin r) (Fin r) ℝ) := inferInstanceAs (NormalSpace (Fin r→Fin r→ℝ)) + obtain ⟨F,hF,he⟩ := (gaussianCovarianceKernel (gaussianReplicaTest (ι := Fin r) f)).exists_extension_norm_eq_of_isClosedEmbedding + (isClosed_matrix_posSemidef r).isClosedEmbedding_subtypeVal + exact ⟨F,hF,fun C => congrFun he C⟩ + +def freshReplicaMatrixKernel (f : ℝ →ᵇ ℝ) (r : ℕ) : Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ := + Classical.choose (freshKernel_extension_exists f r) + +lemma freshReplicaMatrixKernel_gram (f : ℝ →ᵇ ℝ) (r : ℕ) + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] (v : Fin r→E) : + freshReplicaMatrixKernel f r (Matrix.gram ℝ v)= + ∫ z, gaussianReplicaTest f z ∂multivariateGaussian 0 (Matrix.gram ℝ v) := + (Classical.choose_spec (freshKernel_extension_exists f r)).2 (gramCovariance v) + +def freshReplicaArrayKernel (f : ℝ →ᵇ ℝ) (r : ℕ) : CompactArray CompactJointOverlap →ᵇ ℝ := + (freshReplicaMatrixKernel f r).compContinuous + ⟨fun Q => fun i j : Fin r => (Q i j).1.val,by fun_prop⟩ + +lemma freshReplicaArrayKernel_source (f : ℝ →ᵇ ℝ) (r : ℕ) {N k : ℕ} + (x : ℕ→NormalizedSpin N×IndexedLeaf k) : + freshReplicaArrayKernel f r (sourceJointArray x)= + ∫ z, gaussianReplicaTest f z ∂multivariateGaussian 0 + (Matrix.gram ℝ (fun i : Fin r => (x i).1.val)) := by + change freshReplicaMatrixKernel f r _=_ + convert freshReplicaMatrixKernel_gram f r (fun i : Fin r => (x i).1.val) using 1 + congr 1 + +lemma freshReplicaArrayKernel_tendsto {ν : ℕ→ProbabilityMeasure (CompactArray CompactJointOverlap)} + {ν₀ : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hν : Tendsto ν atTop (𝓝 ν₀)) (f : ℝ →ᵇ ℝ) (r : ℕ) : + Tendsto (fun n => ∫ Q, freshReplicaArrayKernel f r Q ∂ν n) atTop + (𝓝 (∫ Q, freshReplicaArrayKernel f r Q ∂ν₀)) := + (ProbabilityMeasure.continuous_integral_boundedContinuousFunction (freshReplicaArrayKernel f r)).continuousAt.tendsto.comp hν + +lemma freshPattern_moment_measurable_spins + {S E : Type*} [MeasurableSpace S] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (μ : Measure S) [IsProbabilityMeasure μ] + (v : S→E) (hv : Measurable v) (f : ℝ →ᵇ ℝ) (r : ℕ) : + (∫ g, (∫ x, f (inner ℝ (v x) g) ∂μ)^r ∂stdGaussian E)= + ∫ xs : Fin r→S, ∫ z, gaussianReplicaTest f z ∂multivariateGaussian 0 + (Matrix.gram ℝ (fun i => v (xs i))) ∂Measure.pi (fun _ => μ) := by + classical + let F : E×(Fin r→S)→ℝ := fun p => ∏ i, f (inner ℝ (v (p.2 i)) p.1) + have hm : Measurable F := Finset.measurable_prod _ fun i _ => f.continuous.measurable.comp + ((hv.comp ((measurable_pi_apply i).comp measurable_snd)).inner measurable_fst) + have hb (p : E×(Fin r→S)) : ‖F p‖≤‖f‖^r := by + simp only [F,norm_prod] + exact (Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) (fun _ _ => f.norm_coe_le_norm _)).trans_eq + (by simp) + have hi : Integrable F ((stdGaussian E).prod (Measure.pi fun _ : Fin r => μ)) := + Integrable.of_bound hm.aestronglyMeasurable _ (ae_of_all _ hb) + calc + _ = ∫ g, ∫ xs : Fin r→S, F (g,xs) ∂Measure.pi (fun _ => μ) ∂stdGaussian E := by + apply integral_congr_ae + filter_upwards [] with g + simpa only [F,Fintype.card_fin] using + (integral_fintype_prod_eq_pow (ι := Fin r) (fun x : S => f (inner ℝ (v x) g)) (μ := μ)).symm + _ = ∫ xs : Fin r→S, ∫ g, F (g,xs) ∂stdGaussian E ∂Measure.pi (fun _ => μ) := + integral_integral_swap hi + _ = _ := by + apply integral_congr_ae + filter_upwards [] with xs + rw [← gaussianRows_map_stdGaussian (fun i => v (xs i)), + integral_map (gaussianRows (fun i => v (xs i))).continuous.measurable.aemeasurable + (gaussianReplicaTest f).continuous.aestronglyMeasurable] + apply integral_congr_ae + filter_upwards [] with g + simp only [F,gaussianReplicaTest_apply,gaussianRows_apply] + +lemma freshPattern_gibbs_moment {S E : Type*} [MeasurableSpace S] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (μ : Measure S) [IsProbabilityMeasure μ] + (v : S→E) (hv : Measurable v) (H : S→ℝ) (hH : Measurable H) + (he : Integrable (fun x => Real.exp (H x)) μ) (f : ℝ →ᵇ ℝ) (r : ℕ) : + (∫ g, (tiltMean μ H (fun x => f (inner ℝ (v x) g)) 1)^r ∂stdGaussian E)= + gibbsReplicaMean μ H r (fun xs => freshReplicaMatrixKernel f r + (Matrix.gram ℝ (fun i => v (xs i)))) := by + have he1 : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using he + let := tilt_law_probability_of_integrable μ he1 + simp_rw [← tilt_law_integral_of_integrable μ hH he1] + rw [gibbsReplicaMean_integral_of_integrable μ hH he, + freshPattern_moment_measurable_spins (tiltLaw μ H 1) v hv f r] + apply integral_congr_ae + exact ae_of_all _ fun xs => (freshReplicaMatrixKernel_gram f r (fun i => v (xs i))).symm + +def sourceFreshMoment (n k : ℕ) (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) (r : ℕ) : ℝ := + ∫ a, ∫ g, (tiltMean (sourceFullSpinLeafKernel n k a) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => ψ (inner ℝ x.1.val g)) 1)^r ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1))) + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw + +lemma sourceFreshMoment_array (n k : ℕ) (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) (r : ℕ) : + sourceFreshMoment n k f ψ p d h u z t r= + ∫ Q, freshReplicaArrayKernel ψ r Q ∂sourceGibbsArrayLaw n k f p d h u z t := by + let F : CompactBlock CompactJointOverlap r→ᵇ ℝ := + (freshReplicaMatrixKernel ψ r).compContinuous + ⟨fun Q => fun i j : Fin r => (Q i j).1.val,by fun_prop⟩ + have hblock := sourceGibbsArray_block_integral n k f p d h hh0 hh u z t r F.measurable + (fun Q => F.norm_coe_le_norm Q) + change (∫ Q, freshReplicaArrayKernel ψ r Q ∂sourceGibbsArrayLaw n k f p d h u z t)=_ at hblock + rw [hblock] + unfold sourceFreshMoment + apply integral_congr_ae + filter_upwards [sourceCoupling_all_exp_ae n k f p d h hh0 hh u 0 z t] with a ha + have he : Integrable (fun x => Real.exp (sourceCouplingHamiltonian n k f p d h u a x)) + (sourceFullSpinLeafKernel n k a) := by + simpa only [sourceFullSpinLeafKernel,Kernel.comap_apply,zero_mul,add_zero] using ha 0 + have hv : Measurable (fun x : NormalizedSpin (n+1)×IndexedLeaf k => x.1.val) := + measurable_subtype_coe.comp measurable_fst + rw [freshPattern_gibbs_moment _ _ hv _ (sourceCouplingHamiltonian_measurable n k f p d h u).of_uncurry_left he] + rfl + +theorem sourceFreshMoment_tendsto (k : ℕ) (f ψ : ℝ →ᵇ ℝ) + (p d : (n : ℕ)→Fin (n+1)→ℕ) (h : ℕ→Fin (k+1)→ℝ) + (hh0 : ∀ n i, 0≤h n i) (hh : ∀ n, Monotone (h n)) + (u : (n : ℕ)→Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℕ→ℝ≥0) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) (r : ℕ) : + Tendsto (fun n => sourceFreshMoment (s n) k f ψ (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n)) r) atTop + (𝓝 (∫ Q, freshReplicaArrayKernel ψ r Q ∂ν)) := by + simp_rw [sourceFreshMoment_array _ _ _ _ _ _ _ (hh0 _) (hh _)] + exact freshReplicaArrayKernel_tendsto hlim ψ r + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/FreshThermalLaw.lean b/lean/OAI/Probability/Perceptron/Cavity/FreshThermalLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..f03186d72f28b89f8774c937b298d9eb19778410 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/FreshThermalLaw.lean @@ -0,0 +1,176 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.IntegrableReplicaGibbs +import OAI.Probability.Perceptron.Variational.UnboundedContact + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +section + +abbrev FreshPartitionRange (f : ℝ →ᵇ ℝ) := Icc (Real.exp (-‖f‖)) (Real.exp ‖f‖) + +private lemma freshPartition_lower_le_upper (f : ℝ →ᵇ ℝ) : Real.exp (-‖f‖)≤Real.exp ‖f‖ := + Real.exp_le_exp.mpr (neg_le_self (norm_nonneg f)) + +def freshPartitionClip (f : ℝ →ᵇ ℝ) (x : ℝ) : FreshPartitionRange f := + ⟨max (Real.exp (-‖f‖)) (min (Real.exp ‖f‖) x),le_max_left _ _, + max_le (freshPartition_lower_le_upper f) (min_le_left _ _)⟩ + +lemma freshPartitionClip_measurable (f : ℝ →ᵇ ℝ) : Measurable (freshPartitionClip f) := by + apply Measurable.subtype_mk + exact measurable_const.max (measurable_const.min measurable_id) + +lemma freshPartitionClip_eq (f : ℝ →ᵇ ℝ) {x : ℝ} (hx : x∈FreshPartitionRange f) : + (freshPartitionClip f x).val=x := by + dsimp [freshPartitionClip] + rw [min_eq_right hx.2,max_eq_right hx.1] + +variable {A S E : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] +variable [MeasurableSpace E] [BorelSpace E] +variable (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) [IsProbabilityMeasure P] +variable (H : A→S→ℝ) (hH : Measurable (Function.uncurry H)) +variable (v : S→E) (hv : Measurable v) (f : ℝ →ᵇ ℝ) + +def freshThermalPartition (a : A×E) : ℝ := + tiltMean (κ a.1) (H a.1) (fun x => Real.exp (f (inner ℝ (v x) a.2))) 1 + +include hH hv in +lemma freshThermalPartition_measurable : Measurable (freshThermalPartition κ H v f) := by + let κ' : Kernel (A×E) S := κ.comap (fun a : A×E => a.1) measurable_fst + have hH' : Measurable (fun a : (A×E)×S => H a.1.1 a.2) := + hH.comp (measurable_fst.fst.prodMk measurable_snd) + have hF : Measurable (fun a : (A×E)×S => Real.exp (f (inner ℝ (v a.2) a.1.2))) := + (f.measurable.comp ((hv.comp measurable_snd).inner measurable_fst.snd)).exp + exact kernel_tiltMean_measurable κ' hH' hF + +include hH hv in +lemma freshThermalPartition_mem {a : A} + (he : Integrable (fun x => Real.exp (H a x)) (κ a)) (g : E) : + freshThermalPartition κ H v f (a,g)∈FreshPartitionRange f := by + have he1 : Integrable (fun x => Real.exp (1*H a x)) (κ a) := by simpa only [one_mul] using he + let := tilt_law_probability_of_integrable (κ a) he1 + let μ := tiltLaw (κ a) (H a) 1 + have hm : Measurable (fun x => Real.exp (f (inner ℝ (v x) g))) := + (f.measurable.comp (hv.inner measurable_const)).exp + have hi : Integrable (fun x => Real.exp (f (inner ℝ (v x) g))) μ := by + apply Integrable.of_bound hm.aestronglyMeasurable (Real.exp ‖f‖) + exact ae_of_all _ fun x => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans (f.norm_coe_le_norm _)) + have hb x := abs_le.mp (f.norm_coe_le_norm (inner ℝ (v x) g)) + unfold freshThermalPartition + rw [← tilt_law_integral_of_integrable (κ a) hH.of_uncurry_left he1] + constructor + · simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono (integrable_const (Real.exp (-‖f‖))) hi (fun x => Real.exp_le_exp.mpr (hb x).1) + · simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono hi (integrable_const (Real.exp ‖f‖)) (fun x => Real.exp_le_exp.mpr (hb x).2) + +def freshThermalLaw : ProbabilityMeasure (FreshPartitionRange f) := + ⟨(P.prod (stdGaussian E)).map (fun a => freshPartitionClip f (freshThermalPartition κ H v f a)), by + exact (Measure.isProbabilityMeasure_map_iff ((freshPartitionClip_measurable f).comp + (freshThermalPartition_measurable κ H hH v hv f)).aemeasurable).2 inferInstance⟩ + +lemma freshThermalLaw_integral (he : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) + (F : ℝ→ℝ) (hF : Measurable F) : + (∫ x, F x.val ∂(freshThermalLaw κ P H hH v hv f : Measure (FreshPartitionRange f)))= + ∫ a, F (freshThermalPartition κ H v f a) ∂P.prod (stdGaussian E) := by + change (∫ x : FreshPartitionRange f, F x.val ∂(P.prod (stdGaussian E)).map + (fun a => freshPartitionClip f (freshThermalPartition κ H v f a)))=_ + have hmap := integral_map (μ := P.prod (stdGaussian E)) + (f := fun x : FreshPartitionRange f => F x.val) + (φ := fun a => freshPartitionClip f (freshThermalPartition κ H v f a)) + (((freshPartitionClip_measurable f).comp + (freshThermalPartition_measurable κ H hH v hv f)).aemeasurable) + ((hF.comp measurable_subtype_coe).aestronglyMeasurable) + refine hmap.trans ?_ + apply integral_congr_ae + filter_upwards [measurePreserving_fst.quasiMeasurePreserving.ae he] with a ha + rw [freshPartitionClip_eq f (freshThermalPartition_mem κ H hH v hv f ha a.2)] + +include hH hv in +lemma freshThermalPartition_power_integrable (r : ℕ) : + Integrable (fun a => freshThermalPartition κ H v f a^r) (P.prod (stdGaussian E)) := by + apply Integrable.of_bound ((freshThermalPartition_measurable κ H hH v hv f).pow_const r).aestronglyMeasurable + ((Real.exp ‖f‖)^r) + apply ae_of_all + intro a + rw [norm_pow,Real.norm_eq_abs] + apply pow_le_pow_left₀ (abs_nonneg _) + apply tiltMean_bound_general (κ a.1) hH.of_uncurry_left + ((f.measurable.comp (hv.inner measurable_const)).exp) (Real.exp_pos _).le + intro x + rw [abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((abs_le.mp (f.norm_coe_le_norm _)).2) + +lemma freshThermalLaw_moment (he : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) (r : ℕ) : + (∫ x, x.val^r ∂(freshThermalLaw κ P H hH v hv f : Measure (FreshPartitionRange f)))= + ∫ a, ∫ g, (tiltMean (κ a) (H a) (fun x => expBCF 1 f (inner ℝ (v x) g)) 1)^r + ∂stdGaussian E ∂P := by + rw [freshThermalLaw_integral κ P H hH v hv f he (fun x => x^r) (by fun_prop), + integral_prod _ (freshThermalPartition_power_integrable κ P H hH v hv f r)] + simp only [freshThermalPartition,expBCF_apply,one_mul] + +include hH hv in +lemma freshThermalPartition_log_integrable + (he : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) : + Integrable (fun a => Real.log (freshThermalPartition κ H v f a)) (P.prod (stdGaussian E)) := by + apply Integrable.of_bound + ((freshThermalPartition_measurable κ H hH v hv f).log).aestronglyMeasurable ‖f‖ + filter_upwards [measurePreserving_fst.quasiMeasurePreserving.ae he] with a ha + have hb := freshThermalPartition_mem κ H hH v hv f ha a.2 + have hpos : 0 Real.exp (H a x)) (κ a)) : + (∫ x, Real.log x.val ∂(freshThermalLaw κ P H hH v hv f : Measure (FreshPartitionRange f)))= + ∫ a, ∫ g, Real.log (tiltMean (κ a) (H a) + (fun x => Real.exp (f (inner ℝ (v x) g))) 1) ∂stdGaussian E ∂P := by + rw [freshThermalLaw_integral κ P H hH v hv f he _ Real.measurable_log, + integral_prod _ (freshThermalPartition_log_integrable κ P H hH v hv f he)] + rfl + +end + +lemma log_tiltMean_exp_bound_general {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {H F : S→ℝ} + (hH : Measurable H) (hF : Measurable F) {C : ℝ} (hC : 0≤C) + (hFC : ∀ x, |F x|≤C) : + |Real.log (tiltMean μ H (fun x => Real.exp (F x)) 1)|≤C := by + by_cases hi : Integrable (fun x => Real.exp (1*H x)) μ + · let := tilt_law_probability_of_integrable μ hi + let ν := tiltLaw μ H 1 + have hf : Integrable (fun x => Real.exp (F x)) ν := by + apply Integrable.of_bound hF.exp.aestronglyMeasurable (Real.exp C) + exact ae_of_all _ fun x => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (abs_le.mp (hFC x)).2 + have hlo : Real.exp (-C)≤∫ x, Real.exp (F x) ∂ν := by + simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono (integrable_const (Real.exp (-C))) hf + (fun x => Real.exp_le_exp.mpr (abs_le.mp (hFC x)).1) + have hhi : (∫ x, Real.exp (F x) ∂ν)≤Real.exp C := by + simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono hf (integrable_const (Real.exp C)) + (fun x => Real.exp_le_exp.mpr (abs_le.mp (hFC x)).2) + have hp := (Real.exp_pos (-C)).trans_le hlo + rw [← tilt_law_integral_of_integrable μ hH hi] + apply abs_le.mpr + constructor + · exact (Real.log_exp (-C)).symm.trans_le (Real.log_le_log (Real.exp_pos _) hlo) + · exact (Real.log_le_log hp hhi).trans_eq (Real.log_exp C) + · simp only [tiltMean,tiltPartition,integral_undef hi,div_zero,Real.log_zero,abs_zero] + exact hC + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/IndexedFreshTilt.lean b/lean/OAI/Probability/Perceptron/Cavity/IndexedFreshTilt.lean new file mode 100644 index 0000000000000000000000000000000000000000..41d09cf44c9a0ca5aa37bd3a6c96b41573c2c401 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/IndexedFreshTilt.lean @@ -0,0 +1,96 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.IndexedGibbsPartition +import OAI.Probability.Perceptron.Cascade.CascadeIndependentTilt + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal +namespace SphericalPerceptronFreeEnergy + +lemma indexedLeaf_tilt_terminal_ratio {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) {step : X×S→X} (hs : Measurable step) + {H G : X→ℝ} (hH : Measurable H) (hG : Measurable G) + (n : ℕ) (b : IndexedCascadeBase n) (hb : IndexedCascadeGood n b) + (hb' : 0<((indexedLeafMeasure n b) univ).toReal) (m : IndexedCascadeMarks S n) (x : X) : + tiltMean (indexedLeafProbability n b) + (fun l => G (indexedLeafState step n (x,m) l)) + (fun l => Real.exp (H (indexedLeafState step n (x,m) l))) 1 = + decoratedTerminalTotal step (fun x => H x+G x) n (x,indexedCascadeRealize n (b,m)) / + decoratedTerminalTotal step G n (x,indexedCascadeRealize n (b,m)) := by + have hzero := indexedLeafProbability_terminal_integral ν hs (H := fun _ => 0) + measurable_const n b hb hb' m x + simp only [Real.exp_zero,integral_const,probReal_univ,one_smul] at hzero + have hne : decoratedTerminalTotal step (fun _ => 0) n (x,indexedCascadeRealize n (b,m))≠0 := by + intro hz + rw [hz,div_zero] at hzero + exact one_ne_zero hzero + unfold tiltMean tiltIntegral tiltPartition + simp only [one_mul] + have he : (fun l => Real.exp (G (indexedLeafState step n (x,m) l)) * + Real.exp (H (indexedLeafState step n (x,m) l))) = + (fun l => Real.exp ((fun y => H y+G y) (indexedLeafState step n (x,m) l))) := by + funext l + rw [Real.exp_add,mul_comm] + rw [he,indexedLeafProbability_terminal_integral ν hs (H := fun a => H a+G a) (hH.add hG) n b hb hb' m x, + indexedLeafProbability_terminal_integral ν hs hG n b hb hb' m x] + field_simp + +theorem indexed_independent_fresh_log {X Y S T : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace S] [MeasurableSpace T] + [Nonempty S] [Nonempty T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 G (indexedLeafState + (fun a : (X×Y)×(S×T) => (step₁ (a.1.1,a.2.1),step₂ (a.1.2,a.2.2))) n ((x,y),p.2) l).2) + (fun l => Real.exp (H (indexedLeafState + (fun a : (X×Y)×(S×T) => (step₁ (a.1.1,a.2.1),step₂ (a.1.2,a.2.2))) n ((x,y),p.2) l).1)) 1) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw (productMarkLaw ν ρ) n)) = + finiteCascadeLogRecursion ν step₁ n z H x := by + let step : (X×Y)×(S×T)→X×Y := fun a => (step₁ (a.1.1,a.2.1),step₂ (a.1.2,a.2.2)) + have hs : Measurable step := by fun_prop + let B := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)) + let M := (indexedCascadeMarksLaw (productMarkLaw ν ρ) n : Measure (IndexedCascadeMarks (S×T) n)) + have hb : ∀ᵐ p ∂B.prod M, IndexedCascadeGood n p.1 := + (measurePreserving_fst (μ := B) (ν := M)).quasiMeasurePreserving.ae + (indexedCascadeGood_ae n z hz0 hz1) + have hb' : ∀ᵐ p ∂B.prod M, 0<((indexedLeafMeasure n p.1) univ).toReal := + (measurePreserving_fst (μ := B) (ν := M)).quasiMeasurePreserving.ae + (indexedLeafMeasure_regular n z hz hz0 hz1) + have he : (fun p : IndexedCascadeBase n×IndexedCascadeMarks (S×T) n => + Real.log (tiltMean (indexedLeafProbability n p.1) + (fun l => G (indexedLeafState step n ((x,y),p.2) l).2) + (fun l => Real.exp (H (indexedLeafState step n ((x,y),p.2) l).1)) 1)) =ᵐ[B.prod M] + (fun p => Real.log (decoratedTerminalTotal step (fun a => H a.1+G a.2) n + ((x,y),indexedCascadeRealize n p) / + decoratedTerminalTotal step (fun a => G a.2) n ((x,y),indexedCascadeRealize n p))) := by + filter_upwards [hb,hb'] with p hp hp' + congr 1 + exact indexedLeaf_tilt_terminal_ratio (productMarkLaw ν ρ) hs + (hH.comp measurable_fst) (hG.comp measurable_snd) n p.1 hp hp' p.2 (x,y) + change (∫ p, Real.log (tiltMean (indexedLeafProbability n p.1) + (fun l => G (indexedLeafState step n ((x,y),p.2) l).2) + (fun l => Real.exp (H (indexedLeafState step n ((x,y),p.2) l).1)) 1) ∂B.prod M)=_ + rw [integral_congr_ae he] + have hm : Measurable (fun η : DecoratedCascade (S×T) n => + Real.log (decoratedTerminalTotal step (fun a => H a.1+G a.2) n ((x,y),η) / + decoratedTerminalTotal step (fun a => G a.2) n ((x,y),η))) := by + exact (((decoratedTerminalTotal_measurable (productMarkLaw ν ρ) step hs + ((hH.comp measurable_fst).add (hG.comp measurable_snd)) n z).comp (by fun_prop)).div + ((decoratedTerminalTotal_measurable (productMarkLaw ν ρ) step hs + (hG.comp measurable_snd) n z).comp (by fun_prop))).log + rw [← integral_map (indexedCascadeRealize_measurable n).aemeasurable hm.aestronglyMeasurable, + indexedCascadeRealize_law (productMarkLaw ν ρ) n z] + exact finiteCascade_independent_tilt_log ν ρ step₁ step₂ hs₁ hs₂ n z hz hz0 hz1 hH hG hIH hIG x y + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/LabelFreshKernel.lean b/lean/OAI/Probability/Perceptron/Cavity/LabelFreshKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea71763c36eb2c41f8ac174f395fd93da4d50fbb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/LabelFreshKernel.lean @@ -0,0 +1,124 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshDiagonalNoise +import OAI.Probability.Perceptron.Cavity.FreshMomentLimit +import OAI.Probability.Perceptron.Variational.SynchronizedLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma sourceLabelLevel_val_injective (k : ℕ) : + Function.Injective (fun l : Fin (k+1) => (sourceLabelLevel k l).val) := by + intro i j hij + apply Fin.ext + have h : (i.val:ℝ)=(j.val:ℝ) := by + apply (div_left_inj' (show (k+1:ℕ)≠(0:ℝ) by positivity)).mp + exact hij + exact_mod_cast h + +def labelProfileInterpolant {k : ℕ} (q : Fin (k+1)→ℝ) : Time →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact + ⟨fun u => (Lagrange.interpolate Finset.univ (fun l => (sourceLabelLevel k l).val) q).eval u.val, + by fun_prop⟩ + +lemma labelProfileInterpolant_node {k : ℕ} (q : Fin (k+1)→ℝ) (l : Fin (k+1)) : + labelProfileInterpolant q (sourceLabelLevel k l)=q l := by + exact Lagrange.eval_interpolate_at_node q (sourceLabelLevel_val_injective k).injOn (Finset.mem_univ l) + +def labelFreshBlockKernel {k : ℕ} (q : Fin (k+1)→ℝ) (f : ℝ →ᵇ ℝ) (r : ℕ) : + CompactBlock CompactJointOverlap r →ᵇ ℝ := + (freshReplicaMatrixKernel f r).compContinuous + ⟨fun Q => fun i j => if i=j then 1 else labelProfileInterpolant q (Q i j).2, + by + classical + apply continuous_pi + intro i + apply continuous_pi + intro j + by_cases hij : i=j + · simp only [ite_eq_left hij] + exact continuous_const + · simp only [ite_eq_right hij] + fun_prop⟩ + +def labelFreshArrayKernel {k : ℕ} (q : Fin (k+1)→ℝ) (f : ℝ →ᵇ ℝ) (r : ℕ) : + CompactArray CompactJointOverlap →ᵇ ℝ := + (labelFreshBlockKernel q f r).compContinuous ⟨compactBlock r,compactBlock_continuous r⟩ + +lemma labelFreshBlockKernel_source {N k : ℕ} (q : Fin (k+1)→ℝ) (f : ℝ →ᵇ ℝ) (r : ℕ) + (xs : Fin r→NormalizedSpin N×IndexedLeaf k) : + labelFreshBlockKernel q f r (fun i j => sourceJointOverlap (xs i) (xs j))= + freshReplicaMatrixKernel f r + (fun i j => if i=j then 1 else q (indexedCommonDepth k (xs j).2 (xs i).2)) := by + apply congrArg (freshReplicaMatrixKernel f r) + funext i j + change (if i=j then 1 else labelProfileInterpolant q (sourceJointOverlap (xs i) (xs j)).2)=_ + split_ifs with h + · rfl + · exact labelProfileInterpolant_node q _ + +lemma labelProfile_gibbs_moment {S : Type} [MeasurableSpace S] {k : ℕ} + (q : Fin (k+1)→ℝ) (h0 : 0≤q 0) (hq : Monotone q) (h1 : q (Fin.last k)≤1) + (μ : Measure (S×IndexedLeaf k)) [IsProbabilityMeasure μ] + (H : S×IndexedLeaf k→ℝ) (hH : Measurable H) + (he : Integrable (fun x => Real.exp (H x)) μ) (f : ℝ →ᵇ ℝ) (r : ℕ) : + (∫ g, (tiltMean μ H (fun x => gaussianAverageBCF ⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ f + (labelProfileField q g x)) 1)^r ∂countableGaussianLaw)= + gibbsReplicaMean μ H r (fun xs => freshReplicaMatrixKernel f r + (fun i j => if i=j then 1 else q (indexedCommonDepth k (xs j).2 (xs i).2))) := by + have he1 : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using he + let := tilt_law_probability_of_integrable μ he1 + simp_rw [← tilt_law_integral_of_integrable μ hH he1] + rw [gibbsReplicaMean_integral_of_integrable μ hH he] + exact labelProfile_diagonal_one_moment q h0 hq h1 (tiltLaw μ H 1) f r + +def sourceLabelFreshMoment (n k : ℕ) (q : Fin (k+1)→ℝ) (h1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) (r : ℕ) : ℝ := + ∫ a, ∫ g, (tiltMean (sourceFullSpinLeafKernel n k a) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => gaussianAverageBCF ⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ ψ + (labelProfileField q g x)) 1)^r ∂countableGaussianLaw + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw + +lemma sourceLabelFreshMoment_array (n k : ℕ) (q : Fin (k+1)→ℝ) + (h0 : 0≤q 0) (hq : Monotone q) (h1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) + (hh0 : ∀ i, 0≤h i) (hh : Monotone h) (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) (r : ℕ) : + sourceLabelFreshMoment n k q h1 f ψ p d h u z t r= + ∫ Q, labelFreshArrayKernel q ψ r Q ∂sourceGibbsArrayLaw n k f p d h u z t := by + have hblock := sourceGibbsArray_block_integral n k f p d h hh0 hh u z t r + (labelFreshBlockKernel q ψ r).measurable (fun Q => (labelFreshBlockKernel q ψ r).norm_coe_le_norm Q) + change (∫ Q, labelFreshArrayKernel q ψ r Q ∂sourceGibbsArrayLaw n k f p d h u z t)=_ at hblock + rw [hblock] + unfold sourceLabelFreshMoment + apply integral_congr_ae + filter_upwards [sourceFresh_exp_ae n k f p d h hh0 hh u z t] with a ha + rw [labelProfile_gibbs_moment q h0 hq h1 _ _ + (sourceCouplingHamiltonian_measurable n k f p d h u).of_uncurry_left ha] + congr 1 + funext xs + exact (labelFreshBlockKernel_source q ψ r xs).symm + +theorem sourceLabelFreshMoment_tendsto (k : ℕ) (q : Fin (k+1)→ℝ) + (h0 : 0≤q 0) (hq : Monotone q) (h1 : q (Fin.last k)≤1) (f ψ : ℝ →ᵇ ℝ) + (p d : (n : ℕ)→Fin (n+1)→ℕ) (h : ℕ→Fin (k+1)→ℝ) + (hh0 : ∀ n i, 0≤h n i) (hh : ∀ n, Monotone (h n)) + (u : (n : ℕ)→Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℕ→ℝ≥0) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) (r : ℕ) : + Tendsto (fun n => sourceLabelFreshMoment (s n) k q h1 f ψ (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n)) r) atTop + (𝓝 (∫ Q, labelFreshArrayKernel q ψ r Q ∂ν)) := by + simp_rw [sourceLabelFreshMoment_array _ _ _ h0 hq h1 _ _ _ _ _ (hh0 _) (hh _)] + exact (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (labelFreshArrayKernel q ψ r)).continuousAt.tendsto.comp hlim + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/LabelFreshLog.lean b/lean/OAI/Probability/Perceptron/Cavity/LabelFreshLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..61c6090821da8fd1089c80423357cf7da7cde4bb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/LabelFreshLog.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelThermalLaw +import OAI.Probability.Perceptron.Cavity.LabelFreshKernel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma labelProfileField_measurable {S : Type} [MeasurableSpace S] {k : ℕ} + (q : Fin (k+1)→ℝ) : + Measurable (Function.uncurry (labelProfileField (S := S) q)) := + countableGaussianField_measurable (indexedGaussianRow_measurable _ _ measurable_const) + (indexedGaussianRowLength_measurable k) + +def labelLogResponse {S : Type} {k : ℕ} (q : Fin (k+1)→ℝ) + (hq1 : q (Fin.last k)≤1) (f : ℝ →ᵇ ℝ) (g : ℕ→ℝ) (x : S×IndexedLeaf k) : ℝ := + heatLog ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩ 1 f (labelProfileField q g x) + +lemma labelLogResponse_measurable {S : Type} [MeasurableSpace S] {k : ℕ} + (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) (f : ℝ →ᵇ ℝ) : + Measurable (Function.uncurry (labelLogResponse (S := S) q hq1 f)) := + (heatLog_continuous _ _ f).measurable.comp (labelProfileField_measurable q) + +lemma labelLogResponse_bound {S : Type} {k : ℕ} (q : Fin (k+1)→ℝ) + (hq1 : q (Fin.last k)≤1) (f : ℝ →ᵇ ℝ) (g : ℕ→ℝ) (x : S×IndexedLeaf k) : + |labelLogResponse q hq1 f g x|≤‖f‖ := heatLog_abs_le _ _ _ _ + +lemma labelLogResponse_exp {S : Type} {k : ℕ} (q : Fin (k+1)→ℝ) + (hq1 : q (Fin.last k)≤1) (f : ℝ →ᵇ ℝ) (g : ℕ→ℝ) (x : S×IndexedLeaf k) : + Real.exp (labelLogResponse q hq1 f g x)= + gaussianAverageBCF ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩ (expBCF 1 f) + (labelProfileField q g x) := by + change Real.exp (heatLog ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩ 1 f + (labelProfileField q g x)) = gaussianAverage _ (expBCF 1 f) _ + simpa only [NNReal.coe_one,one_mul] using + exp_heatLog ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩ 1 (by norm_num) f (labelProfileField q g x) + +def sourceLabelPartitionLaw (n k : ℕ) (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) : ProbabilityMeasure (FreshPartitionRange ψ) := + boundedThermalLaw (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) countableGaussianLaw + (sourceCouplingHamiltonian n k f p d h u) + (sourceCouplingHamiltonian_measurable n k f p d h u) + (labelLogResponse q hq1 ψ) (labelLogResponse_measurable q hq1 ψ) ψ + +def sourceLabelFreshLog (n k : ℕ) (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) : ℝ := + ∫ a, ∫ g, Real.log (tiltMean (sourceFullSpinLeafKernel n k a) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => gaussianAverageBCF ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩ (expBCF 1 ψ) + (labelProfileField q g x)) 1) ∂countableGaussianLaw + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw + +lemma sourceLabelPartitionLaw_moment (n k : ℕ) (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) + (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) (r : ℕ) : + (∫ x, x.val^r ∂(sourceLabelPartitionLaw n k q hq1 f ψ p d h u z t : + Measure (FreshPartitionRange ψ)))= + sourceLabelFreshMoment n k q hq1 f (expBCF 1 ψ) p d h u z t r := by + have hm := boundedThermalLaw_moment (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) countableGaussianLaw + (sourceCouplingHamiltonian n k f p d h u) + (sourceCouplingHamiltonian_measurable n k f p d h u) + (labelLogResponse q hq1 ψ) (labelLogResponse_measurable q hq1 ψ) ψ + (labelLogResponse_bound q hq1 ψ) (sourceFresh_exp_ae n k f p d h hh0 hh u z t) r + simpa only [sourceLabelPartitionLaw,sourceLabelFreshMoment,labelLogResponse_exp] using hm + +lemma sourceLabelPartitionLaw_log (n k : ℕ) (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) + (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) : + (∫ x, Real.log x.val ∂(sourceLabelPartitionLaw n k q hq1 f ψ p d h u z t : + Measure (FreshPartitionRange ψ)))=sourceLabelFreshLog n k q hq1 f ψ p d h u z t := by + have hm := boundedThermalLaw_log (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) countableGaussianLaw + (sourceCouplingHamiltonian n k f p d h u) + (sourceCouplingHamiltonian_measurable n k f p d h u) + (labelLogResponse q hq1 ψ) (labelLogResponse_measurable q hq1 ψ) ψ + (labelLogResponse_bound q hq1 ψ) (sourceFresh_exp_ae n k f p d h hh0 hh u z t) + simpa only [sourceLabelPartitionLaw,sourceLabelFreshLog,labelLogResponse_exp] using hm + +theorem sourceLabelFreshLog_tendsto (k : ℕ) (q : Fin (k+1)→ℝ) + (h0 : 0≤q 0) (hq : Monotone q) (h1 : q (Fin.last k)≤1) (f ψ : ℝ →ᵇ ℝ) + (p d : (n : ℕ)→Fin (n+1)→ℕ) (h : ℕ→Fin (k+1)→ℝ) + (hh0 : ∀ n i, 0≤h n i) (hh : ∀ n, Monotone (h n)) + (u : (n : ℕ)→Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℕ→ℝ≥0) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∃ η : ProbabilityMeasure (FreshPartitionRange ψ), + Tendsto (fun n => sourceLabelPartitionLaw (s n) k q h1 f ψ (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 η) ∧ + (∀ r, (∫ x, x.val^r ∂(η : Measure (FreshPartitionRange ψ)))= + ∫ Q, labelFreshArrayKernel q (expBCF 1 ψ) r Q ∂ν) ∧ + Tendsto (fun n => sourceLabelFreshLog (s n) k q h1 f ψ (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop + (𝓝 (∫ x, Real.log x.val ∂(η : Measure (FreshPartitionRange ψ)))) := by + have hmom r := sourceLabelFreshMoment_tendsto k q h0 hq h1 f (expBCF 1 ψ) + p d h hh0 hh u z t s hlim r + simp_rw [← sourceLabelPartitionLaw_moment _ _ _ _ _ _ _ _ _ (hh0 _) (hh _)] at hmom + obtain ⟨η,hη,hm⟩ := compact_moment_limit _ _ hmom + refine ⟨η,hη,hm,?_⟩ + let F : FreshPartitionRange ψ→ᵇℝ := BoundedContinuousFunction.mkOfCompact + ⟨fun x => Real.log x.val, continuous_subtype_val.log fun x => + ne_of_gt ((Real.exp_pos _).trans_le x.prop.1)⟩ + have ht := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction F).continuousAt.tendsto.comp hη + change Tendsto (fun n => ∫ x, Real.log x.val ∂(sourceLabelPartitionLaw (s n) k q h1 f ψ (p (s n)) + (d (s n)) (h (s n)) (u (s n)) z (t (s n)) : Measure (FreshPartitionRange ψ))) atTop _ at ht + simpa only [F,BoundedContinuousFunction.mkOfCompact_apply,ContinuousMap.coe_mk, + sourceLabelPartitionLaw_log _ _ _ _ _ _ _ _ _ (hh0 _) (hh _)] using ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Cavity/LeafFreshLog.lean b/lean/OAI/Probability/Perceptron/Cavity/LeafFreshLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..63a7f1c2e2be32f9dc531723e62fa5a3c2466d48 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Cavity/LeafFreshLog.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedMarkProduct + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators ENNReal NNReal BoundedContinuousFunction + +theorem source_leaf_independent_fresh_log + (n M k : ℕ) (f : ℝ →ᵇ ℝ) (a : Fin M→Fin (n+1)→ℝ) + (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 enrichedTerminal n M f a p u (h (Fin.last k)) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => y),b.2.2) l 0)) + (fun l => Real.exp (F (indexedLeafState (gaussianLinearMarkStep A) k + ((fun _ => x),b.2.1) l 0))) 1) + ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ (Fin 1))) k : + Measure (IndexedCascadeMarks (EuclideanSpace ℝ (Fin 1)) k)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EnrichedMark (n+1) (n+1) p)) k))) = + gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (linearCascadeWord A k z) F x := by + let : IsGaussian (gaussianMarkLaw (E := EuclideanSpace ℝ (Fin 1)) : Measure (EuclideanSpace ℝ (Fin 1))) := + (inferInstance : IsGaussian (stdGaussian (EuclideanSpace ℝ (Fin 1)))) + let : IsGaussian (gaussianMarkLaw (E := EnrichedMark (n+1) (n+1) p) : Measure (EnrichedMark (n+1) (n+1) p)) := + (inferInstance : IsGaussian (stdGaussian (EnrichedMark (n+1) (n+1) p))) + have hG := enrichedTerminal_lipschitz n M f a p u (h (Fin.last k)) + have hIF := gaussianLinearRecursion_realization + (gaussianMarkLaw (E := EuclideanSpace ℝ (Fin 1))) A hF k z hz0 + have hIG := gaussianLinearRecursion_realization + (gaussianMarkLaw (E := EnrichedMark (n+1) (n+1) p)) + (enrichedIncrementMap p d h) hG k z hz0 + exact (indexed_independent_arrays_fresh_log + (gaussianMarkLaw (E := EuclideanSpace ℝ (Fin 1))) + (gaussianMarkLaw (E := EnrichedMark (n+1) (n+1) p)) + (gaussianLinearMarkStep A) (gaussianLinearMarkStep (enrichedIncrementMap p d h)) + (gaussianLinearMarkStep_measurable A) + (gaussianLinearMarkStep_measurable (enrichedIncrementMap p d h)) + k z hz hz0 hz1 + (hF.continuous.measurable.comp (measurable_pi_apply 0)) + (hG.continuous.measurable.comp (measurable_pi_apply 0)) + hIF.2 hIG.2 (fun _ => x) (fun _ => y)).trans (hIF.1 (fun _ => x)) + +theorem source_leaf_independent_fresh_log_roots + (n M k : ℕ) (f : ℝ →ᵇ ℝ) (a : Fin M→Fin (n+1)→ℝ) + (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 enrichedTerminal n M f a p u (h (Fin.last k)) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h r.2),b.2.2) l 0)) + (fun l => Real.exp (F (indexedLeafState (gaussianLinearMarkStep A) k + ((fun _ => R r.1),b.2.1) l 0))) 1) + ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ (Fin 1))) k : + Measure (IndexedCascadeMarks (EuclideanSpace ℝ (Fin 1)) k)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EnrichedMark (n+1) (n+1) p)) k))) + ∂(stdGaussian (EuclideanSpace ℝ (Fin 1))).prod + (stdGaussian (EnrichedMark (n+1) (n+1) p))) = + ∫ x, gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (linearCascadeWord A k z) F (R x) ∂stdGaussian (EuclideanSpace ℝ (Fin 1)) := by + simp_rw [source_leaf_independent_fresh_log n M k f a p d h u z hz hz0 hz1 A hF] + simpa only [probReal_univ,one_smul] using + (integral_fun_fst (μ := stdGaussian (EuclideanSpace ℝ (Fin 1))) + (ν := stdGaussian (EnrichedMark (n+1) (n+1) p)) + (fun x => gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (linearCascadeWord A k z) F (R x))) + +lemma freshRoot_swap_nested {A B C : Type*} + [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace C] + (μ : Measure A) (ν : Measure B) (ρ : Measure C) [SFinite μ] [SFinite ν] [SFinite ρ] : + MeasurePreserving (fun t : A×(B×C) => (t.2.1,(t.1,t.2.2))) + (μ.prod (ν.prod ρ)) (ν.prod (μ.prod ρ)) := by + have h₁ := MeasurePreserving.symm MeasurableEquiv.prodAssoc + (measurePreserving_prodAssoc μ ν ρ) + have h₂ := (Measure.measurePreserving_swap (μ := μ) (ν := ν)).prod + (MeasurePreserving.id ρ) + exact (measurePreserving_prodAssoc ν μ ρ).comp (h₂.comp h₁) + +lemma freshRoot_four_shuffle {A B C D : Type*} + [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace C] [MeasurableSpace D] + (μ : Measure A) (ν : Measure B) (ρ : Measure C) (σ : Measure D) + [SFinite μ] [SFinite ν] [SFinite ρ] [SFinite σ] : + MeasurePreserving (fun t : (A×B)×(C×D) => ((t.1.1,t.2.1),(t.1.2,t.2.2))) + ((μ.prod ν).prod (ρ.prod σ)) ((μ.prod ρ).prod (ν.prod σ)) := by + have h₁ := measurePreserving_prodAssoc μ ν (ρ.prod σ) + have h₂ := (MeasurePreserving.id μ).prod (freshRoot_swap_nested ν ρ σ) + have h₃ := MeasurePreserving.symm MeasurableEquiv.prodAssoc + (measurePreserving_prodAssoc μ ρ (ν.prod σ)) + exact h₃.comp (h₂.comp h₁) + +lemma freshRoot_five_regroup {B X S Y T : Type*} + [MeasurableSpace B] [MeasurableSpace X] [MeasurableSpace S] + [MeasurableSpace Y] [MeasurableSpace T] + (β : Measure B) (μ : Measure X) (ν : Measure S) (ρ : Measure Y) (σ : Measure T) + [SFinite β] [SFinite μ] [SFinite ν] [SFinite ρ] [SFinite σ] : + MeasurePreserving + (fun t : B×((X×S)×(Y×T)) => ((t.2.1.1,t.2.2.1),(t.1,(t.2.1.2,t.2.2.2)))) + (β.prod ((μ.prod ν).prod (ρ.prod σ))) ((μ.prod ρ).prod (β.prod (ν.prod σ))) := by + exact (freshRoot_swap_nested β (μ.prod ρ) (ν.prod σ)).comp + ((MeasurePreserving.id β).prod (freshRoot_four_shuffle μ ν ρ σ)) + +lemma indexedGaussian_fresh_regroup_law (k : ℕ) (z : Fin k→ℝ) + (I J : Type) [Fintype I] [Fintype J] : + MeasurePreserving + (fun t : IndexedCascadeBase k×((ℕ→ℝ)×(ℕ→ℝ)) => + (((indexedGaussianDisorder k I t.2.1).1,(indexedGaussianDisorder k J t.2.2).1), + (t.1,((indexedGaussianDisorder k I t.2.1).2,(indexedGaussianDisorder k J t.2.2).2)))) + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + (countableGaussianLaw.prod countableGaussianLaw)) + (((stdGaussian (EuclideanSpace ℝ I)).prod (stdGaussian (EuclideanSpace ℝ J))).prod + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ I)) k : + Measure (IndexedCascadeMarks (EuclideanSpace ℝ I) k)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ J)) k)))) := by + have hI : MeasurePreserving (indexedGaussianDisorder k I) countableGaussianLaw + ((stdGaussian (EuclideanSpace ℝ I)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ I)) k)) := + ⟨indexedGaussianDisorder_measurable k I,indexedGaussianDisorder_law k I⟩ + have hJ : MeasurePreserving (indexedGaussianDisorder k J) countableGaussianLaw + ((stdGaussian (EuclideanSpace ℝ J)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ J)) k)) := + ⟨indexedGaussianDisorder_measurable k J,indexedGaussianDisorder_law k J⟩ + exact (freshRoot_five_regroup _ _ _ _ _).comp + ((MeasurePreserving.id (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k))).prod + (hI.prod hJ)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/ContactControl.lean b/lean/OAI/Probability/Perceptron/Control/ContactControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d87bb7fd17bdd3a20ace721d54f4586bf64c702 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/ContactControl.lean @@ -0,0 +1,152 @@ +import Mathlib +import OAI.Probability.Perceptron.Control.QuantileControlTail +import OAI.Probability.Perceptron.Variational.ContactTail + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +section + +variable (k : ℕ) (P : Measure BrownianPath) (g : Jet3) (p d : ℕ→ℕ) +variable (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) +variable (hw : ∀ i, 0 p i.val) (fun i => d i.val) w q (fun i => (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) (c n)) +variable (hcap : ∀ n, (c n).2.1 (Fin.last k) sourceGibbsArrayLaw (s n) k g.f (fun i => p i.val) (fun i => d i.val) + (c (s n)).2.1 (c (s n)).2.2 (stepCumulative w) (c (s n)).1) atTop (𝓝 ν)) + +include hc hmin hcap hH hcover hs hlim hq in + theorem source_global_contact_control_order [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) : + controlValue P g.f (quantileTrial (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst))) ≤ + controlValue P g.f (weightedStepTrial w q (fun i => (hw i).le) hw1) := by + obtain ⟨he,ht⟩ := source_global_contact_limit_tail_order k P g.f p d w q hw hw1 hq δ α H c + hc hmin hcap hH hcover hs hlim + have := weightedTrialLaw_probability w q (fun i => (hw i).le) hw1 + have : IsProbabilityMeasure ((compactPositivePairLaw ν).map Prod.fst) := + inferInstance + rw [← he] + apply sourceQuantile_control_tail_order P hB g _ _ (boundedQuantile_monotone _) + (boundedQuantile_monotone _) + simpa only [timeLaw_eq_volume] using ht + +end + +section Contact +variable (k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) (p d : ℕ→ℕ) +variable (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) +variable (hw : ∀ i, 0 p i.val) (fun i => d i.val) w q (fun i => (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) (c n)) + +include hc hmin in + +theorem source_global_contact_limit_field_along + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} {s : ℕ→ℕ} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (fun i => p i.val) (fun i => d i.val) + (c (s n)).2.1 (c (s n)).2.2 (stepCumulative w) (c (s n)).1) atTop (𝓝 ν)) + (hcap : ∀ᶠ n in atTop, (c (s n)).2.1 (Fin.last k) sourceGibbsArrayLaw (s n) k f (fun i => p i.val) (fun i => d i.val) + (c (s n)).2.1 (c (s n)).2.2 (stepCumulative w) (c (s n)).1) atTop (𝓝 ν)) + +variable (hcap : ∀ᶠ n in atTop, (c (s n)).2.1 (Fin.last k) p i.val) (fun i => d i.val) + w q (fun i => (hw i).le) hw1 δ α H (hc n) (hmin n) + obtain ⟨hn,hl,-⟩ := source_contact_limit_quantile k f p d w hw hw1 + (fun n => (c n).1) (fun n => (c n).2.1) (fun n => (hc n).2.1.1.1) + (fun n => (hc n).2.1.2) (fun n => (c n).2.2) (fun n => (hc n).2.2) hm hH + (fun n => (hc n).2.1.1.2 0) (T := (α:ℝ)) (fun n => (hc n).1.2) hcover hs hlim + obtain ⟨hr,ht⟩ := sourceGibbsArray_limit_gram k f (fun _ i => p i.val) (fun _ i => d i.val) + (fun n => (c n).2.1) (fun n => (c n).2.2) (stepCumulative w) (fun n => (c n).1) s hlim + apply source_field_stoploss w q (fun i => (hw i).le) hq (compactPositivePairLaw ν) hl + intro a ha0 ha + rw [← compactPositivePairLaw_field_integral ν hr ht hn a] + exact source_global_contact_limit_field_along k P f p d w q hw hw1 δ α H c hc hmin hlim hcap ha0 ha + +include hc hmin hcap hH hcover hs hlim hq in + +theorem source_global_contact_limit_tail_order_along : + quantileTrial (boundedQuantile (weightedTrialLaw w q))= + weightedStepTrial w q (fun i => (hw i).le) hw1 ∧ + ∀ t : Time, (∫ u : Time in Ici t, (boundedQuantile (weightedTrialLaw w q) u:ℝ))≤ + ∫ u : Time in Ici t, (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst) u:ℝ) := by + have := weightedTrialLaw_probability w q (fun i => (hw i).le) hw1 + have : IsProbabilityMeasure ((compactPositivePairLaw ν).map Prod.fst) := + inferInstance + refine ⟨quantileTrial_weightedTrialLaw w q (fun i => (hw i).le) hw1,?_⟩ + apply upper_tail_order_of_stoploss (boundedQuantile_measurable _) + (boundedQuantile_monotone _) + intro r + rw [boundedQuantile_stoploss,boundedQuantile_stoploss,weightedTrialLaw_integral w q (fun i => (hw i).le)] + exact source_global_contact_limit_stoploss_along k P f p d w q hw hw1 hq δ α H c hc hmin hH hcover hs hlim hcap r + +end Contact + +variable (k : ℕ) (P : Measure BrownianPath) (g : Jet3) (p d : ℕ→ℕ) +variable (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) +variable (hw : ∀ i, 0 p i.val) (fun i => d i.val) w q (fun i => (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) (c n)) +variable (hH : 0≤H) (hcover : ∀ a b : ℕ, 1≤a+b → ∃ j, p j=a ∧ d j=b) +variable {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} {s : ℕ→ℕ} (hs : StrictMono s) +variable (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k g.f (fun i => p i.val) (fun i => d i.val) + (c (s n)).2.1 (c (s n)).2.2 (stepCumulative w) (c (s n)).1) atTop (𝓝 ν)) + +variable (hcap : ∀ᶠ n in atTop, (c (s n)).2.1 (Fin.last k) (hw i).le) hw1) := by + obtain ⟨he,ht⟩ := source_global_contact_limit_tail_order_along k P g.f p d w q hw hw1 hq δ α H c + hc hmin hH hcover hs hlim hcap + have := weightedTrialLaw_probability w q (fun i => (hw i).le) hw1 + have : IsProbabilityMeasure ((compactPositivePairLaw ν).map Prod.fst) := + inferInstance + rw [← he] + apply sourceQuantile_control_tail_order P hB g _ _ (boundedQuantile_monotone _) + (boundedQuantile_monotone _) + simpa only [timeLaw_eq_volume] using ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/ControlDrift.lean b/lean/OAI/Probability/Perceptron/Control/ControlDrift.lean new file mode 100644 index 0000000000000000000000000000000000000000..5833c889c12b129f4ca05ab090d7158bceb1ba50 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/ControlDrift.lean @@ -0,0 +1,438 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.Trial + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma abs_hamiltonian_update_sub_le (α : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) + (g : Patterns α N) (a : Fin (patternCount α N)) (y : Fin N → ℝ) (x : Spin N) : + |hamiltonian α φ N (Function.update g a y) x - hamiltonian α φ N g x| ≤ 2 * ‖φ‖ := by + classical + have heq : hamiltonian α φ N (Function.update g a y) x - hamiltonian α φ N g x = + φ (patternField (Function.update g a y) a x) - φ (patternField g a x) := by + unfold hamiltonian + rw [← Finset.sum_sub_distrib] + apply Finset.sum_eq_single a + · intro b _ hba + simp [patternField, Function.update_of_ne hba] + · simp + rw [heq] + calc + _ ≤ |φ (patternField (Function.update g a y) a x)| + |φ (patternField g a x)| := + abs_sub _ _ + _ ≤ ‖φ‖ + ‖φ‖ := add_le_add (φ.norm_coe_le_norm _) (φ.norm_coe_le_norm _) + _ = _ := by ring + +lemma abs_pressure_update_sub_le (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) + (g : Patterns α (N + 1)) (a : Fin (patternCount α (N + 1))) (y : Fin (N + 1) → ℝ) : + |pressure α β φ (N + 1) (Function.update g a y) - pressure α β φ (N + 1) g| ≤ + (2 * |β| * ‖φ‖) / (N + 1 : ℝ) := by + have hh := abs_log_integral_exp_sub_le (sphereLaw (N + 1)) + (integrable_partition α β φ N (Function.update g a y)) (integrable_partition α β φ N g) + (partition_pos α β φ N (Function.update g a y)) (partition_pos α β φ N g) + (c := 2 * |β| * ‖φ‖) (fun x => by + rw [← mul_sub, abs_mul] + calc + _ ≤ |β| * (2 * ‖φ‖) := mul_le_mul_of_nonneg_left + (abs_hamiltonian_update_sub_le α φ (N + 1) g a y x) (abs_nonneg β) + _ = _ := by ring) + unfold pressure + rw [← sub_div, abs_div, abs_of_nonneg (show 0 ≤ ((N + 1 : ℕ) : ℝ) by positivity)] + simpa only [Nat.cast_add, Nat.cast_one] using div_le_div_of_nonneg_right hh + (show 0 ≤ (N + 1 : ℝ) by positivity) + +lemma variance_pressure_le (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) : + variance (pressure α β φ (N + 1)) (patternLaw α (N + 1)) ≤ + (patternCount α (N + 1) : ℝ) * ((2 * |β| * ‖φ‖) / (N + 1 : ℝ)) ^ 2 := by + exact variance_pi_le_of_bounded_differences (Measure.pi fun _ : Fin (N + 1) => gaussianReal 0 1) + (patternCount α (N + 1)) (continuous_pressure α β φ N) + (abs_pressure_le α β φ N) (abs_pressure_update_sub_le α β φ N) + +lemma variance_pressure_le_rate (α β : ℝ) (hα : 0 ≤ α) (φ : ℝ →ᵇ ℝ) (N : ℕ) : + variance (pressure α β φ (N + 1)) (patternLaw α (N + 1)) ≤ + α * (2 * |β| * ‖φ‖) ^ 2 / (N + 1 : ℝ) := by + have hM : (patternCount α (N + 1) : ℝ) ≤ α * (N + 1 : ℝ) := by + simpa [patternCount] using Nat.floor_le + (mul_nonneg hα (show 0 ≤ ((N + 1 : ℕ) : ℝ) by positivity)) + calc + _ ≤ (patternCount α (N + 1) : ℝ) * ((2 * |β| * ‖φ‖) / (N + 1 : ℝ)) ^ 2 := + variance_pressure_le α β φ N + _ ≤ (α * (N + 1 : ℝ)) * ((2 * |β| * ‖φ‖) / (N + 1 : ℝ)) ^ 2 := + mul_le_mul_of_nonneg_right hM (sq_nonneg _) + _ = _ := by + have hn : (N + 1 : ℝ) ≠ 0 := by positivity + field_simp + +lemma pressure_deviation_le (α β : ℝ) (hα : 0 ≤ α) (φ : ℝ →ᵇ ℝ) + (N : ℕ) (ε : ℝ) (hε : 0 < ε) : + patternLaw α (N + 1) + {g | ε < |pressure α β φ (N + 1) g - expectedPressure α β φ (N + 1)|} ≤ + ENNReal.ofReal ((α * (2 * |β| * ‖φ‖) ^ 2 / (N + 1 : ℝ)) / ε ^ 2) := by + have : IsProbabilityMeasure (patternLaw α (N + 1)) := by + unfold patternLaw + infer_instance + have hp : MemLp (pressure α β φ (N + 1)) 2 (patternLaw α (N + 1)) := + MemLp.of_bound (continuous_pressure α β φ N).aestronglyMeasurable _ + (Filter.Eventually.of_forall (abs_pressure_le α β φ N)) + calc + _ ≤ patternLaw α (N + 1) + {g | ε ≤ |pressure α β φ (N + 1) g - expectedPressure α β φ (N + 1)|} := + by + apply measure_mono + intro g hg + change ε < |pressure α β φ (N + 1) g - expectedPressure α β φ (N + 1)| at hg + change ε ≤ |pressure α β φ (N + 1) g - expectedPressure α β φ (N + 1)| + exact le_of_lt hg + _ ≤ ENNReal.ofReal (variance (pressure α β φ (N + 1)) (patternLaw α (N + 1)) / ε ^ 2) := + meas_ge_le_variance_div_sq hp hε + _ ≤ _ := ENNReal.ofReal_le_ofReal (div_le_div_of_nonneg_right + (variance_pressure_le_rate α β hα φ N) (sq_nonneg _)) + +theorem pressure_concentrates (α β : ℝ) (hα : 0 ≤ α) (φ : ℝ →ᵇ ℝ) + (ε : ℝ) (hε : 0 < ε) : + Tendsto (fun N : ℕ => patternLaw α (N + 1) + {g | ε < |pressure α β φ (N + 1) g - expectedPressure α β φ (N + 1)|}) + atTop (𝓝 0) := by + have hr : Tendsto (fun N : ℕ => + (α * (2 * |β| * ‖φ‖) ^ 2 / (N + 1 : ℝ)) / ε ^ 2) atTop (𝓝 0) := by + simpa only [div_eq_mul_inv, one_mul, mul_zero, zero_mul] using + (tendsto_const_nhds.mul (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ))).div_const + (ε ^ 2) + have he := ENNReal.tendsto_ofReal hr + simp only [ENNReal.ofReal_zero] at he + exact tendsto_of_tendsto_of_tendsto_of_le_of_le tendsto_const_nhds he + (fun _ => bot_le) (fun N => pressure_deviation_le α β hα φ N ε hε) + +theorem pressure_probability_of_expected_limit (α β : ℝ) (hα : 0 ≤ α) + (φ : ℝ →ᵇ ℝ) (p : ℝ) + (hp : Tendsto (fun N : ℕ => expectedPressure α β φ (N+1)) atTop (𝓝 p)) + (ε : ℝ) (hε : 0 < ε) : + Tendsto (fun N : ℕ => patternLaw α (N+1) + {g | ε < |pressure α β φ (N+1) g - p|}) atTop (𝓝 0) := by + have he : ∀ᶠ N in atTop, |expectedPressure α β φ (N+1) - p| < ε/2 := by + simpa only [Real.dist_eq] using (Metric.tendsto_nhds.mp hp (ε/2) (by positivity)) + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds + (pressure_concentrates α β hα φ (ε/2) (by positivity)) + · exact Filter.Eventually.of_forall fun _ => bot_le + · filter_upwards [he] with N hN + apply measure_mono + intro g hg + change ε/2 < |pressure α β φ (N+1) g - expectedPressure α β φ (N+1)| + change ε < |pressure α β φ (N+1) g - p| at hg + have hh := abs_sub_le (pressure α β φ (N+1) g) (expectedPressure α β φ (N+1)) p + linarith + +lemma brownianEval_measurable (t : ℝ≥0) : Measurable (brownianEval t) := + (continuous_eval_const t).measurable + +lemma usualBrownianSigma_le_completion (P : Measure BrownianPath) (t : Time) : + usualBrownianSigma P t ≤ + (inferInstance : MeasurableSpace (NullMeasurableSpace BrownianPath P)) := by + unfold usualBrownianSigma + refine (iInf_le _ (⟨2, lt_of_le_of_lt t.property.2 (by norm_num)⟩ : + {s : ℝ≥0 // (t : ℝ) < s})).trans ?_ + apply sup_le + · apply iSup_le + intro r + exact (brownianEval_measurable r.val).comap_le.trans + (fun _ hs => hs.nullMeasurableSet) + · apply MeasurableSpace.generateFrom_le + intro s hs + exact NullMeasurableSet.of_null hs + +lemma progressive_joint_complete (P : Measure BrownianPath) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) : + Measurable (fun p : Time × NullMeasurableSpace BrownianPath P => v p.1 p.2) := by + have h := (hv 1).mono (show MeasurableSpace.prod inferInstance (usualBrownianSigma P 1) ≤ + MeasurableSpace.prod inferInstance + (inferInstance : MeasurableSpace (NullMeasurableSpace BrownianPath P)) from + sup_le_sup le_rfl (MeasurableSpace.comap_mono (usualBrownianSigma_le_completion P 1))) le_rfl + have hf : Measurable (fun p : Time × NullMeasurableSpace BrownianPath P => + (⟨p.1, p.1.property.2⟩ : Set.Iic (1 : Time))) := measurable_fst.subtype_mk + exact h.comp (hf.prodMk measurable_snd) + +lemma progressive_time_measurable (P : Measure BrownianPath) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (ω : BrownianPath) : + Measurable (fun t : Time => v t ω) := + (progressive_joint_complete P hv).comp (measurable_id.prodMk measurable_const) + +lemma drift_sq_le_cost (m : Trial) (v : Time → ℝ) (hv : Measurable v) + (hc : (∫⁻ t, ENNReal.ofReal (m t * v t ^ 2) ∂timeLaw) < ∞) : + (∫ t, m t * v t ∂timeLaw) ^ 2 ≤ + (∫⁻ t, ENNReal.ofReal (m t * v t ^ 2) ∂timeLaw).toReal := by + have hm : Integrable m timeLaw := + (integrable_const (1 : ℝ)).mono' m.measurable.aestronglyMeasurable + (Filter.Eventually.of_forall fun t => by simpa [abs_of_nonneg (m.nonneg t)] using m.le_one t) + have hq : Integrable (fun t => m t * v t ^ 2) timeLaw := + ⟨(m.measurable.mul (hv.pow_const 2)).aestronglyMeasurable, + (hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall fun t => + mul_nonneg (m.nonneg t) (sq_nonneg _))).mpr hc⟩ + have hi : Integrable (fun t => m t * v t) timeLaw := by + apply (hq.add hm).mono' (m.measurable.mul hv).aestronglyMeasurable + apply Filter.Eventually.of_forall + intro t + change |m t * v t| ≤ m t * v t ^ 2 + m t + rw [abs_mul, abs_of_nonneg (m.nonneg t)] + have h := sq_nonneg (|v t| - 1) + have habs : |v t| ≤ v t ^ 2 + 1 := by nlinarith [sq_abs (v t)] + calc + _ ≤ m t * (v t ^ 2 + 1) := mul_le_mul_of_nonneg_left habs (m.nonneg t) + _ = _ := by ring + let D := ∫ t, m t * v t ∂timeLaw + have hnon : 0 ≤ ∫ t, (m t * v t ^ 2 - 2 * D * (m t * v t) + D^2 * m t) ∂timeLaw := by + apply integral_nonneg + intro t + change 0 ≤ m t * v t ^ 2 - 2 * D * (m t * v t) + D^2 * m t + nlinarith [mul_nonneg (m.nonneg t) (sq_nonneg (v t - D))] + have hs : Integrable (fun t => m t * v t ^ 2 - 2 * D * (m t * v t)) timeLaw := + hq.sub (hi.const_mul (2*D)) + rw [integral_add hs (hm.const_mul (D^2)), + integral_sub hq (hi.const_mul (2*D)), integral_const_mul, integral_const_mul] at hnon + have hmone : (∫ t, m t ∂timeLaw) ≤ 1 := by + calc + _ ≤ ∫ _ : Time, (1 : ℝ) ∂timeLaw := integral_mono hm (integrable_const _) m.le_one + _ = _ := by simp + rw [← integral_eq_lintegral_of_nonneg_ae + (Filter.Eventually.of_forall fun t => mul_nonneg (m.nonneg t) (sq_nonneg _)) + hq.aestronglyMeasurable] + change D ^ 2 ≤ _ + nlinarith [mul_le_mul_of_nonneg_left hmone (sq_nonneg D)] + +def controlDrift (m : Trial) (v : Time → BrownianPath → ℝ) (ω : BrownianPath) : ℝ := + ∫ t, m t * v t ω ∂timeLaw + +def pathControlCost (m : Trial) (v : Time → BrownianPath → ℝ) (ω : BrownianPath) : ℝ≥0∞ := + ∫⁻ t, ENNReal.ofReal (m t * v t ω ^ 2) ∂timeLaw + +lemma controlDrift_aemeasurable (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) : + AEMeasurable (controlDrift m v) P := by + have h : Measurable (fun ω : NullMeasurableSpace BrownianPath P => controlDrift m v ω) := + ((m.measurable.comp measurable_fst).mul + (progressive_joint_complete P hv)).stronglyMeasurable.integral_prod_left'.measurable + exact (show NullMeasurable (controlDrift m v) P from h).aemeasurable + +lemma pathControlCost_aemeasurable (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) : + AEMeasurable (pathControlCost m v) P := by + have h : Measurable (fun ω : NullMeasurableSpace BrownianPath P => pathControlCost m v ω) := + ((m.measurable.comp measurable_fst).mul + ((progressive_joint_complete P hv).pow_const 2)).ennreal_ofReal.lintegral_prod_left' + exact (show NullMeasurable (pathControlCost m v) P from h).aemeasurable + +lemma controlDrift_sq_integrable (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) + (hc : controlCost P m v < ∞) : + Integrable (fun ω => controlDrift m v ω ^ 2) P := by + have hm := pathControlCost_aemeasurable P m hv + have hfin : ∀ᵐ ω ∂P, pathControlCost m v ω < ∞ := ae_lt_top' hm hc.ne + apply (integrable_toReal_of_lintegral_ne_top hm hc.ne).mono' + ((controlDrift_aemeasurable P m hv).pow_const 2).aestronglyMeasurable + filter_upwards [hfin] with ω hω + rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] + exact drift_sq_le_cost m (fun t => v t ω) (progressive_time_measurable P hv ω) hω + +lemma integral_controlDrift_sq_le (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) + (hc : controlCost P m v < ∞) : + (∫ ω, controlDrift m v ω ^ 2 ∂P) ≤ (controlCost P m v).toReal := by + have hm := pathControlCost_aemeasurable P m hv + have hfin : ∀ᵐ ω ∂P, pathControlCost m v ω < ∞ := ae_lt_top' hm hc.ne + calc + _ ≤ ∫ ω, (pathControlCost m v ω).toReal ∂P := by + apply integral_mono_ae (controlDrift_sq_integrable P m hv hc) + (integrable_toReal_of_lintegral_ne_top hm hc.ne) + filter_upwards [hfin] with ω hω + exact drift_sq_le_cost m (fun t => v t ω) (progressive_time_measurable P hv ω) hω + _ = _ := integral_toReal hm hfin + +lemma brownianEval_one_sq_integral (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) : (∫ ω, brownianEval 1 ω ^ 2 ∂P) = 1 := by + have hm := (hB.isGaussianProcess.hasGaussianLaw_eval 1).memLp_two + have h := hB.covariance_eval 1 1 + rw [covariance_eq_sub hm hm, hB.integral_eval, zero_mul, sub_zero] at h + simpa only [sq, min_self, NNReal.coe_one, Pi.mul_apply] using h + +lemma controlledTerminal_sq_integral_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) + (hc : controlCost P m v < ∞) : + (∫ ω, (brownianEval 1 ω + controlDrift m v ω)^2 ∂P) ≤ + 2 + 2 * (controlCost P m v).toReal := by + have hb := (hB.isGaussianProcess.hasGaussianLaw_eval 1).memLp_two + have hd := (memLp_two_iff_integrable_sq + (controlDrift_aemeasurable P m hv).aestronglyMeasurable).mpr + (controlDrift_sq_integrable P m hv hc) + calc + _ ≤ ∫ ω, (2 * brownianEval 1 ω ^ 2 + 2 * controlDrift m v ω ^ 2) ∂P := by + apply integral_mono (hb.add hd).integrable_sq + ((hb.integrable_sq.const_mul 2).add (hd.integrable_sq.const_mul 2)) + intro ω + change (brownianEval 1 ω + controlDrift m v ω)^2 ≤ + 2 * brownianEval 1 ω ^ 2 + 2 * controlDrift m v ω ^ 2 + nlinarith [sq_nonneg (brownianEval 1 ω - controlDrift m v ω)] + _ = 2 + 2 * ∫ ω, controlDrift m v ω ^ 2 ∂P := by + rw [integral_add (hb.integrable_sq.const_mul 2) (hd.integrable_sq.const_mul 2), + integral_const_mul, integral_const_mul, brownianEval_one_sq_integral P hB] + ring + _ ≤ _ := by linarith [integral_controlDrift_sq_le P m hv hc] + +lemma controlledTerminal_aemeasurable (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) : + AEMeasurable (fun ω => brownianEval 1 ω + controlDrift m v ω) P := + (brownianEval_measurable 1).aemeasurable.add (controlDrift_aemeasurable P m hv) + +lemma controlReward_integrable (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) {v : Time → BrownianPath → ℝ} + (hv : Progressive P v) : + Integrable (fun ω => f (brownianEval 1 ω + controlDrift m v ω)) P := by + apply (integrable_const ‖f‖).mono' + (f.continuous.measurable.comp_aemeasurable + (controlledTerminal_aemeasurable P m hv)).aestronglyMeasurable + exact Filter.Eventually.of_forall fun ω => f.norm_coe_le_norm _ + +lemma controlPayoff_compact_bound (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (f g : ℝ →ᵇ ℝ) + (K R ε : ℝ) (hK : 0 ≤ K) (hR : 0 < R) (hε : 0 ≤ ε) + (hf : ‖f‖ ≤ K) (hg : ‖g‖ ≤ K) + (hnear : ∀ x : ℝ, |x| ≤ R → |f x - g x| ≤ ε) + (m : Trial) {v : Time → BrownianPath → ℝ} (hv : Progressive P v) + (hc : controlCost P m v < ∞) : + |controlPayoff P f m v - controlPayoff P g m v| ≤ + ε + (2 * K / R^2) * (2 + 2 * (controlCost P m v).toReal) := by + let X := fun ω => brownianEval 1 ω + controlDrift m v ω + have hfI := controlReward_integrable P f m hv + have hgI := controlReward_integrable P g m hv + have hX : Integrable (fun ω => X ω ^ 2) P := by + have hb := (hB.isGaussianProcess.hasGaussianLaw_eval 1).memLp_two + have hd := (memLp_two_iff_integrable_sq + (controlDrift_aemeasurable P m hv).aestronglyMeasurable).mpr + (controlDrift_sq_integrable P m hv hc) + exact (hb.add hd).integrable_sq + have hconst : 0 ≤ 2 * K / R ^ 2 := div_nonneg (by positivity) (sq_nonneg _) + have hbound (x : ℝ) : |f x - g x| ≤ ε + (2*K/R^2)*x^2 := by + by_cases hx : |x| ≤ R + · exact (hnear x hx).trans (le_add_of_nonneg_right (mul_nonneg hconst (sq_nonneg _))) + · have habs : |f x - g x| ≤ 2*K := by + calc + _ ≤ |f x| + |g x| := abs_sub _ _ + _ ≤ K + K := add_le_add ((f.norm_coe_le_norm x).trans hf) + ((g.norm_coe_le_norm x).trans hg) + _ = _ := by ring + have hsq : R^2 ≤ x^2 := by nlinarith [sq_abs x, lt_of_not_ge hx] + have hr : R^2 ≠ 0 := ne_of_gt (sq_pos_of_pos hR) + have heq : (2*K/R^2)*R^2 = 2*K := div_mul_cancel₀ _ hr + have hb := mul_le_mul_of_nonneg_left hsq hconst + rw [heq] at hb + exact habs.trans (hb.trans (le_add_of_nonneg_left hε)) + have heq : controlPayoff P f m v - controlPayoff P g m v = + ∫ ω, (f (X ω) - g (X ω)) ∂P := by + rw [integral_sub hfI hgI] + unfold controlPayoff controlDrift + ring + rw [heq] + calc + _ ≤ ∫ ω, |f (X ω) - g (X ω)| ∂P := abs_integral_le_integral_abs + _ ≤ ∫ ω, (ε + (2*K/R^2)*X ω^2) ∂P := + integral_mono (hfI.sub hgI).abs ((integrable_const ε).add (hX.const_mul _)) + (fun ω => hbound (X ω)) + _ = ε + (2*K/R^2) * ∫ ω, X ω^2 ∂P := by + rw [integral_add (integrable_const ε) (hX.const_mul _), integral_const_mul] + simp + _ ≤ _ := add_le_add le_rfl (mul_le_mul_of_nonneg_left + (controlledTerminal_sq_integral_le P hB m hv hc) hconst) + +lemma controlValue_le_of_cost_cutoff (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) (K b : ℝ) (hf : ‖f‖ ≤ K) + (hb : -K ≤ b) + (hsmall : ∀ v : Time → BrownianPath → ℝ, Progressive P v → + controlCost P m v < ∞ → (controlCost P m v).toReal ≤ 4*K+2 → + controlPayoff P f m v ≤ b) : controlValue P f m ≤ b := by + apply csSup_le (controlPayoffs_nonempty P f m) + rintro a ⟨v, hv, hc, rfl⟩ + by_cases hcost : (controlCost P m v).toReal ≤ 4*K+2 + · exact hsmall v hv hc hcost + · have hr := (abs_le.mp (abs_integral_reward_le P f + (fun ω => brownianEval 1 ω + ∫ t, m t * v t ω ∂timeLaw))).2 + unfold controlPayoff + linarith [lt_of_not_ge hcost] + +lemma controlValue_compact_bound (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (f g : ℝ →ᵇ ℝ) + (K R ε : ℝ) (hK : 0 ≤ K) (hR : 0 < R) (hε : 0 ≤ ε) + (hf : ‖f‖ ≤ K) (hg : ‖g‖ ≤ K) + (hnear : ∀ x : ℝ, |x| ≤ R → |f x - g x| ≤ ε) + (m : Trial) : + |controlValue P f m - controlValue P g m| ≤ + ε + (2 * K / R^2) * (2 + 2 * (4*K+2)) := by + let δ := ε + (2*K/R^2)*(2+2*(4*K+2)) + have hδ : 0 ≤ δ := by dsimp [δ]; positivity + have hfg : controlValue P f m ≤ controlValue P g m + δ := by + apply controlValue_le_of_cost_cutoff P f m K _ hf + · linarith [neg_norm_le_controlValue P g m] + · intro v hv hc hcost + have hd := (abs_le.mp (controlPayoff_compact_bound P hB f g K R ε hK hR hε + hf hg hnear m hv hc)).2 + have hp : controlPayoff P g m v ≤ controlValue P g m := + le_csSup (controlPayoffs_bddAbove P g m) ⟨v, hv, hc, rfl⟩ + have hh : ε + (2*K/R^2)*(2+2*(controlCost P m v).toReal) ≤ δ := by + dsimp [δ] + apply add_le_add le_rfl + apply mul_le_mul_of_nonneg_left _ (by positivity) + linarith + linarith + have hgf : controlValue P g m ≤ controlValue P f m + δ := by + apply controlValue_le_of_cost_cutoff P g m K _ hg + · linarith [neg_norm_le_controlValue P f m] + · intro v hv hc hcost + have hd := (abs_le.mp (controlPayoff_compact_bound P hB f g K R ε hK hR hε + hf hg hnear m hv hc)).1 + have hp : controlPayoff P f m v ≤ controlValue P f m := + le_csSup (controlPayoffs_bddAbove P f m) ⟨v, hv, hc, rfl⟩ + have hh : ε + (2*K/R^2)*(2+2*(controlCost P m v).toReal) ≤ δ := by + dsimp [δ] + apply add_le_add le_rfl + apply mul_le_mul_of_nonneg_left _ (by positivity) + linarith + linarith + exact abs_le.mpr ⟨by linarith, by linarith⟩ + +lemma controlValue_uniform_of_compact (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (f : ℝ →ᵇ ℝ) (fseq : ℕ → ℝ →ᵇ ℝ) + (K : ℝ) (hK : 0 ≤ K) (hf : ‖f‖ ≤ K) (hseq : ∀ n, ‖fseq n‖ ≤ K) + (hcomp : ∀ R : ℝ, 0 < R → ∀ ε : ℝ, 0 < ε → + ∃ N : ℕ, ∀ n ≥ N, ∀ x : ℝ, |x| ≤ R → |fseq n x - f x| ≤ ε) : + ∀ ε : ℝ, 0 < ε → ∃ N : ℕ, ∀ n ≥ N, ∀ m : Trial, + |controlValue P (fseq n) m - controlValue P f m| < ε := by + intro ε hε + let C := 2*K*(2+2*(4*K+2)) + have hC : 0 ≤ C := by dsimp [C]; positivity + let Q := C / (ε/2) + have hQ : 0 ≤ Q := div_nonneg hC (by positivity) + let R := Q+1 + have hR : 0 < R := by dsimp [R]; positivity + have hQR : Q < R^2 := by dsimp [R]; nlinarith [sq_nonneg Q] + have hCQ : C = (ε/2)*Q := by dsimp [Q]; field_simp + have htail : C/R^2 < ε/2 := by + apply (div_lt_iff₀ (sq_pos_of_pos hR)).mpr + rw [hCQ] + exact mul_lt_mul_of_pos_left hQR (by positivity) + obtain ⟨N,hN⟩ := hcomp R hR (ε/2) (by positivity) + refine ⟨N, fun n hn m => ?_⟩ + have hb := controlValue_compact_bound P hB (fseq n) f K R (ε/2) hK hR + (by positivity) (hseq n) hf (hN n hn) m + have heq : (2*K/R^2)*(2+2*(4*K+2)) = C/R^2 := by dsimp [C]; ring + rw [heq] at hb + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/ControlledPrefix.lean b/lean/OAI/Probability/Perceptron/Control/ControlledPrefix.lean new file mode 100644 index 0000000000000000000000000000000000000000..3cdcae07e9ae92ba054b08dd0a71aea868f1d83f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/ControlledPrefix.lean @@ -0,0 +1,419 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.HeatLogBCF + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma heatLog_control_step_error (d L C₀ C₁ C₂ C₃ : ℝ≥0) : + ∃ C : ℝ≥0, ∀ {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P] + (g : Jet3), ‖g.f‖ ≤ C₀ → ‖g.d1‖ ≤ C₁ → ‖g.d2‖ ≤ C₂ → ‖g.d3‖ ≤ C₃ → + ∀ (s : ℝ≥0), s ≤ 1 → ∀ (X Z A : Ω → ℝ), AEMeasurable X P → + HasLaw Z (gaussianReal 0 s) P → IndepFun X Z P → AEMeasurable A P → + (∀ ω, |A ω| ≤ (L : ℝ)*s) → + |(∫ ω, g.f (X ω+Z ω+A ω) ∂P) - (∫ ω, heatLog s d g.f (X ω) ∂P) - + (∫ ω, g.d1 (X ω)*A ω ∂P) + (d : ℝ)*(s : ℝ)/2 * (∫ ω, (g.d1 (X ω))^2 ∂P)| ≤ + (C : ℝ)*(s : ℝ)*Real.sqrt s := by + obtain ⟨C,hC⟩ := heatLog_generator_uniform d C₀ C₁ C₂ C₃ + let M₁ := ∫ z : ℝ, |z| ∂gaussianReal 0 1 + let M₃ := ∫ z : ℝ, |z|^3 ∂gaussianReal 0 1 + have hM₁ : 0 ≤ M₁ := integral_nonneg (fun z => abs_nonneg z) + have hM₃ : 0 ≤ M₃ := integral_nonneg (fun z => by positivity) + let K := (C₂ : ℝ)*((L : ℝ)*M₁+(L : ℝ)^2/2) + (C₃ : ℝ)/6*M₃ + have hK : 0 ≤ K := by positivity + refine ⟨⟨K+C, by positivity⟩, ?_⟩ + intro Ω _ P _ g h₀ h₁ h₂ h₃ s hs X Z A hX hZ hI hA hAK + have hG := gaussian_drift_taylor_mean_bound g.f g.contDiff C₁ C₃ C₂ (L*s) + (fun y => by rw [g.deriv_eq]; exact (g.d1.norm_coe_le_norm y).trans h₁) + (fun y => by rw [g.deriv2_eq]; exact (g.d2.norm_coe_le_norm y).trans h₂) + (fun y => by rw [g.deriv3_eq]; exact (g.d3.norm_coe_le_norm y).trans h₃) + hX hZ hI hA (by simpa only [NNReal.coe_mul] using hAK) + rw [g.deriv_eq, g.deriv2_eq] at hG + have hs0 := s.coe_nonneg + have hr0 := Real.sqrt_nonneg (s : ℝ) + have hr1 : Real.sqrt (s : ℝ) ≤ 1 := Real.sqrt_le_one.mpr hs + have hsr : (s : ℝ) ≤ Real.sqrt (s : ℝ) := by nlinarith [Real.sq_sqrt hs0] + have hrcube : (Real.sqrt (s : ℝ))^3 = (s : ℝ)*Real.sqrt s := by nlinarith [Real.sq_sqrt hs0] + have hG' : |(∫ ω, g.f (X ω+Z ω+A ω) ∂P) - (∫ ω, g.f (X ω) ∂P) - + (∫ ω, g.d1 (X ω)*A ω ∂P) - (s : ℝ)/2*(∫ ω, g.d2 (X ω) ∂P)| ≤ + K*(s : ℝ)*Real.sqrt s := by + refine hG.trans ?_ + simp only [NNReal.coe_mul, hrcube] + have ht := mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_left hsr hs0) + (show 0 ≤ (C₂ : ℝ)*(L : ℝ)^2/2 by positivity) + dsimp [K,M₁,M₃] at * + nlinarith only [ht] + have hiF := boundedContinuousFunction_integrable_comp g.f hX + have hiH := boundedContinuousFunction_integrable_comp (heatLogBCF s d g.f) hX + change Integrable (fun ω => heatLog s d g.f (X ω)) P at hiH + have hi₂ := boundedContinuousFunction_integrable_comp g.d2 hX + have hi₁₂ := boundedContinuousFunction_integrable_comp (g.d1^2) hX + change Integrable (fun ω => (g.d1 (X ω))^2) P at hi₁₂ + let R := fun ω => heatLog s d g.f (X ω) - g.f (X ω) - + (s : ℝ)/2*(g.d2 (X ω)+(d : ℝ)*(g.d1 (X ω))^2) + have hiR : Integrable R P := (hiH.sub hiF).sub ((hi₂.add (hi₁₂.const_mul d)).const_mul ((s : ℝ)/2)) + have hR : |∫ ω, R ω ∂P| ≤ (C : ℝ)*(s : ℝ)*Real.sqrt s := by + simpa only [Real.norm_eq_abs, probReal_univ, mul_one] using + norm_integral_le_of_norm_le_const (f := R) (μ := P) (Filter.Eventually.of_forall fun ω => + show ‖R ω‖ ≤ (C : ℝ)*(s : ℝ)*Real.sqrt s by + simpa only [Real.norm_eq_abs, R] using hC g h₀ h₁ h₂ h₃ s hs (X ω)) + have hRe : (∫ ω, R ω ∂P) = (∫ ω, heatLog s d g.f (X ω) ∂P) - (∫ ω, g.f (X ω) ∂P) - + (s : ℝ)/2*((∫ ω, g.d2 (X ω) ∂P)+(d : ℝ)*(∫ ω, (g.d1 (X ω))^2 ∂P)) := by + have he := integral_sub (hiH.sub hiF) ((hi₂.add (hi₁₂.const_mul d)).const_mul ((s : ℝ)/2)) + simp only [Pi.sub_apply, Pi.add_apply] at he + dsimp only [R] + rw [he, integral_sub hiH hiF, integral_const_mul, integral_add hi₂ (hi₁₂.const_mul d), integral_const_mul] + rw [hRe] at hR + have hh := abs_sub + ((∫ ω, g.f (X ω+Z ω+A ω) ∂P) - (∫ ω, g.f (X ω) ∂P) - + (∫ ω, g.d1 (X ω)*A ω ∂P) - (s : ℝ)/2*(∫ ω, g.d2 (X ω) ∂P)) + ((∫ ω, heatLog s d g.f (X ω) ∂P) - (∫ ω, g.f (X ω) ∂P) - + (s : ℝ)/2*((∫ ω, g.d2 (X ω) ∂P)+(d : ℝ)*(∫ ω, (g.d1 (X ω))^2 ∂P))) + have hh' := hh.trans (add_le_add hG' hR) + convert! hh' using 1 + · congr 1; ring + · change (K+(C : ℝ))*(s : ℝ)*Real.sqrt s = K*(s : ℝ)*Real.sqrt s + (C : ℝ)*(s : ℝ)*Real.sqrt s + ring + +lemma usualBrownianSigma_mono (P : Measure BrownianPath) {s t : Time} (hst : s ≤ t) : + usualBrownianSigma P s ≤ usualBrownianSigma P t := by + apply le_iInf + intro r + exact iInf_le_of_le (⟨r.val, lt_of_le_of_lt hst r.property⟩ : {r : ℝ≥0 // (s : ℝ) < r}) le_rfl + +lemma brownianEval_usual_measurable (P : Measure BrownianPath) (t : Time) : + @Measurable _ _ (usualBrownianSigma P t) (borel ℝ) + (brownianEval ⟨t.val,t.property.1⟩) := by + rw [measurable_iff_comap_le] + apply le_iInf + intro r + apply le_sup_of_le_left + exact le_iSup_of_le (⟨⟨t.val,t.property.1⟩, r.property.le⟩ : {s : ℝ≥0 // s ≤ r.val}) le_rfl + +lemma progressive_prefix_integral_measurable (P : Measure BrownianPath) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) + (a : Time → ℝ) (ha : Measurable a) (t : Time) : + @Measurable _ _ (usualBrownianSigma P t) (borel ℝ) + (fun ω => ∫ r in Set.Iic t, a r * v r ω ∂timeLaw) := by + let : MeasurableSpace BrownianPath := usualBrownianSigma P t + have hm : Measurable (fun p : Set.Iic t × BrownianPath => a p.1.val * v p.1.val p.2) := + (ha.comp (measurable_subtype_coe.comp measurable_fst)).mul (hv t) + have hi := hm.stronglyMeasurable.integral_prod_left (f := fun r ω => a r.val * v r.val ω) (μ := Measure.comap Subtype.val timeLaw) + have he : (fun ω => ∫ r : Set.Iic t, a r.val * v r.val ω ∂Measure.comap Subtype.val timeLaw) = + (fun ω => ∫ r in Set.Iic t, a r * v r ω ∂timeLaw) := by + funext ω + exact integral_subtype_comap (μ := timeLaw) (s := Set.Iic t) measurableSet_Iic (fun r => a r * v r ω) + rw [he] at hi + exact hi.measurable + +lemma progressive_interval_integral_aemeasurable (P : Measure BrownianPath) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) + (a : Time → ℝ) (ha : Measurable a) (s t : Time) : + AEMeasurable (fun ω => ∫ r in Set.Ioc s t, a r * v r ω ∂timeLaw) P := by + have hm := (ha.comp measurable_fst).mul (progressive_joint_complete P hv) + have hi := hm.stronglyMeasurable.integral_prod_left (β := NullMeasurableSpace BrownianPath P) + (f := fun r ω => a r * v r ω) (μ := timeLaw.restrict (Set.Ioc s t)) + exact (show NullMeasurable (fun ω => ∫ r in Set.Ioc s t, a r * v r ω ∂timeLaw) P from hi.measurable).aemeasurable + +def controlledPrefix (m : Trial) (v : Time → BrownianPath → ℝ) (t : Time) (ω : BrownianPath) : ℝ := + brownianEval ⟨t.val,t.property.1⟩ ω + ∫ r in Set.Iic t, m r * v r ω ∂timeLaw + +lemma controlledPrefix_usual_measurable (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (t : Time) : + @Measurable _ _ (usualBrownianSigma P t) (borel ℝ) (controlledPrefix m v t) := + (brownianEval_usual_measurable P t).add (progressive_prefix_integral_measurable P hv m m.measurable t) + +def timeSpan (s t : Time) : ℝ≥0 := Real.toNNReal ((t : ℝ)-(s : ℝ)) + +lemma timeSpan_coe {s t : Time} (hst : s ≤ t) : + (timeSpan s t : ℝ) = (t : ℝ)-(s : ℝ) := Real.coe_toNNReal _ (sub_nonneg.mpr hst) + +lemma timeSpan_le_one (s t : Time) : timeSpan s t ≤ 1 := by + apply Real.toNNReal_le_one.mpr + linarith [t.property.2,s.property.1] + +lemma timeLaw_real_Ioc {s t : Time} (hst : s ≤ t) : + timeLaw.real (Set.Ioc s t) = (t : ℝ)-(s : ℝ) := by + simp only [timeLaw_eq_volume, Measure.real, unitInterval.volume_Ioc, + ENNReal.toReal_ofReal (sub_nonneg.mpr hst)] + +lemma timeLaw_integral_const_Ioc {s t : Time} (hst : s ≤ t) (a : ℝ) : + (∫ _r in Set.Ioc s t, a ∂timeLaw) = ((t : ℝ)-(s : ℝ))*a := by + rw [integral_const, Measure.real, Measure.restrict_apply_univ, ← Measure.real, + timeLaw_real_Ioc hst, smul_eq_mul] + +lemma bounded_control_integrable (P : Measure BrownianPath) (m : Trial) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hL : ∀ t ω, |v t ω| ≤ L) (ω : BrownianPath) : + Integrable (fun r => m r * v r ω^2) timeLaw ∧ Integrable (fun r => m r * v r ω) timeLaw := + weightedTime_integrable m (progressive_time_measurable P hv ω) + ((pathControlCost_le_bound m L hL ω).trans_lt (by finiteness)) + +lemma controlledPrefix_increment (P : Measure BrownianPath) (m : Trial) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hL : ∀ t ω, |v t ω| ≤ L) + {s t : Time} (hst : s ≤ t) (ω : BrownianPath) : + controlledPrefix m v t ω = controlledPrefix m v s ω + + (brownianEval ⟨t.val,t.property.1⟩ ω - brownianEval ⟨s.val,s.property.1⟩ ω) + + ∫ r in Set.Ioc s t, m r * v r ω ∂timeLaw := by + have hi := (bounded_control_integrable P m L hv hL ω).2 + have he := setIntegral_union (s := Set.Iic s) (t := Set.Ioc s t) + (Set.Iic_disjoint_Ioc (a := s) (c := t) le_rfl) measurableSet_Ioc + hi.integrableOn hi.integrableOn + rw [Set.Iic_union_Ioc_eq_Iic hst] at he + unfold controlledPrefix + rw [he] + ring + +lemma bounded_interval_drift (P : Measure BrownianPath) (m : Trial) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hL : ∀ t ω, |v t ω| ≤ L) + {s t : Time} (hst : s ≤ t) (ω : BrownianPath) : + |∫ r in Set.Ioc s t, m r * v r ω ∂timeLaw| ≤ (L : ℝ) * timeSpan s t := by + rw [timeSpan_coe hst, mul_comm (L : ℝ)] + calc + _ ≤ ∫ r in Set.Ioc s t, |m r*v r ω| ∂timeLaw := abs_integral_le_integral_abs + _ ≤ ∫ _r in Set.Ioc s t, (L : ℝ) ∂timeLaw := by + apply integral_mono (bounded_control_integrable P m L hv hL ω).2.integrableOn.abs (integrable_const _) + intro r + change |m r * v r ω| ≤ (L : ℝ) + rw [abs_mul, abs_of_nonneg (m.nonneg r)] + exact (mul_le_mul_of_nonneg_left (hL r ω) (m.nonneg r)).trans + (by nlinarith [m.le_one r]) + _ = _ := timeLaw_integral_const_Ioc hst L + +def intervalControlCost (m : Trial) (v : Time → BrownianPath → ℝ) (s t : Time) (ω : BrownianPath) : ℝ := + ∫ r in Set.Ioc s t, m r * (v r ω)^2 ∂timeLaw + +lemma intervalControlCost_nonneg (m : Trial) (v : Time → BrownianPath → ℝ) (s t : Time) (ω : BrownianPath) : + 0 ≤ intervalControlCost m v s t ω := integral_nonneg (fun r => mul_nonneg (m.nonneg r) (sq_nonneg _)) + +lemma intervalControlCost_aemeasurable (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (s t : Time) : + AEMeasurable (intervalControlCost m v s t) P := + progressive_interval_integral_aemeasurable P (fun r => (hv r).pow_const 2) m m.measurable s t + +lemma intervalControlCost_le_bound (P : Measure BrownianPath) (m : Trial) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hL : ∀ t ω, |v t ω| ≤ L) + {s t : Time} (hst : s ≤ t) (ω : BrownianPath) : + intervalControlCost m v s t ω ≤ (L : ℝ)^2 * timeSpan s t := by + rw [timeSpan_coe hst, mul_comm ((L : ℝ)^2)] + calc + _ ≤ ∫ _r in Set.Ioc s t, (L : ℝ)^2 ∂timeLaw := by + apply integral_mono (bounded_control_integrable P m L hv hL ω).1.integrableOn (integrable_const _) + intro r + have hh : (v r ω)^2 ≤ (L : ℝ)^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) L.coe_nonneg).mpr (hL r ω) + exact (mul_le_mul_of_nonneg_left hh (m.nonneg r)).trans (by nlinarith [m.le_one r]) + _ = _ := timeLaw_integral_const_Ioc hst _ + +lemma intervalControlCost_integrable (P : Measure BrownianPath) [IsProbabilityMeasure P] + (m : Trial) (L : ℝ≥0) {v : Time → BrownianPath → ℝ} (hv : Progressive P v) + (hL : ∀ t ω, |v t ω| ≤ L) {s t : Time} (hst : s ≤ t) : + Integrable (intervalControlCost m v s t) P := + bounded_real_integrable (intervalControlCost_aemeasurable P m hv s t) ((L : ℝ)^2*timeSpan s t) + (Filter.Eventually.of_forall fun ω => by + rw [abs_of_nonneg (intervalControlCost_nonneg m v s t ω)] + exact intervalControlCost_le_bound P m L hv hL hst ω) + +lemma interval_square_completion (P : Measure BrownianPath) (m : Trial) (L d : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hL : ∀ t ω, |v t ω| ≤ L) + {s t : Time} (hst : s ≤ t) (hm : ∀ r ∈ Set.Ioc s t, m r = (d : ℝ)) + (a : ℝ) (ω : BrownianPath) : + 2*a*(∫ r in Set.Ioc s t, m r * v r ω ∂timeLaw) - + (d : ℝ)*(timeSpan s t : ℝ)*a^2 ≤ intervalControlCost m v s t ω := by + have hi := bounded_control_integrable P m L hv hL ω + have him : Integrable (fun r => m r) timeLaw := by + apply (integrable_const (1 : ℝ)).mono' m.measurable.aestronglyMeasurable + exact Filter.Eventually.of_forall fun r => by + rw [Real.norm_eq_abs, abs_of_nonneg (m.nonneg r)]; exact m.le_one r + have hmono := setIntegral_mono_on (s := Set.Ioc s t) ((hi.2.const_mul (2*a)).sub (him.const_mul (a^2))).integrableOn + hi.1.integrableOn measurableSet_Ioc (fun r _ => by + change 2*a*(m r*v r ω) - a^2*m r ≤ m r*(v r ω)^2 + nlinarith [mul_nonneg (m.nonneg r) (sq_nonneg (v r ω-a))]) + have he : (∫ r in Set.Ioc s t, m r ∂timeLaw) = (d : ℝ)*timeSpan s t := by + rw [setIntegral_congr_fun measurableSet_Ioc hm, timeLaw_integral_const_Ioc hst, timeSpan_coe hst, mul_comm] + simp only [Pi.sub_apply] at hmono + rw [integral_sub (hi.2.const_mul (2*a)).integrableOn (him.const_mul (a^2)).integrableOn, + integral_const_mul, integral_const_mul, he] at hmono + convert! hmono using 1 + ring + +lemma brownian_increment_timeSpan (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) {s t : Time} (hst : s ≤ t) : + HasLaw (fun ω => brownianEval ⟨t.val,t.property.1⟩ ω - brownianEval ⟨s.val,s.property.1⟩ ω) + (gaussianReal 0 (timeSpan s t)) P := by + have he : timeSpan s t = nndist (t : ℝ) (s : ℝ) := by + apply NNReal.coe_injective + rw [timeSpan_coe hst, coe_nndist, Real.dist_eq, abs_of_nonneg (sub_nonneg.mpr (show (s : ℝ) ≤ (t : ℝ) from hst))] + rw [he] + exact (hB.toIsPreBrownianReal.hasLaw_sub ⟨t.val,t.property.1⟩ ⟨s.val,s.property.1⟩).congr + (Filter.Eventually.of_forall fun ω => rfl) + +lemma brownian_control_cell_upper (d L C₀ C₁ C₂ C₃ : ℝ≥0) : + ∃ C : ℝ≥0, ∀ (P : Measure BrownianPath) [IsProbabilityMeasure P], + IsBrownianReal brownianEval P → ∀ (m : Trial) (v : Time → BrownianPath → ℝ), + Progressive P v → (∀ r ω, |v r ω| ≤ L) → ∀ (s t : Time), s < t → + (∀ r ∈ Set.Ioc s t, m r = (d : ℝ)) → ∀ (g : Jet3), + ‖g.f‖ ≤ C₀ → ‖g.d1‖ ≤ C₁ → ‖g.d2‖ ≤ C₂ → ‖g.d3‖ ≤ C₃ → + (∫ ω, g.f (controlledPrefix m v t ω) ∂P) - + (∫ ω, heatLog (timeSpan s t) d g.f (controlledPrefix m v s ω) ∂P) ≤ + (∫ ω, intervalControlCost m v s t ω ∂P)/2 + + (C : ℝ)*(timeSpan s t : ℝ)*Real.sqrt (timeSpan s t) := by + obtain ⟨C,hC⟩ := heatLog_control_step_error d L C₀ C₁ C₂ C₃ + refine ⟨C, ?_⟩ + intro P _ hB m v hv hL s t hst hm g h₀ h₁ h₂ h₃ + let X := controlledPrefix m v s + let Z := fun ω => brownianEval ⟨t.val,t.property.1⟩ ω - brownianEval ⟨s.val,s.property.1⟩ ω + let A := fun ω => ∫ r in Set.Ioc s t, m r*v r ω ∂timeLaw + have hX := controlledPrefix_usual_measurable P m hv s + have hXm : AEMeasurable X P := usual_measurable_aemeasurable P s hX + have hAm : AEMeasurable A P := progressive_interval_integral_aemeasurable P hv m m.measurable s t + have hAb : ∀ ω, |A ω| ≤ (L : ℝ)*timeSpan s t := bounded_interval_drift P m L hv hL hst.le + have he := hC P g h₀ h₁ h₂ h₃ (timeSpan s t) (timeSpan_le_one s t) X Z A hXm + (brownian_increment_timeSpan P hB hst.le) + (brownian_increment_indep_adapted P hB s ⟨t.val,t.property.1⟩ hst hX) hAm hAb + have hXT : ∀ ω, X ω+Z ω+A ω = controlledPrefix m v t ω := by + intro ω + exact (controlledPrefix_increment P m L hv hL hst.le ω).symm + simp only [hXT] at he + have hi₁ := boundedContinuousFunction_integrable_comp g.d1 hXm + have hi₂ := boundedContinuousFunction_integrable_comp (g.d1^2) hXm + change Integrable (fun ω => (g.d1 (X ω))^2) P at hi₂ + have hiA := bounded_real_integrable hAm ((L : ℝ)*timeSpan s t) (Filter.Eventually.of_forall hAb) + have hiJ : Integrable (fun ω => g.d1 (X ω)*A ω) P := + hiA.bdd_mul ((g.d1.continuous.measurable.comp_aemeasurable hXm).aestronglyMeasurable) + (Filter.Eventually.of_forall fun ω => g.d1.norm_coe_le_norm (X ω)) + have hq := integral_mono ((hiJ.const_mul 2).sub (hi₂.const_mul ((d : ℝ)*(timeSpan s t : ℝ)))) + (intervalControlCost_integrable P m L hv hL hst.le) + (fun ω => by + change 2*(g.d1 (X ω)*A ω) - (d : ℝ)*(timeSpan s t : ℝ)*(g.d1 (X ω))^2 ≤ _ + nlinarith only [interval_square_completion P m L d hv hL hst.le hm (g.d1 (X ω)) ω]) + simp only [Pi.sub_apply] at hq + rw [integral_sub (hiJ.const_mul 2) (hi₂.const_mul ((d : ℝ)*(timeSpan s t : ℝ))), + integral_const_mul, integral_const_mul] at hq + exact le_trans (by linarith only [(abs_le.mp he).2,hq]) le_rfl + +lemma antitoneOn_of_superlinear_increment (F : Time → ℝ) (C : ℝ) + {a b : Time} (hab : a ≤ b) + (h : ∀ s ∈ Set.Icc a b, ∀ t ∈ Set.Icc a b, s < t → + F t - F s ≤ C*((t : ℝ)-(s : ℝ))*Real.sqrt ((t : ℝ)-(s : ℝ))) : F b ≤ F a := by + have hbnd : ∀ n : ℕ, ∀ s ∈ Set.Icc a b, ∀ t ∈ Set.Icc a b, s < t → + F t - F s ≤ C*((t : ℝ)-(s : ℝ))*Real.sqrt (((t : ℝ)-(s : ℝ))*(1/2 : ℝ)^n) := by + intro n + induction n with + | zero => simpa using h + | succ n ih => + intro s hs t ht hst + have hstreal : (s : ℝ) < (t : ℝ) := hst + let u : Time := ⟨((s : ℝ)+(t : ℝ))/2, by + constructor <;> linarith [s.property.1,s.property.2,t.property.1,t.property.2]⟩ + have hsu : s < u := by change (s : ℝ) < ((s : ℝ)+(t : ℝ))/2; linarith only [hstreal] + have hut : u < t := by change ((s : ℝ)+(t : ℝ))/2 < (t : ℝ); linarith only [hstreal] + have hu : u ∈ Set.Icc a b := ⟨hs.1.trans hsu.le,hut.le.trans ht.2⟩ + have h₁ := ih s hs u hu hsu + have h₂ := ih u hu t ht hut + have e₁ : (u : ℝ)-(s : ℝ) = ((t : ℝ)-(s : ℝ))/2 := by dsimp [u]; ring + have e₂ : (t : ℝ)-(u : ℝ) = ((t : ℝ)-(s : ℝ))/2 := by dsimp [u]; ring + rw [e₁] at h₁ + rw [e₂] at h₂ + have e₃ : ((t : ℝ)-(s : ℝ))*(1/2 : ℝ)^(n+1) = (((t : ℝ)-(s : ℝ))/2)*(1/2 : ℝ)^n := by rw [pow_succ]; ring + rw [e₃] + linarith only [h₁,h₂] + rcases hab.eq_or_lt with heq | hlt + · simp [heq] + have hlim : Tendsto (fun n : ℕ => C*((b : ℝ)-(a : ℝ))*Real.sqrt (((b : ℝ)-(a : ℝ))*(1/2 : ℝ)^n)) atTop (𝓝 0) := by + have hp := tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : (0 : ℝ) ≤ 1/2) (by norm_num : (1/2 : ℝ) < 1) + simpa using (hp.const_mul ((b : ℝ)-(a : ℝ))).sqrt.const_mul (C*((b : ℝ)-(a : ℝ))) + have he := ge_of_tendsto hlim (Filter.Eventually.of_forall fun n => hbnd n a ⟨le_rfl,hab⟩ b ⟨hab,le_rfl⟩ hlt) + linarith only [he] + +lemma timeSpan_add {a b c : Time} (hab : a ≤ b) (hbc : b ≤ c) : + timeSpan a b + timeSpan b c = timeSpan a c := by + apply NNReal.coe_injective + simp only [NNReal.coe_add,timeSpan_coe hab,timeSpan_coe hbc,timeSpan_coe (hab.trans hbc)] + ring + +lemma intervalControlCost_add (P : Measure BrownianPath) (m : Trial) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hL : ∀ r ω, |v r ω| ≤ L) + {a b c : Time} (hab : a ≤ b) (hbc : b ≤ c) (ω : BrownianPath) : + intervalControlCost m v a c ω = intervalControlCost m v a b ω + intervalControlCost m v b c ω := by + have hi := (bounded_control_integrable P m L hv hL ω).1 + have he := setIntegral_union (s := Set.Ioc a b) (t := Set.Ioc b c) + (Set.Ioc_disjoint_Ioc_of_le le_rfl) measurableSet_Ioc hi.integrableOn hi.integrableOn + rwa [Set.Ioc_union_Ioc_eq_Ioc hab hbc] at he + +lemma expected_intervalControlCost_add (P : Measure BrownianPath) [IsProbabilityMeasure P] + (m : Trial) (L : ℝ≥0) {v : Time → BrownianPath → ℝ} (hv : Progressive P v) + (hL : ∀ r ω, |v r ω| ≤ L) {a b c : Time} (hab : a ≤ b) (hbc : b ≤ c) : + (∫ ω, intervalControlCost m v a c ω ∂P) = + (∫ ω, intervalControlCost m v a b ω ∂P) + (∫ ω, intervalControlCost m v b c ω ∂P) := by + simp only [intervalControlCost_add P m L hv hL hab hbc] + exact integral_add (intervalControlCost_integrable P m L hv hL hab) + (intervalControlCost_integrable P m L hv hL hbc) + +lemma brownian_control_interval_upper (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (m : Trial) (L d : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hL : ∀ r ω, |v r ω| ≤ L) + {a b : Time} (hab : a ≤ b) (hm : ∀ r ∈ Set.Ioc a b, m r = (d : ℝ)) (g : Jet3) : + (∫ ω, g.f (controlledPrefix m v b ω) ∂P) - + (∫ ω, heatLog (timeSpan a b) d g.f (controlledPrefix m v a ω) ∂P) ≤ + (∫ ω, intervalControlCost m v a b ω ∂P)/2 := by + obtain ⟨C₀,C₁,C₂,C₃,hG⟩ := g.heatLog_uniform_bounds d + obtain ⟨C,hC⟩ := brownian_control_cell_upper d L C₀ C₁ C₂ C₃ + let F : Time → ℝ := fun t => + (∫ ω, heatLog (timeSpan t b) d g.f (controlledPrefix m v t ω) ∂P) - + (∫ ω, intervalControlCost m v a t ω ∂P)/2 + have hF := antitoneOn_of_superlinear_increment F (C : ℝ) hab (by + intro s hs t ht hst + have hmst : ∀ r ∈ Set.Ioc s t, m r = (d : ℝ) := fun r hr => hm r ⟨hs.1.trans_lt hr.1,hr.2.trans ht.2⟩ + obtain ⟨h₀,h₁,h₂,h₃⟩ := hG (timeSpan t b) + have hh := hC P hB m v hv hL s t hst hmst (g.heatLog (timeSpan t b) d) h₀ h₁ h₂ h₃ + rw [g.heatLog_f] at hh + simp only [heatLogBCF_coe, heatLog_semigroup, timeSpan_add hst.le ht.2] at hh + have hcost := expected_intervalControlCost_add P m L hv hL hs.1 hst.le + rw [timeSpan_coe hst.le] at hh + dsimp [F] + linarith only [hh,hcost]) + have he₁ : timeSpan b b = 0 := by simp [timeSpan] + have he₂ : ∀ ω, intervalControlCost m v a a ω = 0 := by intro ω; simp [intervalControlCost] + dsimp [F] at hF + simp only [he₁,heatLog_zero,he₂,integral_zero,zero_div,sub_zero] at hF + linarith only [hF] + +def patchControl (v : Time → BrownianPath → ℝ) (s t : Time) (a : BrownianPath → ℝ) : + Time → BrownianPath → ℝ := fun r ω => if r ∈ Set.Ioc s t then a ω else v r ω + +lemma progressive_patchControl (P : Measure BrownianPath) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (s t : Time) + {a : BrownianPath → ℝ} (ha : @Measurable _ _ (usualBrownianSigma P s) (borel ℝ) a) : + Progressive P (patchControl v s t a) := by + intro T + by_cases hs : s ≤ T + · have haT := ha.mono (usualBrownianSigma_mono P hs) le_rfl + apply Measurable.ite _ (haT.comp measurable_snd) (hv T) + exact (measurableSet_Ioc : MeasurableSet (Set.Ioc s t)).preimage + (measurable_subtype_coe.comp measurable_fst) + · have he : (fun p : Set.Iic T × BrownianPath => patchControl v s t a p.1.val p.2) = + (fun p : Set.Iic T × BrownianPath => v p.1.val p.2) := by + funext p + apply ite_eq_right + intro h + exact hs (h.1.le.trans p.1.property) + rw [he] + exact hv T + +lemma patchControl_bound {v : Time → BrownianPath → ℝ} {L : ℝ≥0} + (hv : ∀ r ω, |v r ω| ≤ L) (s t : Time) {a : BrownianPath → ℝ} + (ha : ∀ ω, |a ω| ≤ L) : ∀ r ω, |patchControl v s t a r ω| ≤ L := by + intro r ω + simp only [patchControl] + split <;> first | exact ha ω | exact hv r ω + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/FreshControl.lean b/lean/OAI/Probability/Perceptron/Control/FreshControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..701ab1b17377e8194376e20e606b3f7933a452c0 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/FreshControl.lean @@ -0,0 +1,88 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.QuantileReference +import OAI.Probability.Perceptron.Variational.QuantileLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +instance compactPositivePairLaw_fst_isProbability + (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) : + IsProbabilityMeasure ((compactPositivePairLaw ν).map Prod.fst) := + inferInstance + +lemma compactPositivePairLaw_spin_quantile + (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hn : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) : + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst)) + (boundedQuantile_measurable _) : Measure CompactOverlap) := by + have : IsProbabilityMeasure ((compactPositivePairLaw ν).map Prod.fst) := + inferInstance + change _=timeLaw.map (timeSpin ∘ boundedQuantile ((compactPositivePairLaw ν).map Prod.fst)) + rw [←Measure.map_map timeSpin_continuous.measurable (boundedQuantile_measurable _), + timeLaw_eq_volume,boundedQuantile_law] + unfold compactPositivePairLaw + rw [Measure.map_map (f := fun Q : CompactArray CompactJointOverlap => compactPositivePair (Q 0 1)) + measurable_fst (by exact compactPositivePair_measurable.comp (by fun_prop))] + rw [Measure.map_map timeSpin_continuous.measurable + (show Measurable (Prod.fst ∘ fun Q : CompactArray CompactJointOverlap => compactPositivePair (Q 0 1)) from + measurable_fst.comp (compactPositivePair_measurable.comp (by fun_prop)))] + apply Measure.map_congr + filter_upwards [hn] with Q hQ + apply Subtype.ext + change (Q 0 1).1.val=max 0 (Q 0 1).1.val + exact (max_eq_right hQ).symm + +theorem compactGG_freshLog_control (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hGG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0) + (hgeo : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) + (hn : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), 0≤(Q 0 1).1.val) + (g : Jet3) (η : ProbabilityMeasure (FreshPartitionRange g.f)) + (hm : ∀ r, (∫ x, x.val^r ∂(η : Measure (FreshPartitionRange g.f)))= + ∫ Q, freshReplicaArrayKernel (expBCF 1 g.f) r Q ∂(ν : Measure _)) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) : + (∫ x, Real.log x.val ∂(η : Measure (FreshPartitionRange g.f)))= + controlValue P g.f (quantileTrial (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst))) := by + obtain ⟨ρ,ξ,hG,hge,hp,hξ,hl⟩ := quantile_reference_exists + (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst)) (boundedQuantile_monotone _) g P hB + rw [freshLog_eq_of_pair_law ν ρ hGG hG hgeo hge + ((compactPositivePairLaw_spin_quantile ν hn).trans hp.symm) g.f η ξ hm hξ] + exact hl + +theorem source_contact_freshLog_control (k : ℕ) (g : Jet3) (p d : ℕ → ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 1) (fun _ => 2)) + (hmin : ∀ n, IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k g.f (fun j => p j.val) (fun j => d j.val) (h n) z (t n) v) + (Icc (fun _ : Fin (n+1) => 1) (fun _ => 2)) (u n)) + {H T : ℝ} (hH : 0≤H) (hhH : ∀ n, h n 0≤H) (ht : ∀ n, (t n:ℝ)≤T) + (hcover : ∀ a b : ℕ, 1≤a+b → ∃ j, p j=a ∧ d j=b) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} {s : ℕ → ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k g.f + (fun a => p a.val) (fun a => d a.val) (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) : + Tendsto (fun n => sourceFreshLog (s n) k g.f (fun a => p a.val) (fun a => d a.val) + (h (s n)) (u (s n)) z (t (s n))) atTop + (𝓝 (controlValue P g.f (quantileTrial (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst))))) := by + obtain ⟨η,hη,hm,hl⟩ := sourceFreshLog_tendsto k g.f (fun _ a => p a.val) (fun _ a => d a.val) + h hh0 hh u z t s hlim + have hGG := source_contact_limit_joint_gg k g.f p d z hz hz0 hz1 t h hh0 hh u hu hmin + hH hhH ht hs hlim hcover + have hgeo := source_contact_limit_spin_geometry k g.f p d z hz hz0 hz1 t h hh0 hh u hu hmin + hH hhH ht hcover hs hlim + have hn := compact_spin_nonnegative ν (compactRealLaw_gg ν hGG) + (sourceGibbsArray_limit_gram k g.f (fun _ a => p a.val) (fun _ a => d a.val) h u z t s hlim).1 + rwa [compactGG_freshLog_control ν hGG hgeo hn g η hm P hB] at hl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/LabelProfileControl.lean b/lean/OAI/Probability/Perceptron/Control/LabelProfileControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..6bb4efa6b88520c6077113389b31d143816c54fb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/LabelProfileControl.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelValue +import OAI.Probability.Perceptron.Control.StepControl + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma oneDim_inner (v : EuclideanSpace ℝ (Fin 1)) : + inner ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) v=v 0 := by + simp [PiLp.inner_apply] + +lemma oneDim_gaussian_average (s : ℝ≥0) (f : ℝ →ᵇ ℝ) (a : ℝ) : + (∫ v : EuclideanSpace ℝ (Fin 1), f (a+Real.sqrt s*v 0) + ∂stdGaussian (EuclideanSpace ℝ (Fin 1)))=gaussianAverage s f a := by + rw [gaussianAverage_scaling] + have h : (∫ z, f (a+Real.sqrt s*z) ∂((stdGaussian (EuclideanSpace ℝ (Fin 1))).map + (fun v => v 0)))=∫ v : EuclideanSpace ℝ (Fin 1), f (a+Real.sqrt s*v 0) + ∂stdGaussian (EuclideanSpace ℝ (Fin 1)) := + integral_map (show Measurable (fun v : EuclideanSpace ℝ (Fin 1) => v 0) from by fun_prop).aemeasurable + (show Measurable (fun z : ℝ => f (a+Real.sqrt s*z)) from by fun_prop).aestronglyMeasurable + rw [stdGaussian_coordinate_law] at h + exact h.symm + +lemma oneDim_gaussian_entropic (s b : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : EuclideanSpace ℝ (Fin 1)) : + gaussianLinearEntropic (stdGaussian (EuclideanSpace ℝ (Fin 1))) b + (diagonalMark (fun _ => Real.sqrt s)) (fun v => f (v 0)) x=heatLog s b f (x 0) := by + have hX : ∀ a : ℝ, Integrable + (fun v : EuclideanSpace ℝ (Fin 1) => Real.exp (a*f (x 0+Real.sqrt s*v 0))) + (stdGaussian (EuclideanSpace ℝ (Fin 1))) := fun a => + boundedContinuousFunction_integrable_comp (expBCF a f) (by fun_prop) + change entropicMean (stdGaussian (EuclideanSpace ℝ (Fin 1))) b + (fun v => f (x 0+Real.sqrt s*v 0))=heatLog s b f (x 0) + by_cases hb : b=0 + · subst b + rw [NNReal.coe_zero,entropicMean_zero _ hX,heatLog,ite_eq_left rfl,oneDim_gaussian_average] + · rw [entropicMean_eq_div _ hX (by exact_mod_cast hb),heatLog,ite_eq_right hb] + unfold cgf mgf + change Real.log (∫ v : EuclideanSpace ℝ (Fin 1), expBCF b f (x 0+Real.sqrt s*v 0) + ∂stdGaussian (EuclideanSpace ℝ (Fin 1)))/(b:ℝ)=_ + rw [oneDim_gaussian_average] + ring + +lemma linearCascadeWord_congr {E : Type} [NormedAddCommGroup E] [NormedSpace ℝ E] + (A B : ℕ→E→L[ℝ] E) (k : ℕ) (z : Fin k→ℝ) (h : ∀ j rfl + | succ k ih => + simp only [linearCascadeWord] + rw [h k (Nat.lt_succ_self k),ih (fun i => z i.succ) (fun j hj => h j (Nat.lt_succ_of_lt hj))] + +lemma profileGaussianStep_first {k : ℕ} (q : Fin (k+2)→Time) : + profileGaussianStep (fun l (_ : Fin 1) => (q l:ℝ)) k= + fun _ => Real.sqrt (timeSpan (q 0) (q 1)) := by + funext i + simp only [profileGaussianStep,dite_eq_left (Nat.lt_succ_self k)] + have h0 : (⟨k+1-k-1,by omega⟩ : Fin (k+2))=0 := by ext; simp + have h1 : (⟨k+1-k,by omega⟩ : Fin (k+2))=1 := by ext; simp + rw [h0,h1] + simp only [timeSpan,Real.coe_toNNReal'] + by_cases h : 0≤(q 1:ℝ)-q 0 + · rw [max_eq_left h] + · have hn : (q 1:ℝ)-q 0≤0 := by linarith + rw [max_eq_right hn,Real.sqrt_eq_zero_of_nonpos hn,Real.sqrt_zero] + +lemma profileGaussianStep_tail {k : ℕ} (q : Fin (k+2)→Time) {j : ℕ} (hj : j (q l:ℝ)) j= + profileGaussianStep (fun l (_ : Fin 1) => (q l.succ:ℝ)) j := by + funext i + simp only [profileGaussianStep,dite_eq_left hj,dite_eq_left (Nat.lt_succ_of_lt hj)] + have ha : (⟨k+1-j,by omega⟩ : Fin (k+2))=(⟨k-j,by omega⟩ : Fin (k+1)).succ := by + ext; simp only [Fin.val_succ]; omega + have hb : (⟨k+1-j-1,by omega⟩ : Fin (k+2))=(⟨k-j-1,by omega⟩ : Fin (k+1)).succ := by + ext; simp only [Fin.val_succ]; omega + rw [ha,hb] + +lemma oneDim_profile_backward (g : Jet3) (k : ℕ) (q : Fin (k+1)→Time) + (z : Fin k→ℝ≥0) (x : EuclideanSpace ℝ (Fin 1)) : + gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (linearCascadeWord (fun j => diagonalMark (profileGaussianStep (fun l (_ : Fin 1) => (q l:ℝ)) j)) + k (fun i => z i)) (fun v => g.f (v 0)) x=(finiteStepControlJet g k q z).f (x 0) := by + induction k generalizing x with + | zero => rfl + | succ k ih => + simp only [linearCascadeWord,gaussianLinearBackward,finiteStepControlJet] + rw [profileGaussianStep_first] + have hw := linearCascadeWord_congr + (fun j => diagonalMark (profileGaussianStep (fun l (_ : Fin 1) => (q l:ℝ)) j)) + (fun j => diagonalMark (profileGaussianStep (fun l (_ : Fin 1) => (q l.succ:ℝ)) j)) + k (fun i => (z i.succ:ℝ)) (fun j hj => congrArg diagonalMark (profileGaussianStep_tail q hj)) + rw [hw] + have hf := funext (ih (fun i => q i.succ) (fun i => z i.succ)) + rw [hf,oneDim_gaussian_entropic,Jet3.heatLog_f] + change _=heatLog _ _ _ _ + rfl + +lemma HeatChain.prepend {m : Trial} {g h j : Jet3} {a b c : Time} + (H : HeatChain m g b c h) (J : HeatChain m h a b j) : HeatChain m g a c j := by + induction J with + | nil => exact H + | cons d hat htb hm tail ih => + exact HeatChain.cons d hat (htb.trans H.left_le_right) hm (ih H) + +lemma weightedStepTrial_controlValue_core (k : ℕ) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i,w i=1) (hq : Monotone q) (g : Jet3) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) : + controlValue P g.f (weightedStepTrial w q hw hw1)= + ((finiteStepControlJet (g.heatLog (timeSpan (q (Fin.last k)) 1) 1) k q + (weightedControlCoefficient k w hw)).heatLog (timeSpan 0 (q 0)) 0).f 0 := by + let m := leftWeightedStepTrial w q hw hw1 + have ht : HeatChain m g (q (Fin.last k)) 1 (g.heatLog (timeSpan (q (Fin.last k)) 1) 1) := by + rcases lt_or_eq_of_le (show q (Fin.last k)≤1 from le_top) with hl|he + · apply HeatChain.cons 1 hl le_rfl _ (HeatChain.nil 1) + intro r hr + change (∑ i, if q i leftWeightedStepTrial_interval k w q hw hw1 hq i hr) + have hm' := ht.prepend hm + have H : HeatChain m g 0 1 ((finiteStepControlJet (g.heatLog (timeSpan (q (Fin.last k)) 1) 1) + k q (weightedControlCoefficient k w hw)).heatLog (timeSpan 0 (q 0)) 0) := by + rcases lt_or_eq_of_le (show (0:Time)≤q 0 from bot_le) with hl|he + · apply HeatChain.cons 0 hl (show q 0≤1 from le_top) _ hm' + intro r hr + change (∑ i, if q i (q i:ℝ)) (q (Fin.last k)).prop.2 g= + controlValue P g.f (weightedStepTrial w q hw hw1) := by + rw [weightedStepTrial_controlValue_core k w q hw hw1 hq g P hB] + have hend : (⟨1-(q (Fin.last k):ℝ),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0)= + timeSpan (q (Fin.last k)) 1 := by + apply Subtype.ext + change 1-(q (Fin.last k):ℝ)=(timeSpan (q (Fin.last k)) 1:ℝ) + exact (timeSpan_coe (show q (Fin.last k)≤1 from le_top)).symm + have hstart : (timeSpan 0 (q 0):ℝ)=(q 0:ℝ) := by + rw [timeSpan_coe (show (0:Time)≤q 0 from bot_le)]; simp + have hterm : labelProfileTerminal g (timeSpan (q (Fin.last k)) 1)= + fun v : EuclideanSpace ℝ (Fin 1) => (g.heatLog (timeSpan (q (Fin.last k)) 1) 1).f (v 0) := by + funext v + rw [labelProfileTerminal,oneDim_inner,Jet3.heatLog_f] + rfl + have hc : stepCumulative w=fun i => (weightedControlCoefficient k w hw i:ℝ) := rfl + unfold labelProfileValue + rw [hend,hterm,hc] + simp_rw [oneDim_profile_backward] + simp only [diagonalMark_apply,profileGaussianRoot] + rw [Jet3.heatLog_f] + change (∫ x : EuclideanSpace ℝ (Fin 1), + (finiteStepControlJet (g.heatLog (timeSpan (q (Fin.last k)) 1) 1) k q + (weightedControlCoefficient k w hw)).f (Real.sqrt (q 0:ℝ)*x 0) + ∂stdGaussian (EuclideanSpace ℝ (Fin 1)))=heatLog (timeSpan 0 (q 0)) 0 _ 0 + rw [heatLog,ite_eq_left rfl] + simpa only [hstart,zero_add] using oneDim_gaussian_average (timeSpan 0 (q 0)) + (finiteStepControlJet (g.heatLog (timeSpan (q (Fin.last k)) 1) 1) k q + (weightedControlCoefficient k w hw)).f 0 + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/QuantileControlContinuity.lean b/lean/OAI/Probability/Perceptron/Control/QuantileControlContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..d0dba81e53078f50b3af96da649cdb40be2858a6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/QuantileControlContinuity.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.BackwardScore +import OAI.Probability.Perceptron.Variational.FieldRounding + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def cdfIndicator (a t : Time) : ℝ := if a≤t then 1 else 0 + +lemma cdfIndicator_integrable (a : Time) : Integrable (cdfIndicator a) timeLaw := by + apply Integrable.mono' (integrable_const (1:ℝ)) + ((measurable_const.ite (measurableSet_le measurable_const measurable_id) measurable_const).aestronglyMeasurable) + exact ae_of_all _ fun _ => by split_ifs <;> norm_num + +lemma cdfIndicator_integral (a : Time) : (∫ t, cdfIndicator a t ∂timeLaw)=1-(a:ℝ) := by + have he := timeTail_atom_integral a 0 1 + rw [show Ici (0:Time)=univ from Ici_bot,Measure.restrict_univ] at he + change (∫ s, (if a ≤ s then (1:ℝ) else 0) ∂timeLaw)=1*(1-max (a:ℝ) 0) at he + simpa only [cdfIndicator,one_mul,max_eq_left a.2.1] using he + +lemma cdfIndicator_order {a b : Time} (hab : a≤b) (t : Time) : cdfIndicator b t≤cdfIndicator a t := by + unfold cdfIndicator + by_cases hb : b≤t + · rw [ite_eq_left hb,ite_eq_left (hab.trans hb)] + · rw [ite_eq_right hb] + split_ifs <;> norm_num + +lemma cdfIndicator_abs_integral (a b : Time) : + (∫ t, |cdfIndicator a t-cdfIndicator b t| ∂timeLaw)=|(a:ℝ)-b| := by + have hle {a b : Time} (hab : a≤b) : + (∫ t, |cdfIndicator a t-cdfIndicator b t| ∂timeLaw)=(b:ℝ)-a := by + simp_rw [abs_of_nonneg (sub_nonneg.mpr (cdfIndicator_order hab _))] + rw [integral_sub (cdfIndicator_integrable a) (cdfIndicator_integrable b), + cdfIndicator_integral,cdfIndicator_integral] + ring + rcases le_total a b with hab | hba + · rw [hle hab,abs_sub_comm,abs_of_nonneg (sub_nonneg.mpr (show (a:ℝ)≤b from hab))] + · simp_rw [abs_sub_comm (cdfIndicator a _) (cdfIndicator b _)] + rw [hle hba,abs_of_nonneg (sub_nonneg.mpr (show (b:ℝ)≤a from hba))] + +lemma quantileTrial_L1_le (q r : Time→Time) (hq : Measurable q) (hr : Measurable r) : + (∫ t, |quantileTrial q t-quantileTrial r t| ∂timeLaw)≤ + ∫ u, |(q u:ℝ)-r u| ∂timeLaw := by + let F := fun p : Time×Time => |cdfIndicator (q p.2) p.1-cdfIndicator (r p.2) p.1| + have hmq : Measurable (fun p : Time×Time => cdfIndicator (q p.2) p.1) := + measurable_const.ite (measurableSet_le (hq.comp measurable_snd) measurable_fst) measurable_const + have hmr : Measurable (fun p : Time×Time => cdfIndicator (r p.2) p.1) := + measurable_const.ite (measurableSet_le (hr.comp measurable_snd) measurable_fst) measurable_const + have hF : Integrable F (timeLaw.prod timeLaw) := by + apply Integrable.mono' (integrable_const (1:ℝ)) ((hmq.sub hmr).abs.aestronglyMeasurable) + exact ae_of_all _ fun p => by dsimp [F,cdfIndicator]; split_ifs <;> norm_num + have hpoint (t : Time) : |quantileTrial q t-quantileTrial r t|≤∫ u, F (t,u) ∂timeLaw := by + rw [quantileTrial_eq_integral q hq,quantileTrial_eq_integral r hr] + have hi (v : Time→Time) (hv : Measurable v) : + Integrable (fun u => if v u≤t then (1:ℝ) else 0) timeLaw := by + apply Integrable.mono' (integrable_const (1:ℝ)) + ((measurable_const.ite (measurableSet_le hv measurable_const) measurable_const).aestronglyMeasurable) + exact ae_of_all _ fun _ => by split_ifs <;> norm_num + rw [← integral_sub (hi q hq) (hi r hr)] + simpa only [Real.norm_eq_abs,F,cdfIndicator] using (norm_integral_le_integral_norm + (fun u : Time => (if q u≤t then (1:ℝ) else 0)-(if r u≤t then (1:ℝ) else 0))) + calc + _ ≤ ∫ t, ∫ u, F (t,u) ∂timeLaw ∂timeLaw := + integral_mono ((trial_integrable (quantileTrial q)).sub (trial_integrable (quantileTrial r))).abs + hF.integral_prod_left hpoint + _ = ∫ u, |(q u:ℝ)-r u| ∂timeLaw := by + rw [integral_integral_swap hF] + exact integral_congr_ae (ae_of_all _ fun u => cdfIndicator_abs_integral (q u) (r u)) + +theorem controlValue_quantile_abs_sub_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (g : Jet3) (q r : Time→Time) (hq : Measurable q) (hr : Measurable r) : + |controlValue P g.f (quantileTrial q)-controlValue P g.f (quantileTrial r)|≤ + (3/2:ℝ)*(‖g.d1‖₊:ℝ)^2*∫ u, |(q u:ℝ)-r u| ∂timeLaw := by + apply (controlValue_trial_abs_sub_le P g.f _ _ ‖g.d1‖₊ g.lipschitz).trans + exact mul_le_mul_of_nonneg_left (quantileTrial_L1_le q r hq hr) (by positivity) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/QuantileControlTail.lean b/lean/OAI/Probability/Perceptron/Control/QuantileControlTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..39906c16a41e449d1973488310202d95195b4d6a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/QuantileControlTail.lean @@ -0,0 +1,92 @@ +import Mathlib +import OAI.Probability.Perceptron.Control.StepControlTail +import OAI.Probability.Perceptron.Control.QuantileControlContinuity +import OAI.Probability.Perceptron.Variational.QuantileUpperTail + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma sampledQuantile_tail_order (n : ℕ) {q r : Time→Time} (hq : Monotone q) (hr : Monotone r) + (ht : ∀ t : Time, (∫ u in Ici t, (q u:ℝ) ∂timeLaw) ≤ ∫ u in Ici t, (r u:ℝ) ∂timeLaw) + (k : ℕ) : 0 ≤ ∑ i : Fin (n+1), if k ≤ i.val then + (1/(n+1:ℝ))*((uniformQuantileUpper n r i:ℝ)-uniformQuantileLower n q i) else 0 := by + by_cases hk : k (sampleQuantile_bracket n hq u).1 + _ ≤ ∫ u in Ici (uniformQuantileGrid n j.castSucc), (r u:ℝ) ∂timeLaw := ht _ + _ ≤ _ := by + apply integral_mono (unit_valued_integrable _ hr.measurable) + (unit_valued_integrable _ (sampleQuantileUpper_mono n hr).measurable) + exact fun u => (sampleQuantile_bracket n hr u).2 + change (∫ u in Ici (uniformQuantileGrid n j.castSucc), + (uniformQuantileLower n q (uniformQuantileCell n u):ℝ) ∂timeLaw) ≤ + ∫ u in Ici (uniformQuantileGrid n j.castSucc), + (uniformQuantileUpper n r (uniformQuantileCell n u):ℝ) ∂timeLaw at h1 + rw [uniformQuantileCell_tail_integral n (fun i => (uniformQuantileLower n q i:ℝ)) j, + uniformQuantileCell_tail_integral n (fun i => (uniformQuantileUpper n r i:ℝ)) j] at h1 + have he : (∑ i : Fin (n+1), if k ≤ i.val then + (1/(n+1:ℝ))*((uniformQuantileUpper n r i:ℝ)-uniformQuantileLower n q i) else 0)= + (∑ i : Fin (n+1), if j ≤ i then (1/(n+1:ℝ))*(uniformQuantileUpper n r i:ℝ) else 0)- + (∑ i : Fin (n+1), if j ≤ i then (1/(n+1:ℝ))*(uniformQuantileLower n q i:ℝ) else 0) := by + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + change (if k ≤ i.val then _ else _)=(if k ≤ i.val then _ else _)-(if k ≤ i.val then _ else _) + split_ifs <;> ring + rw [he] + exact sub_nonneg.mpr h1 + · have hz : ∀ i : Fin (n+1), ¬k ≤ i.val := fun i => by have := i.isLt; omega + simp only [hz,ite_false,Finset.sum_const_zero,le_refl] + +lemma sampleQuantile_control_error (P : Measure BrownianPath) [IsProbabilityMeasure P] + (g : Jet3) (q : Time→Time) (hq : Monotone q) (n : ℕ) : + |controlValue P g.f (quantileTrial (sampleQuantileLower n q))-controlValue P g.f (quantileTrial q)| ≤ + (3/2:ℝ)*(‖g.d1‖₊:ℝ)^2*(1/(n+1:ℝ)) ∧ + |controlValue P g.f (quantileTrial (sampleQuantileUpper n q))-controlValue P g.f (quantileTrial q)| ≤ + (3/2:ℝ)*(‖g.d1‖₊:ℝ)^2*(1/(n+1:ℝ)) := by + constructor + · exact (controlValue_quantile_abs_sub_le P g _ _ (sampleQuantileLower_mono n hq).measurable hq.measurable).trans + (mul_le_mul_of_nonneg_left (sampleQuantileLower_L1 n hq) (by positivity)) + · exact (controlValue_quantile_abs_sub_le P g _ _ (sampleQuantileUpper_mono n hq).measurable hq.measurable).trans + (mul_le_mul_of_nonneg_left (sampleQuantileUpper_L1 n hq) (by positivity)) + +theorem sourceQuantile_control_tail_order (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (g : Jet3) (q r : Time→Time) + (hq : Monotone q) (hr : Monotone r) + (ht : ∀ t : Time, (∫ u in Ici t, (q u:ℝ) ∂timeLaw) ≤ ∫ u in Ici t, (r u:ℝ) ∂timeLaw) : + controlValue P g.f (quantileTrial r) ≤ controlValue P g.f (quantileTrial q) := by + have hi (n : ℕ) : controlValue P g.f (quantileTrial (sampleQuantileUpper n r)) ≤ + controlValue P g.f (quantileTrial (sampleQuantileLower n q)) := by + unfold sampleQuantileUpper sampleQuantileLower + rw [sampleQuantile_trial,sampleQuantile_trial] + exact sourceWeightedTrial_control_tail_order n _ _ _ (uniformQuantileWeights_nonneg n) + (uniformQuantileWeights_sum n) (uniformQuantileLower_mono n hq) (uniformQuantileUpper_mono n hr) + (sampledQuantile_tail_order n hq hr ht) g P hB + have hz : Tendsto (fun n : ℕ => (3/2:ℝ)*(‖g.d1‖₊:ℝ)^2*(1/(n+1:ℝ))) atTop (𝓝 0) := by + simpa using (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul ((3/2:ℝ)*(‖g.d1‖₊:ℝ)^2) + have hl : Tendsto (fun n => controlValue P g.f (quantileTrial (sampleQuantileLower n q))) atTop + (𝓝 (controlValue P g.f (quantileTrial q))) := by + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) hz + simpa only [Real.dist_eq] using (sampleQuantile_control_error P g q hq n).1 + have hu : Tendsto (fun n => controlValue P g.f (quantileTrial (sampleQuantileUpper n r))) atTop + (𝓝 (controlValue P g.f (quantileTrial r))) := by + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) hz + simpa only [Real.dist_eq] using (sampleQuantile_control_error P g r hr n).2 + exact le_of_tendsto_of_tendsto hu hl (Eventually.of_forall hi) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/StepControl.lean b/lean/OAI/Probability/Perceptron/Control/StepControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..40ba6de560532e121ae52e32213faa7cd7ece66a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/StepControl.lean @@ -0,0 +1,205 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.BackwardScore +import OAI.Probability.Perceptron.Variational.CoupledDual + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma Jet3.eq_of_f_eq {g h : Jet3} (he : g.f=h.f) : g=h := by + have h1 : g.d1=h.d1 := by + ext x + rw [← g.deriv_eq,← h.deriv_eq,he] + have h2 : g.d2=h.d2 := by + ext x + rw [← g.deriv2_eq,← h.deriv2_eq,he] + have h3 : g.d3=h.d3 := by + ext x + rw [← g.deriv3_eq,← h.deriv3_eq,he] + cases g + cases h + simp_all + +lemma Jet3.heatLog_zero_time (g : Jet3) (d : ℝ≥0) : g.heatLog 0 d=g := by + apply Jet3.eq_of_f_eq + ext x + simp only [Jet3.heatLog_f,heatLogBCF_coe,heatLog_zero] + +def finiteStepControlJet (g : Jet3) : (n : ℕ)→(Fin (n+1)→Time)→(Fin n→ℝ≥0)→Jet3 + | 0,_,_ => g + | n+1,q,d => (finiteStepControlJet g n (fun i => q i.succ) (fun i => d i.succ)).heatLog + (timeSpan (q 0) (q 1)) (d 0) + +lemma finiteStepControlJet_chain (g : Jet3) (m : Trial) (n : ℕ) + (q : Fin (n+1)→Time) (d : Fin n→ℝ≥0) (hq : Monotone q) + (hm : ∀ i : Fin n, ∀ r∈Ioc (q i.castSucc) (q i.succ), m r=(d i:ℝ)) : + HeatChain m g (q 0) (q (Fin.last n)) (finiteStepControlJet g n q d) := by + induction n with + | zero => exact HeatChain.nil (q 0) + | succ n ih => + have ih' := ih (fun i => q i.succ) (fun i => d i.succ) + (hq.comp (Fin.strictMono_succ.monotone)) (fun i => hm i.succ) + change HeatChain m g (q 1) (q (Fin.last (n+1))) _ at ih' + have h01 : q 0≤q 1 := hq (Fin.zero_le _) + rcases lt_or_eq_of_le h01 with hlt | he + · exact HeatChain.cons (d 0) hlt (hq (Fin.le_last _)) (hm 0) ih' + · simpa only [finiteStepControlJet,he,timeSpan,sub_self,Real.toNNReal_zero, + Jet3.heatLog_zero_time] using ih' + +lemma finiteStepControlJet_value (g : Jet3) (m : Trial) (n : ℕ) + (q : Fin (n+1)→Time) (d : Fin n→ℝ≥0) (hq : Monotone q) + (hq0 : q 0=0) (hq1 : q (Fin.last n)=1) + (hm : ∀ i : Fin n, ∀ r∈Ioc (q i.castSucc) (q i.succ), m r=(d i:ℝ)) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) : + controlValue P g.f m=(finiteStepControlJet g n q d).f 0 := by + have H := finiteStepControlJet_chain g m n q d hq hm + rw [hq0,hq1] at H + exact H.controlValue_eq P hB + +def leftWeightedStepTrial {I : Type*} [Fintype I] (w : I→ℝ) (q : I→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) : Trial where + toFun := fun t => ∑ i, if q i first | exact hw i | rfl + measurable := by + apply Finset.measurable_sum + intro i _ + exact measurable_const.ite (measurableSet_lt measurable_const measurable_id) measurable_const + nonneg := by + intro t + apply Finset.sum_nonneg + intro i _ + split_ifs <;> first | exact hw i | rfl + le_one := by + intro t + rw [← hw1] + apply Finset.sum_le_sum + intro i _ + split_ifs <;> first | rfl | exact hw i + +lemma leftWeightedStepTrial_ae {I : Type*} [Fintype I] (w : I→ℝ) (q : I→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) : + (leftWeightedStepTrial w q hw hw1 : Time→ℝ)=ᵐ[timeLaw] weightedStepTrial w q hw hw1 := by + have he : ∀ᵐ t ∂timeLaw, ∀ i, t≠q i := by + apply ae_all_iff.mpr + intro i + apply ae_iff.mpr + simp + filter_upwards [he] with t ht + apply Finset.sum_congr rfl + intro i _ + by_cases hi : q i≤t + · rw [ite_eq_left hi,ite_eq_left (lt_of_le_of_ne hi (Ne.symm (ht i)))] + · rw [ite_eq_right hi,ite_eq_right (not_lt_of_ge (le_of_not_ge hi))] + +def weightedControlCoefficient (n : ℕ) (w : Fin (n+1)→ℝ) (hw : ∀ i, 0≤w i) + (i : Fin n) : ℝ≥0 := + ⟨∑ j : Fin (n+1), if j ≤ i.castSucc then w j else 0,Finset.sum_nonneg fun j _ => by + split_ifs <;> first | exact hw j | rfl⟩ + +lemma leftWeightedStepTrial_interval (n : ℕ) (w : Fin (n+1)→ℝ) (q : Fin (n+1)→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) (hq : Monotone q) + (i : Fin n) {r : Time} (hr : r∈Ioc (q i.castSucc) (q i.succ)) : + leftWeightedStepTrial w q hw hw1 r=(weightedControlCoefficient n w hw i:ℝ) := by + change (∑ j, if q j leftWeightedStepTrial_interval n w q hw hw1 hq i hr) P hB + +def paddedControlNodes {n : ℕ} (q : Fin (n+1)→Time) : Fin (n+3)→Time := + Fin.cons 0 (Fin.snoc q 1) + +def paddedControlWeights {n : ℕ} (w : Fin (n+1)→ℝ) : Fin (n+3)→ℝ := + Fin.cons 0 (Fin.snoc w 0) + +lemma paddedControlWeights_nonneg {n : ℕ} (w : Fin (n+1)→ℝ) (hw : ∀ i, 0≤w i) : + ∀ i, 0≤paddedControlWeights w i := by + intro i + refine Fin.cases (by simp [paddedControlWeights]) (fun j => ?_) i + change 0≤(Fin.snoc w 0 : Fin (n+2)→ℝ) j + refine Fin.lastCases (by simp) (fun l => ?_) j + simpa using hw l + +lemma paddedControlWeights_sum {n : ℕ} (w : Fin (n+1)→ℝ) (hw1 : ∑ i, w i=1) : + ∑ i, paddedControlWeights w i=1 := by + unfold paddedControlWeights + rw [Fin.sum_univ_succ] + simp only [Fin.cons_zero,Fin.cons_succ,zero_add] + rw [Fin.sum_univ_castSucc] + simpa using hw1 + +lemma paddedControlNodes_mono {n : ℕ} (q : Fin (n+1)→Time) (hq : Monotone q) : + Monotone (paddedControlNodes q) := by + have hs : Monotone (Fin.snoc q 1) := by + simpa only [Fin.insertNth_last'] using Fin.insertNth_last_monotone hq 1 (show q (Fin.last n)≤1 from le_top) + simpa only [Fin.insertNth_zero',paddedControlNodes] using + Fin.insertNth_zero_monotone hs 0 (show (0:Time)≤(Fin.snoc q 1 : Fin (n+2)→Time) 0 from bot_le) + +lemma paddedControlTrial_eq {n : ℕ} (w : Fin (n+1)→ℝ) (q : Fin (n+1)→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) : + weightedStepTrial (paddedControlWeights w) (paddedControlNodes q) + (paddedControlWeights_nonneg w hw) (paddedControlWeights_sum w hw1)= + weightedStepTrial w q hw hw1 := by + apply Trial.ext_fun + intro t + change (∑ i, if paddedControlNodes q i≤t then paddedControlWeights w i else 0)= + ∑ i, if q i≤t then w i else 0 + unfold paddedControlNodes paddedControlWeights + rw [Fin.sum_univ_succ] + simp only [Fin.cons_zero,Fin.cons_succ,ite_self,zero_add] + rw [Fin.sum_univ_castSucc] + simp only [Fin.snoc_castSucc,Fin.snoc_last,ite_self,add_zero] + +theorem sourceWeightedTrial_controlValue (n : ℕ) (w : Fin (n+1)→ℝ) (q : Fin (n+1)→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) (hq : Monotone q) (g : Jet3) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) : + controlValue P g.f (weightedStepTrial w q hw hw1)= + (finiteStepControlJet g (n+2) (paddedControlNodes q) + (weightedControlCoefficient (n+2) (paddedControlWeights w) (paddedControlWeights_nonneg w hw))).f 0 := by + rw [← paddedControlTrial_eq w q hw hw1] + exact weightedStepTrial_controlValue (n+2) _ _ (paddedControlWeights_nonneg w hw) + (paddedControlWeights_sum w hw1) (paddedControlNodes_mono q hq) + (by simp [paddedControlNodes]) (by simp [paddedControlNodes]) g P hB + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Control/StepControlTail.lean b/lean/OAI/Probability/Perceptron/Control/StepControlTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..8645484d00864e9868e8c161c68365c6f0e45ec3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Control/StepControlTail.lean @@ -0,0 +1,312 @@ +import Mathlib +import OAI.Probability.Perceptron.Control.StepControl + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def linearStepIntervals : (n : ℕ) → (Fin (n+1)→ℝ) → (Fin (n+1)→ℝ) → + (Fin n→ℝ≥0) → List HeatIntervalParam + | 0,_,_,_ => [] + | n+1,q,r,d => + { duration := fun t => (1-t)*(q 1-q 0)+t*(r 1-r 0) + rate := (r 1-q 1)-(r 0-q 0) + coefficient := d 0 } :: + linearStepIntervals n (fun i => q i.succ) (fun i => r i.succ) (fun i => d i.succ) + +def stepBoundaryWeights : (n : ℕ) → (Fin (n+1)→ℝ) → (Fin n→ℝ≥0) → List ℝ + | 0,_,_ => [] + | 1,_,_ => [] + | n+2,v,d => ((d 1:ℝ)-(d 0:ℝ))*v 1 :: + stepBoundaryWeights (n+1) (fun i => v i.succ) (fun i => d i.succ) + +lemma linearStepIntervals_start (g : Jet3) (n : ℕ) + (q r : Fin (n+1)→Time) (d : Fin n→ℝ≥0) : + parametricHeatJet g (linearStepIntervals n (fun i => q i) (fun i => r i) d) 0= + finiteStepControlJet g n q d := by + induction n with + | zero => rfl + | succ n ih => + simp only [linearStepIntervals,parametricHeatJet,finiteStepControlJet, + sub_zero,one_mul,zero_mul,add_zero,timeSpan] + rw [ih] + +lemma linearStepIntervals_end (g : Jet3) (n : ℕ) + (q r : Fin (n+1)→Time) (d : Fin n→ℝ≥0) : + parametricHeatJet g (linearStepIntervals n (fun i => q i) (fun i => r i) d) 1= + finiteStepControlJet g n r d := by + induction n with + | zero => rfl + | succ n ih => + simp only [linearStepIntervals,parametricHeatJet,finiteStepControlJet, + sub_self,zero_mul,one_mul,zero_add,timeSpan] + rw [ih] + +lemma linearStepIntervals_boundary (g : Jet3) (θ : ℝ) (n : ℕ) + (q r : Fin (n+1)→ℝ) (d : Fin n→ℝ≥0) : + (heatBoundaryTerms g θ (linearStepIntervals n q r d) (r 0-q 0)).map Prod.fst= + stepBoundaryWeights n (fun i => r i-q i) d := by + induction n with + | zero => rfl + | succ n ih => + cases n with + | zero => rfl + | succ n => + simp only [linearStepIntervals,heatBoundaryTerms,List.map_cons,List.map_map, + Function.comp_def,stepBoundaryWeights] + have he : r 0-q 0+((r 1-q 1)-(r 0-q 0))=r 1-q 1 := by ring + rw [he] + congr 1 + exact ih (fun i => q i.succ) (fun i => r i.succ) (fun i => d i.succ) + +lemma linearStepIntervals_rate (n : ℕ) (q r : Fin (n+1)→ℝ) (d : Fin n→ℝ≥0) : + ((linearStepIntervals n q r d).map HeatIntervalParam.rate).sum= + (r (Fin.last n)-q (Fin.last n))-(r 0-q 0) := by + induction n with + | zero => simp [linearStepIntervals] + | succ n ih => + simp only [linearStepIntervals,List.map_cons,List.sum_cons] + rw [ih] + simp only [Fin.succ_last,Fin.succ_zero_eq_one] + ring + +lemma linearStepIntervals_continuous (n : ℕ) (q r : Fin (n+1)→ℝ) (d : Fin n→ℝ≥0) : + ∀ p∈linearStepIntervals n q r d, Continuous p.duration := by + induction n with + | zero => simp [linearStepIntervals] + | succ n ih => + intro p hp + rcases List.mem_cons.mp hp with rfl | hp + · exact ((continuous_const.sub continuous_id).mul continuous_const).add + (continuous_id.mul continuous_const) + · exact ih _ _ _ p hp + +lemma linearStepIntervals_deriv (n : ℕ) (q r : Fin (n+1)→ℝ) (d : Fin n→ℝ≥0) + (hq : StrictMono q) (hr : StrictMono r) (θ : ℝ) (hθ : θ∈Ioo (0:ℝ) 1) : + ∀ p∈linearStepIntervals n q r d, HasDerivAt p.duration p.rate θ ∧ 0 simp [linearStepIntervals] + | succ n ih => + intro p hp + rcases List.mem_cons.mp hp with rfl | hp + · constructor + · convert! (((hasDerivAt_const θ 1).sub (hasDerivAt_id θ)).mul_const (q 1-q 0)).add + ((hasDerivAt_id θ).mul_const (r 1-r 0)) using 1 + dsimp + ring + · exact add_pos (mul_pos (sub_pos.mpr hθ.2) (sub_pos.mpr (hq (by simp)))) + (mul_pos hθ.1 (sub_pos.mpr (hr (by simp)))) + · exact ih _ _ _ (hq.comp Fin.strictMono_succ) (hr.comp Fin.strictMono_succ) p hp + +lemma finiteStepControlJet_tail_order_strict (g : Jet3) (n : ℕ) + (q r : Fin (n+1)→Time) (d : Fin n→ℝ≥0) (hq : StrictMono q) (hr : StrictMono r) + (h0 : q 0=r 0) (h1 : q (Fin.last n)=r (Fin.last n)) + (ht : ∀ zs : List ℝ, zs.IsSuffix (stepBoundaryWeights n (fun i => (r i:ℝ)-q i) d) → + 0≤zs.sum) (x : ℝ) : + (finiteStepControlJet g n r d).f x≤(finiteStepControlJet g n q d).f x := by + rw [← linearStepIntervals_start g n q r d,← linearStepIntervals_end g n q r d] + apply parametricHeatJet_tail_order + · exact linearStepIntervals_continuous n _ _ d + · intro θ hθ + exact linearStepIntervals_deriv n _ _ d ((Subtype.strictMono_coe _).comp hq) + ((Subtype.strictMono_coe _).comp hr) θ hθ + · rw [linearStepIntervals_rate,h0,h1] + ring + · intro θ _ zs hz + apply ht + have hb := linearStepIntervals_boundary g θ n (fun i => (q i:ℝ)) (fun i => (r i:ℝ)) d + rw [h0,sub_self] at hb + rw [← hb] + exact hz.map _ + +def uniformControlNodes (n : ℕ) (i : Fin (n+1)) : Time := + ⟨(i:ℝ)/(n+1),div_nonneg (Nat.cast_nonneg _) (by positivity), + (div_le_one (by positivity : (0:ℝ) q i) (fun i => e i) d) t= + finiteStepControlJet g n (blendControlNodes q e t) d := by + induction n with + | zero => rfl + | succ n ih => + simp only [linearStepIntervals,parametricHeatJet,finiteStepControlJet] + rw [ih] + congr 1 + unfold timeSpan blendControlNodes + congr 1 + ring + +lemma stepBoundaryWeights_scale (n : ℕ) (v : Fin (n+1)→ℝ) (d : Fin n→ℝ≥0) (c : ℝ) : + stepBoundaryWeights n (fun i => c*v i) d=(stepBoundaryWeights n v d).map (c*·) := by + induction n with + | zero => rfl + | succ n ih => + cases n with + | zero => rfl + | succ n => + simp only [stepBoundaryWeights,List.map_cons] + rw [ih] + congr 1 + ring + +lemma stepBoundaryWeights_blend {n : ℕ} (q r e : Fin (n+1)→Time) (d : Fin n→ℝ≥0) (t : Time) : + stepBoundaryWeights n (fun i => (blendControlNodes r e t i:ℝ)-blendControlNodes q e t i) d= + (stepBoundaryWeights n (fun i => (r i:ℝ)-q i) d).map ((1-(t:ℝ))*·) := by + rw [← stepBoundaryWeights_scale] + congr 1 + funext i + simp only [blendControlNodes] + ring + +theorem finiteStepControlJet_tail_order (g : Jet3) (n : ℕ) + (q r : Fin (n+1)→Time) (d : Fin n→ℝ≥0) (hq : Monotone q) (hr : Monotone r) + (h0 : q 0=r 0) (h1 : q (Fin.last n)=r (Fin.last n)) + (ht : ∀ zs : List ℝ, zs.IsSuffix (stepBoundaryWeights n (fun i => (r i:ℝ)-q i) d) → + 0≤zs.sum) (x : ℝ) : + (finiteStepControlJet g n r d).f x≤(finiteStepControlJet g n q d).f x := by + let e := uniformControlNodes n + have he : StrictMono e := uniformControlNodes_strict n + let F := fun s : ℝ => (parametricHeatJet g + (linearStepIntervals n (fun i => q i) (fun i => e i) d) s).f x + let G := fun s : ℝ => (parametricHeatJet g + (linearStepIntervals n (fun i => r i) (fun i => e i) d) s).f x + have hF : ContinuousAt F 0 := + (BoundedContinuousFunction.evalCLM ℝ x).continuous.continuousAt.comp + (parametricHeatJet_continuousAt _ _ _ (fun p hp => + (linearStepIntervals_continuous n _ _ d p hp).continuousAt)) + have hG : ContinuousAt G 0 := + (BoundedContinuousFunction.evalCLM ℝ x).continuous.continuousAt.comp + (parametricHeatJet_continuousAt _ _ _ (fun p hp => + (linearStepIntervals_continuous n _ _ d p hp).continuousAt)) + have hi (s : ℝ) (hs : s∈Ioo (0:ℝ) 1) : G s≤F s := by + let t : Time := ⟨s,hs.1.le,hs.2.le⟩ + change (parametricHeatJet g _ (t:ℝ)).f x≤(parametricHeatJet g _ (t:ℝ)).f x + rw [linearStepIntervals_eval,linearStepIntervals_eval] + apply finiteStepControlJet_tail_order_strict g n _ _ d + (blendControlNodes_strict q e t hq he hs.1) (blendControlNodes_strict r e t hr he hs.1) + · apply Subtype.ext + simp only [blendControlNodes,h0] + · apply Subtype.ext + simp only [blendControlNodes,h1] + · intro zs hz + rw [stepBoundaryWeights_blend] at hz + obtain ⟨ys,hy,rfl⟩ := List.suffix_map_iff.mp hz + rw [List.sum_map_mul_left] + simpa using mul_nonneg (sub_nonneg.mpr hs.2.le) (ht ys hy) + let : NeBot (𝓝[Ioo (0:ℝ) 1] 0) := left_nhdsWithin_Ioo_neBot zero_lt_one + have hlim : G 0≤F 0 := le_of_tendsto_of_tendsto hG.continuousWithinAt.tendsto + hF.continuousWithinAt.tendsto (eventually_mem_nhdsWithin.mono fun s hs => hi s hs) + simpa only [F,G,linearStepIntervals_start] using hlim + +lemma stepBoundaryWeights_ofFn (n : ℕ) (v : Fin (n+2)→ℝ) (d : Fin (n+1)→ℝ≥0) : + stepBoundaryWeights (n+1) v d= + List.ofFn (fun i : Fin n => ((d i.succ:ℝ)-(d i.castSucc:ℝ))*v i.succ.castSucc) := by + induction n with + | zero => simp [stepBoundaryWeights] + | succ n ih => + rw [stepBoundaryWeights,List.ofFn_succ,ih] + rfl + +lemma weightedControlCoefficient_gap (n : ℕ) (w : Fin (n+2)→ℝ) (hw : ∀ i, 0≤w i) (i : Fin n) : + (weightedControlCoefficient (n+1) w hw i.succ:ℝ)- + weightedControlCoefficient (n+1) w hw i.castSucc=w i.succ.castSucc := by + have he (j : Fin (n+2)) : + (if j ≤ i.succ.castSucc then w j else 0)= + (if j ≤ i.castSucc.castSucc then w j else 0)+(if j=i.succ.castSucc then w j else 0) := by + by_cases hj : j=i.succ.castSucc + · subst j + have hn : ¬i.succ.castSucc ≤ i.castSucc.castSucc := by + simp only [Fin.le_iff_val_le_val,Fin.val_castSucc,Fin.val_succ] + omega + simp only [le_refl,ite_true,hn,ite_false,zero_add] + · have hle : j ≤ i.succ.castSucc ↔ j ≤ i.castSucc.castSucc := by + simp only [Fin.le_iff_val_le_val,Fin.val_castSucc,Fin.val_succ] + have hne : j.val≠i.val+1 := by simpa [Fin.ext_iff] using hj + omega + simp only [hj,hle,ite_false,add_zero] + change (∑ j, if j ≤ i.succ.castSucc then w j else 0)- + (∑ j, if j ≤ i.castSucc.castSucc then w j else 0)=_ + simp_rw [he] + rw [Finset.sum_add_distrib] + simp + +lemma paddedControl_boundaryWeights (n : ℕ) (w : Fin (n+1)→ℝ) (hw : ∀ i, 0≤w i) + (q r : Fin (n+1)→Time) : + stepBoundaryWeights (n+2) + (fun i => (paddedControlNodes r i:ℝ)-paddedControlNodes q i) + (weightedControlCoefficient (n+2) (paddedControlWeights w) (paddedControlWeights_nonneg w hw))= + List.ofFn (fun i => w i*((r i:ℝ)-q i)) := by + rw [stepBoundaryWeights_ofFn] + congr 1 + funext i + rw [weightedControlCoefficient_gap] + simp [paddedControlWeights,paddedControlNodes,Fin.castSucc_succ] + +lemma listOfFn_suffix_sum_nonneg (n : ℕ) (v : Fin n→ℝ) + (ht : ∀ k : ℕ, 0≤∑ i, if k ≤ i.val then v i else 0) : + ∀ zs : List ℝ, zs.IsSuffix (List.ofFn v) → 0≤zs.sum := by + induction n with + | zero => + intro zs hz + simpa using (show zs=[] from by simpa using hz) ▸ (le_refl (0:ℝ)) + | succ n ih => + intro zs hz + rw [List.ofFn_succ] at hz + obtain ⟨ys,hys⟩ := hz + cases ys with + | nil => + have he : zs=v 0 ::List.ofFn (fun i => v i.succ) := by simpa using hys + rw [he,← List.ofFn_succ,List.sum_ofFn] + simpa using ht 0 + | cons a ys => + have he : ys++zs=List.ofFn (fun i => v i.succ) := (List.cons.inj hys).2 + apply ih (fun i => v i.succ) ?_ zs ⟨ys,he⟩ + intro k + have H := ht (k+1) + rw [Fin.sum_univ_succ] at H + simpa only [Fin.val_zero,(show ¬k+1≤0 by omega),ite_false,zero_add,Fin.val_succ, + Nat.add_le_add_iff_right] using H + +theorem sourceWeightedTrial_control_tail_order (n : ℕ) (w : Fin (n+1)→ℝ) + (q r : Fin (n+1)→Time) (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) + (hq : Monotone q) (hr : Monotone r) + (ht : ∀ k : ℕ, 0≤∑ i, if k ≤ i.val then w i*((r i:ℝ)-q i) else 0) + (g : Jet3) (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) : + controlValue P g.f (weightedStepTrial w r hw hw1)≤ + controlValue P g.f (weightedStepTrial w q hw hw1) := by + rw [sourceWeightedTrial_controlValue n w r hw hw1 hr g P hB, + sourceWeightedTrial_controlValue n w q hw hw1 hq g P hB] + apply finiteStepControlJet_tail_order g (n+2) _ _ _ (paddedControlNodes_mono q hq) + (paddedControlNodes_mono r hr) + · simp [paddedControlNodes] + · simp [paddedControlNodes] + · rw [paddedControl_boundaryWeights n w hw q r] + exact listOfFn_suffix_sum_nonneg (n+1) _ ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/AnnealedMarkedReplica.lean b/lean/OAI/Probability/Perceptron/Interpolation/AnnealedMarkedReplica.lean new file mode 100644 index 0000000000000000000000000000000000000000..4afb67591ba0efa844f91ab6a2636818a26c87a6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/AnnealedMarkedReplica.lean @@ -0,0 +1,34 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.KernelInfiniteReplica + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +namespace SphericalPerceptronFreeEnergy +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) [IsProbabilityMeasure P] +variable (H : A→S→ℝ) (hH : Measurable (Function.uncurry H)) + +lemma annealedInfiniteReplica_marked_prefix (hexp : ∀ᵐ a ∂P, + Integrable (fun x => Real.exp (H a x)) (κ a)) (r : ℕ) {G : A→(Fin r→S)→ℝ} + (hG : Measurable (Function.uncurry G)) {B : ℝ} (hGB : ∀ a x,|G a x|≤B) : + (∫ a,G a.1 (fun i => a.2 i.val) ∂annealedInfiniteReplicaMeasure κ P H hH)= + ∫ a,gibbsReplicaMean (κ a) (H a) r (G a) ∂P := by + let := gibbsProbabilityKernel_markov κ H hH + have hm : Measurable (fun a : A×(ℕ→S) => G a.1 (fun i : Fin r => a.2 i.val)) := + hG.comp (measurable_fst.prodMk (by fun_prop)) + have hi : Integrable (fun a : A×(ℕ→S) => G a.1 (fun i : Fin r => a.2 i.val)) + (annealedInfiniteReplicaMeasure κ P H hH) := + Integrable.of_bound hm.aestronglyMeasurable B (ae_of_all _ fun a => by + simpa only [Real.norm_eq_abs] using hGB a.1 (fun i => a.2 i.val)) + rw [annealedInfiniteReplicaMeasure,Measure.integral_compProd hi] + apply integral_congr_ae + filter_upwards [hexp] with a ha + rw [kernelInfiniteReplica_prefix_integral _ a r hG.of_uncurry_left] + exact gibbsProbabilityKernel_replica_integral κ H hH a ha r (G a) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/AnnealedReplicaConvergence.lean b/lean/OAI/Probability/Perceptron/Interpolation/AnnealedReplicaConvergence.lean new file mode 100644 index 0000000000000000000000000000000000000000..e67d1b104a90025c4d910891f747b6021e3d7ca2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/AnnealedReplicaConvergence.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedAncestry +import OAI.Probability.Perceptron.Interpolation.CountableGaussianReplicaIBP + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +section +variable {S Ω : Type*} [MeasurableSpace S] [MeasurableSpace Ω] +variable (μ : Measure S) (ν : Measure Ω) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] +variable {H : Ω → S → ℝ} (hH : Measurable (Function.uncurry H)) + +include hH in +lemma annealedReplica_bounded_integrable {r : ℕ} {G : (Fin r → S) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Integrable (fun g => gibbsReplicaMean μ (H g) r G) ν := by + apply Integrable.of_bound (replicaMean_varying_measurable μ (F := fun _ => G) hH (hG.comp measurable_snd)).aestronglyMeasurable B + exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs,gibbsReplicaMean] using tiltMean_bound_general (Measure.pi fun _ : Fin r => μ) (H := replicaPotential (H g) r) + (replicaPotential_measurable (hH.comp (measurable_const.prodMk measurable_id)) r) hG hB hGB + +include hH in +lemma annealedReplica_bounded_tendsto {r : ℕ} {F : ℕ → (Fin r → S) → ℝ} {G : (Fin r → S) → ℝ} + (hF : ∀ n, Measurable (F n)) (_ : Measurable G) {B : ℝ} (hB : 0 ≤ B) + (hFB : ∀ n x, |F n x| ≤ B) (hlim : ∀ x, Tendsto (fun n => F n x) atTop (nhds (G x))) + (he : ∀ᵐ g ∂ν, Integrable (fun x => Real.exp (H g x)) μ) : + Tendsto (fun n => ∫ g, gibbsReplicaMean μ (H g) r (F n) ∂ν) atTop + (nhds (∫ g, gibbsReplicaMean μ (H g) r G ∂ν)) := by + apply tendsto_integral_of_dominated_convergence (fun _ : Ω => B) + (fun n => (replicaMean_varying_measurable μ (F := fun _ => F n) hH ((hF n).comp measurable_snd)).aestronglyMeasurable) + (integrable_const B) + · intro n + exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs,gibbsReplicaMean] using tiltMean_bound_general (Measure.pi fun _ : Fin r => μ) (H := replicaPotential (H g) r) + (replicaPotential_measurable (hH.comp (measurable_const.prodMk measurable_id)) r) (hF n) hB (hFB n) + · filter_upwards [he] with g hg + have hh : Measurable (H g) := hH.comp (measurable_const.prodMk measurable_id) + let := tilt_law_probability_of_integrable μ (by simpa only [one_mul] using hg : + Integrable (fun x => Real.exp (1*H g x)) μ) + simp_rw [gibbsReplicaMean_integral_of_integrable μ hh hg] + exact tendsto_integral_of_dominated_convergence (fun _ : Fin r → S => B) + (fun n => (hF n).aestronglyMeasurable) (integrable_const B) + (fun n => ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hFB n x) + (ae_of_all _ hlim) + +end +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma gaussianReplica_prefix_ibp (m n : ℕ) (j : Fin n) + {W : S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} {G : (Fin n → S) → ℝ} + (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) + (hL : Measurable L) (hG : Measurable G) {A D E B : ℝ} + (hA : ∀ x, |W x| ≤ A) (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) + (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) + (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + let H := countableGaussianHamiltonian W v L + (∫ g, gibbsReplicaMean μ (H g) n (fun x => truncatedCountableGaussianField w L m g (x j)*G x) + ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean μ (H g) n (fun x => G x*∑ l, gaussianPrefixCovariance v w L m (x j) (x l)) - + n*gibbsReplicaMean μ (H g) (n+1) + (fun x => G (fun l => x l.succ)*gaussianPrefixCovariance v w L m (x j.succ) (x 0)) ∂countableGaussianLaw := by + dsimp only + let H := countableGaussianHamiltonian W v L + let a := maskedGaussianCoefficient v L + let b := maskedGaussianCoefficient w L + let C := Real.sqrt D + let Q := Real.sqrt E + have hmH : Measurable (Function.uncurry H) := countableGaussianHamiltonian_measurable hW hv hL + have hmHg (g) : Measurable (H g) := hmH.comp (measurable_const.prodMk measurable_id) + have hma (i) : Measurable (a i) := maskedGaussianCoefficient_measurable hv hL i + have hmb (i) : Measurable (b i) := maskedGaussianCoefficient_measurable hw hL i + have ha (i x) : |a i x| ≤ C := maskedGaussianCoefficient_bound v L hD i x + have hb (i x) : |b i x| ≤ Q := maskedGaussianCoefficient_bound w L hE i x + have hC : 0 ≤ C := Real.sqrt_nonneg _ + have hQ : 0 ≤ Q := Real.sqrt_nonneg _ + have he : ∀ᵐ g ∂countableGaussianLaw, Integrable (fun x => Real.exp (H g x)) μ := by + simpa only [one_mul] using (countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).prod_left_ae + let F (i : Fin m) (x : Fin n → S) := b i.val (x j)*G x + let U (i : Fin m) (x : Fin n → S) := replicaPotential (a i.val) n x*F i x + let V (i : Fin m) (x : Fin (n+1) → S) := a i.val (x 0)*(b i.val (x j.succ)*G (fun l => x l.succ)) + have hFm (i) : Measurable (F i) := ((hmb i.val).comp (measurable_pi_apply j)).mul hG + have hUm (i) : Measurable (U i) := (replicaPotential_measurable (hma i.val) n).mul (hFm i) + have hVm (i) : Measurable (V i) := by + exact ((hma i.val).comp (measurable_pi_apply 0)).mul + (((hmb i.val).comp (measurable_pi_apply j.succ)).mul + (hG.comp (Measurable.of_eval fun index : Fin n => measurable_pi_apply index.succ))) + have hFB (i x) : |F i x| ≤ Q*B := by + exact (abs_mul _ _).trans_le (mul_le_mul (hb _ _) (hGB _) (abs_nonneg _) hQ) + have hUB (i x) : |U i x| ≤ (n:ℝ)*C*Q*B := by + dsimp only [U] + rw [abs_mul] + calc + _ ≤ ((n:ℝ)*C)*(Q*B) := mul_le_mul (replicaPotential_bound (ha i.val) n x) (hFB i x) + (abs_nonneg _) (mul_nonneg (Nat.cast_nonneg n) hC) + _ = _ := by ring + have hVB (i x) : |V i x| ≤ C*Q*B := by + dsimp only [V] + rw [abs_mul] + calc + _ ≤ C*(Q*B) := mul_le_mul (ha _ _) (hFB i (fun l => x l.succ)) (abs_nonneg _) hC + _ = _ := by ring + have hUi (i) : Integrable (fun g => gibbsReplicaMean μ (H g) n (U i)) countableGaussianLaw := + annealedReplica_bounded_integrable μ countableGaussianLaw hmH (hUm i) (by positivity) (hUB i) + have hVi (i) : Integrable (fun g => gibbsReplicaMean μ (H g) (n+1) (V i)) countableGaussianLaw := + annealedReplica_bounded_integrable μ countableGaussianLaw hmH (hVm i) (by positivity) (hVB i) + have hFi (i : Fin m) : Integrable (fun g => g i.val*gibbsReplicaMean μ (H g) n (F i)) countableGaussianLaw := by + have hg : Integrable (fun g : ℕ → ℝ => g i.val) countableGaussianLaw := + (measurePreserving_eval_infinitePi (fun _ : ℕ => gaussianReal 0 1) i.val).integrable_comp_of_integrable + ((memLp_id_gaussianReal (μ := 0) (v := 1) 1).integrable (by norm_num)) + apply hg.mul_bdd (replicaMean_measurable μ hmH (hFm i)).aestronglyMeasurable + exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs,gibbsReplicaMean] using tiltMean_bound_general _ + (replicaPotential_measurable (hmHg g) n) (hFm i) (mul_nonneg hQ hB) (hFB i) + have hleft : ∀ᵐ g ∂countableGaussianLaw, + gibbsReplicaMean μ (H g) n (fun x => truncatedCountableGaussianField w L m g (x j)*G x) = + ∑ i : Fin m, g i.val*gibbsReplicaMean μ (H g) n (F i) := by + filter_upwards [he] with g hg + rw [show (fun x => truncatedCountableGaussianField w L m g (x j)*G x) = + fun x => ∑ i : Fin m, g i.val*F i x by + funext x + simp only [truncatedCountableGaussianField,gaussianPrefixField,Finset.sum_mul,F,b] + apply Finset.sum_congr rfl + intro i _ + ring] + rw [gibbsReplicaMean_sum_of_integrable μ Finset.univ (hmHg g) hg + (fun i _ => (hFm i).const_mul (g i.val)) (D := fun i => |g i.val| *(Q*B)) + (fun i _ x => by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (hFB i x) (abs_nonneg _))] + simp_rw [replicaMean_const_mul] + have hright : ∀ᵐ g ∂countableGaussianLaw, + (∑ i : Fin m, (gibbsReplicaMean μ (H g) n (U i)-(n:ℝ)*gibbsReplicaMean μ (H g) (n+1) (V i))) = + gibbsReplicaMean μ (H g) n (fun x => G x*∑ l, gaussianPrefixCovariance v w L m (x j) (x l)) - + n*gibbsReplicaMean μ (H g) (n+1) + (fun x => G (fun l => x l.succ)*gaussianPrefixCovariance v w L m (x j.succ) (x 0)) := by + filter_upwards [he] with g hg + rw [Finset.sum_sub_distrib,← Finset.mul_sum, + ← gibbsReplicaMean_sum_of_integrable μ Finset.univ (hmHg g) hg (fun i _ => hUm i) (fun i _ => hUB i), + ← gibbsReplicaMean_sum_of_integrable μ Finset.univ (hmHg g) hg (fun i _ => hVm i) (fun i _ => hVB i)] + congr 1 + · congr 1 + funext x + dsimp [U,F,replicaPotential,gaussianPrefixCovariance,a,b] + simp only [Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro l _ + apply Finset.sum_congr rfl + intro i _ + ring + · congr 1 + congr 1 + funext x + simp only [V,gaussianPrefixCovariance,Finset.mul_sum,a,b] + apply Finset.sum_congr rfl + intro i _ + ring + calc + _ = ∫ g, ∑ i : Fin m, g i.val*gibbsReplicaMean μ (H g) n (F i) ∂countableGaussianLaw := + integral_congr_ae hleft + _ = ∑ i : Fin m, ∫ g, g i.val*gibbsReplicaMean μ (H g) n (F i) ∂countableGaussianLaw := + integral_finsetSum _ (fun i _ => hFi i) + _ = ∑ i : Fin m, ∫ g, gibbsReplicaMean μ (H g) n (U i)- + n*gibbsReplicaMean μ (H g) (n+1) (V i) ∂countableGaussianLaw := by + apply Finset.sum_congr rfl + intro i _ + exact gaussianHamiltonian_replica_coordinate_ibp μ i.val n hW hv hL (hFm i) hA hD + (mul_nonneg hQ hB) (hFB i) + _ = ∫ g, ∑ i : Fin m, (gibbsReplicaMean μ (H g) n (U i)- + n*gibbsReplicaMean μ (H g) (n+1) (V i)) ∂countableGaussianLaw := + (integral_finsetSum _ (fun i _ => (hUi i).sub ((hVi i).const_mul n))).symm + _ = _ := integral_congr_ae hright + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/ArrayGeometry.lean b/lean/OAI/Probability/Perceptron/Interpolation/ArrayGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..d4b5985f1e940ce1f269a34d64b20d8095beed80 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/ArrayGeometry.lean @@ -0,0 +1,186 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.KernelInfiniteReplica + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set TopologicalSpace Matrix +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma countableGaussianCovariance_posSemidef {S : Type*} [MeasurableSpace S] + (v : ℕ → S → ℝ) (L : S → ℕ) (r : ℕ) (x : Fin r → S) : + Matrix.PosSemidef (fun i j => countableGaussianCovariance v v L (x i) (x j)) := by + classical + have he : ∀ᶠ n in atTop, ∀ i j : Fin r, + gaussianPrefixCovariance v v L n (x i) (x j) = countableGaussianCovariance v v L (x i) (x j) := by + simp only [Filter.eventually_all] + exact fun i j => gaussianPrefixCovariance_eventually_eq v v L (x i) (x j) + obtain ⟨n,hn⟩ := he.exists + let A : Matrix (Fin n) (Fin r) ℝ := fun a i => maskedGaussianCoefficient v L a.val (x i) + have hp := Matrix.posSemidef_conjTranspose_mul_self A + have hm : (fun i j => countableGaussianCovariance v v L (x i) (x j)) = Aᴴ * A := by + funext i j + rw [← hn i j] + simp only [gaussianPrefixCovariance,A] + rfl + rw [hm] + exact hp + +lemma sourceSpinArray_posSemidef {N k : ℕ} (x : ℕ → NormalizedSpin N×IndexedLeaf k) (r : ℕ) : + Matrix.PosSemidef (fun i j : Fin r => ((sourceJointArray x i j).1:ℝ)) := by + exact Matrix.posSemidef_gram ℝ (fun i : Fin r => (x i).1.val) + +lemma sourceTreeArray_posSemidef {N k : ℕ} (x : ℕ → NormalizedSpin N×IndexedLeaf k) (r : ℕ) : + Matrix.PosSemidef (fun i j : Fin r => ((sourceJointArray x i j).2:ℝ)) := by + let q : Fin (k+1) → Fin 1 → ℝ := fun l _ => (l.val:ℝ)/(k+1:ℕ) + let V : NormalizedSpin N → EuclideanSpace ℝ (Fin 1) := fun _ => WithLp.toLp 2 (fun _ => 1) + let v := indexedGaussianRow k (hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q)) V + have hq : ∀ i, Monotone (fun l => q l i) := by + intro i a b hab + exact div_le_div_of_nonneg_right (by exact_mod_cast hab) (by positivity) + have he (i j : Fin r) : countableGaussianCovariance v v + (indexedGaussianRowLength (I := Fin 1) k) (x i) (x j) = ((sourceJointArray x i j).2:ℝ) := by + rw [profileGaussianRow_covariance q (by intro; simp [q]) hq V V] + simp [q,V,sourceJointArray,sourceJointOverlap] + have hp := countableGaussianCovariance_posSemidef v + (indexedGaussianRowLength (I := Fin 1) k) r (fun i => x i) + simpa only [he] using hp + +lemma sourceJointArray_diagonal {N k : ℕ} (x : ℕ → NormalizedSpin N×IndexedLeaf k) (i : ℕ) : + ((sourceJointArray x i i).1:ℝ) = 1 := by + change inner ℝ (x i).1.val (x i).1.val = 1 + have hx : ‖(x i).1.val‖=1 := by simp + simp [hx] + +lemma isClosed_matrix_posSemidef (r : ℕ) : IsClosed {M : Matrix (Fin r) (Fin r) ℝ | M.PosSemidef} := by + have he : {M : Matrix (Fin r) (Fin r) ℝ | M.PosSemidef} = + {M : Matrix (Fin r) (Fin r) ℝ | ∀ i j, M j i=M i j} ∩ ⋂ x : Fin r → ℝ, {M : Matrix (Fin r) (Fin r) ℝ | 0 ≤ star x ⬝ᵥ (M *ᵥ x)} := by + ext M + simp only [mem_ofPred_eq,mem_inter_iff,mem_iInter,Matrix.posSemidef_iff_dotProduct_mulVec,Matrix.IsHermitian.ext_iff,star_trivial] + rw [he] + apply IsClosed.inter + · simp only [ofPred_forall] + exact isClosed_iInter fun i => isClosed_iInter fun j => isClosed_eq (by fun_prop) (by fun_prop) + · exact isClosed_iInter fun x => isClosed_le continuous_const (by + unfold dotProduct Matrix.mulVec + fun_prop) + +section +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma pi_iid_reindex_preserving {ι : Type*} [Fintype ι] (e : Equiv.Perm ι) : + MeasurePreserving (fun x : ι → S => fun i => x (e i)) + (Measure.pi (fun _ : ι => μ)) (Measure.pi (fun _ : ι => μ)) := by + have he : (fun x : ι → S => fun i => x (e i)) = MeasurableEquiv.piCongrLeft (fun _ : ι => S) e.symm := by + funext x i + simp [MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft_apply_eq_cast] + rw [he] + exact measurePreserving_piCongrLeft (fun _ : ι => μ) e.symm + +lemma infinite_iid_reindex_preserving (e : Equiv.Perm ℕ) : + MeasurePreserving (fun x : ℕ → S => fun i => x (e i)) + (Measure.infinitePi (fun _ : ℕ => μ)) (Measure.infinitePi (fun _ : ℕ => μ)) := by + have he : (fun x : ℕ → S => fun i => x (e i)) = MeasurableEquiv.piCongrLeft (fun _ : ℕ => S) e.symm := by + funext x i + simp [MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft_apply_eq_cast] + rw [he] + exact ⟨(MeasurableEquiv.piCongrLeft _ e.symm).measurable, + Measure.infinitePi_map_piCongrLeft (fun _ : ℕ => μ) e.symm⟩ + +lemma gibbsReplicaMean_reindex {H : S → ℝ} (hH : Measurable H) + (hexp : Integrable (fun x => Real.exp (H x)) μ) (r : ℕ) (e : Equiv.Perm (Fin r)) + {G : (Fin r → S) → ℝ} (hG : Measurable G) : + gibbsReplicaMean μ H r (fun x => G (fun i => x (e i))) = gibbsReplicaMean μ H r G := by + let : IsProbabilityMeasure (tiltLaw μ H 1) := + tilt_law_probability_of_integrable μ (by simpa only [one_mul] using hexp) + rw [gibbsReplicaMean_integral_of_integrable μ hH hexp, + gibbsReplicaMean_integral_of_integrable μ hH hexp] + have hp := pi_iid_reindex_preserving (tiltLaw μ H 1) e + calc + _ = ∫ x, G x ∂Measure.map (fun x : Fin r → S => fun i => x (e i)) + (Measure.pi (fun _ : Fin r => tiltLaw μ H 1)) := + (integral_map hp.measurable.aemeasurable hG.aestronglyMeasurable).symm + _ = _ := by rw [hp.map_eq] + +lemma gibbsReplicaMean_fresh_last {H : S → ℝ} (hH : Measurable H) + (hexp : Integrable (fun x => Real.exp (H x)) μ) (r : ℕ) + {G : (Fin r → S) → S → ℝ} (hG : Measurable (Function.uncurry G)) : + gibbsReplicaMean μ H (r+1) (fun x => G (fun i => x i.succ) (x 0)) = + gibbsReplicaMean μ H (r+1) (fun x => G (fun i => x i.castSucc) (x (Fin.last r))) := by + have hr := gibbsReplicaMean_reindex μ hH hexp (r+1) (finRotate (r+1)) + (G:=fun x => G (fun i => x i.castSucc) (x (Fin.last r))) + (hG.comp (show Measurable (fun x : Fin (r+1) → S => ((fun i : Fin r => x i.castSucc),x (Fin.last r))) from by fun_prop)) + have he (i : Fin r) : finRotate (r+1) i.castSucc = i.succ := finRotate_of_lt i.isLt + simpa only [finRotate_last,he] using hr + +end + +lemma annealedInfiniteReplica_reindex {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] + (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) [IsProbabilityMeasure P] + (H : A → S → ℝ) (hH : Measurable (Function.uncurry H)) (e : Equiv.Perm ℕ) : + MeasurePreserving (fun a : A×(ℕ→S) => (a.1,fun i => a.2 (e i))) + (annealedInfiniteReplicaMeasure κ P H hH) (annealedInfiniteReplicaMeasure κ P H hH) := by + let : IsMarkovKernel (gibbsProbabilityKernel κ H) := gibbsProbabilityKernel_markov κ H hH + have hm : Measurable (fun x : ℕ→S => fun i => x (e i)) := by fun_prop + have he : (kernelInfiniteReplica (gibbsProbabilityKernel κ H) ℕ).map (fun x i => x (e i)) = + kernelInfiniteReplica (gibbsProbabilityKernel κ H) ℕ := by + ext a s hs + rw [Kernel.map_apply _ hm _] + exact congrArg (fun μ : Measure (ℕ→S) => μ s) + (infinite_iid_reindex_preserving (gibbsProbabilityKernel κ H a) e).map_eq + refine ⟨by fun_prop, ?_⟩ + change (P ⊗ₘ kernelInfiniteReplica (gibbsProbabilityKernel κ H) ℕ).map + (Prod.map id (fun x i => x (e i))) = _ + rw [← Measure.compProd_map hm,he] + rfl + +def compactRelabel {K : Type*} (e : Equiv.Perm ℕ) (Q : CompactArray K) : CompactArray K := + fun i j => Q (e i) (e j) + +lemma compactRelabel_continuous {K : Type*} [TopologicalSpace K] (e : Equiv.Perm ℕ) : + Continuous (compactRelabel (K:=K) e) := by unfold compactRelabel; fun_prop + +lemma sourceGibbsArray_exchangeable (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) + (e : Equiv.Perm ℕ) : + MeasurePreserving (compactRelabel (K:=CompactJointOverlap) e) + (sourceGibbsArrayLaw n k f p d h u z t : Measure _) + (sourceGibbsArrayLaw n k f p d h u z t : Measure _) := by + have hr := annealedInfiniteReplica_reindex (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) (sourceCouplingHamiltonian_measurable n k f p d h u) e + have hm : Measurable (fun a : (SourceBaseData n k × (ℕ→ℝ)) × + (ℕ → NormalizedSpin (n+1) × IndexedLeaf k) => sourceJointArray a.2) := + (sourceJointArray_measurable (n+1) k).comp measurable_snd + refine ⟨(compactRelabel_continuous e).measurable, ?_⟩ + change Measure.map _ (Measure.map (fun a : (SourceBaseData n k × (ℕ→ℝ)) × + (ℕ → NormalizedSpin (n+1) × IndexedLeaf k) => sourceJointArray a.2) _) = _ + rw [Measure.map_map (compactRelabel_continuous e).measurable hm] + change Measure.map ((fun a : (SourceBaseData n k × (ℕ→ℝ)) × + (ℕ → NormalizedSpin (n+1) × IndexedLeaf k) => sourceJointArray a.2) ∘ + (fun a : (SourceBaseData n k × (ℕ→ℝ)) × + (ℕ → NormalizedSpin (n+1) × IndexedLeaf k) => (a.1,fun i => a.2 (e i)))) _ = _ + rw [← Measure.map_map hm hr.measurable,hr.map_eq] + rfl + +lemma compact_exchangeability_limit {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [MetrizableSpace K] [SecondCountableTopology K] + {μ : ℕ → ProbabilityMeasure (CompactArray K)} {ν : ProbabilityMeasure (CompactArray K)} + (hμ : Tendsto μ atTop (𝓝 ν)) (e : Equiv.Perm ℕ) + (he : ∀ n, MeasurePreserving (compactRelabel (K:=K) e) (μ n : Measure _) (μ n : Measure _)) : + MeasurePreserving (compactRelabel (K:=K) e) (ν : Measure _) (ν : Measure _) := by + have hc := compactRelabel_continuous (K:=K) e + have hmap := ProbabilityMeasure.tendsto_map_of_tendsto_of_continuous μ ν hμ hc + have he' (n : ℕ) : (μ n).map (compactRelabel e) = μ n := by + apply Subtype.ext + exact (he n).map_eq + simp_rw [he'] at hmap + have hv := tendsto_nhds_unique hmap hμ + exact ⟨hc.measurable,congrArg Subtype.val hv⟩ + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/ArrayLawExt.lean b/lean/OAI/Probability/Perceptron/Interpolation/ArrayLawExt.lean new file mode 100644 index 0000000000000000000000000000000000000000..1af10fd6d728439bbbd0531822a608f222aff53e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/ArrayLawExt.lean @@ -0,0 +1,45 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CovarianceMatrix + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology +namespace SphericalPerceptronFreeEnergy + +lemma array_law_eq_of_blocks {K : Type*} [MeasurableSpace K] + (μ ν : Measure (CompactArray K)) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (h : ∀ n, μ.map (compactBlock (n+1)) = ν.map (compactBlock (n+1))) : μ = ν := by + let e : CompactArray K ≃ᵐ (ℕ × ℕ → K) := (MeasurableEquiv.curry ℕ ℕ K).symm + apply e.map_measurableEquiv_injective + let P (I : Finset (ℕ × ℕ)) := (ν.map e).map I.restrict + have hp : IsProjectiveLimit (ν.map e) P := fun _ => rfl + apply IsProjectiveLimit.unique (P := P) ?_ hp + intro I + let n := I.sup (fun a => max a.1 a.2) + have hb (a : I) : a.val.1 < n+1 ∧ a.val.2 < n+1 := by + have he : max a.val.1 a.val.2 ≤ n := Finset.le_sup (f := fun a : ℕ × ℕ => max a.1 a.2) a.property + exact ⟨by omega,by omega⟩ + let G : CompactBlock K (n+1) → (I → K) := + fun B a => B ⟨a.val.1,(hb a).1⟩ ⟨a.val.2,(hb a).2⟩ + have hG : Measurable G := by + apply Measurable.of_eval + intro a + exact (measurable_pi_apply _).comp (measurable_pi_apply _) + have hm : Measurable (compactBlock (K:=K) (n+1)) := by + unfold compactBlock + exact Measurable.of_eval fun _ => Measurable.of_eval fun _ => by fun_prop + change (μ.map e).map I.restrict = (ν.map e).map I.restrict + have he : I.restrict ∘ e = G ∘ compactBlock (n+1) := by + funext Q a + rfl + rw [Measure.map_map I.measurable_restrict e.measurable, + Measure.map_map I.measurable_restrict e.measurable,he, + ← Measure.map_map hG hm,← Measure.map_map hG hm,h n] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/ArrayLimitGeometry.lean b/lean/OAI/Probability/Perceptron/Interpolation/ArrayLimitGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..420024709c8d62382abe0b92295b635b72781309 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/ArrayLimitGeometry.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ArrayGeometry + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set TopologicalSpace Matrix +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma sourceGibbsArray_closed_full (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) + {F : Set (CompactArray CompactJointOverlap)} (hF : IsClosed F) + (hfull : ∀ x : ℕ→NormalizedSpin (n+1)×IndexedLeaf k, sourceJointArray x ∈ F) : + sourceGibbsArrayLaw n k f p d h u z t F=1 := by + have hp : (fun a : (SourceBaseData n k × (ℕ→ℝ)) × + (ℕ → NormalizedSpin (n+1) × IndexedLeaf k) => sourceJointArray a.2) ⁻¹' F=univ := by + ext a + simp only [mem_preimage,mem_univ,iff_true] + exact hfull a.2 + apply ENNReal.coe_injective + rw [ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure] + change (Measure.map (fun a : (SourceBaseData n k × (ℕ→ℝ)) × + (ℕ → NormalizedSpin (n+1) × IndexedLeaf k) => sourceJointArray a.2) _) F=1 + rw [Measure.map_apply (show Measurable (fun a : (SourceBaseData n k × (ℕ→ℝ)) × + (ℕ → NormalizedSpin (n+1) × IndexedLeaf k) => sourceJointArray a.2) from + (sourceJointArray_measurable (n+1) k).comp measurable_snd) hF.measurableSet,hp] + exact measure_univ + +lemma compact_spin_gram_closed (r : ℕ) : + IsClosed {Q : CompactArray CompactJointOverlap | Matrix.PosSemidef (fun i j : Fin r => (Q i j).1.val)} := + (isClosed_matrix_posSemidef r).preimage (by fun_prop) + +lemma compact_tree_gram_closed (r : ℕ) : + IsClosed {Q : CompactArray CompactJointOverlap | Matrix.PosSemidef (fun i j : Fin r => (Q i j).2.val)} := + (isClosed_matrix_posSemidef r).preimage (by fun_prop) + +lemma sourceGibbsArray_limit_gram (k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : (n : ℕ) → Fin (n+1) → ℕ) (h : ℕ → Fin (k+1) → ℝ) + (u : (n : ℕ) → Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℕ → ℝ≥0) + (s : ℕ→ℕ) {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + (∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), ∀ r, Matrix.PosSemidef (fun i j : Fin r => (Q i j).1.val)) ∧ + (∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), ∀ r, Matrix.PosSemidef (fun i j : Fin r => (Q i j).2.val)) := by + constructor + · rw [ae_all_iff] + intro r + apply (mem_ae_iff_prob_eq_one (compact_spin_gram_closed r).measurableSet).mpr + have hv := weak_limit_closed_full hlim (compact_spin_gram_closed r) + (fun n => sourceGibbsArray_closed_full (s n) k f (p (s n)) (d (s n)) (h (s n)) (u (s n)) z (t (s n)) + (compact_spin_gram_closed r) (fun x => sourceSpinArray_posSemidef x r)) + simp only [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + · rw [ae_all_iff] + intro r + apply (mem_ae_iff_prob_eq_one (compact_tree_gram_closed r).measurableSet).mpr + have hv := weak_limit_closed_full hlim (compact_tree_gram_closed r) + (fun n => sourceGibbsArray_closed_full (s n) k f (p (s n)) (d (s n)) (h (s n)) (u (s n)) z (t (s n)) + (compact_tree_gram_closed r) (fun x => sourceTreeArray_posSemidef x r)) + simp only [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/ArrayTangentConsistency.lean b/lean/OAI/Probability/Perceptron/Interpolation/ArrayTangentConsistency.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d7feba30ff7ffc87a361a7ef4be36ed959a4b79 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/ArrayTangentConsistency.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ArrayGeometry +import OAI.Probability.Perceptron.Variational.TangentConsistency + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set TopologicalSpace +open scoped NNReal BoundedContinuousFunction ContDiff +namespace SphericalPerceptronFreeEnergy + +lemma compact_other_edge_law {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [MetrizableSpace K] [SecondCountableTopology K] + (μ : ProbabilityMeasure (CompactArray K)) + (hGG : ∀ (F : CompactBlock K 2→ᵇℝ) (g : K→ᵇℝ),compactGGDefect μ 2 0 F g=0) + (he : MeasurePreserving (compactRelabel (K:=K) (Equiv.swap 0 1)) (μ : Measure _) (μ : Measure _)) + (hsy : ∀ᵐ Q ∂(μ : Measure (CompactArray K)),Q 1 0=Q 0 1) : + (μ : Measure (CompactArray K)).map (fun Q=>(Q 0 1,Q 1 2))= + (1/2:ℝ≥0) • (((μ : Measure (CompactArray K)).map (fun Q=>Q 0 1)).prod + ((μ : Measure (CompactArray K)).map (fun Q=>Q 0 1)))+ + (1/2:ℝ≥0) • ((μ : Measure (CompactArray K)).map (fun Q=>(Q 0 1,Q 0 1))) := by + have h := congrArg (Measure.map (fun Q : CompactArray K=>(Q 0 1,Q 0 2))) he.map_eq + rw [Measure.map_map (by fun_prop) he.measurable] at h + have h' : (μ : Measure (CompactArray K)).map (fun Q=>(Q 1 0,Q 1 2))= + (μ : Measure (CompactArray K)).map (fun Q=>(Q 0 1,Q 0 2)) := by + simpa [Function.comp_def,compactRelabel,Equiv.swap_apply_def] using h + have hm : (μ : Measure (CompactArray K)).map (fun Q=>(Q 1 0,Q 1 2))= + (μ : Measure (CompactArray K)).map (fun Q=>(Q 0 1,Q 1 2)) := + Measure.map_congr (hsy.mono (fun Q hQ=>by dsimp only; rw [hQ])) + rw [←hm,h',compact_two_edge_law μ hGG] + +lemma array_tangent_self_consistency (μ : ProbabilityMeasure (CompactArray Time)) + (hGG : ∀ (F : CompactBlock Time 2→ᵇℝ) (g : Time→ᵇℝ),compactGGDefect μ 2 0 F g=0) + (he : MeasurePreserving (compactRelabel (K:=Time) (Equiv.swap 0 1)) (μ : Measure _) (μ : Measure _)) + (hsy : ∀ᵐ Q ∂(μ : Measure (CompactArray Time)),∀ i j,Q i j=Q j i) + (hul : ∀ᵐ Q ∂(μ : Measure (CompactArray Time)),∀ i j k,min (Q i j:ℝ) (Q i k:ℝ)≤(Q j k:ℝ)) + (a : Time→ℝ) (ha : Measurable a) {A : ℝ} (hA : 0≤A) (hab : ∀ x,0≤a x ∧ a x≤A) + (hT : ∀ G : ℝ→ᵇℝ,ContDiff ℝ 1 (G : ℝ→ℝ)→ + (∫ Q : CompactArray Time,G (Q 0 1)*((Q 0 1:ℝ)-a (Q 0 1)*(1-(Q 0 1:ℝ)^2)+ + 2*a (Q 0 2)*((Q 1 2:ℝ)-(Q 0 1:ℝ)*(Q 0 2:ℝ))) ∂(μ : Measure _))=0) : + (∀ᵐ x : Time ∂((μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1)), + a x=∫ y in 0..(x:ℝ),(realTail ((μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1)) y)⁻¹^2) ∧ + ∀ᵐ x : Time ∂((μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1)),(x:ℝ)≤A/(1+A) := by + let ν := (μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1) + have : IsProbabilityMeasure ν := by dsimp [ν]; infer_instance + have hd : ν.map (fun x=>(x,x))=(μ : Measure (CompactArray Time)).map (fun Q=>(Q 0 1,Q 0 1)) := by + change ((μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1)).map (fun x=>(x,x))=_ + rw [Measure.map_map (by fun_prop) (by fun_prop)] + rfl + apply tangent_sphere_self_consistency (μ : Measure (CompactArray Time)) ν (fun Q=>Q 0 1) (fun Q=>Q 0 2) (fun Q=>Q 1 2) + (by fun_prop) (by fun_prop) (by fun_prop) rfl + (by rw [hd]; exact compact_two_edge_law μ hGG) + (by rw [hd]; exact compact_other_edge_law μ hGG he (hsy.mono (fun Q hQ=>hQ 1 0))) + _ a ha hA hab hT + filter_upwards [hsy,hul] with Q hS hU + refine ⟨hU 0 1 2,?_,?_⟩ + · have h := hU 1 0 2 + simpa only [hS 1 0] using h + · have h := hU 2 0 1 + simpa only [hS 2 0,hS 2 1] using h + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/CompactArrayMap.lean b/lean/OAI/Probability/Perceptron/Interpolation/CompactArrayMap.lean new file mode 100644 index 0000000000000000000000000000000000000000..ff845a3e795c50174ca69c9ab3443c283030910f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/CompactArrayMap.lean @@ -0,0 +1,147 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CovarianceMatrix + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +variable {K L : Type*} [TopologicalSpace K] [TopologicalSpace L] + +def compactMapArray (e : K→L) (Q : CompactArray K) : CompactArray L := fun i j => e (Q i j) +def compactMapBlock (e : K→L) (n : ℕ) (Q : CompactBlock K n) : CompactBlock L n := fun i j => e (Q i j) + +lemma compactMapArray_continuous {e : K→L} (he : Continuous e) : Continuous (compactMapArray e) := by + unfold compactMapArray + fun_prop +lemma compactMapBlock_continuous {e : K→L} (he : Continuous e) (n : ℕ) : + Continuous (compactMapBlock e n) := by + unfold compactMapBlock + fun_prop + +def compactDiagonalMapArray (e d : K→L) (Q : CompactArray K) : CompactArray L := + fun i j => if i=j then d (Q i j) else e (Q i j) +def compactDiagonalMapBlock (e d : K→L) (n : ℕ) (Q : CompactBlock K n) : CompactBlock L n := + fun i j => if i=j then d (Q i j) else e (Q i j) + +lemma compactDiagonalMapArray_continuous {e d : K→L} (he : Continuous e) (hd : Continuous d) : + Continuous (compactDiagonalMapArray e d) := by + apply continuous_pi; intro i; apply continuous_pi; intro j + unfold compactDiagonalMapArray + split_ifs <;> fun_prop +lemma compactDiagonalMapBlock_continuous {e d : K→L} (he : Continuous e) (hd : Continuous d) (n : ℕ) : + Continuous (compactDiagonalMapBlock e d n) := by + apply continuous_pi; intro i; apply continuous_pi; intro j + unfold compactDiagonalMapBlock + split_ifs <;> fun_prop + +omit [TopologicalSpace K] [TopologicalSpace L] in +lemma compactDiagonalMapBlock_compactBlock (e d : K→L) (n : ℕ) (Q : CompactArray K) : + compactBlock n (compactDiagonalMapArray e d Q)=compactDiagonalMapBlock e d n (compactBlock n Q) := by + funext i j + simp only [compactBlock,compactDiagonalMapArray,compactDiagonalMapBlock,Fin.val_inj] + + +variable [MeasurableSpace K] [MeasurableSpace L] [BorelSpace K] [BorelSpace L] + [SecondCountableTopology K] [SecondCountableTopology L] + +def compactMapLaw (e : K→L) (he : Continuous e) (μ : ProbabilityMeasure (CompactArray K)) : + ProbabilityMeasure (CompactArray L) := + ⟨(μ : Measure (CompactArray K)).map (compactMapArray e), + (Measure.isProbabilityMeasure_map_iff (compactMapArray_continuous he).measurable.aemeasurable).2 + inferInstance⟩ + +lemma compactMapLaw_integral (e : K→L) (he : Continuous e) (μ : ProbabilityMeasure (CompactArray K)) + (F : CompactArray L→ℝ) (hF : Measurable F) : + (∫ Q, F Q ∂(compactMapLaw e he μ : Measure (CompactArray L)))= + ∫ Q, F (compactMapArray e Q) ∂(μ : Measure (CompactArray K)) := + integral_map (compactMapArray_continuous he).measurable.aemeasurable hF.aestronglyMeasurable + +lemma compactMapLaw_gg (e : K→L) (he : Continuous e) (μ : ProbabilityMeasure (CompactArray K)) + (hGG : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock K n →ᵇ ℝ) (g : K →ᵇ ℝ), + compactGGDefect μ n i f g=0) (n : ℕ) (i : Fin n) + (f : CompactBlock L n →ᵇ ℝ) (g : L →ᵇ ℝ) : + compactGGDefect (compactMapLaw e he μ) n i f g=0 := by + let f' := f.compContinuous ⟨compactMapBlock e n,compactMapBlock_continuous he n⟩ + let g' := g.compContinuous ⟨e,he⟩ + have hmul (a b : ℕ) : + (∫ Q, f (compactBlock n Q)*g (Q a b) ∂(compactMapLaw e he μ : Measure (CompactArray L)))= + ∫ Q, f' (compactBlock n Q)*g' (Q a b) ∂(μ : Measure (CompactArray K)) := by + exact compactMapLaw_integral e he μ _ + ((f.measurable.comp (compactBlock_continuous n).measurable).mul (g.measurable.comp (by fun_prop))) + have hf : (∫ Q, f (compactBlock n Q) ∂(compactMapLaw e he μ : Measure (CompactArray L)))= + ∫ Q, f' (compactBlock n Q) ∂(μ : Measure (CompactArray K)) := by + exact compactMapLaw_integral e he μ _ + (f.measurable.comp (compactBlock_continuous n).measurable) + have hg : (∫ Q, g (Q 0 1) ∂(compactMapLaw e he μ : Measure (CompactArray L)))= + ∫ Q, g' (Q 0 1) ∂(μ : Measure (CompactArray K)) := by + exact compactMapLaw_integral e he μ _ (by fun_prop) + unfold compactGGDefect + simp_rw [hmul,hf,hg] + exact hGG n i f' g' + +lemma compactMapLaw_pair (e : K→L) (he : Continuous e) (μ : ProbabilityMeasure (CompactArray K)) + (a b : ℕ) : + (compactMapLaw e he μ : Measure (CompactArray L)).map (fun Q => Q a b)= + ((μ : Measure (CompactArray K)).map (fun Q => Q a b)).map e := by + change ((μ : Measure (CompactArray K)).map (compactMapArray e)).map (fun Q => Q a b)=_ + rw [Measure.map_map (by fun_prop) (compactMapArray_continuous he).measurable, + Measure.map_map he.measurable (by fun_prop)] + rfl + +def compactDiagonalMapLaw (e d : K→L) (he : Continuous e) (hd : Continuous d) + (μ : ProbabilityMeasure (CompactArray K)) : ProbabilityMeasure (CompactArray L) := + ⟨(μ : Measure (CompactArray K)).map (compactDiagonalMapArray e d), + (Measure.isProbabilityMeasure_map_iff + (compactDiagonalMapArray_continuous he hd).measurable.aemeasurable).2 inferInstance⟩ + +lemma compactDiagonalMapLaw_integral (e d : K→L) (he : Continuous e) (hd : Continuous d) + (μ : ProbabilityMeasure (CompactArray K)) (F : CompactArray L→ℝ) (hF : Measurable F) : + (∫ Q, F Q ∂(compactDiagonalMapLaw e d he hd μ : Measure (CompactArray L)))= + ∫ Q, F (compactDiagonalMapArray e d Q) ∂(μ : Measure (CompactArray K)) := + integral_map (compactDiagonalMapArray_continuous he hd).measurable.aemeasurable hF.aestronglyMeasurable + +lemma compactDiagonalMapLaw_gg (e d : K→L) (he : Continuous e) (hd : Continuous d) + (μ : ProbabilityMeasure (CompactArray K)) + (hGG : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock K n →ᵇ ℝ) (g : K →ᵇ ℝ), + compactGGDefect μ n i f g=0) (n : ℕ) (i : Fin n) + (f : CompactBlock L n →ᵇ ℝ) (g : L →ᵇ ℝ) : + compactGGDefect (compactDiagonalMapLaw e d he hd μ) n i f g=0 := by + let f' := f.compContinuous ⟨compactDiagonalMapBlock e d n,compactDiagonalMapBlock_continuous he hd n⟩ + let g' := g.compContinuous ⟨e,he⟩ + have hmul (a b : ℕ) (hab : a≠b) : + (∫ Q, f (compactBlock n Q)*g (Q a b) ∂(compactDiagonalMapLaw e d he hd μ : Measure (CompactArray L)))= + ∫ Q, f' (compactBlock n Q)*g' (Q a b) ∂(μ : Measure (CompactArray K)) := by + rw [compactDiagonalMapLaw_integral e d he hd μ (fun Q => f (compactBlock n Q)*g (Q a b)) + ((f.measurable.comp (compactBlock_continuous n).measurable).mul (g.measurable.comp (by fun_prop)))] + simp only [compactDiagonalMapBlock_compactBlock,compactDiagonalMapArray,ite_eq_right hab] + rfl + have hf : (∫ Q, f (compactBlock n Q) ∂(compactDiagonalMapLaw e d he hd μ : Measure (CompactArray L)))= + ∫ Q, f' (compactBlock n Q) ∂(μ : Measure (CompactArray K)) := by + rw [compactDiagonalMapLaw_integral e d he hd μ (fun Q => f (compactBlock n Q)) + (f.measurable.comp (compactBlock_continuous n).measurable)] + simp only [compactDiagonalMapBlock_compactBlock] + rfl + have hg : (∫ Q, g (Q 0 1) ∂(compactDiagonalMapLaw e d he hd μ : Measure (CompactArray L)))= + ∫ Q, g' (Q 0 1) ∂(μ : Measure (CompactArray K)) := by + rw [compactDiagonalMapLaw_integral e d he hd μ (fun Q => g (Q 0 1)) (by fun_prop)] + rfl + unfold compactGGDefect + rw [hmul i.val n (Nat.ne_of_lt i.isLt),hf,hg] + have hs : (∑ j ∈ Finset.univ.erase i, ∫ Q, f (compactBlock n Q)*g (Q i j) + ∂(compactDiagonalMapLaw e d he hd μ : Measure (CompactArray L)))= + ∑ j ∈ Finset.univ.erase i, ∫ Q, f' (compactBlock n Q)*g' (Q i j) + ∂(μ : Measure (CompactArray K)) := by + apply Finset.sum_congr rfl + intro j hj + apply hmul + intro hij + exact (Finset.mem_erase.mp hj).1 (Fin.ext hij.symm) + rw [hs] + exact hGG n i f' g' +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/CountableGaussianReplicaIBP.lean b/lean/OAI/Probability/Perceptron/Interpolation/CountableGaussianReplicaIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..b50064af7163ef716ee4ae63569e2008a336f881 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/CountableGaussianReplicaIBP.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.GaussianHamiltonianCoordinates +import OAI.Probability.Perceptron.Variational.CountableGaussianIBP + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma countableGaussian_replica_coordinate_ibp (i n : ℕ) + {H : (ℕ → ℝ) → S → ℝ} {v : S → ℝ} {G : (Fin n → S) → ℝ} + (hH : Measurable (Function.uncurry H)) (hv : Measurable v) (hG : Measurable G) + {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hGD : ∀ x, |G x| ≤ D) + (haff : ∀ g t x, H (Function.update g i t) x = H (Function.update g i 0) x+t*v x) + (hi : ∀ᵐ g ∂countableGaussianLaw, Integrable (fun x => Real.exp (H g x)) μ) : + (∫ g, g i*gibbsReplicaMean μ (H g) n G ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean μ (H g) n (fun x => replicaPotential v n x*G x)- + n*gibbsReplicaMean μ (H g) (n+1) (fun x => v (x 0)*G (fun l => x l.succ)) + ∂countableGaussianLaw := by + let Hr (g : ℕ → ℝ) := replicaPotential (H g) n + have hHr : Measurable (Function.uncurry Hr) := by + change Measurable (fun p : (ℕ → ℝ)×(Fin n → S) => ∑ l, H p.1 (p.2 l)) + exact Finset.measurable_sum _ fun l _ => hH.comp + (measurable_fst.prodMk ((measurable_pi_apply l).comp measurable_snd)) + have hvr := replicaPotential_measurable hv n + have hir : ∀ᵐ g ∂countableGaussianLaw, Integrable (fun x => Real.exp (Hr g x)) + (Measure.pi fun _ : Fin n => μ) := by + filter_upwards [hi] with g hg + simpa only [one_mul] using replica_exp_integrable μ (by simpa only [one_mul] using hg : + Integrable (fun x => Real.exp (1*H g x)) μ) n + have haffr (g : ℕ → ℝ) (t : ℝ) (x : Fin n → S) : + Hr (Function.update g i t) x = Hr (Function.update g i 0) x+t*replicaPotential v n x := by + calc + _ = ∑ l, (H (Function.update g i 0) (x l)+t*v (x l)) := + Finset.sum_congr rfl (fun l _ => haff g t (x l)) + _ = _ := by simp only [Hr,replicaPotential,Finset.sum_add_distrib,Finset.mul_sum] + have hh := countableGaussian_coordinate_tilt_ibp_of_exp_integrable + (Measure.pi fun _ : Fin n => μ) i hHr hvr hG (mul_nonneg (Nat.cast_nonneg n) hC) hD + (replicaPotential_bound hvC n) hGD haffr hir + change (∫ g, g i*gibbsReplicaMean μ (H g) n G ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean μ (H g) n (fun x => replicaPotential v n x*G x)- + gibbsReplicaMean μ (H g) n G*gibbsReplicaMean μ (H g) n (replicaPotential v n) + ∂countableGaussianLaw at hh + refine hh.trans ?_ + apply integral_congr_ae + filter_upwards [hi] with g hg + have hHg : Measurable (H g) := hH.comp (measurable_const.prodMk measurable_id) + rw [gibbsReplicaMean_potential_of_integrable μ hHg hv hg hvC, + gibbsReplicaMean_product_of_integrable μ hHg hv hG hg hvC hGD] + ring + +lemma gaussianHamiltonian_replica_coordinate_ibp (i n : ℕ) + {W : S → ℝ} {v : ℕ → S → ℝ} {L : S → ℕ} {G : (Fin n → S) → ℝ} + (hW : Measurable W) (hv : ∀ j, Measurable (v j)) (hL : Measurable L) (hG : Measurable G) + {A D B : ℝ} (hA : ∀ x, |W x| ≤ A) + (hD : ∀ x, (∑ j : Fin (L x), v j.val x^2) ≤ D) + (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + let H := countableGaussianHamiltonian W v L + let a := maskedGaussianCoefficient v L i + (∫ g, g i*gibbsReplicaMean μ (H g) n G ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean μ (H g) n (fun x => replicaPotential a n x*G x)- + n*gibbsReplicaMean μ (H g) (n+1) (fun x => a (x 0)*G (fun l => x l.succ)) + ∂countableGaussianLaw := by + dsimp only + apply countableGaussian_replica_coordinate_ibp μ i n + (countableGaussianHamiltonian_measurable hW hv hL) + (maskedGaussianCoefficient_measurable hv hL i) hG (Real.sqrt_nonneg D) hB + (maskedGaussianCoefficient_bound v L hD i) hGB + (fun g t x => countableGaussianHamiltonian_update W v L g i t x) + simpa only [one_mul] using + (countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).prod_left_ae + +lemma integrable_tiltLaw_of_weighted {H F : S → ℝ} (hH : Measurable H) + (he : Integrable (fun x => Real.exp (H x)) μ) + (hF : Integrable (fun x => Real.exp (H x)*F x) μ) : Integrable F (tiltLaw μ H 1) := by + have hp := tilt_partition_pos_of_integrable μ (by simpa only [one_mul] using he : + Integrable (fun x => Real.exp (1*H x)) μ) + unfold tiltLaw + apply Integrable.smul_measure _ (ENNReal.inv_ne_top.mpr (ne_of_gt (ENNReal.ofReal_pos.mpr hp))) + apply (integrable_withDensity_iff_integrable_smul' (hH.const_mul 1).exp.ennreal_ofReal + (ae_of_all _ fun _ => ENNReal.ofReal_lt_top)).mpr + simpa only [one_mul,ENNReal.toReal_ofReal (Real.exp_pos _).le,smul_eq_mul] using hF + +lemma replicaMean_varying_measurable {Ω : Type*} [MeasurableSpace Ω] {H : Ω → S → ℝ} + {n : ℕ} {F : Ω → (Fin n → S) → ℝ} (hH : Measurable (Function.uncurry H)) + (hF : Measurable (Function.uncurry F)) : + Measurable (fun g => gibbsReplicaMean μ (H g) n (F g)) := by + have hr : Measurable (fun p : Ω×(Fin n → S) => Real.exp (replicaPotential (H p.1) n p.2)) := by + apply Measurable.exp + exact Finset.measurable_sum _ fun i _ => hH.comp + (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd)) + let ρ := Measure.pi fun _ : Fin n => μ + have hn : Measurable (fun g => ∫ x, Real.exp (replicaPotential (H g) n x)*F g x ∂ρ) := + (hr.mul hF).stronglyMeasurable.integral_prod_right'.measurable + have hd : Measurable (fun g => ∫ x, Real.exp (replicaPotential (H g) n x) ∂ρ) := + hr.stronglyMeasurable.integral_prod_right'.measurable + unfold gibbsReplicaMean tiltMean tiltIntegral tiltPartition + simp only [one_mul] + convert hn.div hd using 1 + +lemma replicaMean_energy_bound {H F : S → ℝ} {n : ℕ} (j : Fin n) + {G : (Fin n → S) → ℝ} (hH : Measurable H) (hF : Measurable F) (hG : Measurable G) + (he : Integrable (fun x => Real.exp (H x)) μ) + (hFint : Integrable (fun x => Real.exp (H x)*F x) μ) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + |gibbsReplicaMean μ H n (fun x => F (x j)*G x)| ≤ B*tiltMean μ H (fun x => |F x|) 1 := by + have he1 : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using he + let := tilt_law_probability_of_integrable μ he1 + let θ := tiltLaw μ H 1 + let ρ := Measure.pi fun _ : Fin n => θ + have hFi : Integrable F θ := integrable_tiltLaw_of_weighted μ hH he hFint + have hcoord : Integrable (fun x : Fin n → S => F (x j)) ρ := + (measurePreserving_eval (fun _ : Fin n => θ) j).integrable_comp_of_integrable hFi + have hprod : Integrable (fun x : Fin n → S => F (x j)*G x) ρ := by + apply (hcoord.abs.const_mul B).mono' ((hF.comp (measurable_pi_apply j)).mul hG).aestronglyMeasurable + exact ae_of_all _ fun x => by + change |F (x j)*G x| ≤ B*|F (x j)| + rw [abs_mul,mul_comm |F (x j)|] + exact mul_le_mul (hGB x) le_rfl (abs_nonneg _) hB + rw [gibbsReplicaMean_integral_of_integrable μ hH he] + calc + _ ≤ ∫ x : Fin n → S, |F (x j)*G x| ∂ρ := by + simpa only [Real.norm_eq_abs] using norm_integral_le_integral_norm (μ := ρ) (fun x : Fin n → S => F (x j)*G x) + _ ≤ ∫ x : Fin n → S, B*|F (x j)| ∂ρ := by + apply integral_mono hprod.abs (hcoord.abs.const_mul B) + intro x + change |F (x j)*G x| ≤ B*|F (x j)| + rw [abs_mul] + nlinarith [mul_le_mul_of_nonneg_left (hGB x) (abs_nonneg (F (x j)))] + _ = _ := by + rw [integral_const_mul] + congr 1 + rw [← gibbsReplicaMean_coordinate_of_integrable μ hH hF.abs he n j, + gibbsReplicaMean_integral_of_integrable μ hH he] + +lemma replicaMean_energy_sub {H F Q : S → ℝ} {n : ℕ} (j : Fin n) + {G : (Fin n → S) → ℝ} (hH : Measurable H) (hF : Measurable F) (hQ : Measurable Q) (hG : Measurable G) + (he : Integrable (fun x => Real.exp (H x)) μ) + (hFint : Integrable (fun x => Real.exp (H x)*F x) μ) + (hQint : Integrable (fun x => Real.exp (H x)*Q x) μ) + {B : ℝ} (hGB : ∀ x, |G x| ≤ B) : + gibbsReplicaMean μ H n (fun x => (F (x j)-Q (x j))*G x) = + gibbsReplicaMean μ H n (fun x => F (x j)*G x)-gibbsReplicaMean μ H n (fun x => Q (x j)*G x) := by + have he1 : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using he + let := tilt_law_probability_of_integrable μ he1 + let θ := tiltLaw μ H 1 + let ρ := Measure.pi fun _ : Fin n => θ + have him (f : S → ℝ) (hf : Measurable f) (hfi : Integrable (fun x => Real.exp (H x)*f x) μ) : + Integrable (fun x : Fin n → S => f (x j)*G x) ρ := by + have hc := (measurePreserving_eval (fun _ : Fin n => θ) j).integrable_comp_of_integrable + (integrable_tiltLaw_of_weighted μ hH he hfi) + apply (hc.abs.const_mul B).mono' ((hf.comp (measurable_pi_apply j)).mul hG).aestronglyMeasurable + exact ae_of_all _ fun x => by + change |f (x j)*G x| ≤ B*|f (x j)| + rw [abs_mul] + nlinarith [mul_le_mul_of_nonneg_left (hGB x) (abs_nonneg (f (x j)))] + simp_rw [gibbsReplicaMean_integral_of_integrable μ hH he,sub_mul] + exact integral_sub (him F hF hFint) (him Q hQ hQint) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/FieldArray.lean b/lean/OAI/Probability/Perceptron/Interpolation/FieldArray.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f094d57e72276f9e722a3491c2cf7136fc30c61 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/FieldArray.lean @@ -0,0 +1,57 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FieldDerivative + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def sourceFieldPolynomial {k : ℕ} (a : Fin (k+1)→ℝ) : Polynomial ℝ := + Lagrange.interpolate Finset.univ (fun l : Fin (k+1) => (l.val:ℝ)/(k+1:ℕ)) a + +lemma sourceFieldPolynomial_eval {k : ℕ} (a : Fin (k+1)→ℝ) (l : Fin (k+1)) : + (sourceFieldPolynomial a).eval ((l.val:ℝ)/(k+1:ℕ))=a l := by + unfold sourceFieldPolynomial + apply Lagrange.eval_interpolate_at_node (s := Finset.univ) + (v := fun l : Fin (k+1) => (l.val:ℝ)/(k+1:ℕ)) (i := l) a + · intro i hi j hj he + apply Fin.ext + have hv : (i.val:ℝ)=(j.val:ℝ) := (div_left_inj' (by positivity : ((k+1:ℕ):ℝ)≠0)).mp he + exact_mod_cast hv + · exact Finset.mem_univ l + +lemma sourceFieldPolynomial_continuous {k : ℕ} (a : Fin (k+1)→ℝ) : + Continuous (fun t : unitInterval => (sourceFieldPolynomial a).eval t.val) := + (sourceFieldPolynomial a).continuous.comp continuous_subtype_val + +def sourceFieldArrayTest {k : ℕ} (a : Fin (k+1)→ℝ) : CompactArray CompactJointOverlap→ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun Q => (sourceFieldPolynomial a).eval (Q 1 0).2.val*(Q 1 0).1.val, + by fun_prop⟩ + +lemma sourceGibbsArray_field_integral (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (hh0 : ∀ l, 0≤h l) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℝ≥0) (a : Fin (k+1)→ℝ) : + (∫ Q, sourceFieldArrayTest a Q ∂sourceGibbsArrayLaw n k f p d h u z t)= + ∫ b, gibbsReplicaMean (sourceSpinLeafKernel n k b.1) + (sourceCouplingHamiltonian n k f p d h u b) 2 (sourceFieldObservable a) + ∂((sourceBaseDataLaw n k z t).prod countableGaussianLaw) := by + let F : CompactBlock CompactJointOverlap 2→ᵇ ℝ := BoundedContinuousFunction.mkOfCompact + ⟨fun Q => (sourceFieldPolynomial a).eval (Q 1 0).2.val*(Q 1 0).1.val,by fun_prop⟩ + have he := sourceGibbsArray_block_integral n k f p d h hh0 hh u z t 2 F.measurable + (fun Q => F.norm_coe_le_norm Q) + change (∫ Q, sourceFieldArrayTest a Q ∂sourceGibbsArrayLaw n k f p d h u z t)=_ at he + rw [he] + apply integral_congr_ae + exact ae_of_all _ fun b => by + change gibbsReplicaMean (sourceSpinLeafKernel n k b.1) _ 2 _ = _ + congr 1 + funext x + dsimp [F,sourceJointOverlap,sourceFieldObservable] + rw [sourceFieldPolynomial_eval] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/FiniteOverlap.lean b/lean/OAI/Probability/Perceptron/Interpolation/FiniteOverlap.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8fec7ed011b31a781beb35432f3f75b2e12e8d3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/FiniteOverlap.lean @@ -0,0 +1,413 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma ultrametric_extension_row {ι L : Type*} [LinearOrder L] + (A : ι → ι → L) (v : ι → L) (i : ι) + (hmax : ∀ j, v j ≤ v i) + (hlo : ∀ j, min (v i) (A i j) ≤ v j) + (hhi : ∀ j, min (v i) (v j) ≤ A i j) : + ∀ j, v j = min (v i) (A i j) := by + intro j + apply le_antisymm + · apply le_min (hmax j) + simpa only [min_eq_right (hmax j)] using hhi j + · exact hlo j + +lemma finite_measure_eq_of_maximal_coordinates + {ι L : Type*} [Fintype ι] [Nonempty ι] [Fintype L] [LinearOrder L] + [MeasurableSpace L] [MeasurableSingletonClass L] + (μ ν : Measure (ι → L)) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (S : Set (ι → L)) (hμ : ∀ᵐ v ∂μ, v ∈ S) (hν : ∀ᵐ v ∂ν, v ∈ S) + (htri : ∀ v ∈ S, ∀ i, (∀ j, v j ≤ v i) → ∀ w ∈ S, + w i = v i → (∀ j, w j ≤ v i) → w = v) + (hcoord : ∀ i c, μ.real {v | v i = c} = ν.real {v | v i = c}) : μ = ν := by + classical + have hout (v : ι → L) (hv : v ∉ S) : μ.real {v} = 0 ∧ ν.real {v} = 0 := by + have he (ρ : Measure (ι → L)) (hρ : ∀ᵐ w ∂ρ, w ∈ S) : ρ {v} = 0 := + measure_mono_null (by simpa using hv) (ae_iff.mp hρ) + simp only [measureReal_def,he μ hμ,he ν hν,ENNReal.toReal_zero,and_self] + have hmass : ∀ v : ι → L, μ.real {v} = ν.real {v} := by + by_contra h + have hex : ∃ v : ι → L, μ.real {v} ≠ ν.real {v} := by simpa only [not_forall] using h + let D : Finset (ι → L) := Finset.univ.filter fun v => μ.real {v} ≠ ν.real {v} + have hD : D.Nonempty := by obtain ⟨v,hv⟩ := hex; exact ⟨v,by simp [D,hv]⟩ + let M (v : ι → L) : L := (Finset.univ.image v).max' (Finset.univ_nonempty.image v) + have hbound (v : ι → L) (i : ι) : v i ≤ M v := + Finset.le_max' _ _ (Finset.mem_image.mpr ⟨i,Finset.mem_univ _,rfl⟩) + obtain ⟨v,hv,hvmax⟩ := D.exists_max_image M hD + have hvneq : μ.real {v} ≠ ν.real {v} := (Finset.mem_filter.mp hv).2 + have hvS : v ∈ S := by by_contra hh; exact hvneq (by rw [(hout v hh).1,(hout v hh).2]) + obtain ⟨i,_,hi⟩ := Finset.mem_image.mp (Finset.max'_mem (Finset.univ.image v) (Finset.univ_nonempty.image v)) + change v i = M v at hi + have hpivot : ∀ j, v j ≤ v i := fun j => (hbound v j).trans_eq hi.symm + have hother (w : ι → L) (hwi : w i = v i) (hwv : w ≠ v) : μ.real {w} = ν.real {w} := by + by_contra hw + have hwD : w ∈ D := by simp [D,hw] + have hwS : w ∈ S := by by_contra hh; exact hw (by rw [(hout w hh).1,(hout w hh).2]) + apply hwv + apply htri v hvS i hpivot w hwS hwi + intro j + exact ((hbound w j).trans (hvmax w hwD)).trans_eq hi.symm + let T : Finset (ι → L) := Finset.univ.filter fun w => w i = v i + have hvT : v ∈ T := by simp [T] + have hT : (T : Set (ι → L)) = {w | w i = v i} := by ext w; simp [T] + have he := hcoord i (v i) + rw [← hT,← sum_measureReal_singleton,← sum_measureReal_singleton] at he + rw [← Finset.sum_erase_add _ _ hvT,← Finset.sum_erase_add _ _ hvT] at he + have hs : (∑ w ∈ T.erase v, μ.real {w}) = ∑ w ∈ T.erase v, ν.real {w} := by + apply Finset.sum_congr rfl + intro w hw + exact hother w (by simpa [T] using (Finset.mem_erase.mp hw).2) (Finset.mem_erase.mp hw).1 + rw [hs] at he + exact hvneq (add_left_cancel he) + exact Measure.ext_of_singleton fun v => + (ENNReal.toReal_eq_toReal_iff' (measure_ne_top μ _) (measure_ne_top ν _)).mp (hmass v) + +lemma finite_ultrametric_row_law_unique + {ι L : Type*} [Fintype ι] [Nonempty ι] [Fintype L] [LinearOrder L] + [MeasurableSpace L] [MeasurableSingletonClass L] + (A : ι → ι → L) (μ ν : Measure (ι → L)) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (hμ : ∀ᵐ v ∂μ, ∀ i j, min (v i) (A i j) ≤ v j ∧ min (v i) (v j) ≤ A i j) + (hν : ∀ᵐ v ∂ν, ∀ i j, min (v i) (A i j) ≤ v j ∧ min (v i) (v j) ≤ A i j) + (hcoord : ∀ i c, μ.real {v | v i = c} = ν.real {v | v i = c}) : μ = ν := by + apply finite_measure_eq_of_maximal_coordinates μ ν + {v | ∀ i j, min (v i) (A i j) ≤ v j ∧ min (v i) (v j) ≤ A i j} hμ hν ?_ hcoord + intro v hv i hmax w hw hwi hwmax + have hvrow := ultrametric_extension_row A v i hmax + (fun j => (hv i j).1) (fun j => (hv i j).2) + have hwrow := ultrametric_extension_row A w i (by simpa only [hwi] using hwmax) + (fun j => (hw i j).1) (fun j => (hw i j).2) + funext j + rw [hwrow j,hvrow j,hwi] + +abbrev FiniteOverlap (L : Type*) := ℕ → ℕ → L +abbrev FiniteBlock (L : Type*) (n : ℕ) := Fin n → Fin n → L + +def finiteBlock {L : Type*} (n : ℕ) (R : FiniteOverlap L) : FiniteBlock L n := + fun i j => R i j + +def finiteRow {L : Type*} (n : ℕ) (R : FiniteOverlap L) : Fin n → L := + fun i => R i n + +def FiniteGG {L : Type*} [MeasurableSpace L] (μ : Measure (FiniteOverlap L)) : Prop := + ∀ n, 1 ≤ n → ∀ (i : Fin n) (A : FiniteBlock L n) (c : L), + μ.real {R | finiteBlock n R = A ∧ R i n = c} = + μ.real {R | finiteBlock n R = A} * μ.real {R | R 0 1 = c} / n + + (∑ j ∈ Finset.univ.erase i, μ.real {R | finiteBlock n R = A ∧ R i j = c}) / n + +lemma finiteBlock_measurable {L : Type*} [MeasurableSpace L] (n : ℕ) : + Measurable (finiteBlock (L := L) n) := + Measurable.of_eval fun row => Measurable.of_eval fun column => + (measurable_pi_apply (column : ℕ)).comp (measurable_pi_apply (row : ℕ)) + +lemma finiteRow_measurable {L : Type*} [MeasurableSpace L] (n : ℕ) : + Measurable (finiteRow (L := L) n) := + Measurable.of_eval fun row => + (measurable_pi_apply n).comp (measurable_pi_apply (row : ℕ)) + +def finiteFiberRow {L : Type*} [MeasurableSpace L] + (μ : Measure (FiniteOverlap L)) (n : ℕ) (A : FiniteBlock L n) : Measure (Fin n → L) := + (μ.restrict {R | finiteBlock n R = A}).map (finiteRow n) + +lemma finiteFiberRow_real {L : Type*} [Fintype L] [MeasurableSpace L] + [MeasurableSingletonClass L] (μ : Measure (FiniteOverlap L)) + (n : ℕ) (A : FiniteBlock L n) (i : Fin n) (c : L) : + (finiteFiberRow μ n A).real {v | v i = c} = + μ.real {R | finiteBlock n R = A ∧ R i n = c} := by + rw [measureReal_def,finiteFiberRow,Measure.map_apply (finiteRow_measurable n) + (show MeasurableSet {v : Fin n → L | v i = c} from (Set.to_countable _).measurableSet), + Measure.restrict_apply ((finiteRow_measurable n) ((Set.to_countable _).measurableSet))] + congr 1 + congr 1 + ext R + simp [finiteRow,and_comm] + +lemma finiteFiberRow_unique {L : Type*} [Fintype L] [LinearOrder L] + [MeasurableSpace L] [MeasurableSingletonClass L] + (μ ν : Measure (FiniteOverlap L)) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (hμ : ∀ᵐ R ∂μ, (∀ i j, R i j = R j i) ∧ + ∀ i j k, min (R i j) (R i k) ≤ R j k) + (hν : ∀ᵐ R ∂ν, (∀ i j, R i j = R j i) ∧ + ∀ i j k, min (R i j) (R i k) ≤ R j k) + (hGGμ : FiniteGG μ) (hGGν : FiniteGG ν) + (hpair : ∀ c, μ.real {R | R 0 1 = c} = ν.real {R | R 0 1 = c}) + (n : ℕ) (hn : 1 ≤ n) + (hblock : μ.map (finiteBlock n) = ν.map (finiteBlock n)) + (A : FiniteBlock L n) : finiteFiberRow μ n A = finiteFiberRow ν n A := by + classical + have : Nonempty (Fin n) := ⟨⟨0,hn⟩⟩ + have he : MeasurableSet {R : FiniteOverlap L | finiteBlock n R = A} := + (finiteBlock_measurable n) (measurableSet_singleton A) + have hbase : μ.real {R | finiteBlock n R = A} = ν.real {R | finiteBlock n R = A} := by + have hh := congrArg (fun ρ : Measure (FiniteBlock L n) => ρ.real {A}) hblock + simpa only [measureReal_def,Measure.map_apply (finiteBlock_measurable n) + (measurableSet_singleton A),Set.preimage,Set.mem_singleton_iff] using hh + have hprev (i j : Fin n) (c : L) : + μ.real {R | finiteBlock n R = A ∧ R i j = c} = + ν.real {R | finiteBlock n R = A ∧ R i j = c} := by + have hset : {R : FiniteOverlap L | finiteBlock n R = A ∧ R i j = c} = + if A i j = c then {R | finiteBlock n R = A} else ∅ := by + ext R + by_cases hA : A i j = c + · simp only [hA,ite_true,mem_ofPred_eq,and_iff_left_iff_imp] + intro hR + exact (congrFun (congrFun hR i) j).trans hA + · simp only [hA,ite_false,mem_empty_iff_false,mem_ofPred_eq,iff_false,not_and] + intro hR hh + exact hA ((congrFun (congrFun hR i) j).symm.trans hh) + rw [hset] + split_ifs + · exact hbase + · simp + have hrow (ρ : Measure (FiniteOverlap L)) + (hρ : ∀ᵐ R ∂ρ, (∀ i j, R i j = R j i) ∧ + ∀ i j k, min (R i j) (R i k) ≤ R j k) : + ∀ᵐ v ∂finiteFiberRow ρ n A, ∀ i j, + min (v i) (A i j) ≤ v j ∧ min (v i) (v j) ≤ A i j := by + rw [finiteFiberRow,ae_map_iff (finiteRow_measurable n).aemeasurable (Set.to_countable _).measurableSet] + apply (ae_restrict_iff' he).mpr + filter_upwards [hρ] with R hR hRA + intro i j + have hij : R i j = A i j := congrFun (congrFun hRA i) j + dsimp [finiteRow] + constructor + · simpa only [← hij,hR.1 n (j : ℕ)] using hR.2 (i : ℕ) n (j : ℕ) + · simpa only [hR.1 n (i : ℕ),hR.1 n (j : ℕ),hij] using hR.2 n (i : ℕ) (j : ℕ) + let : IsFiniteMeasure (μ.restrict {R | finiteBlock n R = A}) := inferInstance + let : IsFiniteMeasure (ν.restrict {R | finiteBlock n R = A}) := inferInstance + have : IsFiniteMeasure (finiteFiberRow μ n A) := by unfold finiteFiberRow; infer_instance + have : IsFiniteMeasure (finiteFiberRow ν n A) := by unfold finiteFiberRow; infer_instance + apply finite_ultrametric_row_law_unique A _ _ (hrow μ hμ) (hrow ν hν) + intro i c + rw [finiteFiberRow_real,finiteFiberRow_real,hGGμ n hn i A c,hGGν n hn i A c,hbase,hpair] + congr 1 + congr 1 + apply Finset.sum_congr rfl + intro j _ + exact hprev i j c + +lemma map_pair_eq_of_fiber_map_eq + {Ω X Y : Type*} [MeasurableSpace Ω] [Fintype X] [Fintype Y] + [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSingletonClass X] [MeasurableSingletonClass Y] + (μ ν : Measure Ω) (a : Ω → X) (v : Ω → Y) + (ha : Measurable a) (hv : Measurable v) + (h : ∀ x, (μ.restrict {ω | a ω = x}).map v = + (ν.restrict {ω | a ω = x}).map v) : + μ.map (fun ω => (a ω,v ω)) = ν.map (fun ω => (a ω,v ω)) := by + apply Measure.ext_of_singleton + intro p + have hh := congrArg (fun ρ : Measure Y => ρ {p.2}) (h p.1) + rw [Measure.map_apply hv (measurableSet_singleton _), + Measure.map_apply hv (measurableSet_singleton _), + Measure.restrict_apply (hv (measurableSet_singleton _)), + Measure.restrict_apply (hv (measurableSet_singleton _))] at hh + rw [Measure.map_apply (ha.prodMk hv) (measurableSet_singleton _), + Measure.map_apply (ha.prodMk hv) (measurableSet_singleton _)] + convert hh using 1 <;> congr 1 <;> ext ω <;> simp [and_comm,Prod.ext_iff] + +def finiteExtension {L : Type*} (d : L) {n : ℕ} + (p : FiniteBlock L n × (Fin n → L)) : FiniteBlock L (n+1) := + fun i j => Fin.lastCases (Fin.lastCases d p.2 j) + (fun ii => Fin.lastCases (p.2 ii) (p.1 ii) j) i + +lemma finiteBlock_eq_extension {L : Type*} (d : L) (R : FiniteOverlap L) + (hsym : ∀ i j, R i j = R j i) (hdiag : ∀ i, R i i = d) (n : ℕ) : + finiteBlock (n+1) R = finiteExtension d (finiteBlock n R,finiteRow n R) := by + funext i j + refine Fin.lastCases ?_ (fun ii => ?_) i + · refine Fin.lastCases ?_ (fun jj => ?_) j + · simpa [finiteBlock,finiteExtension] using hdiag n + · simpa [finiteBlock,finiteRow,finiteExtension] using hsym n jj + · refine Fin.lastCases ?_ (fun jj => ?_) j + · simp [finiteBlock,finiteRow,finiteExtension] + · simp [finiteBlock,finiteExtension] + +lemma finiteBlock_succ_law_unique {L : Type*} [Fintype L] [LinearOrder L] + [MeasurableSpace L] [MeasurableSingletonClass L] + (μ ν : Measure (FiniteOverlap L)) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (d : L) + (hμ : ∀ᵐ R ∂μ, (∀ i j, R i j = R j i) ∧ (∀ i, R i i = d) ∧ + ∀ i j k, min (R i j) (R i k) ≤ R j k) + (hν : ∀ᵐ R ∂ν, (∀ i j, R i j = R j i) ∧ (∀ i, R i i = d) ∧ + ∀ i j k, min (R i j) (R i k) ≤ R j k) + (hGGμ : FiniteGG μ) (hGGν : FiniteGG ν) + (hpair : ∀ c, μ.real {R | R 0 1 = c} = ν.real {R | R 0 1 = c}) + (n : ℕ) (hn : 1 ≤ n) + (hblock : μ.map (finiteBlock n) = ν.map (finiteBlock n)) : + μ.map (finiteBlock (n+1)) = ν.map (finiteBlock (n+1)) := by + have hjoint : μ.map (fun R => (finiteBlock n R,finiteRow n R)) = + ν.map (fun R => (finiteBlock n R,finiteRow n R)) := + map_pair_eq_of_fiber_map_eq μ ν _ _ (finiteBlock_measurable n) (finiteRow_measurable n) + fun A => finiteFiberRow_unique μ ν + (hμ.mono fun _ h => ⟨h.1,h.2.2⟩) (hν.mono fun _ h => ⟨h.1,h.2.2⟩) + hGGμ hGGν hpair n hn hblock A + have hext (ρ : Measure (FiniteOverlap L)) + (hρ : ∀ᵐ R ∂ρ, (∀ i j, R i j = R j i) ∧ (∀ i, R i i = d) ∧ + ∀ i j k, min (R i j) (R i k) ≤ R j k) : + ρ.map (finiteBlock (n+1)) = + (ρ.map (fun R => (finiteBlock n R,finiteRow n R))).map (finiteExtension d) := by + rw [Measure.map_map (measurable_of_countable _) + ((finiteBlock_measurable n).prodMk (finiteRow_measurable n))] + apply Measure.map_congr + exact hρ.mono fun R hR => finiteBlock_eq_extension d R hR.1 hR.2.1 n + rw [hext μ hμ,hext ν hν,hjoint] + +theorem finiteGG_block_law_unique {L : Type*} [Fintype L] [LinearOrder L] + [MeasurableSpace L] [MeasurableSingletonClass L] + (μ ν : Measure (FiniteOverlap L)) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (d : L) + (hμ : ∀ᵐ R ∂μ, (∀ i j, R i j = R j i) ∧ (∀ i, R i i = d) ∧ + ∀ i j k, min (R i j) (R i k) ≤ R j k) + (hν : ∀ᵐ R ∂ν, (∀ i j, R i j = R j i) ∧ (∀ i, R i i = d) ∧ + ∀ i j k, min (R i j) (R i k) ≤ R j k) + (hGGμ : FiniteGG μ) (hGGν : FiniteGG ν) + (hpair : ∀ c, μ.real {R | R 0 1 = c} = ν.real {R | R 0 1 = c}) : + ∀ n, μ.map (finiteBlock (n+1)) = ν.map (finiteBlock (n+1)) := by + have hbase (ρ : Measure (FiniteOverlap L)) [IsProbabilityMeasure ρ] + (hρ : ∀ᵐ R ∂ρ, ∀ i, R i i = d) : + ρ.map (finiteBlock 1) = Measure.dirac (fun (_ _ : Fin 1) => d) := by + have he : finiteBlock 1 =ᵐ[ρ] (fun _ => fun (_ _ : Fin 1) => d) := by + filter_upwards [hρ] with R hR + funext i j + have hi : i = 0 := Subsingleton.elim _ _ + have hj : j = 0 := Subsingleton.elim _ _ + simpa [hi,hj,finiteBlock] using hR 0 + rw [Measure.map_congr he] + simp + intro n + induction n with + | zero => + exact (hbase μ (hμ.mono fun _ h => h.2.1)).trans + (hbase ν (hν.mono fun _ h => h.2.1)).symm + | succ n ih => + exact finiteBlock_succ_law_unique μ ν d hμ hν hGGμ hGGν hpair + (n+1) (by omega) ih + +lemma measureReal_atom_inter_of_ae_const {Ω X Y : Type*} [MeasurableSpace Ω] [DecidableEq X] + (μ : Measure Ω) (a : Ω → X) (v : Ω → Y) (x₀ x : X) (y : Y) + (ha : a =ᵐ[μ] fun _ => x₀) : + μ.real {ω | a ω = x ∧ v ω = y} = if x₀ = x then μ.real {ω | v ω = y} else 0 := by + classical + by_cases hx : x₀ = x + · rw [ite_eq_left hx] + apply measureReal_congr + filter_upwards [ha] with ω hω + simp [hω, hx] + · rw [ite_eq_right hx] + convert (show μ.real ∅ = 0 from measureReal_empty) using 1 + apply measureReal_congr + filter_upwards [ha] with ω hω + change (a ω = x ∧ v ω = y) = False + simp [hω, hx] + +lemma finiteGG_of_ge_two {L : Type*} [Fintype L] [MeasurableSpace L] + [MeasurableSingletonClass L] (μ : Measure (FiniteOverlap L)) [IsProbabilityMeasure μ] + (d : L) (hdiag : ∀ᵐ R ∂μ, ∀ i, R i i = d) + (hGG : ∀ n, 2 ≤ n → ∀ (i : Fin n) (A : FiniteBlock L n) (c : L), + μ.real {R | finiteBlock n R = A ∧ R i n = c} = + μ.real {R | finiteBlock n R = A} * μ.real {R | R 0 1 = c} / n + + (∑ j ∈ Finset.univ.erase i, μ.real {R | finiteBlock n R = A ∧ R i j = c}) / n) : + FiniteGG μ := by + classical + intro n hn i A c + by_cases hn2 : 2 ≤ n + · exact hGG n hn2 i A c + have hn1 : n = 1 := by omega + subst n + have hi : i = 0 := Subsingleton.elim _ _ + subst i + have hblock : finiteBlock (L := L) 1 =ᵐ[μ] fun _ => fun (_ _ : Fin 1) => d := by + filter_upwards [hdiag] with R hR + funext a b + have ha : a = 0 := Subsingleton.elim _ _ + have hb : b = 0 := Subsingleton.elim _ _ + simpa [ha,hb,finiteBlock] using hR 0 + have hbase : μ.real {R | finiteBlock 1 R = A} = + if (fun (_ _ : Fin 1) => d) = A then 1 else 0 := by + have hh := measureReal_atom_inter_of_ae_const μ (finiteBlock 1) (fun _ => ()) + (fun (_ _ : Fin 1) => d) A () hblock + simpa using hh + have hnew := measureReal_atom_inter_of_ae_const μ (finiteBlock 1) + (fun R => R 0 1) (fun (_ _ : Fin 1) => d) A c hblock + simp only [Fin.val_zero,Nat.cast_one,div_one] + rw [hnew,hbase] + have herase : (Finset.univ : Finset (Fin 1)).erase 0 = ∅ := by decide + rw [herase,Finset.sum_empty,add_zero] + split_ifs <;> simp + +lemma poisson_power_integral (r : ℝ≥0) (a : ℝ) : + ∫ n, a ^ n ∂poissonMeasure r = Real.exp ((r : ℝ) * (a - 1)) := by + rw [integral_poissonMeasure] + simp only [smul_eq_mul] + calc + (∑' n : ℕ, Real.exp (-(r : ℝ)) * (r : ℝ)^n / n.factorial * a^n) = + Real.exp (-(r : ℝ)) * ∑' n : ℕ, ((r : ℝ) * a)^n / n.factorial := by + rw [← tsum_mul_left] + congr 1 + funext n + rw [mul_pow] + ring + _ = Real.exp ((r : ℝ) * (a-1)) := by + rw [(NormedSpace.expSeries_div_hasSum_exp ((r : ℝ)*a)).tsum_eq] + rw [← Real.exp_eq_exp_ℝ,← Real.exp_add] + congr 1 + ring + +def finitePointMeasure {S : Type*} [MeasurableSpace S] (n : ℕ) (x : Fin n → S) : Measure S := + ∑ i : Fin n, Measure.dirac (x i) + +@[fun_prop] lemma finitePointMeasure_measurable {S : Type*} [MeasurableSpace S] (n : ℕ) : + Measurable (finitePointMeasure (S := S) n) := by + unfold finitePointMeasure + fun_prop + +def finitePoissonLaw {S : Type*} [MeasurableSpace S] (r : ℝ≥0) (ν : Measure S) : + Measure (Measure S) := + Measure.sum fun n : ℕ => + poissonMeasure r {n} • (Measure.pi fun _ : Fin n => ν).map (finitePointMeasure n) + +instance finitePoissonLaw_probability {S : Type*} [MeasurableSpace S] + (r : ℝ≥0) (ν : Measure S) [IsProbabilityMeasure ν] : + IsProbabilityMeasure (finitePoissonLaw r ν) := by + constructor + rw [finitePoissonLaw,Measure.sum_apply _ MeasurableSet.univ] + have hmass (n : ℕ) : ((Measure.pi fun _ : Fin n => ν).map (finitePointMeasure n)) univ = 1 := by + rw [Measure.map_apply (finitePointMeasure_measurable n) MeasurableSet.univ, + preimage_univ,measure_univ] + simp only [Measure.smul_apply,hmass,smul_eq_mul,mul_one] + have hh := hasSum_one_poissonMeasure r + simp_rw [poissonMeasure_singleton] + rw [← ENNReal.ofReal_tsum_of_nonneg (fun _ => by positivity) hh.summable,hh.tsum_eq] + norm_num + +def expNegENNReal (u : ℝ≥0∞) : ℝ := (EReal.exp (-(u : EReal))).toReal + +lemma expNegENNReal_bound (u : ℝ≥0∞) : 0 ≤ expNegENNReal u ∧ expNegENNReal u ≤ 1 := by + have hu : EReal.exp (-(u : EReal)) ≤ 1 := + EReal.exp_le_one_iff.mpr (EReal.neg_le_zero.mpr (EReal.coe_ennreal_nonneg u)) + exact ⟨ENNReal.toReal_nonneg, ENNReal.toReal_le_of_le_ofReal (by norm_num) (by simpa using hu)⟩ + +lemma expNegENNReal_continuous : Continuous expNegENNReal := by + have hc : Continuous (fun u : ℝ≥0∞ => EReal.exp (-(u : EReal))) := ENNReal.continuous_exp.comp continuous_coe_ennreal_ereal.neg + rw [continuous_iff_continuousAt] + intro u + apply (ENNReal.continuousAt_toReal ?_).comp hc.continuousAt + apply ne_of_lt + exact lt_of_le_of_lt (EReal.exp_le_one_iff.mpr + (EReal.neg_le_zero.mpr (EReal.coe_ennreal_nonneg u))) ENNReal.one_lt_top + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/FiniteVectorReplica.lean b/lean/OAI/Probability/Perceptron/Interpolation/FiniteVectorReplica.lean new file mode 100644 index 0000000000000000000000000000000000000000..b6e7db4b9b501fc2854f44150d4081b690b5da3d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/FiniteVectorReplica.lean @@ -0,0 +1,95 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IntegratedConvex + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma euclideanReplica_measurable_left {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (r : ℕ) (j : Fin r) + {H : S→ℝ} {V W : S→EuclideanSpace ℝ I} {G : (Fin r→S)→ℝ} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) (hG : Measurable G) : + Measurable (fun g => gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) r + (fun x => inner ℝ (W (x j)) g*G x)) := by + have hh : Measurable (fun a : EuclideanSpace ℝ I × S => H a.2+inner ℝ (V a.2) a.1) := + (hH.comp measurable_snd).add ((hV.comp measurable_snd).inner measurable_fst) + have hmj : Measurable (fun x : Fin r→S => W (x j)) := hW.comp (measurable_pi_apply j) + have hl : Measurable (fun a : EuclideanSpace ℝ I × (Fin r→S) => inner ℝ (W (a.2 j)) a.1*G a.2) := + ((hmj.comp measurable_snd).inner measurable_fst).mul (hG.comp measurable_snd) + exact kernel_replicaMean_measurable (Kernel.const (EuclideanSpace ℝ I) μ) hh hl + +lemma euclideanReplica_measurable_right {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (r : ℕ) (j : Fin r) + {H : S→ℝ} {V W : S→EuclideanSpace ℝ I} {G : (Fin r→S)→ℝ} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) (hG : Measurable G) : + Measurable (fun g => gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) r + (fun x => G x*∑ l, inner ℝ (W (x j)) (V (x l))) - + r*gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) (r+1) + (fun x => G (fun l => x l.succ)*inner ℝ (W (x j.succ)) (V (x 0)))) := by + have hh : Measurable (fun a : EuclideanSpace ℝ I × S => H a.2+inner ℝ (V a.2) a.1) := + (hH.comp measurable_snd).add ((hV.comp measurable_snd).inner measurable_fst) + have hsum : Measurable (fun x : Fin r→S => G x*∑ l, inner ℝ (W (x j)) (V (x l))) := by + apply hG.mul + exact Finset.measurable_sum _ fun l _ => (hW.comp (measurable_pi_apply j)).inner (hV.comp (measurable_pi_apply l)) + have hpair : Measurable (fun x : Fin (r+1)→S => G (fun l => x l.succ)*inner ℝ (W (x j.succ)) (V (x 0))) := + (hG.comp (Measurable.of_eval fun replica => measurable_pi_apply replica.succ)).mul + ((hW.comp (measurable_pi_apply j.succ)).inner (hV.comp (measurable_pi_apply 0))) + exact (kernel_replicaMean_measurable (Kernel.const (EuclideanSpace ℝ I) μ) + (H := fun g x => H x+inner ℝ (V x) g) + (G := fun _ x => G x*∑ l, inner ℝ (W (x j)) (V (x l))) hh + (hsum.comp measurable_snd)).sub ((kernel_replicaMean_measurable (Kernel.const (EuclideanSpace ℝ I) μ) + (H := fun g x => H x+inner ℝ (V x) g) + (G := fun _ x => G (fun l => x l.succ)*inner ℝ (W (x j.succ)) (V (x 0))) hh + (hpair.comp measurable_snd)).const_mul r) + +lemma countableVector_replica_ibp {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (r : ℕ) (j : Fin r) + {H : S→ℝ} {V W : S→EuclideanSpace ℝ I} {G : (Fin r→S)→ℝ} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) (hG : Measurable G) + {A D E B : ℝ} (hA : ∀ x, |H x|≤A) (hD : ∀ x, ‖V x‖^2≤D) + (hE : ∀ x, ‖W x‖^2≤E) (hB : 0≤B) (hGB : ∀ x, |G x|≤B) : + (∫ g, gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) (countableGaussianVector g)) r + (fun x => inner ℝ (W (x j)) (countableGaussianVector g)*G x) ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) (countableGaussianVector g)) r + (fun x => G x*∑ l, inner ℝ (W (x j)) (V (x l))) - + r*gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) (countableGaussianVector g)) (r+1) + (fun x => G (fun l => x l.succ)*inner ℝ (W (x j.succ)) (V (x 0))) + ∂countableGaussianLaw := by + have he := countableGaussian_replica_full_ibp μ r j hH + (vectorGaussianRow_measurable hV) (vectorGaussianRow_measurable hW) measurable_const hG hA + (fun x => (vectorGaussianRow_norm V x).trans_le (hD x)) + (fun x => (vectorGaussianRow_norm W x).trans_le (hE x)) hB hGB + have hham (g) : countableGaussianHamiltonian H (vectorGaussianRow V) + (fun _ => vectorGaussianLength I) g=fun x => H x+inner ℝ (V x) (countableGaussianVector g) := by + funext x + exact congrArg (fun y => H x+y) (vectorGaussianRow_field V g x) + simp_rw [hham,vectorGaussianRow_field,vectorGaussianRow_covariance] at he + exact he + +lemma euclideanGaussian_replica_ibp {I : Type} {S : Type*} [Fintype I] [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (r : ℕ) (j : Fin r) + {H : S→ℝ} {V W : S→EuclideanSpace ℝ I} {G : (Fin r→S)→ℝ} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) (hG : Measurable G) + {A D E B : ℝ} (hA : ∀ x, |H x|≤A) (hD : ∀ x, ‖V x‖^2≤D) + (hE : ∀ x, ‖W x‖^2≤E) (hB : 0≤B) (hGB : ∀ x, |G x|≤B) : + (∫ g, gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) r + (fun x => inner ℝ (W (x j)) g*G x) ∂stdGaussian (EuclideanSpace ℝ I)) = + ∫ g, gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) r + (fun x => G x*∑ l, inner ℝ (W (x j)) (V (x l))) - + r*gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) (r+1) + (fun x => G (fun l => x l.succ)*inner ℝ (W (x j.succ)) (V (x 0))) + ∂stdGaussian (EuclideanSpace ℝ I) := by + have hleft := euclideanReplica_measurable_left μ r j hH hV hW hG + have hright := euclideanReplica_measurable_right μ r j hH hV hW hG + rw [← countableGaussianVector_law (I:=I), + integral_map countableGaussianVector_measurable.aemeasurable hleft.aestronglyMeasurable, + integral_map countableGaussianVector_measurable.aemeasurable hright.aestronglyMeasurable] + exact countableVector_replica_ibp μ r j hH hV hW hG hA hD hE hB hGB + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/GaussianReplicaFubini.lean b/lean/OAI/Probability/Perceptron/Interpolation/GaussianReplicaFubini.lean new file mode 100644 index 0000000000000000000000000000000000000000..635c68dd539efb3ba7a27f8156dd8ff8168adc92 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/GaussianReplicaFubini.lean @@ -0,0 +1,72 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshMarkedKernel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +variable {S E : Type*} [MeasurableSpace S] [TopologicalSpace S] [BorelSpace S] + [SecondCountableTopology S] [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [MeasurableSpace S] [BorelSpace S] [SecondCountableTopology S] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma gaussianRows_joint_continuous {r : ℕ} {v : S→E} (hv : Continuous v) : + Continuous (fun p : E×(Fin r→S) => gaussianRows (fun i => v (p.2 i)) p.1) := by + change Continuous (fun p : E×(Fin r→S) => WithLp.toLp 2 (fun i => inner ℝ (v (p.2 i)) p.1)) + fun_prop + +lemma twoFreshReplica_fubini {r : ℕ} (ν : Measure (Fin r→S)) [IsProbabilityMeasure ν] + (v : S→E) (hv : Continuous v) (G : (Fin r→S)→ℝ) (hG : Measurable G) + {C : ℝ} (hC : 0≤C) (hb : ∀ x, |G x|≤C) + (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + (∫ g, ∫ x, G x*Ψ (gaussianRows (fun i => v (x i)) g.1)* + Φ (gaussianRows (fun i => v (x i)) g.2) ∂ν + ∂(stdGaussian E).prod (stdGaussian E)) = + ∫ x, G x*freshMarkedMatrixKernel Ψ (Matrix.gram ℝ (fun i => v (x i)))* + freshMarkedMatrixKernel Φ (Matrix.gram ℝ (fun i => v (x i))) ∂ν := by + let P := (stdGaussian E).prod (stdGaussian E) + have hc₁ : Continuous (fun p : (E×E)×(Fin r→S) => + Ψ (gaussianRows (fun i => v (p.2 i)) p.1.1)) := + Ψ.continuous.comp ((gaussianRows_joint_continuous (r:=r) hv).comp + (continuous_fst.fst.prodMk continuous_snd)) + have hc₂ : Continuous (fun p : (E×E)×(Fin r→S) => + Φ (gaussianRows (fun i => v (p.2 i)) p.1.2)) := + Φ.continuous.comp ((gaussianRows_joint_continuous (r:=r) hv).comp + (continuous_fst.snd.prodMk continuous_snd)) + have hm : Measurable (fun p : (E×E)×(Fin r→S) => G p.2* + Ψ (gaussianRows (fun i => v (p.2 i)) p.1.1)*Φ (gaussianRows (fun i => v (p.2 i)) p.1.2)) := + ((hG.comp measurable_snd).mul hc₁.measurable).mul hc₂.measurable + have hi : Integrable (fun p : (E×E)×(Fin r→S) => G p.2* + Ψ (gaussianRows (fun i => v (p.2 i)) p.1.1)*Φ (gaussianRows (fun i => v (p.2 i)) p.1.2)) + (P.prod ν) := by + apply Integrable.of_bound hm.aestronglyMeasurable (C*‖Ψ‖*‖Φ‖) + exact ae_of_all _ fun p => by + simp only [Real.norm_eq_abs,abs_mul] + exact mul_le_mul (mul_le_mul (hb _) (Ψ.norm_coe_le_norm _) (abs_nonneg _) hC) + (Φ.norm_coe_le_norm _) (abs_nonneg _) (mul_nonneg hC (norm_nonneg _)) + rw [integral_integral_swap hi] + apply integral_congr_ae + exact ae_of_all _ fun x => by + simp_rw [mul_assoc] + rw [integral_const_mul,freshMarkedMatrixKernel_two] + +lemma gibbs_twoFreshReplica_fubini {r : ℕ} (μ : Measure S) [IsProbabilityMeasure μ] + {H : S→ℝ} (hH : Measurable H) (hi : Integrable (fun x => Real.exp (H x)) μ) + (v : S→E) (hv : Continuous v) (G : (Fin r→S)→ℝ) (hG : Measurable G) + {C : ℝ} (hC : 0≤C) (hb : ∀ x, |G x|≤C) + (Ψ Φ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + (∫ g, gibbsReplicaMean μ H r (fun x => G x*Ψ (gaussianRows (fun i => v (x i)) g.1)* + Φ (gaussianRows (fun i => v (x i)) g.2)) ∂(stdGaussian E).prod (stdGaussian E)) = + gibbsReplicaMean μ H r (fun x => G x*freshMarkedMatrixKernel Ψ (Matrix.gram ℝ (fun i => v (x i)))* + freshMarkedMatrixKernel Φ (Matrix.gram ℝ (fun i => v (x i)))) := by + let := tilt_law_probability_of_integrable μ (by simpa only [one_mul] using hi : + Integrable (fun x => Real.exp (1*H x)) μ) + simp_rw [gibbsReplicaMean_integral_of_integrable μ hH hi] + exact twoFreshReplica_fubini _ v hv G hG hC hb Ψ Φ +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/GibbsArrayGeometry.lean b/lean/OAI/Probability/Perceptron/Interpolation/GibbsArrayGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..81e8f7f6b006ac730b256b51b95e53246408d524 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/GibbsArrayGeometry.lean @@ -0,0 +1,70 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.CompactArrayMap +import OAI.Probability.Perceptron.Interpolation.GibbsOverlapArray + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +section +variable {A S K : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable [TopologicalSpace K] [MeasurableSpace K] [BorelSpace K] + [SecondCountableTopology K] [CompactSpace K] +variable (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) [IsProbabilityMeasure P] +variable (H : A → S → ℝ) (hH : Measurable (Function.uncurry H)) +variable (Q : S → S → K) (hQ : Measurable (Function.uncurry Q)) + +omit [CompactSpace K] in +lemma gibbsOverlapArray_exchangeable (e : Equiv.Perm ℕ) : + MeasurePreserving (compactRelabel (K:=K) e) + (gibbsOverlapArrayLaw κ P H hH Q hQ : Measure _) + (gibbsOverlapArrayLaw κ P H hH Q hQ : Measure _) := by + have hr := annealedInfiniteReplica_reindex κ P H hH e + have hm : Measurable (fun a : A×(ℕ→S) => overlapArray Q a.2) := + (overlapArray_measurable Q hQ).comp measurable_snd + refine ⟨(compactRelabel_continuous e).measurable,?_⟩ + change Measure.map _ (Measure.map (fun a : A×(ℕ→S) => overlapArray Q a.2) _) = _ + rw [Measure.map_map (compactRelabel_continuous e).measurable hm] + change Measure.map ((fun a : A×(ℕ→S) => overlapArray Q a.2) ∘ + (fun a : A×(ℕ→S) => (a.1,fun i => a.2 (e i)))) _ = _ + rw [← Measure.map_map hm hr.measurable,hr.map_eq] + rfl + +omit [CompactSpace K] in +lemma gibbsOverlapArray_closed_full {F : Set (CompactArray K)} (hF : IsClosed F) + (hfull : ∀ x : ℕ→S, overlapArray Q x ∈ F) : + gibbsOverlapArrayLaw κ P H hH Q hQ F=1 := by + have hp : (fun a : A×(ℕ→S) => overlapArray Q a.2) ⁻¹' F=univ := by + ext a + simp only [mem_preimage,mem_univ,iff_true] + exact hfull a.2 + apply ENNReal.coe_injective + rw [ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure] + change (Measure.map (fun a : A×(ℕ→S) => overlapArray Q a.2) _) F=1 + have hm : Measurable (fun a : A×(ℕ→S) => overlapArray Q a.2) := + (overlapArray_measurable Q hQ).comp measurable_snd + rw [Measure.map_apply hm hF.measurableSet,hp] + exact measure_univ +end + +lemma compactMapLaw_exchangeable {K L : Type*} [TopologicalSpace K] [TopologicalSpace L] + [MeasurableSpace K] [MeasurableSpace L] [BorelSpace K] [BorelSpace L] + [SecondCountableTopology K] [SecondCountableTopology L] + (f : K→L) (hf : Continuous f) (μ : ProbabilityMeasure (CompactArray K)) + (e : Equiv.Perm ℕ) + (he : MeasurePreserving (compactRelabel (K:=K) e) (μ : Measure _) (μ : Measure _)) : + MeasurePreserving (compactRelabel (K:=L) e) (compactMapLaw f hf μ : Measure _) + (compactMapLaw f hf μ : Measure _) := by + refine ⟨(compactRelabel_continuous e).measurable,?_⟩ + change Measure.map _ (Measure.map (compactMapArray f) _) = _ + rw [Measure.map_map (compactRelabel_continuous e).measurable (compactMapArray_continuous hf).measurable] + change Measure.map (compactMapArray f ∘ compactRelabel e) _ = _ + rw [← Measure.map_map (compactMapArray_continuous hf).measurable he.measurable,he.map_eq] + rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/GibbsOverlapArray.lean b/lean/OAI/Probability/Perceptron/Interpolation/GibbsOverlapArray.lean new file mode 100644 index 0000000000000000000000000000000000000000..5ea6ef8b7b69a2924a269bc26982f62a4f354868 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/GibbsOverlapArray.lean @@ -0,0 +1,129 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ArrayGeometry + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +variable {A S K : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable [TopologicalSpace K] [MeasurableSpace K] [BorelSpace K] + [SecondCountableTopology K] [CompactSpace K] +variable (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) [IsProbabilityMeasure P] +variable (H : A → S → ℝ) (hH : Measurable (Function.uncurry H)) +variable (Q : S → S → K) (hQ : Measurable (Function.uncurry Q)) + +def overlapArray (x : ℕ → S) : CompactArray K := fun i j => Q (x i) (x j) + +include hQ in +omit [TopologicalSpace K] [BorelSpace K] [SecondCountableTopology K] [CompactSpace K] in +lemma overlapArray_measurable : Measurable (overlapArray Q) := by + unfold overlapArray + exact Measurable.of_eval fun row => Measurable.of_eval fun column => + hQ.comp (show Measurable (fun sequence : ℕ → S => (sequence row,sequence column)) from + (measurable_pi_apply row).prodMk (measurable_pi_apply column)) + +def gibbsOverlapArrayLaw : ProbabilityMeasure (CompactArray K) := + ⟨(annealedInfiniteReplicaMeasure κ P H hH).map (fun a => overlapArray Q a.2), + (Measure.isProbabilityMeasure_map_iff + ((overlapArray_measurable Q hQ).comp measurable_snd).aemeasurable).2 inferInstance⟩ + +omit [TopologicalSpace K] [BorelSpace K] [SecondCountableTopology K] [CompactSpace K] in +lemma gibbsOverlapArray_integral {F : CompactArray K → ℝ} (hF : Measurable F) : + (∫ R, F R ∂gibbsOverlapArrayLaw κ P H hH Q hQ) = + ∫ a, F (overlapArray Q a.2) ∂annealedInfiniteReplicaMeasure κ P H hH := + integral_map ((overlapArray_measurable Q hQ).comp measurable_snd).aemeasurable hF.aestronglyMeasurable + +omit [CompactSpace K] + +lemma gibbsOverlapArray_block (hexp : ∀ᵐ a ∂P, + Integrable (fun x => Real.exp (H a x)) (κ a)) (r : ℕ) + (F : CompactBlock K r →ᵇ ℝ) : + (∫ R, F (compactBlock r R) ∂gibbsOverlapArrayLaw κ P H hH Q hQ) = + ∫ a, gibbsReplicaMean (κ a) (H a) r + (fun x => F (fun i j => Q (x i) (x j))) ∂P := by + rw [gibbsOverlapArray_integral κ P H hH Q hQ + (F:=fun R => F (compactBlock r R)) (F.continuous.measurable.comp (compactBlock_continuous r).measurable)] + exact annealedInfiniteReplica_gibbs_prefix κ P H hH hexp r + (F.continuous.measurable.comp (Measurable.of_eval fun row => Measurable.of_eval fun column => + hQ.comp ((measurable_pi_apply row).prodMk (measurable_pi_apply column)))) + (fun x => by + change |F (fun i j => Q (x i) (x j))|≤‖F‖ + simpa only [Real.norm_eq_abs] using F.norm_coe_le_norm (fun i j => Q (x i) (x j))) + +lemma compactGGDefect_gibbsOverlapArray (hexp : ∀ᵐ a ∂P, + Integrable (fun x => Real.exp (H a x)) (κ a)) + (r : ℕ) (i : Fin r) (f : CompactBlock K r →ᵇ ℝ) (g : K →ᵇ ℝ) + (diag : ℝ) (hdiag : ∀ x, g (Q x x)=diag) (hsymm : ∀ x y, g (Q x y)=g (Q y x)) : + compactGGDefect (gibbsOverlapArrayLaw κ P H hH Q hQ) r i f g = + -kernelGGDefect κ P H (fun x y => g (Q x y)) diag r i + (fun x => f (fun j l => Q (x j) (x l))) := by + classical + let μ := gibbsOverlapArrayLaw κ P H hH Q hQ + let F : CompactArray K →ᵇ ℝ := f.compContinuous ⟨compactBlock r,compactBlock_continuous r⟩ + let E (a b : ℕ) : CompactArray K →ᵇ ℝ := g.compContinuous ⟨fun R => R a b,by fun_prop⟩ + let Es (a b : Fin r) : CompactBlock K r →ᵇ ℝ := g.compContinuous ⟨fun R => R a b,by fun_prop⟩ + have hmean := gibbsOverlapArray_block κ P H hH Q hQ hexp r f + have hsum := gibbsOverlapArray_block κ P H hH Q hQ hexp r (f * ∑ l, Es i l) + have hp := gibbsOverlapArray_block κ P H hH Q hQ hexp 2 + (g.compContinuous ⟨fun R => R 0 1,by fun_prop⟩) + have hpair : (∫ R : CompactArray K, g (R 0 1) ∂μ) = + ∫ a, gibbsReplicaMean (κ a) (H a) 2 (fun x => g (Q (x 1) (x 0))) ∂P := by + change (∫ R : CompactArray K, g (R 0 1) ∂μ) = + ∫ a, gibbsReplicaMean (κ a) (H a) 2 (fun x => g (Q (x 0) (x 1))) ∂P at hp + rw [hp] + apply integral_congr_ae + exact Eventually.of_forall fun a => congrArg (gibbsReplicaMean (κ a) (H a) 2) + (funext fun x => hsymm (x 0) (x 1)) + let fnew : CompactBlock K (r+1) →ᵇ ℝ := + (f.compContinuous ⟨fun R => fun j l => R j.castSucc l.castSucc,by fun_prop⟩) * + (g.compContinuous ⟨fun R => R i.castSucc (Fin.last r),by fun_prop⟩) + have hn := gibbsOverlapArray_block κ P H hH Q hQ hexp (r+1) fnew + have hnew : (∫ R, f (compactBlock r R)*g (R i r) ∂μ) = + ∫ a, gibbsReplicaMean (κ a) (H a) (r+1) + (fun x => f (fun j l => Q (x j.succ) (x l.succ))*g (Q (x i.succ) (x 0))) ∂P := by + change (∫ R, fnew (compactBlock (r+1) R) ∂μ) = _ + rw [hn] + apply integral_congr_ae + filter_upwards [hexp] with a ha + symm + have hG : Measurable (Function.uncurry (fun (x : Fin r → S) (y : S) => + f (fun j l => Q (x j) (x l))*g (Q (x i) y))) := by + apply Measurable.mul + · exact f.continuous.measurable.comp (Measurable.of_eval fun row => + Measurable.of_eval fun column => hQ.comp + (show Measurable (fun replica : (Fin r → S)×S => + (replica.1 row,replica.1 column)) from by fun_prop)) + · exact g.continuous.measurable.comp (hQ.comp + (show Measurable (fun a : (Fin r → S)×S => (a.1 i,a.2)) from by fun_prop)) + simpa only [fnew,BoundedContinuousFunction.mul_apply,BoundedContinuousFunction.compContinuous_apply, + ContinuousMap.coe_mk] using gibbsReplicaMean_fresh_last (κ a) (hH.of_uncurry_left) ha r hG + have hdiagint : (∫ R, f (compactBlock r R)*g (R i i) ∂μ) = + diag*(∫ R, f (compactBlock r R) ∂μ) := by + change (∫ R, (F*E i i) R ∂gibbsOverlapArrayLaw κ P H hH Q hQ) = + diag*(∫ R, F R ∂gibbsOverlapArrayLaw κ P H hH Q hQ) + rw [gibbsOverlapArray_integral κ P H hH Q hQ (F * E i i).continuous.measurable, + gibbsOverlapArray_integral κ P H hH Q hQ F.continuous.measurable] + simp only [F,E,BoundedContinuousFunction.mul_apply,BoundedContinuousFunction.compContinuous_apply, + ContinuousMap.coe_mk,overlapArray,hdiag] + rw [integral_mul_const,mul_comm] + have hsumint : (∫ R, f (compactBlock r R)*∑ l : Fin r, g (R i l) ∂μ) = + (∑ l ∈ Finset.univ.erase i, ∫ R, f (compactBlock r R)*g (R i l) ∂μ)+ + diag*(∫ R, f (compactBlock r R) ∂μ) := by + simp_rw [Finset.mul_sum] + rw [integral_finsetSum (f:=fun (l : Fin r) (R : CompactArray K) => f (compactBlock r R)*g (R i l)) + Finset.univ (fun l _ => by exact (F*E i l).integrable μ)] + rw [← Finset.sum_erase_add _ _ (Finset.mem_univ i),hdiagint] + simp only [BoundedContinuousFunction.mul_apply,BoundedContinuousFunction.sum_apply, + Es,BoundedContinuousFunction.compContinuous_apply,ContinuousMap.coe_mk] at hsum + change (∫ R, f (compactBlock r R)*∑ l : Fin r, g (R i l) ∂μ) = _ at hsum + unfold compactGGDefect kernelGGDefect + change _ = - ((_)-diag*(_)+(_)*(_)-r*(_)) + rw [← hmean,← hpair,← hnew,← hsum,hsumint] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/GibbsReplicaMean.lean b/lean/OAI/Probability/Perceptron/Interpolation/GibbsReplicaMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..e5f7cf0355122985e7d55ae70d08446068e68954 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/GibbsReplicaMean.lean @@ -0,0 +1,168 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.TiltReplicaCoordinate + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +def gibbsReplicaMean (H : S → ℝ) (n : ℕ) (G : (Fin n → S) → ℝ) : ℝ := + tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential H n) G 1 + +def fieldCovariance (m : ℕ) (v : Fin m → S → ℝ) (x y : S) : ℝ := + ∑ i, v i x * v i y + +lemma replicaMean_measurable {Ω : Type*} [MeasurableSpace Ω] {H : Ω → S → ℝ} + {n : ℕ} {G : (Fin n → S) → ℝ} (hH : Measurable (Function.uncurry H)) + (hG : Measurable G) : Measurable (fun ω => gibbsReplicaMean μ (H ω) n G) := by + apply measurable_tiltMean _ _ hG + change Measurable (fun p : Ω×(Fin n → S) => ∑ i, H p.1 (p.2 i)) + exact Finset.measurable_sum _ fun i _ => hH.comp + (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd)) + +lemma replicaMean_bound {H : S → ℝ} {n : ℕ} {G : (Fin n → S) → ℝ} + (hH : Measurable H) (hG : Measurable G) {A D : ℝ} (hA : 0 ≤ A) (hD : 0 ≤ D) + (hHA : ∀ x, |H x| ≤ A) (hGD : ∀ x, |G x| ≤ D) : |gibbsReplicaMean μ H n G| ≤ D := + tilt_mean_bound _ (replicaPotential_measurable hH n) hG + (mul_nonneg (Nat.cast_nonneg n) hA) hD (replicaPotential_bound hHA n) hGD 1 + +lemma replicaMean_sum {ι : Type*} (t : Finset ι) {H : S → ℝ} {n : ℕ} + {G : ι → (Fin n → S) → ℝ} (hH : Measurable H) + (hG : ∀ i ∈ t, Measurable (G i)) {A : ℝ} {D : ι → ℝ} + (hA : 0 ≤ A) (hHA : ∀ x, |H x| ≤ A) + (hGD : ∀ i ∈ t, ∀ x, |G i x| ≤ D i) : + gibbsReplicaMean μ H n (fun x => ∑ i ∈ t, G i x) = ∑ i ∈ t, gibbsReplicaMean μ H n (G i) := + tilt_mean_sum _ t (replicaPotential_measurable hH n) hG + (mul_nonneg (Nat.cast_nonneg n) hA) (replicaPotential_bound hHA n) hGD 1 + +omit [IsProbabilityMeasure μ] in +lemma replicaMean_const_mul {H : S → ℝ} {n : ℕ} {G : (Fin n → S) → ℝ} (c : ℝ) : + gibbsReplicaMean μ H n (fun x => c*G x) = c*gibbsReplicaMean μ H n G := + tilt_mean_mulObservable _ c 1 + +lemma gaussian_replica_field_ibp (m n : ℕ) (j : Fin n) + {v : Fin (m+1) → S → ℝ} {h : S → ℝ} {G : (Fin n → S) → ℝ} + (hv : ∀ i, Measurable (v i)) (hh : Measurable h) (hG : Measurable G) + {C A D : ℝ} (hC : 0 ≤ C) (hA : 0 ≤ A) (hD : 0 ≤ D) + (hvC : ∀ i x, |v i x| ≤ C) (hhA : ∀ x, |h x| ≤ A) (hGD : ∀ x, |G x| ≤ D) + (s : ℝ) : + let H := fun (g : Fin (m+1) → ℝ) (x : S) => h x+s*gaussianField (m+1) v g x + (∫ g, gibbsReplicaMean μ (H g) n (fun x => gaussianField (m+1) v g (x j)*G x) + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + s * ∫ g, + gibbsReplicaMean μ (H g) n (fun x => G x * ∑ l, fieldCovariance (m+1) v (x j) (x l)) - + n * gibbsReplicaMean μ (H g) (n+1) + (fun x => G (fun l => x l.succ)*fieldCovariance (m+1) v (x j.succ) (x 0)) + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + dsimp only + let γ := Measure.pi (fun _ : Fin (m+1) => gaussianReal 0 1) + let H := fun (g : Fin (m+1) → ℝ) (x : S) => h x+s*gaussianField (m+1) v g x + have hH : Measurable (Function.uncurry H) := hh.comp measurable_snd |>.add + ((gaussianField_measurable hv).const_mul s) + let B := fun (g : Fin (m+1) → ℝ) => A + |s| * ((∑ i, |g i|) * C) + have hB (g) : 0 ≤ B g := by dsimp [B]; positivity + have hb (g) (x : S) : |H g x| ≤ B g := by + exact (abs_add_le _ _).trans (add_le_add (hhA x) (by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (gaussianField_bound hvC g x) (abs_nonneg s))) + have hhg (g) : Measurable (H g) := hH.comp (measurable_const.prodMk measurable_id) + let F := fun i (x : Fin n → S) => v i (x j)*G x + let U := fun i (x : Fin n → S) => replicaPotential (v i) n x * F i x + let V := fun i (x : Fin (n+1) → S) => v i (x 0) * (v i (x j.succ)*G (fun l => x l.succ)) + have hFm (i) : Measurable (F i) := ((hv i).comp (measurable_pi_apply j)).mul hG + have hUm (i) : Measurable (U i) := (replicaPotential_measurable (hv i) n).mul (hFm i) + have hVm (i) : Measurable (V i) := by dsimp [V]; fun_prop + have hFB (i) (x) : |F i x| ≤ C*D := by + exact (abs_mul _ _).trans_le (mul_le_mul (hvC i _) (hGD _) (abs_nonneg _) hC) + have hUB (i) (x) : |U i x| ≤ (n:ℝ)*C^2*D := by + dsimp only [U] + rw [abs_mul] + have hh := mul_le_mul (replicaPotential_bound (hvC i) n x) (hFB i x) + (abs_nonneg _) (mul_nonneg (Nat.cast_nonneg n) hC) + calc + _ ≤ ((n:ℝ)*C)*(C*D) := hh + _ = _ := by ring + have hVB (i) (x) : |V i x| ≤ C^2*D := by + dsimp only [V] + rw [abs_mul,abs_mul] + have hh := mul_le_mul (hvC i (x 0)) + (mul_le_mul (hvC i (x j.succ)) (hGD (fun l => x l.succ)) (abs_nonneg _) hC) (by positivity) hC + calc + _ ≤ C*(C*D) := hh + _ = _ := by ring + have hUi (i) : Integrable (fun g => gibbsReplicaMean μ (H g) n (U i)) γ := by + apply Integrable.of_bound (replicaMean_measurable μ hH (hUm i)).aestronglyMeasurable + ((n:ℝ)*C^2*D) + exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs] using replicaMean_bound μ (hhg g) (hUm i) (hB g) + (by positivity) (hb g) (hUB i) + have hVi (i) : Integrable (fun g => gibbsReplicaMean μ (H g) (n+1) (V i)) γ := by + apply Integrable.of_bound (replicaMean_measurable μ hH (hVm i)).aestronglyMeasurable (C^2*D) + exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs] using replicaMean_bound μ (hhg g) (hVm i) (hB g) + (by positivity) (hb g) (hVB i) + have hFi (i) : Integrable (fun g => g i * gibbsReplicaMean μ (H g) n (F i)) γ := by + have hg : Integrable (fun g : Fin (m+1) → ℝ => g i) γ := by + exact ((measurePreserving_eval (fun _ : Fin (m+1) => gaussianReal 0 1) i).integrable_comp + measurable_id.aestronglyMeasurable).mpr + ((memLp_id_gaussianReal (μ := 0) (v := 1) 1).integrable (by norm_num)) + exact hg.mul_bdd (replicaMean_measurable μ hH (hFm i)).aestronglyMeasurable + (ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs] using replicaMean_bound μ (hhg g) (hFm i) (hB g) + (mul_nonneg hC hD) (hb g) (hFB i)) + have hleft (g) : gibbsReplicaMean μ (H g) n + (fun x => gaussianField (m+1) v g (x j)*G x) = + ∑ i, g i * gibbsReplicaMean μ (H g) n (F i) := by + rw [show (fun x => gaussianField (m+1) v g (x j)*G x) = + fun x => ∑ i, g i * F i x by funext x; simp only [gaussianField,Finset.sum_mul,F]; congr 1; funext i; ring] + rw [replicaMean_sum μ Finset.univ (hhg g) (fun i _ => (hFm i).const_mul (g i)) + (hB g) (hb g) (D := fun i => |g i| * (C*D)) (fun i _ x => by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hFB i x) (abs_nonneg _))] + simp_rw [replicaMean_const_mul] + have hright (g) : + (∑ i, (gibbsReplicaMean μ (H g) n (U i)-(n:ℝ)*gibbsReplicaMean μ (H g) (n+1) (V i))) = + gibbsReplicaMean μ (H g) n (fun x => G x * ∑ l, fieldCovariance (m+1) v (x j) (x l)) - + n * gibbsReplicaMean μ (H g) (n+1) + (fun x => G (fun l => x l.succ)*fieldCovariance (m+1) v (x j.succ) (x 0)) := by + rw [Finset.sum_sub_distrib,← Finset.mul_sum, + ← replicaMean_sum μ Finset.univ (hhg g) (fun i _ => hUm i) (hB g) (hb g) (fun i _ => hUB i), + ← replicaMean_sum μ Finset.univ (hhg g) (fun i _ => hVm i) (hB g) (hb g) (fun i _ => hVB i)] + congr 1 + · congr 1; funext x + dsimp [U,F,replicaPotential,fieldCovariance] + simp only [Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro l _ + apply Finset.sum_congr rfl + intro i _ + ring + · congr 1; congr 1; funext x + simp only [V,fieldCovariance,Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + change (∫ g, gibbsReplicaMean μ (H g) n (fun x => gaussianField (m+1) v g (x j)*G x) ∂γ) = _ + simp_rw [hleft] + rw [integral_finsetSum _ (fun i _ => hFi i)] + simp_rw [show ∀ i, (∫ g, g i*gibbsReplicaMean μ (H g) n (F i) ∂γ) = + s * ∫ g, gibbsReplicaMean μ (H g) n (U i)-(n:ℝ)*gibbsReplicaMean μ (H g) (n+1) (V i) ∂γ + from fun i => gaussian_replica_coordinate_ibp μ m n i j hv hh hG hC hA hD hvC hhA hGD s] + rw [← Finset.mul_sum] + congr 1 + have hi : ∀ i ∈ (Finset.univ : Finset (Fin (m+1))), Integrable + (fun g => gibbsReplicaMean μ (H g) n (U i)-(n:ℝ)*gibbsReplicaMean μ (H g) (n+1) (V i)) γ := + fun i _ => (hUi i).sub ((hVi i).const_mul n) + rw [← integral_finsetSum Finset.univ hi] + exact integral_congr_ae (ae_of_all _ hright) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/IntegrableReplicaGibbs.lean b/lean/OAI/Probability/Perceptron/Interpolation/IntegrableReplicaGibbs.lean new file mode 100644 index 0000000000000000000000000000000000000000..10c1a967252d0135bacd3cbffddb31f6362566b1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/IntegrableReplicaGibbs.lean @@ -0,0 +1,149 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.GibbsReplicaMean +import OAI.Probability.Perceptron.Variational.IntegrableGibbs + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma tilt_mean_twice_of_integrable {v w F : S → ℝ} (hw : Measurable w) + {s : ℝ} (hi : Integrable (fun x => Real.exp (s*w x)) μ) (t : ℝ) : + tiltMean (tiltLaw μ w s) v F t = tiltMean μ (fun x => s*w x+t*v x) F 1 := by + let := tilt_law_probability_of_integrable μ hi + have hp := (tilt_partition_pos_of_integrable μ hi).ne' + unfold tiltMean tiltIntegral tiltPartition + rw [tilt_law_integral_of_integrable μ hw hi,tilt_law_integral_of_integrable μ hw hi] + simp only [tiltMean,tiltIntegral,one_mul,Real.exp_add] + have he (x : S) : Real.exp (s*w x) * (Real.exp (t*v x)*F x) = + Real.exp (s*w x) * Real.exp (t*v x) * F x := by ring + simp_rw [he] + change ((∫ x, Real.exp (s*w x) * Real.exp (t*v x) * F x ∂μ) / tiltPartition μ w s) / + ((∫ x, Real.exp (s*w x) * Real.exp (t*v x) ∂μ) / tiltPartition μ w s) = _ + rw [div_div_div_cancel_right₀ hp] + +lemma tiltMean_bound_general {H F : S → ℝ} (hH : Measurable H) (hF : Measurable F) + {t C : ℝ} (hC : 0 ≤ C) (hFC : ∀ x, |F x| ≤ C) : + |tiltMean μ H F t| ≤ C := by + by_cases hi : Integrable (fun x => Real.exp (t*H x)) μ + · exact tiltMean_bound_of_integrable μ hH hF hi hFC + · simp only [tiltMean,tiltPartition,integral_undef hi,div_zero,abs_zero] + exact hC + +lemma replica_exp_integrable {H : S → ℝ} {t : ℝ} + (hi : Integrable (fun x => Real.exp (t*H x)) μ) (n : ℕ) : + Integrable (fun x : Fin n → S => Real.exp (t*replicaPotential H n x)) + (Measure.pi fun _ : Fin n => μ) := by + simp only [replicaPotential,Finset.mul_sum,Real.exp_sum] + exact Integrable.fintype_prod (fun _ => hi) + +omit [IsProbabilityMeasure μ] in +lemma tilt_law_apply_of_integrable {H : S → ℝ} {t : ℝ} + (hi : Integrable (fun x => Real.exp (t*H x)) μ) + {s : Set S} (hs : MeasurableSet s) : + tiltLaw μ H t s = (ENNReal.ofReal (tiltPartition μ H t))⁻¹ * + ENNReal.ofReal (∫ x in s, Real.exp (t * H x) ∂μ) := by + rw [tiltLaw,Measure.smul_apply,smul_eq_mul,withDensity_apply _ hs, + ← ofReal_integral_eq_lintegral_ofReal hi.integrableOn (ae_of_all _ fun x => (Real.exp_pos _).le)] + +lemma tilt_law_pi_of_integrable {H : S → ℝ} (hH : Measurable H) {t : ℝ} + (hi : Integrable (fun x => Real.exp (t*H x)) μ) (n : ℕ) : + tiltLaw (Measure.pi fun _ : Fin n => μ) (replicaPotential H n) t = + Measure.pi (fun _ : Fin n => tiltLaw μ H t) := by + let := tilt_law_probability_of_integrable μ hi + symm + apply Measure.pi_eq + intro s hs + rw [tilt_law_apply_of_integrable _ (replica_exp_integrable μ hi n) (MeasurableSet.univ_pi hs), + replica_partition μ hH n,ENNReal.ofReal_pow (tilt_partition_pos_of_integrable μ hi).le, + Measure.restrict_pi_pi] + have he (x : Fin n → S) : Real.exp (t * replicaPotential H n x) = + ∏ i, Real.exp (t * H (x i)) := by + simp only [replicaPotential,Finset.mul_sum,Real.exp_sum] + simp_rw [he] + rw [integral_fintype_prod_eq_prod (f := fun (_ : Fin n) x => Real.exp (t * H x)), + ENNReal.ofReal_prod_of_nonneg (fun i _ => integral_nonneg (fun _ => (Real.exp_pos _).le))] + simp_rw [tilt_law_apply_of_integrable μ hi (hs _)] + rw [Finset.prod_mul_distrib,Finset.prod_const,Finset.card_univ,Fintype.card_fin,ENNReal.inv_pow] + +lemma gibbsReplicaMean_integral_of_integrable {H : S → ℝ} (hH : Measurable H) + (hi : Integrable (fun x => Real.exp (H x)) μ) (n : ℕ) (G : (Fin n → S) → ℝ) : + gibbsReplicaMean μ H n G = ∫ x, G x ∂Measure.pi (fun _ : Fin n => tiltLaw μ H 1) := by + rw [← tilt_law_pi_of_integrable μ hH (by simpa only [one_mul] using hi), + tilt_law_integral_of_integrable _ (replicaPotential_measurable hH n) + (replica_exp_integrable μ (by simpa only [one_mul] using hi) n)] + rfl + +lemma gibbsReplicaMean_bound_of_integrable {H : S → ℝ} {n : ℕ} {G : (Fin n → S) → ℝ} + (hH : Measurable H) (hG : Measurable G) {D : ℝ} + (hi : Integrable (fun x => Real.exp (H x)) μ) (hGD : ∀ x, |G x| ≤ D) : + |gibbsReplicaMean μ H n G| ≤ D := + tiltMean_bound_of_integrable _ (replicaPotential_measurable hH n) hG + (replica_exp_integrable μ (by simpa only [one_mul] using hi) n) hGD + +lemma gibbsReplicaMean_coordinate_of_integrable {H F : S → ℝ} + (hH : Measurable H) (hF : Measurable F) + (hi : Integrable (fun x => Real.exp (H x)) μ) (n : ℕ) (j : Fin n) : + gibbsReplicaMean μ H n (fun x => F (x j)) = tiltMean μ H F 1 := by + have heI : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using hi + let := tilt_law_probability_of_integrable μ heI + rw [gibbsReplicaMean_integral_of_integrable μ hH hi, + ← tilt_law_integral_of_integrable μ hH heI] + have he := measurePreserving_eval (fun _ : Fin n => tiltLaw μ H 1) j + conv_rhs => rw [← he.map_eq,integral_map he.measurable.aemeasurable hF.aestronglyMeasurable] + +lemma gibbsReplicaMean_sum_of_integrable {ι : Type*} (s : Finset ι) + {H : S → ℝ} {n : ℕ} {G : ι → (Fin n → S) → ℝ} + (hH : Measurable H) (hi : Integrable (fun x => Real.exp (H x)) μ) + (hG : ∀ i ∈ s, Measurable (G i)) {D : ι → ℝ} + (hGD : ∀ i ∈ s, ∀ x, |G i x| ≤ D i) : + gibbsReplicaMean μ H n (fun x => ∑ i ∈ s, G i x) = + ∑ i ∈ s, gibbsReplicaMean μ H n (G i) := by + let := tilt_law_probability_of_integrable μ (by simpa only [one_mul] using hi : + Integrable (fun x => Real.exp (1*H x)) μ) + simp_rw [gibbsReplicaMean_integral_of_integrable μ hH hi] + exact integral_finsetSum s fun i hi => Integrable.of_bound (hG i hi).aestronglyMeasurable + (D i) (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hGD i hi x) + +lemma gibbsReplicaMean_potential_of_integrable {H F : S → ℝ} + (hH : Measurable H) (hF : Measurable F) + (hi : Integrable (fun x => Real.exp (H x)) μ) {D : ℝ} (hFD : ∀ x, |F x| ≤ D) (n : ℕ) : + gibbsReplicaMean μ H n (replicaPotential F n) = n*tiltMean μ H F 1 := by + change gibbsReplicaMean μ H n (fun x => ∑ i, F (x i)) = _ + rw [gibbsReplicaMean_sum_of_integrable μ Finset.univ (G := fun i (x : Fin n → S) => F (x i)) hH hi + (fun i _ => hF.comp (measurable_pi_apply i)) (fun i _ x => hFD (x i))] + simp_rw [gibbsReplicaMean_coordinate_of_integrable μ hH hF hi] + simp + +lemma gibbsReplicaMean_product_of_integrable {H F : S → ℝ} {n : ℕ} + {G : (Fin n → S) → ℝ} (hH : Measurable H) (hF : Measurable F) (hG : Measurable G) + (hi : Integrable (fun x => Real.exp (H x)) μ) {D B : ℝ} + (hFD : ∀ x, |F x| ≤ D) (hGB : ∀ x, |G x| ≤ B) : + gibbsReplicaMean μ H (n+1) (fun x => F (x 0)*G (fun j => x j.succ)) = + tiltMean μ H F 1*gibbsReplicaMean μ H n G := by + have heI : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using hi + let := tilt_law_probability_of_integrable μ heI + simp_rw [gibbsReplicaMean_integral_of_integrable μ hH hi] + rw [← tilt_law_integral_of_integrable μ hH heI] + let ν := tiltLaw μ H 1 + have he := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => ν) 0).symm + rw [← he.integral_comp' (fun x => F (x 0)*G (fun j => x j.succ))] + change (∫ p : S×(Fin n → S), F ((Fin.insertNth 0 p.1 p.2 : Fin (n+1) → S) 0)* + G (fun j => (Fin.insertNth 0 p.1 p.2 : Fin (n+1) → S) j.succ) + ∂ν.prod (Measure.pi fun _ => ν)) = _ + simp only [Fin.insertNth_zero',Fin.cons_zero,Fin.cons_succ] + have hFi : Integrable F ν := Integrable.of_bound hF.aestronglyMeasurable D + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hFD x) + have hGi : Integrable G (Measure.pi fun _ : Fin n => ν) := Integrable.of_bound + hG.aestronglyMeasurable B (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hGB x) + rw [integral_prod _ (hFi.mul_prod hGi)] + simp_rw [integral_const_mul] + rw [integral_mul_const] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/KernelInfiniteReplica.lean b/lean/OAI/Probability/Perceptron/Interpolation/KernelInfiniteReplica.lean new file mode 100644 index 0000000000000000000000000000000000000000..f9e02a17ac7f89afc995cfc6061d103d6b9a70f4 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/KernelInfiniteReplica.lean @@ -0,0 +1,184 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ContactGGRate + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +section + +section +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) [IsMarkovKernel κ] + +lemma kernelFiniteProduct_measurable (ι : Type*) [Fintype ι] : + Measurable (fun a => Measure.pi (fun _ : ι => κ a)) := by + apply Measurable.measure_of_isPiSystem_of_isProbabilityMeasure generateFrom_pi.symm isPiSystem_pi + rintro _ ⟨s,hs,rfl⟩ + simp_rw [Measure.pi_pi] + exact Finset.measurable_prod _ fun i _ => κ.measurable_coe (hs i (mem_univ i)) + +lemma kernelInfiniteReplica_measurable (ι : Type*) : + Measurable (fun a => Measure.infinitePi (fun _ : ι => κ a)) := by + apply Measurable.measure_of_isPiSystem_of_isProbabilityMeasure + generateFrom_measurableCylinders.symm isPiSystem_measurableCylinders + intro s hs + obtain ⟨I,E,hE,rfl⟩ := (mem_measurableCylinders s).mp hs + have hm := (Measure.measurable_coe hE).comp (kernelFiniteProduct_measurable κ I) + convert hm using 1 + funext a + change (Measure.infinitePi (fun _ : ι => κ a)) (I.restrict ⁻¹' E) = + (Measure.pi (fun _ : I => κ a)) E + have hmI : Measurable (I.restrict : (ι → S) → I → S) := by fun_prop + rw [← Measure.map_apply (f := I.restrict) hmI hE,Measure.infinitePi_map_restrict] + +def kernelInfiniteReplica (ι : Type*) : Kernel A (ι → S) := + ⟨(fun a => Measure.infinitePi (fun _ : ι => κ a)),kernelInfiniteReplica_measurable κ ι⟩ + +instance (ι : Type*) : IsMarkovKernel (kernelInfiniteReplica κ ι) := ⟨fun _ => by + change IsProbabilityMeasure (Measure.infinitePi _) + infer_instance⟩ + +lemma infiniteReplica_prefix_preserving (μ : Measure S) [IsProbabilityMeasure μ] (r : ℕ) : + MeasurePreserving (fun x : ℕ → S => fun i : Fin r => x i.val) + (Measure.infinitePi (fun _ : ℕ => μ)) (Measure.pi (fun _ : Fin r => μ)) := by + let e : (Finset.range r) ≃ Fin r := + { toFun := fun i => ⟨i.val,Finset.mem_range.mp i.property⟩ + invFun := fun i => ⟨i.val,Finset.mem_range.mpr i.isLt⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + have hp : MeasurePreserving ((Finset.range r).restrict : (ℕ → S) → (Finset.range r) → S) + (Measure.infinitePi (fun _ : ℕ => μ)) (Measure.pi (fun _ : (Finset.range r) => μ)) := + ⟨by fun_prop,Measure.infinitePi_map_restrict _⟩ + have he := measurePreserving_piCongrLeft (fun _ : Fin r => μ) e + exact he.comp hp + +lemma kernelInfiniteReplica_prefix_integral (a : A) (r : ℕ) {G : (Fin r → S) → ℝ} + (hG : Measurable G) : + (∫ x, G (fun i => x i.val) ∂kernelInfiniteReplica κ ℕ a) = + ∫ x, G x ∂Measure.pi (fun _ : Fin r => κ a) := by + have hp := infiniteReplica_prefix_preserving (κ a) r + rw [← hp.map_eq,integral_map hp.measurable.aemeasurable hG.aestronglyMeasurable] + rfl + +end +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) [IsProbabilityMeasure P] +variable (H : A → S → ℝ) (hH : Measurable (Function.uncurry H)) + +def annealedInfiniteReplicaMeasure : Measure (A × (ℕ → S)) := by + letI : IsMarkovKernel (gibbsProbabilityKernel κ H) := gibbsProbabilityKernel_markov κ H hH + exact P ⊗ₘ kernelInfiniteReplica (gibbsProbabilityKernel κ H) ℕ + +instance : IsProbabilityMeasure (annealedInfiniteReplicaMeasure κ P H hH) := by + let : IsMarkovKernel (gibbsProbabilityKernel κ H) := gibbsProbabilityKernel_markov κ H hH + unfold annealedInfiniteReplicaMeasure + infer_instance + +lemma annealedInfiniteReplica_prefix_integral (r : ℕ) {G : (Fin r → S) → ℝ} + (hG : Measurable G) {B : ℝ} (hGB : ∀ x, |G x|≤B) : + (∫ a, G (fun i => a.2 i.val) ∂annealedInfiniteReplicaMeasure κ P H hH) = + ∫ a, (∫ x, G x ∂Measure.pi (fun _ : Fin r => gibbsProbabilityKernel κ H a)) ∂P := by + let : IsMarkovKernel (gibbsProbabilityKernel κ H) := gibbsProbabilityKernel_markov κ H hH + have hm : Measurable (fun a : A × (ℕ → S) => G (fun i : Fin r => a.2 i.val)) := + hG.comp (by fun_prop) + have hi : Integrable (fun a : A × (ℕ → S) => G (fun i : Fin r => a.2 i.val)) + (annealedInfiniteReplicaMeasure κ P H hH) := + (integrable_const B).mono' hm.aestronglyMeasurable (Eventually.of_forall fun a => by + simpa only [Real.norm_eq_abs] using hGB (fun i => a.2 i.val)) + rw [annealedInfiniteReplicaMeasure,Measure.integral_compProd hi] + apply integral_congr_ae + exact Eventually.of_forall fun a => kernelInfiniteReplica_prefix_integral _ a r hG + +lemma annealedInfiniteReplica_gibbs_prefix (hexp : ∀ᵐ a ∂P, + Integrable (fun x => Real.exp (H a x)) (κ a)) (r : ℕ) {G : (Fin r → S) → ℝ} + (hG : Measurable G) {B : ℝ} (hGB : ∀ x, |G x|≤B) : + (∫ a, G (fun i => a.2 i.val) ∂annealedInfiniteReplicaMeasure κ P H hH) = + ∫ a, gibbsReplicaMean (κ a) (H a) r G ∂P := by + rw [annealedInfiniteReplica_prefix_integral κ P H hH r hG hGB] + apply integral_congr_ae + filter_upwards [hexp] with a ha + exact gibbsProbabilityKernel_replica_integral κ H hH a ha r G + +end + +def sourceJointOverlap {N k : ℕ} (x y : NormalizedSpin N×IndexedLeaf k) : CompactJointOverlap := + (⟨spinOverlap x.1 y.1,abs_le.mp (spinOverlap_abs_le x.1 y.1)⟩, + ⟨((indexedCommonDepth k y.2 x.2).val:ℝ)/(k+1:ℕ),by + constructor + · positivity + · apply (div_le_one (by positivity : (0:ℝ)<(k+1:ℕ))).mpr + exact_mod_cast (indexedCommonDepth k y.2 x.2).isLt.le⟩) + +lemma sourceJointOverlap_measurable (N k : ℕ) : + Measurable (Function.uncurry (sourceJointOverlap (N:=N) (k:=k))) := by + apply Measurable.prodMk + · apply Measurable.subtype_mk + exact (measurable_fst.fst.subtype_val.inner measurable_snd.fst.subtype_val) + · apply Measurable.subtype_mk + have hm : Measurable (fun a : IndexedLeaf k × IndexedLeaf k => + ((indexedCommonDepth k a.2 a.1).val:ℝ)/(k+1:ℕ)) := measurable_of_countable _ + exact hm.comp (measurable_fst.snd.prodMk measurable_snd.snd) + +def sourceJointArray {N k : ℕ} (x : ℕ → NormalizedSpin N×IndexedLeaf k) : CompactArray CompactJointOverlap := + fun i j => sourceJointOverlap (x i) (x j) + +lemma sourceJointArray_measurable (N k : ℕ) : Measurable (sourceJointArray (N:=N) (k:=k)) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + exact (sourceJointOverlap_measurable N k).comp (show Measurable (fun x : ℕ → NormalizedSpin N×IndexedLeaf k => (x i,x j)) from by fun_prop) + +def sourceGibbsArrayLaw (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) : + ProbabilityMeasure (CompactArray CompactJointOverlap) := + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + let H := sourceCouplingHamiltonian n k f p d h u + let μ := annealedInfiniteReplicaMeasure (sourceFullSpinLeafKernel n k) P H + (sourceCouplingHamiltonian_measurable n k f p d h u) + ⟨μ.map (fun a => sourceJointArray a.2),inferInstance⟩ + +lemma sourceGibbsArray_integral (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) + {F : CompactArray CompactJointOverlap → ℝ} (hF : Measurable F) : + (∫ Q, F Q ∂sourceGibbsArrayLaw n k f p d h u z t) = + ∫ a, F (sourceJointArray a.2) ∂annealedInfiniteReplicaMeasure (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) (sourceCouplingHamiltonian_measurable n k f p d h u) := by + exact integral_map ((sourceJointArray_measurable (n+1) k).comp measurable_snd).aemeasurable hF.aestronglyMeasurable + +lemma sourceGibbsArray_block_integral (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0≤h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) (r : ℕ) + {F : CompactBlock CompactJointOverlap r → ℝ} (hF : Measurable F) + {B : ℝ} (hFB : ∀ Q, |F Q|≤B) : + (∫ Q, F (compactBlock r Q) ∂sourceGibbsArrayLaw n k f p d h u z t) = + ∫ a, gibbsReplicaMean (sourceFullSpinLeafKernel n k a) + (sourceCouplingHamiltonian n k f p d h u a) r + (fun x => F (fun i j => sourceJointOverlap (x i) (x j))) + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw := by + rw [sourceGibbsArray_integral n k f p d h u z t (F:=fun Q => F (compactBlock r Q)) + (hF.comp (compactBlock_continuous r).measurable)] + have he := sourceCoupling_all_exp_ae n k f p d h hh0 hh u 0 z t + have he0 : ∀ᵐ a ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw, + Integrable (fun x => Real.exp (sourceCouplingHamiltonian n k f p d h u a x)) + (sourceFullSpinLeafKernel n k a) := by + filter_upwards [he] with a ha + simpa only [sourceFullSpinLeafKernel,Kernel.comap_apply,zero_mul,add_zero] using ha 0 + exact annealedInfiniteReplica_gibbs_prefix (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) _ + (sourceCouplingHamiltonian_measurable n k f p d h u) he0 r + (hF.comp (Measurable.of_eval fun row => Measurable.of_eval fun column => + (sourceJointOverlap_measurable (n+1) k).comp + ((measurable_pi_apply row).prodMk (measurable_pi_apply column)))) + (fun x => hFB _) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/KernelReplicaGibbs.lean b/lean/OAI/Probability/Perceptron/Interpolation/KernelReplicaGibbs.lean new file mode 100644 index 0000000000000000000000000000000000000000..391acd2abe2019ae72badd0ca427966b16cfd036 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/KernelReplicaGibbs.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ReplicaIBP +import OAI.Probability.Perceptron.Variational.UnboundedContact + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +section +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) [IsMarkovKernel κ] + +lemma kernelReplica_measurable (n : ℕ) : + Measurable (fun a => Measure.pi (fun _ : Fin n => κ a)) := by + apply Measurable.measure_of_isPiSystem_of_isProbabilityMeasure generateFrom_pi.symm isPiSystem_pi + rintro _ ⟨s,hs,rfl⟩ + simp_rw [Measure.pi_pi] + exact Finset.measurable_prod _ fun i _ => κ.measurable_coe (hs i (mem_univ i)) + +def kernelReplica (n : ℕ) : Kernel A (Fin n → S) := + ⟨(fun a => Measure.pi (fun _ : Fin n => κ a)),kernelReplica_measurable κ n⟩ + +instance (n : ℕ) : IsMarkovKernel (kernelReplica κ n) := ⟨fun _ => by + change IsProbabilityMeasure (Measure.pi _) + infer_instance⟩ + +lemma kernel_replicaMean_measurable {H : A → S → ℝ} {n : ℕ} {G : A → (Fin n → S) → ℝ} + (hH : Measurable (Function.uncurry H)) (hG : Measurable (Function.uncurry G)) : + Measurable (fun a => gibbsReplicaMean (κ a) (H a) n (G a)) := by + change Measurable (fun a => tiltMean (kernelReplica κ n a) (replicaPotential (H a) n) (G a) 1) + apply kernel_tiltMean_measurable (kernelReplica κ n) (H := fun a => replicaPotential (H a) n) _ hG + change Measurable (fun a : A × (Fin n → S) => ∑ i, H a.1 (a.2 i)) + exact Finset.measurable_sum _ fun i _ => hH.comp + (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd)) + +lemma kernel_replicaMean_bounded_integrable (P : Measure A) [IsFiniteMeasure P] + {H : A → S → ℝ} {n : ℕ} {G : A → (Fin n → S) → ℝ} + (hH : Measurable (Function.uncurry H)) (hG : Measurable (Function.uncurry G)) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ a x, |G a x| ≤ B) : + Integrable (fun a => gibbsReplicaMean (κ a) (H a) n (G a)) P := by + apply Integrable.of_bound (kernel_replicaMean_measurable κ hH hG).aestronglyMeasurable B + exact ae_of_all _ fun a => by + simpa only [Real.norm_eq_abs,gibbsReplicaMean] using tiltMean_bound_general (Measure.pi fun _ : Fin n => κ a) + (replicaPotential_measurable hH.of_uncurry_left n) hG.of_uncurry_left hB (hGB a) + +lemma kernel_replica_energy_integrable (P : Measure A) + {H Y : A → S → ℝ} {n : ℕ} (j : Fin n) {G : (Fin n → S) → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) (hG : Measurable G) + (he : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) + (hi : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)*Y a x) (κ a)) + (hYi : Integrable (fun a => tiltMean (κ a) (H a) (fun x => |Y a x|) 1) P) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Integrable (fun a => gibbsReplicaMean (κ a) (H a) n (fun x => Y a (x j)*G x)) P := by + apply (hYi.const_mul B).mono' + (kernel_replicaMean_measurable κ hH ((hY.comp (measurable_fst.prodMk + ((measurable_pi_apply j).comp measurable_snd))).mul (hG.comp measurable_snd))).aestronglyMeasurable + filter_upwards [he,hi] with a he hi + simpa only [Real.norm_eq_abs] using replicaMean_energy_bound (κ a) j hH.of_uncurry_left + hY.of_uncurry_left hG he hi hB hGB + +lemma kernel_replica_energy_factorization (P : Measure A) [IsProbabilityMeasure P] + {H Y : A → S → ℝ} {n : ℕ} (j : Fin n) {G : (Fin n → S) → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) (hG : Measurable G) + (he : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) + (hi : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)*Y a x) (κ a)) + (hYi : Integrable (fun a => tiltMean (κ a) (H a) (fun x => |Y a x|) 1) P) + (c : ℝ) (hci : Integrable (fun a => tiltMean (κ a) (H a) (fun x => |Y a x-c|) 1) P) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + |(∫ a, gibbsReplicaMean (κ a) (H a) n (fun x => Y a (x j)*G x) ∂P) - + c*(∫ a, gibbsReplicaMean (κ a) (H a) n G ∂P)| ≤ + B*∫ a, tiltMean (κ a) (H a) (fun x => |Y a x-c|) 1 ∂P := by + have hI := kernel_replica_energy_integrable κ P j hH hY hG he hi hYi hB hGB + have hGI := kernel_replicaMean_bounded_integrable κ P (G := fun _ => G) hH (hG.comp measurable_snd) hB (fun _ => hGB) + rw [← integral_const_mul,← integral_sub hI (hGI.const_mul c),← integral_const_mul] + calc + _ ≤ ∫ a, |gibbsReplicaMean (κ a) (H a) n (fun x => Y a (x j)*G x) - + c*gibbsReplicaMean (κ a) (H a) n G| ∂P := by + simpa only [Real.norm_eq_abs] using norm_integral_le_integral_norm + (fun a => gibbsReplicaMean (κ a) (H a) n (fun x => Y a (x j)*G x) - + c*gibbsReplicaMean (κ a) (H a) n G) + _ ≤ _ := by + apply integral_mono_ae (hI.sub (hGI.const_mul c)).abs (hci.const_mul B) + filter_upwards [he,hi] with a he hi + have hci' := he.mul_const c + have hs := replicaMean_energy_sub (κ a) j hH.of_uncurry_left hY.of_uncurry_left + measurable_const hG he hi hci' hGB + rw [replicaMean_const_mul] at hs + simp only [Pi.sub_apply] at * + rw [← hs] + have hii : Integrable (fun x => Real.exp (H a x)*(Y a x-c)) (κ a) := + (hi.sub hci').congr (ae_of_all _ fun x => by dsimp; ring) + exact replicaMean_energy_bound (κ a) j hH.of_uncurry_left (hY.of_uncurry_left.sub measurable_const) + hG he hii hB hGB + +end + +lemma sourceJointMonomial_measurable {N k : ℕ} (p d : Fin N → ℕ) (j : Fin N) : + Measurable (Function.uncurry (sourceJointMonomial (k := k) p d j)) := by + have ht : Measurable (fun a : (NormalizedSpin N×IndexedLeaf k)×(NormalizedSpin N×IndexedLeaf k) => + ((indexedCommonDepth k a.2.2 a.1.2).val:ℝ)/(k+1:ℕ)) := by + exact (Measurable.of_discrete (f := fun a : IndexedLeaf k×IndexedLeaf k => + ((indexedCommonDepth k a.1 a.2).val:ℝ)/(k+1:ℕ))).comp (measurable_snd.snd.prodMk measurable_fst.snd) + have hr : Measurable (fun a : (NormalizedSpin N×IndexedLeaf k)×(NormalizedSpin N×IndexedLeaf k) => + spinOverlap a.1.1 a.2.1) := by + exact (measurable_subtype_coe.comp measurable_fst.fst).inner + (measurable_subtype_coe.comp measurable_snd.fst) + exact (ht.pow_const _).mul (hr.pow_const _) + +lemma sourceJointMonomial_abs_le {N k : ℕ} (p d : Fin N → ℕ) (j : Fin N) + (x y : NormalizedSpin N×IndexedLeaf k) : |sourceJointMonomial p d j x y| ≤ 1 := by + have ht0 : 0 ≤ ((indexedCommonDepth k y.2 x.2).val:ℝ)/(k+1:ℕ) := by positivity + have ht1 : ((indexedCommonDepth k y.2 x.2).val:ℝ)/(k+1:ℕ) ≤ 1 := by + rw [div_le_one (by positivity)] + exact_mod_cast (indexedCommonDepth k y.2 x.2).isLt.le + rw [sourceJointMonomial,abs_mul,abs_pow,abs_pow,abs_of_nonneg ht0] + exact (mul_le_of_le_one_left (by positivity) (pow_le_one₀ ht0 ht1)).trans + (pow_le_one₀ (abs_nonneg _) (spinOverlap_abs_le _ _)) + +lemma sourceReplica_covariance_measurable {N k r : ℕ} (p d : Fin N → ℕ) (j : Fin N) + (i l : Fin r) : Measurable (fun x : Fin r → NormalizedSpin N×IndexedLeaf k => + sourceJointMonomial p d j (x i) (x l)) := by + have hs : Measurable (fun x : Fin r → NormalizedSpin N×IndexedLeaf k => (x i,x l)) := + (measurable_pi_apply i).prodMk (measurable_pi_apply l) + have hm := (sourceJointMonomial_measurable (N := N) (k := k) p d j).comp hs + exact hm + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/NonlinearReplicaIBP.lean b/lean/OAI/Probability/Perceptron/Interpolation/NonlinearReplicaIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..dad31a7f55556760e64c23a3fe108ea99ba45d44 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/NonlinearReplicaIBP.lean @@ -0,0 +1,127 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.BoundedGibbsDerivative + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma bounded_gaussian_replica_coordinate_ibp {m n : ℕ} (i : Fin (m+1)) + {H H' : (Fin (m+1) → ℝ) → S → ℝ} + {F F' : (Fin (m+1) → ℝ) → (Fin n → S) → ℝ} + (hH : Measurable (Function.uncurry H)) (hH' : Measurable (Function.uncurry H')) + (hF : Measurable (Function.uncurry F)) (hF' : Measurable (Function.uncurry F')) + {A B C D : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hHA : ∀ g x, |H g x| ≤ A) (hHB : ∀ g x, |H' g x| ≤ B) + (hFC : ∀ g x, |F g x| ≤ C) (hFD : ∀ g x, |F' g x| ≤ D) + (hdH : ∀ g t x, HasDerivAt (fun u => H (i.insertNth u g) x) (H' (i.insertNth t g) x) t) + (hdF : ∀ g t x, HasDerivAt (fun u => F (i.insertNth u g) x) (F' (i.insertNth t g) x) t) : + (∫ g, g i * gibbsReplicaMean μ (H g) n (F g) + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ g, gibbsReplicaMean μ (H g) n + (fun x => replicaPotential (H' g) n x*F g x+F' g x) - + n*gibbsReplicaMean μ (H g) (n+1) + (fun x => H' g (x 0)*F g (fun j => x j.succ)) + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + have hr (J : (Fin (m+1) → ℝ) → S → ℝ) + (hJ : Measurable (Function.uncurry J)) : + Measurable (Function.uncurry (fun g => replicaPotential (J g) n)) := by + change Measurable (fun p : (Fin (m+1) → ℝ)×(Fin n → S) => ∑ j : Fin n, J p.1 (p.2 j)) + exact Finset.measurable_sum _ fun j _ => hJ.comp + (measurable_fst.prodMk ((measurable_pi_apply j).comp measurable_snd)) + have he := bounded_gaussian_gibbs_coordinate_ibp (Measure.pi (fun _ : Fin n => μ)) i + (hr H hH) (hr H' hH') hF hF' (by positivity) (by positivity) hC hD + (fun g => replicaPotential_bound (hHA g) n) + (fun g => replicaPotential_bound (hHB g) n) hFC hFD + (fun g t x => HasDerivAt.fun_sum fun j _ => hdH g t (x j)) hdF + refine he.trans ?_ + apply integral_congr_ae + filter_upwards [] with g + have hm : Measurable (H g) := hH.comp (measurable_const.prodMk measurable_id) + have hm' : Measurable (H' g) := hH'.comp (measurable_const.prodMk measurable_id) + have fm : Measurable (F g) := hF.comp (measurable_const.prodMk measurable_id) + rw [tilt_replica_sum μ hm hm' hA (hHA g) (hHB g) n 1] + simp only [gibbsReplicaMean] + rw [tilt_replica_new_product μ hm hm' fm hA (hHA g) (hHB g) (hFC g) 1] + change _ - _ * ((n:ℝ)*_) = _ - (n:ℝ)*(_*_) + ring + +lemma nonlinear_pattern_replica_coordinate_ibp {m n : ℕ} (i : Fin (m+1)) (j : Fin n) + (f : Jet3) {v : Fin (m+1) → S → ℝ} {h : S → ℝ} {U : (Fin n → S) → ℝ} + (hv : ∀ l, Measurable (v l)) (hh : Measurable h) (hU : Measurable U) + {A C D : ℝ} (hA : 0 ≤ A) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hhA : ∀ x, |h x| ≤ A) (hvC : ∀ l x, |v l x| ≤ C) (hUD : ∀ x, |U x| ≤ D) : + let b := gaussianField (m+1) v + let H := fun g x => h x+f.f (b g x) + (∫ g, g i*gibbsReplicaMean μ (H g) n (fun x => f.d1 (b g (x j))*U x) + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ g, gibbsReplicaMean μ (H g) n + (fun x => ((∑ l, f.d1 (b g (x l))*v i (x l))*f.d1 (b g (x j))+ + f.d2 (b g (x j))*v i (x j))*U x) - + n*gibbsReplicaMean μ (H g) (n+1) + (fun x => f.d1 (b g (x 0))*v i (x 0)* + (f.d1 (b g (x j.succ))*U (fun l => x l.succ))) + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + dsimp only + let b := gaussianField (m+1) v + let H := fun g x => h x+f.f (b g x) + let H' := fun g x => f.d1 (b g x)*v i x + let F := fun g (x : Fin n → S) => f.d1 (b g (x j))*U x + let F' := fun g (x : Fin n → S) => f.d2 (b g (x j))*v i (x j)*U x + have hb : Measurable (Function.uncurry b) := gaussianField_measurable hv + have hb' : Measurable (fun p : (Fin (m+1) → ℝ)×(Fin n → S) => b p.1 (p.2 j)) := + hb.comp (measurable_fst.prodMk ((measurable_pi_apply j).comp measurable_snd)) + have hHm : Measurable (Function.uncurry H) := + (hh.comp measurable_snd).add (f.f.continuous.measurable.comp hb) + have hH'm : Measurable (Function.uncurry H') := + (f.d1.continuous.measurable.comp hb).mul ((hv i).comp measurable_snd) + have hFm : Measurable (Function.uncurry F) := + (f.d1.continuous.measurable.comp hb').mul (hU.comp measurable_snd) + have hF'm : Measurable (Function.uncurry F') := + ((f.d2.continuous.measurable.comp hb').mul + ((hv i).comp ((measurable_pi_apply j).comp measurable_snd))).mul (hU.comp measurable_snd) + have hHA (g x) : |H g x| ≤ A+‖f.f‖ := + (abs_add_le _ _).trans (add_le_add (hhA x) (f.f.norm_coe_le_norm _)) + have hHB (g x) : |H' g x| ≤ ‖f.d1‖*C := by + dsimp only [H'] + rw [abs_mul] + exact mul_le_mul (f.d1.norm_coe_le_norm _) (hvC i x) (abs_nonneg _) (norm_nonneg _) + have hFC (g x) : |F g x| ≤ ‖f.d1‖*D := by + dsimp only [F] + rw [abs_mul] + exact mul_le_mul (f.d1.norm_coe_le_norm _) (hUD x) (abs_nonneg _) (norm_nonneg _) + have hFD (g x) : |F' g x| ≤ ‖f.d2‖*C*D := by + dsimp only [F'] + rw [abs_mul,abs_mul] + exact mul_le_mul (mul_le_mul (f.d2.norm_coe_le_norm _) (hvC i _) + (abs_nonneg _) (norm_nonneg _)) (hUD _) (abs_nonneg _) (by positivity) + have hdH (g t x) : HasDerivAt (fun s => H (i.insertNth s g) x) + (H' (i.insertNth t g) x) t := by + dsimp [H,H',b] + simp_rw [gaussianField_insertNth] + convert! ((f.has1 _).comp t (((hasDerivAt_id t).mul_const (v i x)).add_const + (gaussianField m (fun l => v (i.succAbove l)) g x))).const_add (h x) using 1 + simp only [one_mul,id_eq] + have hdF (g t x) : HasDerivAt (fun s => F (i.insertNth s g) x) + (F' (i.insertNth t g) x) t := by + dsimp [F,F',b] + simp_rw [gaussianField_insertNth] + convert! (((f.has2 _).comp t (((hasDerivAt_id t).mul_const (v i (x j))).add_const + (gaussianField m (fun l => v (i.succAbove l)) g (x j)))).mul_const (U x)) using 1 + simp only [one_mul,id_eq] + have he := bounded_gaussian_replica_coordinate_ibp μ i hHm hH'm hFm hF'm + (by positivity) (by positivity) (by positivity) (by positivity) hHA hHB hFC hFD hdH hdF + convert! he using 1 + apply integral_congr_ae + filter_upwards [] with g + congr 2 + funext x + dsimp only [H', F, F', replicaPotential, b] + ring +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/OverlapArray.lean b/lean/OAI/Probability/Perceptron/Interpolation/OverlapArray.lean new file mode 100644 index 0000000000000000000000000000000000000000..45aa5eeddd0b64623d8c6595dfac4b5ace75801d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/OverlapArray.lean @@ -0,0 +1,427 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.OverlapBlock + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev OverlapArray := ℕ → ℕ → ℝ +def relabelArray (π : Equiv.Perm ℕ) (Q : OverlapArray) : OverlapArray := + fun i j => Q (π i) (π j) + +def OverlapSwapInvariant (μ : Measure OverlapArray) : Prop := + ∀ i j : ℕ, MeasurePreserving (relabelArray (Equiv.swap i j)) μ μ + +def copyIndex (r j : ℕ) (i : Fin (r + 1)) : ℕ := if i.val = r then j else i.val + +def copyBlock (r j : ℕ) (Q : OverlapArray) : OverlapBlock (r + 1) := + fun a b => Q (copyIndex r j a) (copyIndex r j b) + +def copyEvent (r : ℕ) (s : Set (OverlapBlock (r + 1))) (j : ℕ) : Set OverlapArray := + copyBlock r j ⁻¹' s + +@[simp] lemma copyIndex_self (r : ℕ) (i : Fin (r + 1)) : copyIndex r r i = i := by + unfold copyIndex + split_ifs with h + · exact h.symm + · rfl + +lemma copyBlock_measurable (r j : ℕ) : Measurable (copyBlock r j) := by + exact Measurable.of_eval fun firstIndex => Measurable.of_eval fun secondIndex => + (measurable_pi_apply _).comp (measurable_pi_apply _) + +lemma copyEvent_measurable (r : ℕ) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) (j : ℕ) : MeasurableSet (copyEvent r s j) := + hs.preimage (copyBlock_measurable r j) + +lemma copyBlock_self (r : ℕ) (Q : OverlapArray) : + copyBlock r r Q = overlapBlock id (r + 1) Q := by + ext i j + simp [copyBlock, overlapBlock] + +lemma copyIndex_relabel (r j : ℕ) (π : Equiv.Perm ℕ) + (hπ : ∀ a < r, π a = a) (i : Fin (r + 1)) : + π (copyIndex r j i) = copyIndex r (π j) i := by + by_cases hi : i.val = r + · simp [copyIndex, hi] + · simp only [copyIndex, ite_eq_right hi] + exact hπ i (by omega) + +lemma copyBlock_relabel (r j : ℕ) (π : Equiv.Perm ℕ) + (hπ : ∀ a < r, π a = a) (Q : OverlapArray) : + copyBlock r j (relabelArray π Q) = copyBlock r (π j) Q := by + ext a b + simp only [copyBlock, relabelArray, copyIndex_relabel r j π hπ] + +lemma copyEvent_relabel (r j : ℕ) (π : Equiv.Perm ℕ) + (hπ : ∀ a < r, π a = a) (s : Set (OverlapBlock (r + 1))) : + relabelArray π ⁻¹' copyEvent r s j = copyEvent r s (π j) := by + ext Q + simp only [copyEvent, mem_preimage, copyBlock_relabel r j π hπ] + +def uniqueEvent {Ω ι : Type*} (A : ι → Set Ω) (i : ι) : Set Ω := + {ω | ω ∈ A i ∧ ∀ j, j ≠ i → ω ∉ A j} + +lemma uniqueEvent_measurable {Ω ι : Type*} [MeasurableSpace Ω] [Countable ι] + (A : ι → Set Ω) (hA : ∀ i, MeasurableSet (A i)) (i : ι) : + MeasurableSet (uniqueEvent A i) := by + simp only [uniqueEvent, ofPred_and, ofPred_forall] + exact (hA i).inter (MeasurableSet.iInter fun j => + MeasurableSet.iInter fun _ => (hA j).compl) + +lemma uniqueEvent_disjoint {Ω ι : Type*} (A : ι → Set Ω) : + Pairwise (fun i j => Disjoint (uniqueEvent A i) (uniqueEvent A j)) := by + intro i j hij + apply Set.disjoint_left.mpr + intro ω hi hj + exact hi.2 j hij.symm hj.1 + +lemma uniqueEvent_probability_bound {Ω ι : Type*} [MeasurableSpace Ω] [Fintype ι] + (μ : Measure Ω) [IsProbabilityMeasure μ] (A : ι → Set Ω) + (hA : ∀ i, MeasurableSet (A i)) (i₀ : ι) + (hsame : ∀ i, μ.real (uniqueEvent A i) = μ.real (uniqueEvent A i₀)) : + Fintype.card ι * μ.real (uniqueEvent A i₀) ≤ 1 := by + have h := sum_measureReal_le_measureReal_univ (μ := μ) (s := Finset.univ) + (t := uniqueEvent A) (fun i _ => uniqueEvent_measurable A hA i) + (fun i _ j _ hij => uniqueEvent_disjoint A hij) + simp only [hsame, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] at h + simpa [Measure.real] using h + +lemma uniqueEvent_preimage {Ω ι : Type*} {f : Ω → Ω} (A : ι → Set Ω) + (e : Equiv.Perm ι) (h : ∀ j, f ⁻¹' A j = A (e j)) (i : ι) : + f ⁻¹' uniqueEvent A i = uniqueEvent A (e i) := by + ext ω + have hm (j : ι) : f ω ∈ A j ↔ ω ∈ A (e j) := by + change ω ∈ f ⁻¹' A j ↔ ω ∈ A (e j) + rw [h] + constructor + · intro hw + refine ⟨(hm i).mp hw.1, ?_⟩ + intro j hji hj + apply hw.2 (e.symm j) (fun heq => hji (by rw [← e.apply_symm_apply j, heq])) + exact (hm _).mpr (by simpa using hj) + · intro hw + refine ⟨(hm i).mpr hw.1, ?_⟩ + intro j hji hj + exact hw.2 (e j) (fun h' => hji (e.injective h')) ((hm j).mp hj) + +lemma uniqueCopy_probability_bound (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (r k : ℕ) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) : + (k + 1 : ℝ) * μ.real (uniqueEvent + (fun j : Fin (k + 1) => copyEvent r s (r + j)) 0) ≤ 1 := by + let A : Fin (k + 1) → Set OverlapArray := fun j => copyEvent r s (r + j) + have hA (j) : MeasurableSet (A j) := copyEvent_measurable r hs _ + have hsame (i : Fin (k + 1)) : μ.real (uniqueEvent A i) = μ.real (uniqueEvent A 0) := by + let e : Equiv.Perm (Fin (k + 1)) := Equiv.swap i 0 + let π : Equiv.Perm ℕ := Equiv.swap (r + i) (r + (0 : Fin (k + 1))) + have hfix : ∀ a < r, π a = a := by + intro a ha + exact Equiv.swap_apply_of_ne_of_ne (by omega) (by simp; omega) + have hinj : Function.Injective (fun j : Fin (k + 1) => r + j.val) := by + intro a b hab + apply Fin.ext + exact Nat.add_left_cancel hab + have hmap (j : Fin (k + 1)) : relabelArray π ⁻¹' A j = A (e j) := by + dsimp [A] + rw [copyEvent_relabel r _ π hfix] + congr 1 + exact (hinj.map_swap i 0 j).symm + have he : e 0 = i := Equiv.swap_apply_right _ _ + rw [← he, ← uniqueEvent_preimage A e hmap] + exact (hEx _ _).measureReal_preimage (uniqueEvent_measurable A hA 0).nullMeasurableSet + have h := uniqueEvent_probability_bound μ A hA 0 hsame + simpa only [Fintype.card_fin, Nat.cast_add, Nat.cast_one] using h + +def prefixBlock {n m : ℕ} (h : n ≤ m) (Q : OverlapBlock m) : OverlapBlock n := + fun a b => Q (Fin.castLE h a) (Fin.castLE h b) + +lemma prefixBlock_measurable {n m : ℕ} (h : n ≤ m) : Measurable (prefixBlock h) := by + exact Measurable.of_eval fun firstIndex => Measurable.of_eval fun secondIndex => + (measurable_pi_apply _).comp (measurable_pi_apply _) + +def starMatrices (r : ℕ) (s : Set (OverlapBlock (r + 1))) (t : ℝ) (k : ℕ) : + Set (OverlapBlock (r + 1 + k)) := + {Q | prefixBlock (Nat.le_add_right (r + 1) k) Q ∈ s ∧ + ∀ j : Fin (r + 1 + k), j.val ≠ r → Q ⟨r, by omega⟩ j < t} + +def starEvent (r : ℕ) (s : Set (OverlapBlock (r + 1))) (t : ℝ) (k : ℕ) : + Set OverlapArray := + copyEvent r s r ∩ {Q | ∀ j < r + 1 + k, j ≠ r → Q r j < t} + +lemma starMatrices_measurable (r : ℕ) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) (t : ℝ) (k : ℕ) : MeasurableSet (starMatrices r s t k) := by + simp only [starMatrices, ofPred_and, ofPred_forall] + apply MeasurableSet.inter (hs.preimage (prefixBlock_measurable _)) + apply MeasurableSet.iInter + intro j + apply MeasurableSet.iInter + intro _ + exact measurableSet_lt ((measurable_pi_apply j).comp (measurable_pi_apply _)) measurable_const + +lemma starEvent_measurable (r : ℕ) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) (t : ℝ) (k : ℕ) : MeasurableSet (starEvent r s t k) := by + apply (copyEvent_measurable r hs r).inter + simp only [ofPred_forall] + apply MeasurableSet.iInter + intro j + apply MeasurableSet.iInter + intro _ + apply MeasurableSet.iInter + intro _ + exact measurableSet_lt ((measurable_pi_apply j).comp (measurable_pi_apply r)) measurable_const + +lemma starEvent_preimage (r : ℕ) (s : Set (OverlapBlock (r + 1))) (t : ℝ) (k : ℕ) : + overlapBlock id (r + 1 + k) ⁻¹' starMatrices r s t k = starEvent r s t k := by + ext Q + have hprefix : prefixBlock (Nat.le_add_right (r + 1) k) + (overlapBlock id (r + 1 + k) Q) = copyBlock r r Q := by + ext a b + simp [prefixBlock, overlapBlock, copyBlock] + simp only [mem_preimage, starMatrices, mem_ofPred_eq, hprefix, starEvent, + copyEvent, mem_inter_iff, mem_preimage] + constructor + · rintro ⟨h, h'⟩ + exact ⟨h, fun j hj hne => h' ⟨j, hj⟩ hne⟩ + · rintro ⟨h, h'⟩ + exact ⟨h, fun j hne => h' j j.isLt hne⟩ + +lemma starEvent_succ (r : ℕ) (s : Set (OverlapBlock (r + 1))) (t : ℝ) (k : ℕ) : + starEvent r s t (k + 1) = + starEvent r s t k ∩ {Q | Q r (r + 1 + k) < t} := by + ext Q + constructor + · rintro ⟨hA, hQ⟩ + exact ⟨⟨hA, fun j hj hne => hQ j (by omega) hne⟩, + hQ (r + 1 + k) (by omega) (by omega)⟩ + · rintro ⟨⟨hA, hQ⟩, hn⟩ + refine ⟨hA, ?_⟩ + intro j hj hne + by_cases hlt : j < r + 1 + k + · exact hQ j hlt hne + · have heq : j = r + 1 + k := by omega + simpa only [mem_ofPred_eq, heq] using hn + +lemma starEvent_zero (r : ℕ) (s : Set (OverlapBlock (r + 1))) (t : ℝ) + (hrow : ∀ Q ∈ copyEvent r s r, ∀ j < r, Q r j < t) : + starEvent r s t 0 = copyEvent r s r := by + ext Q + constructor + · exact fun h => h.1 + · intro h + exact ⟨h, fun j hj hne => hrow Q h j (by omega)⟩ + +lemma gg_star_recurrence (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hGG : GhirlandaGuerra μ id) {r : ℕ} (hr : 1 ≤ r) + {s : Set (OverlapBlock (r + 1))} (hs : MeasurableSet s) (t : ℝ) (k : ℕ) : + ((r + 1 + k : ℕ) : ℝ) * μ.real (starEvent r s t (k + 1)) = + (((r + 1 + k : ℕ) : ℝ) - 1 + μ.real {Q | Q 0 1 < t}) * + μ.real (starEvent r s t k) := by + classical + let m := r + 1 + k + let i : Fin m := ⟨r, by dsimp [m]; omega⟩ + have hm : 2 ≤ m := by dsimp [m]; omega + have hmpos : (0 : ℝ) < m := by exact_mod_cast (by omega : 0 < m) + have h := hGG m hm i (starMatrices r s t k) (starMatrices_measurable r hs t k) + (Iio t) measurableSet_Iio + rw [starEvent_preimage] at h + change μ.real (starEvent r s t k ∩ {Q | Q r m < t}) = + μ.real (starEvent r s t k) * μ.real {Q | Q 0 1 < t} / m + + (∑ j ∈ Finset.univ.erase i, + μ.real (starEvent r s t k ∩ {Q | Q r j < t})) / m at h + have hpair (j : Fin m) (hne : j ≠ i) : + starEvent r s t k ∩ {Q | Q r j < t} = starEvent r s t k := by + apply inter_eq_left.mpr + intro Q hQ + exact hQ.2 j j.isLt (fun heq => hne (Fin.ext heq)) + rw [Finset.sum_congr rfl (fun j hj => congrArg μ.real + (hpair j (Finset.ne_of_mem_erase hj)))] at h + have hcard : ((Finset.univ.erase i).card : ℝ) = (m : ℝ) - 1 := by + simp only [Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ, Fintype.card_fin] + rw [Nat.cast_sub (by omega)] + norm_num + simp only [Finset.sum_const, nsmul_eq_mul, hcard] at h + rw [← starEvent_succ] at h + have hmul := congrArg (fun x : ℝ => (m : ℝ) * x) h + field_simp at hmul + dsimp [m] at hmul + nlinarith [hmul] + +def duplicateEvent (r : ℕ) (s : Set (OverlapBlock (r + 1))) (t : ℝ) (j : ℕ) : + Set OverlapArray := + copyEvent r s r ∩ copyEvent r s j ∩ {Q | Q r j < t} + +lemma duplicateEvent_measurable (r : ℕ) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) (t : ℝ) (j : ℕ) : MeasurableSet (duplicateEvent r s t j) := + ((copyEvent_measurable r hs r).inter (copyEvent_measurable r hs j)).inter + (measurableSet_lt ((measurable_pi_apply j).comp (measurable_pi_apply r)) measurable_const) + +lemma duplicateEvent_relabel (r j : ℕ) (π : Equiv.Perm ℕ) + (hπ : ∀ a < r, π a = a) (hr : π r = r) + (s : Set (OverlapBlock (r + 1))) (t : ℝ) : + relabelArray π ⁻¹' duplicateEvent r s t j = duplicateEvent r s t (π j) := by + ext Q + simp only [duplicateEvent, copyEvent, mem_preimage, mem_inter_iff, mem_ofPred_eq, + copyBlock_relabel r r π hπ, copyBlock_relabel r j π hπ, hr, relabelArray] + +lemma duplicateEvent_null_future (μ : Measure OverlapArray) + (hEx : OverlapSwapInvariant μ) (r : ℕ) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) (t : ℝ) + (hzero : μ (duplicateEvent r s t (r + 1)) = 0) {j : ℕ} (hj : r + 1 ≤ j) : + μ (duplicateEvent r s t j) = 0 := by + let π : Equiv.Perm ℕ := Equiv.swap (r + 1) j + have hfix : ∀ a ≤ r, π a = a := by + intro a ha + exact Equiv.swap_apply_of_ne_of_ne (by omega) (by omega) + calc + μ (duplicateEvent r s t j) = μ (relabelArray π ⁻¹' duplicateEvent r s t (r + 1)) := by + rw [duplicateEvent_relabel r (r + 1) π (fun a ha => hfix a ha.le) (hfix r le_rfl)] + simp only [π, Equiv.swap_apply_left] + _ = μ (duplicateEvent r s t (r + 1)) := + (hEx _ _).measure_preimage (duplicateEvent_measurable r hs t (r + 1)).nullMeasurableSet + _ = 0 := hzero + +lemma star_unique_bound_of_no_duplication (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (r : ℕ) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) (t : ℝ) + (hzero : μ (duplicateEvent r s t (r + 1)) = 0) (k : ℕ) : + (k + 1 : ℝ) * μ.real (starEvent r s t k) ≤ 1 := by + have hnul (j : Fin (k + 1)) : ∀ᵐ Q ∂μ, j ≠ 0 → Q ∉ duplicateEvent r s t (r + j) := by + by_cases hj : j = 0 + · exact Filter.Eventually.of_forall fun _ h => (h hj).elim + · have hz : μ (duplicateEvent r s t (r + j)) = 0 := + duplicateEvent_null_future μ hEx r hs t hzero (by + have : j.val ≠ 0 := fun h => hj (Fin.ext h) + omega) + filter_upwards [measure_eq_zero_iff_ae_notMem.mp hz] with Q hQ + exact fun _ => hQ + have hae : starEvent r s t k ≤ᵐ[μ] + uniqueEvent (fun j : Fin (k + 1) => copyEvent r s (r + j)) 0 := by + filter_upwards [ae_all_iff.mpr hnul] with Q hQ + intro hstar + refine ⟨by simpa using hstar.1, ?_⟩ + intro j hj hmem + apply hQ j hj + refine ⟨⟨hstar.1, hmem⟩, ?_⟩ + exact hstar.2 (r + j) (by have := j.isLt; omega) (by + have : j.val ≠ 0 := fun h => hj (Fin.ext h) + omega) + have hle : μ.real (starEvent r s t k) ≤ μ.real + (uniqueEvent (fun j : Fin (k + 1) => copyEvent r s (r + j)) 0) := + ENNReal.toReal_mono (measure_ne_top _ _) (measure_mono_ae hae) + exact (mul_le_mul_of_nonneg_left hle (by positivity)).trans + (uniqueCopy_probability_bound μ hEx r k hs) + +lemma edge_probability_swap (μ : Measure OverlapArray) (hEx : OverlapSwapInvariant μ) + (a b i j : ℕ) (t : ℝ) : + μ.real {Q | Q (Equiv.swap a b i) (Equiv.swap a b j) < t} = + μ.real {Q | Q i j < t} := by + exact (hEx a b).measureReal_preimage + (measurableSet_lt ((measurable_pi_apply j).comp (measurable_pi_apply i)) + measurable_const).nullMeasurableSet + +theorem gg_duplicate_last (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + {r : ℕ} (hr : 1 ≤ r) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) (t : ℝ) + (hA : 0 < μ.real (copyEvent r s r)) + (hrow : ∀ Q ∈ copyEvent r s r, ∀ j < r, Q r j < t) : + 0 < μ.real (duplicateEvent r s t (r + 1)) := by + by_contra hbad + have hz : μ (duplicateEvent r s t (r + 1)) = 0 := + (measureReal_eq_zero_iff (measure_ne_top _ _)).mp (le_antisymm (not_lt.mp hbad) (measureReal_nonneg)) + have heq : μ.real {Q | Q r 0 < t} = μ.real {Q | Q 0 1 < t} := by + have h₁ := edge_probability_swap μ hEx 1 r 1 0 t + have h₂ := edge_probability_swap μ hEx 0 1 0 1 t + have hr0 : (0 : ℕ) ≠ r := by omega + simp only [Equiv.swap_apply_left, Equiv.swap_apply_right, + Equiv.swap_apply_of_ne_of_ne (by decide : (0 : ℕ) ≠ 1) hr0] at h₁ h₂ + exact h₁.trans h₂ + have hζ : 0 < μ.real {Q | Q 0 1 < t} := by + rw [← heq] + refine hA.trans_le (measureReal_mono ?_) + exact fun Q hQ => hrow Q hQ 0 (by omega) + apply gg_star_growth_impossible (a := fun k => μ.real (starEvent r s t k)) + (N := (r + 1 : ℕ)) (ζ := μ.real {Q | Q 0 1 < t}) + (by exact_mod_cast (by omega : 2 ≤ r + 1)) hζ (fun _ => measureReal_nonneg) + · rwa [starEvent_zero r s t hrow] + · intro k + simpa only [Nat.cast_add] using gg_star_recurrence μ hGG hr hs t k + · exact star_unique_bound_of_no_duplication μ hEx r hs t hz + +def relabelBlock {n : ℕ} (e : Equiv.Perm (Fin n)) (B : OverlapBlock n) : OverlapBlock n := + fun i j => B (e i) (e j) + +def replaceIndex {n : ℕ} (p : Fin n) (j : ℕ) (a : Fin n) : ℕ := + if a = p then j else a.val + +def replaceBlock {n : ℕ} (p : Fin n) (j : ℕ) (Q : OverlapArray) : OverlapBlock n := + fun a b => Q (replaceIndex p j a) (replaceIndex p j b) + +def replaceEvent {n : ℕ} (p : Fin n) (s : Set (OverlapBlock n)) (j : ℕ) : Set OverlapArray := + replaceBlock p j ⁻¹' s + +lemma relabelBlock_measurable {n : ℕ} (e : Equiv.Perm (Fin n)) : + Measurable (relabelBlock e) := + Measurable.of_eval fun _ => Measurable.of_eval fun _ => + (measurable_pi_apply _).comp (measurable_pi_apply _) + +lemma replaceBlock_measurable {n : ℕ} (p : Fin n) (j : ℕ) : + Measurable (replaceBlock p j) := + Measurable.of_eval fun _ => Measurable.of_eval fun _ => + (measurable_pi_apply _).comp (measurable_pi_apply _) + +lemma fin_swap_val {n : ℕ} (p q a : Fin n) : + (Equiv.swap p q a).val = Equiv.swap p.val q.val a.val := + Fin.val_injective.map_swap p q a + +lemma relabelBlock_swap {n : ℕ} (p q : Fin n) (Q : OverlapArray) : + relabelBlock (Equiv.swap p q) (overlapBlock id n Q) = + overlapBlock id n (relabelArray (Equiv.swap p.val q.val) Q) := by + ext a b + simp only [relabelBlock, overlapBlock, id_eq, relabelArray, fin_swap_val] + +lemma relabelArray_swap_swap (p q : ℕ) (Q : OverlapArray) : + relabelArray (Equiv.swap p q) (relabelArray (Equiv.swap p q) Q) = Q := by + ext a b + simp [relabelArray] + +lemma relabelBlock_swap_swap {n : ℕ} (p q : Fin n) (B : OverlapBlock n) : + relabelBlock (Equiv.swap p q) (relabelBlock (Equiv.swap p q) B) = B := by + ext a b + simp [relabelBlock] + +lemma replaceBlock_last (r j : ℕ) (Q : OverlapArray) : + replaceBlock (Fin.last r) j Q = copyBlock r j Q := by + have h (a : Fin (r + 1)) : replaceIndex (Fin.last r) j a = copyIndex r j a := by + simp [replaceIndex, copyIndex, Fin.ext_iff] + ext a b + simp only [replaceBlock, copyBlock, h] + +lemma replaceBlock_swap {n : ℕ} (p q : Fin n) {j : ℕ} (hj : n ≤ j) (Q : OverlapArray) : + relabelBlock (Equiv.swap p q) + (replaceBlock q j (relabelArray (Equiv.swap p.val q.val) Q)) = + replaceBlock p j Q := by + have h (a : Fin n) : Equiv.swap p.val q.val (replaceIndex q j (Equiv.swap p q a)) = + replaceIndex p j a := by + by_cases ha : a = p + · subst a + simp only [Equiv.swap_apply_left, replaceIndex, ↓reduceIte] + exact Equiv.swap_apply_of_ne_of_ne (by have := p.isLt; omega) (by have := q.isLt; omega) + · have he : Equiv.swap p q a ≠ q := by + intro h + apply ha + have := congrArg (Equiv.swap p q) h + simpa using this + simp only [replaceIndex, ite_eq_right he, ite_eq_right ha, fin_swap_val, + Equiv.swap_apply_self] + ext a b + exact congrArg₂ Q (h a) (h b) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/OverlapBlock.lean b/lean/OAI/Probability/Perceptron/Interpolation/OverlapBlock.lean new file mode 100644 index 0000000000000000000000000000000000000000..cfe790f6872790586ea3dee297cb16635a4178c3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/OverlapBlock.lean @@ -0,0 +1,314 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction + +namespace SphericalPerceptronFreeEnergy + +section Positivity + +variable {Ω : Type*} [MeasurableSpace Ω] + +abbrev OverlapBlock (n : ℕ) := Fin n → Fin n → ℝ + +def overlapBlock (R : Ω → ℕ → ℕ → ℝ) (n : ℕ) (ω : Ω) : OverlapBlock n := + fun i j => R ω i j + +def GhirlandaGuerra (μ : Measure Ω) (R : Ω → ℕ → ℕ → ℝ) : Prop := + ∀ (n : ℕ), 2 ≤ n → ∀ (i : Fin n) (s : Set (OverlapBlock n)), MeasurableSet s → + ∀ t : Set ℝ, MeasurableSet t → + μ.real ((overlapBlock R n) ⁻¹' s ∩ {ω | R ω i n ∈ t}) = + μ.real ((overlapBlock R n) ⁻¹' s) * μ.real {ω | R ω 0 1 ∈ t} / n + + (∑ j ∈ (Finset.univ.erase i), + μ.real ((overlapBlock R n) ⁻¹' s ∩ {ω | R ω i j ∈ t})) / n + +def negativeMatrices (n : ℕ) (δ : ℝ) : Set (OverlapBlock n) := + {q | ∀ i j : Fin n, i < j → q i j < -δ} + +def negativeClique (R : Ω → ℕ → ℕ → ℝ) (n : ℕ) (δ : ℝ) : Set Ω := + (overlapBlock R n) ⁻¹' negativeMatrices n δ + +lemma negativeMatrices_measurable (n : ℕ) (δ : ℝ) : + MeasurableSet (negativeMatrices n δ) := by + unfold negativeMatrices + simp only [ofPred_forall] + apply MeasurableSet.iInter + intro i + apply MeasurableSet.iInter + intro j + apply MeasurableSet.iInter + intro _h + exact measurableSet_lt ((measurable_pi_apply j).comp (measurable_pi_apply i)) measurable_const + +lemma overlapBlock_measurable {R : Ω → ℕ → ℕ → ℝ} + (hR : ∀ i j, Measurable (fun ω => R ω i j)) (n : ℕ) : + Measurable (overlapBlock R n) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + exact hR i j + +lemma negativeClique_measurable {R : Ω → ℕ → ℕ → ℝ} + (hR : ∀ i j, Measurable (fun ω => R ω i j)) (n : ℕ) (δ : ℝ) : + MeasurableSet (negativeClique R n δ) := + (negativeMatrices_measurable n δ).preimage (overlapBlock_measurable hR n) + +omit [MeasurableSpace Ω] in +lemma mem_negativeClique {R : Ω → ℕ → ℕ → ℝ} {n : ℕ} {δ : ℝ} {ω : Ω} : + ω ∈ negativeClique R n δ ↔ ∀ i j : Fin n, i < j → R ω i j < -δ := Iff.rfl + +omit [MeasurableSpace Ω] in +lemma negativeClique_succ (R : Ω → ℕ → ℕ → ℝ) (n : ℕ) (δ : ℝ) : + negativeClique R (n + 1) δ = negativeClique R n δ ∩ + ⋂ i : Fin n, {ω | R ω i n < -δ} := by + ext ω + simp only [mem_inter_iff, mem_iInter, mem_ofPred] + constructor + · intro h + refine ⟨?_, ?_⟩ + · intro i j hij + exact h i.castSucc j.castSucc (by exact hij) + · intro i + exact h i.castSucc (Fin.last n) (by simp) + · rintro ⟨hold, hnew⟩ i j hij + by_cases hj : j.val < n + · exact hold ⟨i, lt_trans hij hj⟩ ⟨j, hj⟩ hij + · have jeq : (j : ℕ) = n := by omega + have hi : (i : ℕ) < n := by omega + simpa only [overlapBlock, jeq] using hnew ⟨i, hi⟩ + +omit [MeasurableSpace Ω] in +lemma negativeClique_two (R : Ω → ℕ → ℕ → ℝ) (δ : ℝ) : + negativeClique R 2 δ = {ω | R ω 0 1 < -δ} := by + ext ω + constructor + · intro h + exact h 0 1 (by decide) + · intro h i j hij + have hi : (i : ℕ) = 0 := by omega + have hj : (j : ℕ) = 1 := by omega + change R ω 0 1 < -δ at h + simpa only [overlapBlock, hi, hj] using h + +lemma measureReal_inter_iInter_lower (μ : Measure Ω) [IsProbabilityMeasure μ] + {ι : Type*} [Fintype ι] {E : Set Ω} {T : ι → Set Ω} + (hT : ∀ i, MeasurableSet (T i)) : + μ.real E - ∑ i, μ.real (E \ T i) ≤ μ.real (E ∩ ⋂ i, T i) := by + classical + have hu : E \ (⋂ i, T i) = ⋃ i ∈ (Finset.univ : Finset ι), E \ T i := by + ext ω + simp + have hbound : μ.real (E \ ⋂ i, T i) ≤ ∑ i, μ.real (E \ T i) := by + rw [hu] + exact measureReal_biUnion_finset_le _ _ + have hsum := measureReal_inter_add_sdiff (μ := μ) (s := E) (MeasurableSet.iInter hT) + linarith + +lemma gg_negativeClique_extension (μ : Measure Ω) [IsProbabilityMeasure μ] + {R : Ω → ℕ → ℕ → ℝ} (hR : ∀ i j, Measurable (fun ω => R ω i j)) + (hsym : ∀ᵐ ω ∂μ, ∀ i j, R ω i j = R ω j i) + (hGG : GhirlandaGuerra μ R) {n : ℕ} (hn : 2 ≤ n) (δ : ℝ) : + μ.real {ω | R ω 0 1 < -δ} * μ.real (negativeClique R n δ) ≤ + μ.real (negativeClique R (n + 1) δ) := by + classical + let b := μ.real {ω | R ω 0 1 < -δ} + let p := μ.real (negativeClique R n δ) + have hnpos : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n) + have htail (i : Fin n) : + μ.real (negativeClique R n δ ∩ {ω | R ω i n < -δ}) = p * (b + (n - 1)) / n := by + have h := hGG n hn i (negativeMatrices n δ) (negativeMatrices_measurable n δ) + (Iio (-δ)) measurableSet_Iio + have hpair (j : Fin n) (hji : j ≠ i) : + μ.real (negativeClique R n δ ∩ {ω | R ω i j < -δ}) = p := by + apply congrArg ENNReal.toReal + apply measure_congr + filter_upwards [hsym] with ω hω + apply propext + constructor + · exact fun h => h.1 + · intro h + refine ⟨h, ?_⟩ + change R ω i j < -δ + rcases lt_or_gt_of_ne (Ne.symm hji) with hij | hij + · exact h i j hij + · rw [hω i j] + exact h j i hij + change μ.real (negativeClique R n δ ∩ {ω | R ω i n < -δ}) = + p * b / n + (∑ j ∈ Finset.univ.erase i, + μ.real (negativeClique R n δ ∩ {ω | R ω i j < -δ})) / n at h + rw [Finset.sum_congr rfl (fun j hj => hpair j (Finset.ne_of_mem_erase hj))] at h + have hcard : ((Finset.univ.erase i).card : ℝ) = (n : ℝ) - 1 := by + simp only [Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ, Fintype.card_fin] + rw [Nat.cast_sub (by omega)] + norm_num + simp only [Finset.sum_const, nsmul_eq_mul, hcard] at h + rw [h] + ring + have hbad (i : Fin n) : + μ.real (negativeClique R n δ \ {ω | R ω i n < -δ}) = p * (1 - b) / n := by + have h := measureReal_inter_add_sdiff (μ := μ) (s := negativeClique R n δ) + (t := {ω | R ω i n < -δ}) (measurableSet_lt (hR i n) measurable_const) + rw [htail i] at h + change _ + _ = p at h + apply (eq_div_iff (ne_of_gt hnpos)).mpr + field_simp at h + nlinarith + rw [negativeClique_succ] + have h := measureReal_inter_iInter_lower μ (E := negativeClique R n δ) + (T := fun i : Fin n => {ω | R ω i n < -δ}) + (fun i => measurableSet_lt (hR i n) measurable_const) + simp_rw [hbad] at h + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at h + have he : p - (n : ℝ) * (p * (1 - b) / n) = b * p := by + field_simp + ring + rwa [he] at h + +lemma negative_gram_sum_bound {n : ℕ} {Q : Fin n → Fin n → ℝ} {δ : ℝ} + (hsym : ∀ i j, Q i j = Q j i) (hdiag : ∀ i, Q i i ≤ 1) + (hneg : ∀ i j, i < j → Q i j < -δ) : + (∑ i, ∑ j, Q i j) ≤ (n : ℝ) * (1 - δ * ((n : ℝ) - 1)) := by + classical + have hrow (i : Fin n) : (∑ j, Q i j) ≤ 1 - δ * ((n : ℝ) - 1) := by + have hpair (j : Fin n) (hji : j ≠ i) : Q i j ≤ -δ := by + rcases lt_or_gt_of_ne (Ne.symm hji) with hij | hij + · exact (hneg i j hij).le + · rw [hsym i j] + exact (hneg j i hij).le + have hs : (∑ j ∈ Finset.univ.erase i, Q i j) ≤ + ∑ _j ∈ Finset.univ.erase i, -δ := + Finset.sum_le_sum fun j hj => hpair j (Finset.ne_of_mem_erase hj) + have hc : ((Finset.univ.erase i).card : ℝ) = (n : ℝ) - 1 := by + simp only [Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ, Fintype.card_fin] + rw [Nat.cast_sub (by have := i.isLt; omega)] + norm_num + simp only [Finset.sum_const, nsmul_eq_mul, hc] at hs + have ht := Finset.sum_erase_add Finset.univ (Q i) (Finset.mem_univ i) + nlinarith [hdiag i] + calc + _ ≤ ∑ _i : Fin n, (1 - δ * ((n : ℝ) - 1)) := Finset.sum_le_sum fun i _ => hrow i + _ = _ := by simp; ring + +lemma negativeClique_null (μ : Measure Ω) [IsProbabilityMeasure μ] + {R : Ω → ℕ → ℕ → ℝ} + (hsym : ∀ᵐ ω ∂μ, ∀ i j, R ω i j = R ω j i) + (hdiag : ∀ᵐ ω ∂μ, ∀ i, R ω i i ≤ 1) + (hpos : ∀ n : ℕ, ∀ᵐ ω ∂μ, 0 ≤ ∑ i : Fin n, ∑ j : Fin n, R ω i j) + {n : ℕ} {δ : ℝ} (hn : 0 < n) (hδ : 1 < δ * ((n : ℝ) - 1)) : + μ (negativeClique R n δ) = 0 := by + have hnot : ∀ᵐ ω ∂μ, ω ∉ negativeClique R n δ := by + filter_upwards [hsym, hdiag, hpos n] with ω hωs hωd hωp + intro hωn + have hb := negative_gram_sum_bound + (Q := fun i j : Fin n => R ω i j) + (fun i j => hωs i j) (fun i => hωd i) hωn + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have : (n : ℝ) * (1 - δ * ((n : ℝ) - 1)) < 0 := + mul_neg_of_pos_of_neg hn' (by linarith) + linarith + simpa only [not_not, ofPred_mem_eq] using ae_iff.mp hnot + +theorem gg_negative_threshold_null (μ : Measure Ω) [IsProbabilityMeasure μ] + {R : Ω → ℕ → ℕ → ℝ} (hR : ∀ i j, Measurable (fun ω => R ω i j)) + (hsym : ∀ᵐ ω ∂μ, ∀ i j, R ω i j = R ω j i) + (hdiag : ∀ᵐ ω ∂μ, ∀ i, R ω i i ≤ 1) + (hpos : ∀ n : ℕ, ∀ᵐ ω ∂μ, 0 ≤ ∑ i : Fin n, ∑ j : Fin n, R ω i j) + (hGG : GhirlandaGuerra μ R) {δ : ℝ} (hδ : 0 < δ) : + μ {ω | R ω 0 1 < -δ} = 0 := by + apply (measureReal_eq_zero_iff (μ := μ)).mp + apply le_antisymm _ measureReal_nonneg + by_contra hb + have hbpos : 0 < μ.real {ω | R ω 0 1 < -δ} := lt_of_not_ge hb + have hcpos (k : ℕ) : 0 < μ.real (negativeClique R (k + 2) δ) := by + induction k with + | zero => simpa only [zero_add, negativeClique_two] using hbpos + | succ k hk => + have he := gg_negativeClique_extension μ hR hsym hGG (n := k + 2) (by omega) δ + exact (mul_pos hbpos hk).trans_le he + obtain ⟨k, hk⟩ := exists_nat_gt (1 / δ) + have hkδ : 1 < (k : ℝ) * δ := (div_lt_iff₀ hδ).mp hk + have he : 1 < δ * (((k + 2 : ℕ) : ℝ) - 1) := by + push_cast + nlinarith + have hz := negativeClique_null μ hsym hdiag hpos (n := k + 2) (by omega) he + have hz' : μ.real (negativeClique R (k + 2) δ) = 0 := (measureReal_eq_zero_iff (μ := μ)).mpr hz + linarith [hcpos k] + +theorem gg_overlap_nonnegative (μ : Measure Ω) [IsProbabilityMeasure μ] + {R : Ω → ℕ → ℕ → ℝ} (hR : ∀ i j, Measurable (fun ω => R ω i j)) + (hsym : ∀ᵐ ω ∂μ, ∀ i j, R ω i j = R ω j i) + (hdiag : ∀ᵐ ω ∂μ, ∀ i, R ω i i ≤ 1) + (hpos : ∀ n : ℕ, ∀ᵐ ω ∂μ, 0 ≤ ∑ i : Fin n, ∑ j : Fin n, R ω i j) + (hGG : GhirlandaGuerra μ R) : + ∀ᵐ ω ∂μ, 0 ≤ R ω 0 1 := by + have ht (k : ℕ) : ∀ᵐ ω ∂μ, -(1 / ((k : ℝ) + 1)) ≤ R ω 0 1 := by + rw [ae_iff] + simpa only [not_le] using gg_negative_threshold_null μ hR hsym hdiag hpos hGG + (δ := 1 / ((k : ℝ) + 1)) (by positivity) + filter_upwards [ae_all_iff.mpr ht] with ω hω + have hlim : Tendsto (fun k : ℕ => -(1 / ((k : ℝ) + 1))) atTop (𝓝 (0 : ℝ)) := by + simpa using (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)).neg + exact le_of_tendsto hlim (Eventually.of_forall hω) + +end Positivity + +lemma gg_star_growth_impossible {a : ℕ → ℝ} {N ζ : ℝ} + (hN : 2 ≤ N) (hζ : 0 < ζ) (ha : ∀ k, 0 ≤ a k) (hzero : 0 < a 0) + (hrec : ∀ k, (N + k) * a (k + 1) = (N + k - 1 + ζ) * a k) + (hbound : ∀ k : ℕ, (k + 1 : ℝ) * a k ≤ 1) : False := by + let b : ℕ → ℝ := fun k => (N + k - 1) * a k + have hbzero : 0 < b 0 := by dsimp [b]; nlinarith + have hdiff (k : ℕ) : b (k + 1) = b k + ζ * a k := by + dsimp [b] + push_cast + nlinarith [hrec k] + have hbmono : Monotone b := monotone_nat_of_le_succ fun k => by + rw [hdiff] + exact le_add_of_nonneg_right (mul_nonneg hζ.le (ha k)) + have hblower (k : ℕ) : b 0 ≤ b k := hbmono (Nat.zero_le k) + have hbupper (k : ℕ) : b k ≤ N := by + have hk : (0 : ℝ) ≤ k := Nat.cast_nonneg k + calc + b k ≤ N * ((k + 1 : ℝ) * a k) := by + dsimp [b] + have : N + (k : ℝ) - 1 ≤ N * (k + 1) := by nlinarith + nlinarith [mul_le_mul_of_nonneg_right this (ha k)] + _ ≤ N := by nlinarith [hbound k] + have hsum (k : ℕ) : ζ * ∑ j ∈ Finset.range k, a j = b k - b 0 := by + induction k with + | zero => simp + | succ k ih => rw [Finset.sum_range_succ, mul_add, ih, hdiff]; ring + have hasum : Summable a := by + apply summable_of_sum_range_le ha (c := N / ζ) + intro k + apply (le_div_iff₀ hζ).mpr + nlinarith [hsum k, hbupper k] + have hdom (k : ℕ) : (1 / (k + 1 : ℝ)) ≤ (N / b 0) * a k := by + have hk : (0 : ℝ) < k + 1 := by positivity + rw [div_le_iff₀ hk] + have : b 0 ≤ N * ((k + 1 : ℝ) * a k) := by + calc b 0 ≤ b k := hblower k + _ ≤ N * ((k + 1 : ℝ) * a k) := by + dsimp [b] + have hknonneg : (0 : ℝ) ≤ k := Nat.cast_nonneg k + have : N + (k : ℝ) - 1 ≤ N * (k + 1) := by nlinarith + nlinarith [mul_le_mul_of_nonneg_right this (ha k)] + have hn : N * ((k + 1 : ℝ) * a k) / b 0 ≥ 1 := + (le_div_iff₀ hbzero).mpr (by simpa using this) + calc 1 ≤ N * ((k + 1 : ℝ) * a k) / b 0 := hn + _ = (N / b 0) * a k * (k + 1 : ℝ) := by ring + have hharm : Summable (fun k : ℕ => 1 / (k + 1 : ℝ)) := + Summable.of_nonneg_of_le (fun _ => by positivity) hdom (hasum.mul_left (N / b 0)) + have hharm' : Summable (fun k : ℕ => 1 / ((k + 1 : ℕ) : ℝ)) := by + simpa only [Nat.cast_add, Nat.cast_one] using hharm + exact Real.not_summable_one_div_natCast ((summable_nat_add_iff 1).mp hharm') + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/PerturbationComparison.lean b/lean/OAI/Probability/Perceptron/Interpolation/PerturbationComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..9478330b9815d6a165a4416225488f19f8cbb472 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/PerturbationComparison.lean @@ -0,0 +1,77 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CouplingDerivative +import OAI.Probability.Perceptron.Sphere.CoordinateBoxBound + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma perturbationAmplitude_one_mul (N : ℕ) (u : Fin N → ℝ) (j : Fin N) : + perturbationAmplitude N u j=perturbationAmplitude N (fun _ => 1) j*u j := by + simp only [perturbationAmplitude,mul_one] + +lemma perturbation_normalized_square_sum (n : ℕ) : + (∑ j : Fin (n+1), 4*perturbationAmplitude (n+1) (fun _ => 1) j^2/(n+1:ℕ)) ≤ + 4*perturbationScale (n+1)^2 := by + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + have he (j : Fin (n+1)) : + 4*perturbationAmplitude (n+1) (fun _ => 1) j^2/(n+1:ℕ) = + 4*perturbationScale (n+1)^2*((1/2:ℝ)^(j.val+1))^2 := by + simp only [perturbationAmplitude,mul_one,perturbationWeight_eq,mul_pow,Real.sq_sqrt hn.le] + field_simp + calc + _ = ∑ j : Fin (n+1), 4*perturbationScale (n+1)^2*((1/2:ℝ)^(j.val+1))^2 := Finset.sum_congr rfl fun j _ => he j + _ ≤ ∑ j : Fin (n+1), 4*perturbationScale (n+1)^2*(1/2:ℝ)^(j.val+1) := by + apply Finset.sum_le_sum + intro j _ + apply mul_le_mul_of_nonneg_left _ (by positivity) + have hw0 : (0:ℝ) ≤ (1/2:ℝ)^(j.val+1) := by positivity + have hw1 : (1/2:ℝ)^(j.val+1) ≤ 1 := pow_le_one₀ (by norm_num) (by norm_num) + nlinarith + _ = 4*perturbationScale (n+1)^2 * ∑ j : Fin (n+1), (1/2:ℝ)^(j.val+1) := by rw [Finset.mul_sum] + _ ≤ _ := by + simpa using mul_le_mul_of_nonneg_left (half_power_sum_le_one (n+1)) + (show 0 ≤ 4*perturbationScale (n+1)^2 from by positivity) + +lemma sourceExpectedPressure_box_comparison (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 1) j^2/(n+1:ℕ))*|v j-u j| := by + apply box_sum_coordinate_comparison (a := (0:ℝ)) (b := (2:ℝ)) (hu := hu) (hv := hv) + intro w hw j + obtain ⟨D,hD,hDb⟩ := sourceExpectedPressure_coordinate_derivative_bound n k f p d h hh0 hh w j z hz hz0 hz1 t + refine ⟨D,hD,hDb.trans ?_⟩ + apply div_le_div_of_nonneg_right _ (by positivity) + rw [perturbationAmplitude_one_mul (n+1) w j] + rw [← mul_assoc,← pow_two,abs_mul,abs_of_nonneg (sq_nonneg _),abs_of_nonneg (hw j).1] + nlinarith [mul_le_mul_of_nonneg_left (hw j).2 (sq_nonneg (perturbationAmplitude (n+1) (fun _ => 1) j))] + +lemma sourceExpectedPressure_perturbation_comparison (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 1) j^2/(n+1:ℕ))*2 := by + apply Finset.sum_le_sum + intro j _ + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact abs_le.mpr ⟨by linarith [(hu j).2,(hv j).1],by linarith [(hu j).1,(hv j).2]⟩ + _ = 2*∑ j : Fin (n+1), 4*perturbationAmplitude (n+1) (fun _ => 1) j^2/(n+1:ℕ) := by rw [Finset.mul_sum]; congr 1; ext j; ring + _ ≤ _ := by nlinarith [perturbation_normalized_square_sum n] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/PerturbationContact.lean b/lean/OAI/Probability/Perceptron/Interpolation/PerturbationContact.lean new file mode 100644 index 0000000000000000000000000000000000000000..a895f1e312a49a6ae86343cbf376b84d48a3aa55 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/PerturbationContact.lean @@ -0,0 +1,130 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.PerturbationComparison +import OAI.Probability.Perceptron.Sphere.CoordinateContact +import OAI.Probability.Perceptron.Variational.CompactJointMonomials + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def sourceExpectedPressure (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) (u : Fin (n+1) → ℝ) : ℝ := + ∫ a, sourceKernelPressure n k f p d u h a ∂((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + +def sourcePenaltyWeight (N : ℕ) (j : Fin N) : ℝ := (2:ℝ)^(-((j.val+1:ℕ):ℤ)) + +lemma sourceExpectedPressure_continuousOn (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 1) (fun _ => 2)) := by + apply box_comparison_continuous + (L := fun j => 4*perturbationAmplitude (n+1) (fun _ => 1) j^2/(n+1:ℕ)) + (fun j => by positivity) + intro u hu v hv + apply sourceExpectedPressure_box_comparison n k f p d h hh0 hh z hz hz0 hz1 t + · exact fun j => ⟨(by linarith [hu.1 j]),hu.2 j⟩ + · exact fun j => ⟨(by linarith [hv.1 j]),hv.2 j⟩ + +lemma source_perturbation_contact_exists (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 1) (fun _ => 2), + IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k f p d h z t v) + (Icc (fun _ : Fin (n+1) => 1) (fun _ => 2)) u := + exists_quadratic_box_min _ _ (sourceExpectedPressure_continuousOn n k f p d h hh0 hh z hz hz0 hz1 t) + +lemma source_perturbation_contact_coord (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 1) (fun _ => 2)) + (hmin : IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k f p d h z t v) + (Icc (fun _ : Fin (n+1) => 1) (fun _ => 2)) u) (j : Fin (n+1)) : + sourcePenaltyWeight (n+1) j*(u j-3/2)^2 ≤ 8*perturbationScale (n+1)^2 := by + have hc : |sourceExpectedPressure n k f p d h z t u- + sourceExpectedPressure n k f p d h z t (fun _ => 3/2)| ≤ 8*perturbationScale (n+1)^2 := + sourceExpectedPressure_perturbation_comparison n k f p d h hh0 hh z hz hz0 hz1 t + (fun j => by constructor <;> norm_num) + (fun j => ⟨by linarith [hu.1 j],hu.2 j⟩) + exact quadratic_box_min_coord (fun j => by unfold sourcePenaltyWeight; positivity) hmin hc j + +lemma source_perturbation_contact_interior (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 1) (fun _ => 2)) + (hmin : IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k f p d h z t v) + (Icc (fun _ : Fin (n+1) => 1) (fun _ => 2)) u) (j : Fin (n+1)) + (hsmall : 8*perturbationScale (n+1)^2 < sourcePenaltyWeight (n+1) j/16) : + u j ∈ Ioo (5/4) (7/4) := by + have hr := source_perturbation_contact_coord n k f p d h hh0 hh z hz hz0 hz1 t hu hmin j + have hc : 0 nlinarith [sq_nonneg (u j-5/4),sq_nonneg (u j-7/4)] + +lemma single_coordinate_box {I : Type*} [DecidableEq I] + {u : I → ℝ} (hu : ∀ i, u i ∈ Icc 1 2) (j : I) + (hj : u j ∈ Ioo (5/4) (7/4)) {s : ℝ} (hs : |s| ≤ 1/4) : + ∀ i, (u+Pi.single j s : I → ℝ) i ∈ Icc 1 2 := by + intro i + by_cases hi : i=j + · subst i + simp only [Pi.add_apply,Pi.single_eq_same] + exact ⟨by linarith [hj.1,(abs_le.mp hs).1],by linarith [hj.2,(abs_le.mp hs).2]⟩ + · simpa [Pi.single_eq_of_ne hi] using hu i + +lemma source_contact_compact_gg_rate (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 1) (fun _ => 2)) + (hmin : IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k f p d h z t v) + (Icc (fun _ : Fin (n+1) => 1) (fun _ => 2)) u) (j : Fin (n+1)) + {H T : ℝ} (hH : 0 ≤ H) (hhH : h 0 ≤ H) (ht : (t:ℝ) ≤ T) + (hsmall : 8*perturbationScale (n+1)^2 < sourcePenaltyWeight (n+1) j/16) + (hs : (n+1:ℕ)^(-(1:ℝ)/4) ≤ (1/4:ℝ)) + (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) : + |compactGGDefect (sourceGibbsArrayLaw n k f p d h u z t) r i G (compactJointMonomial (p j) (d j))| ≤ + ‖G‖/(sourcePenaltyWeight (n+1) j)^2 * + (Real.sqrt (2*sourcePenaltyWeight (n+1) j)*(n+1:ℕ)^(-(3:ℝ)/8)+ + (sourcePenaltyWeight (n+1) j+4*Real.sqrt (enrichedVarianceConstant k z f H T))* + (n+1:ℕ)^(-(1:ℝ)/8)) := by + have hj := source_perturbation_contact_interior n k f p d h hh0 hh z hz hz0 hz1 t hu hmin j hsmall + have hui : ∀ i, u i ∈ Icc 1 2 := fun i => ⟨hu.1 i,hu.2 i⟩ + have hp := single_coordinate_box hui j hj (s := (n+1:ℕ)^(-(1:ℝ)/4)) + (by rwa [abs_of_nonneg (by positivity)]) + have hm := single_coordinate_box hui j hj (s := -((n+1:ℕ)^(-(1:ℝ)/4))) + (by rwa [abs_neg,abs_of_nonneg (by positivity)]) + have hloc := quadratic_box_min_local_direction hu hmin j + (show u j ∈ Ioo 1 2 from ⟨by linarith [hj.1],by linarith [hj.2]⟩) + have hplus := quadratic_box_min_direction hmin j ((n+1:ℕ)^(-(1:ℝ)/4)) ⟨fun i => (hp i).1,fun i => (hp i).2⟩ + have hminus := quadratic_box_min_direction hmin j (-((n+1:ℕ)^(-(1:ℝ)/4))) ⟨fun i => (hm i).1,fun i => (hm i).2⟩ + have hObs : Measurable (fun x : Fin r → NormalizedSpin (n+1) × IndexedLeaf k => + G (fun a b => sourceJointOverlap (x a) (x b))) := by + apply G.continuous.measurable.comp + apply Measurable.of_eval; intro row; apply Measurable.of_eval; intro column + exact (sourceJointOverlap_measurable (n+1) k).comp + (show Measurable (fun replica : Fin r → NormalizedSpin (n+1) × IndexedLeaf k => + (replica row,replica column)) + from (measurable_pi_apply row).prodMk (measurable_pi_apply column)) + rw [source_compact_gg_defect n k f p d h hh0 hh u j z t r i G,abs_neg] + apply source_contact_joint_gg_rate n k f p d h hh0 hh u j z hz hz0 hz1 t hH hhH ht + (by positivity) hui hp hm hloc hplus hminus r i + hObs (norm_nonneg _) (fun x => by + simpa only [Real.norm_eq_abs] using G.norm_coe_le_norm (fun a b => sourceJointOverlap (x a) (x b))) + (by unfold sourcePenaltyWeight; positivity) rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/ReplicaIBP.lean b/lean/OAI/Probability/Perceptron/Interpolation/ReplicaIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..64a1c729694878b627abd24e7e2afa2504db2094 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/ReplicaIBP.lean @@ -0,0 +1,83 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianCoupling +import OAI.Probability.Perceptron.Variational.IndexedGaussianCovariance +import OAI.Probability.Perceptron.Variational.CountableGaussianFullIBP + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma sourceGaussianTestRow_measurable {N k : ℕ} (p d : Fin N → ℕ) + (h : Fin (k+1) → ℝ) (j : Fin N) (i : ℕ) : + Measurable (sourceGaussianTestRow p d h j i) := + indexedGaussianRow_measurable _ _ (enrichedFeature_continuous _ _ _ _ _).measurable i + +lemma sourceGaussianTestRow_square_bound {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) {H : ℝ} (hH : 0 ≤ H) (hhH : ∀ l, h l ≤ H) + (j : Fin N) (x : NormalizedSpin N×IndexedLeaf k) : + (∑ i : Fin (indexedGaussianRowLength (I := EnrichedIndex N N p) k x), + sourceGaussianTestRow p d h j i.val x^2) ≤ 2*H+1 := by + have hb (y : NormalizedSpin N) : (∑ i, sourceGaussianTestFeature N p j y i^2) ≤ (1:ℝ) := by + have he := enrichedFeature_norm_sq N N p 0 (Pi.single j 1) y + have hsum : (∑ i : Fin N, ((Pi.single j (1:ℝ) : Fin N → ℝ) i)^2) = (1:ℝ) := by + classical + simp [Pi.single_apply] + simp only [zero_pow (by decide : (2:ℕ) ≠ 0),zero_add,hsum] at he + simpa only [EuclideanSpace.norm_sq_eq,Real.norm_eq_abs,sq_abs,sourceGaussianTestFeature] using he.le + have ht := indexedGaussianRow_norm_le k + (hierarchyRowCoefficients k (profileGaussianRoot (enrichedCoordinateLevel p d h)) + (profileGaussianStep (enrichedCoordinateLevel p d h))) (sourceGaussianTestFeature N p j) + (C := 2*H+1) (D := 1) + (fun i => by + rw [profileGaussian_coefficient_squares _ (enrichedCoordinateLevel_nonneg p d hh0 0) + (enrichedCoordinateLevel_monotone p d hh)] + exact enrichedCoordinateLevel_le p d hH hhH _ i) + (by positivity) hb x + simpa only [mul_one,sourceGaussianTestRow] using ht + +def sourceJointMonomial {N k : ℕ} (p d : Fin N → ℕ) (j : Fin N) + (x y : NormalizedSpin N×IndexedLeaf k) : ℝ := + (((indexedCommonDepth k y.2 x.2).val:ℝ)/(k+1:ℕ))^(d j)*spinOverlap x.1 y.1^(p j) + +lemma sourceJointMonomial_diagonal {N k : ℕ} (p d : Fin N → ℕ) (j : Fin N) + (x : NormalizedSpin N×IndexedLeaf k) : + sourceJointMonomial p d j x x = ((k:ℝ)/(k+1:ℕ))^(d j) := by + have hx : ‖x.1.val‖=1 := by simp + simp [sourceJointMonomial,indexedCommonDepth_self,spinOverlap,hx] + +lemma sourceReplica_gaussian_ibp (n M k r : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (b : IndexedCascadeBase k) (j : Fin (n+1)) (z : Fin r) + {G : (Fin r → NormalizedSpin (n+1)×IndexedLeaf k) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + let μ := enrichedIndexedBaseMeasure n k b + let H := enrichedIndexedHamiltonian n M k f a p d h u + let Y := countableGaussianField (sourceGaussianTestRow p d h j) + (indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) k) + (∫ g, gibbsReplicaMean μ (H g) r (fun x => Y g (x z)*G x) ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean μ (H g) r (fun x => G x*∑ l, + perturbationAmplitude (n+1) u j*sourceJointMonomial p d j (x z) (x l)) - + r*gibbsReplicaMean μ (H g) (r+1) (fun x => G (fun l => x l.succ)* + (perturbationAmplitude (n+1) u j*sourceJointMonomial p d j (x z.succ) (x 0))) + ∂countableGaussianLaw := by + dsimp only + have ht : ∀ l, h l ≤ h (Fin.last k) := fun l => hh (Fin.le_last l) + have hi := countableGaussian_replica_full_ibp (enrichedIndexedBaseMeasure n k b) r z + (enrichedIndexedBoundedEnergy_measurable n M k f a h) + (sourceGaussianRow_measurable p d h u) (sourceGaussianTestRow_measurable p d h j) + (indexedGaussianRowLength_measurable k) hG + (enrichedIndexedBoundedEnergy_bound n M k f a h) + (sourceGaussianRow_square_bound p d h u hh0 hh (hh0 (Fin.last k)) ht) + (sourceGaussianTestRow_square_bound p d h hh0 hh (hh0 (Fin.last k)) ht j) hB hGB + dsimp only at hi + simpa only [sourceGaussianRow_test_covariance p d h hh0 hh u j,mul_assoc, + sourceJointMonomial,enrichedIndexedHamiltonian] using hi + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/ReplicaMeanConst.lean b/lean/OAI/Probability/Perceptron/Interpolation/ReplicaMeanConst.lean new file mode 100644 index 0000000000000000000000000000000000000000..1704d876f04fafefd9037b176152502fab01a6f3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/ReplicaMeanConst.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.VarianceProdMemLp + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma replicaMean_const {H : S → ℝ} (hH : Measurable H) {A : ℝ} + (hA : 0 ≤ A) (hHA : ∀ x, |H x| ≤ A) (n : ℕ) (c : ℝ) : + gibbsReplicaMean μ H n (fun _ => c) = c := by + have := tilt_law_probability μ hH hA hHA 1 + rw [gibbsReplicaMean,tilt_replica_integral μ hH hA hHA] + simp + +lemma replicaMean_annealed_integrable {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsFiniteMeasure P] {H : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) {A : Ω → ℝ} + (hA : ∀ ω, 0 ≤ A ω) (hHA : ∀ ω x, |H ω x| ≤ A ω) + {n : ℕ} {G : (Fin n → S) → ℝ} (hG : Measurable G) + {D : ℝ} (hD : 0 ≤ D) (hGD : ∀ x, |G x| ≤ D) : + Integrable (fun ω => gibbsReplicaMean μ (H ω) n G) P := + Integrable.of_bound (replicaMean_measurable μ hH hG).aestronglyMeasurable D + (ae_of_all _ fun ω => by + simpa only [Real.norm_eq_abs] using replicaMean_bound μ + (show Measurable (H ω) from hH.comp (measurable_const.prodMk measurable_id)) hG (hA ω) hD (hHA ω) hGD) + +omit μ [IsProbabilityMeasure μ] in +lemma fieldCovariance_measurable {m : ℕ} {v : Fin m → S → ℝ} + (hv : ∀ i, Measurable (v i)) : Measurable (Function.uncurry (fieldCovariance m v)) := by + change Measurable (fun p : S×S => ∑ i : Fin m, v i p.1*v i p.2) + exact Finset.measurable_sum _ fun i _ => ((hv i).comp measurable_fst).mul ((hv i).comp measurable_snd) + +omit μ [IsProbabilityMeasure μ] in +lemma fieldCovariance_comp_measurable {Ω : Type*} [MeasurableSpace Ω] + {m : ℕ} {v : Fin m → S → ℝ} (hv : ∀ i, Measurable (v i)) + {a b : Ω → S} (ha : Measurable a) (hb : Measurable b) : + Measurable (fun ω => fieldCovariance m v (a ω) (b ω)) := by + exact Finset.measurable_sum _ fun i _ => ((hv i).comp ha).mul ((hv i).comp hb) + +omit μ [IsProbabilityMeasure μ] [MeasurableSpace S] in +lemma fieldCovariance_bound {m : ℕ} {v : Fin m → S → ℝ} {C : ℝ} + (hC : 0 ≤ C) (hvC : ∀ i x, |v i x| ≤ C) (x y : S) : + |fieldCovariance m v x y| ≤ (m:ℝ)*C^2 := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _ : Fin m, C^2 := Finset.sum_le_sum fun i _ => by + rw [abs_mul,pow_two]; exact mul_le_mul (hvC i x) (hvC i y) (abs_nonneg _) hC + _ = _ := by simp + +lemma gaussian_field_energy_mean (m : ℕ) {v : Fin (m+1) → S → ℝ} {h : S → ℝ} + (hv : ∀ i, Measurable (v i)) (hh : Measurable h) {C A k : ℝ} + (hC : 0 ≤ C) (hA : 0 ≤ A) (hvC : ∀ i x, |v i x| ≤ C) (hhA : ∀ x, |h x| ≤ A) + (hdiag : ∀ x, fieldCovariance (m+1) v x x = k) (s : ℝ) : + let H := fun (g : Fin (m+1) → ℝ) (x : S) => h x+s*gaussianField (m+1) v g x + (∫ g, tiltMean μ (H g) (gaussianField (m+1) v g) 1 ∂Measure.pi (fun _ => gaussianReal 0 1)) = + s * (k-∫ g, gibbsReplicaMean μ (H g) 2 (fun x => fieldCovariance (m+1) v (x 1) (x 0)) + ∂Measure.pi (fun _ => gaussianReal 0 1)) := by + dsimp only + let γ := Measure.pi (fun _ : Fin (m+1) => gaussianReal 0 1) + let H := fun (g : Fin (m+1) → ℝ) (x : S) => h x+s*gaussianField (m+1) v g x + let B := fun (g : Fin (m+1) → ℝ) => A+|s| * ((∑ i, |g i|)*C) + have hH : Measurable (Function.uncurry H) := (hh.comp measurable_snd).add ((gaussianField_measurable hv).const_mul s) + have hB (g) : 0 ≤ B g := by dsimp [B]; positivity + have hb (g) (x) : |H g x| ≤ B g := + (abs_add_le _ _).trans (add_le_add (hhA x) (by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (gaussianField_bound hvC g x) (abs_nonneg s))) + have hHg (g) : Measurable (H g) := hH.comp (measurable_const.prodMk measurable_id) + have hYg (g) : Measurable (gaussianField (m+1) v g) := + (gaussianField_measurable hv).comp (measurable_const.prodMk measurable_id) + have hc : Integrable (fun g => gibbsReplicaMean μ (H g) 2 + (fun x => fieldCovariance (m+1) v (x 1) (x 0))) γ := + replicaMean_annealed_integrable μ γ hH hB hb + (fieldCovariance_comp_measurable hv (measurable_pi_apply 1) (measurable_pi_apply 0)) + (by positivity) (fun x => fieldCovariance_bound hC hvC (x 1) (x 0)) + have he := gaussian_replica_field_ibp μ m 1 0 (G := fun _ => 1) hv hh measurable_const hC hA + (show (0:ℝ) ≤ 1 by norm_num) hvC hhA (fun _ => by norm_num) s + change (∫ g, gibbsReplicaMean μ (H g) 1 (fun x => gaussianField (m+1) v g (x 0)*1) ∂γ) = _ at he + have hleft (g) : gibbsReplicaMean μ (H g) 1 (fun x => gaussianField (m+1) v g (x 0)*1) = + tiltMean μ (H g) (gaussianField (m+1) v g) 1 := by + simp only [mul_one] + exact tilt_replica_coordinate μ (hHg g) (hYg g) (hB g) (hb g) 1 0 1 + have hright (g) : gibbsReplicaMean μ (H g) 1 + (fun x => ∑ l, fieldCovariance (m+1) v (x 0) (x l)) = k := by + simp only [Fin.sum_univ_one,hdiag] + exact replicaMean_const μ (hHg g) (hB g) (hb g) 1 k + simp_rw [hleft] at he + simp only [Nat.cast_one,one_mul,Fin.succ_zero_eq_one] at he + change (∫ g, tiltMean μ (H g) (gaussianField (m+1) v g) 1 ∂γ) = + s * ∫ g, gibbsReplicaMean μ (H g) 1 (fun x => ∑ l, fieldCovariance (m+1) v (x 0) (x l))- + gibbsReplicaMean μ (H g) 2 (fun x => fieldCovariance (m+1) v (x 1) (x 0)) ∂γ at he + simp_rw [hright] at he + rw [integral_sub (integrable_const k) hc,integral_const] at he + simpa only [Measure.real,γ,measure_univ,ENNReal.toReal_one,one_smul] using he + +lemma gaussian_gg_defect_bound (m n : ℕ) (j : Fin n) + {v : Fin (m+1) → S → ℝ} {h : S → ℝ} {G : (Fin n → S) → ℝ} + (hv : ∀ i, Measurable (v i)) (hh : Measurable h) (hG : Measurable G) + {C A D k s : ℝ} (hC : 0 ≤ C) (hA : 0 ≤ A) (hD : 0 ≤ D) + (hvC : ∀ i x, |v i x| ≤ C) (hhA : ∀ x, |h x| ≤ A) (hGD : ∀ x, |G x| ≤ D) + (hdiag : ∀ x, fieldCovariance (m+1) v x x = k) (hs : s ≠ 0) : + let γ := Measure.pi (fun _ : Fin (m+1) => gaussianReal 0 1) + let H := fun (g : Fin (m+1) → ℝ) (x : S) => h x+s*gaussianField (m+1) v g x + let EG := ∫ g, gibbsReplicaMean μ (H g) n G ∂γ + let EY := ∫ g, tiltMean μ (H g) (gaussianField (m+1) v g) 1 ∂γ + |(∫ g, gibbsReplicaMean μ (H g) n (fun x => G x*∑ l, fieldCovariance (m+1) v (x j) (x l)) ∂γ)- + k*EG+EG*(∫ g, gibbsReplicaMean μ (H g) 2 (fun x => fieldCovariance (m+1) v (x 1) (x 0)) ∂γ)- + (n:ℝ)*(∫ g, gibbsReplicaMean μ (H g) (n+1) + (fun x => G (fun l => x l.succ)*fieldCovariance (m+1) v (x j.succ) (x 0)) ∂γ)| ≤ + D*(∫ g, tiltMean μ (H g) (fun x => |gaussianField (m+1) v g x-EY|) 1 ∂γ)/|s| := by + dsimp only + let γ := Measure.pi (fun _ : Fin (m+1) => gaussianReal 0 1) + let Y := gaussianField (m+1) v + let H := fun (g : Fin (m+1) → ℝ) (x : S) => h x+s*Y g x + let B := fun (g : Fin (m+1) → ℝ) => (∑ i, |g i|)*C + let T := fun g => A+|s| * B g + have hY : Measurable (Function.uncurry Y) := gaussianField_measurable hv + have hH : Measurable (Function.uncurry H) := (hh.comp measurable_snd).add (hY.const_mul s) + have hB (g) : 0 ≤ B g := by dsimp [B]; positivity + have hT (g) : 0 ≤ T g := by dsimp [T]; positivity + have hYB (g x) : |Y g x| ≤ B g := gaussianField_bound hvC g x + have hHT (g x) : |H g x| ≤ T g := (abs_add_le _ _).trans (add_le_add (hhA x) (by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hYB g x) (abs_nonneg s))) + have hBI : Integrable B γ := by + apply Integrable.mul_const + exact integrable_finsetSum _ fun i _ => + (((measurePreserving_eval (fun _ : Fin (m+1) => gaussianReal 0 1) i).integrable_comp + measurable_id.aestronglyMeasurable).mpr + ((memLp_id_gaussianReal (μ := 0) (v := 1) 1).integrable (by norm_num))).abs + let U := fun x : Fin n → S => G x*∑ l, fieldCovariance (m+1) v (x j) (x l) + let W := fun x : Fin (n+1) → S => G (fun l => x l.succ)*fieldCovariance (m+1) v (x j.succ) (x 0) + have hcm (a b : Fin n) : Measurable (fun x : Fin n → S => fieldCovariance (m+1) v (x a) (x b)) := + fieldCovariance_comp_measurable hv (measurable_pi_apply a) (measurable_pi_apply b) + have hUm : Measurable U := hG.mul (Finset.measurable_sum _ fun l _ => hcm j l) + have hWm : Measurable W := by + apply (hG.comp (Measurable.of_eval fun index => measurable_pi_apply index.succ)).mul + exact fieldCovariance_comp_measurable hv (measurable_pi_apply j.succ) (measurable_pi_apply 0) + have hUB (x) : |U x| ≤ D*((n:ℝ)*((m+1:ℕ):ℝ)*C^2) := by + dsimp only [U] + rw [abs_mul] + apply mul_le_mul (hGD x) _ (abs_nonneg _) hD + calc + _ ≤ ∑ l : Fin n, |fieldCovariance (m+1) v (x j) (x l)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _ : Fin n, ((m+1:ℕ):ℝ)*C^2 := Finset.sum_le_sum fun l _ => fieldCovariance_bound hC hvC _ _ + _ = _ := by simp; ring + have hWB (x) : |W x| ≤ D*(((m+1:ℕ):ℝ)*C^2) := by + dsimp only [W] + rw [abs_mul] + exact mul_le_mul (hGD _) (fieldCovariance_bound hC hvC _ _) (abs_nonneg _) hD + have hUI := replicaMean_annealed_integrable μ γ hH hT hHT hUm (by positivity) hUB + have hWI := replicaMean_annealed_integrable μ γ hH hT hHT hWm (by positivity) hWB + let EY := ∫ g, tiltMean μ (H g) (Y g) 1 ∂γ + have hf := annealed_replica_energy_factorization_bound μ γ hH hY hT hB hHT hYB hBI j hG hD hGD EY + have he := gaussian_replica_field_ibp μ m n j hv hh hG hC hA hD hvC hhA hGD s + change (∫ g, gibbsReplicaMean μ (H g) n (fun x => Y g (x j)*G x) ∂γ) = + s*∫ g, gibbsReplicaMean μ (H g) n U-(n:ℝ)*gibbsReplicaMean μ (H g) (n+1) W ∂γ at he + rw [integral_sub hUI (hWI.const_mul n),integral_const_mul] at he + have hey := gaussian_field_energy_mean μ m hv hh hC hA hvC hhA hdiag s + change EY = s*(k-∫ g, gibbsReplicaMean μ (H g) 2 (fun x => fieldCovariance (m+1) v (x 1) (x 0)) ∂γ) at hey + rw [he] at hf + have hab : + |s| * |(∫ g, gibbsReplicaMean μ (H g) n U ∂γ)-k*(∫ g, gibbsReplicaMean μ (H g) n G ∂γ)+ + (∫ g, gibbsReplicaMean μ (H g) n G ∂γ)*(∫ g, gibbsReplicaMean μ (H g) 2 + (fun x => fieldCovariance (m+1) v (x 1) (x 0)) ∂γ)- + (n:ℝ)*(∫ g, gibbsReplicaMean μ (H g) (n+1) W ∂γ)| = + |s*((∫ g, gibbsReplicaMean μ (H g) n U ∂γ)-(n:ℝ)*(∫ g, gibbsReplicaMean μ (H g) (n+1) W ∂γ))- + EY*(∫ g, gibbsReplicaMean μ (H g) n G ∂γ)| := by + rw [← abs_mul,hey]; congr 1; ring + exact (le_div_iff₀ (abs_pos.mpr hs)).mpr (by rw [mul_comm,hab]; exact hf) + +end SphericalPerceptronFreeEnergy + +open scoped Pointwise + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/RestorationReplicaBlocks.lean b/lean/OAI/Probability/Perceptron/Interpolation/RestorationReplicaBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..c06cc6218e4558e1adcf8dc0c512ab3004941596 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/RestorationReplicaBlocks.lean @@ -0,0 +1,62 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkModel +import OAI.Probability.Perceptron.Variational.RestorationMoments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def restorationBlockTest (r : ℕ) (F : CompactBlock CompactOverlap r→ᵇℝ) : + (k : ℕ) → CompactBlock CompactOverlap (r+k)→ᵇℝ + | 0 => F + | k+1 => (restorationBlockTest r F k).compContinuous + ⟨fun Q i j => Q i.succ j.succ,by fun_prop⟩ + +def restorationMarkTest (r : ℕ) (f : ℝ→ᵇℝ) (Ψ : EuclideanSpace ℝ (Fin r)→ᵇℝ) : + (k : ℕ) → EuclideanSpace ℝ (Fin (r+k))→ᵇℝ + | 0 => gaussianReplicaTest (expBCF 1 f)*Ψ + | k+1 => ((expBCF 1 f).compContinuous ⟨fun x => x 0,by fun_prop⟩)* + (restorationMarkTest r f Ψ k).compContinuous + ⟨fun x => WithLp.toLp 2 (fun i => x i.succ),by fun_prop⟩ + +lemma restorationReplicaTest_twoMarks {N r : ℕ} (f : ℝ→ᵇℝ) + (F : CompactBlock CompactOverlap r→ᵇℝ) (Ψ Φ : EuclideanSpace ℝ (Fin r)→ᵇℝ) + (z₁ z₂ : EuclideanSpace ℝ (Fin N)) (k : ℕ) (x : Fin (r+k)→NormalizedSpin N) : + restorationReplicaTest r (fun x : NormalizedSpin N => Real.exp (f (inner ℝ x.val z₁)+f (inner ℝ x.val z₂))) + (fun x => (∏ i, Real.exp (f (inner ℝ (x i).val z₁)+f (inner ℝ (x i).val z₂)))* + F (fun i j => bulkOverlap (x i) (x j))*Ψ (gaussianRows (fun i => (x i).val) z₁)* + Φ (gaussianRows (fun i => (x i).val) z₂)) k x = + restorationBlockTest r F k (fun i j => bulkOverlap (x i) (x j))* + restorationMarkTest r f Ψ k (gaussianRows (fun i => (x i).val) z₁)* + restorationMarkTest r f Φ k (gaussianRows (fun i => (x i).val) z₂) := by + induction k with + | zero => + simp only [restorationReplicaTest,restorationBlockTest,restorationMarkTest, + BoundedContinuousFunction.mul_apply, gaussianReplicaTest, BoundedContinuousFunction.prod_apply, + BoundedContinuousFunction.compContinuous_apply, ContinuousMap.coe_mk, expBCF_apply,one_mul, + gaussianRows_apply,Real.exp_add,Finset.prod_mul_distrib] + ring_nf + rfl + | succ k hk => + change Real.exp (f (inner ℝ (x 0).val z₁)+f (inner ℝ (x 0).val z₂))* + restorationReplicaTest r _ _ k (fun i => x i.succ) = _ + rw [hk,Real.exp_add] + change Real.exp (f (inner ℝ (x 0).val z₁))*Real.exp (f (inner ℝ (x 0).val z₂))* + (restorationBlockTest r F k (fun i j => bulkOverlap (x i.succ) (x j.succ))* + restorationMarkTest r f Ψ k (gaussianRows (fun i => (x i.succ).val) z₁)* + restorationMarkTest r f Φ k (gaussianRows (fun i => (x i.succ).val) z₂)) = + restorationBlockTest r F k (fun i j => bulkOverlap (x i.succ) (x j.succ))* + (Real.exp (1*f (inner ℝ (x 0).val z₁))*restorationMarkTest r f Ψ k + (gaussianRows (fun i => (x i.succ).val) z₁))* + (Real.exp (1*f (inner ℝ (x 0).val z₂))*restorationMarkTest r f Φ k + (gaussianRows (fun i => (x i.succ).val) z₂)) + simp only [one_mul] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/TerminalReplicaRestoration.lean b/lean/OAI/Probability/Perceptron/Interpolation/TerminalReplicaRestoration.lean new file mode 100644 index 0000000000000000000000000000000000000000..4705651aa6c3e9a8df03fe8b71252afbdb1ebf43 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/TerminalReplicaRestoration.lean @@ -0,0 +1,174 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GibbsRestoration +import OAI.Probability.Perceptron.Sphere.UnitSphereTangent +import OAI.Probability.Perceptron.Pressure.TerminalRestorationCoefficients +import OAI.Probability.Perceptron.Variational.LeafMarginalLaw + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators ContDiff + +section +section +variable {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + +lemma gibbsReplicaMean_pair_integral (μ : Measure S) [IsProbabilityMeasure μ] + {H : S→ℝ} (hH : Measurable H) (hi : Integrable (fun x => Real.exp (H x)) μ) + (F : S×S→ℝ) (hF : Measurable F) : + gibbsReplicaMean μ H 2 (fun x => F (x 0,x 1)) = + ∫ x, F x ∂(tiltLaw μ H 1).prod (tiltLaw μ H 1) := by + have hi' : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using hi + let := tilt_law_probability_of_integrable μ hi' + rw [gibbsReplicaMean_integral_of_integrable μ hH hi] + have hp := measurePreserving_finTwoArrow (tiltLaw μ H 1) + have he := integral_map (μ:=Measure.pi fun _ : Fin 2 => tiltLaw μ H 1) + hp.measurable.aemeasurable hF.aestronglyMeasurable + rw [hp.map_eq] at he + exact he.symm + +lemma gibbsReplicaMean_product_leaf (μ : Measure S) (ν : Measure T) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (H : S×T→ℝ) (G : T→ℝ) (hH : Measurable H) (hG : Measurable G) + (hi : Integrable (fun x => Real.exp (H x)) (μ.prod ν)) + (hp : ∀ t, (∫ s, Real.exp (H (s,t)) ∂μ)=Real.exp (G t)) + (r : ℕ) (F : (Fin r→T)→ℝ) (hF : Measurable F) : + gibbsReplicaMean (μ.prod ν) H r (fun x => F (fun i => (x i).2)) = + gibbsReplicaMean ν G r F := by + have hiG : Integrable (fun t => Real.exp (G t)) ν := by simpa only [hp] using hi.integral_prod_right + rw [gibbsReplicaMean_integral_of_integrable (μ.prod ν) hH hi, + gibbsReplicaMean_integral_of_integrable ν hG hiG] + have hmap := tiltLaw_prod_snd_replica μ ν H G hH hG hi hp r + have he := integral_map (μ:=Measure.pi fun _ : Fin r => tiltLaw (μ.prod ν) H 1) + hmap.measurable.aemeasurable hF.aestronglyMeasurable + rw [hmap.map_eq] at he + exact he.symm + +end +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + +lemma indexedTerminalPairMean_replica (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (x : X) (d : Fin (n+1)) (f : X→ℝ) + (p : IndexedCascadeBase n×IndexedCascadeMarks S n) + (hi : Integrable (fun l => Real.exp (H (indexedLeafState step n (x,p.2) l))) (indexedLeafProbability n p.1)) : + indexedTerminalPairMean step n H x d f p = + gibbsReplicaMean (indexedLeafProbability n p.1) (indexedTerminalEnergy step n H x p) 2 + (fun l => if indexedCommonDepth n (l 0) (l 1)=d then + f (indexedLeafState step n (x,p.2) (l 0))*f (indexedLeafState step n (x,p.2) (l 1)) else 0) := by + unfold indexedTerminalPairMean + dsimp only + rw [gibbsProbabilityKernel_of_integrable (indexedTerminalBaseKernel n) _ + (indexedTerminalEnergy_measurable step hs n H hH x) p hi] + symm + exact gibbsReplicaMean_pair_integral (indexedLeafProbability n p.1) + (H:=indexedTerminalEnergy step n H x p) (measurable_of_countable _) + (by simpa only [indexedTerminalEnergy] using hi) + (fun l : IndexedLeaf n×IndexedLeaf n => if indexedCommonDepth n l.1 l.2=d then + f (indexedLeafState step n (x,p.2) l.1)*f (indexedLeafState step n (x,p.2) l.2) else 0) + (measurable_of_countable _) + +lemma indexedTerminalMean_tiltMean (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (x : X) (f : X→ℝ) + (p : IndexedCascadeBase n×IndexedCascadeMarks S n) + (hi : Integrable (fun l => Real.exp (H (indexedLeafState step n (x,p.2) l))) (indexedLeafProbability n p.1)) : + indexedTerminalMean step n H x f p = + tiltMean (indexedLeafProbability n p.1) (indexedTerminalEnergy step n H x p) + (fun l => f (indexedLeafState step n (x,p.2) l)) 1 := by + unfold indexedTerminalMean + rw [gibbsProbabilityKernel_of_integrable (indexedTerminalBaseKernel n) _ + (indexedTerminalEnergy_measurable step hs n H hH x) p hi] + exact tilt_law_integral_of_integrable (indexedLeafProbability n p.1) (measurable_of_countable _) + (by simpa only [one_mul,indexedTerminalEnergy] using hi) + +lemma indexedTerminalPairMean_restore (step : X×S→X) (hs : Measurable step) + (n : ℕ) (J W : X→ℝ) (hJ : Measurable J) (hW : Measurable W) + (x : X) (d : Fin (n+1)) (f : X→ℝ) (p : IndexedCascadeBase n×IndexedCascadeMarks S n) + (hiJ : Integrable (fun l => Real.exp (J (indexedLeafState step n (x,p.2) l))) (indexedLeafProbability n p.1)) + (hi : Integrable (fun l => Real.exp (J (indexedLeafState step n (x,p.2) l)+W (indexedLeafState step n (x,p.2) l))) + (indexedLeafProbability n p.1)) : + indexedTerminalPairMean step n (fun y => J y+W y) x d f p = + gibbsReplicaMean (indexedLeafProbability n p.1) (indexedTerminalEnergy step n J x p) 2 + (fun l => (∏ i, Real.exp (W (indexedLeafState step n (x,p.2) (l i)))) * + (if indexedCommonDepth n (l 0) (l 1)=d then + f (indexedLeafState step n (x,p.2) (l 0))*f (indexedLeafState step n (x,p.2) (l 1)) else 0)) / + (tiltMean (indexedLeafProbability n p.1) (indexedTerminalEnergy step n J x p) + (fun l => Real.exp (W (indexedLeafState step n (x,p.2) l))) 1)^2 := by + have he := indexedTerminalPairMean_replica step hs n (fun y => J y+W y) + (show Measurable (fun y => J y+W y) from hJ.add hW) x d f p hi + rw [he] + change gibbsReplicaMean _ (fun l => J (indexedLeafState step n (x,p.2) l)+W (indexedLeafState step n (x,p.2) l)) 2 _ = _ + exact gibbsReplicaMean_restore (indexedLeafProbability n p.1) (measurable_of_countable _) hiJ 2 _ + +end + +lemma continuous_integrable_compact {X : Type*} [TopologicalSpace X] [MeasurableSpace X] + [BorelSpace X] [CompactSpace X] {μ : Measure X} [IsFiniteMeasure μ] + {f : X→ℝ} (hf : Continuous f) : Integrable f μ := + hf.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + +lemma unitSphere_gibbs_tangent_mean (n : ℕ) (y : NormalizedSpin (n+1)) + {H : Spin (n+1)→ℝ} (hH : ContDiff ℝ 1 H) {G : ℝ→ℝ} (hG : ContDiff ℝ 1 G) : + (n:ℝ)*(∫ x : NormalizedSpin (n+1), spinOverlap x y*G (spinOverlap x y) + ∂tiltLaw (unitSphereLaw (n+1)) (fun x => H x.val) 1) = + ∫ x : NormalizedSpin (n+1), + deriv G (spinOverlap x y)*(1-spinOverlap x y^2)+G (spinOverlap x y)* + fderiv ℝ H x.val (y.val-spinOverlap x y • x.val) + ∂tiltLaw (unitSphereLaw (n+1)) (fun x => H x.val) 1 := by + have hHc : Continuous (fun x : NormalizedSpin (n+1) => H x.val) := hH.continuous.comp continuous_subtype_val + have hi := continuous_integrable_compact (μ:=unitSphereLaw (n+1)) (Real.continuous_exp.comp hHc) + have hi' : Integrable (fun x : NormalizedSpin (n+1) => Real.exp (1*H x.val)) (unitSphereLaw (n+1)) := by + simpa only [one_mul,Function.comp_def] using hi + rw [tilt_law_integral_of_integrable _ hHc.measurable hi', + tilt_law_integral_of_integrable _ hHc.measurable hi'] + have he := unitSphere_gibbs_tangent_integral n y hH hG + have hr (x : NormalizedSpin (n+1)) : spinOverlap y x=spinOverlap x y := real_inner_comm _ _ + simp_rw [hr] at he + unfold tiltMean tiltIntegral + simp only [one_mul] + rw [←mul_div_assoc] + congr 1 + convert he using 1 + · congr 1 + apply integral_congr_ae + exact ae_of_all _ fun x => by ring + · apply integral_congr_ae + exact ae_of_all _ fun x => by ring + +lemma unitSphere_gibbs_replica_tangent (n : ℕ) + {H : Spin (n+1)→ℝ} (hH : ContDiff ℝ 1 H) {G : ℝ→ℝ} (hG : ContDiff ℝ 1 G) : + (n:ℝ)*gibbsReplicaMean (unitSphereLaw (n+1)) (fun x => H x.val) 2 + (fun x => spinOverlap (x 0) (x 1)*G (spinOverlap (x 0) (x 1))) = + gibbsReplicaMean (unitSphereLaw (n+1)) (fun x => H x.val) 2 + (fun x => deriv G (spinOverlap (x 0) (x 1))*(1-spinOverlap (x 0) (x 1)^2)+ + G (spinOverlap (x 0) (x 1))*fderiv ℝ H (x 0).val + ((x 1).val-spinOverlap (x 0) (x 1) • (x 0).val)) := by + let L : NormalizedSpin (n+1)×NormalizedSpin (n+1)→ℝ := + fun x => spinOverlap x.1 x.2*G (spinOverlap x.1 x.2) + let R : NormalizedSpin (n+1)×NormalizedSpin (n+1)→ℝ := + fun x => deriv G (spinOverlap x.1 x.2)*(1-spinOverlap x.1 x.2^2)+ + G (spinOverlap x.1 x.2)*fderiv ℝ H x.1.val (x.2.val-spinOverlap x.1 x.2 • x.1.val) + have hLc : Continuous L := by dsimp [L,spinOverlap]; fun_prop + have hRc : Continuous R := by + have hdG := hG.continuous_deriv (by norm_num : 1≤(1:WithTop ℕ∞)) + have hdH := hH.continuous_fderiv (by norm_num) + dsimp [R,spinOverlap] + fun_prop + have hHc : Continuous (fun x : NormalizedSpin (n+1) => H x.val) := hH.continuous.comp continuous_subtype_val + have hi := continuous_integrable_compact (μ:=unitSphereLaw (n+1)) (Real.continuous_exp.comp hHc) + have hi' : Integrable (fun x : NormalizedSpin (n+1) => Real.exp (1*H x.val)) (unitSphereLaw (n+1)) := by + simpa only [one_mul,Function.comp_def] using hi + let := tilt_law_probability_of_integrable (unitSphereLaw (n+1)) hi' + change (n:ℝ)*gibbsReplicaMean _ _ 2 (fun x => L (x 0,x 1))=gibbsReplicaMean _ _ 2 (fun x => R (x 0,x 1)) + rw [gibbsReplicaMean_pair_integral _ hHc.measurable hi L hLc.measurable, + gibbsReplicaMean_pair_integral _ hHc.measurable hi R hRc.measurable, + integral_prod_symm _ (continuous_integrable_compact hLc), + integral_prod_symm _ (continuous_integrable_compact hRc),←integral_const_mul] + apply integral_congr_ae + exact ae_of_all _ fun y => unitSphere_gibbs_tangent_mean n y hH hG + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/TiltReplicaCoordinate.lean b/lean/OAI/Probability/Perceptron/Interpolation/TiltReplicaCoordinate.lean new file mode 100644 index 0000000000000000000000000000000000000000..c89267c7b2f09027de1240c0ec012dc78451ba21 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/TiltReplicaCoordinate.lean @@ -0,0 +1,431 @@ +import Mathlib +import OAI.Probability.Perceptron.Brownian.GaussianField + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] +section ReplicaCalculus +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma tilt_replica_coordinate {v F : S → ℝ} (hv : Measurable v) (hF : Measurable F) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (n : ℕ) (j : Fin n) (t : ℝ) : + tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) (fun x => F (x j)) t = + tiltMean μ v F t := by + have := tilt_law_probability μ hv hC hvC t + rw [tilt_replica_integral μ hv hC hvC,← tilt_law_integral μ hv hC hvC t] + have he := measurePreserving_eval (fun _ : Fin n => tiltLaw μ v t) j + conv_rhs => rw [← he.map_eq,integral_map he.measurable.aemeasurable hF.aestronglyMeasurable] + +lemma tilt_mean_sum {ι : Type*} (s : Finset ι) {v : S → ℝ} {F : ι → S → ℝ} + (hv : Measurable v) (hF : ∀ i ∈ s, Measurable (F i)) + {C : ℝ} {D : ι → ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) + (hFD : ∀ i ∈ s, ∀ x, |F i x| ≤ D i) (t : ℝ) : + tiltMean μ v (fun x => ∑ i ∈ s, F i x) t = ∑ i ∈ s, tiltMean μ v (F i) t := by + have := tilt_law_probability μ hv hC hvC t + simp_rw [← tilt_law_integral μ hv hC hvC t] + exact integral_finsetSum s fun i hi => Integrable.of_bound (hF i hi).aestronglyMeasurable + (D i) (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hFD i hi x) + +lemma tilt_replica_sum {v F : S → ℝ} (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) + (n : ℕ) (t : ℝ) : + tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) (replicaPotential F n) t = + n * tiltMean μ v F t := by + change tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) + (fun x => ∑ i, F (x i)) t = _ + rw [tilt_mean_sum (Measure.pi fun _ : Fin n => μ) Finset.univ + (F := fun i (x : Fin n → S) => F (x i)) (replicaPotential_measurable hv n) + (fun i _ => hF.comp (measurable_pi_apply i)) (mul_nonneg (Nat.cast_nonneg n) hC) + (replicaPotential_bound hvC n) (fun i _ x => hFD (x i))] + simp_rw [tilt_replica_coordinate μ hv hF hC hvC] + simp + +lemma tilt_replica_new_product {n : ℕ} {v F : S → ℝ} {G : (Fin n → S) → ℝ} + (hv : Measurable v) (hF : Measurable F) (hG : Measurable G) + {C D B : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) + (hFD : ∀ x, |F x| ≤ D) (hGB : ∀ x, |G x| ≤ B) (t : ℝ) : + tiltMean (Measure.pi fun _ : Fin (n+1) => μ) (replicaPotential v (n+1)) + (fun x => F (x 0) * G (fun j => x j.succ)) t = + tiltMean μ v F t * tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) G t := by + have := tilt_law_probability μ hv hC hvC t + simp_rw [tilt_replica_integral μ hv hC hvC] + rw [← tilt_law_integral μ hv hC hvC t] + let ν := tiltLaw μ v t + have he := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => ν) 0).symm + rw [← he.integral_comp' (fun x => F (x 0) * G (fun j => x j.succ))] + change (∫ p : S × (Fin n → S), F ((Fin.insertNth 0 p.1 p.2 : Fin (n+1) → S) 0) * + G (fun j => (Fin.insertNth 0 p.1 p.2 : Fin (n+1) → S) j.succ) + ∂ν.prod (Measure.pi fun _ => ν)) = _ + simp only [Fin.insertNth_zero',Fin.cons_zero,Fin.cons_succ] + have hFi : Integrable F ν := Integrable.of_bound hF.aestronglyMeasurable D + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hFD x) + have hGi : Integrable G (Measure.pi fun _ : Fin n => ν) := Integrable.of_bound + hG.aestronglyMeasurable B (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hGB x) + rw [integral_prod _ (hFi.mul_prod hGi)] + simp_rw [integral_const_mul] + rw [integral_mul_const] + +omit [MeasurableSpace S] in +lemma gaussianField_replica (m n : ℕ) (v : Fin m → S → ℝ) (g : Fin m → ℝ) + (x : Fin n → S) : + replicaPotential (gaussianField m v g) n x = + gaussianField m (fun i => replicaPotential (v i) n) g x := by + simp only [gaussianField,replicaPotential,Finset.mul_sum] + exact Finset.sum_comm + +omit [MeasurableSpace S] in +lemma replicaPotential_add_field (m n : ℕ) (v : Fin m → S → ℝ) (h : S → ℝ) + (s : ℝ) (g : Fin m → ℝ) : + replicaPotential (fun x => h x+s*gaussianField m v g x) n = + fun x => replicaPotential h n x + + s*gaussianField m (fun i => replicaPotential (v i) n) g x := by + funext x + simp only [replicaPotential,Finset.sum_add_distrib,Finset.mul_sum,gaussianField] + congr 1 + exact Finset.sum_comm + +end ReplicaCalculus + +section ReplicaField +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma gaussian_replica_coordinate_ibp (m n : ℕ) (i : Fin (m+1)) (j : Fin n) + {v : Fin (m+1) → S → ℝ} {h : S → ℝ} {G : (Fin n → S) → ℝ} + (hv : ∀ l, Measurable (v l)) (hh : Measurable h) (hG : Measurable G) + {C A D : ℝ} (hC : 0 ≤ C) (hA : 0 ≤ A) (hD : 0 ≤ D) + (hvC : ∀ l x, |v l x| ≤ C) (hhA : ∀ x, |h x| ≤ A) (hGD : ∀ x, |G x| ≤ D) + (s : ℝ) : + let H := fun (g : Fin (m+1) → ℝ) (x : S) => h x+s*gaussianField (m+1) v g x + (∫ g, g i * tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential (H g) n) + (fun x => v i (x j)*G x) 1 ∂Measure.pi (fun _ => gaussianReal 0 1)) = + s * ∫ g, + tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential (H g) n) + (fun x => replicaPotential (v i) n x * (v i (x j)*G x)) 1 - + n * tiltMean (Measure.pi fun _ : Fin (n+1) => μ) (replicaPotential (H g) (n+1)) + (fun x => v i (x 0) * (v i (x j.succ)*G (fun l => x l.succ))) 1 + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + dsimp only + let H := fun (g : Fin (m+1) → ℝ) (x : S) => h x+s*gaussianField (m+1) v g x + have hFi : Measurable (fun x : Fin n → S => v i (x j)*G x) := + ((hv i).comp (measurable_pi_apply j)).mul hG + have hFB (x : Fin n → S) : |v i (x j)*G x| ≤ C*D := by + rw [abs_mul]; exact mul_le_mul (hvC i (x j)) (hGD x) (abs_nonneg _) hC + have hi := gaussian_field_coordinate_ibp (Measure.pi fun _ : Fin n => μ) (n := m) i + (fun l => replicaPotential_measurable (hv l) n) (replicaPotential_measurable hh n) hFi + (mul_nonneg (Nat.cast_nonneg n) hC) (mul_nonneg (Nat.cast_nonneg n) hA) + (mul_nonneg hC hD) (fun l => replicaPotential_bound (hvC l) n) + (replicaPotential_bound hhA n) hFB s + simp_rw [← replicaPotential_add_field] at hi + refine hi.trans ?_ + congr 1 + apply integral_congr_ae + refine ae_of_all _ fun g => ?_ + have hHm : Measurable (H g) := hh.add (((gaussianField_measurable hv).comp + (measurable_const.prodMk measurable_id)).const_mul s) + have hHb (x : S) : |H g x| ≤ A+|s| *((∑ l, |g l|)*C) := by + exact (abs_add_le _ _).trans (add_le_add (hhA x) (by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (gaussianField_bound hvC g x) (abs_nonneg s))) + change _ - _ * tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential (H g) n) + (replicaPotential (v i) n) 1 = _ + rw [tilt_replica_sum μ hHm (hv i) (by positivity) hHb (hvC i)] + change _ = _ - (n : ℝ) * tiltMean (Measure.pi fun _ : Fin (n+1) => μ) + (replicaPotential (H g) (n+1)) + (fun x => v i (x 0) * ((fun y : Fin n → S => v i (y j)*G y) (fun l => x l.succ))) 1 + rw [tilt_replica_new_product μ hHm (hv i) hFi (by positivity) hHb (hvC i) hFB] + ring + +end ReplicaField + +lemma gamma_lintegral_positive_scale {a r : ℝ} (ha : 0 < a) (hr : 0 < r) : + (∫⁻ t : ℝ in Ioi 0, ENNReal.ofReal (t^(a-1) * Real.exp (-t*r))) = + ENNReal.ofReal (r^(-a) * Real.Gamma a) := by + have hi : IntegrableOn (fun t : ℝ => t^(a-1) * Real.exp (-t*r)) (Ioi 0) := by + convert integrableOn_rpow_mul_exp_neg_mul_rpow (p := 1) (s := a-1) + (b := r) (by linarith) (by norm_num) hr using 1 + funext t + simp only [Real.rpow_one] + congr 2 + ring + rw [← ofReal_integral_eq_lintegral_ofReal hi (by + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + exact mul_nonneg (Real.rpow_nonneg ht.le _) (Real.exp_pos _).le)] + congr 1 + calc + (∫ t : ℝ in Ioi 0, t^(a-1)*Real.exp (-t*r)) = + ∫ t : ℝ in Ioi 0, t^(a-1)*Real.exp (-(r*t)) := by + congr 1; funext t; congr 2; ring + _ = (1/r)^a * Real.Gamma a := Real.integral_rpow_mul_exp_neg_mul_Ioi ha hr + _ = r^(-a) * Real.Gamma a := by + rw [one_div,Real.inv_rpow hr.le,Real.rpow_neg hr.le] + +lemma integrable_rpow_neg_of_laplace {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {S : Ω → ℝ} + (hS : Measurable S) (hpos : ∀ᵐ ω ∂P, 0 < S ω) + {b c : ℝ} (hb : 0 < b) (hc : 0 < c) + (hLap : ∀ t : ℝ, 0 < t → (∫ ω, Real.exp (-t*S ω) ∂P) = Real.exp (-c*t^b)) + {a : ℝ} (ha : 0 < a) : Integrable (fun ω => S ω ^ (-a)) P := by + let K := fun (ω : Ω) (t : ℝ) => ENNReal.ofReal (t^(a-1)*Real.exp (-t*S ω)) + have hm : Measurable (Function.uncurry K) := by dsimp [K]; fun_prop + have hexp (t : ℝ) (ht : 0 < t) : Integrable (fun ω => Real.exp (-t*S ω)) P := by + apply Integrable.of_bound (by fun_prop) 1 + filter_upwards [hpos] with ω hω + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_one_iff.mpr (by nlinarith) + have hinner (t : ℝ) (ht : 0 < t) : + (∫⁻ ω, K ω t ∂P) = ENNReal.ofReal (t^(a-1)*Real.exp (-c*t^b)) := by + dsimp [K] + simp_rw [ENNReal.ofReal_mul (Real.rpow_nonneg ht.le _)] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + ← ofReal_integral_eq_lintegral_ofReal (hexp t ht) (ae_of_all _ fun _ => (Real.exp_pos _).le), + hLap t ht] + have hi : (∫⁻ t : ℝ in Ioi 0, ∫⁻ ω, K ω t ∂P) ≠ ⊤ := by + have hfinite := (integrableOn_rpow_mul_exp_neg_mul_rpow + (s := a-1) (p := b) (b := c) (by linarith) hb hc).hasFiniteIntegral + have hfinite' : (∫⁻ t : ℝ in Ioi 0, + ENNReal.ofReal (t^(a-1)*Real.exp (-c*t^b))) < ⊤ := by + apply (hasFiniteIntegral_iff_ofReal _).mp hfinite + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + exact mul_nonneg (Real.rpow_nonneg ht.le _) (Real.exp_pos _).le + apply ne_top_of_le_ne_top hfinite'.ne + apply le_of_eq + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + exact hinner t ht + have hi' : (∫⁻ ω, ENNReal.ofReal (S ω^(-a)*Real.Gamma a) ∂P) ≠ ⊤ := by + rw [← lintegral_congr_ae (hpos.mono fun ω hω => gamma_lintegral_positive_scale ha hω)] + change (∫⁻ ω, (∫⁻ t : ℝ in Ioi 0, K ω t) ∂P) ≠ ⊤ + rw [lintegral_lintegral_swap hm.aemeasurable] + exact hi + have hnonneg : ∀ᵐ ω ∂P, 0 ≤ S ω^(-a)*Real.Gamma a := + hpos.mono fun ω hω => mul_nonneg (Real.rpow_nonneg hω.le _) (Real.Gamma_pos_of_pos ha).le + have hprod : Integrable (fun ω => S ω^(-a)*Real.Gamma a) P := + ⟨(hS.pow_const (-a) |>.mul_const (Real.Gamma a)).aestronglyMeasurable, + (hasFiniteIntegral_iff_ofReal hnonneg).mpr hi'.lt_top⟩ + have hh := hprod.div_const (Real.Gamma a) + simpa only [mul_div_assoc, div_self (Real.Gamma_pos_of_pos ha).ne', mul_one] using hh + +lemma stablePoissonTotal_negative_integrable {b a : ℝ} (hb0 : 0 < b) (hb1 : b < 1) + (ha : 0 < a) : Integrable (fun η => stablePoissonTotal η ^ (-a)) + (poissonRandomMeasureLaw (stableLogIntensity b)) := by + exact integrable_rpow_neg_of_laplace _ stablePoissonTotal_measurable + (stablePoissonTotal_pos hb0 hb1) hb0 + (ENNReal.toReal_pos (stableLaplaceConstant_positive hb0).ne' (stableLaplaceConstant_finite hb0 hb1)) + (fun _ ht => stablePoissonTotal_laplace hb0 hb1 ht) ha + +section GibbsConvex +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma tilt_log_partition_deriv {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (t : ℝ) : + HasDerivAt (fun u => Real.log (tiltPartition μ v u)) (tiltMean μ v v t) t := by + exact (tilt_partition_deriv μ hv hC hvC t).log (tilt_partition_pos μ hv hC hvC t).ne' + +lemma tilt_variance_eq {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (t : ℝ) : + tiltMean μ v (fun x => v x * v x) t - tiltMean μ v v t * tiltMean μ v v t = + variance v (tiltLaw μ v t) := by + have := tilt_law_probability μ hv hC hvC t + have hLp : MemLp v 2 (tiltLaw μ v t) := memLp_of_bounded + (ae_of_all _ fun x => abs_le.mp (hvC x)) hv.aestronglyMeasurable 2 + rw [variance_eq_sub hLp] + simp_rw [tilt_law_integral μ hv hC hvC t] + simp only [pow_two] + rfl + +lemma tilt_mean_potential_monotone {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) : Monotone (tiltMean μ v v) := by + apply monotone_of_hasDerivAt_nonneg (tilt_mean_deriv μ hv hv hC hC hvC hvC) + intro t + change 0 ≤ tiltMean μ v (fun x => v x*v x) t - tiltMean μ v v t*tiltMean μ v v t + rw [tilt_variance_eq μ hv hC hvC] + exact variance_nonneg _ _ + +lemma tilt_log_partition_convex {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) : + ConvexOn ℝ Set.univ (fun t => Real.log (tiltPartition μ v t)) := by + have hd := tilt_log_partition_deriv μ hv hC hvC + apply Monotone.convexOn_univ_of_deriv (fun t => (hd t).differentiableAt) + have he : deriv (fun t => Real.log (tiltPartition μ v t)) = tiltMean μ v v := + funext fun t => (hd t).deriv + rw [he] + exact tilt_mean_potential_monotone μ hv hC hvC + +end GibbsConvex + +lemma convex_contact_derivative_bound {f A : ℝ → ℝ} {u s d dA C : ℝ} + (hs : 0 < s) (hf : ConvexOn ℝ Set.univ f) (hd : HasDerivAt f d u) + (hp : A (u+s)-A u-s*dA ≤ C*s^2) + (hm : A (u-s)-A u+s*dA ≤ C*s^2) : + |d-dA| ≤ C*s + (|f (u+s)-A (u+s)| + 2*|f u-A u| + |f (u-s)-A (u-s)|)/s := by + have hu := hf.le_slope_of_hasDerivAt (Set.mem_univ u) (Set.mem_univ (u+s)) + (by linarith : u < u+s) hd + have hl := hf.slope_le_of_hasDerivAt (Set.mem_univ (u-s)) (Set.mem_univ u) + (by linarith : u-s < u) hd + simp only [slope_def_field] at hu hl + have he1 : u+s-u = s := by ring + have he2 : u-(u-s) = s := by ring + rw [he1,le_div_iff₀ hs] at hu + rw [he2,div_le_iff₀ hs] at hl + apply (abs_le).mpr + constructor + · apply (mul_le_mul_iff_of_pos_right hs).mp + rw [neg_mul,add_mul,div_mul_cancel₀ _ hs.ne'] + nlinarith [le_abs_self (f (u-s)-A (u-s)),neg_abs_le (f u-A u), + abs_nonneg (f (u+s)-A (u+s)),abs_nonneg (f u-A u)] + · apply (mul_le_mul_iff_of_pos_right hs).mp + rw [add_mul,div_mul_cancel₀ _ hs.ne'] + nlinarith [le_abs_self (f (u+s)-A (u+s)),neg_abs_le (f u-A u), + abs_nonneg (f (u-s)-A (u-s)),abs_nonneg (f u-A u)] + +lemma poissonRandomMeasureLaw_superposition {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ ζ : Measure S) [SFinite κ] [SFinite ζ] : + ((poissonRandomMeasureLaw κ).prod (poissonRandomMeasureLaw ζ)).map + (fun p => p.1+p.2) = poissonRandomMeasureLaw (κ+ζ) := by + have hm : Measurable (fun p : Measure S × Measure S => p.1+p.2) := by fun_prop + apply measureLaw_eq_of_laplace + intro f hf hf0 + rw [integral_map hm.aemeasurable (poissonLaplace_measurable hf).aestronglyMeasurable] + have hsum (p : Measure S × Measure S) : poissonLaplace f (p.1+p.2) = + poissonLaplace f p.1 * poissonLaplace f p.2 := by + simp only [poissonLaplace,lintegral_add_measure,expNegENNReal_add] + simp_rw [hsum] + have hi (ν : Measure S) [SFinite ν] : Integrable (poissonLaplace f) (poissonRandomMeasureLaw ν) := + Integrable.of_bound (poissonLaplace_measurable hf).aestronglyMeasurable 1 + (ae_of_all _ fun η => by simpa only [Real.norm_eq_abs,abs_of_nonneg (poissonLaplace_bounds f η).1] + using (poissonLaplace_bounds f η).2) + rw [integral_prod _ ((hi κ).mul_prod (hi ζ))] + simp_rw [integral_const_mul] + rw [integral_mul_const,poissonRandomMeasureLaw_laplace κ hf hf0, + poissonRandomMeasureLaw_laplace ζ hf hf0,poissonRandomMeasureLaw_laplace (κ+ζ) hf hf0, + lintegral_add_measure,expNegENNReal_add] + +lemma poissonRandomMeasureLaw_of_finite {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [IsFiniteMeasure κ] : + poissonRandomMeasureLaw κ = finitePoissonLaw (κ univ).toNNReal (finiteIntensityMarks κ) := by + apply measureLaw_eq_of_laplace + intro f hf hf0 + rw [poissonRandomMeasureLaw_laplace κ hf hf0,finitePoissonLaw_laplace_nonneg _ _ hf hf0] + have hi : Integrable (fun x => 1 - Real.exp (-f x)) (finiteIntensityMarks κ) := by + apply Integrable.of_bound (measurable_const.sub hf.neg.exp).aestronglyMeasurable 1 + exact ae_of_all _ fun x => by + change |1-Real.exp (-f x)| ≤ 1 + rw [abs_of_nonneg (sub_nonneg.mpr (Real.exp_le_one_iff.mpr (neg_nonpos.mpr (hf0 x))))] + linarith [Real.exp_pos (-f x)] + congr 1 + calc + _ = ((κ univ).toNNReal : ℝ≥0∞) * ∫⁻ x, ENNReal.ofReal (1-Real.exp (-f x)) + ∂finiteIntensityMarks κ := by + conv_lhs => rw [← finiteIntensityMarks_smul κ] + rw [lintegral_smul_measure] + rfl + _ = _ := by + rw [← ofReal_integral_eq_lintegral_ofReal hi + (ae_of_all _ fun x => sub_nonneg.mpr (Real.exp_le_one_iff.mpr (neg_nonpos.mpr (hf0 x)))), + ENNReal.ofReal_mul (NNReal.coe_nonneg _),ENNReal.ofReal_coe_nnreal] + +lemma aemeasurable_randomMeasure_lintegral_of_finite {Ω S : Type*} + [MeasurableSpace Ω] [MeasurableSpace S] {P : Measure Ω} {A : Ω → Measure S} + (hA : Measurable A) (hfinite : ∀ᵐ ω ∂P, A ω univ < ⊤) + {H : Ω × S → ℝ≥0∞} (hH : Measurable H) : + AEMeasurable (fun ω => ∫⁻ x, H (ω,x) ∂A ω) P := by + have hm : Measurable (fun ω => ⨆ n : ℕ, ∫⁻ x, H (ω,x) ∂finiteMeasureCutKernel n (A ω)) := by + apply Measurable.iSup + intro n + exact hH.lintegral_kernel_prod_right' (κ := (finiteMeasureCutKernel n).comap A hA) + apply hm.aemeasurable.congr + filter_upwards [hfinite] with ω hω + apply le_antisymm + · apply iSup_le + intro n + change (∫⁻ x, H (ω,x) ∂(if A ω univ ≤ n then A ω else 0)) ≤ _ + split_ifs <;> simp + · obtain ⟨n,hn⟩ := ENNReal.exists_nat_gt hω.ne + calc + (∫⁻ x, H (ω,x) ∂A ω) = ∫⁻ x, H (ω,x) ∂finiteMeasureCutKernel n (A ω) := by + change _ = ∫⁻ x, H (ω,x) ∂(if A ω univ ≤ n then A ω else 0) + rw [ite_eq_left hn.le] + _ ≤ _ := le_iSup (fun m : ℕ => ∫⁻ x, H (ω,x) ∂finiteMeasureCutKernel m (A ω)) n + +lemma poissonRandomMeasureLaw_ae_restrict_finite {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {E : Set S} (hE : MeasurableSet E) (hκ : κ E < ⊤) : + ∀ᵐ η ∂poissonRandomMeasureLaw κ, (η.restrict E) univ < ⊤ := by + have he : (∫⁻ η, η E ∂poissonRandomMeasureLaw κ) = κ E := by + simpa only [lintegral_indicator hE,lintegral_one,Measure.restrict_apply_univ] + using poissonRandomMeasureLaw_campbell κ (measurable_const.indicator hE : + Measurable (E.indicator (fun _ : S => (1 : ℝ≥0∞)))) + simpa only [Measure.restrict_apply_univ] using + ae_lt_top (Measure.measurable_coe hE) (he ▸ hκ.ne) + +lemma poissonRandomMeasureLaw_ae_null {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {E : Set S} (hE : MeasurableSet E) (hκ : κ E = 0) : + ∀ᵐ η ∂poissonRandomMeasureLaw κ, η E = 0 := by + have he : (∫⁻ η, η E ∂poissonRandomMeasureLaw κ) = 0 := by + rw [← hκ] + simpa only [lintegral_indicator hE,lintegral_one,Measure.restrict_apply_univ] + using poissonRandomMeasureLaw_campbell κ (measurable_const.indicator hE : + Measurable (E.indicator (fun _ : S => (1 : ℝ≥0∞)))) + exact (lintegral_eq_zero_iff (Measure.measurable_coe hE)).mp he + +lemma stablePoissonTotal_rpow_integrable {b a : ℝ} (hb0 : 0 < b) (hb1 : b < 1) + (hab : a < b) : Integrable (fun η => stablePoissonTotal η ^ a) + (poissonRandomMeasureLaw (stableLogIntensity b)) := by + by_cases ha : 0 ≤ a + · exact stablePoissonTotal_fractional_integrable hb0 hb1 ha hab + · have ha' : 0 < -a := neg_pos.mpr (lt_of_not_ge ha) + simpa only [neg_neg] using stablePoissonTotal_negative_integrable hb0 hb1 ha' + +lemma log_sq_le_two_rpow {x ε : ℝ} (hx : 0 < x) (hε : 0 < ε) : + (Real.log x)^2 ≤ (x^(2*ε)+x^(-(2*ε)))/ε^2 := by + have hpow : (x^ε/ε)^2 = x^(2*ε)/ε^2 := by + rw [div_pow,← Real.rpow_two,← Real.rpow_mul hx.le] + congr 2 + ring + have hinvpow : ((x⁻¹)^ε/ε)^2 = x^(-(2*ε))/ε^2 := by + rw [div_pow,← Real.rpow_two,← Real.rpow_mul (inv_nonneg.mpr hx.le), + Real.inv_rpow hx.le,← Real.rpow_neg hx.le] + congr 2 + ring + by_cases hl : 0 ≤ Real.log x + · have hh := pow_le_pow_left₀ hl (Real.log_le_rpow_div hx.le hε) 2 + rw [hpow] at hh + exact hh.trans (div_le_div_of_nonneg_right (le_add_of_nonneg_right (Real.rpow_nonneg hx.le _)) (sq_nonneg ε)) + · have hh := pow_le_pow_left₀ (le_of_lt (neg_pos.mpr (lt_of_not_ge hl))) + (show -Real.log x ≤ (x⁻¹)^ε/ε by + simpa only [Real.log_inv] using Real.log_le_rpow_div (inv_nonneg.mpr hx.le) hε) 2 + rw [neg_sq,hinvpow] at hh + exact hh.trans (div_le_div_of_nonneg_right (le_add_of_nonneg_left (Real.rpow_nonneg hx.le _)) (sq_nonneg ε)) + +lemma stablePoissonTotal_weighted_log_sq_integrable {b a : ℝ} (hb0 : 0 < b) (hb1 : b < 1) + (hab : a < b) : Integrable (fun η => stablePoissonTotal η ^ a * + (Real.log (stablePoissonTotal η))^2) (poissonRandomMeasureLaw (stableLogIntensity b)) := by + let ε : ℝ := (b-a)/4 + have hε : 0 < ε := by dsimp [ε]; linarith + have hplus : a+2*ε < b := by dsimp [ε]; linarith + have hminus : a-2*ε < b := by linarith + have hI := ((stablePoissonTotal_rpow_integrable hb0 hb1 hplus).add + (stablePoissonTotal_rpow_integrable hb0 hb1 hminus)).div_const (ε^2) + apply hI.mono' ((stablePoissonTotal_measurable.pow_const a).mul + (stablePoissonTotal_measurable.log.pow_const (2 : ℕ))).aestronglyMeasurable + filter_upwards [stablePoissonTotal_pos hb0 hb1] with η hη + change |stablePoissonTotal η^a*(Real.log (stablePoissonTotal η))^2| ≤ + (stablePoissonTotal η^(a+2*ε)+stablePoissonTotal η^(a-2*ε))/ε^2 + rw [abs_of_nonneg (mul_nonneg (Real.rpow_nonneg hη.le _) (sq_nonneg _))] + calc + _ ≤ stablePoissonTotal η ^ a * ((stablePoissonTotal η ^ (2*ε)+ + stablePoissonTotal η ^ (-(2*ε)))/ε^2) := + mul_le_mul_of_nonneg_left (log_sq_le_two_rpow hη hε) (Real.rpow_nonneg hη.le _) + _ = _ := by + rw [← mul_div_assoc,mul_add,← Real.rpow_add hη,← Real.rpow_add hη] + rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/TripleGaussianReplica.lean b/lean/OAI/Probability/Perceptron/Interpolation/TripleGaussianReplica.lean new file mode 100644 index 0000000000000000000000000000000000000000..12be5025b0dda7c7cbb638b62b35f35e0ea63dbb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/TripleGaussianReplica.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.TerminalReplicaRestoration +import OAI.Probability.Perceptron.Pressure.CountableTerminalRestoration + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators +namespace SphericalPerceptronFreeEnergy +variable {I J K : Type} [Fintype I] [Fintype J] [Fintype K] + +def gaussianLeafValue (k : ℕ) + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (R : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) (g : ℕ→ℝ) (l : IndexedLeaf k) : EuclideanSpace ℝ I := + indexedLeafState (gaussianLinearMarkStep A) k + ((fun _ => R (indexedGaussianDisorder k I g).1),(indexedGaussianDisorder k I g).2) l 0 + +def tripleGaussianCountableData (k : ℕ) (b : IndexedCascadeBase k) + (t : ((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ)) : TripleGaussianData I J K k := + ((((indexedGaussianDisorder k I t.1.1).1,(indexedGaussianDisorder k J t.1.2).1), + (indexedGaussianDisorder k K t.2).1), + (b,(indexedMarksZip k ((indexedGaussianDisorder k I t.1.1).2, + (indexedGaussianDisorder k J t.1.2).2),(indexedGaussianDisorder k K t.2).2))) + +lemma tripleGaussianLeafState (k : ℕ) + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (x : ℕ→EuclideanSpace ℝ I) (y : ℕ→EuclideanSpace ℝ J) (z : ℕ→EuclideanSpace ℝ K) + (a : IndexedCascadeMarks (EuclideanSpace ℝ I) k) (b : IndexedCascadeMarks (EuclideanSpace ℝ J) k) + (c : IndexedCascadeMarks (EuclideanSpace ℝ K) k) (l : IndexedLeaf k) : + indexedLeafState (tripleGaussianStep A B C) k (((x,y),z),indexedMarksZip k (indexedMarksZip k (a,b),c)) l = + ((indexedLeafState (gaussianLinearMarkStep A) k (x,a) l, + indexedLeafState (gaussianLinearMarkStep B) k (y,b) l), + indexedLeafState (gaussianLinearMarkStep C) k (z,c) l) := by + have he := indexedLeafState_product + (fun p : ((ℕ→EuclideanSpace ℝ I)×(ℕ→EuclideanSpace ℝ J))× + (EuclideanSpace ℝ I×EuclideanSpace ℝ J) => + (gaussianLinearMarkStep A (p.1.1,p.2.1),gaussianLinearMarkStep B (p.1.2,p.2.2))) + (gaussianLinearMarkStep C) k (x,y) z (indexedMarksZip k (a,b)) c l + rw [indexedLeafState_product] at he + exact he + +lemma tripleGaussianPair_replica (k : ℕ) + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (R : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (Q : EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (T : EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (H : EuclideanSpace ℝ I→ℝ) (G : EuclideanSpace ℝ J→ℝ) (F : EuclideanSpace ℝ K→ℝ) + (hH : Measurable H) (hG : Measurable G) (hF : Measurable F) + (d : Fin (k+1)) (f : EuclideanSpace ℝ I→ℝ) (g : EuclideanSpace ℝ J→ℝ) + (b : IndexedCascadeBase k) (t : ((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ)) + (hi : Integrable (fun l => Real.exp ((H (gaussianLeafValue k A R t.1.1 l)+ + G (gaussianLeafValue k B Q t.1.2 l))+F (gaussianLeafValue k C T t.2 l))) (indexedLeafProbability k b)) : + tripleGaussianPair k A B C R Q T H G F d f g (tripleGaussianCountableData (I:=I) (J:=J) (K:=K) k b t) = + gibbsReplicaMean (indexedLeafProbability k b) + (fun l => (H (gaussianLeafValue k A R t.1.1 l)+G (gaussianLeafValue k B Q t.1.2 l))+ + F (gaussianLeafValue k C T t.2 l)) 2 + (fun l => if indexedCommonDepth k (l 0) (l 1)=d then + (f (gaussianLeafValue k A R t.1.1 (l 0))*g (gaussianLeafValue k B Q t.1.2 (l 0)))* + (f (gaussianLeafValue k A R t.1.1 (l 1))*g (gaussianLeafValue k B Q t.1.2 (l 1))) else 0) := by + have ht : Measurable (tripleGaussianTerminal H G F) := by unfold tripleGaussianTerminal; fun_prop + unfold tripleGaussianPair + have he := indexedTerminalPairMean_replica (tripleGaussianStep A B C) (tripleGaussianStep_measurable A B C) + k (tripleGaussianTerminal H G F) ht + (tripleGaussianRoot R Q T (tripleGaussianCountableData (I:=I) (J:=J) (K:=K) k b t).1) d (tripleGaussianObservable f g) + ((tripleGaussianCountableData (I:=I) (J:=J) (K:=K) k b t).2.1,indexedMarksZip k (tripleGaussianCountableData (I:=I) (J:=J) (K:=K) k b t).2.2) + have hstate (l : IndexedLeaf k) := tripleGaussianLeafState k A B C + (fun _ => R (indexedGaussianDisorder k I t.1.1).1) + (fun _ => Q (indexedGaussianDisorder k J t.1.2).1) + (fun _ => T (indexedGaussianDisorder k K t.2).1) + (indexedGaussianDisorder k I t.1.1).2 (indexedGaussianDisorder k J t.1.2).2 + (indexedGaussianDisorder k K t.2).2 l + simp only [tripleGaussianCountableData,tripleGaussianRoot] at he ⊢ + simp only [tripleGaussianTerminal,hstate] at he + have hv := he hi + simp only [tripleGaussianObservable] at hv + rw [hv] + congr 1 + funext l + simp only [indexedTerminalEnergy,tripleGaussianTerminal,hstate,gaussianLeafValue] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Interpolation/VectorReplicaDirectionBound.lean b/lean/OAI/Probability/Perceptron/Interpolation/VectorReplicaDirectionBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..936dd5751743286ec0a2dd0b11467297ea58d648 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Interpolation/VectorReplicaDirectionBound.lean @@ -0,0 +1,80 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IntegratedConvex + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma euclideanGaussian_replica_direction_bound {I : Type} [Fintype I] {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (r : ℕ) + {H : S→ℝ} {V : S→EuclideanSpace ℝ I} {W : (Fin r→S)→EuclideanSpace ℝ I} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) + {A C D K : ℝ} (hC : 0≤C) (hD : 0≤D) (hK : 0≤K) + (hA : ∀ x, |H x|≤A) (hVC : ∀ x, ‖V x‖≤C) (hWD : ∀ x, ‖W x‖≤D) + (hWK : ∀ x y, |inner ℝ (W x) (V y)|≤K) : + |∫ g, gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) r + (fun x => inner ℝ (W x) g) ∂stdGaussian (EuclideanSpace ℝ I)|≤2*r*K := by + let ν := Measure.pi (fun _ : Fin r => μ) + let HH := replicaPotential H r + let VV := fun x : Fin r→S => ∑ l, V (x l) + have hHH : Measurable HH := replicaPotential_measurable hH r + have hVV : Measurable VV := Finset.measurable_sum _ fun l _ => hV.comp (measurable_pi_apply l) + have hHHA (x : Fin r→S) : |HH x|≤r*A := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _ : Fin r, A := Finset.sum_le_sum fun l _ => hA (x l) + _ = _ := by simp + have hVVC (x : Fin r→S) : ‖VV x‖^2≤(r*C)^2 := by + have hb : ‖VV x‖≤r*C := by + apply (norm_sum_le _ _).trans + calc + _ ≤ ∑ _ : Fin r, C := Finset.sum_le_sum fun l _ => hVC (x l) + _ = _ := by simp + exact (sq_le_sq₀ (norm_nonneg _) (mul_nonneg (Nat.cast_nonneg r) hC)).2 hb + have hWWD (x : Fin r→S) : ‖W x‖^2≤D^2 := + (sq_le_sq₀ (norm_nonneg _) hD).2 (hWD x) + have hc (x y : Fin r→S) : |inner ℝ (W x) (VV y)|≤r*K := by + dsimp only [VV] + rw [inner_sum] + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _ : Fin r, K := Finset.sum_le_sum fun l _ => hWK x (y l) + _ = _ := by simp + have he := euclideanGaussian_tiltMean_ibp ν hHH hVV hW hHHA hVVC hWWD + have hham (g : EuclideanSpace ℝ I) : (fun x => HH x+inner ℝ (VV x) g)= + replicaPotential (fun x => H x+inner ℝ (V x) g) r := by + funext x + simp only [HH,VV,replicaPotential,sum_inner,Finset.sum_add_distrib] + have hl (g : EuclideanSpace ℝ I) : + gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) r (fun x => inner ℝ (W x) g)= + tiltMean ν (fun x => HH x+inner ℝ (VV x) g) (fun x => inner ℝ (W x) g) 1 := by + rw [hham] + rfl + simp_rw [hl] + rw [he] + apply abs_integral_le_integral_abs.trans + calc + _ ≤ ∫ _ : EuclideanSpace ℝ I, (2*r*K:ℝ) ∂stdGaussian (EuclideanSpace ℝ I) := by + apply integral_mono_of_nonneg (ae_of_all _ fun _ => abs_nonneg _) (integrable_const _) + apply ae_of_all + intro g + have hm : Measurable (fun x => HH x+inner ℝ (VV x) g) := hHH.add (hVV.inner measurable_const) + have hm1 : Measurable (fun x => inner ℝ (W x) (VV x)) := hW.inner hVV + have hm2 : Measurable (fun x : Fin 2→(Fin r→S) => inner ℝ (W (x 1)) (VV (x 0))) := + (hW.comp (measurable_pi_apply 1)).inner (hVV.comp (measurable_pi_apply 0)) + have hb1 := tiltMean_bound_general ν hm hm1 (t:=1) (by positivity : 0≤(r:ℝ)*K) (fun x => hc x x) + have hb2 : |gibbsReplicaMean ν (fun x => HH x+inner ℝ (VV x) g) 2 + (fun x => inner ℝ (W (x 1)) (VV (x 0)))|≤(r:ℝ)*K := + tiltMean_bound_general (Measure.pi (fun _ : Fin 2 => ν)) + (replicaPotential_measurable hm 2) hm2 (by positivity) + (fun x => hc (x 1) (x 0)) + exact (abs_sub _ _).trans (by linarith) + _ = _ := by simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Main.lean b/lean/OAI/Probability/Perceptron/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d8114c59ca04ca78a686655d22babf0c94d14b2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Main.lean @@ -0,0 +1,45 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ReplicaMeanConst +import OAI.Probability.Perceptron.Cascade.ReweightedMomentComparison +import OAI.Probability.Perceptron.Cavity.CavityBoundedContinuous + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma expectedPressure_terminal_scaling (α β : ℝ) (φ : ℝ→ᵇℝ) (n : ℕ) : + expectedPressure α β φ (n+1)=expectedPressure α 1 (β • φ) (n+1) := by + unfold expectedPressure + apply integral_congr_ae + filter_upwards [] with g + rw [←normalizedPatternLog_source α β φ n g, + ←normalizedPatternLog_source α 1 (β • φ) n g,one_smul] + +theorem main (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) + (α β : ℝ) (hα : 0 < α) (_hβ : 0 < β) (φ : ℝ →ᵇ ℝ) : + ∃ p : ℝ, variationalValue P α β φ = (p : EReal) ∧ + Tendsto (fun N : ℕ => expectedPressure α β φ (N + 1)) atTop (𝓝 p) ∧ + ∀ ε : ℝ, 0 < ε → + Tendsto (fun N : ℕ => patternLaw α (N + 1) + {g | ε < |pressure α β φ (N + 1) g - p|}) atTop (𝓝 0) := by + let p:=(terminalVariational P α (β • φ)).toReal + have hp : Tendsto (fun N : ℕ=>expectedPressure α β φ (N+1)) atTop (𝓝 p) := by + have heq : (fun N : ℕ=>expectedPressure α β φ (N+1)) = + (fun N : ℕ=>expectedPressure α 1 (β • φ) (N+1)) := + funext (expectedPressure_terminal_scaling α β φ) + rw [heq] + exact expectedPressure_limit_terminal P hB hα (β • φ) + refine ⟨p,?_,hp,?_⟩ + · rw [variationalValue_eq_terminal] + exact (terminalVariational_coe_toReal P α hα.le (β • φ)).symm + · exact pressure_probability_of_expected_limit α β hα.le φ p hp + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Model.lean b/lean/OAI/Probability/Perceptron/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..6daf6d78d411c2c790b07ac8a89e47c6b59c77ed --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Model.lean @@ -0,0 +1,101 @@ +import Mathlib + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction + +namespace SphericalPerceptronFreeEnergy + +abbrev Time := unitInterval +abbrev BrownianPath := C(ℝ≥0, ℝ) + +instance : MeasurableSpace BrownianPath := borel BrownianPath +instance : BorelSpace BrownianPath := ⟨rfl⟩ + +abbrev Spin (N : ℕ) := EuclideanSpace ℝ (Fin N) + +def patternCount (α : ℝ) (N : ℕ) : ℕ := ⌊α * (N : ℝ)⌋₊ +abbrev Patterns (α : ℝ) (N : ℕ) := Fin (patternCount α N) → Fin N → ℝ + +def patternLaw (α : ℝ) (N : ℕ) : Measure (Patterns α N) := + Measure.pi fun _ => Measure.pi fun _ => gaussianReal 0 1 + +def unitSphereLaw (N : ℕ) : Measure (Metric.sphere (0 : Spin N) 1) := + let s := (volume : Measure (Spin N)).toSphere + (s Set.univ)⁻¹ • s + +def sphereLaw (N : ℕ) : Measure (Spin N) := + (unitSphereLaw N).map fun x => Real.sqrt (N : ℝ) • x.val + +def patternField {α : ℝ} {N : ℕ} (g : Patterns α N) + (a : Fin (patternCount α N)) (x : Spin N) : ℝ := + (∑ i : Fin N, g a i * x i) / Real.sqrt (N : ℝ) + +def hamiltonian (α : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) (g : Patterns α N) + (x : Spin N) : ℝ := + ∑ a : Fin (patternCount α N), φ (patternField g a x) + +def pressure (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) (g : Patterns α N) : ℝ := + Real.log (∫ x, Real.exp (β * hamiltonian α φ N g x) ∂sphereLaw N) / (N : ℝ) + +def expectedPressure (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) : ℝ := + ∫ g, pressure α β φ N g ∂patternLaw α N + +structure Trial where + toFun : Time → ℝ + monotone : Monotone toFun + measurable : Measurable toFun + nonneg : ∀ t, 0 ≤ toFun t + le_one : ∀ t, toFun t ≤ 1 + +instance : CoeFun Trial (fun _ => Time → ℝ) := ⟨Trial.toFun⟩ + +def timeLaw : Measure Time := Measure.comap Subtype.val volume + +def tailIntegral (m : Trial) (t : Time) : ℝ := + ∫ s in Set.Ici t, m s ∂timeLaw + +def entropy (m : Trial) : ℝ≥0∞ := + (∫⁻ t, (ENNReal.ofReal (tailIntegral m t))⁻¹ - + (ENNReal.ofReal (1 - (t : ℝ)))⁻¹ ∂timeLaw) / 2 + +def brownianEval (t : ℝ≥0) (ω : BrownianPath) : ℝ := ω t + +@[instance_reducible] def nullSigma (P : Measure BrownianPath) : MeasurableSpace BrownianPath := + MeasurableSpace.generateFrom {s | P s = 0} + +@[instance_reducible] def usualBrownianSigma (P : Measure BrownianPath) (t : Time) : + MeasurableSpace BrownianPath := + ⨅ s : {s : ℝ≥0 // (t : ℝ) < s}, + (⨆ r : {r : ℝ≥0 // r ≤ s.val}, + MeasurableSpace.comap (brownianEval r.val) (borel ℝ)) ⊔ nullSigma P + +def Progressive (P : Measure BrownianPath) (v : Time → BrownianPath → ℝ) : Prop := + ∀ t : Time, + @Measurable (Set.Iic t × BrownianPath) ℝ + (MeasurableSpace.prod inferInstance (usualBrownianSigma P t)) (borel ℝ) + (fun p => v p.1.val p.2) + +def controlCost (P : Measure BrownianPath) (m : Trial) + (v : Time → BrownianPath → ℝ) : ℝ≥0∞ := + ∫⁻ ω, ∫⁻ t, ENNReal.ofReal (m t * v t ω ^ 2) ∂timeLaw ∂P + +def controlPayoff (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) (m : Trial) + (v : Time → BrownianPath → ℝ) : ℝ := + (∫ ω, f (brownianEval 1 ω + ∫ t, m t * v t ω ∂timeLaw) ∂P) - + (controlCost P m v).toReal / 2 + +def controlValue (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) (m : Trial) : ℝ := + sSup {a | ∃ v : Time → BrownianPath → ℝ, + Progressive P v ∧ controlCost P m v < ∞ ∧ a = controlPayoff P f m v} + +def variationalValue (P : Measure BrownianPath) (α β : ℝ) (φ : ℝ →ᵇ ℝ) : EReal := + ⨅ m : Trial, ((α * controlValue P (β • φ) m : ℝ) : EReal) + (entropy m).toEReal + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/CountableTerminalRestoration.lean b/lean/OAI/Probability/Perceptron/Pressure/CountableTerminalRestoration.lean new file mode 100644 index 0000000000000000000000000000000000000000..2cca26e18d2c163a22edf8e5f395a2d4e4ea9e48 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/CountableTerminalRestoration.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.TerminalRestorationLaw +import OAI.Probability.Perceptron.Variational.TripleRootRegroup + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable (I J K : Type) [Fintype I] [Fintype J] [Fintype K] + +abbrev TripleGaussianState := ((ℕ→EuclideanSpace ℝ I)×(ℕ→EuclideanSpace ℝ J))×(ℕ→EuclideanSpace ℝ K) +abbrev TripleGaussianMark := (EuclideanSpace ℝ I×EuclideanSpace ℝ J)×EuclideanSpace ℝ K +abbrev TripleGaussianData (k : ℕ) := + TripleGaussianMark I J K × (IndexedCascadeBase k× + (IndexedCascadeMarks (EuclideanSpace ℝ I×EuclideanSpace ℝ J) k×IndexedCascadeMarks (EuclideanSpace ℝ K) k)) + +variable {I J K} +def tripleGaussianStep + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) : + TripleGaussianState I J K×TripleGaussianMark I J K→TripleGaussianState I J K := + fun p => ((gaussianLinearMarkStep A (p.1.1.1,p.2.1.1), + gaussianLinearMarkStep B (p.1.1.2,p.2.1.2)),gaussianLinearMarkStep C (p.1.2,p.2.2)) + +lemma tripleGaussianStep_measurable + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) : Measurable (tripleGaussianStep A B C) := by + have ha := gaussianLinearMarkStep_measurable A + have hb := gaussianLinearMarkStep_measurable B + have hc := gaussianLinearMarkStep_measurable C + unfold tripleGaussianStep + fun_prop + +def tripleGaussianTerminal + (H : EuclideanSpace ℝ I→ℝ) (G : EuclideanSpace ℝ J→ℝ) (F : EuclideanSpace ℝ K→ℝ) : + TripleGaussianState I J K→ℝ := fun x => (H (x.1.1 0)+G (x.1.2 0))+F (x.2 0) + +def tripleGaussianObservable (f : EuclideanSpace ℝ I→ℝ) (g : EuclideanSpace ℝ J→ℝ) : + TripleGaussianState I J K→ℝ := fun x => f (x.1.1 0)*g (x.1.2 0) + +def tripleGaussianRoot + (R : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (Q : EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (T : EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) : + TripleGaussianMark I J K→TripleGaussianState I J K := + fun p => ((fun _ => R p.1.1,fun _ => Q p.1.2),fun _ => T p.2) + +def tripleGaussianPair (k : ℕ) + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (R : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (Q : EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (T : EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (H : EuclideanSpace ℝ I→ℝ) (G : EuclideanSpace ℝ J→ℝ) (F : EuclideanSpace ℝ K→ℝ) + (d : Fin (k+1)) (f : EuclideanSpace ℝ I→ℝ) (g : EuclideanSpace ℝ J→ℝ) + (p : TripleGaussianData I J K k) : ℝ := + indexedTerminalPairMean (tripleGaussianStep A B C) k (tripleGaussianTerminal H G F) + (tripleGaussianRoot R Q T p.1) d (tripleGaussianObservable f g) + (p.2.1,indexedMarksZip k p.2.2) + +lemma tripleGaussianPair_measurable (k : ℕ) + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (R : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (Q : EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (T : EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (H : EuclideanSpace ℝ I→ℝ) (G : EuclideanSpace ℝ J→ℝ) (F : EuclideanSpace ℝ K→ℝ) + (hH : Measurable H) (hG : Measurable G) (hF : Measurable F) + (d : Fin (k+1)) (f : EuclideanSpace ℝ I→ℝ) (g : EuclideanSpace ℝ J→ℝ) + (hf : Measurable f) (hg : Measurable g) : + Measurable (tripleGaussianPair k A B C R Q T H G F d f g) := by + have ht : Measurable (tripleGaussianTerminal H G F) := by unfold tripleGaussianTerminal; fun_prop + have ho : Measurable (tripleGaussianObservable (K:=K) f g) := by unfold tripleGaussianObservable; fun_prop + have hr : Measurable (tripleGaussianRoot R Q T) := by unfold tripleGaussianRoot; fun_prop + have hm := indexedTerminalPairMean_joint_measurable (tripleGaussianStep A B C) + (tripleGaussianStep_measurable A B C) k (tripleGaussianTerminal H G F) ht d + (tripleGaussianObservable f g) ho + have hp : Measurable (fun p : TripleGaussianData I J K k => + (tripleGaussianRoot R Q T p.1,(p.2.1,indexedMarksZip k p.2.2))) := + (hr.comp measurable_fst).prodMk (measurable_snd.fst.prodMk + ((indexedMarksZip_measurable k).comp measurable_snd.snd)) + have hc := hm.comp hp + exact hc + +theorem countable_three_terminal_pair_value (k : ℕ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 fun _ => R r) k + (fun i => tiltedStateStep (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) (gaussianLinearMarkStep A) (z i) + (finiteCascadeShifts (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) (gaussianLinearMarkStep A) k z (fun x => H (x 0)) i)) + (fun x => f (x 0)) d * + rootPathCorrelation (stdGaussian (EuclideanSpace ℝ J)) (fun r => fun _ => Q r) k + (fun i => tiltedStateStep (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) (gaussianLinearMarkStep B) (z i) + (finiteCascadeShifts (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) (gaussianLinearMarkStep B) k z (fun x => G (x 0)) i)) + (fun x => g (x 0)) d) := by + let : IsGaussian (gaussianMarkLaw (E:=EuclideanSpace ℝ I) : Measure (EuclideanSpace ℝ I)) := (inferInstance : IsGaussian (stdGaussian (EuclideanSpace ℝ I))) + let : IsGaussian (gaussianMarkLaw (E:=EuclideanSpace ℝ J) : Measure (EuclideanSpace ℝ J)) := (inferInstance : IsGaussian (stdGaussian (EuclideanSpace ℝ J))) + let : IsGaussian (gaussianMarkLaw (E:=EuclideanSpace ℝ K) : Measure (EuclideanSpace ℝ K)) := (inferInstance : IsGaussian (stdGaussian (EuclideanSpace ℝ K))) + have hI := gaussianLinearRecursion_realization (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) A hH k z hz0 + have hJ := gaussianLinearRecursion_realization (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) B hG k z hz0 + have hK := gaussianLinearRecursion_realization (gaussianMarkLaw (E:=EuclideanSpace ℝ K)) C hF k z hz0 + have hv := indexedTerminalPairMean_two_fresh_old + (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ K)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ K)) + (gaussianLinearMarkStep A) (gaussianLinearMarkStep B) (gaussianLinearMarkStep C) + (gaussianLinearMarkStep_measurable A) (gaussianLinearMarkStep_measurable B) (gaussianLinearMarkStep_measurable C) + k z hz hz0 hz1 (fun x => H (x 0)) (fun x => G (x 0)) (fun x => F (x 0)) + (hH.continuous.measurable.comp (measurable_pi_apply 0)) + (hG.continuous.measurable.comp (measurable_pi_apply 0)) + (hF.continuous.measurable.comp (measurable_pi_apply 0)) hI.2 hJ.2 hK.2 + (fun r => fun _ => R r) (fun r => fun _ => Q r) (fun r => fun _ => T r) + (by fun_prop) (by fun_prop) (by fun_prop) d (fun x => f (x 0)) (fun x => g (x 0)) + (hf.comp (measurable_pi_apply 0)) (hg.comp (measurable_pi_apply 0)) D E hD hE (fun x => hfB _) (fun x => hgB _) + have hp := indexedGaussian_three_regroup_law k z I J K + have hm := tripleGaussianPair_measurable k A B C R Q T H G F hH.continuous.measurable + hG.continuous.measurable hF.continuous.measurable d f g hf hg + have he := integral_map (μ:=(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((countableGaussianLaw.prod countableGaussianLaw).prod countableGaussianLaw)) + hp.measurable.aemeasurable hm.aestronglyMeasurable + rw [hp.map_eq] at he + exact he.symm.trans hv + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/EnrichedConcentration.lean b/lean/OAI/Probability/Perceptron/Pressure/EnrichedConcentration.lean new file mode 100644 index 0000000000000000000000000000000000000000..a46123c243c1ad82d3fe32178e22f0ff398f1aaf --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/EnrichedConcentration.lean @@ -0,0 +1,47 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianLinearVariance + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma enrichedTerminal_C1 (n M : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin (n+1) → ℝ) (p : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) + (htop : ℝ) : + ∃ D : EnrichedMark (n+1) (n+1) p → StrongDual ℝ (EnrichedMark (n+1) (n+1) p), + Continuous D ∧ ∀ x, HasFDerivAt (enrichedTerminal n M f g p u htop) (D x) x := by + let W := normalizedPatternEnergy (n+1) M f g + let V := fun x : NormalizedSpin (n+1) => innerSL ℝ (sourceEnrichedFeature (n+1) p u x) + have hW : Continuous W := (normalizedPatternEnergy_continuous (n+1) M f).comp + (continuous_const.prodMk continuous_id) + have hV : Continuous V := (innerSL ℝ).continuous.comp (enrichedFeature_continuous _ _ _ _ _) + have hWB : ∀ x, |W x| ≤ (M:ℝ)*‖f‖ := normalizedPatternEnergy_bound _ _ _ _ + have hVB : ∀ x, ‖V x‖ ≤ enrichedFeatureBound (n+1) u := fun x => by + change ‖innerSL ℝ (sourceEnrichedFeature (n+1) p u x)‖ ≤ _ + rw [innerSL_apply_norm,sourceEnrichedFeature_norm] + refine ⟨vectorLogDerivative (unitSphereLaw (n+1)) W V, + vectorLogDerivative_continuous (unitSphereLaw (n+1)) hW.measurable hV.measurable + (enrichedFeatureBound (n+1) u).coe_nonneg hWB hVB,?_⟩ + intro x + exact (vectorLogPartition_hasFDerivAt (unitSphereLaw (n+1)) hW.measurable hV.measurable + (enrichedFeatureBound (n+1) u).coe_nonneg hWB hVB x).sub_const _ + +lemma enrichedCascadeLog_fixed_patterns_variance (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) + (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 + enrichedTerminal n M f a.1 p u htop a.2) := by + let V := fun x : NormalizedSpin (n+1) => innerSL ℝ (sourceEnrichedFeature (n+1) p u x) + have hV : Continuous V := (innerSL ℝ).continuous.comp (enrichedFeature_continuous _ _ _ _ _) + have hW := normalizedPatternEnergy_continuous (n+1) M f + have hm : Measurable (fun a : ((Fin M → Fin (n+1) → ℝ) × EnrichedMark (n+1) (n+1) p) × NormalizedSpin (n+1) => + Real.exp (normalizedPatternEnergy (n+1) M f a.1.1 a.2+V a.2 a.1.2)) := + ((hW.comp ((continuous_fst.comp continuous_fst).prodMk continuous_snd)).add + ((hV.comp continuous_snd).clm_apply (continuous_snd.comp continuous_fst))).rexp.measurable + exact hm.stronglyMeasurable.integral_prod_right'.measurable.log.sub_const _ + +lemma enrichedCascadeLog_parameters_measurable (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) : + Measurable (fun a : (Fin M → Fin (n+1) → ℝ) × + (EnrichedMark (n+1) (n+1) p × DecoratedCascade (EnrichedMark (n+1) (n+1) p) k) => + enrichedCascadeLog n M k f a.1 p d u h a.2) := by + have hh := gaussianLinearCascadeLog_parameter_measurable + (P := Fin M → Fin (n+1) → ℝ) (E := EnrichedMark (n+1) (n+1) p) + (enrichedIncrementMap p d h) (enrichedRootMap p d h) + (H := fun g => enrichedTerminal n M f g p u (h (Fin.last k))) + (enrichedTerminal_parameters_measurable n M f p u (h (Fin.last k))) k z + simpa only [enrichedCascadeLog,gaussianLinearCascadeLog] using hh + +def enrichedExpectedLog (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (g : Fin M → Fin (n+1) → ℝ) : ℝ := + ∫ a, enrichedCascadeLog n M k f g p d u h a ∂enrichedDisorderLaw n k p z + +lemma enrichedExpectedLog_measurable (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) : + Measurable (enrichedExpectedLog n M k f p d u h z) := + (enrichedCascadeLog_parameters_measurable n M k f p d u h z).stronglyMeasurable.integral_prod_right'.measurable + +lemma enrichedTerminal_pattern_change (n M M' : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin (n+1) → ℝ) (g' : Fin M' → Fin (n+1) → ℝ) + (p : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (htop : ℝ) {C : ℝ} + (hC : ∀ x, |normalizedPatternEnergy (n+1) M f g x- + normalizedPatternEnergy (n+1) M' f g' x| ≤ C) + (a : EnrichedMark (n+1) (n+1) p) : + |enrichedTerminal n M f g p u htop a-enrichedTerminal n M' f g' p u htop a| ≤ C := by + have hW (M : ℕ) (g : Fin M → Fin (n+1) → ℝ) : + Continuous (normalizedPatternEnergy (n+1) M f g) := + (normalizedPatternEnergy_continuous (n+1) M f).comp (continuous_const.prodMk continuous_id) + have hV : Continuous (fun x : NormalizedSpin (n+1) => innerSL ℝ (sourceEnrichedFeature (n+1) p u x)) := + (innerSL ℝ).continuous.comp (enrichedFeature_continuous _ _ _ _ _) + simp only [enrichedTerminal,sub_sub_sub_cancel_right] + exact vectorLogPartition_data_bound (unitSphereLaw (n+1)) (hW M g).measurable (hW M' g').measurable + hV.measurable (normalizedPatternEnergy_bound _ _ _ _) (normalizedPatternEnergy_bound _ _ _ _) + (C := enrichedFeatureBound (n+1) u) + (fun x => by rw [innerSL_apply_norm,sourceEnrichedFeature_norm]) hC a + +lemma enrichedExpectedLog_pattern_change (n M M' k : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin (n+1) → ℝ) (g' : Fin M' → Fin (n+1) → ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 ?_⟩ + have hh := enrichedExpectedLog_pattern_change n M M k f g 0 p d u h z hz hz0 hz1 + (C := 2*(M:ℝ)*‖f‖) (fun x => (abs_sub _ _).trans (by + have h1 := normalizedPatternEnergy_bound (n+1) M f g x + have h0 := normalizedPatternEnergy_bound (n+1) M f 0 x + linarith)) + have ht := abs_sub_le (enrichedExpectedLog n M k f p d u h z g) + (enrichedExpectedLog n M k f p d u h z 0) 0 + simp only [sub_zero] at ht + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/EnrichedPatternVariance.lean b/lean/OAI/Probability/Perceptron/Pressure/EnrichedPatternVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c5f4e0b95da27353dfa06e5671796408c8b6bc6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/EnrichedPatternVariance.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.EnrichedConcentration +import OAI.Probability.Perceptron.Pressure.EnrichedPatternMean +import OAI.Probability.Perceptron.Variational.MeasurableVariance + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def finitePatternRowsLaw (N M : ℕ) : Measure (Fin M → Fin N → ℝ) := + Measure.pi fun _ : Fin M => Measure.pi fun _ : Fin N => gaussianReal 0 1 + +instance (N M : ℕ) : IsProbabilityMeasure (finitePatternRowsLaw N M) := by + unfold finitePatternRowsLaw + infer_instance + +lemma enrichedExpectedLog_memLp (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 gaussianReal 0 1) M + (enrichedExpectedLog_measurable n M k f p d u h z) hC + (enrichedExpectedLog_update n M k f p d u h z hz hz0 hz1) + +def enrichedFixedCountLog (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) + (a : (Fin M → Fin (n+1) → ℝ) × + (EnrichedMark (n+1) (n+1) p × DecoratedCascade (EnrichedMark (n+1) (n+1) p) k)) : ℝ := + enrichedCascadeLog n M k f a.1 p d u h a.2 + +lemma enrichedFixedCountLog_variance (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 F (g,a)) 2 ν ∧ variance (fun a => F (g,a)) ν ≤ K := + enrichedCascadeLog_fixed_patterns_variance n M k f g p d u h z hz hz0 hz1 + have hp : MemLp F 2 (μ.prod ν) := memLp_prod_of_conditional_square μ ν + (enrichedCascadeLog_parameters_measurable n M k f p d u h z) hG K (fun g => (hs g).1) + (fun g => by + have hv := (hs g).2 + rw [variance_eq_integral (hs g).1.aestronglyMeasurable.aemeasurable] at hv + exact hv) + refine ⟨hp,?_⟩ + exact variance_prod_le_memLp μ ν hp (fun g => (hs g).1) hG (fun g => (hs g).2) + (enrichedExpectedLog_variance n M k f p d u h z hz hz0 hz1) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/FiniteTerminal.lean b/lean/OAI/Probability/Perceptron/Pressure/FiniteTerminal.lean new file mode 100644 index 0000000000000000000000000000000000000000..f7d2f3e0eb401806cefdc250f1c7187b1d93ca79 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/FiniteTerminal.lean @@ -0,0 +1,428 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.HeatLogBCF +import OAI.Probability.Perceptron.Variational.CovarianceMatrix + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial + +lemma le_terminalTrial (m : Trial) (r t : Time) : m t ≤ terminalTrial m r t := by + change m t ≤ if r ≤ t then 1 else m t + split_ifs; exact m.le_one t; exact le_rfl + +lemma terminalTrial_finite_range (m : Trial) (r : Time) (h : (Set.range m).Finite) : + (Set.range (terminalTrial m r)).Finite := by + apply (h.insert 1).subset + rintro _ ⟨t,rfl⟩ + change (if r ≤ t then 1 else m t) ∈ _ + split_ifs + · exact mem_insert _ _ + · exact mem_insert_of_mem _ (mem_range_self t) + +lemma terminalTrial_tail (m : Trial) {r t : Time} (hrt : r ≤ t) : + tailIntegral (terminalTrial m r) t = 1 - (t : ℝ) := by + have he : (fun s : Time => terminalTrial m r s) =ᵐ[timeLaw.restrict (Ici t)] (fun _ => (1 : ℝ)) := by + filter_upwards [ae_restrict_mem measurableSet_Ici] with s hs + simp only [terminalTrial, ite_eq_left (hrt.trans hs)] + rw [tailIntegral,integral_congr_ae he] + simp [Measure.real,ENNReal.toReal_ofReal,sub_nonneg.mpr t.property.2] + +lemma tailIntegral_antitone (m : Trial) : Antitone (tailIntegral m) := by + intro s t hst + apply setIntegral_mono_set (trial_integrable m).integrableOn + (Eventually.of_forall fun x => m.nonneg x) + exact Filter.Eventually.of_forall (fun x hx => hst.trans hx) + +lemma terminalTrial_entropy_finite (m : Trial) {r : Time} (hr : (r : ℝ) < 1) : + entropy (terminalTrial m r) < ∞ := by + have hbound : (∫⁻ t, (ENNReal.ofReal (tailIntegral (terminalTrial m r) t))⁻¹ - + (ENNReal.ofReal (1-(t : ℝ)))⁻¹ ∂timeLaw) ≤ (ENNReal.ofReal (1-(r : ℝ)))⁻¹ := by + calc + _ ≤ ∫⁻ _t : Time, (ENNReal.ofReal (1-(r : ℝ)))⁻¹ ∂timeLaw := by + apply lintegral_mono + intro t + dsimp only + by_cases ht : r ≤ t + · rw [terminalTrial_tail m ht,tsub_self] + exact bot_le + · have htr : t ≤ r := le_of_not_ge ht + have hd := tailIntegral_antitone (terminalTrial m r) htr + rw [terminalTrial_tail m le_rfl] at hd + exact (tsub_le_self).trans (ENNReal.inv_le_inv.mpr (ENNReal.ofReal_le_ofReal hd)) + _ = _ := by simp + unfold entropy + apply ENNReal.div_lt_top _ (by norm_num) + exact (hbound.trans_lt (ENNReal.inv_lt_top.mpr (ENNReal.ofReal_pos.mpr (sub_pos.mpr hr)))).ne + +lemma terminalTrial_L1_le (m : Trial) (r : Time) : + (∫ t, |terminalTrial m r t - m t| ∂timeLaw) ≤ 1-(r : ℝ) := by + calc + _ ≤ ∫ t, (Ici r).indicator (fun _ => (1 : ℝ)) t ∂timeLaw := by + apply integral_mono ((trial_integrable _).sub (trial_integrable _)).abs + ((integrable_const (1 : ℝ)).indicator measurableSet_Ici) + intro t + dsimp only [Pi.sub_apply] + rw [abs_of_nonneg (sub_nonneg.mpr (le_terminalTrial m r t))] + by_cases ht : r ≤ t + · simp only [terminalTrial,ite_eq_left ht,Set.indicator_of_mem (show t ∈ Ici r from ht)] + linarith [m.nonneg t] + · simp only [terminalTrial,ite_eq_right ht,Set.indicator_of_notMem (show t ∉ Ici r from ht),sub_self] + exact le_rfl + _ = 1-(r : ℝ) := by + rw [integral_indicator measurableSet_Ici] + simp [Measure.real,ENNReal.toReal_ofReal,sub_nonneg.mpr r.property.2] + +lemma upperRoundedTrial_L1_le (m : Trial) (n : ℕ) : + (∫ t, |upperRoundedTrial m n t - m t| ∂timeLaw) ≤ 1/((n+1 : ℕ) : ℝ) := by + calc + _ ≤ ∫ _t : Time, (1 : ℝ)/((n+1 : ℕ) : ℝ) ∂timeLaw := by + apply integral_mono ((trial_integrable _).sub (trial_integrable _)).abs (integrable_const _) + intro t + dsimp only [Pi.sub_apply] + rw [abs_of_nonneg (sub_nonneg.mpr (le_upperRoundedTrial m n t))] + exact upperRoundedTrial_sub_le m n t + _ = _ := by simp + +lemma exists_finite_terminal_trial_approx (m : Trial) {ε : ℝ} (hε : 0 < ε) : + ∃ q : Trial, (Set.range q).Finite ∧ (∃ r : Time, (r : ℝ) < 1 ∧ ∀ t, r ≤ t → q t = 1) ∧ + (∀ t, m t ≤ q t) ∧ entropy q ≤ entropy m ∧ entropy q < ∞ ∧ + (∫ t, |q t-m t| ∂timeLaw) < ε := by + obtain ⟨n,hn⟩ := exists_nat_one_div_lt (half_pos hε) + let r : Time := ⟨1-min (ε/2) (1/2),by constructor <;> linarith [min_le_left (ε/2) (1/2),min_le_right (ε/2) (1/2),lt_min (half_pos hε) (by norm_num : (0:ℝ)<1/2)]⟩ + have hr : (r : ℝ) < 1 := by dsimp [r]; exact sub_lt_self _ (lt_min (half_pos hε) (by norm_num)) + let q := terminalTrial (upperRoundedTrial m n) r + have hmq (t : Time) : m t ≤ q t := (le_upperRoundedTrial m n t).trans (le_terminalTrial _ r t) + refine ⟨q,terminalTrial_finite_range _ r (upperRoundedTrial_finite_range m n), + ⟨r,hr,fun t ht => by simp [q,terminalTrial,ht]⟩,hmq,entropy_antitone hmq, + terminalTrial_entropy_finite _ hr,?_⟩ + calc + _ ≤ (∫ t, |q t-upperRoundedTrial m n t| + |upperRoundedTrial m n t-m t| ∂timeLaw) := + integral_mono ((trial_integrable _).sub (trial_integrable _)).abs + (((trial_integrable _).sub (trial_integrable _)).abs.add + ((trial_integrable _).sub (trial_integrable _)).abs) (fun t => abs_sub_le _ _ _) + _ = (∫ t, |q t-upperRoundedTrial m n t| ∂timeLaw) + + ∫ t, |upperRoundedTrial m n t-m t| ∂timeLaw := + integral_add ((trial_integrable _).sub (trial_integrable _)).abs ((trial_integrable _).sub (trial_integrable _)).abs + _ ≤ 1-(r : ℝ)+1/((n+1 : ℕ) : ℝ) := add_le_add (terminalTrial_L1_le _ r) (upperRoundedTrial_L1_le m n) + _ < ε := by + have hn' : 1/((n+1 : ℕ) : ℝ) < ε/2 := by simpa only [Nat.cast_add,Nat.cast_one] using hn + dsimp [r] + linarith [min_le_left (ε/2) (1/2)] + +def FiniteTerminal (m : Trial) : Prop := + (Set.range m).Finite ∧ ∃ r : Time, (r : ℝ) < 1 ∧ ∀ t, r ≤ t → m t = 1 + +def finiteTerminalVariational (P : Measure BrownianPath) (α : ℝ) (f : ℝ →ᵇ ℝ) : EReal := + ⨅ m : {m : Trial // FiniteTerminal m}, + ((α * controlValue P f m.val : ℝ) : EReal) + (entropy m.val).toEReal + +lemma finiteTerminal_one : FiniteTerminal oneTrial := by + constructor + · change (Set.range (fun _ : Time => (1 : ℝ))).Finite + simpa only [Set.range_const] using Set.finite_singleton (1 : ℝ) + · exact ⟨0,by norm_num,fun _ _ => rfl⟩ + +lemma finiteTerminalVariational_bounds (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f : ℝ →ᵇ ℝ) : + ((-α*‖f‖ : ℝ) : EReal) ≤ finiteTerminalVariational P α f ∧ + finiteTerminalVariational P α f ≤ ((α*‖f‖ : ℝ) : EReal) := by + constructor + · apply (terminalVariational_bounds P α hα f).1.trans + apply le_iInf + intro m + exact iInf_le _ m.val + · calc + _ ≤ ((α*controlValue P f oneTrial : ℝ) : EReal) + (entropy oneTrial).toEReal := + iInf_le (fun m : {m : Trial // FiniteTerminal m} => + ((α*controlValue P f m.val : ℝ) : EReal)+(entropy m.val).toEReal) ⟨oneTrial,finiteTerminal_one⟩ + _ ≤ ((α*‖f‖ : ℝ) : EReal) := by + simp only [entropy_oneTrial,EReal.coe_ennreal_zero,add_zero] + exact EReal.coe_le_coe_iff.mpr (mul_le_mul_of_nonneg_left (controlValue_le_norm P f _) hα) + +lemma finiteTerminalVariational_coe_toReal (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f : ℝ →ᵇ ℝ) : + ((finiteTerminalVariational P α f).toReal : EReal) = finiteTerminalVariational P α f := by + obtain ⟨hlo,hhi⟩ := finiteTerminalVariational_bounds P α hα f + exact EReal.coe_toReal (ne_top_of_le_ne_top (EReal.coe_ne_top _) hhi) + (ne_bot_of_le_ne_bot (EReal.coe_ne_bot _) hlo) + +lemma terminalVariational_eq_finiteTerminal (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f : ℝ →ᵇ ℝ) (L : ℝ≥0) (hf : LipschitzWith L f) : + terminalVariational P α f = finiteTerminalVariational P α f := by + apply le_antisymm + · apply le_iInf + intro m + exact iInf_le _ m.val + · apply le_iInf + intro m + by_cases hm : entropy m = ∞ + · simp only [hm,EReal.coe_ennreal_top,EReal.coe_add_top,le_top] + · rw [← EReal.coe_ennreal_toReal hm,← EReal.coe_add, + ← finiteTerminalVariational_coe_toReal P α hα f,EReal.coe_le_coe_iff] + apply le_of_forall_pos_le_add + intro ε hε + let C : ℝ := α*(3/2)*(L : ℝ)^2 + have hC : 0 ≤ C := by dsimp [C]; positivity + obtain ⟨q,hqfin,hqterm,_,hS,hSf,hL1⟩ := + exists_finite_terminal_trial_approx m (div_pos hε (by positivity : 0 < C+1)) + have hi : finiteTerminalVariational P α f ≤ + ((α*controlValue P f q : ℝ) : EReal) + (entropy q).toEReal := + iInf_le (fun m : {m : Trial // FiniteTerminal m} => + ((α*controlValue P f m.val : ℝ) : EReal)+(entropy m.val).toEReal) ⟨q,hqfin,hqterm⟩ + rw [← EReal.coe_ennreal_toReal hSf.ne,← EReal.coe_add, + ← finiteTerminalVariational_coe_toReal P α hα f,EReal.coe_le_coe_iff] at hi + have hc := (abs_le.mp (controlValue_trial_abs_sub_le P f q m L hf)).2 + have hS' := ENNReal.toReal_mono hm hS + have herror : C*(∫ t, |q t-m t| ∂timeLaw) ≤ ε := by + have h := mul_le_mul_of_nonneg_left hL1.le hC + have he : C*(ε/(C+1)) ≤ ε := by + rw [← mul_div_assoc] + apply (div_le_iff₀ (by positivity : 0 < C+1)).mpr + nlinarith + exact h.trans he + have hc' := mul_le_mul_of_nonneg_left hc hα + change (α*(3/2)*(L : ℝ)^2)*(∫ t, |q t-m t| ∂timeLaw) ≤ ε at herror + nlinarith + +open scoped ContDiff + +def Jet3.ofCompactSmooth (f : ℝ → ℝ) (hf : ContDiff ℝ ∞ f) (hs : HasCompactSupport f) : Jet3 := by + have h1 : ContDiff ℝ ∞ (deriv f) := (contDiff_infty_iff_deriv.mp hf).2 + have h2 : ContDiff ℝ ∞ (deriv (deriv f)) := (contDiff_infty_iff_deriv.mp h1).2 + have h3 : ContDiff ℝ ∞ (deriv (deriv (deriv f))) := (contDiff_infty_iff_deriv.mp h2).2 + exact { + f := ofCompactSupport f hf.continuous hs + d1 := ofCompactSupport (deriv f) h1.continuous hs.deriv + d2 := ofCompactSupport (deriv (deriv f)) h2.continuous hs.deriv.deriv + d3 := ofCompactSupport (deriv (deriv (deriv f))) h3.continuous hs.deriv.deriv.deriv + has1 := fun x => (hf.differentiable (by norm_num)).differentiableAt.hasDerivAt + has2 := fun x => (h1.differentiable (by norm_num)).differentiableAt.hasDerivAt + has3 := fun x => (h2.differentiable (by norm_num)).differentiableAt.hasDerivAt } + +@[simp] lemma Jet3.ofCompactSmooth_apply (f : ℝ → ℝ) (hf : ContDiff ℝ ∞ f) + (hs : HasCompactSupport f) (x : ℝ) : (Jet3.ofCompactSmooth f hf hs).f x = f x := rfl + +lemma exists_bounded_smooth_terminal (f : ℝ →ᵇ ℝ) {R ε : ℝ} (hR : 0 < R) + (hε : 0 < ε) : ∃ g : Jet3, ‖g.f‖ ≤ ‖f‖+ε ∧ + ∀ x : ℝ, |x| ≤ R → |g.f x-f x| < ε := by + let ψ : ContDiffBump (0 : ℝ) := ⟨R,R+1,hR,by linarith⟩ + let F : ℝ → ℝ := fun x => ψ x*f x + have hF : Continuous F := ψ.continuous.mul f.continuous + have hFs : HasCompactSupport F := ψ.hasCompactSupport.mul_right + obtain ⟨g,hg,hgf,hgs⟩ := hF.exists_contDiff_approx (⊤ : ℕ∞) + (ε := fun _ => ε) continuous_const (fun _ => hε) + have hg' : ContDiff ℝ ∞ g := hg + have hgs' : HasCompactSupport g := hFs.mono hgs + refine ⟨Jet3.ofCompactSmooth g hg' hgs',?_,?_⟩ + · rw [BoundedContinuousFunction.norm_le (by positivity : 0 ≤ ‖f‖+ε)] + intro x + change |g x| ≤ ‖f‖+ε + have hFbound : |F x| ≤ ‖f‖ := by + dsimp [F] + rw [abs_mul,abs_of_nonneg ψ.nonneg] + exact (mul_le_mul_of_nonneg_left (f.norm_coe_le_norm x) ψ.nonneg).trans + (mul_le_of_le_one_left (norm_nonneg f) ψ.le_one) + have h := hgf x + rw [Real.dist_eq] at h + calc + |g x| = |(g x-F x)+F x| := by congr 1; ring + _ ≤ |g x-F x|+|F x| := abs_add_le _ _ + _ ≤ ‖f‖+ε := by linarith + · intro x hx + have he : ψ x = 1 := ψ.one_of_mem_closedBall (by simpa [Real.dist_eq] using hx) + simpa only [Jet3.ofCompactSmooth_apply,F,he,one_mul,Real.dist_eq] using hgf x + +lemma exists_bounded_smooth_terminal_sequence (f : ℝ →ᵇ ℝ) : + ∃ g : ℕ → Jet3, (∀ n, ‖(g n).f‖ ≤ ‖f‖+1) ∧ + ∀ R : ℝ, 0 < R → ∀ ε : ℝ, 0 < ε → + ∃ N : ℕ, ∀ n ≥ N, ∀ x : ℝ, |x| ≤ R → |(g n).f x-f x| ≤ ε := by + have h (n : ℕ) := exists_bounded_smooth_terminal f + (by positivity : 0 < (n : ℝ)+1) (by positivity : 0 < 1/((n : ℝ)+1)) + choose g hg hcomp using h + refine ⟨g,?_,?_⟩ + · intro n + apply (hg n).trans + have h : 1/((n : ℝ)+1) ≤ 1 := (div_le_one (by positivity)).mpr (by linarith [Nat.cast_nonneg (α := ℝ) n]) + linarith + · intro R _ ε hε + obtain ⟨N₁,hR⟩ := exists_nat_ge R + obtain ⟨N₂,hε'⟩ := exists_nat_one_div_lt hε + refine ⟨max N₁ N₂,fun n hn x hx => ?_⟩ + have hn1 : N₁ ≤ n := (le_max_left _ _).trans hn + have hn2 : N₂ ≤ n := (le_max_right _ _).trans hn + have hx' : |x| ≤ (n : ℝ)+1 := by + have hc : (N₁ : ℝ) ≤ n := Nat.cast_le.mpr hn1 + linarith + apply (hcomp n x hx').le.trans + apply le_trans _ hε'.le + exact one_div_le_one_div_of_le (by positivity) (by exact_mod_cast Nat.add_le_add_right hn2 1) + +lemma finiteTerminalVariational_toReal_sub_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f g : ℝ →ᵇ ℝ) (δ : ℝ) + (hfg : ∀ m : Trial, controlValue P f m - controlValue P g m ≤ δ) : + (finiteTerminalVariational P α f).toReal - (finiteTerminalVariational P α g).toReal ≤ α*δ := by + have hbound : (((finiteTerminalVariational P α f).toReal - α*δ : ℝ) : EReal) ≤ + finiteTerminalVariational P α g := by + apply le_iInf + intro m + have h : finiteTerminalVariational P α f ≤ + ((α*controlValue P f m : ℝ) : EReal) + (entropy m).toEReal := iInf_le (fun m : {m : Trial // FiniteTerminal m} => + ((α*controlValue P f m.val : ℝ) : EReal)+(entropy m.val).toEReal) m + have hh : (((finiteTerminalVariational P α f).toReal - α*δ : ℝ) : EReal) ≤ + ((α*controlValue P f m - α*δ : ℝ) : EReal) + (entropy m).toEReal := by + have hs := add_le_add_right h ((-α*δ : ℝ) : EReal) + rw [← finiteTerminalVariational_coe_toReal P α hα f] at hs + convert hs using 1 <;> simp only [sub_eq_add_neg, EReal.coe_add, EReal.coe_neg] <;> + push_cast <;> simp only [neg_mul, add_assoc, add_comm] + apply hh.trans + apply add_le_add_left + apply EReal.coe_le_coe_iff.mpr + nlinarith [mul_le_mul_of_nonneg_left (hfg m) hα] + rw [← finiteTerminalVariational_coe_toReal P α hα g, EReal.coe_le_coe_iff] at hbound + linarith + +lemma finiteTerminalVariational_abs_sub_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f g : ℝ →ᵇ ℝ) (δ : ℝ) + (hfg : ∀ m : Trial, |controlValue P f m - controlValue P g m| ≤ δ) : + |(finiteTerminalVariational P α f).toReal - (finiteTerminalVariational P α g).toReal| ≤ α*δ := by + have h₁ := finiteTerminalVariational_toReal_sub_le P α hα f g δ + (fun m => (abs_le.mp (hfg m)).2) + have h₂ := finiteTerminalVariational_toReal_sub_le P α hα g f δ + (fun m => by have hh := (abs_le.mp (hfg m)).1; linarith) + exact abs_le.mpr ⟨by linarith, h₁⟩ + +lemma terminalVariational_eq_finiteTerminal_continuous + (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (α : ℝ) (hα : 0 ≤ α) (f : ℝ →ᵇ ℝ) : + terminalVariational P α f = finiteTerminalVariational P α f := by + rw [← terminalVariational_coe_toReal P α hα f, + ← finiteTerminalVariational_coe_toReal P α hα f] + congr 1 + apply le_antisymm + · apply EReal.coe_le_coe_iff.mp + rw [terminalVariational_coe_toReal P α hα f, + finiteTerminalVariational_coe_toReal P α hα f] + exact le_iInf fun m => iInf_le _ m.val + · apply le_of_forall_pos_le_add + intro ε hε + obtain ⟨g,hg,hcomp⟩ := exists_bounded_smooth_terminal_sequence f + let δ := ε/(2*(α+1)) + have hδ : 0 < δ := div_pos hε (by positivity) + obtain ⟨N,hN⟩ := controlValue_uniform_of_compact P hB f (fun n => (g n).f) + (‖f‖+1) (by positivity) (by linarith) hg hcomp δ hδ + have hclose : ∀ m : Trial, + |controlValue P (g N).f m - controlValue P f m| ≤ δ := fun m => (hN N le_rfl m).le + have h₁ := (abs_le.mp (finiteTerminalVariational_abs_sub_le P α hα (g N).f f δ hclose)).1 + have h₂ := (abs_le.mp (terminalVariational_abs_sub_le P α hα (g N).f f δ hclose)).2 + have hlipschitz : LipschitzWith ‖(g N).d1‖₊ (g N).f := by + apply lipschitzWith_of_nnnorm_deriv_le (fun point => ((g N).has1 point).differentiableAt) + intro point + rw [(g N).deriv_eq] + exact_mod_cast (g N).d1.norm_coe_le_norm point + have he := terminalVariational_eq_finiteTerminal P α hα (g N).f ‖(g N).d1‖₊ hlipschitz + have he' := congrArg EReal.toReal he + have herr : 2*α*δ ≤ ε := by + dsimp [δ] + rw [← mul_div_assoc] + apply (div_le_iff₀ (by positivity : 0 < 2*(α+1))).mpr + nlinarith + linarith + +abbrev RadialSpace (n : ℕ) := EuclideanSpace ℝ (Fin (n+1)) + +def radialNormalizer (n : ℕ) : ℝ := ((2*Real.pi)^(((n+1 : ℕ) : ℝ)/2))⁻¹ + +def canonicalRadialDensity (n : ℕ) (b : ℝ) (x : RadialSpace n) : ℝ := + radialNormalizer n * Real.exp (-(b/2)*‖x‖^2) + +def canonicalRadialMass (n : ℕ) (b : ℝ) : Measure (RadialSpace n) := + volume.withDensity (fun x => ENNReal.ofReal (canonicalRadialDensity n b x)) + +lemma radialNormalizer_pos (n : ℕ) : 0 < radialNormalizer n := by + unfold radialNormalizer + positivity + +lemma canonicalRadialDensity_pos (n : ℕ) (b : ℝ) (x : RadialSpace n) : + 0 < canonicalRadialDensity n b x := mul_pos (radialNormalizer_pos n) (Real.exp_pos _) + +lemma canonicalRadialDensity_continuous (n : ℕ) (b : ℝ) : + Continuous (canonicalRadialDensity n b) := by unfold canonicalRadialDensity; fun_prop + +lemma integrable_exp_neg_norm_sq (n : ℕ) {b : ℝ} (hb : 0 < b) : + Integrable (fun x : RadialSpace n => Real.exp (-(b/2)*‖x‖^2)) := by + have h := (GaussianFourier.integrable_cexp_neg_mul_sq_norm_add + (b := ((b/2 : ℝ) : ℂ)) (by simpa using half_pos hb) 0 (0 : RadialSpace n)).re + convert h using 1 + ext x + simp only [zero_mul,add_zero,← Complex.ofReal_pow,← Complex.ofReal_mul,← Complex.ofReal_neg, + ] + exact (Complex.exp_ofReal_re _).symm + +lemma canonicalRadialDensity_integrable (n : ℕ) {b : ℝ} (hb : 0 < b) : + Integrable (canonicalRadialDensity n b) := + (integrable_exp_neg_norm_sq n hb).const_mul _ + +lemma canonicalRadialDensity_integral (n : ℕ) {b : ℝ} (hb : 0 < b) : + (∫ x, canonicalRadialDensity n b x) = b ^ (-((n+1 : ℕ) : ℝ)/2) := by + simp only [canonicalRadialDensity] + rw [integral_const_mul, + GaussianFourier.integral_rexp_neg_mul_sq_norm (half_pos hb)] + simp only [finrank_euclideanSpace, Fintype.card_fin] + rw [show Real.pi/(b/2) = (2*Real.pi)/b by ring,Real.div_rpow (by positivity) hb.le] + unfold radialNormalizer + rw [show -((n+1 : ℕ) : ℝ)/2 = -(((n+1 : ℕ) : ℝ)/2) by ring, Real.rpow_neg hb.le] + field_simp + +instance (n : ℕ) : IsProbabilityMeasure (canonicalRadialMass n 1) := by + constructor + rw [canonicalRadialMass,withDensity_apply _ MeasurableSet.univ, + Measure.restrict_univ,← ofReal_integral_eq_lintegral_ofReal + (canonicalRadialDensity_integrable n (by norm_num : (0:ℝ)<1)) + (Eventually.of_forall fun x => (canonicalRadialDensity_pos n 1 x).le), + canonicalRadialDensity_integral n (by norm_num : (0:ℝ)<1)] + simp + +lemma canonicalRadialMass_apply {n : ℕ} {b : ℝ} (hb : 0 < b) + {A : Set (RadialSpace n)} (hA : MeasurableSet A) : + canonicalRadialMass n b A = ENNReal.ofReal (∫ x in A, canonicalRadialDensity n b x) := by + rw [canonicalRadialMass,withDensity_apply _ hA] + exact (ofReal_integral_eq_lintegral_ofReal (canonicalRadialDensity_integrable n hb).integrableOn + (Eventually.of_forall fun x => (canonicalRadialDensity_pos n b x).le)).symm + +lemma canonicalRadial_mass_le {n : ℕ} {a b c : ℝ} (ha : 0 < a) (hb : 0 < b) + {A : Set (RadialSpace n)} (hA : MeasurableSet A) + (hc : ∀ x ∈ A, -(a/2)*‖x‖^2 ≤ c-(b/2)*‖x‖^2) : + canonicalRadialMass n a A ≤ ENNReal.ofReal (Real.exp c * b ^ (-((n+1 : ℕ) : ℝ)/2)) := by + rw [canonicalRadialMass_apply ha hA] + apply ENNReal.ofReal_le_ofReal + calc + _ ≤ ∫ x in A, Real.exp c * canonicalRadialDensity n b x := by + apply setIntegral_mono_on (canonicalRadialDensity_integrable n ha).integrableOn + ((canonicalRadialDensity_integrable n hb).const_mul _).integrableOn hA + intro x hx + unfold canonicalRadialDensity + calc + _ ≤ radialNormalizer n * Real.exp (c-(b/2)*‖x‖^2) := + mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (hc x hx)) (radialNormalizer_pos n).le + _ = _ := by rw [Real.exp_sub,neg_mul,Real.exp_neg]; ring + _ ≤ ∫ x, Real.exp c * canonicalRadialDensity n b x := by + apply setIntegral_le_integral ((canonicalRadialDensity_integrable n hb).const_mul _) + exact Eventually.of_forall fun x => (mul_pos (Real.exp_pos c) (canonicalRadialDensity_pos n b x)).le + _ = _ := by rw [integral_const_mul,canonicalRadialDensity_integral n hb] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/GaussianHamiltonianCoordinates.lean b/lean/OAI/Probability/Perceptron/Pressure/GaussianHamiltonianCoordinates.lean new file mode 100644 index 0000000000000000000000000000000000000000..15008669977fa672b13ef2e056fc9973011ec57f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/GaussianHamiltonianCoordinates.lean @@ -0,0 +1,54 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianBoltzmann + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] + +omit [MeasurableSpace S] in +lemma countableGaussianField_update (v : ℕ → S → ℝ) (L : S → ℕ) + (g : ℕ → ℝ) (i : ℕ) (t : ℝ) (x : S) : + countableGaussianField v L (Function.update g i t) x = + countableGaussianField v L (Function.update g i 0) x+t*maskedGaussianCoefficient v L i x := by + unfold countableGaussianField gaussianPrefixField + rw [Fin.sum_univ_eq_sum_range (fun j => Function.update g i t j*v j x) (L x), + Fin.sum_univ_eq_sum_range (fun j => Function.update g i 0 j*v j x) (L x)] + have he (j : ℕ) : Function.update g i t j*v j x = + Function.update g i 0 j*v j x+if j=i then t*v i x else 0 := by + by_cases hj : j=i + · subst j + simp only [Function.update_self,ite_true,zero_mul,zero_add] + · simp only [Function.update_of_ne hj,ite_eq_right hj,add_zero] + simp_rw [he] + rw [Finset.sum_add_distrib] + simp only [Finset.sum_ite_eq',Finset.mem_range,maskedGaussianCoefficient] + split_ifs <;> simp + +omit [MeasurableSpace S] in +lemma countableGaussianHamiltonian_update (W : S → ℝ) (v : ℕ → S → ℝ) (L : S → ℕ) + (g : ℕ → ℝ) (i : ℕ) (t : ℝ) (x : S) : + countableGaussianHamiltonian W v L (Function.update g i t) x = + countableGaussianHamiltonian W v L (Function.update g i 0) x+t*maskedGaussianCoefficient v L i x := by + unfold countableGaussianHamiltonian + conv_lhs => rw [countableGaussianField_update] + ring + +omit [MeasurableSpace S] in +lemma maskedGaussianCoefficient_bound (v : ℕ → S → ℝ) (L : S → ℕ) + {D : ℝ} (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) (i : ℕ) (x : S) : + |maskedGaussianCoefficient v L i x| ≤ Real.sqrt D := by + unfold maskedGaussianCoefficient + split_ifs with hi + · apply Real.abs_le_sqrt + exact (Finset.single_le_sum (fun j (_ : j ∈ Finset.univ) => sq_nonneg (v j.val x)) + (Finset.mem_univ (⟨i,hi⟩ : Fin (L x)))).trans (hD x) + · simpa only [abs_zero] using Real.sqrt_nonneg D + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/GaussianPressureDerivative.lean b/lean/OAI/Probability/Perceptron/Pressure/GaussianPressureDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..42b9add9c2ddda5211aa095b07a7ec1568dffbc2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/GaussianPressureDerivative.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CountableGaussianFullIBP +import OAI.Probability.Perceptron.Variational.UnboundedContact + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma abs_log_le_self_add_inv {x : ℝ} (hx : 0 Real.log (tiltPartition μ (countableGaussianHamiltonian W v L g) 1)) countableGaussianLaw := by + have hi : Integrable (fun g => tiltPartition μ (countableGaussianHamiltonian W v L g) 1) countableGaussianLaw := by + simpa only [tiltPartition,one_mul] using + (countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).integral_prod_right + have hj : Integrable (fun g => (tiltPartition μ (countableGaussianHamiltonian W v L g) 1)⁻¹) countableGaussianLaw := by + simpa only [pow_one] using gaussianHamiltonianPartition_inverse_power_integrable μ hW hv hL hA hD 1 + refine (hi.add hj).mono' ((gaussianHamiltonianPartition_measurable μ hW hv hL).log.aestronglyMeasurable) ?_ + filter_upwards [gaussianHamiltonianPartition_pos_ae μ hW hv hL hA hD] with g hg + simpa only [Real.norm_eq_abs,Pi.add_apply] using abs_log_le_self_add_inv hg + +include hW hv hw hL hA hD hE + +lemma gaussianCouplingLog_integrable (a : ℝ) : + Integrable (fun g => Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) 1)) countableGaussianLaw := by + have hm (i : ℕ) : Measurable (fun x => v i x+a*w i x) := (hv i).add ((hw i).const_mul a) + have hb (x : S) : (∑ i : Fin (L x), (v i.val x+a*w i.val x)^2)≤2*D+2*a^2*E := by + simpa only [gaussianTailCoefficient,zero_le,ite_true,one_mul,mul_one,one_pow] using + gaussianCombinedCoefficient_sq_bound v w L hD hE 1 a 0 x + convert gaussianLogPartition_integrable μ hW hm hL hA hb using 1 + ext g + congr 3 + ext x + simp only [countableGaussianHamiltonian,countableGaussianField_add,countableGaussianField_smul] + ring + +lemma gaussianCouplingMean_derivative (a : ℝ) : + HasDerivAt (fun b => ∫ g, Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+b*countableGaussianField w L g x) 1) ∂countableGaussianLaw) + (∫ g, tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (countableGaussianField w L g) 1 ∂countableGaussianLaw) a := by + let H := countableGaussianHamiltonian W v L + let Y := countableGaussianField w L + have hH : Measurable (Function.uncurry H) := countableGaussianHamiltonian_measurable hW hv hL + have hY : Measurable (Function.uncurry Y) := countableGaussianField_measurable hw hL + have hi := gaussianCouplingLog_integrable μ hW hv hw hL hA hD hE + apply (annealed_convex_hasDerivAt countableGaussianLaw (fun b => (hi b).aestronglyMeasurable) _ hi _ a).2 + · intro b + exact (kernel_tiltMean_measurable (Kernel.const _ μ) (hH.add (hY.const_mul b)) hY).aestronglyMeasurable + · filter_upwards [countableGaussian_all_coupling_exp_ae μ hW hv hw hL hA hD hE] with g hg + have hHg : Measurable (H g) := hH.of_uncurry_left + have hYg : Measurable (Y g) := hY.of_uncurry_left + exact ⟨coupling_log_convex μ hHg hYg hg,fun b => coupling_log_hasDerivAt μ hHg hYg hg b⟩ + +lemma annealedGaussianTiltMean_ibp : + (∫ g, tiltMean μ (countableGaussianHamiltonian W v L g) + (countableGaussianField w L g) 1 ∂countableGaussianLaw) = + ∫ g, tiltMean μ (countableGaussianHamiltonian W v L g) + (fun x => countableGaussianCovariance v w L x x) 1 - + gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) 2 + (fun x => countableGaussianCovariance v w L (x 1) (x 0)) ∂countableGaussianLaw := by + have hH := countableGaussianHamiltonian_measurable hW hv hL + have hY := countableGaussianField_measurable hw hL + have hK := countableGaussianCovariance_measurable hv hw hL + have he : ∀ᵐ g ∂countableGaussianLaw, Integrable + (fun x => Real.exp (countableGaussianHamiltonian W v L g x)) μ := by + simpa only [one_mul] using + (countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).prod_left_ae + have hb := countableGaussian_replica_full_ibp μ 1 (0 : Fin 1) hW hv hw hL + (G := fun _ => 1) measurable_const hA hD hE (B := 1) (by norm_num) (by simp) + simp only [mul_one,one_mul,Fin.sum_univ_one,Nat.cast_one] at hb + calc + _ = ∫ g, gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) 1 + (fun x => countableGaussianField w L g (x 0)) ∂countableGaussianLaw := by + apply integral_congr_ae + filter_upwards [he] with g hg + exact (gibbsReplicaMean_coordinate_of_integrable μ hH.of_uncurry_left hY.of_uncurry_left hg 1 0).symm + _ = _ := hb.trans (integral_congr_ae (by + filter_upwards [he] with g hg + have hd := gibbsReplicaMean_coordinate_of_integrable μ hH.of_uncurry_left + (show Measurable (fun x => countableGaussianCovariance v w L x x) from + hK.comp (measurable_id.prodMk measurable_id)) hg 1 0 + exact congrArg (fun r => r - gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) 2 + (fun x => countableGaussianCovariance v w L (x 1) (x 0))) hd)) + +lemma gaussianCouplingMean_zero_derivative : + HasDerivAt (fun b => ∫ g, Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+b*countableGaussianField w L g x) 1) ∂countableGaussianLaw) + (∫ g, tiltMean μ (countableGaussianHamiltonian W v L g) + (fun x => countableGaussianCovariance v w L x x) 1 - + gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) 2 + (fun x => countableGaussianCovariance v w L (x 1) (x 0)) ∂countableGaussianLaw) 0 := by + have hh := gaussianCouplingMean_derivative μ hW hv hw hL hA hD hE 0 + simp only [zero_mul,add_zero] at hh + rw [annealedGaussianTiltMean_ibp μ hW hv hw hL hA hD hE] at hh + exact hh + +lemma gaussianCouplingMean_derivative_covariance (a : ℝ) : + HasDerivAt (fun b => ∫ g, Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+b*countableGaussianField w L g x) 1) ∂countableGaussianLaw) + (∫ g, tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (fun x => countableGaussianCovariance (fun i x => v i x+a*w i x) w L x x) 1 - + gibbsReplicaMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) 2 + (fun x => countableGaussianCovariance (fun i x => v i x+a*w i x) w L (x 1) (x 0)) ∂countableGaussianLaw) a := by + have hm (i : ℕ) : Measurable (fun x => v i x+a*w i x) := (hv i).add ((hw i).const_mul a) + have hb (x : S) : (∑ i : Fin (L x), (v i.val x+a*w i.val x)^2)≤2*D+2*a^2*E := by + simpa only [gaussianTailCoefficient,zero_le,ite_true,one_mul,mul_one,one_pow] using + gaussianCombinedCoefficient_sq_bound v w L hD hE 1 a 0 x + have he (g) : countableGaussianHamiltonian W (fun i x => v i x+a*w i x) L g = + fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x := by + funext x + simp only [countableGaussianHamiltonian,countableGaussianField_add,countableGaussianField_smul] + ring + have hi := annealedGaussianTiltMean_ibp μ hW hm hw hL hA hb hE + simp_rw [he] at hi + exact hi ▸ gaussianCouplingMean_derivative μ hW hv hw hL hA hD hE a + +lemma gaussianCouplingMean_difference_bound {B : ℝ} (hB : 0≤B) + (hC : ∀ a ∈ Icc (0:ℝ) 1, ∀ x y, + |countableGaussianCovariance (fun i x => v i x+a*w i x) w L x y|≤B) : + |(∫ g, Real.log (tiltPartition μ (fun x => countableGaussianHamiltonian W v L g x+ + countableGaussianField w L g x) 1) ∂countableGaussianLaw)- + ∫ g, Real.log (tiltPartition μ (countableGaussianHamiltonian W v L g) 1) ∂countableGaussianLaw|≤2*B := by + let F := fun a => ∫ g, Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) 1) ∂countableGaussianLaw + let C := fun a => countableGaussianCovariance (fun i x => v i x+a*w i x) w L + let D' := fun a => ∫ g, tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (fun x => C a x x) 1 - + gibbsReplicaMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) 2 + (fun x => C a (x 1) (x 0)) ∂countableGaussianLaw + have hd (a : ℝ) : HasDerivAt F (D' a) a := + gaussianCouplingMean_derivative_covariance μ hW hv hw hL hA hD hE a + have hb (a) (ha : a ∈ Icc (0:ℝ) 1) : ‖D' a‖≤2*B := by + have hm : Measurable (Function.uncurry (C a)) := countableGaussianCovariance_measurable + (fun i => (hv i).add ((hw i).const_mul a)) hw hL + have hH (g) : Measurable (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) := + (countableGaussianHamiltonian_measurable hW hv hL).of_uncurry_left.add + ((countableGaussianField_measurable hw hL).of_uncurry_left.const_mul a) + have hdiag (g) : |tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (fun x => C a x x) 1|≤B := tiltMean_bound_general μ (hH g) + (hm.comp (measurable_id.prodMk measurable_id)) hB (fun x => hC a ha x x) + have hpair (g) : |gibbsReplicaMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) 2 + (fun x => C a (x 1) (x 0))|≤B := tiltMean_bound_general _ + (replicaPotential_measurable (hH g) 2) + (hm.comp ((measurable_pi_apply 1).prodMk (measurable_pi_apply 0))) hB (fun x => hC a ha _ _) + simpa only [D',probReal_univ,mul_one] using norm_integral_le_of_norm_le_const + (μ := countableGaussianLaw) (C := 2*B) (ae_of_all _ fun g => by + rw [Real.norm_eq_abs] + exact (abs_sub _ _).trans (by linarith [hdiag g,hpair g])) + have hm := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun a (_ : a ∈ Icc (0:ℝ) 1) => (hd a).hasDerivWithinAt) hb (convex_Icc (0:ℝ) 1) + (show (0:ℝ) ∈ Icc (0:ℝ) 1 by constructor <;> norm_num) + (show (1:ℝ) ∈ Icc (0:ℝ) 1 by constructor <;> norm_num) + simpa only [F,one_mul,zero_mul,add_zero,sub_zero,norm_one,mul_one,Real.norm_eq_abs] using hm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/HeightPartition.lean b/lean/OAI/Probability/Perceptron/Pressure/HeightPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..df5e273193db1030cb9d90c2599d0fc27eb7514f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/HeightPartition.lean @@ -0,0 +1,98 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GridGap + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +def heightIndex {d : ℕ} (h : Fin (d+1) → ℝ) (t : ℝ) : Fin (d+2) := + ⟨(Finset.univ.filter (fun r => h r < t)).card,by + have H := Finset.card_le_card (Finset.filter_subset (fun r => h r < t) Finset.univ) + simp only [Finset.card_univ,Fintype.card_fin] at H + omega⟩ + +lemma heightIndex_monotone {d : ℕ} (h : Fin (d+1) → ℝ) : Monotone (heightIndex h) := by + intro s t hst + change (Finset.univ.filter (fun r => h r < s)).card ≤ (Finset.univ.filter (fun r => h r < t)).card + apply Finset.card_le_card + intro r hr + simp only [Finset.mem_filter,Finset.mem_univ,true_and] at hr ⊢ + exact hr.trans_le hst + +lemma heightIndex_le_iff {d : ℕ} (h : Fin (d+1) → ℝ) (hh : Monotone h) + (t : ℝ) (i : Fin (d+1)) : heightIndex h t ≤ i.castSucc ↔ t ≤ h i := by + constructor + · intro hi + by_contra ht + have hsub : Finset.Iic i ⊆ Finset.univ.filter (fun r => h r < t) := by + intro r hr + simp only [Finset.mem_filter,Finset.mem_univ,true_and] + exact (hh (Finset.mem_Iic.mp hr)).trans_lt (lt_of_not_ge ht) + have H := Finset.card_le_card hsub + rw [Fin.card_Iic] at H + change (Finset.univ.filter (fun r => h r < t)).card ≤ i.val at hi + omega + · intro hi + have hsub : Finset.univ.filter (fun r => h r < t) ⊆ Finset.Iio i := by + intro r hr + simp only [Finset.mem_filter,Finset.mem_univ,true_and] at hr + apply Finset.mem_Iio.mpr + by_contra hir + exact (not_lt_of_ge (hi.trans (hh (le_of_not_gt hir)))) hr + have H := Finset.card_le_card hsub + rw [Fin.card_Iio] at H + exact H + +lemma lt_heightIndex_iff {d : ℕ} (h : Fin (d+1) → ℝ) (hh : Monotone h) + (t : ℝ) (i : Fin (d+1)) : i.castSucc < heightIndex h t ↔ h i < t := by + simpa only [not_le] using not_congr (heightIndex_le_iff h hh t i) + +def heightVariances {K : ℕ} (z : Fin (K+1) → ℝ) (j : Fin K) : ℝ := + 2*(z j.succ-z j.castSucc) + +lemma heightVariances_nonneg {K : ℕ} (z : Fin (K+1) → ℝ) (hz : Monotone z) + (j : Fin K) : 0 ≤ heightVariances z j := by + exact mul_nonneg (by norm_num) (sub_nonneg.mpr (hz (Fin.castSucc_le_succ j))) + +lemma heightVariances_sum {K : ℕ} (z : Fin (K+1) → ℝ) : + (∑ j, heightVariances z j)=2*(z (Fin.last K)-z 0) := by + simp only [heightVariances,← Finset.mul_sum,finite_sum_successive_differences] + +lemma heightVariances_prefix {K : ℕ} (z : Fin (K+1) → ℝ) (hz : Monotone z) + (r : ℝ) (hr : r ∈ Set.range z) : + (∑ j, if z j.succ ≤ r then heightVariances z j else 0)=2*(r-z 0) := by + obtain ⟨a,rfl⟩ := hr + have he (j : Fin K) : (if z j.succ ≤ z a then heightVariances z j else 0)= + 2*(min (z a) (z j.succ)-min (z a) (z j.castSucc)) := by + by_cases hja : j.val < a.val + · have hs : j.succ ≤ a := by simp only [Fin.le_def,Fin.val_succ]; omega + have hc : j.castSucc ≤ a := (Fin.castSucc_le_succ j).trans hs + simp [ite_eq_left (hz hs),min_eq_right (hz hs),min_eq_right (hz hc),heightVariances] + · have hc : a ≤ j.castSucc := by simp only [Fin.le_def,Fin.val_castSucc]; omega + have hs : a ≤ j.succ := hc.trans (Fin.castSucc_le_succ j) + rw [min_eq_left (hz hc),min_eq_left (hz hs),sub_self,mul_zero] + split_ifs with ht + · have heq : z j.succ=z j.castSucc := le_antisymm (ht.trans (hz hc)) (hz (Fin.castSucc_le_succ j)) + simp [heightVariances,heq] + · rfl + simp only [he,← Finset.mul_sum] + rw [finite_sum_successive_differences K (fun i => min (z a) (z i))] + rw [min_eq_left (hz (Fin.le_last a)),min_eq_right (hz (Fin.zero_le a))] + +lemma heightIndex_grid_prefix {d K : ℕ} (h : Fin (d+1) → ℝ) (hh : Monotone h) + (z : Fin (K+1) → ℝ) (hz : Monotone z) (hz0 : z 0=0) + (hm : ∀ i, h i ∈ Set.range z) (i : Fin (d+1)) : + varianceLevels (fun j => gridVariance + (List.ofFn fun r => (heightIndex h (z r.succ),heightVariances z r)) j.castSucc) i=h i := by + rw [varianceLevels_gridVariance] + simp only [List.map_ofFn,List.sum_ofFn,Function.comp_apply,heightIndex_le_iff h hh] + rw [heightVariances_prefix z hz (h i) (hm i),hz0,sub_zero] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/IndexedGibbsPartition.lean b/lean/OAI/Probability/Perceptron/Pressure/IndexedGibbsPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..1554fd4233cc363b282915ded4b885bdf9a20469 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/IndexedGibbsPartition.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedDiagonalField +import OAI.Probability.Perceptron.Variational.IndexedLeafTotal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators ENNReal +namespace SphericalPerceptronFreeEnergy + +lemma indexedLeafProbability_terminal_integral {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) {step : X×S → X} (hs : Measurable step) {H : X → ℝ} + (hH : Measurable H) (n : ℕ) (b : IndexedCascadeBase n) (hb : IndexedCascadeGood n b) + (hb' : 0 < ((indexedLeafMeasure n b) univ).toReal) + (m : IndexedCascadeMarks S n) (x : X) : + (∫ l, Real.exp (H (indexedLeafState step n (x,m) l)) ∂indexedLeafProbability n b) = + decoratedTerminalTotal step H n (x,indexedCascadeRealize n (b,m)) / + decoratedTerminalTotal step (fun _ => 0) n (x,indexedCascadeRealize n (b,m)) := by + rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun _ => (Real.exp_pos _).le) + (measurable_of_countable _).aestronglyMeasurable, + indexedLeafProbability_terminal_identity ν hs hH n b hb hb',ENNReal.toReal_mul,ENNReal.toReal_inv] + have he := indexedLeafMeasure_terminal_identity ν hs (H := fun _ => 0) measurable_const n b hb m x + simp only [Real.exp_zero,ENNReal.ofReal_one,lintegral_one] at he + unfold decoratedTerminalTotal + rw [he,div_eq_mul_inv,mul_comm] + +variable {S I : Type} [MeasurableSpace S] [Fintype I] +variable (ρ : Measure S) [IsProbabilityMeasure ρ] +variable {W : S → ℝ} {V : S → EuclideanSpace ℝ I} +variable (hWm : Measurable W) (hVm : Measurable V) {K C : ℝ} +variable (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) + +include hWm hVm hW hV + +lemma vectorPartition_exp_terminal (c : ℝ) (a : EuclideanSpace ℝ I) : + (∫ s, Real.exp (W s+inner ℝ (V s) a-c) ∂ρ) = + Real.exp (vectorLogPartition ρ W (fun s => innerSL ℝ (V s)) a-c) := by + have hm : Measurable (fun s => innerSL ℝ (V s)) := (innerSL ℝ).continuous.measurable.comp hVm + have hb : ∀ s, ‖innerSL ℝ (V s)‖ ≤ C := by simpa only [innerSL_apply_norm] using hV + simp only [Real.exp_sub,integral_div,vectorLogPartition] + rw [Real.exp_log (vectorPartition_pos ρ hWm hm hW hb a)] + rfl + +lemma indexedGaussian_spin_partition (n : ℕ) (root : I → ℝ) (step : ℕ → I → ℝ) + (b : IndexedCascadeBase n) (c : ℝ) (g : ℕ → ℝ) : + tiltPartition (ρ.prod (indexedLeafProbability n b)) (fun x => W x.1+ + countableGaussianField (indexedGaussianRow n (hierarchyRowCoefficients n root step) V) + (indexedGaussianRowLength (I := I) n) g x-c) 1 = + ∫ l, Real.exp (vectorLogPartition ρ W (fun s => innerSL ℝ (V s)) + (indexedLeafState (gaussianLinearMarkStep (fun j => diagonalMark (step j))) n + ((fun _ => diagonalMark root (indexedGaussianDisorder n I g).1), + (indexedGaussianDisorder n I g).2) l 0)-c) ∂indexedLeafProbability n b := by + let F : S×IndexedLeaf n → ℝ := fun x => W x.1+ + countableGaussianField (indexedGaussianRow n (hierarchyRowCoefficients n root step) V) + (indexedGaussianRowLength (I := I) n) g x-c + have hm : Measurable F := ((hWm.comp measurable_fst).add + ((countableGaussianField_measurable (indexedGaussianRow_measurable n _ hVm) + (indexedGaussianRowLength_measurable n)).comp (measurable_const.prodMk measurable_id))).sub measurable_const + change (∫ x, Real.exp (1*F x) ∂ρ.prod (indexedLeafProbability n b)) = _ + simp only [one_mul] + rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun _ => (Real.exp_pos _).le) hm.exp.aestronglyMeasurable, + lintegral_prod_symm _ hm.exp.ennreal_ofReal.aemeasurable] + rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ fun _ => (Real.exp_pos _).le) + (measurable_of_countable _).aestronglyMeasurable] + congr 1 + apply lintegral_congr + intro l + let a := indexedLeafState (gaussianLinearMarkStep (fun j => diagonalMark (step j))) n + ((fun _ => diagonalMark root (indexedGaussianDisorder n I g).1), + (indexedGaussianDisorder n I g).2) l 0 + have he (s : S) : F (s,l) = W s+inner ℝ (V s) a-c := by + dsimp only [F] + rw [indexedGaussianRow_diagonal_identity] + simp_rw [he] + rw [← vectorPartition_exp_terminal ρ hWm hVm hW hV c a] + apply (ofReal_integral_eq_lintegral_ofReal _ (ae_of_all _ fun _ => (Real.exp_pos _).le)).symm + have hv' : ∀ s, ‖innerSL ℝ (V s)‖ ≤ C := by simpa only [innerSL_apply_norm] using hV + have hi := vectorPartition_integrable ρ hWm ((innerSL ℝ).continuous.measurable.comp hVm) hW hv' a + simpa only [Real.exp_sub,Function.comp_apply,innerSL_apply_apply] using hi.div_const (Real.exp c) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalGibbs.lean b/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalGibbs.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f2b8f63d359e188f65098482546d0c157620a03 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalGibbs.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedLeafTotal +import OAI.Probability.Perceptron.Variational.IntegrableGibbs +import OAI.Probability.Perceptron.Variational.IndexedPathCorrelation + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma tiltLaw_eq_normalized_exp {A : Type*} [MeasurableSpace A] + (μ : Measure A) [IsProbabilityMeasure μ] (H : A→ℝ) + (hi : Integrable (fun x => Real.exp (H x)) μ) : + tiltLaw μ H 1 = normalizedMeasure (μ.withDensity (fun x => ENNReal.ofReal (Real.exp (H x)))) := by + unfold tiltLaw normalizedMeasure tiltPartition + simp only [one_mul] + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ←ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ fun x => (Real.exp_pos _).le)] + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + +lemma indexed_terminal_tiltLaw (ν : ProbabilityMeasure S) (step : X×S→X) + (n : ℕ) (z : Fin n→ℝ) (H : X→ℝ) (x : X) (b : IndexedCascadeBase n) + (m : IndexedCascadeMarks S n) (hb : 0<((indexedLeafMeasure n b) univ).toReal) + (hi : Integrable (fun l => Real.exp (H (indexedLeafState step n (x,m) l))) + (indexedLeafProbability n b)) : + tiltLaw (indexedLeafProbability n b) (fun l => H (indexedLeafState step n (x,m) l)) 1 = + normalizedMeasure (indexedTiltedLeafMeasure step n (finiteCascadeShifts ν step n z H) x b m) := by + rw [indexedTiltedLeafMeasure_normalized_terminal,tiltLaw_eq_normalized_exp _ _ hi, + indexedLeafProbability,ite_eq_left hb,withDensity_smul_measure] + apply normalizedMeasure_smul + · exact ENNReal.inv_ne_zero.mpr (ENNReal.toReal_pos_iff.mp hb).2.ne + · exact ENNReal.inv_ne_top.mpr (ENNReal.toReal_pos_iff.mp hb).1.ne' + +lemma indexed_terminal_lintegral (ν : ProbabilityMeasure S) (step : X×S→X) + (n : ℕ) (z : Fin n→ℝ) (H : X→ℝ) (x : X) (b : IndexedCascadeBase n) + (m : IndexedCascadeMarks S n) (hb : 0<((indexedLeafMeasure n b) univ).toReal) + (hi : Integrable (fun l => Real.exp (H (indexedLeafState step n (x,m) l))) + (indexedLeafProbability n b)) (f : IndexedLeaf n→ℝ≥0∞) : + (∫⁻ l, f l ∂tiltLaw (indexedLeafProbability n b) + (fun l => H (indexedLeafState step n (x,m) l)) 1) = + ∑' l, indexedTiltedProbability step n (finiteCascadeShifts ν step n z H) (x,(b,m)) l*f l := by + rw [indexed_terminal_tiltLaw ν step n z H x b m hb hi] + exact indexedTiltedProbability_lintegral step n (finiteCascadeShifts ν step n z H) (x,(b,m)) f + +variable [Nonempty S] + +omit [Nonempty S] in +lemma indexed_terminal_oneState (ν : ProbabilityMeasure S) (step : X×S→X) (hs : Measurable step) + (n : ℕ) (z : Fin n→ℝ) (H : X→ℝ) (hH : Measurable H) (x : X) (b : IndexedCascadeBase n) + (m : IndexedCascadeMarks S n) (hb : 0<((indexedLeafMeasure n b) univ).toReal) + (hi : Integrable (fun l => Real.exp (H (indexedLeafState step n (x,m) l))) + (indexedLeafProbability n b)) : + (tiltLaw (indexedLeafProbability n b) (fun l => H (indexedLeafState step n (x,m) l)) 1).map + (indexedLeafState step n (x,m)) = + indexedOneStateKernel step hs n (finiteCascadeShifts ν step n z H) + (finiteCascadeShifts_measurable ν step hs n z hH) x (b,m) := by + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (measurable_of_countable _),indexed_terminal_lintegral ν step n z H x b m hb hi, + indexedOneStateKernel,atomicVisitKernel_lintegral _ _ _ _ _ hf] + +lemma indexed_terminal_exp_integrable_ae (ν : ProbabilityMeasure S) (step : X×S→X) + (hs : Measurable step) (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 Real.exp (H (indexedLeafState step n (x,p.2) l))) + (indexedLeafProbability n p.1) := by + have hnorm := finiteCascadeShifts_normalized_of_fractional ν step n z (fun i => (hz0 i).ne') H hI + have ht := indexedTiltedTotal_regular ν step hs n z hz hz0 hz1 + (finiteCascadeShifts ν step n z H) (finiteCascadeShifts_measurable ν step hs n z hH) + (fun i x => (hnorm i x).1) (fun i x => (hnorm i x).2) x + have hb := (measurePreserving_fst (μ := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n))) + (ν := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))).quasiMeasurePreserving.ae (indexedLeafMeasure_regular n z hz hz0 hz1) + have hg := (measurePreserving_fst (μ := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n))) + (ν := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))).quasiMeasurePreserving.ae (indexedCascadeGood_ae n z hz0 hz1) + filter_upwards [ht,hb,hg] with p ht hb hg + refine ⟨(measurable_of_countable _).aestronglyMeasurable,?_⟩ + simp only [HasFiniteIntegral,Real.enorm_eq_ofReal (Real.exp_pos _).le] + rw [indexedLeafProbability_terminal_identity ν hs hH n p.1 hg hb p.2 x, + decoratedTerminalTotalE_telescoping ν step H n z, + ←indexedTiltedTotal_eq hs n (finiteCascadeShifts ν step n z H) + (finiteCascadeShifts_measurable ν step hs n z hH) (x,p) hg] + exact ENNReal.mul_lt_top (ENNReal.inv_lt_top.mpr (ENNReal.toReal_pos_iff.mp hb).1) + (ENNReal.mul_lt_top ENNReal.ofReal_lt_top (ENNReal.toReal_pos_iff.mp ht).2) + +omit [Nonempty S] in +lemma indexed_terminal_pairState (ν : ProbabilityMeasure S) (step : X×S→X) (hs : Measurable step) + (n : ℕ) (z : Fin n→ℝ) (H : X→ℝ) (hH : Measurable H) (x : X) (b : IndexedCascadeBase n) + (m : IndexedCascadeMarks S n) (hb : 0<((indexedLeafMeasure n b) univ).toReal) + (hi : Integrable (fun l => Real.exp (H (indexedLeafState step n (x,m) l))) + (indexedLeafProbability n b)) (d : Fin (n+1)) : + let μ := tiltLaw (indexedLeafProbability n b) (fun l => H (indexedLeafState step n (x,m) l)) 1 + ((μ.prod μ).restrict {l : IndexedLeaf n×IndexedLeaf n | indexedCommonDepth n l.1 l.2=d}).map + (fun l => (indexedLeafState step n (x,m) l.1,indexedLeafState step n (x,m) l.2)) = + indexedPairStateKernel step hs n (finiteCascadeShifts ν step n z H) + (finiteCascadeShifts_measurable ν step hs n z hH) x d (b,m) := by + dsimp only + let μ := tiltLaw (indexedLeafProbability n b) (fun l => H (indexedLeafState step n (x,m) l)) 1 + have : IsProbabilityMeasure μ := tilt_law_probability_of_integrable _ + (by simpa only [one_mul] using hi) + change ((μ.prod μ).restrict _).map _ = _ + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (measurable_of_countable _), + ←lintegral_indicator ((Set.to_countable _).measurableSet), + lintegral_prod _ (measurable_of_countable _).aemeasurable] + simp only [Set.indicator,Set.mem_ofPred_eq] + change (∫⁻ a, (∫⁻ c, (if indexedCommonDepth n a c=d then + f (indexedLeafState step n (x,m) a,indexedLeafState step n (x,m) c) else 0) ∂μ) ∂μ) = _ + dsimp only [μ] + simp_rw [indexed_terminal_lintegral ν step n z H x b m hb hi] + rw [indexedPairStateKernel,atomicVisitKernel_lintegral _ _ _ _ _ hf,ENNReal.tsum_prod'] + apply tsum_congr + intro a + rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro c + simp only [indexedPairStateWeight] + split_ifs <;> simp [mul_assoc] + +lemma indexed_terminal_pair_integral (ν : ProbabilityMeasure S) (step : X×S→X) + (hs : Measurable step) (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 H (indexedLeafState step n (x,p.2) a)) 1).prod + (tiltLaw (indexedLeafProbability n p.1) + (fun a => H (indexedLeafState step n (x,p.2) a)) 1)).restrict + {l | indexedCommonDepth n l.1 l.2=d}) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) = + (twoVisitMass n z d).toReal * pathCorrelation n + (fun i => tiltedStateStep ν step (z i) (finiteCascadeShifts ν step n z H i)) f d x := by + have hnorm := finiteCascadeShifts_normalized_of_fractional ν step n z (fun i => (hz0 i).ne') H hI + rw [←indexedPairState_integral ν step hs n z hz hz0 hz1 + (finiteCascadeShifts ν step n z H) (finiteCascadeShifts_measurable ν step hs n z hH) + (fun i x => (hnorm i x).1) (fun i x => (hnorm i x).2) x d f hf C hC hfB] + apply integral_congr_ae + have hb := (measurePreserving_fst (μ := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n))) + (ν := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))).quasiMeasurePreserving.ae + (indexedLeafMeasure_regular n z hz hz0 hz1) + filter_upwards [hb,indexed_terminal_exp_integrable_ae ν step hs n z hz hz0 hz1 H hH hI x] + with p hb hi + rw [←indexed_terminal_pairState ν step hs n z H hH x p.1 p.2 hb hi d] + exact (integral_map (measurable_of_countable + (fun l : IndexedLeaf n×IndexedLeaf n => + (indexedLeafState step n (x,p.2) l.1,indexedLeafState step n (x,p.2) l.2))).aemeasurable + ((hf.comp measurable_fst).mul (hf.comp measurable_snd)).aestronglyMeasurable).symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalProduct.lean b/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..a7427933d60f36ef2329c2dca9ce0e3ad3ca3a47 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalProduct.lean @@ -0,0 +1,257 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ContactGGRate +import OAI.Probability.Perceptron.Variational.IndexedMarkProduct +import OAI.Probability.Perceptron.Variational.TiltedPathProduct +import OAI.Probability.Perceptron.Pressure.IndexedTerminalGibbs + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {X Y S T : Type} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace S] [MeasurableSpace T] + +lemma cascadeTiltedStep_parallel (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : ∀ i, 0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) (z i) + (finiteCascadeShifts (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) n z + (fun x => H x.1+G x.2) i) = + tiltedStateStep ν step₁ (z i) (finiteCascadeShifts ν step₁ n z H i) ∥ₖ + tiltedStateStep ρ step₂ (z i) (finiteCascadeShifts ρ step₂ n z G i) := by + have he := fun p => finiteCascadeShifts_add_product ν ρ step₁ step₂ n z hz hHI hGI i p + rw [funext he] + exact tiltedStateStep_parallel ν ρ step₁ step₂ hs₁ hs₂ (z i) _ _ + (finiteCascadeShifts_measurable ν step₁ hs₁ n z hH i) + (finiteCascadeShifts_measurable ρ step₂ hs₂ n z hG i) + (fun x => (finiteCascadeShifts_normalized_of_fractional ν step₁ n z (fun i => (hz i).ne') H hHI i x).1) + (fun x => (finiteCascadeShifts_normalized_of_fractional ρ step₂ n z (fun i => (hz i).ne') G hGI i x).1) + (fun x => (finiteCascadeShifts_normalized_of_fractional ν step₁ n z (fun i => (hz i).ne') H hHI i x).2) + (fun x => (finiteCascadeShifts_normalized_of_fractional ρ step₂ n z (fun i => (hz i).ne') G hGI i x).2) + +lemma cascadeTiltedStep_markov (ν : ProbabilityMeasure S) (step : X×S→X) + (hs : Measurable step) (n : ℕ) (z : Fin n→ℝ) (hz : ∀ i, 0 (finiteCascadeShifts_normalized_of_fractional ν step n z (fun i => (hz i).ne') H hI i x).1) + (fun x => (finiteCascadeShifts_normalized_of_fractional ν step n z (fun i => (hz i).ne') H hI i x).2) + +lemma pathCorrelation_one (n : ℕ) (κ : Fin n→Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (d : Fin (n+1)) (x : X) : pathCorrelation n κ (fun _ => 1) d x=1 := by + have := pathPairKernel_markov n κ hκ d + simp [pathCorrelation] + +lemma indexed_terminal_product_pair_integral [Nonempty S] [Nonempty T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + let term := fun x : X×Y => H x.1+G x.2 + (∫ p, (∫ l : IndexedLeaf n×IndexedLeaf n, + (f (indexedLeafState st n ((x,y),p.2) l.1).1*g (indexedLeafState st n ((x,y),p.2) l.1).2)* + (f (indexedLeafState st n ((x,y),p.2) l.2).1*g (indexedLeafState st n ((x,y),p.2) l.2).2) + ∂((tiltLaw (indexedLeafProbability n p.1) + (fun a => term (indexedLeafState st n ((x,y),p.2) a)) 1).prod + (tiltLaw (indexedLeafProbability n p.1) + (fun a => term (indexedLeafState st n ((x,y),p.2) a)) 1)).restrict + {l | indexedCommonDepth n l.1 l.2=d}) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw (productMarkLaw ν ρ) n : Measure (IndexedCascadeMarks (S×T) n))) = + (twoVisitMass n z d).toReal * + (pathCorrelation n (fun i => tiltedStateStep ν step₁ (z i) (finiteCascadeShifts ν step₁ n z H i)) f d x * + pathCorrelation n (fun i => tiltedStateStep ρ step₂ (z i) (finiteCascadeShifts ρ step₂ n z G i)) g d y) := by + dsimp only + have hfg : Measurable (fun p : X×Y => f p.1*g p.2) := + (hf.comp measurable_fst).mul (hg.comp measurable_snd) + have hB : ∀ p : X×Y, |f p.1*g p.2|≤C*D := fun p => by + rw [abs_mul]; exact mul_le_mul (hfB p.1) (hgB p.2) (abs_nonneg _) hC + have he := indexed_terminal_pair_integral (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) (by fun_prop) + n z hz hz0 hz1 (fun p : X×Y => H p.1+G p.2) + (show Measurable (fun p : X×Y => H p.1+G p.2) from + (hH.comp measurable_fst).add (hG.comp measurable_snd)) + (finiteCascadeFractionalIntegrable_add_product ν ρ step₁ step₂ n z hz0 hHI hGI) + (x,y) d (fun p : X×Y => f p.1*g p.2) hfg (C*D) (mul_nonneg hC hD) hB + refine he.trans ?_ + simp_rw [cascadeTiltedStep_parallel ν ρ step₁ step₂ hs₁ hs₂ n z hz0 H G hH hG hHI hGI] + rw [pathCorrelation_parallel n _ _ + (cascadeTiltedStep_markov ν step₁ hs₁ n z hz0 H hH hHI) + (cascadeTiltedStep_markov ρ step₂ hs₂ n z hz0 G hG hGI) f g hf hg C D hC hD hfB hgB] + +def indexedTerminalBaseKernel (n : ℕ) : + Kernel (IndexedCascadeBase n×IndexedCascadeMarks S n) (IndexedLeaf n) := + (indexedLeafKernel n).comap Prod.fst measurable_fst +instance (n : ℕ) : IsMarkovKernel (indexedTerminalBaseKernel (S:=S) n) := by + unfold indexedTerminalBaseKernel + infer_instance + +def indexedTerminalEnergy (step : X×S→X) (n : ℕ) (H : X→ℝ) (x : X) + (p : IndexedCascadeBase n×IndexedCascadeMarks S n) (l : IndexedLeaf n) : ℝ := + H (indexedLeafState step n (x,p.2) l) + +lemma indexedTerminalEnergy_measurable (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (x : X) : + Measurable (Function.uncurry (indexedTerminalEnergy step n H x)) := + hH.comp ((indexedLeafState_measurable hs n).comp + ((measurable_const.prodMk measurable_fst.snd).prodMk measurable_snd)) + +def indexedTerminalPairMean (step : X×S→X) (n : ℕ) (H : X→ℝ) (x : X) + (d : Fin (n+1)) (f : X→ℝ) (p : IndexedCascadeBase n×IndexedCascadeMarks S n) : ℝ := + let κ := gibbsProbabilityKernel (indexedTerminalBaseKernel n) (indexedTerminalEnergy step n H x) + ∫ l : IndexedLeaf n×IndexedLeaf n, + (if indexedCommonDepth n l.1 l.2=d then + f (indexedLeafState step n (x,p.2) l.1)*f (indexedLeafState step n (x,p.2) l.2) else 0) + ∂(κ p).prod (κ p) + +lemma indexedTerminalPairMean_measurable (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (x : X) (d : Fin (n+1)) + (f : X→ℝ) (hf : Measurable f) : + Measurable (indexedTerminalPairMean step n H x d f) := by + let κ := gibbsProbabilityKernel (indexedTerminalBaseKernel n) (indexedTerminalEnergy step n H x) + have hm (j : IndexedLeaf n×IndexedLeaf n→IndexedLeaf n) (hj : Measurable j) : + Measurable (fun p : (IndexedCascadeBase n×IndexedCascadeMarks S n)×(IndexedLeaf n×IndexedLeaf n) => + f (indexedLeafState step n (x,p.1.2) (j p.2))) := + hf.comp ((indexedLeafState_measurable hs n).comp + ((measurable_const.prodMk measurable_fst.snd).prodMk (hj.comp measurable_snd))) + have hcond : MeasurableSet {p : (IndexedCascadeBase n×IndexedCascadeMarks S n)×(IndexedLeaf n×IndexedLeaf n) | + indexedCommonDepth n p.2.1 p.2.2=d} := + ((Set.to_countable {l : IndexedLeaf n×IndexedLeaf n | indexedCommonDepth n l.1 l.2=d}).measurableSet).preimage measurable_snd + have : IsMarkovKernel κ := gibbsProbabilityKernel_markov _ _ + (indexedTerminalEnergy_measurable step hs n H hH x) + let F : (IndexedCascadeBase n×IndexedCascadeMarks S n)×(IndexedLeaf n×IndexedLeaf n)→ℝ := + fun p => if indexedCommonDepth n p.2.1 p.2.2=d then + f (indexedLeafState step n (x,p.1.2) p.2.1)*f (indexedLeafState step n (x,p.1.2) p.2.2) else 0 + have hF : Measurable F := + Measurable.ite hcond ((hm Prod.fst measurable_fst).mul (hm Prod.snd measurable_snd)) measurable_const + have hm' : Measurable (fun p => ∫ l, F (p,l) ∂(κ×ₖκ) p) := + (hF.stronglyMeasurable.integral_kernel_prod_right').measurable + unfold indexedTerminalPairMean + simpa only [F,κ, Kernel.prod_apply] using hm' + +lemma indexedTerminalPairMean_eq (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (x : X) (d : Fin (n+1)) (f : X→ℝ) + (p : IndexedCascadeBase n×IndexedCascadeMarks S n) + (hi : Integrable (fun l => Real.exp (H (indexedLeafState step n (x,p.2) l))) (indexedLeafProbability n p.1)) : + indexedTerminalPairMean step n H x d f p = + ∫ l : IndexedLeaf n×IndexedLeaf n, + f (indexedLeafState step n (x,p.2) l.1)*f (indexedLeafState step n (x,p.2) l.2) + ∂((tiltLaw (indexedLeafProbability n p.1) (indexedTerminalEnergy step n H x p) 1).prod + (tiltLaw (indexedLeafProbability n p.1) (indexedTerminalEnergy step n H x p) 1)).restrict + {l | indexedCommonDepth n l.1 l.2=d} := by + unfold indexedTerminalPairMean + dsimp only + rw [gibbsProbabilityKernel_of_integrable (indexedTerminalBaseKernel n) _ (indexedTerminalEnergy_measurable step hs n H hH x) p hi] + simpa only [Set.indicator_apply,Set.mem_ofPred_eq,indexedTerminalBaseKernel,Kernel.comap_apply,indexedLeafKernel,Kernel.coe_mk] using + (integral_indicator (f:=fun l : IndexedLeaf n×IndexedLeaf n => + f (indexedLeafState step n (x,p.2) l.1)*f (indexedLeafState step n (x,p.2) l.2)) + (μ:=((tiltLaw (indexedLeafProbability n p.1) (indexedTerminalEnergy step n H x p) 1).prod + (tiltLaw (indexedLeafProbability n p.1) (indexedTerminalEnergy step n H x p) 1))) + ((Set.to_countable {l : IndexedLeaf n×IndexedLeaf n | indexedCommonDepth n l.1 l.2=d}).measurableSet)) + +lemma indexedTerminalPairMean_integral [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S→X) + (hs : Measurable step) (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 tiltedStateStep ν step (z i) (finiteCascadeShifts ν step n z H i)) f d x := by + rw [←indexed_terminal_pair_integral ν step hs n z hz hz0 hz1 H hH hI x d f hf C hC hfB] + apply integral_congr_ae + filter_upwards [indexed_terminal_exp_integrable_ae ν step hs n z hz hz0 hz1 H hH hI x] with p hp + exact indexedTerminalPairMean_eq step hs n H hH x d f p hp + +lemma indexedTerminalPairMean_bound (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (x : X) (d : Fin (n+1)) (f : X→ℝ) + (C : ℝ) (hC : 0≤C) (hB : ∀ x, |f x|≤C) + (p : IndexedCascadeBase n×IndexedCascadeMarks S n) : + |indexedTerminalPairMean step n H x d f p|≤C^2 := by + have := gibbsProbabilityKernel_markov (indexedTerminalBaseKernel n) + (indexedTerminalEnergy step n H x) (indexedTerminalEnergy_measurable step hs n H hH x) + have hb : ∀ l : IndexedLeaf n×IndexedLeaf n, + ‖(if indexedCommonDepth n l.1 l.2=d then + f (indexedLeafState step n (x,p.2) l.1)*f (indexedLeafState step n (x,p.2) l.2) else 0)‖≤C^2 := by + intro l + split_ifs + · rw [Real.norm_eq_abs,abs_mul,pow_two] + exact mul_le_mul (hB _) (hB _) (abs_nonneg _) hC + · simp only [norm_zero] + positivity + simpa [indexedTerminalPairMean] using norm_integral_le_of_norm_le_const + (μ:=(gibbsProbabilityKernel (indexedTerminalBaseKernel n) (indexedTerminalEnergy step n H x) p).prod + (gibbsProbabilityKernel (indexedTerminalBaseKernel n) (indexedTerminalEnergy step n H x) p)) + (Filter.Eventually.of_forall hb) + +variable [Nonempty S] [Nonempty T] + +lemma indexedTerminalPairMean_independent_arrays + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + (∫ p, indexedTerminalPairMean st n (fun p => H p.1+G p.2) (x,y) d + (fun p => f p.1*g p.2) (p.1,indexedMarksZip n p.2) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n))) = + (twoVisitMass n z d).toReal * + (pathCorrelation n (fun i => tiltedStateStep ν step₁ (z i) (finiteCascadeShifts ν step₁ n z H i)) f d x * + pathCorrelation n (fun i => tiltedStateStep ρ step₂ (z i) (finiteCascadeShifts ρ step₂ n z G i)) g d y) := by + dsimp only + let st : (X×Y)×(S×T)→X×Y := fun p => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + have hs : Measurable st := by fun_prop + let B := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)) + let M := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n : Measure (IndexedCascadeMarks T n)) + let M' := (indexedCascadeMarksLaw (productMarkLaw ν ρ) n : Measure (IndexedCascadeMarks (S×T) n)) + let a : IndexedCascadeBase n×(IndexedCascadeMarks S n×IndexedCascadeMarks T n) → + IndexedCascadeBase n×IndexedCascadeMarks (S×T) n := + Prod.map id (indexedMarksZip (S:=S) (T:=T) n) + have ha : Measurable a := measurable_id.prodMap (indexedMarksZip_measurable n) + have hmap : (B.prod M).map a=B.prod M' := by + rw [←Measure.map_prod_map _ _ measurable_id (indexedMarksZip_measurable n),Measure.map_id] + exact congrArg (Measure.prod B) (indexedMarksZip_law ν ρ n) + have hterm : Measurable (fun p : X×Y => H p.1+G p.2) := + (hH.comp measurable_fst).add (hG.comp measurable_snd) + have hfg : Measurable (fun p : X×Y => f p.1*g p.2) := + (hf.comp measurable_fst).mul (hg.comp measurable_snd) + have hval := indexedTerminalPairMean_integral (productMarkLaw ν ρ) st hs n z hz hz0 hz1 + (fun p : X×Y => H p.1+G p.2) hterm + (finiteCascadeFractionalIntegrable_add_product ν ρ step₁ step₂ n z hz0 hHI hGI) + (x,y) d (fun p : X×Y => f p.1*g p.2) hfg (C*D) (mul_nonneg hC hD) + (fun p => by rw [abs_mul]; exact mul_le_mul (hfB p.1) (hgB p.2) (abs_nonneg _) hC) + change (∫ p, indexedTerminalPairMean st n _ _ _ _ p ∂B.prod M')=_ at hval + rw [←hmap,integral_map ha.aemeasurable + (indexedTerminalPairMean_measurable st hs n _ hterm (x,y) d _ hfg).aestronglyMeasurable] at hval + refine hval.trans ?_ + dsimp only [st] + simp_rw [cascadeTiltedStep_parallel ν ρ step₁ step₂ hs₁ hs₂ n z hz0 H G hH hG hHI hGI] + rw [pathCorrelation_parallel n _ _ + (cascadeTiltedStep_markov ν step₁ hs₁ n z hz0 H hH hHI) + (cascadeTiltedStep_markov ρ step₂ hs₂ n z hz0 G hG hGI) f g hf hg C D hC hD hfB hgB] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalRoots.lean b/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalRoots.lean new file mode 100644 index 0000000000000000000000000000000000000000..08f9ba005de6231f9f656de2c4707ff29978c407 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/IndexedTerminalRoots.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.IndexedTerminalProduct + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +section +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + +lemma indexedTerminalPairMean_joint_measurable (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (d : Fin (n+1)) + (f : X→ℝ) (hf : Measurable f) : + Measurable (fun p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n) => + indexedTerminalPairMean step n H p.1 d f p.2) := by + let β : Kernel (X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) (IndexedLeaf n) := + (indexedTerminalBaseKernel n).comap Prod.snd measurable_snd + let E : (X×(IndexedCascadeBase n×IndexedCascadeMarks S n))→IndexedLeaf n→ℝ := + fun p l => H (indexedLeafState step n (p.1,p.2.2) l) + have hE : Measurable (Function.uncurry E) := + hH.comp ((indexedLeafState_measurable hs n).comp + ((measurable_fst.fst.prodMk measurable_fst.snd.snd).prodMk measurable_snd)) + let κ := gibbsProbabilityKernel β E + have : IsMarkovKernel β := by dsimp [β]; infer_instance + have : IsMarkovKernel κ := gibbsProbabilityKernel_markov β E hE + have he (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : + κ p=gibbsProbabilityKernel (indexedTerminalBaseKernel n) (indexedTerminalEnergy step n H p.1) p.2 := + gibbsProbabilityKernel_congr_apply β E (indexedTerminalBaseKernel n) + (indexedTerminalEnergy step n H p.1) hE + (indexedTerminalEnergy_measurable step hs n H hH p.1) p p.2 + (by simp [β]) rfl + let F : (X×(IndexedCascadeBase n×IndexedCascadeMarks S n))×(IndexedLeaf n×IndexedLeaf n)→ℝ := + fun p => if indexedCommonDepth n p.2.1 p.2.2=d then + f (indexedLeafState step n (p.1.1,p.1.2.2) p.2.1)* + f (indexedLeafState step n (p.1.1,p.1.2.2) p.2.2) else 0 + have hm (j : IndexedLeaf n×IndexedLeaf n→IndexedLeaf n) (hj : Measurable j) : + Measurable (fun p : (X×(IndexedCascadeBase n×IndexedCascadeMarks S n))×(IndexedLeaf n×IndexedLeaf n) => + f (indexedLeafState step n (p.1.1,p.1.2.2) (j p.2))) := + hf.comp ((indexedLeafState_measurable hs n).comp + ((measurable_fst.fst.prodMk measurable_fst.snd.snd).prodMk (hj.comp measurable_snd))) + have hcond : MeasurableSet {p : (X×(IndexedCascadeBase n×IndexedCascadeMarks S n))×(IndexedLeaf n×IndexedLeaf n) | + indexedCommonDepth n p.2.1 p.2.2=d} := + ((Set.to_countable {l : IndexedLeaf n×IndexedLeaf n | indexedCommonDepth n l.1 l.2=d}).measurableSet).preimage measurable_snd + have hF : Measurable F := + Measurable.ite hcond ((hm Prod.fst measurable_fst).mul (hm Prod.snd measurable_snd)) measurable_const + have hv : Measurable (fun p => ∫ l, F (p,l) ∂(κ×ₖκ) p) := + (hF.stronglyMeasurable.integral_kernel_prod_right').measurable + simp_rw [Kernel.prod_apply,he] at hv + unfold indexedTerminalPairMean + simpa only [F] using hv + +end +variable {X Y S T R Q : Type} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace S] [MeasurableSpace T] [Nonempty S] [Nonempty T] + [MeasurableSpace R] [MeasurableSpace Q] + +lemma indexedTerminalPairMean_independent_roots + (μ : ProbabilityMeasure R) (σ : ProbabilityMeasure Q) (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + (∫ p, indexedTerminalPairMean st n (fun p => H p.1+G p.2) (x p.1.1,y p.1.2) d + (fun p => f p.1*g p.2) (p.2.1,indexedMarksZip n p.2.2) + ∂((μ : Measure R).prod (σ : Measure Q)).prod + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n)))) = + (twoVisitMass n z d).toReal * + ((∫ r, pathCorrelation n (fun i => tiltedStateStep ν step₁ (z i) (finiteCascadeShifts ν step₁ n z H i)) f d (x r) ∂μ) * + (∫ q, pathCorrelation n (fun i => tiltedStateStep ρ step₂ (z i) (finiteCascadeShifts ρ step₂ n z G i)) g d (y q) ∂σ)) := by + dsimp only + let st : (X×Y)×(S×T)→X×Y := fun p => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + let term : X×Y→ℝ := fun p => H p.1+G p.2 + let obs : X×Y→ℝ := fun p => f p.1*g p.2 + have hs : Measurable st := by fun_prop + have hterm : Measurable term := by fun_prop + have hfg : Measurable obs := by fun_prop + have hb (p : X×Y) : |f p.1*g p.2|≤C*D := by + rw [abs_mul]; exact mul_le_mul (hfB p.1) (hgB p.2) (abs_nonneg _) hC + let V : (R×Q)×(IndexedCascadeBase n×(IndexedCascadeMarks S n×IndexedCascadeMarks T n))→ℝ := + fun p => indexedTerminalPairMean st n term (x p.1.1,y p.1.2) d obs (p.2.1,indexedMarksZip n p.2.2) + let B := IndexedCascadeBase n×(IndexedCascadeMarks S n×IndexedCascadeMarks T n) + let transport : (R×Q)×B→(X×Y)×(IndexedCascadeBase n×IndexedCascadeMarks (S×T) n) := + fun p => ((x p.1.1,y p.1.2),(p.2.1,indexedMarksZip n p.2.2)) + have hzip : Measurable (indexedMarksZip (S:=S) (T:=T) n) := indexedMarksZip_measurable n + have htransport : Measurable transport := + (((hx.comp (measurable_fst.fst : Measurable (fun p : (R×Q)×B => p.1.1))).prodMk + (hy.comp measurable_fst.snd)).prodMk + (measurable_snd.fst.prodMk (hzip.comp measurable_snd.snd))) + have hjoint := indexedTerminalPairMean_joint_measurable st hs n term hterm d obs hfg + have hV' := hjoint.comp htransport + have hV : Measurable V := hV' + have hi : Integrable V (((μ : Measure R).prod (σ : Measure Q)).prod + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n)))) := + Integrable.of_bound hV.aestronglyMeasurable ((C*D)^2) (ae_of_all _ fun p => by + simpa only [Real.norm_eq_abs] using indexedTerminalPairMean_bound st hs n term hterm + (x p.1.1,y p.1.2) d obs (C*D) (mul_nonneg hC hD) hb _) + change (∫ p, V p ∂_)=_ + rw [integral_prod _ hi] + simp_rw [V,term,obs,st,indexedTerminalPairMean_independent_arrays ν ρ step₁ step₂ hs₁ hs₂ n z hz hz0 hz1 + H G hH hG hHI hGI _ _ d f g hf hg C D hC hD hfB hgB] + rw [integral_const_mul] + exact congrArg ((twoVisitMass n z d).toReal * ·) + (integral_prod_mul + (fun r => pathCorrelation n (fun i => tiltedStateStep ν step₁ (z i) + (finiteCascadeShifts ν step₁ n z H i)) f d (x r)) + (fun q => pathCorrelation n (fun i => tiltedStateStep ρ step₂ (z i) + (finiteCascadeShifts ρ step₂ n z G i)) g d (y q))) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/KernelEnergyConcentration.lean b/lean/OAI/Probability/Perceptron/Pressure/KernelEnergyConcentration.lean new file mode 100644 index 0000000000000000000000000000000000000000..507fef4af6b14746c4fb4146a9f527672f1c12d6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/KernelEnergyConcentration.lean @@ -0,0 +1,80 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.UnboundedContact + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) [IsProbabilityMeasure P] +variable {H Y : A → S → ℝ} + +lemma kernel_coupling_energy_concentration + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + (he : ∀ᵐ a ∂P, ∀ r : ℝ, Integrable (fun x => Real.exp (H a x+r*Y a x)) (κ a)) + (hm : Integrable (fun a => tiltMean (κ a) (H a) (Y a) 1) P) + (ht : Integrable (fun a => tiltMean (κ a) (H a) + (fun x => |Y a x-tiltMean (κ a) (H a) (Y a) 1|) 1) P) : + let EY := ∫ a, tiltMean (κ a) (H a) (Y a) 1 ∂P + Integrable (fun a => tiltMean (κ a) (H a) (fun x => |Y a x|) 1) P ∧ + Integrable (fun a => tiltMean (κ a) (H a) (fun x => |Y a x-EY|) 1) P ∧ + (∫ a, tiltMean (κ a) (H a) (fun x => |Y a x-EY|) 1 ∂P) ≤ + (∫ a, tiltMean (κ a) (H a) (fun x => |Y a x-tiltMean (κ a) (H a) (Y a) 1|) 1 ∂P)+ + ∫ a, |tiltMean (κ a) (H a) (Y a) 1-EY| ∂P := by + dsimp only + let m := fun a => tiltMean (κ a) (H a) (Y a) 1 + let U := fun a => tiltMean (κ a) (H a) (fun x => |Y a x-m a|) 1 + have ht' : Integrable U P := ht + have hbound (c : ℝ) : ∀ᵐ a ∂P, + tiltMean (κ a) (H a) (fun x => |Y a x-c|) 1 ≤ U a+|m a-c| := by + filter_upwards [he] with a he + simpa only [zero_mul,add_zero] using + coupling_tilt_center_triangle (κ a) hH.of_uncurry_left hY.of_uncurry_left he 0 (m a) c + have hib (c : ℝ) : Integrable (fun a => tiltMean (κ a) (H a) (fun x => |Y a x-c|) 1) P := by + apply (ht'.add ((hm.sub (integrable_const c)).abs)).mono' + (kernel_tiltMean_measurable κ (Y := fun a x => |Y a x-c|) hH (hY.sub measurable_const |>.abs)).aestronglyMeasurable + filter_upwards [hbound c] with a ha + simpa only [Pi.add_apply,Pi.sub_apply,Real.norm_of_nonneg (tiltMean_nonneg (κ a) (fun _ => abs_nonneg _) 1)] using ha + refine ⟨by simpa only [sub_zero] using hib 0,hib (∫ a, m a ∂P),?_⟩ + calc + _ ≤ ∫ a, U a+|m a-∫ b, m b ∂P| ∂P := integral_mono_ae (hib _) (ht'.add ((hm.sub (integrable_const _)).abs)) (hbound _) + _ = _ := integral_add ht' ((hm.sub (integrable_const _)).abs) + +lemma kernel_scaled_energy_concentration + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + (he : ∀ᵐ a ∂P, ∀ r : ℝ, Integrable (fun x => Real.exp (H a x+r*Y a x)) (κ a)) + {v C D : ℝ} (hv : 0 v*tiltMean (κ a) (H a) (Y a) 1) P) + (ht : Integrable (fun a => Real.sqrt v*tiltMean (κ a) (H a) + (fun x => |Y a x-tiltMean (κ a) (H a) (Y a) 1|) 1) P) + (hC : (∫ a, Real.sqrt v*tiltMean (κ a) (H a) + (fun x => |Y a x-tiltMean (κ a) (H a) (Y a) 1|) 1 ∂P) ≤ C) + (hD : (∫ a, |v*tiltMean (κ a) (H a) (Y a) 1- + ∫ b, v*tiltMean (κ b) (H b) (Y b) 1 ∂P| ∂P) ≤ D) : + let EY := ∫ a, tiltMean (κ a) (H a) (Y a) 1 ∂P + Integrable (fun a => tiltMean (κ a) (H a) (fun x => |Y a x|) 1) P ∧ + Integrable (fun a => tiltMean (κ a) (H a) (fun x => |Y a x-EY|) 1) P ∧ + (∫ a, tiltMean (κ a) (H a) (fun x => |Y a x-EY|) 1 ∂P) ≤ C/Real.sqrt v+D/v := by + have hm' : Integrable (fun a => tiltMean (κ a) (H a) (Y a) 1) P := by + convert hm.div_const v using 1 + funext a + exact (mul_div_cancel_left₀ _ hv.ne').symm + have ht' : Integrable (fun a => tiltMean (κ a) (H a) + (fun x => |Y a x-tiltMean (κ a) (H a) (Y a) 1|) 1) P := by + convert ht.div_const (Real.sqrt v) using 1 + funext a + exact (mul_div_cancel_left₀ _ (Real.sqrt_pos.mpr hv).ne').symm + have hres := kernel_coupling_energy_concentration κ P hH hY he hm' ht' + refine ⟨hres.1,hres.2.1,hres.2.2.trans (add_le_add ?_ ?_)⟩ + · rw [integral_const_mul] at hC + exact (le_div_iff₀ (Real.sqrt_pos.mpr hv)).mpr (by simpa only [mul_comm] using hC) + · simp_rw [integral_const_mul,← mul_sub,abs_mul,abs_of_pos hv] at hD + rw [integral_const_mul] at hD + exact (le_div_iff₀ hv).mpr (by simpa only [mul_comm] using hD) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/PatternFree.lean b/lean/OAI/Probability/Perceptron/Pressure/PatternFree.lean new file mode 100644 index 0000000000000000000000000000000000000000..6bf44717ec052f4538f20e15c641e8bee66c689e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/PatternFree.lean @@ -0,0 +1,218 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DensityDerivative +import OAI.Probability.Perceptron.Variational.StepDual +import OAI.Probability.Perceptron.Cascade.CascadeHeat + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def enrichedSpinProjection (N : ℕ) (p : Fin N→ℕ) : EnrichedMark N N p →L[ℝ] Spin N := + ({ toFun := fun a => WithLp.toLp 2 (fun i => a (.inl i)) + map_add' := by intros; rfl + map_smul' := by intros; rfl } : EnrichedMark N N p →ₗ[ℝ] Spin N).toContinuousLinearMap + +@[simp] lemma enrichedSpinProjection_apply (N : ℕ) (p : Fin N→ℕ) + (a : EnrichedMark N N p) (i : Fin N) : enrichedSpinProjection N p a i=a (.inl i) := rfl + +lemma enrichedSpinProjection_preserving (N : ℕ) (p : Fin N→ℕ) : + MeasurePreserving (enrichedSpinProjection N p) (stdGaussian (EnrichedMark N N p)) + (stdGaussian (Spin N)) := by + refine ⟨(enrichedSpinProjection N p).measurable,?_⟩ + have hi : (Measure.pi (fun _ : EnrichedIndex N N p => gaussianReal 0 1)).map + (fun a i => a (Sum.inl i))=Measure.pi (fun _ : Fin N => gaussianReal 0 1) := by + simpa only [Measure.infinitePi_eq_pi] using + (Measure.map_infinitePi_infinitePi_of_inj + (P := fun _ : EnrichedIndex N N p => gaussianReal 0 1) + (f := (Sum.inl : Fin N→EnrichedIndex N N p)) Sum.inl_injective) + rw [← map_pi_eq_stdGaussian,Measure.map_map (by fun_prop) (by fun_prop)] + change (Measure.pi (fun _ : EnrichedIndex N N p => gaussianReal 0 1)).map + ((WithLp.toLp 2) ∘ (fun a i => a (Sum.inl i)))=_ + rw [← Measure.map_map (by fun_prop) (by fun_prop),hi,map_pi_eq_stdGaussian] + +section Transport +variable {E F : Type} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + [NormedAddCommGroup F] [InnerProductSpace ℝ F] + [FiniteDimensional ℝ F] [MeasurableSpace F] [BorelSpace F] + +omit [BorelSpace E] in +lemma gaussianLinearBackward_projection (P : E →L[ℝ] F) + (hp : MeasurePreserving P (stdGaussian E) (stdGaussian F)) + (A : ℕ→E →L[ℝ] E) (σ : ℕ→ℝ) (hA : ∀ j x, P (A j x)=σ j • P x) + {f : F→ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (k : ℕ) (z : Fin k→ℝ) (hz : ∀ i, 0≤z i) (x : E) : + gaussianLinearBackward (stdGaussian E) (linearCascadeWord A k z) (fun a => f (P a)) x= + gaussianBackward (stdGaussian F) (cascadeHeatWord σ k z) f (P x) := by + induction k generalizing x with + | zero => rfl + | succ k ih => + simp only [linearCascadeWord,gaussianLinearBackward,cascadeHeatWord,gaussianBackward, + gaussianLinearEntropic,gaussianEntropic] + simp_rw [ih (fun i => z i.succ) (fun i => hz i.succ),map_add,hA] + let g := gaussianBackward (stdGaussian F) (cascadeHeatWord σ k (fun i => z i.succ)) f + have hg : Continuous g := (gaussianBackward_lipschitz (stdGaussian F) hf _ + (cascadeHeatWord_nonneg σ k _ (fun i => hz i.succ))).continuous + have hc : cgf (fun y => g (P x+σ k • P y)) (stdGaussian E)= + cgf (fun y => g (P x+σ k • y)) (stdGaussian F) := by + funext t + unfold cgf mgf + rw [← hp.map_eq,integral_map hp.measurable.aemeasurable (by + exact (Real.continuous_exp.comp (continuous_const.mul + (hg.comp (continuous_const.add (continuous_const.smul continuous_id))))).aestronglyMeasurable)] + exact congrArg (fun c : ℝ→ℝ => ∫ t in (0:ℝ)..1, deriv c (z 0*t)) hc +end Transport + +lemma enrichedSpinProjection_increment {N k : ℕ} (p d : Fin N→ℕ) + (h : Fin (k+1)→ℝ) (j : ℕ) (a : EnrichedMark N N p) : + enrichedSpinProjection N p (enrichedIncrementMap p d h j a)= + stepFieldIncrement k h j • enrichedSpinProjection N p a := by + ext i + by_cases hj : j 0) htop a= + logSphericalExp n (Real.sqrt (n+1:ℕ)) (enrichedSpinProjection (n+1) p a)-(n+1:ℕ)*htop := by + unfold enrichedTerminal vectorLogPartition vectorPartition logSphericalExp sphericalExp + congr 2 + apply integral_congr_ae + exact ae_of_all _ fun x => by + apply congrArg Real.exp + simp only [normalizedPatternEnergy,Finset.univ_eq_empty,Finset.sum_empty,zero_add, + sourceEnrichedFeature,innerSL_apply_apply,PiLp.inner_apply,enrichedFeature, + Fintype.sum_sum_type,perturbationAmplitude,mul_zero, + inner_zero_left,zero_mul,Finset.sum_const_zero,add_zero,enrichedSpinProjection_apply] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + change a (.inl i)*(Real.sqrt (n+1:ℕ)*x.val i)= + Real.sqrt (n+1:ℕ)*(x.val i*a (.inl i)) + ring + +lemma enrichedExpectedLog_patternFree (n k : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin 0→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 0) h z g= + (n+1:ℕ)*amplitudeSphereValue n k (stepFieldIncrement k h) z (Real.sqrt (2*h 0))- + (n+1:ℕ)*h (Fin.last k) := by + let F := logSphericalExp n (Real.sqrt (n+1:ℕ)) + let c := -((n+1:ℕ)*h (Fin.last k)) + have hF : LipschitzWith ⟨|Real.sqrt (n+1:ℕ)|,abs_nonneg _⟩ F := + logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ)) + have hFc : LipschitzWith ⟨|Real.sqrt (n+1:ℕ)|,abs_nonneg _⟩ (fun a => F a+c) := by + intro a b + simpa only [F,edist_add_right] using hF a b + have hp := enrichedSpinProjection_preserving (n+1) p + have hG := gaussianBackward_lipschitz (stdGaussian (Spin (n+1))) hF _ + (cascadeHeatWord_nonneg (stepFieldIncrement k h) k z (fun i => (hz0 i).le)) + have hroot : Continuous (fun a : Spin (n+1) => + gaussianBackward (stdGaussian (Spin (n+1))) (cascadeHeatWord (stepFieldIncrement k h) k z) + F (Real.sqrt (2*h 0) • a)) := hG.continuous.comp (show Continuous (fun a : Spin (n+1) => Real.sqrt (2*h 0) • a) by fun_prop) + unfold enrichedExpectedLog + rw [(enrichedCascadeLog_joint_mean n 0 k f g p d (fun _ => 0) h z hz hz0 hz1).2] + have ht : enrichedTerminal n 0 f g p (fun _ => 0) (h (Fin.last k))= + (fun a => F (enrichedSpinProjection (n+1) p a)+c) := by + funext a + exact enrichedTerminal_patternFree n f g p (h (Fin.last k)) a + rw [ht] + change (∫ a, gaussianLinearBackward (stdGaussian (EnrichedMark (n+1) (n+1) p)) + (linearCascadeWord (enrichedIncrementMap p d h) k z) + (fun a => F (enrichedSpinProjection (n+1) p a)+c) (enrichedRootMap p d h a) + ∂stdGaussian (EnrichedMark (n+1) (n+1) p))=_ + simp_rw [gaussianLinearBackward_projection (enrichedSpinProjection (n+1) p) hp + (enrichedIncrementMap p d h) (stepFieldIncrement k h) (enrichedSpinProjection_increment p d h) + hFc k z (fun i => (hz0 i).le),enrichedSpinProjection_root, + gaussianBackward_add_const (stdGaussian (Spin (n+1))) hF _ + (cascadeHeatWord_nonneg (stepFieldIncrement k h) k z (fun i => (hz0 i).le)) c] + have hi : Integrable (fun a : Spin (n+1) => + gaussianBackward (stdGaussian (Spin (n+1))) (cascadeHeatWord (stepFieldIncrement k h) k z) + F (Real.sqrt (2*h 0) • a)) (stdGaussian (Spin (n+1))) := + ((lipschitz_memLp_stdGaussian (hG.comp ((Real.sqrt (2*h 0) • ContinuousLinearMap.id ℝ (Spin (n+1))).lipschitzWith)))).integrable (by norm_num) + have hi' : Integrable (fun a : EnrichedMark (n+1) (n+1) p => + gaussianBackward (stdGaussian (Spin (n+1))) (cascadeHeatWord (stepFieldIncrement k h) k z) + F (Real.sqrt (2*h 0) • enrichedSpinProjection (n+1) p a)) + (stdGaussian (EnrichedMark (n+1) (n+1) p)) := by + convert ((hp.integrable_comp hroot.aestronglyMeasurable).mpr hi) using 1 + rfl + rw [integral_add hi' (integrable_const c), + integral_const,probReal_univ,one_smul] + have he : (∫ a, gaussianBackward (stdGaussian (Spin (n+1))) + (cascadeHeatWord (stepFieldIncrement k h) k z) F (Real.sqrt (2*h 0) • enrichedSpinProjection (n+1) p a) + ∂stdGaussian (EnrichedMark (n+1) (n+1) p))= + (∫ a, gaussianBackward (stdGaussian (Spin (n+1))) + (cascadeHeatWord (stepFieldIncrement k h) k z) F (Real.sqrt (2*h 0) • a) + ∂stdGaussian (Spin (n+1))) := by + have hm := integral_map (μ := stdGaussian (EnrichedMark (n+1) (n+1) p)) + hp.measurable.aemeasurable hroot.aestronglyMeasurable + rw [hp.map_eq] at hm + exact hm.symm + rw [he,amplitudeSphereValue_eq_backward n k _ z hz hz0 hz1, + gaussianBackward,gaussianEntropic_zero _ hG] + simp only [zero_add] + dsimp only [F,c] + field_simp + ring + +lemma sourceCountExpectedLog_patternFree (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (w h : Fin (k+1)→ℝ) + (hw : ∀ i, 0 0) 0= + finiteSphericalFieldValue n k w h := by + have hz := stepCumulative_strictMono w hw + have hz0 := stepCumulative_pos w hw + have hz1 := stepCumulative_lt_one w hw hw1 + have hi := (enrichedPoissonLog_section_variance n 0 k f p d (fun _ => 0) h + (stepCumulative w) hz hz0 hz1).1.integrable (by norm_num) + have he : sourceCountExpectedLog n k f p d h (stepCumulative w) (fun _ => 0) 0= + ∫ g, enrichedExpectedLog n 0 k f p d (fun _ => 0) h (stepCumulative w) + (patternPrefix (n+1) 0 g) ∂infinitePatternRowsLaw (n+1) := integral_prod _ hi + rw [he] + simp_rw [enrichedExpectedLog_patternFree n k f _ p d h (stepCumulative w) hz hz0 hz1] + rw [integral_const,probReal_univ,one_smul,amplitudeSphereValue_eq] + have hnonneg (index : Fin (k+1)) : 0≤2*h index := + mul_nonneg (by norm_num) (hh0.trans (hh (Fin.zero_le index))) + have hs : (⟨(Real.sqrt (2*h 0))^2,sq_nonneg _⟩ : ℝ≥0)=Real.toNNReal (2*h 0) := by + apply NNReal.eq + change (Real.sqrt (2*h 0))^2=(Real.toNNReal (2*h 0):ℝ) + rw [Real.sq_sqrt (hnonneg 0),Real.toNNReal_of_nonneg (hnonneg 0)] + rfl + rw [hs] + unfold finiteSphericalFieldValue + field_simp + +lemma sourceExpectedPressure_patternFree (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (w h : Fin (k+1)→ℝ) + (hw : ∀ i, 0 0)= + finiteSphericalFieldValue n k w h := by + rw [sourceExpectedPressure_poissonMean n k f p d h (stepCumulative w) (fun _ => 0) + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1)] + simp only [mul_zero,NNReal.coe_zero] + simp only [poissonRealMean,neg_zero,Real.exp_zero,one_mul,zero_pow_eq,ite_div,zero_div,ite_mul,zero_mul] + simp only [tsum_ite_eq,one_div,Nat.factorial_zero,Nat.cast_one,inv_one,one_mul] + simpa only [one_div] using sourceCountExpectedLog_patternFree n k f p d w h hw hw1 hh hh0 + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/PatternMatrices.lean b/lean/OAI/Probability/Perceptron/Pressure/PatternMatrices.lean new file mode 100644 index 0000000000000000000000000000000000000000..c3524d4135bc6f2424db7f910557b9eae9277048 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/PatternMatrices.lean @@ -0,0 +1,411 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.OverlapArray + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma block_event_swap (μ : Measure OverlapArray) (hEx : OverlapSwapInvariant μ) + {n : ℕ} (p q : Fin n) {s : Set (OverlapBlock n)} (hs : MeasurableSet s) : + μ.real (overlapBlock id n ⁻¹' (relabelBlock (Equiv.swap p q) ⁻¹' s)) = + μ.real (overlapBlock id n ⁻¹' s) := by + have heq : overlapBlock id n ⁻¹' (relabelBlock (Equiv.swap p q) ⁻¹' s) = + relabelArray (Equiv.swap p.val q.val) ⁻¹' (overlapBlock id n ⁻¹' s) := by + ext Q + change relabelBlock (Equiv.swap p q) (overlapBlock id n Q) ∈ s ↔ _ + rw [relabelBlock_swap] + rfl + rw [heq] + exact (hEx _ _).measureReal_preimage + (hs.preimage (Measurable.of_eval fun _ => Measurable.of_eval fun _ => + (measurable_pi_apply _).comp (measurable_pi_apply _))).nullMeasurableSet + +theorem gg_duplicate_index (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + {r : ℕ} (hr : 1 ≤ r) (p : Fin (r + 1)) {s : Set (OverlapBlock (r + 1))} + (hs : MeasurableSet s) (t : ℝ) + (hA : 0 < μ.real (overlapBlock id (r + 1) ⁻¹' s)) + (hrow : ∀ Q ∈ overlapBlock id (r + 1) ⁻¹' s, + ∀ j : Fin (r + 1), j ≠ p → Q p j < t) : + 0 < μ.real ((overlapBlock id (r + 1) ⁻¹' s) ∩ replaceEvent p s (r + 1) ∩ + {Q | Q p (r + 1) < t}) := by + let q : Fin (r + 1) := Fin.last r + let e := Equiv.swap p q + let π := Equiv.swap p.val q.val + let s' := relabelBlock e ⁻¹' s + have hs' : MeasurableSet s' := hs.preimage (relabelBlock_measurable e) + have hbase : copyEvent r s' r = overlapBlock id (r + 1) ⁻¹' s' := by + ext Q + change copyBlock r r Q ∈ s' ↔ overlapBlock id (r + 1) Q ∈ s' + have hb : copyBlock r r Q = overlapBlock id (r + 1) Q := by + ext a b + simp [copyBlock, overlapBlock] + rw [hb] + have hA' : 0 < μ.real (copyEvent r s' r) := by + rw [hbase] + exact (block_event_swap μ hEx p q hs).symm ▸ hA + have hrow' : ∀ Q ∈ copyEvent r s' r, ∀ j < r, Q r j < t := by + intro Q hQ j hj + have hmem : relabelArray π Q ∈ overlapBlock id (r + 1) ⁻¹' s := by + rw [hbase] at hQ + change relabelBlock e (overlapBlock id (r + 1) Q) ∈ s at hQ + rwa [relabelBlock_swap] at hQ + let a : Fin (r + 1) := ⟨j, by omega⟩ + have hne : e a ≠ p := by + intro h + have h' := congrArg e h + have haq : a = q := by simpa [e] using h' + have := congrArg Fin.val haq + dsimp [a, q] at this + omega + have h := hrow (relabelArray π Q) hmem (e a) hne + have hp : π p.val = r := by simp [π, q] + have ha : π (e a).val = j := by simp [π, e, fin_swap_val, a] + simpa only [relabelArray, hp, ha] using h + have hD := gg_duplicate_last μ hEx hGG hr hs' t hA' hrow' + have hset : relabelArray π ⁻¹' duplicateEvent r s' t (r + 1) = + (overlapBlock id (r + 1) ⁻¹' s) ∩ replaceEvent p s (r + 1) ∩ + {Q | Q p (r + 1) < t} := by + ext Q + have hfirst : copyBlock r r (relabelArray π Q) ∈ s' ↔ + overlapBlock id (r + 1) Q ∈ s := by + change relabelBlock e (copyBlock r r (relabelArray π Q)) ∈ s ↔ _ + have hb : copyBlock r r (relabelArray π Q) = + overlapBlock id (r + 1) (relabelArray π Q) := by + ext a b + simp [copyBlock, overlapBlock] + rw [hb, relabelBlock_swap, relabelArray_swap_swap] + have hsecond : copyBlock r (r + 1) (relabelArray π Q) ∈ s' ↔ + replaceBlock p (r + 1) Q ∈ s := by + change relabelBlock e (copyBlock r (r + 1) (relabelArray π Q)) ∈ s ↔ _ + rw [← replaceBlock_last] + change relabelBlock (Equiv.swap p q) + (replaceBlock q (r + 1) (relabelArray (Equiv.swap p.val q.val) Q)) ∈ s ↔ _ + rw [replaceBlock_swap p q (le_refl _)] + have hp : π r = p.val := by exact Equiv.swap_apply_right _ _ + have hnew : π (r + 1) = r + 1 := + Equiv.swap_apply_of_ne_of_ne (by have := p.isLt; omega) (by dsimp [q]; omega) + change ((copyBlock r r (relabelArray π Q) ∈ s' ∧ + copyBlock r (r + 1) (relabelArray π Q) ∈ s') ∧ + Q (π r) (π (r + 1)) < t) ↔ ((overlapBlock id (r + 1) Q ∈ s ∧ + replaceBlock p (r + 1) Q ∈ s) ∧ Q p (r + 1) < t) + rw [hfirst, hsecond, hp, hnew] + rw [← hset] + rwa [(hEx _ _).measureReal_preimage + (duplicateEvent_measurable r hs' t (r + 1)).nullMeasurableSet] + +def patternMatrices {κ : Type*} {n : ℕ} (labels : Fin n → κ) + (C : κ → κ → Set ℝ) : Set (OverlapBlock n) := + {B | ∀ i j, i ≠ j → B i j ∈ C (labels i) (labels j)} + +lemma patternMatrices_measurable {κ : Type*} {n : ℕ} (labels : Fin n → κ) + (C : κ → κ → Set ℝ) (hC : ∀ k l, MeasurableSet (C k l)) : + MeasurableSet (patternMatrices labels C) := by + simp only [patternMatrices, ofPred_forall] + apply MeasurableSet.iInter + intro i + apply MeasurableSet.iInter + intro j + apply MeasurableSet.iInter + intro _ + exact (hC _ _).preimage ((measurable_pi_apply j).comp (measurable_pi_apply i)) + +def appendLabel {κ : Type*} {n : ℕ} (labels : Fin n → κ) (k : κ) : Fin (n + 1) → κ := + Fin.lastCases k labels + +@[simp] lemma appendLabel_last {κ : Type*} {n : ℕ} (labels : Fin n → κ) (k : κ) : + appendLabel labels k (Fin.last n) = k := Fin.lastCases_last + +@[simp] lemma appendLabel_castSucc {κ : Type*} {n : ℕ} (labels : Fin n → κ) (k : κ) + (i : Fin n) : appendLabel labels k i.castSucc = labels i := Fin.lastCases_castSucc i + +lemma pattern_append_of_duplicate {κ : Type*} {n : ℕ} (labels : Fin n → κ) + (C : κ → κ → Set ℝ) (p : Fin n) (t : ℝ) (hdiag : C (labels p) (labels p) = Iio t) + (Q : OverlapArray) (hSym : ∀ i j, Q i j = Q j i) + (hA : overlapBlock id n Q ∈ patternMatrices labels C) + (hB : replaceBlock p n Q ∈ patternMatrices labels C) (hedge : Q p n < t) : + overlapBlock id (n + 1) Q ∈ patternMatrices (appendLabel labels (labels p)) C := by + intro i + refine Fin.lastCases ?_ (fun a => ?_) i + · intro j + refine Fin.lastCases (fun h => (h rfl).elim) (fun b _ => ?_) j + by_cases hb : b = p + · subst b + simpa [overlapBlock, hdiag, hSym n p] using hedge + · have h := hB p b (Ne.symm hb) + simpa [replaceBlock, replaceIndex, hb, overlapBlock] using h + · intro j + refine Fin.lastCases (fun _ => ?_) (fun b hab => ?_) j + · by_cases ha : a = p + · subst a + simpa [overlapBlock, hdiag] using hedge + · have h := hB a p ha + simpa [replaceBlock, replaceIndex, ha, overlapBlock] using h + · have h := hA a b (fun h => hab (congrArg Fin.castSucc h)) + simpa [overlapBlock] using h + +theorem gg_pattern_append (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + (hSym : ∀ᵐ Q ∂μ, ∀ i j, Q i j = Q j i) + {κ : Type*} {r : ℕ} (hr : 1 ≤ r) (labels : Fin (r + 1) → κ) + (C : κ → κ → Set ℝ) (hC : ∀ k l, MeasurableSet (C k l)) (p : Fin (r + 1)) (t : ℝ) + (hdiag : C (labels p) (labels p) = Iio t) (hcut : ∀ k l, C k l ⊆ Iio t) + (hA : 0 < μ.real (overlapBlock id (r + 1) ⁻¹' patternMatrices labels C)) : + 0 < μ.real (overlapBlock id (r + 1 + 1) ⁻¹' + patternMatrices (appendLabel labels (labels p)) C) := by + have hd := gg_duplicate_index μ hEx hGG hr p (patternMatrices_measurable labels C hC) t hA + (fun Q hQ j hj => hcut _ _ (hQ p j (Ne.symm hj))) + apply hd.trans_le + apply ENNReal.toReal_mono (measure_ne_top _ _) + apply measure_mono_ae + filter_upwards [hSym] with Q hQ + exact fun h => pattern_append_of_duplicate labels C p t hdiag Q hQ h.1.1 h.1.2 h.2 + +lemma gg_pattern_append_nat (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + (hSym : ∀ᵐ Q ∂μ, ∀ i j, Q i j = Q j i) + {κ : Type*} {n : ℕ} (hn : 2 ≤ n) (labels : Fin n → κ) + (C : κ → κ → Set ℝ) (hC : ∀ k l, MeasurableSet (C k l)) (p : Fin n) (t : ℝ) + (hdiag : C (labels p) (labels p) = Iio t) (hcut : ∀ k l, C k l ⊆ Iio t) + (hA : 0 < μ.real (overlapBlock id n ⁻¹' patternMatrices labels C)) : + 0 < μ.real (overlapBlock id (n + 1) ⁻¹' + patternMatrices (appendLabel labels (labels p)) C) := by + cases n with + | zero => omega + | succ r => exact gg_pattern_append μ hEx hGG hSym (by omega) labels C hC p t hdiag hcut hA + +def tripleLabels (n : ℕ) (i : Fin n) : Fin 3 := ⟨i.val % 3, Nat.mod_lt _ (by omega)⟩ + +lemma appendLabel_tripleLabels {n : ℕ} (hn : 3 ≤ n) : + appendLabel (tripleLabels n) (tripleLabels n ⟨n % 3, (Nat.mod_lt _ (by omega)).trans_le hn⟩) = + tripleLabels (n + 1) := by + funext i + refine Fin.lastCases ?_ (fun a => ?_) i + · apply Fin.ext + simp [tripleLabels] + · simp [tripleLabels] + +theorem gg_triple_pattern (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + (hSym : ∀ᵐ Q ∂μ, ∀ i j, Q i j = Q j i) + (C : Fin 3 → Fin 3 → Set ℝ) (hC : ∀ k l, MeasurableSet (C k l)) (t : ℝ) + (hdiag : ∀ k, C k k = Iio t) (hcut : ∀ k l, C k l ⊆ Iio t) + (hA : 0 < μ.real (overlapBlock id 3 ⁻¹' patternMatrices (tripleLabels 3) C)) : + ∀ n ≥ 3, 0 < μ.real (overlapBlock id n ⁻¹' patternMatrices (tripleLabels n) C) := by + intro n hn + induction n, hn using Nat.le_induction with + | base => exact hA + | succ n hn ih => + have h := gg_pattern_append_nat μ hEx hGG hSym (by omega) (tripleLabels n) C hC + ⟨n % 3, (Nat.mod_lt _ (by omega)).trans_le hn⟩ t (hdiag _) hcut ih + rwa [appendLabel_tripleLabels hn] at h + +open Matrix +open scoped InnerProductSpace + +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +def replicaMean {n : ℕ} (v : Fin n → H) : H := (n : ℝ)⁻¹ • ∑ i, v i + +lemma inner_replicaMean {n : ℕ} (v w : Fin n → H) : + ⟪replicaMean v, replicaMean w⟫_ℝ = + (n : ℝ)⁻¹ ^ 2 * ∑ i, ∑ j, ⟪v i, w j⟫_ℝ := by + simp only [replicaMean, real_inner_smul_left, real_inner_smul_right] + rw [sum_inner] + simp_rw [inner_sum] + ring + +lemma replicaMean_norm_sq_le {n : ℕ} (hn : 0 < n) (v : Fin n → H) {c : ℝ} + (hdiag : ∀ i, ‖v i‖ ^ 2 ≤ 1) + (hoff : ∀ i j, i ≠ j → ⟪v i, v j⟫_ℝ ≤ c) : + ‖replicaMean v‖ ^ 2 ≤ c + (1 - c) / n := by + classical + have hnpos : (0 : ℝ) < n := by exact_mod_cast hn + have hrow (i : Fin n) : (∑ j, ⟪v i, v j⟫_ℝ) ≤ 1 + ((n : ℝ) - 1) * c := by + have hs : (∑ j ∈ Finset.univ.erase i, ⟪v i, v j⟫_ℝ) ≤ + ∑ _j ∈ Finset.univ.erase i, c := + Finset.sum_le_sum fun j hj => hoff i j (Ne.symm (Finset.ne_of_mem_erase hj)) + have hc : ((Finset.univ.erase i).card : ℝ) = (n : ℝ) - 1 := by + simp only [Finset.card_erase_of_mem (Finset.mem_univ i), Finset.card_univ, + Fintype.card_fin] + rw [Nat.cast_sub hn] + norm_num + simp only [Finset.sum_const, nsmul_eq_mul, hc] at hs + rw [← Finset.sum_erase_add _ _ (Finset.mem_univ i)] + rw [real_inner_self_eq_norm_sq] + linarith [hdiag i] + rw [← real_inner_self_eq_norm_sq, inner_replicaMean] + have hs := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => hrow i) + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hs + calc + (n : ℝ)⁻¹ ^ 2 * (∑ i, ∑ j, ⟪v i, v j⟫_ℝ) ≤ + (n : ℝ)⁻¹ ^ 2 * ((n : ℝ) * (1 + ((n : ℝ) - 1) * c)) := + mul_le_mul_of_nonneg_left hs (sq_nonneg _) + _ = c + (1 - c) / n := by field_simp; ring + +lemma inner_replicaMean_eq {n : ℕ} (hn : 0 < n) (v w : Fin n → H) {a : ℝ} + (h : ∀ i j, ⟪v i, w j⟫_ℝ = a) : + ⟪replicaMean v, replicaMean w⟫_ℝ = a := by + rw [inner_replicaMean] + simp_rw [h] + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn) + field_simp + +lemma duplicate_blocks_bound {n : ℕ} (hn : 0 < n) (v : Fin 3 → Fin n → H) + {a b c : ℝ} (hc0 : 0 ≤ c) (hc1 : c ≤ 1) + (hdiag : ∀ k i, ‖v k i‖ ^ 2 ≤ 1) + (hoff : ∀ k i j, i ≠ j → ⟪v k i, v k j⟫_ℝ ≤ c) + (h12 : ∀ i j, ⟪v 0 i, v 1 j⟫_ℝ = a) + (h13 : ∀ i j, ⟪v 0 i, v 2 j⟫_ℝ = b) + (h23 : ∀ i j, ⟪v 1 i, v 2 j⟫_ℝ = c) : + (a - b) ^ 2 ≤ 2 / (n : ℝ) := by + have hnpos : (0 : ℝ) < n := by exact_mod_cast hn + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn + let x := replicaMean (v 0) + let y := replicaMean (v 1) + let z := replicaMean (v 2) + have hx := replicaMean_norm_sq_le hn (v 0) (hdiag 0) (hoff 0) + have hy := replicaMean_norm_sq_le hn (v 1) (hdiag 1) (hoff 1) + have hz := replicaMean_norm_sq_le hn (v 2) (hdiag 2) (hoff 2) + have hxy : ⟪x, y⟫_ℝ = a := inner_replicaMean_eq hn _ _ h12 + have hxz : ⟪x, z⟫_ℝ = b := inner_replicaMean_eq hn _ _ h13 + have hyz : ⟪y, z⟫_ℝ = c := inner_replicaMean_eq hn _ _ h23 + change ‖x‖ ^ 2 ≤ _ at hx + change ‖y‖ ^ 2 ≤ _ at hy + change ‖z‖ ^ 2 ≤ _ at hz + have hsmall : (1 - c) / n ≤ 1 - c := + (div_le_iff₀ hnpos).mpr (by nlinarith) + have hx1 : ‖x‖ ^ 2 ≤ 1 := by linarith + have hdiff : ‖y - z‖ ^ 2 ≤ 2 * ((1 - c) / n) := by + rw [norm_sub_sq_real, hyz] + linarith + have hcs : (a - b) ^ 2 ≤ ‖x‖ ^ 2 * ‖y - z‖ ^ 2 := by + have h := abs_real_inner_le_norm x (y - z) + rw [inner_sub_right, hxy, hxz] at h + have hs := sq_le_sq₀ (abs_nonneg (a - b)) + (mul_nonneg (norm_nonneg x) (norm_nonneg (y - z))) |>.mpr h + simpa only [sq_abs, mul_pow] using hs + calc + (a - b) ^ 2 ≤ ‖x‖ ^ 2 * ‖y - z‖ ^ 2 := hcs + _ ≤ 1 * ‖y - z‖ ^ 2 := mul_le_mul_of_nonneg_right hx1 (sq_nonneg _) + _ ≤ 2 * ((1 - c) / n) := by simpa using hdiff + _ ≤ 2 / n := by apply (le_div_iff₀ hnpos).mpr; nlinarith [div_mul_cancel₀ (1 - c) (ne_of_gt hnpos)] + +lemma arbitrary_duplicate_blocks_equal {a b c : ℝ} (hc0 : 0 ≤ c) (hc1 : c ≤ 1) + (hdup : ∀ n : ℕ, 0 < n → ∃ v : Fin 3 → Fin n → H, + (∀ k i, ‖v k i‖ ^ 2 ≤ 1) ∧ + (∀ k i j, i ≠ j → ⟪v k i, v k j⟫_ℝ ≤ c) ∧ + (∀ i j, ⟪v 0 i, v 1 j⟫_ℝ = a) ∧ + (∀ i j, ⟪v 0 i, v 2 j⟫_ℝ = b) ∧ + (∀ i j, ⟪v 1 i, v 2 j⟫_ℝ = c)) : a = b := by + have hbound (n : ℕ) : (a - b) ^ 2 ≤ 2 / ((n : ℝ) + 1) := by + obtain ⟨v, hd, ho, h12, h13, h23⟩ := hdup (n + 1) (by omega) + simpa only [Nat.cast_add, Nat.cast_one] using + duplicate_blocks_bound (by omega : 0 < n + 1) v hc0 hc1 hd ho h12 h13 h23 + have ht : Tendsto (fun n : ℕ => 2 / ((n : ℝ) + 1)) atTop (𝓝 (0 : ℝ)) := by + simpa only [mul_zero, mul_one_div] using + tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ) |>.const_mul 2 + have hs : (a - b) ^ 2 ≤ 0 := ge_of_tendsto ht (Eventually.of_forall hbound) + nlinarith [sq_nonneg (a - b)] + +lemma replicaMean_norm_le_one {n : ℕ} (hn : 0 < n) (v : Fin n → H) + (hdiag : ∀ i, ‖v i‖ ^ 2 ≤ 1) : ‖replicaMean v‖ ≤ 1 := by + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn) + have hsum : ‖∑ i, v i‖ ≤ (n : ℝ) := by + calc + ‖∑ i, v i‖ ≤ ∑ i, ‖v i‖ := norm_sum_le _ _ + _ ≤ ∑ _i : Fin n, (1 : ℝ) := Finset.sum_le_sum fun i _ => by + nlinarith [hdiag i, norm_nonneg (v i)] + _ = n := by simp + calc + ‖replicaMean v‖ = (n : ℝ)⁻¹ * ‖∑ i, v i‖ := by + simp [replicaMean, norm_smul] + _ ≤ (n : ℝ)⁻¹ * n := mul_le_mul_of_nonneg_left hsum (by positivity) + _ = 1 := inv_mul_cancel₀ hn0 + +lemma inner_replicaMean_le {n : ℕ} (hn : 0 < n) (v w : Fin n → H) {a : ℝ} + (h : ∀ i j, ⟪v i, w j⟫_ℝ ≤ a) : ⟪replicaMean v, replicaMean w⟫_ℝ ≤ a := by + rw [inner_replicaMean] + have hs := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => + Finset.sum_le_sum (fun j (_ : j ∈ Finset.univ) => h i j)) + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hs + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn) + calc + (n : ℝ)⁻¹ ^ 2 * (∑ i, ∑ j, ⟪v i, w j⟫_ℝ) ≤ + (n : ℝ)⁻¹ ^ 2 * ((n : ℝ) * ((n : ℝ) * a)) := mul_le_mul_of_nonneg_left hs (sq_nonneg _) + _ = a := by field_simp + +lemma le_inner_replicaMean {n : ℕ} (hn : 0 < n) (v w : Fin n → H) {a : ℝ} + (h : ∀ i j, a ≤ ⟪v i, w j⟫_ℝ) : a ≤ ⟪replicaMean v, replicaMean w⟫_ℝ := by + rw [inner_replicaMean] + have hs := Finset.sum_le_sum (fun i (_ : i ∈ Finset.univ) => + Finset.sum_le_sum (fun j (_ : j ∈ Finset.univ) => h i j)) + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] at hs + have hn0 : (n : ℝ) ≠ 0 := by exact_mod_cast (ne_of_gt hn) + calc + a = (n : ℝ)⁻¹ ^ 2 * ((n : ℝ) * ((n : ℝ) * a)) := by field_simp + _ ≤ (n : ℝ)⁻¹ ^ 2 * (∑ i, ∑ j, ⟪v i, w j⟫_ℝ) := + mul_le_mul_of_nonneg_left hs (sq_nonneg _) + +lemma duplicate_ordered_blocks_bound {n : ℕ} (hn : 0 < n) (v : Fin 3 → Fin n → H) + {a b c t : ℝ} (hab : a ≤ b) + (hdiag : ∀ k i, ‖v k i‖ ^ 2 ≤ 1) + (hoff : ∀ k i j, i ≠ j → ⟪v k i, v k j⟫_ℝ ≤ t) + (h12 : ∀ i j, ⟪v 0 i, v 1 j⟫_ℝ ≤ a) + (h13 : ∀ i j, b ≤ ⟪v 0 i, v 2 j⟫_ℝ) + (h23 : ∀ i j, c ≤ ⟪v 1 i, v 2 j⟫_ℝ) : + (b - a) ^ 2 ≤ 2 * (t - c) + 2 * ((1 - t) / n) := by + let x := replicaMean (v 0) + let y := replicaMean (v 1) + let z := replicaMean (v 2) + have hx := replicaMean_norm_le_one hn (v 0) (hdiag 0) + have hy := replicaMean_norm_sq_le hn (v 1) (hdiag 1) (hoff 1) + have hz := replicaMean_norm_sq_le hn (v 2) (hdiag 2) (hoff 2) + have hxy : ⟪x, y⟫_ℝ ≤ a := inner_replicaMean_le hn _ _ h12 + have hxz : b ≤ ⟪x, z⟫_ℝ := le_inner_replicaMean hn _ _ h13 + have hyz : c ≤ ⟪y, z⟫_ℝ := le_inner_replicaMean hn _ _ h23 + change ‖x‖ ≤ _ at hx + change ‖y‖ ^ 2 ≤ _ at hy + change ‖z‖ ^ 2 ≤ _ at hz + have hx1 : ‖x‖ ^ 2 ≤ 1 := by nlinarith [norm_nonneg x] + have hdiff : ‖z - y‖ ^ 2 ≤ 2 * (t - c) + 2 * ((1 - t) / n) := by + rw [norm_sub_sq_real, real_inner_comm] + linarith + have hinner : b - a ≤ ⟪x, z - y⟫_ℝ := by rw [inner_sub_right]; linarith + have hnonneg : 0 ≤ ⟪x, z - y⟫_ℝ := by linarith + have habsq : (b - a) ^ 2 ≤ ⟪x, z - y⟫_ℝ ^ 2 := + (sq_le_sq₀ (sub_nonneg.mpr hab) hnonneg).mpr hinner + have hcs : ⟪x, z - y⟫_ℝ ^ 2 ≤ ‖x‖ ^ 2 * ‖z - y‖ ^ 2 := by + have h := abs_real_inner_le_norm x (z - y) + have hs := (sq_le_sq₀ (abs_nonneg _) (mul_nonneg (norm_nonneg x) (norm_nonneg _))).mpr h + simpa only [sq_abs, mul_pow] using hs + exact habsq.trans (hcs.trans ((mul_le_mul_of_nonneg_right hx1 (sq_nonneg _)).trans + (by simpa using hdiff))) + +lemma posSemidef_standard_basis_inner {n : ℕ} (B : Matrix (Fin n) (Fin n) ℝ) + (hB : B.PosSemidef) (i j : Fin n) : + letI := B.toSeminormedAddCommGroup hB + letI := B.toInnerProductSpace hB + ⟪(Pi.single i 1 : Fin n → ℝ), Pi.single j 1⟫_ℝ = B i j := by + change (B *ᵥ Pi.single j 1) ⬝ᵥ star (Pi.single i 1) = B i j + simp + +def triangleConstraints (a b c t : ℝ) (k l : Fin 3) : Set ℝ := + if k = l then Iio t + else if (k = 0 ∧ l = 1) ∨ (k = 1 ∧ l = 0) then Iio a + else if (k = 0 ∧ l = 2) ∨ (k = 2 ∧ l = 0) then Ioo b t + else Ioo c t + +lemma triangleConstraints_measurable (a b c t : ℝ) (k l : Fin 3) : + MeasurableSet (triangleConstraints a b c t k l) := by + unfold triangleConstraints + split_ifs <;> measurability + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/PressureMonotone.lean b/lean/OAI/Probability/Perceptron/Pressure/PressureMonotone.lean new file mode 100644 index 0000000000000000000000000000000000000000..003c6df072bdf396f475a8382a4e904ece59363d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/PressureMonotone.lean @@ -0,0 +1,45 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityTelescoping + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma normalizedPatternLog_mono (n M : ℕ) (f g : ℝ→ᵇℝ) + (hfg : ∀ x : ℝ, f x≤g x) (a : Fin M→Fin (n+1)→ℝ) : + normalizedPatternLog n M f a≤normalizedPatternLog n M g a := by + have hm (f : ℝ→ᵇℝ) : Measurable (normalizedPatternEnergy (n+1) M f a) := + ((normalizedPatternEnergy_continuous (n+1) M f).comp + (show Continuous (fun x : NormalizedSpin (n+1)=>(a,x)) from continuous_const.prodMk continuous_id)).measurable + have hi (f : ℝ→ᵇℝ) : Integrable + (fun x=>Real.exp (normalizedPatternEnergy (n+1) M f a x)) (unitSphereLaw (n+1)) := by + apply Integrable.of_bound (hm f).exp.aestronglyMeasurable (Real.exp (M*‖f‖)) + filter_upwards [] with x + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans (normalizedPatternEnergy_bound _ _ _ a x)) + apply Real.log_le_log + · simpa only [tiltPartition,one_mul] using tilt_partition_pos (unitSphereLaw (n+1)) + (hm f) (by positivity : 0≤M*‖f‖) (normalizedPatternEnergy_bound _ _ _ a) 1 + · apply integral_mono (hi f) (hi g) + intro x + apply Real.exp_le_exp.mpr + unfold normalizedPatternEnergy + exact Finset.sum_le_sum (fun j _=>hfg _) + +lemma expectedPressure_mono_terminal (α : ℝ) (f g : ℝ→ᵇℝ) + (hfg : ∀ x : ℝ,f x≤g x) (n : ℕ) : + expectedPressure α 1 f (n+1)≤expectedPressure α 1 g (n+1) := by + unfold expectedPressure + simp_rw [←normalizedPatternLog_source α 1 _ n,one_smul] + rw [integral_const_mul,integral_const_mul] + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact integral_mono (normalizedPatternLog_integrable n _ f) + (normalizedPatternLog_integrable n _ g) (normalizedPatternLog_mono n _ f g hfg) +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/PressureTransport.lean b/lean/OAI/Probability/Perceptron/Pressure/PressureTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..52bdfc53b213fafa3cb147186ddd7e0a2e771fa7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/PressureTransport.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.HeightWord +import OAI.Probability.Perceptron.Variational.GaussianWordStability + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma finiteFieldCDFLeft_mem {d : ℕ} (w h : Fin (d+1) → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) (t : ℝ) : + finiteFieldCDFLeft w h t ∈ Icc (0:ℝ) 1 := by + constructor + · apply Finset.sum_nonneg + intro i _ + split_ifs <;> first | exact hw i | rfl + · rw [← hw1] + apply Finset.sum_le_sum + intro i _ + split_ifs <;> first | exact le_rfl | exact hw i + +def sphericalContinuityConstant (n : ℕ) (H : ℝ) : ℝ := + 2*gaussianEntropicParamConstant (stdGaussian (Spin (n+1))) + |Real.sqrt (n+1:ℕ)| (Real.sqrt (2*H))/(n+1:ℕ) + +lemma sphericalContinuityConstant_nonneg (n : ℕ) (H : ℝ) : + 0 ≤ sphericalContinuityConstant n H := by + unfold sphericalContinuityConstant + exact div_nonneg (mul_nonneg (by norm_num) (gaussianEntropicParamConstant_nonneg _ _ _)) (by positivity) + +lemma sphericalHeatValue_parameter_bound (n N : ℕ) (a b σ : Fin N → ℝ) (S : ℝ) + (ha : ∀ i, a i ∈ Icc (0:ℝ) 1) (hb : ∀ i, b i ∈ Icc (0:ℝ) 1) + (hσ : ∀ i, σ i ∈ Icc (0:ℝ) S) : + |sphericalHeatValue n (List.ofFn fun i => (a i,σ i))- + sphericalHeatValue n (List.ofFn fun i => (b i,σ i))| ≤ + gaussianEntropicParamConstant (stdGaussian (Spin (n+1))) |Real.sqrt (n+1:ℕ)| S * + (∑ i, (σ i)^2*|a i-b i|)/(n+1:ℕ) := by + have H := gaussianBackward_ofFn_parameter_bound (stdGaussian (Spin (n+1))) + (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) N a b σ ha hb hσ 0 + have hn : (0:ℝ) < (n+1:ℕ) := by positivity + have Hd := div_le_div_of_nonneg_right H hn.le + have hs (x y c : ℝ) : |(x/(n+1:ℕ)-c)-(y/(n+1:ℕ)-c)|=|x-y|/(n+1:ℕ) := by + rw [show (x/(n+1:ℕ)-c)-(y/(n+1:ℕ)-c)=(x-y)/(n+1:ℕ) by ring] + rw [abs_div,abs_of_pos hn] + simp only [sphericalHeatValue,List.map_ofFn,List.sum_ofFn,Function.comp_def,hs] + convert Hd using 1 + rfl + +theorem finiteSphericalFieldValue_coupling_bound {d e : ℕ} (w h : Fin (d+1) → ℝ) + (v g : Fin (e+1) → ℝ) (c : Fin (d+1)×Fin (e+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) + (hv : ∀ j, 0 < v j) (hv1 : ∑ j, v j=1) + (hh : Monotone h) (hh0 : 0 ≤ h 0) (hg : Monotone g) (hg0 : 0 ≤ g 0) + (hcn : ∀ a, 0 ≤ c a) (hr : ∀ i, ∑ j, c (i,j)=w i) (hc : ∀ j, ∑ i, c (i,j)=v j) + (H : ℝ) (hH : 0 ≤ H) (hhH : h (Fin.last d) ≤ H) (hgH : g (Fin.last e) ≤ H) (n : ℕ) : + |finiteSphericalFieldValue n d w h-finiteSphericalFieldValue n e v g| ≤ + sphericalContinuityConstant n H*(∑ a, c a*|h a.1-g a.2|) := by + have hhb : ∀ i, h i ∈ Icc (0:ℝ) H := fun i => + ⟨hh0.trans (hh (Fin.zero_le i)),(hh (Fin.le_last i)).trans hhH⟩ + have hgb : ∀ i, g i ∈ Icc (0:ℝ) H := fun i => + ⟨hg0.trans (hg (Fin.zero_le i)),(hg (Fin.le_last i)).trans hgH⟩ + obtain ⟨K,z,hz,hz0,hzH,hm,gm⟩ := exists_common_height_partition h g H hH hhb hgb + rw [finiteSphericalFieldValue_height_word w h hw hw1 hh hh0 z hz hz0 hm n, + finiteSphericalFieldValue_height_word v g hv hv1 hg hg0 z hz hz0 gm n] + have hσ : ∀ j, Real.sqrt (heightVariances z j) ∈ Icc (0:ℝ) (Real.sqrt (2*H)) := by + intro j + refine ⟨Real.sqrt_nonneg _,Real.sqrt_le_sqrt ?_⟩ + have Hsum := heightVariances_sum z + rw [hz0,hzH,sub_zero] at Hsum + rw [← Hsum] + exact Finset.single_le_sum (fun i _ => heightVariances_nonneg z hz i) (Finset.mem_univ j) + have hp := sphericalHeatValue_parameter_bound n K _ _ _ (Real.sqrt (2*H)) + (fun j => finiteFieldCDFLeft_mem w h (fun i => (hw i).le) hw1 (z j.succ)) + (fun j => finiteFieldCDFLeft_mem v g (fun i => (hv i).le) hv1 (z j.succ)) hσ + simp only [Real.sq_sqrt (heightVariances_nonneg z hz _)] at hp + have hcst := gaussianEntropicParamConstant_nonneg (stdGaussian (Spin (n+1))) + |Real.sqrt (n+1:ℕ)| (Real.sqrt (2*H)) + have hcost := finiteFieldCDFLeft_partition_cost w h v g c hcn hr hc z hz hm gm + calc + _ ≤ _ := hp + _ ≤ _ := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_left hcost hcst) (by positivity) + _ = _ := by unfold sphericalContinuityConstant; ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/RootPartition.lean b/lean/OAI/Probability/Perceptron/Pressure/RootPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..30f9dbfef2b109e955c89e1660644284d9be216e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/RootPartition.lean @@ -0,0 +1,240 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open scoped Classical +open MeasureTheory Set +open scoped ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +def RootPartitionMatch {I A B : Type*} {J : I → Type*} + (xs : (Σ i, J i) → A × B) : Prop := + ∀ u v, (xs u).1 = (xs v).1 ↔ u.1 = v.1 + +def rootPartitionEncode {I A B : Type*} {J : I → Type*} + (a : I ↪ A) (bs : (Σ i, J i) → B) : (Σ i, J i) → A × B := + fun x => (a x.1, bs x) + +lemma rootPartitionEncode_matches {I A B : Type*} {J : I → Type*} + (a : I ↪ A) (bs : (Σ i, J i) → B) : + RootPartitionMatch (rootPartitionEncode a bs) := by + intro u v + exact a.injective.eq_iff + +def rootPartitionEquiv {I A B : Type*} {J : I → Type*} + [∀ i, Nonempty (J i)] : + ((I ↪ A) × ((Σ i, J i) → B)) ≃ + {xs : (Σ i, J i) → A × B // RootPartitionMatch xs} := by + classical + let f : ((I ↪ A) × ((Σ i, J i) → B)) → + {xs : (Σ i, J i) → A × B // RootPartitionMatch xs} := + fun ab => ⟨rootPartitionEncode ab.1 ab.2, rootPartitionEncode_matches ab.1 ab.2⟩ + refine Equiv.ofBijective f ⟨?_, ?_⟩ + · intro ab cd h + have he := congrArg Subtype.val h + apply Prod.ext + · apply Function.Embedding.ext + intro i + exact congrArg (fun xs => (xs ⟨i, Classical.choice inferInstance⟩).1) he + · funext x + exact congrArg (fun xs => (xs x).2) he + · rintro ⟨xs, hx⟩ + let a : I ↪ A := ⟨(fun i => (xs ⟨i, Classical.choice inferInstance⟩).1), by + intro i j hij + exact (hx ⟨i, Classical.choice inferInstance⟩ ⟨j, Classical.choice inferInstance⟩).mp hij⟩ + refine ⟨(a, fun x => (xs x).2), Subtype.ext ?_⟩ + funext x + apply Prod.ext + · change (xs ⟨x.1, Classical.choice inferInstance⟩).1 = (xs x).1 + exact (hx _ _).mpr rfl + · rfl + +@[simp] lemma rootPartitionEquiv_apply {I A B : Type*} {J : I → Type*} + [∀ i, Nonempty (J i)] (a : I ↪ A) (bs : (Σ i, J i) → B) : + (rootPartitionEquiv (a,bs)).val = rootPartitionEncode a bs := rfl + +lemma ennreal_tsum_fin_prod (m : ℕ) (J : Fin m → Type*) + (f : ∀ i, J i → ℝ≥0∞) : + (∑' x : ∀ i, J i, ∏ i, f i (x i)) = ∏ i, ∑' y, f i y := by + induction m with + | zero => simp + | succ m ih => + rw [← (Fin.consEquiv J).tsum_eq] + simp only [ENNReal.tsum_prod', Fin.prod_univ_succ, Fin.consEquiv_apply, + Fin.cons_zero, Fin.cons_succ, ENNReal.tsum_mul_left] + rw [ih, ENNReal.tsum_mul_right] + +lemma ennreal_tsum_pi_prod {I : Type*} [Fintype I] (J : I → Type*) + (f : ∀ i, J i → ℝ≥0∞) : + (∑' x : ∀ i, J i, ∏ i, f i (x i)) = ∏ i, ∑' y, f i y := by + let e := (Fintype.equivFin I).symm + rw [← (Equiv.piCongrLeft J e).tsum_eq] + simp_rw [← e.prod_comp, Equiv.piCongrLeft_apply_apply] + exact ennreal_tsum_fin_prod _ _ _ + +lemma tsum_rootPartition {I A B : Type*} {J : I → Type*} + [∀ i, Nonempty (J i)] (F : ((Σ i, J i) → A × B) → ℝ≥0∞) : + (∑' xs, if RootPartitionMatch xs then F xs else 0) = + ∑' a : I ↪ A, ∑' bs : (Σ i, J i) → B, F (rootPartitionEncode a bs) := by + classical + calc + _ = ∑' xs : {xs : (Σ i, J i) → A × B // RootPartitionMatch xs}, F xs.val := by + exact (tsum_subtype {xs | RootPartitionMatch xs} F).symm + _ = ∑' ab : (I ↪ A) × ((Σ i, J i) → B), F (rootPartitionEncode ab.1 ab.2) := + (rootPartitionEquiv.tsum_eq (fun xs => F xs.val)).symm + _ = _ := ENNReal.tsum_prod' + +lemma root_partition_sum_factor {I A B : Type*} [Fintype I] {J : I → Type*} + [∀ i, Fintype (J i)] [∀ i, Nonempty (J i)] + (p : A → ℝ≥0∞) (q : A → B → ℝ≥0∞) + (H : ∀ i, (J i → B) → ℝ≥0∞) : + (∑' xs : (Σ i, J i) → A × B, + if RootPartitionMatch xs then + (∏ u, p (xs u).1 * q (xs u).1 (xs u).2) * + ∏ i, H i (fun j => (xs ⟨i,j⟩).2) else 0) = + ∑' a : I ↪ A, ∏ i, (p (a i)) ^ Fintype.card (J i) * + (∑' ys : J i → B, (∏ j, q (a i) (ys j)) * H i ys) := by + classical + rw [tsum_rootPartition] + apply tsum_congr + intro a + rw [← (Equiv.piCurry (fun (i : I) (_ : J i) => B)).symm.tsum_eq] + simp only [Equiv.piCurry_symm_apply, rootPartitionEncode] + simp_rw [Fintype.prod_sigma] + simp only [Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ] + simp_rw [← Finset.prod_mul_distrib, mul_assoc] + simp only [Sigma.uncurry] + rw [ennreal_tsum_pi_prod (fun i => J i → B) + (fun i ys => p (a i) ^ Fintype.card (J i) * ((∏ j, q (a i) (ys j)) * H i ys))] + apply Finset.prod_congr rfl + intro i hi + exact ENNReal.tsum_mul_left + +lemma tsum_pi_supported {I U V : Type*} [Fintype I] + (e : U ↪ V) (w : V → ℝ≥0∞) (hw : ∀ v, v ∉ Set.range e → w v = 0) + (F : (I → V) → ℝ≥0∞) : + (∑' xs : I → V, (∏ i, w (xs i)) * F xs) = + ∑' xs : I → U, (∏ i, w (e (xs i))) * F (fun i => e (xs i)) := by + classical + let g : (I → U) → (I → V) := fun xs i => e (xs i) + have hg : Function.Injective g := by + intro xs ys he + funext i + exact e.injective (congrFun he i) + exact (hg.tsum_eq (by + intro xs hxs + have hx : ∀ i, ∃ u, e u = xs i := by + intro i + by_contra h + have hz := hw (xs i) h + have hp : (∏ j, w (xs j)) = 0 := Finset.prod_eq_zero (Finset.mem_univ i) hz + exact hxs (by simp [hp]) + choose ys hy using hx + exact ⟨ys, funext hy⟩)).symm + +lemma indicator_forall_eq_prod {I : Type*} [Fintype I] (P : I → Prop) : + (if ∀ i, P i then (1 : ℝ≥0∞) else 0) = ∏ i, if P i then 1 else 0 := by + classical + by_cases h : ∀ i, P i + · simp [h] + · rw [ite_eq_right h] + obtain ⟨i, hi⟩ := not_forall.mp h + exact (Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi)).symm + +def excludedBlockSum {A B : Type*} (label : A → B) : + List (A → ℝ≥0∞) → {m : ℕ} → (Fin m → B) → ℝ≥0∞ + | [], _, _ => 1 + | f::fs, _, v => ∑' a, if ∃ j, v j = label a then 0 else + f a * excludedBlockSum label fs (Fin.cons (label a) v) + +def DistinctAssignmentGood {A B : Type*} (label : A → B) + {n m : ℕ} (a : Fin n → A) (v : Fin m → B) : Prop := + Function.Injective (label ∘ a) ∧ ∀ i j, v j ≠ label (a i) + +lemma distinctAssignmentGood_cons {A B : Type*} (label : A → B) + {n m : ℕ} (a : A) (as : Fin n → A) (v : Fin m → B) : + DistinctAssignmentGood label (Fin.cons a as) v ↔ + (¬ ∃ j, v j = label a) ∧ + DistinctAssignmentGood label as (Fin.cons (label a) v) := by + rw [DistinctAssignmentGood, Fin.comp_cons, Fin.cons_injective_iff] + simp only [Fin.forall_fin_succ, Fin.cons_zero, Fin.cons_succ, + DistinctAssignmentGood, Set.mem_range, not_exists] + constructor + · rintro ⟨⟨hdis, hinj⟩, hroot, htail⟩ + exact ⟨hroot, hinj, fun i => ⟨Ne.symm (hdis i), htail i⟩⟩ + · rintro ⟨hroot, hinj, htail⟩ + exact ⟨⟨fun i => Ne.symm (htail i).1, hinj⟩, hroot, fun i => (htail i).2⟩ + +lemma excludedBlockSum_assignments {A B : Type*} (label : A → B) + (fs : List (A → ℝ≥0∞)) {m : ℕ} (v : Fin m → B) : + excludedBlockSum label fs v = + ∑' a : Fin fs.length → A, + if DistinctAssignmentGood label a v then ∏ i : Fin fs.length, fs[i] (a i) else 0 := by + classical + induction fs generalizing m with + | nil => + simp [excludedBlockSum, DistinctAssignmentGood, Function.Injective] + | cons f fs ih => + simp only [List.length_cons] + rw [excludedBlockSum, ← (Fin.consEquiv (fun _ : Fin (fs.length+1) => A)).tsum_eq, + ENNReal.tsum_prod'] + apply tsum_congr + intro a + simp only [Fin.consEquiv, Equiv.coe_fn_mk, distinctAssignmentGood_cons] + by_cases h : ∃ j, v j = label a + · simp [h] + · rw [ite_eq_right h, ih, ← ENNReal.tsum_mul_left] + apply tsum_congr + intro as + simp only [h, not_false_eq_true, true_and] + by_cases ha : DistinctAssignmentGood label as (Fin.cons (label a) v) + · simp only [Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ, ite_eq_left ha] + rfl + · simp [ha] + +lemma excludedBlockSum_embeddings {A B : Type*} (label : A → B) + (hl : Function.Injective label) (fs : List (A → ℝ≥0∞)) : + excludedBlockSum label fs (Fin.elim0 : Fin 0 → B) = + ∑' a : Fin fs.length ↪ A, ∏ i : Fin fs.length, fs[i] (a i) := by + classical + rw [excludedBlockSum_assignments] + have hg (a : Fin fs.length → A) : + DistinctAssignmentGood label a (Fin.elim0 : Fin 0 → B) ↔ Function.Injective a := by + simp only [DistinctAssignmentGood, Fin.forall_fin_zero, implies_true, and_true] + exact ⟨fun h => fun i j he => h (congrArg label he), fun h => hl.comp h⟩ + simp_rw [hg] + let g : (Fin fs.length ↪ A) → (Fin fs.length → A) := fun a => a + have hginj : Function.Injective g := by + intro a b h + exact Function.Embedding.ext (fun i => congrFun h i) + have he := hginj.tsum_eq (f := fun a : Fin fs.length → A => + if Function.Injective a then ∏ i : Fin fs.length, fs[i] (a i) else 0) (by + intro a ha + have hi : Function.Injective a := by + by_contra hn + exact ha (ite_eq_right hn) + exact ⟨⟨a,hi⟩, rfl⟩) + simpa only [g, Function.Embedding.injective, ↓reduceIte] using he.symm + +lemma tsum_embedding_cast {A : Type*} {n m : ℕ} (h : n = m) + (f : Fin n → A → ℝ≥0∞) : + (∑' a : Fin n ↪ A, ∏ i : Fin n, f i (a i)) = + ∑' a : Fin m ↪ A, ∏ i : Fin m, f (Fin.cast h.symm i) (a i) := by + cases h + rfl + +lemma tsum_embeddings_list_map {A B C : Type*} (xs : List A) (f : A → B) + (g : B → C → ℝ≥0∞) : + (∑' a : Fin (xs.map f).length ↪ C, + ∏ i : Fin (xs.map f).length, g (xs.map f)[i] (a i)) = + ∑' a : Fin xs.length ↪ C, ∏ i : Fin xs.length, g (f xs[i]) (a i) := by + rw [tsum_embedding_cast (List.length_map (f := f))] + simp only [Fin.getElem_fin, Fin.val_cast, List.getElem_map] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/SphericalPatternDirection.lean b/lean/OAI/Probability/Perceptron/Pressure/SphericalPatternDirection.lean new file mode 100644 index 0000000000000000000000000000000000000000..bb2dd310dad54e4bd40251ff006ca92b3a355720 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/SphericalPatternDirection.lean @@ -0,0 +1,87 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.TensorFeatures +import OAI.Probability.Perceptron.Variational.NonlinearDirectionIBP + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma spinOverlap_self {N : ℕ} (x : NormalizedSpin N) : spinOverlap x x = 1 := by + have hx : ‖x.val‖ = 1 := by simp + simp [spinOverlap,hx] + +lemma spinOverlap_sum {N : ℕ} (x y : NormalizedSpin N) : + spinOverlap x y = ∑ i, x.val i*y.val i := by + simp [spinOverlap,PiLp.inner_apply,mul_comm] + +lemma normalizedSpin_coord_bound {N : ℕ} (x : NormalizedSpin N) (i : Fin N) : |x.val i| ≤ 1 := by + have hx : ‖x.val‖ = 1 := by simp + simpa only [Real.norm_eq_abs,hx] using PiLp.norm_apply_le x.val i + +lemma spherical_pattern_direction_ibp {n : ℕ} + (μ : Measure (NormalizedSpin (n+1))) [IsProbabilityMeasure μ] + (f : Jet3) (G : ℝ →ᵇ ℝ) {h : NormalizedSpin (n+1) → ℝ} + (hh : Measurable h) {A : ℝ} (hA : 0≤A) (hhA : ∀ x, |h x|≤A) : + let b := gaussianField (n+1) (fun i (x : NormalizedSpin (n+1)) => x.val i) + let H := fun g x => h x+f.f (b g x) + (∫ g, gibbsReplicaMean μ (H g) 2 (fun x => + G (spinOverlap (x 0) (x 1))*f.d1 (b g (x 0))* + (b g (x 1)-spinOverlap (x 0) (x 1)*b g (x 0))) + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ g, gibbsReplicaMean μ (H g) 2 (fun x => + G (spinOverlap (x 0) (x 1))*f.d1 (b g (x 0))*f.d1 (b g (x 1))* + (1-spinOverlap (x 0) (x 1)^2)) - + 2*gibbsReplicaMean μ (H g) 3 (fun x => + G (spinOverlap (x 1) (x 2))*f.d1 (b g (x 1))*f.d1 (b g (x 0))* + (spinOverlap (x 2) (x 0)-spinOverlap (x 1) (x 2)*spinOverlap (x 1) (x 0))) + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + dsimp only + let v := fun i (x : NormalizedSpin (n+1)) => x.val i + let w := fun i (x : Fin 2→NormalizedSpin (n+1)) => + G (spinOverlap (x 0) (x 1))*(v i (x 1)-spinOverlap (x 0) (x 1)*v i (x 0)) + have hv : ∀ i, Measurable (v i) := fun i => by dsimp [v]; fun_prop + have hw : ∀ i, Measurable (w i) := fun i => by dsimp [w,v,spinOverlap]; fun_prop + have hwB (i x) : |w i x| ≤ ‖G‖*2 := by + dsimp [w]; rw [abs_mul] + apply mul_le_mul (G.norm_coe_le_norm _) _ (abs_nonneg _) (norm_nonneg _) + apply (abs_sub _ _).trans + have h1 := normalizedSpin_coord_bound (x 1) i + have h0 := normalizedSpin_coord_bound (x 0) i + have hr := spinOverlap_abs_le (x 0) (x 1) + dsimp [v]; rw [abs_mul] + have := mul_le_mul hr h0 (abs_nonneg _) (by norm_num : (0:ℝ)≤1) + linarith + have hK (x : Fin 2→NormalizedSpin (n+1)) (y : NormalizedSpin (n+1)) : + (∑ i, w i x*v i y) = G (spinOverlap (x 0) (x 1))* + (spinOverlap (x 1) y-spinOverlap (x 0) (x 1)*spinOverlap (x 0) y) := by + simp only [w,v,spinOverlap_sum,Finset.mul_sum,Finset.sum_sub_distrib,sub_mul,mul_sub] + congr 1 <;> (apply Finset.sum_congr rfl; intros; ring) + have hb (g : Fin (n+1)→ℝ) (x : Fin 2→NormalizedSpin (n+1)) : + (∑ i, g i*w i x) = G (spinOverlap (x 0) (x 1))* + (gaussianField (n+1) v g (x 1)-spinOverlap (x 0) (x 1)*gaussianField (n+1) v g (x 0)) := by + simp only [w,gaussianField,Finset.mul_sum,Finset.sum_sub_distrib,mul_sub] + congr 1 <;> (apply Finset.sum_congr rfl; intros; ring) + have he := nonlinear_pattern_direction_ibp μ (0:Fin 2) f hv hh hw hA + (by norm_num : (0:ℝ)≤1) (by positivity : 0≤‖G‖*2) hhA + (fun i x => normalizedSpin_coord_bound x i) hwB + dsimp only at he + simp_rw [hK,hb] at he + convert he using 1 + · congr 1; funext g; congr 1; funext x; ring + · congr 1; funext g + congr 1 + · congr 1; funext x + simp only [Fin.sum_univ_two,spinOverlap_self] + rw [show spinOverlap (x 1) (x 0) = spinOverlap (x 0) (x 1) from real_inner_comm _ _] + ring + · congr 1; congr 1; funext x + simp only [Fin.succ_zero_eq_one,Fin.succ_one_eq_two] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/SphericalPatternRadial.lean b/lean/OAI/Probability/Perceptron/Pressure/SphericalPatternRadial.lean new file mode 100644 index 0000000000000000000000000000000000000000..989751bdd5787cb6f9c2ce642ea514520c302561 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/SphericalPatternRadial.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.SphericalPatternDirection + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma spherical_pattern_radial_ibp {n : ℕ} + (μ : Measure (NormalizedSpin (n+1))) [IsProbabilityMeasure μ] + (f : Jet3) {h : NormalizedSpin (n+1)→ℝ} + (hh : Measurable h) {A : ℝ} (hA : 0≤A) (hhA : ∀ x,|h x|≤A) : + let b := gaussianField (n+1) (fun i (x : NormalizedSpin (n+1)) => x.val i) + let H := fun g x => h x+f.f (b g x) + (∫ g,gibbsReplicaMean μ (H g) 1 (fun x => b g (x 0)*f.d1 (b g (x 0))) + ∂Measure.pi (fun _ => gaussianReal 0 1))= + ∫ g,gibbsReplicaMean μ (H g) 1 (fun x => f.d2 (b g (x 0))+f.d1 (b g (x 0))^2)- + gibbsReplicaMean μ (H g) 2 (fun x => spinOverlap (x 0) (x 1)*f.d1 (b g (x 0))*f.d1 (b g (x 1))) + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + dsimp only + let v := fun i (x : NormalizedSpin (n+1)) => x.val i + let w := fun i (x : Fin 1→NormalizedSpin (n+1)) => v i (x 0) + have hv : ∀ i,Measurable (v i) := fun i => by dsimp [v]; fun_prop + have hw : ∀ i,Measurable (w i) := fun i => by dsimp [w,v]; fun_prop + have hK (x : Fin 1→NormalizedSpin (n+1)) (y : NormalizedSpin (n+1)) : + (∑ i,w i x*v i y)=spinOverlap (x 0) y := by simp only [w,v,spinOverlap_sum] + have hb (g : Fin (n+1)→ℝ) (x : Fin 1→NormalizedSpin (n+1)) : + (∑ i,g i*w i x)=gaussianField (n+1) v g (x 0) := rfl + have he := nonlinear_pattern_direction_ibp μ (0:Fin 1) f hv hh hw hA + (by norm_num : (0:ℝ)≤1) (by norm_num : (0:ℝ)≤1) hhA + (fun i x => normalizedSpin_coord_bound x i) (fun i x => normalizedSpin_coord_bound (x 0) i) + dsimp only at he + simp_rw [hK,hb] at he + convert he using 1 + · congr 1; funext g; congr 1; funext x; ring + · congr 1; funext g + simp only [Nat.cast_one,one_mul,Fin.sum_univ_one,spinOverlap_self,Fin.succ_zero_eq_one,mul_one] + congr 1 + · congr 1; funext x; ring + · congr 1; funext x + rw [show spinOverlap (x 1) (x 0)=spinOverlap (x 0) (x 1) from real_inner_comm _ _] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/TerminalRestorationCoefficients.lean b/lean/OAI/Probability/Perceptron/Pressure/TerminalRestorationCoefficients.lean new file mode 100644 index 0000000000000000000000000000000000000000..d126ce36a94cb7e56d0ea87b8199a118f13ffff6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/TerminalRestorationCoefficients.lean @@ -0,0 +1,189 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.IndexedTerminalRoots +import OAI.Probability.Perceptron.Variational.TiltedPathDiagonal + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators BoundedContinuousFunction + +section +section +variable {X Y R Q S T : Type} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace R] [MeasurableSpace Q] [MeasurableSpace S] [MeasurableSpace T] + [Nonempty S] [Nonempty T] + +lemma indexedTerminalPairMean_ignore_old + (μ : ProbabilityMeasure R) (σ : ProbabilityMeasure Q) (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + (∫ p, indexedTerminalPairMean st n (fun p => H p.1+G p.2) (x p.1.1,y p.1.2) d + (fun p => f p.1) (p.2.1,indexedMarksZip n p.2.2) + ∂((μ : Measure R).prod (σ : Measure Q)).prod + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n)))) = + (twoVisitMass n z d).toReal * rootPathCorrelation μ x n + (fun i => tiltedStateStep ν step₁ (z i) (finiteCascadeShifts ν step₁ n z H i)) f d := by + have h := indexedTerminalPairMean_independent_roots μ σ ν ρ step₁ step₂ hs₁ hs₂ + n z hz hz0 hz1 H G hH hG hHI hGI x y hx hy d f (fun _ => 1) + hf measurable_const C 1 hC (by norm_num) hfB (fun _ => by norm_num) + have hm i := cascadeTiltedStep_markov ρ step₂ hs₂ n z hz0 G hG hGI i + simpa only [mul_one,pathCorrelation_one n _ hm,integral_const,probReal_univ, + one_smul,rootPathCorrelation] using h + +omit [Nonempty S] [Nonempty T] in +lemma cascade_root_pair_coefficients_product + (μ : ProbabilityMeasure R) (σ : ProbabilityMeasure Q) (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz0 : ∀ i, 0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + rootPathCorrelation ((μ : Measure R).prod (σ : Measure Q)) (fun r => (x r.1,y r.2)) n + (fun i => tiltedStateStep (productMarkLaw ν ρ) st (z i) + (finiteCascadeShifts (productMarkLaw ν ρ) st n z (fun p => H p.1+G p.2) i)) + (fun p => f p.1*g p.2) d = + rootPathCorrelation μ x n (fun i => tiltedStateStep ν step₁ (z i) + (finiteCascadeShifts ν step₁ n z H i)) f d * + rootPathCorrelation σ y n (fun i => tiltedStateStep ρ step₂ (z i) + (finiteCascadeShifts ρ step₂ n z G i)) g d := by + dsimp only + simp_rw [cascadeTiltedStep_parallel ν ρ step₁ step₂ hs₁ hs₂ n z hz0 H G hH hG hHI hGI] + exact rootPathCorrelation_parallel μ σ x y n _ _ + (fun i => cascadeTiltedStep_markov ν step₁ hs₁ n z hz0 H hH hHI i) + (fun i => cascadeTiltedStep_markov ρ step₂ hs₂ n z hz0 G hG hGI i) + f g hf hg C D hC hD hfB hgB d + +end +variable {X R : Type} [MeasurableSpace X] [MeasurableSpace R] + +lemma residual_path_pair_coefficients + (μ : Measure R) [IsProbabilityMeasure μ] (x : R→X) (hx : Measurable x) + (n : ℕ) (κ : Fin n→Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (e : X→ℝ) (he : Measurable e) (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) : + (∀ d, 0≤rootPathCorrelation μ x n κ (fun y => residualResponse s f v (e y)) d) ∧ + Monotone (rootPathCorrelation μ x n κ (fun y => residualResponse s f v (e y))) ∧ + (∀ d, rootPathCorrelation μ x n κ (fun y => residualResponse s f v (e y)) d ≤ + rootPathMean μ x n κ (fun y => residualResponse s f (v*v) (e y))) ∧ + (rootPathMean μ x n κ (fun y => residualResponse s f (v*v) (e y))≤‖v‖^2) := by + have hv := (residualResponse_continuous s f v).measurable.comp he + have hvv := (residualResponse_continuous s f (v*v)).measurable.comp he + have hb := fun y => residualResponse_bound s f v (e y) + have hbb := fun y => residualResponse_bound s f (v*v) (e y) + refine ⟨fun d => rootPathCorrelation_nonneg μ x n κ hκ _ hv _ (norm_nonneg _) hb d, + rootPathCorrelation_monotone μ x hx n κ hκ _ hv _ (norm_nonneg _) hb,?_,?_⟩ + · intro d + exact rootPathCorrelation_le_diagonal μ x hx n κ hκ _ _ hv hvv _ _ + (norm_nonneg _) hb hbb (fun y => residualResponse_jensen s f v (e y)) d + · apply (le_abs_self _).trans + apply (show |rootPathMean μ x n κ (fun y => residualResponse s f (v*v) (e y))|≤‖v*v‖ from ?_).trans + · simpa only [pow_two] using norm_mul_le v v + · simpa only [rootPathMean,Real.norm_eq_abs,probReal_univ,mul_one] using + norm_integral_le_of_norm_le_const + (μ:=μ) (f:=fun r => pathMean n κ (fun y => residualResponse s f (v*v) (e y)) (x r)) + (ae_of_all _ fun r => by + simpa only [Real.norm_eq_abs] using pathMean_bound n κ hκ _ ‖v*v‖ hbb (x r)) + +end +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + +def indexedTerminalMean (step : X×S→X) (n : ℕ) (H : X→ℝ) (x : X) + (f : X→ℝ) (p : IndexedCascadeBase n×IndexedCascadeMarks S n) : ℝ := + ∫ l, f (indexedLeafState step n (x,p.2) l) + ∂gibbsProbabilityKernel (indexedTerminalBaseKernel n) (indexedTerminalEnergy step n H x) p + +lemma indexedTerminalMean_joint_measurable (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (f : X→ℝ) (hf : Measurable f) : + Measurable (fun p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n) => + indexedTerminalMean step n H p.1 f p.2) := by + let β : Kernel (X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) (IndexedLeaf n) := + (indexedTerminalBaseKernel n).comap Prod.snd measurable_snd + let E : (X×(IndexedCascadeBase n×IndexedCascadeMarks S n))→IndexedLeaf n→ℝ := + fun p l => H (indexedLeafState step n (p.1,p.2.2) l) + have hstate : Measurable (fun p : (X×(IndexedCascadeBase n×IndexedCascadeMarks S n))×IndexedLeaf n => + indexedLeafState step n (p.1.1,p.1.2.2) p.2) := (indexedLeafState_measurable hs n).comp + ((measurable_fst.fst.prodMk measurable_fst.snd.snd).prodMk measurable_snd) + have hE : Measurable (Function.uncurry E) := hH.comp hstate + let κ := gibbsProbabilityKernel β E + have : IsMarkovKernel β := by dsimp [β]; infer_instance + have : IsMarkovKernel κ := gibbsProbabilityKernel_markov β E hE + have he (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : + κ p=gibbsProbabilityKernel (indexedTerminalBaseKernel n) (indexedTerminalEnergy step n H p.1) p.2 := + gibbsProbabilityKernel_congr_apply β E (indexedTerminalBaseKernel n) + (indexedTerminalEnergy step n H p.1) hE + (indexedTerminalEnergy_measurable step hs n H hH p.1) p p.2 + (by simp [β]) rfl + have hm := (hf.comp hstate).stronglyMeasurable.integral_kernel_prod_right' (κ:=κ) + simpa only [he,indexedTerminalMean,Function.comp_apply] using hm.measurable + +lemma indexedTerminalMean_bound (step : X×S→X) (hs : Measurable step) + (n : ℕ) (H : X→ℝ) (hH : Measurable H) (x : X) (f : X→ℝ) + (C : ℝ) (hb : ∀ y, |f y|≤C) (p : IndexedCascadeBase n×IndexedCascadeMarks S n) : + |indexedTerminalMean step n H x f p|≤C := by + have := gibbsProbabilityKernel_markov (indexedTerminalBaseKernel n) _ + (indexedTerminalEnergy_measurable step hs n H hH x) + simpa only [indexedTerminalMean,Real.norm_eq_abs,probReal_univ,mul_one] using + norm_integral_le_of_norm_le_const + (μ:=gibbsProbabilityKernel (indexedTerminalBaseKernel n) (indexedTerminalEnergy step n H x) p) + (f:=fun l => f (indexedLeafState step n (x,p.2) l)) + (ae_of_all _ fun l => by simpa only [Real.norm_eq_abs] using hb (indexedLeafState step n (x,p.2) l)) + +variable [Nonempty S] +lemma indexedTerminalMean_integral (ν : ProbabilityMeasure S) (step : X×S→X) (hs : Measurable step) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 tiltedStateStep ν step (z i) (finiteCascadeShifts ν step n z H i)) f x := by + let μ := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)) + let F := finiteCascadeShifts ν step n z H + have hF := finiteCascadeShifts_measurable ν step hs n z hH + let κ := indexedOneStateKernel step hs n F hF x + have he : (fun p => indexedTerminalMean step n H x f p)=ᵐ[μ] + (fun p => ∫ y, f y ∂κ p) := by + have hi := indexed_terminal_exp_integrable_ae ν step hs n z hz hz0 hz1 H hH hI x + have hb₀ := (measurePreserving_fst (μ := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n))) + (ν := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))).quasiMeasurePreserving.ae + (indexedLeafMeasure_regular n z hz hz0 hz1) + filter_upwards [hi,hb₀] with p hi hp + unfold indexedTerminalMean + rw [gibbsProbabilityKernel_of_integrable (indexedTerminalBaseKernel n) _ + (indexedTerminalEnergy_measurable step hs n H hH x) p hi] + have hmap := indexed_terminal_oneState ν step hs n z H hH x p.1 p.2 hp hi + have hh := integral_map (μ:=tiltLaw (indexedLeafProbability n p.1) + (fun l => H (indexedLeafState step n (x,p.2) l)) 1) + (measurable_of_countable (indexedLeafState step n (x,p.2))).aemeasurable hf.aestronglyMeasurable + rw [hmap] at hh + exact hh.symm + rw [integral_congr_ae he] + have hnorm := finiteCascadeShifts_normalized_of_fractional ν step n z (fun i => (hz0 i).ne') H hI + have hi := path_bounded_integrable (κ ∘ₘ μ) f hf C hb + have hcomp : (∫ y, f y ∂(κ ∘ₘ μ))=∫ p, ∫ y, f y ∂κ p ∂μ := by + rw [Measure.comp_eq_comp_const_apply] at hi ⊢ + exact Kernel.integral_comp hi + rw [←hcomp] + change (∫ y, f y ∂(indexedOneStateKernel step hs n F hF x ∘ₘ μ))=_ + rw [indexedOneStateLaw_eq ν step hs n z hz hz0 hz1 F hF + (fun i y => (hnorm i y).1) (fun i y => (hnorm i y).2)] + rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/TerminalRestorationLaw.lean b/lean/OAI/Probability/Perceptron/Pressure/TerminalRestorationLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..3eb4fb9e99e752b9fe2ad1e922c5e5f6906a4f33 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/TerminalRestorationLaw.lean @@ -0,0 +1,137 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.TerminalRestorationCoefficients + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +section +variable {X R S : Type} [MeasurableSpace X] [MeasurableSpace R] [MeasurableSpace S] [Nonempty S] + +lemma indexedTerminalMean_root_integral (μ : ProbabilityMeasure R) (ν : ProbabilityMeasure S) + (step : X×S→X) (hs : Measurable step) (n : ℕ) (z : Fin n→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 tiltedStateStep ν step (z i) (finiteCascadeShifts ν step n z H i)) f := by + let V : R×(IndexedCascadeBase n×IndexedCascadeMarks S n)→ℝ := + fun p => indexedTerminalMean step n H (x p.1) f p.2 + have hm := (indexedTerminalMean_joint_measurable step hs n H hH f hf).comp + ((hx.comp measurable_fst).prodMk measurable_snd) + have hV : Measurable V := hm + have hi : Integrable V ((μ : Measure R).prod ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))) := by + apply Integrable.of_bound hV.aestronglyMeasurable C + exact ae_of_all _ fun p => by + simpa only [Real.norm_eq_abs] using indexedTerminalMean_bound step hs n H hH (x p.1) f C hb p.2 + change (∫ p, V p ∂_)=_ + rw [integral_prod _ hi] + simp only [V,indexedTerminalMean_integral ν step hs n z hz hz0 hz1 H hH hI _ f hf C hb,rootPathMean] + +end +section +variable {X Y R Q S T : Type} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace R] [MeasurableSpace Q] [MeasurableSpace S] [MeasurableSpace T] + +lemma rootPathMean_parallel (μ : Measure R) (σ : Measure Q) [SFinite μ] [SFinite σ] + (x : R→X) (y : Q→Y) (n : ℕ) (κ : Fin n→Kernel X X) (η : Fin n→Kernel Y Y) + (hκ : ∀ i, IsMarkovKernel (κ i)) (hη : ∀ i, IsMarkovKernel (η i)) + (f : X→ℝ) (g : Y→ℝ) (hf : Measurable f) (hg : Measurable g) + (C D : ℝ) (hC : 0≤C) (hD : 0≤D) (hfB : ∀ a, |f a|≤C) (hgB : ∀ b, |g b|≤D) : + rootPathMean (μ.prod σ) (fun p => (x p.1,y p.2)) n (fun i => κ i ∥ₖ η i) + (fun p => f p.1*g p.2) = rootPathMean μ x n κ f * rootPathMean σ y n η g := by + unfold rootPathMean + simp_rw [pathMean_parallel n κ η hκ hη f g hf hg C D hC hD hfB hgB] + exact integral_prod_mul (fun r => pathMean n κ f (x r)) (fun q => pathMean n η g (y q)) + +lemma cascade_root_single_coefficients_product + (μ : ProbabilityMeasure R) (σ : ProbabilityMeasure Q) (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz0 : ∀ i, 0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + rootPathMean ((μ : Measure R).prod (σ : Measure Q)) (fun r => (x r.1,y r.2)) n + (fun i => tiltedStateStep (productMarkLaw ν ρ) st (z i) + (finiteCascadeShifts (productMarkLaw ν ρ) st n z (fun p => H p.1+G p.2) i)) + (fun p => f p.1*g p.2) = + rootPathMean μ x n (fun i => tiltedStateStep ν step₁ (z i) + (finiteCascadeShifts ν step₁ n z H i)) f * + rootPathMean σ y n (fun i => tiltedStateStep ρ step₂ (z i) + (finiteCascadeShifts ρ step₂ n z G i)) g := by + dsimp only + simp_rw [cascadeTiltedStep_parallel ν ρ step₁ step₂ hs₁ hs₂ n z hz0 H G hH hG hHI hGI] + exact rootPathMean_parallel μ σ x y n _ _ + (fun i => cascadeTiltedStep_markov ν step₁ hs₁ n z hz0 H hH hHI i) + (fun i => cascadeTiltedStep_markov ρ step₂ hs₂ n z hz0 G hG hGI i) + f g hf hg C D hC hD hfB hgB + +end +variable {X Y Z R Q U S T V : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + [MeasurableSpace R] [MeasurableSpace Q] [MeasurableSpace U] + [MeasurableSpace S] [MeasurableSpace T] [MeasurableSpace V] + [Nonempty S] [Nonempty T] [Nonempty V] + +lemma indexedTerminalPairMean_two_fresh_old + (μ : ProbabilityMeasure R) (σ : ProbabilityMeasure Q) (τ : ProbabilityMeasure U) + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) (π : ProbabilityMeasure V) + (st₁ : X×S→X) (st₂ : Y×T→Y) (st₀ : Z×V→Z) + (hs₁ : Measurable st₁) (hs₂ : Measurable st₂) (hs₀ : Measurable st₀) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 + ((st₁ (p.1.1.1,p.2.1.1),st₂ (p.1.1.2,p.2.1.2)),st₀ (p.1.2,p.2.2)) + (∫ p, indexedTerminalPairMean st n (fun p => (H p.1.1+G p.1.2)+J p.2) + ((x p.1.1.1,y p.1.1.2),v p.1.2) d (fun p => f p.1.1*g p.1.2) + (p.2.1,indexedMarksZip n p.2.2) + ∂(((μ : Measure R).prod (σ : Measure Q)).prod (τ : Measure U)).prod + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw (productMarkLaw ν ρ) n : Measure (IndexedCascadeMarks (S×T) n)).prod + (indexedCascadeMarksLaw π n)))) = + (twoVisitMass n z d).toReal * + (rootPathCorrelation μ x n (fun i => tiltedStateStep ν st₁ (z i) + (finiteCascadeShifts ν st₁ n z H i)) f d * + rootPathCorrelation σ y n (fun i => tiltedStateStep ρ st₂ (z i) + (finiteCascadeShifts ρ st₂ n z G i)) g d) := by + let st : (X×Y)×(S×T)→X×Y := fun p => (st₁ (p.1.1,p.2.1),st₂ (p.1.2,p.2.2)) + have hs : Measurable st := by fun_prop + have hfg : Measurable (fun p : X×Y => f p.1*g p.2) := by fun_prop + have hb (p : X×Y) : |f p.1*g p.2|≤C*D := by + rw [abs_mul]; exact mul_le_mul (hfB _) (hgB _) (abs_nonneg _) hC + have h := indexedTerminalPairMean_ignore_old (productMarkLaw μ σ) τ (productMarkLaw ν ρ) π + st st₀ hs hs₀ n z hz hz0 hz1 (fun p => H p.1+G p.2) J (by fun_prop) hJ + (finiteCascadeFractionalIntegrable_add_product ν ρ st₁ st₂ n z hz0 hHI hGI) hJI + (fun p => (x p.1,y p.2)) v (by fun_prop) hv d (fun p => f p.1*g p.2) hfg + (C*D) (mul_nonneg hC hD) hb + dsimp only [st] at h ⊢ + change _ = (twoVisitMass n z d).toReal * + rootPathCorrelation ((μ : Measure R).prod (σ : Measure Q)) (fun p => (x p.1,y p.2)) n + (fun i => tiltedStateStep (productMarkLaw ν ρ) + (fun p => (st₁ (p.1.1,p.2.1),st₂ (p.1.2,p.2.2))) (z i) + (finiteCascadeShifts (productMarkLaw ν ρ) + (fun p => (st₁ (p.1.1,p.2.1),st₂ (p.1.2,p.2.2))) n z (fun p => H p.1+G p.2) i)) + (fun p => f p.1*g p.2) d at h + rw [cascade_root_pair_coefficients_product μ σ ν ρ st₁ st₂ hs₁ hs₂ n z hz0 + H G hH hG hHI hGI x y d f g hf hg C D hC hD hfB hgB] at h + exact h + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/TerminalVariational.lean b/lean/OAI/Probability/Perceptron/Pressure/TerminalVariational.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c7378a11d5a43c1802fe978dd2a1bbb82757b36 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/TerminalVariational.lean @@ -0,0 +1,462 @@ +import Mathlib +import OAI.Probability.Perceptron.Control.ControlDrift + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +def terminalVariational (P : Measure BrownianPath) (α : ℝ) (f : ℝ →ᵇ ℝ) : EReal := + ⨅ m : Trial, ((α * controlValue P f m : ℝ) : EReal) + (entropy m).toEReal + +lemma variationalValue_eq_terminal (P : Measure BrownianPath) (α β : ℝ) (φ : ℝ →ᵇ ℝ) : + variationalValue P α β φ = terminalVariational P α (β • φ) := rfl + +lemma terminalVariational_bounds (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f : ℝ →ᵇ ℝ) : + ((-α*‖f‖ : ℝ) : EReal) ≤ terminalVariational P α f ∧ + terminalVariational P α f ≤ ((α*‖f‖ : ℝ) : EReal) := by + constructor + · apply le_iInf + intro m + have hcv : -α*‖f‖ ≤ α*controlValue P f m := by + nlinarith [mul_le_mul_of_nonneg_left (neg_norm_le_controlValue P f m) hα] + exact (EReal.coe_le_coe_iff.mpr hcv).trans + (le_add_of_nonneg_right (EReal.coe_ennreal_nonneg _)) + · calc + _ ≤ ((α*controlValue P f oneTrial : ℝ) : EReal) + (entropy oneTrial).toEReal := + iInf_le _ oneTrial + _ ≤ ((α*‖f‖ : ℝ) : EReal) := by + simp only [entropy_oneTrial, EReal.coe_ennreal_zero, add_zero] + exact EReal.coe_le_coe_iff.mpr (mul_le_mul_of_nonneg_left (controlValue_le_norm P f _) hα) + +lemma terminalVariational_coe_toReal (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f : ℝ →ᵇ ℝ) : + ((terminalVariational P α f).toReal : EReal) = terminalVariational P α f := by + obtain ⟨hlo,hhi⟩ := terminalVariational_bounds P α hα f + exact EReal.coe_toReal (ne_top_of_le_ne_top (EReal.coe_ne_top _) hhi) + (ne_bot_of_le_ne_bot (EReal.coe_ne_bot _) hlo) + +lemma terminalVariational_toReal_sub_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f g : ℝ →ᵇ ℝ) (δ : ℝ) + (hfg : ∀ m : Trial, controlValue P f m - controlValue P g m ≤ δ) : + (terminalVariational P α f).toReal - (terminalVariational P α g).toReal ≤ α*δ := by + have hbound : (((terminalVariational P α f).toReal - α*δ : ℝ) : EReal) ≤ + terminalVariational P α g := by + apply le_iInf + intro m + have h : terminalVariational P α f ≤ + ((α*controlValue P f m : ℝ) : EReal) + (entropy m).toEReal := iInf_le _ m + have hh : (((terminalVariational P α f).toReal - α*δ : ℝ) : EReal) ≤ + ((α*controlValue P f m - α*δ : ℝ) : EReal) + (entropy m).toEReal := by + have hs := add_le_add_right h ((-α*δ : ℝ) : EReal) + rw [← terminalVariational_coe_toReal P α hα f] at hs + convert hs using 1 <;> simp only [sub_eq_add_neg, EReal.coe_add, EReal.coe_neg] <;> + push_cast <;> simp only [neg_mul, add_assoc, add_comm] + apply hh.trans + apply add_le_add_left + apply EReal.coe_le_coe_iff.mpr + nlinarith [mul_le_mul_of_nonneg_left (hfg m) hα] + rw [← terminalVariational_coe_toReal P α hα g, EReal.coe_le_coe_iff] at hbound + linarith + +lemma terminalVariational_abs_sub_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (α : ℝ) (hα : 0 ≤ α) (f g : ℝ →ᵇ ℝ) (δ : ℝ) + (hfg : ∀ m : Trial, |controlValue P f m - controlValue P g m| ≤ δ) : + |(terminalVariational P α f).toReal - (terminalVariational P α g).toReal| ≤ α*δ := by + have h₁ := terminalVariational_toReal_sub_le P α hα f g δ + (fun m => (abs_le.mp (hfg m)).2) + have h₂ := terminalVariational_toReal_sub_le P α hα g f δ + (fun m => by have hh := (abs_le.mp (hfg m)).1; linarith) + exact abs_le.mpr ⟨by linarith, h₁⟩ + +lemma indep_eventuallyMeasurable_left {Ω : Type*} [mΩ : MeasurableSpace Ω] + (μ : Measure Ω) {m n : MeasurableSpace Ω} (h : Indep m n μ) : + Indep (eventuallyMeasurableSpace m (ae μ)) n μ := by + rw [Indep_iff] at h ⊢ + rintro A B ⟨A', hA', hAA'⟩ hB + rw [measure_congr (hAA'.inter (Filter.EventuallyEq.refl (ae μ) B)), measure_congr hAA'] + exact h A' B hA' hB + +lemma nullSigma_le_eventuallyMeasurable (P : Measure BrownianPath) + (m : MeasurableSpace BrownianPath) : + nullSigma P ≤ eventuallyMeasurableSpace m (ae P) := by + apply MeasurableSpace.generateFrom_le + intro A hA + exact ⟨∅, MeasurableSet.empty, ae_eq_empty.mpr hA⟩ + +@[instance_reducible] def rawBrownianSigma (s : ℝ≥0) : MeasurableSpace BrownianPath := + ⨆ r : {r : ℝ≥0 // r ≤ s}, + MeasurableSpace.comap (brownianEval r.val) (borel ℝ) + +lemma rawBrownianSigma_le (s : ℝ≥0) : rawBrownianSigma s ≤ (inferInstance : MeasurableSpace BrownianPath) := by + apply iSup_le + intro r + exact (brownianEval_measurable r.val).comap_le + +lemma rawBrownianSigma_le_past_comap (s : ℝ≥0) : + rawBrownianSigma s ≤ + MeasurableSpace.comap (fun ω (r : Set.Iic s) => brownianEval r.val ω) inferInstance := by + apply iSup_le + intro r + rintro A ⟨B, hB, rfl⟩ + exact ⟨(fun f : Set.Iic s → ℝ => f r) ⁻¹' B, (measurable_pi_apply r) hB, rfl⟩ + +lemma usualBrownianSigma_le_ae_raw (P : Measure BrownianPath) (t : Time) + (s : ℝ≥0) (hts : (t : ℝ) < s) : + usualBrownianSigma P t ≤ eventuallyMeasurableSpace (rawBrownianSigma s) (ae P) := by + apply (iInf_le _ (⟨s, hts⟩ : {s : ℝ≥0 // (t : ℝ) < s})).trans + exact sup_le le_eventuallyMeasurableSpace (nullSigma_le_eventuallyMeasurable P _) + +lemma brownian_future_indep_raw (P : Measure BrownianPath) + (hB : IsBrownianReal brownianEval P) (s u : ℝ≥0) : + Indep (rawBrownianSigma s) + (MeasurableSpace.comap (fun ω => brownianEval (s+u) ω - brownianEval s ω) (borel ℝ)) P := by + have h := (hB.toIsPreBrownianReal.indepFun_shift s).symm.comp + measurable_id (measurable_pi_apply u) + exact indep_of_indep_of_le_left h (rawBrownianSigma_le_past_comap s) + +lemma brownian_future_indep_usual_earlier (P : Measure BrownianPath) + (hB : IsBrownianReal brownianEval P) (t : Time) (s u : ℝ≥0) + (hts : (t : ℝ) < s) : + Indep (usualBrownianSigma P t) + (MeasurableSpace.comap (fun ω => brownianEval (s+u) ω - brownianEval s ω) (borel ℝ)) P := + indep_of_indep_of_le_left + (indep_eventuallyMeasurable_left P (brownian_future_indep_raw P hB s u)) + (usualBrownianSigma_le_ae_raw P t s hts) + +lemma indep_setIntegral_eq_mul_null {Ω : Type*} {m : MeasurableSpace Ω} + [mΩ : MeasurableSpace Ω] (P : Measure Ω) {X : Ω → ℝ} {A : Set Ω} + (hI : Indep m (MeasurableSpace.comap X (borel ℝ)) P) + (hX : AEMeasurable X P) (hA : MeasurableSet[m] A) (hAn : NullMeasurableSet A P) + (f : ℝ →ᵇ ℝ) : + (∫ ω in A, f (X ω) ∂P) = P.real A * ∫ ω, f (X ω) ∂P := by + calc + _ = ∫ ω, id (A.indicator (1 : Ω → ℝ) ω) * f (X ω) ∂P := by + rw [← integral_indicator₀ hAn] + congr with ω + by_cases hω : ω ∈ A <;> simp [hω] + _ = _ := by + simp only [Pi.one_def] + rw [IndepFun.integral_fun_comp_mul_comp + (hI.indicator_indepFun 1 hA) + ((aemeasurable_indicator_const_iff 1).2 hAn) hX + measurable_id.aestronglyMeasurable f.continuous.measurable.aestronglyMeasurable] + simp only [id_eq, integral_indicator₀ hAn, integral_const, smul_eq_mul, mul_one, + measureReal_def, Measure.restrict_apply_univ] + +lemma indep_comap_of_ae_tendsto {Ω : Type*} {m : MeasurableSpace Ω} + [mΩ : MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P] + (hm : ∀ A, MeasurableSet[m] A → NullMeasurableSet A P) + {X : ℕ → Ω → ℝ} {Y : Ω → ℝ} + (hX : ∀ n, AEMeasurable (X n) P) (hY : AEMeasurable Y P) + (hI : ∀ n, Indep m (MeasurableSpace.comap (X n) (borel ℝ)) P) + (hlim : ∀ᵐ ω ∂P, Tendsto (fun n => X n ω) atTop (𝓝 (Y ω))) : + Indep m (MeasurableSpace.comap Y (borel ℝ)) P := by + apply (Indep_iff_IndepSets _ _ P).2 + apply indepSets_comap_of_bcf (fun A hA => hm A hA) hY + intro A hA f + have hall := tendsto_integral_of_dominated_convergence (fun _ : Ω => ‖f‖) + (fun n => (f.continuous.measurable.comp_aemeasurable (hX n)).aestronglyMeasurable) + (integrable_const _) (fun n => Filter.Eventually.of_forall fun ω => f.norm_coe_le_norm _) + (hlim.mono fun ω hω => f.continuous.continuousAt.tendsto.comp hω) + have hres := tendsto_integral_of_dominated_convergence (μ := P.restrict A) + (fun _ : Ω => ‖f‖) + (fun n => (f.continuous.measurable.comp_aemeasurable (hX n)).aestronglyMeasurable.restrict) + (integrable_const _) (fun n => Filter.Eventually.of_forall fun ω => f.norm_coe_le_norm _) + ((ae_restrict_of_ae hlim).mono fun ω hω => f.continuous.continuousAt.tendsto.comp hω) + apply tendsto_nhds_unique hres + convert hall.const_mul (P.real A) using 1 + ext n + exact indep_setIntegral_eq_mul_null P (hI n) (hX n) hA (hm A hA) f + +lemma brownian_increment_indep_usual (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (t : Time) (r : ℝ≥0) (htr : (t : ℝ) < r) : + Indep (usualBrownianSigma P t) + (MeasurableSpace.comap (fun ω => brownianEval r ω - + brownianEval ⟨t.val, t.property.1⟩ ω) (borel ℝ)) P := by + let t₀ : ℝ≥0 := ⟨t.val, t.property.1⟩ + have ht₀r : t₀ < r := htr + obtain ⟨s, -, hs, hlim⟩ := exists_seq_strictAnti_tendsto' ht₀r + apply indep_comap_of_ae_tendsto P (fun A hA => + (usualBrownianSigma_le_completion P t A hA)) + (X := fun n ω => brownianEval r ω - brownianEval (s n) ω) + (fun n => ((brownianEval_measurable r).sub (brownianEval_measurable (s n))).aemeasurable) + (((brownianEval_measurable r).sub (brownianEval_measurable t₀)).aemeasurable) + · intro n + have hI := brownian_future_indep_usual_earlier P hB t (s n) (r-s n) (hs n).1 + rwa [add_tsub_cancel_of_le (hs n).2.le] at hI + · exact Filter.Eventually.of_forall fun ω => tendsto_const_nhds.sub + (ω.continuous.continuousAt.tendsto.comp hlim) + +def clipControl (L : ℝ) (v : Time → BrownianPath → ℝ) : Time → BrownianPath → ℝ := + fun t ω => max (-L) (min L (v t ω)) + +lemma progressive_clipControl (P : Measure BrownianPath) {v : Time → BrownianPath → ℝ} + (hv : Progressive P v) (L : ℝ) : Progressive P (clipControl L v) := by + intro t + exact measurable_const.max (measurable_const.min (hv t)) + +lemma abs_clip_le {L : ℝ} (hL : 0 ≤ L) (x : ℝ) : |max (-L) (min L x)| ≤ L := by + apply abs_le.mpr + exact ⟨le_max_left _ _, max_le (by linarith) (min_le_left _ _)⟩ + +lemma clip_cost_gain {L : ℝ} (hL : 0 ≤ L) (x : ℝ) : + L * |x - max (-L) (min L x)| ≤ (x^2 - (max (-L) (min L x))^2)/2 := by + by_cases hx : x ≤ -L + · have hxL : x ≤ L := hx.trans (by linarith) + rw [min_eq_right hxL, max_eq_left hx, abs_of_nonpos (by linarith)] + nlinarith [sq_nonneg (x+L)] + · by_cases hLx : L ≤ x + · rw [min_eq_left hLx, max_eq_right (by linarith : -L ≤ L), + abs_of_nonneg (by linarith : 0 ≤ x-L)] + nlinarith [sq_nonneg (x-L)] + · rw [min_eq_right (le_of_not_ge hLx), max_eq_right (le_of_not_ge hx)] + simp + +lemma clip_sq_le {L : ℝ} (hL : 0 ≤ L) (x : ℝ) : + (max (-L) (min L x))^2 ≤ x^2 := by + have h := clip_cost_gain hL x + nlinarith [mul_nonneg hL (abs_nonneg (x - max (-L) (min L x)))] + +lemma pathControlCost_clip_le (m : Trial) {L : ℝ} (hL : 0 ≤ L) + (v : Time → BrownianPath → ℝ) (ω : BrownianPath) : + pathControlCost m (clipControl L v) ω ≤ pathControlCost m v ω := by + apply lintegral_mono + intro t + exact ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left (clip_sq_le hL _) (m.nonneg t)) + +lemma controlCost_clip_le (P : Measure BrownianPath) (m : Trial) {L : ℝ} (hL : 0 ≤ L) + (v : Time → BrownianPath → ℝ) : controlCost P m (clipControl L v) ≤ controlCost P m v := + lintegral_mono fun ω => pathControlCost_clip_le m hL v ω + +lemma weightedTime_integrable (m : Trial) {v : Time → ℝ} (hv : Measurable v) + (hc : (∫⁻ t, ENNReal.ofReal (m t * v t ^ 2) ∂timeLaw) < ∞) : + Integrable (fun t => m t * v t ^ 2) timeLaw ∧ + Integrable (fun t => m t * v t) timeLaw := by + have hm : Integrable m timeLaw := + (integrable_const (1 : ℝ)).mono' m.measurable.aestronglyMeasurable + (Filter.Eventually.of_forall fun t => by simpa [abs_of_nonneg (m.nonneg t)] using m.le_one t) + have hq : Integrable (fun t => m t * v t ^ 2) timeLaw := + ⟨(m.measurable.mul (hv.pow_const 2)).aestronglyMeasurable, + (hasFiniteIntegral_iff_ofReal (Filter.Eventually.of_forall fun t => + mul_nonneg (m.nonneg t) (sq_nonneg _))).mpr hc⟩ + refine ⟨hq, (hq.add hm).mono' (m.measurable.mul hv).aestronglyMeasurable ?_⟩ + apply Filter.Eventually.of_forall + intro t + change |m t * v t| ≤ m t * v t ^ 2 + m t + rw [abs_mul, abs_of_nonneg (m.nonneg t)] + have h : |v t| ≤ v t ^ 2 + 1 := by nlinarith [sq_nonneg (|v t| - 1), sq_abs (v t)] + nlinarith [mul_le_mul_of_nonneg_left h (m.nonneg t)] + +lemma integral_pathControlCost (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hc : controlCost P m v < ∞) : + (∫ ω, (pathControlCost m v ω).toReal ∂P) = (controlCost P m v).toReal := + integral_toReal (pathControlCost_aemeasurable P m hv) + (ae_lt_top' (pathControlCost_aemeasurable P m hv) hc.ne) + +lemma clipping_drift_gain (m : Trial) {L : ℝ} (hL : 0 ≤ L) + {v : Time → BrownianPath → ℝ} (ω : BrownianPath) + (hv : Measurable (fun t => v t ω)) (hc : pathControlCost m v ω < ∞) : + L * |controlDrift m v ω - controlDrift m (clipControl L v) ω| ≤ + ((pathControlCost m v ω).toReal - (pathControlCost m (clipControl L v) ω).toReal)/2 := by + have hw : Measurable (fun t => clipControl L v t ω) := measurable_const.max (measurable_const.min hv) + have hcv := weightedTime_integrable m hv hc + have hcw := weightedTime_integrable m hw ((pathControlCost_clip_le m hL v ω).trans_lt hc) + have hev : (∫ t, m t * v t ω ^ 2 ∂timeLaw) = (pathControlCost m v ω).toReal := + integral_eq_lintegral_of_nonneg_ae + (Filter.Eventually.of_forall fun t => mul_nonneg (m.nonneg t) (sq_nonneg _)) + hcv.1.aestronglyMeasurable + have hew : (∫ t, m t * clipControl L v t ω ^ 2 ∂timeLaw) = + (pathControlCost m (clipControl L v) ω).toReal := + integral_eq_lintegral_of_nonneg_ae + (Filter.Eventually.of_forall fun t => mul_nonneg (m.nonneg t) (sq_nonneg _)) + hcw.1.aestronglyMeasurable + unfold controlDrift + rw [← integral_sub hcv.2 hcw.2] + calc + _ ≤ L * ∫ t, |m t * v t ω - m t * clipControl L v t ω| ∂timeLaw := + mul_le_mul_of_nonneg_left abs_integral_le_integral_abs hL + _ = ∫ t, L * |m t * v t ω - m t * clipControl L v t ω| ∂timeLaw := + (integral_const_mul _ _).symm + _ ≤ ∫ t, (m t * v t ω ^ 2 - m t * clipControl L v t ω ^ 2)/2 ∂timeLaw := by + apply integral_mono ((hcv.2.sub hcw.2).abs.const_mul L) ((hcv.1.sub hcw.1).div_const 2) + intro t + dsimp only [Pi.sub_apply] + rw [← mul_sub, abs_mul, abs_of_nonneg (m.nonneg t)] + have h := mul_le_mul_of_nonneg_left (clip_cost_gain hL (v t ω)) (m.nonneg t) + dsimp [clipControl] + nlinarith + _ = _ := by rw [integral_div, integral_sub hcv.1 hcw.1, hev, hew] + +lemma controlPayoff_le_clipControl (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) (L : ℝ≥0) (hf : LipschitzWith L f) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hc : controlCost P m v < ∞) : + controlPayoff P f m v ≤ controlPayoff P f m (clipControl L v) := by + let w := clipControl L v + have hw : Progressive P w := progressive_clipControl P hv L + have hcw : controlCost P m w < ∞ := (controlCost_clip_le P m L.coe_nonneg v).trans_lt hc + have hpv := pathControlCost_aemeasurable P m hv + have hpw := pathControlCost_aemeasurable P m hw + have hcvI := integrable_toReal_of_lintegral_ne_top hpv hc.ne + have hcwI := integrable_toReal_of_lintegral_ne_top hpw hcw.ne + have hineq : (∫ ω, (f (brownianEval 1 ω + controlDrift m v ω) - + f (brownianEval 1 ω + controlDrift m w ω)) ∂P) ≤ + (∫ ω, ((pathControlCost m v ω).toReal - (pathControlCost m w ω).toReal)/2 ∂P) := by + apply integral_mono_ae ((controlReward_integrable P f m hv).sub (controlReward_integrable P f m hw)) + ((hcvI.sub hcwI).div_const 2) + filter_upwards [ae_lt_top' hpv hc.ne] with ω hω + have hLip := hf.dist_le_mul (brownianEval 1 ω + controlDrift m v ω) + (brownianEval 1 ω + controlDrift m w ω) + rw [Real.dist_eq, Real.dist_eq, add_sub_add_left_eq_sub] at hLip + exact (le_abs_self _).trans (hLip.trans + (clipping_drift_gain m L.coe_nonneg ω (progressive_time_measurable P hv ω) hω)) + rw [integral_sub (controlReward_integrable P f m hv) (controlReward_integrable P f m hw), + integral_div, integral_sub hcvI hcwI, integral_pathControlCost P m hv hc, + integral_pathControlCost P m hw hcw] at hineq + unfold controlPayoff + change _ ≤ _ + dsimp only [controlDrift, w] at hineq + linarith + +lemma controlValue_le_of_bounded_controls (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) (L : ℝ≥0) (hf : LipschitzWith L f) (b : ℝ) + (hb : ∀ v : Time → BrownianPath → ℝ, Progressive P v → controlCost P m v < ∞ → + (∀ t ω, |v t ω| ≤ L) → controlPayoff P f m v ≤ b) : controlValue P f m ≤ b := by + apply csSup_le (controlPayoffs_nonempty P f m) + rintro a ⟨v, hv, hc, rfl⟩ + exact (controlPayoff_le_clipControl P f m L hf hv hc).trans + (hb (clipControl L v) (progressive_clipControl P hv L) + ((controlCost_clip_le P m L.coe_nonneg v).trans_lt hc) + (fun t ω => abs_clip_le L.coe_nonneg (v t ω))) + +lemma pathControlCost_le_bound (m : Trial) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : ∀ t ω, |v t ω| ≤ L) (ω : BrownianPath) : + pathControlCost m v ω ≤ ENNReal.ofReal ((L : ℝ)^2) := by + calc + _ ≤ ∫⁻ _t : Time, ENNReal.ofReal ((L : ℝ)^2) ∂timeLaw := by + apply lintegral_mono + intro t + apply ENNReal.ofReal_le_ofReal + have hx : v t ω ^ 2 ≤ (L : ℝ)^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg (v t ω)) L.coe_nonneg).mpr (hv t ω) + exact (mul_le_mul_of_nonneg_right (m.le_one t) (sq_nonneg _)).trans (by simpa using hx) + _ = _ := by simp + +lemma controlCost_le_bound (P : Measure BrownianPath) [IsProbabilityMeasure P] + (m : Trial) (L : ℝ≥0) {v : Time → BrownianPath → ℝ} (hv : ∀ t ω, |v t ω| ≤ L) : + controlCost P m v ≤ ENNReal.ofReal ((L : ℝ)^2) := by + calc + _ ≤ ∫⁻ _ω : BrownianPath, ENNReal.ofReal ((L : ℝ)^2) ∂P := + lintegral_mono fun ω => pathControlCost_le_bound m L hv ω + _ = _ := by simp + +lemma trial_abs_sub_integrable (m n : Trial) : + Integrable (fun t => |m t - n t|) timeLaw := by + apply (integrable_const (2 : ℝ)).mono' + ((m.measurable.sub n.measurable).abs.aestronglyMeasurable) + refine Filter.Eventually.of_forall fun t => ?_ + rw [Real.norm_eq_abs, abs_abs] + exact (abs_sub _ _).trans (by rw [abs_of_nonneg (m.nonneg t), abs_of_nonneg (n.nonneg t)]; linarith [m.le_one t,n.le_one t]) + +lemma bounded_drift_trial_diff (m n : Trial) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : ∀ t ω, |v t ω| ≤ L) (ω : BrownianPath) + (hmv : Measurable (fun t => v t ω)) : + |controlDrift m v ω - controlDrift n v ω| ≤ (L : ℝ) * ∫ t, |m t - n t| ∂timeLaw := by + have hm := weightedTime_integrable m hmv ((pathControlCost_le_bound m L hv ω).trans_lt (by finiteness)) + have hn := weightedTime_integrable n hmv ((pathControlCost_le_bound n L hv ω).trans_lt (by finiteness)) + rw [controlDrift, controlDrift, ← integral_sub hm.2 hn.2] + calc + _ ≤ ∫ t, |m t * v t ω - n t * v t ω| ∂timeLaw := abs_integral_le_integral_abs + _ ≤ ∫ t, (L : ℝ) * |m t - n t| ∂timeLaw := by + apply integral_mono (hm.2.sub hn.2).abs ((trial_abs_sub_integrable m n).const_mul L) + intro t + dsimp only [Pi.sub_apply] + rw [← sub_mul, abs_mul] + nlinarith [mul_le_mul_of_nonneg_left (hv t ω) (abs_nonneg (m t - n t))] + _ = _ := integral_const_mul _ _ + +lemma bounded_pathCost_trial_diff (m n : Trial) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : ∀ t ω, |v t ω| ≤ L) (ω : BrownianPath) + (hmv : Measurable (fun t => v t ω)) : + |(pathControlCost m v ω).toReal - (pathControlCost n v ω).toReal| ≤ + (L : ℝ)^2 * ∫ t, |m t - n t| ∂timeLaw := by + have hm := weightedTime_integrable m hmv ((pathControlCost_le_bound m L hv ω).trans_lt (by finiteness)) + have hn := weightedTime_integrable n hmv ((pathControlCost_le_bound n L hv ω).trans_lt (by finiteness)) + have hem : (pathControlCost m v ω).toReal = ∫ t, m t * v t ω ^ 2 ∂timeLaw := + (integral_eq_lintegral_of_nonneg_ae + (Filter.Eventually.of_forall fun t => mul_nonneg (m.nonneg t) (sq_nonneg _)) + hm.1.aestronglyMeasurable).symm + have hen : (pathControlCost n v ω).toReal = ∫ t, n t * v t ω ^ 2 ∂timeLaw := + (integral_eq_lintegral_of_nonneg_ae + (Filter.Eventually.of_forall fun t => mul_nonneg (n.nonneg t) (sq_nonneg _)) + hn.1.aestronglyMeasurable).symm + rw [hem, hen, ← integral_sub hm.1 hn.1] + calc + _ ≤ ∫ t, |m t * v t ω ^ 2 - n t * v t ω ^ 2| ∂timeLaw := abs_integral_le_integral_abs + _ ≤ ∫ t, (L : ℝ)^2 * |m t - n t| ∂timeLaw := by + apply integral_mono (hm.1.sub hn.1).abs ((trial_abs_sub_integrable m n).const_mul ((L : ℝ)^2)) + intro t + dsimp only [Pi.sub_apply] + rw [← sub_mul, abs_mul, abs_of_nonneg (sq_nonneg (v t ω))] + have hx : v t ω ^ 2 ≤ (L : ℝ)^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg (v t ω)) L.coe_nonneg).mpr (hv t ω) + nlinarith [mul_le_mul_of_nonneg_left hx (abs_nonneg (m t - n t))] + _ = _ := integral_const_mul _ _ + +lemma controlPayoff_trial_diff_bound (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m n : Trial) (L : ℝ≥0) (hf : LipschitzWith L f) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hbound : ∀ t ω, |v t ω| ≤ L) : + |controlPayoff P f m v - controlPayoff P f n v| ≤ + (3/2 : ℝ) * (L : ℝ)^2 * ∫ t, |m t-n t| ∂timeLaw := by + let D := ∫ t, |m t-n t| ∂timeLaw + have hcm : controlCost P m v < ∞ := (controlCost_le_bound P m L hbound).trans_lt (by finiteness) + have hcn : controlCost P n v < ∞ := (controlCost_le_bound P n L hbound).trans_lt (by finiteness) + have hm := controlReward_integrable P f m hv + have hn := controlReward_integrable P f n hv + have hrew : |(∫ ω, f (brownianEval 1 ω + controlDrift m v ω) ∂P) - + (∫ ω, f (brownianEval 1 ω + controlDrift n v ω) ∂P)| ≤ (L : ℝ)^2 * D := by + rw [← integral_sub hm hn] + calc + _ ≤ ∫ ω, |f (brownianEval 1 ω + controlDrift m v ω) - + f (brownianEval 1 ω + controlDrift n v ω)| ∂P := abs_integral_le_integral_abs + _ ≤ ∫ _ω : BrownianPath, (L : ℝ)^2 * D ∂P := by + apply integral_mono (hm.sub hn).abs (integrable_const _) + intro ω + have hh := hf.dist_le_mul (brownianEval 1 ω + controlDrift m v ω) + (brownianEval 1 ω + controlDrift n v ω) + rw [Real.dist_eq, Real.dist_eq, add_sub_add_left_eq_sub] at hh + have hb := mul_le_mul_of_nonneg_left + (bounded_drift_trial_diff m n L hbound ω (progressive_time_measurable P hv ω)) L.coe_nonneg + exact hh.trans (by dsimp only [D]; nlinarith [hb]) + _ = _ := by simp + have hcost : |(controlCost P m v).toReal - (controlCost P n v).toReal| ≤ (L : ℝ)^2 * D := by + rw [← integral_pathControlCost P m hv hcm, ← integral_pathControlCost P n hv hcn, + ← integral_sub (integrable_toReal_of_lintegral_ne_top (pathControlCost_aemeasurable P m hv) hcm.ne) + (integrable_toReal_of_lintegral_ne_top (pathControlCost_aemeasurable P n hv) hcn.ne)] + calc + _ ≤ ∫ ω, |(pathControlCost m v ω).toReal - (pathControlCost n v ω).toReal| ∂P := + abs_integral_le_integral_abs + _ ≤ ∫ _ω : BrownianPath, (L : ℝ)^2 * D ∂P := by + apply integral_mono + ((integrable_toReal_of_lintegral_ne_top (pathControlCost_aemeasurable P m hv) hcm.ne).sub + (integrable_toReal_of_lintegral_ne_top (pathControlCost_aemeasurable P n hv) hcn.ne)).abs + (integrable_const _) + intro ω + exact bounded_pathCost_trial_diff m n L hbound ω (progressive_time_measurable P hv ω) + _ = _ := by simp + apply abs_le.mpr + obtain ⟨hrewlo,hrewhi⟩ := abs_le.mp hrew + obtain ⟨hcostlo,hcosthi⟩ := abs_le.mp hcost + dsimp only [controlPayoff, controlDrift] at * + constructor <;> linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Pressure/VectorPartition.lean b/lean/OAI/Probability/Perceptron/Pressure/VectorPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..0df68b4151cd04dc4332642fe6bfdfd2619fd49b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Pressure/VectorPartition.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.GaussianRotation + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +namespace SphericalPerceptronFreeEnergy +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +variable {S : Type*} [MeasurableSpace S] (ρ : Measure S) [IsProbabilityMeasure ρ] + {W : S → ℝ} {V : S → StrongDual ℝ E} + +def vectorPartition (W : S → ℝ) (V : S → StrongDual ℝ E) (x : E) : ℝ := + ∫ s, Real.exp (W s + V s x) ∂ρ + +def vectorLogPartition (W : S → ℝ) (V : S → StrongDual ℝ E) (x : E) : ℝ := + Real.log (vectorPartition ρ W V x) + +def vectorLogDerivative (W : S → ℝ) (V : S → StrongDual ℝ E) (x : E) : StrongDual ℝ E := + (vectorPartition ρ W V x)⁻¹ • (∫ s, Real.exp (W s + V s x) • V s ∂ρ) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [MeasurableSpace S] in +lemma vectorEnergy_bound {K C : ℝ} (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) + (x : E) (s : S) : |W s + V s x| ≤ K+C*‖x‖ := by + apply (abs_add_le _ _).trans + apply add_le_add (hW s) + exact (ContinuousLinearMap.le_opNorm _ _).trans + (mul_le_mul_of_nonneg_right (hV s) (norm_nonneg x)) + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorPartition_integrable (hWm : Measurable W) (hVm : Measurable V) + {K C : ℝ} (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) (x : E) : + Integrable (fun s => Real.exp (W s + V s x)) ρ := by + refine Integrable.of_bound (by fun_prop) (Real.exp (K+C*‖x‖)) (ae_of_all _ fun s => ?_) + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans (vectorEnergy_bound hW hV x s)) + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorPartition_pos (hWm : Measurable W) (hVm : Measurable V) + {K C : ℝ} (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) (x : E) : + 0 < vectorPartition ρ W V x := by + apply integral_pos_iff_support_of_nonneg (fun s => (Real.exp_pos _).le) + (vectorPartition_integrable ρ hWm hVm hW hV x) |>.mpr + simp [Function.support,Real.exp_ne_zero] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorPartition_hasFDerivAt (hWm : Measurable W) (hVm : Measurable V) + {K C : ℝ} (hC : 0 ≤ C) (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) (x : E) : + HasFDerivAt (vectorPartition ρ W V) (∫ s, Real.exp (W s+V s x) • V s ∂ρ) x := by + apply hasFDerivAt_integral_of_dominated_of_fderiv_le + (s := Metric.ball x 1) (bound := fun _ => Real.exp (K+C*(‖x‖+1))*C) + (F' := fun y s => Real.exp (W s+V s y) • V s) (Metric.ball_mem_nhds x zero_lt_one) + (Filter.Eventually.of_forall fun y => by fun_prop) + (vectorPartition_integrable ρ hWm hVm hW hV x) (by fun_prop) + (ae_of_all _ fun s y hy => ?_) (integrable_const _) (ae_of_all _ fun s y _ => ?_) + · have hy' : ‖y‖ ≤ ‖x‖+1 := by + have hh : ‖y-x‖ < 1 := by simpa only [Metric.mem_ball,dist_eq_norm] using hy + have hn := norm_add_le (y-x) x + rw [sub_add_cancel] at hn + linarith + rw [norm_smul,Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + apply mul_le_mul _ (hV _) (norm_nonneg _) (Real.exp_pos _).le + apply Real.exp_le_exp.mpr + exact ((le_abs_self _).trans (vectorEnergy_bound hW hV y s)).trans + (add_le_add le_rfl (mul_le_mul_of_nonneg_left hy' hC)) + · exact (((V s).hasFDerivAt).const_add (W s)).exp + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorLogPartition_hasFDerivAt (hWm : Measurable W) (hVm : Measurable V) + {K C : ℝ} (hC : 0 ≤ C) (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) (x : E) : + HasFDerivAt (vectorLogPartition ρ W V) (vectorLogDerivative ρ W V x) x := + (vectorPartition_hasFDerivAt ρ hWm hVm hC hW hV x).log + (vectorPartition_pos ρ hWm hVm hW hV x).ne' + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorLogDerivative_bound (hWm : Measurable W) (hVm : Measurable V) + {K C : ℝ} (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) (x : E) : + ‖vectorLogDerivative ρ W V x‖ ≤ C := by + have hp := vectorPartition_pos ρ hWm hVm hW hV x + have hn : ‖∫ s, Real.exp (W s+V s x) • V s ∂ρ‖ ≤ C*vectorPartition ρ W V x := by + have hh := norm_integral_le_of_norm_le (f := fun s => Real.exp (W s+V s x) • V s) + ((vectorPartition_integrable ρ hWm hVm hW hV x).const_mul C) + (ae_of_all _ fun s => by + rw [norm_smul,Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact (mul_le_mul_of_nonneg_left (hV s) (Real.exp_pos _).le).trans_eq (mul_comm ..)) + simpa only [integral_const_mul,vectorPartition] using hh + rw [vectorLogDerivative,norm_smul,Real.norm_eq_abs,abs_of_pos (inv_pos.mpr hp)] + calc + _ ≤ (vectorPartition ρ W V x)⁻¹*(C*vectorPartition ρ W V x) := + mul_le_mul_of_nonneg_left hn (inv_nonneg.mpr hp.le) + _ = C := by field_simp + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorLogDerivative_continuous (hWm : Measurable W) (hVm : Measurable V) + {K C : ℝ} (hC : 0 ≤ C) (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) : + Continuous (vectorLogDerivative ρ W V) := by + apply continuous_iff_continuousAt.mpr + intro x + have hp := (vectorPartition_hasFDerivAt ρ hWm hVm hC hW hV x).continuousAt + apply (hp.inv₀ (vectorPartition_pos ρ hWm hVm hW hV x).ne').smul + apply continuousAt_of_dominated (bound := fun _ => Real.exp (K+C*(‖x‖+1))*C) + · exact Filter.Eventually.of_forall fun y => by fun_prop + · filter_upwards [Metric.ball_mem_nhds x zero_lt_one] with y hy + exact ae_of_all _ fun s => by + have hy' : ‖y‖ ≤ ‖x‖+1 := by + have hh : ‖y-x‖ < 1 := by simpa only [Metric.mem_ball,dist_eq_norm] using hy + have hn := norm_add_le (y-x) x + rw [sub_add_cancel] at hn + linarith + rw [norm_smul,Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + apply mul_le_mul _ (hV _) (norm_nonneg _) (Real.exp_pos _).le + apply Real.exp_le_exp.mpr + exact ((le_abs_self _).trans (vectorEnergy_bound hW hV y s)).trans + (add_le_add le_rfl (mul_le_mul_of_nonneg_left hy' hC)) + · exact integrable_const _ + · exact ae_of_all _ fun s => by fun_prop + +lemma vectorLogPartition_gaussian_variance (hWm : Measurable W) (hVm : Measurable V) + {K C : ℝ} (hC : 0 ≤ C) (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) : + variance (vectorLogPartition ρ W V) (stdGaussian E) ≤ (Real.pi^2/8)*C^2 := + stdGaussian_variance_le_of_fderiv_bound + (vectorLogPartition_hasFDerivAt ρ hWm hVm hC hW hV) + (vectorLogDerivative_continuous ρ hWm hVm hC hW hV) hC + (vectorLogDerivative_bound ρ hWm hVm hW hV) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/CoordinateBoxBound.lean b/lean/OAI/Probability/Perceptron/Sphere/CoordinateBoxBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..88599802b3a4e01e39569cdc4f38f6913d0486af --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/CoordinateBoxBound.lean @@ -0,0 +1,88 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open Set Filter +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma box_coordinate_comparison {I : Type*} [Fintype I] [DecidableEq I] + {F : (I → ℝ) → ℝ} {L : I → ℝ} {a b : ℝ} + (hderiv : ∀ u : I → ℝ, (∀ i, u i ∈ Icc a b) → ∀ j, + ∃ D : ℝ, HasDerivAt (fun r => F (u+Pi.single j r)) D 0 ∧ |D| ≤ L j) + {u : I → ℝ} (hu : ∀ i, u i ∈ Icc a b) (j : I) + {x y : ℝ} (hx : x ∈ Icc a b) (hy : y ∈ Icc a b) : + |F (Function.update u j y)-F (Function.update u j x)| ≤ L j*|y-x| := by + have hd (s : ℝ) (hs : s ∈ Icc a b) : + ∃ D : ℝ, HasDerivAt (fun r => F (Function.update u j r)) D s ∧ |D| ≤ L j := by + have huw : ∀ i, Function.update u j s i ∈ Icc a b := by + intro i + by_cases hi : i=j + · subst i; simpa using hs + · simpa [Function.update_of_ne hi] using hu i + obtain ⟨D,hD,hDb⟩ := hderiv (Function.update u j s) huw j + refine ⟨D,?_,hDb⟩ + have hsub : HasDerivAt (fun r : ℝ => r-s) 1 s := (hasDerivAt_id s).sub_const s + have hc := hD.comp_of_eq s hsub (sub_self s).symm + simp only [mul_one] at hc + apply hc.congr_of_eventuallyEq + apply Filter.Eventually.of_forall + intro r + change F (Function.update u j r) = F (Function.update u j s + Pi.single j (r-s)) + congr 1 + funext i + by_cases hi : i=j + · subst i + simp + · simp [Function.update_of_ne hi,Pi.single_eq_of_ne hi] + let D := fun s => if hs : s ∈ Icc a b then (hd s hs).choose else 0 + have hD (s) (hs : s ∈ Icc a b) : + HasDerivWithinAt (fun r => F (Function.update u j r)) (D s) (Icc a b) s := by + dsimp [D] + rw [dite_eq_left hs] + exact (hd s hs).choose_spec.1.hasDerivWithinAt + have hDb (s) (hs : s ∈ Icc a b) : ‖D s‖ ≤ L j := by + dsimp [D] + rw [dite_eq_left hs] + exact (hd s hs).choose_spec.2 + simpa only [Real.norm_eq_abs] using + Convex.norm_image_sub_le_of_norm_hasDerivWithin_le hD hDb (convex_Icc a b) hx hy + +lemma box_sum_coordinate_comparison {I : Type*} [Fintype I] [DecidableEq I] + {F : (I → ℝ) → ℝ} {L : I → ℝ} {a b : ℝ} + (hderiv : ∀ u : I → ℝ, (∀ i, u i ∈ Icc a b) → ∀ j, + ∃ D : ℝ, HasDerivAt (fun r => F (u+Pi.single j r)) D 0 ∧ |D| ≤ L j) + {u v : I → ℝ} (hu : ∀ i, u i ∈ Icc a b) (hv : ∀ i, v i ∈ Icc a b) : + |F v-F u| ≤ ∑ j, L j*|v j-u j| := by + let w := fun s : Finset I => fun i => if i ∈ s then v i else u i + have hw (s : Finset I) (i : I) : w s i ∈ Icc a b := by + dsimp [w] + split_ifs + · exact hv i + · exact hu i + have hh (s : Finset I) : |F (w s)-F u| ≤ ∑ j ∈ s, L j*|v j-u j| := by + induction s using Finset.induction_on with + | empty => simp [w] + | @insert j s hj ih => + have h0 : Function.update (w s) j (u j)=w s := by + funext i + by_cases hi : i=j + · subst i; simp [w,hj] + · simp [Function.update_of_ne hi] + have h1 : Function.update (w s) j (v j)=w (insert j s) := by + funext i + by_cases hi : i=j + · subst i; simp [w] + · simp [w,hi] + have hc := box_coordinate_comparison hderiv (hw s) j (hu j) (hv j) + rw [h0,h1] at hc + rw [Finset.sum_insert hj] + exact (abs_sub_le (F (w (insert j s))) (F (w s)) (F u)).trans (add_le_add hc ih) + simpa [w] using hh Finset.univ + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/CoordinateContact.lean b/lean/OAI/Probability/Perceptron/Sphere/CoordinateContact.lean new file mode 100644 index 0000000000000000000000000000000000000000..0939d0f1662bcdd1766d39a4a39d7d16f528bd22 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/CoordinateContact.lean @@ -0,0 +1,118 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open Set Filter +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma box_comparison_continuous {I : Type*} [Fintype I] + {F : (I → ℝ) → ℝ} {L : I → ℝ} (hL : ∀ i, 0 ≤ L i) {a b : ℝ} + (hcomp : ∀ u ∈ Icc (fun _ : I => a) (fun _ => b), + ∀ v ∈ Icc (fun _ : I => a) (fun _ => b), + |F v-F u| ≤ ∑ i, L i*|v i-u i|) : + ContinuousOn F (Icc (fun _ : I => a) (fun _ => b)) := by + have hsum : 0 ≤ ∑ i, L i := Finset.sum_nonneg fun i _ => hL i + apply (LipschitzOnWith.of_dist_le_mul (K := ⟨∑ i, L i,hsum⟩) ?_).continuousOn + intro u hu v hv + change |F u-F v| ≤ (∑ i, L i)*‖u-v‖ + apply (hcomp v hv u hu).trans + calc + _ ≤ ∑ i, L i*‖u-v‖ := by + apply Finset.sum_le_sum + intro i _ + apply mul_le_mul_of_nonneg_left _ (hL i) + simpa only [Pi.sub_apply,Real.norm_eq_abs] using norm_le_pi_norm (u-v) i + _ = _ := by rw [Finset.sum_mul] + +def quadraticBoxPenalty {I : Type*} [Fintype I] (c u : I → ℝ) : ℝ := + ∑ i, c i*(u i-3/2)^2 + +lemma quadraticBoxPenalty_continuous {I : Type*} [Fintype I] (c : I → ℝ) : + Continuous (quadraticBoxPenalty c) := by + unfold quadraticBoxPenalty + fun_prop + +lemma exists_quadratic_box_min {I : Type*} [Fintype I] (F : (I → ℝ) → ℝ) (c : I → ℝ) + (hF : ContinuousOn F (Icc (fun _ : I => 1) (fun _ => 2))) : + ∃ u ∈ Icc (fun _ : I => 1) (fun _ => 2), + IsMinOn (fun v => quadraticBoxPenalty c v-F v) + (Icc (fun _ : I => 1) (fun _ => 2)) u := by + refine isCompact_Icc.exists_isMinOn ?_ ((quadraticBoxPenalty_continuous c).continuousOn.sub hF) + exact ⟨fun _ => 3/2,by constructor <;> intro i <;> norm_num⟩ + +lemma quadratic_box_min_penalty {I : Type*} [Fintype I] + {F : (I → ℝ) → ℝ} {c u : I → ℝ} {ε : ℝ} + (hmin : IsMinOn (fun v => quadraticBoxPenalty c v-F v) + (Icc (fun _ : I => 1) (fun _ => 2)) u) + (hcomp : |F u-F (fun _ => 3/2)| ≤ ε) : + quadraticBoxPenalty c u ≤ ε := by + have hm : quadraticBoxPenalty c u-F u ≤ quadraticBoxPenalty c (fun _ => 3/2)-F (fun _ => 3/2) := + hmin (show (fun _ : I => (3/2:ℝ)) ∈ Icc (fun _ => 1) (fun _ => 2) from + by constructor <;> intro i <;> norm_num) + have hc : quadraticBoxPenalty c (fun _ : I => 3/2)=0 := by simp [quadraticBoxPenalty] + rw [hc] at hm + linarith [le_abs_self (F u-F (fun _ => 3/2))] + +lemma quadratic_box_min_coord {I : Type*} [Fintype I] + {F : (I → ℝ) → ℝ} {c u : I → ℝ} {ε : ℝ} (hc : ∀ i, 0 ≤ c i) + (hmin : IsMinOn (fun v => quadraticBoxPenalty c v-F v) + (Icc (fun _ : I => 1) (fun _ => 2)) u) + (hcomp : |F u-F (fun _ => 3/2)| ≤ ε) (j : I) : + c j*(u j-3/2)^2 ≤ ε := by + have hj : c j*(u j-3/2)^2 ≤ quadraticBoxPenalty c u := + Finset.single_le_sum (s := Finset.univ) (f := fun i => c i*(u i-3/2)^2) + (fun i _ => mul_nonneg (hc i) (sq_nonneg _)) (Finset.mem_univ j) + exact hj.trans (quadratic_box_min_penalty hmin hcomp) + +lemma quadraticBoxPenalty_single {I : Type*} [Fintype I] [DecidableEq I] + (c u : I → ℝ) (j : I) (r : ℝ) : + quadraticBoxPenalty c (u+Pi.single j r) = quadraticBoxPenalty c u+ + c j*(r^2+2*(u j-3/2)*r) := by + unfold quadraticBoxPenalty + calc + _ = ∑ i, (c i*(u i-3/2)^2+if i=j then c j*(r^2+2*(u j-3/2)*r) else 0) := by + apply Finset.sum_congr rfl + intro i _ + by_cases hij : i=j + · subst i; simp; ring + · simp [hij] + _ = _ := by rw [Finset.sum_add_distrib]; simp + +lemma quadratic_box_min_direction {I : Type*} [Fintype I] [DecidableEq I] + {F : (I → ℝ) → ℝ} {c u : I → ℝ} + (hmin : IsMinOn (fun v => quadraticBoxPenalty c v-F v) + (Icc (fun _ : I => 1) (fun _ => 2)) u) + (j : I) (r : ℝ) (hr : u+Pi.single j r ∈ Icc (fun _ : I => 1) (fun _ => 2)) : + c j*(0-(3/2-u j))^2-F u ≤ + c j*(r-(3/2-u j))^2-F (u+Pi.single j r) := by + have hm : quadraticBoxPenalty c u-F u ≤ quadraticBoxPenalty c (u+Pi.single j r)-F (u+Pi.single j r) := hmin hr + rw [quadraticBoxPenalty_single] at hm + nlinarith + +lemma quadratic_box_min_local_direction {I : Type*} [Fintype I] [DecidableEq I] + {F : (I → ℝ) → ℝ} {c u : I → ℝ} + (hu : u ∈ Icc (fun _ : I => 1) (fun _ => 2)) + (hmin : IsMinOn (fun v => quadraticBoxPenalty c v-F v) + (Icc (fun _ : I => 1) (fun _ => 2)) u) + (j : I) (hj : u j ∈ Ioo 1 2) : + IsLocalMin (fun r => c j*(r-(3/2-u j))^2-F (u+Pi.single j r)) 0 := by + have hnb : Icc (1-u j) (2-u j) ∈ 𝓝 (0:ℝ) := Icc_mem_nhds (by linarith [hj.1]) (by linarith [hj.2]) + apply Filter.Eventually.mono hnb + intro r hr + have hub : u+Pi.single j r ∈ Icc (fun _ : I => 1) (fun _ => 2) := by + constructor <;> intro i + · by_cases hi : i=j + · subst i; simp only [Pi.add_apply,Pi.single_eq_same]; linarith [hr.1] + · simpa [Pi.single_eq_of_ne hi] using hu.1 i + · by_cases hi : i=j + · subst i; simp only [Pi.add_apply,Pi.single_eq_same]; linarith [hr.2] + · simpa [Pi.single_eq_of_ne hi] using hu.2 i + simpa using quadratic_box_min_direction hmin j r hub + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/GaussianAffineCoordinate.lean b/lean/OAI/Probability/Perceptron/Sphere/GaussianAffineCoordinate.lean new file mode 100644 index 0000000000000000000000000000000000000000..690452466c9657fbfa6aaef8f2b4548b8165ebda --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/GaussianAffineCoordinate.lean @@ -0,0 +1,298 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianMarkRecursion +import OAI.Probability.Perceptron.Variational.TensorFeatures + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +variable {I : Type} [Fintype I] [DecidableEq I] + +def eraseMarkCoordinate (i : I) (x : EuclideanSpace ℝ I) : EuclideanSpace ℝ I := + WithLp.toLp 2 (Function.update (fun j => x j) i 0) + +omit [Fintype I] in +lemma eraseMarkCoordinate_continuous (i : I) : Continuous (eraseMarkCoordinate i) := by + unfold eraseMarkCoordinate + fun_prop + +lemma pi_coordinate_rest_indep (μ : I→Measure ℝ) [∀ i, IsProbabilityMeasure (μ i)] (i : I) : + IndepFun (fun x : I→ℝ => Function.update x i 0) (fun x => x i) (Measure.pi μ) := by + have hi : iIndepFun (fun i (x : I→ℝ) => x i) (Measure.pi μ) := + iIndepFun_pi (fun _ => measurable_id.aemeasurable) + have hh := hi.indepFun_finset (Finset.univ.erase i) {i} (by simp) (fun j => measurable_pi_apply j) + let R : ({j // j∈Finset.univ.erase i}→ℝ)→I→ℝ := fun x j => + if hj : j=i then 0 else x ⟨j,by simp [hj]⟩ + have hR : Measurable R := by + apply Measurable.of_eval + intro j + dsimp [R] + split_ifs <;> fun_prop + have hr := hh.comp hR (measurable_pi_apply (⟨i,by simp⟩ : ({i}:Finset I))) + convert hr using 1 + · funext x j + by_cases hj : j=i + · subst j + simp [R] + · simp [R,hj] + · rfl + +lemma gaussian_coordinate_rest_indep (i : I) : + IndepFun (eraseMarkCoordinate i) (fun x : EuclideanSpace ℝ I => x i) + (stdGaussian (EuclideanSpace ℝ I)) := by + have hp := (pi_coordinate_rest_indep (fun _ => gaussianReal 0 1) i).comp + (by fun_prop : Measurable (WithLp.toLp 2 : (I→ℝ)→EuclideanSpace ℝ I)) measurable_id + have he := (eraseMarkCoordinate_continuous i).measurable + have hx : Measurable (fun x : EuclideanSpace ℝ I => x i) := by fun_prop + have ht : Measurable (WithLp.toLp 2 : (I→ℝ)→EuclideanSpace ℝ I) := by fun_prop + apply (indepFun_iff_map_prod_eq_prod_map_map he.aemeasurable hx.aemeasurable).mpr + rw [← map_pi_eq_stdGaussian, + Measure.map_map (he.prodMk hx) ht, Measure.map_map he ht, Measure.map_map hx ht] + convert hp.map_prod_eq_prod_map_map + (ht.comp (Measurable.of_eval (fun coordinate => by fun_prop))).aemeasurable + (measurable_pi_apply i).aemeasurable using 1 <;> rfl + +omit [DecidableEq I] in +lemma stdGaussian_coordinate_law (i : I) : + (stdGaussian (EuclideanSpace ℝ I)).map (fun x => x i)=gaussianReal 0 1 := by + rw [← map_pi_eq_stdGaussian,Measure.map_map (by fun_prop) (by fun_prop)] + exact (measurePreserving_eval (fun _ => gaussianReal 0 1) i).map_eq + +omit [DecidableEq I] in +lemma gaussian_coordinate_cgf (i : I) (c t : ℝ) : + cgf (fun x : EuclideanSpace ℝ I => c*x i) (stdGaussian (EuclideanSpace ℝ I)) t= + c^2*t^2/2 := by + have he : cgf (fun x : EuclideanSpace ℝ I => c*x i) (stdGaussian (EuclideanSpace ℝ I)) t= + cgf (fun x : EuclideanSpace ℝ I => x i) (stdGaussian (EuclideanSpace ℝ I)) (t*c) := by + simp only [cgf,mgf,mul_assoc] + have hlaw : HasLaw (fun x : EuclideanSpace ℝ I => x i) (gaussianReal 0 1) + (stdGaussian (EuclideanSpace ℝ I)) := ⟨by fun_prop, stdGaussian_coordinate_law i⟩ + rw [he,cgf_gaussianReal hlaw] + simp only [zero_mul,NNReal.coe_one,one_mul] + ring + +omit [Fintype I] in +lemma eraseMarkCoordinate_add (i : I) (x y : EuclideanSpace ℝ I) : + eraseMarkCoordinate i (x+y)=eraseMarkCoordinate i x+eraseMarkCoordinate i y := by + ext j + by_cases hj : j=i + · subst j; simp [eraseMarkCoordinate] + · simp [eraseMarkCoordinate,Function.update_of_ne hj] + +lemma eraseMarkCoordinate_diagonal (i : I) (a : I→ℝ) (x : EuclideanSpace ℝ I) : + eraseMarkCoordinate i (diagonalMark a x)=diagonalMark a (eraseMarkCoordinate i x) := by + ext j + by_cases hj : j=i + · subst j; simp [eraseMarkCoordinate] + · simp [eraseMarkCoordinate,Function.update_of_ne hj] + +omit [DecidableEq I] in +lemma gaussian_coordinate_mean (i : I) : + (∫ x : EuclideanSpace ℝ I, x i ∂stdGaussian (EuclideanSpace ℝ I))=0 := by + have H := integral_map (μ := stdGaussian (EuclideanSpace ℝ I)) + (φ := fun x => x i) (f := id) (by fun_prop) (by fun_prop) + rw [stdGaussian_coordinate_law] at H + simpa using H.symm.trans integral_id_gaussianReal + +lemma all_exp_indep_add {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + {X Y : Ω→ℝ} (hi : IndepFun X Y μ) + (hX : Measurable X) (hY : Measurable Y) + (hXI : ∀ t:ℝ, Integrable (fun x => Real.exp (t*X x)) μ) + (hYI : ∀ t:ℝ, Integrable (fun x => Real.exp (t*Y x)) μ) : + ∀ t:ℝ, Integrable (fun x => Real.exp (t*(X x+Y x))) μ := by + intro t + convert + (hi.comp₀ hX.aemeasurable hY.aemeasurable + (by fun_prop : AEMeasurable (fun value:ℝ => Real.exp (t*value)) (μ.map X)) + (by fun_prop : AEMeasurable (fun value:ℝ => Real.exp (t*value)) (μ.map Y))).integrable_mul + (hXI t) (hYI t) using 1 + funext x + simp [mul_add,Real.exp_add,Function.comp_def] + +lemma entropicMean_indep_add {Ω : Type*} [MeasurableSpace Ω] {μ : Measure Ω} + [IsProbabilityMeasure μ] {X Y : Ω→ℝ} (hi : IndepFun X Y μ) + (hX : Measurable X) (hY : Measurable Y) + (hXI : ∀ t:ℝ, Integrable (fun x => Real.exp (t*X x)) μ) + (hYI : ∀ t:ℝ, Integrable (fun x => Real.exp (t*Y x)) μ) (b : ℝ) : + entropicMean μ b (fun x => X x+Y x)=entropicMean μ b X+entropicMean μ b Y := by + by_cases hb : b=0 + · subst b + rw [entropicMean_zero μ (all_exp_indep_add hi hX hY hXI hYI), + entropicMean_zero μ hXI,entropicMean_zero μ hYI] + exact integral_add (integrable_of_all_exp μ hXI) (integrable_of_all_exp μ hYI) + · rw [entropicMean_eq_div μ (all_exp_indep_add hi hX hY hXI hYI) hb, + entropicMean_eq_div μ hXI hb,entropicMean_eq_div μ hYI hb] + change cgf (X+Y) μ b / b = _ + rw [hi.cgf_add (hXI b) (hYI b),add_div] + +omit [DecidableEq I] in +lemma gaussian_coordinate_entropic (i : I) (c b : ℝ) : + entropicMean (stdGaussian (EuclideanSpace ℝ I)) b (fun x => c*x i)=b*c^2/2 := by + have hL := (c • EuclideanSpace.proj (𝕜 := ℝ) i).lipschitzWith + have hI : ∀ t:ℝ, Integrable (fun x : EuclideanSpace ℝ I => Real.exp (t*(c*x i))) + (stdGaussian (EuclideanSpace ℝ I)) := by + intro t + simpa using gaussian_integrable_exp_lipschitz _ hL t 1 (0:EuclideanSpace ℝ I) + by_cases hb : b=0 + · subst b + rw [entropicMean_zero _ hI,integral_const_mul,gaussian_coordinate_mean] + ring + · rw [entropicMean_eq_div _ hI hb,gaussian_coordinate_cgf] + field_simp + +lemma gaussianLinearEntropic_free_coordinate (i : I) (a : I→ℝ) + {f : EuclideanSpace ℝ I→ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (hfree : ∀ x, f (eraseMarkCoordinate i x)=f x) (b c : ℝ) (x : EuclideanSpace ℝ I) : + gaussianLinearEntropic (stdGaussian (EuclideanSpace ℝ I)) b (diagonalMark a) + (fun y => f y+c*y i) x= + gaussianLinearEntropic (stdGaussian (EuclideanSpace ℝ I)) b (diagonalMark a) f x+ + c*x i+b*c^2*(a i)^2/2 := by + let X := fun y : EuclideanSpace ℝ I => f (x+diagonalMark a y) + let Y := fun y : EuclideanSpace ℝ I => c*a i*y i + have hx : Measurable X := hf.continuous.measurable.comp (by fun_prop) + have hy : Measurable Y := by fun_prop + have hXI := fun t => gaussian_integrable_exp_linear_shift (stdGaussian (EuclideanSpace ℝ I)) hf (diagonalMark a) t x + have hYI : ∀ t:ℝ, Integrable (fun y => Real.exp (t*Y y)) (stdGaussian (EuclideanSpace ℝ I)) := by + intro t + simpa [Y] using gaussian_integrable_exp_lipschitz _ + ((c*a i) • EuclideanSpace.proj (𝕜 := ℝ) i).lipschitzWith t 1 (0:EuclideanSpace ℝ I) + have hi : IndepFun X Y (stdGaussian (EuclideanSpace ℝ I)) := by + have H := (gaussian_coordinate_rest_indep i).comp + (hf.continuous.measurable.comp (by fun_prop : Measurable (fun y => x+diagonalMark a y))) + (by fun_prop : Measurable (fun r:ℝ => c*a i*r)) + convert H using 1 + · funext y + dsimp [X,Function.comp_def] + rw [← hfree (x+diagonalMark a y),← hfree (x+diagonalMark a (eraseMarkCoordinate i y))] + congr 1 + rw [eraseMarkCoordinate_add,eraseMarkCoordinate_add, + eraseMarkCoordinate_diagonal,eraseMarkCoordinate_diagonal] + congr 2 + ext j + by_cases hj : j=i + · subst j; simp [eraseMarkCoordinate] + · simp [eraseMarkCoordinate,Function.update_of_ne hj] + · rfl + have he : (fun y => f (x+diagonalMark a y)+c*(x+diagonalMark a y) i)= + (fun y => (X y+Y y)+c*x i) := by + funext y + change f (x+diagonalMark a y)+c*(x i+a i*y i)=(f (x+diagonalMark a y)+c*a i*y i)+c*x i + ring + simp only [gaussianLinearEntropic,he] + rw [entropicMean_add_const _ (all_exp_indep_add hi hx hy hXI hYI), + entropicMean_indep_add hi hx hy hXI hYI] + dsimp only [Y] + rw [gaussian_coordinate_entropic] + dsimp only [X] + ring + +omit [DecidableEq I] in +lemma gaussianLinearEntropic_add_const (a : I→ℝ) + {f : EuclideanSpace ℝ I→ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) (b c : ℝ) : + gaussianLinearEntropic (stdGaussian (EuclideanSpace ℝ I)) b (diagonalMark a) + (fun y => f y+c)=fun x => + gaussianLinearEntropic (stdGaussian (EuclideanSpace ℝ I)) b (diagonalMark a) f x+c := by + funext x + exact entropicMean_add_const _ + (fun t => gaussian_integrable_exp_linear_shift _ hf (diagonalMark a) t x) b c + +lemma gaussianLinearEntropic_preserves_free (i : I) (a : I→ℝ) + {f : EuclideanSpace ℝ I→ℝ} (hfree : ∀ x, f (eraseMarkCoordinate i x)=f x) (b : ℝ) : + ∀ x, gaussianLinearEntropic (stdGaussian (EuclideanSpace ℝ I)) b (diagonalMark a) f + (eraseMarkCoordinate i x)= + gaussianLinearEntropic (stdGaussian (EuclideanSpace ℝ I)) b (diagonalMark a) f x := by + intro x + unfold gaussianLinearEntropic + congr 1 + funext y + rw [← hfree (eraseMarkCoordinate i x+diagonalMark a y),← hfree (x+diagonalMark a y)] + congr 1 + ext j + by_cases hj : j=i + · subst j; simp [eraseMarkCoordinate] + · simp [eraseMarkCoordinate,Function.update_of_ne hj] + +def diagonalWord (l : List (ℝ×(I→ℝ))) : List (ℝ×(EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I)) := + l.map (fun a => (a.1,diagonalMark a.2)) + +omit [DecidableEq I] in +lemma diagonalWord_nonneg (l : List (ℝ×(I→ℝ))) (hl : ∀ a∈l, 0≤a.1) : + ∀ a∈diagonalWord l, 0≤a.1 := by + intro a ha + obtain ⟨b,hb,rfl⟩ := List.mem_map.mp ha + exact hl b hb + +lemma gaussianLinearBackward_preserves_free (i : I) (l : List (ℝ×(I→ℝ))) + {f : EuclideanSpace ℝ I→ℝ} (hfree : ∀ x, f (eraseMarkCoordinate i x)=f x) : + ∀ x, gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ I)) (diagonalWord l) f + (eraseMarkCoordinate i x)= + gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ I)) (diagonalWord l) f x := by + induction l with + | nil => exact hfree + | cons a l ih => exact gaussianLinearEntropic_preserves_free i a.2 ih a.1 + +lemma gaussianLinearBackward_free_coordinate (i : I) (l : List (ℝ×(I→ℝ))) + (hl : ∀ a∈l, 0≤a.1) + {f : EuclideanSpace ℝ I→ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (hfree : ∀ x, f (eraseMarkCoordinate i x)=f x) (c : ℝ) : + gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ I)) (diagonalWord l) + (fun y => f y+c*y i)=fun x => + gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ I)) (diagonalWord l) f x+ + c*x i+c^2/2*(l.map (fun a => a.1*(a.2 i)^2)).sum := by + induction l with + | nil => funext x; simp [diagonalWord,gaussianLinearBackward] + | cons a l ih => + have hl' : ∀ a∈l, 0≤a.1 := fun b hb => hl b (List.mem_cons_of_mem a hb) + let g := gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ I)) (diagonalWord l) f + have hg := gaussianLinearBackward_lipschitz (stdGaussian (EuclideanSpace ℝ I)) hf + (diagonalWord l) (diagonalWord_nonneg l hl') + have hgfree := gaussianLinearBackward_preserves_free i l hfree + have hgc := hg.add ((c • EuclideanSpace.proj (𝕜 := ℝ) i).lipschitzWith) + change LipschitzWith _ (fun x => g x+c*x i) at hgc + simp only [diagonalWord,List.map_cons,gaussianLinearBackward] + change gaussianLinearEntropic _ a.1 (diagonalMark a.2) + (gaussianLinearBackward _ (diagonalWord l) (fun y => f y+c*y i)) = _ + rw [ih hl',gaussianLinearEntropic_add_const a.2 hgc] + funext x + rw [gaussianLinearEntropic_free_coordinate i a.2 hg hgfree] + simp only [List.sum_cons] + dsimp only [g,diagonalWord] + ring + +lemma gaussianLinearBackward_affine_root_mean (i : I) (l : List (ℝ×(I→ℝ))) + (hl : ∀ a∈l, 0≤a.1) (root : I→ℝ) + {f : EuclideanSpace ℝ I→ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (hfree : ∀ x, f (eraseMarkCoordinate i x)=f x) (c : ℝ) : + (∫ x, gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ I)) (diagonalWord l) + (fun y => f y+c*y i) (diagonalMark root x) ∂stdGaussian (EuclideanSpace ℝ I)) = + (∫ x, gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ I)) (diagonalWord l) f + (diagonalMark root x) ∂stdGaussian (EuclideanSpace ℝ I))+ + c^2/2*(l.map (fun a => a.1*(a.2 i)^2)).sum := by + have hG := gaussianLinearBackward_lipschitz (stdGaussian (EuclideanSpace ℝ I)) hf + (diagonalWord l) (diagonalWord_nonneg l hl) + have hGI := integrable_of_all_exp (stdGaussian (EuclideanSpace ℝ I)) + (fun t => gaussian_integrable_exp_linear_shift _ hG (diagonalMark root) t 0) + simp only [zero_add] at hGI + have hCI : Integrable (fun x : EuclideanSpace ℝ I => c*root i*x i) + (stdGaussian (EuclideanSpace ℝ I)) := by + apply integrable_of_all_exp + intro t + simpa using gaussian_integrable_exp_lipschitz _ + ((c*root i) • EuclideanSpace.proj (𝕜 := ℝ) i).lipschitzWith t 1 (0:EuclideanSpace ℝ I) + rw [gaussianLinearBackward_free_coordinate i l hl hf hfree] + simp only [diagonalMark_apply,← mul_assoc] + have hsum : Integrable (fun x => + gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ I)) (diagonalWord l) f + (diagonalMark root x)+c*root i*x i) (stdGaussian (EuclideanSpace ℝ I)) := by + convert hGI.add hCI using 1 + rw [integral_add hsum (integrable_const _),integral_add hGI hCI, + integral_const_mul,gaussian_coordinate_mean,integral_const] + simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/GaussianCoordinateProjection.lean b/lean/OAI/Probability/Perceptron/Sphere/GaussianCoordinateProjection.lean new file mode 100644 index 0000000000000000000000000000000000000000..887100f1f99b342c5edb296b8740217f49650abb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/GaussianCoordinateProjection.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityBulkCoefficients +import OAI.Probability.Perceptron.Cavity.CavitySphericalMoments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory +open scoped Topology +namespace SphericalPerceptronFreeEnergy + +lemma finiteGaussian_coordinate_projection {I J : Type*} [Fintype I] [Fintype J] + (e : J→I) (he : Function.Injective e) : + MeasurePreserving (fun x : EuclideanSpace ℝ I=>fun j=>x (e j)) + (stdGaussian (EuclideanSpace ℝ I)) (Measure.pi fun _ : J=>gaussianReal 0 1) := by + refine ⟨by fun_prop,?_⟩ + rw [←map_pi_eq_stdGaussian,Measure.map_map (by fun_prop) (PiLp.continuous_toLp 2 _).measurable] + change (Measure.pi fun _ : I=>gaussianReal 0 1).map (fun x j=>x (e j))=_ + rw [←Measure.infinitePi_eq_pi,Measure.map_infinitePi_infinitePi_of_inj he,Measure.infinitePi_eq_pi] + +lemma finiteGaussian_curry_preserving (I J : Type*) [Fintype I] [Fintype J] : + MeasurePreserving (fun x : I×J→ℝ=>fun i j=>x (i,j)) + (Measure.pi fun _ : I×J=>gaussianReal 0 1) + (Measure.pi fun _ : I=>Measure.pi fun _ : J=>gaussianReal 0 1) := by + refine ⟨by fun_prop,?_⟩ + have h:=Measure.infinitePi_map_curry (μ:=fun (_ : I) (_ : J)=>gaussianReal 0 1) + simp only [Measure.infinitePi_eq_pi] at h + convert h using 1 + rfl + +def cavityBulkNoiseSplit (n d m M : ℕ) + (y : EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : + (Fin M→Spin (n+1))×(Fin d→Fin (m+1)→ℝ) := + (fun t=>WithLp.toLp 2 (fun i=>y (Sum.inl i,Sum.inl t)), + fun t i=>y (Sum.inr t,Sum.inr i)) + +lemma cavityBulkNoiseSplit_preserving (n d m M : ℕ) : + MeasurePreserving (cavityBulkNoiseSplit n d m M) + (stdGaussian (EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M))) + ((Measure.pi fun _ : Fin M=>stdGaussian (Spin (n+1))).prod + (finitePatternRowsLaw (m+1) d)) := by + let e : (Fin M×Fin (n+1))⊕(Fin d×Fin (m+1))→CavityBulkNoiseIndex n d m M := + Sum.elim (fun p=>(Sum.inl p.2,Sum.inl p.1)) (fun p=>(Sum.inr p.1,Sum.inr p.2)) + have he : Function.Injective e := by + intro a b h + cases a <;> cases b <;> simp only [e,Sum.elim_inl,Sum.elim_inr,Prod.mk.injEq,Sum.inl.injEq, + Sum.inr.injEq,Sum.inl_ne_inr,Sum.inr_ne_inl,false_and] at h + · exact congrArg Sum.inl (Prod.ext h.2 h.1) + · exact congrArg Sum.inr (Prod.ext h.1 h.2) + have hp:=(measurePreserving_sumPiEquivProdPi + (fun _ : (Fin M×Fin (n+1))⊕(Fin d×Fin (m+1))=>gaussianReal 0 1)).comp + (finiteGaussian_coordinate_projection e he) + have ht : MeasurePreserving (WithLp.toLp 2 : (Fin (n+1)→ℝ)→Spin (n+1)) + (Measure.pi fun _=>gaussianReal 0 1) (stdGaussian (Spin (n+1))) := + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + have hleft:=(measurePreserving_pi (fun _ : Fin M=>Measure.pi fun _ : Fin (n+1)=>gaussianReal 0 1) + (fun _=>stdGaussian (Spin (n+1))) (fun _=>ht)).comp (finiteGaussian_curry_preserving (Fin M) (Fin (n+1))) + convert (hleft.prod (finiteGaussian_curry_preserving (Fin d) (Fin (m+1)))).comp hp using 1 + · rfl + · rfl + +lemma cavityBulkNoiseSplit_scalar (n d m M : ℕ) (f : Jet3) (a : BulkDisorder (m+1) M) + (x : NormalizedSpin (m+1)) (y : EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) (t : Fin d) : + inner ℝ (cavityBulkFeature n d m M f a x (Sum.inr t)) y= + ∑ i,(cavityBulkNoiseSplit n d m M y).2 t i*x.val i := by + classical + simp only [EuclideanSpace.inner_eq_star_dotProduct,dotProduct,cavityBulkFeature, + star_trivial,Fintype.sum_prod_type] + simp only [mul_ite,mul_zero,cavityBulkBase,Fintype.sum_sum_type,cavityBulkNoiseSplit] + simp only [Sum.inl_ne_inr,Sum.inr.injEq,ite_false,ite_self,Finset.sum_const_zero,zero_add] + rw [Finset.sum_comm] + simp + +lemma cavityBulkNoiseSplit_vector (n d m M : ℕ) (f : Jet3) (a : BulkDisorder (m+1) M) + (x : NormalizedSpin (m+1)) (y : EuclideanSpace ℝ (CavityBulkNoiseIndex n d m M)) : + gaussianRows (fun i=>cavityBulkFeature n d m M f a x (Sum.inl i)) y= + cavityVectorField M (n+1) (fun t=>f.d1 (∑ i,a.1 t i*x.val i)) + (Real.sqrt (m+1:ℕ))⁻¹ (cavityBulkNoiseSplit n d m M y).1 := by + classical + ext i + simp only [gaussianRows_apply,EuclideanSpace.inner_eq_star_dotProduct,dotProduct,cavityBulkFeature, + star_trivial,Fintype.sum_prod_type] + simp only [mul_ite,mul_zero,cavityBulkBase,Fintype.sum_sum_type, + cavityBulkNoiseSplit,cavityVectorField,PiLp.smul_apply,smul_eq_mul] + simp only [EuclideanSpace.inner_eq_star_dotProduct,dotProduct,star_trivial] + simp only [Sum.inl.injEq,Sum.inr_ne_inl,ite_false,ite_self,Finset.sum_const_zero,add_zero] + rw [Finset.sum_comm] + simp only [Fintype.sum_ite_eq'] + try simp only [cavityVectorField,PiLp.smul_apply,smul_eq_mul,PiLp.sum_apply,PiLp.toLp_apply] + simp_rw [mul_comm (y.ofLp _) _] + simp only [WithLp.ofLp_sum,PiLp.smul_apply,Finset.sum_apply,smul_eq_mul] + simp only [mul_assoc,Finset.mul_sum] +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/GaussianPolar.lean b/lean/OAI/Probability/Perceptron/Sphere/GaussianPolar.lean new file mode 100644 index 0000000000000000000000000000000000000000..59c4bf507b3337a0e2e9403043f4791ac512ac2d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/GaussianPolar.lean @@ -0,0 +1,103 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereBridge +import OAI.Probability.Perceptron.Sphere.SphereHeat + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal +namespace SphericalPerceptronFreeEnergy + +lemma canonicalRadial_exp_integrable (n : ℕ) (z : Spin (n+1)) : + Integrable (fun x => Real.exp (inner ℝ z x)) (canonicalRadialMass n 1) := by + apply (lintegral_ofReal_ne_top_iff_integrable (by fun_prop) + (Eventually.of_forall fun x => (Real.exp_pos _).le)).mp + rw [canonicalRadial_linear_integral n (by norm_num)] + exact ENNReal.ofReal_ne_top + +lemma canonicalRadial_exp_integral (n : ℕ) (z : Spin (n+1)) : + (∫ x, Real.exp (inner ℝ z x) ∂canonicalRadialMass n 1)=Real.exp (‖z‖^2/2) := by + have h := canonicalRadial_linear_integral n (b:=1) (by norm_num) z + rw [←ofReal_integral_eq_lintegral_ofReal (canonicalRadial_exp_integrable n z) + (Eventually.of_forall fun x => (Real.exp_pos _).le)] at h + apply (ENNReal.ofReal_eq_ofReal_iff (integral_nonneg fun x => (Real.exp_pos _).le) (Real.exp_pos _).le).mp + simpa using h + +lemma canonicalRadialMass_eq_stdGaussian (n : ℕ) : + canonicalRadialMass n 1=stdGaussian (Spin (n+1)) := by + apply Measure.ext_of_charFun + funext z + have hm : mgf (fun x => inner ℝ z x) (canonicalRadialMass n 1)= + mgf (fun x => inner ℝ z x) (stdGaussian (Spin (n+1))) := by + funext t + change (∫ x, Real.exp (t*inner ℝ z x) ∂canonicalRadialMass n 1)= + (∫ x, Real.exp (t*inner ℝ z x) ∂stdGaussian (Spin (n+1))) + rw [integral_exp_inner_stdGaussian] + have h := canonicalRadial_exp_integral n (t • z) + simp only [real_inner_smul_left,norm_smul,Real.norm_eq_abs,mul_pow,sq_abs] at h + exact h + have hs : integrableExpSet (fun x => inner ℝ z x) (canonicalRadialMass n 1)=univ := by + apply eq_univ_of_forall + intro t + change Integrable (fun x => Real.exp (t*inner ℝ z x)) _ + simpa only [real_inner_smul_left] using canonicalRadial_exp_integrable n (t • z) + have h := eqOn_complexMGF_of_mgf hm (show (Complex.I:ℂ)∈{w | w.re∈interior + (integrableExpSet (fun x => inner ℝ z x) (canonicalRadialMass n 1))} by simp [hs]) + simpa only [complexMGF,charFun_apply,real_inner_comm z, mul_comm Complex.I] using h + +def gaussianRadialWeight (n : ℕ) (r : ℝ) : ℝ≥0∞ := + ENNReal.ofReal (radialNormalizer n * Real.exp (-(1/2:ℝ)*r^2)) + +def gaussianRadiusLaw (n : ℕ) : Measure (Ioi (0:ℝ)) := + (haarRadiusMeasure (volume : Measure (Spin (n+1)))).withDensity + (fun r => gaussianRadialWeight n r) + +lemma stdGaussian_polar_lintegral (n : ℕ) (f : Spin (n+1) → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ x, f x ∂stdGaussian (Spin (n+1)))= + ∫⁻ r : Ioi (0:ℝ), ∫⁻ u : Metric.sphere (0:Spin (n+1)) 1, + f (r.val • u.val) ∂unitSphereLaw (n+1) ∂gaussianRadiusLaw n := by + rw [←canonicalRadialMass_eq_stdGaussian,canonicalRadialMass, + lintegral_withDensity_eq_lintegral_mul _ + (canonicalRadialDensity_continuous n 1).measurable.ennreal_ofReal hf] + change (∫⁻ x, gaussianRadialWeight n ‖x‖ * f x)=_ + rw [polar_weighted_lintegral volume f hf (gaussianRadialWeight n) (by unfold gaussianRadialWeight; fun_prop)] + rw [gaussianRadiusLaw,lintegral_withDensity_eq_lintegral_mul _ (by unfold gaussianRadialWeight; fun_prop)] + · rfl + · exact Measurable.lintegral_prod_right (hf.comp (measurable_fst.subtype_val.smul measurable_snd.subtype_val)) + +instance gaussianRadiusLaw_probability (n : ℕ) : IsProbabilityMeasure (gaussianRadiusLaw n) := by + constructor + have h := stdGaussian_polar_lintegral n (fun _ => 1) measurable_const + simpa using h.symm + +lemma normalizedGaussian_smul (n : ℕ) (r : Ioi (0:ℝ)) + (u : Metric.sphere (0:Spin (n+1)) 1) : + ‖r.val • u.val‖⁻¹ • (r.val • u.val)=u.val := by + have hn : ‖u.val‖=1 := by simpa only [Metric.mem_sphere,dist_zero_right] using u.prop + rw [norm_smul,Real.norm_eq_abs,abs_of_pos r.prop,hn,mul_one,smul_smul, + inv_mul_cancel₀ (ne_of_gt r.prop),one_smul] + +lemma normalizedGaussian_polar_law (n : ℕ) : + (stdGaussian (Spin (n+1))).map (fun x => (‖x‖,‖x‖⁻¹ • x))= + ((gaussianRadiusLaw n).map Subtype.val).prod + ((unitSphereLaw (n+1)).map Subtype.val) := by + apply Measure.ext_of_lintegral + intro F hF + rw [lintegral_map hF (by fun_prop)] + rw [stdGaussian_polar_lintegral n (fun x => F (‖x‖,‖x‖⁻¹ • x)) (by fun_prop), + lintegral_prod _ hF.aemeasurable] + rw [lintegral_map (by fun_prop) (by fun_prop)] + apply lintegral_congr + intro r + rw [lintegral_map (f:=fun y : Spin (n+1) => F (r.val,y)) (by fun_prop) measurable_subtype_coe] + apply lintegral_congr + intro u + rw [normalizedGaussian_smul] + have hn : ‖u.val‖=1 := by simpa only [Metric.mem_sphere,dist_zero_right] using u.prop + rw [norm_smul,Real.norm_eq_abs,abs_of_pos r.prop,hn,mul_one] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/GaussianRotation.lean b/lean/OAI/Probability/Perceptron/Sphere/GaussianRotation.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e64f66da6df52196080a1f16fd0a05e92fdfb68 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/GaussianRotation.lean @@ -0,0 +1,430 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +namespace SphericalPerceptronFreeEnergy + +lemma charFunDual_standardGaussian (L : StrongDual ℝ ℝ) : + charFunDual (gaussianReal 0 1) L = Complex.exp (-(L 1 : ℂ)^2/2) := by + have he : (L : ℝ → ℝ) = fun x => L 1*x := by + funext x + have h := L.map_smul x (1 : ℝ) + simpa only [smul_eq_mul,mul_one,mul_comm x,one_mul] using h + have hm : (∫ x : ℝ, L 1*x ∂gaussianReal 0 1) = 0 := by + rw [integral_const_mul] + simp + have hv : variance (fun x : ℝ => L 1*x) (gaussianReal 0 1) = (L 1)^2 := by + change variance (fun x : ℝ => L 1*id x) (gaussianReal 0 1) = _ + rw [variance_const_mul] + simp [variance_id_gaussianReal] + rw [IsGaussian.charFunDual_eq, integral_complex_ofReal, he, hm, hv] + congr 1 + push_cast only [Complex.ofReal_zero,Complex.ofReal_pow] + ring_nf + +def gaussianRotation (t : ℝ) : (ℝ × ℝ) →L[ℝ] (ℝ × ℝ) := + ((Real.cos t • ContinuousLinearMap.fst ℝ ℝ ℝ + + Real.sin t • ContinuousLinearMap.snd ℝ ℝ ℝ).prod + (-Real.sin t • ContinuousLinearMap.fst ℝ ℝ ℝ + + Real.cos t • ContinuousLinearMap.snd ℝ ℝ ℝ)) + +lemma gaussianRotation_apply (t : ℝ) (p : ℝ × ℝ) : + gaussianRotation t p = (Real.cos t*p.1+Real.sin t*p.2, + -Real.sin t*p.1+Real.cos t*p.2) := rfl + +lemma gaussianRotation_preserving (t : ℝ) : + MeasurePreserving (gaussianRotation t) ((gaussianReal 0 1).prod (gaussianReal 0 1)) + ((gaussianReal 0 1).prod (gaussianReal 0 1)) := by + refine ⟨by fun_prop, Measure.ext_of_charFunDual ?_⟩ + ext L + rw [charFunDual_map] + simp only [charFunDual_prod, charFunDual_standardGaussian] + rw [← Complex.exp_add, ← Complex.exp_add] + congr 1 + have hL (x y : ℝ) : L (x,y) = x*L (1,0)+y*L (0,1) := by + have he : (x,y) = x • (1,0) + y • (0,1) := by ext <;> simp + rw [he,map_add,map_smul,map_smul] + rfl + simp only [ContinuousLinearMap.comp_apply,ContinuousLinearMap.inl_apply, + ContinuousLinearMap.inr_apply,gaussianRotation_apply,mul_one,mul_zero,zero_add,add_zero] + rw [hL (Real.cos t) (-Real.sin t),hL (Real.sin t) (Real.cos t)] + have h := Real.sin_sq_add_cos_sq t + have h' : (Real.sin t : ℂ)^2+(Real.cos t : ℂ)^2=1 := by exact_mod_cast h + push_cast only [Complex.ofReal_add,Complex.ofReal_mul,Complex.ofReal_neg] + linear_combination -(L (1,0)^2+L (0,1)^2)/2*h' + +lemma integral_sq_ge_sq_integral_div {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsFiniteMeasure μ] {f : Ω → ℝ} + (hf : MemLp f 2 μ) (hμ : 0 < μ.real univ) : + (∫ x, f x ∂μ)^2 ≤ μ.real univ * ∫ x, (f x)^2 ∂μ := by + let i := ∫ x, f x ∂μ + let a := μ.real univ + have hi := hf.integrable (by norm_num) + have hi2 := hf.integrable_sq + have he : (∫ x, (f x-i/a)^2 ∂μ) = + (∫ x, (f x)^2 ∂μ)-2*(i/a)*i+a*(i/a)^2 := by + calc + _ = ∫ x, (f x)^2-(2*(i/a))*f x+(i/a)^2 ∂μ := integral_congr_ae (ae_of_all _ fun x => by ring) + _ = _ := by + have ha := integral_add (hi2.sub (hi.const_mul (2*(i/a)))) (integrable_const ((i/a)^2)) + have hb := integral_sub hi2 (hi.const_mul (2*(i/a))) + simp only [Pi.sub_apply] at ha + rw [ha,hb,integral_const_mul,integral_const] + rfl + have hn : (0 : ℝ) ≤ ∫ x, (f x-i/a)^2 ∂μ := integral_nonneg (fun x => sq_nonneg _) + rw [he] at hn + have ha : a ≠ 0 := hμ.ne' + have hae : a*(i/a)^2 = i^2/a := by field_simp + have hie : 2*(i/a)*i = 2*(i^2/a) := by ring + rw [hae,hie] at hn + have : i^2/a ≤ ∫ x, (f x)^2 ∂μ := by linarith + exact (div_le_iff₀ hμ).mp this |>.trans_eq (mul_comm ..) + +lemma gaussian_rotation_path_bound {F D : ℝ → ℝ} (hF : ∀ x, HasDerivAt F (D x) x) + (hD : Continuous D) (x y : ℝ) : + (F y-F x)^2 ≤ (Real.pi/2) * ∫ t in Ioc 0 (Real.pi/2), + (D (Real.cos t*x+Real.sin t*y)*(-Real.sin t*x+Real.cos t*y))^2 := by + let d := fun t => D (Real.cos t*x+Real.sin t*y)*(-Real.sin t*x+Real.cos t*y) + have hd : Continuous d := by dsimp [d]; fun_prop + have hdF (t : ℝ) : HasDerivAt (fun t => F (Real.cos t*x+Real.sin t*y)) (d t) t := by + exact (hF _).comp t (((Real.hasDerivAt_cos t).mul_const x).add + ((Real.hasDerivAt_sin t).mul_const y)) + have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun t _ => hdF t) (hd.intervalIntegrable 0 (Real.pi/2)) + simp only [Real.cos_pi_div_two,Real.sin_pi_div_two,Real.cos_zero,Real.sin_zero, + zero_mul,one_mul,zero_add,add_zero] at hi + rw [intervalIntegral.integral_of_le (by positivity)] at hi + have hm : MemLp d 2 (volume.restrict (Ioc 0 (Real.pi/2))) := + (memLp_two_iff_integrable_sq hd.aestronglyMeasurable).mpr + ((hd.pow 2).integrableOn_Icc.mono_set Ioc_subset_Icc_self) + have hmass : (volume.restrict (Ioc 0 (Real.pi/2))).real univ = Real.pi/2 := by + simp [Measure.real,Real.volume_Ioc]; positivity + have hh := integral_sq_ge_sq_integral_div (volume.restrict (Ioc 0 (Real.pi/2))) hm + (by rw [hmass]; positivity) + rwa [hmass,hi] at hh + +lemma standardGaussian_secondMoment : (∫ x : ℝ, x^2 ∂gaussianReal 0 1) = 1 := by + have h := variance_eq_sub (memLp_id_gaussianReal (μ := 0) (v := 1) 2) + simpa only [variance_id_gaussianReal,NNReal.coe_one,Pi.pow_apply,id_eq, + integral_id_gaussianReal,zero_pow (by norm_num : (2 : ℕ) ≠ 0),sub_zero] using h.symm + +lemma hasDerivAt_bounded_memLp {F D : ℝ → ℝ} (hF : ∀ x, HasDerivAt F (D x) x) + {C : ℝ} (hC : 0 ≤ C) (hDC : ∀ x, |D x| ≤ C) : + MemLp F 2 (gaussianReal 0 1) := by + have hL : LipschitzWith ⟨C,hC⟩ F := lipschitzWith_of_nnnorm_deriv_le + (fun x => (hF x).differentiableAt) (fun x => by + rw [(hF x).deriv] + exact_mod_cast hDC x) + have hgc : LipschitzWith ⟨C,hC⟩ (fun x => F x-F 0) := by + intro x y + simpa only [edist_sub_right] using hL x y + have hg := hgc.comp_memLp (by simp) (memLp_id_gaussianReal (μ := 0) (v := 1) 2) + have hh := hg.add (memLp_const (F 0)) + have he : ((fun x => F x-F 0) ∘ id + fun _ => F 0) = F := by + funext x + simp + rw [he] at hh + convert! hh + +lemma gaussian_rotation_derivative_square_mean {D : ℝ → ℝ} + (hD : Continuous D) (t : ℝ) : + (∫ p : ℝ × ℝ, + (D (Real.cos t*p.1+Real.sin t*p.2)*(-Real.sin t*p.1+Real.cos t*p.2))^2 + ∂(gaussianReal 0 1).prod (gaussianReal 0 1)) = + ∫ x, (D x)^2 ∂gaussianReal 0 1 := by + have he := integral_map (μ := (gaussianReal 0 1).prod (gaussianReal 0 1)) + (gaussianRotation t).continuous.measurable.aemeasurable + (f := fun p : ℝ×ℝ => (D p.1*p.2)^2) (by fun_prop) + rw [(gaussianRotation_preserving t).map_eq] at he + dsimp only [gaussianRotation_apply] at he + rw [← he] + simp_rw [mul_pow] + rw [integral_prod_mul (fun x : ℝ => (D x)^2) (fun y : ℝ => y^2),standardGaussian_secondMoment,mul_one] + +lemma integral_independent_difference_square {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] {F : Ω → ℝ} (hF : MemLp F 2 μ) : + (∫ p : Ω×Ω, (F p.1-F p.2)^2 ∂μ.prod μ) = 2*variance F μ := by + have hi := hF.integrable (by norm_num) + have hi2 := hF.integrable_sq + have hprod := hi.mul_prod hi + calc + _ = ∫ p : Ω×Ω, (F p.1)^2-2*(F p.1*F p.2)+(F p.2)^2 ∂μ.prod μ := + integral_congr_ae (ae_of_all _ fun p => by ring) + _ = _ := by + have ha := integral_add ((hi2.comp_fst μ).sub (hprod.const_mul 2)) (hi2.comp_snd μ) + have hb := integral_sub (hi2.comp_fst μ) (hprod.const_mul 2) + simp only [Pi.sub_apply] at ha + rw [ha,hb,integral_const_mul,integral_fun_fst (fun x : Ω => (F x)^2), + integral_fun_snd (fun x : Ω => (F x)^2), + integral_prod_mul F F,variance_eq_sub hF] + simp only [probReal_univ,one_smul,Pi.pow_apply] + ring + +lemma standardGaussian_poincare {F D : ℝ → ℝ} (hF : ∀ x, HasDerivAt F (D x) x) + (hD : Continuous D) {C : ℝ} (hC : 0 ≤ C) (hDC : ∀ x, |D x| ≤ C) : + variance F (gaussianReal 0 1) ≤ (Real.pi^2/8)*(∫ x, (D x)^2 ∂gaussianReal 0 1) := by + let γ := gaussianReal 0 1 + let μ := γ.prod γ + let T := Real.pi/2 + let ν := volume.restrict (Ioc 0 T) + let d := fun (t : ℝ) (p : ℝ×ℝ) => + D (Real.cos t*p.1+Real.sin t*p.2)*(-Real.sin t*p.1+Real.cos t*p.2) + have hT : 0 < T := by dsimp [T]; positivity + have hν : ν.real univ = T := by simp [ν,Measure.real,Real.volume_Ioc,hT.le] + have hdom (t : ℝ) (p : ℝ×ℝ) : (d t p)^2 ≤ 2*C^2*(p.1^2+p.2^2) := by + have hb : |-Real.sin t*p.1+Real.cos t*p.2| ≤ |p.1|+|p.2| := by + apply (abs_add_le _ _).trans + rw [abs_mul,abs_mul,abs_neg] + exact add_le_add (by nlinarith [Real.abs_sin_le_one t,abs_nonneg p.1]) + (by nlinarith [Real.abs_cos_le_one t,abs_nonneg p.2]) + have hb2 : (-Real.sin t*p.1+Real.cos t*p.2)^2 ≤ 2*(p.1^2+p.2^2) := by + have hh := (sq_le_sq₀ (abs_nonneg _) (by positivity : 0 ≤ |p.1|+|p.2|)).mpr hb + simp only [sq_abs] at hh + nlinarith [sq_nonneg (|p.1|-|p.2|),sq_abs p.1,sq_abs p.2] + have hD2 : (D (Real.cos t*p.1+Real.sin t*p.2))^2 ≤ C^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg _) hC).mpr (hDC _) + dsimp only [d] + rw [mul_pow] + have hh := mul_le_mul hD2 hb2 (sq_nonneg _) (sq_nonneg C) + nlinarith + have hs : Integrable (fun x : ℝ => x^2) γ := (memLp_id_gaussianReal 2).integrable_sq + have hdI : Integrable (fun p : (ℝ×ℝ)×ℝ => (d p.2 p.1)^2) (μ.prod ν) := by + have hh : Integrable (fun p : (ℝ×ℝ)×ℝ => 2*C^2*(p.1.1^2+p.1.2^2)) (μ.prod ν) := + (((hs.comp_fst γ).add (hs.comp_snd γ)).const_mul (2*C^2)).comp_fst ν + apply hh.mono' (by dsimp [d]; fun_prop) + exact ae_of_all _ fun p => by simpa only [Real.norm_eq_abs,abs_sq] using hdom p.2 p.1 + have hmF : MemLp F 2 γ := hasDerivAt_bounded_memLp hF hC hDC + have hdiff : Integrable (fun p : ℝ×ℝ => (F p.2-F p.1)^2) μ := by + simpa only [Pi.sub_apply] using ((hmF.comp_snd γ).sub (hmF.comp_fst γ)).integrable_sq + have he : (∫ p : ℝ×ℝ, (F p.2-F p.1)^2 ∂μ) = 2*variance F γ := by + rw [show (fun p : ℝ×ℝ => (F p.2-F p.1)^2) = fun p => (F p.1-F p.2)^2 by + funext p; ring] + exact integral_independent_difference_square γ hmF + have hn := integral_mono_ae hdiff (hdI.integral_prod_left.const_mul T) + (ae_of_all _ fun p => gaussian_rotation_path_bound hF hD p.1 p.2) + rw [he,integral_const_mul,← integral_prod _ hdI,integral_prod_symm _ hdI] at hn + have hmeans : (∫ t, ∫ p : ℝ×ℝ, (d t p)^2 ∂μ ∂ν) = + T*(∫ x, (D x)^2 ∂γ) := by + simp_rw [show ∀ t, (∫ p : ℝ×ℝ, (d t p)^2 ∂μ) = ∫ x, (D x)^2 ∂γ + from fun t => gaussian_rotation_derivative_square_mean hD t] + rw [integral_const,hν,smul_eq_mul] + rw [hmeans] at hn + dsimp only [T] at hn + nlinarith + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma dual_rotation_norm (A B : StrongDual ℝ E) (t : ℝ) : + ‖Real.cos t • A - Real.sin t • B‖^2 + ‖Real.sin t • A + Real.cos t • B‖^2 = + ‖A‖^2+‖B‖^2 := by + let e := (InnerProductSpace.toDual ℝ E).symm + rw [← e.norm_map (Real.cos t • A - Real.sin t • B), + ← e.norm_map (Real.sin t • A + Real.cos t • B),← e.norm_map A,← e.norm_map B] + simp only [map_sub,map_add,map_smul,norm_sub_sq_real,norm_add_sq_real, + real_inner_smul_left,real_inner_smul_right,norm_smul,Real.norm_eq_abs,mul_pow,sq_abs] + have h := Real.sin_sq_add_cos_sq t + nlinarith [sq_nonneg ‖e A‖,sq_nonneg ‖e B‖] + +def gaussianVectorRotation (t : ℝ) : (E × E) →L[ℝ] (E × E) := + ((Real.cos t • ContinuousLinearMap.fst ℝ E E + + Real.sin t • ContinuousLinearMap.snd ℝ E E).prod + (-Real.sin t • ContinuousLinearMap.fst ℝ E E + + Real.cos t • ContinuousLinearMap.snd ℝ E E)) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma gaussianVectorRotation_apply (t : ℝ) (p : E×E) : + gaussianVectorRotation t p = (Real.cos t • p.1+Real.sin t • p.2, + -Real.sin t • p.1+Real.cos t • p.2) := rfl + +lemma gaussianVectorRotation_preserving (t : ℝ) : + MeasurePreserving (gaussianVectorRotation (E := E) t) ((stdGaussian E).prod (stdGaussian E)) + ((stdGaussian E).prod (stdGaussian E)) := by + refine ⟨by fun_prop, Measure.ext_of_charFunDual ?_⟩ + ext L + rw [charFunDual_map] + simp only [charFunDual_prod,charFunDual_stdGaussian] + rw [← Complex.exp_add,← Complex.exp_add] + congr 1 + let A := L.comp (ContinuousLinearMap.inl ℝ E E) + let B := L.comp (ContinuousLinearMap.inr ℝ E E) + have hsplit (x y : E) : L (x,y) = L (x,0)+L (0,y) := by + simpa using L.map_add (x,0) (0,y) + have ha : (L.comp (gaussianVectorRotation t)).comp (ContinuousLinearMap.inl ℝ E E) = + Real.cos t • A - Real.sin t • B := by + ext x + simp only [ContinuousLinearMap.comp_apply,ContinuousLinearMap.inl_apply, + smul_apply,sub_apply,gaussianVectorRotation_apply,smul_zero,add_zero] + rw [hsplit] + change A (Real.cos t • x) + B (-Real.sin t • x) = _ + simp [sub_eq_add_neg] + have hb : (L.comp (gaussianVectorRotation t)).comp (ContinuousLinearMap.inr ℝ E E) = + Real.sin t • A + Real.cos t • B := by + ext x + simp only [ContinuousLinearMap.comp_apply,ContinuousLinearMap.inr_apply, + smul_apply,add_apply,gaussianVectorRotation_apply,smul_zero,zero_add] + rw [hsplit] + change A (Real.sin t • x) + B (Real.cos t • x) = _ + simp + rw [ha,hb] + have h := dual_rotation_norm A B t + have hc : (‖Real.cos t • A - Real.sin t • B‖ : ℂ)^2 + + (‖Real.sin t • A + Real.cos t • B‖ : ℂ)^2 = (‖A‖ : ℂ)^2+(‖B‖ : ℂ)^2 := by + exact_mod_cast h + change _ = -(‖A‖ : ℂ)^2/2 + -(‖B‖ : ℂ)^2/2 + linear_combination -hc/2 + +lemma stdGaussian_dual_secondMoment (L : StrongDual ℝ E) : + (∫ x, (L x)^2 ∂stdGaussian E) = ‖L‖^2 := by + have hm : MemLp L 2 (stdGaussian E) := IsGaussian.memLp_dual _ _ 2 (by simp) + have h := variance_eq_sub hm + rw [integral_strongDual_stdGaussian,zero_pow (by omega),sub_zero, + variance_dual_stdGaussian] at h + exact h.symm + +lemma hasFDerivAt_bounded_gaussian_memLp {F : E → ℝ} {D : E → StrongDual ℝ E} + (hF : ∀ x, HasFDerivAt F (D x) x) {C : ℝ} (hC : 0 ≤ C) + (hDC : ∀ x, ‖D x‖ ≤ C) : MemLp F 2 (stdGaussian E) := by + have hL : LipschitzWith ⟨C,hC⟩ F := lipschitzWith_of_nnnorm_fderiv_le + (fun x => (hF x).differentiableAt) (fun x => by + rw [(hF x).fderiv] + exact_mod_cast hDC x) + have hgc : LipschitzWith ⟨C,hC⟩ (fun x => F x-F 0) := by + intro x y + simpa only [edist_sub_right] using hL x y + have hg := hgc.comp_memLp (by simp) (IsGaussian.memLp_id (stdGaussian E) 2 (by simp)) + have hh := hg.add (memLp_const (F 0)) + have he : ((fun x => F x-F 0) ∘ id + fun _ => F 0) = F := by + funext x + simp + rw [he] at hh + convert! hh + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma gaussian_vector_rotation_path_bound {F : E → ℝ} {D : E → StrongDual ℝ E} + (hF : ∀ x, HasFDerivAt F (D x) x) (hD : Continuous D) (x y : E) : + (F y-F x)^2 ≤ (Real.pi/2) * ∫ t in Ioc 0 (Real.pi/2), + (D (Real.cos t • x+Real.sin t • y) (-Real.sin t • x+Real.cos t • y))^2 := by + let d := fun t => D (Real.cos t • x+Real.sin t • y) (-Real.sin t • x+Real.cos t • y) + have hd : Continuous d := by dsimp [d]; fun_prop + have hdF (t : ℝ) : HasDerivAt (fun t => F (Real.cos t • x+Real.sin t • y)) (d t) t := by + exact (hF _).comp_hasDerivAt t (((Real.hasDerivAt_cos t).smul_const x).add + ((Real.hasDerivAt_sin t).smul_const y)) + have hi := intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun t _ => hdF t) (hd.intervalIntegrable 0 (Real.pi/2)) + simp only [Real.cos_pi_div_two,Real.sin_pi_div_two,Real.cos_zero,Real.sin_zero, + zero_smul,one_smul,zero_add,add_zero] at hi + rw [intervalIntegral.integral_of_le (by positivity)] at hi + have hm : MemLp d 2 (volume.restrict (Ioc 0 (Real.pi/2))) := + (memLp_two_iff_integrable_sq hd.aestronglyMeasurable).mpr + ((hd.pow 2).integrableOn_Icc.mono_set Ioc_subset_Icc_self) + have hmass : (volume.restrict (Ioc 0 (Real.pi/2))).real univ = Real.pi/2 := by + simp [Measure.real,Real.volume_Ioc]; positivity + have hh := integral_sq_ge_sq_integral_div (volume.restrict (Ioc 0 (Real.pi/2))) + hm (by rw [hmass]; positivity) + rw [hmass,hi] at hh + exact hh + +lemma gaussian_vector_rotation_derivative_square_mean {D : E → StrongDual ℝ E} + (hD : Continuous D) {C : ℝ} (hDC : ∀ x, ‖D x‖ ≤ C) (t : ℝ) : + (∫ p : E × E, + (D (Real.cos t • p.1+Real.sin t • p.2) (-Real.sin t • p.1+Real.cos t • p.2))^2 + ∂(stdGaussian E).prod (stdGaussian E)) = + ∫ x, ‖D x‖^2 ∂stdGaussian E := by + have he := integral_map (μ := (stdGaussian E).prod (stdGaussian E)) + (gaussianVectorRotation t).continuous.measurable.aemeasurable + (f := fun p : E×E => (D p.1 p.2)^2) (by fun_prop) + rw [(gaussianVectorRotation_preserving t).map_eq] at he + dsimp only [gaussianVectorRotation_apply] at he + rw [← he] + have hi : Integrable (fun p : E×E => (D p.1 p.2)^2) ((stdGaussian E).prod (stdGaussian E)) := by + have hh := ((IsGaussian.memLp_id (stdGaussian E) 2 (by simp)).norm.integrable_sq.const_mul (C^2)).comp_snd (stdGaussian E) + apply hh.mono' (by fun_prop) + refine ae_of_all _ fun p => ?_ + have hC : 0 ≤ C := (norm_nonneg (D p.1)).trans (hDC _) + have hh : |D p.1 p.2| ≤ C*‖p.2‖ := (ContinuousLinearMap.le_opNorm _ _).trans + (mul_le_mul_of_nonneg_right (hDC _) (norm_nonneg _)) + have hh2 := (sq_le_sq₀ (abs_nonneg _) (mul_nonneg hC (norm_nonneg p.2))).mpr hh + simpa only [Real.norm_eq_abs,abs_sq,sq_abs,mul_pow,id_eq] using hh2 + rw [integral_prod _ hi] + congr 1 + funext x + exact stdGaussian_dual_secondMoment (D x) + +lemma stdGaussian_poincare {F : E → ℝ} {D : E → StrongDual ℝ E} + (hF : ∀ x, HasFDerivAt F (D x) x) (hD : Continuous D) + {C : ℝ} (hC : 0 ≤ C) (hDC : ∀ x, ‖D x‖ ≤ C) : + variance F (stdGaussian E) ≤ (Real.pi^2/8)*(∫ x, ‖D x‖^2 ∂stdGaussian E) := by + let γ := stdGaussian E + let μ := γ.prod γ + let T := Real.pi/2 + let ν := volume.restrict (Ioc 0 T) + let d := fun (t : ℝ) (p : E×E) => + D (Real.cos t • p.1+Real.sin t • p.2) (-Real.sin t • p.1+Real.cos t • p.2) + have hT : 0 < T := by dsimp [T]; positivity + have hν : ν.real univ = T := by simp [ν,Measure.real,Real.volume_Ioc,hT.le] + have hdom (t : ℝ) (p : E×E) : (d t p)^2 ≤ 2*C^2*(‖p.1‖^2+‖p.2‖^2) := by + have hb : ‖-Real.sin t • p.1+Real.cos t • p.2‖ ≤ ‖p.1‖+‖p.2‖ := by + apply (norm_add_le _ _).trans + rw [norm_smul,norm_smul,Real.norm_eq_abs,Real.norm_eq_abs,abs_neg] + exact add_le_add (by nlinarith [Real.abs_sin_le_one t,norm_nonneg p.1]) + (by nlinarith [Real.abs_cos_le_one t,norm_nonneg p.2]) + have hh : |d t p| ≤ C*(‖p.1‖+‖p.2‖) := by + change ‖D (Real.cos t • p.1+Real.sin t • p.2) (-Real.sin t • p.1+Real.cos t • p.2)‖ ≤ _ + apply (ContinuousLinearMap.le_opNorm _ _).trans + exact mul_le_mul (hDC _) hb (norm_nonneg _) hC + have hh2 := (sq_le_sq₀ (abs_nonneg _) (by positivity : 0 ≤ C*(‖p.1‖+‖p.2‖))).mpr hh + simp only [sq_abs,mul_pow] at hh2 + have hh3 := mul_nonneg (sq_nonneg C) (sq_nonneg (‖p.1‖-‖p.2‖)) + nlinarith + have hs : Integrable (fun x : E => ‖x‖^2) γ := + (IsGaussian.memLp_id γ 2 (by simp)).norm.integrable_sq + have hdI : Integrable (fun p : (E×E)×ℝ => (d p.2 p.1)^2) (μ.prod ν) := by + have hh : Integrable (fun p : (E×E)×ℝ => 2*C^2*(‖p.1.1‖^2+‖p.1.2‖^2)) (μ.prod ν) := + (((hs.comp_fst γ).add (hs.comp_snd γ)).const_mul (2*C^2)).comp_fst ν + apply hh.mono' (by dsimp [d]; fun_prop) + exact ae_of_all _ fun p => by simpa only [Real.norm_eq_abs,abs_sq] using hdom p.2 p.1 + have hmF : MemLp F 2 γ := hasFDerivAt_bounded_gaussian_memLp hF hC hDC + have hdiff : Integrable (fun p : E×E => (F p.2-F p.1)^2) μ := by + simpa only [Pi.sub_apply] using ((hmF.comp_snd γ).sub (hmF.comp_fst γ)).integrable_sq + have he : (∫ p : E×E, (F p.2-F p.1)^2 ∂μ) = 2*variance F γ := by + rw [show (fun p : E×E => (F p.2-F p.1)^2) = fun p => (F p.1-F p.2)^2 by + funext p; ring] + exact integral_independent_difference_square γ hmF + have hn := integral_mono_ae hdiff (hdI.integral_prod_left.const_mul T) + (ae_of_all _ fun p => gaussian_vector_rotation_path_bound hF hD p.1 p.2) + rw [he,integral_const_mul,← integral_prod _ hdI,integral_prod_symm _ hdI] at hn + have hmeans : (∫ t, ∫ p : E×E, (d t p)^2 ∂μ ∂ν) = + T*(∫ x, ‖D x‖^2 ∂γ) := by + simp_rw [show ∀ t, (∫ p : E×E, (d t p)^2 ∂μ) = ∫ x, ‖D x‖^2 ∂γ + from fun t => gaussian_vector_rotation_derivative_square_mean hD hDC t] + rw [integral_const,hν,smul_eq_mul] + rw [hmeans] at hn + dsimp only [T] at hn + nlinarith + +lemma stdGaussian_variance_le_of_fderiv_bound {F : E → ℝ} {D : E → StrongDual ℝ E} + (hF : ∀ x, HasFDerivAt F (D x) x) (hD : Continuous D) + {C : ℝ} (hC : 0 ≤ C) (hDC : ∀ x, ‖D x‖ ≤ C) : + variance F (stdGaussian E) ≤ (Real.pi^2/8)*C^2 := by + apply (stdGaussian_poincare hF hD hC hDC).trans + gcongr + calc + _ ≤ ∫ _ : E, C^2 ∂stdGaussian E := + integral_mono_of_nonneg (ae_of_all _ fun x => sq_nonneg _) (integrable_const _) + (ae_of_all _ fun x => (sq_le_sq₀ (norm_nonneg _) hC).mpr (hDC x)) + _ = C^2 := by simp + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/SphereBridge.lean b/lean/OAI/Probability/Perceptron/Sphere/SphereBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..2eb2ede534907677f868865179f5290c2ac383c9 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/SphereBridge.lean @@ -0,0 +1,613 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IntegrableProdConditionalSquare + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction + +namespace SphericalPerceptronFreeEnergy + +def decoratedLeafIntegral {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X × S → X) (F : X → ℝ≥0∞) : + (n : ℕ) → X × DecoratedCascade S n → ℝ≥0∞ + | 0, p => F p.1 + | n+1, p => ∫⁻ q : ℝ × (S × DecoratedCascade S n), + ENNReal.ofReal (Real.exp q.1) * + decoratedLeafIntegral step F n (step (p.1,q.2.1),q.2.2) + ∂markedStableCountKernel p.2 + +lemma decoratedLeafIntegral_exp {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X × S → X) (H : X → ℝ) (n : ℕ) (p : X × DecoratedCascade S n) : + decoratedLeafIntegral step (fun x => ENNReal.ofReal (Real.exp (H x))) n p = + decoratedTerminalTotalE step H n p := by + induction n with + | zero => rfl + | succ n ih => + simp only [decoratedLeafIntegral, decoratedTerminalTotalE, ih] + +lemma decoratedLeafIntegral_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X × S → X) (hs : Measurable step) (F : X → ℝ≥0∞) + (hF : Measurable F) (n : ℕ) : Measurable (decoratedLeafIntegral step F n) := by + induction n with + | zero => exact hF.comp measurable_fst + | succ n ih => + have hm : Measurable (fun p : (X × DecoratedCascade S (n+1)) × + (ℝ × (S × DecoratedCascade S n)) => + ENNReal.ofReal (Real.exp p.2.1) * + decoratedLeafIntegral step F n (step (p.1.1,p.2.2.1),p.2.2.2)) := + (measurable_snd.fst.exp.ennreal_ofReal).mul + (ih.comp ((hs.comp (measurable_fst.fst.prodMk measurable_snd.snd.fst)).prodMk + measurable_snd.snd.snd)) + exact hm.lintegral_kernel_prod_right' (κ := markedStableCountKernel.prodMkLeft X) + +lemma decoratedLeafIntegral_param_measurable {A X S : Type} + [MeasurableSpace A] [MeasurableSpace X] [MeasurableSpace S] + (step : X × S → X) (hs : Measurable step) (F : A × X → ℝ≥0∞) + (hF : Measurable F) (n : ℕ) : + Measurable (fun p : A × (X × DecoratedCascade S n) => + decoratedLeafIntegral step (fun x => F (p.1,x)) n p.2) := by + induction n with + | zero => exact hF.comp (measurable_fst.prodMk measurable_snd.fst) + | succ n ih => + have hm : Measurable (fun p : (A × (X × DecoratedCascade S (n+1))) × + (ℝ × (S × DecoratedCascade S n)) => + ENNReal.ofReal (Real.exp p.2.1) * + decoratedLeafIntegral step (fun x => F (p.1.1,x)) n + (step (p.1.2.1,p.2.2.1),p.2.2.2)) := + (measurable_snd.fst.exp.ennreal_ofReal).mul + (ih.comp (measurable_fst.fst.prodMk + ((hs.comp (measurable_fst.snd.fst.prodMk measurable_snd.snd.fst)).prodMk + measurable_snd.snd.snd))) + exact hm.lintegral_kernel_prod_right' + (κ := (markedStableCountKernel.prodMkLeft X).prodMkLeft A) + +lemma decoratedLeafIntegral_mono {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X × S → X) {F G : X → ℝ≥0∞} (h : ∀ x, F x ≤ G x) + (n : ℕ) (p : X × DecoratedCascade S n) : + decoratedLeafIntegral step F n p ≤ decoratedLeafIntegral step G n p := by + induction n with + | zero => exact h p.1 + | succ n ih => + exact lintegral_mono fun q => mul_le_mul_right (ih _) _ + +lemma decoratedLeafIntegral_const_mul {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X × S → X) (F : X → ℝ≥0∞) (c : ℝ≥0∞) (hc : c ≠ ∞) + (n : ℕ) (p : X × DecoratedCascade S n) : + decoratedLeafIntegral step (fun x => c * F x) n p = + c * decoratedLeafIntegral step F n p := by + induction n with + | zero => rfl + | succ n ih => + simp only [decoratedLeafIntegral, ih, mul_left_comm _ c] + exact lintegral_const_mul' _ _ hc + +lemma decoratedLeafIntegral_lintegral {A X S : Type} + [MeasurableSpace A] [MeasurableSpace X] [MeasurableSpace S] + (μ : Measure A) [SFinite μ] (step : X × S → X) (hs : Measurable step) + (F : A × X → ℝ≥0∞) (hF : Measurable F) (n : ℕ) + (p : X × DecoratedCascade S n) : + decoratedLeafIntegral step (fun x => ∫⁻ a, F (a,x) ∂μ) n p = + ∫⁻ a, decoratedLeafIntegral step (fun x => F (a,x)) n p ∂μ := by + induction n with + | zero => rfl + | succ n ih => + simp only [decoratedLeafIntegral, ih] + have hm : Measurable (fun q : (ℝ × (S × DecoratedCascade S n)) × A => + ENNReal.ofReal (Real.exp q.1.1) * + decoratedLeafIntegral step (fun x => F (q.2,x)) n + (step (p.1,q.1.2.1),q.1.2.2)) := + (measurable_fst.fst.exp.ennreal_ofReal).mul + ((decoratedLeafIntegral_param_measurable step hs F hF n).comp + (measurable_snd.prodMk + ((hs.comp (measurable_const.prodMk measurable_fst.snd.fst)).prodMk + measurable_fst.snd.snd))) + calc + _ = ∫⁻ q : ℝ × (S × DecoratedCascade S n), ∫⁻ a, + ENNReal.ofReal (Real.exp q.1) * + decoratedLeafIntegral step (fun x => F (a,x)) n + (step (p.1,q.2.1),q.2.2) ∂μ ∂markedStableCountKernel p.2 := by + apply lintegral_congr + intro q + exact (lintegral_const_mul' _ _ ENNReal.ofReal_ne_top).symm + _ = _ := lintegral_lintegral_swap hm.aemeasurable + +def decoratedFieldFactor {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (d : ℕ) (step : X × S → X) (field : X → Spin d) (k : ℕ) + (p : X × DecoratedCascade S k) (x : Spin d) : ℝ≥0∞ := + decoratedLeafIntegral step (fun y => ENNReal.ofReal (Real.exp (inner ℝ (field y) x))) k p + +def decoratedAngularFactor {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (n : ℕ) (step : X × S → X) (field : X → Spin (n+1)) (k : ℕ) + (p : X × DecoratedCascade S k) (r : ℝ) : ℝ≥0∞ := + ∫⁻ u : Metric.sphere (0:Spin (n+1)) 1, + decoratedFieldFactor (n+1) step field k p (r • (u:Spin (n+1))) ∂unitSphereLaw (n+1) + +lemma decoratedFieldFactor_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (d : ℕ) (step : X × S → X) (hs : Measurable step) (field : X → Spin d) + (hf : Measurable field) (k : ℕ) (p : X × DecoratedCascade S k) : + Measurable (decoratedFieldFactor d step field k p) := by + let F : Spin d × X → ℝ≥0∞ := fun q => ENNReal.ofReal (Real.exp (inner ℝ (field q.2) q.1)) + have hF : Measurable F := + (((hf.comp measurable_snd).inner measurable_fst).exp.ennreal_ofReal) + have hm : Measurable (fun q : Spin d × (X × DecoratedCascade S k) => + decoratedLeafIntegral step (fun y => F (q.1,y)) k q.2) := + decoratedLeafIntegral_param_measurable step hs F hF k + have hp : Measurable (fun x : Spin d => (x,p)) := measurable_id.prodMk measurable_const + change Measurable (fun x : Spin d => decoratedLeafIntegral step (fun y => F (x,y)) k p) + have hh := hm.comp hp + exact hh + +lemma decoratedAngularFactor_eq {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (n : ℕ) (step : X × S → X) (hs : Measurable step) (field : X → Spin (n+1)) + (hf : Measurable field) (k : ℕ) (p : X × DecoratedCascade S k) (r : ℝ) : + decoratedAngularFactor n step field k p r = + decoratedLeafIntegral step (fun y => ENNReal.ofReal (sphericalExp n (field y) r)) k p := by + have h := decoratedLeafIntegral_lintegral (unitSphereLaw (n+1)) step hs + (fun q : (Metric.sphere (0:Spin (n+1)) 1) × X => + ENNReal.ofReal (Real.exp (inner ℝ (field q.2) (r • (q.1:Spin (n+1)))))) + (((hf.comp measurable_snd).inner (measurable_fst.subtype_coe.const_smul r)).exp.ennreal_ofReal) + k p + change (∫⁻ a : Metric.sphere (0:Spin (n+1)) 1, + decoratedLeafIntegral step (fun y => ENNReal.ofReal (Real.exp (inner ℝ (field y) (r • (a:Spin (n+1)))))) k p + ∂unitSphereLaw (n+1)) = _ + rw [← h] + congr 1 + funext y + simp only [inner_smul_right] + exact (ofReal_integral_eq_lintegral_ofReal + (unitSphere_continuous_integrable (by fun_prop)) + (Eventually.of_forall fun u => (Real.exp_pos _).le)).symm + +lemma decoratedAngularFactor_mono {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (n : ℕ) (step : X × S → X) (hs : Measurable step) (field : X → Spin (n+1)) + (hf : Measurable field) (k : ℕ) (p : X × DecoratedCascade S k) + {r s : ℝ} (hr : 0 ≤ r) (hrs : r ≤ s) : + decoratedAngularFactor n step field k p r ≤ decoratedAngularFactor n step field k p s := by + rw [decoratedAngularFactor_eq n step hs field hf, decoratedAngularFactor_eq n step hs field hf] + exact decoratedLeafIntegral_mono step + (fun y => ENNReal.ofReal_le_ofReal (sphericalExp_mono n (field y) hr hrs)) k p + +lemma decoratedAngularFactor_mass_le {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (n : ℕ) (step : X × S → X) (hs : Measurable step) (field : X → Spin (n+1)) + (hf : Measurable field) (k : ℕ) (p : X × DecoratedCascade S k) (r : ℝ) : + decoratedTerminalTotalE step (fun _ => 0) k p ≤ decoratedAngularFactor n step field k p r := by + rw [decoratedAngularFactor_eq n step hs field hf, ← decoratedLeafIntegral_exp] + apply decoratedLeafIntegral_mono + intro y + simpa using ENNReal.ofReal_le_ofReal (one_le_sphericalExp n (field y) r) + +theorem decoratedCanonical_band_bounds {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (n : ℕ) (step : X × S → X) (hs : Measurable step) (field : X → Spin (n+1)) + (hf : Measurable field) (k : ℕ) (p : X × DecoratedCascade S k) (b ε : ℝ) : + decoratedAngularFactor n step field k p (Real.sqrt (((n+1:ℕ):ℝ)*(1-ε))) * + canonicalRadialMass n b (normSquareBand n ε) ≤ + (∫⁻ x in normSquareBand n ε, + decoratedFieldFactor (n+1) step field k p x ∂canonicalRadialMass n b) ∧ + (∫⁻ x in normSquareBand n ε, + decoratedFieldFactor (n+1) step field k p x ∂canonicalRadialMass n b) ≤ + decoratedAngularFactor n step field k p (Real.sqrt (((n+1:ℕ):ℝ)*(1+ε))) * + canonicalRadialMass n b (normSquareBand n ε) := by + have hm := decoratedFieldFactor_measurable (n+1) step hs field hf k p + have hh := polar_weighted_bounds (volume : Measure (RadialSpace n)) + (decoratedFieldFactor (n+1) step field k p) hm + (canonicalBandRadiusWeight n b ε) (canonicalBandRadiusWeight_measurable n b ε) + (L := decoratedAngularFactor n step field k p (Real.sqrt (((n+1:ℕ):ℝ)*(1-ε)))) + (U := decoratedAngularFactor n step field k p (Real.sqrt (((n+1:ℕ):ℝ)*(1+ε)))) + rw [canonicalBandRadiusWeight_integral n b ε _ hm,canonicalBandRadiusWeight_mass] at hh + apply hh + · intro r hr + have hb : ((n+1:ℕ):ℝ)*(1-ε) ≤ (r:ℝ)^2 ∧ (r:ℝ)^2 ≤ ((n+1:ℕ):ℝ)*(1+ε) := by + by_contra hn + exact hr (by simp only [canonicalBandRadiusWeight,Set.indicator_apply,Set.mem_ofPred_eq,hn,ite_false]) + change _ ≤ decoratedAngularFactor n step field k p r + apply decoratedAngularFactor_mono n step hs field hf k p (Real.sqrt_nonneg _) + exact (Real.sqrt_le_iff).mpr ⟨r.property.le,hb.1⟩ + · intro r hr + have hb : ((n+1:ℕ):ℝ)*(1-ε) ≤ (r:ℝ)^2 ∧ (r:ℝ)^2 ≤ ((n+1:ℕ):ℝ)*(1+ε) := by + by_contra hn + exact hr (by simp only [canonicalBandRadiusWeight,Set.indicator_apply,Set.mem_ofPred_eq,hn,ite_false]) + change decoratedAngularFactor n step field k p r ≤ _ + apply decoratedAngularFactor_mono n step hs field hf k p r.property.le + exact (Real.le_sqrt' r.property).mpr hb.2 + +lemma canonicalRadialDensity_complete_square (n : ℕ) {b : ℝ} (hb : 0 < b) + (z x : Spin (n+1)) : + canonicalRadialDensity n b x * Real.exp (inner ℝ z x) = + Real.exp (‖z‖^2/(2*b)) * canonicalRadialDensity n b (x - b⁻¹ • z) := by + have he : -(b/2)*‖x‖^2 + inner ℝ z x = ‖z‖^2/(2*b) - (b/2)*‖x-b⁻¹ • z‖^2 := by + rw [norm_sub_sq_real,inner_smul_right,norm_smul,Real.norm_eq_abs, + abs_of_pos (inv_pos.mpr hb),mul_pow,real_inner_comm x z] + field_simp + ring + unfold canonicalRadialDensity + calc + _ = radialNormalizer n * Real.exp (-(b/2)*‖x‖^2 + inner ℝ z x) := by rw [Real.exp_add]; ring + _ = _ := by rw [he,Real.exp_sub,neg_mul,Real.exp_neg]; ring + +lemma canonicalRadial_linear_integral (n : ℕ) {b : ℝ} (hb : 0 < b) + (z : Spin (n+1)) : + (∫⁻ x, ENNReal.ofReal (Real.exp (inner ℝ z x)) ∂canonicalRadialMass n b) = + ENNReal.ofReal (Real.exp (-((n+1:ℕ):ℝ)*Real.log b/2 + ‖z‖^2/(2*b))) := by + rw [canonicalRadialMass,lintegral_withDensity_eq_lintegral_mul _ + (canonicalRadialDensity_continuous n b).measurable.ennreal_ofReal (by fun_prop)] + simp only [Pi.mul_apply,← ENNReal.ofReal_mul (canonicalRadialDensity_pos n b _).le, + canonicalRadialDensity_complete_square n hb] + simp_rw [ENNReal.ofReal_mul (Real.exp_pos _).le] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + rw [lintegral_sub_right_eq_self (fun x => ENNReal.ofReal (canonicalRadialDensity n b x)) (b⁻¹ • z)] + rw [← ofReal_integral_eq_lintegral_ofReal (canonicalRadialDensity_integrable n hb) + (Eventually.of_forall fun x => (canonicalRadialDensity_pos n b x).le), + canonicalRadialDensity_integral n hb,← ENNReal.ofReal_mul (Real.exp_pos _).le, + Real.rpow_def_of_pos hb,← Real.exp_add] + congr 2 + ring + +def coordinateLeafField (d : ℕ) (x : Fin d → ℕ → ℝ) : Spin d := + WithLp.toLp 2 (fun i => x i 0) + +lemma coordinateLeafField_measurable (d : ℕ) : Measurable (coordinateLeafField d) := by + apply (MeasurableEquiv.toLp 2 (Fin d → ℝ)).measurable.comp + apply Measurable.of_eval + intro i + exact (measurable_pi_apply 0).comp (measurable_pi_apply i) + +lemma coordinateLeafField_norm_sq (d : ℕ) (x : Fin d → ℕ → ℝ) : + ‖coordinateLeafField d x‖^2 = ∑ i, (x i 0)^2 := by + rw [EuclideanSpace.norm_sq_eq] + simp only [coordinateLeafField,WithLp.ofLp_toLp,Real.norm_eq_abs,sq_abs] + +lemma canonicalCoordinatePotential_eq_norm (d : ℕ) (b : ℝ) (x : Fin d → ℕ → ℝ) : + canonicalCoordinatePotential d b x = - (d:ℝ)*Real.log b/2 + ‖coordinateLeafField d x‖^2/(2*b) := by + rw [coordinateLeafField_norm_sq] + simp only [canonicalCoordinatePotential,Finset.sum_add_distrib,Finset.sum_const, + Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,Finset.sum_div] + ring + +theorem canonicalCoordinateTotalE_eq_radial (n k : ℕ) (σ : ℕ → ℝ) {b : ℝ} (hb : 0 < b) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : + decoratedTerminalTotalE (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k p = + ∫⁻ x, decoratedFieldFactor (n+1) (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p x ∂canonicalRadialMass n b := by + let : SFinite (canonicalRadialMass n b) := by + unfold canonicalRadialMass + infer_instance + have hf : Measurable (fun q : Spin (n+1) × (Fin (n+1) → ℕ → ℝ) => + ENNReal.ofReal (Real.exp (inner ℝ (coordinateLeafField (n+1) q.2) q.1))) := + (((coordinateLeafField_measurable (n+1)).comp measurable_snd).inner measurable_fst).exp.ennreal_ofReal + have h := decoratedLeafIntegral_lintegral (canonicalRadialMass n b) + (canonicalCoordinateStep (n+1) σ) (canonicalCoordinateStep_measurable (n+1) σ) _ hf k p + change _ = ∫⁻ x, decoratedLeafIntegral (canonicalCoordinateStep (n+1) σ) + (fun y => ENNReal.ofReal (Real.exp (inner ℝ (coordinateLeafField (n+1) y) x))) k p + ∂canonicalRadialMass n b + rw [← h, ← decoratedLeafIntegral_exp] + congr 1 + funext y + change _ = ∫⁻ a, ENNReal.ofReal (Real.exp (inner ℝ (coordinateLeafField (n+1) y) a)) ∂canonicalRadialMass n b + rw [canonicalRadial_linear_integral n hb,canonicalCoordinatePotential_eq_norm] + +def sphericalCoordinateLog (n k : ℕ) (σ : ℕ → ℝ) (v : ℝ) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : ℝ := + Real.log ((decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p (Real.sqrt (((n+1:ℕ):ℝ)*v))).toReal / + decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + +lemma canonicalCoordinateLog_eq_radial (n k : ℕ) (σ : ℕ → ℝ) {b : ℝ} (hb : 0 < b) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : + canonicalCoordinateLog (n+1) k σ b p = + Real.log ((∫⁻ x, decoratedFieldFactor (n+1) (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p x ∂canonicalRadialMass n b).toReal / + decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) := by + unfold canonicalCoordinateLog decoratedTerminalTotal + rw [canonicalCoordinateTotalE_eq_radial n k σ hb] + +lemma decoratedLeafIntegral_holder {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X × S → X) (hs : Measurable step) {F G : X → ℝ≥0∞} + (hF : Measurable F) (hG : Measurable G) {a b : ℝ} + (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) (k : ℕ) + (p : X × DecoratedCascade S k) : + decoratedLeafIntegral step (fun x => F x ^ a * G x ^ b) k p ≤ + decoratedLeafIntegral step F k p ^ a * decoratedLeafIntegral step G k p ^ b := by + induction k with + | zero => exact le_rfl + | succ k ih => + let H : (ℝ × (S × DecoratedCascade S k)) → X × DecoratedCascade S k := + fun q => (step (p.1,q.2.1),q.2.2) + have hH : Measurable H := + (hs.comp (measurable_const.prodMk measurable_snd.fst)).prodMk measurable_snd.snd + have hFm : Measurable (fun q => ENNReal.ofReal (Real.exp q.1) * + decoratedLeafIntegral step F k (H q)) := + (measurable_fst.exp.ennreal_ofReal).mul + ((decoratedLeafIntegral_measurable step hs F hF k).comp hH) + have hGm : Measurable (fun q => ENNReal.ofReal (Real.exp q.1) * + decoratedLeafIntegral step G k (H q)) := + (measurable_fst.exp.ennreal_ofReal).mul + ((decoratedLeafIntegral_measurable step hs G hG k).comp hH) + change (∫⁻ q, ENNReal.ofReal (Real.exp q.1) * + decoratedLeafIntegral step (fun x => F x ^ a * G x ^ b) k (H q) + ∂markedStableCountKernel p.2) ≤ _ + refine le_trans (lintegral_mono fun q => mul_le_mul_right (ih (H q)) _) ?_ + calc + _ = ∫⁻ q, (ENNReal.ofReal (Real.exp q.1) * decoratedLeafIntegral step F k (H q)) ^ a * + (ENNReal.ofReal (Real.exp q.1) * decoratedLeafIntegral step G k (H q)) ^ b + ∂markedStableCountKernel p.2 := by + congr 1 + funext q + rw [ENNReal.mul_rpow_of_nonneg _ _ ha,ENNReal.mul_rpow_of_nonneg _ _ hb] + have he : ENNReal.ofReal (Real.exp q.1) ^ a * ENNReal.ofReal (Real.exp q.1) ^ b = + ENNReal.ofReal (Real.exp q.1) := by + rw [← ENNReal.rpow_add _ _ (by simp [Real.exp_pos]) ENNReal.ofReal_ne_top,hab,ENNReal.rpow_one] + calc + _ = (ENNReal.ofReal (Real.exp q.1) ^ a * ENNReal.ofReal (Real.exp q.1) ^ b) * + (decoratedLeafIntegral step F k (H q) ^ a * decoratedLeafIntegral step G k (H q) ^ b) := by rw [he] + _ = _ := by ring + _ ≤ _ := ENNReal.lintegral_mul_norm_pow_le hFm.aemeasurable hGm.aemeasurable ha hb hab + +lemma ofReal_exp_affine (x y a b : ℝ) : + ENNReal.ofReal (Real.exp (a*x+b*y)) = + ENNReal.ofReal (Real.exp x) ^ a * ENNReal.ofReal (Real.exp y) ^ b := by + rw [Real.exp_add, ENNReal.ofReal_mul (Real.exp_pos _).le] + congr 1 <;> rw [ENNReal.ofReal_rpow_of_pos (Real.exp_pos _),Real.rpow_def_of_pos (Real.exp_pos _),Real.log_exp] <;> congr 1 <;> ring_nf + +lemma sphericalExp_holder (n : ℕ) (z : Spin (n+1)) (r s : ℝ) {a b : ℝ} + (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) : + ENNReal.ofReal (sphericalExp n z (a*r+b*s)) ≤ + ENNReal.ofReal (sphericalExp n z r)^a * ENNReal.ofReal (sphericalExp n z s)^b := by + have he (t : ℝ) : ENNReal.ofReal (sphericalExp n z t) = + ∫⁻ x : Metric.sphere (0 : Spin (n+1)) 1, + ENNReal.ofReal (Real.exp (inner ℝ z (t • x.val))) ∂unitSphereLaw (n+1) := by + simp only [inner_smul_right] + exact ofReal_integral_eq_lintegral_ofReal + (unitSphere_continuous_integrable (by fun_prop)) + (ae_of_all _ fun _ => (Real.exp_pos _).le) + simp_rw [he] + have h (x : Metric.sphere (0 : Spin (n+1)) 1) : + ENNReal.ofReal (Real.exp (inner ℝ z ((a*r+b*s) • x.val))) = + ENNReal.ofReal (Real.exp (inner ℝ z (r • x.val)))^a * + ENNReal.ofReal (Real.exp (inner ℝ z (s • x.val)))^b := by + simp only [inner_smul_right] + rw [show (a*r+b*s)*inner ℝ z x.val = a*(r*inner ℝ z x.val)+b*(s*inner ℝ z x.val) by ring] + exact ofReal_exp_affine _ _ _ _ + simp_rw [h] + exact ENNReal.lintegral_mul_norm_pow_le (by fun_prop) (by fun_prop) ha hb hab + +lemma decoratedAngularFactor_holder {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (n : ℕ) (step : X × S → X) (hs : Measurable step) + (z : X → Spin (n+1)) (hz : Measurable z) (k : ℕ) (p : X × DecoratedCascade S k) + (r s : ℝ) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) : + decoratedAngularFactor n step z k p (a*r+b*s) ≤ + decoratedAngularFactor n step z k p r ^ a * decoratedAngularFactor n step z k p s ^ b := by + simp_rw [decoratedAngularFactor_eq n step hs z hz] + refine (decoratedLeafIntegral_mono step (fun x => sphericalExp_holder n (z x) r s ha hb hab) k p).trans ?_ + apply decoratedLeafIntegral_holder step hs _ _ ha hb hab + all_goals + unfold sphericalExp + apply ENNReal.measurable_ofReal.comp + exact (show StronglyMeasurable (fun p : X × Metric.sphere (0:Spin (n+1)) 1 => + Real.exp (_ * inner ℝ (z p.1) (p.2:Spin (n+1)))) from (by fun_prop)).integral_prod_right'.measurable + +lemma decoratedTerminalTotal_pos_of_fractional {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X × S → X) (hs : Measurable step) + (H : X → ℝ) (hH : Measurable H) (k : ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hI : finiteCascadeFractionalIntegrable ν step H k z) (x : X) : + ∀ᵐ η ∂(decoratedCascadeLaw ν k z : Measure (DecoratedCascade S k)), + 0 < decoratedTerminalTotal step H k (x,η) := by + have hid := decoratedWeightedTotal_identDistrib ν step hs k z hz0 hz1 + (finiteCascadeShifts ν step k z H) (finiteCascadeShifts_measurable ν step hs k z hH) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step k z + (fun j => (hz0 j).ne') H hI i y).1) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step k z + (fun j => (hz0 j).ne') H hI i y).2) x + have hp := hid.symm.ae_snd measurableSet_Ioi (cascadeTotal_regular k z hz hz0 hz1).1 + filter_upwards [hp] with η hη + rw [decoratedTerminalTotal_telescoping ν step H k z] + exact mul_pos (Real.exp_pos _) hη + +lemma decoratedTerminalTotal_zero_pos {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X × S → X) (hs : Measurable step) + (k : ℕ) (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (x : X) : + ∀ᵐ η ∂(decoratedCascadeLaw ν k z : Measure (DecoratedCascade S k)), + 0 < decoratedTerminalTotal step (fun _ => 0) k (x,η) := by + have hid := decoratedWeightedTotal_identDistrib ν step hs k z hz0 hz1 (fun _ _ => 0) + (fun _ => measurable_const) (by intro i y; simp only [mul_zero,Real.exp_zero]; exact integrable_const 1) + (by intro i y; simp) x + simpa only [decoratedTerminalTotal_zero] using + hid.symm.ae_snd measurableSet_Ioi (cascadeTotal_regular k z hz hz0 hz1).1 + +def coordinateCascadeLaw (d k : ℕ) (z : Fin k → ℝ) (r : ℝ≥0) : + Measure ((Fin d → ℝ) × DecoratedCascade (Fin d → ℝ) k) := + (Measure.pi (fun _ : Fin d => gaussianReal 0 r)).prod + (decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) k z) + +instance coordinateCascadeLaw_probability (d k : ℕ) (z : Fin k → ℝ) (r : ℝ≥0) : + IsProbabilityMeasure (coordinateCascadeLaw d k z r) := by + unfold coordinateCascadeLaw + infer_instance + +lemma canonicalCoordinateTotal_pos (d k : ℕ) (σ : ℕ → ℝ) (b : ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b k z) (r : ℝ≥0) : + ∀ᵐ p ∂coordinateCascadeLaw d k z r, + 0 < decoratedTerminalTotal (canonicalCoordinateStep d σ) + (canonicalCoordinatePotential d b) k ((fun i _ => p.1 i),p.2) := by + have hm : Measurable (fun p : (Fin d → ℝ) × DecoratedCascade (Fin d → ℝ) k => + decoratedTerminalTotal (canonicalCoordinateStep d σ) (canonicalCoordinatePotential d b) k + ((fun i _ => p.1 i),p.2)) := + (decoratedTerminalTotal_measurable (piMarkLaw (fun _ : Fin d => standardGaussianMark)) _ (canonicalCoordinateStep_measurable d σ) + (canonicalCoordinatePotential_measurable d b) k z).comp + (show Measurable (fun p : (Fin d → ℝ) × DecoratedCascade (Fin d → ℝ) k => + ((fun (i : Fin d) (_ : ℕ) => p.1 i),p.2)) from by fun_prop) + apply (Measure.ae_prod_iff_ae_ae (measurableSet_lt measurable_const hm)).mpr + exact ae_of_all _ fun x => decoratedTerminalTotal_pos_of_fractional + (piMarkLaw (fun _ : Fin d => standardGaussianMark)) (canonicalCoordinateStep d σ) + (canonicalCoordinateStep_measurable d σ) _ (canonicalCoordinatePotential_measurable d b) + k z hz hz0 hz1 (canonical_coordinate_recursion d σ b k z hz0 hp).2 (fun i _ => x i) + +lemma canonicalCoordinateBase_pos (d k : ℕ) (σ : ℕ → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (r : ℝ≥0) : + ∀ᵐ p ∂coordinateCascadeLaw d k z r, + 0 < decoratedTerminalTotal (canonicalCoordinateStep d σ) + (fun _ => 0) k ((fun i _ => p.1 i),p.2) := by + have hm : Measurable (fun p : (Fin d → ℝ) × DecoratedCascade (Fin d → ℝ) k => + decoratedTerminalTotal (canonicalCoordinateStep d σ) (fun _ => 0) k + ((fun i _ => p.1 i),p.2)) := + (decoratedTerminalTotal_measurable (piMarkLaw (fun _ : Fin d => standardGaussianMark)) _ (canonicalCoordinateStep_measurable d σ) + measurable_const k z).comp + (show Measurable (fun p : (Fin d → ℝ) × DecoratedCascade (Fin d → ℝ) k => + ((fun (i : Fin d) (_ : ℕ) => p.1 i),p.2)) from by fun_prop) + apply (Measure.ae_prod_iff_ae_ae (measurableSet_lt measurable_const hm)).mpr + exact ae_of_all _ fun x => decoratedTerminalTotal_zero_pos + (piMarkLaw (fun _ : Fin d => standardGaussianMark)) (canonicalCoordinateStep d σ) + (canonicalCoordinateStep_measurable d σ) k z hz hz0 hz1 (fun i _ => x i) + +lemma sphericalExp_le_gaussian (n : ℕ) (z : Spin (n+1)) (R : ℝ) {b : ℝ} (hb : 0 < b) : + sphericalExp n z R ≤ Real.exp (‖z‖^2/(2*b)+b*R^2/2) := by + have h (u : Metric.sphere (0 : Spin (n+1)) 1) : + R * inner ℝ z (u : Spin (n+1)) ≤ ‖z‖^2/(2*b)+b*R^2/2 := by + have hn : ‖(u : Spin (n+1))‖ = 1 := by simp + have hh := sq_nonneg ‖z - (b*R) • (u : Spin (n+1))‖ + rw [norm_sub_sq_real,inner_smul_right,norm_smul,hn,Real.norm_eq_abs,mul_one,sq_abs] at hh + calc + _ ≤ (‖z‖^2+(b*R)^2)/(2*b) := + (le_div_iff₀ (by positivity : 0 < 2*b)).mpr (by nlinarith [hh]) + _ = _ := by field_simp + unfold sphericalExp + calc + _ ≤ ∫ _ : Metric.sphere (0 : Spin (n+1)) 1, + Real.exp (‖z‖^2/(2*b)+b*R^2/2) ∂unitSphereLaw (n+1) := + integral_mono (unitSphere_continuous_integrable (by fun_prop)) (integrable_const _) + (fun u => Real.exp_le_exp.mpr (h u)) + _ = _ := by simp + +lemma decoratedAngularFactor_le_canonical (n k : ℕ) (σ : ℕ → ℝ) (R : ℝ) {b : ℝ} (hb : 0 < b) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : + decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) (coordinateLeafField (n+1)) k p R ≤ + ENNReal.ofReal (Real.exp (((n+1:ℕ):ℝ)*Real.log b/2+b*R^2/2)) * + decoratedTerminalTotalE (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p := by + rw [decoratedAngularFactor_eq n _ (canonicalCoordinateStep_measurable (n+1) σ) _ + (coordinateLeafField_measurable (n+1)), ← decoratedLeafIntegral_exp, + ← decoratedLeafIntegral_const_mul _ _ _ ENNReal.ofReal_ne_top] + apply decoratedLeafIntegral_mono + intro x + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le,← Real.exp_add,canonicalCoordinatePotential_eq_norm] + apply ENNReal.ofReal_le_ofReal + convert sphericalExp_le_gaussian n (coordinateLeafField (n+1) x) R hb using 1 + congr 1 + ring + +def coordinateAngularLog (n k : ℕ) (σ : ℕ → ℝ) (R : ℝ) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : ℝ := + Real.log ((decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p R).toReal / + decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + +lemma coordinateAngularLog_regular (n k : ℕ) (σ : ℕ → ℝ) (R : ℝ) {b : ℝ} (hb : 0 < b) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + (hc : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p) : + 0 < (decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p R).toReal ∧ + 0 ≤ coordinateAngularLog n k σ R p ∧ + coordinateAngularLog n k σ R p ≤ canonicalCoordinateLog (n+1) k σ b p + + ((n+1:ℕ):ℝ)*Real.log b/2+b*R^2/2 := by + let A := decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p R + let B := decoratedTerminalTotalE (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p + let C := decoratedTerminalTotalE (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p + let c := ((n+1:ℕ):ℝ)*Real.log b/2+b*R^2/2 + have hB : 0 < B.toReal := h0 + have hC : 0 < C.toReal := hc + obtain ⟨hB₀,hBtop⟩ := ENNReal.toReal_pos_iff.mp hB + obtain ⟨hC₀,hCtop⟩ := ENNReal.toReal_pos_iff.mp hC + have hba : B ≤ A := decoratedAngularFactor_mass_le n _ (canonicalCoordinateStep_measurable (n+1) σ) + _ (coordinateLeafField_measurable (n+1)) k p R + have hac : A ≤ ENNReal.ofReal (Real.exp c)*C := decoratedAngularFactor_le_canonical n k σ R hb p + have hAtop : A ≠ ∞ := ne_top_of_le_ne_top (ENNReal.mul_ne_top ENNReal.ofReal_ne_top hCtop.ne) hac + have hA := ENNReal.toReal_pos (ne_of_gt (hB₀.trans_le hba)) hAtop + have hba' := ENNReal.toReal_mono hAtop hba + have hac' := ENNReal.toReal_mono (ENNReal.mul_ne_top ENNReal.ofReal_ne_top hCtop.ne) hac + rw [ENNReal.toReal_mul,ENNReal.toReal_ofReal (Real.exp_pos _).le] at hac' + refine ⟨hA,?_,?_⟩ + · exact Real.log_nonneg ((le_div_iff₀ hB).mpr (by simpa using hba')) + · have hh := Real.log_le_log (div_pos hA hB) (div_le_div_of_nonneg_right hac' hB.le) + rw [Real.log_div (mul_pos (Real.exp_pos c) hC).ne' hB.ne', + Real.log_mul (Real.exp_pos c).ne' hC.ne',Real.log_exp] at hh + change Real.log (A.toReal/B.toReal) ≤ Real.log (C.toReal/B.toReal)+ + ((n+1:ℕ):ℝ)*Real.log b/2+b*R^2/2 + rw [Real.log_div hC.ne' hB.ne'] + dsimp only [c] at hh + linarith + +lemma coordinateAngularLog_convex (n k : ℕ) (σ : ℕ → ℝ) {b : ℝ} (hb : 0 < b) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + (hc : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p) : + ConvexOn ℝ Set.univ (fun R => coordinateAngularLog n k σ R p) := by + let A := fun R => decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p R + let B := decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p + have hA (R : ℝ) : 0 < (A R).toReal := (coordinateAngularLog_regular n k σ R hb p h0 hc).1 + have ht (R : ℝ) : A R ≠ ∞ := (ENNReal.toReal_pos_iff.mp (hA R)).2.ne + refine ⟨convex_univ,?_⟩ + intro R _ S _ a c ha hc' hac + have H := decoratedAngularFactor_holder n (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinateStep_measurable (n+1) σ) (coordinateLeafField (n+1)) + (coordinateLeafField_measurable (n+1)) k p R S ha hc' hac + have Hr := ENNReal.toReal_mono (ENNReal.mul_ne_top + (ENNReal.rpow_ne_top_of_nonneg ha (ht R)) (ENNReal.rpow_ne_top_of_nonneg hc' (ht S))) H + change (A (a*R+c*S)).toReal ≤ (A R ^ a * A S ^ c).toReal at Hr + rw [ENNReal.toReal_mul,← ENNReal.toReal_rpow,← ENNReal.toReal_rpow] at Hr + have Hlog := Real.log_le_log (hA (a*R+c*S)) Hr + rw [Real.log_mul (Real.rpow_pos_of_pos (hA R) a).ne' (Real.rpow_pos_of_pos (hA S) c).ne', + Real.log_rpow (hA R),Real.log_rpow (hA S)] at Hlog + simp only [smul_eq_mul] + change Real.log ((A (a*R+c*S)).toReal/B) ≤ a*Real.log ((A R).toReal/B)+c*Real.log ((A S).toReal/B) + rw [Real.log_div (hA _).ne' h0.ne',Real.log_div (hA R).ne' h0.ne',Real.log_div (hA S).ne' h0.ne'] + have hh := congrArg (fun t : ℝ => t * Real.log B) hac + nlinarith [Hlog, hh] + +lemma coordinateAngularLog_measurable (n k : ℕ) (σ : ℕ → ℝ) (R : ℝ) : + Measurable (coordinateAngularLog n k σ R) := by + let X := Fin (n+1) → ℕ → ℝ + let S := Fin (n+1) → ℝ + let F : Spin (n+1) × X → ℝ≥0∞ := fun q => ENNReal.ofReal (Real.exp (inner ℝ (coordinateLeafField (n+1) q.2) q.1)) + have hm := decoratedLeafIntegral_param_measurable (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinateStep_measurable (n+1) σ) F + ((((coordinateLeafField_measurable (n+1)).comp measurable_snd).inner measurable_fst).exp.ennreal_ofReal) k + have hmap : Measurable (fun q : (X × DecoratedCascade S k) × Metric.sphere (0:Spin (n+1)) 1 => + (R • (q.2:Spin (n+1)),q.1)) := + (measurable_snd.subtype_coe.const_smul R).prodMk measurable_fst + have hh := hm.comp hmap + have ha : Measurable (fun p : X × DecoratedCascade S k => + decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) (coordinateLeafField (n+1)) k p R) := + hh.lintegral_prod_right' + exact (ha.ennreal_toReal.div (decoratedTerminalTotal_measurable + (piMarkLaw (fun _ : Fin (n+1) => standardGaussianMark)) _ + (canonicalCoordinateStep_measurable (n+1) σ) measurable_const k (fun _ => 0))).log + +lemma coordinateAngularLog_integrable (n k : ℕ) (σ : ℕ → ℝ) {b : ℝ} (R : ℝ) + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b k z) (r : ℝ≥0) : + Integrable (fun p => coordinateAngularLog n k σ R ((fun i _ => p.1 i),p.2)) + (coordinateCascadeLaw (n+1) k z r) := by + have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le σ b k z (fun i => (hz0 i).le)) + have hm := (coordinateAngularLog_measurable n k σ R).comp + (show Measurable (fun p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k => + ((fun (i : Fin (n+1)) (_ : ℕ) => p.1 i),p.2)) from by fun_prop) + have hi := (canonical_coordinate_joint_mean (n+1) σ b k z hz hz0 hz1 hp r).1 + apply (hi.add (integrable_const (((n+1:ℕ):ℝ)*Real.log b/2+b*R^2/2))).mono' hm.aestronglyMeasurable + filter_upwards [canonicalCoordinateBase_pos (n+1) k σ z hz hz0 hz1 r, + canonicalCoordinateTotal_pos (n+1) k σ b z hz hz0 hz1 hp r] with p h0 hc + have h := coordinateAngularLog_regular n k σ R hb _ h0 hc + simp only [Function.comp_apply, Pi.add_apply] + rw [Real.norm_eq_abs,abs_of_nonneg h.2.1] + linarith [h.2.2] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/SphereHeat.lean b/lean/OAI/Probability/Perceptron/Sphere/SphereHeat.lean new file mode 100644 index 0000000000000000000000000000000000000000..be638703f65315c523051327003e74a92e31d07d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/SphereHeat.lean @@ -0,0 +1,130 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.NormSquareBand +import OAI.Probability.Perceptron.Variational.EntropicHeat + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +def logSphericalExp (n : ℕ) (R : ℝ) (x : Spin (n+1)) : ℝ := + Real.log (sphericalExp n x R) + +lemma sphericalExp_le_mul (n : ℕ) (R : ℝ) (x y : Spin (n+1)) : + sphericalExp n x R ≤ Real.exp (|R| *‖x-y‖)*sphericalExp n y R := by + unfold sphericalExp + rw [← integral_const_mul] + apply integral_mono (unitSphere_continuous_integrable (by fun_prop)) + (unitSphere_continuous_integrable (by fun_prop)) + intro u + dsimp only + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have hu : ‖(u:Spin (n+1))‖=1 := by simp + have hh := abs_real_inner_le_norm (x-y) (u:Spin (n+1)) + rw [hu,mul_one,inner_sub_left] at hh + have hm := mul_le_mul_of_nonneg_left hh (abs_nonneg R) + rw [← abs_mul] at hm + have hl := (le_abs_self (R*(inner ℝ x (u:Spin (n+1))-inner ℝ y (u:Spin (n+1))))).trans hm + linarith + +lemma logSphericalExp_lipschitz (n : ℕ) (R : ℝ) : + LipschitzWith ⟨|R|,abs_nonneg R⟩ (logSphericalExp n R) := by + have hle (x y : Spin (n+1)) : logSphericalExp n R x-logSphericalExp n R y ≤ |R| *‖x-y‖ := by + have hx : 0 < sphericalExp n x R := lt_of_lt_of_le zero_lt_one (one_le_sphericalExp n x R) + have hy : 0 < sphericalExp n y R := lt_of_lt_of_le zero_lt_one (one_le_sphericalExp n y R) + have hh := Real.log_le_log hx (sphericalExp_le_mul n R x y) + rw [Real.log_mul (Real.exp_pos _).ne' hy.ne',Real.log_exp] at hh + change Real.log (sphericalExp n x R)-Real.log (sphericalExp n y R) ≤ _ + linarith + apply LipschitzWith.of_dist_le_mul + intro x y + change |logSphericalExp n R x-logSphericalExp n R y| ≤ |R| *‖x-y‖ + apply abs_le.mpr + constructor + · have hh := hle y x + rw [norm_sub_rev] at hh + linarith + · exact hle x y + +lemma logSphericalExp_nonneg (n : ℕ) (R : ℝ) (x : Spin (n+1)) : + 0 ≤ logSphericalExp n R x := Real.log_nonneg (one_le_sphericalExp n x R) + +lemma logSphericalExp_zero (n : ℕ) (R : ℝ) : logSphericalExp n R 0=0 := by + simp [logSphericalExp,sphericalExp] + +lemma integral_exp_inner_stdGaussian {E : Type*} [NormedAddCommGroup E] + [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + (v : E) (a : ℝ) : (∫ x, Real.exp (a*inner ℝ v x) ∂stdGaussian E)= + Real.exp (a^2*‖v‖^2/2) := by + have H := mgf_gaussianReal + ⟨(innerSL ℝ v).continuous.measurable.aemeasurable, + IsGaussian.map_eq_gaussianReal (μ := stdGaussian E) (innerSL ℝ v)⟩ a + simp only [integral_strongDual_stdGaussian,variance_dual_stdGaussian,innerSL_apply_norm,Real.coe_toNNReal (‖v‖^2) (sq_nonneg ‖v‖),zero_mul,zero_add] at H + change (∫ x, Real.exp (a*inner ℝ v x) ∂stdGaussian E)=Real.exp (‖v‖^2*a^2/2) at H + convert H using 1 + congr 1 + ring + +lemma sphericalExp_gaussian_average (n : ℕ) (R σ : ℝ) (x : Spin (n+1)) : + (∫ y, sphericalExp n (x+σ • y) R ∂stdGaussian (Spin (n+1)))= + Real.exp (R^2*σ^2/2)*sphericalExp n x R := by + let μ := stdGaussian (Spin (n+1)) + let ν := unitSphereLaw (n+1) + have hI : Integrable (fun p : Spin (n+1)×Metric.sphere (0:Spin (n+1)) 1 => + Real.exp (R*inner ℝ (x+σ • p.1) (p.2:Spin (n+1)))) (μ.prod ν) := by + apply (((gaussian_integrable_exp_norm μ (|R| *|σ|)).const_mul (Real.exp (|R| *‖x‖))).comp_fst ν).mono' (by fun_prop) + exact ae_of_all _ fun p => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),← Real.exp_add] + apply Real.exp_le_exp.mpr + have hu : ‖(p.2:Spin (n+1))‖=1 := by simp + have hh := abs_real_inner_le_norm (x+σ • p.1) (p.2:Spin (n+1)) + rw [hu,mul_one] at hh + have ht := norm_add_le x (σ • p.1) + rw [norm_smul,Real.norm_eq_abs] at ht + have hb := mul_le_mul_of_nonneg_left (hh.trans ht) (abs_nonneg R) + rw [← abs_mul] at hb + have hl := (le_abs_self (R*inner ℝ (x+σ • p.1) (p.2:Spin (n+1)))).trans hb + nlinarith + have H := integral_integral_swap (f := fun (y : Spin (n+1)) (u : Metric.sphere (0:Spin (n+1)) 1) => + Real.exp (R*inner ℝ (x+σ • y) (u:Spin (n+1)))) hI + change (∫ y, ∫ u, Real.exp (R*inner ℝ (x+σ • y) (u:Spin (n+1))) ∂ν ∂μ)=_ at H + change (∫ y, ∫ u, Real.exp (R*inner ℝ (x+σ • y) (u:Spin (n+1))) ∂ν ∂μ)=_ + rw [H] + have he (u : Metric.sphere (0:Spin (n+1)) 1) : + (∫ y : Spin (n+1), Real.exp (R*inner ℝ (x+σ • y) (u:Spin (n+1))) ∂μ)= + Real.exp (R^2*σ^2/2)*Real.exp (R*inner ℝ x (u:Spin (n+1))) := by + simp only [inner_add_left,real_inner_smul_left,mul_add,Real.exp_add] + rw [integral_const_mul] + have hh := integral_exp_inner_stdGaussian (u:Spin (n+1)) (R*σ) + have hu : ‖(u:Spin (n+1))‖=1 := by simp + rw [hu] at hh + simp only [one_pow,mul_one] at hh + have hinner : (fun y : Spin (n+1) => Real.exp (R*(σ*inner ℝ y (u:Spin (n+1)))))= + (fun y => Real.exp ((R*σ)*inner ℝ (u:Spin (n+1)) y)) := by + funext y + rw [real_inner_comm y (u:Spin (n+1))] + congr 1 + ring + rw [hinner,hh,mul_pow] + ring + simp_rw [he] + rw [integral_const_mul] + rfl + +lemma gaussianEntropic_logSphericalExp_one (n : ℕ) (R σ : ℝ) (x : Spin (n+1)) : + gaussianEntropic (stdGaussian (Spin (n+1))) 1 σ (logSphericalExp n R) x= + logSphericalExp n R x+R^2*σ^2/2 := by + rw [gaussianEntropic_pos _ (logSphericalExp_lipschitz n R) (by norm_num)] + simp only [one_mul,div_one,logSphericalExp] + simp_rw [Real.exp_log (lt_of_lt_of_le zero_lt_one (one_le_sphericalExp n _ R))] + rw [sphericalExp_gaussian_average,Real.log_mul (Real.exp_pos _).ne' + (lt_of_lt_of_le zero_lt_one (one_le_sphericalExp n x R)).ne',Real.log_exp] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/SphereIsometryMap.lean b/lean/OAI/Probability/Perceptron/Sphere/SphereIsometryMap.lean new file mode 100644 index 0000000000000000000000000000000000000000..e11d4c4959a4baf530bfbcae790e6ed60b56b959 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/SphereIsometryMap.lean @@ -0,0 +1,440 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StableLogIntensity + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +section SphereInvariance +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def sphereIsometryMap (e : E ≃ₗᵢ[ℝ] E) (x : Metric.sphere (0 : E) 1) : + Metric.sphere (0 : E) 1 := ⟨e x, by simp⟩ + +omit [FiniteDimensional ℝ E] in +lemma sphereIsometryMap_measurable (e : E ≃ₗᵢ[ℝ] E) : Measurable (sphereIsometryMap e) := + (e.continuous.comp continuous_subtype_val).subtype_mk _ |>.measurable + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma sphereIsometryMap_preimage_cone (e : E ≃ₗᵢ[ℝ] E) (s : Set (Metric.sphere (0 : E) 1)) : + Ioo (0:ℝ) 1 • (Subtype.val '' (sphereIsometryMap e ⁻¹' s)) = + e ⁻¹' (Ioo (0:ℝ) 1 • (Subtype.val '' s)) := by + ext x + constructor + · rintro ⟨r,hr,v,⟨u,hu,rfl⟩,rfl⟩ + exact ⟨r,hr,e u,⟨sphereIsometryMap e u,hu,rfl⟩,by simp⟩ + · rintro ⟨r,hr,v,⟨u,hu,rfl⟩,he⟩ + refine ⟨r,hr,e.symm u,⟨sphereIsometryMap e.symm u,?_,rfl⟩,?_⟩ + · simpa [sphereIsometryMap] using hu + · apply e.injective + simpa only [map_smul,LinearIsometryEquiv.apply_symm_apply] using he + +lemma sphereIsometryMap_preserving (e : E ≃ₗᵢ[ℝ] E) : + MeasurePreserving (sphereIsometryMap e) (volume : Measure E).toSphere (volume : Measure E).toSphere := by + refine ⟨sphereIsometryMap_measurable e,?_⟩ + apply Measure.ext + intro s hs + rw [Measure.map_apply (sphereIsometryMap_measurable e) hs, + Measure.toSphere_apply' _ ((sphereIsometryMap_measurable e) hs),Measure.toSphere_apply' _ hs, + sphereIsometryMap_preimage_cone] + congr 1 + exact e.measurePreserving.measure_preimage_emb e.toHomeomorph.measurableEmbedding _ + +end SphereInvariance + +lemma unitSphereLaw_isometry_preserving {N : ℕ} (e : Spin N ≃ₗᵢ[ℝ] Spin N) : + MeasurePreserving (sphereIsometryMap e) (unitSphereLaw N) (unitSphereLaw N) := by + refine ⟨sphereIsometryMap_measurable e,?_⟩ + unfold unitSphereLaw + rw [Measure.map_smul _ (sphereIsometryMap_measurable e).aemeasurable, + (sphereIsometryMap_preserving e).map_eq] + +lemma sphereLaw_isometry_preserving {N : ℕ} (e : Spin N ≃ₗᵢ[ℝ] Spin N) : + MeasurePreserving e (sphereLaw N) (sphereLaw N) := by + refine ⟨e.continuous.measurable,?_⟩ + have hm : Measurable (fun x : Metric.sphere (0 : Spin N) 1 => Real.sqrt (N:ℝ) • x.val) := + (continuous_subtype_val.const_smul (Real.sqrt (N:ℝ))).measurable + rw [sphereLaw,Measure.map_map e.continuous.measurable hm] + have hc : (e ∘ fun x : Metric.sphere (0 : Spin N) 1 => Real.sqrt (N:ℝ) • x.val) = + (fun x : Metric.sphere (0 : Spin N) 1 => Real.sqrt (N:ℝ) • x.val) ∘ sphereIsometryMap e := by + funext x + exact e.map_smul _ _ + rw [hc] + rw [← Measure.map_map hm (sphereIsometryMap_measurable e), + (unitSphereLaw_isometry_preserving e).map_eq] + +section RotationCalculus +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + +noncomputable def skewFlow (A : E →L[ℝ] E) (hA : A ∈ skewAdjoint (E →L[ℝ] E)) (t : ℝ) : E ≃ₗᵢ[ℝ] E := by + letI : NormedAlgebra ℚ (E →L[ℝ] E) := NormedAlgebra.restrictScalars ℚ ℝ (E →L[ℝ] E) + exact Unitary.linearIsometryEquiv ⟨NormedSpace.exp (t • A), + NormedSpace.exp_mem_unitary_of_mem_skewAdjoint (by + rw [skewAdjoint.mem_iff] at hA ⊢ + simp [hA])⟩ + +lemma skewFlow_apply (A : E →L[ℝ] E) (hA : A ∈ skewAdjoint (E →L[ℝ] E)) (t : ℝ) (x : E) : + skewFlow A hA t x = NormedSpace.exp (t • A) x := rfl + +lemma skewFlow_zero (A : E →L[ℝ] E) (hA : A ∈ skewAdjoint (E →L[ℝ] E)) (x : E) : + skewFlow A hA 0 x = x := by simp [skewFlow_apply] + +lemma skewFlow_deriv (A : E →L[ℝ] E) (hA : A ∈ skewAdjoint (E →L[ℝ] E)) (t : ℝ) (x : E) : + HasDerivAt (fun u => skewFlow A hA u x) (A (skewFlow A hA t x)) t := by + simpa only [skewFlow_apply,mul_apply_eq_comp,map_zero, + add_zero] using (hasDerivAt_exp_smul_const' A t).clm_apply (hasDerivAt_const t x) + +variable [MeasurableSpace E] [BorelSpace E] + +lemma integrable_of_continuous_sphere_support (μ : Measure E) [IsFiniteMeasure μ] {R : ℝ} + (hR : ∀ᵐ x ∂μ, ‖x‖ ≤ R) {f : E → ℝ} (hf : Continuous f) : Integrable f μ := by + obtain ⟨C,hC⟩ := (isCompact_closedBall (0:E) R).exists_bound_of_continuousOn hf.continuousOn + exact Integrable.of_bound hf.aestronglyMeasurable C (hR.mono fun x hx => + hC x (by simpa only [Metric.mem_closedBall,dist_zero_right] using hx)) + +lemma invariant_skew_integral_zero (μ : Measure E) [IsFiniteMeasure μ] {R : ℝ} + (hR : ∀ᵐ x ∂μ, ‖x‖ ≤ R) (A : E →L[ℝ] E) (hA : A ∈ skewAdjoint (E →L[ℝ] E)) + (hμ : ∀ t, MeasurePreserving (skewFlow A hA t) μ μ) {f : E → ℝ} (hf : ContDiff ℝ 1 f) : + ∫ x, fderiv ℝ f x (A x) ∂μ = 0 := by + obtain ⟨C,hC⟩ := (isCompact_closedBall (0:E) R).exists_bound_of_continuousOn + (hf.continuous_fderiv (by norm_num)).continuousOn + have hDf (t : ℝ) : Continuous (fun x => fderiv ℝ f (skewFlow A hA t x) (A (skewFlow A hA t x))) := + ((hf.continuous_fderiv (by norm_num)).comp (skewFlow A hA t).continuous).clm_apply + (A.continuous.comp (skewFlow A hA t).continuous) + have hder := (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (μ := μ) (s := Set.univ) (x₀ := (0:ℝ)) + (F := fun t x => f (skewFlow A hA t x)) + (F' := fun t x => fderiv ℝ f (skewFlow A hA t x) (A (skewFlow A hA t x))) + (bound := fun _ => max C 0 * (‖A‖ * R)) (Filter.univ_mem) + (Filter.Eventually.of_forall fun t => (hf.continuous.comp (skewFlow A hA t).continuous).aestronglyMeasurable) + (integrable_of_continuous_sphere_support μ hR (hf.continuous.comp (skewFlow A hA 0).continuous)) + ((hDf 0).aestronglyMeasurable) (hR.mono fun x hx t _ => ?_) (integrable_const _) + (Filter.Eventually.of_forall fun x t _ => + (hf.differentiable (by norm_num) _).hasFDerivAt.comp_hasDerivAt t (skewFlow_deriv A hA t x))).2 + · have hconst (t : ℝ) : (∫ x, f (skewFlow A hA t x) ∂μ) = ∫ x, f x ∂μ := + (hμ t).integral_comp (skewFlow A hA t).toHomeomorph.measurableEmbedding f + have hc : HasDerivAt (fun t : ℝ => ∫ x, f (skewFlow A hA t x) ∂μ) 0 0 := by + simp_rw [hconst] + exact hasDerivAt_const _ _ + simpa only [skewFlow_zero] using hder.unique hc + · have hb : ‖fderiv ℝ f (skewFlow A hA t x)‖ ≤ max C 0 := + (hC _ (by simpa only [Metric.mem_closedBall,dist_zero_right,LinearIsometryEquiv.norm_map] using hx)).trans (le_max_left _ _) + calc + ‖fderiv ℝ f (skewFlow A hA t x) (A (skewFlow A hA t x))‖ ≤ + ‖fderiv ℝ f (skewFlow A hA t x)‖ * ‖A (skewFlow A hA t x)‖ := ContinuousLinearMap.le_opNorm _ _ + _ ≤ max C 0 * (‖A‖ * R) := mul_le_mul hb + ((A.le_opNorm _).trans (by rw [LinearIsometryEquiv.norm_map]; gcongr)) (norm_nonneg _) (le_max_right _ _) + +noncomputable def planeSkew (a y : E) : E →L[ℝ] E := + InnerProductSpace.rankOne ℝ a y - InnerProductSpace.rankOne ℝ y a + +omit [MeasurableSpace E] [BorelSpace E] in +lemma planeSkew_mem (a y : E) : planeSkew a y ∈ skewAdjoint (E →L[ℝ] E) := by + rw [skewAdjoint.mem_iff,planeSkew,star_sub,ContinuousLinearMap.star_eq_adjoint, + ContinuousLinearMap.star_eq_adjoint,InnerProductSpace.adjoint_rankOne,InnerProductSpace.adjoint_rankOne] + abel + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma planeSkew_apply (a y x : E) : planeSkew a y x = inner ℝ y x • a - inner ℝ a x • y := by + simp [planeSkew,InnerProductSpace.rankOne_apply] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma rotation_product_deriv {f : E → ℝ} (hf : ContDiff ℝ 1 f) (a y x : E) : + fderiv ℝ (fun z => inner ℝ a z * f z) x (planeSkew a y x) = + inner ℝ a (planeSkew a y x) * f x + inner ℝ a x * fderiv ℝ f x (planeSkew a y x) := by + have hh := ((innerSL ℝ a).hasFDerivAt.mul (hf.differentiable (by norm_num) x).hasFDerivAt).fderiv + have hh' : fderiv ℝ (fun z => inner ℝ a z * f z) x = + (inner ℝ a x) • fderiv ℝ f x + f x • (innerSL ℝ a) := by + simpa only [Pi.mul_def,coe_innerSL_apply,innerSL_apply_apply] using hh + rw [hh'] + simp [mul_comm,add_comm] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma sum_planeSkew (ι : Type*) [Fintype ι] (b : OrthonormalBasis ι ℝ E) (x y : E) : + ∑ i, inner ℝ (b i) x • planeSkew (b i) y x = + inner ℝ y x • x - (‖x‖^2) • y := by + have hn : ∑ i, (inner ℝ (b i) x)^2 = ‖x‖^2 := by + simpa only [real_inner_comm x,pow_two,real_inner_self_eq_norm_sq] using b.sum_inner_mul_inner x x + simp_rw [planeSkew_apply,smul_sub,smul_smul] + rw [Finset.sum_sub_distrib] + congr 1 + · calc + _ = ∑ i, inner ℝ y x • (inner ℝ (b i) x • b i) := by + apply Finset.sum_congr rfl + intro i _ + rw [smul_smul,mul_comm] + _ = _ := by rw [← Finset.smul_sum,b.sum_repr' x] + · rw [← Finset.sum_smul,← hn] + simp only [pow_two] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma sum_planeSkew_divergence (ι : Type*) [Fintype ι] (b : OrthonormalBasis ι ℝ E) (x y : E) : + ∑ i, inner ℝ (b i) (planeSkew (b i) y x) = (Fintype.card ι - 1 : ℝ) * inner ℝ y x := by + simp_rw [planeSkew_apply,inner_sub_right,inner_smul_right,b.inner_eq_one,mul_one] + rw [Finset.sum_sub_distrib,Finset.sum_const,Finset.card_univ,nsmul_eq_mul] + have hb : (∑ i, inner ℝ (b i) x * inner ℝ (b i) y) = inner ℝ y x := by + calc + _ = ∑ i, inner ℝ y (b i) * inner ℝ (b i) x := by + apply Finset.sum_congr rfl + intro i _ + rw [real_inner_comm y (b i),mul_comm] + _ = _ := b.sum_inner_mul_inner y x + rw [hb] + ring + +lemma invariant_tangent_integral (μ : Measure E) [IsFiniteMeasure μ] {R : ℝ} + (hR : ∀ᵐ x ∂μ, ‖x‖ ≤ R) (hμ : ∀ e : E ≃ₗᵢ[ℝ] E, MeasurePreserving e μ μ) + (ι : Type*) [Fintype ι] (b : OrthonormalBasis ι ℝ E) (y : E) {f : E → ℝ} (hf : ContDiff ℝ 1 f) : + ∫ x, fderiv ℝ f x ((‖x‖^2) • y - inner ℝ y x • x) ∂μ = + ∫ x, (Fintype.card ι - 1 : ℝ) * inner ℝ y x * f x ∂μ := by + let F : ι → E → ℝ := fun i x => inner ℝ (b i) x * f x + have hF (i) : ContDiff ℝ 1 (F i) := (innerSL ℝ (b i)).contDiff.mul hf + have hI (i) : Integrable (fun x => fderiv ℝ (F i) x (planeSkew (b i) y x)) μ := + integrable_of_continuous_sphere_support μ hR + (((hF i).continuous_fderiv (by norm_num)).clm_apply (planeSkew (b i) y).continuous) + have hzero (i) := invariant_skew_integral_zero μ hR (planeSkew (b i) y) (planeSkew_mem _ _) + (fun t => hμ (skewFlow _ (planeSkew_mem _ _) t)) (hF i) + have halg (x) : (∑ i, fderiv ℝ (F i) x (planeSkew (b i) y x)) = + (Fintype.card ι - 1 : ℝ) * inner ℝ y x * f x - + fderiv ℝ f x ((‖x‖^2) • y - inner ℝ y x • x) := by + simp_rw [F,rotation_product_deriv hf,Finset.sum_add_distrib] + rw [← Finset.sum_mul,sum_planeSkew_divergence] + have hh : (∑ i, inner ℝ (b i) x * fderiv ℝ f x (planeSkew (b i) y x)) = + fderiv ℝ f x (inner ℝ y x • x - (‖x‖^2) • y) := by + rw [← sum_planeSkew ι b x y,map_sum] + simp only [map_smul,smul_eq_mul] + rw [hh,map_sub,map_sub] + ring + have hi₁ := integrable_of_continuous_sphere_support μ hR + (show Continuous (fun x => (Fintype.card ι - 1 : ℝ)*inner ℝ y x*f x) by fun_prop) + have hi₂ := integrable_of_continuous_sphere_support μ hR + (show Continuous (fun x => fderiv ℝ f x ((‖x‖^2) • y - inner ℝ y x • x)) from + (hf.continuous_fderiv (by norm_num)).clm_apply (by fun_prop)) + have he : (∫ x, (Fintype.card ι - 1 : ℝ)*inner ℝ y x*f x ∂μ) - + (∫ x, fderiv ℝ f x ((‖x‖^2) • y - inner ℝ y x • x) ∂μ) = 0 := by + rw [← integral_sub hi₁ hi₂] + simp_rw [← halg] + rw [integral_finsetSum _ (fun i _ => hI i)] + simp only [hzero,Finset.sum_const_zero] + linarith + +end RotationCalculus +lemma sphereLaw_ae_norm (N : ℕ) : ∀ᵐ x ∂sphereLaw N, ‖x‖ = Real.sqrt (N:ℝ) := by + have hm : Measurable (fun x : Metric.sphere (0 : Spin N) 1 => Real.sqrt (N:ℝ) • x.val) := + (continuous_subtype_val.const_smul (Real.sqrt (N:ℝ))).measurable + rw [sphereLaw,ae_map_iff hm.aemeasurable (measurableSet_eq_fun continuous_norm.measurable measurable_const)] + exact Filter.Eventually.of_forall fun x => by + have hx : ‖x.val‖ = 1 := by simpa only [Metric.mem_sphere,dist_zero_right] using x.property + simp only [norm_smul,Real.norm_eq_abs,abs_of_nonneg (Real.sqrt_nonneg _),hx,mul_one] + +local instance (N : ℕ) : IsFiniteMeasure (sphereLaw N) := by + unfold sphereLaw unitSphereLaw + infer_instance + +lemma sphere_integrable_of_continuous (N : ℕ) {f : Spin (N+1) → ℝ} (hf : Continuous f) : + Integrable f (sphereLaw (N+1)) := + integrable_of_continuous_sphere_support _ ((sphereLaw_ae_norm (N+1)).mono fun _ hx => hx.le) hf + +lemma sphere_tangent_integral (N : ℕ) (y : Spin (N+1)) {f : Spin (N+1) → ℝ} (hf : ContDiff ℝ 1 f) : + ∫ x, fderiv ℝ f x (((N+1:ℕ):ℝ) • y - inner ℝ y x • x) ∂sphereLaw (N+1) = + (N:ℝ) * ∫ x, inner ℝ y x * f x ∂sphereLaw (N+1) := by + have hh := invariant_tangent_integral (sphereLaw (N+1)) + ((sphereLaw_ae_norm (N+1)).mono fun _ hx => hx.le) (fun e => sphereLaw_isometry_preserving e) + (Fin (N+1)) (EuclideanSpace.basisFun (Fin (N+1)) ℝ) y hf + calc + _ = ∫ x, fderiv ℝ f x ((‖x‖^2) • y - inner ℝ y x • x) ∂sphereLaw (N+1) := by + apply integral_congr_ae + filter_upwards [sphereLaw_ae_norm (N+1)] with x hx + rw [hx,Real.sq_sqrt (by positivity)] + _ = _ := by simpa only [Fintype.card_fin,Nat.cast_add,Nat.cast_one,add_sub_cancel_right, + mul_assoc,integral_const_mul] using hh + +def sphereOverlap {N : ℕ} (x y : Spin N) : ℝ := inner ℝ y x / (N:ℝ) + +lemma sphere_tangent_integral_normalized (N : ℕ) (y : Spin (N+1)) {f : Spin (N+1) → ℝ} + (hf : ContDiff ℝ 1 f) : + ∫ x, fderiv ℝ f x (y - sphereOverlap x y • x) ∂sphereLaw (N+1) = + (N:ℝ) * ∫ x, sphereOverlap x y * f x ∂sphereLaw (N+1) := by + have hd : ((N+1:ℕ):ℝ) ≠ 0 := by positivity + apply mul_left_cancel₀ hd + rw [← integral_const_mul] + have he (x : Spin (N+1)) : ((N+1:ℕ):ℝ) * fderiv ℝ f x (y - sphereOverlap x y • x) = + fderiv ℝ f x (((N+1:ℕ):ℝ) • y - inner ℝ y x • x) := by + rw [← smul_eq_mul,← map_smul,smul_sub,smul_smul] + simp only [sphereOverlap,mul_div_cancel₀ _ hd] + simp_rw [he] + rw [sphere_tangent_integral N y hf] + have hr : (∫ x, inner ℝ y x*f x ∂sphereLaw (N+1)) = + ((N+1:ℕ):ℝ) * ∫ x, sphereOverlap x y * f x ∂sphereLaw (N+1) := by + rw [← integral_const_mul] + congr 1 + funext x + dsimp [sphereOverlap] + field_simp + rw [hr] + ring + +lemma sphereOverlap_hasFDerivAt (N : ℕ) (y x : Spin (N+1)) : + HasFDerivAt (fun z => sphereOverlap z y) (((N+1:ℕ):ℝ)⁻¹ • innerSL ℝ y) x := by + simpa only [sphereOverlap,Pi.smul_def,smul_eq_mul,div_eq_mul_inv,mul_comm,coe_innerSL_apply] using + (innerSL ℝ y).hasFDerivAt.const_smul (((N+1:ℕ):ℝ)⁻¹) + +lemma sphereOverlap_tangent_deriv (N : ℕ) (y : Spin (N+1)) (hy : ‖y‖^2 = ((N+1:ℕ):ℝ)) + (x : Spin (N+1)) : + ((((N+1:ℕ):ℝ)⁻¹ • innerSL ℝ y) (y - sphereOverlap x y • x)) = 1 - sphereOverlap x y ^ 2 := by + have hd : ((N+1:ℕ):ℝ) ≠ 0 := by positivity + simp only [smul_apply,innerSL_apply_apply,inner_sub_right,inner_smul_right, + real_inner_self_eq_norm_sq,hy,smul_eq_mul,sphereOverlap] + field_simp + +lemma sphere_gibbs_tangent_identity (N : ℕ) (y : Spin (N+1)) (hy : ‖y‖^2 = ((N+1:ℕ):ℝ)) + {H : Spin (N+1) → ℝ} (hH : ContDiff ℝ 1 H) {G : ℝ → ℝ} (hG : ContDiff ℝ 1 G) : + (N:ℝ) * (∫ x, sphereOverlap x y * (G (sphereOverlap x y) * Real.exp (H x)) ∂sphereLaw (N+1)) = + ∫ x, (deriv G (sphereOverlap x y) * (1-sphereOverlap x y^2) + + G (sphereOverlap x y)*fderiv ℝ H x (y-sphereOverlap x y • x))*Real.exp (H x) ∂sphereLaw (N+1) := by + let F : Spin (N+1) → ℝ := fun x => G (sphereOverlap x y) * Real.exp (H x) + have hR : ContDiff ℝ 1 (fun x : Spin (N+1) => sphereOverlap x y) := by + unfold sphereOverlap + exact (innerSL ℝ y).contDiff.div_const _ + have hF : ContDiff ℝ 1 F := (hG.comp hR).mul hH.exp + rw [← sphere_tangent_integral_normalized N y hF] + apply integral_congr_ae + exact Filter.Eventually.of_forall fun x => by + have hh := (((hG.differentiable (by norm_num) (sphereOverlap x y)).hasDerivAt.comp_hasFDerivAt x + (sphereOverlap_hasFDerivAt N y x)).mul (hH.differentiable (by norm_num) x).hasFDerivAt.exp).fderiv + have he : fderiv ℝ F x = G (sphereOverlap x y) • (Real.exp (H x) • fderiv ℝ H x) + + Real.exp (H x) • (deriv G (sphereOverlap x y) • (((N+1:ℕ):ℝ)⁻¹ • innerSL ℝ y)) := by + simpa only [F,Pi.mul_def,Function.comp_def] using hh + dsimp only + rw [he] + simp only [add_apply,smul_apply,smul_eq_mul, + sphereOverlap_tangent_deriv N y hy] + ring + +def poissonMarkMeasure {S : Type*} [MeasurableSpace S] (η : Measure (ℝ × S)) : Measure S := + (η.withDensity (fun p => ENNReal.ofReal (Real.exp p.1))).map Prod.snd + +def normalizedMeasure {S : Type*} [MeasurableSpace S] (μ : Measure S) : Measure S := + (μ univ)⁻¹ • μ + +lemma measurable_measure_withDensity_fixed {S : Type*} [MeasurableSpace S] + {f : S → ℝ≥0∞} (hf : Measurable f) : Measurable (fun μ : Measure S => μ.withDensity f) := by + refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ + simp only [withDensity_apply _ hs,← lintegral_indicator hs] + exact Measure.measurable_lintegral (hf.indicator hs) + +lemma poissonMarkMeasure_measurable {S : Type*} [MeasurableSpace S] : + Measurable (poissonMarkMeasure (S := S)) := + (Measure.measurable_map _ measurable_snd).comp + (measurable_measure_withDensity_fixed (by fun_prop)) + +lemma normalizedMeasure_measurable {S : Type*} [MeasurableSpace S] : + Measurable (normalizedMeasure (S := S)) := by + refine Measure.measurable_of_measurable_coe _ fun s hs => ?_ + change Measurable (fun μ : Measure S => (μ univ)⁻¹ * μ s) + exact (Measure.measurable_coe MeasurableSet.univ).inv.mul (Measure.measurable_coe hs) + +lemma normalizedMeasure_probability {S : Type*} [MeasurableSpace S] (μ : Measure S) + (h0 : μ univ ≠ 0) (hf : μ univ ≠ ⊤) : IsProbabilityMeasure (normalizedMeasure μ) := by + constructor + change (μ univ)⁻¹ * μ univ = 1 + exact ENNReal.inv_mul_cancel h0 hf + +lemma normalizedMeasure_smul {S : Type*} [MeasurableSpace S] (μ : Measure S) + {c : ℝ≥0∞} (hc0 : c ≠ 0) (hcf : c ≠ ⊤) : + normalizedMeasure (c • μ) = normalizedMeasure μ := by + unfold normalizedMeasure + rw [Measure.smul_apply,smul_eq_mul,ENNReal.mul_inv (Or.inl hc0) (Or.inl hcf),smul_smul] + congr 1 + calc + c⁻¹ * (μ univ)⁻¹ * c = c⁻¹*c*(μ univ)⁻¹ := by ac_rfl + _ = _ := by rw [ENNReal.inv_mul_cancel hc0 hcf,one_mul] + +lemma map_withDensity_comp {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + (μ : Measure S) {f : S → T} (hf : Measurable f) {g : T → ℝ≥0∞} (hg : Measurable g) : + (μ.map f).withDensity g = (μ.withDensity (g ∘ f)).map f := by + apply Measure.ext_of_lintegral + intro h hh + rw [lintegral_withDensity_eq_lintegral_mul _ hg hh, + lintegral_map (hg.mul hh) hf,lintegral_map hh hf] + rw [lintegral_withDensity_eq_lintegral_mul _ (hg.comp hf) (show Measurable (fun x => h (f x)) from hh.comp hf)] + rfl + +lemma poissonMarkMeasure_shift {S : Type*} [MeasurableSpace S] + (η : Measure (ℝ × S)) {F : S → ℝ} (hF : Measurable F) : + poissonMarkMeasure (η.map (logMarkShift F)) = + (poissonMarkMeasure η).withDensity (fun s => ENNReal.ofReal (Real.exp (F s))) := by + unfold poissonMarkMeasure + rw [map_withDensity_comp _ (logMarkShift_measurable hF) (by fun_prop), + Measure.map_map measurable_snd (logMarkShift_measurable hF), + map_withDensity_comp _ measurable_snd (by fun_prop),← withDensity_mul _ (by fun_prop) (by fun_prop)] + congr 1 + congr 1 + funext p + simp only [Function.comp_def,logMarkShift,Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos _).le,Pi.mul_apply] + +lemma poissonMarkMeasure_mass {S : Type*} [MeasurableSpace S] (η : Measure (ℝ × S)) : + poissonMarkMeasure η univ = ∫⁻ p, ENNReal.ofReal (Real.exp p.1) ∂η := by + unfold poissonMarkMeasure + rw [Measure.map_apply measurable_snd MeasurableSet.univ] + simp only [preimage_univ,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + +lemma poissonMarkMeasure_probability {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) : + ∀ᵐ η ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν), + IsProbabilityMeasure (normalizedMeasure (poissonMarkMeasure η)) := by + have he : (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).map (Measure.map Prod.fst) = + poissonRandomMeasureLaw (stableLogIntensity b) := by + rw [poissonRandomMeasureLaw_map _ measurable_fst] + simp only [Measure.map_fst_prod,measure_univ,one_smul] + have hh : ∀ᵐ η ∂poissonRandomMeasureLaw (stableLogIntensity b), + (∫⁻ x, ENNReal.ofReal (Real.exp x) ∂η) ≠ 0 ∧ + (∫⁻ x, ENNReal.ofReal (Real.exp x) ∂η) ≠ ⊤ := by + filter_upwards [stablePoisson_total_positive hb0,stablePoisson_total_finite hb0 hb1] with η h1 h2 + exact ⟨h1.ne',h2⟩ + rw [← he] at hh + have hmeas : Measurable (fun η : Measure ℝ => ∫⁻ x, ENNReal.ofReal (Real.exp x) ∂η) := + Measure.measurable_lintegral (by fun_prop) + have hh' := (ae_map_iff (Measure.measurable_map _ measurable_fst).aemeasurable + (((measurableSet_eq_fun hmeas measurable_const).compl).inter + ((measurableSet_eq_fun hmeas measurable_const).compl))).mp hh + filter_upwards [hh'] with η hη + change (∫⁻ x, ENNReal.ofReal (Real.exp x) ∂η.map Prod.fst) ≠ 0 ∧ + (∫⁻ x, ENNReal.ofReal (Real.exp x) ∂η.map Prod.fst) ≠ ⊤ at hη + rw [lintegral_map (by fun_prop) measurable_fst] at hη + exact normalizedMeasure_probability _ (by simpa only [poissonMarkMeasure_mass] using hη.1) (by simpa only [poissonMarkMeasure_mass] using hη.2) + +lemma stablePoisson_gibbs_measure_law {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb : 0 ≤ b) + {F : S → ℝ} (hF : Measurable F) : + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).map + (fun η => normalizedMeasure ((poissonMarkMeasure η).withDensity + (fun s => ENNReal.ofReal (Real.exp (F s))))) = + (poissonRandomMeasureLaw ((stableLogIntensity b).prod + (ν.withDensity (fun s => ENNReal.ofReal (Real.exp (b*F s)))))).map + (fun η => normalizedMeasure (poissonMarkMeasure η)) := by + rw [← stablePoisson_mark_shift ν hb hF, + Measure.map_map (show Measurable (fun η => normalizedMeasure (poissonMarkMeasure η)) from + normalizedMeasure_measurable.comp poissonMarkMeasure_measurable) + (show Measurable (Measure.map (logMarkShift F)) from + Measure.measurable_map _ (logMarkShift_measurable hF))] + congr 1 + funext η + simp only [Function.comp_def,poissonMarkMeasure_shift η hF] + +open Matrix +open scoped RealInnerProductSpace MatrixOrder + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/SphereKernel.lean b/lean/OAI/Probability/Perceptron/Sphere/SphereKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..01fb041259ab66b1d450c0ae75803fd5d066b333 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/SphereKernel.lean @@ -0,0 +1,422 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.TripleIndex + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +theorem joint_gg_crossed_regions_null (μ : Measure PairedOverlapArray) [IsProbabilityMeasure μ] + (hGG : JointGhirlandaGuerra μ) + (hNo : ∀ᵐ Q ∂μ, ¬ ((Q 0 1).1 < (Q 0 2).1 ∧ (Q 0 2).2 < (Q 0 1).2)) + (s t : Set (ℝ × ℝ)) (hs : MeasurableSet s) (ht : MeasurableSet t) + (hst : ∀ u ∈ s, ∀ v ∈ t, u.1 < v.1 ∧ v.2 < u.2) : + μ {Q | Q 0 1 ∈ s} = 0 ∨ μ {Q | Q 0 1 ∈ t} = 0 := by + let S : Set (PairedOverlapBlock 2) := {A | A 0 1 ∈ s} + have hS : MeasurableSet S := hs.preimage + ((measurable_pi_apply 1).comp (measurable_pi_apply 0)) + have hnull : μ (pairedBlock 2 ⁻¹' S ∩ {Q | Q 0 2 ∈ t}) = 0 := by + apply measure_eq_zero_iff_ae_notMem.mpr + filter_upwards [hNo] with Q hQ + rintro ⟨h₁, h₂⟩ + exact hQ (hst (Q 0 1) h₁ (Q 0 2) h₂) + have hid := hGG 2 (by omega) 0 S hS t ht + have hzero : μ.real (pairedBlock 2 ⁻¹' S ∩ {Q | Q 0 2 ∈ t}) = 0 := by + simp only [measureReal_def, hnull, ENNReal.toReal_zero] + have hsum : 0 ≤ ∑ j ∈ (Finset.univ.erase (0 : Fin 2)), + μ.real (pairedBlock 2 ⁻¹' S ∩ {Q | Q 0 j ∈ t}) := + Finset.sum_nonneg fun _ _ => measureReal_nonneg + have hprod : μ.real {Q | Q 0 1 ∈ s} * μ.real {Q | Q 0 1 ∈ t} = 0 := by + change μ.real (pairedBlock 2 ⁻¹' S) * μ.real {Q | Q 0 1 ∈ t} = 0 + simp only [Fin.val_zero, Nat.cast_ofNat] at hid + rw [hzero] at hid + have h₁ := measureReal_nonneg (μ := μ) (s := pairedBlock 2 ⁻¹' S) + have h₂ := measureReal_nonneg (μ := μ) (s := {Q | Q 0 1 ∈ t}) + nlinarith [mul_nonneg h₁ h₂] + rcases mul_eq_zero.mp hprod with h | h + · left + exact ((ENNReal.toReal_eq_zero_iff _).mp h).resolve_right (measure_ne_top _ _) + · right + exact ((ENNReal.toReal_eq_zero_iff _).mp h).resolve_right (measure_ne_top _ _) + +theorem weighted_kernel_homogeneous_eq_zero {X : Type*} [MeasurableSpace X] + (μ : Measure X) [NeZero μ] {D : X → ℝ} {K : X → X → ℝ} {B : ℝ} + (hB : B < 1) (hD : ∀ᵐ r ∂μ, 0 < D r) + (hK : ∀ r, Integrable (K r) μ) (hKpos : ∀ᵐ r ∂μ, ∀ᵐ s ∂μ, 0 ≤ K r s) + (hrow : ∀ᵐ r ∂μ, (∫ s, K r s ∂μ) ≤ B * D r) + {f : X → ℝ} (hf : AEStronglyMeasurable f μ) + (hbounded : ∃ M : ℝ, ∀ᵐ r ∂μ, |f r| ≤ M) + (heq : ∀ᵐ r ∂μ, f r * D r = ∫ s, K r s * f s ∂μ) : + f =ᵐ[μ] 0 := by + let C : ℝ := essSup (fun r => |f r|) μ + obtain ⟨M, hM⟩ := hbounded + have hb : IsBoundedUnder (· ≤ ·) (ae μ) (fun r => |f r|) := + isBoundedUnder_of_eventually_le hM + have hcob : IsCoboundedUnder (· ≤ ·) (ae μ) (fun r => |f r|) := + isCoboundedUnder_le_of_le (ae μ) (fun r => abs_nonneg (f r)) + have hfC : ∀ᵐ r ∂μ, |f r| ≤ C := ae_le_essSup hb + have hC : 0 ≤ C := by + obtain ⟨r, hr⟩ := hfC.exists + exact (abs_nonneg (f r)).trans hr + have hsmall : ∀ᵐ r ∂μ, |f r| ≤ B * C := by + filter_upwards [hD, hKpos, hrow, heq] with r hrD hrK hrrow hreq + have hbound : ∀ᵐ s ∂μ, ‖K r s * f s‖ ≤ K r s * C := by + filter_upwards [hrK, hfC] with s hsK hsC + rw [Real.norm_eq_abs, abs_mul, abs_of_nonneg hsK] + exact mul_le_mul_of_nonneg_left hsC hsK + have hi : Integrable (fun s => K r s * f s) μ := + ((hK r).mul_const C).mono' ((hK r).aestronglyMeasurable.mul hf) hbound + have hh : |f r| * D r ≤ B * D r * C := by + calc + |f r| * D r = |f r * D r| := by rw [abs_mul, abs_of_pos hrD] + _ = |∫ s, K r s * f s ∂μ| := by rw [hreq] + _ ≤ ∫ s, ‖K r s * f s‖ ∂μ := by + simpa only [Real.norm_eq_abs] using + (norm_integral_le_integral_norm (fun s => K r s * f s) (μ := μ)) + _ ≤ ∫ s, K r s * C ∂μ := + integral_mono_ae hi.norm ((hK r).mul_const C) hbound + _ = (∫ s, K r s ∂μ) * C := integral_mul_const C (K r) + _ ≤ B * D r * C := mul_le_mul_of_nonneg_right hrrow hC + nlinarith + have hCC : C ≤ B * C := essSup_le_of_ae_le (B * C) hsmall hcob + have hC0 : C = 0 := by nlinarith + filter_upwards [hfC] with r hr + exact abs_eq_zero.mp (le_antisymm (by simpa only [hC0] using hr) (abs_nonneg _)) + +def sphereKernel (r s : Time) : ℝ := min (r : ℝ) (s : ℝ) - (r : ℝ) * (s : ℝ) + +def sphereTail (μ : Measure Time) (r : Time) : ℝ := + ∫ s, 1 - max (r : ℝ) (s : ℝ) ∂μ + +lemma sphereKernel_nonneg (r s : Time) : 0 ≤ sphereKernel r s := by + unfold sphereKernel + rcases le_total (r : ℝ) (s : ℝ) with h | h + · rw [min_eq_left h] + nlinarith [r.property.1, s.property.2] + · rw [min_eq_right h] + nlinarith [s.property.1, r.property.2] + +lemma sphereKernel_le_weight (r s : Time) : + sphereKernel r s ≤ (r : ℝ) * (1 - max (r : ℝ) (s : ℝ)) := by + unfold sphereKernel + rcases le_total (r : ℝ) (s : ℝ) with h | h + · rw [min_eq_left h, max_eq_right h] + ring_nf + exact le_rfl + · rw [min_eq_right h, max_eq_left h] + nlinarith [r.property.2] + +lemma sphereTail_integrable (μ : Measure Time) [IsFiniteMeasure μ] (r : Time) : + Integrable (fun s : Time => 1 - max (r : ℝ) (s : ℝ)) μ := by + apply (integrable_const (1 : ℝ)).mono' (by fun_prop) + filter_upwards [] with s + rw [Real.norm_eq_abs, abs_of_nonneg (by + have := r.property.2 + have := s.property.2 + simp only [sub_nonneg, max_le_iff] + exact ⟨‹_›, ‹_›⟩)] + have h := r.property.1 + have hh : (r : ℝ) ≤ max (r : ℝ) (s : ℝ) := le_max_left _ _ + linarith + +lemma sphereKernel_integrable (μ : Measure Time) [IsFiniteMeasure μ] (r : Time) : + Integrable (sphereKernel r) μ := by + apply (integrable_const (1 : ℝ)).mono' (by unfold sphereKernel; fun_prop) + filter_upwards [] with s + rw [Real.norm_eq_abs, abs_of_nonneg (sphereKernel_nonneg r s)] + have h := sphereKernel_le_weight r s + have hmax : 0 ≤ max (r : ℝ) (s : ℝ) := r.property.1.trans (le_max_left _ _) + nlinarith [r.property.1, r.property.2] + +lemma sphereTail_lower (μ : Measure Time) [IsProbabilityMeasure μ] {B : ℝ} + (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) {r : Time} (hr : (r : ℝ) ≤ B) : + 1 - B ≤ sphereTail μ r := by + calc + _ = ∫ _ : Time, 1 - B ∂μ := by simp + _ ≤ _ := integral_mono_ae (integrable_const _) (sphereTail_integrable μ r) (by + filter_upwards [hμ] with s hs + exact sub_le_sub_left (max_le hr hs) 1) + +lemma sphereKernel_row_bound (μ : Measure Time) [IsProbabilityMeasure μ] + {B : ℝ} {r : Time} (hr : (r : ℝ) ≤ B) : + (∫ s, sphereKernel r s ∂μ) ≤ B * sphereTail μ r := by + have htail : 0 ≤ sphereTail μ r := integral_nonneg (fun s => + sub_nonneg.mpr (max_le r.property.2 s.property.2)) + calc + _ ≤ ∫ s, (r : ℝ) * (1 - max (r : ℝ) (s : ℝ)) ∂μ := + integral_mono (sphereKernel_integrable μ r) ((sphereTail_integrable μ r).const_mul _) + (sphereKernel_le_weight r) + _ = (r : ℝ) * sphereTail μ r := integral_const_mul _ _ + _ ≤ _ := mul_le_mul_of_nonneg_right hr htail + +theorem sphere_equation_unique (μ : Measure Time) [IsProbabilityMeasure μ] + {B : ℝ} (hB : B < 1) (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) + {a b : Time → ℝ} (ha : AEStronglyMeasurable a μ) (hb : AEStronglyMeasurable b μ) + (haBound : ∃ C : ℝ, ∀ᵐ r ∂μ, |a r| ≤ C) + (hbBound : ∃ C : ℝ, ∀ᵐ r ∂μ, |b r| ≤ C) + (haEq : ∀ᵐ r ∂μ, a r * sphereTail μ r = (r : ℝ) + ∫ s, sphereKernel r s * a s ∂μ) + (hbEq : ∀ᵐ r ∂μ, b r * sphereTail μ r = (r : ℝ) + ∫ s, sphereKernel r s * b s ∂μ) : + a =ᵐ[μ] b := by + obtain ⟨A, hA⟩ := haBound + obtain ⟨B', hB'⟩ := hbBound + have hzero : (fun r => a r - b r) =ᵐ[μ] 0 := + weighted_kernel_homogeneous_eq_zero μ (D := sphereTail μ) (K := sphereKernel) hB + (by filter_upwards [hμ] with r hr; have := sphereTail_lower μ hμ hr; linarith) + (sphereKernel_integrable μ) + (Filter.Eventually.of_forall fun r => Filter.Eventually.of_forall (sphereKernel_nonneg r)) + (by filter_upwards [hμ] with r hr; exact sphereKernel_row_bound μ hr) + (ha.sub hb) + ⟨A + B', by + filter_upwards [hA, hB'] with r hAr hBr + exact (abs_sub (a r) (b r)).trans (add_le_add hAr hBr)⟩ + (by + filter_upwards [haEq, hbEq] with r har hbr + have hai : Integrable (fun s => sphereKernel r s * a s) μ := by + apply ((sphereKernel_integrable μ r).mul_const A).mono' + ((sphereKernel_integrable μ r).aestronglyMeasurable.mul ha) + filter_upwards [hA] with s hs + change |sphereKernel r s * _| ≤ _ + rw [abs_mul, abs_of_nonneg (sphereKernel_nonneg r s)] + exact mul_le_mul_of_nonneg_left hs (sphereKernel_nonneg r s) + have hbi : Integrable (fun s => sphereKernel r s * b s) μ := by + apply ((sphereKernel_integrable μ r).mul_const B').mono' + ((sphereKernel_integrable μ r).aestronglyMeasurable.mul hb) + filter_upwards [hB'] with s hs + change |sphereKernel r s * _| ≤ _ + rw [abs_mul, abs_of_nonneg (sphereKernel_nonneg r s)] + exact mul_le_mul_of_nonneg_left hs (sphereKernel_nonneg r s) + simp_rw [mul_sub] + rw [integral_sub hai hbi, sub_mul, har, hbr] + ring) + filter_upwards [hzero] with r hr + exact sub_eq_zero.mp hr + +lemma sphereTail_nonneg (μ : Measure Time) [IsProbabilityMeasure μ] (r : Time) : + 0 ≤ sphereTail μ r := integral_nonneg (fun s => + sub_nonneg.mpr (max_le r.property.2 s.property.2)) + +lemma sphereTail_upper (μ : Measure Time) [IsProbabilityMeasure μ] (r : Time) : + sphereTail μ r ≤ 1 - (r : ℝ) := by + calc + _ ≤ ∫ _ : Time, 1 - (r : ℝ) ∂μ := + integral_mono (sphereTail_integrable μ r) (integrable_const _) + (fun s => sub_le_sub_left (le_max_left _ _) 1) + _ = _ := by simp + +theorem sphere_equation_support_bound (μ : Measure Time) [IsProbabilityMeasure μ] + {a : Time → ℝ} {A : ℝ} (hA : 0 ≤ A) + (haNonneg : ∀ᵐ r ∂μ, 0 ≤ a r) (haBound : ∀ᵐ r ∂μ, a r ≤ A) + (haEq : ∀ᵐ r ∂μ, a r * sphereTail μ r = (r : ℝ) + ∫ s, sphereKernel r s * a s ∂μ) : + ∀ᵐ r : Time ∂μ, (r : ℝ) ≤ A / (1 + A) := by + filter_upwards [haBound, haEq] with r har heq + have hint : 0 ≤ ∫ s, sphereKernel r s * a s ∂μ := + integral_nonneg_of_ae (by + filter_upwards [haNonneg] with s hs + exact mul_nonneg (sphereKernel_nonneg r s) hs) + have hineq : (r : ℝ) ≤ A * (1 - (r : ℝ)) := by + calc + _ ≤ a r * sphereTail μ r := by linarith + _ ≤ A * sphereTail μ r := mul_le_mul_of_nonneg_right har (sphereTail_nonneg μ r) + _ ≤ _ := mul_le_mul_of_nonneg_left (sphereTail_upper μ r) hA + apply (le_div_iff₀ (by linarith : 0 < 1 + A)).mpr + nlinarith + +def realTail (μ : Measure Time) (x : ℝ) : ℝ := + ∫ s, 1 - max x (s : ℝ) ∂μ + +def realCDF (μ : Measure Time) (x : ℝ) : ℝ := μ.real {s : Time | (s : ℝ) ≤ x} + +lemma continuous_time_integrable (μ : Measure Time) [IsFiniteMeasure μ] + {f : Time → ℝ} (hf : Continuous f) : Integrable f μ := + hf.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + +lemma realTail_integrable (μ : Measure Time) [IsFiniteMeasure μ] (x : ℝ) : + Integrable (fun s : Time => 1 - max x (s : ℝ)) μ := + continuous_time_integrable μ (by fun_prop) + +lemma hasDerivWithinAt_max_right (x s : ℝ) : + HasDerivWithinAt (fun y => max y s) (if s ≤ x then 1 else 0) (Ioi x) x := by + split_ifs with h + · exact (hasDerivAt_id x).hasDerivWithinAt.congr + (fun y hy => max_eq_left (h.trans (le_of_lt hy))) (max_eq_left h) + · have hd : HasDerivAt (fun y => max y s) 0 x := by + apply (hasDerivAt_const x s).congr_of_eventuallyEq + filter_upwards [gt_mem_nhds (lt_of_not_ge h)] with y hy + exact max_eq_right (le_of_lt hy) + exact hd.hasDerivWithinAt + +lemma realTail_right_derivative (μ : Measure Time) [IsFiniteMeasure μ] (x : ℝ) : + HasDerivWithinAt (realTail μ) (-realCDF μ x) (Ioi x) x := by + have hlim (s : Time) : + Tendsto (slope (fun y => 1 - max y (s : ℝ)) x) (𝓝[Ioi x] x) + (𝓝 (-(if (s : ℝ) ≤ x then 1 else 0))) := by + have hd := (hasDerivAt_const x (1 : ℝ)).hasDerivWithinAt.sub + (hasDerivWithinAt_max_right x (s : ℝ)) + change HasDerivWithinAt (fun y => 1 - max y (s : ℝ)) + (0 - (if (s : ℝ) ≤ x then 1 else 0)) (Ioi x) x at hd + have hh := hasDerivWithinAt_iff_tendsto_slope.mp hd + simpa using hh + have hint : (∫ s : Time, -(if (s : ℝ) ≤ x then 1 else 0) ∂μ) = -realCDF μ x := by + rw [integral_neg] + congr 1 + change (∫ s : Time, {s : Time | (s : ℝ) ≤ x}.indicator (fun _ => (1 : ℝ)) s ∂μ) = _ + rw [integral_indicator (measurableSet_le (by fun_prop) measurable_const)] + simp [realCDF] + apply hasDerivWithinAt_iff_tendsto_slope.mpr + have hd := tendsto_integral_filter_of_dominated_convergence (μ := μ) + (F := fun y (s : Time) => slope (fun z => 1 - max z (s : ℝ)) x y) + (fun _ => (1 : ℝ)) + (Eventually.of_forall fun y => by unfold slope; fun_prop) + (by + filter_upwards [self_mem_nhdsWithin] with y hy + filter_upwards [] with s + rw [slope_def_field, Real.norm_eq_abs, abs_div] + have h := abs_max_sub_max_le_max y (s : ℝ) x (s : ℝ) + simp only [sub_self, abs_zero, max_eq_left (abs_nonneg (y - x))] at h + have he : |(1 - max y (s : ℝ)) - (1 - max x (s : ℝ))| = + |max y (s : ℝ) - max x (s : ℝ)| := by + rw [show (1 - max y (s : ℝ)) - (1 - max x (s : ℝ)) = + -(max y (s : ℝ) - max x (s : ℝ)) by ring, abs_neg] + rw [he] + exact (div_le_one (abs_pos.mpr (sub_ne_zero.mpr (ne_of_gt hy)))).mpr h) + (integrable_const _) (Eventually.of_forall hlim) + rw [hint] at hd + convert hd using 1 + · ext y + rw [slope_def_field, realTail, realTail, ← integral_sub (realTail_integrable μ y) + (realTail_integrable μ x), ← integral_div] + simp only [slope_def_field] + · simp + +lemma abs_realTail_sub_le (μ : Measure Time) [IsProbabilityMeasure μ] (x y : ℝ) : + |realTail μ x - realTail μ y| ≤ |x - y| := by + rw [realTail, realTail, ← integral_sub (realTail_integrable μ x) (realTail_integrable μ y)] + have hh := norm_integral_le_of_norm_le_const (μ := μ) + (f := fun s : Time => (1 - max x (s : ℝ)) - (1 - max y (s : ℝ))) + (C := |x - y|) (Eventually.of_forall fun s => by + rw [Real.norm_eq_abs, show (1 - max x (s : ℝ)) - (1 - max y (s : ℝ)) = + -(max x (s : ℝ) - max y (s : ℝ)) by ring, abs_neg] + simpa using abs_max_sub_max_le_max x (s : ℝ) y (s : ℝ)) + simpa using hh + +lemma realTail_continuous (μ : Measure Time) [IsProbabilityMeasure μ] : + Continuous (realTail μ) := by + have h : LipschitzWith 1 (realTail μ) := by + rw [lipschitzWith_iff_dist_le_mul] + intro x y + simpa [Real.dist_eq] using abs_realTail_sub_le μ x y + exact h.continuous + +lemma realCDF_monotone (μ : Measure Time) [IsFiniteMeasure μ] : + Monotone (realCDF μ) := by + intro x y hxy + exact measureReal_mono (fun _ hs => hs.trans hxy) + +lemma realCDF_integrable (μ : Measure Time) [IsFiniteMeasure μ] (a b : ℝ) : + IntervalIntegrable (realCDF μ) volume a b := + (realCDF_monotone μ).intervalIntegrable + +lemma integral_cdf_mul (μ : Measure Time) [IsFiniteMeasure μ] {r : ℝ} (hr : 0 ≤ r) + {f : ℝ → ℝ} (hf : IntervalIntegrable f volume 0 r) : + (∫ t in 0..r, realCDF μ t * f t) = + ∫ s : Time, if (s : ℝ) ≤ r then ∫ t in (s : ℝ)..r, f t else 0 ∂μ := by + let ν : Measure ℝ := volume.restrict (Icc 0 r) + have hfi : Integrable f ν := (intervalIntegrable_iff_integrableOn_Icc_of_le hr).mp hf + have hmeas : MeasurableSet {p : ℝ × Time | (p.2 : ℝ) ≤ p.1} := + measurableSet_le (by fun_prop) measurable_fst + have hbase : Integrable (fun p : ℝ × Time => f p.1) (ν.prod μ) := by + simpa using hfi.mul_prod (integrable_const (1 : ℝ) (μ := μ)) + have hswap := integral_integral_swap (μ := ν) (ν := μ) + (f := fun t s => {p : ℝ × Time | (p.2 : ℝ) ≤ p.1}.indicator (fun p => f p.1) (t, s)) + (hbase.indicator hmeas) + have hleft (t : ℝ) : + (∫ s : Time, {p : ℝ × Time | (p.2 : ℝ) ≤ p.1}.indicator + (fun p => f p.1) (t, s) ∂μ) = realCDF μ t * f t := by + change (∫ s : Time, {s : Time | (s : ℝ) ≤ t}.indicator (fun _ => f t) s ∂μ) = _ + rw [integral_indicator (measurableSet_le (by fun_prop) measurable_const)] + simp [realCDF] + have hright (s : Time) : + (∫ t, {p : ℝ × Time | (p.2 : ℝ) ≤ p.1}.indicator + (fun p => f p.1) (t, s) ∂ν) = + if (s : ℝ) ≤ r then ∫ t in (s : ℝ)..r, f t else 0 := by + change (∫ t, (Ici (s : ℝ)).indicator f t ∂ν) = _ + rw [integral_indicator measurableSet_Ici] + have hset : Icc 0 r ∩ Ici (s : ℝ) = Icc (s : ℝ) r := by + ext t + simp only [mem_inter_iff, mem_Icc, mem_Ici] + constructor + · intro h; exact ⟨h.2, h.1.2⟩ + · intro h; exact ⟨⟨s.property.1.trans h.1, h.2⟩, h.1⟩ + dsimp only [ν] + rw [Measure.restrict_restrict measurableSet_Ici, inter_comm, hset] + split_ifs with hs + · rw [integral_Icc_eq_integral_Ioc, intervalIntegral.integral_of_le hs] + · simp [Icc_eq_empty_of_lt (lt_of_not_ge hs)] + have hl : (∫ (t : ℝ), realCDF μ t * f t ∂ν) = ∫ t in 0..r, realCDF μ t * f t := by + dsimp only [ν] + rw [integral_Icc_eq_integral_Ioc, intervalIntegral.integral_of_le hr] + simpa only [Function.uncurry_apply_pair, hleft, hright, hl] using hswap + +lemma realTail_lower (μ : Measure Time) [IsProbabilityMeasure μ] {B x : ℝ} + (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) (hx : x ≤ B) : + 1 - B ≤ realTail μ x := by + calc + _ = ∫ _ : Time, 1 - B ∂μ := by simp + _ ≤ _ := integral_mono_ae (integrable_const _) (realTail_integrable μ x) (by + filter_upwards [hμ] with s hs + exact sub_le_sub_left (max_le hx hs) 1) + +def cappedDensity (μ : Measure Time) (B x : ℝ) : ℝ := + (max (1 - B) (realTail μ x))⁻¹ ^ 2 + +def cappedA (μ : Measure Time) (B r : ℝ) : ℝ := + ∫ t in 0..r, cappedDensity μ B t + +lemma cappedDensity_continuous (μ : Measure Time) [IsProbabilityMeasure μ] + {B : ℝ} (hB : B < 1) : Continuous (cappedDensity μ B) := by + unfold cappedDensity + apply Continuous.pow + exact (continuous_const.max (realTail_continuous μ)).inv₀ (fun x => + ne_of_gt (lt_of_lt_of_le (sub_pos.mpr hB) (le_max_left _ _))) + +lemma cappedA_hasDerivAt (μ : Measure Time) [IsProbabilityMeasure μ] + {B : ℝ} (hB : B < 1) (r : ℝ) : + HasDerivAt (cappedA μ B) (cappedDensity μ B r) r := by + have hc := cappedDensity_continuous μ hB + exact intervalIntegral.integral_hasDerivAt_right (hc.intervalIntegrable _ _) + hc.aestronglyMeasurable.stronglyMeasurableAtFilter hc.continuousAt + +lemma cappedA_continuous (μ : Measure Time) [IsProbabilityMeasure μ] + {B : ℝ} (hB : B < 1) : Continuous (cappedA μ B) := + continuous_iff_continuousAt.mpr (fun r => (cappedA_hasDerivAt μ hB r).continuousAt) + +lemma cappedDensity_eq (μ : Measure Time) [IsProbabilityMeasure μ] {B x : ℝ} + (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) (hx : x ≤ B) : + cappedDensity μ B x = (realTail μ x)⁻¹ ^ 2 := by + rw [cappedDensity, max_eq_right (realTail_lower μ hμ hx)] + +lemma realTail_inv_integral (μ : Measure Time) [IsProbabilityMeasure μ] {B r : ℝ} + (hB : B < 1) (hμ : ∀ᵐ s : Time ∂μ, (s : ℝ) ≤ B) (hr : 0 ≤ r) (hrB : r ≤ B) : + (realTail μ r)⁻¹ - (realTail μ 0)⁻¹ = + ∫ t in 0..r, realCDF μ t * cappedDensity μ B t := by + have hn (x : ℝ) (hx : x ≤ B) : realTail μ x ≠ 0 := + ne_of_gt ((sub_pos.mpr hB).trans_le (realTail_lower μ hμ hx)) + symm + apply intervalIntegral.integral_eq_sub_of_hasDeriv_right_of_le (f := fun x : ℝ => (realTail μ x)⁻¹) hr + · exact (realTail_continuous μ).continuousOn.inv₀ (fun x hx => hn x (hx.2.trans hrB)) + · intro x hx + have hd := (realTail_right_derivative μ x).inv (hn x (hx.2.le.trans hrB)) + convert! hd using 1 + simp only [cappedDensity_eq μ hμ (hx.2.le.trans hrB), neg_neg, div_eq_mul_inv, inv_pow] + · exact (realCDF_integrable μ 0 r).mul_continuousOn + (cappedDensity_continuous μ hB).continuousOn + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/SphereLimit.lean b/lean/OAI/Probability/Perceptron/Sphere/SphereLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..a3ec667e1e62d09ec7a98dc19374eed8a444b276 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/SphereLimit.lean @@ -0,0 +1,250 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ShellBridge + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def normalizedCoordinateSphereLog (n k : ℕ) (σ : ℕ → ℝ) + (p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : ℝ := + coordinateAngularLog n k σ (Real.sqrt (n+1:ℕ)) ((fun i _ => p.1 i),p.2) / ((n+1:ℕ):ℝ) + +def expectedCoordinateSphereLog (n k : ℕ) (σ : ℕ → ℝ) (z : Fin k → ℝ) (r : ℝ≥0) : ℝ := + ∫ p, normalizedCoordinateSphereLog n k σ p ∂coordinateCascadeLaw (n+1) k z r + +lemma normalizedCoordinateSphereLog_measurable (n k : ℕ) (σ : ℕ → ℝ) : + Measurable (normalizedCoordinateSphereLog n k σ) := by + have hm := (coordinateAngularLog_measurable n k σ (Real.sqrt (n+1:ℕ))).comp + (show Measurable (fun p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k => + ((fun (i : Fin (n+1)) (_ : ℕ) => p.1 i),p.2)) from by fun_prop) + exact hm.div_const _ + +lemma normalizedCoordinateSphereLog_integrable (n k : ℕ) (σ : ℕ → ℝ) {b : ℝ} + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b k z) (r : ℝ≥0) : + Integrable (normalizedCoordinateSphereLog n k σ) (coordinateCascadeLaw (n+1) k z r) := + (coordinateAngularLog_integrable n k σ (Real.sqrt (n+1:ℕ)) z hz hz0 hz1 hp r).div_const _ + +lemma normalizedCoordinateSphereLog_nonneg (n k : ℕ) (σ : ℕ → ℝ) {b : ℝ} + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b k z) (r : ℝ≥0) : + 0 ≤ᵐ[coordinateCascadeLaw (n+1) k z r] normalizedCoordinateSphereLog n k σ := by + have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le σ b k z (fun i => (hz0 i).le)) + filter_upwards [canonicalCoordinateBase_pos (n+1) k σ z hz hz0 hz1 r, + canonicalCoordinateTotal_pos (n+1) k σ b z hz hz0 hz1 hp r] with p h0 hc + exact div_nonneg (coordinateAngularLog_regular n k σ _ hb _ h0 hc).2.1 (by positivity) + +lemma expectedCoordinateSphereLog_upper (n k : ℕ) (σ : ℕ → ℝ) {b ε : ℝ} + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b k z) (r : ℝ≥0) + (hε : 0 ≤ ε) (hε1 : ε ≤ 1) + (hm : 0 < (canonicalRadialMass n b).real (normSquareBand n ε)) : + expectedCoordinateSphereLog n k σ z r ≤ + (1+ε)*canonicalGaussianFreeValue σ k z r b- + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))/((n+1:ℕ):ℝ)+ + ε*(Real.log b/2+2*b) := by + let μ := coordinateCascadeLaw (n+1) k z r + let C := fun p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k => + canonicalCoordinateLog (n+1) k σ b ((fun i _ => p.1 i),p.2) + let M := Real.log ((canonicalRadialMass n b).real (normSquareBand n ε)) + let d : ℝ := n+1 + have hd : 0 < d := by dsimp [d]; positivity + have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le σ b k z (fun i => (hz0 i).le)) + have hi : Integrable C μ := (canonical_coordinate_joint_mean (n+1) σ b k z hz hz0 hz1 hp r).1 + have he : (∫ p, C p ∂μ) = d*canonicalGaussianFreeValue σ k z r b := by + simpa [d,C,μ,coordinateCascadeLaw] using (canonical_coordinate_joint_mean (n+1) σ b k z hz hz0 hz1 hp r).2 + have hni := normalizedCoordinateSphereLog_integrable n k σ z hz hz0 hz1 hp r + have hbi : Integrable (fun p => (1+ε)*C p/d-M/d+ε*(Real.log b/2+2*b)) μ := + (((hi.const_mul (1+ε)).div_const d).sub (integrable_const _)).add (integrable_const _) + have hlo : ∀ᵐ p ∂μ, normalizedCoordinateSphereLog n k σ p ≤ + (1+ε)*C p/d-M/d+ε*(Real.log b/2+2*b) := by + filter_upwards [canonicalCoordinateBase_pos (n+1) k σ z hz hz0 hz1 r, + canonicalCoordinateTotal_pos (n+1) k σ b z hz hz0 hz1 hp r] with p h0 hc + have hraw := canonicalCoordinate_unitSphere_upper n k σ hb hε hε1 _ h0 hc hm + have hh := div_le_div_of_nonneg_right hraw hd.le + have heq : ((1+ε)*C p-M+ε*((n+1:ℕ):ℝ)*(Real.log b/2+2*b))/d = + (1+ε)*C p/d-M/d+ε*(Real.log b/2+2*b) := by + dsimp only [d] + push_cast + field_simp + change coordinateAngularLog n k σ (Real.sqrt (n+1:ℕ)) ((fun i _ => p.1 i),p.2)/d ≤ + ((1+ε)*C p-M+ε*((n+1:ℕ):ℝ)*(Real.log b/2+2*b))/d at hh + rw [heq] at hh + simpa only [normalizedCoordinateSphereLog,d,Nat.cast_add,Nat.cast_one] using hh + have hh := integral_mono_ae hni hbi hlo + have hcalc : (∫ p, (1+ε)*C p/d-M/d+ε*(Real.log b/2+2*b) ∂μ) = + (1+ε)*canonicalGaussianFreeValue σ k z r b-M/d+ε*(Real.log b/2+2*b) := by + rw [integral_add (f := fun p => (1+ε)*C p/d-M/d) + (g := fun _ => ε*(Real.log b/2+2*b)) + (((hi.const_mul (1+ε)).div_const d).sub (integrable_const (M/d))) + (integrable_const (ε*(Real.log b/2+2*b))), + integral_sub (f := fun p => (1+ε)*C p/d) (g := fun _ => M/d) + ((hi.const_mul (1+ε)).div_const d) (integrable_const (M/d)), + integral_div,integral_const_mul,he] + simp only [integral_const,probReal_univ,one_smul] + field_simp + rw [hcalc] at hh + simpa [expectedCoordinateSphereLog,M,d] using hh + +lemma expectedCoordinateSphereLog_upper_eventually (k : ℕ) (σ : ℕ → ℝ) {b ε : ℝ} + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b k z) (r : ℝ≥0) (hε : 0 < ε) (hε1 : ε < 1) : + ∀ᶠ n : ℕ in atTop, expectedCoordinateSphereLog n k σ z r ≤ + canonicalGaussianFreeValue σ k z r b+(b-1)/2+ + ε*(canonicalGaussianFreeValue σ k z r b+Real.log b/2+2*b+|1-b|/2)+ + Real.log 2/((n+1:ℕ):ℝ) := by + have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le σ b k z (fun i => (hz0 i).le)) + filter_upwards [canonicalRadial_band_eventually_half hε hε1] with n hn + have hm := (canonicalRadial_band_mass_bounds n hb hn).1 + have hmp : 0 < (canonicalRadialMass n b).real (normSquareBand n ε) := + (by positivity : 0 < Real.exp (((n+1:ℕ):ℝ)*((1-b)/2-|1-b| * ε/2))/2).trans_le hm + have hu := expectedCoordinateSphereLog_upper n k σ z hz hz0 hz1 hp r hε.le hε1.le hmp + have hl := (canonicalRadial_band_log_bounds n hb hn).1 + linarith + +lemma normalizedCoordinateSphereLog_lower_probability (k : ℕ) (σ : ℕ → ℝ) + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (r : ℝ≥0) (b : ℝ) (hp : 0 < quadraticCascadePrecision σ b k z) + (hstat : -1/(2*b)+quadraticCascadeReciprocalSlope σ b k z- + (r:ℝ)/(2*(quadraticCascadePrecision σ b k z)^2) = -1/2) + {ε a : ℝ} (hε : 0 < ε) (hε1 : ε < 1) + (ha : a < canonicalGaussianFreeValue σ k z r b+(b-1)/2- + ε*(canonicalGaussianFreeValue σ k z r b+Real.log b/2+2*b+|1-b|/2)) : + Tendsto (fun n : ℕ => (coordinateCascadeLaw (n+1) k z r).real + {p | a ≤ normalizedCoordinateSphereLog n k σ p}) atTop (𝓝 1) := by + let C := canonicalGaussianFreeValue σ k z r b + let K := Real.log b/2+2*b + let L := C+(b-1)/2-ε*(C+K+|1-b|/2) + let δ := L-a + have hδ : 0 < δ := by + apply sub_pos.mpr + simpa [L,C,K,add_assoc] using ha + let μ := fun n => coordinateCascadeLaw (n+1) k z r + let F := fun n (p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) => + canonicalCoordinateLog (n+1) k σ b ((fun i _ => p.1 i),p.2) + let B := fun n => {p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k | + (canonicalCoordinateBandTotalE n k σ b ε ((fun i _ => p.1 i),p.2)).toReal < + decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k ((fun i _ => p.1 i),p.2)/2} + let D := fun n => {p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k | + (δ/2)*((n+1:ℕ):ℝ) ≤ |F n p-((n+1:ℕ):ℝ)*C|} + have hB : Tendsto (fun n => μ n (B n)) atTop (𝓝 0) := + canonicalCoordinate_bad_half_band_tendsto_zero k σ z hz hz0 hz1 r b hp hstat hε + have hD : Tendsto (fun n => μ n (D n)) atTop (𝓝 0) := + (canonical_coordinate_converges σ b k z hz hz0 hz1 hp r (half_pos hδ)).comp + (tendsto_add_atTop_nat 1) + have hsum := hB.add hD + simp only [add_zero] at hsum + have ht : Tendsto (fun n : ℕ => Real.log 2/((n+1:ℕ):ℝ)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1)) + have hev : ∀ᶠ n : ℕ in atTop, Real.log 2/((n+1:ℕ):ℝ) < δ/2 := + ht.eventually (gt_mem_nhds (half_pos hδ)) + have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le σ b k z (fun i => (hz0 i).le)) + have hbad : Tendsto (fun n => μ n {p | normalizedCoordinateSphereLog n k σ p < a}) atTop (𝓝 0) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hsum + (Eventually.of_forall (fun _ => bot_le)) + filter_upwards [hev,canonicalRadial_band_eventually_half hε hε1] with n hn hhalf + apply le_trans (measure_mono_ae (t := B n ∪ D n) ?_) (measure_union_le _ _) + filter_upwards [canonicalCoordinateBase_pos (n+1) k σ z hz hz0 hz1 r, + canonicalCoordinateTotal_pos (n+1) k σ b z hz hz0 hz1 hp r] with p h0 hc + intro hbad + by_cases hpB : p ∈ B n + · exact Or.inl hpB + · right + by_contra hpD + have hm := (canonicalRadial_band_mass_bounds n hb hhalf).1 + have hmp : 0 < (canonicalRadialMass n b).real (normSquareBand n ε) := + (by positivity : 0 < Real.exp (((n+1:ℕ):ℝ)*((1-b)/2-|1-b| * ε/2))/2).trans_le hm + have hu := (canonicalRadial_band_log_bounds n hb hhalf).2 + have hraw := canonicalCoordinate_unitSphere_lower n k σ hb hε.le hε1.le _ h0 hc hmp + (le_of_not_gt hpB) + have hd : 0 < ((n+1:ℕ):ℝ) := by positivity + have hlow := (div_le_div_of_nonneg_right hraw hd.le) + have herr : |F n p-((n+1:ℕ):ℝ)*C| < (δ/2)*((n+1:ℕ):ℝ) := not_le.mp hpD + have herr' : C-δ/2 < F n p/((n+1:ℕ):ℝ) := by + apply (lt_div_iff₀ hd).mpr + have hh := (abs_lt.mp herr).1 + nlinarith + have he : ((1-ε)*F n p-Real.log 2- + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))- + ε*((n+1:ℕ):ℝ)*K)/((n+1:ℕ):ℝ) = + (1-ε)*(F n p/((n+1:ℕ):ℝ))-Real.log 2/((n+1:ℕ):ℝ)- + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))/((n+1:ℕ):ℝ)-ε*K := by + field_simp + change ((1-ε)*F n p-Real.log 2- + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))- + ε*((n+1:ℕ):ℝ)*K)/((n+1:ℕ):ℝ) ≤ normalizedCoordinateSphereLog n k σ p at hlow + rw [he] at hlow + have hmule := mul_lt_mul_of_pos_left herr' (sub_pos.mpr hε1) + have haeq : a = L-δ := by dsimp [δ]; ring + change normalizedCoordinateSphereLog n k σ p < a at hbad + dsimp only [L] at haeq + nlinarith [mul_nonneg hε.le hδ.le] + have hreal : Tendsto (fun n => (μ n).real {p | normalizedCoordinateSphereLog n k σ p < a}) atTop (𝓝 0) := by + exact (ENNReal.tendsto_toReal (by simp : (0:ℝ≥0∞) ≠ ⊤)).comp hbad + have hone : Tendsto (fun n => 1-(μ n).real {p | normalizedCoordinateSphereLog n k σ p < a}) atTop (𝓝 1) := by + simpa using (tendsto_const_nhds (x := (1:ℝ))).sub hreal + convert hone using 1 + ext n + have hmeas : MeasurableSet {p | normalizedCoordinateSphereLog n k σ p < a} := + measurableSet_lt (normalizedCoordinateSphereLog_measurable n k σ) measurable_const + rw [← probReal_compl_eq_one_sub hmeas] + congr 1 + ext p + simp only [mem_compl_iff,mem_ofPred_eq,not_lt] + +lemma expectedCoordinateSphereLog_lower_eventually (k : ℕ) (σ : ℕ → ℝ) + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (r : ℝ≥0) (b : ℝ) (hp : 0 < quadraticCascadePrecision σ b k z) + (hstat : -1/(2*b)+quadraticCascadeReciprocalSlope σ b k z- + (r:ℝ)/(2*(quadraticCascadePrecision σ b k z)^2) = -1/2) + {ε : ℝ} (hε : 0 < ε) (hε1 : ε < 1) : + ∀ a : ℝ, a < canonicalGaussianFreeValue σ k z r b+(b-1)/2- + ε*(canonicalGaussianFreeValue σ k z r b+Real.log b/2+2*b+|1-b|/2) → + ∀ᶠ n : ℕ in atTop, a < expectedCoordinateSphereLog n k σ z r := by + apply expected_eventually_gt_of_probability_lower + (fun n => coordinateCascadeLaw (n+1) k z r) (fun n => normalizedCoordinateSphereLog n k σ) + (fun n => normalizedCoordinateSphereLog_integrable n k σ z hz hz0 hz1 hp r) + (fun n => normalizedCoordinateSphereLog_nonneg n k σ z hz hz0 hz1 hp r) + exact fun a ha => normalizedCoordinateSphereLog_lower_probability k σ z hz hz0 hz1 r b hp hstat hε hε1 ha + +theorem expectedCoordinateSphereLog_tendsto (k : ℕ) (σ : ℕ → ℝ) + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (r : ℝ≥0) (b : ℝ) (hp : 0 < quadraticCascadePrecision σ b k z) + (hstat : -1/(2*b)+quadraticCascadeReciprocalSlope σ b k z- + (r:ℝ)/(2*(quadraticCascadePrecision σ b k z)^2) = -1/2) : + Tendsto (fun n : ℕ => expectedCoordinateSphereLog n k σ z r) atTop + (𝓝 (canonicalGaussianFreeValue σ k z r b+(b-1)/2)) := by + let T := canonicalGaussianFreeValue σ k z r b+(b-1)/2 + let A := canonicalGaussianFreeValue σ k z r b+Real.log b/2+2*b+|1-b|/2 + let e := fun j : ℕ => 1/((j+1:ℕ):ℝ) + have he : Tendsto e atTop (𝓝 0) := + tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1)) + have he0 : ∀ j, 0 < e j := by intro j; dsimp [e]; positivity + have he1 : ∀ᶠ j in atTop, e j < 1 := he.eventually (gt_mem_nhds zero_lt_one) + have hl : Tendsto (fun j => T-e j*A) atTop (𝓝 T) := by + simpa using tendsto_const_nhds.sub (he.mul_const A) + have hu : Tendsto (fun j => T+e j*A) atTop (𝓝 T) := by + simpa using tendsto_const_nhds.add (he.mul_const A) + apply tendsto_order.mpr + constructor + · intro a ha + obtain ⟨j,hj1,hja⟩ := (he1.and (hl.eventually (lt_mem_nhds ha))).exists + exact expectedCoordinateSphereLog_lower_eventually k σ z hz hz0 hz1 r b hp hstat (he0 j) hj1 a hja + · intro a ha + obtain ⟨j,hj1,hja⟩ := (he1.and (hu.eventually (gt_mem_nhds ha))).exists + have ht : Tendsto (fun n : ℕ => T+e j*A+Real.log 2/((n+1:ℕ):ℝ)) atTop (𝓝 (T+e j*A)) := by + have hh : Tendsto (fun n : ℕ => Real.log 2/((n+1:ℕ):ℝ)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop (tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1)) + simpa using tendsto_const_nhds.add hh + filter_upwards [expectedCoordinateSphereLog_upper_eventually k σ z hz hz0 hz1 hp r (he0 j) hj1, + ht.eventually (gt_mem_nhds hja)] with n hn hn' + exact hn.trans_lt hn' + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Sphere/UnitSphereTangent.lean b/lean/OAI/Probability/Perceptron/Sphere/UnitSphereTangent.lean new file mode 100644 index 0000000000000000000000000000000000000000..ee577bf8b2cfd5f44e1ff3ef81d6f0f485ec2123 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Sphere/UnitSphereTangent.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereIsometryMap +import OAI.Probability.Perceptron.Variational.TensorFeatures + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +def unitSphereAmbientLaw (N : ℕ) : Measure (Spin N) := + (unitSphereLaw N).map (fun x : NormalizedSpin N => x.val) + +instance unitSphereAmbientLaw_probability (n : ℕ) : IsProbabilityMeasure (unitSphereAmbientLaw (n+1)) := by + unfold unitSphereAmbientLaw + apply (Measure.isProbabilityMeasure_map_iff measurable_subtype_coe.aemeasurable).2 + have : NeZero ((volume : Measure (Spin (n+1))).toSphere) := + ⟨Measure.toSphere_ne_zero volume⟩ + unfold unitSphereLaw + infer_instance + +lemma unitSphereAmbientLaw_norm (N : ℕ) : ∀ᵐ x ∂unitSphereAmbientLaw N, ‖x‖=1 := by + apply (ae_map_iff measurable_subtype_coe.aemeasurable (measurableSet_eq_fun continuous_norm.measurable measurable_const)).mpr + exact ae_of_all _ fun x => by simpa only [Metric.mem_sphere,dist_zero_right] using x.property + +lemma unitSphereAmbientLaw_preserving {N : ℕ} (e : Spin N≃ₗᵢ[ℝ]Spin N) : + MeasurePreserving e (unitSphereAmbientLaw N) (unitSphereAmbientLaw N) := by + refine ⟨e.continuous.measurable,?_⟩ + rw [unitSphereAmbientLaw,Measure.map_map e.continuous.measurable measurable_subtype_coe] + have he : e ∘ (fun x : NormalizedSpin N => x.val) = + (fun x : NormalizedSpin N => x.val) ∘ sphereIsometryMap e := rfl + rw [he,← Measure.map_map measurable_subtype_coe (sphereIsometryMap_measurable e), + (unitSphereLaw_isometry_preserving e).map_eq] + +lemma unitSphere_tangent_integral (n : ℕ) (y : Spin (n+1)) {F : Spin (n+1)→ℝ} + (hF : ContDiff ℝ 1 F) : + (∫ x : NormalizedSpin (n+1), fderiv ℝ F x.val (y-inner ℝ y x.val • x.val) ∂unitSphereLaw (n+1)) = + (n:ℝ)*(∫ x : NormalizedSpin (n+1), inner ℝ y x.val*F x.val ∂unitSphereLaw (n+1)) := by + have he := invariant_tangent_integral (unitSphereAmbientLaw (n+1)) + ((unitSphereAmbientLaw_norm (n+1)).mono fun _ h => h.le) + (fun e => unitSphereAmbientLaw_preserving e) (Fin (n+1)) + (EuclideanSpace.basisFun (Fin (n+1)) ℝ) y hF + have hleft : AEStronglyMeasurable (fun x : Spin (n+1) => fderiv ℝ F x ((‖x‖^2) • y-inner ℝ y x • x)) + (unitSphereAmbientLaw (n+1)) := + ((hF.continuous_fderiv (by norm_num)).clm_apply (by fun_prop)).aestronglyMeasurable + have hright : AEStronglyMeasurable (fun x : Spin (n+1) => ((Fintype.card (Fin (n+1)):ℝ)-1)*inner ℝ y x*F x) + (unitSphereAmbientLaw (n+1)) := (by fun_prop : Continuous _).aestronglyMeasurable + rw [unitSphereAmbientLaw,integral_map measurable_subtype_coe.aemeasurable hleft, + integral_map measurable_subtype_coe.aemeasurable hright] at he + have hn (x : NormalizedSpin (n+1)) : ‖x.val‖=1 := by + simpa only [Metric.mem_sphere,dist_zero_right] using x.property + simpa only [hn,one_pow,one_smul,Fintype.card_fin,Nat.cast_add,Nat.cast_one, + add_sub_cancel_right,mul_assoc,integral_const_mul] using he + +lemma unitSphere_gibbs_tangent_integral (n : ℕ) (y : NormalizedSpin (n+1)) + {H : Spin (n+1)→ℝ} (hH : ContDiff ℝ 1 H) {G : ℝ→ℝ} (hG : ContDiff ℝ 1 G) : + (n:ℝ)*(∫ x : NormalizedSpin (n+1), spinOverlap y x*(G (spinOverlap y x)*Real.exp (H x.val)) + ∂unitSphereLaw (n+1)) = + ∫ x : NormalizedSpin (n+1), + (deriv G (spinOverlap y x)*(1-spinOverlap y x^2)+G (spinOverlap y x)* + fderiv ℝ H x.val (y.val-spinOverlap y x • x.val))*Real.exp (H x.val) ∂unitSphereLaw (n+1) := by + let F : Spin (n+1)→ℝ := fun x => G (inner ℝ y.val x)*Real.exp (H x) + have hF : ContDiff ℝ 1 F := (hG.comp (innerSL ℝ y.val).contDiff).mul hH.exp + change (n:ℝ)*(∫ x : NormalizedSpin (n+1), inner ℝ y.val x.val*F x.val ∂unitSphereLaw (n+1)) = _ + rw [← unitSphere_tangent_integral n y.val hF] + apply integral_congr_ae + exact ae_of_all _ fun x => by + have hd := (((hG.differentiable (by norm_num) (inner ℝ y.val x.val)).hasDerivAt.comp_hasFDerivAt x.val + (innerSL ℝ y.val).hasFDerivAt).mul (hH.differentiable (by norm_num) x.val).hasFDerivAt.exp).fderiv + change fderiv ℝ F x.val (y.val-spinOverlap y x • x.val)=_ + have he : fderiv ℝ F x.val = G (spinOverlap y x) • (Real.exp (H x.val) • fderiv ℝ H x.val)+ + Real.exp (H x.val) • (deriv G (spinOverlap y x) • innerSL ℝ y.val) := by + simpa only [F,spinOverlap,Function.comp_def,Pi.mul_def] using hd + rw [he] + have hy : ‖y.val‖=1 := by simpa only [Metric.mem_sphere,dist_zero_right] using y.property + simp only [add_apply,smul_apply,smul_eq_mul, + coe_innerSL_apply,inner_sub_right,inner_smul_right,real_inner_self_eq_norm_sq,hy,one_pow,spinOverlap] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/AmplitudeConvex.lean b/lean/OAI/Probability/Perceptron/Variational/AmplitudeConvex.lean new file mode 100644 index 0000000000000000000000000000000000000000..a90957925f5b91fc593c324f0895400adaaf9894 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/AmplitudeConvex.lean @@ -0,0 +1,279 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma sphericalExp_field_holder (n : ℕ) (u v : Spin (n+1)) (R : ℝ) {a b : ℝ} + (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) : + ENNReal.ofReal (sphericalExp n (a • u+b • v) R) ≤ + ENNReal.ofReal (sphericalExp n u R)^a * ENNReal.ofReal (sphericalExp n v R)^b := by + have he (z : Spin (n+1)) : ENNReal.ofReal (sphericalExp n z R) = + ∫⁻ x : Metric.sphere (0 : Spin (n+1)) 1, + ENNReal.ofReal (Real.exp (R*inner ℝ z x.val)) ∂unitSphereLaw (n+1) := + ofReal_integral_eq_lintegral_ofReal + (unitSphere_continuous_integrable (by fun_prop)) + (ae_of_all _ fun _ => (Real.exp_pos _).le) + simp_rw [he] + have h (x : Metric.sphere (0 : Spin (n+1)) 1) : + ENNReal.ofReal (Real.exp (R*inner ℝ (a • u+b • v) x.val)) = + ENNReal.ofReal (Real.exp (R*inner ℝ u x.val))^a * + ENNReal.ofReal (Real.exp (R*inner ℝ v x.val))^b := by + simp only [inner_add_left,real_inner_smul_left] + rw [show R*(a*inner ℝ u x.val+b*inner ℝ v x.val)= + a*(R*inner ℝ u x.val)+b*(R*inner ℝ v x.val) by ring] + exact ofReal_exp_affine _ _ _ _ + simp_rw [h] + exact ENNReal.lintegral_mul_norm_pow_le (by fun_prop) (by fun_prop) ha hb hab + +lemma decoratedLeafIntegral_mixed_holder {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [AddCommMonoid X] [Module ℝ X] + (s₁ s₂ s₃ : X × S → X) (hs₁ : Measurable s₁) (hs₂ : Measurable s₂) + (F : X → ℝ≥0∞) (hF : Measurable F) {a b : ℝ} + (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) + (hstep : ∀ x y t, s₃ (a • x+b • y,t)=a • s₁ (x,t)+b • s₂ (y,t)) + (hconv : ∀ x y, F (a • x+b • y) ≤ F x^a*F y^b) + (k : ℕ) (η : DecoratedCascade S k) (x y : X) : + decoratedLeafIntegral s₃ F k (a • x+b • y,η) ≤ + decoratedLeafIntegral s₁ F k (x,η)^a*decoratedLeafIntegral s₂ F k (y,η)^b := by + induction k generalizing x y with + | zero => exact hconv x y + | succ k ih => + have hm (s : X × S → X) (hs : Measurable s) (x : X) : + Measurable (fun q : ℝ × (S × DecoratedCascade S k) => + ENNReal.ofReal (Real.exp q.1)*decoratedLeafIntegral s F k (s (x,q.2.1),q.2.2)) := + (measurable_fst.exp.ennreal_ofReal).mul + ((decoratedLeafIntegral_measurable s hs F hF k).comp + ((hs.comp (measurable_const.prodMk measurable_snd.fst)).prodMk measurable_snd.snd)) + simp only [decoratedLeafIntegral,hstep] + refine le_trans (lintegral_mono fun q => mul_le_mul_right (ih q.2.2 (s₁ (x,q.2.1)) (s₂ (y,q.2.1))) _) ?_ + calc + _ = ∫⁻ q : ℝ × (S × DecoratedCascade S k), + (ENNReal.ofReal (Real.exp q.1)*decoratedLeafIntegral s₁ F k (s₁ (x,q.2.1),q.2.2))^a * + (ENNReal.ofReal (Real.exp q.1)*decoratedLeafIntegral s₂ F k (s₂ (y,q.2.1),q.2.2))^b + ∂markedStableCountKernel η := by + congr 1 + funext q + rw [ENNReal.mul_rpow_of_nonneg _ _ ha,ENNReal.mul_rpow_of_nonneg _ _ hb] + have he : ENNReal.ofReal (Real.exp q.1)^a*ENNReal.ofReal (Real.exp q.1)^b = + ENNReal.ofReal (Real.exp q.1) := by + rw [← ENNReal.rpow_add _ _ (by simp [Real.exp_pos]) ENNReal.ofReal_ne_top,hab,ENNReal.rpow_one] + calc + _ = (ENNReal.ofReal (Real.exp q.1)^a*ENNReal.ofReal (Real.exp q.1)^b)* + (decoratedLeafIntegral s₁ F k (s₁ (x,q.2.1),q.2.2)^a* + decoratedLeafIntegral s₂ F k (s₂ (y,q.2.1),q.2.2)^b) := by rw [he] + _ = _ := by ring + _ ≤ _ := ENNReal.lintegral_mul_norm_pow_le (hm s₁ hs₁ x).aemeasurable + (hm s₂ hs₂ y).aemeasurable ha hb hab + +lemma canonicalCoordinateStep_affine (d : ℕ) (σ τ : ℕ → ℝ) (x y : Fin d → ℕ → ℝ) + (t : Fin d → ℝ) (a b : ℝ) : + canonicalCoordinateStep d (a • σ+b • τ) (a • x+b • y,t) = + a • canonicalCoordinateStep d σ (x,t)+b • canonicalCoordinateStep d τ (y,t) := by + funext i j + simp only [canonicalCoordinateStep,gaussianShiftStep,Pi.add_apply,Pi.smul_apply,smul_eq_mul] + ring + +lemma coordinateLeafField_affine (d : ℕ) (x y : Fin d → ℕ → ℝ) (a b : ℝ) : + coordinateLeafField d (a • x+b • y)=a • coordinateLeafField d x+b • coordinateLeafField d y := by + ext i + simp [coordinateLeafField] + +lemma coordinateAngularFactor_amplitude_holder (n k : ℕ) (σ τ : ℕ → ℝ) + (x y : Fin (n+1) → ℕ → ℝ) (η : DecoratedCascade (Fin (n+1) → ℝ) k) + (R : ℝ) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) : + decoratedAngularFactor n (canonicalCoordinateStep (n+1) (a • σ+b • τ)) + (coordinateLeafField (n+1)) k (a • x+b • y,η) R ≤ + decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k (x,η) R ^ a * + decoratedAngularFactor n (canonicalCoordinateStep (n+1) τ) + (coordinateLeafField (n+1)) k (y,η) R ^ b := by + simp_rw [decoratedAngularFactor_eq n _ (canonicalCoordinateStep_measurable _ _) + _ (coordinateLeafField_measurable _) ] + apply decoratedLeafIntegral_mixed_holder _ _ _ (canonicalCoordinateStep_measurable _ _) + (canonicalCoordinateStep_measurable _ _) + (fun x => ENNReal.ofReal (sphericalExp n (coordinateLeafField (n+1) x) R)) + ?_ ha hb hab (fun x y t => canonicalCoordinateStep_affine _ _ _ x y t a b) + · intro x y + rw [coordinateLeafField_affine] + exact sphericalExp_field_holder n _ _ R ha hb hab + · have hm := coordinateLeafField_measurable (n+1) + unfold sphericalExp + apply ENNReal.measurable_ofReal.comp + exact (show StronglyMeasurable (fun p : (Fin (n+1) → ℕ → ℝ) × + Metric.sphere (0:Spin (n+1)) 1 => + Real.exp (R*inner ℝ (coordinateLeafField (n+1) p.1) (p.2:Spin (n+1)))) from (by fun_prop)).integral_prod_right'.measurable + +lemma decoratedLeafIntegral_constant_step {X Y S : Type} [MeasurableSpace X] + [MeasurableSpace Y] [MeasurableSpace S] (s : X × S → X) (t : Y × S → Y) + (c : ℝ≥0∞) (k : ℕ) (η : DecoratedCascade S k) (x : X) (y : Y) : + decoratedLeafIntegral s (fun _ => c) k (x,η)= + decoratedLeafIntegral t (fun _ => c) k (y,η) := by + induction k generalizing x y with + | zero => rfl + | succ k ih => + simp only [decoratedLeafIntegral] + congr 1 + funext q + rw [ih q.2.2 (s (x,q.2.1)) (t (y,q.2.1))] + +lemma decoratedTerminalTotal_zero_step {X Y S : Type} [MeasurableSpace X] + [MeasurableSpace Y] [MeasurableSpace S] (s : X × S → X) (t : Y × S → Y) + (k : ℕ) (η : DecoratedCascade S k) (x : X) (y : Y) : + decoratedTerminalTotal s (fun _ => 0) k (x,η)= + decoratedTerminalTotal t (fun _ => 0) k (y,η) := by + unfold decoratedTerminalTotal + rw [← decoratedLeafIntegral_exp,← decoratedLeafIntegral_exp] + exact congrArg ENNReal.toReal (decoratedLeafIntegral_constant_step s t _ k η x y) + +lemma quadraticCascadePrecision_add (σ : ℕ → ℝ) (b c : ℝ) (k : ℕ) (z : Fin k → ℝ) : + quadraticCascadePrecision σ (b+c) k z=quadraticCascadePrecision σ b k z+c := by + induction k with + | zero => rfl + | succ k ih => simp only [quadraticCascadePrecision,ih]; ring + +lemma exists_positive_canonical_precision (σ : ℕ → ℝ) (k : ℕ) (z : Fin k → ℝ) : + ∃ b : ℝ, 0 < quadraticCascadePrecision σ b k z := by + refine ⟨0+(1-quadraticCascadePrecision σ 0 k z),?_⟩ + rw [quadraticCascadePrecision_add] + linarith + +lemma coordinateAngularLog_amplitude_convex (n k : ℕ) (σ τ : ℕ → ℝ) + (x y : Fin (n+1) → ℕ → ℝ) (η : DecoratedCascade (Fin (n+1) → ℝ) k) + (R : ℝ) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k (x,η)) + (hσ : 0 < (decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k (x,η) R).toReal) + (hτ : 0 < (decoratedAngularFactor n (canonicalCoordinateStep (n+1) τ) + (coordinateLeafField (n+1)) k (y,η) R).toReal) + (hm : 0 < (decoratedAngularFactor n (canonicalCoordinateStep (n+1) (a • σ+b • τ)) + (coordinateLeafField (n+1)) k (a • x+b • y,η) R).toReal) : + coordinateAngularLog n k (a • σ+b • τ) R (a • x+b • y,η) ≤ + a*coordinateAngularLog n k σ R (x,η)+b*coordinateAngularLog n k τ R (y,η) := by + have H := coordinateAngularFactor_amplitude_holder n k σ τ x y η R ha hb hab + have H' := ENNReal.toReal_mono (ENNReal.mul_ne_top + (ENNReal.rpow_ne_top_of_nonneg ha (ENNReal.toReal_pos_iff.mp hσ).2.ne) + (ENNReal.rpow_ne_top_of_nonneg hb (ENNReal.toReal_pos_iff.mp hτ).2.ne)) H + rw [ENNReal.toReal_mul,← ENNReal.toReal_rpow,← ENNReal.toReal_rpow] at H' + have Hlog := Real.log_le_log hm H' + rw [Real.log_mul (Real.rpow_pos_of_pos hσ a).ne' (Real.rpow_pos_of_pos hτ b).ne', + Real.log_rpow hσ,Real.log_rpow hτ] at Hlog + have he₁ := decoratedTerminalTotal_zero_step (canonicalCoordinateStep (n+1) (a • σ+b • τ)) + (canonicalCoordinateStep (n+1) σ) k η (a • x+b • y) x + have he₂ := decoratedTerminalTotal_zero_step (canonicalCoordinateStep (n+1) τ) + (canonicalCoordinateStep (n+1) σ) k η y x + unfold coordinateAngularLog + rw [he₁,he₂,Real.log_div hm.ne' h0.ne',Real.log_div hσ.ne' h0.ne',Real.log_div hτ.ne' h0.ne'] + have hh := congrArg (fun t : ℝ => t*Real.log (decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k (x,η))) hab + nlinarith + +def coordinateRootScale (d k : ℕ) (r : ℝ) + (p : (Fin d → ℝ) × DecoratedCascade (Fin d → ℝ) k) : + (Fin d → ℝ) × DecoratedCascade (Fin d → ℝ) k := ((fun i => r*p.1 i),p.2) + +lemma coordinateRootScale_preserving (d k : ℕ) (z : Fin k → ℝ) (r : ℝ) : + MeasurePreserving (coordinateRootScale d k r) (coordinateCascadeLaw d k z 1) + (coordinateCascadeLaw d k z ⟨r^2,sq_nonneg r⟩) := by + have hp : MeasurePreserving (fun x : Fin d → ℝ => fun i => r*x i) + (Measure.pi (fun _ : Fin d => gaussianReal 0 1)) + (Measure.pi (fun _ : Fin d => gaussianReal 0 ⟨r^2,sq_nonneg r⟩)) := by + refine ⟨by fun_prop,?_⟩ + erw [Measure.pi_map_pi (fun _ => (measurable_id.const_mul r).aemeasurable)] + congr 1 + funext i + change (gaussianReal 0 1).map (fun x : ℝ => r*x)=gaussianReal 0 ⟨r^2,sq_nonneg r⟩ + rw [gaussianReal_map_const_mul,mul_zero,mul_one] + rfl + exact hp.prod (MeasurePreserving.id _) + +def amplitudeSphereLog (n k : ℕ) (σ : ℕ → ℝ) (r : ℝ) + (p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : ℝ := + coordinateAngularLog n k σ (Real.sqrt (n+1:ℕ)) ((fun i _ => r*p.1 i),p.2)/(n+1:ℕ) + +def amplitudeSphereValue (n k : ℕ) (σ : ℕ → ℝ) (z : Fin k → ℝ) (r : ℝ) : ℝ := + ∫ p, amplitudeSphereLog n k σ r p ∂coordinateCascadeLaw (n+1) k z 1 + +lemma amplitudeSphereLog_integrable (n k : ℕ) (σ : ℕ → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (r : ℝ) : + Integrable (amplitudeSphereLog n k σ r) (coordinateCascadeLaw (n+1) k z 1) := by + obtain ⟨b,hb⟩ := exists_positive_canonical_precision σ k z + have hi := normalizedCoordinateSphereLog_integrable n k σ z hz hz0 hz1 hb ⟨r^2,sq_nonneg r⟩ + exact ((coordinateRootScale_preserving (n+1) k z r).integrable_comp hi.aestronglyMeasurable).mpr hi + +lemma amplitudeSphereValue_eq (n k : ℕ) (σ : ℕ → ℝ) (z : Fin k → ℝ) (r : ℝ) : + amplitudeSphereValue n k σ z r= + expectedCoordinateSphereLog n k σ z ⟨r^2,sq_nonneg r⟩ := by + have hp := coordinateRootScale_preserving (n+1) k z r + have he := integral_map (μ := coordinateCascadeLaw (n+1) k z 1) hp.measurable.aemeasurable + ((normalizedCoordinateSphereLog_measurable n k σ).aestronglyMeasurable) + rw [hp.map_eq] at he + exact he.symm + +lemma amplitudeSphereLog_nonneg (n k : ℕ) (σ : ℕ → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (r : ℝ) : + 0 ≤ᵐ[coordinateCascadeLaw (n+1) k z 1] amplitudeSphereLog n k σ r := by + obtain ⟨b,hb⟩ := exists_positive_canonical_precision σ k z + exact (coordinateRootScale_preserving (n+1) k z r).quasiMeasurePreserving.ae + (normalizedCoordinateSphereLog_nonneg n k σ z hz hz0 hz1 hb ⟨r^2,sq_nonneg r⟩) + +lemma amplitudeSphereLog_regular (n k : ℕ) (σ : ℕ → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (r : ℝ) : + ∀ᵐ p ∂coordinateCascadeLaw (n+1) k z 1, + 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) + k ((fun i _ => r*p.1 i),p.2) ∧ + 0 < (decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k ((fun i _ => r*p.1 i),p.2) (Real.sqrt (n+1:ℕ))).toReal := by + obtain ⟨b,hb⟩ := exists_positive_canonical_precision σ k z + have hb0 : 0 < b := hb.trans_le (quadraticCascadePrecision_le σ b k z (fun i => (hz0 i).le)) + have he : ∀ᵐ p ∂coordinateCascadeLaw (n+1) k z ⟨r^2,sq_nonneg r⟩, + 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) + k ((fun i _ => p.1 i),p.2) ∧ + 0 < (decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k ((fun i _ => p.1 i),p.2) (Real.sqrt (n+1:ℕ))).toReal := by + filter_upwards [canonicalCoordinateBase_pos (n+1) k σ z hz hz0 hz1 ⟨r^2,sq_nonneg r⟩, + canonicalCoordinateTotal_pos (n+1) k σ b z hz hz0 hz1 hb ⟨r^2,sq_nonneg r⟩] with p h0 hc + exact ⟨h0,(coordinateAngularLog_regular n k σ _ hb0 _ h0 hc).1⟩ + exact (coordinateRootScale_preserving (n+1) k z r).quasiMeasurePreserving.ae he + +lemma amplitudeSphereValue_convex (n k : ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (σ τ : ℕ → ℝ) (r s : ℝ) {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a+b=1) : + amplitudeSphereValue n k (a • σ+b • τ) z (a*r+b*s) ≤ + a*amplitudeSphereValue n k σ z r+b*amplitudeSphereValue n k τ z s := by + have hi := amplitudeSphereLog_integrable n k (a • σ+b • τ) z hz hz0 hz1 (a*r+b*s) + have hσ := amplitudeSphereLog_integrable n k σ z hz hz0 hz1 r + have hτ := amplitudeSphereLog_integrable n k τ z hz hz0 hz1 s + have he (p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : + (fun (i : Fin (n+1)) (_ : ℕ) => (a*r+b*s)*p.1 i)= + a • (fun (i : Fin (n+1)) (_ : ℕ) => r*p.1 i)+b • (fun (i : Fin (n+1)) (_ : ℕ) => s*p.1 i) := by + funext i j + simp only [Pi.add_apply,Pi.smul_apply,smul_eq_mul] + ring + have hle : amplitudeSphereLog n k (a • σ+b • τ) (a*r+b*s) ≤ᵐ[coordinateCascadeLaw (n+1) k z 1] + (fun p => a*amplitudeSphereLog n k σ r p+b*amplitudeSphereLog n k τ s p) := by + filter_upwards [amplitudeSphereLog_regular n k σ z hz hz0 hz1 r, + amplitudeSphereLog_regular n k τ z hz hz0 hz1 s, + amplitudeSphereLog_regular n k (a • σ+b • τ) z hz hz0 hz1 (a*r+b*s)] with p h1 h2 h3 + rw [he p] at h3 + have h := coordinateAngularLog_amplitude_convex n k σ τ _ _ p.2 _ ha hb hab h1.1 h1.2 h2.2 h3.2 + unfold amplitudeSphereLog + rw [he p] + calc + _ ≤ (a*coordinateAngularLog n k σ (Real.sqrt (n+1:ℕ)) ((fun i _ => r*p.1 i),p.2)+ + b*coordinateAngularLog n k τ (Real.sqrt (n+1:ℕ)) ((fun i _ => s*p.1 i),p.2))/(n+1:ℕ) := + div_le_div_of_nonneg_right h (by positivity) + _ = _ := by ring + have hh := integral_mono_ae hi ((hσ.const_mul a).add (hτ.const_mul b)) hle + change (∫ p, amplitudeSphereLog n k (a • σ+b • τ) (a*r+b*s) p ∂coordinateCascadeLaw (n+1) k z 1) ≤ + ∫ p, a*amplitudeSphereLog n k σ r p+b*amplitudeSphereLog n k τ s p ∂coordinateCascadeLaw (n+1) k z 1 at hh + rw [integral_add (hσ.const_mul a) (hτ.const_mul b),integral_const_mul,integral_const_mul] at hh + exact hh + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/AnnealedIBP.lean b/lean/OAI/Probability/Perceptron/Variational/AnnealedIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..707d643888dd6e6e097c0532983b4fa01de3058a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/AnnealedIBP.lean @@ -0,0 +1,155 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.Contact +import OAI.Probability.Perceptron.Interpolation.KernelReplicaGibbs + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def sourceCouplingCovariance (n k : ℕ) (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (x y : NormalizedSpin (n+1)×IndexedLeaf k) := + perturbationAmplitude (n+1) (fun _ => 1) j * perturbationAmplitude (n+1) u j * + sourceJointMonomial p d j x y + +lemma sourceCouplingCovariance_measurable (n k r : ℕ) (p d : Fin (n+1) → ℕ) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (i l : Fin r) : + Measurable (fun x : Fin r → NormalizedSpin (n+1)×IndexedLeaf k => + sourceCouplingCovariance n k p d u j (x i) (x l)) := by + have hh := (sourceReplica_covariance_measurable (N := n+1) (k := k) p d j i l).const_mul + (perturbationAmplitude (n+1) (fun _ => 1) j * perturbationAmplitude (n+1) u j) + exact hh + +lemma sourceCouplingCovariance_bound (n k : ℕ) (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (x y : NormalizedSpin (n+1)×IndexedLeaf k) : + |sourceCouplingCovariance n k p d u j x y| ≤ + |perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j| := by + unfold sourceCouplingCovariance + rw [abs_mul] + simpa only [mul_one] using mul_le_mul_of_nonneg_left + (sourceJointMonomial_abs_le p d j x y) (abs_nonneg (perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j)) + +lemma sourceCoupling_conditional_ibp (n k r : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (i : Fin r) (b : SourceBaseData n k) + {G : (Fin r → NormalizedSpin (n+1)×IndexedLeaf k) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + (∫ g, gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d h u (b,g)) r + (fun x => sourceCouplingEnergy n k p d h j (b,g) (x i)*G x) ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d h u (b,g)) r + (fun x => G x*∑ l, sourceCouplingCovariance n k p d u j (x i) (x l)) - + r*gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d h u (b,g)) (r+1) + (fun x => G (fun l => x l.succ)*sourceCouplingCovariance n k p d u j (x i.succ) (x 0)) + ∂countableGaussianLaw := by + let c := perturbationAmplitude (n+1) (fun _ => 1) j + have hb := sourceReplica_gaussian_ibp n b.1 k r f (patternPrefix (n+1) b.1 b.2.1) + p d h hh0 hh u b.2.2 j i hG hB hGB + dsimp only at hb + have he := congrArg (fun x : ℝ => c*x) hb + simp only [sourceSpinLeafKernel_apply,sourceCouplingHamiltonian,sourceCouplingEnergy, + sourceCouplingCovariance] + have hs (x : Fin r → NormalizedSpin (n+1)×IndexedLeaf k) : + G x*∑ l, c*perturbationAmplitude (n+1) u j*sourceJointMonomial p d j (x i) (x l) = + c*(G x*∑ l, perturbationAmplitude (n+1) u j*sourceJointMonomial p d j (x i) (x l)) := by + simp only [mul_assoc,Finset.mul_sum] + ring_nf + simp only [mul_assoc] + change (∫ g, gibbsReplicaMean (enrichedIndexedBaseMeasure n k b.2.2) + (enrichedIndexedHamiltonian n b.1 k f (patternPrefix (n+1) b.1 b.2.1) p d h u g) r + (fun x => c*(countableGaussianField (sourceGaussianTestRow p d h j) + (indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) k) g (x i)*G x)) ∂countableGaussianLaw) = _ + simp_rw [replicaMean_const_mul,integral_const_mul] + rw [hb, ← integral_const_mul] + apply integral_congr_ae + exact ae_of_all _ fun g => by + have hs₁ : (fun x : Fin r → NormalizedSpin (n+1)×IndexedLeaf k => + G x * ∑ l, c*(perturbationAmplitude (n+1) u j*sourceJointMonomial p d j (x i) (x l))) = + (fun x => c*(G x*∑ l, perturbationAmplitude (n+1) u j*sourceJointMonomial p d j (x i) (x l))) := by + funext x + rw [← Finset.mul_sum] + ring + have hs₂ : (fun x : Fin (r+1) → NormalizedSpin (n+1)×IndexedLeaf k => + G (fun l => x l.succ)*(c*(perturbationAmplitude (n+1) u j*sourceJointMonomial p d j (x i.succ) (x 0)))) = + (fun x => c*(G (fun l => x l.succ)*(perturbationAmplitude (n+1) u j*sourceJointMonomial p d j (x i.succ) (x 0)))) := by + funext x + ring + rw [hs₁, hs₂] + simp only [replicaMean_const_mul] + ring + +lemma sourceCoupling_annealed_ibp (n k r : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (i : Fin r) (z : Fin k → ℝ) (t : ℝ≥0) + {G : (Fin r → NormalizedSpin (n+1)×IndexedLeaf k) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) + (hYi : Integrable (fun a => tiltMean (sourceSpinLeafKernel n k a.1) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => |sourceCouplingEnergy n k p d h j a x|) 1) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw)) : + let H := sourceCouplingHamiltonian n k f p d h u + let Y := sourceCouplingEnergy n k p d h j + let C := sourceCouplingCovariance n k p d u j + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + (∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) r (fun x => Y a (x i)*G x) ∂P) = + ∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) r (fun x => G x*∑ l, C (x i) (x l)) - + r*gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) (r+1) + (fun x => G (fun l => x l.succ)*C (x i.succ) (x 0)) ∂P := by + dsimp only + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + let H := sourceCouplingHamiltonian n k f p d h u + let Y := sourceCouplingEnergy n k p d h j + let C := sourceCouplingCovariance n k p d u j + let C₀ := |perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j| + have hH := sourceCouplingHamiltonian_measurable n k f p d h u + have hY := sourceCouplingEnergy_measurable n k p d h j + have he := sourceCoupling_all_exp_ae n k f p d h hh0 hh u j z t + have he0 : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (sourceSpinLeafKernel n k a.1) := by + filter_upwards [he] with a ha + simpa only [zero_mul,add_zero] using ha 0 + have he1 : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)*Y a x) (sourceSpinLeafKernel n k a.1) := by + filter_upwards [he] with a ha + simpa only [zero_mul,add_zero,pow_one] using coupling_weighted_power_integrable + (sourceSpinLeafKernel n k a.1) hH.of_uncurry_left hY.of_uncurry_left ha 0 1 + have hi := kernel_replica_energy_integrable (sourceFullSpinLeafKernel n k) P i hH hY hG he0 he1 hYi hB hGB + have hmG : Measurable (fun x : Fin (r+1) → NormalizedSpin (n+1)×IndexedLeaf k => G (fun l => x l.succ)) := + hG.comp (Measurable.of_eval fun coordinate => measurable_pi_apply coordinate.succ) + have hsum : ∀ x : Fin r → NormalizedSpin (n+1)×IndexedLeaf k, |∑ l, C (x i) (x l)| ≤ r*C₀ := by + intro x + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _ : Fin r, C₀ := Finset.sum_le_sum fun l _ => sourceCouplingCovariance_bound n k p d u j _ _ + _ = _ := by simp + have h1G : Measurable (fun x : Fin r → NormalizedSpin (n+1)×IndexedLeaf k => G x*∑ l, C (x i) (x l)) := + hG.mul (Finset.measurable_sum _ fun l _ => sourceCouplingCovariance_measurable n k r p d u j i l) + have h2G : Measurable (fun x : Fin (r+1) → NormalizedSpin (n+1)×IndexedLeaf k => G (fun l => x l.succ)*C (x i.succ) (x 0)) := + hmG.mul (sourceCouplingCovariance_measurable n k (r+1) p d u j i.succ 0) + have hi1 := kernel_replicaMean_bounded_integrable (sourceFullSpinLeafKernel n k) P + (G := fun _ x => G x*∑ l, C (x i) (x l)) hH (h1G.comp measurable_snd) + (show 0 ≤ B*(r*C₀) by positivity) (fun _ x => by + rw [abs_mul]; exact mul_le_mul (hGB x) (hsum x) (abs_nonneg _) hB) + have hi2 := kernel_replicaMean_bounded_integrable (sourceFullSpinLeafKernel n k) P + (G := fun _ x => G (fun l => x l.succ)*C (x i.succ) (x 0)) hH (h2G.comp measurable_snd) + (show 0 ≤ B*C₀ by positivity) (fun _ x => by + rw [abs_mul]; exact mul_le_mul (hGB _) (sourceCouplingCovariance_bound n k p d u j _ _) (abs_nonneg _) hB) + change (∫ a, gibbsReplicaMean (sourceFullSpinLeafKernel n k a) (H a) r (fun x => Y a (x i)*G x) ∂P) = + ∫ a, gibbsReplicaMean (sourceFullSpinLeafKernel n k a) (H a) r (fun x => G x*∑ l, C (x i) (x l))- + r*gibbsReplicaMean (sourceFullSpinLeafKernel n k a) (H a) (r+1) (fun x => G (fun l => x l.succ)*C (x i.succ) (x 0)) ∂P + have hiR := hi1.sub (hi2.const_mul (r:ℝ)) + dsimp only [sourceFullSpinLeafKernel,Kernel.comap_apply,P,H,Y,C,Pi.sub_apply] at hi hiR ⊢ + have hprodR := integral_prod _ hiR + simp only [Pi.sub_apply] at hprodR + rw [integral_prod _ hi, hprodR] + apply integral_congr_ae + exact ae_of_all _ fun b => sourceCoupling_conditional_ibp n k r f p d h hh0 hh u j i b hG hB hGB + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/AtomicBranches.lean b/lean/OAI/Probability/Perceptron/Variational/AtomicBranches.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e1d823c59b7292275800b7c2f2ca3b8dd9e8eed --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/AtomicBranches.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.IndexedCascadeRegular + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma injective_of_simple_count_map {I A : Type*} [Countable I] + [MeasurableSpace I] [MeasurableSingletonClass I] + [MeasurableSpace A] [MeasurableSingletonClass A] + (p : I → A) (hp : Measurable p) + (hs : ∀ᵐ x ∂(Measure.count.map p), (Measure.count.map p) {x} = 1) : + Function.Injective p := by + classical + have h : ∀ i, (Measure.count.map p) {p i} = 1 := + Measure.ae_count_iff.mp (ae_of_ae_map hp.aemeasurable hs) + intro i j hij + by_contra hn + have hle : (Measure.count : Measure I) {i,j} ≤ 1 := by + rw [← h i,Measure.map_apply hp (measurableSet_singleton _)] + apply measure_mono + intro k hk + rcases hk with rfl | hk + · rfl + · simpa only [mem_singleton_iff] using hk ▸ hij.symm + have htwo : (Measure.count : Measure I) {i,j} = 2 := by + have he : (↑({i,j} : Finset I) : Set I) = {i,j} := by ext k; simp + rw [← he,Measure.count_apply_finset] + simp [hn] + rw [htwo] at hle + norm_num at hle + +lemma markedStableMassKernel_count_map {I S : Type*} [Countable I] + [MeasurableSpace I] [MeasurableSingletonClass I] [MeasurableSpace S] + (p : I → ℝ×S) (hp : Measurable p) : + markedStableMassKernel (Measure.count.map p) = + (normalizedMeasure (Measure.count.withDensity + (fun i => ENNReal.ofReal (Real.exp (p i).1)))).map p := by + rw [normalizedMeasure_map _ hp] + change normalizedMeasure ((Measure.count.map p).withDensity + (fun t : ℝ×S => ENNReal.ofReal (Real.exp t.1))) = _ + rw [map_withDensity_comp Measure.count hp (by fun_prop)] + rfl + +lemma stableMassKernel_count_map_atom {I S : Type*} [Countable I] + [MeasurableSpace I] [MeasurableSingletonClass I] [MeasurableSpace S] + (p : I → ℝ×S) (hp : Measurable p) (hinj : Function.Injective (fun i => (p i).1)) + (i : I) : + stableMassKernel ((Measure.count.map p).map Prod.fst) {(p i).1} = + ((∑' j, ENNReal.ofReal (Real.exp (p j).1))⁻¹) * + ENNReal.ofReal (Real.exp (p i).1) := by + rw [Measure.map_map measurable_fst hp] + change normalizedMeasure ((Measure.count.map (fun j => (p j).1)).withDensity + (fun x => ENNReal.ofReal (Real.exp x))) {(p i).1} = _ + have hp' : Measurable (fun j => (p j).1) := hp.fst + rw [map_withDensity_comp Measure.count hp' (by fun_prop), + ← normalizedMeasure_map _ hp', + Measure.map_apply hp' (measurableSet_singleton _)] + have hpre : (fun j => (p j).1) ⁻¹' {(p i).1} = {i} := by + ext j + simp only [mem_preimage,mem_singleton_iff,hinj.eq_iff] + rw [hpre,normalizedMeasure,Measure.smul_apply,smul_eq_mul, + withDensity_apply _ (measurableSet_singleton i),withDensity_apply _ MeasurableSet.univ, + Measure.restrict_univ,lintegral_count] + simp + +def countedBlockProbability {I S : Type*} (p : I → ℝ×S) : + List (ℕ×(S → ℝ≥0∞)) → {m : ℕ} → (Fin m → ℝ) → ℝ≥0∞ + | [],_,_ => 1 + | nf::ns,_,z => ∑' i, if ∃ j, z j = (p i).1 then 0 else + (((∑' k, ENNReal.ofReal (Real.exp (p k).1))⁻¹)* + ENNReal.ofReal (Real.exp (p i).1))^nf.1 * nf.2 (p i).2 * + countedBlockProbability p ns (Fin.cons (p i).1 z) + +lemma markedBlockProbability_count_map {I S : Type*} [Countable I] + [MeasurableSpace I] [MeasurableSingletonClass I] [MeasurableSpace S] + (p : I → ℝ×S) (hp : Measurable p) (hinj : Function.Injective (fun i => (p i).1)) + (ns : List (ℕ×(S → ℝ≥0∞))) + (hn : ∀ nf ∈ ns, 1 ≤ nf.1) (hm : ∀ nf ∈ ns, Measurable nf.2) + {m : ℕ} (z : Fin m → ℝ) : + markedBlockProbability ns (Measure.count.map p) z = countedBlockProbability p ns z := by + classical + induction ns generalizing m with + | nil => rfl + | cons nf ns ih => + have hnf := hn nf (by simp) + have hn' : ∀ n ∈ ns, 1 ≤ n.1 := fun n h => hn n (by simp [h]) + have hm' : ∀ n ∈ ns, Measurable n.2 := fun n h => hm n (by simp [h]) + unfold markedBlockProbability countedBlockProbability + rw [markedStableMassKernel_count_map p hp] + have ha : Measurable (fun t : ℝ×S => + stableMassKernel ((Measure.count.map p).map Prod.fst) {t.1}) := + stableMassAtom_measurable_comp measurable_const measurable_fst + have ht : Measurable (fun t : ℝ×S => + markedBlockProbability ns (Measure.count.map p) (Fin.cons t.1 z)) := + (markedBlockProbability_measurable ns hm' (m+1)).comp + (measurable_const.prodMk (measurable_fin_cons measurable_fst measurable_const)) + have hf : Measurable (fun t : ℝ×S => if ∃ j, z j = t.1 then (0:ℝ≥0∞) else + (stableMassKernel ((Measure.count.map p).map Prod.fst) {t.1})^(nf.1-1)* + nf.2 t.2*markedBlockProbability ns (Measure.count.map p) (Fin.cons t.1 z)) := + measurable_const.ite (cascadeMeasurableSet_exists fun j => + measurableSet_eq_fun measurable_const measurable_fst) + (((ha.pow_const _).mul ((hm nf (by simp)).comp measurable_snd)).mul ht) + have hweight : Measurable (fun i => ENNReal.ofReal (Real.exp (p i).1)) := + hp.fst.exp.ennreal_ofReal + have hfp : Measurable (fun i => if ∃ j, z j = (p i).1 then (0:ℝ≥0∞) else + (stableMassKernel ((Measure.count.map p).map Prod.fst) {(p i).1})^(nf.1-1)* + nf.2 (p i).2*markedBlockProbability ns (Measure.count.map p) (Fin.cons (p i).1 z)) := + hf.comp hp + rw [lintegral_map hf hp,normalizedMeasure,lintegral_smul_measure,smul_eq_mul, + withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + lintegral_withDensity_eq_lintegral_mul _ hweight hfp, + lintegral_count,lintegral_count,← ENNReal.tsum_mul_left] + apply tsum_congr + intro i + simp only [Pi.mul_apply] + split_ifs with hi + · simp + · rw [stableMassKernel_count_map_atom p hp hinj,ih hn' hm'] + have hpw := pow_succ (((∑' k, ENNReal.ofReal (Real.exp (p k).1))⁻¹)* + ENNReal.ofReal (Real.exp (p i).1)) (nf.1-1) + rw [Nat.sub_add_cancel hnf] at hpw + rw [hpw] + ring + +instance finiteSigmaMeasurableSingleton (k : ℕ → ℕ) : + MeasurableSingletonClass (Σ j, Fin (k j)) := by + constructor + intro x + apply MeasurableSpace.measurableSet_iInf.mpr + intro j + change MeasurableSet ((Sigma.mk j) ⁻¹' {x}) + exact (Set.toFinite _).measurableSet + +lemma indexedPoissonMeasure_eq_map_count {A : Type*} [MeasurableSpace A] + (a : ℕ → ℕ×(ℕ → A)) : + indexedPoissonMeasure a = Measure.count.map + (fun i : Σ j, Fin ((a j).1) => (a i.1).2 i.2.val) := by + apply Measure.ext_of_lintegral + intro f hf + rw [indexedPoissonMeasure_lintegral a hf, + lintegral_map hf (measurable_of_countable _),lintegral_count,ENNReal.tsum_sigma'] + simp only [tsum_fintype] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/AtomicPairVisitLaw.lean b/lean/OAI/Probability/Perceptron/Variational/AtomicPairVisitLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..d9737e79592e67f5d9f4108cc801f3aca2197582 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/AtomicPairVisitLaw.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.TiltedVisitKernelLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +section +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +def indexedPairStateWeight (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (x : X) (d : Fin (n+1)) (a : IndexedLeaf n×IndexedLeaf n) + (p : IndexedCascadeBase n×IndexedCascadeMarks S n) : ℝ≥0∞ := + if indexedCommonDepth n a.1 a.2=d then + indexedTiltedProbability step n F (x,p) a.1*indexedTiltedProbability step n F (x,p) a.2 else 0 + +omit [Nonempty S] in +lemma indexedPairStateWeight_measurable (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (x : X) (d : Fin (n+1)) (a : IndexedLeaf n×IndexedLeaf n) : + Measurable (indexedPairStateWeight step n F x d a) := by + unfold indexedPairStateWeight + split_ifs + · exact (indexedTiltedProbability_fixed_measurable step hs n F hF x a.1).mul + (indexedTiltedProbability_fixed_measurable step hs n F hF x a.2) + · exact measurable_const + +omit [MeasurableSpace X] [Nonempty S] in +lemma indexedPairStateWeight_mass_le (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (x : X) (d : Fin (n+1)) (p : IndexedCascadeBase n×IndexedCascadeMarks S n) : + (∑' a, indexedPairStateWeight step n F x d a p) ≤ 1 := by + calc + _ ≤ ∑' a : IndexedLeaf n×IndexedLeaf n, + indexedTiltedProbability step n F (x,p) a.1*indexedTiltedProbability step n F (x,p) a.2 := + ENNReal.tsum_le_tsum (fun a => by unfold indexedPairStateWeight; split_ifs <;> simp) + _ = (∑' l, indexedTiltedProbability step n F (x,p) l)* + (∑' l, indexedTiltedProbability step n F (x,p) l) := by + rw [ENNReal.tsum_prod'] + simp_rw [ENNReal.tsum_mul_left,ENNReal.tsum_mul_right] + _ ≤ 1*1 := mul_le_mul' (indexedTiltedProbability_mass_le step n F (x,p)) + (indexedTiltedProbability_mass_le step n F (x,p)) + _ = 1 := one_mul _ + +def indexedPairStateKernel (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) (x : X) (d : Fin (n+1)) : + Kernel (IndexedCascadeBase n×IndexedCascadeMarks S n) (X×X) := + atomicVisitKernel (I := IndexedLeaf n×IndexedLeaf n) + (P := IndexedCascadeBase n×IndexedCascadeMarks S n) (Y := X×X) + (indexedPairStateWeight step n F x d) (indexedPairStateWeight_measurable step hs n F hF x d) + (fun a p => (indexedLeafState step n (x,p.2) a.1,indexedLeafState step n (x,p.2) a.2)) + (fun a => (indexedLeafState_fixed_measurable step hs n x a.1).prodMk + (indexedLeafState_fixed_measurable step hs n x a.2)) + +instance indexedPairStateKernel_finite (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) (x : X) (d : Fin (n+1)) : + IsFiniteKernel (indexedPairStateKernel step hs n F hF x d) := + atomicVisitKernel_finite _ _ _ _ (indexedPairStateWeight_mass_le step n F x d) + +omit [Nonempty S] in +lemma indexedPairStateKernel_lintegral (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) (x : X) (d : Fin (n+1)) + (h k : X → ℝ≥0∞) (hh : Measurable h) (hk : Measurable k) + (p : IndexedCascadeBase n×IndexedCascadeMarks S n) : + (∫⁻ y, h y.1*k y.2 ∂indexedPairStateKernel step hs n F hF x d p) = + indexedTwoVisit step n F h k d (x,p) := by + rw [indexedPairStateKernel,atomicVisitKernel_lintegral _ _ _ _ _ + (show Measurable (fun y : X×X => h y.1*k y.2) from + (hh.comp measurable_fst).mul (hk.comp measurable_snd)),ENNReal.tsum_prod'] + unfold indexedTwoVisit + apply tsum_congr + intro l + rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro m + simp only [indexedPairStateWeight] + split_ifs <;> simp [mul_assoc] + +omit [MeasurableSpace X] in +lemma oneDecoratedVisit_bare_eq {Y : Type} (h : X → ℝ≥0∞) (k : Y → ℝ≥0∞) (n : ℕ) : + (oneDecoratedVisit h n).bare n = (oneDecoratedVisit k n).bare n := by + induction n with + | zero => rfl + | succ n ih => simpa [oneDecoratedVisit,DecoratedVisitShape.bare] using ih + +omit [MeasurableSpace X] in +lemma twoDecoratedVisit_bare_eq {Y : Type} (h k : X → ℝ≥0∞) (h' k' : Y → ℝ≥0∞) + (n : ℕ) (d : Fin (n+1)) : + (twoDecoratedVisit h k n d).bare n = (twoDecoratedVisit h' k' n d).bare n := by + induction n with + | zero => rfl + | succ n ih => + induction d using Fin.cases with + | zero => simp [twoDecoratedVisit,DecoratedVisitShape.bare,oneDecoratedVisit_bare_eq h h', + oneDecoratedVisit_bare_eq k k'] + | succ d => simpa [twoDecoratedVisit,DecoratedVisitShape.bare] using ih d + +def twoVisitMass (n : ℕ) (z : Fin n → ℝ) (d : Fin (n+1)) : ℝ≥0∞ := + cascadeShapeLikelihood n z 0 ((twoDecoratedVisit (X := Unit) (fun _ => 1) (fun _ => 1) n d).bare n) + +omit [MeasurableSpace X] in +lemma twoVisitMass_eq (n : ℕ) (z : Fin n → ℝ) (d : Fin (n+1)) (h k : X → ℝ≥0∞) : + twoVisitMass n z d = cascadeShapeLikelihood n z 0 ((twoDecoratedVisit h k n d).bare n) := by + unfold twoVisitMass + rw [twoDecoratedVisit_bare_eq (fun _ : Unit => 1) (fun _ => 1) h k] + +end +section +variable {X Y : Type} [MeasurableSpace X] [MeasurableSpace Y] + +lemma lintegral_indicator_prod (μ : Measure (X×Y)) (s : Set X) (t : Set Y) + (hs : MeasurableSet s) (ht : MeasurableSet t) : + (∫⁻ p, s.indicator (fun _ => (1 : ℝ≥0∞)) p.1*t.indicator (fun _ => (1 : ℝ≥0∞)) p.2 ∂μ) = + μ (s×ˢt) := by + rw [← lintegral_indicator_one (hs.prod ht)] + congr 1 + funext p + by_cases h : p.1∈s <;> by_cases k : p.2∈t <;> simp [h,k] + +end +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +lemma indexedPairStateLaw_eq (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) (d : Fin (n+1)) : + indexedPairStateKernel step hs n F hF x d ∘ₘ + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) = + twoVisitMass n z d • pathPairKernel n (fun i => tiltedStateStep ν step (z i) (F i)) d x := by + apply Measure.ext_prod + intro s t hs' ht' + let h := s.indicator (fun _ => (1 : ℝ≥0∞)) + let k := t.indicator (fun _ => (1 : ℝ≥0∞)) + have hh : Measurable h := measurable_const.indicator hs' + have hk : Measurable k := measurable_const.indicator ht' + rw [← lintegral_indicator_prod _ s t hs' ht',← lintegral_indicator_prod _ s t hs' ht'] + change (∫⁻ p : X×X, h p.1*k p.2 ∂_) = ∫⁻ p : X×X, h p.1*k p.2 ∂_ + rw [Measure.comp_eq_comp_const_apply,Kernel.lintegral_comp _ _ _ + (show Measurable (fun p : X×X => h p.1*k p.2) from + (hh.comp measurable_fst).mul (hk.comp measurable_snd))] + simp_rw [indexedPairStateKernel_lintegral step hs n F hF x d h k hh hk,Kernel.const_apply] + rw [indexedTwoVisit_integral ν step hs n z hz hz0 hz1 F hF hI hM h k hh hk d x, + lintegral_smul_measure,smul_eq_mul, + pathPairKernel_lintegral ν step hs n z F hF hI hM h k hh hk d x, + twoVisitMass_eq n z d h k] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/BackwardScore.lean b/lean/OAI/Probability/Perceptron/Variational/BackwardScore.lean new file mode 100644 index 0000000000000000000000000000000000000000..bb4dcf0be12a175343e85c0562257955794d7dfe --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/BackwardScore.lean @@ -0,0 +1,447 @@ +import Mathlib +import OAI.Probability.Perceptron.Control.ControlledPrefix + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma patchControl_prefix (m : Trial) (v : Time → BrownianPath → ℝ) + (s t : Time) (a : BrownianPath → ℝ) {r : Time} (hrs : r ≤ s) (ω : BrownianPath) : + controlledPrefix m (patchControl v s t a) r ω = controlledPrefix m v r ω := by + unfold controlledPrefix + congr 1 + apply setIntegral_congr_fun measurableSet_Iic + intro u hu + have hh : u ∉ Set.Ioc s t := fun h => (not_lt_of_ge (hu.trans hrs)) h.1 + simp only [patchControl,ite_eq_right hh] + +lemma patchControl_cost_prefix (m : Trial) (v : Time → BrownianPath → ℝ) + (s t : Time) (a : BrownianPath → ℝ) (q : Time) {r : Time} (hrs : r ≤ s) (ω : BrownianPath) : + intervalControlCost m (patchControl v s t a) q r ω = intervalControlCost m v q r ω := by + unfold intervalControlCost + apply setIntegral_congr_fun measurableSet_Ioc + intro u hu + have hh : u ∉ Set.Ioc s t := fun h => (not_lt_of_ge (hu.2.trans hrs)) h.1 + simp only [patchControl,ite_eq_right hh] + +lemma patchControl_drift_cell (m : Trial) (v : Time → BrownianPath → ℝ) + {s t : Time} (hst : s ≤ t) (a : BrownianPath → ℝ) (d : ℝ≥0) + (hm : ∀ r ∈ Set.Ioc s t, m r = (d : ℝ)) (ω : BrownianPath) : + (∫ r in Set.Ioc s t, m r * patchControl v s t a r ω ∂timeLaw) = + (d : ℝ)*(timeSpan s t : ℝ)*a ω := by + have he : ∀ r ∈ Set.Ioc s t, m r * patchControl v s t a r ω = (d : ℝ)*a ω := by + intro r hr + rw [hm r hr,patchControl,ite_eq_left hr] + rw [setIntegral_congr_fun measurableSet_Ioc he,timeLaw_integral_const_Ioc hst,timeSpan_coe hst] + ring + +lemma patchControl_cost_cell (m : Trial) (v : Time → BrownianPath → ℝ) + {s t : Time} (hst : s ≤ t) (a : BrownianPath → ℝ) (d : ℝ≥0) + (hm : ∀ r ∈ Set.Ioc s t, m r = (d : ℝ)) (ω : BrownianPath) : + intervalControlCost m (patchControl v s t a) s t ω = + (d : ℝ)*(timeSpan s t : ℝ)*(a ω)^2 := by + have he : ∀ r ∈ Set.Ioc s t, m r * (patchControl v s t a r ω)^2 = (d : ℝ)*(a ω)^2 := by + intro r hr + rw [hm r hr,patchControl,ite_eq_left hr] + rw [intervalControlCost,setIntegral_congr_fun measurableSet_Ioc he,timeLaw_integral_const_Ioc hst,timeSpan_coe hst] + ring + +lemma brownian_control_feedback_cell (d L C₀ C₁ C₂ C₃ : ℝ≥0) : + ∃ C : ℝ≥0, ∀ (P : Measure BrownianPath) [IsProbabilityMeasure P], + IsBrownianReal brownianEval P → ∀ (m : Trial) (v : Time → BrownianPath → ℝ), + Progressive P v → (∀ r ω, |v r ω| ≤ L) → ∀ (s t : Time), s < t → + (∀ r ∈ Set.Ioc s t, m r = (d : ℝ)) → ∀ (g : Jet3), + ‖g.f‖ ≤ C₀ → ‖g.d1‖ ≤ C₁ → ‖g.d2‖ ≤ C₂ → ‖g.d3‖ ≤ C₃ → + (∀ r ∈ Set.Ioc s t, ∀ ω, v r ω = g.d1 (controlledPrefix m v s ω)) → + |(∫ ω, g.f (controlledPrefix m v t ω) ∂P) - + (∫ ω, heatLog (timeSpan s t) d g.f (controlledPrefix m v s ω) ∂P) - + (∫ ω, intervalControlCost m v s t ω ∂P)/2| ≤ + (C : ℝ)*(timeSpan s t : ℝ)*Real.sqrt (timeSpan s t) := by + obtain ⟨C,hC⟩ := heatLog_control_step_error d L C₀ C₁ C₂ C₃ + refine ⟨C, ?_⟩ + intro P _ hB m v hv hL s t hst hm g h₀ h₁ h₂ h₃ hV + let X := controlledPrefix m v s + let Z := fun ω => brownianEval ⟨t.val,t.property.1⟩ ω - brownianEval ⟨s.val,s.property.1⟩ ω + let A := fun ω => ∫ r in Set.Ioc s t, m r*v r ω ∂timeLaw + have hX := controlledPrefix_usual_measurable P m hv s + have hXm : AEMeasurable X P := usual_measurable_aemeasurable P s hX + have hAm : AEMeasurable A P := progressive_interval_integral_aemeasurable P hv m m.measurable s t + have hAb : ∀ ω, |A ω| ≤ (L : ℝ)*timeSpan s t := bounded_interval_drift P m L hv hL hst.le + have he := hC P g h₀ h₁ h₂ h₃ (timeSpan s t) (timeSpan_le_one s t) X Z A hXm + (brownian_increment_timeSpan P hB hst.le) + (brownian_increment_indep_adapted P hB s ⟨t.val,t.property.1⟩ hst hX) hAm hAb + have hXT : ∀ ω, X ω+Z ω+A ω = controlledPrefix m v t ω := fun ω => + (controlledPrefix_increment P m L hv hL hst.le ω).symm + simp only [hXT] at he + have hA : ∀ ω, A ω = (d : ℝ)*(timeSpan s t : ℝ)*g.d1 (X ω) := by + intro ω + dsimp only [A] + rw [setIntegral_congr_fun measurableSet_Ioc (fun r hr => by rw [hm r hr,hV r hr ω]), + timeLaw_integral_const_Ioc hst.le, timeSpan_coe hst.le] + ring + have hQ : ∀ ω, intervalControlCost m v s t ω = + (d : ℝ)*(timeSpan s t : ℝ)*(g.d1 (X ω))^2 := by + intro ω + rw [intervalControlCost,setIntegral_congr_fun measurableSet_Ioc (fun r hr => by rw [hm r hr,hV r hr ω]), + timeLaw_integral_const_Ioc hst.le, timeSpan_coe hst.le] + ring + have hJ : (∫ ω, g.d1 (X ω)*A ω ∂P) = + (d : ℝ)*(timeSpan s t : ℝ)*(∫ ω, (g.d1 (X ω))^2 ∂P) := by + simp only [hA] + rw [← integral_const_mul] + apply integral_congr_ae + exact Filter.Eventually.of_forall fun ω => by ring + have hQi : (∫ ω, intervalControlCost m v s t ω ∂P) = + (d : ℝ)*(timeSpan s t : ℝ)*(∫ ω, (g.d1 (X ω))^2 ∂P) := by + simp only [hQ,integral_const_mul] + rw [hJ] at he + rw [hQi] + convert! he using 1 + congr 1 + ring + +def backwardScore (P : Measure BrownianPath) (m : Trial) (v : Time → BrownianPath → ℝ) + (a b : Time) (d : ℝ≥0) (g : Jet3) (t : Time) : ℝ := + (∫ ω, heatLog (timeSpan t b) d g.f (controlledPrefix m v t ω) ∂P) - + (∫ ω, intervalControlCost m v a t ω ∂P)/2 + +lemma brownian_control_patch_gain (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (m : Trial) (d L₀ : ℝ≥0) (g : Jet3) + {a b : Time} (hm : ∀ r ∈ Set.Ioc a b, m r = (d : ℝ)) : + ∃ L C : ℝ≥0, L₀ ≤ L ∧ ∀ (v : Time → BrownianPath → ℝ), Progressive P v → + (∀ r ω, |v r ω| ≤ L) → ∀ s ∈ Set.Icc a b, ∀ t ∈ Set.Icc a b, s < t → + ∃ w : Time → BrownianPath → ℝ, Progressive P w ∧ (∀ r ω, |w r ω| ≤ L) ∧ + (∀ r ∉ Set.Ioc s t, ∀ ω, w r ω = v r ω) ∧ + backwardScore P m v a b d g s - (C : ℝ)*(timeSpan s t : ℝ)*Real.sqrt (timeSpan s t) ≤ + backwardScore P m w a b d g t := by + obtain ⟨C₀,C₁,C₂,C₃,hG⟩ := g.heatLog_uniform_bounds d + let L := max L₀ C₁ + obtain ⟨C,hC⟩ := brownian_control_feedback_cell d L C₀ C₁ C₂ C₃ + refine ⟨L,C,le_max_left _ _,?_⟩ + intro v hv hL s hs t ht hst + let j := g.heatLog (timeSpan t b) d + let A := fun ω => j.d1 (controlledPrefix m v s ω) + have hAm : @Measurable _ _ (usualBrownianSigma P s) (borel ℝ) A := + j.d1.continuous.measurable.comp (controlledPrefix_usual_measurable P m hv s) + obtain ⟨h₀,h₁,h₂,h₃⟩ := hG (timeSpan t b) + have hAL : ∀ ω, |A ω| ≤ L := fun ω => + ((j.d1.norm_coe_le_norm _).trans h₁).trans (show (C₁ : ℝ) ≤ L from le_max_right _ _) + let w := patchControl v s t A + have hw : Progressive P w := progressive_patchControl P hv s t hAm + have hwL : ∀ r ω, |w r ω| ≤ L := patchControl_bound hL s t hAL + have hmst : ∀ r ∈ Set.Ioc s t, m r = (d : ℝ) := fun r hr => hm r ⟨hs.1.trans_lt hr.1,hr.2.trans ht.2⟩ + have hXe : ∀ ω, controlledPrefix m w s ω = controlledPrefix m v s ω := + patchControl_prefix m v s t A le_rfl + have hQe : ∀ ω, intervalControlCost m w a s ω = intervalControlCost m v a s ω := + patchControl_cost_prefix m v s t A a le_rfl + have hfeedback : ∀ r ∈ Set.Ioc s t, ∀ ω, w r ω = j.d1 (controlledPrefix m w s ω) := by + intro r hr ω + rw [hXe] + exact ite_eq_left hr + have hh := hC P hB m w hw hwL s t hst hmst j h₀ h₁ h₂ h₃ hfeedback + change |(∫ ω, (g.heatLog (timeSpan t b) d).f (controlledPrefix m w t ω) ∂P) - _ - _| ≤ _ at hh + rw [g.heatLog_f] at hh + simp only [heatLogBCF_coe,heatLog_semigroup,timeSpan_add hst.le ht.2,hXe] at hh + have hcost := expected_intervalControlCost_add P m L hw hwL hs.1 hst.le + simp only [hQe] at hcost + refine ⟨w,hw,hwL,?_,?_⟩ + · intro r hr ω + exact ite_eq_right hr + · dsimp [backwardScore] + linarith only [(abs_le.mp hh).1,hcost] + +def timeMesh (a b : Time) (n k : ℕ) : Time := + Set.Icc.convexComb a b (Set.projIcc 0 1 zero_le_one ((k : ℝ)/(n+1))) + +lemma timeMesh_coe (a b : Time) (n k : ℕ) (hk : k ≤ n+1) : + (timeMesh a b n k : ℝ) = (a : ℝ)+((b : ℝ)-(a : ℝ))*((k : ℝ)/(n+1)) := by + have hp : (0 : ℝ) < n+1 := by positivity + have hh : (k : ℝ)/(n+1) ∈ Set.Icc (0 : ℝ) 1 := by + constructor + · positivity + · apply (div_le_one hp).mpr + exact_mod_cast hk + simp only [timeMesh, Set.projIcc_of_mem zero_le_one hh, Set.Icc.coe_convexComb] + ring + +lemma timeMesh_zero (a b : Time) (n : ℕ) : timeMesh a b n 0 = a := by + apply Subtype.ext + rw [timeMesh_coe a b n 0 (Nat.zero_le _)] + simp + +lemma timeMesh_last (a b : Time) (n : ℕ) : timeMesh a b n (n+1) = b := by + apply Subtype.ext + rw [timeMesh_coe a b n (n+1) le_rfl] + push_cast + rw [div_self (by positivity : (n : ℝ)+1 ≠ 0)] + ring + +lemma timeMesh_between {a b : Time} (hab : a ≤ b) (n k : ℕ) (hk : k ≤ n+1) : + timeMesh a b n k ∈ Set.Icc a b := by + have hp : (0 : ℝ) < n+1 := by positivity + have hq : 0 ≤ (k : ℝ)/(n+1) := by positivity + have hr : (k : ℝ)/(n+1) ≤ 1 := (div_le_one hp).mpr (by exact_mod_cast hk) + have habr : (a : ℝ) ≤ (b : ℝ) := hab + constructor <;> change _ ≤ (show ℝ from ↑_) + · rw [timeMesh_coe a b n k hk] + nlinarith + · rw [timeMesh_coe a b n k hk] + nlinarith + +lemma timeMesh_step {a b : Time} (hab : a < b) (n k : ℕ) (hk : k < n+1) : + timeMesh a b n k < timeMesh a b n (k+1) := by + change (timeMesh a b n k : ℝ) < (timeMesh a b n (k+1) : ℝ) + rw [timeMesh_coe a b n k hk.le, timeMesh_coe a b n (k+1) hk] + have hh : (a : ℝ) < (b : ℝ) := hab + have hp : (0 : ℝ) < n+1 := by positivity + apply add_lt_add_of_le_of_lt le_rfl + apply mul_lt_mul_of_pos_left _ (sub_pos.mpr hh) + apply div_lt_div_of_pos_right _ hp + exact_mod_cast Nat.lt_succ_self k + +lemma timeMesh_step_size (a b : Time) (n k : ℕ) (hk : k < n+1) : + (timeMesh a b n (k+1) : ℝ) - (timeMesh a b n k : ℝ) = ((b : ℝ)-(a : ℝ))/(n+1) := by + rw [timeMesh_coe a b n k hk.le,timeMesh_coe a b n (k+1) hk] + push_cast + ring + +lemma brownian_control_interval_lower_mesh (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (m : Trial) (d L₀ : ℝ≥0) (g : Jet3) + {a b : Time} (hab : a < b) (hm : ∀ r ∈ Set.Ioc a b, m r = (d : ℝ)) + (v : Time → BrownianPath → ℝ) (hv : Progressive P v) (hvL : ∀ r ω, |v r ω| ≤ L₀) : + ∃ L C : ℝ≥0, L₀ ≤ L ∧ ∀ n : ℕ, + ∃ w : Time → BrownianPath → ℝ, Progressive P w ∧ (∀ r ω, |w r ω| ≤ L) ∧ + (∀ r ∉ Set.Ioc a b, ∀ ω, w r ω = v r ω) ∧ + (∫ ω, heatLog (timeSpan a b) d g.f (controlledPrefix m v a ω) ∂P) - + (C : ℝ)*((b : ℝ)-(a : ℝ))*Real.sqrt (((b : ℝ)-(a : ℝ))/(n+1)) ≤ + (∫ ω, g.f (controlledPrefix m w b ω) ∂P) - + (∫ ω, intervalControlCost m w a b ω ∂P)/2 := by + obtain ⟨L,C,hLL,hgain⟩ := brownian_control_patch_gain P hB m d L₀ g hm + refine ⟨L,C,hLL,?_⟩ + intro n + let τ := timeMesh a b n + let δ : ℝ := ((b : ℝ)-(a : ℝ))/(n+1) + let E : ℝ := (C : ℝ)*δ*Real.sqrt δ + have hind : ∀ k : ℕ, k ≤ n+1 → + ∃ w : Time → BrownianPath → ℝ, Progressive P w ∧ (∀ r ω, |w r ω| ≤ L) ∧ + (∀ r ∉ Set.Ioc a b, ∀ ω, w r ω = v r ω) ∧ + backwardScore P m v a b d g a - (k : ℝ)*E ≤ backwardScore P m w a b d g (τ k) := by + intro k + induction k with + | zero => + intro _ + refine ⟨v,hv,fun r ω => (hvL r ω).trans (show (L₀ : ℝ) ≤ L from hLL),?_,?_⟩ + · intro _ _ _; rfl + · simp only [τ,timeMesh_zero,Nat.cast_zero,zero_mul,sub_zero,le_refl] + | succ k ih => + intro hk + obtain ⟨u,hu,huL,huout,huScore⟩ := ih (Nat.le_trans (Nat.le_succ k) hk) + have hk' : k < n+1 := hk + have hs := timeMesh_between hab.le n k hk'.le + have ht := timeMesh_between hab.le n (k+1) hk + have hst := timeMesh_step hab n k hk' + obtain ⟨w,hw,hwL,hwout,hwScore⟩ := hgain u hu huL (τ k) hs (τ (k+1)) ht hst + have heδ : (timeSpan (τ k) (τ (k+1)) : ℝ) = δ := by + rw [timeSpan_coe hst.le] + exact timeMesh_step_size a b n k hk' + rw [heδ] at hwScore + refine ⟨w,hw,hwL,?_,?_⟩ + · intro r hr ω + have hr' : r ∉ Set.Ioc (τ k) (τ (k+1)) := fun hh => + hr ⟨hs.1.trans_lt hh.1,hh.2.trans ht.2⟩ + rw [hwout r hr' ω] + exact huout r hr ω + · change backwardScore P m u a b d g (τ k) - E ≤ _ at hwScore + rw [Nat.cast_succ] + linarith only [huScore,hwScore] + obtain ⟨w,hw,hwL,hwout,hwScore⟩ := hind (n+1) le_rfl + have he : ((n+1 : ℕ) : ℝ)*E = + (C : ℝ)*((b : ℝ)-(a : ℝ))*Real.sqrt (((b : ℝ)-(a : ℝ))/(n+1)) := by + dsimp [E,δ] + push_cast + field_simp + have hz : timeSpan b b = 0 := by simp [timeSpan] + have hq : ∀ ω, intervalControlCost m v a a ω = 0 := by intro ω; simp [intervalControlCost] + simp only [τ,timeMesh_last,he,backwardScore,hz,heatLog_zero,hq,integral_zero,zero_div,sub_zero] at hwScore + exact ⟨w,hw,hwL,hwout,hwScore⟩ + +lemma brownian_control_interval_lower (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (m : Trial) (d L₀ : ℝ≥0) (g : Jet3) + {a b : Time} (hab : a < b) (hm : ∀ r ∈ Set.Ioc a b, m r = (d : ℝ)) + (v : Time → BrownianPath → ℝ) (hv : Progressive P v) (hvL : ∀ r ω, |v r ω| ≤ L₀) + {ε : ℝ} (hε : 0 < ε) : + ∃ L : ℝ≥0, ∃ w : Time → BrownianPath → ℝ, Progressive P w ∧ (∀ r ω, |w r ω| ≤ L) ∧ + (∀ r ∉ Set.Ioc a b, ∀ ω, w r ω = v r ω) ∧ + (∫ ω, heatLog (timeSpan a b) d g.f (controlledPrefix m v a ω) ∂P) - ε ≤ + (∫ ω, g.f (controlledPrefix m w b ω) ∂P) - + (∫ ω, intervalControlCost m w a b ω ∂P)/2 := by + obtain ⟨L,C,_,hmesh⟩ := brownian_control_interval_lower_mesh P hB m d L₀ g hab hm v hv hvL + have hn : Tendsto (fun n : ℕ => (n : ℝ)+1) atTop atTop := + tendsto_atTop_add_const_right _ _ tendsto_natCast_atTop_atTop + have hd : Tendsto (fun n : ℕ => ((b : ℝ)-(a : ℝ))/((n : ℝ)+1)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop hn + have he : Tendsto (fun n : ℕ => (C : ℝ)*((b : ℝ)-(a : ℝ))*Real.sqrt (((b : ℝ)-(a : ℝ))/(n+1))) + atTop (𝓝 0) := by + simpa using (Real.continuous_sqrt.tendsto 0 |>.comp hd).const_mul ((C : ℝ)*((b : ℝ)-(a : ℝ))) + obtain ⟨n,hn⟩ := (he.eventually (gt_mem_nhds hε)).exists + obtain ⟨w,hw,hwL,hwout,hwval⟩ := hmesh n + exact ⟨L,w,hw,hwL,hwout,by linarith⟩ + +inductive HeatChain (m : Trial) (g : Jet3) : Time → Time → Jet3 → Prop + | nil (a : Time) : HeatChain m g a a g + | cons {a t b : Time} {h : Jet3} (d : ℝ≥0) (hat : a < t) (htb : t ≤ b) + (hm : ∀ r ∈ Set.Ioc a t, m r = (d : ℝ)) (tail : HeatChain m g t b h) : + HeatChain m g a b (h.heatLog (timeSpan a t) d) + +lemma HeatChain.left_le_right {m : Trial} {g h : Jet3} {a b : Time} + (H : HeatChain m g a b h) : a ≤ b := by + cases H with + | nil => exact le_rfl + | cons _ hat htb _ _ => exact hat.le.trans htb + +lemma controls_equal_prefix {m : Trial} {v w : Time → BrownianPath → ℝ} {a b r : Time} + (h : ∀ t ∉ Set.Ioc a b, ∀ ω, w t ω = v t ω) (hr : r ≤ a) (ω : BrownianPath) : + controlledPrefix m w r ω = controlledPrefix m v r ω := by + unfold controlledPrefix + congr 1 + apply setIntegral_congr_fun measurableSet_Iic + intro t ht + dsimp only + rw [h t (fun hh => not_lt_of_ge (ht.trans hr) hh.1) ω] + +lemma controls_equal_cost_prefix {m : Trial} {v w : Time → BrownianPath → ℝ} {a b r s : Time} + (h : ∀ t ∉ Set.Ioc a b, ∀ ω, w t ω = v t ω) (hr : r ≤ a) (ω : BrownianPath) : + intervalControlCost m w s r ω = intervalControlCost m v s r ω := by + unfold intervalControlCost + apply setIntegral_congr_fun measurableSet_Ioc + intro t ht + dsimp only + rw [h t (fun hh => not_lt_of_ge (ht.2.trans hr) hh.1) ω] + +lemma HeatChain.upper {m : Trial} {g h : Jet3} {a b : Time} + (H : HeatChain m g a b h) (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (L : ℝ≥0) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hL : ∀ r ω, |v r ω| ≤ L) : + (∫ ω, g.f (controlledPrefix m v b ω) ∂P) - + (∫ ω, intervalControlCost m v a b ω ∂P)/2 ≤ + (∫ ω, h.f (controlledPrefix m v a ω) ∂P) := by + induction H with + | nil a => simp [intervalControlCost] + | @cons a t b h d hat htb hm tail ih => + have hi := brownian_control_interval_upper P hB m L d hv hL hat.le hm h + have hc := expected_intervalControlCost_add P m L hv hL hat.le htb + rw [Jet3.heatLog_f] + simp only [heatLogBCF_coe] + linarith only [ih,hi,hc] + +lemma HeatChain.lower {m : Trial} {g h : Jet3} {a b : Time} + (H : HeatChain m g a b h) (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (L : ℝ≥0) + (v : Time → BrownianPath → ℝ) (hv : Progressive P v) (hL : ∀ r ω, |v r ω| ≤ L) + {ε : ℝ} (hε : 0 < ε) : + ∃ K : ℝ≥0, ∃ w : Time → BrownianPath → ℝ, Progressive P w ∧ (∀ r ω, |w r ω| ≤ K) ∧ + (∀ r ∉ Set.Ioc a b, ∀ ω, w r ω = v r ω) ∧ + (∫ ω, h.f (controlledPrefix m v a ω) ∂P) - ε ≤ + (∫ ω, g.f (controlledPrefix m w b ω) ∂P) - + (∫ ω, intervalControlCost m w a b ω ∂P)/2 := by + induction H generalizing v L ε with + | nil a => + refine ⟨L,v,hv,hL,fun _ _ _ => rfl,?_⟩ + simp only [intervalControlCost,Set.Ioc_self,Measure.restrict_empty,integral_zero_measure, + integral_zero,zero_div,sub_zero] + linarith + | @cons a t b h d hat htb hm tail ih => + obtain ⟨K,u,hu,huK,huout,huval⟩ := + brownian_control_interval_lower P hB m d L h hat hm v hv hL (by positivity : 0 < ε/2) + obtain ⟨K',w,hw,hwK,hwout,hwval⟩ := ih K u hu huK (by positivity : 0 < ε/2) + have hc := expected_intervalControlCost_add P m K' hw hwK hat.le htb + have he : ∀ ω, intervalControlCost m w a t ω = intervalControlCost m u a t ω := + controls_equal_cost_prefix hwout le_rfl + simp only [he] at hc + refine ⟨K',w,hw,hwK,?_,?_⟩ + · intro r hr ω + rw [hwout r (fun hh => hr ⟨hat.trans hh.1,hh.2⟩) ω] + exact huout r (fun hh => hr ⟨hh.1,hh.2.trans htb⟩) ω + · rw [Jet3.heatLog_f] + simp only [heatLogBCF_coe] + linarith only [huval,hwval,hc] + +lemma controlledPrefix_one (m : Trial) (v : Time → BrownianPath → ℝ) (ω : BrownianPath) : + controlledPrefix m v 1 ω = brownianEval 1 ω + controlDrift m v ω := by + simp only [controlledPrefix,controlDrift,show Set.Iic (1 : Time) = Set.univ from Set.Iic_top, + Measure.restrict_univ] + rfl + +lemma controlledPrefix_zero (P : Measure BrownianPath) (hB : IsBrownianReal brownianEval P) + (m : Trial) (v : Time → BrownianPath → ℝ) : controlledPrefix m v 0 =ᵐ[P] fun _ => 0 := by + filter_upwards [hB.toIsPreBrownianReal.eval_zero_ae_eq_zero] with ω hω + simp only [controlledPrefix,show Set.Iic (0 : Time) = {0} from Set.Iic_bot, + Measure.restrict_singleton,measure_singleton,zero_smul,integral_zero_measure,add_zero] + exact hω + +lemma intervalControlCost_full (m : Trial) (v : Time → BrownianPath → ℝ) + (ω : BrownianPath) (hm : Measurable (v · ω)) : + intervalControlCost m v 0 1 ω = (pathControlCost m v ω).toReal := by + unfold intervalControlCost + rw [Measure.restrict_congr_set (Ioc_ae_eq_Icc (μ := timeLaw)), show Set.Icc (0 : Time) 1 = Set.univ from Set.Icc_bot_top, + Measure.restrict_univ] + exact integral_eq_lintegral_of_nonneg_ae + (Filter.Eventually.of_forall fun r => mul_nonneg (m.nonneg r) (sq_nonneg _)) + ((m.measurable.mul (hm.pow_const 2)).aestronglyMeasurable) + +lemma expected_intervalControlCost_full (P : Measure BrownianPath) (m : Trial) + {v : Time → BrownianPath → ℝ} (hv : Progressive P v) (hc : controlCost P m v < ∞) : + (∫ ω, intervalControlCost m v 0 1 ω ∂P) = (controlCost P m v).toReal := by + simp only [intervalControlCost_full m v _ (progressive_time_measurable P hv _)] + exact integral_pathControlCost P m hv hc + +lemma Jet3.lipschitz (g : Jet3) : LipschitzWith ‖g.d1‖₊ g.f := by + apply lipschitzWith_of_nnnorm_deriv_le (fun x => (g.has1 x).differentiableAt) + intro x + rw [g.deriv_eq] + exact_mod_cast g.d1.norm_coe_le_norm x + +lemma HeatChain.controlValue_eq {m : Trial} {g h : Jet3} + (H : HeatChain m g 0 1 h) (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) : controlValue P g.f m = h.f 0 := by + apply le_antisymm + · apply controlValue_le_of_bounded_controls P g.f m ‖g.d1‖₊ g.lipschitz + intro v hv hc hL + have hh := H.upper P hB ‖g.d1‖₊ hv hL + have he : (∫ ω, h.f (controlledPrefix m v 0 ω) ∂P) = h.f 0 := by + calc + _ = ∫ _ω : BrownianPath, h.f 0 ∂P := integral_congr_ae (by + filter_upwards [controlledPrefix_zero P hB m v] with ω hω + rw [hω]) + _ = _ := by simp + rw [he,expected_intervalControlCost_full P m hv hc] at hh + simp only [controlledPrefix_one] at hh + exact hh + · apply le_of_forall_pos_le_add + intro ε hε + obtain ⟨K,w,hw,hwK,_,hwval⟩ := H.lower P hB 0 (fun _ _ => 0) (progressive_zero P) + (by simp) hε + have hc : controlCost P m w < ∞ := (controlCost_le_bound P m K hwK).trans_lt (by finiteness) + have he : (∫ ω, h.f (controlledPrefix m (fun _ _ => 0) 0 ω) ∂P) = h.f 0 := by + calc + _ = ∫ _ω : BrownianPath, h.f 0 ∂P := integral_congr_ae (by + filter_upwards [controlledPrefix_zero P hB m (fun _ _ => 0)] with ω hω + rw [hω]) + _ = _ := by simp + rw [he,expected_intervalControlCost_full P m hw hc] at hwval + simp only [controlledPrefix_one] at hwval + have hsup : controlPayoff P g.f m w ≤ controlValue P g.f m := + le_csSup (controlPayoffs_bddAbove P g.f m) ⟨w,hw,hc,rfl⟩ + change h.f 0 - ε ≤ controlPayoff P g.f m w at hwval + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/BcfEvalRingHom.lean b/lean/OAI/Probability/Perceptron/Variational/BcfEvalRingHom.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d052fdfc86c04ac39a1ead575feee4647a6a525 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/BcfEvalRingHom.lean @@ -0,0 +1,443 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.HeatTilt + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff + +lemma shiftBCF_gaussian_integrable (f f' : ℝ →ᵇ ℝ) + (hf : ∀ x, HasDerivAt (f:ℝ→ℝ) (f' x) x) (a : ℝ) : + Integrable (fun z => shiftBCF f (a*z)) (gaussianReal 0 1) := by + apply Integrable.of_bound ((shiftBCF_lipschitz f f' hf).continuous.comp + (continuous_const.mul continuous_id)).aestronglyMeasurable ‖f‖ + exact ae_of_all _ (fun z => shiftBCF_norm_le f (a*z)) + +lemma gaussianAverage_scaling (s : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : + gaussianAverage s f x = ∫ z, f (x+Real.sqrt s*z) ∂gaussianReal 0 1 := by + have hv : (⟨(Real.sqrt s)^2, sq_nonneg _⟩ : ℝ≥0) = s := by + ext; exact Real.sq_sqrt s.coe_nonneg + have hL := gaussianReal_const_mul (HasLaw.id (μ := gaussianReal 0 1)) (Real.sqrt s) + simp only [mul_zero,NNReal.mk] at hL + rw [hv,mul_one] at hL + exact (hL.integral_comp (by fun_prop : AEStronglyMeasurable + (fun z => f (x+z)) (gaussianReal 0 s))).symm + +lemma gaussianAverageBCF_scaling (s : ℝ≥0) (g : Jet3) : + gaussianAverageBCF s g.f = ∫ z, shiftBCF g.f (Real.sqrt s*z) ∂gaussianReal 0 1 := by + have hi := shiftBCF_gaussian_integrable g.f g.d1 g.has1 (Real.sqrt s) + ext x + have he := (BoundedContinuousFunction.evalCLM ℝ x).integral_comp_comm hi + change gaussianAverage s g.f x = _ + rw [gaussianAverage_scaling] + exact he + +lemma gaussianAverageBCF_time_hasDerivAt (g : Jet3) (s : ℝ) (hs : 0 < s) : + HasDerivAt (fun t : ℝ => gaussianAverageBCF t.toNNReal g.f) + ((1/2 : ℝ) • gaussianAverageBCF s.toNNReal g.d2) s := by + let F : ℝ → ℝ → (ℝ →ᵇ ℝ) := fun t z => shiftBCF g.f (Real.sqrt t*z) + let D : ℝ → ℝ → (ℝ →ᵇ ℝ) := fun t z => + (z / (2*Real.sqrt t)) • shiftBCF g.d1 (Real.sqrt t*z) + have hz : Integrable (fun z : ℝ => |z|) (gaussianReal 0 1) := by + simpa only [pow_one,id_eq] using gaussian_law_integrable_abs_pow + (HasLaw.id (μ := gaussianReal 0 1)) 1 + have hm (t : ℝ) : AEStronglyMeasurable (F t) (gaussianReal 0 1) := by + exact (shiftBCF_gaussian_integrable g.f g.d1 g.has1 (Real.sqrt t)).aestronglyMeasurable + have hdm : AEStronglyMeasurable (D s) (gaussianReal 0 1) := by + apply Continuous.aestronglyMeasurable + exact (continuous_id.div_const _).smul ((shiftBCF_lipschitz g.d1 g.d2 g.has2).continuous.comp + (continuous_const.mul continuous_id)) + have hb : ∀ᵐ z ∂gaussianReal 0 1, ∀ t ∈ Set.Ioo (s/2) (2*s), + ‖D t z‖ ≤ |z| / (2*Real.sqrt (s/2)) * ‖g.d1‖ := by + apply ae_of_all + intro z t ht + have ht0 : 0 < t := by linarith [ht.1] + dsimp [D] + rw [norm_smul,Real.norm_eq_abs,abs_div,abs_of_pos (by positivity : 0 < 2*Real.sqrt t)] + apply mul_le_mul (div_le_div_of_nonneg_left (abs_nonneg z) (by positivity) + (by gcongr; exact ht.1.le)) (shiftBCF_norm_le _ _) (norm_nonneg _) (by positivity) + have hd : ∀ᵐ z ∂gaussianReal 0 1, ∀ t ∈ Set.Ioo (s/2) (2*s), + HasDerivAt (fun t => F t z) (D t z) t := by + apply ae_of_all + intro z t ht + have ht0 : t ≠ 0 := ne_of_gt (by linarith [ht.1]) + have hh := (shiftBCF_Jet3_hasDerivAt g (Real.sqrt t*z)).scomp t + ((Real.hasDerivAt_sqrt ht0).mul_const z) + simpa only [F,D,Function.comp_def,div_eq_mul_inv,_root_.mul_inv_rev,mul_comm,mul_left_comm,mul_assoc,one_mul] using hh + have hh := hasDerivAt_integral_of_dominated_loc_of_deriv_le + (Ioo_mem_nhds (by linarith : s/2 < s) (by linarith : s < 2*s)) + (Filter.Eventually.of_forall hm) + (shiftBCF_gaussian_integrable g.f g.d1 g.has1 (Real.sqrt s)) + hdm hb ((hz.div_const _).mul_const ‖g.d1‖) hd + have he : (∫ z, D s z ∂gaussianReal 0 1) = + (1/2 : ℝ) • gaussianAverageBCF s.toNNReal g.d2 := by + ext x + have hev := (BoundedContinuousFunction.evalCLM ℝ x).integral_comp_comm hh.1 + have hib := standardGaussian_integrationByParts + (F := fun z => g.d1 (x+Real.sqrt s*z)) + (F' := fun z => Real.sqrt s*g.d2 (x+Real.sqrt s*z)) + (C := ‖g.d1‖) (D := Real.sqrt s*‖g.d2‖) + (fun z => by + have h := (g.has2 (x+Real.sqrt s*z)).comp z + (((hasDerivAt_id z).const_mul (Real.sqrt s)).const_add x) + simpa only [Function.comp_def,id_eq,mul_one,one_mul,mul_comm] using h) + (by fun_prop) + (fun z => by simpa only [Real.norm_eq_abs] using g.d1.norm_coe_le_norm (x+Real.sqrt s*z)) + (fun z => by + rw [abs_mul,abs_of_nonneg (Real.sqrt_nonneg _)] + exact mul_le_mul_of_nonneg_left (g.d2.norm_coe_le_norm (x+Real.sqrt s*z)) + (Real.sqrt_nonneg _)) + change (∫ z, (D s z) x ∂gaussianReal 0 1) = (∫ z,D s z ∂gaussianReal 0 1) x at hev + rw [← hev] + change (∫ z, z/(2*Real.sqrt s)*g.d1 (x+Real.sqrt s*z) ∂gaussianReal 0 1) = + (1/2)*gaussianAverage s.toNNReal g.d2 x + rw [gaussianAverage_scaling,Real.coe_toNNReal s hs.le] + have hc : (∫ z, z/(2*Real.sqrt s)*g.d1 (x+Real.sqrt s*z) ∂gaussianReal 0 1) = + (2*Real.sqrt s)⁻¹ * ∫ z, z*g.d1 (x+Real.sqrt s*z) ∂gaussianReal 0 1 := by + rw [← integral_const_mul]; congr 1; ext z; ring + rw [hc,hib,integral_const_mul] + field_simp [ne_of_gt (Real.sqrt_pos.mpr hs)] + rw [he] at hh + apply hh.2.congr_of_eventuallyEq + filter_upwards [eventually_gt_nhds hs] with t ht + exact (gaussianAverageBCF_scaling t.toNNReal g).trans (by rw [Real.coe_toNNReal t ht.le]) + +lemma log_lipschitz_above {a b c : ℝ} (hc : 0 < c) (ha : c ≤ a) (hb : c ≤ b) : + |Real.log b-Real.log a| ≤ c⁻¹*|b-a| := by + apply (convex_Ici c).norm_image_sub_le_of_norm_hasDerivWithin_le + (fun x hx => (Real.hasDerivAt_log (ne_of_gt (hc.trans_le hx))).hasDerivWithinAt) + (fun x hx => ?_) ha hb + rw [Real.norm_eq_abs,abs_inv,abs_of_pos (hc.trans_le hx)] + exact inv_anti₀ hc hx + +lemma heatLogBCF_time_continuousAt (g : Jet3) (d : ℝ≥0) (s : ℝ) (hs : 0 < s) : + ContinuousAt (fun t : ℝ => heatLogBCF t.toNNReal d g.f) s := by + by_cases hd : d = 0 + · subst d + have he : (fun t : ℝ => heatLogBCF t.toNNReal 0 g.f) = + (fun t => gaussianAverageBCF t.toNNReal g.f) := by ext t x; simp [heatLog] + rw [he] + exact (gaussianAverageBCF_time_hasDerivAt g s hs).continuousAt + let A : ℝ → (ℝ →ᵇ ℝ) := fun t => gaussianAverageBCF t.toNNReal (expBCF d g.f) + let c : ℝ := Real.exp (-(d : ℝ)*‖g.f‖) + have hc : 0 < c := Real.exp_pos _ + have hb t : ∀ x, c ≤ A t x := fun x => (gaussianAverage_exp_bounds t.toNNReal d d.coe_nonneg g.f x).1 + have ha : ContinuousAt A s := (gaussianAverageBCF_time_hasDerivAt (g.exp d) s hs).continuousAt + have hbd t : ‖heatLogBCF t.toNNReal d g.f - heatLogBCF s.toNNReal d g.f‖ ≤ + (d : ℝ)⁻¹*c⁻¹*‖A t-A s‖ := by + apply (BoundedContinuousFunction.norm_le (by positivity)).mpr + intro x + change |heatLog t.toNNReal d g.f x-heatLog s.toNNReal d g.f x| ≤ _ + simp only [heatLog,hd,↓reduceIte,← mul_sub,abs_mul,abs_inv,abs_of_nonneg d.coe_nonneg] + calc + _ ≤ (d : ℝ)⁻¹*(c⁻¹*|A t x-A s x|) := + mul_le_mul_of_nonneg_left (log_lipschitz_above hc (hb s x) (hb t x)) (by positivity) + _ ≤ (d : ℝ)⁻¹*c⁻¹*‖A t-A s‖ := by + rw [← mul_assoc] + exact mul_le_mul_of_nonneg_left ((A t-A s).norm_coe_le_norm x) (by positivity) + have ht : Tendsto (fun t => (d : ℝ)⁻¹*c⁻¹*‖A t-A s‖) (𝓝 s) (𝓝 0) := by + simpa only [Pi.sub_apply,sub_self,norm_zero,mul_zero] using + (ha.sub (continuousAt_const (y := A s))).norm.const_mul ((d : ℝ)⁻¹*c⁻¹) |>.tendsto + exact tendsto_sub_nhds_zero_iff.mp (squeeze_zero_norm hbd ht) + +private def bcfEvalRingHom (x : ℝ) : (ℝ →ᵇ ℝ) →+* ℝ where + toFun := fun f => f x + map_one' := rfl + map_mul' _ _ := rfl + map_zero' := rfl + map_add' _ _ := rfl + +lemma expBCF_eq_normedSpace_exp (d : ℝ) (f : ℝ →ᵇ ℝ) : + expBCF d f = NormedSpace.exp (d • f) := by + ext x + have hh := NormedSpace.map_exp (bcfEvalRingHom x) + (BoundedContinuousFunction.evalCLM ℝ x).continuous (d • f) + change _ = (bcfEvalRingHom x) (NormedSpace.exp (d • f)) + rw [hh,← Real.exp_eq_exp_ℝ] + rfl + +lemma expBCF_hasFDerivAt (d : ℝ) (f : ℝ →ᵇ ℝ) : + HasFDerivAt (expBCF d) + ((expBCF d f • (1 : (ℝ →ᵇ ℝ) →L[ℝ] (ℝ →ᵇ ℝ))) ∘L + (d • (1 : (ℝ →ᵇ ℝ) →L[ℝ] (ℝ →ᵇ ℝ)))) f := by + have hh := (hasFDerivAt_exp (𝕂 := ℝ) (x := d • f)).comp f + ((d • (1 : (ℝ →ᵇ ℝ) →L[ℝ] (ℝ →ᵇ ℝ))).hasFDerivAt) + simpa only [← expBCF_eq_normedSpace_exp,one_apply_eq_self, + _root_.smul_apply,Function.comp_def] using hh + +def heatGenerator (d : ℝ≥0) (g : Jet3) : ℝ →ᵇ ℝ := + (1/2 : ℝ) • (g.d2 + (d : ℝ) • g.d1^2) + +lemma heatLogBCF_time_hasDerivAt (g : Jet3) (d : ℝ≥0) (s : ℝ) (hs : 0 < s) : + HasDerivAt (fun t : ℝ => heatLogBCF t.toNNReal d g.f) + (heatGenerator d (g.heatLog s.toNNReal d)) s := by + by_cases hd : d = 0 + · subst d + convert gaussianAverageBCF_time_hasDerivAt g s hs using 1 + · ext t x; simp [heatLog] + · simp [heatGenerator,Jet3.heatLog,Jet3.gaussianAverage] + have hdR : (d : ℝ) ≠ 0 := NNReal.coe_ne_zero.mpr hd + let U := heatLogBCF s.toNNReal d g.f + let L : (ℝ →ᵇ ℝ) →L[ℝ] (ℝ →ᵇ ℝ) := + ((d : ℝ)⁻¹ • expBCF (-(d : ℝ)) U) • (1 : (ℝ →ᵇ ℝ) →L[ℝ] (ℝ →ᵇ ℝ)) + have hlin : Function.LeftInverse L + ((expBCF d U • (1 : (ℝ →ᵇ ℝ) →L[ℝ] (ℝ →ᵇ ℝ))) ∘L + ((d : ℝ) • (1 : (ℝ →ᵇ ℝ) →L[ℝ] (ℝ →ᵇ ℝ)))) := by + intro h + ext x + change ((d : ℝ)⁻¹*Real.exp (-(d : ℝ)*U x))*(Real.exp ((d : ℝ)*U x)*((d : ℝ)*h x)) = h x + calc + _ = ((d : ℝ)⁻¹*d)*(Real.exp (-(d : ℝ)*U x)*Real.exp ((d : ℝ)*U x))*h x := by ring + _ = h x := by rw [← Real.exp_add]; simp [hdR] + have hcomp : expBCF d ∘ (fun t : ℝ => heatLogBCF t.toNNReal d g.f) =ᶠ[𝓝 s] + (fun t : ℝ => gaussianAverageBCF t.toNNReal (g.exp d).f) := by + apply Filter.Eventually.of_forall + intro t + ext x + exact exp_heatLog t.toNNReal d hd g.f x + have hh := HasFDerivAt.of_comp_of_leftInverse + (heatLogBCF_time_continuousAt g d s hs) (expBCF_hasFDerivAt d U) + (gaussianAverageBCF_time_hasDerivAt (g.exp d) s hs).hasFDerivAt hcomp hlin + have he : L ((1/2 : ℝ) • gaussianAverageBCF s.toNNReal (g.exp d).d2) = + heatGenerator d (g.heatLog s.toNNReal d) := by + ext x + have hex : Real.exp (-(d : ℝ)*U x) = (gaussianAverage s.toNNReal (expBCF d g.f) x)⁻¹ := by + rw [neg_mul,Real.exp_neg,show Real.exp ((d : ℝ)*U x) = _ from exp_heatLog s.toNNReal d hd g.f x] + change ((d : ℝ)⁻¹*Real.exp (-(d : ℝ)*U x)) * + ((1/2)*gaussianAverage s.toNNReal (g.exp d).d2 x) = _ + rw [hex] + simp only [Jet3.heatLog,hd,↓reduceDIte] + change _ = (1/2)*((d : ℝ)⁻¹ * + (gaussianAverage s.toNNReal (g.exp d).d2 x * + (gaussianAverage s.toNNReal (expBCF d g.f) x)⁻¹ - + (gaussianAverage s.toNNReal (g.exp d).d1 x)^2 * + ((gaussianAverage s.toNNReal (expBCF d g.f) x)⁻¹)^2) + + (d : ℝ)*((d : ℝ)⁻¹ * (gaussianAverage s.toNNReal (g.exp d).d1 x * + (gaussianAverage s.toNNReal (expBCF d g.f) x)⁻¹))^2) + field_simp [hdR,(gaussianAverage_exp_pos s.toNNReal d g.f x).ne'] + ring + apply hh.hasDerivAt.congr_deriv + simpa only [ContinuousLinearMap.comp_apply,ContinuousLinearMap.toSpanSingleton_apply, + one_smul] using he + +lemma gaussianAverageBCF_scaling_of_deriv (s : ℝ≥0) (f f' : ℝ →ᵇ ℝ) + (hf : ∀ x, HasDerivAt (f:ℝ→ℝ) (f' x) x) : + gaussianAverageBCF s f = ∫ z, shiftBCF f (Real.sqrt s*z) ∂gaussianReal 0 1 := by + have hi := shiftBCF_gaussian_integrable f f' hf (Real.sqrt s) + ext x + have he := (BoundedContinuousFunction.evalCLM ℝ x).integral_comp_comm hi + change gaussianAverage s f x = _ + rw [gaussianAverage_scaling] + exact he + +lemma gaussianAverageBCF_time_continuous_of_deriv (f f' : ℝ →ᵇ ℝ) + (hf : ∀ x, HasDerivAt (f:ℝ→ℝ) (f' x) x) : + Continuous (fun t : ℝ => gaussianAverageBCF t.toNNReal f) := by + have he : (fun t : ℝ => gaussianAverageBCF t.toNNReal f) = + (fun t : ℝ => ∫ z, shiftBCF f (Real.sqrt t.toNNReal*z) ∂gaussianReal 0 1) := by + ext t x + exact congrArg (fun h : ℝ →ᵇ ℝ => h x) (gaussianAverageBCF_scaling_of_deriv t.toNNReal f f' hf) + rw [he] + apply continuous_of_dominated (bound := fun _ => ‖f‖) + · intro t + exact (shiftBCF_gaussian_integrable f f' hf (Real.sqrt t.toNNReal)).aestronglyMeasurable + · intro t + exact ae_of_all _ (fun z => shiftBCF_norm_le f (Real.sqrt t.toNNReal*z)) + · exact integrable_const _ + · apply ae_of_all + intro z + apply (shiftBCF_lipschitz f f' hf).continuous.comp + exact (Real.continuous_sqrt.comp (NNReal.continuous_coe.comp continuous_real_toNNReal)).mul_const z + +lemma heatTiltBCF_time_continuous_of_deriv (f f' h h' : ℝ →ᵇ ℝ) + (hf : ∀ x, HasDerivAt (f:ℝ→ℝ) (f' x) x) + (hh : ∀ x, HasDerivAt (h:ℝ→ℝ) (h' x) x) (d : ℝ≥0) : + Continuous (fun t : ℝ => heatTiltBCF t.toNNReal d f h) := by + let A := expBCF d f + let A' := (d : ℝ) • (A*f') + have hA x : HasDerivAt (A:ℝ→ℝ) (A' x) x := by + change HasDerivAt (fun y => Real.exp ((d : ℝ)*f y)) ((d : ℝ)*(A x*f' x)) x + exact ((hf x).const_mul (d : ℝ)).exp.congr_deriv (by dsimp [A,expBCF]; ring) + have hB x : HasDerivAt (A*h : ℝ →ᵇ ℝ) ((A'*h+A*h') x) x := by + simpa only [BoundedContinuousFunction.coe_mul,Pi.mul_apply, + BoundedContinuousFunction.coe_add,Pi.add_apply] using (hA x).mul (hh x) + have hca := gaussianAverageBCF_time_continuous_of_deriv A A' hA + have hcb := gaussianAverageBCF_time_continuous_of_deriv (A*h) (A'*h+A*h') hB + let c := Real.exp (-(d : ℝ)*‖f‖) + have hc : 0 < c := Real.exp_pos _ + let J (t : ℝ) := invBCF (gaussianAverageBCF t.toNNReal A) c hc + (fun x => (gaussianAverage_exp_bounds t.toNNReal d d.coe_nonneg f x).1) + have hJ : Continuous J := by + apply continuous_iff_continuousAt.mpr + intro s + have hb t : ‖J t-J s‖ ≤ c⁻¹^2 * ‖gaussianAverageBCF t.toNNReal A-gaussianAverageBCF s.toNNReal A‖ := by + apply (BoundedContinuousFunction.norm_le (by positivity)).mpr + intro x + change |(gaussianAverage t.toNNReal A x)⁻¹-(gaussianAverage s.toNNReal A x)⁻¹| ≤ _ + have h1 := (gaussianAverage_exp_bounds t.toNNReal d d.coe_nonneg f x).1 + have h2 := (gaussianAverage_exp_bounds s.toNNReal d d.coe_nonneg f x).1 + have h1p : 0 < gaussianAverage t.toNNReal A x := hc.trans_le h1 + have h2p : 0 < gaussianAverage s.toNNReal A x := hc.trans_le h2 + rw [inv_sub_inv h1p.ne' h2p.ne',abs_div,abs_mul, + abs_of_pos h1p,abs_of_pos h2p,abs_sub_comm] + calc + _ ≤ ‖gaussianAverageBCF t.toNNReal A-gaussianAverageBCF s.toNNReal A‖/(c*c) := + div_le_div₀ (by positivity) ((gaussianAverageBCF t.toNNReal A-gaussianAverageBCF s.toNNReal A).norm_coe_le_norm x) + (by positivity) (mul_le_mul h1 h2 hc.le h1p.le) + _ = _ := by ring + have ht : Tendsto (fun t => c⁻¹^2*‖gaussianAverageBCF t.toNNReal A-gaussianAverageBCF s.toNNReal A‖) + (𝓝 s) (𝓝 0) := by + simpa only [Pi.sub_apply,sub_self,norm_zero,mul_zero] using + ((hca.continuousAt (x := s)).sub (continuousAt_const (y := gaussianAverageBCF s.toNNReal A))).norm.const_mul (c⁻¹^2) |>.tendsto + exact tendsto_sub_nhds_zero_iff.mp (squeeze_zero_norm hb ht) + have he : (fun t : ℝ => heatTiltBCF t.toNNReal d f h) = + (fun t => gaussianAverageBCF t.toNNReal (A*h)*J t) := by + ext t x + change gaussianAverage t.toNNReal (A*h) x / gaussianAverage t.toNNReal A x = _ + rfl + rw [he] + exact hcb.mul hJ + +lemma heatGenerator_hasDerivAt (g : Jet3) (d : ℝ≥0) (x : ℝ) : + HasDerivAt (heatGenerator d g : ℝ → ℝ) + (((1/2 : ℝ) • (g.d3+(2*(d:ℝ)) • (g.d1*g.d2))) x) x := by + have hh := ((g.has3 x).add ((g.has2 x).pow 2 |>.const_mul (d : ℝ))).const_mul (1/2 : ℝ) + change HasDerivAt (fun y => (1/2 : ℝ)*(g.d2 y+(d:ℝ)*(g.d1 y)^2)) + ((1/2 : ℝ)*(g.d3 x+(2*(d:ℝ))*(g.d1 x*g.d2 x))) x + exact hh.congr_deriv (by norm_num; ring) + +lemma heatTilt_heatGenerator (g : Jet3) (s d : ℝ≥0) : + heatTiltCLM s d g.f (heatGenerator d g) = heatGenerator d (g.heatLog s d) := by + by_cases hd : d = 0 + · subst d + ext x + simp only [heatGenerator,NNReal.coe_zero,zero_smul,add_zero] + change heatTilt s 0 g.f ((1/2 : ℝ) • g.d2) x = _ + rw [heatTilt_zero,gaussianAverage_smul] + simp only [Jet3.heatLog,↓reduceDIte] + rfl + have hdR : (d : ℝ) ≠ 0 := NNReal.coe_ne_zero.mpr hd + ext x + have hf : (g.exp d).d2 = (d : ℝ) • (expBCF d g.f*(g.d2+(d : ℝ) • g.d1^2)) := by + ext z + simp only [Jet3.exp,BoundedContinuousFunction.coe_smul,BoundedContinuousFunction.coe_add, + BoundedContinuousFunction.coe_mul,BoundedContinuousFunction.coe_pow, + Pi.add_apply,Pi.mul_apply,Pi.pow_apply,smul_eq_mul] + ring + have hf1 : (g.exp d).d1 = (d : ℝ) • (expBCF d g.f*g.d1) := rfl + change heatTilt s d g.f (heatGenerator d g) x = _ + simp only [heatGenerator,heatTilt_smul,heatTilt_add,Jet3.heatLog,hd,↓reduceDIte] + change (1/2)*(heatTilt s d g.f g.d2 x + (d:ℝ)*heatTilt s d g.f (g.d1^2) x) = + (1/2)*((d : ℝ)⁻¹ * + (gaussianAverage s (g.exp d).d2 x * (gaussianAverage s (expBCF d g.f) x)⁻¹ - + (gaussianAverage s (g.exp d).d1 x)^2 * ((gaussianAverage s (expBCF d g.f) x)⁻¹)^2) + + (d : ℝ)*((d : ℝ)⁻¹ * (gaussianAverage s (g.exp d).d1 x * + (gaussianAverage s (expBCF d g.f) x)⁻¹))^2) + rw [hf,hf1,gaussianAverage_smul,gaussianAverage_smul] + have hm : expBCF d g.f*(g.d2+(d : ℝ) • g.d1^2) = + expBCF d g.f*g.d2+(d : ℝ) • (expBCF d g.f*g.d1^2) := by ext z; simp; ring + rw [hm,gaussianAverage_add,gaussianAverage_smul] + unfold heatTilt + simp only [BoundedContinuousFunction.coe_mul] + field_simp [hdR,(gaussianAverage_exp_pos s d g.f x).ne'] + ring + +lemma heatLogBCF_moving_hasDerivAt (g : Jet3) (d : ℝ≥0) + (σ : ℝ → ℝ) (G : ℝ → (ℝ →ᵇ ℝ)) (θ v : ℝ) (h h' : ℝ →ᵇ ℝ) + (hσ : HasDerivAt σ v θ) (hs : 0 < σ θ) + (hG : HasDerivAt G h θ) (hGθ : G θ = g.f) + (hh : ∀ x, HasDerivAt (h:ℝ→ℝ) (h' x) x) : + HasDerivAt (fun t => heatLogBCF (σ t).toNNReal d (G t)) + (v • heatGenerator d (g.heatLog (σ θ).toNNReal d) + + heatTiltCLM (σ θ).toNNReal d g.f h) θ := by + let L (t : ℝ) := heatTiltCLM (σ t).toNNReal d g.f + let A (t : ℝ) := heatLogBCF (σ t).toNNReal d g.f + let K (t : ℝ) := G t-g.f + have hK0 : Tendsto K (𝓝 θ) (𝓝 0) := by + simpa only [hGθ,sub_self] using hG.continuousAt.tendsto.sub_const g.f + have hKo : (fun t => ‖K t‖) =o[𝓝 θ] (fun _ => (1 : ℝ)) := + (Asymptotics.isLittleO_one_iff ℝ).mpr (by simpa only [norm_zero] using hK0.norm) + have hKb : (fun t => ‖K t‖) =O[𝓝 θ] (fun t => t-θ) := by + simpa only [hGθ] using hG.isBigO_sub.norm_left + have hR : (fun t => heatLogBCF (σ t).toNNReal d (G t)-A t-L t (K t)) + =o[𝓝 θ] (fun t => t-θ) := by + have hb : (fun t => heatLogBCF (σ t).toNNReal d (G t)-A t-L t (K t)) + =O[𝓝 θ] (fun t => ‖K t‖*‖K t‖) := by + apply Asymptotics.IsBigO.of_bound (2*(d:ℝ)) + apply Filter.Eventually.of_forall + intro t + have he := heatLogBCF_terminal_quadratic_error (σ t).toNNReal d g.f (K t) + simpa only [K,A,L,add_sub_cancel,norm_mul,Real.norm_of_nonneg (norm_nonneg _),pow_two] using he + exact hb.trans_isLittleO (by simpa only [one_mul] using hKo.mul_isBigO hKb) + have hE : (fun t => L t (G t-g.f-(t-θ) • h)) =o[𝓝 θ] (fun t => t-θ) := by + have hb : (fun t => L t (G t-g.f-(t-θ) • h)) =O[𝓝 θ] + (fun t => G t-g.f-(t-θ) • h) := by + apply Asymptotics.IsBigO.of_bound' + exact Filter.Eventually.of_forall (fun t => heatTiltBCF_norm_le (σ t).toNNReal d g.f _) + apply hb.trans_isLittleO + simpa only [hGθ] using hG.isLittleO + have hLc : Tendsto (fun t => L t h-L θ h) (𝓝 θ) (𝓝 0) := by + have hc := (heatTiltBCF_time_continuous_of_deriv g.f g.d1 h h' g.has1 hh d).continuousAt.comp + hσ.continuousAt + have he := hc.tendsto.sub_const (L θ h) + change Tendsto (fun t => L t h-L θ h) (𝓝 θ) (𝓝 (L θ h-L θ h)) at he + simpa only [sub_self] using he + have hLo : (fun t => (t-θ) • (L t h-L θ h)) =o[𝓝 θ] (fun t => t-θ) := by + have he := (Asymptotics.isBigO_refl (fun t : ℝ => t-θ) (𝓝 θ)).smul_isLittleO + ((Asymptotics.isLittleO_one_iff ℝ).mpr hLc) + simpa only [smul_eq_mul,mul_one] using he + have hA : HasDerivAt A (v • heatGenerator d (g.heatLog (σ θ).toNNReal d)) θ := + (heatLogBCF_time_hasDerivAt g d (σ θ) hs).scomp θ hσ + apply HasDerivAt.of_isLittleO + apply ((hA.isLittleO.add hR).add hE |>.add hLo).congr_left + intro t + simp only [hGθ,K,A,L,map_sub,map_smul,smul_add,smul_sub] + abel + +lemma heatTiltBCF_hasDerivAt (s d : ℝ≥0) (f f' h h' : ℝ →ᵇ ℝ) + (hf : ∀ x, HasDerivAt (f:ℝ→ℝ) (f' x) x) + (hh : ∀ x, HasDerivAt (h:ℝ→ℝ) (h' x) x) (x : ℝ) : + HasDerivAt (heatTiltBCF s d f h : ℝ→ℝ) + ((heatTiltBCF s d f h' + (d:ℝ) • + (heatTiltBCF s d f (f'*h)-heatTiltBCF s d f f'*heatTiltBCF s d f h)) x) x := by + let A := expBCF d f + let A' := (d : ℝ) • (A*f') + have hA y : HasDerivAt (A:ℝ→ℝ) (A' y) y := by + change HasDerivAt (fun z => Real.exp ((d:ℝ)*f z)) ((d:ℝ)*(A y*f' y)) y + exact ((hf y).const_mul (d:ℝ)).exp.congr_deriv (by dsimp [A,expBCF]; ring) + have hB y : HasDerivAt (A*h : ℝ→ᵇ ℝ) ((A'*h+A*h') y) y := by + simpa only [BoundedContinuousFunction.coe_mul,Pi.mul_apply, + BoundedContinuousFunction.coe_add,Pi.add_apply] using (hA y).mul (hh y) + have he := (gaussianAverage_hasDerivAt s (A*h) (A'*h+A*h') hB x).div + (gaussianAverage_hasDerivAt s A A' hA x) (gaussianAverage_exp_pos s d f x).ne' + change HasDerivAt (fun y => gaussianAverage s (A*h) y / gaussianAverage s A y) _ x + apply he.congr_deriv + have hmul : A'*h = (d:ℝ) • (A*(f'*h)) := by ext y; dsimp [A']; ring + rw [gaussianAverage_add,hmul,gaussianAverage_smul] + symm + change (gaussianAverage s (A*h') x/gaussianAverage s A x) + + (d:ℝ)*((gaussianAverage s (A*(f'*h)) x/gaussianAverage s A x)- + (gaussianAverage s (A*f') x/gaussianAverage s A x)* + (gaussianAverage s (A*h) x/gaussianAverage s A x)) = _ + dsimp only [A'] + rw [gaussianAverage_smul] + simp only [BoundedContinuousFunction.coe_mul] + field_simp [show gaussianAverage s A x ≠ 0 from (gaussianAverage_exp_pos s d f x).ne'] + ring + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/BlockFocus.lean b/lean/OAI/Probability/Perceptron/Variational/BlockFocus.lean new file mode 100644 index 0000000000000000000000000000000000000000..2607db3874cea54f10389259177931a439d653f7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/BlockFocus.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FocusedSampleLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology +namespace SphericalPerceptronFreeEnergy + +def indexedBlockSample {I : Type} [Fintype I] (k : ℕ) + (A : I → I → Fin (k+1)) (b : IndexedCascadeBase k) : ℝ≥0∞ := + ∑' xs : I → IndexedLeaf k, (∏ i, (indexedLeafProbability k b) {xs i}) * + if (fun i j => indexedCommonDepth k (xs i) (xs j)) = A then 1 else 0 + +def indexedBlockFocused {I : Type} [Fintype I] (k d : ℕ) + (A : I → I → Fin (k+1)) (i₀ : I) (b : IndexedCascadeBase k) : ℝ≥0∞ := + ∑' xs : I → IndexedLeaf k, ((∏ i, (indexedLeafProbability k b) {xs i}) * + if (fun i j => indexedCommonDepth k (xs i) (xs j)) = A then 1 else 0) * + ∑' l : IndexedLeaf k, (indexedLeafProbability k b) {l} * + if d ≤ (indexedCommonDepth k (xs i₀) l).val then 1 else 0 + +lemma reindexed_shape_matches {I : Type} [Fintype I] (k : ℕ) + (s : CascadeVisitShape k) (e : I ≃ CascadeShapeReplicas k s) + (A : I → I → Fin (k+1)) + (hA : ∀ i j, A i j = indexedCommonDepth k (cascadeShapeLeaves k s (e i)) + (cascadeShapeLeaves k s (e j))) (ys : CascadeShapeReplicas k s → IndexedLeaf k) : + (fun i j => indexedCommonDepth k (ys (e i)) (ys (e j))) = A ↔ + CascadeShapeMatches k s ys := by + rw [cascadeShapeMatches_iff] + constructor + · intro h i j + obtain ⟨i,rfl⟩ := e.surjective i + obtain ⟨j,rfl⟩ := e.surjective j + exact congrFun (congrFun h i) j |>.trans (hA i j) + · intro h + funext i j + exact (h (e i) (e j)).trans (hA i j).symm + +lemma indexedBlockSample_shape {I : Type} [Fintype I] (k : ℕ) + (s : CascadeVisitShape k) (e : I ≃ CascadeShapeReplicas k s) + (A : I → I → Fin (k+1)) + (hA : ∀ i j, A i j = indexedCommonDepth k (cascadeShapeLeaves k s (e i)) + (cascadeShapeLeaves k s (e j))) (b : IndexedCascadeBase k) : + indexedBlockSample k A b = indexedSampleShape k s b := by + unfold indexedBlockSample indexedSampleShape + rw [← (Equiv.arrowCongr e.symm (Equiv.refl (IndexedLeaf k))).tsum_eq] + apply tsum_congr + intro ys + change ((∏ i, (indexedLeafProbability k b) {ys (e i)}) * + if (fun i j => indexedCommonDepth k (ys (e i)) (ys (e j))) = A then 1 else 0) = _ + rw [e.prod_comp (fun i => (indexedLeafProbability k b) {ys i})] + simp only [reindexed_shape_matches k s e A hA ys] + +lemma indexedBlockFocused_shape {I : Type} [Fintype I] (k d : ℕ) + (s : CascadeVisitShape k) (hs : s.Valid k) (e : I ≃ CascadeShapeReplicas k s) + (A : I → I → Fin (k+1)) (i₀ : I) (hi₀ : e i₀ = cascadeShapeFocus k s hs) + (hA : ∀ i j, A i j = indexedCommonDepth k (cascadeShapeLeaves k s (e i)) + (cascadeShapeLeaves k s (e j))) (b : IndexedCascadeBase k) : + indexedBlockFocused k d A i₀ b = indexedSampleFocused k d s hs b := by + unfold indexedBlockFocused indexedSampleFocused + rw [← (Equiv.arrowCongr e.symm (Equiv.refl (IndexedLeaf k))).tsum_eq] + apply tsum_congr + intro ys + change (((∏ i, (indexedLeafProbability k b) {ys (e i)}) * + if (fun i j => indexedCommonDepth k (ys (e i)) (ys (e j))) = A then 1 else 0) * + ∑' l, (indexedLeafProbability k b) {l} * if d ≤ (indexedCommonDepth k (ys (e i₀)) l).val then 1 else 0) = _ + rw [e.prod_comp (fun i => (indexedLeafProbability k b) {ys i})] + simp only [reindexed_shape_matches k s e A hA ys,hi₀] + +lemma indexedBlockSample_measurable {I : Type} [Fintype I] (k : ℕ) + (A : I → I → Fin (k+1)) : Measurable (indexedBlockSample k A) := by + unfold indexedBlockSample + refine Measurable.tsum (fun xs => ?_) + exact (Finset.measurable_prod Finset.univ (fun i _ => + (Measure.measurable_coe (measurableSet_singleton (xs i))).comp + (indexedLeafProbability_measurable k))).mul_const _ + +lemma indexedBlockFocused_measurable {I : Type} [Fintype I] (k d : ℕ) + (A : I → I → Fin (k+1)) (i₀ : I) : Measurable (indexedBlockFocused k d A i₀) := by + unfold indexedBlockFocused + refine Measurable.tsum (fun xs => ?_) + exact ((Finset.measurable_prod Finset.univ (fun i _ => + (Measure.measurable_coe (measurableSet_singleton (xs i))).comp + (indexedLeafProbability_measurable k))).mul_const _).mul + (Measurable.tsum (fun l => ((Measure.measurable_coe (measurableSet_singleton l)).comp + (indexedLeafProbability_measurable k)).mul_const _)) + +lemma indexedBlockSample_eq_measure {I : Type} [Fintype I] (k : ℕ) + (A : I → I → Fin (k+1)) (b : IndexedCascadeBase k) : + indexedBlockSample k A b = (Measure.pi (fun _ : I => indexedLeafProbability k b)) + {xs | (fun i j => indexedCommonDepth k (xs i) (xs j)) = A} := by + rw [← lintegral_indicator_one ((Set.to_countable _).measurableSet),lintegral_countable'] + unfold indexedBlockSample + apply tsum_congr + intro xs + rw [Measure.pi_singleton] + simp only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] + split_ifs <;> simp + +lemma indexedBlockFocused_eq_measure {I : Type} [Fintype I] (k d : ℕ) + (A : I → I → Fin (k+1)) (i₀ : I) (b : IndexedCascadeBase k) : + indexedBlockFocused k d A i₀ b = + ((Measure.pi (fun _ : I => indexedLeafProbability k b)).prod (indexedLeafProbability k b)) + {p | (fun i j => indexedCommonDepth k (p.1 i) (p.1 j)) = A ∧ + d ≤ (indexedCommonDepth k (p.1 i₀) p.2).val} := by + rw [← lintegral_indicator_one ((Set.to_countable _).measurableSet),lintegral_countable', + ENNReal.tsum_prod'] + unfold indexedBlockFocused + apply tsum_congr + intro xs + rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro l + rw [← Set.singleton_prod_singleton,Measure.prod_prod,Measure.pi_singleton] + simp only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] + split_ifs <;> simp_all + +theorem indexedBlockFocused_integral {I : Type} [Fintype I] (k : ℕ) + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (d : ℕ) (hd : d ≤ k) (A : I → I → Fin (k+1)) (i₀ : I) : + (∫⁻ b, indexedBlockFocused k d A i₀ b ∂indexedCascadeBaseLaw k z) = + (∫⁻ b, indexedBlockSample k A b ∂indexedCascadeBaseLaw k z) * + ENNReal.ofReal (((∑ j, if d ≤ (A i₀ j).val then (1:ℝ) else 0) - + (if h : d = 0 then 0 else z ⟨d-1,by omega⟩)) / Fintype.card I) := by + by_cases hxs : ∃ xs : I → IndexedLeaf k, (fun i j => indexedCommonDepth k (xs i) (xs j)) = A + · obtain ⟨xs,hxs⟩ := hxs + obtain ⟨s,hs,e,he,hm⟩ := finite_leaf_tuple_pointed_shape k I xs i₀ + have hA (i j : I) : A i j = indexedCommonDepth k (cascadeShapeLeaves k s (e i)) + (cascadeShapeLeaves k s (e j)) := (congrFun (congrFun hxs i) j).symm.trans (hm i j) + simp_rw [indexedBlockFocused_shape k d s hs e A i₀ he hA, + indexedBlockSample_shape k s e A hA] + rw [indexedSampleFocused_integral k z hz hz0 hz1 d hd s hs, + indexedSampleShape_integral k z hz hz0 hz1 s hs, + focusedShapeNumerator_eq_count k z 0 d hd s hs] + have hc : Fintype.card I = cascadeVisitCount k s := + (Fintype.card_congr e).trans (cascadeShapeReplicas_card k s) + rw [hc] + congr 3 + unfold cascadeFocusCount + rw [← e.sum_comp] + apply congrArg (fun a : ℝ => a - (if h : d = 0 then 0 else z ⟨d-1,by omega⟩)) + apply Finset.sum_congr rfl + intro j hj + rw [hA,he] + · have ha (xs : I → IndexedLeaf k) : + ¬ (fun i j => indexedCommonDepth k (xs i) (xs j)) = A := fun h => hxs ⟨xs,h⟩ + simp [indexedBlockFocused,indexedBlockSample,ha] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/BoundaryEstimate.lean b/lean/OAI/Probability/Perceptron/Variational/BoundaryEstimate.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f60cfa28cb36b26671284dbb84a357f7a0c8d56 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/BoundaryEstimate.lean @@ -0,0 +1,166 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ConvexUniform +import OAI.Probability.Perceptron.Variational.GlobalContact +import OAI.Probability.Perceptron.Pressure.PatternFree + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma perturbationScale_tendsto_zero : + Tendsto (fun n : ℕ => perturbationScale (n+1)) atTop (𝓝 0) := by + unfold perturbationScale + convert (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1/16)).comp + (tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1)) using 1 + simp only [neg_div] + rfl + +lemma sourcePatternFree_uniform_upper {k : ℕ} (w : Fin (k+1)→ℝ) + (hw : ∀ i, 0 (hw i).le) hw1 q+ε := by + have hs := finiteSphericalFieldValue_compact_uniform w hw hw1 + (sourceStepFieldCap_compact k H) (fun h hh => ⟨hh.2,hh.1.1 0⟩) + rw [Metric.tendstoUniformlyOn_iff] at hs + have ht : Tendsto (fun n : ℕ => 8*perturbationScale (n+1)^2) atTop (𝓝 0) := by + simpa using perturbationScale_tendsto_zero.pow 2 |>.const_mul 8 + filter_upwards [hs (ε/2) (by positivity),ht.eventually (gt_mem_nhds (show (0:ℝ)<ε/2 by positivity))] + with n hn hn' f p d h hh u hu q hq hq1 + have hc := sourceExpectedPressure_perturbation_comparison n k f p d h hh.1.1 hh.2 + (stepCumulative w) (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) + (stepCumulative_lt_one w hw hw1) 0 (u := fun _ => 0) (v := u) + (fun j => ⟨le_rfl,by norm_num⟩) hu + change |sourceExpectedPressure n k f p d h (stepCumulative w) 0 u- + sourceExpectedPressure n k f p d h (stepCumulative w) 0 (fun _ => 0)|≤_ at hc + rw [sourceExpectedPressure_patternFree n k f p d w h hw hw1 hh.2 (hh.1.1 0)] at hc + obtain ⟨r,hr,hr1,hrmin,-⟩ := finiteSphericalFieldValue_pointwise_dual w h hw hw1 hh.2 (hh.1.1 0) + have hle := hrmin.2 (show finiteSphericalDualObjective w h (fun i => (hw i).le) hw1 q∈ + finiteSphericalDualValues w h (fun i => (hw i).le) hw1 from ⟨q,⟨hq,hq1⟩,rfl⟩) + have he := hn h hh + rw [Real.dist_eq,hrmin.csInf_eq] at he + have hab := (abs_le.mp hc).2 + have hae := (abs_lt.mp he).1 + linarith + +lemma sourcePressure_uniform_upper {k : ℕ} (w : Fin (k+1)→ℝ) + (hw : ∀ i, 0 (hw i).le) hw1 q+ε+(t:ℝ)*‖f‖ := by + filter_upwards [sourcePatternFree_uniform_upper w hw hw1 H hε] with n hn + intro f p d h hh u hu q hq hq1 t + have hc := sourceExpectedPressure_density_comparison n k f p d h (stepCumulative w) u + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) + (stepCumulative_lt_one w hw hw1) 0 t + rw [NNReal.coe_zero,sub_zero,abs_of_nonneg t.coe_nonneg] at hc + linarith [(abs_le.mp hc).2,hn f p d h hh u hu q hq hq1] + +lemma sourceContactObjective_zero_lower {k : ℕ} (w : Fin (k+1)→ℝ) + (hw : ∀ i, 0 (hw i).le) hw1 δ a := by + filter_upwards [sourcePatternFree_uniform_upper w hw hw1 H hε] with n hn + intro P f p d q hq hq1 δ α a ha ht + have he := hn f p d a.2.1 ha.2.1 a.2.2 + (fun j => ⟨by linarith [ha.2.2.1 j],ha.2.2.2 j⟩) q hq hq1 + have hpen : 0≤quadraticBoxPenalty (sourcePenaltyWeight (n+1)) a.2.2 := by + unfold quadraticBoxPenalty sourcePenaltyWeight + positivity + have hsum : (∑ i, w i*(q i:ℝ)*a.2.1 i)=(∑ i, w i*a.2.1 i*(q i:ℝ)) := by + apply Finset.sum_congr rfl + intros + ring + unfold sourceStepContactObjective sourceJointPressure + rw [ht,NNReal.coe_zero,zero_mul,add_zero,hsum] + unfold finiteSphericalDualObjective at he + linarith + +lemma sourceNegativeContact_positive_density {k : ℕ} (w : Fin (k+1)→ℝ) + (hw : ∀ i, 0 (hw i).le) hw1 δ a < -ε → 0 (hw i).le) hw1)).toReal- + (entropy (weightedStepTrial w r (fun i => (hw i).le) hw1)).toReal+ + (a.1:ℝ)*(controlValue P f (weightedStepTrial w q (fun i => (hw i).le) hw1)+δ-‖f‖)-ε ≤ + sourceStepContactObjective n k P f p d w q (fun i => (hw i).le) hw1 δ a := by + filter_upwards [sourcePressure_uniform_upper w hw hw1 H hε] with n hn + intro P f p d q r hr hr1 δ α a ha + have he := hn f p d a.2.1 ha.2.1 a.2.2 + (fun j => ⟨by linarith [ha.2.2.1 j],ha.2.2.2 j⟩) r hr hr1 a.1 + have hpen : 0≤quadraticBoxPenalty (sourcePenaltyWeight (n+1)) a.2.2 := by + unfold quadraticBoxPenalty sourcePenaltyWeight + positivity + have hsum : (∑ i, w i*((r i:ℝ)-(q i:ℝ))*a.2.1 i)= + (∑ i, w i*a.2.1 i*(r i:ℝ))-(∑ i, w i*(q i:ℝ)*a.2.1 i) := by + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intros + ring + unfold sourceStepContactObjective sourceJointPressure + unfold finiteSphericalDualObjective at he + rw [hsum] + linarith + +lemma sourceNegativeContact_field_interior {k : ℕ} (w : Fin (k+1)→ℝ) + (hw : ∀ i, 0 (hw i).le) hw1)).toReal+ + 2*(α:ℝ)*‖f‖ ≤ η*w (Fin.last k)*H) {ε : ℝ} (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, ∀ (p d : Fin (n+1)→ℕ) (δ : ℝ), 0≤δ → + ∀ a : SourceContactParameter n k, a∈sourceContactCompactDomain n k α H → + sourceStepContactObjective n k P f p d w q (fun i => (hw i).le) hw1 δ a < -ε → + a.2.1 (Fin.last k) (hw i).le) hw1)).toReal≥0 := ENNReal.toReal_nonneg + have hv := neg_norm_le_controlValue P f (weightedStepTrial w q (fun i => (hw i).le) hw1) + have ht : -2*(α:ℝ)*‖f‖ ≤ + (a.1:ℝ)*(controlValue P f (weightedStepTrial w q (fun i => (hw i).le) hw1)+δ-‖f‖) := by + have hm := mul_le_mul_of_nonneg_left (show -2*‖f‖ ≤ + controlValue P f (weightedStepTrial w q (fun i => (hw i).le) hw1)+δ-‖f‖ by linarith) a.1.coe_nonneg + have ha' : (a.1:ℝ)≤(α:ℝ) := ha.1.2 + nlinarith [mul_le_mul_of_nonneg_right ha' (norm_nonneg f)] + have hsum : η*w (Fin.last k)*a.2.1 (Fin.last k) ≤ + ∑ i, w i*((r i:ℝ)-(q i:ℝ))*a.2.1 i := by + apply le_trans _ (Finset.single_le_sum (fun i (_ : i∈Finset.univ) => + mul_nonneg (mul_nonneg (hw i).le (by linarith [hqr i])) (ha.2.1.1.1 i)) (Finset.mem_univ (Fin.last k))) + nlinarith [mul_le_mul_of_nonneg_left (hqr (Fin.last k)) + (mul_nonneg (hw (Fin.last k)).le (ha.2.1.1.1 (Fin.last k)))] + by_contra hnot + have hEq : a.2.1 (Fin.last k)=H := le_antisymm (ha.2.1.1.2 (Fin.last k)) (le_of_not_gt hnot) + rw [hEq] at hsum + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/BoundedC1.lean b/lean/OAI/Probability/Perceptron/Variational/BoundedC1.lean new file mode 100644 index 0000000000000000000000000000000000000000..fe36abe08e95424210c2123fc26641c9a42e6c7f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/BoundedC1.lean @@ -0,0 +1,433 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.PoissonWeightedTotal +import OAI.Probability.Perceptron.Variational.BcfEvalRingHom + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff + +def BoundedC1 (f : ℝ→ᵇ ℝ) : Prop := ∃ f' : ℝ→ᵇ ℝ, ∀ x, HasDerivAt (f:ℝ→ℝ) (f' x) x + +lemma BoundedC1.zero : BoundedC1 (0 : ℝ→ᵇ ℝ) := ⟨0,fun x => hasDerivAt_const x 0⟩ + +lemma BoundedC1.add {f h : ℝ→ᵇ ℝ} (hf : BoundedC1 f) (hh : BoundedC1 h) : + BoundedC1 (f+h) := by + obtain ⟨f',hf'⟩ := hf + obtain ⟨h',hh'⟩ := hh + exact ⟨f'+h',fun x => (hf' x).add (hh' x)⟩ + +lemma BoundedC1.smul {f : ℝ→ᵇ ℝ} (hf : BoundedC1 f) (a : ℝ) : + BoundedC1 (a • f) := by + obtain ⟨f',hf'⟩ := hf + exact ⟨a • f',fun x => (hf' x).const_mul a⟩ + +lemma BoundedC1.heatTilt {f h : ℝ→ᵇ ℝ} (hf : BoundedC1 f) (hh : BoundedC1 h) + (s d : ℝ≥0) : BoundedC1 (heatTiltCLM s d f h) := by + obtain ⟨f',hf'⟩ := hf + obtain ⟨h',hh'⟩ := hh + exact ⟨_,fun x => heatTiltBCF_hasDerivAt s d f f' h h' hf' hh' x⟩ + +lemma heatGenerator_boundedC1 (g : Jet3) (d : ℝ≥0) : BoundedC1 (heatGenerator d g) := + ⟨_,heatGenerator_hasDerivAt g d⟩ + +structure HeatIntervalParam where + duration : ℝ → ℝ + rate : ℝ + coefficient : ℝ≥0 + +def parametricHeatJet (g : Jet3) : List HeatIntervalParam → ℝ → Jet3 + | [], _ => g + | p::ps, t => (parametricHeatJet g ps t).heatLog (p.duration t).toNNReal p.coefficient + +def parametricHeatVelocity (g : Jet3) : List HeatIntervalParam → ℝ → (ℝ→ᵇ ℝ) + | [], _ => 0 + | p::ps, t => p.rate • heatGenerator p.coefficient (parametricHeatJet g (p::ps) t) + + heatTiltCLM (p.duration t).toNNReal p.coefficient (parametricHeatJet g ps t).f + (parametricHeatVelocity g ps t) + +lemma parametricHeatVelocity_boundedC1 (g : Jet3) (ps : List HeatIntervalParam) (t : ℝ) : + BoundedC1 (parametricHeatVelocity g ps t) := by + induction ps with + | nil => exact BoundedC1.zero + | cons p ps ih => + exact ((heatGenerator_boundedC1 _ _).smul p.rate).add + (BoundedC1.heatTilt ⟨_,(parametricHeatJet g ps t).has1⟩ ih _ _) + +lemma parametricHeatJet_hasDerivAt (g : Jet3) (ps : List HeatIntervalParam) (θ : ℝ) + (hp : ∀ p ∈ ps, HasDerivAt p.duration p.rate θ ∧ 0 < p.duration θ) : + HasDerivAt (fun t => (parametricHeatJet g ps t).f) (parametricHeatVelocity g ps θ) θ := by + induction ps with + | nil => exact hasDerivAt_const θ g.f + | cons p ps ih => + have hhead := hp p (List.mem_cons_self ..) + have htail := ih (fun q hq => hp q (List.mem_cons_of_mem _ hq)) + obtain ⟨h',hh'⟩ := parametricHeatVelocity_boundedC1 g ps θ + have he := heatLogBCF_moving_hasDerivAt (parametricHeatJet g ps θ) p.coefficient + p.duration (fun t => (parametricHeatJet g ps t).f) θ p.rate + (parametricHeatVelocity g ps θ) h' hhead.1 hhead.2 htail rfl hh' + simpa only [parametricHeatJet,parametricHeatVelocity,Jet3.heatLog_f] using he + +lemma heatLog_boundary_hasDerivAt (g : Jet3) (s r : ℝ) (hs : 0 < s) (hr : 0 < r) + (d e : ℝ≥0) : + HasDerivAt (fun t => heatLogBCF (s+t).toNNReal d + (heatLogBCF (r-t).toNNReal e g.f)) + ((((d:ℝ)-(e:ℝ))/2) • heatTiltCLM s.toNNReal d (g.heatLog r.toNNReal e).f + ((g.heatLog r.toNNReal e).d1^2)) 0 := by + let u := g.heatLog r.toNNReal e + have hsub : HasDerivAt (fun t : ℝ => r-t) (-1 : ℝ) 0 := by + convert! (hasDerivAt_const 0 r).sub (hasDerivAt_id 0) using 1; norm_num + have hadd : HasDerivAt (fun t : ℝ => s+t) (1 : ℝ) 0 := by + convert! (hasDerivAt_const 0 s).add (hasDerivAt_id 0) using 1; norm_num + have ht : HasDerivAt (fun t => heatLogBCF t.toNNReal e g.f) (heatGenerator e u) (r-0) := by + simpa only [sub_zero] using heatLogBCF_time_hasDerivAt g e r hr + have hG : HasDerivAt (fun t => heatLogBCF (r-t).toNNReal e g.f) + ((-1 : ℝ) • heatGenerator e u) 0 := ht.scomp 0 hsub + obtain ⟨h',hh'⟩ := (heatGenerator_boundedC1 u e).smul (-1) + have he := heatLogBCF_moving_hasDerivAt u d (fun t => s+t) + (fun t => heatLogBCF (r-t).toNNReal e g.f) 0 1 + ((-1:ℝ) • heatGenerator e u) h' + hadd + (by simpa only [add_zero] using hs) hG + (by simp only [sub_zero,u,Jet3.heatLog_f]) hh' + apply he.congr_deriv + simp only [add_zero,one_smul,map_smul] + rw [← heatTilt_heatGenerator u s.toNNReal d] + have hg : heatGenerator d u-heatGenerator e u = (((d:ℝ)-(e:ℝ))/2) • (u.d1^2) := by + ext x + simp only [heatGenerator,BoundedContinuousFunction.coe_sub,BoundedContinuousFunction.coe_smul, + BoundedContinuousFunction.coe_add,BoundedContinuousFunction.coe_pow,Pi.sub_apply, + Pi.add_apply,Pi.pow_apply,smul_eq_mul] + ring + have hh := congrArg (heatTiltCLM s.toNNReal d u.f) hg + rw [map_sub,map_smul] at hh + convert hh using 1; module + +lemma weighted_list_tail_nonneg (xs : List (ℝ×ℝ)) + (hc : xs.Pairwise (fun u v => u.2 ≤ v.2)) + (hc0 : ∀ u ∈ xs, 0 ≤ u.2) + (ht : ∀ ys : List (ℝ×ℝ), ys.IsSuffix xs → 0 ≤ (ys.map Prod.fst).sum) : + 0 ≤ (xs.map (fun u => u.1*u.2)).sum := by + suffices ∀ (b : ℝ), (∀ u ∈ xs, b ≤ u.2) → + b*(xs.map Prod.fst).sum ≤ (xs.map (fun u => u.1*u.2)).sum by + simpa only [zero_mul] using this 0 hc0 + intro b hb + induction xs generalizing b with + | nil => simp + | cons u xs ih => + obtain ⟨hum,hrest⟩ := List.pairwise_cons.mp hc + have htail : ∀ ys : List (ℝ×ℝ), ys.IsSuffix xs → 0 ≤ (ys.map Prod.fst).sum := by + intro ys hys + exact ht ys (hys.trans (List.suffix_cons u xs)) + have hi := ih hrest (fun v hv => hc0 v (List.mem_cons_of_mem _ hv)) htail u.2 hum + have hx := ht (u::xs) (by simp) + have hu := hb u (List.mem_cons_self ..) + simp only [List.map_cons,List.sum_cons] at hx ⊢ + nlinarith [mul_nonneg (sub_nonneg.mpr hu) hx] + +def heatBoundaryTerms (g : Jet3) (θ : ℝ) : List HeatIntervalParam → ℝ → List (ℝ×(ℝ→ᵇ ℝ)) + | [], _ => [] + | [_], _ => [] + | p::q::ps, a => + let u := parametricHeatJet g (q::ps) θ + let T := heatTiltCLM (p.duration θ).toNNReal p.coefficient u.f + (((q.coefficient:ℝ)-(p.coefficient:ℝ))*(a+p.rate),T (u.d1^2)) :: + (heatBoundaryTerms g θ (q::ps) (a+p.rate)).map (fun z => (z.1,T z.2)) + +def heatBoundarySum (g : Jet3) (θ : ℝ) (ps : List HeatIntervalParam) (a : ℝ) : ℝ→ᵇ ℝ := + ((heatBoundaryTerms g θ ps a).map (fun z => z.1 • z.2)).sum + +lemma heatBoundarySum_cons (g : Jet3) (θ : ℝ) (p q : HeatIntervalParam) + (ps : List HeatIntervalParam) (a : ℝ) : + heatBoundarySum g θ (p::q::ps) a = + (((q.coefficient:ℝ)-(p.coefficient:ℝ))*(a+p.rate)) • + heatTiltCLM (p.duration θ).toNNReal p.coefficient (parametricHeatJet g (q::ps) θ).f + ((parametricHeatJet g (q::ps) θ).d1^2) + + heatTiltCLM (p.duration θ).toNNReal p.coefficient (parametricHeatJet g (q::ps) θ).f + (heatBoundarySum g θ (q::ps) (a+p.rate)) := by + simp only [heatBoundarySum,heatBoundaryTerms,List.map_cons,List.sum_cons,List.map_map] + congr 1 + rw [map_list_sum,List.map_map] + congr 1 + apply List.map_congr_left + intro z _ + exact (map_smul _ _ _).symm + +lemma heatGenerator_sub (g : Jet3) (d e : ℝ≥0) : + heatGenerator d g-heatGenerator e g = (((d:ℝ)-(e:ℝ))/2) • (g.d1^2) := by + ext x + simp only [heatGenerator,BoundedContinuousFunction.coe_sub,BoundedContinuousFunction.coe_smul, + BoundedContinuousFunction.coe_add,BoundedContinuousFunction.coe_pow,Pi.sub_apply, + Pi.add_apply,Pi.pow_apply,smul_eq_mul] + ring + +def firstHeatGenerator (g : Jet3) (ps : List HeatIntervalParam) (θ : ℝ) : ℝ→ᵇ ℝ := + match ps with + | [] => 0 + | p::_ => heatGenerator p.coefficient (parametricHeatJet g ps θ) + +lemma parametricHeatVelocity_boundary (g : Jet3) (θ : ℝ) (ps : List HeatIntervalParam) + (a : ℝ) (hend : a+(ps.map HeatIntervalParam.rate).sum = 0) : + parametricHeatVelocity g ps θ+a • firstHeatGenerator g ps θ = + (-1/2 : ℝ) • heatBoundarySum g θ ps a := by + induction ps generalizing a with + | nil => simp [parametricHeatVelocity,firstHeatGenerator,heatBoundarySum,heatBoundaryTerms] + | cons p ps ih => + cases ps with + | nil => + simp only [List.map_cons,List.sum_cons,List.map_nil,List.sum_nil,add_zero] at hend + simp only [parametricHeatVelocity,firstHeatGenerator,heatBoundarySum,heatBoundaryTerms, + List.map_nil,List.sum_nil,map_zero,add_zero,smul_zero] + rw [← add_smul,add_comm p.rate a,hend,zero_smul] + | cons q ps => + have hend' : (a+p.rate)+((q::ps).map HeatIntervalParam.rate).sum = 0 := by + simpa only [List.map_cons,List.sum_cons,add_assoc] using hend + have hi := ih (a+p.rate) hend' + let u := parametricHeatJet g (q::ps) θ + let T := heatTiltCLM (p.duration θ).toNNReal p.coefficient u.f + have hh := congrArg T hi + simp only [map_add,map_smul] at hh + change T (parametricHeatVelocity g (q::ps) θ)+(a+p.rate) • T (heatGenerator q.coefficient u) = + (-1/2:ℝ) • T (heatBoundarySum g θ (q::ps) (a+p.rate)) at hh + have hg := congrArg T (heatGenerator_sub u p.coefficient q.coefficient) + simp only [map_sub,map_smul] at hg + rw [heatBoundarySum_cons] + change p.rate • heatGenerator p.coefficient (u.heatLog (p.duration θ).toNNReal p.coefficient)+ + T (parametricHeatVelocity g (q::ps) θ)+ + a • heatGenerator p.coefficient (u.heatLog (p.duration θ).toNNReal p.coefficient) = _ + rw [← heatTilt_heatGenerator u (p.duration θ).toNNReal p.coefficient] + change p.rate • T (heatGenerator p.coefficient u)+T (parametricHeatVelocity g (q::ps) θ)+ + a • T (heatGenerator p.coefficient u) = (-1/2:ℝ) • + ((((q.coefficient:ℝ)-(p.coefficient:ℝ))*(a+p.rate)) • T (u.d1^2)+ + T (heatBoundarySum g θ (q::ps) (a+p.rate))) + linear_combination (norm := module) hh+(a+p.rate) • hg + +lemma heatBoundaryTerms_lower (g : Jet3) (θ : ℝ) (ps : List HeatIntervalParam) (a : ℝ) : + ∀ z ∈ heatBoundaryTerms g θ ps a, ∀ x, + ((parametricHeatJet g ps θ).d1 x)^2 ≤ z.2 x := by + induction ps generalizing a with + | nil => simp [heatBoundaryTerms] + | cons p ps ih => + cases ps with + | nil => simp [heatBoundaryTerms] + | cons q ps => + intro z hz x + let u := parametricHeatJet g (q::ps) θ + let T := heatTiltCLM (p.duration θ).toNNReal p.coefficient u.f + have hfirst := u.heatLog_d1_sq_le (p.duration θ).toNNReal p.coefficient x + change ((parametricHeatJet g (p::q::ps) θ).d1 x)^2 ≤ (T (u.d1^2)) x at hfirst + simp only [heatBoundaryTerms,List.mem_cons] at hz + rcases hz with rfl | hz + · exact hfirst + · obtain ⟨w,hw,rfl⟩ := List.mem_map.mp hz + exact hfirst.trans (heatTilt_mono (p.duration θ).toNNReal p.coefficient u.f + (u.d1^2) w.2 (fun y => ih (a+p.rate) w hw y) x) + +lemma heatBoundaryTerms_ordered (g : Jet3) (θ : ℝ) (ps : List HeatIntervalParam) (a : ℝ) : + (heatBoundaryTerms g θ ps a).Pairwise (fun z w => ∀ x, z.2 x ≤ w.2 x) := by + induction ps generalizing a with + | nil => simp [heatBoundaryTerms] + | cons p ps ih => + cases ps with + | nil => simp [heatBoundaryTerms] + | cons q ps => + simp only [heatBoundaryTerms,List.pairwise_cons] + constructor + · intro z hz x + obtain ⟨w,hw,rfl⟩ := List.mem_map.mp hz + exact heatTilt_mono (p.duration θ).toNNReal p.coefficient (parametricHeatJet g (q::ps) θ).f + ((parametricHeatJet g (q::ps) θ).d1^2) w.2 + (fun y => heatBoundaryTerms_lower g θ (q::ps) (a+p.rate) w hw y) x + · rw [List.pairwise_map] + exact (ih (a+p.rate)).imp (fun hz x => heatTilt_mono (p.duration θ).toNNReal p.coefficient + (parametricHeatJet g (q::ps) θ).f _ _ hz x) + +lemma heatBoundarySum_nonneg (g : Jet3) (θ : ℝ) (ps : List HeatIntervalParam) (a : ℝ) + (ht : ∀ zs : List (ℝ×(ℝ→ᵇ ℝ)), zs.IsSuffix (heatBoundaryTerms g θ ps a) → 0 ≤ (zs.map Prod.fst).sum) + (x : ℝ) : 0 ≤ heatBoundarySum g θ ps a x := by + let zs := heatBoundaryTerms g θ ps a + let val (z : ℝ×(ℝ→ᵇ ℝ)) : ℝ×ℝ := (z.1,z.2 x) + have hc : (zs.map val).Pairwise (fun u v => u.2 ≤ v.2) := by + rw [List.pairwise_map] + exact (heatBoundaryTerms_ordered g θ ps a).imp (fun h => h x) + have hc0 : ∀ u ∈ zs.map val, 0 ≤ u.2 := by + intro u hu + obtain ⟨z,hz,rfl⟩ := List.mem_map.mp hu + exact (sq_nonneg _).trans (heatBoundaryTerms_lower g θ ps a z hz x) + have htail : ∀ ys : List (ℝ×ℝ), ys.IsSuffix (zs.map val) → 0 ≤ (ys.map Prod.fst).sum := by + intro ys hys + obtain ⟨ws,hws,rfl⟩ := List.suffix_map_iff.mp hys + simpa only [List.map_map,Function.comp_def,val] using ht ws hws + have he := weighted_list_tail_nonneg (zs.map val) hc hc0 htail + change 0 ≤ (BoundedContinuousFunction.evalCLM ℝ x) ((zs.map (fun z => z.1 • z.2)).sum) + rw [map_list_sum,List.map_map] + change 0 ≤ (zs.map (fun z => z.1*z.2 x)).sum + simpa only [List.map_map,Function.comp_def,val] using he + +lemma parametricHeatJet_deriv_nonpos (g : Jet3) (θ : ℝ) (ps : List HeatIntervalParam) + (hp : ∀ p ∈ ps, HasDerivAt p.duration p.rate θ ∧ 0 < p.duration θ) + (hend : (ps.map HeatIntervalParam.rate).sum = 0) + (ht : ∀ zs : List (ℝ×(ℝ→ᵇ ℝ)), zs.IsSuffix (heatBoundaryTerms g θ ps 0) → 0 ≤ (zs.map Prod.fst).sum) + (x : ℝ) : deriv (fun t => (parametricHeatJet g ps t).f x) θ ≤ 0 := by + have hd := (BoundedContinuousFunction.evalCLM ℝ x).hasFDerivAt.comp_hasDerivAt θ + (parametricHeatJet_hasDerivAt g ps θ hp) + change HasDerivAt (fun t => (parametricHeatJet g ps t).f x) ((parametricHeatVelocity g ps θ) x) θ at hd + rw [hd.deriv] + have he := parametricHeatVelocity_boundary g θ ps 0 (by simpa only [zero_add] using hend) + simp only [zero_smul,add_zero] at he + rw [he] + change (-1/2:ℝ)*heatBoundarySum g θ ps 0 x ≤ 0 + exact mul_nonpos_of_nonpos_of_nonneg (by norm_num) (heatBoundarySum_nonneg g θ ps 0 ht x) + +lemma heatLogBCF_time_continuousAt_all (g : Jet3) (d : ℝ≥0) (s : ℝ) : + ContinuousAt (fun t : ℝ => heatLogBCF t.toNNReal d g.f) s := by + by_cases hd : d = 0 + · subst d + have he : (fun t : ℝ => heatLogBCF t.toNNReal 0 g.f) = + (fun t => gaussianAverageBCF t.toNNReal g.f) := by ext t x; simp [heatLog] + rw [he] + exact (gaussianAverageBCF_time_continuous_of_deriv g.f g.d1 g.has1).continuousAt + let A : ℝ → (ℝ →ᵇ ℝ) := fun t => gaussianAverageBCF t.toNNReal (expBCF d g.f) + let c : ℝ := Real.exp (-(d : ℝ)*‖g.f‖) + have hc : 0 < c := Real.exp_pos _ + have hb t : ∀ x, c ≤ A t x := fun x => (gaussianAverage_exp_bounds t.toNNReal d d.coe_nonneg g.f x).1 + have ha : ContinuousAt A s := (gaussianAverageBCF_time_continuous_of_deriv (g.exp d).f (g.exp d).d1 (g.exp d).has1).continuousAt + have hbd t : ‖heatLogBCF t.toNNReal d g.f - heatLogBCF s.toNNReal d g.f‖ ≤ + (d : ℝ)⁻¹*c⁻¹*‖A t-A s‖ := by + apply (BoundedContinuousFunction.norm_le (by positivity)).mpr + intro x + change |heatLog t.toNNReal d g.f x-heatLog s.toNNReal d g.f x| ≤ _ + simp only [heatLog,hd,↓reduceIte,← mul_sub,abs_mul,abs_inv,abs_of_nonneg d.coe_nonneg] + calc + _ ≤ (d : ℝ)⁻¹*(c⁻¹*|A t x-A s x|) := + mul_le_mul_of_nonneg_left (log_lipschitz_above hc (hb s x) (hb t x)) (by positivity) + _ ≤ (d : ℝ)⁻¹*c⁻¹*‖A t-A s‖ := by + rw [← mul_assoc] + exact mul_le_mul_of_nonneg_left ((A t-A s).norm_coe_le_norm x) (by positivity) + have ht : Tendsto (fun t => (d : ℝ)⁻¹*c⁻¹*‖A t-A s‖) (𝓝 s) (𝓝 0) := by + simpa only [Pi.sub_apply,sub_self,norm_zero,mul_zero] using + (ha.sub (continuousAt_const (y := A s))).norm.const_mul ((d : ℝ)⁻¹*c⁻¹) |>.tendsto + exact tendsto_sub_nhds_zero_iff.mp (squeeze_zero_norm hbd ht) + +lemma heatLogBCF_terminal_norm_le (s d : ℝ≥0) (f h : ℝ→ᵇ ℝ) : + ‖heatLogBCF s d f-heatLogBCF s d h‖ ≤ ‖f-h‖ := by + have hb (u : ℝ→ᵇ ℝ) : ‖heatTiltCLM s d u‖ ≤ 1 := by + apply (heatTiltCLM s d u).opNorm_le_bound (by norm_num) + intro v + change ‖heatTiltBCF s d u v‖ ≤ 1*‖v‖ + simpa only [one_mul] using heatTiltBCF_norm_le s d u v + simpa only [one_mul] using (convex_univ : Convex ℝ (Set.univ : Set (ℝ→ᵇ ℝ))).norm_image_sub_le_of_norm_hasFDerivWithin_le + (fun u _ => (heatLogBCF_hasFDerivAt s d u).hasFDerivWithinAt) + (fun u _ => hb u) (mem_univ h) (mem_univ f) + +lemma heatLogBCF_moving_continuousAt (g : Jet3) (d : ℝ≥0) + (s : ℝ→ℝ) (F : ℝ→(ℝ→ᵇ ℝ)) (t : ℝ) + (hs : ContinuousAt s t) (hF : ContinuousAt F t) (he : F t = g.f) : + ContinuousAt (fun r => heatLogBCF (s r).toNNReal d (F r)) t := by + have hc := (heatLogBCF_time_continuousAt_all g d (s t)).comp hs + have hb r : ‖heatLogBCF (s r).toNNReal d (F r)-heatLogBCF (s t).toNNReal d (F t)‖ ≤ + ‖F r-F t‖+‖heatLogBCF (s r).toNNReal d g.f-heatLogBCF (s t).toNNReal d g.f‖ := by + calc + _ ≤ ‖heatLogBCF (s r).toNNReal d (F r)-heatLogBCF (s r).toNNReal d (F t)‖+ + ‖heatLogBCF (s r).toNNReal d (F t)-heatLogBCF (s t).toNNReal d (F t)‖ := norm_sub_le_norm_sub_add_norm_sub _ _ _ + _ ≤ _ := by + have H := add_le_add_right (heatLogBCF_terminal_norm_le (s r).toNNReal d (F r) (F t)) + ‖heatLogBCF (s r).toNNReal d (F t)-heatLogBCF (s t).toNNReal d (F t)‖ + simpa only [he,add_comm] using H + have hz : Tendsto (fun r => ‖F r-F t‖+‖heatLogBCF (s r).toNNReal d g.f-heatLogBCF (s t).toNNReal d g.f‖) (𝓝 t) (𝓝 0) := by + have H := ((hF.sub (continuousAt_const (y := F t))).norm.add + (hc.sub (continuousAt_const (y := heatLogBCF (s t).toNNReal d g.f))).norm).tendsto + change Tendsto (fun r => ‖F r-F t‖+‖heatLogBCF (s r).toNNReal d g.f-heatLogBCF (s t).toNNReal d g.f‖) (𝓝 t) + (𝓝 (‖F t-F t‖+‖heatLogBCF (s t).toNNReal d g.f-heatLogBCF (s t).toNNReal d g.f‖)) at H + simpa only [sub_self,norm_zero,zero_add] using H + exact tendsto_sub_nhds_zero_iff.mp (squeeze_zero_norm hb hz) + +lemma parametricHeatJet_continuousAt (g : Jet3) (ps : List HeatIntervalParam) (t : ℝ) + (hp : ∀ p ∈ ps, ContinuousAt p.duration t) : + ContinuousAt (fun r => (parametricHeatJet g ps r).f) t := by + induction ps with + | nil => exact continuousAt_const + | cons p ps ih => + simp only [parametricHeatJet,Jet3.heatLog_f] + exact heatLogBCF_moving_continuousAt (parametricHeatJet g ps t) p.coefficient p.duration + (fun r => (parametricHeatJet g ps r).f) t (hp p (List.mem_cons_self)) + (ih fun q hq => hp q (List.mem_cons_of_mem p hq)) rfl + +lemma parametricHeatJet_tail_order (g : Jet3) (ps : List HeatIntervalParam) + (hc : ∀ p ∈ ps, Continuous p.duration) + (hp : ∀ t ∈ Ioo (0:ℝ) 1, ∀ p ∈ ps, HasDerivAt p.duration p.rate t ∧ 0 < p.duration t) + (hend : (ps.map HeatIntervalParam.rate).sum = 0) + (ht : ∀ t ∈ Ioo (0:ℝ) 1, ∀ zs : List (ℝ×(ℝ→ᵇ ℝ)), + zs.IsSuffix (heatBoundaryTerms g t ps 0) → 0 ≤ (zs.map Prod.fst).sum) + (x : ℝ) : (parametricHeatJet g ps 1).f x ≤ (parametricHeatJet g ps 0).f x := by + have hcont : Continuous (fun t => (parametricHeatJet g ps t).f x) := by + rw [continuous_iff_continuousAt] + intro t + exact (BoundedContinuousFunction.evalCLM ℝ x).continuous.continuousAt.comp + (parametricHeatJet_continuousAt g ps t (fun p h => (hc p h).continuousAt)) + have hdiff : DifferentiableOn ℝ (fun t => (parametricHeatJet g ps t).f x) (interior (Icc (0:ℝ) 1)) := by + rw [interior_Icc] + intro t ht + exact ((BoundedContinuousFunction.evalCLM ℝ x).hasFDerivAt.comp_hasDerivAt t + (parametricHeatJet_hasDerivAt g ps t (hp t ht))).differentiableAt.differentiableWithinAt + have hn := antitoneOn_of_deriv_nonpos (convex_Icc (0:ℝ) 1) hcont.continuousOn hdiff + (fun t h => parametricHeatJet_deriv_nonpos g t ps (hp t (by simpa only [interior_Icc] using h)) + hend (ht t (by simpa only [interior_Icc] using h)) x) + exact hn ⟨le_rfl,zero_le_one⟩ ⟨zero_le_one,le_rfl⟩ zero_le_one + +lemma poissonWeightedTotal_law {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb : 0 < b) + {X : S → ℝ} (hX : Measurable X) + (hI : Integrable (fun x => Real.exp (b*X x)) ν) : + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).map (poissonWeightedTotal X) = + (poissonRandomMeasureLaw (stableLogIntensity b)).map + (fun η => Real.exp (Real.log (∫ x, Real.exp (b*X x) ∂ν)/b)*stablePoissonTotal η) := by + let c := Real.log (∫ x, Real.exp (b*X x) ∂ν)/b + let F := fun x => X x-c + have hF : Measurable F := hX.sub_const c + have hMpos := integral_exp_pos hI + have hfac (x : S) : Real.exp (b*F x) = Real.exp (-b*c)*Real.exp (b*X x) := by + dsimp [F] + rw [← Real.exp_add] + congr 1 + ring + have hFI : Integrable (fun x => Real.exp (b*F x)) ν := by + simp_rw [hfac] + exact hI.const_mul _ + have hFM : (∫ x, Real.exp (b*F x) ∂ν) = 1 := by + simp_rw [hfac] + rw [integral_const_mul,show -b*c = -Real.log (∫ x, Real.exp (b*X x) ∂ν) by dsimp [c]; field_simp, + Real.exp_neg,Real.exp_log hMpos,inv_mul_cancel₀ hMpos.ne'] + have he := stablePoisson_normalized_mark_projection ν hb.le hF hFI hFM + have hm : Measurable (fun p : ℝ×S => p.1+F p.2) := measurable_fst.add (hF.comp measurable_snd) + have hT : poissonWeightedTotal X = fun η => Real.exp c*stablePoissonTotal + (η.map (fun p : ℝ×S => p.1+F p.2)) := by + funext η + rw [← poissonWeightedTotal_eq hF] + convert poissonWeightedTotal_add_const hF c η using 1 + congr 1 + funext x + dsimp [F] + ring + rw [hT,show (fun η : Measure (ℝ×S) => Real.exp c*stablePoissonTotal + (η.map (fun p => p.1+F p.2))) = + (fun η : Measure ℝ => Real.exp c*stablePoissonTotal η) ∘ Measure.map (fun p : ℝ×S => p.1+F p.2) from rfl, + ← Measure.map_map ((stablePoissonTotal_measurable.const_mul _)) + (Measure.measurable_map _ hm),he] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/BoundedGibbsDerivative.lean b/lean/OAI/Probability/Perceptron/Variational/BoundedGibbsDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..c7d7cc4a37e6d6bb7ade1271a96bcfa5366a0d56 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/BoundedGibbsDerivative.lean @@ -0,0 +1,193 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.HeatLogBCF +import OAI.Probability.Perceptron.Variational.VarianceProdMemLp + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma bounded_gibbs_integral_deriv + {H H' F F' : ℝ → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hH' : Measurable (Function.uncurry H')) + (hF : Measurable (Function.uncurry F)) (hF' : Measurable (Function.uncurry F')) + {A B C D : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hHA : ∀ t x, |H t x| ≤ A) (hHB : ∀ t x, |H' t x| ≤ B) + (hFC : ∀ t x, |F t x| ≤ C) (hFD : ∀ t x, |F' t x| ≤ D) + (hdH : ∀ t x, HasDerivAt (fun u => H u x) (H' t x) t) + (hdF : ∀ t x, HasDerivAt (fun u => F u x) (F' t x) t) (t : ℝ) : + HasDerivAt (fun u => tiltIntegral μ (H u) (F u) 1) + (∫ x, Real.exp (H t x) * (H' t x * F t x + F' t x) ∂μ) t := by + simp only [tiltIntegral, one_mul] + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (F := fun u x => Real.exp (H u x)*F u x) + (s := univ) (bound := fun _ => Real.exp A * (B*C+D)) + (F' := fun u x => Real.exp (H u x) * (H' u x * F u x+F' u x)) + (Filter.univ_mem) (Eventually.of_forall fun u => + ((hH.comp (measurable_const.prodMk measurable_id)).exp.mul + (hF.comp (measurable_const.prodMk measurable_id))).aestronglyMeasurable) + (by + simpa only [one_mul, Function.comp_def, Function.uncurry_def, id_eq, Pi.mul_apply] using tilt_integrable μ + (hH.comp (measurable_const.prodMk measurable_id)) + (hF.comp (measurable_const.prodMk measurable_id)) hA hC (hHA t) (hFC t) 1) + (by fun_prop) (ae_of_all _ fun x u _ => ?_) (integrable_const _) + (ae_of_all _ fun x u _ => ?_)).2 + · rw [Real.norm_eq_abs, abs_mul, abs_of_pos (Real.exp_pos _)] + rw [mul_comm (Real.exp (H u x)), mul_comm (Real.exp A)] + apply mul_le_mul _ (Real.exp_le_exp.mpr ((le_abs_self _).trans (hHA u x))) + (Real.exp_pos _).le (add_nonneg (mul_nonneg hB hC) hD) + exact (abs_add_le _ _).trans (add_le_add (by + rw [abs_mul]; exact mul_le_mul (hHB u x) (hFC u x) (abs_nonneg _) hB) (hFD u x)) + · convert! ((hdH u x).exp.mul (hdF u x)) using 1 + ring + +lemma bounded_gibbs_mean_deriv + {H H' F F' : ℝ → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hH' : Measurable (Function.uncurry H')) + (hF : Measurable (Function.uncurry F)) (hF' : Measurable (Function.uncurry F')) + {A B C D : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hHA : ∀ t x, |H t x| ≤ A) (hHB : ∀ t x, |H' t x| ≤ B) + (hFC : ∀ t x, |F t x| ≤ C) (hFD : ∀ t x, |F' t x| ≤ D) + (hdH : ∀ t x, HasDerivAt (fun u => H u x) (H' t x) t) + (hdF : ∀ t x, HasDerivAt (fun u => F u x) (F' t x) t) (t : ℝ) : + HasDerivAt (fun u => tiltMean μ (H u) (F u) 1) + (tiltMean μ (H t) (fun x => H' t x * F t x+F' t x) 1 - + tiltMean μ (H t) (F t) 1 * tiltMean μ (H t) (H' t) 1) t := by + have hnum := bounded_gibbs_integral_deriv μ hH hH' hF hF' hA hB hC hD + hHA hHB hFC hFD hdH hdF t + have hden := bounded_gibbs_integral_deriv μ hH hH' (F := fun _ _ => 1) + (F' := fun _ _ => 0) (C := 1) (D := 0) measurable_const measurable_const hA hB (by norm_num) + (by norm_num) hHA hHB (by simp) (by simp) hdH (by intro t x; exact hasDerivAt_const _ _) t + simp only [mul_one, add_zero, tiltIntegral, one_mul] at hden + have hp := (tilt_partition_pos μ (hH.comp (measurable_const.prodMk measurable_id)) + hA (hHA t) 1).ne' + have hp' : (∫ x, Real.exp (H t x) ∂μ) ≠ 0 := by + simpa only [tiltPartition, one_mul, Function.comp_def, Function.uncurry_def, id_eq] using hp + convert! hnum.div hden hp' using 1 + · simp only [tiltMean, tiltPartition, one_mul, Pi.div_def] + · simp only [tiltMean, tiltIntegral, tiltPartition, one_mul] + field_simp [hp'] + +lemma bounded_gaussian_gibbs_coordinate_ibp {n : ℕ} (i : Fin (n+1)) + {H H' F F' : (Fin (n+1) → ℝ) → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hH' : Measurable (Function.uncurry H')) + (hF : Measurable (Function.uncurry F)) (hF' : Measurable (Function.uncurry F')) + {A B C D : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hHA : ∀ g x, |H g x| ≤ A) (hHB : ∀ g x, |H' g x| ≤ B) + (hFC : ∀ g x, |F g x| ≤ C) (hFD : ∀ g x, |F' g x| ≤ D) + (hdH : ∀ g t x, HasDerivAt (fun u => H (i.insertNth u g) x) (H' (i.insertNth t g) x) t) + (hdF : ∀ g t x, HasDerivAt (fun u => F (i.insertNth u g) x) (F' (i.insertNth t g) x) t) : + (∫ g, g i * tiltMean μ (H g) (F g) 1 ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ g, tiltMean μ (H g) (fun x => H' g x*F g x+F' g x) 1 - + tiltMean μ (H g) (F g) 1 * tiltMean μ (H g) (H' g) 1 + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + have hm := measurable_tiltMean_param μ hH hF + have hmm := measurable_tiltMean_param μ (Y := fun g x => H' g x*F g x+F' g x) hH ((hH'.mul hF).add hF') + have hm' := measurable_tiltMean_param μ hH hH' + have hb (g) := tilt_mean_bound μ + (hH.comp (measurable_const.prodMk measurable_id)) + (hF.comp (measurable_const.prodMk measurable_id)) hA hC (hHA g) (hFC g) 1 + have hb' (g) := tilt_mean_bound μ + (hH.comp (measurable_const.prodMk measurable_id)) + (hH'.comp (measurable_const.prodMk measurable_id)) hA hB (hHA g) (hHB g) 1 + apply gaussian_pi_coordinate_integrationByParts n i hm (hmm.sub (hm.mul hm')) + (C := C) (B := 2*B*C+D) hb + · intro g + have hab (x) : |H' g x*F g x+F' g x| ≤ B*C+D := + (abs_add_le _ _).trans (add_le_add (by + rw [abs_mul]; exact mul_le_mul (hHB g x) (hFC g x) (abs_nonneg _) hB) (hFD g x)) + have hj := tilt_mean_bound μ + (hH.comp (measurable_const.prodMk measurable_id)) + (((hH'.mul hF).add hF').comp (measurable_const.prodMk measurable_id)) + hA (by positivity) (hHA g) hab 1 + exact (abs_sub _ _).trans (by + simp only [Pi.mul_apply, abs_mul] + have hp := mul_le_mul (hb g) (hb' g) (abs_nonneg _) hC + simp only [Function.comp_def, Function.uncurry_def, id_eq, Pi.add_apply, Pi.mul_apply] at hj hp + nlinarith) + · intro g t + have he : Measurable (fun p : ℝ×S => ((i.insertNth p.1 g : Fin (n+1) → ℝ),p.2)) := by + fun_prop + exact bounded_gibbs_mean_deriv μ + (H := fun t x => H (i.insertNth t g) x) + (H' := fun t x => H' (i.insertNth t g) x) + (F := fun t x => F (i.insertNth t g) x) + (F' := fun t x => F' (i.insertNth t g) x) + (hH.comp he) (hH'.comp he) (hF.comp he) (hF'.comp he) + hA hB hC hD (fun u => hHA _) (fun u => hHB _) (fun u => hFC _) (fun u => hFD _) + (hdH g) (hdF g) t + +lemma nonlinear_pattern_coordinate_ibp {n : ℕ} (i : Fin (n+1)) (f : Jet3) + {v : Fin (n+1) → S → ℝ} {h u : S → ℝ} + (hv : ∀ j, Measurable (v j)) (hh : Measurable h) (hu : Measurable u) + {A C D : ℝ} (hA : 0 ≤ A) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hhA : ∀ x, |h x| ≤ A) (hvC : ∀ j x, |v j x| ≤ C) (huD : ∀ x, |u x| ≤ D) : + (∫ a, a i * tiltMean μ (fun x => h x+f.f (gaussianField (n+1) v a x)) + (fun x => f.d1 (gaussianField (n+1) v a x)*u x) 1 + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ a, tiltMean μ (fun x => h x+f.f (gaussianField (n+1) v a x)) + (fun x => (f.d1 (gaussianField (n+1) v a x)^2+ + f.d2 (gaussianField (n+1) v a x))*v i x*u x) 1 - + tiltMean μ (fun x => h x+f.f (gaussianField (n+1) v a x)) + (fun x => f.d1 (gaussianField (n+1) v a x)*u x) 1 * + tiltMean μ (fun x => h x+f.f (gaussianField (n+1) v a x)) + (fun x => f.d1 (gaussianField (n+1) v a x)*v i x) 1 + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + let b := gaussianField (n+1) v + let H := fun a x => h x+f.f (b a x) + let H' := fun a x => f.d1 (b a x)*v i x + let F := fun a x => f.d1 (b a x)*u x + let F' := fun a x => f.d2 (b a x)*v i x*u x + have hb : Measurable (Function.uncurry b) := gaussianField_measurable hv + have hHm : Measurable (Function.uncurry H) := + (hh.comp measurable_snd).add (f.f.continuous.measurable.comp hb) + have hH'm : Measurable (Function.uncurry H') := + (f.d1.continuous.measurable.comp hb).mul ((hv i).comp measurable_snd) + have hFm : Measurable (Function.uncurry F) := + (f.d1.continuous.measurable.comp hb).mul (hu.comp measurable_snd) + have hF'm : Measurable (Function.uncurry F') := + ((f.d2.continuous.measurable.comp hb).mul ((hv i).comp measurable_snd)).mul (hu.comp measurable_snd) + have hHA (a x) : |H a x| ≤ A+‖f.f‖ := + (abs_add_le _ _).trans (add_le_add (hhA x) (f.f.norm_coe_le_norm _)) + have hHB (a x) : |H' a x| ≤ ‖f.d1‖*C := by + exact (abs_mul _ _).trans_le (mul_le_mul (f.d1.norm_coe_le_norm _) (hvC i x) + (abs_nonneg _) (norm_nonneg _)) + have hFC (a x) : |F a x| ≤ ‖f.d1‖*D := by + exact (abs_mul _ _).trans_le (mul_le_mul (f.d1.norm_coe_le_norm _) (huD x) + (abs_nonneg _) (norm_nonneg _)) + have hFD (a x) : |F' a x| ≤ ‖f.d2‖*C*D := by + dsimp [F'] + rw [abs_mul, abs_mul] + exact mul_le_mul (mul_le_mul (f.d2.norm_coe_le_norm _) (hvC i x) + (abs_nonneg _) (norm_nonneg _)) (huD x) (abs_nonneg _) (by positivity) + have hdH (a t x) : HasDerivAt (fun s => H (i.insertNth s a) x) + (H' (i.insertNth t a) x) t := by + dsimp [H, H', b] + simp_rw [gaussianField_insertNth] + convert! ((f.has1 _).comp t (((hasDerivAt_id t).mul_const (v i x)).add_const + (gaussianField n (fun j => v (i.succAbove j)) a x))).const_add (h x) using 1 + simp only [one_mul, id_eq] + have hdF (a t x) : HasDerivAt (fun s => F (i.insertNth s a) x) + (F' (i.insertNth t a) x) t := by + dsimp [F, F', b] + simp_rw [gaussianField_insertNth] + convert! (((f.has2 _).comp t (((hasDerivAt_id t).mul_const (v i x)).add_const + (gaussianField n (fun j => v (i.succAbove j)) a x))).mul_const (u x)) using 1 + simp only [one_mul, id_eq] + have he := bounded_gaussian_gibbs_coordinate_ibp μ i hHm hH'm hFm hF'm + (by positivity) (by positivity) (by positivity) (by positivity) hHA hHB hFC hFD hdH hdF + convert! he using 1 + · apply integral_congr_ae + filter_upwards [] with a + congr 2 + funext x + dsimp [H', F, F', b] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/BoundedLeafRestoration.lean b/lean/OAI/Probability/Perceptron/Variational/BoundedLeafRestoration.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f0177a60988b58523cb84c01dac278abf40b4b3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/BoundedLeafRestoration.lean @@ -0,0 +1,43 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.TerminalReplicaRestoration + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +variable {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + +lemma exp_add_integrable_of_bound (μ : Measure S) {H W : S→ℝ} + (hi : Integrable (fun x => Real.exp (H x)) μ) (hW : Measurable W) + {C : ℝ} (hb : ∀ x, W x≤C) : Integrable (fun x => Real.exp (H x+W x)) μ := by + have h := hi.mul_bdd (hW.exp.aestronglyMeasurable) (ae_of_all μ fun x => + show ‖Real.exp (W x)‖≤Real.exp C by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (hb x)) + simpa only [Real.exp_add] using h + +lemma product_leaf_restore (μ : Measure S) (ν : Measure T) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (H : S×T→ℝ) (G W : T→ℝ) (hH : Measurable H) (hG : Measurable G) (hW : Measurable W) + (hi : Integrable (fun x => Real.exp (H x)) (μ.prod ν)) + (hp : ∀ t, (∫ s, Real.exp (H (s,t)) ∂μ)=Real.exp (G t)) + {C : ℝ} (hb : ∀ t, W t≤C) (r : ℕ) (F : (Fin r→T)→ℝ) (hF : Measurable F) : + gibbsReplicaMean (μ.prod ν) (fun x => H x+W x.2) r (fun x => F (fun i => (x i).2))= + gibbsReplicaMean ν (fun t => G t+W t) r F := by + apply gibbsReplicaMean_product_leaf μ ν _ _ (hH.add (hW.comp measurable_snd)) (hG.add hW) + (exp_add_integrable_of_bound _ hi (hW.comp measurable_snd) (fun x => hb x.2)) _ r F hF + intro t + change (∫ s, Real.exp (H (s,t)+W t) ∂μ)=Real.exp (G t+W t) + simp only [Real.exp_add,integral_mul_const,hp] + +lemma gibbsReplicaMean_congr (μ : Measure S) (H G : S→ℝ) (h : ∀ x,H x=G x) + (r : ℕ) (F K : (Fin r→S)→ℝ) (hF : ∀ x,F x=K x) : + gibbsReplicaMean μ H r F=gibbsReplicaMean μ G r K := by + rw [show H=G from funext h,show F=K from funext hF] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CappedAContinuity.lean b/lean/OAI/Probability/Perceptron/Variational/CappedAContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..1846f14fe7667db15242151345d15d1b7c51af41 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CappedAContinuity.lean @@ -0,0 +1,63 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereKernel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators NNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma realTail_weak_tendsto (μ : ℕ→ProbabilityMeasure Time) (ν : ProbabilityMeasure Time) + (hμ : Tendsto μ atTop (𝓝 ν)) (t : ℝ) : + Tendsto (fun j=>realTail (μ j) t) atTop (𝓝 (realTail ν t)) := by + let F : Time→ᵇℝ:=ContinuousMap.equivBoundedOfCompact Time ℝ ⟨fun s=>1-max t (s:ℝ),by fun_prop⟩ + exact (ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mp hμ) F + +lemma cappedDensity_bound (ν : Measure Time) {B : ℝ} (hB : B<1) (t : ℝ) : + 0≤cappedDensity ν B t ∧ cappedDensity ν B t≤(1-B)⁻¹^2 := by + have hb : 0<1-B:=sub_pos.mpr hB + have hm : 0 < max (1-B) (realTail ν t):=hb.trans_le (le_max_left _ _) + refine ⟨sq_nonneg _,?_⟩ + exact pow_le_pow_left₀ (inv_nonneg.mpr hm.le) + ((inv_le_inv₀ hm hb).mpr (le_max_left _ _)) 2 + +def cappedAError (μ ν : Measure Time) (B : ℝ) : ℝ := + ∫ t in (0:ℝ)..1,|cappedDensity μ B t-cappedDensity ν B t| + +lemma cappedAError_nonneg (μ ν : Measure Time) (B : ℝ) : 0≤cappedAError μ ν B := + intervalIntegral.integral_nonneg (by norm_num) (fun _ _=>abs_nonneg _) + +lemma cappedA_sub_bound (μ ν : Measure Time) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + {B : ℝ} (hB : B<1) (r : Time) : + |cappedA μ B r-cappedA ν B r|≤cappedAError μ ν B := by + have hμ:=cappedDensity_continuous μ hB + have hν:=cappedDensity_continuous ν hB + rw [cappedA,cappedA,←intervalIntegral.integral_sub (hμ.intervalIntegrable _ _) (hν.intervalIntegrable _ _)] + exact (intervalIntegral.abs_integral_le_integral_abs r.prop.1).trans + (intervalIntegral.integral_mono_interval le_rfl r.prop.1 r.prop.2 + (ae_of_all _ fun _=>abs_nonneg _) ((hμ.sub hν).abs.intervalIntegrable _ _)) + +lemma cappedAError_tendsto (μ : ℕ→ProbabilityMeasure Time) (ν : ProbabilityMeasure Time) + (hμ : Tendsto μ atTop (𝓝 ν)) {B : ℝ} (hB : B<1) : + Tendsto (fun j=>cappedAError (μ j) ν B) atTop (𝓝 0) := by + have hd (t : ℝ) : Tendsto (fun j=>cappedDensity (μ j) B t) atTop (𝓝 (cappedDensity ν B t)) := by + exact ((tendsto_const_nhds.max (realTail_weak_tendsto μ ν hμ t)).inv₀ + (ne_of_gt ((sub_pos.mpr hB).trans_le (le_max_left _ _)))).pow 2 + have hh:=tendsto_integral_of_dominated_convergence (μ:=volume.restrict (Ioc (0:ℝ) 1)) + (fun _ : ℝ=>2*(1-B)⁻¹^2) + (F:=fun j t=>|cappedDensity (μ j) B t-cappedDensity ν B t|) + (f:=fun _=>0) + (fun j=>((cappedDensity_continuous (μ j) hB).sub (cappedDensity_continuous ν hB)).abs.measurable.aestronglyMeasurable) + (integrable_const _) (fun j=>ae_of_all _ fun t=>by + have h₁:=cappedDensity_bound (μ j) hB t + have h₂:=cappedDensity_bound ν hB t + rw [Real.norm_eq_abs,abs_abs] + exact abs_le.mpr ⟨by linarith,by linarith⟩) + (ae_of_all _ fun t=>by simpa using ((hd t).sub (tendsto_const_nhds (x:=cappedDensity ν B t))).abs) + simpa only [cappedAError,intervalIntegral.integral_of_le (by norm_num : (0:ℝ)≤1),integral_zero] using hh +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CompactEnvelope.lean b/lean/OAI/Probability/Perceptron/Variational/CompactEnvelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c782bcce0e886581f31e6f3ad6e41fa0b7cfea1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CompactEnvelope.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.FiniteTerminal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction ContDiff +namespace SphericalPerceptronFreeEnergy + +def Jet3.addConstant (g : Jet3) (c : ℝ) : Jet3 where + f:=g.f+BoundedContinuousFunction.const ℝ c + d1:=g.d1 + d2:=g.d2 + d3:=g.d3 + has1 x:=by + change HasDerivAt (fun y => g.f y + c) (g.d1 x) x + exact (g.has1 x).add_const c + has2:=g.has2 + has3:=g.has3 + +def Jet3.negative (g : Jet3) : Jet3 where + f:=-g.f + d1:=-g.d1 + d2:=-g.d2 + d3:=-g.d3 + has1 x:=by simpa using (g.has1 x).neg + has2 x:=by simpa using (g.has2 x).neg + has3 x:=by simpa using (g.has3 x).neg + +lemma exists_smooth_lower_envelope (f : ℝ→ᵇℝ) {R ε : ℝ} (hR : 0ψ x*(f x+K) + have hF : Continuous F:=ψ.continuous.mul (f.continuous.add continuous_const) + have hFs : HasCompactSupport F:=ψ.hasCompactSupport.mul_right + obtain ⟨g,hg,hgf,hgs⟩:=hF.exists_contDiff_approx (⊤:ℕ∞) + (ε:=fun _=>ε) continuous_const (fun _=>hε) + have hg' : ContDiff ℝ ∞ g:=hg + have hs : HasCompactSupport g:=hFs.mono hgs + let J:=(Jet3.ofCompactSmooth g hg' hs).addConstant (-K-ε) + have hJ (x : ℝ) : J.f x=g x-K-ε := by simp [J,Jet3.addConstant]; ring + have hzero (x : ℝ) : 0≤F x := by + have hf:= (abs_le.mp (f.norm_coe_le_norm x)).1 + dsimp [F,K] + exact mul_nonneg ψ.nonneg (by linarith) + have hle (x : ℝ) : F x≤f x+K := + mul_le_of_le_one_left (by have hf:=(abs_le.mp (f.norm_coe_le_norm x)).1; dsimp [K]; linarith) ψ.le_one + have herr (x : ℝ) : |g x-F x|<ε := by simpa only [Real.dist_eq] using hgf x + have hlower (x : ℝ) : J.f x≤f x := by + rw [hJ] + have hh:=(abs_lt.mp (herr x)).2 + linarith [hle x] + refine ⟨J,?_,?_,?_,?_,hlower,?_⟩ + · change HasCompactSupport (deriv g) + exact hs.deriv + · change HasCompactSupport (deriv (deriv g)) + exact hs.deriv.deriv + · change HasCompactSupport (deriv (deriv (deriv g))) + exact hs.deriv.deriv.deriv + · apply (BoundedContinuousFunction.norm_le (by positivity : 0≤‖f‖+2*ε)).mpr + intro x + rw [Real.norm_eq_abs] + apply abs_le.mpr + constructor + · rw [hJ] + have hh:=(abs_lt.mp (herr x)).1 + dsimp [K] at * + linarith [hzero x] + · have hh:=(abs_le.mp (f.norm_coe_le_norm x)).2 + linarith [hlower x] + · intro x hx + have hψ : ψ x=1:=ψ.one_of_mem_closedBall (by simpa only [Metric.mem_closedBall,Real.dist_eq,sub_zero] using hx) + have he : F x=f x+K:=by simp [F,hψ] + rw [hJ] + have hh:=herr x + rw [he] at hh + exact abs_le.mpr ⟨by linarith [(abs_lt.mp hh).1],by linarith [(abs_lt.mp hh).2]⟩ + +lemma exists_smooth_lower_sequence (f : ℝ→ᵇℝ) : + ∃ g : ℕ→Jet3, + (∀ n,HasCompactSupport ((g n).d1 : ℝ→ℝ) ∧ HasCompactSupport ((g n).d2 : ℝ→ℝ) ∧ + HasCompactSupport ((g n).d3 : ℝ→ℝ)) ∧ + (∀ n,‖(g n).f‖≤‖f‖+1) ∧ (∀ n x,(g n).f x≤f x) ∧ + ∀ R : ℝ,0⟨h1 n,h2 n,h3 n⟩),?_,hlo,?_⟩ + · intro n + have hh : 2*((1:ℝ)/(2*((n:ℝ)+1)))=1/((n:ℝ)+1) := by field_simp + have hle : (1:ℝ)/((n:ℝ)+1)≤1 := (div_le_one (by positivity)).mpr (by linarith [Nat.cast_nonneg (α:=ℝ) n]) + have hi:=hn n + rw [hh] at hi + exact hi.trans (by linarith) + · intro R hR ε hε + obtain ⟨N1,hN1⟩:=exists_nat_ge R + obtain ⟨N2,hN2⟩:=exists_nat_one_div_lt hε + refine ⟨max N1 N2,fun n hn x hx=>?_⟩ + have hN1' : N1≤n:=(le_max_left _ _).trans hn + have hN2' : N2≤n:=(le_max_right _ _).trans hn + have hx' : |x|≤(n:ℝ)+1 := by + have hc : (N1:ℝ)≤n:=by exact_mod_cast hN1' + linarith + have hh:=he n x hx' + have heq : 2*((1:ℝ)/(2*((n:ℝ)+1)))=1/((n:ℝ)+1) := by field_simp + rw [heq] at hh + exact hh.trans ((one_div_le_one_div_of_le (by positivity) (by exact_mod_cast Nat.add_le_add_right hN2' 1)).trans hN2.le) + +lemma exists_smooth_upper_sequence (f : ℝ→ᵇℝ) : + ∃ g : ℕ→Jet3, + (∀ n,HasCompactSupport ((g n).d1 : ℝ→ℝ) ∧ HasCompactSupport ((g n).d2 : ℝ→ℝ) ∧ + HasCompactSupport ((g n).d3 : ℝ→ℝ)) ∧ + (∀ n,‖(g n).f‖≤‖f‖+1) ∧ (∀ n x,f x≤(g n).f x) ∧ + ∀ R : ℝ,0(g n).negative,fun n=>⟨(hs n).1.neg,(hs n).2.1.neg,(hs n).2.2.neg⟩,?_,?_,?_⟩ + · intro n + simpa only [Jet3.negative,norm_neg] using hn n + · intro n x + have h:=hlo n x + change f x≤-(g n).f x + change (g n).f x≤-f x at h + linarith + · intro R hR ε hε + obtain ⟨N,hN⟩:=he R hR ε hε + refine ⟨N,fun n hn x hx=>?_⟩ + have h:=hN n hn x hx + change |-(g n).f x-f x|≤ε + change |(g n).f x- -f x|≤ε at h + rw [show -(g n).f x-f x = -((g n).f x+f x) by ring,abs_neg] + simpa only [sub_neg_eq_add] using h + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CompactGGDensity.lean b/lean/OAI/Probability/Perceptron/Variational/CompactGGDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e9616f4ef6d0bb48a36d823a7e41a8b3e1317ac --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CompactGGDensity.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.PerturbationContact + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +section + +variable {X : Type*} [TopologicalSpace X] [MeasurableSpace X] [OpensMeasurableSpace X] + +def boundedTestIntegral (μ : Measure X) [IsProbabilityMeasure μ] : (X →ᵇ ℝ) →L[ℝ] ℝ := + LinearMap.mkContinuous + { toFun := fun f => ∫ x, f x ∂μ + map_add' := fun f g => integral_add (f.integrable μ) (g.integrable μ) + map_smul' := fun c f => by simpa using integral_const_mul c (fun x => f x) } + 1 (fun f => by simpa using f.norm_integral_le_norm μ) + +def compactGGTestCLM {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [SecondCountableTopology K] + (μ : ProbabilityMeasure (CompactArray K)) (n : ℕ) (i : Fin n) + (f : CompactBlock K n →ᵇ ℝ) : (K →ᵇ ℝ) →L[ℝ] ℝ := by + classical + let I := boundedTestIntegral (μ : Measure (CompactArray K)) + let F := f.compContinuous ⟨compactBlock n,compactBlock_continuous n⟩ + let E (a b : ℕ) := BoundedContinuousFunction.compContinuousCLM ℝ ℝ + (⟨fun Q : CompactArray K => Q a b,by fun_prop⟩ : C(CompactArray K,K)) + let L (a b : ℕ) := I.comp ((ContinuousLinearMap.mul ℝ (CompactArray K →ᵇ ℝ) F).comp (E a b)) + exact (n:ℝ) • L i n - (I F) • (I.comp (E 0 1)) - ∑ j ∈ Finset.univ.erase i, L i j + +lemma compactGGTestCLM_apply {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [SecondCountableTopology K] + (μ : ProbabilityMeasure (CompactArray K)) (n : ℕ) (i : Fin n) + (f : CompactBlock K n →ᵇ ℝ) (g : K →ᵇ ℝ) : + compactGGTestCLM μ n i f g = compactGGDefect μ n i f g := by + classical + simp [compactGGTestCLM,compactGGDefect,boundedTestIntegral] + +lemma compactJoint_monomials_total (L : (CompactJointOverlap →ᵇ ℝ) →L[ℝ] ℝ) + (hL : ∀ p d, L (compactJointMonomial p d)=0) : L=0 := by + let e := ContinuousMap.linearIsometryBoundedOfCompact CompactJointOverlap ℝ ℝ + let L' := L.comp e.toContinuousLinearEquiv.toContinuousLinearMap + let m (a : ℕ×ℕ) : C(CompactJointOverlap,ℝ) := (compactJointMonomial a.1 a.2).toContinuousMap + have hm0 : m 0=1 := by ext x; simp [m] + have hmadd (a b : ℕ×ℕ) : m (a+b)=m a*m b := by + ext x + exact congrArg (fun f : CompactJointOverlap →ᵇ ℝ => f x) (compactJointMonomial_add _ _ _ _) + let M : Submonoid C(CompactJointOverlap,ℝ) := + { carrier := Set.range m + one_mem' := ⟨0,hm0⟩ + mul_mem' := by rintro _ _ ⟨a,rfl⟩ ⟨b,rfl⟩; exact ⟨a+b,hmadd a b⟩ } + let A := Algebra.adjoin ℝ (M : Set C(CompactJointOverlap,ℝ)) + have hsep : A.SeparatesPoints := by + intro x y hxy + obtain ⟨p,d,hpd⟩ := compactJointMonomial_separates x y hxy + have hmem : m (p,d) ∈ A := + Algebra.subset_adjoin (show m (p,d) ∈ M from ⟨(p,d),rfl⟩) + exact ⟨m (p,d),⟨m (p,d),hmem,rfl⟩,hpd⟩ + have hA : (A : Set C(CompactJointOverlap,ℝ)) ⊆ (L'.ker : Set C(CompactJointOverlap,ℝ)) := by + have hspan : Submodule.span ℝ (M : Set C(CompactJointOverlap,ℝ)) ≤ L'.ker := by + apply Submodule.span_le.mpr + rintro _ ⟨⟨p,d⟩,rfl⟩ + change L (e ((compactJointMonomial p d).toContinuousMap)) = 0 + have he : e ((compactJointMonomial p d).toContinuousMap) = compactJointMonomial p d := by + ext x; rfl + rw [he] + exact hL p d + intro f hf + apply hspan + change f ∈ A.toSubmodule at hf + simpa only [A,Algebra.adjoin_eq_span,Submonoid.closure_eq] using hf + have hclosed := L'.isClosed_ker + have hc := closure_minimal hA hclosed + have htop := ContinuousMap.subalgebra_topologicalClosure_eq_top_of_separatesPoints A hsep + have hall (f : C(CompactJointOverlap,ℝ)) : L' f=0 := by + apply hc + change f ∈ A.topologicalClosure + rw [htop] + trivial + ext g + have h := hall (e.symm g) + simpa [L'] using h + +lemma compactGG_of_joint_monomials (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (h : ∀ p d, compactGGDefect μ n i f (compactJointMonomial p d)=0) + (g : CompactJointOverlap →ᵇ ℝ) : compactGGDefect μ n i f g=0 := by + have hz := compactJoint_monomials_total (compactGGTestCLM μ n i f) + (fun p d => (compactGGTestCLM_apply μ n i f _).trans (h p d)) + rw [← compactGGTestCLM_apply,hz] + rfl + +end + +lemma compactGGDefect_one (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) : + compactGGDefect μ r i G 1=0 := by + have hr : 1≤r := by have := i.isLt; omega + simp only [compactGGDefect,BoundedContinuousFunction.coe_one,Pi.one_apply,mul_one, + integral_const,probReal_univ,smul_eq_mul,Finset.sum_const,Finset.card_erase_of_mem + (Finset.mem_univ i),Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,Nat.cast_sub hr,Nat.cast_one] + ring + +variable (k : ℕ) (f : ℝ →ᵇ ℝ) (p d : ℕ→ℕ) (z : Fin k→ℝ) +variable (hz : StrictMono z) (hz0 : ∀ i, 01) (fun _=>2)) +variable (hmin : ∀ n, IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k f (fun j=>p j.val) (fun j=>d j.val) (h n) z (t n) v) + (Icc (fun _ : Fin (n+1)=>1) (fun _=>2)) (u n)) +variable {H T : ℝ} (hH : 0≤H) (hhH : ∀ n, h n 0≤H) (ht : ∀ n, (t n:ℝ)≤T) + +include hz hz0 hz1 hh0 hh hu hmin hH hhH ht in +lemma source_contact_monomial_tendsto (j r : ℕ) (i : Fin r) + (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) : + Tendsto (fun n => compactGGDefect (sourceGibbsArrayLaw n k f (fun a=>p a.val) + (fun a=>d a.val) (h n) (u n) z (t n)) r i G (compactJointMonomial (p j) (d j))) atTop (𝓝 0) := by + let c : ℝ := (2:ℝ)^(-((j+1:ℕ):ℤ)) + have hc : 0 ((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have he : Tendsto (fun n : ℕ => perturbationScale (n+1)) atTop (𝓝 0) := by + convert (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1/16)).comp hN using 1 + simp only [perturbationScale,neg_div]; rfl + have he' : Tendsto (fun n : ℕ => 8*perturbationScale (n+1)^2) atTop (𝓝 0) := by + simpa using (he.pow 2).const_mul 8 + have hs : Tendsto (fun n : ℕ => ((n+1:ℕ):ℝ)^(-(1:ℝ)/4)) atTop (𝓝 0) := by + convert (tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1/4)).comp hN using 1 + simp only [neg_div,Function.comp_def] + apply squeeze_zero_norm' (a := fun n => ‖G‖/c^2*(Real.sqrt (2*c)*((n+1:ℕ):ℝ)^(-(3:ℝ)/8)+ + (c+4*Real.sqrt (enrichedVarianceConstant k z f H T))*((n+1:ℕ):ℝ)^(-(1:ℝ)/8))) + · filter_upwards [eventually_ge_atTop j,he'.eventually (gt_mem_nhds (by positivity : (0:ℝ)p a.val) (fun a=>d a.val) (h n) + (hh0 n) (hh n) z hz hz0 hz1 (t n) (hu n) (hmin n) ⟨j,hj⟩ hH (hhH n) (ht n) + he hs.le r i G + · exact (contact_gg_rate_tendsto c (enrichedVarianceConstant k z f H T) ‖G‖ c).comp hN + +include hz hz0 hz1 hh0 hh hu hmin hH hhH ht in +lemma source_contact_limit_joint_gg + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} {s : ℕ→ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n=>sourceGibbsArrayLaw (s n) k f (fun a=>p a.val) (fun a=>d a.val) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) + (hcover : ∀ a b : ℕ, 1≤a+b → ∃ j, p j=a ∧ d j=b) + (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ) : compactGGDefect ν r i G g=0 := by + apply compactGG_of_joint_monomials ν r i G + intro a b + by_cases hab : a+b=0 + · have ha : a=0 := by omega + have hb : b=0 := by omega + subst a b + simpa only [compactJointMonomial_zero] using compactGGDefect_one ν r i G + obtain ⟨j,hp,hd⟩ := hcover a b (by omega) + apply compactGGDefect_limit hlim + simpa only [hp,hd,Function.comp_def] using + (source_contact_monomial_tendsto k f p d z hz hz0 hz1 t h hh0 hh u hu hmin hH hhH ht j r i G).comp hs.tendsto_atTop + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CompactGGEvents.lean b/lean/OAI/Probability/Perceptron/Variational/CompactGGEvents.lean new file mode 100644 index 0000000000000000000000000000000000000000..006343848d5aab27676471045dcc83d6828d0d53 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CompactGGEvents.lean @@ -0,0 +1,138 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.TripleIndex +import OAI.Probability.Perceptron.Interpolation.ArrayGeometry + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set TopologicalSpace Matrix +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma compactGG_events (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (n : ℕ) (hn : 0 + ρ.real (s×ˢt)) (compactGG_joint_law μ hn i hGG) + have hb := (compactBlock_continuous (K:=CompactJointOverlap) n).measurable + have hm (i j : ℕ) : Measurable (fun Q : CompactArray CompactJointOverlap => Q i j) := by fun_prop + rw [map_measureReal_apply (hb.prodMk (hm _ _)) (hs.prod ht), + measureReal_nnreal_smul_apply,measureReal_add_apply] at he + have hsum : (∑ j ∈ Finset.univ.erase i, + (μ : Measure _).map (fun Q => (compactBlock n Q,Q i j))).real (s×ˢt) = + ∑ j ∈ Finset.univ.erase i, (μ : Measure _).real (compactBlock n ⁻¹' s ∩ {Q | Q i j∈t}) := by + simp only [measureReal_def,Measure.finsetSum_apply] + rw [ENNReal.toReal_sum (by intro _ _; finiteness)] + apply Finset.sum_congr rfl + intro j hj + rw [Measure.map_apply (hb.prodMk (hm _ _)) (hs.prod ht)] + rfl + rw [hsum] at he + have hprod : (((μ : Measure _).map (compactBlock n)).prod + ((μ : Measure _).map (fun Q : CompactArray CompactJointOverlap => Q 0 1))).real (s×ˢt) = + (μ : Measure _).real (compactBlock n ⁻¹' s)*(μ : Measure _).real {Q : CompactArray CompactJointOverlap | Q 0 1∈t} := by + simp only [measureReal_def,Measure.prod_prod,ENNReal.toReal_mul, + Measure.map_apply hb hs,Measure.map_apply (hm 0 1) ht] + rfl + rw [hprod] at he + simp only [NNReal.coe_inv,NNReal.coe_natCast] at he + change (μ : Measure _).real (compactBlock n ⁻¹' s ∩ {Q | Q i n∈t}) = (n:ℝ)⁻¹*(_+_) at he + rw [he] + ring + +def compactPairReal (x : CompactJointOverlap) : ℝ×ℝ := (x.1.val,x.2.val) +def compactArrayReal (Q : CompactArray CompactJointOverlap) : PairedOverlapArray := + fun i j => compactPairReal (Q i j) +def compactBlockReal {n : ℕ} (Q : CompactBlock CompactJointOverlap n) : PairedOverlapBlock n := + fun i j => compactPairReal (Q i j) + +lemma compactPairReal_measurable : Measurable compactPairReal := by unfold compactPairReal; fun_prop +lemma compactArrayReal_measurable : Measurable compactArrayReal := by + unfold compactArrayReal; exact Measurable.of_eval fun row => Measurable.of_eval fun column => + compactPairReal_measurable.comp ((measurable_pi_apply column).comp (measurable_pi_apply row)) +lemma compactBlockReal_measurable (n : ℕ) : Measurable (compactBlockReal (n:=n)) := by + unfold compactBlockReal; exact Measurable.of_eval fun row => Measurable.of_eval fun column => + compactPairReal_measurable.comp ((measurable_pi_apply column).comp (measurable_pi_apply row)) + +def compactRealLaw (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) : + Measure PairedOverlapArray := (μ : Measure _).map compactArrayReal + +instance compactRealLaw_probability (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) : + IsProbabilityMeasure (compactRealLaw μ) := + (Measure.isProbabilityMeasure_map_iff compactArrayReal_measurable.aemeasurable).2 inferInstance + +lemma compactRealLaw_gg (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hGG : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect μ n i f g=0) : + JointGhirlandaGuerra (compactRealLaw μ) := by + intro n hn i s hs t ht + have hb : Measurable (pairedBlock n) := by unfold pairedBlock; fun_prop + have hedge (a b : ℕ) : Measurable (fun Q : PairedOverlapArray => Q a b) := by fun_prop + have hmap (u : Set PairedOverlapArray) (hu : MeasurableSet u) : + (compactRealLaw μ).real u=(μ : Measure _).real (compactArrayReal ⁻¹' u) := + map_measureReal_apply compactArrayReal_measurable hu + rw [hmap (pairedBlock n ⁻¹' s ∩ {Q | Q i n∈t}) ((hs.preimage hb).inter (ht.preimage (hedge i n))), + hmap _ (hs.preimage hb), hmap {Q | Q 0 1∈t} (ht.preimage (hedge 0 1))] + have hmj (j : Fin n) := hmap (pairedBlock n ⁻¹' s ∩ {Q | Q i j∈t}) + ((hs.preimage hb).inter (ht.preimage (hedge i j))) + simp_rw [hmj] + exact compactGG_events μ n (by omega) i (hGG n i) + (compactBlockReal ⁻¹' s) (hs.preimage (compactBlockReal_measurable n)) + (compactPairReal ⁻¹' t) (ht.preimage compactPairReal_measurable) + +lemma compactRealLaw_exchangeable (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hEx : ∀ e : Equiv.Perm ℕ, MeasurePreserving (compactRelabel (K:=CompactJointOverlap) e) (μ : Measure _) (μ : Measure _)) : + PairedSwapInvariant (compactRealLaw μ) := by + intro i j + have hp : Measurable (pairedRelabel (Equiv.swap i j)) := by unfold pairedRelabel; fun_prop + refine ⟨hp,?_⟩ + unfold compactRealLaw + rw [Measure.map_map hp compactArrayReal_measurable] + change Measure.map (compactArrayReal ∘ compactRelabel (Equiv.swap i j)) _ = _ + rw [← Measure.map_map compactArrayReal_measurable (hEx _).measurable,(hEx _).map_eq] + +lemma compactRealLaw_gram (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hR : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), ∀ n, Matrix.PosSemidef (fun i j : Fin n => (Q i j).1.val)) + (hT : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), ∀ n, Matrix.PosSemidef (fun i j : Fin n => (Q i j).2.val)) : + (∀ᵐ Q ∂compactRealLaw μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray Prod.fst Q))) ∧ + (∀ᵐ Q ∂compactRealLaw μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray Prod.snd Q))) := by + constructor + · exact ae_map_iff compactArrayReal_measurable.aemeasurable (measurableSet_gram_arrays.preimage + (scalarArray_measurable measurable_fst)) |>.mpr hR + · exact ae_map_iff compactArrayReal_measurable.aemeasurable (measurableSet_gram_arrays.preimage + (scalarArray_measurable measurable_snd)) |>.mpr hT + +lemma compactRealLaw_diagonals (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) : + (∀ᵐ Q ∂compactRealLaw μ, ∀ i, (Q i i).1≤1) ∧ + (∀ᵐ Q ∂compactRealLaw μ, ∀ i, (Q i i).2≤1) := by + constructor + · apply ae_map_iff compactArrayReal_measurable.aemeasurable (by measurability) |>.mpr + exact Filter.Eventually.of_forall (fun Q i => (Q i i).1.property.2) + · apply ae_map_iff compactArrayReal_measurable.aemeasurable (by measurability) |>.mpr + exact Filter.Eventually.of_forall (fun Q i => (Q i i).2.property.2) + +lemma compact_gg_no_crossing (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hEx : ∀ e : Equiv.Perm ℕ, MeasurePreserving (compactRelabel (K:=CompactJointOverlap) e) (μ : Measure _) (μ : Measure _)) + (hGG : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect μ n i f g=0) + (hR : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), ∀ n, Matrix.PosSemidef (fun i j : Fin n => (Q i j).1.val)) + (hT : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), ∀ n, Matrix.PosSemidef (fun i j : Fin n => (Q i j).2.val)) : + ∀ᵐ Q : CompactArray CompactJointOverlap ∂(μ : Measure _), ¬ ((Q 0 1).1.val < (Q 0 2).1.val ∧ (Q 0 2).2.val < (Q 0 1).2.val) := by + obtain ⟨hgr,hgt⟩ := compactRealLaw_gram μ hR hT + obtain ⟨hdr,hdt⟩ := compactRealLaw_diagonals μ + have hh := joint_gg_no_crossing (compactRealLaw μ) (compactRealLaw_exchangeable μ hEx) + (compactRealLaw_gg μ hGG) hgr hgt hdr hdt + exact (ae_map_iff compactArrayReal_measurable.aemeasurable (by measurability)).mp hh + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CompactGGFiniteCode.lean b/lean/OAI/Probability/Perceptron/Variational/CompactGGFiniteCode.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0091ccf84d763111aa893f6b77706fca2e3cc88 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CompactGGFiniteCode.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CompactGGEvents + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BigOperators BoundedContinuousFunction NNReal ENNReal + +section + +variable {L : Type*} [Fintype L] [MeasurableSpace L] [MeasurableSingletonClass L] + +def compactCodeArray (χ : CompactJointOverlap → L) (Q : CompactArray CompactJointOverlap) : + FiniteOverlap L := fun i j => χ (Q i j) + +def compactCodeBlock {n : ℕ} (χ : CompactJointOverlap → L) (Q : CompactBlock CompactJointOverlap n) : + FiniteBlock L n := fun i j => χ (Q i j) + +lemma compactCodeArray_measurable {L : Type*} [Fintype L] [MeasurableSpace L] + [MeasurableSingletonClass L] {χ : CompactJointOverlap → L} (hχ : Measurable χ) : + Measurable (compactCodeArray χ) := by + unfold compactCodeArray + exact Measurable.of_eval fun _ => Measurable.of_eval fun _ => + hχ.comp ((measurable_pi_apply _).comp (measurable_pi_apply _)) + +lemma compactCodeBlock_measurable {L : Type*} [Fintype L] [MeasurableSpace L] + [MeasurableSingletonClass L] {χ : CompactJointOverlap → L} (hχ : Measurable χ) (n : ℕ) : + Measurable (compactCodeBlock (n:=n) χ) := by + unfold compactCodeBlock + exact Measurable.of_eval fun _ => Measurable.of_eval fun _ => + hχ.comp ((measurable_pi_apply _).comp (measurable_pi_apply _)) + +lemma compactGG_finite_pushforward (μ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hGG : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect μ n i f g=0) + {χ : CompactJointOverlap → L} (hχ : Measurable χ) : + FiniteGG ((μ : Measure (CompactArray CompactJointOverlap)).map (compactCodeArray χ)) := by + classical + intro n hn i A c + have hm := compactCodeArray_measurable hχ + have hb := finiteBlock_measurable (L:=L) n + have he (a b : ℕ) : Measurable (fun R : FiniteOverlap L => R a b) := by fun_prop + have hs : MeasurableSet {R : FiniteOverlap L | finiteBlock n R=A} := + measurableSet_eq_fun hb measurable_const + have hv (a b : ℕ) : MeasurableSet {R : FiniteOverlap L | R a b=c} := + measurableSet_eq_fun (he a b) measurable_const + have hvv (a b : ℕ) : MeasurableSet {R : FiniteOverlap L | finiteBlock n R=A ∧ R a b=c} := hs.inter (hv a b) + rw [map_measureReal_apply hm (hvv _ _),map_measureReal_apply hm hs, + map_measureReal_apply hm (hv 0 1)] + simp_rw [map_measureReal_apply hm (hvv _ _)] + exact compactGG_events μ n (by omega) i (hGG n i) + ((compactCodeBlock χ) ⁻¹' {A}) ((measurableSet_singleton A).preimage (compactCodeBlock_measurable hχ n)) + (χ ⁻¹' {c}) ((measurableSet_singleton c).preimage hχ) + +lemma compact_finite_code_block_unique [LinearOrder L] + (μ ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hGGμ : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect μ n i f g=0) + (hGGν : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock CompactJointOverlap n →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν n i f g=0) + {χ : CompactJointOverlap → L} (hχ : Measurable χ) (d : L) + (hμ : ∀ᵐ Q ∂(μ : Measure (CompactArray CompactJointOverlap)), (∀ i j, χ (Q i j)=χ (Q j i)) ∧ + (∀ i, χ (Q i i)=d) ∧ ∀ i j k, min (χ (Q i j)) (χ (Q i k)) ≤ χ (Q j k)) + (hν : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), (∀ i j, χ (Q i j)=χ (Q j i)) ∧ + (∀ i, χ (Q i i)=d) ∧ ∀ i j k, min (χ (Q i j)) (χ (Q i k)) ≤ χ (Q j k)) + (hpair : (μ : Measure (CompactArray CompactJointOverlap)).map (fun Q => χ (Q 0 1))= + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => χ (Q 0 1))) (n : ℕ) : + (μ : Measure (CompactArray CompactJointOverlap)).map (fun Q => compactCodeBlock (n:=n+1) χ (compactBlock (n+1) Q))= + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => compactCodeBlock (n:=n+1) χ (compactBlock (n+1) Q)) := by + let μ' := (μ : Measure (CompactArray CompactJointOverlap)).map (compactCodeArray χ) + let ν' := (ν : Measure (CompactArray CompactJointOverlap)).map (compactCodeArray χ) + have hm := compactCodeArray_measurable hχ + have : IsProbabilityMeasure μ' := inferInstance + have : IsProbabilityMeasure ν' := inferInstance + have hgρ (ρ : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hρ : ∀ᵐ Q ∂(ρ : Measure (CompactArray CompactJointOverlap)), (∀ i j, χ (Q i j)=χ (Q j i)) ∧ + (∀ i, χ (Q i i)=d) ∧ ∀ i j k, min (χ (Q i j)) (χ (Q i k)) ≤ χ (Q j k)) : + ∀ᵐ R ∂(ρ : Measure (CompactArray CompactJointOverlap)).map (compactCodeArray χ), (∀ i j, R i j=R j i) ∧ + (∀ i, R i i=d) ∧ ∀ i j k, min (R i j) (R i k) ≤ R j k := by + apply (ae_map_iff hm.aemeasurable (by measurability)).mpr + exact hρ + have hp : ∀ c, μ'.real {R | R 0 1=c}=ν'.real {R | R 0 1=c} := by + intro c + have hh := congrArg (fun ρ : Measure L => ρ.real {c}) hpair + have he : Measurable (fun Q : CompactArray CompactJointOverlap => χ (Q 0 1)) := hχ.comp (by fun_prop) + rw [map_measureReal_apply he (measurableSet_singleton c), + map_measureReal_apply he (measurableSet_singleton c)] at hh + change ((μ : Measure (CompactArray CompactJointOverlap)).map (compactCodeArray χ)).real {R | R 0 1=c} = + ((ν : Measure (CompactArray CompactJointOverlap)).map (compactCodeArray χ)).real {R | R 0 1=c} + rw [map_measureReal_apply hm (by measurability : MeasurableSet {R : FiniteOverlap L | R 0 1=c}), + map_measureReal_apply hm (by measurability : MeasurableSet {R : FiniteOverlap L | R 0 1=c})] + change (μ : Measure (CompactArray CompactJointOverlap)).real {Q | χ (Q 0 1)=c} = + (ν : Measure (CompactArray CompactJointOverlap)).real {Q | χ (Q 0 1)=c} + exact hh + + have he := finiteGG_block_law_unique μ' ν' d (hgρ μ hμ) (hgρ ν hν) + (compactGG_finite_pushforward μ hGGμ hχ) (compactGG_finite_pushforward ν hGGν hχ) hp n + dsimp only [μ',ν'] at he + rw [Measure.map_map (finiteBlock_measurable (n+1)) hm, + Measure.map_map (finiteBlock_measurable (n+1)) hm] at he + have hf : finiteBlock (L:=L) (n+1) ∘ compactCodeArray χ = + fun Q => compactCodeBlock (n:=n+1) χ (compactBlock (n+1) Q) := by + funext Q i j + rfl + rw [hf] at he + exact he + +end + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def scaledStdGaussian (σ : ℝ) : Measure E := (stdGaussian E).map (σ • ·) + +instance (σ : ℝ) : IsProbabilityMeasure (scaledStdGaussian (E := E) σ) := + inferInstanceAs (IsProbabilityMeasure ((stdGaussian E).map (σ • ·))) + +lemma scaledStdGaussian_conv (σ τ : ℝ) : + (scaledStdGaussian (E := E) σ) ∗ (scaledStdGaussian τ)= + scaledStdGaussian (Real.sqrt (σ^2+τ^2)) := by + apply Measure.ext_of_charFun + funext t + rw [charFun_conv] + simp only [scaledStdGaussian,charFun_map_smul,charFun_stdGaussian] + rw [← Complex.exp_add] + congr 1 + have hr : -‖σ • t‖^2/2 + -‖τ • t‖^2/2 = -‖Real.sqrt (σ^2+τ^2) • t‖^2/2 := by + simp only [norm_smul,Real.norm_eq_abs,mul_pow,sq_abs, + Real.sq_sqrt (add_nonneg (sq_nonneg σ) (sq_nonneg τ))] + ring + exact_mod_cast hr + +lemma stdGaussian_integral_add {F : E → ℝ} (hF : Continuous F) (σ τ : ℝ) + (hI : Integrable (fun y : E => F (Real.sqrt (σ^2+τ^2) • y)) (stdGaussian E)) : + (∫ y, ∫ z, F (σ • y+τ • z) ∂stdGaussian E ∂stdGaussian E)= + ∫ y, F (Real.sqrt (σ^2+τ^2) • y) ∂stdGaussian E := by + have hi : Integrable F (scaledStdGaussian (E := E) (Real.sqrt (σ^2+τ^2))) := by + exact (integrable_map_measure hF.aestronglyMeasurable (by fun_prop)).mpr hI + rw [← scaledStdGaussian_conv σ τ] at hi + have H := integral_conv hi + rw [scaledStdGaussian_conv σ τ] at H + simp only [scaledStdGaussian] at H + rw [integral_map (by fun_prop) hF.aestronglyMeasurable] at H + have hm : StronglyMeasurable (fun y : E => ∫ z : E, F (y+z) ∂(stdGaussian E).map (τ • ·)) := + ((hF.comp (continuous_fst.add continuous_snd)).stronglyMeasurable).integral_prod_right' + rw [integral_map (by fun_prop) hm.aestronglyMeasurable] at H + have HH : ∀ y : E, (∫ z, F (σ • y+z) ∂(stdGaussian E).map (τ • ·))= + ∫ z, F (σ • y+τ • z) ∂stdGaussian E := by + intro y + rw [integral_map (by fun_prop) (by fun_prop)] + simp_rw [HH] at H + exact H.symm + +lemma gaussianEntropic_semigroup {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) {p : ℝ} (hp : 0 ≤ p) (σ τ : ℝ) (x : E) : + gaussianEntropic (stdGaussian E) p σ (gaussianEntropic (stdGaussian E) p τ f) x= + gaussianEntropic (stdGaussian E) p (Real.sqrt (σ^2+τ^2)) f x := by + have hfc := hf.continuous + have hinner := gaussianEntropic_lipschitz (stdGaussian E) hf (σ := τ) hp + by_cases hp0 : p=0 + · subst p + rw [gaussianEntropic_zero _ hinner,gaussianEntropic_zero _ hf] + simp_rw [gaussianEntropic_zero _ hf] + have H := stdGaussian_integral_add (F := fun y => f (x+y)) (by fun_prop) σ τ + (gaussian_integrable_lipschitz (stdGaussian E) hf _ x) + simpa only [add_assoc] using H + · rw [gaussianEntropic_pos _ hinner hp0,gaussianEntropic_pos _ hf hp0] + have he (y : E) : Real.exp (p*gaussianEntropic (stdGaussian E) p τ f (x+σ • y))= + ∫ z, Real.exp (p*f (x+σ • y+τ • z)) ∂stdGaussian E := by + rw [gaussianEntropic_pos _ hf hp0] + rw [mul_div_cancel₀ _ hp0] + apply Real.exp_log + exact mgf_pos (gaussian_integrable_exp_lipschitz (stdGaussian E) hf p τ _) + simp_rw [he] + have H := stdGaussian_integral_add (F := fun y => Real.exp (p*f (x+y))) (by fun_prop) σ τ + (gaussian_integrable_exp_lipschitz (stdGaussian E) hf p _ x) + simpa only [add_assoc] using congrArg (fun a : ℝ => Real.log a/p) H + +lemma gaussianEntropic_variance_zero {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (p : ℝ) (x : E) : + gaussianEntropic (stdGaussian E) p 0 f x=f x := by + by_cases hp : p=0 + · subst p + simp [gaussianEntropic_zero _ hf] + · rw [gaussianEntropic_pos _ hf hp] + simp [hp] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CompactJointMonomials.lean b/lean/OAI/Probability/Perceptron/Variational/CompactJointMonomials.lean new file mode 100644 index 0000000000000000000000000000000000000000..ff4464e7360a0f222d7e52a0045840a27eda3cce --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CompactJointMonomials.lean @@ -0,0 +1,92 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.GibbsOverlapArray + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +def compactJointMonomial (p d : ℕ) : CompactJointOverlap →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x : CompactJointOverlap => (x.2:ℝ)^d*(x.1:ℝ)^p,by fun_prop⟩ + +@[simp] lemma compactJointMonomial_apply (p d : ℕ) (x : CompactJointOverlap) : + compactJointMonomial p d x = (x.2:ℝ)^d*(x.1:ℝ)^p := rfl + +lemma compactJointMonomial_zero : compactJointMonomial 0 0 = 1 := by ext x; simp + +lemma compactJointMonomial_add (p d p' d' : ℕ) : + compactJointMonomial (p+p') (d+d') = compactJointMonomial p d * compactJointMonomial p' d' := by + ext x + simp only [compactJointMonomial_apply,BoundedContinuousFunction.mul_apply,pow_add] + ring + +lemma compactJointMonomial_separates (x y : CompactJointOverlap) (h : x≠y) : + ∃ p d, compactJointMonomial p d x ≠ compactJointMonomial p d y := by + by_contra hn + push Not at hn + apply h + apply Prod.ext <;> apply Subtype.ext + · simpa using hn 1 0 + · simpa using hn 0 1 + +lemma compactJointMonomial_abs_le (p d : ℕ) (x : CompactJointOverlap) : + |compactJointMonomial p d x|≤1 := by + rw [compactJointMonomial_apply,abs_mul,abs_pow,abs_pow,abs_of_nonneg x.2.property.1] + exact (mul_le_of_le_one_left (by positivity) + (pow_le_one₀ x.2.property.1 x.2.property.2)).trans + (pow_le_one₀ (abs_nonneg _) (abs_le.mpr x.1.property)) + +lemma compactJoint_monomials_determine (P Q : Measure CompactJointOverlap) + [IsFiniteMeasure P] [IsFiniteMeasure Q] + (h : ∀ p d, (∫ x, compactJointMonomial p d x ∂P) = ∫ x, compactJointMonomial p d x ∂Q) : P=Q := by + apply measure_eq_of_additive_test_family (fun a : ℕ×ℕ => compactJointMonomial a.1 a.2) + compactJointMonomial_zero (fun a b => compactJointMonomial_add _ _ _ _) + · intro x y hxy + obtain ⟨p,d,hpd⟩ := compactJointMonomial_separates x y hxy + exact ⟨(p,d),hpd⟩ + · exact fun a => h a.1 a.2 + +lemma sourceJointOverlap_symm {N k : ℕ} (x y : NormalizedSpin N×IndexedLeaf k) : + sourceJointOverlap x y = sourceJointOverlap y x := by + apply Prod.ext <;> apply Subtype.ext + · exact real_inner_comm _ _ + · simp only [sourceJointOverlap,indexedCommonDepth_comm k y.2 x.2] + +lemma sourceGibbsArray_eq (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) : + sourceGibbsArrayLaw n k f p d h u z t = + gibbsOverlapArrayLaw (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) + (sourceCouplingHamiltonian_measurable n k f p d h u) + sourceJointOverlap (sourceJointOverlap_measurable (n+1) k) := rfl + +lemma source_compact_gg_defect (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0≤h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (z : Fin k → ℝ) (t : ℝ≥0) + (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) : + compactGGDefect (sourceGibbsArrayLaw n k f p d h u z t) r i G (compactJointMonomial (p j) (d j)) = + -kernelGGDefect (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) (sourceJointMonomial p d j) + (((k:ℝ)/(k+1:ℕ))^(d j)) r i + (fun x => G (fun a b => sourceJointOverlap (x a) (x b))) := by + rw [sourceGibbsArray_eq] + have he := sourceCoupling_all_exp_ae n k f p d h hh0 hh u 0 z t + have hexp : ∀ᵐ a ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw, + Integrable (fun x => Real.exp (sourceCouplingHamiltonian n k f p d h u a x)) + (sourceFullSpinLeafKernel n k a) := by + filter_upwards [he] with a ha + simpa only [sourceFullSpinLeafKernel,Kernel.comap_apply,zero_mul,add_zero] using ha 0 + apply compactGGDefect_gibbsOverlapArray _ _ _ _ _ _ hexp r i G (compactJointMonomial (p j) (d j)) + · exact sourceJointMonomial_diagonal p d j + · intro x y + rw [sourceJointOverlap_symm x y] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CompactRestorationWitness.lean b/lean/OAI/Probability/Perceptron/Variational/CompactRestorationWitness.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd1f3189400f1136a80a2433f16f25a051accef6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CompactRestorationWitness.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelPairTestValue + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology BoundedContinuousFunction NNReal ENNReal BigOperators + +abbrev WeightedRestorationRange (f : ℝ →ᵇ ℝ) (C : ℝ) := Icc (-C) C × RestorationRange f + +def compactWeightedLaw {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] (f : ℝ →ᵇ ℝ) (C : ℝ) + (A : Ω→ℝ) (hA : Measurable A) (Z : Ω→RestorationRange f) (hZ : Measurable Z) + (hb : ∀ x, |A x|≤C) : ProbabilityMeasure (WeightedRestorationRange f C) := + ⟨μ.map (fun x => (⟨A x,abs_le.mp (hb x)⟩,Z x)), + (Measure.isProbabilityMeasure_map_iff ((hA.subtype_mk).prodMk hZ).aemeasurable).2 inferInstance⟩ + +lemma compactWeightedLaw_integral {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsProbabilityMeasure μ] (f : ℝ →ᵇ ℝ) (C : ℝ) + (A : Ω→ℝ) (hA : Measurable A) (Z : Ω→RestorationRange f) (hZ : Measurable Z) + (hb : ∀ x, |A x|≤C) (J : WeightedRestorationRange f C → ℝ) (hJ : Measurable J) : + (∫ x, J x ∂(compactWeightedLaw μ f C A hA Z hZ hb : Measure _))= + ∫ x, J (⟨A x,abs_le.mp (hb x)⟩,Z x) ∂μ := + integral_map ((hA.subtype_mk).prodMk hZ).aemeasurable hJ.aestronglyMeasurable + +lemma compactWeighted_witness {Ω : ℕ→Type*} [∀ n, MeasurableSpace (Ω n)] + (μ : (n : ℕ)→Measure (Ω n)) [∀ n, IsProbabilityMeasure (μ n)] + (f : ℝ →ᵇ ℝ) (C : ℝ) (A : (n : ℕ)→Ω n→ℝ) (Z : (n : ℕ)→Ω n→RestorationRange f) + (hA : ∀ n, Measurable (A n)) (hZ : ∀ n, Measurable (Z n)) (hb : ∀ n x, |A n x|≤C) + (b : ℕ→ℝ) (hm : ∀ j, Tendsto (fun n => ∫ x, A n x*(Z n x).val^j ∂μ n) atTop (𝓝 (b j))) + (J : C(RestorationRange f,ℝ)) (L : ℝ) + (hL : Tendsto (fun n => ∫ x, A n x*J (Z n x) ∂μ n) atTop (𝓝 L)) : + ∃ η : ProbabilityMeasure (WeightedRestorationRange f C), + (∀ j, (∫ x, x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange f C)))=b j) ∧ + (∫ x, x.1.val*J x.2 ∂(η : Measure (WeightedRestorationRange f C)))=L := by + let ν n := compactWeightedLaw (μ n) f C (A n) (hA n) (Z n) (hZ n) (hb n) + obtain ⟨η,-,s,hs,hlim⟩ := isCompact_univ.isSeqCompact (fun n => mem_univ (ν n)) + have ht (G : C(WeightedRestorationRange f C,ℝ)) : + Tendsto (fun n => ∫ x, G x ∂(ν (s n) : Measure (WeightedRestorationRange f C))) atTop (𝓝 (∫ x, G x ∂(η : Measure (WeightedRestorationRange f C)))) := by + exact (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (BoundedContinuousFunction.mkOfCompact G)).continuousAt.tendsto.comp hlim + refine ⟨η,?_,?_⟩ + · intro j + let G : C(WeightedRestorationRange f C,ℝ) := ⟨fun x => x.1.val*x.2.val^j,by fun_prop⟩ + have hh := ht G + simp only [ν,compactWeightedLaw_integral _ _ _ _ _ _ _ _ _ G.continuous.measurable] at hh + exact tendsto_nhds_unique hh ((hm j).comp hs.tendsto_atTop) + · let G : C(WeightedRestorationRange f C,ℝ) := ⟨fun x => x.1.val*J x.2, + (continuous_subtype_val.comp continuous_fst).mul (J.continuous.comp continuous_snd)⟩ + have hh := ht G + simp only [ν,compactWeightedLaw_integral _ _ _ _ _ _ _ _ _ G.continuous.measurable] at hh + exact tendsto_nhds_unique hh (hL.comp hs.tendsto_atTop) + +def pairRestorationBound (f v w : ℝ →ᵇ ℝ) (F : CompactOverlap →ᵇ ℝ) : ℝ := + ‖F‖*(∏ _ : Fin 2, ‖expBCF 1 f*v‖)*(∏ _ : Fin 2, ‖expBCF 1 f*w‖) +lemma pairRestorationBound_nonneg (f v w : ℝ →ᵇ ℝ) (F : CompactOverlap →ᵇ ℝ) : + 0≤pairRestorationBound f v w F := by unfold pairRestorationBound; positivity + +lemma sourceLabelRestorationNumerator_pair_bound (n k : ℕ) (f ψ v w : ℝ →ᵇ ℝ) + (F : CompactOverlap →ᵇ ℝ) (q : Fin (k+1)→Time) (s : ℝ≥0) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (a) : + |sourceLabelRestorationNumerator n k 2 (fun i => (q i:ℝ)) s f ψ + (fun _ => v) (fun _ => w) (labelProfilePairTest q F) p e h u a|≤pairRestorationBound ψ v w F := by + apply (sourceLabelRestorationNumerator_bound n k 2 _ s f ψ (fun _ => v) (fun _ => w) + (labelProfilePairTest q F) p e h u a).trans + apply mul_le_mul_of_nonneg_right _ (Finset.prod_nonneg fun _ _ => norm_nonneg _) + apply mul_le_mul_of_nonneg_right _ (Finset.prod_nonneg fun _ _ => norm_nonneg _) + exact F.norm_compContinuous_le _ + +lemma sourceLabelPair_witness (k : ℕ) (q : Fin (k+1)→Time) (hq : Monotone q) + (f : ℝ →ᵇ ℝ) (g : Jet3) (v w : ℝ →ᵇ ℝ) (F : CompactOverlap →ᵇ ℝ) + (p e : (n : ℕ)→Fin (n+1)→ℕ) (h : ℕ→Fin (k+1)→ℝ) + (hh0 : ∀ n i,0≤h n i) (hh : ∀ n,Monotone (h n)) (u : (n : ℕ)→Fin (n+1)→ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0 sourceGibbsArrayLaw (s n) k f (p (s n)) (e (s n)) (h (s n)) + (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∃ η : ProbabilityMeasure (WeightedRestorationRange g.f (pairRestorationBound g.f v w F)), + (∀ j, (∫ x, x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v w F))))= + ∫ Q, labelRestorationBlockMoment (fun i => (q i:ℝ)) g.f (fun _ => v) (fun _ => w) + (labelProfilePairTest q F) j (compactBlock (2+j) Q) ∂ν) ∧ + (∫ x, x.1.val*restorationReciprocal g.f 2 x.2 ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v w F))))= + ∑ d, F (timeSpin (q d))*(twoVisitMass k z d).toReal* + (labelPairCoefficient k z (fun i => (q i:ℝ)) g (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) v d * + labelPairCoefficient k z (fun i => (q i:ℝ)) g (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) w d) := by + let τ : ℝ≥0 := ⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ + apply compactWeighted_witness + (fun n => ((sourceBaseDataLaw (s n) k z (t (s n))).prod countableGaussianLaw).prod (countableGaussianLaw.prod countableGaussianLaw)) + g.f (pairRestorationBound g.f v w F) + (fun n => sourceLabelRestorationNumerator (s n) k 2 (fun i => (q i:ℝ)) τ f g.f (fun _ => v) (fun _ => w) + (labelProfilePairTest q F) (p (s n)) (e (s n)) (h (s n)) (u (s n))) + (fun n => sourceLabelRestorationDenominator (s n) k (fun i => (q i:ℝ)) τ f g.f + (p (s n)) (e (s n)) (h (s n)) (u (s n))) + (fun n => sourceLabelRestorationNumerator_measurable ..) + (fun n => sourceLabelRestorationDenominator_measurable ..) + (fun n a => sourceLabelRestorationNumerator_pair_bound ..) _ ?_ (restorationReciprocal g.f 2) _ ?_ + · intro j + simp_rw [sourceLabelRestorationPolynomial _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (hh0 _) (hh _) j] + exact sourceLabelRestorationMoment_tendsto k 2 (fun i => (q i:ℝ)) (q 0).prop.1 + (fun i l hil => hq hil) (q (Fin.last k)).prop.2 f g.f (fun _ => v) (fun _ => w) + (labelProfilePairTest q F) p e h hh0 hh u z t s hlim j + · change Tendsto (fun n => sourceLabelRestorationRatio (s n) k 2 (fun i => (q i:ℝ)) τ f g.f + (fun _ => v) (fun _ => w) (labelProfilePairTest q F) (p (s n)) (e (s n)) (h (s n)) (u (s n)) z (t (s n))) atTop _ + simp_rw [sourceLabelRestorationRatio_pair_value _ k f g _ _ _ (hh0 _) (hh _) _ q τ v w F z hz hz0 hz1] + exact tendsto_const_nhds + +lemma labelPairCoefficient_one (k : ℕ) (z : Fin k→ℝ) (hz0 : ∀ i,0 labelProfileTerminal g s (x 0)) + ((labelProfileTerminal_lipschitz g s).continuous.measurable.comp (measurable_pi_apply 0)) hI.2 i + simp only [labelPairCoefficient,labelResidualObservable,residualResponse_one] + exact rootPathCorrelation_one _ _ k _ hκ d + +def labelSingleCoefficient (k : ℕ) (z : Fin k→ℝ) (q : Fin (k+1)→ℝ) + (g : Jet3) (s : ℝ≥0) (v : ℝ →ᵇ ℝ) : ℝ := + rootPathMean (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (fun r => fun _ => labelGaussianRoot q r) k + (fun i => tiltedStateStep (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin 1))) + (gaussianLinearMarkStep (labelGaussianStep q)) (z i) + (finiteCascadeShifts (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin 1))) + (gaussianLinearMarkStep (labelGaussianStep q)) k z (fun x => labelProfileTerminal g s (x 0)) i)) + (fun x => labelResidualObservable s g.f v (x 0)) + +lemma labelPairCoefficient_bounds (k : ℕ) (z : Fin k→ℝ) (hz0 : ∀ i,0 labelProfileTerminal g s (x 0)) + ((labelProfileTerminal_lipschitz g s).continuous.measurable.comp (measurable_pi_apply 0)) hI.2 i + exact residual_path_pair_coefficients (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (fun r => fun _ => labelGaussianRoot q r) (by fun_prop) k _ hκ + (fun x => labelEvaluation (x 0)) (by unfold labelEvaluation; fun_prop) s g.f v + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CompactScalarGG.lean b/lean/OAI/Probability/Perceptron/Variational/CompactScalarGG.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e18da5291a0df6f274ee4583430e3b29653b4dc --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CompactScalarGG.lean @@ -0,0 +1,80 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CompactGGDensity + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def compactScalarMonomial (p : ℕ) : CompactOverlap →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x : CompactOverlap => (x:ℝ)^p,by fun_prop⟩ + +@[simp] lemma compactScalarMonomial_apply (p : ℕ) (x : CompactOverlap) : + compactScalarMonomial p x = (x:ℝ)^p := rfl + +lemma compactScalarMonomial_add (p q : ℕ) : + compactScalarMonomial (p+q)=compactScalarMonomial p*compactScalarMonomial q := by + ext x + simp only [compactScalarMonomial_apply,BoundedContinuousFunction.mul_apply,pow_add] + +lemma compactScalar_monomials_total (L : (CompactOverlap →ᵇ ℝ) →L[ℝ] ℝ) + (hL : ∀ p, L (compactScalarMonomial p)=0) : L=0 := by + let e := ContinuousMap.linearIsometryBoundedOfCompact CompactOverlap ℝ ℝ + let L' := L.comp e.toContinuousLinearEquiv.toContinuousLinearMap + let m (a : ℕ) : C(CompactOverlap,ℝ) := (compactScalarMonomial a).toContinuousMap + have hm0 : m 0=1 := by ext x; simp [m,compactScalarMonomial_apply] + have hmadd (a b : ℕ) : m (a+b)=m a*m b := by + ext x + exact congrArg (fun f : CompactOverlap →ᵇ ℝ => f x) (compactScalarMonomial_add _ _) + let M : Submonoid C(CompactOverlap,ℝ) := + { carrier := Set.range m + one_mem' := ⟨0,hm0⟩ + mul_mem' := by rintro _ _ ⟨a,rfl⟩ ⟨b,rfl⟩; exact ⟨a+b,hmadd a b⟩ } + let A := Algebra.adjoin ℝ (M : Set C(CompactOverlap,ℝ)) + have hsep : A.SeparatesPoints := by + intro x y hxy + have hpd : compactScalarMonomial 1 x ≠ compactScalarMonomial 1 y := by + simpa only [compactScalarMonomial_apply,pow_one] using (Subtype.val_injective.ne hxy) + have hmem : m 1 ∈ A := + Algebra.subset_adjoin (show m 1 ∈ M from ⟨1,rfl⟩) + exact ⟨m 1,⟨m 1,hmem,rfl⟩,hpd⟩ + have hA : (A : Set C(CompactOverlap,ℝ)) ⊆ (L'.ker : Set C(CompactOverlap,ℝ)) := by + have hspan : Submodule.span ℝ (M : Set C(CompactOverlap,ℝ)) ≤ L'.ker := by + apply Submodule.span_le.mpr + rintro _ ⟨p,rfl⟩ + change L (e ((compactScalarMonomial p).toContinuousMap)) = 0 + have he : e ((compactScalarMonomial p).toContinuousMap) = compactScalarMonomial p := by + ext x; rfl + rw [he] + exact hL p + intro f hf + apply hspan + change f ∈ A.toSubmodule at hf + simpa only [A,Algebra.adjoin_eq_span,Submonoid.closure_eq] using hf + have hclosed := L'.isClosed_ker + have hc := closure_minimal hA hclosed + have htop := ContinuousMap.subalgebra_topologicalClosure_eq_top_of_separatesPoints A hsep + have hall (f : C(CompactOverlap,ℝ)) : L' f=0 := by + apply hc + change f ∈ A.topologicalClosure + rw [htop] + trivial + ext g + have h := hall (e.symm g) + simpa [L'] using h + +lemma compactGG_of_scalar_monomials (μ : ProbabilityMeasure (CompactArray CompactOverlap)) + (n : ℕ) (i : Fin n) (f : CompactBlock CompactOverlap n →ᵇ ℝ) + (h : ∀ p, compactGGDefect μ n i f (compactScalarMonomial p)=0) + (g : CompactOverlap →ᵇ ℝ) : compactGGDefect μ n i f g=0 := by + have hz := compactScalar_monomials_total (compactGGTestCLM μ n i f) + (fun p => (compactGGTestCLM_apply μ n i f _).trans (h p)) + rw [← compactGGTestCLM_apply,hz] + rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CompactTripleGG.lean b/lean/OAI/Probability/Perceptron/Variational/CompactTripleGG.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e8f366c8018833e465ed2b0e67740ef6b97acdd --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CompactTripleGG.lean @@ -0,0 +1,181 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereKernel +import OAI.Probability.Perceptron.Variational.CovarianceMatrix + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set TopologicalSpace +open scoped BigOperators Topology BoundedContinuousFunction NNReal ContDiff + +lemma compact_two_edge_law {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [MetrizableSpace K] [SecondCountableTopology K] + (μ : ProbabilityMeasure (CompactArray K)) + (hGG : ∀ (F : CompactBlock K 2→ᵇℝ) (g : K→ᵇℝ),compactGGDefect μ 2 0 F g=0) : + (μ : Measure (CompactArray K)).map (fun Q=>(Q 0 1,Q 0 2))= + (1/2:ℝ≥0) • (((μ : Measure (CompactArray K)).map (fun Q=>Q 0 1)).prod + ((μ : Measure (CompactArray K)).map (fun Q=>Q 0 1)))+ + (1/2:ℝ≥0) • ((μ : Measure (CompactArray K)).map (fun Q=>(Q 0 1,Q 0 1))) := by + have h := compactGG_joint_law μ (n:=2) (by norm_num) 0 hGG + have hm : Measurable (fun p : CompactBlock K 2×K=>(p.1 0 1,p.2)) := by fun_prop + have he := congrArg (Measure.map (fun p : CompactBlock K 2×K=>(p.1 0 1,p.2))) h + simp only [Finset.univ_fin2,Finset.erase_insert,Finset.mem_singleton,Fin.zero_ne_one,not_false_eq_true, + Finset.sum_singleton] at he + rw [Measure.map_map hm ((compactBlock_continuous 2).measurable.prodMk (by fun_prop)),Measure.map_smul _ hm.aemeasurable,Measure.map_add _ _ hm,Measure.map_map hm ((compactBlock_continuous 2).measurable.prodMk (by fun_prop))] at he + have hp : Measure.map (fun p : CompactBlock K 2×K=>(p.1 0 1,p.2)) + (((μ : Measure (CompactArray K)).map (compactBlock 2)).prod + ((μ : Measure (CompactArray K)).map (fun Q=>Q 0 1)))= + ((μ : Measure (CompactArray K)).map (fun Q=>Q 0 1)).prod + ((μ : Measure (CompactArray K)).map (fun Q=>Q 0 1)) := by + change Measure.map (Prod.map (fun A : CompactBlock K 2 => A 0 1) id) _ = _ + rw [←Measure.map_prod_map _ _ (by fun_prop) measurable_id,Measure.map_id] + rw [Measure.map_map (by fun_prop) (compactBlock_continuous 2).measurable] + rfl + rw [hp] at he + simpa [one_div,smul_add,compactBlock,Function.comp_def] using he + +lemma ultrametric_tangent_algebra {r s t : ℝ} (h : UltrametricTriangle r s t) + (a : ℝ→ℝ) : + a s*t=r*a s-max (r-s) 0*a s+a r*max (t-r) 0 := by + rcases lt_trichotomy s r with hs|hs|hs + · have ht : t=s := by + have h' : UltrametricTriangle s r t := ⟨by simpa [min_comm] using h.1,h.2.2,h.2.1⟩ + exact ultrametric_triangle_small_eq h' hs + subst t + rw [max_eq_left (by linarith : 0≤r-s),max_eq_right (by linarith : s-r≤0)] + ring + · subst s + have hr : r≤t := by simpa using h.1 + rw [sub_self,max_self,max_eq_left (by linarith : 0≤t-r)] + ring + · have ht := ultrametric_triangle_small_eq h hs + subst t + rw [max_eq_right (by linarith : r-s≤0),sub_self,max_self] + ring + +lemma boundedAbs_integrable {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) + [IsFiniteMeasure P] (f : Ω→ℝ) (hf : Measurable f) (C : ℝ) (hb : ∀ x,|f x|≤C) : + Integrable f P := Integrable.of_bound hf.aestronglyMeasurable C + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hb x) + +lemma two_edge_integral {Ω K : Type*} [MeasurableSpace Ω] [MeasurableSpace K] + (P : Measure Ω) [IsProbabilityMeasure P] (ν : Measure K) [IsProbabilityMeasure ν] + (r s : Ω→K) (hr : Measurable r) (hs : Measurable s) + (hlaw : P.map (fun x=>(r x,s x))=(1/2:ℝ≥0) • (ν.prod ν)+(1/2:ℝ≥0) • (ν.map fun x=>(x,x))) + (H : K×K→ℝ) (hH : Measurable H) (C : ℝ) (hb : ∀ x,|H x|≤C) : + (∫ x,H (r x,s x) ∂P)=(1/2:ℝ)*((∫ x,∫ y,H (x,y) ∂ν ∂ν)+(∫ x,H (x,x) ∂ν)) := by + have hi : Integrable H (ν.prod ν) := boundedAbs_integrable _ _ hH C hb + have hd : Integrable H (ν.map fun x=>(x,x)) := boundedAbs_integrable _ _ hH C hb + rw [←integral_map (hr.prodMk hs).aemeasurable hH.aestronglyMeasurable,hlaw, + integral_add_measure (hi.smul_measure_nnreal) (hd.smul_measure_nnreal), + integral_smul_nnreal_measure,integral_smul_nnreal_measure, + integral_map (show Measurable (fun x : K=>(x,x)) from measurable_id.prodMk measurable_id).aemeasurable hH.aestronglyMeasurable, + integral_prod _ hi] + simp only [NNReal.smul_def,NNReal.coe_div,NNReal.coe_one,NNReal.coe_ofNat,smul_eq_mul] + ring + +lemma time_abs_le_one (r : Time) : |(r:ℝ)|≤1 := by + rw [abs_of_nonneg r.property.1] + exact r.property.2 + +lemma sphereKernel_abs_le_one (r s : Time) : |sphereKernel r s|≤1 := by + rw [abs_of_nonneg (sphereKernel_nonneg r s)] + unfold sphereKernel + have := min_le_left (r:ℝ) (s:ℝ) + have := mul_nonneg r.property.1 s.property.1 + linarith [r.property.2] + +lemma time_pospart_le_one (r s : Time) : |max ((s:ℝ)-r) 0|≤1 := by + rw [abs_of_nonneg (le_max_right _ _),max_le_iff] + exact ⟨by linarith [s.property.2,r.property.1],by norm_num⟩ + +lemma sphereKernel_tangent_algebra (r s t : Time) + (h : UltrametricTriangle (r:ℝ) (s:ℝ) (t:ℝ)) (a : Time→ℝ) : + a s*((t:ℝ)-(r:ℝ)*s)=sphereKernel r s*a s+a r*max ((t:ℝ)-r) 0 := by + let A : ℝ→ℝ := fun x=>a (Set.projIcc 0 1 zero_le_one x) + have he := ultrametric_tangent_algebra h A + simp only [A,Set.projIcc_of_mem zero_le_one r.property,Set.projIcc_of_mem zero_le_one s.property, + Subtype.coe_eta] at he + have hm : (r:ℝ)-max ((r:ℝ)-s) 0=min (r:ℝ) (s:ℝ) := by + rcases le_total (r:ℝ) (s:ℝ) with h|h + · rw [max_eq_right (sub_nonpos.mpr h),min_eq_left h,sub_zero] + · rw [max_eq_left (sub_nonneg.mpr h),min_eq_right h]; ring + unfold sphereKernel + rw [←hm] + nlinarith only [he] + +lemma sphereTail_pospart (ν : Measure Time) [IsProbabilityMeasure ν] (r : Time) : + sphereTail ν r=1-(r:ℝ)-(∫ s,max ((s:ℝ)-r) 0 ∂ν) := by + have hi := boundedAbs_integrable ν (fun s : Time=>max ((s:ℝ)-r) 0) (by fun_prop) 1 (time_pospart_le_one r) + have he (s : Time) : 1-max (r:ℝ) (s:ℝ)=1-(r:ℝ)-max ((s:ℝ)-r) 0 := by + rcases le_total (r:ℝ) (s:ℝ) with h|h + · rw [max_eq_right h,max_eq_left (sub_nonneg.mpr h)]; ring + · rw [max_eq_left h,max_eq_right (sub_nonpos.mpr h),sub_zero] + simp_rw [sphereTail,he] + rw [integral_sub (integrable_const _) hi,integral_const] + simp + +lemma compact_test_smooth_approx {a b : ℝ} (hab : a≤b) (F : Icc a b→ᵇℝ) + {ε : ℝ} (hε : 0<ε) : + ∃ G : ℝ→ᵇℝ, ContDiff ℝ ∞ (G : ℝ→ℝ) ∧ ∀ r : Icc a b,|G r.val-F r|≤ε := by + let f : ℝ→ℝ := fun x=>F (Set.projIcc a b hab x) + have hu : UniformContinuous f := + (CompactSpace.uniformContinuous_of_continuous F.continuous).comp (LipschitzWith.projIcc hab).uniformContinuous + obtain ⟨g,hg,hgb⟩ := hu.exists_contDiff_dist_le hε + have hb (x : ℝ) : |g x|≤ε+‖F‖ := by + have he := (hgb x).le + rw [Real.dist_eq] at he + have := F.norm_coe_le_norm (Set.projIcc a b hab x) + change |f x|≤‖F‖ at this + calc + |g x|=|g x-f x+f x| := by rw [sub_add_cancel] + _ ≤ |g x-f x|+|f x| := abs_add_le _ _ + _ ≤ ε+‖F‖ := add_le_add he this + let G : ℝ→ᵇℝ := BoundedContinuousFunction.mkOfBound ⟨g,hg.continuous⟩ (2*(ε+‖F‖)) (by + intro x y + change dist (g x) (g y)≤_ + rw [Real.dist_eq] + exact (abs_sub _ _).trans (by linarith [hb x,hb y])) + refine ⟨G,hg,fun r => ?_⟩ + change |g r.val-F r|≤ε + have he := (hgb r.val).le + simpa only [Real.dist_eq,f,Set.projIcc_of_mem hab r.property,Subtype.coe_eta] using he + +lemma smooth_compact_test_extend {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {a b : ℝ} (hab : a≤b) + (p : Ω→Icc a b) (hp : Measurable p) (Z : Ω→ℝ) (hZ : Measurable Z) + {C : ℝ} (hC : 0≤C) (hb : ∀ x,|Z x|≤C) + (hz : ∀ G : ℝ→ᵇℝ,ContDiff ℝ 1 (G : ℝ→ℝ)→(∫ x,G (p x).val*Z x ∂P)=0) + (F : Icc a b→ᵇℝ) : (∫ x,F (p x)*Z x ∂P)=0 := by + have hFi : Integrable (fun x=>F (p x)*Z x) P := + Integrable.of_bound ((F.measurable.comp hp).mul hZ).aestronglyMeasurable (‖F‖*C) + (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul (F.norm_coe_le_norm _) (hb _) (abs_nonneg _) (norm_nonneg F)) + apply abs_nonpos_iff.mp + apply le_of_forall_pos_le_add + intro ε hε + let δ := ε/(C+1) + have hδ : 0<δ := div_pos hε (by linarith) + obtain ⟨G,hG,hGF⟩ := compact_test_smooth_approx hab F hδ + have hGi : Integrable (fun x=>G (p x).val*Z x) P := + Integrable.of_bound ((G.measurable.comp (measurable_subtype_coe.comp hp)).mul hZ).aestronglyMeasurable (‖G‖*C) + (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul (G.norm_coe_le_norm _) (hb _) (abs_nonneg _) (norm_nonneg G)) + have he : (∫ x,F (p x)*Z x ∂P)=(∫ x,(F (p x)-G (p x).val)*Z x ∂P) := by + simp_rw [sub_mul] + rw [integral_sub hFi hGi,hz G (hG.of_le (by norm_num)),sub_zero] + rw [he] + have hb' : ∀ x,‖(F (p x)-G (p x).val)*Z x‖≤δ*C := by + intro x + rw [Real.norm_eq_abs,abs_mul,abs_sub_comm] + exact mul_le_mul (hGF _) (hb _) (abs_nonneg _) hδ.le + have hi := norm_integral_le_of_norm_le_const (ae_of_all P hb') + simp [Real.norm_eq_abs,Measure.real] at hi + have hd : δ*(C+1)=ε := div_mul_cancel₀ ε (by linarith) + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/Contact.lean b/lean/OAI/Probability/Perceptron/Variational/Contact.lean new file mode 100644 index 0000000000000000000000000000000000000000..38dc785a50c716b4f62bb2aebeb8b792e5025949 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/Contact.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CouplingKernel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev sourceFullSpinLeafKernel (n k : ℕ) : Kernel (SourceBaseData n k × (ℕ → ℝ)) + (NormalizedSpin (n+1) × IndexedLeaf k) := + (sourceSpinLeafKernel n k).comap Prod.fst measurable_fst + +def sourceCouplingMean (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (r : ℝ) + (a : SourceBaseData n k × (ℕ → ℝ)) : ℝ := + (1/(n+1:ℕ))*tiltMean (sourceSpinLeafKernel n k a.1) + (fun x => sourceCouplingHamiltonian n k f p d h u a x+r*sourceCouplingEnergy n k p d h j a x) + (sourceCouplingEnergy n k p d h j a) 1 + +def sourceCouplingThermal (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (r : ℝ) + (a : SourceBaseData n k × (ℕ → ℝ)) : ℝ := + let H := fun x => sourceCouplingHamiltonian n k f p d h u a x+r*sourceCouplingEnergy n k p d h j a x + let Y := sourceCouplingEnergy n k p d h j a + Real.sqrt (1/(n+1:ℕ))*tiltMean (sourceSpinLeafKernel n k a.1) H + (fun x => |Y x-tiltMean (sourceSpinLeafKernel n k a.1) H Y 1|) 1 + +def sourceCouplingVariance (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (r : ℝ) + (a : SourceBaseData n k × (ℕ → ℝ)) : ℝ := + let H := fun x => sourceCouplingHamiltonian n k f p d h u a x+r*sourceCouplingEnergy n k p d h j a x + let Y := sourceCouplingEnergy n k p d h j a + (1/(n+1:ℕ))*tiltMean (sourceSpinLeafKernel n k a.1) H + (fun x => (Y x-tiltMean (sourceSpinLeafKernel n k a.1) H Y 1)^2) 1 + +lemma sourceCoupling_observables_measurable (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (r : ℝ) : + Measurable (sourceCouplingMean n k f p d h u j r) ∧ + Measurable (sourceCouplingThermal n k f p d h u j r) ∧ + Measurable (sourceCouplingVariance n k f p d h u j r) := by + have hY := sourceCouplingEnergy_measurable n k p d h j + have hH : Measurable (Function.uncurry (fun a x => + sourceCouplingHamiltonian n k f p d h u a x+r*sourceCouplingEnergy n k p d h j a x)) := + (sourceCouplingHamiltonian_measurable n k f p d h u).add (hY.const_mul r) + exact ⟨(kernel_tiltMean_measurable (sourceFullSpinLeafKernel n k) hH hY).const_mul _, + (kernel_tiltCenteredAbs_measurable (sourceFullSpinLeafKernel n k) hH hY).const_mul _, + (kernel_tiltCenteredVariance_measurable (sourceFullSpinLeafKernel n k) hH hY).const_mul _⟩ + +lemma sourceCoupling_thermal_bound_ae (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (z : Fin k → ℝ) (t : ℝ≥0) (r : ℝ) : + ∀ᵐ a ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw, + 0 ≤ sourceCouplingThermal n k f p d h u j r a ∧ + (sourceCouplingThermal n k f p d h u j r a)^2 ≤ sourceCouplingVariance n k f p d h u j r a := by + filter_upwards [sourceCoupling_all_exp_ae n k f p d h hh0 hh u j z t] with a ha + have hH : Measurable (sourceCouplingHamiltonian n k f p d h u a) := + sourceCouplingHamiltonian_section n k f p d h u a + have hY : Measurable (sourceCouplingEnergy n k p d h j a) := + sourceCouplingEnergy_section n k p d h j a + constructor + · exact mul_nonneg (Real.sqrt_nonneg _) (tiltMean_nonneg _ (fun _ => abs_nonneg _) 1) + · unfold sourceCouplingThermal sourceCouplingVariance + rw [mul_pow,Real.sq_sqrt (by positivity)] + exact mul_le_mul_of_nonneg_left (coupling_thermal_abs_sq_le _ hH hY ha r) (by positivity) + +lemma source_contact_thermal_disorder (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 c*(r-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j r) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) 0) + (hp : c*(0-a)^2-(∫ b, sourceKernelPressure n k f p d u h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) ≤ c*(s-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j s) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (hm : c*(0-a)^2-(∫ b, sourceKernelPressure n k f p d u h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) ≤ c*(-s-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j (-s)) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) : + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + let D := sourceCouplingMean n k f p d h u j 0 + let U := sourceCouplingThermal n k f p d h u j 0 + MemLp U 2 P ∧ Integrable D P ∧ (∫ b, U b ∂P) ≤ Real.sqrt (2*c) ∧ + (∫ b, |D b-∫ b', D b' ∂P| ∂P) ≤ + c*s+4*Real.sqrt (enrichedVarianceConstant k z f H T/(n+1:ℕ))/s := by + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + have hreg := sourceCoupling_regular_ae n k f p d h hh0 hh u j z t + have htherm := sourceCoupling_thermal_bound_ae n k f p d h hh0 hh u j z t 0 + have hmeas := sourceCoupling_observables_measurable n k f p d h u j + apply quadratic_contact_thermal_disorder_separate P + (F := fun r => sourceKernelPressure n k f p d (u+Pi.single j r) h) + (D := sourceCouplingMean n k f p d h u j) + (u := 0) (a := a) (c := c) (s := s) + (V := enrichedVarianceConstant k z f H T/(n+1:ℕ)) + (J := sourceCouplingVariance n k f p d h u j 0) (U := sourceCouplingThermal n k f p d h u j 0) + · intro r + have hr := sourceKernelPressure_memLp n k f p d (u+Pi.single j r) h z hz hz0 hz1 t + exact hr + · exact fun r => (hmeas r).1.aestronglyMeasurable + · exact (hmeas 0).2.2.aestronglyMeasurable + · exact (hmeas 0).2.1.aestronglyMeasurable + · exact htherm.mono fun _ h => h.1 + · exact htherm.mono fun _ h => h.2 + · exact hreg.mono fun _ h => ⟨h.1,h.2.1,h.2.2.1⟩ + · exact hs + · exact hreg.mono fun _ h => h.2.2.2 0 + · exact hmin + · simpa only [zero_add,Pi.single_zero,add_zero] using hp + · simpa only [zero_sub,Pi.single_zero,add_zero] using hm + · have hv := sourceKernelPressure_variance n k f p d (u+Pi.single j s) h z hz hz0 hz1 hup hH hhH t ht + simpa only [zero_add] using hv + · have hv := sourceKernelPressure_variance n k f p d u h z hz hz0 hz1 hu hH hhH t ht + simpa only [Pi.single_zero,add_zero] using hv + · have hv := sourceKernelPressure_variance n k f p d (u+Pi.single j (-s)) h z hz hz0 hz1 hum hH hhH t ht + simpa only [zero_sub] using hv + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ContactDensity.lean b/lean/OAI/Probability/Perceptron/Variational/ContactDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..9985f3022830da4391d3247fdc9265c747f6b67c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ContactDensity.lean @@ -0,0 +1,49 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GlobalContact + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma source_global_contact_density (n k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0 (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) a) (ht : 0 (hw i).le) hw1)+δ ≤ + sourceDensityIncrement n k f p d a.2.1 (stepCumulative w) a.2.2 a.1 := by + let V := controlValue P f (weightedStepTrial w q (fun i => (hw i).le) hw1)+δ + let F : ℝ → ℝ := fun s => -sourceExpectedPressure n k f p d a.2.1 (stepCumulative w) + s.toNNReal a.2.2+s*V + have hm : IsMinOn F (Icc 0 (a.1:ℝ)) a.1 := by + intro s hs + have hs' : s.toNNReal ≤ α := (Real.toNNReal_le_toNNReal hs.2).trans (by simpa using ha.1.2) + have he := hmin (show (s.toNNReal,a.2.1,a.2.2)∈sourceContactCompactDomain n k α H from + ⟨⟨zero_le,hs'⟩,ha.2⟩) + simp only [mem_ofPred_eq,sourceStepContactObjective,sourceJointPressure] at he + rw [Real.coe_toNNReal _ hs.1] at he + change F (a.1:ℝ) ≤ F s + dsimp [F,V] + simp only [Real.toNNReal_coe] + linarith + have hd : HasDerivAt F (-sourceDensityIncrement n k f p d a.2.1 (stepCumulative w) a.2.2 a.1+V) a.1 := by + convert + (sourceExpectedPressure_density_derivative n k f p d a.2.1 (stepCumulative w) a.2.2 + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1) + a.1 ht).neg.add ((hasDerivAt_id (a.1:ℝ)).mul_const V) using 1 <;> first | rfl | simp + have hseg : segment ℝ (a.1:ℝ) 0 ⊆ Icc 0 (a.1:ℝ) := by + rw [segment_symm,segment_eq_Icc a.1.coe_nonneg] + have hn := hm.isLocalMinOn.hasFDerivWithinAt_nonneg hd.hasFDerivAt.hasFDerivWithinAt + (sub_mem_posTangentConeAt_of_segment_subset hseg) + change 0 ≤ (0-(a.1:ℝ))*(-sourceDensityIncrement n k f p d a.2.1 (stepCumulative w) a.2.2 a.1+V) at hn + change V ≤ _ + nlinarith [show (0:ℝ)<(a.1:ℝ) from ht] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ContactFatou.lean b/lean/OAI/Probability/Perceptron/Variational/ContactFatou.lean new file mode 100644 index 0000000000000000000000000000000000000000..eb4765b308b06dd85ea23b818118e286deec2de2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ContactFatou.lean @@ -0,0 +1,187 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.QuadraticContactRemainders +import OAI.Probability.Perceptron.Variational.IntegrableGibbs + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +lemma nonnegative_limit_integral_bound {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) + {F : ℕ → Ω → ℝ} {f : Ω → ℝ} {C : ℝ} (hm : AEStronglyMeasurable f P) + (hF : ∀ n, Integrable (F n) P) (hF0 : ∀ n, 0 ≤ᵐ[P] F n) (hf0 : 0 ≤ᵐ[P] f) + (ht : ∀ᵐ ω ∂P, Tendsto (fun n => F n ω) atTop (nhds (f ω))) + (hb : ∀ᶠ n in atTop, (∫ ω, F n ω ∂P) ≤ C) : + Integrable f P ∧ (∫ ω, f ω ∂P) ≤ C := by + have hle : (∫⁻ ω, ENNReal.ofReal (f ω) ∂P) ≤ ENNReal.ofReal C := by + calc + _ = ∫⁻ ω, liminf (fun n => ENNReal.ofReal (F n ω)) atTop ∂P := by + apply lintegral_congr_ae + filter_upwards [ht] with ω hω + exact (ENNReal.continuous_ofReal.continuousAt.tendsto.comp hω).liminf_eq.symm + _ ≤ liminf (fun n => ∫⁻ ω, ENNReal.ofReal (F n ω) ∂P) atTop := + lintegral_liminf_le' (fun n => (hF n).aestronglyMeasurable.aemeasurable.ennreal_ofReal) + _ ≤ ENNReal.ofReal C := by + apply liminf_le_of_frequently_le' + apply Eventually.frequently + filter_upwards [hb] with n hn + rw [← ofReal_integral_eq_lintegral_ofReal (hF n) (hF0 n)] + exact ENNReal.ofReal_le_ofReal hn + have hi : Integrable f P := ⟨hm,(hasFiniteIntegral_iff_ofReal hf0).mpr (hle.trans_lt ENNReal.ofReal_lt_top)⟩ + refine ⟨hi,?_⟩ + have hC : 0 ≤ C := by + obtain ⟨n,hn⟩ := hb.exists + exact (integral_nonneg_of_ae (hF0 n)).trans hn + rw [← ofReal_integral_eq_lintegral_ofReal hi hf0] at hle + exact (ENNReal.ofReal_le_ofReal_iff hC).mp hle + +lemma taylor_two_explicit (F : ℝ → ℝ) (u v : ℝ) : + taylorWithinEval F 2 univ u v = F u+(v-u)*deriv F u+(v-u)^2/2*iteratedDeriv 2 F u := by + rw [taylorWithinEval_succ F 1,taylorWithinEval_succ F 0,taylor_within_zero_eval] + simp only [iteratedDerivWithin_univ,iteratedDeriv_one,Nat.cast_zero,Nat.factorial_zero, + Nat.cast_one,zero_add,one_mul,inv_one,pow_one,smul_eq_mul,Nat.factorial_one] + ring + +lemma second_symmetric_quotient_tendsto {F : ℝ → ℝ} (hc : ContDiff ℝ 2 F) (u : ℝ) + {s : ℕ → ℝ} (hs : ∀ n, s n ≠ 0) (hst : Tendsto s atTop (nhds 0)) : + Tendsto (fun n => (F (u+s n)+F (u-s n)-2*F u)/(s n)^2) + atTop (nhds (iteratedDeriv 2 F u)) := by + have he := (taylor_isLittleO_univ (x₀ := u) hc).tendsto_div_nhds_zero + have hup : Tendsto (fun n => u+s n) atTop (nhds u) := by simpa using tendsto_const_nhds.add hst + have hum : Tendsto (fun n => u-s n) atTop (nhds u) := by simpa using tendsto_const_nhds.sub hst + have hp := he.comp hup + have hm := he.comp hum + have hp' : Tendsto (fun n => + (F (u+s n)-(F u+s n*deriv F u+(s n)^2/2*iteratedDeriv 2 F u))/(s n)^2) + atTop (nhds (0:ℝ)) := by + simpa only [Function.comp_def,taylor_two_explicit,add_sub_cancel_left,add_zero] using hp + have hm' : Tendsto (fun n => + (F (u-s n)-(F u-s n*deriv F u+(s n)^2/2*iteratedDeriv 2 F u))/(s n)^2) + atTop (nhds (0:ℝ)) := by + convert hm using 1 + funext n + simp only [Function.comp_def,taylor_two_explicit,sub_sub_cancel_left,neg_sq,neg_mul] + ring + have h := (hp'.add hm').add_const (iteratedDeriv 2 F u) + simp only [zero_add] at h + apply h.congr + intro n + field_simp [hs n] + ring + +lemma convex_symmetric_quotient_nonneg {F : ℝ → ℝ} (hc : ConvexOn ℝ univ F) (u s : ℝ) : + 0 ≤ (F (u+s)+F (u-s)-2*F u)/s^2 := by + have hh := hc.2 (mem_univ (u+s)) (mem_univ (u-s)) + (by norm_num : (0:ℝ) ≤ 1/2) (by norm_num : (0:ℝ) ≤ 1/2) (by norm_num : (1:ℝ)/2+1/2=1) + simp only [smul_eq_mul] at hh + have he : (1:ℝ)/2*(u+s)+1/2*(u-s)=u := by ring + rw [he] at hh + exact div_nonneg (by linarith) (sq_nonneg _) + +lemma quadratic_contact_curvature_bound {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) + {F : ℝ → Ω → ℝ} {J : Ω → ℝ} (hJ : AEStronglyMeasurable J P) + (hi : ∀ t, Integrable (F t) P) + (hc : ∀ᵐ ω ∂P, ContDiff ℝ 2 (fun t => F t ω) ∧ ConvexOn ℝ univ (fun t => F t ω)) + {u a c : ℝ} (he : ∀ᵐ ω ∂P, iteratedDeriv 2 (fun t => F t ω) u = J ω) + (hmin : IsLocalMin (fun t => c*(t-a)^2-∫ ω, F t ω ∂P) u) : + Integrable J P ∧ (∫ ω, J ω ∂P) ≤ 2*c := by + let s : ℕ → ℝ := fun n => 1/(n+1:ℝ) + have hs (n) : 0 < s n := by dsimp [s]; positivity + have hst : Tendsto s atTop (nhds 0) := tendsto_one_div_add_atTop_nhds_zero_nat + let Q : ℕ → Ω → ℝ := fun n ω => (F (u+s n) ω+F (u-s n) ω-2*F u ω)/(s n)^2 + have hQi (n) : Integrable (Q n) P := + (((hi (u+s n)).add (hi (u-s n))).sub ((hi u).const_mul 2)).div_const _ + have hQ0 (n) : 0 ≤ᵐ[P] Q n := hc.mono fun ω hω => convex_symmetric_quotient_nonneg hω.2 u (s n) + have hQt : ∀ᵐ ω ∂P, Tendsto (fun n => Q n ω) atTop (nhds (J ω)) := by + filter_upwards [hc,he] with ω hω heω + rw [← heω] + exact second_symmetric_quotient_tendsto hω.1 u (fun n => (hs n).ne') hst + have hJ0 : 0 ≤ᵐ[P] J := by + filter_upwards [hQt,ae_all_iff.mpr hQ0] with ω hω h0 + exact ge_of_tendsto hω (Eventually.of_forall h0) + apply nonnegative_limit_integral_bound P hJ hQi hQ0 hJ0 hQt + have hup : Tendsto (fun n => u+s n) atTop (nhds u) := by simpa using tendsto_const_nhds.add hst + have hum : Tendsto (fun n => u-s n) atTop (nhds u) := by simpa using tendsto_const_nhds.sub hst + have hp := hup.eventually hmin + have hm := hum.eventually hmin + filter_upwards [hp,hm] with n hpn hmn + have hsum : Integrable (fun ω => F (u+s n) ω+F (u-s n) ω) P := (hi _).add (hi _) + have hmul : Integrable (fun ω => 2*F u ω) P := (hi u).const_mul 2 + rw [integral_div,integral_sub hsum hmul,integral_add (hi (u+s n)) (hi (u-s n)),integral_const_mul] + apply (div_le_iff₀ (sq_pos_of_pos (hs n))).mpr + nlinarith + +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) + +lemma coupling_weighted_power_integrable {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) (a : ℝ) (k : ℕ) : + Integrable (fun x => Real.exp (H x+a*Y x)*(Y x)^k) μ := by + have hi := ((he (a+1)).add (he (a-1))).const_mul (k.factorial:ℝ) + apply hi.mono' (((hH.add (hY.const_mul a)).exp).mul (hY.pow_const k)).aestronglyMeasurable + filter_upwards [] with x + change ‖Real.exp (H x+a*Y x)*(Y x)^k‖ ≤ (k.factorial:ℝ)*(Real.exp (H x+(a+1)*Y x)+Real.exp (H x+(a-1)*Y x)) + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _),abs_pow,mul_comm] + convert abs_pow_mul_exp_le (H x+a*Y x) (Y x) k using 1 + congr 2 <;> ring_nf + +variable [IsProbabilityMeasure μ] + +lemma coupling_tilt_memLp_two {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) (a : ℝ) : + MemLp Y 2 (tiltLaw μ (fun x => H x+a*Y x) 1) := by + apply (memLp_two_iff_integrable_sq hY.aestronglyMeasurable).mpr + have hp : 0 < tiltPartition μ (fun x => H x+a*Y x) 1 := + tilt_partition_pos_of_integrable μ (by simpa only [one_mul] using he a) + unfold tiltLaw + apply Integrable.smul_measure _ (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr hp)) + apply (integrable_withDensity_iff_integrable_smul' + ((hH.add (hY.const_mul a)).const_mul 1 |>.exp.ennreal_ofReal) + (ae_of_all _ fun _ => ENNReal.ofReal_lt_top)).mpr + simpa only [ENNReal.toReal_ofReal (Real.exp_pos _).le,smul_eq_mul,one_mul,Pi.add_apply] using + coupling_weighted_power_integrable μ hH hY he a 2 + +lemma coupling_thermal_abs_sq_le {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) (a : ℝ) : + (tiltMean μ (fun x => H x+a*Y x) + (fun x => |Y x-tiltMean μ (fun x => H x+a*Y x) Y 1|) 1)^2 ≤ + tiltMean μ (fun x => H x+a*Y x) + (fun x => (Y x-tiltMean μ (fun x => H x+a*Y x) Y 1)^2) 1 := by + let T := fun x => H x+a*Y x + have hT : Measurable T := hH.add (hY.const_mul a) + have hi : Integrable (fun x => Real.exp (1*T x)) μ := by simpa only [one_mul] using he a + let := tilt_law_probability_of_integrable μ hi + have hY2 := coupling_tilt_memLp_two μ hH hY he a + have hh := integral_centered_abs_le_sqrt_variance (tiltLaw μ T 1) hY2 + have hs := pow_le_pow_left₀ (integral_nonneg (fun x => abs_nonneg _)) hh 2 + rw [Real.sq_sqrt (variance_nonneg _ _),variance_eq_integral hY.aemeasurable] at hs + simpa only [tilt_law_integral_of_integrable μ hT hi] using hs + +lemma coupling_tilt_center_triangle {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) (a b c : ℝ) : + tiltMean μ (fun x => H x+a*Y x) (fun x => |Y x-c|) 1 ≤ + tiltMean μ (fun x => H x+a*Y x) (fun x => |Y x-b|) 1+|b-c| := by + let T := fun x => H x+a*Y x + have hT : Measurable T := hH.add (hY.const_mul a) + have hi : Integrable (fun x => Real.exp (1*T x)) μ := by simpa only [one_mul] using he a + let := tilt_law_probability_of_integrable μ hi + have hYi := (coupling_tilt_memLp_two μ hH hY he a).integrable (by norm_num) + change tiltMean μ T (fun x => |Y x-c|) 1 ≤ tiltMean μ T (fun x => |Y x-b|) 1+|b-c| + simp_rw [← tilt_law_integral_of_integrable μ hT hi] + have hc : (∫ _ : S, |b-c| ∂tiltLaw μ T 1)=|b-c| := by simp + have hib : Integrable (fun x => |Y x-b|) (tiltLaw μ T 1) := (hYi.sub (integrable_const b)).abs + rw [← hc,← integral_add hib (integrable_const _)] + apply integral_mono ((hYi.sub (integrable_const c)).abs) + (((hYi.sub (integrable_const b)).abs).add (integrable_const _)) + intro x + change |Y x-c| ≤ |Y x-b|+|b-c| + calc + _ = |(Y x-b)+(b-c)| := by congr 1; ring + _ ≤ _ := abs_add_le _ _ + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ContactGGRate.lean b/lean/OAI/Probability/Perceptron/Variational/ContactGGRate.lean new file mode 100644 index 0000000000000000000000000000000000000000..8d046ec7a686bbb820d6e46828ee5464cfe43521 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ContactGGRate.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.QuantitativeGG + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open Filter MeasureTheory ProbabilityTheory Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction Classical + +lemma contact_gg_rate_identity {x c C : ℝ} (hx : 0 1) j*perturbationAmplitude (n+1) u j = + (n+1:ℕ)^((7:ℝ)/8)*((2:ℝ)^(-((j.val+1:ℕ):ℤ)))^2*u j := by + have hn : (0:ℝ)<(n+1:ℕ) := by positivity + simp only [perturbationAmplitude,perturbationScale,Real.sqrt_eq_rpow,mul_one] + have he : ((1:ℝ)/2+(-(1:ℝ)/16))+((1:ℝ)/2+(-(1:ℝ)/16))=7/8 := by norm_num + rw [← he,Real.rpow_add hn,Real.rpow_add hn] + ring + +lemma contact_gg_rate_tendsto (c C B θ : ℝ) : + Tendsto (fun x : ℝ => B/(θ^2)*(Real.sqrt (2*c)*x^(-(3:ℝ)/8)+ + (c+4*Real.sqrt C)*x^(-(1:ℝ)/8))) atTop (𝓝 0) := by + have h3 := tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<3/8) + have h1 := tendsto_rpow_neg_atTop (by norm_num : (0:ℝ)<1/8) + convert ((h3.const_mul (Real.sqrt (2*c))).add (h1.const_mul (c+4*Real.sqrt C))).const_mul (B/(θ^2)) using 1 <;> norm_num + +lemma source_contact_joint_gg_rate (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 c*(r-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j r) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) 0) + (hp : c*(0-a)^2-(∫ b, sourceKernelPressure n k f p d u h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) ≤ c*(s-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j s) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (hm : c*(0-a)^2-(∫ b, sourceKernelPressure n k f p d u h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) ≤ c*(-s-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j (-s)) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (r : ℕ) (i : Fin r) {G : (Fin r → NormalizedSpin (n+1)×IndexedLeaf k) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) + (hc0 : 0≤c) (hsdef : s=(n+1:ℕ)^(-(1:ℝ)/4)) : + |kernelGGDefect (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) (sourceJointMonomial p d j) + (((k:ℝ)/(k+1:ℕ))^(d j)) r i G| ≤ + B/(((2:ℝ)^(-((j.val+1:ℕ):ℤ)))^2)* + (Real.sqrt (2*c)*(n+1:ℕ)^(-(3:ℝ)/8)+ + (c+4*Real.sqrt (enrichedVarianceConstant k z f H T))*(n+1:ℕ)^(-(1:ℝ)/8)) := by + have he := source_contact_joint_gg_error n k f p d h hh0 hh u j z hz hz0 hz1 t + hH hhH ht hs hu hup hum hmin hp hm r i hG hB hGB + rw [hsdef,perturbationAmplitude_product] at he + have hT : 0≤T := t.coe_nonneg.trans ht + have hC : 0≤enrichedVarianceConstant k z f H T := by + unfold enrichedVarianceConstant + positivity + have hrate := contact_gg_rate_bound (by positivity : (0:ℝ)<(n+1:ℕ)) hc0 hC hB + (by positivity : (0:ℝ)<(2:ℝ)^(-((j.val+1:ℕ):ℤ))) (hu j).1 + exact he.trans hrate + +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) [IsMarkovKernel κ] (H : A → S → ℝ) + +private def gibbsKernelDensity (a : A) (x : S) : ℝ≥0∞ := + if Integrable (fun y => Real.exp (H a y)) (κ a) then + (ENNReal.ofReal (tiltPartition (κ a) (H a) 1))⁻¹*ENNReal.ofReal (Real.exp (H a x)) else 1 + +private lemma gibbsKernelDensity_measurable (hH : Measurable (Function.uncurry H)) : + Measurable (Function.uncurry (gibbsKernelDensity κ H)) := by + apply Measurable.ite + · exact (measurableSet_kernel_integrable (κ := κ) (f := fun a x => Real.exp (H a x)) hH.exp.stronglyMeasurable).preimage measurable_fst + · exact (((kernel_tiltPartition_measurable κ hH).ennreal_ofReal.inv).comp measurable_fst).mul hH.exp.ennreal_ofReal + · exact measurable_const + +def gibbsProbabilityKernel : Kernel A S := Kernel.withDensity κ (gibbsKernelDensity κ H) + +lemma gibbsProbabilityKernel_of_integrable (hH : Measurable (Function.uncurry H)) (a : A) + (hi : Integrable (fun x => Real.exp (H a x)) (κ a)) : + gibbsProbabilityKernel κ H a = tiltLaw (κ a) (H a) 1 := by + rw [gibbsProbabilityKernel,Kernel.withDensity_apply _ (gibbsKernelDensity_measurable κ H hH)] + change (κ a).withDensity (fun x => if Integrable (fun y => Real.exp (H a y)) (κ a) + then (ENNReal.ofReal (tiltPartition (κ a) (H a) 1))⁻¹*ENNReal.ofReal (Real.exp (H a x)) else 1) = _ + simp only [ite_eq_left hi,tiltLaw,one_mul] + have hm : Measurable (fun x => ENNReal.ofReal (Real.exp (H a x))) := hH.of_uncurry_left.exp.ennreal_ofReal + exact withDensity_smul _ hm + +lemma gibbsProbabilityKernel_of_not_integrable (hH : Measurable (Function.uncurry H)) (a : A) + (hi : ¬Integrable (fun x => Real.exp (H a x)) (κ a)) : + gibbsProbabilityKernel κ H a = κ a := by + rw [gibbsProbabilityKernel,Kernel.withDensity_apply _ (gibbsKernelDensity_measurable κ H hH)] + change (κ a).withDensity (fun x => if Integrable (fun y => Real.exp (H a y)) (κ a) + then (ENNReal.ofReal (tiltPartition (κ a) (H a) 1))⁻¹*ENNReal.ofReal (Real.exp (H a x)) else 1) = _ + simp only [ite_eq_right hi] + exact withDensity_one + +lemma gibbsProbabilityKernel_markov (hH : Measurable (Function.uncurry H)) : + IsMarkovKernel (gibbsProbabilityKernel κ H) := by + constructor + intro a + by_cases hi : Integrable (fun x => Real.exp (H a x)) (κ a) + · rw [gibbsProbabilityKernel_of_integrable κ H hH a hi] + exact tilt_law_probability_of_integrable (κ a) (by simpa only [one_mul] using hi) + · rw [gibbsProbabilityKernel_of_not_integrable κ H hH a hi] + infer_instance + +lemma gibbsProbabilityKernel_replica_integral (hH : Measurable (Function.uncurry H)) (a : A) + (hi : Integrable (fun x => Real.exp (H a x)) (κ a)) (r : ℕ) (G : (Fin r → S) → ℝ) : + (∫ x, G x ∂Measure.pi (fun _ : Fin r => gibbsProbabilityKernel κ H a)) = + gibbsReplicaMean (κ a) (H a) r G := by + rw [gibbsProbabilityKernel_of_integrable κ H hH a hi] + exact (gibbsReplicaMean_integral_of_integrable _ hH.of_uncurry_left hi r G).symm + +lemma gibbsProbabilityKernel_congr_apply {B : Type*} [MeasurableSpace B] + (η : Kernel B S) [IsMarkovKernel η] (G : B→S→ℝ) + (hH : Measurable (Function.uncurry H)) (hG : Measurable (Function.uncurry G)) + (a : A) (b : B) (he : κ a=η b) (hE : H a=G b) : + gibbsProbabilityKernel κ H a=gibbsProbabilityKernel η G b := by + by_cases hi : Integrable (fun x => Real.exp (H a x)) (κ a) + · have hi' : Integrable (fun x => Real.exp (G b x)) (η b) := by simpa [←he,←hE] using hi + rw [gibbsProbabilityKernel_of_integrable κ H hH a hi, + gibbsProbabilityKernel_of_integrable η G hG b hi',he,hE] + · have hi' : ¬Integrable (fun x => Real.exp (G b x)) (η b) := by simpa [←he,←hE] using hi + rw [gibbsProbabilityKernel_of_not_integrable κ H hH a hi, + gibbsProbabilityKernel_of_not_integrable η G hG b hi',he] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ContactTail.lean b/lean/OAI/Probability/Perceptron/Variational/ContactTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..dd6fb87fd3f9d115759a2f48b1bd0315a441f3cd --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ContactTail.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.WeightedTrialLaw +import OAI.Probability.Perceptron.Variational.QuantileUpperTail +import OAI.Probability.Perceptron.Variational.GlobalContactLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +variable (k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) (p d : ℕ→ℕ) +variable (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) +variable (hw : ∀ i, 0 p i.val) (fun i => d i.val) w q (fun i => (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) (c n)) +variable (hcap : ∀ n, (c n).2.1 (Fin.last k) sourceGibbsArrayLaw (s n) k f (fun i => p i.val) (fun i => d i.val) + (c (s n)).2.1 (c (s n)).2.2 (stepCumulative w) (c (s n)).1) atTop (𝓝 ν)) + +include hc hmin hcap hH hcover hs hlim hq in +lemma source_global_contact_limit_stoploss (r : ℝ) : + (∑ i, w i*max ((q i:ℝ)-r) 0)≤ + ∫ x : Time, max (x.val-r) 0 ∂(compactPositivePairLaw ν).map Prod.fst := by + have hm n := source_global_contact_perturbation_min n k P f (fun i => p i.val) (fun i => d i.val) + w q (fun i => (hw i).le) hw1 δ α H (hc n) (hmin n) + obtain ⟨hn,hl,-⟩ := source_contact_limit_quantile k f p d w hw hw1 + (fun n => (c n).1) (fun n => (c n).2.1) (fun n => (hc n).2.1.1.1) + (fun n => (hc n).2.1.2) (fun n => (c n).2.2) (fun n => (hc n).2.2) hm hH + (fun n => (hc n).2.1.1.2 0) (T := (α:ℝ)) (fun n => (hc n).1.2) hcover hs hlim + obtain ⟨hr,ht⟩ := sourceGibbsArray_limit_gram k f (fun _ i => p i.val) (fun _ i => d i.val) + (fun n => (c n).2.1) (fun n => (c n).2.2) (stepCumulative w) (fun n => (c n).1) s hlim + apply source_field_stoploss w q (fun i => (hw i).le) hq (compactPositivePairLaw ν) hl + intro a ha0 ha + rw [← compactPositivePairLaw_field_integral ν hr ht hn a] + exact source_global_contact_limit_field k P f p d w q hw hw1 δ α H c hc hmin hcap hlim ha0 ha + +include hc hmin hcap hH hcover hs hlim hq in + +theorem source_global_contact_limit_tail_order : + quantileTrial (boundedQuantile (weightedTrialLaw w q))= + weightedStepTrial w q (fun i => (hw i).le) hw1 ∧ + ∀ t : Time, (∫ u : Time in Ici t, (boundedQuantile (weightedTrialLaw w q) u:ℝ))≤ + ∫ u : Time in Ici t, (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst) u:ℝ) := by + have := weightedTrialLaw_probability w q (fun i => (hw i).le) hw1 + have : IsProbabilityMeasure ((compactPositivePairLaw ν).map Prod.fst) := + (Measure.isProbabilityMeasure_map_iff measurable_fst.aemeasurable).2 inferInstance + refine ⟨quantileTrial_weightedTrialLaw w q (fun i => (hw i).le) hw1,?_⟩ + apply upper_tail_order_of_stoploss (boundedQuantile_measurable _) + (boundedQuantile_monotone _) + intro r + rw [boundedQuantile_stoploss,boundedQuantile_stoploss,weightedTrialLaw_integral w q (fun i => (hw i).le)] + exact source_global_contact_limit_stoploss k P f p d w q hw hw1 hq δ α H c hc hmin hcap hH hcover hs hlim r + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ConvexUniform.lean b/lean/OAI/Probability/Perceptron/Variational/ConvexUniform.lean new file mode 100644 index 0000000000000000000000000000000000000000..559b4aa56be074c704e4e1a488afb9854ec0e80c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ConvexUniform.lean @@ -0,0 +1,152 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.HeatGrid + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open Filter Set Metric MeasureTheory ProbabilityTheory +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma equicontinuous_of_convex_nonneg_tendsto {E : Type*} + [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] + (F : ℕ → E → ℝ) (f : E → ℝ) + (hcv : ∀ n, ConvexOn ℝ Set.univ (F n)) (h0 : ∀ n x, 0 ≤ F n x) + (ht : ∀ x, Tendsto (fun n => F n x) atTop (𝓝 (f x))) : Equicontinuous F := by + let G : E → ℝ := fun x => sSup (Set.range (fun n => F n x)) + have hb (x : E) : BddAbove (Set.range (fun n => F n x)) := (ht x).bddAbove_range + have hle (n : ℕ) (x : E) : F n x ≤ G x := le_csSup (hb x) ⟨n,rfl⟩ + have hG : ConvexOn ℝ Set.univ G := by + refine ⟨convex_univ,?_⟩ + intro x _ y _ a b ha hb' hab + apply csSup_le (Set.range_nonempty _) + rintro _ ⟨n,rfl⟩ + exact ((hcv n).2 trivial trivial ha hb' hab).trans + (add_le_add (mul_le_mul_of_nonneg_left (hle n x) ha) + (mul_le_mul_of_nonneg_left (hle n y) hb')) + have hGc : Continuous G := continuousOn_univ.mp (hG.continuousOn isOpen_univ) + intro x + have hn : {y : E | G y < G x+1} ∈ 𝓝 x := + (hGc.continuousAt).preimage_mem_nhds (Iio_mem_nhds (by linarith)) + obtain ⟨r,hr,hrG⟩ := Metric.mem_nhds_iff.mp hn + let K : ℝ≥0 := (2*(G x+1)/(r/2)).toNNReal + have hLip (n : ℕ) : LipschitzOnWith K (F n) (ball x (r-r/2)) := by + apply ((hcv n).subset (Set.subset_univ _) (convex_ball _ _)).lipschitzOnWith_of_abs_le + (half_pos hr) + intro y hy + rw [abs_of_nonneg (h0 n y)] + exact (hle n y).trans (hrG hy).le + apply Metric.equicontinuousAt_of_continuity_modulus (fun y => (K:ℝ)*dist x y) + (by + have hc : Continuous (fun y : E => (K:ℝ)*dist x y) := by fun_prop + simpa only [dist_self,mul_zero] using hc.tendsto x) F + filter_upwards [ball_mem_nhds x (by linarith : 0 < r-r/2)] with y hy n + have hx : x ∈ ball x (r-r/2) := by rw [mem_ball,dist_self]; linarith + exact (hLip n).dist_le_mul x hx y hy + +lemma tendstoUniformlyOn_of_convex_nonneg_tendsto {E : Type*} + [NormedAddCommGroup E] [NormedSpace ℝ E] [FiniteDimensional ℝ E] + (F : ℕ → E → ℝ) (f : E → ℝ) + (hcv : ∀ n, ConvexOn ℝ Set.univ (F n)) (h0 : ∀ n x, 0 ≤ F n x) + (ht : ∀ x, Tendsto (fun n => F n x) atTop (𝓝 (f x))) + {K : Set E} (hK : IsCompact K) : TendstoUniformlyOn F f atTop K := by + have he := equicontinuous_of_convex_nonneg_tendsto F f hcv h0 ht + have : CompactSpace K := isCompact_iff_compactSpace.mp hK + have he' : Equicontinuous (fun n (x : K) => F n x) := by + intro x + rw [Metric.equicontinuousAt_iff] + intro ε hε + obtain ⟨δ,hδ,hd⟩ := Metric.equicontinuousAt_iff.mp (he (x:E)) ε hε + exact ⟨δ,hδ,fun y hy n => hd (y:E) hy n⟩ + have hp : Tendsto (fun n (x : K) => F n x) atTop (𝓝 (fun x : K => f x)) := + tendsto_pi_nhds.mpr (fun x => ht x) + have hu := (he'.tendsto_uniformFun_iff_pi atTop (fun x : K => f x)).mpr hp + exact tendstoUniformlyOn_iff_tendstoUniformly_comp_coe.mpr + (UniformFun.tendsto_iff_tendstoUniformly.mp hu) + +lemma finiteAmplitudeSphereValue_uniform {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) {K : Set (Fin (k+1) → ℝ)} + (hK : IsCompact K) : TendstoUniformlyOn (fun n => finiteAmplitudeSphereValue n k w) + (finiteAmplitudeSphereDual w (fun i => (hw i).le) hw1) atTop K := + tendstoUniformlyOn_of_convex_nonneg_tendsto _ _ (finiteAmplitudeSphereValue_convex w hw hw1) + (finiteAmplitudeSphereValue_nonneg w hw hw1) (finiteAmplitudeSphereValue_tendsto w hw hw1) hK + +def fieldAmplitudes (k : ℕ) (h : Fin (k+1) → ℝ) (i : Fin (k+1)) : ℝ := + if _hi : i.val < k then stepFieldIncrement k h i.val else Real.sqrt (2*h 0) + +lemma fieldAmplitudes_last (k : ℕ) (h : Fin (k+1) → ℝ) : + fieldAmplitudes k h (Fin.last k)=Real.sqrt (2*h 0) := by + simp [fieldAmplitudes] + +lemma fieldAmplitudes_increment (k : ℕ) (h : Fin (k+1) → ℝ) : + finiteAmplitudeIncrement k (fieldAmplitudes k h)=stepFieldIncrement k h := by + funext j + by_cases hj : j < k + · simp [finiteAmplitudeIncrement,fieldAmplitudes,hj] + · simp [finiteAmplitudeIncrement,stepFieldIncrement,hj] + +lemma fieldAmplitudes_continuous (k : ℕ) : Continuous (fieldAmplitudes k) := by + apply continuous_pi + intro i + unfold fieldAmplitudes + split_ifs + · unfold stepFieldIncrement + split_ifs + fun_prop + · fun_prop + +lemma amplitudeCovarianceLevels_fieldAmplitudes (k : ℕ) (h : Fin (k+1) → ℝ) + (hh : Monotone h) (hh0 : 0 ≤ h 0) : + amplitudeCovarianceLevels k (finiteAmplitudeIncrement k (fieldAmplitudes k h)) + (fieldAmplitudes k h (Fin.last k))=h := by + rw [fieldAmplitudes_increment,fieldAmplitudes_last] + funext i + induction i using Fin.induction with + | zero => + have hr := amplitudeCovarianceLevels_root k (stepFieldIncrement k h) (Real.sqrt (2*h 0)) + rw [Real.sq_sqrt (mul_nonneg (by norm_num) hh0)] at hr + linarith + | succ i ih => + have hi := amplitudeCovarianceLevels_increment k (stepFieldIncrement k h) (Real.sqrt (2*h 0)) i + rw [stepFieldIncrement_sq k h hh i,ih] at hi + linarith + +lemma finiteAmplitudeSphereDual_fieldAmplitudes {k : ℕ} (w h : Fin (k+1) → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) (hh : Monotone h) (hh0 : 0 ≤ h 0) : + finiteAmplitudeSphereDual w hw hw1 (fieldAmplitudes k h)= + sInf (finiteSphericalDualValues w h hw hw1)+h (Fin.last k) := by + unfold finiteAmplitudeSphereDual amplitudeSphereDual + rw [amplitudeCovarianceLevels_fieldAmplitudes k h hh hh0] + +lemma finiteAmplitudeSphereValue_fieldAmplitudes (n k : ℕ) (w h : Fin (k+1) → ℝ) + (hh0 : 0 ≤ h 0) : + finiteAmplitudeSphereValue n k w (fieldAmplitudes k h)=finiteSphericalFieldValue n k w h+h (Fin.last k) := by + unfold finiteAmplitudeSphereValue + rw [fieldAmplitudes_increment,fieldAmplitudes_last,amplitudeSphereValue_eq] + have hv : (⟨(Real.sqrt (2*h 0))^2,sq_nonneg _⟩ : ℝ≥0)=Real.toNNReal (2*h 0) := by + apply NNReal.coe_injective + change (Real.sqrt (2*h 0))^2=(Real.toNNReal (2*h 0) : ℝ) + rw [Real.sq_sqrt (mul_nonneg (by norm_num) hh0), + Real.coe_toNNReal _ (mul_nonneg (by norm_num) hh0)] + rw [hv,finiteSphericalFieldValue,sub_add_cancel] + +theorem finiteSphericalFieldValue_compact_uniform {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) {K : Set (Fin (k+1) → ℝ)} + (hK : IsCompact K) (hfield : ∀ h ∈ K, Monotone h ∧ 0 ≤ h 0) : + TendstoUniformlyOn (fun n h => finiteSphericalFieldValue n k w h) + (fun h => sInf (finiteSphericalDualValues w h (fun i => (hw i).le) hw1)) atTop K := by + have hu := finiteAmplitudeSphereValue_uniform w hw hw1 (hK.image (fieldAmplitudes_continuous k)) + rw [Metric.tendstoUniformlyOn_iff] at hu ⊢ + intro ε hε + filter_upwards [hu ε hε] with n hn h hh + have ht := hn (fieldAmplitudes k h) ⟨h,hh,rfl⟩ + rw [finiteAmplitudeSphereValue_fieldAmplitudes n k w h (hfield h hh).2, + finiteAmplitudeSphereDual_fieldAmplitudes w h (fun i => (hw i).le) hw1 + (hfield h hh).1 (hfield h hh).2,dist_add_right] at ht + exact ht + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CountMixtureVariance.lean b/lean/OAI/Probability/Perceptron/Variational/CountMixtureVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..abd51d55b419d8ddc985cd97d97034c7340fe9f7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CountMixtureVariance.lean @@ -0,0 +1,65 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +lemma memLp_prod_of_conditional_square_function {X Y : Type} + [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure X) (ν : Measure Y) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + {F : X×Y → ℝ} {G A : X → ℝ} (hF : Measurable F) (hG : MemLp G 2 μ) + (hA : Integrable A μ) (hs : ∀ x, MemLp (fun y => F (x,y)) 2 ν) + (hb : ∀ x, (∫ y, (F (x,y)-G x)^2 ∂ν) ≤ A x) : MemLp F 2 (μ.prod ν) := by + apply (memLp_two_iff_integrable_sq hF.aestronglyMeasurable).mpr + apply (integrable_prod_iff (hF.pow_const 2).aestronglyMeasurable).mpr + refine ⟨Eventually.of_forall (fun x => (hs x).integrable_sq),?_⟩ + have hi : Integrable (fun x => 2*A x+2*(G x)^2) μ := + (hA.const_mul 2).add (hG.integrable_sq.const_mul 2) + apply hi.mono' (hF.pow_const 2).aestronglyMeasurable.norm.integral_prod_right' + exact ae_of_all _ fun x => by + simp only [Real.norm_eq_abs,abs_sq] + rw [abs_of_nonneg (integral_nonneg (fun y : Y => sq_nonneg (F (x,y))))] + have hi1 : Integrable (fun y => (F (x,y)-G x)^2) ν := + ((hs x).sub (memLp_const (G x))).integrable_sq + calc + _ ≤ ∫ y, 2*(F (x,y)-G x)^2+2*(G x)^2 ∂ν := by + apply integral_mono (hs x).integrable_sq ((hi1.const_mul 2).add (integrable_const _)) + intro y + dsimp only [Pi.add_apply] + nlinarith [sq_nonneg (F (x,y)-2*G x)] + _ = 2*(∫ y, (F (x,y)-G x)^2 ∂ν)+2*(G x)^2 := by + rw [integral_add (hi1.const_mul 2) (integrable_const _),integral_const_mul] + simp + _ ≤ _ := by linarith [hb x] + +lemma variance_prod_le_integral {X Y : Type} [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure X) (ν : Measure Y) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + {F : X × Y → ℝ} (hp : MemLp F 2 (μ.prod ν)) + (hs : ∀ x, MemLp (fun y => F (x,y)) 2 ν) + (hh : MemLp (fun x => ∫ y, F (x,y) ∂ν) 2 μ) {A : X → ℝ} {B : ℝ} + (hAi : Integrable A μ) (hA : ∀ x, variance (fun y => F (x,y)) ν ≤ A x) + (hB : variance (fun x => ∫ y, F (x,y) ∂ν) μ ≤ B) : + variance F (μ.prod ν) ≤ (∫ x, A x ∂μ)+B := by + have hi : (∫ x, ∫ y, F (x,y)^2 ∂ν ∂μ) ≤ (∫ x, A x ∂μ)+∫ x, (∫ y, F (x,y) ∂ν)^2 ∂μ := by + calc + _ ≤ ∫ x, (A x+(∫ y, F (x,y) ∂ν)^2) ∂μ := by + apply integral_mono hp.integrable_sq.integral_prod_left (hAi.add hh.integrable_sq) + intro x + have hv := hA x + rw [variance_eq_sub (hs x)] at hv + simpa only [Pi.pow_apply,Pi.add_apply] using sub_le_iff_le_add.mp hv + _ = _ := integral_add hAi hh.integrable_sq + rw [variance_eq_sub hh] at hB + rw [variance_eq_sub hp] + simp only [Pi.pow_apply] at hB ⊢ + rw [integral_prod _ hp.integrable_sq,integral_prod _ (hp.integrable (by norm_num))] + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CountableGaussianFullIBP.lean b/lean/OAI/Probability/Perceptron/Variational/CountableGaussianFullIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..1320ed9527a5e45166f53e0945b857fe673f9bb4 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CountableGaussianFullIBP.lean @@ -0,0 +1,97 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.AnnealedReplicaConvergence +import OAI.Probability.Perceptron.Variational.GaussianGibbsEnergy + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma countableGaussian_replica_full_ibp (n : ℕ) (j : Fin n) + {W : S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} {G : (Fin n → S) → ℝ} + (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) + (hL : Measurable L) (hG : Measurable G) {A D E B : ℝ} + (hA : ∀ x, |W x| ≤ A) (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) + (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) + (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + let H := countableGaussianHamiltonian W v L + (∫ g, gibbsReplicaMean μ (H g) n (fun x => countableGaussianField w L g (x j)*G x) + ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean μ (H g) n (fun x => G x*∑ l, countableGaussianCovariance v w L (x j) (x l)) - + n*gibbsReplicaMean μ (H g) (n+1) + (fun x => G (fun l => x l.succ)*countableGaussianCovariance v w L (x j.succ) (x 0)) ∂countableGaussianLaw := by + dsimp only + let H := countableGaussianHamiltonian W v L + let C := |(D+E)/2| + have hC : 0 ≤ C := abs_nonneg _ + have hHm : Measurable (Function.uncurry H) := countableGaussianHamiltonian_measurable hW hv hL + have he : ∀ᵐ g ∂countableGaussianLaw, Integrable (fun x => Real.exp (H g x)) μ := by + simpa only [one_mul] using (countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).prod_left_ae + let K := gaussianPrefixCovariance v w L + let KFull := countableGaussianCovariance v w L + have hKm (m) : Measurable (Function.uncurry (K m)) := gaussianPrefixCovariance_measurable hv hw hL m + have hKFullm : Measurable (Function.uncurry KFull) := countableGaussianCovariance_measurable hv hw hL + have hKb (m x y) : |K m x y| ≤ C := (gaussianPrefixCovariance_bound v w L hD hE m x y).trans (le_abs_self _) + have hKFullb (x y) : |KFull x y| ≤ C := hKb (L x) x y + have hKt (x y) : Tendsto (fun m => K m x y) atTop (nhds (KFull x y)) := + tendsto_const_nhds.congr' ((gaussianPrefixCovariance_eventually_eq v w L x y).mono fun _ h => h.symm) + let U (m) (x : Fin n → S) := G x*∑ l, K m (x j) (x l) + let UFull (x : Fin n → S) := G x*∑ l, KFull (x j) (x l) + let V (m) (x : Fin (n+1) → S) := G (fun l => x l.succ)*K m (x j.succ) (x 0) + let VFull (x : Fin (n+1) → S) := G (fun l => x l.succ)*KFull (x j.succ) (x 0) + have hPair (a b : Fin n) : Measurable (fun x : Fin n → S => (x a,x b)) := + (measurable_pi_apply a).prodMk (measurable_pi_apply b) + have hUm (m) : Measurable (U m) := hG.mul + (Finset.measurable_sum Finset.univ fun (l : Fin n) _ => (hKm m).comp (hPair j l)) + have hUFullm : Measurable UFull := hG.mul + (Finset.measurable_sum Finset.univ fun (l : Fin n) _ => hKFullm.comp (hPair j l)) + have hPairS : Measurable (fun x : Fin (n+1) → S => (x j.succ,x 0)) := + (measurable_pi_apply j.succ).prodMk (measurable_pi_apply 0) + have hVm (m) : Measurable (V m) := + (hG.comp (Measurable.of_eval fun index : Fin n => measurable_pi_apply index.succ)).mul + ((hKm m).comp hPairS) + have hVFullm : Measurable VFull := + (hG.comp (Measurable.of_eval fun index : Fin n => measurable_pi_apply index.succ)).mul + (hKFullm.comp hPairS) + have hsum (k : S → S → ℝ) (hk : ∀ x y, |k x y| ≤ C) (x : Fin n → S) : + |G x*∑ l, k (x j) (x l)| ≤ B*((n:ℝ)*C) := by + rw [abs_mul] + apply mul_le_mul (hGB x) _ (abs_nonneg _) hB + calc + _ ≤ ∑ l : Fin n, |k (x j) (x l)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ l : Fin n, C := Finset.sum_le_sum fun l _ => hk _ _ + _ = _ := by simp + have hUB (m x) : |U m x| ≤ B*((n:ℝ)*C) := hsum (K m) (hKb m) x + have hUFullB (x) : |UFull x| ≤ B*((n:ℝ)*C) := hsum KFull hKFullb x + have hVB (m x) : |V m x| ≤ B*C := by + exact (abs_mul _ _).trans_le (mul_le_mul (hGB _) (hKb m _ _) (abs_nonneg _) hB) + have hVFullB (x) : |VFull x| ≤ B*C := by + exact (abs_mul _ _).trans_le (mul_le_mul (hGB _) (hKFullb _ _) (abs_nonneg _) hB) + have hUt (x) : Tendsto (fun m => U m x) atTop (nhds (UFull x)) := + (tendsto_finsetSum _ (fun index _ => hKt (x j) (x index))).const_mul (G x) + have hVt (x) : Tendsto (fun m => V m x) atTop (nhds (VFull x)) := + (hKt (x j.succ) (x 0)).const_mul (G (fun l => x l.succ)) + have hUi (m) := annealedReplica_bounded_integrable μ countableGaussianLaw hHm (hUm m) (by positivity) (hUB m) + have hVi (m) := annealedReplica_bounded_integrable μ countableGaussianLaw hHm (hVm m) (by positivity) (hVB m) + have hUFulli := annealedReplica_bounded_integrable μ countableGaussianLaw hHm hUFullm (by positivity) hUFullB + have hVFulli := annealedReplica_bounded_integrable μ countableGaussianLaw hHm hVFullm (by positivity) hVFullB + have hUL := annealedReplica_bounded_tendsto μ countableGaussianLaw hHm hUm hUFullm (by positivity) hUB hUt he + have hVL := annealedReplica_bounded_tendsto μ countableGaussianLaw hHm hVm hVFullm (by positivity) hVB hVt he + have hR := hUL.sub (hVL.const_mul (n:ℝ)) + have hL' := gaussianEnergy_replica_prefix_tendsto μ hW hv hw hL hA hD hE j hG hB hGB + have heq (m) : (∫ g, gibbsReplicaMean μ (H g) n + (fun x => truncatedCountableGaussianField w L m g (x j)*G x) ∂countableGaussianLaw) = + (∫ g, gibbsReplicaMean μ (H g) n (U m) ∂countableGaussianLaw)- + (n:ℝ)*(∫ g, gibbsReplicaMean μ (H g) (n+1) (V m) ∂countableGaussianLaw) := by + rw [gaussianReplica_prefix_ibp μ m n j hW hv hw hL hG hA hD hE hB hGB] + exact (integral_sub (hUi m) ((hVi m).const_mul n)).trans (by rw [integral_const_mul]) + have hlim := tendsto_nhds_unique hL' (hR.congr (fun m => (heq m).symm)) + exact hlim.trans ((integral_sub hUFulli (hVFulli.const_mul n)).trans (by rw [integral_const_mul])).symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CountableGaussianIBP.lean b/lean/OAI/Probability/Perceptron/Variational/CountableGaussianIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea2e35a2757954d46aa37a4928d1768dccec0d63 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CountableGaussianIBP.lean @@ -0,0 +1,126 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CountableGaussianResampling +import OAI.Probability.Perceptron.Interpolation.IntegrableReplicaGibbs + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +lemma countableGaussian_affine_zero_exp_integrable (i : ℕ) + {H : (ℕ → ℝ) → S → ℝ} {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hvC : ∀ x, |v x| ≤ C) + (haff : ∀ g t x, H (Function.update g i t) x = H (Function.update g i 0) x+t*v x) + (hi : ∀ᵐ g ∂countableGaussianLaw, Integrable (fun x => Real.exp (H g x)) μ) : + ∀ᵐ g ∂countableGaussianLaw, + Integrable (fun x => Real.exp (H (Function.update g i 0) x)) μ := by + have hp := (resampleGaussianCoordinate_measurePreserving i).quasiMeasurePreserving.ae hi + have hs := Measure.measurePreserving_swap.quasiMeasurePreserving.ae hp + filter_upwards [Measure.ae_ae_of_ae_prod hs] with g hg + obtain ⟨t,ht⟩ := hg.exists + change Integrable (fun x => Real.exp (H (Function.update g i t) x)) μ at ht + have hb (x) : ‖Real.exp (-t*v x)‖ ≤ Real.exp (|t| * C) := by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + exact (le_abs_self _).trans (by + rw [abs_mul,abs_neg] + exact mul_le_mul_of_nonneg_left (hvC x) (abs_nonneg t)) + have hh := ht.mul_bdd ((hv.const_mul (-t)).exp.aestronglyMeasurable) + (ae_of_all _ hb) + apply hh.congr + exact ae_of_all _ fun x => by + dsimp only + rw [← Real.exp_add,haff] + congr 1 + ring + +lemma countableGaussian_coordinate_tilt_ibp (i : ℕ) + {H : (ℕ → ℝ) → S → ℝ} {v F : S → ℝ} + (hH : Measurable (Function.uncurry H)) (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) + (haff : ∀ g t x, H (Function.update g i t) x = H (Function.update g i 0) x+t*v x) + (hi0 : ∀ᵐ g ∂countableGaussianLaw, + Integrable (fun x => Real.exp (H (Function.update g i 0) x)) μ) : + (∫ g, g i*tiltMean μ (H g) F 1 ∂countableGaussianLaw) = + ∫ g, tiltMean μ (H g) (fun x => v x*F x) 1- + tiltMean μ (H g) F 1*tiltMean μ (H g) v 1 ∂countableGaussianLaw := by + let R (g : ℕ → ℝ) := tiltMean μ (H g) (fun x => v x*F x) 1- + tiltMean μ (H g) F 1*tiltMean μ (H g) v 1 + have hm (K : S → ℝ) (hK : Measurable K) := measurable_tiltMean μ hH hK + have hHg (g) : Measurable (H g) := hH.comp (measurable_const.prodMk measurable_id) + have hb (K : S → ℝ) (hK : Measurable K) {B : ℝ} (hB : 0 ≤ B) + (hKB : ∀ x, |K x| ≤ B) (g) : |tiltMean μ (H g) K 1| ≤ B := + tiltMean_bound_general μ (hHg g) hK hB hKB + have hvF (x : S) : |v x*F x| ≤ C*D := by + rw [abs_mul] + exact mul_le_mul (hvC x) (hFD x) (abs_nonneg _) hC + have hRm : Measurable R := (hm _ (hv.mul hF)).sub ((hm _ hF).mul (hm _ hv)) + have hRb (g) : |R g| ≤ 2*C*D := by + calc + _ ≤ |tiltMean μ (H g) (fun x => v x*F x) 1|+ + |tiltMean μ (H g) F 1*tiltMean μ (H g) v 1| := abs_sub _ _ + _ ≤ C*D+D*C := add_le_add (hb _ (hv.mul hF) (mul_nonneg hC hD) hvF g) (by + rw [abs_mul] + exact mul_le_mul (hb _ hF hD hFD g) (hb _ hv hC hvC g) (abs_nonneg _) hD) + _ = _ := by ring + let e := resampleGaussianCoordinate i + have he := resampleGaussianCoordinate_measurePreserving i + have intmap (K : (ℕ → ℝ) → ℝ) (hK : Measurable K) : + (∫ p, K (e p) ∂(gaussianReal 0 1).prod countableGaussianLaw) = ∫ g, K g ∂countableGaussianLaw := by + simpa only [he.map_eq] using + (integral_map (μ := (gaussianReal 0 1).prod countableGaussianLaw) he.measurable.aemeasurable hK.aestronglyMeasurable).symm + have hmF : Measurable (fun p : ℝ×(ℕ → ℝ) => tiltMean μ (H (e p)) F 1) := + (hm _ hF).comp he.measurable + have hiF : Integrable (fun p : ℝ×(ℕ → ℝ) => p.1*tiltMean μ (H (e p)) F 1) + ((gaussianReal 0 1).prod countableGaussianLaw) := by + apply ((memLp_id_gaussianReal (μ := 0) (v := 1) 1).integrable (by norm_num)).comp_fst countableGaussianLaw |>.mul_bdd + hmF.aestronglyMeasurable + exact ae_of_all _ fun p => by simpa only [Real.norm_eq_abs] using hb _ hF hD hFD (e p) + have hiR : Integrable (fun p => R (e p)) ((gaussianReal 0 1).prod countableGaussianLaw) := + Integrable.of_bound (hRm.comp he.measurable).aestronglyMeasurable (2*C*D) + (ae_of_all _ fun p => by simpa only [Real.norm_eq_abs] using hRb (e p)) + change (∫ g, g i*tiltMean μ (H g) F 1 ∂countableGaussianLaw) = ∫ g, R g ∂countableGaussianLaw + rw [← intmap (fun g => g i*tiltMean μ (H g) F 1) ((measurable_pi_apply i).mul (hm _ hF)),← intmap _ hRm] + simp only [e,resampleGaussianCoordinate,Function.update_self] + change (∫ p, p.1*tiltMean μ (H (e p)) F 1 ∂(gaussianReal 0 1).prod countableGaussianLaw) = + ∫ p, R (e p) ∂(gaussianReal 0 1).prod countableGaussianLaw + rw [integral_prod_symm _ hiF,integral_prod_symm _ hiR] + apply integral_congr_ae + filter_upwards [hi0] with g hg + let w : S → ℝ := H (Function.update g i 0) + have hwm : Measurable w := hHg _ + have hwI : Integrable (fun x => Real.exp (1*w x)) μ := by simpa only [one_mul] using hg + let := tilt_law_probability_of_integrable μ hwI + have heK (K : S → ℝ) (u : ℝ) : tiltMean (tiltLaw μ w 1) v K u = + tiltMean μ (H (Function.update g i u)) K 1 := by + rw [tilt_mean_twice_of_integrable μ hwm hwI u] + congr 2 + funext x + simp only [one_mul] + exact (haff g u x).symm + have hh := gaussian_tilt_integrationByParts (tiltLaw μ w 1) hv hF hC hD hvC hFD + simp_rw [heK] at hh + exact hh + +lemma countableGaussian_coordinate_tilt_ibp_of_exp_integrable (i : ℕ) + {H : (ℕ → ℝ) → S → ℝ} {v F : S → ℝ} + (hH : Measurable (Function.uncurry H)) (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) + (haff : ∀ g t x, H (Function.update g i t) x = H (Function.update g i 0) x+t*v x) + (hi : ∀ᵐ g ∂countableGaussianLaw, Integrable (fun x => Real.exp (H g x)) μ) : + (∫ g, g i*tiltMean μ (H g) F 1 ∂countableGaussianLaw) = + ∫ g, tiltMean μ (H g) (fun x => v x*F x) 1- + tiltMean μ (H g) F 1*tiltMean μ (H g) v 1 ∂countableGaussianLaw := + countableGaussian_coordinate_tilt_ibp μ i hH hv hF hC hD hvC hFD haff + (countableGaussian_affine_zero_exp_integrable μ i hv hvC haff hi) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CountableGaussianResampling.lean b/lean/OAI/Probability/Perceptron/Variational/CountableGaussianResampling.lean new file mode 100644 index 0000000000000000000000000000000000000000..29667406abeab5bd99560eb8bba1fb332e4312a2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CountableGaussianResampling.lean @@ -0,0 +1,59 @@ +import Mathlib +import OAI.Probability.Perceptron.Brownian.CountableGaussianField + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + + def resampleGaussianCoordinate (i : ℕ) (p : ℝ×(ℕ → ℝ)) : ℕ → ℝ := + Function.update p.2 i p.1 + +lemma resampleGaussianCoordinate_measurable (i : ℕ) : + Measurable (resampleGaussianCoordinate i) := by + unfold resampleGaussianCoordinate + fun_prop + +lemma resampleGaussianCoordinate_measurePreserving (i : ℕ) : + MeasurePreserving (resampleGaussianCoordinate i) + ((gaussianReal 0 1).prod countableGaussianLaw) countableGaussianLaw := by + refine ⟨resampleGaussianCoordinate_measurable i,?_⟩ + apply Measure.eq_infinitePi + intro s t ht + rw [Measure.map_apply (resampleGaussianCoordinate_measurable i) + (MeasurableSet.pi s.countable_toSet (fun j _ => ht j))] + classical + by_cases hi : i ∈ s + · have he : (resampleGaussianCoordinate i) ⁻¹' Set.pi s t = + t i ×ˢ Set.pi (s.erase i) t := by + ext p + simp only [mem_preimage,mem_prod,Set.mem_pi,Finset.mem_coe,resampleGaussianCoordinate] + constructor + · intro hp + refine ⟨?_,fun j hj => ?_⟩ + · simpa only [Function.update_self] using hp i hi + · simpa only [Function.update_of_ne (Finset.mem_erase.mp hj).1] using + hp j (Finset.mem_of_mem_erase hj) + · rintro ⟨hp,hq⟩ j hj + by_cases he : j=i + · subst j + simpa only [Function.update_self] using hp + · simpa only [Function.update_of_ne he] using hq j (Finset.mem_erase.mpr ⟨he,hj⟩) + rw [he,Measure.prod_prod,countableGaussianLaw,Measure.infinitePi_pi _ (fun j _ => ht j)] + exact Finset.mul_prod_erase s (fun j => gaussianReal 0 1 (t j)) hi + · have he : (resampleGaussianCoordinate i) ⁻¹' Set.pi s t = + Set.univ ×ˢ Set.pi s t := by + ext p + simp only [mem_preimage,mem_prod,true_and,mem_univ,Set.mem_pi,Finset.mem_coe,resampleGaussianCoordinate] + constructor <;> intro hp j hj + · simpa only [Function.update_of_ne (ne_of_mem_of_not_mem hj hi)] using hp j hj + · simpa only [Function.update_of_ne (ne_of_mem_of_not_mem hj hi)] using hp j hj + rw [he,Measure.prod_prod,measure_univ,one_mul,countableGaussianLaw, + Measure.infinitePi_pi _ (fun j _ => ht j)] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CountableMarkedDiagonal.lean b/lean/OAI/Probability/Perceptron/Variational/CountableMarkedDiagonal.lean new file mode 100644 index 0000000000000000000000000000000000000000..7f8704156c248e1a7e0650fe23d836f803fe1f37 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CountableMarkedDiagonal.lean @@ -0,0 +1,234 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.LabelFreshKernel +import OAI.Probability.Perceptron.Cavity.FreshMarkedKernel + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma truncatedFreshMarkedKernel {S : Type*} [MeasurableSpace S] + (v : ℕ→S→ℝ) (L : S→ℕ) {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) + (n : ℕ) (xs : Fin r→S) : + (∫ g, Ψ (WithLp.toLp 2 (fun i => truncatedCountableGaussianField v L n g (xs i))) + ∂countableGaussianLaw)= + freshMarkedMatrixKernel Ψ (fun i j => gaussianPrefixCovariance v v L n (xs i) (xs j)) := by + let rows : Fin r→EuclideanSpace ℝ (Fin n) := fun i => + WithLp.toLp 2 (fun j => maskedGaussianCoefficient v L j.val (xs i)) + have hg : Matrix.gram ℝ rows=(fun i j => gaussianPrefixCovariance v v L n (xs i) (xs j)) := by + ext i j + change (∑ l : Fin n, maskedGaussianCoefficient v L l.val (xs j)* + maskedGaussianCoefficient v L l.val (xs i)) = _ + unfold gaussianPrefixCovariance + exact Finset.sum_congr rfl fun l _ => mul_comm _ _ + rw [←hg,←freshMarkedMatrixKernel_gaussian,←map_pi_eq_stdGaussian, + integral_map (by fun_prop) (by fun_prop)] + have hp := gaussianCoordinatePrefix_measurePreserving n + have hm : AEStronglyMeasurable (fun y : Fin n→ℝ => Ψ (gaussianRows rows (WithLp.toLp 2 y))) + (Measure.pi fun _ : Fin n => gaussianReal 0 1) := by fun_prop + rw [←hp.map_eq] at hm ⊢ + rw [integral_map hp.measurable.aemeasurable hm] + rfl + +lemma countableFreshMarkedKernel {S : Type*} [MeasurableSpace S] + (v : ℕ→S→ℝ) (L : S→ℕ) {r : ℕ} (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) (xs : Fin r→S) : + (∫ g, Ψ (WithLp.toLp 2 (fun i => countableGaussianField v L g (xs i))) ∂countableGaussianLaw)= + freshMarkedMatrixKernel Ψ (fun i j => countableGaussianCovariance v v L (xs i) (xs j)) := by + have he : ∀ᶠ n : ℕ in atTop, ∀ i : Fin r, ∀ g, + truncatedCountableGaussianField v L n g (xs i)=countableGaussianField v L g (xs i) := + Filter.eventually_all.mpr (fun i => truncatedCountableGaussianField_eventually_eq v L (xs i)) + have hc : ∀ᶠ n : ℕ in atTop, ∀ i j : Fin r, + gaussianPrefixCovariance v v L n (xs i) (xs j)=countableGaussianCovariance v v L (xs i) (xs j) := + Filter.eventually_all.mpr (fun i => Filter.eventually_all.mpr (fun j => + gaussianPrefixCovariance_eventually_eq v v L (xs i) (xs j))) + obtain ⟨n,hn,hc⟩ := (he.and hc).exists + simpa only [hn,hc] using truncatedFreshMarkedKernel v L Ψ n xs + +def gaussianMixedTest {r : ℕ} (f : Fin r→ℝ →ᵇ ℝ) : EuclideanSpace ℝ (Fin r) →ᵇ ℝ := + ∏ i : Fin r, (f i).compContinuous ⟨fun x => x i,by fun_prop⟩ + +@[simp] lemma gaussianMixedTest_apply {r : ℕ} (f : Fin r→ℝ →ᵇ ℝ) + (x : EuclideanSpace ℝ (Fin r)) : gaussianMixedTest f x=∏ i, f i (x i) := by + simp [gaussianMixedTest] + +lemma freshMixedKernel_diagonal_noise {r n : ℕ} (f : Fin r→ℝ →ᵇ ℝ) + (v : Fin r→EuclideanSpace ℝ (Fin n)) (s : ℝ≥0) : + freshMarkedMatrixKernel (gaussianMixedTest f) + (fun i j => Matrix.gram ℝ v i j + if i=j then (s:ℝ) else 0)= + freshMarkedMatrixKernel (gaussianMixedTest (fun i => gaussianAverageBCF s (f i))) + (Matrix.gram ℝ v) := by + classical + rw [←freshNoiseRows_gram v s,←freshMarkedMatrixKernel_gaussian, + ←map_pi_eq_stdGaussian,integral_map (by fun_prop) (by fun_prop)] + let F : (Fin n→ℝ)×(Fin r→ℝ)→ℝ := fun p => + ∏ i : Fin r, f i (inner ℝ (v i) (WithLp.toLp 2 p.1)+Real.sqrt s*p.2 i) + have hF : Integrable F ((Measure.pi fun _ : Fin n => gaussianReal 0 1).prod + (Measure.pi fun _ : Fin r => gaussianReal 0 1)) := by + apply Integrable.of_bound (by fun_prop) (∏ i, ‖f i‖) + exact ae_of_all _ fun p => by + simp only [F,norm_prod] + exact Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) (fun index _ => (f index).norm_coe_le_norm _) + have hp := measurePreserving_sumPiEquivProdPi_symm (fun _ : Fin n⊕Fin r => gaussianReal 0 1) + have hm : AEStronglyMeasurable (fun z : Fin n⊕Fin r→ℝ => + gaussianMixedTest f (gaussianRows (freshNoiseRows v s) (WithLp.toLp 2 z))) + (Measure.pi fun _ => gaussianReal 0 1) := by fun_prop + rw [←hp.map_eq] at hm ⊢ + rw [integral_map hp.measurable.aemeasurable hm] + have he : (fun p : (Fin n→ℝ)×(Fin r→ℝ) => + gaussianMixedTest f (gaussianRows (freshNoiseRows v s) + (WithLp.toLp 2 ((MeasurableEquiv.sumPiEquivProdPi (fun _ : Fin n⊕Fin r => ℝ)).symm p))))=F := by + funext p + simp only [gaussianMixedTest_apply,gaussianRows_apply] + apply Finset.prod_congr rfl + intro i hi + exact congrArg (f i) (freshNoiseRows_apply v s p.1 p.2 i) + rw [he,integral_prod _ hF] + have hi (x : Fin n→ℝ) : (∫ y : Fin r→ℝ, F (x,y) ∂Measure.pi (fun _ => gaussianReal 0 1))= + gaussianMixedTest (fun i => gaussianAverageBCF s (f i)) (gaussianRows v (WithLp.toLp 2 x)) := by + rw [gaussianMixedTest_apply] + change (∫ y : Fin r→ℝ, ∏ i, f i (inner ℝ (v i) (WithLp.toLp 2 x)+Real.sqrt s*y i) + ∂Measure.pi (fun _ => gaussianReal 0 1))=_ + rw [integral_fintype_prod_eq_prod (f := fun i y => f i (inner ℝ (v i) (WithLp.toLp 2 x)+Real.sqrt s*y))] + apply Finset.prod_congr rfl + intro i hi + exact (gaussianAverage_scaling s (f i) _).symm + simp_rw [hi] + rw [←freshMarkedMatrixKernel_gaussian,←map_pi_eq_stdGaussian, + integral_map (by fun_prop) (by fun_prop)] + +lemma countableFreshMixed_diagonal {S : Type*} [MeasurableSpace S] + (v : ℕ→S→ℝ) (L : S→ℕ) {r : ℕ} (f : Fin r→ℝ →ᵇ ℝ) (s : ℝ≥0) (xs : Fin r→S) : + (∫ g, ∏ i, gaussianAverageBCF s (f i) (countableGaussianField v L g (xs i)) ∂countableGaussianLaw)= + freshMarkedMatrixKernel (gaussianMixedTest f) + (fun i j => countableGaussianCovariance v v L (xs i) (xs j) + if i=j then (s:ℝ) else 0) := by + have h := countableFreshMarkedKernel v L (gaussianMixedTest (fun i => gaussianAverageBCF s (f i))) xs + simp only [gaussianMixedTest_apply] at h + rw [h] + obtain ⟨n,w,hw⟩ := countableGaussianCovariance_finite_gram v L r xs + have he (i j : Fin r) := congrFun (congrFun hw i) j + simp_rw [←he] + exact (freshMixedKernel_diagonal_noise f w s).symm + +variable {S : Type} [MeasurableSpace S] {k r : ℕ} + +def labelMarkedBlockKernel (q : Fin (k+1)→ℝ) (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) : + CompactBlock CompactJointOverlap r →ᵇ ℝ := + (freshMarkedMatrixKernel Ψ).compContinuous + ⟨fun Q => fun i j => if i=j then 1 else labelProfileInterpolant q (Q i j).2,by + classical + apply continuous_pi + intro i + apply continuous_pi + intro j + by_cases hij : i=j + · simp only [ite_eq_left hij]; exact continuous_const + · simp only [ite_eq_right hij]; fun_prop⟩ + +lemma labelProfile_mixed_kernel (q : Fin (k+1)→ℝ) (h0 : 0≤q 0) (hq : Monotone q) + (h1 : q (Fin.last k)≤1) (f : Fin r→ℝ →ᵇ ℝ) (xs : Fin r→S×IndexedLeaf k) : + (∫ g, ∏ i, gaussianAverageBCF (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) (f i) + (labelProfileField q g (xs i)) ∂countableGaussianLaw)= + freshMarkedMatrixKernel (gaussianMixedTest f) + (fun i j => if i=j then 1 else q (indexedCommonDepth k (xs j).2 (xs i).2)) := by + have h := countableFreshMixed_diagonal (labelProfileRow q) + (indexedGaussianRowLength (I := Fin 1) k) f (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) xs + apply h.trans + apply congrArg (freshMarkedMatrixKernel (gaussianMixedTest f)) + funext i j + rw [labelProfile_covariance q h0 hq] + by_cases hij : i=j + · subst j + simp only [ite_true,indexedCommonDepth_self] + change q (Fin.last k)+(1-q (Fin.last k))=1 + ring + · simp only [ite_eq_right hij,add_zero] + +lemma labelProfileField_product_measurable (q : Fin (k+1)→ℝ) : + Measurable (fun p : (ℕ→ℝ)×(S×IndexedLeaf k) => labelProfileField q p.1 p.2) := + countableGaussianField_measurable (v := labelProfileRow q) + (indexedGaussianRow_measurable k _ measurable_const) + (indexedGaussianRowLength_measurable (I := Fin 1) k) + +def labelMixedValue (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : Fin r→ℝ →ᵇ ℝ) + (z : ℕ→ℝ) (xs : Fin r→S×IndexedLeaf k) : ℝ := + ∏ i, gaussianAverageBCF s (f i) (labelProfileField q z (xs i)) + +lemma measurableReplicaProduct {A B : Type*} [MeasurableSpace A] [MeasurableSpace B] + (V : A→B→ℝ) (hV : Measurable (Function.uncurry V)) (f : Fin r→ℝ →ᵇ ℝ) : + Measurable (fun p : A×(Fin r→B) => ∏ i, f i (V p.1 (p.2 i))) := by + have h (i : Fin r) : Measurable (fun p : A×(Fin r→B) => f i (V p.1 (p.2 i))) := + (f i).measurable.comp (hV.comp + (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd))) + exact Finset.measurable_prod Finset.univ (fun i _ => h i) + +lemma labelMixedValue_measurable (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : Fin r→ℝ →ᵇ ℝ) : + Measurable (Function.uncurry (labelMixedValue (S:=S) q s f)) := + measurableReplicaProduct (labelProfileField q) (labelProfileField_product_measurable q) + (fun i => gaussianAverageBCF s (f i)) + +lemma labelMixedValue_bound {S : Type} [MeasurableSpace S] {k r : ℕ} + (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : Fin r→ℝ →ᵇ ℝ) + (z : ℕ→ℝ) (xs : Fin r→S×IndexedLeaf k) : + |labelMixedValue q s f z xs|≤∏ i, ‖gaussianAverageBCF s (f i)‖ := by + simp only [labelMixedValue,Finset.abs_prod] + exact Finset.prod_le_prod₀ (fun _ _ => abs_nonneg _) (fun index _ => + (gaussianAverageBCF s (f index)).norm_coe_le_norm _) + +lemma labelTwoMixed_measurable (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f g : Fin r→ℝ →ᵇ ℝ) + (F : (Fin r→S×IndexedLeaf k)→ℝ) (hF : Measurable F) : + Measurable (fun p : ((ℕ→ℝ)×(ℕ→ℝ))×(Fin r→S×IndexedLeaf k) => + F p.2 * labelMixedValue q s f p.1.1 p.2 * labelMixedValue q s g p.1.2 p.2) := by + have hf := (labelMixedValue_measurable (S:=S) q s f).comp + (measurable_fst.fst.prodMk measurable_snd : Measurable + (fun p : ((ℕ→ℝ)×(ℕ→ℝ))×(Fin r→S×IndexedLeaf k) => (p.1.1,p.2))) + have hg := (labelMixedValue_measurable (S:=S) q s g).comp + (measurable_fst.snd.prodMk measurable_snd : Measurable + (fun p : ((ℕ→ℝ)×(ℕ→ℝ))×(Fin r→S×IndexedLeaf k) => (p.1.2,p.2))) + exact ((hF.comp measurable_snd).mul hf).mul hg + +lemma labelProfile_twoMixed_fubini (q : Fin (k+1)→ℝ) (h0 : 0≤q 0) (hq : Monotone q) + (h1 : q (Fin.last k)≤1) (ν : Measure (Fin r→S×IndexedLeaf k)) [IsProbabilityMeasure ν] + (f g : Fin r→ℝ →ᵇ ℝ) (F : (Fin r→S×IndexedLeaf k)→ℝ) (hF : Measurable F) + {C : ℝ} (hC : 0≤C) (hb : ∀ xs, |F xs|≤C) : + (∫ z, ∫ xs, F xs * + (∏ i, gaussianAverageBCF (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) (f i) (labelProfileField q z.1 (xs i))) * + (∏ i, gaussianAverageBCF (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) (g i) (labelProfileField q z.2 (xs i))) ∂ν + ∂countableGaussianLaw.prod countableGaussianLaw) = + ∫ xs, F xs * freshMarkedMatrixKernel (gaussianMixedTest f) + (fun i j => if i=j then 1 else q (indexedCommonDepth k (xs j).2 (xs i).2)) * + freshMarkedMatrixKernel (gaussianMixedTest g) + (fun i j => if i=j then 1 else q (indexedCommonDepth k (xs j).2 (xs i).2)) ∂ν := by + let s : ℝ≥0 := (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) + have hm := labelTwoMixed_measurable q s f g F hF + have hi : Integrable (fun p : ((ℕ→ℝ)×(ℕ→ℝ))×(Fin r→S×IndexedLeaf k) => + F p.2 * (∏ i, gaussianAverageBCF s (f i) (labelProfileField q p.1.1 (p.2 i))) * + (∏ i, gaussianAverageBCF s (g i) (labelProfileField q p.1.2 (p.2 i)))) + ((countableGaussianLaw.prod countableGaussianLaw).prod ν) := by + apply Integrable.of_bound hm.aestronglyMeasurable + (C*(∏ i, ‖gaussianAverageBCF s (f i)‖)*(∏ i, ‖gaussianAverageBCF s (g i)‖)) + exact ae_of_all _ fun p => by + simp only [norm_mul,Real.norm_eq_abs] + exact mul_le_mul (mul_le_mul (hb _) (labelMixedValue_bound q s f p.1.1 p.2) + (abs_nonneg _) hC) (labelMixedValue_bound q s g p.1.2 p.2) + (abs_nonneg _) (mul_nonneg hC (Finset.prod_nonneg fun _ _ => norm_nonneg _)) + + rw [integral_integral_swap hi] + apply integral_congr_ae + exact ae_of_all _ fun xs => by + change (∫ z, F xs * labelMixedValue q s f z.1 xs * labelMixedValue q s g z.2 xs + ∂countableGaussianLaw.prod countableGaussianLaw)=_ + simp_rw [mul_assoc] + rw [integral_const_mul] + apply congrArg (fun y => F xs*y) + calc + _ = (∫ z, labelMixedValue q s f z xs ∂countableGaussianLaw)* + (∫ z, labelMixedValue q s g z xs ∂countableGaussianLaw) := integral_prod_mul _ _ + _ = _ := congrArg₂ (·*·) (labelProfile_mixed_kernel q h0 hq h1 f xs) + (labelProfile_mixed_kernel q h0 hq h1 g xs) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CountableSingleRestoration.lean b/lean/OAI/Probability/Perceptron/Variational/CountableSingleRestoration.lean new file mode 100644 index 0000000000000000000000000000000000000000..a751dd828a5f7d609ceae97b813bb0403c03e52f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CountableSingleRestoration.lean @@ -0,0 +1,158 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.TripleGaussianReplica +import OAI.Probability.Perceptron.Variational.SingleRestorationLaw + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +variable {I J K : Type} [Fintype I] [Fintype J] [Fintype K] + +def tripleGaussianMean (k : ℕ) + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (R : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (Q : EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (T : EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (H : EuclideanSpace ℝ I→ℝ) (G : EuclideanSpace ℝ J→ℝ) (F : EuclideanSpace ℝ K→ℝ) + (f : EuclideanSpace ℝ I→ℝ) (g : EuclideanSpace ℝ J→ℝ) + (p : TripleGaussianData I J K k) : ℝ := + indexedTerminalMean (tripleGaussianStep A B C) k (tripleGaussianTerminal H G F) + (tripleGaussianRoot R Q T p.1) (tripleGaussianObservable f g) + (p.2.1,indexedMarksZip k p.2.2) + +lemma tripleGaussianMean_measurable (k : ℕ) + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (R : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (Q : EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (T : EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (H : EuclideanSpace ℝ I→ℝ) (G : EuclideanSpace ℝ J→ℝ) (F : EuclideanSpace ℝ K→ℝ) + (hH : Measurable H) (hG : Measurable G) (hF : Measurable F) + (f : EuclideanSpace ℝ I→ℝ) (g : EuclideanSpace ℝ J→ℝ) + (hf : Measurable f) (hg : Measurable g) : + Measurable (tripleGaussianMean k A B C R Q T H G F f g) := by + have ht : Measurable (tripleGaussianTerminal H G F) := by unfold tripleGaussianTerminal; fun_prop + have ho : Measurable (tripleGaussianObservable (K:=K) f g) := by unfold tripleGaussianObservable; fun_prop + have hr : Measurable (tripleGaussianRoot R Q T) := by unfold tripleGaussianRoot; fun_prop + have hm := indexedTerminalMean_joint_measurable (tripleGaussianStep A B C) + (tripleGaussianStep_measurable A B C) k (tripleGaussianTerminal H G F) ht + (tripleGaussianObservable f g) ho + have hp : Measurable (fun p : TripleGaussianData I J K k => + (tripleGaussianRoot R Q T p.1,(p.2.1,indexedMarksZip k p.2.2))) := + (hr.comp measurable_fst).prodMk (measurable_snd.fst.prodMk + ((indexedMarksZip_measurable k).comp measurable_snd.snd)) + have hc := hm.comp hp + exact hc + +theorem countable_three_terminal_single_value (k : ℕ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 fun _ => R r) k + (fun i => tiltedStateStep (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) (gaussianLinearMarkStep A) (z i) + (finiteCascadeShifts (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) (gaussianLinearMarkStep A) k z (fun x => H (x 0)) i)) + (fun x => f (x 0)) * + rootPathMean (stdGaussian (EuclideanSpace ℝ J)) (fun r => fun _ => Q r) k + (fun i => tiltedStateStep (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) (gaussianLinearMarkStep B) (z i) + (finiteCascadeShifts (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) (gaussianLinearMarkStep B) k z (fun x => G (x 0)) i)) + (fun x => g (x 0))) := by + let : IsGaussian (gaussianMarkLaw (E:=EuclideanSpace ℝ I) : Measure (EuclideanSpace ℝ I)) := (inferInstance : IsGaussian (stdGaussian (EuclideanSpace ℝ I))) + let : IsGaussian (gaussianMarkLaw (E:=EuclideanSpace ℝ J) : Measure (EuclideanSpace ℝ J)) := (inferInstance : IsGaussian (stdGaussian (EuclideanSpace ℝ J))) + let : IsGaussian (gaussianMarkLaw (E:=EuclideanSpace ℝ K) : Measure (EuclideanSpace ℝ K)) := (inferInstance : IsGaussian (stdGaussian (EuclideanSpace ℝ K))) + have hI := gaussianLinearRecursion_realization (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) A hH k z hz0 + have hJ := gaussianLinearRecursion_realization (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) B hG k z hz0 + have hK := gaussianLinearRecursion_realization (gaussianMarkLaw (E:=EuclideanSpace ℝ K)) C hF k z hz0 + have hv := indexedTerminalMean_two_fresh_old + (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ K)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ K)) + (gaussianLinearMarkStep A) (gaussianLinearMarkStep B) (gaussianLinearMarkStep C) + (gaussianLinearMarkStep_measurable A) (gaussianLinearMarkStep_measurable B) (gaussianLinearMarkStep_measurable C) + k z hz hz0 hz1 (fun x => H (x 0)) (fun x => G (x 0)) (fun x => F (x 0)) + (hH.continuous.measurable.comp (measurable_pi_apply 0)) + (hG.continuous.measurable.comp (measurable_pi_apply 0)) + (hF.continuous.measurable.comp (measurable_pi_apply 0)) hI.2 hJ.2 hK.2 + (fun r => fun _ => R r) (fun r => fun _ => Q r) (fun r => fun _ => T r) + (by fun_prop) (by fun_prop) (by fun_prop) (fun x => f (x 0)) (fun x => g (x 0)) + (hf.comp (measurable_pi_apply 0)) (hg.comp (measurable_pi_apply 0)) D E hD hE (fun x => hfB _) (fun x => hgB _) + have hp := indexedGaussian_three_regroup_law k z I J K + have hm := tripleGaussianMean_measurable k A B C R Q T H G F hH.continuous.measurable + hG.continuous.measurable hF.continuous.measurable f g hf hg + have he := integral_map (μ:=(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((countableGaussianLaw.prod countableGaussianLaw).prod countableGaussianLaw)) + hp.measurable.aemeasurable hm.aestronglyMeasurable + rw [hp.map_eq] at he + exact he.symm.trans hv + + +lemma tripleGaussianMean_replica (k : ℕ) + (A : ℕ→EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (B : ℕ→EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (R : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I) + (Q : EuclideanSpace ℝ J →L[ℝ] EuclideanSpace ℝ J) + (T : EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (H : EuclideanSpace ℝ I→ℝ) (G : EuclideanSpace ℝ J→ℝ) (F : EuclideanSpace ℝ K→ℝ) + (hH : Measurable H) (hG : Measurable G) (hF : Measurable F) + (f : EuclideanSpace ℝ I→ℝ) (g : EuclideanSpace ℝ J→ℝ) + (b : IndexedCascadeBase k) (t : ((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ)) + (hi : Integrable (fun l => Real.exp ((H (gaussianLeafValue k A R t.1.1 l)+ + G (gaussianLeafValue k B Q t.1.2 l))+F (gaussianLeafValue k C T t.2 l))) (indexedLeafProbability k b)) : + tripleGaussianMean k A B C R Q T H G F f g (tripleGaussianCountableData (I:=I) (J:=J) (K:=K) k b t) = + gibbsReplicaMean (indexedLeafProbability k b) + (fun l => (H (gaussianLeafValue k A R t.1.1 l)+G (gaussianLeafValue k B Q t.1.2 l))+ + F (gaussianLeafValue k C T t.2 l)) 1 + (fun l => f (gaussianLeafValue k A R t.1.1 (l 0))*g (gaussianLeafValue k B Q t.1.2 (l 0))) := by + have ht : Measurable (tripleGaussianTerminal H G F) := by unfold tripleGaussianTerminal; fun_prop + unfold tripleGaussianMean + have he := indexedTerminalMean_tiltMean (tripleGaussianStep A B C) (tripleGaussianStep_measurable A B C) + k (tripleGaussianTerminal H G F) ht + (tripleGaussianRoot R Q T (tripleGaussianCountableData (I:=I) (J:=J) (K:=K) k b t).1) (tripleGaussianObservable f g) + ((tripleGaussianCountableData (I:=I) (J:=J) (K:=K) k b t).2.1,indexedMarksZip k (tripleGaussianCountableData (I:=I) (J:=J) (K:=K) k b t).2.2) + have hstate (l : IndexedLeaf k) := tripleGaussianLeafState k A B C + (fun _ => R (indexedGaussianDisorder k I t.1.1).1) + (fun _ => Q (indexedGaussianDisorder k J t.1.2).1) + (fun _ => T (indexedGaussianDisorder k K t.2).1) + (indexedGaussianDisorder k I t.1.1).2 (indexedGaussianDisorder k J t.1.2).2 + (indexedGaussianDisorder k K t.2).2 l + simp only [tripleGaussianCountableData,tripleGaussianRoot] at he ⊢ + simp only [tripleGaussianTerminal,hstate] at he + have hv := he hi + simp only [tripleGaussianObservable] at hv + rw [hv] + symm + refine (gibbsReplicaMean_coordinate_of_integrable (indexedLeafProbability k b) + (F:=fun l => f (gaussianLeafValue k A R t.1.1 l)*g (gaussianLeafValue k B Q t.1.2 l)) + (measurable_of_countable _) (measurable_of_countable _) hi 1 0).trans ?_ + congr 1 + funext l + simp only [indexedTerminalEnergy,tripleGaussianTerminal,hstate,gaussianLeafValue] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CoupledDual.lean b/lean/OAI/Probability/Perceptron/Variational/CoupledDual.lean new file mode 100644 index 0000000000000000000000000000000000000000..a8834c04fe762bd4518bcf4241c40c5781f88d60 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CoupledDual.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StationaryExistence + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma Trial.ext_fun {m n : Trial} (h : ∀ t, m t=n t) : m=n := by + cases m + cases n + congr 1 + exact funext h + +lemma weightedStepTrial_coupling_fst {I J : Type*} [Fintype I] [Fintype J] + (c : I×J → ℝ) (w : I → ℝ) (q : I → Time) + (hc : ∀ a, 0 ≤ c a) (hc1 : ∑ a, c a=1) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) + (hrow : ∀ i, ∑ j, c (i,j)=w i) : + weightedStepTrial c (fun a => q a.1) hc hc1=weightedStepTrial w q hw hw1 := by + apply Trial.ext_fun + intro t + change (∑ a : I×J, if q a.1 ≤ t then c a else 0)=∑ i, if q i ≤ t then w i else 0 + rw [Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro i _ + by_cases hi : q i ≤ t <;> simp [hi,hrow] + +lemma weightedStepTrial_coupling_snd {I J : Type*} [Fintype I] [Fintype J] + (c : I×J → ℝ) (v : J → ℝ) (p : J → Time) + (hc : ∀ a, 0 ≤ c a) (hc1 : ∑ a, c a=1) + (hv : ∀ i, 0 ≤ v i) (hv1 : ∑ i, v i=1) + (hcol : ∀ j, ∑ i, c (i,j)=v j) : + weightedStepTrial c (fun a => p a.2) hc hc1=weightedStepTrial v p hv hv1 := by + apply Trial.ext_fun + intro t + change (∑ a : I×J, if p a.2 ≤ t then c a else 0)=∑ j, if p j ≤ t then v j else 0 + rw [Fintype.sum_prod_type,Finset.sum_comm] + apply Finset.sum_congr rfl + intro j _ + by_cases hj : p j ≤ t <;> simp [hj,hcol] + +lemma coupling_sum_fst {I J : Type*} [Fintype I] [Fintype J] + (c : I×J → ℝ) (w f : I → ℝ) (hrow : ∀ i, ∑ j, c (i,j)=w i) : + (∑ a, c a*f a.1)=∑ i, w i*f i := by + rw [Fintype.sum_prod_type] + simp_rw [← Finset.sum_mul,hrow] + +lemma coupling_sum_snd {I J : Type*} [Fintype I] [Fintype J] + (c : I×J → ℝ) (v f : J → ℝ) (hcol : ∀ j, ∑ i, c (i,j)=v j) : + (∑ a, c a*f a.2)=∑ j, v j*f j := by + rw [Fintype.sum_prod_type,Finset.sum_comm] + simp_rw [← Finset.sum_mul,hcol] + +lemma weightedStepTail_coupling_fst {I J : Type*} [Fintype I] [Fintype J] + (c : I×J → ℝ) (w q : I → ℝ) (hrow : ∀ i, ∑ j, c (i,j)=w i) : + weightedStepTail c (fun a => q a.1)=weightedStepTail w q := by + funext t + exact coupling_sum_fst c w (fun i => 1-max (q i) t) hrow + +lemma weightedStepA_coupling_fst {I J : Type*} [Fintype I] [Fintype J] + (c : I×J → ℝ) (w q : I → ℝ) (hrow : ∀ i, ∑ j, c (i,j)=w i) : + weightedStepA c (fun a => q a.1)=weightedStepA w q := by + unfold weightedStepA + rw [weightedStepTail_coupling_fst c w q hrow] + +lemma entropy_coupled_stationary_comparison {I J : Type*} [Fintype I] [Fintype J] + (c : I×J → ℝ) (w h : I → ℝ) (v g : J → ℝ) (q : I → Time) (p : J → Time) + (hc : ∀ a, 0 ≤ c a) (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) + (hv : ∀ j, 0 ≤ v j) (hv1 : ∑ j, v j=1) + (hrow : ∀ i, ∑ j, c (i,j)=w i) (hcol : ∀ j, ∑ i, c (i,j)=v j) + (B : ℝ) (hB0 : 0 ≤ B) (hB1 : B < 1) + (hq : ∀ i, (q i:ℝ) ≤ B) (hp : ∀ j, (p j:ℝ) ≤ B) + (hstat : ∀ i, 2*h i=weightedStepA w (fun i => (q i:ℝ)) (q i)) : + (entropy (weightedStepTrial w q hw hw1)).toReal-∑ i, w i*h i*(q i:ℝ) ≤ + (entropy (weightedStepTrial v p hv hv1)).toReal-∑ j, v j*g j*(p j:ℝ)+ + ∑ a, c a*|h a.1-g a.2| := by + have hc1 : ∑ a, c a=1 := by rw [Fintype.sum_prod_type]; simp_rw [hrow]; exact hw1 + have hs := entropy_weightedStep_support c (fun a => p a.2) (fun a => q a.1) + hc hc1 B hB0 hB1 (fun a => hp a.2) (fun a => hq a.1) + rw [weightedStepTrial_coupling_fst c w q hc hc1 hw hw1 hrow, + weightedStepTrial_coupling_snd c v p hc hc1 hv hv1 hcol, + weightedStepA_coupling_fst c w (fun i => (q i:ℝ)) hrow] at hs + have he : (∑ a, c a*((p a.2:ℝ)-(q a.1:ℝ))*weightedStepA w (fun i => (q i:ℝ)) (q a.1))/2 = + (∑ a, c a*h a.1*(p a.2:ℝ))-(∑ i, w i*h i*(q i:ℝ)) := by + simp only [mul_assoc] + rw [← coupling_sum_fst c w (fun i => h i*(q i:ℝ)) hrow] + simp only [← mul_assoc] + rw [Finset.sum_div,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro a _ + rw [← hstat a.1] + ring + rw [he] at hs + have hb : (∑ j, v j*g j*(p j:ℝ))-(∑ a, c a*h a.1*(p a.2:ℝ)) ≤ + ∑ a, c a*|h a.1-g a.2| := by + simp only [mul_assoc] + rw [← coupling_sum_snd c v (fun j => g j*(p j:ℝ)) hcol] + simp only [← mul_assoc] + rw [← Finset.sum_sub_distrib] + apply Finset.sum_le_sum + intro a _ + have h₁ : (g a.2-h a.1)*(p a.2:ℝ) ≤ |h a.1-g a.2| := calc + _ ≤ |g a.2-h a.1| *(p a.2:ℝ) := mul_le_mul_of_nonneg_right (le_abs_self _) (p a.2).2.1 + _ ≤ |g a.2-h a.1| *1 := mul_le_mul_of_nonneg_left (p a.2).2.2 (abs_nonneg _) + _ = _ := by rw [mul_one,abs_sub_comm] + have H := mul_le_mul_of_nonneg_left h₁ (hc a) + nlinarith [H] + linarith + +lemma finiteSphericalDual_eq_stationary {k : ℕ} (w h : Fin (k+1) → ℝ) + (q : Fin (k+1) → Time) (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) + (hq : Monotone q) (hq1 : (q (Fin.last k):ℝ) < 1) + (hs : ∀ i, 2*h i=weightedStepA w (fun j => (q j:ℝ)) (q i)) : + sInf (finiteSphericalDualValues w h hw hw1)=finiteSphericalDualObjective w h hw hw1 q := by + apply IsLeast.csInf_eq + refine ⟨⟨q,⟨hq,hq1⟩,rfl⟩,?_⟩ + rintro a ⟨p,⟨hp,hp1⟩,rfl⟩ + exact stationary_finite_entropy_minimizes w h q p hw hw1 hq hp hq1 hp1 hs + +theorem finiteSphericalDual_abs_sub_le {k : ℕ} (w h g : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) + (hh : Monotone h) (hh0 : 0 ≤ h 0) (hg : Monotone g) (hg0 : 0 ≤ g 0) : + |sInf (finiteSphericalDualValues w h (fun i => (hw i).le) hw1)- + sInf (finiteSphericalDualValues w g (fun i => (hw i).le) hw1)| ≤ + ∑ i, w i*|h i-g i| := by + classical + obtain ⟨q,hq,hq1,hsq⟩ := exists_finite_stationary_quantile w h hw hw1 hh hh0 + obtain ⟨p,hp,hp1,hsp⟩ := exists_finite_stationary_quantile w g hw hw1 hg hg0 + rw [finiteSphericalDual_eq_stationary w h q (fun i => (hw i).le) hw1 hq hq1 hsq, + finiteSphericalDual_eq_stationary w g p (fun i => (hw i).le) hw1 hp hp1 hsp] + let c : Fin (k+1)×Fin (k+1) → ℝ := fun a => if a.1=a.2 then w a.1 else 0 + have hc : ∀ a, 0 ≤ c a := by intro a; dsimp [c]; split_ifs; exact (hw a.1).le; rfl + have hr : ∀ i, ∑ j, c (i,j)=w i := by intro i; simp [c] + have he : ∀ j, ∑ i, c (i,j)=w j := by intro j; simp [c] + let B := max (q (Fin.last k):ℝ) (p (Fin.last k):ℝ) + have hB0 : 0 ≤ B := (q (Fin.last k)).2.1.trans (le_max_left _ _) + have hB1 : B < 1 := max_lt hq1 hp1 + have hQ (i : Fin (k+1)) : (q i:ℝ) ≤ B := + (show (q i:ℝ) ≤ (q (Fin.last k):ℝ) from hq (Fin.le_last i)).trans (le_max_left _ _) + have hP (i : Fin (k+1)) : (p i:ℝ) ≤ B := + (show (p i:ℝ) ≤ (p (Fin.last k):ℝ) from hp (Fin.le_last i)).trans (le_max_right _ _) + have H := entropy_coupled_stationary_comparison c w h w g q p hc + (fun i => (hw i).le) hw1 (fun i => (hw i).le) hw1 hr he B hB0 hB1 hQ hP hsq + have H' := entropy_coupled_stationary_comparison c w g w h p q hc + (fun i => (hw i).le) hw1 (fun i => (hw i).le) hw1 hr he B hB0 hB1 hP hQ hsp + have hsum : (∑ a, c a*|h a.1-g a.2|)=∑ i, w i*|h i-g i| := by + simp only [Fintype.sum_prod_type,c,ite_mul,zero_mul] + simp + have hsum' : (∑ a, c a*|g a.1-h a.2|)=∑ i, w i*|h i-g i| := by + simp only [Fintype.sum_prod_type,c,ite_mul,zero_mul] + simp [abs_sub_comm] + rw [hsum] at H + rw [hsum'] at H' + unfold finiteSphericalDualObjective + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CouplingAffine.lean b/lean/OAI/Probability/Perceptron/Variational/CouplingAffine.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ec5f9ae0a073c88275b710b82ed83ef833ddc57 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CouplingAffine.lean @@ -0,0 +1,134 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.TiltMeanCenteredAbsSq +import OAI.Probability.Perceptron.Variational.GaussianCoupling +import OAI.Probability.Perceptron.Variational.IndexedGaussianCovariance + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma sourceEnrichedFeature_add_single (N : ℕ) (p : Fin N → ℕ) (u : Fin N → ℝ) + (j : Fin N) (a : ℝ) (x : NormalizedSpin N) (i : EnrichedIndex N N p) : + sourceEnrichedFeature N p (u+Pi.single j a) x i = + sourceEnrichedFeature N p u x i+ + a*perturbationAmplitude N (fun _ => 1) j*sourceGaussianTestFeature N p j x i := by + classical + cases i with + | inl i => simp [sourceEnrichedFeature,sourceGaussianTestFeature,enrichedFeature] + | inr i => + rcases i with ⟨l,r⟩ + by_cases hl : l=j + · subst l + simp only [sourceEnrichedFeature,sourceGaussianTestFeature,enrichedFeature,perturbationAmplitude, + Pi.add_apply,Pi.single_eq_same,mul_one] + ring + · simp [sourceEnrichedFeature,sourceGaussianTestFeature,enrichedFeature,perturbationAmplitude, + Pi.single_apply,hl] + +lemma sourceGaussianRow_add_single {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) + (u : Fin N → ℝ) (j : Fin N) (a : ℝ) (i : ℕ) (x : NormalizedSpin N×IndexedLeaf k) : + sourceGaussianRow p d h (u+Pi.single j a) i x = + sourceGaussianRow p d h u i x+ + a*perturbationAmplitude N (fun _ => 1) j*sourceGaussianTestRow p d h j i x := by + unfold sourceGaussianRow sourceGaussianTestRow indexedGaussianRow finiteGaussianRow + simp_rw [sourceEnrichedFeature_add_single] + rw [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro q _ + split_ifs <;> ring + +lemma enrichedIndexedHamiltonian_add_single (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (v : ℝ) (g : ℕ → ℝ) + (x : NormalizedSpin (n+1)×IndexedLeaf k) : + enrichedIndexedHamiltonian n M k f a p d h (u+Pi.single j v) g x = + enrichedIndexedHamiltonian n M k f a p d h u g x+ + v*perturbationAmplitude (n+1) (fun _ => 1) j* + countableGaussianField (sourceGaussianTestRow p d h j) + (indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) k) g x := by + unfold enrichedIndexedHamiltonian countableGaussianHamiltonian + have hr : sourceGaussianRow p d h (u+Pi.single j v) = fun i x => + sourceGaussianRow p d h u i x+ + (v*perturbationAmplitude (n+1) (fun _ => 1) j)*sourceGaussianTestRow p d h j i x := by + funext i x + exact sourceGaussianRow_add_single p d h u j v i x + rw [hr,countableGaussianField_add,countableGaussianField_smul] + ring + +lemma coupling_log_contDiff {S : Type*} [MeasurableSpace S] (μ : Measure S) + [IsProbabilityMeasure μ] {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) : + ContDiff ℝ 2 (fun b => Real.log (tiltPartition μ (fun x => H x+b*Y x) 1)) := by + let ρ := μ.withDensity (fun x => ENNReal.ofReal (Real.exp (H x))) + have hf : cgf Y ρ = (fun b => Real.log (tiltPartition μ (fun x => H x+b*Y x) 1)) := by + funext b + exact congrArg Real.log (coupling_mgf_identity μ hH b) + rw [← hf,contDiff_iff_contDiffAt] + intro a + apply AnalyticAt.contDiffAt + apply analyticAt_cgf + rw [coupling_expSet μ hH hY he,interior_univ] + trivial + +lemma coupling_log_convex {S : Type*} [MeasurableSpace S] (μ : Measure S) + [IsProbabilityMeasure μ] {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) : + ConvexOn ℝ univ (fun b => Real.log (tiltPartition μ (fun x => H x+b*Y x) 1)) := by + have hs := coupling_log_contDiff μ hH hY he + apply convexOn_of_deriv2_nonneg' convex_univ + (hs.differentiable (by norm_num)).differentiableOn + ( (ContDiff.deriv' (n := 1) hs).differentiable (by norm_num)).differentiableOn + intro a _ + rw [← iteratedDeriv_eq_iterate,coupling_log_second_derivative μ hH hY he] + exact tiltMean_nonneg μ (fun _ => sq_nonneg _) 1 + +lemma convex_derivative_local_bound {F D : ℝ → ℝ} + (hc : ConvexOn ℝ univ F) (hd : ∀ x, HasDerivAt F (D x) x) (u v : ℝ) + (hv : v ∈ Ioo (u-1) (u+1)) : + |D v| ≤ |F (u-2)|+|F (u-1)|+|F (u+1)|+|F (u+2)| := by + have hmono : Monotone D := by + intro x y hxy + simpa only [(hd x).deriv,(hd y).deriv] using + hc.monotoneOn_deriv (fun x _ => (hd x).differentiableAt) (mem_univ x) (mem_univ y) hxy + have hl := hc.slope_le_of_hasDerivAt (mem_univ (u-2)) (mem_univ (u-1)) + (by linarith : u-2 < u-1) (hd (u-1)) + have hr := hc.le_slope_of_hasDerivAt (mem_univ (u+1)) (mem_univ (u+2)) + (by linarith : u+1 < u+2) (hd (u+1)) + have hl' : F (u-1)-F (u-2) ≤ D v := by + have hh : (u-1)-(u-2) = (1:ℝ) := by ring + simp only [slope,hh,inv_one,one_smul] at hl + exact hl.trans (hmono hv.1.le) + have hr' : D v ≤ F (u+2)-F (u+1) := by + have hh : (u+2)-(u+1) = (1:ℝ) := by ring + simp only [slope,hh,inv_one,one_smul] at hr + exact (hmono hv.2.le).trans hr + apply abs_le.mpr + constructor + · linarith [neg_abs_le (F (u-1)),le_abs_self (F (u-2)),abs_nonneg (F (u+1)),abs_nonneg (F (u+2))] + · linarith [le_abs_self (F (u+2)),neg_abs_le (F (u+1)),abs_nonneg (F (u-1)),abs_nonneg (F (u-2))] + +lemma annealed_convex_hasDerivAt {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) + {F D : ℝ → Ω → ℝ} (hF : ∀ t, AEStronglyMeasurable (F t) P) + (hD : ∀ t, AEStronglyMeasurable (D t) P) (hi : ∀ t, Integrable (F t) P) + (hc : ∀ᵐ ω ∂P, ConvexOn ℝ univ (fun t => F t ω) ∧ ∀ t, HasDerivAt (fun t => F t ω) (D t ω) t) + (u : ℝ) : + Integrable (D u) P ∧ HasDerivAt (fun t => ∫ ω, F t ω ∂P) (∫ ω, D u ω ∂P) u := by + let B : Ω → ℝ := fun ω => |F (u-2) ω|+|F (u-1) ω|+|F (u+1) ω|+|F (u+2) ω| + apply hasDerivAt_integral_of_dominated_loc_of_deriv_le + (Ioo_mem_nhds (by linarith : u-1 < u) (by linarith : u < u+1)) + (Eventually.of_forall hF) (hi u) (hD u) + · filter_upwards [hc] with ω hω t ht + rw [Real.norm_eq_abs] + exact convex_derivative_local_bound hω.1 hω.2 u t ht + · exact (((hi (u-2)).abs.add (hi (u-1)).abs).add (hi (u+1)).abs).add (hi (u+2)).abs + · filter_upwards [hc] with ω hω t _ + exact hω.2 t + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CouplingDerivative.lean b/lean/OAI/Probability/Perceptron/Variational/CouplingDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..336a51a17a85115d180721978a8e678575582229 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CouplingDerivative.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.EnergyMean +import OAI.Probability.Perceptron.Variational.GaussianAbsoluteEnergyBound + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma sourceExpectedPressure_coordinate_derivative (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 ∫ a, sourceKernelPressure n k f p d (u+Pi.single j r) h a ∂P) D 0 ∧ + D = (1/(n+1:ℕ))*(perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j* + ((k:ℝ)/(k+1:ℕ))^(d j)- + ∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) + (sourceCouplingHamiltonian n k f p d h u a) 2 + (fun x => sourceCouplingCovariance n k p d u j (x 1) (x 0)) ∂P) := by + dsimp only + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + have hi (r : ℝ) : Integrable (sourceKernelPressure n k f p d (u+Pi.single j r) h) P := by + have hr := sourceKernelPressure_memLp n k f p d (u+Pi.single j r) h z hz hz0 hz1 t + exact hr.integrable (by norm_num) + have hreg := sourceCoupling_regular_ae n k f p d h hh0 hh u j z t + have hd := annealed_convex_hasDerivAt P (D := sourceCouplingMean n k f p d h u j) + (fun r => (hi r).aestronglyMeasurable) + (fun r => (sourceCoupling_observables_measurable n k f p d h u j r).1.aestronglyMeasurable) + hi (hreg.mono fun a ha => ⟨ha.2.1,ha.2.2.1⟩) 0 + refine ⟨_,hd.2,?_⟩ + simp only [sourceCouplingMean,zero_mul,add_zero,integral_const_mul] + rw [sourceCoupling_energy_mean n k f p d h hh0 hh u j z t + (sourceCoupling_abs_energy_integrable n k f p d h hh0 hh u j z t)] + +lemma sourceExpectedPressure_coordinate_derivative_bound (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 ∫ a, sourceKernelPressure n k f p d (u+Pi.single j r) h a + ∂((sourceBaseDataLaw n k z t).prod countableGaussianLaw)) D 0 ∧ + |D| ≤ 2*|perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j|/(n+1:ℕ) := by + obtain ⟨D,hD,rfl⟩ := sourceExpectedPressure_coordinate_derivative n k f p d h hh0 hh u j z hz hz0 hz1 t + refine ⟨_,hD,?_⟩ + let C := |perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j| + have hcov (a : SourceBaseData n k × (ℕ → ℝ)) : + |gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (sourceCouplingHamiltonian n k f p d h u a) 2 + (fun x => sourceCouplingCovariance n k p d u j (x 1) (x 0))| ≤ C := + tiltMean_bound_general _ (replicaPotential_measurable (sourceCouplingHamiltonian_section n k f p d h u a) 2) + (sourceCouplingCovariance_measurable n k 2 p d u j 1 0) + (abs_nonneg _) (fun x => sourceCouplingCovariance_bound n k p d u j _ _) + have hci : |∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) + (sourceCouplingHamiltonian n k f p d h u a) 2 + (fun x => sourceCouplingCovariance n k p d u j (x 1) (x 0)) + ∂((sourceBaseDataLaw n k z t).prod countableGaussianLaw)| ≤ C := by + simpa only [Real.norm_eq_abs,probReal_univ,mul_one] using norm_integral_le_of_norm_le_const + (μ := ((sourceBaseDataLaw n k z t).prod countableGaussianLaw)) + (f := fun a => gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (sourceCouplingHamiltonian n k f p d h u a) 2 + (fun x => sourceCouplingCovariance n k p d u j (x 1) (x 0))) + (ae_of_all _ fun a => by simpa only [Real.norm_eq_abs] using hcov a) + have hk : |((k:ℝ)/(k+1:ℕ))^(d j)| ≤ 1 := by + rw [abs_of_nonneg (pow_nonneg (by positivity) _)] + apply pow_le_one₀ (by positivity) + apply (div_le_one₀ (by positivity : (0:ℝ)<(k+1:ℕ))).mpr + exact_mod_cast Nat.le_succ k + have hdiag : |perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j* + ((k:ℝ)/(k+1:ℕ))^(d j)| ≤ C := by + rw [abs_mul] + exact (mul_le_mul_of_nonneg_left hk (abs_nonneg _)).trans_eq (mul_one _) + have hsum := (abs_sub _ _).trans (add_le_add hdiag hci) + rw [abs_mul,abs_of_pos (by positivity : (0:ℝ)<1/(n+1:ℕ))] + calc + _ ≤ (1/(n+1:ℕ))*(C+C) := mul_le_mul_of_nonneg_left hsum (by positivity) + _ = _ := by dsimp [C]; ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CouplingKernel.lean b/lean/OAI/Probability/Perceptron/Variational/CouplingKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..701d309ddd15f985f5e5d2a47ddd1f81d08b1fd0 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CouplingKernel.lean @@ -0,0 +1,234 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ReplicaIBP +import OAI.Probability.Perceptron.Variational.EnrichedVarianceBound +import OAI.Probability.Perceptron.Variational.UnboundedContact + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +abbrev SourceBaseData (n k : ℕ) := ℕ × ((ℕ → Fin (n+1) → ℝ) × IndexedCascadeBase k) + +def sourceBaseDataLaw (n k : ℕ) (z : Fin k → ℝ) (t : ℝ≥0) : Measure (SourceBaseData n k) := + (poissonMeasure ((n+1:ℕ)*t)).prod ((infinitePatternRowsLaw (n+1)).prod + (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k))) + +instance (n k : ℕ) (z : Fin k → ℝ) (t : ℝ≥0) : IsProbabilityMeasure (sourceBaseDataLaw n k z t) := by + unfold sourceBaseDataLaw + infer_instance + +def sourceDisorderReassoc (n k : ℕ) (a : SourceBaseData n k × (ℕ → ℝ)) : SourceIndexedDisorder n k := + (a.1.1,(a.1.2.1,(a.1.2.2,a.2))) + +lemma sourceDisorderReassoc_preserving (n k : ℕ) (z : Fin k → ℝ) (t : ℝ≥0) : + MeasurePreserving (sourceDisorderReassoc n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) (sourceIndexedDisorderLaw n k z t) := by + let K := poissonMeasure ((n+1:ℕ)*t) + let R := infinitePatternRowsLaw (n+1) + let B := (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) + exact ((MeasurePreserving.id K).prod (measurePreserving_prodAssoc R B countableGaussianLaw)).comp + (measurePreserving_prodAssoc K (R.prod B) countableGaussianLaw) + +def indexedLeafKernel (k : ℕ) : Kernel (IndexedCascadeBase k) (IndexedLeaf k) := + ⟨indexedLeafProbability k,indexedLeafProbability_measurable k⟩ + +instance (k : ℕ) : IsMarkovKernel (indexedLeafKernel k) := ⟨fun b => indexedLeafProbability_isProbability k b⟩ + +def sourceSpinLeafKernel (n k : ℕ) : Kernel (SourceBaseData n k) (NormalizedSpin (n+1) × IndexedLeaf k) := + (Kernel.const _ (unitSphereLaw (n+1))).prod + ((indexedLeafKernel k).comap + (fun a : SourceBaseData n k => a.2.2) (by fun_prop)) + +lemma sourceSpinLeafKernel_apply (n k : ℕ) (a : SourceBaseData n k) : + sourceSpinLeafKernel n k a = enrichedIndexedBaseMeasure n k a.2.2 := by + rw [sourceSpinLeafKernel,Kernel.prod_apply] + rfl + +instance (n k : ℕ) : IsMarkovKernel (sourceSpinLeafKernel n k) := by + constructor + intro a + rw [sourceSpinLeafKernel_apply] + infer_instance + +def sourceBaseEnergy (n k : ℕ) (f : ℝ →ᵇ ℝ) (h : Fin (k+1) → ℝ) + (a : SourceBaseData n k) : NormalizedSpin (n+1) × IndexedLeaf k → ℝ := + enrichedIndexedBoundedEnergy n a.1 k f (patternPrefix (n+1) a.1 a.2.1) h + +lemma sourceBaseEnergy_measurable (n k : ℕ) (f : ℝ →ᵇ ℝ) (h : Fin (k+1) → ℝ) : + Measurable (Function.uncurry (sourceBaseEnergy n k f h)) := by + have hm : Measurable (fun a : ℕ × (((ℕ → Fin (n+1) → ℝ) × IndexedCascadeBase k) × + (NormalizedSpin (n+1) × IndexedLeaf k)) => + sourceBaseEnergy n k f h (a.1,a.2.1) a.2.2) := by + apply measurable_from_prod_countable_right + intro M + exact ((normalizedPatternEnergy_continuous (n+1) M f).measurable.comp + (((patternPrefix_measurable (n+1) M).comp measurable_fst.fst).prodMk measurable_snd.fst)).sub measurable_const + exact hm.comp (measurable_fst.fst.prodMk (measurable_fst.snd.prodMk measurable_snd)) + +lemma sourceBaseData_regular (n k : ℕ) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 a.2.2) + (sourceBaseDataLaw n k z t) (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) := + measurePreserving_snd.comp measurePreserving_snd + exact hp.quasiMeasurePreserving.ae ((indexedCascadeGood_ae k z hz0 hz1).and + (indexedLeafMeasure_regular k z hz hz0 hz1)) + +def sourceKernelPressure (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) + (a : SourceBaseData n k × (ℕ → ℝ)) : ℝ := + (1/(n+1:ℕ))*Real.log (tiltPartition (sourceSpinLeafKernel n k a.1) + (enrichedIndexedHamiltonian n a.1.1 k f (patternPrefix (n+1) a.1.1 a.1.2.1) p d h u a.2) 1) + +lemma sourceKernelPressure_eq (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (a : SourceBaseData n k × (ℕ → ℝ)) + (ha : IndexedCascadeGood k a.1.2.2) (ha' : 0 < ((indexedLeafMeasure k a.1.2.2) univ).toReal) + (u : Fin (n+1) → ℝ) : + sourceKernelPressure n k f p d u h a = sourceIndexedPressure n k f p d u h (sourceDisorderReassoc n k a) := by + rw [sourceKernelPressure,sourceSpinLeafKernel_apply,enrichedIndexedHamiltonian_partition _ _ _ _ _ _ _ _ _ _ _ ha ha'] + rfl + +lemma sourceKernelPressure_ae (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 (ha u).symm + +lemma sourceKernelPressure_variance (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 ha u + rw [variance_congr he] + have hl := sourceIndexedPressure_memLp n k f p d u h z hz hz0 hz1 t + rw [(sourceDisorderReassoc_preserving n k z t).variance_fun_comp hl.aestronglyMeasurable.aemeasurable] + exact sourceIndexedPressure_variance n k f p d u h z hz hz0 hz1 hu hH hh t ht + +lemma measurable_disorder_state_lift {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] + {F : (ℕ → ℝ) → S → ℝ} (hF : Measurable (Function.uncurry F)) : + Measurable (fun a : (A × (ℕ → ℝ)) × S => F a.1.2 a.2) := + hF.comp (measurable_fst.snd.prodMk measurable_snd) + +def sourceCouplingHamiltonian (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (a : SourceBaseData n k × (ℕ → ℝ)) := + enrichedIndexedHamiltonian n a.1.1 k f (patternPrefix (n+1) a.1.1 a.1.2.1) p d h u a.2 + +def sourceCouplingEnergy (n k : ℕ) (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (j : Fin (n+1)) (a : SourceBaseData n k × (ℕ → ℝ)) + (x : NormalizedSpin (n+1) × IndexedLeaf k) := + perturbationAmplitude (n+1) (fun _ => 1) j* + countableGaussianField (sourceGaussianTestRow p d h j) + (indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) k) a.2 x + +lemma sourceCouplingBase_measurable (n k : ℕ) (f : ℝ →ᵇ ℝ) (h : Fin (k+1) → ℝ) : + Measurable (fun a : (SourceBaseData n k × (ℕ → ℝ)) × + (NormalizedSpin (n+1) × IndexedLeaf k) => sourceBaseEnergy n k f h a.1.1 a.2) := + (sourceBaseEnergy_measurable n k f h).comp (measurable_fst.fst.prodMk measurable_snd) + +lemma sourceCouplingField_measurable (n k : ℕ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) : + Measurable (fun a : (SourceBaseData n k × (ℕ → ℝ)) × + (NormalizedSpin (n+1) × IndexedLeaf k) => + countableGaussianField (sourceGaussianRow p d h u) + (indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) k) a.1.2 a.2) := + measurable_disorder_state_lift (countableGaussianField_measurable + (sourceGaussianRow_measurable p d h u) (indexedGaussianRowLength_measurable k)) + +lemma sourceCouplingHamiltonian_measurable (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) : + Measurable (Function.uncurry (sourceCouplingHamiltonian n k f p d h u)) := by + exact (sourceCouplingBase_measurable n k f h).add (sourceCouplingField_measurable n k p d h u) + +lemma sourceCouplingEnergy_measurable (n k : ℕ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (j : Fin (n+1)) : + Measurable (Function.uncurry (sourceCouplingEnergy n k p d h j)) := + ((countableGaussianField_measurable (sourceGaussianTestRow_measurable p d h j) + (indexedGaussianRowLength_measurable k)).comp + (measurable_fst.snd.prodMk measurable_snd)).const_mul _ + +lemma sourceKernelPressure_shift (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (r : ℝ) + (a : SourceBaseData n k × (ℕ → ℝ)) : + sourceKernelPressure n k f p d (u+Pi.single j r) h a = + (1/(n+1:ℕ))*Real.log (tiltPartition (sourceSpinLeafKernel n k a.1) + (fun x => sourceCouplingHamiltonian n k f p d h u a x+r*sourceCouplingEnergy n k p d h j a x) 1) := by + unfold sourceKernelPressure + congr 3 + funext x + exact (enrichedIndexedHamiltonian_add_single n _ k f _ p d h u j r a.2 x).trans (by simp only [sourceCouplingHamiltonian,sourceCouplingEnergy,mul_assoc]) + +lemma sourceCoupling_all_exp_ae (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (z : Fin k → ℝ) (t : ℝ≥0) : + ∀ᵐ a ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw, ∀ r : ℝ, + Integrable (fun x => Real.exp (sourceCouplingHamiltonian n k f p d h u a x+ + r*sourceCouplingEnergy n k p d h j a x)) (sourceSpinLeafKernel n k a.1) := by + have he := kernelGaussian_all_coupling_exp_ae (sourceSpinLeafKernel n k) (sourceBaseDataLaw n k z t) + (sourceBaseEnergy_measurable n k f h) (sourceGaussianRow_measurable p d h u) + (sourceGaussianTestRow_measurable p d h j) (indexedGaussianRowLength_measurable k) + (fun a => enrichedIndexedBoundedEnergy_bound n a.1 k f (patternPrefix (n+1) a.1 a.2.1) h) + (sourceGaussianRow_square_bound p d h u hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l))) + (sourceGaussianTestRow_square_bound p d h hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l)) j) + filter_upwards [he] with a ha r + simpa only [sourceCouplingHamiltonian,enrichedIndexedHamiltonian,sourceBaseEnergy, + sourceCouplingEnergy,mul_assoc] using ha (r*perturbationAmplitude (n+1) (fun _ => 1) j) + +lemma sourceCouplingHamiltonian_section (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (a : SourceBaseData n k × (ℕ → ℝ)) : + Measurable (sourceCouplingHamiltonian n k f p d h u a) := + (sourceCouplingHamiltonian_measurable n k f p d h u).of_uncurry_left + +lemma sourceCouplingEnergy_section (n k : ℕ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (j : Fin (n+1)) (a : SourceBaseData n k × (ℕ → ℝ)) : + Measurable (sourceCouplingEnergy n k p d h j a) := + (sourceCouplingEnergy_measurable n k p d h j).of_uncurry_left + +lemma sourceCoupling_regular_ae (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (z : Fin k → ℝ) (t : ℝ≥0) : + ∀ᵐ a ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw, + let F := fun r => sourceKernelPressure n k f p d (u+Pi.single j r) h a + let H := sourceCouplingHamiltonian n k f p d h u a + let Y := sourceCouplingEnergy n k p d h j a + let μ := sourceSpinLeafKernel n k a.1 + ContDiff ℝ 2 F ∧ ConvexOn ℝ univ F ∧ + (∀ r, HasDerivAt F ((1/(n+1:ℕ))*tiltMean μ (fun x => H x+r*Y x) Y 1) r) ∧ + (∀ r, iteratedDeriv 2 F r = (1/(n+1:ℕ))*tiltMean μ (fun x => H x+r*Y x) + (fun x => (Y x-tiltMean μ (fun x => H x+r*Y x) Y 1)^2) 1) := by + filter_upwards [sourceCoupling_all_exp_ae n k f p d h hh0 hh u j z t] with a ha + dsimp only + simp_rw [sourceKernelPressure_shift] + have hH := sourceCouplingHamiltonian_section n k f p d h u a + have hY := sourceCouplingEnergy_section n k p d h j a + refine ⟨contDiff_const.mul (coupling_log_contDiff _ hH hY ha), + (coupling_log_convex _ hH hY ha).smul (by positivity),?_,?_⟩ + · intro r + exact (coupling_log_hasDerivAt _ hH hY ha r).const_mul _ + · intro r + rw [iteratedDeriv_const_mul_field] + congr 1 + exact coupling_log_second_derivative _ hH hY ha r + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/CovarianceMatrix.lean b/lean/OAI/Probability/Perceptron/Variational/CovarianceMatrix.lean new file mode 100644 index 0000000000000000000000000000000000000000..f4c87d5ca0ec0ede08f8c202b6eaf51dbd108b00 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/CovarianceMatrix.lean @@ -0,0 +1,413 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder + +abbrev CovarianceMatrix (ι : Type*) [Fintype ι] [DecidableEq ι] := {C : Matrix ι ι ℝ // C.PosSemidef} + +instance covarianceMatrixMeasurableSpace (ι : Type*) [Fintype ι] [DecidableEq ι] : + MeasurableSpace (CovarianceMatrix ι) := + inferInstanceAs (MeasurableSpace {C : ι → ι → ℝ // Matrix.PosSemidef C}) + +instance covarianceMatrixBorelSpace (ι : Type*) [Fintype ι] [DecidableEq ι] : + BorelSpace (CovarianceMatrix ι) := + inferInstanceAs (BorelSpace {C : ι → ι → ℝ // Matrix.PosSemidef C}) + +def gaussianCovarianceLaw {ι : Type*} [Fintype ι] [DecidableEq ι] (p : EuclideanSpace ℝ ι × CovarianceMatrix ι) : + ProbabilityMeasure (EuclideanSpace ℝ ι) := ⟨multivariateGaussian p.1 p.2.val, inferInstance⟩ + +lemma gaussianCovarianceLaw_continuous {ι : Type*} [Fintype ι] [DecidableEq ι] : + Continuous (gaussianCovarianceLaw (ι := ι)) := by + classical + have : SequentialSpace (EuclideanSpace ℝ ι × CovarianceMatrix ι) := + inferInstanceAs (SequentialSpace (EuclideanSpace ℝ ι × {C : ι → ι → ℝ // Matrix.PosSemidef C})) + rw [continuous_iff_seqContinuous] + intro p p₀ hp + apply ProbabilityMeasure.tendsto_of_tendsto_charFun + intro t + change Tendsto (fun n => charFun (multivariateGaussian (p n).1 (p n).2.val) t) atTop + (𝓝 (charFun (multivariateGaussian p₀.1 p₀.2.val) t)) + simp_rw [charFun_multivariateGaussian (p _).2.property,charFun_multivariateGaussian p₀.2.property] + have hc : Continuous (fun q : EuclideanSpace ℝ ι × CovarianceMatrix ι => + Complex.exp (((inner ℝ t q.1 : ℝ) : ℂ)*Complex.I - + ((∑ i, t i * ∑ j, q.2.val i j * t j : ℝ) : ℂ)/2)) := by + have he (i j : ι) : Continuous (fun q : EuclideanSpace ℝ ι × CovarianceMatrix ι => q.2.val i j) := + (show Continuous (fun q : EuclideanSpace ℝ ι × CovarianceMatrix ι => q.2.val) from + continuous_subtype_val.comp continuous_snd).matrix_elem i j + have hi : Continuous (fun q : EuclideanSpace ℝ ι × CovarianceMatrix ι => inner ℝ t q.1) := + continuous_const.inner continuous_fst + exact ((Complex.continuous_ofReal.comp hi).mul continuous_const |>.sub + ((Complex.continuous_ofReal.comp (continuous_finsetSum _ fun i _ => continuous_const.mul + (continuous_finsetSum _ fun j _ => (he i j).mul continuous_const))).div_const 2)).cexp + exact hc.continuousAt.tendsto.comp hp + +lemma gaussianCovariance_integral_continuous {ι : Type*} [Fintype ι] [DecidableEq ι] + (f : EuclideanSpace ℝ ι →ᵇ ℝ) : + Continuous (fun p : EuclideanSpace ℝ ι × CovarianceMatrix ι => + ∫ x, f x ∂multivariateGaussian p.1 p.2.val) := + (ProbabilityMeasure.continuous_integral_boundedContinuousFunction f).comp gaussianCovarianceLaw_continuous + +lemma gaussianCovariance_integral_tendsto {ι : Type*} [Fintype ι] [DecidableEq ι] + {m : ℕ → EuclideanSpace ℝ ι} {m₀ : EuclideanSpace ℝ ι} + {C : ℕ → CovarianceMatrix ι} {C₀ : CovarianceMatrix ι} + (hm : Tendsto m atTop (𝓝 m₀)) (hC : Tendsto C atTop (𝓝 C₀)) + (f : EuclideanSpace ℝ ι →ᵇ ℝ) : + Tendsto (fun n => ∫ x, f x ∂multivariateGaussian (m n) (C n).val) atTop + (𝓝 (∫ x, f x ∂multivariateGaussian m₀ C₀.val)) := + (gaussianCovariance_integral_continuous f).continuousAt.tendsto.comp (hm.prodMk_nhds hC) + +section GaussianRows +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] {ι : Type*} [Fintype ι] [DecidableEq ι] + +def gaussianRows (v : ι → E) : E →L[ℝ] EuclideanSpace ℝ ι := + (PiLp.continuousLinearEquiv 2 ℝ (fun _ : ι => ℝ)).symm.toContinuousLinearMap.comp + (ContinuousLinearMap.pi fun i => innerSL ℝ (v i)) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Fintype ι] [DecidableEq ι] in +lemma gaussianRows_apply (v : ι → E) (x : E) (i : ι) : + gaussianRows v x i = inner ℝ (v i) x := rfl + +omit [MeasurableSpace E] [BorelSpace E] in +lemma gaussianRows_adjoint_basis (v : ι → E) (i : ι) : + (gaussianRows v).adjoint (EuclideanSpace.basisFun ι ℝ i) = v i := by + apply ext_inner_left ℝ + intro x + rw [ContinuousLinearMap.adjoint_inner_right] + simp [PiLp.inner_apply, gaussianRows_apply,real_inner_comm] + +lemma gaussianRows_map_stdGaussian (v : ι → E) : + (stdGaussian E).map (gaussianRows v) = multivariateGaussian 0 (Matrix.gram ℝ v) := by + apply IsGaussian.ext + · simp only [id_eq] + rw [ContinuousLinearMap.integral_id_map IsGaussian.integrable_id] + simp only [integral_id_stdGaussian,map_zero,integral_id_multivariateGaussian] + rw [← ContinuousLinearMap.toBilinForm_inj] + apply LinearMap.BilinForm.ext_basis (EuclideanSpace.basisFun ι ℝ).toBasis + intro i j + simp only [ContinuousLinearMap.toBilinForm_apply,OrthonormalBasis.coe_toBasis] + rw [covarianceBilin_map IsGaussian.memLp_two_id,gaussianRows_adjoint_basis, + gaussianRows_adjoint_basis,covarianceBilin_stdGaussian, + covarianceBilin_multivariateGaussian (Matrix.posSemidef_gram ℝ v)] + simp + rfl + +end GaussianRows + +def gaussianReplicaTest {ι : Type*} [Fintype ι] (f : ℝ →ᵇ ℝ) : EuclideanSpace ℝ ι →ᵇ ℝ := + ∏ i, f.compContinuous ⟨fun z => z i, by fun_prop⟩ + +lemma gaussianReplicaTest_apply {ι : Type*} [Fintype ι] (f : ℝ →ᵇ ℝ) (z : EuclideanSpace ℝ ι) : + gaussianReplicaTest f z = ∏ i, f (z i) := by simp [gaussianReplicaTest] + +lemma freshPattern_moment_covariance_integral + {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] (μ : Measure E) [IsProbabilityMeasure μ] + (f : ℝ →ᵇ ℝ) (n : ℕ) : + (∫ g, (∫ x, f (inner ℝ x g) ∂μ)^n ∂stdGaussian E) = + ∫ xs : Fin n → E, ∫ z, gaussianReplicaTest f z + ∂multivariateGaussian 0 (Matrix.gram ℝ xs) ∂Measure.pi (fun _ => μ) := by + classical + let F : (E × (Fin n → E)) →ᵇ ℝ := + ∏ i, f.compContinuous ⟨fun p => inner ℝ (p.2 i) p.1, by fun_prop⟩ + have hF (g : E) (xs : Fin n → E) : F (g,xs) = ∏ i, f (inner ℝ (xs i) g) := by simp [F] + calc + _ = ∫ g, ∫ xs : Fin n → E, F (g,xs) ∂Measure.pi (fun _ => μ) ∂stdGaussian E := by + apply integral_congr_ae + filter_upwards [] with g + simp only [hF] + simpa only [Fintype.card_fin] using + (integral_fintype_prod_eq_pow (ι := Fin n) (fun x : E => f (inner ℝ x g)) (μ := μ)).symm + _ = ∫ xs : Fin n → E, ∫ g, F (g,xs) ∂stdGaussian E ∂Measure.pi (fun _ => μ) := + integral_integral_swap (F.integrable _) + _ = _ := by + apply integral_congr_ae + filter_upwards [] with xs + rw [← gaussianRows_map_stdGaussian xs, + integral_map (gaussianRows xs).continuous.measurable.aemeasurable + (gaussianReplicaTest f).continuous.aestronglyMeasurable] + apply integral_congr_ae + filter_upwards [] with g + simp only [hF,gaussianReplicaTest_apply,gaussianRows_apply] + +def gramCovariance {ι E : Type*} [Fintype ι] [DecidableEq ι] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] (v : ι → E) : CovarianceMatrix ι := + ⟨Matrix.gram ℝ v,Matrix.posSemidef_gram ℝ v⟩ + +lemma gramCovariance_continuous {ι E : Type*} [Fintype ι] [DecidableEq ι] + [NormedAddCommGroup E] [InnerProductSpace ℝ E] : + Continuous (gramCovariance (ι := ι) (E := E)) := by + apply Continuous.subtype_mk + exact continuous_pi fun i => continuous_pi fun j => + (continuous_apply i).inner (continuous_apply j) + +def gaussianCovarianceKernel {ι : Type*} [Fintype ι] [DecidableEq ι] + (f : EuclideanSpace ℝ ι →ᵇ ℝ) : CovarianceMatrix ι →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound + ⟨fun C => ∫ z, f z ∂multivariateGaussian 0 C.val, + (gaussianCovariance_integral_continuous f).comp (continuous_const.prodMk continuous_id)⟩ + (2*‖f‖) (by + intro C D + calc + dist (∫ z, f z ∂multivariateGaussian 0 C.val) (∫ z, f z ∂multivariateGaussian 0 D.val) ≤ + ‖∫ z, f z ∂multivariateGaussian 0 C.val‖ + ‖∫ z, f z ∂multivariateGaussian 0 D.val‖ := by rw [dist_eq_norm]; exact norm_sub_le _ _ + _ ≤ ‖f‖ + ‖f‖ := add_le_add (f.norm_integral_le_norm _) (f.norm_integral_le_norm _) + _ = 2*‖f‖ := by ring) + +def gramReplicaLaw {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsProbabilityMeasure μ] (n : ℕ) : ProbabilityMeasure (CovarianceMatrix (Fin n)) := + ⟨(Measure.pi (fun _ : Fin n => μ)).map gramCovariance, + inferInstance⟩ + +lemma freshPattern_moment_tendsto_of_gram_laws + {E : ℕ → Type*} [∀ N, NormedAddCommGroup (E N)] [∀ N, InnerProductSpace ℝ (E N)] + [∀ N, FiniteDimensional ℝ (E N)] [∀ N, MeasurableSpace (E N)] [∀ N, BorelSpace (E N)] + (μ : (N : ℕ) → Measure (E N)) [∀ N, IsProbabilityMeasure (μ N)] + (f : ℝ →ᵇ ℝ) (n : ℕ) (ν : ProbabilityMeasure (CovarianceMatrix (Fin n))) + (h : Tendsto (fun N => gramReplicaLaw (μ N) n) atTop (𝓝 ν)) : + Tendsto (fun N => ∫ g, (∫ x, f (inner ℝ x g) ∂μ N)^n ∂stdGaussian (E N)) atTop + (𝓝 (∫ C, gaussianCovarianceKernel (gaussianReplicaTest (ι := Fin n) f) C ∂ν)) := by + have hh := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (gaussianCovarianceKernel (gaussianReplicaTest (ι := Fin n) f))).continuousAt.tendsto.comp h + convert hh using 1 + funext N + change (∫ g, (∫ x, f (inner ℝ x g) ∂μ N)^n ∂stdGaussian (E N)) = + ∫ C, gaussianCovarianceKernel (gaussianReplicaTest (ι := Fin n) f) C + ∂(Measure.pi (fun _ : Fin n => μ N)).map gramCovariance + rw [freshPattern_moment_covariance_integral, + integral_map gramCovariance_continuous.measurable.aemeasurable + (gaussianCovarianceKernel (gaussianReplicaTest (ι := Fin n) f)).continuous.aestronglyMeasurable] + rfl + +open TopologicalSpace + +abbrev CompactOverlap := Set.Icc (-1 : ℝ) 1 +abbrev CompactJointOverlap := CompactOverlap × unitInterval +abbrev CompactArray (K : Type*) := ℕ → ℕ → K +abbrev CompactBlock (K : Type*) (n : ℕ) := Fin n → Fin n → K + +def compactBlock {K : Type*} (n : ℕ) (Q : CompactArray K) : CompactBlock K n := + fun i j => Q i j + +lemma compactBlock_continuous {K : Type*} [TopologicalSpace K] (n : ℕ) : + Continuous (compactBlock (K := K) n) := by unfold compactBlock; fun_prop + +lemma compact_array_law_subsequence {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [CompactSpace K] [MetrizableSpace K] [SecondCountableTopology K] + (μ : ℕ → ProbabilityMeasure (CompactArray K)) : + ∃ ν : ProbabilityMeasure (CompactArray K), ∃ s : ℕ → ℕ, + StrictMono s ∧ Tendsto (μ ∘ s) atTop (𝓝 ν) := by + obtain ⟨ν, -, s, hs, hμ⟩ := isCompact_univ.isSeqCompact (fun n => mem_univ (μ n)) + exact ⟨ν,s,hs,hμ⟩ + +lemma weak_limit_closed_full {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [HasOuterApproxClosed K] + {μ : ℕ → ProbabilityMeasure K} {ν : ProbabilityMeasure K} + (hμ : Tendsto μ atTop (𝓝 ν)) {F : Set K} (hF : IsClosed F) + (hfull : ∀ n, μ n F = 1) : ν F = 1 := by + apply le_antisymm (ProbabilityMeasure.apply_le_one _ _) + have h := ProbabilityMeasure.limsup_measure_closed_le_of_tendsto hμ hF + have hf (n : ℕ) : (μ n : Measure K) F = 1 := by + rw [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hfull n,ENNReal.coe_one] + simp only [hf,limsup_const] at h + rw [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure] at h + exact_mod_cast h + +def compactGGDefect {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [SecondCountableTopology K] (μ : ProbabilityMeasure (CompactArray K)) (n : ℕ) (i : Fin n) + (f : CompactBlock K n →ᵇ ℝ) (g : K →ᵇ ℝ) : ℝ := + (n : ℝ)*(∫ Q, f (compactBlock n Q)*g (Q i n) ∂μ) - + (∫ Q, f (compactBlock n Q) ∂μ)*(∫ Q : CompactArray K, g (Q 0 1) ∂μ) - + ∑ j ∈ Finset.univ.erase i, ∫ Q, f (compactBlock n Q)*g (Q i j) ∂μ + +lemma compactGGDefect_continuous {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [SecondCountableTopology K] (n : ℕ) (i : Fin n) + (f : CompactBlock K n →ᵇ ℝ) (g : K →ᵇ ℝ) : + Continuous (fun μ : ProbabilityMeasure (CompactArray K) => compactGGDefect μ n i f g) := by + let f' : CompactArray K →ᵇ ℝ := f.compContinuous ⟨compactBlock n,compactBlock_continuous n⟩ + let g' (i j : ℕ) : CompactArray K →ᵇ ℝ := g.compContinuous ⟨fun Q => Q i j,by fun_prop⟩ + have hf := ProbabilityMeasure.continuous_integral_boundedContinuousFunction f' + have hg (i j : ℕ) := ProbabilityMeasure.continuous_integral_boundedContinuousFunction (g' i j) + have hfg (i j : ℕ) := ProbabilityMeasure.continuous_integral_boundedContinuousFunction (f' * g' i j) + exact (continuous_const.mul (hfg i n) |>.sub (hf.mul (hg 0 1))).sub + (continuous_finsetSum _ fun j _ => hfg i j) + +lemma compactGGDefect_limit {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [SecondCountableTopology K] {μ : ℕ → ProbabilityMeasure (CompactArray K)} + {ν : ProbabilityMeasure (CompactArray K)} (hμ : Tendsto μ atTop (𝓝 ν)) + (n : ℕ) (i : Fin n) (f : CompactBlock K n →ᵇ ℝ) (g : K →ᵇ ℝ) + (hdef : Tendsto (fun k => compactGGDefect (μ k) n i f g) atTop (𝓝 0)) : + compactGGDefect ν n i f g = 0 := + tendsto_nhds_unique ((compactGGDefect_continuous n i f g).continuousAt.tendsto.comp hμ) hdef + +lemma compactGG_joint_law {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [MetrizableSpace K] [SecondCountableTopology K] + (μ : ProbabilityMeasure (CompactArray K)) {n : ℕ} (hn : 0 < n) (i : Fin n) + (hGG : ∀ (f : CompactBlock K n →ᵇ ℝ) (g : K →ᵇ ℝ), compactGGDefect μ n i f g = 0) : + (μ : Measure (CompactArray K)).map (fun Q => (compactBlock n Q, Q i n)) = + ((n : ℝ≥0)⁻¹) • + (((μ : Measure (CompactArray K)).map (compactBlock n)).prod + ((μ : Measure (CompactArray K)).map (fun Q => Q 0 1)) + + ∑ j ∈ Finset.univ.erase i, + (μ : Measure (CompactArray K)).map (fun Q => (compactBlock n Q, Q i j))) := by + classical + have hb := (compactBlock_continuous (K := K) n).measurable + have he (k l : ℕ) : Measurable (fun Q : CompactArray K => Q k l) := by fun_prop + apply Measure.ext_of_integral_mul_boundedContinuousFunction + intro f g + let F : (CompactBlock K n × K) →ᵇ ℝ := + (f.compContinuous ⟨Prod.fst,continuous_fst⟩) * (g.compContinuous ⟨Prod.snd,continuous_snd⟩) + have hF : ∀ ρ : Measure (CompactBlock K n × K), IsFiniteMeasure ρ → Integrable F ρ := by + intro ρ hρ + exact F.integrable ρ + change ∫ p, F p ∂_ = ∫ p, F p ∂_ + rw [integral_smul_nnreal_measure,integral_add_measure (hF _ inferInstance) (hF _ inferInstance), + integral_finsetSum_measure] + · simp_rw [integral_map (hb.prodMk (he _ _)).aemeasurable F.continuous.aestronglyMeasurable] + simp only [F,BoundedContinuousFunction.mul_apply,BoundedContinuousFunction.compContinuous_apply, + ContinuousMap.coe_mk,NNReal.smul_def,NNReal.coe_inv,NNReal.coe_natCast,smul_eq_mul] + rw [integral_prod_mul,integral_map hb.aemeasurable f.continuous.aestronglyMeasurable, + integral_map (he 0 1).aemeasurable g.continuous.aestronglyMeasurable] + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast hn.ne' + have h := hGG f g + unfold compactGGDefect at h + apply (mul_right_inj' hn').mp + rw [←mul_assoc,mul_inv_cancel₀ hn',one_mul] + linarith [h] + · intro j hj + exact hF _ inferInstance + +open scoped Polynomial + +lemma integral_continuous_tendsto_of_moments {a b : ℝ} + (μ : ℕ → Measure (Icc a b)) (ν : Measure (Icc a b)) + [∀ n, IsProbabilityMeasure (μ n)] [IsProbabilityMeasure ν] + (h : ∀ k : ℕ, Tendsto (fun n => ∫ x, (x.val)^k ∂μ n) atTop + (𝓝 (∫ x, (x.val)^k ∂ν))) (f : C(Icc a b, ℝ)) : + Tendsto (fun n => ∫ x, f x ∂μ n) atTop (𝓝 (∫ x, f x ∂ν)) := by + have hi (ρ : Measure (Icc a b)) [IsFiniteMeasure ρ] (p : ℝ[X]) : + Integrable (fun x : Icc a b => p.eval x.val) ρ := + (p.continuous.comp continuous_subtype_val).integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hp (p : ℝ[X]) : Tendsto (fun n => ∫ x, p.eval x.val ∂μ n) atTop + (𝓝 (∫ x, p.eval x.val ∂ν)) := by + induction p using Polynomial.induction_on' with + | add p q hp hq => + simpa only [Polynomial.eval_add,integral_add (hi _ p) (hi _ q)] using hp.add hq + | monomial k c => + simpa only [Polynomial.eval_monomial,integral_const_mul] using tendsto_const_nhds.mul (h k) + rw [Metric.tendsto_atTop] + intro ε hε + obtain ⟨p, hpε⟩ := exists_polynomial_near_continuousMap a b f (ε/3) (by positivity) + obtain ⟨N, hN⟩ := (Metric.tendsto_atTop.mp (hp p)) (ε/3) (by positivity) + refine ⟨N, fun n hn => ?_⟩ + have hbnd (ρ : Measure (Icc a b)) [IsProbabilityMeasure ρ] : + |(∫ x, p.eval x.val ∂ρ) - ∫ x, f x ∂ρ| < ε/3 := by + rw [← integral_sub (hi ρ p) (f.continuous.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _))] + · calc + |∫ x, p.eval x.val - f x ∂ρ| ≤ ‖p.toContinuousMapOn (Icc a b)-f‖ := by + simpa only [Measure.real,measure_univ,ENNReal.toReal_one,mul_one,Real.norm_eq_abs,ContinuousMap.sub_apply,Polynomial.toContinuousMapOn_apply,Polynomial.toContinuousMap_apply] using + (norm_integral_le_of_norm_le_const (μ := ρ) + (Filter.Eventually.of_forall fun x => ContinuousMap.norm_coe_le_norm + (p.toContinuousMapOn (Icc a b)-f) x)) + _ < ε/3 := hpε + have h₁ := hbnd (μ n) + have h₂ := hbnd ν + have h₃ := hN n hn + rw [Real.dist_eq] at h₃ ⊢ + calc + |(∫ x, f x ∂μ n) - ∫ x, f x ∂ν| ≤ + |(∫ x, f x ∂μ n) - ∫ x, p.eval x.val ∂μ n| + + |(∫ x, p.eval x.val ∂μ n) - ∫ x, p.eval x.val ∂ν| + + |(∫ x, p.eval x.val ∂ν) - ∫ x, f x ∂ν| := by + calc + _ ≤ |(∫ x, f x ∂μ n) - ∫ x, p.eval x.val ∂μ n| + + |(∫ x, p.eval x.val ∂μ n) - ∫ x, f x ∂ν| := abs_sub_le _ _ _ + _ ≤ _ := by + linarith [abs_sub_le (∫ x, p.eval x.val ∂μ n) + (∫ x, p.eval x.val ∂ν) (∫ x, f x ∂ν)] + _ < ε := by rw [abs_sub_comm (∫ x, f x ∂μ n)] ; linarith + +lemma trial_integrable (m : Trial) : Integrable m timeLaw := by + change Integrable m (volume : Measure Time) + apply (integrable_const (1 : ℝ)).mono' m.measurable.aestronglyMeasurable + exact Eventually.of_forall fun t => by + rw [Real.norm_eq_abs,abs_of_nonneg (m.nonneg t)] + exact m.le_one t + +lemma tailIntegral_mono {m n : Trial} (h : ∀ t, m t ≤ n t) (t : Time) : + tailIntegral m t ≤ tailIntegral n t := + integral_mono (trial_integrable m).integrableOn (trial_integrable n).integrableOn h + +lemma entropy_antitone {m n : Trial} (h : ∀ t, m t ≤ n t) : entropy n ≤ entropy m := by + apply ENNReal.div_le_div_right + apply lintegral_mono + intro t + exact tsub_le_tsub_right (ENNReal.inv_le_inv.mpr (ENNReal.ofReal_le_ofReal (tailIntegral_mono h t))) _ + +def upperRoundedTrial (m : Trial) (n : ℕ) : Trial where + toFun := fun t => (⌈((n+1 : ℕ) : ℝ)*m t⌉₊ : ℝ) / (n+1 : ℕ) + monotone := by + intro s t hst + apply div_le_div_of_nonneg_right _ (by positivity) + exact_mod_cast Nat.ceil_mono (mul_le_mul_of_nonneg_left (m.monotone hst) (by positivity)) + measurable := + ((measurable_of_countable (fun k : ℕ => (k : ℝ))).comp + (Nat.measurable_ceil.comp (measurable_const.mul m.measurable))).div_const _ + nonneg := by intro t; positivity + le_one := by + intro t + apply (div_le_one (by positivity)).mpr + exact_mod_cast (Nat.ceil_le.mpr (show (((n+1 : ℕ) : ℝ)*m t) ≤ ((n+1 : ℕ) : ℝ) by + nlinarith [m.le_one t])) + +lemma le_upperRoundedTrial (m : Trial) (n : ℕ) (t : Time) : m t ≤ upperRoundedTrial m n t := by + apply (le_div_iff₀ (by positivity : (0 : ℝ) < (n+1 : ℕ))).mpr + simpa only [mul_comm] using (Nat.le_ceil (((n+1 : ℕ) : ℝ)*m t)) + +lemma upperRoundedTrial_sub_le (m : Trial) (n : ℕ) (t : Time) : + upperRoundedTrial m n t - m t ≤ 1/((n+1 : ℕ) : ℝ) := by + have h := Nat.ceil_lt_add_one (show (0 : ℝ) ≤ ((n+1 : ℕ) : ℝ)*m t from mul_nonneg (by positivity) (m.nonneg t)) + change (⌈((n+1 : ℕ) : ℝ)*m t⌉₊ : ℝ) / (n+1 : ℕ) - m t ≤ _ + apply (le_div_iff₀ (by positivity : (0 : ℝ) < (n+1 : ℕ))).mpr + have hn : (((n+1 : ℕ) : ℝ)) ≠ 0 := by positivity + field_simp + nlinarith + +lemma upperRoundedTrial_finite_range (m : Trial) (n : ℕ) : + (Set.range (upperRoundedTrial m n)).Finite := by + apply (Set.finite_Iic (n+1)).image (fun k : ℕ => (k : ℝ)/((n+1 : ℕ) : ℝ)) |>.subset + rintro _ ⟨t,rfl⟩ + refine ⟨⌈((n+1 : ℕ) : ℝ)*m t⌉₊, ?_, rfl⟩ + exact Nat.ceil_le.mpr (by nlinarith [m.le_one t]) + +def terminalTrial (m : Trial) (r : Time) : Trial where + toFun := fun t => if r ≤ t then 1 else m t + monotone := by + intro s t hst + by_cases hs : r ≤ s + · simp only [ite_eq_left hs,ite_eq_left (hs.trans hst)] + exact le_rfl + · by_cases ht : r ≤ t + · simpa only [ite_eq_right hs,ite_eq_left ht] using m.le_one s + · simpa only [ite_eq_right hs,ite_eq_right ht] using m.monotone hst + measurable := Measurable.ite measurableSet_Ici measurable_const m.measurable + nonneg := by intro t; split_ifs; norm_num; exact m.nonneg t + le_one := by intro t; split_ifs; exact le_rfl; exact m.le_one t + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DecoratedFocus.lean b/lean/OAI/Probability/Perceptron/Variational/DecoratedFocus.lean new file mode 100644 index 0000000000000000000000000000000000000000..2bf4bc4ae304aba9a4e3d1672ba0915b4f75a6e2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DecoratedFocus.lean @@ -0,0 +1,240 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.Shape + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Classical ENNReal NNReal BigOperators Topology +namespace SphericalPerceptronFreeEnergy +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +def decoratedFocusedProbability (ν : ProbabilityMeasure S) (step : X×S → X) : + (n : ℕ) → (Fin n → ℝ) → (Fin n → X×S → ℝ) → ℕ → + CascadeVisitShape n → X×DecoratedCascade S n → ℝ≥0∞ + | n, z, F, 0, s, p => decoratedShapeProbability ν step n z F (trivialDecoratedShape X n s) p + | 0, _, _, _+1, _, _ => 0 + | _+1, _, _, _+1, [], _ => 0 + | n+1, z, F, d+1, s::ss, p => markedBlockProbability + ((cascadeVisitCount n s+1, fun t : S×DecoratedCascade S n => + decoratedFocusedProbability ν step n (fun i => z i.succ) (fun i => F i.succ) d s + (step (p.1,t.1),t.2)) :: + ss.map (fun t => (cascadeVisitCount n t,fun u : S×DecoratedCascade S n => + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) + (trivialDecoratedShape X n t) (step (p.1,u.1),u.2)))) + ((markedStableCountKernel p.2).map (fun t : ℝ×(S×DecoratedCascade S n) => + (t.1+decoratedCenteredRoot ν step n z F (p.1,t.2),t.2))) (Fin.elim0 : Fin 0 → ℝ) + +lemma decoratedFocusedProbability_measurable (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (d : ℕ) (s : CascadeVisitShape n) (hv : s.Valid n) : + Measurable (decoratedFocusedProbability ν step n z F d s) := by + induction n generalizing d with + | zero => + cases d + · exact decoratedShapeProbability_measurable ν step hs 0 z F hF _ + (trivialDecoratedShape_valid X 0 s hv) + · exact measurable_const + | succ n ih => + cases d with + | zero => + exact decoratedShapeProbability_measurable ν step hs (n+1) z F hF _ + (trivialDecoratedShape_valid X (n+1) s hv) + | succ d => + cases s with + | nil => exact measurable_const + | cons s ss => + let ns : List (ℕ×(X×(S×DecoratedCascade S n) → ℝ≥0∞)) := + (cascadeVisitCount n s+1,fun p => + decoratedFocusedProbability ν step n (fun i => z i.succ) (fun i => F i.succ) d s + (step (p.1,p.2.1),p.2.2)) :: + ss.map (fun t => (cascadeVisitCount n t, fun p => + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) + (trivialDecoratedShape X n t) (step (p.1,p.2.1),p.2.2))) + have hm : ∀ nf ∈ ns, Measurable nf.2 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | ht + · exact (ih _ _ (fun i => hF i.succ) d s (hv.2 s (by simp))).comp + ((hs.comp (measurable_fst.prodMk measurable_snd.fst)).prodMk measurable_snd.snd) + · obtain ⟨t,hmem,rfl⟩ := List.mem_map.mp ht + exact (decoratedShapeProbability_measurable ν step hs n _ _ (fun i => hF i.succ) _ + (trivialDecoratedShape_valid X n t (hv.2 t (by simp [hmem])))).comp + ((hs.comp (measurable_fst.prodMk measurable_snd.fst)).prodMk measurable_snd.snd) + have hmap := countKernel_parameter_map_measurable + (fun p : X×(ℝ×(S×DecoratedCascade S n)) => + (p.2.1+decoratedCenteredRoot ν step n z F (p.1,p.2.2),p.2.2)) + ((measurable_snd.fst.add ((decoratedCenteredRoot_measurable ν step hs n z F hF).comp + (measurable_fst.prodMk measurable_snd.snd))).prodMk measurable_snd.snd) + have hh := (markedBlockProbability_parameter_measurable ns hm 0).comp + (measurable_fst.prodMk (hmap.prodMk (measurable_const (a := (Fin.elim0 : Fin 0 → ℝ))))) + convert hh using 1 + funext p + simp only [decoratedFocusedProbability,ns,List.map_cons,List.map_map,Function.comp_def] + +lemma trivialDecoratedShape_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (a : ℝ) (ha : ∀ i, a < z i) (s : CascadeVisitShape n) (hv : s.Valid n) (x : X) : + (∫⁻ η, decoratedShapeProbability ν step n z F (trivialDecoratedShape X n s) (x,η) + ∂decoratedBiasedLaw ν step n z F x a) = cascadeShapeLikelihood n z a s := by + rw [decoratedShapeProbability_integral ν step hs n z hz hz0 hz1 F hF hI hM a ha _ + (trivialDecoratedShape_valid X n s hv) x, + trivialDecoratedShape_bare,trivialDecoratedShape_markValue ν step n z F hI hM s x,mul_one] + +omit [Nonempty S] in +lemma exponentialMarkTilt_probability_of_one (ν : ProbabilityMeasure S) {b : ℝ} {G : S → ℝ} + (hI : Integrable (fun s => Real.exp (b*G s)) ν) + (hM : (∫ s, Real.exp (b*G s) ∂ν) = 1) : + IsProbabilityMeasure (exponentialMarkTilt ν b G) := by + rw [exponentialMarkTilt_eq_density_of_one (ν : Measure S) (b := b) (F := G) hI hM] + exact normalized_mark_density_probability (ν : Measure S) (b := b) (F := G) hI hM + +lemma decoratedFocusedProbability_integral_succ_eq (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (a : ℝ) (ha : ∀ i, a < z i) (d : ℕ) + (s : CascadeVisitShape n) (ss : List (CascadeVisitShape n)) + (hv : CascadeVisitShape.Valid (n+1) (s::ss)) (x : X) + (hchild : ∀ y, (∫⁻ η, decoratedFocusedProbability ν step n (fun i => z i.succ) + (fun i => F i.succ) d s (y,η) ∂decoratedBiasedLaw ν step n (fun i => z i.succ) + (fun i => F i.succ) y (z 0)) = ∫⁻ η, focusedShapeProbability n (fun i => z i.succ) + d s η ∂cascadeBiasedLaw n (fun i => z i.succ) (z 0)) : + (∫⁻ η, decoratedFocusedProbability ν step (n+1) z F (d+1) (s::ss) (x,η) + ∂decoratedBiasedLaw ν step (n+1) z F x a) = + ∫⁻ η, focusedShapeProbability (n+1) z (d+1) (s::ss) η + ∂cascadeBiasedLaw (n+1) z a := by + have htail : StrictMono (fun i : Fin n => z i.succ) := + fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij) + have har : ∀ i : Fin n, z 0 < z i.succ := fun i => hz (by simp) + let ns : List (ℕ×(S×DecoratedCascade S n → ℝ≥0∞)) := + (cascadeVisitCount n s+1,fun t => decoratedFocusedProbability ν step n + (fun i => z i.succ) (fun i => F i.succ) d s (step (x,t.1),t.2)) :: + ss.map (fun t => (cascadeVisitCount n t,fun u => decoratedShapeProbability ν step n + (fun i => z i.succ) (fun i => F i.succ) (trivialDecoratedShape X n t) + (step (x,u.1),u.2))) + let ps : List (ℕ×(StableCascade n → ℝ≥0∞)) := + (cascadeVisitCount n s+1,focusedShapeProbability n (fun i => z i.succ) d s):: + ss.map (fun t => (cascadeVisitCount n t,cascadeShapeProbability n (fun i => z i.succ) t)) + have hn : ∀ nf ∈ ns, 1 ≤ nf.1 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | ht + · simp + · obtain ⟨t,hmem,rfl⟩ := List.mem_map.mp ht + exact cascadeVisitCount_pos n t (hv.2 t (by simp [hmem])) + have hpn : ∀ nf ∈ ps, 1 ≤ nf.1 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | ht + · simp + · obtain ⟨t,hmem,rfl⟩ := List.mem_map.mp ht + exact cascadeVisitCount_pos n t (hv.2 t (by simp [hmem])) + have hm : ∀ nf ∈ ns, Measurable nf.2 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | ht + · exact (decoratedFocusedProbability_measurable ν step hs n _ _ + (fun i => hF i.succ) d s (hv.2 s (by simp))).comp + ((hs.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd) + · obtain ⟨t,hmem,rfl⟩ := List.mem_map.mp ht + exact (decoratedShapeProbability_measurable ν step hs n _ _ (fun i => hF i.succ) _ + (trivialDecoratedShape_valid X n t (hv.2 t (by simp [hmem])))).comp + ((hs.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd) + have hpm : ∀ nf ∈ ps, Measurable nf.2 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | ht + · exact focusedShapeProbability_measurable n _ d s + · obtain ⟨t,hmem,rfl⟩ := List.mem_map.mp ht + exact cascadeShapeProbability_measurable n _ t + change (∫⁻ η, markedBlockProbability ns + ((markedStableCountKernel η).map (logMarkShift + (centeredLogMark ((ν : Measure S).prod + (decoratedCascadeLaw ν n (fun i => z i.succ))) (z 0) + (fun p => decoratedRootPotential step n F (x,p))))) + (Fin.elim0 : Fin 0 → ℝ) ∂decoratedBiasedLaw ν step (n+1) z F x a) = + ∫⁻ η, markedBlockProbability ps _ (Fin.elim0 : Fin 0 → ℝ) ∂cascadeBiasedLaw (n+1) z a + rw [decoratedRootBlock_factor ν step hs n z hz hz0 hz1 F hF hI hM x a (ha 0) + ns (by simp [ns]) hn hm, + cascadeRootBlock_factor z hz hz0 hz1 (ha 0) ps (by simp [ps]) hpn hpm] + let := exponentialMarkTilt_probability_of_one ν (hI 0 x) (hM 0 x) + have he : ns.map Prod.fst = ps.map Prod.fst := by + simp only [ns,ps,List.map_cons,List.map_map,Function.comp_def] + rw [he] + apply congrArg (fun q : ℝ≥0∞ => q * _) + simp only [ns,ps,List.map_cons,List.prod_cons] + apply congrArg₂ (· * ·) + · have hh : ∀ u, (∫⁻ C, decoratedFocusedProbability ν step n (fun i => z i.succ) + (fun i => F i.succ) d s (step (x,u),C) ∂decoratedBiasedLaw ν step n + (fun i => z i.succ) (fun i => F i.succ) (step (x,u)) (z 0)) = + ∫⁻ C, focusedShapeProbability n (fun i => z i.succ) d s C + ∂cascadeBiasedLaw n (fun i => z i.succ) (z 0) := by + intro u + exact hchild (step (x,u)) + simp_rw [hh] + simp + · congr 1 + simp only [List.map_map,Function.comp_def] + apply List.map_congr_left + intro t ht + simp_rw [trivialDecoratedShape_integral ν step hs n _ htail + (fun i => hz0 i.succ) (fun i => hz1 i.succ) _ (fun i => hF i.succ) + (fun i => hI i.succ) (fun i => hM i.succ) (z 0) har t (hv.2 t (by simp [ht])), + cascadeShapeProbability_integral n _ htail (fun i => hz0 i.succ) + (fun i => hz1 i.succ) (z 0) har t (hv.2 t (by simp [ht]))] + simp + +lemma decoratedFocusedProbability_integral_eq (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (a : ℝ) (ha : ∀ i, a < z i) (d : ℕ) (hd : d ≤ n) + (s : CascadeVisitShape n) (hv : s.Valid n) (x : X) : + (∫⁻ η, decoratedFocusedProbability ν step n z F d s (x,η) + ∂decoratedBiasedLaw ν step n z F x a) = + ∫⁻ η, focusedShapeProbability n z d s η ∂cascadeBiasedLaw n z a := by + induction d generalizing n a x with + | zero => + simp only [decoratedFocusedProbability,focusedShapeProbability] + rw [trivialDecoratedShape_integral ν step hs n z hz hz0 hz1 F hF hI hM a ha s hv x, + cascadeShapeProbability_integral n z hz hz0 hz1 a ha s hv] + | succ d ih => + cases n with + | zero => omega + | succ n => + cases s with + | nil => exact (hv.1 rfl).elim + | cons s ss => + apply decoratedFocusedProbability_integral_succ_eq ν step hs n z hz hz0 hz1 F hF hI hM + a ha d s ss hv x + intro y + exact ih n _ (fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij)) + (fun i => hz0 i.succ) (fun i => hz1 i.succ) _ + (fun i => hF i.succ) (fun i => hI i.succ) (fun i => hM i.succ) + (z 0) (fun i => hz (by simp)) (by omega) s (hv.2 s (by simp)) y + +lemma decoratedFocusedProbability_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (a : ℝ) (ha1 : a < 1) (ha : ∀ i, a < z i) (d : ℕ) (hd : d ≤ n) + (s : CascadeVisitShape n) (hv : s.Valid n) (x : X) : + (∫⁻ η, decoratedFocusedProbability ν step n z F d s (x,η) + ∂decoratedBiasedLaw ν step n z F x a) = + cascadeShapeLikelihood n z a s * + ENNReal.ofReal (focusedShapeNumerator n z a d s/((cascadeVisitCount n s:ℝ)-a)) := by + rw [decoratedFocusedProbability_integral_eq ν step hs n z hz hz0 hz1 F hF hI hM a ha d hd s hv x, + focusedShapeProbability_integral n z hz hz0 hz1 a ha1 ha d hd s hv] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DecoratedShapeLaw.lean b/lean/OAI/Probability/Perceptron/Variational/DecoratedShapeLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..a7ce4f31a62440c9901ab78eec17f148c21bbac8 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DecoratedShapeLaw.lean @@ -0,0 +1,209 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ProductMarkLaw +import OAI.Probability.Perceptron.Variational.MarkedBlockParameter +import OAI.Probability.Perceptron.Variational.MarkTiltKernel + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +section + +lemma exponentialMarkTilt_eq_density_of_one {S : Type*} [MeasurableSpace S] + (ν : Measure S) {b : ℝ} {F : S → ℝ} + (hI : Integrable (fun s => Real.exp (b*F s)) ν) + (hM : (∫ s, Real.exp (b*F s) ∂ν) = 1) : + exponentialMarkTilt ν b F = ν.withDensity (fun s => ENNReal.ofReal (Real.exp (b*F s))) := by + unfold exponentialMarkTilt normalizedMeasure + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal hI (ae_of_all _ fun s => (Real.exp_pos _).le),hM] + simp + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +theorem decoratedShapeProbability_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (a : ℝ) (ha : ∀ i, a < z i) (s : DecoratedVisitShape X n) + (hv : s.Valid n) (x : X) : + (∫⁻ η, decoratedShapeProbability ν step n z F s (x,η) + ∂decoratedBiasedLaw ν step n z F x a) = + cascadeShapeLikelihood n z a (s.bare n)*decoratedShapeMarkValue ν step n z F s x := by + induction n generalizing a x with + | zero => + have := decoratedBiasedLaw_probability ν step hs 0 z hz hz0 hz1 F hF hI hM x a ha + simp only [decoratedShapeProbability,cascadeShapeLikelihood,decoratedShapeMarkValue, + lintegral_const,measure_univ,mul_one,one_mul] + | succ n ih => + have htail : StrictMono (fun i : Fin n => z i.succ) := + fun i j h => hz (Fin.succ_lt_succ_iff.mpr h) + have hrange : ∀ i : Fin n, z 0 < z i.succ := fun i => hz (by simp) + let ns : List (ℕ×(S×DecoratedCascade S n → ℝ≥0∞)) := s.map (fun t => + (cascadeVisitCount n (t.bare n),fun p => + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) t + (step (x,p.1),p.2))) + have hne : ns ≠ [] := by simpa [ns] using hv.1 + have hn : ∀ nf ∈ ns, 1 ≤ nf.1 := by + intro nf hnf; obtain ⟨t,ht,rfl⟩ := List.mem_map.mp hnf + exact cascadeVisitCount_pos n _ (t.bare_valid n (hv.2 t ht)) + have hm : ∀ nf ∈ ns, Measurable nf.2 := by + intro nf hnf; obtain ⟨t,ht,rfl⟩ := List.mem_map.mp hnf + exact (decoratedShapeProbability_measurable ν step hs n (fun i => z i.succ) + (fun i => F i.succ) (fun i => hF i.succ) t (hv.2 t ht)).comp + ((hs.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd) + have he := decoratedRootBlock_factor ν step hs n z hz hz0 hz1 F hF hI hM x a + (ha 0) ns hne hn hm + change (∫⁻ η, markedBlockProbability ns + ((markedStableCountKernel η).map (logMarkShift + (centeredLogMark ((ν : Measure S).prod + (decoratedCascadeLaw ν n (fun i => z i.succ))) (z 0) + (fun p => decoratedRootPotential step n F (x,p))))) + (Fin.elim0 : Fin 0 → ℝ) ∂decoratedBiasedLaw ν step (n+1) z F x a) = _ + rw [he,stableBlockProbability_eppf_value (hz0 0) (hz1 0) (ha 0) + (ns.map Prod.fst) (by simpa using hne) + (by intro k hk; obtain ⟨nf,hmem,rfl⟩ := List.mem_map.mp hk; exact hn nf hmem)] + have hchild (t : DecoratedVisitShape X n) (ht : t ∈ s) : + (∫⁻ u, (∫⁻ C, decoratedShapeProbability ν step n (fun i => z i.succ) + (fun i => F i.succ) t (step (x,u),C) ∂decoratedBiasedLaw ν step n + (fun i => z i.succ) (fun i => F i.succ) (step (x,u)) (z 0)) + ∂exponentialMarkTilt ν (z 0) (fun u => F 0 (x,u))) = + cascadeShapeLikelihood n (fun i => z i.succ) (z 0) (t.bare n)* + ∫⁻ u, ENNReal.ofReal (Real.exp (z 0*F 0 (x,u)))* + decoratedShapeMarkValue ν step n (fun i => z i.succ) (fun i => F i.succ) + t (step (x,u)) ∂ν := by + have hval : Measurable (fun u => decoratedShapeMarkValue ν step n + (fun i => z i.succ) (fun i => F i.succ) t (step (x,u))) := + (decoratedShapeMarkValue_measurable ν step hs n (fun i => z i.succ) + (fun i => F i.succ) (fun i => hF i.succ) t (hv.2 t ht)).comp + (hs.comp (measurable_const.prodMk measurable_id)) + calc + _ = ∫⁻ u, cascadeShapeLikelihood n (fun i => z i.succ) (z 0) (t.bare n)* + decoratedShapeMarkValue ν step n (fun i => z i.succ) (fun i => F i.succ) + t (step (x,u)) ∂exponentialMarkTilt ν (z 0) (fun u => F 0 (x,u)) := by + apply lintegral_congr + intro u + exact ih (fun i => z i.succ) htail (fun i => hz0 i.succ) (fun i => hz1 i.succ) + (fun i => F i.succ) (fun i => hF i.succ) (fun i => hI i.succ) + (fun i => hM i.succ) (z 0) hrange t (hv.2 t ht) (step (x,u)) + _ = _ := by + have hweight : Measurable (fun u : S => ENNReal.ofReal (Real.exp (z 0*F 0 (x,u)))) := + (((hF 0).comp (measurable_const.prodMk measurable_id)).const_mul _).exp.ennreal_ofReal + rw [lintegral_const_mul _ hval, + exponentialMarkTilt_eq_density_of_one (ν : Measure S) (b := z 0) + (F := fun u => F 0 (x,u)) (hI 0 x) (hM 0 x), + lintegral_withDensity_eq_lintegral_mul _ hweight hval] + rfl + simp only [ns,List.map_map,Function.comp_def] at * + rw [show (s.map (fun t => ∫⁻ u, (∫⁻ C, decoratedShapeProbability ν step n + (fun i => z i.succ) (fun i => F i.succ) t (step (x,u),C) + ∂decoratedBiasedLaw ν step n (fun i => z i.succ) (fun i => F i.succ) + (step (x,u)) (z 0)) ∂exponentialMarkTilt ν (z 0) (fun u => F 0 (x,u)))) = + s.map (fun t => cascadeShapeLikelihood n (fun i => z i.succ) (z 0) (t.bare n)* + ∫⁻ u, ENNReal.ofReal (Real.exp (z 0*F 0 (x,u)))* + decoratedShapeMarkValue ν step n (fun i => z i.succ) (fun i => F i.succ) + t (step (x,u)) ∂ν) by exact List.map_congr_left hchild] + rw [List.prod_map_mul] + simp only [cascadeShapeLikelihood,DecoratedVisitShape.bare,decoratedShapeMarkValue, + List.map_map,Function.comp_def] + ac_rfl + +end + +@[reducible] def PairedVisitShape (X Y : Type) : ℕ → Type + | 0 => ℕ × ((X → ℝ≥0∞) × (Y → ℝ≥0∞)) + | n+1 => List (PairedVisitShape X Y n) + +def PairedVisitShape.first {X Y : Type} : (n : ℕ) → PairedVisitShape X Y n → DecoratedVisitShape X n + | 0, s => (s.1,s.2.1) + | n+1, s => s.map (PairedVisitShape.first n) + +def PairedVisitShape.second {X Y : Type} : (n : ℕ) → PairedVisitShape X Y n → DecoratedVisitShape Y n + | 0, s => (s.1,s.2.2) + | n+1, s => s.map (PairedVisitShape.second n) + +def PairedVisitShape.product {X Y : Type} : (n : ℕ) → PairedVisitShape X Y n → DecoratedVisitShape (X×Y) n + | 0, s => (s.1,fun p => s.2.1 p.1*s.2.2 p.2) + | n+1, s => s.map (PairedVisitShape.product n) + +lemma PairedVisitShape.bare_first_second {X Y : Type} (n : ℕ) (s : PairedVisitShape X Y n) : + (s.first n).bare n = (s.second n).bare n := by + induction n with + | zero => rfl + | succ n ih => + simp only [first,second,DecoratedVisitShape.bare,List.map_map,Function.comp_def] + exact List.map_congr_left (fun t _ => ih t) + +lemma PairedVisitShape.product_valid {X Y : Type} [MeasurableSpace X] [MeasurableSpace Y] + (n : ℕ) (s : PairedVisitShape X Y n) + (h₁ : (s.first n).Valid n) (h₂ : (s.second n).Valid n) : + (s.product n).Valid n := by + induction n with + | zero => exact ⟨h₁.1,(h₁.2.comp measurable_fst).mul (h₂.2.comp measurable_snd)⟩ + | succ n ih => + refine ⟨by simpa [product,first] using h₁.1,?_⟩ + intro t ht + obtain ⟨u,hu,rfl⟩ := List.mem_map.mp ht + exact ih u (h₁.2 _ (List.mem_map.mpr ⟨u,hu,rfl⟩)) + (h₂.2 _ (List.mem_map.mpr ⟨u,hu,rfl⟩)) + +theorem decoratedShapeMarkValue_product {X Y S T : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace S] [MeasurableSpace T] + [Nonempty S] [Nonempty T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S → X) (step₂ : Y×T → Y) + (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n → ℝ) + (F : Fin n → X×S → ℝ) (G : Fin n → Y×T → ℝ) + (hF : ∀ i, Measurable (F i)) (hG : ∀ i, Measurable (G i)) + (s : PairedVisitShape X Y n) (h₁ : (s.first n).Valid n) (h₂ : (s.second n).Valid n) + (x : X) (y : Y) : + decoratedShapeMarkValue (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) n z + (fun i p => F i (p.1.1,p.2.1)+G i (p.1.2,p.2.2)) (s.product n) (x,y) = + decoratedShapeMarkValue ν step₁ n z F (s.first n) x * + decoratedShapeMarkValue ρ step₂ n z G (s.second n) y := by + induction n generalizing x y with + | zero => rfl + | succ n ih => + simp only [PairedVisitShape.product,PairedVisitShape.first,PairedVisitShape.second, + decoratedShapeMarkValue,List.map_map,Function.comp_def] + rw [← List.prod_map_mul] + apply congrArg List.prod + apply List.map_congr_left + intro t ht + have ht₁ := h₁.2 _ (List.mem_map.mpr ⟨t,ht,rfl⟩) + have ht₂ := h₂.2 _ (List.mem_map.mpr ⟨t,ht,rfl⟩) + simp_rw [ih (fun i => z i.succ) (fun i => F i.succ) (fun i => G i.succ) + (fun i => hF i.succ) (fun i => hG i.succ) t ht₁ ht₂] + have hm₁ : Measurable (fun u => ENNReal.ofReal (Real.exp (z 0*F 0 (x,u)))* + decoratedShapeMarkValue ν step₁ n (fun i => z i.succ) (fun i => F i.succ) + (t.first n) (step₁ (x,u))) := + ((((hF 0).comp (measurable_const.prodMk measurable_id)).const_mul _).exp.ennreal_ofReal).mul + ((decoratedShapeMarkValue_measurable ν step₁ hs₁ n (fun i => z i.succ) + (fun i => F i.succ) (fun i => hF i.succ) _ ht₁).comp + (hs₁.comp (measurable_const.prodMk measurable_id))) + have hm₂ : Measurable (fun u => ENNReal.ofReal (Real.exp (z 0*G 0 (y,u)))* + decoratedShapeMarkValue ρ step₂ n (fun i => z i.succ) (fun i => G i.succ) + (t.second n) (step₂ (y,u))) := + ((((hG 0).comp (measurable_const.prodMk measurable_id)).const_mul _).exp.ennreal_ofReal).mul + ((decoratedShapeMarkValue_measurable ρ step₂ hs₂ n (fun i => z i.succ) + (fun i => G i.succ) (fun i => hG i.succ) _ ht₂).comp + (hs₂.comp (measurable_const.prodMk measurable_id))) + simp only [mul_add,Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos _).le] + convert lintegral_prod_mul (μ := (ν : Measure S)) (ν := (ρ : Measure T)) + hm₁.aemeasurable hm₂.aemeasurable using 1 + apply lintegral_congr + intro p + exact mul_mul_mul_comm _ _ _ _ + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DecoratedTiltTotal.lean b/lean/OAI/Probability/Perceptron/Variational/DecoratedTiltTotal.lean new file mode 100644 index 0000000000000000000000000000000000000000..603a2575f58ef771bab907d9690627a26131a734 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DecoratedTiltTotal.lean @@ -0,0 +1,202 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.DecoratedWeightedTotal + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +omit [Nonempty S] in +lemma decoratedWeightedTotal_measurable (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) : + Measurable (decoratedWeightedTotal step n F) := by + have he : decoratedWeightedTotal step n F = + fun p => cascadeTotal n (decoratedCascadeTransform step n F p) := by + funext p; exact decoratedWeightedTotal_transform step hs n F hF p + rw [he] + exact (cascadeTotal_measurable n).comp (decoratedCascadeTransform_measurable step hs n F hF) + +def decoratedBiasedLaw (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin n → ℝ) (F : Fin n → X×S → ℝ) (x : X) (a : ℝ) : + Measure (DecoratedCascade S n) := + normalizedMeasure ((decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)).withDensity + (fun η => ENNReal.ofReal ((decoratedWeightedTotal step n F (x,η))^a))) + +lemma decoratedWeightedTotal_pos (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + ∀ᵐ η ∂(decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)), + 0 < decoratedWeightedTotal step n F (x,η) := + (decoratedWeightedTotal_identDistrib ν step hs n z hz0 hz1 F hF hI hM x).symm.ae_snd + measurableSet_Ioi (cascadeTotal_regular n z hz hz0 hz1).1 + +lemma decoratedLogTotalMoment_integrable (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (x : X) (a : ℝ) (ha : ∀ i, a < z i) : + Integrable (fun η => Real.exp (a*Real.log (decoratedWeightedTotal step n F (x,η)))) + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) := by + have hid := (decoratedWeightedTotal_identDistrib ν step hs n z hz0 hz1 F hF hI hM x).comp + (Real.measurable_exp.comp (Real.measurable_log.const_mul a)) + exact hid.integrable_iff.mpr (cascadeLogTotalMoment_integrable n z hz hz0 hz1 a ha) + +lemma decoratedLogTotalMoment_eq (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) (a : ℝ) : + (∫ η, Real.exp (a*Real.log (decoratedWeightedTotal step n F (x,η))) + ∂decoratedCascadeLaw ν n z) = + ∫ η, Real.exp (a*Real.log (cascadeTotal n η)) ∂cascadeLaw n z := by + exact ((decoratedWeightedTotal_identDistrib ν step hs n z hz0 hz1 F hF hI hM x).comp + (Real.measurable_exp.comp (Real.measurable_log.const_mul a))).integral_eq + +lemma decoratedBiasedLaw_eq_exponentialTilt (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) (a : ℝ) : + decoratedBiasedLaw ν step n z F x a = + exponentialMarkTilt (decoratedCascadeLaw ν n z) a + (fun η => Real.log (decoratedWeightedTotal step n F (x,η))) := by + unfold decoratedBiasedLaw exponentialMarkTilt + congr 1 + apply withDensity_congr_ae + filter_upwards [decoratedWeightedTotal_pos ν step hs n z hz hz0 hz1 F hF hI hM x] with η hη + rw [Real.rpow_def_of_pos hη,mul_comm] + +lemma decoratedBiasedLaw_probability (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (x : X) (a : ℝ) (ha : ∀ i, a < z i) : + IsProbabilityMeasure (decoratedBiasedLaw ν step n z F x a) := by + rw [decoratedBiasedLaw_eq_exponentialTilt ν step hs n z hz hz0 hz1 F hF hI hM x a] + exact exponentialMarkTilt_probability _ + (decoratedLogTotalMoment_integrable ν step hs n z hz hz0 hz1 F hF hI hM x a ha) + +def decoratedRootPotential (step : X×S → X) (n : ℕ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(S×DecoratedCascade S n)) : ℝ := + F 0 (p.1,p.2.1)+Real.log + (decoratedWeightedTotal step n (fun i => F i.succ) (step (p.1,p.2.1),p.2.2)) + +omit [Nonempty S] in +lemma decoratedRootPotential_measurable (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) : + Measurable (decoratedRootPotential step n F) := + ((hF 0).comp (measurable_fst.prodMk measurable_snd.fst)).add + (((decoratedWeightedTotal_measurable step hs n _ (fun i => hF i.succ)).comp + ((hs.comp (measurable_fst.prodMk measurable_snd.fst)).prodMk measurable_snd.snd)).log) + +lemma decoratedRootPotential_integrable (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + Integrable (fun p => Real.exp (z 0*decoratedRootPotential step n F (x,p))) + ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ))) := by + let ρ : Measure (DecoratedCascade S n) := decoratedCascadeLaw ν n (fun i => z i.succ) + let θ : Measure (StableCascade n) := cascadeLaw n (fun i => z i.succ) + let T : S×DecoratedCascade S n → StableCascade n := fun p => + decoratedCascadeTransform step n (fun i => F i.succ) (step (x,p.1),p.2) + have hT : Measurable T := (decoratedCascadeTransform_measurable step hs n _ + (fun i => hF i.succ)).comp + ((hs.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd) + have hLaw (s) : ρ.map (fun c => T (s,c)) = θ := by + exact decoratedCascadeTransform_law ν step hs n (fun i => z i.succ) + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (fun i => F i.succ) + (fun i => hF i.succ) (fun i => hI i.succ) (fun i => hM i.succ) (step (x,s)) + have hp : MeasurePreserving (fun p : S×DecoratedCascade S n => (p.1,T p)) + ((ν : Measure S).prod ρ) ((ν : Measure S).prod θ) := + ⟨measurable_fst.prodMk hT,descendant_transform_independent _ _ _ T hT hLaw⟩ + have htail := cascadeLogTotalMoment_integrable n (fun i => z i.succ) + (fun i j h => hz (Fin.succ_lt_succ_iff.mpr h)) (fun i => hz0 i.succ) + (fun i => hz1 i.succ) (z 0) (fun i => hz (by simp)) + have hprod := (hI 0 x).mul_prod htail + have he := (hp.integrable_comp hprod.aestronglyMeasurable).mpr hprod + apply he.congr + filter_upwards [] with p + dsimp [Function.comp,T,decoratedRootPotential] + rw [decoratedWeightedTotal_transform step hs n _ (fun i => hF i.succ),mul_add,Real.exp_add] + +lemma decoratedWeightedTotal_succ_eq (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + ∀ᵐ η ∂(decoratedCascadeLaw ν (n+1) z : Measure (DecoratedCascade S (n+1))), + decoratedWeightedTotal step (n+1) F (x,η) = + poissonWeightedTotal (fun p => decoratedRootPotential step n F (x,p)) η := by + have hT : Measurable (fun η : DecoratedCascade S (n+1) => + decoratedCascadeTransform step (n+1) F (x,η)) := + (decoratedCascadeTransform_measurable step hs (n+1) F hF).comp + (measurable_const.prodMk measurable_id) + have hp : MeasurePreserving (fun η => decoratedCascadeTransform step (n+1) F (x,η)) + (decoratedCascadeLaw ν (n+1) z : Measure (DecoratedCascade S (n+1))) (cascadeLaw (n+1) z) := + ⟨hT,decoratedCascadeTransform_law ν step hs (n+1) z hz0 hz1 F hF hI hM x⟩ + have htail := (cascadeTotal_regular n (fun i => z i.succ) + (fun i j h => hz (Fin.succ_lt_succ_iff.mpr h)) + (fun i => hz0 i.succ) (fun i => hz1 i.succ)).1 + have hae := hp.quasiMeasurePreserving.ae (cascadeTotal_succ_eq z htail) + have hreg := markedStable_regular + ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ) : Measure (DecoratedCascade S n))) (hz0 0) (hz1 0) + filter_upwards [hae,hreg] with η hη hr + rw [decoratedWeightedTotal_transform step hs (n+1) F hF,hη] + change poissonWeightedTotal (fun C => Real.log (cascadeTotal n C)) + ((markedStableCountKernel η).map (fun q : ℝ×(S×DecoratedCascade S n) => + (q.1+F 0 (x,q.2.1),decoratedCascadeTransform step n (fun i => F i.succ) + (step (x,q.2.1),q.2.2)))) = _ + rw [markedStableCountKernel_eq η hr.1 hr.2] + have hmap : Measurable (fun q : ℝ×(S×DecoratedCascade S n) => + (q.1+F 0 (x,q.2.1),decoratedCascadeTransform step n (fun i => F i.succ) + (step (x,q.2.1),q.2.2))) := + (measurable_fst.add ((hF 0).comp (measurable_const.prodMk measurable_snd.fst))).prodMk + ((decoratedCascadeTransform_measurable step hs n _ (fun i => hF i.succ)).comp + ((hs.comp (measurable_const.prodMk measurable_snd.fst)).prodMk measurable_snd.snd)) + unfold poissonWeightedTotal + have hobs : Measurable (fun p : ℝ×StableCascade n => + ENNReal.ofReal (Real.exp (p.1+Real.log (cascadeTotal n p.2)))) := + (measurable_fst.add ((cascadeTotal_measurable n).comp measurable_snd).log).exp.ennreal_ofReal + rw [lintegral_map hobs hmap] + congr 1 + apply lintegral_congr + intro q + dsimp [decoratedRootPotential] + rw [decoratedWeightedTotal_transform step hs n _ (fun i => hF i.succ),add_assoc] + +lemma decoratedBiasedLaw_succ_eq_weighted (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) (a : ℝ) : + decoratedBiasedLaw ν step (n+1) z F x a = weightedTotalBiasedLaw + ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ))) a (z 0) + (fun p => decoratedRootPotential step n F (x,p)) := by + unfold decoratedBiasedLaw weightedTotalBiasedLaw + congr 1 + apply withDensity_congr_ae + filter_upwards [decoratedWeightedTotal_succ_eq ν step hs n z hz hz0 hz1 F hF hI hM x] with η hη + rw [hη] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DensityDerivative.lean b/lean/OAI/Probability/Perceptron/Variational/DensityDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..ade85a4269456dd9904de2946f90033682563dc4 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DensityDerivative.lean @@ -0,0 +1,104 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.PerturbationContact +import OAI.Probability.Perceptron.Cascade.PoissonDensityDerivative + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def sourceCountExpectedLog (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) (M : ℕ) : ℝ := + ∫ a, enrichedPoissonLog n k f p d u h (M,a) ∂enrichedRowsDisorderLaw n k p z + +lemma sourceCountExpectedLog_increment (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 ha u)] + rw [← integral_map hr.measurable.aemeasurable (by rw [hr.map_eq]; exact hm.aestronglyMeasurable),hr.map_eq] + unfold sourceIndexedPressure + change (∫ a, enrichedRandomPressure n k f p d u h (sourceDisorderRealization n k p a) + ∂sourceIndexedDisorderLaw n k z t)=_ + rw [← integral_map hs.measurable.aemeasurable (by rw [hs.map_eq]; exact hi'),hs.map_eq] + simp only [enrichedRandomPressure,integral_const_mul] + apply congrArg ((1/(n+1:ℕ):ℝ)* ·) + change (∫ a, enrichedPoissonLog n k f p d u h a ∂enrichedPoissonDisorderLaw n k p z t) = + poissonRealMean (sourceCountExpectedLog n k f p d h z u) (((n+1:ℕ)*t:ℝ≥0):ℝ) + rw [poissonRealMean_eq_integral (norm_nonneg f) + (sourceCountExpectedLog_increment n k f p d h z u hz hz0 hz1) ((n+1:ℕ)*t)] + exact integral_prod _ (hi.integrable (by norm_num)) + +def sourceDensityIncrement (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) (t : ℝ≥0) : ℝ := + ∫ M, sourceCountExpectedLog n k f p d h z u (M+1)-sourceCountExpectedLog n k f p d h z u M + ∂poissonMeasure ((n+1:ℕ)*t) + +lemma sourceDensityIncrement_bound (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 sourceCountExpectedLog n k f p d h z u (M+1)-sourceCountExpectedLog n k f p d h z u M) + (ae_of_all _ fun M => by simpa only [Real.norm_eq_abs] using + sourceCountExpectedLog_increment n k f p d h z u hz hz0 hz1 M) + +lemma sourceExpectedPressure_density_derivative (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 sourceExpectedPressure n k f p d h z s.toNNReal u) + (sourceDensityIncrement n k f p d h z u t) t := by + let F := sourceCountExpectedLog n k f p d h z u + have hF := sourceCountExpectedLog_increment n k f p d h z u hz hz0 hz1 + have hd := ((hasDerivAt_poissonRealMean (norm_nonneg f) hF ((n+1:ℕ)*(t:ℝ))).comp (t:ℝ) + ((hasDerivAt_id (t:ℝ)).const_mul ((n+1:ℕ):ℝ))).const_mul (1/(n+1:ℕ):ℝ) + have hD : poissonRealMean (fun M => F (M+1)-F M) ((n+1:ℕ)*(t:ℝ))= + sourceDensityIncrement n k f p d h z u t := by + have hinc : ∀ M, |(F (M+1+1)-F (M+1))-(F (M+1)-F M)|≤2*‖f‖ := fun M => + (abs_sub _ _).trans (by linarith [hF (M+1),hF M]) + simpa only [sourceDensityIncrement,NNReal.coe_mul,NNReal.coe_natCast] using + poissonRealMean_eq_integral (by positivity : 0≤2*‖f‖) hinc ((n+1:ℕ)*t) + have hd' : HasDerivAt (fun s : ℝ => (1/(n+1:ℕ))*poissonRealMean F ((n+1:ℕ)*s)) + (sourceDensityIncrement n k f p d h z u t) t := by + apply hd.congr_deriv + change (1/(n+1:ℕ))*(poissonRealMean _ _ *((n+1:ℕ)*1))=_ + rw [hD] + field_simp + apply hd'.congr_of_eventuallyEq + filter_upwards [eventually_gt_nhds (show (0:ℝ)<(t:ℝ) from ht)] with s hs + rw [sourceExpectedPressure_poissonMean n k f p d h z u hz hz0 hz1, + Real.coe_toNNReal _ hs.le] + +lemma sourceExpectedPressure_density_continuous (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 sourceExpectedPressure n k f p d h z t u) := by + have hc : Continuous (poissonRealMean (sourceCountExpectedLog n k f p d h z u)) := + continuous_iff_continuousAt.mpr fun r => + (hasDerivAt_poissonRealMean (norm_nonneg f) + (sourceCountExpectedLog_increment n k f p d h z u hz hz0 hz1) r).continuousAt + simp_rw [sourceExpectedPressure_poissonMean n k f p d h z u hz hz0 hz1] + exact continuous_const.mul (hc.comp (continuous_const.mul NNReal.continuous_coe)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DensityLipschitz.lean b/lean/OAI/Probability/Perceptron/Variational/DensityLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..030db66ebe525053000396b4630bde08abd54f3c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DensityLipschitz.lean @@ -0,0 +1,152 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DensityDerivative +import OAI.Probability.Perceptron.Variational.FieldContinuity + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma poissonRealMean_increment_bound (F : ℕ→ℝ) {C : ℝ} (hC : 0≤C) + (hF : ∀ M, |F (M+1)-F M|≤C) (r : ℝ≥0) : + |poissonRealMean (fun M => F (M+1)-F M) r|≤C := by + have hinc (M) : |(F (M+2)-F (M+1))-(F (M+1)-F M)|≤2*C := by + exact (abs_sub _ _).trans (by linarith [hF M,hF (M+1)]) + rw [poissonRealMean_eq_integral (by positivity : 0≤2*C) hinc r] + simpa only [Real.norm_eq_abs,probReal_univ,mul_one] using norm_integral_le_of_norm_le_const + (μ := poissonMeasure r) (f := fun M => F (M+1)-F M) + (ae_of_all _ fun M => by simpa only [Real.norm_eq_abs] using hF M) + +lemma poissonRealMean_lipschitz_bound (F : ℕ→ℝ) {C : ℝ} (hC : 0≤C) + (hF : ∀ M, |F (M+1)-F M|≤C) (s t : ℝ≥0) : + |poissonRealMean F t-poissonRealMean F s|≤C*|(t:ℝ)-(s:ℝ)| := by + have hb : ∀ r ∈ Ici (0:ℝ), ‖deriv (poissonRealMean F) r‖≤C := by + intro r hr + rw [(hasDerivAt_poissonRealMean hC hF r).deriv,Real.norm_eq_abs] + exact poissonRealMean_increment_bound F hC hF ⟨r,hr⟩ + simpa only [Real.norm_eq_abs] using Convex.norm_image_sub_le_of_norm_deriv_le + (fun r (_ : r∈Ici (0:ℝ)) => (hasDerivAt_poissonRealMean hC hF r).differentiableAt) + hb (convex_Ici (0:ℝ)) s.coe_nonneg t.coe_nonneg + +lemma sourceExpectedPressure_density_comparison (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 (enrichedFeatureBound N u:ℝ)) := by + change Continuous (fun u : Fin N→ℝ => Real.sqrt ((N:ℝ)+∑ j, perturbationAmplitude N u j^2)) + unfold perturbationAmplitude + fun_prop + +lemma sourceFieldDistance_joint_continuous {N k : ℕ} (p d : Fin N→ℕ) + (h : Fin (k+1)→ℝ) : Continuous (fun a : (Fin N→ℝ)×(Fin (k+1)→ℝ) => + sourceFieldDistance p d a.1 a.2 h) := by + have hc := (sourceFieldCoefficients_continuous (k := k) p d).comp + (continuous_snd : Continuous (fun a : (Fin N→ℝ)×(Fin (k+1)→ℝ) => a.2)) + have he : Continuous (fun a : (Fin N→ℝ)×(Fin (k+1)→ℝ) => indexedCoefficientSquare k + (fun l i => sourceFieldCoefficients p d a.2 l i-sourceFieldCoefficients p d h l i)) := by + simpa only [Function.comp_def,Pi.sub_def] using + (indexedCoefficientSquare_continuous (I := EnrichedIndex N N p) k).comp + (hc.sub (continuous_const (y := sourceFieldCoefficients p d h))) + have hf := (enrichedFeatureBound_continuous N).comp + (continuous_fst : Continuous (fun a : (Fin N→ℝ)×(Fin (k+1)→ℝ) => a.1)) + unfold sourceFieldDistance + exact (continuous_const.mul (continuous_const.mul + (((continuous_const.mul (continuous_const.mul (hf.pow 2))).add + (continuous_const.mul (he.mul (hf.pow 2)))).sqrt.mul + (he.mul (hf.pow 2)).sqrt))).add + (((continuous_apply _).comp continuous_snd).sub continuous_const).abs + +abbrev SourceContactParameter (n k : ℕ) := ℝ≥0 × (Fin (k+1)→ℝ) × (Fin (n+1)→ℝ) + +def sourceContactDomain (n k : ℕ) : Set (SourceContactParameter n k) := + {a | (∀ l, 0≤a.2.1 l) ∧ Monotone a.2.1 ∧ ∀ j, a.2.2 j∈Icc 1 2} + +def sourceJointPressure (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (z : Fin k→ℝ) (a : SourceContactParameter n k) : ℝ := + sourceExpectedPressure n k f p d a.2.1 z a.1 a.2.2 + +def sourceContactDistance (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (a' a : SourceContactParameter n k) : ℝ := + ‖f‖*|(a'.1:ℝ)-(a.1:ℝ)|+sourceFieldDistance p d a'.2.2 a'.2.1 a.2.1+ + ∑ j : Fin (n+1), (4*perturbationAmplitude (n+1) (fun _ => 1) j^2/(n+1:ℕ))*|a'.2.2 j-a.2.2 j| + +lemma sourceContactDistance_continuous (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (a : SourceContactParameter n k) : Continuous (fun a' => sourceContactDistance n k f p d a' a) := by + unfold sourceContactDistance + have hf : Continuous (fun a' : SourceContactParameter n k => sourceFieldDistance p d a'.2.2 a'.2.1 a.2.1) := + (sourceFieldDistance_joint_continuous (N := n+1) (k := k) p d a.2.1).comp + (f := fun a' : SourceContactParameter n k => (a'.2.2,a'.2.1)) + ((continuous_snd.snd : Continuous (fun a' : SourceContactParameter n k => a'.2.2)).prodMk + (continuous_snd.fst : Continuous (fun a' : SourceContactParameter n k => a'.2.1))) + apply Continuous.add + · have ht : Continuous (fun a' : SourceContactParameter n k => ‖f‖*|(a'.1:ℝ)-(a.1:ℝ)|) := by + exact continuous_const.mul ((NNReal.continuous_coe.comp + (continuous_fst : Continuous (fun a' : SourceContactParameter n k => a'.1))).sub continuous_const).abs + exact ht.add hf + · apply continuous_finsetSum + intro j hj + fun_prop + +lemma sourceContactDistance_self (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (a : SourceContactParameter n k) : sourceContactDistance n k f p d a a=0 := by + simp [sourceContactDistance,sourceFieldDistance_self] + +lemma sourceJointPressure_comparison (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 ⟨by linarith [(ha.2.2 j).1],(ha.2.2 j).2⟩) + (fun j => ⟨by linarith [(ha'.2.2 j).1],(ha'.2.2 j).2⟩) + change |sourceExpectedPressure n k f p d a'.2.1 z a'.1 a'.2.2- + sourceExpectedPressure n k f p d a.2.1 z a.1 a.2.2|≤_ + have hab := abs_sub_le (sourceExpectedPressure n k f p d a'.2.1 z a'.1 a'.2.2) + (sourceExpectedPressure n k f p d a'.2.1 z a.1 a'.2.2) + (sourceExpectedPressure n k f p d a.2.1 z a.1 a.2.2) + have hbc := abs_sub_le (sourceExpectedPressure n k f p d a'.2.1 z a.1 a'.2.2) + (sourceExpectedPressure n k f p d a.2.1 z a.1 a'.2.2) + (sourceExpectedPressure n k f p d a.2.1 z a.1 a.2.2) + change |sourceExpectedPressure n k f p d a.2.1 z a.1 a'.2.2- + sourceExpectedPressure n k f p d a.2.1 z a.1 a.2.2|≤_ at hu + unfold sourceContactDistance + linarith + +lemma sourceJointPressure_continuousOn (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 sourceContactDistance n k f p d a' a) (𝓝 a) + (𝓝 (sourceContactDistance n k f p d a a)) := + (sourceContactDistance_continuous n k f p d a).continuousAt + rw [sourceContactDistance_self] at hc + refine squeeze_zero' (Eventually.of_forall fun _ => norm_nonneg _) ?_ + (hc.mono_left nhdsWithin_le_nhds) + filter_upwards [self_mem_nhdsWithin] with a' ha' + simpa only [Real.norm_eq_abs] using sourceJointPressure_comparison n k f p d z hz hz0 hz1 a' a ha' ha + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DepthBlock.lean b/lean/OAI/Probability/Perceptron/Variational/DepthBlock.lean new file mode 100644 index 0000000000000000000000000000000000000000..4d66af029028fbdfcd2929678661e8ffed0125d7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DepthBlock.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.BlockFocus + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology + +lemma indexedDepthLaw_block_mass (k : ℕ) (z : Fin k → ℝ) + (r : ℕ) (A : FiniteBlock (Fin (k+1)) r) : + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) {R | finiteBlock r R = A} = + ∫⁻ b, indexedBlockSample k A b ∂indexedCascadeBaseLaw k z := by + have hE : MeasurableSet {R : FiniteOverlap (Fin (k+1)) | finiteBlock r R = A} := + measurableSet_eq_fun (finiteBlock_measurable r) measurable_const + rw [← lintegral_indicator_one hE] + simp only [Set.indicator_apply, Pi.one_apply, Set.mem_ofPred_eq] + rw [indexedDepthLaw_lintegral_prefix k z r (fun B => if B = A then 1 else 0)] + apply lintegral_congr + intro b + rw [indexedBlockSample_eq_measure,← lintegral_indicator_one ((Set.to_countable _).measurableSet)] + simp only [Set.indicator_apply, Pi.one_apply, Set.mem_ofPred_eq] + +lemma indexedDepthLaw_focused_mass (k : ℕ) (z : Fin k → ℝ) (r d : ℕ) + (A : FiniteBlock (Fin (k+1)) r) (i : Fin r) : + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) + {R | finiteBlock r R = A ∧ d ≤ (R i r).val} = + ∫⁻ b, indexedBlockFocused k d A i b ∂indexedCascadeBaseLaw k z := by + let E : Set (FiniteOverlap (Fin (k+1))) := {R | finiteBlock r R = A ∧ d ≤ (R i r).val} + have hE : MeasurableSet E := by + exact (measurableSet_eq_fun (finiteBlock_measurable r) measurable_const).inter + ((Set.to_countable {l : Fin (k+1) | d ≤ l.val}).measurableSet.preimage (by fun_prop)) + change (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) E = _ + rw [← lintegral_indicator_one hE] + rw [indexedDepthLaw_lintegral k z (E.indicator 1) (measurable_const.indicator hE)] + apply lintegral_congr + intro b + let S : Set ((Fin r → IndexedLeaf k) × IndexedLeaf k) := + {p | (fun a c => indexedCommonDepth k (p.1 a) (p.1 c)) = A ∧ + d ≤ (indexedCommonDepth k (p.1 i) p.2).val} + have hh := (infiniteReplica_prefix_fresh_preserving (indexedLeafProbability k b) r).lintegral_comp + (f := S.indicator (fun _ => (1 : ℝ≥0∞))) + (measurable_const.indicator ((Set.to_countable S).measurableSet)) + calc + _ = ∫⁻ xs, S.indicator 1 ((fun j : Fin r => xs j.val),xs r) + ∂Measure.infinitePi (fun _ : ℕ => indexedLeafProbability k b) := rfl + _ = ∫⁻ p, S.indicator 1 p + ∂(Measure.pi (fun _ : Fin r => indexedLeafProbability k b)).prod (indexedLeafProbability k b) := hh + _ = _ := by + rw [lintegral_indicator_one ((Set.to_countable S).measurableSet),indexedBlockFocused_eq_measure] + +theorem indexedDepthLaw_focused_formula (k : ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (r d : ℕ) (hd : d ≤ k) (A : FiniteBlock (Fin (k+1)) r) (i : Fin r) : + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) + {R | finiteBlock r R = A ∧ d ≤ (R i r).val} = + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) {R | finiteBlock r R = A} * + ENNReal.ofReal (((∑ j, if d ≤ (A i j).val then (1:ℝ) else 0) - + (if h : d = 0 then 0 else z ⟨d-1,by omega⟩)) / r) := by + rw [indexedDepthLaw_focused_mass,indexedDepthLaw_block_mass, + indexedBlockFocused_integral k z hz hz0 hz1 d hd A i,Fintype.card_fin] + +lemma indexedDepthLaw_one_block_ae (k : ℕ) (z : Fin k → ℝ) : + ∀ᵐ R ∂(indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))), + finiteBlock 1 R = fun _ _ => Fin.last k := by + filter_upwards [indexedDepthLaw_geometry k z] with R hR + funext i j + have hi : i = 0 := Subsingleton.elim _ _ + have hj : j = 0 := Subsingleton.elim _ _ + simpa only [hi,hj,finiteBlock,Fin.val_zero] using hR.2.1 0 + +lemma indexedDepthLaw_pair_tail (k : ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (d : ℕ) (hd : d ≤ k) : + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) {R | d ≤ (R 0 1).val} = + ENNReal.ofReal (1 - (if h : d = 0 then 0 else z ⟨d-1,by omega⟩)) := by + let μ := (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) + let A : FiniteBlock (Fin (k+1)) 1 := fun _ _ => Fin.last k + have hB : μ {R | finiteBlock 1 R = A} = 1 := by + rw [← measure_univ (μ := μ)] + apply measure_congr + filter_upwards [indexedDepthLaw_one_block_ae k z] with R hR + change (finiteBlock 1 R = A) = True + exact propext ⟨fun _ => trivial, fun _ => hR⟩ + have hC : μ {R | finiteBlock 1 R = A ∧ d ≤ (R (0:Fin 1) 1).val} = + μ {R | d ≤ (R 0 1).val} := by + apply measure_congr + filter_upwards [indexedDepthLaw_one_block_ae k z] with R hR + change (finiteBlock 1 R = A ∧ d ≤ (R 0 1).val) = (d ≤ (R 0 1).val) + exact propext ⟨fun h => h.2, fun h => ⟨hR,h⟩⟩ + have h := indexedDepthLaw_focused_formula k z hz hz0 hz1 1 d hd A 0 + change μ _ = μ _ * _ at h + rw [hB,hC] at h + simpa only [A,Fintype.sum_unique,Fin.val_last,ite_eq_left hd,Nat.cast_one,div_one,one_mul] using h + +lemma measureReal_fin_atom_from_tails {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) [IsFiniteMeasure μ] (k : ℕ) + (f : Ω → Fin (k+1)) (hf : Measurable f) (E : Set Ω) (hE : MeasurableSet E) + (c : Fin (k+1)) : + μ.real {x | x ∈ E ∧ f x = c} = + μ.real {x | x ∈ E ∧ c.val ≤ (f x).val} - + μ.real {x | x ∈ E ∧ c.val+1 ≤ (f x).val} := by + have hs : MeasurableSet {x | x ∈ E ∧ c.val+1 ≤ (f x).val} := + hE.inter ((Set.to_countable {l : Fin (k+1) | c.val+1 ≤ l.val}).measurableSet.preimage hf) + have he : {x | x ∈ E ∧ f x = c} = + {x | x ∈ E ∧ c.val ≤ (f x).val} \ {x | x ∈ E ∧ c.val+1 ≤ (f x).val} := by + apply Set.ext + intro x + change (x ∈ E ∧ f x = c) ↔ + (x ∈ E ∧ c.val ≤ (f x).val) ∧ ¬ (x ∈ E ∧ c.val+1 ≤ (f x).val) + constructor + · rintro ⟨hx,hxc⟩ + simp only [hxc,le_refl,and_true,Nat.not_succ_le_self,and_false,not_false_eq_true] + exact hx + · intro hx + have hn : ¬ c.val+1 ≤ (f x).val := fun h => hx.2 ⟨hx.1.1,h⟩ + have hl := hx.1.2 + exact ⟨hx.1.1,Fin.ext (by omega)⟩ + rw [he,measureReal_sdiff (by intro x hx; exact ⟨hx.1, Nat.le_trans (Nat.le_succ _) hx.2⟩) hs] + +theorem finiteGG_of_depth_thresholds (k : ℕ) + (μ : Measure (FiniteOverlap (Fin (k+1)))) [IsProbabilityMeasure μ] + (hh : ∀ r, 1 ≤ r → ∀ (i : Fin r) (A : FiniteBlock (Fin (k+1)) r) + (d : ℕ), d ≤ k+1 → + μ.real {R | finiteBlock r R = A ∧ d ≤ (R i r).val} = + μ.real {R | finiteBlock r R = A} * μ.real {R | d ≤ (R 0 1).val} / r + + (∑ j ∈ Finset.univ.erase i, + μ.real {R | finiteBlock r R = A ∧ d ≤ (R i j).val}) / r) : FiniteGG μ := by + classical + intro r hr i A c + have hE : MeasurableSet {R : FiniteOverlap (Fin (k+1)) | finiteBlock r R = A} := + measurableSet_eq_fun (finiteBlock_measurable r) measurable_const + have hm (i j : ℕ) : Measurable (fun R : FiniteOverlap (Fin (k+1)) => R i j) := by fun_prop + have hAtom (a b : ℕ) : μ.real {R | finiteBlock r R = A ∧ R a b = c} = + μ.real {R | finiteBlock r R = A ∧ c.val ≤ (R a b).val} - + μ.real {R | finiteBlock r R = A ∧ c.val+1 ≤ (R a b).val} := + measureReal_fin_atom_from_tails μ k (fun R => R a b) + (hm a b) {R | finiteBlock r R = A} hE c + have hPair := measureReal_fin_atom_from_tails μ k (fun R => R 0 1) + (hm 0 1) univ MeasurableSet.univ c + simp only [Set.mem_univ,true_and] at hPair + simp_rw [hAtom] + rw [hPair,hh r hr i A c.val (by omega),hh r hr i A (c.val+1) (by omega), + Finset.sum_sub_distrib] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DepthGG.lean b/lean/OAI/Probability/Perceptron/Variational/DepthGG.lean new file mode 100644 index 0000000000000000000000000000000000000000..ef95b695bbe9d8f2db55aee1f08ed0a5585844cb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DepthGG.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DepthBlock + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology +namespace SphericalPerceptronFreeEnergy + +lemma depth_block_row_threshold (k r d : ℕ) + (μ : Measure (FiniteOverlap (Fin (k+1)))) (A : FiniteBlock (Fin (k+1)) r) + (i j : Fin r) : + μ.real {R | finiteBlock r R = A ∧ d ≤ (R i j).val} = + μ.real {R | finiteBlock r R = A} * (if d ≤ (A i j).val then 1 else 0) := by + have he (R : FiniteOverlap (Fin (k+1))) (hR : finiteBlock r R = A) : R i j = A i j := + congrFun (congrFun hR i) j + by_cases hd : d ≤ (A i j).val + · rw [ite_eq_left hd,mul_one] + congr 1 + ext R + constructor + · exact And.left + · intro hR + exact ⟨hR,by rw [he R hR]; exact hd⟩ + · rw [ite_eq_right hd,mul_zero] + have hEmpty : {R : FiniteOverlap (Fin (k+1)) | finiteBlock r R = A ∧ d ≤ (R i j).val} = ∅ := by + ext R + simp only [Set.mem_ofPred_eq,Set.mem_empty_iff_false,iff_false,not_and] + intro hR hD + exact hd (by simpa only [he R hR] using hD) + rw [hEmpty,measureReal_empty] + +lemma indexedDepthLaw_block_zero_of_diagonal (k r : ℕ) (z : Fin k → ℝ) + (A : FiniteBlock (Fin (k+1)) r) (i : Fin r) (hA : A i i ≠ Fin.last k) : + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))).real + {R | finiteBlock r R = A} = 0 := by + convert measureReal_empty (μ := (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1))))) using 1 + apply measureReal_congr + filter_upwards [indexedDepthLaw_geometry k z] with R hR + change (finiteBlock r R = A) = False + apply propext + simp only [iff_false] + intro hB + have he : R i i = A i i := congrFun (congrFun hB i) i + exact hA (he.symm.trans (hR.2.1 i)) + +lemma indexedDepthLaw_focused_formula_real (k : ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (r d : ℕ) (hd : d ≤ k) (A : FiniteBlock (Fin (k+1)) r) (i : Fin r) + (hA : A i i = Fin.last k) : + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))).real + {R | finiteBlock r R = A ∧ d ≤ (R i r).val} = + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))).real {R | finiteBlock r R = A} * + (((∑ j, if d ≤ (A i j).val then (1:ℝ) else 0) - + (if h : d = 0 then 0 else z ⟨d-1,by omega⟩)) / r) := by + have hb : (if h : d = 0 then (0:ℝ) else z ⟨d-1,by omega⟩) ≤ 1 := by + split_ifs + · norm_num + · exact (hz1 _).le + have hc : (1:ℝ) ≤ ∑ j, if d ≤ (A i j).val then (1:ℝ) else 0 := by + have he := Finset.single_le_sum (s := Finset.univ) + (f := fun j : Fin r => if d ≤ (A i j).val then (1:ℝ) else 0) + (fun j _ => by split_ifs <;> norm_num) (Finset.mem_univ i) + simpa only [hA,Fin.val_last,ite_eq_left hd] using he + have hn : 0 ≤ ((∑ j, if d ≤ (A i j).val then (1:ℝ) else 0) - + (if h : d = 0 then (0:ℝ) else z ⟨d-1,by omega⟩)) / r := + div_nonneg (sub_nonneg.mpr (hb.trans hc)) (Nat.cast_nonneg _) + have he := congrArg ENNReal.toReal (indexedDepthLaw_focused_formula k z hz hz0 hz1 r d hd A i) + simpa only [measureReal_def,ENNReal.toReal_mul,ENNReal.toReal_ofReal hn] using he + +lemma indexedDepthLaw_pair_tail_real (k : ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (d : ℕ) (hd : d ≤ k) : + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))).real {R | d ≤ (R 0 1).val} = + 1 - (if h : d = 0 then 0 else z ⟨d-1,by omega⟩) := by + have hb : (if h : d = 0 then (0:ℝ) else z ⟨d-1,by omega⟩) ≤ 1 := by + split_ifs + · norm_num + · exact (hz1 _).le + have he := congrArg ENNReal.toReal (indexedDepthLaw_pair_tail k z hz hz0 hz1 d hd) + simpa only [measureReal_def,ENNReal.toReal_ofReal (sub_nonneg.mpr hb)] using he + +theorem indexedDepthLaw_finiteGG (k : ℕ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) : + FiniteGG (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) := by + apply finiteGG_of_depth_thresholds + intro r _hr i A d hd + let μ := (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))) + change μ.real {R | finiteBlock r R = A ∧ d ≤ (R i r).val} = + μ.real {R | finiteBlock r R = A} * μ.real {R | d ≤ (R 0 1).val} / r + + (∑ j ∈ Finset.univ.erase i, μ.real {R | finiteBlock r R = A ∧ d ≤ (R i j).val}) / r + by_cases hdk : d ≤ k + · by_cases hA : A i i = Fin.last k + · have he := indexedDepthLaw_focused_formula_real k z hz hz0 hz1 r d hdk A i hA + have hp := indexedDepthLaw_pair_tail_real k z hz hz0 hz1 d hdk + change μ.real _ = μ.real _ * _ at he + change μ.real _ = _ at hp + rw [he,hp] + simp_rw [depth_block_row_threshold k r d μ A i] + rw [← Finset.mul_sum,Finset.sum_erase_eq_sub (Finset.mem_univ i)] + simp only [hA,Fin.val_last,ite_eq_left hdk] + ring + · have hB := indexedDepthLaw_block_zero_of_diagonal k r z A i hA + change μ.real _ = 0 at hB + have hF : μ.real {R | finiteBlock r R = A ∧ d ≤ (R i r).val} = 0 := + measureReal_mono_null (fun _ h => h.1) hB + rw [hF,hB] + simp_rw [depth_block_row_threshold k r d μ A i,hB,zero_mul] + simp + · have he : d = k+1 := by omega + subst d + have hfalse (l : Fin (k+1)) : ¬ k+1 ≤ l.val := Nat.not_le.mpr l.isLt + simp only [hfalse,and_false] + simp + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DepthLaw.lean b/lean/OAI/Probability/Perceptron/Variational/DepthLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..d8a4fac2a1f841d35ec8a689d86406fc193dcab2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DepthLaw.lean @@ -0,0 +1,228 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelReference + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology + +def indexedInfiniteLeafMeasure (k : ℕ) (z : Fin k → ℝ) : + Measure (IndexedCascadeBase k × (ℕ → IndexedLeaf k)) := + (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) ⊗ₘ + kernelInfiniteReplica (indexedLeafKernel k) ℕ + +instance indexedInfiniteLeafMeasure_probability (k : ℕ) (z : Fin k → ℝ) : + IsProbabilityMeasure (indexedInfiniteLeafMeasure k z) := by + unfold indexedInfiniteLeafMeasure + infer_instance + +def indexedDepthArray (k : ℕ) (xs : ℕ → IndexedLeaf k) : FiniteOverlap (Fin (k+1)) := + fun i j => indexedCommonDepth k (xs i) (xs j) + +lemma indexedDepthArray_measurable (k : ℕ) : Measurable (indexedDepthArray k) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + change Measurable (fun xs : ℕ → IndexedLeaf k => indexedCommonDepth k (xs i) (xs j)) + have hf : Measurable (fun p : IndexedLeaf k × IndexedLeaf k => indexedCommonDepth k p.1 p.2) := + measurable_of_countable _ + have hg : Measurable (fun xs : ℕ → IndexedLeaf k => (xs i,xs j)) := + (measurable_pi_apply i).prodMk (measurable_pi_apply j) + exact hf.comp hg + +def indexedDepthLaw (k : ℕ) (z : Fin k → ℝ) : ProbabilityMeasure (FiniteOverlap (Fin (k+1))) := + ⟨(indexedInfiniteLeafMeasure k z).map (fun a => indexedDepthArray k a.2), + inferInstance⟩ + +lemma indexedDepthLaw_lintegral (k : ℕ) (z : Fin k → ℝ) + (F : FiniteOverlap (Fin (k+1)) → ℝ≥0∞) (hF : Measurable F) : + (∫⁻ R, F R ∂(indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1))))) = + ∫⁻ b, ∫⁻ xs, F (indexedDepthArray k xs) + ∂Measure.infinitePi (fun _ : ℕ => indexedLeafProbability k b) ∂indexedCascadeBaseLaw k z := by + change (∫⁻ R, F R ∂(indexedInfiniteLeafMeasure k z).map + (fun a => indexedDepthArray k a.2)) = _ + calc + _ = ∫⁻ a, F (indexedDepthArray k a.2) ∂indexedInfiniteLeafMeasure k z := + lintegral_map hF ((indexedDepthArray_measurable k).comp measurable_snd) + _ = _ := by + exact Measure.lintegral_compProd (hF.comp ((indexedDepthArray_measurable k).comp measurable_snd)) + +lemma indexedDepthLaw_lintegral_prefix (k : ℕ) (z : Fin k → ℝ) (r : ℕ) + (F : FiniteBlock (Fin (k+1)) r → ℝ≥0∞) : + (∫⁻ R, F (finiteBlock r R) ∂(indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1))))) = + ∫⁻ b, ∫⁻ xs : Fin r → IndexedLeaf k, + F (fun i j => indexedCommonDepth k (xs i) (xs j)) + ∂Measure.pi (fun _ => indexedLeafProbability k b) ∂indexedCascadeBaseLaw k z := by + have hF : Measurable F := measurable_of_countable _ + refine (indexedDepthLaw_lintegral k z (fun R => F (finiteBlock r R)) + (hF.comp (finiteBlock_measurable r))).trans ?_ + apply lintegral_congr + intro b + exact (infiniteReplica_prefix_preserving (indexedLeafProbability k b) r).lintegral_comp + (measurable_of_countable (fun xs : Fin r → IndexedLeaf k => + F (fun i j => indexedCommonDepth k (xs i) (xs j)))) + +lemma infiniteReplica_prefix_fresh_preserving {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] (r : ℕ) : + MeasurePreserving (fun xs : ℕ → S => ((fun i : Fin r => xs i.val),xs r)) + (Measure.infinitePi (fun _ : ℕ => μ)) ((Measure.pi (fun _ : Fin r => μ)).prod μ) := by + have hfinite := measurePreserving_piFinSuccAbove (fun _ : Fin (r+1) => μ) (Fin.last r) + have h := (Measure.measurePreserving_swap (μ := μ) (ν := Measure.pi (fun _ : Fin r => μ))).comp + (hfinite.comp (infiniteReplica_prefix_preserving μ (r+1))) + convert h using 1 + funext xs + simp only [Function.comp_def,MeasurableEquiv.piFinSuccAbove_apply] + apply Prod.ext + · funext i + simp [Fin.init] + · rfl + +lemma indexedDepthLaw_geometry (k : ℕ) (z : Fin k → ℝ) : + ∀ᵐ R ∂(indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))), + (∀ i j, R i j = R j i) ∧ (∀ i, R i i = Fin.last k) ∧ + ∀ i j l, min (R i j) (R i l) ≤ R j l := by + apply (ae_map_iff ((indexedDepthArray_measurable k).comp measurable_snd).aemeasurable + (by measurability)).mpr + exact ae_of_all _ fun a => ⟨fun i j => indexedCommonDepth_comm k _ _, + fun i => indexedCommonDepth_self k _,fun i j l => indexedCommonDepth_ultrametric k _ _ _⟩ + +def CascadeShapeReplicas : (n : ℕ) → CascadeVisitShape n → Type + | 0, r => Fin r + | n + 1, ss => Σ i : Fin ss.length, CascadeShapeReplicas n ss[i] + +instance cascadeShapeReplicas_fintype (n : ℕ) (s : CascadeVisitShape n) : + Fintype (CascadeShapeReplicas n s) := by + induction n with + | zero => exact inferInstanceAs (Fintype (Fin s)) + | succ n ih => + letI (i : Fin s.length) := ih s[i] + exact inferInstanceAs (Fintype (Σ i : Fin s.length, CascadeShapeReplicas n s[i])) + +def cascadeShapeLeaves : (n : ℕ) → (s : CascadeVisitShape n) → + CascadeShapeReplicas n s → IndexedLeaf n + | 0, _, _ => () + | n + 1, ss, i => (i.1.val, 0, cascadeShapeLeaves n ss[i.1] i.2) + +lemma cascadeShapeReplicas_nonempty (n : ℕ) (s : CascadeVisitShape n) + (hs : s.Valid n) : Nonempty (CascadeShapeReplicas n s) := by + induction n with + | zero => exact ⟨⟨0, hs⟩⟩ + | succ n ih => + have hlen : 0 < s.length := List.length_pos_iff.mpr hs.1 + obtain ⟨x⟩ := ih s[0] (hs.2 _ (List.getElem_mem hlen)) + exact ⟨⟨⟨0, hlen⟩, x⟩⟩ + +lemma cascadeShapeReplicas_card (n : ℕ) (s : CascadeVisitShape n) : + Fintype.card (CascadeShapeReplicas n s) = cascadeVisitCount n s := by + induction n with + | zero => exact Fintype.card_fin s + | succ n ih => + change Fintype.card (Σ i : Fin s.length, CascadeShapeReplicas n s[i]) = _ + rw [Fintype.card_sigma] + simp_rw [ih] + change (∑ i : Fin s.length, cascadeVisitCount n s[i]) = (s.map (cascadeVisitCount n)).sum + rw [← List.sum_ofFn] + simp + +def cascadeShapeReplicasOfFnEquiv (n m : ℕ) (s : Fin m → CascadeVisitShape n) : + (Σ i : Fin m, CascadeShapeReplicas n (s i)) ≃ + CascadeShapeReplicas (n + 1) (List.ofFn s) := by + change (Σ i : Fin m, CascadeShapeReplicas n (s i)) ≃ + (Σ i : Fin (List.ofFn s).length, CascadeShapeReplicas n (List.ofFn s)[i]) + refine Equiv.sigmaCongr (finCongr (List.length_ofFn).symm) (fun i => ?_) + exact Equiv.cast (by simp) + +lemma cascadeShapeLeaves_cast (n : ℕ) {s t : CascadeVisitShape n} + (h : s = t) (x : CascadeShapeReplicas n s) : + cascadeShapeLeaves n t (cast (congrArg (CascadeShapeReplicas n) h) x) = + cascadeShapeLeaves n s x := by + cases h + rfl + +lemma cascadeShapeLeaves_ofFn (n m : ℕ) (s : Fin m → CascadeVisitShape n) + (i : Fin m) (x : CascadeShapeReplicas n (s i)) : + cascadeShapeLeaves (n + 1) (List.ofFn s) + (cascadeShapeReplicasOfFnEquiv n m s ⟨i,x⟩) = + (i.val, 0, cascadeShapeLeaves n (s i) x) := by + simp only [cascadeShapeReplicasOfFnEquiv, Equiv.sigmaCongr, cascadeShapeLeaves] + change (i.val, 0, cascadeShapeLeaves n _ (cast _ x)) = _ + have h : (List.ofFn s)[(finCongr (List.length_ofFn).symm) i] = s i := by simp + congr 2 + exact cascadeShapeLeaves_cast n h.symm x + +theorem finite_leaf_tuple_shape (n : ℕ) : + ∀ (ι : Type) [Fintype ι] [Nonempty ι] (xs : ι → IndexedLeaf n), + ∃ s : CascadeVisitShape n, s.Valid n ∧ + ∃ e : ι ≃ CascadeShapeReplicas n s, + ∀ i j, indexedCommonDepth n (xs i) (xs j) = + indexedCommonDepth n (cascadeShapeLeaves n s (e i)) + (cascadeShapeLeaves n s (e j)) := by + classical + induction n with + | zero => + intro ι _ _ xs + exact ⟨Fintype.card ι, Fintype.card_pos, Fintype.equivFin ι, fun _ _ => rfl⟩ + | succ n ih => + intro ι _ _ xs + let root : ι → ℕ × ℕ := fun i => ((xs i).1, (xs i).2.1) + let V := Set.range root + let : Fintype V := (Set.finite_range root).fintype + let g₀ : ι → V := fun i => ⟨root i, ⟨i,rfl⟩⟩ + have hg₀ : Function.Surjective g₀ := by + rintro ⟨v, i, hi⟩ + exact ⟨i, Subtype.ext hi⟩ + let : Nonempty V := Nonempty.map g₀ inferInstance + let g : ι → Fin (Fintype.card V) := fun i => Fintype.equivFin V (g₀ i) + have hg : Function.Surjective g := (Fintype.equivFin V).surjective.comp hg₀ + have hroot (i j : ι) : g i = g j ↔ (xs i).1 = (xs j).1 ∧ (xs i).2.1 = (xs j).2.1 := by + change (Fintype.equivFin V) (g₀ i) = (Fintype.equivFin V) (g₀ j) ↔ _ + rw [Equiv.apply_eq_iff_eq, Subtype.ext_iff] + exact Prod.ext_iff + let J (a : Fin (Fintype.card V)) := {i : ι // g i = a} + let (a : Fin (Fintype.card V)) : Nonempty (J a) := + ⟨⟨Classical.choose (hg a), Classical.choose_spec (hg a)⟩⟩ + have hc (a : Fin (Fintype.card V)) := ih (J a) (fun i => (xs i.val).2.2) + choose ss hv ee he using hc + let s : CascadeVisitShape (n + 1) := List.ofFn ss + have hs : s.Valid (n + 1) := by + constructor + · have hp : 0 < Fintype.card V := Fintype.card_pos + apply List.length_pos_iff.mp + simpa only [s, List.length_ofFn] using hp + · intro t ht + obtain ⟨a, rfl⟩ := List.mem_ofFn.mp ht + exact hv a + let E : ι ≃ CascadeShapeReplicas (n + 1) s := + ((Equiv.sigmaFiberEquiv g).symm.trans (Equiv.sigmaCongrRight ee)).trans + (cascadeShapeReplicasOfFnEquiv n (Fintype.card V) ss) + refine ⟨s, hs, E, ?_⟩ + intro i j + obtain ⟨⟨a,i⟩, rfl⟩ := (Equiv.sigmaFiberEquiv g).surjective i + obtain ⟨⟨b,j⟩, rfl⟩ := (Equiv.sigmaFiberEquiv g).surjective j + have hE (a : Fin (Fintype.card V)) (i : J a) : + cascadeShapeLeaves (n + 1) s (E ((Equiv.sigmaFiberEquiv g) ⟨a,i⟩)) = + (a.val, 0, cascadeShapeLeaves n (ss a) (ee a i)) := by + simp only [E, Equiv.trans_apply, Equiv.symm_apply_apply, + Equiv.sigmaCongrRight_apply, s, cascadeShapeLeaves_ofFn] + rw [hE, hE] + change indexedCommonDepth (n + 1) (xs i.val) (xs j.val) = _ + by_cases hab : a = b + · subst b + have hij : (xs i.val).1 = (xs j.val).1 ∧ (xs i.val).2.1 = (xs j.val).2.1 := + (hroot i.val j.val).mp (i.property.trans j.property.symm) + simp only [indexedCommonDepth, ite_eq_left hij, and_self, ↓reduceIte] + exact congrArg Fin.succ (he a i j) + · have hij : ¬ ((xs i.val).1 = (xs j.val).1 ∧ (xs i.val).2.1 = (xs j.val).2.1) := by + intro hij + exact hab (i.property.symm.trans ((hroot i.val j.val).mpr hij) |>.trans j.property) + have habv : a.val ≠ b.val := fun h => hab (Fin.ext h) + simp only [indexedCommonDepth, ite_eq_right hij, habv, false_and, ↓reduceIte] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DiagonalDeviation.lean b/lean/OAI/Probability/Perceptron/Variational/DiagonalDeviation.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ee031922e6b44e14bf22953797b08a97d4dfa60 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DiagonalDeviation.lean @@ -0,0 +1,121 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory Filter Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma exists_slow_diagonal {b : ℕ→ℕ→ℝ} (hb : ∀ n p, 0≤b n p) + (hlim : ∀ p, Tendsto (fun n => b n p) atTop (𝓝 0)) : + ∃ J : ℕ→ℕ, Monotone J ∧ (∀ n, J n≤n) ∧ Tendsto J atTop atTop ∧ + Tendsto (fun n => ∑ p∈Finset.range (J n), b n p) atTop (𝓝 0) := by + classical + let P := fun n k => ∀ m≥n, (∑ p∈Finset.range k, b m p)≤1/(k+1:ℝ) + have hP0 (n) : P n 0 := by intro m hm; simp + let J := fun n => Nat.findGreatest (P n) n + have hJ (n) : J n≤n := Nat.findGreatest_le _ + have hJP (n) : P n (J n) := Nat.findGreatest_spec (Nat.zero_le n) (hP0 n) + have hJmono : Monotone J := by + intro m n hmn + exact Nat.findGreatest_mono (fun k hk l hl => hk l (hmn.trans hl)) hmn + have hPJ (k) : ∀ᶠ n in atTop, k≤J n := by + have hs : Tendsto (fun n => ∑ p∈Finset.range k, b n p) atTop (𝓝 (0:ℝ)) := by + simpa using tendsto_finsetSum (Finset.range k) (fun p _ => hlim p) + have he := hs.eventually (gt_mem_nhds (by positivity : (0:ℝ)<1/(k+1:ℝ))) + obtain ⟨N,hN⟩ := eventually_atTop.1 he + filter_upwards [eventually_ge_atTop (max N k)] with n hn + exact Nat.le_findGreatest ((le_max_right N k).trans hn) + (fun m hm => (hN m ((le_max_left N k).trans (hn.trans hm))).le) + have hJlim : Tendsto J atTop atTop := tendsto_atTop.2 hPJ + refine ⟨J,hJmono,hJ,hJlim,?_⟩ + apply squeeze_zero (fun n => Finset.sum_nonneg (fun p _ => hb n p)) + (fun n => hJP n n le_rfl) + have hh : Tendsto (fun n => (J n:ℝ)+1) atTop atTop := + (tendsto_natCast_atTop_atTop.comp hJlim).atTop_add tendsto_const_nhds + simpa only [one_div,Function.comp_def] using tendsto_inv_atTop_zero.comp hh + +variable {X : Type*} [MeasurableSpace X] (μ : Measure X) + (d : ℕ→ℕ→X→ℝ) + +def diagonalDeviationMass (J : ℕ→ℕ) (n : ℕ) : ℝ := + ∑ p∈Finset.range (J n), ∫ v, d n p v ∂μ + +def diagonalDeviationThreshold (J : ℕ→ℕ) (n : ℕ) : ℝ := + Real.sqrt (diagonalDeviationMass μ d J n)+1/(n+1:ℝ) + +def diagonalGoodSet (J : ℕ→ℕ) (n : ℕ) : Set X := + {v | ∀ p∈Finset.range (J n), d n p v≤diagonalDeviationThreshold μ d J n} + +lemma diagonalDeviationThreshold_pos (J : ℕ→ℕ) (n : ℕ) : + 0 MeasurableSet.iInter fun _ => measurableSet_le (hm n p) measurable_const + +lemma diagonalGoodSet_compl_bound [IsProbabilityMeasure μ] (hn : ∀ n p v, 0≤d n p v) + (hi : ∀ n p, Integrable (d n p) μ) (J : ℕ→ℕ) (n : ℕ) : + μ.real (diagonalGoodSet μ d J n)ᶜ ≤ Real.sqrt (diagonalDeviationMass μ d J n) := by + let S := fun v => ∑ p∈Finset.range (J n), d n p v + have hSn (v) : 0≤S v := Finset.sum_nonneg fun p _ => hn n p v + have hSi : Integrable S μ := integrable_finsetSum _ (fun p _ => hi n p) + have hSm : ∫ v, S v ∂μ = diagonalDeviationMass μ d J n := integral_finsetSum _ (fun p _ => hi n p) + have ha : 0≤diagonalDeviationMass μ d J n := hSm ▸ integral_nonneg hSn + have hs : (diagonalGoodSet μ d J n)ᶜ ⊆ {v | diagonalDeviationThreshold μ d J n≤S v} := by + intro v hv + simp only [diagonalGoodSet,mem_compl_iff,mem_ofPred_eq,not_forall,not_le] at hv + obtain ⟨p,hp,hpv⟩ := hv + exact hpv.le.trans (Finset.single_le_sum (fun q _ => hn n q v) hp) + have hb := mul_meas_ge_le_integral_of_nonneg (ae_of_all μ hSn) hSi + (diagonalDeviationThreshold μ d J n) + rw [hSm] at hb + have he := diagonalDeviationThreshold_pos μ d J n + calc + _ ≤ μ.real {v | diagonalDeviationThreshold μ d J n≤S v} := measureReal_mono hs + _ ≤ diagonalDeviationMass μ d J n/diagonalDeviationThreshold μ d J n := + (le_div_iff₀ he).2 (by simpa [mul_comm] using hb) + _ ≤ Real.sqrt (diagonalDeviationMass μ d J n) := by + apply (div_le_iff₀ he).2 + dsimp [diagonalDeviationThreshold] + nlinarith [Real.sq_sqrt ha, mul_nonneg (Real.sqrt_nonneg (diagonalDeviationMass μ d J n)) + (by positivity : (0:ℝ)≤1/(n+1:ℝ))] + +lemma diagonalGoodSet_compl_tendsto [IsProbabilityMeasure μ] (hn : ∀ n p v, 0≤d n p v) + (hi : ∀ n p, Integrable (d n p) μ) (J : ℕ→ℕ) + (hJ : Tendsto (diagonalDeviationMass μ d J) atTop (𝓝 0)) : + Tendsto (fun n => μ.real (diagonalGoodSet μ d J n)ᶜ) atTop (𝓝 0) := by + apply squeeze_zero (fun n => measureReal_nonneg) + (diagonalGoodSet_compl_bound μ d hn hi J) + simpa only [Function.comp_def,Real.sqrt_zero] using Real.continuous_sqrt.continuousAt.tendsto.comp hJ + +lemma diagonalDeviationThreshold_tendsto (J : ℕ→ℕ) + (hJ : Tendsto (diagonalDeviationMass μ d J) atTop (𝓝 0)) : + Tendsto (diagonalDeviationThreshold μ d J) atTop (𝓝 0) := by + have h1 : Tendsto (fun n : ℕ => 1/(n+1:ℝ)) atTop (𝓝 0) := by + have hh : Tendsto (fun n : ℕ => (n:ℝ)+1) atTop atTop := + (tendsto_natCast_atTop_atTop (R:=ℝ)).atTop_add (tendsto_const_nhds (x:=(1:ℝ))) + simpa only [one_div,Function.comp_def] using tendsto_inv_atTop_zero.comp hh + change Tendsto (fun n => Real.sqrt (diagonalDeviationMass μ d J n)+1/(n+1:ℝ)) atTop (𝓝 0) + simpa only [Function.comp_def,Real.sqrt_zero,zero_add] using + (Real.continuous_sqrt.continuousAt.tendsto.comp hJ).add h1 + +lemma diagonalGoodSet_deviation_tendsto (hn : ∀ n p v, 0≤d n p v) (J : ℕ→ℕ) + (hJ : Tendsto J atTop atTop) (hmass : Tendsto (diagonalDeviationMass μ d J) atTop (𝓝 0)) + (v : ℕ→X) (hv : ∀ᶠ n in atTop, v n∈diagonalGoodSet μ d J n) (p : ℕ) : + Tendsto (fun n => d n p (v n)) atTop (𝓝 0) := by + apply squeeze_zero' (Eventually.of_forall fun n => hn n p (v n)) _ + (diagonalDeviationThreshold_tendsto μ d J hmass) + filter_upwards [hv, hJ.eventually (eventually_gt_atTop p)] with n hn hnp + exact hn p (Finset.mem_range.2 hnp) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/DilationExpansion.lean b/lean/OAI/Probability/Perceptron/Variational/DilationExpansion.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2feb0a44ba94435ed1865808fcba63d6a947c6d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/DilationExpansion.lean @@ -0,0 +1,90 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.HeatLogBCF + +namespace OAI + +noncomputable section +open Set +open scoped BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def weightedDerivative (w : ℝ→ᵇℝ) (hw : HasCompactSupport (w : ℝ→ℝ)) (k : ℕ) : ℝ→ᵇℝ := + ofCompactSupport (fun z => z^k*w z) ((continuous_id.pow k).mul w.continuous) hw.mul_left + +lemma weightedDerivative_bound (w : ℝ→ᵇℝ) (hw : HasCompactSupport (w : ℝ→ℝ)) (k : ℕ) (z : ℝ) : + |z^k*w z|≤‖weightedDerivative w hw k‖ := (weightedDerivative w hw k).norm_coe_le_norm z + +lemma Jet3.dilation_has1 (g : Jet3) (s t : ℝ) : + HasDerivAt (fun u => g.f (Real.exp u*s)) (Real.exp t*s*g.d1 (Real.exp t*s)) t := by + simpa only [Function.comp_def, mul_comm] using (g.has1 (Real.exp t*s)).comp t ((Real.hasDerivAt_exp t).mul_const s) + +lemma Jet3.dilation_has2 (g : Jet3) (s t : ℝ) : + HasDerivAt (fun u => Real.exp u*s*g.d1 (Real.exp u*s)) + (Real.exp t*s*g.d1 (Real.exp t*s)+(Real.exp t*s)^2*g.d2 (Real.exp t*s)) t := by + have h := ((Real.hasDerivAt_exp t).mul_const s).mul + ((g.has2 (Real.exp t*s)).comp t ((Real.hasDerivAt_exp t).mul_const s)) + convert h using 1 <;> first | rfl | (simp only [Function.comp_apply]; ring) + +lemma Jet3.dilation_remainder (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) (s t : ℝ) : + |g.f (Real.exp t*s)-g.f s-t*s*g.d1 s|≤ + (‖weightedDerivative g.d1 h1 1‖+‖weightedDerivative g.d2 h2 2‖)*t^2/2 := by + have hd : deriv (fun u => g.f (Real.exp u*s))=fun u => Real.exp u*s*g.d1 (Real.exp u*s) := + funext fun u => (g.dilation_has1 s u).deriv + have hd2 : iteratedDeriv 2 (fun u => g.f (Real.exp u*s))= + fun u => Real.exp u*s*g.d1 (Real.exp u*s)+(Real.exp u*s)^2*g.d2 (Real.exp u*s) := by + rw [iteratedDeriv_succ,iteratedDeriv_one,hd] + exact funext fun u => (g.dilation_has2 s u).deriv + have hc : ContDiff ℝ 2 (fun u => g.f (Real.exp u*s)) := + (g.contDiff.of_le (by norm_num)).comp (Real.contDiff_exp.mul contDiff_const) + have ht := first_order_taylor_bound hc _ (fun u => by + rw [hd2] + apply (abs_add_le _ _).trans + simpa only [pow_one] using add_le_add + (weightedDerivative_bound g.d1 h1 1 (Real.exp u*s)) (weightedDerivative_bound g.d2 h2 2 (Real.exp u*s))) 0 t + simp only [hd,Real.exp_zero,one_mul,sub_zero] at ht + convert ht using 1; ring_nf + +lemma dilation_lipschitz_bound (w w' : ℝ→ᵇℝ) (hw' : HasCompactSupport (w' : ℝ→ℝ)) + (hd : ∀ x,HasDerivAt (w : ℝ→ℝ) (w' x) x) (s t : ℝ) : + |w (Real.exp t*s)-w s|≤‖weightedDerivative w' hw' 1‖*|t| := by + have hh u : HasDerivAt (fun u => w (Real.exp u*s)) (Real.exp u*s*w' (Real.exp u*s)) u := by + simpa only [Function.comp_def, mul_comm] using (hd (Real.exp u*s)).comp u ((Real.hasDerivAt_exp u).mul_const s) + have hl := lipschitzWith_of_nnnorm_deriv_le (C:=‖weightedDerivative w' hw' 1‖₊) + (fun u => (hh u).differentiableAt) (fun u => by + apply NNReal.coe_le_coe.mp + rw [coe_nnnorm,Real.norm_eq_abs,(hh u).deriv] + simpa only [pow_one,coe_nnnorm] using weightedDerivative_bound w' hw' 1 (Real.exp u*s)) + simpa only [Real.dist_eq,sub_zero,Real.exp_zero,one_mul,coe_nnnorm] using hl.dist_le_mul t 0 + +theorem Jet3.cavity_log_dilation_expansion (g : Jet3) + (h1 : HasCompactSupport (g.d1 : ℝ→ℝ)) (h2 : HasCompactSupport (g.d2 : ℝ→ℝ)) + (h3 : HasCompactSupport (g.d3 : ℝ→ℝ)) (s t u : ℝ) : + |g.f (Real.exp t*s+u)-g.f s-t*s*g.d1 s-u*g.d1 s-u^2/2*g.d2 s|≤ + (‖weightedDerivative g.d1 h1 1‖+‖weightedDerivative g.d2 h2 2‖)*t^2/2+ + ‖weightedDerivative g.d2 h2 1‖*|t| * |u|+ + ‖weightedDerivative g.d3 h3 1‖*|t| * u^2/2+‖g.d3‖*|u| ^3/6 := by + have ht := second_order_taylor_bound g.contDiff ‖g.d3‖ (fun z => by rw [g.deriv3_eq]; exact g.d3.norm_coe_le_norm z) + (Real.exp t*s) (Real.exp t*s+u) + simp only [g.deriv_eq,g.deriv2_eq,add_sub_cancel_left] at ht + have hd := g.dilation_remainder h1 h2 s t + have h₁ := dilation_lipschitz_bound g.d1 g.d2 h2 g.has2 s t + have h₂ := dilation_lipschitz_bound g.d2 g.d3 h3 g.has3 s t + calc + _ = |(g.f (Real.exp t*s+u)-g.f (Real.exp t*s)-g.d1 (Real.exp t*s)*u-g.d2 (Real.exp t*s)*u^2/2)+ + (g.f (Real.exp t*s)-g.f s-t*s*g.d1 s)+ + (g.d1 (Real.exp t*s)-g.d1 s)*u+(g.d2 (Real.exp t*s)-g.d2 s)*u^2/2| := by congr 1; ring + _ ≤ |g.f (Real.exp t*s+u)-g.f (Real.exp t*s)-g.d1 (Real.exp t*s)*u-g.d2 (Real.exp t*s)*u^2/2|+ + |g.f (Real.exp t*s)-g.f s-t*s*g.d1 s|+ + |(g.d1 (Real.exp t*s)-g.d1 s)*u|+|(g.d2 (Real.exp t*s)-g.d2 s)*u^2/2| := by + exact (abs_add_le _ _).trans (add_le_add ((abs_add_le _ _).trans (add_le_add (abs_add_le _ _) le_rfl)) le_rfl) + _ ≤ _ := by + rw [abs_mul,abs_div,abs_mul,abs_pow,abs_of_nonneg (by norm_num : (0:ℝ)≤2),sq_abs] + have h₁u := mul_le_mul_of_nonneg_right h₁ (abs_nonneg u) + have h₂u := div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right h₂ (sq_nonneg u)) (by norm_num : (0:ℝ)≤2) + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/EnergyMean.lean b/lean/OAI/Probability/Perceptron/Variational/EnergyMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..8a16e16dcbb83f7ae333585fb1d1520afcc1b3a7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/EnergyMean.lean @@ -0,0 +1,157 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.KernelEnergyConcentration +import OAI.Probability.Perceptron.Variational.AnnealedIBP + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma gibbsReplicaMean_const_of_integrable {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {H : S → ℝ} (hH : Measurable H) + (he : Integrable (fun x => Real.exp (H x)) μ) (r : ℕ) (c : ℝ) : + gibbsReplicaMean μ H r (fun _ => c) = c := by + let := tilt_law_probability_of_integrable μ (by simpa only [one_mul] using he : + Integrable (fun x => Real.exp (1*H x)) μ) + rw [gibbsReplicaMean_integral_of_integrable μ hH he] + simp + +lemma sourceCoupling_exp_integrable_ae (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (z : Fin k → ℝ) (t : ℝ≥0) : + ∀ᵐ a ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw, + Integrable (fun x => Real.exp (sourceCouplingHamiltonian n k f p d h u a x)) (sourceSpinLeafKernel n k a.1) ∧ + Integrable (fun x => Real.exp (sourceCouplingHamiltonian n k f p d h u a x)* + sourceCouplingEnergy n k p d h j a x) (sourceSpinLeafKernel n k a.1) := by + have hH := sourceCouplingHamiltonian_measurable n k f p d h u + have hY := sourceCouplingEnergy_measurable n k p d h j + filter_upwards [sourceCoupling_all_exp_ae n k f p d h hh0 hh u j z t] with a ha + constructor + · simpa only [zero_mul,add_zero] using ha 0 + · simpa only [zero_mul,add_zero,pow_one] using coupling_weighted_power_integrable + (sourceSpinLeafKernel n k a.1) hH.of_uncurry_left hY.of_uncurry_left ha 0 1 + +lemma sourceCoupling_energy_mean (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (z : Fin k → ℝ) (t : ℝ≥0) + (hYi : Integrable (fun a => tiltMean (sourceSpinLeafKernel n k a.1) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => |sourceCouplingEnergy n k p d h j a x|) 1) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw)) : + let H := sourceCouplingHamiltonian n k f p d h u + let Y := sourceCouplingEnergy n k p d h j + let C := sourceCouplingCovariance n k p d u j + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + (∫ a, tiltMean (sourceSpinLeafKernel n k a.1) (H a) (Y a) 1 ∂P) = + perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j* + ((k:ℝ)/(k+1:ℕ))^(d j)- + ∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) 2 (fun x => C (x 1) (x 0)) ∂P := by + dsimp only + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + let H := sourceCouplingHamiltonian n k f p d h u + let C := sourceCouplingCovariance n k p d u j + let D := perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j*((k:ℝ)/(k+1:ℕ))^(d j) + have he := sourceCoupling_annealed_ibp n k 1 f p d h hh0 hh u j 0 z t + (G := fun _ => 1) measurable_const (by norm_num : (0:ℝ) ≤ 1) (fun _ => by norm_num) hYi + dsimp only at he + simp only [mul_one,one_mul,Fin.sum_univ_one,Nat.cast_one,Fin.succ_zero_eq_one] at he + have hAe := sourceCoupling_exp_integrable_ae n k f p d h hh0 hh u j z t + have hleft : (fun a => gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) 1 + (fun x => sourceCouplingEnergy n k p d h j a (x 0))) =ᵐ[P] + (fun a => tiltMean (sourceSpinLeafKernel n k a.1) (H a) (sourceCouplingEnergy n k p d h j a) 1) := by + filter_upwards [hAe] with a ha + exact gibbsReplicaMean_coordinate_of_integrable _ (sourceCouplingHamiltonian_section n k f p d h u a) + (sourceCouplingEnergy_section n k p d h j a) ha.1 1 0 + have hdiag : ∀ x : NormalizedSpin (n+1)×IndexedLeaf k, C x x = D := by + intro x + dsimp [C,sourceCouplingCovariance,D] + rw [sourceJointMonomial_diagonal] + have hright : (fun a => gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) 1 + (fun x => C (x 0) (x 0))) =ᵐ[P] (fun _ => D) := by + filter_upwards [hAe] with a ha + simp only [hdiag] + exact gibbsReplicaMean_const_of_integrable _ (sourceCouplingHamiltonian_section n k f p d h u a) ha.1 1 D + have hI := kernel_replicaMean_bounded_integrable (sourceFullSpinLeafKernel n k) P + (H := H) (G := fun _ (x : Fin 2 → NormalizedSpin (n+1)×IndexedLeaf k) => C (x 1) (x 0)) + (sourceCouplingHamiltonian_measurable n k f p d h u) + ((sourceCouplingCovariance_measurable n k 2 p d u j 1 0).comp measurable_snd) + (abs_nonneg _) (fun _ x => sourceCouplingCovariance_bound n k p d u j _ _) + dsimp only [sourceFullSpinLeafKernel,Kernel.comap_apply] at hI + rw [integral_congr_ae hleft] at he + have hr : (∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) 1 + (fun x => C (x 0) (x 0))-gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) 2 + (fun x => C (x 1) (x 0)) ∂P) = + D-∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) 2 (fun x => C (x 1) (x 0)) ∂P := by + calc + _ = ∫ a, D-gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) 2 (fun x => C (x 1) (x 0)) ∂P := by + apply integral_congr_ae + filter_upwards [hright] with a ha + rw [ha] + _ = _ := by rw [integral_sub (integrable_const _) hI]; simp + exact he.trans hr + +lemma source_contact_energy_concentration (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 c*(r-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j r) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) 0) + (hp : c*(0-a)^2-(∫ b, sourceKernelPressure n k f p d u h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) ≤ c*(s-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j s) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (hm : c*(0-a)^2-(∫ b, sourceKernelPressure n k f p d u h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) ≤ c*(-s-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j (-s)) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) : + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + let H₀ := sourceCouplingHamiltonian n k f p d h u + let Y := sourceCouplingEnergy n k p d h j + let EY := ∫ b, tiltMean (sourceSpinLeafKernel n k b.1) (H₀ b) (Y b) 1 ∂P + Integrable (fun b => tiltMean (sourceSpinLeafKernel n k b.1) (H₀ b) (fun x => |Y b x|) 1) P ∧ + Integrable (fun b => tiltMean (sourceSpinLeafKernel n k b.1) (H₀ b) (fun x => |Y b x-EY|) 1) P ∧ + (∫ b, tiltMean (sourceSpinLeafKernel n k b.1) (H₀ b) (fun x => |Y b x-EY|) 1 ∂P) ≤ + Real.sqrt (2*c)/Real.sqrt (1/(n+1:ℕ))+ + (c*s+4*Real.sqrt (enrichedVarianceConstant k z f H T/(n+1:ℕ))/s)/(1/(n+1:ℕ)) := by + have hc := source_contact_thermal_disorder n k f p d h hh0 hh u j z hz hz0 hz1 t + hH hhH ht hs hu hup hum hmin hp hm + dsimp only at hc ⊢ + have hmean : Integrable (fun b => (1/(n+1:ℕ))*tiltMean (sourceSpinLeafKernel n k b.1) + (sourceCouplingHamiltonian n k f p d h u b) (sourceCouplingEnergy n k p d h j b) 1) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) := by + have hm := hc.2.1 + change Integrable (fun b => (1/(n+1:ℕ))*tiltMean (sourceSpinLeafKernel n k b.1) + (fun x => sourceCouplingHamiltonian n k f p d h u b x+0*sourceCouplingEnergy n k p d h j b x) + (sourceCouplingEnergy n k p d h j b) 1) _ at hm + simpa only [zero_mul,add_zero] using hm + have htherm := hc.1.integrable (by norm_num : (1:ENNReal) ≤ 2) + change Integrable (fun b => Real.sqrt (1/(n+1:ℕ))*tiltMean (sourceSpinLeafKernel n k b.1) + (fun x => sourceCouplingHamiltonian n k f p d h u b x+0*sourceCouplingEnergy n k p d h j b x) + (fun x => |sourceCouplingEnergy n k p d h j b x-tiltMean (sourceSpinLeafKernel n k b.1) + (fun x => sourceCouplingHamiltonian n k f p d h u b x+0*sourceCouplingEnergy n k p d h j b x) + (sourceCouplingEnergy n k p d h j b) 1|) 1) _ at htherm + simp only [zero_mul,add_zero] at htherm + have hC := hc.2.2.1 + simp only [sourceCouplingThermal,zero_mul,add_zero] at hC + have hD := hc.2.2.2 + simp only [sourceCouplingMean,zero_mul,add_zero] at hD + have hr := kernel_scaled_energy_concentration (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian_measurable n k f p d h u) (sourceCouplingEnergy_measurable n k p d h j) + (sourceCoupling_all_exp_ae n k f p d h hh0 hh u j z t) + (show 0<(1/(n+1:ℕ):ℝ) by positivity) hmean htherm hC hD + exact hr + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/EnrichedMoments.lean b/lean/OAI/Probability/Perceptron/Variational/EnrichedMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..04f0cc017779900a3b656158c17ac6ec0ee00541 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/EnrichedMoments.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedDiagonalField + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +def enrichedDisorderLaw (n k : ℕ) (p : Fin (n+1) → ℕ) (z : Fin k → ℝ) : + Measure (EnrichedMark (n+1) (n+1) p × DecoratedCascade (EnrichedMark (n+1) (n+1) p) k) := + (stdGaussian (EnrichedMark (n+1) (n+1) p)).prod + (decoratedCascadeLaw (gaussianMarkLaw : ProbabilityMeasure (EnrichedMark (n+1) (n+1) p)) k z) + +instance (n k : ℕ) (p : Fin (n+1) → ℕ) (z : Fin k → ℝ) : + IsProbabilityMeasure (enrichedDisorderLaw n k p z) := by + unfold enrichedDisorderLaw + infer_instance + +lemma enrichedCascadeLog_joint_mean (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) + (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 enrichedCascadeLog n M k f g p d u h (a,η)) 2 + (decoratedCascadeLaw ν k z : Measure _) ∧ + (∫ η, (enrichedCascadeLog n M k f g p d u h (a,η)-G)^2 + ∂decoratedCascadeLaw ν k z) ≤ cascadeLogFluctuationConstant k z := by + let ν : ProbabilityMeasure (EnrichedMark (n+1) (n+1) p) := gaussianMarkLaw + let : IsGaussian (ν:Measure (EnrichedMark (n+1) (n+1) p)) := (inferInstance : IsGaussian (stdGaussian (EnrichedMark (n+1) (n+1) p))) + have hf := enrichedTerminal_lipschitz n M f g p u (h (Fin.last k)) + have hr := gaussianLinearRecursion_realization ν (enrichedIncrementMap p d h) hf k z hz0 + have H := finiteCascade_terminal_log_second_moment_bound ν + (gaussianLinearMarkStep (enrichedIncrementMap p d h)) + (gaussianLinearMarkStep_measurable _) k z hz hz0 hz1 + (hf.continuous.measurable.comp (measurable_pi_apply 0)) hr.2 + (fun _ => enrichedRootMap p d h a) + simp only [Function.comp_def] at H + rw [hr.1] at H + exact H + +lemma normalizedPatternEnergy_source (α β : ℝ) (φ : ℝ →ᵇ ℝ) (n : ℕ) + (g : Patterns α (n+1)) (x : NormalizedSpin (n+1)) : + normalizedPatternEnergy (n+1) (patternCount α (n+1)) (β • φ) g x= + β*hamiltonian α φ (n+1) g (Real.sqrt (n+1:ℕ) • x.val) := by + have hn : Real.sqrt ((n+1:ℕ):ℝ) ≠ 0 := (Real.sqrt_pos.mpr (by positivity)).ne' + have he (a : Fin (patternCount α (n+1))) : + patternField g a (Real.sqrt (n+1:ℕ) • x.val) = ∑ i, g a i*x.val i := by + unfold patternField + simp only [PiLp.smul_apply,smul_eq_mul] + have hs : (∑ i, g a i*(Real.sqrt (n+1:ℕ)*x.val i)) = + (∑ i, g a i*x.val i)*Real.sqrt (n+1:ℕ) := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro i _ + ring + rw [hs,mul_div_cancel_right₀ _ hn] + simp only [normalizedPatternEnergy,BoundedContinuousFunction.coe_smul,smul_eq_mul, + hamiltonian,he,Finset.mul_sum] + +variable {E : Type} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] + +lemma gaussianLinearEntropic_C1 {f : E → ℝ} {D : E → StrongDual ℝ E} {L : ℝ≥0} + (hf : LipschitzWith L f) (hd : ∀ x, HasFDerivAt f (D x) x) (hD : Continuous D) + {b : ℝ} (hb : 0 ∫ y, Real.exp (b*f (x+A y)) ∂μ + let ZD := fun x => ∫ y, Real.exp (b*f (x+A y)) • (b • D (x+A y)) ∂μ + have hZpos (x : E) : 0 (Real.exp_pos _).le) + (gaussian_integrable_exp_linear_shift μ hf A b x) |>.mpr + simp [Function.support,Real.exp_ne_zero] + have hdom (x₀ x y : E) (hx : x ∈ Metric.ball x₀ 1) : + ‖Real.exp (b*f (x+A y)) • (b • D (x+A y))‖ ≤ + (Real.exp (b*L)*(b*L))*Real.exp (b*f (x₀+A y)) := by + have hh := hf.dist_le_mul (x+A y) (x₀+A y) + rw [dist_add_right,Real.dist_eq] at hh + have hx' : dist x x₀ ≤ 1 := (Metric.mem_ball.mp hx).le + have hff : f (x+A y)-f (x₀+A y) ≤ L := + (le_abs_self _).trans (hh.trans (by simpa using mul_le_mul_of_nonneg_left hx' L.coe_nonneg)) + have hExp : Real.exp (b*f (x+A y)) ≤ Real.exp (b*L)*Real.exp (b*f (x₀+A y)) := by + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + nlinarith + simp only [norm_smul,Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),abs_of_pos hb] + calc + _ ≤ (Real.exp (b*L)*Real.exp (b*f (x₀+A y)))*(b*L) := + mul_le_mul hExp (mul_le_mul_of_nonneg_left (hDC _) hb.le) (by positivity) (by positivity) + _ = _ := by ring + have hZ (x : E) : HasFDerivAt Z (ZD x) x := by + apply hasFDerivAt_integral_of_dominated_of_fderiv_le + (F' := fun x y => Real.exp (b*f (x+A y)) • (b • D (x+A y))) + (bound := fun y => (Real.exp (b*L)*(b*L))*Real.exp (b*f (x+A y))) + (Metric.ball_mem_nhds x zero_lt_one) + · exact Eventually.of_forall fun x => by fun_prop + · exact gaussian_integrable_exp_linear_shift μ hf A b x + · fun_prop + · exact ae_of_all _ fun y x' hx' => hdom x x' y hx' + · exact (gaussian_integrable_exp_linear_shift μ hf A b x).const_mul _ + · exact ae_of_all _ fun y x' _ => by + have hh := (hd (x'+A y)).comp x' ((hasFDerivAt_id x').add_const (A y)) + simpa using (hh.const_mul b).exp + have hZD : Continuous ZD := by + apply continuous_iff_continuousAt.mpr + intro x + apply continuousAt_of_dominated + (bound := fun y => (Real.exp (b*L)*(b*L))*Real.exp (b*f (x+A y))) + · exact Eventually.of_forall fun x => by fun_prop + · filter_upwards [Metric.ball_mem_nhds x zero_lt_one] with x' hx' + exact ae_of_all _ fun y => hdom x x' y hx' + · exact (gaussian_integrable_exp_linear_shift μ hf A b x).const_mul _ + · exact ae_of_all _ fun y => by fun_prop + let D' := fun x => b⁻¹ • ((Z x)⁻¹ • ZD x) + have he : gaussianLinearEntropic μ b A f = fun x => Real.log (Z x)/b := by + funext x + exact entropicMean_eq_div μ (fun s => gaussian_integrable_exp_linear_shift μ hf A s x) hb.ne' + have hd' (x : E) : HasFDerivAt (gaussianLinearEntropic μ b A f) (D' x) x := by + rw [he] + have hh := ((hZ x).log (hZpos x).ne').const_mul b⁻¹ + simpa only [D',div_eq_mul_inv,mul_comm] using hh + refine ⟨D',?_,hd',?_⟩ + · have hcZ : Continuous Z := continuous_iff_continuousAt.mpr (fun x => (hZ x).continuousAt) + change Continuous (fun x => b⁻¹ • ((Z x)⁻¹ • ZD x)) + exact (continuous_const : Continuous (fun _ : E => (b⁻¹ : ℝ))).smul + ((hcZ.inv₀ (fun x => (hZpos x).ne')).smul hZD) + · intro x + rw [← (hd' x).fderiv] + exact norm_fderiv_le_of_lipschitz ℝ (gaussianLinearEntropic_lipschitz μ hf hb.le A) + +lemma gaussianLinearBackward_C1 {f : E → ℝ} {D : E → StrongDual ℝ E} {L : ℝ≥0} + (hf : LipschitzWith L f) (hd : ∀ x, HasFDerivAt f (D x) x) (hD : Continuous D) + (l : List (ℝ×(E →L[ℝ] E))) (hl : ∀ c ∈ l, 0 + exact ⟨D,hD,hd,fun x => by + rw [← (hd x).fderiv] + exact norm_fderiv_le_of_lipschitz ℝ hf⟩ + | cons c l ih => + have hl' : ∀ d ∈ l, 0 hl d (List.mem_cons_of_mem c hd) + obtain ⟨D',hD',hd',_⟩ := ih hl' + exact gaussianLinearEntropic_C1 μ + (gaussianLinearBackward_lipschitz μ hf l (fun d hd => (hl' d hd).le)) + hd' hD' (hl c List.mem_cons_self) c.2 + +lemma gaussianLinearBackward_root_variance {f : E → ℝ} {D : E → StrongDual ℝ E} + {L : ℝ≥0} (hf : LipschitzWith L f) (hd : ∀ x, HasFDerivAt f (D x) x) + (hD : Continuous D) (l : List (ℝ×(E →L[ℝ] E))) (hl : ∀ c ∈ l, 0 gaussianLinearBackward μ l f (R x)) (stdGaussian E) ≤ + (Real.pi^2/8)*((L:ℝ)*‖R‖)^2 := by + obtain ⟨D',hD',hd',hb⟩ := gaussianLinearBackward_C1 μ hf hd hD l hl + apply stdGaussian_variance_le_of_fderiv_bound + (D := fun x => (D' (R x)).comp R) + (fun x => (hd' (R x)).comp x R.hasFDerivAt) + · exact Continuous.clm_comp (hD'.comp R.continuous) continuous_const + · positivity + · intro x + exact (ContinuousLinearMap.opNorm_comp_le _ _).trans + (mul_le_mul_of_nonneg_right (hb _) (norm_nonneg R)) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/EnrichedUniformBounds.lean b/lean/OAI/Probability/Perceptron/Variational/EnrichedUniformBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..cf8986de1dcbaf8c7cdae64e47325e51f75273f2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/EnrichedUniformBounds.lean @@ -0,0 +1,209 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedDiagonalField + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +lemma diagonalMark_norm_le {I : Type} [Fintype I] (c : I → ℝ) {C : ℝ} + (hC : 0 ≤ C) (hc : ∀ i, |c i| ≤ C) : ‖diagonalMark c‖ ≤ C := by + apply ContinuousLinearMap.opNorm_le_bound _ hC + intro x + have hs : ‖diagonalMark c x‖^2 ≤ (C*‖x‖)^2 := by + rw [mul_pow,EuclideanSpace.norm_sq_eq,EuclideanSpace.norm_sq_eq,Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + simp only [Real.norm_eq_abs,sq_abs,diagonalMark_apply,mul_pow] + exact mul_le_mul_of_nonneg_right (by + simpa only [sq_abs] using pow_le_pow_left₀ (abs_nonneg (c i)) (hc i) 2) (sq_nonneg (x i)) + nlinarith [norm_nonneg (diagonalMark c x),mul_nonneg hC (norm_nonneg x)] + +lemma enrichedRootMap_norm_le {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) + {H : ℝ} (hH : 0 ≤ H) (hh : h 0 ≤ H) : + ‖enrichedRootMap p d h‖ ≤ Real.sqrt (2*H+1) := by + apply diagonalMark_norm_le _ (Real.sqrt_nonneg _) + intro i + rw [abs_of_nonneg (Real.sqrt_nonneg _)] + apply Real.sqrt_le_sqrt + cases i with + | inl i => dsimp [enrichedCoordinateLevel]; linarith + | inr i => + simp only [enrichedCoordinateLevel,Fin.val_zero,Nat.cast_zero,zero_div] + by_cases hd : d i.1=0 + · rw [hd,pow_zero]; linarith + · rw [zero_pow hd]; positivity + +lemma perturbationScale_le_one (N : ℕ) (hN : 1 ≤ N) : perturbationScale N ≤ 1 := + Real.rpow_le_one_of_one_le_of_nonpos (by exact_mod_cast hN) (by norm_num) + +lemma perturbationWeight_eq (j : ℕ) : (2:ℝ)^(-((j+1:ℕ):ℤ))=(1/2:ℝ)^(j+1) := by + simp only [zpow_neg,zpow_natCast,one_div,inv_pow] + +lemma half_power_sum_le_one (N : ℕ) : (∑ j : Fin N, (1/2:ℝ)^(j.val+1)) ≤ 1 := by + rw [Fin.sum_univ_eq_sum_range (fun j => (1/2:ℝ)^(j+1)) N] + simp_rw [pow_succ] + rw [← Finset.sum_mul] + nlinarith [sum_geometric_two_le N] + +lemma perturbationAmplitude_square_le (N : ℕ) (hN : 1 ≤ N) (u : Fin N → ℝ) + (hu : ∀ j, u j ∈ Icc 1 2) (j : Fin N) : + perturbationAmplitude N u j^2 ≤ 4*(N:ℝ)*(1/2:ℝ)^(j.val+1) := by + let w : ℝ := (1/2:ℝ)^(j.val+1) + have hw0 : 0 ≤ w := pow_nonneg (by norm_num) _ + have hw1 : w ≤ 1 := pow_le_one₀ (by norm_num) (by norm_num) + have he0 : 0 ≤ perturbationScale N := Real.rpow_nonneg (Nat.cast_nonneg N) _ + have he1 := perturbationScale_le_one N hN + have he2 : perturbationScale N^2 ≤ 1 := by nlinarith + have hu2 : (u j)^2 ≤ 4 := by have h1 := (hu j).1; have h2 := (hu j).2; nlinarith + have hw2 : w^2 ≤ w := by nlinarith + unfold perturbationAmplitude + rw [perturbationWeight_eq] + change (Real.sqrt (N:ℝ)*perturbationScale N*w*u j)^2 ≤ _ + simp only [mul_pow,Real.sq_sqrt (Nat.cast_nonneg N)] + calc + _ ≤ (N:ℝ)*1*w^2*4 := by + apply mul_le_mul _ hu2 (sq_nonneg _) (by positivity) + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left he2 (Nat.cast_nonneg N)) (sq_nonneg w) + _ ≤ 4*(N:ℝ)*w := by nlinarith [mul_le_mul_of_nonneg_left hw2 (show 0 ≤ (N:ℝ) by positivity)] + +lemma enrichedFeatureBound_sq_le (N : ℕ) (hN : 1 ≤ N) (u : Fin N → ℝ) + (hu : ∀ j, u j ∈ Icc 1 2) : (enrichedFeatureBound N u:ℝ)^2 ≤ 5*(N:ℝ) := by + change (Real.sqrt ((N:ℝ)+∑ j, perturbationAmplitude N u j^2))^2 ≤ _ + rw [Real.sq_sqrt (by positivity)] + have hs : (∑ j : Fin N, perturbationAmplitude N u j^2) ≤ 4*(N:ℝ) := by + calc + _ ≤ ∑ j : Fin N, 4*(N:ℝ)*(1/2:ℝ)^(j.val+1) := + Finset.sum_le_sum fun j _ => perturbationAmplitude_square_le N hN u hu j + _ = 4*(N:ℝ)*(∑ j : Fin N, (1/2:ℝ)^(j.val+1)) := (Finset.mul_sum _ _ _).symm + _ ≤ 4*(N:ℝ)*1 := mul_le_mul_of_nonneg_left (half_power_sum_le_one N) (by positivity) + _ = _ := mul_one _ + linarith + +lemma finite_profile_telescope {k : ℕ} (q : Fin (k+1) → ℝ) : + q 0 + ∑ i : Fin k, (q i.succ-q i.castSucc) = q (Fin.last k) := by + rw [Finset.sum_sub_distrib] + have h1 := Fin.sum_univ_succ q + have h2 := Fin.sum_univ_castSucc q + linarith + +def profileGaussianRoot {I : Type} {k : ℕ} (q : Fin (k+1) → I → ℝ) (i : I) : ℝ := + Real.sqrt (q 0 i) + +def profileGaussianStep {I : Type} {k : ℕ} (q : Fin (k+1) → I → ℝ) + (j : ℕ) (i : I) : ℝ := + if hj : j Real.sqrt (q 0 i)) + (fun l i => Real.sqrt (q l.succ i-q l.castSucc i)) := by + funext l i + induction l using Fin.cases with + | zero => rfl + | succ l => + simp only [hierarchyRowCoefficients,Fin.cases_succ,profileGaussianStep, + dite_eq_left (show k-1-l.val congr 1 <;> apply Fin.ext <;> simp only [Fin.val_succ,Fin.val_castSucc] <;> omega + +lemma profileGaussian_coefficient_squares {I : Type} {k : ℕ} (q : Fin (k+1) → I → ℝ) + (h0 : ∀ i, 0 ≤ q 0 i) (hq : ∀ i, Monotone (fun l => q l i)) (i : I) : + (∑ l : Fin (k+1), hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q) l i^2) = + q (Fin.last k) i := by + rw [profileGaussian_coefficient,Fin.sum_univ_succ] + simp only [Fin.cases_zero,Fin.cases_succ,Real.sq_sqrt (h0 i)] + have he (j : Fin k) : (Real.sqrt (q j.succ i-q j.castSucc i))^2 = q j.succ i-q j.castSucc i := + Real.sq_sqrt (sub_nonneg.mpr (hq i (by simp [Fin.le_iff_val_le_val]))) + simp_rw [he] + exact finite_profile_telescope (fun l => q l i) + +lemma enrichedCoordinateLevel_nonneg {N k : ℕ} (p d : Fin N → ℕ) + {h : Fin (k+1) → ℝ} (hh : ∀ l, 0 ≤ h l) (l : Fin (k+1)) (i : EnrichedIndex N N p) : + 0 ≤ enrichedCoordinateLevel p d h l i := by + cases i with + | inl i => exact mul_nonneg (by norm_num) (hh l) + | inr i => exact pow_nonneg (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) _ + +lemma enrichedCoordinateLevel_monotone {N k : ℕ} (p d : Fin N → ℕ) + {h : Fin (k+1) → ℝ} (hh : Monotone h) (i : EnrichedIndex N N p) : + Monotone (fun l => enrichedCoordinateLevel p d h l i) := by + intro a b hab + cases i with + | inl i => exact mul_le_mul_of_nonneg_left (hh hab) (by norm_num) + | inr i => + apply pow_le_pow_left₀ (div_nonneg (Nat.cast_nonneg _) (Nat.cast_nonneg _)) + exact div_le_div_of_nonneg_right (by exact_mod_cast hab) (Nat.cast_nonneg _) + +lemma enrichedCoordinateLevel_le {N k : ℕ} (p d : Fin N → ℕ) + {h : Fin (k+1) → ℝ} {H : ℝ} (hH : 0 ≤ H) (hh : ∀ l, h l ≤ H) + (l : Fin (k+1)) (i : EnrichedIndex N N p) : + enrichedCoordinateLevel p d h l i ≤ 2*H+1 := by + cases i with + | inl i => dsimp [enrichedCoordinateLevel]; linarith [hh l] + | inr i => + have ht : ((l.val:ℝ)/(k+1:ℕ)) ≤ 1 := by + apply (div_le_one (by positivity)).mpr + exact_mod_cast l.isLt.le + have ht0 : 0 ≤ ((l.val:ℝ)/(k+1:ℕ)) := by positivity + exact (pow_le_one₀ ht0 ht).trans (by linarith) + +lemma enrichedIncrementMap_profile {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) (j : ℕ) : + enrichedIncrementMap p d h j = diagonalMark (profileGaussianStep (enrichedCoordinateLevel p d h) j) := by + by_cases hj : j t^2) (sourceEnrichedFeature_norm N p u y) + simpa only [EuclideanSpace.norm_sq_eq,Real.norm_eq_abs,sq_abs] using he.le + +lemma sourceGaussianRow_identity {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) + (u : Fin N → ℝ) (g : ℕ → ℝ) (x : NormalizedSpin N × IndexedLeaf k) : + countableGaussianField (sourceGaussianRow p d h u) + (indexedGaussianRowLength (I := EnrichedIndex N N p) k) g x = + inner ℝ (sourceEnrichedFeature N p u x.1) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h (indexedGaussianDisorder k (EnrichedIndex N N p) g).1), + (indexedGaussianDisorder k (EnrichedIndex N N p) g).2) x.2 0) := by + unfold sourceGaussianRow + rw [indexedGaussianRow_diagonal_identity] + have he : enrichedIncrementMap p d h = fun j => diagonalMark + (profileGaussianStep (enrichedCoordinateLevel p d h) j) := + funext (enrichedIncrementMap_profile p d h) + rw [he] + rfl + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/EnrichedVarianceBound.lean b/lean/OAI/Probability/Perceptron/Variational/EnrichedVarianceBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..82a77316c1c4c3b245d4bc8b64d6b8273ddb9f8e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/EnrichedVarianceBound.lean @@ -0,0 +1,176 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.EnrichedUniformBounds +import OAI.Probability.Perceptron.Cascade.EnrichedPoissonVariance + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +def enrichedRandomPressure (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) := + fun a => (1/(n+1:ℕ))*enrichedPoissonLog n k f p d u h a + +def enrichedPoissonDisorderLaw (n k : ℕ) (p : Fin (n+1) → ℕ) (z : Fin k → ℝ) (t : ℝ≥0) := + (poissonMeasure ((n+1:ℕ)*t)).prod (enrichedRowsDisorderLaw n k p z) + +instance (n k : ℕ) (p : Fin (n+1) → ℕ) (z : Fin k → ℝ) (t : ℝ≥0) : + IsProbabilityMeasure (enrichedPoissonDisorderLaw n k p z t) := by + unfold enrichedPoissonDisorderLaw + infer_instance + +def enrichedVarianceConstant (k : ℕ) (z : Fin k → ℝ) (f : ℝ →ᵇ ℝ) (H T : ℝ) : ℝ := + max (cascadeLogFluctuationConstant k z) 0+(Real.pi^2/8)*5*(2*H+1)+ + 5*T*‖f‖^2+‖f‖^2 + +lemma enrichedRandomPressure_variance (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 (1/N)*enrichedPoissonLog n k f p d u h a) + (enrichedPoissonDisorderLaw n k p z t) ≤ enrichedVarianceConstant k z f H T/N + rw [variance_const_mul] + calc + _ ≤ (1/N)^2*(enrichedVarianceConstant k z f H T*N) := + mul_le_mul_of_nonneg_left hvar (sq_nonneg (1/N)) + _ = _ := by field_simp + +lemma enrichedRandomPressure_centered_square (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 + (a.2.1,(a.1,a.2.2))) (B.prod (R.prod M)) (R.prod (B.prod M)) := + ⟨by fun_prop,prod_rotate_front B R M⟩ + have hc : MeasurePreserving (indexedCascadeRealize (S := E) k) (B.prod M) + (decoratedCascadeLaw (gaussianMarkLaw (E := E)) k z) := + ⟨indexedCascadeRealize_measurable k,indexedCascadeRealize_law _ k z⟩ + exact (((MeasurePreserving.id R).prod hc).comp hr).comp ((MeasurePreserving.id B).prod hg) + +abbrev SourceIndexedDisorder (n k : ℕ) := + ℕ × ((ℕ → Fin (n+1) → ℝ) × (IndexedCascadeBase k × (ℕ → ℝ))) + +def sourceIndexedDisorderLaw (n k : ℕ) (z : Fin k → ℝ) (t : ℝ≥0) : + Measure (SourceIndexedDisorder n k) := + (poissonMeasure ((n+1:ℕ)*t)).prod ((infinitePatternRowsLaw (n+1)).prod + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw)) + +instance (n k : ℕ) (z : Fin k → ℝ) (t : ℝ≥0) : + IsProbabilityMeasure (sourceIndexedDisorderLaw n k z t) := by + unfold sourceIndexedDisorderLaw + infer_instance + +def sourceDisorderRealization (n k : ℕ) (p : Fin (n+1) → ℕ) : + SourceIndexedDisorder n k → ℕ × ((ℕ → Fin (n+1) → ℝ) × + (EnrichedMark (n+1) (n+1) p × DecoratedCascade (EnrichedMark (n+1) (n+1) p) k)) := + Prod.map id (Prod.map id (sourceCascadeRealization n k p)) + +lemma sourceDisorderRealization_preserving (n k : ℕ) (p : Fin (n+1) → ℕ) + (z : Fin k → ℝ) (t : ℝ≥0) : + MeasurePreserving (sourceDisorderRealization n k p) (sourceIndexedDisorderLaw n k z t) + (enrichedPoissonDisorderLaw n k p z t) := + (MeasurePreserving.id _).prod ((MeasurePreserving.id _).prod + (sourceCascadeRealization_preserving n k p z)) + +def sourceIndexedPressure (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) : SourceIndexedDisorder n k → ℝ := + enrichedRandomPressure n k f p d u h ∘ sourceDisorderRealization n k p + +lemma sourceIndexedPressure_memLp (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (u : Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) (z : Fin k → ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 Real.exp (t*X ω)) μ) : + Integrable X μ := + (memLp_of_mem_interior_integrableExpSet (mem_interior_integrableExpSet_of_all μ hX 0) 1).integrable (by simp) + +omit [IsProbabilityMeasure μ] in +lemma all_exp_add_const (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t*X ω)) μ) (c : ℝ) : + ∀ t : ℝ, Integrable (fun ω => Real.exp (t*(X ω+c))) μ := by + intro t + simpa only [mul_add,Real.exp_add] using (hX t).mul_const (Real.exp (t*c)) + +lemma entropicMean_add_const (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t*X ω)) μ) + (p c : ℝ) : entropicMean μ p (fun ω => X ω+c)=entropicMean μ p X+c := by + by_cases hp : p=0 + · subst p + rw [entropicMean_zero μ (all_exp_add_const μ hX c),entropicMean_zero μ hX, + integral_add (integrable_of_all_exp μ hX) (integrable_const c),integral_const] + simp + · rw [entropicMean_eq_div μ (all_exp_add_const μ hX c) hp,entropicMean_eq_div μ hX hp] + simp only [cgf,mgf_add_const] + rw [Real.log_mul (ne_of_gt (mgf_pos (hX p))) (ne_of_gt (Real.exp_pos _)),Real.log_exp] + field_simp + +lemma entropicMean_mono_variable + (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t*X ω)) μ) + (hY : ∀ t : ℝ, Integrable (fun ω => Real.exp (t*Y ω)) μ) + (hXY : X ≤ᵐ[μ] Y) {p : ℝ} (hp : 0 ≤ p) : + entropicMean μ p X ≤ entropicMean μ p Y := by + rcases hp.eq_or_lt with hp|hp + · subst p + rw [entropicMean_zero μ hX,entropicMean_zero μ hY] + exact integral_mono_ae (integrable_of_all_exp μ hX) (integrable_of_all_exp μ hY) hXY + · rw [entropicMean_eq_div μ hX (ne_of_gt hp),entropicMean_eq_div μ hY (ne_of_gt hp)] + apply div_le_div_of_nonneg_right _ hp.le + exact Real.log_le_log (mgf_pos (hX p)) (mgf_mono_of_nonneg hXY hp.le (hY p)) + +lemma entropicMean_bounded_difference + (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t*X ω)) μ) + (hY : ∀ t : ℝ, Integrable (fun ω => Real.exp (t*Y ω)) μ) + {C p : ℝ} (hp : 0 ≤ p) (hXY : ∀ᵐ ω ∂μ, |X ω-Y ω| ≤ C) : + |entropicMean μ p X-entropicMean μ p Y| ≤ C := by + have h1 : X ≤ᵐ[μ] (fun ω => Y ω+C) := by + filter_upwards [hXY] with ω hω + have := (abs_le.mp hω).2 + linarith + have h2 : Y ≤ᵐ[μ] (fun ω => X ω+C) := by + filter_upwards [hXY] with ω hω + have := (abs_le.mp hω).1 + linarith + have H1 := entropicMean_mono_variable μ hX (all_exp_add_const μ hY C) h1 hp + have H2 := entropicMean_mono_variable μ hY (all_exp_add_const μ hX C) h2 hp + rw [entropicMean_add_const μ hY] at H1 + rw [entropicMean_add_const μ hX] at H2 + exact abs_le.mpr ⟨by linarith,by linarith⟩ + +end + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] + +def gaussianEntropic (p σ : ℝ) (f : E → ℝ) (x : E) : ℝ := + entropicMean μ p (fun y => f (x+σ • y)) + +lemma gaussianEntropic_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) {p σ : ℝ} (hp : 0 ≤ p) : + LipschitzWith L (gaussianEntropic μ p σ f) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,gaussianEntropic] + apply entropicMean_bounded_difference μ + (fun a => gaussian_integrable_exp_lipschitz μ hf a σ x) + (fun a => gaussian_integrable_exp_lipschitz μ hf a σ y) hp + exact ae_of_all _ fun z => by + simpa only [Real.dist_eq,dist_add_right] using hf.dist_le_mul (x+σ • z) (y+σ • z) + +lemma gaussianEntropic_mono_parameter {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (σ : ℝ) (x : E) : + Monotone (fun p => gaussianEntropic μ p σ f x) := + entropicMean_monotone μ (fun a => gaussian_integrable_exp_lipschitz μ hf a σ x) + +lemma gaussianEntropic_zero {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (σ : ℝ) (x : E) : + gaussianEntropic μ 0 σ f x=∫ y, f (x+σ • y) ∂μ := + entropicMean_zero μ (fun a => gaussian_integrable_exp_lipschitz μ hf a σ x) + +lemma gaussianEntropic_pos {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) {p : ℝ} (hp : p ≠ 0) (σ : ℝ) (x : E) : + gaussianEntropic μ p σ f x=Real.log (∫ y, Real.exp (p*f (x+σ • y)) ∂μ)/p := + entropicMean_eq_div μ (fun a => gaussian_integrable_exp_lipschitz μ hf a σ x) hp + +lemma gaussianEntropic_mono {f g : E → ℝ} {L M : ℝ≥0} + (hf : LipschitzWith L f) (hg : LipschitzWith M g) {p : ℝ} (hp : 0 ≤ p) + (σ : ℝ) (hfg : ∀ x, f x ≤ g x) (x : E) : + gaussianEntropic μ p σ f x ≤ gaussianEntropic μ p σ g x := + entropicMean_mono_variable μ (fun a => gaussian_integrable_exp_lipschitz μ hf a σ x) + (fun a => gaussian_integrable_exp_lipschitz μ hg a σ x) + (ae_of_all _ fun noise => hfg (x+σ • noise)) hp + +lemma gaussianEntropic_add_const {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (p σ c : ℝ) (x : E) : + gaussianEntropic μ p σ (fun z => f z+c) x=gaussianEntropic μ p σ f x+c := + entropicMean_add_const μ (fun a => gaussian_integrable_exp_lipschitz μ hf a σ x) p c + +def gaussianEntropicParamConstant (L S : ℝ) : ℝ := + L^2*(∫ y : E, ‖y‖^2*Real.exp (L*S*‖y‖) ∂μ) / + mgf (fun y : E => ‖y‖) μ (-(L*S)) + +lemma gaussianEntropicParamConstant_nonneg (L S : ℝ) : + 0 ≤ gaussianEntropicParamConstant μ L S := by + apply div_nonneg + · exact mul_nonneg (sq_nonneg _) (integral_nonneg fun y => + mul_nonneg (sq_nonneg _) (Real.exp_pos _).le) + · exact (mgf_pos (gaussian_integrable_exp_norm μ (-(L*S)))).le + +lemma gaussianEntropic_parameter_bound {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) {p q σ S : ℝ} + (hp : p ∈ Icc (0:ℝ) 1) (hq : q ∈ Icc (0:ℝ) 1) + (hσ : 0 ≤ σ) (hσS : σ ≤ S) (x : E) : + |gaussianEntropic μ p σ f x-gaussianEntropic μ q σ f x| ≤ + gaussianEntropicParamConstant μ L S*σ^2*|p-q| := by + let X : E → ℝ := fun y => f (x+σ • y)-f x + have hX : ∀ t : ℝ, Integrable (fun y => Real.exp (t*X y)) μ := by + intro t + simpa [X,sub_eq_add_neg] using all_exp_add_const μ + (fun a => gaussian_integrable_exp_lipschitz μ hf a σ x) (-f x) t + have hnorm (y : E) : |X y| ≤ (L:ℝ)*σ*‖y‖ := by + have hh := hf.dist_le_mul (x+σ • y) x + simpa only [X,Real.dist_eq,dist_eq_norm,add_sub_cancel_left,norm_smul, + Real.norm_eq_abs,abs_of_nonneg hσ,mul_assoc] using hh + have hlin (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) (y : E) : + |t*X y| ≤ (L:ℝ)*S*‖y‖ := by + rw [abs_mul,abs_of_nonneg ht.1] + calc + t*|X y| ≤ |X y| := mul_le_of_le_one_left (abs_nonneg _) ht.2 + _ ≤ (L:ℝ)*σ*‖y‖ := hnorm y + _ ≤ (L:ℝ)*S*‖y‖ := by gcongr + let c := mgf (fun y : E => ‖y‖) μ (-((L:ℝ)*S)) + have hc : 0 < c := mgf_pos (gaussian_integrable_exp_norm μ (-((L:ℝ)*S))) + let I := ∫ y : E, ‖y‖^2*Real.exp ((L:ℝ)*S*‖y‖) ∂μ + have hI : 0 ≤ I := integral_nonneg fun y => mul_nonneg (sq_nonneg _) (Real.exp_pos _).le + have hbound (t : ℝ) (ht : t ∈ Icc (0:ℝ) 1) : + deriv (deriv (cgf X μ)) t ≤ gaussianEntropicParamConstant μ L S*σ^2 := by + have hl : c ≤ mgf X μ t := by + apply integral_mono (gaussian_integrable_exp_norm μ (-((L:ℝ)*S))) (hX t) + intro y + apply Real.exp_le_exp.mpr + have hh := (abs_le.mp (hlin t ht y)).1 + nlinarith + have hu : (∫ y, (X y)^2*Real.exp (t*X y) ∂μ) ≤ (L:ℝ)^2*σ^2*I := by + have hi := integrable_pow_mul_exp_of_mem_interior_integrableExpSet + (mem_interior_integrableExpSet_of_all μ hX t) 2 + calc + _ ≤ ∫ y : E, ((L:ℝ)^2*σ^2)*(‖y‖^2*Real.exp ((L:ℝ)*S*‖y‖)) ∂μ := by + apply integral_mono hi ((gaussian_integrable_norm_sq_exp μ ((L:ℝ)*S)).const_mul _) + intro y + have hs : (X y)^2 ≤ (L:ℝ)^2*σ^2*‖y‖^2 := by + have hn := hnorm y + have hz : 0 ≤ (L:ℝ)*σ*‖y‖ := by positivity + simpa only [sq_abs,mul_pow] using (sq_le_sq₀ (abs_nonneg (X y)) hz).mpr hn + have he : Real.exp (t*X y) ≤ Real.exp ((L:ℝ)*S*‖y‖) := + Real.exp_le_exp.mpr ((le_abs_self _).trans (hlin t ht y)) + have hh := mul_le_mul hs he (Real.exp_pos _).le (by positivity) + convert hh using 1; ring + _ = _ := by rw [integral_const_mul] + have hh := cgf_second_le_of_moments μ hX hc (by positivity) hl hu + convert hh using 1; dsimp [gaussianEntropicParamConstant,c,I]; ring + have H := entropicMean_param_bound μ hX + (mul_nonneg (gaussianEntropicParamConstant_nonneg μ L S) (sq_nonneg σ)) hbound hp hq + have he (a : ℝ) : entropicMean μ a X=gaussianEntropic μ a σ f x-f x := by + simpa [X,gaussianEntropic,sub_eq_add_neg] using entropicMean_add_const μ + (fun b => gaussian_integrable_exp_lipschitz μ hf b σ x) a (-f x) + rw [he p,he q] at H + convert H using 1; congr 1; ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/EntropicParameter.lean b/lean/OAI/Probability/Perceptron/Variational/EntropicParameter.lean new file mode 100644 index 0000000000000000000000000000000000000000..a9729cd97c90e91fcafeec6f9ce8fc580de5e26f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/EntropicParameter.lean @@ -0,0 +1,180 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal + +section + +variable {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] + {X : Ω → ℝ} + +omit [IsProbabilityMeasure μ] in +lemma mem_interior_integrableExpSet_of_all + (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) (t : ℝ) : + t ∈ interior (integrableExpSet X μ) := by + have he : integrableExpSet X μ=univ := Set.eq_univ_of_forall hX + simp [he] + +omit [IsProbabilityMeasure μ] in +lemma cgf_analytic_of_all + (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) (t : ℝ) : + AnalyticAt ℝ (cgf X μ) t := + analyticAt_cgf (mem_interior_integrableExpSet_of_all μ hX t) + +lemma cgf_second_nonneg + (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) (t : ℝ) : + 0 ≤ deriv (deriv (cgf X μ)) t := by + have hh := iteratedDeriv_two_cgf_eq_integral + (mem_interior_integrableExpSet_of_all μ hX t) + simp only [iteratedDeriv_succ,iteratedDeriv_zero] at hh + rw [hh] + exact div_nonneg (integral_nonneg fun ω => mul_nonneg (sq_nonneg _) (Real.exp_pos _).le) + (mgf_pos (hX t)).le + +lemma cgf_deriv_monotone + (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) : + Monotone (deriv (cgf X μ)) := + monotone_of_deriv_nonneg (fun t => (cgf_analytic_of_all μ hX t).deriv.differentiableAt) + (cgf_second_nonneg μ hX) + +def entropicMean (p : ℝ) (X : Ω → ℝ) : ℝ := + ∫ t : ℝ in (0:ℝ)..1, deriv (cgf X μ) (p*t) + +lemma entropicMean_eq_div (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) + {p : ℝ} (hp : p ≠ 0) : entropicMean μ p X=cgf X μ p/p := by + rw [entropicMean,intervalIntegral.integral_comp_mul_left _ hp] + simp only [mul_zero,mul_one] + have hc : Continuous (deriv (cgf X μ)) := continuous_iff_continuousAt.mpr + (fun t => (cgf_analytic_of_all μ hX t).deriv.differentiableAt.continuousAt) + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun t _ => (cgf_analytic_of_all μ hX t).differentiableAt.hasDerivAt) + (hc.intervalIntegrable _ _),cgf_zero,sub_zero,smul_eq_mul,div_eq_mul_inv,mul_comm] + +lemma entropicMean_zero (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) : + entropicMean μ 0 X=∫ ω, X ω ∂μ := by + simp [entropicMean,deriv_cgf_zero (mem_interior_integrableExpSet_of_all μ hX 0)] + +lemma entropicMean_monotone (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) : + Monotone (fun p => entropicMean μ p X) := by + have hc : Continuous (deriv (cgf X μ)) := continuous_iff_continuousAt.mpr + (fun t => (cgf_analytic_of_all μ hX t).deriv.differentiableAt.continuousAt) + intro p q hpq + apply intervalIntegral.integral_mono_on (by norm_num) + ((hc.comp ((continuous_const.mul continuous_id) : Continuous (fun t : ℝ => p*t))).intervalIntegrable 0 1) + ((hc.comp ((continuous_const.mul continuous_id) : Continuous (fun t : ℝ => q*t))).intervalIntegrable 0 1) + intro t ht + exact cgf_deriv_monotone μ hX (mul_le_mul_of_nonneg_right hpq ht.1) + +lemma entropicMean_param_bound + (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) + {K : ℝ} (hK : 0 ≤ K) + (hbound : ∀ t ∈ Icc (0:ℝ) 1, deriv (deriv (cgf X μ)) t ≤ K) + {p q : ℝ} (hp : p ∈ Icc (0:ℝ) 1) (hq : q ∈ Icc (0:ℝ) 1) : + |entropicMean μ p X-entropicMean μ q X| ≤ K*|p-q| := by + have hc : Continuous (deriv (cgf X μ)) := continuous_iff_continuousAt.mpr + (fun t => (cgf_analytic_of_all μ hX t).deriv.differentiableAt.continuousAt) + have hl : ∀ x ∈ Icc (0:ℝ) 1, ∀ y ∈ Icc (0:ℝ) 1, + |deriv (cgf X μ) x-deriv (cgf X μ) y| ≤ K*|x-y| := by + intro x hx y hy + exact Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (fun t _ => (cgf_analytic_of_all μ hX t).deriv.differentiableAt.hasDerivAt.hasDerivWithinAt) + (fun t ht => by rw [Real.norm_eq_abs,abs_of_nonneg (cgf_second_nonneg μ hX t)]; exact hbound t ht) + (convex_Icc (0:ℝ) 1) hy hx + have hip : IntervalIntegrable (fun t : ℝ => deriv (cgf X μ) (p*t)) volume 0 1 := by + exact (hc.comp ((continuous_const.mul continuous_id) : Continuous (fun t : ℝ => p*t))).intervalIntegrable 0 1 + have hiq : IntervalIntegrable (fun t : ℝ => deriv (cgf X μ) (q*t)) volume 0 1 := by + exact (hc.comp ((continuous_const.mul continuous_id) : Continuous (fun t : ℝ => q*t))).intervalIntegrable 0 1 + unfold entropicMean + rw [← intervalIntegral.integral_sub hip hiq] + have H := intervalIntegral.norm_integral_le_of_norm_le_const + (a := (0:ℝ)) (b := 1) (C := K*|p-q|) + (f := fun t => deriv (cgf X μ) (p*t)-deriv (cgf X μ) (q*t)) (by + intro t ht + have ht' : t ∈ Icc (0:ℝ) 1 := by simpa using (Set.Ioc_subset_Icc_self ht) + have hpt : p*t ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg hp.1 ht'.1, + (mul_le_mul hp.2 ht'.2 ht'.1 (by norm_num)).trans (by norm_num)⟩ + have hqt : q*t ∈ Icc (0:ℝ) 1 := ⟨mul_nonneg hq.1 ht'.1, + (mul_le_mul hq.2 ht'.2 ht'.1 (by norm_num)).trans (by norm_num)⟩ + have hh := hl _ hpt _ hqt + rw [← sub_mul,abs_mul,abs_of_nonneg ht'.1] at hh + apply hh.trans + have := mul_le_mul_of_nonneg_left ht'.2 (mul_nonneg hK (abs_nonneg (p-q))) + nlinarith) + simpa using H + +lemma cgf_second_le_of_moments + (hX : ∀ t : ℝ, Integrable (fun ω => Real.exp (t * X ω)) μ) + {t c K : ℝ} (hc : 0 < c) (hK : 0 ≤ K) (hl : c ≤ mgf X μ t) + (hu : (∫ ω, (X ω)^2*Real.exp (t*X ω) ∂μ) ≤ K) : + deriv (deriv (cgf X μ)) t ≤ K/c := by + have hh := iteratedDeriv_two_cgf (mem_interior_integrableExpSet_of_all μ hX t) + simp only [iteratedDeriv_succ,iteratedDeriv_zero] at hh + rw [hh] + calc + _ ≤ (∫ ω, (X ω)^2*Real.exp (t*X ω) ∂μ)/mgf X μ t := sub_le_self _ (sq_nonneg _) + _ ≤ K/mgf X μ t := div_le_div_of_nonneg_right hu (mgf_pos (hX t)).le + _ ≤ K/c := div_le_div_of_nonneg_left hK hc hl + +end + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] + +lemma gaussian_integrable_exp_norm (a : ℝ) : Integrable (fun y : E => Real.exp (a*‖y‖)) μ := by + obtain ⟨c,hc,hI⟩ := IsGaussian.exists_integrable_exp_sq μ + have hh (y : E) : a*‖y‖ ≤ c*‖y‖^2+a^2/(4*c) := by + have h := sq_nonneg (2*c*‖y‖-a) + have hd : a^2/(4*c)*(4*c)=a^2 := div_mul_cancel₀ _ (by positivity) + nlinarith + apply (hI.const_mul (Real.exp (a^2/(4*c)))).mono' (by fun_prop) + exact ae_of_all _ fun y => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),← Real.exp_add] + apply Real.exp_le_exp.mpr + linarith [hh y] + +lemma gaussian_integrable_norm_sq_exp (a : ℝ) : + Integrable (fun y : E => ‖y‖^2*Real.exp (a*‖y‖)) μ := by + have he : integrableExpSet (fun y : E => ‖y‖) μ=univ := + Set.eq_univ_of_forall (gaussian_integrable_exp_norm μ) + have ht : a ∈ interior (integrableExpSet (fun y : E => ‖y‖) μ) := by simp [he] + have h := integrable_pow_mul_exp_of_mem_interior_integrableExpSet ht 2 + simpa using h + +lemma gaussian_integrable_exp_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (a σ : ℝ) (x : E) : + Integrable (fun y : E => Real.exp (a*f (x+σ • y))) μ := by + have hbound (y : E) : a*f (x+σ • y) ≤ |a| *|f x|+(|a| *L*|σ|)*‖y‖ := by + have hl := hf.dist_le_mul (x+σ • y) x + simp only [dist_eq_norm,add_sub_cancel_left,norm_smul,Real.norm_eq_abs] at hl + have hn := abs_add_le (f (x+σ • y)-f x) (f x) + rw [sub_add_cancel] at hn + have hmul := mul_le_mul_of_nonneg_left (le_trans hn (add_le_add hl le_rfl)) (abs_nonneg a) + have hle := le_abs_self (a*f (x+σ • y)) + rw [abs_mul] at hle + nlinarith + have hfc := hf.continuous + apply ((gaussian_integrable_exp_norm μ (|a| *L*|σ|)).const_mul + (Real.exp (|a| *|f x|))).mono' (by fun_prop) + exact ae_of_all _ fun y => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _),← Real.exp_add] + exact Real.exp_le_exp.mpr (hbound y) + +lemma gaussian_integrable_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (σ : ℝ) (x : E) : + Integrable (fun y : E => f (x+σ • y)) μ := by + have he : integrableExpSet (fun y : E => f (x+σ • y)) μ=univ := + Set.eq_univ_of_forall (fun a => gaussian_integrable_exp_lipschitz μ hf a σ x) + have ht : (0:ℝ) ∈ interior (integrableExpSet (fun y : E => f (x+σ • y)) μ) := by simp [he] + exact (memLp_of_mem_interior_integrableExpSet ht (1:ℝ≥0)).integrable (by simp) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/Entropy.lean b/lean/OAI/Probability/Perceptron/Variational/Entropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..2cb832ef2b4bcf0467b605f7ea200d525d1f075f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/Entropy.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StepEntropy + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma reciprocal_supporting_inequality {x y : ℝ} (hx : 0 < x) (hy : 0 < y) : + (y-x)/y^2 ≤ x⁻¹-y⁻¹ := by + have he : x⁻¹-y⁻¹-(y-x)/y^2=(x-y)^2/(x*y^2) := by + field_simp [hx.ne',hy.ne'] + ring + have hp := div_nonneg (sq_nonneg (x-y)) (mul_pos hx (sq_pos_of_pos hy)).le + rw [← he] at hp + linarith + +lemma max_difference_support {p q t : ℝ} : + (if t ≤ q then p-q else 0) ≤ max p t-max q t := by + split_ifs with ht + · rw [max_eq_left ht] + exact sub_le_sub_right (le_max_left _ _) _ + · rw [max_eq_right (le_of_not_ge ht)] + exact sub_nonneg.mpr (le_max_right _ _) + +theorem entropy_weightedStep_support {I : Type*} [Fintype I] + (w : I → ℝ) (p q : I → Time) (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) + (B : ℝ) (hB0 : 0 ≤ B) (hB1 : B < 1) + (hp : ∀ i, (p i:ℝ) ≤ B) (hq : ∀ i, (q i:ℝ) ≤ B) : + (∑ i, w i*((p i:ℝ)-(q i:ℝ))*weightedStepA w (fun j => (q j:ℝ)) (q i))/2 ≤ + (entropy (weightedStepTrial w p hw hw1)).toReal- + (entropy (weightedStepTrial w q hw hw1)).toReal := by + classical + let P : I → ℝ := fun i => p i + let Q : I → ℝ := fun i => q i + let Dp := weightedStepTail w P + let Dq := weightedStepTail w Q + have hcP := weightedStepTail_inv_continuousOn w P hw hw1 hB1 hp + have hcQ := weightedStepTail_inv_continuousOn w Q hw hw1 hB1 hq + have hiP := hcP.intervalIntegrable_of_Icc (μ := volume) hB0 + have hiQ := hcQ.intervalIntegrable_of_Icc (μ := volume) hB0 + have hcQ2 : ContinuousOn (fun t => 1/(Dq t)^2) (Icc 0 B) := by + have hh := hcQ.pow 2 + change ContinuousOn (fun t => ((Dq t)⁻¹)^2) _ at hh + simpa only [one_div,inv_pow] using hh + have hiQ2 := hcQ2.intervalIntegrable_of_Icc (μ := volume) hB0 + let F : I → ℝ → ℝ := fun i => (Iic (Q i)).indicator (fun t => 1/(Dq t)^2) + have hFi (i : I) : IntervalIntegrable (F i) volume 0 B := + ⟨hiQ2.1.indicator measurableSet_Iic,hiQ2.2.indicator measurableSet_Iic⟩ + have hl (t : ℝ) (ht : t ∈ Icc 0 B) : + (∑ i, w i*(P i-Q i)*F i t) ≤ (Dp t)⁻¹-(Dq t)⁻¹ := by + have hDtP : 0 < Dp t := weightedStepTail_pos w P hw hw1 hB1 hp ht.2 + have hDtQ : 0 < Dq t := weightedStepTail_pos w Q hw hw1 hB1 hq ht.2 + have hmax : (∑ i, w i*(if t ≤ Q i then P i-Q i else 0)) ≤ Dq t-Dp t := by + change _ ≤ (∑ i, w i*(1-max (Q i) t))-(∑ i, w i*(1-max (P i) t)) + rw [← Finset.sum_sub_distrib] + apply Finset.sum_le_sum + intro i _ + have hm := mul_le_mul_of_nonneg_left (@max_difference_support (P i) (Q i) t) (hw i) + linarith + have hmul := mul_le_mul_of_nonneg_right hmax (by positivity : 0 ≤ 1/(Dq t)^2) + have he : (∑ i, w i*(P i-Q i)*F i t) = + (∑ i, w i*(if t ≤ Q i then P i-Q i else 0))*(1/(Dq t)^2) := by + rw [Finset.sum_mul] + apply Finset.sum_congr rfl + intro i _ + simp only [F,Set.indicator_apply,mem_Iic] + split_ifs <;> ring + rw [he] + calc + _ ≤ (Dq t-Dp t)*(1/(Dq t)^2) := hmul + _ = (Dq t-Dp t)/(Dq t)^2 := by ring + _ ≤ _ := reciprocal_supporting_inequality hDtP hDtQ + have hiF : IntervalIntegrable (fun t => ∑ i, w i*(P i-Q i)*F i t) volume 0 B := by + have hh := IntervalIntegrable.sum Finset.univ (fun i _ => (hFi i).const_mul (w i*(P i-Q i))) + have he : (∑ i, fun t => w i*(P i-Q i)*F i t) = + (fun t => ∑ i, w i*(P i-Q i)*F i t) := by + funext t + simp only [Finset.sum_apply] + rw [he] at hh + exact hh + have hInt := intervalIntegral.integral_mono_on hB0 hiF (hiP.sub hiQ) hl + have hIntF (i : I) : (∫ t in (0:ℝ)..B, F i t) = weightedStepA w Q (Q i) := by + exact intervalIntegral.integral_indicator ⟨(q i).2.1,hq i⟩ + rw [intervalIntegral.integral_sub hiP hiQ, + intervalIntegral.integral_finsetSum (fun i _ => (hFi i).const_mul _)] at hInt + simp only [intervalIntegral.integral_const_mul,hIntF] at hInt + rw [entropy_weightedStepTrial_toReal w p hw hw1 B hB0 hB1 hp, + entropy_weightedStepTrial_toReal w q hw hw1 B hB0 hB1 hq] + change (∑ i, w i*(P i-Q i)*weightedStepA w Q (Q i))/2 ≤ + ((∫ t in (0:ℝ)..B, (Dp t)⁻¹)+Real.log (1-B))/2- + ((∫ t in (0:ℝ)..B, (Dq t)⁻¹)+Real.log (1-B))/2 + linarith + +theorem stationary_finite_entropy_minimizes {k : ℕ} (w h : Fin (k+1) → ℝ) + (q p : Fin (k+1) → Time) (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) + (hq : Monotone q) (hp : Monotone p) + (hq1 : (q (Fin.last k):ℝ) < 1) (hp1 : (p (Fin.last k):ℝ) < 1) + (hstat : ∀ i, 2*h i=weightedStepA w (fun j => (q j:ℝ)) (q i)) : + (entropy (weightedStepTrial w q hw hw1)).toReal-∑ i, w i*h i*(q i:ℝ) ≤ + (entropy (weightedStepTrial w p hw hw1)).toReal-∑ i, w i*h i*(p i:ℝ) := by + let B := max (p (Fin.last k):ℝ) (q (Fin.last k):ℝ) + have hB0 : 0 ≤ B := (p (Fin.last k)).2.1.trans (le_max_left _ _) + have hB1 : B < 1 := max_lt hp1 hq1 + have hP (i : Fin (k+1)) : (p i:ℝ) ≤ B := + (show (p i:ℝ) ≤ (p (Fin.last k):ℝ) from hp (Fin.le_last i)).trans (le_max_left _ _) + have hQ (i : Fin (k+1)) : (q i:ℝ) ≤ B := + (show (q i:ℝ) ≤ (q (Fin.last k):ℝ) from hq (Fin.le_last i)).trans (le_max_right _ _) + have hs := entropy_weightedStep_support w p q hw hw1 B hB0 hB1 hP hQ + have he : (∑ i, w i*((p i:ℝ)-(q i:ℝ))*weightedStepA w (fun j => (q j:ℝ)) (q i))/2 = + (∑ i, w i*h i*(p i:ℝ))-(∑ i, w i*h i*(q i:ℝ)) := by + rw [Finset.sum_div,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + rw [← hstat i] + ring + rw [he] at hs + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/Field.lean b/lean/OAI/Probability/Perceptron/Variational/Field.lean new file mode 100644 index 0000000000000000000000000000000000000000..b091f64f17410494f05ef7ade03d63dc6e8f60d3 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/Field.lean @@ -0,0 +1,125 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DensityDerivative + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma sourceGaussianField_zero (N k : ℕ) (p d : Fin N→ℕ) (g : ℕ→ℝ) + (x : NormalizedSpin N×IndexedLeaf k) : + countableGaussianField (sourceGaussianRow p d (fun _ : Fin (k+1) => 0) (fun _ => 0)) + (indexedGaussianRowLength (I := EnrichedIndex N N p) k) g x=0 := by + let v := sourceGaussianRow p d (fun _ : Fin (k+1) => 0) (fun _ => 0) + let L := indexedGaussianRowLength (S := NormalizedSpin N) (I := EnrichedIndex N N p) k + have hc : countableGaussianCovariance v v L x x=0 := by + simpa only [v,L,perturbationAmplitude,mul_zero,zero_mul,zero_pow (by omega : 2≠0), + Finset.sum_const_zero,add_zero] using + sourceGaussianRow_covariance p d (fun _ : Fin (k+1) => 0) (fun _ => le_rfl) + monotone_const (fun _ => 0) x x + have hs : ∑ i : Fin (L x), v i.val x^2=0 := by + simpa only [countableGaussianCovariance,gaussianPrefixCovariance, + maskedGaussianCoefficient,Fin.isLt,ite_true,← sq] using hc + have hv (i : Fin (L x)) : v i.val x=0 := by + have hi := Finset.single_le_sum (s := Finset.univ) (f := fun j : Fin (L x) => v j.val x^2) + (fun j _ => sq_nonneg (v j.val x)) (Finset.mem_univ i) + rw [hs] at hi + nlinarith [sq_nonneg (v i.val x)] + change (∑ i : Fin (L x), g i.val*v i.val x)=0 + simp only [hv,mul_zero,Finset.sum_const_zero] + +lemma enrichedIndexedHamiltonian_zero (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) (g : ℕ→ℝ) + (x : NormalizedSpin (n+1)×IndexedLeaf k) : + enrichedIndexedHamiltonian n M k f a p d (fun _ => 0) (fun _ => 0) g x= + normalizedPatternEnergy (n+1) M f a x.1 := by + simp only [enrichedIndexedHamiltonian,countableGaussianHamiltonian, + sourceGaussianField_zero,enrichedIndexedBoundedEnergy,mul_zero,sub_zero,add_zero] + +def normalizedPatternLog (n M : ℕ) (f : ℝ →ᵇ ℝ) (a : Fin M→Fin (n+1)→ℝ) : ℝ := + Real.log (∫ x, Real.exp (normalizedPatternEnergy (n+1) M f a x) ∂unitSphereLaw (n+1)) + +lemma sourceKernelPressure_zero (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (a : SourceBaseData n k×(ℕ→ℝ)) : + sourceKernelPressure n k f p d (fun _ => 0) (fun _ => 0) a= + (1/(n+1:ℕ))*normalizedPatternLog n a.1.1 f (patternPrefix (n+1) a.1.1 a.1.2.1) := by + simp only [sourceKernelPressure,tiltPartition,sourceSpinLeafKernel_apply, + enrichedIndexedBaseMeasure,enrichedIndexedHamiltonian_zero,one_mul] + rw [integral_fun_fst (f := fun x : NormalizedSpin (n+1) => Real.exp + (normalizedPatternEnergy (n+1) a.1.1 f (patternPrefix (n+1) a.1.1 a.1.2.1) x))] + simp only [probReal_univ,one_smul,normalizedPatternLog] + +lemma normalizedPatternLog_source (α β : ℝ) (φ : ℝ →ᵇ ℝ) (n : ℕ) + (g : Patterns α (n+1)) : + (1/(n+1:ℕ))*normalizedPatternLog n (patternCount α (n+1)) (β • φ) g= + pressure α β φ (n+1) g := by + unfold pressure sphereLaw + rw [integral_map (by fun_prop) (by + apply Continuous.aestronglyMeasurable + unfold hamiltonian patternField + fun_prop)] + simp_rw [← normalizedPatternEnergy_source α β φ n g] + unfold normalizedPatternLog + ring + +lemma normalizedPatternLog_measurable (n M : ℕ) (f : ℝ →ᵇ ℝ) : + Measurable (normalizedPatternLog n M f) := by + have hm := (Real.continuous_exp.comp (normalizedPatternEnergy_continuous (n+1) M f)).measurable + exact Real.measurable_log.comp hm.stronglyMeasurable.integral_prod_right'.measurable + +lemma enrichedExpectedLog_zero (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (z : Fin k→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 0) (fun _ => 0) z g= + normalizedPatternLog n M f g := by + have hp := sourceCascadeRealization_preserving n k p z + have hm := (enrichedCascadeLog_joint_mean n M k f g p d (fun _ => 0) (fun _ => 0) + z hz hz0 hz1).1.aestronglyMeasurable + unfold enrichedExpectedLog + rw [← hp.map_eq,integral_map hp.measurable.aemeasurable (by rw [hp.map_eq]; exact hm)] + have he : ∀ᵐ a ∂((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw), + enrichedCascadeLog n M k f g p d (fun _ => 0) (fun _ => 0) (sourceCascadeRealization n k p a)= + normalizedPatternLog n M f g := by + filter_upwards [(measurePreserving_fst (μ := (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k))) + (ν := countableGaussianLaw)).quasiMeasurePreserving.ae + ((indexedCascadeGood_ae k z hz0 hz1).and (indexedLeafMeasure_regular k z hz hz0 hz1))] with a ha + rw [show enrichedCascadeLog n M k f g p d (fun _ => 0) (fun _ => 0) + (sourceCascadeRealization n k p a)= + Real.log (tiltPartition (enrichedIndexedBaseMeasure n k a.1) + (enrichedIndexedHamiltonian n M k f g p d (fun _ => 0) (fun _ => 0) a.2) 1) from + (enrichedIndexedHamiltonian_partition n M k f g p d (fun _ => 0) (fun _ => 0) a.2 a.1 ha.1 ha.2).symm] + simp only [tiltPartition,enrichedIndexedBaseMeasure,enrichedIndexedHamiltonian_zero,one_mul] + rw [integral_fun_fst (f := fun x : NormalizedSpin (n+1) => Real.exp (normalizedPatternEnergy (n+1) M f g x))] + simp only [probReal_univ,one_smul,normalizedPatternLog] + rw [integral_congr_ae he,integral_const,probReal_univ,one_smul] + +lemma sourceCountExpectedLog_zero (n k M : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (z : Fin k→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 0) z (fun _ => 0) M= + ∫ g, normalizedPatternLog n M f g ∂finitePatternRowsLaw (n+1) M := by + have hi := (enrichedPoissonLog_section_variance n M k f p d (fun _ => 0) (fun _ => 0) + z hz hz0 hz1).1.integrable (by norm_num) + have he : sourceCountExpectedLog n k f p d (fun _ => 0) z (fun _ => 0) M= + ∫ g, enrichedExpectedLog n M k f p d (fun _ => 0) (fun _ => 0) z (patternPrefix (n+1) M g) + ∂infinitePatternRowsLaw (n+1) := integral_prod _ hi + rw [he] + simp_rw [enrichedExpectedLog_zero n M k f p d z hz hz0 hz1] + have hp := patternPrefix_measurePreserving (n+1) M + rw [← integral_map hp.measurable.aemeasurable (normalizedPatternLog_measurable n M f).aestronglyMeasurable,hp.map_eq] + +lemma sourceCountExpectedLog_original (α β : ℝ) (φ : ℝ →ᵇ ℝ) (n k : ℕ) + (p d : Fin (n+1)→ℕ) (z : Fin k→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 0) z (fun _ => 0) + (patternCount α (n+1))=expectedPressure α β φ (n+1) := by + rw [sourceCountExpectedLog_zero n k _ _ p d z hz hz0 hz1,← integral_const_mul] + simp_rw [normalizedPatternLog_source] + rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FieldContinuity.lean b/lean/OAI/Probability/Perceptron/Variational/FieldContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d1621f74def934b71b833d1596a572cdd0898e4 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FieldContinuity.lean @@ -0,0 +1,218 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.PerturbationContact +import OAI.Probability.Perceptron.Variational.GaussianComparison + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +def sourceFieldCoefficients {N k : ℕ} (p d : Fin N→ℕ) (h : Fin (k+1)→ℝ) : + Fin (k+1)→EnrichedIndex N N p→ℝ := + hierarchyRowCoefficients k (profileGaussianRoot (enrichedCoordinateLevel p d h)) + (profileGaussianStep (enrichedCoordinateLevel p d h)) + +lemma sourceFieldCoefficients_continuous {N k : ℕ} (p d : Fin N→ℕ) : + Continuous (@sourceFieldCoefficients N k p d) := by + have hc (l : Fin (k+1)) (i : EnrichedIndex N N p) : + Continuous (fun h : Fin (k+1)→ℝ => enrichedCoordinateLevel p d h l i) := by + cases i <;> simp only [enrichedCoordinateLevel] <;> fun_prop + apply continuous_pi + intro l + apply continuous_pi + intro i + simp only [sourceFieldCoefficients,profileGaussian_coefficient] + induction l using Fin.cases with + | zero => simpa only [Fin.cases_zero] using (hc 0 i).sqrt + | succ l => simpa only [Fin.cases_succ, Pi.sub_apply] using ((hc l.succ i).sub (hc l.castSucc i)).sqrt + +def sourceFieldDistance {N k : ℕ} (p d : Fin N→ℕ) (u : Fin N→ℝ) + (h' h : Fin (k+1)→ℝ) : ℝ := + let D := indexedCoefficientSquare k (sourceFieldCoefficients p d h)*(enrichedFeatureBound N u:ℝ)^2 + let E := indexedCoefficientSquare k (fun l i => sourceFieldCoefficients p d h' l i- + sourceFieldCoefficients p d h l i)*(enrichedFeatureBound N u:ℝ)^2 + (1/(N:ℝ))*(2*(Real.sqrt (2*D+2*E)*Real.sqrt E))+|h' (Fin.last k)-h (Fin.last k)| + +lemma sourceFieldDistance_continuous {N k : ℕ} (p d : Fin N→ℕ) (u : Fin N→ℝ) + (h : Fin (k+1)→ℝ) : Continuous (fun h' => sourceFieldDistance p d u h' h) := by + have hc := sourceFieldCoefficients_continuous (k := k) p d + have he : Continuous (fun h' => indexedCoefficientSquare k + (fun l i => sourceFieldCoefficients p d h' l i-sourceFieldCoefficients p d h l i)) := by + simpa only [Function.comp_def,Pi.sub_def] using + (indexedCoefficientSquare_continuous (I := EnrichedIndex N N p) k).comp + (hc.sub (continuous_const (y := sourceFieldCoefficients p d h))) + unfold sourceFieldDistance + exact (continuous_const.mul (continuous_const.mul + ((continuous_const.add (continuous_const.mul (he.mul continuous_const))).sqrt.mul + (he.mul continuous_const).sqrt))).add ((continuous_apply _).sub continuous_const).abs + +lemma sourceFieldDistance_self {N k : ℕ} (p d : Fin N→ℕ) (u : Fin N→ℝ) + (h : Fin (k+1)→ℝ) : sourceFieldDistance p d u h h=0 := by + simp [sourceFieldDistance,indexedCoefficientSquare] + +lemma sourceKernelPressure_gaussianMean (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (u : Fin (n+1)→ℝ) (h : Fin (k+1)→ℝ) (a : SourceBaseData n k) : + (∫ g, sourceKernelPressure n k f p d u h (a,g) ∂countableGaussianLaw) = + (1/(n+1:ℕ))*indexedGaussianMean k (sourceSpinLeafKernel n k a) + (fun x => normalizedPatternEnergy (n+1) a.1 f (patternPrefix (n+1) a.1 a.2.1) x.1) + (sourceEnrichedFeature (n+1) p u) (sourceFieldCoefficients p d h)-h (Fin.last k) := by + let W : NormalizedSpin (n+1)×IndexedLeaf k→ℝ := fun x => + normalizedPatternEnergy (n+1) a.1 f (patternPrefix (n+1) a.1 a.2.1) x.1 + have hW : Measurable W := by + have hm := enrichedIndexedBoundedEnergy_measurable n a.1 k f (patternPrefix (n+1) a.1 a.2.1) (fun _ => 0) + unfold enrichedIndexedBoundedEnergy at hm + simpa only [mul_zero,sub_zero] using hm + have hA (x) : |W x|≤(a.1:ℝ)*‖f‖ := normalizedPatternEnergy_bound (n+1) a.1 f _ x.1 + have hD (x) : (∑ i, sourceEnrichedFeature (n+1) p u x i^2)≤(enrichedFeatureBound (n+1) u:ℝ)^2 := by + have he := congrArg (fun r : ℝ => r^2) (sourceEnrichedFeature_norm (n+1) p u x) + simpa only [EuclideanSpace.norm_sq_eq,Real.norm_eq_abs,sq_abs] using he.le + have he := indexedGaussianMean_add_const k (sourceSpinLeafKernel n k a) hW + (sourceEnrichedFeature_measurable (n+1) p u) hA hD (sourceFieldCoefficients p d h) + (-((n+1:ℕ)*h (Fin.last k))) + simp only [sourceKernelPressure,integral_const_mul] + change (1/(n+1:ℕ):ℝ)*indexedGaussianMean k (sourceSpinLeafKernel n k a) + (fun x => W x + -((n+1:ℕ)*h (Fin.last k))) (sourceEnrichedFeature (n+1) p u) (sourceFieldCoefficients p d h) = _ + rw [he] + dsimp only [W] + field_simp + ring + +lemma sourceConditional_field_comparison (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (u : Fin (n+1)→ℝ) (h' h : Fin (k+1)→ℝ) (a : SourceBaseData n k) : + |(∫ g, sourceKernelPressure n k f p d u h' (a,g) ∂countableGaussianLaw)- + ∫ g, sourceKernelPressure n k f p d u h (a,g) ∂countableGaussianLaw| ≤ + sourceFieldDistance p d u h' h := by + have hW : Measurable (fun x : NormalizedSpin (n+1)×IndexedLeaf k => + normalizedPatternEnergy (n+1) a.1 f (patternPrefix (n+1) a.1 a.2.1) x.1) := by + have hm := enrichedIndexedBoundedEnergy_measurable n a.1 k f (patternPrefix (n+1) a.1 a.2.1) (fun _ => 0) + unfold enrichedIndexedBoundedEnergy at hm + simpa only [mul_zero,sub_zero] using hm + have H := indexedGaussianMean_comparison k (sourceSpinLeafKernel n k a) + hW (sourceEnrichedFeature_measurable (n+1) p u) + (sq_nonneg (enrichedFeatureBound (n+1) u:ℝ)) + (fun x => normalizedPatternEnergy_bound (n+1) a.1 f (patternPrefix (n+1) a.1 a.2.1) x.1) + (fun x => show (∑ i, sourceEnrichedFeature (n+1) p u x i^2)≤(enrichedFeatureBound (n+1) u:ℝ)^2 from by + have he := congrArg (fun r : ℝ => r^2) (sourceEnrichedFeature_norm (n+1) p u x) + simpa only [EuclideanSpace.norm_sq_eq,Real.norm_eq_abs,sq_abs] using he.le) + (sourceFieldCoefficients p d h') (sourceFieldCoefficients p d h) + rw [sourceKernelPressure_gaussianMean,sourceKernelPressure_gaussianMean] + rw [show ∀ a b c e : ℝ, a-b-(c-e)=(a-c)-(b-e) by intros; ring] + apply (abs_sub _ _).trans + rw [← mul_sub,abs_mul,abs_of_nonneg (by positivity : (0:ℝ)≤1/(n+1:ℕ))] + exact add_le_add (mul_le_mul_of_nonneg_left H (by positivity : (0:ℝ)≤1/(n+1:ℕ))) le_rfl + +lemma sourceExpectedPressure_field_comparison (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (u : Fin (n+1)→ℝ) (h' h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 (∫ g, sourceKernelPressure n k f p d u h' (a,g) ∂countableGaussianLaw)- + ∫ g, sourceKernelPressure n k f p d u h (a,g) ∂countableGaussianLaw) + (ae_of_all _ fun a => by simpa only [Real.norm_eq_abs] using + sourceConditional_field_comparison n k f p d u h' h a) + +lemma sourceExpectedPressure_field_continuous (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 sourceExpectedPressure n k f p d h z t u) := by + apply continuous_iff_continuousAt.mpr + intro h + apply tendsto_iff_norm_sub_tendsto_zero.mpr + refine squeeze_zero (fun _ => norm_nonneg _) (g := fun h' => sourceFieldDistance p d u h' h) ?_ ?_ + · intro h' + simpa only [Real.norm_eq_abs] using sourceExpectedPressure_field_comparison n k f p d u h' h z hz hz0 hz1 t + · have hc : Tendsto (fun h' => sourceFieldDistance p d u h' h) (𝓝 h) + (𝓝 (sourceFieldDistance p d u h h)) := (sourceFieldDistance_continuous p d u h).continuousAt + rwa [sourceFieldDistance_self] at hc + +def sourceDirectionProfile {N k : ℕ} (p : Fin N→ℕ) (a : Fin (k+1)→ℝ) + (l : Fin (k+1)) : EnrichedIndex N N p→ℝ := + Sum.elim (fun _ => 2*a l) (fun _ => 0) + +def sourceDirectionCoefficients {N k : ℕ} (p : Fin N→ℕ) (a : Fin (k+1)→ℝ) : + Fin (k+1)→EnrichedIndex N N p→ℝ := + hierarchyRowCoefficients k (profileGaussianRoot (sourceDirectionProfile p a)) + (profileGaussianStep (sourceDirectionProfile p a)) + +lemma sourceDirectionProfile_nonneg {N k : ℕ} (p : Fin N→ℕ) {a : Fin (k+1)→ℝ} + (ha0 : ∀ l, 0 ≤ a l) (l : Fin (k+1)) (i : EnrichedIndex N N p) : + 0 ≤ sourceDirectionProfile p a l i := by + cases i with + | inl i => exact mul_nonneg (by norm_num) (ha0 l) + | inr i => exact le_rfl + +lemma sourceDirectionProfile_monotone {N k : ℕ} (p : Fin N→ℕ) {a : Fin (k+1)→ℝ} + (ha : Monotone a) (i : EnrichedIndex N N p) : + Monotone (fun l => sourceDirectionProfile p a l i) := by + cases i with + | inl i => exact fun l m hlm => mul_le_mul_of_nonneg_left (ha hlm) (by norm_num) + | inr i => exact monotone_const + +lemma sourceFieldCoefficients_affine_covariance {N k : ℕ} (p d : Fin N→ℕ) + {h a : Fin (k+1)→ℝ} (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) {t : ℝ} (ht : 0 ≤ t) + (l : Fin (k+1)) (i : EnrichedIndex N N p) : + sourceFieldCoefficients p d (fun l => h l+t*a l) l i^2 = + sourceFieldCoefficients p d h l i^2+t*sourceDirectionCoefficients p a l i^2 := by + have hv (r : Fin (k+1)) : enrichedCoordinateLevel p d (fun l => h l+t*a l) r i = + enrichedCoordinateLevel p d h r i+t*sourceDirectionProfile p a r i := by + cases i <;> simp [enrichedCoordinateLevel,sourceDirectionProfile] + ring + have hq0 := enrichedCoordinateLevel_nonneg p d hh0 + have hqm := enrichedCoordinateLevel_monotone p d hh + have hr0 := sourceDirectionProfile_nonneg p ha0 + have hrm := sourceDirectionProfile_monotone p ha + simp only [sourceFieldCoefficients,sourceDirectionCoefficients,profileGaussian_coefficient] + induction l using Fin.cases with + | zero => + simp only [Fin.cases_zero,hv,Real.sq_sqrt (hq0 0 i),Real.sq_sqrt (hr0 0 i)] + rw [Real.sq_sqrt (add_nonneg (hq0 0 i) (mul_nonneg ht (hr0 0 i)))] + | succ l => + have hb := sub_nonneg.mpr (hqm i (Fin.castSucc_le_succ l)) + have hc := sub_nonneg.mpr (hrm i (Fin.castSucc_le_succ l)) + simp only [Fin.cases_succ,hv,Real.sq_sqrt hb,Real.sq_sqrt hc] + have hd : 0 ≤ enrichedCoordinateLevel p d h l.succ i+t*sourceDirectionProfile p a l.succ i- + (enrichedCoordinateLevel p d h l.castSucc i+t*sourceDirectionProfile p a l.castSucc i) := by + nlinarith [mul_nonneg ht hc] + rw [Real.sq_sqrt hd] + ring + +lemma sourceDirection_feature_cross {N k : ℕ} (p : Fin N→ℕ) + (u : Fin N→ℝ) (a : Fin (k+1)→ℝ) (l : Fin (k+1)) (x y : NormalizedSpin N) : + (∑ i : EnrichedIndex N N p, sourceDirectionProfile p a l i* + sourceEnrichedFeature N p u x i*sourceEnrichedFeature N p u y i) = + 2*(N:ℝ)*a l*spinOverlap x y := by + rw [Fintype.sum_sum_type] + simp only [sourceDirectionProfile,Sum.elim_inl,Sum.elim_inr,zero_mul,Finset.sum_const_zero,add_zero] + change (∑ i : Fin N, 2*a l*(Real.sqrt (N:ℝ)*x.val i)*(Real.sqrt (N:ℝ)*y.val i)) = + 2*(N:ℝ)*a l*(∑ i : Fin N, y.val i*x.val i) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + calc + _ = 2*a l*(Real.sqrt (N:ℝ))^2*(y.val i*x.val i) := by ring + _ = _ := by rw [Real.sq_sqrt (Nat.cast_nonneg N)]; ring + +lemma sourceDirection_covariance {N k : ℕ} (p : Fin N→ℕ) + (u : Fin N→ℝ) {a : Fin (k+1)→ℝ} (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) + (x y : NormalizedSpin N×IndexedLeaf k) : + countableGaussianCovariance + (indexedGaussianRow k (sourceDirectionCoefficients p a) (sourceEnrichedFeature N p u)) + (indexedGaussianRow k (sourceDirectionCoefficients p a) (sourceEnrichedFeature N p u)) + (indexedGaussianRowLength (I := EnrichedIndex N N p) k) x y = + 2*(N:ℝ)*a (indexedCommonDepth k y.2 x.2)*spinOverlap x.1 y.1 := by + unfold sourceDirectionCoefficients + rw [profileGaussianRow_covariance _ (sourceDirectionProfile_nonneg p ha0 0) + (sourceDirectionProfile_monotone p ha),sourceDirection_feature_cross] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FieldDerivative.lean b/lean/OAI/Probability/Perceptron/Variational/FieldDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..dc1e8ce091d91f18d82be250c60516aa9dd220ad --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FieldDerivative.lean @@ -0,0 +1,182 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FieldContinuity +import OAI.Probability.Perceptron.Variational.IndexedObservableTransport + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma sourceFeature_square_bound (N : ℕ) (p : Fin N→ℕ) (u : Fin N→ℝ) (x : NormalizedSpin N) : + (∑ i, sourceEnrichedFeature N p u x i^2) ≤ (enrichedFeatureBound N u:ℝ)^2 := by + have he := congrArg (fun r : ℝ => r^2) (sourceEnrichedFeature_norm N p u x) + simpa only [EuclideanSpace.norm_sq_eq,Real.norm_eq_abs,sq_abs] using he.le + +lemma sourceKernelPressure_gaussianMean_base (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (u : Fin (n+1)→ℝ) (h' h : Fin (k+1)→ℝ) (a : SourceBaseData n k) : + (∫ g, sourceKernelPressure n k f p d u h' (a,g) ∂countableGaussianLaw) = + (1/(n+1:ℕ))*indexedGaussianMean k (sourceSpinLeafKernel n k a) + (sourceBaseEnergy n k f h a) (sourceEnrichedFeature (n+1) p u) + (sourceFieldCoefficients p d h')+h (Fin.last k)-h' (Fin.last k) := by + let W : NormalizedSpin (n+1)×IndexedLeaf k→ℝ := fun x => + normalizedPatternEnergy (n+1) a.1 f (patternPrefix (n+1) a.1 a.2.1) x.1 + have hW : Measurable W := by + have hm := enrichedIndexedBoundedEnergy_measurable n a.1 k f (patternPrefix (n+1) a.1 a.2.1) (fun _ => 0) + unfold enrichedIndexedBoundedEnergy at hm + simpa only [mul_zero,sub_zero] using hm + have he := indexedGaussianMean_add_const k (sourceSpinLeafKernel n k a) hW + (sourceEnrichedFeature_measurable (n+1) p u) + (fun x => normalizedPatternEnergy_bound (n+1) a.1 f _ x.1) + (sourceFeature_square_bound (n+1) p u) (sourceFieldCoefficients p d h') + (-((n+1:ℕ)*h (Fin.last k))) + rw [sourceKernelPressure_gaussianMean] + change _ = (1/(n+1:ℕ))*indexedGaussianMean k (sourceSpinLeafKernel n k a) + (fun x => W x+ -((n+1:ℕ)*h (Fin.last k))) (sourceEnrichedFeature (n+1) p u) + (sourceFieldCoefficients p d h')+h (Fin.last k)-h' (Fin.last k) + rw [he] + dsimp only [W] + field_simp + ring + +theorem sourceConditional_field_right_derivative (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) {h a : Fin (k+1)→ℝ} + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) + (b : SourceBaseData n k) : + let w := indexedGaussianRow k (sourceDirectionCoefficients p a) (sourceEnrichedFeature (n+1) p u) + let L := indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) (S := NormalizedSpin (n+1)) k + HasDerivWithinAt (fun t => ∫ g, sourceKernelPressure n k f p d u (fun l => h l+t*a l) (b,g) + ∂countableGaussianLaw) + ((1/(n+1:ℕ))*((∫ g, indexedResponse k (sourceSpinLeafKernel n k b) + (countableGaussianCovariance w w L) (sourceCouplingHamiltonian n k f p d h u (b,g)) + ∂countableGaussianLaw)/2)-a (Fin.last k)) (Ici 0) 0 := by + have hW := (sourceBaseEnergy_measurable n k f h).of_uncurry_left (x := b) + have hA := enrichedIndexedBoundedEnergy_bound n b.1 k f (patternPrefix (n+1) b.1 b.2.1) h + have hd := indexedGaussianMean_right_response k (sourceSpinLeafKernel n k b) + hW (sourceEnrichedFeature_measurable (n+1) p u) (sq_nonneg (enrichedFeatureBound (n+1) u:ℝ)) + hA (sourceFeature_square_bound (n+1) p u) + (sourceFieldCoefficients p d h) (sourceDirectionCoefficients p a) + (fun t => sourceFieldCoefficients p d (fun l => h l+t*a l)) + (fun t ht => sourceFieldCoefficients_affine_covariance p d hh0 hh ha0 ha ht) + have he := (hd.const_mul (1/(n+1:ℕ):ℝ)).sub + (((hasDerivAt_id (0:ℝ)).mul_const (a (Fin.last k))).hasDerivWithinAt (s := Ici 0)) + dsimp only at he ⊢ + simp only [one_mul] at he + apply he.congr + · intro t ht + rw [sourceKernelPressure_gaussianMean_base n k f p d u _ h b] + dsimp only [Pi.sub_apply,id_eq] + ring + · rw [sourceKernelPressure_gaussianMean_base n k f p d u _ h b] + simp only [Pi.sub_apply,id_eq,zero_mul,add_zero,sub_zero] + ring + + +def sourceFieldObservable {N k : ℕ} (a : Fin (k+1)→ℝ) + (x : Fin 2→NormalizedSpin N×IndexedLeaf k) : ℝ := + a (indexedCommonDepth k (x 0).2 (x 1).2)*spinOverlap (x 1).1 (x 0).1 + +lemma sourceFieldObservable_measurable {N k : ℕ} (a : Fin (k+1)→ℝ) : + Measurable (sourceFieldObservable (N := N) a) := by + have ht : Measurable (fun x : Fin 2→NormalizedSpin N×IndexedLeaf k => a (indexedCommonDepth k (x 0).2 (x 1).2)) := + (Measurable.of_discrete (f := fun x : IndexedLeaf k×IndexedLeaf k => a (indexedCommonDepth k x.1 x.2))).comp + (((measurable_pi_apply 0).snd).prodMk ((measurable_pi_apply 1).snd)) + have hr : Measurable (fun x : Fin 2→NormalizedSpin N×IndexedLeaf k => spinOverlap (x 1).1 (x 0).1) := + (measurable_subtype_coe.comp ((measurable_pi_apply 1).fst)).inner + (measurable_subtype_coe.comp ((measurable_pi_apply 0).fst)) + exact ht.mul hr + +lemma sourceFieldObservable_bound {N k : ℕ} {a : Fin (k+1)→ℝ} + (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) (x : Fin 2→NormalizedSpin N×IndexedLeaf k) : + |sourceFieldObservable a x| ≤ a (Fin.last k) := by + rw [sourceFieldObservable,abs_mul,abs_of_nonneg (ha0 _)] + exact (mul_le_mul_of_nonneg_left (spinOverlap_abs_le _ _) (ha0 _)).trans + (by simpa only [mul_one] using ha (Fin.le_last _)) + +lemma sourceConditional_field_observable_bound (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) (h : Fin (k+1)→ℝ) + {a : Fin (k+1)→ℝ} (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) + (b : SourceBaseData n k) (g : ℕ→ℝ) : + |gibbsReplicaMean (sourceSpinLeafKernel n k b) (sourceCouplingHamiltonian n k f p d h u (b,g)) 2 + (sourceFieldObservable a)| ≤ a (Fin.last k) := + tiltMean_bound_general _ + (replicaPotential_measurable (sourceCouplingHamiltonian_section n k f p d h u (b,g)) 2) + (sourceFieldObservable_measurable a) (ha0 _) (sourceFieldObservable_bound ha0 ha) + +lemma sourceConditional_field_observable_integrable (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) (h : Fin (k+1)→ℝ) + {a : Fin (k+1)→ℝ} (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) + (b : SourceBaseData n k) : + Integrable (fun g => gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d h u (b,g)) 2 (sourceFieldObservable a)) countableGaussianLaw := by + have hm : Measurable (Function.uncurry (fun g => sourceCouplingHamiltonian n k f p d h u (b,g))) := + (sourceCouplingHamiltonian_measurable n k f p d h u).comp + ((measurable_const.prodMk measurable_fst).prodMk measurable_snd) + exact kernel_replicaMean_bounded_integrable (Kernel.const _ (sourceSpinLeafKernel n k b)) countableGaussianLaw + (H := fun g => sourceCouplingHamiltonian n k f p d h u (b,g)) (G := fun _ => sourceFieldObservable a) + hm ((sourceFieldObservable_measurable a).comp measurable_snd) (ha0 _) + (fun _ => sourceFieldObservable_bound ha0 ha) + +lemma sourceConditional_partition_pos_ae (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) (h : Fin (k+1)→ℝ) + (b : SourceBaseData n k) : + ∀ᵐ g ∂countableGaussianLaw, + 0 < tiltPartition (sourceSpinLeafKernel n k b) (sourceCouplingHamiltonian n k f p d h u (b,g)) 1 := by + have he := (countableGaussianHamiltonian_exp_joint_integrable (sourceSpinLeafKernel n k b) + ((sourceBaseEnergy_measurable n k f h).of_uncurry_left (x := b)) + (indexedGaussianRow_measurable k (sourceFieldCoefficients p d h) (sourceEnrichedFeature_measurable (n+1) p u)) + (indexedGaussianRowLength_measurable k) + (enrichedIndexedBoundedEnergy_bound n b.1 k f (patternPrefix (n+1) b.1 b.2.1) h) + (indexedGaussianRow_square_total k (sourceFieldCoefficients p d h) (sourceEnrichedFeature (n+1) p u) + (sourceFeature_square_bound (n+1) p u)) 1).prod_left_ae + exact he.mono fun g hg => tilt_partition_pos_of_integrable _ hg + +lemma tiltMean_const_of_pos {S : Type*} [MeasurableSpace S] (μ : Measure S) + (H : S→ℝ) (t c : ℝ) (hpos : 0 < tiltPartition μ H t) : + tiltMean μ H (fun _ => c) t=c := by + unfold tiltMean tiltIntegral + rw [integral_mul_const] + change tiltPartition μ H t*c/tiltPartition μ H t=c + field_simp + +lemma sourceConditional_response_eq (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) (h : Fin (k+1)→ℝ) + {a : Fin (k+1)→ℝ} (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) (b : SourceBaseData n k) : + let w := indexedGaussianRow k (sourceDirectionCoefficients p a) (sourceEnrichedFeature (n+1) p u) + let L := indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) (S := NormalizedSpin (n+1)) k + (∫ g, indexedResponse k (sourceSpinLeafKernel n k b) (countableGaussianCovariance w w L) + (sourceCouplingHamiltonian n k f p d h u (b,g)) ∂countableGaussianLaw) = + 2*(n+1:ℕ)*a (Fin.last k)-2*(n+1:ℕ)*(∫ g, gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d h u (b,g)) 2 (sourceFieldObservable a) ∂countableGaussianLaw) := by + dsimp only + have hd (x : NormalizedSpin (n+1)×IndexedLeaf k) : spinOverlap x.1 x.1=1 := by + have hx : ‖x.1.val‖=1 := by simp + simp [spinOverlap,hx] + have he : ∀ᵐ g ∂countableGaussianLaw, indexedResponse k (sourceSpinLeafKernel n k b) + (countableGaussianCovariance + (indexedGaussianRow k (sourceDirectionCoefficients p a) (sourceEnrichedFeature (n+1) p u)) + (indexedGaussianRow k (sourceDirectionCoefficients p a) (sourceEnrichedFeature (n+1) p u)) + (indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) k)) + (sourceCouplingHamiltonian n k f p d h u (b,g)) = + 2*(n+1:ℕ)*a (Fin.last k)-2*(n+1:ℕ)*gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d h u (b,g)) 2 (sourceFieldObservable a) := by + filter_upwards [sourceConditional_partition_pos_ae n k f p d u h b] with g hg + simp only [indexedResponse,sourceDirection_covariance p u ha0 ha,indexedCommonDepth_self,hd,mul_one] + rw [tiltMean_const_of_pos _ _ _ _ hg] + congr 1 + change tiltMean _ _ (fun x : Fin 2→NormalizedSpin (n+1)×IndexedLeaf k => 2*(n+1:ℕ)*a (indexedCommonDepth k (x 0).2 (x 1).2)*spinOverlap (x 1).1 (x 0).1) 1 = _ + rw [show (fun x : Fin 2→NormalizedSpin (n+1)×IndexedLeaf k => + 2*(n+1:ℕ)*a (indexedCommonDepth k (x 0).2 (x 1).2)*spinOverlap (x 1).1 (x 0).1) = + (fun x => (2*(n+1:ℕ))*sourceFieldObservable a x) from funext fun x => by + unfold sourceFieldObservable + ring,tiltMean_const_mul_general] + rfl + rw [integral_congr_ae he,integral_sub (integrable_const _) + ((sourceConditional_field_observable_integrable n k f p d u h ha0 ha b).const_mul _), + integral_const,probReal_univ,one_smul,integral_const_mul] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FieldRounding.lean b/lean/OAI/Probability/Perceptron/Variational/FieldRounding.lean new file mode 100644 index 0000000000000000000000000000000000000000..09e56a263896381c0f43449fbca3f90b0575728d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FieldRounding.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FiniteFieldModel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +structure BoundedField (H : ℝ) where + toFun : Time → ℝ + monotone : Monotone toFun + nonneg : ∀ u, 0 ≤ toFun u + le_bound : ∀ u, toFun u ≤ H + +instance {H : ℝ} : CoeFun (BoundedField H) (fun _ => Time → ℝ) := ⟨BoundedField.toFun⟩ + +lemma BoundedField.measurable {H : ℝ} (f : BoundedField H) : Measurable f := f.monotone.measurable + +lemma BoundedField.bound_nonneg {H : ℝ} (f : BoundedField H) : 0 ≤ H := (f.nonneg 0).trans (f.le_bound 0) + +lemma BoundedField.integrable {H : ℝ} (f : BoundedField H) : Integrable f timeLaw := by + apply Integrable.mono' (integrable_const H) f.measurable.aestronglyMeasurable + exact ae_of_all _ (fun u => by simpa only [Real.norm_eq_abs,abs_of_nonneg (f.nonneg u)] using f.le_bound u) + +def roundLower (N : ℕ) (x : ℝ) : ℝ := (⌊(N+1:ℕ)*x⌋₊:ℝ)/(N+1:ℕ) + +lemma roundLower_nonneg (N : ℕ) (x : ℝ) : 0 ≤ roundLower N x := by unfold roundLower; positivity + +lemma roundLower_monotone (N : ℕ) : Monotone (roundLower N) := by + intro x y hxy + apply div_le_div_of_nonneg_right _ (by positivity) + exact_mod_cast Nat.floor_mono (mul_le_mul_of_nonneg_left hxy (by positivity)) + +lemma roundLower_le (N : ℕ) {x : ℝ} (hx : 0 ≤ x) : roundLower N x ≤ x := by + unfold roundLower + rw [div_le_iff₀ (by positivity : (0:ℝ)<(N+1:ℕ))] + simpa only [mul_comm] using Nat.floor_le (mul_nonneg (by positivity) hx) + +lemma sub_roundLower_lt (N : ℕ) {x : ℝ} (_hx : 0 ≤ x) : x-roundLower N x < 1/(N+1:ℕ) := by + have h := Nat.lt_floor_add_one ((N+1:ℕ)*x) + unfold roundLower + rw [sub_lt_iff_lt_add,← add_div,lt_div_iff₀ (by positivity : (0:ℝ)<(N+1:ℕ))] + simpa only [mul_comm,add_comm] using h + +lemma roundLower_measurable (N : ℕ) : Measurable (roundLower N) := (roundLower_monotone N).measurable + +def BoundedField.round {H : ℝ} (f : BoundedField H) (N : ℕ) : BoundedField H where + toFun := fun u => roundLower N (f u) + monotone := (roundLower_monotone N).comp f.monotone + nonneg := fun u => roundLower_nonneg N (f u) + le_bound := fun u => (roundLower_le N (f.nonneg u)).trans (f.le_bound u) + +lemma BoundedField.round_error {H : ℝ} (f : BoundedField H) (N : ℕ) (u : Time) : + |f.round N u-f u| ≤ 1/(N+1:ℕ) := by + change |roundLower N (f u)-f u| ≤ _ + rw [abs_sub_comm,abs_of_nonneg (sub_nonneg.mpr (roundLower_le N (f.nonneg u)))] + exact (sub_roundLower_lt N (f.nonneg u)).le + +lemma BoundedField.round_finite {H : ℝ} (f : BoundedField H) (N : ℕ) : + (Set.range (f.round N)).Finite := by + let T := (Finset.range (⌊(N+1:ℕ)*H⌋₊+1)).image (fun k : ℕ => (k:ℝ)/(N+1:ℕ)) + apply T.finite_toSet.subset + rintro x ⟨u,rfl⟩ + apply Finset.mem_image.mpr + refine ⟨⌊(N+1:ℕ)*f u⌋₊,?_,rfl⟩ + apply Finset.mem_range.mpr + exact Nat.lt_succ_of_le (Nat.floor_mono (mul_le_mul_of_nonneg_left (f.le_bound u) (by positivity))) + +def BoundedField.roundModel {H : ℝ} (f : BoundedField H) (N : ℕ) : FiniteFieldModel (f.round N) := + Classical.choice (exists_finiteFieldModel _ (f.round N).measurable (f.round_finite N)) + +lemma BoundedField.round_abs_integral {H : ℝ} (f : BoundedField H) (N : ℕ) : + (∫ u, |f.round N u-f u| ∂timeLaw) ≤ 1/(N+1:ℕ) := by + have h := integral_mono ((f.round N).integrable.sub f.integrable).abs + (integrable_const (1/(N+1:ℕ):ℝ)) (f.round_error N) + simpa using h + + +def quantileTrial (q : Time → Time) : Trial where + toFun := fun t => timeLaw.real {u | q u ≤ t} + monotone := by + intro s t hst + exact measureReal_mono (fun u hu => hu.trans hst) + measurable := by + apply Monotone.measurable + intro s t hst + exact measureReal_mono (fun u hu => hu.trans hst) + nonneg := fun _ => measureReal_nonneg + le_one := by + intro t + simp + +def quantileTail (q : Time → Time) (t : ℝ) : ℝ := + ∫ u, 1-max (q u:ℝ) t ∂timeLaw + +lemma quantileTrial_eq_integral (q : Time → Time) (hq : Measurable q) (t : Time) : + quantileTrial q t=∫ u, (if q u ≤ t then (1:ℝ) else 0) ∂timeLaw := by + change timeLaw.real {u | q u ≤ t}=∫ u, {u | q u ≤ t}.indicator (fun _ => (1:ℝ)) u ∂timeLaw + rw [integral_indicator (measurableSet_le hq measurable_const),integral_const] + simp only [Measure.real,Measure.restrict_apply_univ,smul_eq_mul,mul_one] + +lemma tailIntegral_quantileTrial (q : Time → Time) (hq : Measurable q) (t : Time) : + tailIntegral (quantileTrial q) t=quantileTail q (t:ℝ) := by + have hm : Measurable (fun p : Time×Time => if q p.2 ≤ p.1 then (1:ℝ) else 0) := + measurable_const.ite (measurableSet_le (hq.comp measurable_snd) measurable_fst) measurable_const + have hi : Integrable (fun p : Time×Time => if q p.2 ≤ p.1 then (1:ℝ) else 0) + ((timeLaw.restrict (Ici t)).prod timeLaw) := by + apply Integrable.mono' (integrable_const (1:ℝ)) hm.aestronglyMeasurable + exact ae_of_all _ fun p => by split_ifs <;> norm_num + unfold tailIntegral + simp_rw [quantileTrial_eq_integral q hq] + rw [integral_integral_swap hi] + simp_rw [timeTail_atom_integral (q _) t 1,one_mul] + rfl + +lemma quantileTail_integrable (q : Time → Time) (hq : Measurable q) (t : ℝ) : + Integrable (fun u => 1-max (q u:ℝ) t) timeLaw := by + have hm : Measurable (fun u => 1-max (q u:ℝ) t) := + measurable_const.sub ((measurable_subtype_coe.comp hq).max measurable_const) + apply Integrable.mono' (integrable_const (2+|t|)) hm.aestronglyMeasurable + exact ae_of_all _ fun u => by + rw [Real.norm_eq_abs] + have hq0 := (q u).2.1 + have hq1 := (q u).2.2 + have ha : |max (q u:ℝ) t| ≤ 1+|t| := by + rcases le_total (q u:ℝ) t with h | h + · rw [max_eq_right h]; linarith + · rw [max_eq_left h,abs_of_nonneg hq0]; nlinarith [abs_nonneg t] + have hb := abs_sub 1 (max (q u:ℝ) t) + norm_num at hb + linarith + +lemma quantileTail_lower (q : Time → Time) (hq : Measurable q) {B t : ℝ} + (hb : ∀ᵐ u ∂timeLaw, (q u:ℝ) ≤ B) (ht : t ≤ B) : + 1-B ≤ quantileTail q t := by + have h := integral_mono_ae (integrable_const (1-B)) (quantileTail_integrable q hq t) + (hb.mono fun u hu => sub_le_sub_left (max_le hu ht) 1) + simpa [quantileTail] using h + +lemma quantileTail_upper (q : Time → Time) (hq : Measurable q) (t : ℝ) : + quantileTail q t ≤ 1-t := by + have h := integral_mono (quantileTail_integrable q hq t) (integrable_const (1-t)) + (fun u => sub_le_sub_left (le_max_right (q u:ℝ) t) 1) + simpa [quantileTail] using h + +lemma quantileTail_of_le (q : Time → Time) {t : ℝ} (ht : ∀ᵐ u ∂timeLaw, (q u:ℝ) ≤ t) : + quantileTail q t=1-t := by + unfold quantileTail + calc + _ = ∫ _ : Time, (1-t) ∂timeLaw := integral_congr_ae (ht.mono fun u hu => by rw [max_eq_right hu]) + _ = _ := by simp + +lemma quantileTail_lipschitz (q : Time → Time) (hq : Measurable q) : + LipschitzWith 1 (quantileTail q) := by + apply LipschitzWith.of_dist_le_mul + intro s t + rw [Real.dist_eq,Real.dist_eq,NNReal.coe_one,one_mul] + unfold quantileTail + rw [← integral_sub (quantileTail_integrable q hq s) (quantileTail_integrable q hq t)] + calc + _ ≤ ∫ u, |(1-max (q u:ℝ) s)-(1-max (q u:ℝ) t)| ∂timeLaw := abs_integral_le_integral_abs + _ ≤ ∫ _ : Time, |s-t| ∂timeLaw := by + apply integral_mono ((quantileTail_integrable q hq s).sub (quantileTail_integrable q hq t)).abs (integrable_const _) + intro u + have h := (LipschitzWith.id.const_max (q u:ℝ)).dist_le_mul s t + simp only [Real.dist_eq,NNReal.coe_one,one_mul] at h + change |(1-max (q u:ℝ) s)-(1-max (q u:ℝ) t)| ≤ _ + rw [show (1-max (q u:ℝ) s)-(1-max (q u:ℝ) t)=max (q u:ℝ) t-max (q u:ℝ) s by ring,abs_sub_comm] + exact h + _ = _ := by simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FieldWord.lean b/lean/OAI/Probability/Perceptron/Variational/FieldWord.lean new file mode 100644 index 0000000000000000000000000000000000000000..9afb08fbd707f0fe6b896d1b0701d58ff34f3829 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FieldWord.lean @@ -0,0 +1,172 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.CascadeHeat +import OAI.Probability.Perceptron.Variational.ConvexUniform + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma cascadeHeatWord_eq_ofFn (σ : ℕ → ℝ) (k : ℕ) (z : Fin k → ℝ) : + cascadeHeatWord σ k z=List.ofFn (fun i => (z i,σ (k-1-i.val))) := by + induction k with + | zero => simp [cascadeHeatWord] + | succ k ih => + rw [cascadeHeatWord,List.ofFn_succ,ih] + simp only [Fin.val_zero,Nat.add_sub_cancel,Nat.sub_zero] + congr 1 + congr 1 + funext i + have he : k-1-i.val=k+1-1-i.succ.val := by simp only [Fin.val_succ]; omega + simp only [he,Nat.add_sub_cancel] + +def fieldVariances (k : ℕ) (h : Fin (k+1) → ℝ) : Fin (k+1) → ℝ := + Fin.cases (2*h 0) (fun i => 2*(h i.succ-h i.castSucc)) + +def fieldExponents {k : ℕ} (w : Fin (k+1) → ℝ) : Fin (k+1) → ℝ := + Fin.cases 0 (stepCumulative w) + +lemma fieldVariances_nonneg (k : ℕ) (h : Fin (k+1) → ℝ) + (hh : Monotone h) (hh0 : 0 ≤ h 0) (i : Fin (k+1)) : 0 ≤ fieldVariances k h i := by + refine Fin.cases ?_ (fun i => ?_) i + · exact mul_nonneg (by norm_num) hh0 + · exact mul_nonneg (by norm_num) (sub_nonneg.mpr (hh (Fin.castSucc_le_succ i))) + +lemma fieldVariances_sum (k : ℕ) (h : Fin (k+1) → ℝ) : + (∑ i, fieldVariances k h i)=2*h (Fin.last k) := by + rw [Fin.sum_univ_succ] + simp only [fieldVariances,Fin.cases_zero,Fin.cases_succ] + rw [← Finset.mul_sum,finite_sum_successive_differences] + ring + +lemma fieldExponents_nonneg {k : ℕ} (w : Fin (k+1) → ℝ) (hw : ∀ i, 0 < w i) + (i : Fin (k+1)) : 0 ≤ fieldExponents w i := by + refine Fin.cases (by rfl) (fun j => (stepCumulative_pos w hw j).le) i + +lemma fieldExponents_lt_one {k : ℕ} (w : Fin (k+1) → ℝ) (hw : ∀ i, 0 < w i) + (hw1 : ∑ i, w i=1) (i : Fin (k+1)) : fieldExponents w i < 1 := by + refine Fin.cases (by norm_num [fieldExponents]) (fun j => stepCumulative_lt_one w hw hw1 j) i + +lemma fieldExponents_strictMono {k : ℕ} (w : Fin (k+1) → ℝ) (hw : ∀ i, 0 < w i) : + StrictMono (fieldExponents w) := by + intro i + refine Fin.cases ?_ (fun i => ?_) i + · intro j + refine Fin.cases (by simp) (fun j _ => stepCumulative_pos w hw j) j + · intro j + refine Fin.cases (by simp) (fun j hij => stepCumulative_strictMono w hw (Fin.succ_lt_succ_iff.mp hij)) j + +lemma stepFieldIncrement_reverse (k : ℕ) (h : Fin (k+1) → ℝ) (i : Fin k) : + stepFieldIncrement k h (k-1-i.val)=Real.sqrt (2*(h i.succ-h i.castSucc)) := by + have hi : k-1-i.val < k := by omega + have he : Fin.rev (⟨k-1-i.val,hi⟩ : Fin k)=i := by + apply Fin.ext + simp only [Fin.val_rev] + omega + rw [stepFieldIncrement,dite_eq_left hi,he] + +lemma fieldWord_eq (k : ℕ) (w h : Fin (k+1) → ℝ) : + List.ofFn (fun i => (fieldExponents w i,Real.sqrt (fieldVariances k h i)))= + (0,Real.sqrt (2*h 0))::cascadeHeatWord (stepFieldIncrement k h) k (stepCumulative w) := by + rw [List.ofFn_succ,cascadeHeatWord_eq_ofFn] + simp only [fieldExponents,fieldVariances,Fin.cases_zero,Fin.cases_succ,stepFieldIncrement_reverse] + +def sphericalHeatValue (n : ℕ) (l : List (ℝ×ℝ)) : ℝ := + gaussianBackward (stdGaussian (Spin (n+1))) l + (logSphericalExp n (Real.sqrt (n+1:ℕ))) 0/(n+1:ℕ)-(l.map fun c => c.2^2).sum/2 + +lemma finiteSphericalFieldValue_eq_heat {k : ℕ} (w h : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) (hh : Monotone h) (hh0 : 0 ≤ h 0) (n : ℕ) : + finiteSphericalFieldValue n k w h=sphericalHeatValue n + (List.ofFn fun i => (fieldExponents w i,Real.sqrt (fieldVariances k h i))) := by + have hs : ((List.ofFn fun i => (fieldExponents w i,Real.sqrt (fieldVariances k h i))).map + fun c => c.2^2).sum=2*h (Fin.last k) := by + rw [List.map_ofFn,List.sum_ofFn] + change (∑ i, (Real.sqrt (fieldVariances k h i))^2)=_ + simp only [Real.sq_sqrt (fieldVariances_nonneg k h hh hh0 _)] + exact fieldVariances_sum k h + have ha := finiteAmplitudeSphereValue_fieldAmplitudes n k w h hh0 + unfold finiteAmplitudeSphereValue at ha + rw [fieldAmplitudes_increment,fieldAmplitudes_last, + amplitudeSphereValue_eq_backward n k (stepFieldIncrement k h) (stepCumulative w) + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) + (stepCumulative_lt_one w hw hw1)] at ha + rw [sphericalHeatValue,hs,fieldWord_eq] + linarith + +def varianceLevels {k : ℕ} (v : Fin (k+1) → ℝ) (i : Fin (k+1)) : ℝ := + (∑ j, if j ≤ i then v j else 0)/2 + +lemma varianceLevels_zero {k : ℕ} (v : Fin (k+1) → ℝ) : varianceLevels v 0=v 0/2 := by + simp [varianceLevels] + +lemma varianceLevels_last {k : ℕ} (v : Fin (k+1) → ℝ) : + varianceLevels v (Fin.last k)=(∑ j, v j)/2 := by + simp [varianceLevels,Fin.le_last] + +lemma varianceLevels_increment {k : ℕ} (v : Fin (k+1) → ℝ) (i : Fin k) : + varianceLevels v i.succ-varianceLevels v i.castSucc=v i.succ/2 := by + unfold varianceLevels + rw [← sub_div,← Finset.sum_sub_distrib] + congr 1 + have he : (fun j : Fin (k+1) => (if j ≤ i.succ then v j else 0)- + (if j ≤ i.castSucc then v j else 0))=fun j => if j=i.succ then v j else 0 := by + funext j + by_cases h₁ : j ≤ i.castSucc + · have h₂ : j ≤ i.succ := h₁.trans (Fin.castSucc_le_succ i) + have h₃ : j ≠ i.succ := by intro e; subst j; simp [Fin.le_def,Fin.val_succ] at h₁ + simp [h₁,h₂,h₃] + · by_cases h₂ : j ≤ i.succ + · have hj : j=i.succ := by apply Fin.ext; simp only [Fin.le_def,Fin.val_castSucc,Fin.val_succ] at *; omega + simp [hj] + · have h₃ : j ≠ i.succ := by intro e; subst j; exact h₂ le_rfl + simp [h₁,h₂,h₃] + rw [he] + simp + +lemma fieldVariances_varianceLevels {k : ℕ} (v : Fin (k+1) → ℝ) : + fieldVariances k (varianceLevels v)=v := by + funext i + refine Fin.cases ?_ (fun i => ?_) i + · simp [fieldVariances,varianceLevels_zero]; ring + · simp [fieldVariances,varianceLevels_increment]; ring + +lemma varianceLevels_monotone {k : ℕ} (v : Fin (k+1) → ℝ) (hv : ∀ i, 0 ≤ v i) : + Monotone (varianceLevels v) := by + apply Fin.monotone_iff_le_succ.mpr + intro i + have h := varianceLevels_increment v i + linarith [hv i.succ] + +lemma varianceLevels_nonneg {k : ℕ} (v : Fin (k+1) → ℝ) (hv : ∀ i, 0 ≤ v i) + (i : Fin (k+1)) : 0 ≤ varianceLevels v i := by + apply div_nonneg _ (by norm_num) + apply Finset.sum_nonneg + intro j _ + split_ifs <;> first | exact hv j | rfl + +lemma gaussianGrid_spherical_last (n k : ℕ) (p v : Fin (k+2) → ℝ) + (hp : ∀ i, 0 ≤ p i) (hv : 0 ≤ v (Fin.last (k+1))) (hpl : p (Fin.last (k+1))=1) : + gaussianGrid (k+2) p v (logSphericalExp n (Real.sqrt (n+1:ℕ)))= + fun x => gaussianGrid (k+1) (fun i => p i.castSucc) (fun i => v i.castSucc) + (logSphericalExp n (Real.sqrt (n+1:ℕ))) x+(n+1:ℕ)*v (Fin.last (k+1))/2 := by + unfold gaussianGrid + rw [List.ofFn_succ_last,gaussianBackward_append] + simp only [gaussianBackward] + have he : gaussianEntropic (stdGaussian (Spin (n+1))) (p (Fin.last (k+1))) + (Real.sqrt (v (Fin.last (k+1)))) (logSphericalExp n (Real.sqrt (n+1:ℕ)))= + fun x => logSphericalExp n (Real.sqrt (n+1:ℕ)) x+(n+1:ℕ)*v (Fin.last (k+1))/2 := by + funext x + rw [hpl,gaussianEntropic_logSphericalExp_one,Real.sq_sqrt (by positivity),Real.sq_sqrt hv] + rw [he] + apply gaussianBackward_add_const _ (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) + intro c hc + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hc + exact hp i.castSucc + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FiniteFieldModel.lean b/lean/OAI/Probability/Perceptron/Variational/FiniteFieldModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..b9a4beb0aeeb00b7a0269cb0b7e1e1648e1e98ce --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FiniteFieldModel.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.PressureTransport + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +lemma integral_finite_label {I : Type*} [Fintype I] [MeasurableSpace I] + [MeasurableSingletonClass I] (a : Time → I) (ha : Measurable a) (F : I → ℝ) : + (∫ u, F (a u) ∂timeLaw)=∑ i, timeLaw.real (a ⁻¹' {i})*F i := by + classical + have he (u : Time) : F (a u)=∑ i, (if a u=i then F i else 0) := by simp + simp_rw [he] + rw [integral_finsetSum] + · apply Finset.sum_congr rfl + intro i _ + change (∫ u, (a ⁻¹' {i}).indicator (fun _ => F i) u ∂timeLaw)=_ + rw [integral_indicator (ha (measurableSet_singleton i)),integral_const] + simp only [Measure.restrict_apply_univ,smul_eq_mul,Measure.real] + · intro i _ + exact (integrable_const (F i)).indicator (ha (measurableSet_singleton i)) + +structure FiniteFieldModel (f : Time → ℝ) where + depth : ℕ + value : Fin (depth+1) → ℝ + label : Time → Fin (depth+1) + measurable_label : Measurable label + positive : ∀ i, 0 < timeLaw.real (label ⁻¹' {i}) + monotone_value : Monotone value + agrees : (fun u => value (label u)) =ᵐ[timeLaw] f + +def FiniteFieldModel.weight {f : Time → ℝ} (M : FiniteFieldModel f) (i : Fin (M.depth+1)) : ℝ := + timeLaw.real (M.label ⁻¹' {i}) + +lemma FiniteFieldModel.weight_pos {f : Time → ℝ} (M : FiniteFieldModel f) (i : Fin (M.depth+1)) : + 0 < M.weight i := M.positive i + +lemma FiniteFieldModel.weight_sum {f : Time → ℝ} (M : FiniteFieldModel f) : ∑ i, M.weight i=1 := by + have h := integral_finite_label M.label M.measurable_label (fun _ => 1) + simpa [FiniteFieldModel.weight] using h.symm + +lemma FiniteFieldModel.integral {f : Time → ℝ} (M : FiniteFieldModel f) (F : ℝ → ℝ) : + (∫ u, F (f u) ∂timeLaw)=∑ i, M.weight i*F (M.value i) := by + unfold FiniteFieldModel.weight + rw [← integral_finite_label M.label M.measurable_label (fun i => F (M.value i))] + apply integral_congr_ae + filter_upwards [M.agrees] with u hu + rw [hu] + +def FiniteFieldModel.coupling {f g : Time → ℝ} (M : FiniteFieldModel f) (N : FiniteFieldModel g) + (a : Fin (M.depth+1)×Fin (N.depth+1)) : ℝ := + timeLaw.real ((fun u => (M.label u,N.label u)) ⁻¹' {a}) + +lemma FiniteFieldModel.coupling_nonneg {f g : Time → ℝ} (M : FiniteFieldModel f) (N : FiniteFieldModel g) + (a : Fin (M.depth+1)×Fin (N.depth+1)) : 0 ≤ M.coupling N a := measureReal_nonneg + +lemma FiniteFieldModel.coupling_fst {f g : Time → ℝ} (M : FiniteFieldModel f) (N : FiniteFieldModel g) + (i : Fin (M.depth+1)) : ∑ j, M.coupling N (i,j)=M.weight i := by + classical + have h := integral_finite_label (fun u => (M.label u,N.label u)) + (M.measurable_label.prodMk N.measurable_label) (fun a => if a.1=i then 1 else 0) + have he := integral_finite_label M.label M.measurable_label (fun a => if a=i then 1 else 0) + simp only [FiniteFieldModel.coupling,FiniteFieldModel.weight] at * + simp only [Fintype.sum_prod_type,mul_ite,mul_one,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] at h he + rw [Finset.sum_comm] at h + simpa only [Finset.sum_ite_eq',Finset.mem_univ,ite_true] using h.symm.trans he + +lemma FiniteFieldModel.coupling_snd {f g : Time → ℝ} (M : FiniteFieldModel f) (N : FiniteFieldModel g) + (j : Fin (N.depth+1)) : ∑ i, M.coupling N (i,j)=N.weight j := by + classical + have h := integral_finite_label (fun u => (M.label u,N.label u)) + (M.measurable_label.prodMk N.measurable_label) (fun a => if a.2=j then 1 else 0) + have he := integral_finite_label N.label N.measurable_label (fun a => if a=j then 1 else 0) + simp only [FiniteFieldModel.coupling,FiniteFieldModel.weight] at * + simp only [Fintype.sum_prod_type,mul_ite,mul_one,mul_zero,Finset.sum_ite_eq',Finset.mem_univ,ite_true] at h he + exact h.symm.trans he + +lemma FiniteFieldModel.coupling_cost {f g : Time → ℝ} (M : FiniteFieldModel f) (N : FiniteFieldModel g) : + (∑ a, M.coupling N a*|M.value a.1-N.value a.2|)=∫ u, |f u-g u| ∂timeLaw := by + unfold FiniteFieldModel.coupling + rw [← integral_finite_label (fun u => (M.label u,N.label u)) + (M.measurable_label.prodMk N.measurable_label) (fun a => |M.value a.1-N.value a.2|)] + apply integral_congr_ae + filter_upwards [M.agrees,N.agrees] with u hu hv + rw [hu,hv] + +lemma FiniteFieldModel.values_mem {f : Time → ℝ} (M : FiniteFieldModel f) + {H : ℝ} (hf : ∀ᵐ u ∂timeLaw, f u ∈ Icc (0:ℝ) H) (i : Fin (M.depth+1)) : + M.value i ∈ Icc (0:ℝ) H := by + have hi : timeLaw (M.label ⁻¹' {i}) ≠ 0 := by + intro hi + have hp := M.positive i + change 0 < (timeLaw (M.label ⁻¹' {i})).toReal at hp + rw [hi] at hp + simp at hp + have hne : ∃ u, M.label u=i ∧ M.value (M.label u) ∈ Icc (0:ℝ) H := by + by_contra! hn + have hzero : ∀ᵐ u ∂timeLaw, u ∉ M.label ⁻¹' {i} := by + filter_upwards [M.agrees,hf] with u hu hv + intro hm + exact hn u hm (hu ▸ hv) + exact hi (by simpa only [not_not,Set.ofPred_mem_eq] using ae_iff.mp hzero) + obtain ⟨u,hu,hv⟩ := hne + simpa [hu] using hv + +def FiniteFieldModel.pressure {f : Time → ℝ} (M : FiniteFieldModel f) (n : ℕ) : ℝ := + finiteSphericalFieldValue n M.depth M.weight M.value + +lemma FiniteFieldModel.pressure_bound {f g : Time → ℝ} (M : FiniteFieldModel f) (N : FiniteFieldModel g) + {H : ℝ} (hH : 0 ≤ H) (hf : ∀ᵐ u ∂timeLaw, f u ∈ Icc (0:ℝ) H) + (hg : ∀ᵐ u ∂timeLaw, g u ∈ Icc (0:ℝ) H) (n : ℕ) : + |M.pressure n-N.pressure n| ≤ sphericalContinuityConstant n H*(∫ u, |f u-g u| ∂timeLaw) := by + have h := finiteSphericalFieldValue_coupling_bound M.weight M.value N.weight N.value (M.coupling N) + M.weight_pos M.weight_sum N.weight_pos N.weight_sum M.monotone_value (M.values_mem hf 0).1 + N.monotone_value (N.values_mem hg 0).1 (M.coupling_nonneg N) (M.coupling_fst N) (M.coupling_snd N) + H hH (M.values_mem hf _).2 (N.values_mem hg _).2 n + rwa [M.coupling_cost N] at h + +theorem exists_finiteFieldModel (f : Time → ℝ) (hf : Measurable f) + (hfin : (Set.range f).Finite) : Nonempty (FiniteFieldModel f) := by + classical + let S := hfin.toFinset + let T := S.filter (fun r => 0 < timeLaw.real (f ⁻¹' {r})) + have hae : ∀ᵐ u ∂timeLaw, f u ∈ T := by + have hnull : ∀ r ∈ S, ∀ᵐ u ∂timeLaw, f u=r → 0 < timeLaw.real (f ⁻¹' {r}) := by + intro r _hr + by_cases hp : 0 < timeLaw.real (f ⁻¹' {r}) + · exact ae_of_all _ (fun _ _ => hp) + · have hz : timeLaw (f ⁻¹' {r})=0 := by + have hz : (timeLaw (f ⁻¹' {r})).toReal=0 := le_antisymm (le_of_not_gt hp) ENNReal.toReal_nonneg + have hp := (ENNReal.toReal_eq_zero_iff _).mp hz + rcases hp with hp | hp + · exact hp + · exact (measure_ne_top _ _ hp).elim + have hnot : ∀ᵐ u ∂timeLaw, f u ≠ r := by + apply ae_iff.mpr + simpa only [Set.preimage,Set.mem_singleton_iff,not_not] using hz + filter_upwards [hnot] with u hu + exact fun h => (hu h).elim + have hall := (S.eventually_all).mpr hnull + filter_upwards [hall] with u hu + have hmem : f u ∈ S := hfin.mem_toFinset.mpr (mem_range_self u) + exact Finset.mem_filter.mpr ⟨hmem,hu (f u) hmem rfl⟩ + have hT : T.Nonempty := by + obtain ⟨u,hu⟩ := hae.exists + exact ⟨f u,hu⟩ + obtain ⟨d,hd⟩ := Nat.exists_eq_succ_of_ne_zero (Finset.card_ne_zero.mpr hT) + let e := T.orderIsoOfFin hd + let v : Fin (d+1) → ℝ := fun i => e i + have hv : StrictMono v := fun i j hij => e.strictMono hij + have hve : MeasurableEmbedding v := ⟨hv.injective,measurable_of_finite _,fun _ _ => (Set.toFinite _).measurableSet⟩ + let a : Time → Fin (d+1) := fun u => hve.invFun (f u) + have hag : (fun u => v (a u)) =ᵐ[timeLaw] f := by + filter_upwards [hae] with u hu + have hx : f u=v (e.symm ⟨f u,hu⟩) := congrArg Subtype.val (e.apply_symm_apply ⟨f u,hu⟩) |>.symm + dsimp only [a] + rw [hx,hve.leftInverse_invFun] + refine ⟨⟨d,v,a,hve.measurable_invFun.comp hf,?_,hv.monotone,hag⟩⟩ + intro i + have he : a ⁻¹' {i}=ᵐ[timeLaw] f ⁻¹' {v i} := by + filter_upwards [hag] with u hu + apply propext + change (a u=i) ↔ f u=v i + rw [← hu] + exact hv.injective.eq_iff.symm + change 0 < (timeLaw (a ⁻¹' {i})).toReal + rw [measure_congr he] + exact (Finset.mem_filter.mp (e i).2).2 + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FiniteGaussianRow.lean b/lean/OAI/Probability/Perceptron/Variational/FiniteGaussianRow.lean new file mode 100644 index 0000000000000000000000000000000000000000..98a65278916876d76fa42f2e3a129f13d0cb9976 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FiniteGaussianRow.lean @@ -0,0 +1,147 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedGaussianMarks + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators + +section +variable {K : Type*} [Fintype K] + +def finiteGaussianRow (key : K → ℕ) (a : K → ℝ) (i : ℕ) : ℝ := + ∑ k, if key k = i then a k else 0 + +def finiteGaussianRowLength (key : K → ℕ) : ℕ := + Finset.univ.sup key + 1 + +lemma finiteGaussianRow_key {key : K → ℕ} (hk : Function.Injective key) (a : K → ℝ) (k : K) : + finiteGaussianRow key a (key k) = a k := by + classical + simp [finiteGaussianRow,hk.eq_iff] + +lemma finiteGaussianRow_zero {key : K → ℕ} (a : K → ℝ) (i : ℕ) + (hi : ∀ k, key k ≠ i) : finiteGaussianRow key a i = 0 := by + simp [finiteGaussianRow,hi] + +lemma finiteGaussianRow_key_lt (key : K → ℕ) (k : K) : + key k < finiteGaussianRowLength key := + Nat.lt_succ_of_le (Finset.le_sup (Finset.mem_univ k)) + +lemma finiteGaussianRow_tail (key : K → ℕ) (a : K → ℝ) (i : ℕ) + (hi : finiteGaussianRowLength key ≤ i) : finiteGaussianRow key a i = 0 := by + apply finiteGaussianRow_zero a i + intro k + have h := finiteGaussianRow_key_lt key k + omega + +lemma finiteGaussianRow_sum {key : K → ℕ} (hk : Function.Injective key) (a : K → ℝ) + (F : ℕ → ℝ → ℝ) (hF : ∀ i, F i 0 = 0) : + (∑ i : Fin (finiteGaussianRowLength key), F i.val (finiteGaussianRow key a i.val)) = + ∑ k, F (key k) (a k) := by + classical + rw [Fin.sum_univ_eq_sum_range (fun i => F i (finiteGaussianRow key a i))] + have hs : Finset.univ.image key ⊆ Finset.range (finiteGaussianRowLength key) := by + intro i hi + obtain ⟨k,_,rfl⟩ := Finset.mem_image.mp hi + exact Finset.mem_range.mpr (finiteGaussianRow_key_lt key k) + rw [← Finset.sum_subset hs] + · rw [Finset.sum_image hk.injOn] + simp_rw [finiteGaussianRow_key hk] + · intro i hi hi' + rw [finiteGaussianRow_zero a i,hF] + intro k hki + exact hi' (Finset.mem_image.mpr ⟨k,Finset.mem_univ k,hki⟩) + +lemma finiteGaussianRow_field {key : K → ℕ} (hk : Function.Injective key) (a : K → ℝ) (g : ℕ → ℝ) : + (∑ i : Fin (finiteGaussianRowLength key), g i.val*finiteGaussianRow key a i.val) = + ∑ k, g (key k)*a k := + finiteGaussianRow_sum hk a (fun i x => g i*x) (fun _ => mul_zero _) + +lemma finiteGaussianRow_norm {key : K → ℕ} (hk : Function.Injective key) (a : K → ℝ) : + (∑ i : Fin (finiteGaussianRowLength key), finiteGaussianRow key a i.val^2) = ∑ k, a k^2 := + finiteGaussianRow_sum hk a (fun _ x => x^2) (fun _ => by norm_num) + +end +variable {I : Type} [Fintype I] + +def indexedGaussianRowKey (n : ℕ) (l : IndexedLeaf n) (p : Fin (n+1)×I) : ℕ := + countableCoordinate (indexedLeafSharedVertex n l p.1,p.2) + +lemma indexedGaussianRowKey_injective (n : ℕ) (l : IndexedLeaf n) : + Function.Injective (indexedGaussianRowKey (I := I) n l) := by + intro a b hab + have h := countableCoordinate_injective hab + exact Prod.ext (indexedLeafSharedVertex_injective n l (congrArg Prod.fst h)) (congrArg (fun q : SharedVertex n × I => q.2) h) + +variable {S : Type} [MeasurableSpace S] + +def indexedGaussianRow (n : ℕ) (B : Fin (n+1) → I → ℝ) (V : S → EuclideanSpace ℝ I) + (i : ℕ) (x : S×IndexedLeaf n) : ℝ := + finiteGaussianRow (indexedGaussianRowKey n x.2) (fun p => B p.1 p.2 * V x.1 p.2) i + +def indexedGaussianRowLength (n : ℕ) (x : S×IndexedLeaf n) : ℕ := + finiteGaussianRowLength (indexedGaussianRowKey (I := I) n x.2) + +lemma indexedGaussianRow_measurable (n : ℕ) (B : Fin (n+1) → I → ℝ) + {V : S → EuclideanSpace ℝ I} (hV : Measurable V) (i : ℕ) : + Measurable (indexedGaussianRow n B V i) := by + apply measurable_from_prod_countable_left + intro l + unfold indexedGaussianRow finiteGaussianRow + apply Finset.measurable_sum + intro p hp + by_cases hp : indexedGaussianRowKey n l p = i + · simp only [ite_eq_left hp] + fun_prop + · simp only [ite_eq_right hp] + exact measurable_const + +lemma indexedGaussianRowLength_measurable (n : ℕ) : + Measurable (indexedGaussianRowLength (S := S) (I := I) n) := + (measurable_of_countable (fun l : IndexedLeaf n => + finiteGaussianRowLength (indexedGaussianRowKey (I := I) n l))).comp measurable_snd + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_field (n : ℕ) (B : Fin (n+1) → I → ℝ) (V : S → EuclideanSpace ℝ I) + (g : ℕ → ℝ) (x : S×IndexedLeaf n) : + countableGaussianField (indexedGaussianRow n B V) (indexedGaussianRowLength (I := I) n) g x = + ∑ d : Fin (n+1), ∑ i : I, + g (countableCoordinate (indexedLeafSharedVertex n x.2 d,i))* (B d i * V x.1 i) := by + rw [countableGaussianField,gaussianPrefixField] + change (∑ i : Fin (finiteGaussianRowLength (indexedGaussianRowKey (I := I) n x.2)), + g i.val * finiteGaussianRow (indexedGaussianRowKey n x.2) (fun p => B p.1 p.2 * V x.1 p.2) i.val) = _ + rw [finiteGaussianRow_field (indexedGaussianRowKey_injective n x.2),Fintype.sum_prod_type] + rfl + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_norm (n : ℕ) (B : Fin (n+1) → I → ℝ) (V : S → EuclideanSpace ℝ I) + (x : S×IndexedLeaf n) : + (∑ i : Fin (indexedGaussianRowLength (I := I) n x), indexedGaussianRow n B V i.val x^2) = + ∑ i : I, (∑ d : Fin (n+1), B d i^2) * V x.1 i^2 := by + change (∑ i : Fin (finiteGaussianRowLength (indexedGaussianRowKey (I := I) n x.2)), + finiteGaussianRow (indexedGaussianRowKey n x.2) (fun p => B p.1 p.2 * V x.1 p.2) i.val^2) = _ + rw [finiteGaussianRow_norm (indexedGaussianRowKey_injective n x.2),Fintype.sum_prod_type,Finset.sum_comm] + apply Finset.sum_congr rfl + intro i hi + simp_rw [mul_pow] + rw [Finset.sum_mul] + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_norm_le (n : ℕ) (B : Fin (n+1) → I → ℝ) (V : S → EuclideanSpace ℝ I) + {C D : ℝ} (hC : ∀ i, (∑ d, B d i^2) ≤ C) (hC0 : 0 ≤ C) + (hD : ∀ x, (∑ i, V x i^2) ≤ D) (x : S×IndexedLeaf n) : + (∑ i : Fin (indexedGaussianRowLength (I := I) n x), indexedGaussianRow n B V i.val x^2) ≤ C*D := by + rw [indexedGaussianRow_norm] + calc + _ ≤ ∑ i, C*V x.1 i^2 := Finset.sum_le_sum fun i _ => mul_le_mul_of_nonneg_right (hC i) (sq_nonneg _) + _ = C*∑ i, V x.1 i^2 := (Finset.mul_sum _ _ _).symm + _ ≤ C*D := mul_le_mul_of_nonneg_left (hD x.1) hC0 + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FixedCount.lean b/lean/OAI/Probability/Perceptron/Variational/FixedCount.lean new file mode 100644 index 0000000000000000000000000000000000000000..02ab70b6f1e50e0741b68750985f622954bf2b28 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FixedCount.lean @@ -0,0 +1,201 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshThermalLaw +import OAI.Probability.Perceptron.Variational.DensityDerivative +import OAI.Probability.Perceptron.Cavity.FreshLogRatio + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev SourceCountData (n k : ℕ) := (ℕ→Fin (n+1)→ℝ) × (IndexedCascadeBase k × (ℕ→ℝ)) + +def sourceCountLaw (n k : ℕ) (z : Fin k→ℝ) : Measure (SourceCountData n k) := + (infinitePatternRowsLaw (n+1)).prod + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw) +instance (n k : ℕ) (z : Fin k→ℝ) : IsProbabilityMeasure (sourceCountLaw n k z) := by + unfold sourceCountLaw + infer_instance + +def sourceCountEmbedding (n M k : ℕ) (a : SourceCountData n k) : SourceBaseData n k × (ℕ→ℝ) := + ((M,(a.1,a.2.1)),a.2.2) + +lemma sourceCountEmbedding_measurable (n M k : ℕ) : Measurable (sourceCountEmbedding n M k) := by + unfold sourceCountEmbedding + fun_prop + +def sourceCountKernel (n k : ℕ) : Kernel (SourceCountData n k) (NormalizedSpin (n+1) × IndexedLeaf k) := + (sourceFullSpinLeafKernel n k).comap (sourceCountEmbedding n 0 k) (sourceCountEmbedding_measurable n 0 k) +instance (n k : ℕ) : IsMarkovKernel (sourceCountKernel n k) := by + unfold sourceCountKernel + infer_instance + +lemma sourceCountKernel_apply (n k : ℕ) (a : SourceCountData n k) : + sourceCountKernel n k a=enrichedIndexedBaseMeasure n k a.2.1 := by + simp only [sourceCountKernel,Kernel.comap_apply,sourceFullSpinLeafKernel,sourceCountEmbedding, + sourceSpinLeafKernel_apply] + +def sourceCountHamiltonian (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (a : SourceCountData n k) : NormalizedSpin (n+1) × IndexedLeaf k → ℝ := + sourceCouplingHamiltonian n k f p d h u (sourceCountEmbedding n M k a) + +lemma sourceCountHamiltonian_measurable (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) : + Measurable (Function.uncurry (sourceCountHamiltonian n M k f p d h u)) := by + have hm : Measurable (fun a : SourceCountData n k × (NormalizedSpin (n+1) × IndexedLeaf k) => + (sourceCountEmbedding n M k a.1,a.2)) := + ((sourceCountEmbedding_measurable n M k).comp measurable_fst).prodMk measurable_snd + have he : Function.uncurry (sourceCountHamiltonian n M k f p d h u) = + (Function.uncurry (sourceCouplingHamiltonian n k f p d h u)) ∘ + (fun a : SourceCountData n k × (NormalizedSpin (n+1) × IndexedLeaf k) => + (sourceCountEmbedding n M k a.1,a.2)) := rfl + rw [he] + exact Measurable.comp (sourceCouplingHamiltonian_measurable n k f p d h u) hm + +def sourceCountLog (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (a : SourceCountData n k) : ℝ := + Real.log (tiltPartition (sourceCountKernel n k a) (sourceCountHamiltonian n M k f p d h u a) 1) + +lemma sourceCountLog_ae (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 enrichedPoissonLog n k f p d u h (M,(a.1,sourceCascadeRealization n k p a.2)) := by + have hp : MeasurePreserving (fun a : SourceCountData n k => a.2.1) + (sourceCountLaw n k z) (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) := + measurePreserving_fst.comp measurePreserving_snd + filter_upwards [hp.quasiMeasurePreserving.ae ((indexedCascadeGood_ae k z hz0 hz1).and + (indexedLeafMeasure_regular k z hz hz0 hz1))] with a ha + rw [sourceCountLog,sourceCountKernel_apply] + exact enrichedIndexedHamiltonian_partition n M k f _ p d h u a.2.2 a.2.1 ha.1 ha.2 + +lemma sourceCountLog_memLp (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 Real.exp (sourceCountHamiltonian n M k f p d h u a x)) + (sourceCountKernel n k a) := by + have hm : MeasurableSet {a : SourceCountData n k | Integrable + (fun x => Real.exp (sourceCountHamiltonian n M k f p d h u a x)) (sourceCountKernel n k a)} := + measurableSet_kernel_integrable (κ := sourceCountKernel n k) + (f := fun a x => Real.exp (sourceCountHamiltonian n M k f p d h u a x)) + (sourceCountHamiltonian_measurable n M k f p d h u).exp.stronglyMeasurable + apply (Measure.ae_prod_iff_ae_ae hm).mpr + refine ae_of_all _ fun a => ?_ + have hm' : MeasurableSet {b : IndexedCascadeBase k × (ℕ→ℝ) | + Integrable (fun x => Real.exp (sourceCountHamiltonian n M k f p d h u (a,b) x)) + (sourceCountKernel n k (a,b))} := hm.preimage (measurable_const.prodMk measurable_id) + apply (Measure.ae_prod_iff_ae_ae hm').mpr + refine ae_of_all _ fun b => ?_ + have he := countableGaussian_coupling_exp_ae (enrichedIndexedBaseMeasure n k b) + (enrichedIndexedBoundedEnergy_measurable n M k f (patternPrefix (n+1) M a) h) + (sourceGaussianRow_measurable p d h u) (sourceGaussianRow_measurable p d h u) + (indexedGaussianRowLength_measurable k) + (enrichedIndexedBoundedEnergy_bound n M k f (patternPrefix (n+1) M a) h) + (sourceGaussianRow_square_bound p d h u hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l))) + (sourceGaussianRow_square_bound p d h u hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l))) 0 + simpa only [zero_mul,add_zero,sourceCountHamiltonian,sourceCountKernel_apply, + sourceCountEmbedding,sourceCouplingHamiltonian,enrichedIndexedHamiltonian] using he + +lemma sourceCountHamiltonian_succ (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (a : SourceCountData n k) + (x : NormalizedSpin (n+1) × IndexedLeaf k) : + sourceCountHamiltonian n (M+1) k f p d h u a x= + sourceCountHamiltonian n M k f p d h u a x+f (inner ℝ x.1.val (WithLp.toLp 2 (a.1 M))) := by + simp only [sourceCountHamiltonian,sourceCountEmbedding,sourceCouplingHamiltonian, + enrichedIndexedHamiltonian,countableGaussianHamiltonian,enrichedIndexedBoundedEnergy] + rw [normalizedPatternEnergy_prefix_exact] + ring + +lemma sourceCountLog_succ (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) : + ∀ᵐ a ∂sourceCountLaw n k z, + sourceCountLog n (M+1) k f p d h u a-sourceCountLog n M k f p d h u a= + Real.log (freshThermalPartition (sourceCountKernel n k) + (sourceCountHamiltonian n M k f p d h u) (fun x => x.1.val) f + (a,WithLp.toLp 2 (a.1 M))) := by + filter_upwards [sourceCount_exp_ae n M k f p d h hh0 hh u z] with a ha + unfold sourceCountLog + have hH := funext (sourceCountHamiltonian_succ n M k f p d h u a) + rw [hH] + exact tilt_log_add_bounded _ _ _ + (sourceCountHamiltonian_measurable n M k f p d h u).of_uncurry_left + (f.measurable.comp ((measurable_subtype_coe.comp measurable_fst).inner measurable_const)) + (fun x => f.norm_coe_le_norm _) ha + +lemma sourceCountFreshLog_prefix (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (a : SourceCountData n k) + (g : EuclideanSpace ℝ (Fin (n+1))) : + freshThermalPartition (sourceCountKernel n k) (sourceCountHamiltonian n M k f p d h u) + (fun x => x.1.val) f ((patternExtend (n+1) M (patternPrefix (n+1) M a.1),a.2),g)= + freshThermalPartition (sourceCountKernel n k) (sourceCountHamiltonian n M k f p d h u) + (fun x => x.1.val) f (a,g) := by + unfold freshThermalPartition + simp only [sourceCountKernel_apply,sourceCountHamiltonian,sourceCountEmbedding, + sourceCouplingHamiltonian,patternPrefix_extend] + +lemma sourceCountExpectedLog_fresh (n M k : ℕ) (f : ℝ →ᵇℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 x.1.val) f (a,g)) + ∂stdGaussian (EuclideanSpace ℝ (Fin (n+1))) ∂sourceCountLaw n k z := by + let FT := freshThermalPartition (sourceCountKernel n k) + (sourceCountHamiltonian n M k f p d h u) (fun x => x.1.val) f + have hm : Measurable FT := freshThermalPartition_measurable (sourceCountKernel n k) + (sourceCountHamiltonian n M k f p d h u) (sourceCountHamiltonian_measurable n M k f p d h u) + (fun x => x.1.val) (measurable_subtype_coe.comp measurable_fst) f + let F : ((Fin M→Fin (n+1)→ℝ) × EuclideanSpace ℝ (Fin (n+1))) × + (IndexedCascadeBase k × (ℕ→ℝ)) → ℝ := + fun a => Real.log (FT ((patternExtend (n+1) M a.1.1,a.2),a.1.2)) + have hF : Measurable F := hm.log.comp + ((((patternExtend_measurable (n+1) M).comp measurable_fst.fst).prodMk measurable_snd).prodMk measurable_fst.snd) + have he a g : F ((patternPrefix (n+1) M a.1,g),a.2)=Real.log (FT (a,g)) := + congrArg Real.log (sourceCountFreshLog_prefix n M k f p d h u a g) + have hi1 := (sourceCountLog_memLp n (M+1) k f p d h u z hz hz0 hz1).integrable (by norm_num) + have hi0 := (sourceCountLog_memLp n M k f p d h u z hz hz0 hz1).integrable (by norm_num) + have hi : Integrable (fun a => Real.log (FT (a,WithLp.toLp 2 (a.1 M)))) (sourceCountLaw n k z) := + (hi1.sub hi0).congr (sourceCountLog_succ n M k f p d h hh0 hh u z) + rw [sourceCountExpectedLog_eq n (M+1) k f p d h u z hz hz0 hz1, + sourceCountExpectedLog_eq n M k f p d h u z hz hz0 hz1,← integral_sub hi1 hi0, + integral_congr_ae (sourceCountLog_succ n M k f p d h hh0 hh u z)] + have hind := patternPrefix_fresh_product_integral + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod countableGaussianLaw) + (n+1) M F hF (hi.congr (ae_of_all _ fun a => (he a _).symm)) + simpa only [he,FT,sourceCountLaw] using hind + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FocusedRootProbability.lean b/lean/OAI/Probability/Perceptron/Variational/FocusedRootProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..6635ada1905aa0ecdbbbecab74664348671ae1c1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FocusedRootProbability.lean @@ -0,0 +1,203 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FocusedVisit +import OAI.Probability.Perceptron.Variational.DecoratedFocus + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +lemma indexedMarkedRoot_counted (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hj : Function.Injective (fun a => (indexedRootPoint ν step n z F p a).1)) + (ns : List (ℕ×(S×DecoratedCascade S n → ℝ≥0∞))) + (hn : ∀ nf ∈ ns, 1 ≤ nf.1) (hm : ∀ nf ∈ ns, Measurable nf.2) : + markedBlockProbability ns + ((markedStableCountKernel (indexedCascadeRealize (n+1) p.2)).map + (fun t : ℝ×(S×DecoratedCascade S n) => + (t.1+decoratedCenteredRoot ν step n z F (p.1,t.2),t.2))) + (Fin.elim0 : Fin 0 → ℝ) = + countedBlockProbability (indexedRootPoint ν step n z F p) ns (Fin.elim0 : Fin 0 → ℝ) := by + rw [indexedCascadeGood_countKernel hb] + have hc : Measurable (fun t : ℝ×(S×DecoratedCascade S n) => + (t.1+decoratedCenteredRoot ν step n z F (p.1,t.2),t.2)) := + (measurable_fst.add ((decoratedCenteredRoot_measurable ν step hs n z F hF).comp + (measurable_const.prodMk measurable_snd))).prodMk measurable_snd + have he : (indexedCascadeRealize (n+1) p.2).map + (fun t : ℝ×(S×DecoratedCascade S n) => + (t.1+decoratedCenteredRoot ν step n z F (p.1,t.2),t.2)) = + Measure.count.map (indexedRootPoint ν step n z F p) := by + unfold indexedCascadeRealize + rw [indexedPoissonMeasure_eq_map_count,Measure.map_map hc (measurable_of_countable _)] + rfl + rw [he] + exact markedBlockProbability_count_map _ (measurable_of_countable _) hj ns hn hm (Fin.elim0 : Fin 0 → ℝ) + +lemma indexedFocusedRoot_embeddings (ν : ProbabilityMeasure S) (step : X×S → X) + (hst : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (hj : Function.Injective (fun a => (indexedRootPoint ν step n z F p a).1)) + (d : ℕ) (s : CascadeVisitShape n) (ss : List (CascadeVisitShape n)) + (hv : CascadeVisitShape.Valid (n+1) (s::ss)) : + decoratedFocusedProbability ν step (n+1) z F (d+1) (s::ss) + (p.1,indexedCascadeRealize (n+1) p.2) = + ∑' a : Fin (ss.length+1) ↪ (Σ i, Fin ((p.2.1 i).1)), + (indexedBranchProbability step n F p (a 0)) ^ (cascadeVisitCount n s+1) * + decoratedFocusedProbability ν step n (fun i => z i.succ) (fun i => F i.succ) d s + ((indexedChildPoint step n p (a 0).1 (a 0).2.val).1, + indexedCascadeRealize n (indexedChildPoint step n p (a 0).1 (a 0).2.val).2) * + ∏ i : Fin ss.length, + (indexedBranchProbability step n F p (a i.succ)) ^ cascadeVisitCount n ss[i] * + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) + (trivialDecoratedShape X n ss[i]) + ((indexedChildPoint step n p (a i.succ).1 (a i.succ).2.val).1, + indexedCascadeRealize n (indexedChildPoint step n p (a i.succ).1 (a i.succ).2.val).2) := by + let ns : List (ℕ×(S×DecoratedCascade S n → ℝ≥0∞)) := + (cascadeVisitCount n s+1,fun t => decoratedFocusedProbability ν step n + (fun i => z i.succ) (fun i => F i.succ) d s (step (p.1,t.1),t.2)) :: + ss.map (fun t => (cascadeVisitCount n t,fun u => decoratedShapeProbability ν step n + (fun i => z i.succ) (fun i => F i.succ) (trivialDecoratedShape X n t) (step (p.1,u.1),u.2))) + have hn : ∀ nf ∈ ns, 1 ≤ nf.1 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | ht + · simp + · obtain ⟨t,hmem,rfl⟩ := List.mem_map.mp ht + exact cascadeVisitCount_pos n t (hv.2 t (by simp [hmem])) + have hm : ∀ nf ∈ ns, Measurable nf.2 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | ht + · exact (decoratedFocusedProbability_measurable ν step hst n _ _ + (fun i => hF i.succ) d s (hv.2 s (by simp))).comp + ((hst.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd) + · obtain ⟨t,hmem,rfl⟩ := List.mem_map.mp ht + exact (decoratedShapeProbability_measurable ν step hst n _ _ (fun i => hF i.succ) _ + (trivialDecoratedShape_valid X n t (hv.2 t (by simp [hmem])))).comp + ((hst.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd) + rw [decoratedFocusedProbability, indexedMarkedRoot_counted ν step hst n z F hF p hb hj ns hn hm, + countedBlockProbability_embeddings _ hj] + simp only [indexedRootPoint_probability ν step hst n z F hF p hb hc] + rw [tsum_embedding_cast (show ns.length = ss.length+1 from by simp [ns]) + (fun i a => (indexedBranchProbability step n F p a)^ns[i].1 * + ns[i].2 (indexedRootPoint ν step n z F p a).2)] + simp only [ns,Fin.prod_univ_succ,Fin.getElem_fin,Fin.val_cast,Fin.val_zero,Fin.val_succ, + List.getElem_cons_zero,List.getElem_cons_succ,List.getElem_map] + rfl + + +lemma indexedFocusedVisit_eq_shape (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (d : ℕ) (hd : d ≤ n) (s : CascadeVisitShape n) (hv : s.Valid n) (x : X) : + ∀ᵐ p ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)), + indexedFocusedVisit step n F d s hv (x,p) = + decoratedFocusedProbability ν step n z F d s (x,indexedCascadeRealize n p) := by + induction d generalizing n x with + | zero => + filter_upwards [indexedTiltedTotal_regular ν step hs n z hz hz0 hz1 F hF hI hM x, + indexedShapeVisit_eq_shape ν step hs n z hz hz0 hz1 F hF hI hM s hv x] with p hp he + rw [indexedFocusedVisit_zero step n F s hv (x,p) hp] + cases n <;> simpa only [decoratedFocusedProbability] using he + | succ d ih => + cases n with + | zero => omega + | succ n => + cases s with + | nil => exact (hv.1 rfl).elim + | cons s ss => + have hzt : StrictMono (fun i : Fin n => z i.succ) := + fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij) + have hvs : s.Valid n := hv.2 s (by simp) + have hh := indexedCascade_ae_children ν step hs n z + (fun p => indexedFocusedVisit step n (fun j => F j.succ) d s hvs p = + decoratedFocusedProbability ν step n (fun j => z j.succ) (fun j => F j.succ) d s + (p.1,indexedCascadeRealize n p.2)) + (measurableSet_eq_fun (indexedFocusedVisit_measurable step hs n _ + (fun j => hF j.succ) d s hvs) + ((decoratedFocusedProbability_measurable ν step hs n _ _ (fun j => hF j.succ) d s hvs).comp + (measurable_fst.prodMk ((indexedCascadeRealize_measurable n).comp measurable_snd)))) + (fun y => ih n _ hzt (fun j => hz0 j.succ) (fun j => hz1 j.succ) _ (fun j => hF j.succ) + (fun j => hI j.succ) (fun j => hM j.succ) (by omega) s hvs y) x + have he : ∀ i : Fin ss.length, ∀ᵐ p ∂ + (indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))).prod + (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))), + ∀ a b, indexedShapeVisit step n (fun j => F j.succ) ss[i] + (indexedChildPoint step n (x,p) a b) = + decoratedShapeProbability ν step n (fun j => z j.succ) (fun j => F j.succ) + (trivialDecoratedShape X n ss[i]) + ((indexedChildPoint step n (x,p) a b).1, + indexedCascadeRealize n (indexedChildPoint step n (x,p) a b).2) := by + intro i + have hvi : ss[i].Valid n := hv.2 _ (List.mem_cons_of_mem _ (List.getElem_mem i.isLt)) + exact indexedCascade_ae_children ν step hs n z + (fun p => indexedShapeVisit step n (fun j => F j.succ) ss[i] p = + decoratedShapeProbability ν step n (fun j => z j.succ) (fun j => F j.succ) + (trivialDecoratedShape X n ss[i]) (p.1,indexedCascadeRealize n p.2)) + (measurableSet_eq_fun (indexedShapeVisit_measurable hs n _ (fun j => hF j.succ) ss[i]) + ((decoratedShapeProbability_measurable ν step hs n _ _ (fun j => hF j.succ) _ + (trivialDecoratedShape_valid X n ss[i] hvi)).comp + (measurable_fst.prodMk ((indexedCascadeRealize_measurable n).comp measurable_snd)))) + (fun y => indexedShapeVisit_eq_shape ν step hs n _ hzt (fun j => hz0 j.succ) + (fun j => hz1 j.succ) _ (fun j => hF j.succ) (fun j => hI j.succ) + (fun j => hM j.succ) ss[i] hvi y) x + have hc := indexedCascade_ae_children ν step hs n z + (fun p => 0 < (indexedTiltedTotal step n (fun j => F j.succ) p).toReal) + (measurableSet_lt measurable_const ((indexedTiltedTotal_measurable hs n _ (fun j => hF j.succ)).ennreal_toReal)) + (fun y => indexedTiltedTotal_regular ν step hs n _ hzt (fun j => hz0 j.succ) (fun j => hz1 j.succ) + _ (fun j => hF j.succ) (fun j => hI j.succ) (fun j => hM j.succ) y) x + have hj := indexedCenteredRoot_simple ν step hs n z hz hz0 hz1 F hF hI hM x + have hb := (measurePreserving_fst + (μ := (indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1)))) + (ν := (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))))).quasiMeasurePreserving.ae + (indexedCascadeGood_ae (n+1) z hz0 hz1) + filter_upwards [hh,ae_all_iff.mpr he,hc,hj,hb] with p hh he hc hj hb + rw [indexedFocusedVisit_succ step n F d s ss hv (x,p) hc, + indexedFocusedRoot_embeddings ν step hs n z F hF (x,p) hb hc hj d s ss hv] + apply tsum_congr + intro a + apply congrArg₂ (· * ·) + · exact congrArg (fun c : ℝ≥0∞ => _ * c) (hh (a 0).1 (a 0).2.val) + · apply Finset.prod_congr rfl + intro i _hi + exact congrArg (fun c : ℝ≥0∞ => _ * c) (he i (a i.succ).1 (a i.succ).2.val) + +theorem indexedFocusedVisit_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (d : ℕ) (hd : d ≤ n) (s : CascadeVisitShape n) (hv : s.Valid n) (x : X) : + (∫⁻ p, indexedFocusedVisit step n F d s hv (x,p) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) = + cascadeShapeLikelihood n z 0 s * + ENNReal.ofReal (focusedShapeNumerator n z 0 d s/(cascadeVisitCount n s:ℝ)) := by + rw [lintegral_congr_ae (indexedFocusedVisit_eq_shape ν step hs n z hz hz0 hz1 F hF hI hM d hd s hv x)] + have hm : Measurable (fun η : DecoratedCascade S n => + decoratedFocusedProbability ν step n z F d s (x,η)) := + (decoratedFocusedProbability_measurable ν step hs n z F hF d s hv).comp + (measurable_const.prodMk measurable_id) + rw [← lintegral_map hm (indexedCascadeRealize_measurable n),indexedCascadeRealize_law ν n z, + ← decoratedBiasedLaw_zero ν step n z F x] + simpa only [sub_zero] using decoratedFocusedProbability_integral ν step hs n z hz hz0 hz1 F hF hI hM + 0 (by norm_num) hz0 d hd s hv x + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FocusedSampleLaw.lean b/lean/OAI/Probability/Perceptron/Variational/FocusedSampleLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..a72c449f985ae8af0bde55600b46040f06250726 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FocusedSampleLaw.lean @@ -0,0 +1,136 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FocusedRootProbability + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology + +def indexedSampleFocused (n d : ℕ) (s : CascadeVisitShape n) (hs : s.Valid n) + (b : IndexedCascadeBase n) : ℝ≥0∞ := + ∑' xs : CascadeShapeReplicas n s → IndexedLeaf n, + ((∏ i, (indexedLeafProbability n b) {xs i}) * + if CascadeShapeMatches n s xs then 1 else 0) * + ∑' l : IndexedLeaf n, (indexedLeafProbability n b) {l} * + if d ≤ (indexedCommonDepth n (xs (cascadeShapeFocus n s hs)) l).val then 1 else 0 + +lemma indexedSampleFocused_measurable (n d : ℕ) (s : CascadeVisitShape n) (hs : s.Valid n) : + Measurable (indexedSampleFocused n d s hs) := by + unfold indexedSampleFocused + refine Measurable.tsum (fun xs => ?_) + exact ((Finset.measurable_prod Finset.univ (fun i _ => + (Measure.measurable_coe (measurableSet_singleton (xs i))).comp + (indexedLeafProbability_measurable n))).mul_const _).mul + (Measurable.tsum (fun l => ((Measure.measurable_coe (measurableSet_singleton l)).comp + (indexedLeafProbability_measurable n)).mul_const _)) + +lemma indexedFocusedVisit_zero_eq_sample {X S : Type} [MeasurableSpace X] + [MeasurableSpace S] [Nonempty S] (step : X×S → X) (n d : ℕ) + (s : CascadeVisitShape n) (hs : s.Valid n) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) + (hp : 0 < ((indexedLeafMeasure n p.2.1) univ).toReal) : + indexedFocusedVisit step n (fun _ _ => 0) d s hs p = indexedSampleFocused n d s hs p.2.1 := by + simp only [indexedFocusedVisit,indexedClassMass,indexedSampleFocused, + indexedTiltedProbability_zero step n p hp] + +lemma indexedSampleFocused_eq_measure (n d : ℕ) (s : CascadeVisitShape n) (hs : s.Valid n) + (b : IndexedCascadeBase n) : + indexedSampleFocused n d s hs b = + ((Measure.pi (fun _ : CascadeShapeReplicas n s => indexedLeafProbability n b)).prod + (indexedLeafProbability n b)) + {p | CascadeShapeMatches n s p.1 ∧ + d ≤ (indexedCommonDepth n (p.1 (cascadeShapeFocus n s hs)) p.2).val} := by + rw [← lintegral_indicator_one ((Set.to_countable _).measurableSet),lintegral_countable', + ENNReal.tsum_prod'] + unfold indexedSampleFocused + apply tsum_congr + intro xs + rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro l + rw [← Set.singleton_prod_singleton,Measure.prod_prod,Measure.pi_singleton] + simp only [Set.indicator,Set.mem_ofPred_eq,Pi.one_apply] + split_ifs <;> simp_all + +theorem indexedSampleFocused_integral (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (d : ℕ) (hd : d ≤ n) (s : CascadeVisitShape n) (hs : s.Valid n) : + (∫⁻ b, indexedSampleFocused n d s hs b ∂indexedCascadeBaseLaw n z) = + cascadeShapeLikelihood n z 0 s * + ENNReal.ofReal (focusedShapeNumerator n z 0 d s/(cascadeVisitCount n s:ℝ)) := by + let ν : ProbabilityMeasure Unit := ⟨Measure.dirac (), inferInstance⟩ + let step : Unit×Unit → Unit := fun _ => () + let B := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)) + let M := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks Unit n)) + have he := indexedFocusedVisit_integral ν step measurable_const n z hz hz0 hz1 + (fun _ _ => 0) (fun _ => measurable_const) + (by intro i x; simp only [mul_zero, Real.exp_zero]; exact integrable_const 1) + (by intro i x; simp) d hd s hs () + have ha : ∀ᵐ p ∂B.prod M, + indexedFocusedVisit step n (fun _ _ => 0) d s hs ((),p) = indexedSampleFocused n d s hs p.1 := by + filter_upwards [(measurePreserving_fst (μ := B) (ν := M)).quasiMeasurePreserving.ae + (indexedLeafMeasure_regular n z hz hz0 hz1)] with p hp + exact indexedFocusedVisit_zero_eq_sample step n d s hs ((),p) hp + rw [lintegral_congr_ae ha] at he + have hprod := lintegral_prod (μ := B) (ν := M) + (fun p : IndexedCascadeBase n×IndexedCascadeMarks Unit n => indexedSampleFocused n d s hs p.1) + ((indexedSampleFocused_measurable n d s hs).comp measurable_fst).aemeasurable + rw [hprod] at he + simpa only [lintegral_const,measure_univ,mul_one,B,M] using he + +def cascadeFocusCount (n d : ℕ) (s : CascadeVisitShape n) (hs : s.Valid n) : ℝ := + ∑ i : CascadeShapeReplicas n s, + if d ≤ (indexedCommonDepth n (cascadeShapeLeaves n s (cascadeShapeFocus n s hs)) + (cascadeShapeLeaves n s i)).val then 1 else 0 + +lemma cascadeFocusCount_zero (n : ℕ) (s : CascadeVisitShape n) (hs : s.Valid n) : + cascadeFocusCount n 0 s hs = cascadeVisitCount n s := by + simp [cascadeFocusCount,cascadeShapeReplicas_card] + +lemma cascadeFocusCount_succ (n d : ℕ) (s : CascadeVisitShape n) + (ss : List (CascadeVisitShape n)) (hs : CascadeVisitShape.Valid (n+1) (s::ss)) : + cascadeFocusCount (n+1) (d+1) (s::ss) hs = + cascadeFocusCount n d s (hs.2 s (by simp)) := by + classical + unfold cascadeFocusCount + change (∑ i : (Σ i : Fin (ss.length+1), CascadeShapeReplicas n (s::ss)[i]), _) = _ + rw [Fintype.sum_sigma] + rw [Finset.sum_eq_single 0] + · apply Finset.sum_congr rfl + intro i _hi + simp only [cascadeShapeFocus_cons,cascadeShapeLeaves,indexedCommonDepth, + and_self,↓reduceIte,Fin.val_succ,Nat.add_le_add_iff_right] + rfl + · intro i _hi hne + apply Finset.sum_eq_zero + intro j _hj + have hn : (0:ℕ) ≠ i.val := fun h => hne (Fin.ext h.symm) + simp only [cascadeShapeFocus_cons,cascadeShapeLeaves,indexedCommonDepth, + Fin.val_zero,hn,false_and,↓reduceIte,Nat.not_add_one_le_zero] + · simp + +lemma focusedShapeNumerator_eq_count (n : ℕ) (z : Fin n → ℝ) (a : ℝ) + (d : ℕ) (hd : d ≤ n) (s : CascadeVisitShape n) (hs : s.Valid n) : + focusedShapeNumerator n z a d s = cascadeFocusCount n d s hs - + (if h : d = 0 then a else z ⟨d-1,by omega⟩) := by + induction d generalizing n a with + | zero => simp [focusedShapeNumerator,cascadeFocusCount_zero] + | succ d ih => + cases n with + | zero => omega + | succ n => + cases s with + | nil => exact (hs.1 rfl).elim + | cons s ss => + rw [focusedShapeNumerator,cascadeFocusCount_succ] + rw [ih n (fun i => z i.succ) (z 0) (by omega) s (hs.2 s (by simp))] + cases d with + | zero => simp + | succ d => simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FocusedShapeProbability.lean b/lean/OAI/Probability/Perceptron/Variational/FocusedShapeProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..31ee950557bb44bba70cd25748916a4ea72f4e21 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FocusedShapeProbability.lean @@ -0,0 +1,435 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.WeightedTotalBiasedLaw + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy + +lemma cascadeBiasedLaw_zero (n : ℕ) (z : Fin n → ℝ) : + cascadeBiasedLaw n z 0 = (cascadeLaw n z : Measure (StableCascade n)) := by + simp [cascadeBiasedLaw,normalizedMeasure] + +lemma stableBlockProbability_eppf_value {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) + (ns : List ℕ) (hne : ns ≠ []) (hn : ∀ n ∈ ns, 1 ≤ n) : + (∫⁻ η, stableBlockProbability ns η (Fin.elim0 : Fin 0 → ℝ) ∂stableTotalBiasedLaw a b) = + ENNReal.ofReal (stableEppfValue a b (ns.map (fun n : ℕ => (n:ℝ)))) := by + simpa only [stableEppfValue,List.length_map,List.map_map,Function.comp_def] using + stableBlockProbability_eppf hb hb1 ha ns hne hn (Fin.elim0 : Fin 0 → ℝ) + +lemma cascadeShapeProbability_law (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (s : CascadeVisitShape n) (hs : CascadeVisitShape.Valid n s) : + (∫⁻ η, cascadeShapeProbability n z s η ∂(cascadeLaw n z : Measure (StableCascade n))) = + cascadeShapeLikelihood n z 0 s := by + rw [← cascadeBiasedLaw_zero n z] + exact cascadeShapeProbability_integral n z hz hz0 hz1 0 hz0 s hs + +def focusedShapeProbability : (n : ℕ) → (Fin n → ℝ) → ℕ → CascadeVisitShape n → StableCascade n → ℝ≥0∞ + | n, z, 0, s, η => cascadeShapeProbability n z s η + | 0, _, _+1, _, _ => 0 + | _+1, _, _+1, [], _ => 0 + | n+1, z, d+1, s::ss, η => markedBlockProbability + ((cascadeVisitCount n s+1,focusedShapeProbability n (fun i => z i.succ) d s):: + ss.map (fun s => (cascadeVisitCount n s,cascadeShapeProbability n (fun i => z i.succ) s))) + (η.map (logMarkShift (centeredLogMark (cascadeLaw n (fun i => z i.succ)) (z 0) + (fun C => Real.log (cascadeTotal n C))))) (Fin.elim0 : Fin 0 → ℝ) + +def focusedShapeNumerator : (n : ℕ) → (Fin n → ℝ) → ℝ → ℕ → CascadeVisitShape n → ℝ + | n, _, a, 0, s => (cascadeVisitCount n s : ℝ)-a + | 0, _, _, _+1, _ => 0 + | _+1, _, _, _+1, [] => 0 + | n+1, z, _, d+1, s::_ => focusedShapeNumerator n (fun i => z i.succ) (z 0) d s + +lemma focusedShapeProbability_cons {n d : ℕ} (z : Fin (n+1) → ℝ) + (s : CascadeVisitShape n) (ss : List (CascadeVisitShape n)) : + focusedShapeProbability (n+1) z (d+1) (s::ss) = + (fun η : Measure (ℝ×StableCascade n) => markedBlockProbability + ((cascadeVisitCount n s+1,focusedShapeProbability n (fun i => z i.succ) d s):: + ss.map (fun t => (cascadeVisitCount n t,cascadeShapeProbability n (fun i => z i.succ) t))) + (η.map (logMarkShift (centeredLogMark (cascadeLaw n (fun i => z i.succ)) (z 0) + (fun C => Real.log (cascadeTotal n C))))) (Fin.elim0 : Fin 0 → ℝ)) := by + funext η + rfl + +lemma markedBlockProbability_map_measurable {S : Type*} [MeasurableSpace S] + [Nonempty S] (ns : List (ℕ × (S → ℝ≥0∞))) + (hm : ∀ nf ∈ ns, Measurable nf.2) (F : ℝ×S → ℝ×S) (hF : Measurable F) : + Measurable (fun η : Measure (ℝ×S) => + markedBlockProbability ns (η.map F) (Fin.elim0 : Fin 0 → ℝ)) := by + exact (markedBlockProbability_measurable ns hm 0).comp + ((Measure.measurable_map _ hF).prodMk measurable_const) + +lemma focusedShapeProbability_measurable (n : ℕ) (z : Fin n → ℝ) (d : ℕ) (s : CascadeVisitShape n) : + Measurable (focusedShapeProbability n z d s) := by + induction n generalizing d with + | zero => cases d <;> exact measurable_const + | succ n ih => + cases d with + | zero => exact cascadeShapeProbability_measurable (n+1) z s + | succ d => + cases s with + | nil => exact measurable_const + | cons s ss => + have hm : ∀ nf ∈ (cascadeVisitCount n s+1,focusedShapeProbability n (fun i => z i.succ) d s):: + ss.map (fun s => (cascadeVisitCount n s,cascadeShapeProbability n (fun i => z i.succ) s)), + Measurable nf.2 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | hh + · exact ih (fun i => z i.succ) d s + · obtain ⟨s',_,rfl⟩ := List.mem_map.mp hh + exact cascadeShapeProbability_measurable n (fun i => z i.succ) s' + have hF := logMarkShift_measurable (centeredLogMark_measurable + (cascadeLaw n (fun i => z i.succ)) (z 0) (cascadeTotal_measurable n).log) + let ns := (cascadeVisitCount n s+1,focusedShapeProbability n (fun i => z i.succ) d s):: + ss.map (fun t => (cascadeVisitCount n t,cascadeShapeProbability n (fun i => z i.succ) t)) + rw [focusedShapeProbability_cons] + exact markedBlockProbability_map_measurable ns hm _ hF + +lemma focusedShapeNumerator_pos (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (a : ℝ) (ha : a < 1) + (d : ℕ) (hd : d ≤ n) (s : CascadeVisitShape n) (hs : CascadeVisitShape.Valid n s) : + 0 < focusedShapeNumerator n z a d s := by + induction n generalizing d a with + | zero => + have hd0 : d = 0 := Nat.eq_zero_of_le_zero hd + subst d + change 0 < (cascadeVisitCount 0 s : ℝ)-a + have hr : (1:ℝ) ≤ cascadeVisitCount 0 s := by exact_mod_cast cascadeVisitCount_pos 0 s hs + linarith + | succ n ih => + cases d with + | zero => + change 0 < (cascadeVisitCount (n+1) s : ℝ)-a + have hr : (1:ℝ) ≤ cascadeVisitCount (n+1) s := by exact_mod_cast cascadeVisitCount_pos (n+1) s hs + linarith + | succ d => + obtain ⟨hne,hs⟩ := hs + cases s with + | nil => exact (hne rfl).elim + | cons s ss => + exact ih (fun i => z i.succ) (fun i j h => hz (Fin.succ_lt_succ_iff.mpr h)) + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (z 0) (hz1 0) d (by omega) s (hs s (by simp)) + +theorem focusedShapeProbability_integral (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (a : ℝ) (ha1 : a < 1) (ha : ∀ i, a < z i) + (d : ℕ) (hd : d ≤ n) (s : CascadeVisitShape n) (hs : CascadeVisitShape.Valid n s) : + (∫⁻ η, focusedShapeProbability n z d s η ∂cascadeBiasedLaw n z a) = + cascadeShapeLikelihood n z a s * + ENNReal.ofReal (focusedShapeNumerator n z a d s/((cascadeVisitCount n s:ℝ)-a)) := by + induction d generalizing n a with + | zero => + have hc : 0 < (cascadeVisitCount n s:ℝ)-a := by + have hh : (1:ℝ) ≤ cascadeVisitCount n s := by exact_mod_cast cascadeVisitCount_pos n s hs + linarith + simp only [focusedShapeProbability,focusedShapeNumerator,div_self hc.ne',ENNReal.ofReal_one,mul_one] + exact cascadeShapeProbability_integral n z hz hz0 hz1 a ha s hs + | succ d ih => + cases n with + | zero => omega + | succ n => + obtain ⟨hne,hs⟩ := hs + cases s with + | nil => exact (hne rfl).elim + | cons s ss => + have htail : StrictMono (fun i : Fin n => z i.succ) := fun i j h => hz (Fin.succ_lt_succ_iff.mpr h) + have hsz := hs s (by simp) + have hcount : (1:ℝ) ≤ cascadeVisitCount n s := by exact_mod_cast cascadeVisitCount_pos n s hsz + have hrb : 0 < (cascadeVisitCount n s:ℝ)-z 0 := by linarith [hz1 0] + have hwhole : 0 < (cascadeVisitCount (n+1) (s::ss):ℝ)-a := by + have hh : (1:ℝ) ≤ cascadeVisitCount (n+1) (s::ss) := by + exact_mod_cast cascadeVisitCount_pos (n+1) (s::ss) ⟨by simp,hs⟩ + linarith + have hc : (cascadeVisitCount (n+1) (s::ss):ℝ)-a = + (cascadeVisitCount n s:ℝ)+(ss.map (fun t => (cascadeVisitCount n t:ℝ))).sum-a := by + simp only [cascadeVisitCount,List.map_cons,List.sum_cons,Nat.cast_add,Nat.cast_list_sum, + List.map_map,Function.comp_def] + have hnp := focusedShapeNumerator_pos n (fun i => z i.succ) htail + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (z 0) (hz1 0) d (by omega) s hsz + have hchild := ih n (fun i => z i.succ) htail (fun i => hz0 i.succ) (fun i => hz1 i.succ) + (z 0) (hz1 0) (fun i => hz (by simp)) (by omega) s hsz + have hprod : (ss.map (fun t => ∫⁻ C, cascadeShapeProbability n (fun i => z i.succ) t C + ∂cascadeBiasedLaw n (fun i => z i.succ) (z 0))).prod = + (ss.map (cascadeShapeLikelihood n (fun i => z i.succ) (z 0))).prod := by + congr 1 + apply List.map_congr_left + intro t ht + exact cascadeShapeProbability_integral n (fun i => z i.succ) htail + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (z 0) (fun i => hz (by simp)) t (hs t (by simp [ht])) + let ns := (cascadeVisitCount n s+1,focusedShapeProbability n (fun i => z i.succ) d s):: + ss.map (fun t => (cascadeVisitCount n t,cascadeShapeProbability n (fun i => z i.succ) t)) + have hn : ∀ nf ∈ ns, 1 ≤ nf.1 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | hh + · simp + · obtain ⟨t,ht,rfl⟩ := List.mem_map.mp hh + exact cascadeVisitCount_pos n t (hs t (by simp [ht])) + have hm : ∀ nf ∈ ns, Measurable nf.2 := by + intro nf hnf + rcases List.mem_cons.mp hnf with rfl | hh + · exact focusedShapeProbability_measurable n (fun i => z i.succ) d s + · obtain ⟨t,_,rfl⟩ := List.mem_map.mp hh + exact cascadeShapeProbability_measurable n (fun i => z i.succ) t + change (∫⁻ η, markedBlockProbability ns _ _ ∂cascadeBiasedLaw (n+1) z a) = _ + rw [cascadeRootBlock_factor z hz hz0 hz1 (ha 0) ns (by simp [ns]) hn hm, + stableBlockProbability_eppf_value (hz0 0) (hz1 0) (ha 0) (ns.map Prod.fst) + (by simp [ns]) (by intro r hr; obtain ⟨nf,hmem,rfl⟩ := List.mem_map.mp hr; exact hn nf hmem)] + simp only [ns,List.map_cons,List.prod_cons,List.map_map,Function.comp_def,Nat.cast_add,Nat.cast_one] + rw [hchild,hprod,stableEppfValue_join (by linarith [hz1 0]) _ (by rw [← hc]; exact hwhole), + ENNReal.ofReal_mul (div_nonneg hrb.le (by rw [← hc]; exact hwhole.le))] + simp only [cascadeShapeLikelihood,List.map_cons,List.prod_cons,focusedShapeNumerator] + rw [hc] + let D := (cascadeVisitCount n s:ℝ)+(ss.map (fun t => (cascadeVisitCount n t:ℝ))).sum-a + let U := focusedShapeNumerator n (fun i => z i.succ) (z 0) d s + have hcancel : (U/((cascadeVisitCount n s:ℝ)-z 0))*(((cascadeVisitCount n s:ℝ)-z 0)/D) = U/D := by + field_simp + have hmul : ENNReal.ofReal (U/((cascadeVisitCount n s:ℝ)-z 0))* + ENNReal.ofReal (((cascadeVisitCount n s:ℝ)-z 0)/D) = ENNReal.ofReal (U/D) := by + rw [← ENNReal.ofReal_mul (div_nonneg hnp.le hrb.le),hcancel] + calc + _ = (cascadeShapeLikelihood n (fun i => z i.succ) (z 0) s * + (ss.map (cascadeShapeLikelihood n (fun i => z i.succ) (z 0))).prod * + ENNReal.ofReal (stableEppfValue a (z 0) + ((cascadeVisitCount n s:ℝ)::ss.map (fun t => (cascadeVisitCount n t:ℝ))))) * + (ENNReal.ofReal (U/((cascadeVisitCount n s:ℝ)-z 0))* + ENNReal.ofReal (((cascadeVisitCount n s:ℝ)-z 0)/D)) := by dsimp [U,D]; ring + _ = _ := by rw [hmul] + +lemma descendant_transform_independent {S C D : Type*} + [MeasurableSpace S] [MeasurableSpace C] [MeasurableSpace D] + (ν : Measure S) (ρ : Measure C) (θ : Measure D) [SFinite ν] [SFinite ρ] + (T : S × C → D) (hT : Measurable T) + (hLaw : ∀ s, ρ.map (fun c => T (s,c)) = θ) : + (ν.prod ρ).map (fun p => (p.1,T p)) = ν.prod θ := by + exact ((MeasurePreserving.id ν).skew_product (g := fun s c => T (s,c)) hT (ae_of_all _ hLaw)).map_eq + +lemma stableIntensity_normalized_mark_projection {S : Type*} [MeasurableSpace S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb : 0 ≤ b) + {F : S → ℝ} (hF : Measurable F) + (hI : Integrable (fun x => Real.exp (b*F x)) ν) + (hM : (∫ x, Real.exp (b*F x) ∂ν) = 1) : + ((stableLogIntensity b).prod ν).map (fun p : ℝ×S => p.1+F p.2) = stableLogIntensity b := by + have : IsProbabilityMeasure (ν.withDensity (fun x => ENNReal.ofReal (Real.exp (b*F x)))) := + normalized_mark_density_probability ν hI hM + change Measure.map (Prod.fst ∘ logMarkShift F) ((stableLogIntensity b).prod ν) = _ + rw [← Measure.map_map measurable_fst (logMarkShift_measurable hF),stableLogIntensity_mark_shift ν hb hF, + Measure.map_fst_prod,measure_univ,one_smul] + +lemma stableIntensity_descendant_transform {S C D : Type*} + [MeasurableSpace S] [MeasurableSpace C] [MeasurableSpace D] + (ν : Measure S) (ρ : Measure C) (θ : Measure D) + [IsProbabilityMeasure ν] [IsProbabilityMeasure ρ] [IsProbabilityMeasure θ] + {b : ℝ} (hb : 0 ≤ b) (T : S×C → D) (hT : Measurable T) + (hLaw : ∀ s, ρ.map (fun c => T (s,c)) = θ) + {F : S → ℝ} (hF : Measurable F) + (hI : Integrable (fun x => Real.exp (b*F x)) ν) + (hM : (∫ x, Real.exp (b*F x) ∂ν) = 1) : + ((stableLogIntensity b).prod (ν.prod ρ)).map + (fun p : ℝ×(S×C) => (p.1+F p.2.1,T p.2)) = (stableLogIntensity b).prod θ := by + let I := stableLogIntensity b + have hmark : MeasurePreserving (fun p : S×C => (p.1,T p)) (ν.prod ρ) (ν.prod θ) := + ⟨measurable_fst.prodMk hT, descendant_transform_independent ν ρ θ T hT hLaw⟩ + have hs : MeasurePreserving (fun p : ℝ×S => p.1+F p.2) (I.prod ν) I := + ⟨measurable_fst.add (hF.comp measurable_snd), stableIntensity_normalized_mark_projection ν hb hF hI hM⟩ + have hassoc : MeasurePreserving (MeasurableEquiv.prodAssoc : (ℝ×S)×D ≃ᵐ ℝ×(S×D)) + ((I.prod ν).prod θ) (I.prod (ν.prod θ)) := + ⟨MeasurableEquiv.prodAssoc.measurable,Measure.prodAssoc_prod⟩ + have hmain := (hs.prod (MeasurePreserving.id θ)).comp + ((hassoc.symm).comp ((MeasurePreserving.id I).prod hmark)) + exact hmain.map_eq + +lemma stablePoisson_descendant_transform {S C D : Type*} + [MeasurableSpace S] [MeasurableSpace C] [MeasurableSpace D] + [Nonempty S] [Nonempty C] [Nonempty D] + (ν : Measure S) (ρ : Measure C) (θ : Measure D) + [IsProbabilityMeasure ν] [IsProbabilityMeasure ρ] [IsProbabilityMeasure θ] + {b : ℝ} (hb : 0 ≤ b) (T : S×C → D) (hT : Measurable T) + (hLaw : ∀ s, ρ.map (fun c => T (s,c)) = θ) + {F : S → ℝ} (hF : Measurable F) + (hI : Integrable (fun x => Real.exp (b*F x)) ν) + (hM : (∫ x, Real.exp (b*F x) ∂ν) = 1) : + (poissonRandomMeasureLaw ((stableLogIntensity b).prod (ν.prod ρ))).map + (Measure.map (fun p : ℝ×(S×C) => (p.1+F p.2.1,T p.2))) = + poissonRandomMeasureLaw ((stableLogIntensity b).prod θ) := by + rw [poissonRandomMeasureLaw_map _ (by fun_prop)] + congr 1 + exact stableIntensity_descendant_transform ν ρ θ hb T hT hLaw hF hI hM + +lemma countKernel_parameter_map_measurable {X S D : Type*} + [MeasurableSpace X] [MeasurableSpace S] [MeasurableSpace D] + (F : X×(ℝ×S) → D) (hF : Measurable F) : + Measurable (fun p : X×Measure (ℝ×S) => + (markedStableCountKernel p.2).map (fun q => F (p.1,q))) := by + apply Measure.measurable_of_measurable_coe + intro s hs + let κ : Kernel (X×Measure (ℝ×S)) (ℝ×S) := markedStableCountKernel.comap Prod.snd measurable_snd + have hh : Measurable (fun p : (X×Measure (ℝ×S))×(ℝ×S) => + (s.indicator (fun _ => (1:ℝ≥0∞))) (F (p.1.1,p.2))) := + (measurable_const.indicator hs).comp (hF.comp (measurable_fst.fst.prodMk measurable_snd)) + have hi := hh.lintegral_kernel_prod_right' (κ := κ) + convert hi using 1 + funext p + calc + _ = ∫⁻ d, s.indicator (fun _ => (1:ℝ≥0∞)) d ∂(markedStableCountKernel p.2).map (fun q => F (p.1,q)) := + (lintegral_indicator_one hs).symm + _ = _ := lintegral_map (measurable_const.indicator hs) + (hF.comp (measurable_const.prodMk measurable_id)) + +lemma markedStableCountKernel_ae_eq {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) : + ∀ᵐ η ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν), markedStableCountKernel η = η := by + exact (markedStable_regular ν hb0 hb1).mono (fun η hη => markedStableCountKernel_eq η hη.1 hη.2) + +@[reducible] def DecoratedCascade (S : Type) [MeasurableSpace S] : ℕ → MeasCat + | 0 => MeasCat.of Unit + | n+1 => MeasCat.of (Measure (ℝ×(S×DecoratedCascade S n))) + +instance decoratedCascadeNonempty (S : Type) [MeasurableSpace S] (n : ℕ) : + Nonempty (DecoratedCascade S n) := by + cases n with + | zero => exact ⟨()⟩ + | succ n => exact ⟨(0 : Measure (ℝ×(S×DecoratedCascade S n)))⟩ + +def decoratedCascadeLaw {S : Type} [MeasurableSpace S] [Nonempty S] + (ν : ProbabilityMeasure S) : (n : ℕ) → (Fin n → ℝ) → ProbabilityMeasure (DecoratedCascade S n) + | 0, _ => ⟨Measure.dirac (),by exact Measure.dirac.isProbabilityMeasure⟩ + | n+1, z => ⟨poissonRandomMeasureLaw ((stableLogIntensity (z 0)).prod + ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ)))), + by exact poissonRandomMeasureLaw_probability _⟩ + +def decoratedCascadeTransform {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) : (n : ℕ) → (Fin n → X×S → ℝ) → X×DecoratedCascade S n → StableCascade n + | 0, _, _ => () + | n+1, F, p => (markedStableCountKernel p.2).map (fun q : ℝ×(S×DecoratedCascade S n) => + (q.1+F 0 (p.1,q.2.1),decoratedCascadeTransform step n (fun i => F i.succ) + (step (p.1,q.2.1),q.2.2))) + +lemma decoratedCascadeTransform_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (hstep : Measurable step) (n : ℕ) (F : Fin n → X×S → ℝ) + (hF : ∀ i, Measurable (F i)) : Measurable (decoratedCascadeTransform step n F) := by + induction n with + | zero => exact measurable_const + | succ n ih => + let H : X×(ℝ×(S×DecoratedCascade S n)) → ℝ×StableCascade n := fun p => + (p.2.1+F 0 (p.1,p.2.2.1),decoratedCascadeTransform step n (fun i => F i.succ) + (step (p.1,p.2.2.1),p.2.2.2)) + have hH : Measurable H := + (measurable_snd.fst.add ((hF 0).comp (measurable_fst.prodMk measurable_snd.snd.fst))).prodMk + ((ih (fun i => F i.succ) (fun i => hF i.succ)).comp + ((hstep.comp (measurable_fst.prodMk measurable_snd.snd.fst)).prodMk measurable_snd.snd.snd)) + exact countKernel_parameter_map_measurable H hH + +theorem decoratedCascadeTransform_law {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hstep : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)).map + (fun η => decoratedCascadeTransform step n F (x,η)) = cascadeLaw n z := by + induction n generalizing x with + | zero => + change Measure.map (fun _ : Unit => ()) (Measure.dirac ()) = Measure.dirac () + exact Measure.map_dirac () + | succ n ih => + let ρ : Measure (DecoratedCascade S n) := decoratedCascadeLaw ν n (fun i => z i.succ) + let θ : Measure (StableCascade n) := cascadeLaw n (fun i => z i.succ) + let T : S×DecoratedCascade S n → StableCascade n := fun p => + decoratedCascadeTransform step n (fun i => F i.succ) (step (x,p.1),p.2) + have hT : Measurable T := + (decoratedCascadeTransform_measurable step hstep n _ (fun i => hF i.succ)).comp + ((hstep.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd) + have ht : ∀ s, ρ.map (fun c => T (s,c)) = θ := fun s => + ih (fun i => z i.succ) (fun i => hz0 i.succ) (fun i => hz1 i.succ) + (fun i => F i.succ) (fun i => hF i.succ) (fun i => hI i.succ) (fun i => hM i.succ) (step (x,s)) + let G : ℝ×(S×DecoratedCascade S n) → ℝ×StableCascade n := + fun p => (p.1+F 0 (x,p.2.1),T p.2) + change (poissonRandomMeasureLaw ((stableLogIntensity (z 0)).prod ((ν : Measure S).prod ρ))).map + (fun η => (markedStableCountKernel η).map G) = poissonRandomMeasureLaw ((stableLogIntensity (z 0)).prod θ) + calc + _ = (poissonRandomMeasureLaw ((stableLogIntensity (z 0)).prod ((ν : Measure S).prod ρ))).map + (Measure.map G) := by + apply Measure.map_congr + filter_upwards [markedStable_regular ((ν : Measure S).prod ρ) (hz0 0) (hz1 0)] with η hη + rw [markedStableCountKernel_eq η hη.1 hη.2] + _ = _ := stablePoisson_descendant_transform (ν : Measure S) ρ θ (hz0 0).le T hT ht + ((hF 0).comp (measurable_const.prodMk measurable_id)) (hI 0 x) (hM 0 x) + +lemma decoratedCascadeTransform_root_independent {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (μ : Measure X) [SFinite μ] + (step : X×S → X) (hstep : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) : + (μ.prod (decoratedCascadeLaw ν n z)).map (fun p => (p.1,decoratedCascadeTransform step n F p)) = + μ.prod (cascadeLaw n z) := by + apply descendant_transform_independent _ _ _ _ (decoratedCascadeTransform_measurable step hstep n F hF) + exact decoratedCascadeTransform_law ν step hstep n z hz0 hz1 F hF hI hM + +lemma cascadeTotal_log_memLp_two (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) : + MemLp (fun η => Real.log (cascadeTotal n η)) 2 (cascadeLaw n z : Measure (StableCascade n)) := by + cases n with + | zero => simp [cascadeTotal,cascadeTotalE] + | succ n => + obtain ⟨hp,hI⟩ := cascadeTotal_regular (n+1) z hz hz0 hz1 + let ε : ℝ := z 0/4 + have hε : 0 < ε := div_pos (hz0 0) (by norm_num) + have hmin : ∀ i, z 0 ≤ z i := fun i => hz.monotone (Fin.zero_le i) + have hplus : ∀ i, 2*ε < z i := by intro i; dsimp [ε]; linarith [hmin i,hz0 0] + have hminus : ∀ i, -(2*ε) < z i := by intro i; linarith [hz0 i] + apply (memLp_two_iff_integrable_sq (cascadeTotal_measurable (n+1)).log.aestronglyMeasurable).mpr + apply (((hI (2*ε) hplus).add (hI (-(2*ε)) hminus)).div_const (ε^2)).mono' + ((cascadeTotal_measurable (n+1)).log.pow_const (2:ℕ)).aestronglyMeasurable + filter_upwards [hp] with η hη + change |(Real.log (cascadeTotal (n+1) η))^2| ≤ _ + rw [abs_of_nonneg (sq_nonneg _)] + exact log_sq_le_two_rpow hη hε + +def decoratedWeightedTotalE {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) : (n : ℕ) → (Fin n → X×S → ℝ) → X×DecoratedCascade S n → ℝ≥0∞ + | 0, _, _ => 1 + | n+1, F, p => ∫⁻ q : ℝ×(S×DecoratedCascade S n), + ENNReal.ofReal (Real.exp (q.1+F 0 (p.1,q.2.1))) * + decoratedWeightedTotalE step n (fun i => F i.succ) (step (p.1,q.2.1),q.2.2) + ∂markedStableCountKernel p.2 + +lemma decoratedWeightedTotalE_transform {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (step : X×S → X) (hstep : Measurable step) (n : ℕ) (F : Fin n → X×S → ℝ) + (hF : ∀ i, Measurable (F i)) (p : X×DecoratedCascade S n) : + cascadeTotalE n (decoratedCascadeTransform step n F p) = decoratedWeightedTotalE step n F p := by + induction n with + | zero => rfl + | succ n ih => + let G : ℝ×(S×DecoratedCascade S n) → ℝ×StableCascade n := fun q => + (q.1+F 0 (p.1,q.2.1),decoratedCascadeTransform step n (fun i => F i.succ) + (step (p.1,q.2.1),q.2.2)) + have hG : Measurable G := + (measurable_fst.add ((hF 0).comp (measurable_const.prodMk measurable_snd.fst))).prodMk + ((decoratedCascadeTransform_measurable step hstep n _ (fun i => hF i.succ)).comp + ((hstep.comp (measurable_const.prodMk measurable_snd.fst)).prodMk measurable_snd.snd)) + change (∫⁻ q : ℝ×StableCascade n, ENNReal.ofReal (Real.exp q.1)*cascadeTotalE n q.2 + ∂(markedStableCountKernel p.2).map G) = _ + have hw : Measurable (fun q : ℝ×StableCascade n => ENNReal.ofReal (Real.exp q.1)*cascadeTotalE n q.2) := + ((Real.measurable_exp.comp measurable_fst).ennreal_ofReal.mul ((cascadeTotalE_measurable n).comp measurable_snd)) + calc + _ = ∫⁻ q, ENNReal.ofReal (Real.exp (G q).1)*cascadeTotalE n (G q).2 ∂markedStableCountKernel p.2 := + lintegral_map hw hG + _ = _ := by + apply lintegral_congr + intro q + dsimp only [G] + rw [ih (fun i => F i.succ) (fun i => hF i.succ)] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/FocusedVisit.lean b/lean/OAI/Probability/Perceptron/Variational/FocusedVisit.lean new file mode 100644 index 0000000000000000000000000000000000000000..b81c29056e2969a64be52b671ec1d1b97b14a889 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/FocusedVisit.lean @@ -0,0 +1,132 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.PointedShape + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Classical ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {X S : Type} [MeasurableSpace S] + +lemma indexedClassMass_zero (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) + (hp : 0 < (indexedTiltedTotal step n F p).toReal) (l : IndexedLeaf n) : + indexedClassMass step n F 0 p l = 1 := by + simp only [indexedClassMass,Nat.zero_le,↓reduceIte,mul_one] + exact indexedTiltedProbability_mass step n F p hp + +lemma indexedFocusedVisit_zero (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (s : CascadeVisitShape n) (hs : s.Valid n) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) + (hp : 0 < (indexedTiltedTotal step n F p).toReal) : + indexedFocusedVisit step n F 0 s hs p = indexedShapeVisit step n F s p := by + simp only [indexedFocusedVisit,indexedClassMass_zero step n F p hp,mul_one,indexedShapeVisit] + +lemma indexedFocusedVisit_succ (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) (d : ℕ) (s : CascadeVisitShape n) + (ss : List (CascadeVisitShape n)) (hs : CascadeVisitShape.Valid (n+1) (s::ss)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) : + indexedFocusedVisit step (n+1) F (d+1) (s::ss) hs p = + ∑' a : Fin (ss.length+1) ↪ (Σ i, Fin ((p.2.1 i).1)), + (indexedBranchProbability step n F p (a 0)) ^ (cascadeVisitCount n s+1) * + indexedFocusedVisit step n (fun l => F l.succ) d s (hs.2 s (by simp)) + (indexedChildPoint step n p (a 0).1 (a 0).2.val) * + ∏ i : Fin ss.length, + (indexedBranchProbability step n F p (a i.succ)) ^ cascadeVisitCount n ss[i] * + indexedShapeVisit step n (fun l => F l.succ) ss[i] + (indexedChildPoint step n p (a i.succ).1 (a i.succ).2.val) := by + let ts : CascadeVisitShape (n+1) := s::ss + let J (i : Fin (ss.length+1)) := CascadeShapeReplicas n ts[i] + let A := Σ i, Fin ((p.2.1 i).1) + let (i : Fin (ss.length+1)) : Nonempty (J i) := + cascadeShapeReplicas_nonempty n ts[i] (hs.2 _ (List.getElem_mem i.isLt)) + let e := indexedActiveLeafEmbedding n p.2.1 + let r : J 0 := cascadeShapeFocus n s (hs.2 s (by simp)) + have hw (l : IndexedLeaf (n+1)) (hl : l ∉ Set.range e) : + indexedTiltedProbability step (n+1) F p l = 0 := by + apply indexedTiltedProbability_inactive + intro h + exact hl ⟨(⟨l.1, ⟨l.2.1,h⟩⟩,l.2.2), rfl⟩ + have hweight (t : A × IndexedLeaf n) : + indexedTiltedProbability step (n+1) F p (e t) = + indexedBranchProbability step n F p t.1 * + indexedTiltedProbability step n (fun l => F l.succ) + (indexedChildPoint step n p t.1.1 t.1.2.val) t.2 := + indexedTiltedProbability_active step n F p t.1 (hc _ _) t.2 + have hm (xs : (Σ i : Fin (ss.length+1), J i) → A × IndexedLeaf n) : + CascadeShapeMatches (n+1) ts (fun u => e (xs u)) ↔ + RootPartitionMatch xs ∧ + ∀ i : Fin (ss.length+1), CascadeShapeMatches n ts[i] (fun j => (xs ⟨i,j⟩).2) := by + apply and_congr ?_ Iff.rfl + constructor + · intro h u v + exact (indexedActiveRootEmbedding n p.2.1).injective.eq_iff.symm.trans (h u v) + · intro h u v + exact (indexedActiveRootEmbedding n p.2.1).injective.eq_iff.trans (h u v) + change (∑' xs : (Σ i : Fin (ss.length+1), J i) → IndexedLeaf (n+1), + ((∏ i, indexedTiltedProbability step (n+1) F p (xs i)) * + if CascadeShapeMatches (n+1) ts xs then 1 else 0) * + indexedClassMass step (n+1) F (d+1) p (xs ⟨0,r⟩)) = _ + simp_rw [mul_assoc] + rw [tsum_pi_supported e _ hw] + calc + _ = ∑' xs : (Σ i : Fin (ss.length+1), J i) → A × IndexedLeaf n, + if RootPartitionMatch xs then + ((∏ u, indexedBranchProbability step n F p (xs u).1 * + indexedTiltedProbability step n (fun l => F l.succ) + (indexedChildPoint step n p (xs u).1.1 (xs u).1.2.val) (xs u).2) * + ∏ i : Fin (ss.length+1), + if CascadeShapeMatches n ts[i] (fun j => (xs ⟨i,j⟩).2) then 1 else 0) * + (indexedBranchProbability step n F p (xs ⟨0,r⟩).1 * + indexedClassMass step n (fun l => F l.succ) d + (indexedChildPoint step n p (xs ⟨0,r⟩).1.1 (xs ⟨0,r⟩).1.2.val) (xs ⟨0,r⟩).2) + else 0 := by + apply tsum_congr + intro xs + have hprod := Finset.prod_congr rfl (fun u (_ : u ∈ Finset.univ) => hweight (xs u)) + have hind := if_congr (hm xs) (rfl : (1:ℝ≥0∞)=1) (rfl : (0:ℝ≥0∞)=0) + have hmass := indexedClassMass_active_succ step n F d p hc (xs ⟨0,r⟩).1 (xs ⟨0,r⟩).2 + change _ = _ at hmass + calc + _ = ((∏ u, indexedBranchProbability step n F p (xs u).1 * + indexedTiltedProbability step n (fun l => F l.succ) + (indexedChildPoint step n p (xs u).1.1 (xs u).1.2.val) (xs u).2) * + (if RootPartitionMatch xs ∧ ∀ i : Fin (ss.length+1), + CascadeShapeMatches n ts[i] (fun j => (xs ⟨i,j⟩).2) then 1 else 0)) * + (indexedBranchProbability step n F p (xs ⟨0,r⟩).1 * + indexedClassMass step n (fun l => F l.succ) d + (indexedChildPoint step n p (xs ⟨0,r⟩).1.1 (xs ⟨0,r⟩).1.2.val) (xs ⟨0,r⟩).2) := by + rw [← mul_assoc] + exact congrArg₂ (· * ·) (congrArg₂ (· * ·) hprod hind) hmass + _ = _ := by + by_cases hr : RootPartitionMatch xs + · simp only [hr,true_and,↓reduceIte] + by_cases ha : ∀ i : Fin (ss.length+1), + CascadeShapeMatches n ts[i] (fun j => (xs ⟨i,j⟩).2) + · simp only [ha, implies_true, ↓reduceIte, Finset.prod_const_one] + · have hz : (∏ i : Fin (ss.length+1), + if CascadeShapeMatches n ts[i] (fun j => (xs ⟨i,j⟩).2) + then (1 : ℝ≥0∞) else 0) = 0 := by + obtain ⟨i, hi⟩ := not_forall.mp ha + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + simp only [ha, ↓reduceIte, hz] + · simp [hr] + _ = _ := by + rw [root_partition_sum_focused ss.length J r (indexedBranchProbability step n F p) + (fun a l => indexedTiltedProbability step n (fun l => F l.succ) + (indexedChildPoint step n p a.1 a.2.val) l) + (fun i ys => if CascadeShapeMatches n ts[i] ys then 1 else 0) + (fun a ys => indexedClassMass step n (fun l => F l.succ) d + (indexedChildPoint step n p a.1 a.2.val) (ys r))] + simp only [J,cascadeShapeReplicas_card,ts] + simp only [indexedFocusedVisit,indexedShapeVisit,mul_assoc] + rfl + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianAbsoluteEnergyBound.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianAbsoluteEnergyBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b379192e6cf3ebd02589d1cf79cccb38ed52087 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianAbsoluteEnergyBound.lean @@ -0,0 +1,142 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.Contact + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma gaussianEnergy_abs_tilt_bound {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] + {W : S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} + (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) + (hL : Measurable L) {A D E : ℝ} (hA : ∀ x, |W x| ≤ A) + (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) + (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) : + (∫ g, tiltMean μ (countableGaussianHamiltonian W v L g) + (fun x => |countableGaussianField w L g x|) 1 ∂countableGaussianLaw) ≤ + Real.exp (2*A+2*D)+4*Real.exp (2*A+4*D+E) := by + have hZ := gaussianHamiltonianPartition_inverse_power_integrable μ hW hv hL hA hD 2 + have hY := gaussianEnergy_weighted_moment_joint_integrable hW hv hw hL hA hD hE μ 0 2 2 + simp only [gaussianTailCoefficient_zero,sq_abs] at hY + have hb := tiltMean_abs_annealed_L2_bound μ countableGaussianLaw + (countableGaussianHamiltonian_measurable hW hv hL) + (countableGaussianField_measurable hw hL) hZ hY + have hz := gaussianHamiltonianPartition_inverse_power_bound μ hW hv hL hA hD 2 + norm_num only [Nat.cast_ofNat] at hz + have hze : (2:ℝ)*A+4*D/2=2*A+2*D := by ring + rw [hze] at hz + have hy : (∫ q : S×(ℕ → ℝ), countableGaussianField w L q.2 q.1^2* + Real.exp (2*countableGaussianHamiltonian W v L q.2 q.1) ∂(μ.prod countableGaussianLaw)) ≤ + 4*Real.exp (2*A+4*D+E) := by + rw [integral_prod _ hY] + have hi := hY.integral_prod_left + have hm := integral_mono hi (integrable_const (4*Real.exp (2*A+4*D+E))) (fun x => by + simpa only [gaussianTailCoefficient_zero,sq_abs,Nat.factorial_two,Nat.cast_ofNat, + abs_of_pos (by norm_num : (0:ℝ)<2),show (2:ℝ)^2=4 by norm_num, + show (2:ℝ)*2=4 by norm_num] using + gaussianEnergy_weighted_moment_bound hW hv hw hL hA hD hE 0 2 2 x) + simpa using hm + let a := ∫ g, (tiltPartition μ (countableGaussianHamiltonian W v L g) 1)⁻¹^2 ∂countableGaussianLaw + let b := ∫ q : S×(ℕ → ℝ), countableGaussianField w L q.2 q.1^2* + Real.exp (2*countableGaussianHamiltonian W v L q.2 q.1) ∂(μ.prod countableGaussianLaw) + have ha0 : 0 ≤ a := integral_nonneg fun _ => sq_nonneg _ + have hb0 : 0 ≤ b := integral_nonneg fun _ => mul_nonneg (sq_nonneg _) (Real.exp_pos _).le + have hs : Real.sqrt a*Real.sqrt b ≤ a+b := by + have hsa := Real.sq_sqrt ha0 + have hsb := Real.sq_sqrt hb0 + nlinarith [sq_nonneg (Real.sqrt a-Real.sqrt b)] + exact hb.trans (hs.trans (add_le_add hz hy)) + +lemma poisson_exp_affine_integrable (r : ℝ≥0) (a b : ℝ) : + Integrable (fun M : ℕ => Real.exp (a*(M:ℝ)+b)) (poissonMeasure r) := by + have hi : Integrable (fun M : ℕ => (Real.exp a)^M) (poissonMeasure r) := by + rw [integrable_poissonMeasure_iff] + have he := (NormedSpace.expSeries_div_hasSum_exp ((r:ℝ)*Real.exp a)).summable.mul_left (Real.exp (-(r:ℝ))) + apply he.congr + intro M + rw [Real.norm_eq_abs,abs_of_nonneg (pow_nonneg (Real.exp_pos a).le M),mul_pow] + ring + convert hi.mul_const (Real.exp b) using 1 + ext M + rw [Real.exp_add,mul_comm a (M:ℝ),Real.exp_nat_mul] + +lemma sourceCoupling_abs_energy_integrable (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (z : Fin k → ℝ) (t : ℝ≥0) : + Integrable (fun a => tiltMean (sourceSpinLeafKernel n k a.1) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => |sourceCouplingEnergy n k p d h j a x|) 1) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) := by + let L : (NormalizedSpin (n+1) × IndexedLeaf k) → ℕ := indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) k + let Y := countableGaussianField (sourceGaussianTestRow p d h j) L + let F := fun a : SourceBaseData n k × (ℕ → ℝ) => + tiltMean (sourceSpinLeafKernel n k a.1) (sourceCouplingHamiltonian n k f p d h u a) + (fun x => |Y a.2 x|) 1 + let D := (2*h (Fin.last k)+1)*(enrichedFeatureBound (n+1) u:ℝ)^2 + let E := 2*h (Fin.last k)+1 + let A := fun M : ℕ => (M:ℝ)*‖f‖+|(n+1:ℕ)*h (Fin.last k)| + let B := fun M : ℕ => Real.exp (2*A M+2*D)+4*Real.exp (2*A M+4*D+E) + have hY : Measurable (fun a : (SourceBaseData n k × (ℕ → ℝ)) × + (NormalizedSpin (n+1) × IndexedLeaf k) => Y a.1.2 a.2) := + measurable_disorder_state_lift (countableGaussianField_measurable + (sourceGaussianTestRow_measurable p d h j) (indexedGaussianRowLength_measurable k)) + have hm : Measurable F := kernel_tiltMean_measurable (sourceFullSpinLeafKernel n k) + (sourceCouplingHamiltonian_measurable n k f p d h u) hY.abs + have hf (a : SourceBaseData n k) : Integrable (fun g => F (a,g)) countableGaussianLaw := by + rw [show (fun g => F (a,g)) = fun g => tiltMean (enrichedIndexedBaseMeasure n k a.2.2) + (enrichedIndexedHamiltonian n a.1 k f (patternPrefix (n+1) a.1 a.2.1) p d h u g) + (fun x => |Y g x|) 1 by funext g; simp only [F,sourceSpinLeafKernel_apply,sourceCouplingHamiltonian]] + simpa only [gaussianTailCoefficient_zero,enrichedIndexedHamiltonian] using + gaussianEnergy_tail_tilt_integrable (enrichedIndexedBaseMeasure n k a.2.2) + (enrichedIndexedBoundedEnergy_measurable n a.1 k f _ h) + (sourceGaussianRow_measurable p d h u) (sourceGaussianTestRow_measurable p d h j) + (indexedGaussianRowLength_measurable k) + (enrichedIndexedBoundedEnergy_bound n a.1 k f _ h) + (sourceGaussianRow_square_bound p d h u hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l))) + (sourceGaussianTestRow_square_bound p d h hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l)) j) 0 + have hb (a : SourceBaseData n k) : (∫ g, F (a,g) ∂countableGaussianLaw) ≤ B a.1 := by + simpa only [F,sourceCouplingHamiltonian,sourceSpinLeafKernel_apply,enrichedIndexedHamiltonian, + B,A,D,E] using gaussianEnergy_abs_tilt_bound (enrichedIndexedBaseMeasure n k a.2.2) + (enrichedIndexedBoundedEnergy_measurable n a.1 k f _ h) + (sourceGaussianRow_measurable p d h u) (sourceGaussianTestRow_measurable p d h j) + (indexedGaussianRowLength_measurable k) + (enrichedIndexedBoundedEnergy_bound n a.1 k f _ h) + (sourceGaussianRow_square_bound p d h u hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l))) + (sourceGaussianTestRow_square_bound p d h hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l)) j) + have hbi : Integrable B (poissonMeasure ((n+1:ℕ)*t)) := by + have h1 := poisson_exp_affine_integrable ((n+1:ℕ)*t) (2*‖f‖) (2*|(n+1:ℕ)*h (Fin.last k)|+2*D) + have h2 := poisson_exp_affine_integrable ((n+1:ℕ)*t) (2*‖f‖) (2*|(n+1:ℕ)*h (Fin.last k)|+4*D+E) + apply (h1.add (h2.const_mul 4)).congr + filter_upwards [] with M + dsimp [B,A] + congr 2 <;> ring_nf + have hbi' : Integrable (fun a : SourceBaseData n k => B a.1) (sourceBaseDataLaw n k z t) := + measurePreserving_fst.integrable_comp_of_integrable hbi + have hF0 (a) : 0 ≤ F a := tiltMean_nonneg _ (fun _ => abs_nonneg _) 1 + have hFi : Integrable F ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) := by + rw [integrable_prod_iff hm.aestronglyMeasurable] + refine ⟨ae_of_all _ hf, ?_⟩ + apply hbi'.mono' (hm.norm.stronglyMeasurable.integral_prod_right').aestronglyMeasurable + filter_upwards [] with a + simp only [Real.norm_eq_abs,abs_of_nonneg (hF0 _)] + rw [abs_of_nonneg (integral_nonneg fun g => hF0 (a,g))] + exact hb a + convert hFi.const_mul |perturbationAmplitude (n+1) (fun _ => 1) j| using 1 + ext a + simp only [sourceCouplingEnergy,abs_mul,F,Y,tiltMean,tiltIntegral,one_mul] + rw [show (fun x => Real.exp (sourceCouplingHamiltonian n k f p d h u a x)* + (|perturbationAmplitude (n+1) (fun _ => 1) j| *|Y a.2 x|)) = + fun x => |perturbationAmplitude (n+1) (fun _ => 1) j| * + (Real.exp (sourceCouplingHamiltonian n k f p d h u a x)*|Y a.2 x|) by funext x; ring, + integral_const_mul] + ring + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianAverage.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianAverage.lean new file mode 100644 index 0000000000000000000000000000000000000000..a384c62bdcd4c92cd561c52aa20b57a47740e667 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianAverage.lean @@ -0,0 +1,426 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.TerminalVariational + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma controlValue_trial_sub_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m n : Trial) (L : ℝ≥0) (hf : LipschitzWith L f) : + controlValue P f m - controlValue P f n ≤ + (3/2 : ℝ) * (L : ℝ)^2 * ∫ t, |m t-n t| ∂timeLaw := by + suffices controlValue P f m ≤ controlValue P f n + + (3/2 : ℝ) * (L : ℝ)^2 * ∫ t, |m t-n t| ∂timeLaw by linarith + apply controlValue_le_of_bounded_controls P f m L hf + intro v hv _ hbound + have hpay : controlPayoff P f n v ≤ controlValue P f n := + le_csSup (controlPayoffs_bddAbove P f n) ⟨v, hv, + (controlCost_le_bound P n L hbound).trans_lt (by finiteness), rfl⟩ + have hd := (abs_le.mp (controlPayoff_trial_diff_bound P f m n L hf hv hbound)).2 + linarith + +lemma controlValue_trial_abs_sub_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m n : Trial) (L : ℝ≥0) (hf : LipschitzWith L f) : + |controlValue P f m - controlValue P f n| ≤ + (3/2 : ℝ) * (L : ℝ)^2 * ∫ t, |m t-n t| ∂timeLaw := by + have hmn := controlValue_trial_sub_le P f m n L hf + have hnm := controlValue_trial_sub_le P f n m L hf + simp_rw [abs_sub_comm (n _) (m _)] at hnm + exact abs_le.mpr ⟨by linarith, hmn⟩ + +lemma usual_measurable_aemeasurable (P : Measure BrownianPath) (t : Time) + {Y : BrownianPath → ℝ} (hY : @Measurable _ _ (usualBrownianSigma P t) (borel ℝ) Y) : + AEMeasurable Y P := by + have h : NullMeasurable Y P := hY.mono (usualBrownianSigma_le_completion P t) le_rfl + exact h.aemeasurable + +lemma brownian_increment_indep_adapted (P : Measure BrownianPath) [IsProbabilityMeasure P] + (hB : IsBrownianReal brownianEval P) (t : Time) (r : ℝ≥0) (htr : (t : ℝ) < r) + {Y : BrownianPath → ℝ} (hY : @Measurable _ _ (usualBrownianSigma P t) (borel ℝ) Y) : + IndepFun Y (fun ω => brownianEval r ω - brownianEval ⟨t.val, (show 0 ≤ (t : ℝ) from t.property.1)⟩ ω) P := + indep_of_indep_of_le_left (brownian_increment_indep_usual P hB t r htr) hY.comap_le + +lemma second_order_taylor_bound {f : ℝ → ℝ} (hf : ContDiff ℝ 3 f) + (C : ℝ) (hC : ∀ x, |iteratedDeriv 3 f x| ≤ C) (x y : ℝ) : + |f y - f x - deriv f x * (y-x) - iteratedDeriv 2 f x * (y-x)^2/2| ≤ + C * |y-x|^3 / 6 := by + by_cases hxy : x = y + · subst y; simp + have hs := uniqueDiffOn_uIcc hxy + have hd₁ : iteratedDerivWithin 1 f (uIcc x y) x = deriv f x := by + rw [iteratedDerivWithin_eq_iteratedDeriv hs ((hf.of_le (by norm_num)).contDiffAt) + left_mem_uIcc, iteratedDeriv_one] + have hd₂ : iteratedDerivWithin 2 f (uIcc x y) x = iteratedDeriv 2 f x := + iteratedDerivWithin_eq_iteratedDeriv hs ((hf.of_le (by norm_num)).contDiffAt) + left_mem_uIcc + have hp : taylorWithinEval f 2 (uIcc x y) x y = + f x + deriv f x * (y-x) + iteratedDeriv 2 f x * (y-x)^2/2 := by + rw [show (2 : ℕ) = 1+1 from rfl, taylorWithinEval_succ, + taylorWithinEval_succ, taylor_within_zero_eval, hd₁, hd₂] + norm_num + ring + obtain ⟨z, -, hz⟩ := taylor_mean_remainder_lagrange_iteratedDeriv (n := 2) hxy hf.contDiffOn + rw [hp] at hz + have he : f y - f x - deriv f x * (y-x) - iteratedDeriv 2 f x * (y-x)^2/2 = + iteratedDeriv 3 f z * (y-x)^3/6 := by + norm_num at hz + linarith only [hz] + rw [he, abs_div, abs_mul, abs_pow] + norm_num + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right (hC z) (by positivity)) (by norm_num) + +lemma first_order_taylor_bound {f : ℝ → ℝ} (hf : ContDiff ℝ 2 f) + (C : ℝ) (hC : ∀ x, |iteratedDeriv 2 f x| ≤ C) (x y : ℝ) : + |f y - f x - deriv f x * (y-x)| ≤ C * (y-x)^2 / 2 := by + by_cases hxy : x = y + · subst y; simp + have hs := uniqueDiffOn_uIcc hxy + have hd : iteratedDerivWithin 1 f (uIcc x y) x = deriv f x := by + rw [iteratedDerivWithin_eq_iteratedDeriv hs ((hf.of_le (by norm_num)).contDiffAt) + left_mem_uIcc, iteratedDeriv_one] + have hp : taylorWithinEval f 1 (uIcc x y) x y = f x + deriv f x * (y-x) := by + rw [show (1 : ℕ) = 0+1 from rfl, taylorWithinEval_succ, taylor_within_zero_eval, hd] + norm_num + ring + obtain ⟨z, -, hz⟩ := taylor_mean_remainder_lagrange_iteratedDeriv (n := 1) hxy hf.contDiffOn + rw [hp] at hz + have he : f y - f x - deriv f x * (y-x) = iteratedDeriv 2 f z * (y-x)^2/2 := by + norm_num at hz + linarith only [hz] + rw [he, abs_div, abs_mul, abs_of_nonneg (sq_nonneg (y-x))] + norm_num + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right (hC z) (sq_nonneg _)) (by norm_num) + +lemma smooth_deriv_lipschitz {f : ℝ → ℝ} (hf : ContDiff ℝ 2 f) + (C : ℝ≥0) (hC : ∀ x, |iteratedDeriv 2 f x| ≤ C) : LipschitzWith C (deriv f) := by + apply lipschitzWith_of_nnnorm_deriv_le hf.differentiable_deriv_two + intro x + apply NNReal.coe_le_coe.mp + simpa only [iteratedDeriv_succ, iteratedDeriv_one, iteratedDeriv_zero, coe_nnnorm, Real.norm_eq_abs] using hC x + +lemma drift_shift_taylor_bound {f : ℝ → ℝ} (hf : ContDiff ℝ 2 f) + (C : ℝ≥0) (hC : ∀ x, |iteratedDeriv 2 f x| ≤ C) (x z a : ℝ) : + |f (x+z+a) - f (x+z) - deriv f x * a| ≤ (C : ℝ) * (|z| * |a| + a^2/2) := by + have ht := first_order_taylor_bound hf C hC (x+z) (x+z+a) + simp only [add_sub_cancel_left] at ht + have hd := (smooth_deriv_lipschitz hf C hC).dist_le_mul (x+z) x + simp only [Real.dist_eq, add_sub_cancel_left] at hd + calc + _ = |(f (x+z+a) - f (x+z) - deriv f (x+z) * a) + (deriv f (x+z) - deriv f x) * a| := by congr 1; ring + _ ≤ |f (x+z+a) - f (x+z) - deriv f (x+z) * a| + |(deriv f (x+z) - deriv f x) * a| := abs_add_le _ _ + _ ≤ (C : ℝ) * a^2/2 + (C : ℝ) * |z| * |a| := by + rw [abs_mul] + exact add_le_add ht (mul_le_mul_of_nonneg_right hd (abs_nonneg _)) + _ = _ := by ring + +lemma gaussian_abs_moment (v : ℝ≥0) (n : ℕ) : + (∫ x : ℝ, |x| ^ n ∂gaussianReal 0 v) = + (Real.sqrt v)^n * ∫ x : ℝ, |x| ^ n ∂gaussianReal 0 1 := by + have hv : (⟨(Real.sqrt v)^2, sq_nonneg _⟩ : ℝ≥0) = v := by + ext; exact Real.sq_sqrt v.coe_nonneg + have hL := gaussianReal_const_mul (HasLaw.id (μ := gaussianReal 0 1)) (Real.sqrt v) + simp only [mul_zero, NNReal.mk] at hL + rw [hv, mul_one] at hL + rw [← hL.integral_comp (by fun_prop : AEStronglyMeasurable (fun x : ℝ => |x|^n) (gaussianReal 0 v))] + simp only [Function.comp_apply, id_eq, abs_mul, abs_of_nonneg (Real.sqrt_nonneg _), mul_pow] + exact integral_const_mul _ _ + +lemma gaussian_law_integrable_abs_pow {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} {Z : Ω → ℝ} {v : ℝ≥0} (hZ : HasLaw Z (gaussianReal 0 v) P) (n : ℕ) : + Integrable (fun ω => |Z ω|^n) P := by + have hm : MemLp id (n : ℝ≥0∞) (gaussianReal 0 v) := by + simpa using (memLp_id_gaussianReal (μ := 0) (v := v) (n : ℝ≥0)) + have hi : Integrable (fun x : ℝ => |x|^n) (Measure.map Z P) := by + rw [hZ.map_eq] + simpa only [Real.norm_eq_abs, id_eq] using hm.integrable_norm_pow' + exact (integrable_map_measure hi.aestronglyMeasurable hZ.aemeasurable).mp hi + +lemma gaussian_law_sq_mean {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} {Z : Ω → ℝ} {v : ℝ≥0} (hZ : HasLaw Z (gaussianReal 0 v) P) : + (∫ ω, (Z ω)^2 ∂P) = v := by + have hi := hZ.integral_comp (by fun_prop : AEStronglyMeasurable (fun x : ℝ => x^2) + (gaussianReal 0 v)) + have hv := variance_eq_sub (memLp_id_gaussianReal (μ := 0) (v := v) 2) + simp only [variance_id_gaussianReal, Pi.pow_apply, id_eq, integral_id_gaussianReal, + zero_pow (by decide : 2 ≠ 0), sub_zero] at hv + exact hi.trans hv.symm + +lemma bounded_real_integrable {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} [IsFiniteMeasure P] {Y : Ω → ℝ} (hY : AEMeasurable Y P) + (C : ℝ) (hC : ∀ᵐ ω ∂P, |Y ω| ≤ C) : Integrable Y P := by + exact (integrable_const C).mono' hY.aestronglyMeasurable (by simpa only [Real.norm_eq_abs] using hC) + +lemma boundedContinuousFunction_integrable_comp {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} [IsFiniteMeasure P] (f : ℝ →ᵇ ℝ) {X : Ω → ℝ} + (hX : AEMeasurable X P) : Integrable (fun ω => f (X ω)) P := by + exact bounded_real_integrable (f.continuous.measurable.comp_aemeasurable hX) ‖f‖ + (Filter.Eventually.of_forall fun ω => by simpa only [Real.norm_eq_abs] using f.norm_coe_le_norm (X ω)) + +lemma gaussian_taylor_mean_bound {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} [IsProbabilityMeasure P] (f : ℝ →ᵇ ℝ) (hf : ContDiff ℝ 3 (f : ℝ → ℝ)) + (C₁ C₂ C₃ : ℝ) (h₁ : ∀ x, |deriv (f : ℝ → ℝ) x| ≤ C₁) + (h₂ : ∀ x, |iteratedDeriv 2 (f : ℝ → ℝ) x| ≤ C₂) + (h₃ : ∀ x, |iteratedDeriv 3 (f : ℝ → ℝ) x| ≤ C₃) + {X Z : Ω → ℝ} (hX : AEMeasurable X P) {v : ℝ≥0} + (hZ : HasLaw Z (gaussianReal 0 v) P) (hI : IndepFun X Z P) : + |(∫ ω, f (X ω + Z ω) ∂P) - (∫ ω, f (X ω) ∂P) - + (v : ℝ)/2 * ∫ ω, iteratedDeriv 2 (f : ℝ → ℝ) (X ω) ∂P| ≤ + C₃/6 * (Real.sqrt v)^3 * ∫ x : ℝ, |x|^3 ∂gaussianReal 0 1 := by + let d₁ := deriv (f : ℝ → ℝ) + let d₂ := iteratedDeriv 2 (f : ℝ → ℝ) + have hm₁ : Measurable d₁ := (hf.continuous_deriv (by norm_num)).measurable + have hm₂ : Measurable d₂ := (hf.continuous_iteratedDeriv 2 (by norm_num)).measurable + have hi₁ : Integrable (fun ω => d₁ (X ω) * Z ω) P := by + have hz : Integrable Z P := by + have hi := gaussian_law_integrable_abs_pow hZ 1 + exact (integrable_norm_iff hZ.aemeasurable.aestronglyMeasurable).mp (by + simpa only [pow_one, Real.norm_eq_abs] using hi) + apply hz.bdd_mul (hm₁.comp_aemeasurable hX).aestronglyMeasurable + exact Filter.Eventually.of_forall fun ω => by simpa only [Real.norm_eq_abs, Function.comp_apply, d₁] using h₁ (X ω) + have hi₂ : Integrable (fun ω => d₂ (X ω) * (Z ω)^2) P := by + have hz : Integrable (fun ω => (Z ω)^2) P := by + simpa only [sq_abs] using gaussian_law_integrable_abs_pow hZ 2 + apply hz.bdd_mul (hm₂.comp_aemeasurable hX).aestronglyMeasurable + exact Filter.Eventually.of_forall fun ω => by simpa only [Real.norm_eq_abs, Function.comp_apply, d₂] using h₂ (X ω) + have hv₁ : (∫ ω, d₁ (X ω) * Z ω ∂P) = 0 := by + have hh := (hI.comp hm₁ measurable_id).integral_fun_mul_eq_mul_integral + (hm₁.comp_aemeasurable hX).aestronglyMeasurable hZ.aemeasurable.aestronglyMeasurable + have hz : (∫ ω, Z ω ∂P) = 0 := hZ.integral_eq.trans (integral_id_gaussianReal) + simpa only [Function.comp_apply, id_eq, hz, mul_zero] using hh + have hv₂ : (∫ ω, d₂ (X ω) * (Z ω)^2 ∂P) = (v : ℝ) * (∫ ω, d₂ (X ω) ∂P) := by + have hh := (hI.comp hm₂ (measurable_id.pow_const 2)).integral_fun_mul_eq_mul_integral + (hm₂.comp_aemeasurable hX).aestronglyMeasurable (hZ.aemeasurable.pow_const 2).aestronglyMeasurable + simp only [Function.comp_apply, id_eq] at hh + exact hh.trans (by rw [gaussian_law_sq_mean hZ, mul_comm]) + let R := fun ω => f (X ω + Z ω) - f (X ω) - d₁ (X ω) * Z ω - d₂ (X ω) * (Z ω)^2/2 + have hiR : Integrable R P := + (((boundedContinuousFunction_integrable_comp f (hX.add hZ.aemeasurable)).sub + (boundedContinuousFunction_integrable_comp f hX)).sub hi₁).sub (hi₂.div_const 2) + have hR : ∀ ω, |R ω| ≤ C₃/6 * |Z ω|^3 := by + intro ω + have hh := second_order_taylor_bound hf C₃ h₃ (X ω) (X ω + Z ω) + simpa only [add_sub_cancel_left, R, d₁, d₂, div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm] using hh + have hbound : |∫ ω, R ω ∂P| ≤ C₃/6 * ∫ ω, |Z ω|^3 ∂P := by + calc + _ ≤ ∫ ω, |R ω| ∂P := abs_integral_le_integral_abs + _ ≤ ∫ ω, C₃/6 * |Z ω|^3 ∂P := integral_mono hiR.abs + ((gaussian_law_integrable_abs_pow hZ 3).const_mul _) hR + _ = _ := integral_const_mul _ _ + have he : (∫ ω, R ω ∂P) = (∫ ω, f (X ω + Z ω) ∂P) - (∫ ω, f (X ω) ∂P) - + (v : ℝ)/2 * ∫ ω, d₂ (X ω) ∂P := by + have ha := boundedContinuousFunction_integrable_comp f (hX.add hZ.aemeasurable) + have hb := boundedContinuousFunction_integrable_comp f hX + have he₁ := integral_sub ((ha.sub hb).sub hi₁) (hi₂.div_const 2) + have he₂ := integral_sub (ha.sub hb) hi₁ + have he₃ := integral_sub ha hb + simp only [Pi.add_apply, Pi.sub_apply] at he₁ he₂ he₃ + dsimp only [R] + rw [he₁, he₂, he₃, integral_div, hv₁, hv₂] + ring + have hg : (∫ ω, |Z ω|^3 ∂P) = (Real.sqrt v)^3 * ∫ x : ℝ, |x|^3 ∂gaussianReal 0 1 := + (hZ.integral_comp (by fun_prop : AEStronglyMeasurable (fun x : ℝ => |x|^3) (gaussianReal 0 v))).trans + (gaussian_abs_moment v 3) + rw [he, hg] at hbound + exact hbound.trans_eq (by ring) + +lemma drift_shift_mean_bound {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} [IsProbabilityMeasure P] (f : ℝ →ᵇ ℝ) (hf : ContDiff ℝ 2 (f : ℝ → ℝ)) + (C₁ : ℝ) (C₂ K : ℝ≥0) (h₁ : ∀ x, |deriv (f : ℝ → ℝ) x| ≤ C₁) + (h₂ : ∀ x, |iteratedDeriv 2 (f : ℝ → ℝ) x| ≤ C₂) + {X Z A : Ω → ℝ} (hX : AEMeasurable X P) {v : ℝ≥0} + (hZ : HasLaw Z (gaussianReal 0 v) P) (hA : AEMeasurable A P) + (hAK : ∀ ω, |A ω| ≤ K) : + |(∫ ω, f (X ω + Z ω + A ω) ∂P) - (∫ ω, f (X ω + Z ω) ∂P) - + (∫ ω, deriv (f : ℝ → ℝ) (X ω) * A ω ∂P)| ≤ + (C₂ : ℝ) * ((K : ℝ) * Real.sqrt v * (∫ x : ℝ, |x| ∂gaussianReal 0 1) + (K : ℝ)^2/2) := by + let d₁ := deriv (f : ℝ → ℝ) + have hm₁ : Measurable d₁ := (hf.continuous_deriv (by norm_num)).measurable + have hiA := bounded_real_integrable hA K (Filter.Eventually.of_forall hAK) + have hi₁ : Integrable (fun ω => d₁ (X ω) * A ω) P := by + apply hiA.bdd_mul (hm₁.comp_aemeasurable hX).aestronglyMeasurable + exact Filter.Eventually.of_forall fun ω => by + simpa only [Real.norm_eq_abs, Function.comp_apply, d₁] using h₁ (X ω) + have ha := boundedContinuousFunction_integrable_comp f ((hX.add hZ.aemeasurable).add hA) + have hb := boundedContinuousFunction_integrable_comp f (hX.add hZ.aemeasurable) + let R := fun ω => f (X ω + Z ω + A ω) - f (X ω + Z ω) - d₁ (X ω) * A ω + have hiR : Integrable R P := (ha.sub hb).sub hi₁ + have hR : ∀ ω, |R ω| ≤ (C₂ : ℝ) * (|Z ω| * (K : ℝ) + (K : ℝ)^2/2) := by + intro ω + apply (drift_shift_taylor_bound hf C₂ h₂ (X ω) (Z ω) (A ω)).trans + apply mul_le_mul_of_nonneg_left _ C₂.coe_nonneg + have hsq : A ω ^2 ≤ (K : ℝ)^2 := by + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg (A ω)) K.coe_nonneg).mpr (hAK ω) + exact add_le_add (mul_le_mul_of_nonneg_left (hAK ω) (abs_nonneg _)) (by linarith) + have hiz : Integrable (fun ω => |Z ω|) P := by + simpa only [pow_one] using gaussian_law_integrable_abs_pow hZ 1 + have hbound : |∫ ω, R ω ∂P| ≤ + (C₂ : ℝ) * ((∫ ω, |Z ω| ∂P) * (K : ℝ) + (K : ℝ)^2/2) := by + calc + _ ≤ ∫ ω, |R ω| ∂P := abs_integral_le_integral_abs + _ ≤ ∫ ω, (C₂ : ℝ) * (|Z ω| * (K : ℝ) + (K : ℝ)^2/2) ∂P := + integral_mono hiR.abs (((hiz.mul_const K).add (integrable_const _)).const_mul C₂) hR + _ = _ := by rw [integral_const_mul, integral_add (hiz.mul_const K) (integrable_const _), integral_mul_const]; simp + have he : (∫ ω, R ω ∂P) = (∫ ω, f (X ω + Z ω + A ω) ∂P) - + (∫ ω, f (X ω + Z ω) ∂P) - (∫ ω, d₁ (X ω) * A ω ∂P) := by + have he₁ := integral_sub (ha.sub hb) hi₁ + have he₂ := integral_sub ha hb + simp only [Pi.add_apply, Pi.sub_apply] at he₁ he₂ + exact he₁.trans (by rw [he₂]) + have hg : (∫ ω, |Z ω| ∂P) = Real.sqrt v * ∫ x : ℝ, |x| ∂gaussianReal 0 1 := by + have hh := (hZ.integral_comp (by fun_prop : AEStronglyMeasurable (fun x : ℝ => |x|^1) (gaussianReal 0 v))).trans + (gaussian_abs_moment v 1) + simpa only [pow_one, Function.comp_apply] using hh + rw [he, hg] at hbound + exact hbound.trans_eq (by ring) + +lemma gaussian_drift_taylor_mean_bound {Ω : Type*} [MeasurableSpace Ω] + {P : Measure Ω} [IsProbabilityMeasure P] (f : ℝ →ᵇ ℝ) (hf : ContDiff ℝ 3 (f : ℝ → ℝ)) + (C₁ C₃ : ℝ) (C₂ K : ℝ≥0) (h₁ : ∀ x, |deriv (f : ℝ → ℝ) x| ≤ C₁) + (h₂ : ∀ x, |iteratedDeriv 2 (f : ℝ → ℝ) x| ≤ C₂) + (h₃ : ∀ x, |iteratedDeriv 3 (f : ℝ → ℝ) x| ≤ C₃) + {X Z A : Ω → ℝ} (hX : AEMeasurable X P) {v : ℝ≥0} + (hZ : HasLaw Z (gaussianReal 0 v) P) (hI : IndepFun X Z P) (hA : AEMeasurable A P) + (hAK : ∀ ω, |A ω| ≤ K) : + |(∫ ω, f (X ω + Z ω + A ω) ∂P) - (∫ ω, f (X ω) ∂P) - + (∫ ω, deriv (f : ℝ → ℝ) (X ω) * A ω ∂P) - + (v : ℝ)/2 * ∫ ω, iteratedDeriv 2 (f : ℝ → ℝ) (X ω) ∂P| ≤ + (C₂ : ℝ) * ((K : ℝ) * Real.sqrt v * (∫ x : ℝ, |x| ∂gaussianReal 0 1) + (K : ℝ)^2/2) + + C₃/6 * (Real.sqrt v)^3 * ∫ x : ℝ, |x|^3 ∂gaussianReal 0 1 := by + have hG := gaussian_taylor_mean_bound f hf C₁ C₂ C₃ h₁ h₂ h₃ hX hZ hI + have hD := drift_shift_mean_bound f (hf.of_le (by norm_num)) C₁ C₂ K h₁ h₂ hX hZ hA hAK + have hh := abs_add_le + ((∫ ω, f (X ω + Z ω + A ω) ∂P) - (∫ ω, f (X ω + Z ω) ∂P) - + (∫ ω, deriv (f : ℝ → ℝ) (X ω) * A ω ∂P)) + ((∫ ω, f (X ω + Z ω) ∂P) - (∫ ω, f (X ω) ∂P) - + (v : ℝ)/2 * ∫ ω, iteratedDeriv 2 (f : ℝ → ℝ) (X ω) ∂P) + convert hh.trans (add_le_add hD hG) using 1 + congr 1 + ring + +def gaussianAverage (s : ℝ≥0) (f : ℝ → ℝ) (x : ℝ) : ℝ := + ∫ z, f (x + z) ∂gaussianReal 0 s + +lemma gaussianAverage_integrable (s : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : + Integrable (fun z => f (x + z)) (gaussianReal 0 s) := + boundedContinuousFunction_integrable_comp f (by fun_prop) + +lemma gaussianAverage_abs_le (s : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : + |gaussianAverage s f x| ≤ ‖f‖ := by + simpa [gaussianAverage, Real.norm_eq_abs] using + norm_integral_le_of_norm_le_const (μ := gaussianReal 0 s) + (Filter.Eventually.of_forall fun z => f.norm_coe_le_norm (x+z)) + +lemma gaussianAverage_continuous (s : ℝ≥0) (f : ℝ →ᵇ ℝ) : + Continuous (gaussianAverage s f) := by + apply continuous_of_dominated (bound := fun _ => ‖f‖) + · intro x; exact (gaussianAverage_integrable s f x).aestronglyMeasurable + · intro x; exact Filter.Eventually.of_forall fun z => f.norm_coe_le_norm (x+z) + · exact integrable_const _ + · exact Filter.Eventually.of_forall fun z => f.continuous.comp (continuous_id.add continuous_const) + +def gaussianAverageBCF (s : ℝ≥0) (f : ℝ →ᵇ ℝ) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound ⟨gaussianAverage s f, gaussianAverage_continuous s f⟩ + (2*‖f‖) (by + intro x y + change |gaussianAverage s f x - gaussianAverage s f y| ≤ 2 * ‖f‖ + exact (abs_sub _ _).trans (by linarith [gaussianAverage_abs_le s f x, gaussianAverage_abs_le s f y])) + +@[simp] lemma gaussianAverageBCF_coe (s : ℝ≥0) (f : ℝ →ᵇ ℝ) : + (gaussianAverageBCF s f : ℝ → ℝ) = gaussianAverage s f := rfl + +@[simp] lemma gaussianAverage_zero (f : ℝ →ᵇ ℝ) (x : ℝ) : + gaussianAverage 0 f x = f x := by simp [gaussianAverage] + +lemma gaussianAverage_semigroup (s t : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : + gaussianAverage s (gaussianAverageBCF t f) x = gaussianAverage (s+t) f x := by + have hi : Integrable (fun z => f (x+z)) ((gaussianReal 0 s) ∗ (gaussianReal 0 t)) := by + rw [gaussianReal_conv_gaussianReal, zero_add] + exact gaussianAverage_integrable (s+t) f x + have hh := integral_conv hi + simp only [gaussianReal_conv_gaussianReal, zero_add] at hh + simpa only [gaussianAverage, gaussianAverageBCF_coe, add_assoc] using hh.symm + +lemma gaussianAverage_hasDerivAt (s : ℝ≥0) (f f' : ℝ →ᵇ ℝ) + (hf : ∀ x, HasDerivAt (f : ℝ → ℝ) (f' x) x) (x : ℝ) : + HasDerivAt (gaussianAverage s f) (gaussianAverage s f' x) x := by + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le (s := Set.univ) + (F := fun x z => f (x+z)) (F' := fun x z => f' (x+z)) (bound := fun _ => ‖f'‖) + (μ := gaussianReal 0 s) (by simp) + (Filter.Eventually.of_forall fun x => (gaussianAverage_integrable s f x).aestronglyMeasurable) + (gaussianAverage_integrable s f x) + (gaussianAverage_integrable s f' x).aestronglyMeasurable + (Filter.Eventually.of_forall fun z x _ => f'.norm_coe_le_norm (x+z)) (integrable_const _) + (Filter.Eventually.of_forall fun z x _ => by convert! (hf (x+z)).comp x ((hasDerivAt_id x).add_const z) using 1; simp only [mul_one])).2 + +lemma gaussianAverage_deriv (s : ℝ≥0) (f f' : ℝ →ᵇ ℝ) + (hf : ∀ x, HasDerivAt (f : ℝ → ℝ) (f' x) x) : + deriv (gaussianAverage s f) = gaussianAverage s f' := by + funext x; exact (gaussianAverage_hasDerivAt s f f' hf x).deriv + +lemma exp_bcf_bound (d : ℝ) (f : ℝ →ᵇ ℝ) (x : ℝ) : + |Real.exp (d * f x)| ≤ Real.exp (|d| * ‖f‖) := by + rw [abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + calc + d * f x ≤ |d * f x| := le_abs_self _ + _ = |d| * |f x| := abs_mul _ _ + _ ≤ |d| * ‖f‖ := mul_le_mul_of_nonneg_left + (by simpa only [Real.norm_eq_abs] using f.norm_coe_le_norm x) (abs_nonneg d) + +def expBCF (d : ℝ) (f : ℝ →ᵇ ℝ) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound ⟨fun x => Real.exp (d*f x), by fun_prop⟩ + (2 * Real.exp (|d| * ‖f‖)) (by + intro x y; change |Real.exp (d * f x) - Real.exp (d * f y)| ≤ 2 * Real.exp (|d| * ‖f‖) + exact (abs_sub _ _).trans (by linarith [exp_bcf_bound d f x, exp_bcf_bound d f y])) + +@[simp] lemma expBCF_apply (d : ℝ) (f : ℝ →ᵇ ℝ) (x : ℝ) : + expBCF d f x = Real.exp (d * f x) := rfl + +lemma gaussianAverage_exp_pos (s : ℝ≥0) (d : ℝ) (f : ℝ →ᵇ ℝ) (x : ℝ) : + 0 < gaussianAverage s (expBCF d f) x := by + apply integral_pos_iff_support_of_nonneg (fun z => (Real.exp_pos (d*f (x+z))).le) + (gaussianAverage_integrable s (expBCF d f) x) |>.mpr + simpa only [Function.support, expBCF_apply, ne_eq, Real.exp_ne_zero, not_false_eq_true, + Set.ofPred_true, measure_univ] using (zero_lt_one : (0 : ℝ≥0∞) < 1) + +lemma gaussianAverage_exp_bounds (s : ℝ≥0) (d : ℝ) (hd : 0 ≤ d) (f : ℝ →ᵇ ℝ) (x : ℝ) : + Real.exp (-d*‖f‖) ≤ gaussianAverage s (expBCF d f) x ∧ + gaussianAverage s (expBCF d f) x ≤ Real.exp (d*‖f‖) := by + have hf : ∀ z, |f (x+z)| ≤ ‖f‖ := fun z => by simpa only [Real.norm_eq_abs] using f.norm_coe_le_norm (x+z) + constructor + · have hi := integral_mono (integrable_const (Real.exp (-d*‖f‖))) + (gaussianAverage_integrable s (expBCF d f) x) (fun z => + Real.exp_le_exp.mpr (by nlinarith [(abs_le.mp (hf z)).1])) + simpa only [gaussianAverage, integral_const, probReal_univ, smul_eq_mul, one_mul] using hi + · have hi := integral_mono (gaussianAverage_integrable s (expBCF d f) x) + (integrable_const (Real.exp (d*‖f‖))) (fun z => + Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left (abs_le.mp (hf z)).2 hd)) + simpa only [gaussianAverage, integral_const, probReal_univ, smul_eq_mul, one_mul] using hi + +def heatLog (s : ℝ≥0) (d : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : ℝ := + if d = 0 then gaussianAverage s f x else (d : ℝ)⁻¹ * Real.log (gaussianAverage s (expBCF d f) x) + +lemma heatLog_abs_le (s d : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : |heatLog s d f x| ≤ ‖f‖ := by + unfold heatLog + split_ifs with hd + · exact gaussianAverage_abs_le s f x + have hd' : (0 : ℝ) < d := NNReal.coe_pos.mpr (pos_iff_ne_zero.mpr hd) + obtain ⟨hlo,hhi⟩ := gaussianAverage_exp_bounds s d d.coe_nonneg f x + have hz := gaussianAverage_exp_pos s d f x + have hl := Real.log_le_log (Real.exp_pos _) hlo + have hu := Real.log_le_log hz hhi + rw [Real.log_exp] at hl hu + rw [abs_le] + constructor <;> nlinarith [mul_le_mul_of_nonneg_left hl (inv_nonneg.mpr hd'.le), + mul_le_mul_of_nonneg_left hu (inv_nonneg.mpr hd'.le), inv_mul_cancel₀ hd'.ne'] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianBackward.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianBackward.lean new file mode 100644 index 0000000000000000000000000000000000000000..019ce57964dbc7289f17fe0ef0488c7cf05ae641 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianBackward.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CompactGGFiniteCode + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +section +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] + +def gaussianBackward (μ : Measure E) : List (ℝ×ℝ) → (E → ℝ) → E → ℝ + | [], f => f + | (p,σ)::l, f => gaussianEntropic μ p σ (gaussianBackward μ l f) + +lemma gaussianBackward_lipschitz {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (l : List (ℝ×ℝ)) (hl : ∀ a ∈ l, 0 ≤ a.1) : + LipschitzWith L (gaussianBackward μ l f) := by + induction l with + | nil => exact hf + | cons a l ih => + exact gaussianEntropic_lipschitz μ (ih (fun b hb => hl b (List.mem_cons_of_mem _ hb))) + (hl a (List.mem_cons_self)) + +lemma gaussianBackward_add_const {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (l : List (ℝ×ℝ)) (hl : ∀ a ∈ l, 0 ≤ a.1) (c : ℝ) : + gaussianBackward μ l (fun x => f x+c)=(fun x => gaussianBackward μ l f x+c) := by + induction l with + | nil => rfl + | cons a l ih => + have htail := fun b hb => hl b (List.mem_cons_of_mem a hb) + simp only [gaussianBackward,ih htail] + funext x + exact gaussianEntropic_add_const μ (gaussianBackward_lipschitz μ hf l htail) _ _ _ _ + +lemma gaussianBackward_append {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [CompleteSpace E] [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] (l m : List (ℝ×ℝ)) (f : E → ℝ) : + gaussianBackward μ (l++m) f=gaussianBackward μ l (gaussianBackward μ m f) := by + induction l with + | nil => rfl + | cons a l ih => simp only [List.cons_append,gaussianBackward,ih] + +lemma gaussianBackward_mono {f g : E → ℝ} {L M : ℝ≥0} + (hf : LipschitzWith L f) (hg : LipschitzWith M g) + (l : List (ℝ×ℝ)) (hl : ∀ a ∈ l, 0 ≤ a.1) (hfg : ∀ x, f x ≤ g x) : + ∀ x, gaussianBackward μ l f x ≤ gaussianBackward μ l g x := by + induction l with + | nil => exact hfg + | cons a l ih => + have htail := fun b hb => hl b (List.mem_cons_of_mem a hb) + exact gaussianEntropic_mono μ (gaussianBackward_lipschitz μ hf l htail) + (gaussianBackward_lipschitz μ hg l htail) (hl a List.mem_cons_self) a.2 (ih htail) + +lemma gaussianBackward_bounded_difference {f g : E → ℝ} {L M : ℝ≥0} + (hf : LipschitzWith L f) (hg : LipschitzWith M g) + (l : List (ℝ×ℝ)) (hl : ∀ a ∈ l, 0 ≤ a.1) {C : ℝ} + (hfg : ∀ x, |f x-g x| ≤ C) (x : E) : + |gaussianBackward μ l f x-gaussianBackward μ l g x| ≤ C := by + induction l generalizing x with + | nil => exact hfg x + | cons a l ih => + have htail := fun b hb => hl b (List.mem_cons_of_mem a hb) + apply entropicMean_bounded_difference μ + (fun t => gaussian_integrable_exp_lipschitz μ (gaussianBackward_lipschitz μ hf l htail) t a.2 x) + (fun t => gaussian_integrable_exp_lipschitz μ (gaussianBackward_lipschitz μ hg l htail) t a.2 x) + (hl a List.mem_cons_self) + exact ae_of_all _ fun y => ih htail (x+a.2 • y) + +lemma gaussianBackward_mono_parameters {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (l : List (ℝ×ℝ)) (a b : ℝ → ℝ) + (ha : ∀ c ∈ l, 0 ≤ a c.1) (hab : ∀ c ∈ l, a c.1 ≤ b c.1) : + ∀ x, gaussianBackward μ (l.map fun c => (a c.1,c.2)) f x ≤ + gaussianBackward μ (l.map fun c => (b c.1,c.2)) f x := by + have hb : ∀ c ∈ l, 0 ≤ b c.1 := fun c hc => (ha c hc).trans (hab c hc) + induction l with + | nil => intro x; exact le_rfl + | cons c l ih => + have ha' := fun d hd => ha d (List.mem_cons_of_mem c hd) + have hb' := fun d hd => hb d (List.mem_cons_of_mem c hd) + have hab' := fun d hd => hab d (List.mem_cons_of_mem c hd) + have hla : LipschitzWith L (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) := by + apply gaussianBackward_lipschitz μ hf + intro d hd + obtain ⟨e,he,rfl⟩ := List.mem_map.mp hd + exact ha' e he + have hlb : LipschitzWith L (gaussianBackward μ (l.map fun d => (b d.1,d.2)) f) := by + apply gaussianBackward_lipschitz μ hf + intro d hd + obtain ⟨e,he,rfl⟩ := List.mem_map.mp hd + exact hb' e he + intro x + simp only [List.map_cons,gaussianBackward] + calc + _ ≤ gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) x := + gaussianEntropic_mono_parameter μ hla c.2 x (hab c List.mem_cons_self) + _ ≤ _ := gaussianEntropic_mono μ hla hlb (hb c List.mem_cons_self) c.2 (ih ha' hab' hb') x + +lemma gaussianBackward_parameter_bound {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (l : List (ℝ×ℝ)) (a b : ℝ → ℝ) {S : ℝ} + (ha : ∀ c ∈ l, a c.1 ∈ Icc (0:ℝ) 1) (hb : ∀ c ∈ l, b c.1 ∈ Icc (0:ℝ) 1) + (hσ : ∀ c ∈ l, c.2 ∈ Icc (0:ℝ) S) : ∀ x, + |gaussianBackward μ (l.map fun c => (a c.1,c.2)) f x- + gaussianBackward μ (l.map fun c => (b c.1,c.2)) f x| ≤ + gaussianEntropicParamConstant μ L S*(l.map fun c => c.2^2*|a c.1-b c.1|).sum := by + induction l with + | nil => intro x; simp [gaussianBackward] + | cons c l ih => + have ha' := fun d hd => ha d (List.mem_cons_of_mem c hd) + have hb' := fun d hd => hb d (List.mem_cons_of_mem c hd) + have hσ' := fun d hd => hσ d (List.mem_cons_of_mem c hd) + have hla : LipschitzWith L (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) := by + apply gaussianBackward_lipschitz μ hf + intro d hd + obtain ⟨e,he,rfl⟩ := List.mem_map.mp hd + exact (ha' e he).1 + have hlb : LipschitzWith L (gaussianBackward μ (l.map fun d => (b d.1,d.2)) f) := by + apply gaussianBackward_lipschitz μ hf + intro d hd + obtain ⟨e,he,rfl⟩ := List.mem_map.mp hd + exact (hb' e he).1 + intro x + simp only [List.map_cons,List.sum_cons,gaussianBackward] + have H1 := gaussianEntropic_parameter_bound μ hla (ha c List.mem_cons_self) + (hb c List.mem_cons_self) (hσ c List.mem_cons_self).1 (hσ c List.mem_cons_self).2 x + have H2 := entropicMean_bounded_difference μ + (fun t => gaussian_integrable_exp_lipschitz μ hla t c.2 x) + (fun t => gaussian_integrable_exp_lipschitz μ hlb t c.2 x) (hb c List.mem_cons_self).1 + (ae_of_all _ fun y => ih ha' hb' hσ' (x+c.2 • y)) + have HT := abs_sub_le (gaussianEntropic μ (a c.1) c.2 (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) x) + (gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) x) + (gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (b d.1,d.2)) f) x) + dsimp [entropicMean] at H2 + change |gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) x- + gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (b d.1,d.2)) f) x| ≤ _ at H2 + nlinarith + +end + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussianBackward_merge {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (l : List (ℝ×ℝ)) (hl : ∀ c ∈ l, 0 ≤ c.1) {p : ℝ} (hp : 0 ≤ p) (σ τ : ℝ) : + gaussianBackward (stdGaussian E) ((p,σ)::(p,τ)::l) f= + gaussianBackward (stdGaussian E) ((p,Real.sqrt (σ^2+τ^2))::l) f := by + funext x + exact gaussianEntropic_semigroup (gaussianBackward_lipschitz (stdGaussian E) hf l hl) hp σ τ x + +lemma gaussianBackward_delete_zero {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (l : List (ℝ×ℝ)) (hl : ∀ c ∈ l, 0 ≤ c.1) (p : ℝ) : + gaussianBackward (stdGaussian E) ((p,0)::l) f=gaussianBackward (stdGaussian E) l f := by + funext x + exact gaussianEntropic_variance_zero (gaussianBackward_lipschitz (stdGaussian E) hf l hl) p x + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianBlock.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianBlock.lean new file mode 100644 index 0000000000000000000000000000000000000000..39224d5e0b9df895d14775b61f17847e5a787dad --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianBlock.lean @@ -0,0 +1,54 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.GaussianPolar + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped Topology ENNReal NNReal +namespace SphericalPerceptronFreeEnergy + +def gaussianBlockSplit (N L : ℕ) (x : Spin (N+L)) : Spin N × Spin L := + (WithLp.toLp 2 (fun i => x (Fin.castAdd L i)),WithLp.toLp 2 (fun j => x (Fin.natAdd N j))) + +lemma gaussianBlockSplit_measurable (N L : ℕ) : Measurable (gaussianBlockSplit N L) := by + unfold gaussianBlockSplit + fun_prop + +lemma gaussianBlockSplit_preserving (N L : ℕ) : + MeasurePreserving (gaussianBlockSplit N L) (stdGaussian (Spin (N+L))) + ((stdGaussian (Spin N)).prod (stdGaussian (Spin L))) := by + have hp := (measurePreserving_sumPiEquivProdPi (fun _ : Fin N ⊕ Fin L => gaussianReal 0 1)).comp + (measurePreserving_piCongrLeft (fun _ : Fin N ⊕ Fin L => gaussianReal 0 1) finSumFinEquiv.symm) + have hN : MeasurePreserving (WithLp.toLp 2 : (Fin N→ℝ)→Spin N) + (Measure.pi fun _ => gaussianReal 0 1) (stdGaussian (Spin N)) := + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + have hL : MeasurePreserving (WithLp.toLp 2 : (Fin L→ℝ)→Spin L) + (Measure.pi fun _ => gaussianReal 0 1) (stdGaussian (Spin L)) := + ⟨(PiLp.continuous_toLp 2 _).measurable,map_pi_eq_stdGaussian⟩ + refine ⟨gaussianBlockSplit_measurable N L,?_⟩ + rw [←map_pi_eq_stdGaussian,Measure.map_map (gaussianBlockSplit_measurable N L) + (PiLp.continuous_toLp 2 _).measurable] + convert ((hN.prod hL).comp hp).map_eq using 1 + congr 1 + funext x + apply Prod.ext <;> ext i <;> + simp [gaussianBlockSplit,MeasurableEquiv.piCongrLeft,MeasurableEquiv.sumPiEquivProdPi, + Equiv.piCongrLeft,Equiv.piCongrLeft',eq_rec_constant] + +lemma gaussianBlockSplit_norm_sq (N L : ℕ) (x : Spin (N+L)) : + ‖x‖^2=‖(gaussianBlockSplit N L x).1‖^2+‖(gaussianBlockSplit N L x).2‖^2 := by + simp only [EuclideanSpace.norm_sq_eq,gaussianBlockSplit,Real.norm_eq_abs,sq_abs] + exact Fin.sum_univ_add _ + +lemma stdGaussian_direction_law (n : ℕ) : + (stdGaussian (Spin (n+1))).map (fun x => ‖x‖⁻¹ •x)= + (unitSphereLaw (n+1)).map Subtype.val := by + have : IsProbabilityMeasure ((gaussianRadiusLaw n).map Subtype.val) := inferInstance + have h := congrArg (fun μ : Measure (ℝ×Spin (n+1)) => μ.map Prod.snd) (normalizedGaussian_polar_law n) + rwa [Measure.map_map measurable_snd (by fun_prop),Measure.map_snd_prod,measure_univ,one_smul] at h + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianBoltzmann.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianBoltzmann.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d1c7b9b717b4eb56679097c3dc96782373947bd --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianBoltzmann.lean @@ -0,0 +1,236 @@ +import Mathlib +import OAI.Probability.Perceptron.Brownian.CountableGaussianField +import OAI.Probability.Perceptron.Variational.IntegrableGibbs + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +section + +lemma integrable_prod_of_nonneg_uniform_integral {X Y : Type*} + [MeasurableSpace X] [MeasurableSpace Y] (μ : Measure X) (ν : Measure Y) + [IsProbabilityMeasure μ] [SFinite ν] {F : X×Y → ℝ} {C : ℝ} + (hF : Measurable F) (hpos : ∀ p, 0 ≤ F p) + (hi : ∀ x, Integrable (fun y => F (x,y)) ν) + (hb : ∀ x, (∫ y, F (x,y) ∂ν) ≤ C) : Integrable F (μ.prod ν) := by + apply (integrable_prod_iff hF.aestronglyMeasurable).mpr + refine ⟨ae_of_all _ hi,?_⟩ + apply (integrable_const C).mono' hF.aestronglyMeasurable.norm.integral_prod_right' + exact ae_of_all _ fun x => by + simp only [Real.norm_eq_abs,abs_of_nonneg (hpos _)] + rw [abs_of_nonneg (integral_nonneg fun y => hpos (x,y))] + exact hb x + +lemma exp_square_sub_bound (a b : ℝ) : + (Real.exp a-Real.exp b)^2 ≤ 2*Real.exp (2*a)+2*Real.exp (2*b) := by + rw [show 2*a=a+a by ring,Real.exp_add,show 2*b=b+b by ring,Real.exp_add] + nlinarith [sq_nonneg (Real.exp a+Real.exp b)] + +variable {S : Type*} [MeasurableSpace S] +variable (μ : Measure S) [IsProbabilityMeasure μ] +variable {v : ℕ → S → ℝ} {L : S → ℕ} +variable (hv : ∀ i, Measurable (v i)) (hL : Measurable L) +variable {D : ℝ} (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) +include hv hL hD + +lemma countableGaussianField_exp_joint_integrable (t : ℝ) : + Integrable (fun p : S×(ℕ → ℝ) => Real.exp (t*countableGaussianField v L p.2 p.1)) + (μ.prod countableGaussianLaw) := by + apply integrable_prod_of_nonneg_uniform_integral μ countableGaussianLaw + (((countableGaussianField_measurable hv hL).comp measurable_swap).const_mul t).exp + (fun p => (Real.exp_pos _).le) + (fun x => countableGaussianField_exp_integrable v L x t) + exact fun x => countableGaussianField_exp_integral_le v L hD x t + +lemma truncatedCountableGaussianField_exp_joint_integrable (n : ℕ) (t : ℝ) : + Integrable (fun p : S×(ℕ → ℝ) => + Real.exp (t*truncatedCountableGaussianField v L n p.2 p.1)) + (μ.prod countableGaussianLaw) := by + apply integrable_prod_of_nonneg_uniform_integral μ countableGaussianLaw + (((truncatedCountableGaussianField_measurable hv hL n).comp measurable_swap).const_mul t).exp + (fun p => (Real.exp_pos _).le) + (fun x => gaussianPrefixField_exp_integrable (maskedGaussianCoefficient v L) n x t) + exact fun x => truncatedCountableGaussianField_exp_integral_le v L hD n x t + +omit hD in +lemma gaussianBoltzmann_difference_sq_integrable (n : ℕ) (t : ℝ) (x : S) : + Integrable (fun g => (Real.exp (t*truncatedCountableGaussianField v L n g x)- + Real.exp (t*countableGaussianField v L g x))^2) countableGaussianLaw := by + apply (((gaussianPrefixField_exp_integrable (maskedGaussianCoefficient v L) n x (2*t)).const_mul 2).add + ((countableGaussianField_exp_integrable v L x (2*t)).const_mul 2)).mono' + · exact (((Real.measurable_exp.comp ((measurable_const.mul + ((truncatedCountableGaussianField_measurable hv hL n).comp (measurable_id.prodMk measurable_const))))).sub + (Real.measurable_exp.comp (measurable_const.mul + ((countableGaussianField_measurable hv hL).comp (measurable_id.prodMk measurable_const))))).pow_const 2).aestronglyMeasurable + · exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs,abs_sq,mul_assoc,Pi.add_apply,truncatedCountableGaussianField] using + exp_square_sub_bound (t*truncatedCountableGaussianField v L n g x) + (t*countableGaussianField v L g x) + +lemma gaussianBoltzmann_difference_sq_integral_le (n : ℕ) (t : ℝ) (x : S) : + (∫ g, (Real.exp (t*truncatedCountableGaussianField v L n g x)- + Real.exp (t*countableGaussianField v L g x))^2 ∂countableGaussianLaw) ≤ + 4*Real.exp ((2*t)^2*D/2) := by + calc + _ ≤ ∫ g, 2*Real.exp ((2*t)*truncatedCountableGaussianField v L n g x)+ + 2*Real.exp ((2*t)*countableGaussianField v L g x) ∂countableGaussianLaw := by + apply integral_mono (gaussianBoltzmann_difference_sq_integrable hv hL n t x) + (((gaussianPrefixField_exp_integrable (maskedGaussianCoefficient v L) n x (2*t)).const_mul 2).add + ((countableGaussianField_exp_integrable v L x (2*t)).const_mul 2)) + intro g + simpa only [mul_assoc,Pi.add_apply,truncatedCountableGaussianField] using exp_square_sub_bound + (t*truncatedCountableGaussianField v L n g x) (t*countableGaussianField v L g x) + _ ≤ _ := by + change (∫ g, 2*Real.exp ((2*t)*gaussianPrefixField (maskedGaussianCoefficient v L) n g x)+ + 2*Real.exp ((2*t)*countableGaussianField v L g x) ∂countableGaussianLaw) ≤ _ + rw [integral_add + ((gaussianPrefixField_exp_integrable (maskedGaussianCoefficient v L) n x (2*t)).const_mul 2) + ((countableGaussianField_exp_integrable v L x (2*t)).const_mul 2),integral_const_mul,integral_const_mul] + have h1 := truncatedCountableGaussianField_exp_integral_le v L hD n x (2*t) + change (∫ g, Real.exp ((2*t)*gaussianPrefixField (maskedGaussianCoefficient v L) n g x) ∂countableGaussianLaw) ≤ _ at h1 + linarith [countableGaussianField_exp_integral_le v L hD x (2*t)] + +lemma gaussianBoltzmann_difference_sq_joint_integrable (n : ℕ) (t : ℝ) : + Integrable (fun p : S×(ℕ → ℝ) => (Real.exp (t*truncatedCountableGaussianField v L n p.2 p.1)- + Real.exp (t*countableGaussianField v L p.2 p.1))^2) (μ.prod countableGaussianLaw) := by + apply integrable_prod_of_nonneg_uniform_integral μ countableGaussianLaw + (((((truncatedCountableGaussianField_measurable hv hL n).comp measurable_swap).const_mul t).exp.sub + ((((countableGaussianField_measurable hv hL).comp measurable_swap).const_mul t).exp)).pow_const 2) + (fun _ => sq_nonneg _) (gaussianBoltzmann_difference_sq_integrable hv hL n t) + exact gaussianBoltzmann_difference_sq_integral_le hv hL hD n t + +lemma gaussianBoltzmann_truncation_L2 (t : ℝ) : + Tendsto (fun n => ∫ p : S×(ℕ → ℝ), + (Real.exp (t*truncatedCountableGaussianField v L n p.2 p.1)- + Real.exp (t*countableGaussianField v L p.2 p.1))^2 ∂(μ.prod countableGaussianLaw)) + atTop (nhds 0) := by + have hm (n : ℕ) := (gaussianBoltzmann_difference_sq_joint_integrable μ hv hL hD n t) + simp_rw [integral_prod _ (hm _)] + have hh := tendsto_integral_of_dominated_convergence (f := fun _ : S => (0 : ℝ)) + (fun _ : S => 4*Real.exp ((2*t)^2*D/2)) + (fun n => (hm n).integral_prod_left.aestronglyMeasurable) + (integrable_const _) + (fun n => ae_of_all μ fun x => by + rw [Real.norm_eq_abs,abs_of_nonneg (integral_nonneg (fun _ => sq_nonneg _))] + exact gaussianBoltzmann_difference_sq_integral_le hv hL hD n t x) + (ae_of_all μ fun x => by + apply tendsto_const_nhds.congr' + filter_upwards [truncatedCountableGaussianField_eventually_eq v L x] with n hn + simp only [hn,sub_self,zero_pow (by omega : (2 : ℕ)≠0),integral_zero]) + simpa only [integral_zero] using hh + +end +variable {S : Type*} [MeasurableSpace S] + +def countableGaussianHamiltonian (W : S → ℝ) (v : ℕ → S → ℝ) (L : S → ℕ) + (g : ℕ → ℝ) (x : S) : ℝ := W x+countableGaussianField v L g x + +lemma countableGaussianHamiltonian_measurable {W : S → ℝ} {v : ℕ → S → ℝ} {L : S → ℕ} + (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hL : Measurable L) : + Measurable (Function.uncurry (countableGaussianHamiltonian W v L)) := + (hW.comp measurable_snd).add (countableGaussianField_measurable hv hL) + +variable (μ : Measure S) [IsProbabilityMeasure μ] +variable {W : S → ℝ} {v : ℕ → S → ℝ} {L : S → ℕ} +variable (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hL : Measurable L) +variable {A D : ℝ} (hA : ∀ x, |W x| ≤ A) (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) + +omit [MeasurableSpace S] in +lemma countableGaussianHamiltonian_exp_integrable (x : S) (t : ℝ) : + Integrable (fun g => Real.exp (t*countableGaussianHamiltonian W v L g x)) countableGaussianLaw := by + simp only [countableGaussianHamiltonian,mul_add,Real.exp_add] + exact (countableGaussianField_exp_integrable v L x t).const_mul _ + +include hA hD in +omit [MeasurableSpace S] in +lemma countableGaussianHamiltonian_exp_integral_bound (x : S) (t : ℝ) : + (∫ g, Real.exp (t*countableGaussianHamiltonian W v L g x) ∂countableGaussianLaw) ≤ + Real.exp (|t| * A+t^2*D/2) := by + simp only [countableGaussianHamiltonian,mul_add,Real.exp_add,integral_const_mul] + apply mul_le_mul + · apply Real.exp_le_exp.mpr + exact (le_abs_self _).trans (by rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hA x) (abs_nonneg t)) + · exact countableGaussianField_exp_integral_le v L hD x t + · exact integral_nonneg (fun _ => (Real.exp_pos _).le) + · exact (Real.exp_pos _).le + +include hW hv hL hA hD in +lemma countableGaussianHamiltonian_exp_joint_integrable (t : ℝ) : + Integrable (fun p : S×(ℕ → ℝ) => Real.exp (t*countableGaussianHamiltonian W v L p.2 p.1)) + (μ.prod countableGaussianLaw) := by + apply integrable_prod_of_nonneg_uniform_integral μ countableGaussianLaw + (((countableGaussianHamiltonian_measurable hW hv hL).comp measurable_swap).const_mul t).exp + (fun _ => (Real.exp_pos _).le) + (fun x => countableGaussianHamiltonian_exp_integrable x t) + exact fun x => countableGaussianHamiltonian_exp_integral_bound hA hD x t + +include hW hv hL hA hD in +lemma countableGaussianHamiltonian_joint_integrable : + Integrable (fun p : S×(ℕ → ℝ) => countableGaussianHamiltonian W v L p.2 p.1) + (μ.prod countableGaussianLaw) := by + apply integrable_of_exp_pos_neg _ ((countableGaussianHamiltonian_measurable hW hv hL).comp measurable_swap) + · simpa only [one_mul,Function.comp_def,Function.uncurry,Prod.swap] using countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1 + · simpa only [neg_one_mul,Function.comp_def,Function.uncurry,Prod.swap] using countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD (-1) + +include hW hv hL hA hD in +lemma countableGaussianHamiltonian_exp_double_integral_bound (t : ℝ) : + (∫ g, ∫ x, Real.exp (t*countableGaussianHamiltonian W v L g x) ∂μ ∂countableGaussianLaw) ≤ + Real.exp (|t| * A+t^2*D/2) := by + rw [← integral_integral_swap (countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD t)] + simpa only [integral_const,probReal_univ,one_smul] using + integral_mono (countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD t).integral_prod_left + (integrable_const (Real.exp (|t| * A+t^2*D/2))) + (fun x => countableGaussianHamiltonian_exp_integral_bound hA hD x t) + +include hW hv hL in +lemma gaussianHamiltonianPartition_measurable : + Measurable (fun g => tiltPartition μ (countableGaussianHamiltonian W v L g) 1) := by + simpa only [tiltPartition,one_mul,Function.uncurry_apply_pair] using + (countableGaussianHamiltonian_measurable hW hv hL).exp.stronglyMeasurable.integral_prod_right'.measurable + +include hW hv hL hA hD in +lemma gaussianHamiltonianPartition_pos_ae : + ∀ᵐ g ∂countableGaussianLaw, 0 < tiltPartition μ (countableGaussianHamiltonian W v L g) 1 := by + filter_upwards [(countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).prod_left_ae] with g hg + exact tilt_partition_pos_of_integrable μ hg + +include hW hv hL hA hD in +lemma gaussianHamiltonianPartition_inverse_power_integrable (k : ℕ) : + Integrable (fun g => (tiltPartition μ (countableGaussianHamiltonian W v L g) 1)⁻¹^k) + countableGaussianLaw := by + have hh := countableGaussianHamiltonian_joint_integrable μ hW hv hL hA hD + have h1 := countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1 + have hk := countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD (-(k:ℝ)) + refine hk.integral_prod_right.mono' + ((gaussianHamiltonianPartition_measurable μ hW hv hL).inv.pow_const k).aestronglyMeasurable ?_ + filter_upwards [hh.prod_left_ae,h1.prod_left_ae,hk.prod_left_ae, + gaussianHamiltonianPartition_pos_ae μ hW hv hL hA hD] with g hgi hg1 hgk hgp + rw [Real.norm_eq_abs,abs_of_nonneg (pow_nonneg (inv_nonneg.mpr hgp.le) k)] + exact inverse_partition_power_le μ hgi (by simpa only [one_mul] using hg1) k hgk + +include hW hv hL hA hD in +lemma gaussianHamiltonianPartition_inverse_power_bound (k : ℕ) : + (∫ g, (tiltPartition μ (countableGaussianHamiltonian W v L g) 1)⁻¹^k ∂countableGaussianLaw) ≤ + Real.exp ((k:ℝ)*A+(k:ℝ)^2*D/2) := by + have hh := countableGaussianHamiltonian_joint_integrable μ hW hv hL hA hD + have h1 := countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1 + have hk := countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD (-(k:ℝ)) + calc + _ ≤ ∫ g, ∫ x, Real.exp (-(k:ℝ)*countableGaussianHamiltonian W v L g x) ∂μ ∂countableGaussianLaw := by + apply integral_mono_ae (gaussianHamiltonianPartition_inverse_power_integrable μ hW hv hL hA hD k) + hk.integral_prod_right + filter_upwards [hh.prod_left_ae,h1.prod_left_ae,hk.prod_left_ae] with g hgi hg1 hgk + exact inverse_partition_power_le μ hgi (by simpa only [one_mul] using hg1) k hgk + _ ≤ _ := by + simpa only [abs_neg,abs_of_nonneg (Nat.cast_nonneg k : (0:ℝ) ≤ k),neg_sq] using + countableGaussianHamiltonian_exp_double_integral_bound μ hW hv hL hA hD (-(k:ℝ)) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianComparison.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..959cbde7cf55c32253d83bc9ff0ac73c2a340022 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianComparison.lean @@ -0,0 +1,145 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.GaussianPressureDerivative + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma countableGaussianCovariance_cs {S : Type*} [MeasurableSpace S] + (v w : ℕ → S → ℝ) (L : S → ℕ) {D E : ℝ} (hD0 : 0≤D) (hE0 : 0≤E) + (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2)≤D) + (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2)≤E) (x y : S) : + |countableGaussianCovariance v w L x y|≤Real.sqrt D*Real.sqrt E := by + have hs := Finset.sum_mul_sq_le_sq_mul_sq (s := (Finset.univ : Finset (Fin (L x)))) + (fun i => maskedGaussianCoefficient w L i.val x) (fun i => maskedGaussianCoefficient v L i.val y) + have hm : countableGaussianCovariance v w L x y^2≤E*D := hs.trans + (mul_le_mul (maskedGaussianCoefficient_sq_bound w L hE (L x) x) + (maskedGaussianCoefficient_sq_bound v L hD (L x) y) (by positivity) hE0) + calc + _ = Real.sqrt (countableGaussianCovariance v w L x y^2) := (Real.sqrt_sq_eq_abs _).symm + _ ≤ Real.sqrt (E*D) := Real.sqrt_le_sqrt hm + _ = _ := by rw [mul_comm E D, Real.sqrt_mul hD0] + +lemma countableGaussian_log_comparison {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {W : S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} + (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) + (hL : Measurable L) {A D E : ℝ} (hD0 : 0≤D) (hE0 : 0≤E) + (hA : ∀ x, |W x|≤A) (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2)≤D) + (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2)≤E) : + |(∫ g, Real.log (tiltPartition μ (fun x => countableGaussianHamiltonian W v L g x+ + countableGaussianField w L g x) 1) ∂countableGaussianLaw)- + ∫ g, Real.log (tiltPartition μ (countableGaussianHamiltonian W v L g) 1) ∂countableGaussianLaw|≤ + 2*(Real.sqrt (2*D+2*E)*Real.sqrt E) := by + apply gaussianCouplingMean_difference_bound μ hW hv hw hL hA hD hE (by positivity) + intro a ha x y + apply countableGaussianCovariance_cs _ _ _ (by positivity) hE0 _ hE + intro z + have hb : (∑ i : Fin (L z), (v i.val z+a*w i.val z)^2)≤2*D+2*a^2*E := by + simpa only [gaussianTailCoefficient,zero_le,ite_true,one_mul,mul_one,one_pow] using + gaussianCombinedCoefficient_sq_bound v w L hD hE 1 a 0 z + have ha2 : a^2≤1 := by nlinarith [ha.1,ha.2] + exact hb.trans (by nlinarith [mul_le_mul_of_nonneg_right ha2 hE0]) + +variable {I : Type} [Fintype I] {S : Type} [MeasurableSpace S] (n : ℕ) + +def indexedCoefficientSquare (B : Fin (n+1)→I→ℝ) : ℝ := ∑ i, ∑ l, B l i^2 + +lemma indexedCoefficientSquare_nonneg (B : Fin (n+1)→I→ℝ) : 0 ≤ indexedCoefficientSquare n B := by + unfold indexedCoefficientSquare + positivity + +lemma indexedCoefficientSquare_continuous : Continuous (indexedCoefficientSquare (I := I) n) := by + unfold indexedCoefficientSquare + fun_prop + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_sub (B C : Fin (n+1)→I→ℝ) (V : S→EuclideanSpace ℝ I) (j : ℕ) (x : S×IndexedLeaf n) : + indexedGaussianRow n (fun l i => B l i-C l i) V j x = + indexedGaussianRow n B V j x-indexedGaussianRow n C V j x := by + unfold indexedGaussianRow finiteGaussianRow + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro p hp + split_ifs <;> ring + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_square_total (B : Fin (n+1)→I→ℝ) (V : S→EuclideanSpace ℝ I) + {D : ℝ} (hD : ∀ x, (∑ i, V x i^2)≤D) (x : S×IndexedLeaf n) : + (∑ j : Fin (indexedGaussianRowLength (I := I) n x), indexedGaussianRow n B V j.val x^2)≤ + indexedCoefficientSquare n B*D := by + apply indexedGaussianRow_norm_le _ _ _ _ (indexedCoefficientSquare_nonneg n B) hD + intro i + unfold indexedCoefficientSquare + exact Finset.single_le_sum (f := fun i => ∑ l, B l i^2) (fun j _ => by positivity) (Finset.mem_univ i) + +def indexedGaussianMean (μ : Measure (S×IndexedLeaf n)) (W : S×IndexedLeaf n→ℝ) + (V : S→EuclideanSpace ℝ I) (B : Fin (n+1)→I→ℝ) : ℝ := + ∫ g, Real.log (tiltPartition μ (countableGaussianHamiltonian W (indexedGaussianRow n B V) + (indexedGaussianRowLength (I := I) n) g) 1) ∂countableGaussianLaw + +lemma indexedGaussianMean_comparison (μ : Measure (S×IndexedLeaf n)) [IsProbabilityMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) {A D : ℝ} (hD0 : 0≤D) + (hA : ∀ x, |W x|≤A) (hD : ∀ x, (∑ i, V x i^2)≤D) (B C : Fin (n+1)→I→ℝ) : + |indexedGaussianMean n μ W V B-indexedGaussianMean n μ W V C|≤ + 2*(Real.sqrt (2*(indexedCoefficientSquare n C*D)+ + 2*(indexedCoefficientSquare n (fun l i => B l i-C l i)*D))* + Real.sqrt (indexedCoefficientSquare n (fun l i => B l i-C l i)*D)) := by + have hb := countableGaussian_log_comparison μ hW (indexedGaussianRow_measurable n C hV) + (indexedGaussianRow_measurable n (fun l i => B l i-C l i) hV) + (indexedGaussianRowLength_measurable n) + (mul_nonneg (indexedCoefficientSquare_nonneg n C) hD0) + (mul_nonneg (indexedCoefficientSquare_nonneg n _) hD0) + hA (indexedGaussianRow_square_total n C V hD) (indexedGaussianRow_square_total n _ V hD) + convert hb using 1 + unfold indexedGaussianMean + congr 3 + funext g + congr 2 + funext x + simp only [countableGaussianHamiltonian,countableGaussianField,countableGaussianField, + gaussianPrefixField,indexedGaussianRow_sub] + rw [add_assoc, ← Finset.sum_add_distrib] + congr 1 + apply Finset.sum_congr rfl + intro i hi + ring + +lemma indexedGaussianMean_add_const (μ : Measure (S×IndexedLeaf n)) [IsProbabilityMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) {A D : ℝ} + (hA : ∀ x, |W x|≤A) (hD : ∀ x, (∑ i, V x i^2)≤D) + (B : Fin (n+1)→I→ℝ) (c : ℝ) : + indexedGaussianMean n μ (fun x => W x+c) V B = indexedGaussianMean n μ W V B+c := by + have hrow := indexedGaussianRow_measurable n B hV + have hlen := indexedGaussianRowLength_measurable (S := S) (I := I) n + have hb := indexedGaussianRow_square_total n B V hD + have hi := gaussianLogPartition_integrable μ hW hrow hlen hA hb + have he : ∀ᵐ g ∂countableGaussianLaw, + Real.log (tiltPartition μ (countableGaussianHamiltonian (fun x => W x+c) (indexedGaussianRow n B V) + (indexedGaussianRowLength (I := I) n) g) 1) = + Real.log (tiltPartition μ (countableGaussianHamiltonian W (indexedGaussianRow n B V) + (indexedGaussianRowLength (I := I) n) g) 1)+c := by + filter_upwards [gaussianHamiltonianPartition_pos_ae μ hW hrow hlen hA hb] with g hg + have hf : tiltPartition μ (countableGaussianHamiltonian (fun x => W x+c) (indexedGaussianRow n B V) + (indexedGaussianRowLength (I := I) n) g) 1 = + tiltPartition μ (countableGaussianHamiltonian W (indexedGaussianRow n B V) + (indexedGaussianRowLength (I := I) n) g) 1*Real.exp c := by + unfold tiltPartition countableGaussianHamiltonian + simp only [one_mul] + simp_rw [show ∀ x, W x+c+countableGaussianField (indexedGaussianRow n B V) + (indexedGaussianRowLength (I := I) n) g x = + (W x+countableGaussianField (indexedGaussianRow n B V) + (indexedGaussianRowLength (I := I) n) g x)+c by intro x; ring,Real.exp_add] + exact integral_mul_const _ _ + rw [hf,Real.log_mul hg.ne' (Real.exp_ne_zero c),Real.log_exp] + unfold indexedGaussianMean + rw [integral_congr_ae he,integral_add hi (integrable_const c),integral_const,probReal_univ,one_smul] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianCoupling.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianCoupling.lean new file mode 100644 index 0000000000000000000000000000000000000000..ec5cabafb2458748bb80bba1007c7bbfdb224ee9 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianCoupling.lean @@ -0,0 +1,189 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.EnrichedUniformBounds +import OAI.Probability.Perceptron.Pressure.IndexedGibbsPartition +import OAI.Probability.Perceptron.Variational.GaussianBoltzmann +import OAI.Probability.Perceptron.Brownian.GaussianFieldAlgebra + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +section +variable {S : Type*} [MeasurableSpace S] +variable (μ : Measure S) [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +lemma coupling_integrable_of_integer_endpoints {H Y : S → ℝ} + (hH : Measurable H) (hY : Measurable Y) + (he : ∀ k : ℕ, Integrable (fun x => Real.exp (H x+(k:ℝ)*Y x)) μ ∧ + Integrable (fun x => Real.exp (H x-(k:ℝ)*Y x)) μ) (a : ℝ) : + Integrable (fun x => Real.exp (H x+a*Y x)) μ := by + obtain ⟨k,hk⟩ := exists_nat_gt |a| + refine ((he k).1.add (he k).2).mono' ((hH.add (hY.const_mul a)).exp.aestronglyMeasurable) ?_ + filter_upwards [] with x + rw [Real.norm_of_nonneg (Real.exp_pos _).le] + by_cases hy : 0 ≤ Y x + · have ha : a ≤ (k:ℝ) := (le_abs_self a).trans hk.le + exact (Real.exp_le_exp.mpr (add_le_add_right (mul_le_mul_of_nonneg_right ha hy) _)).trans + (le_add_of_nonneg_right (Real.exp_pos _).le) + · have ha : -(k:ℝ) ≤ a := by linarith [neg_abs_le a] + have hh : H x+a*Y x ≤ H x-(k:ℝ)*Y x := by + have h := mul_le_mul_of_nonpos_right ha (le_of_not_ge hy) + nlinarith + exact (Real.exp_le_exp.mpr hh).trans (le_add_of_nonneg_left (Real.exp_pos _).le) + +variable {W : S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} +variable (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) +variable (hL : Measurable L) {A D E : ℝ} (hA : ∀ x, |W x| ≤ A) +variable (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) +variable (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) +include hW hv hw hL hA hD hE + +lemma countableGaussian_coupling_exp_ae (a : ℝ) : + ∀ᵐ g ∂countableGaussianLaw, Integrable (fun x => Real.exp + (countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x)) μ := by + have hm (i : ℕ) : Measurable (fun x => v i x+a*w i x) := (hv i).add ((hw i).const_mul a) + have hb (x : S) : (∑ i : Fin (L x), (v i.val x+a*w i.val x)^2) ≤ 2*D+2*a^2*E := by + simpa only [gaussianTailCoefficient,zero_le,ite_true,one_mul,mul_one,one_pow] using + gaussianCombinedCoefficient_sq_bound v w L hD hE 1 a 0 x + have he := (countableGaussianHamiltonian_exp_joint_integrable μ hW hm hL hA hb 1).prod_left_ae + filter_upwards [he] with g hg + convert hg using 1 + ext x + simp only [one_mul,countableGaussianHamiltonian,countableGaussianField_add, + countableGaussianField_smul] + congr 1 + ring + +lemma countableGaussian_all_coupling_exp_ae : + ∀ᵐ g ∂countableGaussianLaw, ∀ a : ℝ, Integrable (fun x => Real.exp + (countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x)) μ := by + have hp : ∀ᵐ g ∂countableGaussianLaw, ∀ k : ℕ, Integrable (fun x => Real.exp + (countableGaussianHamiltonian W v L g x+(k:ℝ)*countableGaussianField w L g x)) μ := + ae_all_iff.mpr fun k => countableGaussian_coupling_exp_ae μ hW hv hw hL hA hD hE k + have hn : ∀ᵐ g ∂countableGaussianLaw, ∀ k : ℕ, Integrable (fun x => Real.exp + (countableGaussianHamiltonian W v L g x-(k:ℝ)*countableGaussianField w L g x)) μ := by + apply ae_all_iff.mpr + intro k + simpa only [neg_mul,sub_eq_add_neg] using + countableGaussian_coupling_exp_ae μ hW hv hw hL hA hD hE (-(k:ℝ)) + filter_upwards [hp,hn] with g hgp hgn a + exact coupling_integrable_of_integer_endpoints μ + ((countableGaussianHamiltonian_measurable hW hv hL).comp (measurable_const.prodMk measurable_id)) + ((countableGaussianField_measurable hw hL).comp (measurable_const.prodMk measurable_id)) + (fun k => ⟨hgp k,hgn k⟩) a + +lemma countableGaussian_coupling_derivatives_ae : + ∀ᵐ g ∂countableGaussianLaw, ∀ a : ℝ, + HasDerivAt (fun b => Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+b*countableGaussianField w L g x) 1)) + (tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (countableGaussianField w L g) 1) a ∧ + iteratedDeriv 2 (fun b => Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+b*countableGaussianField w L g x) 1)) a = + tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (fun x => (countableGaussianField w L g x- + tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (countableGaussianField w L g) 1)^2) 1 := by + filter_upwards [countableGaussian_all_coupling_exp_ae μ hW hv hw hL hA hD hE] with g hg a + have hH : Measurable (countableGaussianHamiltonian W v L g) := (countableGaussianHamiltonian_measurable hW hv hL).comp (measurable_const.prodMk measurable_id) + have hY : Measurable (countableGaussianField w L g) := (countableGaussianField_measurable hw hL).comp (measurable_const.prodMk measurable_id) + exact ⟨coupling_log_hasDerivAt μ hH hY hg a,coupling_log_second_derivative μ hH hY hg a⟩ +end + +def enrichedIndexedBaseMeasure (n k : ℕ) (b : IndexedCascadeBase k) : + Measure (NormalizedSpin (n+1) × IndexedLeaf k) := + (unitSphereLaw (n+1)).prod (indexedLeafProbability k b) + +instance enrichedIndexedBaseMeasure_probability (n k : ℕ) (b : IndexedCascadeBase k) : + IsProbabilityMeasure (enrichedIndexedBaseMeasure n k b) := by + unfold enrichedIndexedBaseMeasure + infer_instance + +def enrichedIndexedBoundedEnergy (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) + (x : NormalizedSpin (n+1) × IndexedLeaf k) : ℝ := + normalizedPatternEnergy (n+1) M f a x.1-(n+1:ℕ)*h (Fin.last k) + +lemma enrichedIndexedBoundedEnergy_measurable (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) : + Measurable (enrichedIndexedBoundedEnergy n M k f a h) := + ((normalizedPatternEnergy_continuous (n+1) M f).measurable.comp + (measurable_const.prodMk measurable_fst)).sub measurable_const + +lemma enrichedIndexedBoundedEnergy_bound (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (h : Fin (k+1) → ℝ) + (x : NormalizedSpin (n+1) × IndexedLeaf k) : + |enrichedIndexedBoundedEnergy n M k f a h x| ≤ (M:ℝ)*‖f‖+|(n+1:ℕ)*h (Fin.last k)| := + (abs_sub _ _).trans (add_le_add (normalizedPatternEnergy_bound (n+1) M f a x.1) le_rfl) + +def enrichedIndexedHamiltonian (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (g : ℕ → ℝ) : + NormalizedSpin (n+1) × IndexedLeaf k → ℝ := + countableGaussianHamiltonian (enrichedIndexedBoundedEnergy n M k f a h) + (sourceGaussianRow p d h u) (indexedGaussianRowLength (I := EnrichedIndex (n+1) (n+1) p) k) g + +lemma sourceEnrichedFeature_measurable (N : ℕ) (p : Fin N → ℕ) (u : Fin N → ℝ) : + Measurable (sourceEnrichedFeature N p u) := + (enrichedFeature_continuous N N p (Real.sqrt N) (perturbationAmplitude N u)).measurable + +lemma enrichedIndexedHamiltonian_spin_partition (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (g : ℕ → ℝ) + (b : IndexedCascadeBase k) : + tiltPartition (enrichedIndexedBaseMeasure n k b) + (enrichedIndexedHamiltonian n M k f a p d h u g) 1 = + ∫ l, Real.exp (enrichedTerminal n M f a p u (h (Fin.last k)) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).1), + (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).2) l 0)) + ∂indexedLeafProbability k b := by + let root := profileGaussianRoot (enrichedCoordinateLevel p d h) + let step := profileGaussianStep (enrichedCoordinateLevel p d h) + have hWc : Continuous (normalizedPatternEnergy (n+1) M f a) := + (normalizedPatternEnergy_continuous (n+1) M f).comp (continuous_const.prodMk continuous_id) + have hWm := hWc.measurable + have hp := indexedGaussian_spin_partition (unitSphereLaw (n+1)) hWm + (sourceEnrichedFeature_measurable (n+1) p u) + (normalizedPatternEnergy_bound (n+1) M f a) + (fun x => (sourceEnrichedFeature_norm (n+1) p u x).le) k root step b ((n+1:ℕ)*h (Fin.last k)) g + have hA : enrichedIncrementMap p d h = fun j => diagonalMark (step j) := + funext (enrichedIncrementMap_profile p d h) + have hR : enrichedRootMap p d h = diagonalMark root := rfl + rw [hA,hR] + unfold enrichedIndexedBaseMeasure + convert hp using 2 + · funext x + unfold enrichedIndexedHamiltonian countableGaussianHamiltonian enrichedIndexedBoundedEnergy sourceGaussianRow + dsimp only [root,step] + ring + · rfl + +lemma enrichedIndexedHamiltonian_partition (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (g : ℕ → ℝ) + (b : IndexedCascadeBase k) (hb : IndexedCascadeGood k b) + (hb' : 0 < ((indexedLeafMeasure k b) univ).toReal) : + Real.log (tiltPartition (enrichedIndexedBaseMeasure n k b) + (enrichedIndexedHamiltonian n M k f a p d h u g) 1) = + enrichedCascadeLog n M k f a p d u h + ((indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).1, + indexedCascadeRealize k (b,(indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).2)) := by + rw [enrichedIndexedHamiltonian_spin_partition] + have hH : Measurable (fun x : ℕ → EnrichedMark (n+1) (n+1) p => + enrichedTerminal n M f a p u (h (Fin.last k)) (x 0)) := + (enrichedTerminal_lipschitz n M f a p u _).continuous.measurable.comp (measurable_pi_apply 0) + rw [indexedLeafProbability_terminal_integral + (gaussianMarkLaw : ProbabilityMeasure (EnrichedMark (n+1) (n+1) p)) + (gaussianLinearMarkStep_measurable (enrichedIncrementMap p d h)) hH k b hb hb'] + rfl + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianCovarianceDerivative.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianCovarianceDerivative.lean new file mode 100644 index 0000000000000000000000000000000000000000..1d7093a2c789a9a77fb6583cf0e6e98764ba4a95 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianCovarianceDerivative.lean @@ -0,0 +1,225 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedGaussianCovarianceLaw +import OAI.Probability.Perceptron.Variational.GaussianGibbsContinuity + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +section + +lemma countableGaussianCovariance_add_smul {S : Type*} + (v w z : ℕ → S → ℝ) (L : S → ℕ) (a : ℝ) (x y : S) : + countableGaussianCovariance (fun i q => v i q+a*w i q) z L x y = + countableGaussianCovariance v z L x y+a*countableGaussianCovariance w z L x y := by + have hm (i : ℕ) (q : S) : maskedGaussianCoefficient (fun i q => v i q+a*w i q) L i q = + maskedGaussianCoefficient v L i q+a*maskedGaussianCoefficient w L i q := by + unfold maskedGaussianCoefficient + split_ifs <;> ring + unfold countableGaussianCovariance gaussianPrefixCovariance + simp_rw [hm] + rw [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i hi + ring + +lemma tiltMean_const_mul_general {S : Type*} [MeasurableSpace S] (μ : Measure S) + (H G : S → ℝ) (a t : ℝ) : + tiltMean μ H (fun x => a*G x) t = a*tiltMean μ H G t := by + unfold tiltMean tiltIntegral + simp_rw [← mul_assoc, mul_comm (Real.exp _) a,mul_assoc,integral_const_mul] + ring + +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] +variable {W : S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} +variable (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) +variable (hL : Measurable L) {A D E : ℝ} (hA : ∀ x, |W x|≤A) +variable (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2)≤D) +variable (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2)≤E) +variable {B : ℝ} (hB : 0 ≤ B) (hCB : ∀ x y, |countableGaussianCovariance w w L x y| ≤ B) +include hW hv hw hL hA hD hE hB hCB + +lemma gaussianCoupling_covariance_continuous : + Continuous (fun a => ∫ g, + tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (fun x => countableGaussianCovariance w w L x x) 1 - + gibbsReplicaMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) 2 + (fun x => countableGaussianCovariance w w L (x 1) (x 0)) ∂countableGaussianLaw) := by + let H := countableGaussianHamiltonian W v L + let Y := countableGaussianField w L + have hH := countableGaussianHamiltonian_measurable hW hv hL + have hY := countableGaussianField_measurable hw hL + have he := countableGaussian_all_coupling_exp_ae μ hW hv hw hL hA hD hE + have hm := countableGaussianCovariance_measurable hw hw hL + have hdiag : Measurable (fun x => countableGaussianCovariance w w L x x) := + hm.comp (measurable_id.prodMk measurable_id) + have hpair : Measurable (fun x : Fin 2 → S => countableGaussianCovariance w w L (x 1) (x 0)) := + hm.comp (show Measurable (fun x : Fin 2 → S => (x 1,x 0)) from by fun_prop) + have hi (a : ℝ) : Integrable (fun g => tiltMean μ (fun x => H g x+a*Y g x) + (fun x => countableGaussianCovariance w w L x x) 1) countableGaussianLaw := by + apply Integrable.of_bound (kernel_tiltMean_measurable (Kernel.const _ μ) + (H := fun g x => H g x+a*Y g x) (Y := fun _ x => countableGaussianCovariance w w L x x) + (hH.add (hY.const_mul a)) (hdiag.comp measurable_snd)).aestronglyMeasurable B + exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs,Kernel.const_apply] using tiltMean_bound_general μ + (H := fun x => H g x+a*Y g x) (hH.of_uncurry_left.add (hY.of_uncurry_left.const_mul a)) hdiag hB (fun x => hCB x x) + have hj (a : ℝ) : Integrable (fun g => gibbsReplicaMean μ (fun x => H g x+a*Y g x) 2 + (fun x => countableGaussianCovariance w w L (x 1) (x 0))) countableGaussianLaw := + kernel_replicaMean_bounded_integrable (Kernel.const _ μ) countableGaussianLaw + (H := fun g x => H g x+a*Y g x) (G := fun _ x => countableGaussianCovariance w w L (x 1) (x 0)) + (hH.add (hY.const_mul a)) (hpair.comp measurable_snd) hB (fun _ x => hCB _ _) + change Continuous (fun a => ∫ g, tiltMean μ (fun x => H g x+a*Y g x) _ 1- + gibbsReplicaMean μ (fun x => H g x+a*Y g x) 2 _ ∂countableGaussianLaw) + simp_rw [integral_sub (hi _) (hj _)] + exact (annealedCoupling_tiltMean_continuous countableGaussianLaw μ hH hY hdiag he hB (fun x => hCB x x)).sub + (annealedCoupling_replicaMean_continuous countableGaussianLaw μ hH hY hpair he hB (fun x => hCB _ _)) + +theorem gaussianCovariance_right_derivative + (horth : ∀ x y, countableGaussianCovariance v w L x y=0) : + HasDerivWithinAt (fun t => ∫ g, Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+Real.sqrt t*countableGaussianField w L g x) 1) ∂countableGaussianLaw) + ((∫ g, tiltMean μ (countableGaussianHamiltonian W v L g) + (fun x => countableGaussianCovariance w w L x x) 1 - + gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) 2 + (fun x => countableGaussianCovariance w w L (x 1) (x 0)) ∂countableGaussianLaw)/2) (Ici 0) 0 := by + let M := fun a => ∫ g, Real.log (tiltPartition μ (fun x => + countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) 1) ∂countableGaussianLaw + let C := fun a => ∫ g, + tiltMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) + (fun x => countableGaussianCovariance w w L x x) 1 - + gibbsReplicaMean μ (fun x => countableGaussianHamiltonian W v L g x+a*countableGaussianField w L g x) 2 + (fun x => countableGaussianCovariance w w L (x 1) (x 0)) ∂countableGaussianLaw + have hd (a : ℝ) : HasDerivAt M (a*C a) a := by + have hh := gaussianCouplingMean_derivative_covariance μ hW hv hw hL hA hD hE a + simp_rw [countableGaussianCovariance_add_smul,horth,zero_add, + tiltMean_const_mul_general,gibbsReplicaMean,tiltMean_const_mul_general,← mul_sub,integral_const_mul] at hh + exact hh + have hc : Continuous C := gaussianCoupling_covariance_continuous μ hW hv hw hL hA hD hE hB hCB + simpa only [M,C,zero_mul,add_zero] using sqrt_coupling_right_derivative hd hc + +end +variable {I : Type} [Fintype I] [DecidableEq I] {S : Type} [MeasurableSpace S] +variable (n : ℕ) + +def duplicateFeature (V : S→EuclideanSpace ℝ I) (s : S) : EuclideanSpace ℝ (I ⊕ I) := + WithLp.toLp 2 (Sum.elim (fun i => V s i) (fun i => V s i)) + +def leftCoefficients (B : Fin (n+1)→I→ℝ) (l : Fin (n+1)) : I ⊕ I→ℝ := + Sum.elim (B l) (fun _ => 0) + +def rightCoefficients (C : Fin (n+1)→I→ℝ) (l : Fin (n+1)) : I ⊕ I→ℝ := + Sum.elim (fun _ => 0) (C l) + +omit [DecidableEq I] in +lemma duplicateFeature_measurable {V : S→EuclideanSpace ℝ I} (hV : Measurable V) : + Measurable (duplicateFeature V) := by + apply (PiLp.continuous_toLp 2 _).measurable.comp + apply Measurable.of_eval + intro i + cases i with + | inl i => exact (EuclideanSpace.proj i).measurable.comp hV + | inr i => exact (EuclideanSpace.proj i).measurable.comp hV + +omit [DecidableEq I] [MeasurableSpace S] in +lemma duplicateFeature_square (V : S→EuclideanSpace ℝ I) (s : S) : + (∑ i, duplicateFeature V s i^2) = 2*∑ i, V s i^2 := by + rw [Fintype.sum_sum_type] + simp only [duplicateFeature,Sum.elim_inl,Sum.elim_inr] + ring + +omit [DecidableEq I] [MeasurableSpace S] in +lemma indexedGaussianRow_orthogonal (B C : Fin (n+1)→I→ℝ) (V : S→EuclideanSpace ℝ I) + (x y : S×IndexedLeaf n) : + countableGaussianCovariance (indexedGaussianRow n (leftCoefficients n B) (duplicateFeature V)) + (indexedGaussianRow n (rightCoefficients n C) (duplicateFeature V)) + (indexedGaussianRowLength (I := I ⊕ I) n) x y=0 := by + rw [indexedGaussianRow_covariance,Fintype.sum_sum_type] + simp [leftCoefficients,rightCoefficients] + +omit [DecidableEq I] [MeasurableSpace S] in +lemma indexedGaussianRow_add_smul (B C : Fin (n+1)→I→ℝ) (V : S→EuclideanSpace ℝ I) + (a : ℝ) (j : ℕ) (x : S×IndexedLeaf n) : + indexedGaussianRow n (fun l i => B l i+a*C l i) V j x = + indexedGaussianRow n B V j x+a*indexedGaussianRow n C V j x := by + unfold indexedGaussianRow finiteGaussianRow + rw [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro p hp + split_ifs <;> ring + +omit [DecidableEq I] [MeasurableSpace S] in +lemma indexedHamiltonian_independent_addition (W : S×IndexedLeaf n→ℝ) (V : S→EuclideanSpace ℝ I) + (B C : Fin (n+1)→I→ℝ) (a : ℝ) (g : ℕ→ℝ) (x : S×IndexedLeaf n) : + countableGaussianHamiltonian W + (indexedGaussianRow n (fun l => Sum.elim (B l) (fun i => a*C l i)) (duplicateFeature V)) + (indexedGaussianRowLength (I := I ⊕ I) n) g x = + countableGaussianHamiltonian W + (indexedGaussianRow n (leftCoefficients n B) (duplicateFeature V)) + (indexedGaussianRowLength (I := I ⊕ I) n) g x + + a*countableGaussianField (indexedGaussianRow n (rightCoefficients n C) (duplicateFeature V)) + (indexedGaussianRowLength (I := I ⊕ I) n) g x := by + have he : (fun l => Sum.elim (B l) (fun i => a*C l i)) = + fun l i => leftCoefficients n B l i+a*rightCoefficients n C l i := by + funext l i + cases i <;> simp [leftCoefficients,rightCoefficients] + rw [he] + unfold countableGaussianHamiltonian + have hr : indexedGaussianRow n (fun l i => leftCoefficients n B l i+a*rightCoefficients n C l i) (duplicateFeature V) = + fun j x => indexedGaussianRow n (leftCoefficients n B) (duplicateFeature V) j x+ + a*indexedGaussianRow n (rightCoefficients n C) (duplicateFeature V) j x := by + funext j x + exact indexedGaussianRow_add_smul n _ _ _ _ _ _ + rw [hr,countableGaussianField_add,countableGaussianField_smul] + ring + +theorem indexedGaussianMean_right_derivative (μ : Measure (S×IndexedLeaf n)) [IsProbabilityMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) {A D : ℝ} (hD0 : 0 ≤ D) + (hA : ∀ x, |W x| ≤ A) (hD : ∀ x, (∑ i, V x i^2) ≤ D) + (B C : Fin (n+1)→I→ℝ) (Q : ℝ→Fin (n+1)→I→ℝ) + (hQ : ∀ t, 0 ≤ t → ∀ l i, Q t l i^2=B l i^2+t*C l i^2) : + let v := indexedGaussianRow n (leftCoefficients n B) (duplicateFeature V) + let w := indexedGaussianRow n (rightCoefficients n C) (duplicateFeature V) + let L := indexedGaussianRowLength (I := I ⊕ I) (S := S) n + HasDerivWithinAt (fun t => indexedGaussianMean n μ W V (Q t)) + ((∫ g, tiltMean μ (countableGaussianHamiltonian W v L g) + (fun x => countableGaussianCovariance w w L x x) 1 - + gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) 2 + (fun x => countableGaussianCovariance w w L (x 1) (x 0)) ∂countableGaussianLaw)/2) (Ici 0) 0 := by + let v := indexedGaussianRow n (leftCoefficients n B) (duplicateFeature V) + let w := indexedGaussianRow n (rightCoefficients n C) (duplicateFeature V) + let L := indexedGaussianRowLength (I := I ⊕ I) (S := S) n + let E := indexedCoefficientSquare n (rightCoefficients n C)*(2*D) + have hE0 : 0 ≤ E := mul_nonneg (indexedCoefficientSquare_nonneg n _) (by positivity) + have hDV (x : S) : (∑ i, duplicateFeature V x i^2) ≤ 2*D := by + rw [duplicateFeature_square] + exact mul_le_mul_of_nonneg_left (hD x) (by norm_num) + have hv := indexedGaussianRow_measurable n (leftCoefficients n B) (duplicateFeature_measurable hV) + have hw := indexedGaussianRow_measurable n (rightCoefficients n C) (duplicateFeature_measurable hV) + have hEE : ∀ x, (∑ j : Fin (L x), w j.val x^2) ≤ E := indexedGaussianRow_square_total n _ _ hDV + have hCB (x y) : |countableGaussianCovariance w w L x y| ≤ E := by + have hh := gaussianPrefixCovariance_bound w w L hEE hEE (L x) x y + simpa only [countableGaussianCovariance,add_self_div_two] using hh + have hd := gaussianCovariance_right_derivative μ hW hv hw + (indexedGaussianRowLength_measurable n) hA + (indexedGaussianRow_square_total n (leftCoefficients n B) _ hDV) + hEE hE0 hCB (indexedGaussianRow_orthogonal n B C V) + apply hd.congr_of_mem _ (by simp) + intro t ht + have he := indexedGaussianMean_covariance_addition n μ hW hV B + (fun l i => Real.sqrt t*C l i) (Q t) (fun l i => by rw [mul_pow,Real.sq_sqrt ht]; exact hQ t ht l i) + rw [he] + unfold indexedGaussianMean + apply integral_congr_ae + filter_upwards [] with g + congr 2 + funext x + exact indexedHamiltonian_independent_addition n W V B C (Real.sqrt t) g x + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianEnergyMoments.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianEnergyMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..56f2ac8270395a0d461fcbd0dc5f2134a0480090 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianEnergyMoments.lean @@ -0,0 +1,225 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianBoltzmann +import OAI.Probability.Perceptron.Brownian.GaussianFieldAlgebra + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +section +variable {S : Type*} [MeasurableSpace S] +variable {W : S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} +variable (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) +variable (hL : Measurable L) {A D E : ℝ} (hA : ∀ x, |W x| ≤ A) +variable (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) +variable (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) + +omit [MeasurableSpace S] in +lemma gaussianHamiltonian_energy_combine (t b : ℝ) (n : ℕ) (g : ℕ → ℝ) (x : S) : + t*countableGaussianHamiltonian W v L g x+ + b*countableGaussianField (gaussianTailCoefficient w n) L g x = + countableGaussianHamiltonian (fun x => t*W x) + (fun i x => t*v i x+b*gaussianTailCoefficient w n i x) L g x := by + rw [countableGaussianHamiltonian,countableGaussianHamiltonian,countableGaussianField_add, + countableGaussianField_smul,countableGaussianField_smul] + ring + +omit [MeasurableSpace S] in +lemma gaussianHamiltonian_energy_exp_integrable (t b : ℝ) (n : ℕ) (x : S) : + Integrable (fun g => Real.exp (t*countableGaussianHamiltonian W v L g x+ + b*countableGaussianField (gaussianTailCoefficient w n) L g x)) countableGaussianLaw := by + simp_rw [gaussianHamiltonian_energy_combine] + simpa only [one_mul] using countableGaussianHamiltonian_exp_integrable + (W := fun x => t*W x) (v := fun i x => t*v i x+b*gaussianTailCoefficient w n i x) (L := L) x 1 + +include hA hD hE in +omit [MeasurableSpace S] in +lemma gaussianHamiltonian_energy_exp_bound (t b : ℝ) (n : ℕ) (x : S) : + (∫ g, Real.exp (t*countableGaussianHamiltonian W v L g x+ + b*countableGaussianField (gaussianTailCoefficient w n) L g x) ∂countableGaussianLaw) ≤ + Real.exp (|t| *A+t^2*D+b^2*E) := by + simp_rw [gaussianHamiltonian_energy_combine] + have ha (x : S) : |t*W x| ≤ |t| *A := by + rw [abs_mul] + exact mul_le_mul_of_nonneg_left (hA x) (abs_nonneg t) + have h := countableGaussianHamiltonian_exp_integral_bound + (v := fun i x => t*v i x+b*gaussianTailCoefficient w n i x) (L := L) ha + (gaussianCombinedCoefficient_sq_bound v w L hD hE t b n) x 1 + convert h using 1 <;> simp only [one_mul,abs_one,one_pow] + congr 1 + ring + +include hW hv hw hL + +lemma gaussianEnergy_weighted_moment_integrable (n k : ℕ) (t : ℝ) (x : S) : + Integrable (fun g => |countableGaussianField (gaussianTailCoefficient w n) L g x|^k* + Real.exp (t*countableGaussianHamiltonian W v L g x)) countableGaussianLaw := by + have hp := gaussianHamiltonian_energy_exp_integrable (W := W) (v := v) (w := w) (L := L) t 1 n x + have hn := gaussianHamiltonian_energy_exp_integrable (W := W) (v := v) (w := w) (L := L) t (-1) n x + apply ((hp.add hn).const_mul (k.factorial:ℝ)).mono' + · exact (((countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL).comp + (measurable_id.prodMk measurable_const)).abs.pow_const k |>.mul + (((countableGaussianHamiltonian_measurable hW hv hL).comp + (measurable_id.prodMk measurable_const)).const_mul t).exp).aestronglyMeasurable + · exact ae_of_all _ fun g => by + rw [Real.norm_of_nonneg (by positivity)] + simpa only [one_mul,neg_one_mul,add_neg_cancel,sub_eq_add_neg,Pi.add_apply] using + abs_pow_mul_exp_le (t*countableGaussianHamiltonian W v L g x) + (countableGaussianField (gaussianTailCoefficient w n) L g x) k + +include hA hD hE in +lemma gaussianEnergy_weighted_moment_bound (n k : ℕ) (t : ℝ) (x : S) : + (∫ g, |countableGaussianField (gaussianTailCoefficient w n) L g x|^k* + Real.exp (t*countableGaussianHamiltonian W v L g x) ∂countableGaussianLaw) ≤ + 2*(k.factorial:ℝ)*Real.exp (|t| *A+t^2*D+E) := by + have hp := gaussianHamiltonian_energy_exp_integrable (W := W) (v := v) (w := w) (L := L) t 1 n x + have hn := gaussianHamiltonian_energy_exp_integrable (W := W) (v := v) (w := w) (L := L) t (-1) n x + calc + _ ≤ ∫ g, (k.factorial:ℝ)*(Real.exp (t*countableGaussianHamiltonian W v L g x+ + 1*countableGaussianField (gaussianTailCoefficient w n) L g x)+ + Real.exp (t*countableGaussianHamiltonian W v L g x+ + (-1)*countableGaussianField (gaussianTailCoefficient w n) L g x)) ∂countableGaussianLaw := by + apply integral_mono (gaussianEnergy_weighted_moment_integrable hW hv hw hL n k t x) + ((hp.add hn).const_mul _) + intro g + simpa only [one_mul,neg_one_mul,sub_eq_add_neg,Pi.add_apply] using abs_pow_mul_exp_le + (t*countableGaussianHamiltonian W v L g x) + (countableGaussianField (gaussianTailCoefficient w n) L g x) k + _ ≤ _ := by + rw [integral_const_mul,integral_add hp hn] + have hp' := gaussianHamiltonian_energy_exp_bound hA hD hE t 1 n x + have hn' := gaussianHamiltonian_energy_exp_bound hA hD hE t (-1) n x + norm_num only [one_pow,neg_one_sq,one_mul] at hp' hn' + have hh := mul_le_mul_of_nonneg_left (add_le_add hp' hn') (Nat.cast_nonneg k.factorial : (0:ℝ) ≤ _) + simp only [one_mul] at * + nlinarith + +variable (μ : Measure S) [IsProbabilityMeasure μ] + +include hA hD hE in +lemma gaussianEnergy_weighted_moment_joint_integrable (n k : ℕ) (t : ℝ) : + Integrable (fun p : S×(ℕ → ℝ) => |countableGaussianField (gaussianTailCoefficient w n) L p.2 p.1|^k* + Real.exp (t*countableGaussianHamiltonian W v L p.2 p.1)) (μ.prod countableGaussianLaw) := by + apply integrable_prod_of_nonneg_uniform_integral μ countableGaussianLaw + ((((countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL).comp measurable_swap).abs.pow_const k).mul + (((countableGaussianHamiltonian_measurable hW hv hL).comp measurable_swap).const_mul t).exp) + (fun p => mul_nonneg (pow_nonneg (abs_nonneg _) _) (Real.exp_pos _).le) + (gaussianEnergy_weighted_moment_integrable hW hv hw hL n k t) + exact gaussianEnergy_weighted_moment_bound hW hv hw hL hA hD hE n k t + +include hA hD hE in +lemma gaussianEnergy_tail_weighted_L2 (t : ℝ) : + Tendsto (fun n => ∫ p : S×(ℕ → ℝ), + (countableGaussianField w L p.2 p.1-truncatedCountableGaussianField w L n p.2 p.1)^2* + Real.exp (t*countableGaussianHamiltonian W v L p.2 p.1) ∂(μ.prod countableGaussianLaw)) + atTop (nhds 0) := by + have hm (n : ℕ) := gaussianEnergy_weighted_moment_joint_integrable hW hv hw hL hA hD hE μ n 2 t + have ht := tendsto_integral_of_dominated_convergence (f := fun _ : S => (0:ℝ)) + (fun _ : S => 2*((2:ℕ).factorial:ℝ)*Real.exp (|t| *A+t^2*D+E)) + (fun n => (hm n).integral_prod_left.aestronglyMeasurable) (integrable_const _) + (fun n => ae_of_all μ fun x => by + rw [Real.norm_eq_abs,abs_of_nonneg (integral_nonneg (fun _ => by positivity))] + exact gaussianEnergy_weighted_moment_bound hW hv hw hL hA hD hE n 2 t x) + (ae_of_all μ fun x => by + apply tendsto_const_nhds.congr' + filter_upwards [truncatedCountableGaussianField_eventually_eq w L x] with n hn + simp only [countableGaussianField_tail,hn,sub_self,abs_zero,zero_pow (by omega : (2:ℕ)≠0),zero_mul,integral_zero]) + have he (n : ℕ) : (∫ p : S×(ℕ → ℝ), + (countableGaussianField w L p.2 p.1-truncatedCountableGaussianField w L n p.2 p.1)^2* + Real.exp (t*countableGaussianHamiltonian W v L p.2 p.1) ∂(μ.prod countableGaussianLaw)) = + ∫ x, ∫ g, |countableGaussianField (gaussianTailCoefficient w n) L g x|^2* + Real.exp (t*countableGaussianHamiltonian W v L g x) ∂countableGaussianLaw ∂μ := by + simpa only [countableGaussianField_tail,sq_abs] using integral_prod _ (hm n) + simp_rw [he] + simpa only [integral_zero] using ht + +end + +lemma integral_mul_le_sqrt_integrals {X : Type*} [MeasurableSpace X] (ρ : Measure X) + {a b : X → ℝ} (ha : AEStronglyMeasurable a ρ) (hb : AEStronglyMeasurable b ρ) + (ha0 : ∀ᵐ x ∂ρ, 0 ≤ a x) (hb0 : ∀ᵐ x ∂ρ, 0 ≤ b x) + (hai : Integrable (fun x => a x^2) ρ) (hbi : Integrable (fun x => b x^2) ρ) : + (∫ x, a x*b x ∂ρ) ≤ Real.sqrt (∫ x, a x^2 ∂ρ)*Real.sqrt (∫ x, b x^2 ∂ρ) := by + have h := integral_mul_le_Lp_mul_Lq_of_nonneg Real.HolderConjugate.two_two ha0 hb0 + (by simpa using (memLp_two_iff_integrable_sq ha).mpr hai) + (by simpa using (memLp_two_iff_integrable_sq hb).mpr hbi) + simpa only [← Real.sqrt_eq_rpow,Real.rpow_two] using h + +variable {S Ω : Type*} [MeasurableSpace S] [MeasurableSpace Ω] +variable (μ : Measure S) (ν : Measure Ω) [IsProbabilityMeasure μ] [SFinite ν] +variable {H F : Ω → S → ℝ} (hH : Measurable (Function.uncurry H)) +variable (hF : Measurable (Function.uncurry F)) +variable (hZ : Integrable (fun g => (tiltPartition μ (H g) 1)⁻¹^2) ν) +variable (hI : Integrable (fun p : S×Ω => F p.2 p.1^2*Real.exp (2*H p.2 p.1)) (μ.prod ν)) + +include hH in +lemma tiltPartition_joint_measurable : Measurable (fun g => tiltPartition μ (H g) 1) := by + simpa only [tiltPartition,one_mul,Function.uncurry_apply_pair] using + hH.exp.stronglyMeasurable.integral_prod_right'.measurable + +include hH hF hZ hI in +lemma weighted_gibbs_L1_integrable : + Integrable (fun p : S×Ω => (tiltPartition μ (H p.2) 1)⁻¹* + (|F p.2 p.1| *Real.exp (H p.2 p.1))) (μ.prod ν) := by + have ha : AEStronglyMeasurable (fun p : S×Ω => (tiltPartition μ (H p.2) 1)⁻¹) (μ.prod ν) := + ((tiltPartition_joint_measurable μ hH).comp measurable_snd).inv.aestronglyMeasurable + have hb : AEStronglyMeasurable (fun p : S×Ω => |F p.2 p.1| *Real.exp (H p.2 p.1)) (μ.prod ν) := + (((hF.comp measurable_swap).abs).mul (hH.comp measurable_swap).exp).aestronglyMeasurable + have hai : Integrable (fun p : S×Ω => ((tiltPartition μ (H p.2) 1)⁻¹)^2) (μ.prod ν) := + measurePreserving_snd.integrable_comp_of_integrable hZ + have hbi : Integrable (fun p : S×Ω => (|F p.2 p.1| *Real.exp (H p.2 p.1))^2) (μ.prod ν) := by + simpa only [mul_pow,sq_abs,← Real.exp_nat_mul,Nat.cast_ofNat] using hI + exact (memLp_two_iff_integrable_sq ha).mpr hai |>.integrable_mul + ((memLp_two_iff_integrable_sq hb).mpr hbi) + +omit [MeasurableSpace Ω] [IsProbabilityMeasure μ] in +lemma tiltMean_abs_eq_weighted_integral (g : Ω) : + tiltMean μ (H g) (fun x => |F g x|) 1 = + ∫ x, (tiltPartition μ (H g) 1)⁻¹*(|F g x| *Real.exp (H g x)) ∂μ := by + simp only [tiltMean,tiltIntegral,one_mul,integral_const_mul] + rw [div_eq_inv_mul] + congr 1 + apply integral_congr_ae + exact ae_of_all _ fun _ => mul_comm _ _ + +include hH hF hZ hI in +lemma tiltMean_abs_annealed_integrable : + Integrable (fun g => tiltMean μ (H g) (fun x => |F g x|) 1) ν := by + simp_rw [tiltMean_abs_eq_weighted_integral μ] + exact (weighted_gibbs_L1_integrable μ ν hH hF hZ hI).integral_prod_right + +include hH hF hZ hI in +lemma tiltMean_abs_annealed_L2_bound : + (∫ g, tiltMean μ (H g) (fun x => |F g x|) 1 ∂ν) ≤ + Real.sqrt (∫ g, (tiltPartition μ (H g) 1)⁻¹^2 ∂ν)* + Real.sqrt (∫ p : S×Ω, F p.2 p.1^2*Real.exp (2*H p.2 p.1) ∂(μ.prod ν)) := by + have ha : AEStronglyMeasurable (fun p : S×Ω => (tiltPartition μ (H p.2) 1)⁻¹) (μ.prod ν) := + ((tiltPartition_joint_measurable μ hH).comp measurable_snd).inv.aestronglyMeasurable + have hb : AEStronglyMeasurable (fun p : S×Ω => |F p.2 p.1| *Real.exp (H p.2 p.1)) (μ.prod ν) := + (((hF.comp measurable_swap).abs).mul (hH.comp measurable_swap).exp).aestronglyMeasurable + have hai : Integrable (fun p : S×Ω => ((tiltPartition μ (H p.2) 1)⁻¹)^2) (μ.prod ν) := + measurePreserving_snd.integrable_comp_of_integrable hZ + have hbi : Integrable (fun p : S×Ω => (|F p.2 p.1| *Real.exp (H p.2 p.1))^2) (μ.prod ν) := by + simpa only [mul_pow,sq_abs,← Real.exp_nat_mul,Nat.cast_ofNat] using hI + have ha0 : ∀ p : S×Ω, 0 ≤ (tiltPartition μ (H p.2) 1)⁻¹ := by + intro p + exact inv_nonneg.mpr (integral_nonneg (fun _ => (Real.exp_pos _).le)) + have hh := integral_mul_le_sqrt_integrals (μ.prod ν) ha hb (ae_of_all _ ha0) + (ae_of_all _ fun _ => by positivity) hai hbi + rw [integral_prod _ (weighted_gibbs_L1_integrable μ ν hH hF hZ hI), + integral_integral_swap (weighted_gibbs_L1_integrable μ ν hH hF hZ hI)] at hh + simp_rw [← tiltMean_abs_eq_weighted_integral μ] at hh + have he : (∫ p : S×Ω, (tiltPartition μ (H p.2) 1)⁻¹^2 ∂(μ.prod ν)) = + ∫ g, (tiltPartition μ (H g) 1)⁻¹^2 ∂ν := by + rw [integral_prod _ hai] + simp only [integral_const,probReal_univ,one_smul] + simpa only [he,mul_pow,sq_abs,← Real.exp_nat_mul,Nat.cast_ofNat] using hh + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianGibbsContinuity.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianGibbsContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..fd703a9bd9be4fce8353720aeb16ae4ebdf24fb1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianGibbsContinuity.lean @@ -0,0 +1,135 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.KernelReplicaGibbs + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +section +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +lemma coupling_tiltIntegral_continuous {H Y G : S → ℝ} + (hH : Measurable H) (hY : Measurable Y) (hG : Measurable G) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Continuous (fun a => tiltIntegral μ (fun x => H x+a*Y x) G 1) := by + rw [continuous_iff_continuousAt] + intro a + simp only [tiltIntegral,one_mul] + change Tendsto (fun b => ∫ x, Real.exp (H x+b*Y x)*G x ∂μ) (𝓝 a) + (𝓝 (∫ x, Real.exp (H x+a*Y x)*G x ∂μ)) + apply tendsto_integral_filter_of_dominated_convergence + (fun x => (Real.exp (H x+(a-1)*Y x)+Real.exp (H x+(a+1)*Y x))*B) + · exact Eventually.of_forall fun b => ((hH.add (hY.const_mul b)).exp.mul hG).aestronglyMeasurable + · filter_upwards [Ioo_mem_nhds (by linarith : a-1 (show Continuous (fun b : ℝ => Real.exp (H x+b*Y x)*G x) from by fun_prop).continuousAt + +lemma coupling_tiltMean_continuous {H Y G : S → ℝ} + (hH : Measurable H) (hY : Measurable Y) (hG : Measurable G) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Continuous (fun a => tiltMean μ (fun x => H x+a*Y x) G 1) := by + have hp : Continuous (fun a => tiltPartition μ (fun x => H x+a*Y x) 1) := by + simpa only [tiltIntegral,tiltPartition,mul_one] using + coupling_tiltIntegral_continuous μ hH hY measurable_const he (by norm_num : (0:ℝ) ≤ 1) + (fun _ => by norm_num : ∀ x : S, |(fun _ : S => (1:ℝ)) x| ≤ 1) + exact (coupling_tiltIntegral_continuous μ hH hY hG he hB hGB).div hp + (fun a => (tilt_partition_pos_of_integrable μ (by simpa only [one_mul] using he a)).ne') + +lemma coupling_gibbsReplicaMean_continuous {H Y : S → ℝ} {n : ℕ} {G : (Fin n → S) → ℝ} + (hH : Measurable H) (hY : Measurable Y) (hG : Measurable G) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Continuous (fun a => gibbsReplicaMean μ (fun x => H x+a*Y x) n G) := by + have hr (a : ℝ) : replicaPotential (fun x => H x+a*Y x) n = + fun x => replicaPotential H n x+a*replicaPotential Y n x := by + funext x + simp [replicaPotential,Finset.sum_add_distrib,Finset.mul_sum] + have hi (a : ℝ) : Integrable (fun x => Real.exp (replicaPotential H n x+a*replicaPotential Y n x)) + (Measure.pi (fun _ : Fin n => μ)) := by + simpa only [one_mul,hr] using replica_exp_integrable μ (H := fun x => H x+a*Y x) (t := 1) (by simpa only [one_mul] using he a) n + simpa only [gibbsReplicaMean,hr] using coupling_tiltMean_continuous (Measure.pi (fun _ : Fin n => μ)) + (replicaPotential_measurable hH n) (replicaPotential_measurable hY n) hG hi hB hGB + +end +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (P : Measure A) [IsFiniteMeasure P] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma annealedCoupling_tiltMean_continuous {H Y : A → S → ℝ} {G : S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) (hG : Measurable G) + (he : ∀ᵐ g ∂P, ∀ a : ℝ, Integrable (fun x => Real.exp (H g x+a*Y g x)) μ) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Continuous (fun a => ∫ g, tiltMean μ (fun x => H g x+a*Y g x) G 1 ∂P) := by + rw [continuous_iff_continuousAt] + intro a + apply tendsto_integral_filter_of_dominated_convergence (fun _ => B) + · exact Eventually.of_forall fun b => (kernel_tiltMean_measurable (Kernel.const A μ) (H := fun g x => H g x+b*Y g x) (Y := fun _ => G) + (hH.add (hY.const_mul b)) (hG.comp measurable_snd)).aestronglyMeasurable + · exact Eventually.of_forall fun b => ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs,Pi.add_apply] using tiltMean_bound_general μ (H := fun x => H g x+b*Y g x) + (hH.of_uncurry_left.add (hY.of_uncurry_left.const_mul b)) hG hB hGB + · exact integrable_const _ + · filter_upwards [he] with g hg + exact (coupling_tiltMean_continuous μ hH.of_uncurry_left hY.of_uncurry_left hG hg hB hGB).continuousAt + +lemma annealedCoupling_replicaMean_continuous {H Y : A → S → ℝ} {n : ℕ} {G : (Fin n → S) → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) (hG : Measurable G) + (he : ∀ᵐ g ∂P, ∀ a : ℝ, Integrable (fun x => Real.exp (H g x+a*Y g x)) μ) + {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Continuous (fun a => ∫ g, gibbsReplicaMean μ (fun x => H g x+a*Y g x) n G ∂P) := by + rw [continuous_iff_continuousAt] + intro a + apply tendsto_integral_filter_of_dominated_convergence (fun _ => B) + · exact Eventually.of_forall fun b => (kernel_replicaMean_measurable (Kernel.const A μ) (H := fun g x => H g x+b*Y g x) (G := fun _ => G) + (hH.add (hY.const_mul b)) (hG.comp measurable_snd)).aestronglyMeasurable + · exact Eventually.of_forall fun b => ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs,gibbsReplicaMean,Pi.add_apply] using tiltMean_bound_general + (Measure.pi (fun _ : Fin n => μ)) + (replicaPotential_measurable (v := fun x => H g x+b*Y g x) (hH.of_uncurry_left.add (hY.of_uncurry_left.const_mul b)) n) hG hB hGB + · exact integrable_const _ + · filter_upwards [he] with g hg + exact (coupling_gibbsReplicaMean_continuous μ hH.of_uncurry_left hY.of_uncurry_left hG hg hB hGB).continuousAt + +lemma sqrt_coupling_derivative {M C : ℝ → ℝ} + (hd : ∀ a, HasDerivAt M (a*C a) a) {t : ℝ} (ht : 0 M (Real.sqrt s)) (C (Real.sqrt t)/2) t := by + have hh := (hd (Real.sqrt t)).comp t (Real.hasDerivAt_sqrt ht.ne') + have hp := (Real.sqrt_pos.mpr ht).ne' + have he : Real.sqrt t*C (Real.sqrt t)*(1/(2*Real.sqrt t))=C (Real.sqrt t)/2 := by + field_simp [hp] + simpa only [Function.comp_def,he] using hh + +lemma sqrt_coupling_right_derivative {M C : ℝ → ℝ} + (hd : ∀ a, HasDerivAt M (a*C a) a) (hC : Continuous C) : + HasDerivWithinAt (fun s => M (Real.sqrt s)) (C 0/2) (Ici 0) 0 := by + have hm : Continuous M := continuous_iff_continuousAt.mpr fun a => (hd a).continuousAt + apply hasDerivWithinAt_Ici_of_tendsto_deriv (s := Ioi 0) + · intro t ht + exact (sqrt_coupling_derivative hd ht).differentiableAt.differentiableWithinAt + · exact (hm.comp Real.continuous_sqrt).continuousWithinAt + · exact self_mem_nhdsWithin + · have hh : Tendsto (fun t => C (Real.sqrt t)/2) (𝓝[>] 0) (𝓝 (C 0/2)) := by + simpa only [Function.comp_def,Real.sqrt_zero] using + (((hC.comp Real.continuous_sqrt).div_const 2).continuousAt (x := (0:ℝ))).tendsto.mono_left nhdsWithin_le_nhds + apply hh.congr' + filter_upwards [self_mem_nhdsWithin] with t ht + exact (sqrt_coupling_derivative hd ht).deriv.symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianGibbsEnergy.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianGibbsEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..74781f4c6f6129481c3d14194c8d7eca6d8acce6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianGibbsEnergy.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.CountableGaussianReplicaIBP +import OAI.Probability.Perceptron.Variational.GaussianEnergyMoments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] +variable {W : S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} +variable (hW : Measurable W) (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) +variable (hL : Measurable L) {A D E : ℝ} (hA : ∀ x, |W x| ≤ A) +variable (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) +variable (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) +omit [MeasurableSpace S] in +lemma gaussianTailCoefficient_zero (w : ℕ → S → ℝ) : gaussianTailCoefficient w 0=w := by + funext i x + simp [gaussianTailCoefficient] + +include hW hv hw hL hA hD hE + +lemma gaussianEnergy_tail_tilt_integrable (n : ℕ) : + Integrable (fun g => tiltMean μ (countableGaussianHamiltonian W v L g) + (fun x => |countableGaussianField (gaussianTailCoefficient w n) L g x|) 1) countableGaussianLaw := by + apply tiltMean_abs_annealed_integrable μ countableGaussianLaw + (countableGaussianHamiltonian_measurable hW hv hL) + (countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL) + (gaussianHamiltonianPartition_inverse_power_integrable μ hW hv hL hA hD 2) + simpa only [sq_abs] using gaussianEnergy_weighted_moment_joint_integrable hW hv hw hL hA hD hE μ n 2 2 + +lemma gaussianEnergy_tail_tilt_tendsto : + Tendsto (fun n => ∫ g, tiltMean μ (countableGaussianHamiltonian W v L g) + (fun x => |countableGaussianField (gaussianTailCoefficient w n) L g x|) 1 ∂countableGaussianLaw) + atTop (nhds 0) := by + have hlim := (gaussianEnergy_tail_weighted_L2 hW hv hw hL hA hD hE μ 2).sqrt.const_mul + (Real.sqrt (∫ g, (tiltPartition μ (countableGaussianHamiltonian W v L g) 1)⁻¹^2 ∂countableGaussianLaw)) + simp only [Real.sqrt_zero,mul_zero] at hlim + apply squeeze_zero (fun n => integral_nonneg fun g => ?_) (fun n => ?_) hlim + · unfold tiltMean tiltIntegral tiltPartition + exact div_nonneg (integral_nonneg (fun _ => by positivity)) (integral_nonneg (fun _ => by positivity)) + · have h := tiltMean_abs_annealed_L2_bound μ countableGaussianLaw + (countableGaussianHamiltonian_measurable hW hv hL) + (countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL) + (gaussianHamiltonianPartition_inverse_power_integrable μ hW hv hL hA hD 2) + (by simpa only [sq_abs] using gaussianEnergy_weighted_moment_joint_integrable hW hv hw hL hA hD hE μ n 2 2) + simpa only [countableGaussianField_tail] using h + +lemma gaussianEnergy_tail_weighted_integrable_ae (n : ℕ) : + ∀ᵐ g ∂countableGaussianLaw, + Integrable (fun x => Real.exp (countableGaussianHamiltonian W v L g x)* + countableGaussianField (gaussianTailCoefficient w n) L g x) μ := by + filter_upwards [(gaussianEnergy_weighted_moment_joint_integrable hW hv hw hL hA hD hE μ n 1 1).prod_left_ae] with g hg + apply hg.mono' + · exact (((countableGaussianHamiltonian_measurable hW hv hL).comp + (measurable_const.prodMk measurable_id)).exp.mul + ((countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL).comp + (measurable_const.prodMk measurable_id))).aestronglyMeasurable + · exact ae_of_all _ fun x => by simp only [Real.norm_eq_abs,abs_mul,Real.abs_exp,pow_one,one_mul]; exact le_of_eq (mul_comm _ _) + +lemma gaussianEnergy_tail_replica_integrable {r : ℕ} (j : Fin r) {G : (Fin r → S) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) (n : ℕ) : + Integrable (fun g => gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => countableGaussianField (gaussianTailCoefficient w n) L g (x j)*G x)) countableGaussianLaw := by + have hm : Measurable (fun p : (ℕ → ℝ)×(Fin r → S) => + countableGaussianField (gaussianTailCoefficient w n) L p.1 (p.2 j)*G p.2) := + ((countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL).comp + (measurable_fst.prodMk ((measurable_pi_apply j).comp measurable_snd))).mul (hG.comp measurable_snd) + apply ((gaussianEnergy_tail_tilt_integrable μ hW hv hw hL hA hD hE n).const_mul B).mono' + (replicaMean_varying_measurable μ (countableGaussianHamiltonian_measurable hW hv hL) hm).aestronglyMeasurable + filter_upwards [(countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).prod_left_ae, + gaussianEnergy_tail_weighted_integrable_ae μ hW hv hw hL hA hD hE n] with g hg hf + simpa only [Real.norm_eq_abs] using replicaMean_energy_bound μ j (H := countableGaussianHamiltonian W v L g) + (F := countableGaussianField (gaussianTailCoefficient w n) L g) + ((countableGaussianHamiltonian_measurable hW hv hL).comp (measurable_const.prodMk measurable_id)) + ((countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL).comp + (measurable_const.prodMk measurable_id)) hG (by simpa only [one_mul] using hg) hf hB hGB + +lemma gaussianEnergy_tail_replica_tendsto {r : ℕ} (j : Fin r) {G : (Fin r → S) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Tendsto (fun n => ∫ g, gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => countableGaussianField (gaussianTailCoefficient w n) L g (x j)*G x) ∂countableGaussianLaw) + atTop (nhds 0) := by + have ht := (gaussianEnergy_tail_tilt_tendsto μ hW hv hw hL hA hD hE).const_mul B + simp only [mul_zero] at ht + rw [tendsto_zero_iff_norm_tendsto_zero] + simp only [Real.norm_eq_abs] + apply squeeze_zero (fun _ => abs_nonneg _) (fun n => ?_) ht + calc + _ ≤ ∫ g, |gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => countableGaussianField (gaussianTailCoefficient w n) L g (x j)*G x)| ∂countableGaussianLaw := by + simpa only [Real.norm_eq_abs] using norm_integral_le_integral_norm (μ := countableGaussianLaw) + (fun g => gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => countableGaussianField (gaussianTailCoefficient w n) L g (x j)*G x)) + _ ≤ B*(∫ g, tiltMean μ (countableGaussianHamiltonian W v L g) + (fun x => |countableGaussianField (gaussianTailCoefficient w n) L g x|) 1 ∂countableGaussianLaw) := by + rw [← integral_const_mul] + apply integral_mono_ae (gaussianEnergy_tail_replica_integrable μ hW hv hw hL hA hD hE j hG hB hGB n).abs + ((gaussianEnergy_tail_tilt_integrable μ hW hv hw hL hA hD hE n).const_mul B) + filter_upwards [(countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).prod_left_ae, + gaussianEnergy_tail_weighted_integrable_ae μ hW hv hw hL hA hD hE n] with g hg hf + exact replicaMean_energy_bound μ j (H := countableGaussianHamiltonian W v L g) + (F := countableGaussianField (gaussianTailCoefficient w n) L g) + ((countableGaussianHamiltonian_measurable hW hv hL).comp (measurable_const.prodMk measurable_id)) + ((countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL).comp + (measurable_const.prodMk measurable_id)) hG (by simpa only [one_mul] using hg) hf hB hGB + +lemma gaussianEnergy_replica_integrable {r : ℕ} (j : Fin r) {G : (Fin r → S) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Integrable (fun g => gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => countableGaussianField w L g (x j)*G x)) countableGaussianLaw := by + simpa only [gaussianTailCoefficient_zero] using + gaussianEnergy_tail_replica_integrable μ hW hv hw hL hA hD hE j hG hB hGB 0 + +lemma gaussianEnergy_replica_prefix_tendsto {r : ℕ} (j : Fin r) {G : (Fin r → S) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + Tendsto (fun n => ∫ g, gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => truncatedCountableGaussianField w L n g (x j)*G x) ∂countableGaussianLaw) atTop + (nhds (∫ g, gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => countableGaussianField w L g (x j)*G x) ∂countableGaussianLaw)) := by + have hc : Tendsto (fun _ : ℕ => ∫ g, gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => countableGaussianField w L g (x j)*G x) ∂countableGaussianLaw) atTop + (nhds (∫ g, gibbsReplicaMean μ (countableGaussianHamiltonian W v L g) r + (fun x => countableGaussianField w L g (x j)*G x) ∂countableGaussianLaw)) := tendsto_const_nhds + have ht := hc.sub (gaussianEnergy_tail_replica_tendsto μ hW hv hw hL hA hD hE j hG hB hGB) + simp only [sub_zero] at ht + apply ht.congr + intro n + rw [← integral_sub (gaussianEnergy_replica_integrable μ hW hv hw hL hA hD hE j hG hB hGB) + (gaussianEnergy_tail_replica_integrable μ hW hv hw hL hA hD hE j hG hB hGB n)] + apply integral_congr_ae + have hf := gaussianEnergy_tail_weighted_integrable_ae μ hW hv hw hL hA hD hE 0 + simp only [gaussianTailCoefficient_zero] at hf + filter_upwards [(countableGaussianHamiltonian_exp_joint_integrable μ hW hv hL hA hD 1).prod_left_ae, + hf,gaussianEnergy_tail_weighted_integrable_ae μ hW hv hw hL hA hD hE n] with g hg hfg hqg + have hh : Measurable (countableGaussianHamiltonian W v L g) := + (countableGaussianHamiltonian_measurable hW hv hL).comp (measurable_const.prodMk measurable_id) + have hff : Measurable (countableGaussianField w L g) := + (countableGaussianField_measurable hw hL).comp (measurable_const.prodMk measurable_id) + have hq : Measurable (countableGaussianField (gaussianTailCoefficient w n) L g) := + (countableGaussianField_measurable (gaussianTailCoefficient_measurable hw n) hL).comp + (measurable_const.prodMk measurable_id) + have heq := replicaMean_energy_sub μ j hh hff hq hG (by simpa only [one_mul] using hg) hfg hqg hGB + simpa only [countableGaussianField_tail,sub_sub_cancel] using heq.symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianLinearStability.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianLinearStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a34ac4ed9c6467451a029e591f868b5b1b2b994 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianLinearStability.lean @@ -0,0 +1,62 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianMarkRecursion + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy +section +variable {E : Type} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] + +lemma gaussianLinearBackward_bounded_difference {f g : E → ℝ} {L L' : ℝ≥0} + (hf : LipschitzWith L f) (hg : LipschitzWith L' g) {C : ℝ} + (hC : ∀ x, |f x-g x| ≤ C) + (l : List (ℝ×(E →L[ℝ] E))) (hl : ∀ c ∈ l, 0 ≤ c.1) (x : E) : + |gaussianLinearBackward μ l f x-gaussianLinearBackward μ l g x| ≤ C := by + induction l generalizing x with + | nil => exact hC x + | cons c l ih => + have hl' : ∀ d ∈ l, 0 ≤ d.1 := fun d hd => hl d (List.mem_cons_of_mem c hd) + have hF := gaussianLinearBackward_lipschitz μ hf l hl' + have hG := gaussianLinearBackward_lipschitz μ hg l hl' + exact entropicMean_bounded_difference μ + (fun a => gaussian_integrable_exp_linear_shift μ hF c.2 a x) + (fun a => gaussian_integrable_exp_linear_shift μ hG c.2 a x) + (hl c List.mem_cons_self) (ae_of_all _ fun y => ih hl' (x+c.2 y)) +end + +variable {E : Type} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussianLinearCascadeLog_mean_difference (A : ℕ → E →L[ℝ] E) (R : E →L[ℝ] E) + {f g : E → ℝ} {L L' : ℝ≥0} (hf : LipschitzWith L f) (hg : LipschitzWith L' g) + {C : ℝ} (hC : ∀ x, |f x-g x| ≤ C) + (k : ℕ) (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 gaussianLinearBackward (stdGaussian E) (linearCascadeWord A k z) h (R a)) + (stdGaussian E) := + (lipschitz_memLp_stdGaussian ((gaussianLinearBackward_lipschitz (stdGaussian E) hh _ + (linearCascadeWord_nonneg A k z (fun i => (hz0 i).le))).comp R.lipschitzWith)).integrable (by norm_num) + rw [← integral_sub (hi hf) (hi hg)] + simpa using norm_integral_le_of_norm_le_const (μ := stdGaussian E) + (f := fun a => gaussianLinearBackward (stdGaussian E) (linearCascadeWord A k z) f (R a)- + gaussianLinearBackward (stdGaussian E) (linearCascadeWord A k z) g (R a)) + (C := C) (ae_of_all _ fun a => by + simpa only [Real.norm_eq_abs] using + gaussianLinearBackward_bounded_difference (stdGaussian E) hf hg hC _ + (linearCascadeWord_nonneg A k z (fun i => (hz0 i).le)) (R a)) +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianLinearVariance.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianLinearVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c71cde64e2ae5bab4473b53b120472dcb6c061c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianLinearVariance.lean @@ -0,0 +1,100 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.VarianceProdMemLp +import OAI.Probability.Perceptron.Variational.EnrichedMoments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy + +lemma memLp_prod_of_conditional_square {X Y : Type} [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure X) (ν : Measure Y) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + {F : X×Y → ℝ} {G : X → ℝ} (hF : Measurable F) (hG : MemLp G 2 μ) + (K : ℝ) (hs : ∀ x, MemLp (fun y => F (x,y)) 2 ν) + (hb : ∀ x, (∫ y, (F (x,y)-G x)^2 ∂ν) ≤ K) : MemLp F 2 (μ.prod ν) := by + apply (memLp_two_iff_integrable_sq hF.aestronglyMeasurable).mpr + apply (integrable_prod_iff (hF.pow_const 2).aestronglyMeasurable).mpr + refine ⟨Eventually.of_forall (fun x => (hs x).integrable_sq),?_⟩ + have hi : Integrable (fun x => 2*K+2*(G x)^2) μ := + (integrable_const _).add (hG.integrable_sq.const_mul 2) + apply hi.mono' (hF.pow_const 2).aestronglyMeasurable.norm.integral_prod_right' + exact ae_of_all _ fun x => by + simp only [Real.norm_eq_abs,abs_sq] + rw [abs_of_nonneg (integral_nonneg (fun y : Y => sq_nonneg (F (x,y))))] + have hi1 : Integrable (fun y => (F (x,y)-G x)^2) ν := + ((hs x).sub (memLp_const (G x))).integrable_sq + calc + _ ≤ ∫ y, 2*(F (x,y)-G x)^2+2*(G x)^2 ∂ν := by + apply integral_mono (hs x).integrable_sq ((hi1.const_mul 2).add (integrable_const _)) + intro y + dsimp only [Pi.add_apply] + nlinarith [sq_nonneg (F (x,y)-2*G x)] + _ = 2*(∫ y, (F (x,y)-G x)^2 ∂ν)+2*(G x)^2 := by + rw [integral_add (hi1.const_mul 2) (integrable_const _),integral_const_mul] + simp + _ ≤ _ := by linarith [hb x] + +variable {E : Type} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma linearCascadeWord_pos (A : ℕ → E →L[ℝ] E) (k : ℕ) (z : Fin k → ℝ) + (hz : ∀ i, 0 simp [linearCascadeWord] + | succ k ih => + intro c hc + rcases List.mem_cons.mp hc with rfl|hc + · exact hz 0 + · exact ih (fun i => z i.succ) (fun i => hz i.succ) c hc + +lemma gaussianLinearCascadeLog_variance (A : ℕ → E →L[ℝ] E) (R : E →L[ℝ] E) + {f : E → ℝ} {D : E → StrongDual ℝ E} {L : ℝ≥0} + (hf : LipschitzWith L f) (hd : ∀ x, HasFDerivAt f (D x) x) (hD : Continuous D) + (k : ℕ) (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 gaussianLinearBackward (stdGaussian E) (linearCascadeWord A k z) f (R a) + have hr := gaussianLinearRecursion_realization ν A hf k z hz0 + have hmH : Measurable (fun x : ℕ → E => f (x 0)) := + hf.continuous.measurable.comp (measurable_pi_apply 0) + have hG : MemLp G 2 (stdGaussian E) := lipschitz_memLp_stdGaussian + ((gaussianLinearBackward_lipschitz (stdGaussian E) hf _ + (linearCascadeWord_nonneg A k z (fun i => (hz0 i).le))).comp R.lipschitzWith) + have hsec (a : E) : MemLp (fun η => F (a,η)) 2 (ρ:Measure _) ∧ + (∫ η, (F (a,η)-G a)^2 ∂ρ) ≤ cascadeLogFluctuationConstant k z := by + have H := finiteCascade_terminal_log_second_moment_bound ν (gaussianLinearMarkStep A) + (gaussianLinearMarkStep_measurable A) k z hz hz0 hz1 hmH hr.2 (fun _ => R a) + rw [hr.1] at H + exact H + have hmean (a : E) : (∫ η, F (a,η) ∂ρ)=G a := by + have H := finiteCascade_terminal_log_recursion_of_fractional ν (gaussianLinearMarkStep A) + (gaussianLinearMarkStep_measurable A) k z hz hz0 hz1 hmH hr.2 (fun _ => R a) + rw [hr.1] at H + exact H + have hF := gaussianLinearCascadeLog_measurable A R hf.continuous.measurable k z + have hp := memLp_prod_of_conditional_square (stdGaussian E) ρ hF hG + (cascadeLogFluctuationConstant k z) (fun a => (hsec a).1) (fun a => (hsec a).2) + have hmean' : (fun a => ∫ η, F (a,η) ∂ρ)=G := funext hmean + refine ⟨hp,?_⟩ + apply variance_prod_le_memLp (stdGaussian E) (ρ:Measure (DecoratedCascade E k)) + (F := F) hp (fun a => (hsec a).1) (hmean'.symm ▸ hG) + · intro a + rw [variance_eq_integral (hsec a).1.aestronglyMeasurable.aemeasurable,hmean] + exact (hsec a).2 + · rw [hmean'] + exact gaussianLinearBackward_root_variance (stdGaussian E) hf hd hD _ + (linearCascadeWord_pos A k z hz0) R +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianMarkRecursion.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianMarkRecursion.lean new file mode 100644 index 0000000000000000000000000000000000000000..96495e5717a8c0f31569d1cbef98373a0a8033ac --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianMarkRecursion.lean @@ -0,0 +1,191 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IntegrableProdConditionalSquare +import OAI.Probability.Perceptron.Variational.EntropicHeat + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +section +section +variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] + +lemma gaussian_integrable_exp_linear_shift {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (A : E →L[ℝ] E) (a : ℝ) (x : E) : + Integrable (fun y => Real.exp (a*f (x+A y))) μ := by + have hA : LipschitzWith ‖A‖₊ (fun y => x+A y) := by + apply LipschitzWith.of_dist_le_mul + intro y z + simpa only [dist_add_left] using A.lipschitzWith.dist_le_mul y z + have hg := hf.comp hA + simpa using gaussian_integrable_exp_lipschitz μ hg a 1 (0:E) + +def gaussianLinearEntropic (b : ℝ) (A : E →L[ℝ] E) (f : E → ℝ) (x : E) : ℝ := + entropicMean μ b (fun y => f (x+A y)) + +lemma gaussianLinearEntropic_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) {b : ℝ} (hb : 0 ≤ b) (A : E →L[ℝ] E) : + LipschitzWith L (gaussianLinearEntropic μ b A f) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [Real.dist_eq,gaussianLinearEntropic] + apply entropicMean_bounded_difference μ + (fun a => gaussian_integrable_exp_linear_shift μ hf A a x) + (fun a => gaussian_integrable_exp_linear_shift μ hf A a y) hb + exact ae_of_all _ fun z => by + simpa only [Real.dist_eq,dist_add_right] using hf.dist_le_mul (x+A z) (y+A z) + +def gaussianLinearBackward : List (ℝ×(E →L[ℝ] E)) → (E → ℝ) → E → ℝ + | [],f => f + | (b,A)::l,f => gaussianLinearEntropic μ b A (gaussianLinearBackward l f) + +lemma gaussianLinearBackward_lipschitz {f : E → ℝ} {L : ℝ≥0} + (hf : LipschitzWith L f) (l : List (ℝ×(E →L[ℝ] E))) + (hl : ∀ c ∈ l, 0 ≤ c.1) : LipschitzWith L (gaussianLinearBackward μ l f) := by + induction l with + | nil => exact hf + | cons c l ih => + exact gaussianLinearEntropic_lipschitz μ + (ih (fun d hd => hl d (List.mem_cons_of_mem c hd))) (hl c List.mem_cons_self) c.2 + +end + +variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + +def gaussianLinearMarkStep (A : ℕ → E →L[ℝ] E) : (ℕ → E)×E → ℕ → E := + fun p j => p.1 (j+1)+A j p.2 + +omit [CompleteSpace E] in +lemma gaussianLinearMarkStep_measurable (A : ℕ → E →L[ℝ] E) : + Measurable (gaussianLinearMarkStep A) := by + apply Measurable.of_eval + intro j + exact ((measurable_pi_apply (j+1)).comp measurable_fst).add + ((A j).measurable.comp measurable_snd) + +def linearCascadeWord (A : ℕ → E →L[ℝ] E) : (k : ℕ) → (Fin k → ℝ) → List (ℝ×(E →L[ℝ] E)) + | 0,_ => [] + | k+1,z => (z 0,A k)::linearCascadeWord A k (fun i => z i.succ) + +omit [CompleteSpace E] [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] in +lemma linearCascadeWord_nonneg (A : ℕ → E →L[ℝ] E) (k : ℕ) (z : Fin k → ℝ) + (hz : ∀ i, 0 ≤ z i) : ∀ c ∈ linearCascadeWord A k z, 0 ≤ c.1 := by + induction k with + | zero => simp [linearCascadeWord] + | succ k ih => + intro c hc + rcases List.mem_cons.mp hc with rfl|hc + · exact hz 0 + · exact ih (fun i => z i.succ) (fun i => hz i.succ) c hc + +lemma gaussianLinearRecursion_realization (ν : ProbabilityMeasure E) [IsGaussian (ν:Measure E)] + (A : ℕ → E →L[ℝ] E) {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (k : ℕ) (z : Fin k → ℝ) (hz : ∀ i, 0 < z i) : + (∀ x, finiteCascadeLogRecursion ν (gaussianLinearMarkStep A) k z (fun x => f (x 0)) x= + gaussianLinearBackward (ν:Measure E) (linearCascadeWord A k z) f (x k)) ∧ + finiteCascadeFractionalIntegrable ν (gaussianLinearMarkStep A) (fun x => f (x 0)) k z := by + induction k with + | zero => exact ⟨fun _ => rfl,trivial⟩ + | succ k ih => + have H := ih (fun i => z i.succ) (fun i => hz i.succ) + let g := gaussianLinearBackward (ν:Measure E) (linearCascadeWord A k (fun i => z i.succ)) f + have hg : LipschitzWith L g := gaussianLinearBackward_lipschitz (ν:Measure E) hf _ + (linearCascadeWord_nonneg A k _ (fun i => (hz i.succ).le)) + constructor + · intro x + simp only [finiteCascadeLogRecursion,fractionalLogMoment,H.1,gaussianLinearMarkStep, + linearCascadeWord,gaussianLinearBackward,gaussianLinearEntropic] + rw [entropicMean_eq_div (ν:Measure E) + (fun a => gaussian_integrable_exp_linear_shift (ν:Measure E) hg (A k) a (x (k+1))) + (hz 0).ne'] + rfl + · constructor + · intro x + simp only [H.1,gaussianLinearMarkStep] + exact gaussian_integrable_exp_linear_shift (ν:Measure E) hg (A k) (z 0) (x (k+1)) + · exact H.2 + +end +variable {E : Type} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def gaussianMarkLaw : ProbabilityMeasure E := ⟨stdGaussian E,inferInstance⟩ + +lemma lipschitz_memLp_stdGaussian {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) : + MemLp f 2 (stdGaussian E) := by + have hg : LipschitzWith L (fun x => f x-f 0) := by + intro x y + simpa only [edist_sub_right] using hf x y + have hh := (hg.comp_memLp (by simp) (IsGaussian.memLp_id (stdGaussian E) 2 (by simp))).add + (memLp_const (f 0)) + convert hh using 1 + ext x + simp + +def gaussianLinearCascadeLog (A : ℕ → E →L[ℝ] E) (R : E →L[ℝ] E) + (f : E → ℝ) (k : ℕ) (a : E×DecoratedCascade E k) : ℝ := + Real.log (decoratedTerminalTotal (gaussianLinearMarkStep A) (fun x => f (x 0)) k + ((fun _ => R a.1),a.2) / + decoratedTerminalTotal (gaussianLinearMarkStep A) (fun _ => 0) k ((fun _ => R a.1),a.2)) + +lemma gaussianLinearCascadeLog_measurable (A : ℕ → E →L[ℝ] E) (R : E →L[ℝ] E) + {f : E → ℝ} (hf : Measurable f) (k : ℕ) (z : Fin k → ℝ) : + Measurable (gaussianLinearCascadeLog A R f k) := by + let ν : ProbabilityMeasure E := gaussianMarkLaw + have hm : Measurable (fun a : E×DecoratedCascade E k => ((fun _ : ℕ => R a.1),a.2)) := + (Measurable.of_eval (fun _ => R.measurable.comp measurable_fst)).prodMk measurable_snd + exact (((decoratedTerminalTotal_measurable ν _ (gaussianLinearMarkStep_measurable A) + (hf.comp (measurable_pi_apply 0)) k z).div + (decoratedTerminalTotal_measurable ν _ (gaussianLinearMarkStep_measurable A) + measurable_const k z)).log).comp hm + +lemma gaussianLinearCascadeLog_mean (A : ℕ → E →L[ℝ] E) (R : E →L[ℝ] E) + {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (k : ℕ) (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 gaussianLinearBackward (stdGaussian E) (linearCascadeWord A k z) f (R a) + have hr := gaussianLinearRecursion_realization ν A hf k z hz0 + have hmH : Measurable (fun x : ℕ → E => f (x 0)) := + hf.continuous.measurable.comp (measurable_pi_apply 0) + have hG : MemLp G 2 (stdGaussian E) := lipschitz_memLp_stdGaussian + ((gaussianLinearBackward_lipschitz (stdGaussian E) hf _ + (linearCascadeWord_nonneg A k z (fun i => (hz0 i).le))).comp R.lipschitzWith) + have hsec (a : E) : MemLp (fun η => F (a,η)) 2 (ρ:Measure _) ∧ + (∫ η, (F (a,η)-G a)^2 ∂ρ) ≤ cascadeLogFluctuationConstant k z := by + have H := finiteCascade_terminal_log_second_moment_bound ν (gaussianLinearMarkStep A) + (gaussianLinearMarkStep_measurable A) k z hz hz0 hz1 hmH hr.2 (fun _ => R a) + rw [hr.1] at H + exact H + have hF := gaussianLinearCascadeLog_measurable A R hf.continuous.measurable k z + have hi : Integrable F ((stdGaussian E).prod ρ) := + integrable_prod_of_conditional_square (stdGaussian E) ρ hF hG + (cascadeLogFluctuationConstant k z) (fun a => (hsec a).1) (fun a => (hsec a).2) + refine ⟨hi,?_⟩ + rw [integral_prod _ hi] + apply integral_congr_ae + exact ae_of_all _ fun a => by + have H := finiteCascade_terminal_log_recursion_of_fractional ν (gaussianLinearMarkStep A) + (gaussianLinearMarkStep_measurable A) k z hz hz0 hz1 hmH hr.2 (fun _ => R a) + rw [hr.1] at H + exact H + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GaussianWordStability.lean b/lean/OAI/Probability/Perceptron/Variational/GaussianWordStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..e7147abc01c1bf6916c8238cf07beb589e1b81e1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GaussianWordStability.lean @@ -0,0 +1,71 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianBackward + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [IsGaussian μ] +lemma gaussianBackward_label_parameter_bound {I : Type*} {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (l : List (I×ℝ)) (a b : I → ℝ) {S : ℝ} + (ha : ∀ c ∈ l, a c.1 ∈ Icc (0:ℝ) 1) (hb : ∀ c ∈ l, b c.1 ∈ Icc (0:ℝ) 1) + (hσ : ∀ c ∈ l, c.2 ∈ Icc (0:ℝ) S) : ∀ x, + |gaussianBackward μ (l.map fun c => (a c.1,c.2)) f x- + gaussianBackward μ (l.map fun c => (b c.1,c.2)) f x| ≤ + gaussianEntropicParamConstant μ L S*(l.map fun c => c.2^2*|a c.1-b c.1|).sum := by + induction l with + | nil => intro x; simp [gaussianBackward] + | cons c l ih => + have ha' := fun d hd => ha d (List.mem_cons_of_mem c hd) + have hb' := fun d hd => hb d (List.mem_cons_of_mem c hd) + have hσ' := fun d hd => hσ d (List.mem_cons_of_mem c hd) + have hla : LipschitzWith L (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) := by + apply gaussianBackward_lipschitz μ hf + intro d hd + obtain ⟨e,he,rfl⟩ := List.mem_map.mp hd + exact (ha' e he).1 + have hlb : LipschitzWith L (gaussianBackward μ (l.map fun d => (b d.1,d.2)) f) := by + apply gaussianBackward_lipschitz μ hf + intro d hd + obtain ⟨e,he,rfl⟩ := List.mem_map.mp hd + exact (hb' e he).1 + intro x + simp only [List.map_cons,List.sum_cons,gaussianBackward] + have H1 := gaussianEntropic_parameter_bound μ hla (ha c List.mem_cons_self) + (hb c List.mem_cons_self) (hσ c List.mem_cons_self).1 (hσ c List.mem_cons_self).2 x + have H2 := entropicMean_bounded_difference μ + (fun t => gaussian_integrable_exp_lipschitz μ hla t c.2 x) + (fun t => gaussian_integrable_exp_lipschitz μ hlb t c.2 x) (hb c List.mem_cons_self).1 + (ae_of_all _ fun y => ih ha' hb' hσ' (x+c.2 • y)) + have HT := abs_sub_le (gaussianEntropic μ (a c.1) c.2 (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) x) + (gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) x) + (gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (b d.1,d.2)) f) x) + dsimp [entropicMean] at H2 + change |gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (a d.1,d.2)) f) x- + gaussianEntropic μ (b c.1) c.2 (gaussianBackward μ (l.map fun d => (b d.1,d.2)) f) x| ≤ _ at H2 + nlinarith + +lemma gaussianBackward_ofFn_parameter_bound {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (N : ℕ) (a b σ : Fin N → ℝ) {S : ℝ} + (ha : ∀ i, a i ∈ Icc (0:ℝ) 1) (hb : ∀ i, b i ∈ Icc (0:ℝ) 1) + (hσ : ∀ i, σ i ∈ Icc (0:ℝ) S) (x : E) : + |gaussianBackward μ (List.ofFn fun i => (a i,σ i)) f x- + gaussianBackward μ (List.ofFn fun i => (b i,σ i)) f x| ≤ + gaussianEntropicParamConstant μ L S*(∑ i, (σ i)^2*|a i-b i|) := by + have ha' : ∀ c ∈ List.ofFn (fun i => (i,σ i)), a c.1 ∈ Icc (0:ℝ) 1 := by + intro c hc; obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hc; exact ha i + have hb' : ∀ c ∈ List.ofFn (fun i => (i,σ i)), b c.1 ∈ Icc (0:ℝ) 1 := by + intro c hc; obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hc; exact hb i + have hσ' : ∀ c ∈ List.ofFn (fun i => (i,σ i)), c.2 ∈ Icc (0:ℝ) S := by + intro c hc; obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hc; exact hσ i + simpa only [List.map_ofFn,List.sum_ofFn,Function.comp_def] using + gaussianBackward_label_parameter_bound μ hf (List.ofFn fun i => (i,σ i)) a b ha' hb' hσ' x + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GibbsRestoration.lean b/lean/OAI/Probability/Perceptron/Variational/GibbsRestoration.lean new file mode 100644 index 0000000000000000000000000000000000000000..c468c5543caaebb7449a5cfd2482597ef90a21ae --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GibbsRestoration.lean @@ -0,0 +1,73 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.IntegrableReplicaGibbs + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma tiltMean_restore {H W F : S→ℝ} (_hH : Measurable H) + (hi : Integrable (fun x => Real.exp (H x)) μ) : + tiltMean μ (fun x => H x+W x) F 1 = + tiltMean μ H (fun x => Real.exp (W x)*F x) 1 / + tiltMean μ H (fun x => Real.exp (W x)) 1 := by + have hp : tiltPartition μ H 1≠0 := + (tilt_partition_pos_of_integrable μ (by simpa only [one_mul] using hi)).ne' + simp only [tiltMean,tiltIntegral,tiltPartition,one_mul,Real.exp_add,mul_assoc] + have hp' : (∫ x, Real.exp (H x) ∂μ) ≠ 0 := by + simpa only [tiltPartition,one_mul] using hp + exact (div_div_div_cancel_right₀ hp' _ _).symm + +lemma gibbsReplicaMean_fintype_prod {H F : S→ℝ} (hH : Measurable H) + (hi : Integrable (fun x => Real.exp (H x)) μ) (r : ℕ) : + gibbsReplicaMean μ H r (fun x => ∏ i, F (x i))=(tiltMean μ H F 1)^r := by + have hi' : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using hi + let := tilt_law_probability_of_integrable μ hi' + rw [gibbsReplicaMean_integral_of_integrable μ hH hi, + ← tilt_law_integral_of_integrable μ hH hi'] + simpa only [Fintype.card_fin] using integral_fintype_prod_eq_pow (ι:=Fin r) F (μ:=tiltLaw μ H 1) + +lemma gibbsReplicaMean_restore {H W : S→ℝ} (hH : Measurable H) + (hi : Integrable (fun x => Real.exp (H x)) μ) (r : ℕ) (F : (Fin r→S)→ℝ) : + gibbsReplicaMean μ (fun x => H x+W x) r F = + gibbsReplicaMean μ H r (fun x => (∏ i, Real.exp (W (x i)))*F x) / + (tiltMean μ H (fun x => Real.exp (W x)) 1)^r := by + have hp : replicaPotential (fun x => H x+W x) r = + fun x => replicaPotential H r x+replicaPotential W r x := by + funext x; simp only [replicaPotential,Finset.sum_add_distrib] + have hir : Integrable (fun x => Real.exp (replicaPotential H r x)) (Measure.pi fun _ : Fin r => μ) := by + simpa only [one_mul] using (replica_exp_integrable μ + (show Integrable (fun x => Real.exp (1*H x)) μ by simpa only [one_mul] using hi) r) + unfold gibbsReplicaMean + rw [hp,tiltMean_restore _ (replicaPotential_measurable hH r) hir] + simp only [replicaPotential,Real.exp_sum] + congr 1 + exact gibbsReplicaMean_fintype_prod μ (F:=fun x => Real.exp (W x)) hH hi r + +lemma tiltMean_exp_bounds {H W : S→ℝ} (hH : Measurable H) (hW : Measurable W) + (hi : Integrable (fun x => Real.exp (H x)) μ) {C : ℝ} (_hC : 0≤C) + (hWb : ∀ x, |W x|≤C) : + Real.exp (-C) ≤ tiltMean μ H (fun x => Real.exp (W x)) 1 ∧ + tiltMean μ H (fun x => Real.exp (W x)) 1 ≤ Real.exp C := by + have hi' : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using hi + let := tilt_law_probability_of_integrable μ hi' + rw [←tilt_law_integral_of_integrable μ hH hi'] + have hI : Integrable (fun x => Real.exp (W x)) (tiltLaw μ H 1) := by + apply Integrable.of_bound hW.exp.aestronglyMeasurable (Real.exp C) + exact ae_of_all _ fun x => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (abs_le.mp (hWb x)).2 + constructor + · simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono (integrable_const (Real.exp (-C))) hI + (fun x => Real.exp_le_exp.mpr (abs_le.mp (hWb x)).1) + · simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono hI (integrable_const (Real.exp C)) + (fun x => Real.exp_le_exp.mpr (abs_le.mp (hWb x)).2) +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GlobalContact.lean b/lean/OAI/Probability/Perceptron/Variational/GlobalContact.lean new file mode 100644 index 0000000000000000000000000000000000000000..654137c51adf5cf0a9c3ae06fb2fbd0b60140bab --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GlobalContact.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StepEntropy +import OAI.Probability.Perceptron.Variational.RightDerivativeIntegral +import OAI.Probability.Perceptron.Variational.DensityLipschitz + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +def sourceStepFieldCap (k : ℕ) (H : ℝ) : Set (Fin (k+1)→ℝ) := + Icc (fun _ => 0) (fun _ => H) ∩ {h | Monotone h} + +def sourceContactCompactDomain (n k : ℕ) (α : ℝ≥0) (H : ℝ) : Set (SourceContactParameter n k) := + Icc 0 α ×ˢ (sourceStepFieldCap k H ×ˢ Icc (fun _ => 1) (fun _ => 2)) + +lemma sourceStepFieldCap_compact (k : ℕ) (H : ℝ) : IsCompact (sourceStepFieldCap k H) := + isCompact_Icc.inter_right isClosed_monotone + +lemma sourceContactCompactDomain_compact (n k : ℕ) (α : ℝ≥0) (H : ℝ) : + IsCompact (sourceContactCompactDomain n k α H) := + isCompact_Icc.prod ((sourceStepFieldCap_compact k H).prod isCompact_Icc) + +lemma sourceContactCompactDomain_nonempty (n k : ℕ) (α : ℝ≥0) {H : ℝ} (hH : 0≤H) : + (sourceContactCompactDomain n k α H).Nonempty := by + refine ⟨(0,(fun _ => 0),(fun _ => 3/2)),?_,?_,?_⟩ + · exact ⟨le_rfl,zero_le⟩ + · exact ⟨⟨fun _ => le_rfl,fun _ => hH⟩,monotone_const⟩ + · constructor <;> intro j <;> norm_num + +lemma sourceContactCompactDomain_subset (n k : ℕ) (α : ℝ≥0) (H : ℝ) : + sourceContactCompactDomain n k α H ⊆ sourceContactDomain n k := by + intro a ha + exact ⟨ha.2.1.1.1,ha.2.1.2,fun j => ⟨ha.2.2.1 j,ha.2.2.2 j⟩⟩ + +def sourceStepContactObjective (n k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) (δ : ℝ) (a : SourceContactParameter n k) : ℝ := + -sourceJointPressure n k f p d (stepCumulative w) a- + (∑ i, w i*(q i:ℝ)*a.2.1 i)+ + (entropy (weightedStepTrial w q hw hw1)).toReal+ + (a.1:ℝ)*(controlValue P f (weightedStepTrial w q hw hw1)+δ)+ + quadraticBoxPenalty (sourcePenaltyWeight (n+1)) a.2.2 + +lemma sourceStepContactObjective_continuousOn (n k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0 (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) := by + have hp := (sourceJointPressure_continuousOn n k f p d (stepCumulative w) + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1)).mono + (sourceContactCompactDomain_subset n k α H) + have hc : Continuous (fun a : SourceContactParameter n k => + -(∑ i, w i*(q i:ℝ)*a.2.1 i)+(entropy (weightedStepTrial w q (fun i => (hw i).le) hw1)).toReal+ + (a.1:ℝ)*(controlValue P f (weightedStepTrial w q (fun i => (hw i).le) hw1)+δ)+ + quadraticBoxPenalty (sourcePenaltyWeight (n+1)) a.2.2) := by + unfold quadraticBoxPenalty + fun_prop + convert hp.neg.add hc.continuousOn using 1 + ext a + simp only [sourceStepContactObjective,Pi.add_apply,Pi.neg_apply] + ring + +lemma source_global_contact_exists (n k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0 (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) a := + (sourceContactCompactDomain_compact n k α H).exists_isMinOn + (sourceContactCompactDomain_nonempty n k α hH) + (sourceStepContactObjective_continuousOn n k P f p d w q hw hw1 δ α H) + +lemma source_global_contact_perturbation_min (n k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0≤w i) (hw1 : ∑ i, w i=1) (δ : ℝ) (α : ℝ≥0) (H : ℝ) + {a : SourceContactParameter n k} (ha : a∈sourceContactCompactDomain n k α H) + (hmin : IsMinOn (sourceStepContactObjective n k P f p d w q hw hw1 δ) + (sourceContactCompactDomain n k α H) a) : + IsMinOn (fun u => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) u- + sourceExpectedPressure n k f p d a.2.1 (stepCumulative w) a.1 u) + (Icc (fun _ => 1) (fun _ => 2)) a.2.2 := by + intro u hu + change quadraticBoxPenalty (sourcePenaltyWeight (n+1)) a.2.2- + sourceExpectedPressure n k f p d a.2.1 (stepCumulative w) a.1 a.2.2 ≤ + quadraticBoxPenalty (sourcePenaltyWeight (n+1)) u- + sourceExpectedPressure n k f p d a.2.1 (stepCumulative w) a.1 u + have he := hmin (show (a.1,a.2.1,u)∈sourceContactCompactDomain n k α H from + ⟨ha.1,ha.2.1,hu⟩) + unfold sourceStepContactObjective sourceJointPressure at he + change -sourceExpectedPressure n k f p d a.2.1 (stepCumulative w) a.1 a.2.2- + (∑ i, w i*(q i:ℝ)*a.2.1 i)+(entropy (weightedStepTrial w q hw hw1)).toReal+ + (a.1:ℝ)*(controlValue P f (weightedStepTrial w q hw hw1)+δ)+ + quadraticBoxPenalty (sourcePenaltyWeight (n+1)) a.2.2 ≤ + -sourceExpectedPressure n k f p d a.2.1 (stepCumulative w) a.1 u- + (∑ i, w i*(q i:ℝ)*a.2.1 i)+(entropy (weightedStepTrial w q hw hw1)).toReal+ + (a.1:ℝ)*(controlValue P f (weightedStepTrial w q hw hw1)+δ)+ + quadraticBoxPenalty (sourcePenaltyWeight (n+1)) u at he + linarith + +lemma source_global_contact_field (n k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0 (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) c) (hcap : c.2.1 (Fin.last k) -sourceExpectedPressure n k f p d (fun l => c.2.1 l+s*a l) + (stepCumulative w) c.1 c.2.2-s*L + let ε := (H-c.2.1 (Fin.last k))/(a (Fin.last k)+1) + have hε : 0<ε := div_pos (sub_pos.mpr hcap) (by linarith [ha0 (Fin.last k)]) + have hεa : ε*a (Fin.last k) ≤ H-c.2.1 (Fin.last k) := by + have he : ε*(a (Fin.last k)+1)=H-c.2.1 (Fin.last k) := by + dsimp [ε]; field_simp [ne_of_gt (show 0 c.2.1 l+s*a l),c.2.2)∈sourceContactCompactDomain n k α H := by + refine ⟨hc.1,⟨⟨?_,?_⟩,hc.2.1.2.add (ha.const_mul hs.1)⟩,hc.2.2⟩ + · intro i + exact add_nonneg (hc.2.1.1.1 i) (mul_nonneg hs.1 (ha0 i)) + · intro i + have hi := hc.2.1.2 (Fin.le_last i) + have hai : s*a i ≤ ε*a (Fin.last k) := + mul_le_mul hs.2 (ha (Fin.le_last i)) (ha0 i) hε.le + linarith + have he := hmin hc' + have hsum : (∑ i, w i*(q i:ℝ)*(c.2.1 i+s*a i))= + (∑ i, w i*(q i:ℝ)*c.2.1 i)+s*L := by + rw [Finset.mul_sum,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intros; ring + change sourceStepContactObjective n k P f p d w q (fun i => (hw i).le) hw1 δ c ≤ + sourceStepContactObjective n k P f p d w q (fun i => (hw i).le) hw1 δ + (c.1,(fun l => c.2.1 l+s*a l),c.2.2) at he + dsimp only [sourceStepContactObjective,sourceJointPressure] at he + rw [hsum] at he + change F 0 ≤ F s + dsimp only [F] + simp only [zero_mul,add_zero,sub_zero] + linarith + let D := ∫ b, gibbsReplicaMean (sourceSpinLeafKernel n k b.1) + (sourceCouplingHamiltonian n k f p d c.2.1 c.2.2 b) 2 (sourceFieldObservable a) + ∂((sourceBaseDataLaw n k (stepCumulative w) c.1).prod countableGaussianLaw) + have hd : HasDerivWithinAt F (D-L) (Ici 0) 0 := by + have hp := sourceExpectedPressure_field_right_derivative n k f p d c.2.2 hc.2.1.1.1 + hc.2.1.2 ha0 ha (stepCumulative w) (stepCumulative_strictMono w hw) + (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1) c.1 + convert hp.neg.sub + (((hasDerivAt_id (0:ℝ)).mul_const L).hasDerivWithinAt (s := Ici 0)) using 1 <;> + first | rfl | simp [D] + have hseg : segment ℝ (0:ℝ) ε ⊆ Icc 0 ε := by rw [segment_eq_Icc hε.le] + have hn := hm.isLocalMinOn.hasFDerivWithinAt_nonneg + (hd.mono (fun _ hx => hx.1)).hasFDerivWithinAt + (sub_mem_posTangentConeAt_of_segment_subset hseg) + change 0≤(ε-0)*(D-L) at hn + change L ≤ D + nlinarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GlobalContactLimit.lean b/lean/OAI/Probability/Perceptron/Variational/GlobalContactLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..b1240b58bbb44438a04b6c294589cacbee749c2f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GlobalContactLimit.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.QuantileLimit +import OAI.Probability.Perceptron.Variational.GlobalContact +import OAI.Probability.Perceptron.Interpolation.FieldArray + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction + +section + +lemma compactPositivePairLaw_field_integral + (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hR : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), ∀ n, + Matrix.PosSemidef (fun i j : Fin n => (Q i j).1.val)) + (hT : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), ∀ n, + Matrix.PosSemidef (fun i j : Fin n => (Q i j).2.val)) + (hn : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), 0≤(Q 0 1).1.val) + {k : ℕ} (a : Fin (k+1)→ℝ) : + (∫ Q, sourceFieldArrayTest a Q ∂ν)= + ∫ x : Time×Time, (sourceFieldPolynomial a).eval x.2.val*x.1.val + ∂compactPositivePairLaw ν := by + have hm : Measurable (fun Q : CompactArray CompactJointOverlap => compactPositivePair (Q 0 1)) := + compactPositivePair_measurable.comp (by fun_prop) + rw [compactPositivePairLaw, integral_map hm.aemeasurable (by fun_prop)] + apply integral_congr_ae + filter_upwards [hR,hT,hn] with Q hr ht hn + dsimp [sourceFieldArrayTest,compactPositivePair] + rw [max_eq_right hn, gram_array_symmetric (fun i j => (Q i j).1.val) hr 0 1, + gram_array_symmetric (fun i j => (Q i j).2.val) ht 0 1] + +lemma compactPositivePairLaw_field_quantile + (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hq : (volume : Measure Time).map (fun u => + (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst) u, + boundedQuantile ((compactPositivePairLaw ν).map Prod.snd) u))=compactPositivePairLaw ν) + {k : ℕ} (a : Fin (k+1)→ℝ) : + (∫ x : Time×Time, (sourceFieldPolynomial a).eval x.2.val*x.1.val + ∂compactPositivePairLaw ν)= + ∫ u : Time, (sourceFieldPolynomial a).eval + (boundedQuantile ((compactPositivePairLaw ν).map Prod.snd) u).val * + (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst) u).val := by + have : IsProbabilityMeasure ((compactPositivePairLaw ν).map Prod.fst) := + (Measure.isProbabilityMeasure_map_iff measurable_fst.aemeasurable).2 inferInstance + have : IsProbabilityMeasure ((compactPositivePairLaw ν).map Prod.snd) := + (Measure.isProbabilityMeasure_map_iff measurable_snd.aemeasurable).2 inferInstance + conv_lhs => rw [← hq] + rw [integral_map ((boundedQuantile_measurable _).prodMk (boundedQuantile_measurable _)).aemeasurable + (by fun_prop)] + +variable (k : ℕ) (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) (p d : ℕ→ℕ) +variable (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) +variable (hw : ∀ i, 0 p i.val) (fun i => d i.val) w q (fun i => (hw i).le) hw1 δ) + (sourceContactCompactDomain n k α H) (c n)) +variable (hcap : ∀ n, (c n).2.1 (Fin.last k) sourceGibbsArrayLaw (s n) k f (fun i => p i.val) (fun i => d i.val) + (c (s n)).2.1 (c (s n)).2.2 (stepCumulative w) (c (s n)).1) atTop (𝓝 ν)) + {a : Fin (k+1)→ℝ} (ha0 : ∀ i, 0≤a i) (ha : Monotone a) : + (∑ i, w i*(q i:ℝ)*a i) ≤ ∫ Q, sourceFieldArrayTest a Q ∂ν := by + have ht := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (sourceFieldArrayTest a)).continuousAt.tendsto.comp hlim + apply ge_of_tendsto ht + exact Eventually.of_forall fun n => by + dsimp only [Function.comp_apply] + rw [sourceGibbsArray_field_integral _ _ _ _ _ _ (hc (s n)).2.1.1.1 (hc (s n)).2.1.2] + exact source_global_contact_field _ _ _ _ _ _ _ _ hw hw1 _ _ _ (hc (s n)) (hmin (s n)) + (hcap (s n)) ha0 ha + +include hc hmin hcap in + +theorem source_global_contact_limit_quantile_field + (hH : 0≤H) (hcover : ∀ a b : ℕ, 1≤a+b → ∃ j, p j=a ∧ d j=b) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} {s : ℕ→ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (fun i => p i.val) (fun i => d i.val) + (c (s n)).2.1 (c (s n)).2.2 (stepCumulative w) (c (s n)).1) atTop (𝓝 ν)) + {a : Fin (k+1)→ℝ} (ha0 : ∀ i, 0≤a i) (ha : Monotone a) : + (∑ i, w i*(q i:ℝ)*a i) ≤ + ∫ u : Time, (sourceFieldPolynomial a).eval (boundedQuantile (sourceLabelLaw k w) u).val * + (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst) u).val := by + have hm n := source_global_contact_perturbation_min n k P f (fun i => p i.val) (fun i => d i.val) + w q (fun i => (hw i).le) hw1 δ α H (hc n) (hmin n) + obtain ⟨hn,hl,hq⟩ := source_contact_limit_quantile k f p d w hw hw1 + (fun n => (c n).1) (fun n => (c n).2.1) (fun n => (hc n).2.1.1.1) + (fun n => (hc n).2.1.2) (fun n => (c n).2.2) (fun n => (hc n).2.2) hm hH + (fun n => (hc n).2.1.1.2 0) (T := (α:ℝ)) (fun n => (hc n).1.2) hcover hs hlim + obtain ⟨hr,ht⟩ := sourceGibbsArray_limit_gram k f (fun _ i => p i.val) (fun _ i => d i.val) + (fun n => (c n).2.1) (fun n => (c n).2.2) (stepCumulative w) (fun n => (c n).1) s hlim + have he := source_global_contact_limit_field k P f p d w q hw hw1 δ α H c hc hmin hcap hlim ha0 ha + rw [compactPositivePairLaw_field_integral ν hr ht hn a, + compactPositivePairLaw_field_quantile ν hq a, hl] at he + exact he + +end + +lemma sourceLabelLaw_ae (k : ℕ) (w : Fin (k+1)→ℝ) {P : Time→Prop} + (hP : ∀ i, P (sourceLabelLevel k i)) : ∀ᵐ x ∂sourceLabelLaw k w, P x := by + rw [sourceLabelLaw,← Measure.sum_fintype,Measure.ae_sum_iff] + intro i + exact Measure.ae_smul_measure (by simpa only [ae_dirac_eq,Filter.eventually_pure] using hP i) _ + +def sourceThresholdDirection {k : ℕ} (q : Fin (k+1)→Time) (r : ℝ) : Fin (k+1)→ℝ := + fun i => if r≤(q i:ℝ) then 1 else 0 + +lemma sourceThresholdDirection_nonneg {k : ℕ} (q : Fin (k+1)→Time) (r : ℝ) (i : Fin (k+1)) : + 0 ≤ sourceThresholdDirection q r i := by unfold sourceThresholdDirection; split_ifs <;> norm_num + +lemma sourceThresholdDirection_le_one {k : ℕ} (q : Fin (k+1)→Time) (r : ℝ) (i : Fin (k+1)) : + sourceThresholdDirection q r i≤1 := by unfold sourceThresholdDirection; split_ifs <;> norm_num + +lemma sourceThresholdDirection_monotone {k : ℕ} {q : Fin (k+1)→Time} (hq : Monotone q) (r : ℝ) : + Monotone (sourceThresholdDirection q r) := by + intro i j hij + unfold sourceThresholdDirection + split_ifs with hi hj hj <;> try norm_num + exact False.elim (hj (hi.trans (hq hij))) + +lemma sourceThresholdDirection_stoploss {k : ℕ} (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) (r : ℝ) : + (∑ i, w i*max ((q i:ℝ)-r) 0)= + (∑ i, w i*(q i:ℝ)*sourceThresholdDirection q r i)-r*∑ i, w i*sourceThresholdDirection q r i := by + rw [Finset.mul_sum,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + dsimp [sourceThresholdDirection] + split_ifs with hi + · rw [max_eq_left (sub_nonneg.mpr hi)]; ring + · rw [max_eq_right (sub_nonpos.mpr (le_of_not_ge hi))]; ring + +lemma stoploss_integrable (μ : Measure Time) [IsFiniteMeasure μ] (r : ℝ) : + Integrable (fun x : Time => max (x.val-r) 0) μ := + (show Continuous (fun x : Time => max (x.val-r) 0) from by fun_prop).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + +lemma source_field_stoploss {k : ℕ} (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0≤w i) (hq : Monotone q) + (μ : Measure (Time×Time)) [IsProbabilityMeasure μ] + (hlabel : μ.map Prod.snd=sourceLabelLaw k w) + (hfield : ∀ a : Fin (k+1)→ℝ, (∀ i, 0≤a i) → Monotone a → + (∑ i, w i*(q i:ℝ)*a i)≤∫ x, (sourceFieldPolynomial a).eval x.2.val*x.1.val ∂μ) + (r : ℝ) : + (∑ i, w i*max ((q i:ℝ)-r) 0)≤∫ x : Time, max (x.val-r) 0 ∂μ.map Prod.fst := by + let a := sourceThresholdDirection q r + let g : Time×Time→ℝ := fun x => (sourceFieldPolynomial a).eval x.2.val + have hg : Continuous g := (sourceFieldPolynomial_continuous a).comp continuous_snd + have hgi : Integrable g μ := hg.integrable_of_hasCompactSupport (HasCompactSupport.of_compactSpace _) + have hprod : Integrable (fun x : Time×Time => g x*x.1.val) μ := + (hg.mul (continuous_subtype_val.comp continuous_fst)).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _) + have hb : ∀ᵐ x ∂μ, g x∈Icc 0 1 := by + have hb' : ∀ᵐ t ∂μ.map Prod.snd, (sourceFieldPolynomial a).eval t.val∈Icc 0 1 := by + rw [hlabel] + apply sourceLabelLaw_ae + intro i + change (sourceFieldPolynomial a).eval ((i.val:ℝ)/(k+1:ℕ))∈Icc 0 1 + rw [sourceFieldPolynomial_eval] + exact ⟨sourceThresholdDirection_nonneg q r i,sourceThresholdDirection_le_one q r i⟩ + exact ae_of_ae_map measurable_snd.aemeasurable hb' + have hint : (∫ x, g x ∂μ)=∑ i, w i*a i := by + have he := sourceLabelLaw_integral k w hw (fun t => (sourceFieldPolynomial a).eval t.val) + (sourceFieldPolynomial_continuous a).measurable + rw [← hlabel,integral_map measurable_snd.aemeasurable + (sourceFieldPolynomial_continuous a).measurable.aestronglyMeasurable] at he + simpa only [sourceLabelLevel,sourceFieldPolynomial_eval] using he + have hm : ∫ x, g x*x.1.val-r*g x ∂μ ≤ ∫ x : Time×Time, max (x.1.val-r) 0 ∂μ := by + apply integral_mono_ae (hprod.sub (hgi.const_mul r)) + ((show Continuous (fun x : Time×Time => max (x.1.val-r) 0) from by fun_prop).integrable_of_hasCompactSupport + (HasCompactSupport.of_compactSpace _)) + filter_upwards [hb] with x hx + change g x*x.1.val-r*g x ≤ max (x.1.val-r) 0 + by_cases hr : r≤x.1.val + · rw [max_eq_left (sub_nonneg.mpr hr)] + nlinarith [mul_nonneg (sub_nonneg.mpr hr) (sub_nonneg.mpr hx.2)] + · rw [max_eq_right (by linarith)] + nlinarith [mul_nonneg (sub_nonneg.mpr (le_of_not_ge hr)) hx.1] + rw [integral_sub hprod (hgi.const_mul r),integral_const_mul,hint] at hm + rw [integral_map measurable_fst.aemeasurable (by fun_prop),sourceThresholdDirection_stoploss] + exact (sub_le_sub_right (hfield a (sourceThresholdDirection_nonneg q r) + (sourceThresholdDirection_monotone hq r)) _).trans hm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/GridGap.lean b/lean/OAI/Probability/Perceptron/Variational/GridGap.lean new file mode 100644 index 0000000000000000000000000000000000000000..f089c7b26c83a9f771cd84e5b255b8243d48dff0 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/GridGap.lean @@ -0,0 +1,108 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CoupledDual +import OAI.Probability.Perceptron.Variational.UniformGrid + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma varianceLevels_gridVariance {k : ℕ} (l : List (Fin (k+2)×ℝ)) (i : Fin (k+1)) : + varianceLevels (fun j => gridVariance l j.castSucc) i = + (l.map fun c => if c.1 ≤ i.castSucc then c.2 else 0).sum/2 := by + unfold varianceLevels + congr 1 + have H := gridVariance_weighted_sum l (fun j => if j ≤ i.castSucc then 1 else 0) + simp only [ite_mul,one_mul,zero_mul] at H + rw [Fin.sum_univ_castSucc] at H + simpa only [Fin.castSucc_le_castSucc_iff,ite_eq_right (not_le.mpr (Fin.castSucc_lt_last i)),add_zero] using H + +lemma grid_prefix_step_gap {k N : ℕ} (A B : Fin N → Fin (k+2)) (v : Fin N → ℝ) + (hv : ∀ r, 0 ≤ v r) (hAB : ∀ r, A r ≤ B r) + (hBA : ∀ r, (B r).val ≤ (A r).val+1) (i : Fin (k+1)) : + let hA := varianceLevels (fun j => gridVariance (List.ofFn fun r => (A r,v r)) j.castSucc) + let hB := varianceLevels (fun j => gridVariance (List.ofFn fun r => (B r,v r)) j.castSucc) + 0 ≤ hA i-hB i ∧ hA i-hB i ≤ + gridVariance (List.ofFn fun r => (A r,v r)) i.castSucc/2 := by + dsimp only + rw [varianceLevels_gridVariance,varianceLevels_gridVariance] + simp only [gridVariance,List.map_ofFn,List.sum_ofFn] + rw [← sub_div,← Finset.sum_sub_distrib] + have H (r : Fin N) : + 0 ≤ (if A r ≤ i.castSucc then v r else 0)-(if B r ≤ i.castSucc then v r else 0) ∧ + (if A r ≤ i.castSucc then v r else 0)-(if B r ≤ i.castSucc then v r else 0) ≤ + if A r=i.castSucc then v r else 0 := by + by_cases ha : A r ≤ i.castSucc + · by_cases hb : B r ≤ i.castSucc + · simp only [ite_eq_left ha,ite_eq_left hb,sub_self] + constructor + · rfl + · split_ifs <;> first | exact hv r | rfl + · have he : A r=i.castSucc := by + apply Fin.ext + have h₁ := hBA r + have h₂ : (A r).val ≤ i.val := ha + have h₃ : i.val < (B r).val := lt_of_not_ge hb + omega + simp [hb,he,hv r] + · have hb : ¬B r ≤ i.castSucc := fun hb => ha ((hAB r).trans hb) + have he : A r ≠ i.castSucc := fun he => ha he.le + simp [ha,hb,he] + exact ⟨div_nonneg (Finset.sum_nonneg (fun r _ => (H r).1)) (by norm_num), + div_le_div_of_nonneg_right (Finset.sum_le_sum (fun r _ => (H r).2)) (by norm_num)⟩ + +lemma grid_step_weighted_gap {k N : ℕ} (A B : Fin N → Fin (k+2)) (v : Fin N → ℝ) + (hv : ∀ r, 0 ≤ v r) (hAB : ∀ r, A r ≤ B r) + (hBA : ∀ r, (B r).val ≤ (A r).val+1) : + (∑ i, uniformWeights k i * + |varianceLevels (fun j => gridVariance (List.ofFn fun r => (A r,v r)) j.castSucc) i- + varianceLevels (fun j => gridVariance (List.ofFn fun r => (B r,v r)) j.castSucc) i|) ≤ + (∑ r, v r)/(2*(k+1:ℕ)) := by + have hV : ∀ c ∈ List.ofFn (fun r => (A r,v r)), 0 ≤ c.2 := by + intro c hc; obtain ⟨r,rfl⟩ := List.mem_ofFn.mp hc; exact hv r + calc + _ ≤ ∑ i : Fin (k+1), uniformWeights k i * + (gridVariance (List.ofFn fun r => (A r,v r)) i.castSucc/2) := by + apply Finset.sum_le_sum + intro i _ + have H := grid_prefix_step_gap A B v hv hAB hBA i + rw [abs_of_nonneg H.1] + exact mul_le_mul_of_nonneg_left H.2 (uniformWeights_pos k i).le + _ = (∑ i : Fin (k+1), gridVariance (List.ofFn fun r => (A r,v r)) i.castSucc)/(2*(k+1:ℕ)) := by + simp only [uniformWeights] + rw [Finset.sum_div] + apply Finset.sum_congr rfl + intro i _ + ring + _ ≤ (∑ i, gridVariance (List.ofFn fun r => (A r,v r)) i)/(2*(k+1:ℕ)) := by + apply div_le_div_of_nonneg_right _ (by positivity) + rw [Fin.sum_univ_castSucc (gridVariance (List.ofFn fun r => (A r,v r)))] + exact le_add_of_nonneg_right (gridVariance_nonneg _ hV _) + _ = _ := by rw [gridVariance_sum,List.map_ofFn,List.sum_ofFn]; rfl + +lemma sphericalGridDual_step_gap {k N : ℕ} (A B : Fin N → Fin (k+2)) (v : Fin N → ℝ) + (hv : ∀ r, 0 ≤ v r) (hAB : ∀ r, A r ≤ B r) + (hBA : ∀ r, (B r).val ≤ (A r).val+1) : + |sphericalGridDual k (gridVariance (List.ofFn fun r => (A r,v r)))- + sphericalGridDual k (gridVariance (List.ofFn fun r => (B r,v r)))| ≤ + (∑ r, v r)/(2*(k+1:ℕ)) := by + have hVA : ∀ i, 0 ≤ gridVariance (List.ofFn fun r => (A r,v r)) i := by + apply gridVariance_nonneg + intro c hc; obtain ⟨r,rfl⟩ := List.mem_ofFn.mp hc; exact hv r + have hVB : ∀ i, 0 ≤ gridVariance (List.ofFn fun r => (B r,v r)) i := by + apply gridVariance_nonneg + intro c hc; obtain ⟨r,rfl⟩ := List.mem_ofFn.mp hc; exact hv r + exact (finiteSphericalDual_abs_sub_le (uniformWeights k) _ _ (uniformWeights_pos k) + (uniformWeights_sum k) + (varianceLevels_monotone _ (fun i => hVA i.castSucc)) + (varianceLevels_nonneg _ (fun i => hVA i.castSucc) 0) + (varianceLevels_monotone _ (fun i => hVB i.castSucc)) + (varianceLevels_nonneg _ (fun i => hVB i.castSucc) 0)).trans + (grid_step_weighted_gap A B v hv hAB hBA) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/HeatGrid.lean b/lean/OAI/Probability/Perceptron/Variational/HeatGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..f5aae07ea67cf9166a5d3d15cdfafa0848e4194b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/HeatGrid.lean @@ -0,0 +1,291 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianBackward +import OAI.Probability.Perceptron.Variational.StationaryExistence +import OAI.Probability.Perceptron.Variational.AmplitudeConvex + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +section + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def gaussianGrid (N : ℕ) (p v : Fin N → ℝ) (f : E → ℝ) : E → ℝ := + gaussianBackward (stdGaussian E) (List.ofFn fun i => (p i,Real.sqrt (v i))) f + +lemma gaussianGrid_lipschitz {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (N : ℕ) (p v : Fin N → ℝ) (hp : ∀ i, 0 ≤ p i) : + LipschitzWith L (gaussianGrid N p v f) := by + apply gaussianBackward_lipschitz _ hf + intro c hc + obtain ⟨i,rfl⟩ := List.mem_ofFn.mp hc + exact hp i + +lemma gaussianGrid_succ {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + (N : ℕ) (p v : Fin (N+1) → ℝ) (f : E → ℝ) : + gaussianGrid (N+1) p v f = gaussianEntropic (stdGaussian E) (p 0) (Real.sqrt (v 0)) + (gaussianGrid N (fun i => p i.succ) (fun i => v i.succ) f) := by + simp only [gaussianGrid,List.ofFn_succ,gaussianBackward] + +lemma gaussianGrid_zero {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (N : ℕ) (p : Fin N → ℝ) (hp : ∀ i, 0 ≤ p i) : + gaussianGrid N p (fun _ => 0) f=f := by + induction N with + | zero => simp [gaussianGrid,gaussianBackward] + | succ N ih => + rw [gaussianGrid_succ,Real.sqrt_zero,ih (fun i => p i.succ) (fun i => hp i.succ)] + funext x + exact gaussianEntropic_variance_zero hf _ _ + +lemma gaussianGrid_absorb {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (N : ℕ) (p v : Fin N → ℝ) (hp : ∀ i, 0 ≤ p i) (hv : ∀ i, 0 ≤ v i) + (j : Fin N) (a : ℝ) (ha : 0 ≤ a) (hpre : ∀ i, i < j → v i=0) : + gaussianEntropic (stdGaussian E) (p j) (Real.sqrt a) (gaussianGrid N p v f)= + gaussianGrid N p (fun i => v i+if i=j then a else 0) f := by + induction N with + | zero => exact j.elim0 + | succ N ih => + revert hpre + refine Fin.cases ?_ (fun j => ?_) j + · intro hpre + have ht := gaussianGrid_lipschitz hf N (fun i => p i.succ) (fun i => v i.succ) + (fun i => hp i.succ) + rw [gaussianGrid_succ,gaussianGrid_succ] + simp only [ite_true,Fin.succ_ne_zero,ite_false,add_zero] + funext x + have H := gaussianEntropic_semigroup ht (hp 0) (Real.sqrt a) (Real.sqrt (v 0)) x + rw [Real.sq_sqrt ha,Real.sq_sqrt (hv 0),add_comm a (v 0)] at H + exact H + · intro hpre + have hv0 : v 0=0 := hpre 0 (by simp [Fin.lt_def]) + have ht := gaussianGrid_lipschitz hf N (fun i => p i.succ) (fun i => v i.succ) + (fun i => hp i.succ) + have ht' := gaussianGrid_lipschitz hf N (fun i => p i.succ) + (fun i => v i.succ+if i=j then a else 0) (fun i => hp i.succ) + have H := ih (fun i => p i.succ) (fun i => v i.succ) (fun i => hp i.succ) + (fun i => hv i.succ) j (fun i hij => hpre i.succ (Fin.succ_lt_succ_iff.mpr hij)) + rw [gaussianGrid_succ,gaussianGrid_succ] + simp only [hv0,(Ne.symm (Fin.succ_ne_zero j)),ite_false,add_zero,Real.sqrt_zero,Fin.succ_inj] + have e₁ : gaussianEntropic (stdGaussian E) (p 0) 0 + (gaussianGrid N (fun i => p i.succ) (fun i => v i.succ) f)= + gaussianGrid N (fun i => p i.succ) (fun i => v i.succ) f := by + funext x; exact gaussianEntropic_variance_zero ht _ _ + have e₂ : gaussianEntropic (stdGaussian E) (p 0) 0 + (gaussianGrid N (fun i => p i.succ) (fun i => v i.succ+if i=j then a else 0) f)= + gaussianGrid N (fun i => p i.succ) (fun i => v i.succ+if i=j then a else 0) f := by + funext x; exact gaussianEntropic_variance_zero ht' _ _ + rw [e₁,e₂] + exact H + +end + +def gridVariance {N : ℕ} (l : List (Fin N×ℝ)) (i : Fin N) : ℝ := + (l.map fun c => if c.1=i then c.2 else 0).sum + +lemma gridVariance_nonneg {N : ℕ} (l : List (Fin N×ℝ)) + (hl : ∀ c ∈ l, 0 ≤ c.2) (i : Fin N) : 0 ≤ gridVariance l i := by + unfold gridVariance + apply List.sum_nonneg + intro x hx + obtain ⟨c,hc,rfl⟩ := List.mem_map.mp hx + split_ifs + · exact hl c hc + · exact le_rfl + +lemma gridVariance_below {N : ℕ} (l : List (Fin N×ℝ)) {j i : Fin N} + (hl : ∀ c ∈ l, j ≤ c.1) (hij : i < j) : gridVariance l i=0 := by + apply List.sum_eq_zero + intro x hx + obtain ⟨c,hc,rfl⟩ := List.mem_map.mp hx + rw [ite_eq_right (ne_of_gt (hij.trans_le (hl c hc)))] + +lemma gridVariance_cons {N : ℕ} (c : Fin N×ℝ) (l : List (Fin N×ℝ)) : + gridVariance (c::l)=fun i => gridVariance l i+if i=c.1 then c.2 else 0 := by + funext i + simp only [gridVariance,List.map_cons,List.sum_cons] + split_ifs <;> simp_all + ring + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussianBackward_compress {f : E → ℝ} {L : ℝ≥0} (hf : LipschitzWith L f) + (N : ℕ) (p : Fin N → ℝ) (hp : ∀ i, 0 ≤ p i) (l : List (Fin N×ℝ)) + (hl : l.Pairwise (fun a b => a.1 ≤ b.1)) (hv : ∀ c ∈ l, 0 ≤ c.2) : + gaussianBackward (stdGaussian E) (l.map fun c => (p c.1,Real.sqrt c.2)) f= + gaussianGrid N p (gridVariance l) f := by + induction l with + | nil => + simp only [List.map_nil,gaussianBackward] + exact (gaussianGrid_zero hf N p hp).symm + | cons c l ih => + have hpair := List.pairwise_cons.mp hl + have hv' := fun d hd => hv d (List.mem_cons_of_mem c hd) + simp only [List.map_cons,gaussianBackward,ih hpair.2 hv',gridVariance_cons] + exact gaussianGrid_absorb hf N p (gridVariance l) hp (gridVariance_nonneg l hv') + c.1 c.2 (hv c List.mem_cons_self) (fun i hi => gridVariance_below l hpair.1 hi) + +end + +lemma expectedCoordinateSphereLog_stationary_covariance {k : ℕ} (w h : Fin (k+1) → ℝ) + (q : Fin (k+1) → Time) (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i = 1) + (hq : Monotone q) (hq1 : (q (Fin.last k):ℝ) < 1) + (hstat : ∀ i, 2*h i = weightedStepA w (fun j => (q j:ℝ)) (q i)) + (σ : ℕ → ℝ) (v : ℝ≥0) (hv : (v:ℝ)=2*h 0) + (hσ : ∀ i : Fin k, (σ (k-1-i.val))^2=2*(h i.succ-h i.castSucc)) : + Tendsto (fun n : ℕ => expectedCoordinateSphereLog n k σ (stepCumulative w) v-h (Fin.last k)) atTop + (𝓝 ((entropy (weightedStepTrial w q (fun i => (hw i).le) hw1)).toReal- + ∑ i, w i*h i*(q i:ℝ))) := by + let Q : Fin (k+1) → ℝ := fun i => q i + let D : Fin (k+1) → ℝ := fun i => weightedStepTail w Q (Q i) + have hm : Monotone Q := fun i j hij => hq hij + have h0 : 0 ≤ Q 0 := (q 0).2.1 + have hmax (i : Fin (k+1)) : Q i ≤ Q (Fin.last k) := hm (Fin.le_last i) + have hD (i : Fin (k+1)) : 0 < D i := + weightedStepTail_pos w Q (fun i => (hw i).le) hw1 hq1 hmax (hmax i) + have hz := stepCumulative_strictMono w hw + have hz0 := stepCumulative_pos w hw + have hz1 := stepCumulative_lt_one w hw hw1 + have hroot : 2*h 0=Q 0/(D 0)^2 := + (hstat 0).trans (weightedStepA_root w Q hm h0) + have hinc (i : Fin k) : 2*(h i.succ-h i.castSucc)= + (Q i.succ-Q i.castSucc)/(D i.castSucc*D i.succ) := by + calc + _ = weightedStepA w Q (Q i.succ)-weightedStepA w Q (Q i.castSucc) := by + linarith [hstat i.succ,hstat i.castSucc] + _ = _ := weightedStepA_increment w Q (fun i => (hw i).le) hw1 hm h0 hq1 i (hz0 i) + have hh : Monotone h := by + apply Fin.monotone_iff_le_succ.mpr + intro i + have hp := div_nonneg (sub_nonneg.mpr (hm (Fin.castSucc_le_succ i))) + (mul_pos (hD i.castSucc) (hD i.succ)).le + rw [← hinc i] at hp + linarith + have hr0 : 0 ≤ 2*h 0 := by rw [hroot]; positivity + have hr : (v:ℝ)=Q 0/(D 0)^2 := hv.trans hroot + have hend : D (Fin.last k) = 1-Q (Fin.last k) := weightedStepTail_of_le w Q hw1 hmax + have hgap (i : Fin k) : D i.castSucc-D i.succ=stepCumulative w i*(Q i.succ-Q i.castSucc) := by + have he := weightedStepTail_affine w Q hm i (t := Q i.succ) ⟨hm (Fin.castSucc_le_succ i),le_rfl⟩ + change D i.succ=D i.castSucc-stepCumulative w i*(Q i.succ-Q i.castSucc) at he + linarith + have hσ' (i : Fin k) : (σ (k-1-i.val))^2= + (Q i.succ-Q i.castSucc)/(D i.castSucc*D i.succ) := (hσ i).trans (hinc i) + have ht := (expectedCoordinateSphereLog_stationary_data k σ + Q D (stepCumulative w) hz hz0 hz1 hD hend hgap hσ' v hr).sub_const (h (Fin.last k)) + have he := entropy_weightedStepTrial_toReal_finite_formula w q (fun i => (hw i).le) hw1 hq hq1 hz0 + simp only [tailIntegral_weightedStepTrial] at he + change (entropy (weightedStepTrial w q (fun i => (hw i).le) hw1)).toReal = + Real.log (D (Fin.last k))/2+stepLogRatios k D (stepCumulative w)+Q 0/(2*D 0) at he + have hs := stationary_field_shift_identity w Q h hw1 hm hD hroot hinc + have hv : Real.log (D (Fin.last k))/2+stepLogRatios k D (stepCumulative w)+Q 0/(2*D 0)+ + ((D (Fin.last k))⁻¹-1)/2-h (Fin.last k) = + (entropy (weightedStepTrial w q (fun i => (hw i).le) hw1)).toReal-∑ i, w i*h i*Q i := by + rw [he] + change 2*(h (Fin.last k)-∑ i, w i*h i*Q i)=(D (Fin.last k))⁻¹-1 at hs + linarith + rw [hv] at ht + exact ht + +def amplitudeCovarianceLevels (k : ℕ) (σ : ℕ → ℝ) (r : ℝ) (i : Fin (k+1)) : ℝ := + (r^2+stepTailSum (fun j : Fin k => (σ (k-1-j.val))^2) 0- + stepTailSum (fun j : Fin k => (σ (k-1-j.val))^2) i)/2 + +lemma amplitudeCovarianceLevels_root (k : ℕ) (σ : ℕ → ℝ) (r : ℝ) : + 2*amplitudeCovarianceLevels k σ r 0=r^2 := by unfold amplitudeCovarianceLevels; ring + +lemma amplitudeCovarianceLevels_increment (k : ℕ) (σ : ℕ → ℝ) (r : ℝ) (i : Fin k) : + 2*(amplitudeCovarianceLevels k σ r i.succ-amplitudeCovarianceLevels k σ r i.castSucc)= + (σ (k-1-i.val))^2 := by + have he := stepTailSum_difference (fun j : Fin k => (σ (k-1-j.val))^2) i + unfold amplitudeCovarianceLevels + linarith + +lemma amplitudeCovarianceLevels_monotone (k : ℕ) (σ : ℕ → ℝ) (r : ℝ) : + Monotone (amplitudeCovarianceLevels k σ r) := by + apply Fin.monotone_iff_le_succ.mpr + intro i + have h := amplitudeCovarianceLevels_increment k σ r i + nlinarith [sq_nonneg (σ (k-1-i.val))] + +lemma amplitudeCovarianceLevels_nonneg (k : ℕ) (σ : ℕ → ℝ) (r : ℝ) : + 0 ≤ amplitudeCovarianceLevels k σ r 0 := by + have h := amplitudeCovarianceLevels_root k σ r + nlinarith [sq_nonneg r] + +def amplitudeSphereDual {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) (σ : ℕ → ℝ) (r : ℝ) : ℝ := + sInf (finiteSphericalDualValues w (amplitudeCovarianceLevels k σ r) hw hw1)+ + amplitudeCovarianceLevels k σ r (Fin.last k) + +lemma amplitudeSphereValue_tendsto {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) (σ : ℕ → ℝ) (r : ℝ) : + Tendsto (fun n : ℕ => amplitudeSphereValue n k σ (stepCumulative w) r) atTop + (𝓝 (amplitudeSphereDual w (fun i => (hw i).le) hw1 σ r)) := by + let h := amplitudeCovarianceLevels k σ r + obtain ⟨q,hq,hq1,hs⟩ := exists_finite_stationary_quantile w h hw hw1 + (amplitudeCovarianceLevels_monotone k σ r) (amplitudeCovarianceLevels_nonneg k σ r) + have hleast : IsLeast (finiteSphericalDualValues w h (fun i => (hw i).le) hw1) + (finiteSphericalDualObjective w h (fun i => (hw i).le) hw1 q) := by + refine ⟨⟨q,⟨hq,hq1⟩,rfl⟩,?_⟩ + rintro a ⟨p,⟨hp,hp1⟩,rfl⟩ + exact stationary_finite_entropy_minimizes w h q p (fun i => (hw i).le) hw1 hq hp hq1 hp1 hs + have ht := (expectedCoordinateSphereLog_stationary_covariance w h q hw hw1 hq hq1 hs σ + ⟨r^2,sq_nonneg r⟩ (amplitudeCovarianceLevels_root k σ r).symm + (fun i => (amplitudeCovarianceLevels_increment k σ r i).symm)).add_const (h (Fin.last k)) + simp only [sub_add_cancel,← amplitudeSphereValue_eq] at ht + change Tendsto _ _ (𝓝 (sInf (finiteSphericalDualValues w h (fun i => (hw i).le) hw1)+h (Fin.last k))) + rw [hleast.csInf_eq] + exact ht + +def finiteAmplitudeIncrement (k : ℕ) (a : Fin (k+1) → ℝ) (j : ℕ) : ℝ := + if hj : j < k then a (⟨j,hj⟩ : Fin k).castSucc else 0 + +def finiteAmplitudeSphereValue (n k : ℕ) (w : Fin (k+1) → ℝ) (a : Fin (k+1) → ℝ) : ℝ := + amplitudeSphereValue n k (finiteAmplitudeIncrement k a) (stepCumulative w) (a (Fin.last k)) + +def finiteAmplitudeSphereDual {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) (a : Fin (k+1) → ℝ) : ℝ := + amplitudeSphereDual w hw hw1 (finiteAmplitudeIncrement k a) (a (Fin.last k)) + +lemma finiteAmplitudeSphereValue_convex {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) (n : ℕ) : + ConvexOn ℝ Set.univ (finiteAmplitudeSphereValue n k w) := by + refine ⟨convex_univ,?_⟩ + intro a _ b _ c d hc hd hcd + have he : finiteAmplitudeIncrement k (c • a+d • b)= + c • finiteAmplitudeIncrement k a+d • finiteAmplitudeIncrement k b := by + funext j + unfold finiteAmplitudeIncrement + by_cases hj : j < k + · simp [hj,Pi.add_apply,Pi.smul_apply,smul_eq_mul] + · simp [hj,Pi.add_apply,Pi.smul_apply,smul_eq_mul] + simpa only [finiteAmplitudeSphereValue,he,Pi.add_apply,Pi.smul_apply,smul_eq_mul] using + amplitudeSphereValue_convex n k (stepCumulative w) (stepCumulative_strictMono w hw) + (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1) + (finiteAmplitudeIncrement k a) (finiteAmplitudeIncrement k b) (a (Fin.last k)) + (b (Fin.last k)) hc hd hcd + +lemma finiteAmplitudeSphereValue_nonneg {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) (n : ℕ) (a : Fin (k+1) → ℝ) : + 0 ≤ finiteAmplitudeSphereValue n k w a := + integral_nonneg_of_ae (amplitudeSphereLog_nonneg n k _ _ (stepCumulative_strictMono w hw) + (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1) _) + +lemma finiteAmplitudeSphereValue_tendsto {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) (a : Fin (k+1) → ℝ) : + Tendsto (fun n : ℕ => finiteAmplitudeSphereValue n k w a) atTop + (𝓝 (finiteAmplitudeSphereDual w (fun i => (hw i).le) hw1 a)) := + amplitudeSphereValue_tendsto w hw hw1 _ _ + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/HeatLogBCF.lean b/lean/OAI/Probability/Perceptron/Variational/HeatLogBCF.lean new file mode 100644 index 0000000000000000000000000000000000000000..0652ccc61e6bf3437ad5574bfd10814b1a9c2a5e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/HeatLogBCF.lean @@ -0,0 +1,449 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianAverage + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma heatLog_continuous (s d : ℝ≥0) (f : ℝ →ᵇ ℝ) : Continuous (heatLog s d f) := by + change Continuous (fun x => heatLog s d f x) + by_cases hd : d = 0 + · simpa [heatLog, hd] using gaussianAverage_continuous s f + · have hh := (gaussianAverage_continuous s (expBCF d f)).log (fun x => (gaussianAverage_exp_pos s d f x).ne') + simpa only [heatLog, hd, ↓reduceIte] using hh.const_mul (d : ℝ)⁻¹ + +def heatLogBCF (s d : ℝ≥0) (f : ℝ →ᵇ ℝ) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound ⟨heatLog s d f, heatLog_continuous s d f⟩ + (2*‖f‖) (by + intro x y; change |heatLog s d f x - heatLog s d f y| ≤ 2 * ‖f‖ + exact (abs_sub _ _).trans (by linarith [heatLog_abs_le s d f x, heatLog_abs_le s d f y])) + +@[simp] lemma heatLogBCF_coe (s d : ℝ≥0) (f : ℝ →ᵇ ℝ) : + (heatLogBCF s d f : ℝ → ℝ) = heatLog s d f := rfl + +lemma exp_heatLog (s d : ℝ≥0) (hd : d ≠ 0) (f : ℝ →ᵇ ℝ) (x : ℝ) : + Real.exp (d * heatLog s d f x) = gaussianAverage s (expBCF d f) x := by + simp only [heatLog, hd, ↓reduceIte] + rw [← mul_assoc, mul_inv_cancel₀ (NNReal.coe_ne_zero.mpr hd), one_mul, + Real.exp_log (gaussianAverage_exp_pos s d f x)] + +lemma heatLog_zero (d : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : heatLog 0 d f x = f x := by + by_cases hd : d = 0 + · simp [heatLog, hd] + · simp [heatLog, hd] + +lemma heatLog_semigroup (s t d : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : + heatLog s d (heatLogBCF t d f) x = heatLog (s+t) d f x := by + by_cases hd : d = 0 + · subst d + have he : heatLogBCF t 0 f = gaussianAverageBCF t f := by ext z; simp [heatLog] + simp only [heatLog, ↓reduceIte, he] + exact gaussianAverage_semigroup s t f x + · have he : expBCF d (heatLogBCF t d f) = gaussianAverageBCF t (expBCF d f) := by + ext z + exact exp_heatLog t d hd f z + simp only [heatLog, hd, ↓reduceIte, he, gaussianAverage_semigroup] + +structure Jet3 where + f : ℝ →ᵇ ℝ + d1 : ℝ →ᵇ ℝ + d2 : ℝ →ᵇ ℝ + d3 : ℝ →ᵇ ℝ + has1 : ∀ x, HasDerivAt (f : ℝ → ℝ) (d1 x) x + has2 : ∀ x, HasDerivAt (d1 : ℝ → ℝ) (d2 x) x + has3 : ∀ x, HasDerivAt (d2 : ℝ → ℝ) (d3 x) x + +lemma Jet3.deriv_eq (g : Jet3) : deriv (g.f : ℝ → ℝ) = g.d1 := funext fun x => (g.has1 x).deriv +lemma Jet3.deriv2_eq (g : Jet3) : iteratedDeriv 2 (g.f : ℝ → ℝ) = g.d2 := by + rw [iteratedDeriv_succ, iteratedDeriv_one, g.deriv_eq] + exact funext fun x => (g.has2 x).deriv +lemma Jet3.deriv3_eq (g : Jet3) : iteratedDeriv 3 (g.f : ℝ → ℝ) = g.d3 := by + rw [iteratedDeriv_succ, g.deriv2_eq] + exact funext fun x => (g.has3 x).deriv + +lemma Jet3.contDiff (g : Jet3) : ContDiff ℝ 3 (g.f : ℝ → ℝ) := by + rw [show (3 : WithTop ℕ∞) = 2+1 by norm_num, contDiff_succ_iff_deriv] + refine ⟨fun x => (g.has1 x).differentiableAt, by norm_num, ?_⟩ + rw [g.deriv_eq, show (2 : WithTop ℕ∞) = 1+1 by norm_num, contDiff_succ_iff_deriv] + refine ⟨fun x => (g.has2 x).differentiableAt, by norm_num, ?_⟩ + rw [show deriv (g.d1 : ℝ → ℝ) = g.d2 from funext fun x => (g.has2 x).deriv, + show (1 : WithTop ℕ∞) = 0+1 by norm_num, contDiff_succ_iff_deriv] + refine ⟨fun x => (g.has3 x).differentiableAt, by norm_num, ?_⟩ + rw [show deriv (g.d2 : ℝ → ℝ) = g.d3 from funext fun x => (g.has3 x).deriv] + exact contDiff_zero.mpr g.d3.continuous + +def Jet3.gaussianAverage (s : ℝ≥0) (g : Jet3) : Jet3 where + f := gaussianAverageBCF s g.f + d1 := gaussianAverageBCF s g.d1 + d2 := gaussianAverageBCF s g.d2 + d3 := gaussianAverageBCF s g.d3 + has1 := gaussianAverage_hasDerivAt s g.f g.d1 g.has1 + has2 := gaussianAverage_hasDerivAt s g.d1 g.d2 g.has2 + has3 := gaussianAverage_hasDerivAt s g.d2 g.d3 g.has3 + +lemma Jet3.gaussianAverage_norms (s : ℝ≥0) (g : Jet3) : + ‖(g.gaussianAverage s).f‖ ≤ ‖g.f‖ ∧ ‖(g.gaussianAverage s).d1‖ ≤ ‖g.d1‖ ∧ + ‖(g.gaussianAverage s).d2‖ ≤ ‖g.d2‖ ∧ ‖(g.gaussianAverage s).d3‖ ≤ ‖g.d3‖ := by + have hh (f : ℝ →ᵇ ℝ) : ‖gaussianAverageBCF s f‖ ≤ ‖f‖ := by + rw [BoundedContinuousFunction.norm_le (norm_nonneg _)] + intro x; exact gaussianAverage_abs_le s f x + exact ⟨hh _,hh _,hh _,hh _⟩ + +def Jet3.exp (d : ℝ) (g : Jet3) : Jet3 where + f := expBCF d g.f + d1 := d • (expBCF d g.f * g.d1) + d2 := expBCF d g.f * (d^2 • (g.d1^2) + d • g.d2) + d3 := expBCF d g.f * (d^3 • (g.d1^3) + (3*d^2) • (g.d1*g.d2) + d • g.d3) + has1 x := by + convert! ((g.has1 x).const_mul d).exp using 1 + dsimp [expBCF] + ring + has2 x := by + have he := ((g.has1 x).const_mul d).exp + have h := (he.mul (g.has2 x)).const_mul d + convert! h using 1 + dsimp [expBCF]; ring + has3 x := by + have he := ((g.has1 x).const_mul d).exp + have h := he.mul (((g.has2 x).pow 2).const_mul (d^2) |>.add ((g.has3 x).const_mul d)) + convert! h using 1 + dsimp [expBCF]; ring + +lemma inv_bcf_bound {g : ℝ →ᵇ ℝ} {c : ℝ} (hc : 0 < c) (hg : ∀ x, c ≤ g x) (x : ℝ) : + |(g x)⁻¹| ≤ c⁻¹ := by + rw [abs_of_pos (inv_pos.mpr (hc.trans_le (hg x)))] + exact inv_anti₀ hc (hg x) + +def invBCF (g : ℝ →ᵇ ℝ) (c : ℝ) (hc : 0 < c) (hg : ∀ x, c ≤ g x) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound + ⟨fun x => (g x)⁻¹, g.continuous.inv₀ (fun x => (hc.trans_le (hg x)).ne')⟩ + (2*c⁻¹) (by + intro x y; change |(g x)⁻¹ - (g y)⁻¹| ≤ 2*c⁻¹ + exact (abs_sub _ _).trans (by linarith [inv_bcf_bound hc hg x, inv_bcf_bound hc hg y])) + +@[simp] lemma invBCF_apply (g : ℝ →ᵇ ℝ) (c : ℝ) (hc : 0 < c) (hg : ∀ x, c ≤ g x) (x : ℝ) : + invBCF g c hc hg x = (g x)⁻¹ := rfl + +lemma invBCF_norm_le (g : ℝ →ᵇ ℝ) (c : ℝ) (hc : 0 < c) (hg : ∀ x, c ≤ g x) : + ‖invBCF g c hc hg‖ ≤ c⁻¹ := by + rw [BoundedContinuousFunction.norm_le (inv_nonneg.mpr hc.le)] + intro x; exact inv_bcf_bound hc hg x + +lemma invBCF_hasDerivAt (g g' : ℝ →ᵇ ℝ) (c : ℝ) (hc : 0 < c) (hg : ∀ x, c ≤ g x) + (hder : ∀ x, HasDerivAt (g : ℝ → ℝ) (g' x) x) (x : ℝ) : + HasDerivAt (invBCF g c hc hg : ℝ → ℝ) (- g' x * (invBCF g c hc hg x)^2) x := by + convert! (hder x).inv (hc.trans_le (hg x)).ne' using 1 + simp only [invBCF_apply, div_eq_mul_inv, inv_pow] + +def Jet3.heatLogPos (s d : ℝ≥0) (hd : d ≠ 0) (g : Jet3) : Jet3 := + let A := (g.exp d).gaussianAverage s + let c := Real.exp (-d * ‖g.f‖) + let hc : 0 < c := Real.exp_pos _ + let hA : ∀ x, c ≤ A.f x := fun x => (gaussianAverage_exp_bounds s d d.coe_nonneg g.f x).1 + let J := invBCF A.f c hc hA + { f := heatLogBCF s d g.f + d1 := (d : ℝ)⁻¹ • (A.d1 * J) + d2 := (d : ℝ)⁻¹ • (A.d2 * J - A.d1^2 * J^2) + d3 := (d : ℝ)⁻¹ • (A.d3 * J - (3 : ℝ) • (A.d1*A.d2*J^2) + (2 : ℝ) • (A.d1^3*J^3)) + has1 x := by + have hh := ((A.has1 x).log (hc.trans_le (hA x)).ne').const_mul (d : ℝ)⁻¹ + convert! hh using 1 + · ext y + simp only [heatLogBCF_coe, heatLog, hd, ↓reduceIte] + rfl + has2 x := by + have hi := invBCF_hasDerivAt A.f A.d1 c hc hA A.has1 x + have hh := ((A.has2 x).mul hi).const_mul (d : ℝ)⁻¹ + convert! hh using 1 + dsimp only [BoundedContinuousFunction.coe_smul, BoundedContinuousFunction.coe_mul, + BoundedContinuousFunction.coe_sub, BoundedContinuousFunction.coe_pow, + Pi.smul_apply, smul_eq_mul, Pi.mul_apply, Pi.sub_apply, Pi.pow_apply] + ring + has3 x := by + have hi := invBCF_hasDerivAt A.f A.d1 c hc hA A.has1 x + have hh := (((A.has3 x).mul hi).sub (((A.has2 x).pow 2).mul (hi.pow 2))).const_mul (d : ℝ)⁻¹ + convert! hh using 1 + dsimp only [BoundedContinuousFunction.coe_smul, BoundedContinuousFunction.coe_mul, + BoundedContinuousFunction.coe_sub, BoundedContinuousFunction.coe_add, + BoundedContinuousFunction.coe_pow, Pi.smul_apply, smul_eq_mul, Pi.mul_apply, + Pi.sub_apply, Pi.add_apply, Pi.pow_apply] + ring } + +def Jet3.heatLog (s d : ℝ≥0) (g : Jet3) : Jet3 := + if hd : d = 0 then g.gaussianAverage s else g.heatLogPos s d hd + +lemma Jet3.heatLog_f (s d : ℝ≥0) (g : Jet3) : (g.heatLog s d).f = heatLogBCF s d g.f := by + unfold Jet3.heatLog + split_ifs with hd + · subst d; ext x; simp [Jet3.gaussianAverage, SphericalPerceptronFreeEnergy.heatLog] + · rfl + +lemma gaussianAverage_jet_error (s : ℝ≥0) (g : Jet3) (x : ℝ) : + |gaussianAverage s g.f x - g.f x - (s : ℝ)/2 * g.d2 x| ≤ + ‖g.d3‖/6 * (Real.sqrt s)^3 * ∫ z : ℝ, |z|^3 ∂gaussianReal 0 1 := by + have hh := gaussian_taylor_mean_bound (P := gaussianReal 0 s) g.f g.contDiff + ‖g.d1‖ ‖g.d2‖ ‖g.d3‖ + (fun y => by rw [g.deriv_eq]; exact g.d1.norm_coe_le_norm y) + (fun y => by rw [g.deriv2_eq]; exact g.d2.norm_coe_le_norm y) + (fun y => by rw [g.deriv3_eq]; exact g.d3.norm_coe_le_norm y) + (X := fun _ : ℝ => x) aemeasurable_const (Z := id) HasLaw.id (indepFun_const_left _ _) + simpa only [integral_const, probReal_univ, smul_eq_mul, one_mul, g.deriv2_eq, gaussianAverage, id_eq] using hh + +lemma log_linear_error_le {a b c : ℝ} (hc : 0 < c) (ha : c ≤ a) (hb : c ≤ b) : + |Real.log b - Real.log a - (b-a)/a| ≤ (b-a)^2 / c^2 := by + have ha0 := hc.trans_le ha + have hb0 := hc.trans_le hb + have hu := Real.log_le_sub_one_of_pos (div_pos hb0 ha0) + have hl := Real.log_le_sub_one_of_pos (div_pos ha0 hb0) + rw [Real.log_div hb0.ne' ha0.ne'] at hu + rw [Real.log_div ha0.ne' hb0.ne'] at hl + have heq : b/a-1 = (b-a)/a := by field_simp + rw [heq] at hu + rw [abs_of_nonpos (sub_nonpos.mpr hu)] + have hlin : -(Real.log b - Real.log a - (b-a)/a) ≤ (b-a)^2/(a*b) := by + have he : (b-a)/a + (a/b-1) = (b-a)^2/(a*b) := by field_simp; ring + linarith + exact hlin.trans (div_le_div_of_nonneg_left (sq_nonneg _) (sq_pos_of_pos hc) + (by nlinarith [mul_le_mul ha hb hc.le ha0.le])) + +lemma gaussianAverage_ge_const (s : ℝ≥0) (f : ℝ →ᵇ ℝ) {c : ℝ} + (hc : ∀ x, c ≤ f x) (x : ℝ) : c ≤ gaussianAverage s f x := by + have hh := integral_mono (integrable_const c) (gaussianAverage_integrable s f x) (fun z => hc (x+z)) + simpa only [gaussianAverage, integral_const, probReal_univ, smul_eq_mul, one_mul] using hh + +lemma log_gaussian_generator_error (g : Jet3) (c : ℝ) (hc : 0 < c) + (hg : ∀ x, c ≤ g.f x) (C₂ C₃ : ℝ≥0) (h₂ : ‖g.d2‖ ≤ C₂) (h₃ : ‖g.d3‖ ≤ C₃) + (s : ℝ≥0) (hs : s ≤ 1) (x : ℝ) : + |Real.log (gaussianAverage s g.f x) - Real.log (g.f x) - + (s : ℝ)/2 * g.d2 x / g.f x| ≤ + (((C₂ : ℝ)/2 + (C₃ : ℝ)/6*(∫ z : ℝ, |z|^3 ∂gaussianReal 0 1))^2/c^2 + + ((C₃ : ℝ)/6*(∫ z : ℝ, |z|^3 ∂gaussianReal 0 1))/c) * (s : ℝ) * Real.sqrt s := by + let A := gaussianAverage s g.f x + let a := g.f x + let K := (C₃ : ℝ)/6 * ∫ z : ℝ, |z|^3 ∂gaussianReal 0 1 + let D := (C₂ : ℝ)/2 + K + have ha := hg x + have hA := gaussianAverage_ge_const s g.f hg x + have hM : 0 ≤ ∫ z : ℝ, |z|^3 ∂gaussianReal 0 1 := integral_nonneg (fun z => by positivity) + have hK : 0 ≤ K := by positivity + have hD : 0 ≤ D := by positivity + have hs0 : 0 ≤ (s : ℝ) := s.coe_nonneg + have hs1 : (s : ℝ) ≤ 1 := hs + have hr0 := Real.sqrt_nonneg (s : ℝ) + have hr1 : Real.sqrt (s : ℝ) ≤ 1 := (Real.sqrt_le_one).mpr hs1 + have hrsq := Real.sq_sqrt hs0 + have hsr : (s : ℝ) ≤ Real.sqrt (s : ℝ) := by nlinarith + have hrcube : (Real.sqrt (s : ℝ))^3 = (s : ℝ) * Real.sqrt (s : ℝ) := by nlinarith + have herr : |A-a-(s : ℝ)/2*g.d2 x| ≤ K * (s : ℝ) * Real.sqrt s := by + calc + _ ≤ ‖g.d3‖/6 * (Real.sqrt s)^3 * ∫ z : ℝ, |z|^3 ∂gaussianReal 0 1 := gaussianAverage_jet_error s g x + _ ≤ (C₃ : ℝ)/6 * (Real.sqrt s)^3 * ∫ z : ℝ, |z|^3 ∂gaussianReal 0 1 := by gcongr + _ = _ := by rw [hrcube]; unfold K; ring + have hdx : |g.d2 x| ≤ C₂ := (g.d2.norm_coe_le_norm x).trans h₂ + have hdelta : |A-a| ≤ D * (s : ℝ) := by + have habs := abs_add_le (A-a-(s : ℝ)/2*g.d2 x) ((s : ℝ)/2*g.d2 x) + rw [sub_add_cancel] at habs + have hterm : |(s : ℝ)/2*g.d2 x| ≤ (s : ℝ)/2*C₂ := by + rw [abs_mul, abs_of_nonneg (by positivity : (0 : ℝ) ≤ s/2)] + exact mul_le_mul_of_nonneg_left hdx (by positivity) + have hkr := mul_le_mul_of_nonneg_left hr1 (mul_nonneg hK hs0) + dsimp [D]; nlinarith + have hquad : (A-a)^2/c^2 ≤ (D^2/c^2) * (s : ℝ) * Real.sqrt s := by + have hdsq : (A-a)^2 ≤ (D*(s : ℝ))^2 := by + have hh := (sq_le_sq₀ (abs_nonneg (A-a)) (mul_nonneg hD hs0)).mpr hdelta + simpa only [sq_abs] using hh + calc + _ ≤ (D*(s : ℝ))^2/c^2 := div_le_div_of_nonneg_right hdsq (sq_nonneg c) + _ = D^2/c^2 * (s : ℝ)^2 := by ring + _ ≤ _ := by + have hh := mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left hsr hs0) + (show 0 ≤ D^2/c^2 by positivity) + nlinarith only [hh] + have hrem : |A-a-(s : ℝ)/2*g.d2 x|/a ≤ (K/c) * (s : ℝ) * Real.sqrt s := by + calc + _ ≤ (K*(s : ℝ)*Real.sqrt s)/c := div_le_div₀ (by positivity) herr hc ha + _ = _ := by ring + have hlog := log_linear_error_le hc ha hA + change |Real.log A - Real.log a - (s : ℝ)/2*g.d2 x/a| ≤ _ + calc + _ = |(Real.log A-Real.log a-(A-a)/a) + (A-a-(s : ℝ)/2*g.d2 x)/a| := by congr 1; ring + _ ≤ |Real.log A-Real.log a-(A-a)/a| + |(A-a-(s : ℝ)/2*g.d2 x)/a| := abs_add_le _ _ + _ = |Real.log A-Real.log a-(A-a)/a| + |A-a-(s : ℝ)/2*g.d2 x|/a := by + rw [abs_div, abs_of_pos (hc.trans_le ha)] + _ ≤ (D^2/c^2) * (s : ℝ) * Real.sqrt s + (K/c)*(s : ℝ)*Real.sqrt s := + add_le_add (hlog.trans hquad) hrem + _ = _ := by dsimp [D,K]; ring + +lemma expBCF_norm_le (d : ℝ) (f : ℝ →ᵇ ℝ) : + ‖expBCF d f‖ ≤ Real.exp (|d| * ‖f‖) := by + rw [BoundedContinuousFunction.norm_le (Real.exp_pos _).le] + exact exp_bcf_bound d f + +lemma Jet3.exp_norms (g : Jet3) (d C₀ C₁ C₂ C₃ : ℝ≥0) + (h₀ : ‖g.f‖ ≤ C₀) (h₁ : ‖g.d1‖ ≤ C₁) (h₂ : ‖g.d2‖ ≤ C₂) (h₃ : ‖g.d3‖ ≤ C₃) : + let E := Real.exp ((d : ℝ)*C₀) + ‖(g.exp d).f‖ ≤ E ∧ ‖(g.exp d).d1‖ ≤ (d : ℝ)*E*C₁ ∧ + ‖(g.exp d).d2‖ ≤ E*((d : ℝ)^2*C₁^2 + d*C₂) ∧ + ‖(g.exp d).d3‖ ≤ E*((d : ℝ)^3*C₁^3 + 3*(d : ℝ)^2*C₁*C₂ + d*C₃) := by + dsimp only + have hf : ‖expBCF d g.f‖ ≤ Real.exp ((d : ℝ)*C₀) := by + refine (expBCF_norm_le d g.f).trans ?_ + rw [abs_of_nonneg d.coe_nonneg] + exact Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left h₀ d.coe_nonneg) + refine ⟨hf, ?_, ?_, ?_⟩ + · change ‖(d : ℝ) • (expBCF d g.f * g.d1)‖ ≤ _ + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg d.coe_nonneg] + calc + _ ≤ (d : ℝ) * (‖expBCF d g.f‖ * ‖g.d1‖) := by gcongr; exact norm_mul_le _ _ + _ ≤ (d : ℝ) * (Real.exp ((d : ℝ)*C₀) * C₁) := by gcongr + _ = _ := by ring + · change ‖expBCF d g.f * ((d : ℝ)^2 • (g.d1^2) + (d : ℝ) • g.d2)‖ ≤ _ + calc + _ ≤ ‖expBCF d g.f‖ * (‖(d : ℝ)^2 • (g.d1^2)‖ + ‖(d : ℝ) • g.d2‖) := + (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left (norm_add_le _ _) (norm_nonneg _)) + _ = ‖expBCF d g.f‖ * ((d : ℝ)^2 * ‖g.d1^2‖ + (d : ℝ) * ‖g.d2‖) := by + simp only [norm_smul, Real.norm_eq_abs, abs_of_nonneg d.coe_nonneg, abs_pow] + _ ≤ Real.exp ((d : ℝ)*C₀) * ((d : ℝ)^2 * C₁^2 + (d : ℝ) * C₂) := by + gcongr + exact (norm_pow_le _ _).trans (by gcongr) + · change ‖expBCF d g.f * ((d : ℝ)^3 • (g.d1^3) + (3*(d : ℝ)^2) • (g.d1*g.d2) + (d : ℝ) • g.d3)‖ ≤ _ + calc + _ ≤ ‖expBCF d g.f‖ * ((‖(d : ℝ)^3 • (g.d1^3)‖ + ‖(3*(d : ℝ)^2) • (g.d1*g.d2)‖) + ‖(d : ℝ) • g.d3‖) := by + refine (norm_mul_le _ _).trans (mul_le_mul_of_nonneg_left ?_ (norm_nonneg _)) + exact (norm_add_le _ _).trans (add_le_add (norm_add_le _ _) le_rfl) + _ = ‖expBCF d g.f‖ * ((d : ℝ)^3 * ‖g.d1^3‖ + 3*(d : ℝ)^2*‖g.d1*g.d2‖ + (d : ℝ)*‖g.d3‖) := by + simp only [norm_smul, Real.norm_eq_abs] + rw [abs_of_nonneg (by positivity : (0 : ℝ) ≤ (d : ℝ)^3), + abs_of_nonneg (by positivity : (0 : ℝ) ≤ 3*(d : ℝ)^2), abs_of_nonneg d.coe_nonneg] + _ ≤ Real.exp ((d : ℝ)*C₀) * ((d : ℝ)^3*C₁^3 + 3*(d : ℝ)^2*(C₁*C₂) + (d : ℝ)*C₃) := by + gcongr + · exact (norm_pow_le _ _).trans (by gcongr) + · exact (norm_mul_le _ _).trans (by gcongr) + _ = _ := by ring + +lemma Jet3.heatLog_uniform_bounds (d : ℝ≥0) (g : Jet3) : + ∃ C₀ C₁ C₂ C₃ : ℝ≥0, ∀ s : ℝ≥0, + ‖(g.heatLog s d).f‖ ≤ C₀ ∧ ‖(g.heatLog s d).d1‖ ≤ C₁ ∧ + ‖(g.heatLog s d).d2‖ ≤ C₂ ∧ ‖(g.heatLog s d).d3‖ ≤ C₃ := by + by_cases hd : d = 0 + · subst d + refine ⟨‖g.f‖₊, ‖g.d1‖₊, ‖g.d2‖₊, ‖g.d3‖₊, ?_⟩ + intro s; simpa only [Jet3.heatLog, ↓reduceDIte, coe_nnnorm] using g.gaussianAverage_norms s + let e := g.exp d + let B := (Real.exp (-(d : ℝ)*‖g.f‖))⁻¹ + let r := (d : ℝ)⁻¹ + have hB : 0 ≤ B := by positivity + have hr : 0 ≤ r := by positivity + refine ⟨‖g.f‖₊, + ⟨r*(‖e.d1‖*B), by positivity⟩, + ⟨r*(‖e.d2‖*B+‖e.d1‖^2*B^2), by positivity⟩, + ⟨r*(‖e.d3‖*B+3*(‖e.d1‖*‖e.d2‖*B^2)+2*(‖e.d1‖^3*B^3)), by positivity⟩, ?_⟩ + intro s + let A := e.gaussianAverage s + let c := Real.exp (-(d : ℝ)*‖g.f‖) + let hc := Real.exp_pos (-(d : ℝ)*‖g.f‖) + let hA : ∀ x, c ≤ A.f x := fun x => (gaussianAverage_exp_bounds s d d.coe_nonneg g.f x).1 + let J := invBCF A.f c hc hA + have hj : ‖J‖ ≤ B := invBCF_norm_le A.f c hc hA + obtain ⟨_, h₁,h₂,h₃⟩ := e.gaussianAverage_norms s + have hf : ‖(g.heatLog s d).f‖ ≤ ‖g.f‖ := by + rw [g.heatLog_f, BoundedContinuousFunction.norm_le (norm_nonneg _)] + exact heatLog_abs_le s d g.f + rw [Jet3.heatLog, dite_eq_right hd] + refine ⟨by simpa only [Jet3.heatLog, dite_eq_right hd, coe_nnnorm] using hf, ?_, ?_, ?_⟩ + · change ‖r • (A.d1*J)‖ ≤ r * (‖e.d1‖*B) + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg hr] + exact mul_le_mul_of_nonneg_left ((norm_mul_le _ _).trans (by gcongr)) hr + · change ‖r • (A.d2*J - A.d1^2*J^2)‖ ≤ r*(‖e.d2‖*B+‖e.d1‖^2*B^2) + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg hr] + gcongr + refine (norm_sub_le _ _).trans (add_le_add ?_ ?_) + · exact (norm_mul_le _ _).trans (by gcongr) + · refine (norm_mul_le _ _).trans ?_ + gcongr + · exact (norm_pow_le _ _).trans (by gcongr) + · exact (norm_pow_le _ _).trans (by gcongr) + · change ‖r • (A.d3*J - (3 : ℝ) • (A.d1*A.d2*J^2) + (2 : ℝ) • (A.d1^3*J^3))‖ ≤ _ + rw [norm_smul, Real.norm_eq_abs, abs_of_nonneg hr] + apply mul_le_mul_of_nonneg_left _ hr + refine (norm_add_le _ _).trans (add_le_add ((norm_sub_le _ _).trans (add_le_add ?_ ?_)) ?_) + · exact (norm_mul_le _ _).trans (by gcongr) + · rw [norm_smul]; norm_num [Real.norm_eq_abs] + refine (norm_mul_le _ _).trans ?_ + gcongr + · exact (norm_mul_le _ _).trans (by gcongr) + · exact (norm_pow_le _ _).trans (by gcongr) + · rw [norm_smul]; norm_num [Real.norm_eq_abs] + refine (norm_mul_le _ _).trans ?_ + gcongr + · exact (norm_pow_le _ _).trans (by gcongr) + · exact (norm_pow_le _ _).trans (by gcongr) + +lemma heatLog_generator_uniform (d C₀ C₁ C₂ C₃ : ℝ≥0) : + ∃ C : ℝ≥0, ∀ (g : Jet3), ‖g.f‖ ≤ C₀ → ‖g.d1‖ ≤ C₁ → + ‖g.d2‖ ≤ C₂ → ‖g.d3‖ ≤ C₃ → ∀ (s : ℝ≥0), s ≤ 1 → ∀ x : ℝ, + |heatLog s d g.f x - g.f x - (s : ℝ)/2 * (g.d2 x + (d : ℝ)*(g.d1 x)^2)| ≤ + (C : ℝ) * (s : ℝ) * Real.sqrt s := by + let M := ∫ z : ℝ, |z|^3 ∂gaussianReal 0 1 + have hM : 0 ≤ M := integral_nonneg (fun z => by positivity) + by_cases hd : d = 0 + · subst d + refine ⟨⟨(C₃ : ℝ)/6*M, by positivity⟩, ?_⟩ + intro g _ _ _ h₃ s _ x + simp only [heatLog, ↓reduceIte, NNReal.coe_zero, zero_mul, add_zero] + calc + _ ≤ ‖g.d3‖/6 * (Real.sqrt s)^3 * M := gaussianAverage_jet_error s g x + _ ≤ (C₃ : ℝ)/6 * (Real.sqrt s)^3 * M := by gcongr + _ = (C₃ : ℝ)/6*M * (s : ℝ) * Real.sqrt s := by + have hh := Real.sq_sqrt s.coe_nonneg + calc + _ = (C₃ : ℝ)/6*M * (Real.sqrt s)^2 * Real.sqrt s := by ring + _ = _ := by rw [hh] + let c := Real.exp (-(d : ℝ)*C₀) + let E := Real.exp ((d : ℝ)*C₀) + let E₂ : ℝ≥0 := ⟨E*((d : ℝ)^2*C₁^2+(d : ℝ)*C₂), by positivity⟩ + let E₃ : ℝ≥0 := ⟨E*((d : ℝ)^3*C₁^3+3*(d : ℝ)^2*C₁*C₂+(d : ℝ)*C₃), by positivity⟩ + let K := ((E₂ : ℝ)/2+(E₃ : ℝ)/6*M)^2/c^2 + ((E₃ : ℝ)/6*M)/c + have hc : 0 < c := Real.exp_pos _ + have hK : 0 ≤ K := by positivity + have hdpos : (0 : ℝ) < d := NNReal.coe_pos.mpr (pos_iff_ne_zero.mpr hd) + refine ⟨⟨(d : ℝ)⁻¹*K, by positivity⟩, ?_⟩ + intro g h₀ h₁ h₂ h₃ s hs x + have hh := g.exp_norms d C₀ C₁ C₂ C₃ h₀ h₁ h₂ h₃ + have hlo (x : ℝ) : c ≤ (g.exp d).f x := by + change Real.exp (-(d : ℝ)*C₀) ≤ Real.exp ((d : ℝ)*g.f x) + apply Real.exp_le_exp.mpr + have hb : |g.f x| ≤ C₀ := (g.f.norm_coe_le_norm x).trans h₀ + nlinarith [(abs_le.mp hb).1] + have herr := log_gaussian_generator_error (g.exp d) c hc hlo E₂ E₃ hh.2.2.1 hh.2.2.2 s hs x + have he : (s : ℝ)/2 * (g.exp d).d2 x / (g.exp d).f x = + (d : ℝ) * ((s : ℝ)/2 * (g.d2 x + (d : ℝ)*(g.d1 x)^2)) := by + change (s : ℝ)/2 * (Real.exp ((d : ℝ)*g.f x) * ((d : ℝ)^2*g.d1 x^2 + (d : ℝ)*g.d2 x)) / + Real.exp ((d : ℝ)*g.f x) = _ + field_simp + ring + have hid : heatLog s d g.f x - g.f x - (s : ℝ)/2 * (g.d2 x+(d : ℝ)*g.d1 x^2) = + (d : ℝ)⁻¹ * (Real.log (gaussianAverage s (g.exp d).f x) - Real.log ((g.exp d).f x) - + (s : ℝ)/2 * (g.exp d).d2 x / (g.exp d).f x) := by + rw [he] + change _ = (d : ℝ)⁻¹ * (Real.log (gaussianAverage s (expBCF d g.f) x) - + Real.log (Real.exp ((d : ℝ)*g.f x)) - _) + rw [Real.log_exp] + simp only [heatLog, hd, ↓reduceIte] + field_simp + rw [hid, abs_mul, abs_of_pos (inv_pos.mpr hdpos)] + calc + _ ≤ (d : ℝ)⁻¹ * (K*(s : ℝ)*Real.sqrt s) := mul_le_mul_of_nonneg_left herr (inv_nonneg.mpr hdpos.le) + _ = _ := by change (d : ℝ)⁻¹ * (K*(s : ℝ)*Real.sqrt s) = (d : ℝ)⁻¹*K*(s : ℝ)*Real.sqrt s; ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/HeatTilt.lean b/lean/OAI/Probability/Perceptron/Variational/HeatTilt.lean new file mode 100644 index 0000000000000000000000000000000000000000..b2d20f6be1d2e74da3826c51d81f03b305a8e2e6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/HeatTilt.lean @@ -0,0 +1,443 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StableLaplaceConstant +import OAI.Probability.Perceptron.Variational.NormSquareBand + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff + +lemma canonicalBandRadiusWeight_mass (n : ℕ) (b ε : ℝ) : + (∫⁻ x : RadialSpace n, canonicalBandRadiusWeight n b ε ‖x‖) = + canonicalRadialMass n b (normSquareBand n ε) := by + simpa using canonicalBandRadiusWeight_integral n b ε (fun _ => 1) measurable_const + +lemma canonicalField_band_bounds (n : ℕ) (b ε : ℝ) + (ρ : Measure (Spin (n+1))) [SFinite ρ] : + angularFieldFactor ρ (Real.sqrt (((n+1:ℕ):ℝ)*(1-ε))) * + canonicalRadialMass n b (normSquareBand n ε) ≤ + (∫⁻ x in normSquareBand n ε, linearFieldFactor ρ x ∂canonicalRadialMass n b) ∧ + (∫⁻ x in normSquareBand n ε, linearFieldFactor ρ x ∂canonicalRadialMass n b) ≤ + angularFieldFactor ρ (Real.sqrt (((n+1:ℕ):ℝ)*(1+ε))) * + canonicalRadialMass n b (normSquareBand n ε) := by + have hh := polar_weighted_bounds (volume : Measure (RadialSpace n)) + (linearFieldFactor ρ) (linearFieldFactor_measurable ρ) + (canonicalBandRadiusWeight n b ε) (canonicalBandRadiusWeight_measurable n b ε) + (L := angularFieldFactor ρ (Real.sqrt (((n+1:ℕ):ℝ)*(1-ε)))) + (U := angularFieldFactor ρ (Real.sqrt (((n+1:ℕ):ℝ)*(1+ε)))) + rw [canonicalBandRadiusWeight_integral n b ε _ (linearFieldFactor_measurable ρ), + canonicalBandRadiusWeight_mass] at hh + apply hh + · intro r hr + have hb : ((n+1:ℕ):ℝ)*(1-ε) ≤ (r:ℝ)^2 ∧ (r:ℝ)^2 ≤ ((n+1:ℕ):ℝ)*(1+ε) := by + by_contra hn + exact hr (by simp only [canonicalBandRadiusWeight,Set.indicator_apply,Set.mem_ofPred_eq,hn,ite_false]) + change angularFieldFactor ρ _ ≤ angularFieldFactor ρ (r:ℝ) + apply angularFieldFactor_mono ρ (Real.sqrt_nonneg _) + exact (Real.sqrt_le_iff).mpr ⟨r.property.le,hb.1⟩ + · intro r hr + have hb : ((n+1:ℕ):ℝ)*(1-ε) ≤ (r:ℝ)^2 ∧ (r:ℝ)^2 ≤ ((n+1:ℕ):ℝ)*(1+ε) := by + by_contra hn + exact hr (by simp only [canonicalBandRadiusWeight,Set.indicator_apply,Set.mem_ofPred_eq,hn,ite_false]) + change angularFieldFactor ρ (r:ℝ) ≤ angularFieldFactor ρ _ + apply angularFieldFactor_mono ρ r.property.le + exact (Real.le_sqrt' r.property).mpr hb.2 + +lemma canonicalWeighted_mass_le (n : ℕ) (F : RadialSpace n → ℝ≥0∞) (hF : Measurable F) + {A : Set (RadialSpace n)} (hA : MeasurableSet A) {a b c : ℝ} + (hc : ∀ x ∈ A, -(a/2)*‖x‖^2 ≤ c-(b/2)*‖x‖^2) : + (∫⁻ x in A, F x ∂canonicalRadialMass n a) ≤ + ENNReal.ofReal (Real.exp c) * (∫⁻ x, F x ∂canonicalRadialMass n b) := by + have hd (d : ℝ) : Measurable (fun x : RadialSpace n => ENNReal.ofReal (canonicalRadialDensity n d x)) := + (canonicalRadialDensity_continuous n d).measurable.ennreal_ofReal + rw [canonicalRadialMass,setLIntegral_withDensity_eq_setLIntegral_mul _ (hd a) hF hA, + canonicalRadialMass,lintegral_withDensity_eq_lintegral_mul _ (hd b) hF, + ← lintegral_const_mul _ ((hd b).mul hF)] + calc + _ ≤ ∫⁻ x in A, ENNReal.ofReal (Real.exp c) * + (ENNReal.ofReal (canonicalRadialDensity n b x) * F x) := by + apply lintegral_mono_ae + filter_upwards [ae_restrict_mem hA] with x hx + change ENNReal.ofReal (canonicalRadialDensity n a x) * F x ≤ _ + rw [← mul_assoc,← ENNReal.ofReal_mul (Real.exp_pos c).le] + apply mul_le_mul (ENNReal.ofReal_le_ofReal ?_) le_rfl (by positivity) (by positivity) + unfold canonicalRadialDensity + calc + _ ≤ radialNormalizer n * Real.exp (c-(b/2)*‖x‖^2) := + mul_le_mul_of_nonneg_left (Real.exp_le_exp.mpr (hc x hx)) (radialNormalizer_pos n).le + _ = _ := by rw [Real.exp_sub,neg_mul,Real.exp_neg]; ring + _ ≤ _ := setLIntegral_le_lintegral _ _ + +lemma canonicalWeighted_upper_tail (n : ℕ) (F : RadialSpace n → ℝ≥0∞) (hF : Measurable F) + (b ε : ℝ) {δ : ℝ} (hδ : 0 ≤ δ) : + (∫⁻ x in {x : RadialSpace n | ((n+1:ℕ):ℝ)*(1+ε) ≤ ‖x‖^2}, F x ∂canonicalRadialMass n b) ≤ + ENNReal.ofReal (Real.exp (-δ*((n+1:ℕ):ℝ)*(1+ε)/2)) * + (∫⁻ x, F x ∂canonicalRadialMass n (b-δ)) := by + apply canonicalWeighted_mass_le n F hF + (measurableSet_le measurable_const (continuous_norm.pow 2).measurable) + intro x hx + dsimp only [Set.mem_ofPred_eq,Pi.pow_apply] at hx + have := mul_le_mul_of_nonneg_left hx hδ + nlinarith + +lemma canonicalWeighted_lower_tail (n : ℕ) (F : RadialSpace n → ℝ≥0∞) (hF : Measurable F) + (b ε : ℝ) {δ : ℝ} (hδ : 0 ≤ δ) : + (∫⁻ x in {x : RadialSpace n | ‖x‖^2 ≤ ((n+1:ℕ):ℝ)*(1-ε)}, F x ∂canonicalRadialMass n b) ≤ + ENNReal.ofReal (Real.exp (δ*((n+1:ℕ):ℝ)*(1-ε)/2)) * + (∫⁻ x, F x ∂canonicalRadialMass n (b+δ)) := by + apply canonicalWeighted_mass_le n F hF + (measurableSet_le (continuous_norm.pow 2).measurable measurable_const) + intro x hx + dsimp only [Set.mem_ofPred_eq,Pi.pow_apply] at hx + have := mul_le_mul_of_nonneg_left hx hδ + nlinarith + +def heatTilt (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) (x : ℝ) : ℝ := + gaussianAverage s (expBCF d f * h) x / gaussianAverage s (expBCF d f) x + +lemma heatTilt_zero (s : ℝ≥0) (f h : ℝ →ᵇ ℝ) (x : ℝ) : + heatTilt s 0 f h x = gaussianAverage s h x := by + simp [heatTilt,gaussianAverage,expBCF] + +lemma gaussianAverage_affine (s : ℝ≥0) (f h : ℝ →ᵇ ℝ) (t x : ℝ) : + gaussianAverage s (f+t • h : ℝ →ᵇ ℝ) x = gaussianAverage s f x + t * gaussianAverage s h x := by + simp only [gaussianAverage,BoundedContinuousFunction.coe_add, + BoundedContinuousFunction.coe_smul,Pi.add_apply,smul_eq_mul] + rw [integral_add (gaussianAverage_integrable s f x) + ((gaussianAverage_integrable s h x).const_mul t), integral_const_mul] + +lemma gaussian_exp_affine_deriv (s : ℝ≥0) (d : ℝ) (f h : ℝ →ᵇ ℝ) (t x : ℝ) : + HasDerivAt (fun u : ℝ => gaussianAverage s (expBCF d (f+u • h)) x) + (d * gaussianAverage s (expBCF d (f+t • h) * h) x) t := by + have hv : Measurable (fun z : ℝ => d*h (x+z)) := by fun_prop + have hF : Measurable (fun z : ℝ => Real.exp (d*f (x+z))) := by fun_prop + have hh := tilt_integral_deriv (gaussianReal 0 s) hv hF + (mul_nonneg (abs_nonneg d) (norm_nonneg h)) (Real.exp_pos (|d| * ‖f‖)).le + (fun z => by + change |d*h (x+z)| ≤ |d| * ‖h‖ + rw [abs_mul] + exact mul_le_mul_of_nonneg_left + (by simpa only [Real.norm_eq_abs] using h.norm_coe_le_norm (x+z)) (abs_nonneg d)) + (fun z => exp_bcf_bound d f (x+z)) t + convert! hh using 1 + · ext u + apply integral_congr_ae + filter_upwards [] with z + simp only [expBCF,BoundedContinuousFunction.mkOfBound_coe, + ContinuousMap.coe_mk,BoundedContinuousFunction.coe_add, + BoundedContinuousFunction.coe_smul,Pi.add_apply,smul_eq_mul] + rw [← Real.exp_add] + congr 1 + ring + · unfold gaussianAverage + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with z + simp only [Pi.mul_apply, + expBCF,BoundedContinuousFunction.mkOfBound_coe,ContinuousMap.coe_mk, + BoundedContinuousFunction.coe_add,BoundedContinuousFunction.coe_smul, + Pi.add_apply,smul_eq_mul] + rw [show d*(f (x+z)+t*h (x+z))=t*(d*h (x+z))+d*f (x+z) by ring,Real.exp_add] + ring + +lemma heatLog_directional_deriv (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) (t x : ℝ) : + HasDerivAt (fun u : ℝ => heatLog s d (f+u • h) x) + (heatTilt s d (f+t • h) h x) t := by + by_cases hd : d = 0 + · subst d + simp only [heatTilt_zero,heatLog,↓reduceIte,gaussianAverage_affine] + convert! (hasDerivAt_const t (gaussianAverage s f x)).add + ((hasDerivAt_id t).mul_const (gaussianAverage s h x)) using 1 + simp + · have hh := ((gaussian_exp_affine_deriv s d f h t x).log + (gaussianAverage_exp_pos s d (f+t • h) x).ne').const_mul (d:ℝ)⁻¹ + convert! hh using 1 + · simp only [heatLog,hd,↓reduceIte] + · unfold heatTilt + field_simp [NNReal.coe_ne_zero.mpr hd] + +lemma gaussianAverage_add (s : ℝ≥0) (f h : ℝ →ᵇ ℝ) (x : ℝ) : + gaussianAverage s (f+h : ℝ →ᵇ ℝ) x = gaussianAverage s f x + gaussianAverage s h x := + integral_add (gaussianAverage_integrable s f x) (gaussianAverage_integrable s h x) + +lemma gaussianAverage_smul (s : ℝ≥0) (f : ℝ →ᵇ ℝ) (a x : ℝ) : + gaussianAverage s (a • f : ℝ →ᵇ ℝ) x = a * gaussianAverage s f x := by + exact integral_const_mul _ _ + +lemma heatTilt_add (s d : ℝ≥0) (f h k : ℝ →ᵇ ℝ) (x : ℝ) : + heatTilt s d f (h+k) x = heatTilt s d f h x + heatTilt s d f k x := by + unfold heatTilt + change gaussianAverage s (expBCF d f * (h+k) : ℝ →ᵇ ℝ) x / _ = _ + rw [mul_add,gaussianAverage_add,add_div] + rfl + +lemma heatTilt_smul (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) (a x : ℝ) : + heatTilt s d f (a • h) x = a * heatTilt s d f h x := by + unfold heatTilt + change gaussianAverage s (expBCF d f * (a • h) : ℝ →ᵇ ℝ) x / _ = _ + rw [mul_smul_comm,gaussianAverage_smul,mul_div_assoc] + rfl + +lemma heatTilt_const (s d : ℝ≥0) (f : ℝ →ᵇ ℝ) (a x : ℝ) : + heatTilt s d f (BoundedContinuousFunction.const ℝ a) x = a := by + unfold heatTilt gaussianAverage + simp only [Pi.mul_apply,BoundedContinuousFunction.const_apply] + rw [integral_mul_const] + exact mul_div_cancel_left₀ a (gaussianAverage_exp_pos s d f x).ne' + +lemma heatTilt_nonneg (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) (hh : ∀ x, 0 ≤ h x) (x : ℝ) : + 0 ≤ heatTilt s d f h x := by + apply div_nonneg (integral_nonneg fun z => mul_nonneg (Real.exp_pos _).le (hh _)) + (gaussianAverage_exp_pos s d f x).le + +lemma heatTilt_mono (s d : ℝ≥0) (f h k : ℝ →ᵇ ℝ) + (hh : ∀ x, h x ≤ k x) (x : ℝ) : heatTilt s d f h x ≤ heatTilt s d f k x := by + apply div_le_div_of_nonneg_right _ (gaussianAverage_exp_pos s d f x).le + exact integral_mono (gaussianAverage_integrable s (expBCF d f*h) x) + (gaussianAverage_integrable s (expBCF d f*k) x) + (fun z => mul_le_mul_of_nonneg_left (hh _) (Real.exp_pos _).le) + +lemma heatTilt_abs_le (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) (x : ℝ) : + |heatTilt s d f h x| ≤ ‖h‖ := by + rw [abs_le] + constructor + · have hh := heatTilt_mono s d f (BoundedContinuousFunction.const ℝ (-‖h‖)) h + (fun y => (abs_le.mp (h.norm_coe_le_norm y)).1) x + simpa only [heatTilt_const] using hh + · have hh := heatTilt_mono s d f h (BoundedContinuousFunction.const ℝ ‖h‖) + (fun y => (abs_le.mp (h.norm_coe_le_norm y)).2) x + simpa only [heatTilt_const] using hh + +lemma heatTilt_sq (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) (x : ℝ) : + (heatTilt s d f h x)^2 ≤ heatTilt s d f (h^2) x := by + let c := heatTilt s d f h x + have hp := heatTilt_nonneg s d f ((h-BoundedContinuousFunction.const ℝ c)^2) + (fun y => sq_nonneg _) x + have he : (h-BoundedContinuousFunction.const ℝ c)^2 = + h^2 + (-2*c) • h + BoundedContinuousFunction.const ℝ (c^2) := by + ext y + simp only [BoundedContinuousFunction.coe_pow,BoundedContinuousFunction.coe_sub, + BoundedContinuousFunction.coe_add,BoundedContinuousFunction.coe_smul, + BoundedContinuousFunction.const_apply,Pi.pow_apply,Pi.sub_apply,Pi.add_apply,smul_eq_mul] + ring + rw [he,heatTilt_add,heatTilt_add,heatTilt_smul,heatTilt_const] at hp + dsimp only [c] at hp + nlinarith + +lemma Jet3.heatLog_d1 (g : Jet3) (s d : ℝ≥0) (x : ℝ) : + (g.heatLog s d).d1 x = heatTilt s d g.f g.d1 x := by + by_cases hd : d = 0 + · subst d + simp only [Jet3.heatLog,↓reduceDIte,heatTilt_zero] + rfl + · have he : (g.exp d).d1 = (d:ℝ) • (expBCF d g.f*g.d1) := rfl + simp only [Jet3.heatLog,hd,↓reduceDIte,Jet3.heatLogPos] + change (d:ℝ)⁻¹ * (SphericalPerceptronFreeEnergy.gaussianAverage s (g.exp d).d1 x * + (SphericalPerceptronFreeEnergy.gaussianAverage s (expBCF d g.f) x)⁻¹) = _ + rw [he,SphericalPerceptronFreeEnergy.gaussianAverage_smul] + unfold heatTilt + field_simp [NNReal.coe_ne_zero.mpr hd] + rfl + +lemma Jet3.heatLog_d1_sq_le (g : Jet3) (s d : ℝ≥0) (x : ℝ) : + ((g.heatLog s d).d1 x)^2 ≤ heatTilt s d g.f (g.d1^2) x := by + rw [g.heatLog_d1] + exact heatTilt_sq s d g.f g.d1 x + +lemma gaussian_exp_affine_mul_deriv (s : ℝ≥0) (d : ℝ) (f h k : ℝ →ᵇ ℝ) (t x : ℝ) : + HasDerivAt (fun u : ℝ => gaussianAverage s (expBCF d (f+u • h)*k : ℝ →ᵇ ℝ) x) + (d * gaussianAverage s (expBCF d (f+t • h) * (h*k) : ℝ →ᵇ ℝ) x) t := by + have hv : Measurable (fun z : ℝ => d*h (x+z)) := by fun_prop + have hF : Measurable (fun z : ℝ => Real.exp (d*f (x+z))*k (x+z)) := by fun_prop + have hh := tilt_integral_deriv (gaussianReal 0 s) hv hF + (mul_nonneg (abs_nonneg d) (norm_nonneg h)) + (mul_nonneg (Real.exp_pos (|d| * ‖f‖)).le (norm_nonneg k)) + (fun z => by + change |d*h (x+z)| ≤ |d| * ‖h‖ + rw [abs_mul] + exact mul_le_mul_of_nonneg_left + (by simpa only [Real.norm_eq_abs] using h.norm_coe_le_norm (x+z)) (abs_nonneg d)) + (fun z => by + rw [abs_mul] + exact mul_le_mul (exp_bcf_bound d f (x+z)) (k.norm_coe_le_norm (x+z)) + (abs_nonneg _) (Real.exp_pos _).le) t + convert! hh using 1 + · ext u + apply integral_congr_ae + filter_upwards [] with z + change Real.exp (d*(f (x+z)+u*h (x+z)))*k (x+z) = _ + rw [show d*(f (x+z)+u*h (x+z))=u*(d*h (x+z))+d*f (x+z) by ring,Real.exp_add] + ring + · unfold gaussianAverage + rw [← integral_const_mul] + apply integral_congr_ae + filter_upwards [] with z + change d*(Real.exp (d*(f (x+z)+t*h (x+z)))*(h (x+z)*k (x+z))) = _ + rw [show d*(f (x+z)+t*h (x+z))=t*(d*h (x+z))+d*f (x+z) by ring,Real.exp_add] + ring + +lemma heatTilt_directional_deriv (s d : ℝ≥0) (f h k : ℝ →ᵇ ℝ) (t x : ℝ) : + HasDerivAt (fun u : ℝ => heatTilt s d (f+u • h) k x) + ((d:ℝ)*(heatTilt s d (f+t • h) (h*k) x - + heatTilt s d (f+t • h) h x * heatTilt s d (f+t • h) k x)) t := by + have hh := (gaussian_exp_affine_mul_deriv s d f h k t x).div + (gaussian_exp_affine_deriv s d f h t x) (gaussianAverage_exp_pos s d (f+t • h) x).ne' + convert! hh using 1 + unfold heatTilt + simp only [← BoundedContinuousFunction.coe_mul] + field_simp + +lemma heatTilt_directional_bound (s d : ℝ≥0) (f h k : ℝ →ᵇ ℝ) (t x : ℝ) : + |(d:ℝ)*(heatTilt s d (f+t • h) (h*k) x - + heatTilt s d (f+t • h) h x * heatTilt s d (f+t • h) k x)| ≤ + 2*(d:ℝ)*‖h‖*‖k‖ := by + rw [abs_mul,abs_of_nonneg d.coe_nonneg] + calc + _ ≤ (d:ℝ)*(|heatTilt s d (f+t • h) (h*k) x| + + |heatTilt s d (f+t • h) h x * heatTilt s d (f+t • h) k x|) := by + gcongr; exact abs_sub _ _ + _ ≤ (d:ℝ)*(‖h*k‖ + ‖h‖*‖k‖) := by + rw [abs_mul] + gcongr + · exact heatTilt_abs_le s d _ _ x + · exact heatTilt_abs_le s d _ _ x + · exact heatTilt_abs_le s d _ _ x + _ ≤ 2*(d:ℝ)*‖h‖*‖k‖ := by + nlinarith [mul_le_mul_of_nonneg_left (norm_mul_le h k) d.coe_nonneg] + +lemma heatTilt_affine_sub_bound (s d : ℝ≥0) (f h k : ℝ →ᵇ ℝ) (t x : ℝ) : + |heatTilt s d (f+t • h) k x - heatTilt s d f k x| ≤ + 2*(d:ℝ)*‖h‖*‖k‖*|t| := by + have hh := Convex.norm_image_sub_le_of_norm_hasDerivWithin_le + (s := Set.univ) (fun u _ => (heatTilt_directional_deriv s d f h k u x).hasDerivWithinAt) + (fun u _ => heatTilt_directional_bound s d f h k u x) convex_univ + (mem_univ (0:ℝ)) (mem_univ t) + simpa only [zero_smul,add_zero,sub_zero,Real.norm_eq_abs] using hh + +lemma heatLog_terminal_quadratic_error (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) (x : ℝ) : + |heatLog s d (f+h) x - heatLog s d f x - heatTilt s d f h x| ≤ + 2*(d:ℝ)*‖h‖^2 := by + have hd (u : ℝ) : HasDerivAt + (fun t => heatLog s d (f+t • h) x - heatLog s d f x - t*heatTilt s d f h x) + (heatTilt s d (f+u • h) h x - heatTilt s d f h x) u := by + convert! ((heatLog_directional_deriv s d f h u x).sub_const (heatLog s d f x)).sub + ((hasDerivAt_id u).mul_const (heatTilt s d f h x)) using 1 + simp + have hh := norm_image_sub_le_of_norm_deriv_le_segment_01' + (fun u _ => (hd u).hasDerivWithinAt) (fun u hu => show + ‖heatTilt s d (f+u • h) h x - heatTilt s d f h x‖ ≤ 2*(d:ℝ)*‖h‖^2 from by + calc + _ ≤ 2*(d:ℝ)*‖h‖*‖h‖*|u| := heatTilt_affine_sub_bound s d f h h u x + _ ≤ 2*(d:ℝ)*‖h‖^2 := by + rw [abs_of_nonneg hu.1] + nlinarith [mul_nonneg (show 0 ≤ 2*(d:ℝ)*‖h‖^2 by positivity) (sub_nonneg.mpr hu.2.le)]) + simpa only [zero_smul,one_smul,add_zero,zero_mul,one_mul,sub_self,sub_zero, + Real.norm_eq_abs] using hh + +lemma heatTilt_continuous (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) : Continuous (heatTilt s d f h) := + (gaussianAverage_continuous s (expBCF d f*h)).div + (gaussianAverage_continuous s (expBCF d f)) (fun x => (gaussianAverage_exp_pos s d f x).ne') + +def heatTiltBCF (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound ⟨heatTilt s d f h,heatTilt_continuous s d f h⟩ + (2*‖h‖) (fun x y => by + change |heatTilt s d f h x - heatTilt s d f h y| ≤ 2*‖h‖ + exact (abs_sub _ _).trans (by linarith [heatTilt_abs_le s d f h x,heatTilt_abs_le s d f h y])) + +@[simp] lemma heatTiltBCF_apply (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) (x : ℝ) : + heatTiltBCF s d f h x = heatTilt s d f h x := rfl + +lemma heatTiltBCF_norm_le (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) : ‖heatTiltBCF s d f h‖ ≤ ‖h‖ := + (BoundedContinuousFunction.norm_le (norm_nonneg h)).mpr (heatTilt_abs_le s d f h) + +def heatTiltCLM (s d : ℝ≥0) (f : ℝ →ᵇ ℝ) : (ℝ →ᵇ ℝ) →L[ℝ] (ℝ →ᵇ ℝ) := + LinearMap.mkContinuous + { toFun := heatTiltBCF s d f + map_add' := fun h k => by ext x; exact heatTilt_add s d f h k x + map_smul' := fun a h => by ext x; exact heatTilt_smul s d f h a x } + 1 (fun h => by + change ‖heatTiltBCF s d f h‖ ≤ 1*‖h‖ + simpa only [one_mul] using heatTiltBCF_norm_le s d f h) + +lemma heatLogBCF_terminal_quadratic_error (s d : ℝ≥0) (f h : ℝ →ᵇ ℝ) : + ‖heatLogBCF s d (f+h)-heatLogBCF s d f-heatTiltCLM s d f h‖ ≤ 2*(d:ℝ)*‖h‖^2 := + (BoundedContinuousFunction.norm_le (by positivity)).mpr (heatLog_terminal_quadratic_error s d f h) + +lemma heatLogBCF_hasFDerivAt (s d : ℝ≥0) (f : ℝ →ᵇ ℝ) : + HasFDerivAt (heatLogBCF s d) (heatTiltCLM s d f) f := by + rw [hasFDerivAt_iff_isLittleO_nhds_zero,Asymptotics.isLittleO_iff] + intro ε hε + have he : ∀ᶠ h : (ℝ →ᵇ ℝ) in 𝓝 0, ‖h‖ < ε/(2*(d:ℝ)+1) := + by + filter_upwards [Metric.ball_mem_nhds (0 : ℝ →ᵇ ℝ) + (show 0 < ε/(2*(d:ℝ)+1) by positivity)] with h hh + simpa only [Metric.mem_ball,dist_zero_right] using hh + filter_upwards [he] with h hh + calc + _ ≤ 2*(d:ℝ)*‖h‖^2 := heatLogBCF_terminal_quadratic_error s d f h + _ ≤ ε*‖h‖ := by + have hb : ‖h‖*(2*(d:ℝ)+1) < ε := (lt_div_iff₀ (by positivity)).mp hh + nlinarith [norm_nonneg h,mul_nonneg (norm_nonneg h) (sub_nonneg.mpr hb.le)] + +def shiftBCF (f : ℝ →ᵇ ℝ) (a : ℝ) : ℝ →ᵇ ℝ := + f.compContinuous ⟨fun x => x+a,by fun_prop⟩ + +@[simp] lemma shiftBCF_apply (f : ℝ →ᵇ ℝ) (a x : ℝ) : shiftBCF f a x = f (x+a) := rfl + +lemma shiftBCF_norm_le (f : ℝ →ᵇ ℝ) (a : ℝ) : ‖shiftBCF f a‖ ≤ ‖f‖ := + (BoundedContinuousFunction.norm_le (norm_nonneg f)).mpr (fun x => f.norm_coe_le_norm (x+a)) + +lemma shiftBCF_lipschitz (f f' : ℝ →ᵇ ℝ) + (hf : ∀ x, HasDerivAt (f:ℝ→ℝ) (f' x) x) : + LipschitzWith ‖f'‖₊ (shiftBCF f) := by + have hl := lipschitzWith_of_nnnorm_deriv_le (C := ‖f'‖₊) (fun x => (hf x).differentiableAt) (fun x => by + rw [(hf x).deriv] + exact_mod_cast f'.norm_coe_le_norm x) + apply LipschitzWith.of_dist_le_mul + intro a b + rw [dist_eq_norm] + apply (BoundedContinuousFunction.norm_le (by positivity)).mpr + intro x + change |f (x+a)-f (x+b)| ≤ _ + simpa only [Real.dist_eq,add_sub_add_left_eq_sub,coe_nnnorm] using hl.dist_le_mul (x+a) (x+b) + +lemma shiftBCF_Jet3_hasDerivAt (g : Jet3) (a : ℝ) : + HasDerivAt (shiftBCF g.f) (shiftBCF g.d1 a) a := by + rw [hasDerivAt_iff_isLittleO_nhds_zero,Asymptotics.isLittleO_iff] + intro ε hε + have he : ∀ᶠ h : ℝ in 𝓝 0, |h| < ε/(‖g.d2‖+1) := by + filter_upwards [Metric.ball_mem_nhds (0 : ℝ) + (show 0 < ε/(‖g.d2‖+1) by positivity)] with h hh + simpa only [Metric.mem_ball,Real.dist_eq,sub_zero] using hh + filter_upwards [he] with h hh + have hb : ‖shiftBCF g.f (a+h)-shiftBCF g.f a-h • shiftBCF g.d1 a‖ ≤ ‖g.d2‖*h^2/2 := by + apply (BoundedContinuousFunction.norm_le (by positivity)).mpr + intro x + have ht := first_order_taylor_bound (g.contDiff.of_le (by norm_num)) ‖g.d2‖ + (fun y => by rw [g.deriv2_eq]; exact g.d2.norm_coe_le_norm y) (x+a) (x+(a+h)) + rw [g.deriv_eq] at ht + convert! ht using 1 <;> simp [shiftBCF,add_comm,add_left_comm,mul_comm] + calc + _ ≤ ‖g.d2‖*h^2/2 := hb + _ ≤ ε*‖h‖ := by + have ht : |h| * (‖g.d2‖+1) < ε := (lt_div_iff₀ (by positivity)).mp hh + rw [Real.norm_eq_abs] + nlinarith [sq_abs h,abs_nonneg h,norm_nonneg g.d2, + mul_nonneg (abs_nonneg h) (sub_nonneg.mpr ht.le)] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/HeightWord.lean b/lean/OAI/Probability/Perceptron/Variational/HeightWord.lean new file mode 100644 index 0000000000000000000000000000000000000000..3d75a121b510fdfe7e46f69b3a11f1a26c24588c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/HeightWord.lean @@ -0,0 +1,232 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.HeightPartition + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +def extendedFieldExponents {d : ℕ} (w : Fin (d+1) → ℝ) (i : Fin (d+2)) : ℝ := + ∑ r, if r.castSucc < i then w r else 0 + +def finiteFieldCDFLeft {d : ℕ} (w h : Fin (d+1) → ℝ) (t : ℝ) : ℝ := + ∑ r, if h r < t then w r else 0 + +lemma extendedFieldExponents_castSucc {d : ℕ} (w : Fin (d+1) → ℝ) (i : Fin (d+1)) : + extendedFieldExponents w i.castSucc=fieldExponents w i := by + refine Fin.cases ?_ (fun i => ?_) i + · simp [extendedFieldExponents,fieldExponents] + · unfold extendedFieldExponents fieldExponents + simp only [Fin.cases_succ,stepCumulative] + apply Finset.sum_congr rfl + intro r _ + have he : r.castSucc < i.succ.castSucc ↔ r ≤ i.castSucc := by + simp only [Fin.lt_def,Fin.le_def,Fin.val_castSucc,Fin.val_succ] + omega + simp only [he] + +lemma extendedFieldExponents_last {d : ℕ} (w : Fin (d+1) → ℝ) : + extendedFieldExponents w (Fin.last (d+1))=∑ r, w r := by + simp [extendedFieldExponents,Fin.castSucc_lt_last] + +lemma extendedFieldExponents_nonneg {d : ℕ} (w : Fin (d+1) → ℝ) (hw : ∀ i, 0 ≤ w i) + (i : Fin (d+2)) : 0 ≤ extendedFieldExponents w i := by + apply Finset.sum_nonneg + intro r _ + split_ifs <;> first | exact hw r | rfl + +lemma extendedFieldExponents_heightIndex {d : ℕ} (w h : Fin (d+1) → ℝ) (hh : Monotone h) + (t : ℝ) : extendedFieldExponents w (heightIndex h t)=finiteFieldCDFLeft w h t := by + simp only [extendedFieldExponents,finiteFieldCDFLeft,lt_heightIndex_iff h hh] + +lemma sphericalHeatValue_compress (n N : ℕ) (p : Fin N → ℝ) (hp : ∀ i, 0 ≤ p i) + (l : List (Fin N×ℝ)) (hl : l.Pairwise (fun a b => a.1 ≤ b.1)) + (hv : ∀ c ∈ l, 0 ≤ c.2) : + sphericalHeatValue n (l.map fun c => (p c.1,Real.sqrt c.2))= + sphericalHeatValue n (List.ofFn fun i => (p i,Real.sqrt (gridVariance l i))) := by + unfold sphericalHeatValue + rw [gaussianBackward_compress (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) N p hp l hl hv] + congr 1 + rw [List.map_ofFn,List.sum_ofFn,List.map_map] + change (l.map fun c => (Real.sqrt c.2)^2).sum/2=(∑ i, (Real.sqrt (gridVariance l i))^2)/2 + simp only [Real.sq_sqrt (gridVariance_nonneg l hv _)] + rw [gridVariance_sum] + congr 2 + apply List.map_congr_left + intro c hc + exact Real.sq_sqrt (hv c hc) + +lemma sphericalHeatValue_drop_last_one (n d : ℕ) (p v : Fin (d+2) → ℝ) + (hp : ∀ i, 0 ≤ p i) (hv : ∀ i, 0 ≤ v i) (hpl : p (Fin.last (d+1))=1) : + sphericalHeatValue n (List.ofFn fun i => (p i,Real.sqrt (v i)))= + sphericalHeatValue n (List.ofFn fun i : Fin (d+1) => (p i.castSucc,Real.sqrt (v i.castSucc))) := by + unfold sphericalHeatValue + have he := congrFun (gaussianGrid_spherical_last n d p v hp (hv _) hpl) 0 + unfold gaussianGrid at he + rw [he] + simp only [List.map_ofFn,List.sum_ofFn,Function.comp_apply,Real.sq_sqrt (hv _)] + rw [Fin.sum_univ_castSucc v] + have hn : (n+1:ℕ) ≠ (0:ℝ) := by positivity + field_simp [hn] + ring + +lemma finiteSphericalFieldValue_height_word {d K : ℕ} (w h : Fin (d+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) (hh : Monotone h) (hh0 : 0 ≤ h 0) + (z : Fin (K+1) → ℝ) (hz : Monotone z) (hz0 : z 0=0) + (hm : ∀ i, h i ∈ Set.range z) (n : ℕ) : + finiteSphericalFieldValue n d w h=sphericalHeatValue n + (List.ofFn fun j => (finiteFieldCDFLeft w h (z j.succ),Real.sqrt (heightVariances z j))) := by + let l := List.ofFn fun j => (heightIndex h (z j.succ),heightVariances z j) + have hl : l.Pairwise (fun a b => a.1 ≤ b.1) := by + apply List.pairwise_ofFn.mpr + intro i j hij + exact heightIndex_monotone h (hz (Fin.succ_le_succ_iff.mpr hij.le)) + have hv : ∀ c ∈ l, 0 ≤ c.2 := by + intro c hc; obtain ⟨j,rfl⟩ := List.mem_ofFn.mp hc + exact heightVariances_nonneg z hz j + have he := sphericalHeatValue_compress n (d+2) (extendedFieldExponents w) + (extendedFieldExponents_nonneg w (fun i => (hw i).le)) l hl hv + dsimp only [l] at he + simp only [List.map_ofFn,Function.comp_def,extendedFieldExponents_heightIndex w h hh] at he + rw [he,sphericalHeatValue_drop_last_one n d _ _ + (extendedFieldExponents_nonneg w (fun i => (hw i).le)) (gridVariance_nonneg l hv) + (by rw [extendedFieldExponents_last,hw1])] + have hvf : (fun i => gridVariance l i.castSucc)=fieldVariances d h := by + have hpref : varianceLevels (fun i => gridVariance l i.castSucc)=h := by + funext i + exact heightIndex_grid_prefix h hh z hz hz0 hm i + rw [← hpref,fieldVariances_varianceLevels] + simp only [extendedFieldExponents_castSucc] + change finiteSphericalFieldValue n d w h=sphericalHeatValue n + (List.ofFn fun i => (fieldExponents w i,Real.sqrt ((fun i => gridVariance l i.castSucc) i))) + rw [hvf] + exact finiteSphericalFieldValue_eq_heat w h hw hw1 hh hh0 n + +def heightIndicator (r t : ℝ) : ℝ := if r < t then 1 else 0 + +lemma heightIndicator_antitone (t : ℝ) : Antitone (fun r => heightIndicator r t) := by + intro r s hrs + dsimp only [heightIndicator] + split_ifs with hs hr + · rfl + · exact (hr (hrs.trans_lt hs)).elim + · norm_num + · rfl + +lemma heightIndicator_weighted_sum {K : ℕ} (z : Fin (K+1) → ℝ) (hz : Monotone z) + (r : ℝ) (hr : r ∈ Set.range z) : + (∑ j, heightVariances z j*heightIndicator r (z j.succ))=2*(z (Fin.last K)-r) := by + have he (j : Fin K) : heightVariances z j*heightIndicator r (z j.succ)= + heightVariances z j-(if z j.succ ≤ r then heightVariances z j else 0) := by + unfold heightIndicator + by_cases hj : z j.succ ≤ r + · simp [hj,not_lt.mpr hj] + · simp [hj,lt_of_not_ge hj] + simp only [he,Finset.sum_sub_distrib,heightVariances_prefix z hz r hr,heightVariances_sum] + ring + +lemma heightIndicator_distance_sum {K : ℕ} (z : Fin (K+1) → ℝ) (hz : Monotone z) + (r s : ℝ) (hr : r ∈ Set.range z) (hs : s ∈ Set.range z) : + (∑ j, heightVariances z j*|heightIndicator r (z j.succ)-heightIndicator s (z j.succ)|)= + 2*|r-s| := by + have H (a b : ℝ) (ha : a ∈ Set.range z) (hb : b ∈ Set.range z) (hab : a ≤ b) : + (∑ j, heightVariances z j*|heightIndicator a (z j.succ)-heightIndicator b (z j.succ)|)= + 2*|a-b| := by + simp only [abs_of_nonneg (sub_nonneg.mpr (heightIndicator_antitone _ hab)),mul_sub, + Finset.sum_sub_distrib,heightIndicator_weighted_sum z hz a ha,heightIndicator_weighted_sum z hz b hb] + rw [abs_of_nonpos (sub_nonpos.mpr hab)] + ring + rcases le_total r s with hrs | hsr + · exact H r s hr hs hrs + · simpa only [abs_sub_comm] using H s r hs hr hsr + +lemma finiteFieldCDFLeft_coupling_sub {d e : ℕ} (w h : Fin (d+1) → ℝ) + (v g : Fin (e+1) → ℝ) (c : Fin (d+1)×Fin (e+1) → ℝ) + (hr : ∀ i, ∑ j, c (i,j)=w i) (hc : ∀ j, ∑ i, c (i,j)=v j) (t : ℝ) : + finiteFieldCDFLeft w h t-finiteFieldCDFLeft v g t= + ∑ a, c a*(heightIndicator (h a.1) t-heightIndicator (g a.2) t) := by + simp only [mul_sub,Finset.sum_sub_distrib] + rw [coupling_sum_fst c w (fun i => heightIndicator (h i) t) hr, + coupling_sum_snd c v (fun j => heightIndicator (g j) t) hc] + simp only [finiteFieldCDFLeft,heightIndicator,mul_ite,mul_one,mul_zero] + +lemma finiteFieldCDFLeft_coupling_abs {d e : ℕ} (w h : Fin (d+1) → ℝ) + (v g : Fin (e+1) → ℝ) (c : Fin (d+1)×Fin (e+1) → ℝ) + (hcn : ∀ a, 0 ≤ c a) (hr : ∀ i, ∑ j, c (i,j)=w i) (hc : ∀ j, ∑ i, c (i,j)=v j) (t : ℝ) : + |finiteFieldCDFLeft w h t-finiteFieldCDFLeft v g t| ≤ + ∑ a, c a*|heightIndicator (h a.1) t-heightIndicator (g a.2) t| := by + rw [finiteFieldCDFLeft_coupling_sub w h v g c hr hc t] + simpa only [abs_mul,abs_of_nonneg (hcn _)] using + Finset.abs_sum_le_sum_abs (fun a => c a*(heightIndicator (h a.1) t-heightIndicator (g a.2) t)) Finset.univ + +lemma finiteFieldCDFLeft_partition_cost {d e K : ℕ} (w h : Fin (d+1) → ℝ) + (v g : Fin (e+1) → ℝ) (c : Fin (d+1)×Fin (e+1) → ℝ) + (hcn : ∀ a, 0 ≤ c a) (hr : ∀ i, ∑ j, c (i,j)=w i) (hc : ∀ j, ∑ i, c (i,j)=v j) + (z : Fin (K+1) → ℝ) (hz : Monotone z) + (hm : ∀ i, h i ∈ Set.range z) (gm : ∀ j, g j ∈ Set.range z) : + (∑ j, heightVariances z j*|finiteFieldCDFLeft w h (z j.succ)-finiteFieldCDFLeft v g (z j.succ)|) ≤ + 2*(∑ a, c a*|h a.1-g a.2|) := by + calc + _ ≤ ∑ j, heightVariances z j*(∑ a, c a* + |heightIndicator (h a.1) (z j.succ)-heightIndicator (g a.2) (z j.succ)|) := by + apply Finset.sum_le_sum + intro j _ + exact mul_le_mul_of_nonneg_left (finiteFieldCDFLeft_coupling_abs w h v g c hcn hr hc _) + (heightVariances_nonneg z hz j) + _ = ∑ a, c a*(∑ j, heightVariances z j* + |heightIndicator (h a.1) (z j.succ)-heightIndicator (g a.2) (z j.succ)|) := by + simp only [Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro j _ + ring + _ = _ := by + simp only [heightIndicator_distance_sum z hz _ _ (hm _) (gm _),Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + ring + +lemma exists_common_height_partition {I J : Type*} [Fintype I] [Fintype J] + (h : I → ℝ) (g : J → ℝ) (H : ℝ) (hH : 0 ≤ H) + (hh : ∀ i, h i ∈ Icc (0:ℝ) H) (hg : ∀ j, g j ∈ Icc (0:ℝ) H) : + ∃ (K : ℕ) (z : Fin (K+1) → ℝ), Monotone z ∧ z 0=0 ∧ z (Fin.last K)=H ∧ + (∀ i, h i ∈ Set.range z) ∧ (∀ j, g j ∈ Set.range z) := by + classical + let S : Finset ℝ := insert 0 (insert H (Finset.univ.image h ∪ Finset.univ.image g)) + have hs0 : (0:ℝ) ∈ S := by simp [S] + have hsH : H ∈ S := by simp [S] + have hsb : ∀ x ∈ S, x ∈ Icc (0:ℝ) H := by + intro x hx + simp only [S,Finset.mem_insert,Finset.mem_union,Finset.mem_image,Finset.mem_univ,true_and] at hx + rcases hx with rfl | rfl | ⟨i,rfl⟩ | ⟨j,rfl⟩ + · exact ⟨le_rfl,hH⟩ + · exact ⟨hH,le_rfl⟩ + · exact hh i + · exact hg j + obtain ⟨K,hK⟩ := Nat.exists_eq_succ_of_ne_zero (Finset.card_ne_zero.mpr ⟨0,hs0⟩) + let e := S.orderIsoOfFin hK + let z : Fin (K+1) → ℝ := fun i => e i + have hz : Monotone z := fun i j hij => e.monotone hij + have hm (x : ℝ) (hx : x ∈ S) : x ∈ Set.range z := by + exact ⟨e.symm ⟨x,hx⟩,congrArg Subtype.val (e.apply_symm_apply ⟨x,hx⟩)⟩ + have hz0 : z 0=0 := by + obtain ⟨i,hi⟩ := hm 0 hs0 + apply le_antisymm + · rw [← hi]; exact hz (Fin.zero_le i) + · exact (hsb (z 0) (e 0).2).1 + have hzH : z (Fin.last K)=H := by + obtain ⟨i,hi⟩ := hm H hsH + apply le_antisymm + · exact (hsb (z (Fin.last K)) (e (Fin.last K)).2).2 + · rw [← hi]; exact hz (Fin.le_last i) + exact ⟨K,z,hz,hz0,hzH,(fun i => hm (h i) (by simp [S])),(fun j => hm (g j) (by simp [S]))⟩ + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedAncestry.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedAncestry.lean new file mode 100644 index 0000000000000000000000000000000000000000..320fcdd42bb221c92895fac2a6bbb8f2644e5148 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedAncestry.lean @@ -0,0 +1,171 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedGaussianMarks + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators + +def indexedVertexDepth : (n : ℕ) → IndexedVertex n → Fin n + | 0,v => v.elim + | n+1,v => match v.2.2 with + | .inl _ => 0 + | .inr w => (indexedVertexDepth n w).succ + +lemma indexedLeafVertex_depth (n : ℕ) (l : IndexedLeaf n) (i : Fin n) : + indexedVertexDepth n (indexedLeafVertex n l i) = i := by + induction n with + | zero => exact i.elim0 + | succ n ih => + induction i using Fin.cases with + | zero => rfl + | succ i => simpa only [indexedLeafVertex,Fin.cases_succ,indexedVertexDepth] using congrArg Fin.succ (ih l.2.2 i) + +def indexedSharedVertexDepth (n : ℕ) : SharedVertex n → Fin (n+1) + | .inl _ => 0 + | .inr v => (indexedVertexDepth n v).succ + +lemma indexedLeafSharedVertex_depth (n : ℕ) (l : IndexedLeaf n) (i : Fin (n+1)) : + indexedSharedVertexDepth n (indexedLeafSharedVertex n l i) = i := by + induction i using Fin.cases with + | zero => rfl + | succ i => simpa only [indexedLeafSharedVertex,Fin.cases_succ,indexedSharedVertexDepth] using + congrArg Fin.succ (indexedLeafVertex_depth n l i) + +def indexedCommonDepth : (n : ℕ) → IndexedLeaf n → IndexedLeaf n → Fin (n+1) + | 0,_,_ => 0 + | n+1,l,m => if l.1=m.1 ∧ l.2.1=m.2.1 then (indexedCommonDepth n l.2.2 m.2.2).succ else 0 + +lemma indexedCommonDepth_comm (n : ℕ) (l m : IndexedLeaf n) : + indexedCommonDepth n l m = indexedCommonDepth n m l := by + induction n with + | zero => rfl + | succ n ih => simp only [indexedCommonDepth,ih m.2.2 l.2.2,eq_comm] + +lemma indexedCommonDepth_self (n : ℕ) (l : IndexedLeaf n) : + indexedCommonDepth n l l = Fin.last n := by + induction n with + | zero => rfl + | succ n ih => simp [indexedCommonDepth,ih] + +lemma indexedLeafVertex_eq_iff (n : ℕ) (l m : IndexedLeaf n) (i : Fin n) : + indexedLeafVertex n l i=indexedLeafVertex n m i ↔ i.val< (indexedCommonDepth n l m).val := by + induction n with + | zero => exact i.elim0 + | succ n ih => + by_cases he : l.1=m.1 ∧ l.2.1=m.2.1 + · rcases he with ⟨h1,h2⟩ + rw [indexedCommonDepth,ite_eq_left ⟨h1,h2⟩] + induction i using Fin.cases with + | zero => simp [indexedLeafVertex,h1,h2] + | succ i => + simpa [indexedLeafVertex,h1,h2] using ih l.2.2 m.2.2 i + · rw [indexedCommonDepth,ite_eq_right he] + induction i using Fin.cases <;> simp_all [indexedLeafVertex,Prod.mk.injEq] + +lemma indexedLeafSharedVertex_eq_iff (n : ℕ) (l m : IndexedLeaf n) (i : Fin (n+1)) : + indexedLeafSharedVertex n l i=indexedLeafSharedVertex n m i ↔ i ≤ indexedCommonDepth n l m := by + induction i using Fin.cases with + | zero => simp [indexedLeafSharedVertex] + | succ i => + simpa only [indexedLeafSharedVertex,Fin.cases_succ,Sum.inr.injEq, + Fin.le_iff_val_le_val,Fin.val_succ,Nat.succ_le_iff] using indexedLeafVertex_eq_iff n l m i + +lemma indexedLeafSharedVertex_eq_iff_pair (n : ℕ) (l m : IndexedLeaf n) (i j : Fin (n+1)) : + indexedLeafSharedVertex n l i=indexedLeafSharedVertex n m j ↔ i=j ∧ i ≤ indexedCommonDepth n l m := by + constructor + · intro h + have he : i=j := by + have hh := congrArg (indexedSharedVertexDepth n) h + simpa only [indexedLeafSharedVertex_depth] using hh + subst j + exact ⟨rfl,(indexedLeafSharedVertex_eq_iff n l m i).mp h⟩ + · rintro ⟨rfl,h⟩ + exact (indexedLeafSharedVertex_eq_iff n l m i).mpr h + +variable {S : Type*} [MeasurableSpace S] + +omit [MeasurableSpace S] in +lemma maskedGaussianCoefficient_sq_prefix (v : ℕ → S → ℝ) (L : S → ℕ) (n : ℕ) (x : S) : + (∑ i : Fin n, maskedGaussianCoefficient v L i.val x^2) = + ∑ i : Fin (min n (L x)), v i.val x^2 := by + rw [Fin.sum_univ_eq_sum_range (fun i => maskedGaussianCoefficient v L i x^2) n, + Fin.sum_univ_eq_sum_range (fun i => v i x^2) (min n (L x))] + have he (i : ℕ) : maskedGaussianCoefficient v L i x^2 = if i simp + simp_rw [he] + exact sum_range_cutoff _ n (L x) + +omit [MeasurableSpace S] in +lemma maskedGaussianCoefficient_sq_bound (v : ℕ → S → ℝ) (L : S → ℕ) + {D : ℝ} (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) (n : ℕ) (x : S) : + (∑ i : Fin n, maskedGaussianCoefficient v L i.val x^2) ≤ D := by + rw [maskedGaussianCoefficient_sq_prefix] + exact (gaussianCoefficient_prefix_sq_le v L n x).trans (hD x) + +def gaussianPrefixCovariance (v w : ℕ → S → ℝ) (L : S → ℕ) (n : ℕ) (x y : S) : ℝ := + ∑ i : Fin n, maskedGaussianCoefficient w L i.val x*maskedGaussianCoefficient v L i.val y + +def countableGaussianCovariance (v w : ℕ → S → ℝ) (L : S → ℕ) (x y : S) : ℝ := + gaussianPrefixCovariance v w L (L x) x y + +lemma gaussianPrefixCovariance_measurable {v w : ℕ → S → ℝ} {L : S → ℕ} + (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) (hL : Measurable L) (n : ℕ) : + Measurable (Function.uncurry (gaussianPrefixCovariance v w L n)) := by + unfold gaussianPrefixCovariance Function.uncurry + exact Finset.measurable_sum _ fun i _ => + ((maskedGaussianCoefficient_measurable hw hL i.val).comp measurable_fst).mul + ((maskedGaussianCoefficient_measurable hv hL i.val).comp measurable_snd) + +lemma countableGaussianCovariance_measurable {v w : ℕ → S → ℝ} {L : S → ℕ} + (hv : ∀ i, Measurable (v i)) (hw : ∀ i, Measurable (w i)) (hL : Measurable L) : + Measurable (Function.uncurry (countableGaussianCovariance v w L)) := by + have hm : Measurable (fun p : ℕ×(S×S) => gaussianPrefixCovariance v w L p.1 p.2.1 p.2.2) := by + apply measurable_from_prod_countable_right + exact gaussianPrefixCovariance_measurable hv hw hL + exact hm.comp ((hL.comp measurable_fst).prodMk measurable_id) + +omit [MeasurableSpace S] in +lemma gaussianPrefixCovariance_bound (v w : ℕ → S → ℝ) (L : S → ℕ) + {D E : ℝ} (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) + (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) (n : ℕ) (x y : S) : + |gaussianPrefixCovariance v w L n x y| ≤ (D+E)/2 := by + have hi (i : Fin n) : |maskedGaussianCoefficient w L i.val x*maskedGaussianCoefficient v L i.val y| ≤ + (maskedGaussianCoefficient w L i.val x^2+maskedGaussianCoefficient v L i.val y^2)/2 := by + rw [abs_mul] + nlinarith [sq_abs (maskedGaussianCoefficient w L i.val x), + sq_abs (maskedGaussianCoefficient v L i.val y), + sq_nonneg (|maskedGaussianCoefficient w L i.val x|-|maskedGaussianCoefficient v L i.val y|)] + calc + _ ≤ ∑ i : Fin n, |maskedGaussianCoefficient w L i.val x*maskedGaussianCoefficient v L i.val y| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ i : Fin n, (maskedGaussianCoefficient w L i.val x^2+maskedGaussianCoefficient v L i.val y^2)/2 := + Finset.sum_le_sum fun i _ => hi i + _ ≤ _ := by + rw [← Finset.sum_div,Finset.sum_add_distrib] + linarith [maskedGaussianCoefficient_sq_bound v L hD n y,maskedGaussianCoefficient_sq_bound w L hE n x] + +omit [MeasurableSpace S] in +lemma gaussianPrefixCovariance_eventually_eq (v w : ℕ → S → ℝ) (L : S → ℕ) (x y : S) : + ∀ᶠ n in atTop, gaussianPrefixCovariance v w L n x y=countableGaussianCovariance v w L x y := by + filter_upwards [eventually_ge_atTop (L x)] with n hn + unfold gaussianPrefixCovariance countableGaussianCovariance + rw [Fin.sum_univ_eq_sum_range (fun i => maskedGaussianCoefficient w L i x*maskedGaussianCoefficient v L i y) n] + have he (i : ℕ) : maskedGaussianCoefficient w L i x*maskedGaussianCoefficient v L i y = + if i simp_all + simp_rw [he] + rw [sum_range_cutoff,min_eq_right hn] + unfold gaussianPrefixCovariance + rw [Fin.sum_univ_eq_sum_range (fun i => maskedGaussianCoefficient w L i x*maskedGaussianCoefficient v L i y) (L x)] + simp_rw [he,sum_range_cutoff,min_self] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedChildLaw.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedChildLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..09e88e239d1b90b284023f05695ebb30e951d4e8 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedChildLaw.lean @@ -0,0 +1,57 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.IndexedCascadeRegular + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma indexedCascadeMarks_child_law {S : Type} [MeasurableSpace S] + (ν : ProbabilityMeasure S) (n : ℕ) (i j : ℕ) : + MeasurePreserving (fun m : IndexedCascadeMarks S (n+1) => m i j) + (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))) + ((ν : Measure S).prod (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) := + (measurePreserving_eval_infinitePi (fun _ : ℕ => + (ν : Measure S).prod (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) j).comp + (measurePreserving_eval_infinitePi (fun _ : ℕ => Measure.infinitePi (fun _ : ℕ => + (ν : Measure S).prod (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))) i) + +lemma indexedCascade_joint_child_law {S : Type} [MeasurableSpace S] + (ν : ProbabilityMeasure S) (n : ℕ) (z : Fin (n+1) → ℝ) (i j : ℕ) : + MeasurePreserving (fun p : IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1) => + ((p.2 i j).1,(((p.1 i).2 j).2,(p.2 i j).2))) + ((indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))).prod + (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1)))) + ((ν : Measure S).prod ((indexedCascadeBaseLaw n (fun l => z l.succ) : + Measure (IndexedCascadeBase n)).prod (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))) := by + let B : Measure (IndexedCascadeBase n) := indexedCascadeBaseLaw n (fun l => z l.succ) + let M : Measure (IndexedCascadeMarks S n) := indexedCascadeMarksLaw ν n + have hr : MeasurePreserving (fun p : IndexedCascadeBase n×(S×IndexedCascadeMarks S n) => + (p.2.1,(p.1,p.2.2))) (B.prod ((ν : Measure S).prod M)) ((ν : Measure S).prod (B.prod M)) := + ⟨by fun_prop,prod_rotate_front B (ν : Measure S) M⟩ + exact hr.comp ((indexedCascadeBase_child_law n z i j).prod + (indexedCascadeMarks_child_law ν n i j)) + +lemma indexedCascade_ae_children {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin (n+1) → ℝ) (P : X×(IndexedCascadeBase n×IndexedCascadeMarks S n) → Prop) + (hP : MeasurableSet {p | P p}) + (h : ∀ x, ∀ᵐ p ∂(indexedCascadeBaseLaw n (fun l => z l.succ) : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)), P (x,p)) (x : X) : + ∀ᵐ p ∂(indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))).prod + (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))), ∀ i j, + P (step (x,(p.2 i j).1),(((p.1 i).2 j).2,(p.2 i j).2)) := by + have hprod : ∀ᵐ p ∂(ν : Measure S).prod + ((indexedCascadeBaseLaw n (fun l => z l.succ) : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))), P (step (x,p.1),p.2) := + (Measure.ae_prod_iff_ae_ae (hP.preimage (by fun_prop))).mpr + (ae_of_all _ fun s => h (step (x,s))) + exact ae_all_iff.mpr fun i => ae_all_iff.mpr fun j => + (indexedCascade_joint_child_law ν n z i j).quasiMeasurePreserving.ae hprod + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedDiagonalField.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedDiagonalField.lean new file mode 100644 index 0000000000000000000000000000000000000000..8f3f94153b19e905df3ffc744ab590346fc3522a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedDiagonalField.lean @@ -0,0 +1,154 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.VectorPartition +import OAI.Probability.Perceptron.Variational.FiniteGaussianRow +import OAI.Probability.Perceptron.Variational.TensorFeatures + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped BigOperators Topology NNReal ENNReal BoundedContinuousFunction + +section +variable {I : Type} [Fintype I] {S : Type} [MeasurableSpace S] + +def hierarchyRowCoefficients (n : ℕ) (root : I → ℝ) (step : ℕ → I → ℝ) : Fin (n+1) → I → ℝ := + Fin.cases root (fun d => step (n-1-d.val)) + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_diagonal_identity (n : ℕ) (root : I → ℝ) (step : ℕ → I → ℝ) + (V : S → EuclideanSpace ℝ I) (g : ℕ → ℝ) (x : S×IndexedLeaf n) : + countableGaussianField (indexedGaussianRow n (hierarchyRowCoefficients n root step) V) + (indexedGaussianRowLength (I := I) n) g x = + inner ℝ (V x.1) (indexedLeafState (gaussianLinearMarkStep (fun j => diagonalMark (step j))) n + ((fun _ => diagonalMark root (indexedGaussianDisorder n I g).1), + (indexedGaussianDisorder n I g).2) x.2 0) := by + rw [indexedGaussianRow_field] + change _ = inner ℝ (V x.1) (indexedLeafState (gaussianLinearMarkStep (fun j => diagonalMark (step j))) n + ((fun _ => diagonalMark root (countableGaussianVectors g (Sum.inl ()))), + indexedMarksFromVertices n (fun v => countableGaussianVectors g (Sum.inr v))) x.2 0) + rw [indexedLeafState_gaussianLinear,inner_add_right,inner_sum,Fin.sum_univ_succ] + simp only [Nat.zero_add,hierarchyRowCoefficients,Fin.cases_zero,Fin.cases_succ, + indexedLeafSharedVertex] + congr 1 + · simp only [PiLp.inner_apply,diagonalMark_apply,countableGaussianVectors] + apply Finset.sum_congr rfl + intro i hi + change _ = (root i * g (countableCoordinate (Sum.inl (),i))) * V x.1 i + ring + · apply Finset.sum_congr rfl + intro d hd + simp only [PiLp.inner_apply,diagonalMark_apply,countableGaussianVectors] + apply Finset.sum_congr rfl + intro i hi + change _ = (step (n-1-d.val) i * g (countableCoordinate (Sum.inr (indexedLeafVertex n x.2 d),i))) * V x.1 i + ring + +end + +section Partition +variable {E S : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + [MeasurableSpace S] (ρ : Measure S) [IsProbabilityMeasure ρ] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorLogPartition_lipschitz {W : S → ℝ} {V : S → StrongDual ℝ E} + (hWm : Measurable W) (hVm : Measurable V) {K : ℝ} {C : ℝ≥0} + (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) : + LipschitzWith C (vectorLogPartition ρ W V) := by + apply LipschitzWith.of_dist_le_mul + intro x y + simp only [dist_eq_norm,vectorLogPartition,vectorPartition] + apply abs_log_integral_exp_sub_le ρ + (vectorPartition_integrable ρ hWm hVm hW hV x) + (vectorPartition_integrable ρ hWm hVm hW hV y) + (vectorPartition_pos ρ hWm hVm hW hV x) + (vectorPartition_pos ρ hWm hVm hW hV y) + intro s + simp only [add_sub_add_left_eq_sub,← map_sub] + exact (ContinuousLinearMap.le_opNorm _ _).trans + (mul_le_mul_of_nonneg_right (hV s) (norm_nonneg _)) +end Partition + +def normalizedPatternEnergy (N M : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin N → ℝ) (x : NormalizedSpin N) : ℝ := + ∑ a, f (∑ i, g a i*x.val i) + +lemma normalizedPatternEnergy_continuous (N M : ℕ) (f : ℝ →ᵇ ℝ) : + Continuous (fun p : (Fin M → Fin N → ℝ) × NormalizedSpin N => + normalizedPatternEnergy N M f p.1 p.2) := by + unfold normalizedPatternEnergy + fun_prop + +lemma normalizedPatternEnergy_bound (N M : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin N → ℝ) (x : NormalizedSpin N) : + |normalizedPatternEnergy N M f g x| ≤ (M:ℝ)*‖f‖ := by + unfold normalizedPatternEnergy + calc + _ ≤ ∑ a : Fin M, |f (∑ i, g a i*x.val i)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _ : Fin M, ‖f‖ := Finset.sum_le_sum (fun _ _ => by + simpa only [Real.norm_eq_abs] using f.norm_coe_le_norm _) + _ = _ := by simp + +def enrichedTerminal (n M : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin (n+1) → ℝ) (p : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) + (htop : ℝ) (a : EnrichedMark (n+1) (n+1) p) : ℝ := + vectorLogPartition (unitSphereLaw (n+1)) (normalizedPatternEnergy (n+1) M f g) + (fun x => innerSL ℝ (sourceEnrichedFeature (n+1) p u x)) a - (n+1:ℕ)*htop + +def enrichedFeatureBound (N : ℕ) (u : Fin N → ℝ) : ℝ≥0 := + ⟨Real.sqrt ((N:ℝ)+∑ j, perturbationAmplitude N u j^2),Real.sqrt_nonneg _⟩ + +lemma sourceEnrichedFeature_norm (N : ℕ) (p : Fin N → ℕ) (u : Fin N → ℝ) + (x : NormalizedSpin N) : ‖sourceEnrichedFeature N p u x‖=enrichedFeatureBound N u := by + rw [sourceEnrichedFeature,enrichedFeature_norm,Real.sq_sqrt (Nat.cast_nonneg N)] + rfl + +lemma enrichedTerminal_lipschitz (n M : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin (n+1) → ℝ) (p : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) + (htop : ℝ) : LipschitzWith (enrichedFeatureBound (n+1) u) + (enrichedTerminal n M f g p u htop) := by + have hW : Continuous (normalizedPatternEnergy (n+1) M f g) := + (normalizedPatternEnergy_continuous (n+1) M f).comp + (continuous_const.prodMk continuous_id) + have hV : Continuous (fun x : NormalizedSpin (n+1) => + innerSL ℝ (sourceEnrichedFeature (n+1) p u x)) := + (innerSL ℝ).continuous.comp (enrichedFeature_continuous _ _ _ _ _) + have hL := vectorLogPartition_lipschitz (unitSphereLaw (n+1)) hW.measurable hV.measurable + (normalizedPatternEnergy_bound (n+1) M f g) + (fun x => by rw [innerSL_apply_norm,sourceEnrichedFeature_norm]) + intro x y + simpa only [enrichedTerminal,edist_sub_right] using hL x y + +def enrichedCoordinateLevel {N k : ℕ} (p d : Fin N → ℕ) + (h : Fin (k+1) → ℝ) (l : Fin (k+1)) (i : EnrichedIndex N N p) : ℝ := + match i with + | .inl _ => 2*h l + | .inr ⟨j,_⟩ => ((l.val:ℝ)/(k+1:ℕ))^(d j) + +def enrichedRootMap {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) : + EnrichedMark N N p →L[ℝ] EnrichedMark N N p := + diagonalMark (fun i => Real.sqrt (enrichedCoordinateLevel p d h 0 i)) + +def enrichedIncrementMap {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) + (j : ℕ) : EnrichedMark N N p →L[ℝ] EnrichedMark N N p := + if hj : j Real.sqrt + (enrichedCoordinateLevel p d h ⟨k-j,by omega⟩ i- + enrichedCoordinateLevel p d h ⟨k-j-1,by omega⟩ i)) else 0 + +def enrichedCascadeLog (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M → Fin (n+1) → ℝ) (p d : Fin (n+1) → ℕ) (u : Fin (n+1) → ℝ) + (h : Fin (k+1) → ℝ) + (a : EnrichedMark (n+1) (n+1) p × DecoratedCascade (EnrichedMark (n+1) (n+1) p) k) : ℝ := + let step := gaussianLinearMarkStep (enrichedIncrementMap p d h) + let H := fun x => enrichedTerminal n M f g p u (h (Fin.last k)) (x 0) + let x := fun _ => enrichedRootMap p d h a.1 + Real.log (decoratedTerminalTotal step H k (x,a.2)/ + decoratedTerminalTotal step (fun _ => 0) k (x,a.2)) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedFractionalLog.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedFractionalLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..ee5bd8d041d45c530b79550b23d1e8d261460053 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedFractionalLog.lean @@ -0,0 +1,89 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CouplingKernel + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped Topology BigOperators BoundedContinuousFunction + +lemma cavity_indexed_log_recursion_fractional {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S→X) (hs : Measurable step) + (H : X→ℝ) (hH : Measurable H) + (k : ℕ) (z : Fin k→ℝ) (hfrac : finiteCascadeFractionalIntegrable ν step H k z) (hz : StrictMono z) (hz0 : ∀ i,0 + Real.log (∫ l,Real.exp (H (indexedLeafState step k (x,p.2) l)) + ∂indexedLeafProbability k p.1))=ᵐ[B.prod M] + (fun p=>Real.log (decoratedTerminalTotal step H k (x,indexedCascadeRealize k p)/ + decoratedTerminalTotal step (fun _=>0) k (x,indexedCascadeRealize k p))) := by + filter_upwards [hb,hr] with p hp hpr + rw [indexedLeafProbability_terminal_integral ν hs hH k p.1 hp hpr p.2 x] + have hm : Measurable (fun η : DecoratedCascade S k=> + Real.log (decoratedTerminalTotal step H k (x,η)/decoratedTerminalTotal step (fun _=>0) k (x,η))) := + (((decoratedTerminalTotal_measurable ν step hs hH k z).comp (measurable_const.prodMk measurable_id)).div + ((decoratedTerminalTotal_measurable ν step hs measurable_const k z).comp + (measurable_const.prodMk measurable_id))).log + change (∫ p,Real.log (∫ l,Real.exp (H (indexedLeafState step k (x,p.2) l)) + ∂indexedLeafProbability k p.1) ∂B.prod M)=_ + rw [integral_congr_ae he,←integral_map (indexedCascadeRealize_measurable k).aemeasurable hm.aestronglyMeasurable] + change (∫ η,Real.log (decoratedTerminalTotal step H k (x,η)/ + decoratedTerminalTotal step (fun _=>0) k (x,η)) + ∂(((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + (indexedCascadeMarksLaw ν k)).map (indexedCascadeRealize k)))=_ + rw [indexedCascadeRealize_law ν k z] + exact finiteCascade_terminal_log_recursion_of_fractional ν step hs k z hz hz0 hz1 hH + hfrac x + +def indexedRootTerminalPartition {X S Y : Type} [MeasurableSpace X] [MeasurableSpace S] [MeasurableSpace Y] + (step : X×S→X) (H : X→ℝ) (root : Y→X) (k : ℕ) + (p : Y×(IndexedCascadeBase k×IndexedCascadeMarks S k)) : ℝ := + ∫ l,Real.exp (H (indexedLeafState step k (root p.1,p.2.2) l)) ∂indexedLeafProbability k p.2.1 + +lemma indexedRootTerminalPartition_measurable {X S Y : Type} [MeasurableSpace X] [MeasurableSpace S] [MeasurableSpace Y] + (step : X×S→X) (hs : Measurable step) (H : X→ℝ) (hH : Measurable H) + (root : Y→X) (hr : Measurable root) (k : ℕ) : + Measurable (indexedRootTerminalPartition step H root k) := by + let κ : Kernel (Y×(IndexedCascadeBase k×IndexedCascadeMarks S k)) (IndexedLeaf k):= + (indexedLeafKernel k).comap (fun p=>p.2.1) measurable_snd.fst + have hp : Measurable (fun p : (Y×(IndexedCascadeBase k×IndexedCascadeMarks S k))×IndexedLeaf k=> + ((root p.1.1,p.1.2.2),p.2)) := + ((hr.comp measurable_fst.fst).prodMk measurable_fst.snd.snd).prodMk measurable_snd + have h := (hH.comp ((indexedLeafState_measurable hs k).comp hp)).exp + exact (h.stronglyMeasurable.integral_kernel_prod_right (κ:=κ) + (f:=fun p l=>Real.exp (H (indexedLeafState step k (root p.1,p.2.2) l)))).measurable + +lemma indexed_root_log_fractional {X S Y : Type} [MeasurableSpace X] [MeasurableSpace S] [MeasurableSpace Y] + [Nonempty S] (ν : ProbabilityMeasure S) (ρ : Measure Y) [IsProbabilityMeasure ρ] + (step : X×S→X) (hs : Measurable step) (H : X→ℝ) (hH : Measurable H) + (root : Y→X) (k : ℕ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i,0Real.log (indexedRootTerminalPartition step H root k p)) + (ρ.prod ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod (indexedCascadeMarksLaw ν k)))) : + (∫ p,Real.log (indexedRootTerminalPartition step H root k p) + ∂ρ.prod ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod (indexedCascadeMarksLaw ν k)))= + ∫ y,finiteCascadeLogRecursion ν step k z H (root y) ∂ρ := by + rw [integral_prod _ hi] + apply integral_congr_ae + exact ae_of_all _ fun y=>cavity_indexed_log_recursion_fractional ν step hs H hH k z hfrac hz hz0 hz1 (root y) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianCovariance.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianCovariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..49d8d8a14541a03d6df6da873a20b7d26e383a05 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianCovariance.lean @@ -0,0 +1,202 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.EnrichedUniformBounds +import OAI.Probability.Perceptron.Variational.IndexedAncestry + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators + +section +variable {I : Type} [Fintype I] {S : Type} [MeasurableSpace S] + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_mask (n : ℕ) (B : Fin (n+1) → I → ℝ) + (V : S → EuclideanSpace ℝ I) (i : ℕ) (x : S×IndexedLeaf n) : + maskedGaussianCoefficient (indexedGaussianRow n B V) (indexedGaussianRowLength (I := I) n) i x = + indexedGaussianRow n B V i x := by + unfold maskedGaussianCoefficient + split_ifs with hi + · rfl + · exact (finiteGaussianRow_tail _ _ i (Nat.le_of_not_gt hi)).symm + +lemma indexedGaussianRowKey_eq (n : ℕ) (l m : IndexedLeaf n) (a b : Fin (n+1)×I) : + indexedGaussianRowKey n m b = indexedGaussianRowKey n l a ↔ + b.1=a.1 ∧ b.2=a.2 ∧ a.1 ≤ indexedCommonDepth n m l := by + rw [indexedGaussianRowKey,indexedGaussianRowKey,countableCoordinate_injective.eq_iff, + Prod.mk.injEq,indexedLeafSharedVertex_eq_iff_pair] + constructor + · rintro ⟨⟨he,hc⟩,hi⟩ + exact ⟨he,hi,he ▸ hc⟩ + · rintro ⟨he,hi,hc⟩ + exact ⟨⟨he,he.symm ▸ hc⟩,hi⟩ + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_cross_value (n : ℕ) (B : Fin (n+1) → I → ℝ) + (V : S → EuclideanSpace ℝ I) (x y : S×IndexedLeaf n) (a : Fin (n+1)×I) : + indexedGaussianRow n B V (indexedGaussianRowKey n x.2 a) y = + if a.1 ≤ indexedCommonDepth n y.2 x.2 then B a.1 a.2*V y.1 a.2 else 0 := by + classical + unfold indexedGaussianRow finiteGaussianRow + simp_rw [indexedGaussianRowKey_eq] + rw [Finset.sum_eq_single a] + · simp + · intro b hb hba + have hd : ¬ (b.1=a.1 ∧ b.2=a.2 ∧ a.1 ≤ indexedCommonDepth n y.2 x.2) := by + rintro ⟨h1,h2,_⟩ + exact hba (Prod.ext h1 h2) + simp [hd] + · simp + +omit [MeasurableSpace S] in +lemma indexedGaussianRow_covariance (n : ℕ) (B C : Fin (n+1) → I → ℝ) + (V W : S → EuclideanSpace ℝ I) (x y : S×IndexedLeaf n) : + countableGaussianCovariance (indexedGaussianRow n B V) (indexedGaussianRow n C W) + (indexedGaussianRowLength (I := I) n) x y = + ∑ i : I, (∑ j : Fin (n+1), if j ≤ indexedCommonDepth n y.2 x.2 then C j i*B j i else 0)*W x.1 i*V y.1 i := by + classical + unfold countableGaussianCovariance gaussianPrefixCovariance + simp_rw [indexedGaussianRow_mask] + change (∑ i : Fin (finiteGaussianRowLength (indexedGaussianRowKey (I := I) n x.2)), + finiteGaussianRow (indexedGaussianRowKey n x.2) (fun p => C p.1 p.2*W x.1 p.2) i.val* + indexedGaussianRow n B V i.val y) = _ + rw [finiteGaussianRow_sum (indexedGaussianRowKey_injective n x.2) _ + (fun i z => z*indexedGaussianRow n B V i y) (fun i => zero_mul _)] + simp_rw [indexedGaussianRow_cross_value] + rw [Fintype.sum_prod_type,Finset.sum_comm] + apply Finset.sum_congr rfl + intro i hi + rw [Finset.sum_mul,Finset.sum_mul] + apply Finset.sum_congr rfl + intro j hj + split_ifs <;> ring + +end + +lemma finite_profile_prefix {k : ℕ} (q : Fin (k+1) → ℝ) (a : Fin (k+1)) : + q 0 + ∑ j : Fin k, (if j.succ ≤ a then q j.succ-q j.castSucc else 0) = q a := by + have he (j : Fin k) : (if j.succ ≤ a then q j.succ-q j.castSucc else 0) = + q (min j.succ a)-q (min j.castSucc a) := by + by_cases hj : j.succ ≤ a + · rw [ite_eq_left hj,min_eq_left hj,min_eq_left ((Fin.castSucc_le_succ j).trans hj)] + · have hc : a ≤ j.castSucc := by + simp only [Fin.le_iff_val_le_val,Fin.val_castSucc,Fin.val_succ] at * + omega + rw [ite_eq_right hj,min_eq_right (le_of_not_ge hj),min_eq_right hc,sub_self] + simp_rw [he] + simpa only [min_eq_left (Fin.zero_le a),min_eq_right (Fin.le_last a)] using + finite_profile_telescope (fun l => q (min l a)) + +lemma profileGaussian_coefficient_prefix {I : Type} {k : ℕ} (q : Fin (k+1) → I → ℝ) + (h0 : ∀ i, 0 ≤ q 0 i) (hq : ∀ i, Monotone (fun l => q l i)) (a : Fin (k+1)) (i : I) : + (∑ l : Fin (k+1), if l ≤ a then + hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q) l i^2 else 0) = q a i := by + rw [profileGaussian_coefficient,Fin.sum_univ_succ] + simp only [Fin.cases_zero,Fin.cases_succ,Fin.zero_le,ite_true,Real.sq_sqrt (h0 i)] + have he (j : Fin k) : (Real.sqrt (q j.succ i-q j.castSucc i))^2 = q j.succ i-q j.castSucc i := + Real.sq_sqrt (sub_nonneg.mpr (hq i (Fin.castSucc_le_succ j))) + simp_rw [he] + exact finite_profile_prefix (fun l => q l i) a + +lemma profileGaussianRow_covariance {I S : Type} [Fintype I] [MeasurableSpace S] + {k : ℕ} (q : Fin (k+1) → I → ℝ) (h0 : ∀ i, 0 ≤ q 0 i) + (hq : ∀ i, Monotone (fun l => q l i)) (V W : S → EuclideanSpace ℝ I) + (x y : S×IndexedLeaf k) : + countableGaussianCovariance + (indexedGaussianRow k (hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q)) V) + (indexedGaussianRow k (hierarchyRowCoefficients k (profileGaussianRoot q) (profileGaussianStep q)) W) + (indexedGaussianRowLength (I := I) k) x y = + ∑ i : I, q (indexedCommonDepth k y.2 x.2) i*W x.1 i*V y.1 i := by + rw [indexedGaussianRow_covariance] + simp_rw [← sq,profileGaussian_coefficient_prefix q h0 hq] + +lemma enrichedFeature_profile_cross {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) + (l : Fin (k+1)) (a b : ℝ) (c e : Fin N → ℝ) (x y : NormalizedSpin N) : + (∑ i : EnrichedIndex N N p, enrichedCoordinateLevel p d h l i* + enrichedFeature N N p a c x i*enrichedFeature N N p b e y i) = + 2*h l*a*b*spinOverlap x y+ + ∑ j, (((l.val:ℝ)/(k+1:ℕ))^(d j))*c j*e j*spinOverlap x y^(p j) := by + rw [Fintype.sum_sum_type,Fintype.sum_sigma] + have hlin : (∑ i : Fin N, enrichedCoordinateLevel p d h l (.inl i)* + enrichedFeature N N p a c x (.inl i)*enrichedFeature N N p b e y (.inl i)) = + 2*h l*a*b*spinOverlap x y := by + change (∑ i : Fin N, 2*h l*(a*x.val i)*(b*y.val i)) = + 2*h l*a*b*(∑ i : Fin N, y.val i*x.val i) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + ring + rw [hlin] + congr 1 + apply Finset.sum_congr rfl + intro j hj + rw [← spinTensorFeature_inner N (p j) x y] + change (∑ t : SpinTensorIndex N (p j), (((l.val:ℝ)/(k+1:ℕ))^(d j))* + (c j*spinTensorFeature N (p j) x t)*(e j*spinTensorFeature N (p j) y t)) = + (((l.val:ℝ)/(k+1:ℕ))^(d j))*c j*e j* + (∑ t : SpinTensorIndex N (p j), spinTensorFeature N (p j) y t*spinTensorFeature N (p j) x t) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + ring + +lemma sourceGaussianRow_covariance {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin N → ℝ) + (x y : NormalizedSpin N×IndexedLeaf k) : + countableGaussianCovariance (sourceGaussianRow p d h u) (sourceGaussianRow p d h u) + (indexedGaussianRowLength (I := EnrichedIndex N N p) k) x y = + 2*(N:ℝ)*h (indexedCommonDepth k y.2 x.2)*spinOverlap x.1 y.1+ + ∑ j, perturbationAmplitude N u j^2* + (((indexedCommonDepth k y.2 x.2).val:ℝ)/(k+1:ℕ))^(d j)*spinOverlap x.1 y.1^(p j) := by + unfold sourceGaussianRow + rw [profileGaussianRow_covariance _ (enrichedCoordinateLevel_nonneg p d hh0 0) + (enrichedCoordinateLevel_monotone p d hh)] + unfold sourceEnrichedFeature + rw [enrichedFeature_profile_cross] + have hl : 2*h (indexedCommonDepth k y.2 x.2)*Real.sqrt (N:ℝ)*Real.sqrt (N:ℝ)*spinOverlap x.1 y.1 = + 2*(N:ℝ)*h (indexedCommonDepth k y.2 x.2)*spinOverlap x.1 y.1 := by + calc + _ = 2*h (indexedCommonDepth k y.2 x.2)*(Real.sqrt (N:ℝ))^2*spinOverlap x.1 y.1 := by ring + _ = _ := by rw [Real.sq_sqrt (Nat.cast_nonneg N)]; ring + rw [hl] + congr 1 + apply Finset.sum_congr rfl + intro i hi + ring + +def sourceGaussianTestFeature (N : ℕ) (p : Fin N → ℕ) (j : Fin N) : + NormalizedSpin N → EnrichedMark N N p := enrichedFeature N N p 0 (Pi.single j 1) + +def sourceGaussianTestRow {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) (j : Fin N) : + ℕ → NormalizedSpin N×IndexedLeaf k → ℝ := + indexedGaussianRow k (hierarchyRowCoefficients k + (profileGaussianRoot (enrichedCoordinateLevel p d h)) + (profileGaussianStep (enrichedCoordinateLevel p d h))) (sourceGaussianTestFeature N p j) + +lemma sourceGaussianRow_test_covariance {N k : ℕ} (p d : Fin N → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin N → ℝ) (j : Fin N) + (x y : NormalizedSpin N×IndexedLeaf k) : + countableGaussianCovariance (sourceGaussianRow p d h u) (sourceGaussianTestRow p d h j) + (indexedGaussianRowLength (I := EnrichedIndex N N p) k) x y = + perturbationAmplitude N u j* + (((indexedCommonDepth k y.2 x.2).val:ℝ)/(k+1:ℕ))^(d j)*spinOverlap x.1 y.1^(p j) := by + unfold sourceGaussianRow sourceGaussianTestRow + rw [profileGaussianRow_covariance _ (enrichedCoordinateLevel_nonneg p d hh0 0) + (enrichedCoordinateLevel_monotone p d hh)] + unfold sourceEnrichedFeature sourceGaussianTestFeature + rw [enrichedFeature_profile_cross] + simp only [mul_zero,zero_mul,zero_add] + rw [Finset.sum_eq_single j] + · simp only [Pi.single_eq_same,mul_one] + ring + · intro i hi hij + simp [Pi.single_eq_of_ne hij] + · simp + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianCovarianceLaw.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianCovarianceLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..a72a5c37d2764f8c82079cb0182de9bbea14282f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianCovarianceLaw.lean @@ -0,0 +1,180 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianComparison + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +section +variable {I : Type} [Fintype I] [DecidableEq I] + +def doubledGaussianRows (B C : I → ℝ) (i : I) : EuclideanSpace ℝ (I ⊕ I) := + B i • EuclideanSpace.basisFun (I ⊕ I) ℝ (Sum.inl i) + + C i • EuclideanSpace.basisFun (I ⊕ I) ℝ (Sum.inr i) + +def diagonalGaussianRows (D : I → ℝ) (i : I) : EuclideanSpace ℝ I := + D i • EuclideanSpace.basisFun I ℝ i + +lemma doubledGaussianRows_gram (B C D : I → ℝ) (h : ∀ i, D i^2=B i^2+C i^2) : + Matrix.gram ℝ (doubledGaussianRows B C) = Matrix.gram ℝ (diagonalGaussianRows D) := by + ext i j + change inner ℝ (doubledGaussianRows B C i) (doubledGaussianRows B C j) = + inner ℝ (diagonalGaussianRows D i) (diagonalGaussianRows D j) + simp only [doubledGaussianRows,diagonalGaussianRows,inner_add_left,inner_add_right, + real_inner_smul_left,real_inner_smul_right,EuclideanSpace.basisFun_inner] + by_cases hij : i=j + · subst j; simp [← sq,h] + · simp [hij] + +lemma doubledGaussianRows_law (B C D : I → ℝ) (h : ∀ i, D i^2=B i^2+C i^2) : + (stdGaussian (EuclideanSpace ℝ (I ⊕ I))).map (gaussianRows (doubledGaussianRows B C)) = + (stdGaussian (EuclideanSpace ℝ I)).map (gaussianRows (diagonalGaussianRows D)) := by + rw [gaussianRows_map_stdGaussian,gaussianRows_map_stdGaussian,doubledGaussianRows_gram B C D h] + +omit [DecidableEq I] in +lemma doubledGaussianRows_apply (B C : I → ℝ) (g : EuclideanSpace ℝ (I ⊕ I)) (i : I) : + gaussianRows (doubledGaussianRows B C) g i = B i*g (Sum.inl i)+C i*g (Sum.inr i) := by + simp only [gaussianRows_apply,doubledGaussianRows,inner_add_left,real_inner_smul_left, + EuclideanSpace.basisFun_inner] + +omit [DecidableEq I] in +lemma diagonalGaussianRows_apply (D : I → ℝ) (g : EuclideanSpace ℝ I) (i : I) : + gaussianRows (diagonalGaussianRows D) g i = D i*g i := by + simp only [gaussianRows_apply,diagonalGaussianRows,real_inner_smul_left,EuclideanSpace.basisFun_inner] + +end +variable {V I : Type} [Countable V] [Fintype I] [DecidableEq I] + +theorem countableGaussian_covariance_addition_law (B C D : V → I → ℝ) + (h : ∀ v i, D v i^2=B v i^2+C v i^2) : + countableGaussianLaw.map (fun g v => gaussianRows (doubledGaussianRows (B v) (C v)) + (countableGaussianVectors (I := I ⊕ I) g v)) = + countableGaussianLaw.map (fun g v => gaussianRows (diagonalGaussianRows (D v)) + (countableGaussianVectors (I := I) g v)) := by + have hm : Measurable (fun f : V → EuclideanSpace ℝ (I ⊕ I) => fun v => + gaussianRows (doubledGaussianRows (B v) (C v)) (f v)) := by fun_prop + have hn : Measurable (fun f : V → EuclideanSpace ℝ I => fun v => + gaussianRows (diagonalGaussianRows (D v)) (f v)) := by fun_prop + rw [show (fun g v => gaussianRows (doubledGaussianRows (B v) (C v)) (countableGaussianVectors g v)) = + (fun f v => gaussianRows (doubledGaussianRows (B v) (C v)) (f v)) ∘ countableGaussianVectors from rfl, + ← Measure.map_map hm countableGaussianVectors_measurable,countableGaussianVectors_law, + Measure.infinitePi_map_pi _ (fun v => (gaussianRows (doubledGaussianRows (B v) (C v))).measurable)] + rw [show (fun g v => gaussianRows (diagonalGaussianRows (D v)) (countableGaussianVectors g v)) = + (fun f v => gaussianRows (diagonalGaussianRows (D v)) (f v)) ∘ countableGaussianVectors from rfl, + ← Measure.map_map hn countableGaussianVectors_measurable,countableGaussianVectors_law, + Measure.infinitePi_map_pi _ (fun v => (gaussianRows (diagonalGaussianRows (D v))).measurable)] + congr 1 + funext v + exact doubledGaussianRows_law (B v) (C v) (D v) (h v) + +variable {S : Type} [MeasurableSpace S] +variable (n : ℕ) + +def sharedMarksHamiltonian (W : S×IndexedLeaf n→ℝ) (V : S→EuclideanSpace ℝ I) + (g : SharedVertex n→EuclideanSpace ℝ I) (x : S×IndexedLeaf n) : ℝ := + W x + ∑ l : Fin (n+1), ∑ i : I, g (indexedLeafSharedVertex n x.2 l) i * V x.1 i + +omit [DecidableEq I] in +lemma sharedMarksHamiltonian_measurable {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) : + Measurable (Function.uncurry (sharedMarksHamiltonian n W V)) := by + unfold Function.uncurry sharedMarksHamiltonian + apply (hW.comp measurable_snd).add + apply Finset.measurable_sum + intro l hl + apply Finset.measurable_sum + intro i hi + have he : Measurable (fun q : (SharedVertex n→EuclideanSpace ℝ I)×IndexedLeaf n => + q.1 (indexedLeafSharedVertex n q.2 l) i) := by + apply measurable_from_prod_countable_left + intro leaf + exact (EuclideanSpace.proj (𝕜 := ℝ) i).measurable.comp (measurable_pi_apply (indexedLeafSharedVertex n leaf l)) + exact (he.comp (measurable_fst.prodMk (measurable_snd.comp measurable_snd))).mul + ((EuclideanSpace.proj i).measurable.comp (hV.comp (measurable_fst.comp measurable_snd))) + +omit [MeasurableSpace S] [DecidableEq I] in +lemma sharedMarks_diagonal_eq (W : S×IndexedLeaf n→ℝ) (V : S→EuclideanSpace ℝ I) + (B : Fin (n+1)→I→ℝ) (g : ℕ→ℝ) (x : S×IndexedLeaf n) : + sharedMarksHamiltonian n W V (fun v => gaussianRows (diagonalGaussianRows (B (indexedSharedVertexDepth n v))) + (countableGaussianVectors g v)) x = + countableGaussianHamiltonian W (indexedGaussianRow n B V) (indexedGaussianRowLength (I := I) n) g x := by + rw [countableGaussianHamiltonian,indexedGaussianRow_field] + unfold sharedMarksHamiltonian + simp only [indexedLeafSharedVertex_depth,diagonalGaussianRows_apply,countableGaussianVectors] + congr 1 + apply Finset.sum_congr rfl + intro l hl + apply Finset.sum_congr rfl + intro i hi + ring + +omit [MeasurableSpace S] [DecidableEq I] in +lemma sharedMarks_doubled_eq (W : S×IndexedLeaf n→ℝ) (V : S→EuclideanSpace ℝ I) + (B C : Fin (n+1)→I→ℝ) (g : ℕ→ℝ) (x : S×IndexedLeaf n) : + sharedMarksHamiltonian n W V (fun v => gaussianRows (doubledGaussianRows + (B (indexedSharedVertexDepth n v)) (C (indexedSharedVertexDepth n v))) + (countableGaussianVectors g v)) x = + countableGaussianHamiltonian W (indexedGaussianRow n (fun l => Sum.elim (B l) (C l)) + (fun s => WithLp.toLp 2 (Sum.elim (fun i => V s i) (fun i => V s i)))) + (indexedGaussianRowLength (I := I ⊕ I) n) g x := by + rw [countableGaussianHamiltonian,indexedGaussianRow_field] + unfold sharedMarksHamiltonian + simp only [indexedLeafSharedVertex_depth,doubledGaussianRows_apply,countableGaussianVectors] + congr 1 + apply Finset.sum_congr rfl + intro l hl + rw [Fintype.sum_sum_type,← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i hi + simp only [Sum.elim_inl,Sum.elim_inr] + ring + +theorem indexedGaussianMean_covariance_addition (μ : Measure (S×IndexedLeaf n)) [IsFiniteMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) (B C D : Fin (n+1)→I→ℝ) + (h : ∀ l i, D l i^2=B l i^2+C l i^2) : + indexedGaussianMean n μ W V D = indexedGaussianMean n μ W + (fun s => WithLp.toLp 2 (Sum.elim (fun i => V s i) (fun i => V s i))) + (fun l => Sum.elim (B l) (C l)) := by + let F := fun g : SharedVertex n→EuclideanSpace ℝ I => + Real.log (tiltPartition μ (sharedMarksHamiltonian n W V g) 1) + have hF : Measurable F := by + exact (kernel_tiltPartition_measurable (Kernel.const _ μ) + (sharedMarksHamiltonian_measurable n hW hV)).log + let b := fun g v => gaussianRows (doubledGaussianRows (B (indexedSharedVertexDepth n v)) (C (indexedSharedVertexDepth n v))) + (countableGaussianVectors g v) + let d := fun g v => gaussianRows (diagonalGaussianRows (D (indexedSharedVertexDepth n v))) + (countableGaussianVectors g v) + have hb : Measurable b := by + apply Measurable.of_eval + intro v + exact (gaussianRows (doubledGaussianRows (B (indexedSharedVertexDepth n v)) (C (indexedSharedVertexDepth n v)))).measurable.comp ((measurable_pi_apply v).comp countableGaussianVectors_measurable) + have hd : Measurable d := by + apply Measurable.of_eval + intro v + exact (gaussianRows (diagonalGaussianRows (D (indexedSharedVertexDepth n v)))).measurable.comp ((measurable_pi_apply v).comp countableGaussianVectors_measurable) + have he := countableGaussian_covariance_addition_law + (fun v => B (indexedSharedVertexDepth n v)) (fun v => C (indexedSharedVertexDepth n v)) + (fun v => D (indexedSharedVertexDepth n v)) (fun v => h (indexedSharedVertexDepth n v)) + have hi : (∫ g, F (d g) ∂countableGaussianLaw) = ∫ g, F (b g) ∂countableGaussianLaw := by + rw [← integral_map hd.aemeasurable hF.aestronglyMeasurable, + ← integral_map hb.aemeasurable hF.aestronglyMeasurable,he] + have hf (g) : sharedMarksHamiltonian n W V (d g) = + countableGaussianHamiltonian W (indexedGaussianRow n D V) (indexedGaussianRowLength (I := I) n) g := + funext (sharedMarks_diagonal_eq n W V D g) + have hg (g) : sharedMarksHamiltonian n W V (b g) = + countableGaussianHamiltonian W (indexedGaussianRow n (fun l => Sum.elim (B l) (C l)) + (fun s => WithLp.toLp 2 (Sum.elim (fun i => V s i) (fun i => V s i)))) + (indexedGaussianRowLength (I := I ⊕ I) n) g := + funext (sharedMarks_doubled_eq n W V B C g) + unfold indexedGaussianMean + change _ = _ at hi + simp only [F,hf,hg] at hi + exact hi + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianMarks.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianMarks.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d6c751ae6cc8f13ac11b2c2326cff4881b9a7ae --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedGaussianMarks.lean @@ -0,0 +1,133 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.IndexedVertices +import OAI.Probability.Perceptron.Brownian.CountableGaussianField +import OAI.Probability.Perceptron.Variational.GaussianMarkRecursion + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +def countableCoordinate {ι : Type*} [Countable ι] (i : ι) : ℕ := + @Encodable.encode ι (Encodable.ofCountable ι) i + +lemma countableCoordinate_injective {ι : Type*} [Countable ι] : + Function.Injective (countableCoordinate (ι := ι)) := by + let := Encodable.ofCountable ι + exact Encodable.encode_injective + +section +variable {V I : Type} [Countable V] [Fintype I] + +def countableGaussianVectors (g : ℕ → ℝ) (v : V) : EuclideanSpace ℝ I := + WithLp.toLp 2 (fun i => g (countableCoordinate (v,i))) + +lemma countableGaussianVectors_measurable : Measurable (countableGaussianVectors (V := V) (I := I)) := by + apply Measurable.of_eval + intro v + apply (PiLp.continuous_toLp 2 _).measurable.comp + fun_prop + +lemma countableGaussianVectors_law : + countableGaussianLaw.map (countableGaussianVectors (V := V) (I := I)) = + Measure.infinitePi (fun _ : V => stdGaussian (EuclideanSpace ℝ I)) := by + let c : (ℕ → ℝ) → V×I → ℝ := fun g p => g (countableCoordinate p) + have hc : Measurable c := by fun_prop + have hl : countableGaussianLaw.map c = Measure.infinitePi (fun _ : V×I => gaussianReal 0 1) := + Measure.map_infinitePi_infinitePi_of_inj countableCoordinate_injective + let e := MeasurableEquiv.curry V I ℝ + have he : countableGaussianVectors (V := V) (I := I) = + ((fun f v => WithLp.toLp 2 (f v)) ∘ e) ∘ c := rfl + have hm : Measurable (fun f : V → I → ℝ => fun v => WithLp.toLp 2 (f v)) := by fun_prop + rw [he,← Measure.map_map (hm.comp e.measurable) hc,hl, + ← Measure.map_map hm e.measurable] + rw [show e = MeasurableEquiv.curry V I ℝ from rfl,Measure.infinitePi_map_curry (fun _ _ => gaussianReal 0 1), + Measure.infinitePi_map_pi _ (fun _ => (PiLp.continuous_toLp 2 _).measurable)] + simp only [Measure.infinitePi_eq_pi,map_pi_eq_stdGaussian] + +end + +abbrev SharedVertex (n : ℕ) := Unit ⊕ IndexedVertex n + +def indexedGaussianDisorder (n : ℕ) (I : Type) [Fintype I] (g : ℕ → ℝ) : + EuclideanSpace ℝ I × IndexedCascadeMarks (EuclideanSpace ℝ I) n := + (countableGaussianVectors (V := SharedVertex n) (I := I) g (Sum.inl ()), + indexedMarksFromVertices n (fun v => countableGaussianVectors (V := SharedVertex n) (I := I) g (Sum.inr v))) + +lemma indexedGaussianDisorder_measurable (n : ℕ) (I : Type) [Fintype I] : + Measurable (indexedGaussianDisorder n I) := by + exact ((measurable_pi_apply (Sum.inl ())).comp (countableGaussianVectors_measurable (V := SharedVertex n) (I := I))).prodMk + ((indexedMarksFromVertices_measurable n).comp + ((Measurable.of_eval fun vertex => measurable_pi_apply (Sum.inr vertex)).comp + (countableGaussianVectors_measurable (V := SharedVertex n) (I := I)))) + +lemma indexedGaussianDisorder_law (n : ℕ) (I : Type) [Fintype I] : + countableGaussianLaw.map (indexedGaussianDisorder n I) = + (stdGaussian (EuclideanSpace ℝ I)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ I)) n) := by + let E := EuclideanSpace ℝ I + let e := MeasurableEquiv.sumPiEquivProdPi (fun _ : SharedVertex n => E) + let a := Prod.map (fun f : Unit → E => f ()) (indexedMarksFromVertices (S := E) n) + have ha : Measurable a := (measurable_pi_apply ()).prodMap (indexedMarksFromVertices_measurable n) + have he : indexedGaussianDisorder n I = (a ∘ e) ∘ countableGaussianVectors (V := SharedVertex n) (I := I) := rfl + rw [he,← Measure.map_map (ha.comp e.measurable) countableGaussianVectors_measurable, + countableGaussianVectors_law,← Measure.map_map ha e.measurable,infinitePi_sumPiEquivProdPi] + rw [← Measure.map_prod_map _ _ (measurable_pi_apply ()) (indexedMarksFromVertices_measurable n), + Measure.infinitePi_map_eval] + exact congrArg (Measure.prod (stdGaussian E)) (indexedMarksFromVertices_law (gaussianMarkLaw (E := E)) n) + +section +variable {E : Type} [NormedAddCommGroup E] [NormedSpace ℝ E] [CompleteSpace E] + [SecondCountableTopology E] [MeasurableSpace E] [BorelSpace E] + +omit [CompleteSpace E] [SecondCountableTopology E] [BorelSpace E] in +lemma indexedLeafState_gaussianLinear (A : ℕ → E →L[ℝ] E) (n : ℕ) + (x : ℕ → E) (f : IndexedVertex n → E) (l : IndexedLeaf n) (j : ℕ) : + indexedLeafState (gaussianLinearMarkStep A) n (x,indexedMarksFromVertices n f) l j = + x (j+n) + ∑ i : Fin n, A (j+n-1-i.val) (f (indexedLeafVertex n l i)) := by + induction n generalizing x j with + | zero => simp [indexedLeafState] + | succ n ih => + change indexedLeafState (gaussianLinearMarkStep A) n + (gaussianLinearMarkStep A (x,f (l.1,l.2.1,Sum.inl ())), + indexedMarksFromVertices n (fun v => f (l.1,l.2.1,Sum.inr v))) l.2.2 j = _ + rw [ih,Fin.sum_univ_succ] + simp only [gaussianLinearMarkStep,indexedLeafVertex,Fin.cases_zero,Fin.cases_succ, + Fin.val_zero,Fin.val_succ,Nat.sub_zero] + rw [show j+(n+1)-1 = j+n by omega] + have he : (∑ i : Fin n, A (j+n-1-i.val) (f (l.1,l.2.1,Sum.inr (indexedLeafVertex n l.2.2 i)))) = + ∑ i : Fin n, A (j+n-(i.val+1)) (f (l.1,l.2.1,Sum.inr (indexedLeafVertex n l.2.2 i))) := by + apply Finset.sum_congr rfl + intro i hi + congr 2 + omega + rw [he] + simp only [add_assoc] + +end + +def indexedLeafSharedVertex (n : ℕ) (l : IndexedLeaf n) : Fin (n+1) → SharedVertex n := + Fin.cases (Sum.inl ()) (fun i => Sum.inr (indexedLeafVertex n l i)) + +lemma indexedLeafSharedVertex_injective (n : ℕ) (l : IndexedLeaf n) : + Function.Injective (indexedLeafSharedVertex n l) := by + intro i j hij + induction i using Fin.cases with + | zero => + induction j using Fin.cases with + | zero => rfl + | succ j => simp [indexedLeafSharedVertex] at hij + | succ i => + induction j using Fin.cases with + | zero => simp [indexedLeafSharedVertex] at hij + | succ j => + simpa only [Fin.succ_inj] using indexedLeafVertex_injective n l + (by simpa [indexedLeafSharedVertex] using hij) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedLeafTotal.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedLeafTotal.lean new file mode 100644 index 0000000000000000000000000000000000000000..ffe34fc0dd7c57264166f76026d7d53212ac5530 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedLeafTotal.lean @@ -0,0 +1,123 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.DecoratedWeightedTotal +import OAI.Probability.Perceptron.Cascade.IndexedCascadeRegular + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +lemma decoratedTerminalTotalE_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) {step : X×S → X} (hs : Measurable step) {H : X → ℝ} + (hH : Measurable H) (n : ℕ) : Measurable (decoratedTerminalTotalE step H n) := by + have he : decoratedTerminalTotalE step H n = fun p => + ENNReal.ofReal (Real.exp (finiteCascadeLogRecursion ν step n (fun _ => 0) H p.1)) * + decoratedWeightedTotalE step n (finiteCascadeShifts ν step n (fun _ => 0) H) p := by + funext p + exact decoratedTerminalTotalE_telescoping ν step H n (fun _ => 0) p + rw [he] + exact (((finiteCascadeLogRecursion_measurable ν step hs n _ hH).comp measurable_fst).exp.ennreal_ofReal).mul + (decoratedWeightedTotalE_measurable step hs n _ (finiteCascadeShifts_measurable ν step hs n _ hH)) + +lemma indexedLeafMeasure_terminal_identity {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) {step : X×S → X} (hs : Measurable step) {H : X → ℝ} + (hH : Measurable H) (n : ℕ) (b : IndexedCascadeBase n) (hb : IndexedCascadeGood n b) + (m : IndexedCascadeMarks S n) (x : X) : + decoratedTerminalTotalE step H n (x,indexedCascadeRealize n (b,m)) = + ∫⁻ l, ENNReal.ofReal (Real.exp (H (indexedLeafState step n (x,m) l))) ∂indexedLeafMeasure n b := by + induction n generalizing x with + | zero => + rw [indexedLeafMeasure_lintegral] + simp [decoratedTerminalTotalE,indexedLeafWeight,indexedLeafState,IndexedLeaf] + | succ n ih => + rw [decoratedTerminalTotalE,indexedCascadeGood_countKernel hb] + unfold indexedCascadeRealize + dsimp only [Prod.fst,Prod.snd] + have hm : Measurable (fun q : ℝ×(S×DecoratedCascade S n) => ENNReal.ofReal (Real.exp q.1) * + decoratedTerminalTotalE step H n (step (x,q.2.1),q.2.2)) := + (measurable_fst.exp.ennreal_ofReal).mul + ((decoratedTerminalTotalE_measurable ν hs hH n).comp (by fun_prop)) + rw [indexedPoissonMeasure_lintegral _ hm, + indexedLeafMeasure_lintegral_succ] + apply tsum_congr + intro i + apply Finset.sum_congr rfl + intro j hj + congr 1 + exact ih (((b i).2 j.val).2) (hb.2 i j.val) (m i j.val).2 (step (x,(m i j.val).1)) + +lemma indexedLeafMeasure_regular (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) : + ∀ᵐ b ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)), + 0 < ((indexedLeafMeasure n b) univ).toReal := by + let ν : ProbabilityMeasure Unit := ⟨Measure.dirac (),inferInstance⟩ + let step : Unit×Unit → Unit := fun _ => () + have hs : Measurable step := measurable_const + let B := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)) + let M := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks Unit n)) + let D := (decoratedCascadeLaw ν n z : Measure (DecoratedCascade Unit n)) + have hi := decoratedWeightedTotal_identDistrib ν step hs n z hz0 hz1 (fun _ _ => 0) + (fun _ => measurable_const) (by intro i x; simp only [mul_zero,Real.exp_zero]; exact integrable_const 1) + (by intro i x; simp) () + have hp := hi.symm.ae_snd measurableSet_Ioi (cascadeTotal_regular n z hz hz0 hz1).1 + have hR : MeasurePreserving (indexedCascadeRealize (S := Unit) n) (B.prod M) D := + ⟨indexedCascadeRealize_measurable n,indexedCascadeRealize_law ν n z⟩ + have ht := hR.quasiMeasurePreserving.ae hp + have hg : ∀ᵐ p ∂B.prod M, IndexedCascadeGood n p.1 := + (measurePreserving_fst (μ := B) (ν := M)).quasiMeasurePreserving.ae (indexedCascadeGood_ae n z hz0 hz1) + have he : ∀ᵐ p ∂B.prod M, 0 < ((indexedLeafMeasure n p.1) univ).toReal := by + filter_upwards [ht,hg] with p hp hg + have h := indexedLeafMeasure_terminal_identity ν hs (H := fun _ => 0) measurable_const n p.1 hg p.2 () + simp only [decoratedTerminalTotalE_zero,Real.exp_zero,ENNReal.ofReal_one,lintegral_one] at h + change 0 < (decoratedWeightedTotalE step n (fun _ _ => 0) ((),indexedCascadeRealize n p)).toReal at hp + rwa [← h] + exact (Measure.ae_ae_of_ae_prod he).mono fun b hb => hb.exists.choose_spec + +def indexedLeafProbability (n : ℕ) (b : IndexedCascadeBase n) : Measure (IndexedLeaf n) := + if 0 < ((indexedLeafMeasure n b) univ).toReal then + ((indexedLeafMeasure n b) univ)⁻¹ • indexedLeafMeasure n b + else Measure.dirac (Classical.choice (indexedLeaf_nonempty n)) + +instance indexedLeafProbability_isProbability (n : ℕ) (b : IndexedCascadeBase n) : + IsProbabilityMeasure (indexedLeafProbability n b) := by + constructor + by_cases h : 0 < ((indexedLeafMeasure n b) univ).toReal + · rw [indexedLeafProbability,ite_eq_left h,Measure.smul_apply,smul_eq_mul] + exact ENNReal.inv_mul_cancel (ENNReal.toReal_pos_iff.mp h).1.ne' + (ENNReal.toReal_pos_iff.mp h).2.ne + · simp [indexedLeafProbability,h] + +lemma indexedLeafProbability_measurable (n : ℕ) : Measurable (indexedLeafProbability n) := by + have hm := indexedLeafMeasure_measurable n + have ht : Measurable (fun b => (indexedLeafMeasure n b) univ) := + (Measure.measurable_coe MeasurableSet.univ).comp hm + apply Measurable.ite (measurableSet_lt measurable_const ht.ennreal_toReal) + · apply Measure.measurable_of_measurable_coe + intro s hs + simp only [Measure.smul_apply,smul_eq_mul] + exact ht.inv.mul ((Measure.measurable_coe hs).comp hm) + · exact measurable_const + +lemma indexedLeafProbability_lintegral (n : ℕ) (b : IndexedCascadeBase n) + (hb : 0 < ((indexedLeafMeasure n b) univ).toReal) (f : IndexedLeaf n → ℝ≥0∞) : + (∫⁻ l, f l ∂indexedLeafProbability n b) = + ((indexedLeafMeasure n b) univ)⁻¹ * ∫⁻ l, f l ∂indexedLeafMeasure n b := by + rw [indexedLeafProbability,ite_eq_left hb,lintegral_smul_measure,smul_eq_mul] + +lemma indexedLeafProbability_terminal_identity {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) {step : X×S → X} (hs : Measurable step) {H : X → ℝ} + (hH : Measurable H) (n : ℕ) (b : IndexedCascadeBase n) (hb : IndexedCascadeGood n b) + (hb' : 0 < ((indexedLeafMeasure n b) univ).toReal) + (m : IndexedCascadeMarks S n) (x : X) : + (∫⁻ l, ENNReal.ofReal (Real.exp (H (indexedLeafState step n (x,m) l))) ∂indexedLeafProbability n b) = + ((indexedLeafMeasure n b) univ)⁻¹ * + decoratedTerminalTotalE step H n (x,indexedCascadeRealize n (b,m)) := by + rw [indexedLeafProbability_lintegral n b hb',indexedLeafMeasure_terminal_identity ν hs hH n b hb] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedMarkProduct.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedMarkProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..6ffdd4bd66b380ef2c6310a2e865cbebe5c7aec1 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedMarkProduct.lean @@ -0,0 +1,130 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CouplingKernel +import OAI.Probability.Perceptron.Cavity.IndexedFreshTilt + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal +namespace SphericalPerceptronFreeEnergy + +section +variable {S T : Type} [MeasurableSpace S] [MeasurableSpace T] + +def indexedMarksZip : (n : ℕ) → IndexedCascadeMarks S n × IndexedCascadeMarks T n → + IndexedCascadeMarks (S×T) n + | 0, _ => () + | n+1, p => fun i j => (((p.1 i j).1,(p.2 i j).1), + indexedMarksZip n ((p.1 i j).2,(p.2 i j).2)) + +lemma indexedMarksZip_measurable (n : ℕ) : Measurable (indexedMarksZip (S:=S) (T:=T) n) := by + induction n with + | zero => exact measurable_const + | succ n ih => + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + exact ((by fun_prop : Measurable (fun p : IndexedCascadeMarks S (n+1) × IndexedCascadeMarks T (n+1) => + ((p.1 i j).1,(p.2 i j).1)))).prodMk (ih.comp (by fun_prop)) + +lemma indexedMarksZip_vertices (n : ℕ) (a : IndexedVertex n→S) (b : IndexedVertex n→T) : + indexedMarksZip n (indexedMarksFromVertices n a,indexedMarksFromVertices n b)= + indexedMarksFromVertices n (fun v => (a v,b v)) := by + induction n with + | zero => rfl + | succ n ih => + funext i j + exact congrArg (fun x => ((a (i,j,.inl ()),b (i,j,.inl ())),x)) + (ih (fun v => a (i,j,.inr v)) (fun v => b (i,j,.inr v))) + +lemma indexedMarksZip_law (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) (n : ℕ) : + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n : Measure (IndexedCascadeMarks T n))).map (indexedMarksZip n)= + (indexedCascadeMarksLaw (productMarkLaw ν ρ) n : Measure (IndexedCascadeMarks (S×T) n)) := by + let A := Measure.infinitePi (fun _ : IndexedVertex n => (ν : Measure S)) + let B := Measure.infinitePi (fun _ : IndexedVertex n => (ρ : Measure T)) + have he : (fun p : (IndexedVertex n→S)×(IndexedVertex n→T) => + indexedMarksZip n (indexedMarksFromVertices n p.1,indexedMarksFromVertices n p.2))= + indexedMarksFromVertices n ∘ (fun p v => (p.1 v,p.2 v)) := by + funext p + exact indexedMarksZip_vertices n p.1 p.2 + rw [← indexedMarksFromVertices_law ν n,← indexedMarksFromVertices_law ρ n, + Measure.map_prod_map _ _ (indexedMarksFromVertices_measurable n) (indexedMarksFromVertices_measurable n), + Measure.map_map (indexedMarksZip_measurable n) + ((indexedMarksFromVertices_measurable n).prodMap (indexedMarksFromVertices_measurable n))] + change (A.prod B).map (fun p => indexedMarksZip n (indexedMarksFromVertices n p.1,indexedMarksFromVertices n p.2))=_ + rw [he,← Measure.map_map (indexedMarksFromVertices_measurable n) (by fun_prop)] + dsimp [A,B] + rw [infinitePi_zip] + exact indexedMarksFromVertices_law (productMarkLaw ν ρ) n + +lemma indexedLeafState_product {X Y : Type} [MeasurableSpace X] [MeasurableSpace Y] (step₁ : X×S→X) (step₂ : Y×T→Y) + (n : ℕ) (x : X) (y : Y) (a : IndexedCascadeMarks S n) (b : IndexedCascadeMarks T n) + (l : IndexedLeaf n) : + indexedLeafState (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) n + ((x,y),indexedMarksZip n (a,b)) l= + (indexedLeafState step₁ n (x,a) l,indexedLeafState step₂ n (y,b) l) := by + induction n generalizing x y with + | zero => rfl + | succ n ih => exact ih _ _ _ _ _ + +end + +theorem indexed_independent_arrays_fresh_log {X Y S T : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace S] [MeasurableSpace T] + [Nonempty S] [Nonempty T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 G (indexedLeafState step₂ n (y,p.2.2) l)) + (fun l => Real.exp (H (indexedLeafState step₁ n (x,p.2.1) l))) 1) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n))) = + finiteCascadeLogRecursion ν step₁ n z H x := by + let step : (X×Y)×(S×T)→X×Y := fun a => (step₁ (a.1.1,a.2.1),step₂ (a.1.2,a.2.2)) + have hs : Measurable step := by fun_prop + let F : IndexedCascadeBase n×IndexedCascadeMarks (S×T) n→ℝ := fun p => + Real.log (tiltMean (indexedLeafProbability n p.1) + (fun l => G (indexedLeafState step n ((x,y),p.2) l).2) + (fun l => Real.exp (H (indexedLeafState step n ((x,y),p.2) l).1)) 1) + let κ : Kernel (IndexedCascadeBase n × IndexedCascadeMarks (S×T) n) (IndexedLeaf n) := (indexedLeafKernel n).comap + (Prod.fst : IndexedCascadeBase n×IndexedCascadeMarks (S×T) n→IndexedCascadeBase n) measurable_fst + have hstate : Measurable (fun a : (IndexedCascadeBase n×IndexedCascadeMarks (S×T) n)×IndexedLeaf n => + indexedLeafState step n ((x,y),a.1.2) a.2) := + (indexedLeafState_measurable hs n).comp (show Measurable (fun a : (IndexedCascadeBase n×IndexedCascadeMarks (S×T) n)×IndexedLeaf n => (((x,y),a.1.2),a.2)) from (measurable_const.prodMk measurable_fst.snd).prodMk measurable_snd) + have hF : Measurable F := (kernel_tiltMean_measurable κ + (H := fun p l => G (indexedLeafState step n ((x,y),p.2) l).2) + (Y := fun p l => Real.exp (H (indexedLeafState step n ((x,y),p.2) l).1)) + (hG.comp hstate.snd) (hH.comp hstate.fst |>.exp)).log + let B := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)) + let M := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n : Measure (IndexedCascadeMarks T n)) + let M' := (indexedCascadeMarksLaw (productMarkLaw ν ρ) n : Measure (IndexedCascadeMarks (S×T) n)) + let a : IndexedCascadeBase n × (IndexedCascadeMarks S n × IndexedCascadeMarks T n) → + IndexedCascadeBase n × IndexedCascadeMarks (S×T) n := + Prod.map (id : IndexedCascadeBase n→IndexedCascadeBase n) (indexedMarksZip (S:=S) (T:=T) n) + have ha : Measurable a := measurable_id.prodMap (indexedMarksZip_measurable n) + have hmap : (B.prod M).map a=B.prod M' := by + rw [← Measure.map_prod_map _ _ measurable_id (indexedMarksZip_measurable n),Measure.map_id] + exact congrArg (Measure.prod B) (indexedMarksZip_law ν ρ n) + have hval := indexed_independent_fresh_log ν ρ step₁ step₂ hs₁ hs₂ n z hz hz0 hz1 hH hG hIH hIG x y + change (∫ p, F p ∂B.prod M')=_ at hval + rw [← hmap,integral_map ha.aemeasurable hF.aestronglyMeasurable] at hval + convert hval using 1 + apply integral_congr_ae + exact ae_of_all _ fun p => by + rcases p with ⟨b,m₁,m₂⟩ + dsimp only [a,Prod.map,F,step,id_eq] + simp only [indexedLeafState_product] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedObservableTransport.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedObservableTransport.lean new file mode 100644 index 0000000000000000000000000000000000000000..2962109ce40737159877354c6018d5e2baf0ad6f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedObservableTransport.lean @@ -0,0 +1,161 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianCovarianceDerivative + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology + +variable {I : Type} [Fintype I] [DecidableEq I] {S : Type} [MeasurableSpace S] +variable (n : ℕ) + +omit [MeasurableSpace S] in +theorem indexedHamiltonian_integral_covariance_addition + (W : S×IndexedLeaf n→ℝ) (V : S→EuclideanSpace ℝ I) + (Ψ : (S×IndexedLeaf n→ℝ)→ℝ) + (hΨ : Measurable (fun g => Ψ (sharedMarksHamiltonian n W V g))) + (B C D : Fin (n+1)→I→ℝ) (h : ∀ l i, D l i^2=B l i^2+C l i^2) : + (∫ g, Ψ (countableGaussianHamiltonian W (indexedGaussianRow n D V) + (indexedGaussianRowLength (I := I) n) g) ∂countableGaussianLaw) = + ∫ g, Ψ (countableGaussianHamiltonian W (indexedGaussianRow n (fun l => Sum.elim (B l) (C l)) + (fun s => WithLp.toLp 2 (Sum.elim (fun i => V s i) (fun i => V s i)))) + (indexedGaussianRowLength (I := I ⊕ I) n) g) ∂countableGaussianLaw := by + let F := fun g : SharedVertex n→EuclideanSpace ℝ I => Ψ (sharedMarksHamiltonian n W V g) + have hF : Measurable F := hΨ + let b := fun g v => gaussianRows (doubledGaussianRows (B (indexedSharedVertexDepth n v)) (C (indexedSharedVertexDepth n v))) + (countableGaussianVectors g v) + let d := fun g v => gaussianRows (diagonalGaussianRows (D (indexedSharedVertexDepth n v))) + (countableGaussianVectors g v) + have hb : Measurable b := by + apply Measurable.of_eval + intro v + exact (gaussianRows (doubledGaussianRows (B (indexedSharedVertexDepth n v)) (C (indexedSharedVertexDepth n v)))).measurable.comp ((measurable_pi_apply v).comp countableGaussianVectors_measurable) + have hd : Measurable d := by + apply Measurable.of_eval + intro v + exact (gaussianRows (diagonalGaussianRows (D (indexedSharedVertexDepth n v)))).measurable.comp ((measurable_pi_apply v).comp countableGaussianVectors_measurable) + have he := countableGaussian_covariance_addition_law + (fun v => B (indexedSharedVertexDepth n v)) (fun v => C (indexedSharedVertexDepth n v)) + (fun v => D (indexedSharedVertexDepth n v)) (fun v => h (indexedSharedVertexDepth n v)) + have hi : (∫ g, F (d g) ∂countableGaussianLaw) = ∫ g, F (b g) ∂countableGaussianLaw := by + rw [← integral_map hd.aemeasurable hF.aestronglyMeasurable, + ← integral_map hb.aemeasurable hF.aestronglyMeasurable,he] + have hf (g) : sharedMarksHamiltonian n W V (d g) = + countableGaussianHamiltonian W (indexedGaussianRow n D V) (indexedGaussianRowLength (I := I) n) g := + funext (sharedMarks_diagonal_eq n W V D g) + have hg (g) : sharedMarksHamiltonian n W V (b g) = + countableGaussianHamiltonian W (indexedGaussianRow n (fun l => Sum.elim (B l) (C l)) + (fun s => WithLp.toLp 2 (Sum.elim (fun i => V s i) (fun i => V s i)))) + (indexedGaussianRowLength (I := I ⊕ I) n) g := + funext (sharedMarks_doubled_eq n W V B C g) + change _ = _ at hi + simp only [F,hf,hg] at hi + exact hi + +lemma indexedReplicaMean_covariance_addition (μ : Measure (S×IndexedLeaf n)) [IsProbabilityMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) (r : ℕ) + {G : (Fin r→S×IndexedLeaf n)→ℝ} (hG : Measurable G) + (B C D : Fin (n+1)→I→ℝ) (h : ∀ l i, D l i^2=B l i^2+C l i^2) : + (∫ g, gibbsReplicaMean μ (countableGaussianHamiltonian W (indexedGaussianRow n D V) + (indexedGaussianRowLength (I := I) n) g) r G ∂countableGaussianLaw) = + ∫ g, gibbsReplicaMean μ (countableGaussianHamiltonian W (indexedGaussianRow n (fun l => Sum.elim (B l) (C l)) + (fun s => WithLp.toLp 2 (Sum.elim (fun i => V s i) (fun i => V s i)))) + (indexedGaussianRowLength (I := I ⊕ I) n) g) r G ∂countableGaussianLaw := by + exact indexedHamiltonian_integral_covariance_addition n W V (fun H => gibbsReplicaMean μ H r G) + (kernel_replicaMean_measurable (Kernel.const _ μ) (sharedMarksHamiltonian_measurable n hW hV) + (hG.comp measurable_snd)) B C D h + +lemma indexedTiltMean_covariance_addition (μ : Measure (S×IndexedLeaf n)) [IsProbabilityMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) {G : S×IndexedLeaf n→ℝ} (hG : Measurable G) + (B C D : Fin (n+1)→I→ℝ) (h : ∀ l i, D l i^2=B l i^2+C l i^2) : + (∫ g, tiltMean μ (countableGaussianHamiltonian W (indexedGaussianRow n D V) + (indexedGaussianRowLength (I := I) n) g) G 1 ∂countableGaussianLaw) = + ∫ g, tiltMean μ (countableGaussianHamiltonian W (indexedGaussianRow n (fun l => Sum.elim (B l) (C l)) + (fun s => WithLp.toLp 2 (Sum.elim (fun i => V s i) (fun i => V s i)))) + (indexedGaussianRowLength (I := I ⊕ I) n) g) G 1 ∂countableGaussianLaw := by + exact indexedHamiltonian_integral_covariance_addition n W V (fun H => tiltMean μ H G 1) + (kernel_tiltMean_measurable (Kernel.const _ μ) (sharedMarksHamiltonian_measurable n hW hV) + (hG.comp measurable_snd)) B C D h + + +omit [DecidableEq I] [MeasurableSpace S] in +lemma indexedGaussianRow_right_covariance (C : Fin (n+1)→I→ℝ) (V : S→EuclideanSpace ℝ I) + (x y : S×IndexedLeaf n) : + countableGaussianCovariance + (indexedGaussianRow n (rightCoefficients n C) (duplicateFeature V)) + (indexedGaussianRow n (rightCoefficients n C) (duplicateFeature V)) + (indexedGaussianRowLength (I := I ⊕ I) n) x y = + countableGaussianCovariance (indexedGaussianRow n C V) (indexedGaussianRow n C V) + (indexedGaussianRowLength (I := I) n) x y := by + rw [indexedGaussianRow_covariance,indexedGaussianRow_covariance,Fintype.sum_sum_type] + simp [rightCoefficients,duplicateFeature] + +def indexedResponse (μ : Measure (S×IndexedLeaf n)) + (K : (S×IndexedLeaf n)→(S×IndexedLeaf n)→ℝ) (H : S×IndexedLeaf n→ℝ) : ℝ := + tiltMean μ H (fun x => K x x) 1 - gibbsReplicaMean μ H 2 (fun x => K (x 1) (x 0)) + +omit [DecidableEq I] in +lemma indexedResponse_measurable (μ : Measure (S×IndexedLeaf n)) [IsProbabilityMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) + {K : (S×IndexedLeaf n)→(S×IndexedLeaf n)→ℝ} (hK : Measurable (Function.uncurry K)) : + Measurable (fun g => indexedResponse n μ K (sharedMarksHamiltonian n W V g)) := by + have hKd : Measurable (fun x : S×IndexedLeaf n => K x x) := + hK.comp (measurable_id.prodMk measurable_id) + have hpair : Measurable (fun x : Fin 2→S×IndexedLeaf n => (x 1,x 0)) := + (measurable_pi_apply 1).prodMk (measurable_pi_apply 0) + have hKp : Measurable (fun x : Fin 2→S×IndexedLeaf n => K (x 1) (x 0)) := hK.comp hpair + exact (kernel_tiltMean_measurable (Kernel.const _ μ) + (H := sharedMarksHamiltonian n W V) (Y := fun _ x => K x x) + (sharedMarksHamiltonian_measurable n hW hV) (hKd.comp measurable_snd)).sub + (kernel_replicaMean_measurable (Kernel.const _ μ) + (H := sharedMarksHamiltonian n W V) (G := fun _ x => K (x 1) (x 0)) + (sharedMarksHamiltonian_measurable n hW hV) (hKp.comp measurable_snd)) + +lemma indexedResponse_transport (μ : Measure (S×IndexedLeaf n)) [IsProbabilityMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) + {K : (S×IndexedLeaf n)→(S×IndexedLeaf n)→ℝ} (hK : Measurable (Function.uncurry K)) + (B : Fin (n+1)→I→ℝ) : + (∫ g, indexedResponse n μ K (countableGaussianHamiltonian W + (indexedGaussianRow n (leftCoefficients n B) (duplicateFeature V)) + (indexedGaussianRowLength (I := I ⊕ I) n) g) ∂countableGaussianLaw) = + ∫ g, indexedResponse n μ K (countableGaussianHamiltonian W + (indexedGaussianRow n B V) (indexedGaussianRowLength (I := I) n) g) ∂countableGaussianLaw := by + exact (indexedHamiltonian_integral_covariance_addition n W V (indexedResponse n μ K) + (indexedResponse_measurable n μ hW hV hK) B (fun _ _ => 0) B (fun l i => by simp)).symm + +theorem indexedGaussianMean_right_response (μ : Measure (S×IndexedLeaf n)) [IsProbabilityMeasure μ] + {W : S×IndexedLeaf n→ℝ} {V : S→EuclideanSpace ℝ I} + (hW : Measurable W) (hV : Measurable V) {A D : ℝ} (hD0 : 0 ≤ D) + (hA : ∀ x, |W x| ≤ A) (hD : ∀ x, (∑ i, V x i^2) ≤ D) + (B C : Fin (n+1)→I→ℝ) (Q : ℝ→Fin (n+1)→I→ℝ) + (hQ : ∀ t, 0 ≤ t → ∀ l i, Q t l i^2=B l i^2+t*C l i^2) : + let v := indexedGaussianRow n B V + let w := indexedGaussianRow n C V + let L := indexedGaussianRowLength (I := I) (S := S) n + HasDerivWithinAt (fun t => indexedGaussianMean n μ W V (Q t)) + ((∫ g, indexedResponse n μ (countableGaussianCovariance w w L) + (countableGaussianHamiltonian W v L g) ∂countableGaussianLaw)/2) (Ici 0) 0 := by + let w := indexedGaussianRow n C V + let L := indexedGaussianRowLength (I := I) (S := S) n + have hK : Measurable (Function.uncurry (countableGaussianCovariance w w L)) := + countableGaussianCovariance_measurable (indexedGaussianRow_measurable n C hV) + (indexedGaussianRow_measurable n C hV) (indexedGaussianRowLength_measurable n) + have hd := indexedGaussianMean_right_derivative n μ hW hV hD0 hA hD B C Q hQ + dsimp only at hd ⊢ + simp only [indexedGaussianRow_right_covariance] at hd + change HasDerivWithinAt _ ((∫ g, indexedResponse n μ (countableGaussianCovariance w w L) + (countableGaussianHamiltonian W (indexedGaussianRow n (leftCoefficients n B) (duplicateFeature V)) + (indexedGaussianRowLength (I := I ⊕ I) n) g) ∂countableGaussianLaw)/2) _ _ at hd + rw [indexedResponse_transport n μ hW hV hK B] at hd + exact hd + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedPathCorrelation.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedPathCorrelation.lean new file mode 100644 index 0000000000000000000000000000000000000000..c8b1938c4f57ecac3e4f375655f684dbf02cc1f8 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedPathCorrelation.lean @@ -0,0 +1,44 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.AtomicPairVisitLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +lemma indexedPairState_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) (d : Fin (n+1)) + (f : X → ℝ) (hf : Measurable f) (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, |f x| ≤ C) : + (∫ p, (∫ y, f y.1*f y.2 ∂indexedPairStateKernel step hs n F hF x d p) + ∂((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))) = + (twoVisitMass n z d).toReal * + pathCorrelation n (fun i => tiltedStateStep ν step (z i) (F i)) f d x := by + let μ := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)) + let κ := indexedPairStateKernel step hs n F hF x d + have ht : Measurable (fun y : X×X => f y.1*f y.2) := + (hf.comp measurable_fst).mul (hf.comp measurable_snd) + have hB : ∀ y : X×X, |f y.1*f y.2| ≤ C^2 := fun y => by + rw [abs_mul,pow_two]; exact mul_le_mul (hb _) (hb _) (abs_nonneg _) hC + have hi := path_bounded_integrable (κ ∘ₘ μ) _ ht (C^2) hB + have he : (∫ y, f y.1*f y.2 ∂(κ ∘ₘ μ)) = ∫ p, ∫ y, f y.1*f y.2 ∂κ p ∂μ := by + rw [Measure.comp_eq_comp_const_apply] at hi ⊢ + exact Kernel.integral_comp hi + rw [← he] + change (∫ y, f y.1*f y.2 ∂(indexedPairStateKernel step hs n F hF x d ∘ₘ _)) = _ + rw [indexedPairStateLaw_eq ν step hs n z hz hz0 hz1 F hF hI hM x d, + integral_smul_measure,smul_eq_mul] + rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedTiltedRegular.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedTiltedRegular.lean new file mode 100644 index 0000000000000000000000000000000000000000..253a2f5d337555da7c754488693830ecf13e4deb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedTiltedRegular.lean @@ -0,0 +1,183 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.AtomicBranches +import OAI.Probability.Perceptron.Cascade.IndexedTiltedWeights + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +lemma indexedTiltedTotal_regular (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + ∀ᵐ p ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)), + 0 < (indexedTiltedTotal step n F (x,p)).toReal := by + have hR : MeasurePreserving (indexedCascadeRealize (S := S) n) + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) := + ⟨indexedCascadeRealize_measurable n,indexedCascadeRealize_law ν n z⟩ + have hp := hR.quasiMeasurePreserving.ae + (decoratedWeightedTotal_pos ν step hs n z hz hz0 hz1 F hF hI hM x) + have hg := (measurePreserving_fst (μ := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n))) + (ν := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)))).quasiMeasurePreserving.ae + (indexedCascadeGood_ae n z hz0 hz1) + filter_upwards [hp,hg] with p hp hg + rwa [indexedTiltedTotal_eq hs n F hF (x,p) hg] + +lemma centeredMarkedPoisson_simple (ν : Measure S) [IsProbabilityMeasure ν] + {b : ℝ} (hb : 0 < b) (hb1 : b < 1) {F : S → ℝ} (hF : Measurable F) + (hI : Integrable (fun s => Real.exp (b*F s)) ν) : + ∀ᵐ η ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν), + ∀ᵐ t ∂((η.map (logMarkShift (centeredLogMark ν b F))).map Prod.fst), + ((η.map (logMarkShift (centeredLogMark ν b F))).map Prod.fst) {t} = 1 := by + let τ := exponentialMarkTilt ν b F + have : IsProbabilityMeasure τ := exponentialMarkTilt_probability ν hI + have hc : Measurable (centeredLogMark ν b F) := centeredLogMark_measurable ν b hF + have ht : MeasurePreserving (Measure.map (logMarkShift (centeredLogMark ν b F))) + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) + (poissonRandomMeasureLaw ((stableLogIntensity b).prod τ)) := by + refine ⟨Measure.measurable_map _ (logMarkShift_measurable hc), ?_⟩ + rw [stablePoisson_mark_shift ν hb.le hc] + congr 1 + exact congrArg ((stableLogIntensity b).prod) (centeredLogMark_density ν hb.ne' hI) + have hp : MeasurePreserving (Measure.map (Prod.fst : ℝ×S → ℝ)) + (poissonRandomMeasureLaw ((stableLogIntensity b).prod τ)) + (poissonRandomMeasureLaw (stableLogIntensity b)) := + ⟨Measure.measurable_map _ measurable_fst,markedStable_project_law τ b⟩ + exact (hp.comp ht).quasiMeasurePreserving.ae (stablePoissonCount_simple hb hb1) + +lemma indexedCenteredRoot_simple (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + ∀ᵐ p ∂(indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))).prod + (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))), + Function.Injective (fun a : Σ i, Fin ((p.1 i).1) => + (((p.1 a.1).2 a.2.val).1 + decoratedCenteredRoot ν step n z F + (x,((p.2 a.1 a.2.val).1,indexedCascadeRealize n + ((((p.1 a.1).2 a.2.val).2,(p.2 a.1 a.2.val).2)))))) := by + let D := ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ) : + Measure (DecoratedCascade S n))) + have hR : MeasurePreserving (indexedCascadeRealize (S := S) (n+1)) + ((indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))).prod + (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1)))) + (decoratedCascadeLaw ν (n+1) z : Measure (DecoratedCascade S (n+1))) := + ⟨indexedCascadeRealize_measurable (n+1),indexedCascadeRealize_law ν (n+1) z⟩ + have hpot : Measurable (fun t => decoratedRootPotential step n F (x,t)) := + (decoratedRootPotential_measurable step hs n F hF).comp (measurable_const.prodMk measurable_id) + have he := centeredMarkedPoisson_simple D (hz0 0) (hz1 0) hpot + (decoratedRootPotential_integrable ν step hs n z hz hz0 hz1 F hF hI hM x) + have hae := hR.quasiMeasurePreserving.ae he + filter_upwards [hae] with p hp + let a : ℕ → ℕ×(ℕ → ℝ×(S×DecoratedCascade S n)) := fun i => ((p.1 i).1,fun j => + (((p.1 i).2 j).1,((p.2 i j).1,indexedCascadeRealize n ((((p.1 i).2 j).2,(p.2 i j).2))))) + let f : (Σ i, Fin ((p.1 i).1)) → ℝ := fun q => ((a q.1).2 q.2.val).1 + + decoratedCenteredRoot ν step n z F (x,((a q.1).2 q.2.val).2) + have hmap : (((indexedCascadeRealize (n+1) p).map + (logMarkShift (centeredLogMark D (z 0) (fun t => decoratedRootPotential step n F (x,t))))).map + Prod.fst) = Measure.count.map f := by + change ((indexedPoissonMeasure a).map _).map _ = _ + rw [indexedPoissonMeasure_eq_map_count, + Measure.map_map (logMarkShift_measurable (centeredLogMark_measurable D (z 0) hpot)) + (measurable_of_countable _), + Measure.map_map measurable_fst (measurable_of_countable _)] + rfl + rw [hmap] at hp + exact injective_of_simple_count_map f (measurable_of_countable _) hp + +lemma indexedShapeRoot_counted (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hj : Function.Injective (fun a => (indexedRootPoint ν step n z F p a).1)) + (ss : List (DecoratedVisitShape X n)) (hv : ∀ s ∈ ss, s.Valid n) : + decoratedShapeProbability ν step (n+1) z F ss (p.1,indexedCascadeRealize (n+1) p.2) = + countedBlockProbability (indexedRootPoint ν step n z F p) + (ss.map (fun s => (cascadeVisitCount n (s.bare n),fun t : S×DecoratedCascade S n => + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) s + (step (p.1,t.1),t.2)))) (Fin.elim0 : Fin 0 → ℝ) := by + rw [decoratedShapeProbability,indexedCascadeGood_countKernel hb] + have hc : Measurable (fun t : ℝ×(S×DecoratedCascade S n) => + (t.1+decoratedCenteredRoot ν step n z F (p.1,t.2),t.2)) := + (measurable_fst.add ((decoratedCenteredRoot_measurable ν step hs n z F hF).comp + (measurable_const.prodMk measurable_snd))).prodMk measurable_snd + have he : (indexedCascadeRealize (n+1) p.2).map + (fun t : ℝ×(S×DecoratedCascade S n) => + (t.1+decoratedCenteredRoot ν step n z F (p.1,t.2),t.2)) = + Measure.count.map (indexedRootPoint ν step n z F p) := by + unfold indexedCascadeRealize + rw [indexedPoissonMeasure_eq_map_count,Measure.map_map hc (measurable_of_countable _)] + rfl + rw [he] + apply markedBlockProbability_count_map _ (measurable_of_countable _) hj + · intro nf hnf + obtain ⟨s,hs',rfl⟩ := List.mem_map.mp hnf + exact cascadeVisitCount_pos n _ (s.bare_valid n (hv s hs')) + · intro nf hnf + obtain ⟨s,hs',rfl⟩ := List.mem_map.mp hnf + exact (decoratedShapeProbability_measurable ν step hs n _ _ (fun i => hF i.succ) s (hv s hs')).comp + ((hs.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd) + +lemma indexedShapeRoot_singleton (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (hj : Function.Injective (fun a => (indexedRootPoint ν step n z F p a).1)) + (s : DecoratedVisitShape X n) (hv : s.Valid n) : + decoratedShapeProbability ν step (n+1) z F [s] (p.1,indexedCascadeRealize (n+1) p.2) = + ∑' a, (indexedBranchProbability step n F p a)^(cascadeVisitCount n (s.bare n))* + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) s + ((indexedChildPoint step n p a.1 a.2.val).1, + indexedCascadeRealize n (indexedChildPoint step n p a.1 a.2.val).2) := by + rw [indexedShapeRoot_counted ν step hs n z F hF p hb hj [s] (by simpa using hv)] + simp only [List.map_cons,List.map_nil,countedBlockProbability,Fin.exists_fin_zero, + ite_false,mul_one,indexedRootPoint_probability ν step hs n z F hF p hb hc] + rfl + +lemma indexedShapeRoot_pair (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (hj : Function.Injective (fun a => (indexedRootPoint ν step n z F p a).1)) + (s t : DecoratedVisitShape X n) (hv : s.Valid n) (hw : t.Valid n) : + decoratedShapeProbability ν step (n+1) z F [s,t] (p.1,indexedCascadeRealize (n+1) p.2) = + ∑' a, (indexedBranchProbability step n F p a)^(cascadeVisitCount n (s.bare n))* + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) s + ((indexedChildPoint step n p a.1 a.2.val).1, + indexedCascadeRealize n (indexedChildPoint step n p a.1 a.2.val).2)* + ∑' b, if a=b then 0 else (indexedBranchProbability step n F p b)^(cascadeVisitCount n (t.bare n))* + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) t + ((indexedChildPoint step n p b.1 b.2.val).1, + indexedCascadeRealize n (indexedChildPoint step n p b.1 b.2.val).2) := by + classical + rw [indexedShapeRoot_counted ν step hs n z F hF p hb hj [s,t] (by + intro u hu; simp only [List.mem_cons,List.not_mem_nil,or_false] at hu + rcases hu with rfl|rfl <;> assumption)] + simp only [List.map_cons,List.map_nil,countedBlockProbability,Fin.exists_fin_zero, + ite_false,mul_one,indexedRootPoint_probability ν step hs n z F hF p hb hc, + Fin.exists_fin_succ,Fin.cons_zero,or_false,hj.eq_iff] + rfl + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedTwoShape.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedTwoShape.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a6b64944544cbfadc24984964c3e965054abd2b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedTwoShape.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DecoratedShapeLaw +import OAI.Probability.Perceptron.Variational.IndexedVisit + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +lemma indexedTwoVisit_eq_shape (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (h k : X → ℝ≥0∞) (hh : Measurable h) (hk : Measurable k) (d : Fin (n+1)) (x : X) : + ∀ᵐ p ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)), + indexedTwoVisit step n F h k d (x,p) = + decoratedShapeProbability ν step n z F (twoDecoratedVisit h k n d) (x,indexedCascadeRealize n p) := by + induction n generalizing x with + | zero => exact ae_of_all _ fun p => indexedTwoVisit_zero step F h k d (x,p) + | succ n ih => + have hzt : StrictMono (fun i : Fin n => z i.succ) := fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij) + have hc := indexedCascade_ae_children ν step hs n z + (fun p => 0 < (indexedTiltedTotal step n (fun i => F i.succ) p).toReal) + (measurableSet_lt measurable_const ((indexedTiltedTotal_measurable hs n _ (fun i => hF i.succ)).ennreal_toReal)) + (fun y => indexedTiltedTotal_regular ν step hs n _ hzt (fun i => hz0 i.succ) (fun i => hz1 i.succ) + _ (fun i => hF i.succ) (fun i => hI i.succ) (fun i => hM i.succ) y) x + have hj := indexedCenteredRoot_simple ν step hs n z hz hz0 hz1 F hF hI hM x + have hb := (measurePreserving_fst + (μ := (indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1)))) + (ν := (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))))).quasiMeasurePreserving.ae + (indexedCascadeGood_ae (n+1) z hz0 hz1) + induction d using Fin.cases with + | zero => + have he (f : X → ℝ≥0∞) (hf : Measurable f) := indexedCascade_ae_children ν step hs n z + (fun p => indexedOneVisit step n (fun i => F i.succ) f p = + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) + (oneDecoratedVisit f n) (p.1,indexedCascadeRealize n p.2)) + (measurableSet_eq_fun (indexedOneVisit_measurable hs n _ (fun i => hF i.succ) hf) + ((decoratedShapeProbability_measurable ν step hs n _ _ (fun i => hF i.succ) _ + (oneDecoratedVisit_valid hf n)).comp + (measurable_fst.prodMk ((indexedCascadeRealize_measurable n).comp measurable_snd)))) + (fun y => indexedOneVisit_eq_shape ν step hs n _ hzt (fun i => hz0 i.succ) + (fun i => hz1 i.succ) _ (fun i => hF i.succ) (fun i => hI i.succ) + (fun i => hM i.succ) f hf y) x + filter_upwards [he h hh,he k hk,hc,hj,hb] with p hh' hk' hc hj hb + rw [indexedTwoVisit_succ_zero step n F h k (x,p) hc,twoDecoratedVisit,Fin.cases_zero, + indexedShapeRoot_pair ν step hs n z F hF (x,p) hb hc hj _ _ + (oneDecoratedVisit_valid hh n) (oneDecoratedVisit_valid hk n),oneDecoratedVisit_count, + oneDecoratedVisit_count] + simp only [pow_one] + apply tsum_congr + intro a + have hea := hh' a.1 a.2.val + change indexedOneVisit step n _ h (indexedChildPoint step n (x,p) a.1 a.2.val) = _ at hea + rw [hea] + congr 1 + apply tsum_congr + intro b + split_ifs + · rfl + · exact congrArg (fun t => indexedBranchProbability step n F (x,p) b*t) (hk' b.1 b.2.val) + | succ d => + have he := indexedCascade_ae_children ν step hs n z + (fun p => indexedTwoVisit step n (fun i => F i.succ) h k d p = + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) + (twoDecoratedVisit h k n d) (p.1,indexedCascadeRealize n p.2)) + (measurableSet_eq_fun (indexedTwoVisit_measurable hs n _ (fun i => hF i.succ) hh hk d) + ((decoratedShapeProbability_measurable ν step hs n _ _ (fun i => hF i.succ) _ + (twoDecoratedVisit_valid hh hk n d)).comp + (measurable_fst.prodMk ((indexedCascadeRealize_measurable n).comp measurable_snd)))) + (fun y => ih _ hzt (fun i => hz0 i.succ) (fun i => hz1 i.succ) _ (fun i => hF i.succ) + (fun i => hI i.succ) (fun i => hM i.succ) d y) x + filter_upwards [he,hc,hj,hb] with p he hc hj hb + rw [indexedTwoVisit_succ_succ step n F h k d (x,p) hc,twoDecoratedVisit,Fin.cases_succ, + indexedShapeRoot_singleton ν step hs n z F hF (x,p) hb hc hj _ (twoDecoratedVisit_valid hh hk n d), + twoDecoratedVisit_count] + apply tsum_congr + intro a + exact congrArg (fun t => (indexedBranchProbability step n F (x,p) a)^2*t) (he a.1 a.2.val) + +lemma decoratedBiasedLaw_zero (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin n → ℝ) (F : Fin n → X×S → ℝ) (x : X) : + decoratedBiasedLaw ν step n z F x 0 = + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) := by + simp [decoratedBiasedLaw,normalizedMeasure] + +lemma indexedShapeProbability_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (v : DecoratedVisitShape X n) (hv : v.Valid n) (x : X) : + (∫⁻ p, decoratedShapeProbability ν step n z F v (x,indexedCascadeRealize n p) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) = + cascadeShapeLikelihood n z 0 (v.bare n)*decoratedShapeMarkValue ν step n z F v x := by + have hm : Measurable (fun η : DecoratedCascade S n => + decoratedShapeProbability ν step n z F v (x,η)) := + (decoratedShapeProbability_measurable ν step hs n z F hF v hv).comp + (show Measurable (fun η : DecoratedCascade S n => (x,η)) from by fun_prop) + rw [← lintegral_map hm (indexedCascadeRealize_measurable n),indexedCascadeRealize_law ν n z, + ← decoratedBiasedLaw_zero ν step n z F x] + exact decoratedShapeProbability_integral ν step hs n z hz hz0 hz1 F hF hI hM 0 hz0 v hv x + +lemma indexedOneVisit_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (h : X → ℝ≥0∞) (hh : Measurable h) (x : X) : + (∫⁻ p, indexedOneVisit step n F h (x,p) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) = + decoratedShapeMarkValue ν step n z F (oneDecoratedVisit h n) x := by + rw [lintegral_congr_ae (indexedOneVisit_eq_shape ν step hs n z hz hz0 hz1 F hF hI hM h hh x), + indexedShapeProbability_integral ν step hs n z hz hz0 hz1 F hF hI hM _ (oneDecoratedVisit_valid hh n) x, + oneDecoratedVisit_likelihood h n z hz1 0 zero_lt_one,one_mul] + +lemma indexedTwoVisit_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (h k : X → ℝ≥0∞) (hh : Measurable h) (hk : Measurable k) (d : Fin (n+1)) (x : X) : + (∫⁻ p, indexedTwoVisit step n F h k d (x,p) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) = + cascadeShapeLikelihood n z 0 ((twoDecoratedVisit h k n d).bare n) * + decoratedShapeMarkValue ν step n z F (twoDecoratedVisit h k n d) x := by + rw [lintegral_congr_ae (indexedTwoVisit_eq_shape ν step hs n z hz hz0 hz1 F hF hI hM h k hh hk d x)] + exact indexedShapeProbability_integral ν step hs n z hz hz0 hz1 F hF hI hM _ + (twoDecoratedVisit_valid hh hk n d) x + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IndexedVisit.lean b/lean/OAI/Probability/Perceptron/Variational/IndexedVisit.lean new file mode 100644 index 0000000000000000000000000000000000000000..75e1db66208b7079b12485bb88a034ae17adbe9d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IndexedVisit.lean @@ -0,0 +1,302 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedAncestry +import OAI.Probability.Perceptron.Variational.IndexedChildLaw +import OAI.Probability.Perceptron.Cascade.IndexedReplicaWeights +import OAI.Probability.Perceptron.Variational.IndexedTiltedRegular + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators + +section + +def oneDecoratedVisit {X : Type} (h : X → ℝ≥0∞) : (n : ℕ) → DecoratedVisitShape X n + | 0 => (1,h) + | n+1 => [oneDecoratedVisit h n] + +lemma oneDecoratedVisit_valid {X : Type} [MeasurableSpace X] {h : X → ℝ≥0∞} + (hh : Measurable h) (n : ℕ) : (oneDecoratedVisit h n).Valid n := by + induction n with + | zero => exact ⟨le_rfl,hh⟩ + | succ n ih => exact ⟨by simp [oneDecoratedVisit],by simpa [oneDecoratedVisit] using ih⟩ + +lemma oneDecoratedVisit_count {X : Type} (h : X → ℝ≥0∞) (n : ℕ) : + cascadeVisitCount n ((oneDecoratedVisit h n).bare n) = 1 := by + induction n with + | zero => rfl + | succ n ih => simpa [oneDecoratedVisit,DecoratedVisitShape.bare,cascadeVisitCount] using ih + +lemma oneDecoratedVisit_likelihood {X : Type} (h : X → ℝ≥0∞) (n : ℕ) + (z : Fin n → ℝ) (hz1 : ∀ i, z i < 1) (a : ℝ) (ha : a < 1) : + cascadeShapeLikelihood n z a ((oneDecoratedVisit h n).bare n) = 1 := by + induction n generalizing a with + | zero => rfl + | succ n ih => + simp only [oneDecoratedVisit,DecoratedVisitShape.bare,List.map_cons,List.map_nil, + cascadeShapeLikelihood,List.prod_cons,List.prod_nil,mul_one] + rw [ih (fun i => z i.succ) (fun i => hz1 i.succ) (z 0) (hz1 0)] + simp only [oneDecoratedVisit_count,Nat.cast_one,stableEppfValue_singleton_one ha (hz1 0), + ENNReal.ofReal_one,one_mul] + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +def indexedOneVisit (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (h : X → ℝ≥0∞) (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : ℝ≥0∞ := + ∑' l, indexedTiltedProbability step n F p l * h (indexedLeafState step n (p.1,p.2.2) l) + +omit [Nonempty S] in +lemma indexedOneVisit_measurable {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + {h : X → ℝ≥0∞} (hh : Measurable h) : Measurable (indexedOneVisit step n F h) := by + apply Measurable.tsum + intro l + exact ((indexedTiltedProbability_measurable hs n F hF).comp (measurable_id.prodMk measurable_const)).mul + (hh.comp ((indexedLeafState_measurable hs n).comp (show Measurable + (fun p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n) => ((p.1,p.2.2),l)) from by fun_prop))) + +omit [Nonempty S] in +lemma indexedOneVisit_zero (step : X×S → X) (F : Fin 0 → X×S → ℝ) + (h : X → ℝ≥0∞) (p : X×(IndexedCascadeBase 0×IndexedCascadeMarks S 0)) : + indexedOneVisit step 0 F h p = h p.1 := by + simp [indexedOneVisit,indexedTiltedProbability,indexedTiltedTotal,indexedTiltedWeight, + indexedLeafWeight,indexedLeafState,indexedShiftSum,IndexedLeaf] + +omit [Nonempty S] in +lemma indexedOneVisit_succ (step : X×S → X) (n : ℕ) (F : Fin (n+1) → X×S → ℝ) + (h : X → ℝ≥0∞) (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) : + indexedOneVisit step (n+1) F h p = + ∑' a, indexedBranchProbability step n F p a * indexedOneVisit step n (fun i => F i.succ) h + (indexedChildPoint step n p a.1 a.2.val) := by + rw [indexedOneVisit,indexedTiltedProbability_tsum_succ step n F p hc] + rfl + +lemma indexedOneVisit_eq_shape (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (h : X → ℝ≥0∞) (hh : Measurable h) (x : X) : + ∀ᵐ p ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)), + indexedOneVisit step n F h (x,p) = + decoratedShapeProbability ν step n z F (oneDecoratedVisit h n) (x,indexedCascadeRealize n p) := by + induction n generalizing x with + | zero => exact ae_of_all _ fun p => indexedOneVisit_zero step F h (x,p) + | succ n ih => + have hzt : StrictMono (fun i : Fin n => z i.succ) := fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij) + have he := indexedCascade_ae_children ν step hs n z + (fun p => indexedOneVisit step n (fun i => F i.succ) h p = + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) + (oneDecoratedVisit h n) (p.1,indexedCascadeRealize n p.2)) + (measurableSet_eq_fun (indexedOneVisit_measurable hs n _ (fun i => hF i.succ) hh) + ((decoratedShapeProbability_measurable ν step hs n _ _ (fun i => hF i.succ) _ + (oneDecoratedVisit_valid hh n)).comp + (measurable_fst.prodMk ((indexedCascadeRealize_measurable n).comp measurable_snd)))) + (fun y => ih _ hzt (fun i => hz0 i.succ) (fun i => hz1 i.succ) _ (fun i => hF i.succ) + (fun i => hI i.succ) (fun i => hM i.succ) y) x + have hc := indexedCascade_ae_children ν step hs n z + (fun p => 0 < (indexedTiltedTotal step n (fun i => F i.succ) p).toReal) + (measurableSet_lt measurable_const ((indexedTiltedTotal_measurable hs n _ (fun i => hF i.succ)).ennreal_toReal)) + (fun y => indexedTiltedTotal_regular ν step hs n _ hzt (fun i => hz0 i.succ) (fun i => hz1 i.succ) + _ (fun i => hF i.succ) (fun i => hI i.succ) (fun i => hM i.succ) y) x + have hj := indexedCenteredRoot_simple ν step hs n z hz hz0 hz1 F hF hI hM x + have hb := (measurePreserving_fst + (μ := (indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1)))) + (ν := (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))))).quasiMeasurePreserving.ae + (indexedCascadeGood_ae (n+1) z hz0 hz1) + filter_upwards [he,hc,hj,hb] with p he hc hj hb + rw [indexedOneVisit_succ step n F h (x,p) hc,oneDecoratedVisit, + indexedShapeRoot_singleton ν step hs n z F hF (x,p) hb hc hj _ (oneDecoratedVisit_valid hh n), + oneDecoratedVisit_count] + simp only [pow_one] + apply tsum_congr + intro a + exact congrArg (fun t => indexedBranchProbability step n F (x,p) a * t) + (he a.1 a.2.val) + +end + +def twoDecoratedVisit {X : Type} (h k : X → ℝ≥0∞) : (n : ℕ) → Fin (n+1) → DecoratedVisitShape X n + | 0,_ => (2,fun x => h x*k x) + | n+1,d => Fin.cases [oneDecoratedVisit h n,oneDecoratedVisit k n] + (fun i => [twoDecoratedVisit h k n i]) d + +lemma twoDecoratedVisit_valid {X : Type} [MeasurableSpace X] {h k : X → ℝ≥0∞} + (hh : Measurable h) (hk : Measurable k) (n : ℕ) (d : Fin (n+1)) : + (twoDecoratedVisit h k n d).Valid n := by + induction n with + | zero => exact ⟨by change 1 ≤ 2; omega,hh.mul hk⟩ + | succ n ih => + induction d using Fin.cases with + | zero => + refine ⟨by simp [twoDecoratedVisit],?_⟩ + intro s hs + simp only [twoDecoratedVisit,Fin.cases_zero,List.mem_cons,List.not_mem_nil,or_false] at hs + rcases hs with rfl|rfl + · exact oneDecoratedVisit_valid hh n + · exact oneDecoratedVisit_valid hk n + | succ d => + exact ⟨by simp [twoDecoratedVisit],by simpa [twoDecoratedVisit] using ih d⟩ + +lemma twoDecoratedVisit_count {X : Type} (h k : X → ℝ≥0∞) (n : ℕ) (d : Fin (n+1)) : + cascadeVisitCount n ((twoDecoratedVisit h k n d).bare n) = 2 := by + induction n with + | zero => rfl + | succ n ih => + induction d using Fin.cases with + | zero => simp [twoDecoratedVisit,DecoratedVisitShape.bare,cascadeVisitCount,oneDecoratedVisit_count] + | succ d => simpa [twoDecoratedVisit,DecoratedVisitShape.bare,cascadeVisitCount] using ih d + +lemma activeRoot_eq_iff {n : ℕ} (b : IndexedCascadeBase (n+1)) + (a c : Σ i, Fin ((b i).1)) : a=c ↔ a.1=c.1 ∧ a.2.val=c.2.val := by + constructor + · rintro rfl; exact ⟨rfl,rfl⟩ + · rcases a with ⟨i,j⟩ + rcases c with ⟨i',j'⟩ + rintro ⟨rfl,hj⟩ + have : j=j' := Fin.ext hj + subst j' + rfl + +lemma indexedCommonDepth_active_zero (n : ℕ) (b : IndexedCascadeBase (n+1)) + (a c : Σ i, Fin ((b i).1)) (l m : IndexedLeaf n) : + indexedCommonDepth (n+1) (a.1,a.2.val,l) (c.1,c.2.val,m)=0 ↔ a≠c := by + classical + simp only [indexedCommonDepth, ← activeRoot_eq_iff] + by_cases h : a=c <;> simp [h] + +lemma indexedCommonDepth_active_succ (n : ℕ) (b : IndexedCascadeBase (n+1)) + (a c : Σ i, Fin ((b i).1)) (l m : IndexedLeaf n) (d : Fin (n+1)) : + indexedCommonDepth (n+1) (a.1,a.2.val,l) (c.1,c.2.val,m)=d.succ ↔ + a=c ∧ indexedCommonDepth n l m=d := by + classical + simp only [indexedCommonDepth, ← activeRoot_eq_iff] + by_cases h : a=c <;> simp [h,Ne.symm (Fin.succ_ne_zero d)] + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +omit [MeasurableSpace X] [Nonempty S] in +lemma indexedTiltedPair_tsum_succ (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (f : IndexedLeaf (n+1) → IndexedLeaf (n+1) → ℝ≥0∞) : + (∑' l, indexedTiltedProbability step (n+1) F p l * + ∑' m, indexedTiltedProbability step (n+1) F p m * f l m) = + ∑' a : Σ i, Fin ((p.2.1 i).1), ∑' b : Σ i, Fin ((p.2.1 i).1), + indexedBranchProbability step n F p a * indexedBranchProbability step n F p b * + ∑' l, indexedTiltedProbability step n (fun i => F i.succ) (indexedChildPoint step n p a.1 a.2.val) l * + ∑' m, indexedTiltedProbability step n (fun i => F i.succ) (indexedChildPoint step n p b.1 b.2.val) m * + f (a.1,a.2.val,l) (b.1,b.2.val,m) := by + rw [indexedTiltedProbability_tsum_succ step n F p hc] + simp_rw [indexedTiltedProbability_tsum_succ step n F p hc] + apply tsum_congr + intro a + simp_rw [← ENNReal.tsum_mul_left] + rw [ENNReal.tsum_comm] + apply tsum_congr + intro b + apply tsum_congr + intro l + apply tsum_congr + intro m + ac_rfl + +def indexedTwoVisit (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (h k : X → ℝ≥0∞) (d : Fin (n+1)) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : ℝ≥0∞ := + ∑' l, indexedTiltedProbability step n F p l * ∑' m, indexedTiltedProbability step n F p m * + if indexedCommonDepth n l m=d then h (indexedLeafState step n (p.1,p.2.2) l)* + k (indexedLeafState step n (p.1,p.2.2) m) else 0 + +omit [Nonempty S] in +lemma indexedTwoVisit_measurable {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + {h k : X → ℝ≥0∞} (hh : Measurable h) (hk : Measurable k) (d : Fin (n+1)) : + Measurable (indexedTwoVisit step n F h k d) := by + apply Measurable.tsum + intro l + apply Measurable.mul ((indexedTiltedProbability_measurable hs n F hF).comp + (measurable_id.prodMk measurable_const)) + apply Measurable.tsum + intro m + apply Measurable.mul ((indexedTiltedProbability_measurable hs n F hF).comp + (measurable_id.prodMk measurable_const)) + split_ifs + · exact (hh.comp ((indexedLeafState_measurable hs n).comp (show Measurable + (fun p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n) => ((p.1,p.2.2),l)) from by fun_prop))).mul + (hk.comp ((indexedLeafState_measurable hs n).comp (show Measurable + (fun p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n) => ((p.1,p.2.2),m)) from by fun_prop))) + · exact measurable_const + +omit [Nonempty S] in +lemma indexedTwoVisit_zero (step : X×S → X) (F : Fin 0 → X×S → ℝ) + (h k : X → ℝ≥0∞) (d : Fin 1) (p : X×(IndexedCascadeBase 0×IndexedCascadeMarks S 0)) : + indexedTwoVisit step 0 F h k d p = h p.1*k p.1 := by + have hd : d=0 := Subsingleton.elim _ _ + simp [indexedTwoVisit,indexedTiltedProbability,indexedTiltedTotal,indexedTiltedWeight, + indexedLeafWeight,indexedLeafState,indexedShiftSum,indexedCommonDepth,IndexedLeaf,hd] + +omit [Nonempty S] in +lemma indexedTwoVisit_succ_zero (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) (h k : X → ℝ≥0∞) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) : + indexedTwoVisit step (n+1) F h k 0 p = + ∑' a, indexedBranchProbability step n F p a * indexedOneVisit step n (fun i => F i.succ) h + (indexedChildPoint step n p a.1 a.2.val) * + ∑' b, if a=b then 0 else indexedBranchProbability step n F p b * + indexedOneVisit step n (fun i => F i.succ) k (indexedChildPoint step n p b.1 b.2.val) := by + classical + rw [indexedTwoVisit,indexedTiltedPair_tsum_succ step n F p hc] + apply tsum_congr + intro a + rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro b + simp only [indexedCommonDepth_active_zero n p.2.1] + by_cases hab : a=b + · simp [hab] + · simp only [ite_eq_left hab,ite_eq_right hab,indexedOneVisit,indexedLeafState] + simp_rw [← ENNReal.tsum_mul_left,← ENNReal.tsum_mul_right] + rw [ENNReal.tsum_comm] + apply tsum_congr + intro m + apply tsum_congr + intro l + dsimp only [indexedChildPoint] + ac_rfl + +omit [Nonempty S] in +lemma indexedTwoVisit_succ_succ (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) (h k : X → ℝ≥0∞) (d : Fin (n+1)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) : + indexedTwoVisit step (n+1) F h k d.succ p = + ∑' a, (indexedBranchProbability step n F p a)^2 * + indexedTwoVisit step n (fun i => F i.succ) h k d (indexedChildPoint step n p a.1 a.2.val) := by + classical + rw [indexedTwoVisit,indexedTiltedPair_tsum_succ step n F p hc] + apply tsum_congr + intro a + rw [tsum_eq_single a] + · simp only [indexedCommonDepth_active_succ n p.2.1,true_and,indexedTwoVisit, + indexedLeafState,pow_two] + rfl + · intro b hb + simp [indexedCommonDepth_active_succ n p.2.1,Ne.symm hb] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/InfinitePiSplit.lean b/lean/OAI/Probability/Perceptron/Variational/InfinitePiSplit.lean new file mode 100644 index 0000000000000000000000000000000000000000..1392d63d45228a86ec64c730b9f4354e087ba560 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/InfinitePiSplit.lean @@ -0,0 +1,71 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma infinitePi_sumPiEquivProdPi_symm {ι κ : Type*} {X : ι ⊕ κ → Type*} + [∀ i, MeasurableSpace (X i)] (μ : ∀ i, Measure (X i)) + [∀ i, IsProbabilityMeasure (μ i)] : + ((Measure.infinitePi fun i => μ (.inl i)).prod + (Measure.infinitePi fun i => μ (.inr i))).map + (MeasurableEquiv.sumPiEquivProdPi X).symm = Measure.infinitePi μ := by + classical + apply Measure.eq_infinitePi + intro s t ht + rw [Measure.map_apply (MeasurableEquiv.sumPiEquivProdPi X).symm.measurable + (MeasurableSet.pi s.countable_toSet fun i _ => ht i)] + have he : (MeasurableEquiv.sumPiEquivProdPi X).symm ⁻¹' ((s : Set (ι ⊕ κ)).pi t) = + (s.toLeft : Set ι).pi (fun i => t (.inl i)) ×ˢ + (s.toRight : Set κ).pi (fun i => t (.inr i)) := by + ext p + simp only [mem_preimage,mem_pi,mem_prod,Finset.mem_coe,Finset.mem_toLeft,Finset.mem_toRight] + constructor + · intro h + exact ⟨fun i hi => h (.inl i) hi,fun i hi => h (.inr i) hi⟩ + · rintro ⟨h₁,h₂⟩ (i|i) hi + · exact h₁ i hi + · exact h₂ i hi + rw [he,Measure.prod_prod,Measure.infinitePi_pi _ (fun _ _ => ht _), + Measure.infinitePi_pi _ (fun _ _ => ht _),Finset.prod_sum_eq_prod_toLeft_mul_prod_toRight] + +lemma infinitePi_zip {ι A B : Type*} [MeasurableSpace A] [MeasurableSpace B] + (μ : ι → Measure A) (ν : ι → Measure B) + [∀ i, IsProbabilityMeasure (μ i)] [∀ i, IsProbabilityMeasure (ν i)] : + ((Measure.infinitePi μ).prod (Measure.infinitePi ν)).map + (fun p i => (p.1 i,p.2 i)) = Measure.infinitePi (fun i => (μ i).prod (ν i)) := by + classical + apply Measure.eq_infinitePi + intro s t ht + let e := MeasurableEquiv.arrowProdEquivProdArrow A B s + have hm : Measurable (Prod.map (Finset.restrict s : (ι → A) → (s → A)) + (Finset.restrict s : (ι → B) → (s → B))) := by fun_prop + have hp : ((Measure.infinitePi μ).prod (Measure.infinitePi ν)).map + (fun p (i : s) => (p.1 i,p.2 i)) = Measure.pi (fun i : s => (μ i).prod (ν i)) := by + calc + _ = (((Measure.infinitePi μ).prod (Measure.infinitePi ν)).map + (Prod.map (Finset.restrict s) (Finset.restrict s))).map e.symm := by + rw [Measure.map_map e.symm.measurable hm] + rfl + _ = _ := by + rw [← Measure.map_prod_map _ _ (by fun_prop) (by fun_prop), + Measure.infinitePi_map_restrict,Measure.infinitePi_map_restrict] + exact (measurePreserving_arrowProdEquivProdArrow A B s (fun i => μ i) (fun i => ν i)).symm.map_eq + have he : (fun p : (ι → A) × (ι → B) => fun i => (p.1 i,p.2 i)) ⁻¹' + (s : Set ι).pi t = + (fun p : (ι → A) × (ι → B) => fun i : s => (p.1 i,p.2 i)) ⁻¹' + (univ.pi (fun i : s => t i)) := by + ext p + simp [Set.mem_pi] + rw [Measure.map_apply (by fun_prop) (MeasurableSet.pi s.countable_toSet fun i _ => ht i),he, + ← Measure.map_apply (by fun_prop) (MeasurableSet.univ_pi fun i : s => ht i),hp,Measure.pi_pi] + exact Finset.prod_attach s (fun i => (μ i).prod (ν i) (t i)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IntegrableGibbs.lean b/lean/OAI/Probability/Perceptron/Variational/IntegrableGibbs.lean new file mode 100644 index 0000000000000000000000000000000000000000..81c5230cb4debdc838bdc2be2ed05ae338ab9116 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IntegrableGibbs.lean @@ -0,0 +1,190 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StableLaplaceConstant + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +section +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma tilt_partition_pos_of_integrable {H : S → ℝ} {t : ℝ} + (hi : Integrable (fun x => Real.exp (t*H x)) μ) : 0 < tiltPartition μ H t := by + unfold tiltPartition + apply (integral_pos_iff_support_of_nonneg (fun _ => (Real.exp_pos _).le) hi).mpr + have he : Function.support (fun x => Real.exp (t*H x)) = univ := by + ext x + simp only [Function.mem_support,ne_eq,mem_univ] + exact iff_of_true (Real.exp_pos _).ne' trivial + rw [he,measure_univ] + exact zero_lt_one + +lemma tilt_law_probability_of_integrable {H : S → ℝ} {t : ℝ} + (hi : Integrable (fun x => Real.exp (t*H x)) μ) : + IsProbabilityMeasure (tiltLaw μ H t) := by + have hp := tilt_partition_pos_of_integrable μ hi + constructor + rw [tiltLaw,Measure.smul_apply,smul_eq_mul,withDensity_apply _ .univ, + Measure.restrict_univ,← ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ fun x => (Real.exp_pos _).le)] + exact ENNReal.inv_mul_cancel (ne_of_gt (ENNReal.ofReal_pos.mpr hp)) ENNReal.ofReal_ne_top + +lemma tilt_law_integral_of_integrable {H F : S → ℝ} (hH : Measurable H) {t : ℝ} + (hi : Integrable (fun x => Real.exp (t*H x)) μ) : + (∫ x, F x ∂tiltLaw μ H t)=tiltMean μ H F t := by + rw [tiltLaw,integral_smul_measure,integral_withDensity_eq_integral_toReal_smul + (hH.const_mul t).exp.ennreal_ofReal (ae_of_all _ fun _ => ENNReal.ofReal_lt_top)] + simp only [ENNReal.toReal_inv,ENNReal.toReal_ofReal (tilt_partition_pos_of_integrable μ hi).le, + ENNReal.toReal_ofReal (Real.exp_pos _).le,smul_eq_mul,tiltMean,tiltIntegral] + exact (div_eq_inv_mul _ _).symm + +lemma tiltMean_bound_of_integrable {H F : S → ℝ} (hH : Measurable H) (_hF : Measurable F) + {t C : ℝ} (hi : Integrable (fun x => Real.exp (t*H x)) μ) + (hC : ∀ x, |F x| ≤ C) : |tiltMean μ H F t| ≤ C := by + let := tilt_law_probability_of_integrable μ hi + rw [← tilt_law_integral_of_integrable μ hH hi] + have hh := norm_integral_le_of_norm_le_const (μ := tiltLaw μ H t) (f := F) + (C := C) (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hC x) + simpa only [Real.norm_eq_abs,probReal_univ,mul_one] using hh + +lemma exp_integral_le_of_integrable {H : S → ℝ} (hi : Integrable H μ) + (he : Integrable (fun x => Real.exp (H x)) μ) : + Real.exp (∫ x, H x ∂μ) ≤ ∫ x, Real.exp (H x) ∂μ := by + exact convexOn_exp.map_integral_le Real.continuous_exp.continuousOn isClosed_univ + (ae_of_all _ fun _ => mem_univ _) hi he + +lemma inverse_partition_power_le {H : S → ℝ} (hi : Integrable H μ) + (he : Integrable (fun x => Real.exp (H x)) μ) (k : ℕ) + (hk : Integrable (fun x => Real.exp (-(k:ℝ)*H x)) μ) : + (tiltPartition μ H 1)⁻¹^k ≤ ∫ x, Real.exp (-(k:ℝ)*H x) ∂μ := by + have h1 : Real.exp (∫ x, H x ∂μ) ≤ tiltPartition μ H 1 := by + simpa only [tiltPartition,one_mul] using exp_integral_le_of_integrable μ hi he + have h2 : (tiltPartition μ H 1)⁻¹ ≤ (Real.exp (∫ x, H x ∂μ))⁻¹ := + inv_anti₀ (Real.exp_pos _) h1 + calc + _ ≤ ((Real.exp (∫ x, H x ∂μ))⁻¹)^k := + pow_le_pow_left₀ (inv_nonneg.mpr (tilt_partition_pos_of_integrable μ (by simpa only [one_mul] using he)).le) h2 k + _ = Real.exp (-(k:ℝ)*(∫ x, H x ∂μ)) := by + rw [← Real.exp_neg,← Real.exp_nat_mul] + congr 1 + ring + _ = Real.exp (∫ x, -(k:ℝ)*H x ∂μ) := by rw [integral_const_mul] + _ ≤ _ := exp_integral_le_of_integrable μ (hi.const_mul _) hk + +end + +lemma abs_le_exp_add_exp_neg (a : ℝ) : |a| ≤ Real.exp a+Real.exp (-a) := by + by_cases ha : 0 ≤ a + · rw [abs_of_nonneg ha] + linarith [Real.add_one_le_exp a,Real.exp_pos (-a)] + · rw [abs_of_neg (lt_of_not_ge ha)] + linarith [Real.add_one_le_exp (-a),Real.exp_pos a] + +lemma abs_pow_mul_exp_le (h y : ℝ) (k : ℕ) : + |y|^k*Real.exp h ≤ (k.factorial:ℝ)*(Real.exp (h+y)+Real.exp (h-y)) := by + have hk : (0:ℝ).trans_eq (mul_comm _ _) + have h2 : Real.exp |y| ≤ Real.exp y+Real.exp (-y) := by + by_cases hy : 0 ≤ y + · rw [abs_of_nonneg hy] + exact le_add_of_nonneg_right (Real.exp_pos _).le + · rw [abs_of_neg (lt_of_not_ge hy)] + exact le_add_of_nonneg_left (Real.exp_pos _).le + calc + _ ≤ ((k.factorial:ℝ)*(Real.exp y+Real.exp (-y)))*Real.exp h := + mul_le_mul_of_nonneg_right (h1.trans (mul_le_mul_of_nonneg_left h2 hk.le)) (Real.exp_pos _).le + _ = _ := by + rw [mul_assoc,add_mul,← Real.exp_add,← Real.exp_add] + congr 1 + congr 1 <;> congr 1 <;> ring + +lemma integrable_of_exp_pos_neg {X : Type*} [MeasurableSpace X] (μ : Measure X) + {H : X → ℝ} (hm : Measurable H) + (hp : Integrable (fun x => Real.exp (H x)) μ) + (hn : Integrable (fun x => Real.exp (-H x)) μ) : Integrable H μ := by + apply (hp.add hn).mono' hm.aestronglyMeasurable + exact ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,Pi.add_apply] using abs_le_exp_add_exp_neg (H x) + +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +omit [IsProbabilityMeasure μ] in +lemma coupling_mgf_identity {H Y : S → ℝ} (hH : Measurable H) (a : ℝ) : + mgf Y (μ.withDensity (fun x => ENNReal.ofReal (Real.exp (H x)))) a = + tiltPartition μ (fun x => H x+a*Y x) 1 := by + rw [mgf,integral_withDensity_eq_integral_toReal_smul hH.exp.ennreal_ofReal + (ae_of_all _ fun _ => ENNReal.ofReal_lt_top)] + simp only [ENNReal.toReal_ofReal (Real.exp_pos _).le,smul_eq_mul,tiltPartition,one_mul,Real.exp_add] + +omit [IsProbabilityMeasure μ] in +lemma coupling_expSet {H Y : S → ℝ} (hH : Measurable H) (_hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) : + integrableExpSet Y (μ.withDensity (fun x => ENNReal.ofReal (Real.exp (H x)))) = univ := by + ext a + simp only [mem_univ,iff_true,integrableExpSet,mem_ofPred_eq] + apply (integrable_withDensity_iff_integrable_smul' hH.exp.ennreal_ofReal (ae_of_all _ fun _ => ENNReal.ofReal_lt_top)).mpr + simpa only [ENNReal.toReal_ofReal (Real.exp_pos _).le,smul_eq_mul,Real.exp_add] using he a + +lemma coupling_log_hasDerivAt {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) (a : ℝ) : + HasDerivAt (fun b => Real.log (tiltPartition μ (fun x => H x+b*Y x) 1)) + (tiltMean μ (fun x => H x+a*Y x) Y 1) a := by + let ρ := μ.withDensity (fun x => ENNReal.ofReal (Real.exp (H x))) + have hm : a ∈ interior (integrableExpSet Y ρ) := by + rw [coupling_expSet μ hH hY he,interior_univ] + trivial + have hp : 0 < mgf Y ρ a := by + rw [coupling_mgf_identity μ hH] + exact tilt_partition_pos_of_integrable μ (by simpa only [one_mul] using he a) + have hd := (hasDerivAt_mgf hm).log hp.ne' + have hf : (fun b => Real.log (mgf Y ρ b)) = + (fun b => Real.log (tiltPartition μ (fun x => H x+b*Y x) 1)) := by + funext b + rw [coupling_mgf_identity μ hH] + rw [hf] at hd + convert hd using 1 + rw [coupling_mgf_identity μ hH] + unfold tiltMean tiltIntegral + congr 1 + change _ = ∫ x, Y x*Real.exp (a*Y x) ∂ρ + rw [integral_withDensity_eq_integral_toReal_smul hH.exp.ennreal_ofReal + (ae_of_all _ fun _ => ENNReal.ofReal_lt_top)] + apply integral_congr_ae + filter_upwards [] with x + simp only [ENNReal.toReal_ofReal (Real.exp_pos _).le,smul_eq_mul,one_mul,Real.exp_add] + ring + +lemma coupling_log_second_derivative {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + (he : ∀ a : ℝ, Integrable (fun x => Real.exp (H x+a*Y x)) μ) (a : ℝ) : + iteratedDeriv 2 (fun b => Real.log (tiltPartition μ (fun x => H x+b*Y x) 1)) a = + tiltMean μ (fun x => H x+a*Y x) + (fun x => (Y x-tiltMean μ (fun x => H x+a*Y x) Y 1)^2) 1 := by + let ρ := μ.withDensity (fun x => ENNReal.ofReal (Real.exp (H x))) + have hm : a ∈ interior (integrableExpSet Y ρ) := by + rw [coupling_expSet μ hH hY he,interior_univ] + trivial + have hf : cgf Y ρ = (fun b => Real.log (tiltPartition μ (fun x => H x+b*Y x) 1)) := by + funext b + exact congrArg Real.log (coupling_mgf_identity μ hH b) + have hd : deriv (cgf Y ρ) a = tiltMean μ (fun x => H x+a*Y x) Y 1 := by + rw [hf] + exact (coupling_log_hasDerivAt μ hH hY he a).deriv + rw [← hf,iteratedDeriv_two_cgf_eq_integral hm,hd,coupling_mgf_identity μ hH] + unfold tiltMean tiltIntegral + congr 1 + rw [integral_withDensity_eq_integral_toReal_smul hH.exp.ennreal_ofReal + (ae_of_all _ fun _ => ENNReal.ofReal_lt_top)] + apply integral_congr_ae + filter_upwards [] with x + simp only [ENNReal.toReal_ofReal (Real.exp_pos _).le,smul_eq_mul,one_mul,Real.exp_add] + ring + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IntegrableProdConditionalSquare.lean b/lean/OAI/Probability/Perceptron/Variational/IntegrableProdConditionalSquare.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2096ee057a28d50b1f7b8fb05639068014830a7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IntegrableProdConditionalSquare.lean @@ -0,0 +1,136 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.PiMarkLaw + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy + +lemma integrable_prod_of_conditional_square {X Y : Type} [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure X) (ν : Measure Y) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + {F : X×Y → ℝ} {G : X → ℝ} (hF : Measurable F) (hG : MemLp G 2 μ) + (K : ℝ) (hs : ∀ x, MemLp (fun y => F (x,y)) 2 ν) + (hb : ∀ x, (∫ y, (F (x,y)-G x)^2 ∂ν) ≤ K) : Integrable F (μ.prod ν) := by + apply (integrable_prod_iff hF.aestronglyMeasurable).mpr + refine ⟨Eventually.of_forall (fun x => (hs x).integrable (by norm_num)),?_⟩ + have hi : Integrable (fun x => K+(G x)^2+1) μ := + ((integrable_const K).add hG.integrable_sq).add (integrable_const 1) + apply hi.mono' hF.aestronglyMeasurable.norm.integral_prod_right' + filter_upwards [] with x + rw [Real.norm_eq_abs,abs_of_nonneg (integral_nonneg (fun y => norm_nonneg _))] + have hi1 : Integrable (fun y => (F (x,y)-G x)^2) ν := + ((hs x).sub (memLp_const (G x))).integrable_sq + have hi2 : Integrable (fun y => (F (x,y)-G x)^2+(G x)^2) ν := hi1.add (integrable_const _) + calc + _ ≤ ∫ y, (F (x,y)-G x)^2+(G x)^2+1 ∂ν := by + apply integral_mono ((hs x).integrable (by norm_num)).norm + (hi2.add (integrable_const 1)) + intro y + change ‖F (x,y)‖ ≤ (F (x,y)-G x)^2+(G x)^2+1 + rw [Real.norm_eq_abs] + have h1 := sq_nonneg (|F (x,y)-G x|-1) + have h2 := sq_nonneg (|G x|-1) + have ht : |F (x,y)| ≤ |F (x,y)-G x|+|G x| := by + simpa using abs_sub_le (F (x,y)) (G x) 0 + nlinarith [sq_abs (F (x,y)-G x),sq_abs (G x)] + _ = (∫ y, (F (x,y)-G x)^2 ∂ν)+(G x)^2+1 := by + rw [integral_add hi2 (integrable_const 1),integral_add hi1 (integrable_const ((G x)^2))] + simp + _ ≤ K+(G x)^2+1 := by linarith [hb x] + +lemma finiteCascade_terminal_log_second_moment_bound {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + {H : X → ℝ} (hH : Measurable H) (hI : finiteCascadeFractionalIntegrable ν step H n z) (x : X) : + MemLp (fun η => Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step (fun _ => 0) n (x,η))) 2 (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) ∧ + (∫ η, (Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step (fun _ => 0) n (x,η))-finiteCascadeLogRecursion ν step n z H x)^2 + ∂decoratedCascadeLaw ν n z) ≤ cascadeLogFluctuationConstant n z := by + simp_rw [decoratedTerminalTotal_zero,decoratedTerminalTotal_telescoping ν step H n z] + exact decoratedCascade_log_second_moment_bound ν step hs n z hz hz0 hz1 _ + (finiteCascadeShifts_measurable ν step hs n z hH) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z (fun j => (hz0 j).ne') H hI i y).1) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z (fun j => (hz0 j).ne') H hI i y).2) x + (finiteCascadeLogRecursion ν step n z H x) + +theorem canonical_coordinate_joint_mean (d : ℕ) (σ : ℕ → ℝ) (b : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b n z) (r : ℝ≥0) : + let μ := (Measure.pi (fun _ : Fin d => gaussianReal 0 r)).prod + (decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) n z : + Measure (DecoratedCascade (Fin d → ℝ) n)) + let F := fun p => canonicalCoordinateLog d n σ b ((fun i _ => p.1 i),p.2) + Integrable F μ ∧ (∫ p, F p ∂μ) = d*canonicalGaussianFreeValue σ n z r b := by + let ν := decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) n z + let μ := Measure.pi (fun _ : Fin d => gaussianReal 0 r) + let F := fun p : (Fin d → ℝ)×DecoratedCascade (Fin d → ℝ) n => + canonicalCoordinateLog d n σ b ((fun i _ => p.1 i),p.2) + let P := quadraticCascadePrecision σ b n z + let A := (d : ℝ)*(-Real.log b/2+quadraticCascadeOffset σ b n z) + let G := fun x : Fin d → ℝ => A+(∑ i, (x i)^2)/(2*P) + have hG : MemLp G 2 μ := by + convert (memLp_const A).add ((gaussian_square_sum_memLp_two d r).mul_const (2*P)⁻¹) using 1 + ext x + simp only [G,div_eq_mul_inv,Pi.add_apply] + have hF : Measurable F := (canonicalCoordinateLog_measurable d n σ b z).comp + ((Measurable.of_eval (fun i => Measurable.of_eval (fun _ => + (measurable_pi_apply i).comp measurable_fst))).prodMk measurable_snd) + have hsec : ∀ x, MemLp (fun η => F (x,η)) 2 (ν : Measure _) ∧ + (∫ η, (F (x,η)-G x)^2 ∂ν) ≤ cascadeLogFluctuationConstant n z := by + intro x + have he := finiteCascade_terminal_log_second_moment_bound + (piMarkLaw (fun _ : Fin d => standardGaussianMark)) (canonicalCoordinateStep d σ) + (canonicalCoordinateStep_measurable d σ) n z hz hz0 hz1 + (canonicalCoordinatePotential_measurable d b) (canonical_coordinate_recursion d σ b n z hz0 hp).2 + (fun i _ => x i) + rw [(canonical_coordinate_recursion d σ b n z hz0 hp).1 (fun i _ => x i)] at he + exact he + have hi : Integrable F (μ.prod ν) := integrable_prod_of_conditional_square μ ν hF hG + (cascadeLogFluctuationConstant n z) (fun x => (hsec x).1) (fun x => (hsec x).2) + refine ⟨hi,?_⟩ + change (∫ p, F p ∂μ.prod ν) = _ + rw [integral_prod _ hi] + have he : ∀ x, (∫ η, F (x,η) ∂ν) = G x := by + intro x + exact canonical_coordinate_log_mean d σ b n z hz hz0 hz1 hp (fun i _ => x i) + simp_rw [he] + change (∫ x, A+(∑ i, (x i)^2)/(2*P) ∂μ) = _ + rw [integral_add (integrable_const A) + ((gaussian_square_sum_memLp_two d r).integrable (by norm_num) |>.div_const (2*P)),integral_div] + change (∫ _ : Fin d → ℝ, A ∂μ)+(∫ x : Fin d → ℝ, ∑ i, (x i)^2 ∂Measure.pi (fun _ => gaussianReal 0 r))/(2*P) = _ + rw [gaussian_square_sum_mean] + simp only [integral_const,probReal_univ,one_smul] + dsimp only [A,P,canonicalGaussianFreeValue] + ring + +lemma expected_eventually_gt_of_probability_lower + {Ω : ℕ → Type*} [∀ n, MeasurableSpace (Ω n)] + (μ : ∀ n, Measure (Ω n)) [∀ n, IsProbabilityMeasure (μ n)] + (X : ∀ n, Ω n → ℝ) (hi : ∀ n, Integrable (X n) (μ n)) + (hn : ∀ n, 0 ≤ᵐ[μ n] X n) {c : ℝ} + (hp : ∀ a : ℝ, a < c → + Tendsto (fun n => (μ n).real {ω | a ≤ X n ω}) atTop (𝓝 1)) : + ∀ b : ℝ, b < c → ∀ᶠ n in atTop, b < ∫ ω, X n ω ∂μ n := by + intro b hb + by_cases hb0 : b < 0 + · exact Eventually.of_forall fun n => hb0.trans_le (integral_nonneg_of_ae (hn n)) + · obtain ⟨a, hba, hac⟩ := exists_between hb + have he := (hp a hac).const_mul a + simp only [mul_one] at he + have hev : ∀ᶠ n in atTop, b < a*(μ n).real {ω | a ≤ X n ω} := + he.eventually (lt_mem_nhds hba) + filter_upwards [hev] with n hnb + exact hnb.trans_le (mul_meas_ge_le_integral_of_nonneg (hn n) (hi n) a) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IntegratedConvex.lean b/lean/OAI/Probability/Perceptron/Variational/IntegratedConvex.lean new file mode 100644 index 0000000000000000000000000000000000000000..83864e7ec6568a5fe519c0e7b116c18a199ee6f7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IntegratedConvex.lean @@ -0,0 +1,214 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.KernelReplicaGibbs +import OAI.Probability.Perceptron.Pressure.GaussianPressureDerivative + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators + +lemma convex_derivative_monotone {A a : ℝ→ℝ} (hc : ConvexOn ℝ univ A) + (hd : ∀ u, HasDerivAt A (a u) u) : Monotone a := by + intro x y hxy + simpa only [(hd x).deriv,(hd y).deriv] using + hc.monotoneOn_deriv (fun x _ => (hd x).differentiableAt) (mem_univ x) (mem_univ y) hxy + +lemma integral_convex_derivative_fluctuation {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {F : Ω→ℝ→ℝ} {A a : ℝ→ℝ} + {D : Ω→ℝ} {u s δ : ℝ} (hs : 0 F ω x) P) + (hb : ∀ x ∈ Icc (u-s) (u+s), (∫ ω, |F ω x-A x| ∂P)≤ δ) : + (∫ ω, |D ω-a u| ∂P) ≤ a (u+s)-a (u-s)+4*δ/s := by + have hm := convex_derivative_monotone hA ha + have hp := hA.slope_le_of_hasDerivAt (mem_univ u) (mem_univ (u+s)) + (by linarith : u linarith)) (hi u (by constructor <;> linarith)) + (hi (u-s) (by constructor <;> linarith)) + (hb (u+s) (by constructor <;> linarith)) (hb u (by constructor <;> linarith)) + (hb (u-s) (by constructor <;> linarith)) + simpa only [div_mul_cancel₀ _ (ne_of_gt hs)] using hh + +lemma convex_integrated_derivative_shift {A a : ℝ→ℝ} + (hc : ConvexOn ℝ univ A) (hd : ∀ u, HasDerivAt A (a u) u) + {s K : ℝ} (hs : 0≤ s) (hK : ∀ u ∈ Icc (1-s) (2+s), |a u|≤ K) : + (∫ u in (1:ℝ)..2, a (u+s)-a (u-s)) ≤ 4*K*s := by + have hm := convex_derivative_monotone hc hd + have hp : Monotone (fun u => a (u+s)) := hm.comp (fun _ _ h => by linarith) + have hn : Monotone (fun u => a (u-s)) := hm.comp (fun _ _ h => sub_le_sub_right h s) + rw [intervalIntegral.integral_sub hp.intervalIntegrable hn.intervalIntegrable, + intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun u _ => (hd (u+s)).comp_add_const u s) hp.intervalIntegrable, + intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun u _ => (hd (u-s)).comp_sub_const u s) hn.intervalIntegrable] + have ht (t : ℝ) (ht : t∈Icc (1:ℝ) 2) : |A (t+s)-A (t-s)|≤ 2*K*s := by + rw [← intervalIntegral.integral_eq_sub_of_hasDerivAt (fun u _ => hd u) hm.intervalIntegrable] + have hh : ‖∫ u in (t-s)..(t+s), a u‖≤ K*|(t+s)-(t-s)| := + intervalIntegral.norm_integral_le_of_norm_le_const (fun u hu => by + rw [uIoc_of_le (by linarith : t-s≤t+s)] at hu + exact hK u ⟨by linarith [ht.1,hu.1],by linarith [ht.2,hu.2]⟩) + have he : (t+s)-(t-s)=2*s := by ring + rw [he,abs_of_nonneg (by positivity)] at hh + simpa only [Real.norm_eq_abs] using hh.trans_eq (by ring) + have h1 := ht 1 (by norm_num) + have h2 := ht 2 (by norm_num) + linarith [le_abs_self (A (2+s)-A (2-s)),neg_abs_le (A (1+s)-A (1-s))] + +lemma integrated_convex_fluctuation_bound {H A a : ℝ→ℝ} + (hc : ConvexOn ℝ univ A) (hd : ∀ u, HasDerivAt A (a u) u) + {s K δ : ℝ} (hs : 0 a (u+s)) := hm.comp (fun _ _ h => by linarith) + have hn : Monotone (fun u => a (u-s)) := hm.comp (fun _ _ h => sub_le_sub_right h s) + calc + _ ≤ ∫ u in (1:ℝ)..2, a (u+s)-a (u-s)+4*δ/s := + intervalIntegral.integral_mono_on (by norm_num) hH + ((hp.intervalIntegrable.sub hn.intervalIntegrable).add intervalIntegrable_const) hb + _ = (∫ u in (1:ℝ)..2, a (u+s)-a (u-s))+4*δ/s := by + rw [intervalIntegral.integral_add (hp.intervalIntegrable.sub hn.intervalIntegrable) intervalIntegrable_const] + norm_num + _ ≤ _ := by linarith [convex_integrated_derivative_shift hc hd hs.le hK] + +variable {I : Type} [Fintype I] + +def countableGaussianVector (g : ℕ→ℝ) : EuclideanSpace ℝ I := + WithLp.toLp 2 (fun i => g (countableCoordinate i)) + +lemma countableGaussianVector_measurable : Measurable (countableGaussianVector (I:=I)) := by + unfold countableGaussianVector + fun_prop + +lemma countableGaussianVector_law : + countableGaussianLaw.map (countableGaussianVector (I:=I))=stdGaussian (EuclideanSpace ℝ I) := by + let c : (ℕ→ℝ)→I→ℝ := fun g i => g (countableCoordinate i) + have hc : Measurable c := by fun_prop + have hl : countableGaussianLaw.map c=Measure.infinitePi (fun _ : I => gaussianReal 0 1) := + Measure.map_infinitePi_infinitePi_of_inj countableCoordinate_injective + change countableGaussianLaw.map ((WithLp.toLp 2) ∘ c)=_ + rw [← Measure.map_map (PiLp.continuous_toLp 2 _).measurable hc,hl, + Measure.infinitePi_eq_pi,map_pi_eq_stdGaussian] + +lemma countableGaussianVector_preserving : + MeasurePreserving (countableGaussianVector (I:=I)) countableGaussianLaw (stdGaussian (EuclideanSpace ℝ I)) := + ⟨countableGaussianVector_measurable,countableGaussianVector_law⟩ + +def vectorGaussianRow {S : Type*} (V : S→EuclideanSpace ℝ I) (i : ℕ) (x : S) : ℝ := + finiteGaussianRow countableCoordinate (fun j => V x j) i + +def vectorGaussianLength (I : Type) [Fintype I] : ℕ := + finiteGaussianRowLength (countableCoordinate (ι:=I)) + +lemma vectorGaussianRow_measurable {S : Type*} [MeasurableSpace S] + {V : S→EuclideanSpace ℝ I} (hV : Measurable V) (i : ℕ) : Measurable (vectorGaussianRow V i) := by + classical + unfold vectorGaussianRow finiteGaussianRow + apply Finset.measurable_sum + intro j _ + split_ifs + · exact (EuclideanSpace.proj j).continuous.measurable.comp hV + · exact measurable_const + +lemma vectorGaussianRow_field {S : Type*} (V : S→EuclideanSpace ℝ I) (g : ℕ→ℝ) (x : S) : + countableGaussianField (vectorGaussianRow V) (fun _ => vectorGaussianLength I) g x= + inner ℝ (V x) (countableGaussianVector g) := by + unfold countableGaussianField gaussianPrefixField vectorGaussianRow vectorGaussianLength + rw [finiteGaussianRow_field countableCoordinate_injective] + rfl + +lemma vectorGaussianRow_norm {S : Type*} (V : S→EuclideanSpace ℝ I) (x : S) : + (∑ i : Fin (vectorGaussianLength I), vectorGaussianRow V i.val x^2)=‖V x‖^2 := by + unfold vectorGaussianRow vectorGaussianLength + rw [finiteGaussianRow_norm countableCoordinate_injective,← real_inner_self_eq_norm_sq] + change (∑ i, V x i^2)=∑ i, V x i*V x i + simp only [pow_two] + +lemma vectorGaussianRow_covariance {S : Type*} (V W : S→EuclideanSpace ℝ I) (x y : S) : + countableGaussianCovariance (vectorGaussianRow V) (vectorGaussianRow W) + (fun _ => vectorGaussianLength I) x y = inner ℝ (W x) (V y) := by + unfold countableGaussianCovariance gaussianPrefixCovariance maskedGaussianCoefficient + simp only [Fin.is_lt,ite_true] + change (∑ i : Fin (vectorGaussianLength I), + finiteGaussianRow countableCoordinate (fun j => W x j) i.val * + finiteGaussianRow countableCoordinate (fun j => V y j) i.val)=_ + calc + _ = ∑ j, W x j*finiteGaussianRow countableCoordinate (fun k => V y k) (countableCoordinate j) := + finiteGaussianRow_sum countableCoordinate_injective (fun j => W x j) + (fun i a => a*finiteGaussianRow countableCoordinate (fun j => V y j) i) (by simp) + _ = ∑ j, W x j*V y j := by simp_rw [finiteGaussianRow_key countableCoordinate_injective] + _ = _ := by + change (∑ i, W x i*V y i)=∑ i, V y i*W x i + exact Finset.sum_congr rfl fun _ _ => mul_comm _ _ + +lemma euclideanGaussian_tiltMean_ibp {S : Type*} [MeasurableSpace S] + (μ : Measure S) [IsProbabilityMeasure μ] {H : S→ℝ} {V W : S→EuclideanSpace ℝ I} + (hH : Measurable H) (hV : Measurable V) (hW : Measurable W) + {A D E : ℝ} (hA : ∀ x, |H x|≤A) (hD : ∀ x, ‖V x‖^2≤D) (hE : ∀ x, ‖W x‖^2≤E) : + (∫ g, tiltMean μ (fun x => H x+inner ℝ (V x) g) (fun x => inner ℝ (W x) g) 1 + ∂stdGaussian (EuclideanSpace ℝ I)) = + ∫ g, tiltMean μ (fun x => H x+inner ℝ (V x) g) (fun x => inner ℝ (W x) (V x)) 1 - + gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) 2 + (fun x => inner ℝ (W (x 1)) (V (x 0))) ∂stdGaussian (EuclideanSpace ℝ I) := by + have h1 : Measurable (fun a : EuclideanSpace ℝ I × S => H a.2+inner ℝ (V a.2) a.1) := + (hH.comp measurable_snd).add ((hV.comp measurable_snd).inner measurable_fst) + have h2 : Measurable (fun a : EuclideanSpace ℝ I × S => inner ℝ (W a.2) a.1) := + (hW.comp measurable_snd).inner measurable_fst + have h3 : Measurable (fun x => inner ℝ (W x) (V x)) := hW.inner hV + have h4 : Measurable (fun x : Fin 2→S => inner ℝ (W (x 1)) (V (x 0))) := + (hW.comp (measurable_pi_apply 1)).inner (hV.comp (measurable_pi_apply 0)) + have hleft := kernel_tiltMean_measurable (Kernel.const (EuclideanSpace ℝ I) μ) + (H := fun g x => H x+inner ℝ (V x) g) (Y := fun g x => inner ℝ (W x) g) h1 h2 + have hright := (kernel_tiltMean_measurable (Kernel.const (EuclideanSpace ℝ I) μ) + (H := fun g x => H x+inner ℝ (V x) g) (Y := fun _ x => inner ℝ (W x) (V x)) h1 + (h3.comp measurable_snd)).sub (kernel_replicaMean_measurable (Kernel.const (EuclideanSpace ℝ I) μ) + (H := fun g x => H x+inner ℝ (V x) g) + (G := fun _ x => inner ℝ (W (x 1)) (V (x 0))) h1 (h4.comp measurable_snd)) + have he := annealedGaussianTiltMean_ibp μ hH (vectorGaussianRow_measurable hV) + (vectorGaussianRow_measurable hW) measurable_const hA + (fun x => (vectorGaussianRow_norm V x).trans_le (hD x)) + (fun x => (vectorGaussianRow_norm W x).trans_le (hE x)) + have hham (g) : countableGaussianHamiltonian H (vectorGaussianRow V) + (fun _ => vectorGaussianLength I) g = fun x => H x+inner ℝ (V x) (countableGaussianVector g) := by + funext x + exact congrArg (fun y => H x+y) (vectorGaussianRow_field V g x) + have hfield (g) : countableGaussianField (vectorGaussianRow W) + (fun _ => vectorGaussianLength I) g = fun x => inner ℝ (W x) (countableGaussianVector g) := + funext (vectorGaussianRow_field W g) + simp_rw [hham,hfield,vectorGaussianRow_covariance] at he + simp only [Kernel.const_apply] at hleft hright + change Measurable (fun g => tiltMean μ (fun x => H x+inner ℝ (V x) g) + (fun x => inner ℝ (W x) (V x)) 1 - gibbsReplicaMean μ (fun x => H x+inner ℝ (V x) g) 2 + (fun x => inner ℝ (W (x 1)) (V (x 0)))) at hright + rw [← countableGaussianVector_law (I:=I), + integral_map countableGaussianVector_measurable.aemeasurable hleft.aestronglyMeasurable, + integral_map countableGaussianVector_measurable.aemeasurable hright.aestronglyMeasurable] + exact he + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/IntegratedThermal.lean b/lean/OAI/Probability/Perceptron/Variational/IntegratedThermal.lean new file mode 100644 index 0000000000000000000000000000000000000000..8fbc26a1cfcb050486a88f35e3a588619f670c11 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/IntegratedThermal.lean @@ -0,0 +1,103 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkThermal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma integral_sqrt_le_sqrt_integral_probability {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {F : Ω→ℝ} + (hF : Measurable F) (hI : Integrable F P) (h0 : ∀ x, 0≤F x) : + (∫ x, Real.sqrt (F x) ∂P)≤Real.sqrt (∫ x, F x ∂P) := by + have hs : (fun x => (Real.sqrt (F x))^2)=F := funext fun x => Real.sq_sqrt (h0 x) + have hLp : MemLp (fun x => Real.sqrt (F x)) 2 P := + (memLp_two_iff_integrable_sq hF.sqrt.aestronglyMeasurable).mpr (by simpa only [hs] using hI) + have hv := variance_nonneg (fun x => Real.sqrt (F x)) P + rw [variance_eq_sub hLp] at hv + simp only [Pi.pow_apply] at hv + change 0≤(∫ x, (Real.sqrt (F x))^2 ∂P)-(∫ x, Real.sqrt (F x) ∂P)^2 at hv + rw [hs] at hv + exact (Real.le_sqrt (integral_nonneg fun x => Real.sqrt_nonneg _) (integral_nonneg h0)).mpr (by linarith) + +lemma annealed_centered_energy_bound {S Ω : Type*} [MeasurableSpace S] [MeasurableSpace Ω] + (μ : Measure S) [IsProbabilityMeasure μ] (P : Measure Ω) [IsProbabilityMeasure P] + {H Y : Ω→S→ℝ} (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + {A B : Ω→ℝ} (hA : ∀ a, 0≤A a) (hB : ∀ a, 0≤B a) + (hHA : ∀ a x, |H a x|≤A a) (hYB : ∀ a x, |Y a x|≤B a) + (hB2 : MemLp B 2 P) : + (∫ a, tiltMean μ (H a) (fun x => |Y a x-∫ b, tiltMean μ (H b) (Y b) 1 ∂P|) 1 ∂P) ≤ + Real.sqrt (∫ a, thermalVar μ (H a) (Y a) 0 ∂P)+ + ∫ a, |tiltMean μ (H a) (Y a) 1-∫ b, tiltMean μ (H b) (Y b) 1 ∂P| ∂P := by + let M := fun a => tiltMean μ (H a) (Y a) 1 + let E := ∫ a, M a ∂P + let U := fun a => tiltMean μ (H a) (fun x => |Y a x-M a|) 1 + have hM : Measurable M := measurable_tiltMean_param μ hH hY + have hU : Measurable U := measurable_tiltMean_param μ hH (hY.sub (hM.comp measurable_fst)).abs + have hHm (a) : Measurable (H a) := hH.comp (measurable_const.prodMk measurable_id) + have hYm (a) : Measurable (Y a) := hY.comp (measurable_const.prodMk measurable_id) + have hMB (a) : |M a|≤B a := tilt_mean_bound μ (hHm a) (hYm a) (hA a) (hB a) (hHA a) (hYB a) 1 + have hBI := hB2.integrable (by norm_num) + have hUI : Integrable U P := by + apply (hBI.const_mul 2).mono' hU.aestronglyMeasurable + exact ae_of_all _ fun a => by + simpa only [Real.norm_eq_abs] using tilt_mean_bound μ (hHm a) + ((hYm a).sub_const (M a) |>.abs) (hA a) (mul_nonneg (by norm_num) (hB a)) (hHA a) + (fun x => by rw [abs_abs]; exact (abs_sub _ _).trans (by linarith [hYB a x,hMB a])) 1 + have hMI : Integrable (fun a => |M a-E|) P := + ((hBI.mono' hM.aestronglyMeasurable (ae_of_all _ fun a => by simpa only [Real.norm_eq_abs] using hMB a)).sub (integrable_const E)).abs + have hQI : Integrable (fun a => tiltMean μ (H a) (fun x => |Y a x-E|) 1) P := by + apply (hBI.add (integrable_const |E|)).mono' + (measurable_tiltMean_param μ hH + (show Measurable (Function.uncurry (fun a x => |Y a x-E|)) from (hY.sub_const E).abs)).aestronglyMeasurable + exact ae_of_all _ fun a => by + simpa only [Real.norm_eq_abs,Pi.add_apply] using tilt_mean_bound μ (hHm a) + ((hYm a).sub_const E |>.abs) (hA a) (add_nonneg (hB a) (abs_nonneg E)) (hHA a) + (fun x => by rw [abs_abs]; exact (abs_sub _ _).trans (add_le_add (hYB a x) le_rfl)) 1 + have hs : (∫ a, U a ∂P)^2≤∫ a, thermalVar μ (H a) (Y a) 0 ∂P := by + simpa only [zero_mul,add_zero] using annealed_thermal_abs_sq_le μ P hH hY hA hB hHA hYB hB2 0 + have hu : (∫ a, U a ∂P)≤Real.sqrt (∫ a, thermalVar μ (H a) (Y a) 0 ∂P) := + (Real.le_sqrt (integral_nonneg fun a => tiltMean_nonneg μ (fun _ => abs_nonneg _) 1) + ((sq_nonneg _).trans hs)).mpr hs + have ht : (∫ a, tiltMean μ (H a) (fun x => |Y a x-E|) 1 ∂P)≤ + (∫ a, U a ∂P)+(∫ a, |M a-E| ∂P) := by + rw [← integral_add hUI hMI] + exact integral_mono hQI (hUI.add hMI) fun a => + tilt_mean_center_triangle μ (hHm a) (hYm a) (hA a) (hHA a) (hYB a) E (M a) + exact ht.trans (add_le_add hu le_rfl) + +lemma bulkThermalSqrt_intervalIntegrable (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) (a b : ℝ) : + IntervalIntegrable (fun u => Real.sqrt (∫ x, bulkThermalVar n M f v p u x ∂bulkDisorderLaw (n+1) M)) volume a b := by + have hm := (bulkExpectedThermalVar_measurable n M f v p).sqrt + have hs (u : ℝ) : (Real.sqrt (∫ x, bulkThermalVar n M f v p u x ∂bulkDisorderLaw (n+1) M))^2= + ∫ x, bulkThermalVar n M f v p u x ∂bulkDisorderLaw (n+1) M := + Real.sq_sqrt (integral_nonneg (bulkThermalVar_nonneg n M f v p u)) + have hi := bulkExpectedThermalVar_intervalIntegrable n M f v p a b + constructor + · exact ((memLp_two_iff_integrable_sq hm.aestronglyMeasurable).mpr (by simpa only [IntegrableOn,hs] using hi.1)).integrable (by norm_num) + · exact ((memLp_two_iff_integrable_sq hm.aestronglyMeasurable).mpr (by simpa only [IntegrableOn,hs] using hi.2)).integrable (by norm_num) + +lemma bulkThermalSqrt_integrated_bound (n M : ℕ) (f : ℝ→ᵇℝ) (v : ℕ→ℝ) (p : Fin (n+1)) : + (∫ u in (1:ℝ)..2, Real.sqrt (∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M))≤ + Real.sqrt 6*bulkCoefficient (n+1) p := by + let P := volume.restrict (Ioc (1:ℝ) 2) + have : IsProbabilityMeasure P := ⟨by norm_num [P]⟩ + have hi : Integrable (fun u => ∫ a, bulkThermalVar n M f v p u a ∂bulkDisorderLaw (n+1) M) P := + (bulkExpectedThermalVar_intervalIntegrable n M f v p 1 2).1 + have he := integral_sqrt_le_sqrt_integral_probability P + (bulkExpectedThermalVar_measurable n M f v p) hi + (fun u => integral_nonneg (bulkThermalVar_nonneg n M f v p u)) + rw [intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤2)] + apply he.trans + have hb := bulkThermalVar_integrated_bound n M f v p + rw [intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤2)] at hb + calc + _ ≤ Real.sqrt (6*bulkCoefficient (n+1) p^2) := Real.sqrt_le_sqrt hb + _ = _ := by rw [Real.sqrt_mul (by norm_num),Real.sqrt_sq (bulkCoefficient_pos n p).le] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/KernelProductIntegral.lean b/lean/OAI/Probability/Perceptron/Variational/KernelProductIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..4413f7dfe6f99e51775e6d47e7ed9b75a289caa2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/KernelProductIntegral.lean @@ -0,0 +1,25 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory +namespace SphericalPerceptronFreeEnergy +lemma measurable_kernel_product_integral {X A B Y : Type*} + [MeasurableSpace X] [MeasurableSpace A] [MeasurableSpace B] [MeasurableSpace Y] + (κ : Kernel A B) [IsSFiniteKernel κ] (ν : Measure Y) [SFinite ν] + (a : X→A) (ha : Measurable a) (F : X×(B×Y)→ℝ) (hF : Measurable F) : + Measurable (fun x=>∫ u,F (x,u) ∂(κ (a x)).prod ν) := by + let κ' : Kernel X (B×Y):=(κ.comap a ha).prod (Kernel.const X ν) + have h := hF.stronglyMeasurable.integral_kernel_prod_right (κ:=κ') (f:=fun x u=>F (x,u)) + have he (x : X) : κ' x=(κ (a x)).prod ν := by + change ((κ.comap a ha).prod (Kernel.const X ν)) x=_ + rw [Kernel.prod_apply] + rfl + simpa only [he] using h.measurable +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelPairTestValue.lean b/lean/OAI/Probability/Perceptron/Variational/LabelPairTestValue.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c86bb2156c1f92446833e174e201f07840470ae --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelPairTestValue.lean @@ -0,0 +1,173 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelProfileReferenceFull +import OAI.Probability.Perceptron.Cavity.BulkMarkedMoments +import OAI.Probability.Perceptron.Interpolation.RestorationReplicaBlocks +import OAI.Probability.Perceptron.Variational.LabelRestorationMoments2 +import OAI.Probability.Perceptron.Variational.LabelRestoredValue + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +def labelProfilePairTest {k : ℕ} (q : Fin (k+1)→Time) (F : CompactOverlap →ᵇ ℝ) : + CompactBlock CompactJointOverlap 2 →ᵇ ℝ := + F.compContinuous ⟨fun Q => labelProfileSpin q (Q 1 0).2, + (labelProfileSpin_continuous q).comp (by fun_prop)⟩ + +lemma labelProfilePairTest_source (N k : ℕ) (q : Fin (k+1)→Time) (F : CompactOverlap →ᵇ ℝ) + (x : Fin 2→NormalizedSpin N×IndexedLeaf k) : + labelProfilePairTest q F (fun i j => sourceJointOverlap (x i) (x j))= + F (timeSpin (q (indexedCommonDepth k (x 0).2 (x 1).2))) := by + change F (labelProfileSpin q (sourceLabelLevel k (indexedCommonDepth k (x 0).2 (x 1).2)))=_ + rw [labelProfileSpin_node] + +lemma sourceLabelRestorationRatio_pair_value (n k : ℕ) (f : ℝ →ᵇ ℝ) (g : Jet3) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (hh0 : ∀ i,0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (q : Fin (k+1)→Time) (s : ℝ≥0) (v w : ℝ →ᵇ ℝ) + (F : CompactOverlap →ᵇ ℝ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i,0 (q i:ℝ)) s f g.f (fun _ => v) (fun _ => w) + (labelProfilePairTest q F) p e h u z t = + ∑ d, F (timeSpin (q d))*(twoVisitMass k z d).toReal* + (labelPairCoefficient k z (fun i => (q i:ℝ)) g s v d * + labelPairCoefficient k z (fun i => (q i:ℝ)) g s w d) := by + rw [sourceLabelRestorationRatio_eq _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ hh0 hh] + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + have hae := (measurePreserving_fst (μ:=P) (ν:=countableGaussianLaw.prod countableGaussianLaw)).quasiMeasurePreserving.ae + (sourceFresh_exp_ae n k f p e h hh0 hh u z t) + have he : (fun a => labelKernelRestoredRatio (sourceFullSpinLeafKernel n k) + (sourceCouplingHamiltonian n k f p e h u) (fun i => (q i:ℝ)) s g.f (fun _ : Fin 2 => v) (fun _ => w) + (fun x => labelProfilePairTest q F (fun i j => sourceJointOverlap (x i) (x j))) a) =ᵐ[P.prod (countableGaussianLaw.prod countableGaussianLaw)] + (fun a => ∑ d, F (timeSpin (q d))*sourceLabelPairIntegrand n k f p e h u (fun i => (q i:ℝ)) g s d v w a) := by + filter_upwards [hae] with a ha + simp only [labelProfilePairTest_source] + exact labelKernelRestoredRatio_depth k _ _ (sourceCouplingHamiltonian_measurable n k f p e h u) + _ s g.f v w (fun d => F (timeSpin (q d))) a ha + rw [integral_congr_ae he,integral_finsetSum _ (fun d _ => + (sourceLabelPairIntegrand_integrable n k f p e h hh0 hh u (fun i => (q i:ℝ)) g s d v w z t).const_mul _)] + simp only [integral_const_mul,sourceLabelPairIntegrand_value n k f p e h hh0 hh u _ g s _ v w z hz hz0 hz1 t,mul_assoc] + +def scalarPairMatrixTest (F : CompactOverlap →ᵇ ℝ) : Matrix (Fin 2) (Fin 2) ℝ →ᵇ ℝ := + F.compContinuous ⟨fun Q => Set.projIcc (-1) 1 (by norm_num) (Q 1 0), + by fun_prop⟩ + +def scalarFrontMatrixTest (r : ℕ) (F : Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ) : + (j : ℕ) → Matrix (Fin (r+j)) (Fin (r+j)) ℝ →ᵇ ℝ + | 0 => F + | j+1 => (scalarFrontMatrixTest r F j).compContinuous + ⟨fun Q i l => Q i.succ l.succ,by fun_prop⟩ + +def scalarRestorationPairMoment (f v w : ℝ →ᵇ ℝ) (F : CompactOverlap →ᵇ ℝ) (j : ℕ) : + Matrix (Fin (2+j)) (Fin (2+j)) ℝ →ᵇ ℝ := + scalarFrontMatrixTest 2 (scalarPairMatrixTest F) j * + freshMarkedMatrixKernel (gaussianMixedTest (labelRestoredFunctions f (fun _ : Fin 2 => v) j)) * + freshMarkedMatrixKernel (gaussianMixedTest (labelRestoredFunctions f (fun _ : Fin 2 => w) j)) + +lemma restorationMarkTest_gaussianMixed {r : ℕ} (f : ℝ →ᵇ ℝ) (v : Fin r → ℝ →ᵇ ℝ) (j : ℕ) : + restorationMarkTest r f (gaussianMixedTest v) j = + gaussianMixedTest (labelRestoredFunctions f v j) := by + induction j with + | zero => + ext x + simp only [restorationMarkTest,BoundedContinuousFunction.mul_apply,gaussianReplicaTest_apply, + gaussianMixedTest_apply,labelRestoredFunctions,Finset.prod_mul_distrib] + rfl + | succ j hj => + ext x + change (expBCF 1 f) (x 0) * restorationMarkTest r f (gaussianMixedTest v) j + (WithLp.toLp 2 (fun i => x i.succ)) = + gaussianMixedTest (Fin.cons (expBCF 1 f) (labelRestoredFunctions f v j)) x + rw [hj] + simp only [gaussianMixedTest_apply,Fin.prod_univ_succ,Fin.cons_zero,Fin.cons_succ] + +def compactPairTest (F : CompactOverlap →ᵇ ℝ) : CompactBlock CompactOverlap 2 →ᵇ ℝ := + F.compContinuous ⟨fun Q => Q 1 0,by fun_prop⟩ + +lemma scalarFrontMatrixTest_compact (r : ℕ) (F : Matrix (Fin r) (Fin r) ℝ →ᵇ ℝ) + (j : ℕ) (Q : CompactBlock CompactOverlap (r+j)) : + scalarFrontMatrixTest r F j (fun i l => (Q i l).val) = + restorationBlockTest r (F.compContinuous ⟨fun Q i l => (Q i l).val,by fun_prop⟩) j Q := by + induction j with + | zero => rfl + | succ j hj => exact hj _ + +lemma scalarRestorationPairMoment_compact (f v w : ℝ →ᵇ ℝ) (F : CompactOverlap →ᵇ ℝ) + (j : ℕ) (Q : CompactBlock CompactOverlap (2+j)) : + scalarRestorationPairMoment f v w F j (fun i l => (Q i l).val) = + (restorationBlockTest 2 (compactPairTest F) j * + freshMarkedCompactBlockKernel (restorationMarkTest 2 f (gaussianMixedTest (fun _ => v)) j) * + freshMarkedCompactBlockKernel (restorationMarkTest 2 f (gaussianMixedTest (fun _ => w)) j)) Q := by + have he : (scalarPairMatrixTest F).compContinuous + ⟨fun Q : CompactBlock CompactOverlap 2 => fun i l => (Q i l).val,by fun_prop⟩=compactPairTest F := by + ext Q + change F (Set.projIcc (-1) 1 (by norm_num : (-1:ℝ)≤1) (Q 1 0).val)=F (Q 1 0) + rw [Set.projIcc_of_mem _ (Q 1 0).prop] + change scalarFrontMatrixTest 2 (scalarPairMatrixTest F) j (fun i l => (Q i l).val) * + freshMarkedMatrixKernel _ (fun i l => (Q i l).val) * freshMarkedMatrixKernel _ (fun i l => (Q i l).val) = _ + rw [scalarFrontMatrixTest_compact,he] + simp only [BoundedContinuousFunction.mul_apply,restorationMarkTest_gaussianMixed] + rfl + +def labelProfileGram {k r : ℕ} (q : Fin (k+1)→Time) (Q : CompactBlock CompactJointOverlap r) : + Matrix (Fin r) (Fin r) ℝ := fun i l => if i=l then 1 else (labelProfileSpin q (Q i l).2).val + +lemma scalarFrontMatrixTest_label {k : ℕ} (q : Fin (k+1)→Time) (F : CompactOverlap →ᵇ ℝ) + (j : ℕ) (Q : CompactBlock CompactJointOverlap (2+j)) : + scalarFrontMatrixTest 2 (scalarPairMatrixTest F) j (labelProfileGram q Q) = + jointRestorationBlockTest 2 (labelProfilePairTest q F) j Q := by + induction j with + | zero => + change F (Set.projIcc (-1) 1 (by norm_num : (-1:ℝ)≤1) (if (1 : Fin 2)=0 then 1 else (labelProfileSpin q (Q 1 0).2).val)) = _ + simp only [show (1 : Fin 2) ≠ 0 by decide,ite_false,Set.projIcc_of_mem _ (labelProfileSpin q (Q 1 0).2).prop] + rfl + | succ j hj => + change scalarFrontMatrixTest 2 (scalarPairMatrixTest F) j (fun i l => labelProfileGram q Q i.succ l.succ) = _ + have he : (fun i l => labelProfileGram q Q i.succ l.succ)=labelProfileGram q (fun i l => Q i.succ l.succ) := by + funext i l + simp only [labelProfileGram,Fin.succ_inj] + exact (congrArg (fun M : Matrix (Fin (2+j)) (Fin (2+j)) ℝ => scalarFrontMatrixTest 2 (scalarPairMatrixTest F) j M) he).trans (hj _) + +lemma labelMarkedBlockKernel_profile {k r : ℕ} (q : Fin (k+1)→Time) + (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) (Q : CompactBlock CompactJointOverlap r) + (hN : ∀ i l,(Q i l).2∈Set.range (sourceLabelLevel k)) : + labelMarkedBlockKernel (fun i => (q i:ℝ)) Ψ Q = freshMarkedMatrixKernel Ψ (labelProfileGram q Q) := by + apply congrArg (freshMarkedMatrixKernel Ψ) + funext i l + change (if i=l then 1 else labelProfileInterpolant (fun i => (q i:ℝ)) (Q i l).2)=_ + by_cases hil : i=l + · simp only [hil,labelProfileGram,ite_true] + · obtain ⟨d,hd⟩ := hN i l + simp only [labelProfileGram,ite_eq_right hil,←hd,labelProfileInterpolant_node,labelProfileSpin_node,timeSpin] + +lemma scalarRestorationPairMoment_label {k : ℕ} (q : Fin (k+1)→Time) + (f v w : ℝ →ᵇ ℝ) (F : CompactOverlap →ᵇ ℝ) (j : ℕ) + (Q : CompactBlock CompactJointOverlap (2+j)) + (hN : ∀ i l,(Q i l).2∈Set.range (sourceLabelLevel k)) : + scalarRestorationPairMoment f v w F j (labelProfileGram q Q) = + labelRestorationBlockMoment (fun i => (q i:ℝ)) f (fun _ => v) (fun _ => w) + (labelProfilePairTest q F) j Q := by + simp only [scalarRestorationPairMoment,labelRestorationBlockMoment,BoundedContinuousFunction.mul_apply, + scalarFrontMatrixTest_label,labelMarkedBlockKernel_profile q _ Q hN] + +lemma scalarRestorationPairMoment_diagonalMap {k : ℕ} (q : Fin (k+1)→Time) + (f v w : ℝ →ᵇ ℝ) (F : CompactOverlap →ᵇ ℝ) (j : ℕ) + (Q : CompactArray CompactJointOverlap) (hN : CompactLabelNodes k Q) : + scalarRestorationPairMoment f v w F j (fun i l => + (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal Q i l).1.val) = + labelRestorationBlockMoment (fun i => (q i:ℝ)) f (fun _ => v) (fun _ => w) + (labelProfilePairTest q F) j (compactBlock (2+j) Q) := by + have he : (fun i l : Fin (2+j) => (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal Q i l).1.val)= + labelProfileGram q (compactBlock (2+j) Q) := by + funext i l + simp only [compactDiagonalMapArray,labelProfileGram,Fin.val_inj] + split_ifs <;> rfl + rw [he] + exact scalarRestorationPairMoment_label q f v w F j _ (fun i l => hN i l) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelProfilePairReference.lean b/lean/OAI/Probability/Perceptron/Variational/LabelProfilePairReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..c15c84b6819cfaddd53383eaca69587d3e3a3b27 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelProfilePairReference.lean @@ -0,0 +1,203 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.QuantileReference +import OAI.Probability.Perceptron.Variational.CompactRestorationWitness +import OAI.Probability.Perceptron.Cascade.TwoVisitWeights + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +theorem labelProfile_pair_reference_exists (k : ℕ) (w : Fin (k+1)→ℝ) + (hw : ∀ l,0 (Q i l).1.val) ∂(ν : Measure _)) ∧ + (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v v' F))))= + ∑ d,w d*F (timeSpin (q d))* + (labelPairCoefficient k (stepCumulative w) (fun i => (q i:ℝ)) g + (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) v d * + labelPairCoefficient k (stepCumulative w) (fun i => (q i:ℝ)) g + (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) v' d) := by + let p := fun n => (Nat.unpair n).1 + let d := fun n => (Nat.unpair n).2 + have hcover : ∀ a b : ℕ, 1≤a+b → ∃ j,p j=a ∧ d j=b := by + intro a b _ + exact ⟨Nat.pair a b,by simp [p,d]⟩ + obtain ⟨u,ρ,s,hu,hs,hlim,hGG,hex,hpair,hgeo⟩ := source_label_reference_exists k w hw hw1 p d hcover + have hL := sourceGibbsArray_limit_label_geometry k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + have hN := sourceGibbsArray_limit_label_nodes k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + let ν := compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + obtain ⟨η,hm,hl⟩ := sourceLabelPair_witness k q hq 0 g v v' F + (fun _ j=>p j.val) (fun _ j=>d j.val) (fun _ _=>0) (fun _ _=>le_rfl) + (fun _=>monotone_const) u (stepCumulative w) (stepCumulative_strictMono w hw) + (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1) (fun _=>0) s hlim + refine ⟨ν,η,compactDiagonalMapLaw_gg _ _ _ _ ρ hGG,?_,?_,?_,?_⟩ + · change ∀ᵐ Q ∂(ρ : Measure (CompactArray CompactJointOverlap)).map + (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal), CompactSpinGeometry Q + apply (ae_map_iff (compactDiagonalMapArray_continuous (labelProfileMap_continuous q) labelProfileDiagonal_continuous).measurable.aemeasurable + compactSpinGeometry_closed.measurableSet).mpr + filter_upwards [hL,hN] with Q hLQ hNQ + exact labelProfileDiagonalMap_geometry q hq hLQ hNQ + · intro A + change (∫ Q : CompactArray CompactJointOverlap, A (Q 0 1).1 + ∂(compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ : Measure _))=_ + rw [compactDiagonalMapLaw_integral (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + (fun Q => A (Q 0 1).1) (by fun_prop)] + have he : (∫ Q, A (labelProfileSpin q (Q 0 1).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)))= + ∫ Q, A (labelProfileSpin q (Q 1 0).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)) := by + apply integral_congr_ae + filter_upwards [hL] with Q hLQ + rw [show (Q 0 1).2=(Q 1 0).2 from Subtype.ext (hLQ.1 0 1)] + change (∫ Q, A (labelProfileSpin q (Q 0 1).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)))=_ + have hmap : (∫ x, A (labelProfileSpin q x) ∂((ρ : Measure (CompactArray CompactJointOverlap)).map + (fun Q => (Q 1 0).2)))=∫ Q, A (labelProfileSpin q (Q 1 0).2) + ∂(ρ : Measure (CompactArray CompactJointOverlap)) := + integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 1 0).2) + from by fun_prop).aemeasurable + (show Measurable (fun x : Time => A (labelProfileSpin q x)) from + A.measurable.comp (labelProfileSpin_continuous q).measurable).aestronglyMeasurable + rw [he,←hmap,hpair,sourceLabelLaw_integral k w (fun l => (hw l).le) (fun x => A (labelProfileSpin q x)) + (A.measurable.comp (labelProfileSpin_continuous q).measurable)] + simp_rw [labelProfileSpin_node] + · intro j + rw [hm j] + change _=∫ Q : CompactArray CompactJointOverlap,scalarRestorationPairMoment g.f v v' F j (fun i l => (Q i l).1.val) + ∂(compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal + (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ : Measure _) + rw [compactDiagonalMapLaw_integral (labelProfileMap q) labelProfileDiagonal + (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + (fun Q => scalarRestorationPairMoment g.f v v' F j (fun i l => (Q i l).1.val)) + ((scalarRestorationPairMoment g.f v v' F j).continuous.comp (by fun_prop)).measurable] + apply integral_congr_ae + filter_upwards [hN] with Q hNQ + exact (scalarRestorationPairMoment_diagonalMap q g.f v v' F j Q hNQ).symm + · rw [hl] + apply Finset.sum_congr rfl + intro d _ + rw [twoVisitMass_stepCumulative w hw hw1] + ring + +lemma labelProfile_unmarked_reference_exists (k : ℕ) (w : Fin (k+1)→ℝ) + (hw : ∀ l,0 (Q i l).1.val) ∂(ν : Measure _)) ∧ + (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))= + ∑ d,w d*F (timeSpin (q d)) := by + obtain ⟨ν,η,hν,hgeo,hpair,hm,hl⟩ := labelProfile_pair_reference_exists k w hw hw1 q hq g 1 1 F + refine ⟨ν,η,hν,hgeo,hpair,hm,?_⟩ + have h1 d := labelPairCoefficient_one k (stepCumulative w) (stepCumulative_pos w hw) + (fun i => (q i:ℝ)) g (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) d + simp_rw [h1] at hl + simpa only [mul_one] using hl + + +theorem quantile_pair_reference_exists (q : Time→Time) (hq : Monotone q) + (g : Jet3) (F : CompactOverlap →ᵇ ℝ) : + ∃ (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (η : ProbabilityMeasure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))), + (∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0) ∧ + (∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) ∧ + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) ∧ + (∀ j, (∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))= + ∫ Q : CompactArray CompactJointOverlap,scalarRestorationPairMoment g.f 1 1 F j (fun i l => (Q i l).1.val) ∂(ν : Measure _)) ∧ + (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))= + ∫ z,F z ∂(quantileSpinLaw q hq.measurable : Measure CompactOverlap) := by + have hex (n : ℕ) := labelProfile_unmarked_reference_exists n (fun _=>1/(n+1:ℝ)) + (by intro i; positivity) (uniformQuantileWeights_sum n) (uniformQuantileLower n q) + (uniformQuantileLower_mono n hq) g F + choose μ ξ hGG hgeo hpair hm hl using hex + obtain ⟨ν,s,hs,hlim⟩ := compact_array_law_subsequence μ + have hG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0 := by + intro r i G a + apply compactGGDefect_limit hlim r i G a + simp only [Function.comp_apply,hGG] + exact tendsto_const_nhds + have hgeom : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q := by + apply (mem_ae_iff_prob_eq_one compactSpinGeometry_closed.measurableSet).mpr + have hv := weak_limit_closed_full hlim compactSpinGeometry_closed (fun n => ?_) + · simp only [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + · have hh := (mem_ae_iff_prob_eq_one compactSpinGeometry_closed.measurableSet).mp (hgeo (s n)) + rw [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure] at hh + exact ENNReal.coe_injective hh + have hp : (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) := by + let ρ : ProbabilityMeasure CompactOverlap := ⟨(ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1), + (Measure.isProbabilityMeasure_map_iff (show Measurable + (fun array : CompactArray CompactJointOverlap => (array 0 1).1) + from by fun_prop).aemeasurable).2 inferInstance⟩ + have he : ρ=quantileSpinLaw q hq.measurable := by + apply probability_Icc_eq_of_moments + intro r + rw [quantileSpinLaw_integral q hq.measurable (fun x => x.val^r) (by fun_prop)] + change (∫ x : CompactOverlap, x.val^r ∂(ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1))=_ + rw [integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) + from by fun_prop).aemeasurable (show Measurable (fun x : CompactOverlap => x.val^r) from by fun_prop).aestronglyMeasurable] + let F : CompactOverlap→ᵇℝ := BoundedContinuousFunction.mkOfCompact ⟨fun x=>x.val^r,by fun_prop⟩ + let FF : CompactArray CompactJointOverlap→ᵇℝ := F.compContinuous ⟨fun Q => (Q 0 1).1,by fun_prop⟩ + have hν := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction FF).continuousAt.tendsto.comp hlim + have hv n : (∫ Q, FF Q ∂(μ n : Measure _))=∫ u, (sampleQuantileLower n q u:ℝ)^r ∂timeLaw := by + change (∫ Q, F (Q 0 1).1 ∂(μ n : Measure (CompactArray CompactJointOverlap)))=_ + rw [hpair n F] + exact (uniformQuantileCell_integral n (fun i => (uniformQuantileLower n q i:ℝ)^r)).symm + change Tendsto (fun n => ∫ Q, FF Q ∂(μ (s n) : Measure (CompactArray CompactJointOverlap))) atTop + (𝓝 (∫ Q, FF Q ∂(ν : Measure (CompactArray CompactJointOverlap)))) at hν + simp_rw [hv] at hν + exact tendsto_nhds_unique hν ((sampleQuantileLower_moment_tendsto q hq r).comp hs.tendsto_atTop) + exact congrArg (fun x : ProbabilityMeasure CompactOverlap => (x : Measure CompactOverlap)) he + obtain ⟨η,-,t,ht,hη⟩ := isCompact_univ.isSeqCompact (fun n => mem_univ (ξ (s n))) + have hv := hlim.comp ht.tendsto_atTop + refine ⟨ν,η,hG,hgeom,hp,?_,?_⟩ + · intro j + let A : WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F) →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x => x.1.val*x.2.val^j,by fun_prop⟩ + let B : CompactArray CompactJointOverlap →ᵇ ℝ := + (scalarRestorationPairMoment g.f 1 1 F j).compContinuous + ⟨fun Q i l => (Q i l).1.val,by fun_prop⟩ + have h₁ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction A).continuousAt.tendsto.comp hη + have h₂ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction B).continuousAt.tendsto.comp hv + change Tendsto (fun n => ∫ x,x.1.val*x.2.val^j ∂(ξ (s (t n)) : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F)))) atTop + (𝓝 (∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))) at h₁ + simp_rw [hm] at h₁ + exact tendsto_nhds_unique h₁ h₂ + · let A : WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F) →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x => x.1.val*restorationReciprocal g.f 2 x.2, + (continuous_subtype_val.comp continuous_fst).mul + ((restorationReciprocal g.f 2).continuous.comp continuous_snd)⟩ + let B : CompactArray CompactJointOverlap →ᵇ ℝ := F.compContinuous ⟨fun Q => (Q 0 1).1,by fun_prop⟩ + have h₁ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction A).continuousAt.tendsto.comp hη + have h₂ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction B).continuousAt.tendsto.comp hv + change Tendsto (fun n => ∫ x,x.1.val*restorationReciprocal g.f 2 x.2 ∂(ξ (s (t n)) : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F)))) atTop + (𝓝 (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f 1 1 F))))) at h₁ + simp_rw [hl,←hpair] at h₁ + have he := tendsto_nhds_unique h₁ h₂ + rw [he,←hp] + exact (integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) + from by fun_prop).aemeasurable F.measurable.aestronglyMeasurable).symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelProfileReference.lean b/lean/OAI/Probability/Perceptron/Variational/LabelProfileReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..c72d54d86096596773e3e0d3bbb6e9218f09193e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelProfileReference.lean @@ -0,0 +1,206 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.CompactArrayMap +import OAI.Probability.Perceptron.Variational.LabelValue +import OAI.Probability.Perceptron.Variational.LabelReference + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def CompactLabelNodes (k : ℕ) (Q : CompactArray CompactJointOverlap) : Prop := + ∀ i j, (Q i j).2∈Set.range (sourceLabelLevel k) + +lemma compactLabelNodes_closed (k : ℕ) : IsClosed {Q | CompactLabelNodes k Q} := by + unfold CompactLabelNodes + simp only [ofPred_forall] + exact isClosed_iInter fun i => isClosed_iInter fun j => + (Set.finite_range (sourceLabelLevel k)).isClosed.preimage (by fun_prop) + +lemma sourceGibbsArray_limit_label_nodes (k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : (n : ℕ)→Fin (n+1)→ℕ) (h : ℕ→Fin (k+1)→ℝ) + (u : (n : ℕ)→Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℕ→ℝ≥0) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n=>sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactLabelNodes k Q := by + have hc := compactLabelNodes_closed k + apply (mem_ae_iff_prob_eq_one hc.measurableSet).mpr + have hv := weak_limit_closed_full hlim hc (fun n=>sourceGibbsArray_closed_full + (s n) k f (p (s n)) (d (s n)) (h (s n)) (u (s n)) z (t (s n)) hc + (fun x i j => ⟨indexedCommonDepth k (x j).2 (x i).2,rfl⟩)) + simp only [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + +def timeSpin (x : Time) : CompactOverlap := ⟨x.val,by linarith [x.prop.1],x.prop.2⟩ +lemma timeSpin_continuous : Continuous timeSpin := by unfold timeSpin; fun_prop + +def labelProfileSpin {k : ℕ} (q : Fin (k+1)→Time) (x : Time) : CompactOverlap := + ⟨min 1 (max 0 (labelProfileInterpolant (fun i => (q i:ℝ)) x)), + le_min (by norm_num) ((by norm_num : (-1:ℝ)≤0).trans (le_max_left _ _)),min_le_left _ _⟩ +lemma labelProfileSpin_continuous {k : ℕ} (q : Fin (k+1)→Time) : Continuous (labelProfileSpin q) := by + unfold labelProfileSpin + fun_prop +lemma labelProfileSpin_node {k : ℕ} (q : Fin (k+1)→Time) (l : Fin (k+1)) : + labelProfileSpin q (sourceLabelLevel k l)=timeSpin (q l) := by + apply Subtype.ext + change min 1 (max 0 (labelProfileInterpolant (fun i => (q i:ℝ)) (sourceLabelLevel k l)))=(q l:ℝ) + rw [labelProfileInterpolant_node,max_eq_right (q l).prop.1,min_eq_right (q l).prop.2] + +def labelProfileMap {k : ℕ} (q : Fin (k+1)→Time) (x : CompactJointOverlap) : CompactJointOverlap := + (labelProfileSpin q x.2,x.2) +lemma labelProfileMap_continuous {k : ℕ} (q : Fin (k+1)→Time) : Continuous (labelProfileMap q) := + ((labelProfileSpin_continuous q).comp continuous_snd).prodMk continuous_snd + +lemma sourceLabelLevel_le {k : ℕ} (i j : Fin (k+1)) : + sourceLabelLevel k i ≤ sourceLabelLevel k j ↔ i≤j := by + change (i.val:ℝ)/(k+1:ℕ)≤(j.val:ℝ)/(k+1:ℕ) ↔ i≤j + rw [div_le_div_iff_of_pos_right (by positivity : (0:ℝ)<(k+1:ℕ))] + exact_mod_cast (Iff.rfl : i.val≤j.val ↔ i≤j) + +lemma labelProfileMap_geometry {k : ℕ} (q : Fin (k+1)→Time) (hq : Monotone q) + (h1 : q (Fin.last k)=1) {Q : CompactArray CompactJointOverlap} + (hQ : CompactLabelGeometry k Q) (hN : CompactLabelNodes k Q) : + CompactSpinGeometry (compactMapArray (labelProfileMap q) Q) := by + refine ⟨?_,?_,?_⟩ + · intro i j + have h : (Q i j).2=(Q j i).2 := Subtype.ext (hQ.1 i j) + change (labelProfileSpin q (Q i j).2).val=(labelProfileSpin q (Q j i).2).val + rw [h] + · intro i + have h : (Q i i).2=sourceLabelLevel k (Fin.last k) := Subtype.ext (hQ.2.1 i) + change (labelProfileSpin q (Q i i).2).val=1 + rw [h,labelProfileSpin_node,h1] + rfl + · intro i j l + obtain ⟨a,ha⟩ := hN i j + obtain ⟨b,hb⟩ := hN i l + obtain ⟨c,hc⟩ := hN j l + have hs := hQ.2.2 i j l + rw [←ha,←hb,←hc] at hs + change min (labelProfileSpin q (Q i j).2).val (labelProfileSpin q (Q i l).2).val≤ + (labelProfileSpin q (Q j l).2).val + rw [←ha,←hb,←hc,labelProfileSpin_node,labelProfileSpin_node,labelProfileSpin_node] + change min (q a:ℝ) (q b:ℝ)≤(q c:ℝ) + rcases le_total a b with hab|hab + · have hab' : (sourceLabelLevel k a).val ≤ (sourceLabelLevel k b).val := + (sourceLabelLevel_le a b).mpr hab + have hac : a≤c := (sourceLabelLevel_le a c).mp (by + change (sourceLabelLevel k a).val≤(sourceLabelLevel k c).val + simpa only [min_eq_left hab'] using hs) + exact (min_le_left _ _).trans (hq hac) + · have hba' : (sourceLabelLevel k b).val ≤ (sourceLabelLevel k a).val := + (sourceLabelLevel_le b a).mpr hab + have hbc : b≤c := (sourceLabelLevel_le b c).mp (by + change (sourceLabelLevel k b).val≤(sourceLabelLevel k c).val + simpa only [min_eq_right hba'] using hs) + exact (min_le_right _ _).trans (hq hbc) + +lemma labelProfileMap_kernel {k : ℕ} (q : Fin (k+1)→Time) (h1 : q (Fin.last k)=1) + (f : ℝ →ᵇ ℝ) (r : ℕ) {Q : CompactArray CompactJointOverlap} + (hQ : CompactLabelGeometry k Q) (hN : CompactLabelNodes k Q) : + freshReplicaArrayKernel f r (compactMapArray (labelProfileMap q) Q)= + labelFreshArrayKernel (fun i => (q i:ℝ)) f r Q := by + change freshReplicaMatrixKernel f r (fun i j => (labelProfileSpin q (Q i j).2).val)= + freshReplicaMatrixKernel f r (fun i j => if i=j then 1 else + labelProfileInterpolant (fun l => (q l:ℝ)) (Q i j).2) + congr 1 + funext i j + by_cases hij : i=j + · subst j + rw [ite_eq_left rfl] + have h : (Q i i).2=sourceLabelLevel k (Fin.last k) := Subtype.ext (hQ.2.1 i) + rw [h,labelProfileSpin_node,h1] + rfl + · rw [ite_eq_right hij] + obtain ⟨a,ha⟩ := hN i j + rw [←ha,labelProfileSpin_node,labelProfileInterpolant_node] + rfl + +lemma compactSpinGeometry_closed : IsClosed {Q : CompactArray CompactJointOverlap | CompactSpinGeometry Q} := by + unfold CompactSpinGeometry + simp only [ofPred_and,ofPred_forall] + exact (isClosed_iInter fun i => isClosed_iInter fun j => isClosed_eq (by fun_prop) (by fun_prop)).inter + ((isClosed_iInter fun i => isClosed_eq (by fun_prop) continuous_const).inter + (isClosed_iInter fun i => isClosed_iInter fun j => isClosed_iInter fun l => + isClosed_le (by fun_prop) (by fun_prop))) + +theorem labelProfile_reference_exists (k : ℕ) (w : Fin (k+1)→ℝ) + (hw : ∀ l, 0 (q i:ℝ)) (q (Fin.last k)).prop.2 g := by + let p := fun n => (Nat.unpair n).1 + let d := fun n => (Nat.unpair n).2 + have hcover : ∀ a b : ℕ, 1≤a+b → ∃ j,p j=a ∧ d j=b := by + intro a b _ + exact ⟨Nat.pair a b,by simp [p,d]⟩ + obtain ⟨u,ρ,s,hu,hs,hlim,hGG,hex,hpair,hgeo⟩ := source_label_reference_exists k w hw hw1 p d hcover + have hL := sourceGibbsArray_limit_label_geometry k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + have hN := sourceGibbsArray_limit_label_nodes k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + let ν := compactMapLaw (labelProfileMap q) (labelProfileMap_continuous q) ρ + obtain ⟨η,hη,hm,hl⟩ := sourceLabelFreshLog_tendsto k (fun i => (q i:ℝ)) (q 0).prop.1 + (fun i j hij => hq hij) (q (Fin.last k)).prop.2 0 g.f + (fun _ j=>p j.val) (fun _ j=>d j.val) (fun _ _=>0) (fun _ _=>le_rfl) + (fun _=>monotone_const) u (stepCumulative w) (fun _=>0) s hlim + refine ⟨ν,η,compactMapLaw_gg _ _ ρ hGG,?_,?_,?_,?_⟩ + · change ∀ᵐ Q ∂(ρ : Measure (CompactArray CompactJointOverlap)).map + (compactMapArray (labelProfileMap q)), CompactSpinGeometry Q + apply (ae_map_iff (compactMapArray_continuous (labelProfileMap_continuous q)).measurable.aemeasurable + compactSpinGeometry_closed.measurableSet).mpr + filter_upwards [hL,hN] with Q hLQ hNQ + exact labelProfileMap_geometry q hq h1 hLQ hNQ + · intro F + change (∫ Q : CompactArray CompactJointOverlap, F (Q 0 1).1 + ∂(compactMapLaw (labelProfileMap q) (labelProfileMap_continuous q) ρ : Measure _))=_ + rw [compactMapLaw_integral (labelProfileMap q) (labelProfileMap_continuous q) ρ + (fun Q => F (Q 0 1).1) (by fun_prop)] + have he : (∫ Q, F (labelProfileSpin q (Q 0 1).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)))= + ∫ Q, F (labelProfileSpin q (Q 1 0).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)) := by + apply integral_congr_ae + filter_upwards [hL] with Q hLQ + rw [show (Q 0 1).2=(Q 1 0).2 from Subtype.ext (hLQ.1 0 1)] + change (∫ Q, F (labelProfileSpin q (Q 0 1).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)))=_ + have hmap : (∫ x, F (labelProfileSpin q x) ∂((ρ : Measure (CompactArray CompactJointOverlap)).map + (fun Q => (Q 1 0).2)))=∫ Q, F (labelProfileSpin q (Q 1 0).2) + ∂(ρ : Measure (CompactArray CompactJointOverlap)) := + integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 1 0).2) + from by fun_prop).aemeasurable + (show Measurable (fun x : Time => F (labelProfileSpin q x)) from + F.measurable.comp (labelProfileSpin_continuous q).measurable).aestronglyMeasurable + rw [he,←hmap,hpair,sourceLabelLaw_integral k w (fun l => (hw l).le) (fun x => F (labelProfileSpin q x)) + (F.measurable.comp (labelProfileSpin_continuous q).measurable)] + simp_rw [labelProfileSpin_node] + · intro r + rw [hm r] + change _ = ∫ Q, freshReplicaArrayKernel (expBCF 1 g.f) r Q + ∂(compactMapLaw (labelProfileMap q) (labelProfileMap_continuous q) ρ : Measure _) + rw [compactMapLaw_integral (labelProfileMap q) (labelProfileMap_continuous q) ρ + (fun Q => freshReplicaArrayKernel (expBCF 1 g.f) r Q) + (freshReplicaArrayKernel (expBCF 1 g.f) r).measurable] + apply integral_congr_ae + filter_upwards [hL,hN] with Q hLQ hNQ + exact (labelProfileMap_kernel q h1 (expBCF 1 g.f) r hLQ hNQ).symm + · have hv := fun n => sourceLabelFreshLog_value (s n) k 0 + (fun j=>p j.val) (fun j=>d j.val) (fun _=>0) (fun _=>le_rfl) monotone_const + (u (s n)) (stepCumulative w) (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) + (stepCumulative_lt_one w hw hw1) (fun i => (q i:ℝ)) (q (Fin.last k)).prop.2 g 0 + simp_rw [hv] at hl + exact (tendsto_nhds_unique tendsto_const_nhds hl).symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelProfileReferenceFull.lean b/lean/OAI/Probability/Perceptron/Variational/LabelProfileReferenceFull.lean new file mode 100644 index 0000000000000000000000000000000000000000..9fb61df3d0f5860c14ede6b900cd96f52af168ff --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelProfileReferenceFull.lean @@ -0,0 +1,167 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelProfileReference + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def labelProfileDiagonal (x : CompactJointOverlap) : CompactJointOverlap := + (⟨1,by norm_num,le_rfl⟩,x.2) +lemma labelProfileDiagonal_continuous : Continuous labelProfileDiagonal := by + unfold labelProfileDiagonal + fun_prop + +lemma labelProfileSpin_ultra {k : ℕ} (q : Fin (k+1)→Time) (hq : Monotone q) + {Q : CompactArray CompactJointOverlap} (hQ : CompactLabelGeometry k Q) (hN : CompactLabelNodes k Q) + (i j l : ℕ) : min (labelProfileSpin q (Q i j).2).val (labelProfileSpin q (Q i l).2).val≤ + (labelProfileSpin q (Q j l).2).val := by + obtain ⟨a,ha⟩ := hN i j + obtain ⟨b,hb⟩ := hN i l + obtain ⟨c,hc⟩ := hN j l + have hs := hQ.2.2 i j l + rw [←ha,←hb,←hc] at hs + rw [←ha,←hb,←hc,labelProfileSpin_node,labelProfileSpin_node,labelProfileSpin_node] + change min (q a:ℝ) (q b:ℝ)≤(q c:ℝ) + rcases le_total a b with hab|hab + · have hab' : (sourceLabelLevel k a).val ≤ (sourceLabelLevel k b).val := + (sourceLabelLevel_le a b).mpr hab + have hac : a≤c := (sourceLabelLevel_le a c).mp (by + change (sourceLabelLevel k a).val≤(sourceLabelLevel k c).val + simpa only [min_eq_left hab'] using hs) + exact (min_le_left _ _).trans (hq hac) + · have hba' : (sourceLabelLevel k b).val ≤ (sourceLabelLevel k a).val := + (sourceLabelLevel_le b a).mpr hab + have hbc : b≤c := (sourceLabelLevel_le b c).mp (by + change (sourceLabelLevel k b).val≤(sourceLabelLevel k c).val + simpa only [min_eq_right hba'] using hs) + exact (min_le_right _ _).trans (hq hbc) + +lemma labelProfileDiagonalMap_geometry {k : ℕ} (q : Fin (k+1)→Time) (hq : Monotone q) + {Q : CompactArray CompactJointOverlap} (hQ : CompactLabelGeometry k Q) (hN : CompactLabelNodes k Q) : + CompactSpinGeometry (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal Q) := by + have hsym (i j : ℕ) : (Q i j).2=(Q j i).2 := Subtype.ext (hQ.1 i j) + refine ⟨?_,?_,?_⟩ + · intro i j + by_cases hij : i=j + · subst j; rfl + · simp only [compactDiagonalMapArray,ite_eq_right hij,ite_eq_right (Ne.symm hij),labelProfileMap,hsym i j] + · intro i + simp only [compactDiagonalMapArray,↓reduceIte,labelProfileDiagonal] + · intro i j l + by_cases hjl : j=l + · subst l + simp only [compactDiagonalMapArray,↓reduceIte,labelProfileDiagonal,min_self] + split_ifs <;> first | exact le_rfl | exact (labelProfileSpin q (Q i j).2).prop.2 + · by_cases hij : i=j + · subst j + simp only [compactDiagonalMapArray,↓reduceIte,ite_eq_right hjl,labelProfileDiagonal,labelProfileMap] + exact min_le_right _ _ + · by_cases hil : i=l + · subst l + simp only [compactDiagonalMapArray,↓reduceIte,ite_eq_right hij,ite_eq_right hjl,labelProfileDiagonal,labelProfileMap] + rw [hsym i j] + exact min_le_left _ _ + · simp only [compactDiagonalMapArray,ite_eq_right hij,ite_eq_right hil,ite_eq_right hjl,labelProfileMap] + exact labelProfileSpin_ultra q hq hQ hN i j l + +lemma labelProfileDiagonalMap_kernel {k : ℕ} (q : Fin (k+1)→Time) + (f : ℝ →ᵇ ℝ) (r : ℕ) {Q : CompactArray CompactJointOverlap} (hN : CompactLabelNodes k Q) : + freshReplicaArrayKernel f r (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal Q)= + labelFreshArrayKernel (fun i => (q i:ℝ)) f r Q := by + change freshReplicaMatrixKernel f r (fun i j => + ((if (i:ℕ)=j then labelProfileDiagonal (Q i j) else labelProfileMap q (Q i j)).1:ℝ))= + freshReplicaMatrixKernel f r (fun i j => if i=j then 1 else + labelProfileInterpolant (fun l => (q l:ℝ)) (Q i j).2) + congr 1 + funext i j + by_cases hij : i=j + · subst j + simp only [↓reduceIte,labelProfileDiagonal] + · have hv : (i:ℕ)≠j := fun h => hij (Fin.ext h) + rw [ite_eq_right hv,ite_eq_right hij] + obtain ⟨a,ha⟩ := hN i j + change (labelProfileSpin q (Q i j).2).val=_ + rw [←ha,labelProfileSpin_node,labelProfileInterpolant_node] + rfl + +theorem labelProfile_reference_full_exists (k : ℕ) (w : Fin (k+1)→ℝ) + (hw : ∀ l, 0 (q i:ℝ)) (q (Fin.last k)).prop.2 g := by + let p := fun n => (Nat.unpair n).1 + let d := fun n => (Nat.unpair n).2 + have hcover : ∀ a b : ℕ, 1≤a+b → ∃ j,p j=a ∧ d j=b := by + intro a b _ + exact ⟨Nat.pair a b,by simp [p,d]⟩ + obtain ⟨u,ρ,s,hu,hs,hlim,hGG,hex,hpair,hgeo⟩ := source_label_reference_exists k w hw hw1 p d hcover + have hL := sourceGibbsArray_limit_label_geometry k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + have hN := sourceGibbsArray_limit_label_nodes k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + let ν := compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + obtain ⟨η,hη,hm,hl⟩ := sourceLabelFreshLog_tendsto k (fun i => (q i:ℝ)) (q 0).prop.1 + (fun i j hij => hq hij) (q (Fin.last k)).prop.2 0 g.f + (fun _ j=>p j.val) (fun _ j=>d j.val) (fun _ _=>0) (fun _ _=>le_rfl) + (fun _=>monotone_const) u (stepCumulative w) (fun _=>0) s hlim + refine ⟨ν,η,compactDiagonalMapLaw_gg _ _ _ _ ρ hGG,?_,?_,?_,?_⟩ + · change ∀ᵐ Q ∂(ρ : Measure (CompactArray CompactJointOverlap)).map + (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal), CompactSpinGeometry Q + apply (ae_map_iff (compactDiagonalMapArray_continuous (labelProfileMap_continuous q) labelProfileDiagonal_continuous).measurable.aemeasurable + compactSpinGeometry_closed.measurableSet).mpr + filter_upwards [hL,hN] with Q hLQ hNQ + exact labelProfileDiagonalMap_geometry q hq hLQ hNQ + · intro F + change (∫ Q : CompactArray CompactJointOverlap, F (Q 0 1).1 + ∂(compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ : Measure _))=_ + rw [compactDiagonalMapLaw_integral (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + (fun Q => F (Q 0 1).1) (by fun_prop)] + have he : (∫ Q, F (labelProfileSpin q (Q 0 1).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)))= + ∫ Q, F (labelProfileSpin q (Q 1 0).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)) := by + apply integral_congr_ae + filter_upwards [hL] with Q hLQ + rw [show (Q 0 1).2=(Q 1 0).2 from Subtype.ext (hLQ.1 0 1)] + change (∫ Q, F (labelProfileSpin q (Q 0 1).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)))=_ + have hmap : (∫ x, F (labelProfileSpin q x) ∂((ρ : Measure (CompactArray CompactJointOverlap)).map + (fun Q => (Q 1 0).2)))=∫ Q, F (labelProfileSpin q (Q 1 0).2) + ∂(ρ : Measure (CompactArray CompactJointOverlap)) := + integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 1 0).2) + from by fun_prop).aemeasurable + (show Measurable (fun x : Time => F (labelProfileSpin q x)) from + F.measurable.comp (labelProfileSpin_continuous q).measurable).aestronglyMeasurable + rw [he,←hmap,hpair,sourceLabelLaw_integral k w (fun l => (hw l).le) (fun x => F (labelProfileSpin q x)) + (F.measurable.comp (labelProfileSpin_continuous q).measurable)] + simp_rw [labelProfileSpin_node] + · intro r + rw [hm r] + change _ = ∫ Q, freshReplicaArrayKernel (expBCF 1 g.f) r Q + ∂(compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ : Measure _) + rw [compactDiagonalMapLaw_integral (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + (fun Q => freshReplicaArrayKernel (expBCF 1 g.f) r Q) + (freshReplicaArrayKernel (expBCF 1 g.f) r).measurable] + apply integral_congr_ae + filter_upwards [hL,hN] with Q hLQ hNQ + exact (labelProfileDiagonalMap_kernel q (expBCF 1 g.f) r hNQ).symm + · have hv := fun n => sourceLabelFreshLog_value (s n) k 0 + (fun j=>p j.val) (fun j=>d j.val) (fun _=>0) (fun _=>le_rfl) monotone_const + (u (s n)) (stepCumulative w) (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) + (stepCumulative_lt_one w hw hw1) (fun i => (q i:ℝ)) (q (Fin.last k)).prop.2 g 0 + simp_rw [hv] at hl + exact (tendsto_nhds_unique tendsto_const_nhds hl).symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelProfileSingleReference.lean b/lean/OAI/Probability/Perceptron/Variational/LabelProfileSingleReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..3faf2a1b31e85f334612cc15ef83a17e45c1b95b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelProfileSingleReference.lean @@ -0,0 +1,228 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.QuantileReference +import OAI.Probability.Perceptron.Variational.RoundedMarkedSelection +import OAI.Probability.Perceptron.Variational.LabelSingleRestoredValue + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +theorem labelProfile_single_reference_exists (k : ℕ) (w : Fin (k+1)→ℝ) + (hw : ∀ l,0 (Q i l).1.val) ∂(ν : Measure _)) ∧ + (∫ x,x.1.val*restorationReciprocal g.f 1 x.2 ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v v'))))= + labelSingleCoefficient k (stepCumulative w) (fun i => (q i:ℝ)) g + (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) v * + labelSingleCoefficient k (stepCumulative w) (fun i => (q i:ℝ)) g + (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) v' := by + let p := fun n => (Nat.unpair n).1 + let d := fun n => (Nat.unpair n).2 + have hcover : ∀ a b : ℕ, 1≤a+b → ∃ j,p j=a ∧ d j=b := by + intro a b _ + exact ⟨Nat.pair a b,by simp [p,d]⟩ + obtain ⟨u,ρ,s,hu,hs,hlim,hGG,hex,hpair,hgeo⟩ := source_label_reference_exists k w hw hw1 p d hcover + have hL := sourceGibbsArray_limit_label_geometry k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + have hN := sourceGibbsArray_limit_label_nodes k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + let ν := compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + obtain ⟨η,hm,hl⟩ := sourceLabelSingle_witness k q hq 0 g v v' + (fun _ j=>p j.val) (fun _ j=>d j.val) (fun _ _=>0) (fun _ _=>le_rfl) + (fun _=>monotone_const) u (stepCumulative w) (stepCumulative_strictMono w hw) + (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1) (fun _=>0) s hlim + refine ⟨ν,η,compactDiagonalMapLaw_gg _ _ _ _ ρ hGG,?_,?_,?_,?_⟩ + · change ∀ᵐ Q ∂(ρ : Measure (CompactArray CompactJointOverlap)).map + (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal), CompactSpinGeometry Q + apply (ae_map_iff (compactDiagonalMapArray_continuous (labelProfileMap_continuous q) labelProfileDiagonal_continuous).measurable.aemeasurable + compactSpinGeometry_closed.measurableSet).mpr + filter_upwards [hL,hN] with Q hLQ hNQ + exact labelProfileDiagonalMap_geometry q hq hLQ hNQ + · intro A + change (∫ Q : CompactArray CompactJointOverlap, A (Q 0 1).1 + ∂(compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ : Measure _))=_ + rw [compactDiagonalMapLaw_integral (labelProfileMap q) labelProfileDiagonal (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + (fun Q => A (Q 0 1).1) (by fun_prop)] + have he : (∫ Q, A (labelProfileSpin q (Q 0 1).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)))= + ∫ Q, A (labelProfileSpin q (Q 1 0).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)) := by + apply integral_congr_ae + filter_upwards [hL] with Q hLQ + rw [show (Q 0 1).2=(Q 1 0).2 from Subtype.ext (hLQ.1 0 1)] + change (∫ Q, A (labelProfileSpin q (Q 0 1).2) ∂(ρ : Measure (CompactArray CompactJointOverlap)))=_ + have hmap : (∫ x, A (labelProfileSpin q x) ∂((ρ : Measure (CompactArray CompactJointOverlap)).map + (fun Q => (Q 1 0).2)))=∫ Q, A (labelProfileSpin q (Q 1 0).2) + ∂(ρ : Measure (CompactArray CompactJointOverlap)) := + integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 1 0).2) + from by fun_prop).aemeasurable + (show Measurable (fun x : Time => A (labelProfileSpin q x)) from + A.measurable.comp (labelProfileSpin_continuous q).measurable).aestronglyMeasurable + rw [he,←hmap,hpair,sourceLabelLaw_integral k w (fun l => (hw l).le) (fun x => A (labelProfileSpin q x)) + (A.measurable.comp (labelProfileSpin_continuous q).measurable)] + simp_rw [labelProfileSpin_node] + · intro j + rw [hm j] + change _=∫ Q : CompactArray CompactJointOverlap,scalarRestorationSingleMoment g.f v v' j (fun i l => (Q i l).1.val) + ∂(compactDiagonalMapLaw (labelProfileMap q) labelProfileDiagonal + (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ : Measure _) + rw [compactDiagonalMapLaw_integral (labelProfileMap q) labelProfileDiagonal + (labelProfileMap_continuous q) labelProfileDiagonal_continuous ρ + (fun Q => scalarRestorationSingleMoment g.f v v' j (fun i l => (Q i l).1.val)) + ((scalarRestorationSingleMoment g.f v v' j).continuous.comp (by fun_prop)).measurable] + apply integral_congr_ae + filter_upwards [hN] with Q hNQ + exact (scalarRestorationSingleMoment_diagonalMap q g.f v v' j Q hNQ).symm + · exact hl + +lemma rootPathMean_bound {X R : Type} [MeasurableSpace X] [MeasurableSpace R] + (μ : Measure R) [IsProbabilityMeasure μ] (x : R→X) (n : ℕ) (κ : Fin n→Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f : X→ℝ) (C : ℝ) (hb : ∀ y,|f y|≤C) : + |rootPathMean μ x n κ f|≤C := by + simpa only [rootPathMean,Real.norm_eq_abs,probReal_univ,mul_one] using + norm_integral_le_of_norm_le_const (μ:=μ) + (f:=fun r => pathMean n κ f (x r)) + (ae_of_all _ fun r => by simpa only [Real.norm_eq_abs] using pathMean_bound n κ hκ f C hb (x r)) + +lemma labelSingleCoefficient_bound (k : ℕ) (z : Fin k→ℝ) (hz0 : ∀ i,0 labelProfileTerminal g s (x 0)) + ((labelProfileTerminal_lipschitz g s).continuous.measurable.comp (measurable_pi_apply 0)) hI.2 i + exact rootPathMean_bound (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (fun r => fun _ => labelGaussianRoot q r) k _ hκ + (fun x => labelResidualObservable s g.f v (x 0)) ‖v‖ + (fun x => labelResidualObservable_bound s g.f v (x 0)) + +lemma labelSingleCoefficient_one (k : ℕ) (z : Fin k→ℝ) (hz0 : ∀ i,0 labelProfileTerminal g s (x 0)) + ((labelProfileTerminal_lipschitz g s).continuous.measurable.comp (measurable_pi_apply 0)) hI.2 i + have := pathOneKernel_markov k _ hκ + simp only [labelSingleCoefficient,rootPathMean,labelResidualObservable,residualResponse_one,pathMean, + integral_const,probReal_univ,one_smul] + +def roundedSingleCoeff (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) : ℝ := + labelSingleCoefficient (strictRoundModel q n).depth (stepCumulative (strictRoundModel q n).weight) + (strictRoundModel q n).value g + ⟨1-roundTimeValue q n (Fin.last (strictRoundModel q n).depth), + sub_nonneg.mpr (roundTimeValue q n _).prop.2⟩ v + +lemma roundedSingleCoeff_bound (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) : + |roundedSingleCoeff q n g v|≤‖v‖ := + labelSingleCoefficient_bound _ _ (stepCumulative_pos _ (strictRoundModel q n).weight_pos) _ _ _ _ + +lemma roundedSingleCoeff_one (q : BoundedField 1) (n : ℕ) (g : Jet3) : + roundedSingleCoeff q n g 1=1 := + labelSingleCoefficient_one _ _ (stepCumulative_pos _ (strictRoundModel q n).weight_pos) _ _ _ + +theorem rounded_single_reference_exists (q : Time→Time) (hq : Monotone q) + (g : Jet3) (v v' : ℝ→ᵇℝ) (b : ℕ→ℕ) (hb : StrictMono b) + (L : ℝ) (hL : Tendsto (fun n => + roundedSingleCoeff (unitQuantileField q hq) (b n) g v * + roundedSingleCoeff (unitQuantileField q hq) (b n) g v') atTop (𝓝 L)) : + ∃ (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (η : ProbabilityMeasure (WeightedRestorationRange g.f (singleRestorationBound g.f v v'))), + (∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0) ∧ + (∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) ∧ + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) ∧ + (∀ j,(∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v v'))))= + ∫ Q : CompactArray CompactJointOverlap,scalarRestorationSingleMoment g.f v v' j + (fun i l => (Q i l).1.val) ∂(ν : Measure _)) ∧ + (∫ x,x.1.val*restorationReciprocal g.f 1 x.2 + ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v v'))))=L := by + have hex (n : ℕ) := labelProfile_single_reference_exists + (strictRoundModel (unitQuantileField q hq) (b n)).depth + (strictRoundModel (unitQuantileField q hq) (b n)).weight + (strictRoundModel (unitQuantileField q hq) (b n)).weight_pos + (strictRoundModel (unitQuantileField q hq) (b n)).weight_sum + (roundTimeValue (unitQuantileField q hq) (b n)) (roundTimeValue_mono _ _) g v v' + choose μ ξ hGG hgeo hpair hm hl using hex + obtain ⟨ν,s,hs,hlim⟩ := compact_array_law_subsequence μ + have hG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0 := by + intro r i G a + apply compactGGDefect_limit hlim r i G a + simp only [Function.comp_apply,hGG] + exact tendsto_const_nhds + have hgeom : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q := by + apply (mem_ae_iff_prob_eq_one compactSpinGeometry_closed.measurableSet).mpr + have hv := weak_limit_closed_full hlim compactSpinGeometry_closed (fun n => ?_) + · simp only [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + · have hh := (mem_ae_iff_prob_eq_one compactSpinGeometry_closed.measurableSet).mp (hgeo (s n)) + rw [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure] at hh + exact ENNReal.coe_injective hh + have hp : (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) := by + let ρ : ProbabilityMeasure CompactOverlap := ⟨(ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1), + (Measure.isProbabilityMeasure_map_iff (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) + from by fun_prop).aemeasurable).2 inferInstance⟩ + have he : ρ=quantileSpinLaw q hq.measurable := by + apply probability_Icc_eq_of_moments + intro r + rw [quantileSpinLaw_integral q hq.measurable (fun x => x.val^r) (by fun_prop)] + change (∫ x : CompactOverlap, x.val^r ∂(ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1))=_ + rw [integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) + from by fun_prop).aemeasurable (show Measurable (fun x : CompactOverlap => x.val^r) from by fun_prop).aestronglyMeasurable] + let A : CompactOverlap→ᵇℝ := BoundedContinuousFunction.mkOfCompact ⟨fun x=>x.val^r,by fun_prop⟩ + let B : CompactArray CompactJointOverlap→ᵇℝ := A.compContinuous ⟨fun Q => (Q 0 1).1,by fun_prop⟩ + have hν := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction B).continuousAt.tendsto.comp hlim + change Tendsto (fun n => ∫ Q, A (Q 0 1).1 ∂(μ (s n) : Measure (CompactArray CompactJointOverlap))) atTop + (𝓝 (∫ Q, (Q 0 1).1.val^r ∂(ν : Measure (CompactArray CompactJointOverlap)))) at hν + simp_rw [hpair] at hν + exact tendsto_nhds_unique hν + ((roundTime_sum_tendsto q hq A).comp (hb.comp hs).tendsto_atTop) + exact congrArg (fun x : ProbabilityMeasure CompactOverlap => (x : Measure CompactOverlap)) he + obtain ⟨η,-,t,ht,hη⟩ := isCompact_univ.isSeqCompact (fun n => mem_univ (ξ (s n))) + have hv := hlim.comp ht.tendsto_atTop + refine ⟨ν,η,hG,hgeom,hp,?_,?_⟩ + · intro j + let A : WeightedRestorationRange g.f (singleRestorationBound g.f v v') →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x => x.1.val*x.2.val^j,by fun_prop⟩ + let B : CompactArray CompactJointOverlap →ᵇ ℝ := + (scalarRestorationSingleMoment g.f v v' j).compContinuous + ⟨fun Q i l => (Q i l).1.val,by fun_prop⟩ + have h₁ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction A).continuousAt.tendsto.comp hη + have h₂ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction B).continuousAt.tendsto.comp hv + change Tendsto (fun n => ∫ x,x.1.val*x.2.val^j ∂(ξ (s (t n)) : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v v')))) atTop + (𝓝 (∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v v'))))) at h₁ + simp_rw [hm] at h₁ + exact tendsto_nhds_unique h₁ h₂ + · let A : WeightedRestorationRange g.f (singleRestorationBound g.f v v') →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x => x.1.val*restorationReciprocal g.f 1 x.2, + (continuous_subtype_val.comp continuous_fst).mul + ((restorationReciprocal g.f 1).continuous.comp continuous_snd)⟩ + have h₁ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction A).continuousAt.tendsto.comp hη + change Tendsto (fun n => ∫ x,x.1.val*restorationReciprocal g.f 1 x.2 ∂(ξ (s (t n)) : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v v')))) atTop + (𝓝 (∫ x,x.1.val*restorationReciprocal g.f 1 x.2 ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v v'))))) at h₁ + simp_rw [hl] at h₁ + exact tendsto_nhds_unique h₁ (hL.comp (hs.comp ht).tendsto_atTop) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelReference.lean b/lean/OAI/Probability/Perceptron/Variational/LabelReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..e36597a5a85c43f8482b16c5e4ebea57e31118d2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelReference.lean @@ -0,0 +1,107 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshGeometry + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +theorem source_label_reference_exists (k : ℕ) (w : Fin (k+1)→ℝ) + (hw : ∀ l, 01) (fun _=>2)) ∧ StrictMono s ∧ + Tendsto (fun n => sourceGibbsArrayLaw (s n) k 0 (fun j=>p j.val) + (fun j=>d j.val) (fun _=>0) (u (s n)) (stepCumulative w) 0) atTop (𝓝 ν) ∧ + (∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (g : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G g=0) ∧ + (∀ e : Equiv.Perm ℕ, MeasurePreserving (compactRelabel (K:=CompactJointOverlap) e) + (ν : Measure _) (ν : Measure _)) ∧ + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 1 0).2)=sourceLabelLaw k w ∧ + (∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) := by + have hz := stepCumulative_strictMono w hw + have hz0 := stepCumulative_pos w hw + have hz1 := stepCumulative_lt_one w hw hw1 + have hc (n : ℕ) := source_perturbation_contact_exists n k (0 : ℝ →ᵇ ℝ) + (fun j=>p j.val) (fun j=>d j.val) (fun _=>0) (fun _=>le_rfl) monotone_const + (stepCumulative w) hz hz0 hz1 0 + choose u hu hm using hc + obtain ⟨ν,s,hs,hlim⟩ := compact_array_law_subsequence (fun n => sourceGibbsArrayLaw n k + (0 : ℝ →ᵇ ℝ) (fun j=>p j.val) (fun j=>d j.val) (fun _=>0) (u n) (stepCumulative w) 0) + refine ⟨u,ν,s,hu,hs,hlim,?_,?_,?_,?_⟩ + · exact source_contact_limit_joint_gg k 0 p d (stepCumulative w) hz hz0 hz1 + (fun _=>0) (fun _ _=>0) (fun _ _=>le_rfl) (fun _=>monotone_const) u hu hm + (H:=0) (T:=0) le_rfl (fun _=>le_rfl) (fun _=>le_rfl) hs hlim hcover + · exact source_contact_limit_exchangeable k 0 (fun _ j=>p j.val) (fun _ j=>d j.val) + (fun _ _=>0) u (stepCumulative w) (fun _=>0) s hlim + · apply source_array_limit_label_law k 0 p d w hw hw1 + (fun _ _=>0) (fun _ _=>le_rfl) (fun _=>monotone_const) u (fun n j=>?_) (fun _=>0) + (fun b hb=>hcover 0 b (by omega)) hs hlim + have h := (hu n).1 j + linarith + · exact source_contact_limit_spin_geometry k 0 p d (stepCumulative w) hz hz0 hz1 + (fun _=>0) (fun _ _=>0) (fun _ _=>le_rfl) (fun _=>monotone_const) u hu hm + (H:=0) (T:=0) le_rfl (fun _=>le_rfl) (fun _=>le_rfl) hcover hs hlim + +lemma indexedCommonDepth_ultrametric (n : ℕ) (a b c : IndexedLeaf n) : + min (indexedCommonDepth n a b) (indexedCommonDepth n a c)≤ indexedCommonDepth n b c := by + let l := min (indexedCommonDepth n a b) (indexedCommonDepth n a c) + apply (indexedLeafSharedVertex_eq_iff n b c l).mp + exact ((indexedLeafSharedVertex_eq_iff n a b l).mpr (min_le_left _ _)).symm.trans + ((indexedLeafSharedVertex_eq_iff n a c l).mpr (min_le_right _ _)) + +def CompactLabelGeometry (k : ℕ) (Q : CompactArray CompactJointOverlap) : Prop := + (∀ i j, (Q i j).2.val=(Q j i).2.val) ∧ + (∀ i, (Q i i).2.val=(k:ℝ)/(k+1:ℕ)) ∧ + ∀ i j l, min (Q i j).2.val (Q i l).2.val ≤ (Q j l).2.val + +lemma sourceJointArray_label_geometry {N k : ℕ} (x : ℕ→NormalizedSpin N×IndexedLeaf k) : + CompactLabelGeometry k (sourceJointArray x) := by + refine ⟨?_,?_,?_⟩ + · intro i j + simp only [sourceJointArray,sourceJointOverlap,indexedCommonDepth_comm k (x j).2 (x i).2] + · intro i + simp only [sourceJointArray,sourceJointOverlap,indexedCommonDepth_self,Fin.val_last] + · intro i j l + change min (((indexedCommonDepth k (x j).2 (x i).2).val:ℝ)/(k+1:ℕ)) + (((indexedCommonDepth k (x l).2 (x i).2).val:ℝ)/(k+1:ℕ))≤ + ((indexedCommonDepth k (x l).2 (x j).2).val:ℝ)/(k+1:ℕ) + have h := indexedCommonDepth_ultrametric k (x i).2 (x j).2 (x l).2 + rw [indexedCommonDepth_comm k (x i).2 (x j).2, + indexedCommonDepth_comm k (x i).2 (x l).2,indexedCommonDepth_comm k (x j).2 (x l).2] at h + rcases le_total (indexedCommonDepth k (x j).2 (x i).2) (indexedCommonDepth k (x l).2 (x i).2) with he|he + · rw [min_eq_left he] at h + exact (min_le_left _ _).trans (div_le_div_of_nonneg_right (by exact_mod_cast h) (by positivity)) + · rw [min_eq_right he] at h + exact (min_le_right _ _).trans (div_le_div_of_nonneg_right (by exact_mod_cast h) (by positivity)) + +lemma compactLabelGeometry_closed (k : ℕ) : IsClosed {Q | CompactLabelGeometry k Q} := by + unfold CompactLabelGeometry + simp only [ofPred_and, ofPred_forall] + exact (isClosed_iInter fun i => isClosed_iInter fun j => isClosed_eq (by fun_prop) (by fun_prop)).inter + ((isClosed_iInter fun i => isClosed_eq (by fun_prop) continuous_const).inter + (isClosed_iInter fun i => isClosed_iInter fun j => isClosed_iInter fun l => + isClosed_le (by fun_prop) (by fun_prop))) + +lemma sourceGibbsArray_limit_label_geometry (k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : (n : ℕ)→Fin (n+1)→ℕ) (h : ℕ→Fin (k+1)→ℝ) + (u : (n : ℕ)→Fin (n+1)→ℝ) (z : Fin k→ℝ) (t : ℕ→ℝ≥0) (s : ℕ→ℕ) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n=>sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactLabelGeometry k Q := by + have hc := compactLabelGeometry_closed k + apply (mem_ae_iff_prob_eq_one hc.measurableSet).mpr + have hv := weak_limit_closed_full hlim hc (fun n=>sourceGibbsArray_closed_full + (s n) k f (p (s n)) (d (s n)) (h (s n)) (u (s n)) z (t (s n)) hc + (fun x => sourceJointArray_label_geometry x)) + simp only [← ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelReferenceValue.lean b/lean/OAI/Probability/Perceptron/Variational/LabelReferenceValue.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c780e9380da0afc2f7664a73411e62449c921f8 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelReferenceValue.lean @@ -0,0 +1,84 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CountableFreshMoment +import OAI.Probability.Perceptron.Cavity.FreshReference + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def labelProfileTerminal (g : Jet3) (s : ℝ≥0) (v : EuclideanSpace ℝ (Fin 1)) : ℝ := + heatLog s 1 g.f (inner ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) v) + +lemma labelProfileTerminal_lipschitz (g : Jet3) (s : ℝ≥0) : + LipschitzWith (‖(g.heatLog s 1).d1‖₊* + ‖innerSL ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ)) : EuclideanSpace ℝ (Fin 1))‖₊) + (labelProfileTerminal g s) := by + have he : labelProfileTerminal g s = + fun v : EuclideanSpace ℝ (Fin 1) => (g.heatLog s 1).f + ((innerSL ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ)) : EuclideanSpace ℝ (Fin 1))) v) := by + funext v + rw [Jet3.heatLog_f] + rfl + rw [he] + have heatLipschitz : LipschitzWith ‖(g.heatLog s 1).d1‖₊ (g.heatLog s 1).f := by + apply lipschitzWith_of_nnnorm_deriv_le (fun point => ((g.heatLog s 1).has1 point).differentiableAt) + intro point + rw [(g.heatLog s 1).deriv_eq] + exact_mod_cast (g.heatLog s 1).d1.norm_coe_le_norm point + exact heatLipschitz.comp + (innerSL ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ)) : EuclideanSpace ℝ (Fin 1))).lipschitzWith + +lemma labelProfileTerminal_bound (g : Jet3) (s : ℝ≥0) (v : EuclideanSpace ℝ (Fin 1)) : + |labelProfileTerminal g s v|≤‖g.f‖ := heatLog_abs_le s 1 g.f _ + +lemma labelProfileTerminal_exp (g : Jet3) (s : ℝ≥0) (v : EuclideanSpace ℝ (Fin 1)) : + Real.exp (labelProfileTerminal g s v)= + gaussianAverageBCF s (expBCF 1 g.f) + (inner ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) v) := by + simpa only [NNReal.coe_one,one_mul,labelProfileTerminal,gaussianAverageBCF_coe] using + exp_heatLog s 1 (by norm_num) g.f + (inner ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) v) + +theorem source_countable_label_reference_value (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 diagonalMark (profileGaussianStep (fun l (_ : Fin 1) => q l) j) + let R := diagonalMark (profileGaussianRoot (fun l (_ : Fin 1) => q l)) + (∫ t : IndexedCascadeBase k×((ℕ→ℝ)×(ℕ→ℝ)), + Real.log (tiltMean (indexedLeafProbability k t.1) + (fun l => enrichedTerminal n M f a p u (h (Fin.last k)) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h + (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) t.2.2).1), + (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) t.2.2).2) l 0)) + (fun l => gaussianAverageBCF s (expBCF 1 g.f) + (labelProfileField q t.2.1 ((),l))) 1) + ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + (countableGaussianLaw.prod countableGaussianLaw)) = + ∫ x, gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (linearCascadeWord A k z) (labelProfileTerminal g s) (R x) + ∂stdGaussian (EuclideanSpace ℝ (Fin 1)) := by + dsimp only + have hv := source_countable_fresh_reference_value n M k f a p d h u z hz hz0 hz1 + (fun j => diagonalMark (profileGaussianStep (fun l (_ : Fin 1) => q l) j)) + (diagonalMark (profileGaussianRoot (fun l (_ : Fin 1) => q l))) + (labelProfileTerminal_lipschitz g ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩) + (norm_nonneg g.f) (labelProfileTerminal_bound g _) + refine (integral_congr_ae (ae_of_all _ fun t => ?_)).trans hv + unfold sourceFreshReferenceLog + congr 2 + funext l + dsimp only + rw [labelProfileField_marked_state] + exact (labelProfileTerminal_exp _ _ _).symm + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelResponse.lean b/lean/OAI/Probability/Perceptron/Variational/LabelResponse.lean new file mode 100644 index 0000000000000000000000000000000000000000..7603f9d641883f03c3ceae228952fa3cb982743d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelResponse.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.PureLabel +import OAI.Probability.Perceptron.Variational.DensityDerivative +import OAI.Probability.Perceptron.Variational.StepDual + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma diagonalCascadeWord_response_sum {I : Type} [Fintype I] + (A : ℕ→I→ℝ) (i : I) (k : ℕ) (z : Fin k→ℝ) : + ((diagonalCascadeWord A k z).map (fun a => a.1*(a.2 i)^2)).sum= + ∑ l : Fin k, z l*(A (k-1-l.val) i)^2 := by + induction k with + | zero => simp [diagonalCascadeWord] + | succ k ih => + simp only [diagonalCascadeWord,List.map_cons,List.sum_cons,ih,Fin.sum_univ_succ] + simp only [Fin.val_zero,Nat.add_sub_cancel,Nat.sub_zero,Fin.val_succ] + congr 1 + apply Finset.sum_congr rfl + intro l _ + have he : k-1-l.val=k-(l.val+1) := by omega + rw [he] + +lemma pureLabelResponse_sum {N k : ℕ} (p d : Fin N→ℕ) (j : Fin N) (hp : p j=0) + (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) : + pureLabelResponse p d j hp k h z= + ∑ i : Fin k, z i*((((i.val+1:ℕ):ℝ)/(k+1:ℕ))^(d j)- + ((i.val:ℝ)/(k+1:ℕ))^(d j)) := by + rw [pureLabelResponse,diagonalCascadeWord_response_sum] + apply Finset.sum_congr rfl + intro i _ + have hlt : k-1-i.val ((i.val:ℝ)/(k+1:ℕ))^(d j)) + simp only [Fin.val_last,Fin.val_zero,hw1,sub_self,mul_zero,zero_add,Fin.val_succ,Fin.val_castSucc] at he + rw [he] + apply Finset.sum_congr rfl + intro i _ + have hc : stepCumulative w i=1-∑ l : Fin (k+1), if i.castSucc enrichedExpectedLog n M k f p d (Function.update u j 0) h z + (patternPrefix (n+1) M g)) (infinitePatternRowsLaw (n+1)) := + (hi (Function.update u j 0)).integral_prod_left + rw [integral_add hi' (integrable_const _),integral_const, + probReal_univ,one_smul] + +lemma sourceExpectedPressure_pure_response (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) (u : Fin (n+1)→ℝ) + (j : Fin (n+1)) (hp : p j=0) + (hz : StrictMono z) (hz0 : ∀ i, 0 sourceExpectedPressure n k f p d h z t (u+Pi.single j r)) + ((1/(n+1:ℕ))*perturbationAmplitude (n+1) (fun _ => 1) j* + perturbationAmplitude (n+1) u j*pureLabelResponse p d j hp k h z) 0 := by + classical + have he (r : ℝ) : Function.update (u+Pi.single j r) j 0=Function.update u j 0 := by + funext l + by_cases hl : l=j + · subst l; simp + · simp [Function.update_of_ne hl,Pi.single_eq_of_ne hl] + have ha (r : ℝ) : perturbationAmplitude (n+1) (u+Pi.single j r) j= + perturbationAmplitude (n+1) (fun _ => 1) j*(u j+r) := by + simp only [perturbationAmplitude,Pi.add_apply,Pi.single_eq_same,mul_one] + have hf : (fun r => sourceExpectedPressure n k f p d h z t (u+Pi.single j r))= + (fun r => sourceExpectedPressure n k f p d h z t (Function.update u j 0)+ + (1/(n+1:ℕ))*(perturbationAmplitude (n+1) (fun _ => 1) j*(u j+r))^2/2* + pureLabelResponse p d j hp k h z) := by + funext r + rw [sourceExpectedPressure_pure_response n k f p d h z _ j hp hz hz0 hz1 t,he,ha] + rw [hf] + convert (((((hasDerivAt_id (0:ℝ)).const_add (u j)).const_mul + (perturbationAmplitude (n+1) (fun _ => 1) j)).pow 2).const_mul (1/((n+1:ℕ):ℝ)) |>.div_const (2:ℝ) + |>.mul_const (pureLabelResponse p d j hp k h z) |>.const_add + (sourceExpectedPressure n k f p d h z t (Function.update u j 0))) using 1 + all_goals first | rfl | (simp only [perturbationAmplitude,id_eq,add_zero,mul_one,Nat.reduceSub,Nat.cast_ofNat,pow_one]; ring) + +lemma source_label_moment (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (h w : Fin (k+1)→ℝ) + (hh0 : ∀ l, 0≤h l) (hh : Monotone h) (hw : ∀ l, 0 (((indexedCommonDepth k (x 0).2 (x 1).2).val:ℝ)/(k+1:ℕ))^(d j)) + ∂((sourceBaseDataLaw n k (stepCumulative w) t).prod countableGaussianLaw)= + ∑ l, w l*((l.val:ℝ)/(k+1:ℕ))^(d j) := by + have hz := stepCumulative_strictMono w hw + have hz0 := stepCumulative_pos w hw + have hz1 := stepCumulative_lt_one w hw hw1 + obtain ⟨D,hD,he⟩ := sourceExpectedPressure_coordinate_derivative n k f p d h hh0 hh u j + (stepCumulative w) hz hz0 hz1 t + have hd := sourceExpectedPressure_pure_derivative n k f p d h (stepCumulative w) u j hp hz hz0 hz1 t + change HasDerivAt (fun r => sourceExpectedPressure n k f p d h (stepCumulative w) t (u+Pi.single j r)) D 0 at hD + have hsame := hD.unique hd + rw [he,pureLabelResponse_weights p d j hp h w hw1] at hsame + simp only [sourceCouplingCovariance,sourceJointMonomial,hp,pow_zero,mul_one, + replicaMean_const_mul,integral_const_mul] at hsame + have hA : perturbationAmplitude (n+1) (fun _ => 1) j≠0 := by + unfold perturbationAmplitude perturbationScale + exact mul_ne_zero (mul_ne_zero (mul_ne_zero (by positivity) (by positivity)) (by positivity)) one_ne_zero + have hB : perturbationAmplitude (n+1) u j≠0 := by + unfold perturbationAmplitude perturbationScale + exact mul_ne_zero (mul_ne_zero (mul_ne_zero (by positivity) (by positivity)) (by positivity)) hu + have hN : (1/((n+1:ℕ):ℝ))≠0 := by positivity + apply (mul_left_cancel₀ (mul_ne_zero (mul_ne_zero hN hA) hB)) + nlinarith [hsame] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelRestorationKernel.lean b/lean/OAI/Probability/Perceptron/Variational/LabelRestorationKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..d2caf0441790855904749917240de538e1f85d35 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelRestorationKernel.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelRestorationMoments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +variable {A : Type*} {S : Type} [MeasurableSpace A] [MeasurableSpace S] {k r : ℕ} + +lemma labelRestorationWeight_joint (q : Fin (k+1) → ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) : + Measurable (Function.uncurry (labelRestorationWeight (S:=S) q s f)) := by + have h₁ := (labelProfileField_product_measurable (S:=S) q).comp + (show Measurable (fun p : ((ℕ→ℝ)×(ℕ→ℝ))×(S×IndexedLeaf k) => (p.1.1,p.2)) from + measurable_fst.fst.prodMk measurable_snd) + have h₂ := (labelProfileField_product_measurable (S:=S) q).comp + (show Measurable (fun p : ((ℕ→ℝ)×(ℕ→ℝ))×(S×IndexedLeaf k) => (p.1.2,p.2)) from + measurable_fst.snd.prodMk measurable_snd) + exact ((gaussianAverageBCF s (expBCF 1 f)).measurable.comp h₁).mul + ((gaussianAverageBCF s (expBCF 1 f)).measurable.comp h₂) + +lemma labelRestorationWeight_exp {S : Type} [MeasurableSpace S] {k : ℕ} + (q : Fin (k+1) → ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (z : (ℕ→ℝ)×(ℕ→ℝ)) (x : S×IndexedLeaf k) : + labelRestorationWeight q s f z x = + Real.exp (heatLog s 1 f (labelProfileField q z.1 x)+heatLog s 1 f (labelProfileField q z.2 x)) := by + have he (a : ℝ) : Real.exp (heatLog s 1 f a)=gaussianAverageBCF s (expBCF 1 f) a := by + simpa only [NNReal.coe_one,one_mul,gaussianAverageBCF_coe] using exp_heatLog s 1 (by norm_num) f a + simp only [Real.exp_add,he,labelRestorationWeight] + +variable (κ : Kernel A (S×IndexedLeaf k)) [IsMarkovKernel κ] +variable (H : A → S×IndexedLeaf k → ℝ) +variable (q : Fin (k+1) → ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) +variable (v w : Fin r → ℝ →ᵇ ℝ) (F : (Fin r → S×IndexedLeaf k) → ℝ) + +def labelKernelDenominator (a : A×((ℕ→ℝ)×(ℕ→ℝ))) : ℝ := + tiltMean (κ a.1) (H a.1) (labelRestorationWeight q s f a.2) 1 + +def labelKernelNumerator (a : A×((ℕ→ℝ)×(ℕ→ℝ))) : ℝ := + gibbsReplicaMean (κ a.1) (H a.1) r (labelRestorationTest q s f v w F a.2) + +lemma labelKernelDenominator_measurable (hH : Measurable (Function.uncurry H)) : + Measurable (labelKernelDenominator κ H q s f) := by + have hH' := hH.comp (show Measurable (fun p : (A×((ℕ→ℝ)×(ℕ→ℝ)))×(S×IndexedLeaf k) => + (p.1.1,p.2)) from measurable_fst.fst.prodMk measurable_snd) + have hW := (labelRestorationWeight_joint (S:=S) q s f).comp + (show Measurable (fun p : (A×((ℕ→ℝ)×(ℕ→ℝ)))×(S×IndexedLeaf k) => + (p.1.2,p.2)) from measurable_fst.snd.prodMk measurable_snd) + exact kernel_tiltMean_measurable (κ.comap Prod.fst measurable_fst) hH' hW + +lemma labelKernelNumerator_measurable (hH : Measurable (Function.uncurry H)) (hF : Measurable F) : + Measurable (labelKernelNumerator κ H q s f v w F) := by + have hH' := hH.comp (show Measurable (fun p : (A×((ℕ→ℝ)×(ℕ→ℝ)))×(S×IndexedLeaf k) => + (p.1.1,p.2)) from measurable_fst.fst.prodMk measurable_snd) + have hG := (labelTwoMixed_measurable (S:=S) q s (fun i => expBCF 1 f*v i) + (fun i => expBCF 1 f*w i) F hF).comp + (show Measurable (fun p : (A×((ℕ→ℝ)×(ℕ→ℝ)))×(Fin r → S×IndexedLeaf k) => + (p.1.2,p.2)) from measurable_fst.snd.prodMk measurable_snd) + exact kernel_replicaMean_measurable (κ.comap Prod.fst measurable_fst) hH' hG + +lemma labelKernelNumerator_bound (hH : Measurable (Function.uncurry H)) (hF : Measurable F) + {C : ℝ} (hC : 0≤C) (hb : ∀ x, |F x|≤C) (a : A×((ℕ→ℝ)×(ℕ→ℝ))) : + |labelKernelNumerator κ H q s f v w F a|≤ + C*(∏ i, ‖gaussianAverageBCF s (expBCF 1 f*v i)‖)*(∏ i, ‖gaussianAverageBCF s (expBCF 1 f*w i)‖) := by + apply tiltMean_bound_general (Measure.pi fun _ : Fin r => κ a.1) + (replicaPotential_measurable hH.of_uncurry_left r) + (labelRestorationTest_measurable q s f v w hF a.2) + (mul_nonneg (mul_nonneg hC (Finset.prod_nonneg fun _ _ => norm_nonneg _)) + (Finset.prod_nonneg fun _ _ => norm_nonneg _)) + exact labelRestorationTest_bound q s f v w hC hb a.2 + +lemma labelKernelDenominator_bounds (hH : Measurable (Function.uncurry H)) + {a : A} (hi : Integrable (fun x => Real.exp (H a x)) (κ a)) (z : (ℕ→ℝ)×(ℕ→ℝ)) : + labelKernelDenominator κ H q s f (a,z) ∈ Icc (Real.exp (-(2*‖f‖))) (Real.exp (2*‖f‖)) := by + have hm (g : ℕ→ℝ) : Measurable (fun x : S×IndexedLeaf k => heatLog s 1 f (labelProfileField q g x)) := by + have hp := (labelProfileField_product_measurable (S:=S) q).of_uncurry_left (x:=g) + exact (heatLog_continuous s 1 f).measurable.comp hp + have hb (x : S×IndexedLeaf k) : + |heatLog s 1 f (labelProfileField q z.1 x)+heatLog s 1 f (labelProfileField q z.2 x)|≤2*‖f‖ := + (abs_add_le _ _).trans ((add_le_add (heatLog_abs_le s 1 f _) (heatLog_abs_le s 1 f _)).trans_eq + (two_mul ‖f‖).symm) + have he := tiltMean_exp_bounds (κ a) hH.of_uncurry_left ((hm z.1).add (hm z.2)) hi + (mul_nonneg (by norm_num) (norm_nonneg f)) hb + have hw : labelRestorationWeight (S:=S) q s f z = fun x => + Real.exp (heatLog s 1 f (labelProfileField q z.1 x)+heatLog s 1 f (labelProfileField q z.2 x)) := + funext (labelRestorationWeight_exp q s f z) + simpa only [labelKernelDenominator,hw,Set.mem_Icc,Pi.add_apply] using he + +def labelKernelRestoredRatio (a : A×((ℕ→ℝ)×(ℕ→ℝ))) : ℝ := + labelKernelNumerator κ H q s f v w F a / (labelKernelDenominator κ H q s f a)^r + +lemma labelKernelRestoredRatio_measurable (hH : Measurable (Function.uncurry H)) (hF : Measurable F) : + Measurable (labelKernelRestoredRatio κ H q s f v w F) := + (labelKernelNumerator_measurable κ H q s f v w F hH hF).div + ((labelKernelDenominator_measurable κ H q s f hH).pow_const r) + +lemma labelKernelRestoredRatio_bound (hH : Measurable (Function.uncurry H)) (hF : Measurable F) + {C : ℝ} (hC : 0≤C) (hb : ∀ x, |F x|≤C) {a : A} + (hi : Integrable (fun x => Real.exp (H a x)) (κ a)) (z : (ℕ→ℝ)×(ℕ→ℝ)) : + |labelKernelRestoredRatio κ H q s f v w F (a,z)|≤ + (C*(∏ i, ‖gaussianAverageBCF s (expBCF 1 f*v i)‖)*(∏ i, ‖gaussianAverageBCF s (expBCF 1 f*w i)‖)) / + (Real.exp (-(2*‖f‖)))^r := by + have hd := (labelKernelDenominator_bounds κ H q s f hH hi z).1 + have hp : 0 Real.exp (H a x)) (κ a)) : + Integrable (labelKernelRestoredRatio κ H q s f v w F) + (P.prod (countableGaussianLaw.prod countableGaussianLaw)) := by + apply Integrable.of_bound (labelKernelRestoredRatio_measurable κ H q s f v w F hH hF).aestronglyMeasurable + ((C*(∏ i, ‖gaussianAverageBCF s (expBCF 1 f*v i)‖)*(∏ i, ‖gaussianAverageBCF s (expBCF 1 f*w i)‖)) / + (Real.exp (-(2*‖f‖)))^r) + have ha := (measurePreserving_fst (μ:=P) (ν:=countableGaussianLaw.prod countableGaussianLaw)).quasiMeasurePreserving.ae hi + filter_upwards [ha] with a ha + simpa only [Real.norm_eq_abs] using labelKernelRestoredRatio_bound κ H q s f v w F hH hF hC hb ha a.2 + +abbrev RestorationRange (f : ℝ →ᵇ ℝ) := Icc (Real.exp (-(2*‖f‖))) (Real.exp (2*‖f‖)) + +def restorationClip (f : ℝ →ᵇ ℝ) (x : ℝ) : RestorationRange f := + ⟨max (Real.exp (-(2*‖f‖))) (min (Real.exp (2*‖f‖)) x),le_max_left _ _, + max_le (Real.exp_le_exp.mpr (by nlinarith [norm_nonneg f])) (min_le_left _ _)⟩ +lemma restorationClip_measurable (f : ℝ →ᵇ ℝ) : Measurable (restorationClip f) := + (measurable_const.max (measurable_const.min measurable_id)).subtype_mk +lemma restorationClip_eq (f : ℝ →ᵇ ℝ) {x : ℝ} (hx : x∈RestorationRange f) : + (restorationClip f x).val=x := by + dsimp [restorationClip] + rw [min_eq_right hx.2,max_eq_right hx.1] + +def restorationReciprocal (f : ℝ →ᵇ ℝ) (r : ℕ) : C(RestorationRange f,ℝ) := + ⟨fun x => (x.val^r)⁻¹, (continuous_subtype_val.pow r).inv₀ + (fun x => (pow_pos ((Real.exp_pos _).trans_le x.prop.1) r).ne')⟩ + +lemma gaussianAverageBCF_norm_le (s : ℝ≥0) (f : ℝ →ᵇ ℝ) : ‖gaussianAverageBCF s f‖≤‖f‖ := by + rw [BoundedContinuousFunction.norm_le (norm_nonneg f)] + exact gaussianAverage_abs_le s f + +def labelKernelCompactDenominator (a : A×((ℕ→ℝ)×(ℕ→ℝ))) : RestorationRange f := + restorationClip f (labelKernelDenominator κ H q s f a) + +lemma labelKernelCompactDenominator_measurable (hH : Measurable (Function.uncurry H)) : + Measurable (labelKernelCompactDenominator κ H q s f) := + (restorationClip_measurable f).comp (labelKernelDenominator_measurable κ H q s f hH) + +lemma labelKernelCompactDenominator_eq (hH : Measurable (Function.uncurry H)) + {a : A} (hi : Integrable (fun x => Real.exp (H a x)) (κ a)) (z : (ℕ→ℝ)×(ℕ→ℝ)) : + (labelKernelCompactDenominator κ H q s f (a,z)).val=labelKernelDenominator κ H q s f (a,z) := + restorationClip_eq f (labelKernelDenominator_bounds κ H q s f hH hi z) + +lemma labelKernelNumerator_uniform_bound (hH : Measurable (Function.uncurry H)) (hF : Measurable F) + {C : ℝ} (hC : 0≤C) (hb : ∀ x, |F x|≤C) (a : A×((ℕ→ℝ)×(ℕ→ℝ))) : + |labelKernelNumerator κ H q s f v w F a|≤ + C*(∏ i, ‖expBCF 1 f*v i‖)*(∏ i, ‖expBCF 1 f*w i‖) := by + refine (labelKernelNumerator_bound κ H q s f v w F hH hF hC hb a).trans ?_ + apply mul_le_mul + · apply mul_le_mul_of_nonneg_left _ hC + exact Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) (fun _ _ => gaussianAverageBCF_norm_le s _) + · exact Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) (fun _ _ => gaussianAverageBCF_norm_le s _) + · exact Finset.prod_nonneg (fun _ _ => norm_nonneg _) + · exact mul_nonneg hC (Finset.prod_nonneg fun _ _ => norm_nonneg _) + +lemma labelKernel_weighted_integrable (hH : Measurable (Function.uncurry H)) (hF : Measurable F) + {C : ℝ} (hC : 0≤C) (hb : ∀ x, |F x|≤C) (P : Measure A) [IsFiniteMeasure P] + (J : C(RestorationRange f,ℝ)) : + Integrable (fun a => labelKernelNumerator κ H q s f v w F a * J (labelKernelCompactDenominator κ H q s f a)) + (P.prod (countableGaussianLaw.prod countableGaussianLaw)) := + weighted_compact_integrable _ _ (labelKernelNumerator_measurable κ H q s f v w F hH hF) + _ (labelKernelCompactDenominator_measurable κ H q s f hH) _ (by positivity) + (labelKernelNumerator_uniform_bound κ H q s f v w F hH hF hC hb) J + +lemma labelKernel_weighted_eq (hH : Measurable (Function.uncurry H)) + (P : Measure A) [IsFiniteMeasure P] + (hi : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) (J : ℝ→ℝ) : + (∫ a, labelKernelNumerator κ H q s f v w F a * J (labelKernelCompactDenominator κ H q s f a).val + ∂P.prod (countableGaussianLaw.prod countableGaussianLaw)) = + ∫ a, labelKernelNumerator κ H q s f v w F a * J (labelKernelDenominator κ H q s f a) + ∂P.prod (countableGaussianLaw.prod countableGaussianLaw) := by + apply integral_congr_ae + have ha := (measurePreserving_fst (μ:=P) (ν:=countableGaussianLaw.prod countableGaussianLaw)).quasiMeasurePreserving.ae hi + filter_upwards [ha] with a ha + rw [labelKernelCompactDenominator_eq κ H q s f hH ha a.2] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelRestorationMoments.lean b/lean/OAI/Probability/Perceptron/Variational/LabelRestorationMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..9b915890eeb87b3827373d6254e7054e4236f6ae --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelRestorationMoments.lean @@ -0,0 +1,187 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GibbsRestoration +import OAI.Probability.Perceptron.Variational.RestorationMoments +import OAI.Probability.Perceptron.Variational.TiltedPathDiagonal +import OAI.Probability.Perceptron.Variational.CountableMarkedDiagonal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +variable {S : Type} [MeasurableSpace S] {k : ℕ} + +def replicaFrontLift {r : ℕ} (F : (Fin r→S)→ℝ) : (j : ℕ)→(Fin (r+j)→S)→ℝ + | 0 => F + | j+1 => fun x => replicaFrontLift F j (fun i => x i.succ) + +lemma replicaFrontLift_measurable {r : ℕ} {F : (Fin r→S)→ℝ} + (hF : Measurable F) (j : ℕ) : Measurable (replicaFrontLift F j) := by + induction j with + | zero => exact hF + | succ j hj => exact hj.comp (Measurable.of_eval fun coordinate => measurable_pi_apply coordinate.succ) + +omit [MeasurableSpace S] in +lemma replicaFrontLift_bound {r : ℕ} {F : (Fin r→S)→ℝ} {C : ℝ} + (hF : ∀ x, |F x|≤C) (j : ℕ) (x : Fin (r+j)→S) : |replicaFrontLift F j x|≤C := by + induction j with + | zero => exact hF x + | succ j hj => exact hj _ + +def labelRestoredFunctions {r : ℕ} (f : ℝ →ᵇ ℝ) (v : Fin r→ℝ →ᵇ ℝ) : + (j : ℕ)→Fin (r+j)→ℝ →ᵇ ℝ + | 0 => fun i => expBCF 1 f*v i + | j+1 => Fin.cons (expBCF 1 f) (labelRestoredFunctions f v j) + +def labelRestorationWeight (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (z : (ℕ→ℝ)×(ℕ→ℝ)) (x : S×IndexedLeaf k) : ℝ := + gaussianAverageBCF s (expBCF 1 f) (labelProfileField q z.1 x) * + gaussianAverageBCF s (expBCF 1 f) (labelProfileField q z.2 x) + +def labelRestorationTest {r : ℕ} (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (v w : Fin r→ℝ →ᵇ ℝ) (F : (Fin r→S×IndexedLeaf k)→ℝ) + (z : (ℕ→ℝ)×(ℕ→ℝ)) (x : Fin r→S×IndexedLeaf k) : ℝ := + F x * labelMixedValue q s (fun i => expBCF 1 f*v i) z.1 x * + labelMixedValue q s (fun i => expBCF 1 f*w i) z.2 x + +omit [MeasurableSpace S] in +lemma labelRestorationTest_replica {r : ℕ} (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (v w : Fin r→ℝ →ᵇ ℝ) (F : (Fin r→S×IndexedLeaf k)→ℝ) + (z : (ℕ→ℝ)×(ℕ→ℝ)) (j : ℕ) (x : Fin (r+j)→S×IndexedLeaf k) : + restorationReplicaTest r (labelRestorationWeight q s f z) (labelRestorationTest q s f v w F z) j x = + replicaFrontLift F j x * labelMixedValue q s (labelRestoredFunctions f v j) z.1 x * + labelMixedValue q s (labelRestoredFunctions f w j) z.2 x := by + induction j with + | zero => rfl + | succ j hj => + change labelRestorationWeight q s f z (x 0) * + restorationReplicaTest r (labelRestorationWeight q s f z) (labelRestorationTest q s f v w F z) j (fun i => x i.succ) = _ + rw [hj] + simp only [Nat.add_succ,replicaFrontLift,labelMixedValue,labelRestoredFunctions,Fin.prod_univ_succ, + Fin.cons_zero,Fin.cons_succ,labelRestorationWeight] + ring + +lemma labelRestorationWeight_measurable (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (z : (ℕ→ℝ)×(ℕ→ℝ)) : Measurable (labelRestorationWeight (S:=S) q s f z) := by + have hm (a : ℕ→ℝ) : Measurable (fun x : S×IndexedLeaf k => + gaussianAverageBCF s (expBCF 1 f) (labelProfileField q a x)) := + by + have hp : Measurable (fun x : S×IndexedLeaf k => (a,x)) := measurable_const.prodMk measurable_id + have hfield := (labelProfileField_product_measurable (S:=S) q).comp hp + exact (gaussianAverageBCF s (expBCF 1 f)).measurable.comp hfield + exact (hm z.1).mul (hm z.2) + +omit [MeasurableSpace S] in +lemma labelRestorationWeight_bound (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (z : (ℕ→ℝ)×(ℕ→ℝ)) (x : S×IndexedLeaf k) : + |labelRestorationWeight q s f z x|≤‖gaussianAverageBCF s (expBCF 1 f)‖^2 := by + rw [labelRestorationWeight,abs_mul,pow_two] + exact mul_le_mul ((gaussianAverageBCF s (expBCF 1 f)).norm_coe_le_norm _) + ((gaussianAverageBCF s (expBCF 1 f)).norm_coe_le_norm _) (abs_nonneg _) (norm_nonneg _) + +lemma labelRestorationTest_measurable {r : ℕ} (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (v w : Fin r→ℝ →ᵇ ℝ) {F : (Fin r→S×IndexedLeaf k)→ℝ} (hF : Measurable F) + (z : (ℕ→ℝ)×(ℕ→ℝ)) : Measurable (labelRestorationTest q s f v w F z) := + (labelTwoMixed_measurable q s (fun i => expBCF 1 f*v i) (fun i => expBCF 1 f*w i) F hF).comp + (measurable_const.prodMk measurable_id) + +lemma labelRestorationTest_bound {r : ℕ} (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (v w : Fin r→ℝ →ᵇ ℝ) {F : (Fin r→S×IndexedLeaf k)→ℝ} {C : ℝ} (hC : 0≤C) + (hF : ∀ x, |F x|≤C) (z : (ℕ→ℝ)×(ℕ→ℝ)) (x : Fin r→S×IndexedLeaf k) : + |labelRestorationTest q s f v w F z x|≤ + C*(∏ i, ‖gaussianAverageBCF s (expBCF 1 f*v i)‖)*(∏ i, ‖gaussianAverageBCF s (expBCF 1 f*w i)‖) := by + simp only [labelRestorationTest,abs_mul] + exact mul_le_mul (mul_le_mul (hF _) (labelMixedValue_bound q s _ _ _) (abs_nonneg _) hC) + (labelMixedValue_bound q s _ _ _) (abs_nonneg _) + (mul_nonneg hC (Finset.prod_nonneg fun _ _ => norm_nonneg _)) + +lemma labelRestoration_moments {r : ℕ} (q : Fin (k+1)→ℝ) (h0 : 0≤q 0) (hq : Monotone q) + (h1 : q (Fin.last k)≤1) (f : ℝ →ᵇ ℝ) (v w : Fin r→ℝ →ᵇ ℝ) + (μ : Measure (S×IndexedLeaf k)) [IsProbabilityMeasure μ] (H : (S×IndexedLeaf k)→ℝ) + (hH : Measurable H) (hi : Integrable (fun x => Real.exp (H x)) μ) + (F : (Fin r→S×IndexedLeaf k)→ℝ) (hF : Measurable F) {C : ℝ} (hC : 0≤C) + (hb : ∀ x, |F x|≤C) (j : ℕ) : + let s : ℝ≥0 := ⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ + (∫ z, (tiltMean μ H (labelRestorationWeight q s f z) 1)^j * + gibbsReplicaMean μ H r (labelRestorationTest q s f v w F z) + ∂countableGaussianLaw.prod countableGaussianLaw) = + gibbsReplicaMean μ H (r+j) (fun xs => replicaFrontLift F j xs * + freshMarkedMatrixKernel (gaussianMixedTest (labelRestoredFunctions f v j)) + (fun i l => if i=l then 1 else q (indexedCommonDepth k (xs l).2 (xs i).2)) * + freshMarkedMatrixKernel (gaussianMixedTest (labelRestoredFunctions f w j)) + (fun i l => if i=l then 1 else q (indexedCommonDepth k (xs l).2 (xs i).2))) := by + intro s + have hi' : Integrable (fun x => Real.exp (1*H x)) μ := by simpa only [one_mul] using hi + let := tilt_law_probability_of_integrable μ hi' + have he (z : (ℕ→ℝ)×(ℕ→ℝ)) := restoration_replica_moment μ hH + (labelRestorationWeight_measurable q s f z) (labelRestorationTest_measurable q s f v w hF z) hi + (sq_nonneg _) (mul_nonneg (mul_nonneg hC (Finset.prod_nonneg fun _ _ => norm_nonneg _)) + (Finset.prod_nonneg fun _ _ => norm_nonneg _)) + (labelRestorationWeight_bound q s f z) (labelRestorationTest_bound q s f v w hC hb z) j + simp_rw [←he,gibbsReplicaMean_integral_of_integrable μ hH hi,labelRestorationTest_replica] + exact labelProfile_twoMixed_fubini q h0 hq h1 (Measure.pi fun _ : Fin (r+j) => tiltLaw μ H 1) + (labelRestoredFunctions f v j) (labelRestoredFunctions f w j) (replicaFrontLift F j) + (replicaFrontLift_measurable hF j) hC (replicaFrontLift_bound hb j) + +omit [MeasurableSpace S] in +lemma residual_replica_weight_cancel (s : ℝ≥0) (f : ℝ →ᵇ ℝ) (r : ℕ) + (v w : Fin r→ℝ →ᵇ ℝ) (a b : S→ℝ) (F : (Fin r→S)→ℝ) (xs : Fin r→S) : + (∏ i, Real.exp (heatLog s 1 f (a (xs i))+heatLog s 1 f (b (xs i)))) * + (F xs*(∏ i, residualResponse s f (v i) (a (xs i)))* + (∏ i, residualResponse s f (w i) (b (xs i)))) = + F xs*(∏ i, gaussianAverageBCF s (expBCF 1 f*v i) (a (xs i)))* + (∏ i, gaussianAverageBCF s (expBCF 1 f*w i) (b (xs i))) := by + have hex (x : ℝ) : Real.exp (heatLog s 1 f x)=gaussianAverage s (expBCF 1 f) x := by + simpa only [NNReal.coe_one,one_mul] using exp_heatLog s 1 (by norm_num) f x + simp_rw [Real.exp_add,hex] + calc + _ = F xs * (∏ i, gaussianAverage s (expBCF 1 f) (a (xs i))* + residualResponse s f (v i) (a (xs i))) * + (∏ i, gaussianAverage s (expBCF 1 f) (b (xs i))* + residualResponse s f (w i) (b (xs i))) := by + simp only [Finset.prod_mul_distrib]; ring + _ = _ := by simp_rw [residualResponse_weighted]; rfl + +lemma residual_gibbs_restore (μ : Measure S) [IsProbabilityMeasure μ] + (J : S→ℝ) (hJ : Measurable J) (hi : Integrable (fun x => Real.exp (J x)) μ) + (s : ℝ≥0) (f : ℝ →ᵇ ℝ) (r : ℕ) (v w : Fin r→ℝ →ᵇ ℝ) + (a b : S→ℝ) (F : (Fin r→S)→ℝ) : + gibbsReplicaMean μ (fun x => J x+(heatLog s 1 f (a x)+heatLog s 1 f (b x))) r + (fun xs => F xs*(∏ i, residualResponse s f (v i) (a (xs i)))* + (∏ i, residualResponse s f (w i) (b (xs i)))) = + gibbsReplicaMean μ J r (fun xs => + F xs*(∏ i, gaussianAverageBCF s (expBCF 1 f*v i) (a (xs i)))* + (∏ i, gaussianAverageBCF s (expBCF 1 f*w i) (b (xs i)))) / + (tiltMean μ J (fun x => gaussianAverageBCF s (expBCF 1 f) (a x)* + gaussianAverageBCF s (expBCF 1 f) (b x)) 1)^r := by + rw [gibbsReplicaMean_restore μ hJ hi] + have hex (x : S) : Real.exp (heatLog s 1 f (a x)+heatLog s 1 f (b x)) = + gaussianAverageBCF s (expBCF 1 f) (a x)*gaussianAverageBCF s (expBCF 1 f) (b x) := by + rw [Real.exp_add] + have he (y : ℝ) : Real.exp (heatLog s 1 f y)=gaussianAverageBCF s (expBCF 1 f) y := by + simpa only [NNReal.coe_one,one_mul,gaussianAverageBCF_coe] using exp_heatLog s 1 (by norm_num) f y + rw [he,he] + congr 1 + · apply congrArg (gibbsReplicaMean μ J r) + funext xs + exact residual_replica_weight_cancel s f r v w a b F xs + · simp_rw [hex] + +lemma labelRestoration_ratio {k r : ℕ} (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f : ℝ →ᵇ ℝ) + (v w : Fin r→ℝ →ᵇ ℝ) (μ : Measure (S×IndexedLeaf k)) [IsProbabilityMeasure μ] + (J : (S×IndexedLeaf k)→ℝ) (hJ : Measurable J) + (hi : Integrable (fun x => Real.exp (J x)) μ) + (F : (Fin r→S×IndexedLeaf k)→ℝ) (z : (ℕ→ℝ)×(ℕ→ℝ)) : + gibbsReplicaMean μ (fun x => J x+(heatLog s 1 f (labelProfileField q z.1 x)+ + heatLog s 1 f (labelProfileField q z.2 x))) r + (fun xs => F xs*(∏ i, residualResponse s f (v i) (labelProfileField q z.1 (xs i)))* + (∏ i, residualResponse s f (w i) (labelProfileField q z.2 (xs i)))) = + gibbsReplicaMean μ J r (labelRestorationTest q s f v w F z) / + (tiltMean μ J (labelRestorationWeight q s f z) 1)^r := + residual_gibbs_restore μ J hJ hi s f r v w (labelProfileField q z.1) (labelProfileField q z.2) F + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelRestorationMoments2.lean b/lean/OAI/Probability/Perceptron/Variational/LabelRestorationMoments2.lean new file mode 100644 index 0000000000000000000000000000000000000000..cf700182a975a0421d24f806150f53932a53043d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelRestorationMoments2.lean @@ -0,0 +1,200 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelRestorationKernel + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction + +def jointRestorationBlockTest (r : ℕ) (F : CompactBlock CompactJointOverlap r →ᵇ ℝ) : + (j : ℕ) → CompactBlock CompactJointOverlap (r+j) →ᵇ ℝ + | 0 => F + | j+1 => (jointRestorationBlockTest r F j).compContinuous + ⟨fun Q i l => Q i.succ l.succ,by fun_prop⟩ + +lemma jointRestorationBlockTest_source (N k r : ℕ) (F : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (j : ℕ) (x : Fin (r+j) → NormalizedSpin N×IndexedLeaf k) : + jointRestorationBlockTest r F j (fun i l => sourceJointOverlap (x i) (x l)) = + replicaFrontLift (fun x : Fin r → NormalizedSpin N×IndexedLeaf k => + F (fun i l => sourceJointOverlap (x i) (x l))) j x := by + induction j with + | zero => rfl + | succ j hj => exact hj _ + +lemma labelMarkedBlockKernel_source {N k r : ℕ} (q : Fin (k+1) → ℝ) + (Ψ : EuclideanSpace ℝ (Fin r) →ᵇ ℝ) (x : Fin r → NormalizedSpin N×IndexedLeaf k) : + labelMarkedBlockKernel q Ψ (fun i l => sourceJointOverlap (x i) (x l)) = + freshMarkedMatrixKernel Ψ (fun i l => if i=l then 1 else q (indexedCommonDepth k (x l).2 (x i).2)) := by + apply congrArg (freshMarkedMatrixKernel Ψ) + funext i l + change (if i=l then 1 else labelProfileInterpolant q (sourceJointOverlap (x i) (x l)).2)=_ + split_ifs with hi + · rfl + · exact labelProfileInterpolant_node q _ + +def labelRestorationBlockMoment {k r : ℕ} (q : Fin (k+1) → ℝ) (f : ℝ →ᵇ ℝ) + (v w : Fin r → ℝ →ᵇ ℝ) (F : CompactBlock CompactJointOverlap r →ᵇ ℝ) (j : ℕ) : + CompactBlock CompactJointOverlap (r+j) →ᵇ ℝ := + jointRestorationBlockTest r F j * labelMarkedBlockKernel q (gaussianMixedTest (labelRestoredFunctions f v j)) * + labelMarkedBlockKernel q (gaussianMixedTest (labelRestoredFunctions f w j)) + +lemma labelRestoration_to_block (N k r : ℕ) (q : Fin (k+1) → ℝ) + (h0 : 0≤q 0) (hq : Monotone q) (h1 : q (Fin.last k)≤1) + (ψ : ℝ →ᵇ ℝ) (v w : Fin r → ℝ →ᵇ ℝ) (F : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (μ : Measure (NormalizedSpin N×IndexedLeaf k)) [IsProbabilityMeasure μ] + (H : NormalizedSpin N×IndexedLeaf k → ℝ) (hH : Measurable H) + (hi : Integrable (fun x => Real.exp (H x)) μ) (j : ℕ) : + (∫ b, (tiltMean μ H (labelRestorationWeight q (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) ψ b) 1)^j * + gibbsReplicaMean μ H r (labelRestorationTest q (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) ψ v w + (fun x => F (fun i l => sourceJointOverlap (x i) (x l))) b) + ∂countableGaussianLaw.prod countableGaussianLaw) = + gibbsReplicaMean μ H (r+j) (fun x => labelRestorationBlockMoment q ψ v w F j + (fun i l => sourceJointOverlap (x i) (x l))) := by + have hp (i l : Fin r) : Measurable (fun x : Fin r → NormalizedSpin N×IndexedLeaf k => (x i,x l)) := + (measurable_pi_apply i).prodMk (measurable_pi_apply l) + have hc (i l : Fin r) := (sourceJointOverlap_measurable N k).comp (hp i l) + have hblock : Measurable (fun x : Fin r → NormalizedSpin N×IndexedLeaf k => + fun i l => sourceJointOverlap (x i) (x l)) := + Measurable.of_eval fun row => Measurable.of_eval fun column => hc row column + have hF := F.measurable.comp hblock + have he := labelRestoration_moments q h0 hq h1 ψ v w μ H hH hi _ hF + (norm_nonneg F) (fun x => F.norm_coe_le_norm _) j + refine he.trans ?_ + apply congrArg (gibbsReplicaMean μ H (r+j)) + funext x + simp only [labelRestorationBlockMoment,BoundedContinuousFunction.mul_apply, + labelMarkedBlockKernel_source,jointRestorationBlockTest_source] + rfl + +def sourceLabelRestorationMoment (n k r : ℕ) (q : Fin (k+1) → ℝ) (s : ℝ≥0) + (f ψ : ℝ →ᵇ ℝ) (v w : Fin r → ℝ →ᵇ ℝ) (F : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) (j : ℕ) : ℝ := + ∫ a, ∫ b, (tiltMean (sourceFullSpinLeafKernel n k a) + (sourceCouplingHamiltonian n k f p d h u a) (labelRestorationWeight q s ψ b) 1)^j * + gibbsReplicaMean (sourceFullSpinLeafKernel n k a) (sourceCouplingHamiltonian n k f p d h u a) r + (labelRestorationTest q s ψ v w (fun x => F (fun i l => sourceJointOverlap (x i) (x l))) b) + ∂countableGaussianLaw.prod countableGaussianLaw ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw + +lemma sourceLabelRestorationMoment_array (n k r : ℕ) (q : Fin (k+1) → ℝ) + (h0 : 0≤q 0) (hq : Monotone q) (h1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (v w : Fin r → ℝ →ᵇ ℝ) (F : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℝ≥0) (j : ℕ) : + sourceLabelRestorationMoment n k r q (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) f ψ v w F p d h u z t j = + ∫ Q, labelRestorationBlockMoment q ψ v w F j (compactBlock (r+j) Q) ∂sourceGibbsArrayLaw n k f p d h u z t := by + refine Eq.trans ?_ (sourceGibbsArray_block_integral n k f p d h hh0 hh u z t (r+j) + (F := fun Q => labelRestorationBlockMoment q ψ v w F j Q) + (labelRestorationBlockMoment q ψ v w F j).measurable + (fun Q => (labelRestorationBlockMoment q ψ v w F j).norm_coe_le_norm Q)).symm + unfold sourceLabelRestorationMoment + apply integral_congr_ae + filter_upwards [sourceFresh_exp_ae n k f p d h hh0 hh u z t] with a ha + exact labelRestoration_to_block (n+1) k r q h0 hq h1 ψ v w F _ _ + (sourceCouplingHamiltonian_measurable n k f p d h u).of_uncurry_left ha j + +lemma sourceLabelRestorationMoment_tendsto (k r : ℕ) (q : Fin (k+1) → ℝ) + (h0 : 0≤q 0) (hq : Monotone q) (h1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (v w : Fin r → ℝ →ᵇ ℝ) (F : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (p d : (n : ℕ) → Fin (n+1) → ℕ) (h : ℕ → Fin (k+1) → ℝ) + (hh0 : ∀ n i, 0≤h n i) (hh : ∀ n, Monotone (h n)) (u : (n : ℕ) → Fin (n+1) → ℝ) + (z : Fin k → ℝ) (t : ℕ → ℝ≥0) (s : ℕ → ℕ) + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) (j : ℕ) : + Tendsto (fun n => sourceLabelRestorationMoment (s n) k r q (⟨1-q (Fin.last k),sub_nonneg.mpr h1⟩ : ℝ≥0) + f ψ v w F (p (s n)) (d (s n)) (h (s n)) (u (s n)) z (t (s n)) j) atTop + (𝓝 (∫ Q, labelRestorationBlockMoment q ψ v w F j (compactBlock (r+j) Q) ∂ν)) := by + simp_rw [sourceLabelRestorationMoment_array _ _ _ _ h0 hq h1 _ _ _ _ _ _ _ _ (hh0 _) (hh _)] + exact (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + ((labelRestorationBlockMoment q ψ v w F j).compContinuous + ⟨compactBlock (r+j),compactBlock_continuous (r+j)⟩)).continuousAt.tendsto.comp hlim + +lemma sourceReplicaBlock_measurable (N k r : ℕ) : + Measurable (fun x : Fin r → NormalizedSpin N×IndexedLeaf k => + fun i l => sourceJointOverlap (x i) (x l)) := by + have hp (i l : Fin r) : Measurable (fun x : Fin r → NormalizedSpin N×IndexedLeaf k => (x i,x l)) := + (measurable_pi_apply i).prodMk (measurable_pi_apply l) + have hc (i l : Fin r) := (sourceJointOverlap_measurable N k).comp (hp i l) + exact Measurable.of_eval fun row => Measurable.of_eval fun column => hc row column + +variable (n k r : ℕ) (q : Fin (k+1) → ℝ) (s : ℝ≥0) +variable (f ψ : ℝ →ᵇ ℝ) (v w : Fin r → ℝ →ᵇ ℝ) (F : CompactBlock CompactJointOverlap r →ᵇ ℝ) +variable (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) +variable (z : Fin k → ℝ) (t : ℝ≥0) + +def sourceLabelRestorationNumerator := + labelKernelNumerator (sourceFullSpinLeafKernel n k) (sourceCouplingHamiltonian n k f p d h u) + q s ψ v w (fun x => F (fun i l => sourceJointOverlap (x i) (x l))) +def sourceLabelRestorationDenominator := + labelKernelCompactDenominator (sourceFullSpinLeafKernel n k) (sourceCouplingHamiltonian n k f p d h u) q s ψ + +def sourceLabelRestorationRatio : ℝ := + ∫ a, sourceLabelRestorationNumerator n k r q s f ψ v w F p d h u a * + restorationReciprocal ψ r (sourceLabelRestorationDenominator n k q s f ψ p d h u a) + ∂((sourceBaseDataLaw n k z t).prod countableGaussianLaw).prod (countableGaussianLaw.prod countableGaussianLaw) + +lemma sourceLabelRestorationNumerator_measurable : + Measurable (sourceLabelRestorationNumerator n k r q s f ψ v w F p d h u) := + labelKernelNumerator_measurable _ _ _ _ _ _ _ _ (sourceCouplingHamiltonian_measurable n k f p d h u) + (F.measurable.comp (sourceReplicaBlock_measurable (n+1) k r)) + +lemma sourceLabelRestorationDenominator_measurable : + Measurable (sourceLabelRestorationDenominator n k q s f ψ p d h u) := + labelKernelCompactDenominator_measurable _ _ _ _ _ (sourceCouplingHamiltonian_measurable n k f p d h u) + +lemma sourceLabelRestorationNumerator_bound (a) : + |sourceLabelRestorationNumerator n k r q s f ψ v w F p d h u a|≤ + ‖F‖*(∏ i, ‖expBCF 1 ψ*v i‖)*(∏ i, ‖expBCF 1 ψ*w i‖) := + labelKernelNumerator_uniform_bound _ _ _ _ _ _ _ _ (sourceCouplingHamiltonian_measurable n k f p d h u) + (F.measurable.comp (sourceReplicaBlock_measurable (n+1) k r)) (norm_nonneg F) + (fun _ => F.norm_coe_le_norm _) a + +lemma sourceLabelRestorationPolynomial (hh0 : ∀ i,0≤h i) (hh : Monotone h) (j : ℕ) : + (∫ a, sourceLabelRestorationNumerator n k r q s f ψ v w F p d h u a * + (sourceLabelRestorationDenominator n k q s f ψ p d h u a).val^j + ∂((sourceBaseDataLaw n k z t).prod countableGaussianLaw).prod (countableGaussianLaw.prod countableGaussianLaw)) = + sourceLabelRestorationMoment n k r q s f ψ v w F p d h u z t j := by + let κ := sourceFullSpinLeafKernel n k + let H := sourceCouplingHamiltonian n k f p d h u + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + let T := fun x : Fin r → NormalizedSpin (n+1)×IndexedLeaf k => F (fun i l => sourceJointOverlap (x i) (x l)) + have hH := sourceCouplingHamiltonian_measurable n k f p d h u + have hT := F.measurable.comp (sourceReplicaBlock_measurable (n+1) k r) + have hF := sourceFresh_exp_ae n k f p d h hh0 hh u z t + let J : C(RestorationRange ψ,ℝ) := ⟨fun x => x.val^j,continuous_subtype_val.pow j⟩ + have hI := labelKernel_weighted_integrable κ H q s ψ v w T hH hT + (norm_nonneg F) (fun x => F.norm_coe_le_norm _) P J + have hae := (measurePreserving_fst (μ:=P) (ν:=countableGaussianLaw.prod countableGaussianLaw)).quasiMeasurePreserving.ae hF + have hEq : (fun a => labelKernelNumerator κ H q s ψ v w T a * J (labelKernelCompactDenominator κ H q s ψ a)) =ᵐ[P.prod (countableGaussianLaw.prod countableGaussianLaw)] + (fun a => labelKernelNumerator κ H q s ψ v w T a * (labelKernelDenominator κ H q s ψ a)^j) := by + filter_upwards [hae] with a ha + dsimp only [J,ContinuousMap.coe_mk] + rw [labelKernelCompactDenominator_eq κ H q s ψ hH ha a.2] + have hi := hI.congr hEq + change (∫ a, labelKernelNumerator κ H q s ψ v w T a * J (labelKernelCompactDenominator κ H q s ψ a) ∂P.prod _) = _ + rw [integral_congr_ae hEq,integral_prod _ hi] + unfold sourceLabelRestorationMoment + apply integral_congr_ae + exact ae_of_all _ fun a => integral_congr_ae (ae_of_all _ fun b => mul_comm _ _) + +lemma sourceLabelRestorationRatio_eq (hh0 : ∀ i,0≤h i) (hh : Monotone h) : + sourceLabelRestorationRatio n k r q s f ψ v w F p d h u z t = + ∫ a, labelKernelRestoredRatio (sourceFullSpinLeafKernel n k) + (sourceCouplingHamiltonian n k f p d h u) q s ψ v w + (fun x => F (fun i l => sourceJointOverlap (x i) (x l))) a + ∂((sourceBaseDataLaw n k z t).prod countableGaussianLaw).prod (countableGaussianLaw.prod countableGaussianLaw) := by + have he := labelKernel_weighted_eq (sourceFullSpinLeafKernel n k) + (sourceCouplingHamiltonian n k f p d h u) q s ψ v w + (fun x => F (fun i l => sourceJointOverlap (x i) (x l))) + (sourceCouplingHamiltonian_measurable n k f p d h u) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceFresh_exp_ae n k f p d h hh0 hh u z t) (fun x => (x^r)⁻¹) + simpa only [sourceLabelRestorationRatio,sourceLabelRestorationNumerator,sourceLabelRestorationDenominator, + restorationReciprocal,ContinuousMap.coe_mk,labelKernelRestoredRatio,div_eq_mul_inv] using he + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelRestorationPair.lean b/lean/OAI/Probability/Perceptron/Variational/LabelRestorationPair.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ddf87365b35daaba39bbd7cf1d21f8c4a29b40e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelRestorationPair.lean @@ -0,0 +1,224 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelValue +import OAI.Probability.Perceptron.Variational.LabelRestorationMoments +import OAI.Probability.Perceptron.Variational.BoundedLeafRestoration +import OAI.Probability.Perceptron.Interpolation.TripleGaussianReplica + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev labelGaussianStep {k : ℕ} (q : Fin (k+1)→ℝ) := + fun j => diagonalMark (profileGaussianStep (fun l (_ : Fin 1) => q l) j) +abbrev labelGaussianRoot {k : ℕ} (q : Fin (k+1)→ℝ) := + diagonalMark (profileGaussianRoot (fun l (_ : Fin 1) => q l)) +def labelEvaluation (x : EuclideanSpace ℝ (Fin 1)) : ℝ := + inner ℝ (WithLp.toLp 2 (fun _ : Fin 1 => (1:ℝ))) x + +def labelResidualObservable (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) : EuclideanSpace ℝ (Fin 1)→ℝ := + fun x => residualResponse s f v (labelEvaluation x) + +lemma labelProfileField_leaf {S : Type} [MeasurableSpace S] {k : ℕ} + (q : Fin (k+1)→ℝ) (g : ℕ→ℝ) (x : S×IndexedLeaf k) : + labelProfileField q g x=labelEvaluation (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) g x.2) := + labelProfileField_marked_state q g x + +lemma labelResidualObservable_measurable (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) : + Measurable (labelResidualObservable s f v) := + (residualResponse_continuous s f v).measurable.comp (by unfold labelEvaluation; fun_prop) + +lemma labelResidualObservable_bound (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) (x : EuclideanSpace ℝ (Fin 1)) : + |labelResidualObservable s f v x|≤‖v‖ := residualResponse_bound s f v _ + +variable {S K : Type} [MeasurableSpace S] [Fintype K] + +lemma labelRestorationPair_eq_terminal (μ : Measure S) [IsProbabilityMeasure μ] + (k : ℕ) (b : IndexedCascadeBase k) (J : S×IndexedLeaf k→ℝ) (hJ : Measurable J) + (C : ℕ→EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) + (T : EuclideanSpace ℝ K →L[ℝ] EuclideanSpace ℝ K) (F : EuclideanSpace ℝ K→ℝ) + (hF : Measurable F) (t : ((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ)) + (hi : Integrable (fun x => Real.exp (J x)) (μ.prod (indexedLeafProbability k b))) + (hp : ∀ l, (∫ x, Real.exp (J (x,l)) ∂μ)=Real.exp (F (gaussianLeafValue k C T t.2 l))) + (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (d : Fin (k+1)) (v w : ℝ →ᵇ ℝ) : + gibbsReplicaMean (μ.prod (indexedLeafProbability k b)) J 2 + (labelRestorationTest q s g.f (fun _ => v) (fun _ => w) + (fun xs => if indexedCommonDepth k (xs 0).2 (xs 1).2=d then 1 else 0) t.1) / + (tiltMean (μ.prod (indexedLeafProbability k b)) J (labelRestorationWeight q s g.f t.1) 1)^2 = + tripleGaussianPair k (labelGaussianStep q) (labelGaussianStep q) C + (labelGaussianRoot q) (labelGaussianRoot q) T (labelProfileTerminal g s) (labelProfileTerminal g s) F d + (labelResidualObservable s g.f v) (labelResidualObservable s g.f w) + (tripleGaussianCountableData k b t) := by + let G : IndexedLeaf k→ℝ := fun l => F (gaussianLeafValue k C T t.2 l) + let W : IndexedLeaf k→ℝ := fun l => + labelProfileTerminal g s (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 l)+ + labelProfileTerminal g s (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 l) + let O : (Fin 2→IndexedLeaf k)→ℝ := fun l => if indexedCommonDepth k (l 0) (l 1)=d then + (labelResidualObservable s g.f v (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 (l 0))* + labelResidualObservable s g.f w (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 (l 0)))* + (labelResidualObservable s g.f v (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 (l 1))* + labelResidualObservable s g.f w (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 (l 1))) else 0 + have hW (l) : W l≤2*‖g.f‖ := by + dsimp only [W] + linarith [(le_abs_self _).trans (labelProfileTerminal_bound g s + (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 l)), + (le_abs_self _).trans (labelProfileTerminal_bound g s + (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 l))] + have hiG : Integrable (fun l => Real.exp (G l)) (indexedLeafProbability k b) := by + simpa only [hp,G] using hi.integral_prod_right + have hiGW := exp_add_integrable_of_bound _ hiG (measurable_of_countable W) hW + have hie : Integrable (fun l => Real.exp ( + (labelProfileTerminal g s (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 l)+ + labelProfileTerminal g s (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 l))+ + F (gaussianLeafValue k C T t.2 l))) (indexedLeafProbability k b) := by + convert hiGW using 1 + funext l + congr 1 + exact add_comm _ _ + rw [←labelRestoration_ratio q s g.f (fun _ : Fin 2 => v) (fun _ => w) + (μ.prod (indexedLeafProbability k b)) J hJ hi _ t.1] + have he := product_leaf_restore μ (indexedLeafProbability k b) J G W hJ + (measurable_of_countable G) (measurable_of_countable W) hi hp hW 2 O (measurable_of_countable O) + have hr := tripleGaussianPair_replica k (labelGaussianStep q) (labelGaussianStep q) C + (labelGaussianRoot q) (labelGaussianRoot q) T (labelProfileTerminal g s) (labelProfileTerminal g s) F + (labelProfileTerminal_lipschitz g s).continuous.measurable + (labelProfileTerminal_lipschitz g s).continuous.measurable hF d + (labelResidualObservable s g.f v) (labelResidualObservable s g.f w) b t hie + rw [hr] + refine (gibbsReplicaMean_congr _ _ _ ?_ 2 _ _ ?_).trans (he.trans ?_) + · intro x + simp only [labelProfileField_leaf,W,labelProfileTerminal,labelEvaluation] + · intro xs + simp only [Fin.prod_univ_two,labelProfileField_leaf,O,labelResidualObservable] + split_ifs <;> ring + · apply gibbsReplicaMean_congr + · intro l; exact add_comm _ _ + · intro l; rfl + +def labelPairCoefficient (k : ℕ) (z : Fin k→ℝ) (q : Fin (k+1)→ℝ) + (g : Jet3) (s : ℝ≥0) (v : ℝ →ᵇ ℝ) (d : Fin (k+1)) : ℝ := + rootPathCorrelation (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (fun r => fun _ => labelGaussianRoot q r) k + (fun i => tiltedStateStep (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin 1))) + (gaussianLinearMarkStep (labelGaussianStep q)) (z i) + (finiteCascadeShifts (gaussianMarkLaw (E:=EuclideanSpace ℝ (Fin 1))) + (gaussianLinearMarkStep (labelGaussianStep q)) k z (fun x => labelProfileTerminal g s (x 0)) i)) + (fun x => labelResidualObservable s g.f v (x 0)) d + +def sourceLabelPairRatio (n M k : ℕ) (f : ℝ →ᵇ ℝ) (a : Fin M→Fin (n+1)→ℝ) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (d : Fin (k+1)) (v w : ℝ →ᵇ ℝ) + (t : IndexedCascadeBase k×(((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ))) : ℝ := + gibbsReplicaMean (enrichedIndexedBaseMeasure n k t.1) + (enrichedIndexedHamiltonian n M k f a p e h u t.2.2) 2 + (labelRestorationTest q s g.f (fun _ => v) (fun _ => w) + (fun xs => if indexedCommonDepth k (xs 0).2 (xs 1).2=d then 1 else 0) t.2.1) / + (tiltMean (enrichedIndexedBaseMeasure n k t.1) + (enrichedIndexedHamiltonian n M k f a p e h u t.2.2) (labelRestorationWeight q s g.f t.2.1) 1)^2 + +lemma enrichedIndexedHamiltonian_joint_measurable (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M → Fin (n+1) → ℝ) (p e : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (u : Fin (n+1) → ℝ) : + Measurable (Function.uncurry (enrichedIndexedHamiltonian n M k f a p e h u)) := by + unfold enrichedIndexedHamiltonian + exact countableGaussianHamiltonian_measurable (enrichedIndexedBoundedEnergy_measurable n M k f a h) + (sourceGaussianRow_measurable p e h u) (indexedGaussianRowLength_measurable (I:=EnrichedIndex (n+1) (n+1) p) k) + +lemma sourceLabelPair_exp_ae (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p e : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) (u : Fin (n+1)→ℝ) + (z : Fin k→ℝ) : + ∀ᵐ t ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((countableGaussianLaw.prod countableGaussianLaw).prod countableGaussianLaw), + Integrable (fun x => Real.exp (enrichedIndexedHamiltonian n M k f a p e h u t.2.2 x)) + (enrichedIndexedBaseMeasure n k t.1) := by + let D := IndexedCascadeBase k×(((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ)) + let κ : Kernel D (NormalizedSpin (n+1)×IndexedLeaf k) := + (Kernel.const D (unitSphereLaw (n+1))).prod ((indexedLeafKernel k).comap Prod.fst measurable_fst) + have hκ (t : D) : κ t=enrichedIndexedBaseMeasure n k t.1 := by + rw [Kernel.prod_apply]; rfl + let H : D→NormalizedSpin (n+1)×IndexedLeaf k→ℝ := + fun t => enrichedIndexedHamiltonian n M k f a p e h u t.2.2 + have hbase := enrichedIndexedHamiltonian_joint_measurable n M k f a p e h u + have ht : Measurable (fun p : D×(NormalizedSpin (n+1)×IndexedLeaf k) => (p.1.2.2,p.2)) := + measurable_fst.snd.snd.prodMk measurable_snd + have hc := hbase.comp ht + have hH : Measurable (Function.uncurry H) := hc + have hm : MeasurableSet {t : D | Integrable (fun x => Real.exp (H t x)) (κ t)} := + measurableSet_kernel_integrable (κ:=κ) (f:=fun t x => Real.exp (H t x)) hH.exp.stronglyMeasurable + have hi : ∀ᵐ t ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((countableGaussianLaw.prod countableGaussianLaw).prod countableGaussianLaw), + Integrable (fun x => Real.exp (H t x)) (κ t) := by + apply (Measure.ae_prod_iff_ae_ae hm).mpr + refine ae_of_all _ fun b => ?_ + have hi := (measurePreserving_snd (μ:=countableGaussianLaw.prod countableGaussianLaw) + (ν:=countableGaussianLaw)).quasiMeasurePreserving.ae + (enrichedIndexedHamiltonian_exp_ae n M k f a p e h hh0 hh u b) + simpa only [hκ,H] using hi + simpa only [hκ,H] using hi + +lemma sourceLabelPairRatio_eq_triple (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p e : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (d : Fin (k+1)) (v w : ℝ →ᵇ ℝ) (t : IndexedCascadeBase k×(((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ))) + (hi : Integrable (fun x => Real.exp (enrichedIndexedHamiltonian n M k f a p e h u t.2.2 x)) + (enrichedIndexedBaseMeasure n k t.1)) : + sourceLabelPairRatio n M k f a p e h u q g s d v w t = + tripleGaussianPair k (labelGaussianStep q) (labelGaussianStep q) (enrichedIncrementMap p e h) + (labelGaussianRoot q) (labelGaussianRoot q) (enrichedRootMap p e h) + (labelProfileTerminal g s) (labelProfileTerminal g s) (enrichedTerminal n M f a p u (h (Fin.last k))) d + (labelResidualObservable s g.f v) (labelResidualObservable s g.f w) + (tripleGaussianCountableData k (I:=Fin 1) (J:=Fin 1) (K:=EnrichedIndex (n+1) (n+1) p) t.1 t.2) := by + have hbase := enrichedIndexedHamiltonian_joint_measurable n M k f a p e h u + have hmJ : Measurable (enrichedIndexedHamiltonian n M k f a p e h u t.2.2) := + hbase.of_uncurry_left + have he := labelRestorationPair_eq_terminal (unitSphereLaw (n+1)) k t.1 + (enrichedIndexedHamiltonian n M k f a p e h u t.2.2) hmJ + (enrichedIncrementMap p e h) (enrichedRootMap p e h) (enrichedTerminal n M f a p u (h (Fin.last k))) + (enrichedTerminal_lipschitz n M f a p u (h (Fin.last k))).continuous.measurable t.2 hi + (enrichedIndexedHamiltonian_leaf_partition n M k f a p e h u t.2.2) q g s d v w + exact he + +lemma sourceLabelPairRatio_eq_triple_ae (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p e : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) (u : Fin (n+1)→ℝ) + (z : Fin k→ℝ) (_hz : StrictMono z) (_hz0 : ∀ i, 0 Real.exp (J x)) (μ.prod (indexedLeafProbability k b))) + (hp : ∀ l, (∫ x, Real.exp (J (x,l)) ∂μ)=Real.exp (F (gaussianLeafValue k C T t.2 l))) + (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (v w : ℝ →ᵇ ℝ) : + gibbsReplicaMean (μ.prod (indexedLeafProbability k b)) J 1 + (labelRestorationTest q s g.f (fun _ => v) (fun _ => w) + (fun _ => 1) t.1) / + (tiltMean (μ.prod (indexedLeafProbability k b)) J (labelRestorationWeight q s g.f t.1) 1)^1 = + tripleGaussianMean k (labelGaussianStep q) (labelGaussianStep q) C + (labelGaussianRoot q) (labelGaussianRoot q) T (labelProfileTerminal g s) (labelProfileTerminal g s) F + (labelResidualObservable s g.f v) (labelResidualObservable s g.f w) + (tripleGaussianCountableData k b t) := by + let G : IndexedLeaf k→ℝ := fun l => F (gaussianLeafValue k C T t.2 l) + let W : IndexedLeaf k→ℝ := fun l => + labelProfileTerminal g s (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 l)+ + labelProfileTerminal g s (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 l) + let O : (Fin 1→IndexedLeaf k)→ℝ := fun l => + labelResidualObservable s g.f v (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 (l 0))* + labelResidualObservable s g.f w (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 (l 0)) + have hW (l) : W l≤2*‖g.f‖ := by + dsimp only [W] + linarith [(le_abs_self _).trans (labelProfileTerminal_bound g s + (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 l)), + (le_abs_self _).trans (labelProfileTerminal_bound g s + (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 l))] + have hiG : Integrable (fun l => Real.exp (G l)) (indexedLeafProbability k b) := by + simpa only [hp,G] using hi.integral_prod_right + have hiGW := exp_add_integrable_of_bound _ hiG (measurable_of_countable W) hW + have hie : Integrable (fun l => Real.exp ( + (labelProfileTerminal g s (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.1 l)+ + labelProfileTerminal g s (gaussianLeafValue k (labelGaussianStep q) (labelGaussianRoot q) t.1.2 l))+ + F (gaussianLeafValue k C T t.2 l))) (indexedLeafProbability k b) := by + convert hiGW using 1 + funext l + congr 1 + exact add_comm _ _ + rw [←labelRestoration_ratio q s g.f (fun _ : Fin 1 => v) (fun _ => w) + (μ.prod (indexedLeafProbability k b)) J hJ hi _ t.1] + have he := product_leaf_restore μ (indexedLeafProbability k b) J G W hJ + (measurable_of_countable G) (measurable_of_countable W) hi hp hW 1 O (measurable_of_countable O) + have hr := tripleGaussianMean_replica k (labelGaussianStep q) (labelGaussianStep q) C + (labelGaussianRoot q) (labelGaussianRoot q) T (labelProfileTerminal g s) (labelProfileTerminal g s) F + (labelProfileTerminal_lipschitz g s).continuous.measurable + (labelProfileTerminal_lipschitz g s).continuous.measurable hF + (labelResidualObservable s g.f v) (labelResidualObservable s g.f w) b t hie + rw [hr] + refine (gibbsReplicaMean_congr _ _ _ ?_ 1 _ _ ?_).trans (he.trans ?_) + · intro x + simp only [labelProfileField_leaf,W,labelProfileTerminal,labelEvaluation] + · intro xs + simp only [Fin.prod_univ_one,labelProfileField_leaf,O,labelResidualObservable] + ring + · apply gibbsReplicaMean_congr + · intro l; exact add_comm _ _ + · intro l; rfl + +def sourceLabelSingleRatio (n M k : ℕ) (f : ℝ →ᵇ ℝ) (a : Fin M→Fin (n+1)→ℝ) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (v w : ℝ →ᵇ ℝ) + (t : IndexedCascadeBase k×(((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ))) : ℝ := + gibbsReplicaMean (enrichedIndexedBaseMeasure n k t.1) + (enrichedIndexedHamiltonian n M k f a p e h u t.2.2) 1 + (labelRestorationTest q s g.f (fun _ => v) (fun _ => w) + (fun _ => 1) t.2.1) / + (tiltMean (enrichedIndexedBaseMeasure n k t.1) + (enrichedIndexedHamiltonian n M k f a p e h u t.2.2) (labelRestorationWeight q s g.f t.2.1) 1)^1 + +lemma sourceLabelSingleRatio_eq_triple (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p e : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (v w : ℝ →ᵇ ℝ) (t : IndexedCascadeBase k×(((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ))) + (hi : Integrable (fun x => Real.exp (enrichedIndexedHamiltonian n M k f a p e h u t.2.2 x)) + (enrichedIndexedBaseMeasure n k t.1)) : + sourceLabelSingleRatio n M k f a p e h u q g s v w t = + tripleGaussianMean k (labelGaussianStep q) (labelGaussianStep q) (enrichedIncrementMap p e h) + (labelGaussianRoot q) (labelGaussianRoot q) (enrichedRootMap p e h) + (labelProfileTerminal g s) (labelProfileTerminal g s) (enrichedTerminal n M f a p u (h (Fin.last k))) + (labelResidualObservable s g.f v) (labelResidualObservable s g.f w) + (tripleGaussianCountableData k (I:=Fin 1) (J:=Fin 1) (K:=EnrichedIndex (n+1) (n+1) p) t.1 t.2) := by + have hbase := enrichedIndexedHamiltonian_joint_measurable n M k f a p e h u + have hmJ : Measurable (enrichedIndexedHamiltonian n M k f a p e h u t.2.2) := + hbase.of_uncurry_left + have he := labelRestorationSingle_eq_terminal (unitSphereLaw (n+1)) k t.1 + (enrichedIndexedHamiltonian n M k f a p e h u t.2.2) hmJ + (enrichedIncrementMap p e h) (enrichedRootMap p e h) (enrichedTerminal n M f a p u (h (Fin.last k))) + (enrichedTerminal_lipschitz n M f a p u (h (Fin.last k))).continuous.measurable t.2 hi + (enrichedIndexedHamiltonian_leaf_partition n M k f a p e h u t.2.2) q g s v w + exact he + +lemma sourceLabelSingleRatio_eq_triple_ae (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p e : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) (u : Fin (n+1)→ℝ) + (z : Fin k→ℝ) (_hz : StrictMono z) (_hz0 : ∀ i, 0 ((x 0).2,(x 1).2)) := + ((measurable_pi_apply 0).snd).prodMk ((measurable_pi_apply 1).snd) + exact (measurable_of_countable (fun p : IndexedLeaf k×IndexedLeaf k => + if indexedCommonDepth k p.1 p.2=d then (1:ℝ) else 0)).comp hc + +lemma labelDepthTest_bound {S : Type} (k : ℕ) (d : Fin (k+1)) (x : Fin 2 → S×IndexedLeaf k) : + |labelDepthTest k d x|≤1 := by unfold labelDepthTest; split <;> norm_num + +def sourceLabelPairIntegrand (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (d : Fin (k+1)) (v w : ℝ →ᵇ ℝ) := + labelKernelRestoredRatio (sourceFullSpinLeafKernel n k) + (sourceCouplingHamiltonian n k f p e h u) q s g.f (fun _ : Fin 2 => v) (fun _ => w) (labelDepthTest k d) + +lemma sourceLabelPairIntegrand_integrable (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (hh0 : ∀ i,0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (d : Fin (k+1)) (v w : ℝ →ᵇ ℝ) + (z : Fin k→ℝ) (t : ℝ≥0) : + Integrable (sourceLabelPairIntegrand n k f p e h u q g s d v w) + (((sourceBaseDataLaw n k z t).prod countableGaussianLaw).prod (countableGaussianLaw.prod countableGaussianLaw)) := + labelKernelRestoredRatio_integrable _ _ _ _ _ _ _ _ + (sourceCouplingHamiltonian_measurable n k f p e h u) (labelDepthTest_measurable k d) + (by norm_num) (labelDepthTest_bound k d) _ (sourceFresh_exp_ae n k f p e h hh0 hh u z t) + +lemma sourceLabelPairIntegrand_value (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (hh0 : ∀ i,0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (d : Fin (k+1)) (v w : ℝ →ᵇ ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0 F ((sourceLabelPairReassoc n k).symm a)) + simp only [MeasurableEquiv.symm_apply_apply] at he + change Integrable (fun a => F ((sourceLabelPairReassoc n k).symm a)) (K.prod (R.prod (B.prod ((G.prod G).prod G)))) at hi' + change (∫ a, F a ∂_) = _ + rw [he,integral_prod _ hi'] + have ha := hi'.prod_right_ae + have hval : ∀ᵐ M ∂K, (∫ a, F ((sourceLabelPairReassoc n k).symm (M,a)) ∂(R.prod (B.prod ((G.prod G).prod G)))) = + (twoVisitMass k z d).toReal*(labelPairCoefficient k z q g s v d*labelPairCoefficient k z q g s w d) := by + filter_upwards [ha] with M hM + rw [integral_prod _ hM] + have hir (a : ℕ→Fin (n+1)→ℝ) : + (∫ b, F ((sourceLabelPairReassoc n k).symm (M,(a,b))) ∂(B.prod ((G.prod G).prod G))) = + (twoVisitMass k z d).toReal*(labelPairCoefficient k z q g s v d*labelPairCoefficient k z q g s w d) := by + refine (integral_congr_ae (ae_of_all _ fun b => ?_)).trans + (sourceLabelPairRatio_value n M k f (patternPrefix (n+1) M a) p e h hh0 hh u z hz hz0 hz1 q g s d v w) + change sourceLabelPairIntegrand n k f p e h u q g s d v w (((M,(a,b.1)),b.2.2),b.2.1)=_ + simp only [sourceLabelPairIntegrand,labelKernelRestoredRatio,labelKernelNumerator,labelKernelDenominator, + sourceFullSpinLeafKernel,Kernel.comap_apply,sourceSpinLeafKernel_apply,sourceCouplingHamiltonian, + sourceLabelPairRatio] + rfl + simp_rw [hir] + simp only [integral_const,probReal_univ,smul_eq_mul,one_mul] + rw [integral_congr_ae hval] + simp only [integral_const,probReal_univ,smul_eq_mul,one_mul] + + +lemma labelKernelRestoredRatio_depth {A S : Type} [MeasurableSpace A] [MeasurableSpace S] + (k : ℕ) (κ : Kernel A (S×IndexedLeaf k)) [IsMarkovKernel κ] + (H : A → S×IndexedLeaf k → ℝ) (hH : Measurable (Function.uncurry H)) + (q : Fin (k+1)→ℝ) (s : ℝ≥0) (f v w : ℝ →ᵇ ℝ) (c : Fin (k+1)→ℝ) + (a : A×((ℕ→ℝ)×(ℕ→ℝ))) (hi : Integrable (fun x => Real.exp (H a.1 x)) (κ a.1)) : + labelKernelRestoredRatio κ H q s f (fun _ : Fin 2 => v) (fun _ => w) + (fun x => c (indexedCommonDepth k (x 0).2 (x 1).2)) a = + ∑ d, c d * labelKernelRestoredRatio κ H q s f (fun _ : Fin 2 => v) (fun _ => w) + (labelDepthTest k d) a := by + let T (d : Fin (k+1)) : (Fin 2→S×IndexedLeaf k)→ℝ := labelRestorationTest q s f (fun _ : Fin 2 => v) (fun _ => w) (labelDepthTest k d) a.2 + have hT d : Measurable (T d) := labelRestorationTest_measurable q s f _ _ (labelDepthTest_measurable k d) a.2 + let D := (∏ _ : Fin 2, ‖gaussianAverageBCF s (expBCF 1 f*v)‖)*(∏ _ : Fin 2, ‖gaussianAverageBCF s (expBCF 1 f*w)‖) + have hb d x : |T d x|≤D := by + simpa only [one_mul] using labelRestorationTest_bound q s f (fun _ : Fin 2 => v) (fun _ => w) + (by norm_num : (0:ℝ)≤1) (labelDepthTest_bound k d) a.2 x + have he (x : Fin 2→S×IndexedLeaf k) : + labelRestorationTest q s f (fun _ : Fin 2 => v) (fun _ => w) + (fun x => c (indexedCommonDepth k (x 0).2 (x 1).2)) a.2 x = ∑ d, c d*T d x := by + simp only [T,labelRestorationTest,labelDepthTest] + simp only [mul_ite,ite_mul,mul_zero,zero_mul] + simp [mul_assoc] + let := tilt_law_probability_of_integrable (κ a.1) (by simpa only [one_mul] using hi : + Integrable (fun x => Real.exp (1*H a.1 x)) (κ a.1)) + have hiT d : Integrable (T d) (Measure.pi fun _ : Fin 2 => tiltLaw (κ a.1) (H a.1) 1) := + Integrable.of_bound (hT d).aestronglyMeasurable D (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hb d x) + simp only [labelKernelRestoredRatio,labelKernelNumerator,gibbsReplicaMean_integral_of_integrable _ hH.of_uncurry_left hi] + simp_rw [he] + rw [integral_finsetSum _ (fun d _ => (hiT d).const_mul (c d)),Finset.sum_div] + simp only [integral_const_mul] + apply Finset.sum_congr rfl + intro d _ + dsimp only [T] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelSingleRestoredValue.lean b/lean/OAI/Probability/Perceptron/Variational/LabelSingleRestoredValue.lean new file mode 100644 index 0000000000000000000000000000000000000000..ae72e02580dbaeb78740194762fab8f2cc6dd3d9 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelSingleRestoredValue.lean @@ -0,0 +1,186 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelRestorationSingle + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped NNReal ENNReal BigOperators BoundedContinuousFunction Topology + +def sourceLabelSingleIntegrand (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (v w : ℝ →ᵇ ℝ) := + labelKernelRestoredRatio (sourceFullSpinLeafKernel n k) + (sourceCouplingHamiltonian n k f p e h u) q s g.f (fun _ : Fin 1 => v) (fun _ => w) (fun _ => 1) + +lemma sourceLabelSingleIntegrand_integrable (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (hh0 : ∀ i,0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (v w : ℝ →ᵇ ℝ) + (z : Fin k→ℝ) (t : ℝ≥0) : + Integrable (sourceLabelSingleIntegrand n k f p e h u q g s v w) + (((sourceBaseDataLaw n k z t).prod countableGaussianLaw).prod (countableGaussianLaw.prod countableGaussianLaw)) := + labelKernelRestoredRatio_integrable _ _ _ _ _ _ _ _ + (sourceCouplingHamiltonian_measurable n k f p e h u) measurable_const + (show (0:ℝ)≤1 by norm_num) (fun _ => by norm_num) _ (sourceFresh_exp_ae n k f p e h hh0 hh u z t) + +lemma sourceLabelSingleIntegrand_value (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (hh0 : ∀ i,0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (q : Fin (k+1)→ℝ) (g : Jet3) (s : ℝ≥0) (v w : ℝ →ᵇ ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0 F ((sourceLabelPairReassoc n k).symm a)) + simp only [MeasurableEquiv.symm_apply_apply] at he + change Integrable (fun a => F ((sourceLabelPairReassoc n k).symm a)) (K.prod (R.prod (B.prod ((G.prod G).prod G)))) at hi' + change (∫ a, F a ∂_) = _ + rw [he,integral_prod _ hi'] + have ha := hi'.prod_right_ae + have hval : ∀ᵐ M ∂K, (∫ a, F ((sourceLabelPairReassoc n k).symm (M,a)) ∂(R.prod (B.prod ((G.prod G).prod G)))) = + labelSingleCoefficient k z q g s v*labelSingleCoefficient k z q g s w := by + filter_upwards [ha] with M hM + rw [integral_prod _ hM] + have hir (a : ℕ→Fin (n+1)→ℝ) : + (∫ b, F ((sourceLabelPairReassoc n k).symm (M,(a,b))) ∂(B.prod ((G.prod G).prod G))) = + labelSingleCoefficient k z q g s v*labelSingleCoefficient k z q g s w := by + refine (integral_congr_ae (ae_of_all _ fun b => ?_)).trans + (sourceLabelSingleRatio_value n M k f (patternPrefix (n+1) M a) p e h hh0 hh u z hz hz0 hz1 q g s v w) + change sourceLabelSingleIntegrand n k f p e h u q g s v w (((M,(a,b.1)),b.2.2),b.2.1)=_ + simp only [sourceLabelSingleIntegrand,labelKernelRestoredRatio,labelKernelNumerator,labelKernelDenominator, + sourceFullSpinLeafKernel,Kernel.comap_apply,sourceSpinLeafKernel_apply,sourceCouplingHamiltonian, + sourceLabelSingleRatio] + simp_rw [hir] + simp only [integral_const,probReal_univ,smul_eq_mul,one_mul] + rw [integral_congr_ae hval] + simp only [integral_const,probReal_univ,smul_eq_mul,one_mul] + +def singleRestorationBound (f v w : ℝ →ᵇ ℝ) : ℝ := + ‖expBCF 1 f*v‖*‖expBCF 1 f*w‖ + +lemma singleRestorationBound_nonneg (f v w : ℝ →ᵇ ℝ) : 0≤ singleRestorationBound f v w := by + unfold singleRestorationBound; positivity + +lemma sourceLabelRestorationNumerator_single_bound (n k : ℕ) (f ψ v w : ℝ →ᵇ ℝ) + (q : Fin (k+1)→Time) (s : ℝ≥0) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (a) : + |sourceLabelRestorationNumerator n k 1 (fun i => (q i:ℝ)) s f ψ + (fun _ => v) (fun _ => w) 1 p e h u a|≤ singleRestorationBound ψ v w := by + let : Nonempty (CompactBlock CompactJointOverlap 1) := + ⟨fun _ _ => (⟨0,by norm_num,by norm_num⟩,⟨0,by norm_num,by norm_num⟩)⟩ + simpa [singleRestorationBound] using sourceLabelRestorationNumerator_bound n k 1 + (fun i => (q i:ℝ)) s f ψ (fun _ => v) (fun _ => w) 1 p e h u a + +lemma sourceLabelRestorationRatio_single_value (n k : ℕ) (f : ℝ →ᵇ ℝ) (g : Jet3) + (p e : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (hh0 : ∀ i,0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (q : Fin (k+1)→Time) (s : ℝ≥0) (v w : ℝ →ᵇ ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0 (q i:ℝ)) s f g.f (fun _ => v) (fun _ => w) + 1 p e h u z t = + labelSingleCoefficient k z (fun i => (q i:ℝ)) g s v * + labelSingleCoefficient k z (fun i => (q i:ℝ)) g s w := by + rw [sourceLabelRestorationRatio_eq _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ hh0 hh] + exact sourceLabelSingleIntegrand_value n k f p e h hh0 hh u _ g s v w z hz hz0 hz1 t + +lemma sourceLabelSingle_witness (k : ℕ) (q : Fin (k+1)→Time) (hq : Monotone q) + (f : ℝ →ᵇ ℝ) (g : Jet3) (v w : ℝ →ᵇ ℝ) + (p e : (n : ℕ)→Fin (n+1)→ℕ) (h : ℕ→Fin (k+1)→ℝ) + (hh0 : ∀ n i,0≤h n i) (hh : ∀ n,Monotone (h n)) (u : (n : ℕ)→Fin (n+1)→ℝ) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0 sourceGibbsArrayLaw (s n) k f (p (s n)) (e (s n)) (h (s n)) + (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∃ η : ProbabilityMeasure (WeightedRestorationRange g.f (singleRestorationBound g.f v w)), + (∀ j, (∫ x, x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v w))))= + ∫ Q, labelRestorationBlockMoment (fun i => (q i:ℝ)) g.f (fun _ : Fin 1 => v) (fun _ => w) + 1 j (compactBlock (1+j) Q) ∂ν) ∧ + (∫ x, x.1.val*restorationReciprocal g.f 1 x.2 ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v w))))= + labelSingleCoefficient k z (fun i => (q i:ℝ)) g (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) v * + labelSingleCoefficient k z (fun i => (q i:ℝ)) g (⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ : ℝ≥0) w := by + let τ : ℝ≥0 := ⟨1-q (Fin.last k),sub_nonneg.mpr (q (Fin.last k)).prop.2⟩ + apply compactWeighted_witness + (fun n => ((sourceBaseDataLaw (s n) k z (t (s n))).prod countableGaussianLaw).prod (countableGaussianLaw.prod countableGaussianLaw)) + g.f (singleRestorationBound g.f v w) + (fun n => sourceLabelRestorationNumerator (s n) k 1 (fun i => (q i:ℝ)) τ f g.f (fun _ => v) (fun _ => w) + 1 (p (s n)) (e (s n)) (h (s n)) (u (s n))) + (fun n => sourceLabelRestorationDenominator (s n) k (fun i => (q i:ℝ)) τ f g.f + (p (s n)) (e (s n)) (h (s n)) (u (s n))) + (fun n => sourceLabelRestorationNumerator_measurable ..) + (fun n => sourceLabelRestorationDenominator_measurable ..) + (fun n a => sourceLabelRestorationNumerator_single_bound ..) _ ?_ (restorationReciprocal g.f 1) _ ?_ + · intro j + simp_rw [sourceLabelRestorationPolynomial _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ (hh0 _) (hh _) j] + exact sourceLabelRestorationMoment_tendsto k 1 (fun i => (q i:ℝ)) (q 0).prop.1 + (fun i l hil => hq hil) (q (Fin.last k)).prop.2 f g.f (fun _ => v) (fun _ => w) + 1 p e h hh0 hh u z t s hlim j + · change Tendsto (fun n => sourceLabelRestorationRatio (s n) k 1 (fun i => (q i:ℝ)) τ f g.f + (fun _ => v) (fun _ => w) 1 (p (s n)) (e (s n)) (h (s n)) (u (s n)) z (t (s n))) atTop _ + simp_rw [sourceLabelRestorationRatio_single_value _ k f g _ _ _ (hh0 _) (hh _) _ q τ v w z hz hz0 hz1] + exact tendsto_const_nhds + +def scalarRestorationSingleMoment (f v w : ℝ →ᵇ ℝ) (j : ℕ) : + Matrix (Fin (1+j)) (Fin (1+j)) ℝ →ᵇ ℝ := + freshMarkedMatrixKernel (gaussianMixedTest (labelRestoredFunctions f (fun _ : Fin 1 => v) j)) * + freshMarkedMatrixKernel (gaussianMixedTest (labelRestoredFunctions f (fun _ : Fin 1 => w) j)) + +lemma restorationBlockTest_one (r j : ℕ) : + restorationBlockTest r 1 j=(1 : CompactBlock CompactOverlap (r+j) →ᵇ ℝ) := by + induction j with + | zero => rfl + | succ j hj => ext Q; change restorationBlockTest r 1 j _=1; rw [hj]; rfl + +lemma jointRestorationBlockTest_one (r j : ℕ) : + jointRestorationBlockTest r 1 j=(1 : CompactBlock CompactJointOverlap (r+j) →ᵇ ℝ) := by + induction j with + | zero => rfl + | succ j hj => ext Q; change jointRestorationBlockTest r 1 j _=1; rw [hj]; rfl + +lemma scalarRestorationSingleMoment_compact (f v w : ℝ →ᵇ ℝ) + (j : ℕ) (Q : CompactBlock CompactOverlap (1+j)) : + scalarRestorationSingleMoment f v w j (fun i l => (Q i l).val) = + (restorationBlockTest 1 1 j * + freshMarkedCompactBlockKernel (restorationMarkTest 1 f (gaussianMixedTest (fun _ => v)) j) * + freshMarkedCompactBlockKernel (restorationMarkTest 1 f (gaussianMixedTest (fun _ => w)) j)) Q := by + simp only [restorationBlockTest_one,one_mul,scalarRestorationSingleMoment, + BoundedContinuousFunction.mul_apply,restorationMarkTest_gaussianMixed] + rfl + +lemma scalarRestorationSingleMoment_label {k : ℕ} (q : Fin (k+1)→Time) + (f v w : ℝ →ᵇ ℝ) (j : ℕ) + (Q : CompactBlock CompactJointOverlap (1+j)) + (hN : ∀ i l,(Q i l).2∈Set.range (sourceLabelLevel k)) : + scalarRestorationSingleMoment f v w j (labelProfileGram q Q) = + labelRestorationBlockMoment (fun i => (q i:ℝ)) f (fun _ : Fin 1 => v) (fun _ => w) + 1 j Q := by + simp only [scalarRestorationSingleMoment,labelRestorationBlockMoment,BoundedContinuousFunction.mul_apply, + jointRestorationBlockTest_one,one_mul, + labelMarkedBlockKernel_profile q _ Q hN] + +lemma scalarRestorationSingleMoment_diagonalMap {k : ℕ} (q : Fin (k+1)→Time) + (f v w : ℝ →ᵇ ℝ) (j : ℕ) + (Q : CompactArray CompactJointOverlap) (hN : CompactLabelNodes k Q) : + scalarRestorationSingleMoment f v w j (fun i l => + (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal Q i l).1.val) = + labelRestorationBlockMoment (fun i => (q i:ℝ)) f (fun _ : Fin 1 => v) (fun _ => w) + 1 j (compactBlock (1+j) Q) := by + have he : (fun i l : Fin (1+j) => (compactDiagonalMapArray (labelProfileMap q) labelProfileDiagonal Q i l).1.val)= + labelProfileGram q (compactBlock (1+j) Q) := by + funext i l + simp only [compactDiagonalMapArray,labelProfileGram,Fin.val_inj] + split_ifs <;> rfl + rw [he] + exact scalarRestorationSingleMoment_label q f v w j _ (fun i l => hN i l) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelThermalLaw.lean b/lean/OAI/Probability/Perceptron/Variational/LabelThermalLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a79c025a554e96ecfba81c2ab9a5ea745f5e134 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelThermalLaw.lean @@ -0,0 +1,122 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshThermalLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +variable {A S E : Type*} [MeasurableSpace A] [MeasurableSpace S] [MeasurableSpace E] +variable (κ : Kernel A S) [IsMarkovKernel κ] +variable (P : Measure A) [IsProbabilityMeasure P] (G : Measure E) [IsProbabilityMeasure G] +variable (H : A→S→ℝ) (hH : Measurable (Function.uncurry H)) +variable (F : E→S→ℝ) (hF : Measurable (Function.uncurry F)) +variable (f : ℝ →ᵇ ℝ) (hFb : ∀ g x, |F g x|≤‖f‖) + +def boundedThermalPartition (a : A×E) : ℝ := + tiltMean (κ a.1) (H a.1) (fun x => Real.exp (F a.2 x)) 1 + +include hH hF in +lemma boundedThermalPartition_measurable : Measurable (boundedThermalPartition κ H F) := by + let κ' : Kernel (A×E) S := κ.comap Prod.fst measurable_fst + exact kernel_tiltMean_measurable κ' + (hH.comp (measurable_fst.fst.prodMk measurable_snd)) + ((hF.comp (measurable_fst.snd.prodMk measurable_snd)).exp) + +include hH hF hFb in +lemma boundedThermalPartition_mem {a : A} + (he : Integrable (fun x => Real.exp (H a x)) (κ a)) (g : E) : + boundedThermalPartition κ H F (a,g)∈FreshPartitionRange f := by + have he1 : Integrable (fun x => Real.exp (1*H a x)) (κ a) := by simpa only [one_mul] using he + let := tilt_law_probability_of_integrable (κ a) he1 + let μ := tiltLaw (κ a) (H a) 1 + have hi : Integrable (fun x => Real.exp (F g x)) μ := by + apply Integrable.of_bound hF.of_uncurry_left.exp.aestronglyMeasurable (Real.exp ‖f‖) + exact ae_of_all _ fun x => by + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (abs_le.mp (hFb g x)).2 + unfold boundedThermalPartition + rw [← tilt_law_integral_of_integrable (κ a) hH.of_uncurry_left he1] + constructor + · simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono (integrable_const (Real.exp (-‖f‖))) hi + (fun x => Real.exp_le_exp.mpr (abs_le.mp (hFb g x)).1) + · simpa only [integral_const,probReal_univ,smul_eq_mul,one_mul] using + integral_mono hi (integrable_const (Real.exp ‖f‖)) + (fun x => Real.exp_le_exp.mpr (abs_le.mp (hFb g x)).2) + +def boundedThermalLaw : ProbabilityMeasure (FreshPartitionRange f) := + ⟨(P.prod G).map (fun a => freshPartitionClip f (boundedThermalPartition κ H F a)), + (Measure.isProbabilityMeasure_map_iff ((freshPartitionClip_measurable f).comp + (boundedThermalPartition_measurable κ H hH F hF)).aemeasurable).2 inferInstance⟩ + +include hFb in +lemma boundedThermalLaw_integral + (he : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) + (J : ℝ→ℝ) (hJ : Measurable J) : + (∫ x, J x.val ∂(boundedThermalLaw κ P G H hH F hF f : Measure (FreshPartitionRange f)))= + ∫ a, J (boundedThermalPartition κ H F a) ∂P.prod G := by + change (∫ x : FreshPartitionRange f, J x.val ∂(P.prod G).map + (fun a => freshPartitionClip f (boundedThermalPartition κ H F a)))=_ + have hm := integral_map (μ := P.prod G) (f := fun x : FreshPartitionRange f => J x.val) + (φ := fun a => freshPartitionClip f (boundedThermalPartition κ H F a)) + (((freshPartitionClip_measurable f).comp + (boundedThermalPartition_measurable κ H hH F hF)).aemeasurable) + ((hJ.comp measurable_subtype_coe).aestronglyMeasurable) + refine hm.trans ?_ + apply integral_congr_ae + filter_upwards [measurePreserving_fst.quasiMeasurePreserving.ae he] with a ha + rw [freshPartitionClip_eq f (boundedThermalPartition_mem κ H hH F hF f hFb ha a.2)] + +include hH hF hFb in +lemma boundedThermalPartition_power_integrable (r : ℕ) : + Integrable (fun a => boundedThermalPartition κ H F a^r) (P.prod G) := by + apply Integrable.of_bound ((boundedThermalPartition_measurable κ H hH F hF).pow_const r).aestronglyMeasurable + ((Real.exp ‖f‖)^r) + apply ae_of_all + intro a + rw [norm_pow,Real.norm_eq_abs] + apply pow_le_pow_left₀ (abs_nonneg _) + apply tiltMean_bound_general (κ a.1) hH.of_uncurry_left hF.of_uncurry_left.exp (Real.exp_pos _).le + intro x + rw [abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (abs_le.mp (hFb a.2 x)).2 + +include hFb in +lemma boundedThermalLaw_moment + (he : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) (r : ℕ) : + (∫ x, x.val^r ∂(boundedThermalLaw κ P G H hH F hF f : Measure (FreshPartitionRange f)))= + ∫ a, ∫ g, (tiltMean (κ a) (H a) (fun x => Real.exp (F g x)) 1)^r ∂G ∂P := by + rw [boundedThermalLaw_integral κ P G H hH F hF f hFb he (fun x => x^r) (by fun_prop), + integral_prod _ (boundedThermalPartition_power_integrable κ P G H hH F hF f hFb r)] + rfl + +include hH hF hFb in +lemma boundedThermalPartition_log_bound (a : A×E) : + |Real.log (boundedThermalPartition κ H F a)|≤‖f‖ := + log_tiltMean_exp_bound_general (κ a.1) hH.of_uncurry_left hF.of_uncurry_left (norm_nonneg _) + (hFb a.2) + +include hH hF hFb in +lemma boundedThermalPartition_log_integrable : + Integrable (fun a => Real.log (boundedThermalPartition κ H F a)) (P.prod G) := by + apply Integrable.of_bound + ((boundedThermalPartition_measurable κ H hH F hF).log).aestronglyMeasurable ‖f‖ + exact ae_of_all _ fun a => by + simpa only [Real.norm_eq_abs] using boundedThermalPartition_log_bound κ H hH F hF f hFb a + +include hFb in +lemma boundedThermalLaw_log + (he : ∀ᵐ a ∂P, Integrable (fun x => Real.exp (H a x)) (κ a)) : + (∫ x, Real.log x.val ∂(boundedThermalLaw κ P G H hH F hF f : Measure (FreshPartitionRange f)))= + ∫ a, ∫ g, Real.log (tiltMean (κ a) (H a) (fun x => Real.exp (F g x)) 1) ∂G ∂P := by + rw [boundedThermalLaw_integral κ P G H hH F hF f hFb he _ Real.measurable_log, + integral_prod _ (boundedThermalPartition_log_integrable κ P G H hH F hF f hFb)] + rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LabelValue.lean b/lean/OAI/Probability/Perceptron/Variational/LabelValue.lean new file mode 100644 index 0000000000000000000000000000000000000000..576e71d19a8e0b5cae5a09cd9002412d803ce214 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LabelValue.lean @@ -0,0 +1,190 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LeafGibbsMarginal +import OAI.Probability.Perceptron.Variational.LabelReferenceValue +import OAI.Probability.Perceptron.Cavity.LabelFreshLog + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev SourceLabelData (n k : ℕ) := + ℕ × ((ℕ→Fin (n+1)→ℝ) × (IndexedCascadeBase k × ((ℕ→ℝ)×(ℕ→ℝ)))) + +def sourceLabelReassoc (n k : ℕ) : + ((SourceBaseData n k × (ℕ→ℝ)) × (ℕ→ℝ)) ≃ᵐ SourceLabelData n k := + (MeasurableEquiv.prodAssoc).trans + (((MeasurableEquiv.refl _).prodCongr (MeasurableEquiv.prodComm)).trans + ((MeasurableEquiv.prodAssoc).trans + ((MeasurableEquiv.refl _).prodCongr (MeasurableEquiv.prodAssoc)))) + +lemma sourceLabelReassoc_preserving (n k : ℕ) (z : Fin k→ℝ) (t : ℝ≥0) : + MeasurePreserving (sourceLabelReassoc n k) + (((sourceBaseDataLaw n k z t).prod countableGaussianLaw).prod countableGaussianLaw) + ((poissonMeasure ((n+1:ℕ)*t)).prod ((infinitePatternRowsLaw (n+1)).prod + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + (countableGaussianLaw.prod countableGaussianLaw)))) := by + let K := poissonMeasure ((n+1:ℕ)*t) + let R := infinitePatternRowsLaw (n+1) + let B := (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) + let G := countableGaussianLaw + exact ((MeasurePreserving.id K).prod (measurePreserving_prodAssoc R B (G.prod G))).comp + ((measurePreserving_prodAssoc K (R.prod B) (G.prod G)).comp + (((MeasurePreserving.id (K.prod (R.prod B))).prod (Measure.measurePreserving_swap (μ := G) (ν := G))).comp + (measurePreserving_prodAssoc (K.prod (R.prod B)) G G))) + +def sourceLabelLogIntegrand (n k : ℕ) (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) + (u : Fin (n+1)→ℝ) (a : (SourceBaseData n k × (ℕ→ℝ)) × (ℕ→ℝ)) : ℝ := + Real.log (boundedThermalPartition (sourceFullSpinLeafKernel n k) + (sourceCouplingHamiltonian n k f p d h u) (labelLogResponse q hq1 ψ) a) + +lemma sourceLabelLogIntegrand_measurable (n k : ℕ) (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) : + Measurable (sourceLabelLogIntegrand n k q hq1 f ψ p d h u) := + (boundedThermalPartition_measurable _ _ (sourceCouplingHamiltonian_measurable n k f p d h u) + _ (labelLogResponse_measurable q hq1 ψ)).log + +lemma sourceLabelLogIntegrand_bound (n k : ℕ) (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (a : (SourceBaseData n k × (ℕ→ℝ)) × (ℕ→ℝ)) : + |sourceLabelLogIntegrand n k q hq1 f ψ p d h u a|≤‖ψ‖ := + boundedThermalPartition_log_bound _ _ (sourceCouplingHamiltonian_measurable n k f p d h u) + _ (labelLogResponse_measurable q hq1 ψ) ψ (labelLogResponse_bound q hq1 ψ) a + +lemma sourceLabelLogIntegrand_integrable {D : Type*} [MeasurableSpace D] + (n k : ℕ) (q : Fin (k+1)→ℝ) (hq1 : q (Fin.last k)≤1) + (f ψ : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) + (μ : Measure D) [IsFiniteMeasure μ] + (e : D→(SourceBaseData n k × (ℕ→ℝ)) × (ℕ→ℝ)) (he : Measurable e) : + Integrable (fun a => sourceLabelLogIntegrand n k q hq1 f ψ p d h u (e a)) μ := by + apply Integrable.of_bound + ((sourceLabelLogIntegrand_measurable n k q hq1 f ψ p d h u).comp he).aestronglyMeasurable ‖ψ‖ + exact ae_of_all _ fun a => by + change |sourceLabelLogIntegrand n k q hq1 f ψ p d h u (e a)|≤‖ψ‖ + exact sourceLabelLogIntegrand_bound n k q hq1 f ψ p d h u (e a) + +lemma enrichedIndexedHamiltonian_exp_ae (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (b : IndexedCascadeBase k) : + ∀ᵐ g ∂countableGaussianLaw, Integrable + (fun x => Real.exp (enrichedIndexedHamiltonian n M k f a p d h u g x)) + (enrichedIndexedBaseMeasure n k b) := by + have he := countableGaussian_coupling_exp_ae (enrichedIndexedBaseMeasure n k b) + (enrichedIndexedBoundedEnergy_measurable n M k f a h) + (sourceGaussianRow_measurable p d h u) (sourceGaussianRow_measurable p d h u) + (indexedGaussianRowLength_measurable k) + (enrichedIndexedBoundedEnergy_bound n M k f a h) + (sourceGaussianRow_square_bound p d h u hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l))) + (sourceGaussianRow_square_bound p d h u hh0 hh (hh0 (Fin.last k)) (fun l => hh (Fin.le_last l))) 0 + simpa only [zero_mul,add_zero,enrichedIndexedHamiltonian] using he + +def labelProfileValue (k : ℕ) (z : Fin k→ℝ) (q : Fin (k+1)→ℝ) + (hq1 : q (Fin.last k)≤1) (g : Jet3) : ℝ := + ∫ x, gaussianLinearBackward (stdGaussian (EuclideanSpace ℝ (Fin 1))) + (linearCascadeWord (fun j => diagonalMark (profileGaussianStep (fun l (_ : Fin 1) => q l) j)) k z) + (labelProfileTerminal g ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩) + (diagonalMark (profileGaussianRoot (fun l (_ : Fin 1) => q l)) x) + ∂stdGaussian (EuclideanSpace ℝ (Fin 1)) + +lemma sourceLabelLogIntegrand_fixed_value (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : ℕ→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 ((M,(a,t.1)),t.2.2) + have he : Measurable e := by unfold e; fun_prop + let κ := (sourceFullSpinLeafKernel n k).comap e he + let H := fun t x => sourceCouplingHamiltonian n k f p d h u (e t) x + have hH : Measurable (Function.uncurry H) := + (sourceCouplingHamiltonian_measurable n k f p d h u).comp + ((he.comp measurable_fst).prodMk measurable_snd) + have hm : MeasurableSet {t | Integrable (fun x => Real.exp (H t x)) (κ t)} := + measurableSet_kernel_integrable (κ := κ) (f := fun t x => Real.exp (H t x)) + hH.exp.stronglyMeasurable + have hi : ∀ᵐ t ∂(indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + (countableGaussianLaw.prod countableGaussianLaw), + Integrable (fun x => Real.exp (H t x)) (κ t) := by + apply (Measure.ae_prod_iff_ae_ae hm).mpr + refine ae_of_all _ fun b => ?_ + have ht := (measurePreserving_snd (μ := countableGaussianLaw) (ν := countableGaussianLaw)).quasiMeasurePreserving.ae + (enrichedIndexedHamiltonian_exp_ae n M k f (patternPrefix (n+1) M a) p d h hh0 hh u b) + simpa only [κ,Kernel.comap_apply,H,e,sourceFullSpinLeafKernel,sourceSpinLeafKernel_apply, + sourceCouplingHamiltonian] using ht + refine (integral_congr_ae ?_).trans + (source_countable_label_reference_value n M k f (patternPrefix (n+1) M a) p d h u + z hz hz0 hz1 q hq1 g) + filter_upwards [hi] with t ht + have ht' : Integrable + (fun x => Real.exp (enrichedIndexedHamiltonian n M k f (patternPrefix (n+1) M a) p d h u t.2.2 x)) + (enrichedIndexedBaseMeasure n k t.1) := by + simpa only [κ,Kernel.comap_apply,H,e,sourceFullSpinLeafKernel,sourceSpinLeafKernel_apply, + sourceCouplingHamiltonian] using ht + unfold sourceLabelLogIntegrand boundedThermalPartition + simp only [labelLogResponse_exp,sourceFullSpinLeafKernel,Kernel.comap_apply, + sourceSpinLeafKernel_apply,sourceCouplingHamiltonian] + congr 1 + exact enrichedIndexedHamiltonian_leaf_observable n M k f (patternPrefix (n+1) M a) p d h u + t.2.2 t.1 ht' (fun l => gaussianAverageBCF + ⟨1-q (Fin.last k),sub_nonneg.mpr hq1⟩ (expBCF 1 g.f) (labelProfileField q t.2.1 ((),l))) + (fun l => (gaussianAverageBCF _ (expBCF 1 g.f)).norm_coe_le_norm _) + +theorem sourceLabelFreshLog_value (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (h : Fin (k+1)→ℝ) (hh0 : ∀ i, 0≤h i) (hh : Monotone h) + (u : Fin (n+1)→ℝ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 F ((sourceLabelReassoc n k).symm a)) + simp only [MeasurableEquiv.symm_apply_apply] at hp + rw [hp] + have hi' := sourceLabelLogIntegrand_integrable n k q hq1 f g.f p d h u + (K.prod (R.prod (B.prod (G.prod G)))) (sourceLabelReassoc n k).symm + (sourceLabelReassoc n k).symm.measurable + change Integrable (fun a => F ((sourceLabelReassoc n k).symm a)) + (K.prod (R.prod (B.prod (G.prod G)))) at hi' + rw [integral_prod _ hi'] + have hv (M : ℕ) : (∫ a, F ((sourceLabelReassoc n k).symm (M,a)) + ∂(R.prod (B.prod (G.prod G))))=labelProfileValue k z q hq1 g := by + have hiM := sourceLabelLogIntegrand_integrable n k q hq1 f g.f p d h u + (R.prod (B.prod (G.prod G))) (fun a => (sourceLabelReassoc n k).symm (M,a)) + ((sourceLabelReassoc n k).symm.measurable.comp (measurable_const.prodMk measurable_id)) + change Integrable (fun a => F ((sourceLabelReassoc n k).symm (M,a))) + (R.prod (B.prod (G.prod G))) at hiM + rw [integral_prod _ hiM] + have hval (a : ℕ→Fin (n+1)→ℝ) : + (∫ b, F ((sourceLabelReassoc n k).symm (M,(a,b))) ∂(B.prod (G.prod G)))= + labelProfileValue k z q hq1 g := + sourceLabelLogIntegrand_fixed_value n M k f a p d h hh0 hh u z hz hz0 hz1 q hq1 g + simp_rw [hval] + simp only [integral_const,probReal_univ,smul_eq_mul,one_mul] + simp_rw [hv] + simp only [integral_const,probReal_univ,smul_eq_mul,one_mul] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LeafGibbsMarginal.lean b/lean/OAI/Probability/Perceptron/Variational/LeafGibbsMarginal.lean new file mode 100644 index 0000000000000000000000000000000000000000..949f1bd4bfe396c93c8b30039cc966e9bd3b7599 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LeafGibbsMarginal.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.GaussianCoupling + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped BigOperators ENNReal BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma tiltMean_prod_snd_of_partition {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + (μ : Measure S) (ν : Measure T) [SFinite μ] [SFinite ν] + (H : S×T→ℝ) (G F : T→ℝ) (hF : Measurable F) {B : ℝ} (hB : ∀ t, |F t|≤B) + (he : Integrable (fun x => Real.exp (H x)) (μ.prod ν)) + (hp : ∀ t, (∫ s, Real.exp (H (s,t)) ∂μ)=Real.exp (G t)) : + tiltMean (μ.prod ν) H (fun x => F x.2) 1=tiltMean ν G F 1 := by + have hi : Integrable (fun x : S×T => F x.2*Real.exp (H x)) (μ.prod ν) := + he.bdd_mul (hF.comp measurable_snd).aestronglyMeasurable + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hB x.2) + have hi' : Integrable (fun x : S×T => Real.exp (H x)*F x.2) (μ.prod ν) := by + simpa only [mul_comm] using hi + unfold tiltMean tiltIntegral tiltPartition + simp only [one_mul] + rw [integral_prod_symm _ hi',integral_prod_symm _ he] + simp_rw [integral_mul_const,hp] + +lemma enrichedIndexedHamiltonian_leaf_partition (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (g : ℕ→ℝ) (l : IndexedLeaf k) : + (∫ x, Real.exp (enrichedIndexedHamiltonian n M k f a p d h u g (x,l)) ∂unitSphereLaw (n+1))= + Real.exp (enrichedTerminal n M f a p u (h (Fin.last k)) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).1), + (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).2) l 0)) := by + let root := profileGaussianRoot (enrichedCoordinateLevel p d h) + let step := profileGaussianStep (enrichedCoordinateLevel p d h) + have hA : enrichedIncrementMap p d h = fun j => diagonalMark (step j) := + funext (enrichedIncrementMap_profile p d h) + have hR : enrichedRootMap p d h = diagonalMark root := rfl + rw [hA,hR] + let v := indexedLeafState (gaussianLinearMarkStep (fun j => diagonalMark (step j))) k + ((fun _ => diagonalMark root (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).1), + (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).2) l 0 + have he (x : NormalizedSpin (n+1)) : + enrichedIndexedHamiltonian n M k f a p d h u g (x,l)= + normalizedPatternEnergy (n+1) M f a x+inner ℝ (sourceEnrichedFeature (n+1) p u x) v- + (n+1:ℕ)*h (Fin.last k) := by + unfold enrichedIndexedHamiltonian countableGaussianHamiltonian enrichedIndexedBoundedEnergy sourceGaussianRow + rw [indexedGaussianRow_diagonal_identity] + dsimp only [v,root,step] + ring + simp_rw [he] + exact vectorPartition_exp_terminal (unitSphereLaw (n+1)) + ((normalizedPatternEnergy_continuous (n+1) M f).comp (continuous_const.prodMk continuous_id)).measurable + (sourceEnrichedFeature_measurable (n+1) p u) (normalizedPatternEnergy_bound (n+1) M f a) + (fun x => (sourceEnrichedFeature_norm (n+1) p u x).le) _ v + +theorem enrichedIndexedHamiltonian_leaf_observable (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (a : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) + (h : Fin (k+1)→ℝ) (u : Fin (n+1)→ℝ) (g : ℕ→ℝ) (b : IndexedCascadeBase k) + (he : Integrable (fun x => Real.exp (enrichedIndexedHamiltonian n M k f a p d h u g x)) + (enrichedIndexedBaseMeasure n k b)) (F : IndexedLeaf k→ℝ) {B : ℝ} (hB : ∀ l, |F l|≤B) : + tiltMean (enrichedIndexedBaseMeasure n k b) (enrichedIndexedHamiltonian n M k f a p d h u g) + (fun x => F x.2) 1= + tiltMean (indexedLeafProbability k b) + (fun l => enrichedTerminal n M f a p u (h (Fin.last k)) + (indexedLeafState (gaussianLinearMarkStep (enrichedIncrementMap p d h)) k + ((fun _ => enrichedRootMap p d h (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).1), + (indexedGaussianDisorder k (EnrichedIndex (n+1) (n+1) p) g).2) l 0)) F 1 := by + exact tiltMean_prod_snd_of_partition _ _ _ _ F (measurable_of_countable _) hB he + (enrichedIndexedHamiltonian_leaf_partition n M k f a p d h u g) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LeafMarginalLaw.lean b/lean/OAI/Probability/Perceptron/Variational/LeafMarginalLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..e69aef77f8b255c45a1b76e52cfbb1da71968fc6 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LeafMarginalLaw.lean @@ -0,0 +1,58 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LeafGibbsMarginal + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal +namespace SphericalPerceptronFreeEnergy +variable {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + +lemma tiltLaw_prod_snd_of_partition (μ : Measure S) (ν : Measure T) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (H : S×T→ℝ) (G : T→ℝ) (hH : Measurable H) (hG : Measurable G) + (he : Integrable (fun x => Real.exp (H x)) (μ.prod ν)) + (hp : ∀ t, (∫ s, Real.exp (H (s,t)) ∂μ)=Real.exp (G t)) : + (tiltLaw (μ.prod ν) H 1).map Prod.snd=tiltLaw ν G 1 := by + have heG : Integrable (fun t => Real.exp (G t)) ν := by + have hi := he.integral_prod_right + simpa only [hp] using hi + have hhe : Integrable (fun x => Real.exp (1*H x)) (μ.prod ν) := by simpa using he + have hhG : Integrable (fun t => Real.exp (1*G t)) ν := by simpa using heG + let := tilt_law_probability_of_integrable (μ.prod ν) hhe + let := tilt_law_probability_of_integrable ν hhG + apply Measure.ext + intro s hs + apply (ENNReal.toReal_eq_toReal_iff' (measure_ne_top _ _) (measure_ne_top _ _)).mp + have hi : Measurable (s.indicator (fun _ : T => (1:ℝ))) := measurable_const.indicator hs + have hb (t : T) : |s.indicator (fun _ : T => (1:ℝ)) t|≤1 := by + by_cases ht : t∈s <;> simp [ht] + have h := tiltMean_prod_snd_of_partition μ ν H G _ hi hb he hp + rw [←tilt_law_integral_of_integrable (μ.prod ν) hH hhe, + ←tilt_law_integral_of_integrable ν hG hhG] at h + have hm := integral_map (μ:=tiltLaw (μ.prod ν) H 1) measurable_snd.aemeasurable hi.aestronglyMeasurable + rw [←hm] at h + simpa only [integral_indicator hs,integral_const,smul_eq_mul,mul_one, + measureReal_def,Measure.restrict_apply_univ] using h + +lemma tiltLaw_prod_snd_replica (μ : Measure S) (ν : Measure T) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (H : S×T→ℝ) (G : T→ℝ) (hH : Measurable H) (hG : Measurable G) + (he : Integrable (fun x => Real.exp (H x)) (μ.prod ν)) + (hp : ∀ t, (∫ s, Real.exp (H (s,t)) ∂μ)=Real.exp (G t)) (r : ℕ) : + MeasurePreserving (fun x : Fin r→S×T => fun i => (x i).2) + (Measure.pi fun _ : Fin r => tiltLaw (μ.prod ν) H 1) + (Measure.pi fun _ : Fin r => tiltLaw ν G 1) := by + have hhe : Integrable (fun x => Real.exp (1*H x)) (μ.prod ν) := by simpa using he + let := tilt_law_probability_of_integrable (μ.prod ν) hhe + have heG : Integrable (fun t => Real.exp (1*G t)) ν := by + simpa only [one_mul,hp] using he.integral_prod_right + let := tilt_law_probability_of_integrable ν heG + exact measurePreserving_pi _ _ (fun _ : Fin r => + ⟨measurable_snd,tiltLaw_prod_snd_of_partition μ ν H G hH hG he hp⟩) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LevelTrialApprox.lean b/lean/OAI/Probability/Perceptron/Variational/LevelTrialApprox.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed9cb1ac6229dbf3d567eae422fa27663a481c8a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LevelTrialApprox.lean @@ -0,0 +1,176 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.UpperContact + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def trialLevelQuantile (m : Trial) (n : ℕ) (i : Fin (n+1)) : Time := + sInf {t : Time | (i:ℝ)/(n+1:ℝ)< m t} + +lemma trialLevelQuantile_mono (m : Trial) (n : ℕ) : Monotone (trialLevelQuantile m n) := by + intro i j hij + apply le_sInf + intro t ht + apply sInf_le + exact lt_of_le_of_lt (div_le_div_of_nonneg_right + (show (i:ℝ) ≤ (j:ℝ) by exact_mod_cast hij) (by positivity : (0:ℝ)≤n+1)) ht + +lemma trialLevelQuantile_le (m : Trial) (n : ℕ) (i : Fin (n+1)) {t : Time} + (ht : (i:ℝ)/(n+1:ℝ)< m t) : trialLevelQuantile m n i≤t := sInf_le ht + +lemma trialLevelQuantile_lt (m : Trial) (n : ℕ) (i : Fin (n+1)) {t : Time} + (ht : trialLevelQuantile m n i if j<⌈(n+1:ℝ)*m t⌉₊ then 1/(n+1:ℝ) else 0) i.val)=_ + rw [Fin.sum_univ_eq_sum_range (fun j : ℕ => if j<⌈(n+1:ℝ)*m t⌉₊ then 1/(n+1:ℝ) else 0) (n+1),←Finset.sum_filter] + have hset : (Finset.range (n+1)).filter (fun i => i<⌈(n+1:ℝ)*m t⌉₊)= + Finset.range ⌈(n+1:ℝ)*m t⌉₊ := by + ext i + simp only [Finset.mem_filter,Finset.mem_range] + omega + rw [hset,Finset.sum_const,Finset.card_range,nsmul_eq_mul] + change _=(⌈((n+1:ℕ):ℝ)*m t⌉₊:ℝ)/(n+1:ℕ) + simp only [Nat.cast_add,Nat.cast_one] + ring + +def levelStepTrial (m : Trial) (n : ℕ) : Trial := + weightedStepTrial (fun _ : Fin (n+1) => 1/(n+1:ℝ)) (trialLevelQuantile m n) + (uniformQuantileWeights_nonneg n) (uniformQuantileWeights_sum n) + +lemma le_levelStepTrial (m : Trial) (n : ℕ) (t : Time) : m t≤levelStepTrial m n t := by + apply (le_upperRoundedTrial m n t).trans + rw [←uniform_threshold_sum] + apply Finset.sum_le_sum + intro i _ + by_cases hi : (i:ℝ)/(n+1:ℝ)< m t + · simp only [ite_eq_left hi,ite_eq_left (trialLevelQuantile_le m n i hi),le_refl] + · rw [ite_eq_right hi] + split_ifs <;> positivity + +lemma levelStepTrial_ae (m : Trial) (n : ℕ) : + (fun t => levelStepTrial m n t)=ᵐ[timeLaw] (fun t => upperRoundedTrial m n t) := by + have hn : ∀ᵐ t ∂timeLaw, ∀ i : Fin (n+1), t≠trialLevelQuantile m n i := by + apply ae_all_iff.mpr + intro i + simp [ae_iff,timeLaw_eq_volume] + filter_upwards [hn] with t ht + rw [←uniform_threshold_sum] + change (∑ i : Fin (n+1), if trialLevelQuantile m n i≤t then 1/(n+1:ℝ) else 0)=_ + apply Finset.sum_congr rfl + intro i _ + have hi : trialLevelQuantile m n i≤t ↔ (i:ℝ)/(n+1:ℝ)< m t := + ⟨fun h => trialLevelQuantile_lt m n i (lt_of_le_of_ne h (Ne.symm (ht i))),trialLevelQuantile_le m n i⟩ + simp only [hi] + +lemma levelStepTrial_L1 (m : Trial) (n : ℕ) : + (∫ t, |levelStepTrial m n t-m t| ∂timeLaw)≤1/(n+1:ℝ) := by + have he : (∫ t, |levelStepTrial m n t-m t| ∂timeLaw)= + ∫ t, |upperRoundedTrial m n t-m t| ∂timeLaw := + integral_congr_ae ((levelStepTrial_ae m n).mono fun t ht => by dsimp only at ht ⊢; rw [ht]) + rw [he] + simpa only [Nat.cast_add,Nat.cast_one] using upperRoundedTrial_L1_le m n + +lemma trialLevelQuantile_terminal (m : Trial) (n : ℕ) {r : Time} (hr : m r=1) + (i : Fin (n+1)) : trialLevelQuantile m n i≤r := by + apply trialLevelQuantile_le + rw [hr] + apply (div_lt_one (by positivity : (0:ℝ) 1/(n+1:ℝ)) q + (uniformQuantileWeights_nonneg n) (uniformQuantileWeights_sum n) + (∀ t, m t≤v t) ∧ entropy v≤entropy m ∧ + (∫ t, |v t-m t| ∂timeLaw)<ε := by + obtain ⟨u,hufin,⟨r,hr,hterm⟩,hmu,hS,_,hL⟩ := + exists_finite_terminal_trial_approx m (show 0<ε/2 by positivity) + obtain ⟨n,hn⟩ := exists_nat_one_div_lt (show 0<ε/2 by positivity) + refine ⟨n,trialLevelQuantile u n,trialLevelQuantile_mono u n, + lt_of_le_of_lt (trialLevelQuantile_terminal u n (hterm r le_rfl) _) hr,?_⟩ + change (∀ t, m t≤levelStepTrial u n t) ∧ entropy (levelStepTrial u n)≤entropy m ∧ _ + refine ⟨fun t => (hmu t).trans (le_levelStepTrial u n t), + (entropy_antitone (le_levelStepTrial u n)).trans hS,?_⟩ + have hi : (∫ t, |levelStepTrial u n t-m t| ∂timeLaw) ≤ + (∫ t, |levelStepTrial u n t-u t| ∂timeLaw)+(∫ t, |u t-m t| ∂timeLaw) := by + calc + _ ≤ ∫ t, |levelStepTrial u n t-u t|+|u t-m t| ∂timeLaw := + integral_mono ((trial_integrable _).sub (trial_integrable _)).abs + (((trial_integrable _).sub (trial_integrable _)).abs.add + ((trial_integrable _).sub (trial_integrable _)).abs) (fun t => abs_sub_le _ _ _) + _ = _ := integral_add ((trial_integrable _).sub (trial_integrable _)).abs + ((trial_integrable _).sub (trial_integrable _)).abs + have hl := levelStepTrial_L1 u n + change (∫ t, |levelStepTrial u n t-m t| ∂timeLaw)<ε + linarith + + + theorem expectedPressure_upper_trial + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) + (g : Jet3) (α : ℝ≥0) (m : Trial) (hm : entropy m≠∞) {ε : ℝ} (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, expectedPressure (α:ℝ) 1 g.f (n+1) ≤ + (entropy m).toReal+(α:ℝ)*controlValue P g.f m+ε := by + let C : ℝ := (α:ℝ)*(3/2)*‖g.d1‖^2 + have hC : 0≤C := by dsimp [C]; positivity + obtain ⟨k,q,hq,hq1,_,hS,hL⟩ := exists_uniform_step_trial_approx m + (show 0<ε/(2*(C+1)) by positivity) + let v := weightedStepTrial (fun _ : Fin (k+1) => 1/(k+1:ℝ)) q + (uniformQuantileWeights_nonneg k) (uniformQuantileWeights_sum k) + have hv : ∀ᶠ n : ℕ in atTop, expectedPressure (α:ℝ) 1 g.f (n+1)≤ + (entropy v).toReal+(α:ℝ)*controlValue P g.f v+ε/2 := + expectedPressure_upper_weightedStep k P hB g _ q (fun _ => by positivity) + (uniformQuantileWeights_sum k) hq hq1 α (show 0<ε/2 by positivity) + have hS' : (entropy v).toReal≤(entropy m).toReal := ENNReal.toReal_mono hm hS + have hc := mul_le_mul_of_nonneg_left + (controlValue_trial_sub_le P g.f v m ‖g.d1‖₊ g.lipschitz) α.coe_nonneg + have he : C*(∫ t, |v t-m t| ∂timeLaw)≤ε/2 := by + calc + _ ≤ C*(ε/(2*(C+1))) := mul_le_mul_of_nonneg_left hL.le hC + _ ≤ ε/2 := by + rw [←mul_div_assoc] + apply (div_le_iff₀ (by positivity : 0<2*(C+1))).mpr + nlinarith + filter_upwards [hv] with n hn + dsimp only [C] at he + change (α:ℝ)*(controlValue P g.f v-controlValue P g.f m) ≤ + (α:ℝ)*((3/2)*‖g.d1‖^2*(∫ t, |v t-m t| ∂timeLaw)) at hc + nlinarith + + theorem expectedPressure_upper_variational + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) + (g : Jet3) (α : ℝ≥0) {ε : ℝ} (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, expectedPressure (α:ℝ) 1 g.f (n+1) ≤ + (terminalVariational P (α:ℝ) g.f).toReal+ε := by + have hi : terminalVariational P (α:ℝ) g.f < + (((terminalVariational P (α:ℝ) g.f).toReal+ε/2:ℝ):EReal) := by + rw [←terminalVariational_coe_toReal P (α:ℝ) α.coe_nonneg g.f,EReal.coe_lt_coe_iff] + simp only [EReal.toReal_coe] + linarith + obtain ⟨m,hm⟩ := iInf_lt_iff.mp hi + have hS : entropy m≠∞ := by + intro h + simp only [h,EReal.coe_ennreal_top,EReal.coe_add_top,not_top_lt] at hm + rw [←EReal.coe_ennreal_toReal hS,←EReal.coe_add,EReal.coe_lt_coe_iff] at hm + filter_upwards [expectedPressure_upper_trial P hB g α m hS (show 0<ε/2 by positivity)] with n hn + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/LocalMaxSecondDerivNonpos.lean b/lean/OAI/Probability/Perceptron/Variational/LocalMaxSecondDerivNonpos.lean new file mode 100644 index 0000000000000000000000000000000000000000..92ac97d669540362c1e81043d8321806e40e1c20 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/LocalMaxSecondDerivNonpos.lean @@ -0,0 +1,246 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.HeatLogBCF +import OAI.Probability.Perceptron.Variational.VarianceProdMemLp + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +namespace SphericalPerceptronFreeEnergy + +section + +lemma localMax_second_deriv_nonpos {f : ℝ → ℝ} {u : ℝ} + (hm : IsLocalMax f u) (hc : ContinuousAt f u) : deriv (deriv f) u ≤ 0 := by + by_contra! h + have hn := isLocalMin_of_deriv_deriv_pos h hm.deriv_eq_zero hc + have he : f =ᶠ[𝓝 u] (fun _ => f u) := by + filter_upwards [hm,hn] with x hx hy + exact le_antisymm hx hy + have hz := he.deriv.deriv_eq + simp at hz + linarith + +lemma quadratic_contact_second_deriv {A D : ℝ → ℝ} {u a c v : ℝ} + (hD : ∀ t, HasDerivAt A (D t) t) (hv : HasDerivAt D v u) + (hmin : IsLocalMin (fun t => c*(t-a)^2-A t) u) : v ≤ 2*c := by + let f := fun t => A t-c*(t-a)^2 + have hmax : IsLocalMax f u := by + simpa only [f,neg_sub] using hmin.neg + have hd (t : ℝ) : HasDerivAt f (D t-2*c*(t-a)) t := by + convert! (hD t).sub (((hasDerivAt_id t).sub_const a).pow 2 |>.const_mul c) using 1 + simp + ring + have hderiv : deriv f = fun t => D t-2*c*(t-a) := funext fun t => (hd t).deriv + have h2 : HasDerivAt (deriv f) (v-2*c) u := by + rw [hderiv] + simpa only [Pi.sub_def,id_eq,one_mul,mul_one] using hv.sub (((hasDerivAt_id u).sub_const a).const_mul (2*c)) + have hh := localMax_second_deriv_nonpos hmax (hd u).continuousAt + rw [h2.deriv] at hh + linarith + +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +def affineLogRoot (H Y : S → ℝ) (t : ℝ) : ℝ := + Real.log (tiltPartition μ (fun x => H x+t*Y x) 1) + +lemma affineLogRoot_eq {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hHA : ∀ x, |H x| ≤ A) + (hYB : ∀ x, |Y x| ≤ B) (t : ℝ) : + affineLogRoot μ H Y t = Real.log (tiltPartition (tiltLaw μ H 1) Y t) + + Real.log (tiltPartition μ H 1) := by + have := tilt_law_probability μ hH hA hHA 1 + have hp := tilt_partition_pos μ hH hA hHA 1 + have hy := tilt_partition_pos (tiltLaw μ H 1) hY hB hYB t + have he : tiltPartition (tiltLaw μ H 1) Y t * tiltPartition μ H 1 = + tiltPartition μ (fun x => H x+t*Y x) 1 := by + unfold tiltPartition + rw [tilt_law_integral μ hH hA hHA 1] + simp only [tiltMean,tiltIntegral,tiltPartition,one_mul] + rw [div_mul_cancel₀ _ (by simpa only [tiltPartition,one_mul] using hp.ne')] + simp_rw [Real.exp_add] + rw [affineLogRoot,← he,Real.log_mul hy.ne' hp.ne'] + +lemma affineLogRoot_deriv {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hHA : ∀ x, |H x| ≤ A) + (hYB : ∀ x, |Y x| ≤ B) (t : ℝ) : + HasDerivAt (affineLogRoot μ H Y) (tiltMean μ (fun x => H x+t*Y x) Y 1) t := by + have := tilt_law_probability μ hH hA hHA 1 + have hh := (tilt_log_partition_deriv (tiltLaw μ H 1) hY hB hYB t).add_const + (Real.log (tiltPartition μ H 1)) + simp_rw [tilt_mean_twice μ hH hA hHA,one_mul] at hh + exact hh.congr_of_eventuallyEq (Eventually.of_forall fun u => affineLogRoot_eq μ hH hY hA hB hHA hYB u) + +lemma affineMean_deriv {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hHA : ∀ x, |H x| ≤ A) + (hYB : ∀ x, |Y x| ≤ B) (t : ℝ) : + HasDerivAt (fun u => tiltMean μ (fun x => H x+u*Y x) Y 1) + (tiltMean μ (fun x => H x+t*Y x) (fun x => Y x*Y x) 1 - + (tiltMean μ (fun x => H x+t*Y x) Y 1)^2) t := by + have := tilt_law_probability μ hH hA hHA 1 + have hh := tilt_mean_deriv (tiltLaw μ H 1) hY hY hB hB hYB hYB t + have he : tiltMean (tiltLaw μ H 1) Y Y = (fun u => tiltMean μ (fun x => H x+u*Y x) Y 1) := by + funext u + simpa only [one_mul] using tilt_mean_twice μ (v := Y) (F := Y) hH hA hHA 1 u + rw [he] at hh + simpa only [tilt_mean_twice μ hH hA hHA,one_mul,pow_two] using hh + +lemma tilt_log_partition_bound {H : S → ℝ} (hH : Measurable H) + {A : ℝ} (hA : 0 ≤ A) (hHA : ∀ x, |H x| ≤ A) : + |Real.log (tiltPartition μ H 1)| ≤ A := by + have hp := tilt_partition_pos μ hH hA hHA 1 + have hi : Integrable (fun x => Real.exp (H x)) μ := by + simpa only [one_mul,mul_one] using tilt_integrable μ (F := fun _ => 1) hH measurable_const hA (by norm_num : (0:ℝ) ≤ 1) hHA (fun _ => by norm_num) 1 + have hlo : Real.exp (-A) ≤ tiltPartition μ H 1 := by + calc + _ = ∫ _ : S, Real.exp (-A) ∂μ := by simp + _ ≤ _ := by simpa only [tiltPartition,one_mul] using integral_mono (integrable_const _) hi (fun x => Real.exp_le_exp.mpr (abs_le.mp (hHA x)).1) + have hhi : tiltPartition μ H 1 ≤ Real.exp A := by + calc + _ ≤ ∫ _ : S, Real.exp A ∂μ := by simpa only [tiltPartition,one_mul] using integral_mono hi (integrable_const _) (fun x => Real.exp_le_exp.mpr (abs_le.mp (hHA x)).2) + _ = _ := by simp + exact abs_le.mpr ⟨by simpa using Real.log_le_log (Real.exp_pos (-A)) hlo,by simpa using Real.log_le_log hp hhi⟩ + +omit [MeasurableSpace S] in +lemma affinePotential_bound {H Y : S → ℝ} {A B : ℝ} + (hHA : ∀ x, |H x| ≤ A) (hYB : ∀ x, |Y x| ≤ B) (t : ℝ) (x : S) : + |H x+t*Y x| ≤ A+|t| * B := by + exact (abs_add_le _ _).trans (add_le_add (hHA x) (by rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hYB x) (abs_nonneg t))) + +lemma affineLogRoot_convex {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hHA : ∀ x, |H x| ≤ A) + (hYB : ∀ x, |Y x| ≤ B) : ConvexOn ℝ Set.univ (affineLogRoot μ H Y) := by + have := tilt_law_probability μ hH hA hHA 1 + have he := funext fun t => affineLogRoot_eq μ hH hY hA hB hHA hYB t + rw [he] + exact (tilt_log_partition_convex (tiltLaw μ H 1) hY hB hYB).add (convexOn_const _ (convex_univ)) + +end + +variable {S Ω : Type*} [MeasurableSpace S] [MeasurableSpace Ω] +variable (μ : Measure S) [IsProbabilityMeasure μ] (P : Measure Ω) [IsProbabilityMeasure P] + +def thermalVar (H Y : S → ℝ) (t : ℝ) : ℝ := + tiltMean μ (fun x => H x+t*Y x) (fun x => Y x*Y x) 1 - + (tiltMean μ (fun x => H x+t*Y x) Y 1)^2 + +lemma thermalVar_nonneg {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hHA : ∀ x, |H x| ≤ A) + (hYB : ∀ x, |Y x| ≤ B) (t : ℝ) : 0 ≤ thermalVar μ H Y t := by + have := tilt_law_probability μ hH hA hHA 1 + have he := tilt_variance_eq (tiltLaw μ H 1) hY hB hYB t + have he' : thermalVar μ H Y t = variance Y (tiltLaw (tiltLaw μ H 1) Y t) := by + simpa only [thermalVar,tilt_mean_twice μ hH hA hHA,one_mul,pow_two] using he + rw [he'] + exact variance_nonneg Y _ + +lemma thermalVar_bound {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + {A B : ℝ} (hA : 0 ≤ A) (hB : 0 ≤ B) (hHA : ∀ x, |H x| ≤ A) + (hYB : ∀ x, |Y x| ≤ B) (t : ℝ) : |thermalVar μ H Y t| ≤ 2*B^2 := by + have h0 := tilt_mean_bound μ (hH.add (hY.const_mul t)) hY + (add_nonneg hA (mul_nonneg (abs_nonneg _) hB)) hB (affinePotential_bound hHA hYB t) hYB 1 + have h2 := tilt_mean_bound μ (hH.add (hY.const_mul t)) (hY.mul hY) + (add_nonneg hA (mul_nonneg (abs_nonneg _) hB)) (sq_nonneg B) + (affinePotential_bound hHA hYB t) (fun x => by + simp only [Pi.mul_apply] + rw [abs_mul,pow_two]; exact mul_le_mul (hYB x) (hYB x) (abs_nonneg _) hB) 1 + simp only [Pi.add_def,Pi.mul_def] at h0 h2 + have hs : |(tiltMean μ (fun x => H x+t*Y x) Y 1)^2| ≤ B^2 := by + rw [abs_sq] + exact sq_le_sq.mpr (by simpa [abs_of_nonneg hB] using h0) + unfold thermalVar + exact (abs_sub _ _).trans (by linarith) + +lemma measurable_affineLogRoot {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) (t : ℝ) : + Measurable (fun ω => affineLogRoot μ (H ω) (Y ω) t) := by + simp only [affineLogRoot,tiltPartition,one_mul] + exact (hH.add (hY.const_mul t)).exp.stronglyMeasurable.integral_prod_right'.measurable.log + +lemma measurable_affineMean {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) (t : ℝ) : + Measurable (fun ω => tiltMean μ (fun x => H ω x+t*Y ω x) (Y ω) 1) := + measurable_tiltMean_param μ (hH.add (hY.const_mul t)) hY + +lemma measurable_thermalVar {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) (t : ℝ) : + Measurable (fun ω => thermalVar μ (H ω) (Y ω) t) := by + exact (measurable_tiltMean_param μ (hH.add (hY.const_mul t)) (hY.mul hY)).sub + ((measurable_affineMean μ hH hY t).pow_const 2) + +omit [IsProbabilityMeasure P] in +lemma annealedAffineLogRoot_deriv {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + {A B : Ω → ℝ} (hA : ∀ ω, 0 ≤ A ω) (hB : ∀ ω, 0 ≤ B ω) + (hHA : ∀ ω x, |H ω x| ≤ A ω) (hYB : ∀ ω x, |Y ω x| ≤ B ω) + (hAI : Integrable A P) (hBI : Integrable B P) (t : ℝ) : + HasDerivAt (fun u => ∫ ω, affineLogRoot μ (H ω) (Y ω) u ∂P) + (∫ ω, tiltMean μ (fun x => H ω x+t*Y ω x) (Y ω) 1 ∂P) t := by + have hHm (ω) : Measurable (H ω) := hH.comp (measurable_const.prodMk measurable_id) + have hYm (ω) : Measurable (Y ω) := hY.comp (measurable_const.prodMk measurable_id) + have hi : Integrable (fun ω => affineLogRoot μ (H ω) (Y ω) t) P := by + apply (hAI.add (hBI.const_mul |t|)).mono' (measurable_affineLogRoot μ hH hY t).aestronglyMeasurable + exact ae_of_all _ fun ω => by + simpa only [affineLogRoot,Real.norm_eq_abs,Pi.add_def] using tilt_log_partition_bound μ + ((hHm ω).add ((hYm ω).const_mul t)) (add_nonneg (hA ω) (mul_nonneg (abs_nonneg _) (hB ω))) + (affinePotential_bound (hHA ω) (hYB ω) t) + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le (μ := P) + (s := Set.univ) (bound := B) (F' := fun u ω => tiltMean μ (fun x => H ω x+u*Y ω x) (Y ω) 1) + (by simp) (Eventually.of_forall fun u => (measurable_affineLogRoot μ hH hY u).aestronglyMeasurable) + hi (measurable_affineMean μ hH hY t).aestronglyMeasurable + (ae_of_all _ fun ω u _ => by + simpa only [Real.norm_eq_abs,Pi.add_def] using tilt_mean_bound μ + ((hHm ω).add ((hYm ω).const_mul u)) (hYm ω) + (add_nonneg (hA ω) (mul_nonneg (abs_nonneg _) (hB ω))) (hB ω) + (affinePotential_bound (hHA ω) (hYB ω) u) (hYB ω) 1) + hBI (ae_of_all _ fun ω u _ => affineLogRoot_deriv μ (hHm ω) (hYm ω) (hA ω) (hB ω) (hHA ω) (hYB ω) u)).2 + +omit [IsProbabilityMeasure P] in +lemma annealedAffineMean_deriv {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + {A B : Ω → ℝ} (hA : ∀ ω, 0 ≤ A ω) (hB : ∀ ω, 0 ≤ B ω) + (hHA : ∀ ω x, |H ω x| ≤ A ω) (hYB : ∀ ω x, |Y ω x| ≤ B ω) + (hBI : Integrable B P) (hB2 : Integrable (fun ω => (B ω)^2) P) (t : ℝ) : + HasDerivAt (fun u => ∫ ω, tiltMean μ (fun x => H ω x+u*Y ω x) (Y ω) 1 ∂P) + (∫ ω, thermalVar μ (H ω) (Y ω) t ∂P) t := by + have hHm (ω) : Measurable (H ω) := hH.comp (measurable_const.prodMk measurable_id) + have hYm (ω) : Measurable (Y ω) := hY.comp (measurable_const.prodMk measurable_id) + have hi : Integrable (fun ω => tiltMean μ (fun x => H ω x+t*Y ω x) (Y ω) 1) P := by + apply hBI.mono' (measurable_affineMean μ hH hY t).aestronglyMeasurable + exact ae_of_all _ fun ω => by + simpa only [Real.norm_eq_abs,Pi.add_def] using tilt_mean_bound μ + ((hHm ω).add ((hYm ω).const_mul t)) (hYm ω) + (add_nonneg (hA ω) (mul_nonneg (abs_nonneg _) (hB ω))) (hB ω) + (affinePotential_bound (hHA ω) (hYB ω) t) (hYB ω) 1 + exact (hasDerivAt_integral_of_dominated_loc_of_deriv_le (μ := P) + (s := Set.univ) (bound := fun ω => 2*(B ω)^2) (F' := fun u ω => thermalVar μ (H ω) (Y ω) u) + (by simp) (Eventually.of_forall fun u => (measurable_affineMean μ hH hY u).aestronglyMeasurable) + hi (measurable_thermalVar μ hH hY t).aestronglyMeasurable + (ae_of_all _ fun ω u _ => by + simpa only [Real.norm_eq_abs] using thermalVar_bound μ (hHm ω) (hYm ω) (hA ω) (hB ω) (hHA ω) (hYB ω) u) + (hB2.const_mul 2) (ae_of_all _ fun ω u _ => affineMean_deriv μ + (hHm ω) (hYm ω) (hA ω) (hB ω) (hHA ω) (hYB ω) u)).2 + +omit [IsProbabilityMeasure P] in + +lemma contact_thermal_variance_le {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + {A B : Ω → ℝ} (hA : ∀ ω, 0 ≤ A ω) (hB : ∀ ω, 0 ≤ B ω) + (hHA : ∀ ω x, |H ω x| ≤ A ω) (hYB : ∀ ω x, |Y ω x| ≤ B ω) + (hAI : Integrable A P) (hBI : Integrable B P) (hB2 : Integrable (fun ω => (B ω)^2) P) + {u a c : ℝ} + (hmin : IsLocalMin (fun t => c*(t-a)^2-∫ ω, affineLogRoot μ (H ω) (Y ω) t ∂P) u) : + (∫ ω, thermalVar μ (H ω) (Y ω) u ∂P) ≤ 2*c := by + exact quadratic_contact_second_deriv + (annealedAffineLogRoot_deriv μ P hH hY hA hB hHA hYB hAI hBI) + (annealedAffineMean_deriv μ P hH hY hA hB hHA hYB hBI hB2 u) hmin + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/MarkTiltKernel.lean b/lean/OAI/Probability/Perceptron/Variational/MarkTiltKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..220e77dc0974520373e9de137b0a33c0aa0c6c8f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/MarkTiltKernel.lean @@ -0,0 +1,179 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DecoratedTiltTotal + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +lemma normalized_product_tilt_lintegral {S T : Type*} + [MeasurableSpace S] [MeasurableSpace T] + (ν : Measure S) (ρ : Measure T) [SFinite ν] [SFinite ρ] + {f : S → ℝ≥0∞} {g : S×T → ℝ≥0∞} + (hf : Measurable f) (hg : Measurable g) {c : ℝ≥0∞} + (hc0 : c ≠ 0) (hcf : c ≠ ⊤) + (hrow : ∀ s, (∫⁻ t, g (s,t) ∂ρ) = c) + {H : S×T → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ p, H p ∂normalizedMeasure ((ν.prod ρ).withDensity (fun p => f p.1*g p))) = + ∫⁻ s, (∫⁻ t, H (s,t) ∂normalizedMeasure (ρ.withDensity (fun t => g (s,t)))) + ∂normalizedMeasure (ν.withDensity f) := by + have hfg : Measurable (fun p : S×T => f p.1*g p) := (hf.comp measurable_fst).mul hg + have hgh : Measurable (fun p : S×T => g p*H p) := hg.mul hH + have hfgH : Measurable (fun p : S×T => (f p.1*g p)*H p) := hfg.mul hH + have hgs (s : S) : Measurable (fun t => g (s,t)) := hg.comp (measurable_const.prodMk measurable_id) + have hHs (s : S) : Measurable (fun t => H (s,t)) := hH.comp (measurable_const.prodMk measurable_id) + have hmass : ((ν.prod ρ).withDensity (fun p => f p.1*g p)) univ = + (ν.withDensity f) univ*c := by + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + lintegral_prod _ hfg.aemeasurable] + simp_rw [lintegral_const_mul _ (hgs _),hrow] + rw [lintegral_mul_const _ hf,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + have hi (s : S) : (∫⁻ t, H (s,t) ∂normalizedMeasure (ρ.withDensity (fun t => g (s,t)))) = + c⁻¹ * ∫⁻ t, g (s,t)*H (s,t) ∂ρ := by + rw [normalizedMeasure,lintegral_smul_measure, + withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ,hrow, + lintegral_withDensity_eq_lintegral_mul ρ + (hgs s) (hHs s)] + rfl + have hJ : Measurable (fun s => ∫⁻ t, g (s,t)*H (s,t) ∂ρ) := + (hg.mul hH).lintegral_prod_right + simp_rw [hi] + rw [normalizedMeasure,lintegral_smul_measure,hmass, + lintegral_withDensity_eq_lintegral_mul _ hfg hH] + simp only [Pi.mul_apply] + rw [lintegral_prod _ hfgH.aemeasurable, + normalizedMeasure,lintegral_smul_measure, + lintegral_withDensity_eq_lintegral_mul _ hf (hJ.const_mul _)] + simp only [smul_eq_mul,Pi.mul_apply] + have hinner (s : S) : (∫⁻ t, f s*(g (s,t)*H (s,t)) ∂ρ) = + f s*(∫⁻ t, g (s,t)*H (s,t) ∂ρ) := + lintegral_const_mul (f s) (hgs s |>.mul (hHs s)) + simp_rw [mul_assoc,hinner] + rw [ENNReal.mul_inv (Or.inr hcf) (Or.inr hc0)] + simp_rw [← mul_assoc, mul_right_comm (f _) c⁻¹] + have hfj : Measurable (fun s => f s * ∫⁻ t, g (s,t)*H (s,t) ∂ρ) := hf.mul hJ + rw [lintegral_mul_const _ hfj] + ac_rfl + +lemma exponential_product_tilt_lintegral {S T : Type*} + [MeasurableSpace S] [MeasurableSpace T] + (ν : Measure S) (ρ : Measure T) [SFinite ν] [SFinite ρ] + {f : S → ℝ} {g : S×T → ℝ} + (hf : Measurable f) (hg : Measurable g) (b : ℝ) {c : ℝ} + (hc : 0 < c) + (hI : ∀ s, Integrable (fun t => Real.exp (b*g (s,t))) ρ) + (hrow : ∀ s, (∫ t, Real.exp (b*g (s,t)) ∂ρ) = c) + {H : S×T → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ p, H p ∂exponentialMarkTilt (ν.prod ρ) b (fun p => f p.1+g p)) = + ∫⁻ s, (∫⁻ t, H (s,t) ∂exponentialMarkTilt ρ b (fun t => g (s,t))) + ∂exponentialMarkTilt ν b f := by + have he (p : S×T) : ENNReal.ofReal (Real.exp (b*(f p.1+g p))) = + ENNReal.ofReal (Real.exp (b*f p.1))*ENNReal.ofReal (Real.exp (b*g p)) := by + rw [mul_add,Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos _).le] + unfold exponentialMarkTilt + simp_rw [he] + apply normalized_product_tilt_lintegral ν ρ + (hf.const_mul b |>.exp.ennreal_ofReal) (hg.const_mul b |>.exp.ennreal_ofReal) + (c := ENNReal.ofReal c) (ENNReal.ofReal_ne_zero_iff.mpr hc) ENNReal.ofReal_ne_top + · intro s + rw [← ofReal_integral_eq_lintegral_ofReal (hI s) + (ae_of_all _ fun t => (Real.exp_pos _).le),hrow s] + · exact hH + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +lemma decoratedBiasedLaw_absolutelyContinuous (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin n → ℝ) (F : Fin n → X×S → ℝ) (x : X) (a : ℝ) : + decoratedBiasedLaw ν step n z F x a ≪ (decoratedCascadeLaw ν n z) := + Measure.smul_absolutelyContinuous.trans (withDensity_absolutelyContinuous _ _) + +lemma decoratedRootTilt_disintegrate (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) + (H : S×DecoratedCascade S n → ℝ≥0∞) (hH : Measurable H) : + (∫⁻ p, H p ∂exponentialMarkTilt + ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ))) (z 0) + (fun p => decoratedRootPotential step n F (x,p))) = + ∫⁻ s, (∫⁻ C, H (s,C) ∂decoratedBiasedLaw ν step n + (fun i => z i.succ) (fun i => F i.succ) (step (x,s)) (z 0)) + ∂exponentialMarkTilt ν (z 0) (fun s => F 0 (x,s)) := by + have htail : StrictMono (fun i : Fin n => z i.succ) := + fun i j h => hz (Fin.succ_lt_succ_iff.mpr h) + have hrange : ∀ i : Fin n, z 0 < z i.succ := fun i => hz (by simp) + have hC := cascadeLogTotalMoment_integrable n (fun i => z i.succ) htail + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (z 0) hrange + have hG : Measurable (fun p : S×DecoratedCascade S n => + Real.log (decoratedWeightedTotal step n (fun i => F i.succ) (step (x,p.1),p.2))) := + ((decoratedWeightedTotal_measurable step hs n _ (fun i => hF i.succ)).comp + ((hs.comp (measurable_const.prodMk measurable_fst)).prodMk measurable_snd)).log + have he := exponential_product_tilt_lintegral (ν : Measure S) + (decoratedCascadeLaw ν n (fun i => z i.succ) : Measure (DecoratedCascade S n)) + ((hF 0).comp ((measurable_const (a := x)).prodMk measurable_id)) hG (z 0) + (integral_exp_pos hC) + (fun s => decoratedLogTotalMoment_integrable ν step hs n (fun i => z i.succ) + htail (fun i => hz0 i.succ) (fun i => hz1 i.succ) (fun i => F i.succ) + (fun i => hF i.succ) (fun i => hI i.succ) (fun i => hM i.succ) + (step (x,s)) (z 0) hrange) + (fun s => decoratedLogTotalMoment_eq ν step hs n (fun i => z i.succ) + (fun i => hz0 i.succ) (fun i => hz1 i.succ) (fun i => F i.succ) + (fun i => hF i.succ) (fun i => hI i.succ) (fun i => hM i.succ) + (step (x,s)) (z 0)) hH + have hb (s : S) := decoratedBiasedLaw_eq_exponentialTilt ν step hs n + (fun i => z i.succ) htail (fun i => hz0 i.succ) (fun i => hz1 i.succ) + (fun i => F i.succ) (fun i => hF i.succ) (fun i => hI i.succ) + (fun i => hM i.succ) (step (x,s)) (z 0) + simp_rw [hb] + exact he + +lemma decoratedRootBlock_factor (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) + (a : ℝ) (ha : a < z 0) + (ns : List (ℕ×(S×DecoratedCascade S n → ℝ≥0∞))) (hne : ns ≠ []) + (hn : ∀ nf ∈ ns, 1 ≤ nf.1) (hm : ∀ nf ∈ ns, Measurable nf.2) : + (∫⁻ η, markedBlockProbability ns + ((markedStableCountKernel η).map (logMarkShift + (centeredLogMark ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ))) + (z 0) (fun p => decoratedRootPotential step n F (x,p))))) (Fin.elim0 : Fin 0 → ℝ) + ∂decoratedBiasedLaw ν step (n+1) z F x a) = + (ns.map (fun nf => ∫⁻ s, (∫⁻ C, nf.2 (s,C) ∂decoratedBiasedLaw ν step n + (fun i => z i.succ) (fun i => F i.succ) (step (x,s)) (z 0)) + ∂exponentialMarkTilt ν (z 0) (fun s => F 0 (x,s)))).prod * + (∫⁻ η, stableBlockProbability (ns.map Prod.fst) η (Fin.elim0 : Fin 0 → ℝ) + ∂stableTotalBiasedLaw a (z 0)) := by + have hreg := (decoratedBiasedLaw_absolutelyContinuous ν step (n+1) z F x a).ae_eq + (markedStableCountKernel_ae_eq + ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ) : Measure (DecoratedCascade S n))) + (hz0 0) (hz1 0)) + let G : Measure (ℝ×(S×DecoratedCascade S n)) → ℝ≥0∞ := fun η => + markedBlockProbability ns (η.map (logMarkShift (centeredLogMark + ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ))) (z 0) + (fun p => decoratedRootPotential step n F (x,p))))) (Fin.elim0 : Fin 0 → ℝ) + have he := lintegral_congr_ae (hreg.mono (fun η hη => congrArg G hη)) + dsimp [G] at he + have hR : Measurable (fun p : S×DecoratedCascade S n => + decoratedRootPotential step n F (x,p)) := + (decoratedRootPotential_measurable step hs n F hF).comp + (measurable_const.prodMk measurable_id) + rw [he,decoratedBiasedLaw_succ_eq_weighted ν step hs n z hz hz0 hz1 F hF hI hM x a, + weightedRootBlock_factor _ (hz0 0) (hz1 0) ha + hR + (decoratedRootPotential_integrable ν step hs n z hz hz0 hz1 F hF hI hM x) ns hne hn hm] + congr 2 + apply List.map_congr_left + intro nf hnf + exact decoratedRootTilt_disintegrate ν step hs n z hz hz0 hz1 F hF hI hM x nf.2 (hm nf hnf) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/MarkedBlockParameter.lean b/lean/OAI/Probability/Perceptron/Variational/MarkedBlockParameter.lean new file mode 100644 index 0000000000000000000000000000000000000000..88f63195fcecb1a107d2a3730b5e474ecd4791b8 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/MarkedBlockParameter.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.DecoratedTiltTotal + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +lemma markedBlockProbability_parameter_measurable {X S : Type*} + [MeasurableSpace X] [MeasurableSpace S] + (ns : List (ℕ × (X×S → ℝ≥0∞))) + (hm : ∀ nf ∈ ns, Measurable nf.2) (m : ℕ) : + Measurable (fun p : X×(Measure (ℝ×S)×(Fin m → ℝ)) => + markedBlockProbability (ns.map (fun nf => (nf.1,fun s => nf.2 (p.1,s)))) + p.2.1 p.2.2) := by + induction ns generalizing m with + | nil => exact measurable_const + | cons nf ns ih => + let κ : Kernel (X×(Measure (ℝ×S)×(Fin m → ℝ))) (ℝ×S) := + markedStableMassKernel.comap (fun p => p.2.1) measurable_snd.fst + have hD : Measurable (fun p : (X×(Measure (ℝ×S)×(Fin m → ℝ)))×(ℝ×S) => + markedBlockProbability (ns.map (fun nf => (nf.1,fun s => nf.2 (p.1.1,s)))) + p.1.2.1 (Fin.cons p.2.1 p.1.2.2)) := by + exact (ih (fun r hr => hm r (List.mem_cons_of_mem nf hr)) (m+1)).comp + (measurable_fst.fst.prodMk (measurable_fst.snd.fst.prodMk + (measurable_fin_cons measurable_snd.fst measurable_fst.snd.snd))) + have ha : Measurable (fun p : (X×(Measure (ℝ×S)×(Fin m → ℝ)))×(ℝ×S) => + stableMassKernel (p.1.2.1.map Prod.fst) {p.2.1}) := + stableMassAtom_measurable_comp + ((Measure.measurable_map _ measurable_fst).comp measurable_fst.snd.fst) + measurable_snd.fst + have hset : MeasurableSet {p : (X×(Measure (ℝ×S)×(Fin m → ℝ)))×(ℝ×S) | + ∃ i, p.1.2.2 i = p.2.1} := + cascadeMeasurableSet_exists fun i => measurableSet_eq_fun (by fun_prop) measurable_snd.fst + simp only [List.map_cons,markedBlockProbability] + exact (measurable_const.ite hset + (((ha.pow_const (nf.1-1)).mul ((hm nf (by simp)).comp + (measurable_fst.fst.prodMk measurable_snd.snd))).mul hD)).lintegral_kernel_prod_right' (κ := κ) + +@[reducible] def DecoratedVisitShape (X : Type) : ℕ → Type + | 0 => ℕ × (X → ℝ≥0∞) + | n+1 => List (DecoratedVisitShape X n) + +def DecoratedVisitShape.bare {X : Type} : (n : ℕ) → DecoratedVisitShape X n → CascadeVisitShape n + | 0, s => s.1 + | n+1, ss => ss.map (DecoratedVisitShape.bare n) + +def DecoratedVisitShape.Valid {X : Type} [MeasurableSpace X] : + (n : ℕ) → DecoratedVisitShape X n → Prop + | 0, s => 1 ≤ s.1 ∧ Measurable s.2 + | n+1, ss => ss ≠ [] ∧ ∀ s ∈ ss, DecoratedVisitShape.Valid n s + +lemma DecoratedVisitShape.bare_valid {X : Type} [MeasurableSpace X] + (n : ℕ) (s : DecoratedVisitShape X n) (hs : s.Valid n) : + CascadeVisitShape.Valid n (s.bare n) := by + induction n with + | zero => exact hs.1 + | succ n ih => + exact ⟨by simpa [DecoratedVisitShape.bare] using hs.1, + by intro t ht; obtain ⟨s',hm,rfl⟩ := List.mem_map.mp ht; exact ih s' (hs.2 s' hm)⟩ + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +def decoratedCenteredRoot (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin (n+1) → ℝ) (F : Fin (n+1) → X×S → ℝ) + (p : X×(S×DecoratedCascade S n)) : ℝ := + centeredLogMark ((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ))) + (z 0) (fun t => decoratedRootPotential step n F (p.1,t)) p.2 + +lemma decoratedCenteredRoot_measurable (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) : + Measurable (decoratedCenteredRoot ν step n z F) := by + have hR := decoratedRootPotential_measurable step hs n F hF + have hE : StronglyMeasurable (fun p : X×(S×DecoratedCascade S n) => + Real.exp (z 0*decoratedRootPotential step n F p)) := + (hR.const_mul _).exp.stronglyMeasurable + have hM : Measurable (fun x => ∫ t : S×DecoratedCascade S n, + Real.exp (z 0*decoratedRootPotential step n F (x,t)) + ∂((ν : Measure S).prod (decoratedCascadeLaw ν n (fun i => z i.succ)))) := + (StronglyMeasurable.integral_prod_right + (f := fun x t => Real.exp (z 0*decoratedRootPotential step n F (x,t))) hE).measurable + exact hR.sub ((hM.comp measurable_fst).log.div_const _) + +def decoratedShapeProbability (ν : ProbabilityMeasure S) (step : X×S → X) : + (n : ℕ) → (Fin n → ℝ) → (Fin n → X×S → ℝ) → + DecoratedVisitShape X n → X×DecoratedCascade S n → ℝ≥0∞ + | 0, _, _, s, p => s.2 p.1 + | n+1, z, F, ss, p => markedBlockProbability + (ss.map (fun s => (cascadeVisitCount n (s.bare n),fun t : S×DecoratedCascade S n => + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) s + (step (p.1,t.1),t.2)))) + ((markedStableCountKernel p.2).map (fun t : ℝ×(S×DecoratedCascade S n) => + (t.1+decoratedCenteredRoot ν step n z F (p.1,t.2),t.2))) (Fin.elim0 : Fin 0 → ℝ) + +lemma decoratedShapeProbability_measurable (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (s : DecoratedVisitShape X n) (hs' : s.Valid n) : + Measurable (decoratedShapeProbability ν step n z F s) := by + induction n with + | zero => exact hs'.2.comp measurable_fst + | succ n ih => + let ns : List (ℕ×(X×(S×DecoratedCascade S n) → ℝ≥0∞)) := + s.map (fun t => (cascadeVisitCount n (t.bare n),fun p => + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) t + (step (p.1,p.2.1),p.2.2))) + have hm : ∀ nf ∈ ns, Measurable nf.2 := by + intro nf hnf; obtain ⟨t,ht,rfl⟩ := List.mem_map.mp hnf + exact (ih (fun i => z i.succ) (fun i => F i.succ) (fun i => hF i.succ) t + (hs'.2 t ht)).comp + ((hs.comp (measurable_fst.prodMk measurable_snd.fst)).prodMk measurable_snd.snd) + have hmap := countKernel_parameter_map_measurable + (fun p : X×(ℝ×(S×DecoratedCascade S n)) => + (p.2.1+decoratedCenteredRoot ν step n z F (p.1,p.2.2),p.2.2)) + ((measurable_snd.fst.add ((decoratedCenteredRoot_measurable ν step hs n z F hF).comp + (measurable_fst.prodMk measurable_snd.snd))).prodMk measurable_snd.snd) + have hh := (markedBlockProbability_parameter_measurable ns hm 0).comp + (measurable_fst.prodMk (hmap.prodMk (measurable_const (a := (Fin.elim0 : Fin 0 → ℝ))))) + convert hh using 1 + funext p + simp only [decoratedShapeProbability,ns,List.map_map,Function.comp_def] + +def decoratedShapeMarkValue (ν : ProbabilityMeasure S) (step : X×S → X) : + (n : ℕ) → (Fin n → ℝ) → (Fin n → X×S → ℝ) → + DecoratedVisitShape X n → X → ℝ≥0∞ + | 0, _, _, s, x => s.2 x + | n+1, z, F, ss, x => (ss.map (fun s => ∫⁻ t, + ENNReal.ofReal (Real.exp (z 0*F 0 (x,t)))* + decoratedShapeMarkValue ν step n (fun i => z i.succ) (fun i => F i.succ) + s (step (x,t)) ∂ν)).prod + +omit [Nonempty S] in +lemma decoratedShapeMarkValue_measurable (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (s : DecoratedVisitShape X n) (hs' : s.Valid n) : + Measurable (decoratedShapeMarkValue ν step n z F s) := by + induction n with + | zero => exact hs'.2 + | succ n ih => + have hterm (t : DecoratedVisitShape X n) (ht : t ∈ s) : + Measurable (fun x => ∫⁻ u, ENNReal.ofReal (Real.exp (z 0*F 0 (x,u)))* + decoratedShapeMarkValue ν step n (fun i => z i.succ) (fun i => F i.succ) + t (step (x,u)) ∂ν) := by + have h : Measurable (fun p : X×S => ENNReal.ofReal (Real.exp (z 0*F 0 p))* + decoratedShapeMarkValue ν step n (fun i => z i.succ) (fun i => F i.succ) + t (step p)) := + ((hF 0).const_mul _).exp.ennreal_ofReal.mul + ((ih _ _ (fun i => hF i.succ) t (hs'.2 t ht)).comp hs) + exact h.lintegral_prod_right + change Measurable (fun x => (s.map (fun t => ∫⁻ u, + ENNReal.ofReal (Real.exp (z 0*F 0 (x,u)))* + decoratedShapeMarkValue ν step n (fun i => z i.succ) (fun i => F i.succ) + t (step (x,u)) ∂ν)).prod) + clear hs' ih + induction s with + | nil => exact measurable_const + | cons t ts iht => + simp only [List.map_cons,List.prod_cons] + exact (hterm t (by simp)).mul (iht (fun u hu => hterm u (by simp [hu]))) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/MarkedGraphLaw.lean b/lean/OAI/Probability/Perceptron/Variational/MarkedGraphLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..c38cf037e4747a8f6f0adf7981eab246d0ea7c53 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/MarkedGraphLaw.lean @@ -0,0 +1,86 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.MarkedTangentCanonical +import OAI.Probability.Perceptron.Variational.RoundedCoupling + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +abbrev markedTimePair (K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) : Measure Time := + (markedTimeLaw K μ : Measure (CompactArray Time)).map (fun Q => Q 0 1) + +instance markedTimePair_isProbability (K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) : + IsProbabilityMeasure (markedTimePair K μ) := + inferInstance + +lemma markedTimePair_ae {K : ℝ} (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + {P : Time → Prop} (hP : ∀ᵐ r ∂markedTimePair K μ, P r) : + ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), P (nonnegativeSpinTime (Q 0 1).1) := by + have h := ae_of_ae_map (show Measurable (fun Q : CompactArray Time => Q 0 1) from by fun_prop).aemeasurable hP + exact ae_of_ae_map (compactMapArray_continuous + (nonnegativeSpinTime_continuous.comp (show Continuous (Prod.fst : BulkPairRange K → CompactOverlap) from continuous_fst))).measurable.aemeasurable h + +theorem marked_graph_law {K B d : ℝ} (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (hB : B < 1) (hd0 : 0 ≤ d) (hdK : d ≤ K) + (he : ∀ e : Equiv.Perm ℕ, MeasurePreserving (compactRelabel (K:=BulkPairRange K) e) + (μ : Measure _) (μ : Measure _)) + (hn : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i j, 0 ≤ (Q i j).1.val) + (hD1 : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i, (Q i i).1.val = 1) + (hD2 : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i, (Q i i).2.val = d) + (hBd : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i j, (Q i j).2.val ≤ d) + (a : ℝ → ℝ) (ha0 : ∀ r, 0 ≤ a r) + (hag : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), ∀ i j, i ≠ j → (Q i j).2.val = a (Q i j).1.val) + (hsc : ∀ᵐ r : Time ∂markedTimePair K μ, a r.val = ∫ t in 0..r.val, (realTail (markedTimePair K μ) t)⁻¹^2) + (hbound : ∀ᵐ r : Time ∂markedTimePair K μ, r.val ≤ B) : + (markedTimeLaw K μ).map (timeMarkedDecode + (continuousCavityProfile (markedTimePair K μ) B hd0 hdK) + (cavityTrueDiagonal hd0 hdK)) = μ := by + let P := continuousCavityProfile (markedTimePair K μ) B hd0 hdK + let D := cavityTrueDiagonal hd0 hdK + let e : BulkPairRange K → Time := fun p => nonnegativeSpinTime p.1 + have hP : Continuous P := continuousCavityProfile_continuous (markedTimePair K μ) hB hd0 hdK + have hec : Continuous e := nonnegativeSpinTime_continuous.comp continuous_fst + have h01 : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), P (e (Q 0 1)) = Q 0 1 := by + filter_upwards [markedTimePair_ae μ hsc,markedTimePair_ae μ hbound,hn,hBd,hag] with Q hS hBnd hN hBd hAg + have hval : (e (Q 0 1)).val = (Q 0 1).1.val := nonnegativeSpinTime_val (hN 0 1) + apply Prod.ext + · exact Subtype.ext hval + · apply Subtype.ext + apply continuousCavityProfile_eq (markedTimePair K μ) hd0 hdK hbound hBnd + · rw [hAg 0 1 (by omega)]; exact ha0 _ + · exact hBd 0 1 + · change a (e (Q 0 1)).val = _ at hS + rw [hval] at hS + rw [hAg 0 1 (by omega)] + change a (Q 0 1).1.val = ∫ t in 0..(e (Q 0 1)).val, (realTail (markedTimePair K μ) t)⁻¹^2 + rw [hval] + exact hS + have h10 := (he (Equiv.swap 0 1)).quasiMeasurePreserving.ae h01 + have h10' : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))), P (e (Q 1 0)) = Q 1 0 := by + simpa only [compactRelabel,Equiv.swap_apply_left,Equiv.swap_apply_right] using h10 + have hoff := compact_exchangeable_offdiag_ae μ he (fun p => P (e p) = p) h10' + have hall : (timeMarkedDecode P D ∘ compactMapArray e) =ᵐ[(μ : Measure (CompactArray (BulkPairRange K)))] id := by + filter_upwards [hoff,hD1,hD2] with Q hO hD1 hD2 + funext i j + dsimp only [Function.comp_def,timeMarkedDecode,compactMapArray,id_eq] + by_cases hij : i = j + · rw [ite_eq_left hij] + subst j + exact Prod.ext (Subtype.ext (hD1 i).symm) (Subtype.ext (hD2 i).symm) + · rw [ite_eq_right hij] + exact hO i j hij + apply ProbabilityMeasure.toMeasure_injective + change Measure.map (timeMarkedDecode P D) (Measure.map (compactMapArray e) + (μ : Measure (CompactArray (BulkPairRange K)))) = (μ : Measure (CompactArray (BulkPairRange K))) + rw [Measure.map_map (timeMarkedDecode_measurable hP.measurable D) + (compactMapArray_continuous hec).measurable, + Measure.map_congr hall,Measure.map_id] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/MarkedTangentCanonical.lean b/lean/OAI/Probability/Perceptron/Variational/MarkedTangentCanonical.lean new file mode 100644 index 0000000000000000000000000000000000000000..f95a379456483865f9f5244c141ea33f397bf052 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/MarkedTangentCanonical.lean @@ -0,0 +1,131 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ArrayTangentConsistency +import OAI.Probability.Perceptron.Cavity.BulkMarkedArray + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped BoundedContinuousFunction ContDiff NNReal + +lemma marked_tangent_canonical (K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (he : ∀ e : Equiv.Perm ℕ,MeasurePreserving (compactRelabel (K:=BulkPairRange K) e) (μ : Measure _) (μ : Measure _)) + (a : ℝ→ℝ) + (hgraph : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,i≠j→(Q i j).2.val=a (Q i j).1.val) + (G : ℝ→ᵇℝ) + (hT : (∫ Q,markedTangentR K G (compactBlock 2 Q) ∂(μ : Measure _))- + (∫ Q,markedTangentPair K G (compactBlock 2 Q) ∂(μ : Measure _))+ + 2*(∫ Q,markedTangentTriple K G (compactBlock 3 Q) ∂(μ : Measure _))=0) : + (∫ Q : CompactArray (BulkPairRange K),G (Q 0 1).1.val*((Q 0 1).1.val-a (Q 0 1).1.val*(1-(Q 0 1).1.val^2)+ + 2*a (Q 0 2).1.val*((Q 1 2).1.val-(Q 0 1).1.val*(Q 0 2).1.val)) ∂(μ : Measure _))=0 := by + let F1 := (markedTangentR K G).compContinuous ⟨compactBlock 2,compactBlock_continuous 2⟩ + let F2 := (markedTangentPair K G).compContinuous ⟨compactBlock 2,compactBlock_continuous 2⟩ + let F3 := (markedTangentTriple K G).compContinuous ⟨compactBlock 3,compactBlock_continuous 3⟩ + let F4 : CompactArray (BulkPairRange K)→ᵇℝ := BoundedContinuousFunction.mkOfCompact + ⟨fun Q=>G (Q 0 1).1.val*(Q 0 2).2.val*((Q 1 2).1.val-(Q 0 1).1.val*(Q 0 2).1.val),by fun_prop⟩ + let e : Equiv.Perm ℕ := (Equiv.swap 0 1).trans (Equiv.swap 1 2) + have hp : (∫ Q,F3 Q ∂(μ : Measure _))=∫ Q,F4 Q ∂(μ : Measure _) := by + have h := integral_map (μ:=(μ : Measure (CompactArray (BulkPairRange K)))) (he e).measurable.aemeasurable F3.measurable.aestronglyMeasurable + rw [(he e).map_eq] at h + change (∫ Q,F3 Q ∂(μ : Measure _))=∫ Q,F3 (compactRelabel e Q) ∂(μ : Measure _) at h + rw [h] + apply integral_congr_ae + filter_upwards [] with Q + simp [F3,F4,markedTangentTriple,compactBlock,compactRelabel,e,Equiv.swap_apply_def] + have hi1 := F1.integrable (μ : Measure _) + have hi2 := F2.integrable (μ : Measure _) + have hi4 := F4.integrable (μ : Measure _) + have hi12 : Integrable (fun Q=>F1 Q-F2 Q) (μ : Measure _) := hi1.sub hi2 + have hz : (∫ Q,(F1 Q-F2 Q)+2*F4 Q ∂(μ : Measure _))=0 := by + rw [integral_add hi12 (hi4.const_mul 2),integral_sub hi1 hi2,integral_const_mul,←hp] + exact hT + rw [←hz] + apply integral_congr_ae + filter_upwards [hgraph] with Q hQ + have h01 := hQ 0 1 (by omega) + have h02 := hQ 0 2 (by omega) + change G (Q 0 1).1.val*((Q 0 1).1.val-a (Q 0 1).1.val*(1-(Q 0 1).1.val^2)+ + 2*a (Q 0 2).1.val*((Q 1 2).1.val-(Q 0 1).1.val*(Q 0 2).1.val))= + ((Q 0 1).1.val*G (Q 0 1).1.val-G (Q 0 1).1.val*(Q 0 1).2.val*(1-(Q 0 1).1.val^2))+ + 2*(G (Q 0 1).1.val*(Q 0 2).2.val*((Q 1 2).1.val-(Q 0 1).1.val*(Q 0 2).1.val)) + rw [h01,h02] + ring + +def nonnegativeSpinTime (q : CompactOverlap) : Time := + ⟨max q.val 0,le_max_right _ _,max_le q.property.2 zero_le_one⟩ +lemma nonnegativeSpinTime_continuous : Continuous nonnegativeSpinTime := by + unfold nonnegativeSpinTime + fun_prop +lemma nonnegativeSpinTime_val {q : CompactOverlap} (hq : 0≤q.val) : + (nonnegativeSpinTime q).val=q.val := max_eq_left hq + +def markedTimeLaw (K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) : + ProbabilityMeasure (CompactArray Time) := + compactMapLaw (fun p : BulkPairRange K=>nonnegativeSpinTime p.1) + (nonnegativeSpinTime_continuous.comp continuous_fst) μ + +lemma markedTimeLaw_factor (K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) : + markedTimeLaw K μ=compactMapLaw nonnegativeSpinTime nonnegativeSpinTime_continuous + (compactMapLaw Prod.fst continuous_fst μ) := by + apply Subtype.ext + change Measure.map _ (μ : Measure (CompactArray (BulkPairRange K)))= + Measure.map _ (Measure.map _ (μ : Measure (CompactArray (BulkPairRange K)))) + rw [Measure.map_map (compactMapArray_continuous nonnegativeSpinTime_continuous).measurable + (compactMapArray_continuous continuous_fst).measurable] + rfl + +lemma marked_time_self_consistency (K : ℝ) (μ : ProbabilityMeasure (CompactArray (BulkPairRange K))) + (he : ∀ e : Equiv.Perm ℕ,MeasurePreserving (compactRelabel (K:=BulkPairRange K) e) (μ : Measure _) (μ : Measure _)) + (hGG : ∀ n (i : Fin n) (F : CompactBlock CompactOverlap n→ᵇℝ) (g : CompactOverlap→ᵇℝ), + compactGGDefect (compactMapLaw Prod.fst continuous_fst μ) n i F g=0) + (hsy : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,(Q i j).1=(Q j i).1) + (hul : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j k, + min (Q i j).1.val (Q i k).1.val≤(Q j k).1.val) + (hn : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,0≤(Q i j).1.val) + (a : ℝ→ℝ) (ha : Measurable a) {A : ℝ} (hA : 0≤A) (hab : ∀ x,0≤a x ∧ a x≤A) + (hgraph : ∀ᵐ Q ∂(μ : Measure (CompactArray (BulkPairRange K))),∀ i j,i≠j→(Q i j).2.val=a (Q i j).1.val) + (hT : ∀ G : ℝ→ᵇℝ,ContDiff ℝ 1 (G : ℝ→ℝ)→ + (∫ Q,markedTangentR K G (compactBlock 2 Q) ∂(μ : Measure _))- + (∫ Q,markedTangentPair K G (compactBlock 2 Q) ∂(μ : Measure _))+ + 2*(∫ Q,markedTangentTriple K G (compactBlock 3 Q) ∂(μ : Measure _))=0) : + let ν := (markedTimeLaw K μ : Measure (CompactArray Time)).map (fun Q=>Q 0 1) + (∀ᵐ x : Time ∂ν,a x=∫ y in 0..(x:ℝ),(realTail ν y)⁻¹^2) ∧ + ∀ᵐ x : Time ∂ν,(x:ℝ)≤A/(1+A) := by + let e : BulkPairRange K→Time := fun p=>nonnegativeSpinTime p.1 + have hec : Continuous e := nonnegativeSpinTime_continuous.comp continuous_fst + have hm : Measurable (compactMapArray e) := (compactMapArray_continuous hec).measurable + have hs : ∀ᵐ Q ∂(markedTimeLaw K μ : Measure (CompactArray Time)),∀ i j,Q i j=Q j i := by + apply (ae_map_iff hm.aemeasurable (by + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun i=>MeasurableSet.iInter fun j=>measurableSet_eq_fun (by fun_prop) (by fun_prop))).mpr + filter_upwards [hsy] with Q hQ + intro i j + exact congrArg nonnegativeSpinTime (hQ i j) + have hu : ∀ᵐ Q ∂(markedTimeLaw K μ : Measure (CompactArray Time)),∀ i j k,min (Q i j:ℝ) (Q i k:ℝ)≤(Q j k:ℝ) := by + apply (ae_map_iff hm.aemeasurable (by + simp only [Set.ofPred_forall] + exact MeasurableSet.iInter fun i=>MeasurableSet.iInter fun j=>MeasurableSet.iInter fun k=> + measurableSet_le (by fun_prop) (by fun_prop))).mpr + filter_upwards [hul,hn] with Q hQ hN + intro i j k + simpa only [compactMapArray,e,nonnegativeSpinTime_val (hN i j),nonnegativeSpinTime_val (hN i k), + nonnegativeSpinTime_val (hN j k)] using hQ i j k + apply array_tangent_self_consistency (markedTimeLaw K μ) + (by rw [markedTimeLaw_factor]; exact compactMapLaw_gg _ _ _ hGG 2 0) + (compactMapLaw_exchangeable e hec μ (Equiv.swap 0 1) (he _)) hs hu + (fun x=>a x.val) (ha.comp measurable_subtype_coe) hA (fun x=>hab x.val) + intro G hG + rw [show (markedTimeLaw K μ : Measure (CompactArray Time))=(μ : Measure _).map (compactMapArray e) from rfl, + integral_map hm.aemeasurable (show AEStronglyMeasurable (fun Q : CompactArray Time=>G (Q 0 1)* + ((Q 0 1:ℝ)-a (Q 0 1)*(1-(Q 0 1:ℝ)^2)+2*a (Q 0 2)*((Q 1 2:ℝ)-(Q 0 1:ℝ)*(Q 0 2:ℝ)))) _ from (show Measurable (fun Q : CompactArray Time=>G (Q 0 1)* + ((Q 0 1:ℝ)-a (Q 0 1)*(1-(Q 0 1:ℝ)^2)+2*a (Q 0 2)*((Q 1 2:ℝ)-(Q 0 1:ℝ)*(Q 0 2:ℝ)))) from by fun_prop).aestronglyMeasurable)] + rw [←marked_tangent_canonical K μ he a hgraph G (hT G hG)] + apply integral_congr_ae + filter_upwards [hn] with Q hN + simp only [compactMapArray,e,nonnegativeSpinTime_val (hN 0 1),nonnegativeSpinTime_val (hN 0 2),nonnegativeSpinTime_val (hN 1 2)] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/MarkedTotalBiasedLaw.lean b/lean/OAI/Probability/Perceptron/Variational/MarkedTotalBiasedLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..58a216c7bae947d84249a5d1a6e562824332e065 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/MarkedTotalBiasedLaw.lean @@ -0,0 +1,448 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StableTotalBiasedLaw + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff +attribute [fun_prop] stablePoissonTotal_measurable +variable {S : Type*} [MeasurableSpace S] +variable [Nonempty S] +omit [Nonempty S] in +lemma markedDistinctMoment_add_dirac (rs : List (ℝ × (S → ℝ≥0∞))) + (hr : ∀ rf ∈ rs, Measurable rf.2) (η : Measure (ℝ × S)) (p : ℝ × S) + (hf : markedStableTotalE η ≠ ⊤) (hp : 0 < markedStableTotal η) + {m : ℕ} (z : Fin m → ℝ) (hz : ∃ i, z i = p.1) : + markedDistinctMoment rs (Measure.dirac p+η) z = markedDistinctMoment rs η z := by + induction rs generalizing m with + | nil => rfl + | cons rf rs ih => + have ht : ∀ r ∈ rs, Measurable r.2 := fun r hr' => hr r (List.mem_cons_of_mem rf hr') + have hm : Measurable (fun q : ℝ × S => if ∃ i, z i = q.1 then (0:ℝ≥0∞) else + ENNReal.ofReal (Real.exp (rf.1*q.1))*rf.2 q.2* + markedDistinctMoment rs (Measure.dirac p+η) (Fin.cons q.1 z)) := by + have hF : Measurable (fun q : ℝ × S => ENNReal.ofReal (Real.exp (rf.1*q.1))*rf.2 q.2) := + (by fun_prop : Measurable (fun q : ℝ × S => ENNReal.ofReal (Real.exp (rf.1*q.1)))).mul + ((hr rf (by simp)).comp measurable_snd) + exact measurable_const.ite (cascadeMeasurableSet_exists fun i => + measurableSet_eq_fun measurable_const measurable_fst) + (hF.mul ((markedDistinctMoment_measurable rs ht (m+1)).comp + (measurable_const.prodMk (measurable_fin_cons measurable_fst measurable_const)))) + rw [markedDistinctMoment,markedStableCountKernel_add_dirac η p hf hp, + lintegral_add_measure,lintegral_dirac' _ hm,ite_eq_left hz,zero_add, + markedDistinctMoment,markedStableCountKernel_eq η hf hp] + apply lintegral_congr + intro q + split_ifs + · rfl + · rw [ih ht (Fin.cons q.1 z) (by obtain ⟨i,hi⟩ := hz; exact ⟨i.succ,hi⟩)] + +lemma markedDistinctMoment_palm_laplace (ν : Measure S) [IsProbabilityMeasure ν] + {b t : ℝ} (hb : 0 < b) (hb1 : b < 1) (ht : 0 < t) + (rs : List (ℝ × (S → ℝ≥0∞))) (hr : ∀ rf ∈ rs, b < rf.1) + (hm : ∀ rf ∈ rs, Measurable rf.2) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, markedDistinctMoment rs η z*ENNReal.ofReal (Real.exp (-t*markedStableTotal η)) + ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) = + ((rs.map (fun rf => ENNReal.ofReal (b*t^(b-rf.1)*Real.Gamma (rf.1-b))*(∫⁻ c, rf.2 c ∂ν))).prod)* + ENNReal.ofReal (Real.exp (-Real.Gamma (1-b)*t^b)) := by + induction rs generalizing m with + | nil => simpa [markedDistinctMoment] using markedStable_laplace ν hb hb1 ht + | cons rf rs ih => + have hmt : ∀ r ∈ rs, Measurable r.2 := fun r hr' => hm r (List.mem_cons_of_mem rf hr') + let P := poissonRandomMeasureLaw ((stableLogIntensity b).prod ν) + let L := ENNReal.ofReal (Real.exp (-Real.Gamma (1-b)*t^b)) + let C := (rs.map (fun r => ENNReal.ofReal (b*t^(b-r.1)*Real.Gamma (r.1-b))*(∫⁻ c, r.2 c ∂ν))).prod + let H : Measure (ℝ × S) × (ℝ × S) → ℝ≥0∞ := fun p => if ∃ i, z i = p.2.1 then 0 else + ENNReal.ofReal (Real.exp (rf.1*p.2.1))*rf.2 p.2.2* + markedDistinctMoment rs p.1 (Fin.cons p.2.1 z)* + ENNReal.ofReal (Real.exp (-t*markedStableTotal p.1)) + have hH : Measurable H := by + have hD : Measurable (fun p : Measure (ℝ × S) × (ℝ × S) => + markedDistinctMoment rs p.1 (Fin.cons p.2.1 z)) := + (markedDistinctMoment_measurable rs hmt (m+1)).comp (measurable_fst.prodMk + (measurable_fin_cons measurable_snd.fst measurable_const)) + have hF : Measurable (fun p : Measure (ℝ × S) × (ℝ × S) => + ENNReal.ofReal (Real.exp (rf.1*p.2.1))*rf.2 p.2.2) := + (by fun_prop : Measurable (fun p : Measure (ℝ × S) × (ℝ × S) => ENNReal.ofReal (Real.exp (rf.1*p.2.1)))).mul + ((hm rf (by simp)).comp measurable_snd.snd) + exact measurable_const.ite (cascadeMeasurableSet_exists fun i => + measurableSet_eq_fun measurable_const measurable_snd.fst) ((hF.mul hD).mul (by fun_prop)) + have hstart : (∫⁻ η, markedDistinctMoment (rf::rs) η z* + ENNReal.ofReal (Real.exp (-t*markedStableTotal η)) ∂P) = + ∫⁻ η, ∫⁻ p, H (η,p) ∂η ∂P := by + apply lintegral_congr_ae + filter_upwards [markedStable_regular ν hb hb1] with η hη + rw [markedDistinctMoment,markedStableCountKernel_eq η hη.1 hη.2, + ← lintegral_mul_const' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro p + dsimp [H] + split_ifs <;> simp + have hinner (p : ℝ × S) : (∫⁻ η, H (Measure.dirac p+η,p) ∂P) = + (if ∃ i, z i = p.1 then 0 else ENNReal.ofReal (Real.exp (rf.1*p.1)*Real.exp (-t*Real.exp p.1))*rf.2 p.2)*(C*L) := by + by_cases hx : ∃ i, z i = p.1 + · simp [H,hx] + have he : (fun η => H (Measure.dirac p+η,p)) =ᵐ[P] + (fun η => (ENNReal.ofReal (Real.exp (rf.1*p.1)*Real.exp (-t*Real.exp p.1))*rf.2 p.2)* + (markedDistinctMoment rs η (Fin.cons p.1 z)*ENNReal.ofReal (Real.exp (-t*markedStableTotal η)))) := by + filter_upwards [markedStable_regular ν hb hb1] with η hη + dsimp [H] + rw [ite_eq_right hx,markedDistinctMoment_add_dirac rs hmt η p hη.1 hη.2 + (Fin.cons p.1 z) ⟨0,rfl⟩,markedStableTotal_add_dirac p η hη.1,mul_add,Real.exp_add, + ENNReal.ofReal_mul (Real.exp_pos _).le,ENNReal.ofReal_mul (Real.exp_pos _).le] + ring + have hM : Measurable (fun η => markedDistinctMoment rs η (Fin.cons p.1 z)* + ENNReal.ofReal (Real.exp (-t*markedStableTotal η))) := + ((markedDistinctMoment_measurable rs hmt (m+1)).comp (measurable_id.prodMk measurable_const)).mul (by fun_prop) + rw [lintegral_congr_ae he,lintegral_const_mul _ hM, + ih (fun r hr' => hr r (List.mem_cons_of_mem rf hr')) hmt (Fin.cons p.1 z),ite_eq_right hx] + rw [hstart,poissonRandomMeasureLaw_mecke _ hH] + change (∫⁻ p, ∫⁻ η, H (Measure.dirac p+η,p) ∂P ∂(stableLogIntensity b).prod ν) = _ + simp_rw [hinner] + rw [lintegral_mul_const] + · have hx : ∀ᵐ x ∂stableLogIntensity b, ¬ ∃ i, z i = x := by + filter_upwards [ae_all_iff.mpr (fun i : Fin m => (stableLogIntensity b).ae_ne (z i))] with x hx + exact fun h => by obtain ⟨i,hi⟩ := h; exact hx i hi.symm + have hp : ∀ᵐ p ∂(stableLogIntensity b).prod ν, ¬ ∃ i, z i = p.1 := + (measurePreserving_fst (μ := stableLogIntensity b) (ν := ν)).quasiMeasurePreserving.ae hx + rw [lintegral_congr_ae (hp.mono fun p hp => ite_eq_right hp),lintegral_prod_mul (f := fun x : ℝ => ENNReal.ofReal (Real.exp (rf.1*x)*Real.exp (-t*Real.exp x))) + (g := rf.2) (by fun_prop) (hm rf (by simp)).aemeasurable, + stableLogIntensity_laplace_moment hb.le (hr rf (by simp)) ht] + simp only [List.map_cons,List.prod_cons] + dsimp [C,L] + ring + · exact measurable_const.ite (cascadeMeasurableSet_exists fun i => + measurableSet_eq_fun measurable_const measurable_fst) + ((by fun_prop : Measurable (fun p : ℝ × S => ENNReal.ofReal (Real.exp (rf.1*p.1)*Real.exp (-t*Real.exp p.1)))).mul ((hm rf (by simp)).comp measurable_snd)) + +lemma markedDistinctMoment_laplace_factor (ν : Measure S) [IsProbabilityMeasure ν] + {b t : ℝ} (hb : 0 < b) (hb1 : b < 1) (ht : 0 < t) + (rs : List (ℝ × (S → ℝ≥0∞))) (hr : ∀ rf ∈ rs, b < rf.1) + (hm : ∀ rf ∈ rs, Measurable rf.2) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, markedDistinctMoment rs η z*ENNReal.ofReal (Real.exp (-t*markedStableTotal η)) + ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) = + (rs.map (fun rf => ∫⁻ c, rf.2 c ∂ν)).prod* + (∫⁻ η, stableDistinctMoment (rs.map Prod.fst) η z*ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η)) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) := by + rw [markedDistinctMoment_palm_laplace ν hb hb1 ht rs hr hm, + stableDistinctMoment_palm_laplace hb hb1 ht (rs.map Prod.fst) + (by intro r hr'; obtain ⟨rf,hmem,rfl⟩ := List.mem_map.mp hr'; exact hr rf hmem)] + simp only [List.prod_map_mul,List.map_map,Function.comp_def] + ring + +omit [Nonempty S] in +lemma mellin_weighted_identity (μ : Measure S) [SFinite μ] {D : S → ℝ≥0∞} {T : S → ℝ} + (hD : Measurable D) (hT : Measurable T) (hpos : ∀ᵐ x ∂μ, 0 < T x) {q : ℝ} (hq : 0 < q) : + (∫⁻ x, D x*ENNReal.ofReal (T x^(-q)) ∂μ)*ENNReal.ofReal (Real.Gamma q) = + ∫⁻ t : ℝ in Ioi 0, ENNReal.ofReal (t^(q-1))* + (∫⁻ x, D x*ENNReal.ofReal (Real.exp (-t*T x)) ∂μ) := by + have hm : Measurable (fun p : S × ℝ => D p.1*ENNReal.ofReal (p.2^(q-1)*Real.exp (-p.2*T p.1))) := + (hD.comp measurable_fst).mul (by fun_prop) + calc + _ = ∫⁻ x, D x*ENNReal.ofReal (T x^(-q))*ENNReal.ofReal (Real.Gamma q) ∂μ := + (lintegral_mul_const' _ _ ENNReal.ofReal_ne_top).symm + _ = ∫⁻ x, (∫⁻ t : ℝ in Ioi 0, D x*ENNReal.ofReal (t^(q-1)*Real.exp (-t*T x))) ∂μ := by + apply lintegral_congr_ae + filter_upwards [hpos] with x hx + rw [lintegral_const_mul _ (by fun_prop),gamma_lintegral_positive_scale hq hx, + ENNReal.ofReal_mul (Real.rpow_nonneg hx.le _),mul_assoc] + _ = ∫⁻ t : ℝ in Ioi 0, ∫⁻ x, D x*ENNReal.ofReal (t^(q-1)*Real.exp (-t*T x)) ∂μ := + lintegral_lintegral_swap hm.aemeasurable + _ = _ := by + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + simp_rw [ENNReal.ofReal_mul (Real.rpow_nonneg ht.le _),show ∀ x, + D x*(ENNReal.ofReal (t^(q-1))*ENNReal.ofReal (Real.exp (-t*T x))) = + ENNReal.ofReal (t^(q-1))*(D x*ENNReal.ofReal (Real.exp (-t*T x))) from fun x => by ring] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + +lemma markedDistinctMoment_mellin_factor (ν : Measure S) [IsProbabilityMeasure ν] + {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) + (rs : List (ℝ × (S → ℝ≥0∞))) (hne : rs ≠ []) (hr : ∀ rf ∈ rs, b < rf.1) + (hm : ∀ rf ∈ rs, Measurable rf.2) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, markedDistinctMoment rs η z*ENNReal.ofReal (markedStableTotal η^(a-(rs.map Prod.fst).sum)) + ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) = + (rs.map (fun rf => ∫⁻ c, rf.2 c ∂ν)).prod* + (∫⁻ η, stableDistinctMoment (rs.map Prod.fst) η z*ENNReal.ofReal (stablePoissonTotal η^(a-(rs.map Prod.fst).sum)) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) := by + let q := (rs.map Prod.fst).sum-a + have hrr : ∀ r ∈ rs.map Prod.fst, b < r := by + intro r hr'; obtain ⟨rf,hmem,rfl⟩ := List.mem_map.mp hr'; exact hr rf hmem + have hj : (1:ℝ) ≤ rs.length := by + have hj : 1 ≤ rs.length := by cases rs <;> simp_all + exact_mod_cast hj + have hq : 0 < q := by + have hs := list_length_mul_le_sum (fun r hr' => (hrr r hr').le) + simp only [List.length_map] at hs + dsimp [q]; nlinarith + have hG0 : ENNReal.ofReal (Real.Gamma q) ≠ 0 := + ENNReal.ofReal_ne_zero_iff.mpr (Real.Gamma_pos_of_pos hq) + have hDm : Measurable (fun η => markedDistinctMoment rs η z) := + (markedDistinctMoment_measurable rs hm m).comp (measurable_id.prodMk measurable_const) + have hDu : Measurable (fun η => stableDistinctMoment (rs.map Prod.fst) η z) := + (stableDistinctMoment_measurable (rs.map Prod.fst) m).comp (measurable_id.prodMk measurable_const) + have h1 := mellin_weighted_identity _ hDm markedStableTotal_measurable + ((markedStable_regular ν hb hb1).mono fun _ h => h.2) hq + have h2 := mellin_weighted_identity _ hDu stablePoissonTotal_measurable (stablePoissonTotal_pos hb hb1) hq + have hneg : -q = a-(rs.map Prod.fst).sum := by dsimp [q]; ring + rw [hneg] at h1 h2 + apply (ENNReal.mul_left_inj hG0 ENNReal.ofReal_ne_top).mp + rw [h1,mul_assoc,h2] + have hmeas : Measurable (fun t : ℝ => ENNReal.ofReal (t^(q-1))* + (∫⁻ η, stableDistinctMoment (rs.map Prod.fst) η z*ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η)) + ∂poissonRandomMeasureLaw (stableLogIntensity b))) := by + apply (by fun_prop : Measurable (fun t : ℝ => ENNReal.ofReal (t^(q-1)))).mul + have hM : Measurable (fun p : ℝ × Measure ℝ => stableDistinctMoment (rs.map Prod.fst) p.2 z* + ENNReal.ofReal (Real.exp (-p.1*stablePoissonTotal p.2))) := (hDu.comp measurable_snd).mul (by fun_prop) + exact hM.lintegral_prod_right + rw [← lintegral_const_mul _ hmeas] + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + rw [markedDistinctMoment_laplace_factor ν hb hb1 ht rs hr hm] + ring + +def markedTotalBiasedLaw (ν : Measure S) [IsProbabilityMeasure ν] (a b : ℝ) : Measure (Measure (ℝ × S)) := + normalizedMeasure ((poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).withDensity + (fun η => ENNReal.ofReal (markedStableTotal η^a))) + +lemma markedStableTotal_momentE (ν : Measure S) [IsProbabilityMeasure ν] (a b : ℝ) : + (∫⁻ η, ENNReal.ofReal (markedStableTotal η^a) ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) = + ∫⁻ η, ENNReal.ofReal (stablePoissonTotal η^a) ∂poissonRandomMeasureLaw (stableLogIntensity b) := by + rw [← markedStable_project_law ν b, + lintegral_map (by fun_prop) (Measure.measurable_map _ measurable_fst)] + simp only [markedStableTotal_projection] + +lemma markedTotalBiasedLaw_probability (ν : Measure S) [IsProbabilityMeasure ν] + {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) : + IsProbabilityMeasure (markedTotalBiasedLaw ν a b) := by + have hmass : ((poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).withDensity + (fun η => ENNReal.ofReal (markedStableTotal η^a))) univ = + ((poissonRandomMeasureLaw (stableLogIntensity b)).withDensity + (fun η => ENNReal.ofReal (stablePoissonTotal η^a))) univ := by + simp only [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + exact markedStableTotal_momentE ν a b + have hp : 0 < Real.Gamma (1-a/b)*(Real.Gamma (1-b))^(a/b)/Real.Gamma (1-a) := by + apply div_pos (mul_pos (Real.Gamma_pos_of_pos ?_) (Real.rpow_pos_of_pos (Real.Gamma_pos_of_pos (by linarith)) _)) + (Real.Gamma_pos_of_pos (by linarith)) + have := (div_lt_one hb).mpr ha + linarith + apply normalizedMeasure_probability + · rw [hmass,stableTotalBias_mass hb hb1 ha]; exact ENNReal.ofReal_ne_zero_iff.mpr hp + · rw [hmass,stableTotalBias_mass hb hb1 ha]; exact ENNReal.ofReal_ne_top + +def markedOrderedDistinctMass (rs : List (ℝ × (S → ℝ≥0∞))) (η : Measure (ℝ × S)) {m : ℕ} (z : Fin m → ℝ) : ℝ≥0∞ := + markedDistinctMoment rs η z*ENNReal.ofReal (markedStableTotal η^(-(rs.map Prod.fst).sum)) + +omit [Nonempty S] in +lemma markedOrderedDistinctMass_measurable (rs : List (ℝ × (S → ℝ≥0∞))) + (hm : ∀ rf ∈ rs, Measurable rf.2) {m : ℕ} (z : Fin m → ℝ) : + Measurable (fun η => markedOrderedDistinctMass rs η z) := + ((markedDistinctMoment_measurable rs hm m).comp (measurable_id.prodMk measurable_const)).mul (by fun_prop) + +lemma markedOrderedDistinctMass_biased (ν : Measure S) [IsProbabilityMeasure ν] + {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (rs : List (ℝ × (S → ℝ≥0∞))) + (hm : ∀ rf ∈ rs, Measurable rf.2) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, markedOrderedDistinctMass rs η z ∂markedTotalBiasedLaw ν a b) = + (∫⁻ η, markedDistinctMoment rs η z*ENNReal.ofReal (markedStableTotal η^(a-(rs.map Prod.fst).sum)) + ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν))/ + (∫⁻ η, ENNReal.ofReal (markedStableTotal η^a) + ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) := by + unfold markedTotalBiasedLaw normalizedMeasure + rw [lintegral_smul_measure,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (markedOrderedDistinctMass_measurable rs hm z)] + simp only [smul_eq_mul,Pi.mul_apply] + rw [div_eq_mul_inv,mul_comm] + congr 1 + apply lintegral_congr_ae + filter_upwards [markedStable_regular ν hb hb1] with η hη + unfold markedOrderedDistinctMass + calc + _ = markedDistinctMoment rs η z*(ENNReal.ofReal (markedStableTotal η^a)* + ENNReal.ofReal (markedStableTotal η^(-(rs.map Prod.fst).sum))) := by ring + _ = _ := by rw [← ENNReal.ofReal_mul (Real.rpow_nonneg hη.2.le _),← Real.rpow_add hη.2,sub_eq_add_neg] + +lemma markedOrderedDistinctMass_eppf (ν : Measure S) [IsProbabilityMeasure ν] + {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) + (rs : List (ℝ × (S → ℝ≥0∞))) (hne : rs ≠ []) (hr : ∀ rf ∈ rs, b < rf.1) + (hm : ∀ rf ∈ rs, Measurable rf.2) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, markedOrderedDistinctMass rs η z ∂markedTotalBiasedLaw ν a b) = + (rs.map (fun rf => ∫⁻ c, rf.2 c ∂ν)).prod* + ENNReal.ofReal (Real.Gamma (1-a)/Real.Gamma ((rs.map Prod.fst).sum-a)* + (∏ ℓ ∈ Finset.range (rs.length-1), (((ℓ:ℝ)+1)*b-a))* + (rs.map (fun rf => Real.Gamma (rf.1-b)/Real.Gamma (1-b))).prod) := by + rw [markedOrderedDistinctMass_biased ν hb hb1 rs hm z, + markedDistinctMoment_mellin_factor ν hb hb1 ha rs hne hr hm, + markedStableTotal_momentE ν a b,mul_div_assoc,stableDistinctMoment_eppf hb hb1 ha (rs.map Prod.fst) + (by simpa using hne) (by intro r hr'; obtain ⟨rf,hmem,rfl⟩ := List.mem_map.mp hr'; exact hr rf hmem)] + simp only [List.length_map,List.map_map,Function.comp_def] + +omit [Nonempty S] in +lemma normalizedMeasure_map {A : Type*} [MeasurableSpace A] (μ : Measure S) + {f : S → A} (hf : Measurable f) : + (normalizedMeasure μ).map f = normalizedMeasure (μ.map f) := by + simp only [normalizedMeasure,Measure.map_smul _ hf.aemeasurable, + Measure.map_apply hf MeasurableSet.univ,Set.preimage_univ] + +omit [Nonempty S] in +lemma markedStableMassKernel_projection (η : Measure (ℝ × S)) : + (markedStableMassKernel η).map Prod.fst = stableMassKernel (η.map Prod.fst) := by + change (normalizedMeasure (η.withDensity (fun p : ℝ × S => ENNReal.ofReal (Real.exp p.1)))).map Prod.fst = + normalizedMeasure ((η.map Prod.fst).withDensity (fun x => ENNReal.ofReal (Real.exp x))) + rw [normalizedMeasure_map _ measurable_fst,map_withDensity_comp η measurable_fst (by fun_prop)] + rfl + +def markedBlockProbability : List (ℕ × (S → ℝ≥0∞)) → {m : ℕ} → Measure (ℝ × S) → (Fin m → ℝ) → ℝ≥0∞ + | [], _, _, _ => 1 + | nf::ns, _, η, z => ∫⁻ p, if ∃ i, z i = p.1 then 0 else + (stableMassKernel (η.map Prod.fst) {p.1})^(nf.1-1)*nf.2 p.2* + markedBlockProbability ns η (Fin.cons p.1 z) ∂markedStableMassKernel η + +omit [Nonempty S] in +lemma markedBlockProbability_measurable (ns : List (ℕ × (S → ℝ≥0∞))) + (hm : ∀ nf ∈ ns, Measurable nf.2) (m : ℕ) : + Measurable (fun p : Measure (ℝ × S) × (Fin m → ℝ) => markedBlockProbability ns p.1 p.2) := by + induction ns generalizing m with + | nil => exact measurable_const + | cons nf ns ih => + let κ : Kernel (Measure (ℝ × S) × (Fin m → ℝ)) (ℝ × S) := markedStableMassKernel.comap + (Prod.fst : Measure (ℝ × S) × (Fin m → ℝ) → Measure (ℝ × S)) measurable_fst + have hD : Measurable (fun p : (Measure (ℝ × S) × (Fin m → ℝ)) × (ℝ × S) => + markedBlockProbability ns p.1.1 (Fin.cons p.2.1 p.1.2)) := by + exact (ih (fun r hr' => hm r (List.mem_cons_of_mem nf hr')) (m+1)).comp + (measurable_fst.fst.prodMk (measurable_fin_cons measurable_snd.fst measurable_fst.snd)) + have ha : Measurable (fun p : (Measure (ℝ × S) × (Fin m → ℝ)) × (ℝ × S) => + stableMassKernel (p.1.1.map Prod.fst) {p.2.1}) := + stableMassAtom_measurable_comp ((Measure.measurable_map _ measurable_fst).comp measurable_fst.fst) measurable_snd.fst + have hset : MeasurableSet {p : (Measure (ℝ × S) × (Fin m → ℝ)) × (ℝ × S) | ∃ i, p.1.2 i = p.2.1} := by + exact cascadeMeasurableSet_exists fun i => measurableSet_eq_fun (by fun_prop) measurable_snd.fst + exact (measurable_const.ite hset (((ha.pow_const _).mul ((hm nf (by simp)).comp measurable_snd.snd)).mul hD)).lintegral_kernel_prod_right' (κ := κ) + +omit [Nonempty S] in +lemma markedBlockProbability_moment (ns : List (ℕ × (S → ℝ≥0∞))) + (hn : ∀ nf ∈ ns, 1 ≤ nf.1) (hm : ∀ nf ∈ ns, Measurable nf.2) (η : Measure (ℝ × S)) + (hf : markedStableTotalE η ≠ ⊤) (hp : 0 < markedStableTotal η) + (hs : ∀ᵐ x ∂η.map Prod.fst, (η.map Prod.fst) {x} = 1) {m : ℕ} (z : Fin m → ℝ) : + markedBlockProbability ns η z = markedDistinctMoment (ns.map (fun nf => ((nf.1:ℝ),nf.2))) η z* + ((ENNReal.ofReal (markedStableTotal η))⁻¹)^(ns.map Prod.fst).sum := by + induction ns generalizing m with + | nil => simp [markedBlockProbability,markedDistinctMoment] + | cons nf ns ih => + have hn0 : 1 ≤ nf.1 := hn nf (by simp) + have hn' : nf.1-1+1 = nf.1 := Nat.sub_add_cancel hn0 + have hns : ∀ k ∈ ns, 1 ≤ k.1 := fun k hk => hn k (by simp [hk]) + have hmt : ∀ k ∈ ns, Measurable k.2 := fun k hk => hm k (by simp [hk]) + have ha : Measurable (fun p : ℝ × S => stableMassKernel (η.map Prod.fst) {p.1}) := + stableMassAtom_measurable_comp measurable_const measurable_fst + have hmeas : Measurable (fun p : ℝ × S => if ∃ i, z i = p.1 then (0:ℝ≥0∞) else + (stableMassKernel (η.map Prod.fst) {p.1})^(nf.1-1)*nf.2 p.2* + markedBlockProbability ns η (Fin.cons p.1 z)) := by + exact measurable_const.ite (cascadeMeasurableSet_exists fun i => + measurableSet_eq_fun measurable_const measurable_fst) + (((ha.pow_const _).mul ((hm nf (by simp)).comp measurable_snd)).mul + ((markedBlockProbability_measurable ns hmt (m+1)).comp + (measurable_const.prodMk (measurable_fin_cons measurable_fst measurable_const)))) + have htotal : (η.withDensity (fun p : ℝ × S => ENNReal.ofReal (Real.exp p.1))) univ = + ENNReal.ofReal (markedStableTotal η) := by + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + exact (ENNReal.ofReal_toReal hf).symm + unfold markedBlockProbability + change (∫⁻ p, (if ∃ i, z i = p.1 then 0 else (stableMassKernel (η.map Prod.fst) {p.1})^(nf.1-1)*nf.2 p.2* + markedBlockProbability ns η (Fin.cons p.1 z)) ∂normalizedMeasure + (η.withDensity (fun p => ENNReal.ofReal (Real.exp p.1)))) = _ + rw [normalizedMeasure,lintegral_smul_measure,htotal, + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) hmeas] + simp only [smul_eq_mul,Pi.mul_apply] + rw [← lintegral_const_mul' _ _ (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr hp))] + have hpoint : (fun p : ℝ × S => (ENNReal.ofReal (markedStableTotal η))⁻¹ * + (ENNReal.ofReal (Real.exp p.1)*(if ∃ i, z i = p.1 then 0 else + (stableMassKernel (η.map Prod.fst) {p.1})^(nf.1-1)*nf.2 p.2*markedBlockProbability ns η (Fin.cons p.1 z)))) =ᵐ[η] + (fun p : ℝ × S => (if ∃ i, z i = p.1 then 0 else ENNReal.ofReal (Real.exp ((nf.1:ℝ)*p.1))*nf.2 p.2* + markedDistinctMoment (ns.map (fun nf => ((nf.1:ℝ),nf.2))) η (Fin.cons p.1 z))* + ((ENNReal.ofReal (markedStableTotal η))⁻¹)^(nf.1+(ns.map Prod.fst).sum)) := by + filter_upwards [ae_of_ae_map measurable_fst.aemeasurable hs] with p hx + split_ifs + · simp + · rw [stableMassKernel_atom_eq (η.map Prod.fst) (by simpa [← markedStableTotalE_projection] using hf) + (by simpa [← markedStableTotal_projection] using hp) hx,← markedStableTotal_projection, + ENNReal.ofReal_div_of_pos hp,ih hns hmt (Fin.cons p.1 z),div_eq_mul_inv,mul_pow, + Real.exp_nat_mul,ENNReal.ofReal_pow (Real.exp_pos _).le,pow_add,← hn',pow_succ] + simp only [Nat.add_sub_cancel] + ring + rw [lintegral_congr_ae hpoint,lintegral_mul_const' _ _ (ENNReal.pow_ne_top + (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr hp)))] + simp only [List.map_cons,List.sum_cons] + rw [markedDistinctMoment,markedStableCountKernel_eq η hf hp] + +omit [Nonempty S] in +lemma markedBlockProbability_ordered (ns : List (ℕ × (S → ℝ≥0∞))) + (hn : ∀ nf ∈ ns, 1 ≤ nf.1) (hm : ∀ nf ∈ ns, Measurable nf.2) (η : Measure (ℝ × S)) + (hf : markedStableTotalE η ≠ ⊤) (hp : 0 < markedStableTotal η) + (hs : ∀ᵐ x ∂η.map Prod.fst, (η.map Prod.fst) {x} = 1) {m : ℕ} (z : Fin m → ℝ) : + markedBlockProbability ns η z = markedOrderedDistinctMass (ns.map (fun nf => ((nf.1:ℝ),nf.2))) η z := by + rw [markedBlockProbability_moment ns hn hm η hf hp hs] + unfold markedOrderedDistinctMass + congr 1 + rw [Real.rpow_neg hp.le,ENNReal.ofReal_inv_of_pos (Real.rpow_pos_of_pos hp _)] + have hsum : ((ns.map (fun nf => ((nf.1:ℝ),nf.2))).map Prod.fst).sum = ((ns.map Prod.fst).sum:ℝ) := by + simpa only [List.map_map,Function.comp_def] using + (Nat.cast_list_sum (R := ℝ) (ns.map Prod.fst)).symm + rw [hsum,Real.rpow_natCast,ENNReal.ofReal_pow hp.le,ENNReal.inv_pow] + +lemma markedTotalBiasedLaw_absolutelyContinuous (ν : Measure S) [IsProbabilityMeasure ν] (a b : ℝ) : + markedTotalBiasedLaw ν a b ≪ poissonRandomMeasureLaw ((stableLogIntensity b).prod ν) := by + exact Measure.smul_absolutelyContinuous.trans (withDensity_absolutelyContinuous _ _) + +lemma markedBlockProbability_factor (ν : Measure S) [IsProbabilityMeasure ν] + {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) + (ns : List (ℕ × (S → ℝ≥0∞))) (hne : ns ≠ []) (hn : ∀ nf ∈ ns, 1 ≤ nf.1) + (hm : ∀ nf ∈ ns, Measurable nf.2) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, markedBlockProbability ns η z ∂markedTotalBiasedLaw ν a b) = + (ns.map (fun nf => ∫⁻ c, nf.2 c ∂ν)).prod* + (∫⁻ η, stableBlockProbability (ns.map Prod.fst) η z ∂stableTotalBiasedLaw a b) := by + have hr : ∀ rf ∈ ns.map (fun nf => ((nf.1:ℝ),nf.2)), b < rf.1 := by + intro rf hr + obtain ⟨nf,hmem,rfl⟩ := List.mem_map.mp hr + exact hb1.trans_le (by change (1:ℝ) ≤ (nf.1:ℝ); exact_mod_cast hn nf hmem) + have hm' : ∀ rf ∈ ns.map (fun nf => ((nf.1:ℝ),nf.2)), Measurable rf.2 := by + intro rf hr + obtain ⟨nf,hmem,rfl⟩ := List.mem_map.mp hr + exact hm nf hmem + have he := markedOrderedDistinctMass_eppf ν hb hb1 ha (ns.map (fun nf => ((nf.1:ℝ),nf.2))) + (by simpa using hne) hr hm' z + have hpres : MeasurePreserving (Measure.map (Prod.fst : ℝ × S → ℝ)) + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) + (poissonRandomMeasureLaw (stableLogIntensity b)) := + ⟨Measure.measurable_map _ measurable_fst,markedStable_project_law ν b⟩ + have hs := hpres.quasiMeasurePreserving.ae (stablePoissonCount_simple hb hb1) + have hae : (fun η => markedBlockProbability ns η z) =ᵐ[markedTotalBiasedLaw ν a b] + (fun η => markedOrderedDistinctMass (ns.map (fun nf => ((nf.1:ℝ),nf.2))) η z) := by + apply (markedTotalBiasedLaw_absolutelyContinuous ν a b).ae_eq + filter_upwards [markedStable_regular ν hb hb1,hs] with η hf hs + exact markedBlockProbability_ordered ns hn hm η hf.1 hf.2 hs z + rw [lintegral_congr_ae hae,he,stableBlockProbability_eppf hb hb1 ha (ns.map Prod.fst) + (by simpa using hne) (by intro n hn'; obtain ⟨nf,hmem,rfl⟩ := List.mem_map.mp hn'; exact hn nf hmem)] + simp only [List.map_map,Function.comp_def,List.length_map] + +omit [Nonempty S] in +lemma markedStableTotal_map_shift (η : Measure (ℝ × S)) {F : S → ℝ} (hF : Measurable F) : + markedStableTotal (η.map (logMarkShift F)) = poissonWeightedTotal F η := by + unfold markedStableTotal markedStableTotalE poissonWeightedTotal + rw [lintegral_map (by fun_prop) (logMarkShift_measurable hF)] + rfl + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/MarkedVariance.lean b/lean/OAI/Probability/Perceptron/Variational/MarkedVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..561f97af50c322f07edc129b9c83f9b20b80fd54 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/MarkedVariance.lean @@ -0,0 +1,188 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CompactTripleGG + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory Set ProbabilityTheory +open scoped BoundedContinuousFunction NNReal ContDiff + +lemma bounded_continuous_test_extend {Ω E : Type*} [MeasurableSpace Ω] + [MetricSpace E] [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] + (P : Measure Ω) [IsFiniteMeasure P] (p : Ω→E) (hp : Measurable p) + (Z : Ω→ℝ) (hZ : Measurable Z) {C : ℝ} (hC : 0≤C) (hb : ∀ x,|Z x|≤C) + (hz : ∀ F : E→ᵇℝ,(∫ x,F (p x)*Z x ∂P)=0) + (a : E→ℝ) (ha : Measurable a) {A : ℝ} (hA : 0≤A) (haB : ∀ r,|a r|≤A) : + (∫ x,a (p x)*Z x ∂P)=0 := by + have hmap : MeasurePreserving p P (P.map p) := ⟨hp,rfl⟩ + have hai : Integrable a (P.map p) := Integrable.of_bound ha.aestronglyMeasurable A + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using haB x) + have hap : Integrable (fun x => a (p x)*Z x) P := + Integrable.of_bound ((ha.comp hp).mul hZ).aestronglyMeasurable (A*C) + (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul (haB _) (hb x) (abs_nonneg _) hA) + have he : |∫ x,a (p x)*Z x ∂P|≤0 := by + apply le_of_forall_pos_le_add + intro ε hε + let δ := ε/(C+1) + have hδ : 0<δ := div_pos hε (by linarith) + obtain ⟨F,hF,hFi⟩ := hai.exists_boundedContinuous_integral_sub_le hδ + have hiF : Integrable (fun x => F (p x)*Z x) P := + Integrable.of_bound ((F.measurable.comp hp).mul hZ).aestronglyMeasurable (‖F‖*C) + (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul (F.norm_coe_le_norm _) (hb x) (abs_nonneg _) (norm_nonneg F)) + have hdif : Integrable (fun x => a (p x)-F (p x)) P := + hmap.integrable_comp_of_integrable (hai.sub hFi) + have hrep : (∫ x,a (p x)*Z x ∂P)=(∫ x,(a (p x)-F (p x))*Z x ∂P) := by + simp_rw [sub_mul] + rw [integral_sub hap hiF,hz F,sub_zero] + have happrox : (∫ x,|a (p x)-F (p x)| ∂P)≤δ := by + have hm := integral_map (μ := P) hp.aemeasurable ((ha.sub F.measurable).abs.aestronglyMeasurable) + change (∫ x, |a x - F x| ∂P.map p) = (∫ x, |a (p x) - F (p x)| ∂P) at hm + rw [←hm] + simpa only [Real.norm_eq_abs] using hF + have hbound : |∫ x,(a (p x)-F (p x))*Z x ∂P|≤(∫ x,|a (p x)-F (p x)| * C ∂P) := by + rw [←Real.norm_eq_abs] + apply norm_integral_le_of_norm_le (hdif.abs.mul_const C) + exact ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul_of_nonneg_left (hb x) (abs_nonneg _) + rw [hrep] + refine hbound.trans ?_ + rw [integral_mul_const] + have hmul := mul_le_mul_of_nonneg_right happrox hC + have hc : δ*(C+1)=ε := div_mul_cancel₀ ε (by linarith) + linarith + exact abs_nonpos_iff.mp he + +lemma marked_zero_variance {Ω E : Type*} [MeasurableSpace Ω] + [MetricSpace E] [MeasurableSpace E] [BorelSpace E] [SecondCountableTopology E] + (P : Measure Ω) [IsFiniteMeasure P] (p : Ω→E) (hp : Measurable p) + (b : Ω→ℝ) (hb : Measurable b) (a : E→ℝ) (ha : Measurable a) + {A B : ℝ} (hA : 0≤A) (hB : 0≤B) (haB : ∀ r,|a r|≤A) (hbB : ∀ x,|b x|≤B) + (hfirst : ∀ F : E→ᵇℝ,(∫ x,F (p x)*b x ∂P)=(∫ x,F (p x)*a (p x) ∂P)) + (hsecond : (∫ x,(b x)^2 ∂P)=(∫ x,(a (p x))^2 ∂P)) : + ∀ᵐ x ∂P,b x=a (p x) := by + let Z := fun x => b x-a (p x) + have hZm : Measurable Z := hb.sub (ha.comp hp) + have hZb (x) : |Z x|≤B+A := (abs_sub _ _).trans (add_le_add (hbB x) (haB _)) + have hi (F : E→ᵇℝ) : Integrable (fun x => F (p x)*b x) P := + Integrable.of_bound ((F.measurable.comp hp).mul hb).aestronglyMeasurable (‖F‖*B) + (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul (F.norm_coe_le_norm _) (hbB x) (abs_nonneg _) (norm_nonneg F)) + have hi' (F : E→ᵇℝ) : Integrable (fun x => F (p x)*a (p x)) P := + Integrable.of_bound ((F.measurable.comp hp).mul (ha.comp hp)).aestronglyMeasurable (‖F‖*A) + (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul (F.norm_coe_le_norm _) (haB _) (abs_nonneg _) (norm_nonneg F)) + have hz (F : E→ᵇℝ) : (∫ x,F (p x)*Z x ∂P)=0 := by + simp only [Z,mul_sub] + rw [integral_sub (hi F) (hi' F),hfirst F,sub_self] + have hcross := bounded_continuous_test_extend P p hp Z hZm (add_nonneg hB hA) hZb hz a ha hA haB + have hi2 : Integrable (fun x => (b x)^2) P := + Integrable.of_bound (hb.pow_const 2).aestronglyMeasurable (B^2) + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs,abs_pow] using pow_le_pow_left₀ (abs_nonneg _) (hbB x) 2) + have hi2' : Integrable (fun x => (a (p x))^2) P := + Integrable.of_bound ((ha.comp hp).pow_const 2).aestronglyMeasurable (A^2) + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs,abs_pow] using pow_le_pow_left₀ (abs_nonneg _) (haB _) 2) + have hiZ : Integrable (fun x => a (p x)*Z x) P := + Integrable.of_bound ((ha.comp hp).mul hZm).aestronglyMeasurable (A*(B+A)) + (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_mul] using mul_le_mul (haB _) (hZb x) (abs_nonneg _) hA) + have hiZ2 : Integrable (fun x => (Z x)^2) P := + Integrable.of_bound (hZm.pow_const 2).aestronglyMeasurable ((B+A)^2) + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs,abs_pow] using pow_le_pow_left₀ (abs_nonneg _) (hZb x) 2) + have hzero : (∫ x,(Z x)^2 ∂P)=0 := by + have he (x) : (Z x)^2=(b x)^2-(a (p x))^2-2*(a (p x)*Z x) := by dsimp [Z]; ring + simp_rw [he] + rw [integral_sub (show Integrable (fun x => (b x)^2-(a (p x))^2) P from hi2.sub hi2') (hiZ.const_mul 2),integral_sub hi2 hi2',integral_const_mul, + hsecond,hcross] + ring + have hh := (integral_eq_zero_iff_of_nonneg_ae (ae_of_all _ fun x => sq_nonneg (Z x)) hiZ2).mp hzero + filter_upwards [hh] with x hx + exact sub_eq_zero.mp (sq_eq_zero_iff.mp hx) + +lemma tangent_wronskian_test {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] (ν : Measure Time) [IsProbabilityMeasure ν] + (r s t : Ω→Time) (hr : Measurable r) (hs : Measurable s) (ht : Measurable t) + (hmarg : P.map r=ν) + (hlaws : P.map (fun x=>(r x,s x))=(1/2:ℝ≥0) • (ν.prod ν)+(1/2:ℝ≥0) • (ν.map fun x=>(x,x))) + (hlawt : P.map (fun x=>(r x,t x))=(1/2:ℝ≥0) • (ν.prod ν)+(1/2:ℝ≥0) • (ν.map fun x=>(x,x))) + (htri : ∀ᵐ x ∂P,UltrametricTriangle (r x:ℝ) (s x:ℝ) (t x:ℝ)) + (a : Time→ℝ) (ha : Measurable a) {A : ℝ} (hA : 0≤A) (hab : ∀ x,|a x|≤A) + (G : ℝ→ᵇℝ) : + (∫ x,G (r x)*((r x:ℝ)-a (r x)*(1-(r x:ℝ)^2)+2*a (s x)*((t x:ℝ)-(r x:ℝ)*(s x:ℝ))) ∂P)= + ∫ x,G x*((x:ℝ)-a x*sphereTail ν x+∫ y,sphereKernel x y*a y ∂ν) ∂ν := by + let H : Time×Time→ℝ := fun p=>G p.1*sphereKernel p.1 p.2*a p.2 + let J : Time×Time→ℝ := fun p=>G p.1*a p.1*max ((p.2:ℝ)-p.1) 0 + let B : Time→ℝ := fun x=>G x*((x:ℝ)-a x*(1-(x:ℝ)^2)) + have hH : Measurable H := by dsimp [H]; unfold sphereKernel; fun_prop + have hJ : Measurable J := by dsimp [J]; fun_prop + have hB : Measurable B := by dsimp [B]; fun_prop + have hbH (p : Time×Time) : |H p|≤‖G‖*A := by + dsimp [H] + rw [abs_mul,abs_mul] + have h := mul_le_mul (G.norm_coe_le_norm (p.1:ℝ)) (sphereKernel_abs_le_one p.1 p.2) (abs_nonneg _) (norm_nonneg G) + simp only [mul_one] at h + exact mul_le_mul h (hab _) (abs_nonneg _) (norm_nonneg G) + have hbJ (p : Time×Time) : |J p|≤‖G‖*A := by + dsimp [J] + rw [abs_mul,abs_mul] + have h := mul_le_mul (G.norm_coe_le_norm (p.1:ℝ)) (hab p.1) (abs_nonneg _) (norm_nonneg G) + simpa only [mul_one,Real.norm_eq_abs] using mul_le_mul h (time_pospart_le_one p.1 p.2) (abs_nonneg _) (mul_nonneg (norm_nonneg G) hA) + have hbB (x : Time) : |B x|≤‖G‖*(1+A) := by + have hx : |1-(x:ℝ)^2|≤1 := by + have hx2 : (x:ℝ)^2≤1 := by nlinarith [x.property.1,x.property.2] + rw [abs_of_nonneg (sub_nonneg.mpr hx2)] + nlinarith [sq_nonneg (x:ℝ)] + have habx : |a x*(1-(x:ℝ)^2)|≤A := by + rw [abs_mul] + simpa only [mul_one] using mul_le_mul (hab x) hx (abs_nonneg _) hA + have hb := (abs_sub (x:ℝ) (a x*(1-(x:ℝ)^2))).trans (add_le_add (time_abs_le_one x) habx) + exact (abs_mul _ _).le.trans (mul_le_mul (G.norm_coe_le_norm _) hb (abs_nonneg _) (norm_nonneg G)) + have hiHp := boundedAbs_integrable P (fun x=>H (r x,s x)) (hH.comp (hr.prodMk hs)) _ (fun x=>hbH _) + have hiJp := boundedAbs_integrable P (fun x=>J (r x,t x)) (hJ.comp (hr.prodMk ht)) _ (fun x=>hbJ _) + have hiBp := boundedAbs_integrable P (fun x=>B (r x)) (hB.comp hr) _ (fun x=>hbB _) + have hiB := boundedAbs_integrable ν B hB _ hbB + have hiH := boundedAbs_integrable (ν.prod ν) H hH _ hbH + have hiJ := boundedAbs_integrable (ν.prod ν) J hJ _ hbJ + have hiHd := boundedAbs_integrable ν (fun x=>H (x,x)) (hH.comp (measurable_id.prodMk measurable_id)) _ (fun x=>hbH _) + have hiJd := boundedAbs_integrable ν (fun x=>J (x,x)) (hJ.comp (measurable_id.prodMk measurable_id)) _ (fun x=>hbJ _) + have heH := two_edge_integral P ν r s hr hs hlaws H hH _ hbH + have heJ := two_edge_integral P ν r t hr ht hlawt J hJ _ hbJ + have heB : (∫ x,B (r x) ∂P)=∫ x,B x ∂ν := by + rw [←hmarg,integral_map hr.aemeasurable hB.aestronglyMeasurable] + have hiBH : Integrable (fun x=>B (r x)+2*H (r x,s x)) P := hiBp.add (hiHp.const_mul 2) + have hiHC : Integrable (fun x=>(∫ y,H (x,y) ∂ν)+H (x,x)) ν := hiH.integral_prod_left.add hiHd + have hiJC : Integrable (fun x=>(∫ y,J (x,y) ∂ν)+J (x,x)) ν := hiJ.integral_prod_left.add hiJd + have hiBC : Integrable (fun x=>B x+((∫ y,H (x,y) ∂ν)+H (x,x))) ν := hiB.add hiHC + calc + _ = ∫ x,B (r x)+2*H (r x,s x)+2*J (r x,t x) ∂P := by + apply integral_congr_ae + filter_upwards [htri] with x hx + have he := sphereKernel_tangent_algebra (r x) (s x) (t x) hx a + dsimp [B,H,J] + calc + _ = G (r x)*((r x:ℝ)-a (r x)*(1-(r x:ℝ)^2))+2*G (r x)*(a (s x)*((t x:ℝ)-(r x:ℝ)*(s x:ℝ))) := by ring + _ = _ := by rw [he]; ring + _ = (∫ x,B x ∂ν)+(∫ x,(∫ y,H (x,y) ∂ν)+H (x,x) ∂ν)+ + (∫ x,(∫ y,J (x,y) ∂ν)+J (x,x) ∂ν) := by + rw [integral_add hiBH (hiJp.const_mul 2), + integral_add hiBp (hiHp.const_mul 2),integral_const_mul,integral_const_mul, + heB,heH,heJ,integral_add hiH.integral_prod_left hiHd, + integral_add hiJ.integral_prod_left hiJd] + ring + _ = _ := by + rw [←integral_add hiB hiHC, + ←integral_add hiBC hiJC] + apply integral_congr_ae + filter_upwards [] with x + dsimp [B,H,J] + simp_rw [mul_assoc (G x),integral_const_mul] + rw [sphereTail_pospart] + simp only [sphereKernel,min_self,sub_self,max_self,mul_zero,add_zero] + ring + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/MeasurableVariance.lean b/lean/OAI/Probability/Perceptron/Variational/MeasurableVariance.lean new file mode 100644 index 0000000000000000000000000000000000000000..6765a0407dd8a9f40b73d6c8b796dfe50a78557c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/MeasurableVariance.lean @@ -0,0 +1,85 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.VarianceProdMemLp + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal +namespace SphericalPerceptronFreeEnergy +variable {X : Type} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [SecondCountableTopology X] [Nonempty X] + (μ : Measure X) [IsProbabilityMeasure μ] + +theorem variance_pi_le_of_measurable_bounded_differences (n : ℕ) {F : (Fin n → X) → ℝ} + (hF : Measurable F) {K c : ℝ} (hK : ∀ x, |F x| ≤ K) + (hdiff : ∀ x i y, |F (Function.update x i y) - F x| ≤ c) : + variance F (Measure.pi fun _ : Fin n => μ) ≤ (n : ℝ) * c ^ 2 := by + classical + induction n with + | zero => + rw [Measure.pi_of_empty] + simp + | succ n ih => + let ν := Measure.pi fun _ : Fin n => μ + let G : X × (Fin n → X) → ℝ := fun p => F (Fin.cons (α := fun _ => X) p.1 p.2) + have hG : Measurable G := hF.comp (measurableEmbedding_fin_cons (X := X) n).measurable + have hGK (p) : |G p| ≤ K := hK _ + have hA (x : X) : variance (fun y => G (x, y)) ν ≤ (n : ℝ) * c ^ 2 := by + apply ih (hG.comp (measurable_const.prodMk measurable_id)) (fun y => hGK (x,y)) + intro y i z + simpa only [G, Function.comp_apply, id_eq, Fin.cons_update] using hdiff (Fin.cons x y) i.succ z + have hHc : Measurable (fun x => ∫ y, G (x, y) ∂ν) := + hG.stronglyMeasurable.integral_prod_right'.measurable + have hHosc (x x' : X) : + |(∫ y, G (x, y) ∂ν) - ∫ y, G (x', y) ∂ν| ≤ c := by + have hi (x : X) : Integrable (fun y => G (x, y)) ν := + (integrable_const K).mono' + (hG.comp (measurable_const.prodMk measurable_id)).aestronglyMeasurable + (Filter.Eventually.of_forall fun y => hGK (x, y)) + rw [← integral_sub (hi x) (hi x')] + have hh : ∀ y, |G (x, y) - G (x', y)| ≤ c := by + intro y + have hu : Function.update (Fin.cons x' y) 0 x = Fin.cons (α := fun _ => X) x y := by + ext i + refine Fin.cases ?_ (fun j => ?_) i <;> simp + simpa only [G, hu] using hdiff (Fin.cons x' y) 0 x + simpa using norm_integral_le_of_norm_le_const + (μ := ν) (f := fun y => G (x,y) - G (x',y)) + (Filter.Eventually.of_forall hh) + have hpF : MemLp F 2 (Measure.pi fun _ : Fin (n+1) => μ) := + MemLp.of_bound hF.aestronglyMeasurable K (Filter.Eventually.of_forall hK) + have hpG : MemLp G 2 (μ.prod ν) := + MemLp.of_bound hG.aestronglyMeasurable K (Filter.Eventually.of_forall hGK) + have hHL : MemLp (fun x => ∫ y, G (x,y) ∂ν) 2 μ := + MemLp.of_bound hHc.aestronglyMeasurable K (ae_of_all _ fun x => by + simpa using norm_integral_le_of_norm_le_const (μ := ν) + (f := fun y => G (x,y)) (ae_of_all _ fun y => hGK (x,y))) + let x₀ : X := Classical.choice ‹Nonempty X› + have hHrange : ∀ᵐ x ∂μ, (∫ y, G (x,y) ∂ν) ∈ + Icc ((∫ y, G (x₀,y) ∂ν)-c) ((∫ y, G (x₀,y) ∂ν)+c) := by + exact ae_of_all _ fun x => by + have hh := abs_le.mp (hHosc x x₀) + constructor <;> linarith + have hB : variance (fun x => ∫ y, G (x,y) ∂ν) μ ≤ c^2 := by + convert variance_le_sq_of_bounded hHrange hHc.aemeasurable using 1 + ring + have hv := variance_prod_le_memLp μ ν hpG + (fun x => MemLp.of_bound (hG.comp (measurable_const.prodMk measurable_id)).aestronglyMeasurable + K (ae_of_all _ fun y => hGK (x,y))) hHL hA hB + rw [variance_eq_sub hpG] at hv + rw [variance_eq_sub hpF] + have hmean := (measurePreserving_fin_cons μ n).integral_comp + (measurableEmbedding_fin_cons (X := X) n) F + have hsquare := (measurePreserving_fin_cons μ n).integral_comp + (measurableEmbedding_fin_cons (X := X) n) (fun x => F x ^ 2) + change (∫ x, G x ∂μ.prod ν) = _ at hmean + change (∫ x, G x ^ 2 ∂μ.prod ν) = _ at hsquare + simp only [Pi.pow_apply] at hv ⊢ + rw [hsquare, hmean] at hv + simpa only [Nat.cast_add, Nat.cast_one, add_mul, one_mul, add_comm] using hv + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/NonlinearDirectionIBP.lean b/lean/OAI/Probability/Perceptron/Variational/NonlinearDirectionIBP.lean new file mode 100644 index 0000000000000000000000000000000000000000..2f6b90d77e46fdd6d72bcd4b7553cbc220503988 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/NonlinearDirectionIBP.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.CountableGaussianReplicaIBP +import OAI.Probability.Perceptron.Interpolation.NonlinearReplicaIBP + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma nonlinear_pattern_direction_ibp {m n : ℕ} (j : Fin n) (f : Jet3) + {v : Fin (m+1) → S → ℝ} {h : S → ℝ} {w : Fin (m+1) → (Fin n → S) → ℝ} + (hv : ∀ i, Measurable (v i)) (hh : Measurable h) (hw : ∀ i, Measurable (w i)) + {A C D : ℝ} (hA : 0 ≤ A) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hhA : ∀ x, |h x| ≤ A) (hvC : ∀ i x, |v i x| ≤ C) (hwD : ∀ i x, |w i x| ≤ D) : + let b := gaussianField (m+1) v + let H := fun g x => h x+f.f (b g x) + let K := fun (x : Fin n→S) y => ∑ i, w i x*v i y + (∫ g, gibbsReplicaMean μ (H g) n + (fun x => f.d1 (b g (x j))*(∑ i, g i*w i x)) + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫ g, gibbsReplicaMean μ (H g) n + (fun x => (∑ l, f.d1 (b g (x l))*f.d1 (b g (x j))*K x (x l))+ + f.d2 (b g (x j))*K x (x j)) - + n*gibbsReplicaMean μ (H g) (n+1) + (fun x => f.d1 (b g (x 0))*f.d1 (b g (x j.succ))*K (fun l => x l.succ) (x 0)) + ∂Measure.pi (fun _ => gaussianReal 0 1) := by + dsimp only + let γ := Measure.pi (fun _ : Fin (m+1) => gaussianReal 0 1) + let b := gaussianField (m+1) v + let H := fun g x => h x+f.f (b g x) + let F := fun i g (x : Fin n→S) => f.d1 (b g (x j))*w i x + let U := fun i g (x : Fin n→S) => + ((∑ l, f.d1 (b g (x l))*v i (x l))*f.d1 (b g (x j))+ + f.d2 (b g (x j))*v i (x j))*w i x + let V := fun i g (x : Fin (n+1)→S) => + f.d1 (b g (x 0))*v i (x 0)*(f.d1 (b g (x j.succ))*w i (fun l => x l.succ)) + have hb : Measurable (Function.uncurry b) := gaussianField_measurable hv + have hH : Measurable (Function.uncurry H) := + (hh.comp measurable_snd).add (f.f.continuous.measurable.comp hb) + have hHA (g x) : |H g x| ≤ A+‖f.f‖ := + (abs_add_le _ _).trans (add_le_add (hhA x) (f.f.norm_coe_le_norm _)) + have he (r : ℕ) (i : Fin r) : Measurable + (fun p : (Fin (m+1)→ℝ)×(Fin r→S) => b p.1 (p.2 i)) := + hb.comp (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd)) + have hFm (i) : Measurable (Function.uncurry (F i)) := + (f.d1.measurable.comp (he n j)).mul ((hw i).comp measurable_snd) + have hUm (i) : Measurable (Function.uncurry (U i)) := by + exact (((Finset.measurable_sum _ fun l _ => (f.d1.measurable.comp (he n l)).mul + ((hv i).comp ((measurable_pi_apply l).comp measurable_snd))).mul + (f.d1.measurable.comp (he n j))).add ((f.d2.measurable.comp (he n j)).mul + ((hv i).comp ((measurable_pi_apply j).comp measurable_snd)))).mul ((hw i).comp measurable_snd) + have hVm (i) : Measurable (Function.uncurry (V i)) := by + exact ((f.d1.measurable.comp (he (n+1) 0)).mul + ((hv i).comp ((measurable_pi_apply 0).comp measurable_snd))).mul + ((f.d1.measurable.comp (he (n+1) j.succ)).mul + ((hw i).comp ((Measurable.of_eval fun index : Fin n => measurable_pi_apply index.succ).comp measurable_snd))) + have hFB (i g x) : |F i g x| ≤ ‖f.d1‖*D := by + dsimp [F]; rw [abs_mul] + exact mul_le_mul (f.d1.norm_coe_le_norm _) (hwD i x) (abs_nonneg _) (norm_nonneg _) + have hsB (i g) (x : Fin n→S) : |∑ l, f.d1 (b g (x l))*v i (x l)| ≤ n*(‖f.d1‖*C) := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _ : Fin n, ‖f.d1‖*C := Finset.sum_le_sum fun l _ => by + rw [abs_mul]; exact mul_le_mul (f.d1.norm_coe_le_norm _) (hvC i _) (abs_nonneg _) (norm_nonneg _) + _ = _ := by simp + have hUB (i g x) : |U i g x| ≤ ((n:ℝ)*(‖f.d1‖*C)*‖f.d1‖+‖f.d2‖*C)*D := by + dsimp only [U]; rw [abs_mul] + apply mul_le_mul _ (hwD i x) (abs_nonneg _) (by positivity) + apply (abs_add_le _ _).trans + apply add_le_add + · rw [abs_mul]; exact mul_le_mul (hsB i g x) (f.d1.norm_coe_le_norm _) (abs_nonneg _) (by positivity) + · rw [abs_mul]; exact mul_le_mul (f.d2.norm_coe_le_norm _) (hvC i _) (abs_nonneg _) (norm_nonneg _) + have hVB (i g x) : |V i g x| ≤ (‖f.d1‖*C)*(‖f.d1‖*D) := by + dsimp only [V]; rw [abs_mul,abs_mul,abs_mul] + exact mul_le_mul (mul_le_mul (f.d1.norm_coe_le_norm _) (hvC i _) (abs_nonneg _) (norm_nonneg _)) + (mul_le_mul (f.d1.norm_coe_le_norm _) (hwD i _) (abs_nonneg _) (norm_nonneg _)) (by positivity) (by positivity) + have hiU (i) : Integrable (fun g => gibbsReplicaMean μ (H g) n (U i g)) γ := by + apply Integrable.of_bound (replicaMean_varying_measurable μ hH (hUm i)).aestronglyMeasurable + (((n:ℝ)*(‖f.d1‖*C)*‖f.d1‖+‖f.d2‖*C)*D) + exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs] using replicaMean_bound μ hH.of_uncurry_left (hUm i).of_uncurry_left + (by positivity) (by positivity) (hHA g) (hUB i g) + have hiV (i) : Integrable (fun g => gibbsReplicaMean μ (H g) (n+1) (V i g)) γ := by + apply Integrable.of_bound (replicaMean_varying_measurable μ hH (hVm i)).aestronglyMeasurable + ((‖f.d1‖*C)*(‖f.d1‖*D)) + exact ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs] using replicaMean_bound μ hH.of_uncurry_left (hVm i).of_uncurry_left + (by positivity) (by positivity) (hHA g) (hVB i g) + have hiF (i) : Integrable (fun g => g i*gibbsReplicaMean μ (H g) n (F i g)) γ := by + have hg : Integrable (fun g : Fin (m+1)→ℝ => g i) γ := + ((measurePreserving_eval (fun _ : Fin (m+1) => gaussianReal 0 1) i).integrable_comp + measurable_id.aestronglyMeasurable).mpr + ((memLp_id_gaussianReal (μ := 0) (v := 1) 1).integrable (by norm_num)) + exact hg.mul_bdd (replicaMean_varying_measurable μ hH (hFm i)).aestronglyMeasurable + (ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs] using replicaMean_bound μ hH.of_uncurry_left (hFm i).of_uncurry_left + (by positivity) (by positivity) (hHA g) (hFB i g)) + have hl (g) : gibbsReplicaMean μ (H g) n (fun x => f.d1 (b g (x j))*(∑ i, g i*w i x)) = + ∑ i, g i*gibbsReplicaMean μ (H g) n (F i g) := by + rw [show (fun x => f.d1 (b g (x j))*(∑ i, g i*w i x)) = (fun x => ∑ i, g i*F i g x) by + funext x; simp only [Finset.mul_sum,F]; apply Finset.sum_congr rfl; intros; ring] + rw [replicaMean_sum μ Finset.univ hH.of_uncurry_left (fun i _ => (hFm i).of_uncurry_left.const_mul (g i)) + (by positivity) (hHA g) (D := fun i => |g i| *(‖f.d1‖*D)) (fun i _ x => by + rw [abs_mul]; exact mul_le_mul_of_nonneg_left (hFB i g x) (abs_nonneg _))] + simp_rw [replicaMean_const_mul] + have hr (g) : (∑ i, (gibbsReplicaMean μ (H g) n (U i g)-n*gibbsReplicaMean μ (H g) (n+1) (V i g))) = + gibbsReplicaMean μ (H g) n (fun x => + (∑ l, f.d1 (b g (x l))*f.d1 (b g (x j))*(∑ i, w i x*v i (x l)))+ + f.d2 (b g (x j))*(∑ i, w i x*v i (x j))) - + n*gibbsReplicaMean μ (H g) (n+1) (fun x => + f.d1 (b g (x 0))*f.d1 (b g (x j.succ))*(∑ i, w i (fun l => x l.succ)*v i (x 0))) := by + rw [Finset.sum_sub_distrib,←Finset.mul_sum, + ←replicaMean_sum μ Finset.univ hH.of_uncurry_left (fun i _ => (hUm i).of_uncurry_left) + (by positivity) (hHA g) (fun i _ => hUB i g), + ←replicaMean_sum μ Finset.univ hH.of_uncurry_left (fun i _ => (hVm i).of_uncurry_left) + (by positivity) (hHA g) (fun i _ => hVB i g)] + congr 1 + · congr 1; funext x + simp only [U,add_mul,Finset.sum_add_distrib,Finset.sum_mul,Finset.mul_sum] + rw [Finset.sum_comm] + congr 1 <;> (apply Finset.sum_congr rfl; intro i _) + · apply Finset.sum_congr rfl; intros; ring + · ring + · congr 1; congr 1; funext x + simp only [V,Finset.mul_sum] + apply Finset.sum_congr rfl; intros; ring + calc + _ = ∫ g, ∑ i, g i*gibbsReplicaMean μ (H g) n (F i g) ∂γ := integral_congr_ae (ae_of_all _ hl) + _ = _ := by + rw [integral_finsetSum _ fun i _ => hiF i] + simp_rw [show ∀ i, (∫ g, g i*gibbsReplicaMean μ (H g) n (F i g) ∂γ) = + ∫ g, gibbsReplicaMean μ (H g) n (U i g)-n*gibbsReplicaMean μ (H g) (n+1) (V i g) ∂γ + from fun i => nonlinear_pattern_replica_coordinate_ibp μ i j f hv hh (hw i) hA hC hD hhA hvC (hwD i)] + rw [←integral_finsetSum Finset.univ (f := fun i g => + gibbsReplicaMean μ (H g) n (U i g)-n*gibbsReplicaMean μ (H g) (n+1) (V i g)) + (fun i _ => (hiU i).sub ((hiV i).const_mul n))] + exact integral_congr_ae (ae_of_all _ hr) +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/NormSquareBand.lean b/lean/OAI/Probability/Perceptron/Variational/NormSquareBand.lean new file mode 100644 index 0000000000000000000000000000000000000000..77751f7e9597453925c46af8ddba0ab3abd88bd2 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/NormSquareBand.lean @@ -0,0 +1,436 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereIsometryMap +import OAI.Probability.Perceptron.Pressure.FiniteTerminal + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff + +lemma canonicalRadial_upper_tail (n : ℕ) {ε : ℝ} (hε : 0 < ε) : + canonicalRadialMass n 1 {x | ((n+1 : ℕ) : ℝ)*(1+ε) ≤ ‖x‖^2} ≤ + ENNReal.ofReal (Real.exp (-((ε-Real.log (1+ε))/2)*((n+1 : ℕ) : ℝ))) := by + have hd : 0 < 1+ε := by linarith + have hb : 0 ≤ 1-(1+ε)⁻¹ := by + apply sub_nonneg.mpr + exact (inv_le_one₀ hd).mpr (by linarith) + have hid : (1-(1+ε)⁻¹)*(1+ε) = ε := by field_simp; ring + have h := canonicalRadial_mass_le (n := n) (a := 1) (b := (1+ε)⁻¹) + (A := {x | ((n+1 : ℕ) : ℝ)*(1+ε) ≤ ‖x‖^2}) + (c := -((n+1 : ℕ) : ℝ)*ε/2) (by norm_num) (inv_pos.mpr hd) + (measurableSet_le measurable_const (continuous_norm.pow 2).measurable) (by + intro x hx + have hh := mul_le_mul_of_nonneg_left hx hb + have he : (1-(1+ε)⁻¹)*(((n+1 : ℕ) : ℝ)*(1+ε)) = ((n+1 : ℕ) : ℝ)*ε := by + calc + _ = ((n+1 : ℕ) : ℝ)*((1-(1+ε)⁻¹)*(1+ε)) := by ring + _ = _ := by rw [hid] + rw [he] at hh + nlinarith) + convert h using 1 + congr 1 + rw [Real.rpow_def_of_pos (inv_pos.mpr hd),Real.log_inv,← Real.exp_add] + congr 1 + ring + +lemma canonicalRadial_lower_tail (n : ℕ) {ε : ℝ} (hε : 0 < ε) (hε1 : ε < 1) : + canonicalRadialMass n 1 {x | ‖x‖^2 ≤ ((n+1 : ℕ) : ℝ)*(1-ε)} ≤ + ENNReal.ofReal (Real.exp (-((-ε-Real.log (1-ε))/2)*((n+1 : ℕ) : ℝ))) := by + have hd : 0 < 1-ε := sub_pos.mpr hε1 + have hb : 0 ≤ (1-ε)⁻¹-1 := by + apply sub_nonneg.mpr + exact (one_le_inv₀ hd).mpr (by linarith) + have hid : ((1-ε)⁻¹-1)*(1-ε) = ε := by field_simp; ring + have h := canonicalRadial_mass_le (n := n) (a := 1) (b := (1-ε)⁻¹) + (A := {x | ‖x‖^2 ≤ ((n+1 : ℕ) : ℝ)*(1-ε)}) + (c := ((n+1 : ℕ) : ℝ)*ε/2) (by norm_num) (inv_pos.mpr hd) + (measurableSet_le (continuous_norm.pow 2).measurable measurable_const) (by + intro x hx + have hh := mul_le_mul_of_nonneg_left hx hb + have he : ((1-ε)⁻¹-1)*(((n+1 : ℕ) : ℝ)*(1-ε)) = ((n+1 : ℕ) : ℝ)*ε := by + calc + _ = ((n+1 : ℕ) : ℝ)*(((1-ε)⁻¹-1)*(1-ε)) := by ring + _ = _ := by rw [hid] + rw [he] at hh + nlinarith) + convert h using 1 + congr 1 + rw [Real.rpow_def_of_pos (inv_pos.mpr hd),Real.log_inv,← Real.exp_add] + congr 1 + ring + +def normSquareBand (n : ℕ) (ε : ℝ) : Set (RadialSpace n) := + {x | ((n+1 : ℕ) : ℝ)*(1-ε) ≤ ‖x‖^2 ∧ ‖x‖^2 ≤ ((n+1 : ℕ) : ℝ)*(1+ε)} + +lemma normSquareBand_measurable (n : ℕ) (ε : ℝ) : MeasurableSet (normSquareBand n ε) := + (measurableSet_le measurable_const (continuous_norm.pow 2).measurable).inter + (measurableSet_le (continuous_norm.pow 2).measurable measurable_const) + +lemma canonicalRadial_band_compl_le (n : ℕ) {ε : ℝ} (hε : 0 < ε) (hε1 : ε < 1) : + canonicalRadialMass n 1 (normSquareBand n ε)ᶜ ≤ + ENNReal.ofReal (Real.exp (-((ε-Real.log (1+ε))/2)*((n+1 : ℕ) : ℝ)))+ + ENNReal.ofReal (Real.exp (-((-ε-Real.log (1-ε))/2)*((n+1 : ℕ) : ℝ))) := by + calc + _ ≤ canonicalRadialMass n 1 + ({x | ((n+1 : ℕ) : ℝ)*(1+ε) ≤ ‖x‖^2} ∪ {x | ‖x‖^2 ≤ ((n+1 : ℕ) : ℝ)*(1-ε)}) := + measure_mono (by + intro x hx + change ¬ (_ ∧ _) at hx + rcases not_and_or.mp hx with h | h + · exact Or.inr (le_of_not_ge h) + · exact Or.inl (le_of_not_ge h)) + _ ≤ _ := (measure_union_le _ _).trans + (add_le_add (canonicalRadial_upper_tail n hε) (canonicalRadial_lower_tail n hε hε1)) + +lemma exp_neg_mul_nat_succ_tendsto {c : ℝ} (hc : 0 < c) : + Tendsto (fun n : ℕ => Real.exp (-c*((n+1 : ℕ) : ℝ))) atTop (𝓝 0) := by + apply Real.tendsto_exp_atBot.comp + apply Tendsto.const_mul_atTop_of_neg (neg_neg_of_pos hc) + exact tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + +lemma canonicalRadial_band_eventually_half {ε : ℝ} (hε : 0 < ε) (hε1 : ε < 1) : + ∀ᶠ n : ℕ in atTop, (1/2 : ℝ) ≤ (canonicalRadialMass n 1).real (normSquareBand n ε) := by + have hu : 0 < (ε-Real.log (1+ε))/2 := by + have h := Real.log_lt_sub_one_of_pos (by linarith : 0 < 1+ε) (by linarith : 1+ε ≠ 1) + linarith + have hl : 0 < (-ε-Real.log (1-ε))/2 := by + have h := Real.log_lt_sub_one_of_pos (by linarith : 0 < 1-ε) (by linarith : 1-ε ≠ 1) + linarith + have ht := (exp_neg_mul_nat_succ_tendsto hu).add (exp_neg_mul_nat_succ_tendsto hl) + have hev : ∀ᶠ n : ℕ in atTop, + Real.exp (-((ε-Real.log (1+ε))/2)*((n+1 : ℕ) : ℝ))+ + Real.exp (-((-ε-Real.log (1-ε))/2)*((n+1 : ℕ) : ℝ)) < 1/2 := + ht.eventually (gt_mem_nhds (by norm_num : (0:ℝ)+0 < 1/2)) + filter_upwards [hev] with n hn + have h := canonicalRadial_band_compl_le n hε hε1 + rw [← ENNReal.ofReal_add (Real.exp_pos _).le (Real.exp_pos _).le] at h + have h' := ENNReal.toReal_mono ENNReal.ofReal_ne_top h + rw [ENNReal.toReal_ofReal (by positivity)] at h' + change (canonicalRadialMass n 1).real (normSquareBand n ε)ᶜ ≤ _ at h' + rw [measureReal_compl (normSquareBand_measurable n ε), probReal_univ] at h' + linarith + +lemma canonicalRadialMass_real_apply {n : ℕ} {b : ℝ} (hb : 0 < b) + {A : Set (RadialSpace n)} (hA : MeasurableSet A) : + (canonicalRadialMass n b).real A = ∫ x in A, canonicalRadialDensity n b x := by + rw [Measure.real,canonicalRadialMass_apply hb hA,ENNReal.toReal_ofReal] + exact integral_nonneg fun x => (canonicalRadialDensity_pos n b x).le + +lemma canonicalRadialDensity_tilt (n : ℕ) (b : ℝ) (x : RadialSpace n) : + canonicalRadialDensity n b x = Real.exp (((1-b)/2)*‖x‖^2)*canonicalRadialDensity n 1 x := by + unfold canonicalRadialDensity + rw [mul_left_comm (Real.exp _) (radialNormalizer n),← Real.exp_add] + congr 2 + ring + +lemma normSquareBand_tilt_bounds (n : ℕ) {ε b : ℝ} {x : RadialSpace n} + (hx : x ∈ normSquareBand n ε) : + ((n+1 : ℕ) : ℝ)*((1-b)/2-|1-b| *ε/2) ≤ ((1-b)/2)*‖x‖^2 ∧ + ((1-b)/2)*‖x‖^2 ≤ ((n+1 : ℕ) : ℝ)*((1-b)/2+|1-b| *ε/2) := by + have ha : |‖x‖^2-((n+1 : ℕ) : ℝ)| ≤ ((n+1 : ℕ) : ℝ)*ε := by + rcases hx with ⟨hl,hu⟩ + apply abs_le.mpr + constructor <;> nlinarith + have hm := mul_le_mul_of_nonneg_left ha (abs_nonneg (1-b)) + rw [← abs_mul] at hm + obtain ⟨hl,hu⟩ := abs_le.mp hm + constructor <;> nlinarith + +lemma canonicalRadial_band_mass_bounds (n : ℕ) {b ε : ℝ} (hb : 0 < b) + (hhalf : (1/2 : ℝ) ≤ (canonicalRadialMass n 1).real (normSquareBand n ε)) : + Real.exp (((n+1 : ℕ) : ℝ)*((1-b)/2-|1-b| *ε/2))/2 ≤ + (canonicalRadialMass n b).real (normSquareBand n ε) ∧ + (canonicalRadialMass n b).real (normSquareBand n ε) ≤ + Real.exp (((n+1 : ℕ) : ℝ)*((1-b)/2+|1-b| *ε/2)) := by + have hm := normSquareBand_measurable n ε + have hlo : Real.exp (((n+1 : ℕ) : ℝ)*((1-b)/2-|1-b| *ε/2))* + (canonicalRadialMass n 1).real (normSquareBand n ε) ≤ + (canonicalRadialMass n b).real (normSquareBand n ε) := by + rw [canonicalRadialMass_real_apply hb hm,canonicalRadialMass_real_apply (by norm_num : (0:ℝ)<1) hm, + ← integral_const_mul] + apply setIntegral_mono_on + ((canonicalRadialDensity_integrable n (by norm_num : (0:ℝ)<1)).const_mul _).integrableOn + (canonicalRadialDensity_integrable n hb).integrableOn hm + intro x hx + rw [canonicalRadialDensity_tilt n b x] + exact mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr (normSquareBand_tilt_bounds n hx).1) + (canonicalRadialDensity_pos n 1 x).le + have hup : (canonicalRadialMass n b).real (normSquareBand n ε) ≤ + Real.exp (((n+1 : ℕ) : ℝ)*((1-b)/2+|1-b| *ε/2))* + (canonicalRadialMass n 1).real (normSquareBand n ε) := by + rw [canonicalRadialMass_real_apply hb hm,canonicalRadialMass_real_apply (by norm_num : (0:ℝ)<1) hm, + ← integral_const_mul] + apply setIntegral_mono_on + (canonicalRadialDensity_integrable n hb).integrableOn + ((canonicalRadialDensity_integrable n (by norm_num : (0:ℝ)<1)).const_mul _).integrableOn hm + intro x hx + rw [canonicalRadialDensity_tilt n b x] + exact mul_le_mul_of_nonneg_right (Real.exp_le_exp.mpr (normSquareBand_tilt_bounds n hx).2) + (canonicalRadialDensity_pos n 1 x).le + constructor + · have h := mul_le_mul_of_nonneg_left hhalf (Real.exp_pos (((n+1 : ℕ) : ℝ)*((1-b)/2-|1-b| *ε/2))).le + have h' : Real.exp (((n+1 : ℕ) : ℝ)*((1-b)/2-|1-b| *ε/2))/2 ≤ + Real.exp (((n+1 : ℕ) : ℝ)*((1-b)/2-|1-b| *ε/2))* + (canonicalRadialMass n 1).real (normSquareBand n ε) := by simpa only [mul_one_div] using h + exact h'.trans hlo + · apply hup.trans + exact mul_le_of_le_one_right (Real.exp_pos _).le (measureReal_le_one) + +lemma canonicalRadial_band_log_bounds (n : ℕ) {b ε : ℝ} (hb : 0 < b) + (hhalf : (1/2 : ℝ) ≤ (canonicalRadialMass n 1).real (normSquareBand n ε)) : + (1-b)/2-|1-b| *ε/2-Real.log 2/((n+1 : ℕ) : ℝ) ≤ + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))/((n+1 : ℕ) : ℝ) ∧ + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))/((n+1 : ℕ) : ℝ) ≤ + (1-b)/2+|1-b| *ε/2 := by + obtain ⟨hl,hu⟩ := canonicalRadial_band_mass_bounds n hb hhalf + have hlpos : 0 < Real.exp (((n+1 : ℕ) : ℝ)*((1-b)/2-|1-b| *ε/2))/2 := by positivity + have hmpos := hlpos.trans_le hl + have hl' := Real.log_le_log hlpos hl + have hu' := Real.log_le_log hmpos hu + rw [Real.log_div (Real.exp_ne_zero _) (by norm_num : (2:ℝ) ≠ 0),Real.log_exp] at hl' + rw [Real.log_exp] at hu' + have hn : 0 < ((n+1 : ℕ) : ℝ) := by positivity + constructor + · apply (le_div_iff₀ hn).mpr + have he : ((1-b)/2-|1-b| *ε/2-Real.log 2/((n+1 : ℕ) : ℝ))*((n+1 : ℕ) : ℝ) = + ((n+1 : ℕ) : ℝ)*((1-b)/2-|1-b| *ε/2)-Real.log 2 := by field_simp + rw [he] + exact hl' + · exact (div_le_iff₀ hn).mpr (by nlinarith) + +lemma canonicalRadial_band_log_eventually {b ε : ℝ} (hb : 0 < b) (hε : 0 < ε) (hε1 : ε < 1) : + ∀ᶠ n : ℕ in atTop, + (1-b)/2-|1-b| *ε/2-Real.log 2/((n+1 : ℕ) : ℝ) ≤ + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))/((n+1 : ℕ) : ℝ) ∧ + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))/((n+1 : ℕ) : ℝ) ≤ + (1-b)/2+|1-b| *ε/2 := + (canonicalRadial_band_eventually_half hε hε1).mono fun n hn => canonicalRadial_band_log_bounds n hb hn + +lemma unitSphere_continuous_integrable {n : ℕ} + {f : Metric.sphere (0 : Spin (n+1)) 1 → ℝ} (hf : Continuous f) : + Integrable f (unitSphereLaw (n+1)) := by + obtain ⟨C,hC⟩ := isCompact_univ.exists_bound_of_continuousOn hf.continuousOn + exact Integrable.of_bound hf.aestronglyMeasurable C (Eventually.of_forall fun u => hC u (mem_univ _)) + +def sphericalExp (n : ℕ) (z : Spin (n+1)) (r : ℝ) : ℝ := + ∫ u : Metric.sphere (0 : Spin (n+1)) 1, Real.exp (r * inner ℝ z (u:Spin (n+1))) ∂unitSphereLaw (n+1) + +lemma sphericalExp_even (n : ℕ) (z : Spin (n+1)) (r : ℝ) : + sphericalExp n z (-r) = sphericalExp n z r := by + have hemb : MeasurableEmbedding (sphereIsometryMap (LinearIsometryEquiv.neg ℝ : Spin (n+1) ≃ₗᵢ[ℝ] Spin (n+1))) := by + apply Measurable.measurableEmbedding + (sphereIsometryMap_measurable _) _ + intro u v huv + apply Subtype.ext + have := congrArg Subtype.val huv + simpa [sphereIsometryMap] using this + have h := (unitSphereLaw_isometry_preserving (LinearIsometryEquiv.neg ℝ : Spin (n+1) ≃ₗᵢ[ℝ] Spin (n+1))).integral_comp hemb + (fun u : Metric.sphere (0:Spin (n+1)) 1 => Real.exp (r * inner ℝ z (u:Spin (n+1)))) + simpa [sphericalExp,sphereIsometryMap] using h + +lemma sphericalExp_eq_cosh (n : ℕ) (z : Spin (n+1)) (r : ℝ) : + sphericalExp n z r = + ∫ u : Metric.sphere (0 : Spin (n+1)) 1, Real.cosh (r * inner ℝ z (u:Spin (n+1))) ∂unitSphereLaw (n+1) := by + have hi (s : ℝ) : Integrable (fun u : Metric.sphere (0:Spin (n+1)) 1 => Real.exp (s * inner ℝ z (u:Spin (n+1)))) (unitSphereLaw (n+1)) := + unitSphere_continuous_integrable (by fun_prop) + simp only [Real.cosh_eq,integral_div] + rw [integral_add (hi r) (by simpa only [neg_mul] using hi (-r))] + simp only [← neg_mul] + change sphericalExp n z r = (sphericalExp n z r + sphericalExp n z (-r))/2 + rw [sphericalExp_even] + ring + +lemma sphericalExp_mono (n : ℕ) (z : Spin (n+1)) {r s : ℝ} + (hr : 0 ≤ r) (hrs : r ≤ s) : sphericalExp n z r ≤ sphericalExp n z s := by + rw [sphericalExp_eq_cosh,sphericalExp_eq_cosh] + apply integral_mono (unitSphere_continuous_integrable (by fun_prop)) + (unitSphere_continuous_integrable (by fun_prop)) + intro u + apply Real.cosh_le_cosh.mpr + rw [abs_mul,abs_mul,abs_of_nonneg hr,abs_of_nonneg (hr.trans hrs)] + exact mul_le_mul_of_nonneg_right hrs (abs_nonneg _) + +lemma one_le_sphericalExp (n : ℕ) (z : Spin (n+1)) (r : ℝ) : + 1 ≤ sphericalExp n z r := by + rw [sphericalExp_eq_cosh] + calc + (1:ℝ) = ∫ _ : Metric.sphere (0:Spin (n+1)) 1, (1:ℝ) ∂unitSphereLaw (n+1) := by simp + _ ≤ _ := integral_mono (integrable_const _) (unitSphere_continuous_integrable (by fun_prop)) (fun u => Real.one_le_cosh _) + +section Polar +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [FiniteDimensional ℝ E] [Nontrivial E] [MeasurableSpace E] [BorelSpace E] + (μ : Measure E) [μ.IsAddHaarMeasure] + +lemma polar_lintegral (f : E → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ x, f x ∂μ) = + ∫⁻ u : Metric.sphere (0:E) 1, ∫⁻ r : Ioi (0:ℝ), + f ((r:ℝ) • (u:E)) ∂Measure.volumeIoiPow (Module.finrank ℝ E - 1) ∂μ.toSphere := by + let h := homeomorphUnitSphereProd E + let F : Metric.sphere (0:E) 1 × Ioi (0:ℝ) → ℝ≥0∞ := + fun p => f ((p.2:ℝ) • (p.1:E)) + have hF : Measurable F := hf.comp (measurable_snd.subtype_val.smul measurable_fst.subtype_val) + calc + _ = ∫⁻ x : ({(0:E)}ᶜ : Set E), f (x:E) ∂μ.comap Subtype.val := by + rw [lintegral_subtype_comap (measurableSet_singleton _).compl, + restrict_compl_singleton] + _ = ∫⁻ p, F p ∂μ.toSphere.prod (Measure.volumeIoiPow (Module.finrank ℝ E - 1)) := by + convert (μ.measurePreserving_homeomorphUnitSphereProd.lintegral_comp hF) using 1 + apply lintegral_congr + intro x + change f (x:E) = f ((h x).2.val • (h x).1.val) + have he := congrArg Subtype.val (h.symm_apply_apply x) + exact congrArg f he.symm + _ = _ := lintegral_prod _ hF.aemeasurable + +lemma polar_lintegral_swap (f : E → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ x, f x ∂μ) = + ∫⁻ r : Ioi (0:ℝ), ∫⁻ u : Metric.sphere (0:E) 1, + f ((r:ℝ) • (u:E)) ∂μ.toSphere ∂Measure.volumeIoiPow (Module.finrank ℝ E - 1) := by + rw [polar_lintegral μ f hf] + exact lintegral_lintegral_swap + (hf.comp (measurable_snd.subtype_val.smul measurable_fst.subtype_val)).aemeasurable + +def normalizedAngular : Measure (Metric.sphere (0:E) 1) := + (μ.toSphere univ)⁻¹ • μ.toSphere + +def haarRadiusMeasure : Measure (Ioi (0:ℝ)) := + μ.toSphere univ • Measure.volumeIoiPow (Module.finrank ℝ E - 1) + +lemma angular_total_ne_zero : μ.toSphere univ ≠ 0 := by + exact Measure.measure_univ_ne_zero.mpr (Measure.toSphere_ne_zero μ) + +lemma polar_lintegral_normalized (f : E → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ x, f x ∂μ) = + ∫⁻ r : Ioi (0:ℝ), ∫⁻ u : Metric.sphere (0:E) 1, + f ((r:ℝ) • (u:E)) ∂normalizedAngular μ ∂haarRadiusMeasure μ := by + rw [haarRadiusMeasure,lintegral_smul_measure] + simp only [normalizedAngular,lintegral_smul_measure,smul_eq_mul] + rw [lintegral_const_mul' _ _ (ENNReal.inv_ne_top.mpr (angular_total_ne_zero μ)),← mul_assoc, + ENNReal.mul_inv_cancel (angular_total_ne_zero μ) (measure_ne_top _ _),one_mul] + exact polar_lintegral_swap μ f hf + +lemma polar_radial_lintegral (g : ℝ → ℝ≥0∞) (hg : Measurable g) : + (∫⁻ x, g ‖x‖ ∂μ) = ∫⁻ r : Ioi (0:ℝ), g r ∂haarRadiusMeasure μ := by + rw [polar_lintegral_normalized μ (fun x => g ‖x‖) (hg.comp measurable_norm)] + apply lintegral_congr + intro r + have hnorm (u : Metric.sphere (0:E) 1) : ‖(r:ℝ) • (u:E)‖ = (r:ℝ) := by + rw [norm_smul,Real.norm_eq_abs,abs_of_pos r.property] + simp + simp only [hnorm,lintegral_const,normalizedAngular,Measure.smul_apply,smul_eq_mul] + rw [ENNReal.inv_mul_cancel (angular_total_ne_zero μ) (measure_ne_top _ _),mul_one] + +lemma polar_weighted_lintegral (f : E → ℝ≥0∞) (hf : Measurable f) + (g : ℝ → ℝ≥0∞) (hg : Measurable g) : + (∫⁻ x, g ‖x‖ * f x ∂μ) = + ∫⁻ r : Ioi (0:ℝ), g r * (∫⁻ u : Metric.sphere (0:E) 1, + f ((r:ℝ) • (u:E)) ∂normalizedAngular μ) ∂haarRadiusMeasure μ := by + rw [polar_lintegral_normalized μ (fun x => g ‖x‖ * f x) ((hg.comp measurable_norm).mul hf)] + apply lintegral_congr + intro r + have hnorm (u : Metric.sphere (0:E) 1) : ‖(r:ℝ) • (u:E)‖ = (r:ℝ) := by + rw [norm_smul,Real.norm_eq_abs,abs_of_pos r.property]; simp + simp only [hnorm] + exact lintegral_const_mul _ ((hf.comp (measurable_subtype_coe.const_smul (r:ℝ)))) + +lemma polar_weighted_bounds (f : E → ℝ≥0∞) (hf : Measurable f) + (g : ℝ → ℝ≥0∞) (hg : Measurable g) {L U : ℝ≥0∞} + (hL : ∀ r : Ioi (0:ℝ), g r ≠ 0 → + L ≤ ∫⁻ u : Metric.sphere (0:E) 1, f ((r:ℝ) • (u:E)) ∂normalizedAngular μ) + (hU : ∀ r : Ioi (0:ℝ), g r ≠ 0 → + (∫⁻ u : Metric.sphere (0:E) 1, f ((r:ℝ) • (u:E)) ∂normalizedAngular μ) ≤ U) : + L * (∫⁻ x, g ‖x‖ ∂μ) ≤ (∫⁻ x, g ‖x‖ * f x ∂μ) ∧ + (∫⁻ x, g ‖x‖ * f x ∂μ) ≤ U * (∫⁻ x, g ‖x‖ ∂μ) := by + rw [polar_radial_lintegral μ g hg,polar_weighted_lintegral μ f hf g hg] + constructor + · rw [← lintegral_const_mul (f := fun r : Ioi (0:ℝ) => g r) _ (hg.comp measurable_subtype_coe)] + apply lintegral_mono + intro r + by_cases hr : g r = 0 + · simp [hr] + · simpa only [mul_comm L] using mul_le_mul le_rfl (hL r hr) (by positivity) (by positivity) + · rw [← lintegral_const_mul (f := fun r : Ioi (0:ℝ) => g r) _ (hg.comp measurable_subtype_coe)] + apply lintegral_mono + intro r + by_cases hr : g r = 0 + · simp [hr] + · simpa only [mul_comm U] using mul_le_mul le_rfl (hU r hr) (by positivity) (by positivity) + +end Polar + +def linearFieldFactor {n : ℕ} (ρ : Measure (Spin (n+1))) (x : Spin (n+1)) : ℝ≥0∞ := + ∫⁻ z, ENNReal.ofReal (Real.exp (inner ℝ z x)) ∂ρ + +def angularFieldFactor {n : ℕ} (ρ : Measure (Spin (n+1))) (r : ℝ) : ℝ≥0∞ := + ∫⁻ u : Metric.sphere (0:Spin (n+1)) 1, + linearFieldFactor ρ (r • (u:Spin (n+1))) ∂unitSphereLaw (n+1) + +lemma linearFieldFactor_measurable {n : ℕ} (ρ : Measure (Spin (n+1))) [SFinite ρ] : + Measurable (linearFieldFactor ρ) := by + exact Measurable.lintegral_prod_right + ((continuous_snd.inner continuous_fst).rexp.measurable.ennreal_ofReal) + +lemma angularFieldFactor_eq {n : ℕ} (ρ : Measure (Spin (n+1))) [SFinite ρ] (r : ℝ) : + angularFieldFactor ρ r = ∫⁻ z, ENNReal.ofReal (sphericalExp n z r) ∂ρ := by + unfold angularFieldFactor linearFieldFactor + rw [lintegral_lintegral_swap (by fun_prop)] + apply lintegral_congr + intro z + simp only [inner_smul_right] + exact (ofReal_integral_eq_lintegral_ofReal + (unitSphere_continuous_integrable (by fun_prop)) + (Eventually.of_forall fun u => (Real.exp_pos _).le)).symm + +lemma angularFieldFactor_mono {n : ℕ} (ρ : Measure (Spin (n+1))) [SFinite ρ] + {r s : ℝ} (hr : 0 ≤ r) (hrs : r ≤ s) : + angularFieldFactor ρ r ≤ angularFieldFactor ρ s := by + rw [angularFieldFactor_eq,angularFieldFactor_eq] + exact lintegral_mono fun z => ENNReal.ofReal_le_ofReal (sphericalExp_mono n z hr hrs) + +lemma one_le_angularFieldFactor {n : ℕ} (ρ : Measure (Spin (n+1))) [IsProbabilityMeasure ρ] + (r : ℝ) : 1 ≤ angularFieldFactor ρ r := by + rw [angularFieldFactor_eq] + calc + (1:ℝ≥0∞) = ∫⁻ _ : Spin (n+1), (1:ℝ≥0∞) ∂ρ := by simp + _ ≤ _ := lintegral_mono fun z => by + simpa using ENNReal.ofReal_le_ofReal (one_le_sphericalExp n z r) + +def canonicalBandRadiusWeight (n : ℕ) (b ε : ℝ) : ℝ → ℝ≥0∞ := + {r : ℝ | ((n+1:ℕ):ℝ)*(1-ε) ≤ r^2 ∧ r^2 ≤ ((n+1:ℕ):ℝ)*(1+ε)}.indicator + (fun r => ENNReal.ofReal (radialNormalizer n * Real.exp (-(b/2)*r^2))) + +lemma canonicalBandRadiusWeight_measurable (n : ℕ) (b ε : ℝ) : + Measurable (canonicalBandRadiusWeight n b ε) := by + apply Measurable.indicator (by fun_prop) + exact (measurableSet_le measurable_const (continuous_id.pow 2).measurable).inter + (measurableSet_le (continuous_id.pow 2).measurable measurable_const) + +lemma canonicalBandRadiusWeight_integral (n : ℕ) (b ε : ℝ) + (F : RadialSpace n → ℝ≥0∞) (hF : Measurable F) : + (∫⁻ x, canonicalBandRadiusWeight n b ε ‖x‖ * F x) = + ∫⁻ x in normSquareBand n ε, F x ∂canonicalRadialMass n b := by + rw [canonicalRadialMass,setLIntegral_withDensity_eq_setLIntegral_mul _ + (canonicalRadialDensity_continuous n b).measurable.ennreal_ofReal hF + (normSquareBand_measurable n ε),← lintegral_indicator (normSquareBand_measurable n ε) _] + apply lintegral_congr + intro x + by_cases hx : ((n+1:ℕ):ℝ)*(1-ε) ≤ ‖x‖^2 ∧ ‖x‖^2 ≤ ((n+1:ℕ):ℝ)*(1+ε) + all_goals simp only [canonicalBandRadiusWeight,normSquareBand,Set.indicator_apply,Set.mem_ofPred_eq,hx,and_self,ite_true,ite_false,zero_mul,Pi.mul_apply,canonicalRadialDensity] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/OrderedCode.lean b/lean/OAI/Probability/Perceptron/Variational/OrderedCode.lean new file mode 100644 index 0000000000000000000000000000000000000000..de5217f41295977762376482f4c8a3c60311158b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/OrderedCode.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.RoundedMarkedSelection + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter TopologicalSpace +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction + +def orderedLevelCode {k : ℕ} (v : Fin (k+1) → ℝ) (x : ℝ) : Fin (k+1) := + (Finset.univ.filter (fun i => v i ≤ x)).sup id + +lemma orderedLevelCode_mono {k : ℕ} (v : Fin (k+1) → ℝ) : + Monotone (orderedLevelCode v) := by + intro x y hxy + apply Finset.sup_mono + intro i hi + simp only [Finset.mem_filter,Finset.mem_univ,true_and] at hi ⊢ + exact hi.trans hxy + +lemma orderedLevelCode_value {k : ℕ} (v : Fin (k+1) → ℝ) (hv : StrictMono v) + (j : Fin (k+1)) : orderedLevelCode v (v j) = j := by + apply le_antisymm + · apply Finset.sup_le + intro i hi + simp only [Finset.mem_filter,Finset.mem_univ,true_and] at hi + exact hv.le_iff_le.mp hi + · exact Finset.le_sup (f := id) (by simp) + +lemma orderedLevelCode_top {k : ℕ} (v : Fin (k+1) → ℝ) (x : ℝ) + (hv : v (Fin.last k) ≤ x) : orderedLevelCode v x = Fin.last k := by + apply le_antisymm (Fin.le_last _) + exact Finset.le_sup (f := id) (Finset.mem_filter.mpr ⟨Finset.mem_univ _,hv⟩) + +lemma orderedLevelCode_measurable {k : ℕ} (v : Fin (k+1) → ℝ) : + Measurable (orderedLevelCode v) := (orderedLevelCode_mono v).measurable + +lemma roundLower_one (n : ℕ) : roundLower n 1 = 1 := by + unfold roundLower + simp only [mul_one,Nat.floor_natCast] + exact div_self (by positivity) + +lemma orderedRoundCode_label (q : BoundedField 1) (n : ℕ) : + (fun u => orderedLevelCode (strictRoundModel q n).value (roundLower n (q u))) + =ᵐ[timeLaw] (strictRoundModel q n).label := by + filter_upwards [(strictRoundModel q n).agrees] with u hu + change (strictRoundModel q n).value ((strictRoundModel q n).label u) = + roundLower n (q u) at hu + rw [←hu,orderedLevelCode_value _ (strictRoundModel_strict q n)] + +lemma orderedRoundCode_one (q : BoundedField 1) (n : ℕ) : + orderedLevelCode (strictRoundModel q n).value (roundLower n 1) = + Fin.last (strictRoundModel q n).depth := by + rw [roundLower_one] + apply orderedLevelCode_top + exact (roundTimeValue q n _).property.2 + +lemma compactGG_events_general {K : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [MetrizableSpace K] [SecondCountableTopology K] + (μ : ProbabilityMeasure (CompactArray K)) + (n : ℕ) (hn : 0 + ρ.real (s×ˢt)) (compactGG_joint_law μ hn i hGG) + have hb := (compactBlock_continuous (K:=K) n).measurable + have hm (i j : ℕ) : Measurable (fun Q : CompactArray K => Q i j) := by fun_prop + rw [map_measureReal_apply (hb.prodMk (hm _ _)) (hs.prod ht), + measureReal_nnreal_smul_apply,measureReal_add_apply] at he + have hsum : (∑ j ∈ Finset.univ.erase i, + (μ : Measure _).map (fun Q => (compactBlock n Q,Q i j))).real (s×ˢt) = + ∑ j ∈ Finset.univ.erase i, (μ : Measure _).real (compactBlock n ⁻¹' s ∩ {Q | Q i j∈t}) := by + simp only [measureReal_def,Measure.finsetSum_apply] + rw [ENNReal.toReal_sum (by intro _ _; finiteness)] + apply Finset.sum_congr rfl + intro j hj + rw [Measure.map_apply (hb.prodMk (hm _ _)) (hs.prod ht)] + rfl + rw [hsum] at he + have hprod : (((μ : Measure _).map (compactBlock n)).prod + ((μ : Measure _).map (fun Q : CompactArray K => Q 0 1))).real (s×ˢt) = + (μ : Measure _).real (compactBlock n ⁻¹' s)*(μ : Measure _).real {Q : CompactArray K | Q 0 1∈t} := by + simp only [measureReal_def,Measure.prod_prod,ENNReal.toReal_mul, + Measure.map_apply hb hs,Measure.map_apply (hm 0 1) ht] + rfl + rw [hprod] at he + simp only [NNReal.coe_inv,NNReal.coe_natCast] at he + change (μ : Measure _).real (compactBlock n ⁻¹' s ∩ {Q | Q i n∈t}) = (n:ℝ)⁻¹*(_+_) at he + rw [he] + ring + +variable {K L : Type*} [TopologicalSpace K] [MeasurableSpace K] + [BorelSpace K] [MetrizableSpace K] [SecondCountableTopology K] + [Fintype L] [MeasurableSpace L] [MeasurableSingletonClass L] + +def finiteCodeArray (χ : K → L) (Q : CompactArray K) : + FiniteOverlap L := fun i j => χ (Q i j) + +def finiteCodeBlock {n : ℕ} (χ : K → L) (Q : CompactBlock K n) : + FiniteBlock L n := fun i j => χ (Q i j) + +omit [TopologicalSpace K] [BorelSpace K] [MetrizableSpace K] [SecondCountableTopology K] + [Fintype L] [MeasurableSingletonClass L] in +lemma finiteCodeArray_measurable {χ : K → L} (hχ : Measurable χ) : + Measurable (finiteCodeArray χ) := by + unfold finiteCodeArray + exact Measurable.of_eval fun _ => Measurable.of_eval fun _ => + hχ.comp ((measurable_pi_apply _).comp (measurable_pi_apply _)) + +omit [TopologicalSpace K] [BorelSpace K] [MetrizableSpace K] [SecondCountableTopology K] + [Fintype L] [MeasurableSingletonClass L] in +lemma finiteCodeBlock_measurable {χ : K → L} (hχ : Measurable χ) (n : ℕ) : + Measurable (finiteCodeBlock (n:=n) χ) := by + unfold finiteCodeBlock + exact Measurable.of_eval fun _ => Measurable.of_eval fun _ => + hχ.comp ((measurable_pi_apply _).comp (measurable_pi_apply _)) + +lemma compactGG_finite_pushforward_general (μ : ProbabilityMeasure (CompactArray K)) + (hGG : ∀ (n : ℕ) (i : Fin n) (f : CompactBlock K n →ᵇ ℝ) + (g : K →ᵇ ℝ), compactGGDefect μ n i f g=0) + {χ : K → L} (hχ : Measurable χ) : + FiniteGG ((μ : Measure (CompactArray K)).map (finiteCodeArray χ)) := by + classical + intro n hn i A c + have hm := finiteCodeArray_measurable hχ + have hb := finiteBlock_measurable (L:=L) n + have he (a b : ℕ) : Measurable (fun R : FiniteOverlap L => R a b) := by fun_prop + have hs : MeasurableSet {R : FiniteOverlap L | finiteBlock n R=A} := + measurableSet_eq_fun hb measurable_const + have hv (a b : ℕ) : MeasurableSet {R : FiniteOverlap L | R a b=c} := + measurableSet_eq_fun (he a b) measurable_const + have hvv (a b : ℕ) : MeasurableSet {R : FiniteOverlap L | finiteBlock n R=A ∧ R a b=c} := hs.inter (hv a b) + rw [map_measureReal_apply hm (hvv _ _),map_measureReal_apply hm hs, + map_measureReal_apply hm (hv 0 1)] + simp_rw [map_measureReal_apply hm (hvv _ _)] + exact compactGG_events_general μ n (by omega) i (hGG n i) + ((finiteCodeBlock χ) ⁻¹' {A}) ((measurableSet_singleton A).preimage (finiteCodeBlock_measurable hχ n)) + (χ ⁻¹' {c}) ((measurableSet_singleton c).preimage hχ) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ParameterResampling.lean b/lean/OAI/Probability/Perceptron/Variational/ParameterResampling.lean new file mode 100644 index 0000000000000000000000000000000000000000..c82083cdfa6c61ee6ef9a91d097ee34c02147848 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ParameterResampling.lean @@ -0,0 +1,83 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma infinitePi_update_measurePreserving {X : Type*} [MeasurableSpace X] + (μ : Measure X) [IsProbabilityMeasure μ] (p : ℕ) : + MeasurePreserving (fun a : (ℕ→X) × X => Function.update a.1 p a.2) + ((Measure.infinitePi fun _ : ℕ => μ).prod μ) (Measure.infinitePi fun _ : ℕ => μ) := by + classical + refine ⟨by fun_prop,?_⟩ + apply Measure.eq_infinitePi + intro s t ht + rw [Measure.map_apply (by fun_prop) (MeasurableSet.pi s.countable_toSet (fun i _ => ht i))] + by_cases hp : p∈s + · have he : (fun a : (ℕ→X) × X => Function.update a.1 p a.2) ⁻¹' Set.pi s t = + (Set.pi (s.erase p) t) ×ˢ t p := by + ext a + simp only [Set.mem_preimage,Set.mem_pi,Set.mem_prod,Finset.mem_coe,Finset.mem_erase] + constructor + · intro h + refine ⟨fun i hi => ?_,?_⟩ + · simpa only [Function.update_of_ne hi.1] using h i hi.2 + · simpa only [Function.update_self] using h p hp + · rintro ⟨ha,hb⟩ i hi + by_cases hip : i=p + · subst i; simpa only [Function.update_self] using hb + · simpa only [Function.update_of_ne hip] using ha i ⟨hip,hi⟩ + rw [he,Measure.prod_prod,Measure.infinitePi_pi _ (fun i _ => ht i)] + exact Finset.prod_erase_mul _ _ hp + · have he : (fun a : (ℕ→X) × X => Function.update a.1 p a.2) ⁻¹' Set.pi s t = + (Set.pi s t) ×ˢ (univ : Set X) := by + ext a + simp only [Set.mem_preimage,Set.mem_pi,Set.mem_prod,Set.mem_univ,and_true,Finset.mem_coe] + exact forall_congr' fun i => by + by_cases hi : i∈s + · have hip : i≠p := fun h => hp (h ▸ hi) + simp only [hi,true_implies,Function.update_of_ne hip] + · simp only [hi,false_implies] + rw [he,Measure.prod_prod,measure_univ,mul_one,Measure.infinitePi_pi _ (fun i _ => ht i)] + +def bulkParameterUniform : Measure ℝ := volume.restrict (Ioc (1:ℝ) 2) + +instance : IsProbabilityMeasure bulkParameterUniform := ⟨by norm_num [bulkParameterUniform]⟩ + +def bulkParameterLaw : Measure (ℕ→ℝ) := Measure.infinitePi fun _ : ℕ => bulkParameterUniform + +instance : IsProbabilityMeasure bulkParameterLaw := by unfold bulkParameterLaw; infer_instance + +lemma bulkParameterLaw_ae : ∀ᵐ v ∂bulkParameterLaw, ∀ j, v j∈Icc (1:ℝ) 2 := by + rw [ae_all_iff] + intro j + have he : ∀ᵐ x ∂bulkParameterUniform, x∈Icc (1:ℝ) 2 := + (ae_restrict_mem measurableSet_Ioc).mono fun _ hx => ⟨hx.1.le,hx.2⟩ + exact (measurePreserving_eval_infinitePi (fun _ : ℕ => bulkParameterUniform) j).quasiMeasurePreserving.ae he + +lemma bulkParameterLaw_integral_resample (p : ℕ) {F : (ℕ→ℝ)→ℝ} + (hF : Integrable F bulkParameterLaw) : + (∫ v, F v ∂bulkParameterLaw) = ∫ v, (∫ u in (1:ℝ)..2, + F (Function.update v p u)) ∂bulkParameterLaw := by + have hm := infinitePi_update_measurePreserving bulkParameterUniform p + change MeasurePreserving (fun a : (ℕ→ℝ) × ℝ => Function.update a.1 p a.2) + (bulkParameterLaw.prod bulkParameterUniform) bulkParameterLaw at hm + have hi : Integrable (fun a : (ℕ→ℝ) × ℝ => F (Function.update a.1 p a.2)) + (bulkParameterLaw.prod bulkParameterUniform) := hm.integrable_comp hF.aestronglyMeasurable |>.mpr hF + calc + _ = ∫ a : (ℕ→ℝ) × ℝ, F (Function.update a.1 p a.2) ∂(bulkParameterLaw.prod bulkParameterUniform) := + by + have hh : AEStronglyMeasurable F (Measure.map (fun a : (ℕ→ℝ) × ℝ => Function.update a.1 p a.2) + (bulkParameterLaw.prod bulkParameterUniform)) := by rw [hm.map_eq]; exact hF.aestronglyMeasurable + simpa only [hm.map_eq] using integral_map hm.measurable.aemeasurable hh + _ = ∫ v, ∫ u, F (Function.update v p u) ∂bulkParameterUniform ∂bulkParameterLaw := integral_prod _ hi + _ = _ := by simp only [bulkParameterUniform,intervalIntegral.integral_of_le (by norm_num : (1:ℝ)≤2)] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/PiMarkLaw.lean b/lean/OAI/Probability/Perceptron/Variational/PiMarkLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..f857466d55fbdc6de4410d849a0e2fc874a74ef8 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/PiMarkLaw.lean @@ -0,0 +1,429 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ProductMarkLaw + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy + +def piMarkLaw {ι S : Type} [Fintype ι] [MeasurableSpace S] + (ν : ι → ProbabilityMeasure S) : ProbabilityMeasure (ι → S) := + ⟨Measure.pi (fun i => (ν i : Measure S)),inferInstance⟩ + +lemma fractional_log_moment_sum_pi {ι S : Type} [Fintype ι] [MeasurableSpace S] + (ν : ι → ProbabilityMeasure S) (b : ℝ) (f : ι → S → ℝ) + (hI : ∀ i, Integrable (fun s => Real.exp (b*f i s)) (ν i)) : + (Integrable (fun s : ι → S => Real.exp (b*∑ i, f i (s i))) (piMarkLaw ν)) ∧ + Real.log (∫ s, Real.exp (b*∑ i, f i (s i)) ∂(piMarkLaw ν : Measure (ι → S)))/b = + ∑ i, Real.log (∫ s, Real.exp (b*f i s) ∂(ν i : Measure S))/b := by + simp_rw [Finset.mul_sum,Real.exp_sum] + constructor + · exact Integrable.fintype_prod hI + · change Real.log (∫ s, ∏ i, Real.exp (b*f i (s i)) ∂Measure.pi (fun i => (ν i : Measure S)))/b = _ + rw [integral_fintype_prod_eq_prod (fun i s => Real.exp (b*f i s)),Real.log_prod (fun i _ => (integral_exp_pos (hI i)).ne'),Finset.sum_div] + +theorem finiteCascade_sum_pi {ι X S : Type} [Fintype ι] + [MeasurableSpace X] [MeasurableSpace S] + (ν : ι → ProbabilityMeasure S) (step : ι → X×S → X) + (n : ℕ) (z : Fin n → ℝ) (H : ι → X → ℝ) + (hI : ∀ i, finiteCascadeFractionalIntegrable (ν i) (step i) (H i) n z) : + (∀ x, finiteCascadeLogRecursion (piMarkLaw ν) + (fun p : (ι → X)×(ι → S) => fun i => step i (p.1 i,p.2 i)) n z + (fun x => ∑ i, H i (x i)) x = + ∑ i, finiteCascadeLogRecursion (ν i) (step i) n z (H i) (x i)) ∧ + finiteCascadeFractionalIntegrable (piMarkLaw ν) + (fun p : (ι → X)×(ι → S) => fun i => step i (p.1 i,p.2 i)) + (fun x => ∑ i, H i (x i)) n z := by + induction n with + | zero => exact ⟨fun _ => rfl,trivial⟩ + | succ n ih => + obtain ⟨heq,htail⟩ := ih (fun j => z j.succ) (fun i => (hI i).2) + constructor + · intro x + conv_lhs => rw [finiteCascadeLogRecursion] + unfold fractionalLogMoment + simp_rw [heq] + exact (fractional_log_moment_sum_pi ν (z 0) + (fun i s => finiteCascadeLogRecursion (ν i) (step i) n (fun j => z j.succ) (H i) (step i (x i,s))) + (fun i => (hI i).1 (x i))).2 + · refine ⟨?_,htail⟩ + intro x + simp_rw [heq] + exact (fractional_log_moment_sum_pi ν (z 0) + (fun i s => finiteCascadeLogRecursion (ν i) (step i) n (fun j => z j.succ) (H i) (step i (x i,s))) + (fun i => (hI i).1 (x i))).1 + +theorem finiteCascade_quadratic_coordinates (d : ℕ) (σ : ℕ → ℝ) (b : ℝ) (c : Fin d → ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, 0 < z i) + (hp : 0 < quadraticCascadePrecision σ b n z) : + (∀ x, finiteCascadeLogRecursion (piMarkLaw (fun _ : Fin d => standardGaussianMark)) + (fun p : (Fin d → ℕ → ℝ)×(Fin d → ℝ) => fun i => gaussianShiftStep σ (p.1 i,p.2 i)) n z + (fun x => ∑ i, (c i+(x i 0)^2/(2*b))) x = + (∑ i, c i) + d*quadraticCascadeOffset σ b n z+ + (∑ i, (x i n)^2)/(2*quadraticCascadePrecision σ b n z)) ∧ + finiteCascadeFractionalIntegrable (piMarkLaw (fun _ : Fin d => standardGaussianMark)) + (fun p : (Fin d → ℕ → ℝ)×(Fin d → ℝ) => fun i => gaussianShiftStep σ (p.1 i,p.2 i)) + (fun x => ∑ i, (c i+(x i 0)^2/(2*b))) n z := by + have hq := finiteCascade_sum_pi (fun _ : Fin d => standardGaussianMark) + (fun _ => gaussianShiftStep σ) n z (fun i x => c i+(x 0)^2/(2*b)) + (fun i => (finiteCascade_quadratic_recursion σ b (c i) n z hz hp).2) + refine ⟨?_,hq.2⟩ + intro x + rw [hq.1] + simp_rw [(finiteCascade_quadratic_recursion σ b _ n z hz hp).1] + simp only [Finset.sum_add_distrib,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,Finset.sum_div] + +def canonicalCoordinateStep (d : ℕ) (σ : ℕ → ℝ) : + (Fin d → ℕ → ℝ)×(Fin d → ℝ) → (Fin d → ℕ → ℝ) := + fun p i => gaussianShiftStep σ (p.1 i,p.2 i) + +lemma canonicalCoordinateStep_measurable (d : ℕ) (σ : ℕ → ℝ) : + Measurable (canonicalCoordinateStep d σ) := by + apply Measurable.of_eval + intro i + exact (gaussianShiftStep_measurable σ).comp + (((measurable_pi_apply i).comp measurable_fst).prodMk ((measurable_pi_apply i).comp measurable_snd)) + +def canonicalCoordinatePotential (d : ℕ) (b : ℝ) (x : Fin d → ℕ → ℝ) : ℝ := + ∑ i, (-Real.log b/2+(x i 0)^2/(2*b)) + +lemma canonicalCoordinatePotential_measurable (d : ℕ) (b : ℝ) : + Measurable (canonicalCoordinatePotential d b) := by unfold canonicalCoordinatePotential; fun_prop + +lemma canonical_coordinate_spin_log (d : ℕ) {b : ℝ} (hb : 0 < b) (u : Fin d → ℝ) : + Real.log (∫ y : Fin d → ℝ, Real.exp ((1-b)*(∑ i, (y i)^2)/2+∑ i, u i*y i) + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∑ i, (-Real.log b/2+(u i)^2/(2*b)) := by + have he : (fun y : Fin d → ℝ => Real.exp ((1-b)*(∑ i, (y i)^2)/2+∑ i, u i*y i)) = + (fun y => ∏ i, Real.exp ((1-b)*(y i)^2/2+u i*y i)) := by + funext y + rw [← Real.exp_sum] + congr 1 + simp only [Finset.sum_add_distrib,Finset.sum_div,Finset.mul_sum] + rw [he,integral_fintype_prod_eq_prod (fun i y => Real.exp ((1-b)*y^2/2+u i*y))] + rw [Real.log_prod (fun i _ => (integral_exp_pos (canonical_scalar_integrable hb (u i))).ne')] + simp_rw [canonical_scalar_log hb] + +def canonicalCoordinateLog (d n : ℕ) (σ : ℕ → ℝ) (b : ℝ) + (p : (Fin d → ℕ → ℝ)×DecoratedCascade (Fin d → ℝ) n) : ℝ := + Real.log (decoratedTerminalTotal (canonicalCoordinateStep d σ) (canonicalCoordinatePotential d b) n p / + decoratedTerminalTotal (canonicalCoordinateStep d σ) (fun _ => 0) n p) + +lemma canonical_coordinate_recursion (d : ℕ) (σ : ℕ → ℝ) (b : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, 0 < z i) + (hp : 0 < quadraticCascadePrecision σ b n z) : + (∀ x, finiteCascadeLogRecursion (piMarkLaw (fun _ : Fin d => standardGaussianMark)) + (canonicalCoordinateStep d σ) n z (canonicalCoordinatePotential d b) x = + d*(-Real.log b/2+quadraticCascadeOffset σ b n z)+ + (∑ i, (x i n)^2)/(2*quadraticCascadePrecision σ b n z)) ∧ + finiteCascadeFractionalIntegrable (piMarkLaw (fun _ : Fin d => standardGaussianMark)) + (canonicalCoordinateStep d σ) (canonicalCoordinatePotential d b) n z := by + have he := finiteCascade_quadratic_coordinates d σ b (fun _ => -Real.log b/2) n z hz hp + refine ⟨?_,he.2⟩ + intro x + unfold canonicalCoordinateStep canonicalCoordinatePotential + rw [he.1] + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,mul_add] + +theorem canonical_coordinate_log_mean (d : ℕ) (σ : ℕ → ℝ) (b : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b n z) (x : Fin d → ℕ → ℝ) : + (∫ η, canonicalCoordinateLog d n σ b (x,η) + ∂decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) n z) = + d*(-Real.log b/2+quadraticCascadeOffset σ b n z)+ + (∑ i, (x i n)^2)/(2*quadraticCascadePrecision σ b n z) := by + unfold canonicalCoordinateLog + rw [finiteCascade_terminal_log_recursion_of_fractional _ _ (canonicalCoordinateStep_measurable d σ) + n z hz hz0 hz1 (canonicalCoordinatePotential_measurable d b) + (canonical_coordinate_recursion d σ b n z hz0 hp).2] + exact (canonical_coordinate_recursion d σ b n z hz0 hp).1 x + +lemma canonical_coordinate_log_deviation_le (d : ℕ) (σ : ℕ → ℝ) (b : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b n z) (x : Fin d → ℕ → ℝ) {ε : ℝ} (hε : 0 < ε) : + (decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) n z : + Measure (DecoratedCascade (Fin d → ℝ) n)) + {η | ε ≤ |canonicalCoordinateLog d n σ b (x,η)- + (d*(-Real.log b/2+quadraticCascadeOffset σ b n z)+ + (∑ i, (x i n)^2)/(2*quadraticCascadePrecision σ b n z))|} ≤ + ENNReal.ofReal (cascadeLogFluctuationConstant n z/ε^2) := by + have he := finiteCascade_terminal_log_deviation_le _ _ (canonicalCoordinateStep_measurable d σ) + n z hz hz0 hz1 (canonicalCoordinatePotential_measurable d b) + (canonical_coordinate_recursion d σ b n z hz0 hp).2 x hε + rw [(canonical_coordinate_recursion d σ b n z hz0 hp).1 x] at he + exact he + +lemma gaussian_square_memLp_two (r : ℝ≥0) : MemLp (fun y : ℝ => y^2) 2 (gaussianReal 0 r) := by + have : ENNReal.HolderTriple (4 : ℝ≥0∞) 4 2 := by + apply (ENNReal.holderTriple_coe_iff (p := 4) (q := 4) (r := 2) (by norm_num)).mpr + norm_num [NNReal.holderTriple_iff] + have h4 : MemLp (fun y : ℝ => y) (4 : ℝ≥0∞) (gaussianReal 0 r) := memLp_id_gaussianReal 4 + have hm : MemLp (fun y : ℝ => y*y) 2 (gaussianReal 0 r) := + h4.mul h4 + simpa [pow_two] using hm + +lemma gaussian_square_mean (r : ℝ≥0) : (∫ y, y^2 ∂gaussianReal 0 r) = r := by + have he := variance_fun_id_gaussianReal (μ := 0) (v := r) + rw [variance_eq_integral (by fun_prop : AEMeasurable (fun x : ℝ => x) (gaussianReal 0 r))] at he + simpa only [integral_id_gaussianReal,sub_zero] using he + +lemma gaussian_square_sum_memLp_two (d : ℕ) (r : ℝ≥0) : + MemLp (fun y : Fin d → ℝ => ∑ i, (y i)^2) 2 (Measure.pi (fun _ => gaussianReal 0 r)) := by + exact memLp_finsetSum _ (fun i _ => (gaussian_square_memLp_two r).comp_measurePreserving (measurePreserving_eval _ i)) + +lemma gaussian_square_sum_mean (d : ℕ) (r : ℝ≥0) : + (∫ y : Fin d → ℝ, ∑ i, (y i)^2 ∂Measure.pi (fun _ => gaussianReal 0 r)) = d*r := by + have hi : ∀ i : Fin d, Integrable (fun y : Fin d → ℝ => (y i)^2) (Measure.pi (fun _ => gaussianReal 0 r)) := + fun i => ((gaussian_square_memLp_two r).comp_measurePreserving + (measurePreserving_eval (fun _ : Fin d => gaussianReal 0 r) i)).integrable (by norm_num) + rw [integral_finsetSum Finset.univ (fun i _ => hi i)] + have hj : ∀ i : Fin d, (∫ y : Fin d → ℝ, (y i)^2 ∂Measure.pi (fun _ => gaussianReal 0 r)) = r := by + intro i + rw [integral_comp_eval (μ := fun _ : Fin d => gaussianReal 0 r) (i := i) (by fun_prop : AEStronglyMeasurable (fun y : ℝ => y^2) (gaussianReal 0 r))] + exact gaussian_square_mean r + simp_rw [hj] + simp + +lemma gaussian_square_sum_variance (d : ℕ) (r : ℝ≥0) : + variance (fun y : Fin d → ℝ => ∑ i, (y i)^2) (Measure.pi (fun _ => gaussianReal 0 r)) = + d*variance (fun y : ℝ => y^2) (gaussianReal 0 r) := by + have he := variance_sum_pi (μ := fun _ : Fin d => gaussianReal 0 r) (fun _ => gaussian_square_memLp_two r) + have hs : (∑ i : Fin d, fun ω : Fin d → ℝ => (ω i)^2) = (fun ω => ∑ i, (ω i)^2) := by ext ω; simp + rw [hs] at he + simpa only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] using he + +lemma gaussian_square_average_deviation_le (d : ℕ) (hd : 0 < d) (r : ℝ≥0) + {ε : ℝ} (hε : 0 < ε) : + (Measure.pi (fun _ : Fin d => gaussianReal 0 r)) + {y | ε ≤ |(∑ i, (y i)^2)/(d : ℝ)-r|} ≤ + ENNReal.ofReal (variance (fun y : ℝ => y^2) (gaussianReal 0 r)/(d*ε^2)) := by + have hd' : 0 < (d : ℝ) := Nat.cast_pos.mpr hd + have hc := meas_ge_le_variance_div_sq (gaussian_square_sum_memLp_two d r) (mul_pos hε hd') + rw [gaussian_square_sum_mean,gaussian_square_sum_variance] at hc + have hset : {y : Fin d → ℝ | ε ≤ |(∑ i, (y i)^2)/(d : ℝ)-r|} = + {y | ε*(d : ℝ) ≤ |(∑ i, (y i)^2)-(d : ℝ)*r|} := by + ext y + have he : (∑ i, (y i)^2)/(d : ℝ)-r = ((∑ i, (y i)^2)-(d : ℝ)*r)/(d : ℝ) := by field_simp + simp only [Set.mem_ofPred_eq,he,abs_div,abs_of_pos hd'] + exact le_div_iff₀ hd' + rw [hset] + convert hc using 2 + field_simp [hd'.ne',hε.ne'] + +lemma decoratedTerminalTotal_measurable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) {H : X → ℝ} + (hH : Measurable H) (n : ℕ) (z : Fin n → ℝ) : Measurable (decoratedTerminalTotal step H n) := by + have he : decoratedTerminalTotal step H n = fun p => + Real.exp (finiteCascadeLogRecursion ν step n z H p.1) * + decoratedWeightedTotal step n (finiteCascadeShifts ν step n z H) p := by + funext p + exact decoratedTerminalTotal_telescoping ν step H n z p + rw [he] + exact (((finiteCascadeLogRecursion_measurable ν step hs n z hH).comp measurable_fst).exp).mul + (decoratedWeightedTotalE_measurable step hs n _ (finiteCascadeShifts_measurable ν step hs n z hH)).ennreal_toReal + +lemma canonicalCoordinateLog_measurable (d n : ℕ) (σ : ℕ → ℝ) (b : ℝ) (z : Fin n → ℝ) : + Measurable (canonicalCoordinateLog d n σ b) := by + exact ((decoratedTerminalTotal_measurable (piMarkLaw (fun _ : Fin d => standardGaussianMark)) _ + (canonicalCoordinateStep_measurable d σ) (canonicalCoordinatePotential_measurable d b) n z).div + (decoratedTerminalTotal_measurable (piMarkLaw (fun _ : Fin d => standardGaussianMark)) _ + (canonicalCoordinateStep_measurable d σ) measurable_const n z)).log + +lemma product_deviation_le {X Y : Type} [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure X) (ν : Measure Y) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + {F : X×Y → ℝ} {G : X → ℝ} (hF : Measurable F) (hG : Measurable G) + (c ε : ℝ) (A : ℝ≥0∞) + (hbound : ∀ x, ν {y | ε/2 ≤ |F (x,y)-G x|} ≤ A) : + μ.prod ν {p | ε ≤ |F p-c|} ≤ A+μ {x | ε/2 ≤ |G x-c|} := by + have hsub : {p : X×Y | ε ≤ |F p-c|} ⊆ + {p | ε/2 ≤ |F p-G p.1|} ∪ {p | ε/2 ≤ |G p.1-c|} := by + intro p hp + by_contra hh + simp only [Set.mem_union,Set.mem_ofPred_eq,not_or,not_le] at hh + have ht := abs_sub_le (F p) (G p.1) c + dsimp only [Set.mem_ofPred_eq] at hp + linarith + have hA : μ.prod ν {p : X×Y | ε/2 ≤ |F p-G p.1|} ≤ A := by + rw [Measure.prod_apply (by measurability)] + calc + _ ≤ ∫⁻ _ : X, A ∂μ := lintegral_mono hbound + _ = A := by simp + have hB : μ.prod ν {p : X×Y | ε/2 ≤ |G p.1-c|} = μ {x | ε/2 ≤ |G x-c|} := by + have hs : {p : X×Y | ε/2 ≤ |G p.1-c|} = {x | ε/2 ≤ |G x-c|} ×ˢ Set.univ := by ext p; simp + rw [hs,Measure.prod_prod] + simp + exact (measure_mono hsub).trans ((measure_union_le _ _).trans (by rw [hB]; exact add_le_add hA le_rfl)) + +theorem canonical_coordinate_joint_deviation_le (d : ℕ) (hd : 0 < d) (σ : ℕ → ℝ) (b : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b n z) (r : ℝ≥0) {ε : ℝ} (hε : 0 < ε) : + ((Measure.pi (fun _ : Fin d => gaussianReal 0 r)).prod + (decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) n z : + Measure (DecoratedCascade (Fin d → ℝ) n))) + {p | ε*(d : ℝ) ≤ |canonicalCoordinateLog d n σ b ((fun i _ => p.1 i),p.2)- + d*canonicalGaussianFreeValue σ n z r b|} ≤ + ENNReal.ofReal (cascadeLogFluctuationConstant n z/(ε*d/2)^2)+ + ENNReal.ofReal (variance (fun y : ℝ => y^2) (gaussianReal 0 r)/ + (d*(ε*quadraticCascadePrecision σ b n z)^2)) := by + let P := quadraticCascadePrecision σ b n z + let a := -Real.log b/2+quadraticCascadeOffset σ b n z + let G := fun y : Fin d → ℝ => (d : ℝ)*a+(∑ i, (y i)^2)/(2*P) + let F := fun p : (Fin d → ℝ)×DecoratedCascade (Fin d → ℝ) n => + canonicalCoordinateLog d n σ b ((fun i _ => p.1 i),p.2) + have hP : 0 < P := hp + have hd' : 0 < (d : ℝ) := Nat.cast_pos.mpr hd + have hF : Measurable F := (canonicalCoordinateLog_measurable d n σ b z).comp (by fun_prop) + have hG : Measurable G := by dsimp [G]; fun_prop + have hc := product_deviation_le (Measure.pi (fun _ : Fin d => gaussianReal 0 r)) + (decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) n z : + Measure (DecoratedCascade (Fin d → ℝ) n)) hF hG + (d*canonicalGaussianFreeValue σ n z r b) (ε*d) + (ENNReal.ofReal (cascadeLogFluctuationConstant n z/(ε*d/2)^2)) + (fun y => canonical_coordinate_log_deviation_le d σ b n z hz hz0 hz1 hp + (fun i _ => y i) (half_pos (mul_pos hε hd'))) + apply hc.trans + apply add_le_add le_rfl + have hset : {y : Fin d → ℝ | ε*(d : ℝ)/2 ≤ |G y-d*canonicalGaussianFreeValue σ n z r b|} = + {y | ε*P ≤ |(∑ i, (y i)^2)/(d : ℝ)-r|} := by + ext y + have he : G y-d*canonicalGaussianFreeValue σ n z r b = + ((d : ℝ)/(2*P))*((∑ i, (y i)^2)/(d : ℝ)-r) := by + dsimp [G,a,canonicalGaussianFreeValue] + change (d : ℝ)*(-Real.log b/2+quadraticCascadeOffset σ b n z)+ + (∑ i, (y i)^2)/(2*P)-d*(-Real.log b/2+quadraticCascadeOffset σ b n z+r/(2*P)) = _ + field_simp [hd'.ne',hP.ne'] + ring + have hf : 0 < (d : ℝ)/(2*P) := by positivity + simp only [Set.mem_ofPred_eq,he,abs_mul,abs_of_pos hf] + rw [mul_comm ((d : ℝ)/(2*P)),←div_le_iff₀ hf] + field_simp [hd'.ne',hP.ne'] + rw [hset] + exact gaussian_square_average_deviation_le d hd r (mul_pos hε hP) + +theorem canonical_coordinate_converges (σ : ℕ → ℝ) (b : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b n z) (r : ℝ≥0) {ε : ℝ} (hε : 0 < ε) : + Tendsto (fun d : ℕ => + ((Measure.pi (fun _ : Fin d => gaussianReal 0 r)).prod + (decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) n z : + Measure (DecoratedCascade (Fin d → ℝ) n))) + {p | ε*(d : ℝ) ≤ |canonicalCoordinateLog d n σ b ((fun i _ => p.1 i),p.2)- + d*canonicalGaussianFreeValue σ n z r b|}) atTop (𝓝 0) := by + have hd : Tendsto (fun d : ℕ => (d : ℝ)) atTop atTop := tendsto_natCast_atTop_atTop + have ht : Tendsto (fun d : ℕ => (ε*(d : ℝ)/2)^2) atTop atTop := + (tendsto_pow_atTop (by norm_num : (2 : ℕ) ≠ 0)).comp + ((hd.const_mul_atTop hε).atTop_div_const (by norm_num)) + have hu : Tendsto (fun d : ℕ => (d : ℝ)*(ε*quadraticCascadePrecision σ b n z)^2) atTop atTop := + hd.atTop_mul_const (sq_pos_of_pos (mul_pos hε hp)) + have ht0 : Tendsto (fun d : ℕ => cascadeLogFluctuationConstant n z/(ε*(d : ℝ)/2)^2) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop ht + have hu0 : Tendsto (fun d : ℕ => variance (fun y : ℝ => y^2) (gaussianReal 0 r)/ + ((d : ℝ)*(ε*quadraticCascadePrecision σ b n z)^2)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop hu + have hsum : Tendsto (fun d : ℕ => ENNReal.ofReal (cascadeLogFluctuationConstant n z/(ε*(d : ℝ)/2)^2)+ + ENNReal.ofReal (variance (fun y : ℝ => y^2) (gaussianReal 0 r)/ + ((d : ℝ)*(ε*quadraticCascadePrecision σ b n z)^2))) atTop (𝓝 0) := by + simpa using (ENNReal.tendsto_ofReal ht0).add (ENNReal.tendsto_ofReal hu0) + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hsum + · exact Eventually.of_forall (fun _ => bot_le) + · filter_upwards [eventually_gt_atTop 0] with d hdpos + exact canonical_coordinate_joint_deviation_le d hdpos σ b n z hz hz0 hz1 hp r hε + +lemma exponential_ratio_converges {Ω : ℕ → Type} [∀ d, MeasurableSpace (Ω d)] (μ : ∀ d, Measure (Ω d)) + (X Y : ∀ d, Ω d → ℝ) (x y a : ℝ) (hrate : y-x < a) + (hX : ∀ ε > 0, Tendsto (fun d => μ d {p | ε*(d : ℝ) ≤ |X d p-d*x|}) atTop (𝓝 0)) + (hY : ∀ ε > 0, Tendsto (fun d => μ d {p | ε*(d : ℝ) ≤ |Y d p-d*y|}) atTop (𝓝 0)) + {ρ : ℝ} (hρ : 0 < ρ) : + Tendsto (fun d => μ d {p | ρ ≤ Real.exp (Y d p-X d p-(d : ℝ)*a)}) atTop (𝓝 0) := by + let ε := (a-(y-x))/4 + have hε : 0 < ε := by dsimp [ε]; linarith + have ht : Tendsto (fun d : ℕ => ε*(d : ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.const_mul_atTop hε + have he : ∀ᶠ d : ℕ in atTop, -Real.log ρ < ε*(d : ℝ) := ht.eventually (eventually_gt_atTop _) + have hb : ∀ᶠ d : ℕ in atTop, + μ d {p | ρ ≤ Real.exp (Y d p-X d p-(d : ℝ)*a)} ≤ + μ d {p | ε*(d : ℝ) ≤ |X d p-d*x|}+μ d {p | ε*(d : ℝ) ≤ |Y d p-d*y|} := by + filter_upwards [he,eventually_gt_atTop 0] with d hd hdpos + apply le_trans (measure_mono (t := + {p | ε*(d : ℝ) ≤ |X d p-d*x|} ∪ {p | ε*(d : ℝ) ≤ |Y d p-d*y|}) ?_) (measure_union_le _ _) + intro p hp + by_contra hh + simp only [Set.mem_union,Set.mem_ofPred_eq,not_or,not_le] at hh + have hx := (abs_lt.mp hh.1).1 + have hy := (abs_lt.mp hh.2).2 + have hp' : Real.log ρ ≤ Y d p-X d p-(d : ℝ)*a := by + simpa only [Real.log_exp] using Real.log_le_log hρ hp + have hd' : 0 < (d : ℝ) := Nat.cast_pos.mpr hdpos + have ha : a = y-x+4*ε := by dsimp [ε]; ring + rw [ha] at hp' + nlinarith + have hs := (hX ε hε).add (hY ε hε) + simp only [add_zero] at hs + exact tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds hs + (Eventually.of_forall (fun _ => bot_le)) hb + +theorem canonical_ratio_converges (σ : ℕ → ℝ) (b b' a : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b n z) + (hp' : 0 < quadraticCascadePrecision σ b' n z) (r : ℝ≥0) + (hrate : canonicalGaussianFreeValue σ n z r b'-canonicalGaussianFreeValue σ n z r b < a) + {ρ : ℝ} (hρ : 0 < ρ) : + Tendsto (fun d : ℕ => + ((Measure.pi (fun _ : Fin d => gaussianReal 0 r)).prod + (decoratedCascadeLaw (piMarkLaw (fun _ : Fin d => standardGaussianMark)) n z : + Measure (DecoratedCascade (Fin d → ℝ) n))) + {p | ρ ≤ Real.exp + (canonicalCoordinateLog d n σ b' ((fun i _ => p.1 i),p.2)- + canonicalCoordinateLog d n σ b ((fun i _ => p.1 i),p.2)-(d : ℝ)*a)}) atTop (𝓝 0) := by + apply exponential_ratio_converges _ _ _ _ _ _ hrate + · exact fun ε hε => canonical_coordinate_converges σ b n z hz hz0 hz1 hp r hε + · exact fun ε hε => canonical_coordinate_converges σ b' n z hz hz0 hz1 hp' r hε + · exact hρ + +lemma canonical_stationary_tail_rates (σ : ℕ → ℝ) (n : ℕ) (z : Fin n → ℝ) + (hz : ∀ i, 0 ≤ z i) (r b : ℝ) (hp : 0 < quadraticCascadePrecision σ b n z) + (hstat : -1/(2*b)+quadraticCascadeReciprocalSlope σ b n z- + r/(2*(quadraticCascadePrecision σ b n z)^2) = -1/2) + {ε : ℝ} (hε : 0 < ε) : ∃ δ : ℝ, 0 < δ ∧ + 0 < quadraticCascadePrecision σ (b-δ) n z ∧ + 0 < quadraticCascadePrecision σ (b+δ) n z ∧ + canonicalGaussianFreeValue σ n z r (b-δ)-canonicalGaussianFreeValue σ n z r b < δ*(1+ε)/2 ∧ + canonicalGaussianFreeValue σ n z r (b+δ)-canonicalGaussianFreeValue σ n z r b < -δ*(1-ε)/2 := by + let C := canonicalGaussianFreeValue σ n z r + have hf : HasDerivAt C (-1/2) b := by + simpa only [hstat] using canonicalGaussianFreeValue_hasDerivAt σ n z hz r hp + have hlin := hf.isLittleO.def (by positivity : 0 < ε/4) + have hpos : ∀ᶠ t in 𝓝 b, 0 < quadraticCascadePrecision σ t n z := + (quadraticCascadePrecision_hasDerivAt σ n z b).continuousAt.eventually (eventually_gt_nhds hp) + obtain ⟨η,hη,hboth⟩ := Metric.eventually_nhds_iff.mp (hlin.and hpos) + let δ := η/2 + have hδ : 0 < δ := by dsimp [δ]; positivity + have hdη : δ < η := by dsimp [δ]; linarith + have hleft : dist (b-δ) b < η := by simpa [Real.dist_eq,abs_of_nonneg hδ.le] using hdη + have hright : dist (b+δ) b < η := by simpa [Real.dist_eq,abs_of_nonneg hδ.le] using hdη + obtain ⟨hl,hlp⟩ := hboth hleft + obtain ⟨hr,hrp⟩ := hboth hright + simp only [Real.norm_eq_abs,smul_eq_mul] at hl hr + have hdl : b-δ-b = -δ := by ring + have hdr : b+δ-b = δ := by ring + rw [hdl,abs_neg,abs_of_pos hδ] at hl + rw [hdr,abs_of_pos hδ] at hr + refine ⟨δ,hδ,hlp,hrp,?_,?_⟩ + · have := (abs_le.mp hl).2 + dsimp only [C] at this + nlinarith [mul_pos hε hδ] + · have := (abs_le.mp hr).2 + dsimp only [C] at this + nlinarith [mul_pos hε hδ] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/PointedShape.lean b/lean/OAI/Probability/Perceptron/Variational/PointedShape.lean new file mode 100644 index 0000000000000000000000000000000000000000..8efa33673ec9efe1127b128d28c29816c5569e1f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/PointedShape.lean @@ -0,0 +1,180 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ShapeSampleLaw + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set +open scoped Classical ENNReal NNReal BigOperators + +lemma cascadeShapeFocus_cast (n : ℕ) {s t : CascadeVisitShape n} + (h : s = t) (hs : s.Valid n) (ht : t.Valid n) : + cast (congrArg (CascadeShapeReplicas n) h) (cascadeShapeFocus n s hs) = + cascadeShapeFocus n t ht := by + cases h + rfl + +lemma cascadeShapeReplicasOfFn_focus (n m : ℕ) (hm : 0 < m) + (ss : Fin m → CascadeVisitShape n) (hv : ∀ i, (ss i).Valid n) + (hs : CascadeVisitShape.Valid (n+1) (List.ofFn ss)) : + cascadeShapeReplicasOfFnEquiv n m ss ⟨⟨0,hm⟩,cascadeShapeFocus n (ss ⟨0,hm⟩) (hv _)⟩ = + cascadeShapeFocus (n+1) (List.ofFn ss) hs := by + simp only [cascadeShapeReplicasOfFnEquiv,Equiv.sigmaCongr,cascadeShapeFocus] + apply Sigma.ext (by rfl) + have hlen : 0 < (List.ofFn ss).length := by simpa using hm + have h : (List.ofFn ss)[0] = ss ⟨0,hm⟩ := by simp + change HEq (cast _ (cascadeShapeFocus n (ss ⟨0,hm⟩) (hv _))) + (cascadeShapeFocus n (List.ofFn ss)[0] (hs.2 _ (List.getElem_mem hlen))) + exact heq_of_eq (cascadeShapeFocus_cast n h.symm (hv _) (hs.2 _ (List.getElem_mem (by simpa using hm)))) + +theorem finite_leaf_tuple_pointed_shape (n : ℕ) : + ∀ (ι : Type) [Fintype ι] (xs : ι → IndexedLeaf n) (i₀ : ι), + ∃ s : CascadeVisitShape n, ∃ hs : s.Valid n, + ∃ e : ι ≃ CascadeShapeReplicas n s, + e i₀ = cascadeShapeFocus n s hs ∧ + ∀ i j, indexedCommonDepth n (xs i) (xs j) = + indexedCommonDepth n (cascadeShapeLeaves n s (e i)) + (cascadeShapeLeaves n s (e j)) := by + classical + induction n with + | zero => + intro ι _ xs i₀ + let : Nonempty ι := ⟨i₀⟩ + let e := Fintype.equivFin ι + let z : Fin (Fintype.card ι) := ⟨0,Fintype.card_pos⟩ + refine ⟨Fintype.card ι,Fintype.card_pos,e.trans (Equiv.swap (e i₀) z),?_,fun _ _ => rfl⟩ + exact Equiv.swap_apply_left (e i₀) z + | succ n ih => + intro ι _ xs i₀ + let : Nonempty ι := ⟨i₀⟩ + let root : ι → ℕ×ℕ := fun i => ((xs i).1,(xs i).2.1) + let V := Set.range root + let : Fintype V := (Set.finite_range root).fintype + let g₀ : ι → V := fun i => ⟨root i,⟨i,rfl⟩⟩ + have hg₀ : Function.Surjective g₀ := by + rintro ⟨v,i,hi⟩ + exact ⟨i,Subtype.ext hi⟩ + let : Nonempty V := Nonempty.map g₀ inferInstance + let z : Fin (Fintype.card V) := ⟨0,Fintype.card_pos⟩ + let eV := (Fintype.equivFin V).trans (Equiv.swap ((Fintype.equivFin V) (g₀ i₀)) z) + let g : ι → Fin (Fintype.card V) := fun i => eV (g₀ i) + have hg : Function.Surjective g := eV.surjective.comp hg₀ + have hgzero : g i₀ = z := Equiv.swap_apply_left _ _ + have hroot (i j : ι) : g i = g j ↔ (xs i).1 = (xs j).1 ∧ (xs i).2.1 = (xs j).2.1 := by + change eV (g₀ i) = eV (g₀ j) ↔ _ + rw [Equiv.apply_eq_iff_eq,Subtype.ext_iff] + exact Prod.ext_iff + let J (a : Fin (Fintype.card V)) := {i : ι // g i = a} + let r (a : Fin (Fintype.card V)) : J a := + if h : a = z then ⟨i₀,hgzero.trans h.symm⟩ else + ⟨Classical.choose (hg a),Classical.choose_spec (hg a)⟩ + have hc (a : Fin (Fintype.card V)) := ih (J a) (fun i => (xs i.val).2.2) (r a) + choose ss hv ee hf he using hc + let s : CascadeVisitShape (n+1) := List.ofFn ss + have hs : s.Valid (n+1) := by + constructor + · apply List.length_pos_iff.mp + simpa only [s,List.length_ofFn] using (Fintype.card_pos (α := V)) + · intro t ht + obtain ⟨a,rfl⟩ := List.mem_ofFn.mp ht + exact hv a + let E : ι ≃ CascadeShapeReplicas (n+1) s := + ((Equiv.sigmaFiberEquiv g).symm.trans (Equiv.sigmaCongrRight ee)).trans + (cascadeShapeReplicasOfFnEquiv n (Fintype.card V) ss) + refine ⟨s,hs,E,?_,?_⟩ + · have hr : r z = ⟨i₀,hgzero⟩ := by simp [r] + have hE : E i₀ = cascadeShapeReplicasOfFnEquiv n (Fintype.card V) ss ⟨z,ee z (r z)⟩ := by + simp only [E,Equiv.trans_apply,Equiv.sigmaFiberEquiv,Equiv.coe_fn_mk, + Equiv.symm_mk,Equiv.sigmaCongrRight_apply] + have hi : (Sigma.mk (g i₀) ⟨i₀,rfl⟩ : Σ a, J a) = ⟨z,r z⟩ := by + rw [hr] + apply Sigma.ext hgzero + apply (Subtype.heq_iff_coe_eq (fun x => by simp only [hgzero])).mpr + rfl + exact congrArg (fun p : Σ a, J a => + cascadeShapeReplicasOfFnEquiv n (Fintype.card V) ss ⟨p.1,ee p.1 p.2⟩) hi + rw [hE,hf z] + exact cascadeShapeReplicasOfFn_focus n (Fintype.card V) Fintype.card_pos ss hv hs + · intro i j + obtain ⟨⟨a,i⟩,rfl⟩ := (Equiv.sigmaFiberEquiv g).surjective i + obtain ⟨⟨b,j⟩,rfl⟩ := (Equiv.sigmaFiberEquiv g).surjective j + have hE (a : Fin (Fintype.card V)) (i : J a) : + cascadeShapeLeaves (n+1) s (E ((Equiv.sigmaFiberEquiv g) ⟨a,i⟩)) = + (a.val,0,cascadeShapeLeaves n (ss a) (ee a i)) := by + simp only [E,Equiv.trans_apply,Equiv.symm_apply_apply, + Equiv.sigmaCongrRight_apply,s,cascadeShapeLeaves_ofFn] + rw [hE,hE] + change indexedCommonDepth (n+1) (xs i.val) (xs j.val) = _ + by_cases hab : a = b + · subst b + have hij : (xs i.val).1 = (xs j.val).1 ∧ (xs i.val).2.1 = (xs j.val).2.1 := + (hroot i.val j.val).mp (i.property.trans j.property.symm) + simp only [indexedCommonDepth,ite_eq_left hij,and_self,↓reduceIte] + exact congrArg Fin.succ (he a i j) + · have hij : ¬ ((xs i.val).1 = (xs j.val).1 ∧ (xs i.val).2.1 = (xs j.val).2.1) := by + intro hij + exact hab (i.property.symm.trans ((hroot i.val j.val).mpr hij) |>.trans j.property) + have habv : a.val ≠ b.val := fun h => hab (Fin.ext h) + simp only [indexedCommonDepth,ite_eq_right hij,habv,false_and,↓reduceIte] + +lemma ennreal_tsum_pi_focus (m : ℕ) (J : Fin (m+1) → Type*) + (f : ∀ i, J i → ℝ≥0∞) (g : J 0 → ℝ≥0∞) : + (∑' ys : ∀ i, J i, (∏ i, f i (ys i)) * g (ys 0)) = + (∑' y, f 0 y * g y) * ∏ i : Fin m, ∑' y, f i.succ y := by + rw [← (Fin.consEquiv J).tsum_eq, ENNReal.tsum_prod'] + simp only [Fin.consEquiv_apply, Fin.prod_univ_succ, Fin.cons_zero, Fin.cons_succ] + have he (a : J 0) (b : ∀ i : Fin m, J i.succ) : + (f 0 a * ∏ i, f i.succ (b i)) * g a = + (f 0 a * g a) * ∏ i, f i.succ (b i) := by ring + simp_rw [he, ENNReal.tsum_mul_left, ennreal_tsum_pi_prod, ENNReal.tsum_mul_right] + +lemma root_partition_sum_focused {A B : Type*} (m : ℕ) (J : Fin (m+1) → Type*) + [∀ i, Fintype (J i)] [∀ i, Nonempty (J i)] (r : J 0) + (p : A → ℝ≥0∞) (q : A → B → ℝ≥0∞) + (H : ∀ i, (J i → B) → ℝ≥0∞) (K : A → (J 0 → B) → ℝ≥0∞) : + (∑' xs : (Σ i, J i) → A × B, + if RootPartitionMatch xs then + ((∏ u, p (xs u).1 * q (xs u).1 (xs u).2) * + ∏ i, H i (fun j => (xs ⟨i,j⟩).2)) * + (p (xs ⟨0,r⟩).1 * K (xs ⟨0,r⟩).1 (fun j => (xs ⟨0,j⟩).2)) else 0) = + ∑' a : Fin (m+1) ↪ A, + (p (a 0)) ^ (Fintype.card (J 0)+1) * + (∑' ys : J 0 → B, ((∏ j, q (a 0) (ys j)) * H 0 ys) * K (a 0) ys) * + ∏ i : Fin m, (p (a i.succ)) ^ Fintype.card (J i.succ) * + (∑' ys : J i.succ → B, (∏ j, q (a i.succ) (ys j)) * H i.succ ys) := by + rw [tsum_rootPartition] + apply tsum_congr + intro a + rw [← (Equiv.piCurry (fun (i : Fin (m+1)) (_ : J i) => B)).symm.tsum_eq] + simp only [Equiv.piCurry_symm_apply,rootPartitionEncode,Sigma.uncurry] + simp_rw [Fintype.prod_sigma] + simp only [Finset.prod_mul_distrib,Finset.prod_const,Finset.card_univ] + have he (ys : ∀ i, J i → B) : + (((∏ i, p (a i)^Fintype.card (J i)) * ∏ i, ∏ j, q (a i) (ys i j)) * + ∏ i, H i (ys i)) * (p (a 0) * K (a 0) (ys 0)) = + (∏ i, p (a i)^Fintype.card (J i) * ((∏ j, q (a i) (ys i j))*H i (ys i))) * + (p (a 0) * K (a 0) (ys 0)) := by + simp only [Finset.prod_mul_distrib] + ring + simp_rw [he] + rw [ennreal_tsum_pi_focus m (fun i => J i → B) + (fun i ys => p (a i)^Fintype.card (J i) * ((∏ j, q (a i) (ys j))*H i ys)) + (fun ys => p (a 0)*K (a 0) ys)] + congr 1 + · have hh (ys : J 0 → B) : + (p (a 0)^Fintype.card (J 0) * ((∏ j, q (a 0) (ys j))*H 0 ys)) * + (p (a 0)*K (a 0) ys) = + p (a 0) ^ (Fintype.card (J 0)+1) * + (((∏ j, q (a 0) (ys j))*H 0 ys)*K (a 0) ys) := by + rw [pow_succ] + ring + simp_rw [hh, ENNReal.tsum_mul_left] + · simp_rw [ENNReal.tsum_mul_left] + exact Finset.prod_mul_distrib + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ProbabilityMaps.lean b/lean/OAI/Probability/Perceptron/Variational/ProbabilityMaps.lean new file mode 100644 index 0000000000000000000000000000000000000000..d218c0f4643f8bd0da758e133998a295e9446750 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ProbabilityMaps.lean @@ -0,0 +1,140 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.ContinuousCavityProfile + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter TopologicalSpace +open scoped Topology BoundedContinuousFunction BigOperators NNReal + +lemma probabilityMap_tendsto_of_ae_tendsto {Ω X : Type*} + [MeasurableSpace Ω] [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + (μ : ProbabilityMeasure Ω) (F : ℕ → Ω → X) (G : Ω → X) + (hF : ∀ n, Measurable (F n)) (hG : Measurable G) + (hlim : ∀ᵐ ω ∂(μ : Measure Ω), Tendsto (fun n => F n ω) atTop (𝓝 (G ω))) : + Tendsto (fun n => μ.map (F n)) atTop (𝓝 (μ.map G)) := by + apply ProbabilityMeasure.tendsto_iff_forall_integral_tendsto.mpr + intro f + have he n : (∫ x, f x ∂(μ.map (F n) : Measure X)) = + ∫ ω, f (F n ω) ∂(μ : Measure Ω) := + integral_map (hF n).aemeasurable f.measurable.aestronglyMeasurable + have hg : (∫ x, f x ∂(μ.map G : Measure X)) = + ∫ ω, f (G ω) ∂(μ : Measure Ω) := + integral_map hG.aemeasurable f.measurable.aestronglyMeasurable + simp_rw [he,hg] + apply tendsto_integral_of_dominated_convergence (fun _ => ‖f‖) + (fun n => (f.measurable.comp (hF n)).aestronglyMeasurable) + (integrable_const _) + (fun n => ae_of_all _ fun ω => f.norm_coe_le_norm _) + exact hlim.mono fun ω hω => f.continuous.continuousAt.tendsto.comp hω + +lemma FiniteFieldModel.property_of_ae {f : Time→ℝ} (M : FiniteFieldModel f) + (p : ℝ→Prop) (hf : ∀ᵐ u ∂timeLaw,p (f u)) (i : Fin (M.depth+1)) : p (M.value i) := by + have hi : timeLaw (M.label ⁻¹' {i})≠0 := by + intro hi + have hp:=M.positive i + change 0<(timeLaw (M.label ⁻¹' {i})).toReal at hp + rw [hi] at hp + simp at hp + have hne : ∃ u,M.label u=i ∧ p (M.value (M.label u)) := by + by_contra! hn + have hz : ∀ᵐ u ∂timeLaw,u∉ M.label ⁻¹' {i} := by + filter_upwards [M.agrees,hf] with u hu hv + intro hm + exact hn u hm (hu ▸ hv) + exact hi (by simpa only [not_not,Set.ofPred_mem_eq] using ae_iff.mp hz) + obtain ⟨u,hu,hv⟩:=hne + simpa [hu] using hv + +def quantileRoundLaw (η : Measure Time) [IsProbabilityMeasure η] (j : ℕ) : ProbabilityMeasure Time := + ProbabilityMeasure.map (⟨timeLaw,inferInstance⟩ : ProbabilityMeasure Time) + (roundTime (unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η)) j) + +lemma quantileRoundLaw_tendsto (η : Measure Time) [IsProbabilityMeasure η] : + Tendsto (quantileRoundLaw η) atTop (𝓝 (⟨η,inferInstance⟩ : ProbabilityMeasure Time)) := by + have h:=probabilityMap_tendsto_of_ae_tendsto (⟨timeLaw,inferInstance⟩ : ProbabilityMeasure Time) + (roundTime (unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η))) + (boundedQuantile η) (fun j=>(roundTime_mono _ j).measurable) (boundedQuantile_measurable η) + (ae_of_all _ fun u=>roundTime_tendsto _ (boundedQuantile_monotone η) u) + have he : ProbabilityMeasure.map (⟨timeLaw,inferInstance⟩ : ProbabilityMeasure Time) (boundedQuantile η)= + (⟨η,inferInstance⟩ : ProbabilityMeasure Time) := by + apply Subtype.ext + exact boundedQuantile_law η + rw [he] at h + exact h + +lemma realTail_quantileRoundLaw (η : Measure Time) [IsProbabilityMeasure η] (j : ℕ) (r : ℝ) : + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + realTail (quantileRoundLaw η j) r= + weightedStepTail (strictRoundModel F j).weight (fun i=>(roundTimeValue F j i:ℝ)) r := by + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + change (∫ x,1-max r (x:ℝ) ∂timeLaw.map (roundTime F j))=_ + rw [integral_map (roundTime_mono F j).measurable.aemeasurable (by fun_prop)] + simpa only [F,roundTime,roundTimeValue,weightedStepTail,max_comm] using (strictRoundModel F j).integral (fun x=>1-max r x) + +lemma quantileRoundLaw_support (η : Measure Time) [IsProbabilityMeasure η] {B : ℝ} + (hη : ∀ᵐ r : Time ∂η,(r:ℝ)≤B) (j : ℕ) : + ∀ᵐ r : Time ∂(quantileRoundLaw η j : Measure Time),(r:ℝ)≤B := by + have hq : ∀ᵐ u ∂timeLaw,(boundedQuantile η u:ℝ)≤B := by + have h:=hη + rw [←boundedQuantile_law η] at h + exact ae_of_ae_map (boundedQuantile_measurable η).aemeasurable h + apply (ae_map_iff (roundTime_mono _ _).measurable.aemeasurable (measurableSet_le measurable_subtype_coe measurable_const)).mpr + exact hq.mono fun u hu=>(roundLower_le j (boundedQuantile η u).prop.1).trans hu + +lemma roundTimeValue_support (η : Measure Time) [IsProbabilityMeasure η] {B : ℝ} + (hη : ∀ᵐ r : Time ∂η,(r:ℝ)≤B) (j : ℕ) : + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + ∀ i,(roundTimeValue F j i:ℝ)≤B := by + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + have hq : ∀ᵐ u ∂timeLaw,(boundedQuantile η u:ℝ)≤B := by + have h:=hη + rw [←boundedQuantile_law η] at h + exact ae_of_ae_map (boundedQuantile_measurable η).aemeasurable h + exact (strictRoundModel F j).property_of_ae (fun r=>r≤B) + (hq.mono fun u hu=>(roundLower_le j (boundedQuantile η u).prop.1).trans hu) + +lemma cappedA_nonneg (η : Measure Time) [IsProbabilityMeasure η] (B : ℝ) {r : ℝ} (hr : 0≤r) : + 0≤cappedA η B r := + intervalIntegral.integral_nonneg hr (fun _ _=>sq_nonneg _) + +lemma roundTimeValue_profile_exact (η : Measure Time) [IsProbabilityMeasure η] + {B K a : ℝ} (hB : B<1) (ha0 : 0≤a) (haK : a≤K) + (hA : ∀ᵐ r : Time ∂η,cappedA η B r≤a) (j : ℕ) : + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + ∀ i,(continuousCavityProfile η B ha0 haK (roundTimeValue F j i)).2.val= + cappedA η B (roundTimeValue F j i) := by + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + have hq : ∀ᵐ u ∂timeLaw,cappedA η B (boundedQuantile η u)≤a := by + have h : ∀ᵐ r : Time ∂timeLaw.map (boundedQuantile η),cappedA η B r≤a := by + have hl : timeLaw.map (boundedQuantile η)=η := boundedQuantile_law η + rw [hl] + exact hA + exact ae_of_ae_map (boundedQuantile_measurable η).aemeasurable h + have hv := (strictRoundModel F j).property_of_ae (fun r=>cappedA η B r≤a) + (hq.mono fun u hu=>((cappedA_monotone η hB) (roundLower_le j (boundedQuantile η u).prop.1)).trans hu) + dsimp only + intro i + change min a (max 0 (cappedA η B _))=_ + rw [max_eq_right (cappedA_nonneg η B (roundTimeValue F j i).prop.1)] + exact min_eq_right (hv i) + +lemma quantileRoundLaw_stationary (η : Measure Time) [IsProbabilityMeasure η] {B : ℝ} + (hη : ∀ᵐ r : Time ∂η,(r:ℝ)≤B) (j : ℕ) : + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + ∀ i,cappedA (quantileRoundLaw η j) B (roundTimeValue F j i)= + weightedStepA (strictRoundModel F j).weight (fun l=>(roundTimeValue F j l:ℝ)) (roundTimeValue F j i) := by + dsimp only + intro i + let F:=unitQuantileField (boundedQuantile η) (boundedQuantile_monotone η) + rw [cappedA_eq_integral (quantileRoundLaw η j) (quantileRoundLaw_support η hη j) + (roundTimeValue F j i).prop.1 (roundTimeValue_support η hη j i)] + simp_rw [realTail_quantileRoundLaw] + simp only [weightedStepA,one_div,inv_pow] + rfl + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ProductMarkLaw.lean b/lean/OAI/Probability/Perceptron/Variational/ProductMarkLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..f068666c57b93501936a09bd6323ea6689d0fb89 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ProductMarkLaw.lean @@ -0,0 +1,420 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.DecoratedWeightedTotal + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy + +lemma normalizedMeasure_prod {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + (ν : Measure S) (ρ : Measure T) [SFinite ν] [SFinite ρ] + (hν0 : ν univ ≠ 0) (hνf : ν univ ≠ ⊤) : + normalizedMeasure (ν.prod ρ) = (normalizedMeasure ν).prod (normalizedMeasure ρ) := by + unfold normalizedMeasure + rw [Measure.prod_smul_left,Measure.prod_smul_right,smul_smul] + congr 1 + rw [← univ_prod_univ,Measure.prod_prod,ENNReal.mul_inv (Or.inl hν0) (Or.inl hνf)] + +lemma exponentialMarkTilt_prod_add {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + (ν : Measure S) (ρ : Measure T) [IsProbabilityMeasure ν] [IsProbabilityMeasure ρ] + (b : ℝ) {f : S → ℝ} {g : T → ℝ} (hf : Measurable f) (hg : Measurable g) + (hIf : Integrable (fun s => Real.exp (b*f s)) ν) : + exponentialMarkTilt (ν.prod ρ) b (fun p => f p.1+g p.2) = + (exponentialMarkTilt ν b f).prod (exponentialMarkTilt ρ b g) := by + have hνmass : (ν.withDensity (fun s => ENNReal.ofReal (Real.exp (b*f s)))) univ = + ENNReal.ofReal (∫ s, Real.exp (b*f s) ∂ν) := by + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + exact (ofReal_integral_eq_lintegral_ofReal hIf (ae_of_all _ fun s => (Real.exp_pos _).le)).symm + have hd : (fun p : S×T => ENNReal.ofReal (Real.exp (b*(f p.1+g p.2)))) = + (fun p : S×T => ENNReal.ofReal (Real.exp (b*f p.1))* ENNReal.ofReal (Real.exp (b*g p.2))) := by + funext p + rw [mul_add,Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos _).le] + unfold exponentialMarkTilt + rw [hd,← prod_withDensity ((hf.const_mul b).exp.ennreal_ofReal) ((hg.const_mul b).exp.ennreal_ofReal)] + apply normalizedMeasure_prod + · rw [hνmass]; exact ENNReal.ofReal_ne_zero_iff.mpr (integral_exp_pos hIf) + · rw [hνmass]; exact ENNReal.ofReal_ne_top + +lemma fractional_log_moment_prod_add {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + (ν : Measure S) (ρ : Measure T) [IsProbabilityMeasure ν] [IsProbabilityMeasure ρ] + (b : ℝ) {f : S → ℝ} {g : T → ℝ} + (hIf : Integrable (fun s => Real.exp (b*f s)) ν) + (hIg : Integrable (fun t => Real.exp (b*g t)) ρ) : + Real.log (∫ p, Real.exp (b*(f p.1+g p.2)) ∂ν.prod ρ)/b = + Real.log (∫ s, Real.exp (b*f s) ∂ν)/b + Real.log (∫ t, Real.exp (b*g t) ∂ρ)/b := by + simp_rw [mul_add,Real.exp_add] + rw [integral_prod_mul (fun s => Real.exp (b*f s)) (fun t => Real.exp (b*g t)),Real.log_mul (integral_exp_pos hIf).ne' (integral_exp_pos hIg).ne',add_div] + +def productMarkLaw {S T : Type} [MeasurableSpace S] [MeasurableSpace T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) : ProbabilityMeasure (S×T) := + ⟨(ν : Measure S).prod (ρ : Measure T),inferInstance⟩ + +theorem finiteCascadeLogRecursion_add_product {X Y S T : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace S] [MeasurableSpace T] + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S → X) (step₂ : Y×T → Y) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, 0 < z i) + {H : X → ℝ} {G : Y → ℝ} + (hIH : finiteCascadeFractionalIntegrable ν step₁ H n z) + (hIG : finiteCascadeFractionalIntegrable ρ step₂ G n z) (x : X) (y : Y) : + finiteCascadeLogRecursion (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) n z + (fun q => H q.1+G q.2) (x,y) = + finiteCascadeLogRecursion ν step₁ n z H x + finiteCascadeLogRecursion ρ step₂ n z G y := by + induction n generalizing x y with + | zero => rfl + | succ n ih => + rcases hIH with ⟨hHroot,hHtail⟩ + rcases hIG with ⟨hGroot,hGtail⟩ + conv_lhs => rw [finiteCascadeLogRecursion] + change Real.log (∫ p : S×T, Real.exp (z 0 * + finiteCascadeLogRecursion (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) n (fun i => z i.succ) + (fun q => H q.1+G q.2) (step₁ (x,p.1),step₂ (y,p.2))) ∂(ν : Measure S).prod (ρ : Measure T))/(z 0) = _ + simp_rw [ih (fun i => z i.succ) (fun i => hz i.succ) hHtail hGtail] + exact fractional_log_moment_prod_add (ν : Measure S) (ρ : Measure T) (z 0) (hHroot x) (hGroot y) + +lemma real_quadratic_complete_square {b : ℝ} (hb : b ≠ 0) (c d y : ℝ) : + Real.exp (-b*y^2+c*y+d) = + Real.exp (d+c^2/(4*b))*Real.exp (-b*(y-c/(2*b))^2) := by + rw [← Real.exp_add] + congr 1 + field_simp + ring + +lemma real_quadratic_integrable {b : ℝ} (hb : 0 < b) (c d : ℝ) : + Integrable (fun y : ℝ => Real.exp (-b*y^2+c*y+d)) := by + simp_rw [real_quadratic_complete_square hb.ne'] + exact ((integrable_exp_neg_mul_sq hb).comp_sub_right (c/(2*b))).const_mul _ + +lemma real_quadratic_integral {b : ℝ} (hb : 0 < b) (c d : ℝ) : + (∫ y : ℝ, Real.exp (-b*y^2+c*y+d)) = + Real.exp (d+c^2/(4*b))*Real.sqrt (Real.pi/b) := by + simp_rw [real_quadratic_complete_square hb.ne'] + rw [integral_const_mul, integral_sub_right_eq_self (fun y : ℝ => Real.exp (-b*y^2)),integral_gaussian] + +lemma standardGaussian_quadratic_density (a c d y : ℝ) : + gaussianPDFReal 0 1 y * Real.exp (a*y^2+c*y+d) = + (Real.sqrt (2*Real.pi))⁻¹ * Real.exp (-(1/2-a)*y^2+c*y+d) := by + simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero] + rw [mul_assoc,←Real.exp_add] + congr 2 + ring + +lemma standardGaussian_quadratic_integrable {a : ℝ} (ha : a < 1/2) (c d : ℝ) : + Integrable (fun y : ℝ => Real.exp (a*y^2+c*y+d)) (gaussianReal 0 1) := by + rw [gaussianReal_of_var_ne_zero _ (by norm_num : (1 : ℝ≥0) ≠ 0), + integrable_withDensity_iff_integrable_smul' (measurable_gaussianPDF _ _) + (ae_of_all _ fun _ => gaussianPDF_lt_top)] + simp only [smul_eq_mul] + have he : (fun y : ℝ => (gaussianPDF 0 1 y).toReal * Real.exp (a*y^2+c*y+d)) = + (fun y : ℝ => (Real.sqrt (2*Real.pi))⁻¹ * Real.exp (-(1/2-a)*y^2+c*y+d)) := by + funext y + rw [toReal_gaussianPDF] + exact standardGaussian_quadratic_density a c d y + rw [he] + exact (real_quadratic_integrable (by linarith : 0 < 1/2-a) c d).const_mul _ + +lemma standardGaussian_quadratic_integral {a : ℝ} (ha : a < 1/2) (c d : ℝ) : + (∫ y, Real.exp (a*y^2+c*y+d) ∂gaussianReal 0 1) = + Real.exp (d+c^2/(4*(1/2-a))) / Real.sqrt (1-2*a) := by + rw [integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ℝ≥0) ≠ 0)] + simp only [smul_eq_mul,standardGaussian_quadratic_density] + rw [integral_const_mul,real_quadratic_integral (by linarith : 0 < 1/2-a)] + have hratio : Real.sqrt (Real.pi/(1/2-a)) = Real.sqrt (2*Real.pi)/Real.sqrt (1-2*a) := by + rw [←Real.sqrt_div (by positivity)] + congr 1 + field_simp + rw [hratio] + field_simp [ne_of_gt (Real.sqrt_pos.mpr (by positivity : 0 < 2*Real.pi))] + +lemma gaussian_quadratic_fractional_integrable {b z σ : ℝ} (hb : 0 < b) + (ha : 0 < b-z*σ^2) (c x : ℝ) : + Integrable (fun y : ℝ => Real.exp (z*(c+(x+σ*y)^2/(2*b)))) (gaussianReal 0 1) := by + have hhalf : z*σ^2/(2*b) < 1/2 := by + apply (div_lt_iff₀ (by positivity : 0 < 2*b)).mpr + linarith + convert standardGaussian_quadratic_integrable hhalf (z*x*σ/b) (z*c+z*x^2/(2*b)) using 1 + funext y + congr 1 + field_simp + ring + +lemma gaussian_quadratic_fractional_log {b z σ : ℝ} (hb : 0 < b) (hz : z ≠ 0) + (ha : 0 < b-z*σ^2) (c x : ℝ) : + Real.log (∫ y, Real.exp (z*(c+(x+σ*y)^2/(2*b))) ∂gaussianReal 0 1)/z = + c+(Real.log b-Real.log (b-z*σ^2))/(2*z)+x^2/(2*(b-z*σ^2)) := by + have hhalf : z*σ^2/(2*b) < 1/2 := by + apply (div_lt_iff₀ (by positivity : 0 < 2*b)).mpr + linarith + have hfun : (fun y : ℝ => Real.exp (z*(c+(x+σ*y)^2/(2*b)))) = + (fun y : ℝ => Real.exp ((z*σ^2/(2*b))*y^2+(z*x*σ/b)*y+(z*c+z*x^2/(2*b)))) := by + funext y + congr 1 + field_simp + ring + have hprec : 1-2*(z*σ^2/(2*b)) = (b-z*σ^2)/b := by field_simp + have hprec' : 1/2-z*σ^2/(2*b) = (b-z*σ^2)/(2*b) := by field_simp + rw [hfun,standardGaussian_quadratic_integral hhalf,hprec, + Real.log_div (Real.exp_pos _).ne' (Real.sqrt_pos.mpr (div_pos ha hb)).ne', + Real.log_exp, Real.log_sqrt (div_pos ha hb).le,Real.log_div ha.ne' hb.ne',hprec'] + field_simp [hb.ne',hz,ha.ne'] + ring + +def gaussianShiftStep (σ : ℕ → ℝ) (p : (ℕ → ℝ) × ℝ) : ℕ → ℝ := + fun i => p.1 (i+1)+σ i*p.2 + +lemma gaussianShiftStep_measurable (σ : ℕ → ℝ) : Measurable (gaussianShiftStep σ) := by + unfold gaussianShiftStep + fun_prop + +def standardGaussianMark : ProbabilityMeasure ℝ := ⟨gaussianReal 0 1,inferInstance⟩ + +def quadraticCascadePrecision (σ : ℕ → ℝ) (b : ℝ) : (n : ℕ) → (Fin n → ℝ) → ℝ + | 0, _ => b + | n+1, z => quadraticCascadePrecision σ b n (fun i => z i.succ)-z 0*(σ n)^2 + +def quadraticCascadeOffset (σ : ℕ → ℝ) (b : ℝ) : (n : ℕ) → (Fin n → ℝ) → ℝ + | 0, _ => 0 + | n+1, z => quadraticCascadeOffset σ b n (fun i => z i.succ)+ + (Real.log (quadraticCascadePrecision σ b n (fun i => z i.succ))- + Real.log (quadraticCascadePrecision σ b (n+1) z))/(2*z 0) + +lemma quadraticCascadePrecision_tail_pos (σ : ℕ → ℝ) (b : ℝ) (n : ℕ) (z : Fin (n+1) → ℝ) + (hz : 0 ≤ z 0) (hp : 0 < quadraticCascadePrecision σ b (n+1) z) : + 0 < quadraticCascadePrecision σ b n (fun i => z i.succ) := by + have hsq := mul_nonneg hz (sq_nonneg (σ n)) + dsimp [quadraticCascadePrecision] at hp + linarith + +theorem finiteCascade_quadratic_recursion (σ : ℕ → ℝ) (b c : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : ∀ i, 0 < z i) + (hp : 0 < quadraticCascadePrecision σ b n z) : + (∀ x : ℕ → ℝ, finiteCascadeLogRecursion standardGaussianMark (gaussianShiftStep σ) n z + (fun x => c+(x 0)^2/(2*b)) x = + c+quadraticCascadeOffset σ b n z+(x n)^2/(2*quadraticCascadePrecision σ b n z)) ∧ + finiteCascadeFractionalIntegrable standardGaussianMark (gaussianShiftStep σ) + (fun x => c+(x 0)^2/(2*b)) n z := by + induction n with + | zero => exact ⟨fun _ => by simp [finiteCascadeLogRecursion,quadraticCascadeOffset,quadraticCascadePrecision],trivial⟩ + | succ n ih => + have hpt := quadraticCascadePrecision_tail_pos σ b n z (hz 0).le hp + obtain ⟨heq,hint⟩ := ih (fun i => z i.succ) (fun i => hz i.succ) hpt + constructor + · intro x + conv_lhs => rw [finiteCascadeLogRecursion] + unfold fractionalLogMoment + simp_rw [heq] + change Real.log (∫ y, Real.exp (z 0 * + (c+quadraticCascadeOffset σ b n (fun i => z i.succ)+ + (x (n+1)+σ n*y)^2/(2*quadraticCascadePrecision σ b n (fun i => z i.succ)))) + ∂gaussianReal 0 1)/(z 0) = _ + rw [gaussian_quadratic_fractional_log hpt (hz 0).ne' hp] + dsimp [quadraticCascadeOffset,quadraticCascadePrecision] + ring + · refine ⟨?_,hint⟩ + intro x + simp_rw [heq] + exact gaussian_quadratic_fractional_integrable hpt hp + (c+quadraticCascadeOffset σ b n (fun i => z i.succ)) (x (n+1)) + +theorem canonical_cascade_quadratic_log (σ : ℕ → ℝ) (b c : ℝ) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (hp : 0 < quadraticCascadePrecision σ b n z) (x : ℕ → ℝ) : + (∫ η, Real.log (decoratedTerminalTotal (gaussianShiftStep σ) (fun x => c+(x 0)^2/(2*b)) n (x,η) / + decoratedTerminalTotal (gaussianShiftStep σ) (fun _ => 0) n (x,η)) + ∂decoratedCascadeLaw standardGaussianMark n z) = + c+quadraticCascadeOffset σ b n z+(x n)^2/(2*quadraticCascadePrecision σ b n z) := by + have hq := finiteCascade_quadratic_recursion σ b c n z hz0 hp + rw [finiteCascade_terminal_log_recursion_of_fractional standardGaussianMark (gaussianShiftStep σ) + (gaussianShiftStep_measurable σ) n z hz hz0 hz1 (by fun_prop) hq.2] + exact hq.1 x + +lemma canonical_scalar_integrable {b : ℝ} (hb : 0 < b) (u : ℝ) : + Integrable (fun y : ℝ => Real.exp ((1-b)*y^2/2+u*y)) (gaussianReal 0 1) := by + convert standardGaussian_quadratic_integrable (a := (1-b)/2) (by linarith) u 0 using 1 + funext y + congr 1 + ring + +lemma canonical_scalar_integral {b : ℝ} (hb : 0 < b) (u : ℝ) : + (∫ y, Real.exp ((1-b)*y^2/2+u*y) ∂gaussianReal 0 1) = + Real.exp (u^2/(2*b))/Real.sqrt b := by + have he : (fun y : ℝ => Real.exp ((1-b)*y^2/2+u*y)) = + (fun y : ℝ => Real.exp (((1-b)/2)*y^2+u*y+0)) := by funext y; congr 1; ring + rw [he,standardGaussian_quadratic_integral (by linarith : (1-b)/2 < 1/2)] + congr 2 <;> ring + +lemma canonical_scalar_log {b : ℝ} (hb : 0 < b) (u : ℝ) : + Real.log (∫ y, Real.exp ((1-b)*y^2/2+u*y) ∂gaussianReal 0 1) = + -Real.log b/2+u^2/(2*b) := by + rw [canonical_scalar_integral hb,Real.log_div (Real.exp_pos _).ne' (Real.sqrt_pos.mpr hb).ne', + Real.log_exp,Real.log_sqrt hb.le] + ring + +lemma quadraticCascadePrecision_le (σ : ℕ → ℝ) (b : ℝ) (n : ℕ) (z : Fin n → ℝ) + (hz : ∀ i, 0 ≤ z i) : quadraticCascadePrecision σ b n z ≤ b := by + induction n with + | zero => exact le_rfl + | succ n ih => + have ht := ih (fun i => z i.succ) (fun i => hz i.succ) + have hq := mul_nonneg (hz 0) (sq_nonneg (σ n)) + dsimp [quadraticCascadePrecision] + linarith + +lemma quadraticCascadePrecision_hasDerivAt (σ : ℕ → ℝ) (n : ℕ) (z : Fin n → ℝ) (b : ℝ) : + HasDerivAt (fun b => quadraticCascadePrecision σ b n z) 1 b := by + induction n with + | zero => exact hasDerivAt_id b + | succ n ih => exact (ih (fun i => z i.succ)).sub_const _ + +def quadraticCascadeReciprocalSlope (σ : ℕ → ℝ) (b : ℝ) : (n : ℕ) → (Fin n → ℝ) → ℝ + | 0, _ => 0 + | n+1, z => quadraticCascadeReciprocalSlope σ b n (fun i => z i.succ)+ + (1/(quadraticCascadePrecision σ b n (fun i => z i.succ))- + 1/(quadraticCascadePrecision σ b (n+1) z))/(2*z 0) + +lemma quadraticCascadeOffset_hasDerivAt (σ : ℕ → ℝ) (n : ℕ) (z : Fin n → ℝ) + (hz : ∀ i, 0 ≤ z i) {b : ℝ} (hp : 0 < quadraticCascadePrecision σ b n z) : + HasDerivAt (fun b => quadraticCascadeOffset σ b n z) + (quadraticCascadeReciprocalSlope σ b n z) b := by + induction n with + | zero => exact hasDerivAt_const b 0 + | succ n ih => + have hpt := quadraticCascadePrecision_tail_pos σ b n z (hz 0) hp + exact (ih (fun i => z i.succ) (fun i => hz i.succ) hpt).add + ((((quadraticCascadePrecision_hasDerivAt σ n (fun i => z i.succ) b).log hpt.ne').sub + ((quadraticCascadePrecision_hasDerivAt σ (n+1) z b).log hp.ne')).div_const (2*z 0)) + +def canonicalGaussianFreeValue (σ : ℕ → ℝ) (n : ℕ) (z : Fin n → ℝ) (r b : ℝ) : ℝ := + -Real.log b/2 + quadraticCascadeOffset σ b n z+r/(2*quadraticCascadePrecision σ b n z) + +lemma canonicalGaussianFreeValue_hasDerivAt (σ : ℕ → ℝ) (n : ℕ) (z : Fin n → ℝ) + (hz : ∀ i, 0 ≤ z i) (r : ℝ) {b : ℝ} (hp : 0 < quadraticCascadePrecision σ b n z) : + HasDerivAt (canonicalGaussianFreeValue σ n z r) + (-1/(2*b)+quadraticCascadeReciprocalSlope σ b n z-r/(2*(quadraticCascadePrecision σ b n z)^2)) b := by + have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le σ b n z hz) + have hq := quadraticCascadePrecision_hasDerivAt σ n z b + have ht := (((Real.hasDerivAt_log hb.ne').neg.div_const 2).add + (quadraticCascadeOffset_hasDerivAt σ n z hz hp)).add + ((hasDerivAt_const b r).div (hq.const_mul 2) (by positivity)) + have hd : -b⁻¹/2+quadraticCascadeReciprocalSlope σ b n z+ + (0*(2*quadraticCascadePrecision σ b n z)-r*(2*1))/(2*quadraticCascadePrecision σ b n z)^2 = + -1/(2*b)+quadraticCascadeReciprocalSlope σ b n z-r/(2*(quadraticCascadePrecision σ b n z)^2) := by + field_simp [hb.ne',hp.ne'] + ring + exact ht.congr_deriv hd + +def cascadeLogFluctuationConstant (n : ℕ) (z : Fin n → ℝ) : ℝ := + 4*∫ η, (Real.log (cascadeTotal n η))^2 ∂cascadeLaw n z + +lemma cascadeLogFluctuationConstant_nonneg (n : ℕ) (z : Fin n → ℝ) : + 0 ≤ cascadeLogFluctuationConstant n z := + mul_nonneg (by norm_num) (integral_nonneg fun _ => sq_nonneg _) + +lemma decoratedCascade_log_second_moment_bound {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hstep : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) (c : ℝ) : + MemLp (fun η => Real.log (Real.exp c*decoratedWeightedTotal step n F (x,η) / + decoratedWeightedTotal step n (fun _ _ => 0) (x,η))) 2 + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) ∧ + (∫ η, (Real.log (Real.exp c*decoratedWeightedTotal step n F (x,η) / + decoratedWeightedTotal step n (fun _ _ => 0) (x,η))-c)^2 ∂decoratedCascadeLaw ν n z) ≤ + cascadeLogFluctuationConstant n z := by + have hid := decoratedWeightedTotal_identDistrib ν step hstep n z hz0 hz1 F hF hI hM x + have hiz := decoratedWeightedTotal_identDistrib ν step hstep n z hz0 hz1 (fun _ _ => 0) + (fun _ => measurable_const) (by intro i y; simp only [mul_zero,Real.exp_zero]; exact integrable_const 1) + (by intro i y; simp) x + have hld := hid.comp Real.measurable_log + have hlz := hiz.comp Real.measurable_log + have hL := cascadeTotal_log_memLp_two n z hz hz0 hz1 + have hmD := hld.memLp_iff.mpr hL + have hmZ := hlz.memLp_iff.mpr hL + have hp := (cascadeTotal_regular n z hz hz0 hz1).1 + have hdpos := hid.symm.ae_snd measurableSet_Ioi hp + have hzpos := hiz.symm.ae_snd measurableSet_Ioi hp + have he : (fun η => Real.log (Real.exp c*decoratedWeightedTotal step n F (x,η) / + decoratedWeightedTotal step n (fun _ _ => 0) (x,η))) =ᵐ[(decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n))] + (fun η => c+Real.log (decoratedWeightedTotal step n F (x,η))- + Real.log (decoratedWeightedTotal step n (fun _ _ => 0) (x,η))) := by + filter_upwards [hdpos,hzpos] with η hη hg + rw [Real.log_div (mul_ne_zero (Real.exp_ne_zero _) hη.ne') hg.ne', + Real.log_mul (Real.exp_ne_zero _) hη.ne',Real.log_exp] + refine ⟨(memLp_congr_ae he).mpr (((memLp_const c).add hmD).sub hmZ),?_⟩ + have heD := (hld.comp (by fun_prop : Measurable (fun t : ℝ => t^2))).integral_eq + have heZ := (hlz.comp (by fun_prop : Measurable (fun t : ℝ => t^2))).integral_eq + simp only [Function.comp_apply] at heD heZ + calc + _ = ∫ η, (Real.log (decoratedWeightedTotal step n F (x,η))- + Real.log (decoratedWeightedTotal step n (fun _ _ => 0) (x,η)))^2 ∂decoratedCascadeLaw ν n z := by + apply integral_congr_ae + filter_upwards [he] with η hη + rw [hη] + ring + _ ≤ ∫ η, (2*(Real.log (decoratedWeightedTotal step n F (x,η)))^2+ + 2*(Real.log (decoratedWeightedTotal step n (fun _ _ => 0) (x,η)))^2) ∂decoratedCascadeLaw ν n z := by + apply integral_mono (hmD.sub hmZ).integrable_sq + ((hmD.integrable_sq.const_mul 2).add (hmZ.integrable_sq.const_mul 2)) + intro η + dsimp only [Function.comp_apply,Pi.sub_apply,Pi.add_apply] + nlinarith [sq_nonneg (Real.log (decoratedWeightedTotal step n F (x,η))+ + Real.log (decoratedWeightedTotal step n (fun _ _ => 0) (x,η)))] + _ = _ := by + have hsplit := integral_add (hmD.integrable_sq.const_mul 2) (hmZ.integrable_sq.const_mul 2) + simp only [Function.comp_apply] at hsplit + rw [hsplit,integral_const_mul,integral_const_mul,heD,heZ] + unfold cascadeLogFluctuationConstant + ring + +lemma decoratedCascade_log_deviation_le {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hstep : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) (c : ℝ) + {ε : ℝ} (hε : 0 < ε) : + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) + {η | ε ≤ |Real.log (Real.exp c*decoratedWeightedTotal step n F (x,η) / + decoratedWeightedTotal step n (fun _ _ => 0) (x,η))-c|} ≤ + ENNReal.ofReal (cascadeLogFluctuationConstant n z/ε^2) := by + obtain ⟨hm,hbound⟩ := decoratedCascade_log_second_moment_bound ν step hstep n z hz hz0 hz1 F hF hI hM x c + have he := decoratedCascade_log_identity ν step hstep n z hz hz0 hz1 F hF hI hM x c + have hvar : variance (fun η => Real.log (Real.exp c*decoratedWeightedTotal step n F (x,η) / + decoratedWeightedTotal step n (fun _ _ => 0) (x,η))) + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) ≤ cascadeLogFluctuationConstant n z := by + rw [variance_eq_integral hm.aemeasurable,he] + exact hbound + have hc := meas_ge_le_variance_div_sq hm hε + rw [he] at hc + exact hc.trans (ENNReal.ofReal_le_ofReal (div_le_div_of_nonneg_right hvar (sq_nonneg ε))) + +lemma finiteCascade_terminal_log_deviation_le {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + [Nonempty S] (ν : ProbabilityMeasure S) (step : X×S → X) (hs : Measurable step) + (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + {H : X → ℝ} (hH : Measurable H) (hI : finiteCascadeFractionalIntegrable ν step H n z) (x : X) + {ε : ℝ} (hε : 0 < ε) : + (decoratedCascadeLaw ν n z : Measure (DecoratedCascade S n)) + {η | ε ≤ |Real.log (decoratedTerminalTotal step H n (x,η) / + decoratedTerminalTotal step (fun _ => 0) n (x,η))-finiteCascadeLogRecursion ν step n z H x|} ≤ + ENNReal.ofReal (cascadeLogFluctuationConstant n z/ε^2) := by + simp_rw [decoratedTerminalTotal_zero,decoratedTerminalTotal_telescoping ν step H n z] + exact decoratedCascade_log_deviation_le ν step hs n z hz hz0 hz1 _ + (finiteCascadeShifts_measurable ν step hs n z hH) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z (fun j => (hz0 j).ne') H hI i y).1) + (fun i y => (finiteCascadeShifts_normalized_of_fractional ν step n z (fun j => (hz0 j).ne') H hI i y).2) x + (finiteCascadeLogRecursion ν step n z H x) hε + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/PureLabel.lean b/lean/OAI/Probability/Perceptron/Variational/PureLabel.lean new file mode 100644 index 0000000000000000000000000000000000000000..c90d94a9086859b82ff3b7a6993f994cd52f7a0c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/PureLabel.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.EnrichedPatternMean +import OAI.Probability.Perceptron.Sphere.GaussianAffineCoordinate + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma inner_eraseMarkCoordinate {I : Type} [Fintype I] [DecidableEq I] + (i : I) (x y : EuclideanSpace ℝ I) : + inner ℝ (eraseMarkCoordinate i x) y=inner ℝ x y-y i*x i := by + change (∑ j, y j*(eraseMarkCoordinate i x) j)=(∑ j, y j*x j)-y i*x i + rw [← Finset.sum_erase_add _ _ (Finset.mem_univ i), + ← Finset.sum_erase_add _ _ (Finset.mem_univ i)] + have he : (∑ j∈Finset.univ.erase i, y j*(eraseMarkCoordinate i x) j)= + ∑ j∈Finset.univ.erase i, y j*x j := by + apply Finset.sum_congr rfl + intro j hj + simp [eraseMarkCoordinate,Function.update_of_ne (Finset.mem_erase.mp hj).1] + rw [he] + simp [eraseMarkCoordinate] + +lemma inner_eraseMarkCoordinate_right {I : Type} [Fintype I] [DecidableEq I] + (i : I) (x y : EuclideanSpace ℝ I) : + inner ℝ x (eraseMarkCoordinate i y)=inner ℝ x y-x i*y i := by + rw [real_inner_comm,inner_eraseMarkCoordinate,real_inner_comm y x] + +def pureLabelIndex {N : ℕ} (p : Fin N→ℕ) (j : Fin N) (hp : p j=0) : EnrichedIndex N N p := + Sum.inr ⟨j,fun l => Fin.elim0 (Fin.cast hp l)⟩ + +lemma sourceFeature_pure_coordinate {N : ℕ} (p : Fin N→ℕ) (u : Fin N→ℝ) + (j : Fin N) (hp : p j=0) (x : NormalizedSpin N) : + sourceEnrichedFeature N p u x (pureLabelIndex p j hp)=perturbationAmplitude N u j := by + simp only [sourceEnrichedFeature,enrichedFeature,pureLabelIndex,WithLp.ofLp_toLp] + have he : spinTensorFeature N (p j) x (fun l => Fin.elim0 (Fin.cast hp l))=1 := by + unfold spinTensorFeature + have hx : IsEmpty (Fin (p j)) := by rw [hp]; infer_instance + simp + rw [he,mul_one] + +lemma sourceFeature_erase_pure {N : ℕ} (p : Fin N→ℕ) (u : Fin N→ℝ) + (j : Fin N) (hp : p j=0) (x : NormalizedSpin N) : + sourceEnrichedFeature N p (Function.update u j 0) x= + eraseMarkCoordinate (pureLabelIndex p j hp) (sourceEnrichedFeature N p u x) := by + classical + ext i + rcases i with i|⟨l,t⟩ + · simp [sourceEnrichedFeature,enrichedFeature,eraseMarkCoordinate,pureLabelIndex] + · by_cases hl : l=j + · subst l + have hs : Subsingleton (SpinTensorIndex N (p j)) := by + unfold SpinTensorIndex + rw [hp] + infer_instance + have ht : t=(fun l => Fin.elim0 (Fin.cast hp l)) := Subsingleton.elim _ _ + subst t + simp [sourceEnrichedFeature,enrichedFeature,eraseMarkCoordinate,pureLabelIndex, + perturbationAmplitude] + · have hi : (Sum.inr ⟨l,t⟩ : EnrichedIndex N N p)≠pureLabelIndex p j hp := by + intro he + have := congrArg (fun a : EnrichedIndex N N p => match a with | .inl _ => j | .inr a => a.1) he + exact hl this + simp [sourceEnrichedFeature,enrichedFeature,eraseMarkCoordinate,Function.update_of_ne hi, + perturbationAmplitude,Function.update_of_ne hl] + +lemma enrichedTerminal_free_pure (n M : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M→Fin (n+1)→ℝ) (p : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) + (j : Fin (n+1)) (hp : p j=0) (htop : ℝ) : + ∀ a, enrichedTerminal n M f g p (Function.update u j 0) htop + (eraseMarkCoordinate (pureLabelIndex p j hp) a)= + enrichedTerminal n M f g p (Function.update u j 0) htop a := by + intro a + unfold enrichedTerminal vectorLogPartition vectorPartition + congr 3 + funext x + congr 1 + congr 1 + change inner ℝ (sourceEnrichedFeature (n+1) p (Function.update u j 0) x) + (eraseMarkCoordinate (pureLabelIndex p j hp) a)=_ + rw [inner_eraseMarkCoordinate_right,sourceFeature_pure_coordinate p _ j hp] + simp [perturbationAmplitude] + +lemma enrichedTerminal_affine_pure (n M : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M→Fin (n+1)→ℝ) (p : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) + (j : Fin (n+1)) (hp : p j=0) (htop : ℝ) : + enrichedTerminal n M f g p u htop = fun a => + enrichedTerminal n M f g p (Function.update u j 0) htop a+ + perturbationAmplitude (n+1) u j*a (pureLabelIndex p j hp) := by + funext a + let v := Function.update u j 0 + let c := perturbationAmplitude (n+1) u j*a (pureLabelIndex p j hp) + have hinner (x : NormalizedSpin (n+1)) : + inner ℝ (sourceEnrichedFeature (n+1) p u x) a= + inner ℝ (sourceEnrichedFeature (n+1) p v x) a+c := by + rw [sourceFeature_erase_pure p u j hp,inner_eraseMarkCoordinate, + sourceFeature_pure_coordinate p u j hp] + dsimp [c] + ring + have hW : Measurable (normalizedPatternEnergy (n+1) M f g) := + ((normalizedPatternEnergy_continuous (n+1) M f).comp + (continuous_const.prodMk continuous_id)).measurable + have hV : Measurable (fun x : NormalizedSpin (n+1) => + innerSL ℝ (sourceEnrichedFeature (n+1) p v x)) := + ((innerSL ℝ).continuous.comp (enrichedFeature_continuous _ _ _ _ _)).measurable + have hpos := vectorPartition_pos (unitSphereLaw (n+1)) hW hV + (normalizedPatternEnergy_bound (n+1) M f g) + (fun x => by rw [innerSL_apply_norm,sourceEnrichedFeature_norm]) a + have he : vectorPartition (unitSphereLaw (n+1)) (normalizedPatternEnergy (n+1) M f g) + (fun x => innerSL ℝ (sourceEnrichedFeature (n+1) p u x)) a= + vectorPartition (unitSphereLaw (n+1)) (normalizedPatternEnergy (n+1) M f g) + (fun x => innerSL ℝ (sourceEnrichedFeature (n+1) p v x)) a*Real.exp c := by + unfold vectorPartition + simp only [innerSL_apply_apply,hinner,← add_assoc,Real.exp_add] + exact integral_mul_const _ _ + unfold enrichedTerminal vectorLogPartition + rw [he,Real.log_mul hpos.ne' (Real.exp_ne_zero c),Real.log_exp] + dsimp [v,c] + ring + +section DiagonalWord +variable {I : Type} [Fintype I] + +def diagonalCascadeWord (A : ℕ→I→ℝ) : (k : ℕ)→(Fin k→ℝ)→List (ℝ×(I→ℝ)) + | 0,_ => [] + | k+1,z => (z 0,A k)::diagonalCascadeWord A k (fun i => z i.succ) + +lemma diagonalCascadeWord_exact (A : ℕ→I→ℝ) (k : ℕ) (z : Fin k→ℝ) : + diagonalWord (diagonalCascadeWord A k z)=linearCascadeWord (fun j => diagonalMark (A j)) k z := by + induction k with + | zero => rfl + | succ k ih => simp only [diagonalCascadeWord,diagonalWord,List.map_cons,linearCascadeWord]; rw [← ih]; rfl + +omit [Fintype I] in +lemma diagonalCascadeWord_nonneg (A : ℕ→I→ℝ) (k : ℕ) (z : Fin k→ℝ) (hz : ∀ i, 0≤z i) : + ∀ a∈diagonalCascadeWord A k z, 0≤a.1 := by + induction k with + | zero => simp [diagonalCascadeWord] + | succ k ih => + intro a ha + rcases List.mem_cons.mp ha with rfl|ha + · exact hz 0 + · exact ih (fun i => z i.succ) (fun i => hz i.succ) a ha + +end DiagonalWord + +def enrichedIncrementFactors {N k : ℕ} (p d : Fin N→ℕ) (h : Fin (k+1)→ℝ) + (j : ℕ) : EnrichedIndex N N p→ℝ := + if hj : j Real.sqrt + (enrichedCoordinateLevel p d h ⟨k-j,by omega⟩ i- + enrichedCoordinateLevel p d h ⟨k-j-1,by omega⟩ i) else fun _ => 0 + +lemma enrichedIncrementFactors_exact {N k : ℕ} (p d : Fin N→ℕ) (h : Fin (k+1)→ℝ) : + (fun j => diagonalMark (enrichedIncrementFactors p d h j))=enrichedIncrementMap p d h := by + funext j + simp only [enrichedIncrementFactors,enrichedIncrementMap] + split_ifs + · rfl + · ext x i + change 0*x i=0 + ring + +def pureLabelResponse {N : ℕ} (p d : Fin N→ℕ) (j : Fin N) (hp : p j=0) + (k : ℕ) (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) : ℝ := + ((diagonalCascadeWord (enrichedIncrementFactors p d h) k z).map + (fun a => a.1*(a.2 (pureLabelIndex p j hp))^2)).sum + +lemma enrichedExpectedLog_pure_response (n M k : ℕ) (f : ℝ →ᵇ ℝ) + (g : Fin M→Fin (n+1)→ℝ) (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) + (j : Fin (n+1)) (hp : p j=0) (h : Fin (k+1)→ℝ) (z : Fin k→ℝ) + (hz : StrictMono z) (hz0 : ∀ i, 0 (hz0 i).le)) + (fun i => Real.sqrt (enrichedCoordinateLevel p d h 0 i)) + (enrichedTerminal_lipschitz n M f g p (Function.update u j 0) _) + (enrichedTerminal_free_pure n M f g p u j hp _) _ + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/QuadraticContactRemainders.lean b/lean/OAI/Probability/Perceptron/Variational/QuadraticContactRemainders.lean new file mode 100644 index 0000000000000000000000000000000000000000..c8daf7e5b74832d4ce23042886b2010c141bdf6e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/QuadraticContactRemainders.lean @@ -0,0 +1,75 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.TiltReplicaCoordinate + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +lemma quadratic_contact_remainders {A : ℝ → ℝ} {u a c s dA : ℝ} + (hd : HasDerivAt A dA u) + (hmin : IsLocalMin (fun t => c*(t-a)^2-A t) u) + (hp : c*(u-a)^2-A u ≤ c*(u+s-a)^2-A (u+s)) + (hm : c*(u-a)^2-A u ≤ c*(u-s-a)^2-A (u-s)) : + A (u+s)-A u-s*dA ≤ c*s^2 ∧ A (u-s)-A u+s*dA ≤ c*s^2 := by + have he := hmin.hasDerivAt_eq_zero + (((((hasDerivAt_id u).sub_const a).pow 2).const_mul c).sub hd) + norm_num only [id_eq, Nat.cast_ofNat, Nat.reduceSub, pow_one, mul_one] at he + constructor <;> nlinarith [congrArg (fun t : ℝ => t*s) he] + +lemma integral_convex_contact_bound {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {f : Ω → ℝ → ℝ} {A : ℝ → ℝ} + {d : Ω → ℝ} {u s dA C δ : ℝ} (hs : 0 < s) + (hdm : AEStronglyMeasurable d P) + (hf : ∀ᵐ ω ∂P, ConvexOn ℝ univ (f ω) ∧ HasDerivAt (f ω) (d ω) u) + (hp : A (u+s)-A u-s*dA ≤ C*s^2) (hm : A (u-s)-A u+s*dA ≤ C*s^2) + (hip : Integrable (fun ω => f ω (u+s)) P) + (hi0 : Integrable (fun ω => f ω u) P) + (him : Integrable (fun ω => f ω (u-s)) P) + (hbp : (∫ ω, |f ω (u+s)-A (u+s)| ∂P) ≤ δ) + (hb0 : (∫ ω, |f ω u-A u| ∂P) ≤ δ) + (hbm : (∫ ω, |f ω (u-s)-A (u-s)| ∂P) ≤ δ) : + (∫ ω, |d ω-dA| ∂P) ≤ C*s+4*δ/s := by + have ip := (hip.sub (integrable_const (A (u+s)))).abs + have i0 := (hi0.sub (integrable_const (A u))).abs + have im := (him.sub (integrable_const (A (u-s)))).abs + let B := fun ω => C*s+(|f ω (u+s)-A (u+s)|+2*|f ω u-A u|+|f ω (u-s)-A (u-s)|)/s + have hB : Integrable B P := (integrable_const (C*s)).add ((ip.add (i0.const_mul 2) |>.add im).div_const s) + have hbound : ∀ᵐ ω ∂P, |d ω-dA| ≤ B ω := hf.mono fun ω hω => + convex_contact_derivative_bound hs hω.1 hω.2 hp hm + have hi : Integrable (fun ω => |d ω-dA|) P := hB.mono' + (by simpa only [Real.norm_eq_abs, Pi.sub_apply] using (hdm.sub aestronglyMeasurable_const).norm) (hbound.mono fun ω hω => by simpa using hω) + calc + _ ≤ ∫ ω, B ω ∂P := integral_mono_ae hi hB hbound + _ = C*s+((∫ ω, |f ω (u+s)-A (u+s)| ∂P)+ + 2*(∫ ω, |f ω u-A u| ∂P)+(∫ ω, |f ω (u-s)-A (u-s)| ∂P))/s := by + have he := integral_add (integrable_const (C*s)) ((ip.add (i0.const_mul 2) |>.add im).div_const s) + have he' := integral_add (ip.add (i0.const_mul 2)) im + have he'' := integral_add ip (i0.const_mul 2) + simp only [Pi.add_apply,Pi.sub_apply] at he he' he'' + dsimp only [B] + rw [he,integral_div,he',he''] + simp [integral_const_mul] + _ ≤ _ := by + apply add_le_add_right + apply div_le_div_of_nonneg_right _ hs.le + linarith + +lemma integral_centered_abs_le_sqrt_variance {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {X : Ω → ℝ} (hX : MemLp X 2 P) : + (∫ ω, |X ω-∫ η, X η ∂P| ∂P) ≤ Real.sqrt (variance X P) := by + have hC : MemLp (fun ω => X ω-∫ η, X η ∂P) 2 P := hX.sub (memLp_const _) + have hA := hC.norm + have hv := variance_nonneg (fun ω => |X ω-∫ η, X η ∂P|) P + rw [variance_eq_sub (by simpa only [Real.norm_eq_abs] using hA)] at hv + simp only [Pi.pow_apply,sq_abs] at hv + rw [← variance_eq_integral hX.aestronglyMeasurable.aemeasurable] at hv + apply (Real.le_sqrt (integral_nonneg fun _ => abs_nonneg _) (variance_nonneg X P)).mpr + linarith + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/QuantileLimit.lean b/lean/OAI/Probability/Perceptron/Variational/QuantileLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..201434cfcb644cac4c8580db585c44a4fdbc8afc --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/QuantileLimit.lean @@ -0,0 +1,151 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.WeightedCDF +import OAI.Probability.Perceptron.Variational.SynchronizedLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set TopologicalSpace Matrix +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma scalarArray_nonnegative (μ : Measure PairedOverlapArray) [IsProbabilityMeasure μ] + (hGG : JointGhirlandaGuerra μ) {f : ℝ×ℝ→ℝ} (hf : Measurable f) + (hGram : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray f Q))) + (hdiag : ∀ᵐ Q ∂μ, ∀ i, f (Q i i) ≤ 1) : + ∀ᵐ Q ∂μ, 0 ≤ f (Q 0 1) := by + let ν := μ.map (scalarArray f) + have hm := scalarArray_measurable hf + have : IsProbabilityMeasure ν := + (Measure.isProbabilityMeasure_map_iff hm.aemeasurable).2 inferInstance + have hg : ∀ᵐ Q ∂ν, ∀ n, Matrix.PosSemidef (overlapBlock id n Q) := + (ae_map_iff hm.aemeasurable measurableSet_gram_arrays).mpr hGram + have hd : ∀ᵐ Q ∂ν, ∀ i, Q i i ≤ 1 := + (ae_map_iff hm.aemeasurable (by + simp only [ofPred_forall] + exact MeasurableSet.iInter fun i => measurableSet_le + ((measurable_pi_apply i).comp (measurable_pi_apply i)) measurable_const)).mpr hdiag + have hs : ∀ᵐ Q ∂ν, ∀ i j, Q i j=Q j i := hg.mono fun Q hQ => gram_array_symmetric Q hQ + have hp (n : ℕ) : ∀ᵐ Q ∂ν, 0 ≤ ∑ i : Fin n, ∑ j : Fin n, Q i j := by + filter_upwards [hg] with Q hQ + simpa [dotProduct,Matrix.mulVec,overlapBlock] using (hQ n).dotProduct_mulVec_nonneg (fun _ => (1:ℝ)) + have hn := gg_overlap_nonnegative ν (fun i j => by fun_prop) hs hd hp (scalarArray_gg μ hGG hf) + exact ae_of_ae_map hm.aemeasurable hn + +lemma compact_spin_nonnegative (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hGG : JointGhirlandaGuerra (compactRealLaw ν)) + (hR : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), ∀ n, Matrix.PosSemidef (fun i j : Fin n => (Q i j).1.val)) : + ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), 0 ≤ (Q 0 1).1.val := by + have hr : ∀ᵐ Q ∂compactRealLaw ν, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray Prod.fst Q)) := + ae_map_iff compactArrayReal_measurable.aemeasurable (measurableSet_gram_arrays.preimage + (scalarArray_measurable measurable_fst)) |>.mpr hR + exact ae_of_ae_map compactArrayReal_measurable.aemeasurable + (scalarArray_nonnegative (compactRealLaw ν) hGG measurable_fst hr (compactRealLaw_diagonals ν).1) + +def compactPositivePair (x : CompactJointOverlap) : Time×Time := + (⟨max 0 x.1.val,le_max_left _ _,max_le (by norm_num) x.1.property.2⟩,x.2) + +lemma compactPositivePair_measurable : Measurable compactPositivePair := by + unfold compactPositivePair + fun_prop + +def compactPositivePairLaw (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) : Measure (Time×Time) := + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => compactPositivePair (Q 0 1)) + +instance compactPositivePairLaw_probability (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) : + IsProbabilityMeasure (compactPositivePairLaw ν) := + (Measure.isProbabilityMeasure_map_iff ((compactPositivePair_measurable.comp (show Measurable (fun Q : CompactArray CompactJointOverlap => Q 0 1) from by fun_prop)).aemeasurable)).2 inferInstance + +lemma compactPositivePairLaw_no_crossing (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hGG : JointGhirlandaGuerra (compactRealLaw ν)) + (hNo : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), + ¬ ((Q 0 1).1.val < (Q 0 2).1.val ∧ (Q 0 2).2.val < (Q 0 1).2.val)) (r t : Time) : + compactPositivePairLaw ν (Iic r×ˢIoi t)=0 ∨ compactPositivePairLaw ν (Ioi r×ˢIic t)=0 := by + let A : Set (ℝ×ℝ) := {x | max 0 x.1 ≤ r.val ∧ t.val < x.2} + let B : Set (ℝ×ℝ) := {x | r.val < max 0 x.1 ∧ x.2 ≤ t.val} + have hA : MeasurableSet A := by dsimp [A]; measurability + have hB : MeasurableSet B := by dsimp [B]; measurability + have hno : ∀ᵐ Q ∂compactRealLaw ν, ¬ ((Q 0 1).1 < (Q 0 2).1 ∧ (Q 0 2).2 < (Q 0 1).2) := + (ae_map_iff compactArrayReal_measurable.aemeasurable (by measurability)).mpr hNo + have hh := joint_gg_crossed_regions_null (compactRealLaw ν) hGG hno A B hA hB + (by + intro a ha b hb + refine ⟨?_,hb.2.trans_lt ha.2⟩ + have hm : max 0 a.1 < max 0 b.1 := ha.1.trans_lt hb.1 + exact lt_of_not_ge fun h => (not_le_of_gt hm) (max_le_max_left 0 h)) + have he (S : Set (ℝ×ℝ)) (hS : MeasurableSet S) : + (compactRealLaw ν) {Q | Q 0 1∈S}=(ν : Measure (CompactArray CompactJointOverlap)) {Q | compactPairReal (Q 0 1)∈S} := by + exact Measure.map_apply compactArrayReal_measurable (hS.preimage (by fun_prop)) + rw [he A hA,he B hB] at hh + have hm : Measurable (fun Q : CompactArray CompactJointOverlap => compactPositivePair (Q 0 1)) := + compactPositivePair_measurable.comp (by fun_prop) + unfold compactPositivePairLaw + rw [Measure.map_apply hm (measurableSet_Iic.prod measurableSet_Ioi), + Measure.map_apply hm (measurableSet_Ioi.prod measurableSet_Iic)] + exact hh + +lemma compactPositivePairLaw_quantile (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hGG : JointGhirlandaGuerra (compactRealLaw ν)) + (hNo : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), + ¬ ((Q 0 1).1.val < (Q 0 2).1.val ∧ (Q 0 2).2.val < (Q 0 1).2.val)) : + (volume : Measure Time).map (fun u => + (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst) u, + boundedQuantile ((compactPositivePairLaw ν).map Prod.snd) u))=compactPositivePairLaw ν := + no_crossing_quantile_coupling _ (compactPositivePairLaw_no_crossing ν hGG hNo) + +lemma compactPositivePairLaw_label (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hT : ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), ∀ n, + Matrix.PosSemidef (fun i j : Fin n => (Q i j).2.val)) : + (compactPositivePairLaw ν).map Prod.snd= + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 1 0).2) := by + have hm : Measurable (fun Q : CompactArray CompactJointOverlap => compactPositivePair (Q 0 1)) := + compactPositivePair_measurable.comp (by fun_prop) + unfold compactPositivePairLaw + rw [Measure.map_map measurable_snd hm] + apply Measure.map_congr + filter_upwards [hT] with Q hQ + apply Subtype.ext + exact gram_array_symmetric (fun i j => (Q i j).2.val) hQ 0 1 + +variable (k : ℕ) (f : ℝ →ᵇ ℝ) (p d : ℕ → ℕ) (w : Fin (k+1) → ℝ) +variable (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) +variable (t : ℕ → ℝ≥0) (h : ℕ → Fin (k+1) → ℝ) +variable (hh0 : ∀ n l, 0 ≤ h n l) (hh : ∀ n, Monotone (h n)) +variable (u : (n : ℕ) → Fin (n+1) → ℝ) +variable (hu : ∀ n, u n ∈ Icc (fun _ => 1) (fun _ => 2)) +variable (hmin : ∀ n, IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k f (fun j => p j.val) (fun j => d j.val) (h n) (stepCumulative w) (t n) v) + (Icc (fun _ : Fin (n+1) => 1) (fun _ => 2)) (u n)) +variable {H T : ℝ} (hH : 0 ≤ H) (hhH : ∀ n, h n 0 ≤ H) (ht : ∀ n, (t n:ℝ) ≤ T) +variable (hcover : ∀ a b : ℕ, 1 ≤ a+b → ∃ j, p j=a ∧ d j=b) + +include hw hw1 hh0 hh hu hmin hH hhH ht hcover in + +theorem source_contact_limit_quantile + {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} {s : ℕ → ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f + (fun a => p a.val) (fun a => d a.val) (h (s n)) (u (s n)) (stepCumulative w) (t (s n))) atTop (𝓝 ν)) : + (∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), 0 ≤ (Q 0 1).1.val) ∧ + (compactPositivePairLaw ν).map Prod.snd=sourceLabelLaw k w ∧ + (volume : Measure Time).map (fun a => + (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst) a, + boundedQuantile ((compactPositivePairLaw ν).map Prod.snd) a))=compactPositivePairLaw ν := by + have hz := stepCumulative_strictMono w hw + have hz0 := stepCumulative_pos w hw + have hz1 := stepCumulative_lt_one w hw hw1 + have hg := source_contact_limit_joint_gg k f p d (stepCumulative w) hz hz0 hz1 t h hh0 hh u hu hmin hH hhH ht hs hlim hcover + have hgg := compactRealLaw_gg ν hg + obtain ⟨hr,htt⟩ := sourceGibbsArray_limit_gram k f (fun _ a => p a.val) + (fun _ a => d a.val) h u (stepCumulative w) t s hlim + have hn := source_contact_limit_no_crossing k f p d (stepCumulative w) hz hz0 hz1 t h hh0 hh u hu hmin hH hhH ht hcover hs hlim + refine ⟨compact_spin_nonnegative ν hgg hr,?_,compactPositivePairLaw_quantile ν hgg hn⟩ + rw [compactPositivePairLaw_label ν htt] + exact source_array_limit_label_law k f p d w hw hw1 h hh0 hh u + (fun n j => ne_of_gt ((by norm_num : (0:ℝ) < 1).trans_le ((hu n).1 j))) t + (fun b hb => by simpa only [zero_add] using hcover 0 b (by omega)) hs hlim + + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/QuantileReference.lean b/lean/OAI/Probability/Perceptron/Variational/QuantileReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..ca9e1b56b561183cbcac80b6350218680f36b1fd --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/QuantileReference.lean @@ -0,0 +1,153 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.FreshGGLogUniqueness +import OAI.Probability.Perceptron.Control.LabelProfileControl +import OAI.Probability.Perceptron.Variational.LabelProfileReferenceFull +import OAI.Probability.Perceptron.Control.QuantileControlTail + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma unit_pow_abs_sub_le (a b : Time) (r : ℕ) : + |(a:ℝ)^r-(b:ℝ)^r|≤(r:ℝ)*|(a:ℝ)-b| := by + have hm : max |(a:ℝ)| |(b:ℝ)|≤1 := by + rw [abs_of_nonneg a.prop.1,abs_of_nonneg b.prop.1] + exact max_le a.prop.2 b.prop.2 + have hp : max |(a:ℝ)| |(b:ℝ)|^(r-1)≤1 := pow_le_one₀ (by positivity) hm + calc + _ ≤ |(a:ℝ)-b| *r*max |(a:ℝ)| |(b:ℝ)|^(r-1) := abs_pow_sub_pow_le .. + _ ≤ |(a:ℝ)-b| *r*1 := mul_le_mul_of_nonneg_left hp (by positivity) + _ = _ := by ring + +lemma unit_pow_integrable {A : Type*} [MeasurableSpace A] (μ : Measure A) [IsFiniteMeasure μ] + (q : A→Time) (hq : Measurable q) (r : ℕ) : Integrable (fun u => (q u:ℝ)^r) μ := by + apply Integrable.of_bound ((measurable_subtype_coe.comp hq).pow_const r).aestronglyMeasurable 1 + exact ae_of_all _ fun u => by + change ‖(q u:ℝ)^r‖≤1 + rw [Real.norm_eq_abs,abs_of_nonneg (pow_nonneg (q u).prop.1 r)] + exact pow_le_one₀ (q u).prop.1 (q u).prop.2 + +lemma sampleQuantileLower_moment_tendsto (q : Time→Time) (hq : Monotone q) (r : ℕ) : + Tendsto (fun n => ∫ u, (sampleQuantileLower n q u:ℝ)^r ∂timeLaw) atTop + (𝓝 (∫ u, (q u:ℝ)^r ∂timeLaw)) := by + have hz : Tendsto (fun n : ℕ => (r:ℝ)*(1/(n+1:ℝ))) atTop (𝓝 0) := by + simpa using (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul (r:ℝ) + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) hz + rw [Real.dist_eq,←integral_sub (unit_pow_integrable timeLaw _ (sampleQuantileLower_mono n hq).measurable r) + (unit_pow_integrable timeLaw q hq.measurable r)] + calc + _ ≤ ∫ u, |(sampleQuantileLower n q u:ℝ)^r-(q u:ℝ)^r| ∂timeLaw := by + simpa only [Real.norm_eq_abs] using (norm_integral_le_integral_norm + (fun u => (sampleQuantileLower n q u:ℝ)^r-(q u:ℝ)^r)) + _ ≤ ∫ u, (r:ℝ)*|(sampleQuantileLower n q u:ℝ)-q u| ∂timeLaw := by + apply integral_mono + ((unit_pow_integrable timeLaw _ (sampleQuantileLower_mono n hq).measurable r).sub + (unit_pow_integrable timeLaw q hq.measurable r)).abs + (((unit_valued_integrable timeLaw (sampleQuantileLower_mono n hq).measurable).sub + (unit_valued_integrable timeLaw hq.measurable)).abs.const_mul (r:ℝ)) + exact fun u => unit_pow_abs_sub_le _ _ r + _ = (r:ℝ)*∫ u, |(sampleQuantileLower n q u:ℝ)-q u| ∂timeLaw := integral_const_mul .. + _ ≤ _ := mul_le_mul_of_nonneg_left (sampleQuantileLower_L1 n hq) (by positivity) + +def quantileSpinLaw (q : Time→Time) (hq : Measurable q) : ProbabilityMeasure CompactOverlap := + ⟨timeLaw.map (fun u=>timeSpin (q u)),(Measure.isProbabilityMeasure_map_iff + (timeSpin_continuous.measurable.comp hq).aemeasurable).2 inferInstance⟩ + +lemma quantileSpinLaw_integral (q : Time→Time) (hq : Measurable q) + (F : CompactOverlap→ℝ) (hF : Measurable F) : + (∫ x, F x ∂(quantileSpinLaw q hq : Measure CompactOverlap))=∫ u, F (timeSpin (q u)) ∂timeLaw := + integral_map (timeSpin_continuous.measurable.comp hq).aemeasurable hF.aestronglyMeasurable + +theorem quantile_reference_exists (q : Time→Time) (hq : Monotone q) (g : Jet3) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) : + ∃ (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (η : ProbabilityMeasure (FreshPartitionRange g.f)), + (∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0) ∧ + (∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) ∧ + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) ∧ + (∀ r, (∫ x, x.val^r ∂(η : Measure (FreshPartitionRange g.f)))= + ∫ Q, freshReplicaArrayKernel (expBCF 1 g.f) r Q ∂(ν : Measure _)) ∧ + (∫ x, Real.log x.val ∂(η : Measure (FreshPartitionRange g.f)))= + controlValue P g.f (quantileTrial q) := by + have hex (n : ℕ) := labelProfile_reference_full_exists n (fun _=>1/(n+1:ℝ)) + (by intro i; positivity) (uniformQuantileWeights_sum n) (uniformQuantileLower n q) + (uniformQuantileLower_mono n hq) g + choose μ ξ hGG hgeo hpair hm hl using hex + obtain ⟨ν,s,hs,hlim⟩ := compact_array_law_subsequence μ + have hG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0 := by + intro r i G a + apply compactGGDefect_limit hlim r i G a + simp only [Function.comp_apply,hGG] + exact tendsto_const_nhds + have hgeom : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q := by + apply (mem_ae_iff_prob_eq_one compactSpinGeometry_closed.measurableSet).mpr + have hv := weak_limit_closed_full hlim compactSpinGeometry_closed (fun n => ?_) + · simp only [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + · have hh := (mem_ae_iff_prob_eq_one compactSpinGeometry_closed.measurableSet).mp (hgeo (s n)) + rw [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure] at hh + exact ENNReal.coe_injective hh + have hp : (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) := by + let ρ : ProbabilityMeasure CompactOverlap := ⟨(ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1), + (Measure.isProbabilityMeasure_map_iff (show Measurable + (fun array : CompactArray CompactJointOverlap => (array 0 1).1) + from by fun_prop).aemeasurable).2 inferInstance⟩ + have he : ρ=quantileSpinLaw q hq.measurable := by + apply probability_Icc_eq_of_moments + intro r + rw [quantileSpinLaw_integral q hq.measurable (fun x => x.val^r) (by fun_prop)] + change (∫ x : CompactOverlap, x.val^r ∂(ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1))=_ + rw [integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) + from by fun_prop).aemeasurable (show Measurable (fun x : CompactOverlap => x.val^r) from by fun_prop).aestronglyMeasurable] + let F : CompactOverlap→ᵇℝ := BoundedContinuousFunction.mkOfCompact ⟨fun x=>x.val^r,by fun_prop⟩ + let FF : CompactArray CompactJointOverlap→ᵇℝ := F.compContinuous ⟨fun Q => (Q 0 1).1,by fun_prop⟩ + have hν := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction FF).continuousAt.tendsto.comp hlim + have hv n : (∫ Q, FF Q ∂(μ n : Measure _))=∫ u, (sampleQuantileLower n q u:ℝ)^r ∂timeLaw := by + change (∫ Q, F (Q 0 1).1 ∂(μ n : Measure (CompactArray CompactJointOverlap)))=_ + rw [hpair n F] + exact (uniformQuantileCell_integral n (fun i => (uniformQuantileLower n q i:ℝ)^r)).symm + change Tendsto (fun n => ∫ Q, FF Q ∂(μ (s n) : Measure (CompactArray CompactJointOverlap))) atTop + (𝓝 (∫ Q, FF Q ∂(ν : Measure (CompactArray CompactJointOverlap)))) at hν + simp_rw [hv] at hν + exact tendsto_nhds_unique hν ((sampleQuantileLower_moment_tendsto q hq r).comp hs.tendsto_atTop) + exact congrArg (fun x : ProbabilityMeasure CompactOverlap => (x : Measure CompactOverlap)) he + have hmom r : Tendsto (fun n => ∫ x, x.val^r ∂(ξ (s n) : Measure (FreshPartitionRange g.f))) atTop + (𝓝 (∫ Q, freshReplicaArrayKernel (expBCF 1 g.f) r Q ∂(ν : Measure _))) := by + simp_rw [hm] + exact (ProbabilityMeasure.continuous_integral_boundedContinuousFunction + (freshReplicaArrayKernel (expBCF 1 g.f) r)).continuousAt.tendsto.comp hlim + obtain ⟨η,hη,hηm⟩ := compact_moment_limit (fun n=>ξ (s n)) _ hmom + refine ⟨ν,η,hG,hgeom,hp,hηm,?_⟩ + have hlog : Continuous (fun x : FreshPartitionRange g.f => Real.log x.val) := + continuous_subtype_val.log fun x => ne_of_gt ((Real.exp_pos _).trans_le x.prop.1) + let F : FreshPartitionRange g.f→ᵇℝ := BoundedContinuousFunction.mkOfCompact ⟨_,hlog⟩ + have hv := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction F).continuousAt.tendsto.comp hη + have he n : (∫ x, F x ∂(ξ n : Measure (FreshPartitionRange g.f)))= + controlValue P g.f (quantileTrial (sampleQuantileLower n q)) := by + change (∫ x, Real.log x.val ∂(ξ n : Measure (FreshPartitionRange g.f)))=_ + rw [hl n,labelProfileValue_control n _ _ (uniformQuantileWeights_nonneg n) (uniformQuantileWeights_sum n) + (uniformQuantileLower_mono n hq) g P hB] + exact congrArg (controlValue P g.f) (sampleQuantile_trial n (uniformQuantileLower n q)).symm + change Tendsto (fun n => ∫ x, F x ∂(ξ (s n) : Measure (FreshPartitionRange g.f))) atTop + (𝓝 (∫ x, F x ∂(η : Measure (FreshPartitionRange g.f)))) at hv + simp_rw [he] at hv + have hc : Tendsto (fun n => controlValue P g.f (quantileTrial (sampleQuantileLower n q))) atTop + (𝓝 (controlValue P g.f (quantileTrial q))) := by + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) + (show Tendsto (fun n : ℕ => (3/2:ℝ)*(‖g.d1‖₊:ℝ)^2*(1/(n+1:ℝ))) atTop (𝓝 0) from by + simpa using (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul ((3/2:ℝ)*(‖g.d1‖₊:ℝ)^2)) + exact (sampleQuantile_control_error P g q hq n).1 + exact tendsto_nhds_unique hv (hc.comp hs.tendsto_atTop) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/QuantileSingleReference.lean b/lean/OAI/Probability/Perceptron/Variational/QuantileSingleReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..614951f046a766265ec40e55576da5fae46e62fe --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/QuantileSingleReference.lean @@ -0,0 +1,42 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.RoundedMarkedReference +import OAI.Probability.Perceptron.Variational.LabelProfileSingleReference + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +theorem quantile_single_reference_exists (q : Time→Time) (hq : Monotone q) + (g : Jet3) (v : ℝ→ᵇℝ) : ∃ c : ℝ, |c|≤‖v‖ ∧ ∀ b : Bool, + ∃ (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (η : ProbabilityMeasure (WeightedRestorationRange g.f (singleRestorationBound g.f v (secondPairMark v b)))), + (∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0) ∧ + (∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) ∧ + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) ∧ + (∀ j,(∫ x,x.1.val*x.2.val^j + ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v (secondPairMark v b)))))= + ∫ Q : CompactArray CompactJointOverlap,scalarRestorationSingleMoment g.f v (secondPairMark v b) j + (fun i l => (Q i l).1.val) ∂(ν : Measure _)) ∧ + (∫ x,x.1.val*restorationReciprocal g.f 1 x.2 + ∂(η : Measure (WeightedRestorationRange g.f (singleRestorationBound g.f v (secondPairMark v b)))))= + c^(pairMarkPower b) := by + let a : ℕ→ℝ := fun n => roundedSingleCoeff (unitQuantileField q hq) n g v + have hb (n : ℕ) : a n∈Icc (-‖v‖) ‖v‖ := abs_le.mp (roundedSingleCoeff_bound _ _ _ _) + obtain ⟨c,hc,s,hs,ht⟩ := isCompact_Icc.isSeqCompact hb + change Tendsto (fun n => roundedSingleCoeff (unitQuantileField q hq) (s n) g v) atTop (𝓝 c) at ht + refine ⟨c,abs_le.mpr hc,fun b => ?_⟩ + apply rounded_single_reference_exists q hq g v (secondPairMark v b) s hs + cases b + · simpa only [a,Function.comp_apply,secondPairMark,pairMarkPower,Bool.false_eq_true,ite_false,roundedSingleCoeff_one, + pow_one,mul_one] using ht + · simpa only [a,Function.comp_apply,secondPairMark,pairMarkPower,ite_true,pow_two] using ht.mul ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/QuantileUpperTail.lean b/lean/OAI/Probability/Perceptron/Variational/QuantileUpperTail.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e52cb4594e1b3e9e7afba6b244306833bae936a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/QuantileUpperTail.lean @@ -0,0 +1,174 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.WeightedCDF +import OAI.Probability.Perceptron.Variational.FieldRounding +import OAI.Probability.Perceptron.Variational.UniformQuantileCells + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma unit_valued_integrable (μ : Measure Time) [IsFiniteMeasure μ] + {q : Time→Time} (hq : Measurable q) : Integrable (fun u => (q u:ℝ)) μ := by + apply Integrable.mono' (integrable_const (1:ℝ)) + (measurable_subtype_coe.comp hq).aestronglyMeasurable + exact ae_of_all _ fun u => by + change ‖(q u:ℝ)‖≤1 + rw [Real.norm_eq_abs,abs_of_nonneg (q u).property.1] + exact (q u).property.2 + +lemma quantile_stoploss_integrable (μ : Measure Time) [IsFiniteMeasure μ] + {q : Time→Time} (hq : Measurable q) (r : ℝ) : + Integrable (fun u => max ((q u:ℝ)-r) 0) μ := + ((unit_valued_integrable μ hq).sub (integrable_const r)).sup (integrable_const 0) + +lemma time_tail_constant (t : Time) (r : ℝ) : + (∫ _point : Time in Ici t, r)=(1-(t:ℝ))*r := by + rw [integral_const] + simp only [Measure.real,Measure.restrict_apply_univ,unitInterval.volume_Ici,smul_eq_mul, + ENNReal.toReal_ofReal (sub_nonneg.mpr t.property.2)] + +lemma upper_tail_le_stoploss {q : Time→Time} (hq : Measurable q) (t : Time) (r : ℝ) : + (∫ u : Time in Ici t, (q u:ℝ)) ≤ + (1-(t:ℝ))*r+∫ u : Time, max ((q u:ℝ)-r) 0 := by + have hi := unit_valued_integrable volume hq + have hs := quantile_stoploss_integrable volume hq r + have he : (∫ u : Time, (Ici t).indicator (fun u => (q u:ℝ)-r) u)= + (∫ u : Time in Ici t, (q u:ℝ))-(1-(t:ℝ))*r := by + rw [integral_indicator measurableSet_Ici,integral_sub hi.integrableOn (integrable_const r), + time_tail_constant] + have hm := integral_mono ((hi.sub (integrable_const r)).indicator measurableSet_Ici) hs + (show ∀ u : Time, (Ici t).indicator (fun u => (q u:ℝ)-r) u ≤ max ((q u:ℝ)-r) 0 from by + intro u + by_cases hu : u∈Ici t + · rw [indicator_of_mem hu]; exact le_max_left _ _ + · rw [indicator_of_notMem hu]; exact le_max_right _ _) + change (∫ u : Time, (Ici t).indicator (fun u => (q u:ℝ)-r) u) ≤ _ at hm + rw [he] at hm + linarith + +lemma upper_tail_eq_stoploss {p : Time→Time} (hp : Monotone p) (t : Time) : + (∫ u : Time in Ici t, (p u:ℝ))= + (1-(t:ℝ))*(p t:ℝ)+∫ u : Time, max ((p u:ℝ)-(p t:ℝ)) 0 := by + have hi := unit_valued_integrable volume hp.measurable + have he : (fun u : Time => max ((p u:ℝ)-(p t:ℝ)) 0)= + (Ici t).indicator (fun u => (p u:ℝ)-(p t:ℝ)) := by + funext u + by_cases hu : t≤u + · rw [indicator_of_mem (show u∈Ici t from hu),max_eq_left (sub_nonneg.mpr (show (p t:ℝ)≤(p u:ℝ) from hp hu))] + · rw [indicator_of_notMem (show u∉Ici t from hu),max_eq_right (sub_nonpos.mpr (show (p u:ℝ)≤(p t:ℝ) from hp (le_of_not_ge hu)))] + rw [he,integral_indicator measurableSet_Ici,integral_sub hi.integrableOn (integrable_const _), + time_tail_constant] + ring + +theorem upper_tail_order_of_stoploss {q p : Time→Time} (hq : Measurable q) (hp : Monotone p) + (hstop : ∀ r : ℝ, (∫ u : Time, max ((q u:ℝ)-r) 0)≤ + ∫ u : Time, max ((p u:ℝ)-r) 0) (t : Time) : + (∫ u : Time in Ici t, (q u:ℝ))≤∫ u : Time in Ici t, (p u:ℝ) := by + rw [upper_tail_eq_stoploss hp t] + exact (upper_tail_le_stoploss hq t (p t:ℝ)).trans (add_le_add le_rfl (hstop (p t:ℝ))) + +lemma boundedQuantile_stoploss (μ : Measure Time) [IsProbabilityMeasure μ] (r : ℝ) : + (∫ u : Time, max ((boundedQuantile μ u:ℝ)-r) 0)=∫ x : Time, max (x.val-r) 0 ∂μ := by + conv_rhs => rw [← boundedQuantile_law μ] + rw [integral_map (boundedQuantile_measurable μ).aemeasurable (by fun_prop)] + +def uniformQuantileLower (n : ℕ) (q : Time→Time) (i : Fin (n+1)) : Time := + q (uniformQuantileGrid n i.castSucc) +def uniformQuantileUpper (n : ℕ) (q : Time→Time) (i : Fin (n+1)) : Time := + q (uniformQuantileGrid n i.succ) +def sampleQuantileLower (n : ℕ) (q : Time→Time) (u : Time) : Time := + uniformQuantileLower n q (uniformQuantileCell n u) +def sampleQuantileUpper (n : ℕ) (q : Time→Time) (u : Time) : Time := + uniformQuantileUpper n q (uniformQuantileCell n u) + +lemma uniformQuantileLower_mono (n : ℕ) {q : Time→Time} (hq : Monotone q) : + Monotone (uniformQuantileLower n q) := by + intro i j hij + exact hq ((uniformQuantileGrid_strict n).monotone (show i.castSucc ≤ j.castSucc from hij)) +lemma uniformQuantileUpper_mono (n : ℕ) {q : Time→Time} (hq : Monotone q) : + Monotone (uniformQuantileUpper n q) := by + intro i j hij + exact hq ((uniformQuantileGrid_strict n).monotone (Fin.succ_le_succ_iff.mpr hij)) +lemma sampleQuantileLower_mono (n : ℕ) {q : Time→Time} (hq : Monotone q) : + Monotone (sampleQuantileLower n q) := + (uniformQuantileLower_mono n hq).comp (uniformQuantileCell_mono n) +lemma sampleQuantileUpper_mono (n : ℕ) {q : Time→Time} (hq : Monotone q) : + Monotone (sampleQuantileUpper n q) := + (uniformQuantileUpper_mono n hq).comp (uniformQuantileCell_mono n) +lemma sampleQuantile_bracket (n : ℕ) {q : Time→Time} (hq : Monotone q) (u : Time) : + sampleQuantileLower n q u ≤ q u ∧ q u ≤ sampleQuantileUpper n q u := + ⟨hq (uniformQuantileCell_bounds n u).1,hq (uniformQuantileCell_bounds n u).2⟩ + +lemma sampleQuantile_gap_integral (n : ℕ) (q : Time→Time) : + (∫ u, ((sampleQuantileUpper n q u:ℝ)-sampleQuantileLower n q u) ∂timeLaw)= + ((q 1:ℝ)-q 0)/(n+1:ℝ) := by + change (∫ u, (fun i => (uniformQuantileUpper n q i:ℝ)-uniformQuantileLower n q i) + (uniformQuantileCell n u) ∂timeLaw)=_ + rw [uniformQuantileCell_integral n (fun i => (uniformQuantileUpper n q i:ℝ)-uniformQuantileLower n q i),← Finset.mul_sum] + unfold uniformQuantileUpper uniformQuantileLower + rw [finite_sum_successive_differences (n+1) (fun i => (q (uniformQuantileGrid n i):ℝ)), + uniformQuantileGrid_last,uniformQuantileGrid_zero] + ring + +lemma sampleQuantileLower_L1 (n : ℕ) {q : Time→Time} (hq : Monotone q) : + (∫ u, |(sampleQuantileLower n q u:ℝ)-q u| ∂timeLaw) ≤ 1/(n+1:ℝ) := by + have hl := unit_valued_integrable timeLaw (sampleQuantileLower_mono n hq).measurable + have hu := unit_valued_integrable timeLaw (sampleQuantileUpper_mono n hq).measurable + have hi := unit_valued_integrable timeLaw hq.measurable + calc + _ ≤ ∫ u, ((sampleQuantileUpper n q u:ℝ)-sampleQuantileLower n q u) ∂timeLaw := by + apply integral_mono (hl.sub hi).abs (hu.sub hl) + intro u + have hb := sampleQuantile_bracket n hq u + dsimp only [Pi.sub_apply] + rw [abs_of_nonpos (sub_nonpos.mpr (show (sampleQuantileLower n q u:ℝ) ≤ q u from hb.1))] + have ht : (q u:ℝ) ≤ sampleQuantileUpper n q u := hb.2 + linarith + _ = ((q 1:ℝ)-q 0)/(n+1:ℝ) := sampleQuantile_gap_integral n q + _ ≤ 1/(n+1:ℝ) := div_le_div_of_nonneg_right (by have := (q 1).2.2; have := (q 0).2.1; linarith) (by positivity) + +lemma sampleQuantileUpper_L1 (n : ℕ) {q : Time→Time} (hq : Monotone q) : + (∫ u, |(sampleQuantileUpper n q u:ℝ)-q u| ∂timeLaw) ≤ 1/(n+1:ℝ) := by + have hl := unit_valued_integrable timeLaw (sampleQuantileLower_mono n hq).measurable + have hu := unit_valued_integrable timeLaw (sampleQuantileUpper_mono n hq).measurable + have hi := unit_valued_integrable timeLaw hq.measurable + calc + _ ≤ ∫ u, ((sampleQuantileUpper n q u:ℝ)-sampleQuantileLower n q u) ∂timeLaw := by + apply integral_mono (hu.sub hi).abs (hu.sub hl) + intro u + have hb := sampleQuantile_bracket n hq u + dsimp only [Pi.sub_apply] + rw [abs_of_nonneg (sub_nonneg.mpr (show (q u:ℝ) ≤ sampleQuantileUpper n q u from hb.2))] + exact sub_le_sub_left (show (sampleQuantileLower n q u:ℝ) ≤ q u from hb.1) _ + _ = ((q 1:ℝ)-q 0)/(n+1:ℝ) := sampleQuantile_gap_integral n q + _ ≤ 1/(n+1:ℝ) := div_le_div_of_nonneg_right (by have := (q 1).2.2; have := (q 0).2.1; linarith) (by positivity) + +lemma uniformQuantileWeights_nonneg (n : ℕ) : ∀ _i : Fin (n+1), (0:ℝ) ≤ 1/(n+1:ℝ) := by + intro i + positivity +lemma uniformQuantileWeights_sum (n : ℕ) : (∑ _i : Fin (n+1), (1/(n+1:ℝ)))=1 := by + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] + push_cast + field_simp + +lemma sampleQuantile_trial (n : ℕ) (q : Fin (n+1)→Time) : + quantileTrial (fun u => q (uniformQuantileCell n u))= + weightedStepTrial (fun _ => 1/(n+1:ℝ)) q (uniformQuantileWeights_nonneg n) (uniformQuantileWeights_sum n) := by + apply Trial.ext_fun + intro t + have hm : Measurable (fun u => q (uniformQuantileCell n u)) := + (measurable_of_finite q).comp (uniformQuantileCell_measurable n) + rw [quantileTrial_eq_integral _ hm] + rw [uniformQuantileCell_integral n (fun i => if q i ≤ t then (1:ℝ) else 0)] + change (∑ i, (1/(n+1:ℝ))*(if q i ≤ t then (1:ℝ) else 0))=∑ i, if q i ≤ t then 1/(n+1:ℝ) else 0 + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/QuantitativeGG.lean b/lean/OAI/Probability/Perceptron/Variational/QuantitativeGG.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a2af3fac369661c65637ae4d4b1c04a26619818 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/QuantitativeGG.lean @@ -0,0 +1,170 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.EnergyMean + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +lemma sourceCoupling_gg_defect_bound (n k r : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1) → ℕ) (h : Fin (k+1) → ℝ) + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (u : Fin (n+1) → ℝ) + (j : Fin (n+1)) (i : Fin r) (z : Fin k → ℝ) (t : ℝ≥0) + {G : (Fin r → NormalizedSpin (n+1)×IndexedLeaf k) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) + (hYi : Integrable (fun a => tiltMean (sourceSpinLeafKernel n k a.1) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => |sourceCouplingEnergy n k p d h j a x|) 1) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw)) + (hci : Integrable (fun a => tiltMean (sourceSpinLeafKernel n k a.1) + (sourceCouplingHamiltonian n k f p d h u a) + (fun x => |sourceCouplingEnergy n k p d h j a x- + ∫ b, tiltMean (sourceSpinLeafKernel n k b.1) (sourceCouplingHamiltonian n k f p d h u b) + (sourceCouplingEnergy n k p d h j b) 1 ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw|) 1) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw)) : + let H := sourceCouplingHamiltonian n k f p d h u + let Y := sourceCouplingEnergy n k p d h j + let C := sourceCouplingCovariance n k p d u j + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + let EG := ∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) r G ∂P + let EY := ∫ a, tiltMean (sourceSpinLeafKernel n k a.1) (H a) (Y a) 1 ∂P + let diag := perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j*((k:ℝ)/(k+1:ℕ))^(d j) + |(∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) r (fun x => G x*∑ l, C (x i) (x l)) ∂P)- + diag*EG+EG*(∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) 2 (fun x => C (x 1) (x 0)) ∂P)- + r*(∫ a, gibbsReplicaMean (sourceSpinLeafKernel n k a.1) (H a) (r+1) + (fun x => G (fun l => x l.succ)*C (x i.succ) (x 0)) ∂P)| ≤ + B*∫ a, tiltMean (sourceSpinLeafKernel n k a.1) (H a) (fun x => |Y a x-EY|) 1 ∂P := by + dsimp only + let P := (sourceBaseDataLaw n k z t).prod countableGaussianLaw + let H := sourceCouplingHamiltonian n k f p d h u + let Y := sourceCouplingEnergy n k p d h j + let C := sourceCouplingCovariance n k p d u j + let C₀ := |perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j| + let EY := ∫ a, tiltMean (sourceSpinLeafKernel n k a.1) (H a) (Y a) 1 ∂P + have hH := sourceCouplingHamiltonian_measurable n k f p d h u + have hY := sourceCouplingEnergy_measurable n k p d h j + have hexp := sourceCoupling_exp_integrable_ae n k f p d h hh0 hh u j z t + have hf := kernel_replica_energy_factorization (sourceFullSpinLeafKernel n k) P i hH hY hG + (hexp.mono fun _ h => h.1) (hexp.mono fun _ h => h.2) hYi EY hci hB hGB + have he := sourceCoupling_annealed_ibp n k r f p d h hh0 hh u j i z t hG hB hGB hYi + have hey := sourceCoupling_energy_mean n k f p d h hh0 hh u j z t hYi + dsimp only at he hey + have hmG : Measurable (fun x : Fin (r+1) → NormalizedSpin (n+1)×IndexedLeaf k => G (fun l => x l.succ)) := + hG.comp (Measurable.of_eval fun coordinate => measurable_pi_apply coordinate.succ) + have hsum : ∀ x : Fin r → NormalizedSpin (n+1)×IndexedLeaf k, |∑ l, C (x i) (x l)| ≤ r*C₀ := by + intro x + apply (Finset.abs_sum_le_sum_abs _ _).trans + calc + _ ≤ ∑ _ : Fin r, C₀ := Finset.sum_le_sum fun l _ => sourceCouplingCovariance_bound n k p d u j _ _ + _ = _ := by simp + have h1G : Measurable (fun x : Fin r → NormalizedSpin (n+1)×IndexedLeaf k => G x*∑ l, C (x i) (x l)) := + hG.mul (Finset.measurable_sum _ fun l _ => sourceCouplingCovariance_measurable n k r p d u j i l) + have h2G : Measurable (fun x : Fin (r+1) → NormalizedSpin (n+1)×IndexedLeaf k => G (fun l => x l.succ)*C (x i.succ) (x 0)) := + hmG.mul (sourceCouplingCovariance_measurable n k (r+1) p d u j i.succ 0) + have hi1 := kernel_replicaMean_bounded_integrable (sourceFullSpinLeafKernel n k) P + (G := fun _ x => G x*∑ l, C (x i) (x l)) hH (h1G.comp measurable_snd) + (show 0 ≤ B*(r*C₀) by positivity) (fun _ x => by + rw [abs_mul]; exact mul_le_mul (hGB x) (hsum x) (abs_nonneg _) hB) + have hi2 := kernel_replicaMean_bounded_integrable (sourceFullSpinLeafKernel n k) P + (G := fun _ x => G (fun l => x l.succ)*C (x i.succ) (x 0)) hH (h2G.comp measurable_snd) + (show 0 ≤ B*C₀ by positivity) (fun _ x => by + rw [abs_mul]; exact mul_le_mul (hGB _) (sourceCouplingCovariance_bound n k p d u j _ _) (abs_nonneg _) hB) + dsimp only [sourceFullSpinLeafKernel,Kernel.comap_apply,P,H,Y,C] at hi1 hi2 hf + rw [integral_sub hi1 (hi2.const_mul r),integral_const_mul] at he + rw [he] at hf + change EY = _ at hey + apply le_trans ?_ hf + apply le_of_eq + congr 1 + rw [hey] + ring + +section +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) (P : Measure A) (H : A → S → ℝ) + +def kernelGGDefect (C : S → S → ℝ) (diag : ℝ) (r : ℕ) (i : Fin r) + (G : (Fin r → S) → ℝ) : ℝ := + (∫ a, gibbsReplicaMean (κ a) (H a) r (fun x => G x*∑ l, C (x i) (x l)) ∂P)- + diag*(∫ a, gibbsReplicaMean (κ a) (H a) r G ∂P)+ + (∫ a, gibbsReplicaMean (κ a) (H a) r G ∂P)* + (∫ a, gibbsReplicaMean (κ a) (H a) 2 (fun x => C (x 1) (x 0)) ∂P)- + r*(∫ a, gibbsReplicaMean (κ a) (H a) (r+1) + (fun x => G (fun l => x l.succ)*C (x i.succ) (x 0)) ∂P) + +lemma kernelGGDefect_const_mul [IsMarkovKernel κ] (C : S → S → ℝ) (diag c : ℝ) (r : ℕ) (i : Fin r) + (G : (Fin r → S) → ℝ) : + kernelGGDefect κ P H (fun x y => c*C x y) (c*diag) r i G = + c*kernelGGDefect κ P H C diag r i G := by + have hs : (fun x : Fin r → S => G x*∑ l, c*C (x i) (x l)) = + (fun x => c*(G x*∑ l, C (x i) (x l))) := by + funext x + rw [← Finset.mul_sum] + ring + have hp : (fun x : Fin (r+1) → S => G (fun l => x l.succ)*(c*C (x i.succ) (x 0))) = + (fun x => c*(G (fun l => x l.succ)*C (x i.succ) (x 0))) := by + funext x + ring + unfold kernelGGDefect + rw [hs,hp] + simp only [replicaMean_const_mul,integral_const_mul] + ring + +end + +lemma source_contact_joint_gg_error (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1) → ℕ) + (h : Fin (k+1) → ℝ) (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) + (u : Fin (n+1) → ℝ) (j : Fin (n+1)) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 c*(r-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j r) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) 0) + (hp : c*(0-a)^2-(∫ b, sourceKernelPressure n k f p d u h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) ≤ c*(s-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j s) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (hm : c*(0-a)^2-(∫ b, sourceKernelPressure n k f p d u h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) ≤ c*(-s-a)^2- + ∫ b, sourceKernelPressure n k f p d (u+Pi.single j (-s)) h b + ∂(sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (r : ℕ) (i : Fin r) {G : (Fin r → NormalizedSpin (n+1)×IndexedLeaf k) → ℝ} + (hG : Measurable G) {B : ℝ} (hB : 0 ≤ B) (hGB : ∀ x, |G x| ≤ B) : + |kernelGGDefect (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) (sourceJointMonomial p d j) + (((k:ℝ)/(k+1:ℕ))^(d j)) r i G| ≤ + (B*(Real.sqrt (2*c)/Real.sqrt (1/(n+1:ℕ))+ + (c*s+4*Real.sqrt (enrichedVarianceConstant k z f H T/(n+1:ℕ))/s)/(1/(n+1:ℕ))))/ + (perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j) := by + have hc := source_contact_energy_concentration n k f p d h hh0 hh u j z hz hz0 hz1 t + hH hhH ht hs hu hup hum hmin hp hm + dsimp only at hc + have hb := sourceCoupling_gg_defect_bound n k r f p d h hh0 hh u j i z t hG hB hGB hc.1 hc.2.1 + dsimp only at hb + let A := perturbationAmplitude (n+1) (fun _ => 1) j*perturbationAmplitude (n+1) u j + have hA : 0 < A := by + dsimp [A,perturbationAmplitude,perturbationScale] + have huj : 0 < u j := lt_of_lt_of_le zero_lt_one (hu j).1 + positivity + have hscale := kernelGGDefect_const_mul (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) (sourceJointMonomial p d j) + (((k:ℝ)/(k+1:ℕ))^(d j)) A r i G + change |kernelGGDefect (sourceFullSpinLeafKernel n k) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) + (sourceCouplingHamiltonian n k f p d h u) (fun x y => A*sourceJointMonomial p d j x y) + (A*(((k:ℝ)/(k+1:ℕ))^(d j))) r i G| ≤ _ at hb + rw [hscale,abs_mul,abs_of_pos hA] at hb + rw [le_div_iff₀ hA,mul_comm] + exact hb.trans (mul_le_mul_of_nonneg_left hc.2.2 hB) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/RestorationMoments.lean b/lean/OAI/Probability/Perceptron/Variational/RestorationMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b43700aea4a977df74ee7f3e91015f8b6028d04 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/RestorationMoments.lean @@ -0,0 +1,76 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.IntegrableReplicaGibbs +import OAI.Probability.Perceptron.Cascade.ReweightedMomentLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators Topology +namespace SphericalPerceptronFreeEnergy +variable {S : Type*} [MeasurableSpace S] + +def restorationReplicaTest (r : ℕ) (W : S→ℝ) (F : (Fin r→S)→ℝ) : + (k : ℕ) → (Fin (r+k)→S)→ℝ + | 0 => F + | k+1 => fun x => W (x 0)*restorationReplicaTest r W F k (fun i => x i.succ) + +lemma restorationReplicaTest_measurable (r : ℕ) {W : S→ℝ} {F : (Fin r→S)→ℝ} + (hW : Measurable W) (hF : Measurable F) (k : ℕ) : + Measurable (restorationReplicaTest r W F k) := by + induction k with + | zero => exact hF + | succ k hk => + exact (hW.comp (measurable_pi_apply 0)).mul + (hk.comp (Measurable.of_eval fun index => measurable_pi_apply index.succ)) + +omit [MeasurableSpace S] in +lemma restorationReplicaTest_bound (r : ℕ) {W : S→ℝ} {F : (Fin r→S)→ℝ} + {D B : ℝ} (hD : 0≤D) (_hB : 0≤B) (hW : ∀ x, |W x|≤D) (hF : ∀ x, |F x|≤B) + (k : ℕ) (x : Fin (r+k)→S) : |restorationReplicaTest r W F k x| ≤ D^k*B := by + induction k with + | zero => simpa only [restorationReplicaTest,pow_zero,one_mul] using hF x + | succ k hk => + rw [restorationReplicaTest,abs_mul] + exact (mul_le_mul (hW _) (hk _) (abs_nonneg _) hD).trans_eq (by ring) + +lemma restoration_replica_moment (μ : Measure S) [IsProbabilityMeasure μ] + {H W : S→ℝ} {r : ℕ} {F : (Fin r→S)→ℝ} + (hH : Measurable H) (hW : Measurable W) (hF : Measurable F) + (hi : Integrable (fun x => Real.exp (H x)) μ) + {D B : ℝ} (hD : 0≤D) (hB : 0≤B) (hWD : ∀ x, |W x|≤D) (hFB : ∀ x, |F x|≤B) + (k : ℕ) : + gibbsReplicaMean μ H (r+k) (restorationReplicaTest r W F k) = + (tiltMean μ H W 1)^k*gibbsReplicaMean μ H r F := by + induction k with + | zero => simp only [restorationReplicaTest,pow_zero,one_mul,Nat.add_zero] + | succ k hk => + change gibbsReplicaMean μ H ((r+k)+1) (fun x => W (x 0)*restorationReplicaTest r W F k (fun i => x i.succ)) = _ + rw [gibbsReplicaMean_product_of_integrable μ hH hW + (restorationReplicaTest_measurable r hW hF k) hi hWD + (restorationReplicaTest_bound r hD hB hWD hFB k), hk] + ring + +lemma restoration_ratio_tendsto {Ω : ℕ→Type*} {Ω' : Type*} + [∀ n, MeasurableSpace (Ω n)] [MeasurableSpace Ω'] + (μ : (n : ℕ)→Measure (Ω n)) (ν : Measure Ω') + [∀ n, IsProbabilityMeasure (μ n)] [IsProbabilityMeasure ν] + {a b : ℝ} (ha : 0 ∫ x, A n x*(Z n x).val^k ∂μ n) atTop + (𝓝 (∫ x, A' x*(Z' x).val^k ∂ν))) (r : ℕ) : + Tendsto (fun n => ∫ x, A n x/(Z n x).val^r ∂μ n) atTop + (𝓝 (∫ x, A' x/(Z' x).val^r ∂ν)) := by + let F : C(Icc a b,ℝ) := ⟨fun z => (z.val^r)⁻¹, + (continuous_subtype_val.pow r).inv₀ fun x => pow_ne_zero _ (ne_of_gt (ha.trans_le x.prop.1))⟩ + simpa only [F, ContinuousMap.coe_mk, div_eq_mul_inv] using bounded_weighted_moment_limit μ ν A A' Z Z' hA hA' hZ hZ' + C hC hb hb' hm F + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/RightDerivativeIntegral.lean b/lean/OAI/Probability/Perceptron/Variational/RightDerivativeIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..34592332b71737e1ea5fdd4daaecbec9319202da --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/RightDerivativeIntegral.lean @@ -0,0 +1,148 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FieldDerivative + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory Filter Set ProbabilityTheory +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction + +lemma rightDerivative_translate {F : ℝ→ℝ} {D s : ℝ} + (hd : HasDerivWithinAt (fun t => F (s+t)) D (Ici 0) 0) : + HasDerivWithinAt F D (Ici s) s := by + have hd' : HasDerivWithinAt (fun t => F (s+t)) D (Ici 0) (s-s) := by simpa using hd + have ht : HasDerivWithinAt (fun t : ℝ => t-s) 1 (Ici s) s := by + simpa using ((hasDerivAt_id s).sub_const s).hasDerivWithinAt (s := Ici s) + have hm : MapsTo (fun t : ℝ => t-s) (Ici s) (Ici 0) := by + intro t ht + change 0 ≤ t-s + exact sub_nonneg.mpr (show s ≤ t from ht) + have he := hd.comp_of_eq s ht hm (by simp) + simpa only [Function.comp_def,show ∀ x : ℝ, s+(x-s)=x by intro x; ring,mul_one] using he + +lemma integral_hasDerivWithinAt_right {A : Type*} [MeasurableSpace A] + (μ : Measure A) [IsFiniteMeasure μ] {F : A→ℝ→ℝ} {D : A→ℝ} {C : ℝ} + (hF : ∀ t, Integrable (fun a => F a t) μ) + (hD : ∀ᵐ a ∂μ, HasDerivWithinAt (F a) (D a) (Ici 0) 0) + (hC : ∀ t, 0 ≤ t → ∀ᵐ a ∂μ, |F a t-F a 0| ≤ C*t) : + HasDerivWithinAt (fun t => ∫ a, F a t ∂μ) (∫ a, D a ∂μ) (Ici 0) 0 := by + rw [hasDerivWithinAt_iff_tendsto_slope] + have he (t : ℝ) : slope (fun t => ∫ a, F a t ∂μ) 0 t = + ∫ a, slope (F a) 0 t ∂μ := by + simp only [slope,sub_zero,vsub_eq_sub,smul_eq_mul,integral_const_mul,integral_sub (hF t) (hF 0)] + change Tendsto (fun t => slope (fun t => ∫ a, F a t ∂μ) 0 t) _ _ + simp_rw [he] + apply tendsto_integral_filter_of_dominated_convergence (bound := fun _ => C) + · exact Eventually.of_forall fun t => by + simpa only [slope,sub_zero,vsub_eq_sub,smul_eq_mul,Pi.sub_apply] using ((hF t).sub (hF 0)).aestronglyMeasurable.const_mul t⁻¹ + · filter_upwards [self_mem_nhdsWithin] with t ht + have ht0 : 0 < t := lt_of_le_of_ne ht.1 (Ne.symm ht.2) + filter_upwards [hC t ht0.le] with a ha + simp only [slope,sub_zero,vsub_eq_sub,smul_eq_mul,Real.norm_eq_abs,abs_mul,abs_inv,abs_of_pos ht0] + calc + t⁻¹*|F a t-F a 0| ≤ t⁻¹*(C*t) := mul_le_mul_of_nonneg_left ha (inv_nonneg.mpr ht0.le) + _ = C := by field_simp + · exact integrable_const C + · exact hD.mono fun a ha => hasDerivWithinAt_iff_tendsto_slope.mp ha + +lemma sourceConditional_field_continuous (n k : ℕ) (f : ℝ →ᵇ ℝ) (p d : Fin (n+1)→ℕ) + (u : Fin (n+1)→ℝ) (b : SourceBaseData n k) : + Continuous (fun h => ∫ g, sourceKernelPressure n k f p d u h (b,g) ∂countableGaussianLaw) := by + apply continuous_iff_continuousAt.mpr + intro h + apply tendsto_iff_norm_sub_tendsto_zero.mpr + refine squeeze_zero (fun _ => norm_nonneg _) (g := fun h' => sourceFieldDistance p d u h' h) ?_ ?_ + · intro h' + simpa only [Real.norm_eq_abs] using sourceConditional_field_comparison n k f p d u h' h b + · have hc : Tendsto (fun h' => sourceFieldDistance p d u h' h) (𝓝 h) + (𝓝 (sourceFieldDistance p d u h h)) := (sourceFieldDistance_continuous p d u h).continuousAt + rwa [sourceFieldDistance_self] at hc + +lemma sourceConditional_field_slope (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) {h a : Fin (k+1)→ℝ} + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) + (b : SourceBaseData n k) : + HasDerivWithinAt (fun t => ∫ g, sourceKernelPressure n k f p d u (fun l => h l+t*a l) (b,g) + ∂countableGaussianLaw) + (-(∫ g, gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d h u (b,g)) 2 (sourceFieldObservable a) ∂countableGaussianLaw)) + (Ici 0) 0 := by + have H := sourceConditional_field_right_derivative n k f p d u hh0 hh ha0 ha b + dsimp only at H + rw [sourceConditional_response_eq n k f p d u h ha0 ha b] at H + convert H using 1 + field_simp + ring + +lemma sourceConditional_field_slope_at (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) {h a : Fin (k+1)→ℝ} + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) + (b : SourceBaseData n k) {s : ℝ} (hs : 0 ≤ s) : + HasDerivWithinAt (fun t => ∫ g, sourceKernelPressure n k f p d u (fun l => h l+t*a l) (b,g) + ∂countableGaussianLaw) + (-(∫ g, gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d (fun l => h l+s*a l) u (b,g)) 2 + (sourceFieldObservable a) ∂countableGaussianLaw)) (Ici s) s := by + apply rightDerivative_translate + have hd := sourceConditional_field_slope n k f p d u + (fun l => add_nonneg (hh0 l) (mul_nonneg hs (ha0 l))) (hh.add (ha.const_mul hs)) ha0 ha b + convert hd using 1 + funext t + have he : (fun l => h l+(s+t)*a l) = (fun l => h l+s*a l+t*a l) := by + funext l; ring + rw [he] + +lemma sourceConditional_field_direction_bound (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) {h a : Fin (k+1)→ℝ} + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) + (b : SourceBaseData n k) {s : ℝ} (hs : 0 ≤ s) : + |(∫ g, sourceKernelPressure n k f p d u (fun l => h l+s*a l) (b,g) ∂countableGaussianLaw)- + ∫ g, sourceKernelPressure n k f p d u h (b,g) ∂countableGaussianLaw| ≤ a (Fin.last k)*s := by + have hc : Continuous (fun t : ℝ => ∫ g, sourceKernelPressure n k f p d u (fun l => h l+t*a l) (b,g) + ∂countableGaussianLaw) := (sourceConditional_field_continuous n k f p d u b).comp (by fun_prop) + have hbound (t : ℝ) : ‖-(∫ g, gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d (fun l => h l+t*a l) u (b,g)) 2 + (sourceFieldObservable a) ∂countableGaussianLaw)‖ ≤ a (Fin.last k) := by + rw [norm_neg] + simpa only [probReal_univ,mul_one] using norm_integral_le_of_norm_le_const + (μ := countableGaussianLaw) + (ae_of_all _ fun g => show ‖gibbsReplicaMean (sourceSpinLeafKernel n k b) + (sourceCouplingHamiltonian n k f p d (fun l => h l+t*a l) u (b,g)) 2 + (sourceFieldObservable a)‖ ≤ a (Fin.last k) by + simpa only [Real.norm_eq_abs] using sourceConditional_field_observable_bound n k f p d u _ ha0 ha b g) + have he := norm_image_sub_le_of_norm_deriv_right_le_segment hc.continuousOn + (fun t ht => sourceConditional_field_slope_at n k f p d u hh0 hh ha0 ha b ht.1) + (fun t _ => hbound t) s (show s ∈ Icc 0 s from ⟨hs,le_rfl⟩) + simpa only [zero_mul,add_zero,sub_zero,Real.norm_eq_abs] using he + +theorem sourceExpectedPressure_field_right_derivative (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (u : Fin (n+1)→ℝ) {h a : Fin (k+1)→ℝ} + (hh0 : ∀ l, 0 ≤ h l) (hh : Monotone h) (ha0 : ∀ l, 0 ≤ a l) (ha : Monotone a) + (z : Fin k→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 sourceExpectedPressure n k f p d (fun l => h l+s*a l) z t u) + (-(∫ b, gibbsReplicaMean (sourceSpinLeafKernel n k b.1) + (sourceCouplingHamiltonian n k f p d h u b) 2 (sourceFieldObservable a) + ∂((sourceBaseDataLaw n k z t).prod countableGaussianLaw))) (Ici 0) 0 := by + have hi (s : ℝ) := ((sourceKernelPressure_memLp n k f p d u (fun l => h l+s*a l) + z hz hz0 hz1 t).integrable (by norm_num)) + have hd := integral_hasDerivWithinAt_right (sourceBaseDataLaw n k z t) + (fun s => (hi s).integral_prod_left) + (ae_of_all _ fun b => sourceConditional_field_slope n k f p d u hh0 hh ha0 ha b) + (C := a (Fin.last k)) (fun s hs => ae_of_all _ fun b => by + simpa only [zero_mul,add_zero] using + sourceConditional_field_direction_bound n k f p d u hh0 hh ha0 ha b hs) + have hI : Integrable (fun b => gibbsReplicaMean (sourceSpinLeafKernel n k b.1) + (sourceCouplingHamiltonian n k f p d h u b) 2 (sourceFieldObservable a)) + ((sourceBaseDataLaw n k z t).prod countableGaussianLaw) := + kernel_replicaMean_bounded_integrable (sourceFullSpinLeafKernel n k) _ + (H := sourceCouplingHamiltonian n k f p d h u) (G := fun _ => sourceFieldObservable a) + (sourceCouplingHamiltonian_measurable n k f p d h u) + ((sourceFieldObservable_measurable a).comp measurable_snd) + (ha0 _) (fun _ => sourceFieldObservable_bound ha0 ha) + simpa only [sourceExpectedPressure,integral_prod _ (hi _),integral_neg,integral_prod _ hI] using hd + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/RoundedCoupling.lean b/lean/OAI/Probability/Perceptron/Variational/RoundedCoupling.lean new file mode 100644 index 0000000000000000000000000000000000000000..67d594cce532ff13a0838745a27f35f11f2cd46e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/RoundedCoupling.lean @@ -0,0 +1,124 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.BulkMarkedTangentLimit +import OAI.Probability.Perceptron.Variational.ProbabilityMaps +import OAI.Probability.Perceptron.Variational.RoundedLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def timeGridRound (n : ℕ) (r : Time) : Time := + roundTime (unitQuantileField id monotone_id) n r + +lemma timeGridRound_tendsto (r : Time) : + Tendsto (fun n => timeGridRound n r) atTop (𝓝 r) := + roundTime_tendsto id monotone_id r + +lemma roundedTimeValue_code_ae (q : Time → Time) (hq : Monotone q) (n : ℕ) : + ∀ᵐ r ∂timeLaw.map q, + roundTimeValue (unitQuantileField q hq) n (roundedLevelCode (unitQuantileField q hq) n r) = + timeGridRound n r := by + apply (ae_map_iff hq.measurable.aemeasurable (by + apply measurableSet_eq_fun + · exact (measurable_of_countable (roundTimeValue (unitQuantileField q hq) n)).comp + (roundedLevelCode_measurable (unitQuantileField q hq) n) + · exact (show Measurable (fun r : Time => roundLower n (r : ℝ)) from + (roundLower_measurable n).comp measurable_subtype_coe).subtype_mk)).mpr + filter_upwards [orderedRoundCode_label (unitQuantileField q hq) n, + (strictRoundModel (unitQuantileField q hq) n).agrees] with u hu hv + apply Subtype.ext + change (strictRoundModel (unitQuantileField q hq) n).value + (orderedLevelCode (strictRoundModel (unitQuantileField q hq) n).value (roundLower n (q u))) = _ + change orderedLevelCode _ (roundLower n (q u : ℝ)) = _ at hu + rw [hu] + exact hv + +lemma roundedTimeValue_code_array_ae + (μ : ProbabilityMeasure (CompactArray Time)) (q : Time → Time) (hq : Monotone q) + (hpair : (μ : Measure (CompactArray Time)).map (fun Q => Q 0 1) = timeLaw.map q) + (hsy : ∀ᵐ Q ∂(μ : Measure (CompactArray Time)), ∀ i j, Q i j = Q j i) + (he : ∀ e : Equiv.Perm ℕ, MeasurePreserving (compactRelabel (K:=Time) e) + (μ : Measure _) (μ : Measure _)) : + ∀ᵐ Q ∂(μ : Measure (CompactArray Time)), ∀ n i j, i ≠ j → + roundTimeValue (unitQuantileField q hq) n (roundedLevelCode (unitQuantileField q hq) n (Q i j)) = + timeGridRound n (Q i j) := by + apply ae_all_iff.mpr + intro n + have hp := roundedTimeValue_code_ae q hq n + rw [←hpair] at hp + have hp' := ae_of_ae_map (show Measurable (fun Q : CompactArray Time => Q 0 1) from by fun_prop).aemeasurable hp + apply compact_exchangeable_offdiag_ae μ he (fun r => + roundTimeValue (unitQuantileField q hq) n (roundedLevelCode (unitQuantileField q hq) n r) = + timeGridRound n r) + filter_upwards [hp',hsy] with Q hQ hs + simpa only [hs 1 0] using hQ + +def timeMarkedDecode {K : Type*} (P : Time → K) (D : K) (Q : CompactArray Time) : CompactArray K := + fun i j => if i = j then D else P (Q i j) + +lemma timeMarkedDecode_measurable {K : Type*} [MeasurableSpace K] + {P : Time → K} (hP : Measurable P) (D : K) : Measurable (timeMarkedDecode P D) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + unfold timeMarkedDecode + split_ifs + · exact measurable_const + · exact hP.comp ((measurable_pi_apply j).comp (measurable_pi_apply i)) + +theorem cavityLabelMarkedLaw_tendsto_graph + (μ : ProbabilityMeasure (CompactArray Time)) (q : Time → Time) (hq : Monotone q) + (hpair : (μ : Measure (CompactArray Time)).map (fun Q => Q 0 1) = timeLaw.map q) + (hGG : ∀ n (i : Fin n) (F : CompactBlock Time n →ᵇ ℝ) (g : Time →ᵇ ℝ), + compactGGDefect μ n i F g = 0) + (hgeo : ∀ᵐ Q ∂(μ : Measure (CompactArray Time)), + (∀ i j, Q i j = Q j i) ∧ (∀ i, Q i i = 1) ∧ + ∀ i j l, min (Q i j) (Q i l) ≤ Q j l) + (he : ∀ e : Equiv.Perm ℕ, MeasurePreserving (compactRelabel (K:=Time) e) + (μ : Measure _) (μ : Measure _)) + {K : ℝ} (P : Time → BulkPairRange K) (hP : Continuous P) (D : BulkPairRange K) : + Tendsto (fun n => cavityLabelMarkedLaw + (fun i => P (roundTimeValue (unitQuantileField q hq) n i)) D + (stepCumulative (strictRoundModel (unitQuantileField q hq) n).weight)) atTop + (𝓝 (μ.map (timeMarkedDecode P D))) := by + let f := unitQuantileField q hq + let F n := depthMarkedDecode (fun i => P (roundTimeValue f n i)) D ∘ finiteCodeArray (roundedLevelCode f n) + let G := timeMarkedDecode P D + have hF n : Measurable (F n) := + (depthMarkedDecode_measurable _ _).comp (finiteCodeArray_measurable (roundedLevelCode_measurable f n)) + have hG : Measurable G := timeMarkedDecode_measurable hP.measurable D + have ht : ∀ᵐ Q ∂(μ : Measure (CompactArray Time)), Tendsto (fun n => F n Q) atTop (𝓝 (G Q)) := by + filter_upwards [roundedTimeValue_code_array_ae μ q hq hpair (hgeo.mono fun _ h => h.1) he] with Q hQ + apply tendsto_pi_nhds.mpr + intro i + apply tendsto_pi_nhds.mpr + intro j + by_cases hij : i = j + · simpa only [F,G,Function.comp_def,depthMarkedDecode,timeMarkedDecode,ite_eq_left hij] using + (tendsto_const_nhds : Tendsto (fun _ : ℕ => D) atTop (𝓝 D)) + · have h := hP.continuousAt.tendsto.comp (timeGridRound_tendsto (Q i j)) + convert h using 1 + · funext n + dsimp only [F,G,Function.comp_def,depthMarkedDecode,timeMarkedDecode,finiteCodeArray] + rw [ite_eq_right hij,hQ n i j hij] + · simp only [G,timeMarkedDecode,ite_eq_right hij] + have hlim := probabilityMap_tendsto_of_ae_tendsto μ F G hF hG ht + have hl n : cavityLabelMarkedLaw (fun i => P (roundTimeValue f n i)) D + (stepCumulative (strictRoundModel f n).weight) = μ.map (F n) := by + apply ProbabilityMeasure.toMeasure_injective + rw [cavityLabelMarkedLaw_eq_depth,indexedDepthLaw_eq_rounded_bulk μ q hq hpair hGG hgeo n, + Measure.map_map (depthMarkedDecode_measurable _ _) (finiteCodeArray_measurable (roundedLevelCode_measurable f n))] + rfl + change Tendsto (fun n => cavityLabelMarkedLaw (fun i => P (roundTimeValue f n i)) D + (stepCumulative (strictRoundModel f n).weight)) atTop (𝓝 (μ.map G)) + simpa only [hl] using hlim + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/RoundedLaw.lean b/lean/OAI/Probability/Perceptron/Variational/RoundedLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..abf929aa95d35edf646314c92db9df8bb016b73f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/RoundedLaw.lean @@ -0,0 +1,137 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.CavityLabelArray +import OAI.Probability.Perceptron.Variational.OrderedCode +import OAI.Probability.Perceptron.Variational.DepthGG +import OAI.Probability.Perceptron.Cascade.DepthWeights +import OAI.Probability.Perceptron.Interpolation.ArrayLawExt + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology BoundedContinuousFunction + +def roundedLevelCode (q : BoundedField 1) (n : ℕ) (r : Time) : + Fin ((strictRoundModel q n).depth+1) := + orderedLevelCode (strictRoundModel q n).value (roundLower n r) + +lemma roundedLevelCode_measurable (q : BoundedField 1) (n : ℕ) : + Measurable (roundedLevelCode q n) := + (orderedLevelCode_measurable _).comp ((roundLower_measurable n).comp measurable_subtype_coe) + +lemma roundedLevelCode_mono (q : BoundedField 1) (n : ℕ) : Monotone (roundedLevelCode q n) := + (orderedLevelCode_mono _).comp ((roundLower_monotone n).comp (Subtype.mono_coe _)) + +theorem indexedDepthLaw_eq_rounded_bulk + (μ : ProbabilityMeasure (CompactArray Time)) (q : Time → Time) (hq : Monotone q) + (hpair : (μ : Measure (CompactArray Time)).map (fun Q => Q 0 1) = timeLaw.map q) + (hGG : ∀ n (i : Fin n) (F : CompactBlock Time n →ᵇ ℝ) (g : Time →ᵇ ℝ), + compactGGDefect μ n i F g = 0) + (hgeo : ∀ᵐ Q ∂(μ : Measure (CompactArray Time)), + (∀ i j, Q i j = Q j i) ∧ (∀ i, Q i i = 1) ∧ + ∀ i j l, min (Q i j) (Q i l) ≤ Q j l) (n : ℕ) : + (indexedDepthLaw (strictRoundModel (unitQuantileField q hq) n).depth + (stepCumulative (strictRoundModel (unitQuantileField q hq) n).weight) : + Measure (FiniteOverlap (Fin ((strictRoundModel (unitQuantileField q hq) n).depth+1)))) = + (μ : Measure (CompactArray Time)).map (finiteCodeArray (roundedLevelCode (unitQuantileField q hq) n)) := by + let f := unitQuantileField q hq + let M := strictRoundModel f n + let χ := roundedLevelCode f n + let ν := (μ : Measure (CompactArray Time)).map (finiteCodeArray χ) + let ρ := (indexedDepthLaw M.depth (stepCumulative M.weight) : + Measure (FiniteOverlap (Fin (M.depth+1)))) + have hm := finiteCodeArray_measurable (roundedLevelCode_measurable f n) + have : IsProbabilityMeasure ν := by dsimp [ν]; infer_instance + have : IsProbabilityMeasure ρ := by dsimp [ρ]; infer_instance + have hν : ∀ᵐ R ∂ν, (∀ i j, R i j = R j i) ∧ (∀ i, R i i = Fin.last M.depth) ∧ + ∀ i j l, min (R i j) (R i l) ≤ R j l := by + apply (ae_map_iff hm.aemeasurable (by measurability)).mpr + filter_upwards [hgeo] with Q hQ + refine ⟨fun i j => congrArg χ (hQ.1 i j),?_,?_⟩ + · intro i + change χ (Q i i) = _ + rw [hQ.2.1 i] + exact orderedRoundCode_one f n + · intro i j l + have hχ : Monotone χ := roundedLevelCode_mono f n + have hx := hχ (hQ.2.2 i j l) + change min (χ (Q i j)) (χ (Q i l)) ≤ χ (Q j l) + by_cases hab : Q i j ≤ Q i l + · simpa only [min_eq_left hab,min_eq_left (hχ hab)] using hx + · have hba := le_of_not_ge hab + simpa only [min_eq_right hba,min_eq_right (hχ hba)] using hx + have hp : ν.map (fun R => R 0 1) = timeLaw.map M.label := by + change ((μ : Measure (CompactArray Time)).map (finiteCodeArray χ)).map _ = _ + rw [Measure.map_map (by fun_prop) hm] + have he : (fun R : FiniteOverlap (Fin (M.depth+1)) => R 0 1) ∘ finiteCodeArray χ = + χ ∘ (fun Q : CompactArray Time => Q 0 1) := rfl + rw [he,← Measure.map_map (roundedLevelCode_measurable f n) (by fun_prop),hpair, + Measure.map_map (roundedLevelCode_measurable f n) hq.measurable] + apply Measure.map_congr + exact orderedRoundCode_label f n + have hpa (c : Fin (M.depth+1)) : ρ.real {R | R 0 1 = c} = ν.real {R | R 0 1 = c} := by + have hh := congrArg (fun η : Measure (Fin (M.depth+1)) => η.real {c}) hp + rw [map_measureReal_apply (by fun_prop) (measurableSet_singleton c), + map_measureReal_apply M.measurable_label (measurableSet_singleton c)] at hh + rw [indexedDepthLaw_pair_weights M.depth M.weight M.weight_pos M.weight_sum] + exact hh.symm + apply array_law_eq_of_blocks ρ ν + exact finiteGG_block_law_unique ρ ν (Fin.last M.depth) + (indexedDepthLaw_geometry M.depth _) hν + (indexedDepthLaw_finiteGG M.depth _ (stepCumulative_strictMono M.weight M.weight_pos) + (stepCumulative_pos M.weight M.weight_pos) (stepCumulative_lt_one M.weight M.weight_pos M.weight_sum)) + (compactGG_finite_pushforward_general μ hGG (roundedLevelCode_measurable f n)) hpa + +def depthMarkedDecode {K : Type*} {k : ℕ} (p : Fin (k+1) → K) (D : K) + (R : FiniteOverlap (Fin (k+1))) : CompactArray K := + fun i j => if i = j then D else p (R i j) + +lemma depthMarkedDecode_measurable {K : Type*} [MeasurableSpace K] {k : ℕ} + (p : Fin (k+1) → K) (D : K) : Measurable (depthMarkedDecode p D) := by + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + unfold depthMarkedDecode + split_ifs + · exact measurable_const + · exact (measurable_of_countable p).comp ((measurable_pi_apply j).comp (measurable_pi_apply i)) + +lemma gibbsProbabilityKernel_zero {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] + (κ : Kernel A S) [IsMarkovKernel κ] : + gibbsProbabilityKernel κ (fun _ _ => 0) = κ := by + ext a : 1 + rw [gibbsProbabilityKernel_of_integrable κ (fun _ _ => 0) measurable_const a (integrable_const _)] + simp only [tiltLaw,tiltPartition,mul_zero,Real.exp_zero,integral_const,probReal_univ,one_smul, + ENNReal.ofReal_one,inv_one] + exact withDensity_one + +lemma annealedInfiniteReplicaMeasure_zero {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] + (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) [IsProbabilityMeasure P] : + annealedInfiniteReplicaMeasure κ P (fun _ _ => 0) measurable_const = + P ⊗ₘ kernelInfiniteReplica κ ℕ := by + simp only [annealedInfiniteReplicaMeasure,gibbsProbabilityKernel_zero] + +theorem cavityLabelMarkedLaw_eq_depth {K : ℝ} {k : ℕ} + (p : Fin (k+1) → BulkPairRange K) (D : BulkPairRange K) (z : Fin k → ℝ) : + (cavityLabelMarkedLaw p D z : Measure (CompactArray (BulkPairRange K))) = + (indexedDepthLaw k z : Measure (FiniteOverlap (Fin (k+1)))).map (depthMarkedDecode p D) := by + change Measure.map (fun a : IndexedCascadeBase k × (ℕ → IndexedLeaf k) => + cavityLabelMarkedArray p D a.2) + (annealedInfiniteReplicaMeasure (indexedLeafKernel k) + (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)) (fun _ _ => 0) _) = _ + rw [annealedInfiniteReplicaMeasure_zero] + change _ = ((indexedInfiniteLeafMeasure k z).map (fun a => indexedDepthArray k a.2)).map _ + have hm : Measurable (fun a : IndexedCascadeBase k × (ℕ → IndexedLeaf k) => + indexedDepthArray k a.2) := (indexedDepthArray_measurable k).comp measurable_snd + rw [Measure.map_map (depthMarkedDecode_measurable p D) hm] + apply congrArg (fun F => (indexedInfiniteLeafMeasure k z).map F) + funext a i j + simp only [Function.comp_def,cavityLabelMarkedArray,depthMarkedDecode,indexedDepthArray, + indexedCommonDepth_comm k (a.2 i) (a.2 j)] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/RoundedMarkedReference.lean b/lean/OAI/Probability/Perceptron/Variational/RoundedMarkedReference.lean new file mode 100644 index 0000000000000000000000000000000000000000..bd278f7e42a7a9638754fb442fc6d39c431223ad --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/RoundedMarkedReference.lean @@ -0,0 +1,145 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.LabelProfilePairReference +import OAI.Probability.Perceptron.Variational.RoundedMarkedSelection + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +theorem rounded_marked_reference_exists (q : Time→Time) (hq : Monotone q) + (g : Jet3) (v v' : ℝ→ᵇℝ) (F : CompactOverlap→ᵇℝ) (b : ℕ→ℕ) (hb : StrictMono b) + (L : ℝ) (hL : Tendsto (fun n => ∑ i,(strictRoundModel (unitQuantileField q hq) (b n)).weight i* + F (timeSpin (roundTimeValue (unitQuantileField q hq) (b n) i))* + (roundedPairCoeff (unitQuantileField q hq) (b n) g v i * + roundedPairCoeff (unitQuantileField q hq) (b n) g v' i)) atTop (𝓝 L)) : + ∃ (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (η : ProbabilityMeasure (WeightedRestorationRange g.f (pairRestorationBound g.f v v' F))), + (∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0) ∧ + (∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) ∧ + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) ∧ + (∀ j,(∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v v' F))))= + ∫ Q : CompactArray CompactJointOverlap,scalarRestorationPairMoment g.f v v' F j + (fun i l => (Q i l).1.val) ∂(ν : Measure _)) ∧ + (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 + ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v v' F))))=L := by + have hex (n : ℕ) := labelProfile_pair_reference_exists + (strictRoundModel (unitQuantileField q hq) (b n)).depth + (strictRoundModel (unitQuantileField q hq) (b n)).weight + (strictRoundModel (unitQuantileField q hq) (b n)).weight_pos + (strictRoundModel (unitQuantileField q hq) (b n)).weight_sum + (roundTimeValue (unitQuantileField q hq) (b n)) (roundTimeValue_mono _ _) g v v' F + choose μ ξ hGG hgeo hpair hm hl using hex + obtain ⟨ν,s,hs,hlim⟩ := compact_array_law_subsequence μ + have hG : ∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0 := by + intro r i G a + apply compactGGDefect_limit hlim r i G a + simp only [Function.comp_apply,hGG] + exact tendsto_const_nhds + have hgeom : ∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q := by + apply (mem_ae_iff_prob_eq_one compactSpinGeometry_closed.measurableSet).mpr + have hv := weak_limit_closed_full hlim compactSpinGeometry_closed (fun n => ?_) + · simp only [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure,hv,ENNReal.coe_one] + · have hh := (mem_ae_iff_prob_eq_one compactSpinGeometry_closed.measurableSet).mp (hgeo (s n)) + rw [←ProbabilityMeasure.ennreal_coeFn_eq_coeFn_toMeasure] at hh + exact ENNReal.coe_injective hh + have hp : (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) := by + let ρ : ProbabilityMeasure CompactOverlap := ⟨(ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1), + (Measure.isProbabilityMeasure_map_iff (show Measurable + (fun array : CompactArray CompactJointOverlap => (array 0 1).1) + from by fun_prop).aemeasurable).2 inferInstance⟩ + have he : ρ=quantileSpinLaw q hq.measurable := by + apply probability_Icc_eq_of_moments + intro r + rw [quantileSpinLaw_integral q hq.measurable (fun x => x.val^r) (by fun_prop)] + change (∫ x : CompactOverlap, x.val^r ∂(ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1))=_ + rw [integral_map (show Measurable (fun Q : CompactArray CompactJointOverlap => (Q 0 1).1) + from by fun_prop).aemeasurable (show Measurable (fun x : CompactOverlap => x.val^r) from by fun_prop).aestronglyMeasurable] + let A : CompactOverlap→ᵇℝ := BoundedContinuousFunction.mkOfCompact ⟨fun x=>x.val^r,by fun_prop⟩ + let B : CompactArray CompactJointOverlap→ᵇℝ := A.compContinuous ⟨fun Q => (Q 0 1).1,by fun_prop⟩ + have hν := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction B).continuousAt.tendsto.comp hlim + change Tendsto (fun n => ∫ Q, A (Q 0 1).1 ∂(μ (s n) : Measure (CompactArray CompactJointOverlap))) atTop + (𝓝 (∫ Q, (Q 0 1).1.val^r ∂(ν : Measure (CompactArray CompactJointOverlap)))) at hν + simp_rw [hpair] at hν + exact tendsto_nhds_unique hν + ((roundTime_sum_tendsto q hq A).comp (hb.comp hs).tendsto_atTop) + exact congrArg (fun x : ProbabilityMeasure CompactOverlap => (x : Measure CompactOverlap)) he + obtain ⟨η,-,t,ht,hη⟩ := isCompact_univ.isSeqCompact (fun n => mem_univ (ξ (s n))) + have hv := hlim.comp ht.tendsto_atTop + refine ⟨ν,η,hG,hgeom,hp,?_,?_⟩ + · intro j + let A : WeightedRestorationRange g.f (pairRestorationBound g.f v v' F) →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x => x.1.val*x.2.val^j,by fun_prop⟩ + let B : CompactArray CompactJointOverlap →ᵇ ℝ := + (scalarRestorationPairMoment g.f v v' F j).compContinuous + ⟨fun Q i l => (Q i l).1.val,by fun_prop⟩ + have h₁ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction A).continuousAt.tendsto.comp hη + have h₂ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction B).continuousAt.tendsto.comp hv + change Tendsto (fun n => ∫ x,x.1.val*x.2.val^j ∂(ξ (s (t n)) : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v v' F)))) atTop + (𝓝 (∫ x,x.1.val*x.2.val^j ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v v' F))))) at h₁ + simp_rw [hm] at h₁ + exact tendsto_nhds_unique h₁ h₂ + · let A : WeightedRestorationRange g.f (pairRestorationBound g.f v v' F) →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun x => x.1.val*restorationReciprocal g.f 2 x.2, + (continuous_subtype_val.comp continuous_fst).mul + ((restorationReciprocal g.f 2).continuous.comp continuous_snd)⟩ + have h₁ := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction A).continuousAt.tendsto.comp hη + change Tendsto (fun n => ∫ x,x.1.val*restorationReciprocal g.f 2 x.2 ∂(ξ (s (t n)) : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v v' F)))) atTop + (𝓝 (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v v' F))))) at h₁ + simp_rw [hl] at h₁ + exact tendsto_nhds_unique h₁ (hL.comp (hs.comp ht).tendsto_atTop) + +def secondPairMark (v : ℝ→ᵇℝ) (b : Bool) : ℝ→ᵇℝ := if b then v else 1 + +def pairMarkPower (b : Bool) : ℕ := if b then 2 else 1 + +lemma roundedPairCoeff_one (q : BoundedField 1) (n : ℕ) (g : Jet3) (i : Fin ((strictRoundModel q n).depth+1)) : + roundedPairCoeff q n g 1 i=1 := + labelPairCoefficient_one _ _ (stepCumulative_pos _ (strictRoundModel q n).weight_pos) _ _ _ _ + +lemma roundedPair_mark_tendsto (q : Time→Time) (hq : Monotone q) (g : Jet3) (v : ℝ→ᵇℝ) + (s : ℕ→ℕ) (hs : StrictMono s) (a : ℝ→ℝ) + (ha : ∀ r,Tendsto (fun n => roundedPairFunction (unitQuantileField q hq) (s n) g v r) + atTop (𝓝 (a r))) (F : CompactOverlap→ᵇℝ) (b : Bool) : + Tendsto (fun n => ∑ i,(strictRoundModel (unitQuantileField q hq) (s n)).weight i* + F (timeSpin (roundTimeValue (unitQuantileField q hq) (s n) i))* + (roundedPairCoeff (unitQuantileField q hq) (s n) g v i * + roundedPairCoeff (unitQuantileField q hq) (s n) g (secondPairMark v b) i)) atTop + (𝓝 (∫ u,F (timeSpin (q u))*(a (q u))^(pairMarkPower b) ∂timeLaw)) := by + have h := roundedPair_sum_tendsto q hq g v s hs a ha F (pairMarkPower b) + cases b + · simpa only [secondPairMark,pairMarkPower,Bool.false_eq_true,ite_false,roundedPairCoeff_one,pow_one,mul_one] using h + · simpa only [secondPairMark,pairMarkPower,ite_true,pow_two] using h + +theorem quantile_marked_pair_reference_exists (q : Time→Time) (hq : Monotone q) + (g : Jet3) (v : ℝ→ᵇℝ) : ∃ a : ℝ→ℝ, Monotone a ∧ (∀ r,0≤a r ∧ a r≤‖v‖^2) ∧ + ∀ (F : CompactOverlap→ᵇℝ) (b : Bool), + ∃ (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (η : ProbabilityMeasure (WeightedRestorationRange g.f (pairRestorationBound g.f v (secondPairMark v b) F))), + (∀ (r : ℕ) (i : Fin r) (G : CompactBlock CompactJointOverlap r →ᵇ ℝ) + (a : CompactJointOverlap →ᵇ ℝ), compactGGDefect ν r i G a=0) ∧ + (∀ᵐ Q ∂(ν : Measure (CompactArray CompactJointOverlap)), CompactSpinGeometry Q) ∧ + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 0 1).1)= + (quantileSpinLaw q hq.measurable : Measure CompactOverlap) ∧ + (∀ j,(∫ x,x.1.val*x.2.val^j + ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v (secondPairMark v b) F))))= + ∫ Q : CompactArray CompactJointOverlap,scalarRestorationPairMoment g.f v (secondPairMark v b) F j + (fun i l => (Q i l).1.val) ∂(ν : Measure _)) ∧ + (∫ x,x.1.val*restorationReciprocal g.f 2 x.2 + ∂(η : Measure (WeightedRestorationRange g.f (pairRestorationBound g.f v (secondPairMark v b) F))))= + ∫ u,F (timeSpin (q u))*(a (q u))^(pairMarkPower b) ∂timeLaw := by + obtain ⟨s,a,hs,ham,hab,hal⟩ := roundedPair_selection (unitQuantileField q hq) g v + refine ⟨a,ham,hab,fun F b => ?_⟩ + exact rounded_marked_reference_exists q hq g v (secondPairMark v b) F s hs _ + (roundedPair_mark_tendsto q hq g v s hs a hal F b) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/RoundedMarkedSelection.lean b/lean/OAI/Probability/Perceptron/Variational/RoundedMarkedSelection.lean new file mode 100644 index 0000000000000000000000000000000000000000..dfdca970c839a7148c0ffafde4972598158da87b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/RoundedMarkedSelection.lean @@ -0,0 +1,158 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FieldRounding +import OAI.Probability.Perceptron.Variational.CompactRestorationWitness +import OAI.Probability.Perceptron.Variational.RoundedPairCoefficients + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def unitQuantileField (q : Time→Time) (hq : Monotone q) : BoundedField 1 := + ⟨fun u => q u,fun _ _ h => hq h,fun u => (q u).prop.1,fun u => (q u).prop.2⟩ + +def strictRoundModel {H : ℝ} (q : BoundedField H) (n : ℕ) : FiniteFieldModel (q.round n) := + (exists_finiteFieldModel_strict (q.round n) (q.round n).measurable (q.round_finite n)).choose + +lemma strictRoundModel_strict {H : ℝ} (q : BoundedField H) (n : ℕ) : + StrictMono (strictRoundModel q n).value := + (exists_finiteFieldModel_strict (q.round n) (q.round n).measurable (q.round_finite n)).choose_spec + +def roundTimeValue (q : BoundedField 1) (n : ℕ) : Fin ((strictRoundModel q n).depth+1)→Time := + fun i => ⟨(strictRoundModel q n).value i,(strictRoundModel q n).values_mem + (ae_of_all _ fun u => ⟨(q.round n).nonneg u,(q.round n).le_bound u⟩) i⟩ + +lemma roundTimeValue_mono (q : BoundedField 1) (n : ℕ) : Monotone (roundTimeValue q n) := + (strictRoundModel q n).monotone_value + +def roundTime (q : BoundedField 1) (n : ℕ) (u : Time) : Time := + ⟨q.round n u,⟨(q.round n).nonneg u,(q.round n).le_bound u⟩⟩ + +lemma roundTime_mono (q : BoundedField 1) (n : ℕ) : Monotone (roundTime q n) := + (q.round n).monotone + +lemma BoundedField.round_tendsto {H : ℝ} (q : BoundedField H) (u : Time) : + Tendsto (fun n => q.round n u) atTop (𝓝 (q u)) := by + rw [tendsto_iff_dist_tendsto_zero] + apply squeeze_zero (fun _ => dist_nonneg) (fun n => ?_) + (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)) + simpa only [Real.dist_eq,Nat.cast_add,Nat.cast_one] using q.round_error n u + +lemma roundTime_tendsto (q : Time→Time) (hq : Monotone q) (u : Time) : + Tendsto (fun n => roundTime (unitQuantileField q hq) n u) atTop (𝓝 (q u)) := + tendsto_subtype_rng.mpr ((unitQuantileField q hq).round_tendsto u) + +def roundedPairCoeff (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) : + Fin ((strictRoundModel q n).depth+1)→ℝ := + labelPairCoefficient (strictRoundModel q n).depth (stepCumulative (strictRoundModel q n).weight) + (strictRoundModel q n).value g + ⟨1-roundTimeValue q n (Fin.last (strictRoundModel q n).depth), + sub_nonneg.mpr (roundTimeValue q n _).prop.2⟩ v + +lemma roundedPairCoeff_bounds (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) : + Monotone (roundedPairCoeff q n g v) ∧ + ∀ i,0≤roundedPairCoeff q n g v i ∧ roundedPairCoeff q n g v i≤‖v‖^2 := by + have h := labelPairCoefficient_bounds (strictRoundModel q n).depth + (stepCumulative (strictRoundModel q n).weight) + (stepCumulative_pos _ (strictRoundModel q n).weight_pos) (strictRoundModel q n).value g + (⟨1-roundTimeValue q n (Fin.last (strictRoundModel q n).depth), + sub_nonneg.mpr (roundTimeValue q n _).prop.2⟩ : ℝ≥0) v + exact ⟨h.2.1,fun i => ⟨h.1 i,(h.2.2.1 i).trans h.2.2.2⟩⟩ + +def roundedPairFunction (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) (r : ℝ) : ℝ := + finiteMonotoneExtension (strictRoundModel q n).value (roundedPairCoeff q n g v) (roundLower n r) + +lemma roundedPairFunction_mono (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) : + Monotone (roundedPairFunction q n g v) := + (finiteMonotoneExtension_mono _ _ (roundedPairCoeff_bounds q n g v).1).comp (roundLower_monotone n) + +lemma roundedPairFunction_bounds (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) (r : ℝ) : + 0≤roundedPairFunction q n g v r ∧ roundedPairFunction q n g v r≤‖v‖^2 := + finiteMonotoneExtension_bounds _ _ _ (fun i => ((roundedPairCoeff_bounds q n g v).2 i).1) + (fun i => ((roundedPairCoeff_bounds q n g v).2 i).2) _ + +lemma roundedPairFunction_agrees (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) : + (fun u => roundedPairFunction q n g v (q u)) =ᵐ[timeLaw] + (fun u => roundedPairCoeff q n g v ((strictRoundModel q n).label u)) := by + filter_upwards [(strictRoundModel q n).agrees] with u hu + change finiteMonotoneExtension _ _ (roundLower n (q u))=_ + change (strictRoundModel q n).value ((strictRoundModel q n).label u)=roundLower n (q u) at hu + rw [←hu,finiteMonotoneExtension_value _ _ (strictRoundModel_strict q n) (roundedPairCoeff_bounds q n g v).1] + +lemma roundedPair_selection (q : BoundedField 1) (g : Jet3) (v : ℝ→ᵇℝ) : + ∃ (s : ℕ→ℕ) (a : ℝ→ℝ), StrictMono s ∧ Monotone a ∧ + (∀ r,0≤a r ∧ a r≤‖v‖^2) ∧ ∀ r, + Tendsto (fun n => roundedPairFunction q (s n) g v r) atTop (𝓝 (a r)) := + bounded_monotone_helly _ _ (fun n => roundedPairFunction_mono q n g v) + (fun n r => roundedPairFunction_bounds q n g v r) + +lemma roundedPair_sum_integral (q : BoundedField 1) (n : ℕ) (g : Jet3) (v : ℝ→ᵇℝ) + (F : CompactOverlap→ᵇℝ) (e : ℕ) : + (∑ i,(strictRoundModel q n).weight i*F (timeSpin (roundTimeValue q n i))*(roundedPairCoeff q n g v i)^e)= + ∫ u,F (timeSpin (roundTime q n u))*(roundedPairFunction q n g v (q u))^e ∂timeLaw := by + have he := integral_finite_label (strictRoundModel q n).label (strictRoundModel q n).measurable_label + (fun i => F (timeSpin (roundTimeValue q n i))*(roundedPairCoeff q n g v i)^e) + simp only [←mul_assoc] at he + simp only [FiniteFieldModel.weight] + rw [←he] + apply integral_congr_ae + filter_upwards [(strictRoundModel q n).agrees,roundedPairFunction_agrees q n g v] with u hu hv + have ht : roundTimeValue q n ((strictRoundModel q n).label u)=roundTime q n u := Subtype.ext hu + rw [ht,hv] + +lemma roundedPair_sum_tendsto (q : Time→Time) (hq : Monotone q) (g : Jet3) (v : ℝ→ᵇℝ) + (s : ℕ→ℕ) (hs : StrictMono s) (a : ℝ→ℝ) + (ha : ∀ r,Tendsto (fun n => roundedPairFunction (unitQuantileField q hq) (s n) g v r) + atTop (𝓝 (a r))) (F : CompactOverlap→ᵇℝ) (e : ℕ) : + Tendsto (fun n => ∑ i,(strictRoundModel (unitQuantileField q hq) (s n)).weight i* + F (timeSpin (roundTimeValue (unitQuantileField q hq) (s n) i))* + (roundedPairCoeff (unitQuantileField q hq) (s n) g v i)^e) atTop + (𝓝 (∫ u,F (timeSpin (q u))*(a (q u))^e ∂timeLaw)) := by + simp_rw [roundedPair_sum_integral] + apply tendsto_integral_of_dominated_convergence (fun _ => ‖F‖*(‖v‖^2)^e) + · intro n + exact ((F.measurable.comp (timeSpin_continuous.measurable.comp (roundTime_mono _ _).measurable)).mul + (((roundedPairFunction_mono _ _ _ _).measurable.comp (unitQuantileField q hq).measurable).pow_const e)).aestronglyMeasurable + · exact integrable_const _ + · intro n + exact ae_of_all _ fun u => by + rw [norm_mul,norm_pow] + apply mul_le_mul (F.norm_coe_le_norm _) _ (by positivity) (norm_nonneg _) + apply pow_le_pow_left₀ (norm_nonneg _) + rw [Real.norm_eq_abs,abs_of_nonneg (roundedPairFunction_bounds _ _ _ _ _).1] + exact (roundedPairFunction_bounds _ _ _ _ _).2 + · exact ae_of_all _ fun u => + (((F.continuous.comp timeSpin_continuous).tendsto _).comp + ((roundTime_tendsto q hq u).comp hs.tendsto_atTop)).mul ((ha (q u)).pow e) + +lemma roundTime_sum_integral (q : BoundedField 1) (n : ℕ) (F : CompactOverlap→ᵇℝ) : + (∑ i,(strictRoundModel q n).weight i*F (timeSpin (roundTimeValue q n i)))= + ∫ u,F (timeSpin (roundTime q n u)) ∂timeLaw := by + have he := integral_finite_label (strictRoundModel q n).label (strictRoundModel q n).measurable_label + (fun i => F (timeSpin (roundTimeValue q n i))) + simp only [FiniteFieldModel.weight] + rw [←he] + apply integral_congr_ae + filter_upwards [(strictRoundModel q n).agrees] with u hu + exact congrArg (fun t => F (timeSpin t)) (Subtype.ext hu) + +lemma roundTime_sum_tendsto (q : Time→Time) (hq : Monotone q) (F : CompactOverlap→ᵇℝ) : + Tendsto (fun n => ∑ i,(strictRoundModel (unitQuantileField q hq) n).weight i* + F (timeSpin (roundTimeValue (unitQuantileField q hq) n i))) atTop + (𝓝 (∫ u,F (timeSpin (q u)) ∂timeLaw)) := by + simp_rw [roundTime_sum_integral] + apply tendsto_integral_of_dominated_convergence (fun _ => ‖F‖) + · intro n + exact (F.measurable.comp (timeSpin_continuous.measurable.comp (roundTime_mono _ _).measurable)).aestronglyMeasurable + · exact integrable_const _ + · intro n + exact ae_of_all _ fun u => F.norm_coe_le_norm _ + · exact ae_of_all _ fun u => + (((F.continuous.comp timeSpin_continuous).tendsto _).comp (roundTime_tendsto q hq u)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/RoundedPairCoefficients.lean b/lean/OAI/Probability/Perceptron/Variational/RoundedPairCoefficients.lean new file mode 100644 index 0000000000000000000000000000000000000000..5cb3123c68c325a699f4c867e810f301bab0dbd5 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/RoundedPairCoefficients.lean @@ -0,0 +1,169 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FiniteFieldModel + +namespace OAI + +noncomputable section + +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +theorem exists_finiteFieldModel_strict (f : Time → ℝ) (hf : Measurable f) + (hfin : (Set.range f).Finite) : ∃ M : FiniteFieldModel f, StrictMono M.value := by + classical + let S := hfin.toFinset + let T := S.filter (fun r => 0 < timeLaw.real (f ⁻¹' {r})) + have hae : ∀ᵐ u ∂timeLaw, f u ∈ T := by + have hnull : ∀ r ∈ S, ∀ᵐ u ∂timeLaw, f u=r → 0 < timeLaw.real (f ⁻¹' {r}) := by + intro r _hr + by_cases hp : 0 < timeLaw.real (f ⁻¹' {r}) + · exact ae_of_all _ (fun _ _ => hp) + · have hz : timeLaw (f ⁻¹' {r})=0 := by + have hz : (timeLaw (f ⁻¹' {r})).toReal=0 := le_antisymm (le_of_not_gt hp) ENNReal.toReal_nonneg + have hp := (ENNReal.toReal_eq_zero_iff _).mp hz + rcases hp with hp | hp + · exact hp + · exact (measure_ne_top _ _ hp).elim + have hnot : ∀ᵐ u ∂timeLaw, f u ≠ r := by + apply ae_iff.mpr + simpa only [Set.preimage,Set.mem_singleton_iff,not_not] using hz + filter_upwards [hnot] with u hu + exact fun h => (hu h).elim + have hall := (S.eventually_all).mpr hnull + filter_upwards [hall] with u hu + have hmem : f u ∈ S := hfin.mem_toFinset.mpr (mem_range_self u) + exact Finset.mem_filter.mpr ⟨hmem,hu (f u) hmem rfl⟩ + have hT : T.Nonempty := by + obtain ⟨u,hu⟩ := hae.exists + exact ⟨f u,hu⟩ + obtain ⟨d,hd⟩ := Nat.exists_eq_succ_of_ne_zero (Finset.card_ne_zero.mpr hT) + let e := T.orderIsoOfFin hd + let v : Fin (d+1) → ℝ := fun i => e i + have hv : StrictMono v := fun i j hij => e.strictMono hij + have hve : MeasurableEmbedding v := ⟨hv.injective,measurable_of_finite _,fun _ _ => (Set.toFinite _).measurableSet⟩ + let a : Time → Fin (d+1) := fun u => hve.invFun (f u) + have hag : (fun u => v (a u)) =ᵐ[timeLaw] f := by + filter_upwards [hae] with u hu + have hx : f u=v (e.symm ⟨f u,hu⟩) := congrArg Subtype.val (e.apply_symm_apply ⟨f u,hu⟩) |>.symm + dsimp only [a] + rw [hx,hve.leftInverse_invFun] + refine ⟨⟨d,v,a,hve.measurable_invFun.comp hf,?_,hv.monotone,hag⟩,hv⟩ + intro i + have he : a ⁻¹' {i}=ᵐ[timeLaw] f ⁻¹' {v i} := by + filter_upwards [hag] with u hu + apply propext + change (a u=i) ↔ f u=v i + rw [← hu] + exact hv.injective.eq_iff.symm + change 0 < (timeLaw (a ⁻¹' {i})).toReal + rw [measure_congr he] + exact (Finset.mem_filter.mp (e i).2).2 + +def finiteMonotoneExtension {k : ℕ} (q a : Fin (k+1)→ℝ) (r : ℝ) : ℝ := + Finset.univ.sup' Finset.univ_nonempty (fun i => if q i≤r then a i else a 0) + +lemma finiteMonotoneExtension_mono {k : ℕ} (q a : Fin (k+1)→ℝ) (_ha : Monotone a) : + Monotone (finiteMonotoneExtension q a) := by + intro r s hrs + apply Finset.sup'_le + intro i hi + by_cases hqi : q i≤r + · simp only [ite_eq_left hqi] + have h := Finset.le_sup' (s:=Finset.univ) (f:=fun j=>if q j≤ s then a j else a 0) hi + simpa only [ite_eq_left (hqi.trans hrs),finiteMonotoneExtension] using h + · simp only [ite_eq_right hqi] + have h0 := Finset.le_sup' (s:=Finset.univ) (f:=fun j=>if q j≤ s then a j else a 0) (Finset.mem_univ 0) + simpa only [finiteMonotoneExtension,ite_self] using h0 + +lemma finiteMonotoneExtension_value {k : ℕ} (q a : Fin (k+1)→ℝ) + (hq : StrictMono q) (ha : Monotone a) (j : Fin (k+1)) : + finiteMonotoneExtension q a (q j)=a j := by + apply le_antisymm + · apply Finset.sup'_le + intro i _hi + split_ifs with h + · exact ha (hq.le_iff_le.mp h) + · exact ha (Fin.zero_le j) + · have h := Finset.le_sup' (s:=Finset.univ) (f:=fun i=>if q i≤q j then a i else a 0) (Finset.mem_univ j) + simpa only [finiteMonotoneExtension,le_refl,ite_true] using h + +lemma finiteMonotoneExtension_bounds {k : ℕ} (q a : Fin (k+1)→ℝ) (C : ℝ) + (ha : ∀ i,0≤a i) (hb : ∀ i,a i≤C) (r : ℝ) : + 0≤finiteMonotoneExtension q a r ∧ finiteMonotoneExtension q a r≤C := by + constructor + · have h := Finset.le_sup' (s:=Finset.univ) (f:=fun i=>if q i≤r then a i else a 0) (Finset.mem_univ 0) + exact (ha 0).trans (by simpa only [finiteMonotoneExtension,ite_self] using h) + · apply Finset.sup'_le + intro i _hi + split_ifs <;> apply hb + +lemma monotone_tendsto_of_rat_tendsto {f : ℕ → ℝ → ℝ} {g : ℝ → ℝ} + (hf : ∀ n, Monotone (f n)) (hr : ∀ q : ℚ, + Tendsto (fun n => f n q) atTop (𝓝 (g q))) + {x : ℝ} (hg : ContinuousAt g x) : + Tendsto (fun n => f n x) atTop (𝓝 (g x)) := by + apply tendsto_order.mpr + constructor + · intro a ha + have he : ∀ᶠ y in 𝓝 x, a < g y := hg (eventually_gt_nhds ha) + obtain ⟨δ,hδ,hd⟩ := Metric.eventually_nhds_iff.mp he + obtain ⟨r,hr₁,hr₂⟩ := exists_rat_btwn (show x-δ f (s n) x) atTop (𝓝 (g x)) := by + classical + let Z : ℕ → ℚ → Icc (0 : ℝ) C := fun n r => ⟨f n r,hb n r⟩ + obtain ⟨l,-,s,hs,hl⟩ := isCompact_univ.isSeqCompact (fun n => mem_univ (Z n)) + have hr (q : ℚ) : Tendsto (fun n => f (s n) q) atTop (𝓝 (l q).val) := + continuous_subtype_val.tendsto _ |>.comp ((continuous_apply q).tendsto l |>.comp hl) + let g : ℝ → ℝ := fun x => limsup (fun n => f (s n) x) atTop + have gm : Monotone g := by + intro x y hxy + exact limsup_le_limsup (Eventually.of_forall (fun n => hf (s n) hxy)) + ((isBoundedUnder_of ⟨0,fun n => (hb (s n) x).1⟩).isCobounded_flip) + (isBoundedUnder_of ⟨C,fun n => (hb (s n) y).2⟩) + have hgq (q : ℚ) : g q=(l q).val := (hr q).limsup_eq + have hgc (x : ℝ) (hx : ContinuousAt g x) : + Tendsto (fun n => f (s n) x) atTop (𝓝 (g x)) := + monotone_tendsto_of_rat_tendsto (fun n => hf (s n)) (fun q => by rw [hgq]; exact hr q) hx + let D := {x | ¬ContinuousAt g x} + have hD : D.Countable := gm.countable_not_continuousAt + let : Countable D := hD.to_subtype + let W : ℕ → D → Icc (0 : ℝ) C := fun n x => ⟨f (s n) x,hb (s n) x⟩ + obtain ⟨v,-,t,ht,hv⟩ := isCompact_univ.isSeqCompact (fun n => mem_univ (W n)) + let a : ℝ → ℝ := fun x => if hx : x∈D then (v ⟨x,hx⟩).val else g x + have ha (x : ℝ) : Tendsto (fun n => f (s (t n)) x) atTop (𝓝 (a x)) := by + by_cases hx : x∈D + · dsimp only [a] + rw [dite_eq_left hx] + exact continuous_subtype_val.tendsto _ |>.comp + ((continuous_apply (⟨x,hx⟩ : D)).tendsto v |>.comp hv) + · dsimp only [a] + rw [dite_eq_right hx] + exact (hgc x (not_not.mp hx)).comp ht.tendsto_atTop + refine ⟨s ∘ t,a,hs.comp ht,?_,?_,ha⟩ + · intro x y hxy + exact le_of_tendsto_of_tendsto (ha x) (ha y) + (Eventually.of_forall (fun n => hf (s (t n)) hxy)) + · intro x + exact ⟨le_of_tendsto_of_tendsto tendsto_const_nhds (ha x) (Eventually.of_forall (fun n => (hb (s (t n)) x).1)), + le_of_tendsto_of_tendsto (ha x) tendsto_const_nhds (Eventually.of_forall (fun n => (hb (s (t n)) x).2))⟩ + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/Shape.lean b/lean/OAI/Probability/Perceptron/Variational/Shape.lean new file mode 100644 index 0000000000000000000000000000000000000000..a1f6194864750d3e2c762a9f9f7c411e3eaf7e43 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/Shape.lean @@ -0,0 +1,216 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedTwoShape +import OAI.Probability.Perceptron.Variational.ShapeProbability + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology + +section + +lemma countedBlockProbability_eq_excluded {I S : Type*} (p : I → ℝ×S) + (ns : List (ℕ×(S → ℝ≥0∞))) {m : ℕ} (v : Fin m → ℝ) : + countedBlockProbability p ns v = excludedBlockSum (fun i => (p i).1) + (ns.map (fun nf i => + (((∑' k, ENNReal.ofReal (Real.exp (p k).1))⁻¹)* + ENNReal.ofReal (Real.exp (p i).1))^nf.1 * nf.2 (p i).2)) v := by + induction ns generalizing m with + | nil => rfl + | cons nf ns ih => + simp only [countedBlockProbability, List.map_cons, excludedBlockSum] + apply tsum_congr + intro i + split_ifs <;> simp only [ih] + +lemma countedBlockProbability_embeddings {I S : Type*} (p : I → ℝ×S) + (hinj : Function.Injective (fun i => (p i).1)) + (ns : List (ℕ×(S → ℝ≥0∞))) : + countedBlockProbability p ns (Fin.elim0 : Fin 0 → ℝ) = + ∑' a : Fin ns.length ↪ I, ∏ j : Fin ns.length, + (((∑' k, ENNReal.ofReal (Real.exp (p k).1))⁻¹)* + ENNReal.ofReal (Real.exp (p (a j)).1))^ns[j].1 * ns[j].2 (p (a j)).2 := by + rw [countedBlockProbability_eq_excluded, excludedBlockSum_embeddings _ hinj] + exact tsum_embeddings_list_map ns _ (fun (f : I → ℝ≥0∞) a => f a) + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +lemma indexedShapeRoot_embeddings (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (hj : Function.Injective (fun a => (indexedRootPoint ν step n z F p a).1)) + (ss : List (DecoratedVisitShape X n)) (hv : ∀ s ∈ ss, s.Valid n) : + decoratedShapeProbability ν step (n+1) z F ss (p.1,indexedCascadeRealize (n+1) p.2) = + ∑' a : Fin ss.length ↪ (Σ i, Fin ((p.2.1 i).1)), + ∏ i : Fin ss.length, + (indexedBranchProbability step n F p (a i)) ^ cascadeVisitCount n (ss[i].bare n) * + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) ss[i] + ((indexedChildPoint step n p (a i).1 (a i).2.val).1, + indexedCascadeRealize n (indexedChildPoint step n p (a i).1 (a i).2.val).2) := by + rw [indexedShapeRoot_counted ν step hs n z F hF p hb hj ss hv, + countedBlockProbability_embeddings _ hj] + rw [tsum_embeddings_list_map ss _ (fun (nf : ℕ×(S×DecoratedCascade S n → ℝ≥0∞)) a => + (((∑' b, ENNReal.ofReal (Real.exp (indexedRootPoint ν step n z F p b).1))⁻¹)* + ENNReal.ofReal (Real.exp (indexedRootPoint ν step n z F p a).1))^nf.1 * + nf.2 (indexedRootPoint ν step n z F p a).2)] + simp only [indexedRootPoint_probability ν step hs n z F hF p hb hc] + rfl + +end + +def trivialDecoratedShape (X : Type) : (n : ℕ) → CascadeVisitShape n → DecoratedVisitShape X n + | 0, s => (s,fun _ => 1) + | n+1, ss => ss.map (trivialDecoratedShape X n) + +lemma trivialDecoratedShape_bare (X : Type) (n : ℕ) (s : CascadeVisitShape n) : + (trivialDecoratedShape X n s).bare n = s := by + induction n with + | zero => rfl + | succ n ih => + simp only [trivialDecoratedShape, DecoratedVisitShape.bare, List.map_map] + have h : (DecoratedVisitShape.bare n ∘ trivialDecoratedShape X n) = id := funext ih + rw [h, List.map_id] + +lemma trivialDecoratedShape_valid (X : Type) [MeasurableSpace X] + (n : ℕ) (s : CascadeVisitShape n) (hs : s.Valid n) : + (trivialDecoratedShape X n s).Valid n := by + induction n with + | zero => exact ⟨hs,measurable_const⟩ + | succ n ih => + refine ⟨fun he => hs.1 (List.map_eq_nil_iff.mp he), ?_⟩ + intro t ht + obtain ⟨s',hs',rfl⟩ := List.mem_map.mp ht + exact ih s' (hs.2 s' hs') + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +omit [MeasurableSpace X] [Nonempty S] in +lemma trivialDecoratedShape_markValue (ν : ProbabilityMeasure S) (step : X×S → X) + (n : ℕ) (z : Fin n → ℝ) (F : Fin n → X×S → ℝ) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (s : CascadeVisitShape n) (x : X) : + decoratedShapeMarkValue ν step n z F (trivialDecoratedShape X n s) x = 1 := by + induction n generalizing x with + | zero => rfl + | succ n ih => + simp only [trivialDecoratedShape, decoratedShapeMarkValue, List.map_map] + apply List.prod_eq_one + intro y hy + obtain ⟨s',hs',rfl⟩ := List.mem_map.mp hy + simp only [Function.comp_apply] + simp_rw [ih _ _ (fun i => hI i.succ) (fun i => hM i.succ), mul_one] + rw [← ofReal_integral_eq_lintegral_ofReal (hI 0 x) + (ae_of_all _ fun s => (Real.exp_pos _).le), hM 0 x, ENNReal.ofReal_one] + +lemma trivialDecoratedShape_probability_succ (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin (n+1) → ℝ) + (F : Fin (n+1) → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hb : IndexedCascadeGood (n+1) p.2.1) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (hj : Function.Injective (fun a => (indexedRootPoint ν step n z F p a).1)) + (ss : CascadeVisitShape (n+1)) (hv : ss.Valid (n+1)) : + decoratedShapeProbability ν step (n+1) z F (trivialDecoratedShape X (n+1) ss) + (p.1,indexedCascadeRealize (n+1) p.2) = + ∑' a : Fin ss.length ↪ (Σ i, Fin ((p.2.1 i).1)), + ∏ i : Fin ss.length, + (indexedBranchProbability step n F p (a i)) ^ cascadeVisitCount n ss[i] * + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) + (trivialDecoratedShape X n ss[i]) + ((indexedChildPoint step n p (a i).1 (a i).2.val).1, + indexedCascadeRealize n (indexedChildPoint step n p (a i).1 (a i).2.val).2) := by + rw [trivialDecoratedShape, indexedShapeRoot_embeddings ν step hs n z F hF p hb hc hj _ + (by intro s h; obtain ⟨t,ht,rfl⟩ := List.mem_map.mp h + exact trivialDecoratedShape_valid X n t (hv.2 t ht))] + rw [tsum_embeddings_list_map ss (trivialDecoratedShape X n) + (fun (s : DecoratedVisitShape X n) a => + (indexedBranchProbability step n F p a)^cascadeVisitCount n (s.bare n) * + decoratedShapeProbability ν step n (fun i => z i.succ) (fun i => F i.succ) s + ((indexedChildPoint step n p a.1 a.2.val).1, + indexedCascadeRealize n (indexedChildPoint step n p a.1 a.2.val).2))] + simp only [trivialDecoratedShape_bare] + +lemma indexedShapeVisit_eq_shape (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (s : CascadeVisitShape n) (hv : s.Valid n) (x : X) : + ∀ᵐ p ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)), + indexedShapeVisit step n F s (x,p) = + decoratedShapeProbability ν step n z F (trivialDecoratedShape X n s) + (x,indexedCascadeRealize n p) := by + induction n generalizing x with + | zero => exact ae_of_all _ fun p => indexedShapeVisit_zero step F s (x,p) + | succ n ih => + have hzt : StrictMono (fun i : Fin n => z i.succ) := fun i j hij => hz (Fin.succ_lt_succ_iff.mpr hij) + have he : ∀ i : Fin s.length, ∀ᵐ p ∂ + (indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1))).prod + (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))), + ∀ a b, indexedShapeVisit step n (fun j => F j.succ) s[i] + (indexedChildPoint step n (x,p) a b) = + decoratedShapeProbability ν step n (fun j => z j.succ) (fun j => F j.succ) + (trivialDecoratedShape X n s[i]) + ((indexedChildPoint step n (x,p) a b).1, + indexedCascadeRealize n (indexedChildPoint step n (x,p) a b).2) := by + intro i + exact indexedCascade_ae_children ν step hs n z + (fun p => indexedShapeVisit step n (fun j => F j.succ) s[i] p = + decoratedShapeProbability ν step n (fun j => z j.succ) (fun j => F j.succ) + (trivialDecoratedShape X n s[i]) (p.1,indexedCascadeRealize n p.2)) + (measurableSet_eq_fun (indexedShapeVisit_measurable hs n _ (fun j => hF j.succ) s[i]) + ((decoratedShapeProbability_measurable ν step hs n _ _ (fun j => hF j.succ) _ + (trivialDecoratedShape_valid X n s[i] (hv.2 _ (List.getElem_mem i.isLt)))).comp + (measurable_fst.prodMk ((indexedCascadeRealize_measurable n).comp measurable_snd)))) + (fun y => ih _ hzt (fun j => hz0 j.succ) (fun j => hz1 j.succ) _ (fun j => hF j.succ) + (fun j => hI j.succ) (fun j => hM j.succ) s[i] (hv.2 _ (List.getElem_mem i.isLt)) y) x + have hc := indexedCascade_ae_children ν step hs n z + (fun p => 0 < (indexedTiltedTotal step n (fun j => F j.succ) p).toReal) + (measurableSet_lt measurable_const ((indexedTiltedTotal_measurable hs n _ (fun j => hF j.succ)).ennreal_toReal)) + (fun y => indexedTiltedTotal_regular ν step hs n _ hzt (fun j => hz0 j.succ) (fun j => hz1 j.succ) + _ (fun j => hF j.succ) (fun j => hI j.succ) (fun j => hM j.succ) y) x + have hj := indexedCenteredRoot_simple ν step hs n z hz hz0 hz1 F hF hI hM x + have hb := (measurePreserving_fst + (μ := (indexedCascadeBaseLaw (n+1) z : Measure (IndexedCascadeBase (n+1)))) + (ν := (indexedCascadeMarksLaw ν (n+1) : Measure (IndexedCascadeMarks S (n+1))))).quasiMeasurePreserving.ae + (indexedCascadeGood_ae (n+1) z hz0 hz1) + filter_upwards [ae_all_iff.mpr he,hc,hj,hb] with p he hc hj hb + rw [indexedShapeVisit_succ step n F s hv (x,p) hc, + trivialDecoratedShape_probability_succ ν step hs n z F hF (x,p) hb hc hj s hv] + apply tsum_congr + intro a + apply Finset.prod_congr rfl + intro i hi + rw [he i (a i).1 (a i).2.val] + +theorem indexedShapeVisit_integral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (s : CascadeVisitShape n) (hv : s.Valid n) (x : X) : + (∫⁻ p, indexedShapeVisit step n F s (x,p) + ∂(indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) = + cascadeShapeLikelihood n z 0 s := by + rw [lintegral_congr_ae (indexedShapeVisit_eq_shape ν step hs n z hz hz0 hz1 F hF hI hM s hv x), + indexedShapeProbability_integral ν step hs n z hz hz0 hz1 F hF hI hM _ + (trivialDecoratedShape_valid X n s hv) x, + trivialDecoratedShape_bare, trivialDecoratedShape_markValue ν step n z F hI hM s x, mul_one] + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ShapeProbability.lean b/lean/OAI/Probability/Perceptron/Variational/ShapeProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..d297a1b04b419a89acc41912137ee9d11a8fd0b5 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ShapeProbability.lean @@ -0,0 +1,206 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.IndexedReplicaWeights +import OAI.Probability.Perceptron.Variational.DepthLaw +import OAI.Probability.Perceptron.Pressure.RootPartition + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set Filter +open scoped Classical ENNReal NNReal BigOperators Topology +namespace SphericalPerceptronFreeEnergy + +def CascadeShapeMatches : (n : ℕ) → (s : CascadeVisitShape n) → + (CascadeShapeReplicas n s → IndexedLeaf n) → Prop + | 0, _, _ => True + | n+1, ss, xs => + RootPartitionMatch (fun u => (((xs u).1, (xs u).2.1), (xs u).2.2)) ∧ + ∀ i : Fin ss.length, CascadeShapeMatches n ss[i] (fun j => (xs ⟨i,j⟩).2.2) + +lemma indexedCommonDepth_ne_zero_iff (n : ℕ) (l m : IndexedLeaf (n+1)) : + indexedCommonDepth (n+1) l m ≠ 0 ↔ l.1 = m.1 ∧ l.2.1 = m.2.1 := by + simp only [indexedCommonDepth] + split_ifs <;> simp_all + +lemma cascadeShapeMatches_iff (n : ℕ) (s : CascadeVisitShape n) + (xs : CascadeShapeReplicas n s → IndexedLeaf n) : + CascadeShapeMatches n s xs ↔ + ∀ i j, indexedCommonDepth n (xs i) (xs j) = + indexedCommonDepth n (cascadeShapeLeaves n s i) (cascadeShapeLeaves n s j) := by + induction n with + | zero => simp [CascadeShapeMatches, indexedCommonDepth] + | succ n ih => + constructor + · rintro ⟨hr, hc⟩ ⟨a,i⟩ ⟨b,j⟩ + have hroot : (xs ⟨a,i⟩).1 = (xs ⟨b,j⟩).1 ∧ + (xs ⟨a,i⟩).2.1 = (xs ⟨b,j⟩).2.1 ↔ a = b := by + simpa only [Prod.mk.injEq] using hr ⟨a,i⟩ ⟨b,j⟩ + by_cases hab : a = b + · subst b + simp only [cascadeShapeLeaves, indexedCommonDepth, ite_eq_left (hroot.mpr rfl), + and_self, ↓reduceIte] + exact congrArg Fin.succ ((ih _ _).mp (hc a) i j) + · have hv : a.val ≠ b.val := fun h => hab (Fin.ext h) + simp only [cascadeShapeLeaves, indexedCommonDepth, ite_eq_right (mt hroot.mp hab), + hv, false_and, ↓reduceIte] + · intro hm + have hr : RootPartitionMatch (fun u => (((xs u).1, (xs u).2.1), (xs u).2.2)) := by + intro u v + change ((xs u).1, (xs u).2.1) = ((xs v).1, (xs v).2.1) ↔ u.1 = v.1 + rw [Prod.mk.injEq, ← indexedCommonDepth_ne_zero_iff, hm u v, + indexedCommonDepth_ne_zero_iff] + simp only [cascadeShapeLeaves, and_true, Fin.ext_iff] + refine ⟨hr, fun a => (ih _ _).mpr ?_⟩ + intro i j + have hroot : (xs ⟨a,i⟩).1 = (xs ⟨a,j⟩).1 ∧ + (xs ⟨a,i⟩).2.1 = (xs ⟨a,j⟩).2.1 := by + simpa only [Prod.mk.injEq] using (hr ⟨a,i⟩ ⟨a,j⟩).mpr rfl + have he := hm ⟨a,i⟩ ⟨a,j⟩ + simp only [cascadeShapeLeaves, indexedCommonDepth, ite_eq_left hroot, and_self, ↓reduceIte] at he + exact Fin.succ_inj.mp he + +def indexedActiveRootEmbedding (n : ℕ) (b : IndexedCascadeBase (n+1)) : + (Σ i, Fin ((b i).1)) ↪ ℕ × ℕ where + toFun a := (a.1, a.2.val) + inj' := by + rintro ⟨i,j⟩ ⟨k,l⟩ he + obtain ⟨hik, hjl⟩ := Prod.mk.inj he + change i = k at hik + subst k + have hj : j = l := Fin.ext hjl + subst l + rfl + +def indexedActiveLeafEmbedding (n : ℕ) (b : IndexedCascadeBase (n+1)) : + ((Σ i, Fin ((b i).1)) × IndexedLeaf n) ↪ IndexedLeaf (n+1) where + toFun t := (t.1.1, t.1.2.val, t.2) + inj' := by + intro u v he + apply Prod.ext + · apply (indexedActiveRootEmbedding n b).injective + exact congrArg (fun t : IndexedLeaf (n+1) => (t.1,t.2.1)) he + · exact congrArg (fun t : IndexedLeaf (n+1) => t.2.2) he + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +def indexedShapeVisit (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (s : CascadeVisitShape n) (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : ℝ≥0∞ := + ∑' xs : CascadeShapeReplicas n s → IndexedLeaf n, + (∏ i, indexedTiltedProbability step n F p (xs i)) * + if CascadeShapeMatches n s xs then 1 else 0 + +omit [Nonempty S] in +lemma indexedShapeVisit_measurable {step : X×S → X} (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (s : CascadeVisitShape n) : Measurable (indexedShapeVisit step n F s) := by + unfold indexedShapeVisit + refine Measurable.tsum (fun xs => ?_) + have hf (i : CascadeShapeReplicas n s) : Measurable + (fun p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n) => + indexedTiltedProbability step n F p (xs i)) := + by + have hp : Measurable (fun p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n) => + (p, xs i)) := measurable_id.prodMk measurable_const + have hh := (indexedTiltedProbability_measurable (X := X) (S := S) hs n F hF).comp hp + exact hh + exact (Finset.measurable_prod Finset.univ (fun i _ => hf i)).mul_const _ + +omit [MeasurableSpace X] [Nonempty S] in +lemma indexedShapeVisit_zero (step : X×S → X) (F : Fin 0 → X×S → ℝ) + (s : CascadeVisitShape 0) (p : X×(IndexedCascadeBase 0×IndexedCascadeMarks S 0)) : + indexedShapeVisit step 0 F s p = 1 := by + simp [indexedShapeVisit, CascadeShapeMatches, indexedTiltedProbability, + indexedTiltedTotal, indexedTiltedWeight, indexedLeafWeight, + indexedShiftSum, CascadeShapeReplicas, IndexedLeaf] + +omit [MeasurableSpace X] [Nonempty S] in + +lemma indexedShapeVisit_succ (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) (ss : CascadeVisitShape (n+1)) + (hs : ss.Valid (n+1)) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) : + indexedShapeVisit step (n+1) F ss p = + ∑' a : Fin ss.length ↪ (Σ i, Fin ((p.2.1 i).1)), + ∏ i : Fin ss.length, + (indexedBranchProbability step n F p (a i)) ^ cascadeVisitCount n ss[i] * + indexedShapeVisit step n (fun l => F l.succ) ss[i] + (indexedChildPoint step n p (a i).1 (a i).2.val) := by + classical + let J (i : Fin ss.length) := CascadeShapeReplicas n ss[i] + let A := Σ i, Fin ((p.2.1 i).1) + let (i : Fin ss.length) : Nonempty (J i) := + cascadeShapeReplicas_nonempty n ss[i] (hs.2 _ (List.getElem_mem i.isLt)) + let e := indexedActiveLeafEmbedding n p.2.1 + have hw (l : IndexedLeaf (n+1)) (hl : l ∉ Set.range e) : + indexedTiltedProbability step (n+1) F p l = 0 := by + apply indexedTiltedProbability_inactive + intro h + exact hl ⟨(⟨l.1, ⟨l.2.1,h⟩⟩,l.2.2), rfl⟩ + have hweight (t : A × IndexedLeaf n) : + indexedTiltedProbability step (n+1) F p (e t) = + indexedBranchProbability step n F p t.1 * + indexedTiltedProbability step n (fun l => F l.succ) + (indexedChildPoint step n p t.1.1 t.1.2.val) t.2 := + indexedTiltedProbability_active step n F p t.1 (hc _ _) t.2 + have hm (xs : (Σ i : Fin ss.length, J i) → A × IndexedLeaf n) : + CascadeShapeMatches (n+1) ss (fun u => e (xs u)) ↔ + RootPartitionMatch xs ∧ + ∀ i : Fin ss.length, CascadeShapeMatches n ss[i] (fun j => (xs ⟨i,j⟩).2) := by + apply and_congr ?_ Iff.rfl + constructor + · intro h u v + exact (indexedActiveRootEmbedding n p.2.1).injective.eq_iff.symm.trans (h u v) + · intro h u v + exact (indexedActiveRootEmbedding n p.2.1).injective.eq_iff.trans (h u v) + change (∑' xs : (Σ i : Fin ss.length, J i) → IndexedLeaf (n+1), + (∏ i, indexedTiltedProbability step (n+1) F p (xs i)) * + if CascadeShapeMatches (n+1) ss xs then 1 else 0) = _ + rw [tsum_pi_supported e _ hw] + calc + _ = ∑' xs : (Σ i : Fin ss.length, J i) → A × IndexedLeaf n, + if RootPartitionMatch xs then + (∏ u, indexedBranchProbability step n F p (xs u).1 * + indexedTiltedProbability step n (fun l => F l.succ) + (indexedChildPoint step n p (xs u).1.1 (xs u).1.2.val) (xs u).2) * + ∏ i : Fin ss.length, + if CascadeShapeMatches n ss[i] (fun j => (xs ⟨i,j⟩).2) then 1 else 0 + else 0 := by + apply tsum_congr + intro xs + calc + _ = (∏ u, indexedBranchProbability step n F p (xs u).1 * + indexedTiltedProbability step n (fun l => F l.succ) + (indexedChildPoint step n p (xs u).1.1 (xs u).1.2.val) (xs u).2) * + (if RootPartitionMatch xs ∧ + ∀ i : Fin ss.length, CascadeShapeMatches n ss[i] (fun j => (xs ⟨i,j⟩).2) + then 1 else 0) := by + exact congrArg₂ (· * ·) (Finset.prod_congr rfl (fun u _ => hweight (xs u))) + (if_congr (hm xs) rfl rfl) + _ = _ := by + by_cases hr : RootPartitionMatch xs + · simp only [hr, true_and, ↓reduceIte] + by_cases ha : ∀ i : Fin ss.length, + CascadeShapeMatches n ss[i] (fun j => (xs ⟨i,j⟩).2) + · simp only [ha, implies_true, ↓reduceIte, Finset.prod_const_one] + · have hz : (∏ i : Fin ss.length, + if CascadeShapeMatches n ss[i] (fun j => (xs ⟨i,j⟩).2) + then (1 : ℝ≥0∞) else 0) = 0 := by + obtain ⟨i, hi⟩ := not_forall.mp ha + exact Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi) + simp only [ha, ↓reduceIte, hz] + · simp [hr] + _ = _ := by + rw [root_partition_sum_factor (J := J) (indexedBranchProbability step n F p) + (fun a l => indexedTiltedProbability step n (fun l => F l.succ) + (indexedChildPoint step n p a.1 a.2.val) l) + (fun i ys => if CascadeShapeMatches n ss[i] ys then 1 else 0)] + simp only [J, cascadeShapeReplicas_card] + rfl + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ShapeSampleLaw.lean b/lean/OAI/Probability/Perceptron/Variational/ShapeSampleLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0845652261901d850ae01091405c96d7de12027 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ShapeSampleLaw.lean @@ -0,0 +1,187 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.Shape + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Classical ENNReal NNReal BigOperators Topology + +lemma indexedShiftSum_zero {X S : Type} [MeasurableSpace S] (step : X×S → X) + (n : ℕ) (p : X×IndexedCascadeMarks S n) (l : IndexedLeaf n) : + indexedShiftSum step n (fun _ _ => 0) p l = 0 := by + induction n with + | zero => rfl + | succ n ih => simp only [indexedShiftSum, ih, add_zero] + +lemma indexedTiltedWeight_zero {X S : Type} [MeasurableSpace S] (step : X×S → X) + (n : ℕ) (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) (l : IndexedLeaf n) : + indexedTiltedWeight step n (fun _ _ => 0) p l = indexedLeafWeight n p.2.1 l := by + simp only [indexedTiltedWeight, indexedShiftSum_zero, Real.exp_zero, ENNReal.ofReal_one, mul_one] + +lemma indexedTiltedTotal_zero {X S : Type} [MeasurableSpace S] (step : X×S → X) + (n : ℕ) (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : + indexedTiltedTotal step n (fun _ _ => 0) p = (indexedLeafMeasure n p.2.1) univ := by + rw [← lintegral_one, indexedLeafMeasure_lintegral] + simp only [indexedTiltedTotal, indexedTiltedWeight_zero, mul_one] + +lemma indexedLeafMeasure_singleton (n : ℕ) (b : IndexedCascadeBase n) (l : IndexedLeaf n) : + (indexedLeafMeasure n b) {l} = indexedLeafWeight n b l := by + rw [indexedLeafMeasure, Measure.sum_apply _ (measurableSet_singleton l), tsum_eq_single l] + · simp [Measure.smul_apply] + · intro i hi + simp [Measure.smul_apply, hi] + +lemma indexedTiltedProbability_zero {X S : Type} [MeasurableSpace S] (step : X×S → X) + (n : ℕ) (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) + (hp : 0 < ((indexedLeafMeasure n p.2.1) univ).toReal) (l : IndexedLeaf n) : + indexedTiltedProbability step n (fun _ _ => 0) p l = + (indexedLeafProbability n p.2.1) {l} := by + rw [indexedTiltedProbability, indexedTiltedTotal_zero, indexedTiltedWeight_zero, + indexedLeafProbability, ite_eq_left hp, Measure.smul_apply, smul_eq_mul, + indexedLeafMeasure_singleton] + +def indexedSampleShape (n : ℕ) (s : CascadeVisitShape n) (b : IndexedCascadeBase n) : ℝ≥0∞ := + ∑' xs : CascadeShapeReplicas n s → IndexedLeaf n, + (∏ i, (indexedLeafProbability n b) {xs i}) * + if CascadeShapeMatches n s xs then 1 else 0 + +lemma indexedSampleShape_measurable (n : ℕ) (s : CascadeVisitShape n) : + Measurable (indexedSampleShape n s) := by + unfold indexedSampleShape + refine Measurable.tsum (fun xs => ?_) + exact (Finset.measurable_prod Finset.univ (fun i _ => + (Measure.measurable_coe (measurableSet_singleton (xs i))).comp + (indexedLeafProbability_measurable n))).mul_const _ + +lemma indexedSampleShape_eq_measure (n : ℕ) (s : CascadeVisitShape n) + (b : IndexedCascadeBase n) : + indexedSampleShape n s b = + (Measure.pi (fun _ : CascadeShapeReplicas n s => indexedLeafProbability n b)) + {xs | CascadeShapeMatches n s xs} := by + classical + rw [← lintegral_indicator_one ((Set.to_countable _).measurableSet), lintegral_countable'] + unfold indexedSampleShape + apply tsum_congr + intro xs + rw [Measure.pi_singleton] + simp only [Set.indicator, Set.mem_ofPred_eq, Pi.one_apply] + split_ifs <;> simp + +lemma indexedShapeVisit_zero_eq_sample {X S : Type} [MeasurableSpace X] + [MeasurableSpace S] [Nonempty S] (step : X×S → X) (n : ℕ) + (s : CascadeVisitShape n) (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) + (hp : 0 < ((indexedLeafMeasure n p.2.1) univ).toReal) : + indexedShapeVisit step n (fun _ _ => 0) s p = indexedSampleShape n s p.2.1 := by + unfold indexedShapeVisit indexedSampleShape + congr 1 + funext xs + congr 1 + exact Finset.prod_congr rfl (fun i _ => indexedTiltedProbability_zero step n p hp (xs i)) + +theorem indexedSampleShape_integral (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (s : CascadeVisitShape n) (hs : s.Valid n) : + (∫⁻ b, indexedSampleShape n s b ∂indexedCascadeBaseLaw n z) = + cascadeShapeLikelihood n z 0 s := by + let ν : ProbabilityMeasure Unit := ⟨Measure.dirac (), inferInstance⟩ + let step : Unit×Unit → Unit := fun _ => () + let B := (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)) + let M := (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks Unit n)) + have he := indexedShapeVisit_integral ν step measurable_const n z hz hz0 hz1 + (fun _ _ => 0) (fun _ => measurable_const) + (by intro i x; simp only [mul_zero, Real.exp_zero]; exact integrable_const 1) + (by intro i x; simp) s hs () + have ha : ∀ᵐ p ∂B.prod M, + indexedShapeVisit step n (fun _ _ => 0) s ((),p) = indexedSampleShape n s p.1 := by + filter_upwards [(measurePreserving_fst (μ := B) (ν := M)).quasiMeasurePreserving.ae + (indexedLeafMeasure_regular n z hz hz0 hz1)] with p hp + exact indexedShapeVisit_zero_eq_sample step n s ((),p) hp + rw [lintegral_congr_ae ha] at he + have hprod := lintegral_prod (μ := B) (ν := M) + (fun p : IndexedCascadeBase n×IndexedCascadeMarks Unit n => indexedSampleShape n s p.1) + ((indexedSampleShape_measurable n s).comp measurable_fst).aemeasurable + rw [hprod] at he + simpa only [lintegral_const, measure_univ, mul_one, B, M] using he + +def cascadeShapeFocus : (n : ℕ) → (s : CascadeVisitShape n) → s.Valid n → + CascadeShapeReplicas n s + | 0, s, hs => ⟨0,hs⟩ + | n+1, ss, hs => + let hlen := List.length_pos_iff.mpr hs.1 + ⟨⟨0,hlen⟩, cascadeShapeFocus n ss[0] (hs.2 _ (List.getElem_mem hlen))⟩ + +lemma cascadeShapeFocus_cons (n : ℕ) (s : CascadeVisitShape n) + (ss : List (CascadeVisitShape n)) (hs : CascadeVisitShape.Valid (n+1) (s::ss)) : + cascadeShapeFocus (n+1) (s::ss) hs = + ⟨0,cascadeShapeFocus n s (hs.2 s (by simp))⟩ := rfl + +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +def indexedClassMass (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (d : ℕ) (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) + (l : IndexedLeaf n) : ℝ≥0∞ := + ∑' m : IndexedLeaf n, indexedTiltedProbability step n F p m * + if d ≤ (indexedCommonDepth n l m).val then 1 else 0 + +omit [Nonempty S] in +lemma indexedClassMass_measurable (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (d : ℕ) (l : IndexedLeaf n) : Measurable (fun p => indexedClassMass step n F d p l) := by + unfold indexedClassMass + exact Measurable.tsum (fun m => + ((indexedTiltedProbability_measurable hs n F hF).comp + (measurable_id.prodMk (measurable_const (a := m)))).mul_const _) + +omit [MeasurableSpace X] [Nonempty S] in +lemma indexedClassMass_active_succ (step : X×S → X) (n : ℕ) + (F : Fin (n+1) → X×S → ℝ) (d : ℕ) + (p : X×(IndexedCascadeBase (n+1)×IndexedCascadeMarks S (n+1))) + (hc : ∀ i j, 0 < (indexedTiltedTotal step n (fun l => F l.succ) + (indexedChildPoint step n p i j)).toReal) + (a : Σ i, Fin ((p.2.1 i).1)) (l : IndexedLeaf n) : + indexedClassMass step (n+1) F (d+1) p (a.1,a.2.val,l) = + indexedBranchProbability step n F p a * + indexedClassMass step n (fun i => F i.succ) d + (indexedChildPoint step n p a.1 a.2.val) l := by + unfold indexedClassMass + rw [indexedTiltedProbability_tsum_succ step n F p hc] + rw [tsum_eq_single a] + · apply congrArg (fun v => indexedBranchProbability step n F p a * v) + apply tsum_congr + intro m + simp only [indexedCommonDepth, and_self, ↓reduceIte, Fin.val_succ, + Nat.add_le_add_iff_right] + · intro b hb + have hne : ¬ (a.1 = b.1 ∧ a.2.val = b.2.val) := by + intro he + exact hb ((activeRoot_eq_iff p.2.1 a b).mpr he).symm + simp only [indexedCommonDepth, ite_eq_right hne, Fin.val_zero, + Nat.not_add_one_le_zero, ↓reduceIte, mul_zero, tsum_zero] + +def indexedFocusedVisit (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (d : ℕ) (s : CascadeVisitShape n) (hs : s.Valid n) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : ℝ≥0∞ := + ∑' xs : CascadeShapeReplicas n s → IndexedLeaf n, + ((∏ i, indexedTiltedProbability step n F p (xs i)) * + if CascadeShapeMatches n s xs then 1 else 0) * + indexedClassMass step n F d p (xs (cascadeShapeFocus n s hs)) + +omit [Nonempty S] in +lemma indexedFocusedVisit_measurable (step : X×S → X) (hstep : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (d : ℕ) (s : CascadeVisitShape n) (hs : s.Valid n) : + Measurable (indexedFocusedVisit step n F d s hs) := by + unfold indexedFocusedVisit + refine Measurable.tsum (fun xs => ?_) + exact ((Finset.measurable_prod Finset.univ (fun i _ => + (indexedTiltedProbability_measurable hstep n F hF).comp + (measurable_id.prodMk (measurable_const (a := xs i))))).mul_const _).mul + (indexedClassMass_measurable step hstep n F hF d _) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/ShellBridge.lean b/lean/OAI/Probability/Perceptron/Variational/ShellBridge.lean new file mode 100644 index 0000000000000000000000000000000000000000..38b604d3a0c7fde4b7d24db347f7af48e85ef8c9 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/ShellBridge.lean @@ -0,0 +1,332 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereBridge + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma canonicalWeighted_compl_band_le (n : ℕ) (F : RadialSpace n → ℝ≥0∞) + (hF : Measurable F) (b ε : ℝ) {δ : ℝ} (hδ : 0 ≤ δ) : + (∫⁻ x in (normSquareBand n ε)ᶜ, F x ∂canonicalRadialMass n b) ≤ + ENNReal.ofReal (Real.exp (-δ*((n+1:ℕ):ℝ)*(1+ε)/2)) * + (∫⁻ x, F x ∂canonicalRadialMass n (b-δ)) + + ENNReal.ofReal (Real.exp (δ*((n+1:ℕ):ℝ)*(1-ε)/2)) * + (∫⁻ x, F x ∂canonicalRadialMass n (b+δ)) := by + have hs : (normSquareBand n ε)ᶜ ⊆ + {x : RadialSpace n | ((n+1:ℕ):ℝ)*(1+ε) ≤ ‖x‖^2} ∪ + {x : RadialSpace n | ‖x‖^2 ≤ ((n+1:ℕ):ℝ)*(1-ε)} := by + intro x hx + simp only [normSquareBand,mem_compl_iff,mem_ofPred_eq,not_and_or,not_le] at hx + rcases hx with hx | hx + · exact Or.inr hx.le + · exact Or.inl hx.le + exact (lintegral_mono_set hs).trans ((lintegral_union_le _ _ _).trans + (add_le_add (canonicalWeighted_upper_tail n F hF b ε hδ) + (canonicalWeighted_lower_tail n F hF b ε hδ))) + +lemma exp_log_quotient_mul {x y u : ℝ} (hx : 0 < x) (hy : 0 < y) + (hu : 0 < u) (c : ℝ) : + Real.exp (Real.log (y/u)-Real.log (x/u)+c)*x = Real.exp c*y := by + rw [Real.exp_add,Real.exp_sub,Real.exp_log (div_pos hy hu), + Real.exp_log (div_pos hx hu)] + field_simp + +def canonicalCoordinateBandTotalE (n k : ℕ) (σ : ℕ → ℝ) (b ε : ℝ) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : ℝ≥0∞ := + ∫⁻ x in normSquareBand n ε, + decoratedFieldFactor (n+1) (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p x ∂canonicalRadialMass n b + +lemma canonicalCoordinateBandTotalE_le (n k : ℕ) (σ : ℕ → ℝ) {b : ℝ} + (hb : 0 < b) (ε : ℝ) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) : + canonicalCoordinateBandTotalE n k σ b ε p ≤ + decoratedTerminalTotalE (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k p := by + rw [canonicalCoordinateTotalE_eq_radial n k σ hb] + exact setLIntegral_le_lintegral _ _ + +lemma canonicalCoordinate_half_band (n k : ℕ) (σ : ℕ → ℝ) {b δ : ℝ} + (hb : 0 < b) (hδ : 0 ≤ δ) (hbm : 0 < b-δ) (ε : ℝ) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + (hc : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p) + (hm : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) (b-δ)) k p) + (hp : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) (b+δ)) k p) + (hrm : Real.exp (canonicalCoordinateLog (n+1) k σ (b-δ) p - + canonicalCoordinateLog (n+1) k σ b p - ((n+1:ℕ):ℝ)*(δ*(1+ε)/2)) ≤ 1/4) + (hrp : Real.exp (canonicalCoordinateLog (n+1) k σ (b+δ) p - + canonicalCoordinateLog (n+1) k σ b p - ((n+1:ℕ):ℝ)*(-δ*(1-ε)/2)) ≤ 1/4) : + decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k p / 2 ≤ + (canonicalCoordinateBandTotalE n k σ b ε p).toReal := by + let F := decoratedFieldFactor (n+1) (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p + have hF : Measurable F := decoratedFieldFactor_measurable (n+1) _ + (canonicalCoordinateStep_measurable (n+1) σ) _ (coordinateLeafField_measurable (n+1)) k p + let T := fun a => decoratedTerminalTotalE (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) a) k p + let B := canonicalCoordinateBandTotalE n k σ b ε p + have ht : T b ≠ ∞ := (ENNReal.toReal_pos_iff.mp hc).2.ne + have hmt : T (b-δ) ≠ ∞ := (ENNReal.toReal_pos_iff.mp hm).2.ne + have hpt : T (b+δ) ≠ ∞ := (ENNReal.toReal_pos_iff.mp hp).2.ne + have hBt : B ≠ ∞ := ne_top_of_le_ne_top ht (canonicalCoordinateBandTotalE_le n k σ hb ε p) + have he := lintegral_add_compl F (μ := canonicalRadialMass n b) (normSquareBand_measurable n ε) + have hu := canonicalWeighted_compl_band_le n F hF b ε hδ + have hbp : 0 < b+δ := add_pos_of_pos_of_nonneg hb hδ + have hid (a : ℝ) (ha : 0 < a) : (∫⁻ x, F x ∂canonicalRadialMass n a) = T a := + (canonicalCoordinateTotalE_eq_radial n k σ ha p).symm + rw [hid b hb] at he + rw [hid (b-δ) hbm,hid (b+δ) hbp] at hu + have hbnd : T b ≤ B + (ENNReal.ofReal (Real.exp (-δ*((n+1:ℕ):ℝ)*(1+ε)/2)) * T (b-δ) + + ENNReal.ofReal (Real.exp (δ*((n+1:ℕ):ℝ)*(1-ε)/2)) * T (b+δ)) := by + rw [← he] + exact add_le_add le_rfl hu + have hre := ENNReal.toReal_mono (ENNReal.add_ne_top.mpr ⟨hBt, + ENNReal.add_ne_top.mpr ⟨ENNReal.mul_ne_top ENNReal.ofReal_ne_top hmt, + ENNReal.mul_ne_top ENNReal.ofReal_ne_top hpt⟩⟩) hbnd + rw [ENNReal.toReal_add hBt (ENNReal.add_ne_top.mpr ⟨ENNReal.mul_ne_top ENNReal.ofReal_ne_top hmt, + ENNReal.mul_ne_top ENNReal.ofReal_ne_top hpt⟩), + ENNReal.toReal_add (ENNReal.mul_ne_top ENNReal.ofReal_ne_top hmt) + (ENNReal.mul_ne_top ENNReal.ofReal_ne_top hpt),ENNReal.toReal_mul,ENNReal.toReal_mul, + ENNReal.toReal_ofReal (Real.exp_pos _).le,ENNReal.toReal_ofReal (Real.exp_pos _).le] at hre + have hem := exp_log_quotient_mul hc hm h0 (-δ*((n+1:ℕ):ℝ)*(1+ε)/2) + have hep := exp_log_quotient_mul hc hp h0 (δ*((n+1:ℕ):ℝ)*(1-ε)/2) + change Real.exp (canonicalCoordinateLog (n+1) k σ (b-δ) p- + canonicalCoordinateLog (n+1) k σ b p + _) * (T b).toReal = + Real.exp (-δ*((n+1:ℕ):ℝ)*(1+ε)/2)*(T (b-δ)).toReal at hem + change Real.exp (canonicalCoordinateLog (n+1) k σ (b+δ) p- + canonicalCoordinateLog (n+1) k σ b p + _) * (T b).toReal = + Real.exp (δ*((n+1:ℕ):ℝ)*(1-ε)/2)*(T (b+δ)).toReal at hep + change 0 < (T b).toReal at hc + have hm' : Real.exp (-δ*((n+1:ℕ):ℝ)*(1+ε)/2)*(T (b-δ)).toReal ≤ (T b).toReal/4 := by + rw [← hem] + convert mul_le_mul_of_nonneg_right hrm hc.le using 1 <;> congr 1 <;> ring_nf + have hp' : Real.exp (δ*((n+1:ℕ):ℝ)*(1-ε)/2)*(T (b+δ)).toReal ≤ (T b).toReal/4 := by + rw [← hep] + convert mul_le_mul_of_nonneg_right hrp hc.le using 1 <;> congr 1 <;> ring_nf + change (T b).toReal/2 ≤ B.toReal + linarith + +theorem canonicalCoordinate_bad_half_band_tendsto_zero (k : ℕ) (σ : ℕ → ℝ) + (z : Fin k → ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (r : ℝ≥0) (b : ℝ) (hp : 0 < quadraticCascadePrecision σ b k z) + (hstat : -1/(2*b)+quadraticCascadeReciprocalSlope σ b k z- + (r:ℝ)/(2*(quadraticCascadePrecision σ b k z)^2) = -1/2) + {ε : ℝ} (hε : 0 < ε) : + Tendsto (fun n : ℕ => coordinateCascadeLaw (n+1) k z r + {p | (canonicalCoordinateBandTotalE n k σ b ε ((fun i _ => p.1 i),p.2)).toReal < + decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k ((fun i _ => p.1 i),p.2)/2}) atTop (𝓝 0) := by + obtain ⟨δ,hδ,hpm,hpp,hrm,hrp⟩ := canonical_stationary_tail_rates σ k z + (fun i => (hz0 i).le) r b hp hstat hε + have hb : 0 < b := hp.trans_le (quadraticCascadePrecision_le σ b k z (fun i => (hz0 i).le)) + have hbm : 0 < b-δ := hpm.trans_le (quadraticCascadePrecision_le σ (b-δ) k z (fun i => (hz0 i).le)) + let Xm := fun n (p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) => + Real.exp (canonicalCoordinateLog (n+1) k σ (b-δ) ((fun i _ => p.1 i),p.2)- + canonicalCoordinateLog (n+1) k σ b ((fun i _ => p.1 i),p.2)-((n+1:ℕ):ℝ)*(δ*(1+ε)/2)) + let Xp := fun n (p : (Fin (n+1) → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) => + Real.exp (canonicalCoordinateLog (n+1) k σ (b+δ) ((fun i _ => p.1 i),p.2)- + canonicalCoordinateLog (n+1) k σ b ((fun i _ => p.1 i),p.2)-((n+1:ℕ):ℝ)*(-δ*(1-ε)/2)) + have htm : Tendsto (fun n => coordinateCascadeLaw (n+1) k z r {p | 1/4 ≤ Xm n p}) atTop (𝓝 0) := + (canonical_ratio_converges σ b (b-δ) (δ*(1+ε)/2) k z hz hz0 hz1 hp hpm r hrm + (by norm_num : (0:ℝ)<1/4)).comp (tendsto_add_atTop_nat 1) + have htp : Tendsto (fun n => coordinateCascadeLaw (n+1) k z r {p | 1/4 ≤ Xp n p}) atTop (𝓝 0) := + (canonical_ratio_converges σ b (b+δ) (-δ*(1-ε)/2) k z hz hz0 hz1 hp hpp r hrp + (by norm_num : (0:ℝ)<1/4)).comp (tendsto_add_atTop_nat 1) + have he := htm.add htp + simp only [add_zero] at he + apply tendsto_of_tendsto_of_tendsto_of_le_of_le' tendsto_const_nhds he + (Eventually.of_forall (fun _ => bot_le)) + apply Eventually.of_forall + intro n + apply le_trans (measure_mono_ae (t := {p | 1/4 ≤ Xm n p} ∪ {p | 1/4 ≤ Xp n p}) ?_) + (measure_union_le _ _) + filter_upwards [canonicalCoordinateBase_pos (n+1) k σ z hz hz0 hz1 r, + canonicalCoordinateTotal_pos (n+1) k σ b z hz hz0 hz1 hp r, + canonicalCoordinateTotal_pos (n+1) k σ (b-δ) z hz hz0 hz1 hpm r, + canonicalCoordinateTotal_pos (n+1) k σ (b+δ) z hz hz0 hz1 hpp r] with p h0 hc hm hp' + intro hbad + by_cases hm' : 1/4 ≤ Xm n p + · exact Or.inl hm' + · right + by_contra hp'' + have hhalf := canonicalCoordinate_half_band n k σ hb hδ.le hbm ε _ h0 hc hm hp' + (not_le.mp hm').le (not_le.mp hp'').le + exact (not_le.mpr hbad) hhalf + +lemma canonicalCoordinate_shell_log_upper (n k : ℕ) (σ : ℕ → ℝ) {b ε : ℝ} + (hb : 0 < b) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + (hc : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p) + (hm : 0 < (canonicalRadialMass n b).real (normSquareBand n ε)) : + coordinateAngularLog n k σ (Real.sqrt (((n+1:ℕ):ℝ)*(1-ε))) p ≤ + canonicalCoordinateLog (n+1) k σ b p - + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε)) := by + let A := decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p (Real.sqrt (((n+1:ℕ):ℝ)*(1-ε))) + let T := decoratedTerminalTotalE (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k p + let M := canonicalRadialMass n b (normSquareBand n ε) + have hA : 0 < A.toReal := (coordinateAngularLog_regular n k σ _ hb p h0 hc).1 + change 0 < T.toReal at hc + change 0 < M.toReal at hm + have hle : A*M ≤ T := (decoratedCanonical_band_bounds n _ + (canonicalCoordinateStep_measurable (n+1) σ) _ (coordinateLeafField_measurable (n+1)) k p b ε).1.trans + (canonicalCoordinateBandTotalE_le n k σ hb ε p) + have hr := ENNReal.toReal_mono (ENNReal.toReal_pos_iff.mp hc).2.ne hle + rw [ENNReal.toReal_mul] at hr + change A.toReal*M.toReal ≤ T.toReal at hr + have hlog := Real.log_le_log (mul_pos hA hm) hr + rw [Real.log_mul hA.ne' hm.ne'] at hlog + change Real.log (A.toReal / _) ≤ Real.log (T.toReal / _) - Real.log M.toReal + rw [Real.log_div hA.ne' h0.ne',Real.log_div hc.ne' h0.ne'] + linarith + +lemma canonicalCoordinate_shell_log_lower (n k : ℕ) (σ : ℕ → ℝ) {b ε : ℝ} + (hb : 0 < b) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + (hc : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p) + (hm : 0 < (canonicalRadialMass n b).real (normSquareBand n ε)) + (hh : decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k p / 2 ≤ + (canonicalCoordinateBandTotalE n k σ b ε p).toReal) : + canonicalCoordinateLog (n+1) k σ b p - Real.log 2 - + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε)) ≤ + coordinateAngularLog n k σ (Real.sqrt (((n+1:ℕ):ℝ)*(1+ε))) p := by + let A := decoratedAngularFactor n (canonicalCoordinateStep (n+1) σ) + (coordinateLeafField (n+1)) k p (Real.sqrt (((n+1:ℕ):ℝ)*(1+ε))) + let T := decoratedTerminalTotalE (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k p + let M := canonicalRadialMass n b (normSquareBand n ε) + have hA : 0 < A.toReal := (coordinateAngularLog_regular n k σ _ hb p h0 hc).1 + change 0 < T.toReal at hc + change 0 < M.toReal at hm + have hle : canonicalCoordinateBandTotalE n k σ b ε p ≤ A*M := + (decoratedCanonical_band_bounds n _ (canonicalCoordinateStep_measurable (n+1) σ) _ + (coordinateLeafField_measurable (n+1)) k p b ε).2 + have hr := ENNReal.toReal_mono (ENNReal.mul_ne_top + (ENNReal.toReal_pos_iff.mp hA).2.ne (ENNReal.toReal_pos_iff.mp hm).2.ne) hle + rw [ENNReal.toReal_mul] at hr + change T.toReal/2 ≤ _ at hh + have hlog := Real.log_le_log (div_pos hc (by norm_num : (0:ℝ)<2)) (hh.trans hr) + rw [Real.log_mul hA.ne' hm.ne',Real.log_div hc.ne' (by norm_num : (2:ℝ)≠0)] at hlog + change Real.log (T.toReal / _) - Real.log 2 - Real.log M.toReal ≤ Real.log (A.toReal / _) + rw [Real.log_div hc.ne' h0.ne',Real.log_div hA.ne' h0.ne'] + linarith + +lemma convex_nonneg_radius_transfer {f : ℝ → ℝ} (hf : ConvexOn ℝ univ f) + (hn : ∀ r, 0 ≤ f r) {R r s ε : ℝ} (hR : 0 < R) + (hε : 0 ≤ ε) (hε1 : ε ≤ 1) (hr : (1-ε)*R ≤ r) (hrR : r ≤ R) + (hs : R ≤ s) (hsR : s ≤ (1+ε)*R) : + f R ≤ f r + ε*f (2*R) ∧ f s ≤ f R + ε*f (2*R) := by + have hr2 : 0 < 2*R-r := by linarith + let c := (R-r)/(2*R-r) + have hc0 : 0 ≤ c := div_nonneg (by linarith) hr2.le + have hcε : c ≤ ε := (div_le_iff₀ hr2).mpr (by nlinarith) + have hc1 : c ≤ 1 := hcε.trans hε1 + have hcEq : c*(2*R-r)=R-r := div_mul_cancel₀ _ hr2.ne' + have he : (1-c)*r+c*(2*R) = R := by nlinarith [hcEq] + have hl := hf.2 (mem_univ r) (mem_univ (2*R)) (sub_nonneg.mpr hc1) hc0 (by ring : 1-c+c=1) + simp only [smul_eq_mul,he] at hl + have hmix : (1-c)*f r+c*f (2*R) ≤ f r+ε*f (2*R) := by + nlinarith [mul_nonneg hc0 (hn r),mul_le_mul_of_nonneg_right hcε (hn (2*R))] + refine ⟨hl.trans hmix,?_⟩ + let d := (s-R)/R + have hd0 : 0 ≤ d := div_nonneg (sub_nonneg.mpr hs) hR.le + have hdε : d ≤ ε := (div_le_iff₀ hR).mpr (by nlinarith) + have hd1 : d ≤ 1 := hdε.trans hε1 + have hdEq : d*R=s-R := div_mul_cancel₀ _ hR.ne' + have he' : (1-d)*R+d*(2*R) = s := by nlinarith [hdEq] + have hu := hf.2 (mem_univ R) (mem_univ (2*R)) (sub_nonneg.mpr hd1) hd0 (by ring : 1-d+d=1) + simp only [smul_eq_mul,he'] at hu + apply hu.trans + nlinarith [mul_nonneg hd0 (hn R),mul_le_mul_of_nonneg_right hdε (hn (2*R))] + +lemma sqrt_radius_band {d ε : ℝ} (hd : 0 < d) (hε : 0 ≤ ε) (hε1 : ε ≤ 1) : + (1-ε)*Real.sqrt d ≤ Real.sqrt (d*(1-ε)) ∧ + Real.sqrt (d*(1-ε)) ≤ Real.sqrt d ∧ + Real.sqrt d ≤ Real.sqrt (d*(1+ε)) ∧ + Real.sqrt (d*(1+ε)) ≤ (1+ε)*Real.sqrt d := by + have hs := Real.sq_sqrt hd.le + have hre := Real.sq_sqrt (mul_nonneg hd.le (sub_nonneg.mpr hε1)) + have hse := Real.sq_sqrt (mul_nonneg hd.le (by linarith : 0≤1+ε)) + constructor + · apply (Real.le_sqrt (by positivity) (by positivity)).mpr + rw [mul_pow,hs] + nlinarith [mul_nonneg (mul_nonneg hd.le hε) (sub_nonneg.mpr hε1)] + constructor + · exact Real.sqrt_le_sqrt (by nlinarith) + constructor + · exact Real.sqrt_le_sqrt (by nlinarith) + · apply (Real.sqrt_le_left (by positivity)).mpr + rw [mul_pow,hs] + nlinarith [mul_nonneg hd.le (sq_nonneg ε)] + +lemma coordinateAngularLog_unit_radius_bounds (n k : ℕ) (σ : ℕ → ℝ) {b ε : ℝ} + (hb : 0 < b) (hε : 0 ≤ ε) (hε1 : ε ≤ 1) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + (hc : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p) : + coordinateAngularLog n k σ (Real.sqrt (n+1:ℕ)) p ≤ + coordinateAngularLog n k σ (Real.sqrt (((n+1:ℕ):ℝ)*(1-ε))) p + + ε*(canonicalCoordinateLog (n+1) k σ b p+((n+1:ℕ):ℝ)*(Real.log b/2+2*b)) ∧ + coordinateAngularLog n k σ (Real.sqrt (((n+1:ℕ):ℝ)*(1+ε))) p ≤ + coordinateAngularLog n k σ (Real.sqrt (n+1:ℕ)) p + + ε*(canonicalCoordinateLog (n+1) k σ b p+((n+1:ℕ):ℝ)*(Real.log b/2+2*b)) := by + have hd : 0 < ((n+1:ℕ):ℝ) := by positivity + have hr := sqrt_radius_band hd hε hε1 + have hconv := convex_nonneg_radius_transfer (coordinateAngularLog_convex n k σ hb p h0 hc) + (fun r => (coordinateAngularLog_regular n k σ r hb p h0 hc).2.1) + (Real.sqrt_pos.mpr hd) hε hε1 hr.1 hr.2.1 hr.2.2.1 hr.2.2.2 + have hbig := (coordinateAngularLog_regular n k σ (2*Real.sqrt (n+1:ℕ)) hb p h0 hc).2.2 + have he : ((n+1:ℕ):ℝ)*Real.log b/2+b*(2*Real.sqrt (n+1:ℕ))^2/2 = + ((n+1:ℕ):ℝ)*(Real.log b/2+2*b) := by + rw [mul_pow,Real.sq_sqrt hd.le] + ring + have hbige : coordinateAngularLog n k σ (2*Real.sqrt (n+1:ℕ)) p ≤ + canonicalCoordinateLog (n+1) k σ b p+((n+1:ℕ):ℝ)*(Real.log b/2+2*b) := by + linarith [he] + exact ⟨hconv.1.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_left hbige hε)), + hconv.2.trans (add_le_add le_rfl (mul_le_mul_of_nonneg_left hbige hε))⟩ + +lemma canonicalCoordinate_unitSphere_upper (n k : ℕ) (σ : ℕ → ℝ) {b ε : ℝ} + (hb : 0 < b) (hε : 0 ≤ ε) (hε1 : ε ≤ 1) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + (hc : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p) + (hm : 0 < (canonicalRadialMass n b).real (normSquareBand n ε)) : + coordinateAngularLog n k σ (Real.sqrt (n+1:ℕ)) p ≤ + (1+ε)*canonicalCoordinateLog (n+1) k σ b p- + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))+ + ε*((n+1:ℕ):ℝ)*(Real.log b/2+2*b) := by + have h₁ := canonicalCoordinate_shell_log_upper n k σ hb p h0 hc hm + have h₂ := (coordinateAngularLog_unit_radius_bounds n k σ hb hε hε1 p h0 hc).1 + linarith + +lemma canonicalCoordinate_unitSphere_lower (n k : ℕ) (σ : ℕ → ℝ) {b ε : ℝ} + (hb : 0 < b) (hε : 0 ≤ ε) (hε1 : ε ≤ 1) + (p : (Fin (n+1) → ℕ → ℝ) × DecoratedCascade (Fin (n+1) → ℝ) k) + (h0 : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (fun _ => 0) k p) + (hc : 0 < decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) (canonicalCoordinatePotential (n+1) b) k p) + (hm : 0 < (canonicalRadialMass n b).real (normSquareBand n ε)) + (hh : decoratedTerminalTotal (canonicalCoordinateStep (n+1) σ) + (canonicalCoordinatePotential (n+1) b) k p / 2 ≤ + (canonicalCoordinateBandTotalE n k σ b ε p).toReal) : + (1-ε)*canonicalCoordinateLog (n+1) k σ b p-Real.log 2- + Real.log ((canonicalRadialMass n b).real (normSquareBand n ε))- + ε*((n+1:ℕ):ℝ)*(Real.log b/2+2*b) ≤ + coordinateAngularLog n k σ (Real.sqrt (n+1:ℕ)) p := by + have h₁ := canonicalCoordinate_shell_log_lower n k σ hb p h0 hc hm hh + have h₂ := (coordinateAngularLog_unit_radius_bounds n k σ hb hε hε1 p h0 hc).2 + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/SingleRestorationLaw.lean b/lean/OAI/Probability/Perceptron/Variational/SingleRestorationLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..523c2bb9b3b02478ae764ceac394118cbec8b008 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/SingleRestorationLaw.lean @@ -0,0 +1,163 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.TerminalRestorationLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +section +variable {X R : Type} [MeasurableSpace X] [MeasurableSpace R] +lemma rootPathMean_one (μ : Measure R) [IsProbabilityMeasure μ] (x : R→X) + (n : ℕ) (κ : Fin n→Kernel X X) (hκ : ∀ i,IsMarkovKernel (κ i)) : + rootPathMean μ x n κ (fun _ => 1)=1 := by + have := pathOneKernel_markov n κ hκ + simp [rootPathMean,pathMean] +end +section +variable {X Y R Q S T : Type} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace R] [MeasurableSpace Q] [MeasurableSpace S] [MeasurableSpace T] + [Nonempty S] [Nonempty T] +lemma indexedTerminalMean_independent_roots + (μ : ProbabilityMeasure R) (σ : ProbabilityMeasure Q) (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + (∫ p,indexedTerminalMean st n (fun p => H p.1+G p.2) (x p.1.1,y p.1.2) + (fun p => f p.1*g p.2) (p.2.1,indexedMarksZip n p.2.2) + ∂((μ : Measure R).prod (σ : Measure Q)).prod + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n)))) = + rootPathMean μ x n (fun i => tiltedStateStep ν step₁ (z i) + (finiteCascadeShifts ν step₁ n z H i)) f * + rootPathMean σ y n (fun i => tiltedStateStep ρ step₂ (z i) + (finiteCascadeShifts ρ step₂ n z G i)) g := by + dsimp only + let st : (X×Y)×(S×T)→X×Y := fun p => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + have hs : Measurable st := by fun_prop + have hterm : Measurable (fun p : X×Y => H p.1+G p.2) := by fun_prop + have hobs : Measurable (fun p : X×Y => f p.1*g p.2) := by fun_prop + have hb (p : X×Y) : |f p.1*g p.2|≤C*D := by + rw [abs_mul]; exact mul_le_mul (hfB _) (hgB _) (abs_nonneg _) hC + have hzmap : MeasurePreserving (indexedMarksZip (S:=S) (T:=T) n) + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n)) (indexedCascadeMarksLaw (productMarkLaw ν ρ) n) := + ⟨indexedMarksZip_measurable n,indexedMarksZip_law ν ρ n⟩ + have hp := (MeasurePreserving.id ((μ : Measure R).prod (σ : Measure Q))).prod + ((MeasurePreserving.id (indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n))).prod hzmap) + let F : (R×Q)×(IndexedCascadeBase n×IndexedCascadeMarks (S×T) n)→ℝ := + fun p => indexedTerminalMean st n (fun p => H p.1+G p.2) (x p.1.1,y p.1.2) + (fun p => f p.1*g p.2) p.2 + let D₀ := (R×Q)×(IndexedCascadeBase n×IndexedCascadeMarks (S×T) n) + let tr : D₀→(X×Y)×(IndexedCascadeBase n×IndexedCascadeMarks (S×T) n) := + fun p => ((x p.1.1,y p.1.2),p.2) + have htr : Measurable tr := + (((hx.comp (measurable_fst.fst : Measurable (fun p : D₀ => p.1.1))).prodMk + (hy.comp measurable_fst.snd)).prodMk measurable_snd) + have hj := indexedTerminalMean_joint_measurable st hs n + (fun p => H p.1+G p.2) hterm (fun p => f p.1*g p.2) hobs + have hm' := hj.comp htr + have hm : Measurable F := hm' + have he := integral_map (μ:=((μ : Measure R).prod (σ : Measure Q)).prod + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n)))) hp.measurable.aemeasurable hm.aestronglyMeasurable + rw [hp.map_eq] at he + dsimp only [F,Prod.map_apply,id_eq] at he + have hv := indexedTerminalMean_root_integral + (productMarkLaw μ σ) (productMarkLaw ν ρ) st hs n z hz hz0 hz1 _ hterm + (finiteCascadeFractionalIntegrable_add_product ν ρ step₁ step₂ n z hz0 hHI hGI) + (fun p => (x p.1,y p.2)) (by fun_prop) _ hobs (C*D) hb + have hc := cascade_root_single_coefficients_product μ σ ν ρ step₁ step₂ hs₁ hs₂ n z hz0 + H G hH hG hHI hGI x y f g hf hg C D hC hD hfB hgB + exact he.symm.trans (hv.trans hc) + +lemma indexedTerminalMean_ignore_old + (μ : ProbabilityMeasure R) (σ : ProbabilityMeasure Q) (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i,0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2)) + (∫ p,indexedTerminalMean st n (fun p => H p.1+G p.2) (x p.1.1,y p.1.2) + (fun p => f p.1) (p.2.1,indexedMarksZip n p.2.2) + ∂((μ : Measure R).prod (σ : Measure Q)).prod + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n)).prod + (indexedCascadeMarksLaw ρ n)))) = + rootPathMean μ x n (fun i => tiltedStateStep ν step₁ (z i) + (finiteCascadeShifts ν step₁ n z H i)) f := by + have h := indexedTerminalMean_independent_roots μ σ ν ρ step₁ step₂ hs₁ hs₂ + n z hz hz0 hz1 H G hH hG hHI hGI x y hx hy f (fun _ => 1) + hf measurable_const C 1 hC (by norm_num) hfB (fun _ => by norm_num) + have hm i := cascadeTiltedStep_markov ρ step₂ hs₂ n z hz0 G hG hGI i + simpa only [rootPathMean_one σ y n _ hm,mul_one] using h +end +variable {X Y Z R Q U S T V : Type} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + [MeasurableSpace R] [MeasurableSpace Q] [MeasurableSpace U] + [MeasurableSpace S] [MeasurableSpace T] [MeasurableSpace V] + [Nonempty S] [Nonempty T] [Nonempty V] + +lemma indexedTerminalMean_two_fresh_old + (μ : ProbabilityMeasure R) (σ : ProbabilityMeasure Q) (τ : ProbabilityMeasure U) + (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) (π : ProbabilityMeasure V) + (st₁ : X×S→X) (st₂ : Y×T→Y) (st₀ : Z×V→Z) + (hs₁ : Measurable st₁) (hs₂ : Measurable st₂) (hs₀ : Measurable st₀) + (n : ℕ) (z : Fin n→ℝ) (hz : StrictMono z) (hz0 : ∀ i, 0 + ((st₁ (p.1.1.1,p.2.1.1),st₂ (p.1.1.2,p.2.1.2)),st₀ (p.1.2,p.2.2)) + (∫ p, indexedTerminalMean st n (fun p => (H p.1.1+G p.1.2)+J p.2) + ((x p.1.1.1,y p.1.1.2),v p.1.2) (fun p => f p.1.1*g p.1.2) + (p.2.1,indexedMarksZip n p.2.2) + ∂(((μ : Measure R).prod (σ : Measure Q)).prod (τ : Measure U)).prod + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + ((indexedCascadeMarksLaw (productMarkLaw ν ρ) n : Measure (IndexedCascadeMarks (S×T) n)).prod + (indexedCascadeMarksLaw π n)))) = + (rootPathMean μ x n (fun i => tiltedStateStep ν st₁ (z i) + (finiteCascadeShifts ν st₁ n z H i)) f * + rootPathMean σ y n (fun i => tiltedStateStep ρ st₂ (z i) + (finiteCascadeShifts ρ st₂ n z G i)) g) := by + let st : (X×Y)×(S×T)→X×Y := fun p => (st₁ (p.1.1,p.2.1),st₂ (p.1.2,p.2.2)) + have hs : Measurable st := by fun_prop + have hfg : Measurable (fun p : X×Y => f p.1*g p.2) := by fun_prop + have hb (p : X×Y) : |f p.1*g p.2|≤C*D := by + rw [abs_mul]; exact mul_le_mul (hfB _) (hgB _) (abs_nonneg _) hC + have h := indexedTerminalMean_ignore_old (productMarkLaw μ σ) τ (productMarkLaw ν ρ) π + st st₀ hs hs₀ n z hz hz0 hz1 (fun p => H p.1+G p.2) J (by fun_prop) hJ + (finiteCascadeFractionalIntegrable_add_product ν ρ st₁ st₂ n z hz0 hHI hGI) hJI + (fun p => (x p.1,y p.2)) v (by fun_prop) hv (fun p => f p.1*g p.2) hfg + (C*D) (mul_nonneg hC hD) hb + dsimp only [st] at h ⊢ + change _ = rootPathMean ((μ : Measure R).prod (σ : Measure Q)) (fun p => (x p.1,y p.2)) n + (fun i => tiltedStateStep (productMarkLaw ν ρ) + (fun p => (st₁ (p.1.1,p.2.1),st₂ (p.1.2,p.2.2))) (z i) + (finiteCascadeShifts (productMarkLaw ν ρ) + (fun p => (st₁ (p.1.1,p.2.1),st₂ (p.1.2,p.2.2))) n z (fun p => H p.1+G p.2) i)) + (fun p => f p.1*g p.2) at h + rw [cascade_root_single_coefficients_product μ σ ν ρ st₁ st₂ hs₁ hs₂ n z hz0 + H G hH hG hHI hGI x y f g hf hg C D hC hD hfB hgB] at h + exact h + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/StableLaplaceConstant.lean b/lean/OAI/Probability/Perceptron/Variational/StableLaplaceConstant.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ba750d9558a19fb838fc66afa37dc7fc9c3124f --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/StableLaplaceConstant.lean @@ -0,0 +1,432 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StableLogIntensity + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma finitePointMeasure_insertNth {S : Type*} [MeasurableSpace S] + (n : ℕ) (i : Fin (n+1)) (x : S) (y : Fin n → S) : + finitePointMeasure (n+1) (i.insertNth x y) = Measure.dirac x + finitePointMeasure n y := by + classical + rw [finitePointMeasure,Fin.sum_univ_succAbove _ i] + simp [finitePointMeasure] + +lemma finite_point_mecke {S : Type*} [MeasurableSpace S] + (ν : Measure S) [IsProbabilityMeasure ν] (n : ℕ) + {H : Measure S × S → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ y : Fin (n+1) → S, ∑ i, H (finitePointMeasure (n+1) y,y i) + ∂Measure.pi (fun _ => ν)) = (n+1 : ℝ≥0∞) * + ∫⁻ x, ∫⁻ y : Fin n → S, H (Measure.dirac x + finitePointMeasure n y,x) + ∂Measure.pi (fun _ => ν) ∂ν := by + classical + rw [lintegral_finsetSum (f := fun (i : Fin (n+1)) (y : Fin (n+1) → S) => H (finitePointMeasure (n+1) y,y i)) _ (fun i _ => hH.comp + ((finitePointMeasure_measurable _).prodMk (measurable_pi_apply i)))] + have he (i : Fin (n+1)) : + (∫⁻ y : Fin (n+1) → S, H (finitePointMeasure (n+1) y,y i) + ∂Measure.pi (fun _ => ν)) = + ∫⁻ x, ∫⁻ y : Fin n → S, H (Measure.dirac x + finitePointMeasure n y,x) + ∂Measure.pi (fun _ => ν) ∂ν := by + have hm : Measurable (fun y : Fin (n+1) → S => H (finitePointMeasure (n+1) y,y i)) := + hH.comp ((finitePointMeasure_measurable _).prodMk (measurable_pi_apply i)) + rw [← ((measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => ν) i).symm).lintegral_comp hm] + change (∫⁻ p : S × (Fin n → S), H (finitePointMeasure (n+1) (i.insertNth p.1 p.2), + ((i.insertNth p.1 p.2 : Fin (n+1) → S) i)) ∂ν.prod (Measure.pi fun _ => ν)) = _ + simp only [finitePointMeasure_insertNth,Fin.insertNth_apply_same] + exact lintegral_prod _ (hH.comp + (((by fun_prop : Measurable (fun p : S × (Fin n → S) => + Measure.dirac p.1 + finitePointMeasure n p.2))).prodMk measurable_fst)).aemeasurable + simp_rw [he] + simp + +lemma poissonMeasure_succ_mul (r : ℝ≥0) (n : ℕ) : + poissonMeasure r {n+1} * (n+1 : ℝ≥0∞) = (r : ℝ≥0∞) * poissonMeasure r {n} := by + rw [poissonMeasure_singleton,poissonMeasure_singleton] + have he : Real.exp (-(r : ℝ)) * (r : ℝ)^(n+1) / (n+1).factorial * (n+1) = + (r : ℝ) * (Real.exp (-(r : ℝ)) * (r : ℝ)^n / n.factorial) := by + rw [Nat.factorial_succ,Nat.cast_mul,Nat.cast_add,Nat.cast_one,pow_succ] + field_simp + have hh := congrArg ENNReal.ofReal he + simpa only [ENNReal.ofReal_mul (by positivity : 0 ≤ Real.exp (-(r : ℝ)) * + (r : ℝ)^(n+1) / (n+1).factorial), ENNReal.ofReal_mul r.coe_nonneg, + ENNReal.ofReal_coe_nnreal,ENNReal.ofReal_add (Nat.cast_nonneg n) zero_le_one, + ENNReal.ofReal_natCast,ENNReal.ofReal_one] using hh + +lemma finitePoissonLaw_mecke {S : Type*} [MeasurableSpace S] + (r : ℝ≥0) (ν : Measure S) [IsProbabilityMeasure ν] + {H : Measure S × S → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ η, ∫⁻ x, H (η,x) ∂η ∂finitePoissonLaw r ν) = + (r : ℝ≥0∞) * ∫⁻ x, ∫⁻ η, H (Measure.dirac x + η,x) ∂finitePoissonLaw r ν ∂ν := by + rw [finitePoissonLaw,lintegral_sum_measure] + simp_rw [lintegral_smul_measure] + have hmap (n : ℕ) : + (∫⁻ η, ∫⁻ x, H (η,x) ∂η ∂(Measure.pi fun _ : Fin n => ν).map (finitePointMeasure n)) = + ∫⁻ y : Fin n → S, ∫⁻ x, H (finitePointMeasure n y,x) ∂finitePointMeasure n y + ∂Measure.pi (fun _ => ν) := by + apply lintegral_map' + · exact aemeasurable_measure_lintegral_of_finite + ((ae_map_iff (finitePointMeasure_measurable n).aemeasurable + (measurableSet_lt (Measure.measurable_coe .univ) measurable_const)).mpr + (ae_of_all _ fun y => by simp [finitePointMeasure,Measure.finsetSum_apply])) hH + · exact (finitePointMeasure_measurable n).aemeasurable + simp_rw [hmap] + have hinner (n : ℕ) (y : Fin n → S) : + (∫⁻ x, H (finitePointMeasure n y,x) ∂finitePointMeasure n y) = + ∑ i, H (finitePointMeasure n y,y i) := + finitePointMeasure_lintegral (hH.comp (measurable_const.prodMk measurable_id)) _ _ + simp only [hinner,smul_eq_mul] + rw [tsum_eq_zero_add' ENNReal.summable] + simp only [Fin.sum_univ_zero,lintegral_zero,mul_zero,zero_add] + simp_rw [finite_point_mecke ν _ hH,← mul_assoc,poissonMeasure_succ_mul,mul_assoc] + rw [ENNReal.tsum_mul_left] + congr 1 + have hmn (n : ℕ) : Measurable (fun x : S => ∫⁻ y : Fin n → S, + H (Measure.dirac x + finitePointMeasure n y,x) ∂Measure.pi (fun _ => ν)) := by + have hm : Measurable (fun p : S × (Fin n → S) => Measure.dirac p.1 + finitePointMeasure n p.2) := by + fun_prop + exact (hH.comp (hm.prodMk measurable_fst)).lintegral_prod_right' + symm + calc + _ = ∫⁻ x, ∑' n : ℕ, poissonMeasure r {n} * ∫⁻ y : Fin n → S, + H (Measure.dirac x + finitePointMeasure n y,x) ∂Measure.pi (fun _ => ν) ∂ν := by + apply lintegral_congr + intro x + rw [lintegral_sum_measure] + simp only [lintegral_smul_measure,smul_eq_mul] + apply tsum_congr + intro n + congr 1 + exact lintegral_map + (hH.comp ((measurable_const.add measurable_id).prodMk measurable_const)) + (finitePointMeasure_measurable n) + _ = _ := by + rw [lintegral_tsum (f := fun (n : ℕ) (x : S) => poissonMeasure r {n} * + ∫⁻ y : Fin n → S, H (Measure.dirac x + finitePointMeasure n y,x) ∂Measure.pi (fun _ => ν)) + (fun n => (measurable_const.mul (hmn n)).aemeasurable)] + apply tsum_congr + intro n + exact lintegral_const_mul' _ _ (measure_ne_top _ _) + +def stableLaplaceConstant (b : ℝ) : ℝ≥0∞ := + ∫⁻ x, ENNReal.ofReal (1-Real.exp (-Real.exp x)) ∂stableLogIntensity b + +lemma one_sub_exp_neg_le_min {u : ℝ} (hu : 0 ≤ u) : + 0 ≤ 1-Real.exp (-u) ∧ 1-Real.exp (-u) ≤ min u 1 := by + constructor + · exact sub_nonneg.mpr (Real.exp_le_one_iff.mpr (neg_nonpos.mpr hu)) + · exact le_min (by linarith [Real.add_one_le_exp (-u)]) (by linarith [Real.exp_pos (-u)]) + +lemma stableLaplaceConstant_finite {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) : + stableLaplaceConstant b ≠ ⊤ := by + apply ne_top_of_le_ne_top (stableLogIntensity_min_exp_finite hb0 hb1) + apply lintegral_mono + intro x + exact ENNReal.ofReal_le_ofReal (one_sub_exp_neg_le_min (Real.exp_pos x).le).2 + +lemma stableLaplaceConstant_positive {b : ℝ} (hb : 0 < b) : + 0 < stableLaplaceConstant b := by + unfold stableLaplaceConstant + rw [lintegral_pos_iff_support (by fun_prop)] + have he : Function.support (fun x : ℝ => ENNReal.ofReal (1-Real.exp (-Real.exp x))) = univ := by + ext x + simp only [Function.mem_support,mem_univ,iff_true] + exact ne_of_gt (ENNReal.ofReal_pos.mpr (by + have hh := Real.exp_lt_one_iff.mpr (neg_neg_of_pos (Real.exp_pos x)) + linarith)) + rw [he,stableLogIntensity_univ hb] + simp + +lemma stableLaplaceExponent_scaling {b t : ℝ} (hb : 0 ≤ b) (ht : 0 < t) : + (∫⁻ x, ENNReal.ofReal (1-Real.exp (-(t*Real.exp x))) ∂stableLogIntensity b) = + ENNReal.ofReal (t^b) * stableLaplaceConstant b := by + have he := stableLogIntensity_lintegral_translate hb (Real.log t) + (f := fun x => ENNReal.ofReal (1-Real.exp (-Real.exp x))) (by fun_prop) + have hx (x : ℝ) : Real.exp (x+Real.log t) = t*Real.exp x := by + rw [Real.exp_add,Real.exp_log ht] + exact mul_comm _ _ + simp_rw [hx] at he + convert he using 1 + rw [Real.rpow_def_of_pos ht,mul_comm b (Real.log t)] + rfl + +def stablePoissonTotal (η : Measure ℝ) : ℝ := + (∫⁻ x, ENNReal.ofReal (Real.exp x) ∂η).toReal + +lemma stablePoissonTotal_measurable : Measurable stablePoissonTotal := + ENNReal.measurable_toReal.comp (Measure.measurable_lintegral (by fun_prop)) + +lemma stablePoissonTotal_pos {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) : + ∀ᵐ η ∂poissonRandomMeasureLaw (stableLogIntensity b), 0 < stablePoissonTotal η := by + filter_upwards [stablePoisson_total_positive hb0,stablePoisson_total_finite hb0 hb1] with η hp hf + exact ENNReal.toReal_pos hp.ne' hf + +lemma stablePoissonTotal_laplace {b t : ℝ} (hb0 : 0 < b) (hb1 : b < 1) (ht : 0 < t) : + (∫ η, Real.exp (-t*stablePoissonTotal η) ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + Real.exp (-(stableLaplaceConstant b).toReal * t^b) := by + have he := poissonRandomMeasureLaw_laplace (stableLogIntensity b) + (f := fun x => t*Real.exp x) (by fun_prop) (fun x => mul_nonneg ht.le (Real.exp_pos x).le) + rw [stableLaplaceExponent_scaling hb0.le ht, + expNegENNReal_finite (ENNReal.mul_ne_top ENNReal.ofReal_ne_top (stableLaplaceConstant_finite hb0 hb1)), + ENNReal.toReal_mul,ENNReal.toReal_ofReal (Real.rpow_pos_of_pos ht b).le] at he + convert he using 1 + · apply integral_congr_ae + filter_upwards [stablePoisson_total_finite hb0 hb1] with η hη + simp only [poissonLaplace,ENNReal.ofReal_mul ht.le] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + expNegENNReal_finite (ENNReal.mul_ne_top ENNReal.ofReal_ne_top hη), + ENNReal.toReal_mul,ENNReal.toReal_ofReal ht.le] + congr 1 + dsimp [stablePoissonTotal] + ring + · congr 1 + ring + +lemma standardGaussian_integrationByParts {F F' : ℝ → ℝ} + (hF : ∀ x, HasDerivAt F (F' x) x) (hm : Measurable F') + {C D : ℝ} (hb : ∀ x, |F x| ≤ C) (hb' : ∀ x, |F' x| ≤ D) : + ∫ x, x * F x ∂gaussianReal 0 1 = ∫ x, F' x ∂gaussianReal 0 1 := by + have hfm : Measurable F := (continuous_iff_continuousAt.mpr + (fun x => (hF x).continuousAt)).measurable + have h1 : Integrable (fun x => gaussianPDFReal 0 1 x * F' x) := + (integrable_gaussianPDFReal 0 1).mul_bdd hm.aestronglyMeasurable + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hb' x) + have h2 : Integrable (fun x => (-x * gaussianPDFReal 0 1 x) * F x) := by + have hh := standardGaussian_density_mul_integrable.neg.mul_bdd hfm.aestronglyMeasurable + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hb x) + simpa only [neg_mul,Pi.neg_apply] using hh + have h3 : Integrable (fun x => gaussianPDFReal 0 1 x * F x) := + (integrable_gaussianPDFReal 0 1).mul_bdd hfm.aestronglyMeasurable + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hb x) + have he := integral_mul_deriv_eq_deriv_mul_of_integrable + (fun x _ => standardGaussian_density_deriv x) (fun x _ => hF x) h1 h2 h3 + simp only [integral_gaussianReal_eq_integral_smul (by norm_num : (1 : ℝ≥0) ≠ 0), + smul_eq_mul] + rw [he] + simp only [neg_mul,integral_neg,neg_neg] + apply integral_congr_ae + exact ae_of_all _ fun x => by ring + +section Tilt +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +def tiltIntegral (v F : S → ℝ) (t : ℝ) : ℝ := ∫ x, Real.exp (t * v x) * F x ∂μ + +def tiltPartition (v : S → ℝ) (t : ℝ) : ℝ := ∫ x, Real.exp (t * v x) ∂μ + +def tiltMean (v F : S → ℝ) (t : ℝ) : ℝ := tiltIntegral μ v F t / tiltPartition μ v t + +lemma tilt_integrable {v F : S → ℝ} (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (_hC : 0 ≤ C) (_hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) (t : ℝ) : + Integrable (fun x => Real.exp (t * v x) * F x) μ := by + refine Integrable.of_bound (hv.const_mul t |>.exp.mul hF).aestronglyMeasurable + (Real.exp (|t| * C) * D) (ae_of_all _ fun x => ?_) + rw [Real.norm_eq_abs,abs_mul,abs_of_pos (Real.exp_pos _)] + apply mul_le_mul _ (hFD x) (abs_nonneg _) (Real.exp_pos _).le + apply Real.exp_le_exp.mpr + exact (le_abs_self (t * v x)).trans (by rw [abs_mul]; gcongr; exact hvC x) + +lemma tilt_integral_deriv {v F : S → ℝ} (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) (t : ℝ) : + HasDerivAt (tiltIntegral μ v F) + (∫ x, Real.exp (t * v x) * v x * F x ∂μ) t := by + apply (hasDerivAt_integral_of_dominated_loc_of_deriv_le + (s := Metric.ball t 1) (bound := fun _ => Real.exp ((|t|+1)*C) * C * D) + (F' := fun u x => Real.exp (u * v x) * v x * F x) (Metric.ball_mem_nhds t zero_lt_one) + (Filter.Eventually.of_forall fun u => (hv.const_mul u |>.exp.mul hF).aestronglyMeasurable) + (tilt_integrable μ hv hF hC hD hvC hFD t) + (by fun_prop) (ae_of_all _ fun x u hu => ?_) (integrable_const _) + (ae_of_all _ fun x u _ => ?_)).2 + · have hu' : |u| ≤ |t|+1 := by + have hh : |u-t| < 1 := by simpa only [Metric.mem_ball,Real.dist_eq] using hu + calc + |u| = |(u-t)+t| := by congr 1; ring + _ ≤ |u-t|+|t| := abs_add_le _ _ + _ ≤ |t|+1 := by linarith + rw [Real.norm_eq_abs,abs_mul,abs_mul,abs_of_pos (Real.exp_pos _)] + have hexp : Real.exp (u * v x) ≤ Real.exp ((|t|+1)*C) := by + apply Real.exp_le_exp.mpr + apply (le_abs_self (u * v x)).trans + rw [abs_mul] + exact mul_le_mul hu' (hvC x) (abs_nonneg _) (by positivity) + exact mul_le_mul (mul_le_mul hexp (hvC x) (abs_nonneg _) (Real.exp_pos _).le) + (hFD x) (abs_nonneg _) (mul_nonneg (Real.exp_pos _).le hC) + · convert! (((hasDerivAt_id u).mul_const (v x)).exp.mul_const (F x)) using 1 + simp only [one_mul,id_eq] + +lemma tilt_partition_pos {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (t : ℝ) : + 0 < tiltPartition μ v t := by + have hi : Integrable (fun x => Real.exp (t * v x)) μ := by + simpa only [mul_one] using tilt_integrable μ (F := fun _ => 1) hv measurable_const hC (by norm_num : (0:ℝ) ≤ 1) + hvC (fun _ => by norm_num) t + have he : Real.exp (- |t| * C) ≤ tiltPartition μ v t := by + calc + Real.exp (- |t| * C) = ∫ _ : S, Real.exp (- |t| * C) ∂μ := by simp + _ ≤ tiltPartition μ v t := integral_mono_ae (integrable_const _) hi (ae_of_all _ fun x => by + apply Real.exp_le_exp.mpr + have hh : |t*v x| ≤ |t| * C := by rw [abs_mul]; gcongr; exact hvC x + nlinarith [neg_abs_le (t*v x)]) + exact (Real.exp_pos _).trans_le he + +lemma tilt_partition_deriv {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (t : ℝ) : + HasDerivAt (tiltPartition μ v) (tiltIntegral μ v v t) t := by + have hd := tilt_integral_deriv μ (F := fun _ => 1) hv measurable_const hC + (by norm_num : (0:ℝ) ≤ 1) hvC (fun _ => by norm_num) t + change HasDerivAt (fun u => ∫ x, Real.exp (u * v x) * 1 ∂μ) + (∫ x, Real.exp (t*v x) * v x * 1 ∂μ) t at hd + change HasDerivAt (fun u => ∫ x, Real.exp (u * v x) ∂μ) + (∫ x, Real.exp (t * v x) * v x ∂μ) t + simpa only [mul_one] using hd + +lemma tilt_mean_deriv {v F : S → ℝ} (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) (t : ℝ) : + HasDerivAt (tiltMean μ v F) + (tiltMean μ v (fun x => v x * F x) t - tiltMean μ v F t * tiltMean μ v v t) t := by + have hp := (tilt_partition_pos μ hv hC hvC t).ne' + have hd := (tilt_integral_deriv μ hv hF hC hD hvC hFD t).div + (tilt_partition_deriv μ hv hC hvC t) hp + convert! hd using 1 + simp only [tiltMean,tiltIntegral,mul_assoc] + field_simp + +lemma tilt_mean_bound {v F : S → ℝ} (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) (t : ℝ) : + |tiltMean μ v F t| ≤ D := by + have hp := tilt_partition_pos μ hv hC hvC t + have hi := tilt_integrable μ hv hF hC hD hvC hFD t + have hiExp : Integrable (fun x => Real.exp (t * v x)) μ := by + simpa only [mul_one] using tilt_integrable μ (F := fun _ => 1) hv measurable_const hC + (by norm_num : (0:ℝ) ≤ 1) hvC (fun _ => by norm_num) t + rw [tiltMean,abs_div,abs_of_pos hp,div_le_iff₀ hp] + calc + |tiltIntegral μ v F t| ≤ ∫ x, |Real.exp (t * v x) * F x| ∂μ := by + simpa only [tiltIntegral,Real.norm_eq_abs] using norm_integral_le_integral_norm + (fun x => Real.exp (t * v x) * F x) + _ ≤ ∫ x, Real.exp (t * v x) * D ∂μ := by + apply integral_mono_ae hi.norm (hiExp.mul_const D) + exact ae_of_all _ fun x => by + simp only [Real.norm_eq_abs] + rw [abs_mul,abs_of_pos (Real.exp_pos _)] + exact mul_le_mul_of_nonneg_left (hFD x) (Real.exp_pos _).le + _ = D * tiltPartition μ v t := by rw [integral_mul_const]; exact mul_comm _ _ + +def tiltLaw (v : S → ℝ) (t : ℝ) : Measure S := + (ENNReal.ofReal (tiltPartition μ v t))⁻¹ • + μ.withDensity (fun x => ENNReal.ofReal (Real.exp (t * v x))) + +lemma tilt_law_probability {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (t : ℝ) : + IsProbabilityMeasure (tiltLaw μ v t) := by + have hp := tilt_partition_pos μ hv hC hvC t + have hi : Integrable (fun x => Real.exp (t * v x)) μ := by + simpa only [mul_one] using tilt_integrable μ (F := fun _ => 1) hv measurable_const hC + (by norm_num : (0:ℝ) ≤ 1) hvC (fun _ => by norm_num) t + constructor + rw [tiltLaw,Measure.smul_apply,smul_eq_mul,withDensity_apply _ .univ, + Measure.restrict_univ,← ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ fun x => (Real.exp_pos _).le)] + exact ENNReal.inv_mul_cancel (ne_of_gt (ENNReal.ofReal_pos.mpr hp)) ENNReal.ofReal_ne_top + +lemma tilt_law_integral {v F : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (t : ℝ) : + ∫ x, F x ∂tiltLaw μ v t = tiltMean μ v F t := by + rw [tiltLaw,integral_smul_measure,integral_withDensity_eq_integral_toReal_smul + (show Measurable (fun x => ENNReal.ofReal (Real.exp (t * v x))) from (hv.const_mul t).exp.ennreal_ofReal) + (ae_of_all _ fun _ => ENNReal.ofReal_lt_top)] + simp only [ENNReal.toReal_inv,ENNReal.toReal_ofReal (tilt_partition_pos μ hv hC hvC t).le, + ENNReal.toReal_ofReal (Real.exp_pos _).le,smul_eq_mul,tiltMean,tiltIntegral] + exact (div_eq_inv_mul _ _).symm + +lemma tilt_mean_continuous {v F : S → ℝ} (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) : + Continuous (tiltMean μ v F) := + continuous_iff_continuousAt.mpr fun t => (tilt_mean_deriv μ hv hF hC hD hvC hFD t).continuousAt + +lemma gaussian_tilt_integrationByParts {v F : S → ℝ} (hv : Measurable v) (hF : Measurable F) + {C D : ℝ} (hC : 0 ≤ C) (hD : 0 ≤ D) + (hvC : ∀ x, |v x| ≤ C) (hFD : ∀ x, |F x| ≤ D) : + (∫ t, t * tiltMean μ v F t ∂gaussianReal 0 1) = + ∫ t, tiltMean μ v (fun x => v x * F x) t - + tiltMean μ v F t * tiltMean μ v v t ∂gaussianReal 0 1 := by + have hvF : ∀ x, |v x * F x| ≤ C * D := fun x => by + rw [abs_mul]; exact mul_le_mul (hvC x) (hFD x) (abs_nonneg _) hC + apply standardGaussian_integrationByParts + (fun t => tilt_mean_deriv μ hv hF hC hD hvC hFD t) + ((tilt_mean_continuous μ hv (hv.mul hF) hC (mul_nonneg hC hD) hvC hvF).measurable.sub + ((tilt_mean_continuous μ hv hF hC hD hvC hFD).measurable.mul + (tilt_mean_continuous μ hv hv hC hC hvC hvC).measurable)) + (fun t => tilt_mean_bound μ hv hF hC hD hvC hFD t) + (D := 2*C*D) + intro t + calc + |tiltMean μ v (fun x => v x * F x) t - tiltMean μ v F t * tiltMean μ v v t| ≤ + |tiltMean μ v (fun x => v x * F x) t| + |tiltMean μ v F t * tiltMean μ v v t| := abs_sub _ _ + _ ≤ C*D + D*C := add_le_add (tilt_mean_bound μ hv (hv.mul hF) hC (mul_nonneg hC hD) hvC hvF t) + (by + rw [abs_mul] + exact mul_le_mul (tilt_mean_bound μ hv hF hC hD hvC hFD t) + (tilt_mean_bound μ hv hv hC hC hvC hvC t) (abs_nonneg _) hD) + _ = 2*C*D := by ring + +end Tilt + +def replicaPotential {S : Type*} (v : S → ℝ) (n : ℕ) (x : Fin n → S) : ℝ := ∑ i, v (x i) + +lemma replicaPotential_measurable {S : Type*} [MeasurableSpace S] + {v : S → ℝ} (hv : Measurable v) (n : ℕ) : Measurable (replicaPotential v n) := by + exact Finset.measurable_sum _ fun i _ => hv.comp (measurable_pi_apply i) + +lemma replicaPotential_bound {S : Type*} {v : S → ℝ} {C : ℝ} + (hv : ∀ x, |v x| ≤ C) (n : ℕ) (x : Fin n → S) : + |replicaPotential v n x| ≤ n*C := by + calc + |∑ i, v (x i)| ≤ ∑ i, |v (x i)| := Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _ : Fin n, C := Finset.sum_le_sum (fun i _ => hv (x i)) + _ = n*C := by simp + +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma replica_partition {v : S → ℝ} (_hv : Measurable v) (n : ℕ) (t : ℝ) : + tiltPartition (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) t = + (tiltPartition μ v t)^n := by + unfold tiltPartition replicaPotential + simp_rw [Finset.mul_sum,Real.exp_sum] + rw [integral_fintype_prod_eq_prod (f := fun (_ : Fin n) x => Real.exp (t * v x))] + simp + +lemma replica_mean_potential {v : S → ℝ} (hv : Measurable v) + {C : ℝ} (hC : 0 ≤ C) (hvC : ∀ x, |v x| ≤ C) (n : ℕ) (t : ℝ) : + tiltMean (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) (replicaPotential v n) t = + n * tiltMean μ v v t := by + have hd := tilt_partition_deriv (Measure.pi fun _ : Fin n => μ) + (replicaPotential_measurable hv n) (mul_nonneg (Nat.cast_nonneg n) hC) + (replicaPotential_bound hvC n) t + have he : tiltPartition (Measure.pi fun _ : Fin n => μ) (replicaPotential v n) = + fun u => (tiltPartition μ v u)^n := funext (replica_partition μ hv n) + rw [he] at hd + have hg := (tilt_partition_deriv μ hv hC hvC t).pow n + have hder := hd.unique hg + unfold tiltMean + rw [hder,replica_partition μ hv n] + have hp := (tilt_partition_pos μ hv hC hvC t).ne' + cases n with + | zero => simp + | succ n => + simp only [Nat.succ_sub_one,Nat.cast_add,Nat.cast_one,pow_succ] + field_simp + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/StableLogIntensity.lean b/lean/OAI/Probability/Perceptron/Variational/StableLogIntensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..a439d5c46d9151fef72631de8f486297b8ebec16 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/StableLogIntensity.lean @@ -0,0 +1,422 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.PoissonLaplace + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma poissonLaplace_map {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + {g : S → T} (hg : Measurable g) {f : T → ℝ} (hf : Measurable f) (η : Measure S) : + poissonLaplace f (η.map g) = poissonLaplace (f ∘ g) η := by + rw [poissonLaplace,lintegral_map hf.ennreal_ofReal hg] + rfl + +lemma poissonRandomMeasureLaw_map {S T : Type*} [MeasurableSpace S] [MeasurableSpace T] + [Nonempty S] [Nonempty T] (κ : Measure S) [SFinite κ] + {g : S → T} (hg : Measurable g) : + (poissonRandomMeasureLaw κ).map (Measure.map g) = poissonRandomMeasureLaw (κ.map g) := by + apply measureLaw_eq_of_laplace + intro f hf hf0 + rw [integral_map (Measure.measurable_map g hg).aemeasurable + (poissonLaplace_measurable hf).aestronglyMeasurable] + simp_rw [poissonLaplace_map hg hf] + rw [poissonRandomMeasureLaw_laplace _ (hf.comp hg) (fun x => hf0 (g x)), + poissonRandomMeasureLaw_laplace _ hf hf0, + lintegral_map (show Measurable (fun x : T => ENNReal.ofReal (1 - Real.exp (-f x))) from + (measurable_const.sub hf.neg.exp).ennreal_ofReal) hg] + rfl + +def stableLogIntensity (b : ℝ) : Measure ℝ := + volume.withDensity (fun x => ENNReal.ofReal (b * Real.exp (-b*x))) + +instance stableLogIntensity_sigmaFinite (b : ℝ) : SigmaFinite (stableLogIntensity b) := by + unfold stableLogIntensity + infer_instance + +lemma stableLogDensity_translate {b : ℝ} (_hb : 0 ≤ b) (c x : ℝ) : + ENNReal.ofReal (b * Real.exp (-b*x)) = + ENNReal.ofReal (Real.exp (b*c)) * ENNReal.ofReal (b * Real.exp (-b*(x+c))) := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le] + congr 1 + rw [mul_left_comm,← Real.exp_add] + congr 2 + ring + +lemma stableLogIntensity_lintegral_translate {b : ℝ} (hb : 0 ≤ b) + (c : ℝ) {f : ℝ → ℝ≥0∞} (hf : Measurable f) : + ∫⁻ x, f (x+c) ∂stableLogIntensity b = + ENNReal.ofReal (Real.exp (b*c)) * ∫⁻ x, f x ∂stableLogIntensity b := by + unfold stableLogIntensity + rw [lintegral_withDensity_eq_lintegral_mul volume (by fun_prop) (show Measurable (fun x : ℝ => f (x+c)) from hf.comp (measurable_id.add_const c)), + lintegral_withDensity_eq_lintegral_mul volume (by fun_prop) hf] + change (∫⁻ x, ENNReal.ofReal (b * Real.exp (-b*x)) * f (x+c)) = _ + calc + (∫⁻ x, ENNReal.ofReal (b * Real.exp (-b*x)) * f (x+c)) = + ∫⁻ x, ENNReal.ofReal (Real.exp (b*c)) * + (ENNReal.ofReal (b * Real.exp (-b*(x+c))) * f (x+c)) := by + apply lintegral_congr + intro x + rw [stableLogDensity_translate hb c x,mul_assoc] + _ = ENNReal.ofReal (Real.exp (b*c)) * + ∫⁻ x, ENNReal.ofReal (b * Real.exp (-b*(x+c))) * f (x+c) := + lintegral_const_mul' _ _ ENNReal.ofReal_ne_top + _ = _ := by + congr 1 + exact lintegral_add_right_eq_self + (fun x => ENNReal.ofReal (b * Real.exp (-b*x)) * f x) c + +lemma stableLogIntensity_translate {b : ℝ} (hb : 0 ≤ b) (c : ℝ) : + (stableLogIntensity b).map (fun x => x+c) = + ENNReal.ofReal (Real.exp (b*c)) • stableLogIntensity b := by + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (show Measurable (fun x : ℝ => x+c) from measurable_id.add_const c),lintegral_smul_measure] + exact stableLogIntensity_lintegral_translate hb c hf + +def logMarkShift {S : Type*} (F : S → ℝ) (p : ℝ × S) : ℝ × S := + (p.1 + F p.2,p.2) + +lemma logMarkShift_measurable {S : Type*} [MeasurableSpace S] + {F : S → ℝ} (hF : Measurable F) : Measurable (logMarkShift F) := + (measurable_fst.add (hF.comp measurable_snd)).prodMk measurable_snd + +lemma stableLogIntensity_mark_shift {S : Type*} [MeasurableSpace S] + (ν : Measure S) [SFinite ν] {b : ℝ} (hb : 0 ≤ b) + {F : S → ℝ} (hF : Measurable F) : + ((stableLogIntensity b).prod ν).map (logMarkShift F) = + (stableLogIntensity b).prod (ν.withDensity (fun s => ENNReal.ofReal (Real.exp (b * F s)))) := by + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (logMarkShift_measurable hF)] + rw [lintegral_prod_symm (fun p : ℝ × S => f (logMarkShift F p)) + (show AEMeasurable (fun p : ℝ × S => f (logMarkShift F p)) _ from + (hf.comp (logMarkShift_measurable hF)).aemeasurable), + lintegral_prod_symm _ hf.aemeasurable] + rw [lintegral_withDensity_eq_lintegral_mul ν (by fun_prop) + (Measurable.lintegral_prod_left' hf)] + apply lintegral_congr + intro s + exact stableLogIntensity_lintegral_translate hb (F s) (hf.comp (measurable_id.prodMk measurable_const)) + +lemma stablePoisson_mark_shift {S : Type*} [MeasurableSpace S] [Nonempty S] + (ν : Measure S) [SFinite ν] {b : ℝ} (hb : 0 ≤ b) + {F : S → ℝ} (hF : Measurable F) : + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).map (Measure.map (logMarkShift F)) = + poissonRandomMeasureLaw ((stableLogIntensity b).prod + (ν.withDensity (fun s => ENNReal.ofReal (Real.exp (b * F s))))) := by + rw [poissonRandomMeasureLaw_map _ (logMarkShift_measurable hF)] + congr 1 + exact stableLogIntensity_mark_shift ν hb hF + +lemma poissonMeasure_atom_succ (r : ℝ≥0) (n : ℕ) : + poissonMeasure r {n+1} * (n+1 : ℝ≥0∞) = (r : ℝ≥0∞) * poissonMeasure r {n} := by + have he : Real.exp (-(r : ℝ)) * (r : ℝ)^(n+1) / (n+1).factorial * (n+1 : ℝ) = + (r : ℝ) * (Real.exp (-(r : ℝ)) * (r : ℝ)^n / n.factorial) := by + rw [Nat.factorial_succ,Nat.cast_mul,Nat.cast_add,Nat.cast_one,pow_succ] + have hn : (n : ℝ) + 1 ≠ 0 := by positivity + have hf : (n.factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + field_simp + have he' := congrArg ENNReal.ofReal he + have hcast : ENNReal.ofReal ((n : ℝ)+1) = (n : ℝ≥0∞)+1 := by + rw [ENNReal.ofReal_add (by positivity) (by positivity),ENNReal.ofReal_natCast,ENNReal.ofReal_one] + simpa only [ENNReal.ofReal_mul (by positivity : 0 ≤ Real.exp (-(r : ℝ)) * (r : ℝ)^(n+1) / (n+1).factorial), + ENNReal.ofReal_mul r.coe_nonneg,ENNReal.ofReal_coe_nnreal,hcast,poissonMeasure_singleton] using he' + +lemma poissonMeasure_mean (r : ℝ≥0) : + ∑' n : ℕ, poissonMeasure r {n} * (n : ℝ≥0∞) = r := by + rw [tsum_eq_zero_add' ENNReal.summable] + simp only [Nat.cast_zero,mul_zero,zero_add,Nat.cast_add,Nat.cast_one] + simp_rw [poissonMeasure_atom_succ] + rw [ENNReal.tsum_mul_left] + have hmass : ∑' n : ℕ, poissonMeasure r {n} = 1 := by + simp_rw [poissonMeasure_singleton] + rw [← ENNReal.ofReal_tsum_of_nonneg (fun _ => by positivity) + (hasSum_one_poissonMeasure r).summable,(hasSum_one_poissonMeasure r).tsum_eq] + norm_num + rw [hmass,mul_one] + +lemma finitePointMeasure_lintegral {S : Type*} [MeasurableSpace S] + {f : S → ℝ≥0∞} (hf : Measurable f) (n : ℕ) (x : Fin n → S) : + ∫⁻ a, f a ∂finitePointMeasure n x = ∑ i, f (x i) := by + simp only [finitePointMeasure,lintegral_finsetSum_measure,lintegral_dirac' _ hf] + +lemma finitePoissonLaw_campbell {S : Type*} [MeasurableSpace S] + (r : ℝ≥0) (ν : Measure S) [IsProbabilityMeasure ν] + {f : S → ℝ≥0∞} (hf : Measurable f) : + ∫⁻ η, ∫⁻ x, f x ∂η ∂finitePoissonLaw r ν = (r : ℝ≥0∞) * ∫⁻ x, f x ∂ν := by + have hm := Measure.measurable_lintegral hf + rw [finitePoissonLaw,lintegral_sum_measure] + simp_rw [lintegral_smul_measure,lintegral_map hm (finitePointMeasure_measurable _), + finitePointMeasure_lintegral hf] + have he (n : ℕ) : (∫⁻ x : Fin n → S, ∑ i, f (x i) ∂Measure.pi (fun _ => ν)) = + (n : ℝ≥0∞) * ∫⁻ y, f y ∂ν := by + rw [lintegral_finsetSum (f := fun (i : Fin n) (x : Fin n → S) => f (x i)) _ + (fun i _ => hf.comp (measurable_pi_apply i))] + simp_rw [(measurePreserving_eval (fun _ : Fin n => ν) _).lintegral_comp hf] + simp + simp_rw [he,smul_eq_mul,← mul_assoc] + rw [ENNReal.tsum_mul_right,poissonMeasure_mean] + +lemma countablePoissonLaw_campbell {S : Type*} [MeasurableSpace S] + (r : ℕ → ℝ≥0) (ν : ℕ → Measure S) [∀ i, IsProbabilityMeasure (ν i)] + {f : S → ℝ≥0∞} (hf : Measurable f) : + ∫⁻ η, ∫⁻ x, f x ∂η ∂countablePoissonLaw r ν = + ∫⁻ x, f x ∂countablePoissonIntensity r ν := by + rw [countablePoissonLaw,lintegral_map (Measure.measurable_lintegral hf) measureSum_measurable] + simp only [lintegral_sum_measure] + rw [lintegral_tsum (f := fun (i : ℕ) (η : ℕ → Measure S) => ∫⁻ x, f x ∂η i) + (fun i => ((Measure.measurable_lintegral hf).comp (measurable_pi_apply i)).aemeasurable)] + simp_rw [(measurePreserving_eval_infinitePi (fun i => finitePoissonLaw (r i) (ν i)) _).lintegral_comp + (Measure.measurable_lintegral hf),finitePoissonLaw_campbell _ _ hf] + simp only [countablePoissonIntensity,lintegral_sum_measure,lintegral_smul_measure,smul_eq_mul] + +lemma poissonRandomMeasureLaw_campbell {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {f : S → ℝ≥0∞} (hf : Measurable f) : + ∫⁻ η, ∫⁻ x, f x ∂η ∂poissonRandomMeasureLaw κ = ∫⁻ x, f x ∂κ := by + rw [poissonRandomMeasureLaw,countablePoissonLaw_campbell _ _ hf] + simp only [countablePoissonIntensity,finiteIntensityMarks_smul,sum_sfiniteSeq] + +lemma ae_ne_top_of_laplace_tendsto {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {Z : Ω → ℝ≥0∞} (hZ : Measurable Z) + (hlim : Tendsto (fun n : ℕ => ∫ ω, + expNegENNReal (ENNReal.ofReal (1 / ((n : ℝ)+1)) * Z ω) ∂P) atTop (𝓝 1)) : + ∀ᵐ ω ∂P, Z ω ≠ ⊤ := by + let L : Ω → ℝ := fun ω => if Z ω = ⊤ then 0 else 1 + have hLm : Measurable L := measurable_const.ite (measurableSet_eq_fun hZ measurable_const) measurable_const + have hLb (ω : Ω) : 0 ≤ L ω ∧ L ω ≤ 1 := by unfold L; split_ifs <;> norm_num + have hLi : Integrable L P := Integrable.of_bound hLm.aestronglyMeasurable 1 + (ae_of_all _ fun ω => by rw [Real.norm_eq_abs,abs_of_nonneg (hLb ω).1]; exact (hLb ω).2) + have hconv (ω : Ω) : Tendsto (fun n : ℕ => + expNegENNReal (ENNReal.ofReal (1 / ((n : ℝ)+1)) * Z ω)) atTop (𝓝 (L ω)) := by + by_cases hz : Z ω = ⊤ + · have he (n : ℕ) : expNegENNReal (ENNReal.ofReal (1 / ((n : ℝ)+1)) * Z ω) = 0 := by + rw [hz,ENNReal.mul_top (by exact ne_of_gt (ENNReal.ofReal_pos.mpr (by positivity))),expNegENNReal_top] + simpa only [he,L,ite_eq_left hz] using (tendsto_const_nhds : Tendsto (fun _ : ℕ => (0 : ℝ)) atTop (𝓝 0)) + · have he (n : ℕ) : expNegENNReal (ENNReal.ofReal (1 / ((n : ℝ)+1)) * Z ω) = + Real.exp (-(1 / ((n : ℝ)+1) * (Z ω).toReal)) := by + rw [expNegENNReal_finite (ENNReal.mul_ne_top ENNReal.ofReal_ne_top hz), + ENNReal.toReal_mul,ENNReal.toReal_ofReal (by positivity)] + simp_rw [he] + simpa [L,hz,Function.comp_def] using Real.continuous_exp.continuousAt.tendsto.comp + ((tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)).mul_const (Z ω).toReal).neg + have hconv' := tendsto_integral_of_dominated_convergence (μ := P) + (F := fun n ω => expNegENNReal (ENNReal.ofReal (1 / ((n : ℝ)+1)) * Z ω)) + (fun _ : Ω => (1 : ℝ)) + (fun n => (expNegENNReal_continuous.measurable.comp + (measurable_const.mul hZ)).aestronglyMeasurable) (integrable_const 1) + (fun _ => ae_of_all _ fun ω => by + rw [Real.norm_eq_abs,abs_of_nonneg (expNegENNReal_bound _).1] + exact (expNegENNReal_bound _).2) (ae_of_all _ hconv) + have he : ∫ ω, L ω ∂P = 1 := (tendsto_nhds_unique hlim hconv').symm + have hzero : ∫ ω, 1 - L ω ∂P = 0 := by rw [integral_sub (integrable_const 1) hLi,he]; simp + have hae := (integral_eq_zero_iff_of_nonneg_ae + (ae_of_all _ fun ω => sub_nonneg.mpr (hLb ω).2) ((integrable_const 1).sub hLi)).mp hzero + filter_upwards [hae] with ω hω + intro hz + simp [L,hz] at hω + +lemma poissonRandomMeasureLaw_lintegral_ne_top {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] {f : S → ℝ} (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) + (hfin : ∫⁻ x, ENNReal.ofReal (min (f x) 1) ∂κ ≠ ⊤) : + ∀ᵐ η ∂poissonRandomMeasureLaw κ, (∫⁻ x, ENNReal.ofReal (f x) ∂η) ≠ ⊤ := by + apply ae_ne_top_of_laplace_tendsto _ (Measure.measurable_lintegral hf.ennreal_ofReal) + have hf' (n : ℕ) : Measurable (fun x => 1 / ((n : ℝ)+1) * f x) := measurable_const.mul hf + have hb (n : ℕ) (x : S) : 1 - Real.exp (-(1 / ((n : ℝ)+1) * f x)) ≤ min (f x) 1 := by + apply le_min + · have he := Real.add_one_le_exp (-(1 / ((n : ℝ)+1) * f x)) + have hc : 1 / ((n : ℝ)+1) ≤ 1 := by apply (div_le_iff₀ (by positivity)).mpr; simp + nlinarith [mul_le_of_le_one_left (hf0 x) hc] + · linarith [Real.exp_pos (-(1 / ((n : ℝ)+1) * f x))] + have hl := tendsto_lintegral_of_dominated_convergence (μ := κ) + (F := fun n x => ENNReal.ofReal (1 - Real.exp (-(1 / ((n : ℝ)+1) * f x)))) + (fun x => ENNReal.ofReal (min (f x) 1)) + (fun n => (measurable_const.sub (hf' n).neg.exp).ennreal_ofReal) + (fun n => ae_of_all _ fun x => ENNReal.ofReal_le_ofReal (hb n x)) hfin + (f := fun _ => 0) (ae_of_all _ fun x => by + simpa [Function.comp_def] using ENNReal.continuous_ofReal.continuousAt.tendsto.comp + ((tendsto_const_nhds : Tendsto (fun _ : ℕ => (1 : ℝ)) atTop (𝓝 1)).sub (Real.continuous_exp.continuousAt.tendsto.comp + ((tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)).mul_const (f x)).neg))) + have he (n : ℕ) : (∫ η, expNegENNReal (ENNReal.ofReal (1 / ((n : ℝ)+1)) * + ∫⁻ x, ENNReal.ofReal (f x) ∂η) ∂poissonRandomMeasureLaw κ) = + expNegENNReal (∫⁻ x, ENNReal.ofReal + (1 - Real.exp (-(1 / ((n : ℝ)+1) * f x))) ∂κ) := by + convert poissonRandomMeasureLaw_laplace κ (hf' n) (fun x => mul_nonneg (by positivity) (hf0 x)) using 1 + congr 1 + funext η + unfold poissonLaplace + rw [← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + congr 1 + apply lintegral_congr + intro x + rw [ENNReal.ofReal_mul (by positivity)] + simp_rw [he] + simpa only [lintegral_zero,expNegENNReal_finite (by simp : (0 : ℝ≥0∞) ≠ ⊤), + ENNReal.toReal_zero,neg_zero,Real.exp_zero,Function.comp_def] using + expNegENNReal_continuous.continuousAt.tendsto.comp hl + +lemma stableLogIntensity_min_exp_finite {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) : + (∫⁻ x, ENNReal.ofReal (min (Real.exp x) 1) ∂stableLogIntensity b) ≠ ⊤ := by + have hi : Integrable (fun x : ℝ => b * Real.exp (-b*x) * min (Real.exp x) 1) := by + have hh := (((integrableOn_exp_mul_Iic (a := 1-b) (by linarith) 0).integrable_indicator + measurableSet_Iic).add ((integrableOn_exp_mul_Ioi (a := -b) (by linarith) 0).integrable_indicator + measurableSet_Ioi)).const_mul b + convert hh using 1 + funext x + by_cases hx : x ≤ 0 + · simp only [Pi.add_apply] + rw [indicator_of_mem (show x ∈ Iic 0 from hx), + indicator_of_notMem (show x ∉ Ioi 0 from not_lt.mpr hx),add_zero, + min_eq_left (Real.exp_le_one_iff.mpr hx)] + rw [mul_assoc,← Real.exp_add] + congr 2 + ring + · have hx' : 0 < x := lt_of_not_ge hx + simp only [Pi.add_apply] + rw [indicator_of_notMem (show x ∉ Iic 0 from hx), + indicator_of_mem (show x ∈ Ioi 0 from hx'),zero_add, + min_eq_right (Real.one_le_exp_iff.mpr hx'.le),mul_one] + unfold stableLogIntensity + rw [lintegral_withDensity_eq_lintegral_mul volume (by fun_prop) (by fun_prop)] + have he : (∫⁻ x, ENNReal.ofReal (b * Real.exp (-b*x)) * ENNReal.ofReal (min (Real.exp x) 1)) = + ∫⁻ x, ENNReal.ofReal (b * Real.exp (-b*x) * min (Real.exp x) 1) := by + apply lintegral_congr + intro x + exact (ENNReal.ofReal_mul (mul_nonneg hb0.le (Real.exp_pos _).le)).symm + change (∫⁻ x, ENNReal.ofReal (b * Real.exp (-b*x)) * ENNReal.ofReal (min (Real.exp x) 1)) ≠ ⊤ + rw [he] + exact ((hasFiniteIntegral_iff_ofReal (ae_of_all _ fun x => by positivity)).mp hi.hasFiniteIntegral).ne + +lemma stablePoisson_total_finite {b : ℝ} (hb0 : 0 < b) (hb1 : b < 1) : + ∀ᵐ η ∂poissonRandomMeasureLaw (stableLogIntensity b), + (∫⁻ x, ENNReal.ofReal (Real.exp x) ∂η) ≠ ⊤ := + poissonRandomMeasureLaw_lintegral_ne_top _ Real.measurable_exp (fun x => (Real.exp_pos x).le) + (stableLogIntensity_min_exp_finite hb0 hb1) + +lemma stableLogIntensity_univ {b : ℝ} (hb : 0 < b) : stableLogIntensity b univ = ⊤ := by + have ha : (volume : Measure ℝ) ≪ stableLogIntensity b := + withDensity_absolutelyContinuous' (by fun_prop) + (ae_of_all _ fun x => ne_of_gt (ENNReal.ofReal_pos.mpr (mul_pos hb (Real.exp_pos _)))) + have hne : stableLogIntensity b univ ≠ 0 := by + intro h + have hh := ha h + simp at hh + by_contra ht + have hs := congrArg (fun κ : Measure ℝ => κ univ) (stableLogIntensity_translate hb.le 1) + rw [Measure.map_apply (show Measurable (fun x : ℝ => x+1) from measurable_id.add_const 1) + .univ,preimage_univ,Measure.smul_apply,smul_eq_mul] at hs + have hr := congrArg ENNReal.toReal hs + rw [ENNReal.toReal_mul,ENNReal.toReal_ofReal (Real.exp_pos _).le,mul_one] at hr + have hp := ENNReal.toReal_pos hne ht + have he : 1 < Real.exp b := Real.one_lt_exp_iff.mpr hb + nlinarith + +lemma poissonRandomMeasureLaw_lintegral_pos_of_infinite {S : Type*} [MeasurableSpace S] [Nonempty S] + (κ : Measure S) [SFinite κ] (hκ : κ univ = ⊤) + {f : S → ℝ} (hf : Measurable f) (hfpos : ∀ x, 0 < f x) : + ∀ᵐ η ∂poissonRandomMeasureLaw κ, 0 < ∫⁻ x, ENNReal.ofReal (f x) ∂η := by + have hconst : Measurable (fun _ : S => (1 : ℝ)) := measurable_const + have he := poissonRandomMeasureLaw_laplace κ hconst (fun _ => zero_le_one) + have hc : ENNReal.ofReal (1 - Real.exp (-1)) ≠ 0 := by + apply ne_of_gt + apply ENNReal.ofReal_pos.mpr + exact sub_pos.mpr (Real.exp_lt_one_iff.mpr (by norm_num)) + rw [lintegral_const,hκ,ENNReal.mul_top hc,expNegENNReal_top] at he + have hi : Integrable (poissonLaplace (fun _ : S => (1 : ℝ))) (poissonRandomMeasureLaw κ) := by + apply Integrable.of_bound (poissonLaplace_measurable hconst).aestronglyMeasurable 1 + exact ae_of_all _ fun η => by + rw [Real.norm_eq_abs,abs_of_nonneg (poissonLaplace_bounds _ η).1] + exact (poissonLaplace_bounds _ η).2 + have hae := (integral_eq_zero_iff_of_nonneg_ae + (ae_of_all _ fun η => (poissonLaplace_bounds (fun _ : S => (1 : ℝ)) η).1) hi).mp he + filter_upwards [hae] with η hη + have hsp : Function.support (fun x => ENNReal.ofReal (f x)) = univ := by + ext x + simp only [Function.mem_support,mem_univ,iff_true] + exact ne_of_gt (ENNReal.ofReal_pos.mpr (hfpos x)) + rw [lintegral_pos_iff_support hf.ennreal_ofReal,hsp] + by_contra hn + have hz : η univ = 0 := bot_unique (le_of_not_gt hn) + simp only [poissonLaplace,lintegral_const,ENNReal.ofReal_one,one_mul,hz, + expNegENNReal_finite (by simp : (0 : ℝ≥0∞) ≠ ⊤),ENNReal.toReal_zero,neg_zero,Real.exp_zero] at hη + exact one_ne_zero hη + +lemma stablePoisson_total_positive {b : ℝ} (hb : 0 < b) : + ∀ᵐ η ∂poissonRandomMeasureLaw (stableLogIntensity b), + 0 < ∫⁻ x, ENNReal.ofReal (Real.exp x) ∂η := + poissonRandomMeasureLaw_lintegral_pos_of_infinite _ (stableLogIntensity_univ hb) + Real.measurable_exp Real.exp_pos + +lemma standardGaussian_density_deriv (x : ℝ) : + HasDerivAt (gaussianPDFReal 0 1) (-x * gaussianPDFReal 0 1 x) x := by + have hd := (((hasDerivAt_id x).pow 2).neg.div_const 2).exp.const_mul + (Real.sqrt (2 * Real.pi))⁻¹ + convert! hd using 1 + · funext y + simp [gaussianPDFReal] + · simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero,Pi.neg_apply,Pi.pow_apply,id_eq,Nat.cast_ofNat] + norm_num + ring + +lemma standardGaussian_density_mul_integrable : + Integrable (fun x : ℝ => x * gaussianPDFReal 0 1 x) := by + have hi := (integrable_mul_exp_neg_mul_sq (b := (1/2 : ℝ)) (by norm_num)).const_mul + (Real.sqrt (2 * Real.pi))⁻¹ + convert hi using 1 + funext x + simp only [gaussianPDFReal,NNReal.coe_one,mul_one,sub_zero] + rw [show -(x ^ 2) / 2 = -(1 / 2 : ℝ) * x ^ 2 by ring] + ring + +def finiteMeasureCutKernel {S : Type*} [MeasurableSpace S] (n : ℕ) : Kernel (Measure S) S where + toFun η := if η univ ≤ n then η else 0 + measurable' := measurable_id.piecewise + (measurableSet_le (Measure.measurable_coe .univ) measurable_const) measurable_const + +instance finiteMeasureCutKernel_finite {S : Type*} [MeasurableSpace S] (n : ℕ) : + IsFiniteKernel (finiteMeasureCutKernel (S := S) n) := by + refine ⟨n,by simp,fun η => ?_⟩ + change (if η univ ≤ n then η else 0) univ ≤ n + split_ifs with h + · exact h + · simp + +lemma aemeasurable_measure_lintegral_of_finite {S : Type*} [MeasurableSpace S] + {P : Measure (Measure S)} (hP : ∀ᵐ η ∂P, η univ < ⊤) + {H : Measure S × S → ℝ≥0∞} (hH : Measurable H) : + AEMeasurable (fun η => ∫⁻ x, H (η,x) ∂η) P := by + have hm : Measurable (fun η => ⨆ n : ℕ, ∫⁻ x, H (η,x) ∂finiteMeasureCutKernel n η) := + Measurable.iSup fun n => hH.lintegral_kernel_prod_right' (κ := finiteMeasureCutKernel n) + apply hm.aemeasurable.congr + filter_upwards [hP] with η hη + apply le_antisymm + · apply iSup_le + intro n + change (∫⁻ x, H (η,x) ∂(if η univ ≤ n then η else 0)) ≤ _ + split_ifs <;> simp + · obtain ⟨n,hn⟩ := ENNReal.exists_nat_gt hη.ne + calc + (∫⁻ x, H (η,x) ∂η) = ∫⁻ x, H (η,x) ∂finiteMeasureCutKernel n η := by + change _ = ∫⁻ x, H (η,x) ∂(if η univ ≤ n then η else 0) + rw [ite_eq_left hn.le] + _ ≤ _ := le_iSup (fun m : ℕ => ∫⁻ x, H (η,x) ∂finiteMeasureCutKernel m η) n + +lemma finitePoissonLaw_ae_finite {S : Type*} [MeasurableSpace S] + (r : ℝ≥0) (ν : Measure S) : + ∀ᵐ η ∂finitePoissonLaw r ν, η univ < ⊤ := by + rw [finitePoissonLaw,Measure.ae_sum_iff] + intro n + apply Measure.ae_smul_measure + rw [ae_map_iff (finitePointMeasure_measurable n).aemeasurable + (measurableSet_lt (Measure.measurable_coe .univ) measurable_const)] + exact ae_of_all _ fun x => by simp [finitePointMeasure,Measure.finsetSum_apply] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/StableMassKernel.lean b/lean/OAI/Probability/Perceptron/Variational/StableMassKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f2038b350424c05fbfbf6d43dbe5cb466159cc0 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/StableMassKernel.lean @@ -0,0 +1,427 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.StableCascade + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff +attribute [fun_prop] stablePoissonTotal_measurable + +def stableMassKernel : Kernel (Measure ℝ) ℝ where + toFun η := normalizedMeasure (η.withDensity (fun x => ENNReal.ofReal (Real.exp x))) + measurable' := normalizedMeasure_measurable.comp (measurable_measure_withDensity_fixed (by fun_prop)) + +instance stableMassKernel_finite : IsFiniteKernel stableMassKernel := by + refine ⟨1, by simp, ?_⟩ + intro η + change (η.withDensity (fun x => ENNReal.ofReal (Real.exp x)) univ)⁻¹ * + (η.withDensity (fun x => ENNReal.ofReal (Real.exp x)) univ) ≤ 1 + exact ENNReal.inv_mul_le_one _ + +def stableCountKernel : Kernel (Measure ℝ) ℝ := + stableMassKernel.withDensity (fun η x => ENNReal.ofReal (stablePoissonTotal η*Real.exp (-x))) + +instance stableCountKernel_sFinite : IsSFiniteKernel stableCountKernel := + Kernel.IsSFiniteKernel.withDensity _ (fun _ _ => ENNReal.ofReal_ne_top) + +lemma stableCountKernel_eq (η : Measure ℝ) + (hf : stableJumpMomentE 1 η ≠ ⊤) (hp : 0 < stablePoissonTotal η) : + stableCountKernel η = η := by + rw [stableCountKernel,Kernel.withDensity_apply _ (by fun_prop : Measurable + (Function.uncurry (fun η x => ENNReal.ofReal (stablePoissonTotal η*Real.exp (-x)))))] + change (((η.withDensity (fun x => ENNReal.ofReal (Real.exp x)) univ)⁻¹) • + η.withDensity (fun x => ENNReal.ofReal (Real.exp x))).withDensity + (fun x => ENNReal.ofReal (stablePoissonTotal η*Real.exp (-x))) = η + have hmass : η.withDensity (fun x => ENNReal.ofReal (Real.exp x)) univ = + ENNReal.ofReal (stablePoissonTotal η) := by + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + exact (ENNReal.ofReal_toReal (by simpa [stableJumpMomentE] using hf)).symm + rw [hmass,withDensity_smul_measure,← withDensity_mul _ (by fun_prop) (by fun_prop)] + have hd : (fun x => ENNReal.ofReal (Real.exp x)* + ENNReal.ofReal (stablePoissonTotal η*Real.exp (-x))) = + (fun _ : ℝ => ENNReal.ofReal (stablePoissonTotal η)) := by + funext x + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le] + congr 1 + rw [Real.exp_neg] + field_simp + change (ENNReal.ofReal (stablePoissonTotal η))⁻¹ • η.withDensity + (fun x => ENNReal.ofReal (Real.exp x)*ENNReal.ofReal (stablePoissonTotal η*Real.exp (-x))) = η + rw [hd,withDensity_const,smul_smul,ENNReal.inv_mul_cancel + (ENNReal.ofReal_ne_zero_iff.mpr hp) ENNReal.ofReal_ne_top,one_smul] + +lemma stableJumpMomentE_one_add_dirac (x : ℝ) (η : Measure ℝ) : + stableJumpMomentE 1 (Measure.dirac x+η) = ENNReal.ofReal (Real.exp x)+stableJumpMomentE 1 η := by + simp [stableJumpMomentE,lintegral_add_measure] + +lemma stableCountKernel_add_dirac (η : Measure ℝ) (x : ℝ) + (hf : stableJumpMomentE 1 η ≠ ⊤) (hp : 0 < stablePoissonTotal η) : + stableCountKernel (Measure.dirac x+η) = Measure.dirac x+η := by + apply stableCountKernel_eq + · rw [stableJumpMomentE_one_add_dirac] + exact ENNReal.add_ne_top.mpr ⟨ENNReal.ofReal_ne_top,hf⟩ + · rw [stablePoissonTotal_add_dirac x η (by simpa [stableJumpMomentE] using hf)] + positivity + +lemma cascadeMeasurableSet_exists {A I : Type*} [MeasurableSpace A] [Countable I] + {p : I → A → Prop} (h : ∀ i, MeasurableSet {a | p i a}) : + MeasurableSet {a | ∃ i, p i a} := by + rw [Set.ofPred_exists] + exact MeasurableSet.iUnion h + +@[fun_prop] lemma measurable_fin_cons {A : Type*} [MeasurableSpace A] {n : ℕ} + {f : A → ℝ} {g : A → Fin n → ℝ} (hf : Measurable f) (hg : Measurable g) : + Measurable (fun a => (Fin.cons (f a) (g a) : Fin (n+1) → ℝ)) := by + apply Measurable.of_eval + intro i + refine Fin.cases ?_ (fun j => ?_) i + · simpa using hf + · simpa only [Fin.cons_succ,Function.comp_def] using (measurable_pi_apply j).comp hg + +def stableDistinctMoment : List ℝ → {m : ℕ} → Measure ℝ → (Fin m → ℝ) → ℝ≥0∞ + | [], _, _, _ => 1 + | r::rs, _, η, z => ∫⁻ x, if ∃ i, z i = x then 0 else + ENNReal.ofReal (Real.exp (r*x))*stableDistinctMoment rs η (Fin.cons x z) ∂stableCountKernel η + +lemma stableDistinctMoment_measurable (rs : List ℝ) (m : ℕ) : + Measurable (fun p : Measure ℝ × (Fin m → ℝ) => stableDistinctMoment rs p.1 p.2) := by + induction rs generalizing m with + | nil => exact measurable_const + | cons r rs ih => + let κ : Kernel (Measure ℝ × (Fin m → ℝ)) ℝ := stableCountKernel.comap (Prod.fst : Measure ℝ × (Fin m → ℝ) → Measure ℝ) measurable_fst + have hD : Measurable (fun p : (Measure ℝ × (Fin m → ℝ)) × ℝ => + stableDistinctMoment rs p.1.1 (Fin.cons p.2 p.1.2)) := by + exact (ih (m+1)).comp (measurable_fst.fst.prodMk + (measurable_fin_cons measurable_snd measurable_fst.snd)) + have hset : MeasurableSet {p : (Measure ℝ × (Fin m → ℝ)) × ℝ | ∃ i, p.1.2 i = p.2} := by + exact cascadeMeasurableSet_exists fun i => measurableSet_eq_fun (by fun_prop) measurable_snd + exact (measurable_const.ite hset ((by fun_prop : Measurable (fun p : + (Measure ℝ × (Fin m → ℝ)) × ℝ => ENNReal.ofReal (Real.exp (r*p.2)))).mul hD)).lintegral_kernel_prod_right' + (κ := κ) + +lemma stableDistinctMoment_add_dirac (rs : List ℝ) (η : Measure ℝ) (x : ℝ) + (hf : stableJumpMomentE 1 η ≠ ⊤) (hp : 0 < stablePoissonTotal η) + {m : ℕ} (z : Fin m → ℝ) (hz : ∃ i, z i = x) : + stableDistinctMoment rs (Measure.dirac x+η) z = stableDistinctMoment rs η z := by + induction rs generalizing m with + | nil => rfl + | cons r rs ih => + simp only [stableDistinctMoment,stableCountKernel_add_dirac η x hf hp, + stableCountKernel_eq η hf hp,lintegral_add_measure,lintegral_dirac,ite_eq_left hz,zero_add] + apply lintegral_congr + intro y + split_ifs + · rfl + · rw [ih (Fin.cons y z) (by obtain ⟨i,hi⟩ := hz; exact ⟨i.succ,hi⟩)] + +instance stableLogIntensity_noAtoms (b : ℝ) : NullSingletonClass (stableLogIntensity b) := by + unfold stableLogIntensity + infer_instance + +lemma stableDistinctMoment_palm_laplace {b t : ℝ} (hb : 0 < b) (hb1 : b < 1) + (ht : 0 < t) (rs : List ℝ) (hr : ∀ r ∈ rs, b < r) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, stableDistinctMoment rs η z*ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η)) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + ((rs.map (fun r => ENNReal.ofReal (b*t^(b-r)*Real.Gamma (r-b)))).prod)* + ENNReal.ofReal (Real.exp (-Real.Gamma (1-b)*t^b)) := by + induction rs generalizing m with + | nil => simpa [stableDistinctMoment] using stablePoissonTotal_laplace_lintegral hb hb1 ht + | cons r rs ih => + let P := poissonRandomMeasureLaw (stableLogIntensity b) + let L := ENNReal.ofReal (Real.exp (-Real.Gamma (1-b)*t^b)) + let C := (rs.map (fun r => ENNReal.ofReal (b*t^(b-r)*Real.Gamma (r-b)))).prod + let H : Measure ℝ × ℝ → ℝ≥0∞ := fun p => if ∃ i, z i = p.2 then 0 else + ENNReal.ofReal (Real.exp (r*p.2))*stableDistinctMoment rs p.1 (Fin.cons p.2 z)* + ENNReal.ofReal (Real.exp (-t*stablePoissonTotal p.1)) + have hH : Measurable H := by + have hD : Measurable (fun p : Measure ℝ × ℝ => stableDistinctMoment rs p.1 (Fin.cons p.2 z)) := + (stableDistinctMoment_measurable rs (m+1)).comp (measurable_fst.prodMk + (measurable_fin_cons measurable_snd measurable_const)) + exact measurable_const.ite (cascadeMeasurableSet_exists fun i => + measurableSet_eq_fun measurable_const measurable_snd) (by fun_prop) + have hstart : (∫⁻ η, stableDistinctMoment (r::rs) η z* + ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η)) ∂P) = + ∫⁻ η, ∫⁻ x, H (η,x) ∂η ∂P := by + apply lintegral_congr_ae + filter_upwards [stablePoisson_total_finite hb hb1,stablePoissonTotal_pos hb hb1] with η hf hp + rw [stableDistinctMoment,stableCountKernel_eq η (by simpa [stableJumpMomentE] using hf) hp, + ← lintegral_mul_const' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro x + dsimp [H] + split_ifs <;> simp + have hinner (x : ℝ) : (∫⁻ η, H (Measure.dirac x+η,x) ∂P) = + (if ∃ i, z i = x then 0 else ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*Real.exp x)))*(C*L) := by + by_cases hx : ∃ i, z i = x + · simp [H,hx] + have he : (fun η => H (Measure.dirac x+η,x)) =ᵐ[P] + (fun η => ENNReal.ofReal (Real.exp (r*x)*Real.exp (-t*Real.exp x))* + (stableDistinctMoment rs η (Fin.cons x z)*ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η)))) := by + filter_upwards [stablePoisson_total_finite hb hb1,stablePoissonTotal_pos hb hb1] with η hf hp + dsimp [H] + rw [ite_eq_right hx,stableDistinctMoment_add_dirac rs η x (by simpa [stableJumpMomentE] using hf) hp + (Fin.cons x z) ⟨0,rfl⟩,stablePoissonTotal_add_dirac x η hf,mul_add,Real.exp_add, + ENNReal.ofReal_mul (Real.exp_pos _).le,ENNReal.ofReal_mul (Real.exp_pos _).le] + ring + rw [lintegral_congr_ae he,lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + ih (fun s hs => hr s (List.mem_cons_of_mem r hs)) (Fin.cons x z),ite_eq_right hx] + rw [hstart,poissonRandomMeasureLaw_mecke _ hH] + change (∫⁻ x, ∫⁻ η, H (Measure.dirac x+η,x) ∂P ∂stableLogIntensity b) = _ + simp_rw [hinner] + rw [lintegral_mul_const] + · have hx : ∀ᵐ x ∂stableLogIntensity b, ¬ ∃ i, z i = x := by + filter_upwards [ae_all_iff.mpr (fun i : Fin m => (stableLogIntensity b).ae_ne (z i))] with x hx + exact fun h => by obtain ⟨i,hi⟩ := h; exact hx i hi.symm + rw [lintegral_congr_ae (hx.mono fun x hx => ite_eq_right hx), + stableLogIntensity_laplace_moment hb.le (hr r (by simp)) ht] + simp only [List.map_cons,List.prod_cons] + dsimp [C,L] + ring + · exact measurable_const.ite (cascadeMeasurableSet_exists fun i => + measurableSet_eq_fun measurable_const measurable_id) (by fun_prop) + +lemma stableLaplaceProduct_shape {b t : ℝ} (hb : 0 < b) (ht : 0 < t) + (rs : List ℝ) (hr : ∀ r ∈ rs, b < r) : + (rs.map (fun r => ENNReal.ofReal (b*t^(b-r)*Real.Gamma (r-b)))).prod = + (rs.map (fun r => ENNReal.ofReal (b*Real.Gamma (r-b)))).prod* + ENNReal.ofReal (t^((rs.length:ℝ)*b-rs.sum)) := by + induction rs with + | nil => simp + | cons r rs ih => + have hrr : b < r := hr r (by simp) + have hc : 0 ≤ b*Real.Gamma (r-b) := mul_nonneg hb.le (Real.Gamma_pos_of_pos (sub_pos.mpr hrr)).le + have he : ENNReal.ofReal (b*t^(b-r)*Real.Gamma (r-b)) = + ENNReal.ofReal (b*Real.Gamma (r-b))*ENNReal.ofReal (t^(b-r)) := by + rw [← ENNReal.ofReal_mul hc] + congr 1 + ring + simp only [List.map_cons,List.prod_cons,List.length_cons,List.sum_cons,Nat.cast_add,Nat.cast_one] + rw [he,ih (fun v hv => hr v (List.mem_cons_of_mem r hv))] + calc + _ = (ENNReal.ofReal (b*Real.Gamma (r-b))*(rs.map (fun r => ENNReal.ofReal (b*Real.Gamma (r-b)))).prod)* + (ENNReal.ofReal (t^(b-r))*ENNReal.ofReal (t^((rs.length:ℝ)*b-rs.sum))) := by ring + _ = _ := by + rw [← ENNReal.ofReal_mul (Real.rpow_nonneg ht.le _),← Real.rpow_add ht] + congr 3 + ring + +lemma list_length_mul_le_sum {rs : List ℝ} {b : ℝ} (hr : ∀ r ∈ rs, b ≤ r) : + (rs.length:ℝ)*b ≤ rs.sum := by + induction rs with + | nil => simp + | cons r rs ih => + have hrr := hr r (by simp) + have hi := ih (fun s hs => hr s (List.mem_cons_of_mem r hs)) + simp only [List.length_cons,List.sum_cons,Nat.cast_add,Nat.cast_one] + nlinarith + +lemma stableDistinctMoment_palm_mellin_mul {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) + (ha : a < b) (rs : List ℝ) (hne : rs ≠ []) (hr : ∀ r ∈ rs, b < r) + {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, stableDistinctMoment rs η z*ENNReal.ofReal (stablePoissonTotal η^(a-rs.sum)) + ∂poissonRandomMeasureLaw (stableLogIntensity b))*ENNReal.ofReal (Real.Gamma (rs.sum-a)) = + (rs.map (fun r => ENNReal.ofReal (b*Real.Gamma (r-b)))).prod* + ENNReal.ofReal ((Real.Gamma (1-b))^(a/b-(rs.length:ℝ))*(1/b)* + Real.Gamma ((rs.length:ℝ)-a/b)) := by + let P := poissonRandomMeasureLaw (stableLogIntensity b) + let c := Real.Gamma (1-b) + let A := (rs.map (fun r => ENNReal.ofReal (b*Real.Gamma (r-b)))).prod + have hc : 0 < c := Real.Gamma_pos_of_pos (by linarith) + have hj : (1:ℝ) ≤ rs.length := by + have hj : 1 ≤ rs.length := by cases rs <;> simp_all + exact_mod_cast hj + have hjb : 0 < (rs.length:ℝ)*b-a := by nlinarith + have hsum : 0 < rs.sum-a := by + have hsum := list_length_mul_le_sum (fun r hr' => (hr r hr').le) + linarith + have hD : Measurable (fun η => stableDistinctMoment rs η z) := + (stableDistinctMoment_measurable rs m).comp (measurable_id.prodMk measurable_const) + let K := fun (η : Measure ℝ) (t : ℝ) => stableDistinctMoment rs η z* + ENNReal.ofReal (t^(rs.sum-a-1)*Real.exp (-t*stablePoissonTotal η)) + have hm : Measurable (Function.uncurry K) := by + exact (hD.comp measurable_fst).mul (by fun_prop) + have hgamma : ∀ᵐ η ∂P, + stableDistinctMoment rs η z*ENNReal.ofReal (stablePoissonTotal η^(a-rs.sum))* + ENNReal.ofReal (Real.Gamma (rs.sum-a)) = ∫⁻ t : ℝ in Ioi 0, K η t := by + filter_upwards [stablePoissonTotal_pos hb hb1] with η hη + dsimp [K] + rw [lintegral_const_mul _ (by fun_prop),gamma_lintegral_positive_scale hsum hη, + show -(rs.sum-a) = a-rs.sum by ring,ENNReal.ofReal_mul (Real.rpow_nonneg hη.le _),mul_assoc] + have hinner (t : ℝ) (ht : 0 < t) : (∫⁻ η, K η t ∂P) = + A*ENNReal.ofReal (t^((rs.length:ℝ)*b-a-1)*Real.exp (-c*t^b)) := by + have hfac (η : Measure ℝ) : K η t = ENNReal.ofReal (t^(rs.sum-a-1))* + (stableDistinctMoment rs η z*ENNReal.ofReal (Real.exp (-t*stablePoissonTotal η))) := by + dsimp [K] + rw [ENNReal.ofReal_mul (Real.rpow_nonneg ht.le _)] + ring + simp_rw [hfac] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + stableDistinctMoment_palm_laplace hb hb1 ht rs hr z,stableLaplaceProduct_shape hb ht rs hr] + change ENNReal.ofReal (t^(rs.sum-a-1))*(A*ENNReal.ofReal (t^((rs.length:ℝ)*b-rs.sum))* + ENNReal.ofReal (Real.exp (-c*t^b))) = _ + calc + _ = A*(ENNReal.ofReal (t^(rs.sum-a-1))*ENNReal.ofReal (t^((rs.length:ℝ)*b-rs.sum)))* + ENNReal.ofReal (Real.exp (-c*t^b)) := by ring + _ = _ := by + rw [← ENNReal.ofReal_mul (Real.rpow_nonneg ht.le _),← Real.rpow_add ht, + show rs.sum-a-1+((rs.length:ℝ)*b-rs.sum) = (rs.length:ℝ)*b-a-1 by ring, + mul_assoc,← ENNReal.ofReal_mul (Real.rpow_nonneg ht.le _)] + calc + _ = ∫⁻ η, stableDistinctMoment rs η z*ENNReal.ofReal (stablePoissonTotal η^(a-rs.sum))* + ENNReal.ofReal (Real.Gamma (rs.sum-a)) ∂P := + (lintegral_mul_const' _ _ ENNReal.ofReal_ne_top).symm + _ = ∫⁻ η, (∫⁻ t : ℝ in Ioi 0, K η t) ∂P := lintegral_congr_ae hgamma + _ = ∫⁻ t : ℝ in Ioi 0, ∫⁻ η, K η t ∂P := lintegral_lintegral_swap hm.aemeasurable + _ = ∫⁻ t : ℝ in Ioi 0, + A*ENNReal.ofReal (t^((rs.length:ℝ)*b-a-1)*Real.exp (-c*t^b)) := by + apply lintegral_congr_ae + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + exact hinner t ht + _ = A*ENNReal.ofReal (c^(-(((rs.length:ℝ)*b-a-1)+1)/b)*(1/b)* + Real.Gamma ((((rs.length:ℝ)*b-a-1)+1)/b)) := by + rw [lintegral_const_mul _ (by fun_prop),gamma_lintegral_rpow_scale (by linarith) hb hc] + _ = _ := by + rw [show -(((rs.length:ℝ)*b-a-1)+1)/b = a/b-(rs.length:ℝ) by field_simp; ring, + show (((rs.length:ℝ)*b-a-1)+1)/b = (rs.length:ℝ)-a/b by field_simp; ring] + +lemma gamma_stable_product {a b : ℝ} (hb : 0 < b) (ha : a < b) (k : ℕ) : + b^k * Real.Gamma (((k+1:ℕ):ℝ)-a/b) = + Real.Gamma (1-a/b) * ∏ ℓ ∈ Finset.range k, (((ℓ:ℝ)+1)*b-a) := by + have hab : a/b < 1 := (div_lt_one hb).mpr ha + induction k with + | zero => simp + | succ k ih => + have hp : 0 < ((k+1:ℕ):ℝ)-a/b := by + have hk : (0:ℝ) ≤ k := Nat.cast_nonneg k + push_cast + linarith + rw [show ((k+1+1:ℕ):ℝ)-a/b = (((k+1:ℕ):ℝ)-a/b)+1 by push_cast; ring, + Real.Gamma_add_one hp.ne',pow_succ,Finset.prod_range_succ] + calc + _ = (b^k*Real.Gamma (((k+1:ℕ):ℝ)-a/b))*(((k:ℝ)+1)*b-a) := by + push_cast + field_simp + _ = _ := by rw [ih]; ring + +lemma stable_eppf_scalar {a b c n G : ℝ} (hb : 0 < b) (ha : a < b) + (hc : 0 < c) (hn : 0 < n-a) (ha1 : a < 1) (k : ℕ) : + (b^(k+1)*G*(c^(a/b-((k+1:ℕ):ℝ))*(1/b)*Real.Gamma (((k+1:ℕ):ℝ)-a/b)) / + Real.Gamma (n-a))/(Real.Gamma (1-a/b)*c^(a/b)/Real.Gamma (1-a)) = + Real.Gamma (1-a)/Real.Gamma (n-a)* + (∏ ℓ ∈ Finset.range k, (((ℓ:ℝ)+1)*b-a))*(G/c^(k+1)) := by + have hγ : Real.Gamma (1-a/b) ≠ 0 := (Real.Gamma_pos_of_pos (by + have := (div_lt_one hb).mpr ha + linarith)).ne' + have hγn : Real.Gamma (n-a) ≠ 0 := (Real.Gamma_pos_of_pos hn).ne' + have hpow : c^(a/b) ≠ 0 := (Real.rpow_pos_of_pos hc _).ne' + have hg := gamma_stable_product hb ha k + rw [Real.rpow_sub hc, Real.rpow_natCast] + have hga : Real.Gamma (1-a) ≠ 0 := (Real.Gamma_pos_of_pos (sub_pos.mpr ha1)).ne' + have hcpow : c^(k+1) ≠ 0 := pow_ne_zero _ hc.ne' + have hN : b^(k+1)*G*(c^(a/b)/c^(k+1)*(1/b)*Real.Gamma (((k+1:ℕ):ℝ)-a/b)) = + G*(c^(a/b)/c^(k+1))*(b^k*Real.Gamma (((k+1:ℕ):ℝ)-a/b)) := by + rw [pow_succ] + field_simp + rw [hN,hg] + have hγ' : Real.Gamma ((b-a)/b) ≠ 0 := by simpa [sub_div, hb.ne'] using hγ + field_simp + +lemma list_prod_map_const_mul (c : ℝ) (f : ℝ → ℝ) (rs : List ℝ) : + (rs.map (fun r => c*f r)).prod = c^rs.length*(rs.map f).prod := by + induction rs with + | nil => simp + | cons r rs ih => simp only [List.map_cons,List.prod_cons,List.length_cons,pow_succ,ih]; ring + +lemma list_prod_map_div_const (c : ℝ) (f : ℝ → ℝ) (rs : List ℝ) : + (rs.map (fun r => f r/c)).prod = (rs.map f).prod/c^rs.length := by + simp [div_eq_mul_inv,mul_comm,inv_pow] + +lemma list_prod_ofReal (rs : List ℝ) (hr : ∀ r ∈ rs, 0 ≤ r) : + (rs.map ENNReal.ofReal).prod = ENNReal.ofReal rs.prod := by + induction rs with + | nil => simp + | cons r rs ih => + rw [List.map_cons,List.prod_cons,List.prod_cons,ih (fun x hx => hr x (by simp [hx])), + ENNReal.ofReal_mul (hr r (by simp))] + +theorem stableDistinctMoment_eppf {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) + (ha : a < b) (rs : List ℝ) (hne : rs ≠ []) (hr : ∀ r ∈ rs, b < r) + {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, stableDistinctMoment rs η z*ENNReal.ofReal (stablePoissonTotal η^(a-rs.sum)) + ∂poissonRandomMeasureLaw (stableLogIntensity b))/ + (∫⁻ η, ENNReal.ofReal (stablePoissonTotal η^a) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + ENNReal.ofReal (Real.Gamma (1-a)/Real.Gamma (rs.sum-a)* + (∏ ℓ ∈ Finset.range (rs.length-1), (((ℓ:ℝ)+1)*b-a))* + (rs.map (fun r => Real.Gamma (r-b)/Real.Gamma (1-b))).prod) := by + let c := Real.Gamma (1-b) + let G := (rs.map (fun r => Real.Gamma (r-b))).prod + have hc : 0 < c := Real.Gamma_pos_of_pos (by linarith) + have hga : 0 < Real.Gamma (1-a) := Real.Gamma_pos_of_pos (by linarith) + have hgab : 0 < Real.Gamma (1-a/b) := Real.Gamma_pos_of_pos (by + have := (div_lt_one hb).mpr ha + linarith) + have hj : 1 ≤ rs.length := by cases rs <;> simp_all + have hjR : (1:ℝ) ≤ rs.length := by exact_mod_cast hj + have hj1 : rs.length-1+1 = rs.length := Nat.sub_add_cancel hj + have hsum : 0 < rs.sum-a := by + have := list_length_mul_le_sum (fun r hr' => (hr r hr').le) + nlinarith + have hgn : 0 < Real.Gamma (rs.sum-a) := Real.Gamma_pos_of_pos hsum + have hG : 0 ≤ G := List.prod_nonneg (by + intro x hx + obtain ⟨r,hr',rfl⟩ := List.mem_map.mp hx + exact (Real.Gamma_pos_of_pos (sub_pos.mpr (hr r hr'))).le) + have hA : (rs.map (fun r => ENNReal.ofReal (b*Real.Gamma (r-b)))).prod = + ENNReal.ofReal (b^rs.length*G) := by + rw [show (rs.map (fun r => ENNReal.ofReal (b*Real.Gamma (r-b)))) = + (rs.map (fun r => b*Real.Gamma (r-b))).map ENNReal.ofReal by simp only [List.map_map,Function.comp_def], + list_prod_ofReal _ (by + intro x hx + obtain ⟨r,hr',rfl⟩ := List.mem_map.mp hx + exact mul_nonneg hb.le (Real.Gamma_pos_of_pos (sub_pos.mpr (hr r hr'))).le), + list_prod_map_const_mul] + have hMpos : 0 < Real.Gamma (1-a/b)*c^(a/b)/Real.Gamma (1-a) := + div_pos (mul_pos hgab (Real.rpow_pos_of_pos hc _)) hga + have hM : (∫⁻ η, ENNReal.ofReal (stablePoissonTotal η^a) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + ENNReal.ofReal (Real.Gamma (1-a/b)*c^(a/b)/Real.Gamma (1-a)) := by + rw [← ofReal_integral_eq_lintegral_ofReal (stablePoissonTotal_rpow_integrable hb hb1 ha) + (ae_of_all _ (fun η => Real.rpow_nonneg ENNReal.toReal_nonneg _)), + stablePoissonTotal_rpow_integral hb hb1 ha] + have he := stableDistinctMoment_palm_mellin_mul hb hb1 ha rs hne hr z + have hI : (∫⁻ η, stableDistinctMoment rs η z*ENNReal.ofReal (stablePoissonTotal η^(a-rs.sum)) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) = + ((rs.map (fun r => ENNReal.ofReal (b*Real.Gamma (r-b)))).prod* + ENNReal.ofReal ((Real.Gamma (1-b))^(a/b-(rs.length:ℝ))*(1/b)* + Real.Gamma ((rs.length:ℝ)-a/b)))/ENNReal.ofReal (Real.Gamma (rs.sum-a)) := by + apply (ENNReal.eq_div_iff (ENNReal.ofReal_ne_zero_iff.mpr hgn) ENNReal.ofReal_ne_top).mpr + rw [mul_comm] + exact he + rw [hI,hA,hM,← ENNReal.ofReal_mul (mul_nonneg (pow_nonneg hb.le _) hG), + ← ENNReal.ofReal_div_of_pos hgn,← ENNReal.ofReal_div_of_pos hMpos] + congr 1 + rw [list_prod_map_div_const] + exact (by simpa only [hj1,c,G] using stable_eppf_scalar hb ha hc hsum (by linarith) (rs.length-1)) + +def stableEppfValue (a b : ℝ) (rs : List ℝ) : ℝ := + Real.Gamma (1-a)/Real.Gamma (rs.sum-a)* + (∏ ℓ ∈ Finset.range (rs.length-1), (((ℓ:ℝ)+1)*b-a))* + (rs.map (fun r => Real.Gamma (r-b)/Real.Gamma (1-b))).prod + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/StableTotalBiasedLaw.lean b/lean/OAI/Probability/Perceptron/Variational/StableTotalBiasedLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..392725fa7a34824f605c56c1c939c4857e9116e9 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/StableTotalBiasedLaw.lean @@ -0,0 +1,447 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StableMassKernel + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +open scoped Pointwise +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped RealInnerProductSpace MatrixOrder +open TopologicalSpace +open scoped Polynomial +open scoped ContDiff +attribute [fun_prop] stablePoissonTotal_measurable + +lemma stableEppfValue_singleton_one {a b : ℝ} (ha : a < 1) (hb : b < 1) : + stableEppfValue a b [1] = 1 := by + have hga : Real.Gamma (1-a) ≠ 0 := (Real.Gamma_pos_of_pos (sub_pos.mpr ha)).ne' + have hgb : Real.Gamma (1-b) ≠ 0 := (Real.Gamma_pos_of_pos (sub_pos.mpr hb)).ne' + simp [stableEppfValue,hga,hgb] + +lemma stableEppfValue_join {a b r : ℝ} (hr : b < r) (rs : List ℝ) + (hn : 0 < r+rs.sum-a) : + stableEppfValue a b ((r+1)::rs) = + (r-b)/(r+rs.sum-a)*stableEppfValue a b (r::rs) := by + unfold stableEppfValue + simp only [List.sum_cons,List.length_cons,List.map_cons,List.prod_cons,Nat.add_sub_cancel] + rw [show r+1+rs.sum-a = (r+rs.sum-a)+1 by ring, + show r+1-b = (r-b)+1 by ring, + Real.Gamma_add_one hn.ne',Real.Gamma_add_one (sub_pos.mpr hr).ne'] + field_simp + simp only [mul_comm b] + ring + +lemma stableEppfValue_new {a b : ℝ} (hb : b < 1) (rs : List ℝ) (hne : rs ≠ []) + (hn : 0 < rs.sum-a) : + stableEppfValue a b (1::rs) = + ((rs.length:ℝ)*b-a)/(rs.sum-a)*stableEppfValue a b rs := by + have hj : 1 ≤ rs.length := by cases rs <;> simp_all + have hj1 : rs.length-1+1 = rs.length := Nat.sub_add_cancel hj + have hgb : Real.Gamma (1-b) ≠ 0 := (Real.Gamma_pos_of_pos (sub_pos.mpr hb)).ne' + unfold stableEppfValue + simp only [List.sum_cons,List.length_cons,List.map_cons,List.prod_cons,Nat.add_sub_cancel,div_self hgb,one_mul] + rw [show 1+rs.sum-a = (rs.sum-a)+1 by ring,Real.Gamma_add_one hn.ne', + ← hj1,Finset.prod_range_succ] + have hcast : ((rs.length-1:ℕ):ℝ)+1 = (rs.length:ℝ) := by exact_mod_cast hj1 + rw [hcast,hj1] + field_simp + simp only [mul_comm b] + ring + +def stableTotalBiasedLaw (a b : ℝ) : Measure (Measure ℝ) := + normalizedMeasure ((poissonRandomMeasureLaw (stableLogIntensity b)).withDensity + (fun η => ENNReal.ofReal (stablePoissonTotal η^a))) + +lemma stableTotalBias_mass {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) : + ((poissonRandomMeasureLaw (stableLogIntensity b)).withDensity + (fun η => ENNReal.ofReal (stablePoissonTotal η^a))) univ = + ENNReal.ofReal (Real.Gamma (1-a/b)*(Real.Gamma (1-b))^(a/b)/Real.Gamma (1-a)) := by + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + ← ofReal_integral_eq_lintegral_ofReal (stablePoissonTotal_rpow_integrable hb hb1 ha) + (ae_of_all _ (fun η => Real.rpow_nonneg ENNReal.toReal_nonneg _)), + stablePoissonTotal_rpow_integral hb hb1 ha] + +lemma stableTotalBiasedLaw_probability {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) : + IsProbabilityMeasure (stableTotalBiasedLaw a b) := by + have hp : 0 < Real.Gamma (1-a/b)*(Real.Gamma (1-b))^(a/b)/Real.Gamma (1-a) := by + apply div_pos (mul_pos (Real.Gamma_pos_of_pos ?_) (Real.rpow_pos_of_pos (Real.Gamma_pos_of_pos (by linarith)) _)) + (Real.Gamma_pos_of_pos (by linarith)) + have := (div_lt_one hb).mpr ha + linarith + apply normalizedMeasure_probability + · rw [stableTotalBias_mass hb hb1 ha]; exact ENNReal.ofReal_ne_zero_iff.mpr hp + · rw [stableTotalBias_mass hb hb1 ha]; exact ENNReal.ofReal_ne_top + +def stableOrderedDistinctMass (rs : List ℝ) (η : Measure ℝ) {m : ℕ} (z : Fin m → ℝ) : ℝ≥0∞ := + stableDistinctMoment rs η z*ENNReal.ofReal (stablePoissonTotal η^(-rs.sum)) + +lemma stableOrderedDistinctMass_measurable (rs : List ℝ) {m : ℕ} (z : Fin m → ℝ) : + Measurable (fun η => stableOrderedDistinctMass rs η z) := + ((stableDistinctMoment_measurable rs m).comp (measurable_id.prodMk measurable_const)).mul (by fun_prop) + +lemma stableOrderedDistinctMass_biased {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) + (_ha : a < b) (rs : List ℝ) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, stableOrderedDistinctMass rs η z ∂stableTotalBiasedLaw a b) = + (∫⁻ η, stableDistinctMoment rs η z*ENNReal.ofReal (stablePoissonTotal η^(a-rs.sum)) + ∂poissonRandomMeasureLaw (stableLogIntensity b))/ + (∫⁻ η, ENNReal.ofReal (stablePoissonTotal η^a) + ∂poissonRandomMeasureLaw (stableLogIntensity b)) := by + unfold stableTotalBiasedLaw normalizedMeasure + rw [lintegral_smul_measure,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (stableOrderedDistinctMass_measurable rs z)] + simp only [smul_eq_mul,Pi.mul_apply] + rw [div_eq_mul_inv,mul_comm] + congr 1 + apply lintegral_congr_ae + filter_upwards [stablePoissonTotal_pos hb hb1] with η hp + unfold stableOrderedDistinctMass + calc + _ = stableDistinctMoment rs η z*(ENNReal.ofReal (stablePoissonTotal η^a)* + ENNReal.ofReal (stablePoissonTotal η^(-rs.sum))) := by ring + _ = _ := by rw [← ENNReal.ofReal_mul (Real.rpow_nonneg hp.le _),← Real.rpow_add hp,sub_eq_add_neg] + +lemma stableOrderedDistinctMass_eppf {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) + (ha : a < b) (rs : List ℝ) (hne : rs ≠ []) (hr : ∀ r ∈ rs, b < r) + {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, stableOrderedDistinctMass rs η z ∂stableTotalBiasedLaw a b) = + ENNReal.ofReal (Real.Gamma (1-a)/Real.Gamma (rs.sum-a)* + (∏ ℓ ∈ Finset.range (rs.length-1), (((ℓ:ℝ)+1)*b-a))* + (rs.map (fun r => Real.Gamma (r-b)/Real.Gamma (1-b))).prod) := by + rw [stableOrderedDistinctMass_biased hb hb1 ha,stableDistinctMoment_eppf hb hb1 ha rs hne hr] + +lemma stableCountAtom_measurable : + Measurable (fun p : Measure ℝ × ℝ => stableCountKernel p.1 {p.2}) := by + let κ : Kernel (Measure ℝ × ℝ) ℝ := stableCountKernel.comap (Prod.fst : Measure ℝ × ℝ → Measure ℝ) measurable_fst + have hm : Measurable (fun p : (Measure ℝ × ℝ) × ℝ => if p.2 = p.1.2 then (1:ℝ≥0∞) else 0) := + measurable_const.ite (measurableSet_eq_fun measurable_snd measurable_fst.snd) measurable_const + have hh := hm.lintegral_kernel_prod_right' (κ := κ) + convert hh using 1 + funext p + change _ = ∫⁻ y, if y = p.2 then (1:ℝ≥0∞) else 0 ∂stableCountKernel p.1 + rw [show (fun y : ℝ => if y = p.2 then (1:ℝ≥0∞) else 0) = + ({p.2}:Set ℝ).indicator (fun _ => (1:ℝ≥0∞)) by rfl, + lintegral_indicator (measurableSet_singleton _),lintegral_one,Measure.restrict_apply_univ] + +lemma stablePoissonCount_simple {b : ℝ} (hb : 0 < b) (hb1 : b < 1) : + ∀ᵐ η ∂poissonRandomMeasureLaw (stableLogIntensity b), ∀ᵐ x ∂η, η {x} = 1 := by + let P := poissonRandomMeasureLaw (stableLogIntensity b) + let H := fun p : Measure ℝ × ℝ => if stableCountKernel p.1 {p.2} = 1 then (0:ℝ≥0∞) else 1 + have hm : Measurable H := measurable_const.ite (measurableSet_eq_fun stableCountAtom_measurable measurable_const) measurable_const + have hright (x : ℝ) : (∫⁻ η, H (Measure.dirac x+η,x) ∂P) = 0 := by + apply (lintegral_eq_zero_iff (hm.comp ((measurable_const.add measurable_id).prodMk measurable_const))).mpr + filter_upwards [stablePoisson_total_finite hb hb1,stablePoissonTotal_pos hb hb1, + poissonRandomMeasureLaw_ae_null (stableLogIntensity b) (measurableSet_singleton x) (measure_singleton x)] with η hf hp hnull + have hf' : stableJumpMomentE 1 η ≠ ⊤ := by simpa [stableJumpMomentE] using hf + simp [H,stableCountKernel_add_dirac η x hf' hp,hnull] + have he : (∫⁻ η, ∫⁻ x, H (η,x) ∂η ∂P) = 0 := by + rw [poissonRandomMeasureLaw_mecke (stableLogIntensity b) hm] + change (∫⁻ x, ∫⁻ η, H (Measure.dirac x+η,x) ∂P ∂stableLogIntensity b) = 0 + simp_rw [hright] + exact lintegral_zero + have hkernel : Measurable (fun η => ∫⁻ x, H (η,x) ∂stableCountKernel η) := + hm.lintegral_kernel_prod_right' + have he' : (∫⁻ η, ∫⁻ x, H (η,x) ∂stableCountKernel η ∂P) = 0 := by + rw [← he] + apply lintegral_congr_ae + filter_upwards [stablePoisson_total_finite hb hb1,stablePoissonTotal_pos hb hb1] with η hf hp + rw [stableCountKernel_eq η (by simpa [stableJumpMomentE] using hf) hp] + have hae := (lintegral_eq_zero_iff hkernel).mp he' + filter_upwards [hae,stablePoisson_total_finite hb hb1,stablePoissonTotal_pos hb hb1] with η hzero hf hp + rw [stableCountKernel_eq η (by simpa [stableJumpMomentE] using hf) hp] at hzero + have hz := (lintegral_eq_zero_iff (hm.comp (measurable_const.prodMk measurable_id))).mp hzero + filter_upwards [hz] with x hx + dsimp [H] at hx + rw [stableCountKernel_eq η (by simpa [stableJumpMomentE] using hf) hp] at hx + by_contra h + simp [h] at hx + +lemma stableMassKernel_atom_eq (η : Measure ℝ) {x : ℝ} + (hf : stableJumpMomentE 1 η ≠ ⊤) (hp : 0 < stablePoissonTotal η) (hx : η {x} = 1) : + stableMassKernel η {x} = ENNReal.ofReal (Real.exp x/stablePoissonTotal η) := by + change ((η.withDensity (fun y => ENNReal.ofReal (Real.exp y)) univ)⁻¹ • + η.withDensity (fun y => ENNReal.ofReal (Real.exp y))) {x} = _ + rw [Measure.smul_apply,smul_eq_mul,withDensity_apply _ (measurableSet_singleton x),lintegral_singleton,hx,mul_one, + withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + have htotal : (∫⁻ y, ENNReal.ofReal (Real.exp y) ∂η) = ENNReal.ofReal (stablePoissonTotal η) := by + exact (ENNReal.ofReal_toReal (by simpa [stableJumpMomentE] using hf)).symm + rw [htotal,ENNReal.ofReal_div_of_pos hp,div_eq_mul_inv,mul_comm] + +lemma stableMassAtom_measurable : + Measurable (fun p : Measure ℝ × ℝ => stableMassKernel p.1 {p.2}) := by + let κ : Kernel (Measure ℝ × ℝ) ℝ := stableMassKernel.comap (Prod.fst : Measure ℝ × ℝ → Measure ℝ) measurable_fst + have hm : Measurable (fun p : (Measure ℝ × ℝ) × ℝ => if p.2 = p.1.2 then (1:ℝ≥0∞) else 0) := + measurable_const.ite (measurableSet_eq_fun measurable_snd measurable_fst.snd) measurable_const + have hh := hm.lintegral_kernel_prod_right' (κ := κ) + convert hh using 1 + funext p + change _ = ∫⁻ y, if y = p.2 then (1:ℝ≥0∞) else 0 ∂stableMassKernel p.1 + rw [show (fun y : ℝ => if y = p.2 then (1:ℝ≥0∞) else 0) = + ({p.2}:Set ℝ).indicator (fun _ => (1:ℝ≥0∞)) by rfl, + lintegral_indicator (measurableSet_singleton _),lintegral_one,Measure.restrict_apply_univ] + +lemma stableMassAtom_measurable_comp {A : Type*} [MeasurableSpace A] + {f : A → Measure ℝ} {g : A → ℝ} (hf : Measurable f) (hg : Measurable g) : + Measurable (fun a => stableMassKernel (f a) {g a}) := by + exact Measurable.comp (g := (fun p : Measure ℝ × ℝ => stableMassKernel p.1 {p.2})) + (f := (fun a => (f a,g a))) stableMassAtom_measurable (hf.prodMk hg) + +def stableBlockProbability : List ℕ → {m : ℕ} → Measure ℝ → (Fin m → ℝ) → ℝ≥0∞ + | [], _, _, _ => 1 + | n::ns, _, η, z => ∫⁻ x, if ∃ i, z i = x then 0 else + (stableMassKernel η {x})^(n-1)*stableBlockProbability ns η (Fin.cons x z) ∂stableMassKernel η + +lemma stableBlockProbability_measurable (ns : List ℕ) (m : ℕ) : + Measurable (fun p : Measure ℝ × (Fin m → ℝ) => stableBlockProbability ns p.1 p.2) := by + induction ns generalizing m with + | nil => exact measurable_const + | cons n ns ih => + let κ : Kernel (Measure ℝ × (Fin m → ℝ)) ℝ := stableMassKernel.comap (Prod.fst : Measure ℝ × (Fin m → ℝ) → Measure ℝ) measurable_fst + have hD : Measurable (fun p : (Measure ℝ × (Fin m → ℝ)) × ℝ => + stableBlockProbability ns p.1.1 (Fin.cons p.2 p.1.2)) := by + exact (ih (m+1)).comp (measurable_fst.fst.prodMk + (measurable_fin_cons measurable_snd measurable_fst.snd)) + have ha : Measurable (fun p : (Measure ℝ × (Fin m → ℝ)) × ℝ => + stableMassKernel p.1.1 {p.2}) := + stableMassAtom_measurable_comp (f := fun p : (Measure ℝ × (Fin m → ℝ)) × ℝ => p.1.1) + (g := fun p => p.2) measurable_fst.fst measurable_snd + have hset : MeasurableSet {p : (Measure ℝ × (Fin m → ℝ)) × ℝ | ∃ i, p.1.2 i = p.2} := by + exact cascadeMeasurableSet_exists fun i => measurableSet_eq_fun (by fun_prop) measurable_snd + exact (measurable_const.ite hset ((ha.pow_const _).mul hD)).lintegral_kernel_prod_right' (κ := κ) + +lemma stableBlockProbability_moment (ns : List ℕ) (hn : ∀ n ∈ ns, 1 ≤ n) (η : Measure ℝ) + (hf : stableJumpMomentE 1 η ≠ ⊤) (hp : 0 < stablePoissonTotal η) + (hs : ∀ᵐ x ∂η, η {x} = 1) {m : ℕ} (z : Fin m → ℝ) : + stableBlockProbability ns η z = stableDistinctMoment (ns.map (fun n : ℕ => (n:ℝ))) η z* + ((ENNReal.ofReal (stablePoissonTotal η))⁻¹)^ns.sum := by + induction ns generalizing m with + | nil => simp [stableBlockProbability,stableDistinctMoment] + | cons n ns ih => + have hn0 : 1 ≤ n := hn n (by simp) + have hn' : n-1+1 = n := Nat.sub_add_cancel hn0 + have hns : ∀ k ∈ ns, 1 ≤ k := fun k hk => hn k (by simp [hk]) + have hm : Measurable (fun x => if ∃ i, z i = x then (0:ℝ≥0∞) else + (stableMassKernel η {x})^(n-1)*stableBlockProbability ns η (Fin.cons x z)) := by + exact measurable_const.ite (cascadeMeasurableSet_exists fun i => + measurableSet_eq_fun measurable_const measurable_id) + (((stableMassAtom_measurable.comp (measurable_const.prodMk measurable_id)).pow_const _).mul + ((stableBlockProbability_measurable ns (m+1)).comp + (measurable_const.prodMk (measurable_fin_cons measurable_id measurable_const)))) + have htotal : (η.withDensity (fun x => ENNReal.ofReal (Real.exp x))) univ = + ENNReal.ofReal (stablePoissonTotal η) := by + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + exact (ENNReal.ofReal_toReal (by simpa [stableJumpMomentE] using hf)).symm + unfold stableBlockProbability + change (∫⁻ x, (if ∃ i, z i = x then 0 else (stableMassKernel η {x})^(n-1)* + stableBlockProbability ns η (Fin.cons x z)) ∂normalizedMeasure + (η.withDensity (fun x => ENNReal.ofReal (Real.exp x)))) = _ + rw [normalizedMeasure,lintegral_smul_measure,htotal, + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) hm] + simp only [smul_eq_mul,Pi.mul_apply] + rw [← lintegral_const_mul' _ _ (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr hp))] + have hpoint : (fun x => (ENNReal.ofReal (stablePoissonTotal η))⁻¹ * + (ENNReal.ofReal (Real.exp x)*(if ∃ i, z i = x then 0 else + (stableMassKernel η {x})^(n-1)*stableBlockProbability ns η (Fin.cons x z)))) =ᵐ[η] + (fun x => (if ∃ i, z i = x then 0 else ENNReal.ofReal (Real.exp ((n:ℝ)*x))* + stableDistinctMoment (ns.map (fun n : ℕ => (n:ℝ))) η (Fin.cons x z))* + ((ENNReal.ofReal (stablePoissonTotal η))⁻¹)^(n+ns.sum)) := by + filter_upwards [hs] with x hx + split_ifs + · simp + · rw [stableMassKernel_atom_eq η hf hp hx,ENNReal.ofReal_div_of_pos hp, + ih hns (Fin.cons x z),div_eq_mul_inv,mul_pow,Real.exp_nat_mul,ENNReal.ofReal_pow (Real.exp_pos _).le, + pow_add,← hn',pow_succ] + simp only [Nat.add_sub_cancel] + ring + rw [lintegral_congr_ae hpoint,lintegral_mul_const' _ _ (ENNReal.pow_ne_top + (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr hp)))] + simp only [List.map_cons,List.sum_cons] + rw [stableDistinctMoment,stableCountKernel_eq η hf hp] + +lemma stableTotalBiasedLaw_absolutelyContinuous (a b : ℝ) : + stableTotalBiasedLaw a b ≪ poissonRandomMeasureLaw (stableLogIntensity b) := by + exact Measure.smul_absolutelyContinuous.trans (withDensity_absolutelyContinuous _ _) + +lemma stableBlockProbability_ordered (ns : List ℕ) (hn : ∀ n ∈ ns, 1 ≤ n) (η : Measure ℝ) + (hf : stableJumpMomentE 1 η ≠ ⊤) (hp : 0 < stablePoissonTotal η) + (hs : ∀ᵐ x ∂η, η {x} = 1) {m : ℕ} (z : Fin m → ℝ) : + stableBlockProbability ns η z = stableOrderedDistinctMass (ns.map (fun n : ℕ => (n:ℝ))) η z := by + rw [stableBlockProbability_moment ns hn η hf hp hs] + unfold stableOrderedDistinctMass + congr 1 + rw [Real.rpow_neg hp.le,ENNReal.ofReal_inv_of_pos (Real.rpow_pos_of_pos hp _)] + have hsum : (ns.map (fun n : ℕ => (n:ℝ))).sum = (ns.sum:ℝ) := by + induction ns with + | nil => simp + | cons n ns ih => simp + rw [hsum,Real.rpow_natCast,ENNReal.ofReal_pow hp.le,ENNReal.inv_pow] + +lemma stableBlockProbability_eppf {a b : ℝ} (hb : 0 < b) (hb1 : b < 1) (ha : a < b) + (ns : List ℕ) (hne : ns ≠ []) (hn : ∀ n ∈ ns, 1 ≤ n) {m : ℕ} (z : Fin m → ℝ) : + (∫⁻ η, stableBlockProbability ns η z ∂stableTotalBiasedLaw a b) = + ENNReal.ofReal (Real.Gamma (1-a)/Real.Gamma ((ns.map (fun n : ℕ => (n:ℝ))).sum-a)* + (∏ ℓ ∈ Finset.range (ns.length-1), (((ℓ:ℝ)+1)*b-a))* + (ns.map (fun n : ℕ => Real.Gamma ((n:ℝ)-b)/Real.Gamma (1-b))).prod) := by + have hr : ∀ r ∈ ns.map (fun n : ℕ => (n:ℝ)), b < r := by + intro r hr + obtain ⟨n,hnn,rfl⟩ := List.mem_map.mp hr + exact hb1.trans_le (by exact_mod_cast hn n hnn) + have he := stableOrderedDistinctMass_eppf hb hb1 ha (ns.map (fun n : ℕ => (n:ℝ))) + (by simpa using hne) hr z + have hae : (fun η => stableBlockProbability ns η z) =ᵐ[stableTotalBiasedLaw a b] + (fun η => stableOrderedDistinctMass (ns.map (fun n : ℕ => (n:ℝ))) η z) := by + apply (stableTotalBiasedLaw_absolutelyContinuous a b).ae_eq + filter_upwards [stablePoisson_total_finite hb hb1,stablePoissonTotal_pos hb hb1, + stablePoissonCount_simple hb hb1] with η hf hp hs + exact stableBlockProbability_ordered ns hn η (by simpa [stableJumpMomentE] using hf) hp hs z + rw [lintegral_congr_ae hae] + simpa only [List.length_map,List.map_map,Function.comp_def] using he + +variable {S : Type*} [MeasurableSpace S] + +def markedStableTotalE (η : Measure (ℝ × S)) : ℝ≥0∞ := + ∫⁻ p, ENNReal.ofReal (Real.exp p.1) ∂η + +@[fun_prop] lemma markedStableTotalE_measurable : Measurable (markedStableTotalE (S := S)) := + Measure.measurable_lintegral (by fun_prop) + +def markedStableTotal (η : Measure (ℝ × S)) : ℝ := (markedStableTotalE η).toReal + +@[fun_prop] lemma markedStableTotal_measurable : Measurable (markedStableTotal (S := S)) := + markedStableTotalE_measurable.ennreal_toReal + +lemma markedStableTotalE_projection (η : Measure (ℝ × S)) : + markedStableTotalE η = stableJumpMomentE 1 (η.map Prod.fst) := by + simp only [markedStableTotalE,stableJumpMomentE,one_mul] + rw [lintegral_map (by fun_prop) measurable_fst] + +lemma markedStableTotal_projection (η : Measure (ℝ × S)) : + markedStableTotal η = stablePoissonTotal (η.map Prod.fst) := by + simp only [markedStableTotal,markedStableTotalE_projection,stableJumpMomentE,one_mul,stablePoissonTotal] + +def markedStableMassKernel : Kernel (Measure (ℝ × S)) (ℝ × S) where + toFun η := normalizedMeasure (η.withDensity (fun p => ENNReal.ofReal (Real.exp p.1))) + measurable' := normalizedMeasure_measurable.comp (measurable_measure_withDensity_fixed (by fun_prop)) + +instance markedStableMassKernel_finite : IsFiniteKernel (markedStableMassKernel (S := S)) := by + refine ⟨1, by simp, ?_⟩ + intro η + change (η.withDensity (fun p => ENNReal.ofReal (Real.exp p.1)) univ)⁻¹ * + (η.withDensity (fun p => ENNReal.ofReal (Real.exp p.1)) univ) ≤ 1 + exact ENNReal.inv_mul_le_one _ + +def markedStableCountKernel : Kernel (Measure (ℝ × S)) (ℝ × S) := + markedStableMassKernel.withDensity (fun η p => ENNReal.ofReal (markedStableTotal η*Real.exp (-p.1))) + +instance markedStableCountKernel_sfinite : IsSFiniteKernel (markedStableCountKernel (S := S)) := + Kernel.IsSFiniteKernel.withDensity _ (fun _ _ => ENNReal.ofReal_ne_top) + +lemma markedStableCountKernel_eq (η : Measure (ℝ × S)) + (hf : markedStableTotalE η ≠ ⊤) (hp : 0 < markedStableTotal η) : + markedStableCountKernel η = η := by + rw [markedStableCountKernel,Kernel.withDensity_apply _ (by fun_prop : Measurable + (Function.uncurry (fun (η : Measure (ℝ × S)) (p : ℝ × S) => ENNReal.ofReal (markedStableTotal η*Real.exp (-p.1)))))] + change (((η.withDensity (fun p => ENNReal.ofReal (Real.exp p.1)) univ)⁻¹) • + η.withDensity (fun p => ENNReal.ofReal (Real.exp p.1))).withDensity + (fun p => ENNReal.ofReal (markedStableTotal η*Real.exp (-p.1))) = η + have hmass : η.withDensity (fun p => ENNReal.ofReal (Real.exp p.1)) univ = + ENNReal.ofReal (markedStableTotal η) := by + rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + exact (ENNReal.ofReal_toReal hf).symm + rw [hmass,withDensity_smul_measure,← withDensity_mul _ (by fun_prop) (by fun_prop)] + have hd : (fun p : ℝ × S => ENNReal.ofReal (Real.exp p.1)* + ENNReal.ofReal (markedStableTotal η*Real.exp (-p.1))) = + (fun _ : ℝ × S => ENNReal.ofReal (markedStableTotal η)) := by + funext p + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le] + congr 1 + rw [Real.exp_neg] + field_simp + change (ENNReal.ofReal (markedStableTotal η))⁻¹ • η.withDensity + (fun p => ENNReal.ofReal (Real.exp p.1)*ENNReal.ofReal (markedStableTotal η*Real.exp (-p.1))) = η + rw [hd,withDensity_const,smul_smul,ENNReal.inv_mul_cancel + (ENNReal.ofReal_ne_zero_iff.mpr hp) ENNReal.ofReal_ne_top,one_smul] + +lemma markedStableTotalE_add_dirac (p : ℝ × S) (η : Measure (ℝ × S)) : + markedStableTotalE (Measure.dirac p+η) = ENNReal.ofReal (Real.exp p.1)+markedStableTotalE η := by + simp only [markedStableTotalE,lintegral_add_measure] + rw [lintegral_dirac' _ (by fun_prop)] + +lemma markedStableTotal_add_dirac (p : ℝ × S) (η : Measure (ℝ × S)) + (hf : markedStableTotalE η ≠ ⊤) : + markedStableTotal (Measure.dirac p+η) = Real.exp p.1+markedStableTotal η := by + rw [markedStableTotal,markedStableTotalE_add_dirac, + ENNReal.toReal_add ENNReal.ofReal_ne_top hf,ENNReal.toReal_ofReal (Real.exp_pos _).le] + rfl + +lemma markedStableCountKernel_add_dirac (η : Measure (ℝ × S)) (p : ℝ × S) + (hf : markedStableTotalE η ≠ ⊤) (hp : 0 < markedStableTotal η) : + markedStableCountKernel (Measure.dirac p+η) = Measure.dirac p+η := by + apply markedStableCountKernel_eq + · rw [markedStableTotalE_add_dirac]; exact ENNReal.add_ne_top.mpr ⟨ENNReal.ofReal_ne_top,hf⟩ + · rw [markedStableTotal_add_dirac p η hf]; linarith [Real.exp_pos p.1] + +variable [Nonempty S] +lemma markedStable_project_law (ν : Measure S) [IsProbabilityMeasure ν] (b : ℝ) : + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)).map (Measure.map Prod.fst) = + poissonRandomMeasureLaw (stableLogIntensity b) := by + rw [poissonRandomMeasureLaw_map _ measurable_fst] + simp only [Measure.map_fst_prod,measure_univ,one_smul] + +lemma markedStable_regular (ν : Measure S) [IsProbabilityMeasure ν] {b : ℝ} + (hb : 0 < b) (hb1 : b < 1) : + ∀ᵐ η ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν), + markedStableTotalE η ≠ ⊤ ∧ 0 < markedStableTotal η := by + have hpres : MeasurePreserving (Measure.map (Prod.fst : ℝ × S → ℝ)) + (poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) + (poissonRandomMeasureLaw (stableLogIntensity b)) := + ⟨Measure.measurable_map _ measurable_fst,markedStable_project_law ν b⟩ + have he := hpres.quasiMeasurePreserving.ae ((stablePoisson_total_finite hb hb1).and (stablePoissonTotal_pos hb hb1)) + simpa only [markedStableTotalE_projection,markedStableTotal_projection,stableJumpMomentE,one_mul] using he + +lemma markedStable_laplace (ν : Measure S) [IsProbabilityMeasure ν] {b t : ℝ} + (hb : 0 < b) (hb1 : b < 1) (ht : 0 < t) : + (∫⁻ η, ENNReal.ofReal (Real.exp (-t*markedStableTotal η)) + ∂poissonRandomMeasureLaw ((stableLogIntensity b).prod ν)) = + ENNReal.ofReal (Real.exp (-Real.Gamma (1-b)*t^b)) := by + have he := stablePoissonTotal_laplace_lintegral hb hb1 ht + rw [← markedStable_project_law ν b] at he + rw [lintegral_map (by fun_prop) (Measure.measurable_map _ measurable_fst)] at he + simpa only [markedStableTotal_projection] using he + +def markedDistinctMoment : List (ℝ × (S → ℝ≥0∞)) → {m : ℕ} → Measure (ℝ × S) → (Fin m → ℝ) → ℝ≥0∞ + | [], _, _, _ => 1 + | rf::rs, _, η, z => ∫⁻ p, if ∃ i, z i = p.1 then 0 else + ENNReal.ofReal (Real.exp (rf.1*p.1))*rf.2 p.2* + markedDistinctMoment rs η (Fin.cons p.1 z) ∂markedStableCountKernel η + +omit [Nonempty S] in +lemma markedDistinctMoment_measurable (rs : List (ℝ × (S → ℝ≥0∞))) + (hr : ∀ rf ∈ rs, Measurable rf.2) (m : ℕ) : + Measurable (fun p : Measure (ℝ × S) × (Fin m → ℝ) => markedDistinctMoment rs p.1 p.2) := by + induction rs generalizing m with + | nil => exact measurable_const + | cons rf rs ih => + let κ : Kernel (Measure (ℝ × S) × (Fin m → ℝ)) (ℝ × S) := markedStableCountKernel.comap + (Prod.fst : Measure (ℝ × S) × (Fin m → ℝ) → Measure (ℝ × S)) measurable_fst + have hD : Measurable (fun p : (Measure (ℝ × S) × (Fin m → ℝ)) × (ℝ × S) => + markedDistinctMoment rs p.1.1 (Fin.cons p.2.1 p.1.2)) := by + exact (ih (fun r hr' => hr r (List.mem_cons_of_mem rf hr')) (m+1)).comp + (measurable_fst.fst.prodMk (measurable_fin_cons measurable_snd.fst measurable_fst.snd)) + have hset : MeasurableSet {p : (Measure (ℝ × S) × (Fin m → ℝ)) × (ℝ × S) | + ∃ i, p.1.2 i = p.2.1} := by + exact cascadeMeasurableSet_exists fun i => measurableSet_eq_fun (by fun_prop) measurable_snd.fst + exact (measurable_const.ite hset (((by fun_prop : Measurable (fun p : + (Measure (ℝ × S) × (Fin m → ℝ)) × (ℝ × S) => ENNReal.ofReal (Real.exp (rf.1*p.2.1)))).mul + ((hr rf (by simp)).comp measurable_snd.snd)).mul hD)).lintegral_kernel_prod_right' (κ := κ) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/StationaryExistence.lean b/lean/OAI/Probability/Perceptron/Variational/StationaryExistence.lean new file mode 100644 index 0000000000000000000000000000000000000000..dbd7fd286bf8936dcdd0d93d61194652ae9d3c33 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/StationaryExistence.lean @@ -0,0 +1,267 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StepDual +import OAI.Probability.Perceptron.Variational.Entropy + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def stepTailSum {k : ℕ} (v : Fin k → ℝ) (i : Fin (k+1)) : ℝ := + ∑ j : Fin k, if i ≤ j.castSucc then v j else 0 + +lemma stepTailSum_zero {k : ℕ} (v : Fin k → ℝ) : stepTailSum v 0=∑ j, v j := by + simp only [stepTailSum,Fin.zero_le,ite_true] + +lemma stepTailSum_last {k : ℕ} (v : Fin k → ℝ) : stepTailSum v (Fin.last k)=0 := by + apply Finset.sum_eq_zero + intro j _ + have hj : ¬Fin.last k ≤ j.castSucc := by simp only [Fin.le_iff_val_le_val,Fin.val_last,Fin.val_castSucc]; omega + exact ite_eq_right hj + +lemma stepTailSum_difference {k : ℕ} (v : Fin k → ℝ) (i : Fin k) : + stepTailSum v i.castSucc-stepTailSum v i.succ=v i := by + classical + unfold stepTailSum + rw [← Finset.sum_sub_distrib] + calc + _ = ∑ j : Fin k, if j=i then v j else 0 := by + apply Finset.sum_congr rfl + intro j _ + by_cases hji : j=i + · subst j + have hi : ¬i.succ ≤ i.castSucc := by simp only [Fin.le_iff_val_le_val,Fin.val_succ,Fin.val_castSucc]; omega + simp only [ite_eq_left le_rfl,ite_eq_right hi,sub_zero,ite_true] + · have he : (i.castSucc ≤ j.castSucc) ↔ (i.succ ≤ j.castSucc) := by + simp only [Fin.le_iff_val_le_val,Fin.val_succ,Fin.val_castSucc] + have hv : i.val ≠ j.val := by intro hij; exact hji (Fin.ext hij.symm) + omega + simp only [he,sub_self,ite_eq_right hji] + _ = _ := by simp + +lemma stepTailSum_nonneg {k : ℕ} (v : Fin k → ℝ) (hv : ∀ j, 0 ≤ v j) (i : Fin (k+1)) : + 0 ≤ stepTailSum v i := by + apply Finset.sum_nonneg + intro j _ + split_ifs <;> first | exact hv j | rfl + +lemma stepTailSum_le_zero {k : ℕ} (v : Fin k → ℝ) (hv : ∀ j, 0 ≤ v j) (i : Fin (k+1)) : + stepTailSum v i ≤ stepTailSum v 0 := by + rw [stepTailSum_zero] + apply Finset.sum_le_sum + intro j _ + split_ifs <;> first | rfl | exact hv j + +def finitePrecisionShift {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) : Fin (k+1) → ℝ := + stepTailSum (fun i => 2*z i*(h i.succ-h i.castSucc)) + +def finitePrecisionTail {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (b : ℝ) (i : Fin (k+1)) : ℝ := (b-finitePrecisionShift z h i)⁻¹ + +def finiteOverlapIncrement {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (b : ℝ) (i : Fin k) : ℝ := + 2*(h i.succ-h i.castSucc)*finitePrecisionTail z h b i.castSucc*finitePrecisionTail z h b i.succ + +def finiteStationarityMass {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) (b : ℝ) : ℝ := + 2*h 0*(finitePrecisionTail z h b 0)^2+(∑ i, finiteOverlapIncrement z h b i)+ + finitePrecisionTail z h b (Fin.last k) + +lemma finitePrecisionShift_le_root {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (hz : ∀ i, 0 ≤ z i) (hh : Monotone h) (i : Fin (k+1)) : + finitePrecisionShift z h i ≤ finitePrecisionShift z h 0 := + stepTailSum_le_zero _ (fun j => mul_nonneg (mul_nonneg (by norm_num) (hz j)) + (sub_nonneg.mpr (hh (Fin.castSucc_le_succ j)))) i + +lemma finitePrecisionTail_pos {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (hz : ∀ i, 0 ≤ z i) (hh : Monotone h) {b : ℝ} (hb : finitePrecisionShift z h 0 < b) + (i : Fin (k+1)) : 0 < finitePrecisionTail z h b i := + inv_pos.mpr (sub_pos.mpr ((finitePrecisionShift_le_root z h hz hh i).trans_lt hb)) + +lemma finitePrecisionTail_gap {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (hz : ∀ i, 0 ≤ z i) (hh : Monotone h) {b : ℝ} (hb : finitePrecisionShift z h 0 < b) + (i : Fin k) : finitePrecisionTail z h b i.castSucc-finitePrecisionTail z h b i.succ = + z i*finiteOverlapIncrement z h b i := by + have h1 : b-finitePrecisionShift z h i.castSucc ≠ 0 := + (sub_pos.mpr ((finitePrecisionShift_le_root z h hz hh i.castSucc).trans_lt hb)).ne' + have h2 : b-finitePrecisionShift z h i.succ ≠ 0 := + (sub_pos.mpr ((finitePrecisionShift_le_root z h hz hh i.succ).trans_lt hb)).ne' + have he := stepTailSum_difference (fun j => 2*z j*(h j.succ-h j.castSucc)) i + change finitePrecisionShift z h i.castSucc-finitePrecisionShift z h i.succ = + 2*z i*(h i.succ-h i.castSucc) at he + unfold finiteOverlapIncrement finitePrecisionTail + field_simp [h1,h2] + linear_combination he + +lemma finiteOverlapIncrement_nonneg {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (hz : ∀ i, 0 ≤ z i) (hh : Monotone h) {b : ℝ} (hb : finitePrecisionShift z h 0 < b) + (i : Fin k) : 0 ≤ finiteOverlapIncrement z h b i := by + exact mul_nonneg (mul_nonneg (mul_nonneg (by norm_num) (sub_nonneg.mpr (hh (Fin.castSucc_le_succ i)))) + (finitePrecisionTail_pos z h hz hh hb i.castSucc).le) (finitePrecisionTail_pos z h hz hh hb i.succ).le + +lemma finiteStationarityMass_ge_root {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (hz0 : ∀ i, 0 ≤ z i) (hz1 : ∀ i, z i ≤ 1) (hh : Monotone h) (hh0 : 0 ≤ h 0) + {b : ℝ} (hb : finitePrecisionShift z h 0 < b) : + finitePrecisionTail z h b 0 ≤ finiteStationarityMass z h b := by + have hg (i : Fin k) : finitePrecisionTail z h b i.castSucc-finitePrecisionTail z h b i.succ ≤ + finiteOverlapIncrement z h b i := by + rw [finitePrecisionTail_gap z h hz0 hh hb i] + exact mul_le_of_le_one_left (finiteOverlapIncrement_nonneg z h hz0 hh hb i) (hz1 i) + have hs := Finset.sum_le_sum (fun i (_ : i ∈ (Finset.univ : Finset (Fin k))) => hg i) + have ht := finite_sum_successive_differences k (finitePrecisionTail z h b) + have he : (∑ i : Fin k, (finitePrecisionTail z h b i.castSucc-finitePrecisionTail z h b i.succ)) = + finitePrecisionTail z h b 0-finitePrecisionTail z h b (Fin.last k) := by + rw [Finset.sum_sub_distrib] at ht ⊢ + linarith + rw [he] at hs + have hn : 0 ≤ 2*h 0*(finitePrecisionTail z h b 0)^2 := by positivity + unfold finiteStationarityMass + linarith + +lemma finiteStationarityMass_continuousOn {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (hz : ∀ i, 0 ≤ z i) (hh : Monotone h) : + ContinuousOn (finiteStationarityMass z h) (Ici (finitePrecisionShift z h 0+1)) := by + have hc (i : Fin (k+1)) : ContinuousOn (fun b => finitePrecisionTail z h b i) + (Ici (finitePrecisionShift z h 0+1)) := by + apply (continuous_id.sub continuous_const).continuousOn.inv₀ + intro b hb + have hi := finitePrecisionShift_le_root z h hz hh i + change finitePrecisionShift z h 0+1 ≤ b at hb + change b-finitePrecisionShift z h i ≠ 0 + exact (sub_pos.mpr (by linarith)).ne' + exact ((continuousOn_const.mul (hc 0 |>.pow 2)).add + (continuousOn_finsetSum Finset.univ (fun i _ => + (continuousOn_const.mul (hc i.castSucc)).mul (hc i.succ)))).add (hc (Fin.last k)) + +lemma finiteStationarityMass_tendsto {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) : + Tendsto (finiteStationarityMass z h) atTop (𝓝 0) := by + have ht (i : Fin (k+1)) : Tendsto (fun b => finitePrecisionTail z h b i) atTop (𝓝 0) := by + simpa only [finitePrecisionTail,sub_eq_add_neg,Function.comp_def,id_eq] using + (tendsto_inv_atTop_zero.comp (tendsto_atTop_add_const_right atTop (-finitePrecisionShift z h i) tendsto_id)) + have hi (i : Fin k) : Tendsto (fun b => finiteOverlapIncrement z h b i) atTop (𝓝 0) := by + simpa only [finiteOverlapIncrement,mul_zero] using ((ht i.castSucc).const_mul (2*(h i.succ-h i.castSucc))).mul (ht i.succ) + have hs := tendsto_finsetSum Finset.univ (fun i _ => hi i) + have hf := (((ht 0).pow 2).const_mul (2*h 0)).add hs |>.add (ht (Fin.last k)) + change Tendsto (fun b => 2*h 0*(finitePrecisionTail z h b 0)^2+ + (∑ i, finiteOverlapIncrement z h b i)+finitePrecisionTail z h b (Fin.last k)) atTop (𝓝 0) + simpa only [zero_pow (by norm_num : (2:ℕ) ≠ 0),mul_zero,Finset.sum_const_zero,zero_add] using hf + +theorem exists_finite_normalizing_precision {k : ℕ} (z : Fin k → ℝ) (h : Fin (k+1) → ℝ) + (hz0 : ∀ i, 0 ≤ z i) (hz1 : ∀ i, z i ≤ 1) (hh : Monotone h) (hh0 : 0 ≤ h 0) : + ∃ b : ℝ, finitePrecisionShift z h 0 < b ∧ finiteStationarityMass z h b=1 := by + let a := finitePrecisionShift z h 0+1 + have ha : finitePrecisionShift z h 0 < a := by dsimp only [a]; linarith + have hstart : 1 ≤ finiteStationarityMass z h a := by + have hs := finiteStationarityMass_ge_root z h hz0 hz1 hh hh0 ha + simpa only [finitePrecisionTail,a,add_sub_cancel_left,inv_one] using hs + have hev := (finiteStationarityMass_tendsto z h).eventually_lt_const (by norm_num : (0:ℝ)<1) + obtain ⟨b,hb,hend⟩ := ((eventually_ge_atTop a).and hev).exists + have hc : ContinuousOn (finiteStationarityMass z h) (Icc a b) := + (finiteStationarityMass_continuousOn z h hz0 hh).mono Icc_subset_Ici_self + obtain ⟨c,hc,he⟩ := intermediate_value_Icc' hb hc ⟨hend.le,hstart⟩ + exact ⟨c,ha.trans_le hc.1,he⟩ + +theorem exists_finite_stationary_quantile {k : ℕ} (w h : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) (hh : Monotone h) (hh0 : 0 ≤ h 0) : + ∃ q : Fin (k+1) → Time, Monotone q ∧ (q (Fin.last k):ℝ) < 1 ∧ + ∀ i, 2*h i=weightedStepA w (fun j => (q j:ℝ)) (q i) := by + let z := stepCumulative w + have hz0 : ∀ i, 0 < z i := stepCumulative_pos w hw + have hz1 : ∀ i, z i < 1 := stepCumulative_lt_one w hw hw1 + obtain ⟨b,hb,hb1⟩ := exists_finite_normalizing_precision z h + (fun i => (hz0 i).le) (fun i => (hz1 i).le) hh hh0 + let D := finitePrecisionTail z h b + let v := finiteOverlapIncrement z h b + let Q : Fin (k+1) → ℝ := fun i => 2*h 0*(D 0)^2+(∑ j, v j)-stepTailSum v i + have hD (i : Fin (k+1)) : 0 < D i := finitePrecisionTail_pos z h (fun i => (hz0 i).le) hh hb i + have hv (i : Fin k) : 0 ≤ v i := finiteOverlapIncrement_nonneg z h (fun i => (hz0 i).le) hh hb i + have hQ0 : Q 0=2*h 0*(D 0)^2 := by simp only [Q,stepTailSum_zero]; ring + have hQlast : Q (Fin.last k)=2*h 0*(D 0)^2+∑ j, v j := by simp only [Q,stepTailSum_last,sub_zero] + have hQinc (i : Fin k) : Q i.succ-Q i.castSucc=v i := by + have he := stepTailSum_difference v i + dsimp only [Q] + linarith + have hQmono : Monotone Q := by + apply Fin.monotone_iff_le_succ.mpr + intro i + have he := hQinc i + linarith [hv i] + have hQ0pos : 0 ≤ Q 0 := by rw [hQ0]; positivity + have hnorm : Q (Fin.last k)+D (Fin.last k)=1 := by + rw [hQlast] + exact hb1 + have hQ1 : Q (Fin.last k) < 1 := by linarith [hD (Fin.last k)] + have hgap (i : Fin k) : D i.castSucc-D i.succ=z i*(Q i.succ-Q i.castSucc) := by + rw [hQinc] + exact finitePrecisionTail_gap z h (fun i => (hz0 i).le) hh hb i + let T : Fin (k+1) → ℝ := fun i => weightedStepTail w Q (Q i) + have hTgap (i : Fin k) : T i.castSucc-T i.succ=z i*(Q i.succ-Q i.castSucc) := by + have he := weightedStepTail_affine w Q hQmono i (t := Q i.succ) ⟨hQmono (Fin.castSucc_le_succ i),le_rfl⟩ + change T i.succ=T i.castSucc-z i*(Q i.succ-Q i.castSucc) at he + linarith + have hTlast : T (Fin.last k)=D (Fin.last k) := by + have he := weightedStepTail_of_le w Q hw1 (fun i => hQmono (Fin.le_last i)) + change T (Fin.last k)=1-Q (Fin.last k) at he + linarith + have hconst (i : Fin (k+1)) : T i-D i=T 0-D 0 := by + induction i using Fin.induction with + | zero => rfl + | succ i ih => linarith [hTgap i,hgap i] + have hTD (i : Fin (k+1)) : T i=D i := by + have he := hconst (Fin.last k) + rw [hTlast] at he + linarith [hconst i] + have hroot : 2*h 0=Q 0/(T 0)^2 := by + rw [hTD,hQ0] + have hn : D 0 ≠ 0 := (hD 0).ne' + field_simp [hn] + have hinc (i : Fin k) : 2*(h i.succ-h i.castSucc)=(Q i.succ-Q i.castSucc)/(T i.castSucc*T i.succ) := by + rw [hQinc,hTD,hTD] + change 2*(h i.succ-h i.castSucc)= + (2*(h i.succ-h i.castSucc)*D i.castSucc*D i.succ)/(D i.castSucc*D i.succ) + have hn : D i.castSucc ≠ 0 := (hD i.castSucc).ne' + have hn' : D i.succ ≠ 0 := (hD i.succ).ne' + field_simp [hn,hn'] + have hstat (i : Fin (k+1)) : 2*h i=weightedStepA w Q (Q i) := by + induction i using Fin.induction with + | zero => rw [weightedStepA_root w Q hQmono hQ0pos]; exact hroot + | succ i ih => + have he := weightedStepA_increment w Q (fun i => (hw i).le) hw1 hQmono hQ0pos hQ1 i (hz0 i) + change weightedStepA w Q (Q i.succ)-weightedStepA w Q (Q i.castSucc)= + (Q i.succ-Q i.castSucc)/(T i.castSucc*T i.succ) at he + linarith [hinc i] + let q : Fin (k+1) → Time := fun i => ⟨Q i,⟨hQ0pos.trans (hQmono (Fin.zero_le i)), + ((hQmono (Fin.le_last i)).trans_lt hQ1).le⟩⟩ + exact ⟨q,(fun i j hij => hQmono hij),hQ1,hstat⟩ + +def finiteSphericalDualObjective {k : ℕ} (w h : Fin (k+1) → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) (q : Fin (k+1) → Time) : ℝ := + (entropy (weightedStepTrial w q hw hw1)).toReal-∑ i, w i*h i*(q i:ℝ) + +def finiteSphericalDualValues {k : ℕ} (w h : Fin (k+1) → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i=1) : Set ℝ := + finiteSphericalDualObjective w h hw hw1 '' + {q : Fin (k+1) → Time | Monotone q ∧ (q (Fin.last k):ℝ) < 1} + +theorem finiteSphericalFieldValue_pointwise_dual {k : ℕ} (w h : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i=1) (hh : Monotone h) (hh0 : 0 ≤ h 0) : + ∃ q : Fin (k+1) → Time, Monotone q ∧ (q (Fin.last k):ℝ) < 1 ∧ + IsLeast (finiteSphericalDualValues w h (fun i => (hw i).le) hw1) + (finiteSphericalDualObjective w h (fun i => (hw i).le) hw1 q) ∧ + Tendsto (fun n : ℕ => finiteSphericalFieldValue n k w h) atTop + (𝓝 (sInf (finiteSphericalDualValues w h (fun i => (hw i).le) hw1))) := by + obtain ⟨q,hq,hq1,hs⟩ := exists_finite_stationary_quantile w h hw hw1 hh hh0 + have hleast : IsLeast (finiteSphericalDualValues w h (fun i => (hw i).le) hw1) + (finiteSphericalDualObjective w h (fun i => (hw i).le) hw1 q) := by + refine ⟨⟨q,⟨hq,hq1⟩,rfl⟩,?_⟩ + rintro a ⟨p,⟨hp,hp1⟩,rfl⟩ + exact stationary_finite_entropy_minimizes w h q p (fun i => (hw i).le) hw1 hq hp hq1 hp1 hs + refine ⟨q,hq,hq1,hleast,?_⟩ + rw [hleast.csInf_eq] + exact finiteSphericalFieldValue_stationary w h q hw hw1 hq hq1 hs + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/StepDual.lean b/lean/OAI/Probability/Perceptron/Variational/StepDual.lean new file mode 100644 index 0000000000000000000000000000000000000000..bafe43959eead5d1b2944b26da9f31b14d9ea41d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/StepDual.lean @@ -0,0 +1,194 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StepEntropy + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +lemma finite_weighted_increment_identity (k : ℕ) (a h : Fin (k+1) → ℝ) : + h (Fin.last k)-∑ j, a j*h j = h 0*(1-∑ j, a j)+ + ∑ i : Fin k, (h i.succ-h i.castSucc)*(1-∑ j : Fin (k+1), if i.castSucc < j then a j else 0) := by + classical + induction k with + | zero => simp [Fin.fin_one_eq_zero]; ring + | succ k ih => + have ht := ih (fun j => a j.succ) (fun j => h j.succ) + have hl0 : (∑ j : Fin (k+2), if (0:Fin (k+2)) < j then a j else 0) = + ∑ j : Fin (k+1), a j.succ := by + rw [Fin.sum_univ_succ] + simp only [lt_self_iff_false,ite_false,Fin.succ_pos,ite_true,zero_add] + have hlt (i : Fin k) : (∑ j : Fin (k+2), if i.castSucc.succ < j then a j else 0) = + ∑ j : Fin (k+1), if i.castSucc < j then a j.succ else 0 := by + rw [Fin.sum_univ_succ] + simp only [Fin.not_lt_zero,ite_false,zero_add,Fin.succ_lt_succ_iff] + rw [Fin.sum_univ_succ (fun j => a j*h j),Fin.sum_univ_succ a, + Fin.sum_univ_succ (fun i : Fin (k+1) => + (h i.succ-h i.castSucc)*(1-∑ j : Fin (k+2), if i.castSucc < j then a j else 0))] + simp only [Fin.castSucc_zero,Fin.succ_zero_eq_one,Fin.castSucc_succ] + erw [hl0] + simp only [hlt] + simp only [Fin.succ_last,Fin.succ_zero_eq_one] at ht + linear_combination ht + +lemma weightedStepTail_root {k : ℕ} (w q : Fin (k+1) → ℝ) + (hw1 : ∑ i, w i = 1) (hq : Monotone q) : + weightedStepTail w q (q 0) = 1-∑ i, w i*q i := by + unfold weightedStepTail + simp only [max_eq_left (hq (Fin.zero_le _)),mul_sub,mul_one] + rw [Finset.sum_sub_distrib,hw1] + +lemma weightedStepTail_cut {k : ℕ} (w q : Fin (k+1) → ℝ) + (hw1 : ∑ i, w i = 1) (hq : Monotone q) (i : Fin k) : + weightedStepTail w q (q i.castSucc)+stepCumulative w i*q i.castSucc = + 1-∑ j : Fin (k+1), if i.castSucc < j then w j*q j else 0 := by + unfold weightedStepTail stepCumulative + rw [Finset.sum_mul,← Finset.sum_add_distrib,← hw1,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro j _ + by_cases hj : j ≤ i.castSucc + · rw [ite_eq_left hj,ite_eq_right (not_lt.mpr hj),max_eq_right (hq hj)] + rw [hw1] + ring + · rw [ite_eq_right hj,ite_eq_left (lt_of_not_ge hj),max_eq_left (hq (le_of_not_ge hj))] + rw [hw1] + ring + +lemma finite_sum_successive_differences (k : ℕ) (v : Fin (k+1) → ℝ) : + (∑ i : Fin k, (v i.succ-v i.castSucc)) = v (Fin.last k)-v 0 := by + have h1 := Fin.sum_univ_succ v + have h2 := Fin.sum_univ_castSucc v + rw [Finset.sum_sub_distrib] + linarith + +lemma stationary_field_shift_identity {k : ℕ} (w q h : Fin (k+1) → ℝ) + (hw1 : ∑ i, w i = 1) (hq : Monotone q) + (hD : ∀ i, 0 < weightedStepTail w q (q i)) + (hroot : 2*h 0=q 0/(weightedStepTail w q (q 0))^2) + (hinc : ∀ i : Fin k, 2*(h i.succ-h i.castSucc)= + (q i.succ-q i.castSucc)/(weightedStepTail w q (q i.castSucc)*weightedStepTail w q (q i.succ))) : + 2*(h (Fin.last k)-∑ i, w i*h i*q i) = (weightedStepTail w q (q (Fin.last k)))⁻¹-1 := by + let D := fun i => weightedStepTail w q (q i) + have hgap (i : Fin k) : D i.castSucc-D i.succ = stepCumulative w i*(q i.succ-q i.castSucc) := by + have he := weightedStepTail_affine w q hq i (t := q i.succ) ⟨hq (Fin.castSucc_le_succ i),le_rfl⟩ + change D i.succ = D i.castSucc-stepCumulative w i*(q i.succ-q i.castSucc) at he + linarith + have hroot' : 2*h 0*(1-∑ i, w i*q i) = q 0/D 0 := by + rw [← weightedStepTail_root w q hw1 hq,hroot] + change (q 0/(D 0)^2)*D 0=q 0/D 0 + field_simp [(hD 0).ne'] + have hinc' (i : Fin k) : 2*(h i.succ-h i.castSucc)* + (1-∑ j : Fin (k+1), if i.castSucc < j then w j*q j else 0) = + q i.succ/D i.succ-q i.castSucc/D i.castSucc := by + rw [← weightedStepTail_cut w q hw1 hq i,hinc i] + change ((q i.succ-q i.castSucc)/(D i.castSucc*D i.succ))* + (D i.castSucc+stepCumulative w i*q i.castSucc)=_ + have hg := hgap i + have h1 : D i.castSucc ≠ 0 := (hD i.castSucc).ne' + have h2 : D i.succ ≠ 0 := (hD i.succ).ne' + field_simp [h1,h2] + linear_combination -q i.castSucc * hg + have he := finite_weighted_increment_identity k (fun i => w i*q i) h + have hend : D (Fin.last k) = 1-q (Fin.last k) := + weightedStepTail_of_le w q hw1 (fun i => hq (Fin.le_last i)) + calc + _ = 2*h 0*(1-∑ i, w i*q i)+∑ i : Fin k, + 2*(h i.succ-h i.castSucc)*(1-∑ j : Fin (k+1), if i.castSucc < j then w j*q j else 0) := by + simp only [mul_right_comm (w _) (h _) (q _)] + rw [he,mul_add,Finset.mul_sum] + ring_nf + _ = q 0/D 0+∑ i : Fin k, (q i.succ/D i.succ-q i.castSucc/D i.castSucc) := by + rw [hroot'] + congr 1 + exact Finset.sum_congr rfl (fun i _ => hinc' i) + _ = q (Fin.last k)/D (Fin.last k) := by + rw [finite_sum_successive_differences k (fun i => q i/D i)] + ring + _ = _ := by + change q (Fin.last k)/D (Fin.last k)=(D (Fin.last k))⁻¹-1 + have hn : D (Fin.last k) ≠ 0 := (hD (Fin.last k)).ne' + field_simp [hn] + linarith + +def stepFieldIncrement (k : ℕ) (h : Fin (k+1) → ℝ) (j : ℕ) : ℝ := + if hj : j < k then + Real.sqrt (2*(h (Fin.rev ⟨j,hj⟩).succ-h (Fin.rev ⟨j,hj⟩).castSucc)) else 0 + +lemma stepFieldIncrement_sq (k : ℕ) (h : Fin (k+1) → ℝ) (hh : Monotone h) (i : Fin k) : + (stepFieldIncrement k h (k-1-i.val))^2 = 2*(h i.succ-h i.castSucc) := by + have hi : k-1-i.val < k := by omega + have he : Fin.rev (⟨k-1-i.val,hi⟩ : Fin k) = i := by + apply Fin.ext + simp only [Fin.val_rev] + omega + rw [stepFieldIncrement,dite_eq_left hi,he,Real.sq_sqrt] + exact mul_nonneg (by norm_num) (sub_nonneg.mpr (hh (Fin.castSucc_le_succ i))) + +def finiteSphericalFieldValue (n k : ℕ) (w h : Fin (k+1) → ℝ) : ℝ := + expectedCoordinateSphereLog n k (stepFieldIncrement k h) (stepCumulative w) + (Real.toNNReal (2*h 0))-h (Fin.last k) + +theorem finiteSphericalFieldValue_stationary {k : ℕ} (w h : Fin (k+1) → ℝ) + (q : Fin (k+1) → Time) (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i = 1) + (hq : Monotone q) (hq1 : (q (Fin.last k):ℝ) < 1) + (hstat : ∀ i, 2*h i = weightedStepA w (fun j => (q j:ℝ)) (q i)) : + Tendsto (fun n : ℕ => finiteSphericalFieldValue n k w h) atTop + (𝓝 ((entropy (weightedStepTrial w q (fun i => (hw i).le) hw1)).toReal- + ∑ i, w i*h i*(q i:ℝ))) := by + let Q : Fin (k+1) → ℝ := fun i => q i + let D : Fin (k+1) → ℝ := fun i => weightedStepTail w Q (Q i) + have hm : Monotone Q := fun i j hij => hq hij + have h0 : 0 ≤ Q 0 := (q 0).2.1 + have hmax (i : Fin (k+1)) : Q i ≤ Q (Fin.last k) := hm (Fin.le_last i) + have hD (i : Fin (k+1)) : 0 < D i := + weightedStepTail_pos w Q (fun i => (hw i).le) hw1 hq1 hmax (hmax i) + have hz := stepCumulative_strictMono w hw + have hz0 := stepCumulative_pos w hw + have hz1 := stepCumulative_lt_one w hw hw1 + have hroot : 2*h 0=Q 0/(D 0)^2 := + (hstat 0).trans (weightedStepA_root w Q hm h0) + have hinc (i : Fin k) : 2*(h i.succ-h i.castSucc)= + (Q i.succ-Q i.castSucc)/(D i.castSucc*D i.succ) := by + calc + _ = weightedStepA w Q (Q i.succ)-weightedStepA w Q (Q i.castSucc) := by + linarith [hstat i.succ,hstat i.castSucc] + _ = _ := weightedStepA_increment w Q (fun i => (hw i).le) hw1 hm h0 hq1 i (hz0 i) + have hh : Monotone h := by + apply Fin.monotone_iff_le_succ.mpr + intro i + have hp := div_nonneg (sub_nonneg.mpr (hm (Fin.castSucc_le_succ i))) + (mul_pos (hD i.castSucc) (hD i.succ)).le + rw [← hinc i] at hp + linarith + have hr0 : 0 ≤ 2*h 0 := by rw [hroot]; positivity + have hr : (Real.toNNReal (2*h 0):ℝ)=Q 0/(D 0)^2 := by rw [Real.coe_toNNReal _ hr0,hroot] + have hend : D (Fin.last k) = 1-Q (Fin.last k) := weightedStepTail_of_le w Q hw1 hmax + have hgap (i : Fin k) : D i.castSucc-D i.succ=stepCumulative w i*(Q i.succ-Q i.castSucc) := by + have he := weightedStepTail_affine w Q hm i (t := Q i.succ) ⟨hm (Fin.castSucc_le_succ i),le_rfl⟩ + change D i.succ=D i.castSucc-stepCumulative w i*(Q i.succ-Q i.castSucc) at he + linarith + have hσ (i : Fin k) : (stepFieldIncrement k h (k-1-i.val))^2= + (Q i.succ-Q i.castSucc)/(D i.castSucc*D i.succ) := + (stepFieldIncrement_sq k h hh i).trans (hinc i) + have ht := (expectedCoordinateSphereLog_stationary_data k (stepFieldIncrement k h) + Q D (stepCumulative w) hz hz0 hz1 hD hend hgap hσ _ hr).sub_const (h (Fin.last k)) + have he := entropy_weightedStepTrial_toReal_finite_formula w q (fun i => (hw i).le) hw1 hq hq1 hz0 + simp only [tailIntegral_weightedStepTrial] at he + change (entropy (weightedStepTrial w q (fun i => (hw i).le) hw1)).toReal = + Real.log (D (Fin.last k))/2+stepLogRatios k D (stepCumulative w)+Q 0/(2*D 0) at he + have hs := stationary_field_shift_identity w Q h hw1 hm hD hroot hinc + have hv : Real.log (D (Fin.last k))/2+stepLogRatios k D (stepCumulative w)+Q 0/(2*D 0)+ + ((D (Fin.last k))⁻¹-1)/2-h (Fin.last k) = + (entropy (weightedStepTrial w q (fun i => (hw i).le) hw1)).toReal-∑ i, w i*h i*Q i := by + rw [he] + change 2*(h (Fin.last k)-∑ i, w i*h i*Q i)=(D (Fin.last k))⁻¹-1 at hs + linarith + rw [hv] at ht + exact ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/StepEntropy.lean b/lean/OAI/Probability/Perceptron/Variational/StepEntropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..8dfb028032a1da05a7c4072c7c3a3e87f0a99adb --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/StepEntropy.lean @@ -0,0 +1,469 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.StepStationary + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def weightedStepTrial {I : Type*} [Fintype I] (w : I → ℝ) (q : I → Time) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) : Trial where + toFun := fun t => ∑ i, if q i ≤ t then w i else 0 + monotone := by + intro s t hst + apply Finset.sum_le_sum + intro i _ + by_cases hi : q i ≤ s + · simp only [ite_eq_left hi,ite_eq_left (hi.trans hst),le_refl] + · rw [ite_eq_right hi] + split_ifs <;> first | exact hw i | rfl + measurable := by + apply Finset.measurable_sum + intro i _ + exact measurable_const.ite (measurableSet_le measurable_const measurable_id) measurable_const + nonneg := by + intro t + apply Finset.sum_nonneg + intro i _ + split_ifs <;> first | exact hw i | rfl + le_one := by + intro t + rw [← hw1] + apply Finset.sum_le_sum + intro i _ + split_ifs <;> first | rfl | exact hw i + +lemma timeTail_atom_integral (q t : Time) (w : ℝ) : + (∫ s in Ici t, (if q ≤ s then w else 0) ∂timeLaw) = w*(1-max (q:ℝ) (t:ℝ)) := by + change (∫ s in Ici t, (Ici q).indicator (fun _ => w) s ∂timeLaw) = _ + rw [integral_indicator measurableSet_Ici,Measure.restrict_restrict measurableSet_Ici] + rw [Ici_inter_Ici] + simp only [integral_const,Measure.real,Measure.restrict_apply_univ,timeLaw_eq_volume, + unitInterval.volume_Ici,ENNReal.toReal_ofReal (sub_nonneg.mpr (max q t).2.2),smul_eq_mul] + rcases le_total q t with h | h + · rw [max_eq_right h,max_eq_right (show (q:ℝ) ≤ (t:ℝ) from h)] + ring + · rw [max_eq_left h,max_eq_left (show (t:ℝ) ≤ (q:ℝ) from h)] + ring + +lemma tailIntegral_weightedStepTrial {I : Type*} [Fintype I] (w : I → ℝ) (q : I → Time) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) (t : Time) : + tailIntegral (weightedStepTrial w q hw hw1) t = ∑ i, w i*(1-max (q i:ℝ) (t:ℝ)) := by + unfold tailIntegral + change (∫ s in Ici t, ∑ i, if q i ≤ s then w i else 0 ∂timeLaw) = _ + rw [integral_finsetSum] + · exact Finset.sum_congr rfl (fun i _ => timeTail_atom_integral (q i) t (w i)) + · intro i _ + exact (integrable_const (w i)).indicator measurableSet_Ici + +def weightedStepTail {I : Type*} [Fintype I] (w : I → ℝ) (q : I → ℝ) (t : ℝ) : ℝ := + ∑ i, w i*(1-max (q i) t) + +lemma weightedStepTail_continuous {I : Type*} [Fintype I] (w q : I → ℝ) : + Continuous (weightedStepTail w q) := by + unfold weightedStepTail + fun_prop + +lemma weightedStepTail_lower {I : Type*} [Fintype I] (w q : I → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) {B t : ℝ} + (hq : ∀ i, q i ≤ B) (ht : t ≤ B) : + 1-B ≤ weightedStepTail w q t := by + calc + 1-B = ∑ i, w i*(1-B) := by rw [← Finset.sum_mul,hw1,one_mul] + _ ≤ _ := Finset.sum_le_sum fun i _ => + mul_le_mul_of_nonneg_left (sub_le_sub_left (max_le (hq i) ht) 1) (hw i) + +lemma weightedStepTail_upper {I : Type*} [Fintype I] (w q : I → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) (t : ℝ) : + weightedStepTail w q t ≤ 1-t := by + calc + _ ≤ ∑ i, w i*(1-t) := Finset.sum_le_sum fun i _ => + mul_le_mul_of_nonneg_left (sub_le_sub_left (le_max_right (q i) t) 1) (hw i) + _ = _ := by rw [← Finset.sum_mul,hw1,one_mul] + +lemma weightedStepTail_of_le {I : Type*} [Fintype I] (w q : I → ℝ) + (hw1 : ∑ i, w i = 1) {t : ℝ} (hq : ∀ i, q i ≤ t) : + weightedStepTail w q t = 1-t := by + simp only [weightedStepTail,max_eq_right (hq _)] + rw [← Finset.sum_mul,hw1,one_mul] + +lemma weightedStepTail_pos {I : Type*} [Fintype I] (w q : I → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) {B t : ℝ} + (hB : B < 1) (hq : ∀ i, q i ≤ B) (ht : t ≤ B) : + 0 < weightedStepTail w q t := + (sub_pos.mpr hB).trans_le (weightedStepTail_lower w q hw hw1 hq ht) + +lemma weightedStepTail_inv_continuousOn {I : Type*} [Fintype I] (w q : I → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) {B : ℝ} + (hB : B < 1) (hq : ∀ i, q i ≤ B) : + ContinuousOn (fun t => (weightedStepTail w q t)⁻¹) (Icc 0 B) := + (weightedStepTail_continuous w q).continuousOn.inv₀ + (fun _ ht => (weightedStepTail_pos w q hw hw1 hB hq ht.2).ne') + +lemma integral_one_sub_inv {B : ℝ} (hB : B < 1) : + (∫ t in (0:ℝ)..B, (1-t)⁻¹) = -Real.log (1-B) := by + rw [intervalIntegral.integral_comp_sub_left (fun t : ℝ => t⁻¹) 1] + simp only [sub_zero] + rw [integral_inv_of_pos (sub_pos.mpr hB) zero_lt_one,one_div,Real.log_inv] + +theorem entropy_weightedStepTrial {I : Type*} [Fintype I] (w : I → ℝ) (q : I → Time) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) (B : ℝ) (hB0 : 0 ≤ B) (hB1 : B < 1) + (hq : ∀ i, (q i : ℝ) ≤ B) : + entropy (weightedStepTrial w q hw hw1) = ENNReal.ofReal + (((∫ t in (0:ℝ)..B, (weightedStepTail w (fun i => (q i:ℝ)) t)⁻¹)+Real.log (1-B))/2) := by + let D := weightedStepTail w (fun i => (q i:ℝ)) + let F : ℝ → ℝ := fun t => (D t)⁻¹-(1-t)⁻¹ + have hD (t : ℝ) (ht : t ≤ B) : 0 < D t := weightedStepTail_pos _ _ hw hw1 hB1 hq ht + have hF : ContinuousOn F (Icc 0 B) := + (weightedStepTail_inv_continuousOn _ _ hw hw1 hB1 hq).sub + ((continuous_const.sub continuous_id).continuousOn.inv₀ (fun t ht => by + have : t < 1 := ht.2.trans_lt hB1 + exact (sub_pos.mpr this).ne')) + have hF0 : ∀ t ∈ Icc 0 B, 0 ≤ F t := by + intro t ht + exact sub_nonneg.mpr (inv_le_inv₀ (sub_pos.mpr (ht.2.trans_lt hB1)) (hD t ht.2) |>.mpr + (weightedStepTail_upper _ _ hw hw1 t)) + have he (t : Time) : (ENNReal.ofReal (tailIntegral (weightedStepTrial w q hw hw1) t))⁻¹- + (ENNReal.ofReal (1-(t:ℝ)))⁻¹ = (Iic B).indicator (fun t => ENNReal.ofReal (F t)) (t:ℝ) := by + rw [tailIntegral_weightedStepTrial] + change (ENNReal.ofReal (D (t:ℝ)))⁻¹-_ = _ + by_cases ht : (t:ℝ) ≤ B + · rw [Set.indicator_of_mem (show (t:ℝ) ∈ Iic B from ht)] + dsimp [F] + rw [ENNReal.ofReal_sub _ (inv_nonneg.mpr (sub_nonneg.mpr t.2.2)), + ENNReal.ofReal_inv_of_pos (hD t ht), + ENNReal.ofReal_inv_of_pos (sub_pos.mpr (ht.trans_lt hB1))] + · rw [Set.indicator_of_notMem (show (t:ℝ) ∉ Iic B from ht)] + have hd : D (t:ℝ) = 1-(t:ℝ) := weightedStepTail_of_le _ _ hw1 + (fun i => (hq i).trans (le_of_not_ge ht)) + rw [hd,tsub_self] + have hset : Iic B ∩ Icc (0:ℝ) 1 = Icc 0 B := by + ext t + constructor + · rintro ⟨ht,h0,h1⟩ + exact ⟨h0,ht⟩ + · rintro ⟨h0,ht⟩ + exact ⟨ht,h0,ht.trans hB1.le⟩ + have hel : (∫⁻ t : Time, (ENNReal.ofReal (tailIntegral (weightedStepTrial w q hw hw1) t))⁻¹- + (ENNReal.ofReal (1-(t:ℝ)))⁻¹ ∂timeLaw) = ENNReal.ofReal (∫ t in Icc 0 B, F t) := by + rw [lintegral_congr he] + change (∫⁻ t : Icc (0:ℝ) 1, (Iic B).indicator (fun t => ENNReal.ofReal (F t)) t.val + ∂Measure.comap Subtype.val volume) = _ + rw [lintegral_subtype_comap measurableSet_Icc,lintegral_indicator measurableSet_Iic, + Measure.restrict_restrict measurableSet_Iic,hset] + exact (ofReal_integral_eq_lintegral_ofReal hF.integrableOn_Icc + ((ae_restrict_mem measurableSet_Icc).mono (fun t ht => hF0 t ht))).symm + have hInt : (∫ t in Icc 0 B, F t) = (∫ t in (0:ℝ)..B, (D t)⁻¹)+Real.log (1-B) := by + rw [integral_Icc_eq_integral_Ioc,← intervalIntegral.integral_of_le hB0] + have hiD : IntervalIntegrable (fun t => (D t)⁻¹) volume 0 B := + (weightedStepTail_inv_continuousOn _ _ hw hw1 hB1 hq).intervalIntegrable_of_Icc hB0 + have hiR : IntervalIntegrable (fun t : ℝ => (1-t)⁻¹) volume 0 B := + ((continuous_const.sub continuous_id).continuousOn.inv₀ (fun t (ht : t ∈ Icc (0:ℝ) B) => + (sub_pos.mpr (ht.2.trans_lt hB1)).ne')).intervalIntegrable_of_Icc hB0 + rw [show F = (fun t => (D t)⁻¹-(1-t)⁻¹) from rfl, + intervalIntegral.integral_sub hiD hiR,integral_one_sub_inv hB1,sub_neg_eq_add] + rw [entropy,hel,hInt,ENNReal.ofReal_div_of_pos (by norm_num : (0:ℝ)<2)] + norm_num + rfl + +def stepCumulative {k : ℕ} (w : Fin (k+1) → ℝ) (i : Fin k) : ℝ := + ∑ j : Fin (k+1), if j ≤ i.castSucc then w j else 0 + +lemma weightedStepTail_affine {k : ℕ} (w q : Fin (k+1) → ℝ) (hq : Monotone q) + (i : Fin k) {t : ℝ} (ht : t ∈ Icc (q i.castSucc) (q i.succ)) : + weightedStepTail w q t = weightedStepTail w q (q i.castSucc)- + stepCumulative w i*(t-q i.castSucc) := by + unfold weightedStepTail stepCumulative + rw [Finset.sum_mul,← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro j _ + by_cases hj : j ≤ i.castSucc + · rw [ite_eq_left hj,max_eq_right ((hq hj).trans ht.1),max_eq_right (hq hj)] + ring + · have hj' : i.succ ≤ j := by exact Fin.le_iff_val_le_val.mpr (by + have hh := Fin.lt_def.mp (lt_of_not_ge hj) + simp only [Fin.val_castSucc,Fin.val_succ] at * + omega) + rw [ite_eq_right hj,max_eq_left (ht.2.trans (hq hj')),max_eq_left + ((hq (Fin.castSucc_le_succ i)).trans (hq hj'))] + ring + +lemma weightedStepTail_below_min {I : Type*} [Fintype I] (w q : I → ℝ) + {a t : ℝ} (hq : ∀ i, a ≤ q i) (ht : t ≤ a) : + weightedStepTail w q t = weightedStepTail w q a := by + apply Finset.sum_congr rfl + intro i _ + rw [max_eq_left (ht.trans (hq i)),max_eq_left (hq i)] + +lemma affine_pos_on {A B a b z : ℝ} (_hab : a ≤ b) (hB : 0 < B) (hz : 0 < z) + (hrel : A-z*(b-a)=B) {x : ℝ} (hx : x ∈ Icc a b) : 0 < A-z*(x-a) := by + have hm := mul_le_mul_of_nonneg_left (sub_le_sub_right hx.2 a) hz.le + linarith + +lemma integral_positive_affine_inv {A B a b z : ℝ} (hab : a ≤ b) (_hA : 0 < A) + (hB : 0 < B) (hz : 0 < z) (hrel : A-z*(b-a)=B) : + (∫ x in a..b, (A-z*(x-a))⁻¹) = (Real.log A-Real.log B)/z := by + have hd (x : ℝ) (hx : x ∈ Icc a b) : + HasDerivAt (fun x => -(Real.log (A-z*(x-a)))/z) (A-z*(x-a))⁻¹ x := by + have hd := (((hasDerivAt_id x).sub_const a).const_mul z).const_sub A + have he := ((hd.log (affine_pos_on hab hB hz hrel hx).ne').neg).div_const z + have hv : -(-(z*1)/(A-z*(id x-a)))/z = (A-z*(x-a))⁻¹ := by + dsimp only [id_eq] + field_simp [hz.ne',(affine_pos_on hab hB hz hrel hx).ne'] + rw [hv] at he + exact he + have hi : IntervalIntegrable (fun x => (A-z*(x-a))⁻¹) volume a b := + ((continuous_const.sub (continuous_const.mul (continuous_id.sub continuous_const))).continuousOn.inv₀ + (fun x hx => (affine_pos_on hab hB hz hrel hx).ne')).intervalIntegrable_of_Icc hab + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun x hx => hd x (by simpa only [uIcc_of_le hab] using hx)) hi] + rw [hrel] + simp only [sub_self,mul_zero,sub_zero] + ring + +lemma integral_positive_affine_inv_sq {A B a b z : ℝ} (hab : a ≤ b) (hA : 0 < A) + (hB : 0 < B) (hz : 0 < z) (hrel : A-z*(b-a)=B) : + (∫ x in a..b, 1/(A-z*(x-a))^2) = (b-a)/(A*B) := by + have hd (x : ℝ) (hx : x ∈ Icc a b) : + HasDerivAt (fun x => (A-z*(x-a))⁻¹/z) (1/(A-z*(x-a))^2) x := by + have hd := (((hasDerivAt_id x).sub_const a).const_mul z).const_sub A + have he := (hd.inv (affine_pos_on hab hB hz hrel hx).ne').div_const z + have hv : (- -(z*1)/(A-z*(id x-a))^2)/z = 1/(A-z*(x-a))^2 := by + dsimp only [id_eq] + field_simp [hz.ne',(affine_pos_on hab hB hz hrel hx).ne'] + rw [hv] at he + exact he + have hi : IntervalIntegrable (fun x => 1/(A-z*(x-a))^2) volume a b := by + have hc : ContinuousOn (fun x => (A-z*(x-a))⁻¹) (Icc a b) := + (continuous_const.sub (continuous_const.mul (continuous_id.sub continuous_const))).continuousOn.inv₀ + (fun x hx => (affine_pos_on hab hB hz hrel hx).ne') + have hh := (hc.pow 2).intervalIntegrable_of_Icc (μ := volume) hab + change IntervalIntegrable (fun x => ((A-z*(x-a))⁻¹)^2) volume a b at hh + simpa only [one_div,inv_pow] using hh + rw [intervalIntegral.integral_eq_sub_of_hasDerivAt + (fun x hx => hd x (by simpa only [uIcc_of_le hab] using hx)) hi] + rw [hrel] + simp only [sub_self,mul_zero,sub_zero] + have hAn := hA.ne' + have hBn := hB.ne' + have hzn := hz.ne' + field_simp + nlinarith + +lemma integral_eq_stepLogRatios (k : ℕ) (F : ℝ → ℝ) (q D : Fin (k+1) → ℝ) + (z : Fin k → ℝ) (hq : Monotone q) (hc : ContinuousOn F (Icc (q 0) (q (Fin.last k)))) + (hseg : ∀ i : Fin k, (∫ x in q i.castSucc..q i.succ, F x) = + (Real.log (D i.castSucc)-Real.log (D i.succ))/z i) : + (∫ x in q 0..q (Fin.last k), F x) = 2*stepLogRatios k D z := by + induction k with + | zero => simp [stepLogRatios,Fin.fin_one_eq_zero] + | succ k ih => + have h01 : q 0 ≤ q 1 := hq (Fin.zero_le _) + have h1t : q 1 ≤ q (Fin.last (k+1)) := hq (Fin.le_last 1) + have hct : ContinuousOn F (Icc ((fun i : Fin (k+1) => q i.succ) 0) + ((fun i : Fin (k+1) => q i.succ) (Fin.last k))) := by + exact hc.mono (Icc_subset_Icc h01 le_rfl) + have ht := ih (fun i => q i.succ) (fun i => D i.succ) (fun i => z i.succ) + (fun a b hab => hq (Fin.succ_le_succ_iff.mpr hab)) hct + (fun i => by simpa only [Fin.castSucc_succ] using hseg i.succ) + simp only [Fin.succ_zero_eq_one,Fin.succ_last] at ht + have h0 := hseg 0 + simp only [Fin.castSucc_zero,Fin.succ_zero_eq_one] at h0 + rw [← intervalIntegral.integral_add_adjacent_intervals + ((hc.mono (Icc_subset_Icc le_rfl h1t)).intervalIntegrable_of_Icc h01) + ((hc.mono (Icc_subset_Icc h01 le_rfl)).intervalIntegrable_of_Icc h1t),h0,ht, + stepLogRatios] + ring + +lemma weightedStep_integral_inv {k : ℕ} (w q : Fin (k+1) → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) (hq : Monotone q) + (hq0 : 0 ≤ q 0) (hq1 : q (Fin.last k) < 1) (hz : ∀ i, 0 < stepCumulative w i) : + (∫ t in (0:ℝ)..q (Fin.last k), (weightedStepTail w q t)⁻¹) = + q 0/weightedStepTail w q (q 0)+ + 2*stepLogRatios k (fun i => weightedStepTail w q (q i)) (stepCumulative w) := by + let D := weightedStepTail w q + have hqi (i : Fin (k+1)) : q i ≤ q (Fin.last k) := hq (Fin.le_last i) + have hD (i : Fin (k+1)) : 0 < D (q i) := weightedStepTail_pos _ _ hw hw1 hq1 hqi (hqi i) + have hc := weightedStepTail_inv_continuousOn w q hw hw1 hq1 hqi + have h0t : q 0 ≤ q (Fin.last k) := hqi 0 + have hseg (i : Fin k) : (∫ x in q i.castSucc..q i.succ, (D x)⁻¹) = + (Real.log (D (q i.castSucc))-Real.log (D (q i.succ)))/stepCumulative w i := by + have hab : q i.castSucc ≤ q i.succ := hq (Fin.castSucc_le_succ i) + have he := weightedStepTail_affine w q hq i (t := q i.succ) ⟨hab,le_rfl⟩ + calc + _ = ∫ x in q i.castSucc..q i.succ, + (D (q i.castSucc)-stepCumulative w i*(x-q i.castSucc))⁻¹ := by + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hab] at ht + dsimp only + rw [show D t = _ from weightedStepTail_affine w q hq i ht] + _ = _ := integral_positive_affine_inv hab (hD i.castSucc) (hD i.succ) (hz i) he.symm + have htail := integral_eq_stepLogRatios k (fun t => (D t)⁻¹) q + (fun i => D (q i)) (stepCumulative w) hq (hc.mono (Icc_subset_Icc hq0 le_rfl)) hseg + have hroot : (∫ t in (0:ℝ)..q 0, (D t)⁻¹) = q 0/D (q 0) := by + calc + _ = ∫ _t in (0:ℝ)..q 0, (D (q 0))⁻¹ := by + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hq0] at ht + dsimp only + rw [show D t = D (q 0) from weightedStepTail_below_min w q (fun i => hq (Fin.zero_le i)) ht.2] + _ = _ := by simp [div_eq_mul_inv] + rw [← intervalIntegral.integral_add_adjacent_intervals + ((hc.mono (Icc_subset_Icc le_rfl h0t)).intervalIntegrable_of_Icc hq0) + ((hc.mono (Icc_subset_Icc hq0 le_rfl)).intervalIntegrable_of_Icc h0t),hroot,htail] + +theorem entropy_weightedStepTrial_finite_formula {k : ℕ} (w : Fin (k+1) → ℝ) + (q : Fin (k+1) → Time) (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) + (hq : Monotone q) (hq1 : (q (Fin.last k):ℝ) < 1) + (hz : ∀ i, 0 < stepCumulative w i) : + entropy (weightedStepTrial w q hw hw1) = ENNReal.ofReal + (Real.log (tailIntegral (weightedStepTrial w q hw hw1) (q (Fin.last k)))/2+ + stepLogRatios k (fun i => tailIntegral (weightedStepTrial w q hw hw1) (q i)) (stepCumulative w)+ + (q 0:ℝ)/(2*tailIntegral (weightedStepTrial w q hw hw1) (q 0))) := by + have hqr : Monotone (fun i => (q i:ℝ)) := fun i j hij => hq hij + have hqmax (i : Fin (k+1)) : (q i:ℝ) ≤ (q (Fin.last k):ℝ) := hqr (Fin.le_last i) + rw [entropy_weightedStepTrial w q hw hw1 (q (Fin.last k)) (q (Fin.last k)).2.1 hq1 hqmax, + weightedStep_integral_inv w (fun i => (q i:ℝ)) hw hw1 hqr (q 0).2.1 hq1 hz] + simp only [tailIntegral_weightedStepTrial] + change ENNReal.ofReal _ = ENNReal.ofReal + (Real.log (weightedStepTail w (fun i => (q i:ℝ)) (q (Fin.last k)))/2+ + stepLogRatios k (fun i => weightedStepTail w (fun i => (q i:ℝ)) (q i)) (stepCumulative w)+ + (q 0:ℝ)/(2*weightedStepTail w (fun i => (q i:ℝ)) (q 0))) + rw [weightedStepTail_of_le w (fun i => (q i:ℝ)) hw1 hqmax] + congr 1 + ring + +def weightedStepA {I : Type*} [Fintype I] (w q : I → ℝ) (r : ℝ) : ℝ := + ∫ t in (0:ℝ)..r, 1/(weightedStepTail w q t)^2 + +lemma weightedStepA_root {k : ℕ} (w q : Fin (k+1) → ℝ) + (hq : Monotone q) (hq0 : 0 ≤ q 0) : + weightedStepA w q (q 0) = q 0/(weightedStepTail w q (q 0))^2 := by + unfold weightedStepA + calc + _ = ∫ _t in (0:ℝ)..q 0, 1/(weightedStepTail w q (q 0))^2 := by + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hq0] at ht + dsimp only + rw [weightedStepTail_below_min w q (fun i => hq (Fin.zero_le i)) ht.2] + _ = _ := by simp [div_eq_mul_inv] + +lemma weightedStepA_increment {k : ℕ} (w q : Fin (k+1) → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) (hq : Monotone q) + (hq0 : 0 ≤ q 0) (hq1 : q (Fin.last k) < 1) (i : Fin k) (hz : 0 < stepCumulative w i) : + weightedStepA w q (q i.succ)-weightedStepA w q (q i.castSucc) = + (q i.succ-q i.castSucc)/(weightedStepTail w q (q i.castSucc)*weightedStepTail w q (q i.succ)) := by + let D := weightedStepTail w q + have hqi (i : Fin (k+1)) : q i ≤ q (Fin.last k) := hq (Fin.le_last i) + have hD (i : Fin (k+1)) : 0 < D (q i) := weightedStepTail_pos _ _ hw hw1 hq1 hqi (hqi i) + have hc : ContinuousOn (fun t => 1/(D t)^2) (Icc 0 (q (Fin.last k))) := by + have hh := (weightedStepTail_inv_continuousOn w q hw hw1 hq1 hqi).pow 2 + change ContinuousOn (fun t => ((D t)⁻¹)^2) _ at hh + simpa only [one_div,inv_pow] using hh + have h0i : 0 ≤ q i.castSucc := hq0.trans (hq (Fin.zero_le _)) + have hij : q i.castSucc ≤ q i.succ := hq (Fin.castSucc_le_succ i) + have hi := (hc.mono (Icc_subset_Icc le_rfl (hqi i.castSucc))).intervalIntegrable_of_Icc (μ := volume) h0i + have hj := (hc.mono (Icc_subset_Icc h0i (hqi i.succ))).intervalIntegrable_of_Icc (μ := volume) hij + have ha := intervalIntegral.integral_add_adjacent_intervals hi hj + have hseg : (∫ t in q i.castSucc..q i.succ, 1/(D t)^2) = + (q i.succ-q i.castSucc)/(D (q i.castSucc)*D (q i.succ)) := by + have he := weightedStepTail_affine w q hq i (t := q i.succ) ⟨hij,le_rfl⟩ + calc + _ = ∫ t in q i.castSucc..q i.succ, + 1/(D (q i.castSucc)-stepCumulative w i*(t-q i.castSucc))^2 := by + apply intervalIntegral.integral_congr + intro t ht + rw [uIcc_of_le hij] at ht + dsimp only + rw [show D t = _ from weightedStepTail_affine w q hq i ht] + _ = _ := integral_positive_affine_inv_sq hij (hD i.castSucc) (hD i.succ) hz he.symm + change (∫ t in (0:ℝ)..q i.succ, 1/(D t)^2)- + (∫ t in (0:ℝ)..q i.castSucc, 1/(D t)^2) = _ + rw [← ha,hseg] + ring + +lemma weightedStep_truncated_entropy_nonneg {I : Type*} [Fintype I] (w q : I → ℝ) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) {B : ℝ} (hB0 : 0 ≤ B) (hB1 : B < 1) + (hq : ∀ i, q i ≤ B) : + 0 ≤ ((∫ t in (0:ℝ)..B, (weightedStepTail w q t)⁻¹)+Real.log (1-B))/2 := by + have hiD := (weightedStepTail_inv_continuousOn w q hw hw1 hB1 hq).intervalIntegrable_of_Icc (μ := volume) hB0 + have hiR : IntervalIntegrable (fun t : ℝ => (1-t)⁻¹) volume 0 B := + ((continuous_const.sub continuous_id).continuousOn.inv₀ + (fun t (ht : t ∈ Icc (0:ℝ) B) => (sub_pos.mpr (ht.2.trans_lt hB1)).ne')).intervalIntegrable_of_Icc hB0 + have hle := intervalIntegral.integral_mono_on hB0 hiR hiD (fun t ht => + (inv_le_inv₀ (sub_pos.mpr (ht.2.trans_lt hB1)) + (weightedStepTail_pos w q hw hw1 hB1 hq ht.2)).mpr + (weightedStepTail_upper w q hw hw1 t)) + rw [integral_one_sub_inv hB1] at hle + linarith + +lemma entropy_weightedStepTrial_toReal {I : Type*} [Fintype I] (w : I → ℝ) (q : I → Time) + (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) (B : ℝ) (hB0 : 0 ≤ B) (hB1 : B < 1) + (hq : ∀ i, (q i : ℝ) ≤ B) : + (entropy (weightedStepTrial w q hw hw1)).toReal = + ((∫ t in (0:ℝ)..B, (weightedStepTail w (fun i => (q i:ℝ)) t)⁻¹)+Real.log (1-B))/2 := by + rw [entropy_weightedStepTrial w q hw hw1 B hB0 hB1 hq,ENNReal.toReal_ofReal + (weightedStep_truncated_entropy_nonneg w (fun i => (q i:ℝ)) hw hw1 hB0 hB1 hq)] + +lemma entropy_weightedStepTrial_toReal_finite_formula {k : ℕ} (w : Fin (k+1) → ℝ) + (q : Fin (k+1) → Time) (hw : ∀ i, 0 ≤ w i) (hw1 : ∑ i, w i = 1) + (hq : Monotone q) (hq1 : (q (Fin.last k):ℝ) < 1) + (hz : ∀ i, 0 < stepCumulative w i) : + (entropy (weightedStepTrial w q hw hw1)).toReal = + Real.log (tailIntegral (weightedStepTrial w q hw hw1) (q (Fin.last k)))/2+ + stepLogRatios k (fun i => tailIntegral (weightedStepTrial w q hw hw1) (q i)) (stepCumulative w)+ + (q 0:ℝ)/(2*tailIntegral (weightedStepTrial w q hw hw1) (q 0)) := by + have hqr : Monotone (fun i => (q i:ℝ)) := fun i j hij => hq hij + have hqmax (i : Fin (k+1)) : (q i:ℝ) ≤ (q (Fin.last k):ℝ) := hqr (Fin.le_last i) + rw [entropy_weightedStepTrial_toReal w q hw hw1 (q (Fin.last k)) (q (Fin.last k)).2.1 hq1 hqmax, + weightedStep_integral_inv w (fun i => (q i:ℝ)) hw hw1 hqr (q 0).2.1 hq1 hz] + simp only [tailIntegral_weightedStepTrial] + change _ = Real.log (weightedStepTail w (fun i => (q i:ℝ)) (q (Fin.last k)))/2+ + stepLogRatios k (fun i => weightedStepTail w (fun i => (q i:ℝ)) (q i)) (stepCumulative w)+ + (q 0:ℝ)/(2*weightedStepTail w (fun i => (q i:ℝ)) (q 0)) + rw [weightedStepTail_of_le w (fun i => (q i:ℝ)) hw1 hqmax] + ring + +lemma stepCumulative_pos {k : ℕ} (w : Fin (k+1) → ℝ) (hw : ∀ i, 0 < w i) (i : Fin k) : + 0 < stepCumulative w i := by + apply Finset.sum_pos' + · intro j _ + split_ifs <;> first | exact (hw j).le | rfl + · exact ⟨0,Finset.mem_univ _,by simpa only [ite_eq_left (Fin.zero_le _)] using hw 0⟩ + +lemma stepCumulative_lt_one {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) (hw1 : ∑ i, w i = 1) (i : Fin k) : + stepCumulative w i < 1 := by + rw [← hw1] + apply Finset.sum_lt_sum + · intro j _ + split_ifs <;> first | rfl | exact (hw j).le + · refine ⟨Fin.last k,Finset.mem_univ _,?_⟩ + have hnot : ¬Fin.last k ≤ i.castSucc := by + simp only [Fin.le_iff_val_le_val,Fin.val_last,Fin.val_castSucc] + omega + simpa only [ite_eq_right hnot] using hw (Fin.last k) + +lemma stepCumulative_strictMono {k : ℕ} (w : Fin (k+1) → ℝ) + (hw : ∀ i, 0 < w i) : StrictMono (stepCumulative w) := by + intro i j hij + apply Finset.sum_lt_sum + · intro a _ + by_cases hai : a ≤ i.castSucc + · have haj : a ≤ j.castSucc := hai.trans (Fin.castSucc_le_castSucc_iff.mpr hij.le) + simp only [ite_eq_left hai,ite_eq_left haj,le_refl] + · simp only [ite_eq_right hai] + split_ifs <;> first | exact (hw a).le | rfl + · refine ⟨j.castSucc,Finset.mem_univ _,?_⟩ + have hnot : ¬j.castSucc ≤ i.castSucc := by simpa only [Fin.castSucc_le_castSucc_iff] using not_le.mpr hij + simpa only [ite_eq_right hnot,ite_eq_left le_rfl] using hw j.castSucc + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/StepStationary.lean b/lean/OAI/Probability/Perceptron/Variational/StepStationary.lean new file mode 100644 index 0000000000000000000000000000000000000000..ba2e4d9f55fad539e831e40007e61b834182674d --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/StepStationary.lean @@ -0,0 +1,140 @@ +import Mathlib +import OAI.Probability.Perceptron.Sphere.SphereLimit + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +def stepLogRatios : (k : ℕ) → (Fin (k+1) → ℝ) → (Fin k → ℝ) → ℝ + | 0, _, _ => 0 + | k+1, D, z => stepLogRatios k (fun i => D i.succ) (fun i => z i.succ)+ + (Real.log (D 0)-Real.log (D 1))/(2*z 0) + +lemma quadraticCascadePrecision_stationary (k : ℕ) (σ : ℕ → ℝ) + (q D : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hD : ∀ i, 0 < D i) + (hgap : ∀ i : Fin k, D i.castSucc-D i.succ=z i*(q i.succ-q i.castSucc)) + (hσ : ∀ i : Fin k, (σ (k-1-i.val))^2=(q i.succ-q i.castSucc)/(D i.castSucc*D i.succ)) : + quadraticCascadePrecision σ (D (Fin.last k))⁻¹ k z = (D 0)⁻¹ := by + induction k with + | zero => simp [quadraticCascadePrecision,Fin.fin_one_eq_zero] + | succ k ih => + have ht := ih (fun i => q i.succ) (fun i => D i.succ) (fun i => z i.succ) + (fun i => hD i.succ) (fun i => hgap i.succ) (fun i => by + have hs := hσ i.succ + have he : k+1-1-(i.succ).val=k-1-i.val := by simp only [Fin.val_succ]; omega + simpa only [he,Fin.castSucc_succ] using hs) + simp only [Fin.succ_last,Fin.succ_zero_eq_one] at ht + have hs := hσ 0 + simp only [Fin.val_zero,Nat.add_sub_cancel,Nat.sub_zero,Fin.castSucc_zero,Fin.succ_zero_eq_one] at hs + have hg := hgap 0 + simp only [Fin.castSucc_zero,Fin.succ_zero_eq_one] at hg + dsimp only [quadraticCascadePrecision] + rw [ht,hs] + have h0 := (hD 0).ne' + have h1 := (hD 1).ne' + field_simp + nlinarith + +lemma quadraticCascadeReciprocalSlope_stationary (k : ℕ) (σ : ℕ → ℝ) + (q D : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hD : ∀ i, 0 < D i) (hz : ∀ i, 0 < z i) + (hgap : ∀ i : Fin k, D i.castSucc-D i.succ=z i*(q i.succ-q i.castSucc)) + (hσ : ∀ i : Fin k, (σ (k-1-i.val))^2=(q i.succ-q i.castSucc)/(D i.castSucc*D i.succ)) : + quadraticCascadeReciprocalSlope σ (D (Fin.last k))⁻¹ k z = -(q (Fin.last k)-q 0)/2 := by + induction k with + | zero => simp [quadraticCascadeReciprocalSlope,Fin.fin_one_eq_zero] + | succ k ih => + have hst : ∀ i : Fin k, (σ (k-1-i.val))^2 = + (q i.succ.succ-q i.castSucc.succ)/(D i.castSucc.succ*D i.succ.succ) := by + intro i + have hs := hσ i.succ + have he : k+1-1-(i.succ).val=k-1-i.val := by simp only [Fin.val_succ]; omega + simpa only [he,Fin.castSucc_succ] using hs + have ht := ih (fun i => q i.succ) (fun i => D i.succ) (fun i => z i.succ) + (fun i => hD i.succ) (fun i => hz i.succ) (fun i => hgap i.succ) hst + have hp := quadraticCascadePrecision_stationary (k+1) σ q D z hD hgap hσ + have hpt := quadraticCascadePrecision_stationary k σ (fun i => q i.succ) + (fun i => D i.succ) (fun i => z i.succ) (fun i => hD i.succ) (fun i => hgap i.succ) hst + simp only [Fin.succ_last,Fin.succ_zero_eq_one] at ht hpt + have hg := hgap 0 + simp only [Fin.castSucc_zero,Fin.succ_zero_eq_one] at hg + rw [quadraticCascadeReciprocalSlope,ht,hp,hpt] + simp only [one_div,inv_inv] + have hz0 := (hz 0).ne' + field_simp + nlinarith + +lemma quadraticCascadeOffset_stationary (k : ℕ) (σ : ℕ → ℝ) + (q D : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hD : ∀ i, 0 < D i) + (hgap : ∀ i : Fin k, D i.castSucc-D i.succ=z i*(q i.succ-q i.castSucc)) + (hσ : ∀ i : Fin k, (σ (k-1-i.val))^2=(q i.succ-q i.castSucc)/(D i.castSucc*D i.succ)) : + quadraticCascadeOffset σ (D (Fin.last k))⁻¹ k z = stepLogRatios k D z := by + induction k with + | zero => rfl + | succ k ih => + have hst : ∀ i : Fin k, (σ (k-1-i.val))^2 = + (q i.succ.succ-q i.castSucc.succ)/(D i.castSucc.succ*D i.succ.succ) := by + intro i + have hs := hσ i.succ + have he : k+1-1-(i.succ).val=k-1-i.val := by simp only [Fin.val_succ]; omega + simpa only [he,Fin.castSucc_succ] using hs + have ht := ih (fun i => q i.succ) (fun i => D i.succ) (fun i => z i.succ) + (fun i => hD i.succ) (fun i => hgap i.succ) hst + have hp := quadraticCascadePrecision_stationary (k+1) σ q D z hD hgap hσ + have hpt := quadraticCascadePrecision_stationary k σ (fun i => q i.succ) + (fun i => D i.succ) (fun i => z i.succ) (fun i => hD i.succ) (fun i => hgap i.succ) hst + simp only [Fin.succ_last,Fin.succ_zero_eq_one] at ht hpt + rw [quadraticCascadeOffset,ht,hp,hpt,stepLogRatios] + simp only [Real.log_inv] + ring + +lemma canonicalGaussianFreeValue_stationary (k : ℕ) (σ : ℕ → ℝ) + (q D : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hD : ∀ i, 0 < D i) + (hgap : ∀ i : Fin k, D i.castSucc-D i.succ=z i*(q i.succ-q i.castSucc)) + (hσ : ∀ i : Fin k, (σ (k-1-i.val))^2=(q i.succ-q i.castSucc)/(D i.castSucc*D i.succ)) : + canonicalGaussianFreeValue σ k z (q 0/(D 0)^2) (D (Fin.last k))⁻¹ = + Real.log (D (Fin.last k))/2+stepLogRatios k D z+q 0/(2*D 0) := by + rw [canonicalGaussianFreeValue,quadraticCascadePrecision_stationary k σ q D z hD hgap hσ, + quadraticCascadeOffset_stationary k σ q D z hD hgap hσ,Real.log_inv] + have h0 := (hD 0).ne' + field_simp + +lemma canonicalGaussianFreeValue_stationarity (k : ℕ) (σ : ℕ → ℝ) + (q D : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hD : ∀ i, 0 < D i) (hz : ∀ i, 0 < z i) + (hend : D (Fin.last k)=1-q (Fin.last k)) + (hgap : ∀ i : Fin k, D i.castSucc-D i.succ=z i*(q i.succ-q i.castSucc)) + (hσ : ∀ i : Fin k, (σ (k-1-i.val))^2=(q i.succ-q i.castSucc)/(D i.castSucc*D i.succ)) : + -1/(2*(D (Fin.last k))⁻¹)+quadraticCascadeReciprocalSlope σ (D (Fin.last k))⁻¹ k z- + (q 0/(D 0)^2)/(2*(quadraticCascadePrecision σ (D (Fin.last k))⁻¹ k z)^2) = -1/2 := by + rw [quadraticCascadePrecision_stationary k σ q D z hD hgap hσ, + quadraticCascadeReciprocalSlope_stationary k σ q D z hD hz hgap hσ] + have h0 := (hD 0).ne' + have ht := (hD (Fin.last k)).ne' + field_simp + nlinarith + +theorem expectedCoordinateSphereLog_stationary_data (k : ℕ) (σ : ℕ → ℝ) + (q D : Fin (k+1) → ℝ) (z : Fin k → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) (hD : ∀ i, 0 < D i) + (hend : D (Fin.last k)=1-q (Fin.last k)) + (hgap : ∀ i : Fin k, D i.castSucc-D i.succ=z i*(q i.succ-q i.castSucc)) + (hσ : ∀ i : Fin k, (σ (k-1-i.val))^2=(q i.succ-q i.castSucc)/(D i.castSucc*D i.succ)) + (r : ℝ≥0) (hr : (r:ℝ)=q 0/(D 0)^2) : + Tendsto (fun n : ℕ => expectedCoordinateSphereLog n k σ z r) atTop + (𝓝 (Real.log (D (Fin.last k))/2+stepLogRatios k D z+q 0/(2*D 0)+ + ((D (Fin.last k))⁻¹-1)/2)) := by + have hp : 0 < quadraticCascadePrecision σ (D (Fin.last k))⁻¹ k z := by + rw [quadraticCascadePrecision_stationary k σ q D z hD hgap hσ] + exact inv_pos.mpr (hD 0) + have hstat := canonicalGaussianFreeValue_stationarity k σ q D z hD hz0 hend hgap hσ + rw [← hr] at hstat + have ht := expectedCoordinateSphereLog_tendsto k σ z hz hz0 hz1 r (D (Fin.last k))⁻¹ hp hstat + rw [hr,canonicalGaussianFreeValue_stationary k σ q D z hD hgap hσ] at ht + exact ht + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/SynchronizedLimit.lean b/lean/OAI/Probability/Perceptron/Variational/SynchronizedLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..1c3507449357c8c9fbf35fdb626665fae734756a --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/SynchronizedLimit.lean @@ -0,0 +1,177 @@ +import Mathlib +import OAI.Probability.Perceptron.Interpolation.ArrayLimitGeometry +import OAI.Probability.Perceptron.Variational.LabelResponse +import OAI.Probability.Perceptron.Variational.CompactGGDensity +import OAI.Probability.Perceptron.Variational.CompactGGEvents + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set TopologicalSpace Matrix +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +section + +lemma source_contact_limit_exchangeable (k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : (n : ℕ) → Fin (n+1) → ℕ) (h : ℕ → Fin (k+1) → ℝ) + (u : (n : ℕ) → Fin (n+1) → ℝ) (z : Fin k → ℝ) (t : ℕ → ℝ≥0) + (s : ℕ→ℕ) {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (p (s n)) (d (s n)) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) (e : Equiv.Perm ℕ) : + MeasurePreserving (compactRelabel (K:=CompactJointOverlap) e) (ν : Measure _) (ν : Measure _) := + compact_exchangeability_limit hlim e (fun n => sourceGibbsArray_exchangeable + (s n) k f (p (s n)) (d (s n)) (h (s n)) (u (s n)) z (t (s n)) e) + +variable (k : ℕ) (f : ℝ →ᵇ ℝ) (p d : ℕ → ℕ) (z : Fin k → ℝ) +variable (hz : StrictMono z) (hz0 : ∀ i, 0 1) (fun _ => 2)) +variable (hmin : ∀ n, IsMinOn (fun v => quadraticBoxPenalty (sourcePenaltyWeight (n+1)) v- + sourceExpectedPressure n k f (fun j => p j.val) (fun j => d j.val) (h n) z (t n) v) + (Icc (fun _ : Fin (n+1) => 1) (fun _ => 2)) (u n)) +variable {H T : ℝ} (hH : 0≤H) (hhH : ∀ n, h n 0≤H) (ht : ∀ n, (t n:ℝ)≤T) +variable (hcover : ∀ a b : ℕ, 1≤a+b → ∃ j, p j=a ∧ d j=b) + +include hz hz0 hz1 hh0 hh hu hmin hH hhH ht hcover +lemma source_contact_limit_no_crossing {ν : ProbabilityMeasure (CompactArray CompactJointOverlap)} + {s : ℕ → ℕ} (hs : StrictMono s) + (hlim : Tendsto (fun n => sourceGibbsArrayLaw (s n) k f + (fun a => p a.val) (fun a => d a.val) (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν)) : + ∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), + ¬ ((Q 0 1).1.val < (Q 0 2).1.val ∧ (Q 0 2).2.val < (Q 0 1).2.val) := by + obtain ⟨hR,hT⟩ := sourceGibbsArray_limit_gram k f (fun _ a => p a.val) + (fun _ a => d a.val) h u z t s hlim + exact compact_gg_no_crossing ν + (source_contact_limit_exchangeable k f (fun _ a => p a.val) (fun _ a => d a.val) h u z t s hlim) + (source_contact_limit_joint_gg k f p d z hz hz0 hz1 t h hh0 hh u hu hmin hH hhH ht hs hlim hcover) + hR hT + +lemma source_contact_synchronized_subsequence : + ∃ (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) (s : ℕ → ℕ), + StrictMono s ∧ + Tendsto (fun n => sourceGibbsArrayLaw (s n) k f (fun a => p a.val) (fun a => d a.val) + (h (s n)) (u (s n)) z (t (s n))) atTop (𝓝 ν) ∧ + JointGhirlandaGuerra (compactRealLaw ν) ∧ + PairedSwapInvariant (compactRealLaw ν) ∧ + (∀ᵐ Q : CompactArray CompactJointOverlap ∂(ν : Measure _), + ¬ ((Q 0 1).1.val < (Q 0 2).1.val ∧ (Q 0 2).2.val < (Q 0 1).2.val)) := by + obtain ⟨ν,s,hs,hlim⟩ := compact_array_law_subsequence (fun n => sourceGibbsArrayLaw n k f + (fun a => p a.val) (fun a => d a.val) (h n) (u n) z (t n)) + refine ⟨ν,s,hs,hlim,?_,?_,?_⟩ + · exact compactRealLaw_gg ν (source_contact_limit_joint_gg k f p d z hz hz0 hz1 t h + hh0 hh u hu hmin hH hhH ht hs hlim hcover) + · exact compactRealLaw_exchangeable ν (source_contact_limit_exchangeable k f + (fun _ a => p a.val) (fun _ a => d a.val) h u z t s hlim) + · exact source_contact_limit_no_crossing k f p d z hz hz0 hz1 t h hh0 hh u hu hmin hH hhH ht hcover hs hlim + +end + +lemma sourceGibbsArray_label_moment (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (h w : Fin (k+1)→ℝ) + (hh0 : ∀ l, 0≤h l) (hh : Monotone h) (hw : ∀ l, 0 ((Q 1 0).2.val)^(d j) + have hF : Measurable F := by dsimp [F]; fun_prop + have hB : ∀ Q, |F Q|≤1 := by + intro Q + dsimp [F] + rw [abs_pow,abs_of_nonneg (Q 1 0).2.property.1] + exact pow_le_one₀ (Q 1 0).2.property.1 (Q 1 0).2.property.2 + have he := sourceGibbsArray_block_integral n k f p d h hh0 hh u (stepCumulative w) t 2 hF hB + change (∫ Q : CompactArray CompactJointOverlap, ((Q 1 0).2.val)^(d j) ∂sourceGibbsArrayLaw n k f p d h u (stepCumulative w) t)=_ at he + rw [he] + exact source_label_moment n k f p d h w hh0 hh hw hw1 u j hp hu t + +lemma source_array_limit_label_moments (k : ℕ) (f : ℝ →ᵇ ℝ) (p d : ℕ→ℕ) + (w : Fin (k+1)→ℝ) (hw : ∀ l, 0 sourceGibbsArrayLaw (s n) k f (fun j => p j.val) + (fun j => d j.val) (h (s n)) (u (s n)) (stepCumulative w) (t (s n))) atTop (𝓝 ν)) + (b : ℕ) : (∫ Q : CompactArray CompactJointOverlap, ((Q 1 0).2.val)^b ∂ν)=∑ l, w l*((l.val:ℝ)/(k+1:ℕ))^b := by + by_cases hb : b=0 + · subst b + simp [hw1] + obtain ⟨j,hp,hd⟩ := hcover b (Nat.pos_of_ne_zero hb) + let F : CompactArray CompactJointOverlap →ᵇ ℝ := + BoundedContinuousFunction.mkOfCompact ⟨fun Q => ((Q 1 0).2.val)^b,by fun_prop⟩ + have hI := (ProbabilityMeasure.continuous_integral_boundedContinuousFunction F).tendsto ν |>.comp hlim + have hconst : ∀ᶠ n in atTop, (∫ Q : CompactArray CompactJointOverlap, F Q ∂sourceGibbsArrayLaw (s n) k f (fun j => p j.val) + (fun j => d j.val) (h (s n)) (u (s n)) (stepCumulative w) (t (s n)))= + ∑ l, w l*((l.val:ℝ)/(k+1:ℕ))^b := by + filter_upwards [eventually_ge_atTop j] with n hn + have hn' : j p a.val) (fun a => d a.val) + (h (s n)) w (hh0 (s n)) (hh (s n)) hw hw1 (u (s n)) ⟨j,hn'⟩ hp (hu _ _) (t (s n)) + exact tendsto_nhds_unique hI (tendsto_const_nhds.congr' (Filter.EventuallyEq.symm hconst)) + +def sourceLabelLevel (k : ℕ) (l : Fin (k+1)) : unitInterval := + ⟨(l.val:ℝ)/(k+1:ℕ),by constructor; positivity; exact (div_le_one (by positivity)).mpr (by exact_mod_cast l.isLt.le)⟩ + +def sourceLabelLaw (k : ℕ) (w : Fin (k+1)→ℝ) : Measure unitInterval := + ∑ l, ENNReal.ofReal (w l) • Measure.dirac (sourceLabelLevel k l) + +lemma sourceLabelLaw_probability (k : ℕ) (w : Fin (k+1)→ℝ) + (hw : ∀ l, 0≤w l) (hw1 : ∑ l, w l=1) : IsProbabilityMeasure (sourceLabelLaw k w) := by + constructor + simp only [sourceLabelLaw,Measure.finsetSum_apply,Measure.smul_apply,Measure.dirac_apply_of_mem + (mem_univ _),smul_eq_mul,mul_one] + rw [← ENNReal.ofReal_sum_of_nonneg (fun l _ => hw l),hw1,ENNReal.ofReal_one] + +lemma sourceLabelLaw_integral (k : ℕ) (w : Fin (k+1)→ℝ) (hw : ∀ l, 0≤w l) + (g : unitInterval→ℝ) (hg : Measurable g) : + (∫ x, g x ∂sourceLabelLaw k w)=∑ l, w l*g (sourceLabelLevel k l) := by + unfold sourceLabelLaw + rw [integral_finsetSum_measure] + · simp only [integral_smul_measure,integral_dirac' g _ hg.stronglyMeasurable, + ENNReal.toReal_ofReal (hw _),smul_eq_mul] + · intro l _ + exact (integrable_dirac (by finiteness)).smul_measure ENNReal.ofReal_ne_top + +lemma source_label_law_of_moments (k : ℕ) (w : Fin (k+1)→ℝ) + (hw : ∀ l, 0≤w l) (hw1 : ∑ l, w l=1) + (ν : ProbabilityMeasure (CompactArray CompactJointOverlap)) + (hm : ∀ b : ℕ, (∫ Q : CompactArray CompactJointOverlap, ((Q 1 0).2.val)^b ∂ν)= + ∑ l, w l*((l.val:ℝ)/(k+1:ℕ))^b) : + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 1 0).2)=sourceLabelLaw k w := by + let := sourceLabelLaw_probability k w hw hw1 + have hmeas : Measurable (fun Q : CompactArray CompactJointOverlap => (Q 1 0).2) := by fun_prop + let m (b : ℕ) : unitInterval →ᵇ ℝ := BoundedContinuousFunction.mkOfCompact + ⟨fun x : unitInterval => x.val^b,by fun_prop⟩ + apply measure_eq_of_additive_test_family m + · ext x; simp [m] + · intro a b; ext x; simp [m,pow_add] + · intro x y hxy + refine ⟨1,?_⟩ + simpa only [m,BoundedContinuousFunction.mkOfCompact_apply,ContinuousMap.coe_mk,pow_one, + ne_eq,Subtype.val_inj] using hxy + · intro b + rw [integral_map hmeas.aemeasurable (m b).continuous.aestronglyMeasurable, + sourceLabelLaw_integral k w hw (m b) (m b).measurable] + exact hm b + +theorem source_array_limit_label_law (k : ℕ) (f : ℝ →ᵇ ℝ) (p d : ℕ→ℕ) + (w : Fin (k+1)→ℝ) (hw : ∀ l, 0 sourceGibbsArrayLaw (s n) k f (fun j => p j.val) + (fun j => d j.val) (h (s n)) (u (s n)) (stepCumulative w) (t (s n))) atTop (𝓝 ν)) : + (ν : Measure (CompactArray CompactJointOverlap)).map (fun Q => (Q 1 0).2)=sourceLabelLaw k w := by + apply source_label_law_of_moments k w (fun l => (hw l).le) hw1 ν + exact source_array_limit_label_moments k f p d w hw hw1 h hh0 hh u hu t hcover hs hlim + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TangentConsistency.lean b/lean/OAI/Probability/Perceptron/Variational/TangentConsistency.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ae6a7e4efd9e0ac78d89b06ed80eb1ce3fb1942 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TangentConsistency.lean @@ -0,0 +1,93 @@ +import Mathlib +import OAI.Probability.Perceptron.Cascade.WeightedCDF +import OAI.Probability.Perceptron.Variational.MarkedVariance + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped NNReal BoundedContinuousFunction ContDiff +namespace SphericalPerceptronFreeEnergy + +lemma sphereTail_measurable (ν : Measure Time) [IsProbabilityMeasure ν] : + Measurable (sphereTail ν) := by + have hm : Measurable (fun p : Time×Time=>1-max (p.1:ℝ) (p.2:ℝ)) := by fun_prop + exact hm.stronglyMeasurable.integral_prod_right.measurable + +lemma sphereKernel_integral_measurable (ν : Measure Time) [IsProbabilityMeasure ν] + (a : Time→ℝ) (ha : Measurable a) : + Measurable (fun x=>∫ y,sphereKernel x y*a y ∂ν) := by + have hm : Measurable (fun p : Time×Time=>sphereKernel p.1 p.2*a p.2) := by + unfold sphereKernel + fun_prop + exact hm.stronglyMeasurable.integral_prod_right.measurable + +lemma sphereKernel_integral_abs_bound (ν : Measure Time) [IsProbabilityMeasure ν] + (a : Time→ℝ) {A : ℝ} (_hA : 0≤A) (hab : ∀ x,|a x|≤A) (r : Time) : + |∫ y,sphereKernel r y*a y ∂ν|≤A := by + have hb (y : Time) : ‖sphereKernel r y*a y‖≤A := by + rw [Real.norm_eq_abs,abs_mul] + simpa only [one_mul] using mul_le_mul (sphereKernel_abs_le_one r y) (hab y) (abs_nonneg _) zero_le_one + simpa [Real.norm_eq_abs,Measure.real] using + norm_integral_le_of_norm_le_const (ae_of_all ν hb) + +lemma tangent_wronskian_ae {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] (ν : Measure Time) [IsProbabilityMeasure ν] + (r s t : Ω→Time) (hr : Measurable r) (hs : Measurable s) (ht : Measurable t) + (hmarg : P.map r=ν) + (hlaws : P.map (fun x=>(r x,s x))=(1/2:ℝ≥0) • (ν.prod ν)+(1/2:ℝ≥0) • (ν.map fun x=>(x,x))) + (hlawt : P.map (fun x=>(r x,t x))=(1/2:ℝ≥0) • (ν.prod ν)+(1/2:ℝ≥0) • (ν.map fun x=>(x,x))) + (htri : ∀ᵐ x ∂P,UltrametricTriangle (r x:ℝ) (s x:ℝ) (t x:ℝ)) + (a : Time→ℝ) (ha : Measurable a) {A : ℝ} (hA : 0≤A) (hab : ∀ x,|a x|≤A) + (hT : ∀ G : ℝ→ᵇℝ,ContDiff ℝ 1 (G : ℝ→ℝ)→ + (∫ x,G (r x)*((r x:ℝ)-a (r x)*(1-(r x:ℝ)^2)+2*a (s x)*((t x:ℝ)-(r x:ℝ)*(s x:ℝ))) ∂P)=0) : + ∀ᵐ x ∂ν,a x*sphereTail ν x=(x:ℝ)+∫ y,sphereKernel x y*a y ∂ν := by + let Z : Time→ℝ := fun x=>(x:ℝ)-a x*sphereTail ν x+∫ y,sphereKernel x y*a y ∂ν + have hZm : Measurable Z := (measurable_subtype_coe.sub (ha.mul (sphereTail_measurable ν))).add + (sphereKernel_integral_measurable ν a ha) + have hZb (x : Time) : |Z x|≤1+2*A := by + have htail : |sphereTail ν x|≤1 := by + rw [abs_of_nonneg (sphereTail_nonneg ν x)] + exact (sphereTail_upper ν x).trans (by linarith [x.property.1]) + have hx : |a x*sphereTail ν x|≤A := by + rw [abs_mul] + simpa only [mul_one] using mul_le_mul (hab x) htail (abs_nonneg _) hA + have hg := (abs_sub (x:ℝ) (a x*sphereTail ν x)).trans (add_le_add (time_abs_le_one x) hx) + exact (abs_add_le _ _).trans ((add_le_add hg (sphereKernel_integral_abs_bound ν a hA hab x)).trans (by ring_nf; exact le_rfl)) + have hz : ∀ G : ℝ→ᵇℝ,ContDiff ℝ 1 (G : ℝ→ℝ)→(∫ x,G x*Z x ∂ν)=0 := by + intro G hG + rw [←tangent_wronskian_test P ν r s t hr hs ht hmarg hlaws hlawt htri a ha hA hab G] + exact hT G hG + have hz' (F : Time→ᵇℝ) : (∫ x,F x*Z x ∂ν)=0 := + smooth_compact_test_extend ν zero_le_one id measurable_id Z hZm (by linarith) hZb hz F + have hz2 := bounded_continuous_test_extend ν id measurable_id Z hZm (by linarith) hZb hz' Z hZm (by linarith) hZb + have hi : Integrable (fun x=>Z x*Z x) ν := boundedAbs_integrable ν _ (hZm.mul hZm) ((1+2*A)^2) (fun x=>by + rw [abs_mul,←pow_two] + exact pow_le_pow_left₀ (abs_nonneg _) (hZb x) 2) + have hae := (integral_eq_zero_iff_of_nonneg (fun x=>mul_self_nonneg (Z x)) hi).mp hz2 + filter_upwards [hae] with x hx + have h := mul_self_eq_zero.mp hx + change (x:ℝ)-a x*sphereTail ν x+∫ y,sphereKernel x y*a y ∂ν=0 at h + linarith + +theorem tangent_sphere_self_consistency {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] (ν : Measure Time) [IsProbabilityMeasure ν] + (r s t : Ω→Time) (hr : Measurable r) (hs : Measurable s) (ht : Measurable t) + (hmarg : P.map r=ν) + (hlaws : P.map (fun x=>(r x,s x))=(1/2:ℝ≥0) • (ν.prod ν)+(1/2:ℝ≥0) • (ν.map fun x=>(x,x))) + (hlawt : P.map (fun x=>(r x,t x))=(1/2:ℝ≥0) • (ν.prod ν)+(1/2:ℝ≥0) • (ν.map fun x=>(x,x))) + (htri : ∀ᵐ x ∂P,UltrametricTriangle (r x:ℝ) (s x:ℝ) (t x:ℝ)) + (a : Time→ℝ) (ha : Measurable a) {A : ℝ} (hA : 0≤A) (hab : ∀ x,0≤a x ∧ a x≤A) + (hT : ∀ G : ℝ→ᵇℝ,ContDiff ℝ 1 (G : ℝ→ℝ)→ + (∫ x,G (r x)*((r x:ℝ)-a (r x)*(1-(r x:ℝ)^2)+2*a (s x)*((t x:ℝ)-(r x:ℝ)*(s x:ℝ))) ∂P)=0) : + (∀ᵐ x ∂ν,a x=∫ y in 0..(x:ℝ),(realTail ν y)⁻¹^2) ∧ + ∀ᵐ x : Time ∂ν,(x:ℝ)≤A/(1+A) := by + apply sphere_self_consistency ν hA ha.aestronglyMeasurable + (ae_of_all _ fun x=>(hab x).1) (ae_of_all _ fun x=>(hab x).2) + exact tangent_wronskian_ae P ν r s t hr hs ht hmarg hlaws hlawt htri a ha hA + (fun x=>by rw [abs_of_nonneg (hab x).1]; exact (hab x).2) hT + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TensorFeatures.lean b/lean/OAI/Probability/Perceptron/Variational/TensorFeatures.lean new file mode 100644 index 0000000000000000000000000000000000000000..fde6d0527c614dfae975acc176a0940f800cb531 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TensorFeatures.lean @@ -0,0 +1,150 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +abbrev NormalizedSpin (N : ℕ) := Metric.sphere (0 : Spin N) 1 +abbrev SpinTensorIndex (N p : ℕ) := Fin p → Fin N + +def spinTensorFeature (N p : ℕ) (x : NormalizedSpin N) : + EuclideanSpace ℝ (SpinTensorIndex N p) := + WithLp.toLp 2 (fun i => ∏ j, x.val (i j)) + +def spinOverlap {N : ℕ} (x y : NormalizedSpin N) : ℝ := inner ℝ x.val y.val + +lemma spinTensorFeature_continuous (N p : ℕ) : Continuous (spinTensorFeature N p) := by + apply (PiLp.continuous_toLp 2 _).comp + apply continuous_pi + intro i + exact continuous_finsetProd _ fun j _ => + (EuclideanSpace.proj (i j)).continuous.comp continuous_subtype_val + +lemma spinTensorFeature_inner (N p : ℕ) (x y : NormalizedSpin N) : + inner ℝ (spinTensorFeature N p x) (spinTensorFeature N p y) = + spinOverlap x y ^ p := by + change (∑ i : SpinTensorIndex N p, (∏ j, y.val (i j)) * (∏ j, x.val (i j))) = _ + simp_rw [← Finset.prod_mul_distrib] + rw [← Fintype.prod_sum (fun (_ : Fin p) (i : Fin N) => y.val i*x.val i)] + change (∏ _ : Fin p, spinOverlap x y) = spinOverlap x y ^ p + simp + +lemma spinTensorFeature_norm (N p : ℕ) (x : NormalizedSpin N) : + ‖spinTensorFeature N p x‖ = 1 := by + have hx : ‖x.val‖=1 := by simp + have h := spinTensorFeature_inner N p x x + rw [real_inner_self_eq_norm_sq] at h + simp only [spinOverlap,real_inner_self_eq_norm_sq,hx,one_pow] at h + nlinarith [norm_nonneg (spinTensorFeature N p x)] + +lemma spinTensorFeature_coordinate_bound (N p : ℕ) (x : NormalizedSpin N) + (i : SpinTensorIndex N p) : |spinTensorFeature N p x i| ≤ 1 := by + calc + _ ≤ ‖spinTensorFeature N p x‖ := by + simpa only [Real.norm_eq_abs] using PiLp.norm_apply_le (spinTensorFeature N p x) i + _ = 1 := spinTensorFeature_norm N p x + +lemma spinOverlap_abs_le {N : ℕ} (x y : NormalizedSpin N) : |spinOverlap x y| ≤ 1 := by + have hx : ‖x.val‖=1 := by simp + have hy : ‖y.val‖=1 := by simp + simpa [spinOverlap,hx,hy] using abs_real_inner_le_norm x.val y.val + +abbrev EnrichedIndex (N J : ℕ) (p : Fin J → ℕ) := + Fin N ⊕ (j : Fin J) × SpinTensorIndex N (p j) +abbrev EnrichedMark (N J : ℕ) (p : Fin J → ℕ) := EuclideanSpace ℝ (EnrichedIndex N J p) + +def enrichedFeature (N J : ℕ) (p : Fin J → ℕ) (a : ℝ) (c : Fin J → ℝ) + (x : NormalizedSpin N) : EnrichedMark N J p := + WithLp.toLp 2 fun i => match i with + | .inl i => a*x.val i + | .inr ⟨j,t⟩ => c j*spinTensorFeature N (p j) x t + +lemma enrichedFeature_continuous (N J : ℕ) (p : Fin J → ℕ) (a : ℝ) (c : Fin J → ℝ) : + Continuous (enrichedFeature N J p a c) := by + apply (PiLp.continuous_toLp 2 _).comp + apply continuous_pi + intro i + cases i with + | inl i => exact continuous_const.mul ((EuclideanSpace.proj i).continuous.comp continuous_subtype_val) + | inr i => exact continuous_const.mul ((EuclideanSpace.proj i.2).continuous.comp + (spinTensorFeature_continuous N (p i.1))) + +lemma enrichedFeature_inner (N J : ℕ) (p : Fin J → ℕ) (a : ℝ) (c : Fin J → ℝ) + (x y : NormalizedSpin N) : + inner ℝ (enrichedFeature N J p a c x) (enrichedFeature N J p a c y)= + a^2*spinOverlap x y+∑ j, (c j)^2*spinOverlap x y^(p j) := by + change (∑ i : EnrichedIndex N J p, + (enrichedFeature N J p a c y i)*(enrichedFeature N J p a c x i)) = _ + rw [Fintype.sum_sum_type,Fintype.sum_sigma] + simp only [enrichedFeature] + have hlin : (∑ i : Fin N, a*y.val i*(a*x.val i))=a^2*spinOverlap x y := by + change (∑ i : Fin N, a*y.val i*(a*x.val i)) = a^2*(∑ i : Fin N, y.val i*x.val i) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + rw [hlin] + congr 1 + apply Finset.sum_congr rfl + intro j _ + rw [← spinTensorFeature_inner N (p j) x y] + change (∑ i, c j*spinTensorFeature N (p j) y i*(c j*spinTensorFeature N (p j) x i))= + (c j)^2*(∑ i, spinTensorFeature N (p j) y i*spinTensorFeature N (p j) x i) + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + ring + +lemma enrichedFeature_norm_sq (N J : ℕ) (p : Fin J → ℕ) (a : ℝ) (c : Fin J → ℝ) + (x : NormalizedSpin N) : + ‖enrichedFeature N J p a c x‖^2=a^2+∑ j, (c j)^2 := by + rw [← real_inner_self_eq_norm_sq,enrichedFeature_inner] + have hx : spinOverlap x x=1 := by + have h : ‖x.val‖=1 := by simp + simp [spinOverlap,h] + simp [hx] + +lemma enrichedFeature_norm (N J : ℕ) (p : Fin J → ℕ) (a : ℝ) (c : Fin J → ℝ) + (x : NormalizedSpin N) : + ‖enrichedFeature N J p a c x‖=Real.sqrt (a^2+∑ j, (c j)^2) := by + rw [← enrichedFeature_norm_sq N J p a c x,Real.sqrt_sq (norm_nonneg _)] + +def perturbationScale (N : ℕ) : ℝ := (N:ℝ)^(-(1:ℝ)/16) + +def perturbationAmplitude (N : ℕ) (u : Fin N → ℝ) (j : Fin N) : ℝ := + Real.sqrt (N:ℝ)*perturbationScale N*(2:ℝ)^(-((j.val+1:ℕ):ℤ))*u j + +def sourceEnrichedFeature (N : ℕ) (p : Fin N → ℕ) (u : Fin N → ℝ) : + NormalizedSpin N → EnrichedMark N N p := + enrichedFeature N N p (Real.sqrt (N:ℝ)) (perturbationAmplitude N u) + +variable {I : Type} [Fintype I] + +def diagonalMarkLinear (c : I → ℝ) : EuclideanSpace ℝ I →ₗ[ℝ] EuclideanSpace ℝ I where + toFun x := WithLp.toLp 2 fun i => c i*x i + map_add' x y := by ext i; change c i*(x i+y i)=c i*x i+c i*y i; ring + map_smul' r x := by ext i; change c i*(r*x i)=r*(c i*x i); ring + +def diagonalMark (c : I → ℝ) : EuclideanSpace ℝ I →L[ℝ] EuclideanSpace ℝ I := + (diagonalMarkLinear c).toContinuousLinearMap + +@[simp] lemma diagonalMark_apply (c : I → ℝ) (x : EuclideanSpace ℝ I) (i : I) : + diagonalMark c x i=c i*x i := rfl + +lemma diagonalMark_self_adjoint (c : I → ℝ) (x y : EuclideanSpace ℝ I) : + inner ℝ (diagonalMark c x) y=inner ℝ x (diagonalMark c y) := by + simp only [PiLp.inner_apply] + apply Finset.sum_congr rfl + intro i _ + change y i*(c i*x i)=(c i*y i)*x i + ring + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TiltMeanCenteredAbsSq.lean b/lean/OAI/Probability/Perceptron/Variational/TiltMeanCenteredAbsSq.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ec8fb173583325a0348decb6a463d667df74538 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TiltMeanCenteredAbsSq.lean @@ -0,0 +1,202 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.QuadraticContactRemainders +import OAI.Probability.Perceptron.Variational.LocalMaxSecondDerivNonpos + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +namespace SphericalPerceptronFreeEnergy + +section +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma tilt_mean_centered_abs_sq_le {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + {A B : ℝ} (hA : 0 ≤ A) (hHA : ∀ x, |H x| ≤ A) (hYB : ∀ x, |Y x| ≤ B) : + (tiltMean μ H (fun x => |Y x-tiltMean μ H Y 1|) 1)^2 ≤ + tiltMean μ H (fun x => Y x*Y x) 1-(tiltMean μ H Y 1)^2 := by + have := tilt_law_probability μ hH hA hHA 1 + let ν := tiltLaw μ H 1 + have hLp : MemLp Y 2 ν := MemLp.of_bound hY.aestronglyMeasurable B (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hYB x) + have hh := integral_centered_abs_le_sqrt_variance ν hLp + have hnon : 0 ≤ ∫ x, |Y x-∫ y, Y y ∂ν| ∂ν := integral_nonneg fun _ => abs_nonneg _ + have hsq := pow_le_pow_left₀ hnon hh 2 + rw [Real.sq_sqrt (variance_nonneg Y ν),variance_eq_sub hLp] at hsq + simp only [Pi.pow_apply] at hsq + change (∫ x, |Y x-∫ y, Y y ∂tiltLaw μ H 1| ∂tiltLaw μ H 1)^2 ≤ + (∫ x, (Y x)^2 ∂tiltLaw μ H 1) - (∫ x, Y x ∂tiltLaw μ H 1)^2 at hsq + simp_rw [tilt_law_integral μ hH hA hHA 1] at hsq + simpa only [pow_two] using hsq + +omit [IsProbabilityMeasure μ] in +lemma tiltMean_nonneg {H F : S → ℝ} (hF : ∀ x, 0 ≤ F x) (t : ℝ) : 0 ≤ tiltMean μ H F t := by + exact div_nonneg (integral_nonneg fun x => mul_nonneg (Real.exp_pos _).le (hF x)) + (integral_nonneg fun _ => (Real.exp_pos _).le) + +variable {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P] + +lemma annealed_thermal_abs_sq_le {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + {A B : Ω → ℝ} (hA : ∀ ω, 0 ≤ A ω) (hB : ∀ ω, 0 ≤ B ω) + (hHA : ∀ ω x, |H ω x| ≤ A ω) (hYB : ∀ ω x, |Y ω x| ≤ B ω) + (hB2 : MemLp B 2 P) (t : ℝ) : + (∫ ω, tiltMean μ (fun x => H ω x+t*Y ω x) + (fun x => |Y ω x-tiltMean μ (fun x => H ω x+t*Y ω x) (Y ω) 1|) 1 ∂P)^2 ≤ + ∫ ω, thermalVar μ (H ω) (Y ω) t ∂P := by + let T := fun ω x => H ω x+t*Y ω x + let M := fun ω => tiltMean μ (T ω) (Y ω) 1 + let U := fun ω => tiltMean μ (T ω) (fun x => |Y ω x-M ω|) 1 + have hT : Measurable (Function.uncurry T) := hH.add (hY.const_mul t) + have hM : Measurable M := measurable_tiltMean_param μ hT hY + have hU : Measurable U := measurable_tiltMean_param μ hT ((hY.sub (hM.comp measurable_fst)).abs) + have hTm (ω) : Measurable (T ω) := hT.comp (measurable_const.prodMk measurable_id) + have hYm (ω) : Measurable (Y ω) := hY.comp (measurable_const.prodMk measurable_id) + have hTB (ω x) : |T ω x| ≤ A ω+|t| * B ω := affinePotential_bound (hHA ω) (hYB ω) t x + have hTp (ω) : 0 ≤ A ω+|t| * B ω := add_nonneg (hA ω) (mul_nonneg (abs_nonneg _) (hB ω)) + have hMB (ω) : |M ω| ≤ B ω := tilt_mean_bound μ (hTm ω) (hYm ω) (hTp ω) (hB ω) (hTB ω) (hYB ω) 1 + have hUB (ω) : |U ω| ≤ 2*B ω := by + apply tilt_mean_bound μ (hTm ω) ((hYm ω).sub_const (M ω) |>.abs) (hTp ω) (mul_nonneg (by norm_num) (hB ω)) (hTB ω) _ 1 + intro x + rw [abs_abs] + exact (abs_sub _ _).trans (by linarith [hYB ω x,hMB ω]) + have hULp : MemLp U 2 P := (hB2.const_mul 2).mono' hU.aestronglyMeasurable + (ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs] using hUB ω) + have hv := variance_nonneg U P + rw [variance_eq_sub hULp] at hv + have hIvar : Integrable (fun ω => thermalVar μ (H ω) (Y ω) t) P := + ((memLp_two_iff_integrable_sq hB2.aestronglyMeasurable).mp hB2 |>.const_mul 2).mono' + (measurable_thermalVar μ hH hY t).aestronglyMeasurable (ae_of_all _ fun ω => by + simpa only [Real.norm_eq_abs] using thermalVar_bound μ + (show Measurable (H ω) from hH.comp (measurable_const.prodMk measurable_id)) (hYm ω) (hA ω) (hB ω) (hHA ω) (hYB ω) t) + have hsq : (∫ ω, U ω^2 ∂P) ≤ ∫ ω, thermalVar μ (H ω) (Y ω) t ∂P := by + apply integral_mono ((memLp_two_iff_integrable_sq hULp.aestronglyMeasurable).mp hULp) hIvar + intro ω + exact tilt_mean_centered_abs_sq_le μ (hTm ω) (hYm ω) (hTp ω) (hTB ω) (hYB ω) + simp only [Pi.pow_apply] at hv + change (∫ ω, U ω ∂P)^2 ≤ _ + linarith + +end + +variable {S Ω : Type*} [MeasurableSpace S] [MeasurableSpace Ω] +variable (μ : Measure S) [IsProbabilityMeasure μ] (P : Measure Ω) [IsProbabilityMeasure P] + +omit [IsProbabilityMeasure P] in +lemma affineLogRoot_memLp {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + {A B : Ω → ℝ} (hA : ∀ ω, 0 ≤ A ω) (hB : ∀ ω, 0 ≤ B ω) + (hHA : ∀ ω x, |H ω x| ≤ A ω) (hYB : ∀ ω x, |Y ω x| ≤ B ω) + {p : ℝ≥0∞} (hAp : MemLp A p P) (hBp : MemLp B p P) (t : ℝ) : + MemLp (fun ω => affineLogRoot μ (H ω) (Y ω) t) p P := by + apply (hAp.add (hBp.const_mul |t|)).mono' (measurable_affineLogRoot μ hH hY t).aestronglyMeasurable + exact ae_of_all _ fun ω => by + simpa only [affineLogRoot,Real.norm_eq_abs,Pi.add_def] using tilt_log_partition_bound μ + (show Measurable (fun x => H ω x+t*Y ω x) from + (hH.comp (measurable_const.prodMk measurable_id)).add + ((hY.comp (measurable_const.prodMk measurable_id)).const_mul t)) + (add_nonneg (hA ω) (mul_nonneg (abs_nonneg _) (hB ω))) (affinePotential_bound (hHA ω) (hYB ω) t) + +lemma tilt_mean_center_triangle {H Y : S → ℝ} (hH : Measurable H) (hY : Measurable Y) + {A B : ℝ} (hA : 0 ≤ A) (hHA : ∀ x, |H x| ≤ A) (hYB : ∀ x, |Y x| ≤ B) + (a b : ℝ) : + tiltMean μ H (fun x => |Y x-a|) 1 ≤ tiltMean μ H (fun x => |Y x-b|) 1+|b-a| := by + have := tilt_law_probability μ hH hA hHA 1 + have hi (c : ℝ) : Integrable (fun x => |Y x-c|) (tiltLaw μ H 1) := + Integrable.of_bound (hY.sub_const c).abs.aestronglyMeasurable (B+|c|) + (ae_of_all _ fun x => by + simpa only [Real.norm_eq_abs,abs_abs] using (abs_sub (Y x) c).trans (add_le_add (hYB x) le_rfl)) + simp_rw [← tilt_law_integral μ hH hA hHA 1] + have hc : (∫ _ : S, |b-a| ∂tiltLaw μ H 1) = |b-a| := by simp + rw [← hc, ← integral_add (hi b) (integrable_const _)] + apply integral_mono (hi a) ((hi b).add (integrable_const _)) + intro x + change |Y x-a| ≤ |Y x-b|+|b-a| + calc + _ = |(Y x-b)+(b-a)| := by congr 1; ring + _ ≤ _ := abs_add_le _ _ + +lemma contact_energy_L1_bound {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + {A B : Ω → ℝ} (hA : ∀ ω, 0 ≤ A ω) (hB : ∀ ω, 0 ≤ B ω) + (hHA : ∀ ω x, |H ω x| ≤ A ω) (hYB : ∀ ω x, |Y ω x| ≤ B ω) + (hA2 : MemLp A 2 P) (hB2 : MemLp B 2 P) {u a c s V : ℝ} (hs : 0 < s) + (hmin : IsLocalMin (fun t => c*(t-a)^2-∫ ω, affineLogRoot μ (H ω) (Y ω) t ∂P) u) + (hp : c*(u-a)^2-(∫ ω, affineLogRoot μ (H ω) (Y ω) u ∂P) ≤ + c*(u+s-a)^2-(∫ ω, affineLogRoot μ (H ω) (Y ω) (u+s) ∂P)) + (hm : c*(u-a)^2-(∫ ω, affineLogRoot μ (H ω) (Y ω) u ∂P) ≤ + c*(u-s-a)^2-(∫ ω, affineLogRoot μ (H ω) (Y ω) (u-s) ∂P)) + (hVp : variance (fun ω => affineLogRoot μ (H ω) (Y ω) (u+s)) P ≤ V) + (hV0 : variance (fun ω => affineLogRoot μ (H ω) (Y ω) u) P ≤ V) + (hVm : variance (fun ω => affineLogRoot μ (H ω) (Y ω) (u-s)) P ≤ V) : + let T := fun ω x => H ω x+u*Y ω x + let M := fun ω => tiltMean μ (T ω) (Y ω) 1 + (∫ ω, tiltMean μ (T ω) (fun x => |Y ω x-∫ η, M η ∂P|) 1 ∂P) ≤ + Real.sqrt (2*c)+c*s+4*Real.sqrt V/s := by + dsimp only + let L := fun t => ∫ ω, affineLogRoot μ (H ω) (Y ω) t ∂P + let T := fun ω x => H ω x+u*Y ω x + let M := fun ω => tiltMean μ (T ω) (Y ω) 1 + let U := fun ω => tiltMean μ (T ω) (fun x => |Y ω x-M ω|) 1 + let E := ∫ ω, M ω ∂P + have hT : Measurable (Function.uncurry T) := hH.add (hY.const_mul u) + have hM : Measurable M := measurable_tiltMean_param μ hT hY + have hU : Measurable U := measurable_tiltMean_param μ hT ((hY.sub (hM.comp measurable_fst)).abs) + have hTm (ω) : Measurable (T ω) := hT.comp (measurable_const.prodMk measurable_id) + have hHm (ω) : Measurable (H ω) := hH.comp (measurable_const.prodMk measurable_id) + have hYm (ω) : Measurable (Y ω) := hY.comp (measurable_const.prodMk measurable_id) + have hTB (ω x) : |T ω x| ≤ A ω+|u| * B ω := affinePotential_bound (hHA ω) (hYB ω) u x + have hTp (ω) : 0 ≤ A ω+|u| * B ω := add_nonneg (hA ω) (mul_nonneg (abs_nonneg _) (hB ω)) + have hMB (ω) : |M ω| ≤ B ω := tilt_mean_bound μ (hTm ω) (hYm ω) (hTp ω) (hB ω) (hTB ω) (hYB ω) 1 + have hLp (t) := affineLogRoot_memLp μ P hH hY hA hB hHA hYB hA2 hB2 t + have hBI := hB2.integrable (by norm_num) + have hd := annealedAffineLogRoot_deriv μ P hH hY hA hB hHA hYB (hA2.integrable (by norm_num)) hBI u + have hc := quadratic_contact_remainders hd hmin hp hm + have hAerr (t) (ht : variance (fun ω => affineLogRoot μ (H ω) (Y ω) t) P ≤ V) : + (∫ ω, |affineLogRoot μ (H ω) (Y ω) t-L t| ∂P) ≤ Real.sqrt V := + (integral_centered_abs_le_sqrt_variance P (hLp t)).trans (Real.sqrt_le_sqrt ht) + have hdis : (∫ ω, |M ω-E| ∂P) ≤ c*s+4*Real.sqrt V/s := by + exact integral_convex_contact_bound P hs hM.aestronglyMeasurable + (ae_of_all _ fun ω => ⟨affineLogRoot_convex μ (hHm ω) (hYm ω) (hA ω) (hB ω) (hHA ω) (hYB ω), + affineLogRoot_deriv μ (hHm ω) (hYm ω) (hA ω) (hB ω) (hHA ω) (hYB ω) u⟩) + hc.1 hc.2 ((hLp (u+s)).integrable (by norm_num)) + ((hLp u).integrable (by norm_num)) ((hLp (u-s)).integrable (by norm_num)) + (hAerr (u+s) hVp) (hAerr u hV0) (hAerr (u-s) hVm) + have htherm : (∫ ω, U ω ∂P) ≤ Real.sqrt (2*c) := by + have hv := contact_thermal_variance_le μ P hH hY hA hB hHA hYB + (hA2.integrable (by norm_num)) hBI ((memLp_two_iff_integrable_sq hB2.aestronglyMeasurable).mp hB2) hmin + have hsq := annealed_thermal_abs_sq_le μ P hH hY hA hB hHA hYB hB2 u + have hsq' : (∫ ω, U ω ∂P)^2 ≤ 2*c := hsq.trans hv + exact (Real.le_sqrt (integral_nonneg fun ω => tiltMean_nonneg μ (fun _ => abs_nonneg _) 1) + (le_trans (sq_nonneg _) hsq')).mpr hsq' + have hUI : Integrable U P := by + apply (hBI.const_mul 2).mono' hU.aestronglyMeasurable + exact ae_of_all _ fun ω => by + simpa only [Real.norm_eq_abs] using tilt_mean_bound μ (hTm ω) + ((hYm ω).sub_const (M ω) |>.abs) (hTp ω) (mul_nonneg (by norm_num) (hB ω)) (hTB ω) + (fun x => by rw [abs_abs]; exact (abs_sub _ _).trans (by linarith [hYB ω x,hMB ω])) 1 + have hMI : Integrable (fun ω => |M ω-E|) P := + ((hBI.mono' hM.aestronglyMeasurable (ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs] using hMB ω)).sub (integrable_const E)).abs + have hQI : Integrable (fun ω => tiltMean μ (T ω) (fun x => |Y ω x-E|) 1) P := by + apply (hBI.add (integrable_const |E|)).mono' + (measurable_tiltMean_param μ hT + (show Measurable (Function.uncurry (fun ω x => |Y ω x-E|)) from + (hY.sub_const E).abs)).aestronglyMeasurable + exact ae_of_all _ fun ω => by + simpa only [Real.norm_eq_abs,Pi.add_apply] using tilt_mean_bound μ (hTm ω) + ((hYm ω).sub_const E |>.abs) (hTp ω) (add_nonneg (hB ω) (abs_nonneg E)) (hTB ω) + (fun x => by rw [abs_abs]; exact (abs_sub _ _).trans (add_le_add (hYB ω x) le_rfl)) 1 + have htri : (∫ ω, tiltMean μ (T ω) (fun x => |Y ω x-E|) 1 ∂P) ≤ + (∫ ω, U ω ∂P)+(∫ ω, |M ω-E| ∂P) := by + rw [← integral_add hUI hMI] + exact integral_mono hQI (hUI.add hMI) fun ω => tilt_mean_center_triangle μ (hTm ω) (hYm ω) (hTp ω) (hTB ω) (hYB ω) E (M ω) + exact htri.trans (by linarith) + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TiltedPathDiagonal.lean b/lean/OAI/Probability/Perceptron/Variational/TiltedPathDiagonal.lean new file mode 100644 index 0000000000000000000000000000000000000000..5362c735f49dfc665f25a72551834da1fb121b8b --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TiltedPathDiagonal.lean @@ -0,0 +1,183 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.IndexedTerminalProduct + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy + +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +variable {X Y R Q : Type} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace R] [MeasurableSpace Q] + +lemma pathCorrelation_last (n : ℕ) (κ : Fin n → Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f : X → ℝ) (hf : Measurable f) + (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, |f x| ≤ C) (x : X) : + pathCorrelation n κ f (Fin.last n) x = pathMean n κ (fun y => (f y)^2) x := by + have hsB : ∀ y, |(f y)^2| ≤ C^2 := fun y => by + rw [abs_pow]; exact pow_le_pow_left₀ (abs_nonneg _) (hb y) 2 + induction n generalizing x with + | zero => + simp only [pathCorrelation,pathPairKernel,Kernel.deterministic_apply,pathMean,pathOneKernel,Kernel.id_apply] + rw [integral_dirac' (fun y : X × X => f y.1*f y.2) (x,x) ((hf.comp measurable_fst).mul (hf.comp measurable_snd)).stronglyMeasurable, + integral_dirac' (fun y => (f y)^2) x (hf.pow_const 2).stronglyMeasurable,pow_two] + | succ n ih => + rw [show Fin.last (n+1) = (Fin.last n).succ from rfl, + pathCorrelation_succ n κ hκ f hf C hC hb, + pathMean_succ n κ hκ _ (hf.pow_const 2) (C^2) hsB] + apply integral_congr_ae + exact ae_of_all _ fun y => ih _ (fun i => hκ i.succ) y + +lemma pathCorrelation_le_diagonal (n : ℕ) (κ : Fin n → Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f g : X → ℝ) (hf : Measurable f) (hg : Measurable g) + (C D : ℝ) (hC : 0 ≤ C) (hfB : ∀ x, |f x| ≤ C) (hgB : ∀ x, |g x| ≤ D) + (hfg : ∀ x, (f x)^2 ≤ g x) (d : Fin (n+1)) (x : X) : + pathCorrelation n κ f d x ≤ pathMean n κ g x := by + apply (pathCorrelation_monotone n κ hκ f hf C hC hfB x (Fin.le_last d)).trans + change pathCorrelation n κ f (Fin.last n) x ≤ _ + rw [pathCorrelation_last n κ hκ f hf C hC hfB x] + have := pathOneKernel_markov n κ hκ + apply integral_mono + · apply path_bounded_integrable _ _ (hf.pow_const 2) (C^2) + intro y; rw [abs_pow]; exact pow_le_pow_left₀ (abs_nonneg _) (hfB y) 2 + · exact path_bounded_integrable _ g hg D hgB + · exact hfg + +def rootPathCorrelation (μ : Measure R) (x : R→X) (n : ℕ) (κ : Fin n→Kernel X X) + (f : X→ℝ) (d : Fin (n+1)) : ℝ := ∫ r, pathCorrelation n κ f d (x r) ∂μ + +def rootPathMean (μ : Measure R) (x : R→X) (n : ℕ) (κ : Fin n→Kernel X X) + (f : X→ℝ) : ℝ := ∫ r, pathMean n κ f (x r) ∂μ + +lemma rootPathCorrelation_integrable (μ : Measure R) [IsFiniteMeasure μ] + (x : R→X) (hx : Measurable x) (n : ℕ) (κ : Fin n→Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f : X→ℝ) (hf : Measurable f) + (C : ℝ) (hC : 0≤C) (hb : ∀ y, |f y|≤C) (d : Fin (n+1)) : + Integrable (fun r => pathCorrelation n κ f d (x r)) μ := + path_bounded_integrable μ _ ((pathCorrelation_measurable n κ f hf d).comp hx) + (C^2) (fun r => pathCorrelation_bound n κ hκ f C hC hb d (x r)) + +lemma rootPathCorrelation_nonneg (μ : Measure R) (x : R→X) + (n : ℕ) (κ : Fin n→Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (f : X→ℝ) (hf : Measurable f) (C : ℝ) (hC : 0≤C) (hb : ∀ y, |f y|≤C) + (d : Fin (n+1)) : 0≤rootPathCorrelation μ x n κ f d := + integral_nonneg fun r => pathCorrelation_nonneg n κ hκ f hf C hC hb d (x r) + +lemma rootPathCorrelation_monotone (μ : Measure R) [IsFiniteMeasure μ] + (x : R→X) (hx : Measurable x) (n : ℕ) (κ : Fin n→Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f : X→ℝ) (hf : Measurable f) + (C : ℝ) (hC : 0≤C) (hb : ∀ y, |f y|≤C) : + Monotone (rootPathCorrelation μ x n κ f) := by + intro i j hij + exact integral_mono (rootPathCorrelation_integrable μ x hx n κ hκ f hf C hC hb i) + (rootPathCorrelation_integrable μ x hx n κ hκ f hf C hC hb j) + (fun r => pathCorrelation_monotone n κ hκ f hf C hC hb (x r) hij) + +lemma rootPathCorrelation_bound (μ : Measure R) [IsProbabilityMeasure μ] + (x : R→X) (n : ℕ) (κ : Fin n→Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (f : X→ℝ) (C : ℝ) (hC : 0≤C) (hb : ∀ y, |f y|≤C) (d : Fin (n+1)) : + |rootPathCorrelation μ x n κ f d|≤C^2 := by + simpa only [rootPathCorrelation,Real.norm_eq_abs,probReal_univ,mul_one] using + norm_integral_le_of_norm_le_const (μ:=μ) (f:=fun r => pathCorrelation n κ f d (x r)) + (ae_of_all _ fun r => by + simpa only [Real.norm_eq_abs] using (pathCorrelation_bound n κ hκ f C hC hb d (x r))) + +lemma rootPathCorrelation_le_diagonal (μ : Measure R) [IsFiniteMeasure μ] + (x : R→X) (hx : Measurable x) (n : ℕ) (κ : Fin n→Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f g : X→ℝ) (hf : Measurable f) (hg : Measurable g) + (C D : ℝ) (hC : 0≤C) (hfB : ∀ y, |f y|≤C) (hgB : ∀ y, |g y|≤D) + (hfg : ∀ y, (f y)^2≤g y) (d : Fin (n+1)) : + rootPathCorrelation μ x n κ f d≤rootPathMean μ x n κ g := by + apply integral_mono (rootPathCorrelation_integrable μ x hx n κ hκ f hf C hC hfB d) + (path_bounded_integrable μ _ ((pathMean_measurable n κ g hg).comp hx) D + (fun r => pathMean_bound n κ hκ g D hgB (x r))) + exact fun r => pathCorrelation_le_diagonal n κ hκ f g hf hg C D hC hfB hgB hfg d (x r) + +lemma rootPathCorrelation_one (μ : Measure R) [IsProbabilityMeasure μ] + (x : R→X) (n : ℕ) (κ : Fin n→Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (d : Fin (n+1)) : rootPathCorrelation μ x n κ (fun _=>1) d=1 := by + simp only [rootPathCorrelation,pathCorrelation_one n κ hκ,integral_const,probReal_univ,one_smul] + +lemma rootPathCorrelation_parallel (μ : Measure R) (σ : Measure Q) [SFinite μ] [SFinite σ] + (x : R→X) (y : Q→Y) (n : ℕ) (κ : Fin n→Kernel X X) (η : Fin n→Kernel Y Y) + (hκ : ∀ i, IsMarkovKernel (κ i)) (hη : ∀ i, IsMarkovKernel (η i)) + (f : X→ℝ) (g : Y→ℝ) (hf : Measurable f) (hg : Measurable g) + (C D : ℝ) (hC : 0≤C) (hD : 0≤D) (hfB : ∀ a, |f a|≤C) (hgB : ∀ b, |g b|≤D) + (d : Fin (n+1)) : + rootPathCorrelation (μ.prod σ) (fun p => (x p.1,y p.2)) n (fun i => κ i ∥ₖ η i) + (fun p => f p.1*g p.2) d = + rootPathCorrelation μ x n κ f d * rootPathCorrelation σ y n η g d := by + unfold rootPathCorrelation + simp_rw [pathCorrelation_parallel n κ η hκ hη f g hf hg C D hC hD hfB hgB] + exact integral_prod_mul (fun r => pathCorrelation n κ f d (x r)) + (fun q => pathCorrelation n η g d (y q)) + +open scoped ENNReal NNReal BoundedContinuousFunction + +def residualResponse (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) (x : ℝ) : ℝ := + gaussianAverage s (expBCF 1 f * v) x / gaussianAverage s (expBCF 1 f) x + +lemma residualResponse_eq_tiltMean (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) (x : ℝ) : + residualResponse s f v x = + tiltMean (gaussianReal 0 s) (fun z => f (x+z)) (fun z => v (x+z)) 1 := by + simp only [residualResponse,gaussianAverage,tiltMean,tiltIntegral,tiltPartition, + Pi.mul_apply,expBCF_apply,one_mul] + +lemma residualResponse_continuous (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) : + Continuous (residualResponse s f v) := + (gaussianAverage_continuous s (expBCF 1 f*v)).div + (gaussianAverage_continuous s (expBCF 1 f)) + (fun x => (gaussianAverage_exp_pos s 1 f x).ne') + +lemma residualResponse_bound (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) (x : ℝ) : + |residualResponse s f v x|≤‖v‖ := by + rw [residualResponse_eq_tiltMean] + exact tilt_mean_bound (gaussianReal 0 s) (f.measurable.comp (measurable_const.add measurable_id)) + (v.measurable.comp (measurable_const.add measurable_id)) (norm_nonneg _) (norm_nonneg _) + (fun z => f.norm_coe_le_norm (x+z)) (fun z => v.norm_coe_le_norm (x+z)) 1 + +def residualResponseBCF (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound ⟨residualResponse s f v,residualResponse_continuous s f v⟩ + (2*‖v‖) (by + intro x y + change |residualResponse s f v x-residualResponse s f v y|≤2*‖v‖ + exact (abs_sub _ _).trans (by + linarith [residualResponse_bound s f v x, residualResponse_bound s f v y])) + +@[simp] lemma residualResponseBCF_apply (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) (x : ℝ) : + residualResponseBCF s f v x=residualResponse s f v x := rfl + +lemma residualResponse_weighted (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) (x : ℝ) : + gaussianAverage s (expBCF 1 f) x * residualResponse s f v x = + gaussianAverage s (expBCF 1 f*v) x := by + unfold residualResponse + exact mul_div_cancel₀ _ (gaussianAverage_exp_pos s 1 f x).ne' + +lemma residualResponse_jensen (s : ℝ≥0) (f v : ℝ →ᵇ ℝ) (x : ℝ) : + (residualResponse s f v x)^2≤residualResponse s f (v*v) x := by + have hH : Measurable (fun z => f (x+z)) := f.measurable.comp (measurable_const.add measurable_id) + have hV : Measurable (fun z => v (x+z)) := v.measurable.comp (measurable_const.add measurable_id) + have := tilt_law_probability (gaussianReal 0 s) hH (norm_nonneg f) + (fun z => f.norm_coe_le_norm (x+z)) 1 + let μ := tiltLaw (gaussianReal 0 s) (fun z => f (x+z)) 1 + have hLp : MemLp (fun z => v (x+z)) 2 μ := + MemLp.of_bound hV.aestronglyMeasurable ‖v‖ (ae_of_all _ fun z => v.norm_coe_le_norm (x+z)) + have h := variance_nonneg (fun z => v (x+z)) μ + rw [variance_eq_sub hLp] at h + simp only [Pi.pow_apply] at h + have hsq : (∫ z, v (x+z) ∂μ)^2≤∫ z, (v (x+z))^2 ∂μ := sub_nonneg.mp h + simp only [μ,tilt_law_integral (gaussianReal 0 s) hH (norm_nonneg f) + (fun z => f.norm_coe_le_norm (x+z)) 1,←residualResponse_eq_tiltMean] at hsq + simpa only [residualResponse_eq_tiltMean,BoundedContinuousFunction.mul_apply,pow_two] using hsq + +lemma residualResponse_one (s : ℝ≥0) (f : ℝ →ᵇ ℝ) (x : ℝ) : + residualResponse s f 1 x=1 := by + change gaussianAverage s (expBCF 1 f * 1 : ℝ →ᵇ ℝ) x / _=1 + rw [mul_one] + exact div_self (gaussianAverage_exp_pos s 1 f x).ne' + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TiltedPathProduct.lean b/lean/OAI/Probability/Perceptron/Variational/TiltedPathProduct.lean new file mode 100644 index 0000000000000000000000000000000000000000..6d1c23defeb16ff8a06d3d6a6809bc76ec064f5c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TiltedPathProduct.lean @@ -0,0 +1,156 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.ProductMarkLaw +import OAI.Probability.Perceptron.Variational.TiltedVisitKernel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {X Y S T : Type} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace S] [MeasurableSpace T] + +lemma pathMean_parallel (n : ℕ) (κ : Fin n → Kernel X X) (η : Fin n → Kernel Y Y) + (hκ : ∀ i, IsMarkovKernel (κ i)) (hη : ∀ i, IsMarkovKernel (η i)) + (f : X → ℝ) (g : Y → ℝ) (hf : Measurable f) (hg : Measurable g) + (C D : ℝ) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hfB : ∀ x, |f x| ≤ C) (hgB : ∀ y, |g y| ≤ D) (x : X) (y : Y) : + pathMean n (fun i => κ i ∥ₖ η i) (fun p => f p.1*g p.2) (x,y) = + pathMean n κ f x * pathMean n η g y := by + have hfg : Measurable (fun p : X×Y => f p.1*g p.2) := + (hf.comp measurable_fst).mul (hg.comp measurable_snd) + have hB : ∀ p : X×Y, |f p.1*g p.2| ≤ C*D := fun p => by + simpa only [abs_mul, abs_of_nonneg hD] using + mul_le_mul (hfB p.1) ((hgB p.2).trans (le_abs_self D)) (abs_nonneg _) hC + induction n generalizing x y with + | zero => + simp only [pathMean,pathOneKernel,Kernel.id_apply] + rw [integral_dirac' _ _ hfg.stronglyMeasurable, + integral_dirac' _ _ hf.stronglyMeasurable,integral_dirac' _ _ hg.stronglyMeasurable] + | succ n ih => + have := hκ 0 + have := hη 0 + have hpar : ∀ i, IsMarkovKernel (κ i ∥ₖ η i) := by intro i; have := hκ i; have := hη i; infer_instance + rw [pathMean_succ n _ hpar _ hfg (C*D) hB, + pathMean_succ n κ hκ f hf C hfB,pathMean_succ n η hη g hg D hgB, + Kernel.parallelComp_apply] + simp_rw [ih _ _ (fun i => hκ i.succ) (fun i => hη i.succ)] + exact integral_prod_mul _ _ + +lemma pathCorrelation_parallel (n : ℕ) (κ : Fin n → Kernel X X) (η : Fin n → Kernel Y Y) + (hκ : ∀ i, IsMarkovKernel (κ i)) (hη : ∀ i, IsMarkovKernel (η i)) + (f : X → ℝ) (g : Y → ℝ) (hf : Measurable f) (hg : Measurable g) + (C D : ℝ) (hC : 0 ≤ C) (hD : 0 ≤ D) + (hfB : ∀ x, |f x| ≤ C) (hgB : ∀ y, |g y| ≤ D) (d : Fin (n+1)) (x : X) (y : Y) : + pathCorrelation n (fun i => κ i ∥ₖ η i) (fun p => f p.1*g p.2) d (x,y) = + pathCorrelation n κ f d x * pathCorrelation n η g d y := by + have hfg : Measurable (fun p : X×Y => f p.1*g p.2) := + (hf.comp measurable_fst).mul (hg.comp measurable_snd) + have hB : ∀ p : X×Y, |f p.1*g p.2| ≤ C*D := fun p => by + rw [abs_mul]; exact mul_le_mul (hfB p.1) (hgB p.2) (abs_nonneg _) hC + induction n generalizing x y with + | zero => + have hd : d=0 := by apply Fin.ext; omega + rw [hd,pathCorrelation_zero _ _ (fun i => Fin.elim0 i) _ hfg, + pathCorrelation_zero _ κ hκ f hf,pathCorrelation_zero _ η hη g hg, + pathMean_parallel 0 κ η hκ hη f g hf hg C D hC hD hfB hgB x y] + ring + | succ n ih => + have := hκ 0 + have := hη 0 + have hpar : ∀ i, IsMarkovKernel (κ i ∥ₖ η i) := by intro i; have := hκ i; have := hη i; infer_instance + induction d using Fin.cases with + | zero => + rw [pathCorrelation_zero _ _ hpar _ hfg,pathCorrelation_zero _ κ hκ f hf, + pathCorrelation_zero _ η hη g hg, + pathMean_parallel _ κ η hκ hη f g hf hg C D hC hD hfB hgB x y] + ring + | succ d => + rw [pathCorrelation_succ n _ hpar _ hfg (C*D) (mul_nonneg hC hD) hB, + pathCorrelation_succ n κ hκ f hf C hC hfB, + pathCorrelation_succ n η hη g hg D hD hgB,Kernel.parallelComp_apply] + simp_rw [ih _ _ (fun i => hκ i.succ) (fun i => hη i.succ)] + exact integral_prod_mul _ _ + +lemma finiteCascadeShifts_add_product (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (n : ℕ) (z : Fin n→ℝ) (hz : ∀ i, 0 (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) n z + (fun x => H x.1+G x.2) i p = + finiteCascadeShifts ν step₁ n z H i (p.1.1,p.2.1)+ + finiteCascadeShifts ρ step₂ n z G i (p.1.2,p.2.2) := by + induction n with + | zero => exact i.elim0 + | succ n ih => + induction i using Fin.cases with + | zero => + simp only [finiteCascadeShifts,Fin.cases_zero] + rw [finiteCascadeLogRecursion_add_product ν ρ step₁ step₂ n _ (fun i => hz i.succ) hH.2 hG.2, + finiteCascadeLogRecursion_add_product ν ρ step₁ step₂ (n+1) z hz hH hG] + ring + | succ i => + exact ih (fun i => z i.succ) (fun i => hz i.succ) hH.2 hG.2 i + +lemma tiltedStateStep_parallel (ν : ProbabilityMeasure S) (ρ : ProbabilityMeasure T) + (step₁ : X×S→X) (step₂ : Y×T→Y) (hs₁ : Measurable step₁) (hs₂ : Measurable step₂) + (z : ℝ) (F : X×S→ℝ) (G : Y×T→ℝ) (hF : Measurable F) (hG : Measurable G) + (hFI : ∀ x, Integrable (fun s => Real.exp (z*F (x,s))) ν) + (hGI : ∀ y, Integrable (fun t => Real.exp (z*G (y,t))) ρ) + (hFM : ∀ x, (∫ s, Real.exp (z*F (x,s)) ∂ν)=1) + (hGM : ∀ y, (∫ t, Real.exp (z*G (y,t)) ∂ρ)=1) : + tiltedStateStep (productMarkLaw ν ρ) + (fun p : (X×Y)×(S×T) => (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) z + (fun p => F (p.1.1,p.2.1)+G (p.1.2,p.2.2)) = + tiltedStateStep ν step₁ z F ∥ₖ tiltedStateStep ρ step₂ z G := by + have hs : Measurable (fun p : (X×Y)×(S×T) => + (step₁ (p.1.1,p.2.1),step₂ (p.1.2,p.2.2))) := by fun_prop + have hFG : Measurable (fun p : (X×Y)×(S×T) => F (p.1.1,p.2.1)+G (p.1.2,p.2.2)) := by fun_prop + have hI (x : X×Y) : Integrable (fun s : S×T => Real.exp (z*(F (x.1,s.1)+G (x.2,s.2)))) + (productMarkLaw ν ρ) := by + simp_rw [mul_add,Real.exp_add] + exact (hFI x.1).mul_prod (hGI x.2) + have hM (x : X×Y) : (∫ s : S×T, Real.exp (z*(F (x.1,s.1)+G (x.2,s.2))) + ∂productMarkLaw ν ρ)=1 := by + simp_rw [mul_add,Real.exp_add] + change (∫ s : S×T, Real.exp (z*F (x.1,s.1))*Real.exp (z*G (x.2,s.2)) + ∂(ν : Measure S).prod (ρ : Measure T))=1 + exact (integral_prod_mul (fun s => Real.exp (z*F (x.1,s))) + (fun t => Real.exp (z*G (x.2,t)))).trans (by rw [hFM,hGM,one_mul]) + have := tiltedStateStep_markov ν step₁ hs₁ z F hF hFI hFM + have := tiltedStateStep_markov ρ step₂ hs₂ z G hG hGI hGM + apply Kernel.ext + intro x + apply Measure.ext_of_lintegral + intro f hf + rw [tiltedStateStep_lintegral (productMarkLaw ν ρ) _ hs z _ hFG hI hM f hf, + Kernel.parallelComp_apply,lintegral_prod _ hf.aemeasurable] + have hi (a : X) := tiltedStateStep_lintegral ρ step₂ hs₂ z G hG hGI hGM + (fun b => f (a,b)) (hf.comp (measurable_const.prodMk measurable_id)) x.2 + simp_rw [hi] + have hm : Measurable (fun a : X => ∫⁻ t, ENNReal.ofReal (Real.exp (z*G (x.2,t)))* + f (a,step₂ (x.2,t)) ∂ρ) := by + apply Measurable.lintegral_prod_right + change Measurable (fun p : X×T => ENNReal.ofReal (Real.exp (z*G (x.2,p.2)))* + f (p.1,step₂ (x.2,p.2))) + fun_prop + rw [tiltedStateStep_lintegral ν step₁ hs₁ z F hF hFI hFM _ hm] + change (∫⁻ s : S×T, ENNReal.ofReal (Real.exp (z*(F (x.1,s.1)+G (x.2,s.2))))* + f (step₁ (x.1,s.1),step₂ (x.2,s.2)) ∂(ν : Measure S).prod (ρ : Measure T))=_ + rw [lintegral_prod] + · apply lintegral_congr + intro s + rw [←lintegral_const_mul] + · apply lintegral_congr + intro t + rw [mul_add,Real.exp_add,ENNReal.ofReal_mul (Real.exp_pos _).le] + exact mul_assoc _ _ _ + · fun_prop + · fun_prop + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TiltedVisitKernel.lean b/lean/OAI/Probability/Perceptron/Variational/TiltedVisitKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..a804f4ea315247d79ab4d4dcde31bad697e44df7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TiltedVisitKernel.lean @@ -0,0 +1,240 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] + +def tiltedMarkKernel (ν : ProbabilityMeasure S) (z : ℝ) (F : X×S → ℝ) : Kernel X S := + (Kernel.const X (ν : Measure S)).withDensity + (fun x s => ENNReal.ofReal (Real.exp (z*F (x,s)))) + +lemma tiltedMarkKernel_markov (ν : ProbabilityMeasure S) (z : ℝ) (F : X×S → ℝ) + (hF : Measurable F) (hI : ∀ x, Integrable (fun s => Real.exp (z*F (x,s))) ν) + (hM : ∀ x, (∫ s, Real.exp (z*F (x,s)) ∂ν) = 1) : + IsMarkovKernel (tiltedMarkKernel ν z F) := by + refine ⟨fun x => ⟨?_⟩⟩ + rw [tiltedMarkKernel,Kernel.withDensity_apply _ ((hF.const_mul z).exp.ennreal_ofReal)] + simp only [Kernel.const_apply,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + rw [← ofReal_integral_eq_lintegral_ofReal (hI x) + (Filter.Eventually.of_forall (fun s => (Real.exp_pos _).le)),hM x] + exact ENNReal.ofReal_one + +def tiltedStateStep (ν : ProbabilityMeasure S) (step : X×S → X) + (z : ℝ) (F : X×S → ℝ) : Kernel X X := + (Kernel.id ×ₖ tiltedMarkKernel ν z F).map step + +lemma tiltedStateStep_markov (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (z : ℝ) (F : X×S → ℝ) + (hF : Measurable F) (hI : ∀ x, Integrable (fun s => Real.exp (z*F (x,s))) ν) + (hM : ∀ x, (∫ s, Real.exp (z*F (x,s)) ∂ν) = 1) : + IsMarkovKernel (tiltedStateStep ν step z F) := by + have := tiltedMarkKernel_markov ν z F hF hI hM + exact Kernel.IsMarkovKernel.map _ hs + +lemma tiltedStateStep_lintegral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (z : ℝ) (F : X×S → ℝ) + (hF : Measurable F) (hI : ∀ x, Integrable (fun s => Real.exp (z*F (x,s))) ν) + (hM : ∀ x, (∫ s, Real.exp (z*F (x,s)) ∂ν) = 1) + (h : X → ℝ≥0∞) (hh : Measurable h) (x : X) : + (∫⁻ y, h y ∂tiltedStateStep ν step z F x) = + ∫⁻ s, ENNReal.ofReal (Real.exp (z*F (x,s)))*h (step (x,s)) ∂ν := by + have := tiltedMarkKernel_markov ν z F hF hI hM + rw [tiltedStateStep,Kernel.lintegral_map _ hs _ hh, + Kernel.lintegral_id_prod (show Measurable (fun p : X×S => h (step p)) from hh.comp hs)] + exact Kernel.lintegral_withDensity _ ((hF.const_mul z).exp.ennreal_ofReal) x + ((hh.comp hs).comp (measurable_const.prodMk measurable_id)) + +def pathOneKernel : (n : ℕ) → (Fin n → Kernel X X) → Kernel X X + | 0, _ => Kernel.id + | n+1, κ => pathOneKernel n (fun i => κ i.succ) ∘ₖ κ 0 + +def pathPairKernel : (n : ℕ) → (Fin n → Kernel X X) → Fin (n+1) → Kernel X (X×X) + | 0, _, _ => Kernel.deterministic (fun x => (x,x)) (measurable_id.prodMk measurable_id) + | n+1, κ, d => Fin.cases + (pathOneKernel (n+1) κ ×ₖ pathOneKernel (n+1) κ) + (fun j => pathPairKernel n (fun i => κ i.succ) j ∘ₖ κ 0) d + +lemma pathOneKernel_markov (n : ℕ) (κ : Fin n → Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) : IsMarkovKernel (pathOneKernel n κ) := by + induction n with + | zero => dsimp [pathOneKernel]; infer_instance + | succ n ih => + have := hκ 0 + have := ih (fun i => κ i.succ) (fun i => hκ i.succ) + dsimp [pathOneKernel]; infer_instance + +lemma pathPairKernel_markov (n : ℕ) (κ : Fin n → Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (d : Fin (n+1)) : + IsMarkovKernel (pathPairKernel n κ d) := by + induction n with + | zero => dsimp [pathPairKernel]; infer_instance + | succ n ih => + refine Fin.cases ?_ (fun j => ?_) d + · have := pathOneKernel_markov (n+1) κ hκ + simp only [pathPairKernel,Fin.cases_zero]; infer_instance + · have := hκ 0 + have := ih (fun i => κ i.succ) (fun i => hκ i.succ) j + simp only [pathPairKernel,Fin.cases_succ]; infer_instance + +lemma path_bounded_integrable (μ : Measure X) [IsFiniteMeasure μ] + (f : X → ℝ) (hf : Measurable f) (C : ℝ) (hb : ∀ x, |f x| ≤ C) : Integrable f μ := + Integrable.of_bound hf.aestronglyMeasurable C (Filter.Eventually.of_forall (fun x => by simpa only [Real.norm_eq_abs] using hb x)) + +lemma bounded_probability_mean_sq (μ : Measure X) [IsProbabilityMeasure μ] + (f : X → ℝ) (hf : Measurable f) (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, |f x| ≤ C) : + (∫ x, f x ∂μ)^2 ≤ ∫ x, (f x)^2 ∂μ := by + have hi := path_bounded_integrable μ f hf C hb + have hs : Integrable (fun x => (f x)^2) μ := + path_bounded_integrable μ _ (hf.pow_const 2) (C^2) (fun x => by + rw [abs_of_nonneg (sq_nonneg _)] + nlinarith [hb x,abs_nonneg (f x),sq_abs (f x)]) + let m := ∫ x, f x ∂μ + have he : (∫ x, (f x-m)^2 ∂μ) = (∫ x, (f x)^2 ∂μ)-m^2 := by + calc + _ = ∫ x, (f x)^2 - 2*m*f x + m^2 ∂μ := by congr 1; funext x; ring + _ = (∫ x, (f x)^2 ∂μ) - 2*m*m + m^2 := by + rw [integral_add (f := fun x => (f x)^2-2*m*f x) (g := fun _ => m^2) + (hs.sub (hi.const_mul (2*m))) (integrable_const _), + integral_sub (f := fun x => (f x)^2) (g := fun x => 2*m*f x) hs (hi.const_mul (2*m)), + integral_const_mul,integral_const] + simp [m] + _ = _ := by ring + have hn : 0 ≤ ∫ x, (f x-m)^2 ∂μ := integral_nonneg (fun x => sq_nonneg _) + rw [he] at hn + exact sub_nonneg.mp hn + +def pathMean (n : ℕ) (κ : Fin n → Kernel X X) (f : X → ℝ) (x : X) : ℝ := + ∫ y, f y ∂pathOneKernel n κ x + +def pathCorrelation (n : ℕ) (κ : Fin n → Kernel X X) (f : X → ℝ) + (d : Fin (n+1)) (x : X) : ℝ := + ∫ y, f y.1*f y.2 ∂pathPairKernel n κ d x + +lemma pathMean_measurable (n : ℕ) (κ : Fin n → Kernel X X) + (f : X → ℝ) (hf : Measurable f) : Measurable (pathMean n κ f) := + hf.stronglyMeasurable.integral_kernel.measurable + +lemma pathCorrelation_measurable (n : ℕ) (κ : Fin n → Kernel X X) + (f : X → ℝ) (hf : Measurable f) (d : Fin (n+1)) : + Measurable (pathCorrelation n κ f d) := + ((hf.comp measurable_fst).mul (hf.comp measurable_snd)).stronglyMeasurable.integral_kernel.measurable + +lemma pathMean_bound (n : ℕ) (κ : Fin n → Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (f : X → ℝ) (C : ℝ) (hb : ∀ x, |f x| ≤ C) (x : X) : |pathMean n κ f x| ≤ C := by + have := pathOneKernel_markov n κ hκ + simpa [pathMean] using norm_integral_le_of_norm_le_const + (μ := pathOneKernel n κ x) (f := f) + (Filter.Eventually.of_forall (fun x => by simpa only [Real.norm_eq_abs] using hb x)) + +lemma pathCorrelation_bound (n : ℕ) (κ : Fin n → Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (f : X → ℝ) (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, |f x| ≤ C) + (d : Fin (n+1)) (x : X) : |pathCorrelation n κ f d x| ≤ C^2 := by + have := pathPairKernel_markov n κ hκ d + have hb' (y : X×X) : ‖f y.1*f y.2‖ ≤ C^2 := by + rw [Real.norm_eq_abs,abs_mul,pow_two] + exact mul_le_mul (hb y.1) (hb y.2) (abs_nonneg _) hC + simpa [pathCorrelation] using norm_integral_le_of_norm_le_const + (μ := pathPairKernel n κ d x) (Filter.Eventually.of_forall hb') + +lemma pathMean_succ (n : ℕ) (κ : Fin (n+1) → Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (f : X → ℝ) (hf : Measurable f) (C : ℝ) (hb : ∀ x, |f x| ≤ C) (x : X) : + pathMean (n+1) κ f x = ∫ y, pathMean n (fun i => κ i.succ) f y ∂κ 0 x := by + have := hκ 0 + have := pathOneKernel_markov n (fun i => κ i.succ) (fun i => hκ i.succ) + exact Kernel.integral_comp (path_bounded_integrable _ f hf C hb) + +lemma pathCorrelation_zero (n : ℕ) (κ : Fin n → Kernel X X) (hκ : ∀ i, IsMarkovKernel (κ i)) + (f : X → ℝ) (hf : Measurable f) (x : X) : + pathCorrelation n κ f 0 x = (pathMean n κ f x)^2 := by + cases n with + | zero => + simp only [pathCorrelation,pathPairKernel,Kernel.deterministic_apply,pathMean,pathOneKernel, + Kernel.id_apply] + rw [integral_dirac' (fun y : X×X => f y.1*f y.2) (x,x) + (show StronglyMeasurable (fun y : X×X => f y.1*f y.2) from + ((hf.comp measurable_fst).mul (hf.comp measurable_snd)).stronglyMeasurable), + integral_dirac' _ _ hf.stronglyMeasurable,pow_two] + | succ n => + have := pathOneKernel_markov (n+1) κ hκ + simp only [pathCorrelation,pathPairKernel,Fin.cases_zero,Kernel.prod_apply] + rw [integral_prod_mul] + exact (pow_two _).symm + +lemma pathCorrelation_succ (n : ℕ) (κ : Fin (n+1) → Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f : X → ℝ) (hf : Measurable f) + (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, |f x| ≤ C) (d : Fin (n+1)) (x : X) : + pathCorrelation (n+1) κ f d.succ x = + ∫ y, pathCorrelation n (fun i => κ i.succ) f d y ∂κ 0 x := by + have := hκ 0 + have := pathPairKernel_markov n (fun i => κ i.succ) (fun i => hκ i.succ) d + simp only [pathCorrelation,pathPairKernel,Fin.cases_succ] + apply Kernel.integral_comp + apply path_bounded_integrable _ _ ((hf.comp measurable_fst).mul (hf.comp measurable_snd)) (C^2) + intro y + change |f y.1*f y.2| ≤ C^2 + rw [abs_mul,pow_two] + exact mul_le_mul (hb y.1) (hb y.2) (abs_nonneg _) hC + +lemma pathCorrelation_nonneg (n : ℕ) (κ : Fin n → Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f : X → ℝ) (hf : Measurable f) + (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, |f x| ≤ C) (d : Fin (n+1)) (x : X) : + 0 ≤ pathCorrelation n κ f d x := by + induction n generalizing x with + | zero => + have hd : d=0 := by apply Fin.ext; omega + rw [hd,pathCorrelation_zero _ _ hκ f hf] + exact sq_nonneg _ + | succ n ih => + induction d using Fin.cases with + | zero => rw [pathCorrelation_zero _ _ hκ f hf]; exact sq_nonneg _ + | succ d => + rw [pathCorrelation_succ n κ hκ f hf C hC hb d x] + exact integral_nonneg (fun y => ih _ (fun i => hκ i.succ) d y) + +lemma pathCorrelation_monotone (n : ℕ) (κ : Fin n → Kernel X X) + (hκ : ∀ i, IsMarkovKernel (κ i)) (f : X → ℝ) (hf : Measurable f) + (C : ℝ) (hC : 0 ≤ C) (hb : ∀ x, |f x| ≤ C) (x : X) : + Monotone (fun d => pathCorrelation n κ f d x) := by + induction n generalizing x with + | zero => exact fun a b _ => le_of_eq (congrArg (fun d => pathCorrelation 0 κ f d x) + (by apply Fin.ext; omega)) + | succ n ih => + have := hκ 0 + let κ' : Fin n → Kernel X X := fun i => κ i.succ + have hκ' : ∀ i, IsMarkovKernel (κ' i) := fun i => hκ i.succ + have hi (d : Fin (n+1)) : Integrable (pathCorrelation n κ' f d) (κ 0 x) := + path_bounded_integrable _ _ (pathCorrelation_measurable n κ' f hf d) (C^2) + (fun y => pathCorrelation_bound n κ' hκ' f C hC hb d y) + intro a b hab + change pathCorrelation (n+1) κ f a x ≤ pathCorrelation (n+1) κ f b x + induction a using Fin.cases with + | zero => + induction b using Fin.cases with + | zero => exact le_rfl + | succ b => + rw [pathCorrelation_zero _ _ hκ f hf,pathMean_succ n κ hκ f hf C hb, + pathCorrelation_succ n κ hκ f hf C hC hb] + have hJ := bounded_probability_mean_sq (κ 0 x) (pathMean n κ' f) + (pathMean_measurable n κ' f hf) C hC (pathMean_bound n κ' hκ' f C hb) + apply hJ.trans + have he : (fun y => (pathMean n κ' f y)^2) = pathCorrelation n κ' f 0 := by + funext y; exact (pathCorrelation_zero n κ' hκ' f hf y).symm + rw [he] + exact integral_mono (hi 0) (hi b) (fun y => ih κ' hκ' y (Fin.zero_le b)) + | succ a => + induction b using Fin.cases with + | zero => simp at hab + | succ b => + rw [pathCorrelation_succ n κ hκ f hf C hC hb, + pathCorrelation_succ n κ hκ f hf C hC hb] + exact integral_mono (hi a) (hi b) (fun y => ih κ' hκ' y (Fin.succ_le_succ_iff.mp hab)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TiltedVisitKernelLaw.lean b/lean/OAI/Probability/Perceptron/Variational/TiltedVisitKernelLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..5b7639e6d37cd122d2af8e3220519712723ea749 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TiltedVisitKernelLaw.lean @@ -0,0 +1,176 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.IndexedTwoShape +import OAI.Probability.Perceptron.Variational.TiltedVisitKernel + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy +variable {X S : Type} [MeasurableSpace X] [MeasurableSpace S] [Nonempty S] + +omit [Nonempty S] in +lemma pathOneKernel_lintegral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (F : Fin n → X×S → ℝ) + (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (h : X → ℝ≥0∞) (hh : Measurable h) (x : X) : + (∫⁻ y, h y ∂pathOneKernel n (fun i => tiltedStateStep ν step (z i) (F i)) x) = + decoratedShapeMarkValue ν step n z F (oneDecoratedVisit h n) x := by + induction n generalizing x with + | zero => + simp only [pathOneKernel,Kernel.id_apply,decoratedShapeMarkValue,oneDecoratedVisit] + exact lintegral_dirac' _ hh + | succ n ih => + rw [pathOneKernel,Kernel.lintegral_comp _ _ _ hh] + simp_rw [ih (fun i => z i.succ) (fun i => F i.succ) (fun i => hF i.succ) + (fun i => hI i.succ) (fun i => hM i.succ)] + rw [tiltedStateStep_lintegral ν step hs (z 0) (F 0) (hF 0) (hI 0) (hM 0) _ + (decoratedShapeMarkValue_measurable ν step hs n _ _ (fun i => hF i.succ) _ + (oneDecoratedVisit_valid hh n))] + simp [decoratedShapeMarkValue,oneDecoratedVisit] + +omit [Nonempty S] in +lemma pathPairKernel_lintegral (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (F : Fin n → X×S → ℝ) + (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) + (h k : X → ℝ≥0∞) (hh : Measurable h) (hk : Measurable k) (d : Fin (n+1)) (x : X) : + (∫⁻ p, h p.1*k p.2 ∂pathPairKernel n (fun i => tiltedStateStep ν step (z i) (F i)) d x) = + decoratedShapeMarkValue ν step n z F (twoDecoratedVisit h k n d) x := by + have hg : Measurable (fun p : X×X => h p.1*k p.2) := (hh.comp measurable_fst).mul (hk.comp measurable_snd) + induction n generalizing x with + | zero => + rw [pathPairKernel,Kernel.lintegral_deterministic' _ hg] + rfl + | succ n ih => + have hκ i := tiltedStateStep_markov ν step hs (z i) (F i) (hF i) (hI i) (hM i) + have := pathOneKernel_markov (n+1) (fun i => tiltedStateStep ν step (z i) (F i)) hκ + induction d using Fin.cases with + | zero => + simp only [pathPairKernel,Fin.cases_zero] + rw [Kernel.lintegral_prod _ _ _ hg] + simp_rw [lintegral_const_mul _ hk,lintegral_mul_const _ hh] + rw [pathOneKernel_lintegral ν step hs (n+1) z F hF hI hM h hh x, + pathOneKernel_lintegral ν step hs (n+1) z F hF hI hM k hk x] + simp [decoratedShapeMarkValue,oneDecoratedVisit,twoDecoratedVisit] + | succ d => + simp only [pathPairKernel,Fin.cases_succ] + rw [Kernel.lintegral_comp _ _ _ hg] + simp_rw [ih (fun i => z i.succ) (fun i => F i.succ) (fun i => hF i.succ) + (fun i => hI i.succ) (fun i => hM i.succ) d] + rw [tiltedStateStep_lintegral ν step hs (z 0) (F 0) (hF 0) (hI 0) (hM 0) _ + (decoratedShapeMarkValue_measurable ν step hs n _ _ (fun i => hF i.succ) _ + (twoDecoratedVisit_valid hh hk n d))] + simp [decoratedShapeMarkValue,twoDecoratedVisit] + +section +variable {P Y I : Type} [MeasurableSpace P] [MeasurableSpace Y] [Countable I] + +def atomicVisitKernel (q : I → P → ℝ≥0∞) (hq : ∀ i, Measurable (q i)) + (s : I → P → Y) (hs : ∀ i, Measurable (s i)) : Kernel P Y := + ⟨fun p => Measure.sum (fun i => q i p • Measure.dirac (s i p)), by + apply Measure.measurable_of_measurable_coe + intro t ht + simp only [Measure.sum_apply _ ht,Measure.smul_apply] + exact Measurable.tsum (fun i => (hq i).mul ((Measure.measurable_coe ht).comp + (Measure.measurable_dirac.comp (hs i))))⟩ + +lemma atomicVisitKernel_lintegral (q : I → P → ℝ≥0∞) (hq : ∀ i, Measurable (q i)) + (s : I → P → Y) (hs : ∀ i, Measurable (s i)) (h : Y → ℝ≥0∞) (hh : Measurable h) (p : P) : + (∫⁻ y, h y ∂atomicVisitKernel q hq s hs p) = ∑' i, q i p*h (s i p) := by + change (∫⁻ y, h y ∂Measure.sum (fun i => q i p • Measure.dirac (s i p))) = _ + rw [lintegral_sum_measure] + simp_rw [lintegral_smul_measure,smul_eq_mul,lintegral_dirac' _ hh] + +lemma atomicVisitKernel_finite (q : I → P → ℝ≥0∞) (hq : ∀ i, Measurable (q i)) + (s : I → P → Y) (hs : ∀ i, Measurable (s i)) (hb : ∀ p, (∑' i, q i p) ≤ 1) : + IsFiniteKernel (atomicVisitKernel q hq s hs) := by + refine ⟨1,ENNReal.one_lt_top,fun p => ?_⟩ + change Measure.sum (fun i => q i p • Measure.dirac (s i p)) univ ≤ 1 + simpa [Measure.sum_apply _ MeasurableSet.univ,Measure.smul_apply] using hb p + +lemma atomicVisitLaw_lintegral (q : I → P → ℝ≥0∞) (hq : ∀ i, Measurable (q i)) + (s : I → P → Y) (hs : ∀ i, Measurable (s i)) (μ : Measure P) + (h : Y → ℝ≥0∞) (hh : Measurable h) : + (∫⁻ y, h y ∂(atomicVisitKernel q hq s hs ∘ₘ μ)) = ∫⁻ p, ∑' i, q i p*h (s i p) ∂μ := by + rw [Measure.comp_eq_comp_const_apply,Kernel.lintegral_comp _ _ _ hh] + simp_rw [atomicVisitKernel_lintegral q hq s hs h hh,Kernel.const_apply] + +end + +omit [MeasurableSpace X] [Nonempty S] in +lemma indexedTiltedProbability_mass_le (step : X×S → X) (n : ℕ) (F : Fin n → X×S → ℝ) + (p : X×(IndexedCascadeBase n×IndexedCascadeMarks S n)) : + (∑' l, indexedTiltedProbability step n F p l) ≤ 1 := by + simp only [indexedTiltedProbability,ENNReal.tsum_mul_left] + exact ENNReal.inv_mul_le_one _ + +omit [Nonempty S] in +lemma indexedTiltedProbability_fixed_measurable (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (x : X) (l : IndexedLeaf n) : + Measurable (fun p : IndexedCascadeBase n×IndexedCascadeMarks S n => + indexedTiltedProbability step n F (x,p) l) := by + have hm : Measurable (fun p : IndexedCascadeBase n×IndexedCascadeMarks S n => ((x,p),l)) := + (measurable_const.prodMk measurable_id).prodMk measurable_const + have hc := (indexedTiltedProbability_measurable hs n F hF).comp hm + dsimp only [Function.comp_def, Function.uncurry_def] at hc + exact hc + +omit [Nonempty S] in +lemma indexedLeafState_fixed_measurable (step : X×S → X) (hs : Measurable step) + (n : ℕ) (x : X) (l : IndexedLeaf n) : + Measurable (fun p : IndexedCascadeBase n×IndexedCascadeMarks S n => + indexedLeafState step n (x,p.2) l) := by + have hm : Measurable (fun p : IndexedCascadeBase n×IndexedCascadeMarks S n => ((x,p.2),l)) := + (measurable_const.prodMk measurable_snd).prodMk measurable_const + exact (indexedLeafState_measurable hs n).comp hm + +def indexedOneStateKernel (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) (x : X) : + Kernel (IndexedCascadeBase n×IndexedCascadeMarks S n) X := + atomicVisitKernel (I := IndexedLeaf n) + (P := IndexedCascadeBase n×IndexedCascadeMarks S n) (Y := X) + (fun l p => indexedTiltedProbability step n F (x,p) l) + (indexedTiltedProbability_fixed_measurable step hs n F hF x) + (fun l p => indexedLeafState step n (x,p.2) l) + (indexedLeafState_fixed_measurable step hs n x) + +omit [Nonempty S] in +instance indexedOneStateKernel_finite (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) (x : X) : + IsFiniteKernel (indexedOneStateKernel step hs n F hF x) := + atomicVisitKernel_finite _ _ _ _ (fun p => indexedTiltedProbability_mass_le step n F (x,p)) + +omit [Nonempty S] in +lemma indexedOneStateKernel_lintegral (step : X×S → X) (hs : Measurable step) + (n : ℕ) (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) (x : X) + (h : X → ℝ≥0∞) (hh : Measurable h) (p : IndexedCascadeBase n×IndexedCascadeMarks S n) : + (∫⁻ y, h y ∂indexedOneStateKernel step hs n F hF x p) = indexedOneVisit step n F h (x,p) := + atomicVisitKernel_lintegral _ _ _ _ h hh p + +lemma indexedOneStateLaw_eq (ν : ProbabilityMeasure S) (step : X×S → X) + (hs : Measurable step) (n : ℕ) (z : Fin n → ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 < z i) (hz1 : ∀ i, z i < 1) + (F : Fin n → X×S → ℝ) (hF : ∀ i, Measurable (F i)) + (hI : ∀ i x, Integrable (fun s => Real.exp (z i*F i (x,s))) ν) + (hM : ∀ i x, (∫ s, Real.exp (z i*F i (x,s)) ∂ν) = 1) (x : X) : + indexedOneStateKernel step hs n F hF x ∘ₘ + ((indexedCascadeBaseLaw n z : Measure (IndexedCascadeBase n)).prod + (indexedCascadeMarksLaw ν n : Measure (IndexedCascadeMarks S n))) = + pathOneKernel n (fun i => tiltedStateStep ν step (z i) (F i)) x := by + apply Measure.ext_of_lintegral + intro h hh + rw [Measure.comp_eq_comp_const_apply,Kernel.lintegral_comp _ _ _ hh] + simp_rw [indexedOneStateKernel_lintegral step hs n F hF x h hh,Kernel.const_apply] + rw [indexedOneVisit_integral ν step hs n z hz hz0 hz1 F hF hI hM h hh x, + pathOneKernel_lintegral ν step hs n z F hF hI hM h hh x] + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/Trial.lean b/lean/OAI/Probability/Perceptron/Variational/Trial.lean new file mode 100644 index 0000000000000000000000000000000000000000..985f28f08e666d1aaa3d60b92ab01f28c9d20391 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/Trial.lean @@ -0,0 +1,431 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +@[simp] theorem timeLaw_eq_volume : timeLaw = (volume : Measure Time) := rfl + +instance : IsProbabilityMeasure timeLaw := by + rw [timeLaw_eq_volume] + infer_instance + +instance : NullSingletonClass timeLaw := by + rw [timeLaw_eq_volume] + infer_instance + +theorem progressive_zero (P : Measure BrownianPath) : + Progressive P (fun _ _ => 0) := by + intro t + exact measurable_const + +@[simp] theorem controlCost_zero (P : Measure BrownianPath) (m : Trial) : + controlCost P m (fun _ _ => 0) = 0 := by + simp [controlCost] + +@[simp] theorem controlPayoff_zero (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) (m : Trial) : + controlPayoff P f m (fun _ _ => 0) = ∫ ω, f (brownianEval 1 ω) ∂P := by + simp [controlPayoff] + +theorem abs_integral_reward_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (X : BrownianPath → ℝ) : + |∫ ω, f (X ω) ∂P| ≤ ‖f‖ := by + have h := norm_integral_le_of_norm_le_const + (μ := P) (f := fun ω => f (X ω)) (C := ‖f‖) + (Filter.Eventually.of_forall fun ω => f.norm_coe_le_norm (X ω)) + simpa using h + +theorem controlPayoff_le_norm (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) (v : Time → BrownianPath → ℝ) : + controlPayoff P f m v ≤ ‖f‖ := by + unfold controlPayoff + have h := (abs_integral_reward_le P f + (fun ω => brownianEval 1 ω + ∫ t, m t * v t ω ∂timeLaw)) + have h := (le_abs_self _).trans h + exact (sub_le_self _ (div_nonneg ENNReal.toReal_nonneg (by norm_num))).trans h + +theorem controlPayoffs_nonempty (P : Measure BrownianPath) (f : ℝ →ᵇ ℝ) (m : Trial) : + {a | ∃ v : Time → BrownianPath → ℝ, + Progressive P v ∧ controlCost P m v < ∞ ∧ a = controlPayoff P f m v}.Nonempty := by + exact ⟨_, fun _ _ => 0, progressive_zero P, by simp, rfl⟩ + +theorem controlPayoffs_bddAbove (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) : + BddAbove {a | ∃ v : Time → BrownianPath → ℝ, + Progressive P v ∧ controlCost P m v < ∞ ∧ a = controlPayoff P f m v} := by + refine ⟨‖f‖, ?_⟩ + rintro a ⟨v, _, _, rfl⟩ + exact controlPayoff_le_norm P f m v + +theorem controlValue_le_norm (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) : controlValue P f m ≤ ‖f‖ := by + apply csSup_le (controlPayoffs_nonempty P f m) + rintro a ⟨v, _, _, rfl⟩ + exact controlPayoff_le_norm P f m v + +theorem zero_payoff_le_controlValue (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) : + (∫ ω, f (brownianEval 1 ω) ∂P) ≤ controlValue P f m := by + apply le_csSup (controlPayoffs_bddAbove P f m) + exact ⟨fun _ _ => 0, progressive_zero P, by simp, by simp⟩ + +theorem neg_norm_le_controlValue (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) : -‖f‖ ≤ controlValue P f m := by + exact (abs_le.mp (abs_integral_reward_le P f (brownianEval 1))).1.trans + (zero_payoff_le_controlValue P f m) + +theorem abs_controlValue_le (P : Measure BrownianPath) [IsProbabilityMeasure P] + (f : ℝ →ᵇ ℝ) (m : Trial) : |controlValue P f m| ≤ ‖f‖ := by + exact abs_le.mpr ⟨neg_norm_le_controlValue P f m, controlValue_le_norm P f m⟩ + +def oneTrial : Trial where + toFun := fun _ => 1 + monotone := monotone_const + measurable := measurable_const + nonneg := fun _ => zero_le_one + le_one := fun _ => le_rfl + +@[simp] theorem oneTrial_apply (t : Time) : oneTrial t = 1 := rfl + +@[simp] theorem tailIntegral_oneTrial (t : Time) : + tailIntegral oneTrial t = 1 - (t : ℝ) := by + simp [tailIntegral, Measure.real, ENNReal.toReal_ofReal, sub_nonneg.mpr t.2.2] + +@[simp] theorem entropy_oneTrial : entropy oneTrial = 0 := by + simp [entropy] + +instance (N : ℕ) : IsProbabilityMeasure (unitSphereLaw (N + 1)) := by + have : NeZero ((volume : Measure (Spin (N + 1))).toSphere) := + ⟨Measure.toSphere_ne_zero volume⟩ + unfold unitSphereLaw + infer_instance + +instance (N : ℕ) : IsProbabilityMeasure (sphereLaw (N + 1)) := by + unfold sphereLaw + infer_instance + +lemma continuous_patternField {α : ℝ} {N : ℕ} (a : Fin (patternCount α N)) : + Continuous (fun p : Patterns α N × Spin N => patternField p.1 a p.2) := by + unfold patternField + apply Continuous.div_const + apply continuous_finsetSum + intro i _ + exact ((continuous_apply i).comp ((continuous_apply a).comp + (continuous_fst : Continuous (fun p : Patterns α N × Spin N => p.1)))).mul + ((EuclideanSpace.proj i).continuous.comp + (continuous_snd : Continuous (fun p : Patterns α N × Spin N => p.2))) + +lemma continuous_hamiltonian (α : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) : + Continuous (fun p : Patterns α N × Spin N => hamiltonian α φ N p.1 p.2) := by + unfold hamiltonian + apply continuous_finsetSum + intro a _ + exact φ.continuous.comp (continuous_patternField a) + +lemma abs_hamiltonian_le (α : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) + (g : Patterns α N) (x : Spin N) : + |hamiltonian α φ N g x| ≤ (patternCount α N : ℝ) * ‖φ‖ := by + unfold hamiltonian + calc + |∑ a, φ (patternField g a x)| ≤ ∑ a, |φ (patternField g a x)| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _ : Fin (patternCount α N), ‖φ‖ := + Finset.sum_le_sum fun a _ => φ.norm_coe_le_norm _ + _ = _ := by simp + +lemma log_integral_exp_sub_le {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) {F G : Ω → ℝ} {c : ℝ} + (hF : Integrable (fun x => Real.exp (F x)) μ) + (hG : Integrable (fun x => Real.exp (G x)) μ) + (pF : 0 < ∫ x, Real.exp (F x) ∂μ) (pG : 0 < ∫ x, Real.exp (G x) ∂μ) + (h : ∀ x, F x ≤ G x + c) : + Real.log (∫ x, Real.exp (F x) ∂μ) - Real.log (∫ x, Real.exp (G x) ∂μ) ≤ c := by + have hi : (∫ x, Real.exp (F x) ∂μ) ≤ + Real.exp c * ∫ x, Real.exp (G x) ∂μ := by + rw [← integral_const_mul] + apply integral_mono hF (hG.const_mul _) + intro x + calc + Real.exp (F x) ≤ Real.exp (G x + c) := Real.exp_le_exp.mpr (h x) + _ = Real.exp c * Real.exp (G x) := by rw [Real.exp_add, mul_comm] + have hl := Real.log_le_log pF hi + rw [Real.log_mul (Real.exp_ne_zero _) (ne_of_gt pG), Real.log_exp] at hl + linarith + +lemma abs_log_integral_exp_sub_le {Ω : Type*} [MeasurableSpace Ω] + (μ : Measure Ω) {F G : Ω → ℝ} {c : ℝ} + (hF : Integrable (fun x => Real.exp (F x)) μ) + (hG : Integrable (fun x => Real.exp (G x)) μ) + (pF : 0 < ∫ x, Real.exp (F x) ∂μ) (pG : 0 < ∫ x, Real.exp (G x) ∂μ) + (h : ∀ x, |F x - G x| ≤ c) : + |Real.log (∫ x, Real.exp (F x) ∂μ) - Real.log (∫ x, Real.exp (G x) ∂μ)| ≤ c := by + apply abs_le.mpr + constructor + · have hh := log_integral_exp_sub_le μ hG hF pG pF (fun x => by + have := (abs_le.mp (h x)).1 + linarith) + linarith + · exact log_integral_exp_sub_le μ hF hG pF pG (fun x => by + have := (abs_le.mp (h x)).2 + linarith) + +lemma abs_energy_le (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) + (g : Patterns α N) (x : Spin N) : + |β * hamiltonian α φ N g x| ≤ |β| * (patternCount α N : ℝ) * ‖φ‖ := by + rw [abs_mul, mul_assoc] + exact mul_le_mul_of_nonneg_left (abs_hamiltonian_le α φ N g x) (abs_nonneg β) + +lemma integrable_partition (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) + (g : Patterns α (N + 1)) : + Integrable (fun x => Real.exp (β * hamiltonian α φ (N + 1) g x)) + (sphereLaw (N + 1)) := by + apply (integrable_const (Real.exp (|β| * (patternCount α (N + 1) : ℝ) * ‖φ‖))).mono' + · exact (Real.continuous_exp.comp (continuous_const.mul + ((continuous_hamiltonian α φ (N + 1)).comp + (continuous_const.prodMk continuous_id)))).aestronglyMeasurable + · apply Filter.Eventually.of_forall + intro x + simpa only [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] using + Real.exp_le_exp.mpr ((abs_le.mp (abs_energy_le α β φ (N + 1) g x)).2) + +lemma partition_bounds (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) + (g : Patterns α (N + 1)) : + Real.exp (- (|β| * (patternCount α (N + 1) : ℝ) * ‖φ‖)) ≤ + (∫ x, Real.exp (β * hamiltonian α φ (N + 1) g x) ∂sphereLaw (N + 1)) ∧ + (∫ x, Real.exp (β * hamiltonian α φ (N + 1) g x) ∂sphereLaw (N + 1)) ≤ + Real.exp (|β| * (patternCount α (N + 1) : ℝ) * ‖φ‖) := by + constructor + · calc + _ = ∫ _ : Spin (N + 1), Real.exp (- (|β| * (patternCount α (N + 1) : ℝ) * ‖φ‖)) + ∂sphereLaw (N + 1) := by simp + _ ≤ _ := integral_mono (integrable_const _) (integrable_partition α β φ N g) + (fun x => Real.exp_le_exp.mpr ((abs_le.mp (abs_energy_le α β φ (N + 1) g x)).1)) + · calc + _ ≤ ∫ _ : Spin (N + 1), Real.exp (|β| * (patternCount α (N + 1) : ℝ) * ‖φ‖) + ∂sphereLaw (N + 1) := integral_mono (integrable_partition α β φ N g) + (integrable_const _) + (fun x => Real.exp_le_exp.mpr ((abs_le.mp (abs_energy_le α β φ (N + 1) g x)).2)) + _ = _ := by simp + +lemma partition_pos (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) + (g : Patterns α (N + 1)) : + 0 < ∫ x, Real.exp (β * hamiltonian α φ (N + 1) g x) ∂sphereLaw (N + 1) := + (Real.exp_pos _).trans_le (partition_bounds α β φ N g).1 + +lemma continuous_partition (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) : + Continuous (fun g : Patterns α (N + 1) => + ∫ x, Real.exp (β * hamiltonian α φ (N + 1) g x) ∂sphereLaw (N + 1)) := by + apply continuous_of_dominated (bound := fun _ => + Real.exp (|β| * (patternCount α (N + 1) : ℝ) * ‖φ‖)) + · intro g + exact (integrable_partition α β φ N g).aestronglyMeasurable + · intro g + apply Filter.Eventually.of_forall + intro x + simpa only [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] using + Real.exp_le_exp.mpr ((abs_le.mp (abs_energy_le α β φ (N + 1) g x)).2) + · exact integrable_const _ + · apply Filter.Eventually.of_forall + intro x + exact Real.continuous_exp.comp (continuous_const.mul + ((continuous_hamiltonian α φ (N + 1)).comp + (continuous_id.prodMk continuous_const))) + +lemma continuous_pressure (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) : + Continuous (pressure α β φ (N + 1)) := by + unfold pressure + apply Continuous.div_const + exact (continuous_partition α β φ N).log (fun g => ne_of_gt (partition_pos α β φ N g)) + +lemma abs_pressure_le (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) + (g : Patterns α (N + 1)) : + |pressure α β φ (N + 1) g| ≤ + |β| * (patternCount α (N + 1) : ℝ) * ‖φ‖ / (N + 1 : ℝ) := by + have hp := partition_pos α β φ N g + have hb := partition_bounds α β φ N g + have hlo := Real.log_le_log (Real.exp_pos _) hb.1 + have hhi := Real.log_le_log hp hb.2 + rw [Real.log_exp] at hlo hhi + have hd : 0 ≤ (N + 1 : ℝ) := by positivity + unfold pressure + rw [abs_div, abs_of_nonneg (show 0 ≤ ((N + 1 : ℕ) : ℝ) by positivity)] + simpa only [Nat.cast_add, Nat.cast_one] using div_le_div_of_nonneg_right + (abs_le.mpr ⟨hlo, hhi⟩) hd + +lemma integrable_pressure (α β : ℝ) (φ : ℝ →ᵇ ℝ) (N : ℕ) : + Integrable (pressure α β φ (N + 1)) (patternLaw α (N + 1)) := by + have : IsProbabilityMeasure (patternLaw α (N + 1)) := by + unfold patternLaw + infer_instance + exact (integrable_const _).mono' (continuous_pressure α β φ N).aestronglyMeasurable + (Filter.Eventually.of_forall (abs_pressure_le α β φ N)) +section ProductVariance +variable {X Y : Type*} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [TopologicalSpace Y] [MeasurableSpace Y] [BorelSpace Y] + [SecondCountableTopology X] [SecondCountableTopology Y] + (μ : Measure X) (ν : Measure Y) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + +omit [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology Y] in +lemma continuous_integral_of_bounded {F : X × Y → ℝ} (hF : Continuous F) + {K : ℝ} (hK : ∀ p, |F p| ≤ K) : + Continuous (fun x => ∫ y, F (x, y) ∂ν) := by + apply continuous_of_dominated (bound := fun _ => K) + · intro x + exact (hF.comp (continuous_const.prodMk continuous_id)).aestronglyMeasurable + · intro x + exact Filter.Eventually.of_forall (fun y => hK (x, y)) + · exact integrable_const _ + · exact Filter.Eventually.of_forall fun y => + hF.comp (continuous_id.prodMk continuous_const) + +omit [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [TopologicalSpace Y] [BorelSpace Y] + [SecondCountableTopology X] [SecondCountableTopology Y] in +lemma abs_integral_of_bounded {F : X × Y → ℝ} {K : ℝ} (hK : ∀ p, |F p| ≤ K) + (x : X) : |∫ y, F (x, y) ∂ν| ≤ K := by + simpa using norm_integral_le_of_norm_le_const + (μ := ν) (f := fun y => F (x, y)) + (Filter.Eventually.of_forall fun y => hK (x, y)) + +lemma variance_prod_le {F : X × Y → ℝ} (hF : Continuous F) + {K A B : ℝ} (hK : ∀ p, |F p| ≤ K) + (hA : ∀ x, variance (fun y => F (x, y)) ν ≤ A) + (hB : variance (fun x => ∫ y, F (x, y) ∂ν) μ ≤ B) : + variance F (μ.prod ν) ≤ A + B := by + have hp : MemLp F 2 (μ.prod ν) := + MemLp.of_bound hF.aestronglyMeasurable K (Filter.Eventually.of_forall hK) + have hs (x : X) : MemLp (fun y => F (x, y)) 2 ν := + MemLp.of_bound (hF.comp (continuous_const.prodMk continuous_id)).aestronglyMeasurable + K (Filter.Eventually.of_forall fun y => hK (x, y)) + have hh : MemLp (fun x => ∫ y, F (x, y) ∂ν) 2 μ := + MemLp.of_bound (continuous_integral_of_bounded ν hF hK).aestronglyMeasurable K + (Filter.Eventually.of_forall (abs_integral_of_bounded ν hK)) + have hi : (∫ x, ∫ y, F (x, y) ^ 2 ∂ν ∂μ) ≤ + A + ∫ x, (∫ y, F (x, y) ∂ν) ^ 2 ∂μ := by + calc + _ ≤ ∫ x, (A + (∫ y, F (x, y) ∂ν) ^ 2) ∂μ := by + apply integral_mono hp.integrable_sq.integral_prod_left + ((integrable_const A).add hh.integrable_sq) + intro x + have hv := hA x + rw [variance_eq_sub (hs x)] at hv + simpa only [Pi.pow_apply, Pi.add_apply] using (sub_le_iff_le_add.mp hv) + _ = _ := by rw [integral_add (integrable_const _) hh.integrable_sq]; simp + rw [variance_eq_sub hh] at hB + rw [variance_eq_sub hp] + simp only [Pi.pow_apply] at hB ⊢ + rw [integral_prod _ hp.integrable_sq, + integral_prod _ (hp.integrable (by norm_num))] + simpa only [Pi.pow_apply] using sub_le_iff_le_add.mpr (by linarith : + (∫ x, ∫ y, F (x, y) ^ 2 ∂ν ∂μ) ≤ + A + B + (∫ x, ∫ y, F (x, y) ∂ν ∂μ) ^ 2) + +end ProductVariance + +variable {X : Type*} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [SecondCountableTopology X] [Nonempty X] + (μ : Measure X) [IsProbabilityMeasure μ] + +omit [SecondCountableTopology X] in +lemma variance_le_of_oscillation {F : X → ℝ} (hF : Continuous F) {c : ℝ} + (hosc : ∀ x y, |F x - F y| ≤ c) : variance F μ ≤ c ^ 2 := by + let x₀ : X := Classical.choice ‹Nonempty X› + have hbound : ∀ᵐ x ∂μ, F x ∈ Icc (F x₀ - c) (F x₀ + c) := by + apply Filter.Eventually.of_forall + intro x + have hh := abs_le.mp (hosc x x₀) + constructor <;> linarith + have hv := variance_le_sq_of_bounded hbound hF.measurable.aemeasurable + convert hv using 1 + ring + +omit [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] [Nonempty X] in +lemma continuous_fin_cons {n : ℕ} : + Continuous (fun p : X × (Fin n → X) => Fin.cons (α := fun _ => X) p.1 p.2) := by + apply continuous_pi + intro i + refine Fin.cases ?_ (fun j => ?_) i + · simpa using (continuous_fst : Continuous (fun p : X × (Fin n → X) => p.1)) + · simpa only [Fin.cons_succ, Function.comp_def] using (continuous_apply j).comp + (continuous_snd : Continuous (fun p : X × (Fin n → X) => p.2)) + +omit [BorelSpace X] [Nonempty X] in +lemma measurePreserving_fin_cons (n : ℕ) : + MeasurePreserving (fun p : X × (Fin n → X) => Fin.cons (α := fun _ => X) p.1 p.2) + (μ.prod (Measure.pi fun _ : Fin n => μ)) (Measure.pi fun _ : Fin (n+1) => μ) := by + have h := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => μ) 0).symm + simpa [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv_zero, + Fin.consEquiv] using h + +omit [TopologicalSpace X] [BorelSpace X] [SecondCountableTopology X] [Nonempty X] in +lemma measurableEmbedding_fin_cons (n : ℕ) : + MeasurableEmbedding (fun p : X × (Fin n → X) => Fin.cons (α := fun _ => X) p.1 p.2) := by + have h := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => X) 0).symm.measurableEmbedding + simpa [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv_zero, + Fin.consEquiv] using h + +theorem variance_pi_le_of_bounded_differences (n : ℕ) {F : (Fin n → X) → ℝ} + (hF : Continuous F) {K c : ℝ} (hK : ∀ x, |F x| ≤ K) + (hdiff : ∀ x i y, |F (Function.update x i y) - F x| ≤ c) : + variance F (Measure.pi fun _ : Fin n => μ) ≤ (n : ℝ) * c ^ 2 := by + classical + induction n with + | zero => + rw [Measure.pi_of_empty] + simp + | succ n ih => + let ν := Measure.pi fun _ : Fin n => μ + let G : X × (Fin n → X) → ℝ := fun p => F (Fin.cons (α := fun _ => X) p.1 p.2) + have hG : Continuous G := hF.comp continuous_fin_cons + have hGK (p) : |G p| ≤ K := hK _ + have hA (x : X) : variance (fun y => G (x, y)) ν ≤ (n : ℝ) * c ^ 2 := by + apply ih (hG.comp (continuous_const.prodMk continuous_id)) (fun y => hGK (x,y)) + intro y i z + simpa only [G, Function.comp_apply, id_eq, Fin.cons_update] using hdiff (Fin.cons x y) i.succ z + have hHc : Continuous (fun x => ∫ y, G (x, y) ∂ν) := + continuous_integral_of_bounded ν hG hGK + have hHosc (x x' : X) : + |(∫ y, G (x, y) ∂ν) - ∫ y, G (x', y) ∂ν| ≤ c := by + have hi (x : X) : Integrable (fun y => G (x, y)) ν := + (integrable_const K).mono' + (hG.comp (continuous_const.prodMk continuous_id)).aestronglyMeasurable + (Filter.Eventually.of_forall fun y => hGK (x, y)) + rw [← integral_sub (hi x) (hi x')] + have hh : ∀ y, |G (x, y) - G (x', y)| ≤ c := by + intro y + have hu : Function.update (Fin.cons x' y) 0 x = Fin.cons (α := fun _ => X) x y := by + ext i + refine Fin.cases ?_ (fun j => ?_) i <;> simp + simpa only [G, hu] using hdiff (Fin.cons x' y) 0 x + simpa using norm_integral_le_of_norm_le_const + (μ := ν) (f := fun y => G (x,y) - G (x',y)) + (Filter.Eventually.of_forall hh) + have hv := variance_prod_le μ ν hG hGK hA + (variance_le_of_oscillation μ hHc hHosc) + have hpF : MemLp F 2 (Measure.pi fun _ : Fin (n+1) => μ) := + MemLp.of_bound hF.aestronglyMeasurable K (Filter.Eventually.of_forall hK) + have hpG : MemLp G 2 (μ.prod ν) := + MemLp.of_bound hG.aestronglyMeasurable K (Filter.Eventually.of_forall hGK) + rw [variance_eq_sub hpG] at hv + rw [variance_eq_sub hpF] + have hmean := (measurePreserving_fin_cons μ n).integral_comp + (measurableEmbedding_fin_cons (X := X) n) F + have hsquare := (measurePreserving_fin_cons μ n).integral_comp + (measurableEmbedding_fin_cons (X := X) n) (fun x => F x ^ 2) + change (∫ x, G x ∂μ.prod ν) = _ at hmean + change (∫ x, G x ^ 2 ∂μ.prod ν) = _ at hsquare + simp only [Pi.pow_apply] at hv ⊢ + rw [hsquare, hmean] at hv + simpa only [Nat.cast_add, Nat.cast_one, add_mul, one_mul, add_comm] using hv + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TripleIndex.lean b/lean/OAI/Probability/Perceptron/Variational/TripleIndex.lean new file mode 100644 index 0000000000000000000000000000000000000000..cd5a71134416c039e672f79979b009fbf2de13b4 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TripleIndex.lean @@ -0,0 +1,436 @@ +import Mathlib +import OAI.Probability.Perceptron.Pressure.PatternMatrices + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy +open Matrix +open scoped InnerProductSpace +variable {H : Type*} [SeminormedAddCommGroup H] [InnerProductSpace ℝ H] + +lemma triangleConstraints_diag (a b c t : ℝ) (k : Fin 3) : + triangleConstraints a b c t k k = Iio t := by simp [triangleConstraints] + +lemma triangleConstraints_cut {a : ℝ} (b c t : ℝ) (hat : a ≤ t) (k l : Fin 3) : + triangleConstraints a b c t k l ⊆ Iio t := by + unfold triangleConstraints + split_ifs + · exact Subset.rfl + · exact Iio_subset_Iio hat + · exact Ioo_subset_Iio_self + · exact Ioo_subset_Iio_self + +def tripleIndex {n : ℕ} (k : Fin 3) (i : Fin n) : Fin (3 * n) := + ⟨3 * i.val + k.val, by have := i.isLt; have := k.isLt; omega⟩ + +@[simp] lemma tripleLabels_tripleIndex {n : ℕ} (k : Fin 3) (i : Fin n) : + tripleLabels (3 * n) (tripleIndex k i) = k := by + apply Fin.ext + simp [tripleLabels, tripleIndex, Nat.add_mod] + +lemma tripleIndex_ne {n : ℕ} {k l : Fin 3} (hkl : k ≠ l) (i j : Fin n) : + tripleIndex k i ≠ tripleIndex l j := by + intro h + have := congrArg (tripleLabels (3 * n)) h + exact hkl (by simpa using this) + +lemma tripleIndex_inj {n : ℕ} (k : Fin 3) {i j : Fin n} (hij : i ≠ j) : + tripleIndex k i ≠ tripleIndex k j := by + intro h + apply hij + apply Fin.ext + have h' := congrArg Fin.val h + dsimp [tripleIndex] at h' + omega + +lemma triangle_pattern_psd_bound {n : ℕ} (hn : 0 < n) + (B : OverlapBlock (3 * n)) (hB : Matrix.PosSemidef B) + (hdiag : ∀ i, B i i ≤ 1) {a b c t : ℝ} (hab : a ≤ b) + (hpattern : B ∈ patternMatrices (tripleLabels (3 * n)) (triangleConstraints a b c t)) : + (b - a) ^ 2 ≤ 2 * (t - c) + 2 * ((1 - t) / n) := by + let _ := Matrix.toSeminormedAddCommGroup B hB + let _ := Matrix.toInnerProductSpace B hB + let v : Fin 3 → Fin n → (Fin (3 * n) → ℝ) := fun k i => Pi.single (tripleIndex k i) 1 + have hv (k l : Fin 3) (i j : Fin n) : + ⟪v k i, v l j⟫_ℝ = B (tripleIndex k i) (tripleIndex l j) := + posSemidef_standard_basis_inner B hB _ _ + apply duplicate_ordered_blocks_bound hn v hab + · intro k i + rw [← real_inner_self_eq_norm_sq, hv] + exact hdiag _ + · intro k i j hij + rw [hv] + have h := hpattern _ _ (tripleIndex_inj k hij) + simp only [tripleLabels_tripleIndex, triangleConstraints_diag, mem_Iio] at h + exact h.le + · intro i j + rw [hv] + have h := hpattern _ _ (tripleIndex_ne (by decide : (0 : Fin 3) ≠ 1) i j) + simp [triangleConstraints] at h + exact h.le + · intro i j + rw [hv] + have h := hpattern _ _ (tripleIndex_ne (by decide : (0 : Fin 3) ≠ 2) i j) + simp [triangleConstraints] at h + exact h.1.le + · intro i j + rw [hv] + have h := hpattern _ _ (tripleIndex_ne (by decide : (1 : Fin 3) ≠ 2) i j) + simp [triangleConstraints] at h + exact h.1.le + +theorem gg_triangle_pattern_bound (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + (hSym : ∀ᵐ Q ∂μ, ∀ i j, Q i j = Q j i) + (hGram : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n Q)) + (hdiag : ∀ᵐ Q ∂μ, ∀ i, Q i i ≤ 1) + {a b c t : ℝ} (hab : a ≤ b) (hat : a ≤ t) + (hA : 0 < μ.real (overlapBlock id 3 ⁻¹' + patternMatrices (tripleLabels 3) (triangleConstraints a b c t))) : + (b - a) ^ 2 ≤ 2 * (t - c) := by + have hall := gg_triple_pattern μ hEx hGG hSym (triangleConstraints a b c t) + (triangleConstraints_measurable a b c t) t (triangleConstraints_diag a b c t) + (triangleConstraints_cut b c t hat) hA + have hbound (n : ℕ) : (b - a) ^ 2 ≤ 2 * (t - c) + 2 * ((1 - t) / (n + 1 : ℝ)) := by + have hpos := hall (3 * (n + 1)) (by omega) + have hne : μ (overlapBlock id (3 * (n + 1)) ⁻¹' + patternMatrices (tripleLabels (3 * (n + 1))) (triangleConstraints a b c t)) ≠ 0 := by + intro hz + simp [Measure.real, hz] at hpos + obtain ⟨Q, hQ, hG, hD⟩ := Measure.exists_mem_of_measure_ne_zero_of_ae hne + (ae_restrict_of_ae (hGram.and hdiag)) + have h := triangle_pattern_psd_bound (by omega : 0 < n + 1) + (overlapBlock id (3 * (n + 1)) Q) (hG _) (fun i => hD i) hab hQ + simpa only [Nat.cast_add, Nat.cast_one] using h + have ht : Tendsto (fun n : ℕ => 2 * (t - c) + 2 * ((1 - t) / (n + 1 : ℝ))) atTop + (𝓝 (2 * (t - c))) := by + have h := tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ) |>.const_mul (2 * (1 - t)) + have h' := h.const_add (2 * (t - c)) + simpa only [mul_zero, add_zero, mul_one_div, mul_div_assoc] using h' + exact ge_of_tendsto ht (Eventually.of_forall hbound) + +def triangleEvent (a b c t : ℝ) : Set OverlapArray := + {Q | Q 0 1 < a ∧ b < Q 0 2 ∧ Q 0 2 < t ∧ c < Q 1 2 ∧ Q 1 2 < t} + +lemma triangleEvent_pattern {a b c t : ℝ} (hat : a ≤ t) (Q : OverlapArray) + (hSym : ∀ i j, Q i j = Q j i) (hQ : Q ∈ triangleEvent a b c t) : + overlapBlock id 3 Q ∈ patternMatrices (tripleLabels 3) (triangleConstraints a b c t) := by + have h10 := hSym 1 0 + have h20 := hSym 2 0 + have h21 := hSym 2 1 + have hQt : Q 0 1 < t := hQ.1.trans_le hat + intro i j hij + fin_cases i <;> fin_cases j <;> + simp_all [overlapBlock, tripleLabels, triangleConstraints, triangleEvent] + +lemma gg_triangleEvent_null (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + (hSym : ∀ᵐ Q ∂μ, ∀ i j, Q i j = Q j i) + (hGram : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n Q)) + (hdiag : ∀ᵐ Q ∂μ, ∀ i, Q i i ≤ 1) + {a b c t : ℝ} (hab : a ≤ b) (hat : a ≤ t) (hgap : 2 * (t - c) < (b - a) ^ 2) : + μ (triangleEvent a b c t) = 0 := by + by_contra hne + have hpos : 0 < μ.real (triangleEvent a b c t) := + ENNReal.toReal_pos hne (measure_ne_top _ _) + have hle : μ.real (triangleEvent a b c t) ≤ μ.real + (overlapBlock id 3 ⁻¹' patternMatrices (tripleLabels 3) (triangleConstraints a b c t)) := by + apply ENNReal.toReal_mono (measure_ne_top _ _) + apply measure_mono_ae + filter_upwards [hSym] with Q hQ + exact triangleEvent_pattern hat Q hQ + exact hgap.not_ge (gg_triangle_pattern_bound μ hEx hGG hSym hGram hdiag hab hat (hpos.trans_le hle)) + +lemma exists_rational_triangle_box {x y z : ℝ} (hxy : x < y) (hyz : y ≤ z) : + ∃ a b c t : ℚ, (a : ℝ) ≤ b ∧ (a : ℝ) ≤ t ∧ + 2 * ((t : ℝ) - c) < ((b : ℝ) - a) ^ 2 ∧ + x < a ∧ (b : ℝ) < y ∧ y < t ∧ (c : ℝ) < z ∧ z < t := by + obtain ⟨a, hxa, hay⟩ := exists_rat_btwn hxy + obtain ⟨b, hab, hby⟩ := exists_rat_btwn hay + have hδ : 0 < ((b : ℝ) - a) ^ 2 / 8 := by positivity + obtain ⟨c, hzc, hcz⟩ := exists_rat_btwn (show z - ((b : ℝ) - a) ^ 2 / 8 < z by linarith) + obtain ⟨t, hzt, htz⟩ := exists_rat_btwn (show z < z + ((b : ℝ) - a) ^ 2 / 8 by linarith) + refine ⟨a, b, c, t, hab.le, (hay.trans_le hyz).le.trans hzt.le, ?_, hxa, hby, + hyz.trans_lt hzt, hcz, hzt⟩ + nlinarith + +lemma gg_no_ordered_crossing (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + (hSym : ∀ᵐ Q ∂μ, ∀ i j, Q i j = Q j i) + (hGram : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n Q)) + (hdiag : ∀ᵐ Q ∂μ, ∀ i, Q i i ≤ 1) : + ∀ᵐ Q ∂μ, ¬ (Q 0 1 < Q 0 2 ∧ Q 0 2 ≤ Q 1 2) := by + have hBoxes : ∀ᵐ Q ∂μ, ∀ a b c t : ℚ, + (a : ℝ) ≤ b → (a : ℝ) ≤ t → 2 * ((t : ℝ) - c) < ((b : ℝ) - a) ^ 2 → + Q ∉ triangleEvent a b c t := by + apply ae_all_iff.mpr + intro a + apply ae_all_iff.mpr + intro b + apply ae_all_iff.mpr + intro c + apply ae_all_iff.mpr + intro t + by_cases hab : (a : ℝ) ≤ b + · by_cases hat : (a : ℝ) ≤ t + · by_cases hgap : 2 * ((t : ℝ) - c) < ((b : ℝ) - a) ^ 2 + · filter_upwards [measure_eq_zero_iff_ae_notMem.mp + (gg_triangleEvent_null μ hEx hGG hSym hGram hdiag hab hat hgap)] with Q hQ + exact fun _ _ _ => hQ + · exact Eventually.of_forall fun _ _ _ h => (hgap h).elim + · exact Eventually.of_forall fun _ _ h => (hat h).elim + · exact Eventually.of_forall fun _ h => (hab h).elim + filter_upwards [hBoxes] with Q hQ + rintro ⟨hxy, hyz⟩ + obtain ⟨a, b, c, t, hab, hat, hgap, hbox⟩ := exists_rational_triangle_box hxy hyz + exact hQ a b c t hab hat hgap hbox + +lemma gram_array_symmetric (Q : OverlapArray) + (hGram : ∀ n, Matrix.PosSemidef (overlapBlock id n Q)) : ∀ i j, Q i j = Q j i := by + intro i j + let n := max i j + 1 + let a : Fin n := ⟨i, by dsimp [n]; omega⟩ + let b : Fin n := ⟨j, by dsimp [n]; omega⟩ + have h := (hGram n).isHermitian.apply b a + simpa [overlapBlock, a, b] using h + +theorem gg_ultrametric (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + (hGram : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n Q)) + (hdiag : ∀ᵐ Q ∂μ, ∀ i, Q i i ≤ 1) : + ∀ᵐ Q ∂μ, min (Q 0 1) (Q 0 2) ≤ Q 1 2 := by + have hSym : ∀ᵐ Q ∂μ, ∀ i j, Q i j = Q j i := + hGram.mono fun Q hQ => gram_array_symmetric Q hQ + have hno := gg_no_ordered_crossing μ hEx hGG hSym hGram hdiag + have hno' := (hEx 0 1).quasiMeasurePreserving.ae hno + have hsmall : ∀ᵐ Q ∂μ, min (Q 0 2) (Q 1 2) ≤ Q 0 1 := by + filter_upwards [hno, hno', hSym] with Q hQ hQ' hs + simp only [relabelArray, Equiv.swap_apply_left, Equiv.swap_apply_right, + show Equiv.swap (0 : ℕ) 1 2 = 2 from by decide] at hQ' + rw [hs 1 0] at hQ' + by_cases h : Q 0 2 ≤ Q 1 2 + · rw [min_eq_left h] + exact le_of_not_gt fun hh => hQ ⟨hh, h⟩ + · have h' := le_of_lt (lt_of_not_ge h) + rw [min_eq_right h'] + exact le_of_not_gt fun hh => hQ' ⟨hh, h'⟩ + have hsmall' := (hEx 0 2).quasiMeasurePreserving.ae hsmall + filter_upwards [hsmall', hSym] with Q hQ hs + simp only [relabelArray, Equiv.swap_apply_left, Equiv.swap_apply_right, + show Equiv.swap (0 : ℕ) 2 1 = 1 from by decide] at hQ + simpa only [hs 2 0, hs 1 0, hs 2 1, min_comm] using hQ + +abbrev PairedOverlapArray := ℕ → ℕ → ℝ × ℝ +abbrev PairedOverlapBlock (n : ℕ) := Fin n → Fin n → ℝ × ℝ + +def pairedBlock (n : ℕ) (Q : PairedOverlapArray) : PairedOverlapBlock n := + fun i j => Q i j + +def pairedRelabel (π : Equiv.Perm ℕ) (Q : PairedOverlapArray) : PairedOverlapArray := + fun i j => Q (π i) (π j) + +def PairedSwapInvariant (μ : Measure PairedOverlapArray) : Prop := + ∀ i j : ℕ, MeasurePreserving (pairedRelabel (Equiv.swap i j)) μ μ + +def JointGhirlandaGuerra (μ : Measure PairedOverlapArray) : Prop := + ∀ (n : ℕ), 2 ≤ n → ∀ (i : Fin n) (s : Set (PairedOverlapBlock n)), MeasurableSet s → + ∀ t : Set (ℝ × ℝ), MeasurableSet t → + μ.real (pairedBlock n ⁻¹' s ∩ {Q | Q i n ∈ t}) = + μ.real (pairedBlock n ⁻¹' s) * μ.real {Q | Q 0 1 ∈ t} / n + + (∑ j ∈ (Finset.univ.erase i), + μ.real (pairedBlock n ⁻¹' s ∩ {Q | Q i j ∈ t})) / n + +def scalarArray (f : ℝ × ℝ → ℝ) (Q : PairedOverlapArray) : OverlapArray := + fun i j => f (Q i j) + +def scalarBlock (f : ℝ × ℝ → ℝ) {n : ℕ} (Q : PairedOverlapBlock n) : OverlapBlock n := + fun i j => f (Q i j) + +lemma scalarArray_measurable {f : ℝ × ℝ → ℝ} (hf : Measurable f) : + Measurable (scalarArray f) := by + exact Measurable.of_eval fun _ => Measurable.of_eval fun _ => + hf.comp ((measurable_pi_apply _).comp (measurable_pi_apply _)) + +lemma scalarBlock_measurable {f : ℝ × ℝ → ℝ} (hf : Measurable f) {n : ℕ} : + Measurable (scalarBlock f (n := n)) := by + exact Measurable.of_eval fun _ => Measurable.of_eval fun _ => + hf.comp ((measurable_pi_apply _).comp (measurable_pi_apply _)) + +lemma scalarArray_swap_invariant (μ : Measure PairedOverlapArray) + (hEx : PairedSwapInvariant μ) {f : ℝ × ℝ → ℝ} (hf : Measurable f) : + OverlapSwapInvariant (μ.map (scalarArray f)) := by + intro i j + have heq : relabelArray (Equiv.swap i j) ∘ scalarArray f = + scalarArray f ∘ pairedRelabel (Equiv.swap i j) := rfl + refine ⟨Measurable.of_eval fun _ => Measurable.of_eval fun _ => + (measurable_pi_apply _).comp (measurable_pi_apply _), ?_⟩ + rw [Measure.map_map _ (scalarArray_measurable hf), heq, + ← Measure.map_map (scalarArray_measurable hf) (hEx i j).measurable, + (hEx i j).map_eq] + exact Measurable.of_eval fun _ => Measurable.of_eval fun _ => + (measurable_pi_apply _).comp (measurable_pi_apply _) + +lemma scalarArray_gg (μ : Measure PairedOverlapArray) + (hGG : JointGhirlandaGuerra μ) {f : ℝ × ℝ → ℝ} (hf : Measurable f) : + GhirlandaGuerra (μ.map (scalarArray f)) id := by + intro n hn i s hs t ht + have hblock : Measurable (overlapBlock (id : OverlapArray → OverlapArray) n) := + Measurable.of_eval fun _ => Measurable.of_eval fun _ => + (measurable_pi_apply _).comp (measurable_pi_apply _) + have hedge (i j : ℕ) : Measurable (fun Q : OverlapArray => Q i j) := + (measurable_pi_apply _).comp (measurable_pi_apply _) + have hmap (u : Set OverlapArray) (hu : MeasurableSet u) : + (μ.map (scalarArray f)).real u = μ.real (scalarArray f ⁻¹' u) := by + rw [measureReal_def, Measure.map_apply (scalarArray_measurable hf) hu] + rfl + simp only [id_eq] + rw [hmap (overlapBlock id n ⁻¹' s ∩ {Q | Q i n ∈ t}) + ((hs.preimage hblock).inter (ht.preimage (hedge i n))), + hmap _ (hs.preimage hblock), hmap {Q | Q 0 1 ∈ t} (ht.preimage (hedge 0 1))] + have hmj (j : Fin n) := hmap (overlapBlock id n ⁻¹' s ∩ {Q | Q i j ∈ t}) + ((hs.preimage hblock).inter (ht.preimage (hedge i j))) + simp_rw [hmj] + exact hGG n hn i (scalarBlock f ⁻¹' s) (hs.preimage (scalarBlock_measurable hf)) + (f ⁻¹' t) (ht.preimage hf) + +lemma measurableSet_gram_arrays : + MeasurableSet {Q : OverlapArray | ∀ n, Matrix.PosSemidef (overlapBlock id n Q)} := by + apply IsClosed.measurableSet + simp only [ofPred_forall] + apply isClosed_iInter + intro n + have hiff (Q : OverlapArray) := + Matrix.posSemidef_iff_dotProduct_mulVec (M := overlapBlock id n Q) + simp_rw [hiff] + simp only [ofPred_and, ofPred_forall] + apply IsClosed.inter + · change IsClosed {Q : OverlapArray | Matrix.conjTranspose (overlapBlock id n Q) = overlapBlock id n Q} + apply isClosed_eq <;> unfold overlapBlock <;> fun_prop + · apply isClosed_iInter + intro x + apply isClosed_le continuous_const + unfold overlapBlock + fun_prop + +lemma scalarArray_ultrametric (μ : Measure PairedOverlapArray) [IsProbabilityMeasure μ] + (hEx : PairedSwapInvariant μ) (hGG : JointGhirlandaGuerra μ) + {f : ℝ × ℝ → ℝ} (hf : Measurable f) + (hGram : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray f Q))) + (hdiag : ∀ᵐ Q ∂μ, ∀ i, f (Q i i) ≤ 1) : + ∀ᵐ Q ∂μ, min (f (Q 0 1)) (f (Q 0 2)) ≤ f (Q 1 2) := by + let ν := μ.map (scalarArray f) + have hm := scalarArray_measurable hf + have : IsProbabilityMeasure ν := inferInstance + have hg : ∀ᵐ Q ∂ν, ∀ n, Matrix.PosSemidef (overlapBlock id n Q) := + (ae_map_iff hm.aemeasurable measurableSet_gram_arrays).mpr hGram + have hd : ∀ᵐ Q ∂ν, ∀ i, Q i i ≤ 1 := + (ae_map_iff hm.aemeasurable (by + simp only [ofPred_forall] + exact MeasurableSet.iInter fun i => measurableSet_le + ((measurable_pi_apply i).comp (measurable_pi_apply i)) measurable_const)).mpr hdiag + have hu := gg_ultrametric ν (scalarArray_swap_invariant μ hEx hf) + (scalarArray_gg μ hGG hf) hg hd + exact ae_of_ae_map hm.aemeasurable hu + +def UltrametricTriangle (x y z : ℝ) : Prop := + min x y ≤ z ∧ min x z ≤ y ∧ min y z ≤ x + +lemma gg_ultrametric_triangle (μ : Measure OverlapArray) [IsProbabilityMeasure μ] + (hEx : OverlapSwapInvariant μ) (hGG : GhirlandaGuerra μ id) + (hGram : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n Q)) + (hdiag : ∀ᵐ Q ∂μ, ∀ i, Q i i ≤ 1) : + ∀ᵐ Q ∂μ, UltrametricTriangle (Q 0 1) (Q 0 2) (Q 1 2) := by + have h := gg_ultrametric μ hEx hGG hGram hdiag + have h₁ := (hEx 0 1).quasiMeasurePreserving.ae h + have h₂ := (hEx 0 2).quasiMeasurePreserving.ae h + filter_upwards [h, h₁, h₂, hGram] with Q hQ hQ₁ hQ₂ hg + have hs := gram_array_symmetric Q hg + refine ⟨hQ, ?_, ?_⟩ + · simpa only [relabelArray, Equiv.swap_apply_left, Equiv.swap_apply_right, + show Equiv.swap (0 : ℕ) 1 2 = 2 from by decide, hs 1 0] using hQ₁ + · simpa only [relabelArray, Equiv.swap_apply_left, Equiv.swap_apply_right, + show Equiv.swap (0 : ℕ) 2 1 = 1 from by decide, hs 2 0, hs 2 1, hs 1 0, + min_comm] using hQ₂ + +lemma scalarArray_ultrametric_triangle (μ : Measure PairedOverlapArray) [IsProbabilityMeasure μ] + (hEx : PairedSwapInvariant μ) (hGG : JointGhirlandaGuerra μ) + {f : ℝ × ℝ → ℝ} (hf : Measurable f) + (hGram : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray f Q))) + (hdiag : ∀ᵐ Q ∂μ, ∀ i, f (Q i i) ≤ 1) : + ∀ᵐ Q ∂μ, UltrametricTriangle (f (Q 0 1)) (f (Q 0 2)) (f (Q 1 2)) := by + let ν := μ.map (scalarArray f) + have hm := scalarArray_measurable hf + have : IsProbabilityMeasure ν := inferInstance + have hg : ∀ᵐ Q ∂ν, ∀ n, Matrix.PosSemidef (overlapBlock id n Q) := + (ae_map_iff hm.aemeasurable measurableSet_gram_arrays).mpr hGram + have hd : ∀ᵐ Q ∂ν, ∀ i, Q i i ≤ 1 := + (ae_map_iff hm.aemeasurable (by + simp only [ofPred_forall] + exact MeasurableSet.iInter fun i => measurableSet_le + ((measurable_pi_apply i).comp (measurable_pi_apply i)) measurable_const)).mpr hdiag + exact ae_of_ae_map hm.aemeasurable + (gg_ultrametric_triangle ν (scalarArray_swap_invariant μ hEx hf) + (scalarArray_gg μ hGG hf) hg hd) + +lemma ultrametric_triangle_small_eq {a b c : ℝ} (h : UltrametricTriangle a b c) + (hab : a < b) : c = a := by + have hlo : a ≤ c := by simpa only [min_eq_left hab.le] using h.1 + have hhi : c ≤ a := by + rcases le_total b c with hbc | hcb + · have : b ≤ a := by simpa only [min_eq_left hbc] using h.2.2 + exact (hab.not_ge this).elim + · simpa only [min_eq_right hcb] using h.2.2 + exact le_antisymm hhi hlo + +lemma ultrametric_sum_no_crossing {a b c x y z : ℝ} + (hR : UltrametricTriangle a b c) (hT : UltrametricTriangle x y z) + (hSum : min ((a + x) / 2) ((b + y) / 2) ≤ (c + z) / 2) : + ¬ (a < b ∧ y < x) := by + rintro ⟨hab, hyx⟩ + have hc := ultrametric_triangle_small_eq hR hab + have hz : z = y := ultrametric_triangle_small_eq + (show UltrametricTriangle y x z from ⟨by simpa only [min_comm] using hT.1, + hT.2.2, hT.2.1⟩) hyx + rw [hc, hz] at hSum + rcases le_total ((a + x) / 2) ((b + y) / 2) with h | h + · rw [min_eq_left h] at hSum + linarith + · rw [min_eq_right h] at hSum + linarith + +theorem joint_gg_no_crossing (μ : Measure PairedOverlapArray) [IsProbabilityMeasure μ] + (hEx : PairedSwapInvariant μ) (hGG : JointGhirlandaGuerra μ) + (hR : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray Prod.fst Q))) + (hT : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray Prod.snd Q))) + (hdR : ∀ᵐ Q ∂μ, ∀ i, (Q i i).1 ≤ 1) + (hdT : ∀ᵐ Q ∂μ, ∀ i, (Q i i).2 ≤ 1) : + ∀ᵐ Q ∂μ, ¬ ((Q 0 1).1 < (Q 0 2).1 ∧ (Q 0 2).2 < (Q 0 1).2) := by + have huR := scalarArray_ultrametric_triangle μ hEx hGG measurable_fst hR hdR + have huT := scalarArray_ultrametric_triangle μ hEx hGG measurable_snd hT hdT + let f : ℝ × ℝ → ℝ := fun x => (x.1 + x.2) / 2 + have hf : Measurable f := by fun_prop + have hG : ∀ᵐ Q ∂μ, ∀ n, Matrix.PosSemidef (overlapBlock id n (scalarArray f Q)) := by + filter_upwards [hR, hT] with Q hQ₁ hQ₂ n + have heq : overlapBlock id n (scalarArray f Q) = + (1 / 2 : ℝ) • (overlapBlock id n (scalarArray Prod.fst Q) + + overlapBlock id n (scalarArray Prod.snd Q)) := by + ext i j + simp [overlapBlock, scalarArray, f, smul_eq_mul, div_eq_mul_inv, add_mul, + mul_comm] + rw [heq] + exact ((hQ₁ n).add (hQ₂ n)).smul (by norm_num : (0 : ℝ) ≤ 1 / 2) + have hd : ∀ᵐ Q ∂μ, ∀ i, f (Q i i) ≤ 1 := by + filter_upwards [hdR, hdT] with Q hQ₁ hQ₂ i + dsimp [f] + linarith [hQ₁ i, hQ₂ i] + have huS := scalarArray_ultrametric μ hEx hGG hf hG hd + filter_upwards [huR, huT, huS] with Q hQ₁ hQ₂ hQ₃ + exact ultrametric_sum_no_crossing hQ₁ hQ₂ hQ₃ + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/TripleRootRegroup.lean b/lean/OAI/Probability/Perceptron/Variational/TripleRootRegroup.lean new file mode 100644 index 0000000000000000000000000000000000000000..8754cda15c0022b209e48925ab3f8dbdc6dc8616 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/TripleRootRegroup.lean @@ -0,0 +1,66 @@ +import Mathlib +import OAI.Probability.Perceptron.Cavity.LeafFreshLog + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +lemma indexedGaussian_pair_zip_law (k : ℕ) (I J : Type) [Fintype I] [Fintype J] : + MeasurePreserving (fun t : (ℕ→ℝ)×(ℕ→ℝ) => + (((indexedGaussianDisorder k I t.1).1,(indexedGaussianDisorder k J t.2).1), + indexedMarksZip k ((indexedGaussianDisorder k I t.1).2,(indexedGaussianDisorder k J t.2).2))) + (countableGaussianLaw.prod countableGaussianLaw) + (((stdGaussian (EuclideanSpace ℝ I)).prod (stdGaussian (EuclideanSpace ℝ J))).prod + (indexedCascadeMarksLaw + (productMarkLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ J))) k)) := by + have hI : MeasurePreserving (indexedGaussianDisorder k I) countableGaussianLaw + ((stdGaussian (EuclideanSpace ℝ I)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ I)) k)) := + ⟨indexedGaussianDisorder_measurable k I,indexedGaussianDisorder_law k I⟩ + have hJ : MeasurePreserving (indexedGaussianDisorder k J) countableGaussianLaw + ((stdGaussian (EuclideanSpace ℝ J)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ J)) k)) := + ⟨indexedGaussianDisorder_measurable k J,indexedGaussianDisorder_law k J⟩ + have hz : MeasurePreserving (indexedMarksZip (S:=EuclideanSpace ℝ I) (T:=EuclideanSpace ℝ J) k) + ((indexedCascadeMarksLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) k : Measure _).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ J)) k)) + (indexedCascadeMarksLaw (productMarkLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ J))) k) := + ⟨indexedMarksZip_measurable k,indexedMarksZip_law _ _ k⟩ + exact ((MeasurePreserving.id _).prod hz).comp + ((freshRoot_four_shuffle _ _ _ _).comp (hI.prod hJ)) + +lemma indexedGaussian_three_regroup_law (k : ℕ) (z : Fin k→ℝ) + (I J K : Type) [Fintype I] [Fintype J] [Fintype K] : + MeasurePreserving + (fun t : IndexedCascadeBase k×(((ℕ→ℝ)×(ℕ→ℝ))×(ℕ→ℝ)) => + ((((indexedGaussianDisorder k I t.2.1.1).1,(indexedGaussianDisorder k J t.2.1.2).1), + (indexedGaussianDisorder k K t.2.2).1), + (t.1,(indexedMarksZip k ((indexedGaussianDisorder k I t.2.1.1).2, + (indexedGaussianDisorder k J t.2.1.2).2),(indexedGaussianDisorder k K t.2.2).2)))) + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((countableGaussianLaw.prod countableGaussianLaw).prod countableGaussianLaw)) + ((((stdGaussian (EuclideanSpace ℝ I)).prod (stdGaussian (EuclideanSpace ℝ J))).prod + (stdGaussian (EuclideanSpace ℝ K))).prod + ((indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k)).prod + ((indexedCascadeMarksLaw + (productMarkLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ I)) + (gaussianMarkLaw (E:=EuclideanSpace ℝ J))) k : + Measure (IndexedCascadeMarks (EuclideanSpace ℝ I×EuclideanSpace ℝ J) k)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E:=EuclideanSpace ℝ K)) k)))) := by + have hK : MeasurePreserving (indexedGaussianDisorder k K) countableGaussianLaw + ((stdGaussian (EuclideanSpace ℝ K)).prod + (indexedCascadeMarksLaw (gaussianMarkLaw (E := EuclideanSpace ℝ K)) k)) := + ⟨indexedGaussianDisorder_measurable k K,indexedGaussianDisorder_law k K⟩ + exact (freshRoot_five_regroup _ _ _ _ _).comp + ((MeasurePreserving.id (indexedCascadeBaseLaw k z : Measure (IndexedCascadeBase k))).prod + ((indexedGaussian_pair_zip_law k I J).prod hK)) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/UnboundedContact.lean b/lean/OAI/Probability/Perceptron/Variational/UnboundedContact.lean new file mode 100644 index 0000000000000000000000000000000000000000..15c6727d3a96a2830cb885715928c3c70d8f39d8 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/UnboundedContact.lean @@ -0,0 +1,141 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.CouplingAffine +import OAI.Probability.Perceptron.Variational.ContactFatou + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators + +lemma quadratic_contact_thermal_disorder_separate {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {F D : ℝ → Ω → ℝ} {J U : Ω → ℝ} + (hF : ∀ t, MemLp (F t) 2 P) (hD : ∀ t, AEStronglyMeasurable (D t) P) + (hJ : AEStronglyMeasurable J P) (hU : AEStronglyMeasurable U P) + (hU0 : 0 ≤ᵐ[P] U) (hUsq : ∀ᵐ ω ∂P, (U ω)^2 ≤ J ω) + (hc : ∀ᵐ ω ∂P, ContDiff ℝ 2 (fun t => F t ω) ∧ ConvexOn ℝ univ (fun t => F t ω) ∧ + ∀ t, HasDerivAt (fun t => F t ω) (D t ω) t) + {u a c s V : ℝ} (hs : 0 < s) + (he : ∀ᵐ ω ∂P, iteratedDeriv 2 (fun t => F t ω) u = J ω) + (hmin : IsLocalMin (fun t => c*(t-a)^2-∫ ω, F t ω ∂P) u) + (hp : c*(u-a)^2-(∫ ω, F u ω ∂P) ≤ c*(u+s-a)^2-(∫ ω, F (u+s) ω ∂P)) + (hm : c*(u-a)^2-(∫ ω, F u ω ∂P) ≤ c*(u-s-a)^2-(∫ ω, F (u-s) ω ∂P)) + (hVp : variance (F (u+s)) P ≤ V) (hV0 : variance (F u) P ≤ V) + (hVm : variance (F (u-s)) P ≤ V) : + MemLp U 2 P ∧ Integrable (D u) P ∧ + (∫ ω, U ω ∂P) ≤ Real.sqrt (2*c) ∧ + (∫ ω, |D u ω-∫ η, D u η ∂P| ∂P) ≤ c*s+4*Real.sqrt V/s := by + have hi (t) := (hF t).integrable (by norm_num) + have hcurv := quadratic_contact_curvature_bound P hJ hi (hc.mono fun ω hω => ⟨hω.1,hω.2.1⟩) he hmin + have hUI2 : Integrable (fun ω => U ω^2) P := by + apply hcurv.1.mono' (hU.pow 2) + filter_upwards [hUsq] with ω hω + simpa only [Pi.pow_apply,Real.norm_of_nonneg (sq_nonneg _)] using hω + have hULp := (memLp_two_iff_integrable_sq hU).mpr hUI2 + have hv := variance_nonneg U P + rw [variance_eq_sub hULp] at hv + have hsq : (∫ ω, U ω ∂P)^2 ≤ 2*c := by + have hh := integral_mono_ae hUI2 hcurv.1 hUsq + simp only [Pi.pow_apply] at hv + linarith [hcurv.2] + have htherm : (∫ ω, U ω ∂P) ≤ Real.sqrt (2*c) := + (Real.le_sqrt (integral_nonneg_of_ae hU0) ((sq_nonneg _).trans hsq)).mpr hsq + have hd := annealed_convex_hasDerivAt P (fun t => (hF t).aestronglyMeasurable) hD hi + (hc.mono fun ω hω => ⟨hω.2.1,hω.2.2⟩) u + have hr := quadratic_contact_remainders hd.2 hmin hp hm + have hAerr (t) (ht : variance (F t) P ≤ V) : + (∫ ω, |F t ω-∫ η, F t η ∂P| ∂P) ≤ Real.sqrt V := + (integral_centered_abs_le_sqrt_variance P (hF t)).trans (Real.sqrt_le_sqrt ht) + have hdis := integral_convex_contact_bound P (A := fun t => ∫ ω, F t ω ∂P) + (f := fun ω t => F t ω) (dA := ∫ ω, D u ω ∂P) (C := c) (δ := Real.sqrt V) hs (hD u) + (hc.mono fun ω hω => ⟨hω.2.1,hω.2.2 u⟩) + hr.1 hr.2 (hi (u+s)) (hi u) (hi (u-s)) + (hAerr (u+s) hVp) (hAerr u hV0) (hAerr (u-s) hVm) + exact ⟨hULp,hd.1,htherm,hdis⟩ + +section +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) [IsMarkovKernel κ] (P : Measure A) +variable {W : A → S → ℝ} {v w : ℕ → S → ℝ} {L : S → ℕ} +variable (hW : Measurable (Function.uncurry W)) (hv : ∀ i, Measurable (v i)) +variable (hw : ∀ i, Measurable (w i)) (hL : Measurable L) +variable {B : A → ℝ} {D E : ℝ} (hB : ∀ a x, |W a x| ≤ B a) +variable (hD : ∀ x, (∑ i : Fin (L x), v i.val x^2) ≤ D) +variable (hE : ∀ x, (∑ i : Fin (L x), w i.val x^2) ≤ E) + +include hW hv hw hL + +lemma kernelGaussian_coupling_joint_measurable (r : ℝ) : + Measurable (fun a : (A × (ℕ → ℝ)) × S => + countableGaussianHamiltonian (W a.1.1) v L a.1.2 a.2+ + r*countableGaussianField w L a.1.2 a.2) := by + apply (hW.comp (measurable_fst.fst.prodMk measurable_snd) |>.add + ((countableGaussianField_measurable hv hL).comp (measurable_fst.snd.prodMk measurable_snd))).add + exact ((countableGaussianField_measurable hw hL).comp + (measurable_fst.snd.prodMk measurable_snd)).const_mul r + +include hB hD hE + +lemma kernelGaussian_coupling_exp_ae (r : ℝ) : + ∀ᵐ a : A × (ℕ → ℝ) ∂P.prod countableGaussianLaw, + Integrable (fun x => Real.exp (countableGaussianHamiltonian (W a.1) v L a.2 x+ + r*countableGaussianField w L a.2 x)) (κ a.1) := by + let κ' : Kernel (A × (ℕ → ℝ)) S := κ.comap (Prod.fst : A × (ℕ → ℝ) → A) measurable_fst + have hm : MeasurableSet {a : A × (ℕ → ℝ) | Integrable + (fun x => Real.exp (countableGaussianHamiltonian (W a.1) v L a.2 x+ + r*countableGaussianField w L a.2 x)) (κ' a)} := + measurableSet_kernel_integrable (kernelGaussian_coupling_joint_measurable hW hv hw hL r).exp.stronglyMeasurable + apply (Measure.ae_prod_iff_ae_ae hm).mpr + exact ae_of_all _ fun a => countableGaussian_coupling_exp_ae (κ a) + (hW.comp (measurable_const.prodMk measurable_id)) hv hw hL (hB a) hD hE r + +lemma kernelGaussian_all_coupling_exp_ae : + ∀ᵐ a : A × (ℕ → ℝ) ∂P.prod countableGaussianLaw, ∀ r : ℝ, + Integrable (fun x => Real.exp (countableGaussianHamiltonian (W a.1) v L a.2 x+ + r*countableGaussianField w L a.2 x)) (κ a.1) := by + have hp := ae_all_iff.mpr (fun j : ℕ => kernelGaussian_coupling_exp_ae κ P hW hv hw hL hB hD hE (j:ℝ)) + have hn := ae_all_iff.mpr (fun j : ℕ => kernelGaussian_coupling_exp_ae κ P hW hv hw hL hB hD hE (-(j:ℝ))) + filter_upwards [hp,hn] with a hp hn r + apply coupling_integrable_of_integer_endpoints (κ a.1) + ((hW.comp (measurable_const.prodMk measurable_id)).add + ((countableGaussianField_measurable hv hL).comp (measurable_const.prodMk measurable_id))) + ((countableGaussianField_measurable hw hL).comp (measurable_const.prodMk measurable_id)) _ r + intro j + exact ⟨hp j,by simpa only [neg_mul,sub_eq_add_neg,Function.comp_apply,Function.uncurry_apply_pair, + id_eq,Pi.add_apply,countableGaussianHamiltonian] using hn j⟩ + +end + +variable {A S : Type*} [MeasurableSpace A] [MeasurableSpace S] +variable (κ : Kernel A S) [IsSFiniteKernel κ] {H Y : A → S → ℝ} +variable (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + +include hH + +lemma kernel_tiltPartition_measurable : Measurable (fun a => tiltPartition (κ a) (H a) 1) := by + unfold tiltPartition + exact (hH.const_mul 1 |>.exp.stronglyMeasurable.integral_kernel_prod_right).measurable + +include hY + +lemma kernel_tiltMean_measurable : Measurable (fun a => tiltMean (κ a) (H a) (Y a) 1) := by + unfold tiltMean tiltIntegral + exact ((hH.const_mul 1 |>.exp.mul hY).stronglyMeasurable.integral_kernel_prod_right).measurable.div + (kernel_tiltPartition_measurable κ hH) + +lemma kernel_tiltCenteredVariance_measurable : Measurable (fun a => tiltMean (κ a) (H a) + (fun x => (Y a x-tiltMean (κ a) (H a) (Y a) 1)^2) 1) := by + apply kernel_tiltMean_measurable κ hH + exact (hY.sub ((kernel_tiltMean_measurable κ hH hY).comp measurable_fst)).pow_const 2 + +lemma kernel_tiltCenteredAbs_measurable : Measurable (fun a => tiltMean (κ a) (H a) + (fun x => |Y a x-tiltMean (κ a) (H a) (Y a) 1|) 1) := by + apply kernel_tiltMean_measurable κ hH + exact (hY.sub ((kernel_tiltMean_measurable κ hH hY).comp measurable_fst)).abs + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/UniformGrid.lean b/lean/OAI/Probability/Perceptron/Variational/UniformGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..73bab8374e8bd880a57f3003b8f437c980e84ba7 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/UniformGrid.lean @@ -0,0 +1,144 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FieldWord + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators +namespace SphericalPerceptronFreeEnergy + +def uniformWeights (k : ℕ) : Fin (k+1) → ℝ := fun _ => 1/(k+1:ℕ) +def uniformExponents (k : ℕ) (i : Fin (k+2)) : ℝ := (i:ℕ)/(k+1:ℕ) + +lemma uniformWeights_pos (k : ℕ) (i : Fin (k+1)) : 0 < uniformWeights k i := by + unfold uniformWeights + positivity + +lemma uniformWeights_sum (k : ℕ) : ∑ i, uniformWeights k i=1 := by + simp only [uniformWeights,Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul,one_div] + exact mul_inv_cancel₀ (by positivity) + +lemma uniformExponents_nonneg (k : ℕ) (i : Fin (k+2)) : 0 ≤ uniformExponents k i := by + unfold uniformExponents + positivity + +lemma uniformExponents_last (k : ℕ) : uniformExponents k (Fin.last (k+1))=1 := by + simp only [uniformExponents,Fin.val_last] + exact div_self (by positivity) + +lemma stepCumulative_uniformWeights (k : ℕ) (i : Fin k) : + stepCumulative (uniformWeights k) i=(i.val+1:ℕ)/(k+1:ℕ) := by + unfold stepCumulative uniformWeights + rw [← Finset.sum_filter] + have he : Finset.univ.filter (fun j : Fin (k+1) => j ≤ i.castSucc)=Finset.Iic i.castSucc := by + ext j; simp + rw [he,Finset.sum_const,Fin.card_Iic] + simp only [Fin.val_castSucc,nsmul_eq_mul] + push_cast + ring + +lemma uniformExponents_castSucc (k : ℕ) (i : Fin (k+1)) : + uniformExponents k i.castSucc=fieldExponents (uniformWeights k) i := by + refine Fin.cases ?_ (fun i => ?_) i + · simp [uniformExponents,fieldExponents] + · simp [uniformExponents,fieldExponents,stepCumulative_uniformWeights] + +def sphericalGridValue (n k : ℕ) (v : Fin (k+2) → ℝ) : ℝ := + sphericalHeatValue n (List.ofFn fun i => (uniformExponents k i,Real.sqrt (v i))) + +def sphericalGridDual (k : ℕ) (v : Fin (k+2) → ℝ) : ℝ := + sInf (finiteSphericalDualValues (uniformWeights k) (varianceLevels (fun i => v i.castSucc)) + (fun i => (uniformWeights_pos k i).le) (uniformWeights_sum k)) + +lemma sphericalGridValue_eq (n k : ℕ) (v : Fin (k+2) → ℝ) (hv : ∀ i, 0 ≤ v i) : + sphericalGridValue n k v=finiteSphericalFieldValue n k (uniformWeights k) + (varianceLevels (fun i => v i.castSucc)) := by + rw [finiteSphericalFieldValue_eq_heat (uniformWeights k) _ (uniformWeights_pos k) + (uniformWeights_sum k) (varianceLevels_monotone _ (fun i => hv i.castSucc)) + (varianceLevels_nonneg _ (fun i => hv i.castSucc) 0),fieldVariances_varianceLevels] + unfold sphericalGridValue sphericalHeatValue + have hs : ((List.ofFn fun i => (uniformExponents k i,Real.sqrt (v i))).map fun c => c.2^2).sum= + (∑ i : Fin (k+1), v i.castSucc)+v (Fin.last (k+1)) := by + rw [List.map_ofFn,List.sum_ofFn] + change (∑ i, (Real.sqrt (v i))^2)=_ + simp only [Real.sq_sqrt (hv _)] + exact Fin.sum_univ_castSucc v + have hs' : ((List.ofFn fun i => (fieldExponents (uniformWeights k) i, + Real.sqrt (v (i : Fin (k+1)).castSucc))).map fun c => c.2^2).sum=∑ i : Fin (k+1), v i.castSucc := by + rw [List.map_ofFn,List.sum_ofFn] + change (∑ i : Fin (k+1), (Real.sqrt (v i.castSucc))^2)=_ + simp only [Real.sq_sqrt (hv _)] + rw [hs,hs'] + change gaussianGrid (k+2) (uniformExponents k) v _ 0/(n+1:ℕ)-_= _ + rw [gaussianGrid_spherical_last n k _ _ (uniformExponents_nonneg k) + (hv _) (uniformExponents_last k)] + simp only [uniformExponents_castSucc] + unfold gaussianGrid + have hn : (n+1:ℕ) ≠ (0:ℝ) := by positivity + field_simp [hn] + ring + +lemma varianceLevels_continuous (k : ℕ) : Continuous (varianceLevels (k := k)) := by + apply continuous_pi + intro i + unfold varianceLevels + apply Continuous.div_const + apply continuous_finsetSum + intro j _ + split_ifs <;> fun_prop + +lemma sphericalGridValue_compact_uniform (k : ℕ) (H : ℝ) : + TendstoUniformlyOn (fun n => sphericalGridValue n k) (sphericalGridDual k) atTop + (Icc (fun _ => 0) (fun _ => H)) := by + let T : (Fin (k+2) → ℝ) → (Fin (k+1) → ℝ) := fun v => varianceLevels (fun i => v i.castSucc) + have hT : Continuous T := (varianceLevels_continuous k).comp (by fun_prop) + have hK : IsCompact (T '' Icc (fun _ => 0) (fun _ => H)) := isCompact_Icc.image hT + have hfield : ∀ h ∈ T '' Icc (fun _ => 0) (fun _ => H), Monotone h ∧ 0 ≤ h 0 := by + rintro h ⟨v,hv,rfl⟩ + exact ⟨varianceLevels_monotone _ (fun i => hv.1 i.castSucc), + varianceLevels_nonneg _ (fun i => hv.1 i.castSucc) 0⟩ + have hu := finiteSphericalFieldValue_compact_uniform (uniformWeights k) + (uniformWeights_pos k) (uniformWeights_sum k) hK hfield + rw [Metric.tendstoUniformlyOn_iff] at hu ⊢ + intro ε hε + filter_upwards [hu ε hε] with n hn v hv + rw [sphericalGridValue_eq n k v (fun i => hv.1 i)] + exact hn (T v) ⟨v,hv,rfl⟩ + +lemma gridVariance_weighted_sum {N : ℕ} (l : List (Fin N×ℝ)) (g : Fin N → ℝ) : + (∑ i, g i*gridVariance l i)=(l.map fun c => g c.1*c.2).sum := by + induction l with + | nil => simp [gridVariance] + | cons c l ih => + rw [gridVariance_cons] + simp only [mul_add,Finset.sum_add_distrib,ih,List.map_cons,List.sum_cons] + simp only [mul_ite,mul_zero] + simp [add_comm] + +lemma gridVariance_sum {N : ℕ} (l : List (Fin N×ℝ)) : + (∑ i, gridVariance l i)=(l.map Prod.snd).sum := by + simpa only [one_mul] using gridVariance_weighted_sum l (fun _ => 1) + +lemma sphericalGridValue_compress (n k : ℕ) (l : List (Fin (k+2)×ℝ)) + (hl : l.Pairwise (fun a b => a.1 ≤ b.1)) (hv : ∀ c ∈ l, 0 ≤ c.2) : + sphericalHeatValue n (l.map fun c => (uniformExponents k c.1,Real.sqrt c.2))= + sphericalGridValue n k (gridVariance l) := by + unfold sphericalHeatValue sphericalGridValue + unfold sphericalHeatValue + rw [gaussianBackward_compress (logSphericalExp_lipschitz n (Real.sqrt (n+1:ℕ))) + (k+2) (uniformExponents k) (uniformExponents_nonneg k) l hl hv] + congr 1 + rw [List.map_ofFn,List.sum_ofFn,List.map_map] + change (l.map fun c => (Real.sqrt c.2)^2).sum/2=(∑ i, (Real.sqrt (gridVariance l i))^2)/2 + simp only [Real.sq_sqrt (gridVariance_nonneg l hv _)] + rw [gridVariance_sum] + congr 2 + apply List.map_congr_left + intro c hc + exact Real.sq_sqrt (hv c hc) + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/UniformQuantileCells.lean b/lean/OAI/Probability/Perceptron/Variational/UniformQuantileCells.lean new file mode 100644 index 0000000000000000000000000000000000000000..e5600c2b9d7a134b2e80dbccd90b60bac0e9d420 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/UniformQuantileCells.lean @@ -0,0 +1,185 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.FiniteFieldModel + +namespace OAI + +noncomputable section +namespace SphericalPerceptronFreeEnergy +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology NNReal ENNReal BigOperators BoundedContinuousFunction + +def uniformQuantileGrid (n : ℕ) (i : Fin (n+2)) : Time := + ⟨(i:ℝ)/(n+1),div_nonneg (Nat.cast_nonneg _) (by positivity), + (div_le_one (by positivity : (0:ℝ) hu (Subtype.ext he))) i) + rw [measureReal_congr hae] + simp only [Measure.real,timeLaw_eq_volume,unitInterval.volume_Ico] + rw [ENNReal.toReal_ofReal] + · dsimp [uniformQuantileGrid] + push_cast + ring + · exact sub_nonneg.mpr ((uniformQuantileGrid_strict n).monotone (Fin.castSucc_le_succ i)) + +lemma uniformQuantileCell_integral (n : ℕ) (F : Fin (n+1)→ℝ) : + (∫ u, F (uniformQuantileCell n u) ∂timeLaw)=∑ i, (1/(n+1:ℝ))*F i := by + rw [integral_finite_label _ (uniformQuantileCell_measurable n)] + simp_rw [uniformQuantileCell_weight] + +lemma uniformQuantileCell_upper {n : ℕ} (k : Fin (n+1)) (u : Time) : + k ≤ uniformQuantileCell n u ↔ uniformQuantileGrid n k.castSucc≤u := by + change k.val ≤ min ⌊(n+1:ℝ)*(u:ℝ)⌋₊ n ↔ (k:ℝ)/(n+1)≤u + rw [le_min_iff,and_iff_left (Nat.le_of_lt_succ k.isLt),Nat.le_floor_iff (mul_nonneg (by positivity) u.2.1), + div_le_iff₀ (by positivity)] + rw [mul_comm (u:ℝ)] + +lemma uniformQuantileCell_tail_integral (n : ℕ) (F : Fin (n+1)→ℝ) (k : Fin (n+1)) : + (∫ u in Ici (uniformQuantileGrid n k.castSucc), F (uniformQuantileCell n u) ∂timeLaw)= + ∑ i, if k ≤ i then (1/(n+1:ℝ))*F i else 0 := by + rw [← integral_indicator measurableSet_Ici] + have he (u : Time) : (Ici (uniformQuantileGrid n k.castSucc)).indicator + (fun u => F (uniformQuantileCell n u)) u= + (if k ≤ uniformQuantileCell n u then F (uniformQuantileCell n u) else 0) := by + simp only [Set.indicator_apply,mem_Ici,← uniformQuantileCell_upper] + simp_rw [he] + rw [uniformQuantileCell_integral n (fun i => if k ≤ i then F i else 0)] + apply Finset.sum_congr rfl + intro i _ + split_ifs <;> simp + +def compactSpinTime (x : CompactOverlap) : Time := + ⟨(x.val+1)/2,by linarith [x.2.1],by linarith [x.2.2]⟩ + +lemma compactSpinTime_continuous : Continuous compactSpinTime := by + unfold compactSpinTime + fun_prop + +lemma compactSpinTime_mono : Monotone compactSpinTime := by + intro x y hxy + change (x.val+1)/2 ≤ (y.val+1)/2 + have : x.val ≤ y.val := hxy + linarith + +def compactSpinCode (n : ℕ) (x : CompactJointOverlap) : Fin (n+1) := + uniformQuantileCell n (compactSpinTime x.1) + +lemma compactSpinCode_measurable (n : ℕ) : Measurable (compactSpinCode n) := + (uniformQuantileCell_measurable n).comp (compactSpinTime_continuous.measurable.comp measurable_fst) + +lemma compactSpinCode_mono (n : ℕ) {x y : CompactJointOverlap} (h : x.1.val ≤ y.1.val) : + compactSpinCode n x ≤ compactSpinCode n y := + uniformQuantileCell_mono n (compactSpinTime_mono h) + +def compactSpinDecode (n : ℕ) (i : Fin (n+1)) : ℝ := + 2*(uniformQuantileGrid n i.castSucc:ℝ)-1 + +lemma compactSpinDecode_error (n : ℕ) (x : CompactJointOverlap) : + |compactSpinDecode n (compactSpinCode n x)-x.1.val| ≤ 2/(n+1:ℝ) := by + obtain ⟨hlo,hhi⟩ := uniformQuantileCell_bounds n (compactSpinTime x.1) + have hlo' : (uniformQuantileGrid n (compactSpinCode n x).castSucc:ℝ) ≤ (x.1.val+1)/2 := hlo + have hhi' : (x.1.val+1)/2 ≤ (uniformQuantileGrid n (compactSpinCode n x).succ:ℝ) := hhi + have hgap : (uniformQuantileGrid n (compactSpinCode n x).succ:ℝ)- + (uniformQuantileGrid n (compactSpinCode n x).castSucc:ℝ)=1/(n+1:ℝ) := by + simp only [uniformQuantileGrid,Fin.val_succ,Fin.val_castSucc,Nat.cast_add,Nat.cast_one] + ring + dsimp only [compactSpinDecode] + rw [abs_of_nonpos (by linarith)] + simp only [div_eq_mul_inv,one_mul] at hgap ⊢ + linarith + +lemma compactSpinDecode_tendsto (x : CompactJointOverlap) : + Tendsto (fun n => compactSpinDecode n (compactSpinCode n x)) atTop (𝓝 x.1.val) := by + apply tendsto_of_tendsto_of_tendsto_of_le_of_le + (g := fun n : ℕ => x.1.val-2*(1/(n+1:ℝ))) (h := fun n : ℕ => x.1.val+2*(1/(n+1:ℝ))) + · simpa using tendsto_const_nhds.sub ((tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul 2) + · simpa using tendsto_const_nhds.add ((tendsto_one_div_add_atTop_nhds_zero_nat (𝕜:=ℝ)).const_mul 2) + · intro n + have h := (abs_le.mp (compactSpinDecode_error n x)).1 + simp only [div_eq_mul_inv,one_mul] at h ⊢ + linarith + · intro n + have h := (abs_le.mp (compactSpinDecode_error n x)).2 + simp only [div_eq_mul_inv,one_mul] at h ⊢ + linarith + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/UniformUncapLimit.lean b/lean/OAI/Probability/Perceptron/Variational/UniformUncapLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..a3812001e2e4070d9a530de179a9c5642174a47c --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/UniformUncapLimit.lean @@ -0,0 +1,36 @@ +import Mathlib +import OAI.Probability.Perceptron.Model + +namespace OAI + +noncomputable section +open Filter +open scoped Topology +namespace SphericalPerceptronFreeEnergy + +lemma tendsto_zero_of_uniform_inverse_cap (f : ℕ→ℝ) (g : ℝ→ℕ→ℝ) {C : ℝ} + (hC : 0≤C) (hbound : ∀ Λ,1≤Λ→∀ j,|f j-g Λ j|≤C/Λ) + (hlim : ∀ Λ,1≤Λ→Tendsto (g Λ) atTop (𝓝 0)) : Tendsto f atTop (𝓝 0) := by + apply Metric.tendsto_atTop.mpr + intro ε hε + let Λ:=1+2*C/ε + have hΛ : 1≤Λ:=by dsimp [Λ]; linarith [div_nonneg (mul_nonneg (by norm_num : (0:ℝ)≤2) hC) hε.le] + have hΛp : 0<Λ:=lt_of_lt_of_le zero_lt_one hΛ + have hsmall : C/Λ<ε/2 := by + apply (div_lt_iff₀ hΛp).mpr + dsimp [Λ] + field_simp + nlinarith + obtain ⟨N,hN⟩:=Metric.tendsto_atTop.mp (hlim Λ hΛ) (ε/2) (half_pos hε) + refine ⟨N,fun j hj=>?_⟩ + have he:=hN j hj + rw [Real.dist_eq,sub_zero] at he ⊢ + calc + |f j|≤|f j-g Λ j|+|g Λ j|:=by simpa using abs_add_le (f j-g Λ j) (g Λ j) + _≤C/Λ+|g Λ j|:=add_le_add (hbound Λ hΛ j) le_rfl + _<ε:=by linarith +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/UpperContact.lean b/lean/OAI/Probability/Perceptron/Variational/UpperContact.lean new file mode 100644 index 0000000000000000000000000000000000000000..1a47b12867734dd634c9f608a824824804a2a24e --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/UpperContact.lean @@ -0,0 +1,188 @@ +import Mathlib +import OAI.Probability.Perceptron.Control.FreshControl +import OAI.Probability.Perceptron.Control.ContactControl +import OAI.Probability.Perceptron.Variational.ContactDensity +import OAI.Probability.Perceptron.Cascade.Poissonization +import OAI.Probability.Perceptron.Variational.Field +import OAI.Probability.Perceptron.Variational.BoundaryEstimate +import OAI.Probability.Perceptron.Cavity.FreshDensity + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal NNReal BigOperators BoundedContinuousFunction +namespace SphericalPerceptronFreeEnergy + +theorem sourceStepContactObjective_eventual_lower (k : ℕ) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) + (g : Jet3) (p d : ℕ → ℕ) + (hcover : ∀ a b : ℕ, 1≤a+b → ∃ j, p j=a ∧ d j=b) + (w : Fin (k+1) → ℝ) (q r : Fin (k+1) → Time) + (hw : ∀ i, 0 (hw i).le) hw1)).toReal+ + 2*(α:ℝ)*‖g.f‖ ≤ η*w (Fin.last k)*H) + {δ ε : ℝ} (hδ : 0<δ) (hε : 0<ε) : + ∀ᶠ n : ℕ in atTop, ∀ a ∈ sourceContactCompactDomain n k α H, + -ε ≤ sourceStepContactObjective n k P g.f (fun i => p i.val) (fun i => d i.val) + w q (fun i => (hw i).le) hw1 δ a := by + choose c hc hm using fun n => source_global_contact_exists n k P g.f + (fun i => p i.val) (fun i => d i.val) w q hw hw1 δ α hH0 + have hmin n := source_global_contact_perturbation_min n k P g.f + (fun i => p i.val) (fun i => d i.val) w q (fun i => (hw i).le) hw1 δ α H (hc n) (hm n) + have he : ∀ᶠ n : ℕ in atTop, -ε ≤ sourceStepContactObjective n k P g.f + (fun i => p i.val) (fun i => d i.val) w q (fun i => (hw i).le) hw1 δ (c n) := by + by_contra hnot + have hf : ∃ᶠ n : ℕ in atTop, sourceStepContactObjective n k P g.f + (fun i => p i.val) (fun i => d i.val) w q (fun i => (hw i).le) hw1 δ (c n)< -ε := by + simpa only [not_eventually,not_le] using hnot + obtain ⟨v,hv,hneg⟩ := extraction_of_frequently_atTop hf + obtain ⟨ν,s,hs,hlim⟩ := compact_array_law_subsequence (fun n => + sourceGibbsArrayLaw (v n) k g.f (fun i => p i.val) (fun i => d i.val) + (c (v n)).2.1 (c (v n)).2.2 (stepCumulative w) (c (v n)).1) + let b := v ∘ s + have hb : StrictMono b := hv.comp hs + have hl : Tendsto (fun n => sourceGibbsArrayLaw (b n) k g.f + (fun i => p i.val) (fun i => d i.val) (c (b n)).2.1 (c (b n)).2.2 + (stepCumulative w) (c (b n)).1) atTop (𝓝 ν) := hlim + have ht : ∀ᶠ n in atTop, 0<(c (b n)).1 := by + filter_upwards [hb.tendsto_atTop.eventually + (sourceNegativeContact_positive_density w hw hw1 H hε)] with n hn + exact hn P g.f _ _ q hq hq1 δ α (c (b n)) (hc (b n)) (hneg (s n)) + have hcap : ∀ᶠ n in atTop, (c (b n)).2.1 (Fin.last k) (c n).1) (fun n => (c n).2.1) (fun n => (hc n).2.1.1.1) + (fun n => (hc n).2.1.2) (fun n => (c n).2.2) (fun n => (hc n).2.2) hmin hH0 + (fun n => (hc n).2.1.1.2 0) (T := (α:ℝ)) (fun n => (hc n).1.2) hcover hb hl P hB + have hderiv : controlValue P g.f (weightedStepTrial w q (fun i => (hw i).le) hw1)+δ ≤ + controlValue P g.f (quantileTrial (boundedQuantile ((compactPositivePairLaw ν).map Prod.fst))) := by + apply ge_of_tendsto hfresh + filter_upwards [ht] with n hn + rw [←sourceDensityIncrement_eq_fresh (b n) k g.f _ _ _ + (hc (b n)).2.1.1.1 (hc (b n)).2.1.2 _ _ + (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) (stepCumulative_lt_one w hw hw1)] + exact source_global_contact_density (b n) k P g.f _ _ w q hw hw1 δ α H (hc (b n)) (hm (b n)) hn + linarith + filter_upwards [he] with n hn + intro a ha + exact hn.trans (hm n ha) + + +lemma source_depoisson_error_tendsto (f : ℝ →ᵇ ℝ) (α : ℝ≥0) : + Tendsto (fun n : ℕ => ‖f‖/(n+1:ℕ)*(Real.sqrt ((n+1:ℕ)*(α:ℝ))+1)) atTop (𝓝 0) := by + have hn : Tendsto (fun n : ℕ => ((n+1:ℕ):ℝ)) atTop atTop := + tendsto_natCast_atTop_atTop.comp (tendsto_add_atTop_nat 1) + have h1 : Tendsto (fun n : ℕ => (α:ℝ)/(n+1:ℕ)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop hn + have h2 : Tendsto (fun n : ℕ => (1:ℝ)/(n+1:ℕ)) atTop (𝓝 0) := + tendsto_const_nhds.div_atTop hn + have he (n : ℕ) : ‖f‖/(n+1:ℕ)*(Real.sqrt ((n+1:ℕ)*(α:ℝ))+1)= + ‖f‖*(Real.sqrt ((α:ℝ)/(n+1:ℕ))+1/(n+1:ℕ)) := by + have hn0 : (0:ℝ)<(n+1:ℕ) := by positivity + have hs : Real.sqrt ((n+1:ℕ)*(α:ℝ))/(n+1:ℕ)=Real.sqrt ((α:ℝ)/(n+1:ℕ)) := by + calc + _ = Real.sqrt (((n+1:ℕ)*(α:ℝ))/((n+1:ℕ):ℝ)^2) := by + rw [Real.sqrt_div (by positivity),Real.sqrt_sq hn0.le] + _ = _ := by congr 1; field_simp + calc + _ = ‖f‖*(Real.sqrt ((n+1:ℕ)*(α:ℝ))/(n+1:ℕ)+1/(n+1:ℕ)) := by ring + _ = _ := by rw [hs] + simp_rw [he] + simpa using (h1.sqrt.add h2).const_mul ‖f‖ + +lemma source_zeroField_original_compare (n k : ℕ) (f : ℝ →ᵇ ℝ) + (p d : Fin (n+1)→ℕ) (z : Fin k→ℝ) (hz : StrictMono z) + (hz0 : ∀ i, 0 0) z α (fun _ => 3/2)+ + 8*perturbationScale (n+1)^2+‖f‖/(n+1:ℕ)*(Real.sqrt ((n+1:ℕ)*(α:ℝ))+1) := by + have hp := sourceExpectedPressure_perturbation_comparison n k f p d (fun _ => 0) + (fun _ => le_rfl) monotone_const z hz hz0 hz1 α + (u := fun _ => 0) (v := fun _ => 3/2) + (fun _ => ⟨le_rfl,by norm_num⟩) (fun _ => by constructor <;> norm_num) + change |sourceExpectedPressure n k f p d (fun _ => 0) z α (fun _ => 3/2)- + sourceExpectedPressure n k f p d (fun _ => 0) z α (fun _ => 0)|≤_ at hp + have hd := sourceExpectedPressure_floor_count_compare n k f p d (fun _ => 0) z + (fun _ => 0) hz hz0 hz1 α + have ho := sourceCountExpectedLog_original (α:ℝ) 1 f n k p d z hz hz0 hz1 + simp only [one_smul,patternCount,mul_comm (α:ℝ)] at ho + rw [ho] at hd + linarith [(abs_le.mp hp).1,(abs_le.mp hd).1] + +theorem expectedPressure_upper_weightedStep (k : ℕ) + (P : Measure BrownianPath) [IsProbabilityMeasure P] (hB : IsBrownianReal brownianEval P) + (g : Jet3) (w : Fin (k+1)→ℝ) (q : Fin (k+1)→Time) + (hw : ∀ i, 0 (hw i).le) hw1)).toReal+ + (α:ℝ)*controlValue P g.f (weightedStepTrial w q (fun i => (hw i).le) hw1)+ε := by + let r : Fin (k+1)→Time := fun i => ⟨((q i:ℝ)+1)/2,by + constructor <;> linarith [(q i).2.1,(q i).2.2]⟩ + have hr : Monotone r := by + intro i j hij + change ((q i:ℝ)+1)/2 ≤ ((q j:ℝ)+1)/2 + have he : (q i:ℝ)≤(q j:ℝ) := hq hij + linarith + have hr1 : (r (Fin.last k):ℝ)<1 := by dsimp [r]; linarith + let η : ℝ := (1-(q (Fin.last k):ℝ))/2 + have hη : 0<η := by dsimp [η]; linarith + have hqr i : (q i:ℝ)+η≤(r i:ℝ) := by + have he : (q i:ℝ)≤(q (Fin.last k):ℝ) := hq (Fin.le_last i) + dsimp [η,r] + linarith + let A := (entropy (weightedStepTrial w r (fun i => (hw i).le) hw1)).toReal+2*(α:ℝ)*‖g.f‖ + let H := A/(η*w (Fin.last k)) + have hH0 : 0≤H := by + apply div_nonneg _ (mul_pos hη (hw _)).le + dsimp [A] + positivity + have hH : A≤η*w (Fin.last k)*H := by + dsimp [H] + rw [mul_div_cancel₀ _ (ne_of_gt (mul_pos hη (hw _)))] + let δ := ε/(4*((α:ℝ)+1)) + have hδ : 0<δ := by dsimp [δ]; positivity + have hd : (α:ℝ)*δ≤ε/4 := by + dsimp [δ] + apply (le_div_iff₀ (by norm_num : (0:ℝ)<4)).mpr + have hc : (α:ℝ)*ε≤ε*((α:ℝ)+1) := by nlinarith [α.coe_nonneg] + have he : (α:ℝ)*(ε/(4*((α:ℝ)+1)))*4=(α:ℝ)*ε/((α:ℝ)+1) := by + field_simp + rw [he] + exact (div_le_iff₀ (by positivity)).mpr hc + let p : ℕ→ℕ := fun i => (Nat.unpair i).1 + let d : ℕ→ℕ := fun i => (Nat.unpair i).2 + have hcover : ∀ a b : ℕ, 1≤a+b → ∃ j, p j=a ∧ d j=b := by + intro a b _ + exact ⟨Nat.pair a b,by simp [p,d]⟩ + have hc := sourceStepContactObjective_eventual_lower k P hB g p d hcover w q r hw hw1 + hq hq1 hr hr1 hη hqr α H hH0 hH hδ (show 0<ε/4 by positivity) + have ht : Tendsto (fun n : ℕ => 8*perturbationScale (n+1)^2) atTop (𝓝 0) := by + simpa using perturbationScale_tendsto_zero.pow 2 |>.const_mul 8 + filter_upwards [hc,ht.eventually (gt_mem_nhds (show (0:ℝ)<ε/4 by positivity)), + (source_depoisson_error_tendsto g.f α).eventually (gt_mem_nhds (show (0:ℝ)<ε/4 by positivity))] + with n hn ht' he' + have ha : (α,fun _ => 0,fun _ : Fin (n+1) => 3/2)∈sourceContactCompactDomain n k α H := by + refine ⟨⟨zero_le,le_rfl⟩,⟨⟨fun _ => le_rfl,fun _ => hH0⟩,monotone_const⟩,?_⟩ + constructor <;> intro j <;> norm_num + have hh := hn _ ha + simp only [sourceStepContactObjective,sourceJointPressure,quadraticBoxPenalty, + sub_self,zero_pow (by norm_num : 2≠0),mul_zero,Finset.sum_const_zero,sub_zero,add_zero] at hh + have ho := source_zeroField_original_compare n k g.f (fun i => p i.val) (fun i => d i.val) + (stepCumulative w) (stepCumulative_strictMono w hw) (stepCumulative_pos w hw) + (stepCumulative_lt_one w hw hw1) α + linarith + +end SphericalPerceptronFreeEnergy +end + +end OAI diff --git a/lean/OAI/Probability/Perceptron/Variational/VarianceProdMemLp.lean b/lean/OAI/Probability/Perceptron/Variational/VarianceProdMemLp.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d0db1e476b3f891b34503795038e0bf12d2be26 --- /dev/null +++ b/lean/OAI/Probability/Perceptron/Variational/VarianceProdMemLp.lean @@ -0,0 +1,252 @@ +import Mathlib +import OAI.Probability.Perceptron.Variational.Trial +import OAI.Probability.Perceptron.Pressure.VectorPartition +import OAI.Probability.Perceptron.Interpolation.GibbsReplicaMean + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Filter Set +open scoped ENNReal NNReal Topology BigOperators BoundedContinuousFunction +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal BigOperators Topology RealInnerProductSpace +namespace SphericalPerceptronFreeEnergy + +section +section GeneralProductVariance +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure X) (ν : Measure Y) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + +lemma variance_prod_le_memLp {F : X × Y → ℝ} + (hp : MemLp F 2 (μ.prod ν)) (hs : ∀ x, MemLp (fun y => F (x,y)) 2 ν) + (hh : MemLp (fun x => ∫ y, F (x,y) ∂ν) 2 μ) {A B : ℝ} + (hA : ∀ x, variance (fun y => F (x,y)) ν ≤ A) + (hB : variance (fun x => ∫ y, F (x,y) ∂ν) μ ≤ B) : + variance F (μ.prod ν) ≤ A+B := by + have hi : (∫ x, ∫ y, F (x,y)^2 ∂ν ∂μ) ≤ A+∫ x, (∫ y, F (x,y) ∂ν)^2 ∂μ := by + calc + _ ≤ ∫ x, (A+(∫ y, F (x,y) ∂ν)^2) ∂μ := by + apply integral_mono hp.integrable_sq.integral_prod_left + ((integrable_const A).add hh.integrable_sq) + intro x + have hv := hA x + rw [variance_eq_sub (hs x)] at hv + simpa only [Pi.pow_apply, Pi.add_apply] using sub_le_iff_le_add.mp hv + _ = _ := by rw [integral_add (integrable_const _) hh.integrable_sq]; simp + rw [variance_eq_sub hh] at hB + rw [variance_eq_sub hp] + simp only [Pi.pow_apply] at hB ⊢ + rw [integral_prod _ hp.integrable_sq, + integral_prod _ (hp.integrable (by norm_num))] + linarith + +end GeneralProductVariance + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {S : Type*} [MeasurableSpace S] (ρ : Measure S) [IsProbabilityMeasure ρ] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorLogPartition_bound {W : S → ℝ} {V : S → StrongDual ℝ E} + (hWm : Measurable W) (hVm : Measurable V) {K C : ℝ} + (hW : ∀ s, |W s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) (x : E) : + |vectorLogPartition ρ W V x| ≤ K+C*‖x‖ := by + have hh := abs_log_integral_exp_sub_le ρ + (vectorPartition_integrable ρ hWm hVm hW hV x) + (show Integrable (fun _ : S => Real.exp 0) ρ by simp) + (vectorPartition_pos ρ hWm hVm hW hV x) + (show 0 < ∫ _ : S, Real.exp 0 ∂ρ by simp) + (c := K+C*‖x‖) (fun s => by simpa using vectorEnergy_bound hW hV x s) + simpa [vectorLogPartition,vectorPartition] using hh + +omit [MeasurableSpace E] [BorelSpace E] in +lemma vectorLogPartition_data_bound {W W' : S → ℝ} {V : S → StrongDual ℝ E} + (hWm : Measurable W) (hWm' : Measurable W') (hVm : Measurable V) {K K' C c : ℝ} + (hW : ∀ s, |W s| ≤ K) (hW' : ∀ s, |W' s| ≤ K') (hV : ∀ s, ‖V s‖ ≤ C) + (hWc : ∀ s, |W s-W' s| ≤ c) (x : E) : + |vectorLogPartition ρ W V x-vectorLogPartition ρ W' V x| ≤ c := by + exact abs_log_integral_exp_sub_le ρ + (vectorPartition_integrable ρ hWm hVm hW hV x) + (vectorPartition_integrable ρ hWm' hVm hW' hV x) + (vectorPartition_pos ρ hWm hVm hW hV x) + (vectorPartition_pos ρ hWm' hVm hW' hV x) + (fun s => by simpa only [add_sub_add_right_eq_sub] using hWc s) + +variable {X : Type*} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [SecondCountableTopology X] [Nonempty X] (μ : Measure X) [IsProbabilityMeasure μ] + +lemma vectorLogPartition_mixed_variance (n : ℕ) + {W : (Fin n → X) → S → ℝ} {V : S → StrongDual ℝ E} + (hWm : Measurable (Function.uncurry W)) (hWc : ∀ s, Continuous (fun p => W p s)) + (hVm : Measurable V) {K C c : ℝ} (hC : 0 ≤ C) + (hW : ∀ p s, |W p s| ≤ K) (hV : ∀ s, ‖V s‖ ≤ C) + (hosc : ∀ p i z s, |W (Function.update p i z) s-W p s| ≤ c) : + variance (fun p => vectorLogPartition ρ (W p.1) V p.2) + ((Measure.pi fun _ : Fin n => μ).prod (stdGaussian E)) ≤ + Real.pi^2/8*C^2+(n:ℝ)*c^2 := by + classical + let ν := Measure.pi (fun _ : Fin n => μ) + let γ := stdGaussian E + let F := fun (p : Fin n → X) (g : E) => vectorLogPartition ρ (W p) V g + have hWm' (p) : Measurable (W p) := hWm.comp (measurable_const.prodMk measurable_id) + have hFm : Measurable (Function.uncurry F) := by + have hm : Measurable (fun p : ((Fin n → X)×E)×S => + Real.exp (W p.1.1 p.2+V p.2 p.1.2)) := by + apply Measurable.exp + exact (hWm.comp ((measurable_fst.comp measurable_fst).prodMk measurable_snd)).add + (((continuous_fst.clm_apply continuous_snd : Continuous + (fun p : StrongDual ℝ E × E => p.1 p.2)).measurable).comp + ((hVm.comp measurable_snd).prodMk (measurable_snd.comp measurable_fst))) + exact hm.stronglyMeasurable.integral_prod_right'.measurable.log + have hFB (p) (g) : |F p g| ≤ K+C*‖g‖ := + vectorLogPartition_bound ρ (hWm' p) hVm (hW p) hV g + have hGB : MemLp (fun g : E => K+C*‖g‖) 2 γ := by + exact (memLp_const K).add ((IsGaussian.memLp_id γ 2 (by simp)).norm.const_mul C) + have hFL (p) : MemLp (F p) 2 γ := hGB.mono' + ((hFm.comp (measurable_const.prodMk measurable_id)).aestronglyMeasurable) + (ae_of_all _ fun g => by simpa only [Real.norm_eq_abs] using hFB p g) + have hFp (g : E) : Continuous (fun p => F p g) := by + have hp : Continuous (fun p => vectorPartition ρ (W p) V g) := by + apply continuous_of_dominated (bound := fun _ => Real.exp (K+C*‖g‖)) + · intro p; exact (vectorPartition_integrable ρ (hWm' p) hVm (hW p) hV g).aestronglyMeasurable + · intro p; apply ae_of_all; intro s + rw [Real.norm_eq_abs,abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr ((le_abs_self _).trans (vectorEnergy_bound (hW p) hV g s)) + · exact integrable_const _ + · exact ae_of_all _ fun s => ((hWc s).add continuous_const).rexp + exact hp.log (fun p => (vectorPartition_pos ρ (hWm' p) hVm (hW p) hV g).ne') + have hAc : Continuous (fun p => ∫ g, F p g ∂γ) := by + apply continuous_of_dominated (bound := fun g => K+C*‖g‖) + · intro p; exact (hFL p).aestronglyMeasurable + · intro p; exact ae_of_all _ fun g => by simpa only [Real.norm_eq_abs] using hFB p g + · exact hGB.integrable (by norm_num) + · exact ae_of_all _ hFp + have hAB (p) : |∫ g, F p g ∂γ| ≤ ∫ g, (K+C*‖g‖) ∂γ := by + exact (norm_integral_le_integral_norm _).trans + (integral_mono (hFL p |>.integrable (by norm_num) |>.norm) + (hGB.integrable (by norm_num)) (fun g => by simpa only [Real.norm_eq_abs] using hFB p g)) + have hAL : MemLp (fun p => ∫ g, F p g ∂γ) 2 ν := + MemLp.of_bound hAc.aestronglyMeasurable _ (ae_of_all _ hAB) + apply variance_prod_le_memLp ν γ + ((hGB.comp_snd ν).mono' hFm.aestronglyMeasurable + (ae_of_all _ fun p => by simpa only [Real.norm_eq_abs,Function.uncurry] using hFB p.1 p.2)) hFL hAL + · intro p + exact vectorLogPartition_gaussian_variance ρ (hWm' p) hVm hC (hW p) hV + · apply variance_pi_le_of_bounded_differences μ n hAc hAB + intro p i z + rw [← integral_sub ((hFL _).integrable (by norm_num)) ((hFL _).integrable (by norm_num))] + have hh := norm_integral_le_of_norm_le_const (μ := γ) + (f := fun g => F (Function.update p i z) g-F p g) (C := c) + (ae_of_all _ fun g => by + simpa only [Real.norm_eq_abs] using vectorLogPartition_data_bound ρ + (hWm' _) (hWm' _) hVm (hW _) (hW _) hV (hosc p i z) g) + simpa using hh + +end + +variable {S : Type*} [MeasurableSpace S] (μ : Measure S) [IsProbabilityMeasure μ] + +lemma integral_observable_factorization_bound {F G : S → ℝ} + (hF : Integrable F μ) (hG : Measurable G) {D : ℝ} (_hD : 0 ≤ D) + (hGD : ∀ x, |G x| ≤ D) (a : ℝ) : + |(∫ x, F x*G x ∂μ)-a*(∫ x, G x ∂μ)| ≤ D*∫ x, |F x-a| ∂μ := by + have hGI : Integrable G μ := Integrable.of_bound hG.aestronglyMeasurable D + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hGD x) + have hFG := hF.mul_bdd hG.aestronglyMeasurable + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hGD x) + have hFA := (hF.sub (integrable_const a)).abs + have he : (∫ x, F x*G x ∂μ)-a*(∫ x, G x ∂μ) = ∫ x, (F x-a)*G x ∂μ := by + simp_rw [sub_mul] + rw [integral_sub hFG (hGI.const_mul a),integral_const_mul] + rw [he,← integral_const_mul] + rw [← Real.norm_eq_abs] + apply (norm_integral_le_integral_norm _).trans + apply integral_mono + ((hF.sub (integrable_const a)).mul_bdd hG.aestronglyMeasurable + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hGD x)).norm + (hFA.const_mul D) + intro x + dsimp only [Pi.sub_apply] + rw [Real.norm_eq_abs,abs_mul,mul_comm D] + exact mul_le_mul_of_nonneg_left (hGD x) (abs_nonneg _) + +lemma replicaMean_energy_factorization_bound {H Y : S → ℝ} {n : ℕ} (j : Fin n) + {G : (Fin n → S) → ℝ} (hH : Measurable H) (hY : Measurable Y) (hG : Measurable G) + {A B D : ℝ} (hA : 0 ≤ A) (hD : 0 ≤ D) (hHA : ∀ x, |H x| ≤ A) + (hYB : ∀ x, |Y x| ≤ B) (hGD : ∀ x, |G x| ≤ D) (a : ℝ) : + |gibbsReplicaMean μ H n (fun x => Y (x j)*G x)-a*gibbsReplicaMean μ H n G| ≤ + D*tiltMean μ H (fun x => |Y x-a|) 1 := by + have := tilt_law_probability μ hH hA hHA 1 + have hYm : Measurable (fun x : Fin n → S => Y (x j)) := hY.comp (measurable_pi_apply j) + have hYI : Integrable (fun x : Fin n → S => Y (x j)) + (Measure.pi fun _ : Fin n => tiltLaw μ H 1) := + Integrable.of_bound hYm.aestronglyMeasurable B + (ae_of_all _ fun x => by simpa only [Real.norm_eq_abs] using hYB (x j)) + have hh := integral_observable_factorization_bound + (Measure.pi fun _ : Fin n => tiltLaw μ H 1) hYI hG hD hGD a + simp only [gibbsReplicaMean,tilt_replica_integral μ hH hA hHA] + rw [← tilt_replica_coordinate μ (F := fun x => |Y x-a|) hH (by fun_prop) hA hHA n j 1, + tilt_replica_integral μ hH hA hHA] + exact hh + +lemma measurable_tiltMean_param {Ω : Type*} [MeasurableSpace Ω] {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) : + Measurable (fun ω => tiltMean μ (H ω) (Y ω) 1) := by + simp only [tiltMean,tiltIntegral,tiltPartition,one_mul] + exact ((hH.exp.mul hY).stronglyMeasurable.integral_prod_right'.measurable).div + hH.exp.stronglyMeasurable.integral_prod_right'.measurable + +lemma measurable_replicaMean_param {Ω : Type*} [MeasurableSpace Ω] + {H : Ω → S → ℝ} {n : ℕ} {Y : Ω → (Fin n → S) → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) : + Measurable (fun ω => gibbsReplicaMean μ (H ω) n (Y ω)) := by + apply measurable_tiltMean_param _ _ hY + change Measurable (fun p : Ω×(Fin n → S) => ∑ i, H p.1 (p.2 i)) + exact Finset.measurable_sum _ fun i _ => hH.comp + (measurable_fst.prodMk ((measurable_pi_apply i).comp measurable_snd)) + +lemma annealed_replica_energy_factorization_bound {Ω : Type*} [MeasurableSpace Ω] + (P : Measure Ω) [IsProbabilityMeasure P] {H Y : Ω → S → ℝ} + (hH : Measurable (Function.uncurry H)) (hY : Measurable (Function.uncurry Y)) + {A B : Ω → ℝ} (hA : ∀ ω, 0 ≤ A ω) (hB : ∀ ω, 0 ≤ B ω) + (hHA : ∀ ω x, |H ω x| ≤ A ω) (hYB : ∀ ω x, |Y ω x| ≤ B ω) + (hBI : Integrable B P) {n : ℕ} (j : Fin n) {G : (Fin n → S) → ℝ} + (hG : Measurable G) {D : ℝ} (hD : 0 ≤ D) (hGD : ∀ x, |G x| ≤ D) (a : ℝ) : + |(∫ ω, gibbsReplicaMean μ (H ω) n (fun x => Y ω (x j)*G x) ∂P) - + a*(∫ ω, gibbsReplicaMean μ (H ω) n G ∂P)| ≤ + D*(∫ ω, tiltMean μ (H ω) (fun x => |Y ω x-a|) 1 ∂P) := by + have hHm (ω) : Measurable (H ω) := hH.comp (measurable_const.prodMk measurable_id) + have hYm (ω) : Measurable (Y ω) := hY.comp (measurable_const.prodMk measurable_id) + have hFGm : Measurable (fun ω => gibbsReplicaMean μ (H ω) n (fun x => Y ω (x j)*G x)) := by + apply measurable_replicaMean_param μ hH + exact (hY.comp (measurable_fst.prodMk ((measurable_pi_apply j).comp measurable_snd))).mul + (hG.comp measurable_snd) + have hFGI : Integrable (fun ω => gibbsReplicaMean μ (H ω) n (fun x => Y ω (x j)*G x)) P := by + apply (hBI.mul_const D).mono' hFGm.aestronglyMeasurable + exact ae_of_all _ fun ω => by + simpa only [Real.norm_eq_abs, Pi.mul_def, Function.comp_def] using replicaMean_bound μ (hHm ω) + (((hYm ω).comp (measurable_pi_apply j)).mul hG) (hA ω) (mul_nonneg (hB ω) hD) + (hHA ω) (fun x => by simp only [Pi.mul_apply, Function.comp_apply]; rw [abs_mul]; exact mul_le_mul (hYB ω _) (hGD x) (abs_nonneg _) (hB ω)) + have hGI : Integrable (fun ω => gibbsReplicaMean μ (H ω) n G) P := + Integrable.of_bound (replicaMean_measurable μ hH hG).aestronglyMeasurable D + (ae_of_all _ fun ω => by simpa only [Real.norm_eq_abs] using replicaMean_bound μ (hHm ω) hG (hA ω) hD (hHA ω) hGD) + have hAI : Integrable (fun ω => tiltMean μ (H ω) (fun x => |Y ω x-a|) 1) P := by + apply (hBI.add (integrable_const |a|)).mono' + (measurable_tiltMean_param μ hH (show Measurable (Function.uncurry (fun ω x => |Y ω x-a|)) from (hY.sub_const a).abs)).aestronglyMeasurable + exact ae_of_all _ fun ω => by + simpa only [Real.norm_eq_abs, Pi.sub_apply, Pi.add_apply] using tilt_mean_bound μ (hHm ω) ((hYm ω).sub measurable_const |>.abs) + (hA ω) (add_nonneg (hB ω) (abs_nonneg a)) (hHA ω) + (fun x => by rw [abs_abs]; exact (abs_sub _ _).trans (add_le_add (hYB ω x) le_rfl)) 1 + rw [← integral_const_mul,← integral_sub hFGI (hGI.const_mul a),← integral_const_mul] + rw [← Real.norm_eq_abs] + apply (norm_integral_le_integral_norm _).trans + apply integral_mono (hFGI.sub (hGI.const_mul a)).norm (hAI.const_mul D) + intro ω + simpa only [Real.norm_eq_abs,Pi.sub_apply] using replicaMean_energy_factorization_bound μ j (hHm ω) (hYm ω) hG (hA ω) hD (hHA ω) (hYB ω) hGD a + +end SphericalPerceptronFreeEnergy + +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/ConstrainedGaussian.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/ConstrainedGaussian.lean new file mode 100644 index 0000000000000000000000000000000000000000..c7195d9a8fdcee7dbc8d05437b36dd3287ab0ad7 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/ConstrainedGaussian.lean @@ -0,0 +1,213 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianDensity + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +namespace PosteriorReplicas + +section Rows +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def pairingsDensity {n : ℕ} (v : Fin n → E) (y : Fin n → ℝ) : ℝ≥0∞ := + ENNReal.ofReal ((2 * Real.pi) ^ (-(n : ℝ) / 2) * + Real.exp (-‖pairingLift v y‖^2 / 2) / Real.sqrt (Matrix.gram ℝ v).det) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[fun_prop] lemma continuous_pairingsDensity + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {n : ℕ} (v : Fin n → E) : + Continuous (pairingsDensity v) := by + unfold pairingsDensity + exact ENNReal.continuous_ofReal.comp (by fun_prop) + +lemma gaussian_pairingsDensity {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) : + (stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) = + volume.withDensity (pairingsDensity v) := gaussian_pairings_density hv + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma pairingsDensity_le_zero [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {n : ℕ} (v : Fin n → E) (y : Fin n → ℝ) : + pairingsDensity v y ≤ pairingsDensity v 0 := by + have hzero : pairingLift v 0 = 0 := by simp [pairingLift] + unfold pairingsDensity + rw [hzero, norm_zero, zero_pow (by decide), neg_zero, zero_div, Real.exp_zero, mul_one] + apply ENNReal.ofReal_le_ofReal + apply div_le_div_of_nonneg_right _ (Real.sqrt_nonneg _) + have he : Real.exp (-‖pairingLift v y‖^2 / 2) ≤ 1 := + Real.exp_le_one_iff.mpr (div_nonpos_of_nonpos_of_nonneg + (neg_nonpos.mpr (sq_nonneg _)) (by norm_num)) + simpa using mul_le_mul_of_nonneg_left he + (show 0 ≤ (2 * Real.pi) ^ (-(n : ℝ) / 2) by positivity) + +lemma rows_pairings_residual_joint {n : ℕ} (v : Fin n → E) (k : ℕ) : + (Measure.pi (fun _ : Fin k => stdGaussian E)).map + (fun A => ((fun j i => ⟪v i, A j⟫), + (fun j => (Submodule.span ℝ (Set.range v))ᗮ.starProjection (A j)))) = + (Measure.pi (fun _ : Fin k => (stdGaussian E).map (fun x => fun i => ⟪v i, x⟫))).prod + (Measure.pi (fun _ : Fin k => + (stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection)) := by + let U := Submodule.span ℝ (Set.range v) + let e := MeasurableEquiv.arrowProdEquivProdArrow (Fin n → ℝ) E (Fin k) + have h := (gaussian_pairings_residual_indep v).map_prod_eq_prod_map_map + (by fun_prop) (by fun_prop) + have hm : (fun A : Fin k → E => ((fun j i => ⟪v i, A j⟫), + fun j => Uᗮ.starProjection (A j))) = + e ∘ (fun A => fun j => ((fun i => ⟪v i, A j⟫), Uᗮ.starProjection (A j))) := rfl + change (Measure.pi _).map (fun A => ((fun j i => ⟪v i, A j⟫), fun j => Uᗮ.starProjection (A j))) = _ + rw [hm, ← Measure.map_map e.measurable (by fun_prop), + Measure.pi_map_pi (fun _ => (show Measurable (fun x : E => + ((fun i => ⟪v i, x⟫), Uᗮ.starProjection x)) by fun_prop).aemeasurable)] + dsimp only [U] + simp_rw [h] + exact (measurePreserving_arrowProdEquivProdArrow (Fin n → ℝ) E (Fin k) _ _).map_eq + +lemma rows_pairings_disintegration {n : ℕ} {v : Fin n → E} + (hv : LinearIndependent ℝ v) (k : ℕ) : + ((Measure.pi (fun _ : Fin k => (stdGaussian E).map (fun x => fun i => ⟪v i, x⟫))).prod + (Measure.pi (fun _ : Fin k => + (stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection))).map + (fun z j => pairingLift v (z.1 j) + z.2 j) = + Measure.pi (fun _ : Fin k => stdGaussian E) := by + rw [← rows_pairings_residual_joint, Measure.map_map (by fun_prop) (by fun_prop)] + convert (Measure.map_id (μ := Measure.pi (fun _ : Fin k => stdGaussian E))) using 1 + congr 1 + funext A j + simp only [Function.comp_apply] + rw [← starProjection_eq_pairingLift hv, + Submodule.starProjection_add_starProjection_orthogonal] + rfl + +lemma rows_pairings_density {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) (k : ℕ) : + (Measure.pi (fun _ : Fin k => stdGaussian E)).map (fun A j i => ⟪v i, A j⟫) = + (volume : Measure (Fin k → Fin n → ℝ)).withDensity + (fun y => ∏ j, pairingsDensity v (y j)) := by + have : IsProbabilityMeasure (volume.withDensity (pairingsDensity v)) := by + rw [← gaussian_pairingsDensity hv] + exact (Measure.isProbabilityMeasure_map_iff (by fun_prop)).mpr inferInstance + rw [Measure.pi_map_pi (fun _ => (show Measurable + (fun x : E => fun i => ⟪v i, x⟫) by fun_prop).aemeasurable)] + simp_rw [gaussian_pairingsDensity hv] + exact pi_withDensity _ _ (fun _ => (continuous_pairingsDensity v).measurable) + +lemma constrained_gaussian_integral {n : ℕ} {v : Fin n → E} + (hv : LinearIndependent ℝ v) (k : ℕ) {g : (Fin k → E) → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ A, g A ∂Measure.pi (fun _ : Fin k => stdGaussian E) = + ∫⁻ y : Fin k → Fin n → ℝ, (∏ j, pairingsDensity v (y j)) * + ∫⁻ R, g (fun j => pairingLift v (y j) + R j) + ∂Measure.pi (fun _ : Fin k => + (stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection) := by + have hp : IsProbabilityMeasure (volume.withDensity (pairingsDensity v)) := by + rw [← gaussian_pairingsDensity hv] + exact (Measure.isProbabilityMeasure_map_iff (by fun_prop)).mpr inferInstance + conv_lhs => rw [← rows_pairings_disintegration hv k] + rw [lintegral_map hg (by fun_prop), lintegral_prod _ (by fun_prop)] + simp_rw [gaussian_pairingsDensity hv] + rw [pi_withDensity _ _ (fun _ => (continuous_pairingsDensity v).measurable), + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] + rfl + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma pairingsDensity_zero [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {n : ℕ} (v : Fin n → E) : + pairingsDensity v 0 = ENNReal.ofReal + ((2 * Real.pi) ^ (-(n : ℝ) / 2) / Real.sqrt (Matrix.gram ℝ v).det) := by + simp [pairingsDensity, pairingLift] + +lemma rows_pairingsDensity_zero {n : ℕ} {v : Fin n → E} + (hv : LinearIndependent ℝ v) (k : ℕ) : + (∏ _j : Fin k, pairingsDensity v 0) = + ENNReal.ofReal ((2 * Real.pi) ^ (-((k : ℝ) * n) / 2)) * + (ENNReal.ofReal (Real.sqrt (Matrix.gram ℝ v).det))⁻¹ ^ k := by + have hd : 0 < Real.sqrt (Matrix.gram ℝ v).det := + Real.sqrt_pos.mpr (Matrix.posDef_gram_of_linearIndependent hv).det_pos + rw [Finset.prod_const, Finset.card_univ, Fintype.card_fin, pairingsDensity_zero, + ENNReal.ofReal_div_of_pos hd, div_eq_mul_inv, mul_pow] + congr 1 + rw [← ENNReal.ofReal_pow (by positivity), ← Real.rpow_natCast, + ← Real.rpow_mul (by positivity)] + congr 2 + ring + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma continuous_rows_pairingsDensity [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {n : ℕ} (v : Fin n → E) (k : ℕ) : + Continuous (fun y : Fin k → Fin n → ℝ => ∏ j, pairingsDensity v (y j)) := by + have he (y : Fin k → Fin n → ℝ) : (∏ j, pairingsDensity v (y j)) = + ENNReal.ofReal (∏ j, ((2 * Real.pi) ^ (-(n : ℝ) / 2) * + Real.exp (-‖pairingLift v (y j)‖^2 / 2) / Real.sqrt (Matrix.gram ℝ v).det)) := by + symm + exact ENNReal.ofReal_prod_of_nonneg (by intro j hj; positivity) + simp_rw [he] + exact ENNReal.continuous_ofReal.comp (by fun_prop) + +lemma constrained_gaussian_approximation_limit {n : ℕ} (v : Fin n → E) (k : ℕ) + {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) [IsProbabilityMeasure μ] + (Z : ℕ → Ω → Fin k → Fin n → ℝ) (hZ : ∀ q, Measurable (Z q)) + (hZ0 : ∀ᵐ z ∂μ, Filter.Tendsto (fun q => Z q z) Filter.atTop (nhds 0)) + {g : (Fin k → E) → ℝ≥0∞} (hg : Continuous g) + (b : ℝ≥0∞) (hb : b ≠ ∞) (hgb : ∀ A, g A ≤ b) : + Filter.Tendsto (fun q => ∫⁻ z, ∫⁻ R, + (∏ j, pairingsDensity v (Z q z j)) * + g (fun j => pairingLift v (Z q z j) + R j) + ∂Measure.pi (fun _ : Fin k => + (stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection) ∂μ) + Filter.atTop (nhds ((∏ _j : Fin k, pairingsDensity v 0) * + ∫⁻ R, g R ∂Measure.pi (fun _ : Fin k => + (stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection))) := by + let ρ := Measure.pi (fun _ : Fin k => + (stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection) + have : IsProbabilityMeasure ((stdGaussian E).map + (Submodule.span ℝ (Set.range v))ᗮ.starProjection) := + (Measure.isProbabilityMeasure_map_iff (by fun_prop)).mpr inferInstance + have hc : (∏ _j : Fin k, pairingsDensity v 0) ≠ ∞ := + ENNReal.prod_ne_top (by intro j hj; exact ENNReal.ofReal_ne_top) + have hlim := tendsto_lintegral_of_dominated_convergence + (μ := μ.prod ρ) (fun _ => (∏ _j : Fin k, pairingsDensity v 0) * b) + (F := fun q z => (∏ j, pairingsDensity v (Z q z.1 j)) * + g (fun j => pairingLift v (Z q z.1 j) + z.2 j)) + (f := fun z => (∏ _j : Fin k, pairingsDensity v 0) * g z.2) + (fun q => by fun_prop) + (fun q => Filter.Eventually.of_forall fun z => mul_le_mul' + (Finset.prod_le_prod (fun j hj => pairingsDensity_le_zero _ _)) (hgb _)) + (by simpa using ENNReal.mul_ne_top hc hb) + (by + have hZ' : ∀ᵐ z ∂μ.prod ρ, + Filter.Tendsto (fun q => Z q z.1) Filter.atTop (nhds 0) := + Measure.quasiMeasurePreserving_fst.ae hZ0 + filter_upwards [hZ'] with z hz + apply ENNReal.Tendsto.mul + ((continuous_rows_pairingsDensity v k).tendsto 0 |>.comp hz) + (Or.inr ((lt_of_le_of_lt (hgb _) (lt_top_iff_ne_top.mpr hb)).ne)) + · apply hg.tendsto z.2 |>.comp + have ht : Filter.Tendsto + (fun q => fun j => pairingLift v (Z q z.1 j) + z.2 j) + Filter.atTop (nhds (fun j => pairingLift v 0 + z.2 j)) := + (show Continuous (fun y : Fin k → Fin n → ℝ => + fun j => pairingLift v (y j) + z.2 j) by fun_prop).tendsto 0 |>.comp hz + simpa [pairingLift] using ht + · exact Or.inr hc) + have heq : (fun q => ∫⁻ z, ∫⁻ R, + (∏ j, pairingsDensity v (Z q z j)) * + g (fun j => pairingLift v (Z q z j) + R j) ∂ρ ∂μ) = + (fun q => ∫⁻ z : Ω × (Fin k → E), + (∏ j, pairingsDensity v (Z q z.1 j)) * + g (fun j => pairingLift v (Z q z.1 j) + z.2 j) ∂μ.prod ρ) := by + funext q + symm + exact lintegral_prod _ (by fun_prop) + change Filter.Tendsto (fun q => ∫⁻ z, ∫⁻ R, + (∏ j, pairingsDensity v (Z q z j)) * + g (fun j => pairingLift v (Z q z j) + R j) ∂ρ ∂μ) _ _ + rw [heq] + convert hlim using 1 + rw [lintegral_prod _ (by fun_prop)] + simp only [lintegral_const_mul _ hg.measurable, lintegral_const, measure_univ, mul_one] + rfl + +end Rows +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/ConstrainedNoise.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/ConstrainedNoise.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f78da5903808cd28a9c50422a6a2a5d10e71b61 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/ConstrainedNoise.lean @@ -0,0 +1,122 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.ConstrainedGaussian +import OAI.Probability.PosteriorReplicas.Gaussian.MatrixNoise + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +section Generic +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def gaussianResidualRows {m : ℕ} (v : Fin m → E) (k : ℕ) : Measure (Fin k → E) := + Measure.pi fun _ => (stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection + +instance {m : ℕ} (v : Fin m → E) (k : ℕ) : IsProbabilityMeasure (gaussianResidualRows v k) := by + let : IsProbabilityMeasure ((stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection) := + (Measure.isProbabilityMeasure_map_iff (by fun_prop)).mpr inferInstance + unfold gaussianResidualRows + infer_instance + +omit [MeasurableSpace E] [BorelSpace E] in +lemma pairings_lift_residual {m : ℕ} {v : Fin m → E} (hv : LinearIndependent ℝ v) + (y : Fin m → ℝ) (R : E) : + (fun i => ⟪v i, pairingLift v y + (Submodule.span ℝ (Set.range v))ᗮ.starProjection R⟫) = y := by + funext i + rw [inner_add_right, congrFun (pairings_pairingLift hv y) i] + have hzero : ⟪v i, (Submodule.span ℝ (Set.range v))ᗮ.starProjection R⟫ = 0 := by + rw [real_inner_comm] + exact Submodule.inner_left_of_mem_orthogonal (Submodule.subset_span (Set.mem_range_self i)) (by simp) + rw [hzero, add_zero] + +lemma constrained_gaussian_weighted_integral {m : ℕ} {v : Fin m → E} + (hv : LinearIndependent ℝ v) (k : ℕ) {φ : (Fin k → Fin m → ℝ) → ℝ≥0∞} + (hφ : Measurable φ) {g : (Fin k → E) → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ A, φ (fun j i => ⟪v i, A j⟫) * g A ∂Measure.pi (fun _ => stdGaussian E) = + ∫⁻ y, (∏ j, pairingsDensity v (y j)) * φ y * + ∫⁻ R, g (fun j => pairingLift v (y j) + R j) ∂gaussianResidualRows v k ∂volume := by + rw [constrained_gaussian_integral hv k (by fun_prop)] + apply lintegral_congr + intro y + have he : (∫⁻ R, φ (fun j i => ⟪v i, pairingLift v (y j) + R j⟫) * + g (fun j => pairingLift v (y j) + R j) ∂gaussianResidualRows v k) = + φ y * ∫⁻ R, g (fun j => pairingLift v (y j) + R j) ∂gaussianResidualRows v k := by + unfold gaussianResidualRows + rw [← Measure.pi_map_pi (fun _ => (show Measurable + (Submodule.span ℝ (Set.range v))ᗮ.starProjection by fun_prop).aemeasurable)] + rw [lintegral_map (by fun_prop) (by fun_prop), lintegral_map (by fun_prop) (by fun_prop)] + dsimp only [Function.comp_apply] + have heq (R : Fin k → E) : + (fun j i => ⟪v i, pairingLift v (y j) + + (Submodule.span ℝ (Set.range v))ᗮ.starProjection (R j)⟫) = y := by + funext j + exact pairings_lift_residual hv (y j) (R j) + simp_rw [heq] + rw [lintegral_const_mul _ (by fun_prop)] + change _ * (∫⁻ R, φ (fun j i => ⟪v i, pairingLift v (y j) + R j⟫) * + g (fun j => pairingLift v (y j) + R j) ∂gaussianResidualRows v k) = _ + rw [he, mul_assoc] + +lemma constrained_gaussian_noise_integral {m : ℕ} {v : Fin m → E} + (hv : LinearIndependent ℝ v) (k n : ℕ) {g : (Fin k → E) → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ A, matrixNoiseDensity m k n (fun i j => ⟪v i, A j⟫) * g A + ∂Measure.pi (fun _ => stdGaussian E) = + ∫⁻ z, ∫⁻ R, (∏ j, pairingsDensity v (fun i => noiseScale n * z i j)) * + g (fun j => pairingLift v (fun i => noiseScale n * z i j) + R j) + ∂gaussianResidualRows v k ∂matrixNormal m k := by + have he (A : Fin k → E) : (fun i j => ⟪v i, A j⟫) = + transposeCLE k m (fun j i => ⟪v i, A j⟫) := rfl + simp_rw [he] + rw [constrained_gaussian_weighted_integral hv k + (φ := fun y => matrixNoiseDensity m k n (transposeCLE k m y)) (by fun_prop) hg] + have hrw (y : Fin k → Fin m → ℝ) : + (∏ j, pairingsDensity v (y j)) * matrixNoiseDensity m k n (transposeCLE k m y) * + (∫⁻ R, g (fun j => pairingLift v (y j) + R j) ∂gaussianResidualRows v k) = + matrixNoiseDensity m k n (transposeCLE k m y) * + ((∏ j, pairingsDensity v (y j)) * + ∫⁻ R, g (fun j => pairingLift v (y j) + R j) ∂gaussianResidualRows v k) := by ac_rfl + simp_rw [hrw] + rw [matrixNoise_transpose_lintegral (by fun_prop)] + apply lintegral_congr + intro z + rw [lintegral_const_mul _ (by fun_prop)] + rfl + +lemma constrained_gaussian_noise_limit {m : ℕ} {v : Fin m → E} + (hv : LinearIndependent ℝ v) (k : ℕ) {g : (Fin k → E) → ℝ≥0∞} (hg : Continuous g) + (b : ℝ≥0∞) (hb : b ≠ ∞) (hgb : ∀ A, g A ≤ b) : + Tendsto (fun n => ∫⁻ A, matrixNoiseDensity m k n (fun i j => ⟪v i, A j⟫) * g A + ∂Measure.pi (fun _ => stdGaussian E)) atTop + (nhds ((∏ _j : Fin k, pairingsDensity v 0) * ∫⁻ R, g R ∂gaussianResidualRows v k)) := by + simp_rw [constrained_gaussian_noise_integral hv k _ hg.measurable] + apply constrained_gaussian_approximation_limit v k (matrixNormal m k) + (fun n z j i => noiseScale n * z i j) (fun _ => by fun_prop) _ hg b hb hgb + apply Filter.Eventually.of_forall + intro z + have h := (transposeCLE m k).continuous.tendsto 0 |>.comp (matrix_noise_shrinks z) + convert h using 1 <;> rfl + +lemma constrained_gaussian_noise_bound {m : ℕ} {v : Fin m → E} + (hv : LinearIndependent ℝ v) (k n : ℕ) {g : (Fin k → E) → ℝ≥0∞} (hg : Measurable g) + (b : ℝ≥0∞) (hgb : ∀ A, g A ≤ b) : + (∫⁻ A, matrixNoiseDensity m k n (fun i j => ⟪v i, A j⟫) * g A + ∂Measure.pi (fun _ => stdGaussian E)) ≤ (∏ _j : Fin k, pairingsDensity v 0) * b := by + rw [constrained_gaussian_noise_integral hv k n hg] + calc + _ ≤ ∫⁻ z, ∫⁻ R, (∏ _j : Fin k, pairingsDensity v 0) * b + ∂gaussianResidualRows v k ∂matrixNormal m k := by + apply lintegral_mono + intro z + apply lintegral_mono + intro R + exact mul_le_mul' (Finset.prod_le_prod (fun j _ => pairingsDensity_le_zero _ _)) (hgb _) + _ = _ := by simp + +end Generic +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianDensity.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..5911b2b8e6609c6bdcc4afccd044d1fe6a2fea75 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianDensity.lean @@ -0,0 +1,162 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianFiber +import OAI.Probability.PosteriorReplicas.Measures.DensityTools + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +namespace PosteriorReplicas + +def matrixLinearEquiv {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) (hd : M.det ≠ 0) : + (Fin n → ℝ) ≃ₗ[ℝ] (Fin n → ℝ) := + { Matrix.toLin' M with + invFun := Matrix.toLin' M⁻¹ + left_inv := by + intro x + change M⁻¹ *ᵥ (M *ᵥ x) = x + rw [Matrix.mulVec_mulVec, Matrix.nonsing_inv_mul _ (isUnit_iff_ne_zero.mpr hd), + Matrix.one_mulVec] + right_inv := by + intro x + change M *ᵥ (M⁻¹ *ᵥ x) = x + rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv _ (isUnit_iff_ne_zero.mpr hd), + Matrix.one_mulVec] } + +lemma gaussian_linear_image_density {n : ℕ} (M : Matrix (Fin n) (Fin n) ℝ) + (hd : M.det ≠ 0) : + (Measure.pi (fun _ : Fin n => gaussianReal 0 1)).map (Matrix.toLin' M) = + (volume : Measure (Fin n → ℝ)).withDensity (fun y => + ENNReal.ofReal |M.det⁻¹| * ∏ i, gaussianPDF 0 1 ((M⁻¹ *ᵥ y) i)) := by + let e := (matrixLinearEquiv M hd).toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv + have he : (e : (Fin n → ℝ) → (Fin n → ℝ)) = Matrix.toLin' M := rfl + have hi : (e.symm : (Fin n → ℝ) → (Fin n → ℝ)) = Matrix.toLin' M⁻¹ := rfl + rw [pi_gaussian_density, ← he, map_withDensity_equiv _ e (by fun_prop), he, + Real.map_matrix_volume_pi_eq_smul_volume_pi hd, withDensity_smul_measure, + ← withDensity_smul _ (by fun_prop)] + rfl + +lemma gaussian_density_product {n : ℕ} (z : Fin n → ℝ) : + (∏ i, gaussianPDF 0 1 (z i)) = ENNReal.ofReal + ((2 * Real.pi) ^ (-(n : ℝ) / 2) * Real.exp (-(∑ i, (z i)^2) / 2)) := by + have hconst : (Real.sqrt (2 * Real.pi))⁻¹ ^ n = + (2 * Real.pi) ^ (-(n : ℝ) / 2) := by + rw [inv_pow, Real.sqrt_eq_rpow, ← Real.rpow_natCast, + ← Real.rpow_mul (by positivity), ← Real.rpow_neg (by positivity)] + congr 1 + ring + simp only [gaussianPDF_def] + rw [← ENNReal.ofReal_prod_of_nonneg (fun i _ => gaussianPDFReal_nonneg 0 1 (z i))] + congr 1 + simp only [gaussianPDFReal, NNReal.coe_one, mul_one, sub_zero, + Finset.prod_mul_distrib, Finset.prod_const, Finset.card_univ, Fintype.card_fin] + rw [hconst, ← Real.exp_sum] + congr 2 + rw [← Finset.sum_div, Finset.sum_neg_distrib] + +section PairingsDensity +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +def pairingTriangular {n : ℕ} (v : Fin n → E) : Matrix (Fin n) (Fin n) ℝ := + Matrix.diagonal (fun i => ‖gramSchmidt ℝ v i‖) * PosteriorRegression.gsUpper n v + +lemma pairingTriangular_expansion [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) + (j : Fin n) : ∑ i, pairingTriangular v i j • gramSchmidtNormed ℝ v i = v j := by + have hn (i : Fin n) : ‖gramSchmidt ℝ v i‖ ≠ 0 := + norm_ne_zero_iff.mpr (gramSchmidt_ne_zero i hv) + rw [← PosteriorRegression.gsUpper_expansion n v j] + apply Finset.sum_congr rfl + intro i _ + simp only [pairingTriangular, Matrix.diagonal_mul, gramSchmidtNormed, smul_smul] + congr 1 + simp [hn i, mul_comm] + +lemma pairingTriangular_det [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {n : ℕ} (v : Fin n → E) : + (pairingTriangular v).transpose.det = Real.sqrt (Matrix.gram ℝ v).det := by + rw [pairingTriangular, Matrix.det_transpose, Matrix.det_mul, Matrix.det_diagonal, + PosteriorRegression.gsUpper_det, mul_one, PosteriorRegression.sqrt_det_gram] + +variable [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma pairingTriangular_det_pos {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) : + 0 < (pairingTriangular v).transpose.det := by + rw [pairingTriangular_det] + exact Real.sqrt_pos.mpr (Matrix.posDef_gram_of_linearIndependent hv).det_pos + +lemma pairings_eq_triangular {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) : + (fun x : E => fun j => ⟪v j, x⟫) = + (Matrix.toLin' (pairingTriangular v).transpose) ∘ + (fun x => fun i => ⟪gramSchmidtNormed ℝ v i, x⟫) := by + funext x j + rw [← pairingTriangular_expansion hv j] + simp [Matrix.toLin'_apply, Matrix.mulVec, dotProduct, sum_inner, inner_smul_left] + +lemma gaussian_pairings_density_coordinates {n : ℕ} {v : Fin n → E} + (hv : LinearIndependent ℝ v) : + (stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) = + (volume : Measure (Fin n → ℝ)).withDensity (fun y => + ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ v).det)⁻¹) * + ∏ i, gaussianPDF 0 1 (((pairingTriangular v).transpose⁻¹ *ᵥ y) i)) := by + rw [pairings_eq_triangular hv, ← Measure.map_map (by fun_prop) (by fun_prop), + PosteriorRegression.orthonormal_gaussian_map (gramSchmidtNormed_orthonormal hv), + gaussian_linear_image_density _ (ne_of_gt (pairingTriangular_det_pos hv)), + abs_of_pos (inv_pos.mpr (pairingTriangular_det_pos hv)), pairingTriangular_det] + +lemma orthonormal_pairings_eq_inverse {n : ℕ} {v : Fin n → E} + (hv : LinearIndependent ℝ v) (x : E) : + (fun i => ⟪gramSchmidtNormed ℝ v i, x⟫) = + (pairingTriangular v).transpose⁻¹ *ᵥ (fun i => ⟪v i, x⟫) := by + have he := congrFun (pairings_eq_triangular hv) x + change (fun i => ⟪v i, x⟫) = + (pairingTriangular v).transpose *ᵥ (fun i => ⟪gramSchmidtNormed ℝ v i, x⟫) at he + rw [he, Matrix.mulVec_mulVec, + Matrix.nonsing_inv_mul _ (isUnit_iff_ne_zero.mpr (ne_of_gt (pairingTriangular_det_pos hv))), + Matrix.one_mulVec] + +lemma pairingLift_energy {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) + (y : Fin n → ℝ) : + ‖pairingLift v y‖^2 = ∑ i, (((pairingTriangular v).transpose⁻¹ *ᵥ y) i)^2 := by + have hu := gramSchmidtNormed_orthonormal hv + have hs : Submodule.span ℝ (Set.range (gramSchmidtNormed ℝ v)) = + Submodule.span ℝ (Set.range v) := + (span_gramSchmidtNormed_range v).trans (span_gramSchmidt ℝ v) + have hexp := orthonormal_starProjection hu (pairingLift v y) + rw [hs, (Submodule.span ℝ (Set.range v)).starProjection_eq_self_iff.mpr + (pairingLift_mem v y)] at hexp + have hc := orthonormal_pairings_eq_inverse hv (pairingLift v y) + rw [pairings_pairingLift hv y] at hc + simp_rw [congrFun hc] at hexp + rw [hexp, ← real_inner_self_eq_norm_sq, hu.inner_sum] + simp [pow_two] + +lemma gaussian_pairings_density {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) : + (stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) = + (volume : Measure (Fin n → ℝ)).withDensity (fun y => ENNReal.ofReal + ((2 * Real.pi) ^ (-(n : ℝ) / 2) * Real.exp (-‖pairingLift v y‖^2 / 2) / + Real.sqrt (Matrix.gram ℝ v).det)) := by + rw [gaussian_pairings_density_coordinates hv] + congr 1 + funext y + rw [gaussian_density_product, ← pairingLift_energy hv, + ← ENNReal.ofReal_mul (by positivity)] + congr 1 + ring + +lemma gaussian_fiber_integral {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) + {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ x, g x ∂stdGaussian E = ∫⁻ y, ENNReal.ofReal + ((2 * Real.pi) ^ (-(n : ℝ) / 2) * Real.exp (-‖pairingLift v y‖^2 / 2) / + Real.sqrt (Matrix.gram ℝ v).det) * + ∫⁻ r, g (pairingLift v y + r) + ∂((stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection) := by + rw [gaussian_pairings_integral hv hg, gaussian_pairings_density hv, + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] + rfl + +end PairingsDensity +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianFiber.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianFiber.lean new file mode 100644 index 0000000000000000000000000000000000000000..b813f247380d585c176de5f2ddc79bb4528d7c69 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianFiber.lean @@ -0,0 +1,214 @@ +import OAI.Probability.PosteriorReplicas.Regression.Conclusions + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace + +noncomputable section + +namespace PosteriorReplicas + +section GaussianSplitting +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma charFun_gaussian_starProjection (U : Submodule ℝ E) (t : E) : + charFun ((stdGaussian E).map U.starProjection) t = + Complex.exp (- ‖U.starProjection t‖ ^ 2 / 2) := by + rw [charFun_apply, integral_map U.starProjection.continuous.measurable.aemeasurable + (by fun_prop)] + simp_rw [U.inner_starProjection_left_eq_right] + change charFun (stdGaussian E) (U.starProjection t) = _ + exact charFun_stdGaussian _ + +lemma gaussian_orthogonal_sum (U : Submodule ℝ E) : + (((stdGaussian E).map U.starProjection).prod + ((stdGaussian E).map Uᗮ.starProjection)).map (fun z => z.1 + z.2) = + stdGaussian E := by + let : IsProbabilityMeasure ((stdGaussian E).map U.starProjection) := + (Measure.isProbabilityMeasure_map_iff + U.starProjection.continuous.measurable.aemeasurable).mpr inferInstance + let : IsProbabilityMeasure ((stdGaussian E).map Uᗮ.starProjection) := + (Measure.isProbabilityMeasure_map_iff + Uᗮ.starProjection.continuous.measurable.aemeasurable).mpr inferInstance + apply Measure.ext_of_charFun + ext t + rw [charFun_map_add_prod_eq_mul, Pi.mul_apply, + charFun_gaussian_starProjection, charFun_gaussian_starProjection, + charFun_stdGaussian, ← Complex.exp_add] + congr 1 + have h := Submodule.norm_sq_eq_add_norm_sq_starProjection t U + have hc : (‖t‖ : ℂ)^2 = (‖U.starProjection t‖ : ℂ)^2 + + (‖Uᗮ.starProjection t‖ : ℂ)^2 := by exact_mod_cast h + rw [hc] + ring + +lemma gaussian_orthogonal_pair (U : Submodule ℝ E) : + (stdGaussian E).map (fun x => (U.starProjection x, Uᗮ.starProjection x)) = + ((stdGaussian E).map U.starProjection).prod + ((stdGaussian E).map Uᗮ.starProjection) := by + have hP : Measurable (fun x : E => (U.starProjection x, Uᗮ.starProjection x)) := + U.starProjection.continuous.measurable.prodMk Uᗮ.starProjection.continuous.measurable + conv_lhs => rw [← gaussian_orthogonal_sum U] + rw [Measure.map_map hP (by fun_prop)] + rw [Measure.map_prod_map _ _ U.starProjection.continuous.measurable + Uᗮ.starProjection.continuous.measurable] + rw [Measure.map_map (hP.comp (by fun_prop)) + (U.starProjection.continuous.measurable.prodMap + Uᗮ.starProjection.continuous.measurable)] + congr 1 + funext z + dsimp [Function.comp_def] + simp only [map_add] + have h₁ : U.starProjection (U.starProjection z.1) = U.starProjection z.1 := + U.starProjection_eq_self_iff.mpr (by simp) + have h₂ : Uᗮ.starProjection (Uᗮ.starProjection z.2) = Uᗮ.starProjection z.2 := + Uᗮ.starProjection_eq_self_iff.mpr (by simp) + have h₃ : Uᗮ.starProjection (U.starProjection z.1) = 0 := + U.starProjection_orthogonal_apply_eq_zero (by simp) + have h₄ : U.starProjection (Uᗮ.starProjection z.2) = 0 := by + rw [← U.orthogonal_orthogonal] + exact Uᗮ.starProjection_orthogonal_apply_eq_zero (by simp) + rw [h₁, h₂, h₃, h₄, add_zero, zero_add] + rfl + +lemma gaussian_orthogonal_indep (U : Submodule ℝ E) : + IndepFun U.starProjection Uᗮ.starProjection (stdGaussian E) := by + exact (indepFun_iff_map_prod_eq_prod_map_map + U.starProjection.continuous.measurable.aemeasurable + Uᗮ.starProjection.continuous.measurable.aemeasurable).mpr (gaussian_orthogonal_pair U) + +omit [MeasurableSpace E] [BorelSpace E] in +lemma pairing_starProjection (U : Submodule ℝ E) {v : E} (hv : v ∈ U) (x : E) : + ⟪v, U.starProjection x⟫ = ⟪v, x⟫ := by + rw [← U.inner_starProjection_left_eq_right, U.starProjection_eq_self_iff.mpr hv] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma orthonormal_starProjection {n : ℕ} {u : Fin n → E} (hu : Orthonormal ℝ u) (x : E) : + (Submodule.span ℝ (Set.range u)).starProjection x = ∑ i, ⟪u i, x⟫ • u i := by + let U := Submodule.span ℝ (Set.range u) + have hmem (i : Fin n) : u i ∈ U := Submodule.subset_span (Set.mem_range_self i) + apply U.eq_starProjection_of_mem_of_inner_eq_zero + · exact U.sum_mem (fun i _ => U.smul_mem _ (hmem i)) + · intro v hv + induction hv using Submodule.span_induction with + | mem v hv => + rcases hv with ⟨i, rfl⟩ + rw [inner_sub_left, hu.inner_left_fintype] + simp [real_inner_comm x] + | zero => simp + | add v w hv hw ihv ihw => simp [inner_add_right, ihv, ihw] + | smul a v hv ih => simp [inner_smul_right, ih] + +lemma gaussian_pairings_residual_indep {n : ℕ} (v : Fin n → E) : + IndepFun (fun x : E => fun i => ⟪v i, x⟫) + (Submodule.span ℝ (Set.range v))ᗮ.starProjection (stdGaussian E) := by + let U := Submodule.span ℝ (Set.range v) + have h := (gaussian_orthogonal_indep U).comp + (show Measurable (fun x : E => fun i => ⟪v i, x⟫) by fun_prop) measurable_id + have heq : (fun x : E => fun i => ⟪v i, x⟫) ∘ U.starProjection = + (fun x : E => fun i => ⟪v i, x⟫) := by + funext x i + apply pairing_starProjection U (Submodule.subset_span (Set.mem_range_self i)) + simpa only [heq, Function.id_comp] using h + +lemma gaussian_orthonormal_pair {n : ℕ} {u : Fin n → E} (hu : Orthonormal ℝ u) : + (stdGaussian E).map (fun x => ((fun i => ⟪u i, x⟫), + (Submodule.span ℝ (Set.range u))ᗮ.starProjection x)) = + (Measure.pi (fun _ : Fin n => gaussianReal 0 1)).prod + ((stdGaussian E).map (Submodule.span ℝ (Set.range u))ᗮ.starProjection) := by + rw [(gaussian_pairings_residual_indep u).map_prod_eq_prod_map_map + (by fun_prop) (by fun_prop), PosteriorRegression.orthonormal_gaussian_map hu] + +lemma gaussian_orthonormal_disintegration {n : ℕ} {u : Fin n → E} + (hu : Orthonormal ℝ u) : + ((Measure.pi (fun _ : Fin n => gaussianReal 0 1)).prod + ((stdGaussian E).map (Submodule.span ℝ (Set.range u))ᗮ.starProjection)).map + (fun z => (∑ i, z.1 i • u i) + z.2) = stdGaussian E := by + rw [← gaussian_orthonormal_pair hu, Measure.map_map (by fun_prop) (by fun_prop)] + convert (Measure.map_id (μ := stdGaussian E)) using 1 + congr 1 + funext x + simp only [Function.comp_apply] + rw [← orthonormal_starProjection hu x, + Submodule.starProjection_add_starProjection_orthogonal] + rfl + +def pairingLift {n : ℕ} (v : Fin n → E) (y : Fin n → ℝ) : E := + ∑ i, ((Matrix.gram ℝ v)⁻¹ *ᵥ y) i • v i + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma pairingLift_mem {n : ℕ} (v : Fin n → E) (y : Fin n → ℝ) : + pairingLift v y ∈ Submodule.span ℝ (Set.range v) := by + unfold pairingLift + apply Submodule.sum_mem + intro i _ + exact Submodule.smul_mem _ _ (Submodule.subset_span (Set.mem_range_self i)) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma pairings_pairingLift {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) + (y : Fin n → ℝ) : (fun j => ⟪v j, pairingLift v y⟫) = y := by + have hd : IsUnit (Matrix.gram ℝ v).det := + isUnit_iff_ne_zero.mpr (Matrix.det_gram_ne_zero_iff_linearIndependent.mpr hv) + calc + _ = (Matrix.gram ℝ v) *ᵥ ((Matrix.gram ℝ v)⁻¹ *ᵥ y) := by + ext j + simp [pairingLift, inner_sum, inner_smul_right, Matrix.mulVec, dotProduct, mul_comm] + _ = y := by rw [Matrix.mulVec_mulVec, Matrix.mul_nonsing_inv _ hd, Matrix.one_mulVec] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma starProjection_eq_pairingLift {n : ℕ} {v : Fin n → E} + (hv : LinearIndependent ℝ v) (x : E) : + (Submodule.span ℝ (Set.range v)).starProjection x = + pairingLift v (fun i => ⟪v i, x⟫) := by + apply Submodule.eq_starProjection_of_mem_of_inner_eq_zero (pairingLift_mem _ _) + intro w hw + induction hw using Submodule.span_induction with + | mem w hw => + rcases hw with ⟨i, rfl⟩ + rw [inner_sub_left, real_inner_comm (v i) x, real_inner_comm (v i) (pairingLift _ _)] + have h := congrFun (pairings_pairingLift hv (fun i => ⟪v i, x⟫)) i + rw [h, sub_self] + | zero => simp + | add v w hv hw ihv ihw => simp [inner_add_right, ihv, ihw] + | smul a v hv ih => simp [inner_smul_right, ih] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[fun_prop] lemma continuous_pairingLift {n : ℕ} (v : Fin n → E) : Continuous (pairingLift v) := by + unfold pairingLift + fun_prop + +lemma gaussian_pairings_disintegration {n : ℕ} {v : Fin n → E} + (hv : LinearIndependent ℝ v) : + (((stdGaussian E).map (fun x => fun i => ⟪v i, x⟫)).prod + ((stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection)).map + (fun z => pairingLift v z.1 + z.2) = stdGaussian E := by + rw [← (gaussian_pairings_residual_indep v).map_prod_eq_prod_map_map + (by fun_prop) (by fun_prop), Measure.map_map + (by fun_prop) + (by fun_prop)] + convert (Measure.map_id (μ := stdGaussian E)) using 1 + congr 1 + funext x + simp only [Function.comp_apply] + rw [← starProjection_eq_pairingLift hv x, + Submodule.starProjection_add_starProjection_orthogonal] + rfl + +lemma gaussian_pairings_integral {n : ℕ} {v : Fin n → E} + (hv : LinearIndependent ℝ v) {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ x, g x ∂stdGaussian E = + ∫⁻ y, ∫⁻ r, g (pairingLift v y + r) + ∂((stdGaussian E).map (Submodule.span ℝ (Set.range v))ᗮ.starProjection) + ∂((stdGaussian E).map (fun x => fun i => ⟪v i, x⟫)) := by + conv_lhs => rw [← gaussian_pairings_disintegration hv] + rw [lintegral_map hg + (by fun_prop), + lintegral_prod _ (by fun_prop)] + +end GaussianSplitting +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianGramMoment.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianGramMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6f2eec5b67d6fab68f03de993d329e70412a8d2 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianGramMoment.lean @@ -0,0 +1,90 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianSmallBall +import OAI.Probability.PosteriorReplicas.Geometry.AffineMoments + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric EuclideanGeometry Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma infDist_affine_projection [MeasurableSpace E] [BorelSpace E] + (L : AffineSubspace ℝ E) {p : E} (hp : p ∈ L) (x : E) : + Metric.infDist x L = ‖L.directionᗮ.orthogonalProjectionOnto x - + L.directionᗮ.orthogonalProjectionOnto p‖ := by + conv_lhs => rw [← AffineSubspace.mk'_eq hp] + rw [PosteriorRegression.infDist_affine_mk', Metric.infDist_eq_iInf] + simp only [dist_eq_norm] + change (⨅ y : L.direction, ‖x-p-(y : E)‖) = _ + rw [← L.direction.starProjection_minimal (x-p)] + rw [← map_sub] + change ‖x-p-L.direction.starProjection (x-p)‖ = ‖L.directionᗮ.starProjection (x-p)‖ + rw [Submodule.starProjection_orthogonal_val] + +lemma gaussian_affine_inverse_moment (L : AffineSubspace ℝ E) [Nonempty L] + (k : ℕ) (hk : Module.finrank ℝ L.direction + k + 1 ≤ Module.finrank ℝ E) + {R : ℝ} (hR : 0 < R) : + (∫⁻ x : E, ENNReal.ofReal ((Metric.infDist x L)⁻¹^k) ∂stdGaussian E) ≤ + ENNReal.ofReal (R⁻¹^k) * (1 + ENNReal.ofReal (Real.exp (R^2/2)) * 2^(k+1)) := by + obtain ⟨⟨p,hp⟩⟩ := ‹Nonempty L› + have hdim : k+1 ≤ Module.finrank ℝ L.directionᗮ := by + have := L.direction.finrank_add_finrank_orthogonal + omega + have h := gaussian_inverse_norm_moment (L.directionᗮ.orthogonalProjectionOnto p) k hdim hR + rw [← gaussian_orthogonalProjectionOnto L.directionᗮ, + lintegral_map (by fun_prop) (by fun_prop)] at h + simpa only [infDist_affine_projection L hp] using h + +def gaussianMomentConstant (k : ℕ) : ℝ≥0∞ := + ENNReal.ofReal ((Real.sqrt k)⁻¹^k) * + (1 + ENNReal.ofReal (Real.exp ((k : ℝ)/2)) * 2^(k+1)) + +lemma gaussianMomentConstant_ne_top (k : ℕ) : gaussianMomentConstant k ≠ ∞ := by + unfold gaussianMomentConstant + finiteness + +lemma gaussianMomentConstant_pos {k : ℕ} (hk : 1 ≤ k) : 0 < gaussianMomentConstant k := by + unfold gaussianMomentConstant + have h : 0 < (k : ℝ) := by exact_mod_cast (by omega : 0 < k) + positivity + +lemma gaussian_gram_inverse_moment (k m : ℕ) (hk : 1 ≤ k) + (hd : k+m ≤ Module.finrank ℝ E) (p : E) : + (∫⁻ v : Fin m → E, + ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ (fun j => v j-p)).det)⁻¹ ^ k) + ∂Measure.pi (fun _ => stdGaussian E)) ≤ (gaussianMomentConstant k)^m := by + have h := replica_integral_of_affine_moment (ν := stdGaussian E) k m p (gaussianMomentConstant k) ?_ + · simpa only [PosteriorRegression.replicaWeight_eq_det] using h + intro L hL hdim + have hkp : 0 < (k : ℝ) := by exact_mod_cast (by omega : 0 < k) + have hb := gaussian_affine_inverse_moment L k (by omega : + Module.finrank ℝ L.direction + k + 1 ≤ Module.finrank ℝ E) (Real.sqrt_pos.mpr hkp) + simpa only [gaussianMomentConstant, Real.sq_sqrt hkp.le] using hb + +lemma gaussian_gram_inverse_moment_centered (k m : ℕ) (hk : 1 ≤ k) + (hd : k+m ≤ Module.finrank ℝ E) : + (∫⁻ v : Fin m → E, + ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ v).det)⁻¹ ^ k) + ∂Measure.pi (fun _ => stdGaussian E)) ≤ (gaussianMomentConstant k)^m := by + simpa only [sub_zero] using gaussian_gram_inverse_moment k m hk hd (0 : E) + +lemma ae_gaussian_columns_independent (m : ℕ) (hm : m ≤ Module.finrank ℝ E) : + ∀ᵐ v : Fin m → E ∂Measure.pi (fun _ => stdGaussian E), LinearIndependent ℝ v := by + have h := ae_replica_independent_of_affine_null (ν := stdGaussian E) (0 : E) m ?_ + · simpa only [sub_zero] using h + intro L hL hdim + apply stdGaussian_absolutelyContinuous_volume + apply Measure.addHaar_affineSubspace _ L + intro htop + have hr : L.direction = ⊤ := by rw [htop, AffineSubspace.direction_top] + rw [hr, finrank_top] at hdim + omega + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianLogMoment.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianLogMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..9c0a8bc324eec1191fd2dec5cc3e25eaa6627990 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianLogMoment.lean @@ -0,0 +1,180 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianGramMoment + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +namespace PosteriorReplicas + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma log_le_square_tangent {x a : ℝ} (hx : 0 < x) (ha : 0 < a) : + Real.log x ≤ Real.log a / 2 + x^2/(2*a) - 1/2 := by + have h := Real.log_le_sub_one_of_pos (div_pos (sq_pos_of_pos hx) ha) + rw [Real.log_div (ne_of_gt (sq_pos_of_pos hx)) ha.ne', Real.log_pow] at h + norm_num at h + nlinarith [show x^2/a = 2*(x^2/(2*a)) by field_simp] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma norm_gramSchmidt_le_norm [MeasurableSpace E] [BorelSpace E] + {m : ℕ} (v : Fin m → E) (i : Fin m) : + ‖gramSchmidt ℝ v i‖ ≤ ‖v i‖ := by + rw [PosteriorRegression.gramSchmidt_eq_sub_starProjection, + ← Submodule.starProjection_orthogonal_val] + exact Submodule.norm_starProjection_apply_le _ _ + +def gramVolume {m : ℕ} (v : Fin m → E) : ℝ := Real.sqrt (Matrix.gram ℝ v).det + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma gramVolume_eq_prod [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {m : ℕ} (v : Fin m → E) : + gramVolume v = ∏ i, ‖gramSchmidt ℝ v i‖ := PosteriorRegression.sqrt_det_gram m v + +@[fun_prop] lemma measurable_gramVolume {m : ℕ} : Measurable (gramVolume : (Fin m → E) → ℝ) := by + change Measurable (fun v : Fin m → E => gramVolume v) + simp_rw [gramVolume_eq_prod] + exact Finset.measurable_prod _ (fun i _ => (PosteriorRegression.measurable_gramSchmidt i).norm) + +lemma gramVolume_pos {m : ℕ} {v : Fin m → E} (hv : LinearIndependent ℝ v) : + 0 < gramVolume v := by + rw [gramVolume_eq_prod] + exact Finset.prod_pos fun i _ => norm_pos_iff.mpr (gramSchmidt_ne_zero i hv) + +lemma log_gramVolume_eq_sum {m : ℕ} {v : Fin m → E} (hv : LinearIndependent ℝ v) : + Real.log (gramVolume v) = ∑ i, Real.log ‖gramSchmidt ℝ v i‖ := by + rw [gramVolume_eq_prod, Real.log_prod (fun i _ => norm_ne_zero_iff.mpr (gramSchmidt_ne_zero i hv))] + +lemma log_gramVolume_le_tangent {m : ℕ} {v : Fin m → E} (hv : LinearIndependent ℝ v) + {a : ℝ} (ha : 0 < a) : + Real.log (gramVolume v) ≤ ∑ i, (Real.log a/2 + ‖v i‖^2/(2*a) - 1/2) := by + rw [log_gramVolume_eq_sum hv] + apply Finset.sum_le_sum + intro i _ + apply (log_le_square_tangent (norm_pos_iff.mpr (gramSchmidt_ne_zero i hv)) ha).trans + have h := norm_gramSchmidt_le_norm v i + have hsq : ‖gramSchmidt ℝ v i‖^2 ≤ ‖v i‖^2 := sq_le_sq₀ (norm_nonneg _) (norm_nonneg _) |>.mpr h + exact sub_le_sub_right (add_le_add le_rfl (div_le_div_of_nonneg_right hsq (by positivity))) _ + +lemma abs_log_gramVolume_le {m : ℕ} {v : Fin m → E} (hv : LinearIndependent ℝ v) : + |Real.log (gramVolume v)| ≤ (gramVolume v)⁻¹ + ∑ i, (‖v i‖^2+1) := by + have hp := gramVolume_pos hv + have hneg := Real.log_le_self (inv_pos.mpr hp).le + rw [Real.log_inv] at hneg + have hu := log_gramVolume_le_tangent hv (a := 1) (by norm_num) + have hs : (∑ i, (Real.log (1:ℝ)/2+‖v i‖^2/(2*1)-1/2)) ≤ ∑ i, (‖v i‖^2+1) := by + apply Finset.sum_le_sum + intro i _ + simp only [Real.log_one, zero_div, zero_add, mul_one] + nlinarith [sq_nonneg ‖v i‖] + have hn : 0 ≤ ∑ i, (‖v i‖^2+1) := Finset.sum_nonneg (fun i _ => by positivity) + exact abs_le.mpr ⟨by linarith, by linarith [inv_nonneg.mpr hp.le]⟩ + +lemma gaussian_integrable_norm_sq : Integrable (fun x : E => ‖x‖^2) (stdGaussian E) := + (IsGaussian.memLp_two_id (μ := stdGaussian E)).norm.integrable_sq + +lemma gaussian_integral_norm_sq : (∫ x : E, ‖x‖^2 ∂stdGaussian E) = Module.finrank ℝ E := by + let b := stdOrthonormalBasis ℝ E + have hL (i : Fin (Module.finrank ℝ E)) : + (∫ x : E, ⟪b i,x⟫^2 ∂stdGaussian E) = 1 := by + have h := variance_eq_integral (μ := stdGaussian E) + (X := fun x : E => ⟪b i,x⟫) (by fun_prop) + have hmean : (∫ x : E, ⟪b i,x⟫ ∂stdGaussian E) = 0 := + integral_strongDual_stdGaussian (innerSL ℝ (b i)) + rw [hmean] at h + simp only [sub_zero] at h + rw [← h] + change Var[⇑(innerSL ℝ (b i)); stdGaussian E] = 1 + rw [variance_dual_stdGaussian] + simp [b.norm_eq_one] + have hi (i : Fin (Module.finrank ℝ E)) : + Integrable (fun x : E => ⟪b i,x⟫^2) (stdGaussian E) := by + apply gaussian_integrable_norm_sq.mono' (by fun_prop) + apply ae_of_all + intro x + have h := abs_real_inner_le_norm (b i) x + rw [b.norm_eq_one, one_mul] at h + rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] + simpa only [sq_abs] using (sq_le_sq₀ (abs_nonneg ⟪b i,x⟫) (norm_nonneg x)).mpr h + simp_rw [← b.sum_sq_inner_right] + rw [integral_finsetSum _ (fun i _ => hi i)] + simp only [hL, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one] + +lemma gaussianPi_integrable_norm_sq {m : ℕ} (i : Fin m) : + Integrable (fun v : Fin m → E => ‖v i‖^2) (Measure.pi fun _ => stdGaussian E) := by + exact (measurePreserving_eval (fun _ : Fin m => stdGaussian E) i).integrable_comp + gaussian_integrable_norm_sq.aestronglyMeasurable |>.mpr gaussian_integrable_norm_sq + +lemma gaussianPi_integral_norm_sq {m : ℕ} (i : Fin m) : + (∫ v : Fin m → E, ‖v i‖^2 ∂Measure.pi (fun _ => stdGaussian E)) = Module.finrank ℝ E := by + have h := (measurePreserving_eval (fun _ : Fin m => stdGaussian E) i).map_eq + have he := integral_map (μ := Measure.pi (fun _ : Fin m => stdGaussian E)) + (φ := Function.eval i) (f := fun x : E => ‖x‖^2) + (measurable_pi_apply i).aemeasurable (by fun_prop) + rw [h, gaussian_integral_norm_sq] at he + exact he.symm + +lemma gaussian_integrable_inv_gramVolume {m : ℕ} (hm : m+1 ≤ Module.finrank ℝ E) : + Integrable (fun v : Fin m → E => (gramVolume v)⁻¹) + (Measure.pi fun _ => stdGaussian E) := by + refine ⟨(measurable_gramVolume.inv).aestronglyMeasurable, ?_⟩ + have hn : 0 ≤ᵐ[Measure.pi (fun _ : Fin m => stdGaussian E)] + (fun v => (gramVolume v)⁻¹) := ae_of_all _ (fun v => + inv_nonneg.mpr (Real.sqrt_nonneg _)) + apply (hasFiniteIntegral_iff_ofReal hn).mpr + have h := gaussian_gram_inverse_moment_centered (E := E) 1 m (by omega) (by omega) + simp only [pow_one] at h + exact h.trans_lt (lt_top_iff_ne_top.mpr (ENNReal.pow_ne_top (gaussianMomentConstant_ne_top 1))) + +lemma gaussian_integrable_log_gramVolume {m : ℕ} (hm : m+1 ≤ Module.finrank ℝ E) : + Integrable (fun v : Fin m → E => Real.log (gramVolume v)) + (Measure.pi fun _ => stdGaussian E) := by + have hb : Integrable (fun v : Fin m → E => (gramVolume v)⁻¹ + ∑ i, (‖v i‖^2+1)) + (Measure.pi fun _ => stdGaussian E) := + (gaussian_integrable_inv_gramVolume hm).add + (integrable_finsetSum _ (fun i _ => (gaussianPi_integrable_norm_sq i).add (integrable_const 1))) + refine hb.mono' (measurable_gramVolume.log.aestronglyMeasurable) ?_ + filter_upwards [ae_gaussian_columns_independent (E := E) m (by omega)] with v hv + exact abs_log_gramVolume_le hv + +lemma gaussian_integral_log_gramVolume_le {m : ℕ} (hm : m+1 ≤ Module.finrank ℝ E) : + (∫ v : Fin m → E, Real.log (gramVolume v) ∂Measure.pi (fun _ => stdGaussian E)) ≤ + (m : ℝ)/2 * Real.log ((Module.finrank ℝ E : ℝ)+1) := by + let a : ℝ := (Module.finrank ℝ E : ℝ)+1 + have ha : 0 < a := by dsimp [a]; positivity + have hi (i : Fin m) : Integrable (fun v : Fin m → E => Real.log a/2 + ‖v i‖^2/(2*a)-1/2) + (Measure.pi fun _ => stdGaussian E) := + ((integrable_const _).add ((gaussianPi_integrable_norm_sq i).div_const _)).sub (integrable_const _) + calc + _ ≤ ∫ v : Fin m → E, ∑ i, (Real.log a/2+‖v i‖^2/(2*a)-1/2) + ∂Measure.pi (fun _ => stdGaussian E) := by + apply integral_mono_ae (gaussian_integrable_log_gramVolume hm) (integrable_finsetSum _ (fun i _ => hi i)) + filter_upwards [ae_gaussian_columns_independent (E := E) m (by omega)] with v hv + exact log_gramVolume_le_tangent hv ha + _ = ∑ _i : Fin m, (Real.log a/2 + (Module.finrank ℝ E : ℝ)/(2*a)-1/2) := by + rw [integral_finsetSum _ (fun i _ => hi i)] + apply Finset.sum_congr rfl + intro i _ + have hid : Integrable (fun v : Fin m → E => ‖v i‖^2/(2*a)) + (Measure.pi fun _ => stdGaussian E) := (gaussianPi_integrable_norm_sq i).div_const _ + have hic : Integrable (fun _ : Fin m → E => Real.log a/2) + (Measure.pi fun _ => stdGaussian E) := integrable_const _ + have hia : Integrable (fun v : Fin m → E => Real.log a/2 + ‖v i‖^2/(2*a)) + (Measure.pi fun _ => stdGaussian E) := hic.add hid + rw [integral_sub hia (integrable_const (1/2 : ℝ)), + integral_add hic hid] + simp only [integral_div, gaussianPi_integral_norm_sq, integral_const, probReal_univ, one_smul] + _ ≤ _ := by + simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + have hdiv : (Module.finrank ℝ E : ℝ)/(2*a) ≤ 1/2 := by + apply (div_le_iff₀ (by positivity : 0 < 2*a)).mpr + dsimp [a] + linarith + dsimp [a] + nlinarith [Nat.cast_nonneg (α := ℝ) m] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianPolar.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianPolar.lean new file mode 100644 index 0000000000000000000000000000000000000000..b8dd9d82af198208f1eaf82383485d27762463a1 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianPolar.lean @@ -0,0 +1,162 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.ConstrainedGaussian + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def gaussianRadialDensity (d : ℕ) (r : ℝ) : ℝ≥0∞ := + ENNReal.ofReal ((2 * Real.pi) ^ (-(d : ℝ) / 2) * Real.exp (-r^2 / 2)) + +@[fun_prop] lemma continuous_gaussianRadialDensity (d : ℕ) : + Continuous (gaussianRadialDensity d) := + ENNReal.continuous_ofReal.comp (by fun_prop) + +lemma stdGaussian_density : stdGaussian E = volume.withDensity + (fun x : E => gaussianRadialDensity (Module.finrank ℝ E) ‖x‖) := by + let b := stdOrthonormalBasis ℝ E + have hp : MeasurePreserving (fun x : Fin (Module.finrank ℝ E) → ℝ => ∑ i, x i • b i) + volume volume := by + have heq : (fun x : Fin (Module.finrank ℝ E) → ℝ => ∑ i, x i • b i) = + b.repr.symm ∘ WithLp.toLp 2 := by + funext x + exact b.sum_repr_symm (WithLp.toLp 2 x) + rw [heq] + exact b.measurePreserving_repr_symm.comp (PiLp.volume_preserving_toLp _) + apply Measure.ext_of_lintegral + intro g hg + rw [stdGaussian_eq_map_pi_orthonormalBasis b, + lintegral_map hg (by fun_prop), pi_gaussian_density, + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop), + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) hg, + ← hp.lintegral_comp (by fun_prop)] + apply lintegral_congr + intro x + simp only [Pi.mul_apply] + have hnorm : ‖∑ i, x i • b i‖^2 = ∑ i, (x i)^2 := by + rw [← real_inner_self_eq_norm_sq, b.orthonormal.inner_sum] + simp [sq] + rw [gaussian_density_product, gaussianRadialDensity, hnorm] + +lemma stdGaussian_absolutelyContinuous_volume : stdGaussian E ≪ volume := by + rw [stdGaussian_density] + exact withDensity_absolutelyContinuous _ _ + +lemma stdGaussian_singleton_eq_zero [Nontrivial E] (x : E) : (stdGaussian E) {x} = 0 := + stdGaussian_absolutelyContinuous_volume (measure_singleton x) + +def gaussianPolarRadius (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] : Measure (Ioi (0 : ℝ)) := + (Measure.volumeIoiPow (Module.finrank ℝ E - 1)).withDensity + (fun r => gaussianRadialDensity (Module.finrank ℝ E) r.1) + +instance : SFinite (gaussianPolarRadius E) := by + unfold gaussianPolarRadius + infer_instance + +lemma gaussian_polar [Nontrivial E] : + ((stdGaussian E).comap (Subtype.val : ({0}ᶜ : Set E) → E)).map + (homeomorphUnitSphereProd E) = + (volume : Measure E).toSphere.prod (gaussianPolarRadius E) := by + let e := (homeomorphUnitSphereProd E).toMeasurableEquiv + let c : ({0}ᶜ : Set E) → E := Subtype.val + have hc : MeasurableEmbedding c := MeasurableEmbedding.subtype_coe (measurableSet_singleton 0).compl + have he : ((volume : Measure E).comap c).map e = + (volume : Measure E).toSphere.prod (Measure.volumeIoiPow (Module.finrank ℝ E - 1)) := + (Measure.measurePreserving_homeomorphUnitSphereProd (volume : Measure E)).map_eq + have hcomap : (stdGaussian E).comap c = ((volume : Measure E).comap c).withDensity + (fun x => gaussianRadialDensity (Module.finrank ℝ E) ‖(x : E)‖) := by + apply hc.map_injective + rw [hc.map_comap] + have hd : (fun x : ({0}ᶜ : Set E) => gaussianRadialDensity (Module.finrank ℝ E) ‖(x : E)‖) = + (fun x : E => gaussianRadialDensity (Module.finrank ℝ E) ‖x‖) ∘ c := rfl + rw [hd, map_withDensity_comp _ hc.measurable (by fun_prop)] + rw [hc.map_comap, stdGaussian_density, restrict_withDensity hc.measurableSet_range] + change ((stdGaussian E).comap c).map e = _ + rw [hcomap, map_withDensity_equiv _ e (by fun_prop), he] + have hn (z : sphere (0 : E) 1 × Ioi (0 : ℝ)) : ‖(e.symm z : E)‖ = z.2.1 := by + change ‖z.2.1 • (z.1 : E)‖ = _ + rw [norm_smul, Real.norm_eq_abs, abs_of_pos z.2.2, mem_sphere_zero_iff_norm.mp z.1.2, mul_one] + simp_rw [hn] + rw [gaussianPolarRadius, ← withDensity_one (μ := (volume : Measure E).toSphere), + prod_withDensity (by fun_prop) (by fun_prop)] + simp + +lemma gaussian_polar_reconstruction [Nontrivial E] : + (((volume : Measure E).toSphere).prod (gaussianPolarRadius E)).map + (fun z : sphere (0 : E) 1 × Ioi (0 : ℝ) => z.2.1 • (z.1 : E)) = stdGaussian E := by + rw [← gaussian_polar, Measure.map_map (by fun_prop) (by fun_prop)] + have he : ((fun z : sphere (0 : E) 1 × Ioi (0 : ℝ) => z.2.1 • (z.1 : E)) ∘ + homeomorphUnitSphereProd E) = (Subtype.val : ({0}ᶜ : Set E) → E) := by + funext x + change ((homeomorphUnitSphereProd E).symm ((homeomorphUnitSphereProd E) x) : E) = _ + simp + rw [he, (MeasurableEmbedding.subtype_coe (measurableSet_singleton (0 : E)).compl).map_comap] + simp only [Subtype.range_coe] + apply Measure.restrict_eq_self_of_ae_mem + simpa using (measure_eq_zero_iff_ae_notMem.mp (stdGaussian_singleton_eq_zero (0 : E))) + +lemma gaussian_polar_mass [Nontrivial E] : + (volume : Measure E).toSphere univ * gaussianPolarRadius E univ = 1 := by + have h := congrArg (fun μ : Measure E => μ univ) (gaussian_polar_reconstruction (E := E)) + rw [Measure.map_apply (by fun_prop) MeasurableSet.univ] at h + simpa only [preimage_univ, ← univ_prod_univ, Measure.prod_prod, measure_univ] using h + +lemma gaussianPolarRadius_mass [Nontrivial E] : + gaussianPolarRadius E univ = ((volume : Measure E).toSphere univ)⁻¹ := by + have hs : (volume : Measure E).toSphere univ ≠ 0 := + (Measure.measure_univ_ne_zero.mpr (Measure.toSphere_ne_zero volume)) + have hf : (volume : Measure E).toSphere univ ≠ ∞ := measure_ne_top _ _ + apply (ENNReal.mul_right_inj hs hf).mp + rw [gaussian_polar_mass, ENNReal.mul_inv_cancel hs hf] + +instance [Nontrivial E] : IsFiniteMeasure (gaussianPolarRadius E) where + measure_univ_lt_top := by + rw [gaussianPolarRadius_mass] + exact ENNReal.inv_lt_top.mpr (pos_iff_ne_zero.mpr + (Measure.measure_univ_ne_zero.mpr (Measure.toSphere_ne_zero volume))) + +def normalDirection (x : E) : E := ‖x‖⁻¹ • x + +@[fun_prop] lemma measurable_normalDirection : Measurable (normalDirection (E := E)) := by + unfold normalDirection + fun_prop + +def uniformDirection (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] : Measure E := + let σ := (volume : Measure E).toSphere + ((σ univ)⁻¹ • σ).map Subtype.val + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma normalDirection_smul_sphere [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {r : ℝ} (hr : 0 < r) {x : E} (hx : ‖x‖ = 1) : + normalDirection (r • x) = x := by + simp [normalDirection, norm_smul, Real.norm_eq_abs, abs_of_pos hr, hx, smul_smul, hr.ne'] + +lemma gaussian_normalDirection [Nontrivial E] : + (stdGaussian E).map normalDirection = uniformDirection E := by + rw [← gaussian_polar_reconstruction (E := E), Measure.map_map (by fun_prop) (by fun_prop)] + have he : normalDirection ∘ + (fun z : sphere (0 : E) 1 × Ioi (0 : ℝ) => z.2.1 • (z.1 : E)) = + Subtype.val ∘ Prod.fst := by + funext z + exact normalDirection_smul_sphere z.2.2 (mem_sphere_zero_iff_norm.mp z.1.2) + rw [he, ← Measure.map_map (by fun_prop) (by fun_prop)] + change Measure.map Subtype.val + (((volume : Measure E).toSphere).prod (gaussianPolarRadius E)).fst = _ + rw [Measure.fst, Measure.map_fst_prod, gaussianPolarRadius_mass] + rfl + +instance [Nontrivial E] : IsProbabilityMeasure (uniformDirection E) := by + rw [← gaussian_normalDirection] + infer_instance + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianRowMix.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianRowMix.lean new file mode 100644 index 0000000000000000000000000000000000000000..e53470c18bcf7432fee30aa4ef51db62040a0f3c --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianRowMix.lean @@ -0,0 +1,108 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.MatrixNoise +import OAI.Probability.PosteriorReplicas.Gaussian.RandomComplement + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma matrixNormal_density (m k : ℕ) : matrixNormal m k = + (volume : Measure (Fin m → Fin k → ℝ)).withDensity + (fun z => ∏ i, ∏ j, gaussianPDF 0 1 (z i j)) := by + have h := matrixNormal_scale m k 0 + have he : matrixNoiseDensity m k 0 = (fun z => ∏ i, ∏ j, gaussianPDF 0 1 (z i j)) := by + funext z + have hv : (⟨(noiseScale 0)^2, sq_nonneg _⟩ : ℝ≥0) = 1 := by ext; norm_num [noiseScale] + simp only [matrixNoiseDensity, hv] + rfl + rw [he] at h + simpa [noiseScale] using h + +lemma matrixNormal_transpose (m k : ℕ) : (matrixNormal m k).map (transposeCLE m k) = + matrixNormal k m := by + let e := (transposeCLE m k).toHomeomorph.toMeasurableEquiv + rw [matrixNormal_density, matrixNormal_density] + change ((volume : Measure (Fin m → Fin k → ℝ)).withDensity _).map e = _ + rw [map_withDensity_equiv _ e (by fun_prop)] + change ((volume : Measure (Fin m → Fin k → ℝ)).map (transposeCLE m k)).withDensity _ = _ + rw [(transpose_volume_preserving m k).map_eq] + congr 1 + funext z + exact Finset.prod_comm + +lemma gaussianRows_eq_matrixNormal (d k : ℕ) : gaussianRows d k = + (matrixNormal k d).map (fun z i => WithLp.toLp 2 (z i)) := by + unfold gaussianRows matrixNormal + rw [Measure.pi_map_pi (fun _ => (WithLp.measurable_toLp _ _).aemeasurable)] + simp_rw [map_pi_eq_stdGaussian] + +def vecTranspose {d k : ℕ} (A : Rows d k) : Rows k d := + fun j => WithLp.toLp 2 (fun i => A i j) + +@[fun_prop] lemma measurable_vecTranspose {d k : ℕ} : Measurable (@vecTranspose d k) := by + unfold vecTranspose + fun_prop + +@[simp] lemma vecTranspose_involutive {d k : ℕ} (A : Rows d k) : + vecTranspose (vecTranspose A) = A := rfl + +lemma gaussianRows_transpose (d k : ℕ) : (gaussianRows d k).map vecTranspose = gaussianRows k d := by + rw [gaussianRows_eq_matrixNormal d k, Measure.map_map (by fun_prop) (by fun_prop), + gaussianRows_eq_matrixNormal k d, ← matrixNormal_transpose k d, + Measure.map_map (by fun_prop) (by fun_prop)] + rfl + +def rowMix {d ℓ k : ℕ} (C : Rows ℓ k) (A : Rows d ℓ) : Rows d k := + fun i => ∑ j, (C i j) • A j + +@[fun_prop] lemma measurable_rowMix {d ℓ k : ℕ} : + Measurable (fun z : Rows ℓ k × Rows d ℓ => rowMix z.1 z.2) := by + unfold rowMix + fun_prop + +lemma rowMix_apply {d ℓ k : ℕ} (C : Rows ℓ k) (A : Rows d ℓ) (i : Fin k) (j : Fin d) : + rowMix C A i j = ⟪C i, vecTranspose A j⟫ := by + simp [rowMix, vecTranspose, PiLp.inner_apply, Finset.sum_apply, mul_comm] + +lemma gaussianRows_mix {d ℓ k : ℕ} {C : Rows ℓ k} (hC : Orthonormal ℝ C) : + (gaussianRows d ℓ).map (rowMix C) = gaussianRows d k := by + have hc : (stdGaussian (Vec ℓ)).map (fun x => WithLp.toLp 2 (labels C x)) = stdGaussian (Vec k) := by + change ((stdGaussian (Vec ℓ)).map ((WithLp.toLp 2) ∘ labels C)) = _ + rw [← Measure.map_map (WithLp.measurable_toLp _ _) (show Measurable (labels C) by fun_prop)] + change ((stdGaussian (Vec ℓ)).map (fun x i => ⟪C i, x⟫)).map (WithLp.toLp 2) = _ + rw [PosteriorRegression.orthonormal_gaussian_map hC, map_pi_eq_stdGaussian] + have hm : (gaussianRows ℓ d).map (fun v i => WithLp.toLp 2 (labels C (v i))) = gaussianRows k d := by + unfold gaussianRows + rw [Measure.pi_map_pi (f := fun _ : Fin d => fun x : Vec ℓ => WithLp.toLp 2 (labels C x)) + (fun _ => by fun_prop)] + simp_rw [hc] + have h := congrArg (Measure.map (@vecTranspose k d)) hm + rw [Measure.map_map (by fun_prop) (by fun_prop), gaussianRows_transpose] at h + rw [← gaussianRows_transpose d ℓ, Measure.map_map (by fun_prop) (by fun_prop)] at h + convert h using 1 + congr 1 + funext A i + ext j + exact rowMix_apply C A i j + +lemma rowMix_starProjection {d ℓ k : ℕ} (C : Rows ℓ k) (A : Rows d ℓ) + (U : Submodule ℝ (Vec d)) : + rowMix C (fun j => U.starProjection (A j)) = fun i => U.starProjection (rowMix C A i) := by + ext i + simp [rowMix, map_sum] + +lemma gaussianRows_mix_projected {d ℓ k : ℕ} {C : Rows ℓ k} (hC : Orthonormal ℝ C) + (U : Submodule ℝ (Vec d)) : + (gaussianRows d ℓ).map (fun A => rowMix C (fun j => U.starProjection (A j))) = + (gaussianRows d k).map (fun A i => U.starProjection (A i)) := by + rw [← gaussianRows_mix hC, Measure.map_map (by fun_prop) (by fun_prop)] + congr 1 + funext A + exact rowMix_starProjection C A U + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianSmallBall.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianSmallBall.lean new file mode 100644 index 0000000000000000000000000000000000000000..995846d82a8da4a72555f46b7eade7b0c5ba4286 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianSmallBall.lean @@ -0,0 +1,123 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianPolar + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussian_density_ball_lower {R : ℝ} (hR : 0 ≤ R) : + ENNReal.ofReal ((2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2) * + Real.exp (-R^2/2)) * volume (closedBall (0 : E) R) ≤ 1 := by + calc + _ = ∫⁻ x in closedBall (0 : E) R, + ENNReal.ofReal ((2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2) * + Real.exp (-R^2/2)) ∂volume := by simp + _ ≤ ∫⁻ x in closedBall (0 : E) R, + gaussianRadialDensity (Module.finrank ℝ E) ‖x‖ ∂volume := by + apply setLIntegral_mono' isClosed_closedBall.measurableSet + intro x hx + apply ENNReal.ofReal_le_ofReal + apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Real.exp_le_exp.mpr + have hn : ‖x‖ ≤ R := by simpa only [mem_closedBall, dist_zero_right] using hx + nlinarith [norm_nonneg x, sq_nonneg (R-‖x‖)] + _ = stdGaussian E (closedBall (0 : E) R) := by + rw [stdGaussian_density, withDensity_apply _ isClosed_closedBall.measurableSet] + _ ≤ 1 := prob_le_one + +lemma gaussian_density_ball_upper (a : E) (r : ℝ) : + stdGaussian E (closedBall a r) ≤ + ENNReal.ofReal ((2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2)) * + volume (closedBall a r) := by + rw [stdGaussian_density, withDensity_apply _ isClosed_closedBall.measurableSet] + calc + _ ≤ ∫⁻ _ in closedBall a r, + ENNReal.ofReal ((2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2)) ∂volume := by + apply lintegral_mono + intro x + apply ENNReal.ofReal_le_ofReal + have he : Real.exp (-‖x‖^2/2) ≤ 1 := by + rw [Real.exp_le_one_iff] + nlinarith [sq_nonneg ‖x‖] + exact mul_le_of_le_one_right (by positivity) he + _ = _ := by simp + +lemma gaussian_closedBall_ratio (a : E) {R r : ℝ} (hR : 0 < R) (hr : 0 ≤ r) : + stdGaussian E (closedBall a r) ≤ + ENNReal.ofReal (Real.exp (R^2/2) * (r/R)^(Module.finrank ℝ E)) := by + let c : ℝ := (2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2) + have hexp : ENNReal.ofReal (Real.exp (R^2/2)) * + ENNReal.ofReal (Real.exp (-R^2/2)) = 1 := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← Real.exp_add] + have he : R^2/2 + -R^2/2 = 0 := by ring + rw [he, Real.exp_zero, ENNReal.ofReal_one] + have h := mul_le_mul_right (gaussian_density_ball_lower (E := E) hR.le) + (ENNReal.ofReal (Real.exp (R^2/2))) + have hvol : ENNReal.ofReal c * volume (closedBall (0 : E) R) ≤ + ENNReal.ofReal (Real.exp (R^2/2)) := by + dsimp only [c] at * + rw [ENNReal.ofReal_mul (by positivity), mul_one] at h + calc + _ = (ENNReal.ofReal (Real.exp (R^2/2)) * ENNReal.ofReal (Real.exp (-R^2/2))) * + (ENNReal.ofReal ((2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2)) * + volume (closedBall (0 : E) R)) := by rw [hexp, one_mul] + _ ≤ _ := by simpa only [mul_assoc, mul_comm, mul_left_comm] using h + have hscale : volume (closedBall a r) = + ENNReal.ofReal ((r/R)^(Module.finrank ℝ E)) * volume (closedBall (0 : E) R) := by + have hh := Measure.addHaar_closedBall_mul (volume : Measure E) a (div_nonneg hr hR.le) hR.le + rw [div_mul_cancel₀ _ hR.ne'] at hh + exact hh + calc + _ ≤ ENNReal.ofReal c * volume (closedBall a r) := gaussian_density_ball_upper a r + _ = ENNReal.ofReal ((r/R)^(Module.finrank ℝ E)) * + (ENNReal.ofReal c * volume (closedBall (0 : E) R)) := by rw [hscale]; ac_rfl + _ ≤ ENNReal.ofReal ((r/R)^(Module.finrank ℝ E)) * + ENNReal.ofReal (Real.exp (R^2/2)) := mul_le_mul_right hvol _ + _ = _ := by rw [← ENNReal.ofReal_mul (by positivity)]; congr 1; ring + +lemma gaussian_normalized_inverse_moment (a : E) (k : ℕ) (hk : k+1 ≤ Module.finrank ℝ E) + {R : ℝ} (hR : 0 < R) : + (∫⁻ x : E, ENNReal.ofReal (((‖x-a‖ / R)⁻¹)^k) ∂stdGaussian E) ≤ + 1 + ENNReal.ofReal (Real.exp (R^2/2)) * 2^(k+1) := by + have h := PosteriorRegression.inverse_moment_of_tube_bound (stdGaussian E) + (fun x : E => ‖x-a‖/R) k (by fun_prop) (fun x => by positivity) + (ENNReal.ofReal (Real.exp (R^2/2))) ?_ + · simpa only [measure_univ] using h + intro r hr hr1 + have hs : {x : E | ‖x-a‖ / R ≤ r} = closedBall a (r*R) := by + ext x + simp only [mem_ofPred_eq, mem_closedBall, dist_eq_norm, div_le_iff₀ hR] + rw [hs] + calc + _ ≤ ENNReal.ofReal (Real.exp (R^2/2) * ((r*R)/R)^(Module.finrank ℝ E)) := + gaussian_closedBall_ratio a hR (mul_nonneg hr.le hR.le) + _ ≤ _ := by + rw [mul_div_cancel_right₀ _ hR.ne', ENNReal.ofReal_mul (by positivity)] + apply mul_le_mul_right + exact ENNReal.ofReal_le_ofReal (pow_le_pow_of_le_one hr.le hr1 hk) + +lemma gaussian_inverse_norm_moment (a : E) (k : ℕ) (hk : k+1 ≤ Module.finrank ℝ E) + {R : ℝ} (hR : 0 < R) : + (∫⁻ x : E, ENNReal.ofReal (‖x-a‖⁻¹^k) ∂stdGaussian E) ≤ + ENNReal.ofReal (R⁻¹^k) * (1 + ENNReal.ofReal (Real.exp (R^2/2)) * 2^(k+1)) := by + have he : (∫⁻ x : E, ENNReal.ofReal (‖x-a‖⁻¹^k) ∂stdGaussian E) = + ENNReal.ofReal (R⁻¹^k) * ∫⁻ x : E, ENNReal.ofReal (((‖x-a‖/R)⁻¹)^k) ∂stdGaussian E := by + rw [← lintegral_const_mul _ (show Measurable (fun x : E => + ENNReal.ofReal (((‖x-a‖/R)⁻¹)^k)) by fun_prop)] + apply lintegral_congr + intro x + rw [← ENNReal.ofReal_mul (by positivity), ← mul_pow] + congr 2 + rw [inv_div, div_eq_mul_inv, ← mul_assoc, inv_mul_cancel₀ hR.ne', one_mul] + rw [he] + exact mul_le_mul_right (gaussian_normalized_inverse_moment a k hk hR) _ + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianWishart.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianWishart.lean new file mode 100644 index 0000000000000000000000000000000000000000..9dfd1314dfb2570e779c6ea4be8483a1efd94fbe --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GaussianWishart.lean @@ -0,0 +1,58 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GramTransform + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +def wishartMoment (ℓ m k : ℕ) : ℝ≥0∞ := + ∫⁻ G : Rows ℓ m, ENNReal.ofReal ((gramVolume G)⁻¹^k) ∂gaussianRows ℓ m + +lemma wishartMoment_bound {ℓ m k : ℕ} (hk : 1 ≤ k) (hkm : k+m ≤ ℓ) : + wishartMoment ℓ m k ≤ gaussianMomentConstant k ^ m := by + exact gaussian_gram_inverse_moment_centered k m hk (by simpa using hkm) + +lemma wishartMoment_ne_top {ℓ m k : ℕ} (hk : 1 ≤ k) (hkm : k+m ≤ ℓ) : + wishartMoment ℓ m k ≠ ∞ := + ne_top_of_le_ne_top (ENNReal.pow_ne_top (gaussianMomentConstant_ne_top k)) (wishartMoment_bound hk hkm) + +lemma wishartMoment_pos {ℓ m k : ℕ} (hm : m ≤ ℓ) : 0 < wishartMoment ℓ m k := by + unfold wishartMoment + apply (lintegral_pos_iff_support (by fun_prop)).mpr + have h : ∀ᵐ G : Rows ℓ m ∂gaussianRows ℓ m, 0 < ENNReal.ofReal ((gramVolume G)⁻¹^k) := by + filter_upwards [ae_gaussian_columns_independent (E := Vec ℓ) m (by simpa using hm)] with G hG + exact ENNReal.ofReal_pos.mpr (pow_pos (inv_pos.mpr (gramVolume_pos hG)) _) + have he : (gaussianRows ℓ m) (Function.support (fun G : Rows ℓ m => ENNReal.ofReal ((gramVolume G)⁻¹^k))) = 1 := by + apply (ae_iff_prob_eq_one (by fun_prop)).mp + filter_upwards [h] with G hG + exact hG.ne' + rw [he] + norm_num + +lemma pairingColumns_inverse_moment {d ℓ m k : ℕ} {v : Rows d m} (hv : LinearIndependent ℝ v) (hm : m ≤ ℓ) : + (∫⁻ B, (ENNReal.ofReal (gramVolume (pairingColumns v B)))⁻¹^k ∂gaussianRows d ℓ) = + (ENNReal.ofReal (gramVolume v))⁻¹^k * wishartMoment ℓ m k := by + have h := pairingColumns_law (ℓ := ℓ) hv + have hi := congrArg (fun μ : Measure (Rows ℓ m) => + ∫⁻ G, (ENNReal.ofReal (gramVolume G))⁻¹^k ∂μ) h + rw [lintegral_map (by fun_prop) (by fun_prop), lintegral_map (by fun_prop) (by fun_prop)] at hi + rw [hi] + have hd : (pairingTriangular v).det = gramVolume v := by + rw [← Matrix.det_transpose, pairingTriangular_det] + rfl + simp_rw [gramVolume_columnMix,hd,abs_of_nonneg (show 0 ≤ gramVolume v from Real.sqrt_nonneg _), + ENNReal.ofReal_mul (show 0 ≤ gramVolume v from Real.sqrt_nonneg _), ENNReal.mul_inv (Or.inl (ne_of_gt (ENNReal.ofReal_pos.mpr (gramVolume_pos hv)))) + (Or.inl ENNReal.ofReal_ne_top), + mul_pow] + rw [lintegral_const_mul _ (by fun_prop)] + congr 1 + apply lintegral_congr_ae + filter_upwards [ae_gaussian_columns_independent (E := Vec ℓ) m (by simpa using hm)] with G hG + rw [← ENNReal.ofReal_inv_of_pos (gramVolume_pos hG), ← ENNReal.ofReal_pow (inv_nonneg.mpr (gramVolume_pos hG).le)] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/GramTransform.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GramTransform.lean new file mode 100644 index 0000000000000000000000000000000000000000..3aae32aedb93b5665126ee7df72e733a77a1417a --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/GramTransform.lean @@ -0,0 +1,98 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianRowMix + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def columnMix {m : ℕ} (v : Fin m → E) (M : Matrix (Fin m) (Fin m) ℝ) : Fin m → E := + fun j => ∑ i, M i j • v i + +@[fun_prop] lemma measurable_columnMix {m : ℕ} (M : Matrix (Fin m) (Fin m) ℝ) : + Measurable (fun v : Fin m → E => columnMix v M) := by + unfold columnMix + fun_prop + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma gram_columnMix [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {m : ℕ} (v : Fin m → E) (M : Matrix (Fin m) (Fin m) ℝ) : + Matrix.gram ℝ (columnMix v M) = M.transpose * Matrix.gram ℝ v * M := by + exact PosteriorRegression.gram_linear_combination v M + +lemma gramVolume_columnMix {m : ℕ} (v : Fin m → E) (M : Matrix (Fin m) (Fin m) ℝ) : + gramVolume (columnMix v M) = |M.det| * gramVolume v := by + unfold gramVolume + rw [gram_columnMix, Matrix.det_mul, Matrix.det_mul, Matrix.det_transpose] + have he : M.det * (Matrix.gram ℝ v).det * M.det = M.det^2 * (Matrix.gram ℝ v).det := by ring + rw [he, Real.sqrt_mul (sq_nonneg _), Real.sqrt_sq_eq_abs] + +lemma columnMix_independent {m : ℕ} {v : Fin m → E} (hv : LinearIndependent ℝ v) + {M : Matrix (Fin m) (Fin m) ℝ} (hM : M.det ≠ 0) : + LinearIndependent ℝ (columnMix v M) := by + apply Matrix.linearIndependent_of_det_gram_ne_zero + rw [gram_columnMix, Matrix.det_mul, Matrix.det_mul, Matrix.det_transpose] + exact mul_ne_zero (mul_ne_zero hM (Matrix.det_gram_ne_zero_iff_linearIndependent.mpr hv)) hM + +def pairingColumns {d ℓ m : ℕ} (v : Rows d m) (B : Rows d ℓ) : Rows ℓ m := + fun i => WithLp.toLp 2 (fun j => ⟪v i, B j⟫) + +@[fun_prop] lemma measurable_pairingColumns {d ℓ m : ℕ} : + Measurable (fun z : Rows d m × Rows d ℓ => pairingColumns z.1 z.2) := by + unfold pairingColumns + fun_prop + +lemma pairingColumns_triangular {d ℓ m : ℕ} {v : Rows d m} (hv : LinearIndependent ℝ v) + (B : Rows d ℓ) : + pairingColumns v B = columnMix (pairingColumns (gramSchmidtNormed ℝ v) B) (pairingTriangular v) := by + ext i j + change ⟪v i, B j⟫ = _ + conv_lhs => rw [← pairingTriangular_expansion hv i] + simp [columnMix, pairingColumns, sum_inner, inner_smul_left, Finset.sum_apply] + +lemma orthonormal_pairingColumns_law {d ℓ m : ℕ} {v : Rows d m} (hv : Orthonormal ℝ v) : + (gaussianRows d ℓ).map (pairingColumns v) = gaussianRows ℓ m := by + have he : (pairingColumns v : Rows d ℓ → Rows ℓ m) = rowMix v ∘ vecTranspose := by + funext B + ext i j + exact (rowMix_apply v (vecTranspose B) i j).symm + rw [he, ← Measure.map_map (by fun_prop) (by fun_prop), gaussianRows_transpose, + gaussianRows_mix hv] + +lemma pairingColumns_law {d ℓ m : ℕ} {v : Rows d m} (hv : LinearIndependent ℝ v) : + (gaussianRows d ℓ).map (pairingColumns v) = + (gaussianRows ℓ m).map (fun G => columnMix G (pairingTriangular v)) := by + have he : (pairingColumns v : Rows d ℓ → Rows ℓ m) = (fun G => columnMix G (pairingTriangular v)) ∘ + pairingColumns (gramSchmidtNormed ℝ v) := funext (pairingColumns_triangular hv) + rw [he, ← Measure.map_map (by fun_prop) (by fun_prop), + orthonormal_pairingColumns_law (gramSchmidtNormed_orthonormal hv)] + +lemma ae_pairingColumns_independent {d ℓ m : ℕ} {v : Rows d m} + (hv : LinearIndependent ℝ v) (hm : m ≤ ℓ) : + ∀ᵐ B ∂gaussianRows d ℓ, LinearIndependent ℝ (pairingColumns v B) := by + have he : ∀ᵐ G ∂gaussianRows ℓ m, LinearIndependent ℝ (columnMix G (pairingTriangular v)) := by + filter_upwards [ae_gaussian_columns_independent (E := Vec ℓ) m (by simpa using hm)] with G hG + apply columnMix_independent hG + simpa only [Matrix.det_transpose] using (pairingTriangular_det_pos hv).ne' + have he' : ∀ᵐ V ∂(gaussianRows d ℓ).map (pairingColumns v), LinearIndependent ℝ V := by + rw [pairingColumns_law hv] + exact (ae_map_iff (by fun_prop) isOpen_setOfPred_linearIndependent.measurableSet).mpr he + exact (ae_map_iff (by fun_prop) isOpen_setOfPred_linearIndependent.measurableSet).mp he' + +lemma gramVolume_pairingColumns {d ℓ m : ℕ} {v : Rows d m} (hv : LinearIndependent ℝ v) + (B : Rows d ℓ) : gramVolume (pairingColumns v B) = + gramVolume v * gramVolume (pairingColumns (gramSchmidtNormed ℝ v) B) := by + rw [pairingColumns_triangular hv, gramVolume_columnMix] + have hd : (pairingTriangular v).det = gramVolume v := by + rw [← Matrix.det_transpose, pairingTriangular_det] + rfl + rw [hd, abs_of_nonneg (show 0 ≤ gramVolume v from Real.sqrt_nonneg _)] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/MatrixNoise.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/MatrixNoise.lean new file mode 100644 index 0000000000000000000000000000000000000000..9c005f08a687406ec2d50c594568f772bf5d1ba5 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/MatrixNoise.lean @@ -0,0 +1,143 @@ +import OAI.Probability.PosteriorReplicas.Measures.DensityTools + +namespace OAI + +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal Topology +noncomputable section +namespace PosteriorReplicas + +def transposeCLE (m k : ℕ) : (Fin m → Fin k → ℝ) ≃L[ℝ] (Fin k → Fin m → ℝ) := + ({ toFun := fun z j i => z i j + invFun := fun z i j => z j i + left_inv := fun _ => rfl + right_inv := fun _ => rfl + map_add' := fun _ _ => rfl + map_smul' := fun _ _ => rfl } : + (Fin m → Fin k → ℝ) ≃ₗ[ℝ] (Fin k → Fin m → ℝ)).toContinuousLinearEquiv + +@[simp] lemma transposeCLE_apply (m k : ℕ) (z : Fin m → Fin k → ℝ) : + transposeCLE m k z = fun j i => z i j := rfl + +lemma matrix_volume_unit_cube (m k : ℕ) : + (volume : Measure (Fin m → Fin k → ℝ)) (Icc 0 1) = 1 := by + rw [← pi_univ_Icc, volume_pi_pi] + simp only [Pi.zero_apply, Pi.one_apply, Real.volume_Icc_pi, sub_zero, + ENNReal.ofReal_one, Finset.prod_const_one] + +instance matrixPiVolumeAddHaar (m k : ℕ) : + (volume : Measure (Fin m → Fin k → ℝ)).IsAddHaarMeasure := + Measure.pi.isAddHaarMeasure (fun _ : Fin m => (volume : Measure (Fin k → ℝ))) + +lemma transpose_volume_preserving (m k : ℕ) : + MeasurePreserving (transposeCLE m k) volume volume := by + let e := transposeCLE m k + have h := Measure.isAddLeftInvariant_eq_smul ((volume : Measure (Fin m → Fin k → ℝ)).map e) + (volume : Measure (Fin k → Fin m → ℝ)) + have he : e ⁻¹' Icc 0 1 = Icc 0 1 := by + ext z + simp only [mem_preimage, mem_Icc, Pi.le_def, Pi.zero_apply, Pi.one_apply, + e, transposeCLE_apply] + constructor <;> rintro ⟨h₁,h₂⟩ <;> exact ⟨fun i j => h₁ j i, fun i j => h₂ j i⟩ + have hc := congrArg (fun μ : Measure (Fin k → Fin m → ℝ) => μ (Icc 0 1)) h + rw [Measure.map_apply e.continuous.measurable measurableSet_Icc, he, + matrix_volume_unit_cube, Measure.smul_apply, matrix_volume_unit_cube, + ENNReal.smul_def, smul_eq_mul, mul_one] at hc + refine ⟨e.continuous.measurable, ?_⟩ + rw [h] + have hc' : ((volume : Measure (Fin m → Fin k → ℝ)).map e).addHaarScalarFactor volume = 1 := + ENNReal.coe_inj.mp (by simpa only [ENNReal.coe_one] using hc.symm) + rw [hc', one_smul] + +def matrixNormal (m k : ℕ) : Measure (Fin m → Fin k → ℝ) := + Measure.pi fun _ => Measure.pi fun _ => gaussianReal 0 1 + +instance (m k : ℕ) : IsProbabilityMeasure (matrixNormal m k) := by + unfold matrixNormal + infer_instance + +def noiseScale (n : ℕ) : ℝ := 1 / (n + 1) + +lemma noiseScale_pos (n : ℕ) : 0 < noiseScale n := by unfold noiseScale; positivity +lemma tendsto_noiseScale : Filter.Tendsto noiseScale Filter.atTop (nhds 0) := + tendsto_one_div_add_atTop_nhds_zero_nat + +def matrixNoiseDensity (m k n : ℕ) (z : Fin m → Fin k → ℝ) : ℝ≥0∞ := + ∏ i, ∏ j, gaussianPDF 0 (⟨(noiseScale n)^2, sq_nonneg _⟩ : ℝ≥0) (z i j) + +@[fun_prop] lemma measurable_matrixNoiseDensity (m k n : ℕ) : + Measurable (matrixNoiseDensity m k n) := by + unfold matrixNoiseDensity + fun_prop + +lemma matrixNormal_scale (m k n : ℕ) : + (matrixNormal m k).map (fun z => noiseScale n • z) = + volume.withDensity (matrixNoiseDensity m k n) := by + let v : ℝ≥0 := ⟨(noiseScale n)^2, sq_nonneg _⟩ + have hv : v ≠ 0 := by + intro h + have hh : (noiseScale n)^2 = 0 := congrArg NNReal.toReal h + exact (sq_pos_of_pos (noiseScale_pos n)).ne' hh + have hg : (gaussianReal 0 1).map (fun x => noiseScale n * x) = gaussianReal 0 v := by + have h := gaussianReal_map_const_mul (μ := 0) (v := 1) (noiseScale n) + rw [mul_zero, mul_one] at h + exact h + have hgd : gaussianReal 0 v = volume.withDensity (gaussianPDF 0 v) := + gaussianReal_of_var_ne_zero _ hv + have : IsProbabilityMeasure (volume.withDensity (gaussianPDF 0 v)) := hgd ▸ inferInstance + have hlabel : (Measure.pi (fun _ : Fin k => gaussianReal 0 1)).map + (fun z => noiseScale n • z) = + (volume : Measure (Fin k → ℝ)).withDensity (fun z => ∏ j, gaussianPDF 0 v (z j)) := by + change (Measure.pi (fun _ : Fin k => gaussianReal 0 1)).map + (fun z i => noiseScale n * z i) = _ + rw [Measure.pi_map_pi (fun _ => (show Measurable (fun x : ℝ => noiseScale n * x) by fun_prop).aemeasurable)] + simp_rw [hg, hgd] + exact pi_withDensity _ _ (fun _ => measurable_gaussianPDF _ _) + have : IsProbabilityMeasure ((volume : Measure (Fin k → ℝ)).withDensity + (fun z => ∏ j, gaussianPDF 0 v (z j))) := by + rw [← hlabel] + infer_instance + change (Measure.pi (fun _ : Fin m => Measure.pi (fun _ : Fin k => gaussianReal 0 1))).map + (fun z i => noiseScale n • z i) = _ + rw [Measure.pi_map_pi (fun _ => (show Measurable (fun z : Fin k → ℝ => noiseScale n • z) by fun_prop).aemeasurable)] + simp_rw [hlabel] + exact pi_withDensity _ _ (fun _ => by fun_prop) + +lemma matrix_noise_shrinks {m k : ℕ} (z : Fin m → Fin k → ℝ) : + Filter.Tendsto (fun n => noiseScale n • z) Filter.atTop (nhds 0) := by + simpa using tendsto_noiseScale.smul_const z + +end PosteriorReplicas + +namespace PosteriorReplicas +lemma matrixNoise_convolution {m k n : ℕ} (c : Fin m → Fin k → ℝ) + {F : (Fin m → Fin k → ℝ) → ℝ≥0∞} (hF : Measurable F) : + ∫⁻ y, matrixNoiseDensity m k n (y-c) * F y ∂volume = + ∫⁻ z, F (c + noiseScale n • z) ∂matrixNormal m k := by + have hf : Measurable (fun y => matrixNoiseDensity m k n (y-c) * F y) := by fun_prop + rw [← (measurePreserving_add_left (volume : Measure (Fin m → Fin k → ℝ)) c).lintegral_comp hf] + simp only [add_sub_cancel_left] + have he := lintegral_withDensity_eq_lintegral_mul (volume : Measure (Fin m → Fin k → ℝ)) + (measurable_matrixNoiseDensity m k n) + (show Measurable (fun y => F (c+y)) from hF.comp (by fun_prop)) + simp only [Pi.mul_apply] at he + rw [← he, ← matrixNormal_scale m k n, + lintegral_map (show Measurable (fun y => F (c+y)) by fun_prop) (by fun_prop)] + +lemma matrixNoise_transpose_lintegral {m k n : ℕ} + {F : (Fin k → Fin m → ℝ) → ℝ≥0∞} (hF : Measurable F) : + ∫⁻ y, matrixNoiseDensity m k n (transposeCLE k m y) * F y ∂volume = + ∫⁻ z, F (transposeCLE m k (noiseScale n • z)) ∂matrixNormal m k := by + have hf : Measurable (fun y => matrixNoiseDensity m k n (transposeCLE k m y) * F y) := by fun_prop + rw [← (transpose_volume_preserving m k).lintegral_comp hf] + simp only [transposeCLE_apply] + have he := lintegral_withDensity_eq_lintegral_mul (volume : Measure (Fin m → Fin k → ℝ)) + (measurable_matrixNoiseDensity m k n) + (show Measurable (fun y : Fin m → Fin k → ℝ => F (fun j i => y i j)) from hF.comp (by fun_prop)) + simp only [Pi.mul_apply] at he + rw [← he, ← matrixNormal_scale m k n, + lintegral_map (show Measurable (fun y : Fin m → Fin k → ℝ => F (fun j i => y i j)) by fun_prop) (by fun_prop)] +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/ObservableGaussian.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/ObservableGaussian.lean new file mode 100644 index 0000000000000000000000000000000000000000..df6b31c4901ad4bceb5f6a9d218fb965c2be9674 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/ObservableGaussian.lean @@ -0,0 +1,114 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GramTransform + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma gaussianRows_split {d ℓ : ℕ} (U : Submodule ℝ (Vec d)) : + ((gaussianRows d ℓ).prod (gaussianRows d ℓ)).map + (fun z j => U.starProjection (z.1 j) + Uᗮ.starProjection (z.2 j)) = gaussianRows d ℓ := by + let e := MeasurableEquiv.arrowProdEquivProdArrow (Vec d) (Vec d) (Fin ℓ) + have hj : (gaussianRows d ℓ).map + (fun B => ((fun j => U.starProjection (B j)), fun j => Uᗮ.starProjection (B j))) = + ((gaussianRows d ℓ).map (fun B j => U.starProjection (B j))).prod + ((gaussianRows d ℓ).map (fun B j => Uᗮ.starProjection (B j))) := by + change (gaussianRows d ℓ).map (e ∘ (fun B j => (U.starProjection (B j),Uᗮ.starProjection (B j)))) = _ + rw [← Measure.map_map e.measurable (by fun_prop)] + unfold gaussianRows + rw [Measure.pi_map_pi (f := fun _ : Fin ℓ => fun x : Vec d => + (U.starProjection x,Uᗮ.starProjection x)) (fun _ => by fun_prop)] + simp_rw [gaussian_orthogonal_pair U] + rw [(measurePreserving_arrowProdEquivProdArrow (Vec d) (Vec d) (Fin ℓ) _ _).map_eq] + rw [Measure.pi_map_pi (fun _ => by fun_prop), Measure.pi_map_pi (fun _ => by fun_prop)] + have h := congrArg (Measure.map (fun z : Rows d ℓ × Rows d ℓ => fun j => z.1 j + z.2 j)) hj + rw [Measure.map_map (by fun_prop) (by fun_prop), + Measure.map_prod_map _ _ (by fun_prop) (by fun_prop), + Measure.map_map (by fun_prop) (by fun_prop)] at h + have he : (fun B : Rows d ℓ => fun j => U.starProjection (B j) + Uᗮ.starProjection (B j)) = id := by + funext B j + exact Submodule.starProjection_add_starProjection_orthogonal (B j) + simpa only [Function.comp_def, Prod.map_fst, Prod.map_snd, he, Measure.map_id] using h.symm + +lemma pairingColumns_split {d ℓ m : ℕ} (v : Rows d m) (B R : Rows d ℓ) : + pairingColumns v (fun j => (Submodule.span ℝ (range v)).starProjection (B j) + + (Submodule.span ℝ (range v))ᗮ.starProjection (R j)) = pairingColumns v B := by + let U := Submodule.span ℝ (range v) + have hv (i : Fin m) : v i ∈ U := Submodule.subset_span (mem_range_self i) + ext i j + change ⟪v i,U.starProjection (B j)+Uᗮ.starProjection (R j)⟫ = ⟪v i,B j⟫ + rw [inner_add_right, pairing_starProjection U (hv i)] + have hz : ⟪v i,Uᗮ.starProjection (R j)⟫ = 0 := + (Submodule.mem_orthogonal U _).mp (Submodule.starProjection_apply_mem _ _) _ (hv i) + rw [hz, add_zero] + +lemma rowMix_pairing {d ℓ m k : ℕ} (v : Rows d m) (B : Rows d ℓ) (C : Rows ℓ k) + (i : Fin k) (j : Fin m) : + ⟪v j,rowMix C B i⟫ = ⟪C i,pairingColumns v B j⟫ := by + simp [rowMix, pairingColumns, inner_sum, inner_smul_right, PiLp.inner_apply, mul_comm] + +lemma rowMix_split_cancel {d ℓ m k : ℕ} (v : Rows d m) (B R : Rows d ℓ) (C : Rows ℓ k) + (hC : ∀ i j, ⟪C i,pairingColumns v B j⟫ = 0) : + rowMix C (fun j => (Submodule.span ℝ (range v)).starProjection (B j) + + (Submodule.span ℝ (range v))ᗮ.starProjection (R j)) = + rowMix C (fun j => (Submodule.span ℝ (range v))ᗮ.starProjection (R j)) := by + let U := Submodule.span ℝ (range v) + have hz (i : Fin k) : U.starProjection (rowMix C B i) = 0 := by + apply U.starProjection_apply_eq_zero_iff.mpr + apply (Submodule.mem_orthogonal U _).mpr + intro x hx + induction hx using Submodule.span_induction with + | mem x hx => + obtain ⟨j,rfl⟩ := hx + exact (rowMix_pairing v B C i j).trans (hC i j) + | zero => simp + | add x y _ _ hx hy => simp [inner_add_left,hx,hy] + | smul a x _ hx => simp [inner_smul_left,hx] + funext i + change (∑ j, C i j • (U.starProjection (B j) + Uᗮ.starProjection (R j))) = _ + simp only [smul_add, Finset.sum_add_distrib] + have hmap : (∑ j, C i j • U.starProjection (B j)) = U.starProjection (rowMix C B i) := by + simp [rowMix, map_sum] + rw [hmap,hz,zero_add] + rfl + +lemma observable_gaussian_lintegral {d ℓ m k : ℕ} {v : Rows d m} + (hv : LinearIndependent ℝ v) (hkm : k+m ≤ ℓ) + {H : Rows ℓ m × Rows d k → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ B, ∫⁻ e, H (pairingColumns v B, + rowMix (randomComplement (pairingColumns v B) e) B) ∂gaussianRows ℓ k ∂gaussianRows d ℓ) = + ∫⁻ B, ∫⁻ A, H (pairingColumns v B, + fun i => (Submodule.span ℝ (range v))ᗮ.starProjection (A i)) ∂gaussianRows d k ∂gaussianRows d ℓ := by + let U := Submodule.span ℝ (range v) + let f : Rows d ℓ → ℝ≥0∞ := fun B => ∫⁻ e, H (pairingColumns v B, + rowMix (randomComplement (pairingColumns v B) e) B) ∂gaussianRows ℓ k + have hf : Measurable f := by unfold f; fun_prop + change (∫⁻ B, f B ∂gaussianRows d ℓ) = _ + conv_lhs => rw [← gaussianRows_split U, lintegral_map hf (by fun_prop), lintegral_prod _ (by fun_prop)] + apply lintegral_congr_ae + filter_upwards [ae_pairingColumns_independent hv (by omega : m ≤ ℓ)] with B hB + change (∫⁻ R, ∫⁻ e, H (pairingColumns v (fun j => U.starProjection (B j)+Uᗮ.starProjection (R j)), + rowMix (randomComplement (pairingColumns v (fun j => U.starProjection (B j)+Uᗮ.starProjection (R j))) e) + (fun j => U.starProjection (B j)+Uᗮ.starProjection (R j))) ∂gaussianRows ℓ k ∂gaussianRows d ℓ) = _ + dsimp only [U] + simp_rw [pairingColumns_split] + rw [lintegral_lintegral_swap (by fun_prop)] + calc + _ = ∫⁻ _e, ∫⁻ A, H (pairingColumns v B, fun i => Uᗮ.starProjection (A i)) + ∂gaussianRows d k ∂gaussianRows ℓ k := by + apply lintegral_congr_ae + filter_upwards [ae_randomComplement_orthonormal hB hkm] with e he + dsimp only [U] + simp_rw [rowMix_split_cancel v B _ _ (randomComplement_orthogonal hB e)] + have hmap := gaussianRows_mix_projected (d := d) he Uᗮ + have h := congrArg (fun μ : Measure (Rows d k) => ∫⁻ A, H (pairingColumns v B,A) ∂μ) hmap + rw [lintegral_map (by fun_prop) (by fun_prop), lintegral_map (by fun_prop) (by fun_prop)] at h + exact h + _ = _ := by simp [U] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/RadialIntegrals.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/RadialIntegrals.lean new file mode 100644 index 0000000000000000000000000000000000000000..604339ae456a7cb704474d5e965f45208fd86afc --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/RadialIntegrals.lean @@ -0,0 +1,147 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianPolar + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma lintegral_pos_smul {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {r : ℝ} (hr : 0 < r) {f : E → ℝ≥0∞} (hf : Measurable f) : + ∫⁻ x, f x = ENNReal.ofReal (r ^ Module.finrank ℝ E) * ∫⁻ x, f (r • x) := by + have hm : ENNReal.ofReal (r ^ Module.finrank ℝ E) • + (volume : Measure E).map (fun x => r • x) = volume := by + rw [Measure.map_addHaar_smul _ hr.ne', smul_smul, + abs_of_pos (inv_pos.mpr (pow_pos hr _)), ← ENNReal.ofReal_mul (by positivity), + mul_inv_cancel₀ (pow_ne_zero _ hr.ne'), ENNReal.ofReal_one, one_smul] + conv_lhs => rw [← hm] + rw [lintegral_smul_measure, lintegral_map hf (by fun_prop)] + rfl + +lemma lintegral_Ioi_pos_mul {r : ℝ} (hr : 0 < r) {f : ℝ → ℝ≥0∞} (hf : Measurable f) : + ∫⁻ x in Ioi (0 : ℝ), f x = ENNReal.ofReal r * ∫⁻ x in Ioi (0 : ℝ), f (r * x) := by + have hp : (fun x : ℝ => r * x) ⁻¹' Ioi 0 = Ioi 0 := by + ext x + simp only [mem_preimage, mem_Ioi, mul_pos_iff_of_pos_left hr] + have hm : ENNReal.ofReal r • + ((volume : Measure ℝ).restrict (Ioi 0)).map (fun x => r * x) = volume.restrict (Ioi 0) := by + rw [← hp, ← Measure.restrict_map (by fun_prop) measurableSet_Ioi, + Real.map_volume_mul_left hr.ne', Measure.restrict_smul, smul_smul, + abs_of_pos (inv_pos.mpr hr), ← ENNReal.ofReal_mul hr.le, + mul_inv_cancel₀ hr.ne', ENNReal.ofReal_one, one_smul] + rw [hp] + conv_lhs => rw [← hm] + rw [lintegral_smul_measure, lintegral_map hf (by fun_prop)] + rfl + +lemma radial_lintegral_scale (n : ℕ) {c : ℝ} (hc : 0 < c) {f : ℝ → ℝ≥0∞} + (hf : Measurable f) : + ∫⁻ r in Ioi (0 : ℝ), ENNReal.ofReal (r ^ n) * f (c * r) = + ENNReal.ofReal ((c⁻¹) ^ (n + 1)) * + ∫⁻ r in Ioi (0 : ℝ), ENNReal.ofReal (r ^ n) * f r := by + rw [lintegral_Ioi_pos_mul (inv_pos.mpr hc) (by fun_prop)] + have he (r : ℝ) : ENNReal.ofReal ((c⁻¹ * r)^n) * f (c * (c⁻¹ * r)) = + ENNReal.ofReal ((c⁻¹)^n) * (ENNReal.ofReal (r^n) * f r) := by + rw [mul_pow, ENNReal.ofReal_mul (by positivity), ← mul_assoc, mul_inv_cancel₀ hc.ne', one_mul, + mul_assoc] + simp_rw [he] + rw [lintegral_const_mul _ (by fun_prop), ← mul_assoc, + ← ENNReal.ofReal_mul (by positivity)] + congr 2 + rw [pow_succ'] + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma gaussianPolarRadius_mass_integral [MeasurableSpace E] [BorelSpace E] : + gaussianPolarRadius E univ = + ∫⁻ r in Ioi (0 : ℝ), ENNReal.ofReal (r ^ (Module.finrank ℝ E - 1)) * + gaussianRadialDensity (Module.finrank ℝ E) r := by + rw [gaussianPolarRadius, withDensity_apply _ MeasurableSet.univ, + Measure.restrict_univ, Measure.volumeIoiPow] + rw [lintegral_withDensity_eq_lintegral_mul _ + (show Measurable (fun r : Ioi (0 : ℝ) => ENNReal.ofReal (r.1 ^ (Module.finrank ℝ E - 1))) by fun_prop) + (show Measurable (fun r : Ioi (0 : ℝ) => gaussianRadialDensity (Module.finrank ℝ E) r.1) by fun_prop)] + exact lintegral_subtype_comap (measurableSet_Ioi (a := (0 : ℝ))) + (fun r : ℝ => ENNReal.ofReal (r ^ (Module.finrank ℝ E - 1)) * + gaussianRadialDensity (Module.finrank ℝ E) r) + +omit [MeasurableSpace E] [BorelSpace E] in +lemma lintegral_gaussianPolarRadius [MeasurableSpace E] [BorelSpace E] + {g : ℝ → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ r : Ioi (0 : ℝ), g r.1 ∂gaussianPolarRadius E = + ∫⁻ r in Ioi (0 : ℝ), + ENNReal.ofReal (r ^ (Module.finrank ℝ E - 1)) * + gaussianRadialDensity (Module.finrank ℝ E) r * g r := by + rw [gaussianPolarRadius, lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop), + Measure.volumeIoiPow, lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] + simpa only [Pi.mul_apply, mul_assoc] using + lintegral_subtype_comap (μ := (volume : Measure ℝ)) (measurableSet_Ioi (a := (0 : ℝ))) + (fun r : ℝ => ENNReal.ofReal (r ^ (Module.finrank ℝ E - 1)) * + gaussianRadialDensity (Module.finrank ℝ E) r * g r) + +lemma gaussianRadialDensity_mul (n q : ℕ) (r s : ℝ) : + gaussianRadialDensity q r * gaussianRadialDensity n (r * s) = + ENNReal.ofReal ((2 * Real.pi) ^ (-((n + q : ℕ) : ℝ) / 2) * + Real.exp (-(1 + s^2) * r^2 / 2)) := by + unfold gaussianRadialDensity + rw [← ENNReal.ofReal_mul (by positivity)] + congr 1 + rw [mul_mul_mul_comm, ← Real.rpow_add (by positivity), ← Real.exp_add] + congr 1 <;> congr 1 <;> push_cast <;> ring + +lemma radial_power_gaussian_product {n q d : ℕ} (hq : 1 ≤ q) (hd : n + q = d) + {r : ℝ} (hr : 0 ≤ r) (s : ℝ) : + ENNReal.ofReal (r ^ (q - 1)) * gaussianRadialDensity q r * + (ENNReal.ofReal (r ^ n) * gaussianRadialDensity n (r * s)) = + ENNReal.ofReal (r ^ (d - 1)) * + ENNReal.ofReal ((2 * Real.pi) ^ (-(d : ℝ) / 2) * + Real.exp (-(1 + s^2) * r^2 / 2)) := by + rw [mul_mul_mul_comm, ← ENNReal.ofReal_mul (by positivity), ← pow_add, + gaussianRadialDensity_mul, hd] + have hn : q - 1 + n = d - 1 := by omega + rw [hn] + +lemma radial_gaussian_integral [Nontrivial E] {a : ℝ} (ha : 0 < a) : + ∫⁻ r in Ioi (0 : ℝ), ENNReal.ofReal (r ^ (Module.finrank ℝ E - 1)) * + ENNReal.ofReal ((2 * Real.pi) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2) * + Real.exp (-a * r^2 / 2)) = + ENNReal.ofReal (a ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2)) * + ((volume : Measure E).toSphere univ)⁻¹ := by + have he (r : ℝ) : ENNReal.ofReal ((2 * Real.pi) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2) * + Real.exp (-a * r^2 / 2)) = gaussianRadialDensity (Module.finrank ℝ E) (Real.sqrt a * r) := by + unfold gaussianRadialDensity + rw [mul_pow, Real.sq_sqrt ha.le] + ring_nf + simp_rw [he] + rw [radial_lintegral_scale _ (Real.sqrt_pos.mpr ha) (by fun_prop), + ← gaussianPolarRadius_mass_integral, gaussianPolarRadius_mass] + congr 2 + rw [Nat.sub_add_cancel Module.finrank_pos, Real.sqrt_eq_rpow, + ← Real.rpow_neg ha.le, ← Real.rpow_natCast, + ← Real.rpow_mul ha.le] + congr 1 + ring + +lemma sphere_area [Nontrivial E] : (volume : Measure E).toSphere univ = + ENNReal.ofReal (2 * Real.pi ^ (((Module.finrank ℝ E : ℕ) : ℝ) / 2) / + Real.Gamma (((Module.finrank ℝ E : ℕ) : ℝ) / 2)) := by + have hd : 0 < ((Module.finrank ℝ E : ℕ) : ℝ) := Nat.cast_pos.mpr Module.finrank_pos + have hp : Real.sqrt Real.pi ^ Module.finrank ℝ E = + Real.pi ^ (((Module.finrank ℝ E : ℕ) : ℝ) / 2) := by + rw [Real.sqrt_eq_rpow, ← Real.rpow_natCast, ← Real.rpow_mul Real.pi_pos.le] + congr 1 + ring + rw [Measure.toSphere_apply_univ, InnerProductSpace.volume_ball, ENNReal.ofReal_one, + one_pow, one_mul, ← ENNReal.ofReal_natCast, + ← ENNReal.ofReal_mul (by positivity), hp, Real.Gamma_add_one (by positivity)] + congr 1 + field_simp + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Gaussian/RandomComplement.lean b/lean/OAI/Probability/PosteriorReplicas/Gaussian/RandomComplement.lean new file mode 100644 index 0000000000000000000000000000000000000000..16a59d7bb50d4de34ad25405e7ea7e99c6f3db66 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Gaussian/RandomComplement.lean @@ -0,0 +1,87 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianLogMoment +import OAI.Probability.PosteriorReplicas.Geometry.BaseFunProp + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +@[fun_prop] lemma measurable_gramSchmidtNormed {n : ℕ} (i : Fin n) : + Measurable (fun v : Fin n → E => gramSchmidtNormed ℝ v i) := by + unfold gramSchmidtNormed + exact ((PosteriorRegression.measurable_gramSchmidt i).norm.inv).smul + (PosteriorRegression.measurable_gramSchmidt i) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma gramSchmidtNormed_mem [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {n : ℕ} (U : Submodule ℝ E) (v : Fin n → E) + (hv : ∀ i, v i ∈ U) (i : Fin n) : gramSchmidtNormed ℝ v i ∈ U := by + have hs : Submodule.span ℝ (range v) ≤ U := Submodule.span_le.mpr (by + rintro _ ⟨j,rfl⟩ + exact hv j) + apply hs + rw [← span_gramSchmidt ℝ v, ← span_gramSchmidtNormed_range] + exact Submodule.subset_span (mem_range_self i) + +lemma ae_gaussian_projected_columns_independent (U : Submodule ℝ E) (n : ℕ) + (hn : n ≤ Module.finrank ℝ U) : + ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => stdGaussian E), + LinearIndependent ℝ (fun i => U.starProjection (v i)) := by + have hmap : (Measure.pi (fun _ : Fin n => stdGaussian E)).map + (fun v i => U.orthogonalProjectionOnto (v i)) = Measure.pi (fun _ : Fin n => stdGaussian U) := by + rw [Measure.pi_map_pi (fun _ => by fun_prop)] + simp_rw [gaussian_orthogonalProjectionOnto] + have h := ae_gaussian_columns_independent (E := U) n hn + rw [← hmap] at h + have hz : ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => stdGaussian E), + LinearIndependent ℝ (fun i => U.orthogonalProjectionOnto (v i)) := + (ae_map_iff (f := fun v : Fin n → E => fun i => U.orthogonalProjectionOnto (v i)) + ((Measurable.of_eval (fun i => U.orthogonalProjectionOnto.continuous.measurable.comp + (measurable_pi_apply i))).aemeasurable) isOpen_setOfPred_linearIndependent.measurableSet).mp h + filter_upwards [hz] with v hv + exact hv.map' U.subtype (LinearMap.ker_eq_bot.mpr U.injective_subtype) + +def randomComplement {ℓ m k : ℕ} (V : Rows ℓ m) (e : Rows ℓ k) : Rows ℓ k := + gramSchmidtNormed ℝ (fun i => kernelComponent V (e i)) + +@[fun_prop] lemma measurable_randomComplement {ℓ m k : ℕ} : + Measurable (fun z : Rows ℓ m × Rows ℓ k => randomComplement z.1 z.2) := by + unfold randomComplement + apply Measurable.of_eval + intro i + exact (measurable_gramSchmidtNormed i).comp (by fun_prop) + +lemma randomComplement_orthogonal {ℓ m k : ℕ} {V : Rows ℓ m} + (hV : LinearIndependent ℝ V) (e : Rows ℓ k) (i : Fin k) (j : Fin m) : + ⟪randomComplement V e i, V j⟫ = 0 := by + apply (Submodule.mem_orthogonal' (Submodule.span ℝ (range V)) + (randomComplement V e i)).mp ?_ (V j) (Submodule.subset_span (mem_range_self j)) + unfold randomComplement + apply gramSchmidtNormed_mem + intro a + rw [kernelComponent_eq_starProjection hV] + exact Submodule.starProjection_apply_mem _ _ + +lemma ae_randomComplement_orthonormal {ℓ m k : ℕ} {V : Rows ℓ m} + (hV : LinearIndependent ℝ V) (hkm : k+m ≤ ℓ) : + ∀ᵐ e ∂gaussianRows ℓ k, Orthonormal ℝ (randomComplement V e) := by + let U := (Submodule.span ℝ (range V))ᗮ + have hdim : k ≤ Module.finrank ℝ U := by + have h := (Submodule.span ℝ (range V)).finrank_add_finrank_orthogonal + rw [finrank_euclideanSpace, finrank_span_eq_card hV, Fintype.card_fin] at h + simp only [Fintype.card_fin] at h + dsimp [U] + omega + filter_upwards [ae_gaussian_projected_columns_independent U k hdim] with e he + apply gramSchmidtNormed_orthonormal + simpa only [kernelComponent_eq_starProjection hV] using he + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/AffineMoments.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/AffineMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..3594863c2b433337f9aca4bd904da0f51530ee21 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/AffineMoments.lean @@ -0,0 +1,130 @@ +import OAI.Probability.PosteriorReplicas.Geometry.FrameTubes + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric EuclideanGeometry Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +section Generic +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma replica_integral_of_affine_moment {ν : Measure E} [IsFiniteMeasure ν] + (m n : ℕ) (p : E) (C : ℝ≥0∞) + (hmoment : ∀ L : AffineSubspace ℝ E, ∀ (_ : Nonempty L), + Module.finrank ℝ L.direction < n → + ∫⁻ x, ENNReal.ofReal ((Metric.infDist x L)⁻¹ ^ m) ∂ν ≤ C) : + ∫⁻ v : Fin n → E, PosteriorRegression.replicaWeight m p v ∂Measure.pi (fun _ => ν) ≤ C^n := by + induction n with + | zero => simp [PosteriorRegression.replicaWeight] + | succ n ih => + have hinner (v : Fin n → E) : + ∫⁻ x, PosteriorRegression.replicaWeight m p (Fin.snoc v x) ∂ν ≤ + PosteriorRegression.replicaWeight m p v * C := by + simp_rw [PosteriorRegression.replicaWeight_snoc] + rw [lintegral_const_mul _ (by fun_prop)] + gcongr + apply hmoment _ inferInstance + rw [AffineSubspace.direction_mk'] + have hdim := finrank_range_le_card (R := ℝ) (fun i : Fin n => v i - p) + simpa only [AffineSubspace.direction_mk', Fintype.card_fin, Nat.lt_succ_iff, Set.finrank] using hdim + calc + _ = ∫⁻ v : Fin n → E, ∫⁻ x, PosteriorRegression.replicaWeight m p (Fin.snoc v x) ∂ν + ∂Measure.pi (fun _ => ν) := PosteriorRegression.lintegral_pi_snoc ν _ + (PosteriorRegression.measurable_replicaWeight m p (n+1)) + _ ≤ ∫⁻ v : Fin n → E, PosteriorRegression.replicaWeight m p v * C + ∂Measure.pi (fun _ => ν) := lintegral_mono hinner + _ = (∫⁻ v : Fin n → E, PosteriorRegression.replicaWeight m p v + ∂Measure.pi (fun _ => ν)) * C := lintegral_mul_const _ + (PosteriorRegression.measurable_replicaWeight m p n) + _ ≤ C^n * C := mul_le_mul' (ih (fun L hL hdim => hmoment L hL (by omega))) le_rfl + _ = _ := (pow_succ _ _).symm + +lemma ae_replica_independent_of_affine_null {ν : Measure E} [IsFiniteMeasure ν] + (p : E) (n : ℕ) + (hnull : ∀ L : AffineSubspace ℝ E, ∀ (_ : Nonempty L), + Module.finrank ℝ L.direction < n → ν L = 0) : + ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => ν), LinearIndependent ℝ (fun j => v j - p) := by + suffices h : ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => ν), + ∀ i, gramSchmidt ℝ (fun j => v j - p) i ≠ 0 by + filter_upwards [h] with v hv + apply Matrix.linearIndependent_of_det_gram_ne_zero + rw [PosteriorRegression.det_gram_eq_prod_gramSchmidt] + exact Finset.prod_ne_zero_iff.mpr fun i _ => pow_ne_zero _ (norm_ne_zero_iff.mpr (hv i)) + induction n with + | zero => exact Filter.Eventually.of_forall fun _ i => Fin.elim0 i + | succ n ih => + rw [PosteriorRegression.ae_pi_snoc ν (PosteriorRegression.measurableSet_gramSchmidt_ne_zero p (n+1))] + filter_upwards [ih (fun L hL hdim => hnull L hL (by omega))] with v hv + let L := AffineSubspace.mk' p (Submodule.span ℝ (Set.range (fun i : Fin n => v i - p))) + have hdim : Module.finrank ℝ L.direction < n + 1 := by + dsimp only [L] + rw [AffineSubspace.direction_mk'] + have hh := finrank_range_le_card (R := ℝ) (fun i : Fin n => v i - p) + simpa only [Fintype.card_fin, Nat.lt_succ_iff, Set.finrank] using hh + have ha : ∀ᵐ x ∂ν, x ∉ L := by + rw [ae_iff] + simpa using hnull L inferInstance hdim + filter_upwards [ha] with x hx + intro i + induction i using Fin.lastCases with + | last => + apply norm_ne_zero_iff.mp + rw [PosteriorRegression.norm_gramSchmidt_sub_eq_affine_infDist, PosteriorRegression.image_Iio_last] + simp only [Fin.snoc_castSucc, Fin.snoc_last] + exact ne_of_gt ((L.closed_of_finiteDimensional.notMem_iff_infDist_pos + ⟨p, AffineSubspace.self_mem_mk' _ _⟩).mp hx) + | cast j => simpa only [PosteriorRegression.gramSchmidt_castSucc, Fin.snoc_castSucc] using hv j + +end Generic + +lemma base_affine_null {d : ℕ} (hd : 3 ≤ d) (base : BaseLaw) + (L : AffineSubspace ℝ (Vec d)) [Nonempty L] + (hL : Module.finrank ℝ L.direction < d) : (base.measure d) L = 0 := by + let C := ENNReal.ofReal (baseProjectionConstant base d 1) * 2 + have hC : C ≠ ∞ := ENNReal.mul_ne_top ENNReal.ofReal_ne_top (by norm_num) + have hb (n : ℕ) : (base.measure d) L ≤ C * ENNReal.ofReal ((1/2 : ℝ)^n) := by + calc + _ ≤ (base.measure d) {x | Metric.infDist x L ≤ (1/2 : ℝ)^n} := by + apply measure_mono + intro x hx + simp only [Set.mem_ofPred_eq, Metric.infDist_zero_of_mem hx] + positivity + _ ≤ _ := by simpa [C] using base_affine_tube hd base L (by omega) (r := (1/2 : ℝ)^n) (by positivity) + have hlim : Tendsto (fun n : ℕ => C * ENNReal.ofReal ((1/2 : ℝ)^n)) atTop (nhds 0) := by + have h := ENNReal.tendsto_ofReal + (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : (0 : ℝ) ≤ 1/2) (by norm_num : (1/2 : ℝ)<1)) + simpa using ENNReal.Tendsto.const_mul h (Or.inr hC) + exact le_antisymm (ge_of_tendsto' hlim hb) bot_le + +lemma base_affine_inverse_bound {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hm : 1 ≤ m) (base : BaseLaw) (L : AffineSubspace ℝ (Vec d)) [Nonempty L] + (hL : Module.finrank ℝ L.direction < m) : + ∫⁻ x, ENNReal.ofReal ((Metric.infDist x L)⁻¹ ^ k) ∂base.measure d ≤ + 1 + (ENNReal.ofReal (baseProjectionConstant base d (k+1)) * 2^(k+1)) * 2^(k+1) := by + let : NeZero d := ⟨by omega⟩ + have h := PosteriorRegression.inverse_moment_of_tube_bound (base.measure d) + (fun x => Metric.infDist x L) k (Metric.continuous_infDist_pt _).measurable + (fun _ => Metric.infDist_nonneg) + (ENNReal.ofReal (baseProjectionConstant base d (k+1)) * 2^(k+1)) + (fun r hr _ => base_affine_tube (by omega) base L (by omega) hr) + simpa only [measure_univ] using h + +lemma base_replica_inverse_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hm : 1 ≤ m) (base : BaseLaw) (p : Vec d) : + (∫⁻ v : Fin m → Vec d, ENNReal.ofReal + ((Real.sqrt (Matrix.gram ℝ (fun j => v j - p)).det)⁻¹ ^ k) + ∂Measure.pi (fun _ => base.measure d)) < ∞ := by + let : NeZero d := ⟨by omega⟩ + let C : ℝ≥0∞ := 1 + (ENNReal.ofReal (baseProjectionConstant base d (k+1)) * 2^(k+1)) * 2^(k+1) + have h := replica_integral_of_affine_moment k m p C + (fun L _ hL => base_affine_inverse_bound hd hm base L hL) + simp only [PosteriorRegression.replicaWeight_eq_det] at h + exact lt_of_le_of_lt h (by dsimp [C]; finiteness) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/BallJacobian.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/BallJacobian.lean new file mode 100644 index 0000000000000000000000000000000000000000..2ae6c6124e3e880e2d6970e90cb1e479037db00d --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/BallJacobian.lean @@ -0,0 +1,142 @@ +import Mathlib + +namespace OAI + +open MeasureTheory Set Matrix InnerProductSpace Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +section Determinant +variable {E : Type*} [AddCommGroup E] [Module ℝ E] [FiniteDimensional ℝ E] + +lemma det_id_add_smulRight (φ : E →ₗ[ℝ] ℝ) (v : E) : + (LinearMap.id + φ.smulRight v).det = 1 + φ v := by + classical + let b := Module.finBasis ℝ E + rw [← LinearMap.det_toMatrix b, map_add, LinearMap.toMatrix_id, LinearMap.toMatrix_smulRight] + have he : Matrix.vecMulVec (fun i => b.repr v i) (fun i => φ (b i)) = + Matrix.replicateCol Unit (fun i => b.repr v i) * + Matrix.replicateRow Unit (fun i => φ (b i)) := by + ext i j + simp [Matrix.mul_apply, Matrix.vecMulVec] + change (1 + Matrix.vecMulVec (fun i => b.repr v i) (fun i => φ (b i))).det = _ + rw [he, Matrix.det_one_add_replicateCol_mul_replicateRow] + congr 1 + have hφ := congrArg φ (b.sum_repr v) + simpa only [dotProduct, map_sum, map_smul, smul_eq_mul, mul_comm] using hφ + +end Determinant + +section Ball +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + +def ballStretch (x : E) : E := (1 - ‖x‖^2) ^ (-(1 : ℝ) / 2) • x + +def ballStretchDeriv (x : E) : E →L[ℝ] E := + (1 - ‖x‖^2) ^ (-(1 : ℝ) / 2) • + (ContinuousLinearMap.id ℝ E + + (1 - ‖x‖^2)⁻¹ • ((innerSL ℝ x).smulRight x)) + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] in +lemma one_sub_norm_sq_pos {x : E} (hx : x ∈ ball (0 : E) 1) : 0 < 1 - ‖x‖^2 := by + have h := mem_ball_zero_iff.mp hx + nlinarith [norm_nonneg x] + +omit [FiniteDimensional ℝ E] in +lemma ballStretch_eq : EqOn (ballStretch : E → E) + OpenPartialHomeomorph.univUnitBall.symm (ball 0 1) := by + intro x hx + rw [ballStretch, OpenPartialHomeomorph.univUnitBall_symm_apply, + neg_div, Real.rpow_neg (one_sub_norm_sq_pos hx).le, Real.sqrt_eq_rpow] + +omit [FiniteDimensional ℝ E] in +lemma hasFDerivAt_ballStretch {x : E} (hx : x ∈ ball (0 : E) 1) : + HasFDerivAt ballStretch (ballStretchDeriv x) x := by + have hb := one_sub_norm_sq_pos hx + have h := (((hasFDerivAt_id x).norm_sq.const_sub 1).rpow_const + (p := -(1 : ℝ) / 2) (Or.inl hb.ne')).smul (hasFDerivAt_id x) + apply h.congr_fderiv + ext y + simp only [ballStretchDeriv, _root_.smul_apply, _root_.add_apply, + ContinuousLinearMap.id_apply, ContinuousLinearMap.smulRight_apply, + _root_.neg_apply, ContinuousLinearMap.comp_apply, innerSL_apply_apply, id_eq] + rw [Real.rpow_sub hb, Real.rpow_one] + module + +lemma det_ballStretchDeriv {x : E} (hx : x ∈ ball (0 : E) 1) : + (ballStretchDeriv x).det = + (1 - ‖x‖^2) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2 - 1) := by + have hb := one_sub_norm_sq_pos hx + change ((ballStretchDeriv x).toLinearMap).det = _ + have he : (ballStretchDeriv x).toLinearMap = + (1 - ‖x‖^2) ^ (-(1 : ℝ) / 2) • (LinearMap.id + + (((1 - ‖x‖^2)⁻¹ • innerSL ℝ x).toLinearMap).smulRight x) := by + ext y + simp [ballStretchDeriv, smul_smul, mul_assoc] + rw [he, LinearMap.det_smul, det_id_add_smulRight] + have hi : 1 + (((1 - ‖x‖^2)⁻¹ • innerSL ℝ x).toLinearMap) x = (1 - ‖x‖^2)⁻¹ := by + simp only [ContinuousLinearMap.coe_coe, _root_.smul_apply, + innerSL_apply_apply, real_inner_self_eq_norm_sq, smul_eq_mul] + field_simp + ring + rw [hi, ← Real.rpow_natCast, ← Real.rpow_mul hb.le, + ← Real.rpow_neg_one, ← Real.rpow_add hb] + congr 1 + ring + +@[fun_prop] lemma measurable_ballStretch [MeasurableSpace E] [BorelSpace E] : + Measurable (ballStretch : E → E) := by + unfold ballStretch + fun_prop + +omit [FiniteDimensional ℝ E] in +lemma ballStretch_eq_inv_sqrt {x : E} (hx : x ∈ ball (0 : E) 1) : + ballStretch x = (Real.sqrt (1 - ‖x‖^2))⁻¹ • x := by + rw [ballStretch, neg_div, Real.rpow_neg (one_sub_norm_sq_pos hx).le, Real.sqrt_eq_rpow] + +omit [FiniteDimensional ℝ E] in +lemma one_add_norm_ballStretch_sq {x : E} (hx : x ∈ ball (0 : E) 1) : + 1 + ‖ballStretch x‖^2 = (1 - ‖x‖^2)⁻¹ := by + have hb := one_sub_norm_sq_pos hx + rw [ballStretch_eq_inv_sqrt hx, norm_smul, Real.norm_eq_abs, + abs_of_pos (inv_pos.mpr (Real.sqrt_pos.mpr hb)), mul_pow, inv_pow, Real.sq_sqrt hb.le] + field_simp + ring + +omit [FiniteDimensional ℝ E] in +lemma ballStretch_weight {x : E} (hx : x ∈ ball (0 : E) 1) (q : ℕ) : + ENNReal.ofReal ((1 - ‖x‖^2) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2 - 1)) * + ENNReal.ofReal ((1 + ‖ballStretch x‖^2) ^ + (-((Module.finrank ℝ E + q : ℕ) : ℝ) / 2)) = + ENNReal.ofReal ((1 - ‖x‖^2) ^ (((q : ℝ) - 2) / 2)) := by + have hb := one_sub_norm_sq_pos hx + rw [← ENNReal.ofReal_mul (by positivity), one_add_norm_ballStretch_sq hx, + Real.inv_rpow hb.le, ← Real.rpow_neg hb.le, ← Real.rpow_add hb] + congr 2 + push_cast + ring + +lemma lintegral_ballStretch [MeasurableSpace E] [BorelSpace E] (g : E → ℝ≥0∞) : + ∫⁻ x, g x = ∫⁻ y in ball (0 : E) 1, + ENNReal.ofReal ((1 - ‖y‖^2) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2 - 1)) * + g (ballStretch y) := by + have hi : InjOn (ballStretch : E → E) (ball 0 1) := by + exact OpenPartialHomeomorph.univUnitBall.symm.injOn.congr ballStretch_eq.symm + have he : (ballStretch : E → E) '' ball 0 1 = univ := by + rw [ballStretch_eq.image_eq] + exact OpenPartialHomeomorph.univUnitBall.symm.image_source_eq_target + conv_lhs => rw [← Measure.restrict_univ (μ := (volume : Measure E)), ← he] + rw [lintegral_image_eq_lintegral_abs_det_fderiv_mul volume measurableSet_ball + (fun x hx => (hasFDerivAt_ballStretch hx).hasFDerivWithinAt) hi g] + apply setLIntegral_congr_fun measurableSet_ball + intro x hx + dsimp only + rw [det_ballStretchDeriv hx, abs_of_pos (Real.rpow_pos_of_pos (one_sub_norm_sq_pos hx) _)] + +end Ball +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseContinuity.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..804f08b868ae769eb5aa22f9e44529546460d881 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseContinuity.lean @@ -0,0 +1,83 @@ +import OAI.Probability.PosteriorReplicas.Geometry.FrameTubes + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +@[fun_prop] lemma continuous_basePoint_label {d k : ℕ} (base : BaseLaw) + (A : Rows d k) (x : Vec d) : Continuous (fun y => basePoint base A y x) := by + cases base <;> unfold basePoint <;> fun_prop + +lemma baseDensity_sphere_clipped {d k : ℕ} (hk : k + 2 < d) {A : Rows d k} + (hA : LinearIndependent ℝ A) (y : Labels k) : + baseDensity .spherical A y = ENNReal.ofReal + (baseProjectionConstant .spherical d k * + (max (1 - ‖liftLabel A y‖^2) 0) ^ (((d : ℝ) - k - 2) / 2) / + Real.sqrt (rowGram A).det) := by + have hβ : 0 < ((d : ℝ) - k - 2) / 2 := by + have : (k : ℝ) + 2 < d := by exact_mod_cast hk + linarith + rw [baseDensity.eq_def, ite_eq_left hA] + dsimp only [baseProjectionConstant] + by_cases hy : ‖liftLabel A y‖ < 1 + · rw [ite_eq_left hy, max_eq_left (by nlinarith [norm_nonneg (liftLabel A y)])] + · rw [ite_eq_right hy, max_eq_right (by nlinarith [le_of_not_gt hy]), + Real.zero_rpow hβ.ne', mul_zero, zero_div, ENNReal.ofReal_zero] + +lemma continuous_baseDensity {d k : ℕ} (hk : k + 2 < d) (base : BaseLaw) + {A : Rows d k} (hA : LinearIndependent ℝ A) : Continuous (baseDensity base A) := by + cases base + · have hβ : 0 ≤ ((d : ℝ) - k - 2) / 2 := by + have : (k : ℝ) + 2 < d := by exact_mod_cast hk + linarith + have he : baseDensity .spherical A = fun y => ENNReal.ofReal + (baseProjectionConstant .spherical d k * + (max (1 - ‖liftLabel A y‖^2) 0) ^ (((d : ℝ) - k - 2) / 2) / + Real.sqrt (rowGram A).det) := funext (baseDensity_sphere_clipped hk hA) + rw [he] + apply ENNReal.continuous_ofReal.comp + apply Continuous.div_const + apply Continuous.const_mul + exact (Real.continuous_rpow_const hβ).comp (by fun_prop) + · have he : baseDensity .gaussian A = fun y => ENNReal.ofReal + ((2 * Real.pi) ^ (-(k : ℝ) / 2) * + Real.exp (-‖liftLabel A y‖^2 / 2) / Real.sqrt (rowGram A).det) := by + funext y + rw [baseDensity.eq_def, ite_eq_left hA] + rw [he] + exact ENNReal.continuous_ofReal.comp (by fun_prop) + +lemma base_sample_representation {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (hk : k < d) (base : BaseLaw) : + ((volume.withDensity (baseDensity base A)).prod (stdGaussian (Vec d))).map + (fun z => basePoint base A z.1 z.2) = base.measure d := by + have : NeZero d := ⟨by omega⟩ + have hb0 := (measurable_baseDensity (d := d) (k := k) base).comp + (show Measurable (fun y : Labels k => (A,y)) from measurable_const.prodMk measurable_id) + simp only [Function.comp_def] at hb0 + have hb : Measurable (baseDensity base A) := hb0 + have hm : Measurable (fun z : Labels k × Vec d => basePoint base A z.1 z.2) := by + have h := (measurable_basePoint (d := d) (k := k) base).comp + (show Measurable (fun z : Labels k × Vec d => ((A,z.1),z.2)) from + (measurable_const.prodMk measurable_fst).prodMk measurable_snd) + exact h + have : IsProbabilityMeasure (volume.withDensity (baseDensity base A)) := by + rw [← projected_base_measure hA hk] + infer_instance + apply Measure.ext_of_lintegral + intro g hg + have hgm : Measurable (fun z : Labels k × Vec d => g (basePoint base A z.1 z.2)) := hg.comp hm + rw [lintegral_map hg hm, lintegral_prod _ hgm.aemeasurable, + lintegral_withDensity_eq_lintegral_mul _ hb (by fun_prop), base_lintegral hA hk base hg] + apply lintegral_congr + intro y + simp only [Pi.mul_apply] + rw [baseFiber_eq_map, lintegral_map hg (measurable_basePoint_fixed base A y)] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseFunProp.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseFunProp.lean new file mode 100644 index 0000000000000000000000000000000000000000..df69be1d2620ebcad194c9309aae29bfcf017a44 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseFunProp.lean @@ -0,0 +1,40 @@ +import OAI.Probability.PosteriorReplicas.Measures.BaseDisintegration + +namespace OAI + +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +namespace PosteriorReplicas + +@[fun_prop] lemma measurable_basePoint_comp {X : Type*} [MeasurableSpace X] + {d k : ℕ} (base : BaseLaw) {A : X → Rows d k} {y : X → Labels k} {x : X → Vec d} + (hA : Measurable A) (hy : Measurable y) (hx : Measurable x) : + Measurable (fun z => basePoint base (A z) (y z) (x z)) := by + have h := (measurable_basePoint (d := d) (k := k) base).comp ((hA.prodMk hy).prodMk hx) + exact h + +@[fun_prop] lemma measurable_baseDensity_comp {X : Type*} [MeasurableSpace X] + {d k : ℕ} (base : BaseLaw) {A : X → Rows d k} {y : X → Labels k} + (hA : Measurable A) (hy : Measurable y) : + Measurable (fun z => baseDensity base (A z) (y z)) := by + have h := (measurable_baseDensity (d := d) (k := k) base).comp (hA.prodMk hy) + exact h + +@[fun_prop] lemma measurable_kernelComponent_comp {X : Type*} [MeasurableSpace X] + {d k : ℕ} {A : X → Rows d k} {x : X → Vec d} + (hA : Measurable A) (hx : Measurable x) : + Measurable (fun z => kernelComponent (A z) (x z)) := by + have h := (measurable_kernelComponent (d := d) (k := k)).comp (hA.prodMk hx) + exact h + +@[fun_prop] lemma measurable_labels_comp {X : Type*} [MeasurableSpace X] + {d k : ℕ} {A : X → Rows d k} {x : X → Vec d} + (hA : Measurable A) (hx : Measurable x) : + Measurable (fun z => labels (A z) (x z)) := by + have h := (measurable_labels (d := d) (k := k)).comp (hA.prodMk hx) + exact h +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseGeometry.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..fc86be758efcb21ae7b53948882d8ecd52d4c335 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/BaseGeometry.lean @@ -0,0 +1,127 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianFiber + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +instance matrixRealMeasurableSpace (m n : Type*) : MeasurableSpace (Matrix m n ℝ) := + inferInstanceAs (MeasurableSpace (m → n → ℝ)) + +instance matrixRealBorelSpace (m n : Type*) [Countable m] [Countable n] : + BorelSpace (Matrix m n ℝ) := inferInstanceAs (BorelSpace (m → n → ℝ)) + +attribute [fun_prop] measurable_labels + +@[fun_prop] lemma measurable_matrix_inv_real (n : ℕ) : + Measurable (fun M : Matrix (Fin n) (Fin n) ℝ => M⁻¹) := by + simp_rw [Matrix.inv_def, Ring.inverse_eq_inv] + exact continuous_id.matrix_det.measurable.inv.smul continuous_id.matrix_adjugate.measurable + +@[fun_prop] lemma continuous_rowGram {d k : ℕ} : Continuous (@rowGram d k) := by + unfold rowGram + fun_prop + +@[fun_prop] lemma measurable_liftLabel {d k : ℕ} : + Measurable (fun z : Rows d k × Labels k => liftLabel z.1 z.2) := by + unfold liftLabel Matrix.mulVec dotProduct + fun_prop + +@[fun_prop] lemma continuous_liftLabel {d k : ℕ} (A : Rows d k) : + Continuous (liftLabel A) := continuous_pairingLift A + +@[fun_prop] lemma measurable_kernelComponent {d k : ℕ} : + Measurable (fun z : Rows d k × Vec d => kernelComponent z.1 z.2) := by + unfold kernelComponent + fun_prop + +lemma liftLabel_eq_pairingLift {d k : ℕ} (A : Rows d k) : liftLabel A = pairingLift A := rfl +lemma rowGram_eq_gram {d k : ℕ} (A : Rows d k) : rowGram A = Matrix.gram ℝ A := rfl + +lemma kernelComponent_eq_starProjection {d k : ℕ} {A : Rows d k} + (hA : LinearIndependent ℝ A) (x : Vec d) : + kernelComponent A x = (Submodule.span ℝ (Set.range A))ᗮ.starProjection x := by + rw [Submodule.starProjection_orthogonal_val, starProjection_eq_pairingLift hA] + rfl + +lemma labels_liftLabel {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) (y : Labels k) : + labels A (liftLabel A y) = y := pairings_pairingLift hA y + +lemma labels_kernelComponent {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) (x : Vec d) : + labels A (kernelComponent A x) = 0 := by + unfold kernelComponent + ext i + change ⟪A i, x - liftLabel A (labels A x)⟫ = 0 + rw [inner_sub_right] + change labels A x i - labels A (liftLabel A (labels A x)) i = 0 + rw [labels_liftLabel hA, sub_self] + +def basePoint {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) (x : Vec d) : Vec d := + match base with + | .gaussian => liftLabel A y + kernelComponent A x + | .spherical => liftLabel A y + + (Real.sqrt (1 - ‖liftLabel A y‖ ^ 2) / ‖kernelComponent A x‖) • kernelComponent A x + +@[fun_prop] lemma measurable_basePoint {d k : ℕ} (base : BaseLaw) : + Measurable (fun z : (Rows d k × Labels k) × Vec d => basePoint base z.1.1 z.1.2 z.2) := by + cases base <;> unfold basePoint <;> fun_prop + +lemma baseFiber_eq_map {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) : + baseFiber base A y = (stdGaussian (Vec d)).map (basePoint base A y) := by + cases base <;> rfl + +@[fun_prop] lemma measurable_basePoint_fixed {d k : ℕ} (base : BaseLaw) + (A : Rows d k) (y : Labels k) : Measurable (basePoint base A y) := by + have h := (measurable_basePoint (d := d) (k := k) base).comp + (show Measurable (fun x : Vec d => ((A, y), x)) from measurable_const.prodMk measurable_id) + exact h + +instance {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) : + IsProbabilityMeasure (baseFiber base A y) := by + rw [baseFiber_eq_map] + infer_instance + +lemma labels_basePoint {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (base : BaseLaw) (y : Labels k) (x : Vec d) : labels A (basePoint base A y x) = y := by + have h₁ := labels_liftLabel hA y + have h₂ := labels_kernelComponent hA x + cases base <;> ext i <;> + simp only [basePoint, labels, inner_add_right, inner_smul_right, + show ⟪A i, liftLabel A y⟫ = y i from congrFun h₁ i, + show ⟪A i, kernelComponent A x⟫ = 0 from congrFun h₂ i, mul_zero, add_zero] + +lemma measurable_parametric_map {Z X Y : Type*} [MeasurableSpace Z] [MeasurableSpace X] + [MeasurableSpace Y] (μ : Measure X) [SFinite μ] {F : Z × X → Y} (hF : Measurable F) : + Measurable (fun z => μ.map (fun x => F (z, x))) := by + apply Measure.measurable_of_measurable_coe + intro s hs + have he : (fun z => μ.map (fun x => F (z, x)) s) = + (fun z => μ ((Prod.mk z) ⁻¹' (F ⁻¹' s))) := by + funext z + exact Measure.map_apply (hF.comp (measurable_const.prodMk measurable_id)) hs + rw [he] + exact measurable_measure_prodMk_left (hF hs) + +@[fun_prop] lemma measurable_baseFiber {d k : ℕ} (base : BaseLaw) : + Measurable (fun z : Rows d k × Labels k => baseFiber base z.1 z.2) := by + simp_rw [baseFiber_eq_map] + exact measurable_parametric_map _ (measurable_basePoint base) + +def baseKernel {d k : ℕ} (base : BaseLaw) : Kernel (Rows d k × Labels k) (Vec d) where + toFun z := baseFiber base z.1 z.2 + measurable' := measurable_baseFiber base + +instance {d k : ℕ} (base : BaseLaw) : IsMarkovKernel (@baseKernel d k base) where + isProbabilityMeasure _ := by dsimp [baseKernel]; infer_instance + +@[fun_prop] lemma measurable_tiltMass {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) : Measurable (fun z : Rows d k × Labels k => tiltMass base f z.1 z.2) := by + unfold tiltMass + exact hf.lintegral_kernel (κ := baseKernel base) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/DensityBinEnvelope.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/DensityBinEnvelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..fd4c44ec8cddd86108b7d8fc9947a1cb87cd8eae --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/DensityBinEnvelope.lean @@ -0,0 +1,128 @@ +import OAI.Probability.PosteriorReplicas.Geometry.DensityBinsGeometry +import OAI.Probability.PosteriorReplicas.Geometry.LabelConvolution +import OAI.Probability.PosteriorReplicas.Measures.ReferenceMoments + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +def expectedDensity {d k m : ℕ} (f : Vec d → ℝ≥0∞) (u : Tuple d m) : ℝ≥0∞ := + ∫⁻ A, projectedDensity .spherical f (residualRows u A) + (labels (residualRows u A) (u 0)) ∂gaussianRows d k + +@[fun_prop] lemma measurable_expectedDensity {d k m : ℕ} {f : Vec d → ℝ≥0∞} + (hf : Measurable f) : Measurable (@expectedDensity d k m f) := by + unfold expectedDensity + fun_prop + +def binEnvelope {d k : ℕ} (ν : Measure (Vec d)) (J : ℕ) (A : Rows d k) (y : Labels k) : ℝ≥0∞ := + 2 + ∑ j ∈ Finset.range J, ENNReal.ofReal ((2:ℝ)^(k*(j+1))) * ellipsoidMass ν A y ((1/2:ℝ)^j) + +@[fun_prop] lemma measurable_binEnvelope {d k : ℕ} (ν : Measure (Vec d)) [SFinite ν] (J : ℕ) : + Measurable (fun z : Data d k => binEnvelope ν J z.1 z.2) := by + unfold binEnvelope + fun_prop + +lemma ae_expectedDensity_le_inverse {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + ∀ᵐ u : Tuple d m ∂Measure.pi (fun _ => (sphereLaw d).withDensity f), + expectedDensity (k := k) f u ≤ ∫⁻ x, ENNReal.ofReal ((tupleDistance u x)⁻¹^k) + ∂(sphereLaw d).withDensity f := by + let : NeZero d := ⟨by omega⟩ + have : IsProbabilityMeasure (sphereLaw d) := by + change IsProbabilityMeasure (BaseLaw.spherical.measure d); infer_instance + have := bounded_withDensity_finite (sphereLaw d) hLt hfL + have h := (equalLabelVersions d k m hk hm (by omega) .spherical f hf ⟨L,hLt,hfL⟩).2.2.2.2 + filter_upwards [h] with u hu + have hu' : LinearIndependent ℝ (differences u) := hu.1 + have he : (fun A : Rows d k => residualRows u A) = + fun A i => (differenceSpan u)ᗮ.starProjection (A i) := by + funext A i + exact kernelComponent_eq_starProjection hu' _ + have hv : (fun A : Rows d k => projectedDensity .spherical f A (labels A (u 0))) =ᵐ[constrainedRows k u] + (fun A => ballDensityVersion ((sphereLaw d).withDensity f) A (labels A (u 0))) := by + filter_upwards [hu.2] with A hA + exact hA.2.2.2.2.2.1 + rw [constrainedRows_eq_residualRows hu'] at hv + have hv' := (ae_map_iff (show Measurable (residualRows u) by fun_prop).aemeasurable + (measurableSet_eq_fun (by unfold labels; fun_prop) (by unfold labels; fun_prop))).mp hv + unfold expectedDensity + rw [lintegral_congr_ae hv'] + simp_rw [he] + apply expected_ballDensityVersion_le _ _ _ + filter_upwards [tupleDistance_pos_ae (by omega) (by omega) u f] with x hx + exact norm_ne_zero_iff.mp (ne_of_gt hx) + +lemma ae_constrainedRows_mem {d k m : ℕ} (u : Tuple d m) : + ∀ᵐ A ∂constrainedRows k u, ∀ i, A i ∈ (differenceSpan u)ᗮ := by + unfold constrainedRows + have hp : MeasurableSet {A : Rows d k | ∀ i, A i ∈ (differenceSpan u)ᗮ} := by + rw [Set.ofPred_forall] + exact MeasurableSet.iInter (fun i => (differenceSpan u)ᗮ.closed_of_finiteDimensional.measurableSet.preimage (measurable_pi_apply i)) + exact (ae_map_iff (show AEMeasurable (fun A : Rows d k => fun i => + (differenceSpan u)ᗮ.starProjection (A i)) _ from + (Measurable.of_eval (fun i => (differenceSpan u)ᗮ.starProjection.continuous.measurable.comp (measurable_pi_apply i))).aemeasurable) hp).mpr + (ae_of_all _ (fun A i => Submodule.starProjection_apply_mem _ _)) + +lemma ae_equalReference_bin_bound {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] (J : ℕ) + (hcut : (L*ENNReal.ofReal ((72:ℝ)^d))*ENNReal.ofReal ((1/2:ℝ)^J)* + (1+(2:ℝ≥0∞)^(k+1)) ≤ 1) : + ∀ᵐ z : EqualSpace d k m ∂equalReference ((sphereLaw d).withDensity f), + expectedDensity (k := k) f z.2.2 ≤ binEnvelope ((sphereLaw d).withDensity f) J z.1 z.2.1 := by + apply ae_equalReference_of_constrained (by omega) (by omega) .spherical hf hLt hfL + (measurableSet_le (by fun_prop) (by fun_prop)) + filter_upwards [ae_expectedDensity_le_inverse hd hk hm hf hLt hfL, + ae_constrained_support hd hk hm .spherical hf hLt hfL] with u hu hs + filter_upwards [hs.2, ae_constrainedRows_mem (k := k) u] with A hA hU + exact hu.trans (density_inverse_moment_bins hd u hfL J hcut hA.1 hU) + +lemma binTerm_volume {k : ℕ} (j : ℕ) : + ENNReal.ofReal ((2:ℝ)^(k*(j+1))) * volume {y : Labels k | labelNorm y ≤ (1/2:ℝ)^j} = + (2:ℝ≥0∞)^k * volume {y : Labels k | labelNorm y ≤ 1} := by + rw [label_closedBall_scale (by positivity), ← mul_assoc, ← ENNReal.ofReal_mul (by positivity)] + have he : (2:ℝ)^(k*(j+1)) * ((1/2:ℝ)^j)^k = (2:ℝ)^k := by + rw [Nat.mul_comm k (j+1), pow_mul, ← mul_pow] + congr 1 + rw [pow_succ, div_pow, one_pow, div_eq_mul_inv] + field_simp + rw [he, ENNReal.ofReal_pow (by norm_num)] + norm_num + +lemma normalized_binEnvelope_integral_le {d k : ℕ} {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] + {A : Rows d k} (hA : LinearIndependent ℝ A) (J : ℕ) : + (∫⁻ y, (projectedDensity .spherical f A y)⁻¹ * binEnvelope ((sphereLaw d).withDensity f) J A y + ∂volume.withDensity (projectedDensity .spherical f A)) ≤ + ENNReal.ofReal (gramVolume A) * volume {y : Labels k | labelNorm y ≤ 1} * + (2+(J:ℝ≥0∞)*2^k) := by + simp only [binEnvelope, mul_add, Finset.mul_sum] + rw [lintegral_add_left (by fun_prop), lintegral_mul_const _ (by fun_prop), + normalized_inverse_density_integral _ (by fun_prop) (projectedDensity_ne_top .spherical hLt hfL A), + lintegral_finsetSum _ (fun j _ => by fun_prop)] + calc + _ ≤ (ENNReal.ofReal (gramVolume A) * volume {y : Labels k | labelNorm y ≤ 1}) * 2 + + ∑ j ∈ Finset.range J, ENNReal.ofReal ((2:ℝ)^(k*(j+1))) * + (ENNReal.ofReal (gramVolume A) * volume {y : Labels k | labelNorm y ≤ (1/2:ℝ)^j}) := by + apply add_le_add + · exact mul_le_mul' (projectedDensity_support_volume hA f) le_rfl + · apply Finset.sum_le_sum + intro j hj + simp only [← Nat.mul_add] + simp_rw [mul_left_comm ((projectedDensity .spherical f A _)⁻¹) (ENNReal.ofReal ((2:ℝ)^(k*(j+1))))] + rw [lintegral_const_mul _ (by fun_prop)] + exact mul_le_mul' le_rfl (normalized_ellipsoidMass_integral_le hf hLt hfL hA _) + _ = _ := by + simp_rw [mul_left_comm _ (ENNReal.ofReal (gramVolume A)), binTerm_volume] + simp only [Finset.sum_const, Finset.card_range, nsmul_eq_mul] + ring + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/DensityBinsGeometry.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/DensityBinsGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..0241207949d5d5fd2d5321d234550e097448854e --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/DensityBinsGeometry.lean @@ -0,0 +1,110 @@ +import OAI.Probability.PosteriorReplicas.Geometry.LabelEllipsoids + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma affine_infDist_orthogonal {d : ℕ} (p x : Vec d) (U : Submodule ℝ (Vec d)) : + Metric.infDist x (AffineSubspace.mk' p U : Set (Vec d)) = ‖Uᗮ.starProjection (x-p)‖ := by + rw [PosteriorRegression.infDist_affine_mk', Submodule.starProjection_orthogonal_val, + Submodule.starProjection_minimal, Metric.infDist_eq_iInf] + simp only [dist_eq_norm] + rfl + +def tupleDistance {d m : ℕ} (u : Tuple d m) (x : Vec d) : ℝ := + ‖(differenceSpan u)ᗮ.starProjection (x-u 0)‖ + +lemma tupleDistance_eq_infDist {d m : ℕ} (u : Tuple d m) (x : Vec d) : + tupleDistance u x = Metric.infDist x (AffineSubspace.mk' (u 0) (differenceSpan u) : Set (Vec d)) := + (affine_infDist_orthogonal _ _ _).symm + +@[fun_prop] lemma measurable_tupleDistance_fixed {d m : ℕ} (u : Tuple d m) : + Measurable (tupleDistance u) := by unfold tupleDistance; fun_prop + +lemma differenceSpan_finrank_le {d m : ℕ} (u : Tuple d m) : + Module.finrank ℝ (differenceSpan u) ≤ m := by + change Module.finrank ℝ (Submodule.span ℝ (range (differences u))) ≤ m + simpa only [Set.finrank, Fintype.card_fin] using + finrank_range_le_card (R := ℝ) (differences u) + +lemma tupleDistance_tube {d k m : ℕ} (hd : k+m+2 ≤ d) (u : Tuple d m) + {f : Vec d → ℝ≥0∞} {L : ℝ≥0∞} (hfL : ∀ x, f x ≤ L) + {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) : + (sphereLaw d).withDensity f {x | tupleDistance u x ≤ r} ≤ + (L*ENNReal.ofReal ((72:ℝ)^d))*ENNReal.ofReal (r^(k+1)) := by + let : NeZero d := ⟨by omega⟩ + simp_rw [tupleDistance_eq_infDist] + apply spherical_tilt_affine_tube hfL _ _ hr hr1 + rw [AffineSubspace.direction_mk'] + have h := differenceSpan_finrank_le u + omega + +lemma tupleDistance_pos_ae {d m : ℕ} (hd : 3 ≤ d) (hm : m < d) (u : Tuple d m) + (f : Vec d → ℝ≥0∞) : + ∀ᵐ x ∂(sphereLaw d).withDensity f, 0 < tupleDistance u x := by + let S := AffineSubspace.mk' (u 0) (differenceSpan u) + have hz : sphereLaw d S = 0 := by + apply base_affine_null hd .spherical S + rw [AffineSubspace.direction_mk'] + exact (differenceSpan_finrank_le u).trans_lt hm + have hn : ∀ᵐ x ∂sphereLaw d, x ∉ S := by + rw [ae_iff] + simp only [not_not] + convert hz using 2 + ext x + rfl + filter_upwards [(withDensity_absolutelyContinuous (sphereLaw d) f).ae_le hn] with x hx + rw [tupleDistance_eq_infDist] + exact (S.closed_of_finiteDimensional.notMem_iff_infDist_pos + ⟨u 0, AffineSubspace.self_mem_mk' _ _⟩).mp hx + +lemma labels_sub {d k : ℕ} (A : Rows d k) (x y : Vec d) : + labels A (x-y) = labels A x - labels A y := by + ext i + simp [labels, inner_sub_right] + +lemma constrained_label_lift_le {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (U : Submodule ℝ (Vec d)) (hU : ∀ i, A i ∈ Uᗮ) (p x : Vec d) : + ‖liftLabel A (labels A x - labels A p)‖ ≤ ‖Uᗮ.starProjection (x-p)‖ := by + have he : labels A (Uᗮ.starProjection (x-p)) = labels A (x-p) := by + ext i + change ⟪A i,Uᗮ.starProjection (x-p)⟫ = ⟪A i,x-p⟫ + rw [← Uᗮ.inner_starProjection_left_eq_right, + Uᗮ.starProjection_eq_self_iff.mpr (hU i)] + rw [← labels_sub, ← he, liftLabel_eq_pairingLift] + change ‖pairingLift A (fun i => ⟪A i,Uᗮ.starProjection (x-p)⟫)‖ ≤ _ + rw [← starProjection_eq_pairingLift hA] + exact Submodule.norm_starProjection_apply_le _ _ + +lemma constrained_tube_le_ellipsoid {d k m : ℕ} (ν : Measure (Vec d)) + (u : Tuple d m) {A : Rows d k} (hA : LinearIndependent ℝ A) + (hU : ∀ i, A i ∈ (differenceSpan u)ᗮ) (r : ℝ) : + ν {x | tupleDistance u x ≤ r} ≤ + ν {x | ‖liftLabel A (labels A x - labels A (u 0))‖ ≤ r} := by + apply measure_mono + intro x hx + exact (constrained_label_lift_le hA _ hU _ _).trans hx + +lemma density_inverse_moment_bins {d k m : ℕ} (hd : k+m+2 ≤ d) + (u : Tuple d m) {f : Vec d → ℝ≥0∞} {L : ℝ≥0∞} (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] (J : ℕ) + (hcut : (L*ENNReal.ofReal ((72:ℝ)^d))*ENNReal.ofReal ((1/2:ℝ)^J)* + (1+(2:ℝ≥0∞)^(k+1)) ≤ 1) + {A : Rows d k} (hA : LinearIndependent ℝ A) (hU : ∀ i, A i ∈ (differenceSpan u)ᗮ) : + (∫⁻ x, ENNReal.ofReal ((tupleDistance u x)⁻¹^k) ∂(sphereLaw d).withDensity f) ≤ + 2 + ∑ j ∈ Finset.range J, ENNReal.ofReal ((2:ℝ)^(k*(j+1))) * + (sphereLaw d).withDensity f {x | ‖liftLabel A (labels A x-labels A (u 0))‖ ≤ (1/2:ℝ)^j} := by + apply (inverse_moment_finite_bins _ (measurable_tupleDistance_fixed u) + (fun x => norm_nonneg _) k J _ (fun r hr hr1 => tupleDistance_tube hd u hfL hr hr1) hcut).trans + apply add_le_add le_rfl + apply Finset.sum_le_sum + intro j hj + exact mul_le_mul' le_rfl (constrained_tube_le_ellipsoid _ u hA hU _) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/FrameTubes.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/FrameTubes.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a34dd77a4ed2b56456f1ea914e26ab96bfb4945 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/FrameTubes.lean @@ -0,0 +1,128 @@ +import OAI.Probability.PosteriorReplicas.Measures.BaseDisintegration + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric EuclideanGeometry +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +def baseProjectionConstant (base : BaseLaw) (d k : ℕ) : ℝ := + match base with + | .gaussian => (2 * Real.pi) ^ (-(k : ℝ) / 2) + | .spherical => Real.Gamma ((d : ℝ) / 2) / + (Real.pi ^ ((k : ℝ) / 2) * Real.Gamma (((d : ℝ) - k) / 2)) + +lemma baseProjectionConstant_pos {d k : ℕ} (hk : k < d) (base : BaseLaw) : + 0 < baseProjectionConstant base d k := by + have hd : 0 < (d : ℝ) := by exact_mod_cast (by omega : 0 < d) + have hdk : 0 < (d : ℝ) - k := sub_pos.mpr (by exact_mod_cast hk) + cases base <;> unfold baseProjectionConstant <;> positivity + +lemma baseDensity_le_sup {d k : ℕ} (hk : k + 2 ≤ d) (base : BaseLaw) + (A : Rows d k) (y : Labels k) : baseDensity base A y ≤ + ENNReal.ofReal (baseProjectionConstant base d k / Real.sqrt (rowGram A).det) := by + have hC := (baseProjectionConstant_pos (by omega : k < d) base).le + by_cases hA : LinearIndependent ℝ A + · rw [baseDensity.eq_def, ite_eq_left hA] + cases base + · dsimp only [baseProjectionConstant] at hC ⊢ + split_ifs with hy + · apply ENNReal.ofReal_le_ofReal + apply div_le_div_of_nonneg_right _ (Real.sqrt_nonneg _) + have hb : 0 ≤ 1 - ‖liftLabel A y‖^2 := by nlinarith [norm_nonneg (liftLabel A y)] + have he : 0 ≤ ((d : ℝ) - k - 2) / 2 := by + have : (k : ℝ) + 2 ≤ d := by exact_mod_cast hk + linarith + exact mul_le_of_le_one_right hC (Real.rpow_le_one hb (by nlinarith [sq_nonneg ‖liftLabel A y‖]) he) + · exact bot_le + · dsimp only [baseProjectionConstant] at hC ⊢ + apply ENNReal.ofReal_le_ofReal + apply div_le_div_of_nonneg_right _ (Real.sqrt_nonneg _) + exact mul_le_of_le_one_right hC (Real.exp_le_one_iff.mpr (div_nonpos_of_nonpos_of_nonneg + (neg_nonpos.mpr (sq_nonneg _)) (by norm_num))) + · rw [baseDensity.eq_def, ite_eq_right hA] + exact bot_le + +lemma baseDensity_le_orthonormal {d k : ℕ} (hk : k + 2 ≤ d) (base : BaseLaw) + {A : Rows d k} (hA : Orthonormal ℝ A) (y : Labels k) : + baseDensity base A y ≤ ENNReal.ofReal (baseProjectionConstant base d k) := by + simpa only [rowGram_eq_gram, Matrix.gram_eq_one_iff_orthonormal.mpr hA, + Matrix.det_one, Real.sqrt_one, div_one] using baseDensity_le_sup hk base A y + +lemma projected_base_measure {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (hk : k < d) (base : BaseLaw) : (base.measure d).map (labels A) = + volume.withDensity (baseDensity base A) := by + have h := projected_measure hA hk base (f := fun _ => 1) measurable_const + have hμ : (base.measure d).withDensity (fun _ => 1) = base.measure d := by + exact withDensity_one + have hp : projectedDensity base (fun _ => 1) A = baseDensity base A := by + funext y + simp only [projectedDensity, tiltMass, lintegral_one, measure_univ, mul_one] + rw [hμ, hp] at h + exact h + +lemma orthonormal_in_orthogonal {d q : ℕ} (U : Submodule ℝ (Vec d)) + (hq : q ≤ Module.finrank ℝ Uᗮ) : + ∃ v : Fin q → Vec d, Orthonormal ℝ v ∧ ∀ i, v i ∈ Uᗮ := by + let b := stdOrthonormalBasis ℝ Uᗮ + let v : Fin q → Uᗮ := fun i => b (Fin.castLE hq i) + refine ⟨fun i => (v i : Vec d), ?_, fun i => (v i).2⟩ + exact (b.orthonormal.comp (Fin.castLE hq) (Fin.castLE_injective hq)).comp_linearIsometry Uᗮ.subtypeₗᵢ + +lemma pairing_le_infDist {d : ℕ} (L : AffineSubspace ℝ (Vec d)) [Nonempty L] + {p v : Vec d} (hp : p ∈ L) (hv : v ∈ L.directionᗮ) (hvnorm : ‖v‖ = 1) (x : Vec d) : + |⟪v, x - p⟫| ≤ Metric.infDist x L := by + have ho : ⟪v, (orthogonalProjection L x : Vec d) - p⟫ = 0 := + Submodule.inner_left_of_mem_orthogonal (L.vsub_mem_direction (orthogonalProjection_mem x) hp) hv + have he : ⟪v, x - p⟫ = ⟪v, x - (orthogonalProjection L x : Vec d)⟫ := by + rw [inner_sub_right] at ho + simp only [inner_sub_right] + linarith + rw [he, ← dist_orthogonalProjection_eq_infDist, dist_eq_norm] + simpa only [hvnorm, one_mul] using abs_real_inner_le_norm v (x - (orthogonalProjection L x : Vec d)) + +lemma base_affine_tube {d q : ℕ} (hq : q + 2 ≤ d) (base : BaseLaw) + (L : AffineSubspace ℝ (Vec d)) [Nonempty L] + (hL : Module.finrank ℝ L.direction + q ≤ d) {r : ℝ} (hr : 0 < r) : + (base.measure d) {x | Metric.infDist x L ≤ r} ≤ + (ENNReal.ofReal (baseProjectionConstant base d q) * 2^q) * ENNReal.ofReal (r^q) := by + have hdim : q ≤ Module.finrank ℝ L.directionᗮ := by + have he := L.direction.finrank_add_finrank_orthogonal + simp only [finrank_euclideanSpace_fin] at he + omega + obtain ⟨v, hv, hvin⟩ := orthonormal_in_orthogonal L.direction hdim + obtain ⟨p, hp⟩ := Set.nonempty_coe_sort.mp (inferInstance : Nonempty L) + let c := labels v p + let s : Set (Labels q) := Set.pi univ (fun i => Icc (c i - r) (c i + r)) + have hs : MeasurableSet s := MeasurableSet.univ_pi (fun i => measurableSet_Icc) + have hsub : {x | Metric.infDist x L ≤ r} ⊆ (labels v) ⁻¹' s := by + intro x hx + simp only [Set.mem_preimage, s, Set.mem_pi, Set.mem_univ, true_implies, Set.mem_Icc] + intro i + have hi := (pairing_le_infDist L hp (hvin i) (hv.norm_eq_one i) x).trans hx + rw [inner_sub_right, abs_le] at hi + exact ⟨by dsimp [c, labels]; linarith [hi.1], by dsimp [c, labels]; linarith [hi.2]⟩ + calc + _ ≤ (base.measure d) ((labels v) ⁻¹' s) := measure_mono hsub + _ = ((base.measure d).map (labels v)) s := + (Measure.map_apply (by unfold labels; fun_prop) hs).symm + _ = ∫⁻ y in s, baseDensity base v y := by + rw [projected_base_measure hv.linearIndependent (by omega) base, withDensity_apply _ hs] + _ ≤ ∫⁻ _y in s, ENNReal.ofReal (baseProjectionConstant base d q) := + setLIntegral_mono' hs (fun y _ => baseDensity_le_orthonormal hq base hv y) + _ = ENNReal.ofReal (baseProjectionConstant base d q) * ENNReal.ofReal (2*r)^q := by + rw [lintegral_const, Measure.restrict_apply_univ] + congr 1 + change (Measure.pi (fun _ : Fin q => volume)) s = _ + rw [Measure.pi_pi] + simp only [Real.volume_Icc, show ∀ i, c i + r - (c i - r) = 2*r from fun _ => by ring] + simp + _ = _ := by + rw [ENNReal.ofReal_mul (by norm_num), mul_pow, ENNReal.ofReal_ofNat, + ENNReal.ofReal_pow hr.le, mul_assoc] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/InverseMomentBins.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/InverseMomentBins.lean new file mode 100644 index 0000000000000000000000000000000000000000..96ec9f1e4b42f17e0e6581b3c80b24ae2b0c4373 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/InverseMomentBins.lean @@ -0,0 +1,140 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianGramMoment + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +section +variable {X : Type*} [MeasurableSpace X] + +lemma truncated_inverse_moment (μ : Measure X) {f : X → ℝ} (hf : Measurable f) + (hn : ∀ x, 0 ≤ f x) (k : ℕ) (C : ℝ≥0∞) + (htube : ∀ r : ℝ, 0 < r → r ≤ 1 → μ {x | f x ≤ r} ≤ C*ENNReal.ofReal (r^(k+1))) + {h : ℝ} (hh : 0 < h) (hh1 : h ≤ 1) : + (∫⁻ x in {x | f x ≤ h}, ENNReal.ofReal ((f x)⁻¹^k) ∂μ) ≤ + C * ENNReal.ofReal h * (1+(2:ℝ≥0∞)^(k+1)) := by + let ρ := μ.restrict {x | f x ≤ h} + have hb : ∀ r : ℝ, 0 < r → r ≤ 1 → + ρ {x | f x/h ≤ r} ≤ (C*ENNReal.ofReal (h^(k+1)))*ENNReal.ofReal (r^(k+1)) := by + intro r hr hr1 + calc + _ ≤ μ {x | f x ≤ h*r} := by + rw [Measure.restrict_apply (measurableSet_le (hf.div_const h) measurable_const)] + apply measure_mono + intro x hx + have := (div_le_iff₀ hh).mp hx.1 + change f x ≤ h*r + simpa only [mul_comm r h] using this + _ ≤ C*ENNReal.ofReal ((h*r)^(k+1)) := + htube _ (mul_pos hh hr) ((mul_le_of_le_one_left hr.le hh1).trans hr1) + _ = _ := by rw [mul_pow, ENNReal.ofReal_mul (by positivity), mul_assoc] + have hi := PosteriorRegression.inverse_moment_of_tube_bound ρ (fun x => f x/h) k + (hf.div_const h) (fun x => div_nonneg (hn x) hh.le) (C*ENNReal.ofReal (h^(k+1))) hb + have hm : ρ univ ≤ C*ENNReal.ofReal (h^(k+1)) := by + simpa only [ρ, Measure.restrict_apply_univ] using htube h hh hh1 + have he (x : X) : ENNReal.ofReal ((f x)⁻¹^k) = + ENNReal.ofReal (h⁻¹^k)*ENNReal.ofReal ((f x/h)⁻¹^k) := by + rw [← ENNReal.ofReal_mul (by positivity)] + congr 1 + rw [← mul_pow, inv_div, div_eq_mul_inv, ← mul_assoc, inv_mul_cancel₀ hh.ne', one_mul] + calc + _ = ENNReal.ofReal (h⁻¹^k) * (∫⁻ x, ENNReal.ofReal ((f x/h)⁻¹^k) ∂ρ) := by + simp_rw [he] + rw [lintegral_const_mul _ (by fun_prop)] + _ ≤ ENNReal.ofReal (h⁻¹^k) * + (C*ENNReal.ofReal (h^(k+1)) + (C*ENNReal.ofReal (h^(k+1)))*2^(k+1)) := by + exact mul_le_mul' le_rfl (hi.trans (add_le_add hm le_rfl)) + _ = _ := by + rw [← mul_one_add, ← mul_assoc, ← mul_assoc, mul_comm _ C, mul_assoc C, + ← ENNReal.ofReal_mul (by positivity)] + have hc : h⁻¹^k*h^(k+1) = h := by + rw [pow_succ, ← mul_assoc, ← mul_pow, inv_mul_cancel₀ hh.ne', one_pow, one_mul] + rw [hc] +end + +lemma inverse_pow_finite_dyadic_majorant {X : Type*} (f : X → ℝ) (k J : ℕ) + (hf : ∀ x, 0 ≤ f x) (x : X) : + ENNReal.ofReal ((f x)⁻¹^k) ≤ 1 + + (∑ j ∈ Finset.range J, ({x | f x ≤ (1/2:ℝ)^j}).indicator + (fun _ => ENNReal.ofReal ((2:ℝ)^(k*(j+1)))) x) + + ({x | f x ≤ (1/2:ℝ)^J}).indicator (fun x => ENNReal.ofReal ((f x)⁻¹^k)) x := by + classical + by_cases hsmall : f x ≤ (1/2:ℝ)^J + · rw [indicator_of_mem (show x ∈ {x | f x ≤ (1/2:ℝ)^J} from hsmall)] + exact le_add_left le_rfl + have hp : 0 < f x := lt_trans (by positivity : 0 < (1/2:ℝ)^J) (lt_of_not_ge hsmall) + rw [indicator_of_notMem (show x ∉ {x | f x ≤ (1/2:ℝ)^J} from hsmall), add_zero] + by_cases hlarge : 1 ≤ f x + · apply le_add_of_le_left + apply le_trans (ENNReal.ofReal_le_ofReal (pow_le_one₀ (inv_nonneg.mpr (hf x)) + (inv_le_one_of_one_le₀ hlarge))) + simp + obtain ⟨j,hlo,hhi⟩ := exists_nat_pow_near_of_lt_one hp (le_of_not_ge hlarge) + (by norm_num : (0:ℝ) < 1/2) (by norm_num : (1/2:ℝ) < 1) + have hj : j < J := by + by_contra hnot + have hle := pow_le_pow_of_le_one (by norm_num : (0:ℝ) ≤ 1/2) (by norm_num : (1/2:ℝ) ≤ 1) + (le_of_not_gt hnot) + exact hsmall (hhi.trans hle) + have hpow : ENNReal.ofReal ((f x)⁻¹^k) ≤ ENNReal.ofReal ((2:ℝ)^(k*(j+1))) := by + have hinv := (inv_le_inv₀ hp (pow_pos (by norm_num : (0:ℝ) < 1/2) _)).mpr hlo.le + have hinv' : (f x)⁻¹ ≤ (2:ℝ)^(j+1) := by simpa using hinv + apply ENNReal.ofReal_le_ofReal + simpa only [← pow_mul, Nat.mul_comm] using pow_le_pow_left₀ (by positivity) hinv' k + calc + _ ≤ ENNReal.ofReal ((2:ℝ)^(k*(j+1))) := hpow + _ = ({x | f x ≤ (1/2:ℝ)^j}).indicator + (fun _ => ENNReal.ofReal ((2:ℝ)^(k*(j+1)))) x := by + rw [indicator_of_mem (show x ∈ {x | f x ≤ (1/2:ℝ)^j} from hhi)] + _ ≤ ∑ j ∈ Finset.range J, ({x | f x ≤ (1/2:ℝ)^j}).indicator + (fun _ => ENNReal.ofReal ((2:ℝ)^(k*(j+1)))) x := + Finset.single_le_sum (f := fun j => ({x | f x ≤ (1/2:ℝ)^j}).indicator + (fun _ => ENNReal.ofReal ((2:ℝ)^(k*(j+1)))) x) + (fun i _ => bot_le) (Finset.mem_range.mpr hj) + _ ≤ _ := le_add_left le_rfl + +lemma inverse_moment_finite_bins {X : Type*} [MeasurableSpace X] + (μ : Measure X) [IsProbabilityMeasure μ] {f : X → ℝ} (hf : Measurable f) + (hn : ∀ x, 0 ≤ f x) (k J : ℕ) (C : ℝ≥0∞) + (htube : ∀ r : ℝ, 0 < r → r ≤ 1 → μ {x | f x ≤ r} ≤ C*ENNReal.ofReal (r^(k+1))) + (hcut : C*ENNReal.ofReal ((1/2:ℝ)^J)*(1+(2:ℝ≥0∞)^(k+1)) ≤ 1) : + (∫⁻ x, ENNReal.ofReal ((f x)⁻¹^k) ∂μ) ≤ + 2 + ∑ j ∈ Finset.range J, ENNReal.ofReal ((2:ℝ)^(k*(j+1))) * μ {x | f x ≤ (1/2:ℝ)^j} := by + have hmeas (j : ℕ) : MeasurableSet {x | f x ≤ (1/2:ℝ)^j} := measurableSet_le hf measurable_const + have hsum : Measurable (fun x => ∑ j ∈ Finset.range J, ({x | f x ≤ (1/2:ℝ)^j}).indicator + (fun _ => ENNReal.ofReal ((2:ℝ)^(k*(j+1)))) x) := + Finset.measurable_sum _ (fun j _ => measurable_const.indicator (hmeas j)) + have hadd : Measurable (fun x => 1 + ∑ j ∈ Finset.range J, ({x | f x ≤ (1/2:ℝ)^j}).indicator + (fun _ => ENNReal.ofReal ((2:ℝ)^(k*(j+1)))) x) := measurable_const.add hsum + have htail := (truncated_inverse_moment μ hf hn k C htube + (h := (1/2:ℝ)^J) (by positivity) (pow_le_one₀ (by norm_num) (by norm_num))).trans hcut + calc + _ ≤ ∫⁻ x, 1 + (∑ j ∈ Finset.range J, ({x | f x ≤ (1/2:ℝ)^j}).indicator + (fun _ => ENNReal.ofReal ((2:ℝ)^(k*(j+1)))) x) + + ({x | f x ≤ (1/2:ℝ)^J}).indicator (fun x => ENNReal.ofReal ((f x)⁻¹^k)) x ∂μ := + lintegral_mono (inverse_pow_finite_dyadic_majorant f k J hn) + _ = 1 + (∑ j ∈ Finset.range J, ENNReal.ofReal ((2:ℝ)^(k*(j+1))) * μ {x | f x ≤ (1/2:ℝ)^j}) + + ∫⁻ x in {x | f x ≤ (1/2:ℝ)^J}, ENNReal.ofReal ((f x)⁻¹^k) ∂μ := by + rw [lintegral_add_aux hadd + ((by fun_prop : Measurable (fun x => ENNReal.ofReal ((f x)⁻¹^k))).indicator (hmeas J)), + lintegral_add_left measurable_const, + lintegral_const, measure_univ, mul_one, + lintegral_finsetSum _ (fun j _ => measurable_const.indicator (hmeas j)), + lintegral_indicator (hmeas J)] + congr 2 + apply Finset.sum_congr rfl + intro j _ + rw [lintegral_indicator (hmeas j), lintegral_const, Measure.restrict_apply_univ] + _ ≤ _ := by + calc + _ ≤ 1 + (∑ j ∈ Finset.range J, ENNReal.ofReal ((2:ℝ)^(k*(j+1))) * μ {x | f x ≤ (1/2:ℝ)^j}) + 1 := + add_le_add le_rfl htail + _ = _ := by ring + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/LabelConvolution.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/LabelConvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..397ea375821b8b65cf63c85f5cf04b9977dd12d9 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/LabelConvolution.lean @@ -0,0 +1,88 @@ +import OAI.Probability.PosteriorReplicas.Geometry.LabelEllipsoids + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma liftLabel_neg {d k : ℕ} (A : Rows d k) (y : Labels k) : + liftLabel A (-y) = -liftLabel A y := by + simp [liftLabel, Matrix.mulVec_neg, Finset.sum_neg_distrib] + +lemma norm_liftLabel_sub_comm {d k : ℕ} (A : Rows d k) (x y : Labels k) : + ‖liftLabel A (x-y)‖ = ‖liftLabel A (y-x)‖ := by + rw [← neg_sub y x, liftLabel_neg, norm_neg] + +def ellipsoidMass {d k : ℕ} (ν : Measure (Vec d)) (A : Rows d k) (y : Labels k) (r : ℝ) : ℝ≥0∞ := + ν {x | ‖liftLabel A (labels A x-y)‖ ≤ r} + +@[fun_prop] lemma measurable_ellipsoidMass {d k : ℕ} (ν : Measure (Vec d)) [SFinite ν] (r : ℝ) : + Measurable (fun z : Data d k => ellipsoidMass ν z.1 z.2 r) := by + change Measurable (fun z : Data d k => ν ((Prod.mk z) ⁻¹' + {q : Data d k × Vec d | ‖liftLabel q.1.1 (labels q.1.1 q.2-q.1.2)‖ ≤ r})) + apply measurable_measure_prodMk_left + exact measurableSet_le (by unfold labels; fun_prop) measurable_const + +lemma lintegral_ellipsoidMass {d k : ℕ} (ν : Measure (Vec d)) [IsProbabilityMeasure ν] + {A : Rows d k} (hA : LinearIndependent ℝ A) (r : ℝ) : + (∫⁻ y, ellipsoidMass ν A y r ∂volume) = + ENNReal.ofReal (gramVolume A) * volume {y : Labels k | labelNorm y ≤ r} := by + let S : Set (Labels k × Vec d) := {z | ‖liftLabel A (labels A z.2-z.1)‖ ≤ r} + have hS : MeasurableSet S := measurableSet_le (by unfold labels; fun_prop) measurable_const + have hs := (Measure.prod_apply (μ := volume) (ν := ν) hS).symm.trans + (Measure.prod_apply_symm (μ := volume) (ν := ν) hS) + change (∫⁻ y, ν ((Prod.mk y) ⁻¹' S) ∂volume) = _ + rw [hs] + calc + _ = ∫⁻ _x : Vec d, ENNReal.ofReal (gramVolume A) * + volume {y : Labels k | labelNorm y ≤ r} ∂ν := by + apply lintegral_congr + intro x + change volume {y : Labels k | ‖liftLabel A (labels A x-y)‖ ≤ r} = _ + simp_rw [norm_liftLabel_sub_comm A (labels A x)] + exact label_ellipsoid_translate_volume hA (labels A x) r + _ = _ := by simp + +lemma normalized_density_integral_le {Y : Type*} [MeasurableSpace Y] (μ : Measure Y) + {a h : Y → ℝ≥0∞} (ha : Measurable a) (hh : Measurable h) + (hat : ∀ y, a y ≠ ∞) : + (∫⁻ y, (a y)⁻¹*h y ∂μ.withDensity a) ≤ ∫⁻ y, h y ∂μ := by + rw [lintegral_withDensity_eq_lintegral_mul _ ha (show Measurable (fun y => (a y)⁻¹*h y) from ha.inv.mul hh)] + apply lintegral_mono + intro y + simp only [Pi.mul_apply] + rw [← mul_assoc] + by_cases haz : a y = 0 + · simp [haz] + · rw [ENNReal.mul_inv_cancel haz (hat y), one_mul] + +lemma normalized_inverse_density_integral {Y : Type*} [MeasurableSpace Y] (μ : Measure Y) + {a : Y → ℝ≥0∞} (ha : Measurable a) (hat : ∀ y, a y ≠ ∞) : + (∫⁻ y, (a y)⁻¹ ∂μ.withDensity a) = μ {y | a y ≠ 0} := by + rw [lintegral_withDensity_eq_lintegral_mul _ ha (show Measurable (fun y => (a y)⁻¹) from ha.inv)] + rw [← lintegral_indicator_one (show MeasurableSet {y | a y ≠ 0} from + (measurableSet_eq_fun ha measurable_const).compl)] + apply lintegral_congr + intro y + by_cases haz : a y = 0 + · simp [haz] + · simp [haz,ENNReal.mul_inv_cancel haz (hat y)] + +lemma normalized_ellipsoidMass_integral_le {d k : ℕ} {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] + {A : Rows d k} (hA : LinearIndependent ℝ A) (r : ℝ) : + (∫⁻ y, (projectedDensity .spherical f A y)⁻¹ * + ellipsoidMass ((sphereLaw d).withDensity f) A y r + ∂volume.withDensity (projectedDensity .spherical f A)) ≤ + ENNReal.ofReal (gramVolume A) * volume {y : Labels k | labelNorm y ≤ r} := by + rw [← lintegral_ellipsoidMass ((sphereLaw d).withDensity f) hA r] + apply normalized_density_integral_le _ (by fun_prop) (by fun_prop) + exact projectedDensity_ne_top .spherical hLt hfL A + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/LabelEllipsoids.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/LabelEllipsoids.lean new file mode 100644 index 0000000000000000000000000000000000000000..23be3452eb75812474ee4169986849b872e4f044 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/LabelEllipsoids.lean @@ -0,0 +1,102 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianLogMoment +import OAI.Probability.PosteriorReplicas.Measures.ConstrainedDensityExpectation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma liftLabel_norm_coordinates {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (y : Labels k) : ‖liftLabel A y‖ = labelNorm ((pairingTriangular A).transpose⁻¹ *ᵥ y) := by + have h := pairingLift_energy hA y + have he : labelNorm ((pairingTriangular A).transpose⁻¹ *ᵥ y)^2 = + ∑ i, (((pairingTriangular A).transpose⁻¹ *ᵥ y) i)^2 := by + exact EuclideanSpace.real_norm_sq_eq _ + have hn : 0 ≤ labelNorm ((pairingTriangular A).transpose⁻¹ *ᵥ y) := norm_nonneg _ + change ‖liftLabel A y‖^2 = _ at h + nlinarith [norm_nonneg (liftLabel A y)] + +lemma label_closedBall_volume {k : ℕ} (r : ℝ) : + (volume : Measure (Labels k)) {y | labelNorm y ≤ r} = + volume (closedBall (0 : Vec k) r) := by + rw [← (PiLp.volume_preserving_toLp (Fin k)).measure_preimage (by measurability)] + congr 1 + ext y + simp [labelNorm, mem_closedBall, dist_zero_right] + +lemma label_closedBall_scale {k : ℕ} {r : ℝ} (hr : 0 ≤ r) : + (volume : Measure (Labels k)) {y | labelNorm y ≤ r} = + ENNReal.ofReal (r^k) * volume {y : Labels k | labelNorm y ≤ 1} := by + rw [label_closedBall_volume, label_closedBall_volume] + simpa using Measure.addHaar_closedBall_mul (volume : Measure (Vec k)) (0 : Vec k) hr (by norm_num : (0:ℝ) ≤ 1) + +lemma label_ellipsoid_volume {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (r : ℝ) : + (volume : Measure (Labels k)) {y | ‖liftLabel A y‖ ≤ r} = + ENNReal.ofReal (gramVolume A) * volume {y : Labels k | labelNorm y ≤ r} := by + have hd := (pairingTriangular_det_pos hA).ne' + have hm := Real.map_matrix_volume_pi_eq_smul_volume_pi (M := (pairingTriangular A).transpose⁻¹) + (by simpa [Matrix.det_nonsing_inv] using inv_ne_zero hd) + have h := congrArg (fun μ : Measure (Labels k) => μ {y | labelNorm y ≤ r}) hm + rw [Measure.map_apply (by fun_prop) (measurableSet_le (by fun_prop) measurable_const), + Measure.smul_apply, smul_eq_mul] at h + simp only [Matrix.det_nonsing_inv, Ring.inverse_eq_inv, inv_inv, pairingTriangular_det, abs_of_nonneg (Real.sqrt_nonneg _)] at h + convert h using 1 + congr 1 + ext y + simp only [mem_ofPred_eq, mem_preimage, Matrix.toLin'_apply, liftLabel_norm_coordinates hA] + all_goals rfl + +lemma label_ellipsoid_translate_volume {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (y : Labels k) (r : ℝ) : + (volume : Measure (Labels k)) {z | ‖liftLabel A (z-y)‖ ≤ r} = + ENNReal.ofReal (gramVolume A) * volume {z : Labels k | labelNorm z ≤ r} := by + have h := congrArg (fun μ : Measure (Labels k) => μ {z | ‖liftLabel A z‖ ≤ r}) + (map_add_right_eq_self (volume : Measure (Labels k)) (-y)) + rw [Measure.map_apply (by fun_prop) (measurableSet_le (by fun_prop) measurable_const)] at h + simpa only [preimage_ofPred_eq, sub_eq_add_neg, label_ellipsoid_volume hA r] using h + +lemma projectedDensity_support_ellipsoid {d k : ℕ} (f : Vec d → ℝ≥0∞) + (A : Rows d k) (y : Labels k) (hy : projectedDensity .spherical f A y ≠ 0) : + ‖liftLabel A y‖ < 1 := by + unfold projectedDensity baseDensity at hy + split_ifs at hy with hA hy' <;> simp_all + +lemma projectedDensity_support_volume {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (f : Vec d → ℝ≥0∞) : + (volume : Measure (Labels k)) {y | projectedDensity .spherical f A y ≠ 0} ≤ + ENNReal.ofReal (gramVolume A) * volume {y : Labels k | labelNorm y ≤ 1} := by + rw [← label_ellipsoid_volume hA 1] + exact measure_mono (fun y hy => (projectedDensity_support_ellipsoid f A y hy).le) + +lemma gaussian_integrable_gramVolume {d k : ℕ} : + Integrable (gramVolume : Rows d k → ℝ) (gaussianRows d k) := by + have hp : Integrable (fun A : Rows d k => ∏ i, ‖A i‖) (gaussianRows d k) := + Integrable.fintype_prod (fun _ => (IsGaussian.integrable_id (μ := stdGaussian (Vec d))).norm) + apply hp.mono' (by fun_prop) + exact ae_of_all _ (fun A => by + rw [Real.norm_eq_abs, abs_of_nonneg (show 0 ≤ gramVolume A from Real.sqrt_nonneg _), gramVolume_eq_prod] + exact Finset.prod_le_prod₀ (fun _ _ => norm_nonneg _) + (fun index _ => norm_gramSchmidt_le_norm A index)) + +lemma gaussian_label_support_volume_finite {d k : ℕ} (hd : 3 ≤ d) (hk : k < d) + {f : Vec d → ℝ≥0∞} (_hf : Measurable f) : + (∫⁻ A, (volume : Measure (Labels k)) {y | projectedDensity .spherical f A y ≠ 0} + ∂gaussianRows d k) < ∞ := by + apply lt_of_le_of_lt (lintegral_mono_ae (g := fun A : Rows d k => + ENNReal.ofReal (gramVolume A) * volume {y : Labels k | labelNorm y ≤ 1}) ?_) ?_ + · filter_upwards [ae_gaussian_rows_full_rank hd hk] with A hA + exact projectedDensity_support_volume hA f + · rw [lintegral_mul_const _ (by fun_prop)] + apply ENNReal.mul_lt_top + · exact (hasFiniteIntegral_iff_ofReal (ae_of_all _ (fun _ => Real.sqrt_nonneg _))).mp + gaussian_integrable_gramVolume.hasFiniteIntegral + · rw [label_closedBall_volume] + exact measure_closedBall_lt_top + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereDensity.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..eecec65433480ae698188e9ec9ab7449cfe664a0 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereDensity.lean @@ -0,0 +1,150 @@ +import OAI.Probability.PosteriorReplicas.Geometry.SphereSubspace + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma volume_pairings_on_span {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) : + let U := Submodule.span ℝ (Set.range v) + (volume : Measure U).map (fun x : U => fun i => ⟪v i, (x : E)⟫) = + ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ v).det)⁻¹) • volume := by + let U := Submodule.span ℝ (Set.range v) + let F : U → Fin n → ℝ := fun x i => ⟪v i, (x : E)⟫ + let h : (Fin n → ℝ) → ℝ≥0∞ := fun y => gaussianRadialDensity n ‖pairingLift v y‖ + have hF : Measurable F := by unfold F; fun_prop + have hh : Measurable h := by unfold h; fun_prop + have hj : 0 < Real.sqrt (Matrix.gram ℝ v).det := + Real.sqrt_pos.mpr (Matrix.posDef_gram_of_linearIndependent hv).det_pos + have hU : Module.finrank ℝ U = n := by + simpa only [Fintype.card_fin] using finrank_span_eq_card hv + have hl (x : U) : pairingLift v (F x) = (x : E) := by + rw [← starProjection_eq_pairingLift hv] + exact U.starProjection_eq_self_iff.mpr x.2 + have hg : (stdGaussian U).map F = (stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) := by + rw [← gaussian_orthogonalProjectionOnto U, Measure.map_map hF (by fun_prop)] + congr 1 + funext x i + exact pairing_starProjection U (Submodule.subset_span (Set.mem_range_self i)) x + have hd : (stdGaussian U) = (volume : Measure U).withDensity (h ∘ F) := by + rw [stdGaussian_density, hU] + congr 1 + funext x + simp only [Function.comp_apply, h, hl, Submodule.norm_coe] + have he : ((volume : Measure U).map F).withDensity h = + (ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ v).det)⁻¹) • + (volume : Measure (Fin n → ℝ))).withDensity h := by + rw [← map_withDensity_comp _ hF hh, ← hd, hg, gaussian_pairings_density hv, + withDensity_smul_measure, ← withDensity_smul _ hh] + congr 1 + funext y + change ENNReal.ofReal _ = ENNReal.ofReal _ * gaussianRadialDensity n ‖pairingLift v y‖ + rw [gaussianRadialDensity, ← ENNReal.ofReal_mul (by positivity)] + congr 1 + ring + have hz (y : Fin n → ℝ) : h y ≠ 0 := by + dsimp [h, gaussianRadialDensity] + positivity + have ht (y : Fin n → ℝ) : h y ≠ ∞ := ENNReal.ofReal_ne_top + have hinv := congrArg (fun μ : Measure (Fin n → ℝ) => μ.withDensity (fun y => (h y)⁻¹)) he + rw [withDensity_inv_same hh (Filter.Eventually.of_forall hz) (Filter.Eventually.of_forall ht), + withDensity_inv_same hh (Filter.Eventually.of_forall hz) (Filter.Eventually.of_forall ht)] at hinv + exact hinv + +lemma lintegral_pairingLift {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) + {g : E → ℝ≥0∞} (hg : Measurable g) : + let U := Submodule.span ℝ (Set.range v) + ∫⁻ x : U, g (x : E) ∂volume = + ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ v).det)⁻¹) * ∫⁻ y, g (pairingLift v y) := by + let U := Submodule.span ℝ (Set.range v) + have he := congrArg (fun μ : Measure (Fin n → ℝ) => ∫⁻ y, g (pairingLift v y) ∂μ) + (volume_pairings_on_span hv) + rw [lintegral_map (by fun_prop) (by fun_prop), lintegral_smul_measure] at he + change _ = ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ v).det)⁻¹) * + ∫⁻ y, g (pairingLift v y) at he + convert he using 1 + apply lintegral_congr + intro x + rw [← starProjection_eq_pairingLift hv, U.starProjection_eq_self_iff.mpr x.2] + +def sphericalPairingsDensity {n : ℕ} (v : Fin n → E) (y : Fin n → ℝ) : ℝ≥0∞ := + if ‖pairingLift v y‖ < 1 then ENNReal.ofReal + (Real.Gamma (((Module.finrank ℝ E : ℕ) : ℝ) / 2) / + (Real.pi ^ ((n : ℝ) / 2) * Real.Gamma ((((Module.finrank ℝ E : ℕ) : ℝ) - n) / 2)) * + (1 - ‖pairingLift v y‖^2) ^ ((((Module.finrank ℝ E : ℕ) : ℝ) - n - 2) / 2) / + Real.sqrt (Matrix.gram ℝ v).det) else 0 + +omit [FiniteDimensional ℝ E] in +@[fun_prop] lemma measurable_sphericalPairingsDensity [FiniteDimensional ℝ E] + {n : ℕ} (v : Fin n → E) : + Measurable (sphericalPairingsDensity v) := by + unfold sphericalPairingsDensity + exact Measurable.ite (measurableSet_lt (by fun_prop) measurable_const) (by fun_prop) measurable_const + +lemma sphere_fiber_integral {n : ℕ} {v : Fin n → E} (hv : LinearIndependent ℝ v) + (hn : n < Module.finrank ℝ E) {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ x, g x ∂uniformDirection E = ∫⁻ y, sphericalPairingsDensity v y * + ∫⁻ z, g (pairingLift v y + Real.sqrt (1 - ‖pairingLift v y‖^2) • + normalDirection ((Submodule.span ℝ (Set.range v))ᗮ.starProjection z)) ∂stdGaussian E := by + let U := Submodule.span ℝ (Set.range v) + have hU : Module.finrank ℝ U = n := by + simpa only [Fintype.card_fin] using finrank_span_eq_card hv + have hV : Module.finrank ℝ Uᗮ = Module.finrank ℝ E - n := by + have ha := U.finrank_add_finrank_orthogonal + omega + have hVr : ((Module.finrank ℝ Uᗮ : ℕ) : ℝ) = ((Module.finrank ℝ E : ℕ) : ℝ) - n := by + rw [hV, Nat.cast_sub hn.le] + let : Nontrivial E := Module.nontrivial_of_finrank_pos (by omega : 0 < Module.finrank ℝ E) + let : Nontrivial Uᗮ := Module.nontrivial_of_finrank_pos (by omega : 0 < Module.finrank ℝ Uᗮ) + let C : ℝ := Real.Gamma (((Module.finrank ℝ E : ℕ) : ℝ) / 2) / + (Real.pi ^ ((n : ℝ) / 2) * Real.Gamma ((((Module.finrank ℝ E : ℕ) : ℝ) - n) / 2)) + let β : ℝ := (((Module.finrank ℝ E : ℕ) : ℝ) - n - 2) / 2 + let G : E → ℝ≥0∞ := fun x => ENNReal.ofReal ((1 - ‖x‖^2)^β) * + ∫⁻ z, g (x + Real.sqrt (1 - ‖x‖^2) • normalDirection (Uᗮ.starProjection z)) ∂stdGaussian E + have hG : Measurable G := by unfold G; fun_prop + have hJ : 0 < Real.sqrt (Matrix.gram ℝ v).det := + Real.sqrt_pos.mpr (Matrix.posDef_gram_of_linearIndependent hv).det_pos + have hC : 0 < C := by + dsimp [C] + have hd : 0 < ((Module.finrank ℝ E : ℕ) : ℝ) := Nat.cast_pos.mpr Module.finrank_pos + have hq : 0 < ((Module.finrank ℝ E : ℕ) : ℝ) - n := by + rw [← hVr] + exact Nat.cast_pos.mpr Module.finrank_pos + positivity + rw [sphere_subspace_gaussian_fiber_integral U hg, sphere_area_ratio, hU, hVr] + change ENNReal.ofReal C * (∫⁻ x : U in ball 0 1, G (x : E)) = _ + have hi : (∫⁻ x : U in ball 0 1, G (x : E)) = + ENNReal.ofReal ((Real.sqrt (Matrix.gram ℝ v).det)⁻¹) * + ∫⁻ y, (ball (0 : E) 1).indicator G (pairingLift v y) := by + have he := lintegral_pairingLift hv (g := (ball (0 : E) 1).indicator G) + (hG.indicator measurableSet_ball) + convert he using 1 + rw [← lintegral_indicator measurableSet_ball] + apply lintegral_congr + intro x + rfl + have hI : Measurable (fun y => (ball (0 : E) 1).indicator G (pairingLift v y)) := + (hG.indicator measurableSet_ball).comp (continuous_pairingLift v).measurable + rw [hi, ← mul_assoc, ← lintegral_const_mul _ hI] + apply lintegral_congr + intro y + by_cases hy : ‖pairingLift v y‖ < 1 + · rw [Set.indicator_of_mem (mem_ball_zero_iff.mpr hy)] + dsimp [G, sphericalPairingsDensity] + rw [ite_eq_left hy, ← mul_assoc, ← ENNReal.ofReal_mul hC.le, ← ENNReal.ofReal_mul (by positivity)] + congr 1 + congr 1 + dsimp [C, β] + ring + · rw [Set.indicator_of_notMem (mt mem_ball_zero_iff.mp hy)] + simp [sphericalPairingsDensity, hy] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereSubspace.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereSubspace.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d8869a50a9d465a136bea60942384127fceeae7 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereSubspace.lean @@ -0,0 +1,248 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.RadialIntegrals +import OAI.Probability.PosteriorReplicas.Geometry.BallJacobian + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussian_orthogonalProjectionOnto (U : Submodule ℝ E) : + (stdGaussian E).map U.orthogonalProjectionOnto = stdGaussian U := by + apply Measure.ext_of_charFun + ext t + rw [charFun_apply, integral_map (by fun_prop) (by fun_prop)] + have he (x : E) : ⟪U.orthogonalProjectionOnto x, t⟫ = ⟪x, (t : E)⟫ := by + change ⟪U.starProjection x, (t : E)⟫ = _ + rw [real_inner_comm, pairing_starProjection U t.2, real_inner_comm] + simp_rw [he] + change charFun (stdGaussian E) (t : E) = _ + rw [charFun_stdGaussian, charFun_stdGaussian] + rfl + +lemma gaussian_subspace_map (U : Submodule ℝ E) : + (stdGaussian U).map (Subtype.val : U → E) = (stdGaussian E).map U.starProjection := by + rw [← gaussian_orthogonalProjectionOnto U, Measure.map_map (by fun_prop) (by fun_prop)] + rfl + +lemma gaussian_subspace_sum (U : Submodule ℝ E) : + ((stdGaussian U).prod (stdGaussian Uᗮ)).map (fun z => (z.1 : E) + (z.2 : E)) = + stdGaussian E := by + rw [← gaussian_orthogonal_sum U, ← gaussian_subspace_map, ← gaussian_subspace_map, + Measure.map_prod_map _ _ (by fun_prop) (by fun_prop), + Measure.map_map (by fun_prop) (by fun_prop)] + rfl + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma subspace_sum_norm_sq [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + (U : Submodule ℝ E) (x : U) (z : Uᗮ) : + ‖(x : E) + (z : E)‖^2 = ‖x‖^2 + ‖z‖^2 := by + have ho : ⟪(x : E), (z : E)⟫ = 0 := + (real_inner_comm _ _).trans ((Submodule.mem_orthogonal' U (z : E)).mp z.2 _ x.2) + simp [norm_add_sq_real, ho] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma normalDirection_pos_smul [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {r : ℝ} (hr : 0 < r) (x : E) : + normalDirection (r • x) = normalDirection x := by + simp [normalDirection, norm_smul, Real.norm_eq_abs, abs_of_pos hr, + _root_.mul_inv_rev, smul_smul, hr.ne'] + +lemma sphere_subspace_gaussian_integral (U : Submodule ℝ E) [Nontrivial E] + {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ x, g x ∂uniformDirection E = + ∫⁻ x : U, ∫⁻ z : Uᗮ, g (normalDirection ((x : E) + (z : E))) + ∂stdGaussian Uᗮ ∂stdGaussian U := by + rw [← gaussian_normalDirection, lintegral_map hg (by fun_prop), + ← gaussian_subspace_sum U, lintegral_map (by fun_prop) (by fun_prop), + lintegral_prod _ (by fun_prop)] + +lemma sphere_subspace_polar_integral (U : Submodule ℝ E) [Nontrivial E] [Nontrivial Uᗮ] + {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ y, g y ∂uniformDirection E = + ∫⁻ z : sphere (0 : Uᗮ) 1, ∫⁻ r : Ioi (0 : ℝ), ∫⁻ x : U, + gaussianRadialDensity (Module.finrank ℝ U) ‖x‖ * + g (normalDirection ((x : E) + r.1 • ((z : Uᗮ) : E))) + ∂volume ∂gaussianPolarRadius Uᗮ ∂(volume : Measure Uᗮ).toSphere := by + rw [sphere_subspace_gaussian_integral U hg] + have hp (x : U) : (∫⁻ z : Uᗮ, g (normalDirection ((x : E) + (z : E))) ∂stdGaussian Uᗮ) = + ∫⁻ z : sphere (0 : Uᗮ) 1, ∫⁻ r : Ioi (0 : ℝ), + g (normalDirection ((x : E) + r.1 • ((z : Uᗮ) : E))) + ∂gaussianPolarRadius Uᗮ ∂(volume : Measure Uᗮ).toSphere := by + rw [← gaussian_polar_reconstruction (E := Uᗮ), lintegral_map (by fun_prop) (by fun_prop), + lintegral_prod _ (by fun_prop)] + rfl + simp_rw [hp] + rw [lintegral_lintegral_swap (by fun_prop)] + apply lintegral_congr + intro z + rw [lintegral_lintegral_swap (by fun_prop)] + apply lintegral_congr + intro r + rw [stdGaussian_density, lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] + rfl + +lemma radial_subspace_integral (U : Submodule ℝ E) [Nontrivial E] [Nontrivial Uᗮ] (s : ℝ) : + ∫⁻ r : Ioi (0 : ℝ), ENNReal.ofReal (r.1 ^ Module.finrank ℝ U) * + gaussianRadialDensity (Module.finrank ℝ U) (r.1 * s) ∂gaussianPolarRadius Uᗮ = + ENNReal.ofReal ((1 + s^2) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2)) * + ((volume : Measure E).toSphere univ)⁻¹ := by + rw [lintegral_gaussianPolarRadius (E := Uᗮ) (g := fun r : ℝ => + ENNReal.ofReal (r ^ Module.finrank ℝ U) * + gaussianRadialDensity (Module.finrank ℝ U) (r * s)) (by fun_prop)] + calc + _ = ∫⁻ r in Ioi (0 : ℝ), ENNReal.ofReal (r ^ (Module.finrank ℝ E - 1)) * + ENNReal.ofReal ((2 * Real.pi) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2) * + Real.exp (-(1 + s^2) * r^2 / 2)) := by + apply setLIntegral_congr_fun measurableSet_Ioi + intro r hr + exact radial_power_gaussian_product Module.finrank_pos U.finrank_add_finrank_orthogonal hr.le s + _ = _ := radial_gaussian_integral (by positivity) + +lemma scaled_subspace_integral (U : Submodule ℝ E) (z : sphere (0 : Uᗮ) 1) + (r : Ioi (0 : ℝ)) {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ x : U, gaussianRadialDensity (Module.finrank ℝ U) ‖x‖ * + g (normalDirection ((x : E) + r.1 • ((z : Uᗮ) : E))) = + ∫⁻ x : U, ENNReal.ofReal (r.1 ^ Module.finrank ℝ U) * + gaussianRadialDensity (Module.finrank ℝ U) (r.1 * ‖x‖) * + g (normalDirection ((x : E) + ((z : Uᗮ) : E))) := by + rw [lintegral_pos_smul r.2 (by fun_prop), ← lintegral_const_mul _ (by fun_prop)] + apply lintegral_congr + intro x + rw [norm_smul, Real.norm_eq_abs, abs_of_pos r.2] + have he : ((r.1 • x : U) : E) + r.1 • ((z : Uᗮ) : E) = + r.1 • ((x : E) + ((z : Uᗮ) : E)) := by simp [smul_add] + rw [he, normalDirection_pos_smul r.2, mul_assoc] + +lemma sphere_subspace_slope_integral (U : Submodule ℝ E) [Nontrivial E] [Nontrivial Uᗮ] + {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ y, g y ∂uniformDirection E = + ((volume : Measure E).toSphere univ)⁻¹ * + ∫⁻ z : sphere (0 : Uᗮ) 1, ∫⁻ x : U, + ENNReal.ofReal ((1 + ‖x‖^2) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2)) * + g (normalDirection ((x : E) + ((z : Uᗮ) : E))) + ∂volume ∂(volume : Measure Uᗮ).toSphere := by + rw [sphere_subspace_polar_integral U hg, ← lintegral_const_mul _ (by fun_prop)] + apply lintegral_congr + intro z + simp_rw [scaled_subspace_integral U z _ hg] + rw [lintegral_lintegral_swap (by fun_prop), ← lintegral_const_mul _ (by fun_prop)] + apply lintegral_congr + intro x + rw [lintegral_mul_const _ (by fun_prop), radial_subspace_integral] + ac_rfl + +lemma normalDirection_ballStretch (U : Submodule ℝ E) {x : U} + (hx : x ∈ ball (0 : U) 1) (z : sphere (0 : Uᗮ) 1) : + normalDirection (((ballStretch x : U) : E) + ((z : Uᗮ) : E)) = + (x : E) + Real.sqrt (1 - ‖x‖^2) • ((z : Uᗮ) : E) := by + have hb := one_sub_norm_sq_pos hx + have hs := Real.sqrt_pos.mpr hb + have hz : ‖(z : Uᗮ)‖ = 1 := mem_sphere_zero_iff_norm.mp z.2 + have hn : ‖(x : E) + Real.sqrt (1 - ‖x‖^2) • ((z : Uᗮ) : E)‖ = 1 := by + have h := subspace_sum_norm_sq U x (Real.sqrt (1 - ‖x‖^2) • (z : Uᗮ)) + simp only [Submodule.coe_smul_of_tower, norm_smul, Real.norm_eq_abs, + abs_of_pos hs, hz, mul_one, Real.sq_sqrt hb.le] at h + nlinarith [norm_nonneg ((x : E) + Real.sqrt (1 - ‖x‖^2) • ((z : Uᗮ) : E))] + have he : ((ballStretch x : U) : E) + ((z : Uᗮ) : E) = + (Real.sqrt (1 - ‖x‖^2))⁻¹ • + ((x : E) + Real.sqrt (1 - ‖x‖^2) • ((z : Uᗮ) : E)) := by + rw [ballStretch_eq_inv_sqrt hx] + change (Real.sqrt (1 - ‖x‖^2))⁻¹ • (x : E) + ((z : Uᗮ) : E) = _ + rw [smul_add, smul_smul, inv_mul_cancel₀ hs.ne', one_smul] + rw [he, normalDirection_smul_sphere (inv_pos.mpr hs) hn] + +lemma sphere_subspace_surface_integral (U : Submodule ℝ E) [Nontrivial E] [Nontrivial Uᗮ] + {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ y, g y ∂uniformDirection E = + ((volume : Measure E).toSphere univ)⁻¹ * + ∫⁻ x : U in ball 0 1, + ENNReal.ofReal ((1 - ‖x‖^2) ^ ((((Module.finrank ℝ Uᗮ : ℕ) : ℝ) - 2) / 2)) * + ∫⁻ z : sphere (0 : Uᗮ) 1, + g ((x : E) + Real.sqrt (1 - ‖x‖^2) • ((z : Uᗮ) : E)) + ∂(volume : Measure Uᗮ).toSphere := by + rw [sphere_subspace_slope_integral U hg] + congr 1 + have ht (z : sphere (0 : Uᗮ) 1) : + (∫⁻ x : U, ENNReal.ofReal ((1 + ‖x‖^2) ^ (-((Module.finrank ℝ E : ℕ) : ℝ) / 2)) * + g (normalDirection ((x : E) + ((z : Uᗮ) : E)))) = + ∫⁻ x : U in ball 0 1, + ENNReal.ofReal ((1 - ‖x‖^2) ^ ((((Module.finrank ℝ Uᗮ : ℕ) : ℝ) - 2) / 2)) * + g ((x : E) + Real.sqrt (1 - ‖x‖^2) • ((z : Uᗮ) : E)) := by + rw [lintegral_ballStretch] + apply setLIntegral_congr_fun measurableSet_ball + intro x hx + dsimp only + rw [normalDirection_ballStretch U hx z, ← mul_assoc, + ← U.finrank_add_finrank_orthogonal, ballStretch_weight hx] + simp_rw [ht] + rw [lintegral_lintegral_swap (by fun_prop)] + apply setLIntegral_congr_fun measurableSet_ball + intro x hx + dsimp only + rw [lintegral_const_mul _ (by fun_prop)] + +lemma surface_lintegral_eq_gaussian [Nontrivial E] {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ z : sphere (0 : E) 1, g (z : E) ∂(volume : Measure E).toSphere = + (volume : Measure E).toSphere univ * ∫⁻ x, g (normalDirection x) ∂stdGaussian E := by + have he : (∫⁻ x, g (normalDirection x) ∂stdGaussian E) = ∫⁻ x, g x ∂uniformDirection E := by + rw [← gaussian_normalDirection, lintegral_map hg (by fun_prop)] + rw [he, uniformDirection, lintegral_map hg (by fun_prop), lintegral_smul_measure] + change _ = (volume : Measure E).toSphere univ * + (((volume : Measure E).toSphere univ)⁻¹ * + ∫⁻ z : sphere (0 : E) 1, g (z : E) ∂(volume : Measure E).toSphere) + rw [← mul_assoc, ENNReal.mul_inv_cancel + (Measure.measure_univ_ne_zero.mpr (Measure.toSphere_ne_zero volume)) (measure_ne_top _ _), one_mul] + +lemma sphere_subspace_gaussian_fiber_integral (U : Submodule ℝ E) + [Nontrivial E] [Nontrivial Uᗮ] {g : E → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ y, g y ∂uniformDirection E = + ((volume : Measure E).toSphere univ)⁻¹ * (volume : Measure Uᗮ).toSphere univ * + ∫⁻ x : U in ball 0 1, + ENNReal.ofReal ((1 - ‖x‖^2) ^ ((((Module.finrank ℝ Uᗮ : ℕ) : ℝ) - 2) / 2)) * + ∫⁻ z : E, g ((x : E) + Real.sqrt (1 - ‖x‖^2) • + normalDirection (Uᗮ.starProjection z)) ∂stdGaussian E := by + rw [sphere_subspace_surface_integral U hg, mul_assoc] + congr 1 + rw [← lintegral_const_mul _ (by fun_prop)] + apply setLIntegral_congr_fun measurableSet_ball + intro x hx + dsimp only + rw [surface_lintegral_eq_gaussian (E := Uᗮ) (g := fun z => + g ((x : E) + Real.sqrt (1 - ‖x‖^2) • (z : E))) (by fun_prop)] + have he : (∫⁻ z : Uᗮ, g ((x : E) + Real.sqrt (1 - ‖x‖^2) • ((normalDirection z : Uᗮ) : E)) + ∂stdGaussian Uᗮ) = ∫⁻ z : E, g ((x : E) + Real.sqrt (1 - ‖x‖^2) • + normalDirection (Uᗮ.starProjection z)) ∂stdGaussian E := by + rw [← gaussian_orthogonalProjectionOnto Uᗮ, lintegral_map (by fun_prop) (by fun_prop)] + rfl + rw [he] + ac_rfl + +lemma sphere_area_ratio (U : Submodule ℝ E) [Nontrivial E] [Nontrivial Uᗮ] : + ((volume : Measure E).toSphere univ)⁻¹ * (volume : Measure Uᗮ).toSphere univ = + ENNReal.ofReal (Real.Gamma (((Module.finrank ℝ E : ℕ) : ℝ) / 2) / + (Real.pi ^ (((Module.finrank ℝ U : ℕ) : ℝ) / 2) * + Real.Gamma (((Module.finrank ℝ Uᗮ : ℕ) : ℝ) / 2))) := by + have hd : 0 < ((Module.finrank ℝ E : ℕ) : ℝ) := Nat.cast_pos.mpr Module.finrank_pos + have hq : 0 < ((Module.finrank ℝ Uᗮ : ℕ) : ℝ) := Nat.cast_pos.mpr Module.finrank_pos + have he : ((Module.finrank ℝ E : ℕ) : ℝ) = + ((Module.finrank ℝ U : ℕ) : ℝ) + ((Module.finrank ℝ Uᗮ : ℕ) : ℝ) := by + exact_mod_cast U.finrank_add_finrank_orthogonal.symm + have hp : Real.pi ^ (((Module.finrank ℝ E : ℕ) : ℝ) / 2) = + Real.pi ^ (((Module.finrank ℝ U : ℕ) : ℝ) / 2) * + Real.pi ^ (((Module.finrank ℝ Uᗮ : ℕ) : ℝ) / 2) := by + rw [he, add_div, Real.rpow_add Real.pi_pos] + rw [sphere_area, sphere_area, ← ENNReal.ofReal_inv_of_pos (by positivity), + ← ENNReal.ofReal_mul (by positivity)] + congr 1 + rw [hp] + field_simp + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereTubeQuantitative.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereTubeQuantitative.lean new file mode 100644 index 0000000000000000000000000000000000000000..eb03b5bdd966135719c3fb6776b3687981729be7 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/SphereTubeQuantitative.lean @@ -0,0 +1,88 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianGramMoment + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric EuclideanGeometry Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma sphereLaw_closedBall {d : ℕ} [NeZero d] (z : Vec d) {r : ℝ} (hr : 0 < r) : + sphereLaw d (closedBall z r) ≤ ENNReal.ofReal ((3:ℝ)*4^d) * ENNReal.ofReal (r^(d-1)) := by + simpa only [sphereLaw, PosteriorRegression.ambientSphereLaw, PosteriorRegression.sphereLaw, + finrank_euclideanSpace_fin] using + PosteriorRegression.ambientSphereLaw_closedBall z hr (d-1) (by simp) + +lemma sphereLaw_support_unit {d : ℕ} : (sphereLaw d).support ⊆ closedBall 0 1 := by + exact (PosteriorRegression.ambientSphereLaw_support (E := Vec d)).trans sphere_subset_closedBall + +lemma sphere_affine_tube_quantitative {d k : ℕ} [NeZero d] + (L : AffineSubspace ℝ (Vec d)) [Nonempty L] + (hd : Module.finrank ℝ L.direction + k ≤ d-1) {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) : + sphereLaw d {x | Metric.infDist x L ≤ r} ≤ ENNReal.ofReal ((72:ℝ)^d) * ENNReal.ofReal (r^k) := by + classical + obtain ⟨s,hcard,hcover⟩ := PosteriorRegression.exists_affine_tube_cover L hr hr1 + let c : L.direction → Vec d := fun y => (y : Vec d) + (orthogonalProjection L 0 : Vec d) + have hsub : {x | Metric.infDist x L ≤ r} ≤ᵐ[sphereLaw d] + ⋃ y ∈ s, closedBall (c y) (2*r) := by + filter_upwards [(sphereLaw d).support_mem_ae] with x hx + intro hdist + have hxunit : ‖x‖ ≤ 1 := by simpa using sphereLaw_support_unit hx + obtain ⟨y,hy,hyx⟩ := hcover x hxunit hdist + exact mem_iUnion₂.mpr ⟨y,hy,hyx⟩ + let a := Module.finrank ℝ L.direction + have hd0 : 1 ≤ d := NeZero.one_le + have ha : a ≤ d := by dsimp [a]; omega + have hpow : (3/r)^a * ((3:ℝ)*4^d) * (2*r)^(d-1) ≤ (72:ℝ)^d*r^k := by + have hcan : (3/r)^a * ((3:ℝ)*4^d) * (2*r)^(d-1) = + (3*4^d*3^a*2^(d-1)) * r^(d-1-a) := by + have hdim : d-1 = a+(d-1-a) := by dsimp [a]; omega + nth_rw 1 [hdim] + rw [mul_pow, div_pow, pow_add] + field_simp + rw [hdim, pow_add] + simp only [Nat.add_sub_cancel_left] + ring + rw [hcan] + have hc : (3:ℝ)*4^d*3^a*2^(d-1) ≤ (72:ℝ)^d := by + have h3 : (3:ℝ) ≤ 3^d := by simpa using pow_le_pow_right₀ (by norm_num : (1:ℝ) ≤ 3) hd0 + have h3a : (3:ℝ)^a ≤ 3^d := pow_le_pow_right₀ (by norm_num) ha + have h2 : (2:ℝ)^(d-1) ≤ 2^d := pow_le_pow_right₀ (by norm_num) (Nat.sub_le _ _) + calc + _ ≤ 3^d*4^d*3^d*2^d := by gcongr + _ = (72:ℝ)^d := by simp only [← mul_pow]; congr 1; norm_num + apply mul_le_mul hc ?_ (by positivity) (by positivity) + exact pow_le_pow_of_le_one hr.le hr1 (by dsimp [a]; omega) + calc + _ ≤ sphereLaw d (⋃ y ∈ s, closedBall (c y) (2*r)) := measure_mono_ae hsub + _ ≤ ∑ y ∈ s, sphereLaw d (closedBall (c y) (2*r)) := measure_biUnion_finset_le _ _ + _ ≤ ∑ _y ∈ s, ENNReal.ofReal ((3:ℝ)*4^d)*ENNReal.ofReal ((2*r)^(d-1)) := by + exact Finset.sum_le_sum (fun y _ => sphereLaw_closedBall (c y) (by positivity)) + _ = (s.card : ℝ≥0∞) * (ENNReal.ofReal ((3:ℝ)*4^d)*ENNReal.ofReal ((2*r)^(d-1))) := by simp + _ ≤ ENNReal.ofReal ((3/r)^a) * (ENNReal.ofReal ((3:ℝ)*4^d)*ENNReal.ofReal ((2*r)^(d-1))) := by + gcongr + exact_mod_cast ENNReal.ofReal_le_ofReal hcard + _ ≤ _ := by + rw [← ENNReal.ofReal_mul (by positivity), ← ENNReal.ofReal_mul (by positivity), + ← ENNReal.ofReal_mul (by positivity)] + apply ENNReal.ofReal_le_ofReal + nlinarith [hpow] + +lemma spherical_tilt_affine_tube {d k : ℕ} [NeZero d] + {f : Vec d → ℝ≥0∞} {M : ℝ≥0∞} (hfM : ∀ x, f x ≤ M) + (L : AffineSubspace ℝ (Vec d)) [Nonempty L] + (hd : Module.finrank ℝ L.direction+k ≤ d-1) {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) : + (sphereLaw d).withDensity f {x | Metric.infDist x L ≤ r} ≤ + (M*ENNReal.ofReal ((72:ℝ)^d)) * ENNReal.ofReal (r^k) := by + rw [withDensity_apply _ (measurableSet_le (Metric.continuous_infDist_pt _).measurable measurable_const)] + calc + _ ≤ ∫⁻ _x in {x | Metric.infDist x L ≤ r}, M ∂sphereLaw d := lintegral_mono hfM + _ = M * sphereLaw d {x | Metric.infDist x L ≤ r} := by simp + _ ≤ _ := by + rw [mul_assoc] + exact mul_le_mul' le_rfl (sphere_affine_tube_quantitative L hd hr hr1) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Geometry/TupleMoments.lean b/lean/OAI/Probability/PosteriorReplicas/Geometry/TupleMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..7eff31d5b95e7cca1caf293b35be44172e2fa36f --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Geometry/TupleMoments.lean @@ -0,0 +1,110 @@ +import OAI.Probability.PosteriorReplicas.Geometry.AffineMoments +import OAI.Probability.PosteriorReplicas.Measures.PiTools + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +@[fun_prop] lemma continuous_differences {d m : ℕ} : Continuous (@differences d m) := by + unfold differences + fun_prop + +@[fun_prop] lemma continuous_affineVolume {d m : ℕ} : Continuous (@affineVolume d m) := by + unfold affineVolume + apply Real.continuous_sqrt.comp + apply Continuous.matrix_det + unfold Matrix.gram + fun_prop + +lemma measurableSet_row_independent {d k : ℕ} : + MeasurableSet {A : Rows d k | LinearIndependent ℝ A} := by + have he : {A : Rows d k | LinearIndependent ℝ A} = {A | (rowGram A).det ≠ 0} := by + ext A + exact ⟨fun h => (Matrix.posDef_gram_of_linearIndependent h).det_pos.ne', + fun h => Matrix.linearIndependent_of_det_gram_ne_zero (show (Matrix.gram ℝ A).det ≠ 0 from h)⟩ + rw [he] + exact (isClosed_eq continuous_rowGram.matrix_det continuous_const).isOpen_compl.measurableSet + +lemma measurableSet_affine_independent {d m : ℕ} : + MeasurableSet {u : Tuple d m | LinearIndependent ℝ (differences u)} := + measurableSet_row_independent.preimage continuous_differences.measurable + +@[simp] lemma differences_cons {d m : ℕ} (p : Vec d) (v : Fin m → Vec d) : + differences (Fin.cons p v : Tuple d m) = fun j => v j - p := by + funext j + simp only [PosteriorReplicas.differences, Fin.cons_succ, Fin.cons_zero] + +lemma ae_base_tuple_full_rank {d m : ℕ} (hd : 3 ≤ d) (hm : m < d) (base : BaseLaw) : + ∀ᵐ u : Tuple d m ∂Measure.pi (fun _ => base.measure d), + LinearIndependent ℝ (differences u) := by + have : NeZero d := ⟨by omega⟩ + rw [ae_pi_cons (base.measure d) measurableSet_affine_independent] + apply Filter.Eventually.of_forall + intro p + simpa only [differences_cons] using + ae_replica_independent_of_affine_null p m + (fun L _ hL => base_affine_null hd base L (by omega)) + +lemma ae_gaussian_rows_full_rank {d k : ℕ} (hd : 3 ≤ d) (hk : k < d) : + ∀ᵐ A ∂gaussianRows d k, LinearIndependent ℝ A := by + have h := ae_replica_independent_of_affine_null (ν := stdGaussian (Vec d)) (0 : Vec d) k + (fun L _ hL => base_affine_null hd .gaussian L (by omega)) + simpa only [sub_zero, gaussianRows] using h + +lemma base_tuple_inverse_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) (hm : 1 ≤ m) + (base : BaseLaw) : + (∫⁻ u : Tuple d m, (ENNReal.ofReal (affineVolume u))⁻¹ ^ k + ∂Measure.pi (fun _ => base.measure d)) < ∞ := by + have : NeZero d := ⟨by omega⟩ + have hrank := ae_base_tuple_full_rank (by omega : 3 ≤ d) (by omega : m < d) base + have he : (fun u : Tuple d m => (ENNReal.ofReal (affineVolume u))⁻¹ ^ k) =ᵐ[ + Measure.pi (fun _ => base.measure d)] + (fun u => ENNReal.ofReal ((affineVolume u)⁻¹ ^ k)) := by + filter_upwards [hrank] with u hu + have hp : 0 < affineVolume u := Real.sqrt_pos.mpr + (Matrix.posDef_gram_of_linearIndependent hu).det_pos + rw [ENNReal.ofReal_pow (by positivity), ENNReal.ofReal_inv_of_pos hp] + rw [lintegral_congr_ae he, + lintegral_pi_cons (base.measure d) (by fun_prop)] + let C : ℝ≥0∞ := 1 + (ENNReal.ofReal (baseProjectionConstant base d (k+1)) * 2^(k+1)) * 2^(k+1) + have hbound (p : Vec d) : + (∫⁻ v : Fin m → Vec d, ENNReal.ofReal + ((affineVolume (Fin.cons p v))⁻¹ ^ k) ∂Measure.pi (fun _ => base.measure d)) ≤ C^m := by + have h := replica_integral_of_affine_moment k m p C + (fun L _ hL => base_affine_inverse_bound hd hm base L hL) + simpa only [PosteriorRegression.replicaWeight_eq_det, + affineVolume, differences_cons] using h + apply lt_of_le_of_lt (lintegral_mono hbound) + simp only [lintegral_const, measure_univ, mul_one] + dsimp only [C] + finiteness + +lemma gaussian_rows_inverse_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) (hk : 1 ≤ k) : + (∫⁻ A : Rows d k, ENNReal.ofReal ((Real.sqrt (rowGram A).det)⁻¹ ^ m) + ∂gaussianRows d k) < ∞ := by + simpa only [rowGram_eq_gram, sub_zero, BaseLaw.measure, gaussianRows] using + base_replica_inverse_finite (k := m) (m := k) (by omega) hk .gaussian (0 : Vec d) + +lemma base_density_sup_moment_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) (hk : 1 ≤ k) + (base : BaseLaw) : + (∫⁻ A : Rows d k, ENNReal.ofReal + (baseProjectionConstant base d k / Real.sqrt (rowGram A).det) ^ m + ∂gaussianRows d k) < ∞ := by + have hc := (baseProjectionConstant_pos (by omega : k < d) base).le + have he (A : Rows d k) : ENNReal.ofReal + (baseProjectionConstant base d k / Real.sqrt (rowGram A).det) ^ m = + ENNReal.ofReal (baseProjectionConstant base d k)^m * + ENNReal.ofReal ((Real.sqrt (rowGram A).det)⁻¹ ^ m) := by + rw [div_eq_mul_inv, ENNReal.ofReal_mul hc, mul_pow, + ENNReal.ofReal_pow (by positivity)] + simp_rw [he] + rw [lintegral_const_mul _ (by fun_prop)] + exact ENNReal.mul_lt_top (by finiteness) (gaussian_rows_inverse_finite hd hk) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/BinCutoff.lean b/lean/OAI/Probability/PosteriorReplicas/Information/BinCutoff.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ced6de69e33daf4265f1b0aa610448dbdf4b91a --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/BinCutoff.lean @@ -0,0 +1,67 @@ +import Mathlib + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +def binCutoff (d k : ℕ) (L : ℝ) : ℕ := 7*d+k+2+Nat.ceil (2*Real.log L) + +lemma real_pow_cutoff {d k : ℕ} {L : ℝ} (hL : 1 ≤ L) : + L*(72:ℝ)^d*(1/2)^binCutoff d k L*(1+2^(k+1)) ≤ 1 := by + have hLp : 0 < L := by linarith + have hl : 0 ≤ Real.log L := Real.log_nonneg hL + have hl2 : (1/2:ℝ) ≤ Real.log 2 := by linarith [Real.log_two_gt_d9] + have hceil := Nat.le_ceil (2*Real.log L) + have hpowL : L ≤ (2:ℝ)^Nat.ceil (2*Real.log L) := by + apply (Real.log_le_log_iff hLp (by positivity)).mp + rw [Real.log_pow] + nlinarith [mul_le_mul_of_nonneg_left hl2 (Nat.cast_nonneg (α:=ℝ) (Nat.ceil (2*Real.log L)))] + have h72 : (72:ℝ)^d ≤ 2^(7*d) := by + calc + _ ≤ ((2:ℝ)^7)^d := pow_le_pow_left₀ (by norm_num) (by norm_num) d + _ = _ := (pow_mul _ _ _).symm + have hsum : (1:ℝ)+2^(k+1) ≤ 2^(k+2) := by + have h := one_le_pow₀ (show (1:ℝ)≤2 by norm_num) (n:=k+1) + norm_num [pow_add] at h ⊢ + linarith + have hp : L*(72:ℝ)^d*(1+2^(k+1)) ≤ 2^binCutoff d k L := by + calc + _ ≤ (2:ℝ)^Nat.ceil (2*Real.log L)*2^(7*d)*2^(k+2) := + mul_le_mul (mul_le_mul hpowL h72 (by positivity) (by positivity)) hsum (by positivity) (by positivity) + _ = _ := by rw [← pow_add,← pow_add]; congr 1; unfold binCutoff; omega + calc + _ = (L*(72:ℝ)^d*(1+2^(k+1)))*(1/2)^binCutoff d k L := by ring + _ ≤ (2:ℝ)^binCutoff d k L * (1/2)^binCutoff d k L := mul_le_mul_of_nonneg_right hp (by positivity) + _ = 1 := by rw [← mul_pow]; norm_num + +lemma binCutoff_bound {d k : ℕ} (hk : k≤d) {L : ℝ} (hL : 1≤L) : + (binCutoff d k L : ℝ)+2 ≤ 16*(1+(d:ℝ)+Real.log L) := by + have hceil := (Nat.ceil_lt_add_one (mul_nonneg (by norm_num : (0:ℝ)≤2) (Real.log_nonneg hL))).le + have hkr : (k:ℝ)≤d := by exact_mod_cast hk + unfold binCutoff + push_cast + nlinarith [Nat.cast_nonneg (α:=ℝ) d,Real.log_nonneg hL] + +lemma binCutoff_valid {d k : ℕ} {L : ℝ} (hL : 1≤L) : + (ENNReal.ofReal L*ENNReal.ofReal ((72:ℝ)^d))*ENNReal.ofReal ((1/2:ℝ)^binCutoff d k L)* + (1+(2:ℝ≥0∞)^(k+1)) ≤ 1 := by + have hh := ENNReal.ofReal_le_ofReal (real_pow_cutoff (d:=d) (k:=k) hL) + have hL0 : 0 ≤ L := by linarith + rw [ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_mul hL0, + ENNReal.ofReal_add (by norm_num) (by positivity),ENNReal.ofReal_pow (by norm_num : (0:ℝ)≤2)] at hh + simpa only [ENNReal.ofReal_one,ENNReal.ofReal_ofNat] using hh + +lemma binCutoff_log_bound {d k : ℕ} (hk : k≤d) {L : ℝ} (hL : 1≤L) : + Real.log ((binCutoff d k L:ℝ)+2) ≤ 16+Real.log (1+(d:ℝ)+Real.log L) := by + have ha : 0 < 1+(d:ℝ)+Real.log L := by linarith [Nat.cast_nonneg (α:=ℝ) d,Real.log_nonneg hL] + have hh := Real.log_le_log (by positivity : 0<(binCutoff d k L:ℝ)+2) (binCutoff_bound hk hL) + rw [Real.log_mul (by norm_num) ha.ne'] at hh + linarith [Real.log_le_self (by norm_num : (0:ℝ)≤16)] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/CmiKernel.lean b/lean/OAI/Probability/PosteriorReplicas/Information/CmiKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..00882b4ab857c57f1105856c43119d4a6635a3f1 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/CmiKernel.lean @@ -0,0 +1,88 @@ +import OAI.Probability.PosteriorReplicas.Information.ReplicaInformation + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +section +variable {Z X Y : Type*} [MeasurableSpace Z] [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + (μ : Measure Z) [IsFiniteMeasure μ] (κ : Kernel Z (X × Y)) [IsMarkovKernel κ] + +lemma cmi_compProd : cmi (μ ⊗ₘ κ) = klDiv (μ ⊗ₘ κ) (μ ⊗ₘ (κ.fst ×ₖ κ.snd)) := by + unfold cmi + rw [Measure.fst_compProd] + congr 1 + apply Measure.compProd_congr + filter_upwards [condKernel_compProd μ κ] with z hz + simp only [Kernel.prod_apply, Kernel.fst_apply, Kernel.snd_apply, hz] + +lemma cmi_compProd_integral : cmi (μ ⊗ₘ κ) = + ∫⁻ z, mutualInformation (κ z) ∂μ := by + rw [cmi_compProd, klDiv_compProd_kernel] + simp only [mutualInformation, Kernel.prod_apply, Kernel.fst_apply, Kernel.snd_apply, + Measure.fst, Measure.snd] +end + +lemma kernel_compProd_eval {T Z V : Type*} + [MeasurableSpace T] [MeasurableSpace Z] [MeasurableSpace V] + (κ : Kernel T Z) [IsSFiniteKernel κ] (η : Kernel (T × Z) V) [IsSFiniteKernel η] (t : T) : + (κ ⊗ₖ η) t = κ t ⊗ₘ η.comap (fun z => (t,z)) (by fun_prop) := by + ext s hs + rw [Kernel.compProd_apply hs, Measure.compProd_apply hs] + rfl + +section Tower +variable {T Z X Y : Type*} [MeasurableSpace T] [MeasurableSpace Z] + [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace Z] [StandardBorelSpace X] [StandardBorelSpace Y] + [Nonempty X] [Nonempty Y] + (μ : Measure T) [IsFiniteMeasure μ] + (κ : Kernel T (Z × (X × Y))) [IsMarkovKernel κ] + +lemma cmi_kernel_measurable : Measurable (fun t => cmi (κ t)) := by + have he (t : T) : cmi (κ t) = klDiv (κ t) + ((κ.fst ⊗ₖ (κ.condKernel.fst ×ₖ κ.condKernel.snd)) t) := by + unfold cmi + congr 1 + rw [kernel_compProd_eval] + have hf : (κ t).fst = κ.fst t := (Kernel.fst_apply κ t).symm + rw [hf] + apply Measure.compProd_congr + filter_upwards [κ.condKernel_apply_eq_condKernel t] with z hz + simp only [Kernel.comap_apply, Kernel.prod_apply, Kernel.fst_apply, Kernel.snd_apply] + rw [hz] + simp_rw [he] + exact measurable_kernel_klDiv _ _ + +lemma cmi_compProd_assoc : + cmi ((μ ⊗ₘ κ).map (MeasurableEquiv.prodAssoc.symm : + T × (Z × (X × Y)) ≃ᵐ (T × Z) × (X × Y))) = ∫⁻ t, cmi (κ t) ∂μ := by + have ha : (μ ⊗ₘ κ).map (MeasurableEquiv.prodAssoc.symm : + T × (Z × (X × Y)) ≃ᵐ (T × Z) × (X × Y)) = + (μ ⊗ₘ κ.fst) ⊗ₘ κ.condKernel := by + conv_lhs => rw [← Kernel.disintegrate κ κ.condKernel] + exact Measure.compProd_assoc + simp only [ha] + rw [cmi_compProd_integral, Measure.lintegral_compProd] + · apply lintegral_congr + intro t + rw [cmi_eq_kernel_integral] + have hf : (κ t).fst = κ.fst t := (Kernel.fst_apply κ t).symm + rw [hf] + apply lintegral_congr_ae + filter_upwards [κ.condKernel_apply_eq_condKernel t] with z hz + unfold mutualInformation + rw [hz] + · simpa only [mutualInformation, Kernel.prod_apply, Kernel.fst_apply, Kernel.snd_apply, + Measure.fst, Measure.snd] using + measurable_kernel_klDiv κ.condKernel (κ.condKernel.fst ×ₖ κ.condKernel.snd) +end Tower + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ConditionalKL.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ConditionalKL.lean new file mode 100644 index 0000000000000000000000000000000000000000..71dd21b6182bc2316dc3d8739a2e39694b28dfdf --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ConditionalKL.lean @@ -0,0 +1,73 @@ +import OAI.Probability.PosteriorReplicas.Information.KLTools +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +section Conditional +variable {Z X Y : Type*} [MeasurableSpace Z] [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + (μ : Measure Z) [IsFiniteMeasure μ] + (κ : Kernel Z (X × Y)) (η : Kernel Z X) (ρ : Kernel Z Y) + [IsMarkovKernel κ] [IsMarkovKernel η] [IsMarkovKernel ρ] + +lemma klDiv_kernel_prod_decomposition : + klDiv (μ ⊗ₘ κ) (μ ⊗ₘ (η ×ₖ ρ)) = + klDiv (μ ⊗ₘ κ) (μ ⊗ₘ (κ.fst ×ₖ κ.snd)) + + klDiv (μ ⊗ₘ κ.fst) (μ ⊗ₘ η) + klDiv (μ ⊗ₘ κ.snd) (μ ⊗ₘ ρ) := by + simp_rw [klDiv_compProd_kernel] + calc + _ = ∫⁻ z, (klDiv (κ z) ((κ.fst ×ₖ κ.snd) z) + + klDiv (κ.fst z) (η z)) + klDiv (κ.snd z) (ρ z) ∂μ := by + apply lintegral_congr + intro z + have h := klDiv_prod_decomposition (κ z) (η z) (ρ z) + simpa only [Kernel.prod_apply, Kernel.fst_apply, Kernel.snd_apply, + Measure.fst, Measure.snd, add_assoc, add_comm, add_left_comm] using h + _ = _ := by + rw [lintegral_add_aux (by + exact ((measurable_kernel_klDiv κ (κ.fst ×ₖ κ.snd)).add + (measurable_kernel_klDiv κ.fst η))) + (measurable_kernel_klDiv κ.snd ρ), + lintegral_add_aux (measurable_kernel_klDiv κ (κ.fst ×ₖ κ.snd)) + (measurable_kernel_klDiv κ.fst η)] + +end Conditional + +lemma cmi_eq_kernel_integral {Z X Y : Type*} + [MeasurableSpace Z] [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + (q : Measure (Z × (X × Y))) [IsFiniteMeasure q] : + cmi q = ∫⁻ z, klDiv (q.condKernel z) + ((q.condKernel z).fst.prod (q.condKernel z).snd) ∂q.fst := by + unfold cmi + conv_lhs => lhs; rw [← Measure.disintegrate q q.condKernel] + rw [klDiv_compProd_kernel] + simp only [Kernel.prod_apply, Kernel.fst_apply, Kernel.snd_apply, Measure.fst, Measure.snd] + +lemma klDiv_conditional_chain {Z X Y : Type*} + [MeasurableSpace Z] [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + (q : Measure (Z × (X × Y))) [IsProbabilityMeasure q] + (ν : Measure Y) [IsProbabilityMeasure ν] : + klDiv q (q.fst ⊗ₘ (q.condKernel.fst ×ₖ Kernel.const Z ν)) = + cmi q + klDiv (q.map (fun z => (z.1, z.2.2))) (q.fst.prod ν) := by + have h := klDiv_kernel_prod_decomposition q.fst q.condKernel q.condKernel.fst + (Kernel.const Z ν) + rw [Measure.disintegrate q q.condKernel, klDiv_self, add_zero, Measure.compProd_const] at h + rw [Kernel.snd_eq, Measure.compProd_map measurable_snd, + Measure.disintegrate q q.condKernel] at h + have hm : (Prod.map id Prod.snd : Z × (X × Y) → Z × Y) = (fun z => (z.1,z.2.2)) := by + funext z + rfl + rw [hm] at h + simpa only [cmi, Kernel.snd_eq] using h + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ConditionalPiKL.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ConditionalPiKL.lean new file mode 100644 index 0000000000000000000000000000000000000000..867b6dfd66f4f794abd748fe1b18d6055e9f1103 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ConditionalPiKL.lean @@ -0,0 +1,107 @@ +import OAI.Probability.PosteriorReplicas.Information.ConditionalKL +import OAI.Probability.PosteriorReplicas.Information.PiKL + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +section ConditionalPi +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace Y] [Nonempty Y] {n : ℕ} + (μ : Measure X) [IsProbabilityMeasure μ] + (κ : Kernel X (Fin n → Y)) [IsMarkovKernel κ] + +def coordKernel (i : Fin n) : Kernel X Y := κ.map (fun u => u i) +instance coordKernel_markov (i : Fin n) : IsMarkovKernel (coordKernel κ i) := + Kernel.IsMarkovKernel.map _ (measurable_pi_apply i) + +omit [StandardBorelSpace Y] [Nonempty Y] [IsMarkovKernel κ] in +lemma coordKernel_apply (i : Fin n) (x : X) : coordKernel κ i x = coordinateMarginal (κ x) i := + Kernel.map_apply _ (measurable_pi_apply i) _ + +def conditionalTotalCorrelation : ℝ≥0∞ := + klDiv (μ ⊗ₘ κ) (μ ⊗ₘ piKernel (coordKernel κ)) + +omit [Nonempty Y] in +lemma conditionalTotalCorrelation_integral : + conditionalTotalCorrelation μ κ = ∫⁻ x, klDiv (κ x) (marginalProduct (κ x)) ∂μ := by + rw [conditionalTotalCorrelation, klDiv_compProd_kernel] + apply lintegral_congr + intro x + rw [piKernel_apply] + simp_rw [coordKernel_apply, marginalProduct] + +lemma klDiv_conditional_pi_decomposition (ρ : Fin n → Measure Y) [∀ i, IsProbabilityMeasure (ρ i)] : + klDiv (μ ⊗ₘ κ) (μ.prod (Measure.pi ρ)) = conditionalTotalCorrelation μ κ + + ∑ i, klDiv (μ ⊗ₘ coordKernel κ i) (μ.prod (ρ i)) := by + simp_rw [← Measure.compProd_const, klDiv_compProd_kernel] + rw [conditionalTotalCorrelation_integral] + calc + _ = ∫⁻ x, klDiv (κ x) (marginalProduct (κ x)) + + ∑ i, klDiv (coordinateMarginal (κ x) i) (ρ i) ∂μ := by + exact lintegral_congr fun x => klDiv_pi_decomposition (κ x) ρ + _ = _ := by + have hc : Measurable (fun x => klDiv (κ x) (marginalProduct (κ x))) := by + simpa only [piKernel_apply, coordKernel_apply, marginalProduct] using + (measurable_kernel_klDiv κ (piKernel (coordKernel κ))) + have hi : ∀ i, Measurable (fun x => klDiv (coordinateMarginal (κ x) i) (ρ i)) := by + intro i + simpa only [coordKernel_apply, Kernel.const_apply] using + (measurable_kernel_klDiv (coordKernel κ i) (Kernel.const X (ρ i))) + rw [lintegral_add_aux hc (Finset.measurable_sum _ (fun i _ => hi i)), + lintegral_finsetSum _ (fun i _ => hi i)] + simp_rw [coordKernel_apply, Kernel.const_apply] + +lemma conditionalTotalCorrelation_identity [StandardBorelSpace X] [Nonempty X] : + conditionalTotalCorrelation μ κ + + ∑ i, klDiv (μ ⊗ₘ coordKernel κ i) + (μ.prod (coordinateMarginal (μ ⊗ₘ κ).snd i)) = + klDiv (μ ⊗ₘ κ).snd (marginalProduct (μ ⊗ₘ κ).snd) + + klDiv (μ ⊗ₘ κ) (μ.prod (μ ⊗ₘ κ).snd) := by + rw [← klDiv_conditional_pi_decomposition] + rw [klDiv_prod_decomposition, Measure.fst_compProd, klDiv_self, zero_add] + rfl + +end ConditionalPi + +section Projection +variable {X Y Z : Type*} [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + [StandardBorelSpace Y] [Nonempty Y] [StandardBorelSpace Z] [Nonempty Z] + {n : ℕ} (μ : Measure X) [IsProbabilityMeasure μ] + (κ : Kernel X (Fin n → Y)) [IsMarkovKernel κ] + {g : Y → Z} (hg : Measurable g) +include hg + +omit [StandardBorelSpace Y] [Nonempty Y] [StandardBorelSpace Z] [Nonempty Z] in +lemma marginalProduct_map (ν : Measure (Fin n → Y)) [IsProbabilityMeasure ν] : + marginalProduct (ν.map (fun u i => g (u i))) = + (marginalProduct ν).map (fun u i => g (u i)) := by + unfold marginalProduct coordinateMarginal + have he : (fun i : Fin n => (ν.map (fun u j => g (u j))).map (fun u => u i)) = + fun i => (ν.map (fun u => u i)).map g := by + funext i + rw [Measure.map_map (measurable_pi_apply i) (by fun_prop), + Measure.map_map hg (measurable_pi_apply i)] + rfl + rw [he] + exact (Measure.pi_map_pi (fun _ : Fin n => hg.aemeasurable)).symm + +omit [Nonempty Y] [Nonempty Z] in +lemma conditionalTotalCorrelation_map_le : + conditionalTotalCorrelation μ (κ.map (fun u i => g (u i))) ≤ conditionalTotalCorrelation μ κ := by + let : IsMarkovKernel (κ.map (fun u i => g (u i))) := Kernel.IsMarkovKernel.map _ (by fun_prop) + rw [conditionalTotalCorrelation_integral, conditionalTotalCorrelation_integral] + apply lintegral_mono + intro x + dsimp only + rw [Kernel.map_apply _ (show Measurable (fun u : Fin n → Y => fun i => g (u i)) by fun_prop), marginalProduct_map hg] + exact klDiv_map_le _ _ (by fun_prop) + +end Projection +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/EntropyLossTest.lean b/lean/OAI/Probability/PosteriorReplicas/Information/EntropyLossTest.lean new file mode 100644 index 0000000000000000000000000000000000000000..e39aeb975ae1a8ee00cffd8181412c2fc735bd13 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/EntropyLossTest.lean @@ -0,0 +1,50 @@ +import OAI.Probability.PosteriorReplicas.Information.EntropyTest + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma entropy_loss_test {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ ν : Measure X) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (hkl : klDiv μ ν ≠ ∞) {ψ : X → Y} (hψ : Measurable ψ) + {g : Y → ℝ} (hg : Measurable g) + (he : Integrable (fun y => Real.exp (g y)) (ν.map ψ)) + (hmean : (∫ y, Real.exp (g y) ∂ν.map ψ) ≤ 1) + (herr : Integrable (fun x => max (llr μ ν x - g (ψ x)) 0) μ) : + Integrable (fun x => g (ψ x)) μ ∧ + Integrable (fun x => llr μ ν x - g (ψ x)) μ ∧ + (klDiv μ ν).toReal ≤ (klDiv (μ.map ψ) (ν.map ψ)).toReal + + ∫ x, llr μ ν x - g (ψ x) ∂μ := by + have hkl' : klDiv (μ.map ψ) (ν.map ψ) ≠ ∞ := ne_top_of_le_ne_top hkl (klDiv_map_le μ ν hψ) + obtain ⟨hac,hllr⟩ := klDiv_ne_top_iff.mp hkl + have hp := (entropy_test_positive_integrable (μ.map ψ) (ν.map ψ) hkl' hg he).comp_measurable hψ + have hb := (hllr.norm.add hp).add herr + have hgi : Integrable (fun x => g (ψ x)) μ := by + apply hb.mono' (hg.comp hψ).aestronglyMeasurable + apply ae_of_all + intro x + simp only [Pi.add_apply, Function.comp_def, Real.norm_eq_abs] + apply abs_le.mpr + constructor + · have h₁ := neg_abs_le (llr μ ν x) + have h₂ := le_max_left (llr μ ν x-g (ψ x)) 0 + have h₃ := le_max_right (g (ψ x)) 0 + linarith + · have h₁ := le_max_left (g (ψ x)) 0 + have h₂ := abs_nonneg (llr μ ν x) + have h₃ := le_max_right (llr μ ν x-g (ψ x)) 0 + linarith + refine ⟨hgi,hllr.sub hgi,?_⟩ + have hgm : Integrable g (μ.map ψ) := (integrable_map_measure hg.aestronglyMeasurable hψ.aemeasurable).mpr hgi + have ht := entropy_test_normalized (μ.map ψ) (ν.map ψ) hkl' hgm he hmean + rw [integral_map hψ.aemeasurable hg.aestronglyMeasurable] at ht + rw [toReal_klDiv_of_measure_eq hac (by simp), integral_sub hllr hgi] + linarith + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/EntropyTest.lean b/lean/OAI/Probability/PosteriorReplicas/Information/EntropyTest.lean new file mode 100644 index 0000000000000000000000000000000000000000..9968fa96ef5c6310ad51420da698bd0c45be1109 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/EntropyTest.lean @@ -0,0 +1,82 @@ +import Mathlib + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +variable {X : Type*} [MeasurableSpace X] + +lemma integrable_exp_neg_llr (μ ν : Measure X) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (hac : μ ≪ ν) : Integrable (fun x => Real.exp (-llr μ ν x)) μ := by + exact ν.integrable_toReal_rnDeriv.congr (exp_neg_llr hac).symm + +lemma entropy_test_positive_integrable (μ ν : Measure X) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (hkl : klDiv μ ν ≠ ∞) {g : X → ℝ} (hg : Measurable g) + (he : Integrable (fun x => Real.exp (g x)) ν) : + Integrable (fun x => max (g x) 0) μ := by + obtain ⟨hac,hllr⟩ := klDiv_ne_top_iff.mp hkl + have : IsProbabilityMeasure (ν.tilted g) := isProbabilityMeasure_tilted he + have hac' : μ ≪ ν.tilted g := hac.trans (absolutelyContinuous_tilted he) + have hi := (hllr.norm.add (integrable_exp_neg_llr μ (ν.tilted g) hac')).add + (integrable_const |Real.log (∫ x, Real.exp (g x) ∂ν)|) + apply hi.mono' (by fun_prop) + filter_upwards [llr_tilted_right hac he] with x hx + rw [Real.norm_eq_abs, abs_of_nonneg (le_max_right _ 0)] + simp only [Pi.add_apply, Real.norm_eq_abs] + apply max_le + · have h₁ := Real.add_one_le_exp (-llr μ (ν.tilted g) x) + have h₂ := le_abs_self (llr μ ν x) + have h₃ := le_abs_self (Real.log (∫ x, Real.exp (g x) ∂ν)) + linarith + · positivity + +lemma entropy_test_integral (μ ν : Measure X) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (hkl : klDiv μ ν ≠ ∞) {g : X → ℝ} (hg : Integrable g μ) + (he : Integrable (fun x => Real.exp (g x)) ν) : + (∫ x, g x ∂μ) ≤ (klDiv μ ν).toReal + Real.log (∫ x, Real.exp (g x) ∂ν) := by + obtain ⟨hac,hllr⟩ := klDiv_ne_top_iff.mp hkl + have : IsProbabilityMeasure (ν.tilted g) := isProbabilityMeasure_tilted he + have hnon := integral_llr_add_sub_measure_univ_nonneg + (hac.trans (absolutelyContinuous_tilted he)) (integrable_llr_tilted_right hac hg hllr he) + rw [integral_llr_tilted_right hac hg he hllr] at hnon + rw [toReal_klDiv_of_measure_eq hac (by simp)] + simp only [probReal_univ, add_sub_cancel_right] at hnon + linarith + +lemma entropy_test_normalized (μ ν : Measure X) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (hkl : klDiv μ ν ≠ ∞) {g : X → ℝ} (hg : Integrable g μ) + (he : Integrable (fun x => Real.exp (g x)) ν) + (hmean : (∫ x, Real.exp (g x) ∂ν) ≤ 1) : + (∫ x, g x ∂μ) ≤ (klDiv μ ν).toReal := by + have h := entropy_test_integral μ ν hkl hg he + have hlog : Real.log (∫ x, Real.exp (g x) ∂ν) ≤ 0 := + Real.log_nonpos (integral_nonneg (fun _ => (Real.exp_pos _).le)) hmean + linarith + +lemma llr_withDensity_ae (ν : Measure X) [SigmaFinite ν] {g : X → ℝ≥0∞} + (hg : Measurable g) [IsFiniteMeasure (ν.withDensity g)] : + llr (ν.withDensity g) ν =ᵐ[ν.withDensity g] (fun x => Real.log (g x).toReal) := by + filter_upwards [(withDensity_absolutelyContinuous ν g).ae_le (ν.rnDeriv_withDensity hg)] with x hx + exact congrArg (fun t : ℝ≥0∞ => Real.log t.toReal) hx + +lemma klDiv_withDensity_eq (ν : Measure X) [IsProbabilityMeasure ν] {g : X → ℝ≥0∞} + (hg : Measurable g) [IsProbabilityMeasure (ν.withDensity g)] + (hi : Integrable (fun x => Real.log (g x).toReal) (ν.withDensity g)) : + klDiv (ν.withDensity g) ν = ENNReal.ofReal (∫ x, Real.log (g x).toReal ∂ν.withDensity g) := by + have hi' : Integrable (llr (ν.withDensity g) ν) (ν.withDensity g) := + hi.congr (llr_withDensity_ae ν hg).symm + rw [klDiv_of_ac_of_integrable (withDensity_absolutelyContinuous ν g) hi'] + simp only [probReal_univ, add_sub_cancel_right] + congr 1 + exact integral_congr_ae (llr_withDensity_ae ν hg) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/FiniteConditionalEntropy.lean b/lean/OAI/Probability/PosteriorReplicas/Information/FiniteConditionalEntropy.lean new file mode 100644 index 0000000000000000000000000000000000000000..3cfbc6bad4e7df9913c17bde0b44d35257f0807f --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/FiniteConditionalEntropy.lean @@ -0,0 +1,54 @@ +import OAI.Probability.PosteriorReplicas.Information.FiniteEntropyBounds + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma neg_mul_log_product {p q : ℝ} (hp : 0 ≤ p) (hq : 0 ≤ q) : + -(p*q)*Real.log (p*q) = q*(-p*Real.log p)+p*(-q*Real.log q) := by + rcases hp.eq_or_lt with hp0 | hp0 + · simp [← hp0] + rcases hq.eq_or_lt with hq0 | hq0 + · simp [← hq0] + rw [Real.log_mul (ne_of_gt hp0) (ne_of_gt hq0)] + ring + +section +variable {V W : Type*} [Fintype V] [Fintype W] [MeasurableSpace V] [MeasurableSpace W] + [MeasurableSingletonClass V] [MeasurableSingletonClass W] + (μ : Measure V) [IsProbabilityMeasure μ] (κ : Kernel V W) [IsMarkovKernel κ] + +omit [Fintype W] [IsProbabilityMeasure μ] in +lemma compProd_real_singleton (v : V) (w : W) : + (μ ⊗ₘ κ).real {(v,w)} = μ.real {v} * (κ v).real {w} := by + rw [measureReal_def,← singleton_prod_singleton, + Measure.compProd_apply_prod (measurableSet_singleton v) (measurableSet_singleton w), + lintegral_singleton,ENNReal.toReal_mul] + exact mul_comm _ _ + +omit [IsProbabilityMeasure μ] in +lemma finiteEntropy_compProd : + finiteEntropy (μ ⊗ₘ κ) = finiteEntropy μ + ∑ v, μ.real {v} * finiteEntropy (κ v) := by + unfold finiteEntropy + rw [Fintype.sum_prod_type] + simp_rw [compProd_real_singleton,neg_mul_log_product measureReal_nonneg measureReal_nonneg] + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro v _ + rw [Finset.sum_add_distrib,← Finset.sum_mul,← Finset.mul_sum, + sum_probability_atoms (κ v),one_mul] + +omit [IsProbabilityMeasure μ] in +lemma finiteEntropy_compProd_conditional : + finiteEntropy (μ ⊗ₘ κ) - finiteEntropy μ = ∑ v, μ.real {v} * finiteEntropy (κ v) := by + rw [finiteEntropy_compProd] + ring + +end +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/FiniteEntropyBounds.lean b/lean/OAI/Probability/PosteriorReplicas/Information/FiniteEntropyBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..808839754338696115cba818570af1927a80cf8c --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/FiniteEntropyBounds.lean @@ -0,0 +1,82 @@ +import OAI.Probability.PosteriorReplicas.Information.FiniteKL + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma sum_probability_atoms {W : Type*} [Fintype W] [MeasurableSpace W] + [MeasurableSingletonClass W] (q : Measure W) [IsProbabilityMeasure q] : + ∑ w, q.real {w} = 1 := by + simp + +lemma neg_mul_log_le_tangent {p r : ℝ} (hp : 0 ≤ p) (hr : 0 < r) : + -p*Real.log p ≤ -p*Real.log r + r-p := by + rcases hp.eq_or_lt with h | h + · subst p + simpa using hr.le + · have hl := Real.one_sub_inv_le_log_of_pos (div_pos h hr) + rw [Real.log_div h.ne' hr.ne', inv_div] at hl + have hh := mul_le_mul_of_nonneg_left hl h.le + rw [mul_sub, mul_div_cancel₀ _ h.ne'] at hh + nlinarith + +lemma finiteEntropy_le_log_card {W : Type*} [Fintype W] [Nonempty W] [MeasurableSpace W] + [MeasurableSingletonClass W] (q : Measure W) [IsProbabilityMeasure q] : + finiteEntropy q ≤ Real.log (Fintype.card W : ℝ) := by + have hn : 0 < (Fintype.card W : ℝ) := by exact_mod_cast Fintype.card_pos + have h := Finset.sum_le_sum (s := Finset.univ) (fun w _ => + neg_mul_log_le_tangent (measureReal_nonneg (μ := q) (s := {w})) (inv_pos.mpr hn)) + simp only [Real.log_inv, neg_mul_neg, Finset.sum_sub_distrib, Finset.sum_add_distrib, + ← Finset.sum_mul, sum_probability_atoms q, Finset.sum_const, Finset.card_univ, + nsmul_eq_mul, mul_inv_cancel₀ hn.ne', one_mul, add_sub_cancel_right] at h + exact h + +lemma log_le_tangent {x a : ℝ} (hx : 0 < x) (ha : 0 < a) : + Real.log x ≤ Real.log a + x/a - 1 := by + have h := Real.log_le_sub_one_of_pos (div_pos hx ha) + rw [Real.log_div hx.ne' ha.ne'] at h + linarith + +lemma finite_weighted_log_le {W : Type*} [Fintype W] (p x : W → ℝ) + (hp : ∀ w, 0 ≤ p w) (hpsum : ∑ w, p w = 1) (hx : ∀ w, 0 < x w) : + ∑ w, p w * Real.log (x w) ≤ Real.log (∑ w, p w*x w) := by + have ha : 0 < ∑ w, p w*x w := by + have he : ∃ w, 0 < p w := by + by_contra! hh + have hz : ∑ w, p w = 0 := Finset.sum_eq_zero (fun w _ => le_antisymm (hh w) (hp w)) + linarith + obtain ⟨w,hw⟩ := he + exact Finset.sum_pos' (fun w _ => mul_nonneg (hp w) (hx w).le) + ⟨w,Finset.mem_univ w,mul_pos hw (hx w)⟩ + have h := Finset.sum_le_sum (s := Finset.univ) (fun w _ => + mul_le_mul_of_nonneg_left (log_le_tangent (hx w) ha) (hp w)) + simp only [mul_sub,mul_add,← mul_div_assoc,mul_one] at h + rw [Finset.sum_sub_distrib,Finset.sum_add_distrib,← Finset.sum_mul,← Finset.sum_div, + hpsum,one_mul,div_self ha.ne',add_sub_cancel_right] at h + exact h + +lemma finiteEntropy_log_average {W : Type*} [Fintype W] [MeasurableSpace W] + [MeasurableSingletonClass W] (q : Measure W) [IsProbabilityMeasure q] + {a : ℝ} (ha : 0 < a) : + ∑ w, q.real {w} * Real.log (a - Real.log (q.real {w})) ≤ + Real.log (a + finiteEntropy q) := by + have hx (w : W) : 0 < a - Real.log (q.real {w}) := by + have hlog := Real.log_nonpos (measureReal_nonneg (μ := q) (s := {w})) + (measureReal_le_one (μ := q) (s := {w})) + linarith + have h := finite_weighted_log_le (fun w => q.real {w}) + (fun w => a - Real.log (q.real {w})) (fun _ => measureReal_nonneg) + (sum_probability_atoms q) hx + have he : ∑ w, q.real {w}*(a-Real.log (q.real {w})) = a+finiteEntropy q := by + simp_rw [mul_sub] + rw [Finset.sum_sub_distrib,← Finset.sum_mul,sum_probability_atoms q,one_mul] + simp only [finiteEntropy,neg_mul,Finset.sum_neg_distrib,sub_eq_add_neg] + rwa [he] at h + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/FiniteKL.lean b/lean/OAI/Probability/PosteriorReplicas/Information/FiniteKL.lean new file mode 100644 index 0000000000000000000000000000000000000000..7e19a2be33fd92b4d893dd9270f619f83da3cc5d --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/FiniteKL.lean @@ -0,0 +1,152 @@ +import OAI.Probability.PosteriorReplicas.Information.ConditionalKL + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +section Finite +variable {W : Type*} [Fintype W] [MeasurableSpace W] [MeasurableSingletonClass W] + +omit [MeasurableSingletonClass W] in +lemma finite_ac_of_singleton {μ ν : Measure W} + (h : ∀ w, ν {w} = 0 → μ {w} = 0) : μ ≪ ν := by + intro s hs + apply measure_eq_zero_iff_ae_notMem.mpr + apply ae_iff_of_countable.mpr + intro w hw hws + exact hw (h w (measure_mono_null (singleton_subset_iff.mpr hws) hs)) + +lemma finite_withDensity_ratio (μ ν : Measure W) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (hac : μ ≪ ν) : ν.withDensity (fun w => μ {w} / ν {w}) = μ := by + apply Measure.ext_of_singleton + intro w + rw [withDensity_apply _ (measurableSet_singleton w), lintegral_singleton] + by_cases h : ν {w} = 0 + · simp [h, hac h] + · exact ENNReal.div_mul_cancel h (measure_ne_top ν {w}) + +lemma finite_llr_ratio (μ ν : Measure W) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (hac : μ ≪ ν) : llr μ ν =ᵐ[μ] (fun w => Real.log (μ.real {w} / ν.real {w})) := by + have hd : μ.rnDeriv ν =ᵐ[ν] (fun w => μ {w} / ν {w}) := by + conv_lhs => rw [← finite_withDensity_ratio μ ν hac] + exact Measure.rnDeriv_withDensity _ (measurable_of_countable _) + filter_upwards [hac.ae_le hd] with w hw + simp only [llr, hw, ENNReal.toReal_div, measureReal_def] + +lemma finite_klDiv_formula (μ ν : Measure W) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (hac : μ ≪ ν) : + klDiv μ ν = ENNReal.ofReal (∑ w, μ.real {w} * Real.log (μ.real {w} / ν.real {w})) := by + rw [klDiv_of_ac_of_integrable hac Integrable.of_finite] + rw [integral_congr_ae (finite_llr_ratio μ ν hac), integral_fintype Integrable.of_finite] + simp [smul_eq_mul, measureReal_def] + +lemma finite_klDiv_le_crossEntropy (μ ν : Measure W) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] (hac : μ ≪ ν) : + klDiv μ ν ≤ ENNReal.ofReal (∑ w, μ.real {w} * (-Real.log (ν.real {w}))) := by + rw [finite_klDiv_formula μ ν hac] + apply ENNReal.ofReal_le_ofReal + apply Finset.sum_le_sum + intro w _ + by_cases hw : μ {w} = 0 + · simp [measureReal_def, hw] + · have hw' : 0 < μ.real {w} := ENNReal.toReal_pos hw (measure_ne_top μ {w}) + have hv : ν {w} ≠ 0 := fun h => hw (hac h) + have hv' : 0 < ν.real {w} := ENNReal.toReal_pos hv (measure_ne_top ν {w}) + rw [Real.log_div hw'.ne' hv'.ne'] + apply mul_le_mul_of_nonneg_left _ hw'.le + have hl := Real.log_nonpos hw'.le (measureReal_le_one (μ := μ) (s := {w})) + linarith + +omit [MeasurableSingletonClass W] in +lemma finite_crossEntropy_nonneg (μ ν : Measure W) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] : + 0 ≤ ∑ w, μ.real {w} * (-Real.log (ν.real {w})) := by + apply Finset.sum_nonneg + intro w _ + apply mul_nonneg measureReal_nonneg + exact neg_nonneg.mpr (Real.log_nonpos measureReal_nonneg measureReal_le_one) + +end Finite + +section Kernel +variable {X W : Type*} [MeasurableSpace X] [Fintype W] [MeasurableSpace W] + [MeasurableSingletonClass W] + (μ : Measure X) [IsProbabilityMeasure μ] (κ : Kernel X W) [IsMarkovKernel κ] + +lemma ae_kernel_ac_marginal : ∀ᵐ x ∂μ, κ x ≪ (μ ⊗ₘ κ).snd := by + have h : ∀ w : W, ∀ᵐ x ∂μ, (μ ⊗ₘ κ).snd {w} = 0 → κ x {w} = 0 := by + intro w + by_cases hw : (μ ⊗ₘ κ).snd {w} = 0 + · have he : (∫⁻ x, κ x {w} ∂μ) = 0 := by + rw [Measure.snd_compProd, Measure.bind_apply (measurableSet_singleton w) κ.measurable.aemeasurable] at hw + exact hw + filter_upwards [(lintegral_eq_zero_iff (Kernel.measurable_coe κ (measurableSet_singleton w))).mp he] + with x hx + exact fun _ => hx + · exact ae_of_all _ (fun _ => fun h => (hw h).elim) + filter_upwards [ae_all_iff.mpr h] with x hx + exact finite_ac_of_singleton hx + +omit [Fintype W] in +lemma integrable_kernel_atom (w : W) : Integrable (fun x => (κ x).real {w}) μ := by + apply Integrable.mono' (integrable_const (1 : ℝ)) + ((Kernel.measurable_coe κ (measurableSet_singleton w)).ennreal_toReal.aestronglyMeasurable) + exact ae_of_all _ fun x => by simpa only [Real.norm_eq_abs, abs_of_nonneg ENNReal.toReal_nonneg, measureReal_def] using + (measureReal_le_one (μ := κ x) (s := {w})) + +omit [Fintype W] in +lemma integral_kernel_atom (w : W) : + ∫ x, (κ x).real {w} ∂μ = (μ ⊗ₘ κ).snd.real {w} := by + rw [measureReal_def, Measure.snd_compProd, + Measure.bind_apply (measurableSet_singleton w) κ.measurable.aemeasurable] + simp only [measureReal_def] + rw [integral_eq_lintegral_of_nonneg_ae (ae_of_all _ (fun _ => ENNReal.toReal_nonneg)) + ((Kernel.measurable_coe κ (measurableSet_singleton w)).ennreal_toReal.aestronglyMeasurable)] + congr 1 + apply lintegral_congr + intro x + exact ENNReal.ofReal_toReal (measure_ne_top (κ x) {w}) + +lemma klDiv_kernel_le_finiteEntropy : + klDiv (μ ⊗ₘ κ) (μ.prod (μ ⊗ₘ κ).snd) ≤ + ENNReal.ofReal (finiteEntropy (μ ⊗ₘ κ).snd) := by + rw [← Measure.compProd_const, klDiv_compProd_kernel] + let ν := (μ ⊗ₘ κ).snd + have hi : Integrable (fun x => ∑ w : W, (κ x).real {w} * (-Real.log (ν.real {w}))) μ := by + apply integrable_finsetSum + intro w _ + exact (integrable_kernel_atom μ κ w).mul_const _ + calc + _ ≤ ∫⁻ x, ENNReal.ofReal (∑ w : W, (κ x).real {w} * (-Real.log (ν.real {w}))) ∂μ := by + apply lintegral_mono_ae + filter_upwards [ae_kernel_ac_marginal μ κ] with x hx + exact finite_klDiv_le_crossEntropy (κ x) ν hx + _ = ENNReal.ofReal (∫ x, ∑ w : W, (κ x).real {w} * (-Real.log (ν.real {w})) ∂μ) := by + symm + exact ofReal_integral_eq_lintegral_ofReal hi (ae_of_all _ fun x => finite_crossEntropy_nonneg (κ x) ν) + _ = _ := by + rw [integral_finsetSum _ (fun w _ => (integrable_kernel_atom μ κ w).mul_const _)] + simp_rw [integral_mul_const, integral_kernel_atom μ κ] + congr 1 + unfold finiteEntropy + apply Finset.sum_congr rfl + intro w _ + ring + +end Kernel + +lemma mutualInformation_le_finiteEntropy {X W : Type*} [MeasurableSpace X] + [Fintype W] [MeasurableSpace W] [MeasurableSingletonClass W] + [StandardBorelSpace W] [Nonempty W] + (q : Measure (X × W)) [IsProbabilityMeasure q] : + klDiv q (q.fst.prod q.snd) ≤ ENNReal.ofReal (finiteEntropy q.snd) := by + have h := klDiv_kernel_le_finiteEntropy q.fst q.condKernel + simpa only [Measure.disintegrate q q.condKernel] using h + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/FiniteStateDensity.lean b/lean/OAI/Probability/PosteriorReplicas/Information/FiniteStateDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..e57f6246e9908b319cb196c2e409c237eca17608 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/FiniteStateDensity.lean @@ -0,0 +1,53 @@ +import OAI.Probability.PosteriorReplicas.Information.FiniteEntropyBounds + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma atom_smul_kernel_le_snd {V X : Type*} [MeasurableSpace V] [MeasurableSpace X] + [MeasurableSingletonClass V] (μ : Measure V) [IsProbabilityMeasure μ] + (κ : Kernel V X) [IsMarkovKernel κ] (v : V) : + μ {v} • κ v ≤ (μ ⊗ₘ κ).snd := by + apply Measure.le_iff.mpr + intro s hs + rw [Measure.smul_apply,smul_eq_mul,Measure.snd_compProd, + Measure.bind_apply hs κ.measurable.aemeasurable] + calc + _ = ∫⁻ w in {v}, κ w s ∂μ := by rw [lintegral_singleton,mul_comm] + _ ≤ ∫⁻ w, κ w s ∂μ := lintegral_mono' Measure.restrict_le_self le_rfl + +lemma finite_state_bounded_density {V X : Type*} [MeasurableSpace V] [MeasurableSpace X] + [MeasurableSingletonClass V] (μ : Measure V) [IsProbabilityMeasure μ] + (κ : Kernel V X) [IsMarkovKernel κ] (ν : Measure X) [IsProbabilityMeasure ν] + (hν : (μ ⊗ₘ κ).snd = ν) (v : V) (hv : μ {v} ≠ 0) : + ∃ f : X → ℝ≥0∞, Measurable f ∧ (∀ x, f x ≤ ENNReal.ofReal ((μ.real {v})⁻¹)) ∧ + ν.withDensity f = κ v := by + let τ := μ {v} • κ v + have hle : τ ≤ ν := hν ▸ atom_smul_kernel_le_snd μ κ v + have : IsFiniteMeasure τ := isFiniteMeasure_of_le ν hle + let g : X → ℝ≥0∞ := fun x => min (τ.rnDeriv ν x) 1 + have hg : Measurable g := (Measure.measurable_rnDeriv τ ν).min measurable_const + have he : ν.withDensity g = τ := by + rw [withDensity_congr_ae (show g =ᵐ[ν] τ.rnDeriv ν by + filter_upwards [Measure.rnDeriv_le_one_of_le hle] with x hx + exact min_eq_left hx)] + exact Measure.withDensity_rnDeriv_eq τ ν (Measure.absolutelyContinuous_of_le hle) + refine ⟨fun x => (μ {v})⁻¹*g x,measurable_const.mul hg,?_,?_⟩ + · intro x + have ha : 0 < μ.real {v} := ENNReal.toReal_pos hv (measure_ne_top μ {v}) + rw [ENNReal.ofReal_inv_of_pos ha,measureReal_def,ENNReal.ofReal_toReal (measure_ne_top μ {v})] + calc + _ ≤ (μ {v})⁻¹*1 := mul_le_mul le_rfl (min_le_right _ _) (by positivity) (by positivity) + _ = _ := mul_one _ + · change ν.withDensity ((μ {v})⁻¹ • g) = κ v + rw [withDensity_smul _ hg,he] + change (μ {v})⁻¹ • (μ {v} • κ v) = _ + rw [smul_smul,ENNReal.inv_mul_cancel hv (measure_ne_top μ {v}),one_smul] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/GenericInformationBound.lean b/lean/OAI/Probability/PosteriorReplicas/Information/GenericInformationBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..f01b665cfceaff55f577e48bab377fcdbb1c665d --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/GenericInformationBound.lean @@ -0,0 +1,76 @@ +import OAI.Probability.PosteriorReplicas.Information.BinCutoff +import OAI.Probability.PosteriorReplicas.Information.FiniteEntropyBounds +import OAI.Probability.PosteriorReplicas.Information.ReplicaCost +import OAI.Probability.PosteriorReplicas.Information.ReplicaInformationBound + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma spherical_density_bound_one_le {d : ℕ} (hd : 0 < d) + {f : Vec d → ℝ} {L : ℝ} (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity (fun x => ENNReal.ofReal (f x)))] : 1 ≤ L := by + let : NeZero d := ⟨hd.ne'⟩ + have : IsProbabilityMeasure (sphereLaw d) := by + change IsProbabilityMeasure (BaseLaw.spherical.measure d); infer_instance + apply ENNReal.one_le_ofReal.mp + calc + (1:ℝ≥0∞) = ((sphereLaw d).withDensity (fun x => ENNReal.ofReal (f x))) univ := (measure_univ).symm + _ = ∫⁻ x, ENNReal.ofReal (f x) ∂sphereLaw d := by rw [withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] + _ ≤ ∫⁻ _x, ENNReal.ofReal L ∂sphereLaw d := lintegral_mono (fun x => ENNReal.ofReal_le_ofReal (hfL x)) + _ = ENNReal.ofReal L := by simp + +lemma gaussian_replica_information {d ℓ k m N : ℕ} [NeZero N] + (hd : 4*k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m≤ℓ) + (hdk : d ≤ 32*k) (hℓk : ℓ ≤ 16*k) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ} (hL : 1 ≤ L) + (hfL : ∀ x, f x ≤ ENNReal.ofReal L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + conditionalInformation (sideLaw ℓ (signalMessageLaw ((sphereLaw d).withDensity f) κ)) ≤ + ENNReal.ofReal (messageEntropy (signalMessageLaw ((sphereLaw d).withDensity f) κ) / ((m+1:ℕ):ℝ) + + (100+Real.pi)*(d:ℝ) + Real.log (1+(d:ℝ)+Real.log L)) := by + have hi := gaussian_replica_information_cost hd hk hm hkm hf ENNReal.ofReal_ne_top hfL κ + (binCutoff d k L) (binCutoff_valid hL) + apply hi.trans + apply ENNReal.ofReal_le_ofReal + have hcost := comparisonCost_le hk hkm hdk hℓk (binCutoff d k L) + have hlog := binCutoff_log_bound (by omega : k≤d) hL + have hmm : 0 ≤ (m:ℝ) := by positivity + have hkr : (k:ℝ) ≤ d := by exact_mod_cast (by omega : k≤d) + have hdr : (1:ℝ) ≤ d := by exact_mod_cast (by omega : 1≤d) + have hln : 0 ≤ Real.log (1+(d:ℝ)+Real.log L) := Real.log_nonneg (by linarith [Real.log_nonneg hL]) + have hb : (40+Real.pi)*(k:ℝ)+Real.log ((binCutoff d k L:ℝ)+2) ≤ + (100+Real.pi)*(d:ℝ)+Real.log (1+(d:ℝ)+Real.log L) := by + nlinarith [Real.pi_pos,mul_le_mul_of_nonneg_left hkr (show (0:ℝ)≤40+Real.pi by positivity)] + have ha : 0 ≤ (100+Real.pi)*(d:ℝ)+Real.log (1+(d:ℝ)+Real.log L) := by positivity + have hb' := mul_le_mul_of_nonneg_left hb hmm + have hm1 : ((m+1:ℕ):ℝ) = (m:ℝ)+1 := by norm_cast + rw [hm1] + rw [add_assoc] + apply (div_le_iff₀ (by positivity : (0:ℝ)<(m:ℝ)+1)).mpr + rw [add_mul,div_mul_cancel₀ _ (by positivity : (m:ℝ)+1 ≠ 0)] + nlinarith + +lemma gaussian_replica_information_real {d ℓ k m N : ℕ} [NeZero N] + (hd : 4*k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m≤ℓ) + (hdk : d ≤ 32*k) (hℓk : ℓ ≤ 16*k) + (p : Measure (Vec d)) [IsProbabilityMeasure p] + {f : Vec d → ℝ} (hf : Measurable f) {L : ℝ} (hL : 1 ≤ L) + (hfL : ∀ x, 0 ≤ f x ∧ f x ≤ L) + (hp : p = (sphereLaw d).withDensity (fun x => ENNReal.ofReal (f x))) + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + conditionalInformation (sideLaw ℓ (signalMessageLaw p κ)) ≤ + ENNReal.ofReal (messageEntropy (signalMessageLaw p κ) / ((m+1:ℕ):ℝ) + + (100+Real.pi)*(d:ℝ) + Real.log (1+(d:ℝ)+Real.log L)) := by + subst p + exact gaussian_replica_information hd hk hm hkm hdk hℓk hf.ennreal_ofReal hL + (fun x => ENNReal.ofReal_le_ofReal (hfL x).2) κ + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/GraphKL.lean b/lean/OAI/Probability/PosteriorReplicas/Information/GraphKL.lean new file mode 100644 index 0000000000000000000000000000000000000000..c1ee38da232ddd64fc9999b7919a9638fbe080f4 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/GraphKL.lean @@ -0,0 +1,104 @@ +import OAI.Probability.PosteriorReplicas.Information.ConditionalKL + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma klDiv_map_leftInverse {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ ν : Measure X) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + {f : X → Y} {g : Y → X} (hf : Measurable f) (hg : Measurable g) + (hgf : Function.LeftInverse g f) : klDiv (μ.map f) (ν.map f) = klDiv μ ν := by + apply le_antisymm (klDiv_map_le _ _ hf) + have h := klDiv_map_le (μ.map f) (ν.map f) hg + have he : g ∘ f = id := funext hgf + simpa only [Measure.map_map hg hf, he, Measure.map_id] using h + +lemma compProd_prod_right {Z X Y : Type*} [MeasurableSpace Z] [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure Z) [SFinite μ] (κ : Kernel Z X) [IsSFiniteKernel κ] + (ν : Measure Y) [SFinite ν] : + ((μ ⊗ₘ κ).prod ν).map MeasurableEquiv.prodAssoc = μ ⊗ₘ (κ ×ₖ Kernel.const Z ν) := by + have hk : κ ×ₖ Kernel.const Z ν = κ ⊗ₖ Kernel.const (Z × X) ν := by + ext z s hs + rw [Kernel.prod_apply' _ _ _ hs, Kernel.compProd_apply hs] + rfl + rw [hk, ← Measure.compProd_const, Measure.compProd_assoc'] + +def attachSide {X Y Z : Type*} [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + (g : X → Z) (q : Measure (X × Y)) : Measure (Z × (X × Y)) := + q.map (fun z => (g z.1, z)) + +instance attachSide_finite {X Y Z : Type*} [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + (g : X → Z) (q : Measure (X × Y)) [IsFiniteMeasure q] : + IsFiniteMeasure (attachSide g q) := by + unfold attachSide + infer_instance + +lemma attachSide_probability {X Y Z : Type*} [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + {g : X → Z} (hg : Measurable g) (q : Measure (X × Y)) [IsProbabilityMeasure q] : + IsProbabilityMeasure (attachSide g q) := + (Measure.isProbabilityMeasure_map_iff (by fun_prop)).mpr inferInstance + +lemma attachSide_first_pair {X Y Z : Type*} [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + {g : X → Z} (hg : Measurable g) (q : Measure (X × Y)) : + (attachSide g q).map (fun z => (z.1,z.2.1)) = q.fst.map (fun x => (g x,x)) := by + unfold attachSide Measure.fst + rw [Measure.map_map (by fun_prop) (by fun_prop), Measure.map_map (by fun_prop) measurable_fst] + rfl + +lemma compProd_condKernel_fst {Z X Y : Type*} + [MeasurableSpace Z] [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + (q : Measure (Z × (X × Y))) [IsFiniteMeasure q] : + q.fst ⊗ₘ q.condKernel.fst = q.map (fun z => (z.1,z.2.1)) := by + rw [Kernel.fst_eq, Measure.compProd_map measurable_fst, Measure.disintegrate q q.condKernel] + rfl + +lemma attachSide_conditional_reference {X Y Z : Type*} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + {g : X → Z} (hg : Measurable g) (q : Measure (X × Y)) [IsProbabilityMeasure q] + (ν : Measure Y) [IsProbabilityMeasure ν] : + let r := attachSide g q + r.fst ⊗ₘ (r.condKernel.fst ×ₖ Kernel.const Z ν) = attachSide g (q.fst.prod ν) := by + let := attachSide_probability hg q + dsimp only + rw [← compProd_prod_right, compProd_condKernel_fst, attachSide_first_pair hg] + have hp : (q.fst.map (fun x => (g x,x))).prod ν = + (q.fst.prod ν).map (Prod.map (fun x => (g x,x)) id) := by + simpa only [Measure.map_id] using Measure.map_prod_map q.fst ν + (show Measurable (fun x => (g x,x)) by fun_prop) measurable_id + rw [hp] + rw [Measure.map_map (by fun_prop) (by fun_prop)] + rfl + +lemma mutualInformation_attachSide_chain {X Y Z : Type*} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + {g : X → Z} (hg : Measurable g) (q : Measure (X × Y)) [IsProbabilityMeasure q] : + let r := attachSide g q + klDiv q (q.fst.prod q.snd) = cmi r + + klDiv (q.map (fun z => (g z.1,z.2))) ((q.fst.map g).prod q.snd) := by + let := attachSide_probability hg q + dsimp only + have h := klDiv_conditional_chain (attachSide g q) q.snd + rw [attachSide_conditional_reference hg] at h + have he : klDiv (attachSide g q) (attachSide g (q.fst.prod q.snd)) = klDiv q (q.fst.prod q.snd) := + klDiv_map_leftInverse _ _ (by fun_prop) measurable_snd (fun _ => rfl) + rw [he] at h + have hf : (attachSide g q).fst = q.fst.map g := by + unfold attachSide Measure.fst + rw [Measure.map_map measurable_fst (by fun_prop), Measure.map_map hg measurable_fst] + rfl + have hy : (attachSide g q).map (fun z => (z.1,z.2.2)) = + q.map (fun z => (g z.1,z.2)) := by + rw [attachSide, Measure.map_map (by fun_prop) (by fun_prop)] + rfl + rwa [hf,hy] at h + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/HaarInformationEq.lean b/lean/OAI/Probability/PosteriorReplicas/Information/HaarInformationEq.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc42f6a93990b639461653403b26ee1164740121 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/HaarInformationEq.lean @@ -0,0 +1,79 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianWishart +import OAI.Probability.PosteriorReplicas.Information.RandomProjectionInformation + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +namespace PosteriorReplicas + +@[fun_prop] lemma measurable_gramSchmidtNormed_rows {d ℓ : ℕ} : + Measurable (gramSchmidtNormed ℝ : Rows d ℓ → Rows d ℓ) := + Measurable.of_eval (fun index => measurable_gramSchmidtNormed index) + +instance haarRows_probability (d ℓ : ℕ) : IsProbabilityMeasure (haarRows d ℓ) := by + unfold haarRows + infer_instance + +lemma cmi_attachSide_equiv {X Y Z Z' : Type*} + [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] [MeasurableSpace Z'] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + [Fintype Y] [MeasurableSingletonClass Y] + {g : X → Z} (hg : Measurable g) (e : Z ≃ᵐ Z') + (q : Measure (X × Y)) [IsProbabilityMeasure q] : + cmi (attachSide (e ∘ g) q) = cmi (attachSide g q) := by + have hh := mutualInformation_attachSide_chain hg q + have hh' := mutualInformation_attachSide_chain (e.measurable.comp hg) q + have hp : ((q.fst.map g).prod q.snd).map (Prod.map e id) = + (q.fst.map (e ∘ g)).prod q.snd := by + rw [← Measure.map_prod_map _ _ e.measurable measurable_id,Measure.map_id, + Measure.map_map e.measurable hg] + have hq : (q.map (fun z => (g z.1,z.2))).map (Prod.map e id) = + q.map (fun z => ((e ∘ g) z.1,z.2)) := by + rw [Measure.map_map (by fun_prop) (by fun_prop)] + rfl + have he := klDiv_map_leftInverse (q.map (fun z => (g z.1,z.2))) + ((q.fst.map g).prod q.snd) + (show Measurable (Prod.map e id : Z×Y → Z'×Y) by fun_prop) + (show Measurable (Prod.map e.symm id : Z'×Y → Z×Y) by fun_prop) + (by intro z; exact Prod.ext (e.symm_apply_apply z.1) rfl) + rw [hp,hq] at he + rw [he] at hh' + have hfin : klDiv q (q.fst.prod q.snd) ≠ ∞ := + ne_top_of_le_ne_top ENNReal.ofReal_ne_top (mutualInformation_le_finiteEntropy q) + have hB : klDiv (q.map (fun z => (g z.1,z.2))) ((q.fst.map g).prod q.snd) ≠ ∞ := by + apply ne_top_of_le_ne_top hfin + rw [hh] + exact le_add_left le_rfl + exact (ENNReal.add_left_inj hB).mp (hh'.symm.trans hh) + +lemma cmi_labels_gramSchmidtNormed {d ℓ N : ℕ} [NeZero N] + {A : Rows d ℓ} (hA : LinearIndependent ℝ A) + (q : Measure (Vec d × Fin N)) [IsProbabilityMeasure q] : + cmi (attachSide (labels (gramSchmidtNormed ℝ A)) q) = + cmi (attachSide (labels A) q) := by + let e := (matrixLinearEquiv (pairingTriangular A).transpose + (pairingTriangular_det_pos hA).ne').toContinuousLinearEquiv.toHomeomorph.toMeasurableEquiv + have he : labels A = e ∘ labels (gramSchmidtNormed ℝ A) := pairings_eq_triangular hA + rw [he] + exact (cmi_attachSide_equiv (by unfold labels; fun_prop) e q).symm + +lemma cmi_haar_eq_gaussian {d ℓ N : ℕ} [NeZero N] (hℓ : ℓ ≤ d) + (q : Measure (Vec d × Fin N)) [IsProbabilityMeasure q] : + cmi (randomSideLaw (haarRows d ℓ) (fun z => labels z.1 z.2) q) = + conditionalInformation (sideLaw ℓ q) := by + change cmi (randomSideLaw (haarRows d ℓ) (fun z => labels z.1 z.2) q) = + cmi (randomSideLaw (gaussianRows d ℓ) (fun z => labels z.1 z.2) q) + rw [cmi_randomSideLaw _ measurable_labels,cmi_randomSideLaw _ measurable_labels] + rw [haarRows,lintegral_map (measurable_cmi_attachSide measurable_labels q) + measurable_gramSchmidtNormed_rows] + apply lintegral_congr_ae + have hfull := ae_gaussian_columns_independent (E := Vec d) ℓ (by simpa using hℓ) + filter_upwards [hfull] with A hA + exact cmi_labels_gramSchmidtNormed hA q + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/HaarStateBound.lean b/lean/OAI/Probability/PosteriorReplicas/Information/HaarStateBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..5a6a50eff82ed2f2a04b9a1bd82d2baaf7eef69f --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/HaarStateBound.lean @@ -0,0 +1,100 @@ +import OAI.Probability.PosteriorReplicas.Information.FiniteStateDensity +import OAI.Probability.PosteriorReplicas.Information.GenericInformationBound +import OAI.Probability.PosteriorReplicas.Information.StateSide + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma state_gaussian_information_bound {d ℓ k m V W : ℕ} [NeZero W] + (hd : 4*k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m≤ℓ) + (hdk : d ≤ 32*k) (hℓk : ℓ ≤ 16*k) + (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (hq : q.fst = sphereLaw d) + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] + (v : Fin V) (hv : q.snd {v} ≠ 0) : + conditionalInformation (sideLaw ℓ (stateOutputKernel q κ v)) ≤ + ENNReal.ofReal (finiteEntropy (stateOutputKernel q κ v).snd / ((m+1:ℕ):ℝ) + + (100+Real.pi)*(d:ℝ) + Real.log (1+(d:ℝ)-Real.log (q.snd.real {v}))) := by + have : NeZero d := ⟨by omega⟩ + have : IsProbabilityMeasure (sphereLaw d) := by + change IsProbabilityMeasure (BaseLaw.spherical.measure d) + infer_instance + obtain ⟨f,hf,hfL,hfp⟩ := finite_state_bounded_density q.snd (initialStateKernel q) + (sphereLaw d) ((initialStateKernel_marginal q).trans hq) v hv + have hpos : 0 < q.snd.real {v} := ENNReal.toReal_pos hv (measure_ne_top _ _) + have hL : 1 ≤ (q.snd.real {v})⁻¹ := (one_le_inv₀ hpos).mpr measureReal_le_one + have : IsProbabilityMeasure ((sphereLaw d).withDensity f) := hfp.symm ▸ inferInstance + have hi := gaussian_replica_information hd hk hm hkm hdk hℓk hf hL hfL (stateBlockKernel κ v) + simp only [hfp,messageEntropy_eq_finiteEntropy,Real.log_inv,← sub_eq_add_neg] at hi + exact hi + +lemma haar_state_information_bound {d ℓ k m V W : ℕ} [NeZero W] + (hd : 4*k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m≤ℓ) + (hdk : d ≤ 32*k) (hℓk : ℓ ≤ 16*k) (hℓ : ℓ≤d) + (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (hq : q.fst = sphereLaw d) + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + cmi (stateHaarSideLaw ℓ (stateMessageLaw q κ)) ≤ + ENNReal.ofReal (terminalConditionalEntropy (stateMessageLaw q κ) / ((m+1:ℕ):ℝ) + + (100+Real.pi)*(d:ℝ) + Real.log (1+(d:ℝ)+finiteEntropy q.snd)) := by + let R : Fin V → ℝ := fun v => + finiteEntropy (stateOutputKernel q κ v).snd / ((m+1:ℕ):ℝ) + + (100+Real.pi)*(d:ℝ) + Real.log (1+(d:ℝ)-Real.log (q.snd.real {v})) + have hR (v : Fin V) : 0 ≤ R v := by + have hE := finiteEntropy_nonneg (stateOutputKernel q κ v).snd + have hlog : Real.log (q.snd.real {v}) ≤ 0 := Real.log_nonpos measureReal_nonneg measureReal_le_one + have hl : 0 ≤ Real.log (1+(d:ℝ)-Real.log (q.snd.real {v})) := + Real.log_nonneg (by linarith [Nat.cast_nonneg (α := ℝ) d] : 1≤1+(d:ℝ)-Real.log (q.snd.real {v})) + dsimp [R] + positivity + rw [stateHaarInformation_average hℓ q κ] + calc + _ ≤ ∑ v, q.snd {v} * ENNReal.ofReal (R v) := by + apply Finset.sum_le_sum + intro v _ + by_cases hv : q.snd {v} = 0 + · simp [hv] + · exact mul_le_mul le_rfl (state_gaussian_information_bound hd hk hm hkm hdk hℓk q hq κ v hv) (by positivity) (by positivity) + _ = ENNReal.ofReal (∑ v, q.snd.real {v} * R v) := by + rw [ENNReal.ofReal_sum_of_nonneg (fun v _ => mul_nonneg measureReal_nonneg (hR v))] + apply Finset.sum_congr rfl + intro v _ + rw [ENNReal.ofReal_mul measureReal_nonneg,measureReal_def,ENNReal.ofReal_toReal (measure_ne_top _ _)] + _ ≤ _ := by + apply ENNReal.ofReal_le_ofReal + have havg := finiteEntropy_log_average q.snd (a := 1+(d:ℝ)) (by positivity) + have heq : ∑ v, q.snd.real {v} * R v = + terminalConditionalEntropy (stateMessageLaw q κ) / ((m+1:ℕ):ℝ) + + (100+Real.pi)*(d:ℝ) + + ∑ v, q.snd.real {v} * Real.log (1+(d:ℝ)-Real.log (q.snd.real {v})) := by + simp only [R,mul_add,← mul_div_assoc,Finset.sum_add_distrib,← Finset.sum_div, + ← Finset.sum_mul,sum_probability_atoms q.snd,one_mul, + terminalConditionalEntropy_average] + rw [heq] + linarith + +theorem haarReplicaBlock : HaarReplicaBlock := by + refine ⟨200+Real.pi,by positivity,?_⟩ + intro d hd V W hV hW q hp hq κ hκ + have hi := haar_state_information_bound (m := d/16) (ℓ := d/4) + (by omega : 4*(d/16)+d/16+2≤d) (by omega) (by omega) + (by omega : d/16+d/16≤d/4) (by omega) (by omega) (by omega) q hq κ + apply hi.trans + apply ENNReal.ofReal_le_ofReal + have hE := finiteEntropy_nonneg q.snd + have hdp : (1:ℝ)≤d := by exact_mod_cast (by omega : 1≤d) + have hl := Real.log_le_log (by positivity : 0<1+(d:ℝ)+finiteEntropy q.snd) + (show 1+(d:ℝ)+finiteEntropy q.snd ≤ 1+(200+Real.pi)*(d:ℝ)+finiteEntropy q.snd by + nlinarith [Real.pi_pos]) + have hrem : 0 ≤ (200+Real.pi)*(finiteEntropy q.snd+Real.log (d:ℝ))/(d:ℝ)^2 := + div_nonneg (mul_nonneg (by positivity) (add_nonneg hE (Real.log_nonneg hdp))) (sq_nonneg _) + nlinarith [Real.pi_pos] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/HeadlineInformation.lean b/lean/OAI/Probability/PosteriorReplicas/Information/HeadlineInformation.lean new file mode 100644 index 0000000000000000000000000000000000000000..c6a5781ca87a82d5ba162e830ada25a5dce2f4ef --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/HeadlineInformation.lean @@ -0,0 +1,109 @@ +import OAI.Probability.PosteriorReplicas.Information.GenericInformationBound + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma priorLog_le_dimension_add_log {d : ℕ} {u : ℝ} (hu : 0 ≤ u) : + Real.log (1+(d:ℝ)+u) ≤ (d:ℝ)+Real.log (1+u) := by + have hd : 0 ≤ (d:ℝ) := by positivity + have hh := Real.log_le_log (by positivity : 0<1+(d:ℝ)+u) + (show 1+(d:ℝ)+u ≤ (1+(d:ℝ))*(1+u) by nlinarith) + rw [Real.log_mul (by positivity) (by positivity)] at hh + have hl := Real.log_le_sub_one_of_pos (by positivity : 0<1+(d:ℝ)) + linarith + +lemma priorLog_le_dimension_add_div {d : ℕ} (hd : 1 ≤ d) {b : ℝ} (hb : 0 ≤ b) : + Real.log (1+(d:ℝ)+b) ≤ 2*(d:ℝ)+b/(d:ℝ) := by + have hdr : (1:ℝ) ≤ d := by exact_mod_cast hd + have hdp : (0:ℝ) ENNReal.ofReal (f x))) := hpf ▸ hp + exact spherical_density_bound_one_le (by omega) (fun x => (hfL x).2) + have hi := gaussian_replica_information_real (m := 2*(d/16)) + (by omega : 4*(2*(d/16))+2*(d/16)+2≤d) (by omega) (by omega) + (by omega : 2*(d/16)+2*(d/16)≤4*(2*(d/16))) (by omega) (by omega) + p hf hL hfL hpf κ + apply hi.trans + apply ENNReal.ofReal_le_ofReal + have hlog := priorLog_le_dimension_add_log (d:=d) (Real.log_nonneg hL) + have hmono := Real.log_le_log (by linarith [Real.log_nonneg hL] : 0<1+Real.log L) + (show 1+Real.log L ≤ 2+Real.log L by linarith) + have hpos := Real.log_nonneg (show 1≤2+Real.log L by linarith [Real.log_nonneg hL]) + have hdp : 0 ≤ (d:ℝ) := by positivity + nlinarith [Real.pi_pos,mul_nonneg Real.pi_pos.le hpos] + +theorem distanceReplicaBlock : DistanceReplicaBlock := by + refine ⟨200+Real.pi,by positivity,64,?_⟩ + intro d hd p hp f b hb hf hfL hpf N hN κ hκ + have hL : 1 ≤ Real.exp b := Real.one_le_exp_iff.mpr hb + have hi := gaussian_replica_information_real (m := d/8-1) (ℓ := d/2) + (by omega : 4*(d/16)+(d/8-1)+2≤d) (by omega) (by omega) + (by omega : d/16+(d/8-1)≤d/2) (by omega) (by omega) + p hf hL hfL hpf κ + rw [Nat.sub_add_cancel (by omega : 1≤d/8),Real.log_exp] at hi + apply hi.trans + apply ENNReal.ofReal_le_ofReal + have hlog := priorLog_le_dimension_add_div (by omega : 1≤d) hb + have hdp : 0 ≤ (d:ℝ) := by positivity + have hbdiv : 0 ≤ b/(d:ℝ) := div_nonneg hb hdp + nlinarith [Real.pi_pos,mul_nonneg Real.pi_pos.le hbdiv] + +theorem syntheticReplicaBlock : SyntheticReplicaBlock := by + refine ⟨200+Real.pi,by positivity,?_⟩ + intro d hd p hp f L hL hf hfL hpf N hN z hz + have hi := gaussian_replica_information_real (m := d/8-1) (ℓ := d/2) + (by omega : 4*(d/8)+(d/8-1)+2≤d) (by omega) (by omega) + (by omega : d/8+(d/8-1)≤d/2) (by omega) (by omega) + p hf hL hfL hpf (Kernel.deterministic z hz) + rw [Nat.sub_add_cancel (by omega : 1≤d/8)] at hi + apply hi.trans + apply ENNReal.ofReal_le_ofReal + have hH : messageEntropy (signalMessageLaw p (Kernel.deterministic z hz)) ≤ Real.log (N:ℝ) := by + simpa only [messageEntropy_eq_finiteEntropy,Fintype.card_fin] using + finiteEntropy_le_log_card (signalMessageLaw p (Kernel.deterministic z hz)).snd + have hH' := div_le_div_of_nonneg_right hH (show 0 ≤ ((d/8:ℕ):ℝ) by positivity) + have hlog := priorLog_le_dimension_add_log (d:=d) (Real.log_nonneg hL) + have hpos := Real.log_nonneg (show 1≤1+Real.log L by linarith [Real.log_nonneg hL]) + have hdp : 0 ≤ (d:ℝ) := by positivity + nlinarith [Real.pi_pos,mul_nonneg Real.pi_pos.le hpos] + +theorem incidenceReplicaBlock : IncidenceReplicaBlock := by + refine ⟨200+Real.pi,by positivity,64,?_⟩ + intro d hd p hp f F hF hf hfF hpf N hN κ hκ + have hi := gaussian_replica_information_real (m := d/16-1) (ℓ := d/4) + (by omega : 4*(d/16)+(d/16-1)+2≤d) (by omega) (by omega) + (by omega : d/16+(d/16-1)≤d/4) (by omega) (by omega) + p hf hF hfF hpf κ + rw [Nat.sub_add_cancel (by omega : 1≤d/16)] at hi + apply hi.trans + apply ENNReal.ofReal_le_ofReal + have hH : messageEntropy (signalMessageLaw p κ) ≤ Real.log (N:ℝ) := by + simpa only [messageEntropy_eq_finiteEntropy,Fintype.card_fin] using + finiteEntropy_le_log_card (signalMessageLaw p κ).snd + have hH' := div_le_div_of_nonneg_right hH (show 0 ≤ ((d/16:ℕ):ℝ) by positivity) + have hlog := priorLog_le_dimension_add_log (d:=d) (Real.log_nonneg hF) + have hpos := Real.log_nonneg (show 1≤1+Real.log F by linarith [Real.log_nonneg hF]) + have hdp : 0 ≤ (d:ℝ) := by positivity + nlinarith [Real.pi_pos,mul_nonneg Real.pi_pos.le hpos] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/KLTools.lean b/lean/OAI/Probability/PosteriorReplicas/Information/KLTools.lean new file mode 100644 index 0000000000000000000000000000000000000000..f9dd384eb5ee354db2ed78f33f760d213c6ca538 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/KLTools.lean @@ -0,0 +1,131 @@ +import Mathlib + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma klDiv_map_equiv {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ ν : Measure X) [IsFiniteMeasure μ] [IsFiniteMeasure ν] (e : X ≃ᵐ Y) : + klDiv (μ.map e) (ν.map e) = klDiv μ ν := by + apply le_antisymm (klDiv_map_le _ _ e.measurable) + have h := klDiv_map_le (μ.map e) (ν.map e) e.symm.measurable + simpa only [Measure.map_map e.symm.measurable e.measurable, + e.symm_comp_self, Measure.map_id] using h + +lemma klDiv_swap {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ ν : Measure (X × Y)) [IsFiniteMeasure μ] [IsFiniteMeasure ν] : + klDiv (μ.map Prod.swap) (ν.map Prod.swap) = klDiv μ ν := + klDiv_map_equiv μ ν MeasurableEquiv.prodComm + +lemma klDiv_prod_left {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ ν : Measure X) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (ρ : Measure Y) [IsProbabilityMeasure ρ] : + klDiv (μ.prod ρ) (ν.prod ρ) = klDiv μ ν := by + simpa only [Measure.compProd_const] using klDiv_compProd_left μ ν (Kernel.const X ρ) + +lemma klDiv_prod_right {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure X) [IsProbabilityMeasure μ] + (ν ρ : Measure Y) [IsFiniteMeasure ν] [IsFiniteMeasure ρ] : + klDiv (μ.prod ν) (μ.prod ρ) = klDiv ν ρ := by + rw [← klDiv_swap, Measure.prod_swap, Measure.prod_swap, klDiv_prod_left] + +lemma klDiv_prod_first_chain {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace Y] [Nonempty Y] + (q : Measure (X × Y)) [IsProbabilityMeasure q] + (μ : Measure X) [IsProbabilityMeasure μ] (ν : Measure Y) [IsProbabilityMeasure ν] : + klDiv q (μ.prod ν) = klDiv q.fst μ + klDiv q (q.fst.prod ν) := by + have h := klDiv_compProd_eq_add q.fst μ q.condKernel (Kernel.const X ν) + simpa only [Measure.disintegrate q q.condKernel, Measure.compProd_const] using h + +lemma klDiv_prod_decomposition {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + (q : Measure (X × Y)) [IsProbabilityMeasure q] + (μ : Measure X) [IsProbabilityMeasure μ] (ν : Measure Y) [IsProbabilityMeasure ν] : + klDiv q (μ.prod ν) = klDiv q.fst μ + klDiv q.snd ν + klDiv q (q.fst.prod q.snd) := by + rw [klDiv_prod_first_chain] + have h := klDiv_prod_first_chain (q.map Prod.swap) ν q.fst + rw [Measure.fst_map_swap] at h + have h1 : klDiv (q.map Prod.swap) (ν.prod q.fst) = klDiv q (q.fst.prod ν) := by + rw [← Measure.prod_swap, klDiv_swap] + have h2 : klDiv (q.map Prod.swap) (q.snd.prod q.fst) = klDiv q (q.fst.prod q.snd) := by + rw [← Measure.prod_swap, klDiv_swap] + rw [h1, h2] at h + rw [h, add_assoc] + +section KernelKL +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace.CountableOrCountablyGenerated X Y] + (μ : Measure X) [IsFiniteMeasure μ] (κ η : Kernel X Y) + [IsMarkovKernel κ] [IsMarkovKernel η] + +lemma withDensity_kernel_rnDeriv (hac : ∀ᵐ x ∂μ, κ x ≪ η x) : + (μ ⊗ₘ η).withDensity (fun z => κ.rnDeriv η z.1 z.2) = μ ⊗ₘ κ := by + rw [← Measure.compProd_withDensity (Kernel.measurable_rnDeriv κ η)] + apply Measure.compProd_congr + filter_upwards [hac] with x hx + rw [Kernel.withDensity_apply _ (Kernel.measurable_rnDeriv κ η)] + rw [withDensity_congr_ae (Kernel.rnDeriv_eq_rnDeriv_measure), Measure.withDensity_rnDeriv_eq _ _ hx] + +lemma rnDeriv_compProd_kernel (hac : ∀ᵐ x ∂μ, κ x ≪ η x) : + (μ ⊗ₘ κ).rnDeriv (μ ⊗ₘ η) =ᵐ[μ ⊗ₘ η] (fun z => κ.rnDeriv η z.1 z.2) := by + conv_lhs => rw [← withDensity_kernel_rnDeriv μ κ η hac] + exact Measure.rnDeriv_withDensity _ (Kernel.measurable_rnDeriv κ η) + +lemma klDiv_compProd_kernel_integral (hac : ∀ᵐ x ∂μ, κ x ≪ η x) : + klDiv (μ ⊗ₘ κ) (μ ⊗ₘ η) = ∫⁻ x, klDiv (κ x) (η x) ∂μ := by + rw [klDiv_eq_lintegral_klFun_of_ac (Measure.AbsolutelyContinuous.compProd_right hac)] + calc + _ = ∫⁻ z, ENNReal.ofReal (klFun (κ.rnDeriv η z.1 z.2).toReal) ∂μ ⊗ₘ η := by + apply lintegral_congr_ae + filter_upwards [rnDeriv_compProd_kernel μ κ η hac] with z hz + rw [hz] + _ = ∫⁻ x, ∫⁻ y, ENNReal.ofReal (klFun (κ.rnDeriv η x y).toReal) ∂η x ∂μ := by + rw [Measure.lintegral_compProd (by fun_prop)] + _ = _ := by + apply lintegral_congr_ae + filter_upwards [hac] with x hx + rw [klDiv_eq_lintegral_klFun_of_ac hx] + apply lintegral_congr_ae + filter_upwards [Kernel.rnDeriv_eq_rnDeriv_measure (κ := κ) (η := η) (a := x)] with y hy + rw [hy] + +lemma measurable_kernel_klDiv : Measurable (fun x => klDiv (κ x) (η x)) := by + classical + have he : (fun x => klDiv (κ x) (η x)) = fun x => + if κ x ≪ η x then ∫⁻ y, ENNReal.ofReal (klFun (κ.rnDeriv η x y).toReal) ∂η x + else ∞ := by + funext x + split_ifs with hx + · rw [klDiv_eq_lintegral_klFun_of_ac hx] + apply lintegral_congr_ae + filter_upwards [Kernel.rnDeriv_eq_rnDeriv_measure (κ := κ) (η := η) (a := x)] with y hy + rw [hy] + · exact klDiv_of_not_ac hx + rw [he] + apply Measurable.ite (Kernel.measurableSet_absolutelyContinuous κ η) _ measurable_const + exact Measurable.lintegral_kernel_prod_right' (κ := η) (by + exact ENNReal.measurable_ofReal.comp (continuous_klFun.measurable.comp + (Kernel.measurable_rnDeriv κ η).ennreal_toReal)) + +lemma klDiv_compProd_kernel : + klDiv (μ ⊗ₘ κ) (μ ⊗ₘ η) = ∫⁻ x, klDiv (κ x) (η x) ∂μ := by + by_cases hac : ∀ᵐ x ∂μ, κ x ≪ η x + · exact klDiv_compProd_kernel_integral μ κ η hac + · have hnot : ¬ μ ⊗ₘ κ ≪ μ ⊗ₘ η := fun h => hac h.kernel_of_compProd + rw [klDiv_of_not_ac hnot] + apply (eq_top_iff.mpr _).symm + by_contra h + have hfin : (∫⁻ x, klDiv (κ x) (η x) ∂μ) < ∞ := lt_of_not_ge h + have ha := ae_lt_top (measurable_kernel_klDiv κ η) hfin.ne + apply hac + filter_upwards [ha] with x hx + exact (klDiv_ne_top_iff.mp hx.ne).1 + +end KernelKL +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/LikelihoodIntegrability.lean b/lean/OAI/Probability/PosteriorReplicas/Information/LikelihoodIntegrability.lean new file mode 100644 index 0000000000000000000000000000000000000000..8c423eeca32795953a52f71207b23c6e435a6779 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/LikelihoodIntegrability.lean @@ -0,0 +1,100 @@ +import OAI.Probability.PosteriorReplicas.Information.EntropyTest + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma abs_le_pos_add_exp_neg (x : ℝ) : |x| ≤ max x 0 + Real.exp (-x) := by + by_cases hx : 0 ≤ x + · rw [abs_of_nonneg hx, max_eq_left hx] + linarith [Real.exp_pos (-x)] + · rw [abs_of_neg (lt_of_not_ge hx), max_eq_right (le_of_not_ge hx)] + linarith [Real.add_one_le_exp (-x)] + +lemma integrable_llr_of_positive {X : Type*} [MeasurableSpace X] + (μ ν : Measure X) [IsFiniteMeasure μ] [IsFiniteMeasure ν] + (hac : μ ≪ ν) (hi : Integrable (fun x => max (llr μ ν x) 0) μ) : + Integrable (llr μ ν) μ := by + apply (hi.add (integrable_exp_neg_llr μ ν hac)).mono' (by fun_prop) + exact ae_of_all _ (fun x => by simpa using abs_le_pos_add_exp_neg (llr μ ν x)) + +lemma likelihood_positive_log_bound {w a : ℝ} (hw : 0 ≤ w) (ha : 0 < a) (m : ℕ) : + (w*a⁻¹^m) * max (Real.log (w*a⁻¹^m)) 0 ≤ + 1+w^4 + (2*(m:ℝ)) * (w*a⁻¹^(m+1)) := by + by_cases hw0 : w = 0 + · simp [hw0] + have hwp : 0 < w := lt_of_le_of_ne hw (Ne.symm hw0) + have hrp : 0 < w*a⁻¹^m := mul_pos hwp (pow_pos (inv_pos.mpr ha) _) + have hlog : max (Real.log (w*a⁻¹^m)) 0 ≤ w*a⁻¹^m := + max_le (Real.log_le_self hrp.le) hrp.le + by_cases hlarge : a⁻¹^m ≤ max 1 w + · have hwmax : w ≤ max 1 w := le_max_right _ _ + have hmpos : 0 ≤ max 1 w := (by norm_num : (0:ℝ) ≤ 1).trans (le_max_left _ _) + have hr : w*a⁻¹^m ≤ (max 1 w)^2 := by + simpa [pow_two] using mul_le_mul hwmax hlarge (by positivity) hmpos + have hsq : (w*a⁻¹^m)^2 ≤ (max 1 w)^4 := by + have ht := (sq_le_sq₀ hrp.le (sq_nonneg _)).mpr hr + simpa only [← pow_mul] using ht + have hm4 : (max 1 w)^4 ≤ 1+w^4 := by + by_cases h : w ≤ 1 + · rw [max_eq_left h] + norm_num + positivity + · rw [max_eq_right (le_of_not_ge h)] + linarith + calc + _ ≤ (w*a⁻¹^m)^2 := by nlinarith [mul_le_mul_of_nonneg_left hlog hrp.le] + _ ≤ 1+w^4 := hsq.trans hm4 + _ ≤ _ := le_add_of_nonneg_right (by positivity) + · have hwa : w ≤ a⁻¹^m := (le_max_right 1 w).trans (le_of_not_ge hlarge) + have h1a : 1 ≤ a⁻¹^m := (le_max_left 1 w).trans (le_of_not_ge hlarge) + have hlw := Real.log_le_log hwp hwa + have hlognon : 0 ≤ Real.log (a⁻¹^m) := Real.log_nonneg h1a + have hlogupper : max (Real.log (w*a⁻¹^m)) 0 ≤ 2*(m:ℝ)*a⁻¹ := by + rw [Real.log_mul hw0 (pow_ne_zero _ (inv_ne_zero ha.ne'))] + have ha' := (Real.log_le_self (inv_pos.mpr ha).le) + rw [Real.log_pow] at hlw hlognon + rw [Real.log_pow] + have hm : (0:ℝ) ≤ m := Nat.cast_nonneg _ + have ht := mul_le_mul_of_nonneg_left ha' hm + apply max_le <;> nlinarith + calc + _ ≤ (w*a⁻¹^m) * (2*(m:ℝ)*a⁻¹) := mul_le_mul_of_nonneg_left hlogupper hrp.le + _ = (2*(m:ℝ)) * (w*a⁻¹^(m+1)) := by rw [pow_succ]; ring + _ ≤ _ := le_add_of_nonneg_left (by positivity) + +lemma replica_likelihood_integrable {X : Type*} [MeasurableSpace X] + (R : Measure X) [IsFiniteMeasure R] {w a : X → ℝ} (hw : Measurable w) (ha : Measurable a) + (hwp : ∀ᵐ x ∂ R, 0 ≤ w x) (hap : ∀ᵐ x ∂ R, 0 < a x) (m : ℕ) + (hw4 : Integrable (fun x => w x^4) R) + (hwa : Integrable (fun x => w x*(a x)⁻¹^(m+1)) R) + [IsFiniteMeasure (R.withDensity (fun x => ENNReal.ofReal (w x*(a x)⁻¹^m)))] : + Integrable (fun x => Real.log (w x*(a x)⁻¹^m)) + (R.withDensity (fun x => ENNReal.ofReal (w x*(a x)⁻¹^m))) := by + let g : X → ℝ≥0∞ := fun x => ENNReal.ofReal (w x*(a x)⁻¹^m) + have hg : Measurable g := by unfold g; fun_prop + have hp : Integrable (fun x => max (Real.log (w x*(a x)⁻¹^m)) 0) (R.withDensity g) := by + rw [integrable_withDensity_iff_integrable_smul' hg (ae_of_all _ (fun _ => ENNReal.ofReal_lt_top))] + apply (((integrable_const 1).add hw4).add (hwa.const_mul (2*(m:ℝ)))).mono' (by fun_prop) + filter_upwards [hwp,hap] with x hwx hax + rw [smul_eq_mul, Real.norm_eq_abs, abs_of_nonneg (by positivity)] + change (ENNReal.ofReal (w x*(a x)⁻¹^m)).toReal * _ ≤ _ + rw [ENNReal.toReal_ofReal (mul_nonneg hwx (pow_nonneg (inv_nonneg.mpr hax.le) _))] + exact likelihood_positive_log_bound hwx hax m + have he : llr (R.withDensity g) R =ᵐ[R.withDensity g] + (fun x => Real.log (w x*(a x)⁻¹^m)) := by + apply (llr_withDensity_ae R hg).trans + filter_upwards [(withDensity_absolutelyContinuous R g).ae_le hwp, + (withDensity_absolutelyContinuous R g).ae_le hap] with x hwx hax + dsimp only [g] + rw [ENNReal.toReal_ofReal (by positivity)] + exact (integrable_llr_of_positive (R.withDensity g) R (withDensity_absolutelyContinuous R g) + (hp.congr (he.symm.fun_comp (fun x => max x 0)))).congr he + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/LogComparison.lean b/lean/OAI/Probability/PosteriorReplicas/Information/LogComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..a532e01b3da5584ae25dabd5847199166230f037 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/LogComparison.lean @@ -0,0 +1,58 @@ +import OAI.Probability.PosteriorReplicas.Information.EntropyLossTest + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma log_tangent {x M : ℝ} (hx : 0 < x) (hM : 0 < M) : + Real.log x ≤ Real.log M + x/M - 1 := by + have h := Real.log_le_sub_one_of_pos (div_pos hx hM) + rw [Real.log_div hx.ne' hM.ne'] at h + linarith + +lemma log_replica_comparison {c Z J J' a a' v M : ℝ} + (hc : 0 < c) (hZ : 0 < Z) (hJ : 0 < J) (hJ' : 0 < J') + (ha : 0 < a) (ha' : 0 < a') (hv : 0 < v) (hM : 0 < M) (k m : ℕ) : + Real.log (c*J⁻¹^k*a⁻¹^m) - Real.log (c*Z⁻¹*J'⁻¹^k*a'⁻¹^m) ≤ + Real.log Z + (k:ℝ)*Real.log (J'/J) + (m:ℝ)*Real.log v + + (m:ℝ)*(Real.log M + (a'*a⁻¹*v⁻¹)/M - 1) := by + have hr := log_tangent (mul_pos (mul_pos ha' (inv_pos.mpr ha)) (inv_pos.mpr hv)) hM + simp only [Real.log_mul (mul_pos ha' (inv_pos.mpr ha)).ne' (inv_pos.mpr hv).ne', + Real.log_mul ha'.ne' (inv_pos.mpr ha).ne',Real.log_inv] at hr + have he : Real.log (c*J⁻¹^k*a⁻¹^m) - Real.log (c*Z⁻¹*J'⁻¹^k*a'⁻¹^m) = + Real.log Z + (k:ℝ)*Real.log (J'/J)+(m:ℝ)*(Real.log a'-Real.log a) := by + rw [Real.log_mul (mul_pos hc (pow_pos (inv_pos.mpr hJ) _)).ne' (pow_pos (inv_pos.mpr ha) _).ne', + Real.log_mul hc.ne' (pow_pos (inv_pos.mpr hJ) _).ne', + Real.log_mul (mul_pos (mul_pos hc (inv_pos.mpr hZ)) (pow_pos (inv_pos.mpr hJ') _)).ne' + (pow_pos (inv_pos.mpr ha') _).ne', + Real.log_mul (mul_pos hc (inv_pos.mpr hZ)).ne' (pow_pos (inv_pos.mpr hJ') _).ne', + Real.log_mul hc.ne' (inv_pos.mpr hZ).ne',Real.log_div hJ'.ne' hJ.ne'] + simp only [Real.log_pow,Real.log_inv] + ring + rw [he] + nlinarith [mul_le_mul_of_nonneg_left hr (Nat.cast_nonneg (α := ℝ) m)] + +lemma entropy_loss_envelope {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ ν : Measure X) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (hkl : klDiv μ ν ≠ ∞) {ψ : X → Y} (hψ : Measurable ψ) + {g : Y → ℝ} (hg : Measurable g) + (he : Integrable (fun y => Real.exp (g y)) (ν.map ψ)) + (hmean : (∫ y, Real.exp (g y) ∂ν.map ψ) ≤ 1) + {F : X → ℝ} (hF : Integrable F μ) + (hbound : ∀ᵐ x ∂μ, llr μ ν x - g (ψ x) ≤ F x) : + (klDiv μ ν).toReal ≤ (klDiv (μ.map ψ) (ν.map ψ)).toReal + ∫ x, F x ∂μ := by + have herr : Integrable (fun x => max (llr μ ν x - g (ψ x)) 0) μ := by + apply hF.norm.mono' ((measurable_llr μ ν).sub (hg.comp hψ) |>.max measurable_const |>.aestronglyMeasurable) + filter_upwards [hbound] with x hx + rw [Real.norm_eq_abs,abs_of_nonneg (le_max_right _ 0),Real.norm_eq_abs] + exact max_le (hx.trans (le_abs_self _)) (abs_nonneg _) + obtain ⟨_,hi,h⟩ := entropy_loss_test μ ν hkl hψ hg he hmean herr + exact h.trans (add_le_add le_rfl (integral_mono_ae hi hF hbound)) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/NormalizedLikelihood.lean b/lean/OAI/Probability/PosteriorReplicas/Information/NormalizedLikelihood.lean new file mode 100644 index 0000000000000000000000000000000000000000..38249839277f9b5d507106374e2c8c598e405648 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/NormalizedLikelihood.lean @@ -0,0 +1,56 @@ +import OAI.Probability.PosteriorReplicas.Information.ObservableLikelihood + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma normalized_log_likelihood {X : Type*} [MeasurableSpace X] (ν : Measure X) + {g : X → ℝ≥0∞} (hg : Measurable g) (hpos : ∀ᵐ x ∂ν, 0 < g x) + (hmean : (∫⁻ x, g x ∂ν) = 1) : + Integrable (fun x => Real.exp (Real.log (g x).toReal)) ν ∧ + (∫ x, Real.exp (Real.log (g x).toReal) ∂ν) = 1 := by + have ht : ∀ᵐ x ∂ν, g x < ∞ := ae_lt_top hg (by rw [hmean]; exact ENNReal.one_ne_top) + have he : (fun x => Real.exp (Real.log (g x).toReal)) =ᵐ[ν] (fun x => (g x).toReal) := by + filter_upwards [hpos,ht] with x hx hxt + exact Real.exp_log (ENNReal.toReal_pos hx.ne' hxt.ne) + refine ⟨(integrable_toReal_of_lintegral_ne_top hg.aemeasurable (by rw [hmean]; exact ENNReal.one_ne_top)).congr he.symm,?_⟩ + rw [integral_congr_ae he,integral_toReal hg.aemeasurable ht,hmean,ENNReal.toReal_one] + +lemma observableLikelihood_pos {d ℓ k m : ℕ} (hk : 1 ≤ k) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + (z : Observation d ℓ k m) : 0 < observableLikelihood f z := by + unfold observableLikelihood + apply ENNReal.mul_pos_iff.mpr + constructor + · apply ENNReal.mul_pos_iff.mpr + constructor + · exact ENNReal.mul_pos_iff.mpr ⟨equalConstant_pos _ _, ENNReal.inv_pos.mpr (wishartMoment_ne_top hk hkm)⟩ + · exact ENNReal.pow_pos (ENNReal.inv_pos.mpr ENNReal.ofReal_ne_top) _ + · exact ENNReal.pow_pos (ENNReal.inv_pos.mpr (projectedDensity_ne_top .spherical hLt hfL _ _)) _ + +def observableLog {d ℓ k m : ℕ} (f : Vec d → ℝ≥0∞) (z : Observation d ℓ k m) : ℝ := + Real.log (observableLikelihood f z).toReal + +@[fun_prop] lemma measurable_observableLog {d ℓ k m : ℕ} {f : Vec d → ℝ≥0∞} + (hf : Measurable f) : Measurable (@observableLog d ℓ k m f) := by unfold observableLog; fun_prop + +lemma observableLog_normalized {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + Integrable (fun z => Real.exp (observableLog f z)) + (((equalReference (k := k) (m := m) ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)).map observe) ∧ + (∫ z, Real.exp (observableLog f z) + ∂(((equalReference (k := k) (m := m) ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)).map observe)) = 1 := by + apply normalized_log_likelihood _ (measurable_observableLikelihood hf) + (ae_of_all _ (observableLikelihood_pos hk hkm hLt hfL)) + rw [lintegral_map (by fun_prop) measurable_observe] + exact observableLikelihood_lintegral hd hk hm hkm hf hLt hfL + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ObservableLikelihood.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ObservableLikelihood.lean new file mode 100644 index 0000000000000000000000000000000000000000..630ce8eb169be93ad1d46d12cf7d9752d1c55adc --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ObservableLikelihood.lean @@ -0,0 +1,188 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.GaussianWishart +import OAI.Probability.PosteriorReplicas.Gaussian.ObservableGaussian +import OAI.Probability.PosteriorReplicas.Information.ReplicaFiniteKL + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +abbrev AuxSpace (d ℓ k : ℕ) := Rows d ℓ × Rows ℓ k + +def auxLaw (d ℓ k : ℕ) : Measure (AuxSpace d ℓ k) := + (gaussianRows d ℓ).prod (gaussianRows ℓ k) + +instance (d ℓ k : ℕ) : IsProbabilityMeasure (auxLaw d ℓ k) := by + unfold auxLaw; infer_instance + +def projectedTuple {d ℓ m : ℕ} (B : Rows d ℓ) (u : Tuple d m) : Tuple ℓ m := + fun i => WithLp.toLp 2 (labels B (u i)) + +@[fun_prop] lemma measurable_projectedTuple {d ℓ m : ℕ} : + Measurable (fun z : Rows d ℓ × Tuple d m => projectedTuple z.1 z.2) := by + unfold projectedTuple labels; fun_prop + +lemma differences_projectedTuple {d ℓ m : ℕ} (B : Rows d ℓ) (u : Tuple d m) : + differences (projectedTuple B u) = pairingColumns (differences u) B := by + ext i j + simp [differences,projectedTuple,pairingColumns,labels,inner_sub_left,real_inner_comm] + +def observableRows {d ℓ k m : ℕ} (u : Tuple d m) (b : AuxSpace d ℓ k) : Rows d k := + rowMix (randomComplement (pairingColumns (differences u) b.1) b.2) b.1 + +@[fun_prop] lemma measurable_observableRows {d ℓ k m : ℕ} : + Measurable (fun z : Tuple d m × AuxSpace d ℓ k => observableRows z.1 z.2) := by + unfold observableRows; fun_prop + +lemma observableRows_law {d ℓ k m : ℕ} {u : Tuple d m} + (hu : LinearIndependent ℝ (differences u)) (hkm : k+m ≤ ℓ) : + (auxLaw d ℓ k).map (observableRows u) = constrainedRows k u := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map hH (by fun_prop), auxLaw, lintegral_prod _ (by fun_prop)] + change (∫⁻ B, ∫⁻ e, H (rowMix (randomComplement (pairingColumns (differences u) B) e) B) ∂gaussianRows ℓ k ∂gaussianRows d ℓ) = _ + have he := observable_gaussian_lintegral hu hkm (H := fun z => H z.2) (by fun_prop) + dsimp only [Prod.snd] at he + rw [he] + simp only [lintegral_const, measure_univ, mul_one] + rw [constrainedRows, lintegral_map hH (by fun_prop)] + rfl + +abbrev Observation (d ℓ k m : ℕ) := AuxSpace d ℓ k × Tuple ℓ m + +def observe {d ℓ k m : ℕ} (z : EqualSpace d k m × AuxSpace d ℓ k) : Observation d ℓ k m := + (z.2,projectedTuple z.2.1 z.1.2.2) + +@[fun_prop] lemma measurable_observe {d ℓ k m : ℕ} : Measurable (@observe d ℓ k m) := by + unfold observe; fun_prop + +def observableLikelihood {d ℓ k m : ℕ} (f : Vec d → ℝ≥0∞) + (z : Observation d ℓ k m) : ℝ≥0∞ := + let C := randomComplement (differences z.2) z.1.2 + equalConstant k m * (wishartMoment ℓ m k)⁻¹ * + (ENNReal.ofReal (affineVolume z.2))⁻¹^k * + (projectedDensity .spherical f (rowMix C z.1.1) + (fun i => ⟪C i,z.2 0⟫))⁻¹^m + +@[fun_prop] lemma measurable_observableLikelihood {d ℓ k m : ℕ} {f : Vec d → ℝ≥0∞} + (hf : Measurable f) : Measurable (@observableLikelihood d ℓ k m f) := by + unfold observableLikelihood; fun_prop + +lemma observableLikelihood_observe {d ℓ k m : ℕ} (f : Vec d → ℝ≥0∞) + (z : EqualSpace d k m × AuxSpace d ℓ k) : + observableLikelihood f (observe z) = equalConstant k m * (wishartMoment ℓ m k)⁻¹ * + (ENNReal.ofReal (gramVolume (pairingColumns (differences z.1.2.2) z.2.1)))⁻¹^k * + (projectedDensity .spherical f (observableRows z.1.2.2 z.2) + (labels (observableRows z.1.2.2 z.2) (z.1.2.2 0)))⁻¹^m := by + unfold observableLikelihood observe + simp only [differences_projectedTuple] + have he : (fun i => ⟪randomComplement (pairingColumns (differences z.1.2.2) z.2.1) z.2.2 i, + projectedTuple z.2.1 z.1.2.2 0⟫) = + labels (observableRows z.1.2.2 z.2) (z.1.2.2 0) := by + ext i + unfold observableRows labels projectedTuple rowMix + simp [sum_inner,inner_smul_left,PiLp.inner_apply,labels,mul_comm] + rw [he] + have hv : affineVolume (projectedTuple z.2.1 z.1.2.2) = + gramVolume (pairingColumns (differences z.1.2.2) z.2.1) := by + change gramVolume (differences (projectedTuple z.2.1 z.1.2.2)) = _ + rw [differences_projectedTuple] + rw [hv] + rfl + +lemma observableLikelihood_fixed_lintegral {d ℓ k m : ℕ} + (hk : 1 ≤ k) (hkm : k+m ≤ ℓ) {u : Tuple d m} + (hu : LinearIndependent ℝ (differences u)) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) (A : Rows d k) (y : Labels k) : + (∫⁻ b, observableLikelihood f (observe ((A,y,u),b)) ∂auxLaw d ℓ k) = + ∫⁻ A, replicaDensity .spherical f (A,labels A (u 0),u) ∂constrainedRows k u := by + simp_rw [observableLikelihood_observe] + rw [auxLaw,lintegral_prod _ (by fun_prop)] + have h := observable_gaussian_lintegral hu hkm + (H := fun z : Rows ℓ m × Rows d k => equalConstant k m * (wishartMoment ℓ m k)⁻¹ * + (ENNReal.ofReal (gramVolume z.1))⁻¹^k * + (projectedDensity .spherical f z.2 (labels z.2 (u 0)))⁻¹^m) (by unfold labels; fun_prop) + change _ = _ at h + rw [show (∫⁻ B, ∫⁻ e, equalConstant k m * (wishartMoment ℓ m k)⁻¹ * + (ENNReal.ofReal (gramVolume (pairingColumns (differences u) B)))⁻¹^k * + (projectedDensity .spherical f (observableRows u (B,e)) + (labels (observableRows u (B,e)) (u 0)))⁻¹^m ∂gaussianRows ℓ k ∂gaussianRows d ℓ) = _ from h] + simp_rw [lintegral_const_mul _ (show Measurable (fun A : Rows d k => + (projectedDensity .spherical f (fun i => (Submodule.span ℝ (range (differences u)))ᗮ.starProjection (A i)) + (labels (fun i => (Submodule.span ℝ (range (differences u)))ᗮ.starProjection (A i)) (u 0)))⁻¹^m) by unfold labels; fun_prop)] + rw [lintegral_mul_const _ (by fun_prop),lintegral_const_mul _ (by fun_prop),pairingColumns_inverse_moment hu (by omega : m ≤ ℓ)] + rw [constrainedRows,lintegral_map (by unfold replicaDensity labels; fun_prop) (by fun_prop)] + unfold replicaDensity + dsimp only + rw [lintegral_const_mul _ (by unfold labels; fun_prop)] + have hz := wishartMoment_pos (ℓ := ℓ) (m := m) (k := k) (by omega) + have ht := wishartMoment_ne_top hk hkm + have hc : equalConstant k m * (wishartMoment ℓ m k)⁻¹ * + ((ENNReal.ofReal (gramVolume (differences u)))⁻¹^k * wishartMoment ℓ m k) = + equalConstant k m * (ENNReal.ofReal (gramVolume (differences u)))⁻¹^k := by + calc + _ = (equalConstant k m * (ENNReal.ofReal (gramVolume (differences u)))⁻¹^k) * + ((wishartMoment ℓ m k)⁻¹ * wishartMoment ℓ m k) := by ring + _ = _ := by rw [ENNReal.inv_mul_cancel hz.ne' ht,mul_one] + rw [hc] + rfl + +lemma equalReference_tuple {d k m : ℕ} (ν : Measure (Vec d)) [IsProbabilityMeasure ν] : + (equalReference (k := k) (m := m) ν).map (fun z => z.2.2) = Measure.pi (fun _ => ν) := by + rw [equalReference,Measure.map_map (by fun_prop) measurable_rightBasePoint] + change ((Measure.pi (fun _ : Fin (m+1) => ν)).prod (gaussianRows d k)).map Prod.fst = _ + simp only [Measure.map_fst_prod,measure_univ,one_smul] + +lemma observableLikelihood_lintegral {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + (∫⁻ z : EqualSpace d k m × AuxSpace d ℓ k, observableLikelihood f (observe z) + ∂(equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)) = 1 := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have := replicaLaw_probability hd hk hm .spherical hf hLt hfL + rw [lintegral_prod _ (by fun_prop)] + have he : (fun z : EqualSpace d k m => ∫⁻ b, observableLikelihood f (observe (z,b)) ∂auxLaw d ℓ k) =ᵐ[ + equalReference ((sphereLaw d).withDensity f)] + (fun z => ∫⁻ b, observableLikelihood f (observe ((0,0,z.2.2),b)) ∂auxLaw d ℓ k) := by + exact ae_of_all _ (fun z => rfl) + rw [lintegral_congr_ae he, ← lintegral_map (f := fun u : Tuple d m => + ∫⁻ b, observableLikelihood f (observe (((0 : Rows d k),0,u),b)) ∂auxLaw d ℓ k) (by fun_prop) (by fun_prop), + equalReference_tuple] + calc + _ = ∫⁻ u : Tuple d m, ∫⁻ A, replicaDensity .spherical f (A,labels A (u 0),u) + ∂constrainedRows k u ∂Measure.pi (fun _ => (sphereLaw d).withDensity f) := by + apply lintegral_congr_ae + filter_upwards [ae_tilt_tuple_full_rank (by omega : 3 ≤ d) (by omega : m < d) + .spherical hf hLt hfL] with u hu + exact observableLikelihood_fixed_lintegral hk hkm hu hf 0 0 + _ = ∫⁻ z : EqualSpace d k m, replicaDensity .spherical f z + ∂equalReference ((sphereLaw d).withDensity f) := by + rw [equalReference_lintegral _ (by fun_prop)] + apply lintegral_congr_ae + filter_upwards [ae_tilt_tuple_full_rank (by omega : 3 ≤ d) (by omega : m < d) + .spherical hf hLt hfL] with u hu + rw [constrainedRows_eq_residualRows hu,lintegral_map (by unfold labels; fun_prop) (by fun_prop)] + _ = 1 := by + change (∫⁻ z, replicaDensity .spherical f z ∂equalReference ((BaseLaw.spherical.measure d).withDensity f)) = 1 + have hh := measure_univ (μ := replicaLaw (k := k) (m := m) .spherical f) + rw [replicaLaw,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ] at hh + exact hh + +lemma observableDensity_expected {d ℓ k m : ℕ} {u : Tuple d m} + (hu : LinearIndependent ℝ (differences u)) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) : + (∫⁻ b, projectedDensity .spherical f (observableRows u b) (labels (observableRows u b) (u 0)) + ∂auxLaw d ℓ k) = ∫⁻ A, projectedDensity .spherical f (residualRows u A) + (labels (residualRows u A) (u 0)) ∂gaussianRows d k := by + rw [← lintegral_map (f := fun A : Rows d k => projectedDensity .spherical f A (labels A (u 0))) + (by unfold labels; fun_prop) (by fun_prop),observableRows_law hu hkm, + constrainedRows_eq_residualRows hu,lintegral_map (by unfold labels; fun_prop) (by fun_prop)] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ObservationCorrelation.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ObservationCorrelation.lean new file mode 100644 index 0000000000000000000000000000000000000000..809b53abaefa61ad14c44e1e5415050ce00000ee --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ObservationCorrelation.lean @@ -0,0 +1,104 @@ +import OAI.Probability.PosteriorReplicas.Information.RandomCorrelation +import OAI.Probability.PosteriorReplicas.Kernels.LiftedReplica +import OAI.Probability.PosteriorReplicas.Kernels.ReplicaTupleMarginals + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma observe_law {d ℓ k m : ℕ} (μ : Measure (EqualSpace d k m)) [SFinite μ] : + (μ.prod (auxLaw d ℓ k)).map observe = + ((auxLaw d ℓ k).prod (μ.map (fun z => z.2.2))).map + (fun z => (z.1,projectedTuple z.1.1 z.2)) := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map hH (by fun_prop),lintegral_map hH (by fun_prop), + lintegral_prod _ (by fun_prop),lintegral_prod _ (by fun_prop)] + calc + _ = ∫⁻ b, ∫⁻ z, H (b,projectedTuple b.1 z.2.2) ∂μ ∂auxLaw d ℓ k := + lintegral_lintegral_swap (by fun_prop) + _ = _ := by + apply lintegral_congr + intro b + rw [lintegral_map (by fun_prop) (by fun_prop)] + +lemma totalCorrelation_projectedTuple {d ℓ m : ℕ} (Q : Measure (Tuple d m)) [IsProbabilityMeasure Q] + (B : Rows d ℓ) : totalCorrelation (Q.map (projectedTuple B)) = + totalCorrelation (Q.map (fun u i => labels B (u i))) := by + let h : (Fin (m+1) → Labels ℓ) → Tuple ℓ m := fun y i => WithLp.toLp 2 (y i) + let h' : Tuple ℓ m → (Fin (m+1) → Labels ℓ) := fun y i => WithLp.ofLp (y i) + have hh : Measurable h := by unfold h; fun_prop + have hh' : Measurable h' := by unfold h'; fun_prop + have he : Q.map (projectedTuple B) = (Q.map (fun u i => labels B (u i))).map h := by + rw [Measure.map_map hh (by unfold labels; fun_prop)] + rfl + rw [he] + change totalCorrelation ((Q.map (fun u i => labels B (u i))).map (fun y i => WithLp.toLp 2 (y i))) = _ + simp only [totalCorrelation] + have : IsProbabilityMeasure (Q.map (fun u i => labels B (u i))) := by infer_instance + rw [marginalProduct_map (ν := Q.map (fun u i => labels B (u i))) (g := WithLp.toLp 2) (by fun_prop)] + exact klDiv_map_leftInverse _ _ hh hh' (fun _ => rfl) + +lemma observe_klDiv_eq_correlation {d ℓ k m : ℕ} (μ ν : Measure (EqualSpace d k m)) + [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] + (hν : ν.map (fun z => z.2.2) = marginalProduct (μ.map (fun z => z.2.2))) : + klDiv ((μ.prod (auxLaw d ℓ k)).map observe) ((ν.prod (auxLaw d ℓ k)).map observe) = + ∫⁻ B, totalCorrelation ((μ.map (fun z => z.2.2)).map (fun u i => labels B (u i))) ∂gaussianRows d ℓ := by + have : IsProbabilityMeasure (μ.map (fun z => z.2.2)) := by infer_instance + rw [observe_law,observe_law,hν] + change klDiv (((auxLaw d ℓ k).prod (μ.map (fun z => z.2.2))).map + (fun z => (z.1,fun i => WithLp.toLp 2 (labels z.1.1 (z.2 i))))) + (((auxLaw d ℓ k).prod (marginalProduct (μ.map (fun z => z.2.2)))).map + (fun z => (z.1,fun i => WithLp.toLp 2 (labels z.1.1 (z.2 i))))) = _ + rw [klDiv_random_tuple_observation (auxLaw d ℓ k) (μ.map (fun z => z.2.2)) (g := fun z : AuxSpace d ℓ k × Vec d => WithLp.toLp 2 (labels z.1.1 z.2)) (by unfold labels; fun_prop)] + have he (b : AuxSpace d ℓ k) : totalCorrelation ((μ.map (fun z => z.2.2)).map + (fun u i => WithLp.toLp 2 (labels b.1 (u i)))) = + totalCorrelation ((μ.map (fun z => z.2.2)).map (fun u i => labels b.1 (u i))) := + totalCorrelation_projectedTuple _ b.1 + simp_rw [he] + rw [auxLaw,lintegral_prod _ (by + exact ((measurable_projected_totalCorrelation (μ.map (fun z => z.2.2)) measurable_labels).comp measurable_fst).aemeasurable)] + simp only [lintegral_const,measure_univ,mul_one] + +lemma replica_tuple_klDiv_le {d k m N : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + totalCorrelation (posteriorMessageLaw (m := m) .spherical hf κ).fst ≤ + klDiv (replicaLaw (k := k) (m := m) .spherical f) (equalReference ((sphereLaw d).withDensity f)) := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have := posteriorMessageLaw_probability (m := m) .spherical hf hLt hfL κ + have := replicaLaw_probability hd hk hm .spherical hf hLt hfL + rw [totalCorrelation,posteriorMessageLaw_marginalProduct (by omega) (by omega) .spherical hf hLt hfL κ, + posteriorMessageLaw_tuple hd hk hm .spherical hf hLt hfL κ] + change klDiv _ (Measure.pi (fun _ => (sphereLaw d).withDensity f)) ≤ _ + rw [← equalReference_tuple (k := k) ((sphereLaw d).withDensity f)] + exact klDiv_map_le _ _ (by fun_prop) + +lemma replica_observe_klDiv_eq {d ℓ k m N : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + klDiv (((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)).map observe) + (((equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)).map observe) = + ∫⁻ B, totalCorrelation ((posteriorMessageLaw (m := m) .spherical hf κ).fst.map + (fun u i => labels B (u i))) ∂gaussianRows d ℓ := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have := posteriorMessageLaw_probability (m := m) .spherical hf hLt hfL κ + have := replicaLaw_probability hd hk hm .spherical hf hLt hfL + rw [posteriorMessageLaw_tuple hd hk hm .spherical hf hLt hfL κ] + apply observe_klDiv_eq_correlation + rw [← posteriorMessageLaw_tuple hd hk hm .spherical hf hLt hfL κ, + posteriorMessageLaw_marginalProduct (by omega) (by omega) .spherical hf hLt hfL κ, + equalReference_tuple] + rfl + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ParametricKernel.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ParametricKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..76d22340c408cbd5a94ad7321bb08601177c6da3 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ParametricKernel.lean @@ -0,0 +1,92 @@ +import OAI.Probability.PosteriorReplicas.Information.CmiKernel + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +section +variable {T U V : Type*} [MeasurableSpace T] [MeasurableSpace U] [MeasurableSpace V] + +def parametricMapKernel (q : Measure U) (h : T × U → V) : Kernel T V := + (Kernel.id ×ₖ Kernel.const T q).map h + +instance parametricMapKernel_sfinite (q : Measure U) [SFinite q] + (h : T × U → V) : IsSFiniteKernel (parametricMapKernel q h) := by + unfold parametricMapKernel + infer_instance + +lemma parametricMapKernel_markov (q : Measure U) [IsProbabilityMeasure q] + (h : T × U → V) (hh : Measurable h) : IsMarkovKernel (parametricMapKernel q h) := + Kernel.IsMarkovKernel.map _ hh + +lemma parametricMapKernel_apply (q : Measure U) [SFinite q] + {h : T × U → V} (hh : Measurable h) (t : T) : + parametricMapKernel q h t = q.map (fun u => h (t,u)) := by + rw [parametricMapKernel, Kernel.map_apply _ hh, Kernel.prod_apply, + Kernel.id_apply, Kernel.const_apply, Measure.dirac_prod, + Measure.map_map hh (by fun_prop)] + rfl + +lemma compProd_parametricMapKernel (μ : Measure T) [SFinite μ] (q : Measure U) [SFinite q] + {h : T × U → V} (hh : Measurable h) : + μ ⊗ₘ parametricMapKernel q h = (μ.prod q).map (fun z => (z.1,h z)) := by + apply Measure.ext_of_lintegral + intro f hf + rw [Measure.lintegral_compProd hf, lintegral_map hf (by fun_prop), + lintegral_prod _ (by fun_prop)] + apply lintegral_congr + intro t + rw [parametricMapKernel_apply q hh, lintegral_map (by fun_prop) (by fun_prop)] +end + +section RandomSide +variable {T X Y Z : Type*} [MeasurableSpace T] [MeasurableSpace X] + [MeasurableSpace Y] [MeasurableSpace Z] + [StandardBorelSpace X] [StandardBorelSpace Y] [StandardBorelSpace Z] + [Nonempty X] [Nonempty Y] + +def randomSideLaw (μ : Measure T) (g : T × X → Z) (q : Measure (X × Y)) : + Measure ((T × Z) × (X × Y)) := + (μ.prod q).map (fun z => ((z.1,g (z.1,z.2.1)),z.2)) + +instance randomSideLaw_finite (μ : Measure T) [IsFiniteMeasure μ] + (g : T × X → Z) (q : Measure (X × Y)) [IsFiniteMeasure q] : + IsFiniteMeasure (randomSideLaw μ g q) := by unfold randomSideLaw; infer_instance + +lemma cmi_randomSideLaw (μ : Measure T) [IsFiniteMeasure μ] + {g : T × X → Z} (hg : Measurable g) (q : Measure (X × Y)) [IsProbabilityMeasure q] : + cmi (randomSideLaw μ g q) = ∫⁻ t, cmi (attachSide (fun x => g (t,x)) q) ∂μ := by + let h : T × (X × Y) → Z × (X × Y) := fun z => (g (z.1,z.2.1),z.2) + have hh : Measurable h := by fun_prop + let κ := parametricMapKernel q h + have : IsMarkovKernel κ := parametricMapKernel_markov q h hh + have he : (μ ⊗ₘ κ).map (MeasurableEquiv.prodAssoc.symm : + T × (Z × (X × Y)) ≃ᵐ (T × Z) × (X × Y)) = randomSideLaw μ g q := by + rw [compProd_parametricMapKernel μ q hh, Measure.map_map (by fun_prop) (by fun_prop)] + rfl + have ht (t : T) : κ t = attachSide (fun x => g (t,x)) q := by + rw [parametricMapKernel_apply q hh] + rfl + have hc := cmi_compProd_assoc μ κ + simpa only [he, ht] using hc + +lemma measurable_cmi_attachSide {g : T × X → Z} (hg : Measurable g) + (q : Measure (X × Y)) [IsProbabilityMeasure q] : + Measurable (fun t => cmi (attachSide (fun x => g (t,x)) q)) := by + let h : T × (X × Y) → Z × (X × Y) := fun z => (g (z.1,z.2.1),z.2) + have hh : Measurable h := by fun_prop + let κ := parametricMapKernel q h + have : IsMarkovKernel κ := parametricMapKernel_markov q h hh + have ht (t : T) : κ t = attachSide (fun x => g (t,x)) q := by + rw [parametricMapKernel_apply q hh] + rfl + simpa only [ht] using cmi_kernel_measurable κ +end RandomSide + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/PiKL.lean b/lean/OAI/Probability/PosteriorReplicas/Information/PiKL.lean new file mode 100644 index 0000000000000000000000000000000000000000..5627069c0158b718f632ba3cf50fd01921b5de22 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/PiKL.lean @@ -0,0 +1,96 @@ +import OAI.Probability.PosteriorReplicas.Information.KLTools +import OAI.Probability.PosteriorReplicas.Kernels.KernelPi + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma probability_measure_eq_of_subsingleton {X : Type*} [MeasurableSpace X] [Subsingleton X] + (μ ν : Measure X) [IsProbabilityMeasure μ] [IsProbabilityMeasure ν] : μ = ν := by + ext s hs + by_cases h : s.Nonempty + · have he : s = univ := by + obtain ⟨x,hx⟩ := h + apply eq_univ_of_forall + intro y + simpa only [Subsingleton.elim y x] using hx + simp [he] + · simp [Set.not_nonempty_iff_eq_empty.mp h] + +def coordinateMarginal {Y : Type*} [MeasurableSpace Y] {n : ℕ} + (q : Measure (Fin n → Y)) (i : Fin n) : Measure Y := q.map (fun u => u i) + +instance coordinateMarginal_probability {Y : Type*} [MeasurableSpace Y] {n : ℕ} + (q : Measure (Fin n → Y)) [IsProbabilityMeasure q] (i : Fin n) : + IsProbabilityMeasure (coordinateMarginal q i) := + inferInstanceAs (IsProbabilityMeasure (q.map (fun u => u i))) + +def marginalProduct {Y : Type*} [MeasurableSpace Y] {n : ℕ} + (q : Measure (Fin n → Y)) : Measure (Fin n → Y) := Measure.pi (coordinateMarginal q) + +instance marginalProduct_probability {Y : Type*} [MeasurableSpace Y] {n : ℕ} + (q : Measure (Fin n → Y)) [IsProbabilityMeasure q] : IsProbabilityMeasure (marginalProduct q) := by + unfold marginalProduct + infer_instance + +lemma piFinSucc_fst {Y : Type*} [MeasurableSpace Y] {n : ℕ} + (q : Measure (Fin (n+1) → Y)) : + (q.map (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => Y) 0)).fst = + coordinateMarginal q 0 := by + rw [Measure.fst, Measure.map_map measurable_fst (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => Y) 0).measurable] + rfl + +lemma piFinSucc_tail_marginal {Y : Type*} [MeasurableSpace Y] {n : ℕ} + (q : Measure (Fin (n+1) → Y)) (i : Fin n) : + coordinateMarginal (q.map (MeasurableEquiv.piFinSuccAbove + (fun _ : Fin (n+1) => Y) 0)).snd i = coordinateMarginal q i.succ := by + unfold coordinateMarginal Measure.snd + rw [Measure.map_map measurable_snd (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => Y) 0).measurable, + Measure.map_map (measurable_pi_apply i) (measurable_snd.comp (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => Y) 0).measurable)] + rfl + +lemma klDiv_pi_decomposition {Y : Type*} [MeasurableSpace Y] [StandardBorelSpace Y] [Nonempty Y] + {n : ℕ} (q : Measure (Fin n → Y)) [IsProbabilityMeasure q] + (ρ : Fin n → Measure Y) [∀ i, IsProbabilityMeasure (ρ i)] : + klDiv q (Measure.pi ρ) = klDiv q (marginalProduct q) + ∑ i, klDiv (coordinateMarginal q i) (ρ i) := by + induction n with + | zero => + have h1 := probability_measure_eq_of_subsingleton q (Measure.pi ρ) + have h2 := probability_measure_eq_of_subsingleton q (marginalProduct q) + simp only [← h1, ← h2, klDiv_self, Finset.univ_eq_empty, Finset.sum_empty, add_zero] + | succ n ih => + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => Y) 0 + let r := q.map e + have : IsProbabilityMeasure r := inferInstance + have hρ : (Measure.pi ρ).map e = (ρ 0).prod (Measure.pi (fun i : Fin n => ρ i.succ)) := + (measurePreserving_piFinSuccAbove ρ 0).map_eq + have ho : (marginalProduct q).map e = r.fst.prod (marginalProduct r.snd) := by + rw [marginalProduct, (measurePreserving_piFinSuccAbove (coordinateMarginal q) 0).map_eq] + congr 1 + · exact (piFinSucc_fst q).symm + · unfold marginalProduct + congr 1 + funext i + exact (piFinSucc_tail_marginal q i).symm + have hD : klDiv q (Measure.pi ρ) = + klDiv r.fst (ρ 0) + klDiv r.snd (Measure.pi (fun i : Fin n => ρ i.succ)) + + klDiv r (r.fst.prod r.snd) := by + rw [← klDiv_map_equiv _ _ e, hρ] + exact klDiv_prod_decomposition r (ρ 0) _ + have hC : klDiv q (marginalProduct q) = + klDiv r.snd (marginalProduct r.snd) + klDiv r (r.fst.prod r.snd) := by + rw [← klDiv_map_equiv _ _ e, ho, klDiv_prod_decomposition r r.fst _, klDiv_self, zero_add] + rw [hD, hC, ih r.snd (fun i : Fin n => ρ i.succ), Fin.sum_univ_succ] + have hf : r.fst = coordinateMarginal q 0 := piFinSucc_fst q + have ht : ∀ i : Fin n, coordinateMarginal r.snd i = coordinateMarginal q i.succ := + piFinSucc_tail_marginal q + simp_rw [hf, ht] + ac_rfl + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/RandomCorrelation.lean b/lean/OAI/Probability/PosteriorReplicas/Information/RandomCorrelation.lean new file mode 100644 index 0000000000000000000000000000000000000000..e4652a7604bc89c2759349febc34a20354676e48 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/RandomCorrelation.lean @@ -0,0 +1,36 @@ +import OAI.Probability.PosteriorReplicas.Information.ParametricKernel + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma klDiv_random_tuple_observation {T Y Z : Type*} + [MeasurableSpace T] [MeasurableSpace Y] [MeasurableSpace Z] + [StandardBorelSpace Y] [Nonempty Y] [StandardBorelSpace Z] [Nonempty Z] + {n : ℕ} (β : Measure T) [IsProbabilityMeasure β] + (Q : Measure (Fin n → Y)) [IsProbabilityMeasure Q] + {g : T × Y → Z} (hg : Measurable g) : + klDiv ((β.prod Q).map (fun z => (z.1,fun i => g (z.1,z.2 i)))) + ((β.prod (marginalProduct Q)).map (fun z => (z.1,fun i => g (z.1,z.2 i)))) = + ∫⁻ b, totalCorrelation (Q.map (fun u i => g (b,u i))) ∂β := by + let h : T × (Fin n → Y) → (Fin n → Z) := fun z i => g (z.1,z.2 i) + have hh : Measurable h := by unfold h; fun_prop + let κ := parametricMapKernel Q h + let η := parametricMapKernel (marginalProduct Q) h + have : IsMarkovKernel κ := parametricMapKernel_markov Q h hh + have : IsMarkovKernel η := parametricMapKernel_markov (marginalProduct Q) h hh + rw [← compProd_parametricMapKernel β Q hh,← compProd_parametricMapKernel β (marginalProduct Q) hh] + change klDiv (β ⊗ₘ κ) (β ⊗ₘ η) = _ + rw [klDiv_compProd_kernel] + apply lintegral_congr + intro b + simp only [κ,η,parametricMapKernel_apply _ hh,h] + rw [totalCorrelation,marginalProduct_map (ν := Q) (g := fun y => g (b,y)) (by fun_prop)] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/RandomProjectionInformation.lean b/lean/OAI/Probability/PosteriorReplicas/Information/RandomProjectionInformation.lean new file mode 100644 index 0000000000000000000000000000000000000000..ce0e38af2ee2666ffad3aa9f69cd3021261f4fbb --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/RandomProjectionInformation.lean @@ -0,0 +1,85 @@ +import OAI.Probability.PosteriorReplicas.Information.ParametricKernel + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +section +variable {T Y Z : Type*} [MeasurableSpace T] [MeasurableSpace Y] [MeasurableSpace Z] + [StandardBorelSpace Y] [StandardBorelSpace Z] [Nonempty Y] [Nonempty Z] + {n : ℕ} + +omit [StandardBorelSpace Y] [Nonempty Y] [Nonempty Z] in +lemma measurable_projected_totalCorrelation (ν : Measure (Fin n → Y)) [IsProbabilityMeasure ν] + {g : T × Y → Z} (hg : Measurable g) : + Measurable (fun b => totalCorrelation (ν.map (fun u i => g (b,u i)))) := by + let h : T × (Fin n → Y) → (Fin n → Z) := fun z i => g (z.1,z.2 i) + have hh : Measurable h := by fun_prop + let κ := parametricMapKernel ν h + have : IsMarkovKernel κ := parametricMapKernel_markov ν h hh + have hc := measurable_kernel_klDiv κ (piKernel (coordKernel κ)) + simp only [piKernel_apply, coordKernel_apply] at hc + change Measurable (fun b => totalCorrelation (κ b)) at hc + simpa only [κ, parametricMapKernel_apply ν hh, h] using hc +end + +section +variable {T W Y Z : Type*} [MeasurableSpace T] [MeasurableSpace W] + [MeasurableSpace Y] [MeasurableSpace Z] + [StandardBorelSpace W] [Nonempty W] [Fintype W] [MeasurableSingletonClass W] + [StandardBorelSpace Y] [Nonempty Y] [StandardBorelSpace Z] [Nonempty Z] + {n : ℕ} (β : Measure T) [IsProbabilityMeasure β] + (μ : Measure W) [IsProbabilityMeasure μ] + (κ : Kernel W (Fin n → Y)) [IsMarkovKernel κ] + {g : T × Y → Z} (hg : Measurable g) +include hg + +lemma random_replica_information_le_entropy : + (∑ i, cmi (randomSideLaw β g (coordinateJoint μ κ i))) + + (∫⁻ b, totalCorrelation ((μ ⊗ₘ κ).snd.map (fun u i => g (b,u i))) ∂β) ≤ + totalCorrelation (μ ⊗ₘ κ).snd + ENNReal.ofReal (finiteEntropy μ) := by + have hi (i : Fin n) := measurable_cmi_attachSide hg (coordinateJoint μ κ i) + have ht := measurable_projected_totalCorrelation (μ ⊗ₘ κ).snd hg + have h := lintegral_mono (μ := β) (fun b => + replica_information_le_entropy μ κ (g := fun y => g (b,y)) (by fun_prop)) + rw [lintegral_add_aux (Finset.measurable_sum _ (fun i _ => hi i)) ht, + lintegral_finsetSum _ (fun i _ => hi i)] at h + simp only [lintegral_const, measure_univ, mul_one] at h + simpa only [cmi_randomSideLaw β hg] using h + +lemma random_replica_information_identical (q : Measure (Y × W)) [IsProbabilityMeasure q] + (hq : ∀ i, coordinateJoint μ κ i = q) : + (n : ℝ≥0∞) * cmi (randomSideLaw β g q) + + (∫⁻ b, totalCorrelation ((μ ⊗ₘ κ).snd.map (fun u i => g (b,u i))) ∂β) ≤ + totalCorrelation (μ ⊗ₘ κ).snd + ENNReal.ofReal (finiteEntropy μ) := by + have h := random_replica_information_le_entropy β μ κ hg + have hs : (∑ i, cmi (randomSideLaw β g (coordinateJoint μ κ i))) = + (n : ℝ≥0∞) * cmi (randomSideLaw β g q) := by + calc + _ = ∑ _i : Fin n, cmi (randomSideLaw β g q) := by + apply Finset.sum_congr rfl + intro i _ + cases hq i + rfl + _ = _ := by simp + rw [hs] at h + exact h +end + +lemma conditionalInformation_eq_cmi {d ℓ N : ℕ} [NeZero N] + (q : Measure (Data d ℓ × (Vec d × Fin N))) [IsFiniteMeasure q] : + conditionalInformation q = cmi q := rfl + +lemma sideLaw_eq_randomSideLaw {d ℓ N : ℕ} (q : Measure (Vec d × Fin N)) : + sideLaw ℓ q = randomSideLaw (gaussianRows d ℓ) (fun z => labels z.1 z.2) q := rfl + +lemma messageEntropy_eq_finiteEntropy {d N : ℕ} (q : Measure (Vec d × Fin N)) : + messageEntropy q = finiteEntropy q.snd := rfl + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaCost.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaCost.lean new file mode 100644 index 0000000000000000000000000000000000000000..ade53d7fab3f314045b4ac5b551bf7e15988bb38 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaCost.lean @@ -0,0 +1,107 @@ +import OAI.Probability.PosteriorReplicas.Information.ReplicaLoss + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Matrix InnerProductSpace Filter Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma gaussianMomentConstant_log_le {k : ℕ} (hk : 1 ≤ k) : + Real.log (gaussianMomentConstant k).toReal ≤ -(k:ℝ)/2*Real.log k + 4*k := by + have hkp : 0 < (k:ℝ) := by exact_mod_cast (by omega : 0 Real.log (replicaDensity .spherical f z).toReal) + (replicaLaw .spherical f) := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have hd' : k+m+2 ≤ d := by omega + have := replicaLaw_probability hd' hk hm .spherical hf hLt hfL + let R : Measure (EqualSpace d k m) := equalReference ((sphereLaw d).withDensity f) + let w : EqualSpace d k m → ℝ≥0∞ := fun z => equalConstant k m * (ENNReal.ofReal (affineVolume z.2.2))⁻¹^k + let a : EqualSpace d k m → ℝ≥0∞ := fun z => projectedDensity .spherical f z.1 z.2.1 + have hw : Measurable w := by unfold w; fun_prop + have ha : Measurable a := by unfold a; fun_prop + have he : R.withDensity (fun z => ENNReal.ofReal ((w z).toReal * (a z).toReal⁻¹^m)) = + replicaLaw .spherical f := by + apply withDensity_congr_ae + filter_upwards [replicaDensity_ne_top_ae hd' hk hm .spherical hf hLt hfL] with z hz + rw [← ENNReal.toReal_inv, ← ENNReal.toReal_pow, ← ENNReal.toReal_mul] + exact ENNReal.ofReal_toReal hz + have : IsFiniteMeasure (R.withDensity (fun z => ENNReal.ofReal ((w z).toReal * (a z).toReal⁻¹^m))) := by + rw [he]; infer_instance + have hw4 : Integrable (fun z => (w z).toReal^4) R := by + have h := reference_weight_moment (n := 4) (by omega : k*4+m+2 ≤ d) hm .spherical hf hLt hfL + simpa only [ENNReal.toReal_pow, BaseLaw.measure, R] using + (integrable_toReal_of_lintegral_ne_top (hw.pow_const 4).aemeasurable h.ne) + have hwa : Integrable (fun z => (w z).toReal * (a z).toReal⁻¹^(m+1)) R := by + have h := reference_inverse_density_moment hd' hk hm .spherical hf hLt hfL + have ht : (∫⁻ z, w z * (a z)⁻¹^(m+1) ∂ R) < ∞ := by + exact lt_of_eq_of_lt (by simpa only [R,w,a,BaseLaw.measure] using h) + (gaussian_label_support_volume_finite (by omega) (by omega) hf) + simpa only [ENNReal.toReal_mul, ENNReal.toReal_pow, ENNReal.toReal_inv] using + (integrable_toReal_of_lintegral_ne_top (show AEMeasurable (fun z => w z * (a z)⁻¹^(m+1)) R by fun_prop) ht.ne) + have hap : ∀ᵐ z ∂ R, 0 < (a z).toReal := by + filter_upwards [ae_equalReference_density_pos hd' hk hm .spherical hf hLt hfL] with z hz + exact ENNReal.toReal_pos hz.ne' (projectedDensity_ne_top .spherical hLt hfL z.1 z.2.1) + have hi := replica_likelihood_integrable R hw.ennreal_toReal ha.ennreal_toReal + (ae_of_all _ (fun z => ENNReal.toReal_nonneg)) hap m hw4 hwa + rw [he] at hi + simpa only [replicaDensity, ENNReal.toReal_mul, ENNReal.toReal_pow, ENNReal.toReal_inv, w, a] using hi + +lemma replica_klDiv_ne_top {d k m : ℕ} (hd : 4*k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + klDiv (replicaLaw (k := k) (m := m) .spherical f) + (equalReference ((sphereLaw d).withDensity f)) ≠ ∞ := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have := replicaLaw_probability (by omega : k+m+2 ≤ d) hk hm .spherical hf hLt hfL + apply klDiv_ne_top_iff.mpr + refine ⟨withDensity_absolutelyContinuous _ _, ?_⟩ + have : IsFiniteMeasure + ((equalReference ((BaseLaw.spherical.measure d).withDensity f)).withDensity + (@replicaDensity d k m .spherical f)) := by + change IsFiniteMeasure (replicaLaw (k := k) (m := m) .spherical f); infer_instance + exact (replica_log_integrable hd hk hm hf hLt hfL).congr + (llr_withDensity_ae _ (measurable_replicaDensity .spherical hf)).symm + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaInformation.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaInformation.lean new file mode 100644 index 0000000000000000000000000000000000000000..2868a525ddebf19bde23cf0b881e9115498bb91b --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaInformation.lean @@ -0,0 +1,156 @@ +import OAI.Probability.PosteriorReplicas.Information.ConditionalPiKL +import OAI.Probability.PosteriorReplicas.Information.FiniteKL +import OAI.Probability.PosteriorReplicas.Information.GraphKL + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +def mutualInformation {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (q : Measure (X × Y)) : ℝ≥0∞ := klDiv q (q.fst.prod q.snd) + +def totalCorrelation {Y : Type*} [MeasurableSpace Y] {n : ℕ} + (q : Measure (Fin n → Y)) : ℝ≥0∞ := klDiv q (marginalProduct q) + +lemma snd_compProd_map {X Y Z : Type*} [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + (μ : Measure X) [SFinite μ] (κ : Kernel X Y) [IsSFiniteKernel κ] + {g : Y → Z} (hg : Measurable g) : + (μ ⊗ₘ κ.map g).snd = (μ ⊗ₘ κ).snd.map g := by + rw [Measure.compProd_map hg, Measure.snd, Measure.map_map measurable_snd (by fun_prop), + Measure.snd, Measure.map_map hg measurable_snd] + rfl + +lemma mutualInformation_swap {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (q : Measure (X × Y)) [IsProbabilityMeasure q] : + mutualInformation (q.map Prod.swap) = mutualInformation q := by + unfold mutualInformation + rw [Measure.fst_map_swap, Measure.snd_map_swap, ← Measure.prod_swap, klDiv_swap] + +section Coordinates +variable {W Y : Type*} [MeasurableSpace W] [StandardBorelSpace W] [Nonempty W] + [MeasurableSpace Y] [StandardBorelSpace Y] [Nonempty Y] {n : ℕ} + (μ : Measure W) [IsProbabilityMeasure μ] (κ : Kernel W (Fin n → Y)) [IsMarkovKernel κ] + +def coordinateJoint (i : Fin n) : Measure (Y × W) := + (μ ⊗ₘ coordKernel κ i).map Prod.swap + +instance coordinateJoint_probability (i : Fin n) : IsProbabilityMeasure (coordinateJoint μ κ i) := by + unfold coordinateJoint + infer_instance + +omit [StandardBorelSpace W] [Nonempty W] [StandardBorelSpace Y] [Nonempty Y] in +lemma coordinateJoint_fst (i : Fin n) : + (coordinateJoint μ κ i).fst = coordinateMarginal (μ ⊗ₘ κ).snd i := by + rw [coordinateJoint, Measure.fst_map_swap, coordKernel, snd_compProd_map _ _ (measurable_pi_apply i)] + rfl + +omit [StandardBorelSpace W] [Nonempty W] [StandardBorelSpace Y] [Nonempty Y] in +lemma coordinateJoint_snd (i : Fin n) : (coordinateJoint μ κ i).snd = μ := by + rw [coordinateJoint, Measure.snd_map_swap, Measure.fst_compProd] + +omit [StandardBorelSpace W] [Nonempty W] [StandardBorelSpace Y] [Nonempty Y] in +lemma coordinateJoint_information (i : Fin n) : + mutualInformation (coordinateJoint μ κ i) = + klDiv (μ ⊗ₘ coordKernel κ i) (μ.prod (coordinateMarginal (μ ⊗ₘ κ).snd i)) := by + rw [coordinateJoint, mutualInformation_swap, mutualInformation, Measure.fst_compProd, + coordKernel, snd_compProd_map _ _ (measurable_pi_apply i)] + rfl + +lemma tuple_information_decomposition : + conditionalTotalCorrelation μ κ + ∑ i, mutualInformation (coordinateJoint μ κ i) = + totalCorrelation (μ ⊗ₘ κ).snd + mutualInformation (μ ⊗ₘ κ) := by + simp_rw [coordinateJoint_information] + simpa only [totalCorrelation, mutualInformation, Measure.fst_compProd] using + conditionalTotalCorrelation_identity μ κ + +end Coordinates + +section Projection +variable {W Y Z : Type*} [MeasurableSpace W] [StandardBorelSpace W] [Nonempty W] + [MeasurableSpace Y] [StandardBorelSpace Y] [Nonempty Y] + [MeasurableSpace Z] [StandardBorelSpace Z] [Nonempty Z] {n : ℕ} + (μ : Measure W) [IsProbabilityMeasure μ] (κ : Kernel W (Fin n → Y)) [IsMarkovKernel κ] + {g : Y → Z} (hg : Measurable g) +include hg + +omit [StandardBorelSpace W] [Nonempty W] [StandardBorelSpace Y] [Nonempty Y] + [StandardBorelSpace Z] [Nonempty Z] in +lemma coordinateJoint_projection (i : Fin n) : + coordinateJoint μ (κ.map (fun u j => g (u j))) i = + (coordinateJoint μ κ i).map (fun z => (g z.1,z.2)) := by + unfold coordinateJoint coordKernel + rw [Measure.compProd_map (measurable_pi_apply i), + Measure.compProd_map (show Measurable (fun u : Fin n → Y => fun j => g (u j)) by fun_prop), + Measure.compProd_map (measurable_pi_apply i)] + repeat rw [Measure.map_map (by fun_prop) (by fun_prop)] + rfl + +omit [StandardBorelSpace Z] [Nonempty Z] in +lemma coordinate_information_chain (i : Fin n) : + mutualInformation (coordinateJoint μ κ i) = + cmi (attachSide g (coordinateJoint μ κ i)) + + mutualInformation (coordinateJoint μ (κ.map (fun u j => g (u j))) i) := by + have h := mutualInformation_attachSide_chain hg (coordinateJoint μ κ i) + dsimp only at h + rw [coordinateJoint_projection μ κ hg] + unfold mutualInformation + have hfst : ((coordinateJoint μ κ i).map (fun z => (g z.1,z.2))).fst = + (coordinateJoint μ κ i).fst.map g := by + rw [Measure.fst, Measure.map_map measurable_fst (by fun_prop), + Measure.fst, Measure.map_map hg measurable_fst] + rfl + have hsnd : ((coordinateJoint μ κ i).map (fun z => (g z.1,z.2))).snd = + (coordinateJoint μ κ i).snd := by + rw [Measure.snd, Measure.map_map measurable_snd (by fun_prop)] + rfl + rwa [hfst, hsnd] + +lemma replica_information_inequality : + (∑ i, cmi (attachSide g (coordinateJoint μ κ i))) + + totalCorrelation ((μ ⊗ₘ κ).snd.map (fun u i => g (u i))) ≤ + totalCorrelation (μ ⊗ₘ κ).snd + mutualInformation (μ ⊗ₘ κ) := by + let κ' := κ.map (fun u i => g (u i)) + have : IsMarkovKernel κ' := Kernel.IsMarkovKernel.map _ (by fun_prop) + have hc := conditionalTotalCorrelation_map_le μ κ hg + have h := tuple_information_decomposition μ κ + have h' := tuple_information_decomposition μ κ' + have hm : (μ ⊗ₘ κ').snd = (μ ⊗ₘ κ).snd.map (fun u i => g (u i)) := + snd_compProd_map _ _ (by fun_prop) + rw [← hm, ← h] + have hs : (∑ i, mutualInformation (coordinateJoint μ κ i)) = + (∑ i, cmi (attachSide g (coordinateJoint μ κ i))) + + ∑ i, mutualInformation (coordinateJoint μ κ' i) := by + simp_rw [coordinate_information_chain μ κ hg, Finset.sum_add_distrib] + rfl + rw [hs] + calc + _ ≤ (∑ i, cmi (attachSide g (coordinateJoint μ κ i))) + + (totalCorrelation (μ ⊗ₘ κ').snd + mutualInformation (μ ⊗ₘ κ')) := + add_le_add le_rfl le_self_add + _ = (∑ i, cmi (attachSide g (coordinateJoint μ κ i))) + + (conditionalTotalCorrelation μ κ' + ∑ i, mutualInformation (coordinateJoint μ κ' i)) := by + rw [h'] + _ ≤ (∑ i, cmi (attachSide g (coordinateJoint μ κ i))) + + (conditionalTotalCorrelation μ κ + ∑ i, mutualInformation (coordinateJoint μ κ' i)) := + add_le_add le_rfl (add_le_add hc le_rfl) + _ = _ := by ac_rfl + +lemma replica_information_le_entropy [Fintype W] [MeasurableSingletonClass W] : + (∑ i, cmi (attachSide g (coordinateJoint μ κ i))) + + totalCorrelation ((μ ⊗ₘ κ).snd.map (fun u i => g (u i))) ≤ + totalCorrelation (μ ⊗ₘ κ).snd + ENNReal.ofReal (finiteEntropy μ) := by + apply (replica_information_inequality μ κ hg).trans + refine add_le_add le_rfl ?_ + have : IsProbabilityMeasure ((μ ⊗ₘ κ).map Prod.swap) := inferInstance + have h := mutualInformation_le_finiteEntropy ((μ ⊗ₘ κ).map Prod.swap) + change mutualInformation ((μ ⊗ₘ κ).map Prod.swap) ≤ _ at h + simpa only [mutualInformation_swap, Measure.snd_map_swap, Measure.fst_compProd] using h + +end Projection +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaInformationBound.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaInformationBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..8b42b3abed6b81d59b14743a901a5ff87bb3410c --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaInformationBound.lean @@ -0,0 +1,65 @@ +import OAI.Probability.PosteriorReplicas.Information.ObservationCorrelation +import OAI.Probability.PosteriorReplicas.Information.ReplicaLoss + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma finiteEntropy_nonneg {W : Type*} [Fintype W] [MeasurableSpace W] [MeasurableSingletonClass W] + (q : Measure W) [IsProbabilityMeasure q] : 0 ≤ finiteEntropy q := by + simpa only [finiteEntropy, neg_mul, mul_neg] using finite_crossEntropy_nonneg q q + +lemma information_of_correlation_loss {t : ℕ} (ht : 0 posteriorMessageLaw_coordinate (by omega) (by omega) .spherical hf hLt hfL κ i) + (g := fun z => labels z.1 z.2) measurable_labels + have hQ : Q.snd = q.snd := posteriorMessageLaw_message (by omega) (by omega) .spherical hf hLt hfL κ + rw [hQ] at hinfo + have hTC := replica_tuple_klDiv_le hd' hk hm hf hLt hfL κ + have hinfo' := hinfo.trans (add_le_add hTC le_rfl) + have hloss := replica_lifted_loss hd hk hm hkm hf hLt hfL J hcut + rw [replica_observe_klDiv_eq hd' hk hm hf hLt hfL κ] at hloss + exact information_of_correlation_loss (by omega : 0 < m + 1) + (replica_klDiv_ne_top hd hk hm hf hLt hfL) (finiteEntropy_nonneg q.snd) hinfo' hloss + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaLoss.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaLoss.lean new file mode 100644 index 0000000000000000000000000000000000000000..37f8a4e104c8167f56e970094df5e919a1042277 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaLoss.lean @@ -0,0 +1,172 @@ +import OAI.Probability.PosteriorReplicas.Information.LogComparison +import OAI.Probability.PosteriorReplicas.Kernels.LiftedReplica + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Matrix InnerProductSpace Filter Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +def binMeanBound (k J : ℕ) : ℝ := + (volume {y : Labels k | labelNorm y ≤ 1}).toReal * (2+(J:ℝ)*2^k) + +lemma label_unitBall_ne_top (k : ℕ) : (volume {y : Labels k | labelNorm y ≤ 1}) ≠ ∞ := by + rw [label_closedBall_volume] + exact measure_closedBall_lt_top.ne + +lemma label_unitBall_pos (k : ℕ) : 0 < (volume {y : Labels k | labelNorm y ≤ 1}) := by + rw [label_closedBall_volume] + exact (measure_ball_pos volume (0 : Vec k) (by norm_num : (0:ℝ)<1)).trans_le + (measure_mono ball_subset_closedBall) + +lemma binMeanBound_pos (k J : ℕ) : 0 < binMeanBound k J := by + unfold binMeanBound + exact mul_pos (ENNReal.toReal_pos (label_unitBall_pos k).ne' (label_unitBall_ne_top k)) (by positivity) + +lemma binMeanBound_eq (k J : ℕ) : ENNReal.ofReal (binMeanBound k J) = + volume {y : Labels k | labelNorm y ≤ 1} * (2+(J:ℝ≥0∞)*2^k) := by + unfold binMeanBound + rw [ENNReal.ofReal_mul ENNReal.toReal_nonneg, ENNReal.ofReal_toReal (label_unitBall_ne_top k), + ENNReal.ofReal_add (by norm_num) (by positivity),ENNReal.ofReal_mul (by positivity)] + simp only [ENNReal.ofReal_ofNat, ENNReal.ofReal_natCast, ENNReal.ofReal_pow (by norm_num : (0:ℝ)≤2)] + +lemma normalizedRatio_integrable_mean {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] (J : ℕ) + (hcut : (L*ENNReal.ofReal ((72:ℝ)^d))*ENNReal.ofReal ((1/2:ℝ)^J)* + (1+(2:ℝ≥0∞)^(k+1)) ≤ 1) : + Integrable (fun z => (normalizedRatio f z).toReal) + ((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) ∧ + (∫ z, (normalizedRatio f z).toReal + ∂(replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) ≤ binMeanBound k J := by + have hb := normalizedRatio_lintegral_le hd hk hm hkm hf hLt hfL J hcut + rw [← binMeanBound_eq] at hb + have ht := ne_top_of_le_ne_top ENNReal.ofReal_ne_top hb + refine ⟨integrable_toReal_of_lintegral_ne_top (by fun_prop) ht,?_⟩ + rw [integral_toReal (by fun_prop) (ae_lt_top (by fun_prop) ht)] + exact (ENNReal.toReal_le_toReal ht ENNReal.ofReal_ne_top).mpr hb |>.trans_eq + (ENNReal.toReal_ofReal (binMeanBound_pos k J).le) + +def comparisonEnvelope {d ℓ k m : ℕ} (f : Vec d → ℝ≥0∞) (J : ℕ) + (z : EqualSpace d k m × AuxSpace d ℓ k) : ℝ := + Real.log (wishartMoment ℓ m k).toReal + (k:ℝ)*Real.log (projectionGramRatio z) + + (m:ℝ)*Real.log (gramVolume z.1.1) + + (m:ℝ)*(Real.log (binMeanBound k J) + (normalizedRatio f z).toReal / binMeanBound k J - 1) + +lemma replica_log_comparison_ae {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] (J : ℕ) : + ∀ᵐ z ∂(replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k), + llr ((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) + ((equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)) z - + observableLog f (observe z) ≤ comparisonEnvelope f J z := by + have ha := (Measure.quasiMeasurePreserving_fst (ν := auxLaw d ℓ k)).ae (replicaLaw_ae_of_reference (k := k) (m := m) .spherical f + (ae_equalReference_density_pos hd hk hm .spherical hf hLt hfL)) + have hJ := (Measure.quasiMeasurePreserving_fst (ν := auxLaw d ℓ k)).ae (replicaLaw_ae_of_reference (k := k) (m := m) .spherical f + (ae_equalReference_affine_pos (by omega) (by omega) .spherical hf hLt hfL)) + have hA := (Measure.quasiMeasurePreserving_fst (ν := auxLaw d ℓ k)).ae (replicaLaw_ae_sensing_full_rank hd hk hm hf hLt hfL) + filter_upwards [ha,hJ,hA,liftedReplica_llr hd hk hm hf hLt hfL, + liftedReplica_ae_observable_density_pos hd hk hm hkm hf hLt hfL, + liftedReplica_ae_projectionGram_pos (by omega) (by omega) (by omega) hf hLt hfL] with z haz hJz hAz hll hz' hJ' + rw [hll] + unfold observableLog + rw [observableLikelihood_observe] + have hc : 0 < (equalConstant k m).toReal := ENNReal.toReal_pos + (equalConstant_pos k m).ne' (by unfold equalConstant; exact ENNReal.ofReal_ne_top) + have hZ : 0 < (wishartMoment ℓ m k).toReal := ENNReal.toReal_pos + (wishartMoment_pos (by omega : m ≤ ℓ)).ne' (wishartMoment_ne_top hk hkm) + have hato : 0 < (projectedDensity .spherical f z.1.1 z.1.2.1).toReal := + ENNReal.toReal_pos haz.ne' (projectedDensity_ne_top .spherical hLt hfL _ _) + have ha'to : 0 < (projectedDensity .spherical f (observableRows z.1.2.2 z.2) + (labels (observableRows z.1.2.2 z.2) (z.1.2.2 0))).toReal := + ENNReal.toReal_pos hz'.ne' (projectedDensity_ne_top .spherical hLt hfL _ _) + have h := log_replica_comparison hc hZ hJz hJ' hato ha'to (gramVolume_pos hAz) (binMeanBound_pos k J) k m + simpa only [replicaDensity,ENNReal.toReal_mul,ENNReal.toReal_pow,ENNReal.toReal_inv, + ENNReal.toReal_ofReal hJz.le, ENNReal.toReal_ofReal hJ'.le, + ENNReal.toReal_ofReal (gramVolume_pos hAz).le,comparisonEnvelope,projectionGramRatio,normalizedRatio] using h + +def comparisonCost (d ℓ k m J : ℕ) : ℝ := + Real.log (wishartMoment ℓ m k).toReal + (k:ℝ)*((m:ℝ)/2*Real.log ((ℓ:ℝ)+1)) + + (m:ℝ)*((k:ℝ)/2*Real.log ((d:ℝ)+1)) + (m:ℝ)*Real.log (binMeanBound k J) + +lemma comparisonEnvelope_integrable_mean {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] (J : ℕ) + (hcut : (L*ENNReal.ofReal ((72:ℝ)^d))*ENNReal.ofReal ((1/2:ℝ)^J)* + (1+(2:ℝ≥0∞)^(k+1)) ≤ 1) : + Integrable (@comparisonEnvelope d ℓ k m f J) ((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) ∧ + (∫ z, comparisonEnvelope f J z ∂(replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) ≤ + comparisonCost d ℓ k m J := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have := replicaLaw_probability hd hk hm .spherical hf hLt hfL + have hu := replicaLaw_ae_tuple_full_rank (k := k) (m := m) (by omega) (by omega) hf hLt hfL + have hG := projectionGramRatio_log_integrable (k := k) (by omega : m+1≤ℓ) (replicaLaw (k := k) (m := m) .spherical f) hu + have hA := replicaLaw_sensing_log_integrable (ℓ := ℓ) hd hk hm hf hLt hfL + obtain ⟨hR,hmR⟩ := normalizedRatio_integrable_mean hd hk hm hkm hf hLt hfL J hcut + have hterm : Integrable (fun z : EqualSpace d k m × AuxSpace d ℓ k => + Real.log (binMeanBound k J) + (normalizedRatio f z).toReal / binMeanBound k J - 1) + ((replicaLaw .spherical f).prod (auxLaw d ℓ k)) := ((integrable_const (Real.log (binMeanBound k J))).add (hR.div_const (binMeanBound k J))).sub (integrable_const (1:ℝ)) + have hbase : Integrable (fun z : EqualSpace d k m × AuxSpace d ℓ k => + Real.log (wishartMoment ℓ m k).toReal + (k:ℝ)*Real.log (projectionGramRatio z) + + (m:ℝ)*Real.log (gramVolume z.1.1)) ((replicaLaw .spherical f).prod (auxLaw d ℓ k)) := ((integrable_const (Real.log (wishartMoment ℓ m k).toReal)).add + (hG.const_mul (k:ℝ))).add (hA.const_mul (m:ℝ)) + have hbase2 : Integrable (fun z : EqualSpace d k m × AuxSpace d ℓ k => + Real.log (wishartMoment ℓ m k).toReal + (k:ℝ)*Real.log (projectionGramRatio z)) + ((replicaLaw .spherical f).prod (auxLaw d ℓ k)) := + (integrable_const _).add (hG.const_mul (k:ℝ)) + have hterm2 : Integrable (fun z : EqualSpace d k m × AuxSpace d ℓ k => + Real.log (binMeanBound k J) + (normalizedRatio f z).toReal / binMeanBound k J) + ((replicaLaw .spherical f).prod (auxLaw d ℓ k)) := + (integrable_const _).add (hR.div_const (binMeanBound k J)) + refine ⟨hbase.add (hterm.const_mul (m:ℝ)),?_⟩ + unfold comparisonEnvelope + rw [integral_add hbase (hterm.const_mul (m:ℝ)), integral_add hbase2 (hA.const_mul (m:ℝ)), + integral_add (integrable_const (Real.log (wishartMoment ℓ m k).toReal)) (hG.const_mul (k:ℝ)), + integral_const_mul, integral_const_mul, integral_const_mul, + integral_sub hterm2 (integrable_const (1:ℝ)), + integral_add (integrable_const (Real.log (binMeanBound k J))) (hR.div_const (binMeanBound k J)), + integral_div] + simp only [integral_const,probReal_univ,one_smul] + have hgm := projectionGramRatio_log_mean_le (k := k) (by omega : m+1≤ℓ) (replicaLaw (k := k) (m := m) .spherical f) hu + have ham := replicaLaw_sensing_log_mean_le (ℓ := ℓ) hd hk hm hf hLt hfL + have hrdiv : (∫ z, (normalizedRatio f z).toReal ∂(replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) / + binMeanBound k J ≤ 1 := (div_le_one (binMeanBound_pos k J)).mpr hmR + unfold comparisonCost + nlinarith [mul_le_mul_of_nonneg_left hgm (Nat.cast_nonneg (α:=ℝ) k), + mul_le_mul_of_nonneg_left ham (Nat.cast_nonneg (α:=ℝ) m), + mul_le_mul_of_nonneg_left hrdiv (Nat.cast_nonneg (α:=ℝ) m)] + +lemma replica_lifted_loss {d ℓ k m : ℕ} (hd : 4*k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] (J : ℕ) + (hcut : (L*ENNReal.ofReal ((72:ℝ)^d))*ENNReal.ofReal ((1/2:ℝ)^J)* + (1+(2:ℝ≥0∞)^(k+1)) ≤ 1) : + (klDiv (replicaLaw (k := k) (m := m) .spherical f) (equalReference ((sphereLaw d).withDensity f))).toReal ≤ + (klDiv (((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)).map observe) + (((equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)).map observe)).toReal + + comparisonCost d ℓ k m J := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have hd' : k+m+2 ≤ d := by omega + have := replicaLaw_probability hd' hk hm .spherical hf hLt hfL + have hh : klDiv ((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) + ((equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)) ≠ ∞ := by + rw [klDiv_prod_left] + exact replica_klDiv_ne_top hd hk hm hf hLt hfL + obtain ⟨he,heq⟩ := observableLog_normalized (ℓ := ℓ) hd' hk hm hkm hf hLt hfL + obtain ⟨hF,hFm⟩ := comparisonEnvelope_integrable_mean hd' hk hm hkm hf hLt hfL J hcut + have hh := entropy_loss_envelope _ _ hh measurable_observe (measurable_observableLog hf) + he heq.le hF (replica_log_comparison_ae hd' hk hm hkm hf hLt hfL J) + rw [klDiv_prod_left] at hh + exact hh.trans (add_le_add le_rfl hFm) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaMeasureInformation.lean b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaMeasureInformation.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3595232f516ed59b0ca7ce4cbfc411cf4f07670 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/ReplicaMeasureInformation.lean @@ -0,0 +1,37 @@ +import OAI.Probability.PosteriorReplicas.Information.RandomProjectionInformation + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma random_replica_measure_information {T W Y Z : Type*} + [MeasurableSpace T] [MeasurableSpace W] [MeasurableSpace Y] [MeasurableSpace Z] + [StandardBorelSpace W] [Nonempty W] [Fintype W] [MeasurableSingletonClass W] + [StandardBorelSpace Y] [Nonempty Y] [StandardBorelSpace Z] [Nonempty Z] + {n : ℕ} (β : Measure T) [IsProbabilityMeasure β] + (Q : Measure ((Fin n → Y) × W)) [IsProbabilityMeasure Q] + (q : Measure (Y × W)) [IsProbabilityMeasure q] + (hq : ∀ i, Q.map (fun z => (z.1 i,z.2)) = q) + {g : T × Y → Z} (hg : Measurable g) : + (n : ℝ≥0∞)*cmi (randomSideLaw β g q) + + (∫⁻ b, totalCorrelation (Q.fst.map (fun u i => g (b,u i))) ∂β) ≤ + totalCorrelation Q.fst + ENNReal.ofReal (finiteEntropy Q.snd) := by + let R := Q.map Prod.swap + have : IsProbabilityMeasure R := by dsimp [R]; infer_instance + have hl (i : Fin n) : coordinateJoint R.fst R.condKernel i = q := by + rw [coordinateJoint, coordKernel, Measure.compProd_map (measurable_pi_apply i), + Measure.disintegrate R R.condKernel] + change ((Q.map Prod.swap).map (fun z => (z.1,z.2 i))).map Prod.swap = q + rw [Measure.map_map (by fun_prop) (by fun_prop), Measure.map_map (by fun_prop) (by fun_prop)] + exact hq i + have h := random_replica_information_identical β R.fst R.condKernel hg q hl + rw [Measure.disintegrate R R.condKernel] at h + simpa only [R,Measure.fst_map_swap,Measure.snd_map_swap] using h + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/StateExperiment.lean b/lean/OAI/Probability/PosteriorReplicas/Information/StateExperiment.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3c76b39c39ddc0e8359c51ab63a711059a3bdc0 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/StateExperiment.lean @@ -0,0 +1,115 @@ +import OAI.Probability.PosteriorReplicas.Information.FiniteConditionalEntropy +import OAI.Probability.PosteriorReplicas.Information.HaarInformationEq + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +def initialStateKernel {d V : ℕ} (q : Measure (Vec d × Fin V)) [IsFiniteMeasure q] : + Kernel (Fin V) (Vec d) := (q.map Prod.swap).condKernel + +instance {d V : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] : + IsMarkovKernel (initialStateKernel q) := by unfold initialStateKernel; infer_instance + +lemma initialStateKernel_marginal {d V : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] : + (q.snd ⊗ₘ initialStateKernel q).snd = q.fst := by + have h : q.snd ⊗ₘ initialStateKernel q = q.map Prod.swap := by + rw [initialStateKernel,← Measure.fst_map_swap (ρ := q),Measure.disintegrate] + rw [h,Measure.snd_map_swap] + +lemma lintegral_initialStateKernel {d V : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + {g : Vec d × Fin V → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ z, g z ∂q = ∫⁻ v, ∫⁻ s, g (s,v) ∂initialStateKernel q v ∂q.snd := by + have h : q.snd ⊗ₘ initialStateKernel q = q.map Prod.swap := by + rw [initialStateKernel,← Measure.fst_map_swap (ρ := q),Measure.disintegrate] + calc + _ = ∫⁻ z, g z.swap ∂q.map Prod.swap := by + rw [lintegral_map (by fun_prop) measurable_swap] + rfl + _ = _ := by rw [← h,Measure.lintegral_compProd (by fun_prop)]; rfl + +def stateBlockKernel {d k V W : ℕ} (κ : Kernel (Fin V × Data d k) (Fin W)) (v : Fin V) : + Kernel (Data d k) (Fin W) := κ.comap (fun z => (v,z)) (by fun_prop) + +instance {d k V W : ℕ} (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] (v : Fin V) : + IsMarkovKernel (stateBlockKernel κ v) := by unfold stateBlockKernel; infer_instance + +def stateOutputKernel {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsFiniteMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) : Kernel (Fin V) (Vec d × Fin W) := + Kernel.ofFunOfCountable (fun v => signalMessageLaw (initialStateKernel q v) (stateBlockKernel κ v)) + +instance {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + IsMarkovKernel (stateOutputKernel q κ) where + isProbabilityMeasure v := inferInstanceAs + (IsProbabilityMeasure (signalMessageLaw (initialStateKernel q v) (stateBlockKernel κ v))) + +lemma stateOutputKernel_apply {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsFiniteMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) (v : Fin V) : + stateOutputKernel q κ v = signalMessageLaw (initialStateKernel q v) (stateBlockKernel κ v) := rfl + +lemma signalMessageLaw_lintegral {d k W : ℕ} (p : Measure (Vec d)) [IsProbabilityMeasure p] + (κ : Kernel (Data d k) (Fin W)) [IsMarkovKernel κ] + {g : Vec d × Fin W → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ z, g z ∂signalMessageLaw p κ = + ∫⁻ s, ∫⁻ A, ∫⁻ w, g (s,w) ∂κ (A,labels A s) ∂gaussianRows d k ∂p := by + have hm : Measurable (fun a : Vec d × Rows d k => + ∫⁻ w, g (a.1,w) ∂messageKernel κ a) := + (hg.comp (measurable_fst.fst.prodMk measurable_snd)).lintegral_kernel_prod_right' + rw [signalMessageLaw,lintegral_map hg (by fun_prop),Measure.lintegral_compProd (by fun_prop)] + exact lintegral_prod _ hm.aemeasurable + +lemma stateMessageLaw_lintegral {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] + {g : (Vec d × Fin V) × Fin W → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ z, g z ∂stateMessageLaw q κ = + ∫⁻ z, ∫⁻ A, ∫⁻ w, g (z,w) ∂κ (z.2,(A,labels A z.1)) ∂gaussianRows d k ∂q := by + have hm : Measurable (fun a : (Vec d × Fin V) × Rows d k => + ∫⁻ w, g (a.1,w) ∂stateMessageKernel κ a) := + (hg.comp (measurable_fst.fst.prodMk measurable_snd)).lintegral_kernel_prod_right' + rw [stateMessageLaw,lintegral_map hg (by fun_prop),Measure.lintegral_compProd (by fun_prop)] + exact lintegral_prod _ hm.aemeasurable + +lemma stateMessageLaw_eq_compProd {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + stateMessageLaw q κ = (q.snd ⊗ₘ stateOutputKernel q κ).map (fun z => ((z.2.1,z.1),z.2.2)) := by + apply Measure.ext_of_lintegral + intro g hg + rw [stateMessageLaw_lintegral q κ hg,lintegral_map hg (by fun_prop), + Measure.lintegral_compProd (by fun_prop),lintegral_initialStateKernel q (show Measurable (fun z : Vec d × Fin V => + ∫⁻ A, ∫⁻ w, g (z,w) ∂κ (z.2,(A,labels A z.1)) ∂gaussianRows d k) from + ((hg.comp (measurable_fst.fst.prodMk measurable_snd)).lintegral_kernel_prod_right' (κ := stateMessageKernel κ)).lintegral_prod_right)] + apply lintegral_congr + intro v + rw [stateOutputKernel_apply,signalMessageLaw_lintegral _ _ (by fun_prop)] + rfl + +lemma stateMessageLaw_state_terminal {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + (stateMessageLaw q κ).map (fun z => (z.1.2,z.2)) = q.snd ⊗ₘ (stateOutputKernel q κ).snd := by + rw [stateMessageLaw_eq_compProd,Measure.map_map (by fun_prop) (by fun_prop), + Kernel.snd_eq,Measure.compProd_map measurable_snd] + rfl + +lemma stateMessageLaw_initial {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + (stateMessageLaw q κ).map (fun z => z.1.2) = q.snd := by + rw [stateMessageLaw_eq_compProd,Measure.map_map (by fun_prop) (by fun_prop)] + change (q.snd ⊗ₘ stateOutputKernel q κ).fst = q.snd + exact Measure.fst_compProd _ _ + +lemma terminalConditionalEntropy_average {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + terminalConditionalEntropy (stateMessageLaw q κ) = + ∑ v, q.snd.real {v} * finiteEntropy (stateOutputKernel q κ v).snd := by + rw [terminalConditionalEntropy,stateMessageLaw_state_terminal,stateMessageLaw_initial, + finiteEntropy_compProd_conditional] + simp only [Kernel.snd_apply,Measure.snd] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Information/StateSide.lean b/lean/OAI/Probability/PosteriorReplicas/Information/StateSide.lean new file mode 100644 index 0000000000000000000000000000000000000000..f268cce36a00e5feb2c1a3d636cb0bb16090cbef --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Information/StateSide.lean @@ -0,0 +1,80 @@ +import OAI.Probability.PosteriorReplicas.Information.StateExperiment + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +def stateSideKernel {d k V W : ℕ} (ℓ : ℕ) + (q : Measure (Vec d × Fin V)) [IsFiniteMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) : + Kernel (Fin V) (Data d ℓ × (Vec d × Fin W)) := + Kernel.ofFunOfCountable (fun v => randomSideLaw (haarRows d ℓ) + (fun z => labels z.1 z.2) (stateOutputKernel q κ v)) + +instance {d k V W : ℕ} (ℓ : ℕ) + (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + IsMarkovKernel (stateSideKernel ℓ q κ) where + isProbabilityMeasure v := by + change IsProbabilityMeasure ((haarRows d ℓ).prod (stateOutputKernel q κ v) |>.map + (fun z => ((z.1,labels z.1 z.2.1),z.2))) + infer_instance + +lemma stateSideKernel_apply {d k V W : ℕ} (ℓ : ℕ) + (q : Measure (Vec d × Fin V)) [IsFiniteMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) (v : Fin V) : + stateSideKernel ℓ q κ v = randomSideLaw (haarRows d ℓ) + (fun z => labels z.1 z.2) (stateOutputKernel q κ v) := rfl + +lemma stateHaarSideLaw_eq_compProd {d ℓ k V W : ℕ} + (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + stateHaarSideLaw ℓ (stateMessageLaw q κ) = + (q.snd ⊗ₘ stateSideKernel ℓ q κ).map + (MeasurableEquiv.prodAssoc.symm : + Fin V × (Data d ℓ × (Vec d × Fin W)) ≃ᵐ + (Fin V × Data d ℓ) × (Vec d × Fin W)) := by + apply Measure.ext_of_lintegral + intro g hg + let F : Rows d ℓ × Fin V → ℝ≥0∞ := fun z => + ∫⁻ sw, g ((z.2,(z.1,labels z.1 sw.1)),sw) ∂stateOutputKernel q κ z.2 + have hF : Measurable F := by + exact (show Measurable (fun z : (Rows d ℓ × Fin V) × (Vec d × Fin W) => + g ((z.1.2,(z.1.1,labels z.1.1 z.2.1)),z.2)) by unfold labels; fun_prop).lintegral_kernel_prod_right' + (κ := (stateOutputKernel q κ).comap Prod.snd measurable_snd) + rw [stateHaarSideLaw,lintegral_map hg (by unfold labels; fun_prop), + lintegral_prod _ (by unfold labels; fun_prop), + lintegral_map hg (by fun_prop),Measure.lintegral_compProd (by fun_prop)] + calc + _ = ∫⁻ B, ∫⁻ v, F (B,v) ∂q.snd ∂haarRows d ℓ := by + apply lintegral_congr + intro B + rw [stateMessageLaw_eq_compProd,lintegral_map (by unfold labels; fun_prop) (by fun_prop), + Measure.lintegral_compProd (by unfold labels; fun_prop)] + _ = ∫⁻ v, ∫⁻ B, F (B,v) ∂haarRows d ℓ ∂q.snd := + lintegral_lintegral_swap hF.aemeasurable + _ = _ := by + apply lintegral_congr + intro v + rw [stateSideKernel_apply,randomSideLaw,lintegral_map (by fun_prop) (by unfold labels; fun_prop), + lintegral_prod _ (by unfold labels; fun_prop)] + rfl + +lemma stateHaarInformation_average {d ℓ k V W : ℕ} [NeZero W] + (hℓ : ℓ ≤ d) (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + cmi (stateHaarSideLaw ℓ (stateMessageLaw q κ)) = + ∑ v, q.snd {v} * conditionalInformation (sideLaw ℓ (stateOutputKernel q κ v)) := by + simp only [stateHaarSideLaw_eq_compProd] + rw [cmi_compProd_assoc,lintegral_fintype] + apply Finset.sum_congr rfl + intro v _ + simp only [stateSideKernel_apply,cmi_haar_eq_gaussian hℓ,mul_comm] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Kernels/DensityRatio.lean b/lean/OAI/Probability/PosteriorReplicas/Kernels/DensityRatio.lean new file mode 100644 index 0000000000000000000000000000000000000000..90805e742f66715c9d3e52f46c41d0a9b3cc6714 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Kernels/DensityRatio.lean @@ -0,0 +1,106 @@ +import OAI.Probability.PosteriorReplicas.Geometry.DensityBinEnvelope +import OAI.Probability.PosteriorReplicas.Information.ObservableLikelihood +import OAI.Probability.PosteriorReplicas.Kernels.PosteriorKernel + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +def normalizedRatio {d ℓ k m : ℕ} (f : Vec d → ℝ≥0∞) + (z : EqualSpace d k m × AuxSpace d ℓ k) : ℝ≥0∞ := + (projectedDensity .spherical f (observableRows z.1.2.2 z.2) + (labels (observableRows z.1.2.2 z.2) (z.1.2.2 0))) * + (projectedDensity .spherical f z.1.1 z.1.2.1)⁻¹ * (ENNReal.ofReal (gramVolume z.1.1))⁻¹ + +@[fun_prop] lemma measurable_normalizedRatio {d ℓ k m : ℕ} {f : Vec d → ℝ≥0∞} (hf : Measurable f) : + Measurable (@normalizedRatio d ℓ k m f) := by unfold normalizedRatio labels; fun_prop + +lemma replicaLaw_ae_of_reference {d k m : ℕ} (base : BaseLaw) (f : Vec d → ℝ≥0∞) + {P : EqualSpace d k m → Prop} (h : ∀ᵐ z ∂equalReference ((base.measure d).withDensity f), P z) : + ∀ᵐ z ∂replicaLaw base f, P z := + (withDensity_absolutelyContinuous _ _).ae_le h + +lemma replicaLaw_ae_tuple_full_rank {d k m : ℕ} (hd : 3 ≤ d) (hm : m < d) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + ∀ᵐ z : EqualSpace d k m ∂replicaLaw .spherical f, LinearIndependent ℝ (differences z.2.2) := by + apply replicaLaw_ae_of_reference + have h : ∀ᵐ u : Tuple d m ∂(equalReference (k := k) ((sphereLaw d).withDensity f)).map (fun z => z.2.2), + LinearIndependent ℝ (differences u) := by + rw [equalReference_tuple] + exact ae_tilt_tuple_full_rank hd hm .spherical hf hLt hfL + exact (ae_map_iff (show Measurable (fun z : EqualSpace d k m => z.2.2) by fun_prop).aemeasurable + (show MeasurableSet {u : Tuple d m | LinearIndependent ℝ (differences u)} from + isOpen_setOfPred_linearIndependent.measurableSet.preimage (show Measurable (@differences d m) by fun_prop))).mp h + +lemma replicaLaw_data_lintegral {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {H : Data d k → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ z : EqualSpace d k m, H (z.1,z.2.1) ∂replicaLaw base f) = + ∫⁻ A, ∫⁻ y, H (A,y) ∂volume.withDensity (projectedDensity base f A) ∂gaussianRows d k := by + have (A : Rows d k) (y : Labels k) := tiltedFiber_probability base hLt hfL A y + rw [replicaLaw_lintegral hd hk hm base hf hLt hfL (by fun_prop)] + simp only [lintegral_const,measure_univ,mul_one] + apply lintegral_congr + intro A + rw [lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] + rfl + +lemma normalizedRatio_lintegral_le {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] (J : ℕ) + (hcut : (L*ENNReal.ofReal ((72:ℝ)^d))*ENNReal.ofReal ((1/2:ℝ)^J)* + (1+(2:ℝ≥0∞)^(k+1)) ≤ 1) : + (∫⁻ z, normalizedRatio f z ∂(replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) ≤ + volume {y : Labels k | labelNorm y ≤ 1} * (2+(J:ℝ≥0∞)*2^k) := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have := replicaLaw_probability hd hk hm .spherical hf hLt hfL + rw [lintegral_prod _ (by fun_prop)] + calc + _ ≤ ∫⁻ z : EqualSpace d k m, + (projectedDensity .spherical f z.1 z.2.1)⁻¹ * + binEnvelope ((sphereLaw d).withDensity f) J z.1 z.2.1 * + (ENNReal.ofReal (gramVolume z.1))⁻¹ ∂replicaLaw .spherical f := by + apply lintegral_mono_ae + filter_upwards [replicaLaw_ae_of_reference .spherical f + (ae_equalReference_bin_bound hd hk hm hf hLt hfL J hcut),replicaLaw_ae_tuple_full_rank (k := k) (by omega) (by omega) hf hLt hfL] with z hz hu + unfold normalizedRatio + dsimp only + rw [lintegral_mul_const _ (by fun_prop),lintegral_mul_const _ (by unfold labels; fun_prop), + observableDensity_expected hu hkm hf] + change expectedDensity f z.2.2 * _ * _ ≤ _ + exact mul_le_mul' (by simpa only [mul_comm] using mul_le_mul' hz (le_refl (projectedDensity .spherical f z.1 z.2.1)⁻¹)) le_rfl + _ = ∫⁻ A, (∫⁻ y, (projectedDensity .spherical f A y)⁻¹ * + binEnvelope ((sphereLaw d).withDensity f) J A y + ∂volume.withDensity (projectedDensity .spherical f A)) * + (ENNReal.ofReal (gramVolume A))⁻¹ ∂gaussianRows d k := by + rw [replicaLaw_data_lintegral hd hk hm .spherical hf hLt hfL + (H := fun z => (projectedDensity .spherical f z.1 z.2)⁻¹ * + binEnvelope ((sphereLaw d).withDensity f) J z.1 z.2 * (ENNReal.ofReal (gramVolume z.1))⁻¹) (by fun_prop)] + apply lintegral_congr + intro A + exact lintegral_mul_const (μ := volume.withDensity (projectedDensity .spherical f A)) + (ENNReal.ofReal (gramVolume A))⁻¹ (show Measurable (fun y : Labels k => (projectedDensity .spherical f A y)⁻¹ * + binEnvelope ((sphereLaw d).withDensity f) J A y) by fun_prop) + _ ≤ ∫⁻ _A : Rows d k, volume {y : Labels k | labelNorm y ≤ 1} * (2+(J:ℝ≥0∞)*2^k) + ∂gaussianRows d k := by + apply lintegral_mono_ae + filter_upwards [ae_gaussian_rows_full_rank (by omega : 3 ≤ d) (by omega : k < d)] with A hA + apply (mul_le_mul' (normalized_binEnvelope_integral_le hf hLt hfL hA J) le_rfl).trans_eq + have hp := ENNReal.ofReal_pos.mpr (gramVolume_pos hA) + calc + _ = (ENNReal.ofReal (gramVolume A) * (ENNReal.ofReal (gramVolume A))⁻¹) * + (volume {y : Labels k | labelNorm y ≤ 1} * (2+(J:ℝ≥0∞)*2^k)) := by ring + _ = _ := by rw [ENNReal.mul_inv_cancel hp.ne' ENNReal.ofReal_ne_top,one_mul] + _ = _ := by simp + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Kernels/KernelPi.lean b/lean/OAI/Probability/PosteriorReplicas/Kernels/KernelPi.lean new file mode 100644 index 0000000000000000000000000000000000000000..67c52cac9c2f96c3f57cd3bd8291b418cd99d582 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Kernels/KernelPi.lean @@ -0,0 +1,59 @@ +import Mathlib + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +@[fun_prop] lemma measurable_fin_cons {Y : Type*} [MeasurableSpace Y] {n : ℕ} : + Measurable (fun z : Y × (Fin n → Y) => (Fin.cons z.1 z.2 : Fin (n+1) → Y)) := by + apply measurable_pi_iff.mpr + intro i + refine Fin.cases ?_ (fun j => ?_) i + · simpa only [Fin.cons_zero] using (measurable_fst : Measurable (Prod.fst : Y × (Fin n → Y) → Y)) + · simpa only [Fin.cons_succ, Function.comp_def] using (measurable_pi_apply j).comp measurable_snd + +def piKernel {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] : + {n : ℕ} → (Fin n → Kernel X Y) → Kernel X (Fin n → Y) + | 0, _ => Kernel.deterministic (fun _ i => Fin.elim0 i) (by fun_prop) + | n+1, κ => ((κ 0) ×ₖ piKernel (fun i : Fin n => κ i.succ)).map + (fun z => Fin.cons z.1 z.2) + +instance piKernel_markov {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + {n : ℕ} (κ : Fin n → Kernel X Y) [∀ i, IsMarkovKernel (κ i)] : + IsMarkovKernel (piKernel κ) := by + induction n with + | zero => unfold piKernel; infer_instance + | succ n ih => + have : IsMarkovKernel (piKernel (fun i : Fin n => κ i.succ)) := ih _ + unfold piKernel + exact Kernel.IsMarkovKernel.map _ (by fun_prop) + +lemma piKernel_apply {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + {n : ℕ} (κ : Fin n → Kernel X Y) [∀ i, IsMarkovKernel (κ i)] (x : X) : + piKernel κ x = Measure.pi (fun i => κ i x) := by + induction n with + | zero => + rw [piKernel, Kernel.deterministic_apply, Measure.pi_of_empty _ (fun i => Fin.elim0 i)] + | succ n ih => + have hκ : ∀ i : Fin n, IsMarkovKernel (κ i.succ) := inferInstance + rw [piKernel, Kernel.map_apply _ (by fun_prop), Kernel.prod_apply, ih] + let e := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => Y) 0).symm + have he : (fun z : Y × (Fin n → Y) => Fin.cons z.1 z.2) = e := by + funext z + simp only [e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv, + Fin.insertNth_zero, Fin.zero_succAbove, Equiv.coe_fn_mk, cast_eq] + rw [he] + exact (measurePreserving_piFinSuccAbove (fun i : Fin (n+1) => κ i x) 0).symm.map_eq + +@[fun_prop] lemma measurable_piKernel {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + {n : ℕ} (κ : Fin n → Kernel X Y) [∀ i, IsMarkovKernel (κ i)] : + Measurable (fun x => Measure.pi (fun i => κ i x)) := by + simpa only [← piKernel_apply] using (piKernel κ).measurable + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Kernels/LiftedReplica.lean b/lean/OAI/Probability/PosteriorReplicas/Kernels/LiftedReplica.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6fa0459ac4584ed5001aac5fa585efeb7e018b3 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Kernels/LiftedReplica.lean @@ -0,0 +1,85 @@ +import OAI.Probability.PosteriorReplicas.Information.KLTools +import OAI.Probability.PosteriorReplicas.Information.NormalizedLikelihood +import OAI.Probability.PosteriorReplicas.Kernels.ReplicaGaussianMarginals + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma liftedReplica_absolutelyContinuous {d ℓ k m : ℕ} (f : Vec d → ℝ≥0∞) : + ((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) ≪ + ((equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)) := + (withDensity_absolutelyContinuous _ _).prod (Measure.AbsolutelyContinuous.refl _) + +lemma liftedReplica_llr {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + ∀ᵐ z ∂(replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k), + llr ((replicaLaw .spherical f).prod (auxLaw d ℓ k)) + ((equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)) z = + Real.log (replicaDensity .spherical f z.1).toReal := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have := replicaLaw_probability hd hk hm .spherical hf hLt hfL + have he : ((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)) = + ((equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)).withDensity + (fun z => replicaDensity .spherical f z.1) := prod_withDensity_left (measurable_replicaDensity .spherical hf) + have : IsFiniteMeasure (((equalReference ((sphereLaw d).withDensity f)).prod (auxLaw d ℓ k)).withDensity + (fun z : EqualSpace d k m × AuxSpace d ℓ k => replicaDensity .spherical f z.1)) := by + rw [← he]; infer_instance + rw [he] + exact llr_withDensity_ae _ (by fun_prop) + +lemma replicaLaw_ae_sensing_full_rank {d k m : ℕ} (hd : k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + ∀ᵐ z : EqualSpace d k m ∂replicaLaw .spherical f, LinearIndependent ℝ z.1 := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have h := ae_gaussian_rows_full_rank (by omega : 3 ≤ d) (by omega : k < d) + rw [← replicaLaw_sensing_law hd hk hm .spherical hf hLt hfL] at h + exact (ae_map_iff measurable_fst.aemeasurable isOpen_setOfPred_linearIndependent.measurableSet).mp h + +lemma liftedReplica_ae_observable_density_pos {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (hkm : k+m ≤ ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + ∀ᵐ z ∂(replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k), + 0 < projectedDensity .spherical f (observableRows z.1.2.2 z.2) + (labels (observableRows z.1.2.2 z.2) (z.1.2.2 0)) := by + apply (liftedReplica_absolutelyContinuous f).ae_le + apply (Measure.ae_prod_iff_ae_ae (measurableSet_lt measurable_const (by unfold labels; fun_prop))).mpr + have h : ∀ᵐ u : Tuple d m ∂(equalReference (k := k) ((sphereLaw d).withDensity f)).map (fun z => z.2.2), + ∀ᵐ b ∂auxLaw d ℓ k, 0 < projectedDensity .spherical f (observableRows u b) (labels (observableRows u b) (u 0)) := by + rw [equalReference_tuple] + filter_upwards [ae_constrained_support hd hk hm .spherical hf hLt hfL] with u hu + have hh : ∀ᵐ A ∂(auxLaw d ℓ k).map (observableRows u), + 0 < projectedDensity .spherical f A (labels A (u 0)) := by + rw [observableRows_law hu.1 hkm] + filter_upwards [hu.2] with A hA + exact hA.2.2.2.1 + exact (ae_map_iff (show Measurable (observableRows u) by fun_prop).aemeasurable + (measurableSet_lt measurable_const (by unfold labels; fun_prop))).mp hh + exact ae_of_ae_map (show Measurable (fun z : EqualSpace d k m => z.2.2) by fun_prop).aemeasurable h + +lemma liftedReplica_ae_projectionGram_pos {d ℓ k m : ℕ} (hd : 3 ≤ d) (hm : m < d) (hml : m < ℓ) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + ∀ᵐ z ∂(replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k), + 0 < gramVolume (pairingColumns (differences z.1.2.2) z.2.1) := by + apply (Measure.ae_prod_iff_ae_ae (measurableSet_lt measurable_const (by fun_prop))).mpr + filter_upwards [replicaLaw_ae_tuple_full_rank hd hm hf hLt hfL] with z hz + have hr : ∀ᵐ B ∂gaussianRows d ℓ, 0 < gramVolume (pairingColumns (differences z.2.2) B) := by + have h := ae_pairingColumns_independent hz hml.le + filter_upwards [h] with B hB + exact gramVolume_pos hB + exact Measure.quasiMeasurePreserving_fst.ae hr + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Kernels/PosteriorExperiment.lean b/lean/OAI/Probability/PosteriorReplicas/Kernels/PosteriorExperiment.lean new file mode 100644 index 0000000000000000000000000000000000000000..f4a684cc861fdf040091032b5c68178a07c3cb7d --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Kernels/PosteriorExperiment.lean @@ -0,0 +1,130 @@ +import OAI.Probability.PosteriorReplicas.Information.ReplicaMeasureInformation +import OAI.Probability.PosteriorReplicas.Kernels.PosteriorKernel + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma replicaLaw_eq_dataKernel {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + replicaLaw (k := k) (m := m) base f = + (dataLaw (k := k) ((base.measure d).withDensity f) ⊗ₘ + piKernel (fun _ : Fin (m+1) => posteriorKernel base hf)).map + (fun z => (z.1.1,z.1.2,z.2)) := by + let : NeZero d := ⟨by omega⟩ + let := bounded_withDensity_finite (base.measure d) hLt hfL + let := posteriorKernel_markov (k := k) base hf hLt hfL + let : IsFiniteMeasure (dataLaw (k := k) ((base.measure d).withDensity f)) := by + unfold dataLaw + infer_instance + apply Measure.ext_of_lintegral + intro H hH + rw [replicaLaw_lintegral hd hk hm base hf hLt hfL hH, + lintegral_map hH (by fun_prop), Measure.lintegral_compProd (by fun_prop), + dataLaw_density (by omega) (by omega) base hf hLt hfL, + lintegral_withDensity_eq_lintegral_mul _ (measurable_projectedDensity base hf) (by fun_prop), + lintegral_prod _ (by fun_prop)] + simp only [Pi.mul_apply] + simp_rw [piKernel_apply] + rfl + +lemma dataSignal_lintegral {d k : ℕ} (hd : 3 ≤ d) (hk : k < d) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {H : Data d k × Vec d → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ z, ∫⁻ x, H (z,x) ∂posteriorKernel base hf z + ∂dataLaw (k := k) ((base.measure d).withDensity f)) = + ∫⁻ A, ∫⁻ x, H ((A,labels A x),x) ∂(base.measure d).withDensity f ∂gaussianRows d k := by + let : NeZero d := ⟨by omega⟩ + let := bounded_withDensity_finite (base.measure d) hLt hfL + let := posteriorKernel_markov (k := k) base hf hLt hfL + rw [dataLaw_density hd hk base hf hLt hfL, + lintegral_withDensity_eq_lintegral_mul _ (measurable_projectedDensity base hf) (by fun_prop), + lintegral_prod _ (by fun_prop)] + apply lintegral_congr_ae + filter_upwards [ae_gaussian_rows_full_rank hd hk] with A hA + exact (posterior_disintegration_lintegral hA hk base hf hLt hfL + (H := fun z => H ((A,z.1),z.2)) (by fun_prop)).symm + +def posteriorMessageLaw {d k m N : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + (κ : Kernel (Data d k) (Fin N)) : Measure (Tuple d m × Fin N) := + (dataLaw (k := k) ((base.measure d).withDensity f) ⊗ₘ + (piKernel (fun _ : Fin (m+1) => posteriorKernel base hf) ×ₖ κ)).snd + +lemma posteriorMessageLaw_probability {d k m N : ℕ} (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((base.measure d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + IsProbabilityMeasure (posteriorMessageLaw (m := m) base hf κ) := by + let := posteriorKernel_markov (k := k) base hf hLt hfL + unfold posteriorMessageLaw + infer_instance + +lemma posteriorMessageLaw_coordinate {d k m N : ℕ} (hd : 3 ≤ d) (hk : k < d) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((base.measure d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] (i : Fin (m+1)) : + (posteriorMessageLaw (m := m) base hf κ).map (fun z => (z.1 i,z.2)) = + signalMessageLaw ((base.measure d).withDensity f) κ := by + let := posteriorKernel_markov (k := k) base hf hLt hfL + have (z : Data d k) := tiltedFiber_probability base hLt hfL z.1 z.2 + apply Measure.ext_of_lintegral + intro H hH + rw [posteriorMessageLaw, Measure.snd, Measure.map_map (by fun_prop) measurable_snd, + lintegral_map hH (by fun_prop), Measure.lintegral_compProd (by fun_prop)] + simp only [Kernel.prod_apply, piKernel_apply] + have hp (z : Data d k) : + (∫⁻ uw, H (uw.1 i,uw.2) ∂(Measure.pi (fun _ : Fin (m+1) => posteriorKernel base hf z)).prod (κ z)) = + ∫⁻ x, ∫⁻ w, H (x,w) ∂κ z ∂posteriorKernel base hf z := by + rw [lintegral_prod _ (by fun_prop)] + exact (measurePreserving_eval (fun _ : Fin (m+1) => posteriorKernel base hf z) i).lintegral_comp + (show Measurable (fun x : Vec d => ∫⁻ w, H (x,w) ∂κ z) by fun_prop) + change (∫⁻ z, ∫⁻ uw, H (uw.1 i,uw.2) + ∂(Measure.pi (fun _ : Fin (m+1) => posteriorKernel base hf z)).prod (κ z) + ∂dataLaw ((base.measure d).withDensity f)) = _ + simp_rw [hp] + have hK : Measurable (fun z : Data d k × Vec d => ∫⁻ w, H (z.2,w) ∂κ z.1) := by + exact (hH.comp (show Measurable (fun z : (Data d k × Vec d) × Fin N => (z.1.2,z.2)) by fun_prop)).lintegral_kernel_prod_right' + (κ := κ.comap Prod.fst measurable_fst) + rw [dataSignal_lintegral hd hk base hf hLt hfL hK] + rw [signalMessageLaw, lintegral_map hH (by fun_prop), Measure.lintegral_compProd (by fun_prop)] + have hK' : Measurable (fun a : Vec d × Rows d k => ∫⁻ w, H (a.1,w) ∂messageKernel κ a) := by + exact (hH.comp (show Measurable (fun z : (Vec d × Rows d k) × Fin N => (z.1.1,z.2)) by fun_prop)).lintegral_kernel_prod_right' + (κ := messageKernel κ) + rw [lintegral_prod _ (show AEMeasurable (fun a : Vec d × Rows d k => + ∫⁻ w, H (a.1,w) ∂messageKernel κ a) _ from hK'.aemeasurable)] + simp only [messageKernel, Kernel.comap_apply] + exact lintegral_lintegral_swap + ((hK.comp (show Measurable (fun z : Rows d k × Vec d => ((z.1,labels z.1 z.2),z.2)) by + unfold labels; fun_prop)).aemeasurable) + +lemma posteriorMessageLaw_tuple {d k m N : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((base.measure d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + (posteriorMessageLaw (m := m) base hf κ).fst = (replicaLaw (k := k) (m := m) base f).map (fun z => z.2.2) := by + let := posteriorKernel_markov (k := k) base hf hLt hfL + let := posteriorMessageLaw_probability (m := m) base hf hLt hfL κ + rw [replicaLaw_eq_dataKernel hd hk hm base hf hLt hfL, + Measure.map_map (by fun_prop) (by fun_prop)] + apply Measure.ext_of_lintegral + intro H hH + rw [posteriorMessageLaw, Measure.fst, Measure.snd, + Measure.map_map measurable_fst measurable_snd, + lintegral_map hH (by fun_prop), lintegral_map hH (by fun_prop), + Measure.lintegral_compProd (by fun_prop), Measure.lintegral_compProd (by fun_prop)] + apply lintegral_congr + intro z + rw [Kernel.prod_apply, lintegral_prod _ (by fun_prop)] + simp + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Kernels/PosteriorKernel.lean b/lean/OAI/Probability/PosteriorReplicas/Kernels/PosteriorKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..aca7337dbd2ff722e957aab99166e2fefc0ecfe3 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Kernels/PosteriorKernel.lean @@ -0,0 +1,96 @@ +import OAI.Probability.PosteriorReplicas.Kernels.KernelPi +import OAI.Probability.PosteriorReplicas.Kernels.ReplicaMeasure + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +@[fun_prop] lemma measurable_tiltedFiber {d k : ℕ} (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) : + Measurable (fun z : Data d k => tiltedFiber base f z.1 z.2) := by + apply Measure.measurable_of_measurable_coe + intro s hs + have ht := measurable_tiltMass (d := d) (k := k) base hf + have hm : Measurable (fun z : Data d k => (baseFiber base z.1 z.2).withDensity f s) := by + simp only [withDensity_apply _ hs] + simpa only [lintegral_indicator hs, baseKernel, Kernel.coe_mk] using + (hf.indicator hs).lintegral_kernel (κ := baseKernel base) + have he : (fun z : Data d k => tiltedFiber base f z.1 z.2 s) = + fun z => if tiltMass base f z.1 z.2 = 0 then (Measure.dirac (0 : Vec d)) s + else (tiltMass base f z.1 z.2)⁻¹ * (baseFiber base z.1 z.2).withDensity f s := by + funext z + unfold tiltedFiber + split_ifs <;> simp [Measure.smul_apply] + rw [he] + exact Measurable.ite (measurableSet_eq_fun ht measurable_const) measurable_const (ht.inv.mul hm) + +def posteriorKernel {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) : + Kernel (Data d k) (Vec d) where + toFun z := tiltedFiber base f z.1 z.2 + measurable' := measurable_tiltedFiber base hf + +lemma posteriorKernel_markov {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + IsMarkovKernel (@posteriorKernel d k base f hf) := + ⟨fun z => tiltedFiber_probability base hLt hfL z.1 z.2⟩ + +def dataLaw {d k : ℕ} (ν : Measure (Vec d)) : Measure (Data d k) := + ((gaussianRows d k).prod ν).map (fun z => (z.1,labels z.1 z.2)) + +instance {d k : ℕ} (ν : Measure (Vec d)) [IsProbabilityMeasure ν] : + IsProbabilityMeasure (dataLaw (k := k) ν) := by + unfold dataLaw + infer_instance + +lemma posterior_disintegration_lintegral {d k : ℕ} {A : Rows d k} + (hA : LinearIndependent ℝ A) (hk : k < d) (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) + (hfL : ∀ x, f x ≤ L) {H : Labels k × Vec d → ℝ≥0∞} (hH : Measurable H) : + (∫⁻ x, H (labels A x,x) ∂(base.measure d).withDensity f) = + ∫⁻ y, projectedDensity base f A y * + ∫⁻ x, H (y,x) ∂tiltedFiber base f A y := by + rw [weighted_base_lintegral hA hk base hf (show Measurable (fun x => H (labels A x,x)) by + unfold labels; fun_prop)] + apply lintegral_congr + intro y + by_cases hb : baseDensity base A y = 0 + · simp [projectedDensity,hb] + have he : (∫⁻ x, f x * H (labels A x,x) ∂baseFiber base A y) = + ∫⁻ x, H (y,x) ∂(baseFiber base A y).withDensity f := by + rw [lintegral_withDensity_eq_lintegral_mul _ hf (show Measurable (fun x => H (y,x)) by fun_prop)] + simp only [Pi.mul_apply] + rw [baseFiber_eq_map, + lintegral_map (show Measurable (fun x => f x * H (labels A x,x)) by unfold labels; fun_prop) + (measurable_basePoint_fixed base A y), + lintegral_map (show Measurable (fun x => f x * H (y,x)) by fun_prop) + (measurable_basePoint_fixed base A y)] + simp only [labels_basePoint hA] + rw [he, ← tiltMass_smul_tiltedFiber base hf hLt hfL A y, lintegral_smul_measure] + simp only [projectedDensity, smul_eq_mul, mul_assoc] + +lemma dataLaw_density {d k : ℕ} (hd : 3 ≤ d) (hk : k < d) (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) + (hfL : ∀ x, f x ≤ L) : + dataLaw (k := k) ((base.measure d).withDensity f) = + ((gaussianRows d k).prod volume).withDensity (fun z => projectedDensity base f z.1 z.2) := by + let : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + apply Measure.ext_of_lintegral + intro H hH + rw [dataLaw, lintegral_map hH (by unfold labels; fun_prop), lintegral_prod _ (by unfold labels; fun_prop), + lintegral_withDensity_eq_lintegral_mul _ (measurable_projectedDensity base hf) hH, + lintegral_prod _ (by fun_prop)] + apply lintegral_congr_ae + filter_upwards [ae_gaussian_rows_full_rank hd hk] with A hA + have h := posterior_disintegration_lintegral hA hk base hf hLt hfL + (H := fun z : Labels k × Vec d => H (A,z.1)) (by fun_prop) + have (y : Labels k) := tiltedFiber_probability base hLt hfL A y + simpa using h + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaGaussianMarginals.lean b/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaGaussianMarginals.lean new file mode 100644 index 0000000000000000000000000000000000000000..1dbdf607b544f7236b154477c249d2c5548ba819 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaGaussianMarginals.lean @@ -0,0 +1,116 @@ +import OAI.Probability.PosteriorReplicas.Kernels.DensityRatio + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +def projectionGramRatio {d ℓ k m : ℕ} (z : EqualSpace d k m × AuxSpace d ℓ k) : ℝ := + gramVolume (pairingColumns (differences z.1.2.2) z.2.1) / affineVolume z.1.2.2 + +@[fun_prop] lemma measurable_projectionGramRatio {d ℓ k m : ℕ} : + Measurable (@projectionGramRatio d ℓ k m) := by unfold projectionGramRatio; fun_prop + +lemma projectionGramRatio_law {d ℓ k m : ℕ} + (μ : Measure (EqualSpace d k m)) [IsProbabilityMeasure μ] + (hμ : ∀ᵐ z ∂μ, LinearIndependent ℝ (differences z.2.2)) : + (μ.prod (auxLaw d ℓ k)).map projectionGramRatio = (gaussianRows ℓ m).map gramVolume := by + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (by fun_prop),lintegral_map hf (by fun_prop),lintegral_prod _ (by fun_prop)] + calc + _ = ∫⁻ z, ∫⁻ G, f (gramVolume G) ∂gaussianRows ℓ m ∂μ := by + apply lintegral_congr_ae + filter_upwards [hμ] with z hz + unfold projectionGramRatio + rw [auxLaw,lintegral_prod _ (by fun_prop)] + simp only [lintegral_const,measure_univ,mul_one] + have he (B : Rows d ℓ) : gramVolume (pairingColumns (differences z.2.2) B) / affineVolume z.2.2 = + gramVolume (pairingColumns (gramSchmidtNormed ℝ (differences z.2.2)) B) := by + rw [gramVolume_pairingColumns hz] + change gramVolume (differences z.2.2) * _ / gramVolume (differences z.2.2) = _ + field_simp [(gramVolume_pos hz).ne'] + simp_rw [he] + have h := congrArg (fun ν : Measure (Rows ℓ m) => ∫⁻ G, f (gramVolume G) ∂ν) + (orthonormal_pairingColumns_law (ℓ := ℓ) (gramSchmidtNormed_orthonormal hz)) + rw [lintegral_map (by fun_prop) (by fun_prop)] at h + exact h + _ = _ := by simp + +lemma projectionGramRatio_log_integrable {d ℓ k m : ℕ} (hml : m+1 ≤ ℓ) + (μ : Measure (EqualSpace d k m)) [IsProbabilityMeasure μ] + (hμ : ∀ᵐ z ∂μ, LinearIndependent ℝ (differences z.2.2)) : + Integrable (fun z => Real.log (projectionGramRatio z)) (μ.prod (auxLaw d ℓ k)) := by + have h : Integrable Real.log ((μ.prod (auxLaw d ℓ k)).map projectionGramRatio) := by + rw [projectionGramRatio_law μ hμ] + apply (integrable_map_measure (by fun_prop) (by fun_prop)).mpr + exact gaussian_integrable_log_gramVolume (by simpa using hml) + exact h.comp_measurable (by fun_prop) + +lemma projectionGramRatio_log_mean_le {d ℓ k m : ℕ} (hml : m+1 ≤ ℓ) + (μ : Measure (EqualSpace d k m)) [IsProbabilityMeasure μ] + (hμ : ∀ᵐ z ∂μ, LinearIndependent ℝ (differences z.2.2)) : + (∫ z, Real.log (projectionGramRatio z) ∂μ.prod (auxLaw d ℓ k)) ≤ + (m:ℝ)/2 * Real.log ((ℓ:ℝ)+1) := by + rw [← integral_map (show Measurable (@projectionGramRatio d ℓ k m) by fun_prop).aemeasurable (by fun_prop), + projectionGramRatio_law μ hμ,integral_map (by fun_prop) (by fun_prop)] + simpa only [finrank_euclideanSpace_fin, gaussianRows] using + (gaussian_integral_log_gramVolume_le (E := Vec ℓ) (m := m) (by simpa using hml)) + +lemma replicaLaw_sensing_law {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((base.measure d).withDensity f)] : + (replicaLaw (k := k) (m := m) base f).map Prod.fst = gaussianRows d k := by + apply Measure.ext_of_lintegral + intro H hH + rw [lintegral_map hH measurable_fst,replicaLaw_data_lintegral hd hk hm base hf hLt hfL + (H := fun z => H z.1) (by fun_prop)] + apply lintegral_congr_ae + filter_upwards [ae_gaussian_rows_full_rank (by omega : 3 ≤ d) (by omega : k < d)] with A hA + rw [lintegral_const,withDensity_apply _ MeasurableSet.univ,Measure.restrict_univ, + lintegral_projectedDensity hA (by omega) base hf,measure_univ,mul_one] + +lemma replicaLaw_sensing_log_integrable {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + Integrable (fun z : EqualSpace d k m × AuxSpace d ℓ k => Real.log (gramVolume z.1.1)) + ((replicaLaw .spherical f).prod (auxLaw d ℓ k)) := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have hmap : ((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)).map (fun z => z.1.1) = + gaussianRows d k := by + change (((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)).map (Prod.fst ∘ Prod.fst)) = _ + rw [← Measure.map_map measurable_fst measurable_fst,Measure.map_fst_prod,measure_univ,one_smul, + replicaLaw_sensing_law hd hk hm .spherical hf hLt hfL] + have h : Integrable (fun A : Rows d k => Real.log (gramVolume A)) + (((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)).map (fun z => z.1.1)) := by + rw [hmap] + exact gaussian_integrable_log_gramVolume (by simp; omega) + exact h.comp_measurable (by fun_prop) + +lemma replicaLaw_sensing_log_mean_le {d ℓ k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((sphereLaw d).withDensity f)] : + (∫ z : EqualSpace d k m × AuxSpace d ℓ k, Real.log (gramVolume z.1.1) + ∂((replicaLaw .spherical f).prod (auxLaw d ℓ k))) ≤ (k:ℝ)/2 * Real.log ((d:ℝ)+1) := by + have : IsProbabilityMeasure ((BaseLaw.spherical.measure d).withDensity f) := by + change IsProbabilityMeasure ((sphereLaw d).withDensity f); infer_instance + have hmap : ((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)).map (fun z => z.1.1) = + gaussianRows d k := by + change (((replicaLaw (k := k) (m := m) .spherical f).prod (auxLaw d ℓ k)).map (Prod.fst ∘ Prod.fst)) = _ + rw [← Measure.map_map measurable_fst measurable_fst,Measure.map_fst_prod,measure_univ,one_smul, + replicaLaw_sensing_law hd hk hm .spherical hf hLt hfL] + rw [← integral_map (show Measurable (fun z : EqualSpace d k m × AuxSpace d ℓ k => z.1.1) by fun_prop).aemeasurable + measurable_gramVolume.log.aestronglyMeasurable, hmap] + simpa only [finrank_euclideanSpace_fin, gaussianRows] using + gaussian_integral_log_gramVolume_le (E := Vec d) (m := k) (by simp; omega) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaMeasure.lean b/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..32973987e4010ed07b253edf2ad69079fc9e42ac --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaMeasure.lean @@ -0,0 +1,133 @@ +import OAI.Probability.PosteriorReplicas.Measures.EqualLabelVersions + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology +noncomputable section +namespace PosteriorReplicas + +def equalReference {d k m : ℕ} (ν : Measure (Vec d)) : Measure (EqualSpace d k m) := + ((Measure.pi (fun _ : Fin (m+1) => ν)).prod (gaussianRows d k)).map rightBasePoint + +instance {d k m : ℕ} (ν : Measure (Vec d)) [IsProbabilityMeasure ν] : + IsProbabilityMeasure (equalReference (k := k) (m := m) ν) := by + unfold equalReference + infer_instance + +instance {d k m : ℕ} (ν : Measure (Vec d)) [IsFiniteMeasure ν] : + IsFiniteMeasure (equalReference (k := k) (m := m) ν) := by + unfold equalReference + infer_instance + +def replicaDensity {d k m : ℕ} (base : BaseLaw) (f : Vec d → ℝ≥0∞) + (z : EqualSpace d k m) : ℝ≥0∞ := + equalConstant k m * (ENNReal.ofReal (affineVolume z.2.2))⁻¹ ^ k * + (projectedDensity base f z.1 z.2.1)⁻¹ ^ m + +@[fun_prop] lemma measurable_replicaDensity {d k m : ℕ} (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) : Measurable (@replicaDensity d k m base f) := by + unfold replicaDensity + fun_prop + +def replicaLaw {d k m : ℕ} (base : BaseLaw) (f : Vec d → ℝ≥0∞) : Measure (EqualSpace d k m) := + (equalReference ((base.measure d).withDensity f)).withDensity (replicaDensity base f) + +lemma equalReference_lintegral {d k m : ℕ} (ν : Measure (Vec d)) [IsFiniteMeasure ν] + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + ∫⁻ z, H z ∂equalReference ν = ∫⁻ u : Tuple d m, ∫⁻ A, + H (residualRows u A, labels (residualRows u A) (u 0), u) ∂gaussianRows d k + ∂Measure.pi (fun _ => ν) := by + rw [equalReference, lintegral_map hH measurable_rightBasePoint, + lintegral_prod _ (show AEMeasurable (fun z => H (rightBasePoint z)) _ from + (hH.comp measurable_rightBasePoint).aemeasurable)] + rfl + +lemma density_power_cancel (m : ℕ) {a : ℝ≥0∞} (ha : a ≠ ∞) : + a^(m+1) * a⁻¹^m = a := by + by_cases h0 : a = 0 + · simp [h0] + · rw [pow_succ, mul_comm (a^m) a, mul_assoc, ← mul_pow, ENNReal.mul_inv_cancel h0 ha, + one_pow, mul_one] + +lemma replicaLaw_lintegral {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + ∫⁻ z, H z ∂replicaLaw base f = + ∫⁻ A, ∫⁻ y, projectedDensity base f A y * + ∫⁻ u, H (A,y,u) ∂Measure.pi (fun _ : Fin (m+1) => tiltedFiber base f A y) + ∂volume ∂gaussianRows d k := by + let : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + have hG : Measurable (fun z : EqualSpace d k m => + (projectedDensity base f z.1 z.2.1)⁻¹^m * H z) := by fun_prop + have he := equal_label_tilt_identity hd hk hm base hf hLt hfL hG + rw [equalLabelRight_residual (by omega) (by omega) base hf hLt hfL hG] at he + have hrep : (∫⁻ z, H z ∂replicaLaw base f) = equalLabelLeft base f + (fun z : EqualSpace d k m => (projectedDensity base f z.1 z.2.1)⁻¹^m * H z) := by + rw [he] + rw [replicaLaw, lintegral_withDensity_eq_lintegral_mul _ (measurable_replicaDensity base hf) hH] + simp only [Pi.mul_apply] + rw [equalReference_lintegral (base.measure d |>.withDensity f) (by fun_prop)] + unfold replicaDensity + simp only + rw [← lintegral_const_mul _ (show Measurable (fun u : Tuple d m => + (ENNReal.ofReal (affineVolume u))⁻¹^k * + ∫⁻ A, (projectedDensity base f (residualRows u A) + (labels (residualRows u A) (u 0)))⁻¹^m * + H (residualRows u A, labels (residualRows u A) (u 0), u) ∂gaussianRows d k) by + unfold residualRows; fun_prop)] + apply lintegral_congr + intro u + rw [← mul_assoc, ← lintegral_const_mul _ (show Measurable (fun A => + (projectedDensity base f (residualRows u A) + (labels (residualRows u A) (u 0)))⁻¹^m * + H (residualRows u A, labels (residualRows u A) (u 0), u)) by unfold residualRows; fun_prop)] + apply lintegral_congr + intro A + ring + rw [hrep] + unfold equalLabelLeft + apply lintegral_congr + intro A + apply lintegral_congr + intro y + dsimp only + rw [lintegral_const_mul _ (show Measurable (fun u : Tuple d m => H (A,y,u)) by fun_prop), + ← mul_assoc, density_power_cancel m (projectedDensity_ne_top base hLt hfL A y)] + +lemma lintegral_projectedDensity {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (hk : k < d) (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) : + (∫⁻ y, projectedDensity base f A y) = (base.measure d).withDensity f univ := by + have h := congrArg (fun μ : Measure (Labels k) => μ univ) (projected_measure hA hk base hf) + rw [Measure.map_apply (by unfold labels; fun_prop) MeasurableSet.univ, + preimage_univ, withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] at h + simpa only [withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] using h.symm + +lemma replicaLaw_mass {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + replicaLaw (k := k) (m := m) base f univ = (base.measure d).withDensity f univ := by + rw [← lintegral_one, replicaLaw_lintegral hd hk hm base hf hLt hfL measurable_const] + have (A : Rows d k) (y : Labels k) := tiltedFiber_probability base hLt hfL A y + simp only [lintegral_one, measure_univ, mul_one] + calc + _ = ∫⁻ (_ : Rows d k), (base.measure d).withDensity f univ ∂gaussianRows d k := by + apply lintegral_congr_ae + filter_upwards [ae_gaussian_rows_full_rank (by omega : 3 ≤ d) (by omega : k < d)] with A hA + exact lintegral_projectedDensity hA (by omega) base hf + _ = _ := by simp + +lemma replicaLaw_probability {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((base.measure d).withDensity f)] : + IsProbabilityMeasure (replicaLaw (k := k) (m := m) base f) := by + constructor + rw [replicaLaw_mass hd hk hm base hf hLt hfL, measure_univ] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaTupleMarginals.lean b/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaTupleMarginals.lean new file mode 100644 index 0000000000000000000000000000000000000000..cf2a3f23dbb79d887bced037458ffdc54722f585 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Kernels/ReplicaTupleMarginals.lean @@ -0,0 +1,58 @@ +import OAI.Probability.PosteriorReplicas.Kernels.PosteriorExperiment + +namespace OAI + +open MeasureTheory ProbabilityTheory InformationTheory Set Filter +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma signalMessageLaw_fst {d k N : ℕ} (p : Measure (Vec d)) [IsProbabilityMeasure p] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : (signalMessageLaw p κ).fst = p := by + rw [signalMessageLaw,Measure.fst,Measure.map_map measurable_fst (by fun_prop)] + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (by fun_prop),Measure.lintegral_compProd (by fun_prop)] + simp only [Function.comp_def,lintegral_const,measure_univ,mul_one] + rw [lintegral_prod _ (by fun_prop)] + simp + +lemma posteriorMessageLaw_message {d k m N : ℕ} (hd : 3 ≤ d) (hk : k < d) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((base.measure d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + (posteriorMessageLaw (m := m) base hf κ).snd = (signalMessageLaw ((base.measure d).withDensity f) κ).snd := by + rw [← posteriorMessageLaw_coordinate hd hk base hf hLt hfL κ (0 : Fin (m+1)), + Measure.snd,Measure.snd,Measure.map_map measurable_snd (by fun_prop)] + rfl + +lemma posteriorMessageLaw_coordinateMarginal {d k m N : ℕ} (hd : 3 ≤ d) (hk : k < d) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((base.measure d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] (i : Fin (m+1)) : + coordinateMarginal (posteriorMessageLaw (m := m) base hf κ).fst i = + (base.measure d).withDensity f := by + rw [← signalMessageLaw_fst ((base.measure d).withDensity f) κ, + ← posteriorMessageLaw_coordinate hd hk base hf hLt hfL κ i] + rw [coordinateMarginal,Measure.fst,Measure.map_map (measurable_pi_apply i) measurable_fst, + Measure.fst,Measure.map_map measurable_fst (by fun_prop)] + rfl + +lemma posteriorMessageLaw_marginalProduct {d k m N : ℕ} (hd : 3 ≤ d) (hk : k < d) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + [IsProbabilityMeasure ((base.measure d).withDensity f)] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + marginalProduct (posteriorMessageLaw (m := m) base hf κ).fst = + Measure.pi (fun _ : Fin (m+1) => (base.measure d).withDensity f) := by + unfold marginalProduct + congr 1 + funext i + exact posteriorMessageLaw_coordinateMarginal hd hk base hf hLt hfL κ i + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Learners/CompletedKernelLaw.lean b/lean/OAI/Probability/PosteriorReplicas/Learners/CompletedKernelLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..93895f4ba0a3c2d7f3358e20ef204276e2bd5bc7 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Learners/CompletedKernelLaw.lean @@ -0,0 +1,191 @@ +import OAI.Probability.PosteriorReplicas.Learners.CompletedKernelLearner + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Function +open scoped ENNReal NNReal RealInnerProductSpace unitInterval +noncomputable section +namespace PosteriorRegression + +lemma map_prod_eq_bind {A B C : Type*} [MeasurableSpace A] [MeasurableSpace B] + [MeasurableSpace C] [Countable A] [MeasurableSingletonClass A] + (μ : Measure A) (ν : Measure B) [SFinite ν] {f : A × B → C} (hf : Measurable f) : + (μ.prod ν).map f = μ.bind (fun a => ν.map (fun b => f (a,b))) := by + ext s hs + rw [Measure.map_apply hf hs, Measure.prod_apply (hf hs), + Measure.bind_apply hs (measurable_of_countable _).aemeasurable] + apply lintegral_congr + intro a + exact (Measure.map_apply (hf.comp measurable_prodMk_left) hs).symm + +namespace CompletedKernelLearner +open Learner + +def Realization.stepMap {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) (i : Fin T) : RunStatus M × unitInterval → RunStatus M + | (.inr done,_) => .inr done + | (.inl a,u) => destStatus (i.val+1) (R.transition (i.val+1) a (x i,⟪x i,s.val⟫) u) + +lemma Realization.measurable_stepMap {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) (i : Fin T) : Measurable (R.stepMap s x i) := by + apply measurable_from_prod_countable_right + intro r + rcases r with a | done + · exact (measurable_of_finite (destStatus (i.val+1))).comp + ((R.measurable_transition (i.val+1) a).comp (measurable_const.prodMk measurable_id)) + · exact measurable_const + +lemma Realization.run_succ {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) (n : ℕ) (hn : n + simp only [dite_eq_left hn, Realization.toLearner, dite_eq_left (show n+1≤T by omega), stepMap, destStatus] + +lemma Realization.measurable_run {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) (n : ℕ) : + Measurable (fun ω => (R.toLearner T).run s ω x n) := by + induction n with + | zero => exact (measurable_of_finite (destStatus 0)).comp (R.measurable_initial.comp (measurable_pi_apply 0)) + | succ n ih => + by_cases hn : n (R.toLearner T).run s ω x (n+1)) = (fun ω => (R.toLearner T).run s ω x n) := by + funext ω + rw [Learner.run] + cases (R.toLearner T).run s ω x n <;> simp [hn] + rw [he] + exact ih + +lemma Realization.run_depends_prefix {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) (n : ℕ) {ω ω' : Coins T} + (hω : ∀ j : Fin (T+2), j.val≤n → ω j = ω' j) : + (R.toLearner T).run s ω x n = (R.toLearner T).run s ω' x n := by + induction n with + | zero => exact congrArg (destStatus 0 ∘ R.initial) (hω 0 (by simp)) + | succ n ih => + have hprev := ih (fun j hj => hω j (by omega)) + by_cases hn : n simp [hn] + +def fillCoins {T : ℕ} (A : Finset (Fin (T+2))) (u : A → unitInterval) : Coins T := + fun j => if hj : j∈A then u ⟨j,hj⟩ else 0 + +lemma measurable_fillCoins {T : ℕ} (A : Finset (Fin (T+2))) : Measurable (fillCoins A) := by + apply Measurable.of_eval + intro j + by_cases hj : j∈A + · simpa [fillCoins,hj] using (measurable_pi_apply (⟨j,hj⟩ : A)) + · simp [fillCoins,hj] + +lemma indep_fresh_coin {T : ℕ} {Z : Type*} [MeasurableSpace Z] (n : ℕ) + {f : Coins T → Z} (hf : Measurable f) + (hprefix : ∀ ω ω', (∀ j : Fin (T+2), j.val≤n → ω j = ω' j) → f ω = f ω') + (j : Fin (T+2)) (hj : n ω j) (coinsLaw T) := by + classical + let A := Finset.univ.filter (fun i : Fin (T+2) => i.val≤n) + have hd : Disjoint A {j} := by + simp only [Finset.disjoint_singleton_right, A, Finset.mem_filter, Finset.mem_univ, true_and] + omega + have hi : iIndepFun (fun i (ω : Coins T) => ω i) (coinsLaw T) := + iIndepFun_pi (fun _ => aemeasurable_id) + have hh := (hi.indepFun_finset A {j} hd (fun i => measurable_pi_apply i)).comp + (hf.comp (measurable_fillCoins A)) (measurable_pi_apply (⟨j,Finset.mem_singleton_self j⟩ : ({j} : Finset (Fin (T+2))))) + have he : (fun ω : Coins T => f (fillCoins A (fun i : A => ω i))) = f := by + funext ω + apply hprefix + intro i hi + simp [fillCoins, A, hi] + simpa only [Function.comp_def, he] using hh + +lemma Realization.step_law {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) (i : Fin T) (r : RunStatus M) : + volume.map (fun u => R.stepMap s x i (r,u)) = K.stepMeasure s x i r := by + rcases r with a | done + · change volume.map (destStatus (i.val+1) ∘ R.transition (i.val+1) a (x i,⟪x i,s.val⟫)) = _ + have hm : Measurable (R.transition (i.val+1) a (x i,⟪x i,s.val⟫)) := + (R.measurable_transition (i.val+1) a).comp (measurable_const.prodMk measurable_id) + rw [← Measure.map_map (measurable_of_finite (destStatus (M := M) (i.val+1))) hm] + rw [R.law_transition] + rfl + · simp [stepMap,stepMeasure,Measure.map_const] + +lemma Realization.run_law {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) (n : ℕ) : + (coinsLaw T).map (fun ω => (R.toLearner T).run s ω x n) = K.runMeasure s x n := by + induction n with + | zero => + change (coinsLaw T).map (destStatus 0 ∘ (R.toLearner T).initialChoice) = _ + have hm : Measurable (R.toLearner T).initialChoice := R.measurable_initial.comp (measurable_pi_apply 0) + rw [← Measure.map_map (measurable_of_finite (destStatus (M := M) 0)) hm, R.initial_law] + rfl + | succ n ih => + by_cases hn : n R.run_depends_prefix s x n hω) (⟨n+1,by omega⟩ : Fin (T+2)) (by simp) + have hj := hi.map_prod_eq_prod_map_map (R.measurable_run s x n).aemeasurable + (measurable_pi_apply (⟨n+1,by omega⟩ : Fin (T+2))).aemeasurable + have hc : (coinsLaw T).map (fun ω => ω (⟨n+1,by omega⟩ : Fin (T+2))) = volume := + (measurePreserving_eval (fun _ : Fin (T+2) => (volume : Measure unitInterval)) ⟨n+1,by omega⟩).map_eq + simp only [R.run_succ s x n hn] + change (coinsLaw T).map (R.stepMap s x ⟨n,hn⟩ ∘ (fun ω => ((R.toLearner T).run s ω x n,ω ⟨n+1,by omega⟩))) = _ + rw [← Measure.map_map (R.measurable_stepMap s x _) ((R.measurable_run s x n).prodMk (measurable_pi_apply _)), hj, ih, hc, + map_prod_eq_bind _ _ (R.measurable_stepMap s x _)] + simp only [R.step_law,runMeasure,dite_eq_left hn] + · have he : (fun ω => (R.toLearner T).run s ω x (n+1)) = (fun ω => (R.toLearner T).run s ω x n) := by + funext ω + rw [Learner.run] + cases (R.toLearner T).run s ω x n <;> simp [hn] + simpa only [he, runMeasure, dite_eq_right hn] using ih + +lemma Realization.measurable_terminal {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) : + Measurable (fun ω => (R.toLearner T).terminal s ω x) := + (measurable_of_countable (finishState T)).comp (R.measurable_run s x T) + +lemma Realization.terminal_law {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) : + (coinsLaw T).map (fun ω => (R.toLearner T).terminal s ω x) = K.terminalLaw s x := by + change (coinsLaw T).map (finishState T ∘ fun ω => (R.toLearner T).run s ω x T) = _ + rw [← Measure.map_map (measurable_of_countable _) (R.measurable_run s x T),R.run_law] + rfl + +lemma Realization.measurable_estimate {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) : + Measurable (fun ω => (R.toLearner T).estimate s ω x) := by + have hm : Measurable (fun z : (ℕ × State M) × unitInterval => R.output z.1.1 z.1.2 z.2) := + measurable_from_prod_countable_right (fun a => R.measurable_output a.1 a.2) + exact hm.comp ((R.measurable_terminal s x).prodMk (measurable_pi_apply (⟨T+1,by omega⟩ : Fin (T+2)))) + +lemma Realization.estimate_law {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (s : UnitSphere d) (x : Samples d T) : + (coinsLaw T).map (fun ω => (R.toLearner T).estimate s ω x) = K.estimateLaw s x := by + let g : (ℕ × State M) × unitInterval → UnitSphere d := fun z => R.output z.1.1 z.1.2 z.2 + have hg : Measurable g := + measurable_from_prod_countable_right (fun a => R.measurable_output a.1 a.2) + have hi := indep_fresh_coin T (R.measurable_terminal s x) (fun ω ω' hω => + congrArg (finishState T) (R.run_depends_prefix s x T hω)) (⟨T+1,by omega⟩ : Fin (T+2)) (by simp) + have hj := hi.map_prod_eq_prod_map_map (R.measurable_terminal s x).aemeasurable + (measurable_pi_apply (⟨T+1,by omega⟩ : Fin (T+2))).aemeasurable + have hc : (coinsLaw T).map (fun ω => ω (⟨T+1,by omega⟩ : Fin (T+2))) = volume := + (measurePreserving_eval (fun _ : Fin (T+2) => (volume : Measure unitInterval)) ⟨T+1,by omega⟩).map_eq + change (coinsLaw T).map (g ∘ (fun ω => ((R.toLearner T).terminal s ω x,ω ⟨T+1,by omega⟩))) = _ + rw [← Measure.map_map hg ((R.measurable_terminal s x).prodMk (measurable_pi_apply _)), hj, + R.terminal_law, hc, map_prod_eq_bind _ _ hg] + simp only [g, R.law_output, estimateLaw] + +instance estimateLaw_probability {d M T : ℕ} (K : CompletedKernelLearner d M) + (s : UnitSphere d) (x : Samples d T) : IsProbabilityMeasure (K.estimateLaw s x) := by + rw [← K.realization.estimate_law s x] + exact (Measure.isProbabilityMeasure_map_iff + (K.realization.measurable_estimate s x).aemeasurable).mpr inferInstance + +end CompletedKernelLearner +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Learners/CompletedKernelLearner.lean b/lean/OAI/Probability/PosteriorReplicas/Learners/CompletedKernelLearner.lean new file mode 100644 index 0000000000000000000000000000000000000000..a4d16662d5679ffba9848d113f181306058c2f4b --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Learners/CompletedKernelLearner.lean @@ -0,0 +1,144 @@ +import OAI.Probability.PosteriorReplicas.Learners.KernelLearnerBridge + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Function +open scoped ENNReal NNReal RealInnerProductSpace unitInterval +noncomputable section +namespace PosteriorRegression + +namespace CompletedKernelLearner + +structure Realization {d M : ℕ} (K : CompletedKernelLearner d M) where + initial : unitInterval → Destination M + measurable_initial : Measurable initial + law_initial : volume.map initial = K.initial + transition : ℕ → State M → (Vector d × ℝ) → unitInterval → Destination M + measurable_transition : ∀ t a, @Measurable (CompletedObservation d × unitInterval) + (Destination M) _ _ (uncurry (transition t a)) + law_transition : ∀ t a obs, volume.map (transition t a obs) = K.transition t a obs + output : ℕ → State M → unitInterval → UnitSphere d + measurable_output : ∀ t a, Measurable (output t a) + law_output : ∀ t a, volume.map (output t a) = K.output t a + +lemma exists_realization {d M : ℕ} (K : CompletedKernelLearner d M) : Nonempty (Realization K) := by + have : Nonempty (UnitSphere d) := nonempty_of_isProbabilityMeasure (K.output 0 0) + obtain ⟨i,hi,hiLaw⟩ := K.initial.exists_measurable_map_eq + choose δ hδ hδLaw using (fun t a => (K.transition t a).exists_measurable_map_eq_unitInterval) + choose o ho hoLaw using (fun t a => (K.output t a).exists_measurable_map_eq) + exact ⟨⟨i,hi,hiLaw,δ,hδ,hδLaw,o,ho,hoLaw⟩⟩ + +def realization {d M : ℕ} (K : CompletedKernelLearner d M) : Realization K := + Classical.choice K.exists_realization + +abbrev Coins (T : ℕ) := Fin (T+2) → unitInterval + +def coinsLaw (T : ℕ) : Measure (Coins T) := Measure.pi (fun _ => volume) + +instance coinsLaw_probability (T : ℕ) : IsProbabilityMeasure (coinsLaw T) := by + unfold coinsLaw + infer_instance + +def Realization.toLearner {d M : ℕ} {K : CompletedKernelLearner d M} + (R : Realization K) (T : ℕ) : Learner d M T (Coins T) where + initialChoice ω := R.initial (ω 0) + transition t ω a obs := if ht : t≤T then R.transition t a obs (ω ⟨t,by omega⟩) else (false,a) + output t ω a := R.output t a (ω ⟨T+1,by omega⟩) + +lemma Realization.transition_completed {d M T : ℕ} {K : CompletedKernelLearner d M} + (R : Realization K) (ω : Coins T) (t : ℕ) (a : State M) : + AEMeasurable (fun obs => ((R.toLearner T).transition t ω a obs).2) (observationReference d) := by + by_cases ht : t≤T + · change AEMeasurable (fun obs => (if _ : t≤T then R.transition t a obs (ω ⟨t,by omega⟩) else (false,a)).2) _ + simp only [dite_eq_left ht] + have hm : @Measurable (CompletedObservation d) (Destination M) _ _ + (fun obs => R.transition t a obs (ω ⟨t,by omega⟩)) := + (R.measurable_transition t a).comp (measurable_id.prodMk measurable_const) + apply NullMeasurable.aemeasurable + exact measurable_snd.comp hm + · simpa only [toLearner, dite_eq_right ht] using (aemeasurable_const : + AEMeasurable (fun _ : Vector d × ℝ => a) (observationReference d)) + +lemma observation_coin_quasi {d T : ℕ} (hd : 3≤d) (i : Fin T) (j : Fin (T+2)) : + Measure.QuasiMeasurePreserving + (fun z : UnitSphere d × (Coins T × Samples d T) => + ((z.2.2 i,⟪z.2.2 i,z.1.val⟫),z.2.1 j)) + ((uniformSphere d).prod ((coinsLaw T).prod (sampleLaw d T))) + ((observationReference d).prod (volume : Measure unitInterval)) := by + have : NeZero d := ⟨by omega⟩ + let e : ((UnitSphere d × Samples d T) × Coins T) ≃ᵐ + UnitSphere d × (Coins T × Samples d T) := + MeasurableEquiv.prodAssoc.trans (MeasurableEquiv.prodCongr (MeasurableEquiv.refl _) + MeasurableEquiv.prodComm) + have he : MeasurePreserving e + (((uniformSphere d).prod (sampleLaw d T)).prod (coinsLaw T)) + ((uniformSphere d).prod ((coinsLaw T).prod (sampleLaw d T))) := + ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := coinsLaw T))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) (coinsLaw T)) + have hp := MeasureTheory.QuasiMeasurePreserving.prodMap + (sphere_sample_observation_quasi (E := Vector d) (by simpa using hd) i) + (measurePreserving_eval (fun _ : Fin (T+2) => (volume : Measure unitInterval)) j).quasiMeasurePreserving + have hh := hp.comp (MeasurePreserving.symm e he).quasiMeasurePreserving + change Measure.QuasiMeasurePreserving + (fun z : UnitSphere d × (Coins T × Samples d T) => + ((z.2.2 i,⟪z.1.val,z.2.2 i⟫),z.2.1 j)) + ((uniformSphere d).prod ((coinsLaw T).prod (sampleLaw d T))) + ((observationReference d).prod (volume : Measure unitInterval)) at hh + simpa only [real_inner_comm] using hh + +lemma Realization.uniformAdmissible {d M T : ℕ} (hd : 3≤d) {K : CompletedKernelLearner d M} + (R : Realization K) : (R.toLearner T).UniformAdmissible (coinsLaw T) := by + refine ⟨Filter.Eventually.of_forall (fun ω t a => R.transition_completed ω t a),?_⟩ + apply Learner.uniform_experiment_of_steps + · exact R.measurable_initial.comp (measurable_pi_apply 0) + · intro t a i + by_cases ht : t≤T + · simp only [toLearner,dite_eq_left ht] + have hm := aemeasurable_completed_prod (observationReference d) (volume : Measure unitInterval) + (R.measurable_transition t a) + exact hm.comp_quasiMeasurePreserving (observation_coin_quasi hd i ⟨t,by omega⟩) + · simpa only [toLearner,dite_eq_right ht] using (aemeasurable_const : AEMeasurable + (fun _ : UnitSphere d × (Coins T × Samples d T) => (false,a)) + ((uniformSphere d).prod ((coinsLaw T).prod (sampleLaw d T)))) + · intro t a + exact (R.measurable_output t a).comp (measurable_pi_apply (⟨T+1,by omega⟩ : Fin (T+2))) + +lemma Realization.initial_law {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) : + (coinsLaw T).map (R.toLearner T).initialChoice = K.initial := by + change (coinsLaw T).map (R.initial ∘ fun ω => ω 0) = K.initial + unfold coinsLaw + rw [← Measure.map_map R.measurable_initial (measurable_pi_apply 0), + (measurePreserving_eval (fun _ : Fin (T+2) => (volume : Measure unitInterval)) 0).map_eq] + exact R.law_initial + +lemma Realization.transition_law {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (t : ℕ) (ht : t≤T) (a : State M) (obs : Vector d × ℝ) : + (coinsLaw T).map (fun ω => (R.toLearner T).transition t ω a obs) = K.transition t a obs := by + have hm : Measurable (R.transition t a obs) := + (R.measurable_transition t a).comp (measurable_const.prodMk measurable_id) + change (coinsLaw T).map (fun ω => if _ : t≤T then R.transition t a obs (ω ⟨t,by omega⟩) else (false,a)) = _ + simp only [dite_eq_left ht] + calc + (coinsLaw T).map (fun ω => R.transition t a obs (ω ⟨t,by omega⟩)) = + volume.map (R.transition t a obs) := by + change (coinsLaw T).map (R.transition t a obs ∘ (fun ω : Coins T => ω ⟨t,by omega⟩)) = _ + unfold coinsLaw + rw [← Measure.map_map hm (measurable_pi_apply (⟨t,by omega⟩ : Fin (T+2))), + (measurePreserving_eval (fun _ : Fin (T+2) => (volume : Measure unitInterval)) ⟨t,by omega⟩).map_eq] + _ = _ := R.law_transition t a obs + +lemma Realization.output_law {d M T : ℕ} {K : CompletedKernelLearner d M} (R : Realization K) + (t : ℕ) (a : State M) : + (coinsLaw T).map (fun ω => (R.toLearner T).output t ω a) = K.output t a := by + change (coinsLaw T).map (R.output t a ∘ fun ω => ω ⟨T+1,by omega⟩) = _ + unfold coinsLaw + rw [← Measure.map_map (R.measurable_output t a) (measurable_pi_apply (⟨T+1,by omega⟩ : Fin (T+2))), + (measurePreserving_eval (fun _ : Fin (T+2) => (volume : Measure unitInterval)) ⟨T+1,by omega⟩).map_eq] + exact R.law_output t a + +end CompletedKernelLearner +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Learners/HaarLawIdentification.lean b/lean/OAI/Probability/PosteriorReplicas/Learners/HaarLawIdentification.lean new file mode 100644 index 0000000000000000000000000000000000000000..a02153fa1dffddf2a84328d39aa4eeecdb6f2c69 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Learners/HaarLawIdentification.lean @@ -0,0 +1,64 @@ +import OAI.Probability.PosteriorReplicas.Information.HaarInformationEq + +namespace OAI + +open MeasureTheory ProbabilityTheory Set InnerProductSpace +open scoped RealInnerProductSpace +noncomputable section +namespace PosteriorReplicas + +lemma gramSchmidt_linearIsometry {d ℓ : ℕ} (e : Vec d ≃ₗᵢ[ℝ] Vec d) + (A : Rows d ℓ) (i : Fin ℓ) : + gramSchmidt ℝ (fun j => e (A j)) i = e (gramSchmidt ℝ A i) := by + induction i using WellFoundedLT.induction with + | ind i hi => + rw [gramSchmidt_def, gramSchmidt_def, map_sub, map_sum] + congr 1 + apply Finset.sum_congr rfl + intro j hj + have hj : j < i := Finset.mem_Iio.mp hj + rw [hi j hj, Submodule.starProjection_singleton, Submodule.starProjection_singleton, + e.inner_map_map, e.norm_map, map_smul] + +lemma gramSchmidtNormed_linearIsometry {d ℓ : ℕ} (e : Vec d ≃ₗᵢ[ℝ] Vec d) + (A : Rows d ℓ) : + gramSchmidtNormed ℝ (fun j => e (A j)) = fun j => e (gramSchmidtNormed ℝ A j) := by + funext j + simp only [gramSchmidtNormed, gramSchmidt_linearIsometry, e.norm_map, map_smul] + +lemma gaussianRows_orthogonal_invariant {d ℓ : ℕ} (e : Vec d ≃ₗᵢ[ℝ] Vec d) : + (gaussianRows d ℓ).map (fun A i => e (A i)) = gaussianRows d ℓ := by + unfold gaussianRows + rw [Measure.pi_map_pi (fun _ => e.continuous.measurable.aemeasurable)] + simp only [stdGaussian_map] + +lemma haarRows_orthogonal_invariant {d ℓ : ℕ} (e : Vec d ≃ₗᵢ[ℝ] Vec d) : + (haarRows d ℓ).map (fun A i => e (A i)) = haarRows d ℓ := by + have hm : Measurable (fun A : Rows d ℓ => fun i => e (A i)) := by fun_prop + rw [haarRows, Measure.map_map hm measurable_gramSchmidtNormed_rows] + have he : (fun A : Rows d ℓ => fun i => e (gramSchmidtNormed ℝ A i)) = + (fun A => gramSchmidtNormed ℝ (fun i => e (A i))) := by + funext A + exact (gramSchmidtNormed_linearIsometry e A).symm + change (gaussianRows d ℓ).map (fun A => fun i => e (gramSchmidtNormed ℝ A i)) = _ + rw [he] + change (gaussianRows d ℓ).map ((gramSchmidtNormed ℝ) ∘ (fun A i => e (A i))) = _ + rw [← Measure.map_map measurable_gramSchmidtNormed_rows hm, + gaussianRows_orthogonal_invariant] + +lemma haarRows_ae_orthonormal {d ℓ : ℕ} (hℓ : ℓ ≤ d) : + ∀ᵐ A ∂haarRows d ℓ, Orthonormal ℝ A := by + have hmeas : MeasurableSet {A : Rows d ℓ | Orthonormal ℝ A} := by + simp only [orthonormal_iff_ite, ofPred_forall] + exact MeasurableSet.iInter fun i => MeasurableSet.iInter fun j => + measurableSet_eq_fun (by fun_prop) measurable_const + rw [haarRows] + apply (ae_map_iff measurable_gramSchmidtNormed_rows.aemeasurable hmeas).mpr + have hfull := ae_gaussian_columns_independent (E := Vec d) ℓ (by simpa using hℓ) + filter_upwards [hfull] with A hA + exact gramSchmidtNormed_orthonormal hA + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Learners/JointKernelExperiment.lean b/lean/OAI/Probability/PosteriorReplicas/Learners/JointKernelExperiment.lean new file mode 100644 index 0000000000000000000000000000000000000000..bee72fd0ddf0d794caaf726fe4ca0b8b84921c12 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Learners/JointKernelExperiment.lean @@ -0,0 +1,73 @@ +import OAI.Probability.PosteriorReplicas.Learners.KernelSuccess + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Function +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression + +namespace JointKernelExperiment +open Learner + +instance law_probability {d M T : ℕ} [NeZero d] {Ω : Type u} [MeasurableSpace Ω] + {ρ : Measure Ω} [IsProbabilityMeasure ρ] (E : JointKernelExperiment d M T Ω ρ) : + IsProbabilityMeasure E.law := by + unfold law + infer_instance + +lemma uniformSuccess_eq_average {d M T : ℕ} [NeZero d] {Ω : Type u} [MeasurableSpace Ω] + {ρ : Measure Ω} [IsProbabilityMeasure ρ] (E : JointKernelExperiment d M T Ω ρ) (ε : ℝ) : + E.uniformSuccess ε = ∫⁻ ω, (E.rules ω).uniformSuccess T ε ∂ρ := by + have hS : MeasurableSet {z : (Ω × (UnitSphere d × Samples d T)) × UnitSphere d | + angularError z.1.2.1 z.2 ≤ ε} := by + exact measurableSet_le (Real.continuous_arccos.measurable.comp + ((measurable_subtype_coe.comp measurable_snd).inner + (measurable_subtype_coe.comp measurable_fst.snd.fst))) measurable_const + have hm := Kernel.measurable_kernel_prodMk_left (κ := E.outputKernel) hS + rw [uniformSuccess,law,Measure.compProd_apply hS,lintegral_prod _ hm.aemeasurable] + apply lintegral_congr_ae + filter_upwards [E.conditional_output] with ω hω + apply lintegral_congr_ae + filter_upwards [hω] with z hz + rw [hz] + rfl + +lemma exists_seed_ge_success {d M T : ℕ} [NeZero d] {Ω : Type u} [MeasurableSpace Ω] + {ρ : Measure Ω} [IsProbabilityMeasure ρ] (E : JointKernelExperiment d M T Ω ρ) (ε : ℝ) : + ∃ ω, E.uniformSuccess ε ≤ (E.rules ω).uniformSuccess T ε := by + rw [E.uniformSuccess_eq_average ε] + apply exists_lintegral_le + apply ne_of_lt + apply lt_of_le_of_lt (lintegral_mono (fun ω => (E.rules ω).uniformSuccess_le_one T ε)) + simp + +lemma fixed_quadratic_memory {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + {ρ : Measure Ω} [IsProbabilityMeasure ρ] {A : ℝ} (hA : 0 (z.1,z.2)) := by + apply Measurable.prodMk + · intro s hs + have hs' : @NullMeasurableSet X mX s μ := hs + change @NullMeasurableSet (X × Y) _ (Prod.fst ⁻¹' s) (μ.prod ν) + exact @NullMeasurableSet.preimage (X × Y) X _ mX _ μ Prod.fst s hs' + (Measure.quasiMeasurePreserving_fst (μ := μ) (ν := ν)) + · exact measurable_snd.nullMeasurable.measurable' + exact hf.comp hp + +lemma aemeasurable_countable_choice {X J Y : Type*} [MeasurableSpace X] [MeasurableSpace J] + [MeasurableSpace Y] [Countable J] [MeasurableSingletonClass J] + {μ : Measure X} {j : X → J} (hj : AEMeasurable j μ) + {f : J → X → Y} (hf : ∀ a, AEMeasurable (f a) μ) : + AEMeasurable (fun x => f (j x) x) μ := by + let g : J → X → Y := fun a => (hf a).mk (f a) + have hg : Measurable (fun z : X × J => g z.2 z.1) := + measurable_from_prod_countable_left (fun a => (hf a).measurable_mk) + apply (hg.comp_aemeasurable (aemeasurable_id.prodMk hj)).congr + filter_upwards [ae_all_iff.mpr (fun a => (hf a).ae_eq_mk)] with x hx + exact (hx (j x)).symm + +namespace Learner + +instance runStatus_measurableSingleton (M : ℕ) : MeasurableSingletonClass (RunStatus M) where + measurableSet_singleton r := by + rcases r with a | done + · simpa only [Set.image_singleton] using (measurableSet_inl_image (β := ℕ × State M) (s := {a})).mpr (measurableSet_singleton a) + · simpa only [Set.image_singleton] using (measurableSet_inr_image (α := State M) (s := {done})).mpr (measurableSet_singleton done) + +lemma uniform_experiment_of_steps {d M T : ℕ} {Ω : Type*} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hinit : Measurable L.initialChoice) + (htrans : ∀ t a (i : Fin T), AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => + L.transition t z.2.1 a (z.2.2 i,⟪z.2.2 i,z.1.val⟫)) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T)))) + (hout : ∀ t a, Measurable (fun ω => L.output t ω a)) : + AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => L.estimate z.1 z.2.1 z.2.2) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := by + let μ := (uniformSphere d).prod (ρ.prod (sampleLaw d T)) + have hstart : Measurable L.start := by + have he : L.start = (fun a : Bool × State M => if a.1 then Sum.inr (0,a.2) else Sum.inl a.2) ∘ L.initialChoice := rfl + rw [he] + exact (measurable_of_finite _).comp hinit + have hr (n : ℕ) : AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => L.run z.1 z.2.1 z.2.2 n) μ := by + induction n with + | zero => exact (hstart.comp measurable_snd.fst).aemeasurable + | succ n ih => + have hf (r : RunStatus M) : AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => + (match r with + | .inr done => .inr done + | .inl a => if hn : n + if v.1 then Sum.inr (n+1,v.2) else Sum.inl v.2)).comp_aemeasurable (htrans (n+1) a ⟨n,hn⟩) + · simpa only [dite_eq_right hn] using (aemeasurable_const : AEMeasurable (fun _ : UnitSphere d × (Ω × Samples d T) => Sum.inl a : _ → RunStatus M) μ) + · exact aemeasurable_const + exact aemeasurable_countable_choice ih hf + have ht : AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => L.terminal z.1 z.2.1 z.2.2) μ := by + exact (measurable_of_countable (fun r : RunStatus M => + match r with | .inl a => (T,a) | .inr done => done)).comp_aemeasurable (hr T) + have ho (r : ℕ × State M) : AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => L.output r.1 z.2.1 r.2) μ := + ((hout r.1 r.2).comp measurable_snd.fst).aemeasurable + exact aemeasurable_countable_choice ht ho + +end Learner +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Learners/KernelSuccess.lean b/lean/OAI/Probability/PosteriorReplicas/Learners/KernelSuccess.lean new file mode 100644 index 0000000000000000000000000000000000000000..22d82887741890892b54c47645e7e74d97496daa --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Learners/KernelSuccess.lean @@ -0,0 +1,77 @@ +import OAI.Probability.PosteriorReplicas.Learners.CompletedKernelLaw + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Function +open scoped ENNReal NNReal RealInnerProductSpace unitInterval +noncomputable section +namespace PosteriorRegression + +namespace CompletedKernelLearner +open Learner + +def uniformSuccess {d M : ℕ} (K : CompletedKernelLearner d M) (T : ℕ) (ε : ℝ) : ℝ≥0∞ := + ∫⁻ z : UnitSphere d × Samples d T, + K.estimateLaw z.1 z.2 {ŝ | angularError z.1 ŝ ≤ ε} + ∂((uniformSphere d).prod (sampleLaw d T)) + +lemma angularBall_measurable {d : ℕ} (s : UnitSphere d) (ε : ℝ) : + MeasurableSet {ŝ : UnitSphere d | angularError s ŝ ≤ ε} := by + exact measurableSet_le (Real.continuous_arccos.measurable.comp + (measurable_subtype_coe.inner measurable_const)) measurable_const + +lemma Realization.uniformSuccess_eq {d M T : ℕ} (hd : 3≤d) {K : CompletedKernelLearner d M} + (R : Realization K) (ε : ℝ) : + (R.toLearner T).uniformSuccess (coinsLaw T) ε = K.uniformSuccess T ε := by + have : NeZero d := ⟨by omega⟩ + let S : Set (UnitSphere d × (Coins T × Samples d T)) := + {z | angularError z.1 ((R.toLearner T).estimate z.1 z.2.1 z.2.2) ≤ ε} + have hS : NullMeasurableSet S ((uniformSphere d).prod ((coinsLaw T).prod (sampleLaw d T))) := + (R.uniformAdmissible hd).angularSuccess_nullMeasurable ε + let e : ((UnitSphere d × Samples d T) × Coins T) ≃ᵐ + UnitSphere d × (Coins T × Samples d T) := + MeasurableEquiv.prodAssoc.trans ((MeasurableEquiv.refl _).prodCongr MeasurableEquiv.prodComm) + have he : MeasurePreserving e + (((uniformSphere d).prod (sampleLaw d T)).prod (coinsLaw T)) + ((uniformSphere d).prod ((coinsLaw T).prod (sampleLaw d T))) := + ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := coinsLaw T))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) (coinsLaw T)) + have hQ := hS.preimage he.quasiMeasurePreserving + have hI := (aemeasurable_const : AEMeasurable (fun _ : (UnitSphere d × Samples d T) × Coins T => (1 : ℝ≥0∞)) + (((uniformSphere d).prod (sampleLaw d T)).prod (coinsLaw T))).indicator₀ hQ + change ((uniformSphere d).prod ((coinsLaw T).prod (sampleLaw d T))) S = _ + rw [← he.measure_preimage hS] + rw [← one_mul ((((uniformSphere d).prod (sampleLaw d T)).prod (coinsLaw T)) (e ⁻¹' S)), + ← lintegral_indicator_const₀ hQ 1, lintegral_prod _ hI] + unfold uniformSuccess + apply lintegral_congr + intro z + have hball := angularBall_measurable z.1 ε + rw [← R.estimate_law z.1 z.2, Measure.map_apply (R.measurable_estimate z.1 z.2) hball] + have hm : MeasurableSet {ω : Coins T | angularError z.1 ((R.toLearner T).estimate z.1 ω z.2) ≤ ε} := + (R.measurable_estimate z.1 z.2) hball + change (∫⁻ ω, ({ω : Coins T | angularError z.1 ((R.toLearner T).estimate z.1 ω z.2) ≤ ε}).indicator + (fun _ => (1 : ℝ≥0∞)) ω ∂coinsLaw T) = _ + rw [lintegral_indicator_const hm] + simp only [one_mul] + rfl + +lemma uniformSuccess_le_one {d M : ℕ} [NeZero d] (K : CompletedKernelLearner d M) (T : ℕ) (ε : ℝ) : + K.uniformSuccess T ε ≤ 1 := by + apply (lintegral_mono (fun z => prob_le_one)).trans + simp + +lemma fixed_quadratic_memory {d M T : ℕ} {A : ℝ} (hA : 0 (L.transition t ω a obs).2) (observationReference d) + uniform_experiment : AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => L.estimate z.1 z.2.1 z.2.2) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) + +lemma Admissible.uniformAdmissible {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + {L : Learner d M T Ω} {ρ : Measure Ω} [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) : L.UniformAdmissible ρ := by + have : SigmaFinite (observationReference d) := by unfold observationReference; infer_instance + refine ⟨?_,hL.uniform_experiment⟩ + simp only [ae_all_iff] + intro t a + filter_upwards [ae_fiber_aemeasurable (hL.transition t a).prod_swap] with ω hω + exact measurable_snd.comp_aemeasurable hω + +lemma UniformAdmissible.angularSuccess_nullMeasurable {d M T : ℕ} {Ω : Type u} + [MeasurableSpace Ω] {L : Learner d M T Ω} {ρ : Measure Ω} + (hL : L.UniformAdmissible ρ) (ε : ℝ) : + NullMeasurableSet {z : UnitSphere d × (Ω × Samples d T) | + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := by + apply nullMeasurableSet_le _ aemeasurable_const + exact Real.continuous_arccos.measurable.comp_aemeasurable + ((measurable_subtype_coe.comp_aemeasurable hL.uniform_experiment).inner + (measurable_subtype_coe.comp measurable_fst).aemeasurable) + +lemma UniformAdmissible.linear_success_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + {L : Learner d M T Ω} {ρ : Measure Ω} [IsProbabilityMeasure ρ] + (hL : L.UniformAdmissible ρ) (hd : 0 < d) (hT : 4*T ≤ d) {ε : ℝ} (hε : ε ≤ 1/10) : + L.uniformSuccess ρ ε ≤ ENNReal.ofReal (21/32 : ℝ) := by + classical + have : NeZero d := ⟨hd.ne'⟩ + have hmeas := ae_fiber_aemeasurable hL.uniform_experiment + unfold uniformSuccess + refine (prod_null_set_bound (hL.angularSuccess_nullMeasurable ε) + (c := ENNReal.ofReal (21/32 : ℝ)) ?_).trans_eq (by simp) + filter_upwards [hmeas] with z hz + let U : Submodule ℝ (Vector d) := Submodule.span ℝ (Set.range z.2) + have hdim : Module.finrank ℝ U ≤ T := by + have h := finrank_span_le_card (R := ℝ) (Set.range z.2) + apply h.trans + rw [Set.toFinset_range] + exact (Finset.card_image_le).trans_eq (by simp) + have hU : 4 * Module.finrank ℝ U ≤ Module.finrank ℝ (Vector d) := by + simpa only [Vector, finrank_euclideanSpace_fin] using (Nat.mul_le_mul_left 4 hdim).trans hT + change sphereLaw {s : UnitSphere d | angularError s (L.estimate s z.1 z.2) ≤ ε} ≤ _ + apply sphere_reflection_success_bound U hU + · exact nullMeasurableSet_le + (Real.continuous_arccos.measurable.comp_aemeasurable + ((measurable_subtype_coe.comp_aemeasurable hz).inner measurable_subtype_coe.aemeasurable)) + aemeasurable_const + · intro s hs ht + let t := sphereIsometry U.reflection s + have he : L.estimate s z.1 z.2 = L.estimate t z.1 z.2 := by + apply L.estimate_congr_labels + intro i + have hi : z.2 i ∈ U := Submodule.subset_span (Set.mem_range_self i) + have he := U.reflection.inner_map_map (z.2 i) s.val + rw [(Submodule.reflection_eq_self_iff (z.2 i)).2 hi] at he + exact he.symm + have hs' : dist s.val (L.estimate s z.1 z.2).val ≤ ε := by + apply (chord_le_arccos s (L.estimate s z.1 z.2)).trans + simpa only [Set.mem_ofPred_eq, angularError, real_inner_comm] using hs + have ht' : dist t.val (L.estimate t z.1 z.2).val ≤ ε := by + apply (chord_le_arccos t (L.estimate t z.1 z.2)).trans + simpa only [Set.mem_ofPred_eq, angularError, real_inner_comm] using ht + calc + _ = dist s.val t.val := rfl + _ ≤ dist s.val (L.estimate s z.1 z.2).val + dist (L.estimate s z.1 z.2).val t.val := dist_triangle _ _ _ + _ ≤ ε + ε := by rw [he, dist_comm (L.estimate t z.1 z.2).val t.val] at *; exact add_le_add hs' ht' + _ ≤ 1/5 := by linarith + +lemma UniformAdmissible.streaming_success_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + {L : Learner d M T Ω} {ρ : Measure Ω} [IsProbabilityMeasure ρ] + (hL : L.UniformAdmissible ρ) (hd : 3 ≤ d) {ε : ℝ} (hε : 0 < ε) + {a q : ℕ} (ha : 2*a ≤ d-1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) : + L.uniformSuccess ρ ε ≤ + (T+1 : ℝ≥0∞) * (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := State M) q ^ (T/q+1) := by + have : NeZero d := ⟨by omega⟩ + have hp := ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := ρ))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) ρ) + let S := {z : UnitSphere d × (Ω × Samples d T) | + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + have hS : NullMeasurableSet S ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := + hL.angularSuccess_nullMeasurable ε + have he := hp.measure_preimage hS + have hb := prod_null_set_bound (hS.preimage hp.quasiMeasurePreserving) + (c := (T+1 : ℝ≥0∞) * (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := State M) q ^ (T/q+1)) + (by + filter_upwards [hL.transition] with ω hω + exact L.frozen_success_bound ω hd hω hε ha hq hqa) + simpa only [he, measure_univ, mul_one, S, uniformSuccess] using hb + +lemma UniformAdmissible.streaming_success_bound_real {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + {L : Learner d M T Ω} {ρ : Measure Ω} [IsProbabilityMeasure ρ] + (hL : L.UniformAdmissible ρ) (hd : 3 ≤ d) {ε : ℝ} (hε : 0 < ε) + {a q : ℕ} (ha : 2*a ≤ d-1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) + (hs : (2/3 : ℝ≥0∞) ≤ L.uniformSuccess ρ ε) : + (2/3 : ℝ) ≤ ((T : ℝ)+1) * ((3 : ℝ)*4^d * ε^a) * + ((32768 : ℝ)^d * ((2 : ℝ)^M)^(1/(q : ℝ)))^(T/q+1) := by + have hb := hs.trans (hL.streaming_success_bound hd hε ha hq hqa) + have ht : (T+1 : ℝ≥0∞) * + (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := State M) q ^ (T/q+1) ≠ ∞ := by + apply ENNReal.mul_ne_top + · apply ENNReal.mul_ne_top (by simp) + exact ENNReal.mul_ne_top ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top + · exact ENNReal.pow_ne_top (streamFactor_ne_top q) + have hr := ENNReal.toReal_mono ht hb + simpa [ENNReal.toReal_div, ENNReal.toReal_ofNat, ENNReal.toReal_mul, + ENNReal.toReal_add, ENNReal.toReal_natCast, ENNReal.toReal_one, + ENNReal.toReal_ofReal (by positivity : (0 : ℝ) ≤ 3*4^d), + ENNReal.toReal_ofReal (by positivity : 0 ≤ ε^a), streamFactor, + ENNReal.toReal_pow, ← ENNReal.toReal_rpow, finrank_euclideanSpace_fin, + Fintype.card_fin, State, Nat.cast_pow, Nat.cast_ofNat, Vector] using hr + +end Learner + +def UniformSubquadraticMemory : Prop := + ∃ c : ℝ, 0 < c ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d : ℝ)) (fun d => (d : ℝ) ^ 2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0 < ε → ε ≤ 1 / 10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Learner d (M d) T Ω, L.UniformAdmissible ρ → + (2 / 3 : ℝ≥0∞) ≤ L.uniformSuccess ρ ε → + c * (d : ℝ) * Real.log (1 / ε) ≤ (T : ℝ) + +lemma source_fixed_quadratic_memory {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + {A : ℝ} (hA : 0 < A) (hd : 32 ≤ d) (hM : (M:ℝ) ≤ A*(d:ℝ)^2) + {ε : ℝ} (hε : 0<ε) (hε10 : ε≤1/10) + (ρ : Measure Ω) [IsProbabilityMeasure ρ] (L : Learner d M T Ω) + (hL : L.UniformAdmissible ρ) (hs : (2/3 : ℝ≥0∞) ≤ L.uniformSuccess ρ ε) : + (1 / (4*(400000+100*A))) * (d : ℝ) * Real.log (1/ε) ≤ (T : ℝ) := by + have hT : d ≤ 4*T := by + by_contra h + have hb := hs.trans (hL.linear_success_bound (by omega) (by omega) hε10) + have hr := ENNReal.toReal_mono ENNReal.ofReal_ne_top hb + norm_num [ENNReal.toReal_div] at hr + let q := (d-1)/4 + let a := 2*q + have hq : 2 ≤ q := by dsimp [q]; omega + have hqa : 2*q ≤ a := le_rfl + have ha : 2*a ≤ d-1 := by dsimp [a, q]; omega + have hdq : d ≤ 8*q := by dsimp [q]; omega + have hda : d ≤ 4*a := by dsimp [a]; omega + exact precision_from_stream_bound hd hT (by omega) hdq hda hM hA hε (by linarith) + (hL.streaming_success_bound_real (by omega) hε ha hq hqa hs) + +theorem source_subquadratic_memory : UniformSubquadraticMemory.{u} := by + refine ⟨1/(4*(400000+100*(1:ℝ))),by positivity,?_⟩ + intro M hM + obtain ⟨d₂, hd₂⟩ := eventually_atTop.1 hM.eventuallyLE + refine ⟨max 32 d₂, ?_⟩ + intro d hd T ε hε hε10 Ω _ ρ hρ L hL hs + have : IsProbabilityMeasure ρ := hρ + have hmem : (M d : ℝ) ≤ 1 * (d : ℝ)^2 := by + have hm := hd₂ d (by omega) + simpa only [Real.norm_eq_abs, abs_of_nonneg (Nat.cast_nonneg (M d) : (0 : ℝ) ≤ M d), + abs_of_nonneg (sq_nonneg (d : ℝ)), one_mul] using hm + exact source_fixed_quadratic_memory (by norm_num) (by omega) hmem hε hε10 ρ L hL hs + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Main.lean b/lean/OAI/Probability/PosteriorReplicas/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..40cdda96a543c0d2515213690cc3681bf8b18ceb --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Main.lean @@ -0,0 +1,28 @@ +import OAI.Probability.PosteriorReplicas.Information.HaarStateBound +import OAI.Probability.PosteriorReplicas.Information.HeadlineInformation +import OAI.Probability.PosteriorReplicas.Learners.HaarLawIdentification +import OAI.Probability.PosteriorReplicas.Learners.JointLawBridge + +namespace OAI + +namespace PosteriorReplicas +universe u + +theorem main : EqualLabelMeasureIdentity ∧ EqualLabelVersions ∧ + GaussianReplicaBlock ∧ DistanceReplicaBlock ∧ HaarReplicaBlock ∧ + SyntheticReplicaBlock ∧ IncidenceReplicaBlock ∧ + PosteriorRegression.SubquadraticMemory.{u} := + ⟨equalLabelMeasureIdentity, equalLabelVersions, gaussianReplicaBlock, + distanceReplicaBlock, haarReplicaBlock, syntheticReplicaBlock, + incidenceReplicaBlock, PosteriorRegression.subquadratic_memory⟩ + +theorem source_main : EqualLabelMeasureIdentity ∧ EqualLabelVersions ∧ + GaussianReplicaBlock ∧ DistanceReplicaBlock ∧ HaarReplicaBlock ∧ + SyntheticReplicaBlock ∧ IncidenceReplicaBlock ∧ + PosteriorRegression.KernelSubquadraticMemory.{u} := + ⟨equalLabelMeasureIdentity, equalLabelVersions, gaussianReplicaBlock, + distanceReplicaBlock, haarReplicaBlock, syntheticReplicaBlock, + incidenceReplicaBlock, PosteriorRegression.kernel_subquadratic_memory⟩ +end PosteriorReplicas + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/BaseDisintegration.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/BaseDisintegration.lean new file mode 100644 index 0000000000000000000000000000000000000000..899040bd37608b4582b7725e0e02ccf07505da6a --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/BaseDisintegration.lean @@ -0,0 +1,133 @@ +import OAI.Probability.PosteriorReplicas.Geometry.BaseGeometry +import OAI.Probability.PosteriorReplicas.Geometry.SphereDensity + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +instance baseLaw_probability (base : BaseLaw) (d : ℕ) [NeZero d] : + IsProbabilityMeasure (base.measure d) := by + cases base + · change IsProbabilityMeasure (PosteriorRegression.ambientSphereLaw (E := Vec d)) + infer_instance + · change IsProbabilityMeasure (stdGaussian (Vec d)) + infer_instance + +@[fun_prop] lemma measurable_baseDensity {d k : ℕ} (base : BaseLaw) : + Measurable (fun z : Rows d k × Labels k => baseDensity base z.1 z.2) := by + have hLI : MeasurableSet {z : Rows d k × Labels k | LinearIndependent ℝ z.1} := by + simp_rw [← Matrix.det_gram_ne_zero_iff_linearIndependent] + exact (measurableSet_eq_fun ((continuous_rowGram.comp continuous_fst).matrix_det.measurable) + measurable_const).compl + unfold baseDensity + apply Measurable.ite hLI + · cases base + · exact Measurable.ite (measurableSet_lt (by fun_prop) measurable_const) + (by fun_prop) measurable_const + · fun_prop + · exact measurable_const + +@[fun_prop] lemma measurable_projectedDensity {d k : ℕ} (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) : + Measurable (fun z : Rows d k × Labels k => projectedDensity base f z.1 z.2) := + (measurable_baseDensity base).mul (measurable_tiltMass base hf) + +lemma baseDensity_lt_top {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) : + baseDensity base A y < ∞ := by + cases base <;> dsimp only [baseDensity] <;> split_ifs <;> simp + +lemma baseDensity_spherical {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (y : Labels k) : baseDensity .spherical A y = sphericalPairingsDensity A y := by + simp only [baseDensity, ite_eq_left hA, sphericalPairingsDensity, + finrank_euclideanSpace, Fintype.card_fin] + rfl + +lemma base_lintegral {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (hk : k < d) (base : BaseLaw) {g : Vec d → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ x, g x ∂base.measure d = ∫⁻ y, baseDensity base A y * + ∫⁻ x, g x ∂baseFiber base A y := by + simp_rw [baseFiber_eq_map, lintegral_map hg (measurable_basePoint_fixed base A _)] + cases base + · change (∫⁻ x, g x ∂uniformDirection (Vec d)) = _ + rw [sphere_fiber_integral hA (by simpa using hk) hg] + apply lintegral_congr + intro y + rw [baseDensity_spherical hA] + congr 1 + apply lintegral_congr + intro x + congr 1 + simp only [basePoint, kernelComponent_eq_starProjection hA, normalDirection, + smul_smul, div_eq_mul_inv] + rfl + · change (∫⁻ x, g x ∂stdGaussian (Vec d)) = _ + rw [gaussian_fiber_integral hA hg] + apply lintegral_congr + intro y + rw [baseDensity, ite_eq_left hA] + congr 1 + rw [lintegral_map (by fun_prop) (by fun_prop)] + apply lintegral_congr + intro x + rw [basePoint, kernelComponent_eq_starProjection hA] + rfl + +lemma weighted_base_lintegral {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (hk : k < d) (base : BaseLaw) {f g : Vec d → ℝ≥0∞} (hf : Measurable f) + (hg : Measurable g) : + ∫⁻ x, g x ∂(base.measure d).withDensity f = + ∫⁻ y, baseDensity base A y * ∫⁻ x, f x * g x ∂baseFiber base A y := by + rw [lintegral_withDensity_eq_lintegral_mul _ hf hg] + exact base_lintegral hA hk base (hf.mul hg) + +lemma tiltMass_le {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} {L : ℝ≥0∞} + (hL : ∀ x, f x ≤ L) (A : Rows d k) (y : Labels k) : tiltMass base f A y ≤ L := by + unfold tiltMass + calc + _ ≤ ∫⁻ _, L ∂baseFiber base A y := lintegral_mono hL + _ = L := by simp + +lemma tiltMass_ne_top {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} {L : ℝ≥0∞} + (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) (A : Rows d k) (y : Labels k) : + tiltMass base f A y ≠ ∞ := ne_top_of_le_ne_top hL (tiltMass_le base hfL A y) + +lemma projectedDensity_ne_top {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} + {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) (A : Rows d k) (y : Labels k) : + projectedDensity base f A y ≠ ∞ := + ENNReal.mul_ne_top (baseDensity_lt_top base A y).ne (tiltMass_ne_top base hL hfL A y) + +lemma weighted_fiber_labels {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (base : BaseLaw) (y : Labels k) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {g : Labels k → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ x, f x * g (labels A x) ∂baseFiber base A y = tiltMass base f A y * g y := by + have hfg : Measurable (fun x => f x * g (labels A x)) := by fun_prop + rw [baseFiber_eq_map, lintegral_map hfg (measurable_basePoint_fixed base A y)] + simp_rw [labels_basePoint hA] + rw [lintegral_mul_const _ (show Measurable (fun x => f (basePoint base A y x)) from + hf.comp (measurable_basePoint_fixed base A y))] + congr 1 + rw [tiltMass, baseFiber_eq_map, lintegral_map hf (measurable_basePoint_fixed base A y)] + +lemma projected_measure {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (hk : k < d) (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) : + ((base.measure d).withDensity f).map (labels A) = + volume.withDensity (projectedDensity base f A) := by + have hl : Measurable (labels A) := by unfold labels; fun_prop + have hp0 := (measurable_projectedDensity (d := d) (k := k) base hf).comp + (show Measurable (fun y : Labels k => (A,y)) from measurable_const.prodMk measurable_id) + simp only [Function.comp_def] at hp0 + have hp : Measurable (projectedDensity base f A) := hp0 + apply Measure.ext_of_lintegral + intro g hg + rw [lintegral_map hg hl] + rw [weighted_base_lintegral hA hk base hf (g := fun x => g (labels A x)) (hg.comp hl)] + rw [lintegral_withDensity_eq_lintegral_mul _ hp hg] + simp only [Pi.mul_apply, weighted_fiber_labels hA base _ hf hg, projectedDensity, mul_assoc] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/ConstrainedDensityExpectation.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/ConstrainedDensityExpectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..47962d57fdecaca5679e882e354833e6dd4bb711 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/ConstrainedDensityExpectation.lean @@ -0,0 +1,114 @@ +import OAI.Probability.PosteriorReplicas.Geometry.InverseMomentBins +import OAI.Probability.PosteriorReplicas.Geometry.SphereTubeQuantitative +import OAI.Probability.PosteriorReplicas.Measures.EqualLabelVersions + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter Metric +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma volume_labels_smul {k : ℕ} {r : ℝ} (hr : 0 < r) : + (volume : Measure (Labels k)).map (fun x => r • x) = + ENNReal.ofReal (r⁻¹^k) • (volume : Measure (Labels k)) := by + have he : (fun x : Labels k => r • x) = Matrix.toLin' (r • (1 : Matrix (Fin k) (Fin k) ℝ)) := by + funext x + simp + rw [he, Real.map_matrix_volume_pi_eq_smul_volume_pi (by simp [hr.ne'])] + simp [inv_pow, abs_of_pos hr] + +lemma gaussian_rows_inner_le_volume {d k : ℕ} {v : Vec d} (hv : v ≠ 0) : + (gaussianRows d k).map (fun A => fun i => ⟪v, A i⟫) ≤ + ENNReal.ofReal (‖v‖⁻¹^k) • (volume : Measure (Labels k)) := by + rw [gaussianRows, PosteriorRegression.rows_inner_map] + calc + _ ≤ (volume : Measure (Labels k)).map (fun x => ‖v‖ • x) := + Measure.map_mono (PosteriorRegression.pi_gaussianReal_le_volume k) (by fun_prop) + _ = _ := volume_labels_smul (norm_pos_iff.mpr hv) + +lemma projected_rows_ball_bound {d k : ℕ} (U : Submodule ℝ (Vec d)) (p x : Vec d) + (hx : U.starProjection (x-p) ≠ 0) (r : ℝ) : + gaussianRows d k {A | labelNorm (labels (fun i => U.starProjection (A i)) x - + labels (fun i => U.starProjection (A i)) p) < r} ≤ + ENNReal.ofReal (‖U.starProjection (x-p)‖⁻¹^k) * + volume {y : Labels k | labelNorm y < r} := by + have hl (A : Rows d k) : + labels (fun i => U.starProjection (A i)) x - labels (fun i => U.starProjection (A i)) p = + fun i => ⟪U.starProjection (x-p), A i⟫ := by + ext i + change ⟪U.starProjection (A i), x⟫ - ⟪U.starProjection (A i), p⟫ = _ + rw [← inner_sub_right, U.inner_starProjection_left_eq_right, real_inner_comm] + simp_rw [hl] + have h := gaussian_rows_inner_le_volume (k := k) hx {y : Labels k | labelNorm y < r} + rw [Measure.map_apply (by fun_prop) (measurableSet_lt (by fun_prop) measurable_const), + Measure.smul_apply, smul_eq_mul] at h + exact h + +lemma label_ball_pos {k : ℕ} {r : ℝ} (hr : 0 < r) : + 0 < (volume : Measure (Labels k)) {y | labelNorm y < r} := by + rw [← euclidean_label_ball_volume (0 : Labels k) r] + exact (isOpen_ball.measure_pos volume) (⟨0, mem_ball_self hr⟩) + +lemma label_ball_ne_top {k : ℕ} (r : ℝ) : + (volume : Measure (Labels k)) {y | labelNorm y < r} ≠ ∞ := by + have he := euclidean_label_ball_volume (0 : Labels k) r + rw [← he] + exact (measure_ball_lt_top).ne + +lemma expected_ballDensityVersion_le {d k : ℕ} (ν : Measure (Vec d)) [IsFiniteMeasure ν] + (U : Submodule ℝ (Vec d)) (p : Vec d) + (hnull : ∀ᵐ x ∂ν, U.starProjection (x-p) ≠ 0) : + (∫⁻ A, ballDensityVersion ν (fun i => U.starProjection (A i)) + (labels (fun i => U.starProjection (A i)) p) ∂gaussianRows d k) ≤ + ∫⁻ x, ENNReal.ofReal (‖U.starProjection (x-p)‖⁻¹^k) ∂ν := by + let f : ℕ → Rows d k → ℝ≥0∞ := fun n A => + ((volume : Measure (Labels k)) {y | labelNorm y < (n+1:ℝ)⁻¹})⁻¹ * + ν {x | labelNorm (labels (fun i => U.starProjection (A i)) x - + labels (fun i => U.starProjection (A i)) p) < (n+1:ℝ)⁻¹} + have hf (n : ℕ) : Measurable (f n) := by + apply Measurable.const_mul + exact measurable_measure_prodMk_left (show MeasurableSet + {z : Rows d k × Vec d | labelNorm (labels (fun i => U.starProjection (z.1 i)) z.2 - + labels (fun i => U.starProjection (z.1 i)) p) < (n+1:ℝ)⁻¹} by + apply measurableSet_lt _ measurable_const + exact continuous_labelNorm.measurable.comp (by fun_prop)) + change (∫⁻ A, liminf (fun n => f n A) atTop ∂gaussianRows d k) ≤ _ + apply (lintegral_liminf_le hf).trans + apply liminf_le_of_frequently_le (hu_le := by isBoundedDefault) + apply Filter.Eventually.frequently + apply Filter.Eventually.of_forall + intro n + let r : ℝ := (n+1:ℝ)⁻¹ + have hr : 0 < r := by dsimp [r]; positivity + let S : Set (Rows d k × Vec d) := {z | labelNorm (labels (fun i => U.starProjection (z.1 i)) z.2 - + labels (fun i => U.starProjection (z.1 i)) p) < r} + have hS : MeasurableSet S := by + apply measurableSet_lt _ measurable_const + exact continuous_labelNorm.measurable.comp (by fun_prop) + have hs : (∫⁻ A, ν {x | (A,x) ∈ S} ∂gaussianRows d k) = + ∫⁻ x, gaussianRows d k {A | (A,x) ∈ S} ∂ν := by + exact (Measure.prod_apply (μ := gaussianRows d k) (ν := ν) hS).symm.trans + (Measure.prod_apply_symm (μ := gaussianRows d k) (ν := ν) hS) + calc + _ = ((volume : Measure (Labels k)) {y | labelNorm y < r})⁻¹ * + ∫⁻ x, gaussianRows d k {A | (A,x) ∈ S} ∂ν := by + rw [← hs] + change (∫⁻ A, ((volume : Measure (Labels k)) {y | labelNorm y < r})⁻¹ * + ν (Prod.mk A ⁻¹' S) ∂gaussianRows d k) = _ + exact lintegral_const_mul _ (measurable_measure_prodMk_left hS) + _ ≤ ((volume : Measure (Labels k)) {y | labelNorm y < r})⁻¹ * + ∫⁻ x, ENNReal.ofReal (‖U.starProjection (x-p)‖⁻¹^k) * + volume {y : Labels k | labelNorm y < r} ∂ν := by + apply mul_le_mul' le_rfl + apply lintegral_mono_ae + filter_upwards [hnull] with x hx + exact projected_rows_ball_bound U p x hx r + _ = _ := by + rw [lintegral_mul_const _ (by fun_prop), mul_comm (∫⁻ x, _ ∂ν), ← mul_assoc, + ENNReal.inv_mul_cancel (label_ball_pos hr).ne' (label_ball_ne_top r), one_mul] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/DensityDifferentiation.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/DensityDifferentiation.lean new file mode 100644 index 0000000000000000000000000000000000000000..8614319af242a6790026fa8d7bd794763fc11534 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/DensityDifferentiation.lean @@ -0,0 +1,70 @@ +import OAI.Probability.PosteriorReplicas.Measures.EqualLabelTransfer + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Metric +open scoped ENNReal NNReal Topology +noncomputable section +namespace PosteriorReplicas + +@[fun_prop] lemma continuous_labelNorm {k : ℕ} : Continuous (@labelNorm k) := by + unfold labelNorm + fun_prop + +@[fun_prop] lemma measurable_ballDensityVersion {d k : ℕ} (ν : Measure (Vec d)) [SFinite ν] : + Measurable (fun z : Rows d k × Labels k => ballDensityVersion ν z.1 z.2) := by + unfold ballDensityVersion + apply Measurable.liminf + intro n + apply Measurable.const_mul + exact measurable_measure_prodMk_left (show MeasurableSet + {z : (Rows d k × Labels k) × Vec d | + labelNorm (labels z.1.1 z.2 - z.1.2) < (n + 1 : ℝ)⁻¹} from + measurableSet_lt (continuous_labelNorm.measurable.comp (by fun_prop)) measurable_const) + +@[fun_prop] lemma measurable_gaussianDensityVersion {d k : ℕ} (ν : Measure (Vec d)) [SFinite ν] : + Measurable (fun z : Rows d k × Labels k => gaussianDensityVersion ν z.1 z.2) := by + unfold gaussianDensityVersion + apply Measurable.liminf + intro n + apply Measurable.lintegral_prod_right + apply ENNReal.measurable_ofReal.comp + fun_prop + +section Generic +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] + +lemma closedBall_ae_eq_ball (μ : Measure E) (hμ : μ ≪ volume) (y : E) (r : ℝ) : + closedBall y r =ᵐ[μ] ball y r := by + rw [ae_eq_set, closedBall_sdiff_ball, sdiff_eq_empty.mpr ball_subset_closedBall, measure_empty] + exact ⟨hμ (Measure.addHaar_sphere volume y r), rfl⟩ + +lemma ae_ball_differentiation {μ : Measure E} [IsFiniteMeasure μ] {h : E → ℝ≥0∞} + (hh : Measurable h) (hμ : μ = volume.withDensity h) : + ∀ᵐ y ∂(volume : Measure E), + Tendsto (fun r => μ (ball y r) / volume (ball y r)) (𝓝[>] 0) (𝓝 (h y)) := by + have hac : μ ≪ volume := by rw [hμ]; exact withDensity_absolutelyContinuous _ _ + have hrn : μ.rnDeriv volume =ᵐ[volume] h := by + rw [hμ] + exact Measure.rnDeriv_withDensity volume hh + filter_upwards [Besicovitch.ae_tendsto_rnDeriv μ volume, hrn] with y hy hry + rw [hry] at hy + convert hy using 1 + ext r + rw [(closedBall_ae_eq_ball μ hac y r).measure_eq, + (closedBall_ae_eq_ball volume (Measure.AbsolutelyContinuous.refl _) y r).measure_eq] + +omit [Nontrivial E] in +lemma bounded_density_measure_le [Nontrivial E] {μ : Measure E} {h : E → ℝ≥0∞} + (hμ : μ = volume.withDensity h) {M : ℝ≥0∞} (hM : ∀ x, h x ≤ M) + (s : Set E) (hs : MeasurableSet s) : μ s ≤ M * volume s := by + rw [hμ, withDensity_apply _ hs] + simpa using lintegral_mono (μ := volume.restrict s) hM + +end Generic + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/DensityTools.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/DensityTools.lean new file mode 100644 index 0000000000000000000000000000000000000000..04ee1534d4d7394fc783c39c77664520f91c9987 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/DensityTools.lean @@ -0,0 +1,96 @@ +import Mathlib + +namespace OAI + +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma map_withDensity_comp {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + (μ : Measure α) {T : α → β} (hT : Measurable T) {f : β → ℝ≥0∞} (hf : Measurable f) : + (μ.withDensity (f ∘ T)).map T = (μ.map T).withDensity f := by + apply Measure.ext_of_lintegral + intro g hg + rw [lintegral_map hg hT, + lintegral_withDensity_eq_lintegral_mul _ (hf.comp hT) + (show Measurable (fun a => g (T a)) from hg.comp hT), + lintegral_withDensity_eq_lintegral_mul _ hf hg, + lintegral_map (hf.mul hg) hT] + rfl + +lemma map_withDensity_equiv {α β : Type*} [MeasurableSpace α] [MeasurableSpace β] + (μ : Measure α) (e : α ≃ᵐ β) {f : α → ℝ≥0∞} (hf : Measurable f) : + (μ.withDensity f).map e = (μ.map e).withDensity (fun y => f (e.symm y)) := by + apply Measure.ext_of_lintegral + intro g hg + rw [lintegral_map hg e.measurable, + lintegral_withDensity_eq_lintegral_mul _ hf (show Measurable (fun a => g (e a)) from hg.comp e.measurable), + lintegral_withDensity_eq_lintegral_mul _ (show Measurable (fun y => f (e.symm y)) from hf.comp e.symm.measurable) hg] + simp only [Pi.mul_apply] + rw [lintegral_map (show Measurable (fun y => f (e.symm y) * g y) from (hf.comp e.symm.measurable).mul hg) e.measurable] + simp + +lemma lintegral_fin_prod {n : ℕ} {E : Fin n → Type*} + [∀ i, MeasurableSpace (E i)] (μ : (i : Fin n) → Measure (E i)) + [∀ i, SigmaFinite (μ i)] (f : (i : Fin n) → E i → ℝ≥0∞) + (hf : ∀ i, Measurable (f i)) : + ∫⁻ x, ∏ i, f i (x i) ∂Measure.pi μ = ∏ i, ∫⁻ x, f i x ∂μ i := by + induction n with + | zero => simp + | succ n ih => + calc + _ = ∫⁻ x : E 0 × ((i : Fin n) → E i.succ), + f 0 x.1 * ∏ i, f i.succ (x.2 i) + ∂((μ 0).prod (Measure.pi (fun i => μ i.succ))) := by + rw [← ((measurePreserving_piFinSuccAbove μ 0).symm).lintegral_comp + (by exact Finset.measurable_prod _ (fun i _ => (hf i).comp (measurable_pi_apply i)))] + simp only [Fin.prod_univ_succ, Fin.zero_succAbove] + rfl + _ = (∫⁻ x, f 0 x ∂μ 0) * ∏ i : Fin n, ∫⁻ x, f i.succ x ∂μ i.succ := by + have hg : Measurable (fun x : (i : Fin n) → E i.succ => ∏ i, f i.succ (x i)) := + Finset.measurable_prod _ (fun i _ => (hf i.succ).comp (measurable_pi_apply i)) + rw [lintegral_prod_mul (hf 0).aemeasurable hg.aemeasurable, + ih _ _ (fun i => hf i.succ)] + _ = _ := by rw [Fin.prod_univ_succ] + +lemma lintegral_finite_prod {ι : Type*} [Fintype ι] {E : ι → Type*} + [∀ i, MeasurableSpace (E i)] (μ : (i : ι) → Measure (E i)) + [∀ i, SigmaFinite (μ i)] (f : (i : ι) → E i → ℝ≥0∞) + (hf : ∀ i, Measurable (f i)) : + ∫⁻ x, ∏ i, f i (x i) ∂Measure.pi μ = ∏ i, ∫⁻ x, f i x ∂μ i := by + let e := (Fintype.equivFin ι).symm + rw [← (measurePreserving_piCongrLeft _ e).lintegral_comp + (show Measurable (fun x => ∏ i, f i (x i)) from Finset.measurable_prod _ (fun i _ => (hf i).comp (measurable_pi_apply i)))] + simp_rw [← e.prod_comp, MeasurableEquiv.coe_piCongrLeft, Equiv.piCongrLeft_apply_apply] + exact lintegral_fin_prod _ _ (fun i => hf (e i)) + +lemma pi_withDensity {ι : Type*} [Fintype ι] {X : ι → Type*} + [∀ i, MeasurableSpace (X i)] (μ : ∀ i, Measure (X i)) [∀ i, SigmaFinite (μ i)] + (f : ∀ i, X i → ℝ≥0∞) (hf : ∀ i, Measurable (f i)) + [∀ i, SigmaFinite ((μ i).withDensity (f i))] : + Measure.pi (fun i => (μ i).withDensity (f i)) = + (Measure.pi μ).withDensity (fun x => ∏ i, f i (x i)) := by + apply Measure.pi_eq + intro s hs + rw [withDensity_apply _ (MeasurableSet.univ_pi hs), Measure.restrict_pi_pi] + rw [lintegral_finite_prod _ _ hf] + congr 1 + ext i + rw [withDensity_apply _ (hs i)] + +lemma pi_gaussian_density (n : ℕ) : + Measure.pi (fun _ : Fin n => gaussianReal 0 1) = + (volume : Measure (Fin n → ℝ)).withDensity (fun x => ∏ i, gaussianPDF 0 1 (x i)) := by + have h : gaussianReal 0 1 = (volume : Measure ℝ).withDensity (gaussianPDF 0 1) := + gaussianReal_of_var_ne_zero _ (by norm_num) + have : IsProbabilityMeasure ((volume : Measure ℝ).withDensity (gaussianPDF 0 1)) := by + rw [← h] + infer_instance + rw [h] + exact pi_withDensity _ _ (fun _ => measurable_gaussianPDF _ _) + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/EqualApproximation.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualApproximation.lean new file mode 100644 index 0000000000000000000000000000000000000000..1fa6525bb0cc6f2bf0f90c114178e31da83bcb43 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualApproximation.lean @@ -0,0 +1,183 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.MatrixNoise +import OAI.Probability.PosteriorReplicas.Measures.EqualBaseMeasures + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +def equalApprox {d k m : ℕ} (base : BaseLaw) (n : ℕ) + (H : EqualSpace d k m → ℝ≥0∞) : ℝ≥0∞ := + ∫⁻ A, ∫⁻ u : Tuple d m, + matrixNoiseDensity m k n (fun i => labels A (u i.succ) - labels A (u 0)) * + H (A, labels A (u 0), u) ∂Measure.pi (fun _ => base.measure d) ∂gaussianRows d k + +def smoothedTail {d k m : ℕ} (base : BaseLaw) (n : ℕ) + (H : EqualSpace d k m → ℝ≥0∞) (A : Rows d k) (p : Vec d) : ℝ≥0∞ := + ∫⁻ v : Fin m → Vec d, matrixNoiseDensity m k n (fun i => labels A (v i) - labels A p) * + H (A, labels A p, Fin.cons p v) ∂Measure.pi (fun _ => base.measure d) + +lemma equalApprox_cons {d k m : ℕ} [NeZero d] (base : BaseLaw) (n : ℕ) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + equalApprox base n H = ∫⁻ A, ∫⁻ p, smoothedTail base n H A p + ∂base.measure d ∂gaussianRows d k := by + unfold equalApprox smoothedTail + apply lintegral_congr + intro A + rw [lintegral_pi_cons (base.measure d) (by fun_prop)] + simp only [Fin.cons_succ, Fin.cons_zero] + +lemma smoothedTail_representation {d k m : ℕ} {A : Rows d k} + (hA : LinearIndependent ℝ A) (hk : k < d) (base : BaseLaw) (n : ℕ) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) (p : Vec d) : + smoothedTail base n H A p = + ∫⁻ z, ∫⁻ R, (∏ i, baseDensity base A (labels A p + noiseScale n • z i)) * + H (A, labels A p, Fin.cons p + (fun i => basePoint base A (labels A p + noiseScale n • z i) (R i))) + ∂gaussianRows d m ∂matrixNormal m k := by + unfold smoothedTail + rw [base_pi_lintegral hA hk base (by fun_prop)] + simp_rw [labels_basePoint hA] + have hrw (y : Fin m → Labels k) : + (∏ i, baseDensity base A (y i)) * + (∫⁻ R, matrixNoiseDensity m k n (fun i => y i - labels A p) * + H (A, labels A p, Fin.cons p (fun i => basePoint base A (y i) (R i))) + ∂gaussianRows d m) = + matrixNoiseDensity m k n (y - fun _ => labels A p) * + ((∏ i, baseDensity base A (y i)) * + ∫⁻ R, H (A, labels A p, Fin.cons p (fun i => basePoint base A (y i) (R i))) + ∂gaussianRows d m) := by + rw [lintegral_const_mul _ (by fun_prop)] + ac_rfl + simp_rw [hrw] + rw [matrixNoise_convolution (fun _ => labels A p) (by fun_prop)] + apply lintegral_congr + intro z + rw [lintegral_const_mul _ (by fun_prop)] + rfl + +lemma smoothedTail_bound {d k m : ℕ} {A : Rows d k} + (hA : LinearIndependent ℝ A) (hk : k + 2 < d) (base : BaseLaw) (n : ℕ) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) + (b : ℝ≥0∞) (hHb : ∀ x, H x ≤ b) (p : Vec d) : + smoothedTail base n H A p ≤ + ENNReal.ofReal (baseProjectionConstant base d k / Real.sqrt (rowGram A).det)^m * b := by + rw [smoothedTail_representation hA (by omega) base n hH p] + calc + _ ≤ ∫⁻ z, ∫⁻ R, ENNReal.ofReal + (baseProjectionConstant base d k / Real.sqrt (rowGram A).det)^m * b + ∂gaussianRows d m ∂matrixNormal m k := by + apply lintegral_mono + intro z + apply lintegral_mono + intro R + apply mul_le_mul' _ (hHb _) + simpa using Finset.prod_le_prod (fun i (_ : i ∈ (Finset.univ : Finset (Fin m))) => + baseDensity_le_sup (by omega) base A (labels A p + noiseScale n • z i)) + _ = _ := by simp + +lemma smoothedTail_limit {d k m : ℕ} {A : Rows d k} + (hA : LinearIndependent ℝ A) (hk : k + 2 < d) (base : BaseLaw) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Continuous H) + (b : ℝ≥0∞) (hb : b ≠ ∞) (hHb : ∀ x, H x ≤ b) (p : Vec d) : + Tendsto (fun n => smoothedTail base n H A p) atTop + (nhds (baseDensity base A (labels A p)^m * + ∫⁻ R, H (A, labels A p, Fin.cons p + (fun i => basePoint base A (labels A p) (R i))) ∂gaussianRows d m)) := by + let B := ENNReal.ofReal (baseProjectionConstant base d k / Real.sqrt (rowGram A).det)^m * b + have hfin : B ≠ ∞ := ENNReal.mul_ne_top (by finiteness) hb + have hbound (n) (z : (Fin m → Labels k) × Rows d m) : + (∏ i, baseDensity base A (labels A p + noiseScale n • z.1 i)) * + H (A, labels A p, Fin.cons p + (fun i => basePoint base A (labels A p + noiseScale n • z.1 i) (z.2 i))) ≤ B := by + apply mul_le_mul' _ (hHb _) + simpa using Finset.prod_le_prod (fun i (_ : i ∈ (Finset.univ : Finset (Fin m))) => + baseDensity_le_sup (by omega) base A (labels A p + noiseScale n • z.1 i)) + have hlim := tendsto_lintegral_of_dominated_convergence + (μ := (matrixNormal m k).prod (gaussianRows d m)) (fun _ => B) + (F := fun n z => (∏ i, baseDensity base A (labels A p + noiseScale n • z.1 i)) * + H (A, labels A p, Fin.cons p + (fun i => basePoint base A (labels A p + noiseScale n • z.1 i) (z.2 i)))) + (f := fun z => baseDensity base A (labels A p)^m * + H (A, labels A p, Fin.cons p (fun i => basePoint base A (labels A p) (z.2 i)))) + (fun _ => by fun_prop) + (fun n => Filter.Eventually.of_forall (hbound n)) + (by simpa using hfin) + (by + apply Filter.Eventually.of_forall + intro z + have hy (i : Fin m) : Tendsto (fun n => labels A p + noiseScale n • z.1 i) atTop + (nhds (labels A p)) := by + simpa using tendsto_const_nhds.add (tendsto_noiseScale.smul_const (z.1 i)) + have hprod : Tendsto (fun n => ∏ i, baseDensity base A (labels A p + noiseScale n • z.1 i)) atTop + (nhds (baseDensity base A (labels A p)^m)) := by + simpa using ENNReal.tendsto_finsetProd_of_ne_top Finset.univ + (fun i _ => (continuous_baseDensity hk base hA).tendsto (labels A p) |>.comp (hy i)) + (fun i _ => (baseDensity_lt_top base A (labels A p)).ne) + apply ENNReal.Tendsto.mul hprod (Or.inr (ne_top_of_le_ne_top hb (hHb _))) + · apply hH.tendsto _ |>.comp + apply tendsto_const_nhds.prodMk_nhds + apply tendsto_const_nhds.prodMk_nhds + apply tendsto_const_nhds.finCons + apply tendsto_pi_nhds.mpr + intro i + exact (continuous_basePoint_label base A (z.2 i)).tendsto (labels A p) |>.comp (hy i) + · exact Or.inr (by finiteness [baseDensity_lt_top base A (labels A p)])) + have he (n) : smoothedTail base n H A p = + ∫⁻ z : (Fin m → Labels k) × Rows d m, + (∏ i, baseDensity base A (labels A p + noiseScale n • z.1 i)) * + H (A, labels A p, Fin.cons p + (fun i => basePoint base A (labels A p + noiseScale n • z.1 i) (z.2 i))) + ∂(matrixNormal m k).prod (gaussianRows d m) := by + rw [smoothedTail_representation hA (by omega) base n hH.measurable p, + lintegral_prod _ (by fun_prop)] + simp_rw [he] + convert hlim using 1 + rw [lintegral_prod _ (by fun_prop)] + simp only [lintegral_const, measure_univ, mul_one] + rw [lintegral_const_mul _ (show Measurable (fun R : Rows d m => + H (A, labels A p, Fin.cons p (fun i => basePoint base A (labels A p) (R i)))) by fun_prop)] + +lemma equalApprox_left_limit {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Continuous H) + (b : ℝ≥0∞) (hb : b ≠ ∞) (hHb : ∀ x, H x ≤ b) : + Tendsto (fun n => equalApprox base n H) atTop + (nhds (∫⁻ z, H z ∂leftBaseMeasure d k m base)) := by + have : NeZero d := ⟨by omega⟩ + have hAe : ∀ᵐ z ∂(gaussianRows d k).prod (base.measure d), LinearIndependent ℝ z.1 := + Measure.quasiMeasurePreserving_fst.ae (ae_gaussian_rows_full_rank (by omega) (by omega)) + have he (n) : equalApprox base n H = + ∫⁻ z : Rows d k × Vec d, smoothedTail base n H z.1 z.2 + ∂(gaussianRows d k).prod (base.measure d) := by + rw [equalApprox_cons base n hH.measurable, lintegral_prod _ (by unfold smoothedTail; fun_prop)] + simp_rw [he] + rw [leftBaseMeasure_lintegral base hH.measurable] + have hf_meas : Measurable (fun z : Rows d k × Vec d => + baseDensity base z.1 (labels z.1 z.2)^m * + ∫⁻ R, H (z.1, labels z.1 z.2, + Fin.cons z.2 (fun i => basePoint base z.1 (labels z.1 z.2) (R i))) + ∂gaussianRows d m) := by fun_prop + rw [← lintegral_prod _ hf_meas.aemeasurable] + apply tendsto_lintegral_of_dominated_convergence + (fun z : Rows d k × Vec d => + ENNReal.ofReal (baseProjectionConstant base d k / Real.sqrt (rowGram z.1).det)^m * b) + · intro n + unfold smoothedTail + fun_prop + · intro n + filter_upwards [hAe] with z hz + exact smoothedTail_bound hz (by omega) base n hH.measurable b hHb z.2 + · rw [lintegral_prod _ (by fun_prop)] + simp only [lintegral_const, measure_univ, mul_one] + rw [lintegral_mul_const _ (by fun_prop)] + exact ENNReal.mul_ne_top (base_density_sup_moment_finite hd hk base).ne hb + · filter_upwards [hAe] with z hz + exact smoothedTail_limit hz (by omega) base hH b hb hHb z.2 + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/EqualBaseMeasures.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualBaseMeasures.lean new file mode 100644 index 0000000000000000000000000000000000000000..6226ceab02bf257e4d0455483d876c5606cf8614 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualBaseMeasures.lean @@ -0,0 +1,121 @@ +import OAI.Probability.PosteriorReplicas.Geometry.TupleMoments +import OAI.Probability.PosteriorReplicas.Measures.ProductFibers + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +abbrev EqualSpace (d k m : ℕ) := Rows d k × Labels k × Tuple d m +abbrev LeftSource (d k m : ℕ) := Rows d k × Vec d × Rows d m + +def leftBaseSource (d k m : ℕ) (base : BaseLaw) : Measure (LeftSource d k m) := + (gaussianRows d k).prod ((base.measure d).prod (gaussianRows d m)) + +instance {d k m : ℕ} [NeZero d] (base : BaseLaw) : + IsProbabilityMeasure (leftBaseSource d k m base) := by + unfold leftBaseSource + infer_instance + +def leftBasePoint {d k m : ℕ} (base : BaseLaw) (z : LeftSource d k m) : EqualSpace d k m := + (z.1, labels z.1 z.2.1, + Fin.cons z.2.1 (fun i => basePoint base z.1 (labels z.1 z.2.1) (z.2.2 i))) + +def leftBaseWeight {d k m : ℕ} (base : BaseLaw) (z : LeftSource d k m) : ℝ≥0∞ := + baseDensity base z.1 (labels z.1 z.2.1) ^ m + +@[fun_prop] lemma measurable_leftBasePoint {d k m : ℕ} (base : BaseLaw) : + Measurable (@leftBasePoint d k m base) := by + unfold leftBasePoint + fun_prop + +@[fun_prop] lemma measurable_leftBaseWeight {d k m : ℕ} (base : BaseLaw) : + Measurable (@leftBaseWeight d k m base) := by + unfold leftBaseWeight + fun_prop + +def leftBaseMeasure (d k m : ℕ) (base : BaseLaw) : Measure (EqualSpace d k m) := + ((leftBaseSource d k m base).withDensity (leftBaseWeight base)).map (leftBasePoint base) + +lemma leftBaseWeight_integral_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) (hk : 1 ≤ k) + (base : BaseLaw) : (∫⁻ z, leftBaseWeight base z ∂leftBaseSource d k m base) < ∞ := by + let : NeZero d := ⟨by omega⟩ + have hb (z : LeftSource d k m) : leftBaseWeight base z ≤ + ENNReal.ofReal (baseProjectionConstant base d k / Real.sqrt (rowGram z.1).det)^m := + pow_le_pow_left' (baseDensity_le_sup (by omega) base _ _) _ + apply lt_of_le_of_lt (lintegral_mono hb) + unfold leftBaseSource + rw [lintegral_prod _ (by fun_prop)] + simp only [lintegral_const, measure_univ, mul_one] + exact base_density_sup_moment_finite hd hk base + +lemma leftBaseMeasure_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) (hk : 1 ≤ k) + (base : BaseLaw) : IsFiniteMeasure (leftBaseMeasure d k m base) := by + let := isFiniteMeasure_withDensity (leftBaseWeight_integral_finite hd hk base).ne + unfold leftBaseMeasure + infer_instance + +lemma leftBaseMeasure_lintegral {d k m : ℕ} (base : BaseLaw) [NeZero d] + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + ∫⁻ z, H z ∂leftBaseMeasure d k m base = + ∫⁻ A, ∫⁻ p, baseDensity base A (labels A p)^m * + ∫⁻ R, H (A, labels A p, Fin.cons p + (fun i => basePoint base A (labels A p) (R i))) ∂gaussianRows d m + ∂base.measure d ∂gaussianRows d k := by + rw [leftBaseMeasure, lintegral_map hH (measurable_leftBasePoint base), + lintegral_withDensity_eq_lintegral_mul _ (measurable_leftBaseWeight base) + (show Measurable (fun z => H (leftBasePoint base z)) from hH.comp (measurable_leftBasePoint base))] + change (∫⁻ z, leftBaseWeight base z * H (leftBasePoint base z) ∂leftBaseSource d k m base) = _ + unfold leftBaseSource leftBaseWeight leftBasePoint + rw [lintegral_prod _ (by fun_prop)] + apply lintegral_congr + intro A + rw [lintegral_prod _ (by fun_prop)] + apply lintegral_congr + intro p + dsimp only [Prod.fst, Prod.snd] + rw [lintegral_const_mul _ (by fun_prop)] + +lemma leftBaseMeasure_lintegral_fibers {d k m : ℕ} (hd : 3 ≤ d) (hk : k < d) + (base : BaseLaw) {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + ∫⁻ z, H z ∂leftBaseMeasure d k m base = + ∫⁻ A, ∫⁻ y, baseDensity base A y^(m+1) * + ∫⁻ u, H (A,y,u) ∂Measure.pi (fun _ : Fin (m+1) => baseFiber base A y) + ∂volume ∂gaussianRows d k := by + let : NeZero d := ⟨by omega⟩ + rw [leftBaseMeasure_lintegral base hH] + apply lintegral_congr_ae + filter_upwards [ae_gaussian_rows_full_rank hd hk] with A hA + rw [base_lintegral hA hk base (by fun_prop)] + apply lintegral_congr + intro y + conv_lhs => rw [baseFiber_eq_map, + lintegral_map (by fun_prop) (measurable_basePoint_fixed base A y)] + simp_rw [labels_basePoint hA] + rw [lintegral_const_mul _ (by fun_prop)] + rw [lintegral_pi_cons (baseFiber base A y) (by fun_prop)] + have hpi (p : Vec d) := baseFiber_pi_lintegral base A y + (g := fun v : Fin m → Vec d => H (A,y,Fin.cons p v)) (by fun_prop) + simp_rw [hpi] + rw [baseFiber_eq_map, lintegral_map (by fun_prop) (measurable_basePoint_fixed base A y)] + rw [← mul_assoc, ← pow_succ'] + +@[simp] lemma tiltMass_one {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) : + tiltMass base (fun _ => 1) A y = 1 := by simp [tiltMass] + +@[simp] lemma tiltedFiber_one {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) : + tiltedFiber base (fun _ => 1) A y = baseFiber base A y := by + simp [tiltedFiber] + +lemma leftBaseMeasure_eq_equalLabelLeft {d k m : ℕ} (hd : 3 ≤ d) (hk : k < d) + (base : BaseLaw) {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + ∫⁻ z, H z ∂leftBaseMeasure d k m base = equalLabelLeft base (fun _ => 1) H := by + rw [leftBaseMeasure_lintegral_fibers hd hk base hH] + simp only [equalLabelLeft, projectedDensity, tiltMass_one, mul_one, tiltedFiber_one] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelIdentity.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelIdentity.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f8dc47db179422b962a3385be1cdaa5b1c9f7f2 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelIdentity.lean @@ -0,0 +1,64 @@ +import OAI.Probability.PosteriorReplicas.Measures.EqualRightMeasure +import OAI.Probability.PosteriorReplicas.Measures.TiltNormalization + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal Topology BoundedContinuousFunction +noncomputable section +namespace PosteriorReplicas + +lemma equal_base_measures {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) : + leftBaseMeasure d k m base = rightBaseMeasure d k m base := by + have := leftBaseMeasure_finite hd hk base + apply ext_of_forall_lintegral_eq_of_IsFiniteMeasure + intro H + have hc : Continuous (fun z => (H z : ℝ≥0∞)) := ENNReal.continuous_coe.comp H.continuous + have hb : ∀ z, (H z : ℝ≥0∞) ≤ (nndist 0 H : ℝ≥0∞) := + fun z => ENNReal.coe_le_coe.mpr (H.apply_le_nndist_zero z) + exact tendsto_nhds_unique + (equalApprox_left_limit hd hk hm base hc _ ENNReal.coe_ne_top hb) + (equalApprox_right_limit hd hk hm base hc _ ENNReal.coe_ne_top hb) + +lemma equal_label_base_identity {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + equalLabelLeft base (fun _ => 1) H = equalLabelRight base (fun _ => 1) H := by + rw [← leftBaseMeasure_eq_equalLabelLeft (by omega) (by omega) base hH, + equal_base_measures hd hk hm base, + rightBaseMeasure_eq_equalLabelRight (by omega) (by omega) base hH] + +lemma equal_label_tilt_identity {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + equalLabelLeft base f H = equalLabelRight base f H := by + have : NeZero d := ⟨by omega⟩ + rw [equalLabelLeft_tilt base hf hL hfL hH, equalLabelRight_tilt base hf hL hfL hH] + exact equal_label_base_identity hd hk hm base (by fun_prop) + +lemma equal_label_tilt_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + equalLabelLeft (k := k) (m := m) base f (fun _ => 1) < ∞ := by + have := leftBaseMeasure_finite hd hk base + rw [equalLabelLeft_tilt base hf hL hfL measurable_const, + ← leftBaseMeasure_eq_equalLabelLeft (by omega) (by omega) base (by fun_prop)] + apply lt_of_le_of_lt (lintegral_mono (g := fun _ => L^(m+1)) ?_) + (by simpa using ENNReal.mul_lt_top (ENNReal.pow_lt_top (lt_top_iff_ne_top.mpr hL)) (measure_lt_top _ univ)) + intro z + simp only [mul_one] + simpa using Finset.prod_le_prod (fun i (_ : i ∈ (Finset.univ : Finset (Fin (m+1)))) => hfL (z.2.2 i)) + +theorem equalLabelMeasureIdentity : EqualLabelMeasureIdentity := by + intro d k m hk hm hd base f hf hbounded + obtain ⟨L,hL,hfL⟩ := hbounded + have hdim : k + m + 2 ≤ d := by omega + exact ⟨equal_label_tilt_finite hdim hk hm base hf hL hfL, + fun H hH => equal_label_tilt_identity hdim hk hm base hf hL hfL hH⟩ + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelTransfer.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..c2fa14ebfb9b2e64090917c907f2f7d3ce7ea546 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelTransfer.lean @@ -0,0 +1,158 @@ +import OAI.Probability.PosteriorReplicas.Measures.EqualLabelIdentity + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma equalConstant_pos (k m : ℕ) : 0 < equalConstant k m := by + unfold equalConstant + exact ENNReal.ofReal_pos.mpr (Real.rpow_pos_of_pos (by positivity) _) + +lemma ae_tilt_tuple_full_rank {d m : ℕ} (hd : 3 ≤ d) (hm : m < d) (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + ∀ᵐ u : Tuple d m ∂Measure.pi (fun _ => (base.measure d).withDensity f), + LinearIndependent ℝ (differences u) := by + have : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hL hfL + rw [pi_withDensity _ _ (fun _ => hf)] + apply (ae_withDensity_iff (by fun_prop)).mpr + filter_upwards [ae_base_tuple_full_rank hd hm base] with u hu + exact fun _ => hu + +lemma equalLabelRight_residual {d k m : ℕ} (hd : 3 ≤ d) (hm : m < d) (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + equalLabelRight base f H = equalConstant k m * + ∫⁻ u : Tuple d m, (ENNReal.ofReal (affineVolume u))⁻¹ ^ k * + ∫⁻ A, H (residualRows u A, labels (residualRows u A) (u 0), u) ∂gaussianRows d k + ∂Measure.pi (fun _ => (base.measure d).withDensity f) := by + unfold equalLabelRight equalConstant + congr 1 + apply lintegral_congr_ae + filter_upwards [ae_tilt_tuple_full_rank hd hm base hf hL hfL] with u hu + rw [constrainedRows_eq_residualRows hu, lintegral_map (by fun_prop) (by unfold residualRows; fun_prop)] + +lemma equal_label_transfer {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {g : Rows d k × Labels k → ℝ≥0∞} (hg : Measurable g) + (hzero : ∀ A, LinearIndependent ℝ A → ∀ᵐ y ∂volume, + 0 < projectedDensity base f A y → g (A,y) = 0) : + ∀ᵐ u : Tuple d m ∂Measure.pi (fun _ => (base.measure d).withDensity f), + ∀ᵐ A ∂constrainedRows k u, g (A, labels A (u 0)) = 0 := by + have : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hL hfL + have he : equalLabelLeft (m := m) base f (fun z => g (z.1,z.2.1)) = 0 := by + unfold equalLabelLeft + apply lintegral_eq_zero_of_ae_eq_zero + filter_upwards [ae_gaussian_rows_full_rank (by omega : 3 ≤ d) (by omega : k < d)] with A hA + apply lintegral_eq_zero_of_ae_eq_zero + filter_upwards [hzero A hA] with y hy + by_cases hp : projectedDensity base f A y = 0 + · simp [hp] + · simp [hy (pos_iff_ne_zero.mpr hp)] + rw [equal_label_tilt_identity hd hk hm base hf hL hfL (by fun_prop), + equalLabelRight_residual (by omega) (by omega) base hf hL hfL (by fun_prop)] at he + have hint : (∫⁻ u : Tuple d m, (ENNReal.ofReal (affineVolume u))⁻¹ ^ k * + ∫⁻ A, g (residualRows u A, labels (residualRows u A) (u 0)) ∂gaussianRows d k + ∂Measure.pi (fun _ => (base.measure d).withDensity f)) = 0 := + (mul_eq_zero.mp he).resolve_left (equalConstant_pos k m).ne' + have hzg := (lintegral_eq_zero_iff (show Measurable (fun u : Tuple d m => + (ENNReal.ofReal (affineVolume u))⁻¹ ^ k * + ∫⁻ A, g (residualRows u A, labels (residualRows u A) (u 0)) ∂gaussianRows d k) by + unfold residualRows; fun_prop)).mp hint + filter_upwards [hzg, ae_tilt_tuple_full_rank (by omega : 3 ≤ d) (by omega : m < d) base hf hL hfL] + with u hgu hu + have hinn : (∫⁻ A, g (residualRows u A, labels (residualRows u A) (u 0)) ∂gaussianRows d k) = 0 := + (mul_eq_zero.mp hgu).resolve_left + (pow_ne_zero _ (ENNReal.inv_ne_zero.mpr ENNReal.ofReal_ne_top)) + rw [constrainedRows_eq_residualRows hu] + apply (ae_map_iff ((show Measurable (residualRows u) by unfold residualRows; fun_prop).aemeasurable) + (measurableSet_eq_fun (by fun_prop) measurable_const)).mpr + exact (lintegral_eq_zero_iff (by unfold residualRows; fun_prop)).mp hinn + +lemma equal_label_transfer_prop {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {P : Rows d k → Labels k → Prop} (hP : MeasurableSet {z : Rows d k × Labels k | P z.1 z.2}) + (hgood : ∀ A, LinearIndependent ℝ A → ∀ᵐ y ∂volume, + 0 < projectedDensity base f A y → P A y) : + ∀ᵐ u : Tuple d m ∂Measure.pi (fun _ => (base.measure d).withDensity f), + ∀ᵐ A ∂constrainedRows k u, P A (labels A (u 0)) := by + classical + let g : Rows d k × Labels k → ℝ≥0∞ := fun z => if P z.1 z.2 then 0 else 1 + have hg : Measurable g := Measurable.ite hP measurable_const measurable_const + have h := equal_label_transfer hd hk hm base hf hL hfL hg (by + intro A hA + filter_upwards [hgood A hA] with y hy + intro hp + simp [g, hy hp]) + filter_upwards [h] with u hu + filter_upwards [hu] with A hA + by_contra hp + simp [g, hp] at hA + +lemma residualRows_equal_labels {d k m : ℕ} {u : Tuple d m} + (hu : LinearIndependent ℝ (differences u)) (R : Rows d k) (i : Fin (m+1)) : + labels (residualRows u R) (u i) = labels (residualRows u R) (u 0) := by + refine Fin.cases rfl (fun i => ?_) i + ext j + have h := congrFun (labels_kernelComponent hu (R j)) i + change ⟪differences u i, kernelComponent (differences u) (R j)⟫ = 0 at h + rw [real_inner_comm, differences, inner_sub_right] at h + exact sub_eq_zero.mp h + +lemma ae_constrained_equal_labels {d k m : ℕ} {u : Tuple d m} + (hu : LinearIndependent ℝ (differences u)) : + ∀ᵐ A ∂constrainedRows k u, ∀ i, labels A (u i) = labels A (u 0) := by + rw [constrainedRows_eq_residualRows hu] + have hp : Measurable (fun A : Rows d k => ∀ i, labels A (u i) = labels A (u 0)) := by + unfold labels + fun_prop + apply (ae_map_iff ((show Measurable (residualRows u) by unfold residualRows; fun_prop).aemeasurable) hp.setOf).mpr + exact Filter.Eventually.of_forall (fun R => residualRows_equal_labels hu R) + +lemma projectedDensity_positive_sphere {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (A : Rows d k) (y : Labels k) (hp : 0 < projectedDensity base f A y) : + LinearIndependent ℝ A ∧ (base = .spherical → ‖liftLabel A y‖ < 1) := by + have hb : baseDensity base A y ≠ 0 := by + intro hc + simp [projectedDensity, hc] at hp + by_cases hA : LinearIndependent ℝ A + · refine ⟨hA, ?_⟩ + intro hs + subst base + by_contra hy + exact hb (by simp [baseDensity, hA, hy]) + · exact False.elim (hb (by simp [baseDensity, hA])) + +lemma ae_constrained_support {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + ∀ᵐ u : Tuple d m ∂Measure.pi (fun _ => (base.measure d).withDensity f), + LinearIndependent ℝ (differences u) ∧ + ∀ᵐ A ∂constrainedRows k u, + LinearIndependent ℝ A ∧ (∀ i, labels A (u i) = labels A (u 0)) ∧ + (base = .spherical → ‖liftLabel A (labels A (u 0))‖ < 1) ∧ + 0 < projectedDensity base f A (labels A (u 0)) ∧ + projectedDensity base f A (labels A (u 0)) ≠ ∞ := by + have hp := equal_label_transfer_prop hd hk hm base hf hL hfL + (P := fun A y => 0 < projectedDensity base f A y) + (measurableSet_lt measurable_const (measurable_projectedDensity base hf)) + (fun A _ => Filter.Eventually.of_forall fun y => id) + filter_upwards [hp, ae_tilt_tuple_full_rank (by omega : 3 ≤ d) (by omega : m < d) base hf hL hfL] + with u hu hU + refine ⟨hU, ?_⟩ + filter_upwards [hu, ae_constrained_equal_labels hU] with A hA heq + have hsup := projectedDensity_positive_sphere base A (labels A (u 0)) hA + exact ⟨hsup.1, heq, hsup.2, hA, projectedDensity_ne_top base hL hfL A (labels A (u 0))⟩ + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelVersions.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelVersions.lean new file mode 100644 index 0000000000000000000000000000000000000000..049a4f0918f297325495bef450311ac00521158e --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualLabelVersions.lean @@ -0,0 +1,81 @@ +import OAI.Probability.PosteriorReplicas.Measures.EuclideanLabels +import OAI.Probability.PosteriorReplicas.Measures.GaussianConstant + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Metric +open scoped ENNReal NNReal Topology +noncomputable section +namespace PosteriorReplicas + +lemma ae_gaussianDensityVersion {d k : ℕ} (hk : 1 ≤ k) (hk' : k+2 ≤ d) (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) + (hfL : ∀ x, f x ≤ L) {A : Rows d k} (hA : LinearIndependent ℝ A) : + projectedDensity base f A =ᵐ[volume] + gaussianDensityVersion ((base.measure d).withDensity f) A := by + let : NeZero d := ⟨by omega⟩ + let : NeZero k := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + have he0 := (measurable_projectedDensity (d := d) (k := k) base hf).comp + (show Measurable (fun y : Vec k => (A,WithLp.ofLp y)) from + measurable_const.prodMk (WithLp.measurable_ofLp 2 (Labels k))) + simp only [Function.comp_def] at he0 + have he : Measurable (fun y : Vec k => projectedDensity base f A (WithLp.ofLp y)) := he0 + have hμ := euclideanLabelLaw_density hA (by omega : k < d) base hf + have hd := ae_ball_differentiation (E := Vec k) he hμ + have hde := (PiLp.volume_preserving_toLp (Fin k)).quasiMeasurePreserving.ae hd + filter_upwards [hde] with y hy + have hM := fun v : Vec k => projectedDensity_uniform_bound hk' base hfL A (WithLp.ofLp v) + have H := tendsto_scaledRadial_at_ball_point he hμ + (ENNReal.mul_ne_top ENNReal.ofReal_ne_top hLt) hM hy + have heq : ∀ n, (∫⁻ x, scaledRadial n (WithLp.toLp 2 y) x + ∂euclideanLabelLaw ((base.measure d).withDensity f) A) = + ∫⁻ x, ENNReal.ofReal ((2*Real.pi*((n+1:ℝ)⁻¹)^2)^(-(k:ℝ)/2) * + Real.exp (-(labelNorm (labels A x-y))^2/(2*((n+1:ℝ)⁻¹)^2))) + ∂(base.measure d).withDensity f := by + intro n + rw [euclideanLabelLaw, lintegral_map (show Measurable (scaledRadial n (WithLp.toLp 2 y)) by + unfold scaledRadial; fun_prop) (by fun_prop)] + simp only [scaledRadial_eq, labelNorm, WithLp.toLp_sub] + simp_rw [heq] at H + exact H.liminf_eq.symm + +theorem equalLabelVersions : EqualLabelVersions := by + intro d k m hk hm hdim base f hf hL + obtain ⟨L,hLt,hfL⟩ := hL + have hd : k+m+2 ≤ d := by omega + let : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + dsimp only + let ν := (base.measure d).withDensity f + have hp := measurable_projectedDensity (d := d) (k := k) base hf + have hb := measurable_ballDensityVersion (d := d) (k := k) ν + have hg := measurable_gaussianDensityVersion (d := d) (k := k) ν + have hball : ∀ A : Rows d k, LinearIndependent ℝ A → + projectedDensity base f A =ᵐ[volume] ballDensityVersion ν A := + fun A hA => ae_ballDensityVersion hk (by omega : k < d) base hf hLt hfL hA + have hgauss : ∀ A : Rows d k, LinearIndependent ℝ A → + projectedDensity base f A =ᵐ[volume] gaussianDensityVersion ν A := + fun A hA => ae_gaussianDensityVersion hk (by omega : k+2 ≤ d) base hf hLt hfL hA + refine ⟨hp, hb, hg, ?_, ?_⟩ + · intro A hA + exact ⟨projected_measure hA (by omega) base hf, hball A hA, hgauss A hA⟩ + · have hbt := equal_label_transfer_prop hd hk hm base hf hLt hfL + (P := fun A y => projectedDensity base f A y = ballDensityVersion ν A y) + (measurableSet_eq_fun hp hb) (fun A hA => by + filter_upwards [hball A hA] with y hy + exact fun _ => hy) + have hgt := equal_label_transfer_prop hd hk hm base hf hLt hfL + (P := fun A y => projectedDensity base f A y = gaussianDensityVersion ν A y) + (measurableSet_eq_fun hp hg) (fun A hA => by + filter_upwards [hgauss A hA] with y hy + exact fun _ => hy) + filter_upwards [ae_constrained_support hd hk hm base hf hLt hfL, hbt, hgt] with u hu hb hg + refine ⟨hu.1, ?_⟩ + filter_upwards [hu.2, hb, hg] with A hA hba hga + exact ⟨hA.1, hA.2.1, hA.2.2.1, hA.2.2.2.1, hA.2.2.2.2, hba, hga⟩ + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/EqualRightMeasure.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualRightMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..57a57a017cedb768555794a8afb56c642e7408fe --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/EqualRightMeasure.lean @@ -0,0 +1,153 @@ +import OAI.Probability.PosteriorReplicas.Gaussian.ConstrainedNoise +import OAI.Probability.PosteriorReplicas.Measures.EqualApproximation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace Filter +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +abbrev RightSource (d k m : ℕ) := Tuple d m × Rows d k + +def rightBaseSource (d k m : ℕ) (base : BaseLaw) : Measure (RightSource d k m) := + (Measure.pi (fun _ : Fin (m+1) => base.measure d)).prod (gaussianRows d k) + +instance {d k m : ℕ} [NeZero d] (base : BaseLaw) : + IsProbabilityMeasure (rightBaseSource d k m base) := by + unfold rightBaseSource + infer_instance + +def equalConstant (k m : ℕ) : ℝ≥0∞ := ENNReal.ofReal ((2 * Real.pi) ^ (-(k * m : ℝ) / 2)) + +def rightBaseWeight {d k m : ℕ} (z : RightSource d k m) : ℝ≥0∞ := + equalConstant k m * (ENNReal.ofReal (affineVolume z.1))⁻¹ ^ k + +def residualRows {d k m : ℕ} (u : Tuple d m) (A : Rows d k) : Rows d k := + fun j => kernelComponent (differences u) (A j) + +def rightBasePoint {d k m : ℕ} (z : RightSource d k m) : EqualSpace d k m := + (residualRows z.1 z.2, labels (residualRows z.1 z.2) (z.1 0), z.1) + +@[fun_prop] lemma measurable_residualRows {d k m : ℕ} : + Measurable (fun z : RightSource d k m => residualRows z.1 z.2) := by + unfold residualRows + fun_prop + +@[fun_prop] lemma measurable_rightBasePoint {d k m : ℕ} : + Measurable (@rightBasePoint d k m) := by unfold rightBasePoint; fun_prop + +@[fun_prop] lemma measurable_rightBaseWeight {d k m : ℕ} : + Measurable (@rightBaseWeight d k m) := by unfold rightBaseWeight; fun_prop + +def rightBaseMeasure (d k m : ℕ) (base : BaseLaw) : Measure (EqualSpace d k m) := + ((rightBaseSource d k m base).withDensity rightBaseWeight).map rightBasePoint + +lemma rightBaseWeight_integral_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) (hm : 1 ≤ m) + (base : BaseLaw) : (∫⁻ z, rightBaseWeight z ∂rightBaseSource d k m base) < ∞ := by + have : NeZero d := ⟨by omega⟩ + unfold rightBaseSource rightBaseWeight + rw [lintegral_prod _ (by fun_prop)] + simp only [lintegral_const, measure_univ, mul_one] + rw [lintegral_const_mul _ (by fun_prop)] + exact ENNReal.mul_lt_top (by unfold equalConstant; finiteness) (base_tuple_inverse_finite hd hm base) + +lemma rightBaseMeasure_finite {d k m : ℕ} (hd : k + m + 2 ≤ d) (hm : 1 ≤ m) + (base : BaseLaw) : IsFiniteMeasure (rightBaseMeasure d k m base) := by + have := isFiniteMeasure_withDensity (rightBaseWeight_integral_finite hd hm base).ne + unfold rightBaseMeasure + infer_instance + +lemma rightBaseMeasure_lintegral {d k m : ℕ} [NeZero d] (base : BaseLaw) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + ∫⁻ z, H z ∂rightBaseMeasure d k m base = + ∫⁻ u : Tuple d m, equalConstant k m * (ENNReal.ofReal (affineVolume u))⁻¹ ^ k * + ∫⁻ A, H (residualRows u A, labels (residualRows u A) (u 0), u) ∂gaussianRows d k + ∂Measure.pi (fun _ => base.measure d) := by + rw [rightBaseMeasure, lintegral_map hH measurable_rightBasePoint, + lintegral_withDensity_eq_lintegral_mul _ measurable_rightBaseWeight + (show Measurable (fun z => H (rightBasePoint z)) by fun_prop)] + change (∫⁻ z, rightBaseWeight z * H (rightBasePoint z) ∂rightBaseSource d k m base) = _ + unfold rightBaseSource rightBaseWeight rightBasePoint + rw [lintegral_prod _ (by fun_prop)] + apply lintegral_congr + intro u + dsimp only [Prod.fst,Prod.snd] + rw [lintegral_const_mul _ (by fun_prop)] + +lemma constrainedRows_eq_residualRows {d k m : ℕ} {u : Tuple d m} + (hu : LinearIndependent ℝ (differences u)) : + constrainedRows k u = (gaussianRows d k).map (residualRows u) := by + unfold constrainedRows residualRows differenceSpan + simp_rw [kernelComponent_eq_starProjection hu] + +lemma constrainedRows_eq_gaussianResidualRows {d k m : ℕ} (u : Tuple d m) : + constrainedRows k u = gaussianResidualRows (differences u) k := by + unfold constrainedRows gaussianRows gaussianResidualRows differenceSpan + exact Measure.pi_map_pi (fun _ => (show Measurable + (Submodule.span ℝ (range (differences u)))ᗮ.starProjection by fun_prop).aemeasurable) + +lemma rows_pairingsDensity_differences {d k m : ℕ} {u : Tuple d m} + (hu : LinearIndependent ℝ (differences u)) : + (∏ _j : Fin k, pairingsDensity (differences u) 0) = + equalConstant k m * (ENNReal.ofReal (affineVolume u))⁻¹ ^ k := by + exact rows_pairingsDensity_zero hu k + +lemma rightBaseMeasure_eq_equalLabelRight {d k m : ℕ} (hd : 3 ≤ d) (hm : m < d) + (base : BaseLaw) {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + ∫⁻ z, H z ∂rightBaseMeasure d k m base = equalLabelRight base (fun _ => 1) H := by + have : NeZero d := ⟨by omega⟩ + rw [rightBaseMeasure_lintegral base hH] + unfold equalLabelRight + simp only [show (fun _ : Vec d => (1 : ℝ≥0∞)) = 1 from rfl, withDensity_one] + rw [← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr_ae + filter_upwards [ae_base_tuple_full_rank hd hm base] with u hu + rw [constrainedRows_eq_residualRows hu, lintegral_map (by fun_prop) (by unfold residualRows; fun_prop)] + rw [mul_assoc] + rfl + +lemma equalApprox_right_limit {d k m : ℕ} (hd : k + m + 2 ≤ d) + (hk : 1 ≤ k) (hm : 1 ≤ m) (base : BaseLaw) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Continuous H) + (b : ℝ≥0∞) (hb : b ≠ ∞) (hHb : ∀ x, H x ≤ b) : + Tendsto (fun n => equalApprox base n H) atTop + (nhds (∫⁻ z, H z ∂rightBaseMeasure d k m base)) := by + have : NeZero d := ⟨by omega⟩ + have he (n) : equalApprox base n H = + ∫⁻ u : Tuple d m, ∫⁻ A, matrixNoiseDensity m k n (fun i j => ⟪differences u i, A j⟫) * + H (A, labels A (u 0), u) ∂gaussianRows d k ∂Measure.pi (fun _ => base.measure d) := by + unfold equalApprox + rw [lintegral_lintegral_swap (by fun_prop)] + congr 1 + funext u + congr 1 + funext A + congr 2 + funext i j + simp only [labels, differences, Pi.sub_apply, inner_sub_left, real_inner_comm] + simp_rw [he] + rw [rightBaseMeasure_lintegral base hH.measurable] + apply tendsto_lintegral_of_dominated_convergence (fun u : Tuple d m => + equalConstant k m * (ENNReal.ofReal (affineVolume u))⁻¹ ^ k * b) + · intro n + unfold differences + fun_prop + · intro n + filter_upwards [ae_base_tuple_full_rank (by omega : 3 ≤ d) (by omega : m < d) base] with u hu + rw [← rows_pairingsDensity_differences hu] + exact constrained_gaussian_noise_bound hu k n (by unfold labels; fun_prop) b (fun A => hHb _) + · rw [lintegral_mul_const _ (by fun_prop), lintegral_const_mul _ (by fun_prop)] + exact ENNReal.mul_ne_top (ENNReal.mul_ne_top ENNReal.ofReal_ne_top + (base_tuple_inverse_finite hd hm base).ne) hb + · filter_upwards [ae_base_tuple_full_rank (by omega : 3 ≤ d) (by omega : m < d) base] with u hu + have hlim := constrained_gaussian_noise_limit hu k + (g := fun A => H (A, labels A (u 0), u)) (by unfold labels; fun_prop) b hb (fun A => hHb _) + rw [rows_pairingsDensity_differences hu, ← constrainedRows_eq_gaussianResidualRows, + constrainedRows_eq_residualRows hu, lintegral_map (by fun_prop) (by unfold residualRows; fun_prop)] at hlim + exact hlim + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/EuclideanLabels.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/EuclideanLabels.lean new file mode 100644 index 0000000000000000000000000000000000000000..b9fac223d18842f40a2412741e9151ddd548b646 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/EuclideanLabels.lean @@ -0,0 +1,95 @@ +import OAI.Probability.PosteriorReplicas.Measures.DensityDifferentiation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Metric +open scoped ENNReal NNReal Topology +noncomputable section +namespace PosteriorReplicas + +def euclideanLabelLaw {d k : ℕ} (ν : Measure (Vec d)) (A : Rows d k) : Measure (Vec k) := + ν.map (fun x => WithLp.toLp 2 (labels A x)) + +instance {d k : ℕ} (ν : Measure (Vec d)) [IsFiniteMeasure ν] (A : Rows d k) : + IsFiniteMeasure (euclideanLabelLaw ν A) := by unfold euclideanLabelLaw; infer_instance + +lemma euclidean_map_density {k : ℕ} {h : Labels k → ℝ≥0∞} (hh : Measurable h) : + (volume.withDensity h).map (WithLp.toLp 2) = + (volume : Measure (Vec k)).withDensity (fun y => h (WithLp.ofLp y)) := by + have ht : Measurable (WithLp.toLp 2 : Labels k → Vec k) := WithLp.measurable_toLp _ _ + have ho : Measurable (WithLp.ofLp : Vec k → Labels k) := WithLp.measurable_ofLp _ _ + apply Measure.ext_of_lintegral + intro g hg + rw [lintegral_map hg ht, + lintegral_withDensity_eq_lintegral_mul _ hh (show Measurable (fun x => g (WithLp.toLp 2 x)) from hg.comp ht), + lintegral_withDensity_eq_lintegral_mul _ (show Measurable (fun y => h (WithLp.ofLp y)) from hh.comp ho) hg] + simp only [Pi.mul_apply] + rw [← (PiLp.volume_preserving_toLp (Fin k)).lintegral_comp + (show Measurable (fun y => h (WithLp.ofLp y) * g y) from (hh.comp ho).mul hg)] + +lemma euclideanLabelLaw_density {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (hk : k < d) (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) : + euclideanLabelLaw ((base.measure d).withDensity f) A = + volume.withDensity (fun y : Vec k => projectedDensity base f A (WithLp.ofLp y)) := by + have ht : Measurable (WithLp.toLp 2 : Labels k → Vec k) := WithLp.measurable_toLp _ _ + have hl : Measurable (labels A) := by unfold labels; fun_prop + have hp0 := (measurable_projectedDensity (d := d) (k := k) base hf).comp + (show Measurable (fun y : Labels k => (A,y)) from measurable_const.prodMk measurable_id) + simp only [Function.comp_def] at hp0 + have hp : Measurable (projectedDensity base f A) := hp0 + change Measure.map (WithLp.toLp 2 ∘ labels A) _ = _ + rw [← Measure.map_map ht hl, projected_measure hA hk base hf] + exact euclidean_map_density hp + +lemma euclideanLabelLaw_ball {d k : ℕ} (ν : Measure (Vec d)) (A : Rows d k) + (y : Labels k) (r : ℝ) : + euclideanLabelLaw ν A (ball (WithLp.toLp 2 y) r) = + ν {x | labelNorm (labels A x - y) < r} := by + rw [euclideanLabelLaw, Measure.map_apply (by fun_prop) measurableSet_ball] + rfl + +lemma euclidean_label_ball_volume {k : ℕ} (y : Labels k) (r : ℝ) : + (volume : Measure (Vec k)) (ball (WithLp.toLp 2 y) r) = + (volume : Measure (Labels k)) {v | labelNorm v < r} := by + rw [Measure.addHaar_ball_center] + rw [← (PiLp.volume_preserving_toLp (Fin k)).measure_preimage (by measurability)] + congr 1 + ext v + simp only [mem_preimage, mem_ball, dist_zero_right] + rfl + +lemma projectedDensity_uniform_bound {d k : ℕ} (hk : k + 2 ≤ d) (base : BaseLaw) + {f : Vec d → ℝ≥0∞} {L : ℝ≥0∞} (hfL : ∀ x, f x ≤ L) (A : Rows d k) (y : Labels k) : + projectedDensity base f A y ≤ + ENNReal.ofReal (baseProjectionConstant base d k / Real.sqrt (rowGram A).det) * L := + mul_le_mul' (baseDensity_le_sup hk base A y) (tiltMass_le base hfL A y) + +lemma ae_ballDensityVersion {d k : ℕ} (hk : 1 ≤ k) (hk' : k < d) (base : BaseLaw) + {f : Vec d → ℝ≥0∞} (hf : Measurable f) {L : ℝ≥0∞} (hLt : L ≠ ∞) + (hfL : ∀ x, f x ≤ L) {A : Rows d k} (hA : LinearIndependent ℝ A) : + projectedDensity base f A =ᵐ[volume] + ballDensityVersion ((base.measure d).withDensity f) A := by + have : NeZero d := ⟨by omega⟩ + have : NeZero k := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + have he0 := (measurable_projectedDensity (d := d) (k := k) base hf).comp + (show Measurable (fun y : Vec k => (A,WithLp.ofLp y)) from + measurable_const.prodMk (WithLp.measurable_ofLp 2 (Labels k))) + simp only [Function.comp_def] at he0 + have he : Measurable (fun y : Vec k => projectedDensity base f A (WithLp.ofLp y)) := he0 + have hd := ae_ball_differentiation (E := Vec k) he + (euclideanLabelLaw_density hA hk' base hf) + have hde := (PiLp.volume_preserving_toLp (Fin k)).quasiMeasurePreserving.ae hd + filter_upwards [hde] with y hy + have hn : Tendsto (fun n : ℕ => (n+1:ℝ)⁻¹) atTop (𝓝[>] 0) := by + refine tendsto_nhdsWithin_iff.mpr ⟨?_, Filter.Eventually.of_forall (fun n => by change 0 < (n+1:ℝ)⁻¹; positivity)⟩ + simpa only [noiseScale, one_div] using + (show Tendsto (fun n => noiseScale n) atTop (𝓝 0) from tendsto_noiseScale) + have H := hy.comp hn + simp only [euclideanLabelLaw_ball, euclidean_label_ball_volume] at H + simpa only [ballDensityVersion, div_eq_mul_inv, mul_comm, Function.comp_def] using H.liminf_eq.symm + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/GaussianConstant.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/GaussianConstant.lean new file mode 100644 index 0000000000000000000000000000000000000000..3e801d97c143f19faaac82b10d134d7cd0513b43 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/GaussianConstant.lean @@ -0,0 +1,36 @@ +import OAI.Probability.PosteriorReplicas.Measures.GaussianDifferentiation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Metric +open scoped ENNReal NNReal Topology +noncomputable section +namespace PosteriorReplicas + +lemma gaussian_scaled_constant (q : ℕ) {ε : ℝ} (hε : 0 < ε) : + (ε^q)⁻¹ * (2*Real.pi)^(-(q:ℝ)/2) = (2*Real.pi*ε^2)^(-(q:ℝ)/2) := by + have he : (ε^2)^(-(q:ℝ)/2) = (ε^q)⁻¹ := by + rw [← Real.rpow_natCast ε 2, ← Real.rpow_mul hε.le] + norm_num only [Nat.cast_ofNat] + rw [show (2:ℝ) * (-(q:ℝ)/2) = -(q:ℝ) by ring, Real.rpow_neg hε.le, + Real.rpow_natCast] + rw [Real.mul_rpow (by positivity) (sq_nonneg ε), he, mul_comm] + +lemma scaledRadial_eq {k : ℕ} (n : ℕ) (y x : Vec k) : + scaledRadial n y x = ENNReal.ofReal + ((2*Real.pi* ((n+1:ℝ)⁻¹)^2)^(-(k:ℝ)/2) * + Real.exp (-‖x-y‖^2 / (2*((n+1:ℝ)⁻¹)^2))) := by + have he := noiseScale_pos n + simp only [scaledRadial, gaussianRadialDensity, finrank_euclideanSpace_fin] + rw [← ENNReal.ofReal_inv_of_pos (pow_pos he _), ← ENNReal.ofReal_mul (by positivity)] + congr 1 + rw [← mul_assoc, gaussian_scaled_constant k he] + have hexp : -(‖x-y‖/noiseScale n)^2/2 = -‖x-y‖^2/(2*(noiseScale n)^2) := by + field_simp + rw [hexp] + simp only [noiseScale, one_div] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/GaussianDifferentiation.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/GaussianDifferentiation.lean new file mode 100644 index 0000000000000000000000000000000000000000..aec4e7304b364aaa7a9853a0c75bddd568ce5b90 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/GaussianDifferentiation.lean @@ -0,0 +1,190 @@ +import OAI.Probability.PosteriorReplicas.Measures.DensityDifferentiation + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Metric +open scoped ENNReal NNReal Topology +noncomputable section +namespace PosteriorReplicas + +section Generic +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] + +def radialLevel (E : Type*) [NormedAddCommGroup E] (t : ℝ) : Set E := + {x | t < Real.exp (-‖x‖^2 / 2)} + +def radialWeight (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] (t : ℝ) : ℝ≥0∞ := + ENNReal.ofReal ((2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2)) * volume (radialLevel E t) + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + [Nontrivial E] in +lemma exp_norm_level_ball [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] [Nontrivial E] + {t : ℝ} (ht : 0 < t) (ht1 : t < 1) (y : E) {ε : ℝ} (hε : 0 < ε) : + {x : E | t < Real.exp (-(‖x-y‖ / ε)^2 / 2)} = + ball y (ε * Real.sqrt (-2 * Real.log t)) := by + have hlog : Real.log t < 0 := Real.log_neg ht ht1 + have hr : 0 < Real.sqrt (-2 * Real.log t) := Real.sqrt_pos.mpr (by linarith) + ext x + simp only [mem_ofPred_eq, mem_ball, dist_eq_norm] + rw [← Real.log_lt_log_iff ht (Real.exp_pos _), Real.log_exp] + have hn : 0 ≤ ‖x-y‖ / ε := div_nonneg (norm_nonneg _) hε.le + have hs : (Real.sqrt (-2 * Real.log t))^2 = -2 * Real.log t := Real.sq_sqrt (by linarith) + constructor + · intro h + have : ‖x-y‖ / ε < Real.sqrt (-2 * Real.log t) := by nlinarith + exact (div_lt_iff₀ hε).mp this |>.trans_eq (mul_comm _ _) + · intro h + have : ‖x-y‖ / ε < Real.sqrt (-2 * Real.log t) := (div_lt_iff₀ hε).mpr (by simpa [mul_comm] using h) + nlinarith + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + [Nontrivial E] in +lemma exp_norm_level_empty [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] [Nontrivial E] + {t : ℝ} (ht : 1 ≤ t) (y : E) (ε : ℝ) : + {x : E | t < Real.exp (-(‖x-y‖ / ε)^2 / 2)} = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro x hx + have he : Real.exp (-(‖x-y‖ / ε)^2 / 2) ≤ 1 := + Real.exp_le_one_iff.mpr (by nlinarith [sq_nonneg (‖x-y‖ / ε)]) + exact (not_lt_of_ge (he.trans ht)) hx + +lemma radialLevel_ball {t : ℝ} (ht : 0 < t) (ht1 : t < 1) : + radialLevel E t = ball 0 (Real.sqrt (-2 * Real.log t)) := by + simpa [radialLevel] using exp_norm_level_ball (E := E) ht ht1 0 (by norm_num : (0:ℝ)<1) + +lemma radialLevel_empty {t : ℝ} (ht : 1 ≤ t) : radialLevel E t = ∅ := by + simpa [radialLevel] using exp_norm_level_empty (E := E) ht 0 1 + +omit [Nontrivial E] in +@[fun_prop] lemma measurable_radialWeight [Nontrivial E] : Measurable (radialWeight E) := by + unfold radialWeight radialLevel + apply Measurable.const_mul + exact measurable_measure_prodMk_left (show MeasurableSet + {z : ℝ × E | z.1 < Real.exp (-‖z.2‖^2/2)} from measurableSet_lt (by fun_prop) (by fun_prop)) + +omit [Nontrivial E] in +lemma lintegral_radialWeight [Nontrivial E] : ∫⁻ t in Ioi (0:ℝ), radialWeight E t = 1 := by + have hc := lintegral_eq_lintegral_meas_lt (volume : Measure E) + (f := fun x => Real.exp (-‖x‖^2/2)) (Filter.Eventually.of_forall fun x => (Real.exp_pos _).le) + (by fun_prop) + have hg := congrArg (fun μ : Measure E => μ univ) (stdGaussian_density (E := E)) + rw [measure_univ, withDensity_apply _ MeasurableSet.univ] at hg + have hC : 0 ≤ (2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2) := + Real.rpow_nonneg (by positivity) _ + simp only [gaussianRadialDensity, ENNReal.ofReal_mul hC, Measure.restrict_univ, + ] at hg + rw [lintegral_const_mul _ (show Measurable (fun x : E => ENNReal.ofReal (Real.exp (-‖x‖^2/2))) by fun_prop)] at hg + unfold radialWeight radialLevel + rw [lintegral_const_mul _ (show Measurable (fun t : ℝ => + (volume : Measure E) {x | t < Real.exp (-‖x‖^2/2)}) from + measurable_measure_prodMk_left (show MeasurableSet {z : ℝ × E | z.1 < Real.exp (-‖z.2‖^2/2)} from + measurableSet_lt (by fun_prop) (by fun_prop))), ← hc] + exact hg.symm + +lemma radialWeight_ne_top {t : ℝ} (ht : 0 < t) : radialWeight E t ≠ ∞ := by + unfold radialWeight + by_cases ht1 : t < 1 + · rw [radialLevel_ball ht ht1] + exact ENNReal.mul_ne_top ENNReal.ofReal_ne_top measure_ball_lt_top.ne + · rw [radialLevel_empty (le_of_not_gt ht1), measure_empty, mul_zero] + exact ENNReal.zero_ne_top + +def scaledRadial (n : ℕ) (y x : E) : ℝ≥0∞ := + (ENNReal.ofReal ((noiseScale n) ^ Module.finrank ℝ E))⁻¹ * + gaussianRadialDensity (Module.finrank ℝ E) (‖x-y‖ / noiseScale n) + +lemma scaled_level_ratio {μ : Measure E} (y : E) (n : ℕ) {t : ℝ} (ht : 0 < t) (ht1 : t < 1) : + (ENNReal.ofReal ((noiseScale n)^Module.finrank ℝ E))⁻¹ * + ENNReal.ofReal ((2*Real.pi)^(-(Module.finrank ℝ E:ℝ)/2)) * + μ {x | t < Real.exp (-(‖x-y‖ / noiseScale n)^2/2)} = + (μ (ball y (noiseScale n * Real.sqrt (-2*Real.log t))) / + volume (ball y (noiseScale n * Real.sqrt (-2*Real.log t)))) * radialWeight E t := by + have hr : 0 < Real.sqrt (-2*Real.log t) := Real.sqrt_pos.mpr (by + have := Real.log_neg ht ht1 + linarith) + have hV0 := (measure_ball_pos (volume : Measure E) 0 hr).ne' + have hVt := (measure_ball_lt_top (μ := (volume : Measure E)) + (x := 0) (r := Real.sqrt (-2*Real.log t))).ne + rw [exp_norm_level_ball ht ht1 y (noiseScale_pos n), radialWeight, radialLevel_ball ht ht1, + Measure.addHaar_ball_mul_of_pos volume y (noiseScale_pos n)] + simp only [div_eq_mul_inv] + rw [ENNReal.mul_inv (Or.inr hVt) (Or.inl ENNReal.ofReal_ne_top)] + calc + _ = ((ENNReal.ofReal ((noiseScale n)^Module.finrank ℝ E))⁻¹ * + ENNReal.ofReal ((2*Real.pi)^(-(Module.finrank ℝ E:ℝ)/2)) * + μ (ball y (noiseScale n * Real.sqrt (-2*Real.log t)))) * + (((volume : Measure E) (ball 0 (Real.sqrt (-2*Real.log t))))⁻¹ * + (volume : Measure E) (ball 0 (Real.sqrt (-2*Real.log t)))) := by + rw [ENNReal.inv_mul_cancel hV0 hVt, mul_one] + simp only [div_eq_mul_inv] + _ = _ := by ring_nf + +lemma tendsto_scaledRadial_at_ball_point {μ : Measure E} [IsFiniteMeasure μ] + {h : E → ℝ≥0∞} (_ : Measurable h) (hμ : μ = volume.withDensity h) + {M : ℝ≥0∞} (hMt : M ≠ ∞) (hM : ∀ x, h x ≤ M) {y : E} + (hy : Tendsto (fun r => μ (ball y r) / volume (ball y r)) (𝓝[>] 0) (𝓝 (h y))) : + Tendsto (fun n => ∫⁻ x, scaledRadial n y x ∂μ) atTop (𝓝 (h y)) := by + let F : ℕ → ℝ → ℝ≥0∞ := fun n t => + (ENNReal.ofReal ((noiseScale n)^Module.finrank ℝ E))⁻¹ * + ENNReal.ofReal ((2*Real.pi)^(-(Module.finrank ℝ E:ℝ)/2)) * + μ {x | t < Real.exp (-(‖x-y‖ / noiseScale n)^2/2)} + have hFm : ∀ n, Measurable (F n) := by + intro n + apply Measurable.const_mul + exact measurable_measure_prodMk_left (show MeasurableSet + {z : ℝ × E | z.1 < Real.exp (-(‖z.2-y‖ / noiseScale n)^2/2)} from + measurableSet_lt (by fun_prop) (by fun_prop)) + have hbound : ∀ n, ∀ᵐ t ∂volume.restrict (Ioi (0:ℝ)), F n t ≤ M * radialWeight E t := by + intro n + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + by_cases ht1 : t < 1 + · dsimp only [F] + rw [scaled_level_ratio y n ht ht1] + apply mul_le_mul' _ le_rfl + apply (ENNReal.div_le_iff (measure_ball_pos volume y (mul_pos (noiseScale_pos n) + (Real.sqrt_pos.mpr (by have := Real.log_neg ht ht1; linarith)))).ne' + measure_ball_lt_top.ne).mpr + exact bounded_density_measure_le hμ hM _ measurableSet_ball + · simp [F, exp_norm_level_empty (le_of_not_gt ht1)] + have hlim : ∀ᵐ t ∂volume.restrict (Ioi (0:ℝ)), + Tendsto (fun n => F n t) atTop (𝓝 (h y * radialWeight E t)) := by + filter_upwards [ae_restrict_mem measurableSet_Ioi] with t ht + by_cases ht1 : t < 1 + · have hr : 0 < Real.sqrt (-2*Real.log t) := Real.sqrt_pos.mpr (by + have := Real.log_neg ht ht1; linarith) + have hε : Tendsto (fun n => noiseScale n * Real.sqrt (-2*Real.log t)) atTop (𝓝[>] 0) := by + apply tendsto_nhdsWithin_iff.mpr + exact ⟨by simpa using tendsto_noiseScale.mul_const (Real.sqrt (-2*Real.log t)), + Filter.Eventually.of_forall fun n => mul_pos (noiseScale_pos n) hr⟩ + simpa only [F, scaled_level_ratio y _ ht ht1, Function.comp_apply] using + ENNReal.Tendsto.mul_const (hy.comp hε) (Or.inr (radialWeight_ne_top ht)) + · simp only [F, exp_norm_level_empty (le_of_not_gt ht1), measure_empty, mul_zero, + radialWeight, radialLevel_empty (le_of_not_gt ht1)] + exact tendsto_const_nhds + have H := tendsto_lintegral_of_dominated_convergence (μ := volume.restrict (Ioi (0:ℝ))) + (fun t => M * radialWeight E t) hFm hbound + (by rw [lintegral_const_mul _ measurable_radialWeight, lintegral_radialWeight, mul_one]; exact hMt) hlim + rw [lintegral_const_mul _ measurable_radialWeight, lintegral_radialWeight, mul_one] at H + convert H using 1 + funext n + have hc := lintegral_eq_lintegral_meas_lt μ + (f := fun x => Real.exp (-(‖x-y‖/noiseScale n)^2/2)) + (Filter.Eventually.of_forall fun x => (Real.exp_pos _).le) (by fun_prop) + have hC : 0 ≤ (2 * Real.pi) ^ (-(Module.finrank ℝ E : ℝ) / 2) := + Real.rpow_nonneg (by positivity) _ + simp only [scaledRadial, gaussianRadialDensity, ENNReal.ofReal_mul hC, ← mul_assoc] + rw [lintegral_const_mul _ (by fun_prop), hc] + symm + exact lintegral_const_mul _ (measurable_measure_prodMk_left (show MeasurableSet + {z : ℝ × E | z.1 < Real.exp (-(‖z.2-y‖ / noiseScale n)^2/2)} from + measurableSet_lt (by fun_prop) (by fun_prop))) + +end Generic +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/PiTools.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/PiTools.lean new file mode 100644 index 0000000000000000000000000000000000000000..f73188d762daa155628855fc7c5c324218c3560c --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/PiTools.lean @@ -0,0 +1,42 @@ +import Mathlib + +namespace OAI + +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma lintegral_pi_cons {E : Type*} [MeasurableSpace E] (μ : Measure E) [SigmaFinite μ] + {n : ℕ} {f : (Fin (n+1) → E) → ℝ≥0∞} (hf : Measurable f) : + ∫⁻ v, f v ∂Measure.pi (fun _ => μ) = + ∫⁻ p, ∫⁻ v : Fin n → E, f (Fin.cons p v) ∂Measure.pi (fun _ => μ) ∂μ := by + let e := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => E) 0).symm + have he (z : E × (Fin n → E)) : e z = Fin.cons z.1 z.2 := by + simp only [e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv, + Fin.insertNth_zero, Fin.zero_succAbove, Equiv.coe_fn_mk, cast_eq] + have hm := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => μ) 0).symm + rw [← hm.lintegral_comp hf] + change (∫⁻ z, f (e z) ∂μ.prod (Measure.pi (fun _ : Fin n => μ))) = _ + have hfe : Measurable (fun z => f (e z)) := hf.comp e.measurable + rw [lintegral_prod _ hfe.aemeasurable] + simp_rw [he] + +lemma ae_pi_cons {E : Type*} [MeasurableSpace E] (μ : Measure E) [SigmaFinite μ] + {n : ℕ} {P : (Fin (n+1) → E) → Prop} (hP : MeasurableSet {v | P v}) : + (∀ᵐ v ∂Measure.pi (fun _ => μ), P v) ↔ + ∀ᵐ p ∂μ, ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => μ), P (Fin.cons p v) := by + let e := (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => E) 0).symm + have he (z : E × (Fin n → E)) : e z = Fin.cons z.1 z.2 := by + simp only [e, MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv, + Fin.insertNth_zero, Fin.zero_succAbove, Equiv.coe_fn_mk, cast_eq] + have hm := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => μ) 0).symm + rw [← hm.map_eq, MeasurableEmbedding.ae_map_iff e.measurableEmbedding] + have hPe : MeasurableSet {z | P (e z)} := hP.preimage e.measurable + rw [Measure.ae_prod_iff_ae_ae hPe] + simp_rw [he] + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/ProductFibers.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/ProductFibers.lean new file mode 100644 index 0000000000000000000000000000000000000000..e9d3b4b27d01dfa466dbe3c0d85a95d56950b919 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/ProductFibers.lean @@ -0,0 +1,67 @@ +import OAI.Probability.PosteriorReplicas.Geometry.BaseContinuity +import OAI.Probability.PosteriorReplicas.Geometry.BaseFunProp +import OAI.Probability.PosteriorReplicas.Measures.PiTools + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Matrix InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace PosteriorReplicas + +lemma base_pi_sample_representation {d k : ℕ} {A : Rows d k} + (hA : LinearIndependent ℝ A) (hk : k < d) (base : BaseLaw) (n : ℕ) : + ((Measure.pi (fun _ : Fin n => volume.withDensity (baseDensity base A))).prod + (gaussianRows d n)).map (fun z i => basePoint base A (z.1 i) (z.2 i)) = + Measure.pi (fun _ : Fin n => base.measure d) := by + have : IsProbabilityMeasure (volume.withDensity (baseDensity base A)) := by + have : NeZero d := ⟨by omega⟩ + rw [← projected_base_measure hA hk] + infer_instance + have hm : Measurable (fun z : Labels k × Vec d => basePoint base A z.1 z.2) := by + exact measurable_basePoint_comp base measurable_const measurable_fst measurable_snd + have hsample : (Measure.pi (fun _ : Fin n => + (volume.withDensity (baseDensity base A)).prod (stdGaussian (Vec d)))).map + (fun z i => basePoint base A (z i).1 (z i).2) = Measure.pi (fun _ => base.measure d) := by + rw [Measure.pi_map_pi (fun _ => hm.aemeasurable)] + simp_rw [base_sample_representation hA hk base] + have he := measurePreserving_arrowProdEquivProdArrow (Labels k) (Vec d) (Fin n) + (fun _ => volume.withDensity (baseDensity base A)) (fun _ => stdGaussian (Vec d)) + unfold gaussianRows + rw [← he.map_eq, Measure.map_map (by fun_prop) he.measurable] + exact hsample + +lemma base_pi_lintegral {d k : ℕ} {A : Rows d k} (hA : LinearIndependent ℝ A) + (hk : k < d) (base : BaseLaw) {n : ℕ} {g : (Fin n → Vec d) → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ v, g v ∂Measure.pi (fun _ => base.measure d) = + ∫⁻ y : Fin n → Labels k, (∏ i, baseDensity base A (y i)) * + ∫⁻ R, g (fun i => basePoint base A (y i) (R i)) ∂gaussianRows d n ∂volume := by + have hb0 := (measurable_baseDensity (d := d) (k := k) base).comp + (show Measurable (fun y : Labels k => (A,y)) from measurable_const.prodMk measurable_id) + simp only [Function.comp_def] at hb0 + have hb : Measurable (baseDensity base A) := hb0 + have : IsProbabilityMeasure (volume.withDensity (baseDensity base A)) := by + have : NeZero d := ⟨by omega⟩ + rw [← projected_base_measure hA hk] + infer_instance + have hs : Measurable (fun z : (Fin n → Labels k) × Rows d n => + g (fun i => basePoint base A (z.1 i) (z.2 i))) := hg.comp (by fun_prop) + rw [← base_pi_sample_representation hA hk base n, lintegral_map hg (by fun_prop), + lintegral_prod _ hs.aemeasurable, pi_withDensity _ _ (fun _ => hb), + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) hs.lintegral_prod_right] + + rfl + +lemma baseFiber_pi_lintegral {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) + {n : ℕ} {g : (Fin n → Vec d) → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ v, g v ∂Measure.pi (fun _ => baseFiber base A y) = + ∫⁻ R, g (fun i => basePoint base A y (R i)) ∂gaussianRows d n := by + simp_rw [baseFiber_eq_map] + rw [← Measure.pi_map_pi (fun _ => (measurable_basePoint_fixed base A y).aemeasurable), + lintegral_map hg (by fun_prop)] + rfl + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/ReferenceMoments.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/ReferenceMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..63f5004eb144d536dff0722332b41847f2169eeb --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/ReferenceMoments.lean @@ -0,0 +1,132 @@ +import OAI.Probability.PosteriorReplicas.Geometry.LabelEllipsoids +import OAI.Probability.PosteriorReplicas.Information.LikelihoodIntegrability +import OAI.Probability.PosteriorReplicas.Kernels.ReplicaMeasure + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter Matrix +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma tilt_tuple_inverse_finite {d k m : ℕ} (hd : k+m+2 ≤ d) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + (∫⁻ u : Tuple d m, (ENNReal.ofReal (affineVolume u))⁻¹^k + ∂Measure.pi (fun _ => (base.measure d).withDensity f)) < ∞ := by + let : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + rw [pi_withDensity _ _ (fun _ => hf), + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] + have hbound (u : Tuple d m) : (∏ i, f (u i)) ≤ L^(m+1) := by + simpa using Finset.prod_le_prod (fun i (_ : i ∈ (Finset.univ : Finset (Fin (m+1)))) => hfL (u i)) + simp only [Pi.mul_apply] + apply lt_of_le_of_lt (lintegral_mono (fun u => mul_le_mul' (hbound u) le_rfl)) + rw [lintegral_const_mul _ (by fun_prop)] + exact ENNReal.mul_lt_top (ENNReal.pow_lt_top hLt.lt_top) (base_tuple_inverse_finite hd hm base) + +lemma ae_equalReference_of_constrained {d k m : ℕ} (hd : 3 ≤ d) (hm : m < d) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {P : EqualSpace d k m → Prop} (hP : MeasurableSet {z | P z}) + (h : ∀ᵐ u : Tuple d m ∂Measure.pi (fun _ => (base.measure d).withDensity f), + ∀ᵐ A ∂constrainedRows k u, P (A,labels A (u 0),u)) : + ∀ᵐ z ∂equalReference (k := k) (m := m) ((base.measure d).withDensity f), P z := by + let : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + unfold equalReference + apply (ae_map_iff measurable_rightBasePoint.aemeasurable hP).mpr + apply (Measure.ae_prod_iff_ae_ae (hP.preimage measurable_rightBasePoint)).mpr + filter_upwards [h, ae_tilt_tuple_full_rank hd hm base hf hLt hfL] with u hu hU + rw [constrainedRows_eq_residualRows hU] at hu + exact (ae_map_iff (show Measurable (residualRows u) by fun_prop).aemeasurable + (hP.preimage (show Measurable (fun A => (A,labels A (u 0),u)) by unfold labels; fun_prop))).mp hu + +lemma ae_equalReference_density_pos {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + ∀ᵐ z ∂equalReference (k := k) (m := m) ((base.measure d).withDensity f), + 0 < projectedDensity base f z.1 z.2.1 := by + apply ae_equalReference_of_constrained (by omega) (by omega) base hf hLt hfL + (measurableSet_lt measurable_const (by fun_prop)) + filter_upwards [ae_constrained_support hd hk hm base hf hLt hfL] with u hu + filter_upwards [hu.2] with A hA + exact hA.2.2.2.1 + +lemma ae_equalReference_affine_pos {d k m : ℕ} (hd : 3 ≤ d) (hm : m < d) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + ∀ᵐ z ∂equalReference (k := k) (m := m) ((base.measure d).withDensity f), + 0 < affineVolume z.2.2 := by + apply ae_equalReference_of_constrained hd hm base hf hLt hfL + (measurableSet_lt measurable_const (by fun_prop)) + filter_upwards [ae_tilt_tuple_full_rank hd hm base hf hLt hfL] with u hu + apply ae_of_all + intro A + exact Real.sqrt_pos.mpr (Matrix.posDef_gram_of_linearIndependent hu).det_pos + +lemma reference_weight_moment {d k m n : ℕ} (hd : k*n+m+2 ≤ d) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + (∫⁻ z : EqualSpace d k m, + (equalConstant k m * (ENNReal.ofReal (affineVolume z.2.2))⁻¹^k)^n + ∂equalReference ((base.measure d).withDensity f)) < ∞ := by + let : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + rw [equalReference_lintegral _ (by fun_prop)] + simp only [lintegral_const, measure_univ, mul_one, mul_pow, ← pow_mul] + rw [lintegral_const_mul _ (by fun_prop)] + exact ENNReal.mul_lt_top (by unfold equalConstant; finiteness) + (tilt_tuple_inverse_finite hd hm base hf hLt hfL) + +lemma reference_inverse_density_moment {d k m : ℕ} (hd : k+m+2 ≤ d) (hk : 1 ≤ k) (hm : 1 ≤ m) + (base : BaseLaw) {f : Vec d → ℝ≥0∞} (hf : Measurable f) + {L : ℝ≥0∞} (hLt : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + (∫⁻ z : EqualSpace d k m, + (equalConstant k m * (ENNReal.ofReal (affineVolume z.2.2))⁻¹^k) * + (projectedDensity base f z.1 z.2.1)⁻¹^(m+1) + ∂equalReference ((base.measure d).withDensity f)) = + ∫⁻ A, (volume : Measure (Labels k)) {y | projectedDensity base f A y ≠ 0} ∂gaussianRows d k := by + let : NeZero d := ⟨by omega⟩ + have := bounded_withDensity_finite (base.measure d) hLt hfL + have (A : Rows d k) (y : Labels k) := tiltedFiber_probability base hLt hfL A y + have he := equal_label_tilt_identity hd hk hm base hf hLt hfL + (H := fun z : EqualSpace d k m => (projectedDensity base f z.1 z.2.1)⁻¹^(m+1)) (by fun_prop) + have hr : (∫⁻ z : EqualSpace d k m, + (equalConstant k m * (ENNReal.ofReal (affineVolume z.2.2))⁻¹^k) * + (projectedDensity base f z.1 z.2.1)⁻¹^(m+1) + ∂equalReference ((base.measure d).withDensity f)) = + equalLabelRight base f (fun z : EqualSpace d k m => + (projectedDensity base f z.1 z.2.1)⁻¹^(m+1)) := by + rw [equalLabelRight_residual (by omega) (by omega) base hf hLt hfL (by fun_prop), + equalReference_lintegral _ (by fun_prop)] + rw [← lintegral_const_mul _ (show Measurable (fun u : Tuple d m => + (ENNReal.ofReal (affineVolume u))⁻¹^k * ∫⁻ A, (projectedDensity base f + (residualRows u A) (labels (residualRows u A) (u 0)))⁻¹^(m+1) ∂gaussianRows d k) by + unfold residualRows; fun_prop)] + apply lintegral_congr + intro u + dsimp only [Prod.fst, Prod.snd] + rw [lintegral_const_mul _ (show Measurable (fun A : Rows d k => + (projectedDensity base f (residualRows u A) (labels (residualRows u A) (u 0)))⁻¹^(m+1)) by + unfold residualRows; fun_prop)] + rw [mul_assoc] + rw [hr, ← he] + unfold equalLabelLeft + apply lintegral_congr + intro A + simp only [lintegral_const, measure_univ, mul_one] + rw [← lintegral_indicator_one (show MeasurableSet {y | projectedDensity base f A y ≠ 0} by + exact (measurableSet_eq_fun (by fun_prop) measurable_const).compl)] + apply lintegral_congr + intro y + by_cases ha : projectedDensity base f A y = 0 + · simp [ha] + · rw [Set.indicator_of_mem (show y ∈ {y | projectedDensity base f A y ≠ 0} from ha)] + rw [← mul_pow, ENNReal.mul_inv_cancel ha (projectedDensity_ne_top base hLt hfL A y), one_pow] + rfl + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Measures/TiltNormalization.lean b/lean/OAI/Probability/PosteriorReplicas/Measures/TiltNormalization.lean new file mode 100644 index 0000000000000000000000000000000000000000..053d9fb4c395dbebe7f2026ee92eb7cce62945c8 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Measures/TiltNormalization.lean @@ -0,0 +1,104 @@ +import OAI.Probability.PosteriorReplicas.Measures.EqualBaseMeasures + +namespace OAI + +open MeasureTheory ProbabilityTheory Set +open scoped ENNReal NNReal +noncomputable section +namespace PosteriorReplicas + +lemma bounded_withDensity_finite {X : Type*} [MeasurableSpace X] (μ : Measure X) + [IsFiniteMeasure μ] {f : X → ℝ≥0∞} {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) : + IsFiniteMeasure (μ.withDensity f) := by + apply isFiniteMeasure_withDensity + exact ne_top_of_le_ne_top (by simpa using ENNReal.mul_ne_top hL (measure_ne_top μ univ)) + (lintegral_mono hfL) + +lemma tiltedFiber_probability {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} + {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) (A : Rows d k) (y : Labels k) : + IsProbabilityMeasure (tiltedFiber base f A y) := by + unfold tiltedFiber + split_ifs with ha + · infer_instance + · constructor + rw [Measure.smul_apply, smul_eq_mul, withDensity_apply _ MeasurableSet.univ, Measure.restrict_univ] + change (tiltMass base f A y)⁻¹ * tiltMass base f A y = 1 + exact ENNReal.inv_mul_cancel ha (tiltMass_ne_top base hL hfL A y) + +lemma tiltMass_smul_tiltedFiber {d k : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + (A : Rows d k) (y : Labels k) : + tiltMass base f A y • tiltedFiber base f A y = (baseFiber base A y).withDensity f := by + by_cases ha : tiltMass base f A y = 0 + · have hz : f =ᵐ[baseFiber base A y] 0 := (lintegral_eq_zero_iff hf).mp ha + rw [ha, zero_smul, withDensity_congr_ae hz, withDensity_zero] + · rw [tiltedFiber, ite_eq_right ha, smul_smul, + ENNReal.mul_inv_cancel ha (tiltMass_ne_top base hL hfL A y), one_smul] + +lemma pi_tiltMass_smul {d k n : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + (A : Rows d k) (y : Labels k) : + Measure.pi (fun _ : Fin n => (baseFiber base A y).withDensity f) = + (tiltMass base f A y)^n • Measure.pi (fun _ : Fin n => tiltedFiber base f A y) := by + have := bounded_withDensity_finite (baseFiber base A y) hL hfL + have := tiltedFiber_probability base hL hfL A y + apply Measure.pi_eq + intro s hs + rw [Measure.smul_apply, smul_eq_mul, Measure.pi_pi] + simp_rw [← tiltMass_smul_tiltedFiber base hf hL hfL A y, Measure.smul_apply, + smul_eq_mul] + rw [Finset.prod_mul_distrib] + simp + +lemma weighted_fiber_pi_integral {d k n : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + (A : Rows d k) (y : Labels k) {g : (Fin n → Vec d) → ℝ≥0∞} (hg : Measurable g) : + ∫⁻ u, (∏ i, f (u i)) * g u ∂Measure.pi (fun _ => baseFiber base A y) = + (tiltMass base f A y)^n * ∫⁻ u, g u ∂Measure.pi (fun _ => tiltedFiber base f A y) := by + have := bounded_withDensity_finite (baseFiber base A y) hL hfL + have he := lintegral_withDensity_eq_lintegral_mul + (Measure.pi (fun _ : Fin n => baseFiber base A y)) + (show Measurable (fun u : Fin n → Vec d => ∏ i, f (u i)) by fun_prop) hg + simp only [Pi.mul_apply] at he + rw [← he, ← pi_withDensity _ _ (fun _ => hf), pi_tiltMass_smul base hf hL hfL A y, + lintegral_smul_measure, smul_eq_mul] + +lemma equalLabelLeft_tilt {d k m : ℕ} (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + equalLabelLeft base f H = equalLabelLeft base (fun _ => 1) + (fun z => (∏ i, f (z.2.2 i)) * H z) := by + unfold equalLabelLeft + simp only [projectedDensity, tiltMass_one, mul_one, tiltedFiber_one] + apply lintegral_congr + intro A + apply lintegral_congr + intro y + rw [weighted_fiber_pi_integral base hf hL hfL A y (by fun_prop), mul_pow, mul_assoc] + +lemma equalLabelRight_tilt {d k m : ℕ} [NeZero d] (base : BaseLaw) {f : Vec d → ℝ≥0∞} + (hf : Measurable f) {L : ℝ≥0∞} (hL : L ≠ ∞) (hfL : ∀ x, f x ≤ L) + {H : EqualSpace d k m → ℝ≥0∞} (hH : Measurable H) : + equalLabelRight base f H = equalLabelRight base (fun _ => 1) + (fun z => (∏ i, f (z.2.2 i)) * H z) := by + have := bounded_withDensity_finite (base.measure d) hL hfL + unfold equalLabelRight + simp only [show (fun _ : Vec d => (1 : ℝ≥0∞)) = 1 from rfl, withDensity_one] + rw [pi_withDensity _ _ (fun _ => hf)] + + have hfprod : Measurable (fun u : Tuple d m => ∏ i, f (u i)) := by fun_prop + rw [lintegral_withDensity_eq_lintegral_mul_non_measurable _ hfprod + (Filter.Eventually.of_forall fun u => lt_top_iff_ne_top.mpr + (ENNReal.prod_ne_top (fun i _ => ne_top_of_le_ne_top hL (hfL _))))] + congr 1 + apply lintegral_congr + intro u + rw [lintegral_const_mul _ (show Measurable + (fun rows : Rows d k => H (rows, labels rows (u 0), u)) from hH.comp (by fun_prop))] + dsimp only [Pi.mul_apply] + ac_rfl + +end PosteriorReplicas +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Model.lean b/lean/OAI/Probability/PosteriorReplicas/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..cc39a500f103b8217db54f63e09e181bc3305080 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Model.lean @@ -0,0 +1,444 @@ +import Mathlib + +namespace OAI + + +section + +open MeasureTheory ProbabilityTheory InformationTheory Set Matrix +open scoped ENNReal NNReal RealInnerProductSpace Classical + +noncomputable section + +namespace PosteriorReplicas + +abbrev Vec (d : ℕ) := EuclideanSpace ℝ (Fin d) +abbrev Rows (d k : ℕ) := Fin k → Vec d +abbrev Labels (k : ℕ) := Fin k → ℝ +abbrev Data (d k : ℕ) := Rows d k × Labels k +abbrev Tuple (d m : ℕ) := Fin (m + 1) → Vec d + +def sphereLaw (d : ℕ) : Measure (Vec d) := + let σ := (volume : Measure (Vec d)).toSphere + ((σ univ)⁻¹ • σ).map Subtype.val + +def gaussianRows (d k : ℕ) : Measure (Rows d k) := + Measure.pi fun _ => stdGaussian (Vec d) + +instance (d k : ℕ) : IsProbabilityMeasure (gaussianRows d k) := by + unfold gaussianRows + infer_instance + +def labels {d k : ℕ} (A : Rows d k) (s : Vec d) : Labels k := + fun i => ⟪A i, s⟫ + +lemma measurable_labels {d k : ℕ} : + Measurable (fun z : Rows d k × Vec d => labels z.1 z.2) := by + unfold labels + fun_prop + +def messageKernel {d k N : ℕ} (κ : Kernel (Data d k) (Fin N)) : + Kernel (Vec d × Rows d k) (Fin N) := + κ.comap (fun z => (z.2, labels z.2 z.1)) (by + unfold labels + fun_prop) + +instance {d k N : ℕ} (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + IsMarkovKernel (messageKernel κ) := by + unfold messageKernel + infer_instance + +def signalMessageLaw {d k N : ℕ} (p : Measure (Vec d)) + (κ : Kernel (Data d k) (Fin N)) : Measure (Vec d × Fin N) := + ((p.prod (gaussianRows d k)) ⊗ₘ messageKernel κ).map + (fun z => (z.1.1, z.2)) + +instance {d k N : ℕ} (p : Measure (Vec d)) [IsProbabilityMeasure p] + (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ] : + IsProbabilityMeasure (signalMessageLaw p κ) := by + unfold signalMessageLaw + infer_instance + +def sideLaw {d N : ℕ} (ℓ : ℕ) (q : Measure (Vec d × Fin N)) : + Measure (Data d ℓ × (Vec d × Fin N)) := + ((gaussianRows d ℓ).prod q).map + (fun z => ((z.1, labels z.1 z.2.1), z.2)) + +instance {d N : ℕ} (ℓ : ℕ) (q : Measure (Vec d × Fin N)) [IsProbabilityMeasure q] : + IsProbabilityMeasure (sideLaw ℓ q) := by + unfold sideLaw + infer_instance + +def messageEntropy {d N : ℕ} (q : Measure (Vec d × Fin N)) : ℝ := + ∑ w : Fin N, -(q.snd.real {w}) * Real.log (q.snd.real {w}) + +def conditionalInformation {d ℓ N : ℕ} [NeZero N] + (μ : Measure (Data d ℓ × (Vec d × Fin N))) [IsFiniteMeasure μ] : ℝ≥0∞ := + klDiv μ (μ.fst ⊗ₘ (μ.condKernel.fst ×ₖ μ.condKernel.snd)) + +def GaussianReplicaBlock : Prop := + ∃ C : ℝ, 0 < C ∧ ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → + let k := 2 * (d / 16) + let t := k + 1 + let ℓ := 4 * k + ∀ (p : Measure (Vec d)) [IsProbabilityMeasure p] + (f : Vec d → ℝ) (L : ℝ), + Measurable f → (∀ x, 0 ≤ f x ∧ f x ≤ L) → + p = (sphereLaw d).withDensity (fun x => ENNReal.ofReal (f x)) → + ∀ (N : ℕ) [NeZero N] (κ : Kernel (Data d k) (Fin N)) [IsMarkovKernel κ], + conditionalInformation (sideLaw ℓ (signalMessageLaw p κ)) ≤ + ENNReal.ofReal (messageEntropy (signalMessageLaw p κ) / (t : ℝ) + + C * (d : ℝ) + C * Real.log (2 + Real.log L)) + +inductive BaseLaw where + | spherical + | gaussian + deriving DecidableEq + +def BaseLaw.measure (base : BaseLaw) (d : ℕ) : Measure (Vec d) := + match base with + | .spherical => sphereLaw d + | .gaussian => stdGaussian (Vec d) + +def rowGram {d k : ℕ} (A : Rows d k) : Matrix (Fin k) (Fin k) ℝ := + fun i j => ⟪A i, A j⟫ + +def liftLabel {d k : ℕ} (A : Rows d k) (y : Labels k) : Vec d := + ∑ i, ((rowGram A)⁻¹ *ᵥ y) i • A i + +def kernelComponent {d k : ℕ} (A : Rows d k) (x : Vec d) : Vec d := + x - liftLabel A (labels A x) + +def baseFiber {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) : + Measure (Vec d) := + match base with + | .gaussian => (stdGaussian (Vec d)).map + (fun x => liftLabel A y + kernelComponent A x) + | .spherical => (stdGaussian (Vec d)).map + (fun x => liftLabel A y + + (Real.sqrt (1 - ‖liftLabel A y‖ ^ 2) / ‖kernelComponent A x‖) • + kernelComponent A x) + +def baseDensity {d k : ℕ} (base : BaseLaw) (A : Rows d k) (y : Labels k) : ℝ≥0∞ := + if LinearIndependent ℝ A then + match base with + | .gaussian => ENNReal.ofReal + ((2 * Real.pi) ^ (-(k : ℝ) / 2) * + Real.exp (-‖liftLabel A y‖ ^ 2 / 2) / Real.sqrt (rowGram A).det) + | .spherical => if ‖liftLabel A y‖ < 1 then ENNReal.ofReal + (Real.Gamma ((d : ℝ) / 2) / + (Real.pi ^ ((k : ℝ) / 2) * Real.Gamma (((d : ℝ) - k) / 2)) * + (1 - ‖liftLabel A y‖ ^ 2) ^ (((d : ℝ) - k - 2) / 2) / + Real.sqrt (rowGram A).det) else 0 + else 0 + +def tiltMass {d k : ℕ} (base : BaseLaw) (f : Vec d → ℝ≥0∞) + (A : Rows d k) (y : Labels k) : ℝ≥0∞ := + ∫⁻ x, f x ∂baseFiber base A y + +def projectedDensity {d k : ℕ} (base : BaseLaw) (f : Vec d → ℝ≥0∞) + (A : Rows d k) (y : Labels k) : ℝ≥0∞ := + baseDensity base A y * tiltMass base f A y + +def tiltedFiber {d k : ℕ} (base : BaseLaw) (f : Vec d → ℝ≥0∞) + (A : Rows d k) (y : Labels k) : Measure (Vec d) := + if tiltMass base f A y = 0 then Measure.dirac 0 + else (tiltMass base f A y)⁻¹ • (baseFiber base A y).withDensity f + +def differences {d m : ℕ} (u : Tuple d m) : Fin m → Vec d := + fun i => u i.succ - u 0 + +def differenceSpan {d m : ℕ} (u : Tuple d m) : Submodule ℝ (Vec d) := + Submodule.span ℝ (Set.range (differences u)) + +def affineVolume {d m : ℕ} (u : Tuple d m) : ℝ := + Real.sqrt (Matrix.gram ℝ (differences u)).det + +def constrainedRows {d m : ℕ} (k : ℕ) (u : Tuple d m) : Measure (Rows d k) := + (gaussianRows d k).map + (fun A i => (differenceSpan u)ᗮ.starProjection (A i)) + +def equalLabelLeft {d k m : ℕ} (base : BaseLaw) (f : Vec d → ℝ≥0∞) + (H : Rows d k × Labels k × Tuple d m → ℝ≥0∞) : ℝ≥0∞ := + ∫⁻ A, ∫⁻ y, (projectedDensity base f A y) ^ (m + 1) * + ∫⁻ u, H (A, y, u) ∂Measure.pi (fun _ : Fin (m + 1) => tiltedFiber base f A y) + ∂volume ∂gaussianRows d k + +def equalLabelRight {d k m : ℕ} (base : BaseLaw) (f : Vec d → ℝ≥0∞) + (H : Rows d k × Labels k × Tuple d m → ℝ≥0∞) : ℝ≥0∞ := + ENNReal.ofReal ((2 * Real.pi) ^ (-(k * m : ℝ) / 2)) * + ∫⁻ u, (ENNReal.ofReal (affineVolume u))⁻¹ ^ k * + ∫⁻ A, H (A, labels A (u 0), u) ∂constrainedRows k u + ∂Measure.pi (fun _ : Fin (m + 1) => (base.measure d).withDensity f) + +def EqualLabelMeasureIdentity : Prop := + ∀ (d k m : ℕ), 1 ≤ k → 1 ≤ m → k + m ≤ d - 2 → + ∀ (base : BaseLaw) (f : Vec d → ℝ≥0∞), Measurable f → + (∃ L : ℝ≥0∞, L ≠ ∞ ∧ ∀ x, f x ≤ L) → + equalLabelLeft (k := k) (m := m) base f (fun _ => 1) < ∞ ∧ + ∀ H : Rows d k × Labels k × Tuple d m → ℝ≥0∞, + Measurable H → equalLabelLeft base f H = equalLabelRight base f H + +def DistanceReplicaBlock : Prop := + ∃ C : ℝ, 0 < C ∧ ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → + ∀ (p : Measure (Vec d)) [IsProbabilityMeasure p] + (f : Vec d → ℝ) (b : ℝ), + 0 ≤ b → Measurable f → (∀ x, 0 ≤ f x ∧ f x ≤ Real.exp b) → + p = (sphereLaw d).withDensity (fun x => ENNReal.ofReal (f x)) → + ∀ (N : ℕ) [NeZero N] (κ : Kernel (Data d (d / 16)) (Fin N)) [IsMarkovKernel κ], + conditionalInformation (sideLaw (d / 2) (signalMessageLaw p κ)) ≤ + ENNReal.ofReal (messageEntropy (signalMessageLaw p κ) / ((d / 8 : ℕ) : ℝ) + + C * ((d : ℝ) + b / (d : ℝ))) + +def SyntheticReplicaBlock : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ d : ℕ, 16 ≤ d → + ∀ (p : Measure (Vec d)) [IsProbabilityMeasure p] + (f : Vec d → ℝ) (L : ℝ), + 1 ≤ L → Measurable f → (∀ x, 0 ≤ f x ∧ f x ≤ L) → + p = (sphereLaw d).withDensity (fun x => ENNReal.ofReal (f x)) → + ∀ (N : ℕ) [NeZero N] (z : Data d (d / 8) → Fin N) (hz : Measurable z), + conditionalInformation + (sideLaw (d / 2) (signalMessageLaw p (Kernel.deterministic z hz))) ≤ + ENNReal.ofReal (Real.log (N : ℝ) / ((d / 8 : ℕ) : ℝ) + + C * ((d : ℝ) + Real.log (1 + Real.log L))) + +def IncidenceReplicaBlock : Prop := + ∃ C : ℝ, 0 < C ∧ ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → + ∀ (p : Measure (Vec d)) [IsProbabilityMeasure p] + (f : Vec d → ℝ) (F : ℝ), + 1 ≤ F → Measurable f → (∀ x, 0 ≤ f x ∧ f x ≤ F) → + p = (sphereLaw d).withDensity (fun x => ENNReal.ofReal (f x)) → + ∀ (N : ℕ) [NeZero N] (κ : Kernel (Data d (d / 16)) (Fin N)) [IsMarkovKernel κ], + conditionalInformation (sideLaw (d / 4) (signalMessageLaw p κ)) ≤ + ENNReal.ofReal (Real.log (N : ℝ) / ((d / 16 : ℕ) : ℝ) + + C * (d : ℝ) + C * Real.log (1 + Real.log F)) + +def labelNorm {k : ℕ} (y : Labels k) : ℝ := ‖WithLp.toLp 2 y‖ + +def ballDensityVersion {d k : ℕ} (ν : Measure (Vec d)) + (A : Rows d k) (y : Labels k) : ℝ≥0∞ := + Filter.liminf (fun n : ℕ => + ((volume : Measure (Labels k)) {v | labelNorm v < (n + 1 : ℝ)⁻¹})⁻¹ * + ν {x | labelNorm (labels A x - y) < (n + 1 : ℝ)⁻¹}) Filter.atTop + +def gaussianDensityVersion {d k : ℕ} (ν : Measure (Vec d)) + (A : Rows d k) (y : Labels k) : ℝ≥0∞ := + Filter.liminf (fun n : ℕ => ∫⁻ x, + ENNReal.ofReal ((2 * Real.pi * ((n + 1 : ℝ)⁻¹)^2) ^ (-(k : ℝ) / 2) * + Real.exp (-(labelNorm (labels A x - y))^2 / (2 * ((n + 1 : ℝ)⁻¹)^2))) ∂ν) + Filter.atTop + +def EqualLabelVersions : Prop := + ∀ (d k m : ℕ), 1 ≤ k → 1 ≤ m → k + m ≤ d - 2 → + ∀ (base : BaseLaw) (f : Vec d → ℝ≥0∞), Measurable f → + (∃ L : ℝ≥0∞, L ≠ ∞ ∧ ∀ x, f x ≤ L) → + let ν := (base.measure d).withDensity f + (Measurable (fun z : Rows d k × Labels k => projectedDensity base f z.1 z.2)) ∧ + (Measurable (fun z : Rows d k × Labels k => ballDensityVersion ν z.1 z.2)) ∧ + (Measurable (fun z : Rows d k × Labels k => gaussianDensityVersion ν z.1 z.2)) ∧ + (∀ A : Rows d k, LinearIndependent ℝ A → + ν.map (labels A) = volume.withDensity (projectedDensity base f A) ∧ + projectedDensity base f A =ᵐ[volume] ballDensityVersion ν A ∧ + projectedDensity base f A =ᵐ[volume] gaussianDensityVersion ν A) ∧ + (∀ᵐ u ∂Measure.pi (fun _ : Fin (m + 1) => ν), + LinearIndependent ℝ (differences u) ∧ + ∀ᵐ A ∂constrainedRows k u, + LinearIndependent ℝ A ∧ + (∀ i, labels A (u i) = labels A (u 0)) ∧ + (base = .spherical → ‖liftLabel A (labels A (u 0))‖ < 1) ∧ + 0 < projectedDensity base f A (labels A (u 0)) ∧ + projectedDensity base f A (labels A (u 0)) ≠ ∞ ∧ + projectedDensity base f A (labels A (u 0)) = + ballDensityVersion ν A (labels A (u 0)) ∧ + projectedDensity base f A (labels A (u 0)) = + gaussianDensityVersion ν A (labels A (u 0))) + +def haarRows (d ℓ : ℕ) : Measure (Rows d ℓ) := + (gaussianRows d ℓ).map (InnerProductSpace.gramSchmidtNormed ℝ) + +def cmi {Z X Y : Type*} [MeasurableSpace Z] [MeasurableSpace X] [MeasurableSpace Y] + [StandardBorelSpace X] [StandardBorelSpace Y] [Nonempty X] [Nonempty Y] + (μ : Measure (Z × (X × Y))) [IsFiniteMeasure μ] : ℝ≥0∞ := + klDiv μ (μ.fst ⊗ₘ (μ.condKernel.fst ×ₖ μ.condKernel.snd)) + +def finiteEntropy {J : Type*} [Fintype J] [MeasurableSpace J] (μ : Measure J) : ℝ := + ∑ j, - μ.real {j} * Real.log (μ.real {j}) + +def stateMessageKernel {d k V W : ℕ} (κ : Kernel (Fin V × Data d k) (Fin W)) : + Kernel ((Vec d × Fin V) × Rows d k) (Fin W) := + κ.comap (fun z => (z.1.2, (z.2, labels z.2 z.1.1))) (by unfold labels; fun_prop) + +instance {d k V W : ℕ} (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + IsMarkovKernel (stateMessageKernel κ) := by + unfold stateMessageKernel + infer_instance + +def stateMessageLaw {d k V W : ℕ} (q : Measure (Vec d × Fin V)) + (κ : Kernel (Fin V × Data d k) (Fin W)) : Measure ((Vec d × Fin V) × Fin W) := + (((q.prod (gaussianRows d k)) ⊗ₘ stateMessageKernel κ).map + (fun z => (z.1.1, z.2))) + +instance {d k V W : ℕ} (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q] + (κ : Kernel (Fin V × Data d k) (Fin W)) [IsMarkovKernel κ] : + IsProbabilityMeasure (stateMessageLaw q κ) := by + unfold stateMessageLaw + infer_instance + +def stateHaarSideLaw {d V W : ℕ} (ℓ : ℕ) + (q : Measure ((Vec d × Fin V) × Fin W)) : + Measure ((Fin V × Data d ℓ) × (Vec d × Fin W)) := + ((haarRows d ℓ).prod q).map + (fun z => ((z.2.1.2, (z.1, labels z.1 z.2.1.1)), (z.2.1.1, z.2.2))) + +instance {d V W : ℕ} (ℓ : ℕ) + (q : Measure ((Vec d × Fin V) × Fin W)) [IsFiniteMeasure q] : + IsFiniteMeasure (stateHaarSideLaw ℓ q) := by + unfold stateHaarSideLaw haarRows + infer_instance + +def terminalConditionalEntropy {d V W : ℕ} + (q : Measure ((Vec d × Fin V) × Fin W)) : ℝ := + finiteEntropy (q.map (fun z => (z.1.2, z.2))) - finiteEntropy (q.map (fun z => z.1.2)) + +def HaarReplicaBlock : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ d : ℕ, 64 ≤ d → + ∀ (V W : ℕ) [NeZero V] [NeZero W] + (q : Measure (Vec d × Fin V)) [IsProbabilityMeasure q], + q.fst = sphereLaw d → + ∀ (κ : Kernel (Fin V × Data d (d / 16)) (Fin W)) [IsMarkovKernel κ], + cmi (stateHaarSideLaw (d / 4) (stateMessageLaw q κ)) ≤ + ENNReal.ofReal (terminalConditionalEntropy (stateMessageLaw q κ) / + ((d / 16 + 1 : ℕ) : ℝ) + C * (d : ℝ) + + Real.log (1 + C * (d : ℝ) + finiteEntropy q.snd) + + C * (finiteEntropy q.snd + Real.log (d : ℝ)) / (d : ℝ)^2) + +end PosteriorReplicas +end +end + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace + +noncomputable section + +universe u + +namespace PosteriorRegression + +abbrev Vector (d : ℕ) := EuclideanSpace ℝ (Fin d) +abbrev UnitSphere (d : ℕ) := Metric.sphere (0 : Vector d) 1 +abbrev State (M : ℕ) := Fin (2 ^ M) +abbrev Samples (d T : ℕ) := Fin T → Vector d + +def uniformSphere (d : ℕ) : Measure (UnitSphere d) := + let σ := (volume : Measure (Vector d)).toSphere + (σ Set.univ)⁻¹ • σ + +def sampleLaw (d T : ℕ) : Measure (Samples d T) := + Measure.pi fun _ => stdGaussian (Vector d) + +def observationReference (d : ℕ) : Measure (Vector d × ℝ) := + (stdGaussian (Vector d)).prod volume + +namespace Learner + +abbrev RunStatus (M : ℕ) := Sum (State M) (ℕ × State M) + +def angularError {d : ℕ} (s ŝ : UnitSphere d) : ℝ := + Real.arccos ⟪ŝ.val, s.val⟫ + +end Learner + +end PosteriorRegression + +open MeasureTheory ProbabilityTheory InformationTheory Set Matrix +open scoped ENNReal NNReal RealInnerProductSpace Classical + +noncomputable section + +namespace PosteriorRegression +abbrev CompletedObservation (d : ℕ) := NullMeasurableSpace (Vector d × ℝ) (observationReference d) +abbrev Destination (M : ℕ) := Bool × State M + +structure CompletedKernelLearner (d M : ℕ) where + initial : Measure (Destination M) + initial_probability : IsProbabilityMeasure initial + transition : ℕ → State M → Kernel (CompletedObservation d) (Destination M) + transition_markov : ∀ t a, IsMarkovKernel (transition t a) + output : ℕ → State M → Measure (UnitSphere d) + output_probability : ∀ t a, IsProbabilityMeasure (output t a) + +attribute [instance] CompletedKernelLearner.initial_probability + CompletedKernelLearner.transition_markov CompletedKernelLearner.output_probability + +namespace CompletedKernelLearner +open Learner +def destStatus {M : ℕ} (n : ℕ) (v : Destination M) : RunStatus M := + if v.1 then Sum.inr (n,v.2) else Sum.inl v.2 + +def finishState {M : ℕ} (T : ℕ) : RunStatus M → ℕ × State M + | .inl a => (T,a) + | .inr done => done + +def stepMeasure {d M T : ℕ} (K : CompletedKernelLearner d M) + (s : UnitSphere d) (x : Samples d T) (i : Fin T) : RunStatus M → Measure (RunStatus M) + | .inr done => Measure.dirac (.inr done) + | .inl a => (K.transition (i.val+1) a (x i,⟪x i,s.val⟫)).map (destStatus (i.val+1)) + +def runMeasure {d M T : ℕ} (K : CompletedKernelLearner d M) + (s : UnitSphere d) (x : Samples d T) : ℕ → Measure (RunStatus M) + | 0 => K.initial.map (destStatus 0) + | n+1 => if hn : n K.output a.1 a.2) + +end CompletedKernelLearner + +structure JointKernelExperiment (d M T : ℕ) (Ω : Type u) [MeasurableSpace Ω] + (ρ : Measure Ω) where + rules : Ω → CompletedKernelLearner d M + outputKernel : Kernel (Ω × (UnitSphere d × Samples d T)) (UnitSphere d) + output_markov : IsMarkovKernel outputKernel + conditional_output : ∀ᵐ ω ∂ρ, ∀ᵐ z ∂((uniformSphere d).prod (sampleLaw d T)), + outputKernel (ω,z) = (rules ω).estimateLaw z.1 z.2 + +attribute [instance] JointKernelExperiment.output_markov + +namespace JointKernelExperiment +open Learner +def law {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] {ρ : Measure Ω} + (E : JointKernelExperiment d M T Ω ρ) : Measure ((Ω × (UnitSphere d × Samples d T)) × UnitSphere d) := + (ρ.prod ((uniformSphere d).prod (sampleLaw d T))) ⊗ₘ E.outputKernel + +def uniformSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] {ρ : Measure Ω} + (E : JointKernelExperiment d M T Ω ρ) (ε : ℝ) : ℝ≥0∞ := + E.law {z | angularError z.1.2.1 z.2 ≤ ε} + +end JointKernelExperiment + +def KernelSubquadraticMemory : Prop := + ∃ c : ℝ, 0 < c ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d : ℝ)) (fun d => (d : ℝ)^2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0<ε → ε≤1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ E : JointKernelExperiment d (M d) T Ω ρ, + (2/3 : ℝ≥0∞) ≤ E.uniformSuccess ε → + c * (d : ℝ) * Real.log (1/ε) ≤ (T : ℝ) + +end PosteriorRegression + +namespace PosteriorReplicas + +end PosteriorReplicas +end +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/AePiLast.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/AePiLast.lean new file mode 100644 index 0000000000000000000000000000000000000000..da69abe60d534c9c8f5053ef379c234468c343f2 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/AePiLast.lean @@ -0,0 +1,39 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section AePiLast +variable {E : Type*} [MeasurableSpace E] {n : ℕ} (ν : Measure E) [SigmaFinite ν] +lemma ae_pi_snoc {P : (Fin (n+1) → E) → Prop} (hP : MeasurableSet {v | P v}) : + (∀ᵐ v ∂Measure.pi (fun _ => ν), P v) ↔ + ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => ν), ∀ᵐ x ∂ν, P (Fin.snoc v x) := by + have hp := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => ν) (Fin.last n)).symm + rw [← hp.map_eq, MeasurableEmbedding.ae_map_iff (MeasurableEquiv.measurableEmbedding _)] + have heq : (fun z : E × (Fin n → E) => + (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => E) (Fin.last n)).symm z) = + fun z => Fin.snoc z.2 z.1 := by + ext z : 1 + change (Fin.last n).insertNth (α := fun _ => E) z.1 z.2 = _ + exact Fin.insertNth_last' z.1 z.2 + have hm : Measurable (fun z : E × (Fin n → E) => Fin.snoc (α := fun _ => E) z.2 z.1) := by + rw [← heq] + exact hp.measurable + change (∀ᵐ z ∂ν.prod (Measure.pi (fun _ : Fin n => ν)), + P ((fun z => (MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => E) + (Fin.last n)).symm z) z)) ↔ _ + have hPP : MeasurableSet {z : E × (Fin n → E) | P (Fin.snoc z.2 z.1)} := hP.preimage hm + rw [heq, Measure.ae_prod_iff_ae_ae hPP] + exact Measure.ae_ae_comm hPP +end AePiLast + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/AffineTubes.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/AffineTubes.lean new file mode 100644 index 0000000000000000000000000000000000000000..e3b1fe2d55cce02c6f18984c1735ef0babf74b61 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/AffineTubes.lean @@ -0,0 +1,149 @@ +import OAI.Probability.PosteriorReplicas.Regression.EuclideanNets +import OAI.Probability.PosteriorReplicas.Regression.InverseMoments + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +section AffineTubes + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +open EuclideanGeometry + +theorem exists_affine_tube_cover (L : AffineSubspace ℝ E) [Nonempty L] + {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) : + ∃ s : Finset L.direction, + (s.card : ℝ) ≤ (3 / r) ^ Module.finrank ℝ L.direction ∧ + ∀ t : E, ‖t‖ ≤ 1 → Metric.infDist t L ≤ r → + ∃ y ∈ s, dist t ((y : E) + (orthogonalProjection L 0 : E)) ≤ 2 * r := by + classical + obtain ⟨s, _, hcard, hnet⟩ := exists_unit_ball_net (E := L.direction) hr hr1 + refine ⟨s, hcard, ?_⟩ + intro t ht hdist + obtain ⟨y, hy, hty⟩ := hnet (L.direction.orthogonalProjectionOnto t) + ((L.direction.norm_orthogonalProjectionOnto_apply_le t).trans ht) + refine ⟨y, hy, ?_⟩ + have hproj : (orthogonalProjection L t : E) = + (L.direction.orthogonalProjectionOnto t : E) + (orthogonalProjection L 0 : E) := by + have h := (orthogonalProjection L).map_vadd (0 : E) t + simpa only [vadd_eq_add, add_zero, orthogonalProjection_contLinear, + AffineSubspace.coe_vadd] using congrArg (fun x : L => (x : E)) h + have hpdist : dist (orthogonalProjection L t : E) + ((y : E) + (orthogonalProjection L 0 : E)) ≤ r := by + rw [hproj, dist_add_right] + exact hty + have hd : dist t (orthogonalProjection L t : E) ≤ r := by + rwa [dist_orthogonalProjection_eq_infDist] + calc + dist t ((y : E) + (orthogonalProjection L 0 : E)) ≤ + dist t (orthogonalProjection L t : E) + + dist (orthogonalProjection L t : E) ((y : E) + (orthogonalProjection L 0 : E)) := + dist_triangle _ _ _ + _ ≤ r + r := add_le_add hd hpdist + _ = 2 * r := by ring + +theorem HasLocalMassBound.affine_tube {ν : Measure E} {a : ℝ} + (hν : HasLocalMassBound ν a) (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (L : AffineSubspace ℝ E) [Nonempty L] {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) : + ν {t | Metric.infDist t L ≤ r} ≤ + ENNReal.ofReal ((3 / r) ^ Module.finrank ℝ L.direction * (4 * r) ^ a) := by + classical + obtain ⟨s, hcard, hcover⟩ := exists_affine_tube_cover L hr hr1 + let c : L.direction → E := fun y => (y : E) + (orthogonalProjection L 0 : E) + have hsub : {t | Metric.infDist t L ≤ r} ≤ᵐ[ν] + ⋃ y ∈ s, Metric.closedBall (c y) (2 * r) := by + filter_upwards [ν.support_mem_ae] with t ht + intro hdist + have htunit : ‖t‖ ≤ 1 := by simpa using hsupport ht + obtain ⟨y, hy, hty⟩ := hcover t htunit hdist + exact mem_iUnion₂.mpr ⟨y, hy, hty⟩ + calc + ν {t | Metric.infDist t L ≤ r} ≤ ν (⋃ y ∈ s, Metric.closedBall (c y) (2 * r)) := + measure_mono_ae hsub + _ ≤ ∑ y ∈ s, ν (Metric.closedBall (c y) (2 * r)) := measure_biUnion_finset_le _ _ + _ ≤ ∑ _y ∈ s, ENNReal.ofReal ((4 * r) ^ a) := by + refine Finset.sum_le_sum fun y _ => ?_ + simpa only [show (2 : ℝ) * (2 * r) = 4 * r by ring] using + hν.any_center (c y) (r := 2 * r) (by positivity) + _ = (s.card : ℝ≥0∞) * ENNReal.ofReal ((4 * r) ^ a) := by simp + _ ≤ ENNReal.ofReal ((3 / r) ^ Module.finrank ℝ L.direction) * + ENNReal.ofReal ((4 * r) ^ a) := by + gcongr + exact_mod_cast ENNReal.ofReal_le_ofReal hcard + _ = _ := (ENNReal.ofReal_mul (by positivity)).symm + +lemma tube_radius_factors (ℓ : ℕ) (a : ℝ) {r : ℝ} (hr : 0 < r) : + (3 / r) ^ ℓ * (4 * r) ^ a = + (3 : ℝ) ^ ℓ * (4 : ℝ) ^ a * r ^ (a - ℓ) := by + rw [div_pow, Real.mul_rpow (by norm_num) hr.le, + Real.rpow_sub_natCast hr.ne'] + ring + +theorem HasLocalMassBound.affine_tube_pow {ν : Measure E} {a : ℝ} + (hν : HasLocalMassBound ν a) (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (L : AffineSubspace ℝ E) [Nonempty L] (k : ℕ) + (hmargin : (Module.finrank ℝ L.direction : ℝ) + k ≤ a) + {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) : + ν {t | Metric.infDist t L ≤ r} ≤ + ENNReal.ofReal ((3 : ℝ) ^ Module.finrank ℝ L.direction * (4 : ℝ) ^ a) * + ENNReal.ofReal (r ^ k) := by + refine (hν.affine_tube hsupport L hr hr1).trans ?_ + rw [tube_radius_factors _ _ hr, ← ENNReal.ofReal_mul (by positivity)] + apply ENNReal.ofReal_le_ofReal + apply mul_le_mul_of_nonneg_left _ (by positivity) + rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_ge hr hr1 (by linarith) + +theorem HasLocalMassBound.affine_inverse_moment {ν : Measure E} {a : ℝ} + (hν : HasLocalMassBound ν a) (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (L : AffineSubspace ℝ E) [Nonempty L] (m : ℕ) + (hmargin : (Module.finrank ℝ L.direction : ℝ) + (m + 1 : ℕ) ≤ a) : + ∫⁻ t, ENNReal.ofReal ((Metric.infDist t L)⁻¹ ^ m) ∂ν ≤ + ν Set.univ + + ENNReal.ofReal ((3 : ℝ) ^ Module.finrank ℝ L.direction * (4 : ℝ) ^ a) * + (2 : ℝ≥0∞) ^ (m + 1) := by + apply inverse_moment_of_tube_bound ν _ m (Metric.continuous_infDist_pt _).measurable + (fun _ => Metric.infDist_nonneg) + intro r hr hr1 + exact hν.affine_tube_pow hsupport L (m + 1) hmargin hr hr1 + +theorem HasLocalMassBound.affine_null {ν : Measure E} {a : ℝ} + (hν : HasLocalMassBound ν a) (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (L : AffineSubspace ℝ E) [Nonempty L] + (hmargin : (Module.finrank ℝ L.direction : ℝ) + 1 ≤ a) : ν L = 0 := by + let C : ℝ := (3 : ℝ) ^ Module.finrank ℝ L.direction * (4 : ℝ) ^ a + have hC : 0 ≤ C := by dsimp [C]; positivity + have hb (n : ℕ) : ν L ≤ ENNReal.ofReal (C * (1 / 2 : ℝ) ^ n) := by + have hn : 0 < (1 / 2 : ℝ) ^ n := by positivity + have hn1 : (1 / 2 : ℝ) ^ n ≤ 1 := pow_le_one₀ (by norm_num) (by norm_num) + calc + ν L ≤ ν {t | Metric.infDist t L ≤ (1 / 2 : ℝ) ^ n} := by + apply measure_mono + intro t ht + simp only [mem_ofPred_eq, Metric.infDist_zero_of_mem ht] + exact hn.le + _ ≤ ENNReal.ofReal C * ENNReal.ofReal (((1 / 2 : ℝ) ^ n) ^ 1) := + hν.affine_tube_pow hsupport L 1 (by simpa using hmargin) hn hn1 + _ = _ := by rw [pow_one, ENNReal.ofReal_mul hC] + have hlim : Tendsto (fun n : ℕ => ENNReal.ofReal (C * (1 / 2 : ℝ) ^ n)) + atTop (𝓝 0) := by + convert ENNReal.tendsto_ofReal ((tendsto_const_nhds (x := C)).mul + (tendsto_pow_atTop_nhds_zero_of_lt_one (by norm_num : (0 : ℝ) ≤ 1 / 2) + (by norm_num : (1 / 2 : ℝ) < 1))) using 1 + simp + exact le_antisymm (ge_of_tendsto' hlim hb) (by positivity) + +end AffineTubes + +open InnerProductSpace + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/Conclusions.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/Conclusions.lean new file mode 100644 index 0000000000000000000000000000000000000000..4ae3fcd1a63563aa955ff09e30c91b713f5a8b87 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/Conclusions.lean @@ -0,0 +1,2 @@ +import OAI.Probability.PosteriorReplicas.Regression.MemoryBounds + diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/EuclideanNets.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/EuclideanNets.lean new file mode 100644 index 0000000000000000000000000000000000000000..19bbd443f06d7d4fbb6e96dd4dc7129290dbf393 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/EuclideanNets.lean @@ -0,0 +1,43 @@ +import OAI.Probability.PosteriorReplicas.Regression.FiniteNets +import OAI.Probability.PosteriorReplicas.Regression.FrostmanGeometry + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +section EuclideanNets + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem exists_unit_ball_net {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) : + ∃ s : Finset E, (∀ x ∈ s, ‖x‖ ≤ 1) ∧ + (s.card : ℝ) ≤ (3 / r) ^ Module.finrank ℝ E ∧ + ∀ x : E, ‖x‖ ≤ 1 → ∃ y ∈ s, dist x y ≤ r := by + classical + have hbound : ∀ s : Finset E, (∀ x ∈ s, ‖x‖ ≤ 1) → + (∀ x ∈ s, ∀ y ∈ s, x ≠ y → r < dist x y) → + (s.card : ℝ) ≤ (3 / r) ^ Module.finrank ℝ E := by + intro s hs hsep + refine (card_le_volume_ratio s hr zero_le_one hs + (fun x hx y hy hne => (hsep x hx y hy hne).le)).trans ?_ + apply pow_le_pow_left₀ (by positivity) + apply (div_le_div_iff₀ (by positivity : 0 < r / 2) hr).mpr + nlinarith + obtain ⟨s, hs, hsep, hnet⟩ := exists_net_of_finite_packing_bound + {x : E | ‖x‖ ≤ 1} hr.le ⌈(3 / r) ^ Module.finrank ℝ E⌉₊ + (by + intro s hs hsep + exact_mod_cast (hbound s hs hsep).trans (Nat.le_ceil _)) + exact ⟨s, hs, hbound s hs hsep, hnet⟩ + +end EuclideanNets + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/FiniteNets.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/FiniteNets.lean new file mode 100644 index 0000000000000000000000000000000000000000..2857d42079d5ed79aaaa26e3ce111a7e4f53ca8e --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/FiniteNets.lean @@ -0,0 +1,63 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +section FiniteNets + +variable {E : Type*} [PseudoMetricSpace E] + +theorem exists_net_of_finite_packing_bound (A : Set E) {r : ℝ} (hr : 0 ≤ r) (N : ℕ) + (hcard : ∀ s : Finset E, (∀ x ∈ s, x ∈ A) → + (∀ x ∈ s, ∀ y ∈ s, x ≠ y → r < dist x y) → s.card ≤ N) : + ∃ s : Finset E, (∀ x ∈ s, x ∈ A) ∧ + (∀ x ∈ s, ∀ y ∈ s, x ≠ y → r < dist x y) ∧ + ∀ x ∈ A, ∃ y ∈ s, dist x y ≤ r := by + classical + let S : Set ℕ := {n | ∃ s : Finset E, (∀ x ∈ s, x ∈ A) ∧ + (∀ x ∈ s, ∀ y ∈ s, x ≠ y → r < dist x y) ∧ s.card = n} + have hS : S.Finite := (Set.finite_Iic N).subset (by + rintro n ⟨s, hs, hsep, rfl⟩ + exact hcard s hs hsep) + have hS0 : S.Nonempty := ⟨0, ∅, by simp⟩ + obtain ⟨n, hn, hmax⟩ := Set.exists_max_image S id hS hS0 + obtain ⟨s, hs, hsep, rfl⟩ := hn + refine ⟨s, hs, hsep, ?_⟩ + intro x hx + by_contra! hnot + have hxs : x ∉ s := by + intro h + have := hnot x h + simpa using lt_of_le_of_lt hr this + have hins : ∀ y ∈ insert x s, y ∈ A := by + intro y hy + rcases Finset.mem_insert.mp hy with rfl | hy + · exact hx + · exact hs y hy + have hsep' : ∀ y ∈ insert x s, ∀ z ∈ insert x s, y ≠ z → r < dist y z := by + intro y hy z hz hne + rcases Finset.mem_insert.mp hy with hxy | hys + · subst y + rcases Finset.mem_insert.mp hz with hxz | hzs + · exact (hne hxz.symm).elim + · exact hnot z hzs + · rcases Finset.mem_insert.mp hz with hxz | hzs + · subst z + simpa [dist_comm] using hnot y hys + · exact hsep y hys z hzs hne + have hinS : (insert x s).card ∈ S := ⟨insert x s, hins, hsep', rfl⟩ + have hh := hmax _ hinS + simp only [id_eq, Finset.card_insert_of_notMem hxs] at hh + omega + +end FiniteNets + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/FrostmanGeometry.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/FrostmanGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..118c97b14eee9af8966e679253be54eb7a8fcc5f --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/FrostmanGeometry.lean @@ -0,0 +1,84 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +section FrostmanGeometry + +variable {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def HasLocalMassBound (ν : Measure E) (a : ℝ) : Prop := + ∀ t ∈ ν.support, ∀ r : ℝ, 0 < r → + ν (Metric.closedBall t r) ≤ ENNReal.ofReal (r ^ a) + +omit [BorelSpace E] in + +theorem HasLocalMassBound.any_center {ν : Measure E} {a : ℝ} + (hν : HasLocalMassBound ν a) (z : E) {r : ℝ} (hr : 0 < r) : + ν (Metric.closedBall z r) ≤ ENNReal.ofReal ((2 * r) ^ a) := by + by_cases hmass : ν (Metric.closedBall z r) = 0 + · simp [hmass] + obtain ⟨t, htball, htsupp⟩ := ν.nonempty_inter_support_of_pos (pos_iff_ne_zero.mpr hmass) + refine (measure_mono ?_).trans (hν t htsupp (2 * r) (by positivity)) + intro x hx + apply Metric.mem_closedBall.mpr + calc + dist x t ≤ dist x z + dist z t := dist_triangle _ _ _ + _ ≤ r + r := add_le_add (Metric.mem_closedBall.mp hx) + (by simpa [dist_comm] using Metric.mem_closedBall.mp htball) + _ = 2 * r := by ring + +theorem card_le_volume_ratio (s : Finset E) {r R : ℝ} (hr : 0 < r) (hR : 0 ≤ R) + (hs : ∀ x ∈ s, ‖x‖ ≤ R) + (hsep : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → r ≤ dist x y) : + (s.card : ℝ) ≤ ((R + r / 2) / (r / 2)) ^ Module.finrank ℝ E := by + classical + let ν : Measure E := Measure.addHaar + let δ : ℝ := r / 2 + let ρ : ℝ := R + r / 2 + have hδ : 0 < δ := by dsimp [δ]; positivity + have hρ : 0 < ρ := by dsimp [ρ]; positivity + let A : Set E := ⋃ c ∈ s, Metric.ball c δ + have hd : Set.Pairwise (s : Set E) (fun c d => Disjoint (Metric.ball c δ) (Metric.ball d δ)) := by + intro c hc d hd hcd + apply Metric.ball_disjoint_ball + simpa [δ] using hsep c hc d hd hcd + have hsub : A ⊆ Metric.ball (0 : E) ρ := by + refine iUnion₂_subset fun x hx => ?_ + apply Metric.ball_subset_ball' + dsimp [δ, ρ] + rw [dist_zero_right] + linarith [hs x hx] + have I : + (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ Module.finrank ℝ E) * ν (Metric.ball 0 1) ≤ + ENNReal.ofReal (ρ ^ Module.finrank ℝ E) * ν (Metric.ball 0 1) := by + calc + (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ Module.finrank ℝ E) * ν (Metric.ball 0 1) = ν A := by + dsimp only [A] + rw [measure_biUnion_finset hd (fun _ _ => Metric.isOpen_ball.measurableSet)] + simp only [ν.addHaar_ball_of_pos _ hδ, Finset.sum_const, nsmul_eq_mul, mul_assoc] + _ ≤ ν (Metric.ball (0 : E) ρ) := measure_mono hsub + _ = _ := ν.addHaar_ball_of_pos 0 hρ + have J : (s.card : ℝ≥0∞) * ENNReal.ofReal (δ ^ Module.finrank ℝ E) ≤ + ENNReal.ofReal (ρ ^ Module.finrank ℝ E) := + (ENNReal.mul_le_mul_iff_left (Metric.measure_ball_pos ν 0 zero_lt_one).ne' + measure_ball_lt_top.ne).mp I + have K : (s.card : ℝ) * δ ^ Module.finrank ℝ E ≤ ρ ^ Module.finrank ℝ E := by + simpa only [ENNReal.toReal_mul, ENNReal.toReal_natCast, + ENNReal.toReal_ofReal (pow_nonneg hδ.le _)] using + ENNReal.toReal_le_of_le_ofReal (pow_nonneg hρ.le _) J + rw [div_pow] + exact (le_div_iff₀ (pow_pos hδ _)).mpr K + +end FrostmanGeometry + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/Fubini.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/Fubini.lean new file mode 100644 index 0000000000000000000000000000000000000000..95324f42e89d38e3699db6aa4b103683aa824972 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/Fubini.lean @@ -0,0 +1,52 @@ +import OAI.Probability.PosteriorReplicas.Regression.SphereGeometry + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +section FubiniAux +variable {X Y Z : Type*} [MeasurableSpace X] [MeasurableSpace Y] [MeasurableSpace Z] + {μ : Measure X} {ν : Measure Y} [SFinite μ] [SFinite ν] +lemma ae_fiber_aemeasurable {f : X × Y → Z} (hf : AEMeasurable f (μ.prod ν)) : + ∀ᵐ y ∂ν, AEMeasurable (fun x => f (x,y)) μ := by + have he := Measure.ae_ae_of_ae_prod hf.prod_swap.ae_eq_mk + filter_upwards [he] with y hy + have hm : Measurable (fun x => hf.prod_swap.mk _ (y,x)) := + hf.prod_swap.measurable_mk.comp (measurable_const.prodMk measurable_id) + exact hm.aemeasurable.congr (Filter.EventuallyEq.symm hy) + +lemma prod_null_set_bound {S : Set (X × Y)} (hS : NullMeasurableSet S (μ.prod ν)) + {c : ℝ≥0∞} (h : ∀ᵐ y ∂ν, μ {x | (x,y) ∈ S} ≤ c) : + (μ.prod ν) S ≤ c * ν univ := by + have hm : AEMeasurable (S.indicator (fun _ => (1 : ℝ≥0∞))) (μ.prod ν) := + aemeasurable_const.indicator₀ hS + rw [← one_mul ((μ.prod ν) S), ← lintegral_indicator_const₀ hS 1, lintegral_prod_symm _ hm] + apply (lintegral_mono_ae ?_).trans_eq (lintegral_const c) + filter_upwards [h, ae_fiber_aemeasurable hm] with y hy hmy + have hs : NullMeasurableSet {x | (x,y) ∈ S} μ := by + have heq : {x | (x,y) ∈ S} = {x | S.indicator (fun _ => (1 : ℝ≥0∞)) (x,y) = 1} := by + ext x + by_cases hx : (x,y) ∈ S <;> simp [hx] + rw [heq] + exact nullMeasurableSet_eq_fun hmy aemeasurable_const + change (∫⁻ x, ({x | (x,y) ∈ S}).indicator (fun _ => (1 : ℝ≥0∞)) x ∂μ) ≤ c + simpa [lintegral_indicator_const₀ hs] using hy +end FubiniAux + +instance sampleLaw_probability (d T : ℕ) : IsProbabilityMeasure (sampleLaw d T) := by + unfold sampleLaw + infer_instance +instance uniformSphere_probability (d : ℕ) [NeZero d] : IsProbabilityMeasure (uniformSphere d) := by + change IsProbabilityMeasure (sphereLaw (E := Vector d)) + infer_instance + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianDomination.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianDomination.lean new file mode 100644 index 0000000000000000000000000000000000000000..879ca3d9824a8ddc72ca7e6cf75d66a283d25b3c --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianDomination.lean @@ -0,0 +1,141 @@ +import OAI.Probability.PosteriorReplicas.Regression.GramFactorization + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section GaussianDomination +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma orthonormal_gaussian_map {n : ℕ} {u : Fin n → E} (hu : Orthonormal ℝ u) : + (stdGaussian E).map (fun x => fun i => ⟪u i, x⟫) = + Measure.pi (fun _ : Fin n => gaussianReal 0 1) := by + let f : E → EuclideanSpace ℝ (Fin n) := fun x => WithLp.toLp 2 (fun i => ⟪u i, x⟫) + have hf : Measurable f := by dsimp [f]; fun_prop + have he : (stdGaussian E).map f = stdGaussian (EuclideanSpace ℝ (Fin n)) := by + apply Measure.ext_of_charFun + ext t + have hi (x : E) : ⟪f x, t⟫ = ⟪x, ∑ i, t i • u i⟫ := by + simp [f, PiLp.inner_apply, inner_sum, inner_smul_right, real_inner_comm x] + have hn : ‖∑ i, t i • u i‖ ^ 2 = ‖t‖ ^ 2 := by + rw [← real_inner_self_eq_norm_sq, hu.inner_sum, EuclideanSpace.real_norm_sq_eq] + simp [pow_two] + rw [charFun_apply, integral_map hf.aemeasurable (by fun_prop)] + simp_rw [hi] + change charFun (stdGaussian E) (∑ i, t i • u i) = _ + rw [charFun_stdGaussian, charFun_stdGaussian] + congr 2 + exact_mod_cast congrArg Neg.neg hn + have h := congrArg (Measure.map (WithLp.ofLp : EuclideanSpace ℝ (Fin n) → (Fin n → ℝ))) he + rw [← map_pi_eq_stdGaussian] at h + simpa [Measure.map_map (WithLp.measurable_ofLp _ _) hf, + Measure.map_map (WithLp.measurable_ofLp _ _) (WithLp.measurable_toLp _ _), + Function.comp_def, f, WithLp.ofLp_toLp, Measure.map_id] using h + +lemma gaussianReal_le_volume : gaussianReal 0 1 ≤ (volume : Measure ℝ) := by + rw [gaussianReal_of_var_ne_zero _ (by norm_num)] + conv_rhs => rw [← withDensity_one (μ := (volume : Measure ℝ))] + apply withDensity_mono + filter_upwards [] with x + change ENNReal.ofReal (gaussianPDFReal 0 1 x) ≤ 1 + rw [← ENNReal.ofReal_one] + apply ENNReal.ofReal_le_ofReal + unfold gaussianPDFReal + have hs : 1 ≤ Real.sqrt (2 * Real.pi * (1 : ℝ≥0)) := by + norm_num only [NNReal.coe_one, mul_one] + apply (Real.le_sqrt (by norm_num) (by positivity)).mpr + nlinarith [Real.pi_gt_three] + have he : Real.exp (-(x - 0)^2 / (2 * (1 : ℝ≥0))) ≤ 1 := by + apply Real.exp_le_one_iff.mpr + exact div_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (sq_nonneg _)) (by positivity) + exact (mul_le_of_le_one_left (by positivity) (inv_le_one_of_one_le₀ hs)).trans he +lemma measure_pi_mono {ι : Type*} [Fintype ι] {X : ι → Type*} + [∀ i, MeasurableSpace (X i)] {μ ν : ∀ i, Measure (X i)} + (h : ∀ i, μ i ≤ ν i) : Measure.pi μ ≤ Measure.pi ν := by + have ho : OuterMeasure.pi (fun i => (μ i).toOuterMeasure) ≤ + OuterMeasure.pi (fun i => (ν i).toOuterMeasure) := by + apply OuterMeasure.le_pi.mpr + intro s _ + exact (OuterMeasure.pi_pi_le _ s).trans (Finset.prod_le_prod fun i _ => h i (s i)) + apply Measure.le_iff.mpr + intro s hs + rw [Measure.pi_def, Measure.pi_def, toMeasure_apply _ _ hs, toMeasure_apply _ _ hs] + exact ho s + +lemma pi_gaussianReal_le_volume (n : ℕ) : + Measure.pi (fun _ : Fin n => gaussianReal 0 1) ≤ (volume : Measure (Fin n → ℝ)) := + measure_pi_mono (fun _ => gaussianReal_le_volume) +lemma gaussian_pairings_le {n : ℕ} (v : Fin n → E) (hv : LinearIndependent ℝ v) : + (stdGaussian E).map (fun x => fun i => ⟪v i, x⟫) ≤ + ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹) • + (volume : Measure (Fin n → ℝ)) := by + let u := gramSchmidtNormed ℝ v + let R : Matrix (Fin n) (Fin n) ℝ := + Matrix.diagonal (fun i => ‖gramSchmidt ℝ v i‖) * gsUpper n v + have hu : Orthonormal ℝ u := gramSchmidtNormed_orthonormal hv + have hn (i : Fin n) : ‖gramSchmidt ℝ v i‖ ≠ 0 := + norm_ne_zero_iff.mpr (gramSchmidt_ne_zero i hv) + have hexp (j : Fin n) : ∑ i, R i j • u i = v j := by + rw [← gsUpper_expansion n v j] + apply Finset.sum_congr rfl + intro i _ + simp only [R, u, Matrix.diagonal_mul, gramSchmidtNormed, smul_smul] + congr 1 + simp [hn i, mul_comm] + have hdet : R.transpose.det = ∏ i, ‖gramSchmidt ℝ v i‖ := by + dsimp only [R] + rw [Matrix.det_transpose, Matrix.det_mul, Matrix.det_diagonal, gsUpper_det, mul_one] + have hd : R.transpose.det ≠ 0 := by + rw [hdet] + exact Finset.prod_ne_zero_iff.mpr (fun i _ => hn i) + have hpos : 0 ≤ R.transpose.det := by rw [hdet]; positivity + have hf : Measurable (Matrix.toLin' R.transpose) := + (Matrix.toLin' R.transpose).continuous_of_finiteDimensional.measurable + have heq : (fun x : E => fun j => ⟪v j, x⟫) = + (Matrix.toLin' R.transpose) ∘ (fun x => fun i => ⟪u i, x⟫) := by + funext x j + rw [← hexp j] + simp [Matrix.toLin'_apply, Matrix.mulVec, dotProduct, sum_inner, + inner_smul_left] + rw [heq, ← Measure.map_map hf (by fun_prop), orthonormal_gaussian_map hu] + calc + _ ≤ (volume : Measure (Fin n → ℝ)).map (Matrix.toLin' R.transpose) := + Measure.map_mono (pi_gaussianReal_le_volume n) hf + _ = _ := by + rw [Real.map_matrix_volume_pi_eq_smul_volume_pi hd, + abs_of_nonneg (inv_nonneg.mpr hpos), hdet] +lemma measure_pi_smul {ι : Type*} [Fintype ι] {X : ι → Type*} + [∀ i, MeasurableSpace (X i)] (μ : ∀ i, Measure (X i)) [∀ i, SigmaFinite (μ i)] + (c : ℝ≥0∞) (hc : c ≠ ∞) : + Measure.pi (fun i => c • μ i) = c ^ Fintype.card ι • Measure.pi μ := by + lift c to ℝ≥0 using hc + simp_rw [Measure.coe_nnreal_smul] + apply Measure.pi_eq + intro s _ + simp only [Measure.smul_apply, Measure.pi_pi, ENNReal.smul_def, smul_eq_mul, Finset.prod_mul_distrib, + Finset.prod_const, Finset.card_univ] + +lemma gaussian_rows_pairings_le {n : ℕ} (v : Fin n → E) (hv : LinearIndependent ℝ v) + (m : ℕ) : + (Measure.pi (fun _ : Fin m => stdGaussian E)).map + (fun A => fun j i => ⟪v i, A j⟫) ≤ + ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) • + (volume : Measure (Fin m → Fin n → ℝ)) := by + rw [Measure.pi_map_pi (fun _ => (by fun_prop : Measurable + (fun x : E => fun i => ⟪v i, x⟫)).aemeasurable)] + have h := measure_pi_mono (fun _ : Fin m => gaussian_pairings_le v hv) + rw [measure_pi_smul _ _ ENNReal.ofReal_ne_top] at h + rw [ENNReal.ofReal_pow (by positivity)] + simpa only [Fintype.card_fin, volume_pi] using h +end GaussianDomination + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianKernel.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..fa1e9c2083d34d1d02e5dcf6d5006c7404e850f1 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianKernel.lean @@ -0,0 +1,77 @@ +import OAI.Probability.PosteriorReplicas.Regression.GaussianDomination +import OAI.Probability.PosteriorReplicas.Regression.ReplicaKernel + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section GaussianKernel +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussian_rows_kernel_bound {n : ℕ} (v : Fin n → E) (hv : LinearIndependent ℝ v) + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ z, φ z = 1) + (m : ℕ) (y : Fin m → ℝ) : + ∫⁻ A : Fin m → E, (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫) + ∂Measure.pi (fun _ => stdGaussian E) ≤ + ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) * ∏ j, φ (y j) := by + let H : (Fin m → Fin n → ℝ) → ℝ≥0∞ := + fun z => ∏ j, φ (y j) * ∏ i, φ (y j - z j i) + have hH : Measurable H := by dsimp [H]; fun_prop + have heq (A : Fin m → E) : + (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫) = + H (fun j i => ⟪v i, A j⟫) := by + dsimp [H] + rw [Finset.prod_mul_distrib, Finset.prod_comm] + simp_rw [heq] + rw [← lintegral_map hH (by fun_prop)] + calc + _ ≤ ∫⁻ z, H z ∂(ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) • + (volume : Measure (Fin m → Fin n → ℝ))) := + lintegral_mono' (gaussian_rows_pairings_le v hv m) (fun _ => le_rfl) + _ = _ := by + rw [lintegral_smul_measure] + change _ * (∫⁻ z : Fin m → Fin n → ℝ, ∏ j, φ (y j) * ∏ i, φ (y j - z j i)) = _ + rw [lintegral_product_differences φ hφ hφ1] + +lemma gaussian_replica_kernel_bound {n : ℕ} (p : E) (v : Fin n → E) + (hv : LinearIndependent ℝ (fun i => v i - p)) + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ z, φ z = 1) (m : ℕ) : + ∫⁻ A : Fin m → E, ∫⁻ y : Fin m → ℝ, + (∏ j, φ (y j - ⟪p, A j⟫)) * ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫) + ∂volume ∂Measure.pi (fun _ => stdGaussian E) ≤ + ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ (fun i => v i - p) i‖)⁻¹ ^ m) := by + have ht (A : Fin m → E) : + (∫⁻ y : Fin m → ℝ, (∏ j, φ (y j - ⟪p, A j⟫)) * + ∏ i, ∏ j, φ (y j - ⟪v i, A j⟫)) = + ∫⁻ y : Fin m → ℝ, (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i - p, A j⟫) := by + have he (y : Fin m → ℝ) (i : Fin n) (j : Fin m) : + y j - ⟪p, A j⟫ - ⟪v i - p, A j⟫ = y j - ⟪v i, A j⟫ := by + rw [inner_sub_left] + ring + simpa only [Pi.sub_apply, he] using + lintegral_sub_right_eq_self + (fun y : Fin m → ℝ => (∏ j, φ (y j)) * ∏ i, ∏ j, φ (y j - ⟪v i - p, A j⟫)) + (fun j => ⟪p, A j⟫) + simp_rw [ht] + rw [lintegral_lintegral_swap (by fun_prop)] + calc + _ ≤ ∫⁻ y : Fin m → ℝ, + ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ (fun i => v i - p) i‖)⁻¹ ^ m) * + ∏ j, φ (y j) := lintegral_mono fun y => + gaussian_rows_kernel_bound (fun i => v i - p) hv φ hφ hφ1 m y + _ = _ := by + rw [lintegral_const_mul _ (by fun_prop), volume_pi, + lintegral_fin_prod volume m (fun _ => φ) (fun _ => hφ)] + simp [hφ1] +end GaussianKernel + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianNoise.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianNoise.lean new file mode 100644 index 0000000000000000000000000000000000000000..05a7b7e3b393300de433ac8d0272066b97994121 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/GaussianNoise.lean @@ -0,0 +1,59 @@ +import OAI.Probability.PosteriorReplicas.Regression.ProductDensity + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section GaussianNoise +lemma pi_gaussian_map_scale (m : ℕ) (δ : ℝ) : + (Measure.pi (fun _ : Fin m => gaussianReal 0 1)).map + (fun u => fun j => δ * u j) = + Measure.pi (fun _ : Fin m => gaussianReal 0 (NNReal.mk (δ^2) (sq_nonneg δ))) := by + rw [Measure.pi_map_pi (f := fun _ : Fin m => fun x : ℝ => δ * x) + (fun _ => (by fun_prop : Measurable (fun x : ℝ => δ * x)).aemeasurable)] + simp_rw [gaussianReal_map_const_mul, mul_zero, mul_one] + +lemma pi_gaussian_withDensity (m : ℕ) (v : ℝ≥0) (hv : v ≠ 0) : + Measure.pi (fun _ : Fin m => gaussianReal 0 v) = + (volume : Measure (Fin m → ℝ)).withDensity (fun y => ∏ j, gaussianPDF 0 v (y j)) := by + simp_rw [gaussianReal_of_var_ne_zero _ hv] + have : SigmaFinite ((volume : Measure ℝ).withDensity (gaussianPDF 0 v)) := by + rw [← gaussianReal_of_var_ne_zero 0 hv] + infer_instance + rw [measure_pi_withDensity (volume : Measure ℝ) m + (fun _ => gaussianPDF 0 v) (fun _ => measurable_gaussianPDF 0 v)] + rfl +lemma lintegral_gaussian_shift_scale (m : ℕ) (δ : ℝ) (hδ : δ ≠ 0) + (a : Fin m → ℝ) (f : (Fin m → ℝ) → ℝ≥0∞) (hf : Measurable f) : + ∫⁻ u : Fin m → ℝ, f (fun j => a j + δ * u j) + ∂Measure.pi (fun _ => gaussianReal 0 1) = + ∫⁻ y : Fin m → ℝ, (∏ j, gaussianPDF 0 (NNReal.mk (δ^2) (sq_nonneg δ)) (y j - a j)) * f y := by + let v : ℝ≥0 := NNReal.mk (δ^2) (sq_nonneg δ) + have hv : v ≠ 0 := by + rw [← NNReal.coe_ne_zero] + exact pow_ne_zero 2 hδ + have he : + (∫⁻ u : Fin m → ℝ, f (fun j => a j + δ * u j) + ∂Measure.pi (fun _ => gaussianReal 0 1)) = + ∫⁻ y : Fin m → ℝ, f (a + y) ∂Measure.pi (fun _ => gaussianReal 0 v) := by + rw [← pi_gaussian_map_scale m δ, lintegral_map (by fun_prop) (by fun_prop)] + rfl + rw [he, pi_gaussian_withDensity m v hv, + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) (by fun_prop)] + have hh (y : Fin m → ℝ) : + (∏ j, gaussianPDF 0 v (y j)) * f (a + y) = + (fun z : Fin m → ℝ => (∏ j, gaussianPDF 0 v (z j - a j)) * f z) (a + y) := by + simp only [Pi.add_apply, add_sub_cancel_left] + exact (lintegral_congr (μ := volume) hh).trans (lintegral_add_left_eq_self + (μ := volume) (fun z : Fin m → ℝ => (∏ j, gaussianPDF 0 v (z j - a j)) * f z) a) +end GaussianNoise + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/GramDistances.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/GramDistances.lean new file mode 100644 index 0000000000000000000000000000000000000000..07bfd0edc914ec6c1b3d0dcbb633d796031ff51c --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/GramDistances.lean @@ -0,0 +1,122 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section GramDistances +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] {n : ℕ} +omit [FiniteDimensional ℝ E] in +lemma sub_gramSchmidt_mem_span (v : Fin n → E) (j : Fin n) : + v j - gramSchmidt ℝ v j ∈ Submodule.span ℝ (v '' Set.Iio j) := by + rw [← span_gramSchmidt_Iio ℝ v j] + conv => arg 2; lhs; rw [gramSchmidt_def'' ℝ v j] + rw [add_sub_cancel_left] + exact Submodule.sum_mem _ fun i hi => Submodule.smul_mem _ _ + (Submodule.subset_span ⟨i, Finset.mem_Iio.mp hi, rfl⟩) + +omit [FiniteDimensional ℝ E] in +lemma gramSchmidt_mem_span_orthogonal (v : Fin n → E) (j : Fin n) : + gramSchmidt ℝ v j ∈ (Submodule.span ℝ (v '' Set.Iio j))ᗮ := by + rw [Submodule.mem_orthogonal'] + intro w hw + induction hw using Submodule.span_induction with + | mem x hx => + rcases hx with ⟨i, hi, rfl⟩ + exact gramSchmidt_inv_triangular ℝ v hi + | zero => simp + | add x y _ _ hx hy => simp [inner_add_right, hx, hy] + | smul c x _ hx => simp [inner_smul_right, hx] + +lemma gramSchmidt_eq_sub_starProjection (v : Fin n → E) (j : Fin n) : + gramSchmidt ℝ v j = v j - + (Submodule.span ℝ (v '' Set.Iio j)).starProjection (v j) := by + have h := (Submodule.span ℝ (v '' Set.Iio j)).eq_starProjection_of_mem_orthogonal + (u := v j) (sub_gramSchmidt_mem_span v j) + (by simpa using gramSchmidt_mem_span_orthogonal v j) + rw [h, sub_sub_cancel] + +lemma norm_gramSchmidt_eq_infDist (v : Fin n → E) (j : Fin n) : + ‖gramSchmidt ℝ v j‖ = Metric.infDist (v j) + (Submodule.span ℝ (v '' Set.Iio j) : Set E) := by + rw [gramSchmidt_eq_sub_starProjection, Submodule.starProjection_minimal, + Metric.infDist_eq_iInf] + simp only [dist_eq_norm] + rfl +lemma infDist_affine_mk' (p x : E) (K : Submodule ℝ E) : + Metric.infDist x (AffineSubspace.mk' p K : Set E) = + Metric.infDist (x - p) (K : Set E) := by + rw [← EuclideanGeometry.dist_orthogonalProjection_eq_infDist, + EuclideanGeometry.orthogonalProjection_apply_mem _ (AffineSubspace.self_mem_mk' p K), + dist_eq_norm, Metric.infDist_eq_iInf] + simp only [dist_eq_norm] + change ‖x - _‖ = ⨅ y : K, ‖(x - p) - y‖ + rw [← Submodule.starProjection_minimal] + simp only [AffineSubspace.direction_mk', vsub_eq_sub, vadd_eq_add, + Submodule.coe_orthogonalProjectionOnto_apply] + congr 1 + abel + +lemma norm_gramSchmidt_sub_eq_affine_infDist (p : E) (t : Fin n → E) (j : Fin n) : + ‖gramSchmidt ℝ (fun i => t i - p) j‖ = + Metric.infDist (t j) (AffineSubspace.mk' p + (Submodule.span ℝ ((fun i => t i - p) '' Set.Iio j)) : Set E) := by + rw [infDist_affine_mk', norm_gramSchmidt_eq_infDist] + +omit [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] in +lemma image_Iio_castSucc (v : Fin (n+1) → E) (j : Fin n) : + v '' Set.Iio j.castSucc = (fun i => v i.castSucc) '' Set.Iio j := by + ext x + constructor + · rintro ⟨i, hi, rfl⟩ + have hin : i.val < n := lt_trans hi j.isLt + exact ⟨⟨i.val, hin⟩, hi, rfl⟩ + · rintro ⟨i, hi, rfl⟩ + exact ⟨i.castSucc, hi, rfl⟩ + +omit [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] in +lemma image_Iio_last (v : Fin (n+1) → E) : + v '' Set.Iio (Fin.last n) = Set.range (fun i : Fin n => v i.castSucc) := by + ext x + constructor + · rintro ⟨i, hi, rfl⟩ + exact ⟨⟨i.val, hi⟩, rfl⟩ + · rintro ⟨i, rfl⟩ + exact ⟨i.castSucc, i.isLt, rfl⟩ + +lemma gramSchmidt_castSucc (v : Fin (n+1) → E) (j : Fin n) : + gramSchmidt ℝ v j.castSucc = gramSchmidt ℝ (fun i => v i.castSucc) j := by + rw [gramSchmidt_eq_sub_starProjection, gramSchmidt_eq_sub_starProjection, + image_Iio_castSucc] + +variable [MeasurableSpace E] [BorelSpace E] +lemma measurable_gramSchmidt (j : Fin n) : + Measurable (fun v : Fin n → E => gramSchmidt ℝ v j) := by + refine (wellFounded_lt : WellFounded ((· < ·) : Fin n → Fin n → Prop)).induction + (C := fun j : Fin n => Measurable (fun v : Fin n → E => gramSchmidt ℝ v j)) j ?_ + intro j ih + have heq : (fun v : Fin n → E => gramSchmidt ℝ v j) = + fun v => v j - ∑ i ∈ Finset.Iio j, + (⟪gramSchmidt ℝ v i, v j⟫ / ‖gramSchmidt ℝ v i‖ ^ 2) • gramSchmidt ℝ v i := by + ext v + rw [gramSchmidt_def] + simp only [Submodule.starProjection_singleton] + rfl + rw [heq] + apply (measurable_pi_apply j).sub + apply Finset.measurable_sum + intro i hi + have hi' := ih i (Finset.mem_Iio.mp hi) + exact ((hi'.inner (measurable_pi_apply j)).div (hi'.norm.pow_const 2)).smul hi' +end GramDistances + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/GramFactorization.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/GramFactorization.lean new file mode 100644 index 0000000000000000000000000000000000000000..57e1aa2e14cf6799a31d45f6e8106952775e6de0 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/GramFactorization.lean @@ -0,0 +1,74 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section GramFactorization +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + {ι : Type*} [Fintype ι] +lemma gram_linear_combination (w : ι → E) (T : Matrix ι ι ℝ) : + Matrix.gram ℝ (fun j => ∑ i, (T i j) • w i) = + T.transpose * Matrix.gram ℝ w * T := by + ext a b + simp only [Matrix.gram_apply, sum_inner, inner_sum, real_inner_smul_left, + real_inner_smul_right, Matrix.mul_apply, Matrix.transpose_apply] + simp only [Finset.sum_mul] + congr 1 + ext j + congr 1 + ext i + ring + +variable (n : ℕ) +def gsUpper (v : Fin n → E) : Matrix (Fin n) (Fin n) ℝ := fun i j => + (if i = j then 1 else 0) + + if i < j then ⟪gramSchmidt ℝ v i, v j⟫ / ‖gramSchmidt ℝ v i‖ ^ 2 else 0 + +lemma gsUpper_expansion (v : Fin n → E) (j : Fin n) : + ∑ i, (gsUpper n v i j) • gramSchmidt ℝ v i = v j := by + simp only [gsUpper, add_smul, Finset.sum_add_distrib] + simp only [ite_smul, one_smul, zero_smul, Finset.sum_ite_eq', Finset.mem_univ, ite_true] + conv_rhs => rw [gramSchmidt_def'' ℝ v j] + congr 1 + rw [← Finset.sum_filter] + congr 1 + ext i + simp + +lemma gsUpper_det (v : Fin n → E) : (gsUpper n v).det = 1 := by + have htri : (gsUpper n v).IsUpperTriangular := by + intro i j hij + change j < i at hij + simp [gsUpper, (ne_of_gt hij), (not_lt_of_ge hij.le)] + rw [Matrix.det_of_isUpperTriangular htri] + simp [gsUpper] + +lemma gram_gramSchmidt_diagonal (v : Fin n → E) : + Matrix.gram ℝ (gramSchmidt ℝ v) = Matrix.diagonal (fun i => ‖gramSchmidt ℝ v i‖ ^ 2) := by + ext i j + by_cases hij : i = j + · subst j + simp [Matrix.gram_apply] + · simp [Matrix.gram_apply, hij, + gramSchmidt_orthogonal ℝ v hij] + +theorem det_gram_eq_prod_gramSchmidt (v : Fin n → E) : + (Matrix.gram ℝ v).det = ∏ i, ‖gramSchmidt ℝ v i‖ ^ 2 := by + have hv : (fun j => ∑ i, (gsUpper n v i j) • gramSchmidt ℝ v i) = v := + funext (gsUpper_expansion n v) + have h := gram_linear_combination (gramSchmidt ℝ v) (gsUpper n v) + rw [hv] at h + rw [h, Matrix.det_mul, Matrix.det_mul, Matrix.det_transpose, gsUpper_det, + one_mul, mul_one, gram_gramSchmidt_diagonal, Matrix.det_diagonal] +end GramFactorization + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/HolderSet.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/HolderSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c0939f7bcb5a1b4482be0ab9436304d562a95fc --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/HolderSet.lean @@ -0,0 +1,34 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section HolderSet +variable {X : Type*} [MeasurableSpace X] (μ : Measure X) +lemma withDensity_apply_le_moment (f : X → ℝ≥0∞) (hf : Measurable f) + {p : ℝ} (hp : 1 < p) {C : ℝ≥0∞} + (hC : ∫⁻ x, f x ^ p ∂μ ≤ C) (S : Set X) (hS : MeasurableSet S) : + μ.withDensity f S ≤ C^(1/p) * (μ S)^(1 - 1/p) := by + have hpq := Real.HolderConjugate.conjExponent hp + have h := ENNReal.lintegral_mul_le_Lp_mul_Lq (μ.restrict S) hpq + hf.aemeasurable (aemeasurable_const (b := (1 : ℝ≥0∞))) + have he : 1 / (Real.conjExponent p) = 1 - 1/p := by + have hh := hpq.inv_add_inv_eq_one + simpa only [one_div] using (eq_sub_of_add_eq' hh) + simp only [Pi.mul_apply, mul_one, ENNReal.one_rpow, lintegral_const, + Measure.restrict_apply_univ, one_mul, he] at h + rw [withDensity_apply _ hS] + exact h.trans (mul_le_mul' (ENNReal.rpow_le_rpow + ((lintegral_mono' Measure.restrict_le_self (fun _ => le_rfl)).trans hC) (by positivity)) le_rfl) +end HolderSet + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/InverseMoments.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/InverseMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..f1c53435c19686291abfa5a627e2637f0450fe4f --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/InverseMoments.lean @@ -0,0 +1,109 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +section InverseMoments + +variable {X : Type*} [MeasurableSpace X] + +omit [MeasurableSpace X] in +lemma inverse_pow_dyadic_majorant (f : X → ℝ) (m : ℕ) (hf : ∀ x, 0 ≤ f x) (x : X) : + ENNReal.ofReal ((f x)⁻¹ ^ m) ≤ + 1 + ∑' k : ℕ, ({x | f x ≤ (1 / 2 : ℝ) ^ k}).indicator + (fun _ => ENNReal.ofReal ((2 : ℝ) ^ (m * (k + 1)))) x := by + classical + by_cases hzero : f x = 0 + · simp only [hzero, inv_zero] + exact le_add_of_le_left (by cases m <;> simp) + have hxpos : 0 < f x := lt_of_le_of_ne (hf x) (Ne.symm hzero) + by_cases hxone : 1 ≤ f x + · apply le_add_of_le_left + have h : (f x)⁻¹ ^ m ≤ 1 := + pow_le_one₀ (inv_nonneg.mpr (hf x)) (inv_le_one_of_one_le₀ hxone) + simpa using ENNReal.ofReal_le_ofReal h + obtain ⟨k, hklo, hkhi⟩ := exists_nat_pow_near_of_lt_one hxpos + (le_of_not_ge hxone) (by norm_num : (0 : ℝ) < 1 / 2) (by norm_num : (1 / 2 : ℝ) < 1) + have hinv : (f x)⁻¹ ≤ (2 : ℝ) ^ (k + 1) := by + have h := (inv_le_inv₀ hxpos (pow_pos (by norm_num : (0 : ℝ) < 1 / 2) _)).2 hklo.le + simpa using h + have hpow : ENNReal.ofReal ((f x)⁻¹ ^ m) ≤ + ENNReal.ofReal ((2 : ℝ) ^ (m * (k + 1))) := by + apply ENNReal.ofReal_le_ofReal + simpa [← pow_mul, Nat.mul_comm] using pow_le_pow_left₀ (inv_nonneg.mpr (hf x)) hinv m + calc + ENNReal.ofReal ((f x)⁻¹ ^ m) ≤ ENNReal.ofReal ((2 : ℝ) ^ (m * (k + 1))) := hpow + _ = ({x | f x ≤ (1 / 2 : ℝ) ^ k}).indicator + (fun _ => ENNReal.ofReal ((2 : ℝ) ^ (m * (k + 1)))) x := by + rw [Set.indicator_of_mem (show x ∈ {x | f x ≤ (1 / 2 : ℝ) ^ k} from hkhi)] + _ ≤ ∑' j : ℕ, ({x | f x ≤ (1 / 2 : ℝ) ^ j}).indicator + (fun _ => ENNReal.ofReal ((2 : ℝ) ^ (m * (j + 1)))) x := + ENNReal.le_tsum (f := fun index : ℕ => + ({point | f point ≤ (1 / 2 : ℝ) ^ index}).indicator + (fun _ => ENNReal.ofReal ((2 : ℝ) ^ (m * (index + 1)))) x) k + _ ≤ 1 + ∑' j : ℕ, ({x | f x ≤ (1 / 2 : ℝ) ^ j}).indicator + (fun _ => ENNReal.ofReal ((2 : ℝ) ^ (m * (j + 1)))) x := le_add_left le_rfl + +lemma dyadic_power_cancel (m k : ℕ) : + (2 : ℝ) ^ (m * (k + 1)) * ((1 / 2 : ℝ) ^ k) ^ (m + 1) = + (2 : ℝ) ^ m * (1 / 2 : ℝ) ^ k := by + rw [Nat.mul_add, mul_one, pow_add, pow_succ] + have h : (2 : ℝ) ^ (m * k) * ((1 / 2 : ℝ) ^ k) ^ m = 1 := by + rw [Nat.mul_comm m k, pow_mul, ← mul_pow, ← mul_pow] + norm_num + calc + 2 ^ (m * k) * 2 ^ m * (((1 / 2 : ℝ) ^ k) ^ m * (1 / 2 : ℝ) ^ k) = + (2 ^ (m * k) * ((1 / 2 : ℝ) ^ k) ^ m) * (2 ^ m * (1 / 2 : ℝ) ^ k) := by ring + _ = _ := by rw [h, one_mul] + +theorem inverse_moment_of_tube_bound (μ : Measure X) (f : X → ℝ) (m : ℕ) + (hf : Measurable f) (hnonneg : ∀ x, 0 ≤ f x) (C : ℝ≥0∞) + (htube : ∀ r : ℝ, 0 < r → r ≤ 1 → + μ {x | f x ≤ r} ≤ C * ENNReal.ofReal (r ^ (m + 1))) : + ∫⁻ x, ENNReal.ofReal ((f x)⁻¹ ^ m) ∂μ ≤ + μ Set.univ + C * (2 : ℝ≥0∞) ^ (m + 1) := by + classical + let g : ℕ → X → ℝ≥0∞ := fun k => + ({x | f x ≤ (1 / 2 : ℝ) ^ k}).indicator + (fun _ => ENNReal.ofReal ((2 : ℝ) ^ (m * (k + 1)))) + have hg : ∀ k, Measurable (g k) := fun k => + measurable_const.indicator (measurableSet_le hf measurable_const) + calc + ∫⁻ x, ENNReal.ofReal ((f x)⁻¹ ^ m) ∂μ ≤ ∫⁻ x, 1 + ∑' k, g k x ∂μ := + lintegral_mono (inverse_pow_dyadic_majorant f m hnonneg) + _ = μ Set.univ + ∑' k, ∫⁻ x, g k x ∂μ := by + rw [lintegral_add_left measurable_const, lintegral_const, one_mul, lintegral_tsum (fun k => (hg k).aemeasurable)] + _ ≤ μ Set.univ + ∑' k, C * ENNReal.ofReal ((2 : ℝ) ^ m * (1 / 2 : ℝ) ^ k) := by + apply add_le_add le_rfl + apply ENNReal.tsum_le_tsum + intro k + dsimp only [g] + rw [lintegral_indicator (measurableSet_le hf measurable_const), lintegral_const, + Measure.restrict_apply_univ] + calc + ENNReal.ofReal ((2 : ℝ) ^ (m * (k + 1))) * μ {x | f x ≤ (1 / 2 : ℝ) ^ k} ≤ + ENNReal.ofReal ((2 : ℝ) ^ (m * (k + 1))) * + (C * ENNReal.ofReal (((1 / 2 : ℝ) ^ k) ^ (m + 1))) := by + gcongr + exact htube _ (by positivity) (pow_le_one₀ (by norm_num) (by norm_num)) + _ = _ := by + rw [← mul_assoc, mul_comm _ C, mul_assoc, ← ENNReal.ofReal_mul (by positivity), + dyadic_power_cancel] + _ = μ Set.univ + C * (2 : ℝ≥0∞) ^ (m + 1) := by + simp_rw [ENNReal.ofReal_mul (by positivity : (0 : ℝ) ≤ 2 ^ m), + ENNReal.ofReal_pow (by norm_num : (0 : ℝ) ≤ 1 / 2), + ENNReal.ofReal_pow (by norm_num : (0 : ℝ) ≤ 2)] + rw [ENNReal.tsum_mul_left, ENNReal.tsum_mul_left, ENNReal.tsum_geometric] + norm_num [pow_succ, mul_assoc, ENNReal.ofReal_div_of_pos] + +end InverseMoments + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/LabelDependence.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/LabelDependence.lean new file mode 100644 index 0000000000000000000000000000000000000000..cf111f6ad761dafcccca8b4dffe8b560ccddf4f8 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/LabelDependence.lean @@ -0,0 +1,94 @@ +import OAI.Probability.PosteriorReplicas.Regression.Fubini +import OAI.Probability.PosteriorReplicas.Regression.LearnerBasics + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +namespace Learner +lemma run_congr_labels {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (s t : UnitSphere d) (ω : Ω) (x : Samples d T) + (h : ∀ i, ⟪x i,s.val⟫ = ⟪x i,t.val⟫) (n : ℕ) : + L.run s ω x n = L.run t ω x n := by + induction n with + | zero => rfl + | succ n ih => + simp only [run, ih] + split + · rfl + · split + · rw [h] + · rfl + +lemma estimate_congr_labels {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (s t : UnitSphere d) (ω : Ω) (x : Samples d T) + (h : ∀ i, ⟪x i,s.val⟫ = ⟪x i,t.val⟫) : L.estimate s ω x = L.estimate t ω x := by + simp only [estimate, terminal, run_congr_labels L s t ω x h] + +lemma angularSuccess_nullMeasurable {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) (ε : ℝ) (hL : L.Admissible ρ) : + NullMeasurableSet {z : UnitSphere d × (Ω × Samples d T) | + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := by + apply nullMeasurableSet_le _ aemeasurable_const + exact Real.continuous_arccos.measurable.comp_aemeasurable + ((measurable_subtype_coe.comp_aemeasurable hL.uniform_experiment).inner + (measurable_subtype_coe.comp measurable_fst).aemeasurable) + +lemma linear_success_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hd : 0 < d) (hT : 4*T ≤ d) {ε : ℝ} (hε : ε ≤ 1/10) (hL : L.Admissible ρ) : + L.uniformSuccess ρ ε ≤ ENNReal.ofReal (21/32 : ℝ) := by + classical + let : NeZero d := ⟨hd.ne'⟩ + have hmeas := ae_fiber_aemeasurable hL.uniform_experiment + unfold uniformSuccess + refine (prod_null_set_bound (L.angularSuccess_nullMeasurable ρ ε hL) + (c := ENNReal.ofReal (21/32 : ℝ)) ?_).trans_eq (by simp) + filter_upwards [hmeas] with z hz + let U : Submodule ℝ (Vector d) := Submodule.span ℝ (Set.range z.2) + have hdim : Module.finrank ℝ U ≤ T := by + have h := finrank_span_le_card (R := ℝ) (Set.range z.2) + apply h.trans + rw [Set.toFinset_range] + exact (Finset.card_image_le).trans_eq (by simp) + have hU : 4 * Module.finrank ℝ U ≤ Module.finrank ℝ (Vector d) := by + simpa only [Vector, finrank_euclideanSpace_fin] using (Nat.mul_le_mul_left 4 hdim).trans hT + change sphereLaw {s : UnitSphere d | angularError s (L.estimate s z.1 z.2) ≤ ε} ≤ _ + apply sphere_reflection_success_bound U hU + · exact nullMeasurableSet_le + (Real.continuous_arccos.measurable.comp_aemeasurable + ((measurable_subtype_coe.comp_aemeasurable hz).inner measurable_subtype_coe.aemeasurable)) + aemeasurable_const + · intro s hs ht + let t := sphereIsometry U.reflection s + have he : L.estimate s z.1 z.2 = L.estimate t z.1 z.2 := by + apply L.estimate_congr_labels + intro i + have hi : z.2 i ∈ U := Submodule.subset_span (Set.mem_range_self i) + have he := U.reflection.inner_map_map (z.2 i) s.val + rw [(Submodule.reflection_eq_self_iff (z.2 i)).2 hi] at he + exact he.symm + have hs' : dist s.val (L.estimate s z.1 z.2).val ≤ ε := by + apply (chord_le_arccos s (L.estimate s z.1 z.2)).trans + simpa only [Set.mem_ofPred_eq, angularError, real_inner_comm] using hs + have ht' : dist t.val (L.estimate t z.1 z.2).val ≤ ε := by + apply (chord_le_arccos t (L.estimate t z.1 z.2)).trans + simpa only [Set.mem_ofPred_eq, angularError, real_inner_comm] using ht + calc + _ = dist s.val t.val := rfl + _ ≤ dist s.val (L.estimate s z.1 z.2).val + dist (L.estimate s z.1 z.2).val t.val := dist_triangle _ _ _ + _ ≤ ε + ε := by rw [he, dist_comm (L.estimate t z.1 z.2).val t.val] at *; exact add_le_add hs' ht' + _ ≤ 1/5 := by linarith +end Learner + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/LearnerBasics.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/LearnerBasics.lean new file mode 100644 index 0000000000000000000000000000000000000000..595dfe9d4adfc13bbe26a1438f36b9c8e5f83770 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/LearnerBasics.lean @@ -0,0 +1,96 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression + +structure Learner (d M T : ℕ) (Ω : Type u) where + initialChoice : Ω → Bool × State M + transition : ℕ → Ω → State M → (Vector d × ℝ) → Bool × State M + output : ℕ → Ω → State M → UnitSphere d + +namespace Learner + +def start {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) (ω : Ω) : + RunStatus M := + let a := L.initialChoice ω + if a.1 then .inr (0, a.2) else .inl a.2 + +def run {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (s : UnitSphere d) (ω : Ω) (x : Samples d T) : ℕ → RunStatus M + | 0 => L.start ω + | n + 1 => + match L.run s ω x n with + | .inr done => .inr done + | .inl state => + if hn : n < T then + let row := x ⟨n, hn⟩ + let a := L.transition (n + 1) ω state (row, ⟪row, s.val⟫) + if a.1 then .inr (n + 1, a.2) else .inl a.2 + else .inl state + +def terminal {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (s : UnitSphere d) (ω : Ω) (x : Samples d T) : ℕ × State M := + match L.run s ω x T with + | .inl state => (T, state) + | .inr done => done + +def estimate {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (s : UnitSphere d) (ω : Ω) (x : Samples d T) : UnitSphere d := + let a := L.terminal s ω x + L.output a.1 ω a.2 + +structure Admissible {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) : Prop where + initialChoice : AEMeasurable L.initialChoice ρ + transition : ∀ t a, AEMeasurable (fun z : Ω × (Vector d × ℝ) => + L.transition t z.1 a z.2) (ρ.prod (observationReference d)) + output : ∀ t a, AEMeasurable (fun ω => L.output t ω a) ρ + fixed_experiment : ∀ s, AEMeasurable (fun z : Ω × Samples d T => + L.estimate s z.1 z.2) (ρ.prod (sampleLaw d T)) + uniform_experiment : AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => L.estimate z.1 z.2.1 z.2.2) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) + +def success {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) (ε : ℝ) (s : UnitSphere d) : ℝ≥0∞ := + (ρ.prod (sampleLaw d T)) + {z | angularError s (L.estimate s z.1 z.2) ≤ ε} + +def uniformSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) (ε : ℝ) : ℝ≥0∞ := + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) + {z | angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + +end Learner + +def SubquadraticMemory : Prop := + ∃ c : ℝ, 0 < c ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d : ℝ)) (fun d => (d : ℝ) ^ 2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0 < ε → ε ≤ 1 / 10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Learner d (M d) T Ω, L.Admissible ρ → + ((2 / 3 : ℝ≥0∞) ≤ L.uniformSuccess ρ ε ∨ + ∀ s, (2 / 3 : ℝ≥0∞) ≤ L.success ρ ε s) → + c * (d : ℝ) * Real.log (1 / ε) ≤ (T : ℝ) + +def FixedQuadraticMemory : Prop := + ∀ A₀ : ℝ, 0 < A₀ → ∃ c : ℝ, 0 < c ∧ ∃ d₀ : ℕ, + ∀ d : ℕ, d₀ ≤ d → ∀ M T : ℕ, (M : ℝ) ≤ A₀ * (d : ℝ) ^ 2 → + ∀ ε : ℝ, 0 < ε → ε ≤ 1 / 10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Learner d M T Ω, L.Admissible ρ → + (2 / 3 : ℝ≥0∞) ≤ L.uniformSuccess ρ ε → + c * (d : ℝ) * Real.log (1 / ε) ≤ (T : ℝ) + +open scoped Topology + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/LimitSet.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/LimitSet.lean new file mode 100644 index 0000000000000000000000000000000000000000..6f2093d4267ac7cd3d34c59161c88254616c2c06 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/LimitSet.lean @@ -0,0 +1,57 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section LimitSet +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + [TopologicalSpace Y] [BorelSpace Y] + (ρ : Measure X) (τ : Measure Y) + +lemma map_apply_open_le_of_tendsto (F : X → Y) (Fₖ : ℕ → X → Y) + (hF : Measurable F) (hFₖ : ∀ k, Measurable (Fₖ k)) + (ht : ∀ x, Tendsto (fun k => Fₖ k x) atTop (𝓝 (F x))) + (C : ℝ≥0∞) (α : ℝ) + (hbound : ∀ k U, IsOpen U → (ρ.map (Fₖ k)) U ≤ C * (τ U)^α) + (U : Set Y) (hU : IsOpen U) : + (ρ.map F) U ≤ C * (τ U)^α := by + let f : ℕ → X → ℝ≥0∞ := fun k => (Fₖ k ⁻¹' U).indicator (fun _ => 1) + have hf : ∀ k, Measurable (f k) := fun k => + measurable_const.indicator (hU.measurableSet.preimage (hFₖ k)) + have hind : ∀ x, (F ⁻¹' U).indicator (fun _ => (1 : ℝ≥0∞)) x ≤ + atTop.liminf (fun k => f k x) := by + intro x + by_cases hx : F x ∈ U + · rw [Set.indicator_of_mem (show x ∈ F ⁻¹' U from hx)] + apply le_liminf_of_le (by isBoundedDefault) + filter_upwards [(ht x).eventually (hU.mem_nhds hx)] with k hk + change 1 ≤ (Fₖ k ⁻¹' U).indicator (fun _ => (1 : ℝ≥0∞)) x + rw [Set.indicator_of_mem (show x ∈ Fₖ k ⁻¹' U from hk)] + · rw [Set.indicator_of_notMem (show x ∉ F ⁻¹' U from hx)] + exact zero_le + calc + (ρ.map F) U = ∫⁻ x, (F ⁻¹' U).indicator (fun _ => (1 : ℝ≥0∞)) x ∂ρ := by + rw [Measure.map_apply hF hU.measurableSet, + lintegral_indicator (hU.measurableSet.preimage hF)] + simp + _ ≤ ∫⁻ x, atTop.liminf (fun k => f k x) ∂ρ := lintegral_mono hind + _ ≤ atTop.liminf (fun k => ∫⁻ x, f k x ∂ρ) := lintegral_liminf_le hf + _ ≤ _ := by + apply liminf_le_of_frequently_le (hu_le := by isBoundedDefault) + apply Filter.Eventually.frequently + filter_upwards [] with k + have hk := hbound k U hU + simpa [f, lintegral_indicator (hU.measurableSet.preimage (hFₖ k)), + Measure.map_apply (hFₖ k) hU.measurableSet] using hk +end LimitSet + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/LowerFubini.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/LowerFubini.lean new file mode 100644 index 0000000000000000000000000000000000000000..733229a74baa309e4598b1e8a752f41c7c231563 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/LowerFubini.lean @@ -0,0 +1,39 @@ +import OAI.Probability.PosteriorReplicas.Regression.Fubini + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +section LowerFubini +variable {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + {μ : Measure X} {ν : Measure Y} [SFinite μ] [SFinite ν] +lemma prod_null_set_lower_bound {S : Set (X × Y)} (hS : NullMeasurableSet S (μ.prod ν)) + {c : ℝ≥0∞} (h : ∀ᵐ x ∂μ, c ≤ ν {y | (x,y) ∈ S}) : + c * μ univ ≤ (μ.prod ν) S := by + have hm : AEMeasurable (S.indicator (fun _ => (1 : ℝ≥0∞))) (μ.prod ν) := + aemeasurable_const.indicator₀ hS + rw [← one_mul ((μ.prod ν) S), ← lintegral_indicator_const₀ hS 1, lintegral_prod _ hm] + have hc : c * μ univ = ∫⁻ _ : X, c ∂μ := (lintegral_const c).symm + rw [hc] + apply lintegral_mono_ae + filter_upwards [h, ae_fiber_aemeasurable hm.prod_swap] with x hx hmx + have hs : NullMeasurableSet {y | (x,y) ∈ S} ν := by + have heq : {y | (x,y) ∈ S} = {y | S.indicator (fun _ => (1 : ℝ≥0∞)) (x,y) = 1} := by + ext y + by_cases hy : (x,y) ∈ S <;> simp [hy] + rw [heq] + exact nullMeasurableSet_eq_fun hmx aemeasurable_const + change c ≤ ∫⁻ y, ({y | (x,y) ∈ S}).indicator (fun _ => (1 : ℝ≥0∞)) y ∂ν + simpa [lintegral_indicator_const₀ hs] using hx +end LowerFubini + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/MemoryBounds.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/MemoryBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..faa662f58c9503dcee4a0a9f94f397e94d0f81ef --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/MemoryBounds.lean @@ -0,0 +1,48 @@ +import OAI.Probability.PosteriorReplicas.Regression.LowerFubini +import OAI.Probability.PosteriorReplicas.Regression.MemoryPrecision + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +namespace Learner +lemma uniformSuccess_of_pointwise {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 0 < d) (ε : ℝ) {c : ℝ≥0∞} + (hs : ∀ s, c ≤ L.success ρ ε s) : c ≤ L.uniformSuccess ρ ε := by + let : NeZero d := ⟨hd.ne'⟩ + have hb := prod_null_set_lower_bound (L.angularSuccess_nullMeasurable ρ ε hL) + (c := c) (Filter.Eventually.of_forall hs) + simpa only [measure_univ, mul_one, uniformSuccess] using hb +end Learner + +theorem subquadratic_memory : SubquadraticMemory.{u} := by + obtain ⟨c, hc, d₁, hfixed⟩ := fixed_quadratic_memory (1 : ℝ) (by norm_num) + refine ⟨c, hc, ?_⟩ + intro M hM + obtain ⟨d₂, hd₂⟩ := eventually_atTop.1 hM.eventuallyLE + refine ⟨max d₁ (max d₂ 1), ?_⟩ + intro d hd T ε hε hε10 Ω _ ρ hρ L hL hs + let : IsProbabilityMeasure ρ := hρ + have hmem : (M d : ℝ) ≤ 1 * (d : ℝ)^2 := by + have hm := hd₂ d (by omega) + simpa only [Real.norm_eq_abs, abs_of_nonneg (Nat.cast_nonneg (M d) : (0 : ℝ) ≤ M d), + abs_of_nonneg (sq_nonneg (d : ℝ)), one_mul] using hm + apply hfixed d (by omega) (M d) T hmem ε hε hε10 Ω ρ hρ L hL + rcases hs with hs | hs + · exact hs + · exact L.uniformSuccess_of_pointwise ρ hL (by omega) ε hs + +theorem main : SubquadraticMemory.{u} ∧ FixedQuadraticMemory.{u} := + ⟨subquadratic_memory, fixed_quadratic_memory⟩ + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/MemoryPrecision.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/MemoryPrecision.lean new file mode 100644 index 0000000000000000000000000000000000000000..a714e025d7df30d08ade00416b333fb1cadddba7 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/MemoryPrecision.lean @@ -0,0 +1,143 @@ +import OAI.Probability.PosteriorReplicas.Regression.StreamEstimates + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +namespace Learner + +lemma streaming_success_bound_real {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 3 ≤ d) {ε : ℝ} (hε : 0 < ε) + {a q : ℕ} (ha : 2*a ≤ d-1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) + (hs : (2/3 : ℝ≥0∞) ≤ L.uniformSuccess ρ ε) : + (2/3 : ℝ) ≤ ((T : ℝ)+1) * ((3 : ℝ)*4^d * ε^a) * + ((32768 : ℝ)^d * ((2 : ℝ)^M)^(1/(q : ℝ)))^(T/q+1) := by + have hb := hs.trans (L.streaming_success_bound ρ hL hd hε ha hq hqa) + have ht : (T+1 : ℝ≥0∞) * + (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := State M) q ^ (T/q+1) ≠ ∞ := by + apply ENNReal.mul_ne_top + · apply ENNReal.mul_ne_top (by simp) + exact ENNReal.mul_ne_top ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top + · exact ENNReal.pow_ne_top (streamFactor_ne_top q) + have hr := ENNReal.toReal_mono ht hb + simpa [ENNReal.toReal_div, ENNReal.toReal_ofNat, ENNReal.toReal_mul, + ENNReal.toReal_add, ENNReal.toReal_natCast, ENNReal.toReal_one, + ENNReal.toReal_ofReal (by positivity : (0 : ℝ) ≤ 3*4^d), + ENNReal.toReal_ofReal (by positivity : 0 ≤ ε^a), streamFactor, + ENNReal.toReal_pow, ← ENNReal.toReal_rpow, finrank_euclideanSpace_fin, + Fintype.card_fin, State, Nat.cast_pow, Nat.cast_ofNat, Vector] using hr + +end Learner + +lemma precision_from_stream_bound {d M T a q : ℕ} {ε A : ℝ} + (hd : 32 ≤ d) (hT : d ≤ 4*T) (hq : 0 < q) (hdq : d ≤ 8*q) + (ha : d ≤ 4*a) (hM : (M : ℝ) ≤ A * (d : ℝ)^2) (hA : 0 < A) + (hε : 0 < ε) (hε1 : ε ≤ 1) + (hbound : (2/3 : ℝ) ≤ ((T : ℝ)+1) * ((3 : ℝ)*4^d * ε^a) * + ((32768 : ℝ)^d * ((2 : ℝ)^M)^(1/(q : ℝ)))^(T/q+1)) : + (1 / (4*(400000+100*A))) * (d : ℝ) * Real.log (1/ε) ≤ (T : ℝ) := by + have hd0 : (0 : ℝ) < d := by exact_mod_cast (by omega : 0 < d) + have hq0 : (0 : ℝ) < q := by exact_mod_cast hq + have hT0 : (0 : ℝ) ≤ T := Nat.cast_nonneg T + have hdp : (d : ℝ) ≤ 4*T := by exact_mod_cast hT + have hdqp : (d : ℝ) ≤ 8*q := by exact_mod_cast hdq + have hap : (d : ℝ) ≤ 4*a := by exact_mod_cast ha + have hB : ((T/q+1 : ℕ) : ℝ) * d ≤ 12*T := by + have hbd : (T/q+1)*d ≤ 12*T := by + have hmul := Nat.div_mul_le_self T q + calc + (T/q+1)*d = (T/q)*d+d := by ring + _ ≤ (T/q)*(8*q)+d := Nat.add_le_add_right (Nat.mul_le_mul_left _ hdq) _ + _ = 8*((T/q)*q)+d := by ring + _ ≤ 8*T+d := Nat.add_le_add_right (Nat.mul_le_mul_left 8 hmul) _ + _ ≤ 12*T := by omega + exact_mod_cast hbd + have hMq : (M : ℝ) / q ≤ 8*A*d := by + apply (div_le_iff₀ hq0).2 + calc + (M : ℝ) ≤ A*d^2 := hM + _ ≤ A*d*(8*q) := by nlinarith [mul_le_mul_of_nonneg_left hdqp (by positivity : 0 ≤ A*d)] + _ = 8*A*d*q := by ring + have hlog := Real.log_le_log (by norm_num : (0 : ℝ) < 2/3) hbound + rw [Real.log_mul (by positivity) (by positivity), + Real.log_mul (by positivity) (by positivity), + Real.log_mul (by positivity) (by positivity), + Real.log_mul (by positivity) (by positivity), + Real.log_pow, Real.log_pow, Real.log_pow, + Real.log_mul (by positivity) (by positivity), Real.log_pow, + Real.log_rpow (by positivity), Real.log_pow] at hlog + have hlogε : Real.log (1/ε) = -Real.log ε := by simp + have hlogε0 : 0 ≤ Real.log (1/ε) := Real.log_nonneg ((le_div_iff₀ hε).2 (by simpa using hε1)) + have heq : (1/(q : ℝ)) * ((M : ℝ)*Real.log 2) = ((M : ℝ)/q)*Real.log 2 := by ring + rw [heq] at hlog + have hlT : Real.log ((T : ℝ)+1) ≤ T := by + simpa using Real.log_le_sub_one_of_pos (by positivity : (0 : ℝ) < T+1) + have hl3 : Real.log (3 : ℝ) ≤ 3 := Real.log_le_self (by norm_num) + have hl4 : Real.log (4 : ℝ) ≤ 4 := Real.log_le_self (by norm_num) + have hl32 : Real.log (32768 : ℝ) ≤ 32768 := Real.log_le_self (by norm_num) + have hl2 : Real.log (2 : ℝ) ≤ 1 := by + convert Real.log_le_sub_one_of_pos (by norm_num : (0 : ℝ) < 2) using 1; norm_num + have hl23 : -(1 : ℝ) ≤ Real.log (2/3 : ℝ) := by + have h := Real.one_sub_inv_le_log_of_pos (by norm_num : (0 : ℝ) < 2/3) + norm_num at h + linarith + have hinside : (d : ℝ)*Real.log 32768 + ((M : ℝ)/q)*Real.log 2 ≤ + (32768+8*A)*d := by + have hm0 : (0 : ℝ) ≤ (M : ℝ)/q := by positivity + have h1 := mul_le_mul_of_nonneg_left hl32 hd0.le + have h2 := mul_le_mul_of_nonneg_left hl2 hm0 + nlinarith + have hfull : ((T/q+1 : ℕ) : ℝ) * + ((d : ℝ)*Real.log 32768 + ((M : ℝ)/q)*Real.log 2) ≤ + 12*T*(32768+8*A) := by + calc + _ ≤ ((T/q+1 : ℕ) : ℝ) * ((32768+8*A)*d) := + mul_le_mul_of_nonneg_left hinside (Nat.cast_nonneg _) + _ = (32768+8*A)*(((T/q+1 : ℕ) : ℝ)*d) := by ring + _ ≤ (32768+8*A)*(12*T) := mul_le_mul_of_nonneg_left hB (by positivity) + _ = _ := by ring + have hd4 : (4 : ℝ) ≤ d := by exact_mod_cast (by omega : 4 ≤ d) + have hlogbound : (a : ℝ)*Real.log (1/ε) ≤ (400000+100*A)*T := by + have h4 := mul_le_mul_of_nonneg_left hl4 hd0.le + rw [hlogε] + nlinarith [mul_nonneg hA.le hT0] + have hmain : (d : ℝ)*Real.log (1/ε) ≤ 4*(400000+100*A)*T := by + have ham := mul_le_mul_of_nonneg_right hap hlogε0 + linarith + have hden : (0 : ℝ) < 4*(400000+100*A) := by positivity + calc + _ = ((d : ℝ)*Real.log (1/ε))/(4*(400000+100*A)) := by ring + _ ≤ T := (div_le_iff₀ hden).2 (by nlinarith [hmain]) + +theorem fixed_quadratic_memory : FixedQuadraticMemory.{u} := by + intro A hA + refine ⟨1/(4*(400000+100*A)), by positivity, 32, ?_⟩ + intro d hd M T hM ε hε hε10 Ω _ ρ hρ L hL hs + let : IsProbabilityMeasure ρ := hρ + have hT : d ≤ 4*T := by + by_contra h + have hb := hs.trans (L.linear_success_bound ρ (by omega) (by omega) hε10 hL) + have hr := ENNReal.toReal_mono ENNReal.ofReal_ne_top hb + norm_num [ENNReal.toReal_div] at hr + let q := (d-1)/4 + let a := 2*q + have hq : 2 ≤ q := by dsimp [q]; omega + have hqa : 2*q ≤ a := le_rfl + have ha : 2*a ≤ d-1 := by dsimp [a, q]; omega + have hdq : d ≤ 8*q := by dsimp [q]; omega + have hda : d ≤ 4*a := by dsimp [a]; omega + exact precision_from_stream_bound hd hT (by omega) hdq hda hM hA hε (by linarith) + (L.streaming_success_bound_real ρ hL (by omega) hε ha hq hqa hs) + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/ObservationContinuity.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/ObservationContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..0130492b35f6979419133fab705b704fac47fab4 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/ObservationContinuity.lean @@ -0,0 +1,76 @@ +import OAI.Probability.PosteriorReplicas.Regression.ProjectionBlocks + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +section ObservationAC +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma projectionLaw_absolutelyContinuous {ν : Measure E} [IsFiniteMeasure ν] + {a m n : ℕ} {C : ℝ≥0∞} (hν : PolynomialMass ν a C) (hC : C ≠ 0) (hCt : C ≠ ∞) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) (hn : 1 ≤ n) (hmargin : n+m ≤ a) : + projectionLaw ν m ≪ matrixLabelReference (E := E) m := by + let ν' := C⁻¹ • ν + have hCi : C⁻¹ ≠ ∞ := ENNReal.inv_ne_top.mpr hC + let : IsFiniteMeasure ν' := ⟨by simp only [ν', Measure.smul_apply, smul_eq_mul]; finiteness⟩ + have hlocal : HasLocalMassBound ν' (a : ℝ) := by + intro z _ r hr + have hh := mul_le_mul' (le_rfl : C⁻¹ ≤ C⁻¹) (hν z r hr) + simpa only [ν', Measure.smul_apply, smul_eq_mul, ← mul_assoc, + ENNReal.inv_mul_cancel hC hCt, one_mul, Real.rpow_natCast] using hh + have hs : ν'.support ⊆ Metric.closedBall 0 1 := + (Measure.smul_absolutelyContinuous.support_mono).trans hsupport + have hbound (S : Set ((Fin m → E) × (Fin m → ℝ))) := + projectionLaw_set_bound hlocal hs m n hn (by exact_mod_cast hmargin) S + have he : projectionLaw ν' m = C⁻¹ • projectionLaw ν m := by + exact projectionLaw_smul ν m C⁻¹ + intro S hS + have h := hbound S + rw [hS, ENNReal.zero_rpow_of_pos (by + have : (1 : ℝ) < n+1 := by exact_mod_cast (by omega : 1 < n+1) + exact sub_pos.mpr ((div_lt_one (by positivity)).mpr this)), mul_zero, he, + Measure.smul_apply, smul_eq_mul] at h + exact (mul_eq_zero.mp (le_antisymm h bot_le)).resolve_left (ENNReal.inv_ne_zero.mpr hCt) + +lemma sphere_observation_quasi [Nontrivial E] (hd : 3 ≤ Module.finrank ℝ E) : + Measure.QuasiMeasurePreserving + (fun z : (Metric.sphere (0 : E) 1) × E => (z.2, ⟪z.1.val,z.2⟫)) + ((sphereLaw (E := E)).prod (stdGaussian E)) ((stdGaussian E).prod volume) := by + have hac : projectionLaw (ambientSphereLaw (E := E)) 1 ≪ matrixLabelReference (E := E) 1 := by + apply projectionLaw_absolutelyContinuous (a := 2) (n := 1) + (C := ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E)) + · intro z r hr + exact ambientSphereLaw_closedBall z hr 2 (by omega) + · positivity + · exact ENNReal.ofReal_ne_top + · exact ambientSphereLaw_support.trans Metric.sphere_subset_closedBall + · omega + · omega + have hp : Measure.QuasiMeasurePreserving + (fun z : (Fin 1 → E) × E => (z.1, fun j => ⟪z.2,z.1 j⟫)) + ((Measure.pi (fun _ : Fin 1 => stdGaussian E)).prod (ambientSphereLaw (E := E))) + (matrixLabelReference (E := E) 1) := ⟨by fun_prop, hac⟩ + have h1 := ((measurePreserving_funUnique (stdGaussian E) (Fin 1)).symm + (MeasurableEquiv.funUnique (Fin 1) E)).prod + (measurable_subtype_coe.measurePreserving (sphereLaw (E := E))) + have h2 := (measurePreserving_funUnique (stdGaussian E) (Fin 1)).prod + (volume_preserving_funUnique (Fin 1) ℝ) + have h3 := h2.quasiMeasurePreserving.comp (hp.comp (h1.quasiMeasurePreserving.comp + Measure.measurePreserving_swap.quasiMeasurePreserving)) + convert h3 using 1 + ext z <;> simp [MeasurableEquiv.funUnique] + +end ObservationAC + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/OuterBound.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/OuterBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d8aeff765c6d22c47534cc6ddee6598a0717376 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/OuterBound.lean @@ -0,0 +1,35 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section OuterBound +variable {Y : Type*} [MeasurableSpace Y] [TopologicalSpace Y] + +lemma ennreal_rpow_iInf {ι : Sort*} (f : ι → ℝ≥0∞) {α : ℝ} (hα : 0 < α) : + (⨅ i, f i)^α = ⨅ i, (f i)^α := + (ENNReal.orderIsoRpow α hα).map_iInf f + +lemma measure_apply_le_of_isOpen (μ τ : Measure Y) [τ.OuterRegular] + {C : ℝ≥0∞} (hC : C ≠ ∞) {α : ℝ} (hα : 0 < α) + (hbound : ∀ U, IsOpen U → μ U ≤ C * (τ U)^α) (S : Set Y) : + μ S ≤ C * (τ S)^α := by + by_cases hC0 : C = 0 + · simp only [hC0, zero_mul] at hbound ⊢ + exact (measure_mono (Set.subset_univ S)).trans (hbound Set.univ isOpen_univ) + rw [S.measure_eq_iInf_isOpen τ] + simp_rw [ennreal_rpow_iInf _ hα, ENNReal.mul_iInf_of_ne hC0 hC] + exact le_iInf fun U => le_iInf fun hSU => le_iInf fun hU => + (measure_mono hSU).trans (hbound U hU) +end OuterBound + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/PiLast.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/PiLast.lean new file mode 100644 index 0000000000000000000000000000000000000000..f85d97dbd3bc2ccaa6538deba280d54b2b0591da --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/PiLast.lean @@ -0,0 +1,33 @@ +import OAI.Probability.PosteriorReplicas.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section PiLast +variable {E : Type*} [MeasurableSpace E] {n : ℕ} (ν : Measure E) [SigmaFinite ν] +lemma lintegral_pi_snoc (f : (Fin (n+1) → E) → ℝ≥0∞) (hf : Measurable f) : + ∫⁻ v, f v ∂Measure.pi (fun _ => ν) = + ∫⁻ v : Fin n → E, ∫⁻ x, f (Fin.snoc v x) ∂ν ∂Measure.pi (fun _ => ν) := by + have hp := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => ν) (Fin.last n)).symm + rw [← hp.lintegral_comp_emb (MeasurableEquiv.measurableEmbedding _) f, + lintegral_prod_symm] + · congr 1 + ext v + congr 1 + ext x + congr 1 + simp only [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv] + exact Fin.insertNth_last' x v + · exact (hf.comp (MeasurableEquiv.measurable _)).aemeasurable +end PiLast + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/ProductDensity.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/ProductDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..12dd21d0f92eb89d7b18d8a3f1c8274722110cf4 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/ProductDensity.lean @@ -0,0 +1,44 @@ +import OAI.Probability.PosteriorReplicas.Regression.ReplicaKernel + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section ProductDensity +variable {X : Type*} [MeasurableSpace X] (μ : Measure X) [SigmaFinite μ] + +lemma measure_pi_withDensity (n : ℕ) (f : Fin n → X → ℝ≥0∞) + (hf : ∀ i, Measurable (f i)) [∀ i, SigmaFinite (μ.withDensity (f i))] : + Measure.pi (fun i => μ.withDensity (f i)) = + (Measure.pi (fun _ : Fin n => μ)).withDensity (fun x => ∏ i, f i (x i)) := by + classical + apply Measure.pi_eq + intro s hs + rw [withDensity_apply _ (MeasurableSet.univ_pi hs), ← lintegral_indicator (MeasurableSet.univ_pi hs)] + have he (x : Fin n → X) : + (Set.univ.pi s).indicator (fun x => ∏ i, f i (x i)) x = + ∏ i, (s i).indicator (f i) (x i) := by + by_cases hx : x ∈ Set.univ.pi s + · rw [Set.indicator_of_mem hx] + exact Finset.prod_congr rfl fun i _ => + (Set.indicator_of_mem (hx i (Set.mem_univ i)) _).symm + · rw [Set.indicator_of_notMem hx] + have : ∃ i, x i ∉ s i := by simpa only [Set.mem_univ_pi, not_forall] using hx + obtain ⟨i, hi⟩ := this + exact (Finset.prod_eq_zero (Finset.mem_univ i) (Set.indicator_of_notMem hi _)).symm + simp_rw [he] + rw [lintegral_fin_prod μ n _ (fun i => (hf i).indicator (hs i))] + apply Finset.prod_congr rfl + intro i _ + rw [lintegral_indicator (hs i), withDensity_apply _ (hs i)] +end ProductDensity + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/ProjectionBlocks.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/ProjectionBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..11f3ed3eeab0f97ab9910d6041f1c2e6aff4923b --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/ProjectionBlocks.lean @@ -0,0 +1,368 @@ +import OAI.Probability.PosteriorReplicas.Regression.Fubini + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +section Block +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def PolynomialMass (ν : Measure E) (a : ℕ) (C : ℝ≥0∞) : Prop := + ∀ z : E, ∀ r : ℝ, 0 < r → ν (Metric.closedBall z r) ≤ C * ENNReal.ofReal (r^a) + +def localNormalize (ν : Measure E) (a : ℕ) (C : ℝ≥0∞) (z : E) (r : ℝ) : Measure E := + (C * ENNReal.ofReal (r^a))⁻¹ • (ν.restrict (Metric.closedBall z r)).map (fun x => r⁻¹ • (x-z)) + +omit [FiniteDimensional ℝ E] in +lemma localNormalize_univ {ν : Measure E} {a : ℕ} {C : ℝ≥0∞} + (hν : PolynomialMass ν a C) (hC : C ≠ 0) (hCt : C ≠ ∞) (z : E) {r : ℝ} (hr : 0 < r) : + localNormalize ν a C z r univ ≤ 1 := by + have hc0 : C * ENNReal.ofReal (r^a) ≠ 0 := mul_ne_zero hC (by positivity) + have hct : C * ENNReal.ofReal (r^a) ≠ ∞ := ENNReal.mul_ne_top hCt ENNReal.ofReal_ne_top + simp only [localNormalize, Measure.smul_apply, smul_eq_mul, Measure.map_apply (by fun_prop : Measurable (fun x : E => r⁻¹ • (x-z))) MeasurableSet.univ, + Set.preimage_univ, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter] + exact (mul_le_mul' le_rfl (hν z r hr)).trans_eq (ENNReal.inv_mul_cancel hc0 hct) + +omit [FiniteDimensional ℝ E] in +lemma localNormalize_finite {ν : Measure E} {a : ℕ} {C : ℝ≥0∞} + (hν : PolynomialMass ν a C) (hC : C ≠ 0) (hCt : C ≠ ∞) (z : E) {r : ℝ} (hr : 0 < r) : + IsFiniteMeasure (localNormalize ν a C z r) := + ⟨(localNormalize_univ hν hC hCt z hr).trans_lt (by simp)⟩ + +omit [FiniteDimensional ℝ E] in +lemma localNormalize_support (ν : Measure E) (a : ℕ) (C : ℝ≥0∞) (z : E) {r : ℝ} (hr : 0 < r) : + (localNormalize ν a C z r).support ⊆ Metric.closedBall 0 1 := by + apply Measure.support_subset_of_isClosed Metric.isClosed_closedBall + rw [mem_ae_iff, localNormalize, Measure.smul_apply, Measure.map_apply (by fun_prop) + Metric.isClosed_closedBall.measurableSet.compl, + Measure.restrict_apply ((by fun_prop : Measurable (fun x : E => r⁻¹ • (x-z))) + Metric.isClosed_closedBall.measurableSet.compl)] + have he : (fun x : E => r⁻¹ • (x-z)) ⁻¹' (Metric.closedBall 0 1)ᶜ ∩ Metric.closedBall z r = ∅ := by + apply Set.eq_empty_iff_forall_notMem.mpr + intro x ⟨hx,hb⟩ + apply hx + rw [Metric.mem_closedBall, dist_zero_right, norm_smul, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr hr)] + exact (inv_mul_le_iff₀ hr).2 (by simpa [dist_eq_norm] using hb) + rw [he, measure_empty, smul_zero] + +omit [FiniteDimensional ℝ E] in +lemma localNormalize_local {ν : Measure E} {a : ℕ} {C : ℝ≥0∞} + (hν : PolynomialMass ν a C) (hC : C ≠ 0) (hCt : C ≠ ∞) (z : E) {r : ℝ} (hr : 0 < r) : + HasLocalMassBound (localNormalize ν a C z r) (a : ℝ) := by + have hc0 : C * ENNReal.ofReal (r^a) ≠ 0 := mul_ne_zero hC (by positivity) + have hct : C * ENNReal.ofReal (r^a) ≠ ∞ := ENNReal.mul_ne_top hCt ENNReal.ofReal_ne_top + intro t _ ρ hρ + rw [localNormalize, Measure.smul_apply, smul_eq_mul, + Measure.map_apply (by fun_prop) Metric.isClosed_closedBall.measurableSet] + have hsub : (fun x : E => r⁻¹ • (x-z)) ⁻¹' Metric.closedBall t ρ ⊆ + Metric.closedBall (z + r • t) (r*ρ) := by + intro x hx + have he : x - (z+r • t) = r • (r⁻¹ • (x-z) - t) := by + rw [smul_sub, smul_smul, mul_inv_cancel₀ hr.ne', one_smul] + abel + rw [Metric.mem_closedBall, dist_eq_norm, he, norm_smul, Real.norm_eq_abs, abs_of_pos hr] + exact mul_le_mul_of_nonneg_left (by simpa only [Set.mem_preimage, Metric.mem_closedBall, dist_eq_norm] using hx) hr.le + calc + _ ≤ (C * ENNReal.ofReal (r^a))⁻¹ * ν (Metric.closedBall (z+r • t) (r*ρ)) := + mul_le_mul' le_rfl ((Measure.restrict_le_self _).trans (measure_mono hsub)) + _ ≤ (C * ENNReal.ofReal (r^a))⁻¹ * (C * ENNReal.ofReal ((r*ρ)^a)) := + mul_le_mul' le_rfl (hν _ _ (mul_pos hr hρ)) + _ = ENNReal.ofReal (ρ^(a : ℝ)) := by + rw [mul_pow, ENNReal.ofReal_mul (pow_nonneg hr.le a), ← mul_assoc C, + ← mul_assoc, ENNReal.inv_mul_cancel hc0 hct, one_mul, Real.rpow_natCast] + +omit [FiniteDimensional ℝ E] [BorelSpace E] in +lemma replicaConstant_le {ν : Measure E} (hν : ν univ ≤ 1) {a m : ℕ} + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) (hm : m ≤ Module.finrank ℝ E) : + replicaConstant ν (a : ℝ) m ≤ (128 : ℝ≥0∞) ^ Module.finrank ℝ E := by + let d := Module.finrank ℝ E + have h2 : (2 : ℝ≥0∞) ≤ 2^d := by simpa using pow_le_pow_right₀ (by norm_num : (1 : ℝ≥0∞) ≤ 2) hd + have hp : (2 : ℝ≥0∞)^(m+1) ≤ 4^d := by + rw [pow_succ] + calc + _ ≤ (2 : ℝ≥0∞)^d * 2^d := mul_le_mul' (pow_le_pow_right₀ (by norm_num) hm) h2 + _ = _ := by rw [← mul_pow]; norm_num + calc + replicaConstant ν (a : ℝ) m ≤ 1 + (4 : ℝ≥0∞)^d * 4^d * 4^d := by + unfold replicaConstant + rw [Real.rpow_natCast, ENNReal.ofReal_mul (by positivity), ENNReal.ofReal_pow (by norm_num), + ENNReal.ofReal_pow (by norm_num)] + norm_num only [ENNReal.ofReal_ofNat] + gcongr <;> norm_num + _ = 1 + (64 : ℝ≥0∞)^d := by rw [mul_assoc, ← mul_pow, ← mul_pow]; norm_num + _ ≤ (2 : ℝ≥0∞) * 64^d := by + rw [two_mul] + exact add_le_add (one_le_pow₀ (by norm_num)) le_rfl + _ ≤ (2 : ℝ≥0∞)^d * 64^d := mul_le_mul' h2 le_rfl + _ = _ := by rw [← mul_pow]; norm_num; rfl + +lemma projectionLaw_uniform_set_bound {ν : Measure E} [IsFiniteMeasure ν] + {a m n : ℕ} (hν : HasLocalMassBound ν (a : ℝ)) (hν1 : ν univ ≤ 1) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) (hm : m ≤ Module.finrank ℝ E) + (hn : 1 ≤ n) (hmargin : n+m ≤ a) (S : Set ((Fin m → E) × (Fin m → ℝ))) : + projectionLaw ν m S ≤ (128 : ℝ≥0∞) ^ Module.finrank ℝ E * + (matrixLabelReference (E := E) m S)^(1 - 1 / ((n : ℝ)+1)) := by + apply (projectionLaw_set_bound hν hsupport m n hn (by exact_mod_cast hmargin) S).trans + apply mul_le_mul' _ le_rfl + have hn0 : (0 : ℝ) < n+1 := by positivity + calc + _ ≤ (((128 : ℝ≥0∞)^Module.finrank ℝ E) ^ n)^(1 / ((n : ℝ)+1)) := by + apply ENNReal.rpow_le_rpow _ (by positivity) + simpa only [one_mul] using mul_le_mul' hν1 (pow_le_pow_left' (replicaConstant_le hν1 hd ha hm) n) + _ = ((128 : ℝ≥0∞)^Module.finrank ℝ E)^((n : ℝ)/(n+1)) := by + rw [← ENNReal.rpow_natCast, ← ENNReal.rpow_mul] + congr 1 + rw [mul_one_div] + _ ≤ ((128 : ℝ≥0∞)^Module.finrank ℝ E)^(1 : ℝ) := + ENNReal.rpow_le_rpow_of_exponent_le (one_le_pow₀ (by norm_num)) + ((div_le_one hn0).2 (by linarith)) + _ = _ := ENNReal.rpow_one _ + +lemma finite_rpow_holder {J : Type*} [Fintype J] (a : J → ℝ≥0∞) {q : ℝ} (hq : 1 < q) : + (∑ j, a j ^ (1 - 1/q)) ≤ + (Fintype.card J : ℝ≥0∞)^(1/q) * (∑ j, a j)^(1-1/q) := by + have hh := Real.HolderConjugate.conjExponent hq + have hq' : q.conjExponent ≠ 0 := ne_of_gt hh.symm.pos + have hex : 1 - 1/q = q.conjExponent⁻¹ := by simpa only [one_div] using hh.one_sub_inv + rw [hex] + simpa only [one_mul, one_div, ENNReal.one_rpow, ENNReal.rpow_inv_rpow hq', + Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one] using + ENNReal.inner_le_Lp_mul_Lq Finset.univ (fun _ : J => (1 : ℝ≥0∞)) + (fun j => a j ^ q.conjExponent⁻¹) hh + +lemma normalized_routing_bound {J : Type*} [Fintype J] [MeasurableSpace J] + [MeasurableSingletonClass J] (ν : J → Measure E) [∀ j, IsFiniteMeasure (ν j)] + {a m n : ℕ} (hν : ∀ j, HasLocalMassBound (ν j) (a : ℝ)) + (hν1 : ∀ j, ν j univ ≤ 1) (hsupport : ∀ j, (ν j).support ⊆ Metric.closedBall 0 1) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) (hn : 1 ≤ n) (hmargin : n+m ≤ a) + (φ : ((Fin m → E) × (Fin m → ℝ)) → J) (hφ : Measurable φ) : + (∑ j, projectionLaw (ν j) m {x | φ x = j}) ≤ + (32768 : ℝ≥0∞)^Module.finrank ℝ E * (Fintype.card J : ℝ≥0∞)^(1/((n : ℝ)+1)) := by + classical + obtain ⟨D, hD, hDs, hDV⟩ := exists_projection_support (E := E) m hm + let S : J → Set ((Fin m → E) × (Fin m → ℝ)) := fun j => D ∩ {x | φ x = j} + have hS (j : J) : MeasurableSet (S j) := hD.inter (hφ (measurableSet_singleton j)) + have hSD (j : J) : projectionLaw (ν j) m (S j) = projectionLaw (ν j) m {x | φ x = j} := by + apply Measure.measure_inter_eq_of_ae + unfold projectionLaw + apply (ae_map_iff (by fun_prop) hD).2 + filter_upwards [Measure.quasiMeasurePreserving_snd.ae (ν j).support_mem_ae] with x hx + exact hDs x.1 x.2 (by simpa using hsupport j hx) + have hdis : Pairwise (Function.onFun Disjoint S) := by + intro i j hij + apply Set.disjoint_left.mpr + intro x hi hj + exact hij (hi.2.symm.trans hj.2) + have hUnion : (⋃ j, S j) = D := by + ext x + simp only [S, Set.mem_iUnion, Set.mem_inter_iff, Set.mem_ofPred_eq] + exact ⟨fun ⟨_,h,_⟩ => h, fun h => ⟨φ x,h,rfl⟩⟩ + have hsum : ∑ j, matrixLabelReference (E := E) m (S j) = matrixLabelReference (E := E) m D := by + simpa only [hUnion, tsum_fintype] using (measure_iUnion (μ := matrixLabelReference (E := E) m) hdis hS).symm + have hα : 0 ≤ 1 - 1/((n : ℝ)+1) := by + have : (1 : ℝ) ≤ n := by exact_mod_cast hn + nlinarith [one_div_le_one_div_of_le (by norm_num : (0 : ℝ) < 1) (by linarith : (1 : ℝ) ≤ n+1)] + have hV : (matrixLabelReference (E := E) m D)^(1-1/((n : ℝ)+1)) ≤ + (256 : ℝ≥0∞)^Module.finrank ℝ E := by + calc + _ ≤ ((256 : ℝ≥0∞)^Module.finrank ℝ E)^(1-1/((n : ℝ)+1)) := + ENNReal.rpow_le_rpow (hDV.trans (pow_le_pow_left' (by norm_num) _)) hα + _ ≤ ((256 : ℝ≥0∞)^Module.finrank ℝ E)^ (1 : ℝ) := + ENNReal.rpow_le_rpow_of_exponent_le (one_le_pow₀ (by norm_num)) (sub_le_self _ (by positivity)) + _ = _ := ENNReal.rpow_one _ + calc + _ = ∑ j, projectionLaw (ν j) m (S j) := by simp_rw [hSD] + _ ≤ ∑ j, (128 : ℝ≥0∞)^Module.finrank ℝ E * + (matrixLabelReference (E := E) m (S j))^(1-1/((n : ℝ)+1)) := + Finset.sum_le_sum fun j _ => projectionLaw_uniform_set_bound + (hν j) (hν1 j) (hsupport j) hd ha hm hn hmargin (S j) + _ = (128 : ℝ≥0∞)^Module.finrank ℝ E * + ∑ j, (matrixLabelReference (E := E) m (S j))^(1-1/((n : ℝ)+1)) := by rw [Finset.mul_sum] + _ ≤ (128 : ℝ≥0∞)^Module.finrank ℝ E * + ((Fintype.card J : ℝ≥0∞)^(1/((n : ℝ)+1)) * + (∑ j, matrixLabelReference (E := E) m (S j))^(1-1/((n : ℝ)+1))) := + mul_le_mul' le_rfl (finite_rpow_holder _ (by exact_mod_cast Nat.lt_add_one_of_le hn)) + _ ≤ (128 : ℝ≥0∞)^Module.finrank ℝ E * + ((Fintype.card J : ℝ≥0∞)^(1/((n : ℝ)+1)) * (256 : ℝ≥0∞)^Module.finrank ℝ E) := by + rw [hsum] + exact mul_le_mul' le_rfl (mul_le_mul' le_rfl hV) + _ = _ := by rw [mul_left_comm, ← mul_pow]; norm_num; rw [mul_comm] + +omit [FiniteDimensional ℝ E] in +lemma localNormalize_reconstruct (ν : Measure E) (a : ℕ) {C : ℝ≥0∞} + (hC : C ≠ 0) (hCt : C ≠ ∞) (z : E) {r : ℝ} (hr : 0 < r) : + (C * ENNReal.ofReal (r^a)) • (localNormalize ν a C z r).map (fun t => z+r • t) = + ν.restrict (Metric.closedBall z r) := by + have hc0 : C * ENNReal.ofReal (r^a) ≠ 0 := mul_ne_zero hC (by positivity) + have hct : C * ENNReal.ofReal (r^a) ≠ ∞ := ENNReal.mul_ne_top hCt ENNReal.ofReal_ne_top + rw [localNormalize, Measure.map_smul _ (by fun_prop), smul_smul, ENNReal.mul_inv_cancel hc0 hct, + one_smul, Measure.map_map (by fun_prop) (by fun_prop)] + have he : (fun t : E => z+r • t) ∘ (fun x => r⁻¹ • (x-z)) = id := by + ext x + simp [smul_smul, hr.ne'] + rw [he, Measure.map_id] + +lemma projectionLaw_smul (ν : Measure E) [SFinite ν] (m : ℕ) (c : ℝ≥0∞) : + projectionLaw (c • ν) m = c • projectionLaw ν m := by + rw [projectionLaw, Measure.prod_smul_right, Measure.map_smul _ (by fun_prop)] + rfl + +lemma projectionLaw_affine (ν : Measure E) [SFinite ν] (m : ℕ) (z : E) (r : ℝ) : + projectionLaw (ν.map (fun t => z + r • t)) m = + (projectionLaw ν m).map (fun x => (x.1, fun j => ⟪z,x.1 j⟫ + r * x.2 j)) := by + unfold projectionLaw + rw [← Measure.map_id (μ := Measure.pi (fun _ : Fin m => stdGaussian E)), + Measure.map_prod_map _ _ measurable_id (by fun_prop), Measure.map_map (by fun_prop) (by fun_prop), + Measure.map_id, Measure.map_map (by fun_prop) (by fun_prop)] + congr 1 + ext x <;> simp [inner_add_left, real_inner_smul_left] + +lemma localized_routing_bound {J : Type*} [Fintype J] [MeasurableSpace J] + [MeasurableSingletonClass J] (ν : J → Measure E) [∀ j, IsFiniteMeasure (ν j)] + {a m n : ℕ} {C : ℝ≥0∞} (hν : ∀ j, PolynomialMass (ν j) a C) + (hC : C ≠ 0) (hCt : C ≠ ∞) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) (hn : 1 ≤ n) (hmargin : n+m ≤ a) + (φ : ((Fin m → E) × (Fin m → ℝ)) → J) (hφ : Measurable φ) + (z : E) {r : ℝ} (hr : 0 < r) : + (∑ j, projectionLaw ((ν j).restrict (Metric.closedBall z r)) m {x | φ x = j}) ≤ + (32768 : ℝ≥0∞)^Module.finrank ℝ E * (Fintype.card J : ℝ≥0∞)^(1/((n : ℝ)+1)) * + C * ENNReal.ofReal (r^a) := by + let τ (j : J) := localNormalize (ν j) a C z r + let F : ((Fin m → E) × (Fin m → ℝ)) → ((Fin m → E) × (Fin m → ℝ)) := + fun x => (x.1, fun i => ⟪z,x.1 i⟫ + r * x.2 i) + have hF : Measurable F := by fun_prop + let (j : J) : IsFiniteMeasure (τ j) := localNormalize_finite (hν j) hC hCt z hr + have hb := normalized_routing_bound τ + (fun j => localNormalize_local (hν j) hC hCt z hr) + (fun j => localNormalize_univ (hν j) hC hCt z hr) + (fun j => localNormalize_support (ν j) a C z hr) hd ha hm hn hmargin (φ ∘ F) (hφ.comp hF) + have he (j : J) : projectionLaw ((ν j).restrict (Metric.closedBall z r)) m {x | φ x = j} = + (C * ENNReal.ofReal (r^a)) * projectionLaw (τ j) m {x | φ (F x) = j} := by + rw [← localNormalize_reconstruct (ν j) a hC hCt z hr, projectionLaw_smul, + projectionLaw_affine, Measure.smul_apply, smul_eq_mul, Measure.map_apply hF + (measurableSet_eq_fun hφ measurable_const)] + rfl + simp_rw [he] + rw [← Finset.mul_sum] + exact (mul_le_mul' le_rfl hb).trans_eq (by ring) + +lemma projectionLaw_withDensity_apply (μ : Measure E) [SFinite μ] {h : E → ℝ≥0∞} + (hh : Measurable h) [SFinite (μ.withDensity h)] (m : ℕ) + {S : Set ((Fin m → E) × (Fin m → ℝ))} (hS : MeasurableSet S) : + projectionLaw (μ.withDensity h) m S = + ∫⁻ s, h s * (∫⁻ A, S.indicator (fun _ => (1 : ℝ≥0∞)) (A, fun j => ⟪s,A j⟫) + ∂Measure.pi (fun _ : Fin m => stdGaussian E)) ∂μ := by + have hobs : Measurable (fun x : (Fin m → E) × E => (x.1, fun j => ⟪x.2,x.1 j⟫)) := by fun_prop + have hi : Measurable (fun x : (Fin m → E) × E => S.indicator (fun _ => (1 : ℝ≥0∞)) + (x.1, fun j => ⟪x.2,x.1 j⟫)) := + ((measurable_const : Measurable (fun _ => (1 : ℝ≥0∞))).indicator hS).comp hobs + rw [projectionLaw, Measure.map_apply hobs hS] + rw [← one_mul (((Measure.pi (fun _ : Fin m => stdGaussian E)).prod (μ.withDensity h)) _), + ← lintegral_indicator_const (hobs hS) 1] + change (∫⁻ x : (Fin m → E) × E, S.indicator (fun _ => (1 : ℝ≥0∞)) + (x.1, fun j => ⟪x.2,x.1 j⟫) ∂(Measure.pi (fun _ : Fin m => stdGaussian E)).prod (μ.withDensity h)) = _ + rw [lintegral_prod_symm _ hi.aemeasurable, + lintegral_withDensity_eq_lintegral_mul μ hh hi.lintegral_prod_left] + rfl + +def blockValue {J : Type*} [Fintype J] {m : ℕ} (h : J → E → ℝ≥0∞) + (φ : ((Fin m → E) × (Fin m → ℝ)) → J) (s : E) : ℝ≥0∞ := + ∫⁻ A, h (φ (A, fun j => ⟪s,A j⟫)) s ∂Measure.pi (fun _ : Fin m => stdGaussian E) + +lemma measurable_finite_select {X J : Type*} [MeasurableSpace X] [Fintype J] + [MeasurableSpace J] [MeasurableSingletonClass J] + {h : J → X → ℝ≥0∞} (hh : ∀ j, Measurable (h j)) {φ : X → J} (hφ : Measurable φ) : + Measurable (fun x => h (φ x) x) := by + classical + have he (x : X) : h (φ x) x = ∑ j : J, if φ x = j then h j x else 0 := by simp + simp_rw [he] + exact Finset.measurable_sum _ fun j _ => Measurable.ite + (measurableSet_eq_fun hφ measurable_const) (hh j) measurable_const + +lemma measurable_blockValue {J : Type*} [Fintype J] [MeasurableSpace J] + [MeasurableSingletonClass J] {m : ℕ} {h : J → E → ℝ≥0∞} + (hh : ∀ j, Measurable (h j)) {φ : ((Fin m → E) × (Fin m → ℝ)) → J} + (hφ : Measurable φ) : Measurable (blockValue h φ) := by + apply Measurable.lintegral_prod_left + exact measurable_finite_select (fun j => (hh j).comp measurable_snd) + (hφ.comp (by fun_prop)) + +omit [BorelSpace E] in +lemma blockValue_le_one {J : Type*} [Fintype J] {m : ℕ} {h : J → E → ℝ≥0∞} + (hh : ∀ j s, h j s ≤ 1) (φ : ((Fin m → E) × (Fin m → ℝ)) → J) (s : E) : + blockValue h φ s ≤ 1 := by + exact (lintegral_mono (fun A => hh _ s)).trans_eq (by simp) + +lemma blockValue_mass_identity (μ : Measure E) [IsFiniteMeasure μ] + {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] + {m : ℕ} {h : J → E → ℝ≥0∞} (hh : ∀ j, Measurable (h j)) + (hh1 : ∀ j s, h j s ≤ 1) + {φ : ((Fin m → E) × (Fin m → ℝ)) → J} (hφ : Measurable φ) + {S : Set E} (hS : MeasurableSet S) : + (μ.withDensity (blockValue h φ)) S = + ∑ j, projectionLaw ((μ.withDensity (h j)).restrict S) m {x | φ x = j} := by + classical + let g (j : J) (s : E) (A : Fin m → E) : ℝ≥0∞ := + if φ (A, fun k => ⟪s,A k⟫) = j then h j s else 0 + have hg (j : J) : Measurable (Function.uncurry (g j)) := by + exact Measurable.ite (measurableSet_eq_fun (hφ.comp (by fun_prop)) measurable_const) + ((hh j).comp measurable_fst) measurable_const + have hselect (s : E) (A : Fin m → E) : h (φ (A, fun k => ⟪s,A k⟫)) s = ∑ j, g j s A := by + simp [g] + have he (j : J) : projectionLaw ((μ.withDensity (h j)).restrict S) m {x | φ x = j} = + ∫⁻ s in S, ∫⁻ A, g j s A ∂Measure.pi (fun _ : Fin m => stdGaussian E) ∂μ := by + rw [restrict_withDensity hS] + let : IsFiniteMeasure ((μ.restrict S).withDensity (h j)) := + isFiniteMeasure_withDensity (ne_of_lt ((lintegral_mono (hh1 j)).trans_lt (by simp))) + rw [projectionLaw_withDensity_apply _ (hh j) _ (measurableSet_eq_fun hφ measurable_const)] + apply lintegral_congr + intro s + rw [← lintegral_const_mul' _ _ (ne_of_lt ((hh1 j s).trans_lt (by simp)))] + apply lintegral_congr + intro A + by_cases hx : φ (A, fun k => ⟪s,A k⟫) = j <;> simp [g, hx] + rw [withDensity_apply _ hS] + calc + _ = ∫⁻ s in S, ∑ j, ∫⁻ A, g j s A ∂Measure.pi (fun _ : Fin m => stdGaussian E) ∂μ := by + apply lintegral_congr + intro s + unfold blockValue + simp_rw [hselect] + exact lintegral_finsetSum _ (fun j _ => (hg j).comp (measurable_const.prodMk measurable_id)) + _ = _ := by + rw [lintegral_finsetSum _ (fun j _ => (hg j).lintegral_prod_right)] + simp_rw [he] + +lemma blockValue_mass_bound (μ : Measure E) [IsFiniteMeasure μ] + {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] + {a m n : ℕ} {C : ℝ≥0∞} {h : J → E → ℝ≥0∞} + (hh : ∀ j, Measurable (h j)) (hh1 : ∀ j s, h j s ≤ 1) + (hlocal : ∀ j, PolynomialMass (μ.withDensity (h j)) a C) + (hC : C ≠ 0) (hCt : C ≠ ∞) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) (hn : 1 ≤ n) (hmargin : n+m ≤ a) + {φ : ((Fin m → E) × (Fin m → ℝ)) → J} (hφ : Measurable φ) : + PolynomialMass (μ.withDensity (blockValue h φ)) a + ((32768 : ℝ≥0∞)^Module.finrank ℝ E * (Fintype.card J : ℝ≥0∞)^(1/((n : ℝ)+1)) * C) := by + let (j : J) : IsFiniteMeasure (μ.withDensity (h j)) := + isFiniteMeasure_withDensity (ne_of_lt ((lintegral_mono (hh1 j)).trans_lt (by simp))) + intro z r hr + rw [blockValue_mass_identity μ hh hh1 hφ Metric.isClosed_closedBall.measurableSet] + exact localized_routing_bound (fun j => μ.withDensity (h j)) hlocal hC hCt hd ha hm hn hmargin φ hφ z hr + +end Block + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/ProjectionCoupling.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/ProjectionCoupling.lean new file mode 100644 index 0000000000000000000000000000000000000000..f342b566f163eac3e79d1e91b598e50ed8b36881 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/ProjectionCoupling.lean @@ -0,0 +1,139 @@ +import OAI.Probability.PosteriorReplicas.Regression.GaussianNoise +import OAI.Probability.PosteriorReplicas.Regression.HolderSet +import OAI.Probability.PosteriorReplicas.Regression.LimitSet +import OAI.Probability.PosteriorReplicas.Regression.OuterBound +import OAI.Probability.PosteriorReplicas.Regression.SmoothingMoments + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section ProjectionCoupling +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def matrixLabelReference (m : ℕ) : Measure ((Fin m → E) × (Fin m → ℝ)) := + (Measure.pi (fun _ => stdGaussian E)).prod volume + +def projectionLaw (ν : Measure E) (m : ℕ) : Measure ((Fin m → E) × (Fin m → ℝ)) := + ((Measure.pi (fun _ => stdGaussian E)).prod ν).map + (fun z => (z.1, fun j => ⟪z.2, z.1 j⟫)) + +def gaussianCoupling (ν : Measure E) (m : ℕ) : + Measure ((Fin m → E) × (E × (Fin m → ℝ))) := + (Measure.pi (fun _ => stdGaussian E)).prod + (ν.prod (Measure.pi (fun _ => gaussianReal 0 1))) + +def noisyObservation (m : ℕ) (δ : ℝ) + (z : (Fin m → E) × (E × (Fin m → ℝ))) : (Fin m → E) × (Fin m → ℝ) := + (z.1, fun j => ⟪z.2.1, z.1 j⟫ + δ * z.2.2 j) + +lemma measurable_noisyObservation (m : ℕ) (δ : ℝ) : + Measurable (noisyObservation (E := E) m δ) := by + unfold noisyObservation + fun_prop + +lemma gaussianCoupling_map_noisyObservation_zero (ν : Measure E) [SigmaFinite ν] (m : ℕ) : + (gaussianCoupling ν m).map (noisyObservation m 0) = projectionLaw ν m := by + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (measurable_noisyObservation m 0), + projectionLaw, lintegral_map hf (by fun_prop)] + dsimp [gaussianCoupling, noisyObservation] + simp only [zero_mul, add_zero] + rw [lintegral_prod _ (by fun_prop), lintegral_prod _ (by fun_prop)] + apply lintegral_congr + intro A + rw [lintegral_prod _ (by fun_prop)] + simp + +lemma gaussianCoupling_map_noisyObservation (ν : Measure E) [SigmaFinite ν] + (m : ℕ) (δ : ℝ) (hδ : δ ≠ 0) : + (gaussianCoupling ν m).map (noisyObservation m δ) = + (matrixLabelReference (E := E) m).withDensity + (projectionSmoothing ν (gaussianPDF 0 (NNReal.mk (δ^2) (sq_nonneg δ))) m) := by + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (measurable_noisyObservation m δ), + lintegral_withDensity_eq_lintegral_mul _ + (measurable_projectionSmoothing _ _ (measurable_gaussianPDF _ _) _) hf] + dsimp [gaussianCoupling, matrixLabelReference, noisyObservation] + rw [lintegral_prod _ (by fun_prop), lintegral_prod _ (by + exact ((measurable_projectionSmoothing _ _ (measurable_gaussianPDF _ _) _).mul hf).aemeasurable)] + apply lintegral_congr + intro A + rw [lintegral_prod _ (by fun_prop)] + have he (p : E) := lintegral_gaussian_shift_scale m δ hδ + (fun j => ⟪p, A j⟫) (fun y => f (A, y)) (hf.comp (measurable_const.prodMk measurable_id)) + simp_rw [he] + rw [lintegral_lintegral_swap (by fun_prop)] + apply lintegral_congr + intro y + rw [lintegral_mul_const _ (by fun_prop)] + rfl +lemma matrixLabelReference_outerRegular (m : ℕ) : + (matrixLabelReference (E := E) m).OuterRegular := by + unfold matrixLabelReference + exact (Measure.WeaklyRegular.of_pseudoMetrizableSpace_secondCountable_of_locallyFinite + ((Measure.pi (fun _ : Fin m => stdGaussian E)).prod volume)).toOuterRegular + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma tendsto_noisyObservation (m : ℕ) + (z : (Fin m → E) × (E × (Fin m → ℝ))) : + Tendsto (fun k : ℕ => noisyObservation m (1 / ((k : ℝ) + 1)) z) + atTop (𝓝 (noisyObservation m 0 z)) := by + apply Filter.Tendsto.prodMk_nhds tendsto_const_nhds + apply tendsto_pi_nhds.mpr + intro j + exact tendsto_const_nhds.add + (tendsto_one_div_add_atTop_nhds_zero_nat.mul_const _) + +theorem projectionLaw_set_bound {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (m n : ℕ) (hn : 1 ≤ n) (hmargin : (n : ℝ) + m ≤ a) + (S : Set ((Fin m → E) × (Fin m → ℝ))) : + projectionLaw ν m S ≤ + (ν Set.univ * (replicaConstant ν a m)^n)^(1 / ((n : ℝ) + 1)) * + (matrixLabelReference (E := E) m S)^(1 - 1 / ((n : ℝ) + 1)) := by + have hp : 1 < (n : ℝ) + 1 := by exact_mod_cast (by omega : 1 < n + 1) + have hα : 0 < 1 - 1 / ((n : ℝ) + 1) := by + exact sub_pos.mpr ((div_lt_one (by positivity)).mpr hp) + have hC : ν Set.univ * (replicaConstant ν a m)^n ≠ ∞ := by + unfold replicaConstant + finiteness + have := matrixLabelReference_outerRegular (E := E) m + apply measure_apply_le_of_isOpen _ _ (ENNReal.rpow_ne_top_of_nonneg (by positivity) hC) hα + intro U hU + rw [← gaussianCoupling_map_noisyObservation_zero ν m] + apply map_apply_open_le_of_tendsto (gaussianCoupling ν m) + (matrixLabelReference (E := E) m) (noisyObservation m 0) + (fun k => noisyObservation m (1 / ((k : ℝ) + 1))) + (measurable_noisyObservation m 0) (fun k => measurable_noisyObservation m _) + (tendsto_noisyObservation m) _ _ (U := U) (hU := hU) + intro k V hV + have hδ : (1 / ((k : ℝ) + 1)) ≠ 0 := by positivity + rw [gaussianCoupling_map_noisyObservation ν m _ hδ] + apply withDensity_apply_le_moment _ _ + (measurable_projectionSmoothing _ _ (measurable_gaussianPDF _ _) _) hp _ _ hV.measurableSet + have hv : (NNReal.mk ((1 / ((k : ℝ) + 1)) ^ 2) + (sq_nonneg (1 / ((k : ℝ) + 1)))) ≠ 0 := by + rw [← NNReal.coe_ne_zero] + exact pow_ne_zero 2 hδ + simpa only [← ENNReal.rpow_natCast, Nat.cast_add, Nat.cast_one, matrixLabelReference] + using projectionSmoothing_moment hν hsupport + (gaussianPDF 0 (NNReal.mk ((1 / ((k : ℝ) + 1)) ^ 2) + (sq_nonneg (1 / ((k : ℝ) + 1))))) (measurable_gaussianPDF _ _) + (lintegral_gaussianPDF_eq_one _ hv) m n hmargin + +end ProjectionCoupling + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaKernel.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..e488600f18c3f809867c7ba5edfb74634b6cb14f --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaKernel.lean @@ -0,0 +1,51 @@ +import OAI.Probability.PosteriorReplicas.Regression.PiLast + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section ReplicaKernel +variable {X : Type*} [MeasurableSpace X] (μ : Measure X) [SigmaFinite μ] + +lemma lintegral_fin_prod (n : ℕ) (f : Fin n → X → ℝ≥0∞) (hf : ∀ i, Measurable (f i)) : + ∫⁻ x : Fin n → X, ∏ i, f i (x i) ∂Measure.pi (fun _ => μ) = + ∏ i, ∫⁻ x, f i x ∂μ := by + induction n with + | zero => simp + | succ n ih => + rw [lintegral_pi_snoc μ _ (by fun_prop)] + simp_rw [Fin.prod_univ_castSucc, Fin.snoc_castSucc, Fin.snoc_last] + simp_rw [lintegral_const_mul _ (hf (Fin.last n))] + rw [lintegral_mul_const _ (by fun_prop), ih _ (fun i => hf i.castSucc)] + +lemma lintegral_pow_pi (f : X → ℝ≥0∞) (hf : Measurable f) (n : ℕ) : + (∫⁻ x, f x ∂μ)^n = + ∫⁻ x : Fin n → X, ∏ i, f (x i) ∂Measure.pi (fun _ => μ) := by + rw [lintegral_fin_prod μ n _ (fun _ => hf)] + simp + +lemma lintegral_product_differences (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) + (hφ1 : ∫⁻ x, φ x = 1) (m n : ℕ) (y : Fin m → ℝ) : + ∫⁻ z : Fin m → Fin n → ℝ, + ∏ j, φ (y j) * ∏ i, φ (y j - z j i) = ∏ j, φ (y j) := by + rw [volume_pi, lintegral_fin_prod (volume : Measure (Fin n → ℝ)) m + (fun j z => φ (y j) * ∏ i, φ (y j - z i)) (by intro i; fun_prop)] + apply Finset.prod_congr rfl + intro j _ + rw [lintegral_const_mul _ (by fun_prop), volume_pi, + lintegral_fin_prod (volume : Measure ℝ) n + (fun _ z => φ (y j - z)) (by intro i; fun_prop)] + simp_rw [lintegral_sub_left_eq_self φ (y j), hφ1] + simp + +end ReplicaKernel + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaMoments.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..0882d8d1254e21af9b91770fee27ec7226745ea4 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaMoments.lean @@ -0,0 +1,93 @@ +import OAI.Probability.PosteriorReplicas.Regression.AffineTubes +import OAI.Probability.PosteriorReplicas.Regression.GramDistances +import OAI.Probability.PosteriorReplicas.Regression.PiLast + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section ReplicaMoments +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def replicaWeight (m : ℕ) (p : E) {n : ℕ} (v : Fin n → E) : ℝ≥0∞ := + ∏ i, ENNReal.ofReal ((‖gramSchmidt ℝ (fun j => v j - p) i‖)⁻¹ ^ m) + +lemma measurable_replicaWeight (m : ℕ) (p : E) (n : ℕ) : + Measurable (replicaWeight m p (n := n)) := by + have hs : Measurable (fun v : Fin n → E => fun j => v j - p) := by fun_prop + exact Finset.measurable_prod _ fun i _ => + (((measurable_gramSchmidt i).comp hs).norm.inv.pow_const m).ennreal_ofReal + +omit [MeasurableSpace E] [BorelSpace E] in +lemma replicaWeight_snoc (m : ℕ) (p : E) {n : ℕ} (v : Fin n → E) (x : E) : + replicaWeight m p (Fin.snoc v x) = replicaWeight m p v * + ENNReal.ofReal ((Metric.infDist x (AffineSubspace.mk' p + (Submodule.span ℝ (Set.range (fun i => v i - p))) : Set E))⁻¹ ^ m) := by + unfold replicaWeight + rw [Fin.prod_univ_castSucc] + simp only [gramSchmidt_castSucc, Fin.snoc_castSucc] + rw [norm_gramSchmidt_sub_eq_affine_infDist, image_Iio_last] + simp only [Fin.snoc_last, Fin.snoc_castSucc] + +def replicaConstant (ν : Measure E) (a : ℝ) (m : ℕ) : ℝ≥0∞ := + ν Set.univ + ENNReal.ofReal ((3 : ℝ) ^ Module.finrank ℝ E * (4 : ℝ) ^ a) * + (2 : ℝ≥0∞) ^ (m+1) + +lemma affine_inverse_moment_le_replicaConstant {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (L : AffineSubspace ℝ E) [Nonempty L] (m : ℕ) + (hmargin : (Module.finrank ℝ L.direction : ℝ) + (m + 1 : ℕ) ≤ a) : + ∫⁻ x, ENNReal.ofReal ((Metric.infDist x L)⁻¹ ^ m) ∂ν ≤ replicaConstant ν a m := by + apply (hν.affine_inverse_moment hsupport L m hmargin).trans + dsimp [replicaConstant] + gcongr + · norm_num + · exact Submodule.finrank_le L.direction + +theorem replica_integral_bound {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) (m : ℕ) (p : E) + (n : ℕ) (hmargin : (n : ℝ) + m ≤ a) : + ∫⁻ v : Fin n → E, replicaWeight m p v ∂Measure.pi (fun _ => ν) ≤ + (replicaConstant ν a m) ^ n := by + induction n with + | zero => simp [replicaWeight] + | succ n ih => + have hmargin' : (n : ℝ) + m ≤ a := by exact le_trans (by push_cast; linarith) hmargin + have hinner (v : Fin n → E) : + ∫⁻ x, replicaWeight m p (Fin.snoc v x) ∂ν ≤ + replicaWeight m p v * replicaConstant ν a m := by + simp_rw [replicaWeight_snoc] + rw [lintegral_const_mul _ (by fun_prop)] + gcongr + apply affine_inverse_moment_le_replicaConstant hν hsupport + have hdim := finrank_range_le_card (R := ℝ) (fun i : Fin n => v i - p) + simp only [Fintype.card_fin] at hdim + have hdim' : (Module.finrank ℝ (Submodule.span ℝ (Set.range (fun i => v i - p))) : ℝ) ≤ n := + by exact_mod_cast hdim + rw [AffineSubspace.direction_mk'] + push_cast at hmargin ⊢ + linarith + calc + _ = ∫⁻ v : Fin n → E, ∫⁻ x, replicaWeight m p (Fin.snoc v x) ∂ν + ∂Measure.pi (fun _ => ν) := lintegral_pi_snoc ν _ (measurable_replicaWeight m p (n+1)) + _ ≤ ∫⁻ v : Fin n → E, replicaWeight m p v * replicaConstant ν a m + ∂Measure.pi (fun _ => ν) := lintegral_mono hinner + _ = (∫⁻ v : Fin n → E, replicaWeight m p v ∂Measure.pi (fun _ => ν)) * + replicaConstant ν a m := lintegral_mul_const _ (measurable_replicaWeight m p n) + _ ≤ (replicaConstant ν a m)^n * replicaConstant ν a m := + mul_le_mul' (ih hmargin') le_rfl + _ = _ := (pow_succ _ _).symm +end ReplicaMoments + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaNondegenerate.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaNondegenerate.lean new file mode 100644 index 0000000000000000000000000000000000000000..3b90f175fe51cafd733dda58f6b2d0387f49d145 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/ReplicaNondegenerate.lean @@ -0,0 +1,100 @@ +import OAI.Probability.PosteriorReplicas.Regression.AePiLast +import OAI.Probability.PosteriorReplicas.Regression.GramFactorization +import OAI.Probability.PosteriorReplicas.Regression.ReplicaMoments + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section ReplicaNondegenerate +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma measurableSet_gramSchmidt_ne_zero (p : E) (n : ℕ) : + MeasurableSet {v : Fin n → E | ∀ i, gramSchmidt ℝ (fun j => v j - p) i ≠ 0} := by + rw [Set.ofPred_forall] + apply MeasurableSet.iInter + intro i + have h := (measurable_gramSchmidt i).comp + (show Measurable (fun v : Fin n → E => fun j => v j - p) by fun_prop) + exact (measurableSet_eq_fun h measurable_const).compl + +theorem ae_gramSchmidt_ne_zero {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) (p : E) + (n : ℕ) (hmargin : (n : ℝ) ≤ a) : + ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => ν), + ∀ i, gramSchmidt ℝ (fun j => v j - p) i ≠ 0 := by + induction n with + | zero => exact Filter.Eventually.of_forall fun _ i => Fin.elim0 i + | succ n ih => + rw [ae_pi_snoc ν (measurableSet_gramSchmidt_ne_zero p (n+1))] + have hn : (n : ℝ) ≤ a := by push_cast at hmargin; linarith + filter_upwards [ih hn] with v hv + let L := AffineSubspace.mk' p (Submodule.span ℝ (Set.range (fun i : Fin n => v i - p))) + have hdim : (Module.finrank ℝ L.direction : ℝ) ≤ n := by + dsimp [L] + rw [AffineSubspace.direction_mk'] + have hh := finrank_range_le_card (R := ℝ) (fun i : Fin n => v i - p) + simp only [Fintype.card_fin, Set.finrank] at hh + exact_mod_cast hh + have hnull : ν L = 0 := hν.affine_null hsupport L (by push_cast at hmargin; linarith) + have ha : ∀ᵐ x ∂ν, x ∉ L := by + rw [ae_iff] + convert hnull using 2 + ext x + simp + filter_upwards [ha] with x hx + intro i + induction i using Fin.lastCases with + | last => + apply norm_ne_zero_iff.mp + rw [norm_gramSchmidt_sub_eq_affine_infDist, image_Iio_last] + simp only [Fin.snoc_castSucc, Fin.snoc_last] + exact ne_of_gt ((L.closed_of_finiteDimensional.notMem_iff_infDist_pos + ⟨p, AffineSubspace.self_mem_mk' _ _⟩).mp hx) + | cast j => simpa only [gramSchmidt_castSucc, Fin.snoc_castSucc] using hv j + +theorem ae_replica_linearIndependent {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) (p : E) + (n : ℕ) (hmargin : (n : ℝ) ≤ a) : + ∀ᵐ v : Fin n → E ∂Measure.pi (fun _ => ν), + LinearIndependent ℝ (fun j => v j - p) := by + filter_upwards [ae_gramSchmidt_ne_zero hν hsupport p n hmargin] with v hv + apply Matrix.linearIndependent_of_det_gram_ne_zero + rw [det_gram_eq_prod_gramSchmidt] + exact Finset.prod_ne_zero_iff.mpr fun i _ => pow_ne_zero _ (norm_ne_zero_iff.mpr (hv i)) + +omit [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] in +lemma sqrt_det_gram (n : ℕ) (v : Fin n → E) : + Real.sqrt (Matrix.gram ℝ v).det = ∏ i, ‖gramSchmidt ℝ v i‖ := by + rw [det_gram_eq_prod_gramSchmidt, Real.sqrt_prod _ (fun _ _ => sq_nonneg _)] + simp only [Real.sqrt_sq (norm_nonneg _)] + +omit [MeasurableSpace E] [BorelSpace E] [FiniteDimensional ℝ E] in +lemma replicaWeight_eq_det (m : ℕ) (p : E) {n : ℕ} (v : Fin n → E) : + replicaWeight m p v = ENNReal.ofReal + ((Real.sqrt (Matrix.gram ℝ (fun j => v j - p)).det)⁻¹ ^ m) := by + rw [sqrt_det_gram, ← Finset.prod_inv_distrib, ← Finset.prod_pow] + exact (ENNReal.ofReal_prod_of_nonneg (fun i _ => by positivity)).symm + +theorem gram_integral_bound {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) (m : ℕ) (p : E) + (n : ℕ) (hmargin : (n : ℝ) + m ≤ a) : + ∫⁻ v : Fin n → E, ENNReal.ofReal + ((Real.sqrt (Matrix.gram ℝ (fun j => v j - p)).det)⁻¹ ^ m) + ∂Measure.pi (fun _ => ν) ≤ (replicaConstant ν a m)^n := by + simpa only [← replicaWeight_eq_det] using replica_integral_bound hν hsupport m p n hmargin +end ReplicaNondegenerate + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/SmoothingMoments.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/SmoothingMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f066f6a481907187ad01d90381d29e1abe080cf --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/SmoothingMoments.lean @@ -0,0 +1,72 @@ +import OAI.Probability.PosteriorReplicas.Regression.GaussianKernel +import OAI.Probability.PosteriorReplicas.Regression.ReplicaNondegenerate + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section SmoothingMoments +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def projectionSmoothing (ν : Measure E) (φ : ℝ → ℝ≥0∞) (m : ℕ) + (z : (Fin m → E) × (Fin m → ℝ)) : ℝ≥0∞ := + ∫⁻ t, ∏ j, φ (z.2 j - ⟪t, z.1 j⟫) ∂ν + +lemma measurable_projectionSmoothing (ν : Measure E) [SFinite ν] + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (m : ℕ) : + Measurable (projectionSmoothing ν φ m) := by + apply Measurable.lintegral_prod_right + fun_prop + +lemma projectionSmoothing_pow (ν : Measure E) [SigmaFinite ν] + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (m n : ℕ) + (z : (Fin m → E) × (Fin m → ℝ)) : + (projectionSmoothing ν φ m z)^(n+1) = + ∫⁻ w : E × (Fin n → E), + (∏ j, φ (z.2 j - ⟪w.1, z.1 j⟫)) * + ∏ i, ∏ j, φ (z.2 j - ⟪w.2 i, z.1 j⟫) + ∂ν.prod (Measure.pi (fun _ => ν)) := by + rw [lintegral_prod _ (by fun_prop)] + have hG : Measurable (fun v : Fin n → E => + ∏ i, ∏ j, φ (z.2 j - ⟪v i, z.1 j⟫)) := by fun_prop + simp_rw [lintegral_const_mul _ hG] + rw [lintegral_mul_const _ (by fun_prop), ← lintegral_pow_pi ν + (fun t : E => ∏ j, φ (z.2 j - ⟪t, z.1 j⟫)) (by fun_prop) n] + exact pow_succ' _ _ + +theorem projectionSmoothing_moment {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (φ : ℝ → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ z, φ z = 1) + (m n : ℕ) (hmargin : (n : ℝ) + m ≤ a) : + ∫⁻ z : (Fin m → E) × (Fin m → ℝ), + (projectionSmoothing ν φ m z)^(n+1) + ∂(Measure.pi (fun _ => stdGaussian E)).prod volume ≤ + ν Set.univ * (replicaConstant ν a m)^n := by + simp_rw [projectionSmoothing_pow ν φ hφ m n] + rw [lintegral_lintegral_swap (by fun_prop), lintegral_prod _ (by fun_prop)] + calc + _ ≤ ∫⁻ p, ∫⁻ v : Fin n → E, replicaWeight m p v + ∂Measure.pi (fun _ => ν) ∂ν := by + apply lintegral_mono + intro p + apply lintegral_mono_ae + filter_upwards [ae_replica_linearIndependent hν hsupport p n + (le_trans (le_add_of_nonneg_right (Nat.cast_nonneg m)) hmargin)] with v hv + rw [lintegral_prod _ (by fun_prop), replicaWeight_eq_det, sqrt_det_gram] + exact gaussian_replica_kernel_bound p v hv φ hφ hφ1 m + _ ≤ ∫⁻ _p, (replicaConstant ν a m)^n ∂ν := + lintegral_mono fun p => replica_integral_bound hν hsupport m p n hmargin + _ = _ := by rw [lintegral_const, mul_comm] +end SmoothingMoments + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/SphereBounds.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/SphereBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c9bb3a429901069f62f7b0cc9c189d5fab6d2fe --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/SphereBounds.lean @@ -0,0 +1,124 @@ +import OAI.Probability.PosteriorReplicas.Regression.SupportVolume + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section SphereBounds +open scoped Pointwise +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def unitBallLaw : Measure E := + ((volume : Measure E) (Metric.ball 0 1))⁻¹ • volume.restrict (Metric.closedBall 0 1) + +def sphereLaw : Measure (Metric.sphere (0 : E) 1) := + let σ := (volume : Measure E).toSphere + (σ Set.univ)⁻¹ • σ + +lemma unitBallLaw_closedBall (z : E) {r : ℝ} (hr : 0 < r) : + unitBallLaw (Metric.closedBall z r) ≤ ENNReal.ofReal (r ^ Module.finrank ℝ E) := by + have h0 : (volume : Measure E) (Metric.ball 0 1) ≠ 0 := + (Metric.measure_ball_pos volume 0 zero_lt_one).ne' + have ht : (volume : Measure E) (Metric.ball 0 1) ≠ ∞ := measure_ball_lt_top.ne + calc + _ ≤ ((volume : Measure E) (Metric.ball 0 1))⁻¹ * volume (Metric.closedBall z r) := by + exact mul_le_mul' le_rfl (Measure.restrict_apply_le _ _) + _ = _ := by + rw [Measure.addHaar_closedBall _ _ hr.le, mul_comm _ (_ * _), mul_assoc, + ENNReal.mul_inv_cancel h0 ht, mul_one] + +lemma unitBallLaw_local : HasLocalMassBound (unitBallLaw : Measure E) + (Module.finrank ℝ E : ℝ) := by + intro z _ r hr + simpa only [Real.rpow_natCast] using unitBallLaw_closedBall z hr + +lemma unitBallLaw_support : (unitBallLaw : Measure E).support ⊆ Metric.closedBall 0 1 := by + apply Measure.support_subset_of_isClosed Metric.isClosed_closedBall + rw [mem_ae_iff, unitBallLaw, Measure.smul_apply, smul_eq_mul, + Measure.restrict_apply Metric.isClosed_closedBall.measurableSet.compl] + simp + +instance unitBallLaw_probability : IsProbabilityMeasure (unitBallLaw : Measure E) := by + constructor + rw [unitBallLaw, Measure.smul_apply, smul_eq_mul, Measure.restrict_apply_univ, + Measure.addHaar_closedBall _ _ (by norm_num : (0 : ℝ) ≤ 1)] + simp only [one_pow, ENNReal.ofReal_one, one_mul] + exact ENNReal.inv_mul_cancel (Metric.measure_ball_pos volume 0 zero_lt_one).ne' + measure_ball_lt_top.ne + +instance sphereLaw_probability [Nontrivial E] : IsProbabilityMeasure (sphereLaw (E := E)) := by + constructor + rw [sphereLaw, Measure.smul_apply, smul_eq_mul] + apply ENNReal.inv_mul_cancel _ (measure_ne_top _ _) + rw [Measure.toSphere_apply_univ] + exact mul_ne_zero (by exact_mod_cast (Module.finrank_pos (R := ℝ) (M := E)).ne') + (Metric.measure_ball_pos volume 0 zero_lt_one).ne' + +lemma sphereLaw_apply [Nontrivial E] {s : Set (Metric.sphere (0 : E) 1)} + (hs : MeasurableSet s) : + sphereLaw s = unitBallLaw (Set.Ioo (0 : ℝ) 1 • (Subtype.val '' s)) := by + have hd0 : (Module.finrank ℝ E : ℝ≥0∞) ≠ 0 := by + exact_mod_cast (Module.finrank_pos (R := ℝ) (M := E)).ne' + have hdt : (Module.finrank ℝ E : ℝ≥0∞) ≠ ∞ := ENNReal.natCast_ne_top _ + have hsub : Set.Ioo (0 : ℝ) 1 • (Subtype.val '' s) ⊆ Metric.closedBall (0 : E) 1 := by + rintro _ ⟨r, hr, _, ⟨x, hx, rfl⟩, rfl⟩ + rw [Metric.mem_closedBall, dist_zero_right, norm_smul, + (mem_sphere_zero_iff_norm.mp x.property), mul_one, Real.norm_eq_abs, + abs_of_pos hr.1] + exact hr.2.le + rw [sphereLaw, Measure.smul_apply, smul_eq_mul, Measure.toSphere_apply_univ, + Measure.toSphere_apply' _ hs, ENNReal.mul_inv (Or.inl hd0) (Or.inl hdt), unitBallLaw, Measure.smul_apply, + smul_eq_mul, Measure.restrict_apply' Metric.isClosed_closedBall.measurableSet, + Set.inter_eq_left.mpr hsub] + calc + _ = ((volume : Measure E) (Metric.ball 0 1))⁻¹ * + (((Module.finrank ℝ E : ℝ≥0∞))⁻¹ * (Module.finrank ℝ E)) * + volume (Set.Ioo (0 : ℝ) 1 • (Subtype.val '' s)) := by ring + _ = _ := by rw [ENNReal.inv_mul_cancel hd0 hdt, mul_one] + +lemma sphereLaw_cap_raw [Nontrivial E] (z : E) {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) + (hd : 1 ≤ Module.finrank ℝ E) : + sphereLaw {s : Metric.sphere (0 : E) 1 | dist s.val z ≤ r} ≤ + ENNReal.ofReal ((3 : ℝ) * 4 ^ Module.finrank ℝ E) * + ENNReal.ofReal (r ^ (Module.finrank ℝ E - 1)) := by + classical + let L := (Submodule.span ℝ ({z} : Set E)).toAffineSubspace + let : Nonempty L := ⟨⟨0, (Submodule.span ℝ ({z} : Set E)).zero_mem⟩⟩ + have hl : Module.finrank ℝ L.direction ≤ 1 := by + dsimp only [L] + rw [Submodule.toAffineSubspace_direction] + simpa using (finrank_span_le_card (R := ℝ) ({z} : Set E)) + have hm : (Module.finrank ℝ L.direction : ℝ) + (Module.finrank ℝ E - 1 : ℕ) ≤ + (Module.finrank ℝ E : ℝ) := by + exact_mod_cast (by omega : Module.finrank ℝ L.direction + (Module.finrank ℝ E - 1) ≤ Module.finrank ℝ E) + have hsub : Set.Ioo (0 : ℝ) 1 • + (Subtype.val '' {s : Metric.sphere (0 : E) 1 | dist s.val z ≤ r}) ⊆ + {t | Metric.infDist t L ≤ r} := by + rintro _ ⟨c, hc, _, ⟨s, hs, rfl⟩, rfl⟩ + have hz : c • z ∈ L := Submodule.smul_mem _ c (Submodule.subset_span (by simp)) + exact (Metric.infDist_le_dist_of_mem hz).trans (by + rw [dist_smul₀, Real.norm_eq_abs, abs_of_pos hc.1] + exact (mul_le_mul_of_nonneg_left hs hc.1.le).trans (mul_le_of_le_one_left hr.le hc.2.le)) + rw [sphereLaw_apply (measurableSet_le (by fun_prop) measurable_const)] + apply (measure_mono hsub).trans + apply (unitBallLaw_local.affine_tube_pow unitBallLaw_support L _ hm hr hr1).trans + simp only [Real.rpow_natCast] + apply mul_le_mul' _ le_rfl + apply ENNReal.ofReal_le_ofReal + exact mul_le_mul_of_nonneg_right (by simpa using pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 3) hl) + (by positivity) + +end SphereBounds + +open scoped Pointwise + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/SphereGeometry.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/SphereGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..c5364ffc831dab76282b6018b579b0f14943db86 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/SphereGeometry.lean @@ -0,0 +1,319 @@ +import OAI.Probability.PosteriorReplicas.Regression.SphereBounds + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +section MoreSphere +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def ambientSphereLaw : Measure E := (sphereLaw (E := E)).map Subtype.val + +instance ambientSphereLaw_probability [Nontrivial E] : IsProbabilityMeasure (ambientSphereLaw (E := E)) := by + unfold ambientSphereLaw + infer_instance + +lemma ambientSphereLaw_support : (ambientSphereLaw (E := E)).support ⊆ Metric.sphere 0 1 := by + apply Measure.support_subset_of_isClosed Metric.isClosed_sphere + rw [mem_ae_iff, ambientSphereLaw, Measure.map_apply (by fun_prop) + Metric.isClosed_sphere.measurableSet.compl] + have h : (Subtype.val : Metric.sphere (0 : E) 1 → E) ⁻¹' (Metric.sphere 0 1)ᶜ = ∅ := by + ext x + simp + rw [h, measure_empty] + +lemma ambientSphereLaw_closedBall [Nontrivial E] (z : E) {r : ℝ} (hr : 0 < r) + (k : ℕ) (hk : k ≤ Module.finrank ℝ E - 1) : + ambientSphereLaw (Metric.closedBall z r) ≤ + ENNReal.ofReal ((3 : ℝ) * 4 ^ Module.finrank ℝ E) * ENNReal.ofReal (r^k) := by + by_cases hr1 : r ≤ 1 + · rw [ambientSphereLaw, Measure.map_apply (by fun_prop) Metric.isClosed_closedBall.measurableSet] + apply (sphereLaw_cap_raw z hr hr1 (Module.finrank_pos (R := ℝ) (M := E))).trans + apply mul_le_mul' le_rfl + exact ENNReal.ofReal_le_ofReal (pow_le_pow_of_le_one hr.le hr1 hk) + · have hr1 : 1 ≤ r := (le_of_not_ge hr1) + calc + _ ≤ 1 := prob_le_one + _ ≤ _ := by + apply one_le_mul + · rw [← ENNReal.ofReal_one] + apply ENNReal.ofReal_le_ofReal + have : (1 : ℝ) ≤ 4 ^ Module.finrank ℝ E := one_le_pow₀ (by norm_num) + linarith + · rw [← ENNReal.ofReal_one] + exact ENNReal.ofReal_le_ofReal (one_le_pow₀ hr1) + +lemma terminal_cap_mass [Nontrivial E] (y z : E) {ε r : ℝ} (hε : 0 < ε) (hr : 0 < r) + (a : ℕ) (ha : 2*a ≤ Module.finrank ℝ E - 1) : + ((ambientSphereLaw (E := E)).restrict (Metric.closedBall y ε)) (Metric.closedBall z r) ≤ + ENNReal.ofReal ((3 : ℝ) * 4 ^ Module.finrank ℝ E) * + ENNReal.ofReal (ε^a) * ENNReal.ofReal (r^a) := by + rw [Measure.restrict_apply Metric.isClosed_closedBall.measurableSet] + by_cases h : r ≤ ε + · apply (measure_mono Set.inter_subset_left).trans + apply (ambientSphereLaw_closedBall z hr (2*a) ha).trans + rw [mul_assoc, ← ENNReal.ofReal_mul (pow_nonneg hε.le a)] + apply mul_le_mul' le_rfl + apply ENNReal.ofReal_le_ofReal + rw [mul_comm 2 a, pow_mul, pow_two] + exact mul_le_mul_of_nonneg_right (pow_le_pow_left₀ hr.le h a) (by positivity) + · apply (measure_mono Set.inter_subset_right).trans + apply (ambientSphereLaw_closedBall y hε (2*a) ha).trans + rw [mul_assoc, ← ENNReal.ofReal_mul (pow_nonneg hε.le a)] + apply mul_le_mul' le_rfl + apply ENNReal.ofReal_le_ofReal + rw [mul_comm 2 a, pow_mul, pow_two] + exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ hε.le (le_of_not_ge h) a) (by positivity) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma chord_le_arccos (s t : Metric.sphere (0 : E) 1) : + dist s.val t.val ≤ Real.arccos ⟪s.val,t.val⟫ := by + have hs : ‖s.val‖ = 1 := mem_sphere_zero_iff_norm.mp s.property + have ht : ‖t.val‖ = 1 := mem_sphere_zero_iff_norm.mp t.property + have habs : |⟪s.val,t.val⟫| ≤ 1 := by + simpa [hs, ht] using abs_real_inner_le_norm s.val t.val + have hcos := Real.one_sub_sq_div_two_le_cos (x := Real.arccos ⟪s.val,t.val⟫) + rw [Real.cos_arccos (abs_le.mp habs).1 (abs_le.mp habs).2] at hcos + have hd : (dist s.val t.val)^2 = 2 - 2*⟪s.val,t.val⟫ := by + rw [dist_eq_norm, norm_sub_sq_real, hs, ht] + ring + nlinarith [dist_nonneg (x := s.val) (y := t.val), Real.arccos_nonneg ⟪s.val,t.val⟫] + +lemma unitBallLaw_isometry_apply (e : E ≃ₗᵢ[ℝ] E) (s : Set E) : + unitBallLaw (e ⁻¹' s) = unitBallLaw s := by + have hb : e ⁻¹' Metric.closedBall (0 : E) 1 = Metric.closedBall 0 1 := by + ext x + simp [Metric.mem_closedBall, dist_zero_right] + have hset : e ⁻¹' s ∩ Metric.closedBall (0 : E) 1 = + e ⁻¹' (s ∩ Metric.closedBall 0 1) := by rw [Set.preimage_inter, hb] + rw [unitBallLaw, Measure.smul_apply, Measure.smul_apply, + Measure.restrict_apply' Metric.isClosed_closedBall.measurableSet, + Measure.restrict_apply' Metric.isClosed_closedBall.measurableSet, hset] + congr 1 + calc + _ = (Measure.map e volume) (s ∩ Metric.closedBall 0 1) := + (e.toMeasurableEquiv.measurableEmbedding.map_apply _ _).symm + _ = _ := by rw [e.measurePreserving.map_eq] + +lemma ambientSphereLaw_apply [Nontrivial E] {s : Set E} (hs : MeasurableSet s) : + ambientSphereLaw s = unitBallLaw (Set.Ioo (0 : ℝ) 1 • (Metric.sphere 0 1 ∩ s)) := by + rw [ambientSphereLaw, Measure.map_apply (by fun_prop) hs, + sphereLaw_apply (measurable_subtype_coe hs)] + congr 2 + ext x + simp only [Set.mem_image, Set.mem_preimage, Set.mem_inter_iff] + constructor + · rintro ⟨y, hy, rfl⟩ + exact ⟨y.property, hy⟩ + · rintro ⟨hx, hs⟩ + exact ⟨⟨x,hx⟩,hs,rfl⟩ + +lemma ambientSphereLaw_isometry [Nontrivial E] (e : E ≃ₗᵢ[ℝ] E) : + MeasurePreserving e (ambientSphereLaw (E := E)) (ambientSphereLaw (E := E)) := by + refine ⟨e.continuous.measurable, Measure.ext fun s hs => ?_⟩ + rw [Measure.map_apply e.continuous.measurable hs, + ambientSphereLaw_apply (e.continuous.measurable hs), ambientSphereLaw_apply hs] + have hset : Set.Ioo (0 : ℝ) 1 • (Metric.sphere 0 1 ∩ e ⁻¹' s) = + e ⁻¹' (Set.Ioo (0 : ℝ) 1 • (Metric.sphere 0 1 ∩ s)) := by + ext x + constructor + · rintro ⟨r, hr, y, ⟨hy, hys⟩, he⟩ + refine ⟨r,hr,e y,⟨?_,hys⟩,?_⟩ + · simpa only [mem_sphere_zero_iff_norm, e.norm_map] using hy + · simpa only [map_smul] using congrArg e he + · rintro ⟨r,hr,y,⟨hy,hys⟩,he⟩ + refine ⟨r,hr,e.symm y,⟨?_,?_⟩,?_⟩ + · simpa only [mem_sphere_zero_iff_norm, e.symm.norm_map] using hy + · simpa using hys + · simpa only [map_smul, e.symm_apply_apply] using congrArg e.symm he + rw [hset, unitBallLaw_isometry_apply] + +lemma ambientSphereLaw_ae_norm [Nontrivial E] : + ∀ᵐ x : E ∂ambientSphereLaw, ‖x‖ = 1 := by + filter_upwards [Measure.support_mem_ae (μ := ambientSphereLaw (E := E))] with x hx + exact mem_sphere_zero_iff_norm.mp (ambientSphereLaw_support hx) + +lemma sphere_inner_sq_integrable [Nontrivial E] (v : E) : + Integrable (fun x => ⟪v,x⟫^2) (ambientSphereLaw (E := E)) := by + apply (integrable_const (‖v‖^2)).mono' (by fun_prop) + filter_upwards [ambientSphereLaw_ae_norm (E := E)] with x hx + have h := abs_real_inner_le_norm v x + rw [hx, mul_one] at h + simpa only [Real.norm_eq_abs, abs_pow, sq_abs] using + (sq_le_sq₀ (abs_nonneg _) (norm_nonneg _) |>.2 h) + +lemma sphere_inner_sq_eq [Nontrivial E] {v w : E} (h : ‖v‖ = ‖w‖) : + (∫ x, ⟪v,x⟫^2 ∂ambientSphereLaw) = ∫ x, ⟪w,x⟫^2 ∂ambientSphereLaw := by + let e := (ℝ ∙ (v-w))ᗮ.reflection + have he : e v = w := Submodule.reflection_sub h + have hi := (ambientSphereLaw_isometry e).integral_comp + e.toMeasurableEquiv.measurableEmbedding (fun x => ⟪w,x⟫^2) + rw [← he] at hi + simp only [e.inner_map_map] at hi + simpa only [he] using hi + +lemma sphere_inner_sq_unit [Nontrivial E] {v : E} (hv : ‖v‖ = 1) : + (∫ x, ⟪v,x⟫^2 ∂ambientSphereLaw) = 1 / (Module.finrank ℝ E : ℝ) := by + let b := stdOrthonormalBasis ℝ E + have hsum : ∀ x : E, (∑ i, ⟪b i,x⟫^2) = ‖x‖^2 := by + intro x + simpa only [real_inner_comm x, pow_two, real_inner_self_eq_norm_sq] using + b.sum_inner_mul_inner x x + have h : (Module.finrank ℝ E : ℝ) * (∫ x, ⟪v,x⟫^2 ∂ambientSphereLaw) = 1 := by + calc + _ = ∑ i : Fin (Module.finrank ℝ E), ∫ x, ⟪b i,x⟫^2 ∂ambientSphereLaw := by + have heq : ∀ i, (∫ x, ⟪b i,x⟫^2 ∂ambientSphereLaw) = + ∫ x, ⟪v,x⟫^2 ∂ambientSphereLaw := fun i => + sphere_inner_sq_eq (by rw [b.norm_eq_one, hv]) + simp only [heq, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] + _ = ∫ x, ∑ i, ⟪b i,x⟫^2 ∂ambientSphereLaw := + (integral_finsetSum _ (fun i _ => sphere_inner_sq_integrable (b i))).symm + _ = ∫ _ : E, (1 : ℝ) ∂ambientSphereLaw := by + apply integral_congr_ae + filter_upwards [ambientSphereLaw_ae_norm (E := E)] with x hx + rw [hsum, hx, one_pow] + _ = 1 := by simp + have hd : (Module.finrank ℝ E : ℝ) ≠ 0 := by + exact_mod_cast (Module.finrank_pos (R := ℝ) (M := E)).ne' + exact (eq_div_iff hd).2 (by simpa only [mul_comm] using h) + +lemma sphere_projection_sq_integrable [Nontrivial E] (U : Submodule ℝ E) : + Integrable (fun x => ‖U.orthogonalProjectionOnto x‖^2) (ambientSphereLaw (E := E)) := by + let b := stdOrthonormalBasis ℝ U + have hsum : ∀ x : E, (∑ i, ⟪(b i : E),x⟫^2) = ‖U.orthogonalProjectionOnto x‖^2 := by + intro x + have h := b.sum_inner_mul_inner (U.orthogonalProjectionOnto x) (U.orthogonalProjectionOnto x) + rw [real_inner_self_eq_norm_sq] at h + have hi : ∀ i, ⟪U.orthogonalProjectionOnto x, b i⟫ = ⟪b i, U.orthogonalProjectionOnto x⟫ := + fun i => real_inner_comm _ _ + simpa only [hi, U.inner_orthogonalProjectionOnto_eq_of_mem_left, pow_two] using h + simp_rw [← hsum] + exact integrable_finsetSum _ (fun i _ => sphere_inner_sq_integrable (b i : E)) + +lemma sphere_projection_sq_integral [Nontrivial E] (U : Submodule ℝ E) : + (∫ x, ‖U.orthogonalProjectionOnto x‖^2 ∂ambientSphereLaw) = + (Module.finrank ℝ U : ℝ) / (Module.finrank ℝ E : ℝ) := by + let b := stdOrthonormalBasis ℝ U + have hsum : ∀ x : E, (∑ i, ⟪(b i : E),x⟫^2) = ‖U.orthogonalProjectionOnto x‖^2 := by + intro x + have h := b.sum_inner_mul_inner (U.orthogonalProjectionOnto x) (U.orthogonalProjectionOnto x) + rw [real_inner_self_eq_norm_sq] at h + have hi : ∀ i, ⟪U.orthogonalProjectionOnto x, b i⟫ = ⟪b i, U.orthogonalProjectionOnto x⟫ := + fun i => real_inner_comm _ _ + simpa only [hi, U.inner_orthogonalProjectionOnto_eq_of_mem_left, pow_two] using h + simp_rw [← hsum] + rw [integral_finsetSum _ (fun i _ => sphere_inner_sq_integrable (b i : E))] + have hi : ∀ i, (∫ x, ⟪(b i : E), x⟫^2 ∂ambientSphereLaw) = + 1 / (Module.finrank ℝ E : ℝ) := fun i => + sphere_inner_sq_unit (by exact b.norm_eq_one i) + simp only [hi, Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, mul_one_div] + +def sphereIsometry (e : E ≃ₗᵢ[ℝ] E) : Metric.sphere (0 : E) 1 ≃ₜ Metric.sphere (0 : E) 1 := + e.toHomeomorph.subtype (fun x => by + simp only [mem_sphere_zero_iff_norm] + change ‖x‖ = 1 ↔ ‖e x‖ = 1 + rw [e.norm_map]) + +lemma sphereIsometry_preserving [Nontrivial E] (e : E ≃ₗᵢ[ℝ] E) : + MeasurePreserving (sphereIsometry e) (sphereLaw (E := E)) (sphereLaw (E := E)) := by + refine ⟨(sphereIsometry e).continuous.measurable, ?_⟩ + apply (MeasurableEmbedding.subtype_coe Metric.isClosed_sphere.measurableSet).map_injective + rw [Measure.map_map (by fun_prop) (by fun_prop)] + change (sphereLaw (E := E)).map (e ∘ Subtype.val) = ambientSphereLaw + rw [← Measure.map_map e.continuous.measurable (by fun_prop)] + exact (ambientSphereLaw_isometry e).map_eq + +omit [MeasurableSpace E] [BorelSpace E] in +lemma reflection_dist (U : Submodule ℝ E) (x : E) : + dist x (U.reflection x) = 2 * ‖Uᗮ.starProjection x‖ := by + rw [dist_eq_norm, Submodule.reflection_apply] + have heq : x - (2 • U.starProjection x - x) = (2 : ℝ) • Uᗮ.starProjection x := by + rw [Submodule.starProjection_orthogonal] + simp only [sub_apply, ContinuousLinearMap.id_apply, two_smul ℝ] + abel + rw [heq, norm_smul] + norm_num + +lemma sphere_projection_large [Nontrivial E] (U : Submodule ℝ E) + (hU : 4 * Module.finrank ℝ U ≤ Module.finrank ℝ E) : + sphereLaw {x : Metric.sphere (0 : E) 1 | (4/5 : ℝ) ≤ ‖U.orthogonalProjectionOnto x.val‖^2} ≤ + ENNReal.ofReal (5/16 : ℝ) := by + have hi := ofReal_integral_eq_lintegral_ofReal (sphere_projection_sq_integrable U) + (Filter.Eventually.of_forall fun x => sq_nonneg ‖U.orthogonalProjectionOnto x‖) + rw [sphere_projection_sq_integral] at hi + have hmark := meas_ge_le_lintegral_div + (μ := ambientSphereLaw (E := E)) (f := fun x => ENNReal.ofReal (‖U.orthogonalProjectionOnto x‖^2)) + (by fun_prop) (by norm_num : ENNReal.ofReal (4/5 : ℝ) ≠ 0) (ENNReal.ofReal_ne_top : ENNReal.ofReal (4/5 : ℝ) ≠ ∞) + rw [← hi] at hmark + have hset : {x : E | ENNReal.ofReal (4/5 : ℝ) ≤ ENNReal.ofReal (‖U.orthogonalProjectionOnto x‖^2)} = + {x : E | (4/5 : ℝ) ≤ ‖U.orthogonalProjectionOnto x‖^2} := by + ext x + change ENNReal.ofReal (4/5 : ℝ) ≤ _ ↔ _ + exact ENNReal.ofReal_le_ofReal_iff (sq_nonneg _) + rw [hset, ambientSphereLaw, + (MeasurableEmbedding.subtype_coe Metric.isClosed_sphere.measurableSet).map_apply] at hmark + apply hmark.trans + have hd : (0 : ℝ) < Module.finrank ℝ E := by + exact_mod_cast Module.finrank_pos (R := ℝ) (M := E) + have hdiv : (Module.finrank ℝ U : ℝ) / (Module.finrank ℝ E : ℝ) ≤ 1/4 := by + rw [div_le_iff₀ hd] + have : (4 : ℝ) * Module.finrank ℝ U ≤ Module.finrank ℝ E := by exact_mod_cast hU + linarith + calc + _ ≤ ENNReal.ofReal (1/4 : ℝ) / ENNReal.ofReal (4/5 : ℝ) := by gcongr + _ = ENNReal.ofReal (5/16 : ℝ) := by + rw [← ENNReal.ofReal_div_of_pos (by norm_num : (0 : ℝ) < 4/5)] + norm_num + +lemma sphere_reflection_success_bound [Nontrivial E] (U : Submodule ℝ E) + (hU : 4 * Module.finrank ℝ U ≤ Module.finrank ℝ E) + (S : Set (Metric.sphere (0 : E) 1)) (hS : NullMeasurableSet S sphereLaw) + (hsep : ∀ s ∈ S, sphereIsometry U.reflection s ∈ S → + dist s.val (U.reflection s.val) ≤ 1/5) : + sphereLaw S ≤ ENNReal.ofReal (21/32 : ℝ) := by + let f := sphereIsometry U.reflection + have hp := sphereIsometry_preserving U.reflection + have hi : S ∩ f ⁻¹' S ⊆ + {x : Metric.sphere (0 : E) 1 | (4/5 : ℝ) ≤ ‖U.orthogonalProjectionOnto x.val‖^2} := by + intro s hs + have hd := hsep s hs.1 hs.2 + rw [reflection_dist] at hd + have hn := U.norm_sq_eq_add_norm_sq_starProjection s.val + rw [mem_sphere_zero_iff_norm.mp s.property] at hn + change (4/5 : ℝ) ≤ ‖U.orthogonalProjectionOnto s.val‖^2 + have he : ‖U.starProjection s.val‖ = ‖U.orthogonalProjectionOnto s.val‖ := rfl + rw [he] at hn + nlinarith [norm_nonneg (Uᗮ.starProjection s.val)] + have hinter := (measure_mono hi).trans (sphere_projection_large U hU) + have heq := measure_union_add_inter₀ S (hS.preimage hp.quasiMeasurePreserving) + rw [hp.measure_preimage hS] at heq + calc + sphereLaw S = ENNReal.ofReal (1/2 : ℝ) * (sphereLaw S + sphereLaw S) := by + rw [← two_mul, ← mul_assoc] + have hc : ENNReal.ofReal (1/2 : ℝ) * 2 = 1 := by + rw [← ENNReal.ofReal_ofNat, ← ENNReal.ofReal_mul (by norm_num : (0 : ℝ) ≤ 1/2)] + norm_num + rw [hc, one_mul] + _ = ENNReal.ofReal (1/2 : ℝ) * + (sphereLaw (S ∪ f ⁻¹' S) + sphereLaw (S ∩ f ⁻¹' S)) := by rw [heq] + _ ≤ ENNReal.ofReal (1/2 : ℝ) * (1 + ENNReal.ofReal (5/16 : ℝ)) := by + exact mul_le_mul' le_rfl (add_le_add prob_le_one hinter) + _ = ENNReal.ofReal (21/32 : ℝ) := by + rw [← ENNReal.ofReal_one, ← ENNReal.ofReal_add (by norm_num : (0 : ℝ) ≤ 1) + (by norm_num : (0 : ℝ) ≤ 5/16), + ← ENNReal.ofReal_mul (by norm_num : (0 : ℝ) ≤ 1/2)] + norm_num + +end MoreSphere + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/StreamCaps.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamCaps.lean new file mode 100644 index 0000000000000000000000000000000000000000..510c59fc410f3813f48176047988c5bdbd4be4d2 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamCaps.lean @@ -0,0 +1,108 @@ +import OAI.Probability.PosteriorReplicas.Regression.StreamIntegrals + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +section StreamCaps +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] +variable {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] [Nonempty J] + +def capWeight (y : E) (ε : ℝ) : E → ℝ≥0∞ := + (Metric.closedBall y ε).indicator (fun _ => 1) + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [Nontrivial E] in +lemma measurable_capWeight (y : E) (ε : ℝ) : Measurable (capWeight y ε) := + measurable_const.indicator Metric.isClosed_closedBall.measurableSet + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] in +lemma capWeight_le_one (y s : E) (ε : ℝ) : capWeight y ε s ≤ 1 := by + classical + simp only [capWeight, Set.indicator_apply] + split <;> simp + +lemma capWeight_mass (y : E) {ε : ℝ} (hε : 0 < ε) (a : ℕ) + (ha : 2*a ≤ Module.finrank ℝ E - 1) : + PolynomialMass ((ambientSphereLaw (E := E)).withDensity (capWeight y ε)) a + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) := by + change PolynomialMass ((ambientSphereLaw (E := E)).withDensity ((Metric.closedBall y ε).indicator 1)) a _ + rw [withDensity_indicator_one Metric.isClosed_closedBall.measurableSet] + exact fun z r hr => terminal_cap_mass y z hε hr a ha + +lemma ambient_mass_bound {f : E → ℝ≥0∞} {a : ℕ} {C : ℝ≥0∞} + (h : PolynomialMass ((ambientSphereLaw (E := E)).withDensity f) a C) : + (∫⁻ s, f s ∂ambientSphereLaw) ≤ C := by + rw [← setLIntegral_univ, ← withDensity_apply _ MeasurableSet.univ] + apply (measure_mono_ae ?_).trans (by simpa using h 0 1 zero_lt_one) + filter_upwards [(withDensity_absolutelyContinuous (ambientSphereLaw (E := E)) f).ae_le + (ambientSphereLaw_ae_norm (E := E))] with s hs + intro _ + change dist s 0 ≤ 1 + simp [dist_zero_right, hs] + +lemma continuation_cap_integral_bound {δ : ℕ → J → (E × ℝ) → J} + (hδ : ∀ n j, Measurable (δ n j)) (y : ℕ → J → E) + {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ Module.finrank ℝ E - 1) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (n k : ℕ) (j : J) : + (∫⁻ s, continuation δ (fun n j => capWeight (y n j) ε) n k j s ∂ambientSphereLaw) ≤ + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) * + streamFactor (E := E) (J := J) q ^ (k/q+1) := by + apply ambient_mass_bound + apply continuation_mass_bound _ hδ (fun n j => measurable_capWeight _ _) + (fun n j s => capWeight_le_one _ _ _) + (mul_ne_zero (by positivity) (by positivity)) (ENNReal.mul_ne_top ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top) + (fun n j => capWeight_mass (y n j) hε a ha) + (Module.finrank_pos (R := ℝ) (M := E)) (by omega) hq hqa + +lemma route_cap_bound {δ : ℕ → J → (E × ℝ) → J} + (hδ : ∀ n j, Measurable (δ n j)) (y : J → E) + {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ Module.finrank ℝ E - 1) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (k : ℕ) (j : J) : + ((sphereLaw (E := E)).prod (Measure.pi (fun _ : Fin k => stdGaussian E))) + {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} ≤ + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) * + streamFactor (E := E) (J := J) q ^ (k/q+1) := by + let w : ℕ → J → E → ℝ≥0∞ := fun _ j => capWeight (y j) ε + have hV := measurable_continuation (w := w) hδ (fun _ j => measurable_capWeight (y j) ε) 0 k j + have he (s : E) : continuation δ w 0 k j s = + ∫⁻ A : Fin k → E, capWeight (y (streamRoute δ 0 k j (A,fun i => ⟪s,A i⟫))) ε s + ∂Measure.pi (fun _ => stdGaussian E) := by + simpa [w, blockValue, continuation] using continuation_unroll (w := w) hδ 0 k 0 j s + let S : Set ((Metric.sphere (0 : E) 1) × (Fin k → E)) := + {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} + have hS : MeasurableSet S := by + apply measurableSet_le _ measurable_const + exact measurable_subtype_coe.comp measurable_fst |>.dist + ((measurable_of_finite y).comp ((measurable_streamRoute hδ 0 k j).comp (by fun_prop))) + change ((sphereLaw (E := E)).prod _) S ≤ _ + rw [← one_mul (((sphereLaw (E := E)).prod _) S), ← lintegral_indicator_const hS 1, + lintegral_prod _ (measurable_const.indicator hS).aemeasurable] + have hf : ∀ s : Metric.sphere (0 : E) 1, + (∫⁻ A, S.indicator (fun _ => (1 : ℝ≥0∞)) (s,A) ∂Measure.pi (fun _ => stdGaussian E)) = + continuation δ w 0 k j s.val := by + intro s + rw [he] + apply lintegral_congr + intro A + classical + change (if dist s.val (y (streamRoute δ 0 k j (A,fun i => ⟪s.val,A i⟫))) ≤ ε then 1 else 0) = _ + unfold capWeight + rw [Set.indicator_apply] + rfl + simp_rw [hf] + rw [← lintegral_map hV measurable_subtype_coe] + exact continuation_cap_integral_bound hδ (fun _ => y) hε ha hq hqa 0 k j + +end StreamCaps + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/StreamEstimates.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamEstimates.lean new file mode 100644 index 0000000000000000000000000000000000000000..aec6aaf2a6df263554b9f1bee49131efd7ddfb43 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamEstimates.lean @@ -0,0 +1,101 @@ +import OAI.Probability.PosteriorReplicas.Regression.LabelDependence +import OAI.Probability.PosteriorReplicas.Regression.StreamSlices +import OAI.Probability.PosteriorReplicas.Regression.StreamTransfer + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +namespace Learner + +lemma frozen_success_bound {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (ω : Ω) (hd : 3 ≤ d) + (htrans : ∀ t j, AEMeasurable (fun obs => (L.transition t ω j obs).2) (observationReference d)) + {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ d-1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) : + ((uniformSphere d).prod (sampleLaw d T)) + {z | angularError z.1 (L.estimate z.1 ω z.2) ≤ ε} ≤ + (T+1 : ℝ≥0∞) * (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := State M) q ^ (T/q+1) := by + classical + let : NeZero d := ⟨by omega⟩ + let δ : ℕ → State M → (Vector d × ℝ) → State M := fun t j => (htrans t j).mk _ + have hδ (t : ℕ) (j : State M) : Measurable (δ t j) := (htrans t j).measurable_mk + let μ := (uniformSphere d).prod (sampleLaw d T) + have hgood : ∀ᵐ z ∂μ, ∀ t j (i : Fin T), + (L.transition t ω j (z.2 i,⟪z.1.val,z.2 i⟫)).2 = δ t j (z.2 i,⟪z.1.val,z.2 i⟫) := by + simp only [ae_all_iff] + intro t j i + exact (sphere_sample_observation_quasi (by simpa using hd) i).ae (htrans t j).ae_eq_mk + let S : Fin (T+1) → Set (UnitSphere d × Samples d T) := fun t => + {z | dist z.1.val (L.output t ω (streamRoute δ 0 t (L.initialChoice ω).2 + ((fun i => z.2 (Fin.castLE (by omega) i)),fun i => ⟪z.1.val,z.2 (Fin.castLE (by omega) i)⟫))).val ≤ ε} + have hmono : {z : UnitSphere d × Samples d T | angularError z.1 (L.estimate z.1 ω z.2) ≤ ε} + ≤ᵐ[μ] ⋃ t, S t := by + filter_upwards [hgood] with z hz + intro hs + rcases L.terminal_forced_witness z.1 ω z.2 with ⟨t,ht,he⟩ + have hf : L.forcedRun z.1 ω z.2 t = streamRoute δ 0 t (L.initialChoice ω).2 + ((fun i => z.2 (Fin.castLE ht i)),fun i => ⟪z.1.val,z.2 (Fin.castLE ht i)⟫) := by + rw [L.forcedRun_eq_route z.1 ω z.2 ht] + exact streamRoute_congr _ _ 0 t _ _ _ (fun n j i => hz n j (Fin.castLE ht i)) + have hc : dist z.1.val (L.estimate z.1 ω z.2).val ≤ ε := by + apply le_trans _ hs + simpa only [angularError, dist_comm] using chord_le_arccos (L.estimate z.1 ω z.2) z.1 + refine Set.mem_iUnion.mpr ⟨⟨t,by omega⟩, ?_⟩ + change dist z.1.val (L.output t ω _) ≤ ε + simpa only [estimate, he, hf] using hc + let B : ℝ≥0∞ := (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := State M) q ^ (T/q+1) + have hb (t : Fin (T+1)) : μ (S t) ≤ B := by + simpa only [B, μ, S, uniformSphere, sphereLaw, sampleLaw, finrank_euclideanSpace_fin] using + prefix_route_cap_bound hδ (fun j => (L.output t ω j).val) hε + (by simpa using ha) hq hqa (by omega : (t : ℕ) ≤ T) (L.initialChoice ω).2 + calc + _ ≤ μ (⋃ t, S t) := measure_mono_ae hmono + _ ≤ ∑' t, μ (S t) := measure_iUnion_le S + _ ≤ ∑' _ : Fin (T+1), B := ENNReal.tsum_le_tsum hb + _ = _ := by simp [B, tsum_fintype, nsmul_eq_mul, mul_assoc] + +lemma streaming_success_bound {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 3 ≤ d) {ε : ℝ} (hε : 0 < ε) + {a q : ℕ} (ha : 2*a ≤ d-1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) : + L.uniformSuccess ρ ε ≤ + (T+1 : ℝ≥0∞) * (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := State M) q ^ (T/q+1) := by + let : NeZero d := ⟨by omega⟩ + let : SigmaFinite (observationReference d) := by unfold observationReference; infer_instance + have hω : ∀ᵐ ω ∂ρ, ∀ t j, + AEMeasurable (fun obs => (L.transition t ω j obs).2) (observationReference d) := by + simp only [ae_all_iff] + intro t j + filter_upwards [ae_fiber_aemeasurable (hL.transition t j).prod_swap] with ω hω + exact measurable_snd.comp_aemeasurable hω + have hp := ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := ρ))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) ρ) + let S := {z : UnitSphere d × (Ω × Samples d T) | + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + have hS : NullMeasurableSet S ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := + L.angularSuccess_nullMeasurable ρ ε hL + have he := hp.measure_preimage hS + have hb := prod_null_set_bound (hS.preimage hp.quasiMeasurePreserving) + (c := (T+1 : ℝ≥0∞) * (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := State M) q ^ (T/q+1)) + (by + filter_upwards [hω] with ω hω + exact L.frozen_success_bound ω hd hω hε ha hq hqa) + simpa only [he, measure_univ, mul_one, S, uniformSuccess] using hb + +end Learner + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/StreamIntegrals.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamIntegrals.lean new file mode 100644 index 0000000000000000000000000000000000000000..373ee0bbf34ab849485364acb5b84400130a528e --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamIntegrals.lean @@ -0,0 +1,243 @@ +import OAI.Probability.PosteriorReplicas.Regression.ProjectionBlocks + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +section StreamAux +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +variable {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] + +lemma measurable_select {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + {h : J → X → Y} (hh : ∀ j, Measurable (h j)) {φ : X → J} (hφ : Measurable φ) : + Measurable (fun x => h (φ x) x) := + (measurable_from_prod_countable_right (f := fun p : J × X => h p.1 p.2) hh).comp (hφ.prodMk measurable_id) + +omit [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [BorelSpace E] in +lemma lintegral_pi_cons (ν : Measure E) [SigmaFinite ν] {n : ℕ} + (f : (Fin (n+1) → E) → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ v, f v ∂Measure.pi (fun _ => ν)) = + ∫⁻ x, ∫⁻ v : Fin n → E, f (Fin.cons x v) ∂Measure.pi (fun _ => ν) ∂ν := by + have hp := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => ν) (0 : Fin (n+1))).symm + rw [← hp.lintegral_comp_emb (MeasurableEquiv.measurableEmbedding _) f, lintegral_prod] + · congr 1 + ext x + congr 1 + ext v + congr 1 + simp only [MeasurableEquiv.piFinSuccAbove_symm_apply, Fin.insertNthEquiv] + simp + · exact (hf.comp hp.measurable).aemeasurable + +def streamRoute (δ : ℕ → J → (E × ℝ) → J) (n : ℕ) : + (k : ℕ) → J → ((Fin k → E) × (Fin k → ℝ)) → J + | 0, j, _ => j + | k+1, j, x => streamRoute δ (n+1) k (δ (n+1) j (x.1 0, x.2 0)) (Fin.tail x.1, Fin.tail x.2) + +omit [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [BorelSpace E] in +lemma measurable_streamRoute {δ : ℕ → J → (E × ℝ) → J} + (hδ : ∀ n j, Measurable (δ n j)) (n k : ℕ) (j : J) : + Measurable (streamRoute δ n k j) := by + induction k generalizing n j with + | zero => exact measurable_const + | succ k ih => + change Measurable (fun x : (Fin (k+1) → E) × (Fin (k+1) → ℝ) => streamRoute δ (n+1) k (δ (n+1) j (x.1 0,x.2 0)) (Fin.tail x.1,Fin.tail x.2)) + have ht : Measurable (fun x : (Fin (k+1) → E) × (Fin (k+1) → ℝ) => + (Fin.tail x.1, Fin.tail x.2)) := by + change Measurable (fun x : (Fin (k+1) → E) × (Fin (k+1) → ℝ) => + ((fun i : Fin k => x.1 i.succ), (fun i : Fin k => x.2 i.succ))) + fun_prop + have hd : Measurable (fun x : (Fin (k+1) → E) × (Fin (k+1) → ℝ) => + δ (n+1) j (x.1 0,x.2 0)) := (hδ (n+1) j).comp (by fun_prop) + exact measurable_select (fun a => (ih (n+1) a).comp ht) hd + +def continuation (δ : ℕ → J → (E × ℝ) → J) (w : ℕ → J → E → ℝ≥0∞) + (n : ℕ) : ℕ → J → E → ℝ≥0∞ + | 0, j, s => w n j s + | k+1, j, s => ∫⁻ x, continuation δ w (n+1) k (δ (n+1) j (x, ⟪s,x⟫)) s ∂stdGaussian E + +lemma measurable_continuation {δ : ℕ → J → (E × ℝ) → J} {w : ℕ → J → E → ℝ≥0∞} + (hδ : ∀ n j, Measurable (δ n j)) (hw : ∀ n j, Measurable (w n j)) (n k : ℕ) (j : J) : + Measurable (continuation δ w n k j) := by + induction k generalizing n j with + | zero => exact hw n j + | succ k ih => + apply Measurable.lintegral_prod_left + exact measurable_select (fun a => (ih (n+1) a).comp measurable_snd) + ((hδ (n+1) j).comp (by fun_prop)) + +omit [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] [BorelSpace E] in +lemma continuation_le_one {δ : ℕ → J → (E × ℝ) → J} {w : ℕ → J → E → ℝ≥0∞} + (hw : ∀ n j s, w n j s ≤ 1) (n k : ℕ) (j : J) (s : E) : + continuation δ w n k j s ≤ 1 := by + induction k generalizing n j with + | zero => exact hw n j s + | succ k ih => exact (lintegral_mono (fun x => ih _ _)).trans_eq (by simp) + +lemma continuation_unroll {δ : ℕ → J → (E × ℝ) → J} {w : ℕ → J → E → ℝ≥0∞} + (hδ : ∀ n j, Measurable (δ n j)) + (n m k : ℕ) (j : J) (s : E) : + continuation δ w n (m+k) j s = + blockValue (fun a => continuation δ w (n+m) k a) (streamRoute δ n m j) s := by + induction m generalizing n j with + | zero => + simp [blockValue, streamRoute] + | succ m ih => + rw [Nat.succ_add, continuation] + simp_rw [ih] + unfold blockValue + have hf : Measurable (fun A : Fin (m+1) → E => + continuation δ w (n+(m+1)) k (streamRoute δ n (m+1) j (A,fun i => ⟪s,A i⟫)) s) := by + exact (measurable_of_finite (fun a => continuation δ w (n+(m+1)) k a s)).comp + ((measurable_streamRoute hδ n (m+1) j).comp (by fun_prop)) + rw [lintegral_pi_cons _ _ hf] + apply lintegral_congr + intro x + apply lintegral_congr + intro A + have he : Fin.tail (fun i : Fin (m+1) => ⟪s,(Fin.cons x A : Fin (m+1) → E) i⟫) = (fun i => ⟪s,A i⟫) := by + ext i + simp [Fin.tail] + simp [streamRoute, he, Nat.add_left_comm, Nat.add_comm] + +def streamFactor (q : ℕ) : ℝ≥0∞ := + (32768 : ℝ≥0∞)^Module.finrank ℝ E * (Fintype.card J : ℝ≥0∞)^(1/(q : ℝ)) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [MeasurableSpace J] [MeasurableSingletonClass J] in +lemma streamFactor_ne_top (q : ℕ) : streamFactor (E := E) (J := J) q ≠ ∞ := by + exact ENNReal.mul_ne_top (by simp) (ENNReal.rpow_ne_top_of_nonneg (by positivity) (by simp)) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [MeasurableSpace J] [MeasurableSingletonClass J] in +lemma one_le_streamFactor [Nonempty J] {q : ℕ} (hq : 0 < q) : + 1 ≤ streamFactor (E := E) (J := J) q := by + apply one_le_mul (one_le_pow₀ (by norm_num)) + exact ENNReal.one_le_rpow (by exact_mod_cast Fintype.card_pos (α := J)) (by positivity) + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [BorelSpace E] in +lemma PolynomialMass.mono {μ : Measure E} {a : ℕ} {C D : ℝ≥0∞} + (h : PolynomialMass μ a C) (hCD : C ≤ D) : PolynomialMass μ a D := + fun z r hr => (h z r hr).trans (mul_le_mul' hCD le_rfl) + +lemma continuation_mass_bound [Nonempty J] (μ : Measure E) [IsFiniteMeasure μ] + {δ : ℕ → J → (E × ℝ) → J} {w : ℕ → J → E → ℝ≥0∞} + (hδ : ∀ n j, Measurable (δ n j)) (hw : ∀ n j, Measurable (w n j)) + (hw1 : ∀ n j s, w n j s ≤ 1) + {a q : ℕ} {C : ℝ≥0∞} (hC : C ≠ 0) (hCt : C ≠ ∞) + (hlocal : ∀ n j, PolynomialMass (μ.withDensity (w n j)) a C) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (n k : ℕ) (j : J) : + PolynomialMass (μ.withDensity (continuation δ w n k j)) a + (C * streamFactor (E := E) (J := J) q ^ (k/q+1)) := by + have hden : ((q-1 : ℕ) : ℝ)+1 = (q : ℝ) := by + rw [Nat.cast_sub (by omega : 1 ≤ q), Nat.cast_one] + ring + have hq0 : 0 < q := by omega + have hK1 := one_le_streamFactor (E := E) (J := J) hq0 + have hK0 : streamFactor (E := E) (J := J) q ≠ 0 := ne_of_gt (lt_of_lt_of_le zero_lt_one hK1) + have hKt := streamFactor_ne_top (E := E) (J := J) q + induction k using Nat.strong_induction_on generalizing n j with + | h k ih => + by_cases hk : q ≤ k + · have hki : k-q < k := by omega + have hC1 : C * streamFactor (E := E) (J := J) q ^ ((k-q)/q+1) ≠ 0 := + mul_ne_zero hC (pow_ne_zero _ hK0) + have hC1t : C * streamFactor (E := E) (J := J) q ^ ((k-q)/q+1) ≠ ∞ := + ENNReal.mul_ne_top hCt (ENNReal.pow_ne_top hKt) + have hb := blockValue_mass_bound μ + (fun b => measurable_continuation hδ hw (n+q) (k-q) b) + (fun b s => continuation_le_one hw1 (n+q) (k-q) b s) + (fun b => ih (k-q) hki (n+q) b) hC1 hC1t hd ha + (by omega : q ≤ Module.finrank ℝ E) (by omega : 1 ≤ q-1) + (by omega : q-1+q ≤ a) (measurable_streamRoute hδ n q j) + have he : continuation δ w n k j = + blockValue (fun b => continuation δ w (n+q) (k-q) b) (streamRoute δ n q j) := by + funext s + simpa [Nat.add_sub_of_le hk] using continuation_unroll hδ n q (k-q) j s + rw [he] + have hdiv : k/q = (k-q)/q+1 := by + conv_lhs => rw [← Nat.add_sub_of_le hk] + exact Nat.add_div_left _ hq0 + convert hb using 1 + rw [hden, ← streamFactor, hdiv, pow_succ] + ring + · have hkm : k ≤ q := by omega + have hb := blockValue_mass_bound μ + (fun b => hw (n+k) b) (fun b s => hw1 (n+k) b s) (hlocal (n+k)) hC hCt hd ha + (by omega : k ≤ Module.finrank ℝ E) (by omega : 1 ≤ q-1) + (by omega : q-1+k ≤ a) (measurable_streamRoute hδ n k j) + have he : continuation δ w n k j = blockValue (w (n+k)) (streamRoute δ n k j) := by + funext s + simpa [continuation] using continuation_unroll hδ n k 0 j s + rw [he] + convert hb using 1 + rw [hden, ← streamFactor, Nat.div_eq_of_lt (by omega : k < q)] + simp [mul_comm] + +lemma fin_tail_snoc {X : Type*} {k : ℕ} (A : Fin (k+1) → X) (x : X) : + Fin.tail (Fin.snoc A x : Fin (k+2) → X) = + (Fin.snoc (Fin.tail A : Fin k → X) x : Fin (k+1) → X) := by + rw [← Fin.cons_self_tail A, ← Fin.cons_snoc_eq_snoc_cons, Fin.tail_cons, Fin.tail_cons] + +omit [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] in +lemma streamRoute_snoc (δ : ℕ → J → (E × ℝ) → J) (n k : ℕ) (j : J) + (A : Fin k → E) (b : Fin k → ℝ) (x : E) (y : ℝ) : + streamRoute δ n (k+1) j (Fin.snoc A x, Fin.snoc b y) = + δ (n+k+1) (streamRoute δ n k j (A,b)) (x,y) := by + induction k generalizing n j with + | zero => simp [streamRoute, Fin.snoc_zero] + | succ k ih => + rw [streamRoute] + simp only [Fin.snoc_apply_zero, fin_tail_snoc] + rw [ih, streamRoute] + congr 1; omega + +omit [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [BorelSpace E] in +lemma lintegral_pi_prefix (ν : Measure E) [IsProbabilityMeasure ν] {t T : ℕ} (ht : t ≤ T) + (f : (Fin t → E) → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ x : Fin T → E, f (fun i => x (Fin.castLE ht i)) ∂Measure.pi (fun _ => ν)) = + ∫⁻ x, f x ∂Measure.pi (fun _ => ν) := by + induction T with + | zero => + have : t = 0 := by omega + subst t + rfl + | succ T ih => + by_cases h : t ≤ T + · have he (x : Fin T → E) (y : E) : + (fun i : Fin t => (Fin.snoc x y : Fin (T+1) → E) (Fin.castLE ht i)) = + (fun i : Fin t => x (Fin.castLE h i)) := by + ext i + change (Fin.snoc x y : Fin (T+1) → E) (Fin.castLE h i).castSucc = _ + exact Fin.snoc_castSucc _ _ _ + rw [lintegral_pi_snoc ν (fun x : Fin (T+1) → E => f (fun i => x (Fin.castLE ht i))) + (hf.comp (by fun_prop))] + simp_rw [he, lintegral_const, measure_univ, mul_one] + exact ih h + · have he : t = T+1 := by omega + subst t + rfl + +end StreamAux + +lemma fin_prefix_snoc {X : Type*} {n T : ℕ} (h : n+1 ≤ T) (x : Fin T → X) : + (fun i : Fin (n+1) => x (Fin.castLE h i)) = + (Fin.snoc (fun i : Fin n => x (Fin.castLE (by omega) i)) + (x ⟨n, by omega⟩) : Fin (n+1) → X) := by + ext i + refine Fin.lastCases ?_ (fun j => ?_) i + · simp only [Fin.snoc_last] + rfl + · simp + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/StreamSlices.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamSlices.lean new file mode 100644 index 0000000000000000000000000000000000000000..5678578fcd388ad4d26a1a15ce9cf63d06718f14 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamSlices.lean @@ -0,0 +1,68 @@ +import OAI.Probability.PosteriorReplicas.Regression.LearnerBasics +import OAI.Probability.PosteriorReplicas.Regression.StreamIntegrals + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +namespace Learner +variable {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + +def forcedRun (L : Learner d M T Ω) (s : UnitSphere d) (ω : Ω) (x : Samples d T) : ℕ → State M + | 0 => (L.initialChoice ω).2 + | n+1 => + if hn : n < T then + (L.transition (n+1) ω (L.forcedRun s ω x n) (x ⟨n,hn⟩, ⟪x ⟨n,hn⟩,s.val⟫)).2 + else L.forcedRun s ω x n + +lemma forcedRun_eq_route (s : UnitSphere d) (ω : Ω) (x : Samples d T) + {n : ℕ} (hn : n ≤ T) : + L.forcedRun s ω x n = + streamRoute (fun t j obs => (L.transition t ω j obs).2) 0 n (L.initialChoice ω).2 + ((fun i => x (Fin.castLE hn i)), (fun i => ⟪s.val,x (Fin.castLE hn i)⟫)) := by + induction n with + | zero => rfl + | succ n ih => + rw [forcedRun, dite_eq_left (by omega), ih (by omega)] + rw [fin_prefix_snoc hn x, fin_prefix_snoc hn (fun i => ⟪s.val,x i⟫), streamRoute_snoc] + simp only [zero_add, real_inner_comm] + +lemma run_forced_witness (s : UnitSphere d) (ω : Ω) (x : Samples d T) + (n : ℕ) (hn : n ≤ T) : + (L.run s ω x n = .inl (L.forcedRun s ω x n)) ∨ + ∃ t ≤ n, L.run s ω x n = .inr (t, L.forcedRun s ω x t) := by + induction n with + | zero => + simp only [run, start, forcedRun] + split + · exact Or.inr ⟨0, le_rfl, rfl⟩ + · exact Or.inl rfl + | succ n ih => + rcases ih (by omega) with h | ⟨t,ht,h⟩ + · have hnt : n < T := by omega + rw [run, h] + simp only [dite_eq_left hnt, forcedRun] + split + · exact Or.inr ⟨n+1, le_rfl, by simp [forcedRun, hnt]⟩ + · exact Or.inl rfl + · right + exact ⟨t, by omega, by rw [run, h]⟩ + +lemma terminal_forced_witness (s : UnitSphere d) (ω : Ω) (x : Samples d T) : + ∃ t ≤ T, L.terminal s ω x = (t, L.forcedRun s ω x t) := by + rcases L.run_forced_witness s ω x T le_rfl with h | ⟨t,ht,h⟩ + · exact ⟨T, le_rfl, by simp [terminal, h]⟩ + · exact ⟨t, ht, by simp [terminal, h]⟩ + +end Learner + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/StreamTransfer.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamTransfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..43acaa237ce35d1034efac831e919d1381d91ca7 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/StreamTransfer.lean @@ -0,0 +1,80 @@ +import OAI.Probability.PosteriorReplicas.Regression.ObservationContinuity +import OAI.Probability.PosteriorReplicas.Regression.StreamCaps + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +open scoped Pointwise +section StreamTransfer +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [BorelSpace E] in +lemma measurePreserving_pi_prefix (ν : Measure E) [IsProbabilityMeasure ν] + {t T : ℕ} (ht : t ≤ T) : + MeasurePreserving (fun x : Fin T → E => fun i : Fin t => x (Fin.castLE ht i)) + (Measure.pi (fun _ => ν)) (Measure.pi (fun _ => ν)) := by + refine ⟨by fun_prop, ?_⟩ + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf (by fun_prop)] + exact lintegral_pi_prefix ν ht f hf + +lemma sphere_sample_observation_quasi [Nontrivial E] (hd : 3 ≤ Module.finrank ℝ E) + {T : ℕ} (i : Fin T) : + Measure.QuasiMeasurePreserving + (fun z : (Metric.sphere (0 : E) 1) × (Fin T → E) => (z.2 i, ⟪z.1.val,z.2 i⟫)) + ((sphereLaw (E := E)).prod (Measure.pi (fun _ => stdGaussian E))) + ((stdGaussian E).prod volume) := by + exact (sphere_observation_quasi hd).comp + ((MeasurePreserving.id (sphereLaw (E := E))).prod + (measurePreserving_eval (fun _ : Fin T => stdGaussian E) i)).quasiMeasurePreserving + +omit [NormedAddCommGroup E] [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] in +lemma streamRoute_congr {J : Type*} (δ δ' : ℕ → J → (E × ℝ) → J) + (n k : ℕ) (j : J) (A : Fin k → E) (b : Fin k → ℝ) + (h : ∀ t j i, δ t j (A i,b i) = δ' t j (A i,b i)) : + streamRoute δ n k j (A,b) = streamRoute δ' n k j (A,b) := by + induction k generalizing n j with + | zero => rfl + | succ k ih => + rw [streamRoute, streamRoute, h] + exact ih (n+1) _ (Fin.tail A) (Fin.tail b) (fun t j i => h t j i.succ) + +lemma prefix_route_cap_bound [Nontrivial E] + {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] [Nonempty J] + {δ : ℕ → J → (E × ℝ) → J} (hδ : ∀ n j, Measurable (δ n j)) (y : J → E) + {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ Module.finrank ℝ E - 1) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) {k T : ℕ} (hk : k ≤ T) (j : J) : + ((sphereLaw (E := E)).prod (Measure.pi (fun _ : Fin T => stdGaussian E))) + {z | dist z.1.val (y (streamRoute δ 0 k j + ((fun i => z.2 (Fin.castLE hk i)),fun i => ⟪z.1.val,z.2 (Fin.castLE hk i)⟫))) ≤ ε} ≤ + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) * + streamFactor (E := E) (J := J) q ^ (T/q+1) := by + have hp := (MeasurePreserving.id (sphereLaw (E := E))).prod + (measurePreserving_pi_prefix (stdGaussian E) hk) + have hs : MeasurableSet + {z : (Metric.sphere (0 : E) 1) × (Fin k → E) | + dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} := by + apply measurableSet_le _ measurable_const + exact (measurable_subtype_coe.comp measurable_fst).dist + ((measurable_of_finite y).comp ((measurable_streamRoute hδ 0 k j).comp (by fun_prop))) + apply (le_of_eq (hp.measure_preimage hs.nullMeasurableSet)).trans + apply (route_cap_bound hδ y hε ha hq hqa k j).trans + apply mul_le_mul' le_rfl + exact pow_le_pow_right₀ (one_le_streamFactor (by omega : 0 < q)) + (Nat.add_le_add_right (Nat.div_le_div_right hk) 1) + +end StreamTransfer + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/PosteriorReplicas/Regression/SupportVolume.lean b/lean/OAI/Probability/PosteriorReplicas/Regression/SupportVolume.lean new file mode 100644 index 0000000000000000000000000000000000000000..3eee98b4b9b39ff9b2f1fdbb574bedf02605de20 --- /dev/null +++ b/lean/OAI/Probability/PosteriorReplicas/Regression/SupportVolume.lean @@ -0,0 +1,328 @@ +import OAI.Probability.PosteriorReplicas.Regression.ProjectionCoupling + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +universe u +namespace PosteriorRegression +open scoped Topology +open InnerProductSpace +section SupportVolume +open scoped Pointwise + +def coordinateNorm {m : ℕ} (y : Fin m → ℝ) : ℝ := ‖WithLp.toLp 2 y‖ + +@[fun_prop] lemma continuous_coordinateNorm {m : ℕ} : + Continuous (coordinateNorm (m := m)) := by + unfold coordinateNorm + fun_prop + +lemma coordinateNorm_sq {m : ℕ} (y : Fin m → ℝ) : + coordinateNorm y ^ 2 = ∑ j, (y j)^2 := by + exact EuclideanSpace.real_norm_sq_eq (WithLp.toLp 2 y) + +lemma coordinateNorm_smul {m : ℕ} (c : ℝ) (y : Fin m → ℝ) : + coordinateNorm (c • y) = |c| * coordinateNorm y := by + simp [coordinateNorm, WithLp.toLp_smul, norm_smul, Real.norm_eq_abs] + +def coordinateBall (m : ℕ) (r : ℝ) : Set (Fin m → ℝ) := + {y | coordinateNorm y ≤ r} + +lemma measurableSet_coordinateBall (m : ℕ) (r : ℝ) : + MeasurableSet (coordinateBall m r) := + measurableSet_le continuous_coordinateNorm.measurable measurable_const + +lemma coordinateBall_smul (m : ℕ) (c r : ℝ) (hc : 0 < c) : + coordinateBall m (c * r) = c • coordinateBall m r := by + ext y + constructor + · intro hy + refine ⟨c⁻¹ • y, ?_, by simp [hc.ne']⟩ + change coordinateNorm (c⁻¹ • y) ≤ r + rw [coordinateNorm_smul, abs_of_pos (inv_pos.mpr hc)] + exact (inv_mul_le_iff₀ hc).mpr hy + · rintro ⟨y, hy, rfl⟩ + change coordinateNorm (c • y) ≤ c * r + rw [coordinateNorm_smul, abs_of_pos hc] + exact mul_le_mul_of_nonneg_left hy hc.le + +lemma volume_coordinateBall_smul (m : ℕ) (c r : ℝ) (hc : 0 < c) : + volume (coordinateBall m (c * r)) = + ENNReal.ofReal (c^m) * volume (coordinateBall m r) := by + rw [coordinateBall_smul m c r hc, Measure.addHaar_smul_of_nonneg volume hc.le] + simp + +lemma gaussianPDF_le_exp (x : ℝ) : + gaussianPDF 0 1 x ≤ ENNReal.ofReal (Real.exp (-(x^2)/2)) := by + apply ENNReal.ofReal_le_ofReal + unfold gaussianPDFReal + simp only [NNReal.coe_one, mul_one, sub_zero] + apply mul_le_of_le_one_left (Real.exp_nonneg _) + apply inv_le_one_of_one_le₀ + apply (Real.le_sqrt (by norm_num) (by positivity)).mpr + nlinarith [Real.pi_gt_three] + +lemma lintegral_quarterGaussian_le : + (∫⁻ x : ℝ, ENNReal.ofReal (Real.exp (-(x^2)/4))) ≤ 4 := by + have he : (fun x : ℝ => Real.exp (-(x^2)/4)) = + (fun x : ℝ => Real.exp (-(1/4 : ℝ) * x^2)) := by + ext x + congr 1 + ring + simp_rw [show ∀ x : ℝ, Real.exp (-(x^2)/4) = Real.exp (-(1/4 : ℝ) * x^2) from congrFun he] + rw [← ofReal_integral_eq_lintegral_ofReal + (integrable_exp_neg_mul_sq (by norm_num)) (by filter_upwards [] with x; positivity), + integral_gaussian] + have hs : Real.sqrt (Real.pi / (1/4 : ℝ)) ≤ 4 := by + apply (Real.sqrt_le_iff).mpr + constructor + · norm_num + · nlinarith [Real.pi_lt_four] + exact (ENNReal.ofReal_le_ofReal hs).trans_eq (by norm_num) + +lemma gaussian_density_pair_bound {m : ℕ} (x y : Fin m → ℝ) + (h : coordinateNorm y ≤ coordinateNorm x) : + (∏ j, gaussianPDF 0 1 (x j)) ≤ + (∏ j, ENNReal.ofReal (Real.exp (-(x j)^2/4))) * + ∏ j, ENNReal.ofReal (Real.exp (-(y j)^2/4)) := by + calc + _ ≤ ∏ j, ENNReal.ofReal (Real.exp (-(x j)^2/2)) := + Finset.prod_le_prod fun j _ => gaussianPDF_le_exp (x j) + _ = ENNReal.ofReal (Real.exp (- (∑ j, (x j)^2) / 2)) := by + rw [← ENNReal.ofReal_prod_of_nonneg (fun j _ => Real.exp_nonneg _), ← Real.exp_sum] + congr 2 + rw [← Finset.sum_div, Finset.sum_neg_distrib] + _ ≤ ENNReal.ofReal (Real.exp (- (∑ j, (x j)^2)/4 - (∑ j, (y j)^2)/4)) := by + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + have hn : 0 ≤ coordinateNorm y := norm_nonneg _ + have hs := pow_le_pow_left₀ hn h 2 + rw [coordinateNorm_sq, coordinateNorm_sq] at hs + linarith + _ = _ := by + rw [← ENNReal.ofReal_prod_of_nonneg (fun j _ => Real.exp_nonneg _), + ← ENNReal.ofReal_prod_of_nonneg (fun j _ => Real.exp_nonneg _), + ← Real.exp_sum, ← Real.exp_sum, ← ENNReal.ofReal_mul (Real.exp_nonneg _), + ← Real.exp_add] + congr 2 + simp only [← Finset.sum_div, Finset.sum_neg_distrib] + ring + +lemma measurable_coordinateVolume (m : ℕ) : Measurable (fun x : Fin m → ℝ => volume (coordinateBall m (coordinateNorm x))) := by + have : Measurable (fun z : (Fin m → ℝ) × (Fin m → ℝ) => + ({z | coordinateNorm z.2 ≤ coordinateNorm z.1} : Set _).indicator + (fun _ => (1 : ℝ≥0∞)) z) := + measurable_const.indicator (measurableSet_le (by fun_prop) (by fun_prop)) + change Measurable (Function.uncurry (fun x y : Fin m → ℝ => + (coordinateBall m (coordinateNorm x)).indicator (fun _ => (1 : ℝ≥0∞)) y)) at this + convert this.lintegral_prod_right (ν := (volume : Measure (Fin m → ℝ))) using 1 + ext x + rw [lintegral_indicator (measurableSet_coordinateBall m _)] + simp + +lemma gaussian_expected_coordinate_volume (m : ℕ) : + (∫⁻ x : Fin m → ℝ, volume (coordinateBall m (coordinateNorm x)) + ∂Measure.pi (fun _ => gaussianReal 0 1)) ≤ (16 : ℝ≥0∞)^m := by + have hB := measurable_coordinateVolume m + rw [pi_gaussian_withDensity m 1 (by norm_num), + lintegral_withDensity_eq_lintegral_mul _ (by fun_prop) hB] + have hi (x : Fin m → ℝ) : + (∏ j, gaussianPDF 0 1 (x j)) * volume (coordinateBall m (coordinateNorm x)) = + ∫⁻ y : Fin m → ℝ, (coordinateBall m (coordinateNorm x)).indicator + (fun _ => ∏ j, gaussianPDF 0 1 (x j)) y := by + rw [lintegral_indicator (measurableSet_coordinateBall m _)] + simp + simp only [Pi.mul_apply] + simp_rw [hi] + calc + _ ≤ ∫⁻ x : Fin m → ℝ, ∫⁻ y : Fin m → ℝ, + (∏ j, ENNReal.ofReal (Real.exp (-(x j)^2/4))) * + ∏ j, ENNReal.ofReal (Real.exp (-(y j)^2/4)) := by + apply lintegral_mono + intro x + apply lintegral_mono + intro y + by_cases hy : y ∈ coordinateBall m (coordinateNorm x) + · rw [Set.indicator_of_mem hy] + exact gaussian_density_pair_bound x y hy + · rw [Set.indicator_of_notMem hy] + exact zero_le + _ = ((∫⁻ z : ℝ, ENNReal.ofReal (Real.exp (-(z^2)/4)))^m)^2 := by + have hJ : (∫⁻ y : Fin m → ℝ, ∏ j, ENNReal.ofReal (Real.exp (-(y j)^2/4))) = + (∫⁻ z : ℝ, ENNReal.ofReal (Real.exp (-(z^2)/4)))^m := by + rw [volume_pi, lintegral_fin_prod volume m + (fun _ => fun z : ℝ => ENNReal.ofReal (Real.exp (-(z^2)/4))) (fun _ => by fun_prop)] + simp + have hj (x : Fin m → ℝ) := lintegral_const_mul (μ := volume) + (∏ j, ENNReal.ofReal (Real.exp (-(x j)^2/4))) + (by fun_prop : Measurable (fun y : Fin m → ℝ => + ∏ j, ENNReal.ofReal (Real.exp (-(y j)^2/4)))) + simp_rw [hj, hJ] + rw [lintegral_mul_const _ (by fun_prop), hJ, pow_two] + _ ≤ ((4 : ℝ≥0∞)^m)^2 := pow_le_pow_left₀ (by positivity) + (pow_le_pow_left₀ (by positivity) lintegral_quarterGaussian_le m) 2 + _ = _ := by rw [← pow_mul, Nat.mul_comm, pow_mul]; norm_num + +section Rows +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma stdGaussian_inner_map (u : E) : + (stdGaussian E).map (fun x => ⟪u, x⟫) = + gaussianReal 0 (NNReal.mk (‖u‖^2) (sq_nonneg ‖u‖)) := by + have h := IsGaussian.map_eq_gaussianReal (μ := stdGaussian E) (innerSL ℝ u) + have he : (⇑(innerSL ℝ u)) = (fun x => ⟪u, x⟫) := by + ext x + exact innerSL_apply_apply ℝ u x + simp only [integral_strongDual_stdGaussian, variance_dual_stdGaussian, innerSL_apply_norm] at h + rw [he] at h + have hh : (‖u‖^2).toNNReal = NNReal.mk (‖u‖^2) (sq_nonneg ‖u‖) := by + ext + simp + simpa only [integral_strongDual_stdGaussian, variance_dual_stdGaussian, + innerSL_apply_norm, hh] using h + +lemma rows_inner_map (u : E) (m : ℕ) : + (Measure.pi (fun _ : Fin m => stdGaussian E)).map + (fun A => fun j => ⟪u, A j⟫) = + (Measure.pi (fun _ : Fin m => gaussianReal 0 1)).map + (fun x => ‖u‖ • x) := by + rw [Measure.pi_map_pi (f := fun _ : Fin m => fun x : E => ⟪u, x⟫) + (fun _ => (by fun_prop : Measurable (fun x : E => ⟪u, x⟫)).aemeasurable)] + simp_rw [stdGaussian_inner_map] + exact (pi_gaussian_map_scale m ‖u‖).symm + +lemma rows_expected_coordinate_volume (u : E) (hu : ‖u‖ ≤ 1) (m : ℕ) : + (∫⁻ A : Fin m → E, volume (coordinateBall m (coordinateNorm (fun j => ⟪u, A j⟫))) + ∂Measure.pi (fun _ => stdGaussian E)) ≤ (16 : ℝ≥0∞)^m := by + have h := congrArg (fun μ : Measure (Fin m → ℝ) => + ∫⁻ y, volume (coordinateBall m (coordinateNorm y)) ∂μ) (rows_inner_map u m) + rw [lintegral_map (measurable_coordinateVolume m) (by fun_prop), + lintegral_map (measurable_coordinateVolume m) (by fun_prop)] at h + rw [h] + apply le_trans _ (gaussian_expected_coordinate_volume m) + apply lintegral_mono + intro x + apply measure_mono + intro y hy + change coordinateNorm y ≤ coordinateNorm x + apply le_trans hy + rw [coordinateNorm_smul, abs_of_nonneg (norm_nonneg _)] + exact mul_le_of_le_one_left (norm_nonneg _) hu + +def rowOperator {m : ℕ} (A : Fin m → E) : E →L[ℝ] EuclideanSpace ℝ (Fin m) := + (PiLp.continuousLinearEquiv 2 ℝ (fun _ : Fin m => ℝ)).symm.toContinuousLinearMap.comp + (ContinuousLinearMap.pi (fun j => innerSL ℝ (A j))) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma rowOperator_apply {m : ℕ} (A : Fin m → E) (t : E) : + rowOperator A t = WithLp.toLp 2 (fun j => ⟪t, A j⟫) := by + ext j + exact real_inner_comm _ _ + +def netProjectionSupport (s : Finset E) (m : ℕ) : + Set ((Fin m → E) × (Fin m → ℝ)) := + ⋃ u ∈ s, {z | coordinateNorm z.2 ≤ 2 * coordinateNorm (fun j => ⟪u, z.1 j⟫)} + +lemma measurableSet_netProjectionSupport (s : Finset E) (m : ℕ) : + MeasurableSet (netProjectionSupport s m) := by + apply MeasurableSet.biUnion s.countable_toSet + intro u _ + exact measurableSet_le (by fun_prop) (by fun_prop) + +lemma netProjectionSupport_volume (s : Finset E) (hs : ∀ u ∈ s, ‖u‖ ≤ 1) (m : ℕ) : + matrixLabelReference (E := E) m (netProjectionSupport s m) ≤ + (s.card : ℝ≥0∞) * (32 : ℝ≥0∞)^m := by + classical + apply (measure_biUnion_finset_le s _).trans + calc + _ ≤ ∑ _u ∈ s, (32 : ℝ≥0∞)^m := by + apply Finset.sum_le_sum + intro u hu + rw [matrixLabelReference, Measure.prod_apply (measurableSet_le (by fun_prop) (by fun_prop))] + change (∫⁻ A : Fin m → E, + volume (coordinateBall m (2 * coordinateNorm (fun j => ⟪u, A j⟫))) + ∂Measure.pi (fun _ => stdGaussian E)) ≤ _ + simp_rw [volume_coordinateBall_smul m 2 _ (by norm_num)] + have hme : Measurable (fun A : Fin m → E => + volume (coordinateBall m (coordinateNorm (fun j => ⟪u, A j⟫)))) := + (measurable_coordinateVolume m).comp (by fun_prop) + rw [lintegral_const_mul _ hme] + calc + _ ≤ ENNReal.ofReal ((2 : ℝ)^m) * (16 : ℝ≥0∞)^m := + mul_le_mul' le_rfl (rows_expected_coordinate_volume u (hs u hu) m) + _ = _ := by rw [ENNReal.ofReal_pow (by norm_num)]; norm_num [← mul_pow] + _ = _ := by simp +end Rows + +section NetNorm +variable {E F : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + [NormedAddCommGroup F] [NormedSpace ℝ F] +lemma opNorm_le_twice_net (f : E →L[ℝ] F) (s : Finset E) + (hnet : ∀ x : E, ‖x‖ ≤ 1 → ∃ y ∈ s, dist x y ≤ 1/2) : + ‖f‖ ≤ 2 * (s.sup (fun u => ‖f u‖₊) : ℝ≥0) := by + classical + let K : ℝ := (s.sup (fun u => ‖f u‖₊) : ℝ≥0) + have hK : 0 ≤ K := NNReal.coe_nonneg _ + have hbound : ‖f‖ ≤ K + ‖f‖/2 := by + apply ContinuousLinearMap.opNorm_le_of_unit_norm (by positivity) + intro x hx + obtain ⟨y, hy, hxy⟩ := hnet x hx.le + have hfy : ‖f y‖ ≤ K := by + exact_mod_cast (Finset.le_sup (f := fun u => ‖f u‖₊) hy) + calc + ‖f x‖ = ‖f y + f (x-y)‖ := by rw [map_sub]; congr 1; abel + _ ≤ ‖f y‖ + ‖f (x-y)‖ := norm_add_le _ _ + _ ≤ K + ‖f‖ * (1/2) := add_le_add hfy + ((f.le_opNorm (x-y)).trans (mul_le_mul_of_nonneg_left + (by simpa [dist_eq_norm] using hxy) (norm_nonneg _))) + _ = _ := by ring + dsimp [K] at hbound + linarith +end NetNorm + +section SupportExistence +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem exists_projection_support (m : ℕ) (hm : m ≤ Module.finrank ℝ E) : + ∃ D : Set ((Fin m → E) × (Fin m → ℝ)), MeasurableSet D ∧ + (∀ A t, ‖t‖ ≤ 1 → (A, fun j => ⟪t, A j⟫) ∈ D) ∧ + matrixLabelReference (E := E) m D ≤ (192 : ℝ≥0∞)^(Module.finrank ℝ E) := by + classical + obtain ⟨s, hs, hc, hnet⟩ := exists_unit_ball_net (E := E) + (by norm_num : (0 : ℝ) < 1/2) (by norm_num : (1/2 : ℝ) ≤ 1) + have hsne : s.Nonempty := by + obtain ⟨u, hu, _⟩ := hnet 0 (by simp) + exact ⟨u, hu⟩ + refine ⟨netProjectionSupport s m, measurableSet_netProjectionSupport s m, ?_, ?_⟩ + · intro A t ht + obtain ⟨u, hu, he⟩ := s.exists_mem_eq_sup hsne (fun u => ‖rowOperator A u‖₊) + refine Set.mem_iUnion.mpr ⟨u, Set.mem_iUnion.mpr ⟨hu, ?_⟩⟩ + change coordinateNorm (fun j => ⟪t, A j⟫) ≤ + 2 * coordinateNorm (fun j => ⟪u, A j⟫) + change ‖WithLp.toLp 2 (fun j => ⟪t, A j⟫)‖ ≤ + 2 * ‖WithLp.toLp 2 (fun j => ⟪u, A j⟫)‖ + rw [← rowOperator_apply, ← rowOperator_apply] + calc + _ ≤ ‖rowOperator A‖ * ‖t‖ := (rowOperator A).le_opNorm t + _ ≤ ‖rowOperator A‖ := mul_le_of_le_one_right (norm_nonneg _) ht + _ ≤ _ := by simpa [he] using opNorm_le_twice_net (rowOperator A) s hnet + · apply (netProjectionSupport_volume s hs m).trans + have hcard : (s.card : ℝ≥0∞) ≤ (6 : ℝ≥0∞)^(Module.finrank ℝ E) := by + have h : (s.card : ℝ) ≤ (6 : ℝ)^(Module.finrank ℝ E) := by norm_num at hc ⊢; exact hc + simpa using ENNReal.ofReal_le_ofReal h + calc + _ ≤ (6 : ℝ≥0∞)^Module.finrank ℝ E * (32 : ℝ≥0∞)^Module.finrank ℝ E := + mul_le_mul' hcard (pow_le_pow_right₀ (by norm_num) hm) + _ = _ := by rw [← mul_pow]; norm_num +end SupportExistence + +end SupportVolume + +end PosteriorRegression +end + +end OAI diff --git a/lean/OAI/Probability/ProbabilityMeasure/ArctanCenter.lean b/lean/OAI/Probability/ProbabilityMeasure/ArctanCenter.lean new file mode 100644 index 0000000000000000000000000000000000000000..6ae2911b25b14ec84889dd9ff8d7fba3a002c302 --- /dev/null +++ b/lean/OAI/Probability/ProbabilityMeasure/ArctanCenter.lean @@ -0,0 +1,277 @@ +import Mathlib + +namespace OAI + +/-! +# Arctangent centers of probability laws + +Every real probability law has a unique arctangent center without moment assumptions. +The center depends only on the law, is translation-equivariant, and is continuous +for weak convergence. Convergence of translated log-diameter laws yields scalar +normalization limits; no FK/spanning-tree GHP convergence theorem is asserted. +-/ + +open MeasureTheory Filter Set +open scoped Topology BoundedContinuousFunction + +noncomputable section +namespace MetricMeasureLimits.DiameterCenter + +/-- Expected arctangent after centering at a deterministic real number. -/ +def score (μ : ProbabilityMeasure ℝ) (t : ℝ) : ℝ := + ∫ y, Real.arctan (y - t) ∂(μ : Measure ℝ) + +private lemma norm_arctan_le (x : ℝ) : ‖Real.arctan x‖ ≤ Real.pi / 2 := by + rw [Real.norm_eq_abs, abs_le] + exact ⟨(Real.arctan_mem_Ioo x).1.le, (Real.arctan_mem_Ioo x).2.le⟩ + +lemma integrable_score (μ : ProbabilityMeasure ℝ) (t : ℝ) : + Integrable (fun y => Real.arctan (y - t)) (μ : Measure ℝ) := by + apply (integrable_const (Real.pi / 2)).mono' + · exact (Real.continuous_arctan.comp (continuous_id.sub continuous_const)).aestronglyMeasurable + · exact ae_of_all _ fun y => norm_arctan_le (y - t) + +lemma continuous_score (μ : ProbabilityMeasure ℝ) : Continuous (score μ) := by + refine continuous_of_dominated (bound := fun _ => Real.pi / 2) ?_ ?_ + (integrable_const _) ?_ + · intro t + exact (Real.continuous_arctan.comp (continuous_id.sub continuous_const)).aestronglyMeasurable + · intro t + exact ae_of_all _ fun y => norm_arctan_le (y - t) + · exact ae_of_all _ fun y => + Real.continuous_arctan.comp (continuous_const.sub continuous_id) + +lemma strictAnti_score (μ : ProbabilityMeasure ℝ) : StrictAnti (score μ) := by + intro s t hst + have hpos (y : ℝ) : 0 < Real.arctan (y - s) - Real.arctan (y - t) := by + exact sub_pos.mpr (Real.arctan_strictMono (sub_lt_sub_left hst y)) + have hint : Integrable (fun y => Real.arctan (y - s) - Real.arctan (y - t)) + (μ : Measure ℝ) := (integrable_score μ s).sub (integrable_score μ t) + have hsupp : Function.support (fun y => Real.arctan (y - s) - Real.arctan (y - t)) + = Set.univ := by + ext y + simp only [Function.mem_support, mem_univ, iff_true] + exact (hpos y).ne' + have hi : 0 < ∫ y, Real.arctan (y - s) - Real.arctan (y - t) ∂(μ : Measure ℝ) := by + rw [integral_pos_iff_support_of_nonneg (fun y => (hpos y).le) hint, hsupp] + simp + rw [integral_sub (integrable_score μ s) (integrable_score μ t)] at hi + exact sub_pos.mp hi + +lemma tendsto_score_atTop (μ : ProbabilityMeasure ℝ) : + Tendsto (score μ) atTop (𝓝 (-(Real.pi / 2))) := by + have h : Tendsto (score μ) atTop + (𝓝 (∫ _ : ℝ, -(Real.pi / 2) ∂(μ : Measure ℝ))) := by + refine tendsto_integral_filter_of_dominated_convergence + (fun _ => Real.pi / 2) ?_ ?_ (integrable_const _) ?_ + · exact Eventually.of_forall fun t => (integrable_score μ t).aestronglyMeasurable + · exact Eventually.of_forall fun t => ae_of_all _ fun y => norm_arctan_le (y - t) + · refine ae_of_all _ fun y => ?_ + apply Real.tendsto_arctan_atBot.mono_right nhdsWithin_le_nhds |>.comp + change Tendsto (fun t : ℝ => y - t) _ _ + simpa only [sub_eq_add_neg] using + tendsto_atBot_add_const_left atTop y tendsto_neg_atTop_atBot + simpa using h + +lemma tendsto_score_atBot (μ : ProbabilityMeasure ℝ) : + Tendsto (score μ) atBot (𝓝 (Real.pi / 2)) := by + have h : Tendsto (score μ) atBot + (𝓝 (∫ _ : ℝ, Real.pi / 2 ∂(μ : Measure ℝ))) := by + refine tendsto_integral_filter_of_dominated_convergence + (fun _ => Real.pi / 2) ?_ ?_ (integrable_const _) ?_ + · exact Eventually.of_forall fun t => (integrable_score μ t).aestronglyMeasurable + · exact Eventually.of_forall fun t => ae_of_all _ fun y => norm_arctan_le (y - t) + · refine ae_of_all _ fun y => ?_ + apply Real.tendsto_arctan_atTop.mono_right nhdsWithin_le_nhds |>.comp + change Tendsto (fun t : ℝ => y - t) _ _ + simpa only [sub_eq_add_neg] using + tendsto_atTop_add_const_left atBot y tendsto_neg_atBot_atTop + simpa using h + +/-- Every real probability law has a unique arctangent center, without a +moment assumption. This is the existence/uniqueness part of `measure:center`. -/ +theorem existsUnique_center (μ : ProbabilityMeasure ℝ) : + ∃! t : ℝ, score μ t = 0 := by + have hneg : ∃ t, score μ t < 0 := + ((tendsto_score_atTop μ).eventually_lt_const (by have := Real.pi_pos; linarith)).exists + have hpos : ∃ t, 0 < score μ t := + ((tendsto_score_atBot μ).eventually_const_lt (by have := Real.pi_pos; linarith)).exists + obtain ⟨m, hm⟩ := mem_range_of_exists_le_of_exists_ge (continuous_score μ) + (hneg.imp fun _ h => h.le) (hpos.imp fun _ h => h.le) + refine ⟨m, hm, ?_⟩ + intro t ht + exact (strictAnti_score μ).injective (ht.trans hm.symm) + +/-- The center is a function of the unconditional probability law alone. -/ +def center (μ : ProbabilityMeasure ℝ) : ℝ := (existsUnique_center μ).choose + +@[simp] theorem score_center (μ : ProbabilityMeasure ℝ) : score μ (center μ) = 0 := + (existsUnique_center μ).choose_spec.1 + +lemma center_eq_of_score_eq_zero (μ : ProbabilityMeasure ℝ) {t : ℝ} + (ht : score μ t = 0) : center μ = t := + (strictAnti_score μ).injective ((score_center μ).trans ht.symm) + +lemma score_pos_iff (μ : ProbabilityMeasure ℝ) (t : ℝ) : + 0 < score μ t ↔ t < center μ := by + rw [← score_center μ, (strictAnti_score μ).lt_iff_gt] + +lemma score_neg_iff (μ : ProbabilityMeasure ℝ) (t : ℝ) : + score μ t < 0 ↔ center μ < t := by + rw [← score_center μ, (strictAnti_score μ).lt_iff_gt] + +/-- Push a probability law forward by translation by `c`. -/ +def translate (μ : ProbabilityMeasure ℝ) (c : ℝ) : ProbabilityMeasure ℝ := + μ.map (fun y => y + c) + +lemma score_translate (μ : ProbabilityMeasure ℝ) (c t : ℝ) : + score (translate μ c) (t + c) = score μ t := by + unfold score translate + rw [ProbabilityMeasure.toMeasure_map, integral_map_of_stronglyMeasurable + (measurable_id'.add_const c)] + · congr 1 + ext y + congr 1 + ring + · exact (Real.continuous_arctan.comp + (continuous_id.sub continuous_const)).stronglyMeasurable + +/-- Translation equivariance in `measure:center`. -/ +theorem center_translate (μ : ProbabilityMeasure ℝ) (c : ℝ) : + center (translate μ c) = center μ + c := by + apply center_eq_of_score_eq_zero + rw [score_translate, score_center] + +/-- A bounded continuous arctangent test of a law. -/ +def arctanTest (t : ℝ) : ℝ →ᵇ ℝ := + BoundedContinuousFunction.mkOfBound + ⟨fun y => Real.arctan (y - t), + Real.continuous_arctan.comp (continuous_id.sub continuous_const)⟩ Real.pi + (fun x y => by + calc + dist (Real.arctan (x - t)) (Real.arctan (y - t)) + ≤ ‖Real.arctan (x - t)‖ + ‖Real.arctan (y - t)‖ := dist_le_norm_add_norm _ _ + _ ≤ Real.pi / 2 + Real.pi / 2 := add_le_add (norm_arctan_le _) (norm_arctan_le _) + _ = Real.pi := by ring) + +lemma continuous_score_law (t : ℝ) : Continuous (fun μ : ProbabilityMeasure ℝ => score μ t) := + ProbabilityMeasure.continuous_integral_boundedContinuousFunction (arctanTest t) + +/-- Continuity under weak convergence of real probability laws in +`measure:center`. The filter is arbitrary, not just a filter on subsequences. -/ +theorem tendsto_center {ι : Type*} {l : Filter ι} {μs : ι → ProbabilityMeasure ℝ} + {μ : ProbabilityMeasure ℝ} (h : Tendsto μs l (𝓝 μ)) : + Tendsto (fun i => center (μs i)) l (𝓝 (center μ)) := by + refine tendsto_order.mpr ⟨?_, ?_⟩ + · intro a ha + have ht := ((continuous_score_law a).tendsto μ).comp h + have he := ht.eventually_const_lt ((score_pos_iff μ a).mpr ha) + filter_upwards [he] with i hi + exact (score_pos_iff (μs i) a).mp hi + · intro b hb + have ht := ((continuous_score_law b).tendsto μ).comp h + have he := ht.eventually_lt_const ((score_neg_iff μ b).mpr hb) + filter_upwards [he] with i hi + exact (score_neg_iff (μs i) b).mp hi + +/-- The no-moment arctangent center is continuous for the usual weak topology +on probability measures. -/ +theorem continuous_center : Continuous center := by + rw [continuous_iff_continuousAt] + intro μ + exact tendsto_center tendsto_id + +section RandomVariables + +variable {Ω : Type*} [MeasurableSpace Ω] + +/-- Rewriting the law-level score as an expectation on a probability space. +Only measurability, not integrability of the random variable, is needed. -/ +lemma score_map (P : ProbabilityMeasure Ω) (Y : Ω → ℝ) + (hY : AEMeasurable Y (P : Measure Ω)) (t : ℝ) : + score (P.map Y) t = ∫ ω, Real.arctan (Y ω - t) ∂(P : Measure Ω) := by + unfold score + rw [ProbabilityMeasure.toMeasure_map] + exact integral_map hY (Real.continuous_arctan.comp + (continuous_id.sub continuous_const)).aestronglyMeasurable + +/-- The existence/uniqueness assertion of `measure:center` for an arbitrary +finite real random variable. The defining expectation is with respect to +its unconditional probability law. -/ +theorem existsUnique_randomVariable_center (P : ProbabilityMeasure Ω) (Y : Ω → ℝ) + (hY : AEMeasurable Y (P : Measure Ω)) : + ∃! m : ℝ, (∫ ω, Real.arctan (Y ω - m) ∂(P : Measure Ω)) = 0 := by + simpa only [score_map P Y hY] using existsUnique_center (P.map Y) + +/-- Law equality implies equality of the centers; a change of probability +space causes no ambiguity. -/ +theorem center_eq_of_law_eq {Ω' : Type*} [MeasurableSpace Ω'] + (P : ProbabilityMeasure Ω) (Y : Ω → ℝ) (_hY : AEMeasurable Y (P : Measure Ω)) + (P' : ProbabilityMeasure Ω') (Y' : Ω' → ℝ) (_hY' : AEMeasurable Y' (P' : Measure Ω')) + (h : P.map Y = P'.map Y') : center (P.map Y) = center (P'.map Y') := + congrArg center h + +end RandomVariables + +/-! +The next lemmas establish only the scalar step in `measure:normalization`. +Here `ν` is a law of a logarithmic (truncated) diameter, and `τ` is the law +of the logarithm of the limiting diameter. No assertion that FK or tree +maps satisfy the needed distributional convergence is made. +-/ + +/-- The deterministic scale `exp(m(ν) - m(τ))` from the normalization lemma. -/ +def diameterScale (ν τ : ProbabilityMeasure ℝ) : ℝ := + Real.exp (center ν - center τ) + +lemma diameterScale_pos (ν τ : ProbabilityMeasure ℝ) : 0 < diameterScale ν τ := + Real.exp_pos _ + +/-- The proposed distance rescaling is positive even when no moments exist. -/ +lemma inv_diameterScale_pos (ν τ : ProbabilityMeasure ℝ) : 0 < (diameterScale ν τ)⁻¹ := + inv_pos.mpr (diameterScale_pos ν τ) + +/-- Along any already-established convergence of the centered log-diameter +laws, the deterministic scale ratio converges to the deterministic multiplier. +This is the scalar step in `measure:normalization`, not the subsequential +geometric/probabilistic input required by `thm:main`. -/ +theorem tendsto_diameterScale_ratio {ι : Type*} {l : Filter ι} + (ν : ι → ProbabilityMeasure ℝ) (τ : ProbabilityMeasure ℝ) + (s : ι → ℝ) (hs : ∀ i, 0 < s i) (c : ℝ) (hc : 0 < c) + (h : Tendsto (fun i => translate (ν i) (-Real.log (s i))) l + (𝓝 (translate τ (Real.log c)))) : + Tendsto (fun i => diameterScale (ν i) τ / s i) l (𝓝 c) := by + have hm := (tendsto_center h).sub_const (center τ) + simp only [center_translate] at hm + have hexp := Real.continuous_exp.continuousAt.tendsto.comp hm + have hterm (i : ι) : + Real.exp (center (ν i) + -Real.log (s i) - center τ) = diameterScale (ν i) τ / s i := by + rw [show center (ν i) + -Real.log (s i) - center τ = + (center (ν i) - center τ) - Real.log (s i) by ring] + rw [Real.exp_sub, Real.exp_log (hs i)] + rfl + simpa only [Function.comp_def, hterm, add_sub_cancel_left, Real.exp_log hc] using hexp + +/-- Reciprocal scales tend to zero along such a subsequence when its +reference scale tends to infinity. This conclusion concerns only real +numbers; no GHP convergence is assumed or asserted. -/ +theorem tendsto_inv_diameterScale_zero {ι : Type*} {l : Filter ι} + (ν : ι → ProbabilityMeasure ℝ) (τ : ProbabilityMeasure ℝ) + (s : ι → ℝ) (hs : ∀ i, 0 < s i) (c : ℝ) (hc : 0 < c) + (h : Tendsto (fun i => translate (ν i) (-Real.log (s i))) l + (𝓝 (translate τ (Real.log c)))) (hsInf : Tendsto s l atTop) : + Tendsto (fun i => (diameterScale (ν i) τ)⁻¹) l (𝓝 (0 : ℝ)) := by + have hr := (tendsto_diameterScale_ratio ν τ s hs c hc h).inv₀ hc.ne' + have hz := tendsto_inv_atTop_zero.comp hsInf + have hp := hr.mul hz + have heq (i : ι) : (diameterScale (ν i) τ / s i)⁻¹ * (s i)⁻¹ = + (diameterScale (ν i) τ)⁻¹ := by + rw [inv_div, div_eq_mul_inv] + field_simp [(hs i).ne', (diameterScale_pos (ν i) τ).ne'] + simpa only [Function.comp_def, heq, mul_zero] using hp + +end MetricMeasureLimits.DiameterCenter + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/AllRadii.lean b/lean/OAI/Probability/ProjectionMoments/AllRadii.lean new file mode 100644 index 0000000000000000000000000000000000000000..9f9768cfff137e9b0b223f53923c1b49a93522d3 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/AllRadii.lean @@ -0,0 +1,213 @@ +import OAI.Probability.ProjectionMoments.CapDomination + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma normalized_strong_moment {ν : Measure E} [IsFiniteMeasure ν] {a : ℝ} + (hν : NoiselessRegression.HasLocalMassBound ν a) + (hs : ν.support ⊆ Metric.closedBall 0 1) (hmass : ν Set.univ ≤ 1) + {k n : ℕ} (hk : 1 ≤ k) (hkd : k ≤ Module.finrank ℝ E) + (hdk : Module.finrank ℝ E ≤ 32*k) (ha : a ≤ Module.finrank ℝ E) + (hmargin : (n:ℝ)+k ≤ a) {u : Fin k → E} (hu : Orthonormal ℝ u) + (hac : ∀ᵐ A ∂frameLaw u, ν.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ))) : + (∫⁻ X, ∫⁻ y, normalizedDensity ν k u (X,y)^(n+1) ∂unitBallLaw k + ∂Measure.pi (fun _ => stdGaussian E)) ≤ + ENNReal.ofReal ((16384:ℝ)^(Module.finrank ℝ E*(n+1))) := by + apply (normalizedMoment_le ν hkd hu n).trans + apply (mul_le_mul' le_rfl (frame_moment_unit hν hs hmass (by omega) ha hkd hmargin u hu hac)).trans + simpa only [one_pow, ENNReal.ofReal_one, one_mul, max_self, mul_one] using + normalized_cost (Module.finrank ℝ E) k n hk hkd hdk 1 one_pos + +lemma rescaled_kernel_identity {μ : Measure E} [IsFiniteMeasure μ] {K a : ℝ} + (hK : 0 < K) (c : E) {r : ℝ} (hr : 0 < r) + (hs : μ.support ⊆ Metric.closedBall c r) {k : ℕ} (hk : k ≤ Module.finrank ℝ E) + {Q : (Fin k → E) × Label k → ℝ≥0∞} (hQ : Measurable Q) + {u : Fin k → E} (hu : Orthonormal ℝ u) + (hac : ∀ X, (normalizedRescale μ K a c r).map (rowMap (polarRows u X)) ≪ + (volume : Measure (Label k))) : + (∫⁻ s, capKernelValue Q s ∂μ) = + ENNReal.ofReal (K*r^a) * ∫⁻ X, ∫⁻ y, + normalizedDensity (normalizedRescale μ K a c r) k u (X,y) * + Q (X,capReferenceLabel c r X y) ∂unitBallLaw k ∂Measure.pi (fun _ => stdGaussian E) := by + let ν := normalizedRescale μ K a c r + let : IsFiniteMeasure ν := normalizedRescale_finite μ K a c r (by positivity) + have hsν : ν.support ⊆ Metric.closedBall 0 1 := normalizedRescale_support K a c hr hs + have he (X : Fin k → E) (hX : LinearIndependent ℝ X) : + (∫⁻ s, Q (X,rowMap X s) ∂μ) = + ENNReal.ofReal (K*r^a) * ∫⁻ y, normalizedDensity ν k u (X,y)* + Q (X,capReferenceLabel c r X y) ∂unitBallLaw k := by + have hid := lintegral_withDensity_eq_lintegral_mul (unitBallLaw k) + (show Measurable (fun y => normalizedDensity ν k u (X,y)) by fun_prop) + (show Measurable (fun y => Q (X,capReferenceLabel c r X y)) by fun_prop) + simp only [Pi.mul_apply] at hid + rw [← hid,normalizedDensity_unitBall ν hu hsν X (hac X),lintegral_map (by fun_prop) (by fun_prop)] + have hrec : ENNReal.ofReal (K*r^a) • ν.map (dilate c r) = μ := normalizedRescale_recover μ K a hK c hr + calc + _ = ∫⁻ s, Q (X,rowMap X s) ∂(ENNReal.ofReal (K*r^a) • ν.map (dilate c r)) := by rw [hrec] + _ = _ := by + rw [lintegral_smul_measure,lintegral_map (by fun_prop) (measurable_dilate c r)] + congr 1 + apply lintegral_congr + intro s + rw [capReferenceLabel, ← polar_label_identity hX u c s r] + change (∫⁻ s, ∫⁻ X, Q (X,rowMap X s) ∂Measure.pi (fun _ => stdGaussian E) ∂μ) = _ + rw [lintegral_lintegral_swap (show AEMeasurable (fun z : E × (Fin k → E) => Q (z.2,rowMap z.2 z.1)) _ by + apply Measurable.aemeasurable; exact hQ.comp (measurable_snd.prodMk (by simp only [rowMap_apply]; fun_prop)))] + rw [← lintegral_const_mul _ (by fun_prop)] + exact lintegral_congr_ae (by filter_upwards [gaussian_rows_ae_linearIndependent k hk] with X hX; exact he X hX) + +lemma localized_fractional_kernel_bound {μ : Measure E} [IsFiniteMeasure μ] {K a : ℝ} + (hlocal : AllBallMass μ K a) (hK : 0 ≤ K) + (c : E) {r : ℝ} (hr : 0 < r) (hs : μ.support ⊆ Metric.closedBall c r) + {k n : ℕ} (hk : 1 ≤ k) (hn : 1 ≤ n) (hkd : k ≤ Module.finrank ℝ E) + (hdk : Module.finrank ℝ E ≤ 32*k) (ha : a ≤ Module.finrank ℝ E) + (hmargin : (n:ℝ)+k ≤ a) + {Q : (Fin k → E) × Label k → ℝ≥0∞} (hQ : Measurable Q) (hQ1 : ∀ z, Q z ≤ 1) + {u : Fin k → E} (hu : Orthonormal ℝ u) + (hac : ∀ A, Orthonormal ℝ A → μ.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ))) : + (∫⁻ s, capKernelValue Q s ∂μ) ≤ + ENNReal.ofReal ((16384:ℝ)^Module.finrank ℝ E) * ENNReal.ofReal (K*r^a) * + (capReference Q c r)^(1-1/((n:ℝ)+1)) := by + rcases eq_or_lt_of_le hK with hK | hK + · have hz := measure_eq_zero_of_allBall_zero (hK ▸ hlocal) c hr hs + subst μ + simp + let ν := normalizedRescale μ K a c r + let : IsFiniteMeasure ν := normalizedRescale_finite μ K a c r (by positivity) + have hsν : ν.support ⊆ Metric.closedBall 0 1 := normalizedRescale_support K a c hr hs + have hmass : ν Set.univ ≤ 1 := normalizedRescale_mass hlocal hK c hr hs + have hacν (A : Fin k → E) (hA : Orthonormal ℝ A) : + ν.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ)) := by + change (normalizedRescale μ K a c r).map (coordinateMap A) ≪ _ + rw [normalizedRescale, Measure.map_smul _ (by fun_prop)] + exact Measure.smul_absolutelyContinuous.trans (rescaled_projection_ac A c hr (hac A hA)) + have hacX (X : Fin k → E) : ν.map (rowMap (polarRows u X)) ≪ (volume : Measure (Label k)) := + (rowMap_ac_iff _).mpr (hacν _ (polarRows_orthonormal hu X)) + have hm := normalized_strong_moment (normalizedRescale_local hlocal hK c hr) hsν hmass hk hkd hdk ha hmargin hu + (polar_ac_to_frame ν hkd hu (Filter.Eventually.of_forall hacX)) + let γ := Measure.pi (fun _ : Fin k => stdGaussian E) + let F : (Fin k → E) × Label k → ℝ≥0∞ := fun z => Q (z.1,capReferenceLabel c r z.1 z.2) + have hF : Measurable F := hQ.comp (measurable_fst.prodMk (measurable_capReferenceLabel c r)) + have hp : (1:ℝ) < (n:ℝ)+1 := by exact_mod_cast (show 1 < n+1 by omega) + have hnorm : (∫⁻ z, normalizedDensity ν k u z ^ ((n:ℝ)+1) ∂γ.prod (unitBallLaw k)) ≤ + ENNReal.ofReal ((16384:ℝ)^Module.finrank ℝ E)^(n+1) := by + rw [lintegral_prod _ (by fun_prop)] + simpa only [←Nat.cast_add_one,ENNReal.rpow_natCast,pow_mul,ENNReal.ofReal_pow (by positivity : (0:ℝ) ≤ 16384), + ENNReal.ofReal_pow (by positivity : 0 ≤ (16384:ℝ)^Module.finrank ℝ E)] using hm + have hb := holder_bounded_kernel (γ.prod (unitBallLaw k)) + (measurable_normalizedDensity ν k u) hF (fun z => hQ1 _) hp hnorm + have hroot : (ENNReal.ofReal ((16384:ℝ)^Module.finrank ℝ E)^(n+1))^(1/((n:ℝ)+1)) ≤ + ENNReal.ofReal ((16384:ℝ)^Module.finrank ℝ E) := by + simpa only [Nat.cast_add,Nat.cast_one] using ennreal_root_bound (q := n+1) (by omega) + (by positivity : 0 ≤ (16384:ℝ)^Module.finrank ℝ E) le_rfl + have hb' := hb.trans (mul_le_mul' hroot le_rfl) + rw [lintegral_prod _ (by fun_prop),lintegral_prod _ (by fun_prop)] at hb' + rw [rescaled_kernel_identity hK c hr hs hkd hQ hu hacX] + apply (mul_le_mul' le_rfl hb').trans_eq + dsimp only [F,γ,capReference] + ring + +lemma fractionalBlock_mass_identity {J : Type*} [Fintype J] {k : ℕ} + (Q : J → (Fin k → E) × Label k → ℝ≥0∞) (hQ : ∀ j, Measurable (Q j)) + (f : J → E → ℝ≥0∞) (hf : ∀ j, Measurable (f j)) + (μ : Measure E) [SFinite μ] {S : Set E} (hS : MeasurableSet S) : + (∫⁻ s in S, fractionalBlock Q f s ∂μ) = + ∑ j, ∫⁻ s, capKernelValue (Q j) s ∂(μ.withDensity (f j)).restrict S := by + have he (s : E) : fractionalBlock Q f s = ∑ j, f j s * capKernelValue (Q j) s := by + unfold fractionalBlock capKernelValue + rw [lintegral_finsetSum _ (fun j _ => by simp only [rowMap_apply]; fun_prop)] + apply Finset.sum_congr rfl + intro j hj + rw [lintegral_mul_const _ (by simp only [rowMap_apply]; fun_prop)] + exact mul_comm _ _ + simp_rw [he] + rw [lintegral_finsetSum _ (fun j _ => show Measurable (fun s => f j s * capKernelValue (Q j) s) from + (hf j).mul (measurable_capKernelValue (hQ j)))] + apply Finset.sum_congr rfl + intro j hj + rw [restrict_withDensity hS] + exact (lintegral_withDensity_eq_lintegral_mul _ (hf j) (measurable_capKernelValue (hQ j))).symm + +theorem one_block_all_radii : + ∃ C : ℝ, 1 ≤ C ∧ ∀ d : ℕ, 16 ≤ d → + let k := d/4 + let β : ℝ := (d:ℝ)-1-k + ∀ N : ℕ, ∀ f : Fin N → EuclideanSpace ℝ (Fin d) → ℝ≥0∞, + (∀ j, Measurable (f j)) → (∀ j s, f j s ≤ 1) → + ∀ K : ℝ, 0 ≤ K → + (∀ j, AllBallMass (NoiselessRegression.ambientSphereLaw.withDensity (f j)) K β) → + ∀ Q : Fin N → (Fin k → EuclideanSpace ℝ (Fin d)) × Label k → ℝ≥0∞, + (∀ j, Measurable (Q j)) → (∀ z, ∑ j, Q j z ≤ 1) → + AllBallMass (NoiselessRegression.ambientSphereLaw.withDensity (fractionalBlock Q f)) + (C^d*(N:ℝ)^(1/(k:ℝ))*K) β := by + refine ⟨16384,by norm_num,?_⟩ + intro d hd k β N f hf hf1 K hK hlocal Q hQ hQsum z R hR + let : NeZero d := ⟨by omega⟩ + have hk : 4 ≤ k := by dsimp [k]; omega + have hkd : k ≤ d := by dsimp [k]; omega + have hdk : d ≤ 32*k := by dsimp [k]; omega + have hk2 : k+2 ≤ d := by dsimp [k]; omega + have hkn : k-1+1=k := by omega + have hknR : ((k-1:ℕ):ℝ)+1=k := by exact_mod_cast hkn + have hβ : β ≤ d := by dsimp [β]; linarith [Nat.cast_nonneg (α := ℝ) k] + have hmargin : ((k-1:ℕ):ℝ)+k ≤ β := by + have hn : 3*k ≤ d := by dsimp [k]; omega + have hnR : 3*(k:ℝ) ≤ d := by exact_mod_cast hn + dsimp [β]; linarith + let u : Fin k → EuclideanSpace ℝ (Fin d) := (EuclideanSpace.basisFun (Fin d) ℝ) ∘ Fin.castLE hkd + have hu : Orthonormal ℝ u := (EuclideanSpace.basisFun (Fin d) ℝ).orthonormal.comp _ (Fin.castLE_injective hkd) + let μ (j : Fin N) := sphereWeightedRestriction (f j) (Metric.closedBall z R) + let (j : Fin N) : IsFiniteMeasure (μ j) := sphereWeightedRestriction_finite (hf1 j) _ + have hs (j : Fin N) : (μ j).support ⊆ Metric.closedBall z R := sphereWeightedRestriction_support Subset.rfl + have hl (j : Fin N) : AllBallMass (μ j) K β := fun c r hr => + (Measure.restrict_le_self _).trans (hlocal j c r hr) + have hac (j : Fin N) (A : Fin k → EuclideanSpace ℝ (Fin d)) (hA : Orthonormal ℝ A) : + (μ j).map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ)) := + ((Measure.absolutelyContinuous_of_le (sphereWeightedRestriction_le (hf1 j) _)).map + (by fun_prop)).trans (sphere_frame_ac (by simpa using hk2) hA) + have hQ1 (j : Fin N) (x) : Q j x ≤ 1 := + (Finset.single_le_sum (fun i _ => bot_le) (Finset.mem_univ j)).trans (hQsum x) + have hb' (j : Fin N) : (∫⁻ s, capKernelValue (Q j) s ∂μ j) ≤ + ENNReal.ofReal ((16384:ℝ)^d)*ENNReal.ofReal (K*R^β)*(capReference (Q j) z R)^(1-1/(k:ℝ)) := by + have hh := localized_fractional_kernel_bound (hl j) hK z hR (hs j) (n := k-1) + (by omega) (by omega) (by simpa using hkd) (by simpa using hdk) (by simpa using hβ) + hmargin (hQ j) (hQ1 j) hu (hac j) + simpa only [finrank_euclideanSpace_fin,hknR] using hh + have hp : (1:ℝ) < k := by exact_mod_cast (show 1 < k by omega) + have hθ : 0 ≤ 1-1/(k:ℝ) := by + have hh : 1/(k:ℝ) ≤ 1 := (div_le_one (by linarith)).mpr hp.le + linarith + rw [withDensity_apply _ Metric.isClosed_closedBall.measurableSet, + fractionalBlock_mass_identity Q hQ f hf _ Metric.isClosed_closedBall.measurableSet] + calc + _ ≤ ∑ j, ENNReal.ofReal ((16384:ℝ)^d)*ENNReal.ofReal (K*R^β)*(capReference (Q j) z R)^(1-1/(k:ℝ)) := + Finset.sum_le_sum (fun j _ => hb' j) + _ = ENNReal.ofReal ((16384:ℝ)^d)*ENNReal.ofReal (K*R^β)* + ∑ j, (capReference (Q j) z R)^(1-1/(k:ℝ)) := (Finset.mul_sum _ _ _).symm + _ ≤ ENNReal.ofReal ((16384:ℝ)^d)*ENNReal.ofReal (K*R^β)* + ((N:ℝ≥0∞)^(1/(k:ℝ))) := by + apply mul_le_mul' le_rfl + apply (NoiselessRegression.finite_rpow_holder (fun j => capReference (Q j) z R) hp).trans + have hsum := capReference_sum_le_one Q hQ hQsum z R + simpa only [Fintype.card_fin,ENNReal.one_rpow,mul_one] using + mul_le_mul' (le_rfl : (N:ℝ≥0∞)^(1/(k:ℝ)) ≤ _) (ENNReal.rpow_le_rpow hsum hθ) + _ = _ := by + rw [ENNReal.ofReal_mul (by positivity : 0 ≤ (16384:ℝ)^d*(N:ℝ)^(1/(k:ℝ))*K), + ENNReal.ofReal_mul (by positivity : 0 ≤ (16384:ℝ)^d*(N:ℝ)^(1/(k:ℝ))), + ENNReal.ofReal_mul (by positivity : 0 ≤ (16384:ℝ)^d),ENNReal.ofReal_mul hK, + ← ENNReal.ofReal_rpow_of_nonneg (by positivity : (0:ℝ) ≤ N) (by positivity : (0:ℝ) ≤ 1/k), + ENNReal.ofReal_natCast] + ring + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Asymptotics.lean b/lean/OAI/Probability/ProjectionMoments/Asymptotics.lean new file mode 100644 index 0000000000000000000000000000000000000000..feadc6d77cfce7450a0092fb41f9d8052f2d390a --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Asymptotics.lean @@ -0,0 +1,282 @@ +import OAI.Probability.ProjectionMoments.Seeded + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression +namespace Learner +variable {d M T : ℕ} {Ω : Type*} [MeasurableSpace Ω] + +lemma uniformSuccess_le_sum_fixed (L : Learner d M T Ω) (ρ : Measure Ω) (ε : ℝ) : + L.uniformSuccess ρ ε ≤ ∑ t : Fin (T+1), L.uniformFixedSuccess ρ ε t := by + classical + let μ := (uniformSphere d).prod (ρ.prod (sampleLaw d T)) + have hs : {z : UnitSphere d × (Ω × Samples d T) | + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} = + ⋃ t : Fin (T+1), {z | (L.terminal z.1 z.2.1 z.2.2).1 = t ∧ + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} := by + ext z + simp only [Set.mem_ofPred_eq,Set.mem_iUnion] + constructor + · intro hz + obtain ⟨t,ht,he⟩ := L.terminal_forced_witness z.1 z.2.1 z.2.2 + exact ⟨⟨t,by omega⟩,by simpa [he] using hz⟩ + · rintro ⟨t,ht,hz⟩ + exact hz + change μ _ ≤ ∑ t : Fin (T+1), μ _ + rw [hs] + exact (measure_iUnion_le _).trans_eq (tsum_fintype _) + +end Learner +namespace FiniteKernelLearner + +section +universe u + +theorem cap_total_success : + ∃ C : ℝ, 0 < C ∧ ∀ d M T : ℕ, 32 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + seededSuccess K ρ ε ≤ ENNReal.ofReal + (((T:ℝ)+1)*Real.exp (C*d)*(ε/2)^α* + (Real.exp (C*d)*(2:ℝ)^((M:ℝ)/k))^((T+k-1)/k)) := by + obtain ⟨C,hC,h⟩ := Learner.cap_fixed_stop.{0} + refine ⟨C,hC,?_⟩ + intro d M T hd ε hε hε10 Ξ _ ρ hρ K hK k α + let : IsProbabilityMeasure ρ := hρ + apply seed_average_bound + filter_upwards [hK] with ξ hξ + obtain ⟨ν,L,hν,hB,hL,he,_⟩ := (K ξ).exists_equivalent_tape hξ (by omega) + rw [←he ε] + have hs := L.uniformSuccess_le_sum_fixed ν ε + have hbase : 1 ≤ Real.exp (C*d)*(2:ℝ)^((M:ℝ)/k) := + one_le_mul_of_one_le_of_one_le (Real.one_le_exp (by positivity)) + (Real.one_le_rpow (by norm_num) (by positivity)) + apply hs.trans + calc + _ ≤ ∑ _t : Fin (T+1), ENNReal.ofReal + (Real.exp (C*d)*(ε/2)^α*(Real.exp (C*d)*(2:ℝ)^((M:ℝ)/k))^((T+k-1)/k)) := by + apply Finset.sum_le_sum + intro t _ + apply (h d M T hd ε hε hε10 (Tape M T) ν hν L hL + (L.measurable_terminal hB).fst.aemeasurable t (by omega)).trans + apply ENNReal.ofReal_le_ofReal + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact pow_le_pow_right₀ hbase (Nat.div_le_div_right (by omega)) + _ = _ := by + simp only [Finset.sum_const,Finset.card_univ,Fintype.card_fin] + rw [nsmul_eq_mul, ←ENNReal.ofReal_natCast, + ←ENNReal.ofReal_mul (by positivity : 0 ≤ ((T+1:ℕ):ℝ))] + congr 1 + push_cast + ring + +end + +section + +universe u +variable {d M T : ℕ} {Ξ : Type u} [MeasurableSpace Ξ] + +lemma seededSuccess_eq_integral_pointwise [NeZero d] + (K : Ξ → FiniteKernelLearner d M T) (ρ : Measure Ξ) [SFinite ρ] (ε : ℝ) + (hm : JointSuccessMeasurable K ρ ε) : + seededSuccess K ρ ε = ∫⁻ s, seededPointwiseSuccess K ρ ε s ∂uniformSphere d := by + let f := fun z : UnitSphere d × (Ξ × Samples d T) => + (K z.2.1).conditionalSuccess ε z.1 z.2.2 + let e : ((UnitSphere d × Samples d T) × Ξ) ≃ᵐ UnitSphere d × (Ξ × Samples d T) := + MeasurableEquiv.prodAssoc.trans (MeasurableEquiv.prodCongr (MeasurableEquiv.refl _) + (MeasurableEquiv.prodComm)) + have hp : MeasurePreserving e (((uniformSphere d).prod (sampleLaw d T)).prod ρ) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := + ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := ρ))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) ρ) + have hf : AEMeasurable f ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := hm + have hfD : AEMeasurable (fun z : (UnitSphere d × Samples d T) × Ξ => f (e z)) + (((uniformSphere d).prod (sampleLaw d T)).prod ρ) := + hf.comp_quasiMeasurePreserving hp.quasiMeasurePreserving + calc + _ = ∫⁻ ξ, ∫⁻ z : UnitSphere d × Samples d T, f (z.1,(ξ,z.2)) + ∂((uniformSphere d).prod (sampleLaw d T)) ∂ρ := rfl + _ = ∫⁻ z : UnitSphere d × Samples d T, ∫⁻ ξ, f (z.1,(ξ,z.2)) ∂ρ + ∂((uniformSphere d).prod (sampleLaw d T)) := (lintegral_lintegral_swap hfD).symm + _ = ∫⁻ z, f (e z) ∂(((uniformSphere d).prod (sampleLaw d T)).prod ρ) := + (lintegral_prod _ hfD).symm + _ = ∫⁻ z, f z ∂((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := + hp.lintegral_comp_emb e.measurableEmbedding f + _ = _ := lintegral_prod _ hf + +lemma seededSuccess_of_pointwise [NeZero d] + (K : Ξ → FiniteKernelLearner d M T) (ρ : Measure Ξ) [SFinite ρ] (ε : ℝ) + (hm : JointSuccessMeasurable K ρ ε) + (hs : ∀ s, (2/3 : ℝ≥0∞) ≤ seededPointwiseSuccess K ρ ε s) : + (2/3 : ℝ≥0∞) ≤ seededSuccess K ρ ε := by + rw [seededSuccess_eq_integral_pointwise K ρ ε hm] + calc + _ = ∫⁻ _ : UnitSphere d, (2/3 : ℝ≥0∞) ∂uniformSphere d := by simp + _ ≤ _ := lintegral_mono hs + +theorem subquadratic_memory_with_pointwise : SubquadraticMemoryWithPointwise.{u} := by + obtain ⟨c,hc,h⟩ := subquadratic_memory.{u} + refine ⟨c,hc,?_⟩ + intro M hM + obtain ⟨d₀,hd₀⟩ := h M hM + refine ⟨max d₀ 1,?_⟩ + intro d hd T ε hε hε10 Ξ _ ρ hρ K hK hs + let : IsProbabilityMeasure ρ := hρ + let : NeZero d := ⟨by omega⟩ + apply hd₀ d (by omega) T ε hε hε10 Ξ ρ hρ K hK + rcases hs with hs | ⟨hm,hs⟩ + · exact hs + · exact seededSuccess_of_pointwise K ρ ε hm hs + +end + +universe u + +lemma cap_memory_factor (C : ℝ) {d M : ℕ} (hd : 32 ≤ d) + (hM : (M:ℝ) ≤ (d:ℝ)^2) : + Real.exp (C*d)*(2:ℝ)^((M:ℝ)/(d/16:ℕ)) ≤ Real.exp ((C+32)*d) := by + have hk : 0 < (d/16:ℕ) := by omega + have hkR : (0:ℝ) < (d/16:ℕ) := by exact_mod_cast hk + have hdk : d ≤ 32*(d/16) := by omega + have hdkR : (d:ℝ) ≤ 32*(d/16:ℕ) := by exact_mod_cast hdk + have hfrac : (M:ℝ)/(d/16:ℕ) ≤ 32*d := by + rw [div_le_iff₀ hkR] + nlinarith [Nat.cast_nonneg (α := ℝ) d] + have hlog : Real.log 2 ≤ 1 := by + have h := Real.log_le_sub_one_of_pos (by norm_num : (0:ℝ)<2) + norm_num at h ⊢ + exact h + rw [Real.rpow_def_of_pos (by norm_num),← Real.exp_add] + apply Real.exp_le_exp.mpr + have hnon : (0:ℝ) ≤ (M:ℝ)/(d/16:ℕ) := by positivity + have hl := mul_le_mul_of_nonneg_right hlog hnon + nlinarith + +lemma cap_finite_to_asymptotic (C : ℝ) {d M : ℕ} (hd : 32 ≤ d) + (hM : (M:ℝ) ≤ (d:ℝ)^2) (ε α : ℝ) (n : ℕ) (hε : 0 ≤ ε) : + Real.exp (C*d)*(ε/2)^α*(Real.exp (C*d)*(2:ℝ)^((M:ℝ)/(d/16:ℕ)))^n ≤ + Real.exp ((C+32)*d*(1+n))*(ε/2)^α := by + have hbase := cap_memory_factor C hd hM + have hfront : Real.exp (C*d) ≤ Real.exp ((C+32)*d) := by + apply Real.exp_le_exp.mpr + nlinarith [Nat.cast_nonneg (α := ℝ) d] + have ht := mul_le_mul (mul_le_mul_of_nonneg_right hfront (Real.rpow_nonneg (by positivity : 0 ≤ ε/2) α)) + (pow_le_pow_left₀ (by positivity) hbase n) (by positivity) (by positivity) + apply ht.trans_eq + rw [← Real.exp_nat_mul] + calc + Real.exp ((C+32)*d)*(ε/2)^α*Real.exp ((n:ℝ)*((C+32)*d)) = + (Real.exp ((C+32)*d)*Real.exp ((n:ℝ)*((C+32)*d)))*(ε/2)^α := by ring + _ = _ := by rw [← Real.exp_add]; congr 2; ring + +theorem cap_fixed_stop_asymptotic : + ∃ C : ℝ, 0 < C ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d:ℝ)) (fun d => (d:ℝ)^2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d (M d) T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + ∀ t : ℕ, t ≤ T → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + seededFixedSuccess K ρ ε t ≤ ENNReal.ofReal + (Real.exp (C*d*(1+((t+k-1)/k:ℕ)))*(ε/2)^α) := by + obtain ⟨C,hC,h⟩ := cap_fixed_stop.{u} + refine ⟨C+32,by linarith,?_⟩ + intro M hM + obtain ⟨d₀,hd₀⟩ := eventually_atTop.1 hM.eventuallyLE + refine ⟨max d₀ 32,?_⟩ + intro d hd T ε hε hε10 Ξ _ ρ hρ K hK t ht k α + have hm : (M d:ℝ) ≤ (d:ℝ)^2 := by + simpa only [Real.norm_eq_abs,abs_of_nonneg (Nat.cast_nonneg (α := ℝ) (M d)), + abs_of_nonneg (sq_nonneg (d:ℝ))] using hd₀ d (by omega) + exact (h d (M d) T (by omega) ε hε hε10 Ξ ρ hρ K hK t ht).trans + (ENNReal.ofReal_le_ofReal (cap_finite_to_asymptotic C (by omega) hm ε α _ hε.le)) + +lemma cap_ceil_cost {d T : ℕ} (hd : 32 ≤ d) : + (d:ℝ)*(1+((T+d/16-1)/(d/16):ℕ)) ≤ 2*d+32*T := by + let k := d/16 + let n := (T+k-1)/k + have hk : 0 < k := by dsimp [k]; omega + have hkR : (0:ℝ) < k := by exact_mod_cast hk + have hdiv : n*k ≤ T+k := (Nat.div_mul_le_self _ _).trans (by omega) + have hdivR : (n:ℝ)*k ≤ (T:ℝ)+k := by exact_mod_cast hdiv + have hdR : (d:ℝ) ≤ 32*k := by exact_mod_cast (show d ≤ 32*k by dsimp [k]; omega) + have hn : (n:ℝ) ≤ (T:ℝ)/k+1 := by + have he := div_mul_cancel₀ (T:ℝ) hkR.ne' + nlinarith + have hh := mul_le_mul_of_nonneg_left hn (Nat.cast_nonneg (α := ℝ) d) + have hdk : (d:ℝ)/(k:ℝ) ≤ 32 := (div_le_iff₀ hkR).mpr hdR + have hT := mul_le_mul_of_nonneg_right hdk (Nat.cast_nonneg (α := ℝ) T) + change (d:ℝ)*(1+(n:ℝ)) ≤ _ + calc + _ ≤ (d:ℝ)*((T:ℝ)/k+2) := by nlinarith + _ = (d:ℝ)/k*T+2*d := by ring + _ ≤ _ := by linarith + +lemma cap_accuracy_cost {d : ℕ} (hd : 3 ≤ d) {ε : ℝ} + (hε : 0 < ε) (hε1 : ε ≤ 1) : + (ε/2)^(((d:ℝ)-1)/2) ≤ Real.exp (-(d:ℝ)*Real.log (1/ε)/3) := by + have hdR : (3:ℝ) ≤ d := by exact_mod_cast hd + have ha : 0 ≤ ((d:ℝ)-1)/2 := by linarith + calc + _ ≤ ε^(((d:ℝ)-1)/2) := Real.rpow_le_rpow (by positivity) (by linarith) ha + _ ≤ ε^((d:ℝ)/3) := Real.rpow_le_rpow_of_exponent_ge hε hε1 (by linarith) + _ = _ := by + rw [Real.rpow_def_of_pos hε,one_div,Real.log_inv] + congr 1 + ring + +theorem cap_total_success_asymptotic : + ∃ C₁ C₂ : ℝ, 0 < C₁ ∧ 0 < C₂ ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d:ℝ)) (fun d => (d:ℝ)^2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d (M d) T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + seededSuccess K ρ ε ≤ ENNReal.ofReal + (((T:ℝ)+1)*Real.exp (C₁*d+C₂*T-(d:ℝ)*Real.log (1/ε)/3)) := by + obtain ⟨C,hC,h⟩ := cap_total_success.{u} + refine ⟨2*(C+32),32*(C+32),by positivity,by positivity,?_⟩ + intro M hM + obtain ⟨d₀,hd₀⟩ := eventually_atTop.1 hM.eventuallyLE + refine ⟨max d₀ 32,?_⟩ + intro d hd T ε hε hε10 Ξ _ ρ hρ K hK + have hm : (M d:ℝ) ≤ (d:ℝ)^2 := by + simpa only [Real.norm_eq_abs,abs_of_nonneg (Nat.cast_nonneg (α := ℝ) (M d)), + abs_of_nonneg (sq_nonneg (d:ℝ))] using hd₀ d (by omega) + apply (h d (M d) T (by omega) ε hε hε10 Ξ ρ hρ K hK).trans + apply ENNReal.ofReal_le_ofReal + simp only [mul_assoc] + apply mul_le_mul_of_nonneg_left _ (by positivity : (0:ℝ) ≤ (T:ℝ)+1) + have hfinite := cap_finite_to_asymptotic C (by omega) hm ε (((d:ℝ)-1)/2) + ((T+d/16-1)/(d/16)) hε.le + simp only [mul_assoc] at hfinite + apply hfinite.trans + have hcost := mul_le_mul_of_nonneg_left (cap_ceil_cost (T := T) (by omega : 32 ≤ d)) + (by positivity : (0:ℝ) ≤ C+32) + have he : Real.exp ((C+32)*d*(1+((T+d/16-1)/(d/16):ℕ))) ≤ + Real.exp (2*(C+32)*d+32*(C+32)*T) := by + apply Real.exp_le_exp.mpr + nlinarith + simp only [mul_assoc] at he + apply (mul_le_mul he (cap_accuracy_cost (d := d) (by omega) hε (by linarith)) (by positivity) (by positivity)).trans_eq + rw [← Real.exp_add] + congr 1 + ring + +end FiniteKernelLearner +end NoiselessRegression + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/BallMoments.lean b/lean/OAI/Probability/ProjectionMoments/BallMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..c0f405d59d638b7f6f3fe9058f11f8ea86e5c48a --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/BallMoments.lean @@ -0,0 +1,346 @@ +import OAI.Probability.ProjectionMoments.Polar + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments + +section +attribute [fun_prop] measurable_polarRows +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma rowMap_ac_iff {ν : Measure E} {k : ℕ} (A : Fin k → E) : + ν.map (rowMap A) ≪ (volume : Measure (Label k)) ↔ + ν.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ)) := by + constructor + · intro h + have hh := h.map (MeasurableEquiv.toLp 2 (Fin k → ℝ)).symm.measurable + rw [(EuclideanSpace.volume_preserving_symm_measurableEquiv_toLp (Fin k)).map_eq, + Measure.map_map (by fun_prop) (by fun_prop)] at hh + exact hh + · intro h + rw [rowMap_eq_toLp_coordinateMap, ← Measure.map_map (by fun_prop) (by fun_prop), + ← (PiLp.volume_preserving_toLp (Fin k)).map_eq] + exact h.map (by fun_prop) + +lemma measurableSet_projection_ac (ν : Measure E) [IsFiniteMeasure ν] (k : ℕ) : + MeasurableSet {A : Fin k → E | ν.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ))} := by + have h := Kernel.measurableSet_absolutelyContinuous (projectionKernel ν k) + (Kernel.const (Fin k → E) (volume : Measure (Fin k → ℝ)).toFinite) + convert h using 1 + ext A + exact ⟨fun h => h.trans (absolutelyContinuous_toFinite volume), + fun h => h.trans (toFinite_absolutelyContinuous volume)⟩ + +lemma polar_ac_to_frame (ν : Measure E) [IsFiniteMeasure ν] {k : ℕ} + (hk : k ≤ Module.finrank ℝ E) {u : Fin k → E} (hu : Orthonormal ℝ u) + (h : ∀ᵐ X ∂Measure.pi (fun _ : Fin k => stdGaussian E), + ν.map (rowMap (polarRows u X)) ≪ (volume : Measure (Label k))) : + ∀ᵐ A ∂frameLaw u, ν.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ)) := by + rw [← polarRows_law hk hu] + apply (ae_map_iff (measurable_polarRows u).aemeasurable (measurableSet_projection_ac ν k)).mpr + filter_upwards [h] with X hX + exact (rowMap_ac_iff _).mp hX + +lemma unitBallVolume_ne_zero (k : ℕ) : unitBallVolume k ≠ 0 := by + apply ne_of_gt + exact (Metric.measure_ball_pos volume 0 one_pos).trans_le (measure_mono Metric.ball_subset_closedBall) +lemma unitBallVolume_ne_top (k : ℕ) : unitBallVolume k ≠ ∞ := + (isCompact_closedBall (0 : Label k) (1:ℝ)).measure_ne_top +instance unitBallLaw_probability (k : ℕ) : IsProbabilityMeasure (unitBallLaw k) := by + constructor + simp only [unitBallLaw, Measure.smul_apply, Measure.restrict_apply_univ, + smul_eq_mul] + exact ENNReal.inv_mul_cancel (unitBallVolume_ne_zero k) (unitBallVolume_ne_top k) + +lemma unitBallVolume_bound (k : ℕ) (hk : 1 ≤ k) : + unitBallVolume k ≤ ENNReal.ofReal ((6/Real.sqrt k)^k) := by + rw [unitBallVolume, Measure.addHaar_unitClosedBall_eq_addHaar_unitBall] + exact unit_ball_volume_bound k hk + +@[fun_prop] lemma measurable_normalizedDensity (ν : Measure E) [SFinite ν] (k : ℕ) (u : Fin k → E) : + Measurable (normalizedDensity ν k u) := by + exact measurable_const.mul ((measurable_lowerDensity ν k).comp + (((measurable_polarRows u).comp measurable_fst).prodMk measurable_snd)) + +lemma normalizedDensity_support (ν : Measure E) [IsFiniteMeasure ν] {k : ℕ} + {u : Fin k → E} (hu : Orthonormal ℝ u) (hs : ν.support ⊆ Metric.closedBall 0 1) + (X : Fin k → E) (y : Label k) (hy : 1 < ‖y‖) : normalizedDensity ν k u (X,y) = 0 := by + have h := lowerDensity_eq_zero_of_far ν k (polarRows u X) 0 1 y hs + (by simpa only [map_zero, sub_zero, mul_one] using (norm_rowMap_le (polarRows_orthonormal hu X)).trans_lt hy) + simp only [normalizedDensity, h, mul_zero] + +lemma normalizedDensity_is_density (ν : Measure E) [IsFiniteMeasure ν] {k : ℕ} + {u : Fin k → E} (X : Fin k → E) + (h : ν.map (rowMap (polarRows u X)) ≪ (volume : Measure (Label k))) : + ((unitBallVolume k)⁻¹ • (volume : Measure (Label k))).withDensity + (fun y => normalizedDensity ν k u (X,y)) = ν.map (rowMap (polarRows u X)) := by + rw [withDensity_smul_measure] + change (unitBallVolume k)⁻¹ • volume.withDensity + (unitBallVolume k • (fun y => lowerDensity ν k (polarRows u X,y))) = _ + rw [withDensity_smul _ (by fun_prop), smul_smul, + ENNReal.inv_mul_cancel (unitBallVolume_ne_zero k) (unitBallVolume_ne_top k), one_smul] + exact lowerDensity_is_density ν k _ h + +lemma normalizedMoment_le (ν : Measure E) [IsFiniteMeasure ν] {k : ℕ} + (hk : k ≤ Module.finrank ℝ E) {u : Fin k → E} (hu : Orthonormal ℝ u) (n : ℕ) : + (∫⁻ X, ∫⁻ y, normalizedDensity ν k u (X,y)^(n+1) ∂unitBallLaw k + ∂Measure.pi (fun _ => stdGaussian E)) ≤ + unitBallVolume k ^ n * ∫⁻ A, labelMoment ν k n A ∂frameLaw u := by + have hpoint (X : Fin k → E) : + (∫⁻ y, normalizedDensity ν k u (X,y)^(n+1) ∂unitBallLaw k) ≤ + unitBallVolume k ^ n * labelMoment ν k n (polarRows u X) := by + simp only [unitBallLaw, normalizedDensity, mul_pow, lintegral_smul_measure, smul_eq_mul] + rw [lintegral_const_mul _ (by fun_prop), ← mul_assoc, + pow_succ', ← mul_assoc, ENNReal.inv_mul_cancel (unitBallVolume_ne_zero k) (unitBallVolume_ne_top k), one_mul] + apply mul_le_mul' le_rfl + have he : labelMoment ν k n (polarRows u X) = + ∫⁻ y : Label k, lowerDensity ν k (polarRows u X,y)^(n+1) := + (PiLp.volume_preserving_toLp (Fin k)).lintegral_comp + (show Measurable (fun y : Label k => lowerDensity ν k (polarRows u X,y)^(n+1)) by fun_prop) + rw [he] + exact setLIntegral_le_lintegral _ _ + apply (lintegral_mono hpoint).trans + rw [lintegral_const_mul _ (by fun_prop), lintegral_polarRows_eq_frame hk hu _ (by fun_prop)] + +end + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma sphereWeightedRestriction_le [Nontrivial E] {h : E → ℝ≥0∞} + (h1 : ∀ s, h s ≤ 1) (H : Set E) : + sphereWeightedRestriction h H ≤ NoiselessRegression.ambientSphereLaw := by + apply Measure.restrict_le_self.trans + calc + _ ≤ NoiselessRegression.ambientSphereLaw.withDensity (1 : E → ℝ≥0∞) := + withDensity_mono (Filter.Eventually.of_forall h1) + _ = _ := withDensity_one + +lemma sphereWeightedRestriction_finite [Nontrivial E] {h : E → ℝ≥0∞} + (h1 : ∀ s, h s ≤ 1) (H : Set E) : IsFiniteMeasure (sphereWeightedRestriction h H) := + ⟨(Measure.le_iff.mp (sphereWeightedRestriction_le h1 H) Set.univ MeasurableSet.univ).trans_lt (by simp)⟩ + +lemma sphereWeightedRestriction_support {h : E → ℝ≥0∞} {H : Set E} + {z : E} {ρ : ℝ} (hH : H ⊆ Metric.closedBall z ρ) : + (sphereWeightedRestriction h H).support ⊆ Metric.closedBall z ρ := + Measure.support_restrict_subset.trans (fun _ hx => + (closure_minimal hH Metric.isClosed_closedBall) hx.1) + +theorem riesz_deterministic_offsets : + ∃ C : ℝ, 1 ≤ C ∧ ∀ d : ℕ, 16 ≤ d → + let k := d/8 + let α : ℝ := (d:ℝ)/2 + ∀ h : EuclideanSpace ℝ (Fin d) → ℝ≥0∞, Measurable h → (∀ s, h s ≤ 1) → + ∀ z : EuclideanSpace ℝ (Fin d), ∀ ρ : ℝ, 0 < ρ → + ∀ H : Set (EuclideanSpace ℝ (Fin d)), MeasurableSet H → H ⊆ Metric.closedBall z ρ → + rieszPotential α h < ∞ ∧ + Measurable (lowerDensity (sphereWeightedRestriction h H) k) ∧ + (∀ A : Fin k → EuclideanSpace ℝ (Fin d), LinearIndependent ℝ A → + volume.withDensity (fun y => lowerDensity (sphereWeightedRestriction h H) k (A,y)) = + (sphereWeightedRestriction h H).map (rowMap A)) ∧ + (∀ b : Label k, (∫⁻ A, (lowerDensity (sphereWeightedRestriction h H) k (A,rowMap A z+b))^k + ∂Measure.pi (fun _ => stdGaussian (EuclideanSpace ℝ (Fin d))))^(1/(k:ℝ)) ≤ + ENNReal.ofReal (C^d) * rieszPotential α h * ENNReal.ofReal (ρ^(α-k))) ∧ + (∀ A y, ‖rowMap A‖*ρ < ‖y-rowMap A z‖ → + lowerDensity (sphereWeightedRestriction h H) k (A,y) = 0) := by + refine ⟨128,by norm_num,?_⟩ + intro d hd k α h hh h1 z ρ hρ H hH hHz + let : NeZero d := ⟨by omega⟩ + have hα : 0 ≤ α := by dsimp [α]; positivity + have hk : 2 ≤ k := by dsimp [k]; omega + have hkd : k+2 ≤ d := by dsimp [k]; omega + have hαd : α ≤ d := by dsimp [α]; linarith [Nat.cast_nonneg (α := ℝ) d] + have hmargin : (k:ℝ)+k ≤ α := by + have hn : 4*k ≤ d := by dsimp [k]; omega + have hn' : 4*(k:ℝ) ≤ d := by exact_mod_cast hn + dsimp [α]; linarith + have hfinite : rieszPotential α h < ∞ := by + apply rieszPotential_finite hα (m := d/2+1) _ _ h1 + · have hn : d ≤ 2*(d/2+1) := by omega + have hn' : (d:ℝ) ≤ 2*((d/2+1:ℕ):ℝ) := by exact_mod_cast hn + dsimp [α]; linarith + · simp only [finrank_euclideanSpace_fin]; omega + let μ := sphereWeightedRestriction h H + let : IsFiniteMeasure μ := sphereWeightedRestriction_finite h1 H + have hs : μ.support ⊆ Metric.closedBall z ρ := sphereWeightedRestriction_support hHz + have hball : AllBallMass μ (rieszPotential α h).toReal α := by + intro c r hr + apply (Measure.restrict_le_self _).trans + apply (rieszPotential_ball_control hα hh c hr).trans_eq + rw [ENNReal.ofReal_mul ENNReal.toReal_nonneg, ENNReal.ofReal_toReal hfinite.ne] + refine ⟨hfinite,measurable_lowerDensity μ k,?_,?_,?_⟩ + · intro A hA + apply lowerDensity_is_density + apply (rowMap_ac_iff _).mpr + exact ((Measure.absolutelyContinuous_of_le (sphereWeightedRestriction_le h1 H)).map + (show Measurable (coordinateMap A) by fun_prop)).trans (sphere_fullRank_ac (by simpa using hkd) hA) + · intro b + have hb := gaussian_fixed_offset hball ENNReal.toReal_nonneg z hρ hs k k (by omega) + hmargin (by simpa using hαd) b + simpa only [finrank_euclideanSpace_fin,ENNReal.ofReal_mul (by positivity : 0 ≤ (128:ℝ)^d), + ENNReal.ofReal_mul (by positivity : 0 ≤ (128:ℝ)^d*(rieszPotential α h).toReal), + ENNReal.ofReal_toReal hfinite.ne] using hb + · intro A y hy + exact lowerDensity_eq_zero_of_far μ k A z ρ y hs hy + +end + +theorem all_radii_sphere_moment : + ∃ C : ℝ, 1 ≤ C ∧ ∀ d : ℕ, 16 ≤ d → + let k := d/4 + let β : ℝ := (d:ℝ)-1-k + ∀ f : EuclideanSpace ℝ (Fin d) → ℝ≥0∞, + Measurable f → (∀ s, f s ≤ 1) → + ∀ K : ℝ, 0 ≤ K → + AllBallMass (NoiselessRegression.ambientSphereLaw.withDensity f) K β → + ∀ z : EuclideanSpace ℝ (Fin d), ∀ R : ℝ, 0 < R → + ∀ u : Fin k → EuclideanSpace ℝ (Fin d), Orthonormal ℝ u → + let μ := sphereWeightedRestriction f (Metric.closedBall z R) + Measurable (coordinateDensity μ k) ∧ + (∀ A : Fin k → EuclideanSpace ℝ (Fin d), Orthonormal ℝ A → + (volume : Measure (Fin k → ℝ)).withDensity (fun y => coordinateDensity μ k (A,y)) = + μ.map (coordinateMap A)) ∧ + (∀ A : Fin k → EuclideanSpace ℝ (Fin d), Orthonormal ℝ A → + ∀ y : Fin k → ℝ, R < ‖WithLp.toLp 2 (y-coordinateMap A z)‖ → + coordinateDensity μ k (A,y) = 0) ∧ + (∫⁻ A, ∫⁻ y : Fin k → ℝ, coordinateDensity μ k (A,y)^k ∂volume ∂frameLaw u) ^ (1/(k:ℝ)) ≤ + ENNReal.ofReal (C^d*(C*Real.sqrt d)^((k:ℝ)*(1-1/(k:ℝ)))* + K*R^(β-(k:ℝ)*(1-1/(k:ℝ)))) := by + obtain ⟨C,hC,h⟩ := integrated_frame_moment + refine ⟨C,hC,?_⟩ + intro d hd k β f hf hf1 K hK hball z R hR u hu μ + let : NeZero d := ⟨by omega⟩ + let : IsFiniteMeasure μ := sphereWeightedRestriction_finite hf1 _ + have hk : 4 ≤ k := by dsimp [k]; omega + have h3k : 3*k ≤ d := by dsimp [k]; omega + have h3kR : 3*(k:ℝ) ≤ d := by exact_mod_cast h3k + have hkR : (4:ℝ) ≤ k := by exact_mod_cast hk + have hβ : 0 < β := by dsimp [β]; linarith + have hβd : β ≤ d := by dsimp [β]; linarith + have hm : 1 ≤ β-(k:ℝ)-((k:ℝ)-2) := by dsimp [β]; linarith + have hs : μ.support ⊆ Metric.closedBall z R := sphereWeightedRestriction_support Subset.rfl + have hball' : AllBallMass μ K β := fun c r hr => (Measure.restrict_le_self _).trans (hball c r hr) + have hac (A : Fin k → EuclideanSpace ℝ (Fin d)) (hA : Orthonormal ℝ A) : + μ.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ)) := + ((Measure.absolutelyContinuous_of_le (sphereWeightedRestriction_le hf1 _)).map + (by fun_prop)).trans (sphere_frame_ac (by simp only [finrank_euclideanSpace_fin]; omega) hA) + have hframe := h d k k β K R μ z u (by omega) (by omega) (by omega) + hβ (by exact_mod_cast hβd) hm hK hR hs hball' hu + (polar_ac_to_frame μ (by simpa only [finrank_euclideanSpace_fin] using (show k ≤ d by omega)) hu + (Filter.Eventually.of_forall (fun X => (rowMap_ac_iff _).mpr (hac _ (polarRows_orthonormal hu X))))) + refine ⟨hframe.1,?_,hframe.2.2.1,hframe.2.2.2⟩ + intro A hA + exact coordinateDensity_is_density μ k A (hac A hA) + +lemma normalized_cost (d k n : ℕ) (hk : 1 ≤ k) (hkd : k ≤ d) (hdk : d ≤ 32*k) + (D : ℝ) (hD : 0 < D) : + unitBallVolume k ^ n * + ((2 : ℝ≥0∞)^k * ENNReal.ofReal (Real.sqrt (2*d))^(k*n) * + (ENNReal.ofReal (D^d)^(n+1) * (128 : ℝ≥0∞)^(d*n))) ≤ + ENNReal.ofReal ((16384 * max D 1)^(d*(n+1))) := by + have hkR : (0:ℝ) < k := by exact_mod_cast hk + have hdR : (d:ℝ) ≤ 32*k := by exact_mod_cast hdk + have hroot : Real.sqrt (2*d) ≤ 8*Real.sqrt k := by + have h1 := Real.sq_sqrt (show (0:ℝ) ≤ 2*d by positivity) + have h2 := Real.sq_sqrt hkR.le + have h3 := Real.sqrt_nonneg (2*(d:ℝ)) + have h4 := Real.sqrt_pos.mpr hkR + nlinarith + have hc : 0 ≤ 6/Real.sqrt k := by positivity + have hcs : 6/Real.sqrt k * Real.sqrt (2*d) ≤ 48 := by + rw [div_mul_eq_mul_div, div_le_iff₀ (Real.sqrt_pos.mpr hkR)] + nlinarith + have hvol : unitBallVolume k ^ n * ENNReal.ofReal (Real.sqrt (2*d))^(k*n) ≤ + (48 : ℝ≥0∞)^(k*n) := by + calc + _ ≤ ENNReal.ofReal ((6/Real.sqrt k)^k)^n * ENNReal.ofReal (Real.sqrt (2*d))^(k*n) := + mul_le_mul' (pow_le_pow_left' (unitBallVolume_bound k hk) n) le_rfl + _ = ENNReal.ofReal (6/Real.sqrt k * Real.sqrt (2*d))^(k*n) := by + rw [ENNReal.ofReal_pow hc, ← pow_mul, ENNReal.ofReal_mul hc, mul_pow] + _ ≤ (48 : ℝ≥0∞)^(k*n) := pow_le_pow_left' (by exact_mod_cast ENNReal.ofReal_le_ofReal hcs) _ + have h2 : (2 : ℝ≥0∞)^k ≤ (2 : ℝ≥0∞)^(d*(n+1)) := + pow_le_pow_right₀ (by norm_num) (by nlinarith) + have h48 : (48 : ℝ≥0∞)^(k*n) ≤ (64 : ℝ≥0∞)^(d*(n+1)) := + (pow_le_pow_left' (by norm_num : (48:ℝ≥0∞) ≤ 64) _).trans + (pow_le_pow_right₀ (by norm_num) (by nlinarith)) + have h128 : (128 : ℝ≥0∞)^(d*n) ≤ (128 : ℝ≥0∞)^(d*(n+1)) := + pow_le_pow_right₀ (by norm_num) (by nlinarith) + have hDD : ENNReal.ofReal (D^d)^(n+1) ≤ ENNReal.ofReal (max D 1)^(d*(n+1)) := by + rw [ENNReal.ofReal_pow hD.le, ← pow_mul] + exact pow_le_pow_left' (ENNReal.ofReal_le_ofReal (le_max_left _ _)) _ + calc + _ = (2 : ℝ≥0∞)^k * + (unitBallVolume k ^ n * ENNReal.ofReal (Real.sqrt (2*d))^(k*n)) * + ENNReal.ofReal (D^d)^(n+1) * (128 : ℝ≥0∞)^(d*n) := by ring + _ ≤ (2 : ℝ≥0∞)^(d*(n+1)) * (64 : ℝ≥0∞)^(d*(n+1)) * + ENNReal.ofReal (max D 1)^(d*(n+1)) * (128 : ℝ≥0∞)^(d*(n+1)) := + mul_le_mul' (mul_le_mul' (mul_le_mul' h2 (hvol.trans h48)) hDD) h128 + _ = ENNReal.ofReal ((16384 * max D 1)^(d*(n+1))) := by + rw [ENNReal.ofReal_pow (by positivity), ENNReal.ofReal_mul (by norm_num)] + norm_num only [ENNReal.ofReal_ofNat] + rw [← mul_pow, ← mul_pow, ← mul_pow] + congr 1 + ring + +theorem normalized_unitBall_moment (D : ℝ) (hD : 0 < D) : + ∃ C_D : ℝ, 0 < C_D ∧ ∀ d : ℕ, 32 ≤ d → + let k := d/16 + let lam : ℝ := ((d:ℝ)-1)/2 + ∀ (ν : Measure (EuclideanSpace ℝ (Fin d))) [IsFiniteMeasure ν] + (u : Fin k → EuclideanSpace ℝ (Fin d)), + ν Set.univ ≤ 1 → ν.support ⊆ Metric.closedBall 0 1 → + AllBallMass ν (D^d) lam → Orthonormal ℝ u → + (∀ᵐ X ∂Measure.pi (fun _ : Fin k => stdGaussian (EuclideanSpace ℝ (Fin d))), + ν.map (rowMap (polarRows u X)) ≪ (volume : Measure (Label k))) → + Measurable (normalizedDensity ν k u) ∧ + (∀ᵐ X ∂Measure.pi (fun _ : Fin k => stdGaussian (EuclideanSpace ℝ (Fin d))), + ((unitBallVolume k)⁻¹ • (volume : Measure (Label k))).withDensity + (fun y => normalizedDensity ν k u (X,y)) = ν.map (rowMap (polarRows u X))) ∧ + (∀ X y, 1 < ‖y‖ → normalizedDensity ν k u (X,y) = 0) ∧ + (∫⁻ X, ∫⁻ y, normalizedDensity ν k u (X,y)^k ∂unitBallLaw k + ∂Measure.pi (fun _ => stdGaussian (EuclideanSpace ℝ (Fin d)))) ≤ + ENNReal.ofReal (Real.exp (C_D*d*k)) := by + refine ⟨Real.log (16384*max D 1), Real.log_pos (by nlinarith [le_max_right D 1]), ?_⟩ + intro d hd k lam ν _ u hmass hs hν hu hac + have hk2 : 2 ≤ k := by dsimp [k]; omega + have hk : 1 ≤ k := by omega + have hkd : k ≤ d := by dsimp [k]; omega + have hdk : d ≤ 32*k := by dsimp [k]; omega + have h16 : 16*k ≤ d := by dsimp [k]; omega + have hnc : k-1+1 = k := by omega + have hncR : ((k-1:ℕ):ℝ)+1 = k := by exact_mod_cast hnc + have h16R : 16*(k:ℝ) ≤ d := by exact_mod_cast h16 + have hkR : (2:ℝ) ≤ k := by exact_mod_cast hk2 + have hdR : (32:ℝ) ≤ d := by exact_mod_cast hd + have hmargin : ((k-1:ℕ):ℝ)+k ≤ lam := by dsimp [lam]; linarith + have hlamd : lam ≤ (d:ℝ) := by dsimp [lam]; linarith + have hac' := polar_ac_to_frame ν (by simpa using hkd) hu hac + refine ⟨measurable_normalizedDensity ν k u, ?_, ?_, ?_⟩ + · filter_upwards [hac] with X hX + exact normalizedDensity_is_density ν X hX + · exact normalizedDensity_support ν hu hs + · have hframe := frame_moment_scaled hν (pow_pos hD d) (0 : EuclideanSpace ℝ (Fin d)) + (by norm_num : (0:ℝ) < 1) hs k (k-1) hmargin + (by simpa using (show 1 ≤ d by omega)) (by simpa using hlamd) (by simpa using hkd) u hu hac' + simp only [Real.one_rpow, mul_one, one_pow, ENNReal.ofReal_one, finrank_euclideanSpace_fin] at hframe + have hnorm := (normalizedMoment_le ν (by simpa using hkd) hu (k-1)).trans + (mul_le_mul' le_rfl hframe) + have hcost := normalized_cost d k (k-1) hk hkd hdk D hD + have hres := hnorm.trans hcost + rw [hnc] at hres + have he : (16384*max D 1)^(d*k) = Real.exp (Real.log (16384*max D 1)*d*k) := by + rw [show Real.log (16384*max D 1)*(d:ℝ)*k = ((d*k:ℕ):ℝ)*Real.log (16384*max D 1) by push_cast; ring, + Real.exp_nat_mul, Real.exp_log (by positivity)] + simpa only [he] using hres + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/BorelRules.lean b/lean/OAI/Probability/ProjectionMoments/BorelRules.lean new file mode 100644 index 0000000000000000000000000000000000000000..9116b557f6242f2d15116a026f5f353dbfac4226 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/BorelRules.lean @@ -0,0 +1,164 @@ +import OAI.Probability.ProjectionMoments.Stopping + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression +namespace Learner +universe u +variable {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + +instance runStatusMeasurable : MeasurableSpace (RunStatus M) := ⊤ +instance runStatusSingleton : MeasurableSingletonClass (RunStatus M) := ⟨fun _ => trivial⟩ + +lemma measurable_countable_select {X Y J : Type*} [MeasurableSpace X] [MeasurableSpace Y] + [MeasurableSpace J] [MeasurableSingletonClass J] [Countable J] + {f : J → X → Y} (hf : ∀ j, Measurable (f j)) {g : X → J} (hg : Measurable g) : + Measurable (fun x => f (g x) x) := + (measurable_from_prod_countable_right (f := fun z : J × X => f z.1 z.2) hf).comp (hg.prodMk measurable_id) + +lemma measurable_run (L : Learner d M T Ω) (hL : L.MeasurableRules) (n : ℕ) : + Measurable (fun z : UnitSphere d × (Ω × Samples d T) => L.run z.1 z.2.1 z.2.2 n) := by + classical + induction n with + | zero => + exact (measurable_of_finite (fun a : Bool × State M => + if a.1 then Sum.inr (0,a.2) else Sum.inl a.2)).comp + (hL.initial.comp (measurable_fst.comp measurable_snd)) + | succ n ih => + let F : RunStatus M → (UnitSphere d × (Ω × Samples d T)) → RunStatus M := fun j z => + match j with + | .inr done => .inr done + | .inl j => if hn : n < T then + let row := z.2.2 ⟨n,hn⟩ + let a := L.transition (n+1) z.2.1 j (row,⟪row,z.1.val⟫) + if a.1 then .inr (n+1,a.2) else .inl a.2 + else .inl j + change Measurable (fun z => F (L.run z.1 z.2.1 z.2.2 n) z) + apply measurable_countable_select _ ih + intro j + cases j with + | inr done => exact measurable_const + | inl j => + dsimp [F] + split_ifs with hn + · exact (measurable_of_finite (fun a : Bool × State M => + if a.1 then Sum.inr (n+1,a.2) else Sum.inl a.2)).comp + ((hL.transition (n+1) j).comp (show Measurable (fun z : UnitSphere d × (Ω × Samples d T) => + (z.2.1,(z.2.2 ⟨n,hn⟩,⟪z.2.2 ⟨n,hn⟩,z.1.val⟫))) from by fun_prop)) + · exact measurable_const + +lemma measurable_terminal (L : Learner d M T Ω) (hL : L.MeasurableRules) : + Measurable (fun z : UnitSphere d × (Ω × Samples d T) => L.terminal z.1 z.2.1 z.2.2) := by + exact (measurable_of_countable (fun j : RunStatus M => + match j with | .inl j => (T,j) | .inr done => done)).comp (L.measurable_run hL T) + +lemma measurable_estimate (L : Learner d M T Ω) (hL : L.MeasurableRules) : + Measurable (fun z : UnitSphere d × (Ω × Samples d T) => L.estimate z.1 z.2.1 z.2.2) := by + exact measurable_countable_select (f := fun a z => L.output a.1 z.2.1 a.2) + (fun a => (hL.output a.1 a.2).comp (by fun_prop)) (L.measurable_terminal hL) + +lemma admissible_of_measurable (L : Learner d M T Ω) (hL : L.MeasurableRules) (ρ : Measure Ω) : + L.Admissible ρ := by + refine ⟨hL.initial.aemeasurable,fun t j => (hL.transition t j).aemeasurable, + fun t j => (hL.output t j).aemeasurable,?_,(L.measurable_estimate hL).aemeasurable⟩ + intro s + exact ((L.measurable_estimate hL).comp (measurable_const.prodMk measurable_id)).aemeasurable + +end Learner + +universe u + +lemma joint_sphere_sample_observation_quasi {d T : ℕ} (hd : 3 ≤ d) + {Ω : Type u} [MeasurableSpace Ω] (ρ : Measure Ω) [SFinite ρ] (i : Fin T) : + Measure.QuasiMeasurePreserving + (fun z : UnitSphere d × (Ω × Samples d T) => (z.2.1,(z.2.2 i,⟪z.1.val,z.2.2 i⟫))) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) (ρ.prod (observationReference d)) := by + let : NeZero d := ⟨by omega⟩ + have hp := (measurePreserving_prodAssoc ρ (uniformSphere d) (sampleLaw d T)).comp + (((Measure.measurePreserving_swap (μ := uniformSphere d) (ν := ρ)).prod + (MeasurePreserving.id (sampleLaw d T))).comp + ((measurePreserving_prodAssoc (uniformSphere d) ρ (sampleLaw d T)).symm + MeasurableEquiv.prodAssoc)) + have h := QuasiMeasurePreserving.prodMap (Measure.QuasiMeasurePreserving.id ρ) + (sphere_sample_observation_quasi (E := Vector d) (by simpa using hd) i) + exact h.comp hp.quasiMeasurePreserving + +namespace Learner +variable {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + +theorem exists_borel_version (L : Learner d M T Ω) (ρ : Measure Ω) [SFinite ρ] + (hd : 3 ≤ d) + (hi : AEMeasurable L.initialChoice ρ) + (ht : ∀ t j, AEMeasurable (fun z : Ω × (Vector d × ℝ) => L.transition t z.1 j z.2) + (ρ.prod (observationReference d))) + (ho : ∀ t j, AEMeasurable (fun ω => L.output t ω j) ρ) : + ∃ L' : Learner d M T Ω, L'.MeasurableRules ∧ + (∀ᵐ z ∂((uniformSphere d).prod (ρ.prod (sampleLaw d T))), + (∀ n, L.run z.1 z.2.1 z.2.2 n = L'.run z.1 z.2.1 z.2.2 n) ∧ + L.estimate z.1 z.2.1 z.2.2 = L'.estimate z.1 z.2.1 z.2.2) := by + classical + let L' : Learner d M T Ω := ⟨hi.mk _,fun t ω j obs => (ht t j).mk _ (ω,obs), + fun t ω j => (ho t j).mk _ ω⟩ + have hL' : L'.MeasurableRules := ⟨hi.measurable_mk,fun t j => (ht t j).measurable_mk, + fun t j => (ho t j).measurable_mk⟩ + refine ⟨L',hL',?_⟩ + let μ := (uniformSphere d).prod (ρ.prod (sampleLaw d T)) + have hp : Measure.QuasiMeasurePreserving (fun z : UnitSphere d × (Ω × Samples d T) => z.2.1) μ ρ := + QuasiMeasurePreserving.fst Measure.quasiMeasurePreserving_snd + have hinit : ∀ᵐ z ∂μ, L.initialChoice z.2.1 = L'.initialChoice z.2.1 := hp.ae hi.ae_eq_mk + have hout : ∀ᵐ z ∂μ, ∀ t j, L.output t z.2.1 j = L'.output t z.2.1 j := by + simp only [ae_all_iff] + intro t j + exact hp.ae (ho t j).ae_eq_mk + have htrans : ∀ᵐ z ∂μ, ∀ t j (i : Fin T), + L.transition t z.2.1 j (z.2.2 i,⟪z.2.2 i,z.1.val⟫) = + L'.transition t z.2.1 j (z.2.2 i,⟪z.2.2 i,z.1.val⟫) := by + simp only [ae_all_iff] + intro t j i + simpa only [real_inner_comm] using (joint_sphere_sample_observation_quasi hd ρ i).ae (ht t j).ae_eq_mk + filter_upwards [hinit,hout,htrans] with z hi ho ht + have hr (n : ℕ) : L.run z.1 z.2.1 z.2.2 n = L'.run z.1 z.2.1 z.2.2 n := by + induction n with + | zero => simp only [run,start,hi] + | succ n ih => + rw [run,run,ih] + cases L'.run z.1 z.2.1 z.2.2 n with + | inr done => rfl + | inl j => + split_ifs with hn + · dsimp only + rw [ht (n+1) j ⟨n,hn⟩] + · rfl + refine ⟨hr,?_⟩ + have he : L.terminal z.1 z.2.1 z.2.2 = L'.terminal z.1 z.2.1 z.2.2 := by + simp only [terminal,hr] + simp only [estimate,he,ho] + +lemma aemeasurable_terminal_of_rules (L : Learner d M T Ω) (ρ : Measure Ω) [SFinite ρ] + (hd : 3 ≤ d) (hL : L.Admissible ρ) : + AEMeasurable (fun z : UnitSphere d × (Ω × Samples d T) => L.terminal z.1 z.2.1 z.2.2) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := by + obtain ⟨L',hL',he⟩ := L.exists_borel_version ρ hd hL.initialChoice hL.transition hL.output + apply (L'.measurable_terminal hL').aemeasurable.congr + filter_upwards [he] with z hz + simp only [terminal,hz.1] + +lemma uniformSuccess_borel_version (L : Learner d M T Ω) (ρ : Measure Ω) [SFinite ρ] + (hd : 3 ≤ d) (hL : L.Admissible ρ) : + ∃ L' : Learner d M T Ω, L'.MeasurableRules ∧ L'.Admissible ρ ∧ + ∀ ε, L.uniformSuccess ρ ε = L'.uniformSuccess ρ ε := by + obtain ⟨L',hL',he⟩ := L.exists_borel_version ρ hd hL.initialChoice hL.transition hL.output + refine ⟨L',hL',L'.admissible_of_measurable hL' ρ,fun ε => measure_congr ?_⟩ + filter_upwards [he] with z hz + rw [hz.2] + +end Learner +end NoiselessRegression + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/CapDomination.lean b/lean/OAI/Probability/ProjectionMoments/CapDomination.lean new file mode 100644 index 0000000000000000000000000000000000000000..cdf2969ef55eee71791ecba3faaacb16cd3039c8 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/CapDomination.lean @@ -0,0 +1,119 @@ +import OAI.Probability.ProjectionMoments.WeightedCover + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments + +theorem positive_cap_domination : + ∃ C : ℝ, 0 < C ∧ ∀ d : ℕ, 32 ≤ d → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + ∀ (c : EuclideanSpace ℝ (Fin d)), ‖c‖ = 1 → + ∀ r : ℝ, 0 < r → r ≤ 2 → + ∀ K : (Fin k → EuclideanSpace ℝ (Fin d)) × Label k → ℝ≥0∞, + Measurable K → (∀ z, K z ≤ 1) → + ∃ D : CapDictionary c r α, ∃ a : D.I → ℝ, + (∀ i, 0 ≤ a i) ∧ Summable (fun i => a i*(r/D.radius i)^α) ∧ + (∑' i, a i*(r/D.radius i)^α) ≤ Real.exp (C*d)*(capReference K c r).toReal^(1-1/(k:ℝ)) ∧ + (capMeasure c r).withDensity (capKernelValue K) ≤ + Measure.sum (fun i => ENNReal.ofReal (a i) • capMeasure (D.center i) (D.radius i)) ∧ + (Measure.sum (fun i => ENNReal.ofReal (a i) • capMeasure (D.center i) (D.radius i))) Set.univ < ∞ := by + obtain ⟨C,hC,hdual⟩ := cap_dual_estimate + refine ⟨C,hC,?_⟩ + intro d hd k α c hc r hr hr2 K hK hK1 + let : NeZero d := ⟨by omega⟩ + have hdR : (32:ℝ) ≤ d := by exact_mod_cast hd + have hα : 1 ≤ α := by dsimp [α]; linarith + obtain ⟨D⟩ := exists_capDictionary hc hr hα + let := D.countable + let : IsProbabilityMeasure (capMeasure c r) := capMeasure_probability hc hr hr2 + let P : D.I → Measure (EuclideanSpace ℝ (Fin d)) := fun i => capMeasure (D.center i) (D.radius i) + let (i : D.I) : IsProbabilityMeasure (P i) := + capMeasure_probability (D.center_norm i) (D.radius_pos i) ((D.radius_le i).trans hr2) + let b : D.I → ℝ := fun i => (r/D.radius i)^α + have hb : ∀ i, 1 ≤ b i := fun i => Real.one_le_rpow + ((one_le_div (D.radius_pos i)).mpr (D.radius_le i)) (zero_le_one.trans hα) + let μ := (capMeasure c r).withDensity (capKernelValue K) + let : IsFiniteMeasure μ := isFiniteMeasure_withDensity (ne_of_lt + ((lintegral_mono (capKernelValue_le_one hK1)).trans_lt (by simp))) + let B := Real.exp (C*d)*(capReference K c r).toReal^(1-1/(k:ℝ)) + have hkR : (1:ℝ) < k := by + have hk : 2 ≤ k := by dsimp [k]; omega + exact_mod_cast (show 1 < k by omega) + have hθ : 0 ≤ 1-1/(k:ℝ) := by + have hpq := Real.HolderConjugate.conjExponent hkR + rw [one_div,hpq.one_sub_inv] + exact inv_nonneg.mpr hpq.symm.pos.le + have hqtop : capReference K c r ≠ ∞ := ne_of_lt ((capReference_le_one hK1 c r).trans_lt (by simp)) + have hB : ENNReal.ofReal B = ENNReal.ofReal (Real.exp (C*d))* (capReference K c r)^(1-1/(k:ℝ)) := by + rw [ENNReal.ofReal_mul (Real.exp_pos _).le, ← ENNReal.ofReal_rpow_of_nonneg ENNReal.toReal_nonneg hθ, + ENNReal.ofReal_toReal hqtop] + have htest : ∀ h : EuclideanSpace ℝ (Fin d) → ℝ≥0∞, Measurable h → + (∃ H : ℝ≥0, ∀ x, h x ≤ H) → + (∀ i, ∫⁻ x, h x ∂P i ≤ ENNReal.ofReal (b i)) → ∫⁻ x, h x ∂μ ≤ ENNReal.ofReal B := by + intro h hh _ hhD + rw [hB,lintegral_withDensity_eq_lintegral_mul _ (measurable_capKernelValue hK) hh] + simp only [Pi.mul_apply] + simpa only [mul_comm] using hdual d hd c hc r hr hr2 D K hK hK1 h hh hhD + obtain ⟨a,ha,has,hcost,hdom⟩ := Weighted.measure_domination_nonneg μ P hb D.proper + (show 0 ≤ B by positivity) htest + refine ⟨D,a,ha,has,hcost,hdom,?_⟩ + rw [Measure.sum_apply _ MeasurableSet.univ] + simp only [Measure.smul_apply,measure_univ,smul_eq_mul,mul_one] + have has' : Summable a := Summable.of_nonneg_of_le ha + (fun i => by simpa using mul_le_mul_of_nonneg_left (hb i) (ha i)) has + rw [← ENNReal.ofReal_tsum_of_nonneg ha has'] + exact ENNReal.ofReal_lt_top + +lemma capReference_sum_le_one {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + {k : ℕ} {J : Type*} [Fintype J] + (K : J → (Fin k → E) × Label k → ℝ≥0∞) (hK : ∀ j, Measurable (K j)) + (hKsum : ∀ z, ∑ j, K j z ≤ 1) (c : E) (r : ℝ) : ∑ j, capReference (K j) c r ≤ 1 := by + classical + simp only [capReference] + rw [← lintegral_finsetSum _ (fun j _ => by fun_prop)] + calc + _ = ∫⁻ X, ∫⁻ z, ∑ j, K j (X,capReferenceLabel c r X z) ∂unitBallLaw k + ∂Measure.pi (fun _ => stdGaussian E) := by + apply lintegral_congr + intro X + exact (lintegral_finsetSum _ (fun j _ => by fun_prop)).symm + _ ≤ ∫⁻ X, ∫⁻ z : Label k, (1 : ℝ≥0∞) ∂unitBallLaw k + ∂Measure.pi (fun _ : Fin k => stdGaussian E) := + lintegral_mono (fun X => lintegral_mono (fun z => hKsum _)) + _ = 1 := by simp + +theorem positive_family_cap_domination : + ∃ C : ℝ, 0 < C ∧ ∀ d : ℕ, 32 ≤ d → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + ∀ (c : EuclideanSpace ℝ (Fin d)), ‖c‖ = 1 → + ∀ r : ℝ, 0 < r → r ≤ 2 → ∀ N : ℕ, + ∀ K : Fin N → (Fin k → EuclideanSpace ℝ (Fin d)) × Label k → ℝ≥0∞, + (∀ j, Measurable (K j)) → (∀ z, ∑ j, K j z ≤ 1) → + (∑ j, capReference (K j) c r) ≤ 1 ∧ + ∀ j, ∃ D : CapDictionary c r α, ∃ a : D.I → ℝ, + (∀ i, 0 ≤ a i) ∧ Summable (fun i => a i*(r/D.radius i)^α) ∧ + (∑' i, a i*(r/D.radius i)^α) ≤ Real.exp (C*d)*(capReference (K j) c r).toReal^(1-1/(k:ℝ)) ∧ + (capMeasure c r).withDensity (capKernelValue (K j)) ≤ + Measure.sum (fun i => ENNReal.ofReal (a i) • capMeasure (D.center i) (D.radius i)) ∧ + (Measure.sum (fun i => ENNReal.ofReal (a i) • capMeasure (D.center i) (D.radius i))) Set.univ < ∞ := by + obtain ⟨C,hC,h⟩ := positive_cap_domination + refine ⟨C,hC,?_⟩ + intro d hd k α c hc r hr hr2 N K hK hKsum + refine ⟨capReference_sum_le_one K hK hKsum c r,?_⟩ + intro j + apply h d hd c hc r hr hr2 (K j) (hK j) + intro z + exact (Finset.single_le_sum (fun i _ => bot_le) (Finset.mem_univ j)).trans (hKsum z) + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/CapDuality.lean b/lean/OAI/Probability/ProjectionMoments/CapDuality.lean new file mode 100644 index 0000000000000000000000000000000000000000..c9b3002d82d0484f8ba9dc53b0e9a8cbc9692bb2 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/CapDuality.lean @@ -0,0 +1,209 @@ +import OAI.Probability.ProjectionMoments.CapTests + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace Matrix +open MeasureTheory +open scoped ENNReal NNReal +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +@[fun_prop] lemma measurable_radialLabel {k : ℕ} : + Measurable (fun z : (Fin k → E) × Label k => radialLabel z.1 z.2) := by + have hH : Measurable (fun z : (Fin k → E) × Label k => polarRadial z.1) := (continuous_polarRadial (E := E) (k := k)).measurable.comp measurable_fst + apply (MeasurableEquiv.toLp 2 (Fin k → ℝ)).measurable.comp + apply Measurable.of_eval + intro i + change Measurable (fun z : (Fin k → E) × Label k => ∑ j, polarRadial z.1 i j * z.2.ofLp j) + apply Finset.measurable_sum + intro j hj + exact ((measurable_pi_apply j).comp ((measurable_pi_apply i).comp hH)).mul (by fun_prop) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma rowMap_mixRows [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {k : ℕ} (M : Matrix (Fin k) (Fin k) ℝ) (X : Fin k → E) (s : E) : + rowMap (mixRows M X) s = WithLp.toLp 2 (M *ᵥ (rowMap X s).ofLp) := by + ext i + simp [rowMap, mixRows, Matrix.mulVec, dotProduct] + +lemma polar_label_identity {k : ℕ} {X : Fin k → E} (hX : LinearIndependent ℝ X) + (u : Fin k → E) (c s : E) (r : ℝ) : + rowMap X (dilate c r s) = rowMap X c + r • radialLabel X (rowMap (polarRows u X) s) := by + have he : radialLabel X (rowMap (polarRows u X) s) = rowMap X s := by + rw [radialLabel, ← rowMap_mixRows] + simp only [polarRows, ite_eq_left hX, polar_reconstruction hX] + rw [he, dilate, map_add, map_smul] + exact add_comm _ _ + +lemma normalizedDensity_unitBall (ν : Measure E) [IsFiniteMeasure ν] {k : ℕ} + {u : Fin k → E} (hu : Orthonormal ℝ u) (hs : ν.support ⊆ Metric.closedBall 0 1) + (X : Fin k → E) (hac : ν.map (rowMap (polarRows u X)) ≪ (volume : Measure (Label k))) : + (unitBallLaw k).withDensity (fun y => normalizedDensity ν k u (X,y)) = + ν.map (rowMap (polarRows u X)) := by + have he : (Metric.closedBall (0:Label k) 1).indicator + (fun y => normalizedDensity ν k u (X,y)) = fun y => normalizedDensity ν k u (X,y) := by + funext y + by_cases hy : y ∈ Metric.closedBall (0:Label k) 1 + · simp [hy] + · rw [Set.indicator_of_notMem hy] + have hh : 1 < ‖y‖ := by simpa using hy + exact (normalizedDensity_support ν hu hs X y hh).symm + rw [unitBallLaw, withDensity_smul_measure, ← withDensity_indicator Metric.isClosed_closedBall.measurableSet, he, + ← withDensity_smul_measure] + exact normalizedDensity_is_density ν X hac + +@[fun_prop] lemma measurable_capReferenceLabel {k : ℕ} (c : E) (r : ℝ) : + Measurable (fun z : (Fin k → E) × Label k => capReferenceLabel c r z.1 z.2) := by + unfold capReferenceLabel + exact (show Measurable (fun z : (Fin k → E) × Label k => rowMap z.1 c) by + simp only [rowMap_apply]; fun_prop).add (measurable_radialLabel.const_smul r) + +@[fun_prop] lemma measurable_capKernelValue {k : ℕ} {K : (Fin k → E) × Label k → ℝ≥0∞} + (hK : Measurable K) : Measurable (capKernelValue K) := by + apply Measurable.lintegral_prod_right + exact hK.comp (measurable_snd.prodMk (by simp only [rowMap_apply]; fun_prop)) + +omit [BorelSpace E] in +lemma capReference_le_one [BorelSpace E] {k : ℕ} {K : (Fin k → E) × Label k → ℝ≥0∞} + (hK1 : ∀ z, K z ≤ 1) (c : E) (r : ℝ) : capReference K c r ≤ 1 := by + calc + _ ≤ ∫⁻ X, ∫⁻ z : Label k, (1:ℝ≥0∞) ∂unitBallLaw k ∂Measure.pi (fun _ : Fin k => stdGaussian E) := + lintegral_mono (fun X => lintegral_mono (fun z => hK1 _)) + _ = 1 := by simp + +omit [BorelSpace E] in +lemma capKernelValue_le_one [BorelSpace E] {k : ℕ} {K : (Fin k → E) × Label k → ℝ≥0∞} + (hK1 : ∀ z, K z ≤ 1) (s : E) : capKernelValue K s ≤ 1 := by + calc + _ ≤ ∫⁻ X : Fin k → E, (1:ℝ≥0∞) ∂Measure.pi (fun _ => stdGaussian E) := + lintegral_mono (fun X => hK1 _) + _ = 1 := by simp + +lemma cap_kernel_test_identity {k : ℕ} (hk : k ≤ Module.finrank ℝ E) + {K : (Fin k → E) × Label k → ℝ≥0∞} (hK : Measurable K) + (h : E → ℝ≥0∞) (hh : Measurable h) (c : E) {r : ℝ} (hr : 0 < r) + {u : Fin k → E} (hu : Orthonormal ℝ u) + [IsFiniteMeasure ((capMeasure c r).withDensity h)] + (hac : ∀ X, (capTestMeasure h c r).map (rowMap (polarRows u X)) ≪ (volume : Measure (Label k))) : + (∫⁻ s, h s * capKernelValue K s ∂capMeasure c r) = + ∫⁻ X, ∫⁻ z, normalizedDensity (capTestMeasure h c r) k u (X,z) * + K (X,capReferenceLabel c r X z) ∂unitBallLaw k ∂Measure.pi (fun _ => stdGaussian E) := by + let μ := (capMeasure c r).withDensity h + let ν := capTestMeasure h c r + have : IsFiniteMeasure ν := Measure.isFiniteMeasure_map _ _ + have hf (X : Fin k → E) : Measurable (fun s => K (X,rowMap X s)) := by fun_prop + have he (X : Fin k → E) (hX : LinearIndependent ℝ X) : + (∫⁻ s, K (X,rowMap X s) ∂μ) = + ∫⁻ z, normalizedDensity ν k u (X,z)*K (X,capReferenceLabel c r X z) ∂unitBallLaw k := by + have hid := lintegral_withDensity_eq_lintegral_mul (unitBallLaw k) + (show Measurable (fun z => normalizedDensity ν k u (X,z)) by fun_prop) + (show Measurable (fun z => K (X,capReferenceLabel c r X z)) by fun_prop) + simp only [Pi.mul_apply] at hid + rw [← hid, + normalizedDensity_unitBall ν hu (capTestMeasure_support h c hr) X (hac X), + lintegral_map (by fun_prop) (by fun_prop)] + change _ = ∫⁻ s, K (X,capReferenceLabel c r X (rowMap (polarRows u X) s)) ∂μ.map (rescale c r) + rw [lintegral_map (by fun_prop) (measurable_rescale c r)] + apply lintegral_congr + intro s + congr 1 + rw [capReferenceLabel, ← polar_label_identity hX u c (rescale c r s) r, + dilate_rescale c hr.ne'] + have hid := lintegral_withDensity_eq_lintegral_mul (capMeasure c r) hh (measurable_capKernelValue hK) + simp only [Pi.mul_apply] at hid + rw [← hid] + change (∫⁻ s, ∫⁻ X, K (X,rowMap X s) ∂Measure.pi (fun _ => stdGaussian E) ∂μ) = _ + rw [lintegral_lintegral_swap (show AEMeasurable (fun z : E × (Fin k → E) => K (z.2,rowMap z.2 z.1)) _ by + apply Measurable.aemeasurable; exact hK.comp (measurable_snd.prodMk (by simp only [rowMap_apply]; fun_prop)))] + exact lintegral_congr_ae (by filter_upwards [gaussian_rows_ae_linearIndependent k hk] with X hX; exact he X hX) + +end + +lemma holder_bounded_kernel {Ω : Type*} [MeasurableSpace Ω] (μ : Measure Ω) + {g f : Ω → ℝ≥0∞} (hg : Measurable g) (hf : Measurable f) (hf1 : ∀ x, f x ≤ 1) + {p : ℝ} (hp : 1 < p) {D : ℝ≥0∞} (hD : (∫⁻ x, g x^p ∂μ) ≤ D) : + (∫⁻ x, g x*f x ∂μ) ≤ D^(1/p) * (∫⁻ x, f x ∂μ)^(1-1/p) := by + have hpq := Real.HolderConjugate.conjExponent hp + have hh := ENNReal.lintegral_mul_le_Lp_mul_Lq μ hpq hg.aemeasurable hf.aemeasurable + have he : 1 / Real.conjExponent p = 1-1/p := by + simpa only [one_div] using hpq.one_sub_inv.symm + have hpow : ∀ x, f x ^ Real.conjExponent p ≤ f x := by + intro x + simpa only [ENNReal.rpow_one] using ENNReal.rpow_le_rpow_of_exponent_ge (hf1 x) hpq.symm.lt.le + simp only [Pi.mul_apply, he] at hh + exact hh.trans (mul_le_mul' (ENNReal.rpow_le_rpow hD (by positivity)) + (ENNReal.rpow_le_rpow (lintegral_mono hpow) (by rw [← he]; exact one_div_nonneg.mpr hpq.symm.pos.le))) + +lemma cap_exp_root (C d : ℝ) {p : ℝ} (hp : 0 < p) : + (ENNReal.ofReal (Real.exp (C*d*p))) ^ (1/p) = ENNReal.ofReal (Real.exp (C*d)) := by + rw [ENNReal.ofReal_rpow_of_pos (Real.exp_pos _), ← Real.exp_mul] + congr 2 + field_simp + +lemma cap_dual_estimate : + ∃ C : ℝ, 0 < C ∧ ∀ d : ℕ, 32 ≤ d → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + ∀ (c : EuclideanSpace ℝ (Fin d)), ‖c‖ = 1 → + ∀ r : ℝ, 0 < r → r ≤ 2 → + ∀ D : CapDictionary c r α, + ∀ K : (Fin k → EuclideanSpace ℝ (Fin d)) × Label k → ℝ≥0∞, + Measurable K → (∀ z, K z ≤ 1) → + ∀ h : EuclideanSpace ℝ (Fin d) → ℝ≥0∞, Measurable h → + (∀ i, ∫⁻ x, h x ∂capMeasure (D.center i) (D.radius i) ≤ ENNReal.ofReal ((r/D.radius i)^α)) → + (∫⁻ s, h s*capKernelValue K s ∂capMeasure c r) ≤ + ENNReal.ofReal (Real.exp (C*d)) * (capReference K c r)^(1-1/(k:ℝ)) := by + obtain ⟨C,hC,hmoment⟩ := normalized_unitBall_moment 2048 (by norm_num) + refine ⟨C,hC,?_⟩ + intro d hd k α c hc r hr hr2 D K hK hK1 h hh hdual + let : NeZero d := ⟨by omega⟩ + have hk : 2 ≤ k := by dsimp [k]; omega + have hkd : k ≤ d := by dsimp [k]; omega + have hkd2 : k+2 ≤ d := by dsimp [k]; omega + have hdR : (32:ℝ) ≤ d := by exact_mod_cast hd + have hα : 2*α = (Module.finrank ℝ (EuclideanSpace ℝ (Fin d))-1:ℕ) := by + simp only [finrank_euclideanSpace_fin, Nat.cast_sub (by omega : 1 ≤ d), Nat.cast_one] + dsimp [α] + ring + let u : Fin k → EuclideanSpace ℝ (Fin d) := (EuclideanSpace.basisFun (Fin d) ℝ) ∘ Fin.castLE hkd + have hu : Orthonormal ℝ u := (EuclideanSpace.basisFun (Fin d) ℝ).orthonormal.comp _ (Fin.castLE_injective hkd) + let ν := capTestMeasure h c r + have hmass := capTestMeasure_mass hr D hdual + let : IsFiniteMeasure ν := capTestMeasure_finite hr D hdual + have hs := capTestMeasure_support h c hr + have hball := capTest_allBall hc hr hr2 (by dsimp [α]; linarith : 0 ≤ α) hα D hdual + simp only [finrank_euclideanSpace_fin] at hball + have hac : ∀ X, ν.map (rowMap (polarRows u X)) ≪ (volume : Measure (Label k)) := + fun X => capTest_frame_ac h c hr (by simpa using hkd2) _ (polarRows_orthonormal hu X) + have hm := (hmoment d hd ν u hmass hs hball hu (Filter.Eventually.of_forall hac)).2.2.2 + have hp : (1:ℝ) < k := by exact_mod_cast (show 1 < k by omega) + let γ := Measure.pi (fun _ : Fin k => stdGaussian (EuclideanSpace ℝ (Fin d))) + let F : (Fin k → EuclideanSpace ℝ (Fin d)) × Label k → ℝ≥0∞ := + fun z => K (z.1,capReferenceLabel c r z.1 z.2) + have hF : Measurable F := hK.comp (measurable_fst.prodMk (measurable_capReferenceLabel c r)) + have hnorm : (∫⁻ z, normalizedDensity ν k u z ^ (k:ℝ) ∂γ.prod (unitBallLaw k)) ≤ + ENNReal.ofReal (Real.exp (C*d*k)) := by + rw [lintegral_prod _ (by fun_prop)] + simpa only [ENNReal.rpow_natCast] using hm + have hb := holder_bounded_kernel (γ.prod (unitBallLaw k)) + (measurable_normalizedDensity ν k u) hF (fun z => hK1 _) hp hnorm + rw [cap_exp_root C d (by positivity : (0:ℝ) r⁻¹ • (y-coordinateMap A c) + have hT : Measurable T := by fun_prop + have hv : (volume : Measure (Fin k → ℝ)).map T ≪ volume := by + have he : T = (fun y : Fin k → ℝ => r⁻¹ • y) ∘ (fun y => y + -coordinateMap A c) := by + funext y; simp [T,sub_eq_add_neg] + rw [he, ← Measure.map_map (by fun_prop) (by fun_prop), + Measure.IsAddRightInvariant.map_add_right_eq_self, Measure.map_addHaar_smul volume (inv_ne_zero hr.ne')] + exact Measure.smul_absolutelyContinuous + have hh := (hν.map hT).trans hv + rw [Measure.map_map hT (by fun_prop)] at hh + rw [Measure.map_map (by fun_prop) (measurable_rescale c r)] + convert hh using 1 + congr 1 + funext s + ext i + simp [T, rescale, coordinateMap_apply, real_inner_smul_left, inner_sub_left] + +lemma capTest_frame_ac [Nontrivial E] (h : E → ℝ≥0∞) (c : E) {r : ℝ} (hr : 0 < r) + {k : ℕ} (hk : k+2 ≤ Module.finrank ℝ E) (A : Fin k → E) (hA : Orthonormal ℝ A) : + (capTestMeasure h c r).map (rowMap A) ≪ (volume : Measure (Label k)) := by + apply (rowMap_ac_iff _).mpr + apply rescaled_projection_ac A c hr + have hh := (((withDensity_absolutelyContinuous (capMeasure c r) h).trans (capMeasure_ac c r)).map + (show Measurable (coordinateMap A) by fun_prop)).trans (sphere_frame_ac hk hA) + exact hh + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Caps.lean b/lean/OAI/Probability/ProjectionMoments/Caps.lean new file mode 100644 index 0000000000000000000000000000000000000000..bdf326bbd29ccb695913fb590a41fc41a6d9a848 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Caps.lean @@ -0,0 +1,338 @@ +import OAI.Probability.ProjectionMoments.BallMoments + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma sphere_packing_annulus (s : Finset E) {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) + (hs : ∀ x ∈ s, ‖x‖ = 1) + (hsep : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → r ≤ dist x y) : + (s.card : ℝ) * (r/2)^Module.finrank ℝ E ≤ + (1+r/2)^Module.finrank ℝ E - (1-r/2)^Module.finrank ℝ E := by + classical + let δ := r/2 + let U : Set E := ⋃ c ∈ s, Metric.ball c δ + let V : Set E := Metric.ball 0 (1-δ) + have hδ : 0 < δ := by dsimp [δ]; positivity + have hinner : 0 < 1-δ := by dsimp [δ]; linarith + have houter : 0 < 1+δ := by positivity + have hdis : Set.Pairwise (s : Set E) (fun c d => Disjoint (Metric.ball c δ) (Metric.ball d δ)) := by + intro c hc d hd hcd + apply Metric.ball_disjoint_ball + simpa [δ] using hsep c hc d hd hcd + have hUV : Disjoint U V := by + apply Set.disjoint_left.mpr + intro x hx hxV + obtain ⟨c,hc,hxc⟩ := Set.mem_iUnion₂.mp hx + have hxc' : dist x c < δ := hxc + have hx0 : ‖x‖ < 1-δ := by simpa [V, Metric.mem_ball, dist_zero_right] using hxV + have hc1 := hs c hc + have htri := dist_triangle c x (0 : E) + rw [dist_zero_right, dist_zero_right, dist_comm c x, hc1] at htri + linarith + have hsub : U ∪ V ⊆ Metric.ball (0 : E) (1+δ) := by + rintro x (hx | hx) + · obtain ⟨c,hc,hxc⟩ := Set.mem_iUnion₂.mp hx + apply Metric.mem_ball.mpr + have htri := dist_triangle x c (0 : E) + rw [dist_zero_right c, hs c hc] at htri + exact htri.trans_lt (by have hh : dist x c < δ := hxc; linarith) + · exact (Metric.ball_subset_ball (by linarith : 1-δ ≤ 1+δ)) hx + have hU : MeasurableSet U := MeasurableSet.biUnion s.finite_toSet.countable + (fun c _ => Metric.isOpen_ball.measurableSet) + have hvol : ((s.card : ℝ≥0∞)*ENNReal.ofReal (δ^Module.finrank ℝ E) + + ENNReal.ofReal ((1-δ)^Module.finrank ℝ E)) * volume (Metric.ball (0 : E) 1) ≤ + ENNReal.ofReal ((1+δ)^Module.finrank ℝ E)*volume (Metric.ball (0 : E) 1) := by + calc + _ = volume (U ∪ V) := by + rw [measure_union hUV Metric.isOpen_ball.measurableSet, + show volume U = (s.card : ℝ≥0∞)*ENNReal.ofReal (δ^Module.finrank ℝ E)* + volume (Metric.ball (0 : E) 1) by + rw [measure_biUnion_finset hdis (fun _ _ => Metric.isOpen_ball.measurableSet)] + simp only [Measure.addHaar_ball_of_pos volume _ hδ, Finset.sum_const, nsmul_eq_mul, mul_assoc], + Measure.addHaar_ball_of_pos volume 0 hinner, add_mul] + _ ≤ volume (Metric.ball (0 : E) (1+δ)) := measure_mono hsub + _ = _ := Measure.addHaar_ball_of_pos volume 0 houter + have hv0 : volume (Metric.ball (0 : E) 1) ≠ 0 := (Metric.measure_ball_pos volume 0 zero_lt_one).ne' + have hvt : volume (Metric.ball (0 : E) 1) ≠ ∞ := measure_ball_lt_top.ne + have hh := (ENNReal.mul_le_mul_iff_left hv0 hvt).mp hvol + have hreal := ENNReal.toReal_le_of_le_ofReal (pow_nonneg houter.le _) hh + simp only [ENNReal.toReal_add (by finiteness : + (s.card : ℝ≥0∞)*ENNReal.ofReal (δ^Module.finrank ℝ E) ≠ ∞) ENNReal.ofReal_ne_top, + ENNReal.toReal_mul, ENNReal.toReal_natCast, ENNReal.toReal_ofReal (pow_nonneg hδ.le _), + ENNReal.toReal_ofReal (pow_nonneg hinner.le _)] at hreal + dsimp [δ] at hreal + linarith + +lemma sphere_packing_bound (s : Finset E) {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) + (hd : 1 ≤ Module.finrank ℝ E) (hs : ∀ x ∈ s, ‖x‖ = 1) + (hsep : ∀ x ∈ s, ∀ y ∈ s, x ≠ y → r ≤ dist x y) : + (s.card : ℝ)*r^(Module.finrank ℝ E-1) ≤ (8 : ℝ)^Module.finrank ℝ E := by + let d := Module.finrank ℝ E + have hi : 0 ≤ 1-r/2 := by linarith + have ho : 0 ≤ 1+r/2 := by positivity + have hio : 1-r/2 ≤ 1+r/2 := by linarith + have h := sphere_packing_annulus s hr hr1 hs hsep + have hdiff : (1+r/2)^d - (1-r/2)^d ≤ r*d*(1+r/2)^(d-1) := by + have hh := abs_pow_sub_pow_le (a := (1+r/2)) (b := (1-r/2)) (n := d) + rw [abs_of_nonneg (sub_nonneg.mpr (pow_le_pow_left₀ hi hio d)), + abs_of_nonneg ho, abs_of_nonneg hi, max_eq_left hio, + show (1+r/2)-(1-r/2) = r by ring, abs_of_pos hr] at hh + exact hh + have hpow : (1+r/2)^(d-1) ≤ (2 : ℝ)^d := by + exact (pow_le_pow_left₀ ho (by linarith : 1+r/2 ≤ 2) _).trans + (pow_le_pow_right₀ (by norm_num) (Nat.sub_le d 1)) + have hd2 : (d : ℝ) ≤ (2 : ℝ)^d := by + have hn : ∀ n : ℕ, (n : ℝ) ≤ (2 : ℝ)^n := by + intro n + induction n with + | zero => norm_num + | succ n ih => + have hp : (1 : ℝ) ≤ 2^n := one_le_pow₀ (by norm_num) + rw [Nat.cast_succ, pow_succ] + linarith + exact hn d + have hupper : r*d*(1+r/2)^(d-1) ≤ r*(4 : ℝ)^d := by + calc + _ ≤ r*2^d*2^d := mul_le_mul (mul_le_mul_of_nonneg_left hd2 hr.le) hpow (by positivity) (by positivity) + _ = _ := by rw [mul_assoc, ← mul_pow]; norm_num + have hall := h.trans (hdiff.trans hupper) + have htwo : 0 < (2 : ℝ)^d := by positivity + rw [div_pow, ← mul_div_assoc, div_le_iff₀ htwo] at hall + have hp : r^d = r^(d-1)*r := by rw [← pow_succ, Nat.sub_add_cancel hd] + rw [hp, ← mul_assoc, mul_assoc r, ← mul_pow] at hall + norm_num only at hall + nlinarith + +lemma sphere_cap_mass_center [Nontrivial E] {c c' : E} (hc : ‖c‖ = 1) (hc' : ‖c'‖ = 1) + (r : ℝ) : + NoiselessRegression.ambientSphereLaw (Metric.closedBall c r) = + NoiselessRegression.ambientSphereLaw (Metric.closedBall c' r) := by + obtain ⟨O,hO⟩ := rotation_transitive + (show Orthonormal ℝ (fun _ : Fin 1 => c) by simpa using hc) + (show Orthonormal ℝ (fun _ : Fin 1 => c') by simpa using hc') + let e : E ≃ₗᵢ[ℝ] E := Unitary.linearIsometryEquiv O + have he : e c = c' := hO 0 + have hh := (NoiselessRegression.ambientSphereLaw_isometry e).map_eq + have hpre : e ⁻¹' Metric.closedBall c' r = Metric.closedBall c r := by + ext x + simp only [Set.mem_preimage, Metric.mem_closedBall, ← he, e.dist_map] + have h := congrArg (fun μ : Measure E => μ (Metric.closedBall c' r)) hh + rw [Measure.map_apply (by fun_prop) Metric.isClosed_closedBall.measurableSet, hpre] at h + exact h + +lemma sphere_finite_net {r : ℝ} (hr : 0 < r) : + ∃ s : Finset E, (∀ c ∈ s, ‖c‖ = 1) ∧ + (∀ c ∈ s, ∀ c' ∈ s, c ≠ c' → r < dist c c') ∧ + ∀ x : E, ‖x‖ = 1 → ∃ c ∈ s, dist x c ≤ r := by + classical + let N := ⌈((1+r/2)/(r/2))^Module.finrank ℝ E⌉₊ + obtain ⟨s,hs,hsep,hnet⟩ := NoiselessRegression.exists_net_of_finite_packing_bound + {x : E | ‖x‖ = 1} hr.le N (by + intro s hs hsep + have hh := NoiselessRegression.card_le_volume_ratio s hr (by norm_num : (0:ℝ) ≤ 1) + (fun c hc => (hs c hc).le) (fun c hc c' hc' hne => (hsep c hc c' hc' hne).le) + exact_mod_cast hh.trans (Nat.le_ceil _)) + exact ⟨s,hs,hsep,hnet⟩ + +lemma sphere_cap_lower_one [Nontrivial E] {c : E} (hc : ‖c‖ = 1) + {r : ℝ} (hr : 0 < r) (hr1 : r ≤ 1) : + ENNReal.ofReal (r^(Module.finrank ℝ E-1)) ≤ + ENNReal.ofReal ((8:ℝ)^Module.finrank ℝ E) * + NoiselessRegression.ambientSphereLaw (Metric.closedBall c r) := by + classical + let μ : Measure E := NoiselessRegression.ambientSphereLaw + obtain ⟨s,hs,hsep,hnet⟩ := sphere_finite_net (E := E) hr + have hcard := sphere_packing_bound s hr hr1 + (Module.finrank_pos (R := ℝ) (M := E)) hs + (fun x hx y hy hxy => (hsep x hx y hy hxy).le) + have hcover : μ (⋃ x ∈ s, Metric.closedBall x r) = 1 := by + rw [← measure_univ (μ := μ)] + apply measure_congr + filter_upwards [NoiselessRegression.ambientSphereLaw_ae_norm (E := E)] with x hx + apply propext + change (x ∈ ⋃ y ∈ s, Metric.closedBall y r) ↔ x ∈ Set.univ + simp only [Set.mem_univ, iff_true] + obtain ⟨y,hy,hxy⟩ := hnet x hx + exact Set.mem_iUnion₂.mpr ⟨y,hy,hxy⟩ + have hone : (1 : ℝ≥0∞) ≤ (s.card : ℝ≥0∞)*μ (Metric.closedBall c r) := by + calc + _ = μ (⋃ x ∈ s, Metric.closedBall x r) := hcover.symm + _ ≤ ∑ x ∈ s, μ (Metric.closedBall x r) := measure_biUnion_finset_le _ _ + _ = _ := by + have hm : ∀ x ∈ s, μ (Metric.closedBall x r) = μ (Metric.closedBall c r) := + fun x hx => sphere_cap_mass_center (hs x hx) hc r + simp_rw [Finset.sum_congr rfl hm] + simp + calc + _ = ENNReal.ofReal (r^(Module.finrank ℝ E-1))*1 := (mul_one _).symm + _ ≤ ENNReal.ofReal (r^(Module.finrank ℝ E-1))* + ((s.card : ℝ≥0∞)*μ (Metric.closedBall c r)) := mul_le_mul' le_rfl hone + _ = ENNReal.ofReal ((s.card:ℝ)*r^(Module.finrank ℝ E-1))* + μ (Metric.closedBall c r) := by + rw [ENNReal.ofReal_mul (by positivity), ENNReal.ofReal_natCast]; ring + _ ≤ _ := mul_le_mul' (ENNReal.ofReal_le_ofReal hcard) le_rfl + +lemma sphere_cap_lower [Nontrivial E] {c : E} (hc : ‖c‖ = 1) + {r : ℝ} (hr : 0 < r) (hr2 : r ≤ 2) : + ENNReal.ofReal (r^(Module.finrank ℝ E-1)) ≤ + ENNReal.ofReal ((16:ℝ)^Module.finrank ℝ E) * + NoiselessRegression.ambientSphereLaw (Metric.closedBall c r) := by + by_cases hr1 : r ≤ 1 + · exact (sphere_cap_lower_one hc hr hr1).trans (mul_le_mul' + (ENNReal.ofReal_le_ofReal (pow_le_pow_left₀ (by norm_num : (0:ℝ) ≤ 8) + (by norm_num : (8:ℝ) ≤ 16) _)) le_rfl) + · have h1 := sphere_cap_lower_one hc (by norm_num : (0:ℝ) < 1) le_rfl + simp only [one_pow, ENNReal.ofReal_one] at h1 + have h2 : r^(Module.finrank ℝ E-1) ≤ (2:ℝ)^Module.finrank ℝ E := + (pow_le_pow_left₀ hr.le hr2 _).trans + (pow_le_pow_right₀ (by norm_num) (Nat.sub_le _ _)) + calc + _ ≤ ENNReal.ofReal ((2:ℝ)^Module.finrank ℝ E)*1 := by + simpa using ENNReal.ofReal_le_ofReal h2 + _ ≤ ENNReal.ofReal ((2:ℝ)^Module.finrank ℝ E)* + (ENNReal.ofReal ((8:ℝ)^Module.finrank ℝ E)* + NoiselessRegression.ambientSphereLaw (Metric.closedBall c 1)) := mul_le_mul' le_rfl h1 + _ ≤ ENNReal.ofReal ((2:ℝ)^Module.finrank ℝ E)* + (ENNReal.ofReal ((8:ℝ)^Module.finrank ℝ E)* + NoiselessRegression.ambientSphereLaw (Metric.closedBall c r)) := by + gcongr + exact le_of_not_ge hr1 + _ = _ := by rw [← mul_assoc, ← ENNReal.ofReal_mul (by positivity), ← mul_pow]; norm_num + +end + +universe u +variable {E : Type u} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma cap_mass_pos [Nontrivial E] {c : E} (hc : ‖c‖ = 1) {r : ℝ} (hr : 0 < r) (hr2 : r ≤ 2) : + NoiselessRegression.ambientSphereLaw (Metric.closedBall c r) ≠ 0 := by + intro h + have hh := sphere_cap_lower hc hr hr2 + rw [h,mul_zero] at hh + exact (ENNReal.ofReal_pos.mpr (pow_pos hr _)).not_ge hh + +lemma capMeasure_probability [Nontrivial E] {c : E} (hc : ‖c‖ = 1) {r : ℝ} + (hr : 0 < r) (hr2 : r ≤ 2) : IsProbabilityMeasure (capMeasure c r) := by + constructor + simp only [capMeasure, Measure.smul_apply, Measure.restrict_apply_univ, smul_eq_mul] + exact ENNReal.inv_mul_cancel (cap_mass_pos hc hr hr2) (measure_ne_top _ _) + +lemma capMeasure_ac (c : E) (r : ℝ) : capMeasure c r ≪ NoiselessRegression.ambientSphereLaw := + Measure.smul_absolutelyContinuous.trans Measure.absolutelyContinuous_restrict + +lemma capMeasure_support (c : E) (r : ℝ) : (capMeasure c r).support ⊆ Metric.closedBall c r := by + intro x hx + have hh := (Measure.support_restrict_subset + (Measure.smul_absolutelyContinuous.support_mono hx)).1 + simpa only [Metric.isClosed_closedBall.closure_eq] using hh + +lemma reciprocal_scale {t : ℝ} (ht : 0 < t) (ht4 : t ≤ 1/4) : + ∃ j : ℕ, 4*t ≤ 1/((j:ℝ)+1) ∧ 1/((j:ℝ)+1) < 8*t := by + let n := ⌊1/(4*t)⌋₊ + have hx : 1 ≤ 1/(4*t) := (le_div_iff₀ (by positivity)).mpr (by linarith) + have hn : 1 ≤ n := (Nat.one_le_floor_iff _).mpr hx + have hnle : (n:ℝ) ≤ 1/(4*t) := Nat.floor_le (by positivity) + have hnlt : 1/(4*t) < (n:ℝ)+1 := Nat.lt_floor_add_one _ + have he : ((n-1:ℕ):ℝ)+1 = n := by exact_mod_cast (Nat.sub_add_cancel hn) + refine ⟨n-1, ?_, ?_⟩ + · rw [he] + rw [le_div_iff₀ (by exact_mod_cast (show 0 < n by omega))] + rw [le_div_iff₀ (by positivity)] at hnle + nlinarith + · rw [he, div_lt_iff₀ (by exact_mod_cast (show 0 < n by omega))] + rw [div_lt_iff₀ (by positivity)] at hnlt + have hnR : (1:ℝ) ≤ n := by exact_mod_cast hn + nlinarith + +lemma exists_capDictionary {c : E} (hc : ‖c‖ = 1) {r α : ℝ} + (hr : 0 < r) (hα : 1 ≤ α) : Nonempty (CapDictionary c r α) := by + classical + let ρ : ℕ → ℝ := fun j => r/((j:ℝ)+1) + have hρ : ∀ j, 0 < ρ j := fun j => div_pos hr (by positivity) + choose net hnetnorm hnetsep hnetcover using + (fun j : ℕ => sphere_finite_net (E := E) (half_pos (hρ j))) + let I := Option (Σ j : ℕ, {s : E // s ∈ net j}) + let center : I → E := fun i => match i with | none => c | some p => p.2.val + let radius : I → ℝ := fun i => match i with | none => r | some p => ρ p.1 + have hw (j : ℕ) : (r/ρ j)^α = ((j:ℝ)+1)^α := by + congr 1 + dsimp [ρ] + field_simp + have hproper : ∀ R : ℝ, {i : I | (r/radius i)^α ≤ R}.Finite := by + intro R + have hlevel (j : ℕ) : (j:ℝ) ≤ (r/ρ j)^α := by + rw [hw] + calc + _ ≤ (j:ℝ)+1 := by linarith + _ = ((j:ℝ)+1)^(1:ℝ) := (Real.rpow_one _).symm + _ ≤ _ := Real.rpow_le_rpow_of_exponent_le (by linarith [show (0:ℝ) ≤ j from Nat.cast_nonneg j]) hα + have hsubset : {i : I | (r/radius i)^α ≤ R} ⊆ + insert none (⋃ j ∈ Finset.range (⌈R⌉₊+1), Option.some '' + (Sigma.mk j '' (Set.univ : Set {s : E // s ∈ net j}))) := by + intro i hi + cases i with + | none => exact Set.mem_insert _ _ + | some p => + right + have hjR : (p.1:ℝ) ≤ R := (hlevel p.1).trans hi + have hj : p.1 ∈ Finset.range (⌈R⌉₊+1) := by + apply Finset.mem_range.mpr + have hh : p.1 ≤ ⌈R⌉₊ := by exact_mod_cast hjR.trans (Nat.le_ceil R) + omega + exact Set.mem_iUnion₂.mpr ⟨p.1,hj,⟨p,⟨p.2,Set.mem_univ _,rfl⟩,rfl⟩⟩ + apply Set.Finite.subset _ hsubset + apply Set.Finite.insert + apply Set.Finite.biUnion (Finset.finite_toSet _) + intro j hj + exact ((Set.toFinite (Set.univ : Set {s : E // s ∈ net j})).image (Sigma.mk j)).image Option.some + refine ⟨{ + I := I + countable := inferInstance + center := center + radius := radius + center_norm := ?_ + radius_pos := ?_ + radius_le := ?_ + parent := none + parent_center := rfl + parent_radius := rfl + proper := hproper + cover := ?_ }⟩ + · rintro (_|⟨j,s,hs⟩) + · exact hc + · exact hnetnorm j s hs + · rintro (_|⟨j,s⟩) + · exact hr + · exact hρ j + · rintro (_|⟨j,s⟩) + · exact le_rfl + · change r/((j:ℝ)+1) ≤ r + exact div_le_self hr.le (by linarith [show (0:ℝ) ≤ j from Nat.cast_nonneg j]) + · intro s hs t ht ht4 + obtain ⟨j,hj1,hj2⟩ := reciprocal_scale ht ht4 + obtain ⟨s',hs',hss'⟩ := hnetcover j s hs + refine ⟨some ⟨j,s',hs'⟩,?_,?_,hss'⟩ + · change 4*r*t ≤ r/((j:ℝ)+1) + have hh := mul_le_mul_of_nonneg_left hj1 hr.le + rw [mul_one_div] at hh + nlinarith only [hh] + · change r/((j:ℝ)+1) < 8*r*t + have hh := mul_lt_mul_of_pos_left hj2 hr + rw [mul_one_div] at hh + nlinarith only [hh] + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/FrameMoments.lean b/lean/OAI/Probability/ProjectionMoments/FrameMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..f1d0c27f85f1c537ca711397e45bd32e2cd6126d --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/FrameMoments.lean @@ -0,0 +1,316 @@ +import OAI.Probability.ProjectionMoments.SphereDensity + +namespace OAI + +noncomputable section + +open MeasureTheory +open scoped ENNReal NNReal +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments + +section +attribute [fun_prop] measurable_ballAverage +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma replicaConstant_real_le [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {ν : Measure E} (hν : ν Set.univ ≤ 1) {a : ℝ} {m : ℕ} + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) : + NoiselessRegression.replicaConstant ν a m ≤ (128 : ℝ≥0∞)^Module.finrank ℝ E := by + apply le_trans _ (NoiselessRegression.replicaConstant_le hν hd le_rfl hm) + have hr : (4 : ℝ)^a ≤ (4 : ℝ)^(Module.finrank ℝ E : ℝ) := + Real.rpow_le_rpow_of_exponent_le (by norm_num) ha + have hc : ENNReal.ofReal ((3 : ℝ)^Module.finrank ℝ E * 4^a) ≤ + ENNReal.ofReal ((3 : ℝ)^Module.finrank ℝ E * 4^(Module.finrank ℝ E : ℝ)) := + ENNReal.ofReal_le_ofReal (mul_le_mul_of_nonneg_left hr (by positivity)) + exact add_le_add le_rfl (mul_le_mul' hc le_rfl) + +theorem frame_moment_unit {ν : Measure E} [IsFiniteMeasure ν] {a : ℝ} + (hν : NoiselessRegression.HasLocalMassBound ν a) + (hs : ν.support ⊆ Metric.closedBall 0 1) (hmass : ν Set.univ ≤ 1) + {m n : ℕ} (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) (hmargin : (n : ℝ)+m ≤ a) + (u : Fin m → E) (hu : Orthonormal ℝ u) + (hac : ∀ᵐ A ∂frameLaw u, ν.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ))) : + ∫⁻ A, labelMoment ν m n A ∂frameLaw u ≤ + (2 : ℝ≥0∞)^m * ENNReal.ofReal (Real.sqrt (2 * Module.finrank ℝ E))^(m*n) * + (128 : ℝ≥0∞)^(Module.finrank ℝ E*n) := by + rw [← orbitMoment_eq_frame] + apply (frame_gaussian_comparison ν hm hd u hu hac).trans + apply mul_le_mul' le_rfl + apply (gaussian_labelMoment_bound hν hs m n hmargin).trans + simpa only [one_mul, pow_mul] using + mul_le_mul' hmass (pow_le_pow_left' (replicaConstant_real_le hmass hd ha hm) n) + +lemma lintegral_inv_smul_label {m : ℕ} (f : Label m → ℝ≥0∞) + (hf : Measurable f) {R : ℝ} (hR : 0 < R) : + ∫⁻ y, f (R⁻¹ • y) = ENNReal.ofReal (R^m) * ∫⁻ y, f y := by + rw [← lintegral_map hf (by fun_prop), Measure.map_addHaar_smul volume (inv_ne_zero hR.ne'), + finrank_euclideanSpace_fin, inv_pow, inv_inv, abs_of_nonneg (pow_nonneg hR.le m), + lintegral_smul_measure, smul_eq_mul] + +lemma ballAverage_label_scaled {ν : Measure E} [IsFiniteMeasure ν] + {K a : ℝ} (hK : 0 < K) (z : E) {R η : ℝ} (hR : 0 < R) (hη : 0 < η) + (m n : ℕ) (A : Fin m → E) : + (∫⁻ y : Label m, ballAverage ν m η (A,y)^(n+1)) = + (ENNReal.ofReal (K*R^(a-m)))^(n+1) * ENNReal.ofReal (R^m) * + ∫⁻ y : Label m, ballAverage (normalizedRescale ν K a z R) m (η/R) (A,y)^(n+1) := by + let μ := normalizedRescale ν K a z R + have : IsFiniteMeasure μ := normalizedRescale_finite ν K a z R (by positivity) + rw [← lintegral_add_left_eq_self (fun y : Label m => ballAverage ν m η (A,y)^(n+1)) (rowMap A z)] + simp_rw [ballAverage_normalizedRescale K a hK z hR hη, mul_pow] + rw [lintegral_const_mul _ (by fun_prop), lintegral_inv_smul_label (fun y : Label m => ballAverage (normalizedRescale ν K a z R) m (η/R) (A,y)^(n+1)) (by fun_prop) hR, + mul_assoc] + +theorem ballAverage_integrated_scaled {ν : Measure E} [IsFiniteMeasure ν] + {K a : ℝ} (hν : AllBallMass ν K a) (hK : 0 < K) + (z : E) {R η : ℝ} (hR : 0 < R) (hη : 0 < η) + (hs : ν.support ⊆ Metric.closedBall z R) + (m n : ℕ) (hmargin : (n : ℝ)+m ≤ a) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) : + ∫⁻ x : (Fin m → E) × Label m, ballAverage ν m η x^(n+1) + ∂(Measure.pi (fun _ => stdGaussian E)).prod volume ≤ + ENNReal.ofReal (K*R^(a-m))^(n+1) * ENNReal.ofReal (R^m) * + (128 : ℝ≥0∞)^(Module.finrank ℝ E*n) := by + let μ := normalizedRescale ν K a z R + have : IsFiniteMeasure μ := normalizedRescale_finite ν K a z R (by positivity) + rw [lintegral_prod _ (by fun_prop)] + simp_rw [ballAverage_label_scaled (ν := ν) (a := a) hK z hR hη m n] + rw [lintegral_const_mul _ (by fun_prop)] + apply mul_le_mul' le_rfl + rw [← lintegral_prod _ (show AEMeasurable (fun x : (Fin m → E) × Label m => + ballAverage μ m (η/R) x^(n+1)) _ by fun_prop)] + apply (ballAverage_integrated_moment (normalizedRescale_local hν hK z hR) + (normalizedRescale_support K a z hR hs) m n hmargin (div_pos hη hR)).trans + have hmass := normalizedRescale_mass hν hK z hR hs + simpa only [one_mul, pow_mul] using mul_le_mul' hmass + (pow_le_pow_left' (replicaConstant_real_le hmass hd ha hm) n) + +theorem lowerDensity_integrated_scaled {ν : Measure E} [IsFiniteMeasure ν] + {K a : ℝ} (hν : AllBallMass ν K a) (hK : 0 < K) + (z : E) {R : ℝ} (hR : 0 < R) (hs : ν.support ⊆ Metric.closedBall z R) + (m n : ℕ) (hmargin : (n : ℝ)+m ≤ a) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) : + ∫⁻ x : (Fin m → E) × Label m, lowerDensity ν m x^(n+1) + ∂(Measure.pi (fun _ => stdGaussian E)).prod volume ≤ + ENNReal.ofReal (K*R^(a-m))^(n+1) * ENNReal.ofReal (R^m) * + (128 : ℝ≥0∞)^(Module.finrank ℝ E*n) := by + have hp (v : ℕ → ℝ≥0∞) : (liminf v atTop)^(n+1) = + liminf (fun j => v j^(n+1)) atTop := + (show Monotone (fun x : ℝ≥0∞ => x^(n+1)) from + (fun _ _ h => pow_le_pow_left' h (n+1))).map_liminf_of_continuousAt + v (ENNReal.continuous_pow (n+1)).continuousAt + simp only [lowerDensity, hp] + apply (lintegral_liminf_le (fun j => (measurable_ballAverage ν m _).pow_const _)).trans + apply liminf_le_of_frequently_le' + exact Filter.Frequently.of_forall (fun j => ballAverage_integrated_scaled hν hK z hR + (inv_pos.mpr (by positivity)) hs m n hmargin hd ha hm) + +theorem gaussian_labelMoment_scaled {ν : Measure E} [IsFiniteMeasure ν] + {K a : ℝ} (hν : AllBallMass ν K a) (hK : 0 < K) + (z : E) {R : ℝ} (hR : 0 < R) (hs : ν.support ⊆ Metric.closedBall z R) + (m n : ℕ) (hmargin : (n : ℝ)+m ≤ a) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) : + ∫⁻ A, labelMoment ν m n A ∂Measure.pi (fun _ => stdGaussian E) ≤ + ENNReal.ofReal (K*R^(a-m))^(n+1) * ENNReal.ofReal (R^m) * + (128 : ℝ≥0∞)^(Module.finrank ℝ E*n) := by + have he (A : Fin m → E) : labelMoment ν m n A = + ∫⁻ y : Label m, lowerDensity ν m (A,y)^(n+1) := + (PiLp.volume_preserving_toLp (Fin m)).lintegral_comp + (show Measurable (fun y : Label m => lowerDensity ν m (A,y)^(n+1)) by fun_prop) + simp_rw [he] + rw [← lintegral_prod _ (show AEMeasurable (fun x : (Fin m → E) × Label m => + lowerDensity ν m x^(n+1)) _ by fun_prop)] + exact lowerDensity_integrated_scaled hν hK z hR hs m n hmargin hd ha hm + +theorem frame_moment_scaled {ν : Measure E} [IsFiniteMeasure ν] + {K a : ℝ} (hν : AllBallMass ν K a) (hK : 0 < K) + (z : E) {R : ℝ} (hR : 0 < R) (hs : ν.support ⊆ Metric.closedBall z R) + (m n : ℕ) (hmargin : (n : ℝ)+m ≤ a) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hm : m ≤ Module.finrank ℝ E) (u : Fin m → E) (hu : Orthonormal ℝ u) + (hac : ∀ᵐ A ∂frameLaw u, ν.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ))) : + ∫⁻ A, labelMoment ν m n A ∂frameLaw u ≤ + (2 : ℝ≥0∞)^m * ENNReal.ofReal (Real.sqrt (2*Module.finrank ℝ E))^(m*n) * + (ENNReal.ofReal (K*R^(a-m))^(n+1) * ENNReal.ofReal (R^m) * + (128 : ℝ≥0∞)^(Module.finrank ℝ E*n)) := by + rw [← orbitMoment_eq_frame] + exact (frame_gaussian_comparison ν hm hd u hu hac).trans + (mul_le_mul' le_rfl (gaussian_labelMoment_scaled hν hK z hR hs m n hmargin hd ha hm)) + +end + +lemma frame_cost_power {d m n : ℕ} (hd : 1 ≤ d) (hm : m ≤ d) + (a K R : ℝ) (hK : 0 ≤ K) (hR : 0 < R) : + (2 : ℝ)^m * (Real.sqrt (2*d))^(m*n) * + ((K*R^(a-m))^(n+1) * R^m * (128 : ℝ)^(d*n)) ≤ + ((256 : ℝ)^d * (256*Real.sqrt d)^((m:ℝ)*(1-1/((n:ℝ)+1))) * K * + R^(a-(m:ℝ)*(1-1/((n:ℝ)+1))))^(n+1) := by + have hq : (n : ℝ)+1 ≠ 0 := by positivity + have hexp : ((m:ℝ)*(1-1/((n:ℝ)+1)))*((n:ℝ)+1) = (m*n:ℕ) := by + push_cast + field_simp + ring + have hRexp : (a-(m:ℝ)*(1-1/((n:ℝ)+1)))*((n:ℝ)+1) = + (a-m)*((n:ℝ)+1)+m := by + field_simp + ring + have hscale : (K*R^(a-m))^(n+1)*R^m = + K^(n+1)*R^((a-(m:ℝ)*(1-1/((n:ℝ)+1)))*((n:ℝ)+1)) := by + rw [mul_pow, mul_assoc, ← Real.rpow_mul_natCast hR.le, + ← Real.rpow_natCast R m, ← Real.rpow_add hR] + congr 2 + rw [Nat.cast_add, Nat.cast_one, hRexp] + have h2 : (2 : ℝ)^m ≤ 256^d := by + apply (pow_le_pow_left₀ (by norm_num) (by norm_num : (2 : ℝ) ≤ 256) m).trans + exact pow_le_pow_right₀ (by norm_num) hm + have h128 : (128 : ℝ)^(d*n) ≤ 256^(d*n) := + pow_le_pow_left₀ (by norm_num) (by norm_num) (d*n) + have hcoef : (2 : ℝ)^m * 128^(d*n) ≤ 256^(d*(n+1)) := by + apply (mul_le_mul h2 h128 (by positivity) (by positivity)).trans_eq + rw [← pow_add] + congr 1 + ring + have hsqrt : Real.sqrt (2*d) ≤ 256*Real.sqrt d := by + rw [Real.sqrt_mul (by norm_num)] + apply mul_le_mul_of_nonneg_right _ (Real.sqrt_nonneg _) + exact (Real.sqrt_le_iff.mpr ⟨by norm_num, by norm_num⟩) + have hS : ((256 : ℝ)^d * (256*Real.sqrt d)^((m:ℝ)*(1-1/((n:ℝ)+1))) * K * + R^(a-(m:ℝ)*(1-1/((n:ℝ)+1))))^(n+1) = + 256^(d*(n+1)) * (256*Real.sqrt d)^(m*n) * + (K^(n+1)*R^((a-(m:ℝ)*(1-1/((n:ℝ)+1)))*((n:ℝ)+1))) := by + simp only [mul_pow] + rw [← pow_mul, ← Real.rpow_mul_natCast (by positivity), + ← Real.rpow_mul_natCast hR.le] + simp only [Nat.cast_add, Nat.cast_one] + rw [hexp, Real.rpow_natCast] + ring + rw [hS] + calc + _ = (2^m*128^(d*n))*(Real.sqrt (2*d))^(m*n) * + (K^(n+1)*R^((a-(m:ℝ)*(1-1/((n:ℝ)+1)))*((n:ℝ)+1))) := by + rw [← hscale] + ring + _ ≤ _ := mul_le_mul_of_nonneg_right + (mul_le_mul hcoef (pow_le_pow_left₀ (Real.sqrt_nonneg _) hsqrt (m*n)) + (by positivity) (by positivity)) (by positivity) + +lemma ennreal_root_bound {q : ℕ} (hq : q ≠ 0) {v : ℝ≥0∞} {B : ℝ} + (hB : 0 ≤ B) (h : v ≤ ENNReal.ofReal B ^ q) : + v ^ (1/(q:ℝ)) ≤ ENNReal.ofReal B := by + have hq' : (q : ℝ) ≠ 0 := Nat.cast_ne_zero.mpr hq + have hh := ENNReal.rpow_le_rpow h (by positivity : 0 ≤ 1/(q:ℝ)) + rwa [← ENNReal.ofReal_pow hB, + ENNReal.ofReal_rpow_of_nonneg (pow_nonneg hB q) (by positivity), + ← Real.rpow_natCast_mul hB, mul_one_div_cancel hq', Real.rpow_one] at hh + +lemma frame_cost_root {d m n : ℕ} (hd : 1 ≤ d) (hm : m ≤ d) + (a K R : ℝ) (hK : 0 ≤ K) (hR : 0 < R) {v : ℝ≥0∞} + (h : v ≤ (2 : ℝ≥0∞)^m * ENNReal.ofReal (Real.sqrt (2*d))^(m*n) * + (ENNReal.ofReal (K*R^(a-m))^(n+1) * ENNReal.ofReal (R^m) * + (128 : ℝ≥0∞)^(d*n))) : + v ^ (1/((n:ℝ)+1)) ≤ + ENNReal.ofReal ((256 : ℝ)^d * (256*Real.sqrt d)^((m:ℝ)*(1-1/((n:ℝ)+1))) * K * + R^(a-(m:ℝ)*(1-1/((n:ℝ)+1)))) := by + have hb := ENNReal.ofReal_le_ofReal (frame_cost_power (n := n) hd hm a K R hK hR) + simp (discharger := positivity) only [ENNReal.ofReal_mul, ENNReal.ofReal_pow, + ENNReal.ofReal_ofNat] at hb + simp (discharger := positivity) only [ENNReal.ofReal_mul, ENNReal.ofReal_pow] at h + have hB : 0 ≤ (256 : ℝ)^d * (256*Real.sqrt d)^((m:ℝ)*(1-1/((n:ℝ)+1))) * K * + R^(a-(m:ℝ)*(1-1/((n:ℝ)+1))) := by positivity + have hb' : v ≤ (ENNReal.ofReal ((256 : ℝ)^d * + (256*Real.sqrt d)^((m:ℝ)*(1-1/((n:ℝ)+1))) * K * + R^(a-(m:ℝ)*(1-1/((n:ℝ)+1)))))^(n+1) := by + simp (discharger := positivity) only [ENNReal.ofReal_mul, ENNReal.ofReal_pow, + ENNReal.ofReal_ofNat] + exact h.trans hb + have hh := ennreal_root_bound (show n+1 ≠ 0 by omega) hB hb' + simpa only [Nat.cast_add, Nat.cast_one] using hh + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [BorelSpace E] in +lemma measure_eq_zero_of_allBall_zero [BorelSpace E] {ν : Measure E} {a : ℝ} + (hν : AllBallMass ν 0 a) (z : E) {R : ℝ} (hR : 0 < R) + (hs : ν.support ⊆ Metric.closedBall z R) : ν = 0 := by + apply Measure.measure_univ_eq_zero.mp + have he : ν Set.univ = ν (Metric.closedBall z R) := by + apply measure_congr + filter_upwards [ν.support_mem_ae] with x hx + exact propext (iff_of_true (Set.mem_univ x) (hs hx)) + rw [he] + apply le_antisymm _ bot_le + simpa using hν z R hR + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[simp] lemma lowerDensity_zero [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] (m : ℕ) (x : (Fin m → E) × Label m) : + lowerDensity (0 : Measure E) m x = 0 := by + simp [lowerDensity, ballAverage, vectorSmoothing] + +@[simp] lemma coordinateDensity_zero (m : ℕ) (x : (Fin m → E) × (Fin m → ℝ)) : + coordinateDensity (0 : Measure E) m x = 0 := lowerDensity_zero m _ + +lemma coordinateDensity_frame_support (ν : Measure E) [IsFiniteMeasure ν] {m : ℕ} + (z : E) {R : ℝ} (hR : 0 ≤ R) (hs : ν.support ⊆ Metric.closedBall z R) + (A : Fin m → E) (hA : Orthonormal ℝ A) (y : Fin m → ℝ) + (hy : R < ‖WithLp.toLp 2 (y-coordinateMap A z)‖) : + coordinateDensity ν m (A,y) = 0 := by + apply lowerDensity_eq_zero_of_far ν m A z R (WithLp.toLp 2 y) hs + have he : WithLp.toLp 2 (y-coordinateMap A z) = WithLp.toLp 2 y - rowMap A z := rfl + rw [he] at hy + exact (show ‖rowMap A‖ * R ≤ R from by nlinarith [norm_rowMap_le hA]).trans_lt hy + +theorem integrated_frame_moment : + ∃ C : ℝ, 1 ≤ C ∧ ∀ (d k q : ℕ) (β K R : ℝ) + (ν : Measure (EuclideanSpace ℝ (Fin d))) [IsFiniteMeasure ν] + (z : EuclideanSpace ℝ (Fin d)) (u : Fin k → EuclideanSpace ℝ (Fin d)), + 1 ≤ k → 2 ≤ q → k+q ≤ d → 0 < β → β ≤ d → + 1 ≤ β-k-((q:ℝ)-2) → 0 ≤ K → 0 < R → + ν.support ⊆ Metric.closedBall z R → AllBallMass ν K β → + Orthonormal ℝ u → + (∀ᵐ A ∂frameLaw u, ν.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ))) → + Measurable (coordinateDensity ν k) ∧ + (∀ᵐ A ∂frameLaw u, + (volume : Measure (Fin k → ℝ)).withDensity (fun y => coordinateDensity ν k (A,y)) = + ν.map (coordinateMap A)) ∧ + (∀ (A : Fin k → EuclideanSpace ℝ (Fin d)), Orthonormal ℝ A → + ∀ y : Fin k → ℝ, + R < ‖WithLp.toLp 2 (y-coordinateMap A z)‖ → coordinateDensity ν k (A,y) = 0) ∧ + (∫⁻ A, ∫⁻ y : Fin k → ℝ, coordinateDensity ν k (A,y)^q ∂volume ∂frameLaw u) ^ (1/(q:ℝ)) ≤ + ENNReal.ofReal (C^d * (C*Real.sqrt d)^((k:ℝ)*(1-1/(q:ℝ))) * + K * R^(β-(k:ℝ)*(1-1/(q:ℝ)))) := by + refine ⟨256, by norm_num, ?_⟩ + intro d k q β K R ν _ z u hk hq hdim hβ hβd hmargin hK hR hs hν hu hac + refine ⟨measurable_coordinateDensity ν k, ?_, ?_, ?_⟩ + · filter_upwards [hac] with A hA + exact coordinateDensity_is_density ν k A hA + · intro A hA y hy + exact coordinateDensity_frame_support ν z hR.le hs A hA y hy + · rcases eq_or_lt_of_le hK with hK0 | hK0 + · have hzero : ν = 0 := measure_eq_zero_of_allBall_zero (hK0 ▸ hν) z hR hs + subst ν + simp only [coordinateDensity_zero, zero_pow (by omega : q ≠ 0), lintegral_zero] + rw [ENNReal.zero_rpow_of_pos (by positivity : 0 < 1/(q:ℝ))] + exact bot_le + · have hn : q-1+1 = q := by omega + have hnR : ((q-1:ℕ):ℝ)+1 = q := by exact_mod_cast hn + have hmm : ((q-1:ℕ):ℝ)+k ≤ β := by linarith + have h := frame_moment_scaled hν hK0 z hR hs k (q-1) hmm + (by simpa using (show 1 ≤ d by omega)) (by simpa using hβd) + (by simpa using (show k ≤ d by omega)) u hu hac + have ht := frame_cost_root (d := d) (m := k) (n := q-1) (by omega) (by omega) + β K R hK hR (by simpa only [finrank_euclideanSpace_fin] using h) + simpa only [labelMoment, hn, hnR] using ht + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Frames.lean b/lean/OAI/Probability/ProjectionMoments/Frames.lean new file mode 100644 index 0000000000000000000000000000000000000000..af1eba83d62b70e0007a899a73cd0cced86c32ed --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Frames.lean @@ -0,0 +1,390 @@ +import OAI.Probability.ProjectionMoments.GaussianDensity + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace ProjectionMoments +attribute [fun_prop] measurable_lowerDensity + +section Rotations +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + +instance rotationLaw_probability : IsProbabilityMeasure (rotationLaw E) := by + constructor + simp only [rotationLaw, Measure.smul_apply, smul_eq_mul] + exact ENNReal.inv_mul_cancel ((ne_of_gt (isOpen_univ.measure_pos (Measure.haar : Measure (Rotation E)) Set.univ_nonempty))) (measure_ne_top _ _) + +instance rotationLaw_haar : (rotationLaw E).IsHaarMeasure := by + unfold rotationLaw + apply Measure.IsHaarMeasure.smul _ + · exact ENNReal.inv_ne_zero.mpr (measure_ne_top _ _) + · exact ENNReal.inv_ne_top.mpr (ne_of_gt (isOpen_univ.measure_pos (Measure.haar : Measure (Rotation E)) Set.univ_nonempty)) + +instance rotationLaw_right : (rotationLaw E).IsMulRightInvariant := by + constructor + intro Q + let μ := (rotationLaw E).map (fun O => O * Q) + have hprob : IsProbabilityMeasure μ := inferInstance + have he := Measure.isMulInvariant_eq_smul_of_compactSpace μ (rotationLaw E) + have hc := congrArg (fun ν : Measure (Rotation E) => ν Set.univ) he + simp only [Measure.smul_apply, measure_univ, ENNReal.smul_def, smul_eq_mul, mul_one] at hc + have hc' : Measure.haarScalarFactor μ (rotationLaw E) = 1 := + ENNReal.coe_injective hc.symm + simpa [hc'] using he + +variable {E} + +lemma rotation_transitive {ι : Type*} [Fintype ι] {u v : ι → E} + (hu : Orthonormal ℝ u) (hv : Orthonormal ℝ v) : + ∃ O : Rotation E, ∀ i, (O : E →L[ℝ] E) (u i) = v i := by + classical + let U := Submodule.span ℝ (Set.range u) + let V := Submodule.span ℝ (Set.range v) + let bu : OrthonormalBasis ι ℝ U := (Module.Basis.span hu.linearIndependent).toOrthonormalBasis + (by convert! orthonormal_span hu using 1; ext i; simp) + let bv : OrthonormalBasis ι ℝ V := (Module.Basis.span hv.linearIndependent).toOrthonormalBasis + (by convert! orthonormal_span hv using 1; ext i; simp) + let e : U ≃ₗᵢ[ℝ] V := bu.repr.trans bv.repr.symm + let L : U →ₗᵢ[ℝ] E := V.subtypeₗᵢ.comp e.toLinearIsometry + let O : E ≃ₗᵢ[ℝ] E := L.extend.toLinearIsometryEquiv rfl + refine ⟨Unitary.linearIsometryEquiv.symm O, ?_⟩ + intro i + change O (u i) = v i + change L.extend (u i) = v i + have he : e (bu i) = bv i := by + simp only [e, LinearIsometryEquiv.trans_apply, OrthonormalBasis.repr_self, + OrthonormalBasis.repr_symm_single] + have hbui : (bu i : E) = u i := by simp [bu, Module.Basis.span_apply] + have hbvi : (bv i : E) = v i := by simp [bv, Module.Basis.span_apply] + rw [← hbui, LinearIsometry.extend_apply] + change (e (bu i) : E) = _ + rw [he, hbvi] + +variable [MeasurableSpace E] [BorelSpace E] + +lemma measurable_rotateRows {ι : Type*} [Fintype ι] : + Measurable (fun z : Rotation E × (ι → E) => rotateRows z.1 z.2) := by + apply Continuous.measurable + apply continuous_pi + intro i + exact (continuous_subtype_val.comp continuous_fst).clm_apply (continuous_apply i |>.comp continuous_snd) + +@[fun_prop] lemma measurable_rotateRows_left {ι : Type*} [Fintype ι] (v : ι → E) : + Measurable (fun O : Rotation E => rotateRows O v) := + measurable_rotateRows.comp (measurable_id.prodMk measurable_const) + +@[fun_prop] lemma measurable_rotateRows_right {ι : Type*} [Fintype ι] (O : Rotation E) : + Measurable (fun v : ι → E => rotateRows O v) := + measurable_rotateRows.comp (measurable_const.prodMk measurable_id) + +omit [MeasurableSpace E] [BorelSpace E] in +lemma rotateRows_mul [MeasurableSpace E] [BorelSpace E] {ι : Type*} (O Q : Rotation E) (v : ι → E) : + rotateRows (O*Q) v = rotateRows O (rotateRows Q v) := rfl + +lemma rotationLaw_orbit_eq {ι : Type*} [Fintype ι] {u v : ι → E} + (hu : Orthonormal ℝ u) (hv : Orthonormal ℝ v) : + (rotationLaw E).map (fun O => rotateRows O u) = + (rotationLaw E).map (fun O => rotateRows O v) := by + obtain ⟨Q, hQ⟩ := rotation_transitive hu hv + have he : rotateRows Q u = v := funext hQ + have hm : Measurable (fun O : Rotation E => rotateRows O u) := + measurable_rotateRows.comp (measurable_id.prodMk measurable_const) + rw [← he] + conv_lhs => rw [← (measurePreserving_mul_right (rotationLaw E) Q).map_eq] + rw [Measure.map_map hm (by fun_prop)] + rfl + +lemma gaussianRows_rotation_invariant (m : ℕ) (O : Rotation E) : + (Measure.pi (fun _ : Fin m => stdGaussian E)).map (rotateRows O) = + Measure.pi (fun _ : Fin m => stdGaussian E) := by + change (Measure.pi (fun _ : Fin m => stdGaussian E)).map + (fun v i => O.val (v i)) = _ + rw [Measure.pi_map_pi (f := fun _ : Fin m => (O.val : E →L[ℝ] E)) + (fun _ => O.val.continuous.measurable.aemeasurable)] + congr 1 + funext j + exact stdGaussian_map (Unitary.linearIsometryEquiv O) + +end Rotations + +section Triangular +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[simp] lemma coordinateMap_apply [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {m : ℕ} (A : Fin m → E) (x : E) (i : Fin m) : + coordinateMap A x i = ⟪x, A i⟫ := by + change WithLp.ofLp (rowMap A x) i = _ + rw [rowMap_apply] + +def rowJacobian {m : ℕ} (A : Fin m → E) : ℝ := + ∏ i, ‖gramSchmidt ℝ A i‖ + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma rowJacobian_pos [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {m : ℕ} {A : Fin m → E} (hA : LinearIndependent ℝ A) : + 0 < rowJacobian A := Finset.prod_pos (fun i _ => norm_pos_iff.mpr (gramSchmidt_ne_zero i hA)) + +lemma rows_factor {m : ℕ} (A : Fin m → E) (hA : LinearIndependent ℝ A) : + ∃ u : Fin m → E, Orthonormal ℝ u ∧ + ∃ T : (Fin m → ℝ) ≃L[ℝ] (Fin m → ℝ), + (∀ x, coordinateMap A x = T (coordinateMap u x)) ∧ + (volume : Measure (Fin m → ℝ)).map T = + (ENNReal.ofReal (rowJacobian A))⁻¹ • volume := by + let u := gramSchmidtNormed ℝ A + let R : Matrix (Fin m) (Fin m) ℝ := + Matrix.diagonal (fun i => ‖gramSchmidt ℝ A i‖) * NoiselessRegression.gsUpper m A + have hu : Orthonormal ℝ u := gramSchmidtNormed_orthonormal hA + have hn (i : Fin m) : ‖gramSchmidt ℝ A i‖ ≠ 0 := + norm_ne_zero_iff.mpr (gramSchmidt_ne_zero i hA) + have hexp (j : Fin m) : ∑ i, R i j • u i = A j := by + rw [← NoiselessRegression.gsUpper_expansion m A j] + apply Finset.sum_congr rfl + intro i _ + simp only [R, u, Matrix.diagonal_mul, gramSchmidtNormed, smul_smul] + congr 1 + simp [hn i, mul_comm] + have hdet : R.transpose.det = rowJacobian A := by + dsimp only [R, rowJacobian] + rw [Matrix.det_transpose, Matrix.det_mul, Matrix.det_diagonal, + NoiselessRegression.gsUpper_det, mul_one] + have hd : R.transpose.det ≠ 0 := by rw [hdet]; exact (rowJacobian_pos hA).ne' + let T := (R.transpose.toLinearEquiv' (Matrix.invertibleOfIsUnitDet R.transpose (isUnit_iff_ne_zero.mpr hd))).toContinuousLinearEquiv + refine ⟨u, hu, T, ?_, ?_⟩ + · intro x + ext j + rw [coordinateMap_apply, ← hexp j] + change ⟪x, ∑ i, R i j • u i⟫ = Matrix.mulVec R.transpose (coordinateMap u x) j + simp only [inner_sum, inner_smul_right, Matrix.mulVec, dotProduct, + Matrix.transpose_apply, coordinateMap_apply] + · change (volume : Measure (Fin m → ℝ)).map (Matrix.toLin' R.transpose) = _ + rw [Real.map_matrix_volume_pi_eq_smul_volume_pi hd, + abs_of_pos (inv_pos.mpr (by rw [hdet]; exact rowJacobian_pos hA)), hdet, + ENNReal.ofReal_inv_of_pos (rowJacobian_pos hA)] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma norm_rowMap_le [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {m : ℕ} {u : Fin m → E} (hu : Orthonormal ℝ u) : + ‖rowMap u‖ ≤ 1 := by + apply (rowMap u).opNorm_le_bound zero_le_one + intro x + rw [one_mul] + have h := hu.sum_inner_products_le (x := x) (s := Finset.univ) + apply (sq_le_sq₀ (norm_nonneg (rowMap u x)) (norm_nonneg x)).mp + rw [EuclideanSpace.real_norm_sq_eq] + simpa only [rowMap_apply, Real.norm_eq_abs, sq_abs, + WithLp.ofLp_toLp, real_inner_comm] using h + +omit [MeasurableSpace E] [BorelSpace E] in +lemma rowJacobian_le [MeasurableSpace E] [BorelSpace E] {m : ℕ} (A : Fin m → E) : + rowJacobian A ≤ ∏ i, ‖A i‖ := by + apply Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) (fun i _ => ?_) + rw [NoiselessRegression.norm_gramSchmidt_eq_infDist] + simpa only [dist_zero_right] using + Metric.infDist_le_dist_of_mem (x := A i) (Submodule.zero_mem (Submodule.span ℝ (A '' Set.Iio i))) + +lemma coordinateMap_rotateRows {m : ℕ} (O : Rotation E) (A : Fin m → E) (x : E) : + coordinateMap (rotateRows O A) x = + coordinateMap A ((Unitary.linearIsometryEquiv O).symm x) := by + ext i + simp only [coordinateMap_apply, rotateRows] + calc + _ = ⟪(Unitary.linearIsometryEquiv O) (A i), x⟫ := real_inner_comm _ _ + _ = ⟪A i, (Unitary.linearIsometryEquiv O).symm x⟫ := + LinearIsometryEquiv.inner_map_eq_flip _ _ _ + _ = _ := real_inner_comm _ _ + +end Triangular + +section CoordinateDensity +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] + +@[fun_prop] lemma measurable_coordinateDensity (ν : Measure E) [SFinite ν] (m : ℕ) : + Measurable (coordinateDensity ν m) := by + exact (measurable_lowerDensity ν m).comp (by fun_prop) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma rowMap_eq_toLp_coordinateMap [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {m : ℕ} (A : Fin m → E) : + (rowMap A : E → Label m) = (WithLp.toLp 2) ∘ coordinateMap A := rfl + +lemma coordinateDensity_is_density (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) + (A : Fin m → E) (hA : ν.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ))) : + volume.withDensity (fun y => coordinateDensity ν m (A,y)) = ν.map (coordinateMap A) := by + have hr : ν.map (rowMap A) ≪ (volume : Measure (Label m)) := by + rw [rowMap_eq_toLp_coordinateMap, ← Measure.map_map (by fun_prop) (by fun_prop), + ← (PiLp.volume_preserving_toLp (Fin m)).map_eq] + exact hA.map (by fun_prop) + have h := congrArg (fun μ : Measure (Label m) => μ.map (MeasurableEquiv.toLp 2 (Fin m → ℝ)).symm) + (lowerDensity_is_density ν m A hr) + rw [map_withDensity_equiv _ _ _ (by fun_prop), + (EuclideanSpace.volume_preserving_symm_measurableEquiv_toLp (Fin m)).map_eq, + Measure.map_map (by fun_prop) (by fun_prop)] at h + exact h + +def labelMoment (ν : Measure E) (m n : ℕ) (A : Fin m → E) : ℝ≥0∞ := + ∫⁻ y, coordinateDensity ν m (A,y)^(n+1) + +@[fun_prop] lemma measurable_labelMoment (ν : Measure E) [SFinite ν] (m n : ℕ) : + Measurable (labelMoment ν m n) := by + exact Measurable.lintegral_prod_right (by fun_prop) + +lemma labelMoment_factor (ν : Measure E) [IsFiniteMeasure ν] {m n : ℕ} + (A u : Fin m → E) (T : (Fin m → ℝ) ≃L[ℝ] (Fin m → ℝ)) + (hf : ∀ x, coordinateMap A x = T (coordinateMap u x)) + (c : ℝ≥0∞) (hc0 : c ≠ 0) (hct : c ≠ ∞) + (hT : (volume : Measure (Fin m → ℝ)).map T = c • volume) + (hu : ν.map (coordinateMap u) ≪ (volume : Measure (Fin m → ℝ))) : + labelMoment ν m n A = c^n * labelMoment ν m n u := by + have he : ν.map (coordinateMap A) = (ν.map (coordinateMap u)).map T := by + rw [Measure.map_map (by fun_prop) (by fun_prop)] + congr 1 + exact funext hf + have ha : ν.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ)) := by + rw [he] + have h := hu.map T.continuous.measurable + rw [hT] at h + exact h.trans Measure.smul_absolutelyContinuous + apply density_moment_equiv volume T.toHomeomorph.toMeasurableEquiv c hc0 hct hT + (by fun_prop) (by fun_prop) + rw [coordinateDensity_is_density ν m A ha, coordinateDensity_is_density ν m u hu, he] + rfl + +end CoordinateDensity + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +instance frameLaw_probability {m : ℕ} (u : Fin m → E) : IsProbabilityMeasure (frameLaw u) := + inferInstanceAs (IsProbabilityMeasure ((rotationLaw E).map (fun O => rotateRows O u))) + +lemma frameLaw_eq {m : ℕ} {u v : Fin m → E} (hu : Orthonormal ℝ u) (hv : Orthonormal ℝ v) : + frameLaw u = frameLaw v := rotationLaw_orbit_eq hu hv + +def orbitMoment (ν : Measure E) (m n : ℕ) (A : Fin m → E) : ℝ≥0∞ := + ∫⁻ O, labelMoment ν m n (rotateRows O A) ∂rotationLaw E + +@[fun_prop] lemma measurable_orbitMoment (ν : Measure E) [SFinite ν] (m n : ℕ) : + Measurable (orbitMoment ν m n) := by + apply Measurable.lintegral_prod_right + exact (measurable_labelMoment ν m n).comp (measurable_rotateRows.comp measurable_swap) + +lemma orbitMoment_eq_frame (ν : Measure E) [SFinite ν] (m n : ℕ) (u : Fin m → E) : + orbitMoment ν m n u = ∫⁻ A, labelMoment ν m n A ∂frameLaw u := by + rw [frameLaw, lintegral_map (measurable_labelMoment ν m n) (measurable_rotateRows_left u)] + rfl + +lemma orbitMoment_factor (ν : Measure E) [IsFiniteMeasure ν] {m n : ℕ} + (u : Fin m → E) (hu : Orthonormal ℝ u) + (hac : ∀ᵐ A ∂frameLaw u, ν.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ))) + (A : Fin m → E) (hA : LinearIndependent ℝ A) : + orbitMoment ν m n A = (ENNReal.ofReal (rowJacobian A))⁻¹ ^ n * orbitMoment ν m n u := by + obtain ⟨v, hv, T, hT, hvol⟩ := rows_factor A hA + have hacv : ∀ᵐ O ∂rotationLaw E, + ν.map (coordinateMap (rotateRows O v)) ≪ (volume : Measure (Fin m → ℝ)) := by + apply ae_of_ae_map (p := fun B : Fin m → E => ν.map (coordinateMap B) ≪ (volume : Measure (Fin m → ℝ))) + (measurable_rotateRows_left v).aemeasurable + change ∀ᵐ B ∂frameLaw v, _ + rwa [← frameLaw_eq hu hv] + have hi : orbitMoment ν m n A = + (ENNReal.ofReal (rowJacobian A))⁻¹ ^ n * orbitMoment ν m n v := by + unfold orbitMoment + rw [← lintegral_const_mul _ (by fun_prop)] + apply lintegral_congr_ae + filter_upwards [hacv] with O hO + apply labelMoment_factor ν (rotateRows O A) (rotateRows O v) T + (fun x => ?_) ((ENNReal.ofReal (rowJacobian A))⁻¹) (by simp) + (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr (rowJacobian_pos hA))) hvol hO + rw [coordinateMap_rotateRows, coordinateMap_rotateRows, hT] + rw [hi, orbitMoment_eq_frame, ← frameLaw_eq hu hv, ← orbitMoment_eq_frame] + +lemma gaussian_lintegral_orbitMoment (ν : Measure E) [SFinite ν] (m n : ℕ) : + ∫⁻ A, orbitMoment ν m n A ∂Measure.pi (fun _ => stdGaussian E) = + ∫⁻ A, labelMoment ν m n A ∂Measure.pi (fun _ => stdGaussian E) := by + unfold orbitMoment + rw [lintegral_lintegral_swap (by + exact ((measurable_labelMoment ν m n).comp (measurable_rotateRows.comp measurable_swap)).aemeasurable)] + have hi (O : Rotation E) : + ∫⁻ A, labelMoment ν m n (rotateRows O A) ∂Measure.pi (fun _ => stdGaussian E) = + ∫⁻ A, labelMoment ν m n A ∂Measure.pi (fun _ => stdGaussian E) := by + rw [← lintegral_map (measurable_labelMoment ν m n) (measurable_rotateRows_right O), + gaussianRows_rotation_invariant] + simp_rw [hi] + simp + +lemma gaussian_labelMoment_bound {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : NoiselessRegression.HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (m n : ℕ) (hmargin : (n : ℝ) + m ≤ a) : + ∫⁻ A, labelMoment ν m n A ∂Measure.pi (fun _ => stdGaussian E) ≤ + ν Set.univ * (NoiselessRegression.replicaConstant ν a m)^n := by + have he (A : Fin m → E) : labelMoment ν m n A = + ∫⁻ y : Label m, lowerDensity ν m (A,y)^(n+1) := + (PiLp.volume_preserving_toLp (Fin m)).lintegral_comp + (show Measurable (fun y : Label m => lowerDensity ν m (A,y)^(n+1)) by fun_prop) + simp_rw [he] + rw [← lintegral_prod _ (show AEMeasurable (fun z : (Fin m → E) × Label m => lowerDensity ν m z^(n+1)) _ by fun_prop)] + exact lowerDensity_integrated_moment hν hsupport m n hmargin + +theorem frame_gaussian_comparison (ν : Measure E) [IsFiniteMeasure ν] + {m n : ℕ} (hm : m ≤ Module.finrank ℝ E) (hd : 0 < Module.finrank ℝ E) + (u : Fin m → E) (hu : Orthonormal ℝ u) + (hac : ∀ᵐ A ∂frameLaw u, ν.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ))) : + orbitMoment ν m n u ≤ + (2 : ℝ≥0∞)^m * ENNReal.ofReal (Real.sqrt (2 * Module.finrank ℝ E))^(m*n) * + ∫⁻ A, labelMoment ν m n A ∂Measure.pi (fun _ => stdGaussian E) := by + let γ : Measure (Fin m → E) := Measure.pi (fun _ => stdGaussian E) + let t : ℝ := Real.sqrt (2 * Module.finrank ℝ E) + let G : Set (Fin m → E) := Set.univ.pi (fun _ => Metric.closedBall (0 : E) t) + have ht : 0 < t := Real.sqrt_pos.mpr (by exact_mod_cast (show 0 < 2 * Module.finrank ℝ E by omega)) + have hG : MeasurableSet G := MeasurableSet.univ_pi (fun _ => measurableSet_closedBall) + have hGmass : (2 : ℝ≥0∞)⁻¹^m ≤ γ G := by + rw [show γ G = ∏ _ : Fin m, stdGaussian E (Metric.closedBall 0 t) from Measure.pi_pi _ _] + simpa only [Finset.prod_const, Finset.card_univ, Fintype.card_fin] using + Finset.prod_le_prod (s := Finset.univ) (fun (_ : Fin m) _ => gaussian_norm_ball_mass (E := E) hd) + let B : ℝ≥0∞ := ENNReal.ofReal t ^ m + have hB0 : B ≠ 0 := pow_ne_zero _ (ENNReal.ofReal_ne_zero_iff.mpr ht) + have hBt : B ≠ ∞ := by simp [B] + have hJ (A : Fin m → E) (hA : A ∈ G) : ENNReal.ofReal (rowJacobian A) ≤ B := by + have hnorm (i : Fin m) : ‖A i‖ ≤ t := by + simpa only [Metric.mem_closedBall, dist_zero_right] using hA i (Set.mem_univ i) + have h := (rowJacobian_le A).trans (Finset.prod_le_prod₀ (fun i _ => norm_nonneg _) (fun i _ => hnorm i)) + simp only [Finset.prod_const, Finset.card_univ, Fintype.card_fin] at h + simpa only [B, ENNReal.ofReal_pow ht.le] using ENNReal.ofReal_le_ofReal h + have hlow : B⁻¹^n * orbitMoment ν m n u * γ G ≤ + ∫⁻ A, orbitMoment ν m n A ∂γ := by + calc + _ = ∫⁻ A in G, B⁻¹^n * orbitMoment ν m n u ∂γ := (setLIntegral_const _ _).symm + _ ≤ ∫⁻ A in G, orbitMoment ν m n A ∂γ := by + apply setLIntegral_mono_ae' hG + filter_upwards [gaussian_rows_ae_linearIndependent m hm] with A hA + intro hAG + rw [orbitMoment_factor ν u hu hac A hA] + exact mul_le_mul' (pow_le_pow_left' (ENNReal.inv_le_inv.mpr (hJ A hAG)) n) le_rfl + _ ≤ ∫⁻ A, orbitMoment ν m n A ∂γ := lintegral_mono' Measure.restrict_le_self (fun _ => le_rfl) + have hlow' : ((2 : ℝ≥0∞)⁻¹^m * B⁻¹^n) * orbitMoment ν m n u ≤ + ∫⁻ A, labelMoment ν m n A ∂γ := by + rw [← gaussian_lintegral_orbitMoment ν m n] + exact (show ((2 : ℝ≥0∞)⁻¹^m * B⁻¹^n) * orbitMoment ν m n u ≤ + B⁻¹^n * orbitMoment ν m n u * γ G from by + simpa only [mul_comm, mul_left_comm, mul_assoc] using + mul_le_mul' hGmass (le_rfl : B⁻¹^n * orbitMoment ν m n u ≤ B⁻¹^n * orbitMoment ν m n u)).trans hlow + have hc0 : (2 : ℝ≥0∞)⁻¹^m * B⁻¹^n ≠ 0 := by simp [hBt] + have hct : (2 : ℝ≥0∞)⁻¹^m * B⁻¹^n ≠ ∞ := + ENNReal.mul_ne_top (by finiteness) (by finiteness) + have h := mul_le_mul' (le_rfl : ((2 : ℝ≥0∞)⁻¹^m * B⁻¹^n)⁻¹ ≤ ((2 : ℝ≥0∞)⁻¹^m * B⁻¹^n)⁻¹) hlow' + rw [← mul_assoc, ENNReal.inv_mul_cancel hc0 hct, one_mul] at h + have he : ((2 : ℝ≥0∞)⁻¹^m * B⁻¹^n)⁻¹ = (2 : ℝ≥0∞)^m * ENNReal.ofReal t^(m*n) := by + rw [ENNReal.mul_inv (Or.inl (by simp)) (Or.inl (by finiteness)), + ← ENNReal.inv_pow, ← ENNReal.inv_pow, inv_inv, inv_inv] + simp only [B, ← pow_mul] + rw [he] at h + exact h + +end ProjectionMoments +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/GaussianDensity.lean b/lean/OAI/Probability/ProjectionMoments/GaussianDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..dec0dd62fdc738d8f9deae431e4a7b7e2f155278 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/GaussianDensity.lean @@ -0,0 +1,182 @@ +import OAI.Probability.ProjectionMoments.Graph + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma stdGaussian_le_volume : stdGaussian E ≤ volume := by + let b := stdOrthonormalBasis ℝ E + have hp : MeasurePreserving (fun x : Fin (Module.finrank ℝ E) → ℝ => + ∑ i, x i • b i) (volume : Measure (Fin (Module.finrank ℝ E) → ℝ)) volume := by + have he : (fun x : Fin (Module.finrank ℝ E) → ℝ => ∑ i, x i • b i) = + (fun x => b.repr.symm (WithLp.toLp 2 x)) := by + funext x + exact b.sum_repr_symm (WithLp.toLp 2 x) + rw [he] + exact b.measurePreserving_repr_symm.comp + (PiLp.volume_preserving_toLp (Fin (Module.finrank ℝ E))) + rw [stdGaussian_eq_map_pi_orthonormalBasis b, ← hp.map_eq] + exact Measure.map_mono (NoiselessRegression.pi_gaussianReal_le_volume _) hp.measurable + +lemma stdGaussian_submodule_null (S : Submodule ℝ E) (hS : S ≠ ⊤) : + stdGaussian E S = 0 := by + apply le_antisymm _ zero_le + exact (stdGaussian_le_volume (E := E) S).trans_eq (Measure.addHaar_submodule volume S hS) + +lemma gaussian_rows_ae_gramSchmidt_ne_zero (m : ℕ) (hm : m ≤ Module.finrank ℝ E) : + ∀ᵐ A : Fin m → E ∂Measure.pi (fun _ => stdGaussian E), ∀ i, gramSchmidt ℝ A i ≠ 0 := by + induction m with + | zero => exact Filter.Eventually.of_forall fun _ i => Fin.elim0 i + | succ m ih => + rw [NoiselessRegression.ae_pi_snoc _ (by + simpa only [sub_zero] using NoiselessRegression.measurableSet_gramSchmidt_ne_zero (0 : E) (m+1))] + filter_upwards [ih (by omega)] with v hv + let S := Submodule.span ℝ (Set.range v) + have hd : Module.finrank ℝ S ≤ m := by + simpa only [S, Fintype.card_fin, Set.finrank] using finrank_range_le_card (R := ℝ) v + have hs : S ≠ ⊤ := by + intro he + rw [he, finrank_top] at hd + omega + have ha : ∀ᵐ x ∂stdGaussian E, x ∉ S := by + rw [ae_iff] + convert stdGaussian_submodule_null S hs using 2 + ext x + simp + filter_upwards [ha] with x hx + intro i + induction i using Fin.lastCases with + | last => + apply norm_ne_zero_iff.mp + rw [NoiselessRegression.norm_gramSchmidt_eq_infDist, + NoiselessRegression.image_Iio_last] + simp only [Fin.snoc_castSucc, Fin.snoc_last] + exact ne_of_gt ((S.closed_of_finiteDimensional.notMem_iff_infDist_pos + ⟨0, S.zero_mem⟩).mp hx) + | cast j => simpa only [NoiselessRegression.gramSchmidt_castSucc, Fin.snoc_castSucc] using hv j + +lemma gaussian_rows_ae_linearIndependent (m : ℕ) (hm : m ≤ Module.finrank ℝ E) : + ∀ᵐ A : Fin m → E ∂Measure.pi (fun _ => stdGaussian E), LinearIndependent ℝ A := by + filter_upwards [gaussian_rows_ae_gramSchmidt_ne_zero m hm] with A hA + apply Matrix.linearIndependent_of_det_gram_ne_zero + rw [NoiselessRegression.det_gram_eq_prod_gramSchmidt] + exact Finset.prod_ne_zero_iff.mpr fun i _ => pow_ne_zero _ (norm_ne_zero_iff.mpr (hA i)) + +lemma lintegral_gaussianReal_sq : + ∫⁻ x : ℝ, ENNReal.ofReal (x^2) ∂gaussianReal 0 1 = 1 := by + have hi : Integrable (fun x : ℝ => x^2) (gaussianReal 0 1) := + (memLp_id_gaussianReal' 2 (by norm_num)).integrable_sq + rw [← ofReal_integral_eq_lintegral_ofReal hi (Filter.Eventually.of_forall (fun x => sq_nonneg x))] + have hv := variance_fun_id_gaussianReal (μ := 0) (v := 1) + rw [variance_eq_integral (X := fun x : ℝ => x) (by fun_prop)] at hv + simpa only [integral_id_gaussianReal, sub_zero, NNReal.coe_one, ENNReal.ofReal_one] using + congrArg ENNReal.ofReal hv + +lemma lintegral_stdGaussian_norm_sq : + ∫⁻ x : E, ENNReal.ofReal (‖x‖^2) ∂stdGaussian E = Module.finrank ℝ E := by + let b := stdOrthonormalBasis ℝ E + rw [stdGaussian_eq_map_pi_orthonormalBasis b, lintegral_map (by fun_prop) (by fun_prop)] + have he (x : Fin (Module.finrank ℝ E) → ℝ) : + ‖∑ i, x i • b i‖^2 = ∑ i, (x i)^2 := by + rw [b.sum_repr_symm (WithLp.toLp 2 x), LinearIsometryEquiv.norm_map] + exact EuclideanSpace.real_norm_sq_eq _ + simp_rw [he, ENNReal.ofReal_sum_of_nonneg (fun i _ => sq_nonneg _)] + rw [lintegral_finsetSum _ (fun i _ => by fun_prop)] + have hi (i : Fin (Module.finrank ℝ E)) : + ∫⁻ x : Fin (Module.finrank ℝ E) → ℝ, ENNReal.ofReal (x i ^ 2) + ∂Measure.pi (fun _ => gaussianReal 0 1) = 1 := by + rw [← lintegral_gaussianReal_sq] + exact (measurePreserving_eval (fun _ : Fin (Module.finrank ℝ E) => gaussianReal 0 1) i).lintegral_comp + (show Measurable (fun x : ℝ => ENNReal.ofReal (x^2)) by fun_prop) + simp_rw [hi] + simp + +lemma gaussian_norm_ball_mass (hd : 0 < Module.finrank ℝ E) : + (2 : ℝ≥0∞)⁻¹ ≤ stdGaussian E (Metric.closedBall 0 (Real.sqrt (2 * Module.finrank ℝ E))) := by + let d : ℝ := Module.finrank ℝ E + have hd' : 0 < d := by dsimp [d]; exact_mod_cast hd + have hneg : stdGaussian E {x | ENNReal.ofReal (2*d) ≤ ENNReal.ofReal (‖x‖^2)} ≤ (2 : ℝ≥0∞)⁻¹ := by + have h := meas_ge_le_lintegral_div (μ := stdGaussian E) + (f := fun x => ENNReal.ofReal (‖x‖^2)) (by fun_prop) + (ε := ENNReal.ofReal (2*d)) (by positivity) ENNReal.ofReal_ne_top + rw [lintegral_stdGaussian_norm_sq] at h + convert h using 1 + have hd0 : (Module.finrank ℝ E : ℝ≥0∞) ≠ 0 := by exact_mod_cast hd.ne' + simp only [ENNReal.ofReal_mul (by norm_num : (0:ℝ) ≤ 2), ENNReal.ofReal_ofNat, d, + ENNReal.ofReal_natCast, div_eq_mul_inv] + rw [ENNReal.mul_inv (Or.inl (by norm_num)) (Or.inl (by norm_num)), mul_left_comm, ENNReal.mul_inv_cancel hd0 (by simp), mul_one] + have hsub : (Metric.closedBall (0 : E) (Real.sqrt (2*d)))ᶜ ⊆ + {x | ENNReal.ofReal (2*d) ≤ ENNReal.ofReal (‖x‖^2)} := by + intro x hx + have hx' : Real.sqrt (2*d) < ‖x‖ := by simpa only [mem_compl_iff, Metric.mem_closedBall, + dist_zero_right, not_le] using hx + apply ENNReal.ofReal_le_ofReal + have hsq := (sq_le_sq₀ (Real.sqrt_nonneg (2*d)) (norm_nonneg x)).mpr hx'.le + rwa [Real.sq_sqrt (by positivity)] at hsq + have hc := (measure_mono hsub).trans hneg + rw [measure_compl measurableSet_closedBall (measure_ne_top _ _), measure_univ] at hc + change (2 : ℝ≥0∞)⁻¹ ≤ stdGaussian E (Metric.closedBall 0 (Real.sqrt (2*d))) + have := tsub_le_iff_left.mp hc + have he : (1 : ℝ≥0∞) - (2 : ℝ≥0∞)⁻¹ = (2 : ℝ≥0∞)⁻¹ := by norm_num + rw [← he] + exact tsub_le_iff_right.mpr this + +end + +lemma map_withDensity_equiv {X Y : Type*} [MeasurableSpace X] [MeasurableSpace Y] + (μ : Measure X) (e : X ≃ᵐ Y) (f : X → ℝ≥0∞) (hf : Measurable f) : + (μ.withDensity f).map e = (μ.map e).withDensity (fun y => f (e.symm y)) := by + ext s hs + rw [Measure.map_apply e.measurable hs, withDensity_apply _ (hs.preimage e.measurable), + withDensity_apply _ hs, ← lintegral_indicator hs, + lintegral_map (show Measurable (s.indicator (fun y => f (e.symm y))) from + (hf.comp e.symm.measurable).indicator hs) e.measurable] + have he (x : X) : s.indicator (fun y => f (e.symm y)) (e x) = + (e ⁻¹' s).indicator f x := by + by_cases hx : e x ∈ s <;> simp [hx] + simp_rw [he] + exact (lintegral_indicator (hs.preimage e.measurable) f).symm + +lemma density_moment_equiv {X : Type*} [MeasurableSpace X] (μ : Measure X) [SigmaFinite μ] + (e : X ≃ᵐ X) (c : ℝ≥0∞) (hc0 : c ≠ 0) (hct : c ≠ ∞) + (he : μ.map e = c • μ) {f g : X → ℝ≥0∞} + (hf : Measurable f) (hg : Measurable g) + (hfg : (μ.withDensity f).map e = μ.withDensity g) (n : ℕ) : + ∫⁻ y, g y ^ (n+1) ∂μ = c^n * ∫⁻ x, f x ^ (n+1) ∂μ := by + have hd : g =ᵐ[μ] (fun y => c * f (e.symm y)) := by + apply (withDensity_eq_iff_of_sigmaFinite hg.aemeasurable (by fun_prop)).mp + rw [← hfg, map_withDensity_equiv μ e f hf, he, withDensity_smul_measure] + exact (withDensity_smul c (hf.comp e.symm.measurable)).symm + have hd' : (fun y => g y ^ (n+1)) =ᵐ[μ] + (fun y => (c * f (e.symm y)) ^ (n+1)) := by + filter_upwards [hd] with y hy + rw [hy] + rw [lintegral_congr_ae hd'] + simp_rw [mul_pow] + rw [lintegral_const_mul _ (by fun_prop)] + have hchange : c * (∫⁻ y, f (e.symm y) ^ (n+1) ∂μ) = ∫⁻ x, f x ^ (n+1) ∂μ := by + calc + _ = ∫⁻ y, f (e.symm y) ^ (n+1) ∂(c • μ) := by + simp only [lintegral_smul_measure, smul_eq_mul] + _ = _ := by + rw [← he, lintegral_map_equiv] + simp + have hchange' : (∫⁻ y, f (e.symm y) ^ (n+1) ∂μ) = + c⁻¹ * ∫⁻ x, f x ^ (n+1) ∂μ := by + rw [← hchange, ← mul_assoc, ENNReal.inv_mul_cancel hc0 hct, one_mul] + rw [hchange', pow_succ, mul_assoc, ← mul_assoc c, ENNReal.mul_inv_cancel hc0 hct, + one_mul] + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Graph.lean b/lean/OAI/Probability/ProjectionMoments/Graph.lean new file mode 100644 index 0000000000000000000000000000000000000000..332d9f58ff3b8d1c204bf2fea4f791c57fe8b255 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Graph.lean @@ -0,0 +1,570 @@ +import OAI.Probability.GaussianRegression.Main +import OAI.Probability.ProjectionMoments.Model + +namespace OAI + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace ProjectionMoments + +lemma volume_preserving_curry (ι κ : Type*) [Fintype ι] [Fintype κ] : + MeasurePreserving (MeasurableEquiv.curry ι κ ℝ) := by + apply MeasurePreserving.symm (MeasurableEquiv.curry ι κ ℝ).symm + refine ⟨(MeasurableEquiv.curry ι κ ℝ).symm.measurable, ?_⟩ + symm + apply Measure.pi_eq + intro s hs + rw [MeasurableEquiv.map_apply] + have he : (MeasurableEquiv.curry ι κ ℝ).symm ⁻¹' Set.univ.pi s = + Set.univ.pi (fun i => Set.univ.pi (fun j => s (i,j))) := by + ext x + simp [Set.mem_pi, MeasurableEquiv.curry, Function.uncurry] + rw [he, volume_pi_pi] + simp_rw [volume_pi_pi] + exact (Fintype.prod_prod_type (fun p : ι × κ => (volume : Measure ℝ) (s p))).symm + +lemma volume_preserving_transpose (m n : ℕ) : + MeasurePreserving (fun A : Fin m → Fin n → ℝ => fun i j => A j i) := by + have h1 := (volume_preserving_curry (Fin m) (Fin n)).symm + have h2 := volume_measurePreserving_piCongrLeft + (fun _ : Fin n × Fin m => ℝ) (Equiv.prodComm (Fin m) (Fin n)) + have h3 := volume_preserving_curry (Fin n) (Fin m) + exact h3.comp (h2.comp h1) + +section GaussianGraph +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussian_graph_kernel_bound {n : ℕ} (v : Fin n → E) + (hv : LinearIndependent ℝ v) (m : ℕ) + (φ : (Fin m → ℝ) → ℝ≥0∞) (hφ : Measurable φ) + (hφ1 : ∫⁻ y, φ y = 1) (b : Fin m → ℝ) : + ∫⁻ A : Fin m → E, ∏ i, φ (fun j => b j - ⟪v i, A j⟫) + ∂Measure.pi (fun _ => stdGaussian E) ≤ + ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) := by + let H : (Fin m → Fin n → ℝ) → ℝ≥0∞ := + fun Z => ∏ i, φ (fun j => b j - Z j i) + have hH : Measurable H := by dsimp [H]; fun_prop + change (∫⁻ A : Fin m → E, H (fun j i => ⟪v i, A j⟫) + ∂Measure.pi (fun _ => stdGaussian E)) ≤ _ + rw [← lintegral_map hH (by fun_prop)] + calc + _ ≤ ∫⁻ Z, H Z ∂(ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) • + (volume : Measure (Fin m → Fin n → ℝ))) := + lintegral_mono' (NoiselessRegression.gaussian_rows_pairings_le v hv m) (fun _ => le_rfl) + _ = ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ v i‖)⁻¹ ^ m) := by + rw [lintegral_smul_measure] + have hL : ∫⁻ Z, H Z = 1 := by + have h := (volume_preserving_transpose m n).lintegral_comp + (show Measurable (fun Z : Fin n → Fin m → ℝ => ∏ i, φ (b - Z i)) by fun_prop) + change (∫⁻ Z : Fin m → Fin n → ℝ, ∏ i, φ (b - fun j => Z j i)) = _ at h + rw [show (∫⁻ Z, H Z) = ∫⁻ Z : Fin n → Fin m → ℝ, ∏ i, φ (b - Z i) from h] + rw [volume_pi, NoiselessRegression.lintegral_fin_prod volume n + (fun _ y => φ (b - y)) (by intro i; fun_prop)] + simp_rw [lintegral_sub_left_eq_self φ b, hφ1] + simp + simp [hL, smul_eq_mul] + +lemma measurable_vectorSmoothing (ν : Measure E) [SFinite ν] (m : ℕ) + (φ : (Fin m → ℝ) → ℝ≥0∞) (hφ : Measurable φ) : + Measurable (vectorSmoothing ν m φ) := by + apply Measurable.lintegral_prod_right + exact hφ.comp (by fun_prop) + +theorem vectorSmoothing_graph_moment {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : NoiselessRegression.HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (m q : ℕ) (hmargin : (q : ℝ) + m ≤ a) + (φ : (Fin m → ℝ) → ℝ≥0∞) (hφ : Measurable φ) + (hφ1 : ∫⁻ y, φ y = 1) (z : E) (b : Fin m → ℝ) : + ∫⁻ A : Fin m → E, + (vectorSmoothing ν m φ (A, fun j => ⟪z, A j⟫ + b j)) ^ q + ∂Measure.pi (fun _ => stdGaussian E) ≤ + (NoiselessRegression.replicaConstant ν a m) ^ q := by + have he (A : Fin m → E) (t : E) : + (fun j => (⟪z, A j⟫ + b j) - ⟪t, A j⟫) = + (fun j => b j - ⟪t-z, A j⟫) := by + funext j + rw [inner_sub_left] + ring + simp only [vectorSmoothing, he] + have hp (A : Fin m → E) := NoiselessRegression.lintegral_pow_pi ν + (fun t => φ (fun j => b j - ⟪t-z, A j⟫)) (by fun_prop) q + simp_rw [hp] + rw [lintegral_lintegral_swap (by fun_prop)] + calc + _ ≤ ∫⁻ v : Fin q → E, NoiselessRegression.replicaWeight m z v + ∂Measure.pi (fun _ => ν) := by + apply lintegral_mono_ae + filter_upwards [NoiselessRegression.ae_replica_linearIndependent hν hsupport z q + (le_trans (le_add_of_nonneg_right (Nat.cast_nonneg m)) hmargin)] with v hv + rw [NoiselessRegression.replicaWeight_eq_det, NoiselessRegression.sqrt_det_gram] + exact gaussian_graph_kernel_bound (fun i => v i - z) hv m φ hφ hφ1 b + _ ≤ _ := NoiselessRegression.replica_integral_bound hν hsupport m z q hmargin +end GaussianGraph + +lemma measurable_ballKernel (m : ℕ) (η : ℝ) : Measurable (ballKernel m η) := by + exact (measurable_const.indicator Metric.isClosed_closedBall.measurableSet).comp + (PiLp.continuous_toLp 2 (fun _ : Fin m => ℝ)).measurable + +lemma ballKernel_integral (m : ℕ) {η : ℝ} (hη : 0 < η) : + ∫⁻ y, ballKernel m η y = 1 := by + have hm : Measurable ((Metric.closedBall (0 : Label m) η).indicator + (fun _ => (volume (Metric.closedBall (0 : Label m) η))⁻¹)) := + measurable_const.indicator Metric.isClosed_closedBall.measurableSet + change (∫⁻ y, (Metric.closedBall (0 : Label m) η).indicator + (fun _ => (volume (Metric.closedBall (0 : Label m) η))⁻¹) (WithLp.toLp 2 y)) = 1 + rw [(PiLp.volume_preserving_toLp (Fin m)).lintegral_comp hm, + lintegral_indicator Metric.isClosed_closedBall.measurableSet] + simp only [lintegral_const, Measure.restrict_apply_univ] + apply ENNReal.inv_mul_cancel + · exact ne_of_gt ((Metric.isOpen_ball.measure_pos volume + (Metric.nonempty_ball.mpr hη)).trans_le (measure_mono Metric.ball_subset_closedBall)) + · exact (isCompact_closedBall (0 : Label m) η).measure_lt_top.ne + +section BallDensity +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[simp] lemma rowMap_apply {m : ℕ} (A : Fin m → E) (t : E) : + rowMap A t = WithLp.toLp 2 (fun j => ⟪t, A j⟫) := by + ext j + simp [rowMap, real_inner_comm] + +lemma measurable_ballAverage (ν : Measure E) [SFinite ν] (m : ℕ) (η : ℝ) : + Measurable (ballAverage ν m η) := by + exact (measurable_vectorSmoothing ν m (ballKernel m η) + (measurable_ballKernel m η)).comp + (measurable_fst.prodMk ((PiLp.continuous_ofLp 2 (fun _ : Fin m => ℝ)).measurable.comp + measurable_snd)) + +omit [FiniteDimensional ℝ E] in +lemma ballAverage_eq (ν : Measure E) [SFinite ν] (m : ℕ) (η : ℝ) + (A : Fin m → E) (y : Label m) : + ballAverage ν m η (A,y) = + (ν.map (rowMap A)) (Metric.closedBall y η) / + volume (Metric.closedBall y η) := by + have he (t : E) : + (fun j => WithLp.ofLp y j - ⟪t, A j⟫) = WithLp.ofLp (y - rowMap A t) := by + simp only [rowMap_apply, WithLp.ofLp_sub] + rfl + have hpoint (t : E) : + ballKernel m η (fun j => WithLp.ofLp y j - ⟪t, A j⟫) = + (Metric.closedBall y η).indicator + (fun _ => (volume (Metric.closedBall y η))⁻¹) (rowMap A t) := by + rw [ballKernel, he, WithLp.toLp_ofLp, Measure.addHaar_closedBall_center volume y] + have hh : y - rowMap A t ∈ Metric.closedBall (0 : Label m) η ↔ + rowMap A t ∈ Metric.closedBall y η := by + simp [Metric.mem_closedBall, dist_eq_norm, norm_sub_rev] + by_cases h : rowMap A t ∈ Metric.closedBall y η + · simp only [Set.indicator_of_mem h, Set.indicator_of_mem (hh.mpr h)] + · simp only [Set.indicator_of_notMem h, Set.indicator_of_notMem (not_congr hh |>.mpr h)] + simp only [ballAverage, vectorSmoothing, hpoint] + rw [← lintegral_map (measurable_const.indicator Metric.isClosed_closedBall.measurableSet) + (rowMap A).continuous.measurable, + lintegral_indicator Metric.isClosed_closedBall.measurableSet] + simp [div_eq_mul_inv, mul_comm] + +lemma measurable_lowerDensity (ν : Measure E) [SFinite ν] (m : ℕ) : + Measurable (lowerDensity ν m) := + Measurable.liminf (fun _n => measurable_ballAverage ν m _) + +lemma ballAverage_graph_moment {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : NoiselessRegression.HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (m q : ℕ) (hmargin : (q : ℝ) + m ≤ a) + (z : E) (b : Label m) {η : ℝ} (hη : 0 < η) : + ∫⁻ A : Fin m → E, (ballAverage ν m η (A, rowMap A z + b)) ^ q + ∂Measure.pi (fun _ => stdGaussian E) ≤ + (NoiselessRegression.replicaConstant ν a m) ^ q := by + simpa only [ballAverage, rowMap_apply, WithLp.ofLp_add, WithLp.ofLp_toLp, Pi.add_def] using + vectorSmoothing_graph_moment hν hsupport m q hmargin (ballKernel m η) + (measurable_ballKernel m η) (ballKernel_integral m hη) z (WithLp.ofLp b) + +theorem lowerDensity_graph_moment {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : NoiselessRegression.HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (m q : ℕ) (hmargin : (q : ℝ) + m ≤ a) (z : E) (b : Label m) : + ∫⁻ A : Fin m → E, (lowerDensity ν m (A, rowMap A z + b)) ^ q + ∂Measure.pi (fun _ => stdGaussian E) ≤ + (NoiselessRegression.replicaConstant ν a m) ^ q := by + have hp (u : ℕ → ℝ≥0∞) : (liminf u atTop) ^ q = liminf (fun n => u n ^ q) atTop := + (show Monotone (fun x : ℝ≥0∞ => x ^ q) from (fun _ _ h => pow_le_pow_left' h q)).map_liminf_of_continuousAt + u (ENNReal.continuous_pow q).continuousAt + simp only [lowerDensity, hp] + apply (lintegral_liminf_le (fun n => ?_)).trans + · apply liminf_le_of_frequently_le' + exact Filter.Frequently.of_forall (fun n => ballAverage_graph_moment hν hsupport m q hmargin z b + (inv_pos.mpr (by positivity))) + · apply Measurable.pow_const + apply (measurable_ballAverage ν m _).comp + exact measurable_id.prodMk (by simp only [rowMap_apply]; fun_prop) + +theorem lowerDensity_is_density (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) + (A : Fin m → E) (hA : ν.map (rowMap A) ≪ (volume : Measure (Label m))) : + volume.withDensity (fun y => lowerDensity ν m (A,y)) = ν.map (rowMap A) := by + let ρ := ν.map (rowMap A) + let v := IsUnifLocDoublingMeasure.vitaliFamily (volume : Measure (Label m)) 1 + have hneg : Tendsto (fun n : ℕ => ((n : ℝ) + 1)⁻¹) atTop (𝓝[>] 0) := by + apply tendsto_nhdsWithin_iff.mpr + refine ⟨?_, Filter.Eventually.of_forall (fun n => ?_)⟩ + · simpa only [one_div] using (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)) + · change (0 : ℝ) < ((n : ℝ) + 1)⁻¹ + positivity + have hae : (fun y => lowerDensity ν m (A,y)) =ᵐ[volume] ρ.rnDeriv volume := by + filter_upwards [v.ae_tendsto_rnDeriv_of_absolutelyContinuous hA] with y hy + have ht := IsUnifLocDoublingMeasure.tendsto_closedBall_filterAt volume + (K := (1 : ℝ)) (x := y) (fun _ : ℕ => y) (fun n => ((n : ℝ) + 1)⁻¹) hneg + (Filter.Eventually.of_forall (fun n => Metric.mem_closedBall_self (by positivity))) + have hlim := (hy.comp ht).liminf_eq + simpa only [lowerDensity, ballAverage_eq, ρ, Function.comp_def] using hlim + rw [withDensity_congr_ae hae] + exact Measure.withDensity_rnDeriv_eq _ _ hA + +lemma ballAverage_eq_zero_of_far (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) + (A : Fin m → E) (z : E) (R η : ℝ) (y : Label m) + (hsupport : ν.support ⊆ Metric.closedBall z R) + (hfar : ‖rowMap A‖ * R + η < ‖y - rowMap A z‖) : + ballAverage ν m η (A,y) = 0 := by + have hz : (ν.map (rowMap A)) (Metric.closedBall y η) = 0 := by + rw [Measure.map_apply (rowMap A).continuous.measurable Metric.isClosed_closedBall.measurableSet] + apply measure_eq_zero_iff_ae_notMem.mpr + filter_upwards [ν.support_mem_ae] with t ht hty + have htR : ‖t-z‖ ≤ R := by simpa [Metric.mem_closedBall, dist_eq_norm] using hsupport ht + have hty' : ‖y - rowMap A t‖ ≤ η := by + simpa [Metric.mem_closedBall, dist_eq_norm, norm_sub_rev] using hty + have hn : ‖rowMap A t - rowMap A z‖ ≤ ‖rowMap A‖ * R := by + rw [← map_sub] + exact ((rowMap A).le_opNorm _).trans (mul_le_mul_of_nonneg_left htR (norm_nonneg _)) + have hb : ‖y - rowMap A z‖ ≤ η + ‖rowMap A‖ * R := by + calc + _ = ‖(y - rowMap A t) + (rowMap A t - rowMap A z)‖ := by congr 1; abel + _ ≤ ‖y - rowMap A t‖ + ‖rowMap A t - rowMap A z‖ := norm_add_le _ _ + _ ≤ _ := add_le_add hty' hn + linarith + simp only [ballAverage_eq, hz, ENNReal.zero_div] + +theorem lowerDensity_eq_zero_of_far (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) + (A : Fin m → E) (z : E) (R : ℝ) (y : Label m) + (hsupport : ν.support ⊆ Metric.closedBall z R) + (hfar : ‖rowMap A‖ * R < ‖y - rowMap A z‖) : + lowerDensity ν m (A,y) = 0 := by + have ht : Tendsto (fun n : ℕ => ((n : ℝ) + 1)⁻¹) atTop (𝓝 0) := by + simpa only [one_div] using (tendsto_one_div_add_atTop_nhds_zero_nat (𝕜 := ℝ)) + have he : ∀ᶠ n : ℕ in atTop, ballAverage ν m ((n : ℝ) + 1)⁻¹ (A,y) = 0 := by + filter_upwards [ht (Iio_mem_nhds (sub_pos.mpr hfar))] with n hn + apply ballAverage_eq_zero_of_far ν m A z R _ y hsupport + have hnn : ((n : ℝ) + 1)⁻¹ < ‖y - rowMap A z‖ - ‖rowMap A‖ * R := hn + linarith + exact (liminf_congr he).trans (liminf_const _) +end BallDensity + +section Rescaling +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def rescale (z : E) (R : ℝ) (x : E) : E := R⁻¹ • (x-z) +def dilate (z : E) (R : ℝ) (x : E) : E := R • x + z + +omit [FiniteDimensional ℝ E] in +@[fun_prop] lemma measurable_rescale (z : E) (R : ℝ) : Measurable (rescale z R) := by + unfold rescale; fun_prop +omit [FiniteDimensional ℝ E] in +@[fun_prop] lemma measurable_dilate (z : E) (R : ℝ) : Measurable (dilate z R) := by + unfold dilate; fun_prop + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma dilate_rescale (z : E) {R : ℝ} (hR : R ≠ 0) (x : E) : + dilate z R (rescale z R x) = x := by + simp [dilate, rescale, smul_smul, hR] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma rescale_preimage_closedBall (z b : E) {R : ℝ} (hR : 0 < R) (t : ℝ) : + rescale z R ⁻¹' Metric.closedBall b t = Metric.closedBall (dilate z R b) (R*t) := by + ext x + simp only [Set.mem_preimage, Metric.mem_closedBall, dist_eq_norm] + have he : rescale z R x - b = R⁻¹ • (x - dilate z R b) := by + simp [rescale, dilate, smul_sub, smul_add, smul_smul, hR.ne', sub_sub, add_comm] + rw [he, norm_smul, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr hR)] + rw [inv_mul_le_iff₀ hR] + +def normalizedRescale (ν : Measure E) (K a : ℝ) (z : E) (R : ℝ) : Measure E := + (ENNReal.ofReal (K * R ^ a))⁻¹ • ν.map (rescale z R) + +omit [FiniteDimensional ℝ E] [BorelSpace E] in +lemma normalizedRescale_finite (ν : Measure E) [IsFiniteMeasure ν] + (K a : ℝ) (z : E) (R : ℝ) (hKR : 0 < K * R ^ a) : + IsFiniteMeasure (normalizedRescale ν K a z R) := by + dsimp [normalizedRescale] + exact Measure.smul_finite _ (ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr hKR)) + +omit [FiniteDimensional ℝ E] in +lemma normalizedRescale_local {ν : Measure E} {K a : ℝ} (hν : AllBallMass ν K a) + (hK : 0 < K) (z : E) {R : ℝ} (hR : 0 < R) : + NoiselessRegression.HasLocalMassBound (normalizedRescale ν K a z R) a := by + intro b _ t ht + rw [normalizedRescale, Measure.smul_apply, smul_eq_mul, + Measure.map_apply (measurable_rescale z R) Metric.isClosed_closedBall.measurableSet, + rescale_preimage_closedBall z b hR] + apply (mul_le_mul' le_rfl (hν (dilate z R b) (R*t) (mul_pos hR ht))).trans + rw [Real.mul_rpow hR.le ht.le, ← mul_assoc, + ENNReal.ofReal_mul (mul_nonneg hK.le (Real.rpow_nonneg hR.le a)), + ← mul_assoc, ENNReal.inv_mul_cancel (ENNReal.ofReal_ne_zero_iff.mpr (by positivity)) + ENNReal.ofReal_ne_top, one_mul] + +lemma normalizedRescale_support {ν : Measure E} (K a : ℝ) (z : E) {R : ℝ} + (hR : 0 < R) (hsupport : ν.support ⊆ Metric.closedBall z R) : + (normalizedRescale ν K a z R).support ⊆ Metric.closedBall 0 1 := by + apply Measure.support_subset_of_isClosed Metric.isClosed_closedBall + apply Measure.smul_absolutelyContinuous.ae_le + change ∀ᵐ x ∂ν.map (rescale z R), x ∈ Metric.closedBall 0 1 + apply (ae_map_iff (measurable_rescale z R).aemeasurable + (show MeasurableSet {x : E | x ∈ Metric.closedBall 0 1} from + Metric.isClosed_closedBall.measurableSet)).mpr + filter_upwards [ν.support_mem_ae] with x hx + have he := rescale_preimage_closedBall z (0 : E) hR (1 : ℝ) + have hx' : x ∈ rescale z R ⁻¹' Metric.closedBall 0 1 := by + rw [he] + simpa [dilate] using hsupport hx + exact hx' + +omit [FiniteDimensional ℝ E] in +lemma normalizedRescale_recover (ν : Measure E) (K a : ℝ) (hK : 0 < K) + (z : E) {R : ℝ} (hR : 0 < R) : + ENNReal.ofReal (K * R ^ a) • (normalizedRescale ν K a z R).map (dilate z R) = ν := by + rw [normalizedRescale, Measure.map_smul _ (measurable_dilate z R).aemeasurable, smul_smul, + ENNReal.mul_inv_cancel (ENNReal.ofReal_ne_zero_iff.mpr (by positivity)) ENNReal.ofReal_ne_top, + one_smul, Measure.map_map (measurable_dilate z R) (measurable_rescale z R)] + have he : dilate z R ∘ rescale z R = id := by + funext x; exact dilate_rescale z hR.ne' x + rw [he, Measure.map_id] + +omit [FiniteDimensional ℝ E] [BorelSpace E] in +lemma ballAverage_smul (ν : Measure E) (c : ℝ≥0∞) (m : ℕ) (η : ℝ) + (A : Fin m → E) (y : Label m) : + ballAverage (c • ν) m η (A,y) = c * ballAverage ν m η (A,y) := by + simp only [ballAverage, vectorSmoothing, lintegral_smul_measure, smul_eq_mul] + +lemma ballAverage_dilate (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) + (z : E) {R η : ℝ} (hR : 0 < R) (hη : 0 < η) (A : Fin m → E) (b : Label m) : + ballAverage (ν.map (dilate z R)) m η (A, rowMap A z + b) = + (ENNReal.ofReal (R ^ m))⁻¹ * ballAverage ν m (η/R) (A, R⁻¹ • b) := by + rw [ballAverage_eq, ballAverage_eq] + have hn : ((ν.map (dilate z R)).map (rowMap A)) (Metric.closedBall (rowMap A z + b) η) = + (ν.map (rowMap A)) (Metric.closedBall (R⁻¹ • b) (η/R)) := by + rw [Measure.map_apply (rowMap A).continuous.measurable Metric.isClosed_closedBall.measurableSet, + Measure.map_apply (measurable_dilate z R) + (Metric.isClosed_closedBall.measurableSet.preimage (rowMap A).continuous.measurable), + Measure.map_apply (rowMap A).continuous.measurable Metric.isClosed_closedBall.measurableSet] + congr 1 + ext x + simp only [Set.mem_preimage, Metric.mem_closedBall, dist_eq_norm] + have he : rowMap A (dilate z R x) - (rowMap A z + b) = + R • (rowMap A x - R⁻¹ • b) := by + simp only [dilate, map_add, map_smul, smul_sub, smul_smul, mul_inv_cancel₀ hR.ne', one_smul] + abel + rw [he, norm_smul, Real.norm_eq_abs, abs_of_pos hR, le_div_iff₀ hR, mul_comm] + have hv : volume (Metric.closedBall (rowMap A z + b) η) = + ENNReal.ofReal (R ^ m) * volume (Metric.closedBall (R⁻¹ • b) (η/R)) := by + rw [Measure.addHaar_closedBall volume _ hη.le, + Measure.addHaar_closedBall volume _ (div_pos hη hR).le, + finrank_euclideanSpace_fin, ← mul_assoc, ← ENNReal.ofReal_mul (by positivity), + ← mul_pow, mul_div_cancel₀ _ hR.ne'] + rw [hn, hv, ENNReal.div_eq_inv_mul, ENNReal.mul_inv + (Or.inl (ENNReal.ofReal_ne_zero_iff.mpr (by positivity))) (Or.inl ENNReal.ofReal_ne_top)] + rw [ENNReal.div_eq_inv_mul, mul_assoc] + +lemma normalizedRescale_mass {ν : Measure E} {K a : ℝ} (hν : AllBallMass ν K a) + (hK : 0 < K) (z : E) {R : ℝ} (hR : 0 < R) + (hsupport : ν.support ⊆ Metric.closedBall z R) : + normalizedRescale ν K a z R Set.univ ≤ 1 := by + have he : ν Set.univ = ν (Metric.closedBall z R) := by + apply measure_congr + filter_upwards [ν.support_mem_ae] with x hx + apply propext + exact iff_of_true (Set.mem_univ x) (hsupport hx) + rw [normalizedRescale, Measure.smul_apply, smul_eq_mul, + Measure.map_apply (measurable_rescale z R) MeasurableSet.univ, Set.preimage_univ, he] + exact (mul_le_mul' le_rfl (hν z R hR)).trans_eq + (ENNReal.inv_mul_cancel (ENNReal.ofReal_ne_zero_iff.mpr (by positivity)) ENNReal.ofReal_ne_top) + +lemma ballAverage_normalizedRescale {ν : Measure E} [IsFiniteMeasure ν] + (K a : ℝ) (hK : 0 < K) (z : E) {R η : ℝ} (hR : 0 < R) (hη : 0 < η) + (m : ℕ) (A : Fin m → E) (b : Label m) : + ballAverage ν m η (A, rowMap A z + b) = + ENNReal.ofReal (K * R ^ (a-m)) * + ballAverage (normalizedRescale ν K a z R) m (η/R) (A, R⁻¹ • b) := by + let μ := normalizedRescale ν K a z R + have : IsFiniteMeasure μ := normalizedRescale_finite ν K a z R (by positivity) + conv_lhs => rw [← normalizedRescale_recover ν K a hK z hR] + rw [ballAverage_smul, ballAverage_dilate μ m z hR hη, ← mul_assoc] + congr 1 + rw [Real.rpow_sub_natCast hR.ne', ← mul_div_assoc, ENNReal.ofReal_div_of_pos (by positivity)] + rfl + +theorem ballAverage_graph_moment_scaled {ν : Measure E} [IsFiniteMeasure ν] + {K a : ℝ} (hν : AllBallMass ν K a) (hK : 0 < K) + (z : E) {R : ℝ} (hR : 0 < R) (hsupport : ν.support ⊆ Metric.closedBall z R) + (m q : ℕ) (hmargin : (q : ℝ) + m ≤ a) (b : Label m) {η : ℝ} (hη : 0 < η) : + ∫⁻ A : Fin m → E, (ballAverage ν m η (A, rowMap A z + b)) ^ q + ∂Measure.pi (fun _ => stdGaussian E) ≤ + (ENNReal.ofReal (K * R ^ (a-m)) * + (1 + ENNReal.ofReal ((3 : ℝ)^Module.finrank ℝ E * (4 : ℝ)^a) * + (2 : ℝ≥0∞)^(m+1))) ^ q := by + let μ := normalizedRescale ν K a z R + have : IsFiniteMeasure μ := normalizedRescale_finite ν K a z R (by positivity) + have hl := normalizedRescale_local hν hK z hR + have hs := normalizedRescale_support K a z hR hsupport + have hc : NoiselessRegression.replicaConstant μ a m ≤ + 1 + ENNReal.ofReal ((3 : ℝ)^Module.finrank ℝ E * (4 : ℝ)^a) * (2 : ℝ≥0∞)^(m+1) := by + exact add_le_add (normalizedRescale_mass hν hK z hR hsupport) le_rfl + simp_rw [ballAverage_normalizedRescale K a hK z hR hη, mul_pow] + rw [lintegral_const_mul _ (by apply Measurable.pow_const; exact + (measurable_ballAverage μ m (η/R)).comp (measurable_id.prodMk measurable_const))] + apply mul_le_mul' le_rfl + have hm := ballAverage_graph_moment hl hs m q hmargin (0 : E) + (R⁻¹ • b) (div_pos hη hR) + have hz (A : Fin m → E) : rowMap A (0 : E) = 0 := map_zero (rowMap A) + simp only [hz, zero_add] at hm + exact hm.trans (pow_le_pow_left' hc q) + +theorem lowerDensity_graph_moment_scaled {ν : Measure E} [IsFiniteMeasure ν] + {K a : ℝ} (hν : AllBallMass ν K a) (hK : 0 < K) + (z : E) {R : ℝ} (hR : 0 < R) (hsupport : ν.support ⊆ Metric.closedBall z R) + (m q : ℕ) (hmargin : (q : ℝ) + m ≤ a) (b : Label m) : + ∫⁻ A : Fin m → E, (lowerDensity ν m (A, rowMap A z + b)) ^ q + ∂Measure.pi (fun _ => stdGaussian E) ≤ + (ENNReal.ofReal (K * R ^ (a-m)) * + (1 + ENNReal.ofReal ((3 : ℝ)^Module.finrank ℝ E * (4 : ℝ)^a) * + (2 : ℝ≥0∞)^(m+1))) ^ q := by + have hp (u : ℕ → ℝ≥0∞) : (liminf u atTop) ^ q = liminf (fun n => u n ^ q) atTop := + (show Monotone (fun x : ℝ≥0∞ => x ^ q) from (fun _ _ h => pow_le_pow_left' h q)).map_liminf_of_continuousAt + u (ENNReal.continuous_pow q).continuousAt + simp only [lowerDensity, hp] + apply (lintegral_liminf_le (fun n => ?_)).trans + · apply liminf_le_of_frequently_le' + exact Filter.Frequently.of_forall (fun n => ballAverage_graph_moment_scaled hν hK z hR + hsupport m q hmargin b (inv_pos.mpr (by positivity))) + · apply Measurable.pow_const + apply (measurable_ballAverage ν m _).comp + exact measurable_id.prodMk (by simp only [rowMap_apply]; fun_prop) + +end Rescaling + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +lemma gaussian_vector_replica_bound {n : ℕ} (p : E) (v : Fin n → E) + (hv : LinearIndependent ℝ (fun i => v i - p)) + (m : ℕ) (φ : (Fin m → ℝ) → ℝ≥0∞) (hφ : Measurable φ) + (hφ1 : ∫⁻ y, φ y = 1) : + ∫⁻ A : Fin m → E, ∫⁻ y : Fin m → ℝ, + φ (fun j => y j - ⟪p, A j⟫) * + ∏ i, φ (fun j => y j - ⟪v i, A j⟫) + ∂volume ∂Measure.pi (fun _ => stdGaussian E) ≤ + ENNReal.ofReal ((∏ i, ‖gramSchmidt ℝ (fun i => v i-p) i‖)⁻¹ ^ m) := by + have ht (A : Fin m → E) : + (∫⁻ y : Fin m → ℝ, φ (fun j => y j - ⟪p, A j⟫) * + ∏ i, φ (fun j => y j - ⟪v i, A j⟫)) = + ∫⁻ y : Fin m → ℝ, φ y * ∏ i, φ (fun j => y j - ⟪v i-p, A j⟫) := by + have he (y : Fin m → ℝ) (i : Fin n) : + (fun j => y j - ⟪p, A j⟫ - ⟪v i-p, A j⟫) = + (fun j => y j - ⟪v i, A j⟫) := by + funext j; rw [inner_sub_left]; ring + convert (lintegral_sub_right_eq_self (μ := (volume : Measure (Fin m → ℝ))) + (fun y : Fin m → ℝ => φ y * ∏ i, φ (fun j => y j - ⟪v i-p, A j⟫)) + (fun j => ⟪p, A j⟫)) using 1 + apply lintegral_congr + intro y + simp only [Pi.sub_apply, he] + rfl + simp_rw [ht] + rw [lintegral_lintegral_swap (by fun_prop)] + calc + _ ≤ ∫⁻ y, φ y * ENNReal.ofReal + ((∏ i, ‖gramSchmidt ℝ (fun i => v i-p) i‖)⁻¹ ^ m) := by + apply lintegral_mono + intro y + dsimp only + rw [lintegral_const_mul _ (by fun_prop)] + exact mul_le_mul' le_rfl (gaussian_graph_kernel_bound _ hv m φ hφ hφ1 y) + _ = _ := by rw [lintegral_mul_const _ hφ, hφ1, one_mul] + +lemma vectorSmoothing_pow (ν : Measure E) [IsFiniteMeasure ν] + (m n : ℕ) (φ : (Fin m → ℝ) → ℝ≥0∞) (hφ : Measurable φ) + (z : (Fin m → E) × (Fin m → ℝ)) : + (vectorSmoothing ν m φ z)^(n+1) = + ∫⁻ w : E × (Fin n → E), + φ (fun j => z.2 j - ⟪w.1, z.1 j⟫) * + ∏ i, φ (fun j => z.2 j - ⟪w.2 i, z.1 j⟫) + ∂ν.prod (Measure.pi (fun _ => ν)) := by + rw [lintegral_prod _ (by fun_prop)] + have hG : Measurable (fun v : Fin n → E => + ∏ i, φ (fun j => z.2 j - ⟪v i, z.1 j⟫)) := by fun_prop + simp_rw [lintegral_const_mul _ hG] + rw [lintegral_mul_const _ (by fun_prop), ← NoiselessRegression.lintegral_pow_pi ν + (fun t : E => φ (fun j => z.2 j - ⟪t, z.1 j⟫)) (by fun_prop) n] + exact pow_succ' _ _ + +theorem vectorSmoothing_integrated_moment {m : ℕ} {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : NoiselessRegression.HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (φ : (Fin m → ℝ) → ℝ≥0∞) (hφ : Measurable φ) (hφ1 : ∫⁻ y, φ y = 1) + (n : ℕ) (hmargin : (n : ℝ) + m ≤ a) : + ∫⁻ z : (Fin m → E) × (Fin m → ℝ), (vectorSmoothing ν m φ z)^(n+1) + ∂(Measure.pi (fun _ => stdGaussian E)).prod volume ≤ + ν Set.univ * (NoiselessRegression.replicaConstant ν a m)^n := by + simp_rw [vectorSmoothing_pow ν m n φ hφ] + rw [lintegral_lintegral_swap (by fun_prop), lintegral_prod _ (by fun_prop)] + calc + _ ≤ ∫⁻ p, ∫⁻ v : Fin n → E, NoiselessRegression.replicaWeight m p v + ∂Measure.pi (fun _ => ν) ∂ν := by + apply lintegral_mono + intro p + apply lintegral_mono_ae + filter_upwards [NoiselessRegression.ae_replica_linearIndependent hν hsupport p n + (le_trans (le_add_of_nonneg_right (Nat.cast_nonneg m)) hmargin)] with v hv + rw [lintegral_prod _ (by fun_prop), NoiselessRegression.replicaWeight_eq_det, + NoiselessRegression.sqrt_det_gram] + exact gaussian_vector_replica_bound p v hv m φ hφ hφ1 + _ ≤ ∫⁻ _p, (NoiselessRegression.replicaConstant ν a m)^n ∂ν := + lintegral_mono fun p => NoiselessRegression.replica_integral_bound hν hsupport m p n hmargin + _ = _ := by rw [lintegral_const, mul_comm] + +theorem ballAverage_integrated_moment {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : NoiselessRegression.HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (m n : ℕ) (hmargin : (n : ℝ) + m ≤ a) {η : ℝ} (hη : 0 < η) : + ∫⁻ z : (Fin m → E) × Label m, (ballAverage ν m η z)^(n+1) + ∂(Measure.pi (fun _ => stdGaussian E)).prod volume ≤ + ν Set.univ * (NoiselessRegression.replicaConstant ν a m)^n := by + have hm := (MeasurePreserving.id (Measure.pi (fun _ : Fin m => stdGaussian E))).prod + (PiLp.volume_preserving_toLp (Fin m)) + rw [← hm.lintegral_comp ((measurable_ballAverage ν m η).pow_const (n+1))] + exact vectorSmoothing_integrated_moment hν hsupport _ (measurable_ballKernel m η) + (ballKernel_integral m hη) n hmargin + +theorem lowerDensity_integrated_moment {ν : Measure E} [IsFiniteMeasure ν] + {a : ℝ} (hν : NoiselessRegression.HasLocalMassBound ν a) + (hsupport : ν.support ⊆ Metric.closedBall 0 1) + (m n : ℕ) (hmargin : (n : ℝ) + m ≤ a) : + ∫⁻ z : (Fin m → E) × Label m, (lowerDensity ν m z)^(n+1) + ∂(Measure.pi (fun _ => stdGaussian E)).prod volume ≤ + ν Set.univ * (NoiselessRegression.replicaConstant ν a m)^n := by + have hp (u : ℕ → ℝ≥0∞) : (liminf u atTop) ^ (n+1) = + liminf (fun j => u j ^ (n+1)) atTop := + (show Monotone (fun x : ℝ≥0∞ => x ^ (n+1)) from + (fun _ _ h => pow_le_pow_left' h (n+1))).map_liminf_of_continuousAt + u (ENNReal.continuous_pow (n+1)).continuousAt + simp only [lowerDensity, hp] + apply (lintegral_liminf_le (fun j => (measurable_ballAverage ν m _).pow_const _)).trans + apply liminf_le_of_frequently_le' + exact Filter.Frequently.of_forall (fun j => ballAverage_integrated_moment hν hsupport m n + hmargin (inv_pos.mpr (by positivity))) + +end ProjectionMoments +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Kernels.lean b/lean/OAI/Probability/ProjectionMoments/Kernels.lean new file mode 100644 index 0000000000000000000000000000000000000000..d5ebaff90743adb448bf6cf42b3d082e33b5d2da --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Kernels.lean @@ -0,0 +1,136 @@ +import OAI.Probability.ProjectionMoments.BorelRules + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter +open MeasureTheory ProbabilityTheory Set Filter unitInterval +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression + +lemma finite_kernel_borel_version {X J : Type*} [MeasurableSpace X] + [Fintype J] [Nonempty J] [MeasurableSpace J] [MeasurableSingletonClass J] + (μ : Measure X) (P : X → Measure J) (hP : ∀ x, IsProbabilityMeasure (P x)) + (hm : ∀ j, AEMeasurable (fun x => P x {j}) μ) : + ∃ κ : Kernel X J, IsMarkovKernel κ ∧ (fun x => κ x) =ᵐ[μ] P := by + classical + let v : X → Measure J := fun x => ∑ j, ((hm j).mk _ x) • Measure.dirac j + have hv : Measurable v := by + apply Finset.measurable_sum + intro j _ + exact (hm j).measurable_mk.smul_measure (Measure.dirac j) + have he : v =ᵐ[μ] P := by + have hh : ∀ᵐ x ∂μ, ∀ j, (hm j).mk _ x = P x {j} := by + simp only [ae_all_iff] + intro j + exact (hm j).ae_eq_mk.symm + filter_upwards [hh] with x hx + simp only [v,hx,← Measure.sum_fintype,Measure.sum_smul_dirac] + let κ : Kernel X J := ⟨fun x => if v x Set.univ = 1 then v x else Measure.dirac (Classical.choice ‹Nonempty J›), + hv.ite (measurableSet_eq_fun ((Measure.measurable_coe MeasurableSet.univ).comp hv) measurable_const) + measurable_const⟩ + refine ⟨κ,⟨fun x => ⟨?_⟩⟩,?_⟩ + · dsimp [κ] + split_ifs with h + · exact h + · simp + · filter_upwards [he] with x hx + have hx1 : v x Set.univ = 1 := by rw [hx]; exact (hP x).measure_univ + dsimp only [κ,Kernel.coe_mk] + rw [ite_eq_left hx1,hx] + +namespace FiniteKernelLearner +variable {d M T : ℕ} + +structure BorelRules (K : FiniteKernelLearner d M T) : Prop where + transition : ∀ t j, Measurable (K.transition t j) + +lemma exists_borel_version (K : FiniteKernelLearner d M T) (hK : K.CompletedRules) : + ∃ K' : FiniteKernelLearner d M T, K'.BorelRules ∧ K'.initial = K.initial ∧ + K'.output = K.output ∧ ∀ t j, K'.transition t j =ᵐ[observationReference d] K.transition t j := by + classical + choose κ hκ he using fun t j => finite_kernel_borel_version (observationReference d) + (K.transition t j) (K.transition_probability t j) (hK.transition t j) + let K' : FiniteKernelLearner d M T := ⟨K.initial,K.initial_probability, + fun t j obs => κ t j obs,fun t j obs => (hκ t j).isProbabilityMeasure obs, + K.output,K.output_probability⟩ + exact ⟨K',⟨fun t j => (κ t j).measurable⟩,rfl,rfl,he⟩ + +end FiniteKernelLearner + +variable {J O : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] + [MeasurableSpace O] + +def coinRun (F : ℕ → J → O → I → J) : + (n : ℕ) → J → (Fin n → O) → (Fin n → I) → J + | 0, j, _, _ => j + | n+1, j, obs, u => F (n+1) (coinRun F n j (Fin.init obs) (Fin.init u)) (obs (Fin.last n)) (u (Fin.last n)) + +omit [MeasurableSpace O] in +lemma measurable_coinRun [MeasurableSpace O] {F : ℕ → J → O → I → J} + (hF : ∀ t j obs, Measurable (F t j obs)) (n : ℕ) (j : J) (obs : Fin n → O) : + Measurable (coinRun F n j obs) := by + induction n with + | zero => exact measurable_const + | succ n ih => + change Measurable (fun u : Fin (n+1) → I => F (n+1) (coinRun F n j (Fin.init obs) (Fin.init u)) (obs (Fin.last n)) (u (Fin.last n))) + have hi : Measurable (fun u : Fin (n+1) → I => Fin.init u) := by + change Measurable (fun u : Fin (n+1) → I => fun i : Fin n => u i.castSucc) + fun_prop + have hg : Measurable (fun u : Fin (n+1) → I => coinRun F n j (Fin.init obs) (Fin.init u)) := + (ih (Fin.init obs)).comp hi + exact measurable_select (h := fun a (u : Fin (n+1) → I) => F (n+1) a (obs (Fin.last n)) (u (Fin.last n))) + (fun a => (hF (n+1) a (obs (Fin.last n))).comp (measurable_pi_apply _)) hg + +lemma lintegral_coinRun {F : ℕ → J → O → I → J} {P : ℕ → J → O → Measure J} + (hF : ∀ t j obs, Measurable (F t j obs)) + (hP : ∀ t j obs, volume.map (F t j obs) = P t j obs) + (n : ℕ) (j : J) (obs : Fin n → O) (f : J → ℝ≥0∞) : + (∫⁻ u, f (coinRun F n j obs u) ∂Measure.pi (fun _ => (volume : Measure I))) = + ∫⁻ a, f a ∂kernelRun P n j obs := by + induction n generalizing f with + | zero => simp [coinRun,kernelRun] + | succ n ih => + rw [lintegral_pi_snoc volume (fun u => f (coinRun F (n+1) j obs u)) + ((measurable_of_finite f).comp (measurable_coinRun hF (n+1) j obs))] + simp only [coinRun,Fin.init_snoc,Fin.snoc_last] + have hh (a : J) : (∫⁻ u, f (F (n+1) a (obs (Fin.last n)) u) ∂volume) = + ∫⁻ b, f b ∂P (n+1) a (obs (Fin.last n)) := by + rw [←hP] + exact (lintegral_map (measurable_of_finite f) (hF _ _ _)).symm + simp_rw [hh] + rw [ih (Fin.init obs) (fun a => ∫⁻ b, f b ∂P (n+1) a (obs (Fin.last n)))] + exact (Measure.lintegral_bind (measurable_of_finite _).aemeasurable + (measurable_of_finite f).aemeasurable).symm + +lemma coinRun_law {F : ℕ → J → O → I → J} {P : ℕ → J → O → Measure J} + (hF : ∀ t j obs, Measurable (F t j obs)) + (hP : ∀ t j obs, volume.map (F t j obs) = P t j obs) + (n : ℕ) (j : J) (obs : Fin n → O) : + (Measure.pi (fun _ => (volume : Measure I))).map (coinRun F n j obs) = kernelRun P n j obs := by + apply Measure.ext + intro s hs + have hh := lintegral_coinRun hF hP n j obs (s.indicator (fun _ => (1 : ℝ≥0∞))) + rw [← lintegral_map (by fun_prop) (measurable_coinRun hF n j obs)] at hh + simpa only [lintegral_indicator_const hs,one_mul] using hh + +omit [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] [MeasurableSpace O] in +lemma kernelRun_congr [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] + [MeasurableSpace O] {P P' : ℕ → J → O → Measure J} (n : ℕ) (j : J) (obs : Fin n → O) + (h : ∀ t a i, P t a (obs i) = P' t a (obs i)) : + kernelRun P n j obs = kernelRun P' n j obs := by + induction n with + | zero => rfl + | succ n ih => + simp only [kernelRun] + rw [ih (Fin.init obs) (fun t a i => h t a i.castSucc)] + congr 1 + funext a + exact h _ _ _ + +end NoiselessRegression + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Main.lean b/lean/OAI/Probability/ProjectionMoments/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..c39ebce53bdce9c5d5b0a6b5c94d4c23a05d08d1 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Main.lean @@ -0,0 +1,34 @@ +import OAI.Probability.ProjectionMoments.SphereWeights + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open NoiselessRegression NoiselessRegression.FiniteKernelLearner +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +universe u +namespace ProjectionMoments + +theorem main : MainStatement.{u} := by + refine ⟨integrated_frame_moment, normalized_unitBall_moment, all_radii_sphere_moment, + positive_family_cap_domination, riesz_deterministic_offsets, one_block_all_radii, + NoiselessRegression.FiniteKernelLearner.haar_success, + NoiselessRegression.FiniteKernelLearner.riesz_success, + NoiselessRegression.FiniteKernelLearner.cap_fixed_stop, + NoiselessRegression.FiniteKernelLearner.cap_total_success, + NoiselessRegression.FiniteKernelLearner.cap_fixed_stop_asymptotic, + NoiselessRegression.FiniteKernelLearner.cap_total_success_asymptotic, ?_, + NoiselessRegression.FiniteKernelLearner.subquadratic_memory_with_pointwise, + NoiselessRegression.FiniteKernelLearner.fixed_quadratic_memory⟩ + intro d M T hd K hK + exact K.exists_equivalent_tape hK hd + +end ProjectionMoments + +end + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Model.lean b/lean/OAI/Probability/ProjectionMoments/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..b89ce7d25b4be7453258d69672ebc2c7d2b17287 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Model.lean @@ -0,0 +1,745 @@ +import Mathlib + +namespace OAI + +noncomputable section + +section InlineMainProof + +open MeasureTheory ProbabilityTheory Set Filter + +open scoped ENNReal NNReal RealInnerProductSpace + +universe u + +namespace NoiselessRegression + +abbrev Vector (d : ℕ) := EuclideanSpace ℝ (Fin d) + +abbrev UnitSphere (d : ℕ) := Metric.sphere (0 : Vector d) 1 + +abbrev State (M : ℕ) := Fin (2 ^ M) + +abbrev Samples (d T : ℕ) := Fin T → Vector d + +def uniformSphere (d : ℕ) : Measure (UnitSphere d) := + let σ := (volume : Measure (Vector d)).toSphere + (σ Set.univ)⁻¹ • σ + +def sampleLaw (d T : ℕ) : Measure (Samples d T) := + Measure.pi fun _ => stdGaussian (Vector d) + +def observationReference (d : ℕ) : Measure (Vector d × ℝ) := + (stdGaussian (Vector d)).prod volume + +structure Learner (d M T : ℕ) (Ω : Type u) where + initialChoice : Ω → Bool × State M + transition : ℕ → Ω → State M → (Vector d × ℝ) → Bool × State M + output : ℕ → Ω → State M → UnitSphere d + +namespace Learner + +abbrev RunStatus (M : ℕ) := Sum (State M) (ℕ × State M) + +def start {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) (ω : Ω) : + RunStatus M := + let a := L.initialChoice ω + if a.1 then .inr (0, a.2) else .inl a.2 + +def run {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (s : UnitSphere d) (ω : Ω) (x : Samples d T) : ℕ → RunStatus M + | 0 => L.start ω + | n + 1 => + match L.run s ω x n with + | .inr done => .inr done + | .inl state => + if hn : n < T then + let row := x ⟨n, hn⟩ + let a := L.transition (n + 1) ω state (row, ⟪row, s.val⟫) + if a.1 then .inr (n + 1, a.2) else .inl a.2 + else .inl state + +def terminal {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (s : UnitSphere d) (ω : Ω) (x : Samples d T) : ℕ × State M := + match L.run s ω x T with + | .inl state => (T, state) + | .inr done => done + +def estimate {d M T : ℕ} {Ω : Type u} (L : Learner d M T Ω) + (s : UnitSphere d) (ω : Ω) (x : Samples d T) : UnitSphere d := + let a := L.terminal s ω x + L.output a.1 ω a.2 + +structure Admissible {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) : Prop where + initialChoice : AEMeasurable L.initialChoice ρ + transition : ∀ t a, AEMeasurable (fun z : Ω × (Vector d × ℝ) => + L.transition t z.1 a z.2) (ρ.prod (observationReference d)) + output : ∀ t a, AEMeasurable (fun ω => L.output t ω a) ρ + fixed_experiment : ∀ s, AEMeasurable (fun z : Ω × Samples d T => + L.estimate s z.1 z.2) (ρ.prod (sampleLaw d T)) + uniform_experiment : AEMeasurable + (fun z : UnitSphere d × (Ω × Samples d T) => L.estimate z.1 z.2.1 z.2.2) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) + +def angularError {d : ℕ} (s ŝ : UnitSphere d) : ℝ := + Real.arccos ⟪ŝ.val, s.val⟫ + +def uniformSuccess {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) (ε : ℝ) : ℝ≥0∞ := + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) + {z | angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + +end Learner + +open scoped Topology + +open InnerProductSpace + +section SphereBounds + +open scoped Pointwise + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def sphereLaw : Measure (Metric.sphere (0 : E) 1) := + let σ := (volume : Measure E).toSphere + (σ Set.univ)⁻¹ • σ + +end SphereBounds + +open scoped Pointwise + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def ambientSphereLaw : Measure E := (sphereLaw (E := E)).map Subtype.val + +end NoiselessRegression + +end InlineMainProof + +open scoped ENNReal NNReal RealInnerProductSpace Topology MatrixOrder Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace Matrix +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments + +section GaussianGraph + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def vectorSmoothing (ν : Measure E) (m : ℕ) (φ : (Fin m → ℝ) → ℝ≥0∞) + (z : (Fin m → E) × (Fin m → ℝ)) : ℝ≥0∞ := + ∫⁻ t, φ (fun j => z.2 j - ⟪t, z.1 j⟫) ∂ν + +end GaussianGraph + +section + +abbrev Label (m : ℕ) := EuclideanSpace ℝ (Fin m) + +def ballKernel (m : ℕ) (η : ℝ) (y : Fin m → ℝ) : ℝ≥0∞ := + (Metric.closedBall (0 : Label m) η).indicator + (fun _ => (volume (Metric.closedBall (0 : Label m) η))⁻¹) (WithLp.toLp 2 y) + +section BallDensity + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def rowMap {m : ℕ} (A : Fin m → E) : E →L[ℝ] Label m := + (PiLp.continuousLinearEquiv 2 ℝ (fun _ : Fin m => ℝ)).symm.toContinuousLinearMap.comp + (ContinuousLinearMap.pi (fun j => innerSL ℝ (A j))) + +def ballAverage (ν : Measure E) (m : ℕ) (η : ℝ) + (z : (Fin m → E) × Label m) : ℝ≥0∞ := + vectorSmoothing ν m (ballKernel m η) (z.1, WithLp.ofLp z.2) + +def lowerDensity (ν : Measure E) (m : ℕ) (z : (Fin m → E) × Label m) : ℝ≥0∞ := + liminf (fun n : ℕ => ballAverage ν m ((n : ℝ) + 1)⁻¹ z) atTop + +end BallDensity + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def AllBallMass (ν : Measure E) (K a : ℝ) : Prop := + ∀ b : E, ∀ t : ℝ, 0 < t → ν (Metric.closedBall b t) ≤ ENNReal.ofReal (K * t ^ a) + +end + +section Rotations + +variable (E : Type*) [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + +abbrev Rotation := unitary (E →L[ℝ] E) + +instance rotationMeasurableSpace : MeasurableSpace (Rotation E) := borel (Rotation E) + +instance rotationBorelSpace : BorelSpace (Rotation E) := ⟨rfl⟩ + +instance rotationCompact : CompactSpace (Rotation E) := by + apply isCompact_iff_compactSpace.mp + apply Metric.isCompact_of_isClosed_isBounded isClosed_unitary + apply (Metric.isBounded_closedBall (x := (0 : E →L[ℝ] E)) (r := 1)).subset (s := (unitary (E →L[ℝ] E) : Set (E →L[ℝ] E))) + intro U hU + rw [Metric.mem_closedBall, dist_zero_right] + by_cases h : Subsingleton E + · have := h + simp + · have : Nontrivial E := not_subsingleton_iff_nontrivial.mp h + exact (CStarRing.norm_of_mem_unitary hU).le + +def rotationLaw : Measure (Rotation E) := + ((Measure.haar : Measure (Rotation E)) Set.univ)⁻¹ • Measure.haar + +variable {E} + +variable [MeasurableSpace E] [BorelSpace E] + +def rotateRows {ι : Type*} (O : Rotation E) (v : ι → E) : ι → E := + fun i => (O : E →L[ℝ] E) (v i) + +end Rotations + +section Triangular + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] + +def coordinateMap {m : ℕ} (A : Fin m → E) : E →ₗ[ℝ] (Fin m → ℝ) := + (WithLp.linearEquiv 2 ℝ (Fin m → ℝ)) ∘ₗ (rowMap A).toLinearMap + +end Triangular + +section CoordinateDensity + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] + [MeasurableSpace E] [BorelSpace E] + +def coordinateDensity (ν : Measure E) (m : ℕ) (z : (Fin m → E) × (Fin m → ℝ)) : ℝ≥0∞ := + lowerDensity ν m (z.1, WithLp.toLp 2 z.2) + +end CoordinateDensity + +section + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def frameLaw {m : ℕ} (u : Fin m → E) : Measure (Fin m → E) := + (rotationLaw E).map (fun O => rotateRows O u) + +end + +section + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def rieszKernel (α : ℝ) (z s : E) : ℝ≥0∞ := (ENNReal.ofReal ‖s-z‖)^(-α) + +def rieszPotential (α : ℝ) (h : E → ℝ≥0∞) : ℝ≥0∞ := + ⨆ z : E, ∫⁻ s, h s*rieszKernel α z s ∂NoiselessRegression.ambientSphereLaw + +end + +section + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def mixRows {k : ℕ} (M : Matrix (Fin k) (Fin k) ℝ) (X : Fin k → E) : Fin k → E := + fun i => ∑ j, M i j • X j + +def polarRadial {k : ℕ} (X : Fin k → E) : Matrix (Fin k) (Fin k) ℝ := + CFC.sqrt (Matrix.gram ℝ X) + +def rawPolarRows {k : ℕ} (X : Fin k → E) : Fin k → E := + mixRows (polarRadial X)⁻¹ X + +def polarRows {k : ℕ} (u X : Fin k → E) : Fin k → E := by + classical + exact if LinearIndependent ℝ X then rawPolarRows X else u + +end + +section + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def unitBallVolume (k : ℕ) : ℝ≥0∞ := (volume : Measure (Label k)) (Metric.closedBall 0 1) + +def unitBallLaw (k : ℕ) : Measure (Label k) := + (unitBallVolume k)⁻¹ • volume.restrict (Metric.closedBall 0 1) + +def normalizedDensity (ν : Measure E) (k : ℕ) (u : Fin k → E) + (z : (Fin k → E) × Label k) : ℝ≥0∞ := + unitBallVolume k * lowerDensity ν k (polarRows u z.1,z.2) + +def sphereWeightedRestriction (h : E → ℝ≥0∞) (H : Set E) : Measure E := + (NoiselessRegression.ambientSphereLaw.withDensity h).restrict H + +end + +section + +universe u + +variable {E : Type u} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def capMeasure (c : E) (r : ℝ) : Measure E := + (NoiselessRegression.ambientSphereLaw (Metric.closedBall c r))⁻¹ • + NoiselessRegression.ambientSphereLaw.restrict (Metric.closedBall c r) + +structure CapDictionary (c : E) (r α : ℝ) where + I : Type u + countable : Countable I + center : I → E + radius : I → ℝ + center_norm : ∀ i, ‖center i‖ = 1 + radius_pos : ∀ i, 0 < radius i + radius_le : ∀ i, radius i ≤ r + parent : I + parent_center : center parent = c + parent_radius : radius parent = r + proper : ∀ R : ℝ, {i | (r/radius i)^α ≤ R}.Finite + cover : ∀ (s : E), ‖s‖ = 1 → ∀ t : ℝ, 0 < t → t ≤ 1/4 → + ∃ i, 4*r*t ≤ radius i ∧ radius i < 8*r*t ∧ dist s (center i) ≤ radius i/2 + +end + +section + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def radialLabel {k : ℕ} (X : Fin k → E) (y : Label k) : Label k := + WithLp.toLp 2 (polarRadial X *ᵥ y.ofLp) + +def capKernelValue {k : ℕ} (K : (Fin k → E) × Label k → ℝ≥0∞) (s : E) : ℝ≥0∞ := + ∫⁻ X, K (X,rowMap X s) ∂Measure.pi (fun _ => stdGaussian E) + +def capReferenceLabel {k : ℕ} (c : E) (r : ℝ) (X : Fin k → E) (z : Label k) : Label k := + rowMap X c + r • radialLabel X z + +def capReference {k : ℕ} (K : (Fin k → E) × Label k → ℝ≥0∞) (c : E) (r : ℝ) : ℝ≥0∞ := + ∫⁻ X, ∫⁻ z, K (X,capReferenceLabel c r X z) ∂unitBallLaw k ∂Measure.pi (fun _ => stdGaussian E) + +end + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +def fractionalBlock {J : Type*} [Fintype J] {k : ℕ} + (Q : J → (Fin k → E) × Label k → ℝ≥0∞) (f : J → E → ℝ≥0∞) (s : E) : ℝ≥0∞ := + ∫⁻ X, ∑ j, Q j (X,rowMap X s)*f j s ∂Measure.pi (fun _ => stdGaussian E) + +end ProjectionMoments + +open MeasureTheory ProbabilityTheory Set Filter unitInterval +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression + +namespace Learner + +section + +universe u + +variable {d M T : ℕ} {Ω : Type u} + +abbrev TaggedState (M T : ℕ) := Sum (State M) (Fin (T+1) × State M) + +instance taggedMeasurableSpace : MeasurableSpace (TaggedState M T) := ⊤ + +def taggedStart (a : Bool × State M) : TaggedState M T := + if a.1 then .inr (⟨0,by omega⟩,a.2) else .inl a.2 + +end + +universe u + +variable {d M T : ℕ} {Ω : Type u} [MeasurableSpace Ω] + +structure MeasurableRules (L : Learner d M T Ω) : Prop where + initial : Measurable L.initialChoice + transition : ∀ t j, Measurable (fun z : Ω × (Vector d × ℝ) => L.transition t z.1 j z.2) + output : ∀ t j, Measurable (fun ω => L.output t ω j) + +end Learner + +structure FiniteKernelLearner (d M T : ℕ) where + initial : Measure (Bool × State M) + initial_probability : IsProbabilityMeasure initial + transition : ℕ → State M → (Vector d × ℝ) → Measure (Bool × State M) + transition_probability : ∀ t j obs, IsProbabilityMeasure (transition t j obs) + output : ℕ → State M → Measure (UnitSphere d) + output_probability : ∀ t j, IsProbabilityMeasure (output t j) + +namespace FiniteKernelLearner + +variable {d M T : ℕ} + +structure CompletedRules (K : FiniteKernelLearner d M T) : Prop where + transition : ∀ t j a, AEMeasurable (fun obs => K.transition t j obs {a}) (observationReference d) + +end FiniteKernelLearner + +section + +variable {J O : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] + [MeasurableSpace O] + +def kernelRun (P : ℕ → J → O → Measure J) : (n : ℕ) → J → (Fin n → O) → Measure J + | 0, j, _ => Measure.dirac j + | n+1, j, obs => (kernelRun P n j (Fin.init obs)).bind (fun a => P (n+1) a (obs (Fin.last n))) + +end + +namespace FiniteKernelLearner + +section + +open Learner + +variable {d M T : ℕ} + +abbrev Tape (M T : ℕ) := (Bool × State M) × ((Fin T → I) × I) + +def destination (t : ℕ) (h : t ≤ T) (a : Bool × State M) : TaggedState M T := + if a.1 then .inr (⟨t,by omega⟩,a.2) else .inl a.2 + +def taggedKernel (K : FiniteKernelLearner d M T) (t : ℕ) : + TaggedState M T → (Vector d × ℝ) → Measure (TaggedState M T) + | .inr a, _ => Measure.dirac (.inr a) + | .inl j, obs => if ht : t ≤ T then (K.transition t j obs).map (destination t ht) + else Measure.dirac (.inl j) + +def terminalOutput (K : FiniteKernelLearner d M T) : TaggedState M T → Measure (UnitSphere d) + | .inl j => K.output T j + | .inr (t,j) => K.output t j + +end + +open Learner + +variable {d M T : ℕ} + +abbrev Result (d M : ℕ) := (ℕ × State M) × UnitSphere d + +def terminalTag : TaggedState M T → ℕ × State M + | .inl j => (T,j) + | .inr (t,j) => (t,j) + +def terminalJointOutput (K : FiniteKernelLearner d M T) (j : TaggedState M T) : Measure (Result d M) := + (K.terminalOutput j).map (fun y => (terminalTag j,y)) + +def jointExperimentLaw (K : FiniteKernelLearner d M T) (obs : Fin T → (Vector d × ℝ)) : Measure (Result d M) := + K.initial.bind (fun a => (kernelRun K.taggedKernel T (taggedStart a) obs).bind K.terminalJointOutput) + +def uniformSuccess (K : FiniteKernelLearner d M T) (ε : ℝ) : ℝ≥0∞ := + ∫⁻ z : UnitSphere d × Samples d T, + K.jointExperimentLaw (fun i => (z.2 i,⟪z.1.val,z.2 i⟫)) + {r | angularError z.1 r.2 ≤ ε} ∂((uniformSphere d).prod (sampleLaw d T)) + +def uniformFixedSuccess (K : FiniteKernelLearner d M T) (ε : ℝ) (t : ℕ) : ℝ≥0∞ := + ∫⁻ z : UnitSphere d × Samples d T, + K.jointExperimentLaw (fun i => (z.2 i,⟪z.1.val,z.2 i⟫)) + {r | r.1.1 = t ∧ angularError z.1 r.2 ≤ ε} ∂((uniformSphere d).prod (sampleLaw d T)) + +end FiniteKernelLearner + +section + +universe u + +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] + +namespace Learner + +variable {d M T : ℕ} {Ω : Type u} + +def uniformFixedSuccess [MeasurableSpace Ω] (L : Learner d M T Ω) (ρ : Measure Ω) + (ε : ℝ) (t : ℕ) : ℝ≥0∞ := + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) + {z | (L.terminal z.1 z.2.1 z.2.2).1 = t ∧ angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + +end Learner + +end + +namespace FiniteKernelLearner + +section + +universe u + +variable {d M T : ℕ} + +def seededSuccess {Ξ : Type u} [MeasurableSpace Ξ] + (K : Ξ → FiniteKernelLearner d M T) (ρ : Measure Ξ) (ε : ℝ) : ℝ≥0∞ := + ∫⁻ ξ, (K ξ).uniformSuccess ε ∂ρ + +def seededFixedSuccess {Ξ : Type u} [MeasurableSpace Ξ] + (K : Ξ → FiniteKernelLearner d M T) (ρ : Measure Ξ) (ε : ℝ) (t : ℕ) : ℝ≥0∞ := + ∫⁻ ξ, (K ξ).uniformFixedSuccess ε t ∂ρ + +def FixedQuadraticMemory : Prop := + ∀ A₀ : ℝ, 0 < A₀ → ∃ c : ℝ, 0 < c ∧ ∃ d₀ : ℕ, + ∀ d : ℕ, d₀ ≤ d → ∀ M T : ℕ, (M : ℝ) ≤ A₀ * (d : ℝ)^2 → + ∀ ε : ℝ, 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + (2/3 : ℝ≥0∞) ≤ seededSuccess K ρ ε → + c*(d:ℝ)*Real.log (1/ε) ≤ (T:ℝ) + +end + +universe u + +variable {d M T : ℕ} {Ξ : Type u} [MeasurableSpace Ξ] + +def conditionalSuccess (K : FiniteKernelLearner d M T) (ε : ℝ) + (s : UnitSphere d) (x : Samples d T) : ℝ≥0∞ := + K.jointExperimentLaw (fun i => (x i,⟪s.val,x i⟫)) {r | Learner.angularError s r.2 ≤ ε} + +def seededPointwiseSuccess (K : Ξ → FiniteKernelLearner d M T) (ρ : Measure Ξ) + (ε : ℝ) (s : UnitSphere d) : ℝ≥0∞ := + ∫⁻ z : Ξ × Samples d T, (K z.1).conditionalSuccess ε s z.2 ∂ρ.prod (sampleLaw d T) + +def JointSuccessMeasurable (K : Ξ → FiniteKernelLearner d M T) (ρ : Measure Ξ) (ε : ℝ) : Prop := + AEMeasurable (fun z : UnitSphere d × (Ξ × Samples d T) => + (K z.2.1).conditionalSuccess ε z.1 z.2.2) + ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) + +def SubquadraticMemoryWithPointwise : Prop := + ∃ c : ℝ, 0 < c ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d : ℝ)) (fun d => (d:ℝ)^2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d (M d) T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + ((2/3 : ℝ≥0∞) ≤ seededSuccess K ρ ε ∨ + (JointSuccessMeasurable K ρ ε ∧ ∀ s, (2/3 : ℝ≥0∞) ≤ seededPointwiseSuccess K ρ ε s)) → + c*(d:ℝ)*Real.log (1/ε) ≤ (T:ℝ) + +end FiniteKernelLearner + +end NoiselessRegression + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace + +open NoiselessRegression NoiselessRegression.FiniteKernelLearner + +open scoped ENNReal NNReal RealInnerProductSpace Topology + +universe u + +namespace ProjectionMoments + +def IntegratedFrameMoment : Prop := + ∃ C : ℝ, 1 ≤ C ∧ ∀ (d k q : ℕ) (β K R : ℝ) + (ν : Measure (EuclideanSpace ℝ (Fin d))) [IsFiniteMeasure ν] + (z : EuclideanSpace ℝ (Fin d)) (u : Fin k → EuclideanSpace ℝ (Fin d)), + 1 ≤ k → 2 ≤ q → k+q ≤ d → 0 < β → β ≤ d → + 1 ≤ β-k-((q:ℝ)-2) → 0 ≤ K → 0 < R → + ν.support ⊆ Metric.closedBall z R → AllBallMass ν K β → + Orthonormal ℝ u → + (∀ᵐ A ∂frameLaw u, ν.map (coordinateMap A) ≪ (volume : Measure (Fin k → ℝ))) → + Measurable (coordinateDensity ν k) ∧ + (∀ᵐ A ∂frameLaw u, + (volume : Measure (Fin k → ℝ)).withDensity (fun y => coordinateDensity ν k (A,y)) = + ν.map (coordinateMap A)) ∧ + (∀ (A : Fin k → EuclideanSpace ℝ (Fin d)), Orthonormal ℝ A → + ∀ y : Fin k → ℝ, + R < ‖WithLp.toLp 2 (y-coordinateMap A z)‖ → coordinateDensity ν k (A,y) = 0) ∧ + (∫⁻ A, ∫⁻ y : Fin k → ℝ, coordinateDensity ν k (A,y)^q ∂volume ∂frameLaw u) ^ (1/(q:ℝ)) ≤ + ENNReal.ofReal (C^d * (C*Real.sqrt d)^((k:ℝ)*(1-1/(q:ℝ))) * + K * R^(β-(k:ℝ)*(1-1/(q:ℝ)))) + +def NormalizedUnitBallMoment : Prop := + ∀ D : ℝ, 0 < D → + ∃ C_D : ℝ, 0 < C_D ∧ ∀ d : ℕ, 32 ≤ d → + let k := d/16 + let lam : ℝ := ((d:ℝ)-1)/2 + ∀ (ν : Measure (EuclideanSpace ℝ (Fin d))) [IsFiniteMeasure ν] + (u : Fin k → EuclideanSpace ℝ (Fin d)), + ν Set.univ ≤ 1 → ν.support ⊆ Metric.closedBall 0 1 → + AllBallMass ν (D^d) lam → Orthonormal ℝ u → + (∀ᵐ X ∂Measure.pi (fun _ : Fin k => stdGaussian (EuclideanSpace ℝ (Fin d))), + ν.map (rowMap (polarRows u X)) ≪ (volume : Measure (Label k))) → + Measurable (normalizedDensity ν k u) ∧ + (∀ᵐ X ∂Measure.pi (fun _ : Fin k => stdGaussian (EuclideanSpace ℝ (Fin d))), + ((unitBallVolume k)⁻¹ • (volume : Measure (Label k))).withDensity + (fun y => normalizedDensity ν k u (X,y)) = ν.map (rowMap (polarRows u X))) ∧ + (∀ X y, 1 < ‖y‖ → normalizedDensity ν k u (X,y) = 0) ∧ + (∫⁻ X, ∫⁻ y, normalizedDensity ν k u (X,y)^k ∂unitBallLaw k + ∂Measure.pi (fun _ => stdGaussian (EuclideanSpace ℝ (Fin d)))) ≤ + ENNReal.ofReal (Real.exp (C_D*d*k)) + +def AllRadiiSphereMoment : Prop := + ∃ C : ℝ, 1 ≤ C ∧ ∀ d : ℕ, 16 ≤ d → + let k := d/4 + let β : ℝ := (d:ℝ)-1-k + ∀ f : EuclideanSpace ℝ (Fin d) → ℝ≥0∞, + Measurable f → (∀ s, f s ≤ 1) → + ∀ K : ℝ, 0 ≤ K → + AllBallMass (NoiselessRegression.ambientSphereLaw.withDensity f) K β → + ∀ z : EuclideanSpace ℝ (Fin d), ∀ R : ℝ, 0 < R → + ∀ u : Fin k → EuclideanSpace ℝ (Fin d), Orthonormal ℝ u → + let μ := sphereWeightedRestriction f (Metric.closedBall z R) + Measurable (coordinateDensity μ k) ∧ + (∀ A : Fin k → EuclideanSpace ℝ (Fin d), Orthonormal ℝ A → + (volume : Measure (Fin k → ℝ)).withDensity (fun y => coordinateDensity μ k (A,y)) = + μ.map (coordinateMap A)) ∧ + (∀ A : Fin k → EuclideanSpace ℝ (Fin d), Orthonormal ℝ A → + ∀ y : Fin k → ℝ, R < ‖WithLp.toLp 2 (y-coordinateMap A z)‖ → + coordinateDensity μ k (A,y) = 0) ∧ + (∫⁻ A, ∫⁻ y : Fin k → ℝ, coordinateDensity μ k (A,y)^k ∂volume ∂frameLaw u) ^ (1/(k:ℝ)) ≤ + ENNReal.ofReal (C^d*(C*Real.sqrt d)^((k:ℝ)*(1-1/(k:ℝ)))* + K*R^(β-(k:ℝ)*(1-1/(k:ℝ)))) + +def PositiveCapDomination : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ d : ℕ, 32 ≤ d → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + ∀ (c : EuclideanSpace ℝ (Fin d)), ‖c‖ = 1 → + ∀ r : ℝ, 0 < r → r ≤ 2 → ∀ N : ℕ, + ∀ K : Fin N → (Fin k → EuclideanSpace ℝ (Fin d)) × Label k → ℝ≥0∞, + (∀ j, Measurable (K j)) → (∀ z, ∑ j, K j z ≤ 1) → + (∑ j, capReference (K j) c r) ≤ 1 ∧ + ∀ j, ∃ D : CapDictionary c r α, ∃ a : D.I → ℝ, + (∀ i, 0 ≤ a i) ∧ Summable (fun i => a i*(r/D.radius i)^α) ∧ + (∑' i, a i*(r/D.radius i)^α) ≤ Real.exp (C*d)*(capReference (K j) c r).toReal^(1-1/(k:ℝ)) ∧ + (capMeasure c r).withDensity (capKernelValue (K j)) ≤ + Measure.sum (fun i => ENNReal.ofReal (a i) • capMeasure (D.center i) (D.radius i)) ∧ + (Measure.sum (fun i => ENNReal.ofReal (a i) • capMeasure (D.center i) (D.radius i))) Set.univ < ∞ + +def DeterministicOffsetDensity : Prop := + ∃ C : ℝ, 1 ≤ C ∧ ∀ d : ℕ, 16 ≤ d → + let k := d/8 + let α : ℝ := (d:ℝ)/2 + ∀ h : EuclideanSpace ℝ (Fin d) → ℝ≥0∞, Measurable h → (∀ s, h s ≤ 1) → + ∀ z : EuclideanSpace ℝ (Fin d), ∀ ρ : ℝ, 0 < ρ → + ∀ H : Set (EuclideanSpace ℝ (Fin d)), MeasurableSet H → H ⊆ Metric.closedBall z ρ → + rieszPotential α h < ∞ ∧ + Measurable (lowerDensity (sphereWeightedRestriction h H) k) ∧ + (∀ A : Fin k → EuclideanSpace ℝ (Fin d), LinearIndependent ℝ A → + volume.withDensity (fun y => lowerDensity (sphereWeightedRestriction h H) k (A,y)) = + (sphereWeightedRestriction h H).map (rowMap A)) ∧ + (∀ b : Label k, (∫⁻ A, (lowerDensity (sphereWeightedRestriction h H) k (A,rowMap A z+b))^k + ∂Measure.pi (fun _ => stdGaussian (EuclideanSpace ℝ (Fin d))))^(1/(k:ℝ)) ≤ + ENNReal.ofReal (C^d) * rieszPotential α h * ENNReal.ofReal (ρ^(α-k))) ∧ + (∀ A y, ‖rowMap A‖*ρ < ‖y-rowMap A z‖ → + lowerDensity (sphereWeightedRestriction h H) k (A,y) = 0) + +def AllRadiiBlockBound : Prop := + ∃ C : ℝ, 1 ≤ C ∧ ∀ d : ℕ, 16 ≤ d → + let k := d/4 + let β : ℝ := (d:ℝ)-1-k + ∀ N : ℕ, ∀ f : Fin N → EuclideanSpace ℝ (Fin d) → ℝ≥0∞, + (∀ j, Measurable (f j)) → (∀ j s, f j s ≤ 1) → + ∀ K : ℝ, 0 ≤ K → + (∀ j, AllBallMass (NoiselessRegression.ambientSphereLaw.withDensity (f j)) K β) → + ∀ Q : Fin N → (Fin k → EuclideanSpace ℝ (Fin d)) × Label k → ℝ≥0∞, + (∀ j, Measurable (Q j)) → (∀ z, ∑ j, Q j z ≤ 1) → + AllBallMass (NoiselessRegression.ambientSphereLaw.withDensity (fractionalBlock Q f)) + (C^d*(N:ℝ)^(1/(k:ℝ))*K) β + +def HaarStreamingCost : Prop := + ∃ C : ℝ, 1 ≤ C ∧ ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + let k := d/4 + let Nstar : ℝ := ((k:ℝ)+2)*2^M + seededSuccess K ρ ε ≤ ENNReal.ofReal + (C^d*ε^k*(C^d*Nstar^(1/(k:ℝ)))^((T+k-1)/k)) + +def RieszStreamingCost : Prop := + ∃ C₀ : ℝ, 1 ≤ C₀ ∧ ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + let q := d/8 + let W : ℝ := ((T:ℝ)+2)*2^M + seededSuccess K ρ ε ≤ ENNReal.ofReal + (C₀^d*ε^((d:ℝ)/2-1)*(1+C₀^d*(1+Real.log (1/ε))*W^(1/(q:ℝ)))^((T+q-1)/q)) + +def CapFixedStoppingCost : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ d M T : ℕ, 32 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + ∀ t : ℕ, t ≤ T → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + seededFixedSuccess K ρ ε t ≤ ENNReal.ofReal + (Real.exp (C*d)*(ε/2)^α*(Real.exp (C*d)*(2:ℝ)^((M:ℝ)/k))^((t+k-1)/k)) + +def CapTotalStoppingCost : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ d M T : ℕ, 32 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + seededSuccess K ρ ε ≤ ENNReal.ofReal + (((T:ℝ)+1)*Real.exp (C*d)*(ε/2)^α* + (Real.exp (C*d)*(2:ℝ)^((M:ℝ)/k))^((T+k-1)/k)) + +def CapFixedStoppingAsymptotic : Prop := + ∃ C : ℝ, 0 < C ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d:ℝ)) (fun d => (d:ℝ)^2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d (M d) T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + ∀ t : ℕ, t ≤ T → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + seededFixedSuccess K ρ ε t ≤ ENNReal.ofReal + (Real.exp (C*d*(1+((t+k-1)/k:ℕ)))*(ε/2)^α) + +def CapTotalStoppingAsymptotic : Prop := + ∃ C₁ C₂ : ℝ, 0 < C₁ ∧ 0 < C₂ ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d:ℝ)) (fun d => (d:ℝ)^2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d (M d) T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + seededSuccess K ρ ε ≤ ENNReal.ofReal + (((T:ℝ)+1)*Real.exp (C₁*d+C₂*T-(d:ℝ)*Real.log (1/ε)/3)) + +def KernelModelBridge : Prop := + ∀ d M T : ℕ, 3 ≤ d → ∀ K : FiniteKernelLearner d M T, K.CompletedRules → + ∃ (ρ : Measure (Tape M T)) (L : Learner d M T (Tape M T)), + IsProbabilityMeasure ρ ∧ L.MeasurableRules ∧ L.Admissible ρ ∧ + (∀ ε, L.uniformSuccess ρ ε = K.uniformSuccess ε) ∧ + (∀ ε t, L.uniformFixedSuccess ρ ε t = K.uniformFixedSuccess ε t) + +def MainStatement : Prop := + IntegratedFrameMoment ∧ NormalizedUnitBallMoment ∧ AllRadiiSphereMoment ∧ + PositiveCapDomination ∧ DeterministicOffsetDensity ∧ AllRadiiBlockBound ∧ + HaarStreamingCost.{u} ∧ RieszStreamingCost.{u} ∧ CapFixedStoppingCost.{u} ∧ + CapTotalStoppingCost.{u} ∧ CapFixedStoppingAsymptotic.{u} ∧ + CapTotalStoppingAsymptotic.{u} ∧ KernelModelBridge ∧ + NoiselessRegression.FiniteKernelLearner.SubquadraticMemoryWithPointwise.{u} ∧ + NoiselessRegression.FiniteKernelLearner.FixedQuadraticMemory.{u} + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Polar.lean b/lean/OAI/Probability/ProjectionMoments/Polar.lean new file mode 100644 index 0000000000000000000000000000000000000000..71c10bd73a999c6b3661e2c448e49f80d2acd07d --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Polar.lean @@ -0,0 +1,270 @@ +import OAI.Probability.ProjectionMoments.RieszPotential + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace Matrix +open scoped ENNReal NNReal RealInnerProductSpace Topology MatrixOrder Matrix.Norms.L2Operator +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +instance realMatrixMeasurableSpace (k : ℕ) : MeasurableSpace (Matrix (Fin k) (Fin k) ℝ) := + inferInstanceAs (MeasurableSpace (Fin k → Fin k → ℝ)) +instance realMatrixBorelSpace (k : ℕ) : BorelSpace (Matrix (Fin k) (Fin k) ℝ) := + inferInstanceAs (BorelSpace (Fin k → Fin k → ℝ)) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma mixRows_mul [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {k : ℕ} (M N : Matrix (Fin k) (Fin k) ℝ) (X : Fin k → E) : + mixRows (M*N) X = mixRows M (mixRows N X) := by + ext i + simp only [mixRows, Matrix.mul_apply, Finset.sum_smul, Finset.smul_sum, smul_smul] + exact Finset.sum_comm + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[simp] lemma mixRows_one [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {k : ℕ} (X : Fin k → E) : mixRows 1 X = X := by + ext i + simp [mixRows, Matrix.one_apply] + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma gram_mixRows [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {k : ℕ} (M : Matrix (Fin k) (Fin k) ℝ) (X : Fin k → E) : + Matrix.gram ℝ (mixRows M X) = M * Matrix.gram ℝ X * M.transpose := by + ext i j + simp only [Matrix.gram_apply, mixRows, inner_sum, sum_inner, real_inner_smul_left, + real_inner_smul_right, Matrix.mul_apply, Matrix.transpose_apply, Finset.sum_mul] + apply Finset.sum_congr rfl + intro a ha + apply Finset.sum_congr rfl + intro b hb + ring + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma continuous_polarRadial [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {k : ℕ} : Continuous (polarRadial (E := E) (k := k)) := by + apply CFC.continuousOn_sqrt.comp_continuous + · exact continuous_matrix (fun i j => by simp only [Matrix.gram_apply]; fun_prop) + · intro X + exact (Matrix.posSemidef_gram ℝ X).nonneg + +lemma measurable_matrix_inverse {k : ℕ} : + Measurable (fun M : Matrix (Fin k) (Fin k) ℝ => M⁻¹) := by + simp only [Matrix.inv_def, Ring.inverse_eq_inv] + apply Measurable.of_eval + intro i + apply Measurable.of_eval + intro j + simp only [Matrix.smul_apply, smul_eq_mul, Matrix.adjugate_apply] + fun_prop + +lemma measurable_rawPolarRows {k : ℕ} : Measurable (rawPolarRows (E := E) (k := k)) := by + have hH := measurable_matrix_inverse.comp (continuous_polarRadial (E := E) (k := k)).measurable + apply Measurable.of_eval + intro i + change Measurable (fun X : Fin k → E => ∑ j, (polarRadial X)⁻¹ i j • X j) + apply Finset.measurable_sum + intro j hj + have hh : Measurable (fun X : Fin k → E => (polarRadial X)⁻¹ i j) := + (measurable_pi_apply j).comp ((measurable_pi_apply i).comp hH) + exact hh.smul (measurable_pi_apply j) + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma polarRadial_squared [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {k : ℕ} (X : Fin k → E) : + polarRadial X * polarRadial X = Matrix.gram ℝ X := + CFC.sqrt_mul_sqrt_self _ (Matrix.posSemidef_gram ℝ X).nonneg + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma polarRadial_pos [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {k : ℕ} (X : Fin k → E) : 0 ≤ polarRadial X := CFC.sqrt_nonneg _ + +omit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma polarRadial_isUnit [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {k : ℕ} {X : Fin k → E} (hX : LinearIndependent ℝ X) : + IsUnit (polarRadial X) := + (CFC.isUnit_sqrt_iff _ (Matrix.posSemidef_gram ℝ X).nonneg).mpr + (Matrix.posDef_gram_iff_linearIndependent.mpr hX).isUnit + +lemma rawPolarRows_orthonormal {k : ℕ} {X : Fin k → E} (hX : LinearIndependent ℝ X) : + Orthonormal ℝ (rawPolarRows X) := by + have hH := polarRadial_isUnit hX + have hdet : IsUnit (polarRadial X).det := (Matrix.isUnit_iff_isUnit_det _).mp hH + have hsym : (polarRadial X)⁻¹.transpose = (polarRadial X)⁻¹ := by + have hh : (polarRadial X).IsHermitian := (polarRadial_pos X).isSelfAdjoint + simpa only [Matrix.IsHermitian, Matrix.conjTranspose_eq_transpose_of_trivial] using hh.inv + have hgram : Matrix.gram ℝ (rawPolarRows X) = 1 := by + rw [rawPolarRows, gram_mixRows, hsym, ← polarRadial_squared, + ← mul_assoc, Matrix.nonsing_inv_mul _ hdet, one_mul, Matrix.mul_nonsing_inv _ hdet] + apply orthonormal_iff_ite.mpr + intro i j + simpa only [Matrix.gram_apply, Matrix.one_apply] using congrFun (congrFun hgram i) j + +lemma polar_reconstruction {k : ℕ} {X : Fin k → E} (hX : LinearIndependent ℝ X) : + mixRows (polarRadial X) (rawPolarRows X) = X := by + rw [rawPolarRows, ← mixRows_mul, Matrix.mul_nonsing_inv _ + ((Matrix.isUnit_iff_isUnit_det _).mp (polarRadial_isUnit hX)), mixRows_one] + +omit [MeasurableSpace E] [BorelSpace E] in +lemma gram_rotateRows [MeasurableSpace E] [BorelSpace E] {k : ℕ} (X : Fin k → E) (O : Rotation E) : + Matrix.gram ℝ (rotateRows O X) = Matrix.gram ℝ X := by + ext i j + exact (Unitary.linearIsometryEquiv O).inner_map_map (X i) (X j) + +lemma polarRadial_rotateRows {k : ℕ} (X : Fin k → E) (O : Rotation E) : + polarRadial (rotateRows O X) = polarRadial X := by + simp only [polarRadial, gram_rotateRows] + +lemma rawPolarRows_rotateRows {k : ℕ} (X : Fin k → E) (O : Rotation E) : + rawPolarRows (rotateRows O X) = rotateRows O (rawPolarRows X) := by + ext i + simp only [rawPolarRows, polarRadial_rotateRows, mixRows, rotateRows, map_sum, map_smul] + +lemma measurableSet_linearIndependent {k : ℕ} : + MeasurableSet {X : Fin k → E | LinearIndependent ℝ X} := by + simp only [← Matrix.det_gram_ne_zero_iff_linearIndependent] + have hg : Continuous (fun X : Fin k → E => Matrix.gram ℝ X) := + continuous_matrix (fun i j => by simp only [Matrix.gram_apply]; fun_prop) + exact (isClosed_eq hg.matrix_det continuous_const).measurableSet.compl + +lemma measurable_polarRows {k : ℕ} (u : Fin k → E) : Measurable (polarRows u) := by + classical + exact Measurable.ite measurableSet_linearIndependent measurable_rawPolarRows measurable_const + +lemma polarRows_orthonormal {k : ℕ} {u : Fin k → E} (hu : Orthonormal ℝ u) + (X : Fin k → E) : Orthonormal ℝ (polarRows u X) := by + by_cases hX : LinearIndependent ℝ X + · simpa only [polarRows, ite_eq_left hX] using rawPolarRows_orthonormal hX + · simpa only [polarRows, ite_eq_right hX] using hu + +lemma polarRows_rotateRows {k : ℕ} (u : Fin k → E) {X : Fin k → E} + (hX : LinearIndependent ℝ X) (O : Rotation E) : + polarRows u (rotateRows O X) = rotateRows O (polarRows u X) := by + have hXO : LinearIndependent ℝ (rotateRows O X) := by + rw [← Matrix.det_gram_ne_zero_iff_linearIndependent, gram_rotateRows, + Matrix.det_gram_ne_zero_iff_linearIndependent] + exact hX + simp only [polarRows, ite_eq_left hX, ite_eq_left hXO, rawPolarRows_rotateRows] + +lemma lintegral_polarRows_eq_frame {k : ℕ} (hk : k ≤ Module.finrank ℝ E) + {u : Fin k → E} (hu : Orthonormal ℝ u) (f : (Fin k → E) → ℝ≥0∞) (hf : Measurable f) : + (∫⁻ X, f (polarRows u X) ∂Measure.pi (fun _ => stdGaussian E)) = ∫⁻ A, f A ∂frameLaw u := by + let γ := Measure.pi (fun _ : Fin k => stdGaussian E) + have hrot (O : Rotation E) : (∫⁻ X, f (polarRows u X) ∂γ) = + ∫⁻ X, f (rotateRows O (polarRows u X)) ∂γ := by + calc + _ = ∫⁻ X, f (polarRows u (rotateRows O X)) ∂γ := by + have hm : Measurable (rotateRows O : (Fin k → E) → (Fin k → E)) := + measurable_rotateRows.comp (measurable_const.prodMk measurable_id) + have hh := lintegral_map (μ := γ) (hf.comp (measurable_polarRows u)) hm + rw [show γ.map (rotateRows O) = γ from gaussianRows_rotation_invariant k O] at hh + exact hh + _ = _ := lintegral_congr_ae (by + filter_upwards [gaussian_rows_ae_linearIndependent k hk] with X hX + rw [polarRows_rotateRows u hX]) + calc + _ = ∫⁻ O, ∫⁻ X, f (rotateRows O (polarRows u X)) ∂γ ∂rotationLaw E := by + simp_rw [← hrot] + simp only [lintegral_const, measure_univ, mul_one] + rfl + _ = ∫⁻ X, ∫⁻ O, f (rotateRows O (polarRows u X)) ∂rotationLaw E ∂γ := by + apply lintegral_lintegral_swap + exact (hf.comp (measurable_rotateRows.comp + (measurable_fst.prodMk ((measurable_polarRows u).comp measurable_snd)))).aemeasurable + _ = ∫⁻ X, ∫⁻ A, f A ∂frameLaw u ∂γ := by + apply lintegral_congr + intro X + rw [frameLaw_eq hu (polarRows_orthonormal hu X), frameLaw] + have hm : Measurable (fun O : Rotation E => rotateRows O (polarRows u X)) := + measurable_rotateRows.comp (measurable_id.prodMk measurable_const) + exact (lintegral_map hf hm).symm + _ = _ := by simp [γ] + +lemma polarRows_law {k : ℕ} (hk : k ≤ Module.finrank ℝ E) + {u : Fin k → E} (hu : Orthonormal ℝ u) : + (Measure.pi (fun _ : Fin k => stdGaussian E)).map (polarRows u) = frameLaw u := by + apply Measure.ext + intro s hs + have hf : Measurable (s.indicator (1 : (Fin k → E) → ℝ≥0∞)) := measurable_const.indicator hs + rw [← lintegral_indicator_one hs, lintegral_map hf (measurable_polarRows u), + lintegral_polarRows_eq_frame hk hu _ hf, lintegral_indicator_one hs] + +end + +lemma euclidean_gaussian_integral (k : ℕ) : + (∫⁻ x : Fin k → ℝ, ENNReal.ofReal (Real.exp (-‖WithLp.toLp 2 x‖^2)) ∂volume) = + ENNReal.ofReal (Real.sqrt Real.pi ^ k) := by + have hex (x : Fin k → ℝ) : Real.exp (-‖WithLp.toLp 2 x‖^2) = + ∏ i, Real.exp (-(x i)^2) := by + rw [EuclideanSpace.norm_sq_eq, ← Finset.sum_neg_distrib, Real.exp_sum] + congr 1 + funext i + simp only [Real.norm_eq_abs, sq_abs] + have hscalar : (∫⁻ x : ℝ, ENNReal.ofReal (Real.exp (-x^2)) ∂volume) = + ENNReal.ofReal (Real.sqrt Real.pi) := by + rw [← ofReal_integral_eq_lintegral_ofReal] + · simpa using congrArg ENNReal.ofReal (integral_gaussian 1) + · simpa using integrable_exp_neg_mul_sq (by norm_num : (0:ℝ) < 1) + · exact Filter.Eventually.of_forall (fun x => (Real.exp_pos _).le) + simp_rw [hex, ENNReal.ofReal_prod_of_nonneg (fun i _ => (Real.exp_pos _).le)] + rw [volume_pi, NoiselessRegression.lintegral_fin_prod (volume : Measure ℝ) k + (fun _ x => ENNReal.ofReal (Real.exp (-x^2))) (fun _ => by fun_prop)] + simp only [hscalar, Finset.prod_const, Finset.card_univ, Fintype.card_fin, + ENNReal.ofReal_pow (Real.sqrt_nonneg _)] + +lemma unit_ball_volume_bound (k : ℕ) (hk : 1 ≤ k) : + (volume : Measure (EuclideanSpace ℝ (Fin k))) (Metric.ball 0 1) ≤ + ENNReal.ofReal ((6 / Real.sqrt k)^k) := by + let r := Real.sqrt (k : ℝ) + have hk0 : (0:ℝ) < k := by exact_mod_cast hk + have hr : 0 < r := Real.sqrt_pos.mpr hk0 + have hr2 : r^2 = k := Real.sq_sqrt hk0.le + have hlower : ENNReal.ofReal (Real.exp (-(k:ℝ))) * + (volume : Measure (EuclideanSpace ℝ (Fin k))) (Metric.ball 0 r) ≤ + ENNReal.ofReal (Real.sqrt Real.pi ^ k) := by + calc + _ = ∫⁻ _x in Metric.ball (0 : EuclideanSpace ℝ (Fin k)) r, + ENNReal.ofReal (Real.exp (-(k:ℝ))) ∂volume := by simp + _ ≤ ∫⁻ x in Metric.ball (0 : EuclideanSpace ℝ (Fin k)) r, + ENNReal.ofReal (Real.exp (-‖x‖^2)) ∂volume := by + apply lintegral_mono_ae + filter_upwards [ae_restrict_mem Metric.isOpen_ball.measurableSet] with x hx + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + have hx' : ‖x‖ ≤ r := by simpa [Metric.mem_ball, dist_zero_right] using (Metric.mem_ball.mp hx).le + nlinarith [norm_nonneg x] + _ ≤ ∫⁻ x : EuclideanSpace ℝ (Fin k), ENNReal.ofReal (Real.exp (-‖x‖^2)) ∂volume := + setLIntegral_le_lintegral _ _ + _ = ENNReal.ofReal (Real.sqrt Real.pi ^ k) := by + rw [← (PiLp.volume_preserving_toLp (Fin k)).map_eq, + lintegral_map (by fun_prop) (by fun_prop)] + exact euclidean_gaussian_integral k + rw [Measure.addHaar_ball_of_pos volume 0 hr, finrank_euclideanSpace_fin] at hlower + have h := ENNReal.toReal_le_of_le_ofReal (by positivity) hlower + simp only [ENNReal.toReal_mul, ENNReal.toReal_ofReal (Real.exp_pos _).le, + ENNReal.toReal_ofReal (pow_nonneg hr.le _)] at h + have hexp : Real.exp (-(k:ℝ)) * Real.exp (k:ℝ) = 1 := by + rw [← Real.exp_add]; simp + have hpos : 0 ≤ ((volume : Measure (EuclideanSpace ℝ (Fin k))) (Metric.ball 0 1)).toReal := + ENNReal.toReal_nonneg + have hnum : Real.exp (k:ℝ) * Real.sqrt Real.pi ^ k ≤ (6:ℝ)^k := by + rw [show (k:ℝ) = (k:ℝ)*1 by ring, Real.exp_nat_mul, ← mul_pow] + apply pow_le_pow_left₀ (by positivity) + have hs : Real.sqrt Real.pi < 2 := (Real.sqrt_lt' (by norm_num)).mpr (by nlinarith [Real.pi_lt_four]) + nlinarith [Real.exp_one_lt_three, Real.exp_pos 1, Real.sqrt_nonneg Real.pi] + have hv : ((volume : Measure (EuclideanSpace ℝ (Fin k))) (Metric.ball 0 1)).toReal ≤ + (6/r)^k := by + rw [div_pow, le_div_iff₀ (pow_pos hr _)] + calc + _ = Real.exp (k:ℝ)*(Real.exp (-(k:ℝ))*r^k* + ((volume : Measure (EuclideanSpace ℝ (Fin k))) (Metric.ball 0 1)).toReal) := by + nlinarith [congrArg (fun t : ℝ => t * (r^k * + ((volume : Measure (EuclideanSpace ℝ (Fin k))) (Metric.ball 0 1)).toReal)) hexp] + _ ≤ Real.exp (k:ℝ)*Real.sqrt Real.pi^k := by simpa only [mul_assoc] using mul_le_mul_of_nonneg_left h (Real.exp_pos (k:ℝ)).le + _ ≤ _ := hnum + exact (ENNReal.le_ofReal_iff_toReal_le measure_ball_lt_top.ne (by positivity)).mpr hv + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Realization.lean b/lean/OAI/Probability/ProjectionMoments/Realization.lean new file mode 100644 index 0000000000000000000000000000000000000000..f3c3fa5ea75cffaf948b04b165536679fd9db810 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Realization.lean @@ -0,0 +1,248 @@ +import OAI.Probability.ProjectionMoments.Kernels + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter unitInterval +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression +namespace FiniteKernelLearner +open Learner +variable {d M T : ℕ} + +structure Realizer (K : FiniteKernelLearner d M T) where + transition : ℕ → State M → (Vector d × ℝ) → I → Bool × State M + transition_measurable : ∀ t j, Measurable (Function.uncurry (transition t j)) + transition_law : ∀ t j obs, volume.map (transition t j obs) = K.transition t j obs + output : ℕ → State M → I → UnitSphere d + output_measurable : ∀ t j, Measurable (output t j) + output_law : ∀ t j, volume.map (output t j) = K.output t j + +lemma exists_realizer (K : FiniteKernelLearner d M T) (hK : K.BorelRules) : Nonempty K.Realizer := by + classical + let j₀ : State M := ⟨0,by simp⟩ + let : IsProbabilityMeasure (K.output 0 j₀) := K.output_probability 0 j₀ + let : Nonempty (UnitSphere d) := nonempty_of_isProbabilityMeasure (K.output 0 j₀) + have ht (t : ℕ) (j : State M) : ∃ f : (Vector d × ℝ) → I → Bool × State M, + Measurable (Function.uncurry f) ∧ ∀ obs, volume.map (f obs) = K.transition t j obs := by + let κ : Kernel (Vector d × ℝ) (Bool × State M) := ⟨K.transition t j,hK.transition t j⟩ + let : IsMarkovKernel κ := ⟨K.transition_probability t j⟩ + exact κ.exists_measurable_map_eq_unitInterval + have ho (t : ℕ) (j : State M) : ∃ g : I → UnitSphere d, Measurable g ∧ volume.map g = K.output t j := by + let : IsProbabilityMeasure (K.output t j) := K.output_probability t j + exact (K.output t j).exists_measurable_map_eq + choose f hf hfl using ht + choose g hg hgl using ho + exact ⟨⟨f,hf,hfl,g,hg,hgl⟩⟩ + +def tapeLaw (K : FiniteKernelLearner d M T) : Measure (Tape M T) := + K.initial.prod ((Measure.pi (fun _ => (volume : Measure I))).prod volume) + +instance tapeLaw_probability (K : FiniteKernelLearner d M T) : IsProbabilityMeasure K.tapeLaw := by + let := K.initial_probability + unfold tapeLaw + infer_instance + +def Realizer.toLearner {K : FiniteKernelLearner d M T} (R : K.Realizer) : Learner d M T (Tape M T) where + initialChoice := Prod.fst + transition := fun t ω j obs => if ht : 0 < t ∧ t ≤ T then + R.transition t j obs (ω.2.1 ⟨t-1,by omega⟩) else (false,j) + output := fun t ω j => R.output t j ω.2.2 + +lemma Realizer.measurableRules {K : FiniteKernelLearner d M T} (R : K.Realizer) : + R.toLearner.MeasurableRules := by + refine ⟨measurable_fst,fun t j => ?_,fun t j => (R.output_measurable t j).comp (by fun_prop)⟩ + dsimp [Realizer.toLearner] + split_ifs with ht + · exact (R.transition_measurable t j).comp (show Measurable (fun z : Tape M T × (Vector d × ℝ) => + (z.2,z.1.2.1 ⟨t-1,by omega⟩)) from by fun_prop) + · exact measurable_const + +def Realizer.taggedTransition {K : FiniteKernelLearner d M T} (R : K.Realizer) (t : ℕ) : + TaggedState M T → (Vector d × ℝ) → I → TaggedState M T + | .inr a, _, _ => .inr a + | .inl j, obs, u => if ht : t ≤ T then destination t ht (R.transition t j obs u) else .inl j + +lemma Realizer.tagged_measurable {K : FiniteKernelLearner d M T} (R : K.Realizer) + (t : ℕ) (j : TaggedState M T) (obs : Vector d × ℝ) : Measurable (R.taggedTransition t j obs) := by + cases j with + | inr a => exact measurable_const + | inl j => + change Measurable (fun u => R.taggedTransition t (.inl j) obs u) + simp only [Realizer.taggedTransition] + split_ifs with ht + · exact (measurable_of_finite (destination t ht)).comp (R.transition_measurable t j).of_uncurry_left + · exact measurable_const + +lemma Realizer.tagged_law {K : FiniteKernelLearner d M T} (R : K.Realizer) + (t : ℕ) (j : TaggedState M T) (obs : Vector d × ℝ) : + volume.map (R.taggedTransition t j obs) = K.taggedKernel t j obs := by + cases j with + | inr a => + change volume.map (fun _ : I => Sum.inr a) = Measure.dirac (.inr a) + simp [Measure.map_const] + | inl j => + change volume.map (fun u => R.taggedTransition t (.inl j) obs u) = _ + simp only [Realizer.taggedTransition,taggedKernel] + split_ifs with ht + · rw [← R.transition_law,Measure.map_map (measurable_of_finite _) + (R.transition_measurable t j).of_uncurry_left] + rfl + · simp [Measure.map_const] + +def Realizer.terminalOutput {K : FiniteKernelLearner d M T} (R : K.Realizer) : + TaggedState M T → I → UnitSphere d + | .inl j => R.output T j + | .inr (t,j) => R.output t j + +lemma Realizer.terminalOutput_measurable {K : FiniteKernelLearner d M T} (R : K.Realizer) + (j : TaggedState M T) : Measurable (R.terminalOutput j) := by + cases j with + | inl j => exact R.output_measurable T j + | inr a => exact R.output_measurable a.1 a.2 + +lemma Realizer.terminalOutput_law {K : FiniteKernelLearner d M T} (R : K.Realizer) + (j : TaggedState M T) : volume.map (R.terminalOutput j) = K.terminalOutput j := by + cases j with + | inl j => exact R.output_law T j + | inr a => exact R.output_law a.1 a.2 + +def experimentLaw (K : FiniteKernelLearner d M T) (obs : Fin T → (Vector d × ℝ)) : Measure (UnitSphere d) := + K.initial.bind (fun a => (kernelRun K.taggedKernel T (taggedStart a) obs).bind K.terminalOutput) + +lemma Realizer.run_eq_coinRun {K : FiniteKernelLearner d M T} (R : K.Realizer) + (s : UnitSphere d) (ω : Tape M T) (x : Samples d T) {n : ℕ} (hn : n ≤ T) : + R.toLearner.run s ω x n = decodeTagged + (coinRun R.taggedTransition n (taggedStart ω.1) + (fun i => (x (Fin.castLE hn i),⟪s.val,x (Fin.castLE hn i)⟫)) + (fun i => ω.2.1 (Fin.castLE hn i))) := by + induction n with + | zero => exact (decode_taggedStart _).symm + | succ n ih => + rw [Learner.run,ih (by omega)] + have hp := fin_prefix_snoc hn (fun i => (x i,⟪s.val,x i⟫)) + rw [hp,fin_prefix_snoc hn ω.2.1,coinRun,Fin.init_snoc,Fin.init_snoc,Fin.snoc_last,Fin.snoc_last] + generalize coinRun R.taggedTransition n (taggedStart ω.1) + (fun i => (x (Fin.castLE (by omega : n ≤ T) i),⟪s.val,x (Fin.castLE (by omega : n ≤ T) i)⟫)) + (fun i => ω.2.1 (Fin.castLE (by omega : n ≤ T) i)) = j + cases j with + | inr a => rfl + | inl j => + simp only [decodeTagged,Realizer.taggedTransition,Realizer.toLearner, + dite_eq_left (by omega : n < T),dite_eq_left (by omega : 0 < n+1 ∧ n+1 ≤ T), + dite_eq_left (by omega : n+1 ≤ T),destination,real_inner_comm,Nat.add_sub_cancel] + split_ifs <;> rfl + +lemma Realizer.estimate_eq_coinRun {K : FiniteKernelLearner d M T} (R : K.Realizer) + (s : UnitSphere d) (ω : Tape M T) (x : Samples d T) : + R.toLearner.estimate s ω x = R.terminalOutput + (coinRun R.taggedTransition T (taggedStart ω.1) (fun i => (x i,⟪s.val,x i⟫)) ω.2.1) ω.2.2 := by + unfold Learner.estimate Learner.terminal + rw [R.run_eq_coinRun s ω x le_rfl] + have hi (i : Fin T) : Fin.castLE le_rfl i = i := Fin.ext rfl + simp only [hi] + generalize coinRun R.taggedTransition T (taggedStart ω.1) (fun i => (x i,⟪s.val,x i⟫)) ω.2.1 = j + cases j <;> rfl + +end FiniteKernelLearner + +lemma map_finite_prod_eq_bind {A B C : Type*} [Fintype A] [MeasurableSpace A] + [MeasurableSingletonClass A] [MeasurableSpace B] [MeasurableSpace C] + (μ : Measure A) (ν : Measure B) [SFinite ν] {f : A × B → C} (hf : Measurable f) : + (μ.prod ν).map f = μ.bind (fun a => ν.map (fun b => f (a,b))) := by + apply Measure.ext_of_lintegral + intro g hg + rw [lintegral_map hg hf,lintegral_prod (fun z => g (f z)) (hg.comp hf).aemeasurable, + Measure.lintegral_bind (measurable_of_finite _).aemeasurable hg.aemeasurable] + apply lintegral_congr + intro a + exact (lintegral_map hg (hf.comp (measurable_const.prodMk measurable_id))).symm + +lemma coinRun_output_law {J O Y : Type*} [Fintype J] [MeasurableSpace J] + [MeasurableSingletonClass J] [MeasurableSpace O] [MeasurableSpace Y] + {F : ℕ → J → O → I → J} {P : ℕ → J → O → Measure J} + (hF : ∀ t j obs, Measurable (F t j obs)) + (hP : ∀ t j obs, volume.map (F t j obs) = P t j obs) + {g : J → I → Y} {Q : J → Measure Y} (hg : ∀ j, Measurable (g j)) + (hQ : ∀ j, volume.map (g j) = Q j) (n : ℕ) (j : J) (obs : Fin n → O) : + ((Measure.pi (fun _ => (volume : Measure I))).prod volume).map + (fun z => g (coinRun F n j obs z.1) z.2) = (kernelRun P n j obs).bind Q := by + have hm : Measurable (fun z : (Fin n → I) × I => g (coinRun F n j obs z.1) z.2) := + measurable_select (h := fun a (z : (Fin n → I) × I) => g a z.2) + (fun a => (hg a).comp measurable_snd) ((measurable_coinRun hF n j obs).comp measurable_fst) + apply Measure.ext_of_lintegral + intro f hf + rw [lintegral_map hf hm,lintegral_prod (fun z => f (g (coinRun F n j obs z.1) z.2)) (hf.comp hm).aemeasurable] + have ho (a : J) : (∫⁻ u, f (g a u) ∂volume) = ∫⁻ y, f y ∂Q a := by + rw [← hQ] + exact (lintegral_map hf (hg a)).symm + simp_rw [ho] + rw [lintegral_coinRun hF hP n j obs (fun a => ∫⁻ y, f y ∂Q a)] + exact (Measure.lintegral_bind (measurable_of_finite _).aemeasurable hf.aemeasurable).symm + +namespace FiniteKernelLearner +open Learner +variable {d M T : ℕ} + +def Realizer.terminalJointOutput {K : FiniteKernelLearner d M T} (R : K.Realizer) + (j : TaggedState M T) (u : I) : Result d M := (terminalTag j,R.terminalOutput j u) + +lemma Realizer.terminalJointOutput_measurable {K : FiniteKernelLearner d M T} (R : K.Realizer) + (j : TaggedState M T) : Measurable (R.terminalJointOutput j) := + measurable_const.prodMk (R.terminalOutput_measurable j) + +lemma Realizer.terminalJointOutput_law {K : FiniteKernelLearner d M T} (R : K.Realizer) + (j : TaggedState M T) : volume.map (R.terminalJointOutput j) = K.terminalJointOutput j := by + rw [FiniteKernelLearner.terminalJointOutput,← R.terminalOutput_law, + Measure.map_map (by fun_prop) (R.terminalOutput_measurable j)] + rfl + +lemma Realizer.terminal_eq_coinRun {K : FiniteKernelLearner d M T} (R : K.Realizer) + (s : UnitSphere d) (ω : Tape M T) (x : Samples d T) : + R.toLearner.terminal s ω x = terminalTag + (coinRun R.taggedTransition T (taggedStart ω.1) (fun i => (x i,⟪s.val,x i⟫)) ω.2.1) := by + unfold Learner.terminal + rw [R.run_eq_coinRun s ω x le_rfl] + have hi (i : Fin T) : Fin.castLE le_rfl i = i := Fin.ext rfl + simp only [hi] + generalize coinRun R.taggedTransition T (taggedStart ω.1) (fun i => (x i,⟪s.val,x i⟫)) ω.2.1 = j + cases j <;> rfl + +theorem Realizer.conditional_joint_law {K : FiniteKernelLearner d M T} (R : K.Realizer) + (s : UnitSphere d) (x : Samples d T) : + K.tapeLaw.map (fun ω => (R.toLearner.terminal s ω x,R.toLearner.estimate s ω x)) = + K.jointExperimentLaw (fun i => (x i,⟪s.val,x i⟫)) := by + have hm : Measurable (fun ω : Tape M T => + (R.toLearner.terminal s ω x,R.toLearner.estimate s ω x)) := + ((R.toLearner.measurable_terminal R.measurableRules).prodMk + (R.toLearner.measurable_estimate R.measurableRules)).comp + (show Measurable (fun ω : Tape M T => (s,(ω,x))) from by fun_prop) + unfold tapeLaw jointExperimentLaw + have : IsProbabilityMeasure ((Measure.pi (fun _ : Fin T => (volume : Measure I))).prod + (volume : Measure I)) := inferInstance + have : IsFiniteMeasure ((Measure.pi (fun _ : Fin T => (volume : Measure I))).prod + (volume : Measure I)) := inferInstance + have : SigmaFinite ((Measure.pi (fun _ : Fin T => (volume : Measure I))).prod + (volume : Measure I)) := IsFiniteMeasure.toSigmaFinite _ + rw [map_finite_prod_eq_bind K.initial + ((Measure.pi (fun _ : Fin T => (volume : Measure I))).prod (volume : Measure I)) hm] + congr 1 + funext a + have he : (fun z : (Fin T → I) × I => + (R.toLearner.terminal s (a,z) x,R.toLearner.estimate s (a,z) x)) = + (fun z => R.terminalJointOutput + (coinRun R.taggedTransition T (taggedStart a) (fun i => (x i,⟪s.val,x i⟫)) z.1) z.2) := by + funext z + rw [R.terminal_eq_coinRun,R.estimate_eq_coinRun] + rfl + rw [he] + exact coinRun_output_law R.tagged_measurable R.tagged_law R.terminalJointOutput_measurable + R.terminalJointOutput_law T (taggedStart a) _ + +end FiniteKernelLearner +end NoiselessRegression + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/RieszPotential.lean b/lean/OAI/Probability/ProjectionMoments/RieszPotential.lean new file mode 100644 index 0000000000000000000000000000000000000000..28f4ce5e4ae4005903e1cc658da582ea45f12728 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/RieszPotential.lean @@ -0,0 +1,148 @@ +import OAI.Probability.ProjectionMoments.FrameMoments + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +namespace ProjectionMoments +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +theorem gaussian_fixed_offset {ν : Measure E} [IsFiniteMeasure ν] + {K a : ℝ} (hν : AllBallMass ν K a) (hK : 0 ≤ K) + (z : E) {R : ℝ} (hR : 0 < R) (hs : ν.support ⊆ Metric.closedBall z R) + (m q : ℕ) (hq : 1 ≤ q) (hmargin : (q:ℝ)+m ≤ a) + (ha : a ≤ Module.finrank ℝ E) (b : Label m) : + (∫⁻ A : Fin m → E, (lowerDensity ν m (A,rowMap A z+b))^q + ∂Measure.pi (fun _ => stdGaussian E))^(1/(q:ℝ)) ≤ + ENNReal.ofReal ((128:ℝ)^Module.finrank ℝ E * K * R^(a-m)) := by + have hd : 1 ≤ Module.finrank ℝ E := by + have hq' : 1 ≤ (q:ℝ) := by exact_mod_cast hq + have hdd : (1:ℝ) ≤ Module.finrank ℝ E := by linarith [(show (0:ℝ) ≤ m from Nat.cast_nonneg m)] + exact_mod_cast hdd + have hm : m ≤ Module.finrank ℝ E := by + exact_mod_cast (show (m:ℝ) ≤ Module.finrank ℝ E by linarith [(show (0:ℝ) ≤ q from Nat.cast_nonneg q)]) + rcases eq_or_lt_of_le hK with hK | hK + · have hz := measure_eq_zero_of_allBall_zero (hK ▸ hν) z hR hs + subst ν + simp only [lowerDensity_zero,zero_pow (by omega : q ≠ 0),lintegral_zero] + rw [ENNReal.zero_rpow_of_pos (by positivity : (0:ℝ) < 1/q)] + exact bot_le + · have hc : 1+ENNReal.ofReal ((3:ℝ)^Module.finrank ℝ E*(4:ℝ)^a)*(2:ℝ≥0∞)^(m+1) ≤ + (128:ℝ≥0∞)^Module.finrank ℝ E := by + simpa only [NoiselessRegression.replicaConstant,Measure.dirac_apply_of_mem (Set.mem_univ (0:E))] using + replicaConstant_real_le (ν := Measure.dirac (0:E)) (by simp) hd ha hm + apply ennreal_root_bound (q := q) (by omega) (by positivity) + have hh := lowerDensity_graph_moment_scaled hν hK z hR hs m q hmargin b + apply hh.trans + apply pow_le_pow_left' + calc + _ ≤ ENNReal.ofReal (K*R^(a-m))*(128:ℝ≥0∞)^Module.finrank ℝ E := mul_le_mul' le_rfl hc + _ = _ := by + rw [mul_comm] + simp only [ENNReal.ofReal_mul (by positivity : 0 ≤ (128:ℝ)^Module.finrank ℝ E), + ENNReal.ofReal_mul hK.le,ENNReal.ofReal_pow (by norm_num : (0:ℝ) ≤ 128), + ENNReal.ofReal_ofNat,mul_assoc] + +lemma ambientSphereLaw_nullSingleton [Nontrivial E] (hd : 2 ≤ Module.finrank ℝ E) : + NullSingletonClass (NoiselessRegression.ambientSphereLaw (E := E)) := by + constructor + intro z + let C : ℝ := 3*4^Module.finrank ℝ E + have ht : Tendsto (fun r : ℝ => ENNReal.ofReal (C*r)) (𝓝 (0:ℝ)) (𝓝 0) := by + have hc : Continuous (fun r : ℝ => ENNReal.ofReal (C*r)) := ENNReal.continuous_ofReal.comp (continuous_const.mul continuous_id) + simpa only [mul_zero, ENNReal.ofReal_zero] using hc.tendsto (0:ℝ) + apply le_antisymm _ bot_le + apply ge_of_tendsto (ht.mono_left (show 𝓝[>] (0:ℝ) ≤ 𝓝 0 from nhdsWithin_le_nhds)) + filter_upwards [self_mem_nhdsWithin (s := Set.Ioi (0:ℝ))] with r hr + have hs : {z} ⊆ Metric.closedBall z r := Set.singleton_subset_iff.mpr (Metric.mem_closedBall_self hr.le) + apply (measure_mono hs).trans + have hh := NoiselessRegression.ambientSphereLaw_closedBall (E := E) z hr 1 (by omega) + simpa only [pow_one, ENNReal.ofReal_mul (show 0 ≤ C by positivity)] using hh + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +@[fun_prop] lemma measurable_rieszKernel [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] (α : ℝ) (z : E) : Measurable (rieszKernel α z) := by + unfold rieszKernel + fun_prop + +omit [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] in +lemma rieszKernel_le_inverse_nat [InnerProductSpace ℝ E] [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] {α : ℝ} (hα : 0 ≤ α) {m : ℕ} (hm : α ≤ m) + (z s : E) (hneq : s ≠ z) : + rieszKernel α z s ≤ 1 + ENNReal.ofReal (‖s-z‖⁻¹^m) := by + have hn : 0 < ‖s-z‖ := norm_pos_iff.mpr (sub_ne_zero.mpr hneq) + by_cases h1 : 1 ≤ ‖s-z‖ + · apply le_add_of_le_left + simpa only [rieszKernel, ENNReal.rpow_zero] using ENNReal.rpow_le_rpow_of_exponent_le + (ENNReal.one_le_ofReal.mpr h1) (show -α ≤ 0 by linarith) + · have hh := ENNReal.rpow_le_rpow_of_exponent_ge + (show ENNReal.ofReal ‖s-z‖ ≤ 1 by exact ENNReal.ofReal_le_one.mpr (le_of_not_ge h1)) + (show -(m:ℝ) ≤ -α by linarith) + have he : (ENNReal.ofReal ‖s-z‖)^(-(m:ℝ)) = ENNReal.ofReal (‖s-z‖⁻¹^m) := by + rw [ENNReal.rpow_neg,ENNReal.rpow_natCast,ENNReal.ofReal_pow (inv_nonneg.mpr hn.le), + ENNReal.ofReal_inv_of_pos hn,ENNReal.inv_pow] + exact hh.trans (by rw [he]; exact le_add_left le_rfl) + +lemma rieszPotential_finite [Nontrivial E] {α : ℝ} (hα : 0 ≤ α) {m : ℕ} + (hm : α ≤ m) (hmd : m+1 ≤ Module.finrank ℝ E-1) + {h : E → ℝ≥0∞} (h1 : ∀ s, h s ≤ 1) : rieszPotential α h < ∞ := by + have hd : 2 ≤ Module.finrank ℝ E := by omega + let := ambientSphereLaw_nullSingleton hd + let C : ℝ≥0∞ := ENNReal.ofReal ((3:ℝ)*4^Module.finrank ℝ E) + have hbound (z : E) : (∫⁻ s, h s*rieszKernel α z s ∂NoiselessRegression.ambientSphereLaw) ≤ + 2+C*(2:ℝ≥0∞)^(m+1) := by + have hmom := NoiselessRegression.inverse_moment_of_tube_bound + (NoiselessRegression.ambientSphereLaw (E := E)) (fun s => ‖s-z‖) m + (by fun_prop) (fun _ => norm_nonneg _) C + (fun r hr _ => by + simpa only [Metric.closedBall, dist_eq_norm, C] using NoiselessRegression.ambientSphereLaw_closedBall z hr (m+1) hmd) + have hcmp : ∀ᵐ s ∂NoiselessRegression.ambientSphereLaw, + h s*rieszKernel α z s ≤ 1+ENNReal.ofReal (‖s-z‖⁻¹^m) := by + filter_upwards [(NoiselessRegression.ambientSphereLaw (E := E)).ae_ne z] with s hs + exact (mul_le_of_le_one_left' (h1 s)).trans (rieszKernel_le_inverse_nat hα hm z s hs) + calc + _ ≤ ∫⁻ s, 1+ENNReal.ofReal (‖s-z‖⁻¹^m) ∂NoiselessRegression.ambientSphereLaw := lintegral_mono_ae hcmp + _ = 1+∫⁻ s, ENNReal.ofReal (‖s-z‖⁻¹^m) ∂NoiselessRegression.ambientSphereLaw := by + rw [lintegral_add_left measurable_const]; simp + _ ≤ 1+(1+C*2^(m+1)) := add_le_add le_rfl (by simpa only [measure_univ] using hmom) + _ = _ := by ring + exact (iSup_le hbound).trans_lt (by + apply ENNReal.add_lt_top.mpr + constructor + · norm_num + · exact ENNReal.mul_lt_top (show C < ∞ from ENNReal.ofReal_lt_top) (by finiteness)) + +lemma rieszPotential_ball_control [Nontrivial E] {α : ℝ} (hα : 0 ≤ α) + {h : E → ℝ≥0∞} (hh : Measurable h) (z : E) {r : ℝ} (hr : 0 < r) : + (NoiselessRegression.ambientSphereLaw.withDensity h) (Metric.closedBall z r) ≤ + rieszPotential α h * ENNReal.ofReal (r^α) := by + have hr0 : ENNReal.ofReal r ≠ 0 := ne_of_gt (ENNReal.ofReal_pos.mpr hr) + have hrt : ENNReal.ofReal r ≠ ∞ := ENNReal.ofReal_ne_top + have hnorm (s : E) (hs : s ∈ Metric.closedBall z r) : + 1 ≤ ENNReal.ofReal (r^α) * rieszKernel α z s := by + have hs' : ‖s-z‖ ≤ r := by simpa [dist_eq_norm] using hs + have hb := ENNReal.rpow_le_rpow (ENNReal.ofReal_le_ofReal hs') hα + rw [rieszKernel, ENNReal.rpow_neg, ← ENNReal.ofReal_rpow_of_pos hr] + calc + _ = (ENNReal.ofReal r)^α*((ENNReal.ofReal r)^α)⁻¹ := + (ENNReal.mul_inv_cancel (ne_of_gt (ENNReal.rpow_pos (bot_lt_iff_ne_bot.mpr hr0) hrt)) (ENNReal.rpow_ne_top_of_nonneg hα hrt)).symm + _ ≤ _ := mul_le_mul' le_rfl (ENNReal.inv_le_inv.mpr hb) + rw [withDensity_apply _ Metric.isClosed_closedBall.measurableSet] + calc + _ ≤ ∫⁻ s in Metric.closedBall z r, ENNReal.ofReal (r^α)*(h s*rieszKernel α z s) + ∂NoiselessRegression.ambientSphereLaw := by + apply setLIntegral_mono' Metric.isClosed_closedBall.measurableSet + intro s hs + simpa only [mul_one,mul_left_comm] using mul_le_mul' le_rfl (hnorm s hs) + _ ≤ ∫⁻ s, ENNReal.ofReal (r^α)*(h s*rieszKernel α z s) + ∂NoiselessRegression.ambientSphereLaw := setLIntegral_le_lintegral _ _ + _ = ENNReal.ofReal (r^α)*(∫⁻ s, h s*rieszKernel α z s ∂NoiselessRegression.ambientSphereLaw) := + lintegral_const_mul _ (hh.mul (measurable_rieszKernel α z)) + _ ≤ _ := by rw [mul_comm]; exact mul_le_mul' (show _ ≤ rieszPotential α h from le_iSup (fun z => ∫⁻ s, h s*rieszKernel α z s ∂NoiselessRegression.ambientSphereLaw) z) le_rfl + +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Seeded.lean b/lean/OAI/Probability/ProjectionMoments/Seeded.lean new file mode 100644 index 0000000000000000000000000000000000000000..ebc2e9342df71fee64861eda981b343c7943a5ed --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Seeded.lean @@ -0,0 +1,264 @@ +import OAI.Probability.ProjectionMoments.Streaming + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter unitInterval +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression +namespace FiniteKernelLearner + +section +open Learner +variable {d M T : ℕ} + +lemma Realizer.uniform_event_law [NeZero d] {K : FiniteKernelLearner d M T} (R : K.Realizer) + (S : Set (UnitSphere d × Result d M)) (hS : MeasurableSet S) : + ((uniformSphere d).prod (K.tapeLaw.prod (sampleLaw d T))) + {z | (z.1,(R.toLearner.terminal z.1 z.2.1 z.2.2,R.toLearner.estimate z.1 z.2.1 z.2.2)) ∈ S} = + ∫⁻ z : UnitSphere d × Samples d T, + K.jointExperimentLaw (fun i => (z.2 i,⟪z.1.val,z.2 i⟫)) + {r | (z.1,r) ∈ S} ∂((uniformSphere d).prod (sampleLaw d T)) := by + have hp := ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := K.tapeLaw))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) K.tapeLaw) + have hE : MeasurableSet {z : UnitSphere d × (Tape M T × Samples d T) | + (z.1,(R.toLearner.terminal z.1 z.2.1 z.2.2,R.toLearner.estimate z.1 z.2.1 z.2.2)) ∈ S} := + (measurable_fst.prodMk ((R.toLearner.measurable_terminal R.measurableRules).prodMk + (R.toLearner.measurable_estimate R.measurableRules))) hS + rw [← hp.measure_preimage hE.nullMeasurableSet,Measure.prod_apply (hp.measurable hE)] + apply lintegral_congr + intro z + have hs : MeasurableSet {r : Result d M | (z.1,r) ∈ S} := + (measurable_const.prodMk measurable_id) hS + rw [←R.conditional_joint_law z.1 z.2,Measure.map_apply _ hs] + · rfl + · exact ((R.toLearner.measurable_terminal R.measurableRules).prodMk + (R.toLearner.measurable_estimate R.measurableRules)).comp + (show Measurable (fun ω : Tape M T => (z.1,(ω,z.2))) from by fun_prop) + +lemma Realizer.uniformSuccess_eq [NeZero d] {K : FiniteKernelLearner d M T} (R : K.Realizer) (ε : ℝ) : + R.toLearner.uniformSuccess K.tapeLaw ε = K.uniformSuccess ε := by + exact R.uniform_event_law {z | angularError z.1 z.2.2 ≤ ε} + (measurableSet_le (show Measurable (fun z : UnitSphere d × Result d M => angularError z.1 z.2.2) from by unfold angularError; fun_prop) measurable_const) + +lemma Realizer.uniformFixedSuccess_eq [NeZero d] {K : FiniteKernelLearner d M T} (R : K.Realizer) (ε : ℝ) (t : ℕ) : + R.toLearner.uniformFixedSuccess K.tapeLaw ε t = K.uniformFixedSuccess ε t := by + exact R.uniform_event_law {z | z.2.1.1 = t ∧ angularError z.1 z.2.2 ≤ ε} + ((measurableSet_eq_fun (show Measurable (fun z : UnitSphere d × Result d M => z.2.1.1) from by fun_prop) measurable_const).inter + (measurableSet_le (show Measurable (fun z : UnitSphere d × Result d M => angularError z.1 z.2.2) from by unfold angularError; fun_prop) measurable_const)) + +lemma jointExperimentLaw_congr {K K' : FiniteKernelLearner d M T} + (hi : K.initial = K'.initial) (ho : K.output = K'.output) + (obs : Fin T → (Vector d × ℝ)) + (ht : ∀ t j i, K.transition t j (obs i) = K'.transition t j (obs i)) : + K.jointExperimentLaw obs = K'.jointExperimentLaw obs := by + have htag : ∀ t j i, K.taggedKernel t j (obs i) = K'.taggedKernel t j (obs i) := by + intro t j i + cases j with + | inr a => rfl + | inl j => simp only [taggedKernel,ht] + have hout : K.terminalJointOutput = K'.terminalJointOutput := by + funext j + unfold terminalJointOutput + congr 1 + cases j with + | inl j => exact congrFun (congrFun ho T) j + | inr a => exact congrFun (congrFun ho a.1) a.2 + unfold jointExperimentLaw + rw [hi,hout] + congr 1 + funext a + rw [kernelRun_congr T (taggedStart a) obs htag] + +lemma exists_borel_same_joint (K : FiniteKernelLearner d M T) (hK : K.CompletedRules) (hd : 3 ≤ d) : + ∃ K' : FiniteKernelLearner d M T, K'.BorelRules ∧ + ∀ᵐ z ∂((uniformSphere d).prod (sampleLaw d T)), + K.jointExperimentLaw (fun i => (z.2 i,⟪z.1.val,z.2 i⟫)) = + K'.jointExperimentLaw (fun i => (z.2 i,⟪z.1.val,z.2 i⟫)) := by + obtain ⟨K',hK',hi,ho,ht⟩ := K.exists_borel_version hK + refine ⟨K',hK',?_⟩ + let : NeZero d := ⟨by omega⟩ + have hg : ∀ᵐ z ∂((uniformSphere d).prod (sampleLaw d T)), ∀ t j (i : Fin T), + K.transition t j (z.2 i,⟪z.1.val,z.2 i⟫) = K'.transition t j (z.2 i,⟪z.1.val,z.2 i⟫) := by + simp only [ae_all_iff] + intro t j i + exact (sphere_sample_observation_quasi (E := Vector d) (by simpa using hd) i).ae (ht t j).symm + filter_upwards [hg] with z hz + exact jointExperimentLaw_congr hi.symm ho.symm _ hz + +theorem exists_equivalent_tape (K : FiniteKernelLearner d M T) (hK : K.CompletedRules) (hd : 3 ≤ d) : + ∃ (ρ : Measure (Tape M T)) (L : Learner d M T (Tape M T)), + IsProbabilityMeasure ρ ∧ L.MeasurableRules ∧ L.Admissible ρ ∧ + (∀ ε, L.uniformSuccess ρ ε = K.uniformSuccess ε) ∧ + (∀ ε t, L.uniformFixedSuccess ρ ε t = K.uniformFixedSuccess ε t) := by + let : NeZero d := ⟨by omega⟩ + obtain ⟨K',hK',he⟩ := K.exists_borel_same_joint hK hd + let R := Classical.choice (K'.exists_realizer hK') + refine ⟨K'.tapeLaw,R.toLearner,inferInstance,R.measurableRules, + R.toLearner.admissible_of_measurable R.measurableRules K'.tapeLaw,?_,?_⟩ + · intro ε + rw [R.uniformSuccess_eq] + apply lintegral_congr_ae + filter_upwards [he] with z hz + rw [hz] + · intro ε t + rw [R.uniformFixedSuccess_eq] + apply lintegral_congr_ae + filter_upwards [he] with z hz + rw [hz] + +end + +universe u +variable {d M T : ℕ} + +lemma seed_average_bound {Ξ : Type u} [MeasurableSpace Ξ] (ρ : Measure Ξ) + [IsProbabilityMeasure ρ] {f : Ξ → ℝ≥0∞} {C : ℝ≥0∞} + (h : ∀ᵐ ξ ∂ρ, f ξ ≤ C) : ∫⁻ ξ, f ξ ∂ρ ≤ C := by + calc + _ ≤ ∫⁻ _, C ∂ρ := lintegral_mono_ae h + _ = C := by simp + +lemma exists_successful_seed {Ξ : Type u} [MeasurableSpace Ξ] (ρ : Measure Ξ) + [IsProbabilityMeasure ρ] {P : Ξ → Prop} (hP : ∀ᵐ ξ ∂ρ, P ξ) + {f : Ξ → ℝ≥0∞} {c : ℝ≥0∞} (hc : c ≠ ∞) (hs : c ≤ ∫⁻ ξ, f ξ ∂ρ) : + ∃ ξ, P ξ ∧ c ≤ f ξ := by + by_contra h + have hlt : ∀ᵐ ξ ∂ρ, f ξ < c := by + filter_upwards [hP] with ξ hξ + exact lt_of_not_ge (fun hf => h ⟨ξ,hξ,hf⟩) + have hbound : ∫⁻ ξ, f ξ ∂ρ ≤ c := seed_average_bound ρ (ae_le_of_ae_lt hlt) + have hstrict := lintegral_strict_mono (show ρ ≠ 0 from by + intro he; have hh := measure_univ (μ := ρ); rw [he] at hh; simp at hh) + (aemeasurable_const (b := c)) (ne_top_of_le_ne_top hc hbound) hlt + have hh : ∫⁻ ξ, f ξ ∂ρ < c := by simpa using hstrict + exact not_lt_of_ge hs hh + +theorem riesz_success : + ∃ C₀ : ℝ, 1 ≤ C₀ ∧ ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + let q := d/8 + let W : ℝ := ((T:ℝ)+2)*2^M + seededSuccess K ρ ε ≤ ENNReal.ofReal + (C₀^d*ε^((d:ℝ)/2-1)*(1+C₀^d*(1+Real.log (1/ε))*W^(1/(q:ℝ)))^((T+q-1)/q)) := by + obtain ⟨C,hC,h⟩ := Learner.riesz_success.{0} + refine ⟨C,hC,?_⟩ + intro d M T hd ε hε hε10 Ξ _ ρ hρ K hK q W + let : IsProbabilityMeasure ρ := hρ + apply seed_average_bound + filter_upwards [hK] with ξ hξ + obtain ⟨ν,L,hν,hB,hL,he,_⟩ := (K ξ).exists_equivalent_tape hξ (by omega) + rw [←he ε] + exact h d M T hd ε hε hε10 (Tape M T) ν hν L hL + +theorem haar_success : + ∃ C : ℝ, 1 ≤ C ∧ ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + let k := d/4 + let Nstar : ℝ := ((k:ℝ)+2)*2^M + seededSuccess K ρ ε ≤ ENNReal.ofReal + (C^d*ε^k*(C^d*Nstar^(1/(k:ℝ)))^((T+k-1)/k)) := by + obtain ⟨C,hC,h⟩ := Learner.haar_success.{0} + refine ⟨C,hC,?_⟩ + intro d M T hd ε hε hε10 Ξ _ ρ hρ K hK k Nstar + let : IsProbabilityMeasure ρ := hρ + apply seed_average_bound + filter_upwards [hK] with ξ hξ + obtain ⟨ν,L,hν,hB,hL,he,_⟩ := (K ξ).exists_equivalent_tape hξ (by omega) + rw [←he ε] + exact h d M T hd ε hε hε10 (Tape M T) ν hν L hL + +theorem cap_fixed_stop : + ∃ C : ℝ, 0 < C ∧ ∀ d M T : ℕ, 32 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d M T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + ∀ t : ℕ, t ≤ T → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + seededFixedSuccess K ρ ε t ≤ ENNReal.ofReal + (Real.exp (C*d)*(ε/2)^α*(Real.exp (C*d)*(2:ℝ)^((M:ℝ)/k))^((t+k-1)/k)) := by + obtain ⟨C,hC,h⟩ := Learner.cap_fixed_stop.{0} + refine ⟨C,hC,?_⟩ + intro d M T hd ε hε hε10 Ξ _ ρ hρ K hK t ht k α + let : IsProbabilityMeasure ρ := hρ + apply seed_average_bound + filter_upwards [hK] with ξ hξ + obtain ⟨ν,L,hν,hB,hL,_,he⟩ := (K ξ).exists_equivalent_tape hξ (by omega) + rw [←he ε t] + exact h d M T hd ε hε hε10 (Tape M T) ν hν L hL + (L.measurable_terminal hB).fst.aemeasurable t ht + +theorem fixed_quadratic_memory : FixedQuadraticMemory.{u} := by + intro A hA + obtain ⟨c,hc,d₀,h⟩ := NoiselessRegression.fixed_quadratic_memory.{0} A hA + refine ⟨c,hc,max d₀ 3,?_⟩ + intro d hd M T hM ε hε hε10 Ξ _ ρ hρ K hK hs + let : IsProbabilityMeasure ρ := hρ + obtain ⟨ξ,hξ,hsξ⟩ := exists_successful_seed ρ hK (ENNReal.div_ne_top (by norm_num) (by norm_num) : (2/3 : ℝ≥0∞) ≠ ∞) hs + obtain ⟨ν,L,hν,hB,hL,he,_⟩ := (K ξ).exists_equivalent_tape hξ (by omega) + apply h d (by omega) M T hM ε hε hε10 (Tape M T) ν hν L hL + rwa [he ε] + +def SubquadraticMemory : Prop := + ∃ c : ℝ, 0 < c ∧ ∀ M : ℕ → ℕ, + Asymptotics.IsLittleO atTop (fun d => (M d : ℝ)) (fun d => (d:ℝ)^2) → + ∃ d₀ : ℕ, ∀ d : ℕ, d₀ ≤ d → ∀ T : ℕ, ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ξ : Type u) [MeasurableSpace Ξ] (ρ : Measure Ξ), IsProbabilityMeasure ρ → + ∀ K : Ξ → FiniteKernelLearner d (M d) T, (∀ᵐ ξ ∂ρ, (K ξ).CompletedRules) → + (2/3 : ℝ≥0∞) ≤ seededSuccess K ρ ε → + c*(d:ℝ)*Real.log (1/ε) ≤ (T:ℝ) + +theorem subquadratic_memory : SubquadraticMemory.{u} := by + obtain ⟨c,hc,h⟩ := NoiselessRegression.subquadratic_memory.{0} + refine ⟨c,hc,?_⟩ + intro M hM + obtain ⟨d₀,hd₀⟩ := h M hM + refine ⟨max d₀ 3,?_⟩ + intro d hd T ε hε hε10 Ξ _ ρ hρ K hK hs + let : IsProbabilityMeasure ρ := hρ + obtain ⟨ξ,hξ,hsξ⟩ := exists_successful_seed ρ hK (ENNReal.div_ne_top (by norm_num) (by norm_num) : (2/3 : ℝ≥0∞) ≠ ∞) hs + obtain ⟨ν,L,hν,hB,hL,he,_⟩ := (K ξ).exists_equivalent_tape hξ (by omega) + apply hd₀ d (by omega) T ε hε hε10 (Tape (M d) T) ν hν L hL + exact Or.inl ((he ε).symm ▸ hsξ) + +end FiniteKernelLearner + +lemma fresh_seed_kernel_version {X Ξ J : Type*} [MeasurableSpace X] + [MeasurableSpace Ξ] [Fintype J] [Nonempty J] [MeasurableSpace J] + [MeasurableSingletonClass J] (μ : Measure X) [SFinite μ] + (ρ : Measure Ξ) [IsProbabilityMeasure ρ] + (P : X × Ξ → Measure J) (hP : ∀ z, IsProbabilityMeasure (P z)) + (hm : ∀ j, AEMeasurable (fun z => P z {j}) (μ.prod ρ)) : + ∃ κ : Kernel X J, IsMarkovKernel κ ∧ + ∀ᵐ x ∂μ, ∀ j, κ x {j} = ∫⁻ ξ, P (x,ξ) {j} ∂ρ := by + obtain ⟨κ,hκ,he⟩ := finite_kernel_borel_version (μ.prod ρ) P hP hm + let : IsMarkovKernel κ := hκ + let η : Kernel X J := κ ∘ₖ ((Kernel.id : Kernel X X) ×ₖ Kernel.const X ρ) + refine ⟨η,inferInstance,?_⟩ + filter_upwards [Measure.ae_ae_of_ae_prod he] with x hx + intro j + rw [show η x {j} = ∫⁻ ξ, κ (x,ξ) {j} ∂ρ from ?_] + · apply lintegral_congr_ae + filter_upwards [hx] with ξ hξ + rw [hξ] + · change (κ ∘ₖ ((Kernel.id : Kernel X X) ×ₖ Kernel.const X ρ)) x {j} = _ + rw [Kernel.comp_apply' _ _ _ (measurableSet_singleton j),Kernel.prod_apply, + Kernel.id_apply,Kernel.const_apply] + rw [lintegral_prod _ (κ.measurable_coe (measurableSet_singleton j)).aemeasurable] + apply lintegral_dirac' + exact (κ.measurable_coe (measurableSet_singleton j)).lintegral_prod_right + +end NoiselessRegression + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/SphereDensity.lean b/lean/OAI/Probability/ProjectionMoments/SphereDensity.lean new file mode 100644 index 0000000000000000000000000000000000000000..20e1cd2107da8e17ba96b8bee9797f697ff75cc7 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/SphereDensity.lean @@ -0,0 +1,134 @@ +import OAI.Probability.ProjectionMoments.Frames + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter InnerProductSpace +open scoped ENNReal NNReal RealInnerProductSpace Topology +noncomputable section +namespace ProjectionMoments +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] + +@[fun_prop] lemma measurable_coordinateMap (m : ℕ) : + Measurable (fun z : (Fin m → E) × E => coordinateMap z.1 z.2) := by + apply Measurable.of_eval + intro i + simp only [coordinateMap_apply] + fun_prop + +def projectionKernel (ν : Measure E) [SFinite ν] (m : ℕ) : Kernel (Fin m → E) (Fin m → ℝ) where + toFun A := ν.map (coordinateMap A) + measurable' := by + apply Measure.measurable_of_measurable_coe + intro s hs + have he (A : Fin m → E) : (ν.map (coordinateMap A)) s = + ∫⁻ x, s.indicator (fun _ => (1 : ℝ≥0∞)) (coordinateMap A x) ∂ν := by + rw [← lintegral_map (measurable_const.indicator hs) (by fun_prop)] + simp [lintegral_indicator hs] + simp_rw [he] + apply Measurable.lintegral_prod_right + exact (measurable_const.indicator hs).comp (measurable_coordinateMap m) + +instance projectionKernel_finite (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) : + IsFiniteKernel (projectionKernel ν m) := by + refine ⟨ν Set.univ, measure_lt_top _ _, ?_⟩ + intro A + change (ν.map (coordinateMap A)) Set.univ ≤ _ + rw [Measure.map_apply (by fun_prop) MeasurableSet.univ, Set.preimage_univ] + +lemma projectionKernel_compProd (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) : + (Measure.pi (fun _ : Fin m => stdGaussian E)) ⊗ₘ projectionKernel ν m = + NoiselessRegression.projectionLaw ν m := by + apply Measure.ext_of_lintegral + intro f hf + rw [Measure.lintegral_compProd hf, NoiselessRegression.projectionLaw, + lintegral_map hf (by fun_prop), lintegral_prod _ (by fun_prop)] + apply lintegral_congr + intro A + change (∫⁻ y, f (A,y) ∂ν.map (coordinateMap A)) = _ + rw [lintegral_map (by fun_prop) (by fun_prop)] + congr 1 + funext x + apply congrArg f + exact Prod.ext (by rfl) (funext fun i => coordinateMap_apply A x i) + +lemma ae_projection_ac (ν : Measure E) [IsFiniteMeasure ν] (m : ℕ) + (h : NoiselessRegression.projectionLaw ν m ≪ NoiselessRegression.matrixLabelReference (E := E) m) : + ∀ᵐ A : Fin m → E ∂Measure.pi (fun _ => stdGaussian E), + ν.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ)) := by + let γ : Measure (Fin m → E) := Measure.pi (fun _ => stdGaussian E) + let η : Measure (Fin m → ℝ) := volume.toFinite + have hh : γ ⊗ₘ projectionKernel ν m ≪ γ ⊗ₘ Kernel.const (Fin m → E) η := by + rw [projectionKernel_compProd, Measure.compProd_const] + exact h.trans (Measure.AbsolutelyContinuous.refl γ |>.prod (absolutelyContinuous_toFinite volume)) + filter_upwards [hh.kernel_of_compProd] with A hA + exact hA.trans (toFinite_absolutelyContinuous volume) + +lemma sphere_ae_projection_ac [Nontrivial E] {m : ℕ} (hm : m+2 ≤ Module.finrank ℝ E) : + ∀ᵐ A : Fin m → E ∂Measure.pi (fun _ => stdGaussian E), + NoiselessRegression.ambientSphereLaw.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ)) := by + apply ae_projection_ac + apply NoiselessRegression.projectionLaw_absolutelyContinuous (a := m+1) (n := 1) + (C := ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E)) + · intro z r hr + exact NoiselessRegression.ambientSphereLaw_closedBall z hr (m+1) (by omega) + · positivity + · exact ENNReal.ofReal_ne_top + · exact NoiselessRegression.ambientSphereLaw_support.trans Metric.sphere_subset_closedBall + · omega + · omega + +lemma linearEquiv_preserves_ac {m : ℕ} (T : (Fin m → ℝ) ≃L[ℝ] (Fin m → ℝ)) + {μ : Measure (Fin m → ℝ)} (hμ : μ ≪ volume) : μ.map T ≪ volume := by + exact (T.toHomeomorph.toMeasurableEquiv.measurableEmbedding.absolutelyContinuous_map hμ).trans + (Measure.LinearMap.quasiMeasurePreserving volume T.toLinearEquiv.toLinearMap + (LinearEquiv.isUnit_det' T.toLinearEquiv).ne_zero).absolutelyContinuous + +lemma sphere_projection_rotation [Nontrivial E] {m : ℕ} (O : Rotation E) (A : Fin m → E) : + NoiselessRegression.ambientSphereLaw.map (coordinateMap (rotateRows O A)) = + NoiselessRegression.ambientSphereLaw.map (coordinateMap A) := by + have hfun : (coordinateMap (rotateRows O A) : E → (Fin m → ℝ)) = + coordinateMap A ∘ (Unitary.linearIsometryEquiv O).symm := + funext (coordinateMap_rotateRows O A) + rw [hfun, ← Measure.map_map (by fun_prop) (by fun_prop), + (NoiselessRegression.ambientSphereLaw_isometry (Unitary.linearIsometryEquiv O).symm).map_eq] + +theorem sphere_frame_ac [Nontrivial E] {m : ℕ} (hm : m+2 ≤ Module.finrank ℝ E) + {u : Fin m → E} (hu : Orthonormal ℝ u) : + NoiselessRegression.ambientSphereLaw.map (coordinateMap u) ≪ (volume : Measure (Fin m → ℝ)) := by + obtain ⟨B,hB,hac⟩ := ((gaussian_rows_ae_linearIndependent m (by omega)).and + (sphere_ae_projection_ac hm)).exists + obtain ⟨v,hv,T,hT,hvol⟩ := rows_factor B hB + have he : (NoiselessRegression.ambientSphereLaw.map (coordinateMap B)).map T.symm = + NoiselessRegression.ambientSphereLaw.map (coordinateMap v) := by + rw [Measure.map_map (by fun_prop) (by fun_prop)] + congr 1 + funext x + simp only [Function.comp_apply, hT, T.symm_apply_apply] + have hvac := linearEquiv_preserves_ac T.symm hac + rw [he] at hvac + obtain ⟨O,hO⟩ := rotation_transitive hv hu + have heu : rotateRows O v = u := funext hO + rw [← heu, sphere_projection_rotation] + exact hvac + +theorem sphere_fullRank_ac [Nontrivial E] {m : ℕ} (hm : m+2 ≤ Module.finrank ℝ E) + {A : Fin m → E} (hA : LinearIndependent ℝ A) : + NoiselessRegression.ambientSphereLaw.map (coordinateMap A) ≪ (volume : Measure (Fin m → ℝ)) := by + obtain ⟨u,hu,T,hT,hvol⟩ := rows_factor A hA + have he : NoiselessRegression.ambientSphereLaw.map (coordinateMap A) = + (NoiselessRegression.ambientSphereLaw.map (coordinateMap u)).map T := by + rw [Measure.map_map (by fun_prop) (by fun_prop)] + congr 1 + exact funext hT + rw [he] + exact linearEquiv_preserves_ac T (sphere_frame_ac hm hu) + +end ProjectionMoments +end + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/SphereWeights.lean b/lean/OAI/Probability/ProjectionMoments/SphereWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..1e4c54b8faff0a01345f7ed99fabcfba8cf59eae --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/SphereWeights.lean @@ -0,0 +1,85 @@ +import OAI.Probability.ProjectionMoments.Asymptotics + +namespace OAI + +section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +noncomputable section +namespace ProjectionMoments +open NoiselessRegression +variable {d : ℕ} + +def extendSphereWeight (f : UnitSphere d → ℝ≥0∞) : Vector d → ℝ≥0∞ := + Function.extend Subtype.val f (fun _ => 0) + +@[simp] lemma extendSphereWeight_val (f : UnitSphere d → ℝ≥0∞) (s : UnitSphere d) : + extendSphereWeight f s.val = f s := + Subtype.val_injective.extend_apply f (fun _ => 0) s + +lemma measurable_extendSphereWeight {f : UnitSphere d → ℝ≥0∞} (hf : Measurable f) : + Measurable (extendSphereWeight f) := + (MeasurableEmbedding.subtype_coe Metric.isClosed_sphere.measurableSet).measurable_extend hf measurable_const + +lemma extendSphereWeight_le_one {f : UnitSphere d → ℝ≥0∞} (hf : ∀ s, f s ≤ 1) : + ∀ x, extendSphereWeight f x ≤ 1 := by + intro x + by_cases hx : ∃ s : UnitSphere d, s.val = x + · obtain ⟨s,rfl⟩ := hx + simpa using hf s + · rw [extendSphereWeight,Function.extend_apply' _ _ _ hx] + exact zero_le_one + +lemma sphereWeight_measure (f : UnitSphere d → ℝ≥0∞) (hf : Measurable f) : + ambientSphereLaw.withDensity (extendSphereWeight f) = + ((uniformSphere d).withDensity f).map Subtype.val := by + ext S hS + rw [withDensity_apply _ hS,Measure.map_apply measurable_subtype_coe hS, + withDensity_apply _ (measurable_subtype_coe hS)] + change (∫⁻ x in S, extendSphereWeight f x ∂(uniformSphere d).map Subtype.val) = _ + rw [← lintegral_indicator hS,lintegral_map ((measurable_extendSphereWeight hf).indicator hS) + measurable_subtype_coe,← lintegral_indicator (measurable_subtype_coe hS)] + apply lintegral_congr + intro s + by_cases hs : s.val ∈ S <;> simp [hs,extendSphereWeight_val] + +lemma sphereWeight_potential (α : ℝ) (f : UnitSphere d → ℝ≥0∞) (hf : Measurable f) : + rieszPotential α (extendSphereWeight f) = + ⨆ z : Vector d, ∫⁻ s, f s * (ENNReal.ofReal ‖s.val-z‖)^(-α) ∂uniformSphere d := by + unfold rieszPotential + congr 1 + funext z + change (∫⁻ x, extendSphereWeight f x*rieszKernel α z x ∂(uniformSphere d).map Subtype.val) = _ + rw [lintegral_map (show Measurable (fun x => extendSphereWeight f x*rieszKernel α z x) from + (measurable_extendSphereWeight hf).mul (measurable_rieszKernel α z)) measurable_subtype_coe] + apply lintegral_congr + intro s + simp only [extendSphereWeight_val,rieszKernel] + +lemma sphereWeight_restriction (f : UnitSphere d → ℝ≥0∞) (hf : Measurable f) + (H : Set (UnitSphere d)) (hH : MeasurableSet H) : + sphereWeightedRestriction (extendSphereWeight f) (Subtype.val '' H) = + (((uniformSphere d).withDensity f).restrict H).map Subtype.val := by + have he := MeasurableEmbedding.subtype_coe (Metric.isClosed_sphere.measurableSet : + MeasurableSet (Metric.sphere (0 : Vector d) 1)) + rw [sphereWeightedRestriction,sphereWeight_measure f hf,Measure.restrict_map measurable_subtype_coe + (he.measurableSet_image.mpr hH)] + congr 1 + congr 1 + exact Set.preimage_image_eq _ Subtype.val_injective + +lemma sphere_weight_representation (f : UnitSphere d → ℝ≥0∞) (hf : Measurable f) + (hf1 : ∀ s, f s ≤ 1) : + ∃ F : Vector d → ℝ≥0∞, Measurable F ∧ (∀ x, F x ≤ 1) ∧ + (∀ s : UnitSphere d, F s.val = f s) ∧ + ambientSphereLaw.withDensity F = ((uniformSphere d).withDensity f).map Subtype.val := + ⟨extendSphereWeight f,measurable_extendSphereWeight hf,extendSphereWeight_le_one hf1, + extendSphereWeight_val f,sphereWeight_measure f hf⟩ + +end ProjectionMoments +end + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Stopping.lean b/lean/OAI/Probability/ProjectionMoments/Stopping.lean new file mode 100644 index 0000000000000000000000000000000000000000..1f162009c5152b036d69f66d511d912f49c4bffe --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Stopping.lean @@ -0,0 +1,295 @@ +import OAI.Probability.ProjectionMoments.AllRadii + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] +variable {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] + +lemma continuation_mass_bound_ceil [Nonempty J] (μ : Measure E) [IsFiniteMeasure μ] + {δ : ℕ → J → (E × ℝ) → J} {w : ℕ → J → E → ℝ≥0∞} + (hδ : ∀ n j, Measurable (δ n j)) (hw : ∀ n j, Measurable (w n j)) + (hw1 : ∀ n j s, w n j s ≤ 1) + {a q : ℕ} {C : ℝ≥0∞} (hC : C ≠ 0) (hCt : C ≠ ∞) + (hlocal : ∀ n j, PolynomialMass (μ.withDensity (w n j)) a C) + (hd : 1 ≤ Module.finrank ℝ E) (ha : a ≤ Module.finrank ℝ E) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (n k : ℕ) (j : J) : + PolynomialMass (μ.withDensity (continuation δ w n k j)) a + (C * streamFactor (E := E) (J := J) q ^ ((k+q-1)/q)) := by + have hden : ((q-1 : ℕ) : ℝ)+1 = (q : ℝ) := by + rw [Nat.cast_sub (by omega : 1 ≤ q), Nat.cast_one] + ring + have hq0 : 0 < q := by omega + have hK1 := one_le_streamFactor (E := E) (J := J) hq0 + have hK0 : streamFactor (E := E) (J := J) q ≠ 0 := ne_of_gt (lt_of_lt_of_le zero_lt_one hK1) + have hKt := streamFactor_ne_top (E := E) (J := J) q + induction k using Nat.strong_induction_on generalizing n j with + | h k ih => + by_cases hk0 : k = 0 + · subst k + simpa only [Nat.zero_add,Nat.div_eq_of_lt (by omega : q-1 < q),pow_zero,mul_one,continuation] using hlocal n j + by_cases hk : q ≤ k + · have hki : k-q < k := by omega + have hC1 : C * streamFactor (E := E) (J := J) q ^ ((k-q+q-1)/q) ≠ 0 := + mul_ne_zero hC (pow_ne_zero _ hK0) + have hC1t : C * streamFactor (E := E) (J := J) q ^ ((k-q+q-1)/q) ≠ ∞ := + ENNReal.mul_ne_top hCt (ENNReal.pow_ne_top hKt) + have hb := blockValue_mass_bound μ + (fun b => measurable_continuation hδ hw (n+q) (k-q) b) + (fun b s => continuation_le_one hw1 (n+q) (k-q) b s) + (fun b => ih (k-q) hki (n+q) b) hC1 hC1t hd ha + (by omega : q ≤ Module.finrank ℝ E) (by omega : 1 ≤ q-1) + (by omega : q-1+q ≤ a) (measurable_streamRoute hδ n q j) + have he : continuation δ w n k j = + blockValue (fun b => continuation δ w (n+q) (k-q) b) (streamRoute δ n q j) := by + funext s + simpa [Nat.add_sub_of_le hk] using continuation_unroll hδ n q (k-q) j s + rw [he] + have hdiv : (k+q-1)/q = (k-q+q-1)/q+1 := by + have he : k+q-1 = q+(k-q+q-1) := by omega + rw [he,Nat.add_div_left _ hq0] + convert hb using 1 + rw [hden, ← streamFactor, hdiv, pow_succ] + ring + · have hkm : k ≤ q := by omega + have hb := blockValue_mass_bound μ + (fun b => hw (n+k) b) (fun b s => hw1 (n+k) b s) (hlocal (n+k)) hC hCt hd ha + (by omega : k ≤ Module.finrank ℝ E) (by omega : 1 ≤ q-1) + (by omega : q-1+k ≤ a) (measurable_streamRoute hδ n k j) + have he : continuation δ w n k j = blockValue (w (n+k)) (streamRoute δ n k j) := by + funext s + simpa [continuation] using continuation_unroll hδ n k 0 j s + rw [he] + convert hb using 1 + have hdiv : (k+q-1)/q = 1 := by + have he : k+q-1 = q+(k-1) := by omega + rw [he,Nat.add_div_left _ hq0,Nat.div_eq_of_lt (by omega : k-1 < q)] + rw [hden, ← streamFactor,hdiv,pow_one] + exact mul_comm _ _ + +variable [Nontrivial E] [Nonempty J] + +lemma continuation_cap_integral_bound_ceil {δ : ℕ → J → (E × ℝ) → J} + (hδ : ∀ n j, Measurable (δ n j)) (y : ℕ → J → E) + {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ Module.finrank ℝ E - 1) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (n k : ℕ) (j : J) : + (∫⁻ s, continuation δ (fun n j => capWeight (y n j) ε) n k j s ∂ambientSphereLaw) ≤ + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) * + streamFactor (E := E) (J := J) q ^ ((k+q-1)/q) := by + apply ambient_mass_bound + apply continuation_mass_bound_ceil _ hδ (fun n j => measurable_capWeight _ _) + (fun n j s => capWeight_le_one _ _ _) + (mul_ne_zero (by positivity) (by positivity)) (ENNReal.mul_ne_top ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top) + (fun n j => capWeight_mass (y n j) hε a ha) + (Module.finrank_pos (R := ℝ) (M := E)) (by omega) hq hqa + +lemma route_cap_bound_ceil {δ : ℕ → J → (E × ℝ) → J} + (hδ : ∀ n j, Measurable (δ n j)) (y : J → E) + {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ Module.finrank ℝ E - 1) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (k : ℕ) (j : J) : + ((sphereLaw (E := E)).prod (Measure.pi (fun _ : Fin k => stdGaussian E))) + {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} ≤ + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^a)) * + streamFactor (E := E) (J := J) q ^ ((k+q-1)/q) := by + let w : ℕ → J → E → ℝ≥0∞ := fun _ j => capWeight (y j) ε + have hV := measurable_continuation (w := w) hδ (fun _ j => measurable_capWeight (y j) ε) 0 k j + have he (s : E) : continuation δ w 0 k j s = + ∫⁻ A : Fin k → E, capWeight (y (streamRoute δ 0 k j (A,fun i => ⟪s,A i⟫))) ε s + ∂Measure.pi (fun _ => stdGaussian E) := by + simpa [w, blockValue, continuation] using continuation_unroll (w := w) hδ 0 k 0 j s + let S : Set ((Metric.sphere (0 : E) 1) × (Fin k → E)) := + {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} + have hS : MeasurableSet S := by + apply measurableSet_le _ measurable_const + exact measurable_subtype_coe.comp measurable_fst |>.dist + ((measurable_of_finite y).comp ((measurable_streamRoute hδ 0 k j).comp (by fun_prop))) + change ((sphereLaw (E := E)).prod _) S ≤ _ + rw [← one_mul (((sphereLaw (E := E)).prod _) S), ← lintegral_indicator_const hS 1, + lintegral_prod _ (measurable_const.indicator hS).aemeasurable] + have hf : ∀ s : Metric.sphere (0 : E) 1, + (∫⁻ A, S.indicator (fun _ => (1 : ℝ≥0∞)) (s,A) ∂Measure.pi (fun _ => stdGaussian E)) = + continuation δ w 0 k j s.val := by + intro s + rw [he] + apply lintegral_congr + intro A + classical + change (if dist s.val (y (streamRoute δ 0 k j (A,fun i => ⟪s.val,A i⟫))) ≤ ε then 1 else 0) = _ + unfold capWeight + rw [Set.indicator_apply] + rfl + simp_rw [hf] + rw [← lintegral_map hV measurable_subtype_coe] + exact continuation_cap_integral_bound_ceil hδ (fun _ => y) hε ha hq hqa 0 k j + +end + +namespace Learner +universe u +variable {d M T : ℕ} {Ω : Type u} + +instance taggedMeasurableSingletonClass : MeasurableSingletonClass (TaggedState M T) := + ⟨fun _ => trivial⟩ + +lemma card_taggedState (M T : ℕ) : Fintype.card (TaggedState M T) = (T+2)*2^M := by + simp only [TaggedState, Fintype.card_sum, Fintype.card_prod, Fintype.card_fin, State] + ring + +def decodeTagged : TaggedState M T → RunStatus M + | .inl j => .inl j + | .inr (t,j) => .inr (t.val,j) + +def taggedStep (τ : ℕ → State M → (Vector d × ℝ) → Bool × State M) + (t : ℕ) : TaggedState M T → (Vector d × ℝ) → TaggedState M T + | .inr done, _ => .inr done + | .inl j, obs => + if ht : t ≤ T then + let a := τ t j obs + if a.1 then .inr (⟨t,by omega⟩,a.2) else .inl a.2 + else .inl j + +lemma measurable_taggedStep {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + (hτ : ∀ t j, Measurable (τ t j)) (t : ℕ) (j : TaggedState M T) : + Measurable (taggedStep (T := T) τ t j) := by + classical + cases j with + | inr done => exact measurable_const + | inl j => + unfold taggedStep + split_ifs with ht + · exact (measurable_of_finite (fun a : Bool × State M => + if a.1 then Sum.inr ((⟨t,by omega⟩ : Fin (T+1)),a.2) else Sum.inl a.2)).comp (hτ t j) + · exact measurable_const + +def taggedOutput (L : Learner d M T Ω) (ω : Ω) : TaggedState M T → UnitSphere d + | .inl j => L.output T ω j + | .inr (t,j) => L.output t ω j + +lemma decode_taggedStart (a : Bool × State M) : + decodeTagged (taggedStart (T := T) a) = if a.1 then .inr (0,a.2) else .inl a.2 := by + simp only [taggedStart]; split_ifs <;> rfl + +lemma run_eq_taggedRoute (L : Learner d M T Ω) (s : UnitSphere d) (ω : Ω) (x : Samples d T) + {n : ℕ} (hn : n ≤ T) : + L.run s ω x n = decodeTagged (streamRoute (taggedStep (T := T) (fun t j => L.transition t ω j)) + 0 n (taggedStart (L.initialChoice ω)) + ((fun i => x (Fin.castLE hn i)),fun i => ⟪s.val,x (Fin.castLE hn i)⟫)) := by + induction n with + | zero => exact (decode_taggedStart _).symm + | succ n ih => + rw [fin_prefix_snoc hn x, fin_prefix_snoc hn (fun i => ⟪s.val,x i⟫),streamRoute_snoc] + rw [run,ih (by omega)] + generalize streamRoute (taggedStep (T := T) (fun t j => L.transition t ω j)) 0 n + (taggedStart (L.initialChoice ω)) + ((fun i => x (Fin.castLE (by omega : n ≤ T) i)),fun i => ⟪s.val,x (Fin.castLE (by omega : n ≤ T) i)⟫) = j + cases j with + | inr done => rfl + | inl j => + simp only [decodeTagged, taggedStep, Nat.zero_add,dite_eq_left (by omega : n < T), + dite_eq_left (by omega : n+1 ≤ T),real_inner_comm] + split_ifs <;> rfl + +lemma estimate_eq_taggedRoute (L : Learner d M T Ω) (s : UnitSphere d) (ω : Ω) (x : Samples d T) : + L.estimate s ω x = L.taggedOutput ω (streamRoute + (taggedStep (T := T) (fun t j => L.transition t ω j)) 0 T (taggedStart (L.initialChoice ω)) + (x,fun i => ⟪s.val,x i⟫)) := by + unfold estimate terminal + rw [L.run_eq_taggedRoute s ω x le_rfl] + have hi : (fun i : Fin T => x (Fin.castLE le_rfl i)) = x := by funext i; exact congrArg x (Fin.ext rfl) + have hb : (fun i : Fin T => ⟪s.val,x (Fin.castLE le_rfl i)⟫) = (fun i => ⟪s.val,x i⟫) := by funext i; rfl + rw [hi,hb] + generalize streamRoute (taggedStep (T := T) (fun t j => L.transition t ω j)) 0 T + (taggedStart (L.initialChoice ω)) (x,fun i => ⟪s.val,x i⟫) = j + cases j with + | inl j => rfl + | inr done => rfl + +lemma taggedStep_congr {τ τ' : ℕ → State M → (Vector d × ℝ) → Bool × State M} + (t : ℕ) (j : TaggedState M T) (obs : Vector d × ℝ) + (h : ∀ a, τ t a obs = τ' t a obs) : + taggedStep τ t j obs = taggedStep τ' t j obs := by + cases j with + | inr done => rfl + | inl j => simp only [taggedStep,h] + +lemma frozen_success_bound_tagged (L : Learner d M T Ω) (ω : Ω) (hd : 3 ≤ d) + (htrans : ∀ t j, AEMeasurable (L.transition t ω j) (observationReference d)) + {ε : ℝ} (hε : 0 < ε) {a q : ℕ} (ha : 2*a ≤ d-1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) : + ((uniformSphere d).prod (sampleLaw d T)) + {z | angularError z.1 (L.estimate z.1 ω z.2) ≤ ε} ≤ + (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := TaggedState M T) q ^ ((T+q-1)/q) := by + classical + let : NeZero d := ⟨by omega⟩ + let τ : ℕ → State M → (Vector d × ℝ) → Bool × State M := fun t j => (htrans t j).mk _ + have hτ (t : ℕ) (j : State M) : Measurable (τ t j) := (htrans t j).measurable_mk + let μ := (uniformSphere d).prod (sampleLaw d T) + have hgood : ∀ᵐ z ∂μ, ∀ t j (i : Fin T), + L.transition t ω j (z.2 i,⟪z.1.val,z.2 i⟫) = τ t j (z.2 i,⟪z.1.val,z.2 i⟫) := by + simp only [ae_all_iff] + intro t j i + exact (sphere_sample_observation_quasi (by simpa using hd) i).ae (htrans t j).ae_eq_mk + let S := {z : UnitSphere d × Samples d T | dist z.1.val + (L.taggedOutput ω (streamRoute (taggedStep (T := T) τ) 0 T (taggedStart (L.initialChoice ω)) + (z.2,fun i => ⟪z.1.val,z.2 i⟫))).val ≤ ε} + have hmono : {z : UnitSphere d × Samples d T | angularError z.1 (L.estimate z.1 ω z.2) ≤ ε} + ≤ᵐ[μ] S := by + filter_upwards [hgood] with z hz + intro hs + have he := streamRoute_congr (taggedStep (T := T) (fun t j => L.transition t ω j)) + (taggedStep (T := T) τ) 0 T (taggedStart (L.initialChoice ω)) z.2 + (fun i => ⟪z.1.val,z.2 i⟫) (fun t j i => taggedStep_congr t j _ (fun a => hz t a i)) + have hc : dist z.1.val (L.estimate z.1 ω z.2).val ≤ ε := by + apply le_trans _ hs + simpa only [angularError,dist_comm] using chord_le_arccos (L.estimate z.1 ω z.2) z.1 + change dist z.1.val _ ≤ ε + rw [L.estimate_eq_taggedRoute,he] at hc + exact hc + apply (measure_mono_ae hmono).trans + simpa only [S,μ,uniformSphere,sphereLaw,sampleLaw,finrank_euclideanSpace_fin] using + route_cap_bound_ceil (measurable_taggedStep hτ) (fun j => (L.taggedOutput ω j).val) + hε (by simpa using ha) hq hqa T (taggedStart (L.initialChoice ω)) + +lemma streaming_success_bound_tagged [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 3 ≤ d) {ε : ℝ} (hε : 0 < ε) + {a q : ℕ} (ha : 2*a ≤ d-1) (hq : 2 ≤ q) (hqa : 2*q ≤ a) : + L.uniformSuccess ρ ε ≤ + (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := TaggedState M T) q ^ ((T+q-1)/q) := by + let : NeZero d := ⟨by omega⟩ + let : SigmaFinite (observationReference d) := by unfold observationReference; infer_instance + have hω : ∀ᵐ ω ∂ρ, ∀ t j, + AEMeasurable (L.transition t ω j) (observationReference d) := by + simp only [ae_all_iff] + intro t j + exact ae_fiber_aemeasurable (hL.transition t j).prod_swap + have hp := ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := ρ))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) ρ) + let S := {z : UnitSphere d × (Ω × Samples d T) | + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + have hS : NullMeasurableSet S ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := + L.angularSuccess_nullMeasurable ρ ε hL + have he := hp.measure_preimage hS + have hb := prod_null_set_bound (hS.preimage hp.quasiMeasurePreserving) + (c := (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^a)) * + streamFactor (E := Vector d) (J := TaggedState M T) q ^ ((T+q-1)/q)) + (by + filter_upwards [hω] with ω hω + exact L.frozen_success_bound_tagged ω hd hω hε ha hq hqa) + simpa only [he,measure_univ,mul_one,S,uniformSuccess] using hb + +end Learner +end NoiselessRegression + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/StoppingKernel.lean b/lean/OAI/Probability/ProjectionMoments/StoppingKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..103d8bdc8632f8084212b75a3ae04d63f3454351 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/StoppingKernel.lean @@ -0,0 +1,443 @@ +import OAI.Probability.ProjectionMoments.Realization + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression + +section +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] + +lemma capWeight_mass_mixed (y : E) {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) + (a : ℕ) {b : ℝ} (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (Module.finrank ℝ E-1:ℕ)) : + PolynomialMass ((ambientSphereLaw (E := E)).withDensity (capWeight y ε)) a + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^b)) := by + change PolynomialMass ((ambientSphereLaw (E := E)).withDensity ((Metric.closedBall y ε).indicator 1)) a _ + rw [withDensity_indicator_one Metric.isClosed_closedBall.measurableSet] + intro z r hr + rw [Measure.restrict_apply Metric.isClosed_closedBall.measurableSet] + by_cases h : r ≤ ε + · apply (measure_mono Set.inter_subset_left).trans + apply (ambientSphereLaw_closedBall z hr (Module.finrank ℝ E-1) le_rfl).trans + rw [mul_assoc, ← ENNReal.ofReal_mul (Real.rpow_nonneg hε.le _)] + apply mul_le_mul' le_rfl + apply ENNReal.ofReal_le_ofReal + have hpow : r^(Module.finrank ℝ E-1) ≤ r^((a:ℝ)+b) := by + rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_ge hr (h.trans hε1) hab + apply hpow.trans + rw [Real.rpow_add hr,Real.rpow_natCast,mul_comm] + exact mul_le_mul_of_nonneg_right (Real.rpow_le_rpow hr.le h hb) (pow_nonneg hr.le _) + · apply (measure_mono Set.inter_subset_right).trans + apply (ambientSphereLaw_closedBall y hε (Module.finrank ℝ E-1) le_rfl).trans + rw [mul_assoc, ← ENNReal.ofReal_mul (Real.rpow_nonneg hε.le _)] + apply mul_le_mul' le_rfl + apply ENNReal.ofReal_le_ofReal + have hpow : ε^(Module.finrank ℝ E-1) ≤ ε^((a:ℝ)+b) := by + rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_ge hε hε1 hab + apply hpow.trans + rw [Real.rpow_add hε,Real.rpow_natCast,mul_comm] + exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ hε.le (le_of_not_ge h) a) (Real.rpow_nonneg hε.le _) + +variable {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] [Nonempty J] + +lemma continuation_mixed_integral_bound {δ : ℕ → J → (E × ℝ) → J} + (hδ : ∀ n j, Measurable (δ n j)) (y : ℕ → J → E) + {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) {a q : ℕ} {b : ℝ} + (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (Module.finrank ℝ E-1:ℕ)) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (n k : ℕ) (j : J) : + (∫⁻ s, continuation δ (fun n j => capWeight (y n j) ε) n k j s ∂ambientSphereLaw) ≤ + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^b)) * + streamFactor (E := E) (J := J) q ^ ((k+q-1)/q) := by + have ha : a ≤ Module.finrank ℝ E := by + have : (a:ℝ) ≤ (Module.finrank ℝ E:ℝ) := by + have hh : ((Module.finrank ℝ E-1:ℕ):ℝ) ≤ Module.finrank ℝ E := by exact_mod_cast Nat.sub_le (Module.finrank ℝ E) 1 + linarith + exact_mod_cast this + apply ambient_mass_bound + apply continuation_mass_bound_ceil _ hδ (fun n j => measurable_capWeight _ _) + (fun n j s => capWeight_le_one _ _ _) + (mul_ne_zero (by positivity) (by positivity)) (ENNReal.mul_ne_top ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top) + (fun n j => capWeight_mass_mixed (y n j) hε hε1 a hb hab) + (Module.finrank_pos (R := ℝ) (M := E)) ha hq hqa + +lemma route_mixed_bound {δ : ℕ → J → (E × ℝ) → J} + (hδ : ∀ n j, Measurable (δ n j)) (y : J → E) + {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) {a q : ℕ} {b : ℝ} + (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (Module.finrank ℝ E-1:ℕ)) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (k : ℕ) (j : J) : + ((sphereLaw (E := E)).prod (Measure.pi (fun _ : Fin k => stdGaussian E))) + {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} ≤ + (ENNReal.ofReal ((3 : ℝ)*4^Module.finrank ℝ E) * ENNReal.ofReal (ε^b)) * + streamFactor (E := E) (J := J) q ^ ((k+q-1)/q) := by + let w : ℕ → J → E → ℝ≥0∞ := fun _ j => capWeight (y j) ε + have hV := measurable_continuation (w := w) hδ (fun _ j => measurable_capWeight (y j) ε) 0 k j + have he (s : E) : continuation δ w 0 k j s = + ∫⁻ A : Fin k → E, capWeight (y (streamRoute δ 0 k j (A,fun i => ⟪s,A i⟫))) ε s + ∂Measure.pi (fun _ => stdGaussian E) := by + simpa [w, blockValue, continuation] using continuation_unroll (w := w) hδ 0 k 0 j s + let S : Set ((Metric.sphere (0 : E) 1) × (Fin k → E)) := + {z | dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} + have hS : MeasurableSet S := by + apply measurableSet_le _ measurable_const + exact measurable_subtype_coe.comp measurable_fst |>.dist + ((measurable_of_finite y).comp ((measurable_streamRoute hδ 0 k j).comp (by fun_prop))) + change ((sphereLaw (E := E)).prod _) S ≤ _ + rw [← one_mul (((sphereLaw (E := E)).prod _) S), ← lintegral_indicator_const hS 1, + lintegral_prod _ (measurable_const.indicator hS).aemeasurable] + have hf : ∀ s : Metric.sphere (0 : E) 1, + (∫⁻ A, S.indicator (fun _ => (1 : ℝ≥0∞)) (s,A) ∂Measure.pi (fun _ => stdGaussian E)) = + continuation δ w 0 k j s.val := by + intro s + rw [he] + apply lintegral_congr + intro A + classical + change (if dist s.val (y (streamRoute δ 0 k j (A,fun i => ⟪s.val,A i⟫))) ≤ ε then 1 else 0) = _ + unfold capWeight + rw [Set.indicator_apply] + rfl + simp_rw [hf] + rw [← lintegral_map hV measurable_subtype_coe] + exact continuation_mixed_integral_bound hδ (fun _ => y) hε hε1 hb hab hq hqa 0 k j + +end + +namespace Learner + +section +variable {d M : ℕ} + +def haltShift {k : ℕ} : TaggedState M k → TaggedState M (k+1) + | .inl j => .inl j + | .inr (t,j) => .inr (t.succ,j) + +def haltRoute (τ : ℕ → State M → (Vector d × ℝ) → Bool × State M) (n : ℕ) : + (k : ℕ) → State M → ((Fin k → Vector d) × (Fin k → ℝ)) → TaggedState M k + | 0, j, _ => .inl j + | k+1, j, X => + let a := τ (n+1) j (X.1 0,X.2 0) + if a.1 then .inr (⟨1,by omega⟩,a.2) + else haltShift (haltRoute τ (n+1) k a.2 (Fin.tail X.1,Fin.tail X.2)) + +lemma measurable_haltRoute {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + (hτ : ∀ t j, Measurable (τ t j)) (n k : ℕ) (j : State M) : + Measurable (haltRoute τ n k j) := by + induction k generalizing n j with + | zero => exact measurable_const + | succ k ih => + let h : (Bool × State M) → ((Fin (k+1) → Vector d) × (Fin (k+1) → ℝ)) → TaggedState M (k+1) := + fun a X => if a.1 then .inr (⟨1,by omega⟩,a.2) + else haltShift (haltRoute τ (n+1) k a.2 (Fin.tail X.1,Fin.tail X.2)) + change Measurable (fun X => h (τ (n+1) j (X.1 0,X.2 0)) X) + apply measurable_select (J := Bool × State M) _ ((hτ (n+1) j).comp (by fun_prop)) + intro a + dsimp [h] + split_ifs + · exact measurable_const + · exact (measurable_of_finite haltShift).comp ((ih (n+1) a.2).comp (by + change Measurable (fun X : ((Fin (k+1) → Vector d) × (Fin (k+1) → ℝ)) => + ((fun i : Fin k => X.1 i.succ),(fun i : Fin k => X.2 i.succ))) + fun_prop)) + +def haltChild (w : ℕ → State M → Vector d → ℝ≥0∞) + (v : State M → Vector d → ℝ≥0∞) (n : ℕ) {k : ℕ} : TaggedState M k → Vector d → ℝ≥0∞ + | .inl j => v j + | .inr (t,j) => w (n+t) j + +def stoppedContinuation (τ : ℕ → State M → (Vector d × ℝ) → Bool × State M) + (w : ℕ → State M → Vector d → ℝ≥0∞) (n : ℕ) : ℕ → State M → Vector d → ℝ≥0∞ + | 0, j, s => w n j s + | k+1, j, s => ∫⁻ x, let a := τ (n+1) j (x,⟪s,x⟫) + if a.1 then w (n+1) a.2 s else stoppedContinuation τ w (n+1) k a.2 s ∂stdGaussian (Vector d) + +lemma measurable_stoppedContinuation {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + {w : ℕ → State M → Vector d → ℝ≥0∞} + (hτ : ∀ t j, Measurable (τ t j)) (hw : ∀ n j, Measurable (w n j)) (n k : ℕ) (j : State M) : + Measurable (stoppedContinuation τ w n k j) := by + induction k generalizing n j with + | zero => exact hw n j + | succ k ih => + apply Measurable.lintegral_prod_left + change Measurable (fun z : Vector d × Vector d => + if (τ (n+1) j (z.1,⟪z.2,z.1⟫)).1 then w (n+1) (τ (n+1) j (z.1,⟪z.2,z.1⟫)).2 z.2 + else stoppedContinuation τ w (n+1) k (τ (n+1) j (z.1,⟪z.2,z.1⟫)).2 z.2) + apply measurable_select (J := Bool × State M) (h := fun a (z : Vector d × Vector d) => + if a.1 then w (n+1) a.2 z.2 else stoppedContinuation τ w (n+1) k a.2 z.2) _ + ((hτ (n+1) j).comp (by fun_prop)) + intro a + split_ifs + · exact (hw (n+1) a.2).comp measurable_snd + · exact (ih (n+1) a.2).comp measurable_snd + +lemma stoppedContinuation_le_one + {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + {w : ℕ → State M → Vector d → ℝ≥0∞} + (hw : ∀ n j s, w n j s ≤ 1) (n k : ℕ) (j : State M) (s : Vector d) : + stoppedContinuation τ w n k j s ≤ 1 := by + induction k generalizing n j with + | zero => exact hw n j s + | succ k ih => + change (∫⁻ x, (if (τ (n+1) j (x,⟪s,x⟫)).1 then w (n+1) (τ (n+1) j (x,⟪s,x⟫)).2 s else stoppedContinuation τ w (n+1) k (τ (n+1) j (x,⟪s,x⟫)).2 s) ∂stdGaussian (Vector d)) ≤ 1 + apply (lintegral_mono (g := fun _ => (1:ℝ≥0∞)) (fun x => ?_)).trans_eq (by simp) + split_ifs + · exact hw _ _ _ + · exact ih _ _ + +lemma stoppedContinuation_unroll + {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + {w : ℕ → State M → Vector d → ℝ≥0∞} + (hτ : ∀ t j, Measurable (τ t j)) (n m k : ℕ) (j : State M) (s : Vector d) : + stoppedContinuation τ w n (m+k) j s = + blockValue (haltChild w (stoppedContinuation τ w (n+m) k) n) (haltRoute τ n m j) s := by + induction m generalizing n j with + | zero => simp [blockValue,haltRoute,haltChild] + | succ m ih => + rw [Nat.succ_add,stoppedContinuation] + unfold blockValue + have hf : Measurable (fun X : Fin (m+1) → Vector d => + haltChild w (stoppedContinuation τ w (n+(m+1)) k) n + (haltRoute τ n (m+1) j (X,fun i => ⟪s,X i⟫)) s) := + (measurable_of_finite (fun a => haltChild w (stoppedContinuation τ w (n+(m+1)) k) n a s)).comp + ((measurable_haltRoute hτ n (m+1) j).comp (by fun_prop)) + rw [lintegral_pi_cons _ _ hf] + apply lintegral_congr + intro x + have htail (X : Fin m → Vector d) : Fin.tail (fun i : Fin (m+1) => ⟪s,(Fin.cons x X : Fin (m+1) → Vector d) i⟫) = (fun i => ⟪s,X i⟫) := by funext i; rfl + simp only [haltRoute,Fin.cons_zero,Fin.tail_cons,htail] + split_ifs with h + · simp [haltChild] + · rw [ih] + unfold blockValue + apply lintegral_congr + intro X + have h1 : n+(m+1) = n+1+m := by omega + rw [h1] + generalize haltRoute τ (n+1) m (τ (n+1) j (x,⟪s,x⟫)).2 (X,fun i => ⟪s,X i⟫) = a + cases a with + | inl j => rfl + | inr done => + simp only [haltShift,haltChild,Fin.val_succ] + rw [show n+1+done.1.val = n+(done.1.val+1) by omega] + +lemma stoppedContinuation_mass_bound {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + {w : ℕ → State M → Vector d → ℝ≥0∞} + (hτ : ∀ t j, Measurable (τ t j)) (hw : ∀ n j, Measurable (w n j)) + (hw1 : ∀ n j s, w n j s ≤ 1) + {a q : ℕ} {C : ℝ≥0∞} (hC : C ≠ 0) (hCt : C ≠ ∞) + (hlocal : ∀ n j, PolynomialMass (ambientSphereLaw.withDensity (w n j)) a C) + (hd : 1 ≤ d) (ha : a ≤ d) (hq : 2 ≤ q) (hqa : 2*q ≤ a) + (n k : ℕ) (j : State M) : + PolynomialMass (ambientSphereLaw.withDensity (stoppedContinuation τ w n k j)) a + (C * streamFactor (E := Vector d) (J := TaggedState M q) q ^ ((k+q-1)/q)) := by + let : NeZero d := ⟨by omega⟩ + let K := streamFactor (E := Vector d) (J := TaggedState M q) q + have hK1 : 1 ≤ K := one_le_streamFactor (by omega) + have hK0 : K ≠ 0 := ne_of_gt (lt_of_lt_of_le zero_lt_one hK1) + have hKt : K ≠ ∞ := streamFactor_ne_top _ + have hden : ((q-1 : ℕ) : ℝ)+1 = (q : ℝ) := by rw [Nat.cast_sub (by omega),Nat.cast_one]; ring + have hq0 : 0 < q := by omega + change PolynomialMass _ a (C*K^_) + induction k using Nat.strong_induction_on generalizing n j with + | h k ih => + by_cases hk0 : k = 0 + · subst k + simpa only [Nat.zero_add,Nat.div_eq_of_lt (by omega : q-1 < q),pow_zero,mul_one,stoppedContinuation] using hlocal n j + let m := min k q + have hm0 : 0 < m := by dsimp [m]; omega + have hm : m ≤ q := min_le_right _ _ + have hmk : m ≤ k := min_le_left _ _ + have hki : k-m < k := by omega + let C' := C*K^((k-m+q-1)/q) + have hC' : C' ≠ 0 := mul_ne_zero hC (pow_ne_zero _ hK0) + have hC't : C' ≠ ∞ := ENNReal.mul_ne_top hCt (ENNReal.pow_ne_top hKt) + have hCC' : C ≤ C' := le_mul_of_one_le_right' (one_le_pow₀ hK1) + let f := haltChild w (stoppedContinuation τ w (n+m) (k-m)) n (k := m) + have hf (a : TaggedState M m) : Measurable (f a) := by + cases a with + | inl j => exact measurable_stoppedContinuation hτ hw _ _ _ + | inr done => exact hw _ _ + have hf1 (a : TaggedState M m) (s : Vector d) : f a s ≤ 1 := by + cases a with + | inl j => exact stoppedContinuation_le_one hw1 _ _ _ _ + | inr done => exact hw1 _ _ _ + have hflocal (a' : TaggedState M m) : PolynomialMass (ambientSphereLaw.withDensity (f a')) a C' := by + cases a' with + | inl j => exact ih (k-m) hki (n+m) j + | inr done => + intro z r hr + exact (hlocal (n+done.1) done.2 z r hr).trans (mul_le_mul' hCC' le_rfl) + have hb := blockValue_mass_bound ambientSphereLaw hf hf1 hflocal hC' hC't + (by simpa using hd) (by simpa using ha) (by simpa using (show m ≤ d by omega)) + (by omega : 1 ≤ q-1) (by omega : q-1+m ≤ a) (measurable_haltRoute hτ n m j) + have he : stoppedContinuation τ w n k j = blockValue f (haltRoute τ n m j) := by + funext s + simpa [f,Nat.add_sub_of_le hmk] using stoppedContinuation_unroll hτ n m (k-m) j s + rw [he] + intro z r hr + apply (hb z r hr).trans + apply mul_le_mul' _ le_rfl + have hdiv : (k+q-1)/q = (k-m+q-1)/q+1 := by + by_cases hqk : q ≤ k + · have hme : m = q := min_eq_right hqk + rw [hme] + have he : k+q-1 = q+(k-q+q-1) := by omega + rw [he,Nat.add_div_left _ hq0] + · have hme : m = k := min_eq_left (by omega) + rw [hme,Nat.sub_self,Nat.zero_add,Nat.div_eq_of_lt (by omega : q-1 < q)] + have he : k+q-1 = q+(k-1) := by omega + rw [he,Nat.add_div_left _ hq0,Nat.div_eq_of_lt (by omega : k-1 < q)] + rw [hden] + have hcard : (Fintype.card (TaggedState M m):ℝ≥0∞)^(1/(q:ℝ)) ≤ + (Fintype.card (TaggedState M q):ℝ≥0∞)^(1/(q:ℝ)) := by + apply ENNReal.rpow_le_rpow _ (by positivity) + exact_mod_cast (show Fintype.card (TaggedState M m) ≤ Fintype.card (TaggedState M q) by + rw [card_taggedState,card_taggedState] + exact Nat.mul_le_mul_right _ (Nat.add_le_add_right hm 2)) + calc + _ ≤ K*C' := mul_le_mul' (mul_le_mul' le_rfl hcard) le_rfl + _ = _ := by rw [hdiv,pow_succ]; dsimp [C']; ring + +end + +variable {d M T : ℕ} + +def taggedWeight (w : ℕ → State M → Vector d → ℝ≥0∞) (n : ℕ) : TaggedState M T → Vector d → ℝ≥0∞ + | .inl j => w n j + | .inr (t,j) => w t j + +lemma measurable_taggedWeight {w : ℕ → State M → Vector d → ℝ≥0∞} + (hw : ∀ n j, Measurable (w n j)) (n : ℕ) (j : TaggedState M T) : + Measurable (taggedWeight w n j) := by cases j <;> exact hw _ _ + +lemma continuation_tagged_eq {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + {w : ℕ → State M → Vector d → ℝ≥0∞} + (n k : ℕ) (hnk : n+k ≤ T) (j : TaggedState M T) (s : Vector d) : + continuation (taggedStep τ) (taggedWeight w) n k j s = + match j with + | .inl a => stoppedContinuation τ w n k a s + | .inr (t,a) => w t a s := by + induction k generalizing n j with + | zero => cases j <;> rfl + | succ k ih => + cases j with + | inl j => + simp only [continuation,stoppedContinuation] + apply lintegral_congr + intro x + rw [ih (n+1) (by omega)] + simp only [taggedStep,dite_eq_left (by omega : n+1 ≤ T)] + split_ifs <;> rfl + | inr done => + simp only [continuation,taggedStep] + simp only [ih (n+1) (by omega),lintegral_const,measure_univ,mul_one] + +lemma tagged_continuation_mass {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + {w : ℕ → State M → Vector d → ℝ≥0∞} + (hτ : ∀ t j, Measurable (τ t j)) (hw : ∀ n j, Measurable (w n j)) + (hw1 : ∀ n j s, w n j s ≤ 1) + {a q : ℕ} {C : ℝ≥0∞} (hC : C ≠ 0) (hCt : C ≠ ∞) + (hlocal : ∀ n j, PolynomialMass (ambientSphereLaw.withDensity (w n j)) a C) + (hd : 1 ≤ d) (ha : a ≤ d) (hq : 2 ≤ q) (hqa : 2*q ≤ a) + (j : TaggedState M T) : + PolynomialMass (ambientSphereLaw.withDensity + (continuation (taggedStep τ) (taggedWeight w) 0 T j)) a + (C * streamFactor (E := Vector d) (J := TaggedState M q) q ^ ((T+q-1)/q)) := by + have he := fun s => continuation_tagged_eq (τ := τ) (w := w) 0 T (by omega) j s + cases j with + | inl j => + have he' : continuation (taggedStep (T := T) τ) (taggedWeight w) 0 T (.inl j) = stoppedContinuation τ w 0 T j := + funext he + rw [he'] + exact stoppedContinuation_mass_bound hτ hw hw1 hC hCt hlocal hd ha hq hqa 0 T j + | inr done => + have he' : continuation (taggedStep (T := T) τ) (taggedWeight w) 0 T (.inr done) = w done.1 done.2 := + funext he + rw [he'] + intro z r hr + apply (hlocal _ _ z r hr).trans + apply mul_le_mul' _ le_rfl + exact le_mul_of_one_le_right' (one_le_pow₀ (one_le_streamFactor (by omega))) + +variable [NeZero d] + +lemma stopped_route_mixed_bound {τ : ℕ → State M → (Vector d × ℝ) → Bool × State M} + (hτ : ∀ t j, Measurable (τ t j)) (y : ℕ → State M → Vector d) + {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) {a q : ℕ} {b : ℝ} + (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (d-1:ℕ)) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) (j : TaggedState M T) : + ((uniformSphere d).prod (sampleLaw d T)) + {z | dist z.1.val + (match streamRoute (taggedStep (T := T) τ) 0 T j (z.2,fun i => ⟪z.1.val,z.2 i⟫) with + | .inl a => y T a + | .inr (t,a) => y t a) ≤ ε} ≤ + (ENNReal.ofReal ((3:ℝ)*4^d)*ENNReal.ofReal (ε^b)) * + streamFactor (E := Vector d) (J := TaggedState M q) q ^ ((T+q-1)/q) := by + let w : ℕ → State M → Vector d → ℝ≥0∞ := fun n j => capWeight (y n j) ε + let δ := taggedStep (T := T) τ + let w' : ℕ → TaggedState M T → Vector d → ℝ≥0∞ := taggedWeight w + let yy : TaggedState M T → Vector d := fun a => match a with + | .inl a => y T a + | .inr (t,a) => y t a + have hw' (n : ℕ) (a : TaggedState M T) : Measurable (w' n a) := + measurable_taggedWeight (fun n j => measurable_capWeight _ _) n a + have hδ := measurable_taggedStep (T := T) hτ + have hV := measurable_continuation hδ hw' 0 T j + have he (s : Vector d) : continuation δ w' 0 T j s = + ∫⁻ A : Fin T → Vector d, capWeight (yy (streamRoute δ 0 T j (A,fun i => ⟪s,A i⟫))) ε s + ∂Measure.pi (fun _ => stdGaussian (Vector d)) := by + have hu := continuation_unroll (w := w') hδ 0 T 0 j s + simp only [Nat.add_zero,continuation] at hu + rw [hu] + unfold blockValue + apply lintegral_congr + intro A + cases streamRoute δ 0 T j (A,fun i => ⟪s,A i⟫) <;> simp [w',w,yy,taggedWeight] + let S : Set (UnitSphere d × Samples d T) := + {z | dist z.1.val (yy (streamRoute δ 0 T j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} + have hS : MeasurableSet S := by + apply measurableSet_le _ measurable_const + exact (measurable_subtype_coe.comp measurable_fst).dist + ((measurable_of_finite yy).comp ((measurable_streamRoute hδ 0 T j).comp (by fun_prop))) + change ((sphereLaw (E := Vector d)).prod _) S ≤ _ + rw [← one_mul (((sphereLaw (E := Vector d)).prod _) S), ← lintegral_indicator_const hS 1, + lintegral_prod _ (measurable_const.indicator hS).aemeasurable] + have hf : ∀ s : UnitSphere d, + (∫⁻ A, S.indicator (fun _ => (1:ℝ≥0∞)) (s,A) ∂sampleLaw d T) = continuation δ w' 0 T j s.val := by + intro s + rw [he] + apply lintegral_congr + intro A + classical + change (if dist s.val (yy (streamRoute δ 0 T j (A,fun i => ⟪s.val,A i⟫))) ≤ ε then 1 else 0) = _ + unfold capWeight + rw [Set.indicator_apply] + rfl + simp_rw [hf] + rw [← lintegral_map hV measurable_subtype_coe] + apply ambient_mass_bound (a := a) + have ha : a ≤ d := by + have hdn : ((d-1:ℕ):ℝ) ≤ (d:ℝ) := by exact_mod_cast Nat.sub_le d 1 + have : (a:ℝ) ≤ d := by linarith + exact_mod_cast this + have hl (n : ℕ) (j : State M) : PolynomialMass (ambientSphereLaw.withDensity (w n j)) a + (ENNReal.ofReal ((3:ℝ)*4^d)*ENNReal.ofReal (ε^b)) := by + simpa only [finrank_euclideanSpace_fin] using capWeight_mass_mixed (y n j) hε hε1 a hb (by simpa using hab) + exact tagged_continuation_mass hτ (fun n j => measurable_capWeight _ _) + (fun n j s => capWeight_le_one _ _ _) + (mul_ne_zero (by positivity) (by positivity)) + (ENNReal.mul_ne_top ENNReal.ofReal_ne_top ENNReal.ofReal_ne_top) + hl + (Nat.pos_of_ne_zero (NeZero.ne d)) ha hq hqa j + +end Learner +end NoiselessRegression + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/Streaming.lean b/lean/OAI/Probability/ProjectionMoments/Streaming.lean new file mode 100644 index 0000000000000000000000000000000000000000..9870878d62e1834c4bae2c6dd1d91256ad35347c --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/Streaming.lean @@ -0,0 +1,400 @@ +import OAI.Probability.ProjectionMoments.StoppingKernel + +namespace OAI + +noncomputable section + +open MeasureTheory ProbabilityTheory Set Filter +open scoped ENNReal NNReal RealInnerProductSpace +namespace NoiselessRegression + +section +namespace Learner +universe u + +theorem riesz_success : + ∃ C₀ : ℝ, 1 ≤ C₀ ∧ ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Learner d M T Ω, L.Admissible ρ → + let q := d/8 + let W : ℝ := ((T:ℝ)+2)*2^M + L.uniformSuccess ρ ε ≤ ENNReal.ofReal + (C₀^d*ε^((d:ℝ)/2-1)*(1+C₀^d*(1+Real.log (1/ε))*W^(1/(q:ℝ)))^((T+q-1)/q)) := by + refine ⟨32768,by norm_num,?_⟩ + intro d M T hd ε hε hε10 Ω _ ρ hρ L hL q W + let : IsProbabilityMeasure ρ := hρ + let a := (d-1)/2 + have hq : 2 ≤ q := by dsimp [q]; omega + have ha : 2*a ≤ d-1 := by dsimp [a]; omega + have hqa : 2*q ≤ a := by dsimp [a,q]; omega + have hb := L.streaming_success_bound_tagged ρ hL (by omega) hε ha hq hqa + have hW : 0 ≤ W := by dsimp [W]; positivity + have hqn : 0 ≤ 1/(q:ℝ) := by positivity + have he : ((T+2)*2^M:ℝ≥0∞)^(1/(q:ℝ)) = ENNReal.ofReal (W^(1/(q:ℝ))) := by + rw [← ENNReal.ofReal_rpow_of_nonneg hW hqn] + congr 1 + dsimp [W] + rw [ENNReal.ofReal_mul (by positivity : 0 ≤ (T:ℝ)+2), + ENNReal.ofReal_add (by positivity : 0 ≤ (T:ℝ)) (by norm_num : (0:ℝ) ≤ 2), + ENNReal.ofReal_pow (by norm_num : (0:ℝ) ≤ 2),ENNReal.ofReal_natCast,ENNReal.ofReal_ofNat] + have hfactor : streamFactor (E := Vector d) (J := TaggedState M T) q = + ENNReal.ofReal ((32768:ℝ)^d*W^(1/(q:ℝ))) := by + unfold streamFactor + rw [finrank_euclideanSpace_fin,card_taggedState,Nat.cast_mul,Nat.cast_add,Nat.cast_pow,Nat.cast_ofNat,he] + rw [ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_pow (by norm_num),ENNReal.ofReal_ofNat] + rw [hfactor, ← ENNReal.ofReal_pow (by positivity : 0 ≤ (32768:ℝ)^d*W^(1/(q:ℝ))), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ (3:ℝ)*4^d), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ (3:ℝ)*4^d*ε^a)] at hb + apply hb.trans + apply ENNReal.ofReal_le_ofReal + have hε1 : ε ≤ 1 := by linarith + have hexp : (d:ℝ)/2-1 ≤ a := by + have hh : d-1 ≤ 2*a+1 := by dsimp [a]; omega + have hd1 : 1 ≤ d := by omega + have hh' : (d:ℝ) ≤ 2*(a:ℝ)+2 := by + exact_mod_cast (show d ≤ 2*a+2 by omega) + linarith + have heps : ε^a ≤ ε^((d:ℝ)/2-1) := by + rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_ge hε hε1 hexp + have hconst : (3:ℝ)*4^d ≤ (32768:ℝ)^d := by + have hp' : (3:ℝ)^1 ≤ 3^d := pow_le_pow_right₀ (by norm_num) (by omega) + have hsmall : (12:ℝ)^d ≤ (32768:ℝ)^d := pow_le_pow_left₀ (by norm_num) (by norm_num) d + calc + (3:ℝ)*4^d ≤ 3^d*4^d := mul_le_mul_of_nonneg_right (by simpa using hp') (by positivity) + _ = 12^d := by rw [← mul_pow]; norm_num + _ ≤ _ := hsmall + have hlog : 0 ≤ Real.log (1/ε) := Real.log_nonneg ((one_le_div hε).mpr hε1) + have hstep : (32768:ℝ)^d*W^(1/(q:ℝ)) ≤ + 1+(32768:ℝ)^d*(1+Real.log (1/ε))*W^(1/(q:ℝ)) := by + have hm : (32768:ℝ)^d*W^(1/(q:ℝ)) ≤ + (32768:ℝ)^d*(1+Real.log (1/ε))*W^(1/(q:ℝ)) := by + apply mul_le_mul_of_nonneg_right _ (Real.rpow_nonneg hW _) + nlinarith [pow_nonneg (by norm_num : (0:ℝ) ≤ 32768) d] + linarith + exact mul_le_mul (mul_le_mul hconst heps (by positivity) (by positivity)) + (pow_le_pow_left₀ (by positivity) hstep _) (by positivity) (by positivity) + +end Learner + +universe u +variable {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] [MeasurableSpace E] [BorelSpace E] [Nontrivial E] + +lemma prefix_route_mixed_bound + {J : Type*} [Fintype J] [MeasurableSpace J] [MeasurableSingletonClass J] [Nonempty J] + {δ : ℕ → J → (E × ℝ) → J} (hδ : ∀ n j, Measurable (δ n j)) (y : J → E) + {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) {a q : ℕ} {b : ℝ} + (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (Module.finrank ℝ E-1:ℕ)) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) {k T : ℕ} (hk : k ≤ T) (j : J) : + ((sphereLaw (E := E)).prod (Measure.pi (fun _ : Fin T => stdGaussian E))) + {z | dist z.1.val (y (streamRoute δ 0 k j + ((fun i => z.2 (Fin.castLE hk i)),fun i => ⟪z.1.val,z.2 (Fin.castLE hk i)⟫))) ≤ ε} ≤ + (ENNReal.ofReal ((3:ℝ)*4^Module.finrank ℝ E)*ENNReal.ofReal (ε^b)) * + streamFactor (E := E) (J := J) q ^ ((k+q-1)/q) := by + have hp := (MeasurePreserving.id (sphereLaw (E := E))).prod + (measurePreserving_pi_prefix (stdGaussian E) hk) + have hs : MeasurableSet + {z : (Metric.sphere (0:E) 1) × (Fin k → E) | + dist z.1.val (y (streamRoute δ 0 k j (z.2,fun i => ⟪z.1.val,z.2 i⟫))) ≤ ε} := by + apply measurableSet_le _ measurable_const + exact (measurable_subtype_coe.comp measurable_fst).dist + ((measurable_of_finite y).comp ((measurable_streamRoute hδ 0 k j).comp (by fun_prop))) + apply (le_of_eq (hp.measure_preimage hs.nullMeasurableSet)).trans + exact route_mixed_bound hδ y hε hε1 hb hab hq hqa k j + +namespace Learner +variable {d M T : ℕ} {Ω : Type u} + +lemma terminal_eq_forced_of_index (L : Learner d M T Ω) (s : UnitSphere d) (ω : Ω) + (x : Samples d T) {t : ℕ} (ht : (L.terminal s ω x).1 = t) : + L.terminal s ω x = (t,L.forcedRun s ω x t) := by + rcases L.terminal_forced_witness s ω x with ⟨t',ht',he⟩ + have h : t' = t := (congrArg Prod.fst he).symm.trans ht + subst t' + exact he + +lemma frozen_fixed_success_bound (L : Learner d M T Ω) (ω : Ω) (hd : 3 ≤ d) + (htrans : ∀ t j, AEMeasurable (fun obs => (L.transition t ω j obs).2) (observationReference d)) + {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) {a q : ℕ} {b : ℝ} + (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (d-1:ℕ)) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) {t : ℕ} (ht : t ≤ T) : + ((uniformSphere d).prod (sampleLaw d T)) + {z | (L.terminal z.1 ω z.2).1 = t ∧ angularError z.1 (L.estimate z.1 ω z.2) ≤ ε} ≤ + (ENNReal.ofReal ((3:ℝ)*4^d)*ENNReal.ofReal (ε^b)) * + streamFactor (E := Vector d) (J := State M) q ^ ((t+q-1)/q) := by + classical + let : NeZero d := ⟨by omega⟩ + let δ : ℕ → State M → (Vector d × ℝ) → State M := fun t j => (htrans t j).mk _ + have hδ (t : ℕ) (j : State M) : Measurable (δ t j) := (htrans t j).measurable_mk + let μ := (uniformSphere d).prod (sampleLaw d T) + have hgood : ∀ᵐ z ∂μ, ∀ t j (i : Fin T), + (L.transition t ω j (z.2 i,⟪z.1.val,z.2 i⟫)).2 = δ t j (z.2 i,⟪z.1.val,z.2 i⟫) := by + simp only [ae_all_iff] + intro t j i + exact (sphere_sample_observation_quasi (by simpa using hd) i).ae (htrans t j).ae_eq_mk + let S := {z : UnitSphere d × Samples d T | + dist z.1.val (L.output t ω (streamRoute δ 0 t (L.initialChoice ω).2 + ((fun i => z.2 (Fin.castLE ht i)),fun i => ⟪z.1.val,z.2 (Fin.castLE ht i)⟫))).val ≤ ε} + have hmono : {z : UnitSphere d × Samples d T | + (L.terminal z.1 ω z.2).1 = t ∧ angularError z.1 (L.estimate z.1 ω z.2) ≤ ε} ≤ᵐ[μ] S := by + filter_upwards [hgood] with z hz + rintro ⟨hzt,hs⟩ + have he := L.terminal_eq_forced_of_index z.1 ω z.2 hzt + have hf : L.forcedRun z.1 ω z.2 t = streamRoute δ 0 t (L.initialChoice ω).2 + ((fun i => z.2 (Fin.castLE ht i)),fun i => ⟪z.1.val,z.2 (Fin.castLE ht i)⟫) := by + rw [L.forcedRun_eq_route z.1 ω z.2 ht] + exact streamRoute_congr _ _ 0 t _ _ _ (fun n j i => hz n j (Fin.castLE ht i)) + have hc : dist z.1.val (L.estimate z.1 ω z.2).val ≤ ε := by + apply le_trans _ hs + simpa only [angularError,dist_comm] using chord_le_arccos (L.estimate z.1 ω z.2) z.1 + change dist z.1.val _ ≤ ε + simpa only [estimate,he,hf] using hc + apply (measure_mono_ae hmono).trans + simpa only [S,μ,uniformSphere,sphereLaw,sampleLaw,finrank_euclideanSpace_fin] using + prefix_route_mixed_bound hδ (fun j => (L.output t ω j).val) hε hε1 hb (by simpa using hab) + hq hqa ht (L.initialChoice ω).2 + +lemma streaming_fixed_success_bound [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) + (hstop : AEMeasurable (fun z : UnitSphere d × (Ω × Samples d T) => + (L.terminal z.1 z.2.1 z.2.2).1) ((uniformSphere d).prod (ρ.prod (sampleLaw d T)))) + (hd : 3 ≤ d) {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) {a q : ℕ} {b : ℝ} + (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (d-1:ℕ)) + (hq : 2 ≤ q) (hqa : 2*q ≤ a) {t : ℕ} (ht : t ≤ T) : + L.uniformFixedSuccess ρ ε t ≤ + (ENNReal.ofReal ((3:ℝ)*4^d)*ENNReal.ofReal (ε^b)) * + streamFactor (E := Vector d) (J := State M) q ^ ((t+q-1)/q) := by + let : NeZero d := ⟨by omega⟩ + let : SigmaFinite (observationReference d) := by unfold observationReference; infer_instance + have hω : ∀ᵐ ω ∂ρ, ∀ t j, + AEMeasurable (fun obs => (L.transition t ω j obs).2) (observationReference d) := by + simp only [ae_all_iff] + intro t j + filter_upwards [ae_fiber_aemeasurable (hL.transition t j).prod_swap] with ω hω + exact measurable_snd.comp_aemeasurable hω + have hp := ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := ρ))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) ρ) + let S := {z : UnitSphere d × (Ω × Samples d T) | + (L.terminal z.1 z.2.1 z.2.2).1 = t ∧ angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + have hS : NullMeasurableSet S ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := + (nullMeasurableSet_eq_fun hstop aemeasurable_const).inter (L.angularSuccess_nullMeasurable ρ ε hL) + have he := hp.measure_preimage hS + have hbound := prod_null_set_bound (hS.preimage hp.quasiMeasurePreserving) + (c := (ENNReal.ofReal ((3:ℝ)*4^d)*ENNReal.ofReal (ε^b)) * + streamFactor (E := Vector d) (J := State M) q ^ ((t+q-1)/q)) + (by + filter_upwards [hω] with ω hω + exact L.frozen_fixed_success_bound ω hd hω hε hε1 hb hab hq hqa ht) + simpa only [he,measure_univ,mul_one,S,uniformFixedSuccess] using hbound + +end Learner +end + +lemma streamFactor_ofReal {E : Type*} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + [FiniteDimensional ℝ E] {J : Type*} [Fintype J] (q : ℕ) : + streamFactor (E := E) (J := J) q = ENNReal.ofReal + ((32768:ℝ)^Module.finrank ℝ E*(Fintype.card J:ℝ)^(1/(q:ℝ))) := by + unfold streamFactor + rw [ENNReal.ofReal_mul (by positivity),ENNReal.ofReal_pow (by norm_num), ENNReal.ofReal_ofNat, + ← ENNReal.ofReal_rpow_of_nonneg (Nat.cast_nonneg _) (by positivity : 0 ≤ 1/(q:ℝ)), + ENNReal.ofReal_natCast] + +lemma three_mul_four_pow_le (d : ℕ) (hd : 1 ≤ d) : (3:ℝ)*4^d ≤ (32768:ℝ)^d := by + have hp : (3:ℝ)^1 ≤ 3^d := pow_le_pow_right₀ (by norm_num) hd + calc + (3:ℝ)*4^d ≤ 3^d*4^d := mul_le_mul_of_nonneg_right (by simpa using hp) (by positivity) + _ = 12^d := by rw [← mul_pow]; norm_num + _ ≤ _ := pow_le_pow_left₀ (by norm_num) (by norm_num) d + +namespace Learner + +section +universe u + +theorem cap_fixed_stop : + ∃ C : ℝ, 0 < C ∧ ∀ d M T : ℕ, 32 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Learner d M T Ω, L.Admissible ρ → + AEMeasurable (fun z : UnitSphere d × (Ω × Samples d T) => + (L.terminal z.1 z.2.1 z.2.2).1) ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) → + ∀ t : ℕ, t ≤ T → + let k := d/16 + let α : ℝ := ((d:ℝ)-1)/2 + L.uniformFixedSuccess ρ ε t ≤ ENNReal.ofReal + (Real.exp (C*d)*(ε/2)^α*(Real.exp (C*d)*(2:ℝ)^((M:ℝ)/k))^((t+k-1)/k)) := by + refine ⟨Real.log 65536,Real.log_pos (by norm_num),?_⟩ + intro d M T hd ε hε hε10 Ω _ ρ hρ L hL hstop t ht k α + let : IsProbabilityMeasure ρ := hρ + let a := (d-1)/2 + have hk : 2 ≤ k := by dsimp [k]; omega + have hka : 2*k ≤ a := by dsimp [k,a]; omega + have hα : 0 ≤ α := by + dsimp [α] + have hdR : (32:ℝ) ≤ d := by exact_mod_cast hd + linarith + have hαd : α ≤ (d:ℝ) := by + dsimp [α] + have := Nat.cast_nonneg (α := ℝ) d + linarith + have hab : (a:ℝ)+α ≤ (d-1:ℕ) := by + have hh : (2:ℝ)*a ≤ (d-1:ℕ) := by exact_mod_cast (show 2*a ≤ d-1 by dsimp [a]; omega) + rw [Nat.cast_sub (by omega : 1 ≤ d),Nat.cast_one] at hh ⊢ + dsimp [α]; linarith + have hb := L.streaming_fixed_success_bound ρ hL hstop (by omega) hε (by linarith) + hα hab hk hka ht + have he : Real.exp (Real.log 65536*(d:ℝ)) = (65536:ℝ)^d := by + rw [mul_comm,Real.exp_nat_mul,Real.exp_log (by norm_num)] + rw [he] + rw [streamFactor_ofReal,finrank_euclideanSpace_fin,Fintype.card_fin, + Nat.cast_pow,Nat.cast_ofNat] at hb + have hroot : ((2:ℝ)^M)^(1/(k:ℝ)) = (2:ℝ)^((M:ℝ)/k) := by + rw [← Real.rpow_natCast,← Real.rpow_mul (by norm_num)] + congr 1; ring + rw [hroot, ← ENNReal.ofReal_pow (by positivity : 0 ≤ (32768:ℝ)^d*(2:ℝ)^((M:ℝ)/k)), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ (3:ℝ)*4^d), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ (3:ℝ)*4^d*ε^α)] at hb + apply hb.trans + apply ENNReal.ofReal_le_ofReal + have hbase : (3:ℝ)*4^d*ε^α ≤ (65536:ℝ)^d*(ε/2)^α := by + have heps : ε^α = 2^α*(ε/2)^α := by + rw [← Real.mul_rpow (by norm_num : (0:ℝ) ≤ 2) (by positivity : 0 ≤ ε/2)] + congr 1; ring + rw [heps,← mul_assoc] + apply mul_le_mul_of_nonneg_right _ (by positivity) + calc + (3:ℝ)*4^d*2^α ≤ (32768:ℝ)^d*(2:ℝ)^d := by + apply mul_le_mul (three_mul_four_pow_le d (by omega)) _ (by positivity) (by positivity) + rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_le (by norm_num) hαd + _ = 65536^d := by rw [← mul_pow]; norm_num + apply mul_le_mul hbase _ (by positivity) (by positivity) + exact pow_le_pow_left₀ (by positivity) + (mul_le_mul_of_nonneg_right (pow_le_pow_left₀ (by norm_num) (by norm_num) d) (by positivity)) _ + +end + +universe u +variable {d M T : ℕ} {Ω : Type u} + +lemma frozen_success_bound_local (L : Learner d M T Ω) (ω : Ω) (hd : 3 ≤ d) + (htrans : ∀ t j, AEMeasurable (L.transition t ω j) (observationReference d)) + {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) {a q : ℕ} {b : ℝ} + (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (d-1:ℕ)) (hq : 2 ≤ q) (hqa : 2*q ≤ a) : + ((uniformSphere d).prod (sampleLaw d T)) + {z | angularError z.1 (L.estimate z.1 ω z.2) ≤ ε} ≤ + (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^b)) * + streamFactor (E := Vector d) (J := TaggedState M q) q ^ ((T+q-1)/q) := by + classical + let : NeZero d := ⟨by omega⟩ + let τ : ℕ → State M → (Vector d × ℝ) → Bool × State M := fun t j => (htrans t j).mk _ + have hτ (t : ℕ) (j : State M) : Measurable (τ t j) := (htrans t j).measurable_mk + let μ := (uniformSphere d).prod (sampleLaw d T) + have hgood : ∀ᵐ z ∂μ, ∀ t j (i : Fin T), + L.transition t ω j (z.2 i,⟪z.1.val,z.2 i⟫) = τ t j (z.2 i,⟪z.1.val,z.2 i⟫) := by + simp only [ae_all_iff] + intro t j i + exact (sphere_sample_observation_quasi (by simpa using hd) i).ae (htrans t j).ae_eq_mk + let S := {z : UnitSphere d × Samples d T | dist z.1.val + (L.taggedOutput ω (streamRoute (taggedStep (T := T) τ) 0 T (taggedStart (L.initialChoice ω)) + (z.2,fun i => ⟪z.1.val,z.2 i⟫))).val ≤ ε} + have hmono : {z : UnitSphere d × Samples d T | angularError z.1 (L.estimate z.1 ω z.2) ≤ ε} + ≤ᵐ[μ] S := by + filter_upwards [hgood] with z hz + intro hs + have he := streamRoute_congr (taggedStep (T := T) (fun t j => L.transition t ω j)) + (taggedStep (T := T) τ) 0 T (taggedStart (L.initialChoice ω)) z.2 + (fun i => ⟪z.1.val,z.2 i⟫) (fun t j i => taggedStep_congr t j _ (fun a => hz t a i)) + have hc : dist z.1.val (L.estimate z.1 ω z.2).val ≤ ε := by + apply le_trans _ hs + simpa only [angularError,dist_comm] using chord_le_arccos (L.estimate z.1 ω z.2) z.1 + change dist z.1.val _ ≤ ε + rw [L.estimate_eq_taggedRoute,he] at hc + exact hc + apply (measure_mono_ae hmono).trans + have hy (a : TaggedState M T) : (L.taggedOutput ω a).val = + (match a with | .inl a => (L.output T ω a).val | .inr (t,a) => (L.output t ω a).val) := by + cases a <;> rfl + have hh := stopped_route_mixed_bound hτ (fun t j => (L.output t ω j).val) hε hε1 hb hab hq hqa + (T := T) (taggedStart (L.initialChoice ω)) + have hset : S = {z : UnitSphere d × Samples d T | dist z.1.val + (match streamRoute (taggedStep (T := T) τ) 0 T (taggedStart (L.initialChoice ω)) + (z.2,fun i => ⟪z.1.val,z.2 i⟫) with + | .inl a => (L.output T ω a).val | .inr (t,a) => (L.output t ω a).val) ≤ ε} := by + ext z + change (dist z.1.val (L.taggedOutput ω _).val ≤ ε) ↔ _ + rw [hy] + rfl + rw [hset] + exact hh + +lemma streaming_success_bound_local [MeasurableSpace Ω] + (L : Learner d M T Ω) (ρ : Measure Ω) [IsProbabilityMeasure ρ] + (hL : L.Admissible ρ) (hd : 3 ≤ d) {ε : ℝ} (hε : 0 < ε) (hε1 : ε ≤ 1) + {a q : ℕ} {b : ℝ} (hb : 0 ≤ b) (hab : (a:ℝ)+b ≤ (d-1:ℕ)) (hq : 2 ≤ q) (hqa : 2*q ≤ a) : + L.uniformSuccess ρ ε ≤ + (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^b)) * + streamFactor (E := Vector d) (J := TaggedState M q) q ^ ((T+q-1)/q) := by + let : NeZero d := ⟨by omega⟩ + let : SigmaFinite (observationReference d) := by unfold observationReference; infer_instance + have hω : ∀ᵐ ω ∂ρ, ∀ t j, + AEMeasurable (L.transition t ω j) (observationReference d) := by + simp only [ae_all_iff] + intro t j + exact ae_fiber_aemeasurable (hL.transition t j).prod_swap + have hp := ((MeasurePreserving.id (uniformSphere d)).prod + (Measure.measurePreserving_swap (μ := sampleLaw d T) (ν := ρ))).comp + (measurePreserving_prodAssoc (uniformSphere d) (sampleLaw d T) ρ) + let S := {z : UnitSphere d × (Ω × Samples d T) | + angularError z.1 (L.estimate z.1 z.2.1 z.2.2) ≤ ε} + have hS : NullMeasurableSet S ((uniformSphere d).prod (ρ.prod (sampleLaw d T))) := + L.angularSuccess_nullMeasurable ρ ε hL + have he := hp.measure_preimage hS + have hb := prod_null_set_bound (hS.preimage hp.quasiMeasurePreserving) + (c := (ENNReal.ofReal ((3 : ℝ)*4^d) * ENNReal.ofReal (ε^b)) * + streamFactor (E := Vector d) (J := TaggedState M q) q ^ ((T+q-1)/q)) + (by + filter_upwards [hω] with ω hω + exact L.frozen_success_bound_local ω hd hω hε hε1 hb hab hq hqa) + simpa only [he,measure_univ,mul_one,S,uniformSuccess] using hb + +theorem haar_success : + ∃ C : ℝ, 1 ≤ C ∧ ∀ d M T : ℕ, 16 ≤ d → ∀ ε : ℝ, + 0 < ε → ε ≤ 1/10 → + ∀ (Ω : Type u) [MeasurableSpace Ω] (ρ : Measure Ω), IsProbabilityMeasure ρ → + ∀ L : Learner d M T Ω, L.Admissible ρ → + let k := d/4 + let Nstar : ℝ := ((k:ℝ)+2)*2^M + L.uniformSuccess ρ ε ≤ ENNReal.ofReal + (C^d*ε^k*(C^d*Nstar^(1/(k:ℝ)))^((T+k-1)/k)) := by + refine ⟨32768,by norm_num,?_⟩ + intro d M T hd ε hε hε10 Ω _ ρ hρ L hL k Nstar + let : IsProbabilityMeasure ρ := hρ + let a := d-1-k + have hk : 2 ≤ k := by dsimp [k]; omega + have hka : 2*k ≤ a := by dsimp [k,a]; omega + have hab : (a:ℝ)+(k:ℝ) ≤ (d-1:ℕ) := by + exact_mod_cast (show a+k ≤ d-1 by dsimp [a,k]; omega) + have hb := L.streaming_success_bound_local ρ hL (by omega) hε (by linarith) + (Nat.cast_nonneg k) hab hk hka + have hcard : (Fintype.card (TaggedState M k):ℝ) = Nstar := by + rw [card_taggedState]; simp [Nstar,Nat.cast_mul,Nat.cast_add,Nat.cast_pow] + rw [Real.rpow_natCast,streamFactor_ofReal,finrank_euclideanSpace_fin,hcard, + ← ENNReal.ofReal_pow (by positivity : 0 ≤ (32768:ℝ)^d*Nstar^(1/(k:ℝ))), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ (3:ℝ)*4^d), + ← ENNReal.ofReal_mul (by positivity : 0 ≤ (3:ℝ)*4^d*ε^k)] at hb + apply hb.trans + apply ENNReal.ofReal_le_ofReal + exact mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (three_mul_four_pow_le d (by omega)) (by positivity)) (by positivity) + +end Learner +end NoiselessRegression + +end + +end OAI diff --git a/lean/OAI/Probability/ProjectionMoments/WeightedCover.lean b/lean/OAI/Probability/ProjectionMoments/WeightedCover.lean new file mode 100644 index 0000000000000000000000000000000000000000..3c1b7641fe47c31448bcbb54a612f40427118f17 --- /dev/null +++ b/lean/OAI/Probability/ProjectionMoments/WeightedCover.lean @@ -0,0 +1,386 @@ +import OAI.Probability.ProjectionMoments.CapDuality + +namespace OAI + +noncomputable section + +open scoped Topology BigOperators Pointwise +open MeasureTheory Set Filter +open scoped ENNReal NNReal Topology BigOperators +namespace ProjectionMoments +namespace Weighted + +section +variable {ι : Type*} + +def budget (b : ι → ℝ) (K : ℝ) : Set (ι → ℝ) := + {a | (∀ i, 0 ≤ a i) ∧ ∀ s : Finset ι, ∑ i ∈ s, a i*b i ≤ K} + +lemma budget_closed (b : ι → ℝ) (K : ℝ) : IsClosed (budget b K) := by + have he : budget b K = (⋂ i, {a | 0 ≤ a i}) ∩ + (⋂ s : Finset ι, {a | ∑ i ∈ s, a i*b i ≤ K}) := by ext a; simp [budget] + rw [he] + exact (isClosed_iInter (fun i => isClosed_le continuous_const (continuous_apply i))).inter + (isClosed_iInter (fun s => isClosed_le (by fun_prop) continuous_const)) + +lemma budget_mem_single {b : ι → ℝ} {K : ℝ} {a : ι → ℝ} (ha : a ∈ budget b K) (i : ι) : + a i * b i ≤ K := by + classical + simpa using ha.2 {i} + +lemma budget_compact {b : ι → ℝ} (hb : ∀ i, 0 < b i) (K : ℝ) : IsCompact (budget b K) := by + apply (isCompact_pi_infinite (fun i => isCompact_Icc (a := (0:ℝ)) (b := K/b i))).of_isClosed_subset + (budget_closed b K) + intro a ha + exact fun i => ⟨ha.1 i, (le_div_iff₀ (hb i)).mpr (budget_mem_single ha i)⟩ + +lemma budget_convex (b : ι → ℝ) (K : ℝ) : Convex ℝ (budget b K) := by + intro a ha a' ha' t u ht hu htu + constructor + · intro i + exact add_nonneg (mul_nonneg ht (ha.1 i)) (mul_nonneg hu (ha'.1 i)) + · intro s + have he : (∑ i ∈ s, (t • a + u • a') i * b i) = + t*(∑ i ∈ s, a i*b i) + u*(∑ i ∈ s, a' i*b i) := by + simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul, add_mul, Finset.sum_add_distrib, + mul_assoc, ← Finset.mul_sum] + rw [he] + calc + _ ≤ t*K+u*K := add_le_add (mul_le_mul_of_nonneg_left (ha.2 s) ht) + (mul_le_mul_of_nonneg_left (ha'.2 s) hu) + _ = K := by rw [← add_mul, htu, one_mul] + +lemma cost_summable {b : ι → ℝ} (hb : ∀ i, 0 ≤ b i) {K : ℝ} {a : ι → ℝ} + (ha : a ∈ budget b K) : Summable (fun i => a i*b i) := + summable_of_sum_le (fun i => mul_nonneg (ha.1 i) (hb i)) ha.2 + +lemma cost_le {b : ι → ℝ} (hb : ∀ i, 0 ≤ b i) {K : ℝ} {a : ι → ℝ} + (ha : a ∈ budget b K) : (∑' i, a i*b i) ≤ K := + (cost_summable hb ha).tsum_le_of_sum_le ha.2 + +lemma eval_summable {b : ι → ℝ} (hb : ∀ i, 1 ≤ b i) {K : ℝ} {a v : ι → ℝ} + (ha : a ∈ budget b K) (hv : ∀ i, v i ∈ Icc (0:ℝ) 1) : Summable (fun i => a i*v i) := by + apply Summable.of_nonneg_of_le (fun i => mul_nonneg (ha.1 i) (hv i).1) + (fun i => mul_le_mul_of_nonneg_left ((hv i).2.trans (hb i)) (ha.1 i)) + (cost_summable (fun i => (zero_le_one.trans (hb i))) ha) + +lemma eval_le {b : ι → ℝ} (hb : ∀ i, 1 ≤ b i) {K : ℝ} {a v : ι → ℝ} + (ha : a ∈ budget b K) (hv : ∀ i, v i ∈ Icc (0:ℝ) 1) : (∑' i, a i*v i) ≤ K := by + exact ((eval_summable hb ha hv).tsum_le_tsum + (fun i => mul_le_mul_of_nonneg_left ((hv i).2.trans (hb i)) (ha.1 i)) + (cost_summable (fun i => (zero_le_one.trans (hb i))) ha)).trans (cost_le (fun i => (zero_le_one.trans (hb i))) ha) + +lemma eval_tail {b : ι → ℝ} (hb : ∀ i, 1 ≤ b i) {K : ℝ} {a v : ι → ℝ} + (ha : a ∈ budget b K) (hv : ∀ i, v i ∈ Icc (0:ℝ) 1) + (s : Finset ι) {R : ℝ} (hR : 0 < R) (hs : ∀ i ∉ s, R ≤ b i) : + 0 ≤ (∑' i, a i*v i) - ∑ i ∈ s, a i*v i ∧ + (∑' i, a i*v i) - ∑ i ∈ s, a i*v i ≤ K/R := by + classical + have hc := cost_summable (fun i => zero_le_one.trans (hb i)) ha + have he := eval_summable hb ha hv + have hid := he.sum_add_tsum_subtype_compl s + have hnon : 0 ≤ ∑' i : {i // i ∉ s}, a i*v i := + tsum_nonneg (fun i => mul_nonneg (ha.1 i) (hv i).1) + have hcost : (∑' i : {i // i ∉ s}, a i*b i) ≤ K := by + have heq := hc.sum_add_tsum_subtype_compl s + have hsum : 0 ≤ ∑ i ∈ s, a i*b i := + Finset.sum_nonneg (fun i hi => mul_nonneg (ha.1 i) (zero_le_one.trans (hb i))) + have htot := cost_le (fun i => zero_le_one.trans (hb i)) ha + linarith + have hbound : (∑' i : {i // i ∉ s}, a i*v i) ≤ K/R := by + calc + _ ≤ ∑' i : {i // i ∉ s}, (a i*b i)/R := by + apply (he.subtype _).tsum_le_tsum _ ((hc.subtype _).div_const R) + intro i + apply (le_div_iff₀ hR).mpr + calc + a i*v i*R ≤ a i*1*R := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left (hv i).2 (ha.1 i)) hR.le + _ ≤ a i*b i := by simpa using mul_le_mul_of_nonneg_left (hs i i.2) (ha.1 i) + _ = (∑' i : {i // i ∉ s}, a i*b i)/R := tsum_div_const + _ ≤ K/R := div_le_div_of_nonneg_right hcost hR.le + constructor <;> linarith + +lemma eval_continuousOn {b : ι → ℝ} (hb : ∀ i, 1 ≤ b i) + (hproper : ∀ R : ℝ, {i | b i ≤ R}.Finite) {K : ℝ} (hK : 0 ≤ K) + {v : ι → ℝ} (hv : ∀ i, v i ∈ Icc (0:ℝ) 1) : + ContinuousOn (fun a : ι → ℝ => ∑' i, a i*v i) (budget b K) := by + classical + have hconv : TendstoUniformlyOn (fun s : Finset ι => fun a : ι → ℝ => ∑ i ∈ s, a i*v i) + (fun a => ∑' i, a i*v i) atTop (budget b K) := by + rw [Metric.tendstoUniformlyOn_iff] + intro ε hε + let R := (K+1)/ε + have hR : 0 < R := by dsimp [R]; positivity + let s := (hproper R).toFinset + filter_upwards [eventually_ge_atTop s] with t ht + intro a ha + have hsmall : ∀ i ∉ t, R ≤ b i := by + intro i hi + apply le_of_lt + by_contra! hh + exact hi (ht (by simpa [s] using hh)) + have hh := eval_tail hb ha hv t hR hsmall + rw [Real.dist_eq, abs_of_nonneg hh.1] + apply hh.2.trans_lt + apply (div_lt_iff₀ hR).mpr + have he : ε*R = K+1 := by dsimp [R]; field_simp + linarith + apply hconv.continuousOn + exact Filter.Eventually.frequently (Filter.Eventually.of_forall (fun _ => (by fun_prop : Continuous _).continuousOn)) + +lemma zero_mem_budget {b : ι → ℝ} {K : ℝ} (hK : 0 ≤ K) : (0 : ι → ℝ) ∈ budget b K := by + constructor + · simp + · simpa using (fun _ : Finset ι => hK) + +lemma single_mem_budget [DecidableEq ι] {b : ι → ℝ} (hb : ∀ i, 0 < b i) {K : ℝ} (hK : 0 ≤ K) (i : ι) : + (Pi.single i (K/b i) : ι → ℝ) ∈ budget b K := by + classical + constructor + · intro j + simp only [Pi.single_apply] + split_ifs + · exact div_nonneg hK (hb i).le + · exact le_rfl + · intro s + have he : (fun j => (Pi.single i (K/b i) : ι → ℝ) j * b j) = (Pi.single i K : ι → ℝ) := by + ext j + by_cases hj : j = i + · subst j; simp [div_mul_cancel₀ K (hb i).ne'] + · simp [hj] + rw [he] + simp only [Pi.single_apply] + rw [Finset.sum_ite_eq'] + split_ifs + · exact le_rfl + · exact hK + +lemma eval_single [DecidableEq ι] {b : ι → ℝ} (K : ℝ) (i : ι) (v : ι → ℝ) : + (∑' j, (Pi.single i (K/b i) : ι → ℝ) j * v j) = (K/b i)*v i := by + classical + rw [tsum_eq_single i (by intro j hj; simp [hj])] + simp + +lemma eval_smul_add {b : ι → ℝ} (hb : ∀ i, 1 ≤ b i) {K : ℝ} {a a' v : ι → ℝ} + (ha : a ∈ budget b K) (ha' : a' ∈ budget b K) (hv : ∀ i, v i ∈ Icc (0:ℝ) 1) + (t u : ℝ) : + (∑' i, (t • a + u • a') i * v i) = t*(∑' i, a i*v i)+u*(∑' i, a' i*v i) := by + have he : (fun i => (t • a + u • a') i * v i) = + fun i => t*(a i*v i)+u*(a' i*v i) := by ext i; simp only [Pi.add_apply, Pi.smul_apply, smul_eq_mul]; ring + rw [he, ((eval_summable hb ha hv).mul_left t).tsum_add ((eval_summable hb ha' hv).mul_left u), + tsum_mul_left, tsum_mul_left] + +lemma finite_dual_domination {J : Type*} [Fintype J] {b : ι → ℝ} + (hb : ∀ i, 1 ≤ b i) (hproper : ∀ R : ℝ, {i | b i ≤ R}.Finite) + {K : ℝ} (hK : 0 < K) (v : J → ι → ℝ) (hv : ∀ j i, v j i ∈ Icc (0:ℝ) 1) + (y : J → ℝ) + (hdual : ∀ c : J → ℝ, (∀ j, 0 ≤ c j) → + (∀ i, ∑ j, c j*v j i ≤ b i) → ∑ j, c j*y j ≤ K) : + ∃ a ∈ budget b K, ∀ j, y j ≤ ∑' i, a i*v j i := by + classical + let F : (ι → ℝ) → (J → ℝ) := fun a j => ∑' i, a i*v j i + let C := F '' budget b K + let D := C + Set.Iic (0 : J → ℝ) + have hCc : IsCompact C := (budget_compact (fun i => zero_lt_one.trans_le (hb i)) K).image_of_continuousOn + (continuousOn_pi.mpr (fun j => eval_continuousOn hb hproper hK.le (hv j))) + have hCv : Convex ℝ C := by + rintro _ ⟨a,ha,rfl⟩ _ ⟨a',ha',rfl⟩ t u ht hu htu + refine ⟨t • a + u • a', budget_convex b K ha ha' ht hu htu, ?_⟩ + ext j + exact eval_smul_add hb ha ha' (hv j) t u + have hDc : IsClosed D := isClosed_Iic.add_left_of_isCompact hCc + have hDv : Convex ℝ D := hCv.add (convex_Iic (0 : J → ℝ)) + have h00 : (0 : J → ℝ) ∈ C := ⟨0,zero_mem_budget hK.le,by ext j; simp [F]⟩ + have hneg : ∀ w : J → ℝ, w ≤ 0 → w ∈ D := by + intro w hw + exact ⟨0,h00,w,hw,zero_add _⟩ + have hymem : y ∈ D := by + by_contra hy + obtain ⟨f,U,hf,hUy⟩ := geometric_hahn_banach_closed_point hDv hDc hy + have hU : 0 < U := by simpa using hf 0 (hneg 0 le_rfl) + let c : J → ℝ := fun j => f (Pi.single j 1) + have hfe (x : J → ℝ) : f x = ∑ j, c j*x j := by + have he : x = ∑ j, x j • Pi.single j (1:ℝ) := by + ext i + simp [Finset.sum_apply, Pi.single_apply] + conv_lhs => rw [he, map_sum] + apply Finset.sum_congr rfl + intro j hj + rw [map_smul] + change x j * c j = c j * x j + ring + have hc : ∀ j, 0 ≤ c j := by + intro j + by_contra! hj + let t := (U+1)/(-c j) + have ht : 0 < t := div_pos (by linarith) (neg_pos.mpr hj) + have hw : -t • Pi.single j (1:ℝ) ≤ (0 : J → ℝ) := by + intro i + simp only [Pi.smul_apply, smul_eq_mul, Pi.zero_apply, Pi.single_apply] + split_ifs <;> nlinarith + have hh := hf _ (hneg _ hw) + rw [map_smul] at hh + change -t*c j < U at hh + have he : -t*c j = U+1 := by dsimp [t]; field_simp [hj.ne] + linarith + have hsingle (i : ι) : (K/b i)*(∑ j, c j*v j i) < U := by + have ha := single_mem_budget (fun i => zero_lt_one.trans_le (hb i)) hK.le i + have hmem : F ((Pi.single i (K/b i) : ι → ℝ)) ∈ D := + ⟨F ((Pi.single i (K/b i) : ι → ℝ)),⟨_,ha,rfl⟩,0,by simp,add_zero _⟩ + have hh := hf _ hmem + rw [hfe] at hh + simp only [F, eval_single] at hh + convert hh using 1 + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j hj + ring + have htest : ∀ i, ∑ j, (K/U*c j)*v j i ≤ b i := by + intro i + have hh := hsingle i + rw [div_mul_eq_mul_div, div_lt_iff₀ (zero_lt_one.trans_le (hb i))] at hh + have he : (∑ j, (K/U*c j)*v j i) = (K/U)*(∑ j, c j*v j i) := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro j hj; ring + rw [he, div_mul_eq_mul_div, div_le_iff₀ hU] + nlinarith + have hres := hdual (fun j => K/U*c j) (fun j => mul_nonneg (div_nonneg hK.le hU.le) (hc j)) htest + have he : (∑ j, K/U*c j*y j) = (K/U)*f y := by + rw [hfe, Finset.mul_sum]; apply Finset.sum_congr rfl; intro j hj; ring + rw [he, div_mul_eq_mul_div, div_le_iff₀ hU] at hres + nlinarith + obtain ⟨z,⟨a,ha,rfl⟩,w,hw,he⟩ := hymem + refine ⟨a,ha,?_⟩ + intro j + have hj := congrFun he j + have hh := hw j + change F a j + w j = y j at hj + change w j ≤ 0 at hh + dsimp [F] at hj + linarith + +theorem dual_domination {J : Type*} {b : ι → ℝ} + (hb : ∀ i, 1 ≤ b i) (hproper : ∀ R : ℝ, {i | b i ≤ R}.Finite) + {K : ℝ} (hK : 0 < K) (v : J → ι → ℝ) (hv : ∀ j i, v j i ∈ Icc (0:ℝ) 1) + (y : J → ℝ) + (hdual : ∀ s : Finset J, ∀ c : s → ℝ, (∀ j, 0 ≤ c j) → + (∀ i, ∑ j, c j*v j i ≤ b i) → ∑ j, c j*y j ≤ K) : + ∃ a ∈ budget b K, ∀ j, y j ≤ ∑' i, a i*v j i := by + classical + let B := budget b K + let : CompactSpace B := isCompact_iff_compactSpace.mp (budget_compact (fun i => zero_lt_one.trans_le (hb i)) K) + let t : J → Set B := fun j => {a | y j ≤ ∑' i, a.val i*v j i} + have hclosed : ∀ j, IsClosed (t j) := by + intro j + exact isClosed_le continuous_const (eval_continuousOn hb hproper hK.le (hv j)).domRestrict + have hfinite : ∀ s : Finset J, (Set.univ ∩ ⋂ j ∈ s, t j).Nonempty := by + intro s + obtain ⟨a,ha,haj⟩ := finite_dual_domination hb hproper hK + (fun j : s => v j) (fun j => hv j) (fun j : s => y j) (hdual s) + refine ⟨⟨a,ha⟩,Set.mem_univ _,?_⟩ + simp only [Set.mem_iInter] + intro j hj + exact haj ⟨j,hj⟩ + obtain ⟨a,_,ha⟩ := isCompact_univ.inter_iInter_nonempty t hclosed hfinite + exact ⟨a.val,a.property,fun j => Set.mem_iInter.mp ha j⟩ + +end + +variable {Ω ι : Type*} [MeasurableSpace Ω] + +lemma lintegral_finite_test {J : Type*} [Fintype J] (μ : Measure Ω) [IsFiniteMeasure μ] + (S : J → Set Ω) (hS : ∀ j, MeasurableSet (S j)) (c : J → ℝ) (hc : ∀ j, 0 ≤ c j) : + (∫⁻ x, ∑ j, ENNReal.ofReal (c j) * (S j).indicator (fun _ => (1 : ℝ≥0∞)) x ∂μ) = + ENNReal.ofReal (∑ j, c j * μ.real (S j)) := by + rw [lintegral_finsetSum (f := fun j x => ENNReal.ofReal (c j) * (S j).indicator (fun _ => (1 : ℝ≥0∞)) x) _ (fun j _ => measurable_const.mul (measurable_const.indicator (hS j)))] + simp only [lintegral_const_mul _ (measurable_const.indicator (hS _))] + rw [ENNReal.ofReal_sum_of_nonneg (fun j _ => mul_nonneg (hc j) (measureReal_nonneg))] + apply Finset.sum_congr rfl + intro j hj + rw [ENNReal.ofReal_mul (hc j), measureReal_def, ENNReal.ofReal_toReal (measure_ne_top _ _)] + rw [lintegral_indicator (hS j)] + simp + +theorem measure_domination [Countable ι] (μ : Measure Ω) [IsFiniteMeasure μ] + (P : ι → Measure Ω) [∀ i, IsProbabilityMeasure (P i)] {b : ι → ℝ} + (hb : ∀ i, 1 ≤ b i) (hproper : ∀ R : ℝ, {i | b i ≤ R}.Finite) + {K : ℝ} (hK : 0 < K) + (hdual : ∀ h : Ω → ℝ≥0∞, Measurable h → + (∃ H : ℝ≥0, ∀ x, h x ≤ H) → + (∀ i, ∫⁻ x, h x ∂P i ≤ ENNReal.ofReal (b i)) → + ∫⁻ x, h x ∂μ ≤ ENNReal.ofReal K) : + ∃ a : ι → ℝ, (∀ i, 0 ≤ a i) ∧ Summable (fun i => a i*b i) ∧ (∑' i, a i*b i) ≤ K ∧ + μ ≤ Measure.sum (fun i => ENNReal.ofReal (a i) • P i) := by + classical + let J := {S : Set Ω // MeasurableSet S} + let v : J → ι → ℝ := fun S i => (P i).real S + let y : J → ℝ := fun S => μ.real S + have hv : ∀ S i, v S i ∈ Icc (0:ℝ) 1 := by + intro S i + exact ⟨measureReal_nonneg, measureReal_le_one⟩ + have hd : ∀ s : Finset J, ∀ c : s → ℝ, (∀ j, 0 ≤ c j) → + (∀ i, ∑ j, c j*v j i ≤ b i) → ∑ j, c j*y j ≤ K := by + intro s c hc hci + let h : Ω → ℝ≥0∞ := fun x => ∑ j : s, + ENNReal.ofReal (c j) * (j.val.val).indicator (fun _ => (1:ℝ≥0∞)) x + have hm : Measurable h := by + exact Finset.measurable_sum _ (fun j _ => measurable_const.mul + (measurable_const.indicator j.val.property)) + have hbnd : ∃ H : ℝ≥0, ∀ x, h x ≤ H := by + refine ⟨∑ j : s, (c j).toNNReal, ?_⟩ + intro x + rw [ENNReal.ofNNReal_finsetSum] + change (∑ j : s, ENNReal.ofReal (c j) * (j.val.val).indicator (fun _ => (1:ℝ≥0∞)) x) ≤ _ + apply Finset.sum_le_sum + intro j hj + by_cases hx : x ∈ j.val.val <;> simp [Set.indicator, hx, ENNReal.ofReal] + have he (ν : Measure Ω) [IsFiniteMeasure ν] : (∫⁻ x, h x ∂ν) = + ENNReal.ofReal (∑ j : s, c j*ν.real j.val.val) := + lintegral_finite_test ν (fun j : s => j.val.val) (fun j => j.val.property) c hc + have ht := hdual h hm hbnd (fun i => by rw [he]; exact ENNReal.ofReal_le_ofReal (hci i)) + rw [he, ENNReal.ofReal_le_ofReal_iff hK.le] at ht + exact ht + obtain ⟨a,ha,has⟩ := dual_domination hb hproper hK v hv y hd + refine ⟨a,ha.1,cost_summable (fun i => zero_le_one.trans (hb i)) ha, + cost_le (fun i => zero_le_one.trans (hb i)) ha,?_⟩ + apply Measure.le_iff.mpr + intro S hS + have hs := has ⟨S,hS⟩ + have hsum := eval_summable hb ha (hv ⟨S,hS⟩) + have hc : ∀ i, 0 ≤ a i*(P i).real S := fun i => mul_nonneg (ha.1 i) measureReal_nonneg + have hh := ENNReal.ofReal_le_ofReal hs + change ENNReal.ofReal (μ.real S) ≤ ENNReal.ofReal (∑' i, a i*(P i).real S) at hh + rw [measureReal_def, ENNReal.ofReal_toReal (measure_ne_top _ _), + ENNReal.ofReal_tsum_of_nonneg hc hsum] at hh + rw [Measure.sum_apply _ hS] + convert hh using 1 + congr 1 + funext i + simp only [Measure.smul_apply, smul_eq_mul, ENNReal.ofReal_mul (ha.1 i), + measureReal_def, ENNReal.ofReal_toReal (measure_ne_top _ _)] + +theorem measure_domination_nonneg [Countable ι] (μ : Measure Ω) [IsFiniteMeasure μ] + (P : ι → Measure Ω) [∀ i, IsProbabilityMeasure (P i)] {b : ι → ℝ} + (hb : ∀ i, 1 ≤ b i) (hproper : ∀ R : ℝ, {i | b i ≤ R}.Finite) + {K : ℝ} (hK : 0 ≤ K) + (hdual : ∀ h : Ω → ℝ≥0∞, Measurable h → + (∃ H : ℝ≥0, ∀ x, h x ≤ H) → + (∀ i, ∫⁻ x, h x ∂P i ≤ ENNReal.ofReal (b i)) → + ∫⁻ x, h x ∂μ ≤ ENNReal.ofReal K) : + ∃ a : ι → ℝ, (∀ i, 0 ≤ a i) ∧ Summable (fun i => a i*b i) ∧ + (∑' i, a i*b i) ≤ K ∧ μ ≤ Measure.sum (fun i => ENNReal.ofReal (a i) • P i) := by + rcases eq_or_lt_of_le hK with hK0 | hKpos + · subst K + have hm := hdual (fun _ => 1) measurable_const ⟨1,fun _ => le_rfl⟩ + (fun i => by simp only [lintegral_const,measure_univ,mul_one]; exact ENNReal.one_le_ofReal.mpr (hb i)) + simp only [lintegral_const,one_mul,ENNReal.ofReal_zero,nonpos_iff_eq_zero] at hm + have hμ : μ = 0 := Measure.measure_univ_eq_zero.mp hm + refine ⟨fun _ => 0,fun _ => le_rfl,?_,?_,?_⟩ <;> simp [hμ] + · exact measure_domination μ P hb hproper hKpos hdual + +end Weighted +end ProjectionMoments + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/BadRemoval.lean b/lean/OAI/Probability/RadialTransition/BadRemoval.lean new file mode 100644 index 0000000000000000000000000000000000000000..63c0230641d8b716a6a4ba74cec23627c2f139ca --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/BadRemoval.lean @@ -0,0 +1,77 @@ +import OAI.Probability.RadialTransition.FreeClusterCover + +namespace OAI + +universe uIndex + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition +attribute [local instance] Classical.propDecidable + +def badLabels {ι : Type uIndex} [Fintype ι] (t : ℝ) (x : ι → Position) : Finset ι := + Finset.univ.filter (fun i => ∃ j, i ≠ j ∧ dist (x i) (x j) < 1 ∧ + ¬ (microLength t ≤ dist (x i) (x j) ∧ dist (x i) (x j) ≤ (1+(1:ℝ)/1000)*microLength t)) + +lemma after_removal_free {ι : Type uIndex} [Fintype ι] (t : ℝ) (x : ι → Position) : + CoreFree t (fun i : {i // i ∉ badLabels t x} => x i) := by + intro i j hij hd + by_contra hs + apply i.property + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, j.val, fun he => hij (Subtype.ext he), hd, hs⟩ + +lemma badLabels_energy {ι : Type uIndex} [Fintype ι] {t : ℝ} (ht : 0 ≤ t) (x : ι → Position) : + t^2 * (badLabels t x).card / 2 ≤ orderedEnergy (corePotential t) x := by + classical + have hrow (i : ι) : (if i ∈ badLabels t x then t^2 else 0) ≤ + ∑ j, if i ≠ j then corePotential t (nndist (x i) (x j)) else 0 := by + have hnon (j : ι) : (0:ℝ) ≤ if i ≠ j then corePotential t (nndist (x i) (x j)) else 0 := by + split_ifs + · exact coreReal_nonneg _ _ + · rfl + by_cases hi : i ∈ badLabels t x + · obtain ⟨j,hij,hd,hs⟩ := (Finset.mem_filter.mp hi).2 + have hfull : corePotential t (nndist (x i) (x j)) = t^2 := coreReal_full_of_not_shell ht hd.le hs + rw [ite_eq_left hi] + have hh := Finset.single_le_sum (fun k _ => hnon k) (Finset.mem_univ j) + simpa only [ite_eq_left hij, hfull] using hh + · rw [ite_eq_right hi] + exact Finset.sum_nonneg (fun j _ => hnon j) + have hh := Finset.sum_le_sum (fun i (_ : i ∈ (Finset.univ : Finset ι)) => hrow i) + have hsum : (∑ i : ι, if i ∈ badLabels t x then t^2 else 0) = t^2*(badLabels t x).card := by + rw [← Finset.sum_filter] + simp [mul_comm] + rw [hsum] at hh + exact div_le_div_of_nonneg_right hh (by norm_num) + +def removalWeight (t β : ℝ) (s : Multiset Position) : ℝ≥0∞ := + ENNReal.ofReal (Real.exp (-β*t^2*s.card/2)) + +lemma measurable_removalWeight (t β : ℝ) : MeasurableConfiguration (removalWeight t β) := by + intro s ι _ + simp only [removalWeight, Multiset.card_add, configurationMultiset_card] + exact measurable_const + +lemma particleBase_removalWeight {μ : Measure Position} (hμ : μ univ ≠ ⊤) (t β z : ℝ) : + (∫⁻ x, removalWeight t β (particleMultiset x) ∂particleBase μ z) = + ENNReal.ofReal (Real.exp ((μ univ).toReal*Real.exp (z-β*t^2/2))) := by + have hm := measurable_particleObservable _ (measurable_removalWeight t β) 0 + simp only [zero_add] at hm + have hh := lintegral_particleBase μ (z-β*t^2/2) (f := fun _ => (1:ℝ≥0∞)) measurable_const + simp only [lintegral_one] at hh + rw [lintegral_particleBase μ z hm, ← particleBase_univ hμ (z-β*t^2/2), hh] + apply tsum_congr + intro n + simp only [particleMultiset, removalWeight, configurationMultiset_card, Fintype.card_fin, + lintegral_const] + rw [← mul_assoc, ← ENNReal.ofReal_mul (by positivity)] + congr 2 + rw [div_mul_eq_mul_div, ← Real.exp_add] + congr 1 + ring_nf + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/BoltzmannMeasure.lean b/lean/OAI/Probability/RadialTransition/BoltzmannMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ece8ca5aa5514bce6656e98db26d96d8ed66d1f --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/BoltzmannMeasure.lean @@ -0,0 +1,90 @@ +import OAI.Probability.RadialTransition.ParticleMeasure + +namespace OAI + +universe uX + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +def boltzmannPartition {X : Type uX} [MeasurableSpace X] (μ : Measure X) (E : X → ℝ) : ℝ := + ∫ x, Real.exp (-E x) ∂μ + +def boltzmannMeasure {X : Type uX} [MeasurableSpace X] (μ : Measure X) (E : X → ℝ) : Measure X := + (ENNReal.ofReal (boltzmannPartition μ E))⁻¹ • μ.withDensity (fun x => ENNReal.ofReal (Real.exp (-E x))) + +theorem boltzmannMeasure_probability {X : Type uX} [MeasurableSpace X] {μ : Measure X} + {E : X → ℝ} (hi : Integrable (fun x => Real.exp (-E x)) μ) + (hp : 0 < boltzmannPartition μ E) : IsProbabilityMeasure (boltzmannMeasure μ E) := by + constructor + rw [boltzmannMeasure, Measure.smul_apply, withDensity_apply _ MeasurableSet.univ, + Measure.restrict_univ, ← ofReal_integral_eq_lintegral_ofReal hi + (Eventually.of_forall (fun x => (Real.exp_pos _).le))] + change (ENNReal.ofReal (boltzmannPartition μ E))⁻¹ * ENNReal.ofReal (boltzmannPartition μ E) = 1 + rw [ENNReal.inv_mul_cancel (ENNReal.ofReal_ne_zero_iff.mpr hp) ENNReal.ofReal_ne_top] + +theorem integral_boltzmann {X : Type uX} [MeasurableSpace X] {μ : Measure X} + {E : X → ℝ} (hE : Measurable E) (f : X → ℝ) : + (∫ x, f x ∂boltzmannMeasure μ E) = + (boltzmannPartition μ E)⁻¹ * ∫ x, Real.exp (-E x) * f x ∂μ := by + have hw : Measurable (fun x => ENNReal.ofReal (Real.exp (-E x))) := + (Real.measurable_exp.comp hE.neg).ennreal_ofReal + rw [boltzmannMeasure, integral_smul_measure, + integral_withDensity_eq_integral_toReal_smul + hw (Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top))] + have hZ : 0 ≤ boltzmannPartition μ E := integral_nonneg (fun _ => (Real.exp_pos _).le) + simp only [ENNReal.toReal_inv, ENNReal.toReal_ofReal hZ, + ENNReal.toReal_ofReal (Real.exp_pos _).le, smul_eq_mul] + +theorem integrable_boltzmann {X : Type uX} [MeasurableSpace X] {μ : Measure X} + {E f : X → ℝ} (hE : Measurable E) + (hi : Integrable (fun x => Real.exp (-E x) * f x) μ) + (hp : 0 < boltzmannPartition μ E) : Integrable f (boltzmannMeasure μ E) := by + have hw : Measurable (fun x => ENNReal.ofReal (Real.exp (-E x))) := + (Real.measurable_exp.comp hE.neg).ennreal_ofReal + apply Integrable.smul_measure + · apply (integrable_withDensity_iff_integrable_smul' + hw + (Eventually.of_forall (fun _ => ENNReal.ofReal_lt_top))).mpr + simpa only [ENNReal.toReal_ofReal (Real.exp_pos _).le, smul_eq_mul] using hi + · exact ENNReal.inv_ne_top.mpr (ENNReal.ofReal_ne_zero_iff.mpr hp) + +theorem log_boltzmann_difference_le {X : Type uX} [MeasurableSpace X] {μ : Measure X} + {E F : X → ℝ} (hE : Measurable E) + (hiE : Integrable (fun x => Real.exp (-E x)) μ) + (hiF : Integrable (fun x => Real.exp (-F x)) μ) + (hpE : 0 < boltzmannPartition μ E) (hpF : 0 < boltzmannPartition μ F) + (hi : Integrable (fun x => F x - E x) (boltzmannMeasure μ E)) : + Real.log (boltzmannPartition μ E) - Real.log (boltzmannPartition μ F) ≤ + ∫ x, F x - E x ∂boltzmannMeasure μ E := by + let := boltzmannMeasure_probability hiE hpE + have hexp : Integrable (fun x => Real.exp (-(F x - E x))) (boltzmannMeasure μ E) := by + apply integrable_boltzmann hE _ hpE + convert hiF using 1 + ext x + rw [← Real.exp_add] + congr 1 + ring + have hj := convexOn_exp.map_integral_le Real.continuous_exp.continuousOn isClosed_univ + (Eventually.of_forall (fun x => mem_univ (-(F x - E x)))) hi.neg hexp + rw [integral_neg, integral_boltzmann hE (fun x => Real.exp (-(F x - E x)))] at hj + have he (x : X) : Real.exp (-E x) * Real.exp (-(F x - E x)) = Real.exp (-F x) := by + rw [← Real.exp_add] + congr 1 + ring + simp_rw [he] at hj + have hl := Real.log_le_log (Real.exp_pos _) hj + change Real.log (Real.exp (-∫ x, F x - E x ∂boltzmannMeasure μ E)) ≤ + Real.log ((boltzmannPartition μ E)⁻¹ * boltzmannPartition μ F) at hl + rw [Real.log_exp, Real.log_mul (inv_ne_zero hpE.ne') hpF.ne', Real.log_inv] at hl + linarith + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/BoundedCore.lean b/lean/OAI/Probability/RadialTransition/BoundedCore.lean new file mode 100644 index 0000000000000000000000000000000000000000..0d9b5e77d80be097f6d19f1e5c46e75ed7ba6fd0 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/BoundedCore.lean @@ -0,0 +1,225 @@ +import OAI.Probability.RadialTransition.ShellGeometry + +namespace OAI + +universe uV + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +def clamp01 (x : ℝ) : ℝ := max 0 (min 1 x) + +theorem clamp01_nonneg (x : ℝ) : 0 ≤ clamp01 x := le_max_left _ _ +theorem clamp01_le_one (x : ℝ) : clamp01 x ≤ 1 := + max_le (by norm_num) (min_le_left _ _) +theorem clamp01_eq_zero {x : ℝ} (hx : x ≤ 0) : clamp01 x = 0 := by + exact max_eq_left (le_trans (min_le_right _ _) hx) +theorem clamp01_eq_one {x : ℝ} (hx : 1 ≤ x) : clamp01 x = 1 := by + simp [clamp01, min_eq_left hx] +theorem clamp01_mono : Monotone clamp01 := by + intro x y hxy + exact max_le_max le_rfl (min_le_min le_rfl hxy) +theorem continuous_clamp01 : Continuous clamp01 := by + unfold clamp01 + fun_prop + +def microLength (t : ℝ) : ℝ := Real.exp (-t) +def shellStep (t : ℝ) : ℝ := microLength t / 3000 + +def coreReal (t r : ℝ) : ℝ := + t ^ 2 * min + (1 - clamp01 ((r - microLength t) / shellStep t) + + clamp01 ((r - microLength t - 2 * shellStep t) / shellStep t)) + (clamp01 (1 + t * (1 - r))) + +def corePotential (t : ℝ) : Potential := fun r => coreReal t r + +theorem microLength_pos (t : ℝ) : 0 < microLength t := Real.exp_pos _ +theorem shellStep_pos (t : ℝ) : 0 < shellStep t := div_pos (microLength_pos t) (by norm_num) + +theorem coreReal_nonneg (t r : ℝ) : 0 ≤ coreReal t r := by + apply mul_nonneg (sq_nonneg t) + apply le_min + · linarith [clamp01_le_one ((r - microLength t) / shellStep t), + clamp01_nonneg ((r - microLength t - 2 * shellStep t) / shellStep t)] + · exact clamp01_nonneg _ + +theorem coreReal_le (t r : ℝ) : coreReal t r ≤ t ^ 2 := by + have hh : min + (1 - clamp01 ((r - microLength t) / shellStep t) + + clamp01 ((r - microLength t - 2 * shellStep t) / shellStep t)) + (clamp01 (1 + t * (1 - r))) ≤ 1 := + (min_le_right _ _).trans (clamp01_le_one _) + simpa only [coreReal, mul_one] using mul_le_mul_of_nonneg_left hh (sq_nonneg t) + +theorem continuous_coreReal (t : ℝ) : Continuous (coreReal t) := by + unfold coreReal + exact continuous_const.mul + (((continuous_const.sub (continuous_clamp01.comp + ((continuous_id.sub continuous_const).div_const _))).add + (continuous_clamp01.comp + (((continuous_id.sub continuous_const).sub continuous_const).div_const _))).min + (continuous_clamp01.comp + (continuous_const.add (continuous_const.mul (continuous_const.sub continuous_id))))) + +theorem continuous_corePotential (t : ℝ) : Continuous (corePotential t) := + (continuous_coreReal t).comp NNReal.continuous_coe + +theorem bounded_corePotential (t : ℝ) : IsBoundedPotential (corePotential t) := by + refine ⟨t ^ 2, sq_nonneg t, fun r => ?_⟩ + change |coreReal t r| ≤ t ^ 2 + rw [abs_of_nonneg (coreReal_nonneg t r)] + exact coreReal_le t r + +theorem coreReal_zero_plateau (t r : ℝ) + (hlo : microLength t + shellStep t ≤ r) + (hhi : r ≤ microLength t + 2 * shellStep t) : coreReal t r = 0 := by + have hd := shellStep_pos t + have hdown : clamp01 ((r - microLength t) / shellStep t) = 1 := + clamp01_eq_one ((le_div_iff₀ hd).mpr (by linarith)) + have hup : clamp01 ((r - microLength t - 2 * shellStep t) / shellStep t) = 0 := + clamp01_eq_zero (div_nonpos_of_nonpos_of_nonneg (by linarith) hd.le) + simp only [coreReal, hdown, hup, sub_self, add_zero, + min_eq_left (clamp01_nonneg _), mul_zero] + +theorem coreReal_zero_outer {t r : ℝ} (ht : 0 < t) (hr : 1 + 1 / t ≤ r) : + coreReal t r = 0 := by + have hc : clamp01 (1 + t * (1 - r)) = 0 := by + apply clamp01_eq_zero + have hm := mul_le_mul_of_nonneg_left hr ht.le + have hd := div_mul_cancel₀ (1 : ℝ) (ne_of_gt ht) + nlinarith [hm, hd] + have hs : 0 ≤ 1 - clamp01 ((r - microLength t) / shellStep t) + + clamp01 ((r - microLength t - 2 * shellStep t) / shellStep t) := by + linarith [clamp01_le_one ((r - microLength t) / shellStep t), + clamp01_nonneg ((r - microLength t - 2 * shellStep t) / shellStep t)] + simp only [coreReal, hc, min_eq_right hs, mul_zero] + +theorem coreReal_full_left {t r : ℝ} (ht : 0 ≤ t) + (hl : r ≤ microLength t) (hr : r ≤ 1) : coreReal t r = t ^ 2 := by + have hd := shellStep_pos t + have hdown : clamp01 ((r - microLength t) / shellStep t) = 0 := + clamp01_eq_zero (div_nonpos_of_nonpos_of_nonneg (by linarith) hd.le) + have hup : clamp01 ((r - microLength t - 2 * shellStep t) / shellStep t) = 0 := + clamp01_eq_zero (div_nonpos_of_nonpos_of_nonneg (by linarith) hd.le) + have hc : clamp01 (1 + t * (1 - r)) = 1 := + clamp01_eq_one (by nlinarith [mul_nonneg ht (sub_nonneg.mpr hr)]) + simp [coreReal, hdown, hup, hc] + +theorem coreReal_full_right {t r : ℝ} (ht : 0 ≤ t) + (hl : microLength t + 3 * shellStep t ≤ r) (hr : r ≤ 1) : + coreReal t r = t ^ 2 := by + have hd := shellStep_pos t + have hdown : clamp01 ((r - microLength t) / shellStep t) = 1 := + clamp01_eq_one ((le_div_iff₀ hd).mpr (by linarith)) + have hup : clamp01 ((r - microLength t - 2 * shellStep t) / shellStep t) = 1 := + clamp01_eq_one ((le_div_iff₀ hd).mpr (by linarith)) + have hc : clamp01 (1 + t * (1 - r)) = 1 := + clamp01_eq_one (by nlinarith [mul_nonneg ht (sub_nonneg.mpr hr)]) + simp [coreReal, hdown, hup, hc] + +theorem coreReal_full_of_not_shell {t r : ℝ} (ht : 0 ≤ t) (hr : r ≤ 1) + (hs : ¬(microLength t ≤ r ∧ r ≤ (1 + (1 : ℝ) / 1000) * microLength t)) : + coreReal t r = t ^ 2 := by + by_cases hlo : microLength t ≤ r + · apply coreReal_full_right ht ?_ hr + have hhi : (1 + (1 : ℝ) / 1000) * microLength t < r := + lt_of_not_ge (fun hh => hs ⟨hlo, hh⟩) + dsimp [shellStep] + linarith [hhi] + · exact coreReal_full_left ht (le_of_not_ge hlo) hr + +theorem twice_pair_sum {N : ℕ} (F : Fin N → Fin N → ℝ) + (hF : ∀ i j, F i j = F j i) : + 2 * (∑ i, ∑ j with i < j, F i j) = + ∑ i, ∑ j, if i ≠ j then F i j else 0 := by + classical + simp only [Finset.sum_filter] + have hswap : (∑ i, ∑ j, if j < i then F i j else 0) = + ∑ i, ∑ j, if i < j then F i j else 0 := by + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + rw [hF j i] + calc + 2 * (∑ i, ∑ j, if i < j then F i j else 0) = + (∑ i, ∑ j, if i < j then F i j else 0) + + (∑ i, ∑ j, if j < i then F i j else 0) := by rw [hswap]; ring + _ = _ := by + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro j _ + rcases lt_trichotomy i j with h | h | h + · simp [h, ne_of_lt h, not_lt_of_ge h.le] + · simp [h] + · simp [h, ne_of_gt h, not_lt_of_ge h.le] + +theorem sum_adj_indicator {V : Type uV} [Fintype V] (G : SimpleGraph V) + [DecidableRel G.Adj] : + (∑ i, ∑ j, if G.Adj i j then (1 : ℝ) else 0) = 2 * G.edgeFinset.card := by + classical + have hi (i : V) : (∑ j, if G.Adj i j then (1 : ℝ) else 0) = G.degree i := by + rw [← G.card_neighborFinset_eq_degree, G.neighborFinset_eq_filter] + simp + simp_rw [hi] + exact_mod_cast G.sum_degrees_eq_twice_card_edges + +theorem core_energy_lower_small_diameter {N : ℕ} {t : ℝ} (ht : 0 ≤ t) + (x : Fin N → Position) (hx : ∀ i j, dist (x i) (x j) ≤ 1) : + t ^ 2 / 8 * (N : ℝ) ^ 2 - t ^ 2 / 2 * N ≤ energy (corePotential t) x := by + classical + let G := shellGraph x (microLength t) + have hG : G.CliqueFree 5 := shellGraph_cliqueFree x (microLength_pos t) + have hbound : (8 : ℝ) * G.edgeFinset.card ≤ 3 * (N : ℝ) ^ 2 := by + have hh : 8 * G.edgeFinset.card ≤ 3 * N ^ 2 := by + simpa using shell_edge_bound G hG + exact_mod_cast hh + have hpair := twice_pair_sum + (fun i j => coreReal t (dist (x i) (x j))) (fun i j => by rw [dist_comm]) + have heq : (∑ i, ∑ j with i < j, coreReal t (dist (x i) (x j))) = + energy (corePotential t) x := by rfl + rw [heq] at hpair + have hterm (i j : Fin N) : + t ^ 2 * ((if i ≠ j then (1 : ℝ) else 0) - (if G.Adj i j then 1 else 0)) ≤ + (if i ≠ j then coreReal t (dist (x i) (x j)) else 0) := by + by_cases hij : i = j + · subst j + simp + · simp only [ite_eq_left hij] + by_cases hA : G.Adj i j + · simp only [hA, ite_true, sub_self, mul_zero] + exact coreReal_nonneg _ _ + · simp only [hA, ite_false, sub_zero, mul_one] + rw [coreReal_full_of_not_shell ht (hx i j)] + intro h + exact hA ⟨hij, h⟩ + have hsum := Finset.sum_le_sum (s := Finset.univ) fun i _ => + Finset.sum_le_sum (s := Finset.univ) fun j _ => hterm i j + have hcount : (∑ i : Fin N, ∑ j : Fin N, if i ≠ j then (1 : ℝ) else 0) = + (N : ℝ) ^ 2 - N := by + have hite (i j : Fin N) : (if i ≠ j then (1 : ℝ) else 0) = + 1 - (if i = j then 1 else 0) := by by_cases h : i = j <;> simp [h] + simp_rw [hite] + simp only [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, mul_one, Finset.sum_ite_eq, + Finset.mem_univ, ite_true] + ring + simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.mul_sum] at hsum + rw [hcount, sum_adj_indicator G, ← hpair] at hsum + have hb := mul_le_mul_of_nonneg_left hbound (sq_nonneg t) + nlinarith [hsum, hb] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/BoxEnsembles.lean b/lean/OAI/Probability/RadialTransition/BoxEnsembles.lean new file mode 100644 index 0000000000000000000000000000000000000000..3cfba864b3abf6a81b1f33c6ce16992794fcca21 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/BoxEnsembles.lean @@ -0,0 +1,228 @@ +import OAI.Probability.RadialTransition.DeletedInteractions + +namespace OAI + +noncomputable section + + +open MeasureTheory Set Filter Function + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +def halfCube (L : ℝ) : Set Position := {x | ∀ k, 0 ≤ x k ∧ x k < L} + +lemma measurableSet_halfCube (L : ℝ) : MeasurableSet (halfCube L) := by + have he : halfCube L = ⋂ k : Fin 3, {x : Position | 0 ≤ x k ∧ x k < L} := by + ext x; simp only [halfCube, mem_ofPred_eq, mem_iInter] + rw [he] + apply MeasurableSet.iInter + intro k + exact (isClosed_le continuous_const (PiLp.continuous_apply 2 (fun _ : Fin 3 => ℝ) k)).measurableSet.inter + (isOpen_lt (PiLp.continuous_apply 2 (fun _ : Fin 3 => ℝ) k) continuous_const).measurableSet + +lemma halfCube_ae_cube (L : ℝ) : halfCube L =ᵐ[volume] cube L := by + have hh := Measure.univ_pi_Ico_ae_eq_Icc (μ := fun _ : Fin 3 => (volume : Measure ℝ)) + (f := fun _ => (0:ℝ)) (g := fun _ => L) + have hp := (PiLp.volume_preserving_ofLp (Fin 3)).quasiMeasurePreserving.ae hh + filter_upwards [hp] with x hx + apply propext + change (∀ k, 0 ≤ x k ∧ x k < L) ↔ (∀ k, 0 ≤ x k ∧ x k ≤ L) + have hx' := eq_iff_iff.mp hx + simpa only [Set.pi, Set.Ico, Set.Icc, Membership.mem, Set.Mem, Set.ofPred, Set.univ, Set.mem_univ, true_implies, forall_const, Pi.le_def, forall_and] using hx' + +lemma restrict_halfCube (L : ℝ) : volume.restrict (halfCube L) = volume.restrict (cube L) := + Measure.restrict_congr_set (halfCube_ae_cube L) + +abbrev GridIndex (q : ℕ) := Fin 3 → Fin q + +def gridEmbed {q : ℕ} (i : GridIndex q) : Cell := fun k => (i k : ℤ) + +lemma gridEmbed_injective (q : ℕ) : Function.Injective (@gridEmbed q) := by + intro i j h + funext k + apply Fin.ext + have hh : (i k : ℤ) = (j k : ℤ) := congrFun h k + exact_mod_cast hh + +lemma halfCube_grid_cover (q : ℕ) (x : Position) (hx : x ∈ halfCube ((q:ℝ)/4)) : + ∃ i : GridIndex q, cellOf x = gridEmbed i := by + have hh (k : Fin 3) : 0 ≤ cellOf x k ∧ cellOf x k < (q:ℤ) := by + constructor + · exact Int.floor_nonneg.mpr (by nlinarith [(hx k).1]) + · apply Int.floor_lt.mpr + exact_mod_cast (show 4*x k < (q:ℝ) by linarith [(hx k).2]) + let i : GridIndex q := fun k => ⟨(cellOf x k).toNat, by have := hh k; omega⟩ + refine ⟨i, ?_⟩ + funext k + simp only [gridEmbed, i] + exact (Int.toNat_of_nonneg (hh k).1).symm + +lemma gridEmbed_mem_halfCube_iff {q : ℕ} (i : GridIndex q) (x : Position) + (hx : cellOf x = gridEmbed i) : x ∈ halfCube ((q:ℝ)/4) := by + intro k + have hl := Int.floor_le (4*x k) + have hu := Int.lt_floor_add_one (4*x k) + have he : ⌊4*x k⌋ = (i k : ℤ) := congrFun hx k + rw [he] at hl hu + have hi : (i k : ℝ) + 1 ≤ (q:ℝ) := by exact_mod_cast (i k).isLt + have hin : 0 ≤ (i k : ℝ) := by positivity + constructor <;> push_cast at * <;> linarith + +lemma halfCube_eq_gridUnion (q : ℕ) : + halfCube ((q:ℝ)/4) = ⋃ i : GridIndex q, gridRegion (gridEmbed i) := by + ext x + simp only [mem_iUnion, gridRegion, mem_ofPred_eq] + exact ⟨halfCube_grid_cover q x, fun ⟨i,hi⟩ => gridEmbed_mem_halfCube_iff i x hi⟩ + +lemma volume_halfCube (L : ℝ) : volume (halfCube L) = ENNReal.ofReal L ^ 3 := by + rw [measure_congr (halfCube_ae_cube L), volume_cube] + +def macroOf (q : ℕ) (k : Cell) : Cell := fun d => k d / (q:ℤ) + +def blockEmbed {m q : ℕ} (i : GridIndex m) (j : GridIndex q) : GridIndex (m*q) := + fun d => ⟨(i d : ℕ)*q+(j d : ℕ), by + calc + _ < (i d : ℕ)*q+q := Nat.add_lt_add_left (j d).isLt _ + _ = ((i d : ℕ)+1)*q := by ring + _ ≤ m*q := Nat.mul_le_mul_right q (Nat.succ_le_of_lt (i d).isLt)⟩ + +lemma blockEmbed_macro {m q : ℕ} (hq : 0 < q) (i : GridIndex m) (j : GridIndex q) : + macroOf q (gridEmbed (blockEmbed i j)) = gridEmbed i := by + funext d + simp only [macroOf, gridEmbed, blockEmbed] + have hj := (j d).isLt + have hq' : (0:ℤ) < q := by exact_mod_cast hq + have hj' : (0:ℤ) ≤ (j d : ℕ) ∧ (j d : ℤ) < q := by exact_mod_cast (show 0 ≤ (j d:ℕ) ∧ (j d:ℕ) < q from ⟨Nat.zero_le _, hj⟩) + push_cast + rw [Int.add_ediv_of_dvd_left (dvd_mul_left _ _), + Int.mul_ediv_cancel _ (ne_of_gt hq'), Int.ediv_eq_zero_of_lt hj'.1 hj'.2, add_zero] + +lemma blockEmbed_injective {m q : ℕ} (hq : 0 < q) : + Function.Injective (fun p : GridIndex m × GridIndex q => blockEmbed p.1 p.2) := by + intro p r h + have hi : p.1 = r.1 := gridEmbed_injective m (by + have := congrArg (fun k => macroOf q (gridEmbed k)) h + simpa only [blockEmbed_macro hq] using this) + apply Prod.ext hi + funext d + apply Fin.ext + have hh := congrArg (fun k : GridIndex (m*q) => (k d : ℕ)) h + simp only [blockEmbed, hi] at hh + omega + +lemma blockEmbed_surjective {m q : ℕ} (hq : 0 < q) : + Function.Surjective (fun p : GridIndex m × GridIndex q => blockEmbed p.1 p.2) := by + intro k + let i : GridIndex m := fun d => ⟨(k d : ℕ)/q, Nat.div_lt_of_lt_mul (by simpa only [Nat.mul_comm m q] using (k d).isLt)⟩ + let j : GridIndex q := fun d => ⟨(k d : ℕ)%q, Nat.mod_lt _ hq⟩ + refine ⟨(i,j), ?_⟩ + funext d + apply Fin.ext + simpa only [blockEmbed, i, j, Nat.mul_comm] using Nat.div_add_mod (k d : ℕ) q + +def boundaryCoord (q D : ℕ) : Finset (Fin q) := + Finset.univ.filter (fun a => (a:ℕ) < D ∨ q-D ≤ (a:ℕ)) + +lemma card_boundaryCoord (q D : ℕ) : (boundaryCoord q D).card ≤ 2*D := by + let lo := Finset.univ.filter (fun a : Fin q => (a:ℕ) < D) + let hi := Finset.univ.filter (fun a : Fin q => q-D ≤ (a:ℕ)) + have hlo : lo.card ≤ D := by + calc + _ ≤ (Finset.range D).card := Finset.card_le_card_of_injOn Fin.val + (by intro a ha; exact Finset.mem_range.mpr (Finset.mem_filter.mp ha).2) + (fun a _ b _ h => Fin.ext h) + _ = D := Finset.card_range D + have hhi : hi.card ≤ D := by + calc + _ ≤ (Finset.range D).card := Finset.card_le_card_of_injOn (fun a : Fin q => q-1-(a:ℕ)) + (by intro a ha; have hh := (Finset.mem_filter.mp ha).2; have := a.isLt; apply Finset.mem_range.mpr; change q-1-(a:ℕ) < D; omega) + (by intro a ha b hb h; apply Fin.ext; have := a.isLt; have := b.isLt; change q-1-(a:ℕ) = q-1-(b:ℕ) at h; omega) + _ = D := Finset.card_range D + have he : boundaryCoord q D = lo ∪ hi := by + ext a; simp only [boundaryCoord, lo, hi, Finset.mem_filter, Finset.mem_univ, true_and, Finset.mem_union] + rw [he] + exact le_trans (Finset.card_union_le lo hi) (by omega) + +def boundarySlice (q D : ℕ) (d : Fin 3) : Finset (GridIndex q) := + Fintype.piFinset (fun k => if k = d then boundaryCoord q D else Finset.univ) + +def boundaryGrid (q D : ℕ) : Finset (GridIndex q) := + Finset.univ.biUnion (boundarySlice q D) + +lemma mem_boundaryGrid {q D : ℕ} {j : GridIndex q} : + j ∈ boundaryGrid q D ↔ ∃ d, (j d:ℕ) < D ∨ q-D ≤ (j d:ℕ) := by + simp only [boundaryGrid, Finset.mem_biUnion, Finset.mem_univ, true_and, + boundarySlice, Fintype.mem_piFinset] + constructor + · rintro ⟨d,hd⟩ + refine ⟨d, ?_⟩ + have h := hd d + simpa only [ite_true, boundaryCoord, Finset.mem_filter, Finset.mem_univ, true_and] using h + · rintro ⟨d,hd⟩ + refine ⟨d, ?_⟩ + intro k + split_ifs with h + · subst k + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, hd⟩ + · exact Finset.mem_univ _ + +lemma card_boundaryGrid (q D : ℕ) : (boundaryGrid q D).card ≤ 6*D*q^2 := by + have hs (d : Fin 3) : (boundarySlice q D d).card = (boundaryCoord q D).card*q^2 := by + rw [boundarySlice, Fintype.card_piFinset] + fin_cases d <;> simp [Fin.prod_univ_three] <;> ring + calc + _ ≤ ∑ d : Fin 3, (boundarySlice q D d).card := Finset.card_biUnion_le + _ = 3*((boundaryCoord q D).card*q^2) := by simp only [hs, Finset.sum_const, Finset.card_univ, Fintype.card_fin, smul_eq_mul] + _ ≤ 3*(2*D*q^2) := Nat.mul_le_mul_left _ (Nat.mul_le_mul_right _ (card_boundaryCoord q D)) + _ = _ := by ring + +lemma inner_block_macro {m q D : ℕ} (hq : 0 < q) (i : GridIndex m) (j : GridIndex q) + (hj : j ∉ boundaryGrid q D) {k : Cell} + (hk : ∀ d, |k d-gridEmbed (blockEmbed i j) d| ≤ (D:ℤ)) : + macroOf q k = gridEmbed i := by + have hj' : ∀ d, D ≤ (j d:ℕ) ∧ (j d:ℕ)+D < q := by + have hh := mt mem_boundaryGrid.mpr hj + intro d + have hn : ¬ ((j d:ℕ) < D ∨ q-D ≤ (j d:ℕ)) := fun h => hh ⟨d,h⟩ + omega + funext d + apply (Int.ediv_eq_iff_of_pos (by exact_mod_cast hq)).mpr + have hkd := abs_le.mp (hk d) + have hlow : (D:ℤ) ≤ (j d:ℤ) := by exact_mod_cast (hj' d).1 + have hupp : (j d:ℤ)+(D:ℤ) < (q:ℤ) := by exact_mod_cast (hj' d).2 + change -(D:ℤ) ≤ k d-((i d:ℕ)*q+(j d:ℕ):ℕ) ∧ k d-((i d:ℕ)*q+(j d:ℕ):ℕ) ≤ (D:ℤ) at hkd + push_cast at hkd + change (i d:ℤ)*(q:ℤ) ≤ k d ∧ k d < (i d:ℤ)*(q:ℤ)+(q:ℤ) + constructor <;> omega + +lemma sum_blockGrid {m q : ℕ} (hq : 0 < q) (F : GridIndex (m*q) → ℝ) : + ∑ k, F k = ∑ i : GridIndex m, ∑ j : GridIndex q, F (blockEmbed i j) := by + have hh := Fintype.sum_equiv (Equiv.ofBijective _ ⟨blockEmbed_injective (m := m) hq, blockEmbed_surjective hq⟩) + (fun p => F (blockEmbed p.1 p.2)) F (fun _ => rfl) + rw [Fintype.sum_prod_type] at hh + exact hh.symm + +lemma grid_sum_boundary_bound {m q D : ℕ} (hq : 0 < q) {C : ℝ} (hC : 0 ≤ C) + (F : GridIndex (m*q) → ℝ) + (hF : ∀ k, F k ≤ C) + (hzero : ∀ i j, j ∉ boundaryGrid q D → F (blockEmbed i j) = 0) : + ∑ k, F k ≤ (m:ℝ)^3*(6*D*q^2)*C := by + rw [sum_blockGrid hq] + have hsum (i : GridIndex m) : ∑ j : GridIndex q, F (blockEmbed i j) ≤ (6*D*q^2:ℕ)*C := by + calc + _ = ∑ j ∈ boundaryGrid q D, F (blockEmbed i j) := + (Finset.sum_subset (Finset.subset_univ _) (fun j _ hj => hzero i j hj)).symm + _ ≤ ∑ _j ∈ boundaryGrid q D, C := Finset.sum_le_sum (fun j _ => hF _) + _ = ((boundaryGrid q D).card:ℝ)*C := by simp + _ ≤ (6*D*q^2:ℕ)*C := mul_le_mul_of_nonneg_right (by exact_mod_cast card_boundaryGrid q D) hC + calc + _ ≤ ∑ _i : GridIndex m, (6*D*q^2:ℕ)*C := Finset.sum_le_sum (fun i _ => hsum i) + _ = _ := by simp only [Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_fin]; push_cast; ring + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/BoxPressure.lean b/lean/OAI/Probability/RadialTransition/BoxPressure.lean new file mode 100644 index 0000000000000000000000000000000000000000..8297608068b02cdda11e91774bc5cbfe9b71fdce --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/BoxPressure.lean @@ -0,0 +1,68 @@ +import OAI.Probability.RadialTransition.GridPressure + +namespace OAI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff BigOperators ENNReal NNReal + +namespace RadialTransition + +lemma summable_sectorWeight (φ : Potential) (L β z : ℝ) (n : ℕ) : + Summable (fun k : ℕ => (if k = n then (1:ℝ) else 0)*Real.exp (z*k)*partition φ L k β) := + summable_of_ne_finset_zero (s := {n}) (by intro k hk; simp only [Finset.mem_singleton] at hk; simp [hk]) + +lemma sectorWeight_tsum (φ : Potential) (L β z : ℝ) (n : ℕ) : + (∑' k : ℕ, (if k = n then (1:ℝ) else 0)*Real.exp (z*k)*partition φ L k β) = Real.exp (z*n)*partition φ L n β := by + simp only [ite_mul, one_mul, zero_mul] + exact tsum_ite_eq n _ + +lemma macroProduct_sector (φ : Potential) (m q : ℕ) (β : ℝ) (n : ℕ) (x : MacroState m q) : + macroProduct φ m q β (fun k => if k = n then 1 else 0) x = + if (∀ i, particleCount (x i) = n) then + Real.exp (-β*∑ i : GridIndex m, pairWithin (fun (y z : macroRegion q (gridEmbed i)) => radialPair φ y z) (x i)) else 0 := by + classical + by_cases hh : ∀ i, particleCount (x i) = n + · rw [ite_eq_left hh] + simp only [macroProduct, hh, ite_true, one_mul, ← Real.exp_sum, ← Finset.mul_sum] + · simp only [hh, ite_false] + obtain ⟨i, hi⟩ := not_forall.mp hh + exact Finset.prod_eq_zero (Finset.mem_univ i) (by simp [hi]) + +lemma macroSector_lower {φ : Potential} {m q : ℕ} (hq : 0 < q) {β R lam : ℝ} + (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (hlam : 0 ≤ lam) (n : ℕ) (x : MacroState m q) : + Real.exp (β*lam*((kernelInterior m q R).card*(1-kernelRowError q R)*(n:ℝ)^2/(2*((q:ℝ)/4)^3)))* + macroProduct φ m q β (fun k => if k = n then 1 else 0) x ≤ + Real.exp (-β*macroKacEnergy φ m q R lam x) := by + classical + rw [macroProduct_sector] + split_ifs with hh + · rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have hb := mul_le_mul_of_nonneg_left (macro_attraction_lower hq hR x hh) (mul_nonneg hβ hlam) + unfold macroKacEnergy + nlinarith + · simpa only [mul_zero] using (Real.exp_pos _).le + +lemma macroKac_partition_lower {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {m q : ℕ} (hq : 0 < q) {β R lam z : ℝ} (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (hlam : 0 ≤ lam) + (hi : Integrable (fun x => Real.exp (-β*macroKacEnergy φ m q R lam x)) (macroMeasure m q z)) (n : ℕ) : + Real.exp (β*lam*((kernelInterior m q R).card*(1-kernelRowError q R)*(n:ℝ)^2/(2*((q:ℝ)/4)^3)))* + (Real.exp (z*n)*partition φ ((q:ℝ)/4) n β)^(m^3) ≤ + boltzmannPartition (macroMeasure m q z) (fun x => β*macroKacEnergy φ m q R lam x) := by + have hs := summable_sectorWeight φ ((q:ℝ)/4) β z n + have hn (k : ℕ) : 0 ≤ (if k = n then (1:ℝ) else 0) := by split_ifs <;> norm_num + have hh := integral_mono ((integrable_macroProduct hφ hb hq m β z _ hn hs).const_mul + (Real.exp (β*lam*((kernelInterior m q R).card*(1-kernelRowError q R)*(n:ℝ)^2/(2*((q:ℝ)/4)^3))))) hi + (macroSector_lower hq hβ hR hlam n) + rw [integral_const_mul, integral_macroProduct hφ hb hq m β z _ hn hs, sectorWeight_tsum] at hh + simpa only [boltzmannPartition, neg_mul] using hh + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CanonicalCorner.lean b/lean/OAI/Probability/RadialTransition/CanonicalCorner.lean new file mode 100644 index 0000000000000000000000000000000000000000..274ab6533667a9975765a2b693026b81d5d82b2b --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CanonicalCorner.lean @@ -0,0 +1,106 @@ +import OAI.Probability.RadialTransition.PackingLimit + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +theorem canonical_support_supergradient {H Q : Pressure} {βc hc s ρ : ℝ} + (hβc : 0 < βc) + (hdual : ∀ β, 0 < β → H β ρ = sSup (Set.range fun h : ℝ => h * ρ - Q β h)) + (hs : pressureSupport Q βc hc s ρ) : + ∀ β, 0 < β → H β ρ ≤ H βc ρ - s * (β - βc) := by + have hbound (β : ℝ) (hβ : 0 < β) (h : ℝ) : + h * ρ - Q β h ≤ hc * ρ - Q βc hc - s * (β - βc) := by + have hh := hs β h hβ + linarith + have heq : H βc ρ = hc * ρ - Q βc hc := by + rw [hdual βc hβc] + apply le_antisymm + · apply csSup_le (Set.range_nonempty _) + rintro _ ⟨h, rfl⟩ + simpa using hbound βc hβc h + · apply le_csSup + · refine ⟨hc * ρ - Q βc hc, ?_⟩ + rintro _ ⟨h, rfl⟩ + simpa using hbound βc hβc h + · exact ⟨hc, rfl⟩ + intro β hβ + rw [hdual β hβ, heq] + apply csSup_le (Set.range_nonempty _) + rintro _ ⟨h, rfl⟩ + exact hbound β hβ h + +theorem concave_oneSided_derivatives {H : ℝ → ℝ} + (hH : ConcaveOn ℝ (Ioi 0) H) {β : ℝ} (hβ : 0 < β) : + ∃ l r : ℝ, HasDerivWithinAt H l (Iic β) β ∧ + HasDerivWithinAt H r (Ici β) β := by + have hx : β ∈ interior (Ioi (0 : ℝ)) := by simpa using hβ + have hl := (hH.neg.hasDerivWithinAt_leftDeriv_of_mem_interior hx).neg.Iic_of_Iio + have hr := (hH.neg.hasDerivWithinAt_rightDeriv_of_mem_interior hx).neg.Ici_of_Ioi + exact ⟨_, _, by simpa using hl, by simpa using hr⟩ + +theorem supergradient_oneSided_bounds {H : ℝ → ℝ} {β m l r : ℝ} + (hβ : 0 < β) + (hm : ∀ y, 0 < y → H y ≤ H β + m * (y - β)) + (hl : HasDerivWithinAt H l (Iic β) β) + (hr : HasDerivWithinAt H r (Ici β) β) : r ≤ m ∧ m ≤ l := by + have hl' := (hasDerivWithinAt_iff_tendsto_slope' (s := Iio β) (by simp)).mp hl.Iio_of_Iic + have hr' := (hasDerivWithinAt_iff_tendsto_slope' (s := Ioi β) (by simp)).mp hr.Ioi_of_Ici + constructor + · apply le_of_tendsto hr' + filter_upwards [self_mem_nhdsWithin, + (lt_mem_nhds hβ).filter_mono nhdsWithin_le_nhds] with y hy hy0 + rw [slope_def_field] + apply (div_le_iff₀ (sub_pos.mpr hy)).mpr + linarith [hm y hy0] + · apply ge_of_tendsto hl' + filter_upwards [self_mem_nhdsWithin, + (lt_mem_nhds hβ).filter_mono nhdsWithin_le_nhds] with y hy hy0 + rw [slope_def_field] + apply (le_div_iff_of_neg (sub_neg.mpr hy)).mpr + linarith [hm y hy0] + +theorem not_differentiable_of_oneSided_gap {f : ℝ → ℝ} {x l r : ℝ} + (hl : HasDerivWithinAt f l (Iic x) x) (hr : HasDerivWithinAt f r (Ici x) x) + (hgap : r < l) : ¬DifferentiableAt ℝ f x := by + intro hd + have hl' := hd.hasDerivAt.hasDerivWithinAt.derivWithin (uniqueDiffWithinAt_Iic x) + have hr' := hd.hasDerivAt.hasDerivWithinAt.derivWithin (uniqueDiffWithinAt_Ici x) + rw [hl.derivWithin (uniqueDiffWithinAt_Iic x)] at hl' + rw [hr.derivWithin (uniqueDiffWithinAt_Ici x)] at hr' + linarith + +theorem canonical_corner_of_pressure_supports {H Q : Pressure} + {βc hc s₁ s₂ ρ t : ℝ} (hβc : 0 < βc) (ht : 0 < t) (hs : s₁ < s₂) + (hdual : ∀ β, 0 < β → H β ρ = sSup (Set.range fun h : ℝ => h * ρ - Q β h)) + (hconc : ConcaveOn ℝ (Ioi 0) (fun β => H β ρ)) + (hs₁ : pressureSupport Q βc hc s₁ ρ) + (hs₂ : pressureSupport Q βc hc s₂ ρ) : + StrictTemperatureCorner (fun β => t * H β ρ / β) βc := by + obtain ⟨l, r, hl, hr⟩ := concave_oneSided_derivatives hconc hβc + have hm₁ : ∀ β, 0 < β → H β ρ ≤ H βc ρ + (-s₁) * (β - βc) := by + simpa only [neg_mul, sub_eq_add_neg] using canonical_support_supergradient hβc hdual hs₁ + have hm₂ : ∀ β, 0 < β → H β ρ ≤ H βc ρ + (-s₂) * (β - βc) := by + simpa only [neg_mul, sub_eq_add_neg] using canonical_support_supergradient hβc hdual hs₂ + have hb₁ := supergradient_oneSided_bounds hβc hm₁ hl hr + have hb₂ := supergradient_oneSided_bounds hβc hm₂ hl hr + have hrl : r < l := by linarith + have hleft := (hl.const_mul t).div (hasDerivAt_id βc).hasDerivWithinAt hβc.ne' + have hright := (hr.const_mul t).div (hasDerivAt_id βc).hasDerivWithinAt hβc.ne' + have hgap : (t * r * βc - t * H βc ρ * 1) / βc ^ 2 < + (t * l * βc - t * H βc ρ * 1) / βc ^ 2 := by + apply (div_lt_div_iff_of_pos_right (sq_pos_of_pos hβc)).mpr + nlinarith [mul_lt_mul_of_pos_left hrl (mul_pos ht hβc)] + refine ⟨_, _, hleft, hright, hgap, ?_⟩ + exact not_differentiable_of_oneSided_gap hleft hright hgap + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CanonicalCosts.lean b/lean/OAI/Probability/RadialTransition/CanonicalCosts.lean new file mode 100644 index 0000000000000000000000000000000000000000..1b73157c5df243e29696badb2f1b3cce14f87fef --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CanonicalCosts.lean @@ -0,0 +1,123 @@ +import OAI.Probability.RadialTransition.FinitePartition + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +def coreLift (t : ℝ) (x : Position) : ℝ := coreReal t ‖x‖ + +theorem continuous_coreLift (t : ℝ) : Continuous (coreLift t) := + (continuous_coreReal t).comp continuous_norm + +theorem coreLift_nonneg (t : ℝ) (x : Position) : 0 ≤ coreLift t x := coreReal_nonneg t ‖x‖ + +theorem coreLift_bound (t : ℝ) (x : Position) : |coreLift t x| ≤ t ^ 2 := by + rw [abs_of_nonneg (coreLift_nonneg t x)] + exact coreReal_le t ‖x‖ + +theorem coreLift_compactSupport {t : ℝ} (ht : 1 ≤ t) : HasCompactSupport (coreLift t) := by + apply HasCompactSupport.of_support_subset_isCompact (isCompact_closedBall (0 : Position) 2) + intro x hx + by_contra h + have hn : 2 < ‖x‖ := by simpa only [Metric.mem_closedBall, dist_zero_right, not_le] using h + apply hx + exact coreReal_zero_outer (by linarith) (le_trans + (by have hh := one_div_le_one_div_of_le (by norm_num : (0 : ℝ) < 1) ht; norm_num at hh; simp only [one_div]; linarith) + hn.le) + +theorem integrable_coreLift {t : ℝ} (ht : 1 ≤ t) : Integrable (coreLift t) := + (continuous_coreLift t).integrable_of_hasCompactSupport (coreLift_compactSupport ht) + +def coreIntegral (t : ℝ) : ℝ := ∫ x : Position, coreLift t x + +theorem coreIntegral_nonneg (t : ℝ) : 0 ≤ coreIntegral t := integral_nonneg (coreLift_nonneg t) + +theorem familyPotential_le_core {t : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (r : ℝ≥0) : + familyPotential t a R r ≤ corePotential t r := by + exact sub_le_self _ (mul_nonneg ht (attractionProfile_nonneg ha hR r)) + +theorem probability_energy_family_upper {t L : ℝ} {a R : ℕ → ℝ} (ht : 1 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hL : 0 < L) (N : ℕ) : + (∫ x : Fin N → Position, energy (familyPotential t a R) x + ∂Measure.pi (fun _ : Fin N => cubeProbability L)) ≤ + coreIntegral t * (N : ℝ)^2 / L^3 := by + have hh := probability_energy_upper (continuous_familyPotential ha hR hs t) + (bounded_familyPotential ha hR hs t) hL N (continuous_coreLift t) + (coreLift_bound t) (integrable_coreLift ht) (coreLift_nonneg t) + (fun x y => (familyPotential_le_core (by linarith) ha hR _).trans_eq (by + simp only [corePotential, coreLift, coe_nndist, dist_eq_norm])) + simpa only [coreIntegral, mul_assoc, mul_comm, mul_left_comm, div_eq_mul_inv] using hh + +theorem log_factorial_bounds (N : ℕ) : + (N : ℝ) * Real.log N - N ≤ Real.log (N.factorial : ℝ) ∧ + Real.log (N.factorial : ℝ) ≤ (N : ℝ) * Real.log N := by + by_cases hN : N = 0 + · simp [hN] + have hN1 : (1 : ℝ) ≤ N := by exact_mod_cast Nat.one_le_iff_ne_zero.mpr hN + constructor + · have hh := Stirling.le_log_factorial_stirling hN + have hnlog : 0 ≤ Real.log (N : ℝ) := Real.log_nonneg hN1 + have hpilog : 0 ≤ Real.log (2 * Real.pi) := Real.log_nonneg (by linarith [Real.pi_gt_three]) + linarith + · have hf : (N.factorial : ℝ) ≤ (N : ℝ)^N := by exact_mod_cast Nat.factorial_le_pow N + have hh := Real.log_le_log (by exact_mod_cast Nat.factorial_pos N) hf + simpa only [Real.log_pow] using hh + +def densityAt (L : ℝ) (N : ℕ) : ℝ := (N : ℝ) / L^3 + +theorem finiteCanonical_bounds {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {L t β c B K : ℝ} (hL : 0 < L) (ht : 0 < t) (hβ : 0 ≤ β) (N : ℕ) + (hlow : ∀ x ∈ configurationCube L N, c * (N : ℝ)^2 / L^3 - B * N ≤ energy φ x) + (hmean : (∫ x : Fin N → Position, energy φ x + ∂Measure.pi (fun _ : Fin N => cubeProbability L)) ≤ K * (N : ℝ)^2 / L^3) : + β / t * (c * densityAt L N ^ 2 - B * densityAt L N) + + (densityAt L N * Real.log (densityAt L N) - densityAt L N) / t ≤ + finiteCanonical φ t L N β ∧ + finiteCanonical φ t L N β ≤ + β / t * K * densityAt L N ^ 2 + densityAt L N * Real.log (densityAt L N) / t := by + have hden : 0 < t * L^3 := mul_pos ht (pow_pos hL 3) + have hlog := log_factorial_bounds N + have hl := log_partition_upper_of_energy_lower hφ hb hL hβ N hlow + rw [Real.log_pow] at hl + norm_num only [Nat.cast_ofNat] at hl + have hu := log_partition_lower_of_energy_mean hφ hb hL hβ N hmean + by_cases hN : N = 0 + · subst N + simp [densityAt, finiteCanonical, partition_zero] + have hNr : (N : ℝ) ≠ 0 := by exact_mod_cast hN + have hdlog : Real.log (densityAt L N) = Real.log (N : ℝ) - 3 * Real.log L := by + rw [densityAt, Real.log_div hNr (pow_ne_zero 3 hL.ne'), Real.log_pow] + norm_num + constructor + · rw [finiteCanonical, le_div_iff₀ hden] + rw [hdlog] + dsimp only [densityAt] + have halg : (β / t * (c * ((N : ℝ) / L^3)^2 - B * ((N : ℝ) / L^3)) + + (((N : ℝ) / L^3) * (Real.log N - 3 * Real.log L) - ((N : ℝ) / L^3)) / t) * + (t * L^3) = β * (c * (N : ℝ)^2 / L^3 - B * N) + + (N : ℝ) * Real.log N - (3 * N : ℝ) * Real.log L - N := by field_simp; ring + rw [halg] + linarith + · rw [finiteCanonical, div_le_iff₀ hden] + rw [hdlog] + dsimp only [densityAt] + have halg : (β / t * K * ((N : ℝ) / L^3)^2 + + ((N : ℝ) / L^3) * (Real.log N - 3 * Real.log L) / t) * (t * L^3) = + β * (K * (N : ℝ)^2 / L^3) + (N : ℝ) * Real.log N - (3 * N : ℝ) * Real.log L := by + field_simp + ring + rw [halg] + linarith + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CanonicalDuality.lean b/lean/OAI/Probability/RadialTransition/CanonicalDuality.lean new file mode 100644 index 0000000000000000000000000000000000000000..de460b5e71fb921f4ecb102bda29345540067085 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CanonicalDuality.lean @@ -0,0 +1,234 @@ +import OAI.Probability.RadialTransition.DensityMixtures + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +theorem canonical_le_grand_dual {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t β d : ℝ} (hstable : StableWith φ B) (ht : 0 < t) (hβ : 0 ≤ β) (hd : 0 ≤ d) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) + (hlim : Tendsto (fun z : ℝ × ℕ => finiteCanonical φ t z.1 z.2 β) + (thermodynamicFilter d) (nhds (canonicalThermo φ t β d))) (h : ℝ) : + h * d - canonicalThermo φ t β d ≤ grandPressure φ t β h := by + have hH := hlim.comp (floor_tendsto_thermodynamicFilter hd) + have hlo := ((floor_density_tendsto hd).const_mul h).sub hH + have hhi := (grandPressure_spec hφ hb hstable ht hβ hc h).1 + apply le_of_tendsto_of_tendsto hlo hhi + filter_upwards [eventually_gt_atTop (0 : ℝ)] with L hL + let n : ℕ := ⌊d * L ^ 3⌋₊ + have hterm := (grandPartition_summable hφ hb hstable hL.le hβ t h).le_tsum n + (fun N _ => mul_nonneg (Real.exp_pos _).le (partition_nonneg L N β)) + have hh := Real.log_le_log (mul_pos (Real.exp_pos _) (partition_pos hφ hb hL n β)) hterm + rw [Real.log_mul (Real.exp_ne_zero _) (partition_pos hφ hb hL n β).ne', Real.log_exp] at hh + have hden : 0 < t * L ^ 3 := by positivity + change h * ((n : ℝ) / L ^ 3) - finiteCanonical φ t L n β ≤ finiteGrandPressure φ t L β h + dsimp only [finiteGrandPressure, finiteCanonical] + apply (le_div_iff₀ hden).mpr + have he : (h * ((n : ℝ) / L ^ 3) - -Real.log (partition φ L n β) / (t * L ^ 3)) * + (t * L ^ 3) = t * h * n + Real.log (partition φ L n β) := by field_simp; ring + rw [he] + exact hh + +theorem grandPartition_tail_le_one {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t L β h D : ℝ} (hstable : StableWith φ B) (ht : 0 < t) (hL : 0 ≤ L) + (hβ : 0 ≤ β) (hD : Real.exp (β * B + t * h + 1) ≤ D) : + (∑' n : {n : ℕ // ⌊D * L ^ 3⌋₊ < n}, + Real.exp (t * h * (n : ℕ)) * partition φ L n β) ≤ 1 := by + have hD0 : 0 < D := (Real.exp_pos _).trans_le hD + let m := ⌊D * L ^ 3⌋₊ + let h' := h + t⁻¹ + have hs := grandPartition_summable hφ hb hstable hL hβ t h' + have hfac : Summable (fun n : ℕ => Real.exp (-D * L ^ 3) * + (Real.exp (t * h' * n) * partition φ L n β)) := hs.mul_left _ + have hsub := (grandPartition_summable hφ hb hstable hL hβ t h).subtype (fun n => m < n) + have hh (n : {n : ℕ // m < n}) : + Real.exp (t * h * (n : ℕ)) * partition φ L n β ≤ + Real.exp (-D * L ^ 3) * (Real.exp (t * h' * (n : ℕ)) * partition φ L n β) := by + have hn : D * L ^ 3 < (n : ℕ) := (Nat.floor_lt (by positivity)).mp n.property + have hfield : t * h' = t * h + 1 := by dsimp [h']; field_simp + rw [← mul_assoc, ← Real.exp_add, hfield] + apply mul_le_mul_of_nonneg_right _ (partition_nonneg L n β) + apply Real.exp_le_exp.mpr + nlinarith + have hsum := hsub.tsum_le_tsum hh (hfac.subtype (fun n => m < n)) + have hsuble := Summable.tsum_subtype_le _ {n : ℕ | m < n} + (fun n => mul_nonneg (Real.exp_pos _).le + (mul_nonneg (Real.exp_pos _).le (partition_nonneg L n β))) hfac + have hh' := hsum.trans hsuble + rw [tsum_mul_left] at hh' + have hbound := mul_le_mul_of_nonneg_left + (grandPartition_bounds hφ hb hstable hL hβ t h').2 (Real.exp_pos (-D * L ^ 3)).le + have heq : β * B + t * h' = β * B + t * h + 1 := by dsimp [h']; field_simp; ring + rw [heq, ← Real.exp_add] at hbound + apply hh'.trans (hbound.trans _) + apply Real.exp_le_one_iff.mpr + nlinarith [pow_nonneg hL (3 : ℕ)] + +theorem finiteGrandPressure_max_term {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t L β h D : ℝ} (hstable : StableWith φ B) (ht : 0 < t) (hL : 1 ≤ L) + (hβ : 0 ≤ β) (hD : Real.exp (β * B + t * h + 1) ≤ D) : + ∃ n : ℕ, (n : ℝ) / L ^ 3 ∈ Icc 0 D ∧ + finiteGrandPressure φ t L β h ≤ + h * ((n : ℝ) / L ^ 3) - finiteCanonical φ t L n β + + Real.log ((D + 2) * L ^ 3) / (t * L ^ 3) := by + classical + have hL0 : 0 < L := by linarith + have hD0 : 0 < D := (Real.exp_pos _).trans_le hD + let m := ⌊D * L ^ 3⌋₊ + let F (n : ℕ) := Real.exp (t * h * n) * partition φ L n β + have hs : Summable F := grandPartition_summable hφ hb hstable hL0.le hβ t h + obtain ⟨n, hn, hnmax⟩ := (Finset.range (m+1)).exists_max_image F (by simp) + have hnle : n ≤ m := by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hn + have hnD : (n : ℝ) ≤ D * L ^ 3 := + (by exact_mod_cast hnle : (n : ℝ) ≤ m).trans (Nat.floor_le (by positivity)) + have hge1 : 1 ≤ F n := by + have hh := hnmax 0 (by simp) + simpa [F, partition_zero] using hh + have htail : (∑' k : {k : ℕ // k ∉ Finset.range (m+1)}, F k) ≤ 1 := by + let e : {k : ℕ // k ∉ Finset.range (m+1)} ≃ {k : ℕ // m < k} := + Equiv.subtypeEquivProp (by funext k; apply propext; simp) + have he := e.tsum_eq (fun k => F k) + change (∑' k : {k : ℕ // k ∉ Finset.range (m+1)}, F k) = + (∑' k : {k : ℕ // m < k}, F k) at he + rw [he] + exact grandPartition_tail_le_one hφ hb hstable ht hL0.le hβ hD + have hgrand : grandPartition φ t L β h ≤ ((m : ℝ) + 2) * F n := by + rw [grandPartition, ← hs.sum_add_tsum_compl (s := Finset.range (m+1))] + have hsum := Finset.sum_le_card_nsmul (Finset.range (m+1)) F (F n) hnmax + simp only [Finset.card_range, nsmul_eq_mul, Nat.cast_add, Nat.cast_one] at hsum + change (∑ k ∈ Finset.range (m+1), F k) + (∑' k : {k : ℕ // k ∉ Finset.range (m+1)}, F k) ≤ _ + nlinarith + have hV : 1 ≤ L ^ 3 := one_le_pow₀ hL + have hmD : (m : ℝ) + 2 ≤ (D + 2) * L ^ 3 := by + have hm := Nat.floor_le (show 0 ≤ D * L ^ 3 by positivity) + dsimp only [m] + nlinarith + have hgrand' := hgrand.trans (mul_le_mul_of_nonneg_right hmD (by linarith : 0 ≤ F n)) + have hlog := Real.log_le_log (show 0 < grandPartition φ t L β h by + linarith [(grandPartition_bounds hφ hb hstable hL0.le hβ t h).1]) hgrand' + have hFp : 0 < F n := by linarith + rw [Real.log_mul (by positivity) hFp.ne'] at hlog + have hFlog : Real.log (F n) = t * h * n + Real.log (partition φ L n β) := by + simp only [F, Real.log_mul (Real.exp_ne_zero _) (partition_pos hφ hb hL0 n β).ne', Real.log_exp] + rw [hFlog] at hlog + refine ⟨n, ⟨by positivity, (div_le_iff₀ (by positivity : 0 < L ^ 3)).mpr hnD⟩, ?_⟩ + have hden : 0 < t * L ^ 3 := by positivity + change Real.log (grandPartition φ t L β h) / (t * L ^ 3) ≤ _ + apply (div_le_iff₀ hden).mpr + have he : (h * ((n : ℝ) / L ^ 3) - finiteCanonical φ t L n β + + Real.log ((D + 2) * L ^ 3) / (t * L ^ 3)) * (t * L ^ 3) = + Real.log ((D + 2) * L ^ 3) + (t * h * n + Real.log (partition φ L n β)) := by + dsimp only [finiteCanonical] + field_simp + ring + rw [he] + exact hlog + +theorem tendsto_log_volume_error {C t : ℝ} (hC : 0 < C) (ht : 0 < t) : + Tendsto (fun L : ℝ => Real.log (C * L ^ 3) / (t * L ^ 3)) atTop (nhds 0) := by + have hx : Tendsto (fun L : ℝ => C * L ^ 3) atTop atTop := + Tendsto.const_mul_atTop hC (tendsto_pow_atTop (by norm_num : 3 ≠ 0)) + have hh := (Real.tendsto_pow_log_div_mul_add_atTop 1 0 1 one_ne_zero).comp hx + simp only [one_mul, add_zero, pow_one, Function.comp_def] at hh + have hh' := hh.const_mul (C / t) + simp only [mul_zero] at hh' + apply hh'.congr' + filter_upwards [eventually_gt_atTop (0 : ℝ)] with L hL + field_simp + +theorem grandPressure_exists_maximizing_density {φ : Potential} + (hφ : Continuous φ) (hb : IsBoundedPotential φ) {B t β : ℝ} + (hstable : StableWith φ B) (ht : 0 < t) (hβ : 0 ≤ β) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) + (hlim : ∀ d : ℝ, 0 ≤ d → Tendsto (fun z : ℝ × ℕ => finiteCanonical φ t z.1 z.2 β) + (thermodynamicFilter d) (nhds (canonicalThermo φ t β d))) (h : ℝ) : + ∃ d : ℝ, 0 ≤ d ∧ grandPressure φ t β h = h * d - canonicalThermo φ t β d := by + let D := Real.exp (β * B + t * h + 1) + have hD : 0 < D := Real.exp_pos _ + let L (j : ℕ) : ℝ := j + 1 + have hLs (j : ℕ) : 1 ≤ L j := by dsimp [L]; linarith [Nat.cast_nonneg (α := ℝ) j] + have hL : Tendsto L atTop atTop := by + exact tendsto_atTop_add_const_right atTop (1 : ℝ) tendsto_natCast_atTop_atTop + choose N hNd hNmax using fun j : ℕ => + finiteGrandPressure_max_term hφ hb hstable ht (hLs j) hβ (le_refl D) + obtain ⟨d, hd, σ, hσ, hden⟩ := isCompact_Icc.tendsto_subseq hNd + have hside : Tendsto (L ∘ σ) atTop atTop := hL.comp hσ.tendsto_atTop + have hconfig : Tendsto (fun j => (L (σ j), N (σ j))) atTop (thermodynamicFilter d) := by + apply tendsto_inf.mpr + exact ⟨tendsto_comap_iff.mpr hside, tendsto_comap_iff.mpr hden⟩ + have hcost := (hlim d hd.1).comp hconfig + have hp := (grandPressure_spec hφ hb hstable ht hβ hc h).1.comp hside + have hu := ((hden.const_mul h).sub hcost).add + ((tendsto_log_volume_error (show 0 < D + 2 by linarith) ht).comp hside) + simp only [add_zero, Function.comp_def] at hp hu + have hle := le_of_tendsto_of_tendsto hp hu (Eventually.of_forall (fun j => hNmax (σ j))) + exact ⟨d, hd.1, le_antisymm hle + (canonical_le_grand_dual hφ hb hstable ht hβ hd.1 hc (hlim d hd.1) h)⟩ + +theorem convex_density_support {F : ℝ → ℝ} (hF : ConvexOn ℝ (Ici 0) F) + {d : ℝ} (hd : 0 < d) : ∃ h : ℝ, ∀ v : ℝ, 0 ≤ v → F d + h * (v - d) ≤ F v := by + have hint : d ∈ interior (Ici (0 : ℝ)) := by simpa using hd + let h := derivWithin F (Iio d) d + refine ⟨h, fun v hv => ?_⟩ + rcases lt_trichotomy v d with hvd | rfl | hdv + · have hh := hF.slope_le_of_hasDerivWithinAt_Iio hv hd.le hvd + (hF.hasDerivWithinAt_leftDeriv_of_mem_interior hint) + rw [slope_def_field] at hh + have hmul := (div_le_iff₀ (sub_pos.mpr hvd)).mp hh + dsimp only [h] + nlinarith + · simp + · have hh := (hF.leftDeriv_le_rightDeriv_of_mem_interior hint).trans + (hF.le_slope_of_hasDerivWithinAt_Ioi hd.le hv hdv + (hF.hasDerivWithinAt_rightDeriv_of_mem_interior hint)) + rw [slope_def_field] at hh + have hmul := (le_div_iff₀ (sub_pos.mpr hdv)).mp hh + dsimp only [h] + nlinarith + +theorem canonical_grand_duality {φ : Potential} + (hφ : Continuous φ) (hb : IsBoundedPotential φ) {B t β : ℝ} + (hstable : StableWith φ B) (ht : 0 < t) (hβ : 0 ≤ β) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) + (hlim : ∀ d : ℝ, 0 ≤ d → Tendsto (fun z : ℝ × ℕ => finiteCanonical φ t z.1 z.2 β) + (thermodynamicFilter d) (nhds (canonicalThermo φ t β d))) : + (∀ h : ℝ, grandPressure φ t β h = sSup {v : ℝ | ∃ d ≥ 0, v = h * d - canonicalThermo φ t β d}) ∧ + (∀ d : ℝ, 0 < d → ∃ h : ℝ, canonicalThermo φ t β d = h * d - grandPressure φ t β h ∧ + ∀ j : ℝ, j * d - grandPressure φ t β j ≤ canonicalThermo φ t β d) := by + have hle (h d : ℝ) (hd : 0 ≤ d) := + canonical_le_grand_dual hφ hb hstable ht hβ hd hc (hlim d hd) h + have hconv : ConvexOn ℝ (Ici 0) (canonicalThermo φ t β) := + boxCost_limit_convex (H := fun L N => finiteCanonical φ t L N β) + (fun s L b hs hL hn m => finiteCanonical_replication hφ hb hβ ht hs hL hc b hn m) hlim + constructor + · intro h + obtain ⟨d, hd, he⟩ := grandPressure_exists_maximizing_density hφ hb hstable ht hβ hc hlim h + apply le_antisymm + · apply le_csSup + · exact ⟨grandPressure φ t β h, fun v ⟨r, hr, hv⟩ => hv ▸ hle h r hr⟩ + · exact ⟨d, hd, he⟩ + · apply csSup_le + · exact ⟨h * 0 - canonicalThermo φ t β 0, 0, le_rfl, rfl⟩ + · rintro v ⟨r, hr, rfl⟩ + exact hle h r hr + · intro d hd + obtain ⟨h, hs⟩ := convex_density_support hconv hd + obtain ⟨v, hv, he⟩ := grandPressure_exists_maximizing_density hφ hb hstable ht hβ hc hlim h + refine ⟨h, ?_, ?_⟩ + · have := hs v hv + have := hle h d hd.le + rw [he] at this ⊢ + linarith + · intro j + linarith [hle j d hd.le] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CanonicalLimit.lean b/lean/OAI/Probability/RadialTransition/CanonicalLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..18e27874b1f0bf3037e80b696634f39bfbcaace6 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CanonicalLimit.lean @@ -0,0 +1,316 @@ +import OAI.Probability.RadialTransition.ThermodynamicLimit + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +instance (d : ℝ) : IsCountablyGenerated (thermodynamicFilter d) := by + unfold thermodynamicFilter + infer_instance + +def HasBoxReplication (H : ℝ → ℕ → ℝ) : Prop := + ∀ (s L : ℝ) (b : ℕ), 0 < s → 0 < L → (b : ℝ) * (s + 2) ≤ L → + ∀ m : Fin (b ^ 3) → ℕ, + H L (∑ j, m j) ≤ s ^ 3 / L ^ 3 * ∑ j, H s (m j) + +theorem boxCost_adjustment {H : ℝ → ℕ → ℝ} (hrep : HasBoxReplication H) + {s L : ℝ} (hs : 0 < s) (hL : 0 < L) (b m q N : ℕ) + (hbL : (b : ℝ) * (s + 2) ≤ L) (hm : 0 < m) (hmq : m < q) + (hN : N ≤ b ^ 3 * q) {c K : ℝ} (hc0 : 0 < c) (hcm : c ≤ (m : ℝ)) + (hcq : c ≤ ((q - m : ℕ) : ℝ)) (hK : 0 ≤ K) + (hcost : ∀ j ≤ q, |H s j| ≤ K) : + H L N ≤ s ^ 3 / L ^ 3 * + ((b : ℝ) ^ 3 * H s m + 2 * K * (|(N : ℝ) - (b : ℝ) ^ 3 * m| / c + 1)) := by + obtain ⟨f, hfN, hfq, hfc⟩ := exists_integer_adjustment (b ^ 3) m q N hm hmq hN hc0 hcm hcq + have hr := hrep s L b hs hL hbL f + rw [hfN] at hr + have hsum := sum_changed_cost f m (H s) (hcost m hmq.le) (fun i => hcost (f i) (hfq i)) + simp only [Fintype.card_fin, Nat.cast_pow] at hsum hfc + apply hr.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact hsum.trans (by gcongr) + +theorem boxCost_limsup_bound {H : ℝ → ℕ → ℝ} (hrep : HasBoxReplication H) + {d s c K : ℝ} (hd : 0 < d) (hs : 0 < s) (hc : 0 < c) (hK : 0 ≤ K) + (m q : ℕ) (hm : 0 < m) (hmq : m < q) + (hcm : c * s ^ 3 ≤ (m : ℝ)) (hcq : c * s ^ 3 ≤ ((q - m : ℕ) : ℝ)) + (hcap : d < (q : ℝ) / (s + 2) ^ 3) (hcost : ∀ j ≤ q, |H s j| ≤ K) + (hbelow : IsBoundedUnder (· ≥ ·) (thermodynamicFilter d) (fun z => H z.1 z.2)) : + limsup (fun z => H z.1 z.2) (thermodynamicFilter d) ≤ + (s / (s + 2)) ^ 3 * H s m + + 2 * K / c * |d - (s / (s + 2)) ^ 3 * ((m : ℝ) / s ^ 3)| := by + let _ := thermodynamicFilter_neBot hd.le + let F := thermodynamicFilter d + let b (z : ℝ × ℕ) : ℕ := ⌊z.1 / (s + 2)⌋₊ + let r (z : ℝ × ℕ) : ℝ := ((b z : ℝ) / z.1) ^ 3 + have hr : Tendsto r F (nhds ((s + 2)⁻¹ ^ 3)) := by + have hh := ((tendsto_nat_floor_mul_div_atTop + (show 0 ≤ (s + 2)⁻¹ by positivity)).pow 3).comp (thermodynamicFilter_side d) + simpa only [r, b, Function.comp_def, div_eq_mul_inv, mul_comm] using hh + have hden : Tendsto (fun z : ℝ × ℕ => (z.1 ^ 3)⁻¹) F (nhds 0) := + tendsto_inv_atTop_zero.comp ((tendsto_pow_atTop (by norm_num : 3 ≠ 0)).comp + (thermodynamicFilter_side d)) + let G (z : ℝ × ℕ) : ℝ := s ^ 3 * (r z * H s m + + 2 * K * (|(z.2 : ℝ) / z.1 ^ 3 - r z * m| / (c * s ^ 3) + (z.1 ^ 3)⁻¹)) + have hG : Tendsto G F (nhds (s ^ 3 * ((s + 2)⁻¹ ^ 3 * H s m + + 2 * K * (|d - (s + 2)⁻¹ ^ 3 * m| / (c * s ^ 3))))) := by + have hh := ((hr.mul_const (H s m)).add + (((((thermodynamicFilter_density d).sub (hr.mul_const (m : ℝ))).abs.div_const + (c * s ^ 3)).add hden).const_mul (2 * K))).const_mul (s ^ 3) + simpa only [add_zero] using hh + have hcaplimit : Tendsto (fun z => r z * q) F (nhds ((q : ℝ) / (s + 2) ^ 3)) := by + simpa only [inv_pow, div_eq_mul_inv, mul_comm] using hr.mul_const (q : ℝ) + obtain ⟨a, hda, haq⟩ := exists_between hcap + have hN : ∀ᶠ z in F, (z.2 : ℝ) / z.1 ^ 3 < r z * q := by + filter_upwards [(thermodynamicFilter_density d).eventually_lt_const hda, + hcaplimit.eventually_const_lt haq] with z hz hq + exact hz.trans hq + have hle : ∀ᶠ z in F, H z.1 z.2 ≤ G z := by + filter_upwards [hN, (thermodynamicFilter_side d).eventually (eventually_gt_atTop (0 : ℝ))] + with z hNz hL + have hbL : (b z : ℝ) * (s + 2) ≤ z.1 := + (le_div_iff₀ (by positivity : 0 < s + 2)).mp (Nat.floor_le (by positivity)) + have hNe : z.2 ≤ b z ^ 3 * q := by + have he : r z * q = ((b z : ℝ) ^ 3 * q) / z.1 ^ 3 := by dsimp [r]; ring + rw [he] at hNz + have hh := (div_lt_div_iff_of_pos_right (pow_pos hL 3)).mp hNz + exact_mod_cast hh.le + have hh := boxCost_adjustment hrep hs hL (b z) m q z.2 hbL hm hmq hNe + (mul_pos hc (pow_pos hs 3)) hcm hcq hK hcost + apply hh.trans_eq + have habs : |(z.2 : ℝ) / z.1 ^ 3 - r z * m| = + |(z.2 : ℝ) - (b z : ℝ) ^ 3 * m| / z.1 ^ 3 := by + dsimp only [r] + rw [div_pow, div_mul_eq_mul_div, ← sub_div, abs_div, abs_of_pos (pow_pos hL 3)] + dsimp only [G] + rw [habs] + dsimp only [r] + ring + have hh := limsup_le_limsup hle hbelow.isCobounded_le hG.isBoundedUnder_le + rw [hG.limsup_eq] at hh + apply hh.trans_eq + field_simp + +theorem tendsto_side_ratio : + Tendsto (fun s : ℝ => s / (s + 2)) atTop (nhds 1) := by + have hh := ((tendsto_inv_atTop_zero.comp + (tendsto_atTop_add_const_right atTop (2 : ℝ) tendsto_id)).const_mul 2).const_sub 1 + simp only [mul_zero, sub_zero] at hh + apply hh.congr' + filter_upwards [eventually_gt_atTop (0 : ℝ)] with s hs + simp only [Function.comp_def, id_eq] + field_simp + ring + +theorem boxCost_limit {H : ℝ → ℕ → ℝ} (hrep : HasBoxReplication H) + (hbnd : ∀ D : ℝ, 0 < D → ∃ K : ℝ, 0 ≤ K ∧ + ∀ s : ℝ, 1 ≤ s → ∀ n : ℕ, (n : ℝ) / s ^ 3 ≤ D → |H s n| ≤ K) + {d : ℝ} (hd : 0 < d) : + ∃ A : ℝ, Tendsto (fun z : ℝ × ℕ => H z.1 z.2) (thermodynamicFilter d) (nhds A) := by + let _ := thermodynamicFilter_neBot hd.le + obtain ⟨K, hK, hbound⟩ := hbnd (2 * d) (by positivity) + have hevent : ∀ᶠ z in thermodynamicFilter d, |H z.1 z.2| ≤ K := by + filter_upwards [(thermodynamicFilter_side d).eventually (eventually_ge_atTop (1 : ℝ)), + (thermodynamicFilter_density d).eventually_lt_const (show d < 2 * d by linarith)] + with z hz hdens + exact hbound z.1 hz z.2 hdens.le + have hbelow : IsBoundedUnder (· ≥ ·) (thermodynamicFilter d) (fun z => H z.1 z.2) := + ⟨-K, hevent.mono (fun z hz => (abs_le.mp hz).1)⟩ + have habove : IsBoundedUnder (· ≤ ·) (thermodynamicFilter d) (fun z => H z.1 z.2) := + ⟨K, hevent.mono (fun z hz => (abs_le.mp hz).2)⟩ + let A := liminf (fun z => H z.1 z.2) (thermodynamicFilter d) + obtain ⟨x, hxH, hx⟩ := exists_seq_tendsto_liminf habove.isCobounded_ge hbelow + let s (j : ℕ) := (x j).1 + let m (j : ℕ) := (x j).2 + let q (j : ℕ) : ℕ := ⌊2 * d * s j ^ 3⌋₊ + have hs : Tendsto s atTop atTop := (thermodynamicFilter_side d).comp hx + have hm : Tendsto (fun j => (m j : ℝ) / s j ^ 3) atTop (nhds d) := + (thermodynamicFilter_density d).comp hx + have hq : Tendsto (fun j => (q j : ℝ) / s j ^ 3) atTop (nhds (2 * d)) := + (floor_density_tendsto (show 0 ≤ 2 * d by positivity)).comp hs + have hratio := tendsto_side_ratio.comp hs + have hcap : Tendsto (fun j => (q j : ℝ) / (s j + 2) ^ 3) atTop (nhds (2 * d)) := by + have hh := hq.mul (hratio.pow 3) + simp only [one_pow, mul_one] at hh + apply hh.congr' + filter_upwards [hs.eventually (eventually_gt_atTop (0 : ℝ))] with j hj + simp only [Function.comp_def] + field_simp + have hdiff : Tendsto (fun j => ((q j : ℝ) - m j) / s j ^ 3) atTop (nhds d) := by + have hh := hq.sub hm + simp only [← sub_div] at hh + convert hh using 1 + congr 1 + ring + have href : ∀ᶠ j in atTop, + limsup (fun z => H z.1 z.2) (thermodynamicFilter d) ≤ + (s j / (s j + 2)) ^ 3 * H (s j) (m j) + + 2 * K / (d / 2) * |d - (s j / (s j + 2)) ^ 3 * ((m j : ℝ) / s j ^ 3)| := by + filter_upwards [hs.eventually (eventually_ge_atTop (1 : ℝ)), + hm.eventually_const_lt (show d / 2 < d by linarith), + hdiff.eventually_const_lt (show d / 2 < d by linarith), + hcap.eventually_const_lt (show d < 2 * d by linarith)] with j hsj hmj hdiffj hcapj + have hsj0 : 0 < s j := by linarith + have hcm : d / 2 * s j ^ 3 < (m j : ℝ) := + (lt_div_iff₀ (pow_pos hsj0 3)).mp hmj + have hcq : d / 2 * s j ^ 3 < (q j : ℝ) - m j := + (lt_div_iff₀ (pow_pos hsj0 3)).mp hdiffj + have hm0 : 0 < m j := by + have hh : (0 : ℝ) < m j := (by positivity : (0 : ℝ) < d / 2 * s j ^ 3).trans hcm + exact_mod_cast hh + have hmq : m j < q j := by + have hh : (m j : ℝ) < q j := by linarith [show 0 < d / 2 * s j ^ 3 by positivity] + exact_mod_cast hh + apply boxCost_limsup_bound hrep hd hsj0 (show 0 < d / 2 by positivity) hK (m j) (q j) + hm0 hmq hcm.le + · rw [Nat.cast_sub hmq.le] + exact hcq.le + · exact hcapj + · intro n hn + apply hbound (s j) hsj n + apply (div_le_iff₀ (pow_pos hsj0 3)).mpr + exact (show (n : ℝ) ≤ q j by exact_mod_cast hn).trans (Nat.floor_le (by positivity)) + · exact hbelow + have hlim : Tendsto (fun j => (s j / (s j + 2)) ^ 3 * H (s j) (m j) + + 2 * K / (d / 2) * |d - (s j / (s j + 2)) ^ 3 * ((m j : ℝ) / s j ^ 3)|) + atTop (nhds A) := by + have hh := ((hratio.pow 3).mul hxH).add + ((((hratio.pow 3).mul hm).const_sub d).abs.const_mul (2 * K / (d / 2))) + simpa only [one_pow, one_mul, sub_self, abs_zero, mul_zero, add_zero, Function.comp_def, s, m, A] using hh + refine ⟨A, tendsto_of_le_liminf_of_limsup_le le_rfl ?_ habove hbelow⟩ + exact ge_of_tendsto hlim href + +theorem boxCost_limit_with_bounds {H : ℝ → ℕ → ℝ} (hrep : HasBoxReplication H) + {l u : ℝ → ℝ} (hl : Continuous l) (hu : Continuous u) (hzero : l 0 = u 0) + (hb : ∀ s : ℝ, 1 ≤ s → ∀ n : ℕ, + l ((n : ℝ) / s ^ 3) ≤ H s n ∧ H s n ≤ u ((n : ℝ) / s ^ 3)) + {d : ℝ} (hd : 0 ≤ d) : + ∃ A : ℝ, Tendsto (fun z : ℝ × ℕ => H z.1 z.2) (thermodynamicFilter d) (nhds A) ∧ + l d ≤ A ∧ A ≤ u d := by + let _ := thermodynamicFilter_neBot hd + have hlo : Tendsto (fun z : ℝ × ℕ => l ((z.2 : ℝ) / z.1 ^ 3)) + (thermodynamicFilter d) (nhds (l d)) := hl.continuousAt.tendsto.comp (thermodynamicFilter_density d) + have hup : Tendsto (fun z : ℝ × ℕ => u ((z.2 : ℝ) / z.1 ^ 3)) + (thermodynamicFilter d) (nhds (u d)) := hu.continuousAt.tendsto.comp (thermodynamicFilter_density d) + have hevent : ∀ᶠ z in thermodynamicFilter d, + l ((z.2 : ℝ) / z.1 ^ 3) ≤ H z.1 z.2 ∧ H z.1 z.2 ≤ u ((z.2 : ℝ) / z.1 ^ 3) := by + filter_upwards [(thermodynamicFilter_side d).eventually (eventually_ge_atTop (1 : ℝ))] with z hz + exact hb z.1 hz z.2 + obtain rfl | hdpos := hd.eq_or_lt + · refine ⟨l 0, ?_, le_rfl, hzero.le⟩ + rw [← hzero] at hup + exact tendsto_of_tendsto_of_tendsto_of_le_of_le' hlo hup + (hevent.mono (fun _ hz => hz.1)) (hevent.mono (fun _ hz => hz.2)) + · have hlocal : ∀ D : ℝ, 0 < D → ∃ K : ℝ, 0 ≤ K ∧ + ∀ s : ℝ, 1 ≤ s → ∀ n : ℕ, (n : ℝ) / s ^ 3 ≤ D → |H s n| ≤ K := by + intro D _ + obtain ⟨Cl, hCl⟩ := isCompact_Icc.exists_bound_of_continuousOn (s := Icc (0 : ℝ) D) hl.continuousOn + obtain ⟨Cu, hCu⟩ := isCompact_Icc.exists_bound_of_continuousOn (s := Icc (0 : ℝ) D) hu.continuousOn + refine ⟨max 0 (max Cl Cu), le_max_left _ _, ?_⟩ + intro s hs n hn + have hds : (n : ℝ) / s ^ 3 ∈ Icc (0 : ℝ) D := ⟨by positivity, hn⟩ + have hll : |l ((n : ℝ) / s ^ 3)| ≤ max 0 (max Cl Cu) := by + have hh := hCl _ hds + rw [Real.norm_eq_abs] at hh + exact hh.trans ((le_max_left _ _).trans (le_max_right _ _)) + have huu : |u ((n : ℝ) / s ^ 3)| ≤ max 0 (max Cl Cu) := by + have hh := hCu _ hds + rw [Real.norm_eq_abs] at hh + exact hh.trans ((le_max_right _ _).trans (le_max_right _ _)) + exact abs_le.mpr ⟨(abs_le.mp hll).1.trans (hb s hs n).1, + (hb s hs n).2.trans (abs_le.mp huu).2⟩ + obtain ⟨A, hA⟩ := boxCost_limit hrep hlocal hdpos + exact ⟨A, hA, le_of_tendsto_of_tendsto hlo hA (hevent.mono (fun _ hz => hz.1)), + le_of_tendsto_of_tendsto hA hup (hevent.mono (fun _ hz => hz.2))⟩ + +theorem finiteCanonical_limit {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {t β c B K : ℝ} (ht : 0 < t) (hβ : 0 ≤ β) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) + (hlow : ∀ L : ℝ, 1 ≤ L → ∀ (N : ℕ) (x : Fin N → Position), + x ∈ configurationCube L N → c * (N : ℝ)^2 / L^3 - B * N ≤ energy φ x) + (hmean : ∀ L : ℝ, 1 ≤ L → ∀ N : ℕ, + (∫ x : Fin N → Position, energy φ x + ∂MeasureTheory.Measure.pi (fun _ : Fin N => cubeProbability L)) ≤ K * (N : ℝ)^2 / L^3) + {d : ℝ} (hd : 0 ≤ d) : + ∃ A : ℝ, Tendsto (fun z : ℝ × ℕ => finiteCanonical φ t z.1 z.2 β) + (thermodynamicFilter d) (nhds A) ∧ + β / t * (c * d ^ 2 - B * d) + (d * Real.log d - d) / t ≤ A ∧ + A ≤ β / t * K * d ^ 2 + d * Real.log d / t := by + apply boxCost_limit_with_bounds (H := fun L N => finiteCanonical φ t L N β) (d := d) + (fun s L b hs hL hbL m => finiteCanonical_replication hφ hb hβ ht hs hL hc b hbL m) + (l := fun d => β / t * (c * d ^ 2 - B * d) + (d * Real.log d - d) / t) + (u := fun d => β / t * K * d ^ 2 + d * Real.log d / t) + · fun_prop (disch := exact Real.continuous_mul_log) + · fun_prop (disch := exact Real.continuous_mul_log) + · simp + · intro L hL N + exact finiteCanonical_bounds hφ hb (by linarith) ht hβ N (hlow L hL N) (hmean L hL N) + · exact hd + +def canonicalThermo (φ : Potential) (t β d : ℝ) : ℝ := + liminf (fun z : ℝ × ℕ => finiteCanonical φ t z.1 z.2 β) (thermodynamicFilter d) + +theorem canonicalThermo_spec {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {t β c B K : ℝ} (ht : 0 < t) (hβ : 0 ≤ β) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) + (hlow : ∀ L : ℝ, 1 ≤ L → ∀ (N : ℕ) (x : Fin N → Position), + x ∈ configurationCube L N → c * (N : ℝ)^2 / L^3 - B * N ≤ energy φ x) + (hmean : ∀ L : ℝ, 1 ≤ L → ∀ N : ℕ, + (∫ x : Fin N → Position, energy φ x + ∂MeasureTheory.Measure.pi (fun _ : Fin N => cubeProbability L)) ≤ K * (N : ℝ)^2 / L^3) + {d : ℝ} (hd : 0 ≤ d) : + Tendsto (fun z : ℝ × ℕ => finiteCanonical φ t z.1 z.2 β) + (thermodynamicFilter d) (nhds (canonicalThermo φ t β d)) ∧ + β / t * (c * d ^ 2 - B * d) + (d * Real.log d - d) / t ≤ canonicalThermo φ t β d ∧ + canonicalThermo φ t β d ≤ β / t * K * d ^ 2 + d * Real.log d / t := by + let _ := thermodynamicFilter_neBot hd + obtain ⟨A, hA, hlo, hhi⟩ := finiteCanonical_limit hφ hb ht hβ hc hlow hmean hd + have he : canonicalThermo φ t β d = A := hA.liminf_eq + rw [he] + exact ⟨hA, hlo, hhi⟩ + +theorem familyCanonicalThermo_spec {t β d : ℝ} {a R : ℕ → ℝ} (ht : 1 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hcoerc : 2197 * t * bumpIntegral⁻¹ * (∑' n, a n) / 2 ≤ t ^ 2 / 16) + (hβ : 0 ≤ β) (hd : 0 ≤ d) : + Tendsto (fun z : ℝ × ℕ => finiteCanonical (familyPotential t a R) t z.1 z.2 β) + (thermodynamicFilter d) (nhds (canonicalThermo (familyPotential t a R) t β d)) ∧ + β / t * (t ^ 2 / 3456 * d ^ 2 - t ^ 2 / 2 * d) + + (d * Real.log d - d) / t ≤ canonicalThermo (familyPotential t a R) t β d ∧ + canonicalThermo (familyPotential t a R) t β d ≤ + β / t * coreIntegral t * d ^ 2 + d * Real.log d / t := by + apply canonicalThermo_spec (continuous_familyPotential ha hR hs t) + (bounded_familyPotential ha hR hs t) (by linarith) hβ + (fun _ hr => familyPotential_nonpos_outer ha hR ht hr) + · intro L hL N x hx + exact family_density_stability (by linarith) hL ha hR hs hcoerc x hx + · intro L hL N + exact probability_energy_family_upper ht ha hR hs (by linarith) N + · exact hd + +theorem canonicalThermo_concave {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {t d : ℝ} (ht : 0 < t) (hd : 0 ≤ d) + (hlim : ∀ β : ℝ, 0 < β → Tendsto (fun z : ℝ × ℕ => finiteCanonical φ t z.1 z.2 β) + (thermodynamicFilter d) (nhds (canonicalThermo φ t β d))) : + ConcaveOn ℝ (Ioi 0) (fun β => canonicalThermo φ t β d) := by + let _ := thermodynamicFilter_neBot hd + refine ⟨convex_Ioi _, ?_⟩ + intro β hβ γ hγ a b ha hb' hab + have hmix : 0 < a * β + b * γ := by + exact (convex_Ioi (0 : ℝ)) hβ hγ ha hb' hab + have hl := (hlim β hβ).const_mul a |>.add ((hlim γ hγ).const_mul b) + have hr := hlim (a * β + b * γ) hmix + apply le_of_tendsto_of_tendsto hl hr + filter_upwards [(thermodynamicFilter_side d).eventually (eventually_gt_atTop (0 : ℝ))] with z hz + exact (finiteCanonical_concave hφ hb ht hz z.2).2 (mem_univ β) (mem_univ γ) ha hb' hab + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CellDifferences.lean b/lean/OAI/Probability/RadialTransition/CellDifferences.lean new file mode 100644 index 0000000000000000000000000000000000000000..c3059ca32ec9945722d9cf14f379e26e0cb25cb0 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CellDifferences.lean @@ -0,0 +1,268 @@ +import OAI.Probability.RadialTransition.CroppedCells + +namespace OAI + +universe uX uY uI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +lemma if_zero_sub (p : Prop) [Decidable p] (a b : ℝ) : + (if p then 0 else a-b) = (if p then 0 else a) - (if p then 0 else b) := by + split_ifs <;> simp + +lemma pairWithin_sub {X : Type uX} (v w : X → X → ℝ) (s : ParticleState X) : + pairWithin (fun x y => v x y-w x y) s = pairWithin v s - pairWithin w s := by + classical + unfold pairWithin + simp_rw [if_zero_sub] + simp_rw [Finset.sum_sub_distrib] + ring + +lemma pairBetween_sub {X : Type uX} {Y : Type uY} (v w : X → Y → ℝ) (s : ParticleState X) (t : ParticleState Y) : + pairBetween (fun x y => v x y-w x y) s t = pairBetween v s t - pairBetween w s t := by + unfold pairBetween + simp_rw [Finset.sum_sub_distrib] + +lemma pairWithin_abs_bound {X : Type uX} (v : X → X → ℝ) {K : ℝ} (hK : 0 ≤ K) + (hv : ∀ x y, |v x y| ≤ K) (s : ParticleState X) : + |pairWithin v s| ≤ (1/2:ℝ) * (K * particleCount s * particleCount s) := by + classical + unfold pairWithin + rw [abs_mul, abs_of_pos (by norm_num : (0:ℝ) < 1/2)] + apply mul_le_mul_of_nonneg_left _ (by norm_num) + calc + |∑ i : Fin s.1, ∑ j : Fin s.1, if i = j then 0 else v (s.2 i) (s.2 j)| ≤ + ∑ i : Fin s.1, ∑ j : Fin s.1, |if i = j then 0 else v (s.2 i) (s.2 j)| := + (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun _ _ => Finset.abs_sum_le_sum_abs _ _)) + _ ≤ ∑ i : Fin s.1, ∑ j : Fin s.1, K := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + split_ifs + · simpa only [abs_zero] using hK + · exact hv _ _ + _ = _ := by simp [particleCount]; ring + +lemma pairBetween_abs_bound {X : Type uX} {Y : Type uY} (v : X → Y → ℝ) {K : ℝ} + (hv : ∀ x y, |v x y| ≤ K) (s : ParticleState X) (t : ParticleState Y) : + |pairBetween v s t| ≤ K * particleCount s * particleCount t := by + unfold pairBetween + calc + |∑ i : Fin s.1, ∑ j : Fin t.1, v (s.2 i) (t.2 j)| ≤ + ∑ i : Fin s.1, ∑ j : Fin t.1, |v (s.2 i) (t.2 j)| := + (Finset.abs_sum_le_sum_abs _ _).trans (Finset.sum_le_sum (fun _ _ => Finset.abs_sum_le_sum_abs _ _)) + _ ≤ ∑ i : Fin s.1, ∑ j : Fin t.1, K := + Finset.sum_le_sum (fun i _ => Finset.sum_le_sum (fun j _ => hv _ _)) + _ = _ := by simp [particleCount]; ring + +lemma double_sum_diagonal {I : Type uI} [Fintype I] [DecidableEq I] (a : I → I → ℝ) : + (∑ i, ∑ j, a i j) = ∑ i, a i i + ∑ i, ∑ j, if i = j then 0 else a i j := by + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + conv_lhs => + arg 2; ext j + rw [show a i j = (if i = j then a i j else 0) + (if i = j then 0 else a i j) by split_ifs <;> simp] + simp only [Finset.sum_add_distrib, Finset.sum_ite_eq, Finset.mem_univ, ite_true] + +section CellDifferences +variable {I : Type uI} [Fintype I] [DecidableEq I] {X : I → Type uX} + +lemma pairCellEnergy_sub (v w : ∀ i j, X i → X j → ℝ) (x : ∀ i, ParticleState (X i)) : + pairCellEnergy (fun i j a b => v i j a b-w i j a b) x = pairCellEnergy v x-pairCellEnergy w x := by + unfold pairCellEnergy cellHamiltonian + simp_rw [pairWithin_sub, pairBetween_sub, if_zero_sub, Finset.sum_sub_distrib] + ring + +lemma pairCellEnergy_abs_bound (v : ∀ i j, X i → X j → ℝ) (K : I → I → ℝ) + (hK : ∀ i j, 0 ≤ K i j) (hv : ∀ i j a b, |v i j a b| ≤ K i j) + (x : ∀ i, ParticleState (X i)) : + |pairCellEnergy v x| ≤ (1/2:ℝ) * ∑ i, ∑ j, K i j * cellN i x * cellN j x := by + let a i j := K i j * cellN i x * cellN j x + have hi : (∑ i, |pairWithin (v i i) (x i)|) ≤ (1/2:ℝ) * ∑ i, a i i := by + rw [Finset.mul_sum] + exact Finset.sum_le_sum (fun i _ => pairWithin_abs_bound _ (hK i i) (hv i i) (x i)) + have hc : (∑ i, ∑ j, |if i = j then 0 else pairBetween (v i j) (x i) (x j)|) ≤ + ∑ i, ∑ j, if i = j then 0 else a i j := by + apply Finset.sum_le_sum + intro i _ + apply Finset.sum_le_sum + intro j _ + split_ifs + · simp + · exact pairBetween_abs_bound _ (hv i j) _ _ + unfold pairCellEnergy cellHamiltonian + calc + _ ≤ |∑ i, pairWithin (v i i) (x i)| + + |(1/2:ℝ) * ∑ i, ∑ j, if i = j then 0 else pairBetween (v i j) (x i) (x j)| := abs_add_le _ _ + _ ≤ (∑ i, |pairWithin (v i i) (x i)|) + (1/2:ℝ) * + ∑ i, ∑ j, |if i = j then 0 else pairBetween (v i j) (x i) (x j)| := by + rw [abs_mul, abs_of_pos (by norm_num : (0:ℝ) < 1/2)] + apply add_le_add (Finset.abs_sum_le_sum_abs _ _) + apply mul_le_mul_of_nonneg_left _ (by norm_num) + exact (Finset.abs_sum_le_sum_abs _ _).trans + (Finset.sum_le_sum (fun _ _ => Finset.abs_sum_le_sum_abs _ _)) + _ ≤ (1/2:ℝ) * ∑ i, a i i + (1/2:ℝ) * ∑ i, ∑ j, if i = j then 0 else a i j := + add_le_add hi (mul_le_mul_of_nonneg_left hc (by norm_num)) + _ = _ := by rw [← mul_add, ← double_sum_diagonal] + +lemma pairCellEnergy_abs_difference (v w : ∀ i j, X i → X j → ℝ) (K : I → I → ℝ) + (hK : ∀ i j, 0 ≤ K i j) (hv : ∀ i j a b, |v i j a b-w i j a b| ≤ K i j) + (x : ∀ i, ParticleState (X i)) : + |pairCellEnergy v x-pairCellEnergy w x| ≤ (1/2:ℝ) * ∑ i, ∑ j, K i j * cellN i x * cellN j x := by + rw [← pairCellEnergy_sub] + exact pairCellEnergy_abs_bound _ K hK hv x + +end CellDifferences +section PhysicalControl +variable {I : Type uI} [Fintype I] [DecidableEq I] {X : I → Type uX} + +lemma pairCell_quadratic_bound + (pos : ∀ i, X i → Position) (hdiam : ∀ i x y, dist (pos i x) (pos i y) ≤ 1) + {t : ℝ} (ht : 0 ≤ t) (v : ∀ i j, X i → X j → ℝ) + (J : I → I → ℝ) (hJ : ∀ i j, 0 ≤ J i j) (hJsym : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J i j ≤ t^2/8) + (hintra : ∀ i x y, corePotential t (nndist (pos i x) (pos i y)) - J i i ≤ v i i x y) + (hcross : ∀ i j x y, -J i j ≤ v i j x y) (x : ∀ i, ParticleState (X i)) : + (t^2/8)/2 * ∑ i, (cellN i x)^2 - (t^2/2) * ∑ i, cellN i x ≤ pairCellEnergy v x := by + apply cellHamiltonian_stable (fun i => pairWithin (v i i)) (fun i j => pairBetween (v i j)) + (fun _ s => particleCount s) (fun _ _ => Nat.cast_nonneg _) J hJ hJsym (by positivity) hrow + · intro i s + exact pairWithin_core ht (hJ i i) (pos i) (hdiam i) (v i i) (hintra i) s + · intro i j s r + exact pairBetween_lower (v i j) (hcross i j) s r + +variable [∀ i, TopologicalSpace (X i)] [∀ i, MeasurableSpace (X i)] + [∀ i, BorelSpace (X i)] [∀ i, SecondCountableTopology (X i)] + +omit [DecidableEq I] in +lemma cell_boltzmann_integrable (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (z : ℝ) {D B : ℝ} (hD : 0 ≤ D) {E : (∀ i, ParticleState (X i)) → ℝ} + (hE : Measurable E) + (hstable : ∀ x, D/2 * ∑ i, (cellN i x)^2 - B * ∑ i, cellN i x ≤ E x) : + Integrable (fun x => Real.exp (-E x)) (Measure.pi (fun i => particleBase (ν i) z)) := by + simpa only [zero_sub] using integrable_cell_numerator ν z hE measurable_const hstable + (f := fun _ => 0) (fun x => mul_nonneg (by positivity) (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) + +omit [DecidableEq I] in +lemma cell_exponential_integrable (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (z : ℝ) {D B : ℝ} (hD : 0 ≤ D) {E : (∀ i, ParticleState (X i)) → ℝ} + (hE : Measurable E) + (hstable : ∀ x, D/2 * ∑ i, (cellN i x)^2 - B * ∑ i, cellN i x ≤ E x) (i : I) : + Integrable (fun x => Real.exp (D/4*(cellN i x)^2)) + (boltzmannMeasure (Measure.pi (fun j => particleBase (ν j) z)) E) := by + have hp := cell_partition_pos ν z (cell_boltzmann_integrable ν z hD hE hstable) + apply integrable_boltzmann hE _ hp + have hbound (x : ∀ j, ParticleState (X j)) : D/4*(cellN i x)^2 ≤ D/2*∑ j, (cellN j x)^2 := by + have hh := Finset.single_le_sum (s := Finset.univ) (f := fun j => (cellN j x)^2) + (fun _ _ => sq_nonneg _) (Finset.mem_univ i) + nlinarith [mul_nonneg hD (sq_nonneg (cellN i x)), mul_le_mul_of_nonneg_left hh hD] + have hi := integrable_cell_numerator ν z hE (measurable_const.mul ((measurable_cellN i).pow_const 2)) + hstable hbound + convert hi using 1 + ext x + rw [← Real.exp_add] + congr 1 + dsimp only [Pi.mul_apply] + ring + +lemma pairCell_second_moment [Nonempty I] + (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (pos : ∀ i, X i → Position) (hdiam : ∀ i x y, dist (pos i x) (pos i y) ≤ 1) + {t β V z : ℝ} (ht : 0 < t) (hβ : 0 < β) (hV : 0 ≤ V) + (hvol : ∀ i, (ν i univ).toReal ≤ V) + (v : ∀ i j, X i → X j → ℝ) (hv : ∀ i j, Continuous (Function.uncurry (v i j))) + (hvsym : ∀ i j x y, v i j x y = v j i y x) + (J : I → I → ℝ) (hJ : ∀ i j, 0 ≤ J i j) (hJsym : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J i j ≤ (t^2/8)/8) + (hintra : ∀ i x y, corePotential t (nndist (pos i x) (pos i y)) - J i i ≤ v i i x y) + (hcross : ∀ i j x y, -J i j ≤ v i j x y) : + let μ := Measure.pi (fun j => particleBase (ν j) z) + let E := fun x => β * pairCellEnergy v x + Integrable (fun x => Real.exp (-E x)) μ ∧ 0 < boltzmannPartition μ E ∧ + ∀ i, Integrable (fun x => (cellN i x)^2) (boltzmannMeasure μ E) ∧ + (∫ x, (cellN i x)^2 ∂boltzmannMeasure μ E) ≤ + Real.exp (16/15 * V * Real.exp (z+β*(t^2/2))) / (β*(t^2/8)/4) := by + dsimp only + have hD : 0 < β*(t^2/8) := by positivity + have hr (i : I) : ∑ j, J i j ≤ t^2/8 := (hrow i).trans (by nlinarith [sq_nonneg t]) + have hE : Measurable (fun x => β * pairCellEnergy v x) := + measurable_const.mul (continuous_pairCellEnergy v hv).measurable + have hstable (x : ∀ i, ParticleState (X i)) : + (β*(t^2/8))/2 * ∑ i, (cellN i x)^2 - (β*(t^2/2))*∑ i, cellN i x ≤ β*pairCellEnergy v x := by + have hh := mul_le_mul_of_nonneg_left + (pairCell_quadratic_bound pos hdiam ht.le v J hJ hJsym hr hintra hcross x) hβ.le + convert hh using 1; first | rfl | ring + have hi := cell_boltzmann_integrable ν z hD.le hE hstable + refine ⟨hi, cell_partition_pos ν z hi, fun i => ?_⟩ + exact secondMoment_of_exponential (measurable_cellN i) (by positivity) + (cell_exponential_integrable ν z hD.le hE hstable i) + (pairCell_exponential_moment ν pos hdiam ht hβ hV hvol v hv hvsym J hJ hJsym hrow hintra hcross i) + +theorem pairCell_log_perturbation [Nonempty I] + (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (pos : ∀ i, X i → Position) (hdiam : ∀ i x y, dist (pos i x) (pos i y) ≤ 1) + {t β V z : ℝ} (ht : 0 < t) (hβ : 0 < β) (hV : 0 ≤ V) + (hvol : ∀ i, (ν i univ).toReal ≤ V) + (v w : ∀ i j, X i → X j → ℝ) + (hv : ∀ i j, Continuous (Function.uncurry (v i j))) + (hw : ∀ i j, Continuous (Function.uncurry (w i j))) + (hvsym : ∀ i j x y, v i j x y = v j i y x) + (hwsym : ∀ i j x y, w i j x y = w j i y x) + (J : I → I → ℝ) (hJ : ∀ i j, 0 ≤ J i j) (hJsym : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J i j ≤ (t^2/8)/8) + (hintrav : ∀ i x y, corePotential t (nndist (pos i x) (pos i y)) - J i i ≤ v i i x y) + (hcrossv : ∀ i j x y, -J i j ≤ v i j x y) + (hintraw : ∀ i x y, corePotential t (nndist (pos i x) (pos i y)) - J i i ≤ w i i x y) + (hcrossw : ∀ i j x y, -J i j ≤ w i j x y) + (K : I → I → ℝ) (hK : ∀ i j, 0 ≤ K i j) + (hd : ∀ i j a b, |w i j a b-v i j a b| ≤ K i j) : + let μ := Measure.pi (fun i => particleBase (ν i) z) + |Real.log (boltzmannPartition μ (fun x => β*pairCellEnergy v x)) - + Real.log (boltzmannPartition μ (fun x => β*pairCellEnergy w x))| ≤ + β/2 * (Real.exp (16/15 * V * Real.exp (z+β*(t^2/2))) / (β*(t^2/8)/4)) * ∑ i, ∑ j, K i j := by + dsimp only + have hvdata := pairCell_second_moment (z := z) ν pos hdiam ht hβ hV hvol v hv hvsym J hJ hJsym hrow hintrav hcrossv + have hwdata := pairCell_second_moment (z := z) ν pos hdiam ht hβ hV hvol w hw hwsym J hJ hJsym hrow hintraw hcrossw + let K' i j := β/2*K i j + have hd' (x : ∀ i, ParticleState (X i)) : + |β*pairCellEnergy w x-β*pairCellEnergy v x| ≤ ∑ i, ∑ j, K' i j * cellN i x * cellN j x := by + rw [← mul_sub, abs_mul, abs_of_pos hβ] + calc + _ ≤ β*((1/2:ℝ)*∑ i, ∑ j, K i j*cellN i x*cellN j x) := + mul_le_mul_of_nonneg_left (pairCellEnergy_abs_difference w v K hK hd x) hβ.le + _ = _ := by + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + dsimp [K'] + ring + have hh := log_partition_perturbation (E := fun x => β*pairCellEnergy v x) (F := fun x => β*pairCellEnergy w x) + (measurable_const.mul (continuous_pairCellEnergy v hv).measurable) + (measurable_const.mul (continuous_pairCellEnergy w hw).measurable) + hvdata.1 hwdata.1 hvdata.2.1 hwdata.2.1 (cellN (X := X)) measurable_cellN + K' (fun i j => mul_nonneg (by positivity) (hK i j)) + (fun i => (hvdata.2.2 i).1) (fun i => (hwdata.2.2 i).1) + (fun i => (hvdata.2.2 i).2) (fun i => (hwdata.2.2 i).2) hd' + have hs : (∑ i, ∑ j, K' i j) = β/2*(∑ i, ∑ j, K i j) := by + simp only [K', Finset.mul_sum] + rw [hs] at hh + simpa only [Pi.mul_apply, mul_assoc, mul_left_comm, mul_comm] using hh + +end PhysicalControl + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CellIntegral.lean b/lean/OAI/Probability/RadialTransition/CellIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..89d60b77b44d2182cb13efd76ab1917e3529b3f0 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CellIntegral.lean @@ -0,0 +1,113 @@ +import OAI.Probability.RadialTransition.StarIntegral + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma cluster_rate_le {h α : ℝ} (h1 : h ≤ α) (h4 : 4*h-9 ≤ α) + {n : ℕ} (hn : n ≤ 3) : h*(n+1)-3*n ≤ α := by + have hn0 : (0:ℝ) ≤ n := Nat.cast_nonneg n + have hn3 : (n:ℝ) ≤ 3 := by exact_mod_cast hn + by_cases hh : h ≤ 3 + · nlinarith [mul_nonneg hn0 (sub_nonneg.mpr hh)] + · nlinarith [mul_nonneg (sub_nonneg.mpr hn3) (sub_nonneg.mpr (le_of_not_ge hh))] + +lemma core_cluster_coefficient_bound {t h α : ℝ} (ht : 0 ≤ t) + (h1 : h ≤ α) (h4 : 4*h-9 ≤ α) {n : ℕ} (hn : n ≤ 3) : + Real.exp (t*h*(n+1))/(n+1).factorial * Real.exp (-t*α) * + ((n+1)*((2*((1+(1:ℝ)/1000)*microLength t))^3)^n) ≤ 3000 := by + have hl := (microLength_pos t).le + have hfac : (1:ℝ) ≤ (n+1).factorial := by exact_mod_cast (Nat.succ_le_of_lt (Nat.factorial_pos (n+1))) + have he : Real.exp (t*h*(n+1))*Real.exp (-t*α)* + (((2*((1+(1:ℝ)/1000)*microLength t))^3)^n) = + Real.exp (t*(h*(n+1)-3*n-α))*((2*(1+(1:ℝ)/1000))^3)^n := by + have hbase : 2*((1+(1:ℝ)/1000)*microLength t) = (2*(1+(1:ℝ)/1000))*microLength t := by ring + rw [hbase, mul_pow, mul_pow] + have hexp : (microLength t^3)^n = Real.exp ((n:ℝ)*(3*(-t))) := by + simp only [microLength, ← Real.exp_nat_mul, Nat.cast_ofNat] + rw [hexp] + calc + _ = (Real.exp (t*h*(n+1))*Real.exp (-t*α)*Real.exp ((n:ℝ)*(3*(-t))))* + ((2*(1+(1:ℝ)/1000))^3)^n := by ring + _ = _ := by + rw [← Real.exp_add, ← Real.exp_add] + congr 2 + ring + have hrate : Real.exp (t*(h*(n+1)-3*n-α)) ≤ 1 := by + rw [Real.exp_le_one_iff] + exact mul_nonpos_of_nonneg_of_nonpos ht (sub_nonpos.mpr (cluster_rate_le h1 h4 hn)) + have hpow : (n+1:ℝ)*((2*(1+(1:ℝ)/1000))^3)^n ≤ 3000 := by + interval_cases n <;> norm_num + calc + _ ≤ Real.exp (t*h*(n+1))*Real.exp (-t*α)* + (((2*((1+(1:ℝ)/1000)*microLength t))^3)^n)*(n+1) := by + have hc : Real.exp (t*h*(n+1))/(n+1).factorial ≤ Real.exp (t*h*(n+1)) := + div_le_self (Real.exp_pos _).le hfac + nlinarith [mul_le_mul_of_nonneg_right hc + (mul_nonneg (Real.exp_pos (-t*α)).le + (mul_nonneg (show (0:ℝ) ≤ n+1 by positivity) (by positivity : 0 ≤ ((2*((1+(1:ℝ)/1000)*microLength t))^3)^n)))] + _ = Real.exp (t*(h*(n+1)-3*n-α))*(((2*(1+(1:ℝ)/1000))^3)^n)*(n+1) := by rw [he] + _ ≤ _ := by + nlinarith [mul_le_mul_of_nonneg_right hrate + (mul_nonneg (by positivity : 0 ≤ ((2*(1+(1:ℝ)/1000))^3)^n) (show (0:ℝ) ≤ n+1 by positivity))] + +lemma lintegral_cellClusterWeight_sector {t α r : ℝ} (hr : 0 ≤ r) (k : Cell) + {n : ℕ} (hn : n ≤ 3) : + (∫⁻ x : Fin (n+1) → Position, cellClusterWeight t α r k (configurationMultiset x) + ∂Measure.pi (fun _ => volume)) = + ENNReal.ofReal (Real.exp (-t*α))*((n+1 : ℕ)*(volume (gridRegion k)*(ENNReal.ofReal (2*r)^3)^n)) := by + have hn4 : n+1 ≤ 4 := by omega + simp only [cellClusterWeight, emptyWeight, configurationMultiset_card, Fintype.card_fin, + Nat.add_eq_zero_iff, Nat.one_ne_zero, and_false, ite_false, ite_eq_left hn4, zero_add] + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, lintegral_starWeight _ (measurableSet_gridRegion _) hr] + +lemma particleBase_cellClusterWeight_le {t h α : ℝ} (ht : 0 ≤ t) + (h1 : h ≤ α) (h4 : 4*h-9 ≤ α) (k : Cell) : + (∫⁻ x, cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k (particleMultiset x) + ∂particleBase volume (t*h)) ≤ 15001 := by + have hl := (microLength_pos t).le + have hm := measurable_particleObservable _ (measurable_cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k) 0 + simp only [zero_add] at hm + rw [lintegral_particleBase _ _ hm] + have hz (n : ℕ) (hn : n ∉ Finset.range 5) : + ENNReal.ofReal (Real.exp (t*h*n)/n.factorial)* + (∫⁻ x : Fin n → Position, cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k (particleMultiset ⟨n,x⟩) + ∂Measure.pi (fun _ => volume)) = 0 := by + have hn4 : ¬n ≤ 4 := by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hn + have hn0 : n ≠ 0 := by omega + simp [particleMultiset, cellClusterWeight, emptyWeight, configurationMultiset_card, hn4, hn0] + rw [tsum_eq_sum hz] + have hterm (n : ℕ) (hn : n ∈ Finset.range 5) : + ENNReal.ofReal (Real.exp (t*h*n)/n.factorial)* + (∫⁻ x : Fin n → Position, cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k (particleMultiset ⟨n,x⟩) + ∂Measure.pi (fun _ => volume)) ≤ 3000 := by + rcases n with _|n + · norm_num [particleMultiset, cellClusterWeight, emptyWeight, starWeight, configurationMultiset, Finset.univ_eq_empty] + have hn3 : n ≤ 3 := by have := Finset.mem_range.mp hn; omega + change ENNReal.ofReal _ * (∫⁻ x : Fin (n+1) → Position, + cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k (configurationMultiset x) ∂Measure.pi (fun _ => volume)) ≤ _ + rw [lintegral_cellClusterWeight_sector (by positivity) k hn3] + have hv : volume (gridRegion k) ≤ (1:ℝ≥0∞) := + (volume_gridRegion_le k).trans (by norm_num) + apply le_trans (mul_le_mul' le_rfl (mul_le_mul' le_rfl (mul_le_mul' le_rfl (mul_le_mul' hv le_rfl)) )) + simp only [one_mul] + rw [← ENNReal.ofReal_pow (by positivity : 0 ≤ 2*((1+(1:ℝ)/1000)*microLength t)), + ← ENNReal.ofReal_pow (by positivity : 0 ≤ (2*((1+(1:ℝ)/1000)*microLength t))^3)] + have hnat : ((n+1:ℕ):ℝ≥0∞) = ENNReal.ofReal ((n+1:ℕ):ℝ) := by norm_cast + rw [hnat, ← ENNReal.ofReal_mul (by positivity), ← ENNReal.ofReal_mul (by positivity), ← ENNReal.ofReal_mul (by positivity)] + have hb := ENNReal.ofReal_le_ofReal (core_cluster_coefficient_bound ht h1 h4 hn3) + norm_num only [ENNReal.ofReal_ofNat, Nat.cast_add, Nat.cast_one] at hb ⊢ + convert hb using 1 + congr 1 + ring + calc + _ ≤ ∑ _n ∈ Finset.range 5, (3000:ℝ≥0∞) := Finset.sum_le_sum hterm + _ ≤ 15001 := by norm_num + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CellInteractions.lean b/lean/OAI/Probability/RadialTransition/CellInteractions.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d9ede011cd93d92988c4bda530dd162677ab5a5 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CellInteractions.lean @@ -0,0 +1,367 @@ +import OAI.Probability.RadialTransition.CellMoments + +namespace OAI + +universe uI uX uY uZ + +noncomputable section + + +open MeasureTheory Filter Set + +open scoped ContDiff BigOperators NNReal ENNReal + +namespace RadialTransition + +section AbstractCells +variable {I : Type uI} [Fintype I] [DecidableEq I] {X : I → Type uX} + +def cellHamiltonian (U : ∀ i, X i → ℝ) (W : ∀ i j, X i → X j → ℝ) + (x : ∀ i, X i) : ℝ := + ∑ i, U i (x i) + (1/2:ℝ) * ∑ i, ∑ j, if i = j then 0 else W i j (x i) (x j) + +lemma double_sum_update (w : ∀ i j, X i → X j → ℝ) + (hdiag : ∀ i a b, w i i a b = 0) + (hsym : ∀ i j a b, w i j a b = w j i b a) + (x : ∀ i, X i) (k : I) (s t : X k) : + (∑ i, ∑ j, w i j (Function.update x k s i) (Function.update x k s j)) - + (∑ i, ∑ j, w i j (Function.update x k t i) (Function.update x k t j)) = + 2 * ∑ j, (w k j s (x j) - w k j t (x j)) := by + have hpoint (i j : I) : + w i j (Function.update x k s i) (Function.update x k s j) - + w i j (Function.update x k t i) (Function.update x k t j) = + (if i = k then w k j s (x j) - w k j t (x j) else 0) + + (if j = k then w i k (x i) s - w i k (x i) t else 0) := by + by_cases hi : i = k + · subst i + by_cases hj : j = k + · subst j; simp [hdiag] + · simp [hj, Function.update_of_ne] + · by_cases hj : j = k + · subst j; simp [hi, Function.update_of_ne] + · simp [hi, hj, Function.update_of_ne] + simp_rw [← Finset.sum_sub_distrib, hpoint, Finset.sum_add_distrib] + simp only [Finset.sum_ite_irrel, Finset.sum_const_zero, Finset.sum_ite_eq', Finset.mem_univ, + ite_true] + conv_lhs => arg 2; arg 2; intro i; rw [hsym i k (x i) s, hsym i k (x i) t] + ring + +lemma cellHamiltonian_update (U : ∀ i, X i → ℝ) (W : ∀ i j, X i → X j → ℝ) + (vac : ∀ i, X i) (hU0 : ∀ i, U i (vac i) = 0) + (hW0 : ∀ i j a, W i j (vac i) a = 0) + (hsym : ∀ i j a b, W i j a b = W j i b a) + (x : ∀ i, X i) (k : I) (s : X k) : + cellHamiltonian U W (Function.update x k s) - + cellHamiltonian U W (Function.update x k (vac k)) = + U k s + ∑ j, if k = j then 0 else W k j s (x j) := by + let w (i j : I) (a : X i) (b : X j) := if i = j then 0 else W i j a b + have hwsym (i j : I) (a : X i) (b : X j) : w i j a b = w j i b a := by + dsimp [w] + by_cases h : i = j + · simp [h] + · simp [h, Ne.symm h, hsym i j a b] + have hh := double_sum_update w (by simp [w]) hwsym x k s (vac k) + have hu : (∑ i, U i (Function.update x k s i)) - + (∑ i, U i (Function.update x k (vac k) i)) = U k s := by + rw [← Finset.sum_sub_distrib] + have he (i : I) : U i (Function.update x k s i) - U i (Function.update x k (vac k) i) = + if i = k then U k s else 0 := by + by_cases hi : i = k + · subst i; simp [hU0] + · simp [hi, Function.update_of_ne] + simp_rw [he] + simp + have hz (j : I) : w k j (vac k) (x j) = 0 := by simp [w, hW0] + simp only [hz, sub_zero] at hh + change (∑ i, U i (Function.update x k s i)) + 1/2 * (∑ i, ∑ j, w i j _ _) - + ((∑ i, U i (Function.update x k (vac k) i)) + 1/2 * (∑ i, ∑ j, w i j _ _)) = _ + dsimp only [w] at hh + linarith + +lemma cellHamiltonian_stable (U : ∀ i, X i → ℝ) (W : ∀ i j, X i → X j → ℝ) + (n : ∀ i, X i → ℝ) (_hn : ∀ i x, 0 ≤ n i x) + (J : I → I → ℝ) (hJ : ∀ i j, 0 ≤ J i j) (hJsym : ∀ i j, J i j = J j i) + {D B : ℝ} (_hD : 0 ≤ D) (hrow : ∀ i, ∑ j, J i j ≤ D) + (hU : ∀ i a, D * (n i a)^2 - B * n i a - J i i/2 * (n i a)^2 ≤ U i a) + (hW : ∀ i j a b, -J i j * n i a * n j b ≤ W i j a b) + (x : ∀ i, X i) : + D/2 * ∑ i, (n i (x i))^2 - B * ∑ i, n i (x i) ≤ cellHamiltonian U W x := by + have hb := symmetric_row_quadratic J (fun i => n i (x i)) D hJ hJsym hrow + have hu := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hU i (x i)) + have hw := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + Finset.sum_le_sum (s := Finset.univ) (fun j _ => show + (if i = j then 0 else -J i j * n i (x i) * n j (x j)) ≤ + (if i = j then 0 else W i j (x i) (x j)) from by split_ifs; rfl; exact hW i j _ _)) + have hsplit : (∑ i, ∑ j, J i j * n i (x i) * n j (x j)) = + (∑ i, J i i * (n i (x i))^2) + + ∑ i, ∑ j, if i = j then 0 else J i j * n i (x i) * n j (x j) := by + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro i _ + have he (j : I) : J i j * n i (x i) * n j (x j) = + (if i = j then J i j * n i (x i) * n j (x j) else 0) + + (if i = j then 0 else J i j * n i (x i) * n j (x j)) := by split_ifs <;> simp + calc + _ = ∑ j, ((if i = j then J i j * n i (x i) * n j (x j) else 0) + + (if i = j then 0 else J i j * n i (x i) * n j (x j))) := + Finset.sum_congr rfl (fun j _ => he j) + _ = _ := by + rw [Finset.sum_add_distrib] + simp only [Finset.sum_ite_eq, Finset.mem_univ, ite_true] + congr 1 + ring + have hwneg : (∑ i, ∑ j, if i = j then 0 else -J i j * n i (x i) * n j (x j)) = + -(∑ i, ∑ j, if i = j then 0 else J i j * n i (x i) * n j (x j)) := by + simp only [← Finset.sum_neg_distrib] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + split_ifs <;> ring + rw [hwneg] at hw + simp only [Finset.sum_sub_distrib, ← Finset.mul_sum] at hu + have hd : (∑ i, J i i / 2 * (n i (x i))^2) = (1/2:ℝ) * ∑ i, J i i * (n i (x i))^2 := by + rw [Finset.mul_sum]; apply Finset.sum_congr rfl; intro i _; ring + rw [hd] at hu + unfold cellHamiltonian + linarith + +end AbstractCells + +section PairCells +variable {X : Type uX} {Y : Type uY} {Z : Type uZ} + +def pairWithin (v : X → X → ℝ) (s : ParticleState X) : ℝ := by + classical + exact (1/2:ℝ) * ∑ i : Fin s.1, ∑ j : Fin s.1, if i = j then 0 else v (s.2 i) (s.2 j) + +def pairBetween (v : X → Y → ℝ) (s : ParticleState X) (t : ParticleState Y) : ℝ := + ∑ i : Fin s.1, ∑ j : Fin t.1, v (s.2 i) (t.2 j) + +@[simp] theorem pairWithin_vacuum (v : X → X → ℝ) : pairWithin v particleVacuum = 0 := by + change (1/2:ℝ) * (∑ i : Fin 0, ∑ j : Fin 0, if i = j then 0 else v (Fin.elim0 i) (Fin.elim0 j)) = 0 + rw [Fin.sum_univ_zero, mul_zero] + +@[simp] theorem pairBetween_vacuum (v : X → Y → ℝ) (t : ParticleState Y) : + pairBetween v particleVacuum t = 0 := by + change (∑ i : Fin 0, ∑ j : Fin t.1, v (Fin.elim0 i) (t.2 j)) = 0 + rw [Fin.sum_univ_zero] + +theorem pairBetween_symm (v : X → Y → ℝ) (w : Y → X → ℝ) + (hv : ∀ x y, v x y = w y x) (s : ParticleState X) (t : ParticleState Y) : + pairBetween v s t = pairBetween w t s := by + unfold pairBetween + simp_rw [hv] + exact Finset.sum_comm + +lemma continuous_particle_prod [TopologicalSpace X] [TopologicalSpace Y] [TopologicalSpace Z] + {f : ParticleState X → ParticleState Y → Z} + (hf : ∀ m n, Continuous (fun p : (Fin m → X) × (Fin n → Y) => f ⟨m,p.1⟩ ⟨n,p.2⟩)) : + Continuous (Function.uncurry f) := by + let e := Homeomorph.sigmaProdDistrib (X := fun m : ℕ => Fin m → X) (Y := ParticleState Y) + have h : Continuous (fun q : Σ m : ℕ, (Fin m → X) × ParticleState Y => + f ⟨q.1,q.2.1⟩ q.2.2) := by + apply continuous_sigma + intro m + let e' := Homeomorph.sigmaProdDistrib (X := fun n : ℕ => Fin n → Y) (Y := Fin m → X) + have h' : Continuous (fun q : Σ n : ℕ, (Fin n → Y) × (Fin m → X) => + f ⟨m,q.2.2⟩ ⟨q.1,q.2.1⟩) := by + apply continuous_sigma + intro n + exact (hf m n).comp continuous_swap + exact (h'.comp e'.continuous).comp continuous_swap + exact h.comp e.continuous + +lemma continuous_pairWithin [TopologicalSpace X] (v : X → X → ℝ) + (hv : Continuous (Function.uncurry v)) : Continuous (pairWithin v) := by + apply continuous_sigma + intro n + change Continuous (fun a : Fin n → X => (1/2:ℝ) * + ∑ i : Fin n, ∑ j : Fin n, if i = j then 0 else v (a i) (a j)) + apply continuous_const.mul + apply continuous_finsetSum _ + intro i _ + apply continuous_finsetSum _ + intro j _ + split_ifs + · exact continuous_const + · exact hv.comp (show Continuous (fun a : Fin n → X => (a i, a j)) from + (continuous_apply i).prodMk (continuous_apply j)) + +lemma continuous_pairBetween [TopologicalSpace X] [TopologicalSpace Y] (v : X → Y → ℝ) + (hv : Continuous (Function.uncurry v)) : Continuous (Function.uncurry (pairBetween v)) := by + apply continuous_particle_prod + intro m n + change Continuous (fun p : (Fin m → X) × (Fin n → Y) => + ∑ i : Fin m, ∑ j : Fin n, v (p.1 i) (p.2 j)) + apply continuous_finsetSum _ + intro i _ + apply continuous_finsetSum _ + intro j _ + exact hv.comp (show Continuous (fun p : (Fin m → X) × (Fin n → Y) => (p.1 i, p.2 j)) from + ((continuous_apply i).comp continuous_fst).prodMk ((continuous_apply j).comp continuous_snd)) + +lemma pairBetween_lower (v : X → Y → ℝ) {J : ℝ} (hv : ∀ x y, -J ≤ v x y) + (s : ParticleState X) (t : ParticleState Y) : + -J * particleCount s * particleCount t ≤ pairBetween v s t := by + have hh := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + Finset.sum_le_sum (s := Finset.univ) (fun j _ => hv (s.2 i) (t.2 j))) + simpa only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, + pairBetween, particleCount, mul_comm, mul_left_comm] using hh + +lemma pairWithin_perturb_lower (v w : X → X → ℝ) {J : ℝ} (hJ : 0 ≤ J) + (hv : ∀ x y, w x y - J ≤ v x y) (s : ParticleState X) : + pairWithin w s - J/2 * (particleCount s : ℝ)^2 ≤ pairWithin v s := by + classical + have hp (i j : Fin s.1) : + (if i = j then 0 else w (s.2 i) (s.2 j)) - J ≤ + (if i = j then 0 else v (s.2 i) (s.2 j)) := by + split_ifs + · linarith + · exact hv _ _ + have hh := Finset.sum_le_sum (s := Finset.univ) (fun i _ => + Finset.sum_le_sum (s := Finset.univ) (fun j _ => hp i j)) + simp only [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul] at hh + unfold pairWithin particleCount + nlinarith + +lemma pairWithin_core {t J : ℝ} (ht : 0 ≤ t) (hJ : 0 ≤ J) + (pos : X → Position) (hdiam : ∀ x y, dist (pos x) (pos y) ≤ 1) + (v : X → X → ℝ) (hv : ∀ x y, corePotential t (nndist (pos x) (pos y)) - J ≤ v x y) + (s : ParticleState X) : + t^2/8 * (particleCount s : ℝ)^2 - t^2/2 * particleCount s - + J/2 * (particleCount s : ℝ)^2 ≤ pairWithin v s := by + have hh := pairWithin_perturb_lower v (fun x y => corePotential t (nndist (pos x) (pos y))) hJ hv s + have hc := core_ordered_lower_small_diameter ht (fun i : Fin s.1 => pos (s.2 i)) + (fun i j => hdiam _ _) + simp only [Fintype.card_fin, ne_eq, ite_not] at hc + dsimp only [pairWithin, corePotential, particleCount] at hh + change (1/2:ℝ) * (∑ i : Fin s.1, ∑ j : Fin s.1, + if i = j then 0 else coreReal t (dist (pos (s.2 i)) (pos (s.2 j)))) - _ ≤ _ at hh + dsimp only [particleCount, pairWithin] + linarith + +end PairCells + +section PhysicalCells +variable {I : Type uI} [Fintype I] [DecidableEq I] {X : I → Type uX} + [∀ i, TopologicalSpace (X i)] [∀ i, MeasurableSpace (X i)] + [∀ i, BorelSpace (X i)] [∀ i, SecondCountableTopology (X i)] + +def pairCellEnergy (v : ∀ i j, X i → X j → ℝ) (x : ∀ i, ParticleState (X i)) : ℝ := + cellHamiltonian (fun i => pairWithin (v i i)) (fun i j => pairBetween (v i j)) x + +omit [∀ i, MeasurableSpace (X i)] [∀ i, BorelSpace (X i)] + [∀ i, SecondCountableTopology (X i)] in +lemma continuous_pairCellEnergy (v : ∀ i j, X i → X j → ℝ) + (hv : ∀ i j, Continuous (Function.uncurry (v i j))) : Continuous (pairCellEnergy v) := by + unfold pairCellEnergy cellHamiltonian + apply Continuous.add + · exact continuous_finsetSum _ (fun i _ => (continuous_pairWithin _ (hv i i)).comp (continuous_apply i)) + · apply continuous_const.mul + apply continuous_finsetSum _ + intro i _ + apply continuous_finsetSum _ + intro j _ + split_ifs + · exact continuous_const + · exact (continuous_pairBetween _ (hv i j)).comp + (show Continuous (fun x : ∀ i, ParticleState (X i) => (x i, x j)) from + (continuous_apply i).prodMk (continuous_apply j)) + +theorem pairCell_exponential_moment [Nonempty I] + (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (pos : ∀ i, X i → Position) (hdiam : ∀ i x y, dist (pos i x) (pos i y) ≤ 1) + {t β V z : ℝ} (ht : 0 < t) (hβ : 0 < β) (hV : 0 ≤ V) + (hvol : ∀ i, (ν i univ).toReal ≤ V) + (v : ∀ i j, X i → X j → ℝ) (hv : ∀ i j, Continuous (Function.uncurry (v i j))) + (hvsym : ∀ i j x y, v i j x y = v j i y x) + (J : I → I → ℝ) (hJ : ∀ i j, 0 ≤ J i j) (hJsym : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J i j ≤ (t^2/8)/8) + (hintra : ∀ i x y, corePotential t (nndist (pos i x) (pos i y)) - J i i ≤ v i i x y) + (hcross : ∀ i j x y, -J i j ≤ v i j x y) : + ∀ i, (∫ x, Real.exp (β*(t^2/8)/4 * (cellN i x)^2) + ∂boltzmannMeasure (Measure.pi (fun j => particleBase (ν j) z)) + (fun x => β * pairCellEnergy v x)) ≤ + Real.exp (16/15 * V * Real.exp (z+β*(t^2/2))) := by + let D := t^2/8 + let B := t^2/2 + have hD : 0 < D := by dsimp [D]; positivity + let U (i : I) := pairWithin (v i i) + let W (i j : I) := pairBetween (v i j) + have hU (i : I) (s : ParticleState (X i)) : + D * (particleCount s : ℝ)^2 - B * particleCount s - J i i/2*(particleCount s : ℝ)^2 ≤ U i s := + pairWithin_core ht.le (hJ i i) (pos i) (hdiam i) (v i i) (hintra i) s + have hW (i j : I) (s : ParticleState (X i)) (r : ParticleState (X j)) : + -J i j * particleCount s * particleCount r ≤ W i j s r := + pairBetween_lower (v i j) (hcross i j) s r + have hrowD (i : I) : ∑ j, J i j ≤ D := (hrow i).trans (by dsimp [D]; nlinarith [sq_nonneg t]) + have hH (x : ∀ i, ParticleState (X i)) : + D/2 * ∑ i, (cellN i x)^2 - B * ∑ i, cellN i x ≤ pairCellEnergy v x := by + exact cellHamiltonian_stable U W (fun _ s => particleCount s) (fun _ _ => Nat.cast_nonneg _) + J hJ hJsym hD.le hrowD hU hW x + let θ (i j : I) := if i = j then 0 else 8*J i j/D + have hθ (i j : I) : 0 ≤ θ i j := by + dsimp [θ] + split_ifs + · rfl + · exact div_nonneg (mul_nonneg (by norm_num) (hJ i j)) hD.le + have hθrow (i : I) : ∑ j, θ i j ≤ 1 := by + have hle : ∑ j, θ i j ≤ 8/D * ∑ j, J i j := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro j _ + dsimp [θ] + split_ifs + · exact mul_nonneg (div_nonneg (by norm_num) hD.le) (hJ i j) + · exact le_of_eq (by ring) + refine hle.trans ?_ + calc + _ ≤ 8/D * (D/8) := mul_le_mul_of_nonneg_left (hrow i) (by positivity) + _ = 1 := by field_simp + have hcond (i : I) (x : ∀ j, ParticleState (X j)) (s : ParticleState (X i)) : + D/2 * (particleCount s : ℝ)^2 - B*particleCount s - + (particleCount s : ℝ)*(D/8 * ∑ j, θ i j * cellN j x) ≤ + pairCellEnergy v (Function.update x i s) - + pairCellEnergy v (Function.update x i particleVacuum) := by + rw [pairCellEnergy, pairCellEnergy, + cellHamiltonian_update _ _ (fun _ => particleVacuum) (by simp) + (by simp) (fun k j a b => pairBetween_symm _ _ (hvsym k j) a b)] + have hJi : J i i ≤ D := + (Finset.single_le_sum (fun j _ => hJ i j) (Finset.mem_univ i)).trans (hrowD i) + have hu := hU i s + have hsq := mul_nonneg (sub_nonneg.mpr hJi) (sq_nonneg (particleCount s : ℝ)) + have hw := Finset.sum_le_sum (s := Finset.univ) (fun j _ => show + (if i = j then 0 else -J i j * particleCount s * particleCount (x j)) ≤ + (if i = j then 0 else pairBetween (v i j) s (x j)) from by + split_ifs; rfl; exact hW i j s (x j)) + have he : (∑ j, if i = j then 0 else -J i j * particleCount s * particleCount (x j)) = + -(particleCount s : ℝ) * (D/8 * ∑ j, θ i j * cellN j x) := by + rw [Finset.mul_sum, Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + dsimp [θ, cellN] + split_ifs + · ring + · field_simp + rw [he] at hw + dsimp [U] at hu + linarith + apply uniform_cell_exponential_moment ν z (D := β*D) (B := β*B) + (E := fun x => β * pairCellEnergy v x) + (mul_pos hβ hD) hV hvol θ hθ (by simp [θ]) hθrow + (measurable_const.mul (continuous_pairCellEnergy v hv).measurable) + · intro x + have hh := mul_le_mul_of_nonneg_left (hH x) hβ.le + convert hh using 1; first | rfl | ring + · intro i x s + have hh := mul_le_mul_of_nonneg_left (hcond i x s) hβ.le + convert hh using 1 <;> first | rfl | ring + +end PhysicalCells +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CellMoments.lean b/lean/OAI/Probability/RadialTransition/CellMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..e2603d8c464e6e953a3afdaa5daa93778121fd3f --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CellMoments.lean @@ -0,0 +1,266 @@ +import OAI.Probability.RadialTransition.BoltzmannMeasure + +namespace OAI + +universe uX uI + +noncomputable section + + +open MeasureTheory Filter Set + +open scoped ContDiff BigOperators NNReal ENNReal + +namespace RadialTransition + +lemma cell_young {D G n : ℝ} (hD : 0 < D) : n * G ≤ D / 4 * n^2 + G^2 / D := by + have hh := sq_nonneg (D*n - 2*G) + have he : G^2 / D * D = G^2 := div_mul_cancel₀ _ hD.ne' + nlinarith + +theorem one_cell_exponential_moment {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] + [BorelSpace X] [SecondCountableTopology X] (ν : Measure X) [IsFiniteMeasure ν] + (z : ℝ) {β D B J G : ℝ} (hβ : 0 ≤ β) (hD : 0 < D) (hJ : J ≤ D) + {H : ParticleState X → ℝ} (hH : Measurable H) + (henergy : ∀ x, (D-J/2) * (particleCount x : ℝ)^2 - B*particleCount x - + (particleCount x : ℝ)*G ≤ H x - H particleVacuum) : + (∫⁻ x, ENNReal.ofReal (Real.exp (β*D/4*(particleCount x : ℝ)^2 - β*H x)) ∂particleBase ν z) ≤ + ENNReal.ofReal (Real.exp ((ν univ).toReal * Real.exp (z+β*B))) * + ENNReal.ofReal (Real.exp (β*G^2/D)) * + ∫⁻ x, ENNReal.ofReal (Real.exp (-β*H x)) ∂particleBase ν z := by + let A := Real.exp (β*G^2/D - β*H particleVacuum) + have hm : Measurable (fun x => ENNReal.ofReal (Real.exp (-β*H x))) := + (Real.measurable_exp.comp (measurable_const.mul hH)).ennreal_ofReal + have hlower : ENNReal.ofReal (Real.exp (-β*H particleVacuum)) ≤ + ∫⁻ x, ENNReal.ofReal (Real.exp (-β*H x)) ∂particleBase ν z := by + calc + _ = ∫⁻ x, ENNReal.ofReal (Real.exp (-β*H x)) ∂Measure.dirac particleVacuum := + (lintegral_dirac' _ hm).symm + _ ≤ _ := lintegral_mono' (dirac_vacuum_le_particleBase ν z) le_rfl + have hupper : (∫⁻ x, ENNReal.ofReal (Real.exp (β*D/4*(particleCount x : ℝ)^2 - β*H x)) ∂particleBase ν z) ≤ + ENNReal.ofReal A * ENNReal.ofReal (Real.exp ((ν univ).toReal * Real.exp (z+β*B))) := by + calc + _ ≤ ∫⁻ x, ENNReal.ofReal A * ENNReal.ofReal (Real.exp (β*B*particleCount x)) ∂particleBase ν z := by + apply lintegral_mono + intro x + dsimp only [A] + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← Real.exp_add] + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + have hy := cell_young (G := G) (n := (particleCount x : ℝ)) hD + have hj := mul_nonneg (sub_nonneg.mpr hJ) (sq_nonneg (particleCount x : ℝ)) + have he := mul_le_mul_of_nonneg_left (henergy x) hβ + have hy' := mul_le_mul_of_nonneg_left hy hβ + have hj' := mul_nonneg hβ hj + have heq : β * (G^2/D) = β*G^2/D := by ring + nlinarith + _ = _ := by rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, lintegral_exp_particleCount] + calc + _ ≤ _ := hupper + _ = ENNReal.ofReal (Real.exp ((ν univ).toReal * Real.exp (z+β*B))) * + ENNReal.ofReal (Real.exp (β*G^2/D)) * ENNReal.ofReal (Real.exp (-β*H particleVacuum)) := by + dsimp [A] + rw [sub_eq_add_neg, Real.exp_add, ENNReal.ofReal_mul (Real.exp_pos _).le] + rw [neg_mul] + ac_rfl + _ ≤ _ := mul_le_mul' le_rfl hlower + +section ProductCells +variable {I : Type uI} [Fintype I] {X : I → Type uX} + [∀ i, TopologicalSpace (X i)] [∀ i, MeasurableSpace (X i)] + [∀ i, BorelSpace (X i)] [∀ i, SecondCountableTopology (X i)] + +def cellN (i : I) (x : ∀ j, ParticleState (X j)) : ℝ := particleCount (x i) + +omit [Fintype I] [∀ i, BorelSpace (X i)] [∀ i, SecondCountableTopology (X i)] + [∀ i, TopologicalSpace (X i)] [∀ i, MeasurableSpace (X i)] in +theorem cellN_nonneg (i : I) (x : ∀ j, ParticleState (X j)) : 0 ≤ cellN i x := Nat.cast_nonneg _ + +omit [Fintype I] [∀ i, BorelSpace (X i)] [∀ i, SecondCountableTopology (X i)] + [∀ i, MeasurableSpace (X i)] in +theorem measurable_cellN (i : I) : Measurable (cellN (X := X) i) := + ((show Measurable (fun n : ℕ => (n : ℝ)) from continuous_of_discreteTopology.measurable).comp + continuous_particleCount.measurable).comp (measurable_pi_apply i) + +theorem integrable_exp_cell_total (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (z c : ℝ) : Integrable (fun x => Real.exp (c * ∑ i, cellN i x)) + (Measure.pi (fun i => particleBase (ν i) z)) := by + have hh := Integrable.fintype_prod_dep (fun i => integrable_exp_particleCount (ν i) z c) + convert hh using 1 + ext x + rw [Finset.mul_sum, Real.exp_sum] + rfl + +theorem cell_partition_pos (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (z : ℝ) {E : (∀ i, ParticleState (X i)) → ℝ} + (hi : Integrable (fun x => Real.exp (-E x)) (Measure.pi (fun i => particleBase (ν i) z))) : + 0 < boltzmannPartition (Measure.pi (fun i => particleBase (ν i) z)) E := by + apply (integral_pos_iff_support_of_nonneg (fun _ => (Real.exp_pos _).le) hi).mpr + have hs : Function.support (fun x => Real.exp (-E x)) = univ := by + ext x + simp [Function.support, Real.exp_ne_zero] + rw [hs] + rw [Measure.pi_univ] + apply pos_iff_ne_zero.mpr + apply Finset.prod_ne_zero_iff.mpr + intro i _ + rw [particleBase_univ (measure_ne_top (ν i) univ)] + exact ENNReal.ofReal_ne_zero_iff.mpr (Real.exp_pos _) + +theorem weighted_square_le {I : Type uI} [Fintype I] (w n : I → ℝ) + (hw : ∀ i, 0 ≤ w i) (hrow : ∑ i, w i ≤ 1) : + (∑ i, w i * n i)^2 ≤ ∑ i, w i * (n i)^2 := by + have hh := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul Finset.univ + (fun i _ => hw i) (fun i _ => mul_nonneg (hw i) (sq_nonneg (n i))) + (fun i (_ : i ∈ Finset.univ) => (show (w i * n i)^2 ≤ w i * (w i * (n i)^2) by nlinarith)) + exact hh.trans (mul_le_of_le_one_left (Finset.sum_nonneg (fun i _ => mul_nonneg (hw i) (sq_nonneg (n i)))) hrow) + +theorem integrable_cell_numerator (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (z : ℝ) {D B : ℝ} {E f : (∀ i, ParticleState (X i)) → ℝ} + (hE : Measurable E) (hf : Measurable f) + (hstable : ∀ x, D/2 * ∑ i, (cellN i x)^2 - B * ∑ i, cellN i x ≤ E x) + (hfbound : ∀ x, f x ≤ D/2 * ∑ i, (cellN i x)^2) : + Integrable (fun x => Real.exp (f x - E x)) (Measure.pi (fun i => particleBase (ν i) z)) := by + apply (integrable_exp_cell_total ν z B).mono' (Real.measurable_exp.comp (hf.sub hE)).aestronglyMeasurable + filter_upwards [] with x + change |Real.exp (f x - E x)| ≤ Real.exp (B * ∑ i, cellN i x) + rw [abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (by linarith [hstable x, hfbound x]) + +theorem uniform_cell_exponential_moment [Nonempty I] [DecidableEq I] + (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (z : ℝ) {D B V : ℝ} (hD : 0 < D) (hV : 0 ≤ V) + (hvol : ∀ i, (ν i univ).toReal ≤ V) + (θ : I → I → ℝ) (hθ : ∀ i j, 0 ≤ θ i j) (hθdiag : ∀ i, θ i i = 0) + (hrow : ∀ i, ∑ j, θ i j ≤ 1) + {E : (∀ i, ParticleState (X i)) → ℝ} (hE : Measurable E) + (hstable : ∀ x, D/2 * ∑ i, (cellN i x)^2 - B * ∑ i, cellN i x ≤ E x) + (hconditional : ∀ i x s, D/2 * (particleCount s : ℝ)^2 - B * particleCount s - + (particleCount s : ℝ) * (D/8 * ∑ j, θ i j * cellN j x) ≤ + E (Function.update x i s) - E (Function.update x i particleVacuum)) : + ∀ i, (∫ x, Real.exp (D/4 * (cellN i x)^2) + ∂boltzmannMeasure (Measure.pi (fun j => particleBase (ν j) z)) E) ≤ + Real.exp (16/15 * V * Real.exp (z+B)) := by + classical + let μ := Measure.pi (fun j => particleBase (ν j) z) + let F (i : I) (x : ∀ j, ParticleState (X j)) := D/4 * (cellN i x)^2 + let g (i : I) (x : ∀ j, ParticleState (X j)) := (1/16:ℝ) * ∑ j, θ i j * F j x + let C := Real.exp (V * Real.exp (z+B)) + have hFmeas (i : I) : Measurable (F i) := measurable_const.mul ((measurable_cellN i).pow_const 2) + have hF0 (i : I) (x : ∀ j, ParticleState (X j)) : 0 ≤ F i x := mul_nonneg (by positivity) (sq_nonneg _) + have hθ1 (i j : I) : θ i j ≤ 1 := + (Finset.single_le_sum (fun k _ => hθ i k) (Finset.mem_univ j)).trans (hrow i) + have hFbound (i : I) (x : ∀ j, ParticleState (X j)) : F i x ≤ D/2 * ∑ j, (cellN j x)^2 := by + have hh := Finset.single_le_sum (s := Finset.univ) (f := fun j => (cellN j x)^2) + (fun _ _ => sq_nonneg _) (Finset.mem_univ i) + dsimp [F] + nlinarith [sq_nonneg (cellN i x)] + have hgmeas (i : I) : Measurable (g i) := + measurable_const.mul (Finset.measurable_sum _ (fun j _ => measurable_const.mul (hFmeas j))) + have hgBound (i : I) (x : ∀ j, ParticleState (X j)) : g i x ≤ D/2 * ∑ j, (cellN j x)^2 := by + have hh := Finset.sum_le_sum (s := Finset.univ) + (fun j (_ : j ∈ Finset.univ) => mul_le_of_le_one_left (hF0 j x) (hθ1 i j)) + have hsum : ∑ j, F j x = D/4 * ∑ j, (cellN j x)^2 := by simp only [F, Finset.mul_sum] + have hn : 0 ≤ ∑ j, (cellN j x)^2 := Finset.sum_nonneg (fun _ _ => sq_nonneg _) + dsimp only [g] + rw [hsum] at hh + nlinarith + have hiE : Integrable (fun x => Real.exp (-E x)) μ := by + simpa using integrable_cell_numerator ν z hE measurable_const hstable + (f := fun _ => 0) (fun x => mul_nonneg (by positivity) (Finset.sum_nonneg (fun _ _ => sq_nonneg _))) + have hp := cell_partition_pos ν z hiE + let := boltzmannMeasure_probability hiE hp + have hiF (i : I) := integrable_cell_numerator ν z hE (hFmeas i) hstable (hFbound i) + have hig (i : I) := integrable_cell_numerator ν z hE (hgmeas i) hstable (hgBound i) + have hif (i : I) : Integrable (fun x => Real.exp (F i x)) (boltzmannMeasure μ E) := by + apply integrable_boltzmann hE _ hp + convert hiF i using 1 + ext x + rw [← Real.exp_add] + congr 1 + ring + have hC1 : 1 ≤ C := Real.one_le_exp_iff.mpr (mul_nonneg hV (Real.exp_pos _).le) + have hint (i : I) : (∫ x, Real.exp (F i x) ∂boltzmannMeasure μ E) ≤ + C*(∫ x, Real.exp (g i x) ∂boltzmannMeasure μ E) := by + have hfmeas : Measurable (fun x => ENNReal.ofReal (Real.exp (F i x - E x))) := + (Real.measurable_exp.comp ((hFmeas i).sub hE)).ennreal_ofReal + have hgmeas' : Measurable (fun x => ENNReal.ofReal C * ENNReal.ofReal (Real.exp (g i x - E x))) := + measurable_const.mul (Real.measurable_exp.comp ((hgmeas i).sub hE)).ennreal_ofReal + have hlocal : lmarginal (fun j => particleBase (ν j) z) {i} + (fun x => ENNReal.ofReal (Real.exp (F i x - E x))) ≤ + lmarginal (fun j => particleBase (ν j) z) {i} + (fun x => ENNReal.ofReal C * ENNReal.ofReal (Real.exp (g i x - E x))) := by + rw [lmarginal_singleton, lmarginal_singleton] + intro x + have hginv (s : ParticleState (X i)) : g i (Function.update x i s) = g i x := by + dsimp only [g, F, cellN] + congr 1 + apply Finset.sum_congr rfl + intro j _ + by_cases hj : j = i + · subst j + simp [hθdiag] + · simp [Function.update_of_ne hj] + have hcur := one_cell_exponential_moment (ν i) z (β := 1) (D := D) (B := B) (J := D) + (G := D/8 * ∑ j, θ i j * cellN j x) (by norm_num) hD le_rfl + (H := fun s => E (Function.update x i s)) + (hE.comp (measurable_update x (a := i))) (fun s => by + convert hconditional i x s using 1; ring) + have hG : (D/8 * ∑ j, θ i j * cellN j x)^2 / D ≤ g i x := by + have hh := weighted_square_le (θ i) (fun j => cellN j x) (hθ i) (hrow i) + have hs : ∑ j, θ i j * F j x = D/4 * ∑ j, θ i j * (cellN j x)^2 := by + dsimp only [F] + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + dsimp only [g] + rw [hs] + apply (div_le_iff₀ hD).mpr + nlinarith [mul_nonneg (sq_nonneg D) (sub_nonneg.mpr hh)] + have hCi : Real.exp ((ν i univ).toReal * Real.exp (z+B)) ≤ C := + Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_right (hvol i) (Real.exp_pos _).le) + simp only [one_mul, neg_one_mul] at hcur + calc + _ = ∫⁻ s, ENNReal.ofReal (Real.exp (D/4*(particleCount s : ℝ)^2 - + E (Function.update x i s))) ∂particleBase (ν i) z := by + apply lintegral_congr + intro s + simp only [F, cellN, Function.update_self] + _ ≤ _ := hcur + _ ≤ ENNReal.ofReal C * ENNReal.ofReal (Real.exp (g i x)) * + ∫⁻ s, ENNReal.ofReal (Real.exp (-E (Function.update x i s))) ∂particleBase (ν i) z := by + gcongr + _ = _ := by + rw [mul_assoc, ← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + ← lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + apply lintegral_congr + intro s + rw [hginv, Real.exp_sub] + simp only [div_eq_mul_inv, Real.exp_neg, ENNReal.ofReal_mul (Real.exp_pos _).le] + have htotal := lintegral_le_of_lmarginal_le {i} hfmeas hgmeas' hlocal + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top, + ← ofReal_integral_eq_lintegral_ofReal (hiF i) (Eventually.of_forall (fun _ => (Real.exp_pos _).le)), + ← ofReal_integral_eq_lintegral_ofReal (hig i) (Eventually.of_forall (fun _ => (Real.exp_pos _).le)), + ← ENNReal.ofReal_mul (by linarith [hC1])] at htotal + have hr := (ENNReal.ofReal_le_ofReal_iff (mul_nonneg (by linarith [hC1]) + (integral_nonneg (fun _ => (Real.exp_pos _).le)))).mp htotal + rw [integral_boltzmann hE, integral_boltzmann hE] + simp_rw [← Real.exp_add, neg_add_eq_sub] + have hh := mul_le_mul_of_nonneg_left hr (inv_nonneg.mpr hp.le) + nlinarith + have hc := occupation_moment_closure F θ hC1 (by norm_num : 0 ≤ (1/16:ℝ)) + (by norm_num : (1/16:ℝ) < 1) hFmeas hF0 hif hθ hrow hint + intro i + convert hc i using 1 + congr 1 + dsimp [C] + rw [Real.log_exp] + ring + +end ProductCells +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CellStability.lean b/lean/OAI/Probability/RadialTransition/CellStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..233e4a94ad28a6f4946af0ddbf928897199aa1d5 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CellStability.lean @@ -0,0 +1,218 @@ +import OAI.Probability.RadialTransition.RadialKernel + +namespace OAI + +universe uI uV + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +theorem symmetric_row_quadratic {I : Type uI} [Fintype I] (J : I → I → ℝ) (n : I → ℝ) (M : ℝ) + (hJ : ∀ i j, 0 ≤ J i j) (hsymm : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J i j ≤ M) : + ∑ i, ∑ j, J i j * n i * n j ≤ M * ∑ i, (n i) ^ 2 := by + have ht (i j : I) : 2 * (J i j * n i * n j) ≤ + J i j * (n i ^ 2 + n j ^ 2) := by + nlinarith [mul_nonneg (hJ i j) (sq_nonneg (n i - n j))] + have hl := Finset.sum_le_sum (s := Finset.univ) fun i _ => + Finset.sum_le_sum (s := Finset.univ) fun j _ => ht i j + have hs : (∑ i, ∑ j, J i j * n j ^ 2) = ∑ i, ∑ j, J i j * n i ^ 2 := by + rw [Finset.sum_comm] + congr 1 + funext i + congr 1 + funext j + rw [hsymm] + simp only [mul_add, Finset.sum_add_distrib, ← Finset.mul_sum] at hl + rw [hs] at hl + have hb : (∑ i, ∑ j, J i j * n i ^ 2) ≤ M * ∑ i, n i ^ 2 := by + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [← Finset.sum_mul] + exact mul_le_mul_of_nonneg_right (hrow i) (sq_nonneg _) + linarith + +theorem core_ordered_lower_small_diameter {V : Type uV} [Fintype V] [DecidableEq V] {t : ℝ} (ht : 0 ≤ t) + (x : V → Position) (hx : ∀ i j, dist (x i) (x j) ≤ 1) : + t ^ 2 / 4 * (Fintype.card V : ℝ) ^ 2 - t ^ 2 * Fintype.card V ≤ + ∑ i, ∑ j, if i ≠ j then coreReal t (dist (x i) (x j)) else 0 := by + classical + let G := shellGraph x (microLength t) + have hG : G.CliqueFree 5 := shellGraph_cliqueFree x (microLength_pos t) + have hbound : (8 : ℝ) * G.edgeFinset.card ≤ 3 * (Fintype.card V : ℝ) ^ 2 := by + have hh : 8 * G.edgeFinset.card ≤ 3 * Fintype.card V ^ 2 := by + simpa using shell_edge_bound G hG + exact_mod_cast hh + have hterm (i j : V) : + t ^ 2 * ((if i ≠ j then (1 : ℝ) else 0) - (if G.Adj i j then 1 else 0)) ≤ + (if i ≠ j then coreReal t (dist (x i) (x j)) else 0) := by + by_cases hij : i = j + · subst j + simp + · simp only [ite_eq_left hij] + by_cases hA : G.Adj i j + · simp only [hA, ite_true, sub_self, mul_zero] + exact coreReal_nonneg _ _ + · simp only [hA, ite_false, sub_zero, mul_one] + rw [coreReal_full_of_not_shell ht (hx i j)] + intro h + exact hA ⟨hij, h⟩ + have hsum := Finset.sum_le_sum (s := Finset.univ) fun i _ => + Finset.sum_le_sum (s := Finset.univ) fun j _ => hterm i j + have hcount : (∑ i : V, ∑ j : V, if i ≠ j then (1 : ℝ) else 0) = + (Fintype.card V : ℝ) ^ 2 - Fintype.card V := by + have hite (i j : V) : (if i ≠ j then (1 : ℝ) else 0) = + 1 - (if i = j then 1 else 0) := by by_cases h : i = j <;> simp [h] + simp_rw [hite] + simp only [Finset.sum_sub_distrib, Finset.sum_const, Finset.card_univ, + nsmul_eq_mul, mul_one, Finset.sum_ite_eq, + Finset.mem_univ, ite_true] + ring + simp only [mul_sub, Finset.sum_sub_distrib, ← Finset.mul_sum] at hsum + rw [hcount, sum_adj_indicator G] at hsum + have hb := mul_le_mul_of_nonneg_left hbound (sq_nonneg t) + nlinarith [hsum, hb] + +def occupation {V : Type uV} {I : Type uI} [Fintype V] (q : V → I) (i : I) : ℝ := by + classical + exact (Fintype.card {a : V // q a = i} : ℝ) + +theorem sum_occupation {V : Type uV} {I : Type uI} [Fintype V] [Fintype I] (q : V → I) : + ∑ i, occupation q i = Fintype.card V := by + classical + simpa [occupation] using Fintype.sum_fiberwise q (fun _ => (1 : ℝ)) + +theorem sum_subtype_le_of_nonneg {V : Type uV} [Fintype V] (p : V → Prop) + (f : V → ℝ) (hf : ∀ a, 0 ≤ f a) : + (by classical exact ∑ a : {a // p a}, f a) ≤ ∑ a, f a := by + classical + have hh := Fintype.sum_subtype_add_sum_subtype p f + have hz : 0 ≤ ∑ a : {a // ¬p a}, f a := Finset.sum_nonneg (fun a _ => hf a) + linarith + +theorem core_ordered_cells {V : Type uV} {I : Type uI} [Fintype V] [Fintype I] [DecidableEq V] + {t : ℝ} (ht : 0 ≤ t) (q : V → I) (x : V → Position) + (c : V → V → ℝ) (hc : ∀ a b, 0 ≤ c a b) + (hsame : ∀ a b, q a = q b → c a b = 1) + (hdiam : ∀ a b, q a = q b → dist (x a) (x b) ≤ 1) : + t ^ 2 / 4 * (∑ i, occupation q i ^ 2) - t ^ 2 * Fintype.card V ≤ + ∑ a, ∑ b, if a ≠ b then c a b * coreReal t (dist (x a) (x b)) else 0 := by + classical + let F (a b : V) := if a ≠ b then c a b * coreReal t (dist (x a) (x b)) else 0 + have hF (a b : V) : 0 ≤ F a b := by + exact ite_nonneg (mul_nonneg (hc a b) (coreReal_nonneg _ _)) le_rfl + have hlocal (i : I) : t ^ 2 / 4 * occupation q i ^ 2 - t ^ 2 * occupation q i ≤ + ∑ a : {a // q a = i}, ∑ b, F a b := by + have hl := core_ordered_lower_small_diameter ht (fun a : {a // q a = i} => x a) + (fun a b => hdiam a b (a.property.trans b.property.symm)) + change t ^ 2 / 4 * occupation q i ^ 2 - t ^ 2 * occupation q i ≤ _ at hl + apply hl.trans + apply Finset.sum_le_sum + intro a _ + have heq : (∑ b : {b // q b = i}, + if a ≠ b then coreReal t (dist (x a) (x b)) else 0) = + ∑ b : {b // q b = i}, F a b := by + apply Finset.sum_congr rfl + intro b _ + by_cases hab : a = b + · subst b; simp [F] + · have hab' : (a : V) ≠ (b : V) := fun hh => hab (Subtype.ext hh) + simp [F, hab, hab', hsame a b (a.property.trans b.property.symm)] + rw [heq] + exact sum_subtype_le_of_nonneg (fun b => q b = i) (F a) (hF a) + have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hlocal i) + rw [Fintype.sum_fiberwise q (fun a => ∑ b, F a b)] at hs + simpa only [Finset.sum_sub_distrib, ← Finset.mul_sum, sum_occupation] using hs + +theorem sum_by_occupation {V : Type uV} {I : Type uI} [Fintype V] [Fintype I] + (q : V → I) (f : I → ℝ) : + (∑ a, f (q a)) = ∑ i, occupation q i * f i := by + classical + rw [← Fintype.sum_fiberwise q (fun a => f (q a))] + apply Finset.sum_congr rfl + intro i _ + have heq : (fun a : {a // q a = i} => f (q a)) = (fun _ => f i) := by + funext a + rw [a.property] + rw [heq] + simp [occupation] + +theorem lifted_row_quadratic {V : Type uV} {I : Type uI} [Fintype V] [Fintype I] + (q : V → I) (J : I → I → ℝ) {M : ℝ} + (hJ : ∀ i j, 0 ≤ J i j) (hJsy : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J i j ≤ M) : + (∑ a, ∑ b, J (q a) (q b)) ≤ M * ∑ i, occupation q i ^ 2 := by + classical + have heq : (∑ a, ∑ b, J (q a) (q b)) = + ∑ i, ∑ j, J i j * occupation q i * occupation q j := by + calc + _ = ∑ a, ∑ j, occupation q j * J (q a) j := by + apply Finset.sum_congr rfl + intro a _ + exact sum_by_occupation q (J (q a)) + _ = ∑ i, occupation q i * ∑ j, occupation q j * J i j := + sum_by_occupation q (fun i => ∑ j, occupation q j * J i j) + _ = _ := by + simp only [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + ring + rw [heq] + exact symmetric_row_quadratic J (occupation q) M hJ hJsy hrow + +theorem modified_energy_cell_bound {N : ℕ} {I : Type uI} [Fintype I] + {t M : ℝ} (ht : 0 ≤ t) (q : Fin N → I) (x : Fin N → Position) + (c K : Fin N → Fin N → ℝ) (J : I → I → ℝ) + (hc : ∀ a b, 0 ≤ c a b) (hcsy : ∀ a b, c a b = c b a) + (hsame : ∀ a b, q a = q b → c a b = 1) + (hdiam : ∀ a b, q a = q b → dist (x a) (x b) ≤ 1) + (hK : ∀ a b, 0 ≤ K a b) (hKsy : ∀ a b, K a b = K b a) + (hKJ : ∀ a b, K a b ≤ J (q a) (q b)) + (hJ : ∀ i j, 0 ≤ J i j) (hJsy : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J i j ≤ M) : + (t ^ 2 / 8 - M / 2) * (∑ i, occupation q i ^ 2) - t ^ 2 / 2 * N ≤ + ∑ a, ∑ b with a < b, (c a b * coreReal t (dist (x a) (x b)) - K a b) := by + classical + have hcore := core_ordered_cells ht q x c hc hsame hdiam + have hrow' := lifted_row_quadratic q J hJ hJsy hrow + have hatt : (∑ a, ∑ b, if a ≠ b then K a b else 0) ≤ + M * ∑ i, occupation q i ^ 2 := by + apply le_trans ?_ hrow' + apply Finset.sum_le_sum + intro a _ + apply Finset.sum_le_sum + intro b _ + apply le_trans ?_ (hKJ a b) + split_ifs + · exact le_rfl + · exact hK a b + have hpair := twice_pair_sum + (fun a b => c a b * coreReal t (dist (x a) (x b)) - K a b) + (fun a b => by rw [hcsy a b, dist_comm (x a), hKsy a b]) + have heq : (∑ a, ∑ b, if a ≠ b then + c a b * coreReal t (dist (x a) (x b)) - K a b else 0) = + (∑ a, ∑ b, if a ≠ b then c a b * coreReal t (dist (x a) (x b)) else 0) - + (∑ a, ∑ b, if a ≠ b then K a b else 0) := by + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro a _ + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro b _ + by_cases hab : a = b <;> simp [hab] + rw [heq] at hpair + simp only [Fintype.card_fin] at hcore + nlinarith + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ClusterConvolution.lean b/lean/OAI/Probability/RadialTransition/ClusterConvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..dbb74cd009ea30a9e9f59e493b019b9a026b4e72 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ClusterConvolution.lean @@ -0,0 +1,76 @@ +import OAI.Probability.RadialTransition.GrandBounds + +namespace OAI + +universe uX uY + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma antidiagonal_map {X : Type uX} {Y : Type uY} (f : X → Y) (s : Multiset X) : + (s.map f).antidiagonal = s.antidiagonal.map (fun p => (p.1.map f, p.2.map f)) := by + induction s using Multiset.induction_on with + | empty => simp + | cons a s ih => + simp only [Multiset.map_cons, Multiset.antidiagonal_cons, ih, Multiset.map_add, Multiset.map_map] + congr 1 <;> apply Multiset.map_congr rfl <;> intro p hp <;> simp + +lemma powerset_val_map {X : Type uX} (s : Finset X) : + (s.powerset.val.map Finset.val) = s.val.powerset := by + simp [Finset.powerset, Multiset.map_pmap, Multiset.pmap_eq_map] + +lemma configurationMultiset_val {X : Type uX} {ι : Type} [Fintype ι] (x : ι → X) : + configurationMultiset x = (Finset.univ.val.map x) := by + simp only [configurationMultiset, Finset.sum] + simpa only [Multiset.map_map, Function.comp_def] using + Multiset.sum_map_singleton (Finset.univ.val.map x) + +lemma configurationMultiset_subtype {X : Type uX} {ι : Type} [Fintype ι] + (x : ι → X) (T : Finset ι) : + configurationMultiset (fun i : T => x i) = T.val.map x := by + unfold configurationMultiset + calc + (∑ i : T, {x i}) = ∑ i ∈ T, {x i} := Finset.sum_finset_coe (fun i => {x i}) T + _ = _ := by + change (T.val.map (fun i => {x i})).sum = T.val.map x + simpa only [Multiset.map_map, Function.comp_def] using Multiset.sum_map_singleton (T.val.map x) + +def clusterConvolution {X : Type uX} (F G : Multiset X → ℝ≥0∞) (s : Multiset X) : ℝ≥0∞ := + (s.antidiagonal.map (fun p => F p.1 * G p.2)).sum + +lemma clusterConvolution_add_ge {X : Type uX} (F G : Multiset X → ℝ≥0∞) (s u : Multiset X) : + F s*G u ≤ clusterConvolution F G (s+u) := by + apply Multiset.single_le_sum (fun _ _ => bot_le) + exact Multiset.mem_map.mpr ⟨(s,u), Multiset.mem_antidiagonal.mpr rfl, rfl⟩ + +lemma clusterConvolution_configuration {X : Type uX} {ι : Type} [Fintype ι] [DecidableEq ι] + (F G : Multiset X → ℝ≥0∞) (x : ι → X) : + clusterConvolution F G (configurationMultiset x) = + ∑ T : Finset ι, F (configurationMultiset (fun i : {i // i ∉ T} => x i)) * + G (configurationMultiset (fun i : T => x i)) := by + classical + rw [clusterConvolution, configurationMultiset_val, antidiagonal_map, + Multiset.antidiagonal_eq_map_powerset, ← powerset_val_map] + simp only [Multiset.map_map, Function.comp_def] + rw [Finset.powerset_univ] + apply Finset.sum_congr rfl + intro T _ + congr 1 + · have hval : Finset.univ.val-T.val = Tᶜ.val := by + change (Finset.univ \ T).val = Tᶜ.val + rfl + rw [hval] + congr 1 + let e : {i // i ∉ T} ≃ {i // i ∈ Tᶜ} := Equiv.subtypeEquivProp (by simp) + have hh := configurationMultiset_equiv e (fun i : {i // i ∈ Tᶜ} => x i) + rw [configurationMultiset_subtype] at hh + exact hh.symm + · congr 1 + exact (configurationMultiset_subtype x T).symm + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ClusterEmbedding.lean b/lean/OAI/Probability/RadialTransition/ClusterEmbedding.lean new file mode 100644 index 0000000000000000000000000000000000000000..1514880ca94ea6b6f572c0f59dfdabfa3d5a7b43 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ClusterEmbedding.lean @@ -0,0 +1,62 @@ +import OAI.Probability.RadialTransition.MultiConvolution + +namespace OAI + +universe uX + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition +attribute [local instance] Classical.propDecidable + +lemma configurationMultiset_fibers {X : Type uX} {ι I : Type} [Fintype ι] [Fintype I] + (x : ι → X) (f : ι → I) : + ∑ q : I, ((Finset.univ.filter (fun j => f j = q)).val.map x) = configurationMultiset x := by + classical + have hq (q : I) : ((Finset.univ.filter (fun j => f j=q)).val.map x) = + ∑ j : ι, if f j=q then ({x j}:Multiset X) else 0 := by + rw [← Finset.sum_filter] + change _ = ((Finset.univ.filter (fun j => f j=q)).val.map (fun j => ({x j}:Multiset X))).sum + simpa only [Multiset.map_map, Function.comp_def] using + (Multiset.sum_map_singleton ((Finset.univ.filter (fun j => f j=q)).val.map x)).symm + simp_rw [hq] + rw [Finset.sum_comm] + simp [configurationMultiset] + +section Embed +variable {X : Type uX} {I Q : Type} [Fintype I] [Fintype Q] + +lemma indexedClusterProduct_embedding (W : I → Multiset X → ℝ≥0∞) + (h0 : ∀ i, 1 ≤ W i 0) (f : Q → I) (hf : Function.Injective f) (s : Q → Multiset X) : + (∏ q, W (f q) (s q)) ≤ indexedClusterProduct W (∑ q, s q) := by + classical + let u (i : I) : Multiset X := ∑ q : Q, if f q=i then s q else 0 + have huv (q : Q) : u (f q) = s q := by + simp [u, hf.eq_iff] + have huz (i : I) (hi : i ∉ Finset.univ.image f) : u i = 0 := by + apply Finset.sum_eq_zero + intro q _ + exact ite_eq_right (fun he => hi (Finset.mem_image.mpr ⟨q,Finset.mem_univ _,he⟩)) + have hsum : ∑ i, u i = ∑ q, s q := by + simp only [u] + rw [Finset.sum_comm] + simp + have hp : (∏ q, W (f q) (s q)) = ∏ i ∈ Finset.univ.image f, W i (u i) := by + rw [Finset.prod_image (fun a _ b _ hab => hf hab)] + simp_rw [huv] + rw [hp] + have hle : (∏ i ∈ Finset.univ.image f, W i (u i)) ≤ ∏ i, W i (u i) := by + apply Finset.prod_le_prod_of_subset_of_one_le₀ (Finset.subset_univ _) (fun _ _ => bot_le) + intro i _ hi + rw [huz i hi] + exact h0 i + apply hle.trans + rw [← hsum] + exact indexedClusterProduct_ge W u + +end Embed +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ClusterWeights.lean b/lean/OAI/Probability/RadialTransition/ClusterWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..cf6ef7464633bab7a42734aca377c99477a4c328 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ClusterWeights.lean @@ -0,0 +1,110 @@ +import OAI.Probability.RadialTransition.ConvolutionFock + +namespace OAI + +universe uX uM uY uZ + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition +attribute [local instance] Classical.propDecidable + +lemma configurationMultiset_card {X : Type uX} {ι : Type} [Fintype ι] (x : ι → X) : + (configurationMultiset x).card = Fintype.card ι := by + rw [configurationMultiset_val, Multiset.card_map] + exact Finset.card_univ + +lemma configurationMultiset_sum_map {X : Type uX} {M : Type uM} [AddCommMonoid M] {ι : Type} [Fintype ι] + (x : ι → X) (f : X → M) : ((configurationMultiset x).map f).sum = ∑ i, f (x i) := by + rw [configurationMultiset_val, Multiset.map_map] + rfl + +lemma configurationMultiset_prod_map {X : Type uX} {M : Type uM} [CommMonoid M] {ι : Type} [Fintype ι] + (x : ι → X) (f : X → M) : ((configurationMultiset x).map f).prod = ∏ i, f (x i) := by + rw [configurationMultiset_val, Multiset.map_map] + rfl + +def nearCube (r : ℝ) (x : Position) : Set Position := + {y | ∀ k, |y k-x k| ≤ r} + +def nearMask (r : ℝ) (x y : Position) : ℝ≥0∞ := (nearCube r x).indicator (fun _ => 1) y + +def regionMask (A : Set Position) (x : Position) : ℝ≥0∞ := A.indicator (fun _ => 1) x + +def starWeight (A : Set Position) (r : ℝ) (s : Multiset Position) : ℝ≥0∞ := + (s.map (fun x => regionMask A x * (s.map (nearMask r x)).prod)).sum + +def emptyWeight {X : Type uX} (s : Multiset X) : ℝ≥0∞ := if s.card = 0 then 1 else 0 + +def cellClusterWeight (t α r : ℝ) (k : Cell) (s : Multiset Position) : ℝ≥0∞ := + emptyWeight s + if s.card ≤ 4 then ENNReal.ofReal (Real.exp (-t*α))*starWeight (gridRegion k) r s else 0 + +lemma measurable_regionMask {A : Set Position} (hA : MeasurableSet A) : Measurable (regionMask A) := + measurable_const.indicator hA + +lemma measurable_nearMask (r : ℝ) : Measurable (Function.uncurry (nearMask r)) := by + have hs : MeasurableSet {p : Position × Position | ∀ k, |p.2 k-p.1 k| ≤ r} := by + simp only [Set.ofPred_forall] + apply MeasurableSet.iInter + intro k + exact measurableSet_le (((PiLp.continuous_apply 2 (fun _ : Fin 3 => ℝ) k).comp continuous_snd).sub + ((PiLp.continuous_apply 2 (fun _ : Fin 3 => ℝ) k).comp continuous_fst)).abs.measurable measurable_const + exact measurable_const.indicator hs + +lemma measurable_multiset_prod {Y : Type uY} {Z : Type uZ} [MeasurableSpace Y] + (s : Multiset Z) (f : Z → Y → ℝ≥0∞) (hf : ∀ i, Measurable (f i)) : + Measurable (fun x => (s.map (fun i => f i x)).prod) := by + induction s using Multiset.induction_on with + | empty => simp + | cons a s ih => + simp only [Multiset.map_cons, Multiset.prod_cons] + exact measurable_mul.comp ((hf a).prodMk ih) + +lemma measurable_starWeight {A : Set Position} (hA : MeasurableSet A) (r : ℝ) : + MeasurableConfiguration (starWeight A r) := by + intro s ι _ + classical + have hprod (a : (ι → Position) → Position) (ha : Measurable a) : + Measurable (fun y => ((s+configurationMultiset y).map (nearMask r (a y))).prod) := by + simp only [Multiset.map_add, Multiset.prod_add, configurationMultiset_prod_map] + apply Measurable.mul + · apply measurable_multiset_prod + intro v + exact (measurable_nearMask r).comp (ha.prodMk measurable_const) + · apply Finset.measurable_prod + intro i _ + exact (measurable_nearMask r).comp (ha.prodMk (measurable_pi_apply i)) + have he (x : ι → Position) : starWeight A r (s+configurationMultiset x) = + (s.map (fun a => regionMask A a * ((s+configurationMultiset x).map (nearMask r a)).prod)).sum + + ∑ i, regionMask A (x i) * ((s+configurationMultiset x).map (nearMask r (x i))).prod := by + unfold starWeight + rw [Multiset.map_add, Multiset.sum_add, configurationMultiset_sum_map] + simp_rw [he] + apply Measurable.add + · apply measurable_multiset_sum + intro a + exact measurable_const.mul (hprod (fun _ => a) measurable_const) + · apply Finset.measurable_sum + intro i _ + exact ((measurable_regionMask hA).comp (measurable_pi_apply i)).mul + (hprod (fun x => x i) (measurable_pi_apply i)) + +lemma measurable_emptyWeight {X : Type uX} [MeasurableSpace X] : + MeasurableConfiguration (emptyWeight (X := X)) := by + intro s ι _ + simp only [emptyWeight, Multiset.card_add, configurationMultiset_card] + exact measurable_const + +lemma measurable_cellClusterWeight (t α r : ℝ) (k : Cell) : + MeasurableConfiguration (cellClusterWeight t α r k) := by + intro s ι _ + simp only [cellClusterWeight, Multiset.card_add, configurationMultiset_card] + split_ifs + · exact (measurable_emptyWeight s ι).add (measurable_const.mul (measurable_starWeight (measurableSet_gridRegion k) r s ι)) + · exact (measurable_emptyWeight s ι).add measurable_const + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ConfigurationMaps.lean b/lean/OAI/Probability/RadialTransition/ConfigurationMaps.lean new file mode 100644 index 0000000000000000000000000000000000000000..a082e785c978a4366d32f9a3787da32dad7a5a5b --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ConfigurationMaps.lean @@ -0,0 +1,97 @@ +import OAI.Probability.RadialTransition.ProductConfigurations + +namespace OAI + +universe uX uY + +noncomputable section + + +open Filter MeasureTheory Set + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition +section MapConfigurations +variable {X : Type uX} {Y : Type uY} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [SecondCountableTopology X] [TopologicalSpace Y] [MeasurableSpace Y] [BorelSpace Y] + [SecondCountableTopology Y] + +def mapParticle (f : X → Y) (x : ParticleState X) : ParticleState Y := ⟨x.1, f ∘ x.2⟩ + +lemma measurable_mapParticle {f : X → Y} (hf : Measurable f) : Measurable (mapParticle f) := by + apply measurable_particle_iff.mpr + intro n + exact (measurable_particle_mk n).comp (measurable_pi_iff.mpr (fun i => hf.comp (measurable_pi_apply i))) + +lemma particleBase_map (μ : Measure X) [IsFiniteMeasure μ] (z : ℝ) + {f : X → Y} (hf : Measurable f) : + Measure.map (mapParticle f) (particleBase μ z) = particleBase (Measure.map f μ) z := by + unfold particleBase + rw [Measure.map_sum (measurable_mapParticle hf).aemeasurable] + congr 1 + funext n + rw [Measure.map_smul _ (measurable_mapParticle hf).aemeasurable, + Measure.map_map (measurable_mapParticle hf) (measurable_particle_mk n)] + congr 1 + rw [← Measure.pi_map_pi (fun _ : Fin n => hf.aemeasurable)] + exact (Measure.map_map (measurable_particle_mk n) + (show Measurable (fun x : Fin n → X => fun i => f (x i)) from + measurable_pi_iff.mpr (fun i => hf.comp (measurable_pi_apply i)))).symm + +end MapConfigurations +section FiniteFock +variable {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [SecondCountableTopology X] +variable (F : Multiset X → ℝ≥0∞) (hF : ContinuousConfiguration F) +include hF + +lemma particleBase_zero_observable (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (0 : Measure X) z) = F s := by + rw [lintegral_particleBase _ _ (continuous_particleObservable F hF s).measurable] + rw [tsum_eq_single 0] + · simp [particleMultiset, configurationMultiset] + · intro n hn + have hμ : Measure.pi (fun _ : Fin n => (0 : Measure X)) = 0 := by + apply Measure.measure_univ_eq_zero.mp + rw [Measure.pi_univ] + simp [hn] + rw [hμ, lintegral_zero_measure, mul_zero] + +lemma particleBase_fin_sum_observable (n : ℕ) (μ : Fin n → Measure X) + [∀ i, IsFiniteMeasure (μ i)] (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (∑ i, μ i) z) = + ∫⁻ x, F (s+multiParticleMultiset x) ∂Measure.pi (fun i => particleBase (μ i) z) := by + induction n generalizing s with + | zero => + simp only [Fin.sum_univ_zero] + rw [particleBase_zero_observable F hF] + simp [multiParticleMultiset] + | succ n ih => + rw [Fin.sum_univ_succ, particleBase_add_observable F hF] + simp_rw [ih] + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => ParticleState X) 0 + have hp := MeasurePreserving.symm e + (measurePreserving_piFinSuccAbove (fun i => particleBase (μ i) z) 0) + have hc := (continuous_multiParticleObservable F hF s (I := Fin (n+1))).measurable + rw [← hp.lintegral_comp hc] + change _ = ∫⁻ p : ParticleState X × (Fin n → ParticleState X), + F (s+multiParticleMultiset (e.symm p)) + ∂(particleBase (μ 0) z).prod (Measure.pi (fun i => particleBase (μ i.succ) z)) + have hpmeas : Measurable (fun p : ParticleState X × (Fin n → ParticleState X) => + F (s+multiParticleMultiset (e.symm p))) := hc.comp e.symm.measurable + rw [lintegral_prod _ hpmeas.aemeasurable] + apply lintegral_congr + intro x + apply lintegral_congr + intro y + congr 1 + simp [multiParticleMultiset, Fin.sum_univ_succ, e, + MeasurableEquiv.piFinSuccAbove_symm_apply, add_assoc] + +end FiniteFock +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ConvolutionFock.lean b/lean/OAI/Probability/RadialTransition/ConvolutionFock.lean new file mode 100644 index 0000000000000000000000000000000000000000..7faf0282712053759a26a77c1859bdfd7d7ca159 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ConvolutionFock.lean @@ -0,0 +1,77 @@ +import OAI.Probability.RadialTransition.ConvolutionIntegral + +namespace OAI + +universe uX + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition +section Fock +variable {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [SecondCountableTopology X] + +lemma particleBase_convolution {F G : Multiset X → ℝ≥0∞} + (hF : MeasurableConfiguration F) (hG : MeasurableConfiguration G) + (μ : Measure X) [SigmaFinite μ] (z : ℝ) : + (∫⁻ x, clusterConvolution F G (particleMultiset x) ∂particleBase μ z) = + (∫⁻ x, F (particleMultiset x) ∂particleBase μ z)* + (∫⁻ x, G (particleMultiset x) ∂particleBase μ z) := by + classical + have hmF := measurable_particleObservable F hF 0 + have hmG := measurable_particleObservable G hG 0 + have hmC := measurable_particleObservable _ (measurable_clusterConvolution hF hG) 0 + simp only [zero_add] at hmF hmG hmC + rw [lintegral_particleBase μ z hmC, lintegral_particleBase μ z hmF, + lintegral_particleBase μ z hmG] + let A (n : ℕ) := ∫⁻ x : Fin n → X, F (configurationMultiset x) ∂Measure.pi (fun _ => μ) + let B (n : ℕ) := ∫⁻ x : Fin n → X, G (configurationMultiset x) ∂Measure.pi (fun _ => μ) + have hN (N : ℕ) : + (∫⁻ x : Fin N → X, clusterConvolution F G (configurationMultiset x) ∂Measure.pi (fun _ => μ)) = + ∑ k ∈ Finset.range (N+1), (N.choose k : ℝ≥0∞)* (A (N-k)*B k) := by + simp_rw [clusterConvolution_configuration] + rw [lintegral_finsetSum] + · have hi (T : Finset (Fin N)) : + (∫⁻ x : Fin N → X, + F (configurationMultiset (fun i : {i // i ∉ T} => x i))* + G (configurationMultiset (fun i : T => x i)) ∂Measure.pi (fun _ => μ)) = A (N-T.card)*B T.card := by + rw [configuration_split_integral hF hG μ T, + configuration_integral_card F μ, configuration_integral_card G μ] + have hcardA : Fintype.card {i : Fin N // i ∈ T} = T.card := Fintype.card_coe T + have hcardB : Fintype.card {i : Fin N // i ∉ T} = N-T.card := by + rw [Fintype.card_subtype_compl, Fintype.card_fin, hcardA] + rw [hcardB, Fintype.card_coe T] + simp_rw [hi] + exact ennreal_subsets_card N (fun k => A (N-k)*B k) + · intro T _ + have hFa : Measurable (fun x : Fin N → X => F (configurationMultiset (fun i : {i // i ∉ T} => x i))) := by + have hh := (hF 0 {i // i ∉ T}).comp (show Measurable (fun x : Fin N → X => fun i : {i // i ∉ T} => x i) from measurable_pi_iff.mpr (fun i => measurable_pi_apply i.val)) + simpa only [zero_add, Function.comp_def] using hh + have hGa : Measurable (fun x : Fin N → X => G (configurationMultiset (fun i : T => x i))) := by + have hh := (hG 0 T).comp (show Measurable (fun x : Fin N → X => fun i : T => x i) from measurable_pi_iff.mpr (fun i => measurable_pi_apply i.val)) + simpa only [zero_add, Function.comp_def] using hh + exact hFa.mul hGa + simp only [particleMultiset] + simp_rw [hN, Finset.mul_sum] + have hcoeff (N k : ℕ) (hk : k ∈ Finset.range (N+1)) : + fockCoeff z N*((N.choose k : ℝ≥0∞)*(A (N-k)*B k)) = + (fockCoeff z k*B k)*(fockCoeff z (N-k)*A (N-k)) := by + rw [← mul_assoc, fockCoeff_choose z (Nat.le_of_lt_succ (Finset.mem_range.mp hk))] + ring + have hsum (N : ℕ) : + (∑ k ∈ Finset.range (N+1), fockCoeff z N*((N.choose k : ℝ≥0∞)*(A (N-k)*B k))) = + ∑ k ∈ Finset.range (N+1), (fockCoeff z k*B k)*(fockCoeff z (N-k)*A (N-k)) := by + exact Finset.sum_congr rfl (fun k hk => hcoeff N k hk) + change (∑' N, ∑ k ∈ Finset.range (N+1), fockCoeff z N*((N.choose k : ℝ≥0∞)*(A (N-k)*B k))) = _ + simp_rw [hsum] + rw [ennreal_tsum_triangle (fun k n => (fockCoeff z k*B k)*(fockCoeff z n*A n))] + simp_rw [ENNReal.tsum_mul_left] + rw [ENNReal.tsum_mul_right, mul_comm] + rfl + +end Fock +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ConvolutionIntegral.lean b/lean/OAI/Probability/RadialTransition/ConvolutionIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..f67ed0e2727aad66c0e0eee2d596b97caa0dfccf --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ConvolutionIntegral.lean @@ -0,0 +1,89 @@ +import OAI.Probability.RadialTransition.ClusterConvolution + +namespace OAI + +universe uX uY uIndex + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma clusterConvolution_add {X : Type uX} (F G : Multiset X → ℝ≥0∞) (s u : Multiset X) : + clusterConvolution F G (s+u) = + (s.antidiagonal.map (fun p => clusterConvolution (fun v => F (p.1+v)) (fun v => G (p.2+v)) u)).sum := by + simp [clusterConvolution, Multiset.antidiagonal_add, Multiset.map_bind, Multiset.sum_bind, + Multiset.map_map] + +section Measurable +variable {X : Type uX} [MeasurableSpace X] + +lemma measurable_configuration_subtype {F : Multiset X → ℝ≥0∞} (hF : MeasurableConfiguration F) + (s : Multiset X) {ι : Type} [Fintype ι] (p : ι → Prop) [DecidablePred p] : + Measurable (fun x : ι → X => F (s+configurationMultiset (fun i : Subtype p => x i))) := by + exact (hF s (Subtype p)).comp (measurable_pi_iff.mpr (fun i => measurable_pi_apply i.val)) + +lemma measurable_configuration_restrict {F : Multiset X → ℝ≥0∞} (hF : MeasurableConfiguration F) + (s : Multiset X) {ι : Type} [Fintype ι] (T : Finset ι) : + Measurable (fun x : ι → X => F (s+configurationMultiset (fun i : T => x i))) := by + apply (hF s T).comp + exact measurable_pi_iff.mpr (fun i => measurable_pi_apply i.val) + +lemma measurable_multiset_sum {Y : Type uY} [MeasurableSpace Y] {ι : Type uIndex} + (s : Multiset ι) (f : ι → Y → ℝ≥0∞) (hf : ∀ i, Measurable (f i)) : + Measurable (fun x => (s.map (fun i => f i x)).sum) := by + induction s using Multiset.induction_on with + | empty => simp + | cons a s ih => + simp only [Multiset.map_cons, Multiset.sum_cons] + exact measurable_add.comp ((hf a).prodMk ih) + +lemma measurable_clusterConvolution {F G : Multiset X → ℝ≥0∞} + (hF : MeasurableConfiguration F) (hG : MeasurableConfiguration G) : + MeasurableConfiguration (clusterConvolution F G) := by + classical + intro s ι _ + simp_rw [clusterConvolution_add, clusterConvolution_configuration] + apply measurable_multiset_sum + intro p + apply Finset.measurable_sum + intro T _ + exact (measurable_configuration_subtype hF p.1 (fun i => i ∉ T)).mul + (measurable_configuration_restrict hG p.2 T) + +lemma configuration_integral_card (F : Multiset X → ℝ≥0∞) (μ : Measure X) [SigmaFinite μ] + (ι : Type) [Fintype ι] : + (∫⁻ x : ι → X, F (configurationMultiset x) ∂Measure.pi (fun _ => μ)) = + ∫⁻ x : Fin (Fintype.card ι) → X, F (configurationMultiset x) ∂Measure.pi (fun _ => μ) := by + exact functional_integral_equiv (fun _ι _ x => F (configurationMultiset x)) + (fun _ι _κ _ _ e x => congrArg F (configurationMultiset_equiv e x)) (Fintype.equivFin ι) (fun _ => μ) + +lemma configuration_split_integral {F G : Multiset X → ℝ≥0∞} + (hF : MeasurableConfiguration F) (hG : MeasurableConfiguration G) + (μ : Measure X) [SigmaFinite μ] {ι : Type} [Fintype ι] [DecidableEq ι] (T : Finset ι) : + (∫⁻ x : ι → X, F (configurationMultiset (fun i : {i // i ∉ T} => x i)) * + G (configurationMultiset (fun i : T => x i)) ∂Measure.pi (fun _ => μ)) = + (∫⁻ x : {i // i ∉ T} → X, F (configurationMultiset x) ∂Measure.pi (fun _ => μ))* + (∫⁻ x : T → X, G (configurationMultiset x) ∂Measure.pi (fun _ => μ)) := by + have hp := measurePreserving_piEquivPiSubtypeProd (fun _ : ι => μ) (fun i => i ∈ T) + have hG0 : Measurable (fun x : T → X => G (configurationMultiset x)) := by + simpa only [zero_add] using hG 0 T + have hF0 : Measurable (fun x : {i // i ∉ T} → X => F (configurationMultiset x)) := by + simpa only [zero_add] using hF 0 {i // i ∉ T} + have hmeas : Measurable (fun p : (T → X) × ({i // i ∉ T} → X) => + G (configurationMultiset p.1)*F (configurationMultiset p.2)) := by + exact (hG0.comp measurable_fst).mul (hF0.comp measurable_snd) + have hh := hp.lintegral_comp hmeas + simp only [MeasurableEquiv.piEquivPiSubtypeProd_apply] at hh + have hi : Subtype.fintype (fun i : ι => i ∈ T) = Finset.Subtype.fintype T := Subsingleton.elim _ _ + rw [hi] at hh + have hent := lintegral_prod_mul (μ := Measure.pi (fun _ : T => μ)) + (ν := Measure.pi (fun _ : {i // i ∉ T} => μ)) hG0.aemeasurable hF0.aemeasurable + have hh := hh.trans hent + simpa only [mul_comm] using hh + +end Measurable +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CoreConvergence.lean b/lean/OAI/Probability/RadialTransition/CoreConvergence.lean new file mode 100644 index 0000000000000000000000000000000000000000..0a3288d89d75d38a6293650874e057c8450a0947 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CoreConvergence.lean @@ -0,0 +1,163 @@ +import OAI.Probability.RadialTransition.CoreLocalLower + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +def bareAlpha (h : ℝ) : ℝ := max 0 (max h (4*h-9)) +def bareLimit (h : ℝ) : ℝ := max 0 (max (packingDensity*h) (packingDensity*(4*h-9))) + +lemma bareLimit_eq (h : ℝ) : bareLimit h = bareAlpha h*packingDensity := by + have hp := packingDensity_pos.le + simp only [bareLimit, bareAlpha, max_mul_of_nonneg _ _ hp, zero_mul] + congr 2 <;> ring + +lemma packing_coefficient_approx {ε : ℝ} (hε : 0 < ε) : + ∃ ν : ℝ, 0 < ν ∧ ν ≤ 1 ∧ |packingDensity/(1+ν)^3-packingDensity| < ε := by + have hh : Tendsto (fun x : ℝ => packingDensity/(1+x⁻¹)^3) atTop (nhds packingDensity) := by + have hh : Tendsto (fun x : ℝ => (1+x⁻¹)^3) atTop (nhds (1:ℝ)) := by + simpa using ((tendsto_const_nhds (x := (1:ℝ))).add tendsto_inv_atTop_zero).pow 3 + simpa [div_eq_mul_inv] using (hh.inv₀ (by norm_num : (1:ℝ) ≠ 0)).const_mul packingDensity + have he := (Metric.tendsto_atTop.mp hh ε hε) + obtain ⟨x, hx⟩ := he + let y := max x 1 + have hy : 1 ≤ y := le_max_right _ _ + refine ⟨y⁻¹, inv_pos.mpr (by linarith), inv_le_one_of_one_le₀ hy, ?_⟩ + simpa only [Real.dist_eq] using hx y (le_max_left _ _) + +lemma tendsto_core_micro : Tendsto microLength atTop (nhds 0) := by + exact Real.tendsto_exp_atBot.comp tendsto_neg_atTop_atBot + +lemma corePressure_lower_branch {ν b t β h : ℝ} (ht : 1 ≤ t) (hb : 0 < b) + (hν : 0 ≤ ν) (hsep : 1/t+4*b ≤ ν) (hβ : 0 ≤ β) + (htb : 3*microLength t ≤ b/2) : + packingDensity/(1+ν)^3*h-packingDensity*|Real.log (b^3)|/t ≤ + grandPressure (corePotential t) t β h ∧ + packingDensity/(1+ν)^3*(4*h-9)-packingDensity*|Real.log (blobTetraConstant b)|/t ≤ + grandPressure (corePotential t) t β h := by + let c := packingDensity/(1+ν)^3 + have hp := packingDensity_pos + have hc0 : 0 ≤ c := by dsimp [c]; positivity + have hcp : c ≤ packingDensity := by + dsimp [c] + exact div_le_self packingDensity_pos.le (one_le_pow₀ (by linarith)) + have ht0 : 0 < t := by linarith + have hl := corePressure_packing_lower ht hb.le hν hsep hβ (h := h) + have hh (z : ℝ) : -packingDensity*|z|/t ≤ c*(z/t) := by + have hz := neg_abs_le z + have h1 := mul_le_mul_of_nonneg_left hz hc0 + have h2 := mul_le_mul_of_nonneg_right hcp (abs_nonneg z) + have h3 : -packingDensity*|z| ≤ c*z := by nlinarith + have h4 := div_le_div_of_nonneg_right h3 ht0.le + simpa only [mul_div_assoc] using h4 + constructor + · have hm := mul_le_mul_of_nonneg_left (core_local_log_monomer ht0 hb hβ (h := h)) hc0 + have he := hh (Real.log (b^3)) + dsimp only [c] at hm he + rw [mul_add] at hm + simp only [neg_mul, neg_div] at he + linarith + · have hm := mul_le_mul_of_nonneg_left (core_local_log_tetra ht0 hb hβ htb (h := h)) hc0 + have he := hh (Real.log (blobTetraConstant b)) + dsimp only [c] at hm he + rw [mul_add] at hm + simp only [neg_mul, neg_div] at he + linarith + +lemma corePressure_uniform_bare {β₀ H ε : ℝ} (hβ₀ : 0 < β₀) (hH : 0 ≤ H) (hε : 0 < ε) : + ∀ᶠ t : ℝ in atTop, ∀ β h : ℝ, β₀ ≤ β → |h| ≤ H → + |grandPressure (corePotential t) t β h-bareLimit h| ≤ ε := by + let D : ℝ := 4*H+10 + have hD : 0 < D := by dsimp [D]; positivity + obtain ⟨ν, hν, _, hc⟩ := packing_coefficient_approx (div_pos hε (mul_pos (by norm_num : (0:ℝ)<2) hD)) + let b := ν/10 + let c := packingDensity/(1+ν)^3 + let K := packingDensity*(|Real.log (b^3)|+|Real.log (blobTetraConstant b)|) + have hb : 0 < b := by dsimp [b]; positivity + have hp := packingDensity_pos + have hK : 0 ≤ K := by dsimp [K]; positivity + have hlim1 : Tendsto (fun t : ℝ => 1/t) atTop (nhds 0) := by simpa using tendsto_inv_atTop_zero + have hsep : ∀ᶠ t : ℝ in atTop, 1/t+4*b ≤ ν := by + have hh := ((hlim1.add_const (4*b)).eventually (eventually_le_nhds (by dsimp [b]; linarith : 0+4*b < ν))) + exact hh + have hmic : ∀ᶠ t : ℝ in atTop, 3*microLength t ≤ b/2 := + (tendsto_core_micro.const_mul 3).eventually (eventually_le_nhds (by linarith : (3:ℝ)*0 < b/2)) + have hsmall : ∀ᶠ t : ℝ in atTop, 2*((1+(1:ℝ)/1000)*microLength t) < 1 := by + have hh := (tendsto_core_micro.const_mul (2*(1+(1:ℝ)/1000))).eventually + (eventually_lt_nhds (by norm_num : 2*(1+(1:ℝ)/1000)*0 < 1)) + simpa only [mul_assoc] using hh + have herror : ∀ᶠ t : ℝ in atTop, K/t ≤ ε/2 := by + have hh : Tendsto (fun t : ℝ => K/t) atTop (nhds 0) := by simpa [div_eq_mul_inv] using hlim1.const_mul K + exact hh.eventually (eventually_le_nhds (by positivity : (0:ℝ)<ε/2)) + have hupper : ∀ᶠ t : ℝ in atTop, (216*Real.log 15001+1)/t ≤ ε := by + have hh : Tendsto (fun t : ℝ => (216*Real.log 15001+1)/t) atTop (nhds 0) := by + simpa [div_eq_mul_inv] using hlim1.const_mul (216*Real.log 15001+1) + exact hh.eventually (eventually_le_nhds hε) + filter_upwards [eventually_ge_atTop (max 1 (2*H/β₀)), hsep, hmic, hsmall, herror, hupper] + with t ht hsep hmic hsmall herror hupper + intro β h hβ hh + have ht1 : 1 ≤ t := (le_max_left _ _).trans ht + have ht0 : 0 < t := by linarith + have hβpos : 0 < β := hβ₀.trans_le hβ + have hhH := abs_le.mp hh + have hα0 : 0 ≤ bareAlpha h := le_max_left _ _ + have hα1 : h ≤ bareAlpha h := (le_max_left _ _).trans (le_max_right _ _) + have hα4 : 4*h-9 ≤ bareAlpha h := (le_max_right _ _).trans (le_max_right _ _) + have hup := corePressure_upper ht1 hsmall hβpos.le hα0 hα1 hα4 + have hexp : Real.exp (t*h-β*t^2/2) ≤ 1 := by + apply Real.exp_le_one_iff.mpr + have hth : 2*H ≤ t*β₀ := (div_le_iff₀ hβ₀).mp ((le_max_right _ _).trans ht) + have hh1 := mul_le_mul_of_nonneg_right hth ht0.le + have hh2 := mul_le_mul_of_nonneg_right hβ (sq_nonneg t) + have hh3 := mul_le_mul_of_nonneg_left hhH.2 ht0.le + nlinarith + have hup' : grandPressure (corePotential t) t β h-bareLimit h ≤ ε := by + rw [bareLimit_eq] + have hdiv := div_le_div_of_nonneg_right (show 216*Real.log 15001+Real.exp (t*h-β*t^2/2) ≤ 216*Real.log 15001+1 by linarith) ht0.le + linarith + have hlo := corePressure_lower_branch ht1 hb hν.le hsep hβpos.le hmic (h := h) + have hz := (grandPressure_spec (continuous_corePotential t) (bounded_corePotential t) + (stable_corePotential t) ht0 hβpos.le (core_nonpos_outer ht1) h).2.1 + have hcoeff (x : ℝ) (hx : |x| ≤ D) : |packingDensity*x-c*x| ≤ ε/2 := by + have he : packingDensity*x-c*x = (packingDensity-c)*x := by ring + rw [he, abs_mul] + have hcx : |packingDensity-c| ≤ ε/(2*D) := by + dsimp [c] + rw [abs_sub_comm] + exact hc.le + calc + _ ≤ (ε/(2*D))*D := mul_le_mul hcx hx (abs_nonneg _) (by positivity) + _ = ε/2 := by field_simp + have he1 := hcoeff h (hh.trans (by dsimp [D]; linarith)) + have he4 := hcoeff (4*h-9) (by rw [abs_le]; dsimp [D]; constructor <;> linarith) + have hlog1 : packingDensity*|Real.log (b^3)|/t ≤ ε/2 := by + apply le_trans _ herror + apply div_le_div_of_nonneg_right _ ht0.le + dsimp [K] + nlinarith [packingDensity_pos, abs_nonneg (Real.log (blobTetraConstant b))] + have hlog4 : packingDensity*|Real.log (blobTetraConstant b)|/t ≤ ε/2 := by + apply le_trans _ herror + apply div_le_div_of_nonneg_right _ ht0.le + dsimp [K] + nlinarith [packingDensity_pos, abs_nonneg (Real.log (b^3))] + have hlo' : bareLimit h-grandPressure (corePotential t) t β h ≤ ε := by + have h1 : packingDensity*h ≤ grandPressure (corePotential t) t β h+ε := by + have hh := (abs_le.mp he1).2 + dsimp only [c] at hh + linarith [hlo.1] + have h4 : packingDensity*(4*h-9) ≤ grandPressure (corePotential t) t β h+ε := by + have hh := (abs_le.mp he4).2 + dsimp only [c] at hh + linarith [hlo.2] + have hm : bareLimit h ≤ grandPressure (corePotential t) t β h+ε := + max_le (by linarith) (max_le h1 h4) + linarith + exact abs_le.mpr ⟨by linarith, hup'⟩ + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CoreLocalLower.lean b/lean/OAI/Probability/RadialTransition/CoreLocalLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..76a5f64ce94e42bae21a5daa3f5615c71df322bc --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CoreLocalLower.lean @@ -0,0 +1,83 @@ +import OAI.Probability.RadialTransition.TetraIntegral + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma partitionOn_one (φ : Potential) {b : ℝ} (hb : 0 ≤ b) (β : ℝ) : + partitionOn φ (cube b) 1 β = b^3 := by + simp [partitionOn, rawPartition, orderedEnergy, Measure.real, Measure.pi_univ, + volume_cube, ENNReal.toReal_ofReal hb] + +def blobTetraConstant (b : ℝ) : ℝ := (b/2)^3/((100000:ℝ)^9*24) + +lemma blobTetraConstant_pos {b : ℝ} (hb : 0 < b) : 0 < blobTetraConstant b := by + unfold blobTetraConstant + positivity + +lemma partitionOn_blob_tetra {t b β : ℝ} (hb : 0 ≤ b) (ht : 3*microLength t ≤ b/2) : + blobTetraConstant b*Real.exp (-9*t) ≤ partitionOn (corePotential t) (cube b) 4 β := by + have hsub : cube (b/2+3*microLength t) ⊆ cube b := by + intro x hx k + have hh := hx k + exact ⟨hh.1, by linarith [hh.2]⟩ + have hp := partitionOn_mono (continuous_corePotential t) (bounded_corePotential t) β 4 hsub + (by rw [volume_cube]; finiteness) + have h1 := partitionOn_tetra_lower t (b/2) β (by positivity) + have he : (b/2)^3*tetraEpsilon t^9/24 = blobTetraConstant b*Real.exp (-9*t) := by + dsimp [tetraEpsilon, microLength, blobTetraConstant] + rw [div_pow, div_pow, ← Real.exp_nat_mul] + norm_num only [Nat.cast_ofNat] + rw [show (9:ℝ)*(-t) = -9*t by ring] + ring + rw [he] at h1 + exact h1.trans hp + +lemma core_local_grand_monomer {t b β h : ℝ} (hb : 0 ≤ b) (hβ : 0 ≤ β) : + Real.exp (t*h)*b^3 ≤ grandOn (corePotential t) (cube b) β (t*h) := by + have hs := grandOn_summable (continuous_corePotential t) (bounded_corePotential t) + (stable_corePotential t) hβ (by rw [volume_cube]; finiteness : volume (cube b) ≠ ⊤) (t*h) + have hh := hs.le_tsum 1 (fun n _ => mul_nonneg (Real.exp_pos _).le (partitionOn_nonneg _ _ _ _)) + simpa only [Nat.cast_one, mul_one, partitionOn_one _ hb, grandOn] using hh + +lemma core_local_grand_tetra {t b β h : ℝ} (hb : 0 ≤ b) (hβ : 0 ≤ β) + (ht : 3*microLength t ≤ b/2) : + blobTetraConstant b*Real.exp (t*(4*h-9)) ≤ grandOn (corePotential t) (cube b) β (t*h) := by + have hs := grandOn_summable (continuous_corePotential t) (bounded_corePotential t) + (stable_corePotential t) hβ (by rw [volume_cube]; finiteness : volume (cube b) ≠ ⊤) (t*h) + have hh := hs.le_tsum 4 (fun n _ => mul_nonneg (Real.exp_pos _).le (partitionOn_nonneg _ _ _ _)) + have hl := mul_le_mul_of_nonneg_left (partitionOn_blob_tetra hb ht (β := β)) (Real.exp_pos (t*h*4)).le + have he : Real.exp (t*h*4)*(blobTetraConstant b*Real.exp (-9*t)) = + blobTetraConstant b*Real.exp (t*(4*h-9)) := by + rw [mul_left_comm, ← Real.exp_add] + congr 2 + ring + rw [he] at hl + exact hl.trans hh + +lemma core_local_log_monomer {t b β h : ℝ} (ht : 0 < t) (hb : 0 < b) (hβ : 0 ≤ β) : + h+Real.log (b^3)/t ≤ Real.log (grandOn (corePotential t) (cube b) β (t*h))/t := by + have hh := Real.log_le_log (mul_pos (Real.exp_pos _) (pow_pos hb 3)) (core_local_grand_monomer hb.le hβ (t := t) (h := h)) + rw [Real.log_mul (Real.exp_ne_zero _) (pow_ne_zero _ hb.ne'), Real.log_exp] at hh + apply (le_div_iff₀ ht).mpr + calc + _ = t*h+Real.log (b^3) := by field_simp + _ ≤ _ := hh + +lemma core_local_log_tetra {t b β h : ℝ} (ht : 0 < t) (hb : 0 < b) (hβ : 0 ≤ β) + (htb : 3*microLength t ≤ b/2) : + 4*h-9+Real.log (blobTetraConstant b)/t ≤ Real.log (grandOn (corePotential t) (cube b) β (t*h))/t := by + have hh := Real.log_le_log (mul_pos (blobTetraConstant_pos hb) (Real.exp_pos _)) (core_local_grand_tetra hb.le hβ htb (h := h)) + rw [Real.log_mul (blobTetraConstant_pos hb).ne' (Real.exp_ne_zero _), Real.log_exp] at hh + apply (le_div_iff₀ ht).mpr + calc + _ = Real.log (blobTetraConstant b)+t*(4*h-9) := by field_simp; ring + _ ≤ _ := hh + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CorePressureLower.lean b/lean/OAI/Probability/RadialTransition/CorePressureLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..88231a3834adb73e597d65ad7d596a4b79a4130b --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CorePressureLower.lean @@ -0,0 +1,57 @@ +import OAI.Probability.RadialTransition.CorePressureUpper + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma packing_dilated_limit {ν b : ℝ} (hν : 0 ≤ ν) : + Tendsto (fun L : ℝ => (packingNumber L:ℝ)/((1+ν)*L+b)^3) atTop + (nhds (packingDensity/(1+ν)^3)) := by + have hn : (1+ν)^3 ≠ 0 := by positivity + have hh : Tendsto (fun L : ℝ => (1+ν+b*L⁻¹)^3) atTop (nhds ((1+ν)^3)) := by + simpa using ((tendsto_const_nhds (x := 1+ν)).add (tendsto_inv_atTop_zero.const_mul b)).pow 3 + apply (packingDensity_limit.div hh hn).congr' + filter_upwards [eventually_gt_atTop (0:ℝ)] with L hL + have he : 1+ν+b*L⁻¹ = ((1+ν)*L+b)/L := by field_simp + dsimp only [Pi.div_apply] + rw [he, div_pow] + field_simp + +lemma corePressure_packing_lower {ν b t β h : ℝ} (ht : 1 ≤ t) (hb : 0 ≤ b) + (hν : 0 ≤ ν) (hsep : 1/t+4*b ≤ ν) (hβ : 0 ≤ β) : + packingDensity/(1+ν)^3 * (Real.log (grandOn (corePotential t) (cube b) β (t*h))/t) ≤ + grandPressure (corePotential t) t β h := by + have ht0 : 0 < t := by linarith + have hc := continuous_corePotential t + have hbound := bounded_corePotential t + have hstable := stable_corePotential t + have hlocal := (grandOn_bounds hc hbound hstable hβ (by rw [volume_cube]; finiteness : volume (cube b) ≠ ⊤) (t*h)).1 + have hlimL : Tendsto (fun L : ℝ => (1+ν)*L+b) atTop atTop := + tendsto_atTop_add_const_right atTop b (Tendsto.const_mul_atTop (by linarith : 0 < 1+ν) tendsto_id) + have hright := ((grandPressure_spec hc hbound hstable ht0 hβ (core_nonpos_outer ht) h).1).comp hlimL + have hleft := (packing_dilated_limit (b := b) hν).mul_const + (Real.log (grandOn (corePotential t) (cube b) β (t*h))/t) + apply le_of_tendsto_of_tendsto hleft hright + filter_upwards [eventually_gt_atTop (0:ℝ)] with L hL + have hS : 0 < (1+ν)*L+b := by positivity + have hprod := core_grand_packing_lower (L := L) ht0 hb hν hsep hβ (h := h) + have hlog := Real.log_le_log (pow_pos (show 0 < grandOn (corePotential t) (cube b) β (t*h) by linarith) _) hprod + rw [Real.log_pow] at hlog + rw [grandOn_cube] at hlog + rw [grandOn_cube] at hlog + have hden : 0 < t*((1+ν)*L+b)^3 := by positivity + dsimp only [finiteGrandPressure, Function.comp_def] + apply (le_div_iff₀ hden).mpr + rw [grandOn_cube] + calc + _ = (packingNumber L:ℝ)*Real.log (grandPartition (corePotential t) t b β h) := by + field_simp + _ ≤ _ := hlog + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CorePressureUpper.lean b/lean/OAI/Probability/RadialTransition/CorePressureUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..060a96620bb8fb2e9b4d8920941adefecc51b967 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CorePressureUpper.lean @@ -0,0 +1,62 @@ +import OAI.Probability.RadialTransition.PackingBlob + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma core_nonpos_outer {t : ℝ} (ht : 1 ≤ t) : + ∀ r : ℝ≥0, 2 ≤ (r:ℝ) → corePotential t r ≤ 0 := by + intro r hr + have ht0 : 0 < t := by linarith + have hinv : 1/t ≤ 1 := (div_le_one ht0).mpr ht + rw [corePotential, coreReal_zero_outer ht0 (by linarith)] + +lemma core_finitePressure_upper {t α L β h : ℝ} (hL : 1 ≤ L) + (ht0 : 0 < t) (ht : 2*((1+(1:ℝ)/1000)*microLength t) < 1) + (hβ : 0 ≤ β) (hα : 0 ≤ α) (h1 : h ≤ α) (h4 : 4*h-9 ≤ α) : + finiteGrandPressure (corePotential t) t L β h ≤ + α*((packingNumber L:ℝ)/L^3)+(216*Real.log 15001+Real.exp (t*h-β*t^2/2))/t := by + have hL0 : 0 < L := by linarith + have hh := core_grand_upper hL0.le ht0.le ht hβ (mul_nonneg ht0.le hα) h1 h4 + have hp := (grandPartition_bounds (continuous_corePotential t) (bounded_corePotential t) + (stable_corePotential t) hL0.le hβ t h).1 + have hreal := ENNReal.toReal_mono (by finiteness : + ENNReal.ofReal (Real.exp (t*α*packingNumber L)) * + ((15001:ℝ≥0∞)^(cubeCells L).card * ENNReal.ofReal (Real.exp (L^3*Real.exp (t*h-β*t^2/2)))) ≠ ⊤) hh + simp only [ENNReal.toReal_ofReal (show 0 ≤ grandPartition (corePotential t) t L β h by linarith), + ENNReal.toReal_mul, ENNReal.toReal_pow, ENNReal.toReal_ofReal (Real.exp_pos _).le, + ENNReal.toReal_ofNat] at hreal + have hlog := Real.log_le_log (show 0 < grandPartition (corePotential t) t L β h by linarith) hreal + rw [Real.log_mul (Real.exp_ne_zero _) (by positivity), Real.log_exp, + Real.log_mul (by positivity) (Real.exp_ne_zero _), Real.log_pow, Real.log_exp] at hlog + have hc := mul_le_mul_of_nonneg_right (card_cubeCells hL) (show 0 ≤ Real.log (15001:ℝ) from Real.log_nonneg (by norm_num)) + have hden : 0 < t*L^3 := by positivity + dsimp only [finiteGrandPressure] + apply (div_le_iff₀ hden).mpr + have heq : (α*((packingNumber L:ℝ)/L^3)+(216*Real.log 15001+Real.exp (t*h-β*t^2/2))/t)*(t*L^3) = + t*α*packingNumber L+216*L^3*Real.log 15001+L^3*Real.exp (t*h-β*t^2/2) := by + field_simp + ring + rw [heq] + linarith + +lemma corePressure_upper {t α β h : ℝ} (ht0 : 1 ≤ t) + (ht : 2*((1+(1:ℝ)/1000)*microLength t) < 1) + (hβ : 0 ≤ β) (hα : 0 ≤ α) (h1 : h ≤ α) (h4 : 4*h-9 ≤ α) : + grandPressure (corePotential t) t β h ≤ + α*packingDensity+(216*Real.log 15001+Real.exp (t*h-β*t^2/2))/t := by + have htpos : 0 < t := by linarith + have hl := (grandPressure_spec (continuous_corePotential t) (bounded_corePotential t) + (stable_corePotential t) htpos hβ (core_nonpos_outer ht0) h).1 + have hr := packingDensity_limit.const_mul α |>.add_const ((216*Real.log 15001+Real.exp (t*h-β*t^2/2))/t) + apply le_of_tendsto_of_tendsto hl hr + filter_upwards [eventually_ge_atTop (1:ℝ)] with L hL + exact core_finitePressure_upper hL htpos ht hβ hα h1 h4 + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CoreUpper.lean b/lean/OAI/Probability/RadialTransition/CoreUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..c0e63248973ba67c109d30e752aa80ab7c4bc5e4 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CoreUpper.lean @@ -0,0 +1,124 @@ +import OAI.Probability.RadialTransition.CellIntegral + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition +attribute [local instance] Classical.propDecidable + +def freeCoverWeight (L t α : ℝ) : Multiset Position → ℝ≥0∞ := + indexedClusterProduct (fun k : cubeCells L => + cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k.val) + +lemma measurable_freeCoverWeight (L t α : ℝ) : MeasurableConfiguration (freeCoverWeight L t α) := + measurable_indexedClusterProduct _ (fun _ => measurable_cellClusterWeight _ _ _ _) + +lemma core_boltzmann_cover {ι : Type} [Fintype ι] {t α L β : ℝ} {x : ι → Position} + (ht0 : 0 ≤ t) (ht : 2*((1+(1:ℝ)/1000)*microLength t) < 1) + (hβ : 0 ≤ β) (hbox : ∀ i, x i ∈ cube L) (hta : 0 ≤ t*α) : + ENNReal.ofReal (Real.exp (-β*orderedEnergy (corePotential t) x)) ≤ + ENNReal.ofReal (Real.exp (t*α*packingNumber L))* + clusterConvolution (freeCoverWeight L t α) (removalWeight t β) (configurationMultiset x) := by + classical + let B := badLabels t x + let good := configurationMultiset (fun i : {i // i ∉ B} => x i) + let bad := configurationMultiset (fun i : B => x i) + have hfree : ENNReal.ofReal (Real.exp (-t*α*packingNumber L)) ≤ freeCoverWeight L t α good := + coreFree_cell_cover (after_removal_free t x) ht (fun i => hbox i.val) hta + have hsum : freeCoverWeight L t α good*removalWeight t β bad ≤ + clusterConvolution (freeCoverWeight L t α) (removalWeight t β) (configurationMultiset x) := by + rw [clusterConvolution_configuration] + have hh := Finset.single_le_sum (s := (Finset.univ : Finset (Finset ι))) + (f := fun T : Finset ι => freeCoverWeight L t α (configurationMultiset (fun i : {i // i ∉ T} => x i)) * + removalWeight t β (configurationMultiset (fun i : T => x i))) + (fun _ _ => (bot_le : (0:ℝ≥0∞) ≤ _)) (Finset.mem_univ B) + convert hh using 1 + + have hb : ENNReal.ofReal (Real.exp (-β*orderedEnergy (corePotential t) x)) ≤ + removalWeight t β bad := by + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + change -β*orderedEnergy (corePotential t) x ≤ -β*t^2*(configurationMultiset (fun i : B => x i)).card/2 + rw [configurationMultiset_card, Fintype.card_coe] + have he := mul_le_mul_of_nonneg_left (badLabels_energy ht0 x) hβ + dsimp [B] + nlinarith + have hc : ENNReal.ofReal (Real.exp (t*α*packingNumber L))* + ENNReal.ofReal (Real.exp (-t*α*packingNumber L)) = 1 := by + rw [← ENNReal.ofReal_mul (Real.exp_pos _).le, ← Real.exp_add] + convert (by norm_num : ENNReal.ofReal (Real.exp 0) = 1) using 2; ring_nf + calc + _ ≤ removalWeight t β bad := hb + _ = ENNReal.ofReal (Real.exp (t*α*packingNumber L))* + (ENNReal.ofReal (Real.exp (-t*α*packingNumber L))*removalWeight t β bad) := by rw [← mul_assoc, hc, one_mul] + _ ≤ _ := mul_le_mul' le_rfl ((mul_le_mul' hfree le_rfl).trans hsum) + +lemma particleBase_ae_cube (L z : ℝ) : + ∀ᵐ s : ParticleState Position ∂particleBase (volume.restrict (cube L)) z, + ∀ i, s.2 i ∈ cube L := by + rw [particleBase, Measure.ae_sum_iff] + intro n + apply Measure.ae_smul_measure + rw [(Topology.IsOpenEmbedding.sigmaMk.measurableEmbedding).ae_map_iff] + rw [← Measure.restrict_pi_pi] + filter_upwards [ae_restrict_mem (MeasurableSet.univ_pi (fun _ : Fin n => measurableSet_cube L))] with x hx + exact fun i => hx i (Set.mem_univ i) + +lemma particleBase_restrict_le (A : Set Position) (z : ℝ) (F : Multiset Position → ℝ≥0∞) + (hF : MeasurableConfiguration F) : + (∫⁻ x, F (particleMultiset x) ∂particleBase (volume.restrict A) z) ≤ + ∫⁻ x, F (particleMultiset x) ∂particleBase volume z := by + have hm := measurable_particleObservable F hF 0 + simp only [zero_add] at hm + rw [lintegral_particleBase _ _ hm, lintegral_particleBase _ _ hm] + apply ENNReal.tsum_le_tsum + intro n + apply mul_le_mul' le_rfl + rw [← Measure.restrict_pi_pi] + exact lintegral_mono' Measure.restrict_le_self le_rfl + +lemma particleBase_freeCoverWeight_le {t h α : ℝ} (ht : 0 ≤ t) + (h1 : h ≤ α) (h4 : 4*h-9 ≤ α) (L : ℝ) : + (∫⁻ x, freeCoverWeight L t α (particleMultiset x) + ∂particleBase (volume.restrict (cube L)) (t*h)) ≤ (15001:ℝ≥0∞)^(cubeCells L).card := by + rw [freeCoverWeight, particleBase_indexedClusterProduct _ (fun _ => measurable_cellClusterWeight _ _ _ _)] + have hh : ∀ k : cubeCells L, + (∫⁻ x, cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k.val (particleMultiset x) + ∂particleBase (volume.restrict (cube L)) (t*h)) ≤ 15001 := by + intro k + exact (particleBase_restrict_le _ _ _ (measurable_cellClusterWeight _ _ _ _)).trans + (particleBase_cellClusterWeight_le ht h1 h4 k.val) + simpa using Finset.prod_le_prod (fun k (_ : k ∈ (Finset.univ : Finset (cubeCells L))) => hh k) + +lemma stable_corePotential (t : ℝ) : StableWith (corePotential t) 0 := by + intro N x + simp only [zero_mul, neg_zero, energy] + exact Finset.sum_nonneg (fun i _ => Finset.sum_nonneg (fun j _ => coreReal_nonneg _ _)) + +lemma core_grand_upper {t α L β h : ℝ} (hL : 0 ≤ L) + (ht0 : 0 ≤ t) (ht : 2*((1+(1:ℝ)/1000)*microLength t) < 1) + (hβ : 0 ≤ β) (hta : 0 ≤ t*α) (h1 : h ≤ α) (h4 : 4*h-9 ≤ α) : + ENNReal.ofReal (grandPartition (corePotential t) t L β h) ≤ + ENNReal.ofReal (Real.exp (t*α*packingNumber L))* + ((15001:ℝ≥0∞)^(cubeCells L).card * + ENNReal.ofReal (Real.exp (L^3*Real.exp (t*h-β*t^2/2)))) := by + have hfin : volume (cube L) ≠ ⊤ := by rw [volume_cube]; finiteness + have hmass : (volume.restrict (cube L) univ).toReal = L^3 := by + rw [Measure.restrict_apply MeasurableSet.univ, Set.univ_inter, volume_cube, + ENNReal.toReal_pow, ENNReal.toReal_ofReal hL] + rw [← grandOn_cube] + rw [← lintegral_grandOn (continuous_corePotential t) (bounded_corePotential t) (stable_corePotential t) hβ hfin] + have hle := lintegral_mono_ae ((particleBase_ae_cube L (t*h)).mono (fun x hx => core_boltzmann_cover ht0 ht hβ hx hta)) + apply hle.trans + rw [lintegral_const_mul' _ _ ENNReal.ofReal_ne_top] + change _ * (∫⁻ x, clusterConvolution (freeCoverWeight L t α) (removalWeight t β) (particleMultiset x) ∂particleBase (volume.restrict (cube L)) (t*h)) ≤ _ + rw [particleBase_convolution (measurable_freeCoverWeight _ _ _) (measurable_removalWeight _ _), + particleBase_removalWeight (by simpa using hfin), hmass] + exact mul_le_mul' le_rfl (mul_le_mul' (particleBase_freeCoverWeight_le ht0 h1 h4 L) le_rfl) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CountWeights.lean b/lean/OAI/Probability/RadialTransition/CountWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..5b5478d25d12e78f4e708f6dfdcbf26b7302a698 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CountWeights.lean @@ -0,0 +1,115 @@ +import OAI.Probability.RadialTransition.MacroLower + +namespace OAI + +universe uX uY + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff BigOperators ENNReal NNReal + +namespace RadialTransition + +lemma measurable_countWeight {φ : Potential} (hφ : Continuous φ) (β : ℝ) (F : ℕ → ℝ) : + Measurable (fun s : ParticleState Position => F (particleCount s)*Real.exp (-β*orderedEnergy φ s.2)) := by + apply Continuous.measurable + apply continuous_sigma + intro n + change Continuous (fun x : Fin n → Position => F n * Real.exp (-β*orderedEnergy φ x)) + exact continuous_const.mul (Real.continuous_exp.comp (continuous_const.mul (continuous_orderedEnergy hφ))) + +lemma lintegral_countWeight {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + (β z : ℝ) (F : ℕ → ℝ) (hF : ∀ n, 0 ≤ F n) {A : Set Position} (hAfin : volume A ≠ ⊤) : + (∫⁻ s : ParticleState Position, + ENNReal.ofReal (F (particleCount s)*Real.exp (-β*orderedEnergy φ s.2)) + ∂particleBase (volume.restrict A) z) = + ∑' n : ℕ, ENNReal.ofReal (F n*Real.exp (z*n)*partitionOn φ A n β) := by + let : IsFiniteMeasure (volume.restrict A) := isFiniteMeasure_restrict.mpr hAfin + rw [lintegral_particleBase _ _ (measurable_countWeight hφ β F).ennreal_ofReal] + apply tsum_congr + intro n + dsimp only [particleCount] + have hi := (integrable_orderedBoltzmann (ι := Fin n) hφ hb β (Measure.pi (fun _ => volume.restrict A))).const_mul (F n) + rw [← ofReal_integral_eq_lintegral_ofReal hi (Eventually.of_forall (fun x => mul_nonneg (hF n) (Real.exp_pos _).le)), integral_const_mul, + ← ENNReal.ofReal_mul (by positivity)] + congr 1 + simp only [partitionOn, rawPartition, div_eq_mul_inv] + ring + +lemma partitionOn_macroRegion (φ : Potential) {q : ℕ} (hq : 0 < q) (i : Cell) (n : ℕ) (β : ℝ) : + partitionOn φ (macroRegion q i) n β = partition φ ((q:ℝ)/4) n β := by + rw [macroRegion_translate hq, partitionOn_translate] + have hh : partitionOn φ (halfCube ((q:ℝ)/4)) n β = partitionOn φ (cube ((q:ℝ)/4)) n β := by + simp only [partitionOn, rawPartition, restrict_halfCube] + rw [hh, partitionOn_cube] + +section MapWeight +variable {X : Type uX} {Y : Type uY} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [TopologicalSpace Y] [MeasurableSpace Y] [BorelSpace Y] + [SecondCountableTopology X] [SecondCountableTopology Y] + +lemma lintegral_pairWeight_map (v : Y → Y → ℝ) (hv : Measurable (Function.uncurry v)) + (μ : Measure X) [IsFiniteMeasure μ] (f : X → Y) (hf : Measurable f) (β z : ℝ) (F : ℕ → ℝ) : + (∫⁻ s : ParticleState X, ENNReal.ofReal (F (particleCount s)*Real.exp (-β*pairWithin (fun x y => v (f x) (f y)) s)) ∂particleBase μ z) = + ∫⁻ s : ParticleState Y, ENNReal.ofReal (F (particleCount s)*Real.exp (-β*pairWithin v s)) ∂particleBase (Measure.map f μ) z := by + have hfun : Measurable (fun s : ParticleState Y => ENNReal.ofReal (F (particleCount s)*Real.exp (-β*pairWithin v s))) := by + apply Measurable.ennreal_ofReal + exact (((continuous_of_discreteTopology : Continuous F).comp continuous_particleCount).measurable).mul + (Real.measurable_exp.comp (measurable_const.mul (measurable_pairWithin v hv))) + rw [← particleBase_map μ z hf, lintegral_map hfun (measurable_mapParticle hf)] + rfl + +end MapWeight + +lemma lintegral_macroWeight {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {q : ℕ} (hq : 0 < q) (i : Cell) (β z : ℝ) (F : ℕ → ℝ) (hF : ∀ n, 0 ≤ F n) : + (∫⁻ s : ParticleState (macroRegion q i), ENNReal.ofReal (F (particleCount s)* + Real.exp (-β*pairWithin (fun (x y : macroRegion q i) => radialPair φ x y) s)) + ∂particleBase (regionMeasure (macroRegion q i)) z) = + ∑' n : ℕ, ENNReal.ofReal (F n*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β) := by + have hfin : volume (macroRegion q i) ≠ ⊤ := by rw [volume_macroRegion hq]; finiteness + let : IsFiniteMeasure (regionMeasure (macroRegion q i)) := regionMeasure_finite (measurableSet_macroRegion _ _) hfin + rw [lintegral_pairWeight_map (radialPair φ) (continuous_radialPair hφ).measurable _ Subtype.val measurable_subtype_coe, + regionMeasure_map (measurableSet_macroRegion _ _)] + simp only [pairWithin_radial] + rw [lintegral_countWeight hφ hb β z F hF hfin] + simp only [partitionOn_macroRegion φ hq] + +lemma integrable_macroWeight {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {q : ℕ} (hq : 0 < q) (i : Cell) (β z : ℝ) (F : ℕ → ℝ) (hF : ∀ n, 0 ≤ F n) + (hs : Summable (fun n => F n*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β)) : + Integrable (fun s : ParticleState (macroRegion q i) => F (particleCount s)* + Real.exp (-β*pairWithin (fun (x y : macroRegion q i) => radialPair φ x y) s)) + (particleBase (regionMeasure (macroRegion q i)) z) := by + have hm : Measurable (fun s : ParticleState (macroRegion q i) => F (particleCount s)* + Real.exp (-β*pairWithin (fun (x y : macroRegion q i) => radialPair φ x y) s)) := by + exact ((continuous_of_discreteTopology.comp continuous_particleCount).measurable).mul + (Real.measurable_exp.comp (measurable_const.mul (measurable_pairWithin _ + (continuous_radialPair_comp hφ continuous_subtype_val continuous_subtype_val).measurable))) + apply (lintegral_ofReal_ne_top_iff_integrable hm.aestronglyMeasurable + (Eventually.of_forall (fun s => mul_nonneg (hF _) (Real.exp_pos _).le))).mp + rw [lintegral_macroWeight hφ hb hq i β z F hF, + ← ENNReal.ofReal_tsum_of_nonneg (fun n => mul_nonneg (mul_nonneg (hF n) (Real.exp_pos _).le) (partition_nonneg _ _ _)) hs] + exact ENNReal.ofReal_ne_top + +lemma integral_macroWeight {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {q : ℕ} (hq : 0 < q) (i : Cell) (β z : ℝ) (F : ℕ → ℝ) (hF : ∀ n, 0 ≤ F n) + (hs : Summable (fun n => F n*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β)) : + (∫ s : ParticleState (macroRegion q i), F (particleCount s)* + Real.exp (-β*pairWithin (fun (x y : macroRegion q i) => radialPair φ x y) s) + ∂particleBase (regionMeasure (macroRegion q i)) z) = + ∑' n, F n*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β := by + rw [integral_eq_lintegral_of_nonneg_ae (Eventually.of_forall (fun s => mul_nonneg (hF _) (Real.exp_pos _).le)) + (integrable_macroWeight hφ hb hq i β z F hF hs).aestronglyMeasurable, + lintegral_macroWeight hφ hb hq i β z F hF, + ← ENNReal.ofReal_tsum_of_nonneg (fun n => mul_nonneg (mul_nonneg (hF n) (Real.exp_pos _).le) (partition_nonneg _ _ _)) hs, + ENNReal.toReal_ofReal (tsum_nonneg (fun n => mul_nonneg (mul_nonneg (hF n) (Real.exp_pos _).le) (partition_nonneg _ _ _)))] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/CroppedCells.lean b/lean/OAI/Probability/RadialTransition/CroppedCells.lean new file mode 100644 index 0000000000000000000000000000000000000000..2a9c18c61a1007a9f1b098155032cfd2f08c48b6 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/CroppedCells.lean @@ -0,0 +1,94 @@ +import OAI.Probability.RadialTransition.MultisetEnergy + +namespace OAI + +noncomputable section + + +open MeasureTheory Set Filter Function + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +lemma measurable_cellOf : Measurable cellOf := by + apply Measurable.of_eval + intro k + exact Int.measurable_floor.comp (measurable_const.mul (PiLp.continuous_apply 2 (fun _ : Fin 3 => ℝ) k).measurable) + +def gridRegion (k : Cell) : Set Position := {x | cellOf x = k} + +lemma measurableSet_gridRegion (k : Cell) : MeasurableSet (gridRegion k) := + measurable_cellOf (measurableSet_singleton k) + +abbrev CroppedCell (A : Set Position) (k : Cell) := {x : Position // x ∈ A ∩ gridRegion k} + +def croppedCellMeasure (A : Set Position) (k : Cell) : Measure (CroppedCell A k) := + volume.comap Subtype.val + +def gridOrigin (k : Cell) : Position := WithLp.toLp 2 (fun i => (k i : ℝ)/4) + +lemma gridRegion_subset_box (k : Cell) : gridRegion k ⊆ translateSet (gridOrigin k) (cube (1/4)) := by + intro x hx i + have hh : ⌊4*x i⌋ = k i := congrFun hx i + have hl := Int.floor_le (4*x i) + have hu := Int.lt_floor_add_one (4*x i) + rw [hh] at hl hu + change 0 ≤ x i - (k i : ℝ)/4 ∧ x i - (k i : ℝ)/4 ≤ 1/4 + constructor <;> linarith + +lemma volume_gridRegion_le (k : Cell) : volume (gridRegion k) ≤ ENNReal.ofReal (1/64:ℝ) := by + have hh := measure_mono (gridRegion_subset_box k) (μ := volume) + rw [volume_translateSet _ _ (measurableSet_cube _), volume_cube] at hh + rw [← ENNReal.ofReal_pow (by norm_num : (0:ℝ) ≤ 1/4)] at hh + norm_num at hh ⊢ + exact hh + +lemma croppedCellMeasure_univ {A : Set Position} (hA : MeasurableSet A) (k : Cell) : + croppedCellMeasure A k univ = volume (A ∩ gridRegion k) := by + rw [croppedCellMeasure, comap_subtype_coe_apply (hA.inter (measurableSet_gridRegion k))] + simp only [Set.image_univ, Subtype.range_coe] + +lemma croppedCellMeasure_finite {A : Set Position} (hA : MeasurableSet A) (k : Cell) : + IsFiniteMeasure (croppedCellMeasure A k) := by + constructor + rw [croppedCellMeasure_univ hA k] + exact ((measure_mono inter_subset_right).trans (volume_gridRegion_le k)).trans_lt ENNReal.ofReal_lt_top + +lemma croppedCellMeasure_volume {A : Set Position} (hA : MeasurableSet A) (k : Cell) : + ((croppedCellMeasure A k) univ).toReal ≤ 1/64 := by + rw [croppedCellMeasure_univ hA k] + have hh := ENNReal.toReal_mono ENNReal.ofReal_ne_top + ((measure_mono (inter_subset_right (s := A))).trans (volume_gridRegion_le k)) + simpa only [ENNReal.toReal_ofReal (by norm_num : (0:ℝ) ≤ 1/64)] using hh + +lemma croppedCellMeasure_map {A : Set Position} (hA : MeasurableSet A) (k : Cell) : + Measure.map Subtype.val (croppedCellMeasure A k) = volume.restrict (A ∩ gridRegion k) := + map_comap_subtype_coe (hA.inter (measurableSet_gridRegion k)) volume + +lemma croppedCell_diameter {A : Set Position} {k : Cell} (x y : CroppedCell A k) : + dist (x : Position) y ≤ 1 := + same_cell_diameter (x.property.2.trans y.property.2.symm) + +lemma croppedCell_partition {I : Type} [Fintype I] (e : I → Cell) (he : Function.Injective e) + {A : Set Position} (hA : MeasurableSet A) (hcover : ∀ x ∈ A, ∃ i, cellOf x = e i) : + volume.restrict A = ∑ i, Measure.map Subtype.val (croppedCellMeasure A (e i)) := by + have hd : Pairwise (Disjoint on (fun i => A ∩ gridRegion (e i))) := by + intro i j hij + apply Set.disjoint_left.mpr + intro x hx hy + exact hij (he (hx.2.symm.trans hy.2)) + have hu : (⋃ i, A ∩ gridRegion (e i)) = A := by + ext x + simp only [mem_iUnion, mem_inter_iff, gridRegion, mem_ofPred_eq] + exact ⟨fun ⟨_,hx,_⟩ => hx, fun hx => by obtain ⟨i,hi⟩ := hcover x hx; exact ⟨i,hx,hi⟩⟩ + rw [← hu, Measure.restrict_iUnion hd (fun i => hA.inter (measurableSet_gridRegion (e i))), Measure.sum_fintype] + apply Finset.sum_congr rfl + intro i _ + rw [hu, croppedCellMeasure_map hA] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/DeletedInteractions.lean b/lean/OAI/Probability/RadialTransition/DeletedInteractions.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ab78bd79f7c76768166018e775fd2547198f9bd --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/DeletedInteractions.lean @@ -0,0 +1,156 @@ +import OAI.Probability.RadialTransition.PairEnsembles + +namespace OAI + +universe uG + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +theorem pairGrand_grid_perturbation {I : Type} [Fintype I] [DecidableEq I] [Nonempty I] + (e : I → Cell) (he : Function.Injective e) {A : Set Position} + (hA : MeasurableSet A) (hcover : ∀ x ∈ A, ∃ i, cellOf x = e i) + (v w : Position → Position → ℝ) + (hv : Measurable (Function.uncurry v)) (hw : Measurable (Function.uncurry w)) + (hvcell : ∀ i j, Continuous (fun p : CroppedCell A (e i) × CroppedCell A (e j) => v p.1 p.2)) + (hwcell : ∀ i j, Continuous (fun p : CroppedCell A (e i) × CroppedCell A (e j) => w p.1 p.2)) + (hvsym : ∀ x y, v x y = v y x) (hwsym : ∀ x y, w x y = w y x) + {t β : ℝ} (ht : 0 < t) (hβ : 0 < β) (z : ℝ) + (J K : Cell → Cell → ℝ) + (hJ : ∀ i j, 0 ≤ J i j) (hJsym : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J (e i) (e j) ≤ (t^2/8)/8) + (hintrav : ∀ x y, cellOf x = cellOf y → corePotential t (nndist x y)-J (cellOf x) (cellOf y) ≤ v x y) + (hcrossv : ∀ x y, -J (cellOf x) (cellOf y) ≤ v x y) + (hintraw : ∀ x y, cellOf x = cellOf y → corePotential t (nndist x y)-J (cellOf x) (cellOf y) ≤ w x y) + (hcrossw : ∀ x y, -J (cellOf x) (cellOf y) ≤ w x y) + (hK : ∀ i j, 0 ≤ K i j) + (hd : ∀ x y, |w x y-v x y| ≤ K (cellOf x) (cellOf y)) : + |Real.log (pairGrand v (volume.restrict A) β z)-Real.log (pairGrand w (volume.restrict A) β z)| ≤ + β/2 * localMomentBound t β z * ∑ i, ∑ j, K (e i) (e j) := by + let X i := CroppedCell A (e i) + let ν i := croppedCellMeasure A (e i) + let : ∀ i, IsFiniteMeasure (ν i) := fun i => croppedCellMeasure_finite hA (e i) + let pos : ∀ i, X i → Position := fun _ => Subtype.val + have hpos (i : I) : Measurable (pos i) := measurable_subtype_coe + have hcell (i : I) (x : X i) : cellOf (pos i x) = e i := x.property.2 + have heqv := pairGrand_eq_cell X ν pos hpos v hv hvsym (croppedCell_partition e he hA hcover) β z + have heqw := pairGrand_eq_cell X ν pos hpos w hw hwsym (croppedCell_partition e he hA hcover) β z + rw [heqv, heqw] + apply pairCell_log_perturbation ν pos (fun i => croppedCell_diameter) ht hβ (by norm_num) + (fun i => croppedCellMeasure_volume hA (e i)) + (fun i j x y => v (pos i x) (pos j y)) (fun i j x y => w (pos i x) (pos j y)) + hvcell hwcell (fun i j x y => hvsym _ _) (fun i j x y => hwsym _ _) + (fun i j => J (e i) (e j)) (fun i j => hJ _ _) (fun i j => hJsym _ _) hrow + · intro i x y + simpa only [hcell] using hintrav (pos i x) (pos i y) ((hcell i x).trans (hcell i y).symm) + · intro i j x y + simpa only [hcell] using hcrossv (pos i x) (pos j y) + · intro i x y + simpa only [hcell] using hintraw (pos i x) (pos i y) ((hcell i x).trans (hcell i y).symm) + · intro i j x y + simpa only [hcell] using hcrossw (pos i x) (pos j y) + · exact fun i j => hK _ _ + · intro i j x y + simpa only [hcell] using hd (pos i x) (pos j y) + +def deletedPair {G : Type uG} [DecidableEq G] (g : Cell → G) (φ χ : Potential) + (x y : Position) : ℝ := + (if g (cellOf x) = g (cellOf y) then radialPair φ x y else 0) + radialPair χ x y + +lemma measurable_deletedPair {G : Type uG} [DecidableEq G] (g : Cell → G) + {φ χ : Potential} (hφ : Continuous φ) (hχ : Continuous χ) : + Measurable (Function.uncurry (deletedPair g φ χ)) := by + have hp : MeasurableSet {p : Position × Position | g (cellOf p.1) = g (cellOf p.2)} := by + have hh : MeasurableSet {p : Cell × Cell | g p.1 = g p.2} := Set.to_countable _ |>.measurableSet + exact hh.preimage ((measurable_cellOf.comp measurable_fst).prodMk (measurable_cellOf.comp measurable_snd)) + exact ((continuous_radialPair hφ).measurable.ite hp measurable_const).add + (continuous_radialPair hχ).measurable + +lemma deletedPair_symm {G : Type uG} [DecidableEq G] (g : Cell → G) (φ χ : Potential) (x y : Position) : + deletedPair g φ χ x y = deletedPair g φ χ y x := by + simp only [deletedPair, show (g (cellOf y) = g (cellOf x)) = (g (cellOf x) = g (cellOf y)) from propext eq_comm, radialPair_symm φ y x, radialPair_symm χ y x] + +lemma continuous_deletedPair_cell {G : Type uG} [DecidableEq G] (g : Cell → G) + {φ χ : Potential} (hφ : Continuous φ) (hχ : Continuous χ) + (A : Set Position) (i j : Cell) : + Continuous (fun p : CroppedCell A i × CroppedCell A j => deletedPair g φ χ p.1 p.2) := by + have he : (fun p : CroppedCell A i × CroppedCell A j => deletedPair g φ χ p.1 p.2) = + (fun p => (if g i = g j then radialPair φ p.1 p.2 else 0)+radialPair χ p.1 p.2) := by + funext p + have h₁ : cellOf (p.1 : Position) = i := p.1.property.2 + have h₂ : cellOf (p.2 : Position) = j := p.2.property.2 + simp only [deletedPair, h₁, h₂] + rw [he] + apply Continuous.add + · split_ifs + · exact continuous_radialPair_comp hφ continuous_subtype_val continuous_subtype_val + · exact continuous_const + · exact continuous_radialPair_comp hχ continuous_subtype_val continuous_subtype_val + +def deletionMajorant {G : Type uG} [DecidableEq G] (g : Cell → G) (W : Cell → Cell → ℝ) + (i j : Cell) : ℝ := if g i = g j then 0 else W i j + +lemma deletionMajorant_nonneg {G : Type uG} [DecidableEq G] (g : Cell → G) + {W : Cell → Cell → ℝ} (hW : ∀ i j, 0 ≤ W i j) (i j : Cell) : + 0 ≤ deletionMajorant g W i j := ite_nonneg le_rfl (hW i j) + +theorem deletedPair_grid_bound {I G : Type} [Fintype I] [DecidableEq I] [Nonempty I] [DecidableEq G] + (e : I → Cell) (he : Function.Injective e) (g : Cell → G) {A : Set Position} + (hA : MeasurableSet A) (hcover : ∀ x ∈ A, ∃ i, cellOf x = e i) + {φ χ : Potential} (hφ : Continuous φ) (hχ : Continuous χ) + {t β : ℝ} (ht : 0 < t) (hβ : 0 < β) (z : ℝ) + (J₀ J₁ W : Cell → Cell → ℝ) + (hJ₀ : ∀ i j, 0 ≤ J₀ i j) (hJ₁ : ∀ i j, 0 ≤ J₁ i j) + (hJsym : ∀ i j, J₀ i j + J₁ i j = J₀ j i + J₁ j i) + (hrow : ∀ i, ∑ j, (J₀ (e i) (e j)+J₁ (e i) (e j)) ≤ (t^2/8)/8) + (hlφ : ∀ x y, corePotential t (nndist x y)-J₀ (cellOf x) (cellOf y) ≤ radialPair φ x y) + (hlχ : ∀ x y, -J₁ (cellOf x) (cellOf y) ≤ radialPair χ x y) + (hW : ∀ i j, 0 ≤ W i j) (hbφ : ∀ x y, |radialPair φ x y| ≤ W (cellOf x) (cellOf y)) : + |Real.log (pairGrand (radialPair (φ+χ)) (volume.restrict A) β z)- + Real.log (pairGrand (deletedPair g φ χ) (volume.restrict A) β z)| ≤ + β/2 * localMomentBound t β z * ∑ i, ∑ j, deletionMajorant g W (e i) (e j) := by + have hcore (x y : Position) : 0 ≤ corePotential t (nndist x y) := coreReal_nonneg _ _ + have hall (x y : Position) : corePotential t (nndist x y)-(J₀ (cellOf x) (cellOf y)+J₁ (cellOf x) (cellOf y)) ≤ + radialPair (φ+χ) x y := by + change _ ≤ radialPair φ x y+radialPair χ x y + linarith [hlφ x y, hlχ x y] + have hd (x y : Position) : |deletedPair g φ χ x y-radialPair (φ+χ) x y| ≤ + deletionMajorant g W (cellOf x) (cellOf y) := by + unfold deletedPair deletionMajorant + change |(if _ then _ else _)+radialPair χ x y-(radialPair φ x y+radialPair χ x y)| ≤ _ + split_ifs with h + · simp only [sub_self, abs_zero, le_refl] + · rw [show (0:ℝ)+radialPair χ x y-(radialPair φ x y+radialPair χ x y) = -radialPair φ x y by ring, abs_neg] + exact hbφ x y + apply pairGrand_grid_perturbation e he hA hcover (radialPair (φ+χ)) (deletedPair g φ χ) + (continuous_radialPair (hφ.add hχ)).measurable (measurable_deletedPair g hφ hχ) + (fun i j => continuous_radialPair_comp (hφ.add hχ) continuous_subtype_val continuous_subtype_val) + (fun i j => continuous_deletedPair_cell g hφ hχ A (e i) (e j)) + (radialPair_symm _) (deletedPair_symm g φ χ) ht hβ z + (fun i j => J₀ i j+J₁ i j) (deletionMajorant g W) + (fun i j => add_nonneg (hJ₀ i j) (hJ₁ i j)) hJsym hrow + · exact fun x y _ => hall x y + · intro x y; linarith [hall x y, hcore x y] + · intro x y heq + change _ ≤ (if g (cellOf x) = g (cellOf y) then radialPair φ x y else 0)+radialPair χ x y + rw [ite_eq_left (congrArg g heq)] + exact hall x y + · intro x y + unfold deletedPair + split_ifs + · linarith [hlφ x y, hlχ x y, hcore x y] + · linarith [hlχ x y, hJ₀ (cellOf x) (cellOf y)] + · exact deletionMajorant_nonneg g hW + · exact hd + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/DensityInterval.lean b/lean/OAI/Probability/RadialTransition/DensityInterval.lean new file mode 100644 index 0000000000000000000000000000000000000000..a3fc4a9560db69ad6dcd8ae03af6c8a083a262b0 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/DensityInterval.lean @@ -0,0 +1,109 @@ +import OAI.Probability.RadialTransition.Main + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal ENNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma support_ball_two_pressures_nearby {Q : Pressure} {x : Parameter} {ρ : ℝ} + (hs : Metric.closedBall targetSlope pressureRadius ⊆ + supportSet (onParameters Q) positiveParameters x) + (hρ : |ρ - 5*packingDensity/3| < pressureRadius/2) : + pressureSupport Q (x 0) (x 1) (17*packingDensity/4-pressureRadius/2) ρ ∧ + pressureSupport Q (x 0) (x 1) (17*packingDensity/4+pressureRadius/2) ρ := by + have hmem (z : ℝ) (hz : |z| ≤ pressureRadius/2) : + parameter (17*packingDensity/4+z) ρ ∈ + Metric.closedBall targetSlope pressureRadius := by + rw [Metric.mem_closedBall, dist_eq_norm, targetSlope, parameter_sub] + have he : 17*packingDensity/4+z-17*packingDensity/4 = z := by ring + rw [he] + apply (parameter_norm_le _).trans + simp only [parameter_zero, parameter_one] + linarith + have hpos := pressureRadius_pos + have hs₁ := pressureSupport_iff.mpr + (hs (hmem (-pressureRadius/2) (by rw [abs_of_nonpos (by linarith)]; linarith))) + have hs₂ := pressureSupport_iff.mpr + (hs (hmem (pressureRadius/2) (by rw [abs_of_pos (by positivity)]))) + simpa only [parameter_zero, parameter_one, sub_eq_add_neg, neg_div] using + And.intro hs₁ hs₂ + +theorem densityInterval : + ∃ (p : ℝ) (φ : Potential) (B C η βc : ℝ) (f : ℝ → ℝ → ℝ), + 0 < p ∧ IsPackingDensity p ∧ + IsBoundedPotential φ ∧ Continuous φ ∧ + 0 < B ∧ 0 < C ∧ StableWith φ B ∧ AlgebraicDecayWith φ C ∧ + 0 < η ∧ Ioo (5*p/3 - η) (5*p/3 + η) ⊆ Ioi 0 ∧ + βc ∈ Icc (7/8:ℝ) (9/8) ∧ + ∀ ρ ∈ Ioo (5*p/3 - η) (5*p/3 + η), + IsCanonicalFreeEnergy φ ρ (fun β => f β ρ) ∧ + StrictTemperatureCorner (fun β => f β ρ) βc := by + obtain ⟨t,b,ht,hb,hrow,x,hx,hsupport⟩ := exists_family_pressure_ball + have ht0 : 0 < t := by linarith + have had := iteration_admissible hb t + let φ := familyPotential t (iterationMass b) (scaleRange b) + let ρ₀ := 5*packingDensity/3 + have hρ₀ : 0 < ρ₀ := by dsimp [ρ₀]; have := packingDensity_pos; positivity + let η := min (pressureRadius/2) (ρ₀/2) + have hη : 0 < η := lt_min (by have := pressureRadius_pos; positivity) (by positivity) + have hηγ : η ≤ pressureRadius/2 := min_le_left _ _ + have hηρ : η ≤ ρ₀/2 := min_le_right _ _ + have hI : Ioo (ρ₀-η) (ρ₀+η) ⊆ Ioi 0 := by + intro ρ hρ + change 0 < ρ + linarith [hρ.1] + have hφ : Continuous φ := continuous_familyPotential had.1 had.2.1 had.2.2.1 t + have hbd : IsBoundedPotential φ := bounded_familyPotential had.1 had.2.1 had.2.2.1 t + have hrow' := admissible_row ht0.le had hrow + have hcoerc : 2197*t*bumpIntegral⁻¹*(∑' n, iterationMass b n)/2 ≤ t^2/16 := by + nlinarith [sq_nonneg t] + have hst : StableWith φ (t^2/2) := + stable_family_of_master ht0.le had.1 had.2.1 had.2.2.1 had.2.2.1 (fun _ => le_rfl) hrow' + have hc : ∀ r : ℝ≥0, 2 ≤ (r:ℝ) → φ r ≤ 0 := fun _ hr => + familyPotential_nonpos_outer had.1 had.2.1 ht hr + have hlim (β d : ℝ) (hβ : 0 ≤ β) (hd : 0 ≤ d) := + (familyCanonicalThermo_spec ht had.1 had.2.1 had.2.2.1 hcoerc hβ hd).1 + let f := fun β ρ => t*canonicalThermo φ t β ρ/β + have hβ : 0 < x 0 := phaseWindow_positive (by norm_num) hx + have hβband : x 0 ∈ Icc (7/8:ℝ) (9/8) := by + have hh := abs_le.mp (phaseWindow_coords hx).1 + constructor <;> linarith + let C := t^2*(2:ℝ)^(3+1/32:ℝ)+ + t*bumpIntegral⁻¹*(∑' n, iterationMass b n*(scaleRange b n)^(1/32:ℝ)) + have hC : 0 < C := by + have hw0 : 0 ≤ ∑' n, iterationMass b n*(scaleRange b n)^(1/32:ℝ) := by + apply tsum_nonneg + intro n + exact mul_nonneg (had.1 n) (Real.rpow_nonneg (scaleRange_pos (by linarith) n).le _) + have hbi := bumpIntegral_pos + dsimp [C] + positivity + refine ⟨packingDensity,φ,t^2/2,C,η,x 0,f,packingDensity_pos,packingDensity_limit, + hbd,hφ,by positivity,hC,hst, + decay_familyPotential ht had.1 had.2.1 had.2.2.1 (iterationMass_weight_summable hb), + hη,hI,hβband,?_⟩ + intro ρ hρI + change ρ ∈ Ioo (ρ₀-η) (ρ₀+η) at hρI + have hρ : 0 < ρ := hI hρI + have hdensity : |ρ - 5*packingDensity/3| < pressureRadius/2 := by + change |ρ - ρ₀| < pressureRadius/2 + exact abs_lt.mpr ⟨by linarith [hρI.1], by linarith [hρI.2]⟩ + have hf : IsCanonicalFreeEnergy φ ρ (fun β => f β ρ) := + family_free_energy ht hρ.le had.1 had.2.1 had.2.2.1 hcoerc + have hdual (β : ℝ) (hβ : 0 < β) : canonicalThermo φ t β ρ = + sSup (Set.range fun h : ℝ => h*ρ-grandPressure φ t β h) := + canonical_dual_sup hφ hbd hst ht0 hβ.le hρ hc (fun d hd => hlim β d hβ.le hd) + have hconc : ConcaveOn ℝ (Ioi 0) (fun β => canonicalThermo φ t β ρ) := + canonicalThermo_concave hφ hbd ht0 hρ.le (fun β hβ => hlim β ρ hβ.le hρ.le) + obtain ⟨hs₁,hs₂⟩ := support_ball_two_pressures_nearby hsupport hdensity + exact ⟨hf, canonical_corner_of_pressure_supports hβ ht0 + (show 17*packingDensity/4-pressureRadius/2 < + 17*packingDensity/4+pressureRadius/2 by linarith [pressureRadius_pos]) + hdual hconc hs₁ hs₂⟩ + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/DensityMixtures.lean b/lean/OAI/Probability/RadialTransition/DensityMixtures.lean new file mode 100644 index 0000000000000000000000000000000000000000..7edf86f36fc7739a6543e5656f3b7529cde2618a --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/DensityMixtures.lean @@ -0,0 +1,173 @@ +import OAI.Probability.RadialTransition.CanonicalLimit + +namespace OAI + +universe uG + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +lemma sum_fin_two {G : Type uG} [AddCommMonoid G] (k r : ℕ) (hr : r ≤ k) (u v : G) : + (∑ i : Fin k, if (i : ℕ) < r then u else v) = r • u + (k - r) • v := by + rw [Finset.sum_ite] + simp only [Finset.sum_const, Fin.card_filter_val_lt, min_eq_right hr] + congr 1 + have he : (Finset.univ.filter (fun i : Fin k => ¬(i : ℕ) < r)).card = k - r := by + rw [Finset.filter_not, Finset.card_sdiff_of_subset (Finset.filter_subset _ _)] + simp only [Finset.card_univ, Fintype.card_fin, Fin.card_filter_val_lt, min_eq_right hr] + rw [he] + +theorem boxCost_limit_convex {H : ℝ → ℕ → ℝ} {A : ℝ → ℝ} + (hrep : HasBoxReplication H) + (hlim : ∀ d : ℝ, 0 ≤ d → Tendsto (fun z : ℝ × ℕ => H z.1 z.2) + (thermodynamicFilter d) (nhds (A d))) : ConvexOn ℝ (Ici 0) A := by + refine ⟨convex_Ici _, ?_⟩ + intro d₁ hd₁ d₂ hd₂ a b ha hb hab + simp only [smul_eq_mul] + have ha1 : a ≤ 1 := by linarith + let B (j : ℕ) : ℕ := j + 1 + let s (j : ℕ) : ℝ := B j + let k (j : ℕ) : ℕ := B j ^ 3 + let r (j : ℕ) : ℕ := ⌊a * (k j : ℝ)⌋₊ + let m₁ (j : ℕ) : ℕ := ⌊d₁ * s j ^ 3⌋₊ + let m₂ (j : ℕ) : ℕ := ⌊d₂ * s j ^ 3⌋₊ + let N (j : ℕ) : ℕ := r j * m₁ j + (k j - r j) * m₂ j + let L (j : ℕ) : ℝ := (B j : ℝ) * (s j + 2) + have hspos (j : ℕ) : 0 < s j := by dsimp [s, B]; positivity + have hkpos (j : ℕ) : 0 < (k j : ℝ) := by dsimp [k, B]; positivity + have hkr (j : ℕ) : r j ≤ k j := by + apply Nat.floor_le_of_le + exact mul_le_of_le_one_left (by positivity) ha1 + have hs : Tendsto s atTop atTop := by + have hh := tendsto_atTop_add_const_right atTop (1 : ℝ) + (tendsto_natCast_atTop_atTop : Tendsto (fun j : ℕ => (j : ℝ)) atTop atTop) + simpa only [s, B, Nat.cast_add, Nat.cast_one] using hh + have hk : Tendsto (fun j => (k j : ℝ)) atTop atTop := by + simpa only [k, s, Nat.cast_pow, Function.comp_def] using (tendsto_pow_atTop (by norm_num : 3 ≠ 0)).comp hs + have hr : Tendsto (fun j => (r j : ℝ) / k j) atTop (nhds a) := + (tendsto_nat_floor_mul_div_atTop ha).comp hk + have hrem : Tendsto (fun j => ((k j - r j : ℕ) : ℝ) / k j) atTop (nhds b) := by + have hh := hr.const_sub 1 + rw [show 1 - a = b by linarith] at hh + apply hh.congr' + exact Eventually.of_forall (fun j => by dsimp only; rw [Nat.cast_sub (hkr j)]; field_simp [(hkpos j).ne']) + have hm₁ : Tendsto (fun j => (m₁ j : ℝ) / s j ^ 3) atTop (nhds d₁) := + (floor_density_tendsto hd₁).comp hs + have hm₂ : Tendsto (fun j => (m₂ j : ℝ) / s j ^ 3) atTop (nhds d₂) := + (floor_density_tendsto hd₂).comp hs + have hratio : Tendsto (fun j => (s j / (s j + 2)) ^ 3) atTop (nhds 1) := by + simpa only [one_pow, Function.comp_def] using (tendsto_side_ratio.comp hs).pow 3 + have hL : Tendsto L atTop atTop := hs.atTop_mul_atTop₀ + (tendsto_atTop_add_const_right atTop (2 : ℝ) hs) + have hden : Tendsto (fun j => (N j : ℝ) / L j ^ 3) atTop (nhds (a * d₁ + b * d₂)) := by + have hh := hratio.mul ((hr.mul hm₁).add (hrem.mul hm₂)) + simp only [one_mul] at hh + apply hh.congr' + refine Eventually.of_forall (fun j => ?_) + have hs0 := (hspos j).ne' + have hk0 := (hkpos j).ne' + have hsum0 : s j + 2 ≠ 0 := by linarith [hspos j] + dsimp only [N, L, Function.comp_def] + rw [Nat.cast_add, Nat.cast_mul, Nat.cast_mul] + have hkEq : (B j : ℝ) ^ 3 = k j := by simp [k] + rw [mul_pow, hkEq] + have hsk : s j ^ 3 = (k j : ℝ) := hkEq + field_simp + rw [hsk] + have hnl : Tendsto (fun j => (L j, N j)) atTop (thermodynamicFilter (a * d₁ + b * d₂)) := by + apply tendsto_inf.mpr + exact ⟨tendsto_comap_iff.mpr hL, tendsto_comap_iff.mpr hden⟩ + have hH : Tendsto (fun j => H (L j) (N j)) atTop (nhds (A (a * d₁ + b * d₂))) := + (hlim _ (add_nonneg (mul_nonneg ha hd₁) (mul_nonneg hb hd₂))).comp hnl + have hH₁ : Tendsto (fun j => H (s j) (m₁ j)) atTop (nhds (A d₁)) := + (hlim d₁ hd₁).comp ((floor_tendsto_thermodynamicFilter hd₁).comp hs) + have hH₂ : Tendsto (fun j => H (s j) (m₂ j)) atTop (nhds (A d₂)) := + (hlim d₂ hd₂).comp ((floor_tendsto_thermodynamicFilter hd₂).comp hs) + have hupper : Tendsto (fun j => (s j / (s j + 2)) ^ 3 * + ((r j : ℝ) / k j * H (s j) (m₁ j) + ((k j - r j : ℕ) : ℝ) / k j * H (s j) (m₂ j))) + atTop (nhds (a * A d₁ + b * A d₂)) := by + simpa only [one_mul] using hratio.mul ((hr.mul hH₁).add (hrem.mul hH₂)) + apply le_of_tendsto_of_tendsto hH hupper + refine Eventually.of_forall (fun j => ?_) + let f : Fin (k j) → ℕ := fun i => if (i : ℕ) < r j then m₁ j else m₂ j + have hsum : (∑ i, f i) = N j := by + simpa only [f, N, nsmul_eq_mul, smul_eq_mul] using sum_fin_two (k j) (r j) (hkr j) (m₁ j) (m₂ j) + have hcost : (∑ i, H (s j) (f i)) = (r j : ℝ) * H (s j) (m₁ j) + + ((k j - r j : ℕ) : ℝ) * H (s j) (m₂ j) := by + dsimp only [f] + simp only [apply_ite] + simpa only [nsmul_eq_mul] using sum_fin_two (k j) (r j) (hkr j) + (H (s j) (m₁ j)) (H (s j) (m₂ j)) + have hh := hrep (s j) (L j) (B j) (hspos j) + (by dsimp [L]; positivity) le_rfl f + rw [hsum, hcost] at hh + apply hh.trans_eq + have hs0 := (hspos j).ne' + have hk0 := (hkpos j).ne' + have hsum0 : s j + 2 ≠ 0 := by linarith [hspos j] + dsimp only [L] + have hkEq : (B j : ℝ) ^ 3 = k j := by simp [k] + rw [mul_pow, hkEq] + have hsk : s j ^ 3 = (k j : ℝ) := hkEq + field_simp + rw [hsk] + +def finiteGrandPressure (φ : Potential) (t L β h : ℝ) : ℝ := + Real.log (grandPartition φ t L β h) / (t * L ^ 3) + +def grandPressure (φ : Potential) (t : ℝ) : Pressure := + fun β h => limsup (fun L : ℝ => finiteGrandPressure φ t L β h) atTop + +theorem grandPressure_spec {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t β : ℝ} (hstable : StableWith φ B) (ht : 0 < t) (hβ : 0 ≤ β) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) (h : ℝ) : + Tendsto (fun L : ℝ => finiteGrandPressure φ t L β h) atTop (nhds (grandPressure φ t β h)) ∧ + 0 ≤ grandPressure φ t β h ∧ grandPressure φ t β h ≤ Real.exp (β * B + t * h) / t := by + obtain ⟨p, hp0, hpB, hlim⟩ := grandPressure_exists hφ hb hstable ht hβ hc h + have he : grandPressure φ t β h = p := hlim.limsup_eq + rw [he] + exact ⟨hlim, hp0, hpB⟩ + +theorem finiteGrandPressure_convex_mix {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t L β γ a b : ℝ} (hstable : StableWith φ B) (ht : 0 < t) (hL : 0 < L) + (hβ : 0 ≤ β) (hγ : 0 ≤ γ) (h j : ℝ) (ha : 0 ≤ a) (hbb : 0 ≤ b) (hab : a + b = 1) : + finiteGrandPressure φ t L (a * β + b * γ) (a * h + b * j) ≤ + a * finiteGrandPressure φ t L β h + b * finiteGrandPressure φ t L γ j := by + have hmix : 0 ≤ a * β + b * γ := by positivity + have hh := log_tsum_convex_mix ha hbb hab + (grandPartition_summable hφ hb hstable hL.le hmix t (a * h + b * j)) + (grandPartition_summable hφ hb hstable hL.le hβ t h) + (grandPartition_summable hφ hb hstable hL.le hγ t j) + (fun n => mul_pos (Real.exp_pos _) (partition_pos hφ hb hL n _)) + (fun n => mul_pos (Real.exp_pos _) (partition_pos hφ hb hL n _)) + (fun n => mul_pos (Real.exp_pos _) (partition_pos hφ hb hL n _)) + (fun n => by + simp only [Real.log_mul (Real.exp_ne_zero _) (partition_pos hφ hb hL n _).ne', Real.log_exp] + have hh := log_partition_convex_mix hφ hb hL n β γ ha hbb hab + nlinarith) + dsimp only [finiteGrandPressure] + have hh' := div_le_div_of_nonneg_right hh (show 0 ≤ t * L ^ 3 by positivity) + simpa only [grandPartition, add_div, mul_div_assoc] using hh' + +theorem grandPressure_convex_mix {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t β γ a b : ℝ} (hstable : StableWith φ B) (ht : 0 < t) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) + (hβ : 0 ≤ β) (hγ : 0 ≤ γ) (h j : ℝ) (ha : 0 ≤ a) (hbb : 0 ≤ b) (hab : a + b = 1) : + grandPressure φ t (a * β + b * γ) (a * h + b * j) ≤ + a * grandPressure φ t β h + b * grandPressure φ t γ j := by + have hl := (grandPressure_spec hφ hb hstable ht (β := a * β + b * γ) (by positivity) hc (a * h + b * j)).1 + have hr := ((grandPressure_spec hφ hb hstable ht hβ hc h).1.const_mul a).add + ((grandPressure_spec hφ hb hstable ht hγ hc j).1.const_mul b) + apply le_of_tendsto_of_tendsto hl hr + filter_upwards [eventually_gt_atTop (0 : ℝ)] with L hL + exact finiteGrandPressure_convex_mix hφ hb hstable ht hL hβ hγ h j ha hbb hab + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/EnvelopeSupport.lean b/lean/OAI/Probability/RadialTransition/EnvelopeSupport.lean new file mode 100644 index 0000000000000000000000000000000000000000..1637aa2adb17c40a2c67bcc7b3b2a02b1b5dc2e7 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/EnvelopeSupport.lean @@ -0,0 +1,168 @@ +import OAI.Probability.RadialTransition.BoundedCore + +namespace OAI + +universe uE uX uY + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +section CompactEnvelope + +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +theorem support_norm_bound {F : E → ℝ} {D : Set E} {x v : E} {r M : ℝ} + (hr : 0 < r) (hM : 0 ≤ M) (hball : Metric.closedBall x r ⊆ D) + (hbound : ∀ y ∈ Metric.closedBall x r, |F y| ≤ M) + (hv : SupportsOn F D x v) : ‖v‖ ≤ 2 * M / r := by + apply norm_le_of_unit_inner_le _ (by positivity) + intro z hz + have hy : x + r • z ∈ Metric.closedBall x r := by + simp [Metric.mem_closedBall, dist_eq_norm, norm_smul, abs_of_pos hr, hz] + have hx : x ∈ Metric.closedBall x r := Metric.mem_closedBall_self hr.le + have hh := hv (x + r • z) (hball hy) + simp only [add_sub_cancel_left, real_inner_smul_right] at hh + have hlo := (abs_le.mp (hbound x hx)).1 + have hhi := (abs_le.mp (hbound _ hy)).2 + apply (le_div_iff₀ hr).mpr + nlinarith + +theorem supportsOn_of_tendsto {F : ℕ → E → ℝ} {F₀ : E → ℝ} {D : Set E} + {x v : ℕ → E} {x₀ v₀ : E} + (hx : Tendsto x atTop (nhds x₀)) (hv : Tendsto v atTop (nhds v₀)) + (hbase : Tendsto (fun n => F n (x n)) atTop (nhds (F₀ x₀))) + (hpoint : ∀ y ∈ D, Tendsto (fun n => F n y) atTop (nhds (F₀ y))) + (hs : ∀ n, SupportsOn (F n) D (x n) (v n)) : + SupportsOn F₀ D x₀ v₀ := by + intro y hy + exact le_of_tendsto_of_tendsto + (hbase.add (hv.inner (tendsto_const_nhds.sub hx))) (hpoint y hy) + (Eventually.of_forall fun n => hs n y hy) + +theorem continuousOn_tendsto_sequence {X : Type uX} {Y : Type uY} [TopologicalSpace X] + [TopologicalSpace Y] {f : X → Y} {S : Set X} (hf : ContinuousOn f S) + {a : X} (ha : a ∈ S) {s : ℕ → X} (hs : ∀ n, s n ∈ S) + (hsa : Tendsto s atTop (nhds a)) : Tendsto (fun n => f (s n)) atTop (nhds (f a)) := by + apply (hf.continuousWithinAt ha).tendsto.comp + exact tendsto_nhdsWithin_iff.mpr ⟨hsa, Eventually.of_forall hs⟩ + +theorem supportSet_envelope_closedHull [FiniteDimensional ℝ E] + {F : ℝ → E → ℝ} {P : E → ℝ} {D : Set E} {K : Set ℝ} {x : E} {r : ℝ} + (hD : IsOpen D) (hK : IsCompact K) (hr : 0 < r) + (hball : Metric.closedBall x (2 * r) ⊆ D) + (hF : ∀ i ∈ K, ConvexOn ℝ D (F i)) + (hFc : ContinuousOn (fun z : ℝ × E => F z.1 z.2) (K ×ˢ D)) + (hPc : ContinuousOn P D) + (hle : ∀ i ∈ K, ∀ y ∈ D, F i y ≤ P y) + (hactive : ∀ y ∈ Metric.closedBall x r, ∃ i ∈ K, F i y = P y) : + supportSet P D x = closure (convexHull ℝ + {v | ∃ i ∈ K, F i x = P x ∧ SupportsOn (F i) D x v}) := by + classical + let G : Set E := {v | ∃ i ∈ K, F i x = P x ∧ SupportsOn (F i) D x v} + have hx : x ∈ D := hball (Metric.mem_closedBall_self (by positivity)) + have hG : G ⊆ supportSet P D x := by + rintro v ⟨i, hi, heq, hv⟩ y hy + rw [← heq] + exact (hv y hy).trans (hle i hi y hy) + have hback : closure (convexHull ℝ G) ⊆ supportSet P D x := + closure_minimal (convexHull_min hG (convex_supportSet P D x)) + (isClosed_supportSet P D x) + apply Set.Subset.antisymm ?_ hback + intro v hv + by_contra hvout + obtain ⟨ell, c, hsep, hvc⟩ := geometric_hahn_banach_closed_point + (convex_convexHull ℝ G).closure isClosed_closure hvout + let z : E := (InnerProductSpace.toDual ℝ E).symm ell + have hell (w : E) : inner ℝ w z = ell w := by + rw [real_inner_comm] + exact InnerProductSpace.toDual_symm_apply + obtain ⟨M₀, hM₀⟩ := (hK.prod (isCompact_closedBall x (2 * r))).exists_bound_of_continuousOn + (hFc.mono (Set.prod_mono Subset.rfl hball)) + let M := max 0 M₀ + have hM : 0 ≤ M := le_max_left _ _ + have hbound (i : ℝ) (hi : i ∈ K) (y : E) (hy : y ∈ Metric.closedBall x (2 * r)) : + |F i y| ≤ M := (hM₀ (i, y) ⟨hi, hy⟩).trans (le_max_right _ _) + let s : ℕ → ℝ := fun n => (r / (‖z‖ + 1)) * (1 / ((n : ℝ) + 1)) + have hspos (n : ℕ) : 0 < s n := by dsimp [s]; positivity + have hsbound (n : ℕ) : s n * ‖z‖ ≤ r := by + have hn : 1 ≤ (n : ℝ) + 1 := by have := Nat.cast_nonneg (α := ℝ) n; linarith + have hden : 0 < ‖z‖ + 1 := by positivity + have hdiv : 1 / ((n : ℝ) + 1) ≤ 1 := (div_le_one (by positivity)).mpr hn + have hq : r / (‖z‖ + 1) * ‖z‖ ≤ r := by + rw [div_mul_eq_mul_div] + exact (div_le_iff₀ hden).mpr (show r * ‖z‖ ≤ r * (‖z‖ + 1) by nlinarith) + calc + s n * ‖z‖ = (r / (‖z‖ + 1) * ‖z‖) * (1 / ((n : ℝ) + 1)) := by dsimp [s]; ring + _ ≤ (r / (‖z‖ + 1) * ‖z‖) * 1 := + mul_le_mul_of_nonneg_left hdiv (by positivity) + _ ≤ r := by simpa using hq + have hs0 : Tendsto s atTop (nhds 0) := by + simpa [s] using tendsto_one_div_add_atTop_nhds_zero_nat.const_mul (r / (‖z‖ + 1)) + let y : ℕ → E := fun n => x + s n • z + have hymem (n : ℕ) : y n ∈ Metric.closedBall x r := by + simpa [y, Metric.mem_closedBall, dist_eq_norm, norm_smul, abs_of_pos (hspos n)] using hsbound n + have hyD (n : ℕ) : y n ∈ D := + hball (Metric.closedBall_subset_closedBall (by linarith) (hymem n)) + have hy0 : Tendsto y atTop (nhds x) := by + simpa [y] using tendsto_const_nhds.add (hs0.smul (tendsto_const_nhds (x := z))) + choose i hi hia using fun n => hactive (y n) (hymem n) + choose w hw using fun n => supportSet_nonempty hD (hF (i n) (hi n)) (hyD n) + have hwbound (n : ℕ) : ‖w n‖ ≤ 2 * M / r := by + have hb : Metric.closedBall (y n) r ⊆ Metric.closedBall x (2 * r) := by + intro q hq + apply (dist_triangle q (y n) x).trans + have hqn := Metric.mem_closedBall.mp hq + have hyn := Metric.mem_closedBall.mp (hymem n) + linarith + exact support_norm_bound hr hM (hb.trans hball) + (fun q hq => hbound (i n) (hi n) q (hb hq)) (hw n) + obtain ⟨iw, hiw, σ, hσ, hlim⟩ := + (hK.prod (isCompact_closedBall (0 : E) (2 * M / r))).tendsto_subseq + (x := fun n => (i n, w n)) (fun n => ⟨hi n, by simpa using hwbound n⟩) + have hiwK : iw.1 ∈ K := hiw.1 + have hilim : Tendsto (fun n => i (σ n)) atTop (nhds iw.1) := + continuous_fst.tendsto iw |>.comp hlim + have hwlim : Tendsto (fun n => w (σ n)) atTop (nhds iw.2) := + continuous_snd.tendsto iw |>.comp hlim + have hylim : Tendsto (fun n => y (σ n)) atTop (nhds x) := hy0.comp hσ.tendsto_atTop + have hbase : Tendsto (fun n => F (i (σ n)) (y (σ n))) atTop (nhds (F iw.1 x)) := + continuousOn_tendsto_sequence hFc (a := (iw.1, x)) ⟨hiwK, hx⟩ + (fun n => ⟨hi (σ n), hyD (σ n)⟩) (hilim.prodMk_nhds hylim) + have hPbase : Tendsto (fun n => P (y (σ n))) atTop (nhds (P x)) := + continuousOn_tendsto_sequence hPc hx (fun n => hyD (σ n)) hylim + have hia0 : F iw.1 x = P x := by + apply tendsto_nhds_unique hbase + simpa only [hia] using hPbase + have hiws : SupportsOn (F iw.1) D x iw.2 := by + apply supportsOn_of_tendsto hylim hwlim hbase ?_ (fun n => hw (σ n)) + intro q hq + exact continuousOn_tendsto_sequence hFc (a := (iw.1, q)) ⟨hiwK, hq⟩ + (fun n => ⟨hi (σ n), hq⟩) (hilim.prodMk_nhds tendsto_const_nhds) + have hiwG : iw.2 ∈ G := ⟨iw.1, hiwK, hia0, hiws⟩ + have hendpoint (n : ℕ) : inner ℝ v z ≤ inner ℝ (w n) z := by + have hleft := hv (y n) (hyD n) + have hright := hw n x hx + have hdom := hle (i n) (hi n) x hx + have hyx : y n - x = s n • z := by simp [y] + have hxy : x - y n = -(s n • z) := by simp [y] + rw [hyx, real_inner_smul_right] at hleft + rw [hxy, inner_neg_right, real_inner_smul_right, hia n] at hright + exact (mul_le_mul_iff_right₀ (hspos n)).mp (by nlinarith [hleft, hright, hdom]) + have hfinal : inner ℝ v z ≤ inner ℝ iw.2 z := + le_of_tendsto_of_tendsto tendsto_const_nhds (hwlim.inner tendsto_const_nhds) + (Eventually.of_forall fun n => hendpoint (σ n)) + rw [hell, hell] at hfinal + have hh := hsep iw.2 (subset_closure (subset_convexHull ℝ G hiwG)) + linarith + +end CompactEnvelope + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/FamilyControls.lean b/lean/OAI/Probability/RadialTransition/FamilyControls.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d7d32f204ffb7ac8a7ea0c8c77602d502732351 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/FamilyControls.lean @@ -0,0 +1,106 @@ +import OAI.Probability.RadialTransition.WindowLipschitz + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +def AdmissibleFamily (_t A : ℝ) (b S : ℕ → ℝ) : Prop := + (∀ n, 0 ≤ b n) ∧ (∀ n, 1 ≤ S n) ∧ Summable b ∧ ∑' n, b n ≤ A + +lemma admissible_row {t A : ℝ} {b S : ℕ → ℝ} + (ht : 0 ≤ t) (had : AdmissibleFamily t A b S) + (hrow : 2197*t*bumpIntegral⁻¹*A ≤ (t^2/8)/8) : + 2197*t*bumpIntegral⁻¹*(∑' n, b n) ≤ (t^2/8)/8 := + (mul_le_mul_of_nonneg_left had.2.2.2 (by have := bumpIntegral_pos; positivity)).trans hrow + +lemma admissible_pressure_convex {t A : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (had : AdmissibleFamily t A b S) + (hrow : 2197*t*bumpIntegral⁻¹*A ≤ (t^2/8)/8) : + ConvexOn ℝ positiveParameters (onParameters (grandPressure (familyPotential t b S) t)) := by + have ht0 : 0 < t := by linarith + have hr := admissible_row ht0.le had hrow + exact convexOn_grandPressure (continuous_familyPotential had.1 had.2.1 had.2.2.1 t) + (bounded_familyPotential had.1 had.2.1 had.2.2.1 t) + (stable_family_of_master ht0.le had.1 had.2.1 had.2.2.1 had.2.2.1 (fun _ => le_rfl) hr) ht0 + (fun r h => familyPotential_nonpos_outer had.1 had.2.1 ht h) + +lemma family_controls {t A : ℝ} (ht : 1 ≤ t) (hA : 0 ≤ A) (htA : 6912*A ≤ t) + (hrow : 2197*t*bumpIntegral⁻¹*A ≤ (t^2/8)/8) : + ∃ U C C₀ : ℝ, 1 ≤ U ∧ 1 ≤ C ∧ 0 < C₀ ∧ + ∀ b S : ℕ → ℝ, AdmissibleFamily t A b S → ∀ a ∈ Ioc (0:ℝ) A, + (∀ β h, 0 < β → ∃ u, ActiveShift (grandPressure (familyPotential t b S) t) a β h u) ∧ + (∀ x ∈ phaseWindow (1/2), ∃ u ∈ Icc (0:ℝ) U, + ActiveShift (grandPressure (familyPotential t b S) t) a (x 0) (x 1) u) ∧ + (∀ x ∈ phaseWindow (1/4), ∀ y ∈ phaseWindow (1/4), + |onParameters (idealAttraction (grandPressure (familyPotential t b S) t) a) x- + onParameters (idealAttraction (grandPressure (familyPotential t b S) t) a) y| ≤ C*dist x y) ∧ + (∀ x ∈ phaseWindow (1/4), + 0 ≤ onParameters (idealAttraction (grandPressure (familyPotential t b S) t) a) x- + onParameters (grandPressure (familyPotential t b S) t) x ∧ + onParameters (idealAttraction (grandPressure (familyPotential t b S) t) a) x- + onParameters (grandPressure (familyPotential t b S) t) x ≤ C₀*a) := by + have ht0 : 0 < t := by linarith + obtain ⟨U,hU,hcut⟩ := uniform_ideal_cutoff (by norm_num : (0:ℝ)<1/4) + (by norm_num : (1/4:ℝ)≤2) (by norm_num : (0:ℝ)≤4) hA + let M := Real.exp (t^2+t*(4+2*A*U))/t + have hM : 0 < M := by dsimp [M]; positivity + refine ⟨U,1+8*M,1+U^2,hU,by linarith,by positivity,?_⟩ + intro b S had a ha + have hr := admissible_row ht0.le had hrow + have hta : 6912*a ≤ t := (mul_le_mul_of_nonneg_left ha.2 (by norm_num)).trans htA + have hQ := admissible_pressure_convex ht had hrow + have hact := family_ideal_global_active ht ha.1.le hta had.1 had.2.1 had.2.2.1 hr + have hP := convexOn_idealAttraction hQ hact + have hcut' (x : Parameter) (hx : x ∈ phaseWindow (1/2)) : + ∃ u ∈ Icc (0:ℝ) U, ActiveShift (grandPressure (familyPotential t b S) t) a (x 0) (x 1) u := by + obtain ⟨hβ,hh⟩ := phaseWindow_half_bounds hx + obtain ⟨κ,hκ,hc,hbound⟩ := hcut t ht htA (x 0) ⟨by linarith [hβ.1],by linarith [hβ.2]⟩ + (x 1) (by have := abs_le.mp hh; constructor <;> linarith) a ⟨ha.1.le,ha.2⟩ + exact family_ideal_exists_active ht (by linarith [hβ.1]) ha.1.le had.1 had.2.1 had.2.2.1 hr hκ hc hU hbound + have hbound (x : Parameter) (hx : x ∈ phaseWindow (1/2)) : + |onParameters (idealAttraction (grandPressure (familyPotential t b S) t) a) x| ≤ M := by + obtain ⟨hβ,hh⟩ := phaseWindow_half_bounds hx + have hβ0 : 0 < x 0 := by linarith [hβ.1] + obtain ⟨u,hub,hu⟩ := hcut' x hx + have hs := stable_family_of_master ht0.le had.1 had.2.1 had.2.2.1 had.2.2.1 (fun _ => le_rfl) hr + have hφ := continuous_familyPotential had.1 had.2.1 had.2.2.1 t + have hbd := bounded_familyPotential had.1 had.2.1 had.2.2.1 t + have hn := (grandPressure_spec hφ hbd hs ht0 hβ0.le + (fun r h => familyPotential_nonpos_outer had.1 had.2.1 ht h) (x 1)).2.1 + have hP0 := ideal_nonneg_of_active hu hn + change |idealAttraction (grandPressure (familyPotential t b S) t) a (x 0) (x 1)| ≤ M + rw [abs_of_nonneg hP0,idealAttraction_eq_of_active hu] + have hp := (grandPressure_spec hφ hbd hs ht0 hβ0.le + (fun r h => familyPotential_nonpos_outer had.1 had.2.1 ht h) (x 1+x 0*a*u)).2.2 + have hmul : x 0*a*u ≤ 2*A*U := + mul_le_mul (mul_le_mul (show x 0≤2 by linarith [hβ.2]) ha.2 ha.1.le (by norm_num)) + hub.2 hub.1 (by positivity) + have hexp : x 0*(t^2/2)+t*(x 1+x 0*a*u) ≤ t^2+t*(4+2*A*U) := by + have hh' := (abs_le.mp hh).2 + have hbmul := mul_le_mul_of_nonneg_right (show x 0≤2 by linarith [hβ.2]) (sq_nonneg t) + have hhmul := mul_le_mul_of_nonneg_left hh' ht0.le + nlinarith [mul_le_mul_of_nonneg_left hmul ht0.le] + have hd := div_le_div_of_nonneg_right (Real.exp_le_exp.mpr hexp) ht0.le + dsimp [attractionBranch,M] + have ha0 := ha.1.le + have hsub : 0 ≤ x 0*a/2*u^2 := by positivity + linarith + refine ⟨hact,hcut',?_,?_⟩ + · intro x hx y hy + exact (window_lipschitz hM.le hP hbound x hx y hy).trans + (mul_le_mul_of_nonneg_right (by linarith : 8*M≤1+8*M) dist_nonneg) + · intro x hx + obtain ⟨u,hub,hu⟩ := hcut' x (phaseWindow_mono (by norm_num) hx) + have hβ := (phaseWindow_quarter_bounds hx).1 + have hh := ideal_increment_bound hQ ha.1 (by linarith [hβ.1]) hu hub + refine ⟨hh.1,hh.2.trans ?_⟩ + have hm := mul_le_mul_of_nonneg_right (show x 0≤2 by linarith [hβ.2]) (mul_nonneg ha.1.le (sq_nonneg U)) + nlinarith [ha.1] + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/FamilyIdeal.lean b/lean/OAI/Probability/RadialTransition/FamilyIdeal.lean new file mode 100644 index 0000000000000000000000000000000000000000..95c1ace269567c07d5a7a336aff8b40f9966c4ec --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/FamilyIdeal.lean @@ -0,0 +1,76 @@ +import OAI.Probability.RadialTransition.KacComparison + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma family_pressure_data {t β : ℝ} {b S : ℕ → ℝ} (ht : 1 ≤ t) (hβ : 0 < β) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, b n) ≤ (t^2/8)/8) : + Continuous (grandPressure (familyPotential t b S) t β) ∧ + (∀ h, 0 ≤ grandPressure (familyPotential t b S) t β h) ∧ + (∀ h, ∃ d ≥ 0, grandPressure (familyPotential t b S) t β h = h*d-canonicalThermo (familyPotential t b S) t β d) ∧ + (∀ h d, 0 ≤ d → h*d-canonicalThermo (familyPotential t b S) t β d ≤ grandPressure (familyPotential t b S) t β h) ∧ + (∀ d, 0 ≤ d → β*t/3456*d^2-β*t/2*d-1/t ≤ canonicalThermo (familyPotential t b S) t β d) := by + have ht0 : 0 < t := by linarith + have hst := stable_family_of_master ht0.le hb hS hs hs (fun _ => le_rfl) hrow + have hφ := continuous_familyPotential hb hS hs t + have hbd := bounded_familyPotential hb hS hs t + have hc := fun r hr => familyPotential_nonpos_outer hb hS ht (r := r) hr + have hcoerc : 2197*t*bumpIntegral⁻¹*(∑' n, b n)/2 ≤ t^2/16 := by nlinarith [sq_nonneg t] + have hl := fun d hd => (familyCanonicalThermo_spec ht hb hS hs hcoerc hβ.le (d := d) hd).1 + refine ⟨grandPressure_continuous_h hφ hbd hst ht0 hβ.le hc, + fun h => (grandPressure_spec hφ hbd hst ht0 hβ.le hc h).2.1, + grandPressure_exists_maximizing_density hφ hbd hst ht0 hβ.le hc hl, ?_, ?_⟩ + · intro h d hd + exact canonical_le_grand_dual hφ hbd hst ht0 hβ.le hd hc (hl d hd) h + · intro d hd + have hh := (familyCanonicalThermo_spec ht hb hS hs hcoerc hβ.le hd).2.1 + have he := div_le_div_of_nonneg_right (entropy_lower hd) ht0.le + have halg : β/t*(t^2/3456*d^2-t^2/2*d) = β*t/3456*d^2-β*t/2*d := by field_simp + rw [halg] at hh + simp only [neg_div] at he + linarith + +lemma family_ideal_exists_active {t β a h U κ : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (hβ : 0 < β) (ha : 0 ≤ a) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, b n) ≤ (t^2/8)/8) + (hκ : 0 < κ) (hc : κ ≤ β*t/3456-β*a/2) (hU : 1 ≤ U) + (hcut : h+β*t/2+1/t+1 ≤ κ*U) : + ∃ u ∈ Icc (0:ℝ) U, ActiveShift (grandPressure (familyPotential t b S) t) a β h u := by + obtain ⟨hcont, hpos, hmax, hdual, hH⟩ := family_pressure_data ht hβ hb hS hs hrow + apply ideal_exists_active_of_density_bound hcont (mul_nonneg hβ.le ha) (hpos h) hmax hdual hH + (hκ.trans_le hc) (by positivity) hU + exact hcut.trans (mul_le_mul_of_nonneg_right hc (by linarith)) + +lemma family_active_bound {t β a h U κ u : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (hβ : 0 < β) (ha : 0 < a) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, b n) ≤ (t^2/8)/8) + (hκ : 0 < κ) (hc : κ ≤ β*t/3456-β*a/2) (hU : 1 ≤ U) + (hcut : h+β*t/2+1/t+1 ≤ κ*U) + (hu : ActiveShift (grandPressure (familyPotential t b S) t) a β h u) : u ∈ Icc (0:ℝ) U := by + obtain ⟨_, hpos, hmax, hdual, hH⟩ := family_pressure_data ht hβ hb hS hs hrow + apply active_density_bound (mul_pos hβ ha) (hpos h) hmax hdual hH + (hκ.trans_le hc) (by positivity) hU _ hu + exact hcut.trans (mul_le_mul_of_nonneg_right hc (by linarith)) + +lemma ideal_bddAbove_of_active {Q : Pressure} {a β h u : ℝ} (hu : ActiveShift Q a β h u) : + BddAbove (range fun v => attractionBranch Q a v β h) := + ⟨attractionBranch Q a u β h, fun _ ⟨v, hv⟩ => hv ▸ hu v⟩ + +lemma ideal_nonneg_of_active {Q : Pressure} {a β h u : ℝ} (hu : ActiveShift Q a β h u) + (hQ : 0 ≤ Q β h) : 0 ≤ idealAttraction Q a β h := by + rw [idealAttraction_eq_of_active hu] + have hh := hu 0 + simp only [attractionBranch, mul_zero, add_zero, zero_pow (by decide : 2 ≠ 0), sub_zero] at hh + exact hQ.trans hh + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/FamilyStep.lean b/lean/OAI/Probability/RadialTransition/FamilyStep.lean new file mode 100644 index 0000000000000000000000000000000000000000..4dd1a9ac95840f1664917c486e72583d80cce8c1 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/FamilyStep.lean @@ -0,0 +1,67 @@ +import OAI.Probability.RadialTransition.IdealAttainment + +namespace OAI + +universe uAlpha + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +def prepend {α : Type uAlpha} (v : α) (f : ℕ → α) : ℕ → α := fun n => Nat.casesOn n v f + +@[simp] lemma prepend_zero {α : Type uAlpha} (v : α) (f : ℕ → α) : prepend v f 0 = v := rfl +@[simp] lemma prepend_succ {α : Type uAlpha} (v : α) (f : ℕ → α) (n : ℕ) : prepend v f (n+1) = f n := rfl + +lemma summable_prepend (v : ℝ) {f : ℕ → ℝ} (hf : Summable f) : Summable (prepend v f) := by + apply (summable_nat_add_iff 1).mp + simpa only [prepend_succ] using hf + +lemma tsum_prepend (v : ℝ) {f : ℕ → ℝ} (hf : Summable f) : + (∑' n, prepend v f n) = v+∑' n, f n := by + simpa only [prepend_zero, prepend_succ] using (summable_prepend v hf).tsum_eq_zero_add + +lemma prepend_nonneg {a : ℝ} {b : ℕ → ℝ} (ha : 0 ≤ a) (hb : ∀ n, 0 ≤ b n) : + ∀ n, 0 ≤ prepend a b n := by + intro n; cases n with + | zero => exact ha + | succ n => exact hb n + +lemma prepend_range {R : ℝ} {S : ℕ → ℝ} (hR : 1 ≤ R) (hS : ∀ n, 1 ≤ S n) : + ∀ n, 1 ≤ prepend R S n := by + intro n; cases n with + | zero => exact hR + | succ n => exact hS n + +lemma attractionProfile_prepend {a R : ℝ} {b S : ℕ → ℝ} + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) (r : ℝ) : + attractionProfile (prepend a b) (prepend R S) r = a*scaledBumpProfile R r+attractionProfile b S r := by + unfold attractionProfile + have he : (fun n => prepend a b n*scaledBumpProfile (prepend R S n) r) = + prepend (a*scaledBumpProfile R r) (fun n => b n*scaledBumpProfile (S n) r) := by + funext n; cases n <;> rfl + rw [he, tsum_prepend _ (summable_attractionProfile hb hS hs r)] + +lemma familyPotential_prepend {a R t : ℝ} {b S : ℕ → ℝ} + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) : + familyPotential t (prepend a b) (prepend R S) = familyPotential t b S+singleAttraction R (t*a) := by + funext r + simp only [familyPotential, Pi.add_apply, attractionProfile_prepend hb hS hs, singleAttraction] + ring + +lemma familyCellMajorant_prepend {a R t : ℝ} {b S : ℕ → ℝ} + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) (i j : Cell) : + familyCellMajorant t (prepend a b) (prepend R S) i j = + familyCellMajorant t b S i j+t*a*cellMajorant R bumpIntegral⁻¹ i j := by + unfold familyCellMajorant + have he : (fun n => prepend a b n * cellMajorant (prepend R S n) bumpIntegral⁻¹ i j) = + prepend (a*cellMajorant R bumpIntegral⁻¹ i j) (fun n => b n*cellMajorant (S n) bumpIntegral⁻¹ i j) := by + funext n; cases n <;> rfl + rw [he, tsum_prepend _ (summable_cellMajorant hb hS hs i j)] + ring + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/FinitePartition.lean b/lean/OAI/Probability/RadialTransition/FinitePartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..bc0bfd453183428306948df854feeabc055b12e5 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/FinitePartition.lean @@ -0,0 +1,484 @@ +import OAI.Probability.RadialTransition.LatticeStability + +namespace OAI + +universe uX uIndex + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +theorem isClosed_cube (L : ℝ) : IsClosed (cube L) := by + have heq : cube L = ⋂ k : Fin 3, {x : Position | x k ∈ Icc 0 L} := by + ext x + simp only [cube, mem_ofPred_eq, mem_iInter, mem_Icc] + rw [heq] + exact isClosed_iInter (fun k : Fin 3 => + isClosed_Icc.preimage (PiLp.continuous_apply 2 (fun _ : Fin 3 => ℝ) k)) + +theorem measurableSet_cube (L : ℝ) : MeasurableSet (cube L) := + (isClosed_cube L).measurableSet + +theorem volume_cube (L : ℝ) : volume (cube L) = ENNReal.ofReal L ^ 3 := by + have heq : cube L = WithLp.ofLp ⁻¹' (Set.univ.pi fun _ : Fin 3 => Icc (0 : ℝ) L) := by + ext x + simp only [cube, mem_ofPred_eq, mem_preimage, Set.mem_pi, mem_univ, true_implies, mem_Icc] + rw [heq, (PiLp.volume_preserving_ofLp (Fin 3)).measure_preimage + (MeasurableSet.univ_pi (fun _ : Fin 3 => measurableSet_Icc)).nullMeasurableSet] + rw [volume_pi, Measure.pi_pi] + simp only [Real.volume_Icc, sub_zero, Finset.prod_const, Finset.card_univ, Fintype.card_fin] + +theorem measurableSet_configurationCube (L : ℝ) (N : ℕ) : + MeasurableSet (configurationCube L N) := by + have heq : configurationCube L N = Set.univ.pi (fun _ : Fin N => cube L) := by + ext x + simp only [configurationCube, mem_ofPred_eq, Set.mem_pi, mem_univ, true_implies] + rw [heq] + exact MeasurableSet.univ_pi (fun _ : Fin N => measurableSet_cube L) + +theorem volume_configurationCube (L : ℝ) (N : ℕ) : + volume (configurationCube L N) = ENNReal.ofReal L ^ (3 * N) := by + have heq : configurationCube L N = Set.univ.pi (fun _ : Fin N => cube L) := by + ext x + simp only [configurationCube, mem_ofPred_eq, Set.mem_pi, mem_univ, true_implies] + rw [heq, volume_pi] + rw [Measure.pi_pi] + simp [volume_cube, ← pow_mul] + +theorem continuous_energy {φ : Potential} (hφ : Continuous φ) (N : ℕ) : + Continuous (energy φ (N := N)) := by + unfold energy + exact continuous_finsetSum _ (fun i _ => continuous_finsetSum _ + (fun j _ => hφ.comp ((continuous_apply i).nndist (continuous_apply j)))) + +theorem energy_abs_bound {φ : Potential} {M : ℝ} (hM : 0 ≤ M) + (hφ : ∀ r : ℝ≥0, |φ r| ≤ M) {N : ℕ} (x : Fin N → Position) : + |energy φ x| ≤ (N : ℝ) ^ 2 * M := by + calc + _ ≤ ∑ i : Fin N, ∑ j : Fin N with i < j, |φ (nndist (x i) (x j))| := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + exact Finset.sum_le_sum (fun i _ => Finset.abs_sum_le_sum_abs _ _) + _ ≤ ∑ i : Fin N, ∑ j : Fin N, M := by + apply Finset.sum_le_sum + intro i _ + apply le_trans (Finset.sum_le_sum (fun j _ => hφ _)) + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun _ _ _ => hM) + _ = _ := by simp; ring + +theorem integrableOn_boltzmann {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) (L : ℝ) (N : ℕ) (β : ℝ) : + IntegrableOn (fun x : Fin N → Position => Real.exp (-β * energy φ x)) + (configurationCube L N) := by + obtain ⟨M, hM, hφM⟩ := hb + have hfinite : volume (configurationCube L N) < ⊤ := by + rw [volume_configurationCube] + exact ENNReal.pow_lt_top ENNReal.ofReal_lt_top + apply IntegrableOn.of_bound hfinite ((Real.continuous_exp.comp + (continuous_const.mul (continuous_energy hφ N))).stronglyMeasurable.aestronglyMeasurable) (Real.exp (|β| * ((N : ℝ) ^ 2 * M))) + filter_upwards [] with x + change |Real.exp (-β * energy φ x)| ≤ _ + rw [abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + calc + -β * energy φ x ≤ |-β * energy φ x| := le_abs_self _ + _ = |β| * |energy φ x| := by rw [abs_mul, abs_neg] + _ ≤ _ := mul_le_mul_of_nonneg_left (energy_abs_bound hM hφM x) (abs_nonneg _) + +theorem partition_pos {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {L : ℝ} (hL : 0 < L) (N : ℕ) (β : ℝ) : 0 < partition φ L N β := by + unfold partition + apply mul_pos (inv_pos.mpr (by exact_mod_cast Nat.factorial_pos N)) + apply (integral_pos_iff_support_of_nonneg_ae + (Filter.Eventually.of_forall (fun x => (Real.exp_pos (-β * energy φ x)).le)) + (integrableOn_boltzmann hφ hb L N β)).mpr + have heq : Function.support (fun x : Fin N → Position => Real.exp (-β * energy φ x)) = univ := by + ext x + simp [Function.mem_support] + rw [heq, Measure.restrict_apply_univ] + rw [volume_configurationCube] + exact pos_iff_ne_zero.mpr (pow_ne_zero _ ((ENNReal.ofReal_pos.mpr hL).ne')) + +theorem log_integral_exp_convex_mix {X : Type uX} [MeasurableSpace X] {μ : Measure X} + {F G : X → ℝ} {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) + (hF : Integrable (fun x => Real.exp (F x)) μ) + (hG : Integrable (fun x => Real.exp (G x)) μ) + (hH : Integrable (fun x => Real.exp (a * F x + b * G x)) μ) + (hZF : 0 < ∫ x, Real.exp (F x) ∂μ) (hZG : 0 < ∫ x, Real.exp (G x) ∂μ) + (hZH : 0 < ∫ x, Real.exp (a * F x + b * G x) ∂μ) : + Real.log (∫ x, Real.exp (a * F x + b * G x) ∂μ) ≤ + a * Real.log (∫ x, Real.exp (F x) ∂μ) + b * Real.log (∫ x, Real.exp (G x) ∂μ) := by + let c := a * Real.log (∫ x, Real.exp (F x) ∂μ) + b * Real.log (∫ x, Real.exp (G x) ∂μ) + have hpoint (x : X) : Real.exp (-c) * Real.exp (a * F x + b * G x) ≤ + a * ((∫ x, Real.exp (F x) ∂μ)⁻¹ * Real.exp (F x)) + + b * ((∫ x, Real.exp (G x) ∂μ)⁻¹ * Real.exp (G x)) := by + have hh := convexOn_exp.2 (mem_univ (F x - Real.log (∫ x, Real.exp (F x) ∂μ))) + (mem_univ (G x - Real.log (∫ x, Real.exp (G x) ∂μ))) ha hb hab + simp only [smul_eq_mul] at hh + have heq : a * (F x - Real.log (∫ x, Real.exp (F x) ∂μ)) + + b * (G x - Real.log (∫ x, Real.exp (G x) ∂μ)) = -c + (a * F x + b * G x) := by + dsimp [c]; ring + rw [heq, Real.exp_add, Real.exp_sub, Real.exp_sub, Real.exp_log hZF, Real.exp_log hZG] at hh + simpa only [div_eq_mul_inv, mul_comm] using hh + have hi := integral_mono (hH.const_mul _) ((hF.const_mul _).const_mul a |>.add + ((hG.const_mul _).const_mul b)) hpoint + simp only [Pi.add_apply, integral_add ((hF.const_mul _).const_mul a) ((hG.const_mul _).const_mul b), + integral_const_mul, inv_mul_cancel₀ hZF.ne', inv_mul_cancel₀ hZG.ne', mul_one, hab] at hi + have hexp := Real.log_le_log (mul_pos (Real.exp_pos (-c)) hZH) hi + rw [Real.log_mul (Real.exp_ne_zero _) hZH.ne', Real.log_exp, Real.log_one] at hexp + change _ ≤ c + linarith + +theorem integral_const_configurationCube {L : ℝ} (hL : 0 ≤ L) (N : ℕ) (c : ℝ) : + (∫ _x : Fin N → Position in configurationCube L N, c) = L ^ (3 * N) * c := by + rw [setIntegral_const, Measure.real, volume_configurationCube, ENNReal.toReal_pow, + ENNReal.toReal_ofReal hL] + rfl + +theorem partition_zero (φ : Potential) (L β : ℝ) : partition φ L 0 β = 1 := by + have heq : (fun x : Fin 0 → Position => Real.exp (-β * energy φ x)) = fun _ => (1 : ℝ) := by + funext x + simp [energy] + unfold partition + rw [heq, setIntegral_const, Measure.real, volume_configurationCube] + simp + +theorem partition_nonneg {φ : Potential} (L : ℝ) (N : ℕ) (β : ℝ) : + 0 ≤ partition φ L N β := by + exact mul_nonneg (by positivity) (integral_nonneg fun x => (Real.exp_pos _).le) + +theorem partition_upper_of_energy_lower {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {L β E : ℝ} (hL : 0 ≤ L) (hβ : 0 ≤ β) (N : ℕ) + (hE : ∀ x ∈ configurationCube L N, E ≤ energy φ x) : + partition φ L N β ≤ (N.factorial : ℝ)⁻¹ * L ^ (3 * N) * Real.exp (-β * E) := by + have hfinite : volume (configurationCube L N) ≠ ⊤ := by + simp [volume_configurationCube] + have hconst : IntegrableOn (fun _ : Fin N → Position => Real.exp (-β * E)) + (configurationCube L N) := integrableOn_const hfinite + have hc := setIntegral_mono_on (integrableOn_boltzmann hφ hb L N β) hconst + (measurableSet_configurationCube L N) (fun x hx => + Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_left (hE x hx) (neg_nonpos.mpr hβ))) + rw [integral_const_configurationCube hL] at hc + exact (mul_le_mul_of_nonneg_left hc (by positivity)).trans_eq (mul_assoc _ _ _).symm + +theorem partition_stability_upper {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B L β : ℝ} (hstable : StableWith φ B) + (hL : 0 ≤ L) (hβ : 0 ≤ β) (N : ℕ) : + partition φ L N β ≤ (L ^ 3 * Real.exp (β * B)) ^ N / N.factorial := by + have hh := partition_upper_of_energy_lower hφ hb hL hβ N (fun x _ => hstable N x) + have heq : (N.factorial : ℝ)⁻¹ * L ^ (3 * N) * Real.exp (-β * (-(B * N))) = + (L ^ 3 * Real.exp (β * B)) ^ N / N.factorial := by + rw [mul_pow, ← pow_mul, ← Real.exp_nat_mul] + have he : -β * -(B * (N : ℝ)) = (N : ℝ) * (β * B) := by ring + rw [he] + ring + exact hh.trans_eq heq + +theorem log_partition_upper_of_energy_lower {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {L β E : ℝ} (hL : 0 < L) (hβ : 0 ≤ β) (N : ℕ) + (hE : ∀ x ∈ configurationCube L N, E ≤ energy φ x) : + Real.log (partition φ L N β) ≤ + (N : ℝ) * Real.log (L ^ 3) - Real.log (N.factorial : ℝ) - β * E := by + have hh := Real.log_le_log (partition_pos hφ hb hL N β) + (partition_upper_of_energy_lower hφ hb hL.le hβ N hE) + have hfac : (N.factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero N + rw [Real.log_mul (mul_ne_zero (inv_ne_zero hfac) (pow_ne_zero _ hL.ne')) (Real.exp_ne_zero _), + Real.log_mul (inv_ne_zero hfac) (pow_ne_zero _ hL.ne'), Real.log_inv, + Real.log_pow, Real.log_exp] at hh + rw [Real.log_pow] + + push_cast at hh + norm_num only [Nat.cast_ofNat] at * + nlinarith + +theorem boltzmannIntegral_pos {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {L : ℝ} (hL : 0 < L) (N : ℕ) (β : ℝ) : + 0 < ∫ x in configurationCube L N, Real.exp (-β * energy φ x) := by + have hp := partition_pos hφ hb hL N β + exact (mul_pos_iff_of_pos_left (inv_pos.mpr (by exact_mod_cast Nat.factorial_pos N))).mp hp + +theorem log_partition_convex_mix {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {L a b : ℝ} (hL : 0 < L) (N : ℕ) (β γ : ℝ) + (ha : 0 ≤ a) (hbb : 0 ≤ b) (hab : a + b = 1) : + Real.log (partition φ L N (a * β + b * γ)) ≤ + a * Real.log (partition φ L N β) + b * Real.log (partition φ L N γ) := by + have heq (x : Fin N → Position) : a * (-β * energy φ x) + b * (-γ * energy φ x) = + -(a * β + b * γ) * energy φ x := by ring + have hc := log_integral_exp_convex_mix (F := fun x : Fin N → Position => -β * energy φ x) + (G := fun x => -γ * energy φ x) (μ := volume.restrict (configurationCube L N)) ha hbb hab + (integrableOn_boltzmann hφ hb L N β) (integrableOn_boltzmann hφ hb L N γ) + (by simp_rw [heq]; exact integrableOn_boltzmann hφ hb L N _) (boltzmannIntegral_pos hφ hb hL N β) + (boltzmannIntegral_pos hφ hb hL N γ) (by simp_rw [heq]; exact boltzmannIntegral_pos hφ hb hL N _) + simp_rw [heq] at hc + have hfac : (N.factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero N + simp only [partition, Real.log_mul (inv_ne_zero hfac) + (boltzmannIntegral_pos hφ hb hL N _).ne'] + have haff := congrArg (fun z : ℝ => z * Real.log (N.factorial : ℝ)⁻¹) hab + nlinarith [haff] + +def finiteCanonical (φ : Potential) (t L : ℝ) (N : ℕ) (β : ℝ) : ℝ := + -Real.log (partition φ L N β) / (t * L ^ 3) + +theorem finiteCanonical_concave {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {t L : ℝ} (ht : 0 < t) (hL : 0 < L) (N : ℕ) : + ConcaveOn ℝ univ (finiteCanonical φ t L N) := by + refine ⟨convex_univ, ?_⟩ + intro β _ γ _ a b ha hbb hab + simp only [finiteCanonical, smul_eq_mul] + have hh := log_partition_convex_mix hφ hb hL N β γ ha hbb hab + have hd : 0 < t * L ^ 3 := mul_pos ht (pow_pos hL _) + apply (le_div_iff₀ hd).mpr + field_simp + nlinarith + +def grandPartition (φ : Potential) (t L β h : ℝ) : ℝ := + ∑' N : ℕ, Real.exp (t * h * N) * partition φ L N β + +theorem grandTerm_stability_upper {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B L β : ℝ} (hstable : StableWith φ B) + (hL : 0 ≤ L) (hβ : 0 ≤ β) (t h : ℝ) (N : ℕ) : + Real.exp (t * h * N) * partition φ L N β ≤ + (L ^ 3 * Real.exp (β * B + t * h)) ^ N / N.factorial := by + have hh := mul_le_mul_of_nonneg_left (partition_stability_upper hφ hb hstable hL hβ N) + (Real.exp_pos (t * h * N)).le + apply hh.trans_eq + rw [Real.exp_add, mul_pow, mul_pow, mul_pow, ← Real.exp_nat_mul (β * B) N, + ← Real.exp_nat_mul (t * h) N] + have he : t * h * (N : ℝ) = (N : ℝ) * (t * h) := by ring + rw [he] + ring + +theorem grandPartition_summable {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B L β : ℝ} (hstable : StableWith φ B) + (hL : 0 ≤ L) (hβ : 0 ≤ β) (t h : ℝ) : + Summable (fun N : ℕ => Real.exp (t * h * N) * partition φ L N β) := + Summable.of_nonneg_of_le + (fun N => mul_nonneg (Real.exp_pos _).le (partition_nonneg L N β)) + (grandTerm_stability_upper hφ hb hstable hL hβ t h) + (Real.summable_pow_div_factorial _) + +theorem grandPartition_bounds {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B L β : ℝ} (hstable : StableWith φ B) + (hL : 0 ≤ L) (hβ : 0 ≤ β) (t h : ℝ) : + 1 ≤ grandPartition φ t L β h ∧ + grandPartition φ t L β h ≤ Real.exp (L ^ 3 * Real.exp (β * B + t * h)) := by + have hs := grandPartition_summable hφ hb hstable hL hβ t h + constructor + · have hh := hs.le_tsum 0 (fun N _ => mul_nonneg (Real.exp_pos _).le (partition_nonneg L N β)) + convert hh using 1 <;> first | rfl | norm_num [partition_zero] + · have hh := hs.tsum_le_tsum (grandTerm_stability_upper hφ hb hstable hL hβ t h) + (Real.summable_pow_div_factorial _) + have he : (∑' N : ℕ, (L ^ 3 * Real.exp (β * B + t * h)) ^ N / N.factorial) = + Real.exp (L ^ 3 * Real.exp (β * B + t * h)) := by + rw [Real.exp_eq_exp_ℝ, NormedSpace.exp_eq_tsum_div] + exact hh.trans_eq he + +theorem log_tsum_convex_mix {T U V : ℕ → ℝ} {a b : ℝ} + (ha : 0 ≤ a) (hb : 0 ≤ b) (hab : a + b = 1) + (hT : Summable T) (hU : Summable U) (hV : Summable V) + (hpT : ∀ n, 0 < T n) (hpU : ∀ n, 0 < U n) (hpV : ∀ n, 0 < V n) + (hlog : ∀ n, Real.log (T n) ≤ a * Real.log (U n) + b * Real.log (V n)) : + Real.log (∑' n, T n) ≤ a * Real.log (∑' n, U n) + b * Real.log (∑' n, V n) := by + have hsT : 0 < ∑' n, T n := lt_of_lt_of_le (hpT 0) (hT.le_tsum 0 (fun n _ => (hpT n).le)) + have hsU : 0 < ∑' n, U n := lt_of_lt_of_le (hpU 0) (hU.le_tsum 0 (fun n _ => (hpU n).le)) + have hsV : 0 < ∑' n, V n := lt_of_lt_of_le (hpV 0) (hV.le_tsum 0 (fun n _ => (hpV n).le)) + let c := a * Real.log (∑' n, U n) + b * Real.log (∑' n, V n) + have hpoint (n : ℕ) : Real.exp (-c) * T n ≤ + a * ((∑' n, U n)⁻¹ * U n) + b * ((∑' n, V n)⁻¹ * V n) := by + have hcv := convexOn_exp.2 (mem_univ (Real.log (U n) - Real.log (∑' n, U n))) + (mem_univ (Real.log (V n) - Real.log (∑' n, V n))) ha hb hab + simp only [smul_eq_mul] at hcv + have he : a * (Real.log (U n) - Real.log (∑' n, U n)) + + b * (Real.log (V n) - Real.log (∑' n, V n)) = + -c + (a * Real.log (U n) + b * Real.log (V n)) := by dsimp [c]; ring + rw [he, Real.exp_add, Real.exp_sub, Real.exp_sub, Real.exp_log (hpU n), + Real.exp_log (hpV n), Real.exp_log hsU, Real.exp_log hsV] at hcv + have hh := Real.exp_le_exp.mpr (hlog n) + rw [Real.exp_log (hpT n)] at hh + apply (mul_le_mul_of_nonneg_left hh (Real.exp_pos _).le).trans + simpa only [div_eq_mul_inv, mul_comm] using hcv + have hh := (hT.mul_left (Real.exp (-c))).tsum_le_tsum hpoint + ((hU.mul_left _).mul_left a |>.add ((hV.mul_left _).mul_left b)) + rw [Summable.tsum_add ((hU.mul_left _).mul_left a) ((hV.mul_left _).mul_left b)] at hh + simp only [tsum_mul_left, inv_mul_cancel₀ hsU.ne', inv_mul_cancel₀ hsV.ne', mul_one, hab] at hh + have hh' := Real.log_le_log (mul_pos (Real.exp_pos (-c)) hsT) hh + rw [Real.log_mul (Real.exp_ne_zero _) hsT.ne', Real.log_exp, Real.log_one] at hh' + change _ ≤ c + linarith + +def cubeProbability (L : ℝ) : Measure Position := + (ENNReal.ofReal (L ^ 3))⁻¹ • volume.restrict (cube L) + +theorem cubeProbability_isProbability {L : ℝ} (hL : 0 < L) : + IsProbabilityMeasure (cubeProbability L) := by + constructor + simp only [cubeProbability, Measure.smul_apply, Measure.restrict_apply_univ, smul_eq_mul, + volume_cube, ENNReal.ofReal_pow hL.le] + exact ENNReal.inv_mul_cancel (pow_ne_zero _ (ENNReal.ofReal_pos.mpr hL).ne') + (ENNReal.pow_ne_top ENNReal.ofReal_ne_top) + +theorem measure_pi_smul {ι : Type uIndex} [Fintype ι] {X : ι → Type uX} + [∀ i, MeasurableSpace (X i)] (μ : (i : ι) → Measure (X i)) + [∀ i, SigmaFinite (μ i)] (c : ι → ℝ≥0∞) (hc : ∀ i, c i ≠ ⊤) : + Measure.pi (fun i => c i • μ i) = (∏ i, c i) • Measure.pi μ := by + have : ∀ i, SigmaFinite (c i • μ i) := by + intro i + rw [← ENNReal.coe_toNNReal (hc i)] + change SigmaFinite ((c i).toNNReal • μ i) + infer_instance + apply Measure.pi_eq + intro s _ + simp only [Measure.smul_apply, Measure.pi_pi, smul_eq_mul, Finset.prod_mul_distrib] + +theorem cubeProbability_pi {L : ℝ} (hL : 0 < L) (N : ℕ) : + Measure.pi (fun _ : Fin N => cubeProbability L) = + (ENNReal.ofReal (L ^ (3 * N)))⁻¹ • volume.restrict (configurationCube L N) := by + have heq : configurationCube L N = Set.univ.pi (fun _ : Fin N => cube L) := by + ext x + simp [configurationCube, Set.mem_pi] + rw [heq, volume_pi, Measure.restrict_pi_pi] + unfold cubeProbability + rw [measure_pi_smul _ _ (fun _ => ENNReal.inv_ne_top.mpr + (ENNReal.ofReal_pos.mpr (pow_pos hL _)).ne')] + simp only [Finset.prod_const, Finset.card_univ, Fintype.card_fin] + rw [← ENNReal.inv_pow, ← ENNReal.ofReal_pow (pow_nonneg hL.le 3), + ← pow_mul] + +theorem measurePreserving_pair_eval {ι : Type uIndex} {X : Type uX} [Fintype ι] [MeasurableSpace X] + (μ : Measure X) [IsProbabilityMeasure μ] {i j : ι} (hij : i ≠ j) : + MeasurePreserving (fun x : ι → X => (x i, x j)) + (Measure.pi (fun _ : ι => μ)) (μ.prod μ) := by + have hind := ProbabilityTheory.iIndepFun_pi (μ := fun _ : ι => μ) + (X := fun _ => id) (fun _ => aemeasurable_id) + refine ⟨(measurable_pi_apply _).prodMk (measurable_pi_apply _), ?_⟩ + have hp := (hind.indepFun hij).map_prod_eq_prod_map_map + (measurable_pi_apply _).aemeasurable (measurable_pi_apply _).aemeasurable + simpa only [id_eq, (measurePreserving_eval (fun _ : ι => μ) i).map_eq, + (measurePreserving_eval (fun _ : ι => μ) j).map_eq] using hp + +theorem probability_pair_kernel_bound {L M : ℝ} (hL : 0 < L) {K : Position → ℝ} + (hK : Continuous K) (hKM : ∀ z, |K z| ≤ M) (hKi : Integrable K) + (hK0 : ∀ z, 0 ≤ K z) : + (∫ z : Position × Position, K (z.1 - z.2) ∂(cubeProbability L).prod (cubeProbability L)) ≤ + (L ^ 3)⁻¹ * ∫ z, K z := by + let := cubeProbability_isProbability hL + have hi : Integrable (fun z : Position × Position => K (z.1 - z.2)) + ((cubeProbability L).prod (cubeProbability L)) := + Integrable.of_bound (hK.comp (continuous_fst.sub continuous_snd)).aestronglyMeasurable M + (Eventually.of_forall (fun z => hKM (z.1 - z.2))) + rw [integral_prod _ hi] + have hh (x : Position) : (∫ y, K (x - y) ∂cubeProbability L) ≤ (L ^ 3)⁻¹ * ∫ z, K z := by + simp only [cubeProbability, integral_smul_measure, ENNReal.toReal_inv, + ENNReal.toReal_ofReal (pow_nonneg hL.le 3), smul_eq_mul] + apply mul_le_mul_of_nonneg_left _ (inv_nonneg.mpr (pow_nonneg hL.le _)) + exact (setIntegral_le_integral (hKi.comp_sub_left x) + (Eventually.of_forall (fun y => hK0 (x - y)))).trans_eq (integral_sub_left_eq_self K volume x) + have hh' := integral_mono hi.integral_prod_left (integrable_const _) hh + simpa [integral_const, Measure.real] using hh' + +theorem probability_energy_upper {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {L M : ℝ} (hL : 0 < L) (N : ℕ) {K : Position → ℝ} + (hK : Continuous K) (hKM : ∀ z, |K z| ≤ M) (hKi : Integrable K) + (hK0 : ∀ z, 0 ≤ K z) (hφK : ∀ x y, φ (nndist x y) ≤ K (x - y)) : + (∫ x : Fin N → Position, energy φ x ∂Measure.pi (fun _ : Fin N => cubeProbability L)) ≤ + (N : ℝ) ^ 2 * ((L ^ 3)⁻¹ * ∫ z, K z) := by + classical + let := cubeProbability_isProbability hL + obtain ⟨Mφ, hMφ, hφM⟩ := hb + have hipair (i j : Fin N) : Integrable + (fun x : Fin N → Position => φ (nndist (x i) (x j))) + (Measure.pi (fun _ : Fin N => cubeProbability L)) := + Integrable.of_bound (hφ.comp ((continuous_apply i).nndist (continuous_apply j))).aestronglyMeasurable + Mφ (Eventually.of_forall (fun x => hφM _)) + have hik (i j : Fin N) : Integrable + (fun x : Fin N → Position => K (x i - x j)) + (Measure.pi (fun _ : Fin N => cubeProbability L)) := + Integrable.of_bound (hK.comp ((continuous_apply i).sub (continuous_apply j))).aestronglyMeasurable + M (Eventually.of_forall (fun x => hKM _)) + simp only [energy, integral_finsetSum _ (fun i _ => integrable_finsetSum _ (fun j _ => hipair i j))] + have hbound (i j : Fin N) (hij : i < j) : + (∫ x : Fin N → Position, φ (nndist (x i) (x j)) + ∂Measure.pi (fun _ : Fin N => cubeProbability L)) ≤ (L ^ 3)⁻¹ * ∫ z, K z := by + apply (integral_mono (hipair i j) (hik i j) (fun x => hφK (x i) (x j))).trans + have hp := measurePreserving_pair_eval (cubeProbability L) hij.ne + have hmap := integral_map (μ := Measure.pi (fun _ : Fin N => cubeProbability L)) hp.measurable.aemeasurable + (hK.comp (continuous_fst.sub continuous_snd)).aestronglyMeasurable + rw [hp.map_eq] at hmap + simp only [Function.comp_apply, Pi.sub_apply] at hmap + rw [← hmap] + exact probability_pair_kernel_bound hL hK hKM hKi hK0 + have hconst : 0 ≤ (L ^ 3)⁻¹ * ∫ z, K z := + mul_nonneg (inv_nonneg.mpr (pow_nonneg hL.le _)) (integral_nonneg hK0) + calc + _ = ∑ i : Fin N, ∑ j : Fin N with i < j, + ∫ x : Fin N → Position, φ (nndist (x i) (x j)) + ∂Measure.pi (fun _ : Fin N => cubeProbability L) := by + apply Finset.sum_congr rfl + intro i _ + rw [integral_finsetSum _ (fun j _ => hipair i j)] + _ ≤ ∑ i : Fin N, ∑ j : Fin N, (L ^ 3)⁻¹ * ∫ z, K z := by + apply Finset.sum_le_sum + intro i _ + apply (Finset.sum_le_sum (fun j hj => hbound i j (Finset.mem_filter.mp hj).2)).trans + exact Finset.sum_le_sum_of_subset_of_nonneg (Finset.filter_subset _ _) (fun _ _ _ => hconst) + _ = _ := by simp; ring + +theorem integral_cubeProbability_pi {L : ℝ} (hL : 0 < L) (N : ℕ) + (F : (Fin N → Position) → ℝ) : + (∫ x, F x ∂Measure.pi (fun _ : Fin N => cubeProbability L)) = + (L ^ (3 * N))⁻¹ * ∫ x in configurationCube L N, F x := by + rw [cubeProbability_pi hL N, integral_smul_measure, ENNReal.toReal_inv, + ENNReal.toReal_ofReal (pow_nonneg hL.le _), smul_eq_mul] + +theorem log_partition_lower_of_energy_mean {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {L β E : ℝ} (hL : 0 < L) (hβ : 0 ≤ β) (N : ℕ) + (hE : (∫ x : Fin N → Position, energy φ x + ∂Measure.pi (fun _ : Fin N => cubeProbability L)) ≤ E) : + (3 * N : ℝ) * Real.log L - Real.log (N.factorial : ℝ) - β * E ≤ + Real.log (partition φ L N β) := by + let := cubeProbability_isProbability hL + let μ := Measure.pi (fun _ : Fin N => cubeProbability L) + obtain ⟨M, hM, hφM⟩ := hb + have hi : Integrable (fun x : Fin N → Position => energy φ x) μ := + Integrable.of_bound (continuous_energy hφ N).aestronglyMeasurable + ((N : ℝ)^2 * M) (Eventually.of_forall (energy_abs_bound hM hφM)) + have he : Integrable (fun x : Fin N → Position => Real.exp (-β * energy φ x)) μ := by + apply Integrable.of_bound ((Real.continuous_exp.comp + (continuous_const.mul (continuous_energy hφ N))).aestronglyMeasurable) + (Real.exp (|β| * ((N : ℝ)^2 * M))) + filter_upwards [] with x + change |Real.exp _| ≤ _ + rw [abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + calc + -β * energy φ x ≤ |-β * energy φ x| := le_abs_self _ + _ = |β| * |energy φ x| := by rw [abs_mul, abs_neg] + _ ≤ _ := mul_le_mul_of_nonneg_left (energy_abs_bound hM hφM x) (abs_nonneg β) + have hj := convexOn_exp.map_integral_le Real.continuous_exp.continuousOn isClosed_univ + (Eventually.of_forall (fun x : Fin N → Position => mem_univ (-β * energy φ x))) + (hi.const_mul (-β)) he + rw [integral_const_mul] at hj + have hlow := (Real.exp_le_exp.mpr (mul_le_mul_of_nonpos_left hE (neg_nonpos.mpr hβ))).trans hj + have hp : 0 < ∫ x : Fin N → Position, Real.exp (-β * energy φ x) ∂μ := + lt_of_lt_of_le (Real.exp_pos _) hlow + have hl := Real.log_le_log (Real.exp_pos (-β * E)) hlow + rw [Real.log_exp] at hl + have hpint : 0 < ∫ x in configurationCube L N, Real.exp (-β * energy φ x) := by + have h := partition_pos hφ ⟨M, hM, hφM⟩ hL N β + exact (mul_pos_iff_of_pos_left (inv_pos.mpr (by exact_mod_cast Nat.factorial_pos N))).mp h + change -β * E ≤ Real.log (∫ x, Real.exp (-β * energy φ x) + ∂Measure.pi (fun _ : Fin N => cubeProbability L)) at hl + rw [integral_cubeProbability_pi hL N, Real.log_mul (inv_ne_zero (pow_ne_zero _ hL.ne')) hpint.ne', + Real.log_inv, Real.log_pow] at hl + rw [partition, Real.log_mul (inv_ne_zero (by exact_mod_cast Nat.factorial_ne_zero N)) hpint.ne', + Real.log_inv] + norm_num only [Nat.cast_mul, Nat.cast_ofNat] at hl + linarith + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/FockIntegral.lean b/lean/OAI/Probability/RadialTransition/FockIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..2fd187c2cab9859188e04410f57745da40c538d3 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/FockIntegral.lean @@ -0,0 +1,275 @@ +import OAI.Probability.RadialTransition.PerturbationMoments + +namespace OAI + +universe uX + +noncomputable section + + +open Filter MeasureTheory Set + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +section Fock +variable {X : Type uX} [MeasurableSpace X] +variable (F : ∀ (ι : Type) [Fintype ι], (ι → X) → ℝ≥0∞) +variable (heq : ∀ (ι κ : Type) [Fintype ι] [Fintype κ] (e : ι ≃ κ) (x : κ → X), + F ι (x ∘ e) = F κ x) +include heq + +lemma functional_integral_equiv {ι κ : Type} [Fintype ι] [Fintype κ] + (e : ι ≃ κ) (μ : κ → Measure X) [∀ i, SigmaFinite (μ i)] : + (∫⁻ x, F ι x ∂Measure.pi (fun i => μ (e i))) = ∫⁻ x, F κ x ∂Measure.pi μ := by + have hp := measurePreserving_piCongrLeft μ e + have hh := MeasurePreserving.lintegral_map_equiv (F κ) + (MeasurableEquiv.piCongrLeft (fun _ => X) e) hp + rw [hh] + apply lintegral_congr + intro x + have h := heq ι κ e (MeasurableEquiv.piCongrLeft (fun _ => X) e x) + simpa [MeasurableEquiv.piCongrLeft, Function.comp_def] using h + +lemma functional_sector {ι : Type} [Fintype ι] (p : ι → Prop) [DecidablePred p] + (hF : ∀ (ι : Type) [Fintype ι], Measurable (F ι)) + (μ ν : Measure X) [SigmaFinite μ] [SigmaFinite ν] : + (∫⁻ x : ι → X, F ι x ∂Measure.pi (fun i => if p i then μ else ν)) = + ∫⁻ x : Subtype p → X, ∫⁻ y : {i // ¬p i} → X, + F (Subtype p ⊕ {i // ¬p i}) (Sum.elim x y) + ∂Measure.pi (fun _ => ν) ∂Measure.pi (fun _ => μ) := by + have hs : ∀ i : ι, SigmaFinite (if p i then μ else ν) := by + intro i + split_ifs <;> infer_instance + let e := Equiv.sumCompl p + have hh := functional_integral_equiv F heq e (fun i => if p i then μ else ν) + rw [← hh] + have hm : (fun i : Subtype p ⊕ {i // ¬p i} => if p (e i) then μ else ν) = Sum.elim (fun _ => μ) (fun _ => ν) := by + funext i + cases i with + | inl i => exact ite_eq_left i.property + | inr i => exact ite_eq_right i.property + rw [hm] + have hs' : ∀ i : Subtype p ⊕ {i // ¬p i}, SigmaFinite (Sum.elim (fun _ => μ) (fun _ => ν) i) := by + intro i + cases i + · change SigmaFinite μ; infer_instance + · change SigmaFinite ν; infer_instance + let e' := MeasurableEquiv.sumPiEquivProdPi (fun _ : Subtype p ⊕ {i // ¬p i} => X) + have hp := measurePreserving_sumPiEquivProdPi_symm (Sum.elim (fun _ : Subtype p => μ) (fun _ : {i // ¬p i} => ν)) + have hh := hp.lintegral_comp (hF _) + rw [← hh] + exact lintegral_prod _ ((hF _).comp e'.symm.measurable).aemeasurable + +lemma functional_sector_card (μ ν : Measure X) [SigmaFinite μ] [SigmaFinite ν] + {N : ℕ} (T : Finset (Fin N)) : + (∫⁻ x : Fin N → X, F (Fin N) x ∂Measure.pi (fun i => if i ∈ T then μ else ν)) = + ∫⁻ x : Fin T.card ⊕ Fin (N-T.card) → X, F _ x + ∂Measure.pi (Sum.elim (fun _ => μ) (fun _ => ν)) := by + classical + have hcardA : Fintype.card {i : Fin N // i ∈ T} = T.card := Fintype.card_coe T + have hcardB : Fintype.card {i : Fin N // i ∉ T} = N - T.card := by + rw [Fintype.card_subtype_compl, Fintype.card_fin, hcardA] + let eA := (Fintype.equivFinOfCardEq hcardA).symm + let eB := (Fintype.equivFinOfCardEq hcardB).symm + let e := (Equiv.sumCongr eA eB).trans (Equiv.sumCompl (fun i => i ∈ T)) + have hs : ∀ i : Fin N, SigmaFinite (if i ∈ T then μ else ν) := by + intro i + split_ifs <;> infer_instance + have hh := (functional_integral_equiv F heq e (fun i => if i ∈ T then μ else ν)).symm + have hm : (fun i => if e i ∈ T then μ else ν) = Sum.elim (fun _ : Fin T.card => μ) (fun _ : Fin (N-T.card) => ν) := by + funext i + cases i with + | inl i => exact ite_eq_left (eA i).property + | inr i => exact ite_eq_right (eB i).property + rwa [hm] at hh + +end Fock + +def fockCoeff (z : ℝ) (n : ℕ) : ℝ≥0∞ := ENNReal.ofReal (Real.exp (z*n)/n.factorial) + +lemma fockCoeff_choose (z : ℝ) {N m : ℕ} (hm : m ≤ N) : + fockCoeff z N * N.choose m = fockCoeff z m * fockCoeff z (N-m) := by + have hz : z*(N:ℝ) = z*m + z*(N-m : ℕ) := by rw [Nat.cast_sub hm]; ring + have hr : Real.exp (z*N)/(N.factorial:ℝ) * (N.choose m:ℝ) = + (Real.exp (z*m)/m.factorial) * (Real.exp (z*(N-m : ℕ))/(N-m).factorial) := by + calc + _ = Real.exp (z*N) * ((N.factorial:ℝ)⁻¹ * (N.choose m:ℝ)) := by ring + _ = Real.exp (z*N) * ((m.factorial:ℝ)⁻¹ * ((N-m).factorial:ℝ)⁻¹) := by rw [factorial_choose_cancel hm] + _ = _ := by rw [hz, Real.exp_add]; ring + have hh := congrArg ENNReal.ofReal hr + simpa only [ENNReal.ofReal_mul (by positivity : 0 ≤ Real.exp (z*N)/(N.factorial:ℝ)), + ENNReal.ofReal_mul (by positivity : 0 ≤ Real.exp (z*m)/(m.factorial:ℝ)), + ENNReal.ofReal_natCast, fockCoeff] using hh + +lemma ennreal_subsets_card (N : ℕ) (f : ℕ → ℝ≥0∞) : + (∑ T : Finset (Fin N), f T.card) = ∑ m ∈ Finset.range (N+1), (N.choose m:ℝ≥0∞)*f m := by + have hh := Finset.sum_powerset (Finset.univ : Finset (Fin N)) (fun T => f T.card) + simpa only [Finset.powerset_univ, Finset.card_univ, Fintype.card_fin, + Finset.sum_powersetCard, nsmul_eq_mul] using hh + +lemma ennreal_tsum_triangle (g : ℕ → ℕ → ℝ≥0∞) : + (∑' N, ∑ m ∈ Finset.range (N+1), g m (N-m)) = ∑' m, ∑' n, g m n := by + rw [← ENNReal.tsum_prod, + ← Finset.HasAntidiagonal.sigmaAntidiagonalEquivProd.tsum_eq (fun p : ℕ × ℕ => g p.1 p.2), + ENNReal.tsum_sigma'] + apply tsum_congr + intro n + rw [tsum_fintype] + change (∑ m ∈ Finset.range (n+1), g m (n-m)) = + ∑ b : {p : ℕ × ℕ // p ∈ Finset.HasAntidiagonal.antidiagonal n}, g b.1.1 b.1.2 + exact (Finset.Nat.sum_antidiagonal_eq_sum_range_succ (fun k l => g k l) n).symm.trans + (Finset.sum_finset_coe (fun p : ℕ × ℕ => g p.1 p.2) (Finset.HasAntidiagonal.antidiagonal n)).symm + +section FockAdd +variable {X : Type uX} [MeasurableSpace X] +variable (F : ∀ (ι : Type) [Fintype ι], (ι → X) → ℝ≥0∞) +variable (heq : ∀ (ι κ : Type) [Fintype ι] [Fintype κ] (e : ι ≃ κ) (x : κ → X), + F ι (x ∘ e) = F κ x) + +def fockIntegral (μ : Measure X) (z : ℝ) : ℝ≥0∞ := + ∑' n : ℕ, fockCoeff z n * ∫⁻ x : Fin n → X, F _ x ∂Measure.pi (fun _ => μ) + +include heq in +lemma fockIntegral_add (μ ν : Measure X) [SigmaFinite μ] [SigmaFinite ν] (z : ℝ) : + fockIntegral F (μ+ν) z = ∑' m : ℕ, ∑' n : ℕ, + fockCoeff z m * fockCoeff z n * + ∫⁻ x : Fin m ⊕ Fin n → X, F _ x ∂Measure.pi (Sum.elim (fun _ => μ) (fun _ => ν)) := by + classical + unfold fockIntegral + calc + _ = ∑' N : ℕ, ∑ m ∈ Finset.range (N+1), + fockCoeff z m * fockCoeff z (N-m) * + ∫⁻ x : Fin m ⊕ Fin (N-m) → X, F _ x ∂Measure.pi (Sum.elim (fun _ => μ) (fun _ => ν)) := by + apply tsum_congr + intro N + rw [measure_pi_add, lintegral_finsetSum_measure] + simp_rw [functional_sector_card F heq μ ν] + rw [ennreal_subsets_card N (fun m => + ∫⁻ x : Fin m ⊕ Fin (N-m) → X, F _ x ∂Measure.pi (Sum.elim (fun _ => μ) (fun _ => ν))), + Finset.mul_sum] + apply Finset.sum_congr rfl + intro m hm + rw [← mul_assoc, fockCoeff_choose z (Nat.le_of_lt_succ (Finset.mem_range.mp hm))] + _ = _ := ennreal_tsum_triangle (fun m n => fockCoeff z m * fockCoeff z n * + ∫⁻ x : Fin m ⊕ Fin n → X, F _ x ∂Measure.pi (Sum.elim (fun _ => μ) (fun _ => ν))) + +end FockAdd +section MultisetFock +variable {X : Type uX} + +def configurationMultiset {ι : Type} [Fintype ι] (x : ι → X) : Multiset X := ∑ i, {x i} + +def particleMultiset (x : ParticleState X) : Multiset X := configurationMultiset x.2 + +lemma configurationMultiset_equiv {ι κ : Type} [Fintype ι] [Fintype κ] + (e : ι ≃ κ) (x : κ → X) : configurationMultiset (x ∘ e) = configurationMultiset x := + e.sum_comp (fun i => {x i}) + +lemma configurationMultiset_sum {ι κ : Type} [Fintype ι] [Fintype κ] + (x : ι → X) (y : κ → X) : + configurationMultiset (Sum.elim x y) = configurationMultiset x + configurationMultiset y := by + exact Fintype.sum_sum_type _ + +variable [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] +variable (F : Multiset X → ℝ≥0∞) + +def ContinuousConfiguration : Prop := + ∀ (s : Multiset X) (ι : Type) [Fintype ι], Continuous (fun x : ι → X => F (s+configurationMultiset x)) + +omit [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] in +lemma continuous_particleObservable (hF : ContinuousConfiguration F) (s : Multiset X) : + Continuous (fun x : ParticleState X => F (s+particleMultiset x)) := by + apply continuous_sigma + intro n + exact hF s (Fin n) + +omit [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] in +lemma continuous_particlePairObservable (hF : ContinuousConfiguration F) (s : Multiset X) : + Continuous (fun p : ParticleState X × ParticleState X => F (s+particleMultiset p.1+particleMultiset p.2)) := by + apply continuous_particle_prod (f := fun x y => F (s+particleMultiset x+particleMultiset y)) + intro m n + have hh := (hF s (Fin m ⊕ Fin n)).comp + (show Continuous (fun p : (Fin m → X) × (Fin n → X) => Sum.elim p.1 p.2) from by + apply continuous_pi + intro i + cases i with + | inl i => exact (continuous_apply i).comp continuous_fst + | inr i => exact (continuous_apply i).comp continuous_snd) + change Continuous (fun p : (Fin m → X) × (Fin n → X) => F (s+configurationMultiset (Sum.elim p.1 p.2))) at hh + simpa only [configurationMultiset_sum, add_assoc, particleMultiset] using hh + +lemma fockIntegral_eq_lintegral (hF : ContinuousConfiguration F) (μ : Measure X) (z : ℝ) (s : Multiset X) : + fockIntegral (fun _ι _ x => F (s+configurationMultiset x)) μ z = + ∫⁻ x, F (s+particleMultiset x) ∂particleBase μ z := by + rw [lintegral_particleBase μ z (continuous_particleObservable F hF s).measurable] + rfl + +lemma particleBase_add_observable (hF : ContinuousConfiguration F) + (μ ν : Measure X) [IsFiniteMeasure μ] [IsFiniteMeasure ν] (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (μ+ν) z) = + ∫⁻ x, ∫⁻ y, F (s+particleMultiset x+particleMultiset y) ∂particleBase ν z ∂particleBase μ z := by + let G (ι : Type) [Fintype ι] (x : ι → X) := F (s+configurationMultiset x) + have hG : ∀ (ι κ : Type) [Fintype ι] [Fintype κ] (e : ι ≃ κ) (x : κ → X), G ι (x ∘ e) = G κ x := by + intros + dsimp [G] + rw [configurationMultiset_equiv] + rw [← fockIntegral_eq_lintegral F hF, fockIntegral_add G hG μ ν z] + have hpair := (continuous_particlePairObservable F hF s).measurable + rw [lintegral_particleBase μ z hpair.lintegral_prod_right] + apply tsum_congr + intro m + simp only [particleMultiset] + have hinner (x : Fin m → X) : + (∫⁻ y : ParticleState X, F (s+configurationMultiset x+configurationMultiset y.2) ∂particleBase ν z) = + ∑' n : ℕ, fockCoeff z n * ∫⁻ y : Fin n → X, F (s+configurationMultiset x+configurationMultiset y) + ∂Measure.pi (fun _ => ν) := + lintegral_particleBase ν z ((continuous_particleObservable F hF (s+configurationMultiset x)).measurable) + simp_rw [hinner] + rw [lintegral_tsum] + · rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro n + rw [lintegral_const_mul' _ _ (by exact ENNReal.ofReal_ne_top)] + rw [← mul_assoc] + congr 1 + let e := MeasurableEquiv.sumPiEquivProdPi (fun _ : Fin m ⊕ Fin n => X) + have hs : ∀ i : Fin m ⊕ Fin n, SigmaFinite (Sum.elim (fun _ => μ) (fun _ => ν) i) := by + intro i + cases i + · change SigmaFinite μ; infer_instance + · change SigmaFinite ν; infer_instance + have hp := measurePreserving_sumPiEquivProdPi_symm (Sum.elim (fun _ : Fin m => μ) (fun _ : Fin n => ν)) + rw [← hp.lintegral_comp (hF s (Fin m ⊕ Fin n)).measurable] + change (∫⁻ p : (Fin m → X) × (Fin n → X), F (s+configurationMultiset (Sum.elim p.1 p.2)) + ∂(Measure.pi (fun _ => μ)).prod (Measure.pi (fun _ => ν))) = _ + have hmeas : Measurable (fun p : (Fin m → X) × (Fin n → X) => F (s+configurationMultiset (Sum.elim p.1 p.2))) := + (hF s (Fin m ⊕ Fin n)).measurable.comp e.symm.measurable + rw [lintegral_prod _ hmeas.aemeasurable] + apply lintegral_congr + intro x + apply lintegral_congr + intro y + dsimp [G] + rw [configurationMultiset_sum, add_assoc] + · intro n + apply Measurable.aemeasurable + apply Measurable.const_mul + have hh := (hF s (Fin m ⊕ Fin n)).measurable.comp + (show Measurable (fun p : (Fin m → X) × (Fin n → X) => Sum.elim p.1 p.2) from by + apply measurable_pi_iff.mpr + intro i + cases i with + | inl i => exact (measurable_pi_apply i).comp measurable_fst + | inr i => exact (measurable_pi_apply i).comp measurable_snd) + change Measurable (fun p : (Fin m → X) × (Fin n → X) => F (s+configurationMultiset (Sum.elim p.1 p.2))) at hh + simp only [configurationMultiset_sum, ← add_assoc] at hh + exact hh.lintegral_prod_right + +end MultisetFock +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/FreeClusterCover.lean b/lean/OAI/Probability/RadialTransition/FreeClusterCover.lean new file mode 100644 index 0000000000000000000000000000000000000000..7d00841628df1058dc67826bf7d162ef91386fd3 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/FreeClusterCover.lean @@ -0,0 +1,91 @@ +import OAI.Probability.RadialTransition.FreeGeometry + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma starWeight_ge_one {A : Set Position} {r : ℝ} {s : Multiset Position} {x : Position} + (hx : x ∈ s) (hA : x ∈ A) (hr : ∀ y ∈ s, y ∈ nearCube r x) : + 1 ≤ starWeight A r s := by + have hp : (s.map (nearMask r x)).prod = 1 := by + apply Multiset.prod_eq_one + intro a ha + obtain ⟨y,hy,rfl⟩ := Multiset.mem_map.mp ha + exact indicator_of_mem (hr y hy) _ + have hs := Multiset.single_le_sum (fun _ _ => (bot_le : (0:ℝ≥0∞) ≤ _)) + _ (Multiset.mem_map.mpr ⟨x,hx,rfl⟩ : regionMask A x*(s.map (nearMask r x)).prod ∈ + s.map (fun y => regionMask A y*(s.map (nearMask r y)).prod)) + simpa only [hp, regionMask, indicator_of_mem hA, mul_one, starWeight] using hs + +lemma cellClusterWeight_empty (t α r : ℝ) (k : Cell) : 1 ≤ cellClusterWeight t α r k 0 := by + simp [cellClusterWeight, emptyWeight, starWeight] + +lemma cellClusterWeight_ge {t α r : ℝ} {k : Cell} {s : Multiset Position} + (hc : s.card ≤ 4) {x : Position} (hx : x ∈ s) (hk : cellOf x=k) + (hr : ∀ y ∈ s, y ∈ nearCube r x) : + ENNReal.ofReal (Real.exp (-t*α)) ≤ cellClusterWeight t α r k s := by + have hh := mul_le_mul' (le_rfl : ENNReal.ofReal (Real.exp (-t*α)) ≤ _) (starWeight_ge_one hx (show x ∈ gridRegion k from hk) hr) + rw [mul_one] at hh + exact hh.trans (by simp only [cellClusterWeight, ite_eq_left hc]; exact le_add_self) + +lemma coreFree_cell_cover {ι : Type} [Fintype ι] {t α L : ℝ} {x : ι → Position} + (hx : CoreFree t x) (ht : 2*((1+(1:ℝ)/1000)*microLength t) < 1) + (hbox : ∀ i, x i ∈ cube L) (hta : 0 ≤ t*α) : + ENNReal.ofReal (Real.exp (-t*α*(packingNumber L:ℝ))) ≤ + indexedClusterProduct (fun k : cubeCells L => + cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k.val) (configurationMultiset x) := by + classical + let Q := Quotient (coreFreeSetoid hx ht) + let S (q : Q) := Finset.univ.filter (fun i => Quotient.mk (coreFreeSetoid hx ht) i = q) + let s (q : Q) := (S q).val.map x + let f (q : Q) : cubeCells L := ⟨cellOf (x q.out), cellOf_mem_cubeCells (hbox _)⟩ + let W (k : cubeCells L) := cellClusterWeight t α ((1+(1:ℝ)/1000)*microLength t) k.val + have hroot := coreFree_roots hx ht hbox + have hf : Function.Injective f := by + intro q q' he + exact hroot.2 (congrArg Subtype.val he) + have hsum : ∑ q, s q = configurationMultiset x := by + convert configurationMultiset_fibers x (Quotient.mk (coreFreeSetoid hx ht)) using 1 + apply Finset.sum_congr rfl + intro q _ + dsimp [s, S] + congr 1 + ext i + simp only [Multiset.count_filter] + split_ifs <;> rfl + have hW (q : Q) : ENNReal.ofReal (Real.exp (-t*α)) ≤ W (f q) (s q) := by + apply cellClusterWeight_ge + · simpa only [s, Multiset.card_map, S, Finset.card_def] using coreFree_fiber_card hx ht q + · apply Multiset.mem_map.mpr + refine ⟨q.out, ?_, rfl⟩ + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, Quotient.out_eq q⟩ + · rfl + · intro y hy + obtain ⟨j,hj,rfl⟩ := Multiset.mem_map.mp hy + have hjq : Quotient.mk (coreFreeSetoid hx ht) j = q := (Finset.mem_filter.mp hj).2 + have hd : dist (x j) (x q.out) < 1 := Quotient.exact (hjq.trans (Quotient.out_eq q).symm) + intro d + simpa only [Real.dist_eq] using (PiLp.dist_apply_le (x j) (x q.out) d).trans (hx.dist_bound j q.out hd) + have hprod : ENNReal.ofReal (Real.exp (-t*α*(Fintype.card Q:ℝ))) ≤ ∏ q, W (f q) (s q) := by + have hh := Finset.prod_le_prod (fun q (_ : q ∈ (Finset.univ : Finset Q)) => hW q) + simp only [Finset.prod_const, Finset.card_univ] at hh + rw [← ENNReal.ofReal_pow (Real.exp_pos _).le, ← Real.exp_nat_mul] at hh + rw [mul_comm (Fintype.card Q : ℝ)] at hh + exact hh + have hcount : ENNReal.ofReal (Real.exp (-t*α*(packingNumber L:ℝ))) ≤ + ENNReal.ofReal (Real.exp (-t*α*(Fintype.card Q:ℝ))) := by + apply ENNReal.ofReal_le_ofReal + apply Real.exp_le_exp.mpr + have hc : (Fintype.card Q:ℝ) ≤ packingNumber L := by exact_mod_cast hroot.1 + nlinarith + have hcover := indexedClusterProduct_embedding W (fun k => cellClusterWeight_empty _ _ _ _) f hf s + rw [hsum] at hcover + exact hcount.trans (hprod.trans hcover) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/FreeGeometry.lean b/lean/OAI/Probability/RadialTransition/FreeGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..0b8055433e93a6257378c660a6597a859cb19d14 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/FreeGeometry.lean @@ -0,0 +1,109 @@ +import OAI.Probability.RadialTransition.ClusterEmbedding + +namespace OAI + +universe uIndex + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition +attribute [local instance] Classical.propDecidable + +def CoreFree {ι : Type uIndex} (t : ℝ) (x : ι → Position) : Prop := + ∀ i j, i ≠ j → dist (x i) (x j) < 1 → + microLength t ≤ dist (x i) (x j) ∧ + dist (x i) (x j) ≤ (1+(1:ℝ)/1000)*microLength t + +lemma same_cell_dist_lt {x y : Position} (h : cellOf x = cellOf y) : dist x y < 1 := by + have hc (k : Fin 3) : |x k-y k| ≤ 1/4 := by + have hh : ⌊4*x k⌋ = ⌊4*y k⌋ := congrFun h k + have hxl := Int.floor_le (4*x k) + have hxu := Int.lt_floor_add_one (4*x k) + have hyl := Int.floor_le (4*y k) + have hyu := Int.lt_floor_add_one (4*y k) + rw [← hh] at hyl hyu + exact abs_le.mpr ⟨by linarith, by linarith⟩ + have hs : dist x y ^ 2 ≤ 3*(1/4:ℝ)^2 := by + rw [EuclideanSpace.dist_sq_eq] + calc + _ ≤ ∑ k : Fin 3, (1/4:ℝ)^2 := Finset.sum_le_sum (fun k _ => by + simpa only [Real.dist_eq] using (sq_le_sq₀ (abs_nonneg _) (by norm_num)).mpr (hc k)) + _ = _ := by simp + nlinarith [dist_nonneg (x := x) (y := y)] + +lemma CoreFree.dist_bound {ι : Type uIndex} {t : ℝ} {x : ι → Position} (hx : CoreFree t x) + (i j : ι) (hij : dist (x i) (x j) < 1) : + dist (x i) (x j) ≤ (1+(1:ℝ)/1000)*microLength t := by + by_cases he : i = j + · subst j; simp only [dist_self]; exact mul_nonneg (by norm_num) (microLength_pos t).le + · exact (hx i j he hij).2 + +def coreFreeSetoid {ι : Type uIndex} {t : ℝ} {x : ι → Position} (hx : CoreFree t x) + (ht : 2*((1+(1:ℝ)/1000)*microLength t) < 1) : Setoid ι where + r i j := dist (x i) (x j) < 1 + iseqv := ⟨fun _ => by simp, fun h => by simpa only [dist_comm] using h, by + intro i j k hij hjk + have h1 := hx.dist_bound i j hij + have h2 := hx.dist_bound j k hjk + linarith [dist_triangle (x i) (x j) (x k)]⟩ + +lemma coreFree_fiber_card {ι : Type uIndex} [Fintype ι] [DecidableEq ι] + {t : ℝ} {x : ι → Position} (hx : CoreFree t x) + (ht : 2*((1+(1:ℝ)/1000)*microLength t) < 1) + (q : Quotient (coreFreeSetoid hx ht)) : + (Finset.univ.filter (fun i => Quotient.mk (coreFreeSetoid hx ht) i = q)).card ≤ 4 := by + classical + let S := Finset.univ.filter (fun i => Quotient.mk (coreFreeSetoid hx ht) i = q) + have hclique : (shellGraph x (microLength t)).IsClique S := by + intro i hi j hj hij + have hiq : Quotient.mk (coreFreeSetoid hx ht) i = q := (Finset.mem_filter.mp hi).2 + have hjq : Quotient.mk (coreFreeSetoid hx ht) j = q := (Finset.mem_filter.mp hj).2 + exact ⟨hij, hx i j hij (Quotient.exact (hiq.trans hjq.symm))⟩ + by_contra hc + change ¬ S.card ≤ 4 at hc + have h5 : 5 ≤ S.card := by omega + exact (SimpleGraph.CliqueFree.mono h5 (shellGraph_cliqueFree x (microLength_pos t))) S + ⟨hclique, rfl⟩ + +lemma coreFree_roots {ι : Type uIndex} [Fintype ι] {t L : ℝ} {x : ι → Position} + (hx : CoreFree t x) (ht : 2*((1+(1:ℝ)/1000)*microLength t) < 1) + (hbox : ∀ i, x i ∈ cube L) : + Fintype.card (Quotient (coreFreeSetoid hx ht)) ≤ packingNumber L ∧ + Function.Injective (fun q : Quotient (coreFreeSetoid hx ht) => cellOf (x q.out)) := by + classical + let Q := Quotient (coreFreeSetoid hx ht) + have hsep (q r : Q) (hqr : q ≠ r) : 1 ≤ dist (x q.out) (x r.out) := by + by_contra! hh + apply hqr + have he : Quotient.mk (coreFreeSetoid hx ht) q.out = Quotient.mk (coreFreeSetoid hx ht) r.out := + Quotient.sound hh + simpa only [Quotient.out_eq] using he + have hinj : Function.Injective (fun q : Q => x q.out) := by + intro q r he + by_contra hne + have hh := hsep q r hne + change x q.out = x r.out at he + rw [he, dist_self] at hh + norm_num at hh + constructor + · let S := Finset.univ.image (fun q : Q => x q.out) + have hp : IsPacking L S := by + constructor + · intro y hy + obtain ⟨q, _, rfl⟩ := Finset.mem_image.mp hy + exact hbox _ + · intro y hy z hz hyz + obtain ⟨q, _, rfl⟩ := Finset.mem_image.mp hy + obtain ⟨r, _, rfl⟩ := Finset.mem_image.mp hz + exact hsep q r (fun he => hyz (congrArg (fun q : Q => x q.out) he)) + have hh := packing_card_le hp + simpa only [S, Finset.card_image_of_injective _ hinj, Finset.card_univ] using hh + · intro q r he + by_contra hne + exact (not_lt_of_ge (hsep q r hne)) (same_cell_dist_lt he) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/GrandBounds.lean b/lean/OAI/Probability/RadialTransition/GrandBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..617dcc575538e3d40616b2c2da25da943b3ac52b --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/GrandBounds.lean @@ -0,0 +1,98 @@ +import OAI.Probability.RadialTransition.LinearInteractions + +namespace OAI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff BigOperators ENNReal NNReal + +namespace RadialTransition + +lemma finite_term_le_grand {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t L β : ℝ} (hst : StableWith φ B) (ht : 0 < t) (hL : 0 < L) (hβ : 0 ≤ β) (h : ℝ) (n : ℕ) : + h*((n:ℝ)/L^3)-finiteCanonical φ t L n β ≤ finiteGrandPressure φ t L β h := by + have hterm := (grandPartition_summable hφ hb hst hL.le hβ t h).le_tsum n + (fun N _ => mul_nonneg (Real.exp_pos _).le (partition_nonneg L N β)) + have hh := Real.log_le_log (mul_pos (Real.exp_pos _) (partition_pos hφ hb hL n β)) hterm + rw [Real.log_mul (Real.exp_ne_zero _) (partition_pos hφ hb hL n β).ne', Real.log_exp] at hh + dsimp only [finiteGrandPressure, finiteCanonical] + apply (le_div_iff₀ (by positivity : 0 < t*L^3)).mpr + convert hh using 1 <;> first | rfl | (try field_simp [ht.ne', hL.ne']; ring) + +lemma log_quadraticTerm_eq {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {t L : ℝ} (ht : 0 < t) (hL : 0 < L) (β h a eta : ℝ) (n : ℕ) : + Real.log (quadraticTerm φ L β (t*h) (β*t*a*(1+eta)/2) n)/(t*L^3) = + (h+β*a*((n:ℝ)/L^3))*((n:ℝ)/L^3)-finiteCanonical φ t L n β - + β*a/2*((n:ℝ)/L^3)^2+β*a*eta/2*((n:ℝ)/L^3)^2 := by + rw [quadraticTerm, Real.log_mul (mul_ne_zero (Real.exp_ne_zero _) (partition_pos hφ hb hL n β).ne') (Real.exp_ne_zero _), + Real.log_mul (Real.exp_ne_zero _) (partition_pos hφ hb hL n β).ne', Real.log_exp, Real.log_exp] + unfold finiteCanonical + field_simp + ring + +lemma log_quadraticTerm_bound {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t L β : ℝ} (hst : StableWith φ B) (ht : 0 < t) (hL : 0 < L) (hβ : 0 ≤ β) + (h a eta : ℝ) (n : ℕ) : + Real.log (quadraticTerm φ L β (t*h) (β*t*a*(1+eta)/2) n)/(t*L^3) ≤ + finiteGrandPressure φ t L β (h+β*a*((n:ℝ)/L^3)) - + β*a/2*((n:ℝ)/L^3)^2+β*a*eta/2*((n:ℝ)/L^3)^2 := by + rw [log_quadraticTerm_eq hφ hb ht hL] + linarith [finite_term_le_grand hφ hb hst ht hL hβ (h+β*a*((n:ℝ)/L^3)) n] + +lemma quadratic_sum_pressure_bound {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t L β h a eta c B₀ κ D P : ℝ} (hst : StableWith φ B) (ht : 0 < t) (hL : 1 ≤ L) + (hβ : 0 ≤ β) (ha : 0 ≤ a) (heta : 0 ≤ eta) (hκ : 0 < κ) + (hc : κ ≤ β*c-β*t*a*(1+eta)/2) (hD : 1 ≤ D) (hcut : t*h+β*B₀+2 ≤ κ*D) + (hE : ∀ n x, x ∈ configurationCube L n → c*(n:ℝ)^2/L^3-B₀*n ≤ energy φ x) + (hP : 0 ≤ P) (hbound : ∀ d ∈ Icc (0:ℝ) D, finiteGrandPressure φ t L β (h+β*a*d)-β*a/2*d^2 ≤ P) : + Summable (quadraticTerm φ L β (t*h) (β*t*a*(1+eta)/2)) ∧ + Real.log (∑' n, quadraticTerm φ L β (t*h) (β*t*a*(1+eta)/2) n)/(t*L^3) ≤ + P+β*a*eta/2*D^2+Real.log ((D+2)*L^3)/(t*L^3) := by + have hL0 : 0 < L := zero_lt_one.trans_le hL + have hV : 0 < t*L^3 := by positivity + let N := ⌊D*L^3⌋₊ + let F := quadraticTerm φ L β (t*h) (β*t*a*(1+eta)/2) + have hFp (n : ℕ) : 0 < F n := quadraticTerm_pos hφ hb hL0 _ _ _ n + have htail (n : ℕ) (hn : N < n) : F n ≤ Real.exp (-(n:ℝ)) := by + apply quadraticTerm_tail_bound hφ hb hL0 hβ hκ hc hD hcut hE + exact (Nat.floor_lt (by positivity : 0 ≤ D*L^3)).mp hn + have hs : Summable F := summable_of_tail_exp (fun n => (hFp n).le) N htail + let M := Real.exp (t*L^3*(P+β*a*eta/2*D^2)) + have hM : 1 ≤ M := Real.one_le_exp_iff.mpr (by positivity) + have hsmall (n : ℕ) (hn : n ≤ N) : F n ≤ M := by + have hnD : (n:ℝ)/L^3 ≤ D := by + apply (div_le_iff₀ (by positivity : 0 < L^3)).mpr + exact (by exact_mod_cast hn : (n:ℝ) ≤ N).trans (Nat.floor_le (by positivity)) + have hd0 : 0 ≤ (n:ℝ)/L^3 := by positivity + have hbnd := hbound ((n:ℝ)/L^3) ⟨hd0, hnD⟩ + have hh := log_quadraticTerm_bound hφ hb hst ht hL0 hβ h a eta n + have he : β*a*eta/2*((n:ℝ)/L^3)^2 ≤ β*a*eta/2*D^2 := by + apply mul_le_mul_of_nonneg_left (sq_le_sq₀ hd0 (by positivity) |>.mpr hnD) + positivity + have hl : Real.log (F n)/(t*L^3) ≤ P+β*a*eta/2*D^2 := by linarith + have hl' := (div_le_iff₀ hV).mp hl + calc + _ = Real.exp (Real.log (F n)) := (Real.exp_log (hFp n)).symm + _ ≤ M := Real.exp_le_exp.mpr (by nlinarith) + have hsum := truncated_sum_bound hs hM (tail_le_one_of_exp (fun n => (hFp n).le) N htail) hsmall + have hnV : (N:ℝ)+2 ≤ (D+2)*L^3 := by + have hfloor := Nat.floor_le (show 0 ≤ D*L^3 by positivity) + have hV1 : 1 ≤ L^3 := one_le_pow₀ hL + dsimp only [N] + nlinarith + have hsum' := hsum.trans (mul_le_mul_of_nonneg_right hnV (by positivity : 0 ≤ M)) + have hpos : 0 < ∑' n, F n := lt_of_lt_of_le (hFp 0) (hs.le_tsum 0 (fun n _ => (hFp n).le)) + have hl := Real.log_le_log hpos hsum' + rw [Real.log_mul (by positivity) (Real.exp_ne_zero _), Real.log_exp] at hl + refine ⟨hs, ?_⟩ + apply (div_le_iff₀ hV).mpr + convert hl using 1; first | rfl | (try field_simp [ht.ne', hL0.ne']; ring) + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/GrandPartition.lean b/lean/OAI/Probability/RadialTransition/GrandPartition.lean new file mode 100644 index 0000000000000000000000000000000000000000..c34febb1cdd8012791f9c821802b5c94e7e3f70f --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/GrandPartition.lean @@ -0,0 +1,137 @@ +import OAI.Probability.RadialTransition.PartitionReplication + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +def grandOn (φ : Potential) (A : Set Position) (β z : ℝ) : ℝ := + ∑' N : ℕ, Real.exp (z * N) * partitionOn φ A N β + +theorem partitionOn_stability_upper {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B β : ℝ} (hstable : StableWith φ B) + (hβ : 0 ≤ β) {A : Set Position} (hAfin : volume A ≠ ⊤) (N : ℕ) : + partitionOn φ A N β ≤ (volume.real A) ^ N * Real.exp (β * B * N) / N.factorial := by + let : IsFiniteMeasure (volume.restrict A) := isFiniteMeasure_restrict.mpr hAfin + have hh : rawPartition φ A (Fin N) β ≤ (volume.real A) ^ N * Real.exp (β * B * N) := by + calc + _ ≤ ∫ _ : Fin N → Position, Real.exp (β * B * N) + ∂Measure.pi (fun _ : Fin N => volume.restrict A) := by + apply integral_mono (integrable_orderedBoltzmann hφ hb β _) (integrable_const _) + intro x + apply Real.exp_le_exp.mpr + rw [orderedEnergy_fin] + nlinarith [mul_le_mul_of_nonneg_left (hstable N x) hβ] + _ = _ := by + simp [integral_const, measureReal_def, Measure.pi_univ] + have hh' := mul_le_mul_of_nonneg_left hh + (show (0 : ℝ) ≤ (N.factorial : ℝ)⁻¹ by positivity) + simpa only [partitionOn, div_eq_mul_inv, mul_comm, mul_left_comm, mul_assoc] using hh' + +theorem grandOn_term_upper {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B β : ℝ} (hstable : StableWith φ B) + (hβ : 0 ≤ β) {A : Set Position} (hAfin : volume A ≠ ⊤) (z : ℝ) (N : ℕ) : + Real.exp (z * N) * partitionOn φ A N β ≤ + (volume.real A * Real.exp (β * B + z)) ^ N / N.factorial := by + have hh := mul_le_mul_of_nonneg_left (partitionOn_stability_upper hφ hb hstable hβ hAfin N) + (Real.exp_pos (z * N)).le + apply hh.trans_eq + rw [Real.exp_add, mul_pow, mul_pow, ← Real.exp_nat_mul (β * B) N, + ← Real.exp_nat_mul z N] + have he₁ : β * B * (N : ℝ) = (N : ℝ) * (β * B) := by ring + have he₂ : z * (N : ℝ) = (N : ℝ) * z := by ring + rw [he₁, he₂] + ring + +theorem grandOn_summable {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B β : ℝ} (hstable : StableWith φ B) + (hβ : 0 ≤ β) {A : Set Position} (hAfin : volume A ≠ ⊤) (z : ℝ) : + Summable (fun N : ℕ => Real.exp (z * N) * partitionOn φ A N β) := + Summable.of_nonneg_of_le + (fun N => mul_nonneg (Real.exp_pos _).le (partitionOn_nonneg φ A N β)) + (grandOn_term_upper hφ hb hstable hβ hAfin z) + (Real.summable_pow_div_factorial _) + +theorem grandOn_bounds {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B β : ℝ} (hstable : StableWith φ B) + (hβ : 0 ≤ β) {A : Set Position} (hAfin : volume A ≠ ⊤) (z : ℝ) : + 1 ≤ grandOn φ A β z ∧ grandOn φ A β z ≤ Real.exp (volume.real A * Real.exp (β * B + z)) := by + have hs := grandOn_summable hφ hb hstable hβ hAfin z + constructor + · have hh := hs.le_tsum 0 (fun N _ => mul_nonneg (Real.exp_pos _).le (partitionOn_nonneg φ A N β)) + convert hh using 1 <;> first | rfl | norm_num [partitionOn_zero] + · have hh := hs.tsum_le_tsum (grandOn_term_upper hφ hb hstable hβ hAfin z) + (Real.summable_pow_div_factorial _) + have he : (∑' N : ℕ, (volume.real A * Real.exp (β * B + z)) ^ N / N.factorial) = + Real.exp (volume.real A * Real.exp (β * B + z)) := by + rw [Real.exp_eq_exp_ℝ, NormedSpace.exp_eq_tsum_div] + exact hh.trans_eq he + +theorem grandOn_union_lower {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {B β : ℝ} (hstable : StableWith φ B) (hβ : 0 ≤ β) + {A D : Set Position} (hA : MeasurableSet A) (hD : MeasurableSet D) (had : Disjoint A D) + (hAfin : volume A ≠ ⊤) (hDfin : volume D ≠ ⊤) + (hc : ∀ x ∈ A, ∀ y ∈ D, φ (nndist x y) ≤ 0) (z : ℝ) : + grandOn φ A β z * grandOn φ D β z ≤ grandOn φ (A ∪ D) β z := by + have hUfin : volume (A ∪ D) ≠ ⊤ := (measure_union_le A D).trans_lt + (ENNReal.add_lt_top.mpr ⟨hAfin.lt_top, hDfin.lt_top⟩) |>.ne + have hsA := grandOn_summable hφ hb hstable hβ hAfin z + have hsD := grandOn_summable hφ hb hstable hβ hDfin z + have hsU := grandOn_summable hφ hb hstable hβ hUfin z + have hcov (N : ℕ) : + (∑ m ∈ Finset.range (N + 1), (Real.exp (z * m) * partitionOn φ A m β) * + (Real.exp (z * ((N - m : ℕ) : ℝ)) * partitionOn φ D (N - m) β)) ≤ + Real.exp (z * N) * partitionOn φ (A ∪ D) N β := by + have he : (∑ m ∈ Finset.range (N + 1), (Real.exp (z * m) * partitionOn φ A m β) * + (Real.exp (z * ((N - m : ℕ) : ℝ)) * partitionOn φ D (N - m) β)) = + Real.exp (z * N) * ∑ m ∈ Finset.range (N + 1), + partitionOn φ A m β * partitionOn φ D (N - m) β := by + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro m hm + have hmN : m ≤ N := Nat.le_of_lt_succ (Finset.mem_range.mp hm) + have he : z * (m : ℝ) + z * (N - m : ℕ) = z * N := by + rw [Nat.cast_sub hmN]; ring + calc + _ = (Real.exp (z * m) * Real.exp (z * ((N - m : ℕ) : ℝ))) * + (partitionOn φ A m β * partitionOn φ D (N - m) β) := by ring + _ = _ := by rw [← Real.exp_add, he] + rw [he] + exact mul_le_mul_of_nonneg_left (partitionOn_union_convolution hφ hb hβ hA hD had hAfin hDfin hc N) + (Real.exp_pos _).le + have hnn (N : ℕ) : 0 ≤ ∑ m ∈ Finset.range (N + 1), + (Real.exp (z * m) * partitionOn φ A m β) * + (Real.exp (z * ((N - m : ℕ) : ℝ)) * partitionOn φ D (N - m) β) := by + apply Finset.sum_nonneg + intro m _ + exact mul_nonneg (mul_nonneg (Real.exp_pos _).le (partitionOn_nonneg φ A m β)) + (mul_nonneg (Real.exp_pos _).le (partitionOn_nonneg φ D (N - m) β)) + rw [grandOn, grandOn, + tsum_mul_tsum_eq_tsum_sum_range_of_summable_norm hsA.norm hsD.norm] + exact (Summable.of_nonneg_of_le hnn hcov hsU).tsum_le_tsum hcov hsU + +theorem grandOn_mono {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B β : ℝ} (hstable : StableWith φ B) (hβ : 0 ≤ β) {A D : Set Position} + (hsub : A ⊆ D) (hDfin : volume D ≠ ⊤) (z : ℝ) : grandOn φ A β z ≤ grandOn φ D β z := by + have hAfin : volume A ≠ ⊤ := (measure_mono hsub).trans_lt hDfin.lt_top |>.ne + exact (grandOn_summable hφ hb hstable hβ hAfin z).tsum_le_tsum + (fun N => mul_le_mul_of_nonneg_left (partitionOn_mono hφ hb β N hsub hDfin) (Real.exp_pos _).le) + (grandOn_summable hφ hb hstable hβ hDfin z) + +theorem grandOn_translate (φ : Potential) (A : Set Position) (a : Position) (β z : ℝ) : + grandOn φ (translateSet a A) β z = grandOn φ A β z := by + simp only [grandOn, partitionOn_translate] + +theorem grandOn_cube (φ : Potential) (L t β h : ℝ) : + grandOn φ (cube L) β (t * h) = grandPartition φ t L β h := by + simp only [grandOn, grandPartition, partitionOn_cube] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/GridPressure.lean b/lean/OAI/Probability/RadialTransition/GridPressure.lean new file mode 100644 index 0000000000000000000000000000000000000000..0aa7b36709783e19793d0325f481e53a8142e866 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/GridPressure.lean @@ -0,0 +1,93 @@ +import OAI.Probability.RadialTransition.MixtureBounds + +namespace OAI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff BigOperators ENNReal NNReal + +namespace RadialTransition + +def macroMeasure (m q : ℕ) (z : ℝ) : Measure (MacroState m q) := + Measure.pi (fun i : GridIndex m => particleBase (regionMeasure (macroRegion q (gridEmbed i))) z) + +def macroProduct (φ : Potential) (m q : ℕ) (β : ℝ) (F : ℕ → ℝ) (x : MacroState m q) : ℝ := + ∏ i : GridIndex m, (F (particleCount (x i))* + Real.exp (-β*pairWithin (fun (y z : macroRegion q (gridEmbed i)) => radialPair φ y z) (x i))) + +lemma macroProduct_nonneg (φ : Potential) (m q : ℕ) (β : ℝ) (F : ℕ → ℝ) + (hF : ∀ n, 0 ≤ F n) (x : MacroState m q) : 0 ≤ macroProduct φ m q β F x := + Finset.prod_nonneg (fun _ _ => mul_nonneg (hF _) (Real.exp_pos _).le) + +lemma integrable_macroProduct {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {q : ℕ} (hq : 0 < q) (m : ℕ) (β z : ℝ) (F : ℕ → ℝ) (hF : ∀ n, 0 ≤ F n) + (hs : Summable (fun n => F n*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β)) : + Integrable (macroProduct φ m q β F) (macroMeasure m q z) := by + let (i : GridIndex m) : IsFiniteMeasure (regionMeasure (macroRegion q (gridEmbed i))) := + regionMeasure_finite (measurableSet_macroRegion _ _) (by rw [volume_macroRegion hq]; finiteness) + exact Integrable.fintype_prod_dep (fun i => integrable_macroWeight hφ hb hq (gridEmbed i) β z F hF hs) + +lemma integral_macroProduct {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {q : ℕ} (hq : 0 < q) (m : ℕ) (β z : ℝ) (F : ℕ → ℝ) (hF : ∀ n, 0 ≤ F n) + (hs : Summable (fun n => F n*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β)) : + (∫ x, macroProduct φ m q β F x ∂macroMeasure m q z) = + (∑' n, F n*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β)^(m^3) := by + let (i : GridIndex m) : IsFiniteMeasure (regionMeasure (macroRegion q (gridEmbed i))) := + regionMeasure_finite (measurableSet_macroRegion _ _) (by rw [volume_macroRegion hq]; finiteness) + unfold macroProduct macroMeasure + rw [integral_fintype_prod_eq_prod (fun i : GridIndex m => fun s : ParticleState (macroRegion q (gridEmbed i)) => F (particleCount s)*Real.exp (-β*pairWithin (fun (y w : macroRegion q (gridEmbed i)) => radialPair φ y w) s))] + simp only [integral_macroWeight hφ hb hq _ β z F hF hs, Finset.prod_const, Finset.card_univ, + Fintype.card_fun, Fintype.card_fin] + +lemma macroQuad_upper {φ : Potential} {m q : ℕ} (hq : 0 < q) {β R lam : ℝ} + (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (hlam : 0 ≤ lam) (x : MacroState m q) : + Real.exp (-β*macroKacEnergy φ m q R lam x) ≤ + macroProduct φ m q β (fun n => Real.exp (β*lam*(1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3)*(n:ℝ)^2)) x := by + have hh := mul_le_mul_of_nonpos_left (macroKacEnergy_lower (φ := φ) hq hR hlam x) (neg_nonpos.mpr hβ) + apply (Real.exp_le_exp.mpr hh).trans_eq + simp only [macroProduct, ← Real.exp_add, ← Real.exp_sum] + congr 1 + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro i hi + ring + +lemma integrable_macroKac {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {m q : ℕ} (hq : 0 < q) {β R lam z : ℝ} (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (hlam : 0 ≤ lam) + (hs : Summable (quadraticTerm φ ((q:ℝ)/4) β z (β*lam*(1+10000*(bumpLip:ℝ)*q/R)/2))) : + Integrable (fun x => Real.exp (-β*macroKacEnergy φ m q R lam x)) (macroMeasure m q z) := by + have hs' : Summable (fun n : ℕ => Real.exp (β*lam*(1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3)*(n:ℝ)^2)*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β) := by + convert hs using 1 + funext n + dsimp only [quadraticTerm] + have he : β*lam*(1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3)*(n:ℝ)^2 = β*lam*(1+10000*(bumpLip:ℝ)*q/R)/2*(n:ℝ)^2/((q:ℝ)/4)^3 := by ring + rw [he]; ring + apply (integrable_macroProduct hφ hb hq m β z _ (fun _ => (Real.exp_pos _).le) hs').mono' + (Real.measurable_exp.comp (measurable_const.mul (measurable_macroKacEnergy hφ m q R lam))).aestronglyMeasurable + exact Eventually.of_forall (fun x => by change |Real.exp (-β*macroKacEnergy φ m q R lam x)| ≤ _; rw [abs_of_pos (Real.exp_pos _)]; exact macroQuad_upper hq hβ hR hlam x) + +lemma macroKac_partition_upper {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {m q : ℕ} (hq : 0 < q) {β R lam z : ℝ} (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (hlam : 0 ≤ lam) + (hs : Summable (quadraticTerm φ ((q:ℝ)/4) β z (β*lam*(1+10000*(bumpLip:ℝ)*q/R)/2))) : + boltzmannPartition (macroMeasure m q z) (fun x => β*macroKacEnergy φ m q R lam x) ≤ + (∑' n, quadraticTerm φ ((q:ℝ)/4) β z (β*lam*(1+10000*(bumpLip:ℝ)*q/R)/2) n)^(m^3) := by + have he (n : ℕ) : Real.exp (β*lam*(1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3)*(n:ℝ)^2)*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β = + quadraticTerm φ ((q:ℝ)/4) β z (β*lam*(1+10000*(bumpLip:ℝ)*q/R)/2) n := by + dsimp only [quadraticTerm] + have h : β*lam*(1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3)*(n:ℝ)^2 = β*lam*(1+10000*(bumpLip:ℝ)*q/R)/2*(n:ℝ)^2/((q:ℝ)/4)^3 := by ring + rw [h]; ring + have hs' : Summable (fun n : ℕ => Real.exp (β*lam*(1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3)*(n:ℝ)^2)*Real.exp (z*n)*partition φ ((q:ℝ)/4) n β) := by simpa only [he] using hs + have hh := integral_mono (integrable_macroKac hφ hb hq hβ hR hlam hs) + (integrable_macroProduct hφ hb hq m β z _ (fun _ => (Real.exp_pos _).le) hs') + (macroQuad_upper hq hβ hR hlam) + rw [integral_macroProduct hφ hb hq m β z _ (fun _ => (Real.exp_pos _).le) hs'] at hh + simpa only [he, boltzmannPartition, neg_mul] using hh + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/IdealAttainment.lean b/lean/OAI/Probability/RadialTransition/IdealAttainment.lean new file mode 100644 index 0000000000000000000000000000000000000000..44e459e604dd742e559e19531d307a36a81e66da --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/IdealAttainment.lean @@ -0,0 +1,119 @@ +import OAI.Probability.RadialTransition.CoreConvergence + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma entropy_lower {d : ℝ} (hd : 0 ≤ d) : -1 ≤ d*Real.log d-d := by + rcases eq_or_lt_of_le hd with rfl | hd + · norm_num + have hh := Real.log_le_sub_one_of_pos (inv_pos.mpr hd) + rw [Real.log_inv] at hh + have hm := mul_le_mul_of_nonneg_left hh hd.le + rw [mul_sub, mul_inv_cancel₀ hd.ne', mul_one] at hm + nlinarith + +lemma grandPressure_continuous_h {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t β : ℝ} (hst : StableWith φ B) (ht : 0 < t) (hβ : 0 ≤ β) + (hc : ∀ r : ℝ≥0, 2 ≤ (r:ℝ) → φ r ≤ 0) : Continuous (grandPressure φ t β) := by + have hconv : ConvexOn ℝ univ (grandPressure φ t β) := by + refine ⟨convex_univ, ?_⟩ + intro x _ y _ a b ha hbb hab + have hh := grandPressure_convex_mix hφ hb hst ht hc hβ hβ x y ha hbb hab + have he : a*β+b*β = β := by nlinarith + simpa only [he, smul_eq_mul] using hh + exact continuousOn_univ.mp (hconv.continuousOn isOpen_univ) + +lemma branch_le_density_value {Q : Pressure} {H : ℝ → ℝ} {β a h u d : ℝ} + (hk : 0 ≤ β*a) (hd : Q β (h+β*a*u) = (h+β*a*u)*d-H d) : + attractionBranch Q a u β h ≤ h*d-H d+β*a/2*d^2 := by + unfold attractionBranch + rw [hd] + nlinarith [mul_nonneg hk (sq_nonneg (u-d))] + +lemma branch_le_density_branch {Q : Pressure} {H : ℝ → ℝ} {β a h u d : ℝ} + (hk : 0 ≤ β*a) (hd : Q β (h+β*a*u) = (h+β*a*u)*d-H d) + (hdual : (h+β*a*d)*d-H d ≤ Q β (h+β*a*d)) : + attractionBranch Q a u β h ≤ attractionBranch Q a d β h := by + have hh := branch_le_density_value hk hd + unfold attractionBranch at hh ⊢ + nlinarith [hdual] + +lemma density_value_neg {H : ℝ → ℝ} {h k c B E U d : ℝ} + (hκ : 0 < c-k/2) (hE : 0 ≤ E) (hU : 1 ≤ U) + (hcut : h+B+E+1 ≤ (c-k/2)*U) (hd : U < d) + (hH : c*d^2-B*d-E ≤ H d) : h*d-H d+k/2*d^2 < 0 := by + have hd1 : 1 < d := hU.trans_lt hd + have hkd : h+B+E+1 < (c-k/2)*d := hcut.trans_lt (mul_lt_mul_of_pos_left hd hκ) + have hm := mul_lt_mul_of_pos_right hkd (show 0 < d by linarith) + have he := mul_le_mul_of_nonneg_left (show 1 ≤ d by linarith) hE + nlinarith + +lemma ideal_density_cofinal {Q : Pressure} {H : ℝ → ℝ} {β a h c B E U : ℝ} + (hk : 0 ≤ β*a) (hQ0 : 0 ≤ Q β h) + (hmax : ∀ j, ∃ d ≥ 0, Q β j = j*d-H d) + (hdual : ∀ j d, 0 ≤ d → j*d-H d ≤ Q β j) + (hH : ∀ d, 0 ≤ d → c*d^2-B*d-E ≤ H d) + (hκ : 0 < c-β*a/2) (hE : 0 ≤ E) (hU : 1 ≤ U) + (hcut : h+B+E+1 ≤ (c-β*a/2)*U) (u : ℝ) : + ∃ v ∈ Icc (0:ℝ) U, attractionBranch Q a u β h ≤ attractionBranch Q a v β h := by + obtain ⟨d, hd, he⟩ := hmax (h+β*a*u) + by_cases hdU : d ≤ U + · exact ⟨d, ⟨hd, hdU⟩, branch_le_density_branch hk he (hdual _ d hd)⟩ + · refine ⟨0, ⟨le_rfl, by linarith⟩, ?_⟩ + have hneg := density_value_neg hκ hE hU hcut (lt_of_not_ge hdU) (hH d hd) + have hh := branch_le_density_value hk he + simp only [attractionBranch, mul_zero, add_zero, zero_pow (by decide : 2 ≠ 0), sub_zero] + dsimp only [attractionBranch] at hh + linarith + +lemma ideal_exists_active_of_density_bound {Q : Pressure} {H : ℝ → ℝ} {β a h c B E U : ℝ} + (hcont : Continuous (Q β)) (hk : 0 ≤ β*a) (hQ0 : 0 ≤ Q β h) + (hmax : ∀ j, ∃ d ≥ 0, Q β j = j*d-H d) + (hdual : ∀ j d, 0 ≤ d → j*d-H d ≤ Q β j) + (hH : ∀ d, 0 ≤ d → c*d^2-B*d-E ≤ H d) + (hκ : 0 < c-β*a/2) (hE : 0 ≤ E) (hU : 1 ≤ U) + (hcut : h+B+E+1 ≤ (c-β*a/2)*U) : + ∃ u ∈ Icc (0:ℝ) U, ActiveShift Q a β h u := by + have hbr : Continuous (fun u => attractionBranch Q a u β h) := by + unfold attractionBranch + exact (hcont.comp (continuous_const.add (continuous_const.mul continuous_id))).sub + (continuous_const.mul (continuous_id.pow 2)) + obtain ⟨u, hu, hmaxu⟩ := isCompact_Icc.exists_isMaxOn (nonempty_Icc.mpr (show 0 ≤ U by linarith)) hbr.continuousOn + refine ⟨u, hu, fun v => ?_⟩ + obtain ⟨w, hw, hvw⟩ := ideal_density_cofinal hk hQ0 hmax hdual hH hκ hE hU hcut v + exact hvw.trans (hmaxu hw) + +lemma active_density_bound {Q : Pressure} {H : ℝ → ℝ} {β a h c B E U u : ℝ} + (hk : 0 < β*a) (hQ0 : 0 ≤ Q β h) + (hmax : ∀ j, ∃ d ≥ 0, Q β j = j*d-H d) + (hdual : ∀ j d, 0 ≤ d → j*d-H d ≤ Q β j) + (hH : ∀ d, 0 ≤ d → c*d^2-B*d-E ≤ H d) + (hκ : 0 < c-β*a/2) (hE : 0 ≤ E) (hU : 1 ≤ U) + (hcut : h+B+E+1 ≤ (c-β*a/2)*U) (hu : ActiveShift Q a β h u) : u ∈ Icc (0:ℝ) U := by + obtain ⟨d, hd, he⟩ := hmax (h+β*a*u) + have hh := hdual (h+β*a*d) d hd + have hm := hu d + dsimp only [attractionBranch] at hm + rw [he] at hm + have hsq : β*a*(u-d)^2 ≤ 0 := by nlinarith + have hud : u = d := by + have hs : (u-d)^2 ≤ 0 := le_of_mul_le_mul_left (by simpa only [mul_zero] using hsq) hk + nlinarith [sq_nonneg (u-d)] + subst u + refine ⟨hd, ?_⟩ + by_contra! hdU + have hneg := density_value_neg hκ hE hU hcut hdU (hH d hd) + have hz := hu 0 + dsimp only [attractionBranch] at hz + simp only [mul_zero, add_zero, zero_pow (by decide : 2 ≠ 0), sub_zero] at hz + rw [he] at hz + nlinarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/IdealAttraction.lean b/lean/OAI/Probability/RadialTransition/IdealAttraction.lean new file mode 100644 index 0000000000000000000000000000000000000000..9244f3eeb397c0543ba8f38e26ab1635ed7a5136 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/IdealAttraction.lean @@ -0,0 +1,106 @@ +import OAI.Probability.RadialTransition.Model + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +abbrev Pressure := ℝ → ℝ → ℝ + +def pressureSupport (Q : Pressure) (β h e d : ℝ) : Prop := + ∀ β' h', 0 < β' → + Q β h + e * (β' - β) + d * (h' - h) ≤ Q β' h' + +def attractionBranch (Q : Pressure) (a u : ℝ) : Pressure := + fun β h => Q β (h + β * a * u) - β * a / 2 * u ^ 2 + +def idealAttraction (Q : Pressure) (a : ℝ) : Pressure := + fun β h => sSup (Set.range fun u => attractionBranch Q a u β h) + +def ActiveShift (Q : Pressure) (a β h u : ℝ) : Prop := + ∀ v : ℝ, attractionBranch Q a v β h ≤ attractionBranch Q a u β h + +theorem active_parabola {Q : Pressure} {a β h u : ℝ} + (ha : 0 < a) (hβ : 0 < β) (hu : ActiveShift Q a β h u) (r : ℝ) : + Q β (h + β * a * u + r) ≤ + Q β (h + β * a * u) + u * r + r ^ 2 / (2 * β * a) := by + have ha0 : a ≠ 0 := ne_of_gt ha + have hβ0 : β ≠ 0 := ne_of_gt hβ + have hshift : h + β * a * (u + r / (β * a)) = h + β * a * u + r := by + field_simp + ring + have hc := hu (u + r / (β * a)) + dsimp [attractionBranch] at hc + rw [hshift] at hc + calc + Q β (h + β * a * u + r) ≤ Q β (h + β * a * u) + + β * a / 2 * ((u + r / (β * a)) ^ 2 - u ^ 2) := by linarith + _ = Q β (h + β * a * u) + u * r + r ^ 2 / (2 * β * a) := by + field_simp + ring + +theorem active_support_density {Q : Pressure} {a β h u e d : ℝ} + (ha : 0 < a) (hβ : 0 < β) (hu : ActiveShift Q a β h u) + (hs : pressureSupport Q β (h + β * a * u) e d) : d = u := by + have hba : 0 < β * a := mul_pos hβ ha + have hqa : ∀ r : ℝ, d * r ≤ u * r + r ^ 2 / (2 * β * a) := by + intro r + have hl := hs β (h + β * a * u + r) hβ + have hr := active_parabola ha hβ hu r + simp only [sub_self, mul_zero, add_zero, add_sub_cancel_left] at hl + linarith + have hh := hqa ((β * a) * (d - u)) + have hden : 0 < 2 * β * a := by positivity + have hh' : (d * ((β * a) * (d - u)) - u * ((β * a) * (d - u))) * + (2 * β * a) ≤ ((β * a) * (d - u)) ^ 2 := + (le_div_iff₀ hden).mp (by linarith [hh]) + have hz : (β * a) ^ 2 * (d - u) ^ 2 ≤ 0 := by nlinarith [hh'] + have hd : (d - u) ^ 2 ≤ 0 := le_of_mul_le_mul_left (by simpa only [mul_zero] using hz) (sq_pos_of_pos hba) + nlinarith [sq_nonneg (d - u)] + +theorem support_attractionBranch {Q : Pressure} {a β h u e d : ℝ} + (hs : pressureSupport Q β (h + β * a * u) e d) : + pressureSupport (attractionBranch Q a u) β h + (e + a * u * d - a * u ^ 2 / 2) d := by + intro β' h' hβ' + have hc := hs β' (h' + β' * a * u) hβ' + dsimp [attractionBranch] + nlinarith [hc] + +theorem idealAttraction_eq_of_active {Q : Pressure} {a β h u : ℝ} + (hu : ActiveShift Q a β h u) : + idealAttraction Q a β h = attractionBranch Q a u β h := by + apply IsGreatest.csSup_eq + exact ⟨⟨u, rfl⟩, by rintro _ ⟨v, rfl⟩; exact hu v⟩ + +theorem active_generator_support {Q : Pressure} {a β h u e : ℝ} + (hfinite : ∀ β' h', 0 < β' → + BddAbove (Set.range fun v => attractionBranch Q a v β' h')) + (hu : ActiveShift Q a β h u) + (hs : pressureSupport Q β (h + β * a * u) e u) : + pressureSupport (idealAttraction Q a) β h (e + a * u ^ 2 / 2) u := by + have hb : pressureSupport (attractionBranch Q a u) β h (e + a * u ^ 2 / 2) u := by + convert support_attractionBranch hs using 1 + ring + intro β' h' hβ' + rw [idealAttraction_eq_of_active hu] + exact (hb β' h' hβ').trans (le_csSup (hfinite β' h' hβ') ⟨u, rfl⟩) + +theorem support_of_attractionBranch {Q : Pressure} {a β h u e d : ℝ} + (hs : pressureSupport (attractionBranch Q a u) β h e d) : + pressureSupport Q β (h + β * a * u) (e - a * u * d + a * u ^ 2 / 2) d := by + intro β' h' hβ' + have hc := hs β' (h' - β' * a * u) hβ' + dsimp [attractionBranch] at hc + rw [sub_add_cancel] at hc + nlinarith [hc] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/IdealLimit.lean b/lean/OAI/Probability/RadialTransition/IdealLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..9510ca70e67d3de4aa848990ba6a64a4eedf5580 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/IdealLimit.lean @@ -0,0 +1,127 @@ +import OAI.Probability.RadialTransition.IdealUniform + +namespace OAI + +universe uIndex + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +def finiteMax {ι : Type uIndex} [Fintype ι] (f : ι → ℝ) : ℝ := sSup (range f) +lemma finiteMax_le {ι : Type uIndex} [Fintype ι] [Nonempty ι] (f : ι → ℝ) {c : ℝ} + (hc : ∀ i, f i ≤ c) : finiteMax f ≤ c := csSup_le (range_nonempty f) (by rintro _ ⟨i,rfl⟩; exact hc i) +lemma le_finiteMax {ι : Type uIndex} [Fintype ι] (f : ι → ℝ) (i : ι) : f i ≤ finiteMax f := + le_csSup (Finite.bddAbove_range f) (mem_range_self i) +lemma finiteMax_attained {ι : Type uIndex} [Fintype ι] [Nonempty ι] (f : ι → ℝ) : ∃ i, finiteMax f = f i := by + obtain ⟨i, hi⟩ := Finite.exists_max f + exact ⟨i, le_antisymm (finiteMax_le f hi) (le_finiteMax f i)⟩ + +def phaseMass : ℝ := 3/(2*packingDensity) +def phaseDensity : Fin 3 → ℝ := ![0,packingDensity,4*packingDensity] +def phaseOffset : Fin 3 → ℝ := ![0,0,-9*packingDensity] +def limitingPlane (i : Fin 3) (β h : ℝ) : ℝ := + phaseDensity i*h+phaseOffset i+β*phaseMass/2*(phaseDensity i)^2 +def threePlane (β h : ℝ) : ℝ := finiteMax (fun i => limitingPlane i β h) + +lemma phaseMass_pos : 0 < phaseMass := div_pos (by norm_num) (mul_pos (by norm_num) packingDensity_pos) + +lemma phaseDensity_bounds (i : Fin 3) : 0 ≤ phaseDensity i ∧ phaseDensity i ≤ 4*packingDensity := by + have hp := packingDensity_pos + fin_cases i + · change 0 ≤ (0:ℝ) ∧ 0 ≤ 4*packingDensity + constructor <;> positivity + · change 0 ≤ packingDensity ∧ packingDensity ≤ 4*packingDensity + constructor <;> linarith + · change 0 ≤ 4*packingDensity ∧ 4*packingDensity ≤ 4*packingDensity + constructor + · positivity + · exact le_rfl + +lemma bareLimit_finiteMax (h : ℝ) : bareLimit h = finiteMax (fun i => phaseDensity i*h+phaseOffset i) := by + apply le_antisymm + · apply max_le + · simpa [phaseDensity, phaseOffset] using le_finiteMax (fun i => phaseDensity i*h+phaseOffset i) 0 + apply max_le + · simpa [phaseDensity, phaseOffset] using le_finiteMax (fun i => phaseDensity i*h+phaseOffset i) 1 + · calc + packingDensity*(4*h-9) = phaseDensity 2*h+phaseOffset 2 := by dsimp [phaseDensity, phaseOffset]; ring + _ ≤ _ := le_finiteMax (fun i => phaseDensity i*h+phaseOffset i) 2 + · apply finiteMax_le + intro i + fin_cases i + · simp [phaseDensity, phaseOffset, bareLimit] + · simp [phaseDensity, phaseOffset, bareLimit] + · have hh := (le_max_right (packingDensity*h) (packingDensity*(4*h-9))).trans (le_max_right 0 (max (packingDensity*h) (packingDensity*(4*h-9)))) + dsimp [phaseDensity, phaseOffset] + unfold bareLimit + nlinarith + +lemma limiting_branch_attained (β h u : ℝ) : ∃ i : Fin 3, + attractionBranch (fun _ h => bareLimit h) phaseMass u β h = + limitingPlane i β h-β*phaseMass/2*(u-phaseDensity i)^2 := by + obtain ⟨i, hi⟩ := finiteMax_attained (fun i => phaseDensity i*(h+β*phaseMass*u)+phaseOffset i) + refine ⟨i, ?_⟩ + dsimp only [attractionBranch] + rw [bareLimit_finiteMax, hi] + unfold limitingPlane + ring + +lemma limiting_branch_ge (β h u : ℝ) (i : Fin 3) : + limitingPlane i β h-β*phaseMass/2*(u-phaseDensity i)^2 ≤ + attractionBranch (fun _ h => bareLimit h) phaseMass u β h := by + have hh := le_finiteMax (fun i => phaseDensity i*(h+β*phaseMass*u)+phaseOffset i) i + dsimp only [attractionBranch] + rw [bareLimit_finiteMax] + unfold limitingPlane + nlinarith + +lemma limiting_branch_le {β : ℝ} (hβ : 0 ≤ β) (h u : ℝ) : + attractionBranch (fun _ h => bareLimit h) phaseMass u β h ≤ threePlane β h := by + obtain ⟨i, hi⟩ := limiting_branch_attained β h u + rw [hi] + have hh := le_finiteMax (fun i => limitingPlane i β h) i + change limitingPlane i β h-β*phaseMass/2*(u-phaseDensity i)^2 ≤ finiteMax _ + have hA := phaseMass_pos + nlinarith [mul_nonneg (show 0 ≤ β*phaseMass/2 by positivity) (sq_nonneg (u-phaseDensity i))] + +lemma ideal_approx_threePlane {Q : Pressure} {β h U ε u : ℝ} (hβ : 0 ≤ β) + (hU : 4*packingDensity ≤ U) (hu : ActiveShift Q phaseMass β h u) (hub : u ∈ Icc (0:ℝ) U) + (he : ∀ v ∈ Icc (0:ℝ) U, |Q β (h+β*phaseMass*v)-bareLimit (h+β*phaseMass*v)| ≤ ε) : + |idealAttraction Q phaseMass β h-threePlane β h| ≤ ε := by + rw [idealAttraction_eq_of_active hu, abs_le] + constructor + · obtain ⟨i, hi⟩ := finiteMax_attained (fun i => limitingPlane i β h) + have hib : phaseDensity i ∈ Icc (0:ℝ) U := ⟨(phaseDensity_bounds i).1, (phaseDensity_bounds i).2.trans hU⟩ + have happ := (abs_le.mp (he _ hib)).1 + have hg := limiting_branch_ge β h (phaseDensity i) i + simp only [sub_self, zero_pow (by decide : 2 ≠ 0), mul_zero, sub_zero] at hg + have hm := hu (phaseDensity i) + change threePlane β h = limitingPlane i β h at hi + rw [hi] + dsimp only [attractionBranch] at hg hm ⊢ + linarith + · have happ := (abs_le.mp (he u hub)).2 + have hg := limiting_branch_le hβ h u + dsimp only [attractionBranch] at hg ⊢ + linarith + +lemma active_near_phase {Q : Pressure} {β h U ε u : ℝ} (hβ : 0 ≤ β) + (hU : 4*packingDensity ≤ U) (hu : ActiveShift Q phaseMass β h u) (hub : u ∈ Icc (0:ℝ) U) + (he : ∀ v ∈ Icc (0:ℝ) U, |Q β (h+β*phaseMass*v)-bareLimit (h+β*phaseMass*v)| ≤ ε) : + ∃ i : Fin 3, β*phaseMass/2*(u-phaseDensity i)^2 ≤ 2*ε := by + have hp := (abs_le.mp (ideal_approx_threePlane hβ hU hu hub he)).1 + rw [idealAttraction_eq_of_active hu] at hp + have ha := (abs_le.mp (he u hub)).2 + obtain ⟨i, hi⟩ := limiting_branch_attained β h u + refine ⟨i, ?_⟩ + have hh := le_finiteMax (fun i => limitingPlane i β h) i + change limitingPlane i β h ≤ threePlane β h at hh + dsimp only [attractionBranch] at hi hp + linarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/IdealSupports.lean b/lean/OAI/Probability/RadialTransition/IdealSupports.lean new file mode 100644 index 0000000000000000000000000000000000000000..65954e9a076fc342d46eb9c3c2f45fa3ce6e4430 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/IdealSupports.lean @@ -0,0 +1,110 @@ +import OAI.Probability.RadialTransition.IdealLimit + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma branch_joint_continuous {Q : Pressure} + (hQ : ContinuousOn (onParameters Q) positiveParameters) (a : ℝ) : + ContinuousOn (fun z : ℝ × Parameter => onParameters (attractionBranch Q a z.1) z.2) + (univ ×ˢ positiveParameters) := by + have hc0 : Continuous (fun z : ℝ × Parameter => z.2 0) := + (PiLp.continuous_apply 2 (fun _ : Fin 2 => ℝ) 0).comp continuous_snd + have hc1 : Continuous (fun z : ℝ × Parameter => z.2 1) := + (PiLp.continuous_apply 2 (fun _ : Fin 2 => ℝ) 1).comp continuous_snd + have hmap : Continuous (fun z : ℝ × Parameter => parameter (z.2 0) (z.2 1+z.2 0*a*z.1)) := + continuous_parameter _ _ hc0 (hc1.add ((hc0.mul_const a).mul continuous_fst)) + have hcomp := hQ.comp (s := univ ×ˢ positiveParameters) hmap.continuousOn (by + intro z hz + change 0 < z.2 0 + exact hz.2) + exact hcomp.sub (((hc0.mul_const a).div_const 2).mul (continuous_fst.pow 2)).continuousOn + +lemma ideal_supportSet_generated {Q : Pressure} {a U r : ℝ} {x : Parameter} + (hQ : ConvexOn ℝ positiveParameters (onParameters Q)) (ha : 0 < a) + (hactive : ∀ β h, 0 < β → ∃ u, ActiveShift Q a β h u) + (hr : 0 < r) (hxr : 2*r < x 0) + (hlocal : ∀ y ∈ Metric.closedBall x r, ∃ u ∈ Icc (0:ℝ) U, ActiveShift Q a (y 0) (y 1) u) : + supportSet (onParameters (idealAttraction Q a)) positiveParameters x = + closure (convexHull ℝ {v : Parameter | ∃ u ∈ Icc (0:ℝ) U, + ActiveShift Q a (x 0) (x 1) u ∧ ∃ e : ℝ, + pressureSupport Q (x 0) (x 1+x 0*a*u) e u ∧ v=parameter (e+a*u^2/2) u}) := by + have hball : Metric.closedBall x (2*r) ⊆ positiveParameters := by + intro y hy + have hcoord := parameter_coord_abs_le (y-x) 0 + have hn := Metric.mem_closedBall.mp hy + rw [dist_eq_norm] at hn + simp only [PiLp.sub_apply] at hcoord + have hh := (abs_le.mp (hcoord.trans hn)).1 + change 0 < y 0 + linarith + have hx : 0 < x 0 := by linarith + have hP := convexOn_idealAttraction hQ hactive + have hformula := supportSet_envelope_closedHull isOpen_positiveParameters isCompact_Icc hr hball + (fun u _ => convexOn_attractionBranch hQ a u) + ((branch_joint_continuous (hQ.continuousOn isOpen_positiveParameters) a).mono + (prod_mono (subset_univ _) Subset.rfl)) + (hP.continuousOn isOpen_positiveParameters) + (fun u _ y hy => by + obtain ⟨v, hv⟩ := hactive (y 0) (y 1) hy + change attractionBranch Q a u (y 0) (y 1) ≤ idealAttraction Q a (y 0) (y 1) + rw [idealAttraction_eq_of_active hv] + exact hv u) + (fun y hy => by + obtain ⟨u, hub, hu⟩ := hlocal y hy + exact ⟨u, hub, (idealAttraction_eq_of_active hu).symm⟩) + rw [hformula] + congr 2 + ext v + constructor + · rintro ⟨u, hub, heq, hv⟩ + have hu : ActiveShift Q a (x 0) (x 1) u := by + intro w + change attractionBranch Q a u (x 0) (x 1) = idealAttraction Q a (x 0) (x 1) at heq + rw [heq] + obtain ⟨z, hz⟩ := hactive (x 0) (x 1) hx + exact le_csSup (ideal_bddAbove_of_active hz) (mem_range_self w) + have hs := support_of_attractionBranch (pressureSupport_iff.mpr hv) + have hd := active_support_density ha hx hu hs + refine ⟨u, hub, hu, v 0-a*u*(v 1)+a*u^2/2, ?_, ?_⟩ + · simpa only [hd] using hs + · ext i + fin_cases i + · change v 0 = v 0-a*u*(v 1)+a*u^2/2+a*u^2/2 + rw [hd] + ring + · change v 1 = u + exact hd + · rintro ⟨u, hub, hu, e, hs, rfl⟩ + refine ⟨u, hub, (idealAttraction_eq_of_active hu).symm, ?_⟩ + have hs' : pressureSupport (attractionBranch Q a u) (x 0) (x 1) (e+a*u^2/2) u := by + convert support_attractionBranch hs using 1 + ring + exact pressureSupport_iff.mp hs' + +lemma ideal_increment_bound {Q : Pressure} {a β h U u : ℝ} + (hQ : ConvexOn ℝ positiveParameters (onParameters Q)) (ha : 0 < a) (hβ : 0 < β) + (hu : ActiveShift Q a β h u) (hub : u ∈ Icc (0:ℝ) U) : + 0 ≤ idealAttraction Q a β h-Q β h ∧ idealAttraction Q a β h-Q β h ≤ β*a/2*U^2 := by + obtain ⟨v, hv⟩ := supportSet_nonempty isOpen_positiveParameters hQ + (show parameter β (h+β*a*u) ∈ positiveParameters from hβ) + have hs := pressureSupport_iff.mpr hv + simp only [parameter_zero, parameter_one] at hs + have hd := active_support_density ha hβ hu hs + have hh := hs β h hβ + rw [hd] at hh + have hz := hu 0 + simp only [attractionBranch, mul_zero, add_zero, zero_pow (by decide : 2 ≠ 0), sub_zero] at hz + rw [idealAttraction_eq_of_active hu] + dsimp only [attractionBranch] at hh hz ⊢ + have hsq : u^2 ≤ U^2 := sq_le_sq₀ hub.1 (hub.1.trans hub.2) |>.mpr hub.2 + have hm := mul_le_mul_of_nonneg_left hsq (show 0 ≤ β*a/2 by positivity) + constructor <;> nlinarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/IdealUniform.lean b/lean/OAI/Probability/RadialTransition/IdealUniform.lean new file mode 100644 index 0000000000000000000000000000000000000000..0bba8142f59507b7762522204dcbe615a116826f --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/IdealUniform.lean @@ -0,0 +1,72 @@ +import OAI.Probability.RadialTransition.ParameterPressure + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma familyPotential_zero (t : ℝ) (S : ℕ → ℝ) : + familyPotential t (fun _ => 0) S = corePotential t := by + ext r + simp [familyPotential, attractionProfile, corePotential] + +lemma uniform_ideal_cutoff {βlo βhi H A : ℝ} (hlo : 0 < βlo) (hhi : βlo ≤ βhi) + (hH : 0 ≤ H) (_hA : 0 ≤ A) : + ∃ U : ℝ, 1 ≤ U ∧ ∀ t : ℝ, 1 ≤ t → 6912*A ≤ t → + ∀ β ∈ Icc βlo βhi, ∀ h ∈ Icc (-H) H, ∀ a ∈ Icc (0:ℝ) A, + ∃ κ : ℝ, 0 < κ ∧ κ ≤ β*t/3456-β*a/2 ∧ h+β*t/2+1/t+1 ≤ κ*U := by + let K := H+βhi+2 + have hhi0 : 0 < βhi := hlo.trans_le hhi + have hK : 0 < K := by dsimp [K]; positivity + let U := 1+6912*K/βlo + have hU : 1 ≤ U := by + have hh : 0 ≤ 6912*K/βlo := by positivity + dsimp [U]; linarith + refine ⟨U, hU, ?_⟩ + intro t ht htA β hβ h hh a ha + have ht0 : 0 < t := by linarith + let κ := βlo*t/6912 + have hκ : 0 < κ := by dsimp [κ]; positivity + refine ⟨κ, hκ, ?_, ?_⟩ + · have hta : 6912*a ≤ t := (mul_le_mul_of_nonneg_left ha.2 (by norm_num)).trans htA + have h1 := mul_le_mul_of_nonneg_left hta (hlo.trans_le hβ.1).le + have h2 := mul_le_mul_of_nonneg_right hβ.1 ht0.le + dsimp [κ] + nlinarith + · have hinv : 1/t ≤ 1 := (div_le_one ht0).mpr ht + have h1 := mul_le_mul_of_nonneg_right hβ.2 ht0.le + have h2 := mul_le_mul_of_nonneg_left ht hH + have h3 : 2 ≤ 2*t := by linarith + have he : κ*U = κ+t*K := by dsimp [κ, U]; field_simp + rw [he] + dsimp [K] + nlinarith [hh.2, mul_nonneg hhi0.le ht0.le] + +lemma family_ideal_global_active {t a : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (ha : 0 ≤ a) (htA : 6912*a ≤ t) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, b n) ≤ (t^2/8)/8) : + ∀ β h, 0 < β → ∃ u, ActiveShift (grandPressure (familyPotential t b S) t) a β h u := by + intro β h hβ + obtain ⟨U, hU, hcut⟩ := uniform_ideal_cutoff hβ (le_refl β) (abs_nonneg h) ha + obtain ⟨κ, hκ, hc, hh⟩ := hcut t ht htA β ⟨le_rfl, le_rfl⟩ h (abs_le.mp (le_refl |h|)) a ⟨ha, le_rfl⟩ + obtain ⟨u, _, hu⟩ := family_ideal_exists_active ht hβ ha hb hS hs hrow hκ hc hU hh + exact ⟨u, hu⟩ + +lemma family_ideal_convex {t a : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (ha : 0 ≤ a) (htA : 6912*a ≤ t) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, b n) ≤ (t^2/8)/8) : + ConvexOn ℝ positiveParameters (onParameters (idealAttraction (grandPressure (familyPotential t b S) t) a)) := by + have ht0 : 0 < t := by linarith + apply convexOn_idealAttraction _ (family_ideal_global_active ht ha htA hb hS hs hrow) + exact convexOn_grandPressure (continuous_familyPotential hb hS hs t) (bounded_familyPotential hb hS hs t) + (stable_family_of_master ht0.le hb hS hs hs (fun _ => le_rfl) hrow) ht0 + (fun r hr => familyPotential_nonpos_outer hb hS ht hr) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/InfiniteBall.lean b/lean/OAI/Probability/RadialTransition/InfiniteBall.lean new file mode 100644 index 0000000000000000000000000000000000000000..6b7612e29bf140beca2e942fd28f354f6896eb3b --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/InfiniteBall.lean @@ -0,0 +1,75 @@ +import OAI.Probability.RadialTransition.InitialSeparation + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal +open Set Filter +namespace RadialTransition + +lemma exists_family_pressure_ball : + ∃ t b : ℝ, 1 ≤ t ∧ 2 ≤ b ∧ + 2197*t*bumpIntegral⁻¹*iterationBudget ≤ (t^2/8)/8 ∧ + ∃ x ∈ phaseWindow (1/8), Metric.closedBall targetSlope pressureRadius ⊆ + supportSet (onParameters (grandPressure (familyPotential t (iterationMass b) (scaleRange b)) t)) positiveParameters x := by + have hinitE := initial_separation phaseRadius_pos (show 0.and + (eventually_ge_atTop (6912*iterationBudget)) |>.and + (eventually_ge_atTop (140608*bumpIntegral⁻¹*iterationBudget))).exists + have ht0 : 0 < t := by linarith + have hrow : 2197*t*bumpIntegral⁻¹*iterationBudget ≤ (t^2/8)/8 := by + have hh := mul_le_mul_of_nonneg_left htrow ht0.le + nlinarith only [hh] + obtain ⟨U,C,C₀,hU,hC,hC₀,hcontrol⟩ := family_controls ht iterationBudget_pos.le htA hrow + obtain ⟨D,K,hD,hK,hkac⟩ := family_kac_uniform ht (by norm_num : (0:ℝ)<1/2) + (by norm_num : (1/2:ℝ)≤3/2) (by norm_num : (0:ℝ)≤2) iterationBudget_pos.le htA + obtain ⟨b,k,l,hb,hbK,hk,hl,hdom,hrad,hband,hpress⟩ := + scale_budgets (K := K) (by linarith : 0≤U) (by linarith : 0≤C) hC₀ (show 0<2*D by positivity) + have had := iteration_admissible hb t + have hpre (n : ℕ) := reversePrefix_admissible (t := t) had.1 had.2.1 had.2.2.1 had.2.2.2 n + have hmass (n : ℕ) : iterationMass b n ∈ Ioc (0:ℝ) iterationBudget := + ⟨iterationMass_pos (by linarith) n,iterationMass_le hb n⟩ + have hctrl (n : ℕ) := hcontrol _ _ (hpre n) _ (hmass n) + have hP (n : ℕ) : ConvexOn ℝ positiveParameters (onParameters (iterationP t b n)) := + convexOn_idealAttraction (admissible_pressure_convex ht (hpre n) hrow) (hctrl n).1 + have hQ (n : ℕ) : ConvexOn ℝ positiveParameters (onParameters (iterationQ t b n)) := + admissible_pressure_convex ht (hpre (n+1)) hrow + have happ := iteration_kac ht hD hK hb hbK hrow hkac + have hlip (n : ℕ) (x : Parameter) (hx : x ∈ phaseWindow (1/4)) + (y : Parameter) (hy : y ∈ phaseWindow (1/4)) : + |onParameters (iterationP t b n) x-onParameters (iterationP t b n) y| ≤ C*dist x y := + (hctrl n).2.2.1 x hx y hy + have hinc (n : ℕ) (x : Parameter) (hx : x ∈ phaseWindow (1/4)) : + |onParameters (iterationP t b (n+1)) x-onParameters (iterationQ t b n) x| ≤ C₀*scaleTail b n := by + have hh := (hctrl (n+1)).2.2.2 x hx + change 0 ≤ onParameters (iterationP t b (n+1)) x-onParameters (iterationQ t b n) x ∧ + onParameters (iterationP t b (n+1)) x-onParameters (iterationQ t b n) x ≤ C₀*scaleTail b n at hh + rw [abs_of_nonneg hh.1] + exact hh.2 + have hball : ∀ n, ∃ x ∈ Metric.ball phaseCenter (1/8), Metric.closedBall targetSlope pressureRadius ⊆ + supportSet (onParameters (iterationP t b n)) positiveParameters x := by + apply multiscale_pressure_balls (fun n => scaleTail_pos (by linarith) n) + (fun n => show 0≤2*D*(scaleTail b n)^2 by positivity) (by linarith : 0≤U) + (by linarith : 0≤C) hk hl hP hQ (iterationP_succ t b) happ hlip hinc + (fun n => (hctrl (n+1)).1) (fun n => (hctrl (n+1)).2.1) ?_ hdom hrad hband hpress + intro x hx + rw [iterationP_zero] + exact ⟨(hinit x hx).2,(hinit x hx).1⟩ + have hlim (x : Parameter) (hx : x ∈ phaseWindow (1/4)) : + Tendsto (fun n => onParameters (iterationP t b n) x) atTop + (nhds (onParameters (grandPressure (familyPotential t (iterationMass b) (scaleRange b)) t) x)) := by + have hβ : 0 < x 0 := phaseWindow_positive (by norm_num) hx + have hlimQ := (grandPressure_reversePrefix_tendsto (h := x 1) ht hβ had hrow).comp (tendsto_add_atTop_nat 1) + have hdiff : Tendsto (fun n => onParameters (iterationP t b n) x-onParameters (iterationQ t b n) x) atTop (nhds 0) := by + apply squeeze_zero_norm (a := fun n => 2*D*(scaleTail b n)^2) + · intro n + simpa only [Real.norm_eq_abs,abs_sub_comm] using happ n x hx + · simpa using ((summable_scaleTail hb).tendsto_atTop_zero.pow 2).const_mul (2*D) + have hsum := hdiff.add hlimQ + simpa only [Function.comp_apply,onParameters,iterationQ,sub_add_cancel,zero_add] using hsum + exact ⟨t,b,ht,hb,hrow,pressure_ball_limit (admissible_pressure_convex ht had hrow) hball hlip hlim⟩ + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/InitialSeparation.lean b/lean/OAI/Probability/RadialTransition/InitialSeparation.lean new file mode 100644 index 0000000000000000000000000000000000000000..fb457de44271156f2806b78dfd8234ac18073510 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/InitialSeparation.lean @@ -0,0 +1,117 @@ +import OAI.Probability.RadialTransition.PhysicalIteration + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma core_ideal_convex_active {t : ℝ} (ht : 1 ≤ t) (htA : 6912*phaseMass ≤ t) : + ConvexOn ℝ positiveParameters (onParameters (grandPressure (corePotential t) t)) ∧ + (∀ β h, 0 < β → ∃ u, ActiveShift (grandPressure (corePotential t) t) phaseMass β h u) := by + have hb : ∀ n : ℕ, 0 ≤ (0:ℝ) := fun _ => le_rfl + have hS : ∀ n : ℕ, 1 ≤ (1:ℝ) := fun _ => le_rfl + have hs : Summable (fun _ : ℕ => (0:ℝ)) := summable_zero + have hrow : 2197*t*bumpIntegral⁻¹*(∑' _ : ℕ, (0:ℝ)) ≤ (t^2/8)/8 := by simp; positivity + have hact := family_ideal_global_active ht phaseMass_pos.le htA hb hS hs hrow + rw [familyPotential_zero] at hact + refine ⟨?_, hact⟩ + have ht0 : 0 < t := by linarith + have hst := stable_family_of_master ht0.le hb hS hs hs (fun _ => le_rfl) hrow + rw [familyPotential_zero] at hst + exact convexOn_grandPressure (continuous_corePotential t) (bounded_corePotential t) hst ht0 + (fun r hr => by simpa only [familyPotential_zero] using familyPotential_nonpos_outer hb hS ht (r := r) hr) + +lemma initial_separation {τ ε₀ : ℝ} (hτ : 0 < τ) (hε₀ : 0 < ε₀) : + ∀ᶠ t : ℝ in atTop, ∀ x ∈ phaseWindow (1/4), + |onParameters (idealAttraction (grandPressure (corePotential t) t) phaseMass) x- + onParameters threePlane x| ≤ ε₀ ∧ + HasPhaseGroups (idealAttraction (grandPressure (corePotential t) t) phaseMass) x (τ/2) := by + obtain ⟨U₀, hU₀, hcut⟩ := uniform_ideal_cutoff (by norm_num : (0:ℝ)<1/2) + (by norm_num : (1/2:ℝ)≤3/2) (by norm_num : (0:ℝ)≤2) phaseMass_pos.le + let U := max U₀ (4*packingDensity) + have hUU : U₀ ≤ U := le_max_left _ _ + have hU : 1 ≤ U := hU₀.trans hUU + have hUp : 4*packingDensity ≤ U := le_max_right _ _ + let K := 1+phaseMass/2*(U+4*packingDensity) + have hK : 0 < K := by have := phaseMass_pos; have := packingDensity_pos; dsimp [K]; positivity + let η := τ/(4*K) + have hη : 0 < η := div_pos hτ (by positivity) + let ε := min ε₀ (min (τ/32) (phaseMass*η^2/16)) + have hε : 0 < ε := lt_min hε₀ (lt_min (by positivity) (by have := phaseMass_pos; positivity)) + have he₀ : ε ≤ ε₀ := min_le_left _ _ + have heτ : ε ≤ τ/32 := (min_le_right _ _).trans (min_le_left _ _) + have heη : ε ≤ phaseMass*η^2/16 := (min_le_right _ _).trans (min_le_right _ _) + let H := 2+2*phaseMass*U + have hH : 0 ≤ H := by have := phaseMass_pos; dsimp [H]; positivity + filter_upwards [corePressure_uniform_bare (by norm_num : (0:ℝ)<1/4) hH hε, + eventually_ge_atTop (1:ℝ), eventually_ge_atTop (6912*phaseMass)] with t happ ht htA + let Q := grandPressure (corePotential t) t + obtain ⟨hQ, hact⟩ := core_ideal_convex_active ht htA + have hb : ∀ n : ℕ, 0 ≤ (0:ℝ) := fun _ => le_rfl + have hS : ∀ n : ℕ, 1 ≤ (1:ℝ) := fun _ => le_rfl + have hs : Summable (fun _ : ℕ => (0:ℝ)) := summable_zero + have hrow : 2197*t*bumpIntegral⁻¹*(∑' _ : ℕ, (0:ℝ)) ≤ (t^2/8)/8 := by simp; positivity + have hactive (β h : ℝ) (hβ : β ∈ Icc (1/2:ℝ) (3/2)) (hh : |h| ≤ 2) : + ∃ u ∈ Icc (0:ℝ) U, ActiveShift Q phaseMass β h u := by + obtain ⟨κ, hκ, hc, hbound⟩ := hcut t ht htA β hβ h (abs_le.mp hh) phaseMass ⟨phaseMass_pos.le,le_rfl⟩ + have hbound' := hbound.trans (mul_le_mul_of_nonneg_left hUU hκ.le) + obtain ⟨u, hu, ha⟩ := family_ideal_exists_active ht (by linarith [hβ.1]) phaseMass_pos.le + hb hS hs hrow hκ hc hU hbound' + rw [familyPotential_zero] at ha + exact ⟨u, hu, ha⟩ + have hshift (β h u : ℝ) (hβ : β ∈ Icc (1/2:ℝ) (3/2)) (hh : |h| ≤ 2) + (hu : u ∈ Icc (0:ℝ) U) : |h+β*phaseMass*u| ≤ H := by + have hb0 : 0 ≤ β := by linarith [hβ.1] + have ha0 := phaseMass_pos.le + have hu0 := hu.1 + have hmul : β*phaseMass*u ≤ 2*phaseMass*U := + mul_le_mul (mul_le_mul_of_nonneg_right (show β ≤ 2 by linarith [hβ.2]) phaseMass_pos.le) + hu.2 hu.1 (by have := phaseMass_pos; positivity) + calc + _ ≤ |h|+|β*phaseMass*u| := abs_add_le _ _ + _ ≤ H := by rw [abs_of_nonneg (by positivity : 0 ≤ β*phaseMass*u)]; dsimp [H]; linarith + intro x hx + obtain ⟨hβ, hh⟩ := phaseWindow_quarter_bounds hx + have hβ' : x 0 ∈ Icc (1/2:ℝ) (3/2) := ⟨by linarith [hβ.1], by linarith [hβ.2]⟩ + have hβ0 : 0 < x 0 := by linarith [hβ.1] + have happx : ∀ u ∈ Icc (0:ℝ) U, |Q (x 0) (x 1+x 0*phaseMass*u)-bareLimit (x 1+x 0*phaseMass*u)| ≤ ε := by + intro u hu + exact happ _ _ (by linarith [hβ.1]) (hshift _ _ _ hβ' hh hu) + constructor + · obtain ⟨u, hub, hu⟩ := hactive _ _ hβ' hh + exact (ideal_approx_threePlane hβ0.le hUp hu hub happx).trans he₀ + · have hlocal : ∀ y ∈ Metric.closedBall x (1/16), ∃ u ∈ Icc (0:ℝ) U, ActiveShift Q phaseMass (y 0) (y 1) u := by + intro y hy + have hy' : y ∈ phaseWindow (1/2) := phaseWindow_mono (by norm_num : (1/4:ℝ)+1/16≤1/2) (phaseWindow_near hx hy) + obtain ⟨hyβ, hyh⟩ := phaseWindow_half_bounds hy' + exact hactive _ _ hyβ hyh + have hgen := ideal_supportSet_generated hQ phaseMass_pos hact (by norm_num : (0:ℝ)<1/16) + (by linarith [hβ.1] : 2*(1/16:ℝ) norm_num + exact happ _ _ (by linarith [hβ.1]) (hshift _ _ _ hβ' hh hub) + have hsmall : 2*ε ≤ x 0*phaseMass/2*η^2 := by + have hm := mul_le_mul_of_nonneg_right hβ.1 (mul_nonneg phaseMass_pos.le (sq_nonneg η)) + nlinarith + obtain ⟨i, hi⟩ := phase_generator_distance hβ0 (by norm_num : (0:ℝ)<1/4) + (by linarith [hβ.1]) hη.le hUp hu hub happx happe hsmall hes + refine ⟨i, Metric.mem_closedBall.mpr ?_⟩ + rw [dist_eq_norm] + apply hi.trans + have heq : K*η=τ/4 := by dsimp [η]; field_simp + change 2*ε/(1/4)+K*η ≤ τ/2 + rw [heq] + linarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/InitialSlopes.lean b/lean/OAI/Probability/RadialTransition/InitialSlopes.lean new file mode 100644 index 0000000000000000000000000000000000000000..f0686c0d925f3db36c7c859eea4db9f9cf47d0f6 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/InitialSlopes.lean @@ -0,0 +1,86 @@ +import OAI.Probability.RadialTransition.IdealSupports + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +def phaseSlope (i : Fin 3) : Parameter := parameter (phaseMass/2*(phaseDensity i)^2) (phaseDensity i) +def phaseCenter : Parameter := parameter 1 (-3/4) +def targetSlope : Parameter := parameter (17*packingDensity/4) (5*packingDensity/3) +def phaseWindow (r : ℝ) : Set Parameter := Metric.closedBall phaseCenter r + +def HasPhaseGroups (Q : Pressure) (x : Parameter) (r : ℝ) : Prop := + supportSet (onParameters Q) positiveParameters x = closure (convexHull ℝ + {v : Parameter | v ∈ supportSet (onParameters Q) positiveParameters x ∧ + ∃ i : Fin 3, v ∈ Metric.closedBall (phaseSlope i) r}) + +lemma support_energy_small {Q : Pressure} {β h e d σ ε : ℝ} + (hσ : 0 < σ) (hβ : σ < β) (hs : pressureSupport Q β h e d) + (happ : ∀ s ∈ ({-σ,0,σ} : Set ℝ), |Q (β+s) h-bareLimit h| ≤ ε) : + |e| ≤ 2*ε/σ := by + have hm := hs (β-σ) h (by linarith) + have hp := hs (β+σ) h (by linarith) + have ha0 := abs_le.mp (happ 0 (by simp)) + have ham := abs_le.mp (happ (-σ) (by simp)) + have hap := abs_le.mp (happ σ (by simp)) + simp only [sub_self, mul_zero, add_zero, sub_eq_add_neg] at hm hp ha0 ham hap + have heq := div_mul_cancel₀ (2*ε) hσ.ne' + rw [abs_le] + constructor <;> nlinarith + +lemma phase_generator_distance {Q : Pressure} {β h U ε η σ u e : ℝ} + (hβ : 0 < β) (hσ : 0 < σ) (hβσ : σ < β) (hη : 0 ≤ η) + (hU : 4*packingDensity ≤ U) (hu : ActiveShift Q phaseMass β h u) (hub : u ∈ Icc (0:ℝ) U) + (happ : ∀ v ∈ Icc (0:ℝ) U, |Q β (h+β*phaseMass*v)-bareLimit (h+β*phaseMass*v)| ≤ ε) + (happe : ∀ s ∈ ({-σ,0,σ} : Set ℝ), |Q (β+s) (h+β*phaseMass*u)-bareLimit (h+β*phaseMass*u)| ≤ ε) + (hsmall : 2*ε ≤ β*phaseMass/2*η^2) + (hs : pressureSupport Q β (h+β*phaseMass*u) e u) : + ∃ i : Fin 3, ‖parameter (e+phaseMass*u^2/2) u-phaseSlope i‖ ≤ + 2*ε/σ+(1+phaseMass/2*(U+4*packingDensity))*η := by + have he := support_energy_small hσ hβσ hs happe + obtain ⟨i, hi⟩ := active_near_phase hβ.le hU hu hub happ + have hc : 0 < β*phaseMass/2 := by have := phaseMass_pos; positivity + have hdist : |u-phaseDensity i| ≤ η := by + have hsq : (u-phaseDensity i)^2 ≤ η^2 := by nlinarith + exact (sq_le_sq₀ (abs_nonneg _) hη).mp (by simpa only [sq_abs] using hsq) + have hsum : |u+phaseDensity i| ≤ U+4*packingDensity := by + rw [abs_of_nonneg (add_nonneg hub.1 (phaseDensity_bounds i).1)] + linarith [hub.2, (phaseDensity_bounds i).2] + have hdiff : |u^2-(phaseDensity i)^2| ≤ η*(U+4*packingDensity) := by + rw [show u^2-(phaseDensity i)^2=(u-phaseDensity i)*(u+phaseDensity i) by ring, abs_mul] + exact mul_le_mul hdist hsum (abs_nonneg _) hη + have hA := phaseMass_pos + have hshift : |e+phaseMass*u^2/2-phaseMass/2*(phaseDensity i)^2| ≤ + 2*ε/σ+phaseMass/2*η*(U+4*packingDensity) := by + calc + _ = |e+phaseMass/2*(u^2-(phaseDensity i)^2)| := by congr 1; ring + _ ≤ |e|+|phaseMass/2*(u^2-(phaseDensity i)^2)| := abs_add_le _ _ + _ = |e|+(phaseMass/2)*|u^2-(phaseDensity i)^2| := by rw [abs_mul, abs_of_pos (by positivity : 0 < phaseMass/2)] + _ ≤ _ := by nlinarith [mul_le_mul_of_nonneg_left hdiff (by positivity : 0 ≤ phaseMass/2)] + refine ⟨i, ?_⟩ + have hn := parameter_norm_le (parameter (e+phaseMass*u^2/2) u-phaseSlope i) + change ‖parameter (e+phaseMass*u^2/2) u-phaseSlope i‖ ≤ + |e+phaseMass*u^2/2-phaseMass/2*(phaseDensity i)^2|+|u-phaseDensity i| at hn + nlinarith + +lemma phase_groups_of_generators {Q : Pressure} {x : Parameter} {G : Set Parameter} {r : ℝ} + (hgen : supportSet (onParameters Q) positiveParameters x=closure (convexHull ℝ G)) + (hG : ∀ v ∈ G, ∃ i : Fin 3, v ∈ Metric.closedBall (phaseSlope i) r) : + HasPhaseGroups Q x r := by + apply le_antisymm + · rw [hgen] + apply closure_mono + apply convexHull_mono + intro v hv + refine ⟨?_, hG v hv⟩ + exact subset_closure (subset_convexHull ℝ G hv) + · apply closure_minimal _ (isClosed_supportSet _ _ _) + exact convexHull_min (fun _ h => h.1) (convex_supportSet _ _ _) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/InteriorGrid.lean b/lean/OAI/Probability/RadialTransition/InteriorGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..95b615882c6b71ee022bf075d5434807ac2c1300 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/InteriorGrid.lean @@ -0,0 +1,138 @@ +import OAI.Probability.RadialTransition.KernelError + +namespace OAI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped BigOperators ENNReal NNReal ContDiff + +namespace RadialTransition + +lemma grid_inner_coords {m D : ℕ} {i : GridIndex m} (hi : i ∉ boundaryGrid m D) (d : Fin 3) : + D ≤ (i d:ℕ) ∧ (i d:ℕ)+D < m := by + have hn : ¬ ((i d:ℕ) < D ∨ m-D ≤ (i d:ℕ)) := fun h => hi (mem_boundaryGrid.mpr ⟨d,h⟩) + omega + +lemma grid_inner_reach {m : ℕ} {T : ℝ} (hT : 0 ≤ T) (i : GridIndex m) + (hi : i ∉ boundaryGrid m (cellMargin T).toNat) {j : Cell} (hj : CellReach T (gridEmbed i) j) : + ∃ k : GridIndex m, gridEmbed k = j := by + have hD : 0 ≤ cellMargin T := by unfold cellMargin; have := Int.ceil_nonneg (by positivity : 0 ≤ 4*T); omega + have hd (d : Fin 3) : 0 ≤ j d ∧ j d < (m:ℤ) := by + have hc := grid_inner_coords hi d + have ha := abs_le.mp (hj d) + have he : ((cellMargin T).toNat:ℤ) = cellMargin T := Int.toNat_of_nonneg hD + change -cellMargin T ≤ j d-(i d:ℤ) ∧ j d-(i d:ℤ) ≤ cellMargin T at ha + omega + refine ⟨fun d => ⟨(j d).toNat, by have := hd d; omega⟩, ?_⟩ + funext d + exact Int.toNat_of_nonneg (hd d).1 + +lemma macroKernel_support_inside {q m : ℕ} (hq : 0 < q) {R : ℝ} (hR : 0 ≤ R) (i : GridIndex m) + (hi : i ∉ boundaryGrid m (cellMargin (R/q+1)).toNat) : + ∀ y ∉ halfCube ((m:ℝ)*q/4), scaledBump R (macroOrigin q (gridEmbed i)-y) = 0 := by + intro y hy + by_cases hR0 : R = 0 + · simp [hR0, scaledBump] + have hRpos : 0 < R := lt_of_le_of_ne hR (Ne.symm hR0) + apply scaledBump_zero hRpos + rw [← dist_eq_norm] + apply le_of_not_gt + intro hd + have hm : y ∈ macroRegion q (macroOf q (cellOf y)) := rfl + have hr := macroReach_of_dist hq (macroOrigin_mem hq (gridEmbed i)) hm hd.le + have hT : 0 ≤ R/(q:ℝ)+1 := by positivity + obtain ⟨j, hj⟩ := grid_inner_reach hT i hi hr + rw [← hj] at hm + exact hy (macroRegion_subset_halfCube hq j hm) + +lemma macroKernelLower_diagonal {q : ℕ} {R : ℝ} (hR : 0 < R) (i : Cell) : + macroKernelLower q R i i ≤ (R^3)⁻¹*bumpIntegral⁻¹ := by + apply max_le + · have := bumpIntegral_pos; positivity + · have hb := scaledBump_bound hR (macroOrigin q i-macroOrigin q i) + have hn := macroKernelError_nonneg q R i i + have ha := le_abs_self (scaledBump R (macroOrigin q i-macroOrigin q i)) + change macroKernel q R i i ≤ _ at ha + linarith + +def kernelRowError (q : ℕ) (R : ℝ) : ℝ := + (10000*(bumpLip:ℝ)+bumpIntegral⁻¹)*(q:ℝ)/R + +lemma kernelRowError_nonneg (q : ℕ) {R : ℝ} (hR : 0 ≤ R) : 0 ≤ kernelRowError q R := by + unfold kernelRowError + have := bumpIntegral_pos + positivity + +lemma macroKernelLower_row {q m : ℕ} (hq : 0 < q) {R : ℝ} (hR : (q:ℝ)/4 ≤ R) (i : GridIndex m) + (hi : i ∉ boundaryGrid m (cellMargin (R/q+1)).toNat) : + 1-kernelRowError q R ≤ ((q:ℝ)/4)^3*∑ j : GridIndex m, + (if i = j then 0 else macroKernelLower q R (gridEmbed i) (gridEmbed j)) := by + classical + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hR0 : 0 < R := lt_of_lt_of_le (by positivity) hR + have hall := macroKernelLower_row_all hq hR (gridEmbed i) (macroKernel_support_inside hq hR0.le i hi) + have hs : (∑ j : GridIndex m, if i = j then (0:ℝ) else macroKernelLower q R (gridEmbed i) (gridEmbed j)) = + (∑ j : GridIndex m, macroKernelLower q R (gridEmbed i) (gridEmbed j))-macroKernelLower q R (gridEmbed i) (gridEmbed i) := by + have hh := Finset.sum_erase_add (Finset.univ : Finset (GridIndex m)) + (fun j => macroKernelLower q R (gridEmbed i) (gridEmbed j)) (Finset.mem_univ i) + have he : (∑ j : GridIndex m, if i = j then (0:ℝ) else macroKernelLower q R (gridEmbed i) (gridEmbed j)) = + ∑ j ∈ Finset.univ.erase i, macroKernelLower q R (gridEmbed i) (gridEmbed j) := by + simp only [Finset.sum_ite, Finset.sum_const_zero, zero_add] + congr 1 + ext j + simp [ne_comm] + rw [he] + linarith + rw [hs, mul_sub] + have hd := mul_le_mul_of_nonneg_left (macroKernelLower_diagonal (q := q) hR0 (gridEmbed i)) (show 0 ≤ ((q:ℝ)/4)^3 by positivity) + have hsq : ((q:ℝ)/4)^2 ≤ R^2 := pow_le_pow_left₀ (by positivity) hR 2 + have hd' : ((q:ℝ)/4)^3*((R^3)⁻¹*bumpIntegral⁻¹) ≤ bumpIntegral⁻¹*q/R := by + apply (le_div_iff₀ hR0).mpr + have hb := bumpIntegral_pos + have he : ((q:ℝ)/4)^3*((R^3)⁻¹*bumpIntegral⁻¹)*R = + bumpIntegral⁻¹*((q:ℝ)/4)*(((q:ℝ)/4)^2/R^2) := by field_simp + rw [he] + have hh : ((q:ℝ)/4)^2/R^2 ≤ 1 := (div_le_one (by positivity)).mpr hsq + calc + _ ≤ bumpIntegral⁻¹*((q:ℝ)/4)*1 := mul_le_mul_of_nonneg_left hh (by positivity) + _ ≤ _ := by nlinarith [inv_nonneg.mpr hb.le] + unfold kernelRowError + linear_combination hall + hd + hd' + +lemma kernelInterior_ratio (D : ℕ) : + Tendsto (fun m : ℕ => (((Finset.univ : Finset (GridIndex m)) \ boundaryGrid m D).card:ℝ)/(m:ℝ)^3) + atTop (nhds 1) := by + classical + have hcard (m : ℕ) : (((Finset.univ : Finset (GridIndex m)) \ boundaryGrid m D).card:ℝ) = + (m:ℝ)^3-((boundaryGrid m D).card:ℝ) := by + have hh := Finset.card_sdiff_add_card_inter (Finset.univ : Finset (GridIndex m)) (boundaryGrid m D) + simp only [Finset.univ_inter, Finset.card_univ, Fintype.card_fun, Fintype.card_fin] at hh + have hr : (((Finset.univ : Finset (GridIndex m)) \ boundaryGrid m D).card:ℝ)+((boundaryGrid m D).card:ℝ) = (m:ℝ)^3 := by exact_mod_cast hh + linarith + have hz : Tendsto (fun m : ℕ => (6:ℝ)*D/(m:ℝ)) atTop (nhds (0:ℝ)) := + tendsto_const_nhds.div_atTop tendsto_natCast_atTop_atTop + have hsmall : Tendsto (fun m : ℕ => ((boundaryGrid m D).card:ℝ)/(m:ℝ)^3) atTop (nhds (0:ℝ)) := by + apply squeeze_zero' (Eventually.of_forall (fun _ => by positivity)) ?_ hz + filter_upwards [eventually_gt_atTop (0:ℕ)] with m hm + have hm0 : (0:ℝ) < m := by exact_mod_cast hm + have hb : ((boundaryGrid m D).card:ℝ) ≤ 6*D*(m:ℝ)^2 := by exact_mod_cast card_boundaryGrid m D + apply (div_le_iff₀ (by positivity : 0 < (m:ℝ)^3)).mpr + calc + _ ≤ 6*D*(m:ℝ)^2 := hb + _ = _ := by field_simp + have ht' : Tendsto (fun m : ℕ => 1-((boundaryGrid m D).card:ℝ)/(m:ℝ)^3) atTop (nhds (1:ℝ)) := by + simpa using (tendsto_const_nhds.sub hsmall : Tendsto (fun m : ℕ => (1:ℝ)-((boundaryGrid m D).card:ℝ)/(m:ℝ)^3) atTop (nhds (1-0))) + apply ht'.congr' + filter_upwards [eventually_gt_atTop (0:ℕ)] with m hm + have hm0 : (0:ℝ) < m := by exact_mod_cast hm + rw [hcard] + field_simp + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/KacComparison.lean b/lean/OAI/Probability/RadialTransition/KacComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..7554d443a0fc57bb0ce03a82f4e8ff99ee024b2a --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/KacComparison.lean @@ -0,0 +1,88 @@ +import OAI.Probability.RadialTransition.KacPressure + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma family_row_mono_mass {t a : ℝ} {b : ℕ → ℝ} (ht : 0 ≤ t) (ha : 0 ≤ a) + (hrow : 2197*t*bumpIntegral⁻¹*(a+∑' n, b n) ≤ (t^2/8)/8) : + 2197*t*bumpIntegral⁻¹*(∑' n, b n) ≤ (t^2/8)/8 := by + have hc : 0 ≤ 2197*t*bumpIntegral⁻¹ := by have := bumpIntegral_pos; positivity + exact (mul_le_mul_of_nonneg_left (by linarith : (∑' n, b n) ≤ a+∑' n, b n) hc).trans hrow + +lemma family_grand_prepend_limit {t β a R : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (hβ : 0 ≤ β) (ha : 0 ≤ a) (hR : 1 ≤ R) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hrow : 2197*t*bumpIntegral⁻¹*(a+∑' n, b n) ≤ (t^2/8)/8) (h : ℝ) : + Tendsto (fun L : ℝ => finiteGrandPressure (familyPotential t (prepend a b) (prepend R S)) t L β h) atTop + (nhds (grandPressure (familyPotential t (prepend a b) (prepend R S)) t β h)) := by + have hba := prepend_nonneg ha hb + have hRS := prepend_range hR hS + have hsum := summable_prepend a hs + have hrow' : 2197*t*bumpIntegral⁻¹*(∑' n, prepend a b n) ≤ (t^2/8)/8 := by rw [tsum_prepend _ hs]; exact hrow + exact (grandPressure_spec (continuous_familyPotential hba hRS hsum t) + (bounded_familyPotential hba hRS hsum t) + (stable_family_of_master (by linarith) hba hRS hsum hsum (fun _ => le_rfl) hrow') + (by linarith) hβ (fun _ hr => familyPotential_nonpos_outer hba hRS ht hr) h).1 + +lemma family_kac_lower_limit {q : ℕ} (hq : 0 < q) {t β h R₀ a R D u : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (hβ : 0 < β) (ha : 0 ≤ a) (hR : (q:ℝ)/4 ≤ R) (hq1 : 1 ≤ (q:ℝ)/4) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hR₀ : 2 ≤ R₀) (hrange : ∀ n, S n ≤ R₀) + (hrow : 2197*t*bumpIntegral⁻¹*(a+∑' n, b n) ≤ (t^2/8)/8) + (hks : Summable (kacSeries (familyPotential t b S) q R t a β h)) + (hD : Real.exp (β*(t^2/2)+t*(h+β*a*u)+1) ≤ D) : + finiteGrandPressure (familyPotential t b S) t ((q:ℝ)/4) β (h+β*a*u)-β*a/2*u^2 ≤ + grandPressure (familyPotential t (prepend a b) (prepend R S)) t β h+ + boxPressureConstant t β h (∑' n, b n)*R₀/((q:ℝ)/4)+ + β*a/2*kernelRowError q R*D^2+Real.log ((D+2)*((q:ℝ)/4)^3)/(t*((q:ℝ)/4)^3) := by + have ht0 : 0 < t := by linarith + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hR1 : 1 ≤ R := hq1.trans hR + have hrowb := family_row_mono_mass ht0.le ha hrow + have hstable := stable_family_of_master ht0.le hb hS hs hs (fun _ => le_rfl) hrowb + have hl := (family_grand_prepend_limit ht hβ.le ha hR1 hb hS hs hrow h).comp + ((tendsto_natCast_atTop_atTop.atTop_mul_const hq0).atTop_div_const (by norm_num : (0:ℝ) < 4)) + have hf : Tendsto (fun m : ℕ => ((kernelInterior m q R).card:ℝ)/(m:ℝ)^3) atTop (nhds 1) := + kernelInterior_ratio (cellMargin (R/q+1)).toNat + have he := ((((tendsto_const_nhds (x := (1:ℝ))).sub (hf.mul_const (1-kernelRowError q R))).const_mul (β*a/2)).mul_const (D^2)) + have htt := (((hl.add_const (boxPressureConstant t β h (∑' n, b n)*R₀/((q:ℝ)/4))).add he).add_const + (Real.log ((D+2)*((q:ℝ)/4)^3)/(t*((q:ℝ)/4)^3))) + simp only [one_mul, sub_sub_cancel] at htt + apply ge_of_tendsto htt + filter_upwards [eventually_gt_atTop (0:ℕ)] with m hm + have hd := (abs_le.mp (family_kac_deletion (h := h) hm hq ht hβ ha hR1 hb hS hs hR₀ hrange hrow)).1 + have hk := deletedKacPressure_branch_lower (continuous_familyPotential hb hS hs t) + (bounded_familyPotential hb hS hs t) hm hq hstable ht0 hq1 hβ.le hR ha hks hD + dsimp only [Function.comp_def] + linarith + +lemma family_kac_upper_limit {q : ℕ} (hq : 0 < q) {t β h R₀ a R P : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (hβ : 0 < β) (ha : 0 ≤ a) (hR : (q:ℝ)/4 ≤ R) (hq1 : 1 ≤ (q:ℝ)/4) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hR₀ : 2 ≤ R₀) (hrange : ∀ n, S n ≤ R₀) + (hrow : 2197*t*bumpIntegral⁻¹*(a+∑' n, b n) ≤ (t^2/8)/8) + (hks : Summable (kacSeries (familyPotential t b S) q R t a β h)) + (hP : Real.log (∑' n, kacSeries (familyPotential t b S) q R t a β h n)/(t*((q:ℝ)/4)^3) ≤ P) : + grandPressure (familyPotential t (prepend a b) (prepend R S)) t β h ≤ + P+boxPressureConstant t β h (∑' n, b n)*R₀/((q:ℝ)/4) := by + have ht0 : 0 < t := by linarith + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hR1 : 1 ≤ R := hq1.trans hR + have hl := (family_grand_prepend_limit ht hβ.le ha hR1 hb hS hs hrow h).comp + ((tendsto_natCast_atTop_atTop.atTop_mul_const hq0).atTop_div_const (by norm_num : (0:ℝ) < 4)) + apply le_of_tendsto hl + filter_upwards [eventually_gt_atTop (0:ℕ)] with m hm + have hd := (abs_le.mp (family_kac_deletion (h := h) hm hq ht hβ ha hR1 hb hS hs hR₀ hrange hrow)).2 + have hk := deletedKacPressure_upper (continuous_familyPotential hb hS hs t) + (bounded_familyPotential hb hS hs t) hm hq ht0 hβ.le hR ha hks + dsimp only [Function.comp_def] + linarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/KacDeletion.lean b/lean/OAI/Probability/RadialTransition/KacDeletion.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0e9e433a0882ecd973ddcda578544332f3b7396 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/KacDeletion.lean @@ -0,0 +1,73 @@ +import OAI.Probability.RadialTransition.FamilyStep + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +def deletedKacPressure (φ : Potential) (m q : ℕ) (R t a β h : ℝ) : ℝ := + Real.log (boltzmannPartition (macroMeasure m q (t*h)) (fun x => β*macroKacEnergy φ m q R (t*a) x))/(t*((m:ℝ)*q/4)^3) + +lemma family_kac_deletion {m q : ℕ} (hm : 0 < m) (hq : 0 < q) + {t β h R₀ a R : ℝ} {b S : ℕ → ℝ} (ht : 1 ≤ t) (hβ : 0 < β) (ha : 0 ≤ a) (hR : 1 ≤ R) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hR₀ : 2 ≤ R₀) (hrange : ∀ n, S n ≤ R₀) + (hrow : 2197*t*bumpIntegral⁻¹*(a+∑' n, b n) ≤ (t^2/8)/8) : + |finiteGrandPressure (familyPotential t (prepend a b) (prepend R S)) t ((m:ℝ)*q/4) β h- + deletedKacPressure (familyPotential t b S) m q R t a β h| ≤ + boxPressureConstant t β h (∑' n, b n)*R₀/((q:ℝ)/4) := by + have ht0 : 0 < t := zero_lt_one.trans_le ht + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hm0 : (0:ℝ) < m := by exact_mod_cast hm + let : NeZero (m*q) := ⟨ne_of_gt (Nat.mul_pos hm hq)⟩ + have hba := prepend_nonneg ha hb + have hRS := prepend_range hR hS + have hsum := summable_prepend a hs + have hrow' : 2197*t*bumpIntegral⁻¹*(∑' n, prepend a b n) ≤ (t^2/8)/8 := by rw [tsum_prepend _ hs]; exact hrow + have hcont := continuous_familyPotential hba hRS hsum t + have hbound := bounded_familyPotential hba hRS hsum t + have hstable := stable_family_of_master ht0.le hba hRS hsum hsum (fun _ => le_rfl) hrow' + let W := referenceMajorant t b S + let K := fun i j => t*a*cellMajorant R bumpIntegral⁻¹ i j + have hK : ∀ i j, 0 ≤ K i j := fun i j => mul_nonneg (mul_nonneg ht0.le ha) (cellMajorant_nonneg (zero_le_one.trans hR) (inv_nonneg.mpr bumpIntegral_pos.le) _ _) + have hW : ∀ i j, 0 ≤ W i j := referenceMajorant_nonneg ht0.le hb hS + have htotal (i j : Cell) : familyCellMajorant t b S i j+K i j = familyCellMajorant t (prepend a b) (prepend R S) i j := + (familyCellMajorant_prepend hb hS hs i j).symm + have hcost := deletedPair_grid_bound (@gridEmbed (m*q)) (gridEmbed_injective _) (macroOf q) + (measurableSet_halfCube ((m*q:ℕ)/4)) (halfCube_grid_cover (m*q)) + (continuous_familyPotential hb hS hs t) (continuous_singleAttraction R (t*a)) ht0 hβ (t*h) + (familyCellMajorant t b S) K W (familyCellMajorant_nonneg ht0.le hb hS) hK + (fun i j => by rw [htotal, htotal]; exact familyCellMajorant_symm _ _ _ _ _) + (fun i => by simp_rw [htotal]; exact (familyCellMajorant_row (@gridEmbed (m*q)) (gridEmbed_injective _) ht0.le hba hRS hsum (gridEmbed i)).trans hrow') + (familyPotential_grid_lower ht0.le hb hb hS hs hs (fun _ => le_rfl)) + (fun x y => by + dsimp only [K, radialPair, singleAttraction] + have hh := mul_le_mul_of_nonneg_left (scaledBumpProfile_le_cellMajorant hR x y) (mul_nonneg ht0.le ha) + change -(t*a)*scaledBumpProfile R (dist x y) ≥ -(t*a*cellMajorant R bumpIntegral⁻¹ (cellOf x) (cellOf y)) + nlinarith) + hW (family_abs_le_referenceMajorant ht hb hS hs) + have hA : volume (halfCube (((m:ℝ)*q)/4)) ≠ ⊤ := by rw [volume_halfCube]; finiteness + have hgrand := pairGrand_radial hcont hbound hstable hβ.le hA (t*h) + rw [← familyPotential_prepend hb hS hs] at hcost + simp only [Nat.cast_mul] at hcost + rw [hgrand, grandOn_halfCube hcont hbound hstable hβ.le, grandOn_cube, + deletedPair_macroKac hq (continuous_familyPotential hb hS hs t) (zero_lt_one.trans_le hR)] at hcost + have hC : 0 ≤ referenceRowBound t (∑' n, b n) := referenceRowBound_nonneg ht0.le (tsum_nonneg hb) + have hsumBound := deletionMajorant_grid_sum_range (m := m) hq (show 1 ≤ R₀ by linarith) hC hW + (referenceMajorant_row (@gridEmbed (m*q)) (gridEmbed_injective _) ht0.le hb hS hs) + (referenceMajorant_support hR₀ hrange) + have hcoeff : 0 ≤ β/2*localMomentBound t β (t*h) := + mul_nonneg (by positivity) (localMomentBound_nonneg hβ.le _) + have hlog := hcost.trans (mul_le_mul_of_nonneg_left hsumBound hcoeff) + have hden : 0 < t*((m:ℝ)*q/4)^3 := by positivity + unfold finiteGrandPressure deletedKacPressure + rw [← sub_div, abs_div, abs_of_pos hden] + apply (div_le_iff₀ hden).mpr + convert hlog using 1; first | rfl | (unfold boxPressureConstant; field_simp; ring) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/KacPressure.lean b/lean/OAI/Probability/RadialTransition/KacPressure.lean new file mode 100644 index 0000000000000000000000000000000000000000..af09363f8cdb46b26b9f7e13a357eff0461b11f4 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/KacPressure.lean @@ -0,0 +1,106 @@ +import OAI.Probability.RadialTransition.KacDeletion + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +def kernelUpperError (q : ℕ) (R : ℝ) : ℝ := 10000*(bumpLip:ℝ)*q/R + +def kacSeries (φ : Potential) (q : ℕ) (R t a β h : ℝ) : ℕ → ℝ := + quadraticTerm φ ((q:ℝ)/4) β (t*h) (β*(t*a)*(1+kernelUpperError q R)/2) + +lemma kacPartition_ge_one {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {m q : ℕ} (hq : 0 < q) {R t a β h : ℝ} (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (hta : 0 ≤ t*a) + (hs : Summable (kacSeries φ q R t a β h)) : + 1 ≤ boltzmannPartition (macroMeasure m q (t*h)) (fun x => β*macroKacEnergy φ m q R (t*a) x) := by + have hi := integrable_macroKac (m := m) hφ hb hq hβ hR hta hs + have hh := macroKac_partition_lower hφ hb hq hβ hR hta hi 0 + simpa only [Nat.cast_zero, zero_pow (by decide : 2 ≠ 0), mul_zero, zero_div, Real.exp_zero, + partition_zero, one_mul, one_pow] using hh + +lemma deletedKacPressure_upper {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {m q : ℕ} (hm : 0 < m) (hq : 0 < q) {R t a β h : ℝ} (ht : 0 < t) + (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (ha : 0 ≤ a) + (hs : Summable (kacSeries φ q R t a β h)) : + deletedKacPressure φ m q R t a β h ≤ Real.log (∑' n, kacSeries φ q R t a β h n)/(t*((q:ℝ)/4)^3) := by + have hm0 : (0:ℝ) < m := by exact_mod_cast hm + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hta : 0 ≤ t*a := mul_nonneg ht.le ha + have hpos := (zero_lt_one.trans_le (kacPartition_ge_one hφ hb hq hβ hR hta hs (m := m))) + have hh := Real.log_le_log hpos (macroKac_partition_upper (m := m) hφ hb hq hβ hR hta hs) + rw [Real.log_pow] at hh + change _ ≤ ((m^3:ℕ):ℝ)*Real.log (∑' n, kacSeries φ q R t a β h n) at hh + have hden : 0 < t*((m:ℝ)*q/4)^3 := by positivity + unfold deletedKacPressure + apply (div_le_iff₀ hden).mpr + convert hh using 1 + first + | rfl + | simp only [Nat.cast_pow]; field_simp [ht.ne', hq0.ne'] + +lemma deletedKacPressure_sector_lower {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {m q : ℕ} (hm : 0 < m) (hq : 0 < q) {R t a β h : ℝ} (ht : 0 < t) + (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (ha : 0 ≤ a) + (hs : Summable (kacSeries φ q R t a β h)) (n : ℕ) : + h*((n:ℝ)/((q:ℝ)/4)^3)-finiteCanonical φ t ((q:ℝ)/4) n β+ + β*a/2*((kernelInterior m q R).card/(m:ℝ)^3)*(1-kernelRowError q R)*((n:ℝ)/((q:ℝ)/4)^3)^2 ≤ + deletedKacPressure φ m q R t a β h := by + have hm0 : (0:ℝ) < m := by exact_mod_cast hm + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hs0 : 0 < (q:ℝ)/4 := by positivity + have hta : 0 ≤ t*a := mul_nonneg ht.le ha + have hi := integrable_macroKac (m := m) hφ hb hq hβ hR hta hs + have hpos : 0 < Real.exp (t*h*n)*partition φ ((q:ℝ)/4) n β := + mul_pos (Real.exp_pos _) (partition_pos hφ hb hs0 n β) + have hh := Real.log_le_log (mul_pos (Real.exp_pos _) (pow_pos hpos _)) + (macroKac_partition_lower hφ hb hq hβ hR hta hi n) + rw [Real.log_mul (Real.exp_ne_zero _) (pow_ne_zero _ hpos.ne'), Real.log_exp, Real.log_pow, + Real.log_mul (Real.exp_ne_zero _) (partition_pos hφ hb hs0 n β).ne', Real.log_exp] at hh + unfold deletedKacPressure + apply (le_div_iff₀ (by positivity : 0 < t*((m:ℝ)*q/4)^3)).mpr + convert hh using 1 + first + | rfl + | unfold finiteCanonical + simp only [Nat.cast_pow] + field_simp [ht.ne', hq0.ne', hm0.ne'] + ring + +lemma kernelInterior_fraction {m q : ℕ} (hm : 0 < m) (R : ℝ) : + (0:ℝ) ≤ (kernelInterior m q R).card/(m:ℝ)^3 ∧ (kernelInterior m q R).card/(m:ℝ)^3 ≤ 1 := by + have hm0 : (0:ℝ) < m := by exact_mod_cast hm + refine ⟨by positivity, (div_le_one (by positivity)).mpr ?_⟩ + have hc := Finset.card_le_card (Finset.subset_univ (kernelInterior m q R)) + simpa only [Finset.card_univ, Fintype.card_fun, Fintype.card_fin, Nat.cast_pow] using (by exact_mod_cast hc : ((kernelInterior m q R).card:ℝ) ≤ (Fintype.card (GridIndex m):ℝ)) + +lemma deletedKacPressure_branch_lower {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {m q : ℕ} (hm : 0 < m) (hq : 0 < q) {B R t a β h D u : ℝ} + (hst : StableWith φ B) (ht : 0 < t) (hq1 : 1 ≤ (q:ℝ)/4) + (hβ : 0 ≤ β) (hR : (q:ℝ)/4 ≤ R) (ha : 0 ≤ a) + (hs : Summable (kacSeries φ q R t a β h)) (hD : Real.exp (β*B+t*(h+β*a*u)+1) ≤ D) : + finiteGrandPressure φ t ((q:ℝ)/4) β (h+β*a*u)-β*a/2*u^2 ≤ + deletedKacPressure φ m q R t a β h+ + β*a/2*(1-((kernelInterior m q R).card/(m:ℝ)^3)*(1-kernelRowError q R))*D^2+ + Real.log ((D+2)*((q:ℝ)/4)^3)/(t*((q:ℝ)/4)^3) := by + obtain ⟨n, hn, hmax⟩ := finiteGrandPressure_max_term hφ hb hst ht hq1 hβ hD + have hsector := deletedKacPressure_sector_lower hφ hb hm hq ht hβ hR ha hs n + let d := (n:ℝ)/((q:ℝ)/4)^3 + let v := ((kernelInterior m q R).card:ℝ)/(m:ℝ)^3 + have hv := kernelInterior_fraction (q := q) hm R + have he := kernelRowError_nonneg q (le_trans (by linarith) hR) + have hv' : 0 ≤ 1-v*(1-kernelRowError q R) := by dsimp only [v]; nlinarith [mul_nonneg hv.1 he] + have hb0 : 0 ≤ β*a/2 := by positivity + have hD0 : 0 ≤ D := hn.1.trans hn.2 + have hsq : d^2 ≤ D^2 := (sq_le_sq₀ hn.1 hD0).mpr hn.2 + have herror := mul_le_mul_of_nonneg_left hsq (mul_nonneg hb0 hv') + have hdiff := mul_nonneg hb0 (sq_nonneg (u-d)) + dsimp only [d, v] at herror hdiff + nlinarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/KacVariational.lean b/lean/OAI/Probability/RadialTransition/KacVariational.lean new file mode 100644 index 0000000000000000000000000000000000000000..5147157f756dfc7cf91ea2b97ae587161416477c --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/KacVariational.lean @@ -0,0 +1,104 @@ +import OAI.Probability.RadialTransition.UniformConstants + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma family_kac_variational_grid {q : ℕ} (hq : 0 < q) + {t β h R₀ a R κ D F C : ℝ} {b S : ℕ → ℝ} + (ht : 1 ≤ t) (hβ : 0 < β) (ha : 0 ≤ a) (hR : (q:ℝ)/4 ≤ R) (hq1 : 1 ≤ (q:ℝ)/4) + (hb : ∀ n, 0 ≤ b n) (hS : ∀ n, 1 ≤ S n) (hs : Summable b) + (hR₀ : 2 ≤ R₀) (hrange : ∀ n, S n ≤ R₀) + (hrow : 2197*t*bumpIntegral⁻¹*(a+∑' n, b n) ≤ (t^2/8)/8) + (hκ : 0 < κ) (hc : κ ≤ β*(t^2/3456)-β*t*a*(1+kernelUpperError q R)/2) + (hD : 1 ≤ D) (hcut : t*h+β*(t^2/2)+t+1 ≤ κ*D) + (hDF : D ≤ F) (hF : Real.exp (β*(t^2/2)+t*(h+β*a*D)+1) ≤ F) + (hC : ∀ v ∈ Icc (0:ℝ) D, boxPressureConstant t β (h+β*a*v) (∑' n, b n) ≤ C) : + |grandPressure (familyPotential t (prepend a b) (prepend R S)) t β h- + idealAttraction (grandPressure (familyPotential t b S) t) a β h| ≤ + 2*C*R₀/((q:ℝ)/4)+β*a/2*kernelRowError q R*F^2+ + Real.log ((F+2)*((q:ℝ)/4)^3)/(t*((q:ℝ)/4)^3) := by + let φ := familyPotential t b S + let Q := grandPressure φ t + let s := (q:ℝ)/4 + have hs1 : 1 ≤ s := hq1 + have hs0 : 0 < s := by linarith + have ht0 : 0 < t := by linarith + have hR0 : 0 ≤ R := by linarith + have hR1 : 1 ≤ R := hq1.trans hR + have hrowb := family_row_mono_mass ht0.le ha hrow + have hst := stable_family_of_master ht0.le hb hS hs hs (fun _ => le_rfl) hrowb + have hφ := continuous_familyPotential hb hS hs t + have hbd := bounded_familyPotential hb hS hs t + have heta := kernelUpperError_nonneg q hR0 + have hcoerc : 2197*t*bumpIntegral⁻¹*(∑' n, b n)/2 ≤ t^2/16 := by nlinarith [sq_nonneg t] + have hca : κ/t ≤ β*t/3456-β*a/2 := by + apply (div_le_iff₀ ht0).mpr + nlinarith [mul_nonneg (show 0 ≤ β*t*a by positivity) heta] + have hcuta : h+β*t/2+1/t+1 ≤ κ/t*D := by + apply (mul_le_mul_iff_left₀ ht0).mp + have he1 : t*(h+β*t/2+1/t+1) = t*h+β*(t^2/2)+t+1 := by field_simp; ring + have he2 : t*(κ/t*D) = κ*D := by field_simp + rw [mul_comm _ t, mul_comm (κ/t*D) t, he1, he2] + exact hcut + obtain ⟨u, hu, hactive⟩ := family_ideal_exists_active ht hβ ha hb hS hs hrowb + (div_pos hκ ht0) hca hD hcuta + have hfinite := ideal_bddAbove_of_active hactive + have hnonneg := ideal_nonneg_of_active hactive ((family_pressure_data ht hβ hb hS hs hrowb).2.1 h) + have hC0 : boxPressureConstant t β h (∑' n, b n) ≤ C := by + simpa only [mul_zero, add_zero] using hC 0 ⟨le_rfl, by linarith⟩ + have hCpos : 0 ≤ C := (boxPressureConstant_nonneg ht0.le hβ.le (tsum_nonneg hb)).trans hC0 + have hbox (v : ℝ) (hv : v ∈ Icc (0:ℝ) D) : + |finiteGrandPressure φ t s β (h+β*a*v)-Q β (h+β*a*v)| ≤ C*R₀/s := by + apply (finiteGrandPressure_family_box_error hq ht hβ hb hS hs hR₀ hrange hrowb).trans + exact div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right (hC v hv) (by linarith)) hs0.le + have hbound (d : ℝ) (hd : d ∈ Icc (0:ℝ) D) : + finiteGrandPressure φ t s β (h+β*a*d)-β*a/2*d^2 ≤ idealAttraction Q a β h+C*R₀/s := by + have hsum := le_csSup hfinite (mem_range_self d) + have hh := (abs_le.mp (hbox d hd)).2 + change attractionBranch Q a d β h ≤ idealAttraction Q a β h at hsum + dsimp only [attractionBranch] at hsum + linarith + have hquad := quadratic_sum_pressure_bound hφ hbd hst ht0 hs1 hβ.le ha heta hκ hc hD + (show t*h+β*(t^2/2)+2 ≤ κ*D by linarith) + (fun n x hx => family_density_stability ht0.le hs1 hb hS hs hcoerc x hx) + (show 0 ≤ idealAttraction Q a β h+C*R₀/s by positivity) hbound + have hks : Summable (kacSeries φ q R t a β h) := by + simpa only [kacSeries, φ, s, ← mul_assoc] using hquad.1 + have hup := family_kac_upper_limit hq ht hβ ha hR hq1 hb hS hs hR₀ hrange hrow hks + (show Real.log (∑' n, kacSeries φ q R t a β h n)/(t*s^3) ≤ + idealAttraction Q a β h+C*R₀/s+β*a*kernelUpperError q R/2*D^2+ + Real.log ((D+2)*s^3)/(t*s^3) by + simpa only [kacSeries, φ, s, ← mul_assoc] using hquad.2) + have hFu : Real.exp (β*(t^2/2)+t*(h+β*a*u)+1) ≤ F := by + apply le_trans (Real.exp_le_exp.mpr ?_) hF + gcongr + exact hu.2 + have hlo := family_kac_lower_limit hq ht hβ ha hR hq1 hb hS hs hR₀ hrange hrow hks hFu + have hboxu := (abs_le.mp (hbox u hu)).1 + have heq := idealAttraction_eq_of_active hactive + change idealAttraction Q a β h = Q β (h+β*a*u)-β*a/2*u^2 at heq + have hdel : boxPressureConstant t β h (∑' n, b n)*R₀/s ≤ C*R₀/s := + div_le_div_of_nonneg_right (mul_le_mul_of_nonneg_right hC0 (by linarith)) hs0.le + have hDF0 : 0 ≤ D := by linarith + have hF0 : 0 ≤ F := hDF0.trans hDF + have herr : β*a*kernelUpperError q R/2*D^2 ≤ β*a/2*kernelRowError q R*F^2 := by + have hh := mul_le_mul (kernelUpperError_le_row hR0) ((sq_le_sq₀ hDF0 hF0).mpr hDF) + (sq_nonneg D) (kernelRowError_nonneg q hR0) + nlinarith [mul_le_mul_of_nonneg_left hh (show 0 ≤ β*a/2 by positivity)] + have hlog : Real.log ((D+2)*s^3)/(t*s^3) ≤ Real.log ((F+2)*s^3)/(t*s^3) := by + apply div_le_div_of_nonneg_right _ (by positivity) + apply Real.log_le_log (by positivity) + exact mul_le_mul_of_nonneg_right (by linarith) (by positivity) + apply abs_le.mpr + dsimp only [φ, Q, s] at hboxu hdel heq herr hlog hup hlo ⊢ + rw [show 2*C*R₀/((q:ℝ)/4) = 2*(C*R₀/((q:ℝ)/4)) by ring] + constructor <;> linarith only [hboxu, hdel, heq, herr, hlog, hup, hlo] + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/KernelError.lean b/lean/OAI/Probability/RadialTransition/KernelError.lean new file mode 100644 index 0000000000000000000000000000000000000000..f6f71b192963a1d30413f19c42156a75466e9000 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/KernelError.lean @@ -0,0 +1,126 @@ +import OAI.Probability.RadialTransition.RangeBounds + +namespace OAI + +universe uI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped BigOperators ENNReal NNReal ContDiff + +namespace RadialTransition + +lemma macroKernelError_row {I : Type uI} [Fintype I] (e : I → Cell) (he : Function.Injective e) + {q : ℕ} (hq : 0 < q) {R : ℝ} (hR : (q:ℝ)/4 ≤ R) (i : Cell) : + ((q:ℝ)/4)^3*∑ j, macroKernelError q R i (e j) ≤ 5000*(bumpLip:ℝ)*q/R := by + classical + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hR0 : 0 < R := lt_of_lt_of_le (by positivity) hR + let T := R/(q:ℝ)+1 + have hT : 1 ≤ T := by dsimp [T]; linarith [div_nonneg hR0.le hq0.le] + have hT0 : 0 < T := zero_lt_one.trans_le hT + have hh := cellMajorant_row e he hT (show 0 ≤ T^3*((bumpLip:ℝ)/R^4*q) by positivity) i + have heq (j : I) : cellMajorant T (T^3*((bumpLip:ℝ)/R^4*q)) i (e j) = macroKernelError q R i (e j) := by + unfold cellMajorant macroKernelError + split_ifs <;> simp_all [T, hT0.ne'] + simp_rw [heq] at hh + have hTq : (q:ℝ)*T ≤ 5*R := by dsimp [T]; field_simp; nlinarith + have hc : ((q:ℝ)*T)^3 ≤ (5*R)^3 := pow_le_pow_left₀ (by positivity) hTq 3 + calc + _ ≤ ((q:ℝ)/4)^3*(2197*(T^3*((bumpLip:ℝ)/R^4*q))) := mul_le_mul_of_nonneg_left hh (by positivity) + _ = (2197/64:ℝ)*((q:ℝ)*T)^3*((bumpLip:ℝ)*q/R^4) := by ring + _ ≤ (2197/64:ℝ)*(5*R)^3*((bumpLip:ℝ)*q/R^4) := + mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_left hc (by norm_num)) (by positivity) + _ ≤ _ := by field_simp; nlinarith [show (0:ℝ) ≤ bumpLip from NNReal.coe_nonneg _] + +lemma macroRegions_disjoint (q m : ℕ) : Pairwise (Function.onFun Disjoint (fun i : GridIndex m => macroRegion q (gridEmbed i))) := by + intro i j hij + apply Set.disjoint_left.mpr + intro x hx hy + exact hij (gridEmbed_injective m (hx.symm.trans hy)) + +lemma macroRegions_integral {q m : ℕ} (hq : 0 < q) {f : Position → ℝ} (hf : Integrable f) : + ∫ x in halfCube ((m:ℝ)*q/4), f x = + ∑ j : GridIndex m, ∫ x in macroRegion q (gridEmbed j), f x := by + rw [← halfCube_macro_union hq] + exact integral_iUnion_fintype (fun _ => measurableSet_macroRegion _ _) (macroRegions_disjoint _ _) (fun _ => hf.integrableOn) + +lemma macroKernel_center_error {q : ℕ} (hq : 0 < q) {R : ℝ} (hR : 0 < R) + (i j : Cell) {y : Position} (hy : y ∈ macroRegion q j) : + |scaledBump R (macroOrigin q i-y)-macroKernel q R i j| ≤ macroKernelError q R i j := by + by_cases h : CellReach (R/q+1) i j + · rw [macroKernelError, ite_eq_left h] + exact (scaledBump_oscillation hR _ _).trans + (mul_le_mul_of_nonneg_left (macro_difference_dist hq (macroOrigin_mem hq i) hy) (by positivity)) + · have hd : R < dist (macroOrigin q i) y := lt_of_not_ge (fun hh => h (macroReach_of_dist hq (macroOrigin_mem hq i) hy hh)) + have hd' : R < dist (macroOrigin q i) (macroOrigin q j) := + lt_of_not_ge (fun hh => h (macroReach_of_dist hq (macroOrigin_mem hq i) (macroOrigin_mem hq j) hh)) + rw [macroKernel, scaledBump_zero hR (by simpa only [dist_eq_norm] using hd.le), + scaledBump_zero hR (by simpa only [dist_eq_norm] using hd'.le), sub_self, abs_zero, + macroKernelError, ite_eq_right h] + +lemma macroKernel_upper_integral {q : ℕ} (hq : 0 < q) {R : ℝ} (hR : 0 < R) (i j : Cell) : + ((q:ℝ)/4)^3*(macroKernelUpper q R i j-2*macroKernelError q R i j) ≤ + ∫ y in macroRegion q j, scaledBump R (macroOrigin q i-y) := by + have hh := setIntegral_mono_on + (integrableOn_const (by rw [volume_macroRegion hq]; finiteness) : + IntegrableOn (fun _ : Position => macroKernelUpper q R i j-2*macroKernelError q R i j) (macroRegion q j)) + ((integrable_scaledBump hR).comp_sub_left (macroOrigin q i)).integrableOn + (measurableSet_macroRegion _ _) (fun y hy => ?_) + · simpa only [setIntegral_const, Measure.real, volume_macroRegion hq, + ENNReal.toReal_pow, ENNReal.toReal_ofReal (by positivity : 0 ≤ (q:ℝ)/4), smul_eq_mul] using hh + · have hb := (abs_le.mp (macroKernel_center_error hq hR i j hy)).1 + unfold macroKernelUpper + linarith + +lemma macroKernel_lower_integral {q : ℕ} (hq : 0 < q) {R : ℝ} (hR : 0 < R) (i j : Cell) : + (∫ y in macroRegion q j, scaledBump R (macroOrigin q i-y)) ≤ + ((q:ℝ)/4)^3*(macroKernelLower q R i j+2*macroKernelError q R i j) := by + have hh := setIntegral_mono_on ((integrable_scaledBump hR).comp_sub_left (macroOrigin q i)).integrableOn + (integrableOn_const (by rw [volume_macroRegion hq]; finiteness) : + IntegrableOn (fun _ : Position => macroKernelLower q R i j+2*macroKernelError q R i j) (macroRegion q j)) + (measurableSet_macroRegion _ _) (fun y hy => ?_) + · simpa only [setIntegral_const, Measure.real, volume_macroRegion hq, + ENNReal.toReal_pow, ENNReal.toReal_ofReal (by positivity : 0 ≤ (q:ℝ)/4), smul_eq_mul] using hh + · have hb := (abs_le.mp (macroKernel_center_error hq hR i j hy)).2 + have hm := le_max_right 0 (macroKernel q R i j-macroKernelError q R i j) + change _ ≤ macroKernelLower q R i j at hm + linarith + +lemma macroKernelUpper_row {q m : ℕ} (hq : 0 < q) {R : ℝ} (hR : (q:ℝ)/4 ≤ R) (i : Cell) : + ((q:ℝ)/4)^3*∑ j : GridIndex m, macroKernelUpper q R i (gridEmbed j) ≤ + 1+10000*(bumpLip:ℝ)*q/R := by + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hR0 : 0 < R := lt_of_lt_of_le (by positivity) hR + have hi := (integrable_scaledBump hR0).comp_sub_left (macroOrigin q i) + have hh := Finset.sum_le_sum (s := Finset.univ) (fun (j : GridIndex m) _ => macroKernel_upper_integral hq hR0 i (gridEmbed j)) + rw [← macroRegions_integral hq hi] at hh + have hle : (∫ y in halfCube ((m:ℝ)*q/4), scaledBump R (macroOrigin q i-y)) ≤ 1 := by + have ht := setIntegral_le_integral hi (Eventually.of_forall (fun y => scaledBump_nonneg hR0 _)) (s := halfCube ((m:ℝ)*q/4)) + simpa only [integral_sub_left_eq_self, integral_scaledBump hR0] using ht + have hb := macroKernelError_row (@gridEmbed m) (gridEmbed_injective m) hq hR i + simp_rw [mul_sub, Finset.sum_sub_distrib, ← Finset.mul_sum] at hh + linear_combination hh + hle + 2*hb + +lemma macroKernelLower_row_all {q m : ℕ} (hq : 0 < q) {R : ℝ} (hR : (q:ℝ)/4 ≤ R) (i : Cell) + (hs : ∀ y ∉ halfCube ((m:ℝ)*q/4), scaledBump R (macroOrigin q i-y) = 0) : + 1-10000*(bumpLip:ℝ)*q/R ≤ + ((q:ℝ)/4)^3*∑ j : GridIndex m, macroKernelLower q R i (gridEmbed j) := by + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hR0 : 0 < R := lt_of_lt_of_le (by positivity) hR + have hi := (integrable_scaledBump hR0).comp_sub_left (macroOrigin q i) + have hh := Finset.sum_le_sum (s := Finset.univ) (fun (j : GridIndex m) _ => macroKernel_lower_integral hq hR0 i (gridEmbed j)) + rw [← macroRegions_integral hq hi, setIntegral_eq_integral_of_forall_compl_eq_zero hs, + integral_sub_left_eq_self, integral_scaledBump hR0] at hh + have hb := macroKernelError_row (@gridEmbed m) (gridEmbed_injective m) hq hR i + simp_rw [mul_add, Finset.sum_add_distrib, ← Finset.mul_sum] at hh + linear_combination hh + 2*hb + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/LatticeStability.lean b/lean/OAI/Probability/RadialTransition/LatticeStability.lean new file mode 100644 index 0000000000000000000000000000000000000000..c53c89d61b13d68137e93d042e3fc48171b6d79a --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/LatticeStability.lean @@ -0,0 +1,342 @@ +import OAI.Probability.RadialTransition.ScaledKernels + +namespace OAI + +universe uI uV + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +abbrev Cell := Fin 3 → ℤ + +def cellOf (x : Position) : Cell := fun k => ⌊4 * x k⌋ + +def cellMargin (R : ℝ) : ℤ := ⌈4 * R⌉ + 1 + +def CellReach (R : ℝ) (i j : Cell) : Prop := ∀ k, |j k - i k| ≤ cellMargin R + +instance (R : ℝ) (i j : Cell) : Decidable (CellReach R i j) := inferInstanceAs (Decidable (∀ _k, _)) + +def rangeCells (R : ℝ) (i : Cell) : Finset Cell := + Fintype.piFinset fun k => Finset.Icc (i k - cellMargin R) (i k + cellMargin R) + +theorem mem_rangeCells (R : ℝ) (i j : Cell) : j ∈ rangeCells R i ↔ CellReach R i j := by + simp only [rangeCells, Fintype.mem_piFinset, Finset.mem_Icc, CellReach, abs_le] + constructor <;> intro h k <;> have hh := h k <;> constructor <;> omega + +theorem cellReach_symm {R : ℝ} {i j : Cell} (h : CellReach R i j) : CellReach R j i := by + intro k + simpa only [abs_sub_comm] using h k + +theorem cellMargin_nonneg {R : ℝ} (hR : 0 ≤ R) : 0 ≤ cellMargin R := by + have hh := Int.le_ceil (4 * R) + have : (0 : ℝ) ≤ (cellMargin R : ℝ) := by dsimp [cellMargin]; push_cast; linarith + exact_mod_cast this + +theorem card_rangeCells {R : ℝ} (hR : 1 ≤ R) (i : Cell) : + ((rangeCells R i).card : ℝ) ≤ 2197 * R ^ 3 := by + have hm := cellMargin_nonneg (le_trans zero_le_one hR) + have hm1 : 0 ≤ 2 * cellMargin R + 1 := by omega + have heq : (rangeCells R i).card = (2 * cellMargin R + 1).toNat ^ 3 := by + simp only [rangeCells, Fintype.card_piFinset, Int.card_Icc] + simp_rw [show ∀ k, i k + cellMargin R + 1 - (i k - cellMargin R) = + 2 * cellMargin R + 1 by intro k; ring] + simp + rw [heq] + have hcast : (((2 * cellMargin R + 1).toNat : ℕ) : ℝ) = 2 * (cellMargin R : ℝ) + 1 := by + have hh := Int.toNat_of_nonneg hm1 + exact_mod_cast hh + push_cast + rw [hcast] + have hb : 2 * (cellMargin R : ℝ) + 1 ≤ 13 * R := by + have hc := Int.ceil_lt_add_one (4 * R) + dsimp [cellMargin] + push_cast + linarith + calc + _ ≤ (13 * R) ^ 3 := pow_le_pow_left₀ (by exact_mod_cast hm1) hb 3 + _ = _ := by ring + +theorem cellReach_of_dist {x y : Position} {R : ℝ} (hxy : dist x y ≤ R) : + CellReach R (cellOf x) (cellOf y) := by + intro k + have hc : |x k - y k| ≤ R := by + simpa only [Real.dist_eq] using (PiLp.dist_apply_le x y k).trans hxy + have hxl := Int.floor_le (4 * x k) + have hyl := Int.floor_le (4 * y k) + have hxu := Int.lt_floor_add_one (4 * x k) + have hyu := Int.lt_floor_add_one (4 * y k) + have hceil := Int.le_ceil (4 * R) + have hb : |((⌊4 * y k⌋ : ℤ) : ℝ) - (⌊4 * x k⌋ : ℤ)| ≤ (⌈4 * R⌉ : ℤ) + (1 : ℝ) := by + rcases abs_le.mp hc with ⟨hc1, hc2⟩ + apply abs_le.mpr + constructor <;> linarith + dsimp [cellOf, cellMargin] + exact_mod_cast hb + +def cellMajorant (R W : ℝ) (i j : Cell) : ℝ := + if CellReach R i j then (R ^ 3)⁻¹ * W else 0 + +theorem cellMajorant_nonneg {R W : ℝ} (hR : 0 ≤ R) (hW : 0 ≤ W) (i j : Cell) : + 0 ≤ cellMajorant R W i j := + ite_nonneg (mul_nonneg (inv_nonneg.mpr (pow_nonneg hR _)) hW) le_rfl + +theorem cellMajorant_symm (R W : ℝ) (i j : Cell) : + cellMajorant R W i j = cellMajorant R W j i := by + unfold cellMajorant + have hh : CellReach R i j ↔ CellReach R j i := ⟨cellReach_symm, cellReach_symm⟩ + by_cases h : CellReach R i j + · simp [h, hh.mp h] + · simp [h, show ¬ CellReach R j i from fun hji => h (hh.mpr hji)] + +theorem cellMajorant_row {I : Type uI} [Fintype I] + (e : I → Cell) (he : Function.Injective e) {R W : ℝ} (hR : 1 ≤ R) (hW : 0 ≤ W) + (i : Cell) : ∑ j, cellMajorant R W i (e j) ≤ 2197 * W := by + classical + let s := Finset.univ.filter (fun j => CellReach R i (e j)) + have hcard : s.card ≤ (rangeCells R i).card := by + apply Finset.card_le_card_of_injOn e + · intro j hj + exact (mem_rangeCells R i (e j)).mpr (Finset.mem_filter.mp hj).2 + · exact he.injOn + have hsum : (∑ j, cellMajorant R W i (e j)) = (s.card : ℝ) * ((R ^ 3)⁻¹ * W) := by + simp [cellMajorant, s, ← Finset.sum_filter] + rw [hsum] + have hR0 : 0 < R := lt_of_lt_of_le zero_lt_one hR + have hc : (s.card : ℝ) ≤ 2197 * R ^ 3 := + (by exact_mod_cast hcard : (s.card : ℝ) ≤ (rangeCells R i).card).trans (card_rangeCells hR i) + calc + _ ≤ (2197 * R ^ 3) * ((R ^ 3)⁻¹ * W) := + mul_le_mul_of_nonneg_right hc (mul_nonneg (inv_nonneg.mpr (pow_nonneg hR0.le _)) hW) + _ = _ := by field_simp + +theorem same_cell_diameter {x y : Position} (h : cellOf x = cellOf y) : + dist x y ≤ 1 := by + have hc (k : Fin 3) : |x k - y k| ≤ 1 / 4 := by + have hh : ⌊4 * x k⌋ = ⌊4 * y k⌋ := congrFun h k + have hxl := Int.floor_le (4 * x k) + have hxu := Int.lt_floor_add_one (4 * x k) + have hyl := Int.floor_le (4 * y k) + have hyu := Int.lt_floor_add_one (4 * y k) + rw [← hh] at hyl hyu + apply abs_le.mpr + constructor <;> linarith + have hs : dist x y ^ 2 ≤ 3 * (1 / 4 : ℝ) ^ 2 := by + rw [EuclideanSpace.dist_sq_eq] + calc + _ ≤ ∑ k : Fin 3, (1 / 4 : ℝ) ^ 2 := by + apply Finset.sum_le_sum + intro k _ + simpa only [Real.dist_eq] using pow_le_pow_left₀ (abs_nonneg _) (hc k) 2 + _ = _ := by simp + nlinarith [dist_nonneg (x := x) (y := y)] + +theorem scaledBumpProfile_le_cellMajorant {R : ℝ} (hR : 1 ≤ R) (x y : Position) : + scaledBumpProfile R (dist x y) ≤ cellMajorant R bumpIntegral⁻¹ (cellOf x) (cellOf y) := by + have hR0 := lt_of_lt_of_le zero_lt_one hR + by_cases h : CellReach R (cellOf x) (cellOf y) + · simp only [cellMajorant, ite_eq_left h, scaledBumpProfile] + exact mul_le_mul_of_nonneg_left ((le_abs_self _).trans (bumpProfile_bound _)) + (inv_nonneg.mpr (pow_nonneg hR0.le _)) + · have hd : R ≤ dist x y := le_of_not_ge (fun hh => h (cellReach_of_dist hh)) + simp [cellMajorant, h, scaledBumpProfile_zero hR0 hd] + +def familyCellMajorant (t : ℝ) (a R : ℕ → ℝ) (i j : Cell) : ℝ := + t * ∑' n, a n * cellMajorant (R n) bumpIntegral⁻¹ i j + +theorem summable_cellMajorant {a R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) (i j : Cell) : + Summable (fun n => a n * cellMajorant (R n) bumpIntegral⁻¹ i j) := by + apply (hs.mul_right bumpIntegral⁻¹).of_nonneg_of_le + · intro n + exact mul_nonneg (ha n) (cellMajorant_nonneg (zero_le_one.trans (hR n)) + (inv_nonneg.mpr bumpIntegral_pos.le) i j) + · intro n + apply mul_le_mul_of_nonneg_left ?_ (ha n) + unfold cellMajorant + split_ifs + · exact mul_le_of_le_one_left (inv_nonneg.mpr bumpIntegral_pos.le) + (inv_le_one_of_one_le₀ (one_le_pow₀ (hR n))) + · exact inv_nonneg.mpr bumpIntegral_pos.le + +theorem familyCellMajorant_nonneg {t : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (i j : Cell) : + 0 ≤ familyCellMajorant t a R i j := by + apply mul_nonneg ht (tsum_nonneg _) + intro n + exact mul_nonneg (ha n) (cellMajorant_nonneg (zero_le_one.trans (hR n)) + (inv_nonneg.mpr bumpIntegral_pos.le) i j) + +theorem familyCellMajorant_symm (t : ℝ) (a R : ℕ → ℝ) (i j : Cell) : + familyCellMajorant t a R i j = familyCellMajorant t a R j i := by + unfold familyCellMajorant + congr 1 + apply tsum_congr + intro n + rw [cellMajorant_symm] + +theorem familyCellMajorant_row {I : Type uI} [Fintype I] (e : I → Cell) + (he : Function.Injective e) {t : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) (i : Cell) : + ∑ j, familyCellMajorant t a R i (e j) ≤ 2197 * t * bumpIntegral⁻¹ * ∑' n, a n := by + simp only [familyCellMajorant, ← Finset.mul_sum] + have hswap : (∑ j, ∑' n, a n * cellMajorant (R n) bumpIntegral⁻¹ i (e j)) = + ∑' n, a n * ∑ j, cellMajorant (R n) bumpIntegral⁻¹ i (e j) := by + rw [← Summable.tsum_finsetSum (fun j _ => summable_cellMajorant ha hR hs i (e j))] + simp_rw [Finset.mul_sum] + rw [hswap] + calc + _ ≤ t * ∑' n, a n * (2197 * bumpIntegral⁻¹) := by + apply mul_le_mul_of_nonneg_left ?_ ht + apply Summable.tsum_le_tsum + · intro n + exact mul_le_mul_of_nonneg_left + (cellMajorant_row e he (hR n) (inv_nonneg.mpr bumpIntegral_pos.le) i) (ha n) + · simpa only [Finset.mul_sum] using + summable_sum (fun j (_ : j ∈ (Finset.univ : Finset I)) => + summable_cellMajorant ha hR hs i (e j)) + · exact hs.mul_right _ + _ = _ := by rw [tsum_mul_right]; ring + +theorem attraction_le_familyCellMajorant {t : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) (x y : Position) : + t * attractionProfile a R (dist x y) ≤ familyCellMajorant t a R (cellOf x) (cellOf y) := by + apply mul_le_mul_of_nonneg_left ?_ ht + exact Summable.tsum_le_tsum + (fun n => mul_le_mul_of_nonneg_left (scaledBumpProfile_le_cellMajorant (hR n) x y) (ha n)) + (summable_attractionProfile ha hR hs _) (summable_cellMajorant ha hR hs _ _) + +theorem family_energy_cell_bound {I : Type uI} [Fintype I] {N : ℕ} + (e : I → Cell) (he : Function.Injective e) (q : Fin N → I) (x : Fin N → Position) + (hq : ∀ j, e (q j) = cellOf (x j)) {t : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) : + (t ^ 2 / 8 - (2197 * t * bumpIntegral⁻¹ * ∑' n, a n) / 2) * + (∑ i, occupation q i ^ 2) - t ^ 2 / 2 * N ≤ energy (familyPotential t a R) x := by + have hh := modified_energy_cell_bound ht q x (fun _ _ => 1) + (fun i j => t * attractionProfile a R (dist (x i) (x j))) + (fun i j => familyCellMajorant t a R (e i) (e j)) + (fun _ _ => zero_le_one) (fun _ _ => rfl) (fun _ _ _ => rfl) + (fun i j hij => same_cell_diameter (by rw [← hq i, ← hq j, hij])) + (fun i j => mul_nonneg ht (attractionProfile_nonneg ha hR _)) + (fun i j => by rw [dist_comm (x i) (x j)]) + (fun i j => by simpa only [hq] using attraction_le_familyCellMajorant ht ha hR hs (x i) (x j)) + (fun i j => familyCellMajorant_nonneg ht ha hR (e i) (e j)) + (fun i j => familyCellMajorant_symm t a R (e i) (e j)) + (fun i => familyCellMajorant_row e he ht ha hR hs (e i)) + simpa only [one_mul, energy, familyPotential, coe_nndist] using hh + +theorem stable_familyPotential {t : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hcoerc : 2197 * t * bumpIntegral⁻¹ * (∑' n, a n) / 2 ≤ t ^ 2 / 8) : + StableWith (familyPotential t a R) (t ^ 2 / 2) := by + classical + intro N x + let S : Finset Cell := Finset.univ.image (fun j => cellOf (x j)) + let q : Fin N → S := fun j => ⟨cellOf (x j), Finset.mem_image.mpr ⟨j, Finset.mem_univ _, rfl⟩⟩ + have hh := family_energy_cell_bound (fun i : S => (i : Cell)) Subtype.val_injective q x + (fun _ => rfl) ht ha hR hs + have hn : 0 ≤ (t ^ 2 / 8 - (2197 * t * bumpIntegral⁻¹ * ∑' n, a n) / 2) * + (∑ i, occupation q i ^ 2) := + mul_nonneg (sub_nonneg.mpr hcoerc) (Finset.sum_nonneg (fun i _ => sq_nonneg _)) + change -(t ^ 2 / 2 * (N : ℝ)) ≤ _ + linarith + +theorem decay_familyPotential {t : ℝ} {a R : ℕ → ℝ} (ht : 1 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hw : Summable (fun n => a n * R n ^ (1 / 32 : ℝ))) : + AlgebraicDecayWith (familyPotential t a R) + (t ^ 2 * (2 : ℝ) ^ (3 + 1 / 32 : ℝ) + + t * bumpIntegral⁻¹ * (∑' n, a n * R n ^ (1 / 32 : ℝ))) := by + intro r hr + have ht0 := zero_le_one.trans ht + have hr0 : 0 < (r : ℝ) := lt_of_lt_of_le zero_lt_one hr + have hd := attractionProfile_decay ha hR hs (show (0 : ℝ) ≤ 1 / 32 by norm_num) hw hr + have hc : coreReal t r ≤ t ^ 2 * (2 : ℝ) ^ (3 + 1 / 32 : ℝ) * + (r : ℝ) ^ (-(3 + 1 / 32 : ℝ)) := by + by_cases hrr : 2 ≤ (r : ℝ) + · have hinv : 1 / t ≤ 1 := by simpa using inv_le_one_of_one_le₀ ht + rw [coreReal_zero_outer (lt_of_lt_of_le zero_lt_one ht) (by linarith)] + positivity + · have hpow : (2 : ℝ) ^ (-(3 + 1 / 32 : ℝ)) ≤ + (r : ℝ) ^ (-(3 + 1 / 32 : ℝ)) := + Real.rpow_le_rpow_of_nonpos hr0 (le_of_not_ge hrr) (by norm_num) + calc + _ ≤ t ^ 2 := coreReal_le _ _ + _ = t ^ 2 * (2 : ℝ) ^ (3 + 1 / 32 : ℝ) * (2 : ℝ) ^ (-(3 + 1 / 32 : ℝ)) := by + rw [mul_assoc, ← Real.rpow_add (by norm_num : (0 : ℝ) < 2)] + simp + _ ≤ _ := mul_le_mul_of_nonneg_left hpow (by positivity) + have hab := abs_sub (coreReal t (r : ℝ)) (t * attractionProfile a R (r : ℝ)) + rw [abs_of_nonneg (coreReal_nonneg _ _), abs_of_nonneg + (mul_nonneg ht0 (attractionProfile_nonneg ha hR _))] at hab + have hc' := add_le_add hc (mul_le_mul_of_nonneg_left hd ht0) + change |coreReal t (r : ℝ) - t * attractionProfile a R (r : ℝ)| ≤ _ + have heq : -(3 : ℝ) - 1 / 32 = -(3 + 1 / 32 : ℝ) := by ring + rw [heq] + convert (le_trans hab hc') using 1; first | rfl | (ring_nf; rfl) + +def cubeCells (L : ℝ) : Finset Cell := + Fintype.piFinset (fun _ => Finset.Icc 0 ⌊4 * L⌋) + +theorem cellOf_mem_cubeCells {L : ℝ} {x : Position} (hx : x ∈ cube L) : + cellOf x ∈ cubeCells L := by + simp only [cubeCells, Fintype.mem_piFinset, Finset.mem_Icc, cellOf] + intro k + exact ⟨Int.floor_nonneg.mpr (by linarith [(hx k).1]), Int.floor_mono (by linarith [(hx k).2])⟩ + +theorem card_cubeCells {L : ℝ} (hL : 1 ≤ L) : + ((cubeCells L).card : ℝ) ≤ 216 * L ^ 3 := by + have hf : 0 ≤ ⌊4 * L⌋ := Int.floor_nonneg.mpr (by linarith) + have heq : (cubeCells L).card = (⌊4 * L⌋ + 1).toNat ^ 3 := by + simp [cubeCells, Fintype.card_piFinset, Int.card_Icc] + rw [heq] + have hc : (((⌊4 * L⌋ + 1).toNat : ℕ) : ℝ) = (⌊4 * L⌋ : ℝ) + 1 := by + exact_mod_cast (Int.toNat_of_nonneg (show 0 ≤ ⌊4 * L⌋ + 1 by omega)) + push_cast + rw [hc] + have hb : (⌊4 * L⌋ : ℝ) + 1 ≤ 6 * L := by + have hh := Int.floor_le (4 * L) + linarith + calc + _ ≤ (6 * L) ^ 3 := pow_le_pow_left₀ (by exact_mod_cast (show 0 ≤ ⌊4 * L⌋ + 1 by omega)) hb 3 + _ = _ := by ring + +theorem square_count_le_card_occupation {V : Type uV} {I : Type uI} [Fintype V] [Fintype I] + (q : V → I) : (Fintype.card V : ℝ) ^ 2 ≤ (Fintype.card I : ℝ) * ∑ i, occupation q i ^ 2 := by + rw [← sum_occupation q] + simpa using sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := occupation q) + +theorem family_density_stability {t L : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) (hL : 1 ≤ L) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hcoerc : 2197 * t * bumpIntegral⁻¹ * (∑' n, a n) / 2 ≤ t ^ 2 / 16) + {N : ℕ} (x : Fin N → Position) (hx : x ∈ configurationCube L N) : + t ^ 2 / 3456 * (N : ℝ) ^ 2 / L ^ 3 - t ^ 2 / 2 * N ≤ energy (familyPotential t a R) x := by + classical + let S := cubeCells L + let q : Fin N → S := fun j => ⟨cellOf (x j), cellOf_mem_cubeCells (hx j)⟩ + have hh := family_energy_cell_bound (fun i : S => (i : Cell)) Subtype.val_injective q x + (fun _ => rfl) ht ha hR hs + have hsum : 0 ≤ ∑ i, occupation q i ^ 2 := Finset.sum_nonneg (fun i _ => sq_nonneg _) + have hn := square_count_le_card_occupation q + have hcard : (Fintype.card S : ℝ) ≤ 216 * L ^ 3 := by + simpa using card_cubeCells hL + have hn' := hn.trans (mul_le_mul_of_nonneg_right hcard hsum) + have hL0 : 0 < L ^ 3 := pow_pos (lt_of_lt_of_le zero_lt_one hL) _ + have hocc : (N : ℝ) ^ 2 / (216 * L ^ 3) ≤ ∑ i, occupation q i ^ 2 := by + apply (div_le_iff₀ (mul_pos (by norm_num) hL0)).mpr + simpa only [Fintype.card_fin, mul_comm] using hn' + have hocc' := mul_le_mul_of_nonneg_left hocc (show 0 ≤ t ^ 2 / 16 by positivity) + have heq : t ^ 2 / 16 * ((N : ℝ) ^ 2 / (216 * L ^ 3)) = + t ^ 2 / 3456 * (N : ℝ) ^ 2 / L ^ 3 := by ring + rw [heq] at hocc' + nlinarith [mul_nonneg (show 0 ≤ t ^ 2 / 16 - 2197 * t * bumpIntegral⁻¹ * (∑' n, a n) / 2 by linarith) hsum] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/LinearInteractions.lean b/lean/OAI/Probability/RadialTransition/LinearInteractions.lean new file mode 100644 index 0000000000000000000000000000000000000000..b578cf73951030169ca3dd0d4a85138d32811937 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/LinearInteractions.lean @@ -0,0 +1,92 @@ +import OAI.Probability.RadialTransition.BoxPressure + +namespace OAI + +universe uI uX uY uZ + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff BigOperators ENNReal NNReal + +namespace RadialTransition + +lemma zero_ite_add (p : Prop) [Decidable p] (a b : ℝ) : + (if p then 0 else a+b) = (if p then 0 else a)+(if p then 0 else b) := by split_ifs <;> ring + +section LinearPair +variable {I : Type uI} [Fintype I] [DecidableEq I] {X : I → Type uX} + +lemma pairWithin_add {Y : Type uY} (v w : Y → Y → ℝ) (s : ParticleState Y) : + pairWithin (fun x y => v x y+w x y) s = pairWithin v s+pairWithin w s := by + dsimp only [pairWithin] + simp only [zero_ite_add, Finset.sum_add_distrib, mul_add] + +lemma pairBetween_add {Y : Type uY} {Z : Type uZ} (v w : Y → Z → ℝ) (s : ParticleState Y) (t : ParticleState Z) : + pairBetween (fun x y => v x y+w x y) s t = pairBetween v s t+pairBetween w s t := by + simp only [pairBetween, Finset.sum_add_distrib] + +lemma pairCellEnergy_add (v w : ∀ i j, X i → X j → ℝ) (x : ∀ i, ParticleState (X i)) : + pairCellEnergy (fun i j a b => v i j a b+w i j a b) x = pairCellEnergy v x+pairCellEnergy w x := by + dsimp only [pairCellEnergy, cellHamiltonian] + simp only [pairWithin_add, pairBetween_add, zero_ite_add, Finset.sum_add_distrib, mul_add] + ring + +lemma pairCellEnergy_diagonal (v : ∀ i j, X i → X j → ℝ) (x : ∀ i, ParticleState (X i)) : + pairCellEnergy (fun i j a b => if i = j then v i j a b else 0) x = ∑ i, pairWithin (v i i) (x i) := by + unfold pairCellEnergy cellHamiltonian + simp only [ite_true] + have hcross (i j : I) : (if i = j then 0 else pairBetween (fun a b => if i = j then v i j a b else 0) (x i) (x j)) = 0 := by + split_ifs <;> simp only [pairBetween, Finset.sum_const_zero] + simp only [hcross, Finset.sum_const_zero, mul_zero, add_zero] + +end LinearPair + +def singleAttraction (R lam : ℝ) : Potential := fun r => -lam*scaledBumpProfile R r + +lemma continuous_singleAttraction (R lam : ℝ) : Continuous (singleAttraction R lam) := + continuous_const.mul ((continuous_scaledBumpProfile R).comp NNReal.continuous_coe) + +lemma radialPair_singleAttraction {R : ℝ} (hR : 0 < R) (lam : ℝ) (x y : Position) : + radialPair (singleAttraction R lam) x y = -lam*scaledBump R (x-y) := by + rw [scaledBump_radial hR] + rfl + +lemma deletedPair_macro_energy {φ : Potential} {m q : ℕ} {R : ℝ} (hR : 0 < R) (lam : ℝ) (x : MacroState m q) : + pairCellEnergy (fun i j : GridIndex m => fun (a : macroRegion q (gridEmbed i)) (b : macroRegion q (gridEmbed j)) => + deletedPair (macroOf q) φ (singleAttraction R lam) a b) x = macroKacEnergy φ m q R lam x := by + classical + have he : (fun i j : GridIndex m => fun (a : macroRegion q (gridEmbed i)) (b : macroRegion q (gridEmbed j)) => + deletedPair (macroOf q) φ (singleAttraction R lam) a b) = + (fun i j : GridIndex m => fun (a : macroRegion q (gridEmbed i)) (b : macroRegion q (gridEmbed j)) => + (if i = j then radialPair φ a b else 0)+(-lam*scaledBump R ((a:Position)-(b:Position)))) := by + funext i j a b + have ha : macroOf q (cellOf (a:Position)) = gridEmbed i := a.property + have hb : macroOf q (cellOf (b:Position)) = gridEmbed j := b.property + simp only [deletedPair, ha, hb, radialPair_singleAttraction hR, (gridEmbed_injective m).eq_iff] + rw [he, pairCellEnergy_add, pairCellEnergy_diagonal, pairCellEnergy_smul] + simp only [macroKacEnergy, neg_mul, sub_eq_add_neg] + +lemma deletedPair_macroKac {m q : ℕ} (hq : 0 < q) + {φ : Potential} (hφ : Continuous φ) {R : ℝ} (hR : 0 < R) (lam β z : ℝ) : + pairGrand (deletedPair (macroOf q) φ (singleAttraction R lam)) (volume.restrict (halfCube (((m:ℝ)*q)/4))) β z = + boltzmannPartition (macroMeasure m q z) (fun x => β*macroKacEnergy φ m q R lam x) := by + let X (i : GridIndex m) := macroRegion q (gridEmbed i) + let ν (i : GridIndex m) := regionMeasure (X i) + let : ∀ i, IsFiniteMeasure (ν i) := fun i => regionMeasure_finite (measurableSet_macroRegion _ _) + (by rw [volume_macroRegion hq]; finiteness) + have hh := pairGrand_eq_cell (fun i : GridIndex m => ↥(X i)) ν (fun _ => Subtype.val) + (fun _ => measurable_subtype_coe) (deletedPair (macroOf q) φ (singleAttraction R lam)) + (measurable_deletedPair _ hφ (continuous_singleAttraction R lam)) (deletedPair_symm _ _ _) + (macroRegion_partition (m := m) hq) β z + exact hh.trans (congrArg (boltzmannPartition (macroMeasure m q z)) (by + funext x + exact congrArg (β*·) (deletedPair_macro_energy hR lam x))) + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MacroLower.lean b/lean/OAI/Probability/RadialTransition/MacroLower.lean new file mode 100644 index 0000000000000000000000000000000000000000..e35012cd0b2cdb437155a006a12ac094e8726af1 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MacroLower.lean @@ -0,0 +1,87 @@ +import OAI.Probability.RadialTransition.MacroUpper + +namespace OAI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff BigOperators ENNReal NNReal + +namespace RadialTransition + +def kernelInterior (m q : ℕ) (R : ℝ) : Finset (GridIndex m) := + Finset.univ \ boundaryGrid m (cellMargin (R/q+1)).toNat + +lemma macroKernelLower_total {q m : ℕ} (hq : 0 < q) {R : ℝ} (hR : (q:ℝ)/4 ≤ R) : + (kernelInterior m q R).card*(1-kernelRowError q R)/((q:ℝ)/4)^3 ≤ + ∑ i : GridIndex m, ∑ j : GridIndex m, if i = j then 0 else macroKernelLower q R (gridEmbed i) (gridEmbed j) := by + classical + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + let row (i : GridIndex m) := ∑ j : GridIndex m, if i = j then 0 else macroKernelLower q R (gridEmbed i) (gridEmbed j) + calc + _ = ∑ i ∈ kernelInterior m q R, (1-kernelRowError q R)/((q:ℝ)/4)^3 := by simp only [Finset.sum_const, nsmul_eq_mul]; ring + _ ≤ ∑ i ∈ kernelInterior m q R, row i := by + apply Finset.sum_le_sum + intro i hi + apply (div_le_iff₀ (by positivity : 0 < ((q:ℝ)/4)^3)).mpr + rw [mul_comm] + exact macroKernelLower_row hq hR i (Finset.mem_sdiff.mp hi).2 + _ ≤ ∑ i, row i := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ _) + intro i hi hnot + exact Finset.sum_nonneg (fun j _ => by split_ifs; rfl; exact macroKernelLower_nonneg _ _ _ _) + +lemma macro_attraction_lower {q m n : ℕ} (hq : 0 < q) {R : ℝ} (hR : (q:ℝ)/4 ≤ R) + (x : ∀ i : GridIndex m, ParticleState (macroRegion q (gridEmbed i))) (hx : ∀ i, particleCount (x i) = n) : + (kernelInterior m q R).card*(1-kernelRowError q R)*(n:ℝ)^2/(2*((q:ℝ)/4)^3) ≤ + pairCellEnergy (fun i j (y : macroRegion q (gridEmbed i)) (z : macroRegion q (gridEmbed j)) => scaledBump R ((y:Position)-(z:Position))) x := by + classical + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hR0 : 0 < R := lt_of_lt_of_le (by positivity) hR + have hh := pairCellEnergy_lower_cross + (fun i j (y : macroRegion q (gridEmbed i)) (z : macroRegion q (gridEmbed j)) => scaledBump R ((y:Position)-(z:Position))) + (fun i j => macroKernelLower q R (gridEmbed i) (gridEmbed j)) + (fun i a b => scaledBump_nonneg hR0 _) (fun i j a b => (macroKernel_pair_bounds hq hR0 a.property b.property).1) x + simp only [hx] at hh + have he (i j : GridIndex m) : (if i = j then (0:ℝ) else macroKernelLower q R (gridEmbed i) (gridEmbed j)*(n:ℝ)*n) = + (n:ℝ)^2*(if i = j then 0 else macroKernelLower q R (gridEmbed i) (gridEmbed j)) := by split_ifs <;> ring + simp_rw [he, ← Finset.mul_sum] at hh + have ht := mul_le_mul_of_nonneg_left (macroKernelLower_total (m := m) hq hR) (sq_nonneg (n:ℝ)) + calc + _ = (1/2:ℝ)*((n:ℝ)^2*((kernelInterior m q R).card*(1-kernelRowError q R)/((q:ℝ)/4)^3)) := by ring + _ ≤ _ := by linarith + +abbrev MacroState (m q : ℕ) := ∀ i : GridIndex m, ParticleState (macroRegion q (gridEmbed i)) + +def macroKacEnergy (φ : Potential) (m q : ℕ) (R lam : ℝ) (x : MacroState m q) : ℝ := + (∑ i, pairWithin (fun (y z : macroRegion q (gridEmbed i)) => radialPair φ y z) (x i)) - + lam*pairCellEnergy (fun i j (y : macroRegion q (gridEmbed i)) (z : macroRegion q (gridEmbed j)) => scaledBump R ((y:Position)-(z:Position))) x + +lemma measurable_macroKacEnergy {φ : Potential} (hφ : Continuous φ) (m q : ℕ) (R lam : ℝ) : + Measurable (macroKacEnergy φ m q R lam) := by + apply Measurable.sub + · apply Finset.measurable_sum + intro i hi + exact (measurable_pairWithin _ (continuous_radialPair_comp hφ continuous_subtype_val continuous_subtype_val).measurable).comp (measurable_pi_apply i) + · apply measurable_const.mul + apply measurable_pairCellEnergy + intro i j + exact ((continuous_scaledBump R).comp ((continuous_subtype_val.comp continuous_fst).sub (continuous_subtype_val.comp continuous_snd))).measurable + +lemma macroKacEnergy_lower {φ : Potential} {q m : ℕ} (hq : 0 < q) {R lam : ℝ} + (hR : (q:ℝ)/4 ≤ R) (hlam : 0 ≤ lam) (x : MacroState m q) : + (∑ i : GridIndex m, (pairWithin (fun (y z : macroRegion q (gridEmbed i)) => radialPair φ y z) (x i) - + lam*(1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3)*(particleCount (x i):ℝ)^2)) ≤ + macroKacEnergy φ m q R lam x := by + have hh := mul_le_mul_of_nonneg_left (macro_attraction_upper hq hR x) hlam + unfold macroKacEnergy + simp only [Finset.sum_sub_distrib, ← Finset.mul_sum] + simpa only [mul_div_assoc, mul_assoc] using sub_le_sub_left hh (∑ i : GridIndex m, pairWithin (fun (y z : macroRegion q (gridEmbed i)) => radialPair φ y z) (x i)) + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MacroRegions.lean b/lean/OAI/Probability/RadialTransition/MacroRegions.lean new file mode 100644 index 0000000000000000000000000000000000000000..8bee488125d792afe132204957c6ff0dfcd1ba60 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MacroRegions.lean @@ -0,0 +1,170 @@ +import OAI.Probability.RadialTransition.BoxEnsembles + +namespace OAI + +universe uX uY + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +def macroRegion (q : ℕ) (k : Cell) : Set Position := {x | macroOf q (cellOf x) = k} + +def macroOrigin (q : ℕ) (k : Cell) : Position := WithLp.toLp 2 (fun d => (q:ℝ)*(k d:ℝ)/4) + +lemma measurableSet_macroRegion (q : ℕ) (k : Cell) : MeasurableSet (macroRegion q k) := by + exact (Set.to_countable {i : Cell | macroOf q i = k}).measurableSet.preimage measurable_cellOf + +lemma macroRegion_translate {q : ℕ} (hq : 0 < q) (k : Cell) : + macroRegion q k = translateSet (macroOrigin q k) (halfCube ((q:ℝ)/4)) := by + ext x + have hq' : (0:ℤ) < q := by exact_mod_cast hq + constructor + · intro hx d + have hd : cellOf x d / (q:ℤ) = k d := congrFun hx d + have hb := (Int.ediv_eq_iff_of_pos hq').mp hd + have hl := Int.floor_le (4*x d) + have hu := Int.lt_floor_add_one (4*x d) + have hbl : ((k d:ℤ)*(q:ℤ):ℝ) ≤ (⌊4*x d⌋:ℝ) := by exact_mod_cast hb.1 + have hbu : (⌊4*x d⌋:ℝ)+1 ≤ ((k d:ℤ)*(q:ℤ)+(q:ℤ):ℝ) := by exact_mod_cast hb.2 + change 0 ≤ x d-(q:ℝ)*(k d:ℝ)/4 ∧ x d-(q:ℝ)*(k d:ℝ)/4 < (q:ℝ)/4 + push_cast at hbl hbu + constructor <;> linarith + · intro hx + funext d + apply (Int.ediv_eq_iff_of_pos hq').mpr + have hd : 0 ≤ x d-(q:ℝ)*(k d:ℝ)/4 ∧ x d-(q:ℝ)*(k d:ℝ)/4 < (q:ℝ)/4 := hx d + constructor + · apply Int.le_floor.mpr + push_cast + linarith + · apply Int.floor_lt.mpr + push_cast + linarith + +lemma volume_macroRegion {q : ℕ} (hq : 0 < q) (k : Cell) : + volume (macroRegion q k) = ENNReal.ofReal ((q:ℝ)/4)^3 := by + rw [macroRegion_translate hq, volume_translateSet _ _ (measurableSet_halfCube _), volume_halfCube] + +lemma macroRegion_subset_halfCube {m q : ℕ} (hq : 0 < q) (i : GridIndex m) : + macroRegion q (gridEmbed i) ⊆ halfCube (((m:ℝ)*q)/4) := by + intro x hx + rw [macroRegion_translate hq] at hx + intro d + have hd : 0 ≤ x d-(q:ℝ)*(i d:ℝ)/4 ∧ x d-(q:ℝ)*(i d:ℝ)/4 < (q:ℝ)/4 := hx d + have hi : (i d:ℝ)+1 ≤ (m:ℝ) := by exact_mod_cast (i d).isLt + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hin : (0:ℝ) ≤ (i d:ℝ) := by positivity + constructor <;> nlinarith + +lemma halfCube_macro_cover {m q : ℕ} (hq : 0 < q) (x : Position) + (hx : x ∈ halfCube (((m:ℝ)*q)/4)) : ∃ i : GridIndex m, macroOf q (cellOf x) = gridEmbed i := by + obtain ⟨k,hk⟩ := halfCube_grid_cover (m*q) x (by simpa only [Nat.cast_mul] using hx) + obtain ⟨⟨i,j⟩,he⟩ := blockEmbed_surjective hq k + refine ⟨i, ?_⟩ + rw [hk, ← he, blockEmbed_macro hq] + +lemma halfCube_macro_union {m q : ℕ} (hq : 0 < q) : + (⋃ i : GridIndex m, macroRegion q (gridEmbed i)) = halfCube (((m:ℝ)*q)/4) := by + ext x + simp only [mem_iUnion] + exact ⟨fun ⟨i,hi⟩ => macroRegion_subset_halfCube hq i hi, + fun hx => halfCube_macro_cover hq x hx⟩ + +def regionMeasure (A : Set Position) : Measure A := volume.comap Subtype.val + +lemma regionMeasure_map {A : Set Position} (hA : MeasurableSet A) : + Measure.map Subtype.val (regionMeasure A) = volume.restrict A := map_comap_subtype_coe hA volume + +lemma regionMeasure_univ {A : Set Position} (hA : MeasurableSet A) : + regionMeasure A univ = volume A := by + rw [regionMeasure, comap_subtype_coe_apply hA] + simp only [Set.image_univ, Subtype.range_coe] + +lemma regionMeasure_finite {A : Set Position} (hA : MeasurableSet A) (hAfin : volume A ≠ ⊤) : + IsFiniteMeasure (regionMeasure A) := ⟨by rw [regionMeasure_univ hA]; exact lt_top_iff_ne_top.mpr hAfin⟩ + +lemma macroRegion_partition {m q : ℕ} (hq : 0 < q) : + volume.restrict (halfCube (((m:ℝ)*q)/4)) = + ∑ i : GridIndex m, Measure.map Subtype.val (regionMeasure (macroRegion q (gridEmbed i))) := by + have hd : Pairwise (fun i j : GridIndex m => Disjoint (macroRegion q (gridEmbed i)) (macroRegion q (gridEmbed j))) := by + intro i j hij + apply Set.disjoint_left.mpr + intro x hx hy + exact hij (gridEmbed_injective m (hx.symm.trans hy)) + rw [← halfCube_macro_union hq, Measure.restrict_iUnion hd (fun i => measurableSet_macroRegion _ _), Measure.sum_fintype] + apply Finset.sum_congr rfl + intro i _ + exact (regionMeasure_map (measurableSet_macroRegion _ _)).symm + +section MapGrand +variable {X : Type uX} {Y : Type uY} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] + [TopologicalSpace Y] [MeasurableSpace Y] [BorelSpace Y] [SecondCountableTopology Y] + +omit [BorelSpace X] [SecondCountableTopology X] in +lemma pairGrand_within (v : X → X → ℝ) (μ : Measure X) (β z : ℝ) : + pairGrand v μ β z = boltzmannPartition (particleBase μ z) (fun x => β*pairWithin v x) := by + simp only [pairGrand, boltzmannPartition, multisetEnergy_particle, neg_mul] + +lemma pairGrand_map (v : Y → Y → ℝ) (hv : Measurable (Function.uncurry v)) + (μ : Measure X) [IsFiniteMeasure μ] (f : X → Y) (hf : Measurable f) (β z : ℝ) : + pairGrand v (Measure.map f μ) β z = pairGrand (fun x y => v (f x) (f y)) μ β z := by + simp only [pairGrand_within, boltzmannPartition] + have hfun : AEStronglyMeasurable (fun y : ParticleState Y => Real.exp (-(β*pairWithin v y))) + (Measure.map (mapParticle f) (particleBase μ z)) := + (Real.measurable_exp.comp ((measurable_const.mul (measurable_pairWithin v hv)).neg)).aestronglyMeasurable + rw [← particleBase_map μ z hf, integral_map (measurable_mapParticle hf).aemeasurable hfun] + rfl +end MapGrand + +lemma grandOn_halfCube {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B β : ℝ} (hs : StableWith φ B) (hβ : 0 ≤ β) (L z : ℝ) : + grandOn φ (halfCube L) β z = grandOn φ (cube L) β z := by + rw [← pairGrand_radial hφ hb hs hβ (by rw [volume_halfCube]; finiteness), + ← pairGrand_radial hφ hb hs hβ (by rw [volume_cube]; finiteness), restrict_halfCube] + +lemma deletedPair_macro_factorization {m q : ℕ} (hq : 0 < q) + {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B β : ℝ} (hs : StableWith φ B) (hβ : 0 ≤ β) (z : ℝ) : + pairGrand (deletedPair (macroOf q) φ 0) (volume.restrict (halfCube (((m:ℝ)*q)/4))) β z = + (grandOn φ (cube ((q:ℝ)/4)) β z)^(m^3) := by + let X (i : GridIndex m) := macroRegion q (gridEmbed i) + let ν (i : GridIndex m) := regionMeasure (X i) + let : ∀ i, IsFiniteMeasure (ν i) := fun i => regionMeasure_finite (measurableSet_macroRegion _ _) + (by rw [volume_macroRegion hq]; finiteness) + let pos : ∀ i, X i → Position := fun _ => Subtype.val + have hp (i : GridIndex m) : Measurable (pos i) := measurable_subtype_coe + let v : ∀ i j, X i → X j → ℝ := fun i j x y => deletedPair (macroOf q) φ 0 (pos i x) (pos j y) + have hcross (i j : GridIndex m) (hij : i ≠ j) (x : X i) (y : X j) : v i j x y = 0 := by + have hx : macroOf q (cellOf (pos i x)) = gridEmbed i := x.property + have hy : macroOf q (cellOf (pos j y)) = gridEmbed j := y.property + have hn : gridEmbed i ≠ gridEmbed j := fun h => hij (gridEmbed_injective m h) + simp only [v, deletedPair, hx, hy, hn, ite_false, radialPair, Pi.zero_apply, add_zero] + have hintra (i : GridIndex m) : v i i = fun x y => radialPair φ (pos i x) (pos i y) := by + funext x y + have hx : macroOf q (cellOf (pos i x)) = gridEmbed i := x.property + have hy : macroOf q (cellOf (pos i y)) = gridEmbed i := y.property + simp only [v, deletedPair, hx, hy, ite_true, radialPair, Pi.zero_apply, add_zero] + have hdecomp : volume.restrict (halfCube (((m:ℝ)*q)/4)) = + ∑ i : GridIndex m, Measure.map (pos i) (ν i) := macroRegion_partition (m := m) hq + have hfactor := pairGrand_eq_cell (fun i : GridIndex m => ↥(X i)) ν pos hp (deletedPair (macroOf q) φ 0) (measurable_deletedPair (macroOf q) hφ (show Continuous (0 : Potential) from continuous_const)) + (deletedPair_symm _ _ _) hdecomp β z + rw [hfactor, boltzmannPartition_no_cross ν v hcross] + have he (i : GridIndex m) : boltzmannPartition (particleBase (ν i) z) (fun x => β*pairWithin (v i i) x) = + grandOn φ (cube ((q:ℝ)/4)) β z := by + rw [hintra, ← pairGrand_within, ← pairGrand_map (radialPair φ) (continuous_radialPair hφ).measurable (ν i) (pos i) (hp i)] + have hmap : Measure.map (pos i) (ν i) = volume.restrict (macroRegion q (gridEmbed i)) := regionMeasure_map (measurableSet_macroRegion _ _) + rw [hmap, pairGrand_radial hφ hb hs hβ (by rw [volume_macroRegion hq]; finiteness), + macroRegion_translate hq, grandOn_translate, grandOn_halfCube hφ hb hs hβ] + simp only [he, Finset.prod_const, Finset.card_univ, Fintype.card_fun, Fintype.card_fin] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MacroUpper.lean b/lean/OAI/Probability/RadialTransition/MacroUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..6ed58a83fef6771486f84680cf8f7642b89964f5 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MacroUpper.lean @@ -0,0 +1,88 @@ +import OAI.Probability.RadialTransition.InteriorGrid + +namespace OAI + +universe uI uX uY + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped BigOperators ENNReal NNReal ContDiff + +namespace RadialTransition +section +variable {I : Type uI} [Fintype I] [DecidableEq I] {X : I → Type uX} + +lemma pairWithin_nonneg {Y : Type uY} (v : Y → Y → ℝ) (hv : ∀ x y, 0 ≤ v x y) (s : ParticleState Y) : + 0 ≤ pairWithin v s := by + unfold pairWithin + exact mul_nonneg (by norm_num) (Finset.sum_nonneg (fun i _ => Finset.sum_nonneg (fun j _ => by split_ifs <;> simp_all))) + +lemma pairCellEnergy_upper (v : ∀ i j, X i → X j → ℝ) (K : I → I → ℝ) (M : ℝ) + (hK : ∀ i j, 0 ≤ K i j) (hKs : ∀ i j, K i j = K j i) + (hrow : ∀ i, ∑ j, K i j ≤ M) + (hv : ∀ i j x y, |v i j x y| ≤ K i j) (x : ∀ i, ParticleState (X i)) : + pairCellEnergy v x ≤ M/2*∑ i, (particleCount (x i):ℝ)^2 := by + have hh := (le_abs_self (pairCellEnergy v x)).trans (pairCellEnergy_abs_bound v K hK hv x) + dsimp only [cellN] at hh + have hr := symmetric_row_quadratic K (fun i => (particleCount (x i):ℝ)) M hK hKs hrow + linarith + +lemma pairCellEnergy_lower_cross (v : ∀ i j, X i → X j → ℝ) (K : I → I → ℝ) + (hn : ∀ i a b, 0 ≤ v i i a b) (hv : ∀ i j a b, K i j ≤ v i j a b) + (x : ∀ i, ParticleState (X i)) : + (1/2:ℝ)*∑ i, ∑ j, (if i = j then 0 else K i j*(particleCount (x i):ℝ)*(particleCount (x j):ℝ)) ≤ + pairCellEnergy v x := by + have hc := Finset.sum_le_sum (s := Finset.univ) (fun (i:I) _ => + Finset.sum_le_sum (s := Finset.univ) (fun (j:I) _ => show + (if i = j then 0 else K i j*(particleCount (x i):ℝ)*(particleCount (x j):ℝ)) ≤ + (if i = j then 0 else pairBetween (v i j) (x i) (x j)) from by + split_ifs + · rfl + · simpa only [neg_neg] using pairBetween_lower (v i j) (J := -K i j) (fun a b => by simpa using hv i j a b) (x i) (x j))) + have hd : 0 ≤ ∑ i, pairWithin (v i i) (x i) := + Finset.sum_nonneg (fun i _ => pairWithin_nonneg _ (hn i) _) + unfold pairCellEnergy cellHamiltonian + linarith + +lemma pairCellEnergy_smul (a : ℝ) (v : ∀ i j, X i → X j → ℝ) (x : ∀ i, ParticleState (X i)) : + pairCellEnergy (fun i j x y => a*v i j x y) x = a*pairCellEnergy v x := by + unfold pairCellEnergy cellHamiltonian pairWithin pairBetween + have hh (i : I) (k l : Fin (x i).1) : + (if k = l then (0:ℝ) else a*v i i ((x i).2 k) ((x i).2 l)) = + a*(if k = l then 0 else v i i ((x i).2 k) ((x i).2 l)) := by split_ifs <;> simp + simp_rw [hh, ← Finset.mul_sum] + have hj (i j:I) : (if i = j then (0:ℝ) else a*∑ k, ∑ l, v i j ((x i).2 k) ((x j).2 l)) = + a*(if i = j then 0 else ∑ k, ∑ l, v i j ((x i).2 k) ((x j).2 l)) := by split_ifs <;> simp + simp_rw [hj, ← Finset.mul_sum] + ring + +end + +lemma macro_attraction_upper {q m : ℕ} (hq : 0 < q) {R : ℝ} (hR : (q:ℝ)/4 ≤ R) + (x : ∀ i : GridIndex m, ParticleState (macroRegion q (gridEmbed i))) : + pairCellEnergy (fun i j (y : macroRegion q (gridEmbed i)) (z : macroRegion q (gridEmbed j)) => scaledBump R ((y:Position)-(z:Position))) x ≤ + (1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3)*∑ i, (particleCount (x i):ℝ)^2 := by + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hR0 : 0 < R := lt_of_lt_of_le (by positivity) hR + have he : (1+10000*(bumpLip:ℝ)*q/R)/(2*((q:ℝ)/4)^3) = + ((1+10000*(bumpLip:ℝ)*q/R)/((q:ℝ)/4)^3)/2 := by ring + rw [he] + apply pairCellEnergy_upper _ (fun i j => macroKernelUpper q R (gridEmbed i) (gridEmbed j)) + · exact fun _ _ => macroKernelUpper_nonneg hR0 _ _ + · exact fun _ _ => macroKernelUpper_symm _ _ _ _ + · intro i + apply (le_div_iff₀ (by positivity : 0 < ((q:ℝ)/4)^3)).mpr + rw [mul_comm] + exact macroKernelUpper_row hq hR _ + · intro i j y z + rw [abs_of_nonneg (scaledBump_nonneg hR0 _)] + exact (macroKernel_pair_bounds hq hR0 y.property z.property).2 + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/Main.lean b/lean/OAI/Probability/RadialTransition/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..f33fe6bc671ac5533e40a1fdb7e8f7f9a52a9940 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/Main.lean @@ -0,0 +1,104 @@ +import OAI.Probability.RadialTransition.InfiniteBall + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal ENNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma canonical_dual_sup {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t β ρ : ℝ} (hstable : StableWith φ B) (ht : 0 < t) (hβ : 0 ≤ β) (hρ : 0 < ρ) + (hc : ∀ r : ℝ≥0, 2 ≤ (r:ℝ) → φ r ≤ 0) + (hlim : ∀ d : ℝ, 0 ≤ d → Tendsto (fun z : ℝ × ℕ => finiteCanonical φ t z.1 z.2 β) + (thermodynamicFilter d) (nhds (canonicalThermo φ t β d))) : + canonicalThermo φ t β ρ = sSup (Set.range fun h : ℝ => h*ρ-grandPressure φ t β h) := by + obtain ⟨h,he,hle⟩ := (canonical_grand_duality hφ hb hstable ht hβ hc hlim).2 ρ hρ + apply le_antisymm + · rw [he] + apply le_csSup + · exact ⟨canonicalThermo φ t β ρ,fun v ⟨j,hj⟩ => hj ▸ hle j⟩ + · exact ⟨h,rfl⟩ + · exact csSup_le (Set.range_nonempty _) (fun v ⟨j,hj⟩ => hj ▸ hle j) + +lemma support_ball_two_pressures {Q : Pressure} {x : Parameter} + (hs : Metric.closedBall targetSlope pressureRadius ⊆ supportSet (onParameters Q) positiveParameters x) : + pressureSupport Q (x 0) (x 1) (17*packingDensity/4-pressureRadius/2) (5*packingDensity/3) ∧ + pressureSupport Q (x 0) (x 1) (17*packingDensity/4+pressureRadius/2) (5*packingDensity/3) := by + have hp := pressureRadius_pos + have hmem (z : ℝ) (hz : |z|≤pressureRadius) : parameter (17*packingDensity/4+z) (5*packingDensity/3) ∈ + Metric.closedBall targetSlope pressureRadius := by + rw [Metric.mem_closedBall,dist_eq_norm,targetSlope,parameter_sub,sub_self] + have he : 17*packingDensity/4+z-17*packingDensity/4=z := by ring + rw [he,parameter_horizontal_norm] + exact hz + have hs₁ := pressureSupport_iff.mpr (hs (hmem (-pressureRadius/2) (by rw [abs_of_nonpos (by linarith)]; linarith))) + have hs₂ := pressureSupport_iff.mpr (hs (hmem (pressureRadius/2) (by rw [abs_of_pos (by positivity)]; linarith))) + simpa only [parameter_zero,parameter_one,sub_eq_add_neg,neg_div] using And.intro hs₁ hs₂ + +lemma family_free_energy {t ρ : ℝ} {a R : ℕ → ℝ} (ht : 1 ≤ t) (hρ : 0 ≤ ρ) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hcoerc : 2197*t*bumpIntegral⁻¹*(∑' n, a n)/2 ≤ t^2/16) : + IsCanonicalFreeEnergy (familyPotential t a R) ρ + (fun β => t*canonicalThermo (familyPotential t a R) t β ρ/β) := by + intro β hβ + have ht0 : 0 < t := by linarith + have hlim := ((familyCanonicalThermo_spec ht ha hR hs hcoerc hβ.le hρ).1.comp + (floor_tendsto_thermodynamicFilter hρ)).const_mul t |>.div_const β + convert hlim using 1 + ext L + dsimp only [Function.comp_apply,finiteCanonical] + field_simp + +theorem main : + ∃ (p : ℝ) (φ : Potential) (B C : ℝ) (f : ℝ → ℝ) (βc : ℝ), + 0 < p ∧ IsPackingDensity p ∧ + IsBoundedPotential φ ∧ Continuous φ ∧ + 0 < B ∧ 0 < C ∧ StableWith φ B ∧ AlgebraicDecayWith φ C ∧ + IsCanonicalFreeEnergy φ (5*p/3) f ∧ + βc ∈ Icc (7/8:ℝ) (9/8) ∧ StrictTemperatureCorner f βc := by + obtain ⟨t,b,ht,hb,hrow,x,hx,hsupport⟩ := exists_family_pressure_ball + have ht0 : 0 < t := by linarith + have had := iteration_admissible hb t + let φ := familyPotential t (iterationMass b) (scaleRange b) + let ρ := 5*packingDensity/3 + have hρ : 0 < ρ := by dsimp [ρ]; have := packingDensity_pos; positivity + have hφ : Continuous φ := continuous_familyPotential had.1 had.2.1 had.2.2.1 t + have hbd : IsBoundedPotential φ := bounded_familyPotential had.1 had.2.1 had.2.2.1 t + have hrow' := admissible_row ht0.le had hrow + have hcoerc : 2197*t*bumpIntegral⁻¹*(∑' n, iterationMass b n)/2 ≤ t^2/16 := by + nlinarith [sq_nonneg t] + have hst : StableWith φ (t^2/2) := stable_family_of_master ht0.le had.1 had.2.1 had.2.2.1 had.2.2.1 (fun _ => le_rfl) hrow' + have hc : ∀ r : ℝ≥0, 2 ≤ (r:ℝ) → φ r ≤ 0 := fun _ hr => familyPotential_nonpos_outer had.1 had.2.1 ht hr + have hlim (β d : ℝ) (hβ : 0≤β) (hd : 0≤d) := (familyCanonicalThermo_spec ht had.1 had.2.1 had.2.2.1 hcoerc hβ hd).1 + let f := fun β => t*canonicalThermo φ t β ρ/β + have hf : IsCanonicalFreeEnergy φ ρ f := family_free_energy ht hρ.le had.1 had.2.1 had.2.2.1 hcoerc + have hβ : 0 < x 0 := phaseWindow_positive (by norm_num) hx + have hβband : x 0 ∈ Icc (7/8:ℝ) (9/8) := by + have hh := abs_le.mp (phaseWindow_coords hx).1 + constructor <;> linarith + have hdual (β : ℝ) (hβ : 0 < β) : canonicalThermo φ t β ρ = + sSup (Set.range fun h : ℝ => h*ρ-grandPressure φ t β h) := + canonical_dual_sup hφ hbd hst ht0 hβ.le hρ hc (fun d hd => hlim β d hβ.le hd) + have hconc : ConcaveOn ℝ (Ioi 0) (fun β => canonicalThermo φ t β ρ) := + canonicalThermo_concave hφ hbd ht0 hρ.le (fun β hβ => hlim β ρ hβ.le hρ.le) + obtain ⟨hs₁,hs₂⟩ := support_ball_two_pressures hsupport + have hcorner : StrictTemperatureCorner f (x 0) := canonical_corner_of_pressure_supports hβ ht0 + (show 17*packingDensity/4-pressureRadius/2 < 17*packingDensity/4+pressureRadius/2 by linarith [pressureRadius_pos]) hdual hconc hs₁ hs₂ + let C := t^2*(2:ℝ)^(3+1/32:ℝ)+t*bumpIntegral⁻¹*(∑' n, iterationMass b n*(scaleRange b n)^(1/32:ℝ)) + have hC : 0 < C := by + have hw0 : 0≤∑' n, iterationMass b n*(scaleRange b n)^(1/32:ℝ) := by + apply tsum_nonneg + intro n + exact mul_nonneg (had.1 n) (Real.rpow_nonneg (scaleRange_pos (by linarith) n).le _) + have hbi := bumpIntegral_pos + dsimp [C] + positivity + exact ⟨packingDensity,φ,t^2/2,C,f,x 0,packingDensity_pos,packingDensity_limit,hbd,hφ, + by positivity,hC,hst,decay_familyPotential ht had.1 had.2.1 had.2.2.1 (iterationMass_weight_summable hb), + hf,hβband,hcorner⟩ + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MeasurableEnergy.lean b/lean/OAI/Probability/RadialTransition/MeasurableEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..4acd5f98b3eed19d9cdf2d0652498446150d5574 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MeasurableEnergy.lean @@ -0,0 +1,50 @@ +import OAI.Probability.RadialTransition.MeasurableProducts + +namespace OAI + +universe uX + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition +section MeasurableEnergy +variable {X : Type uX} [MeasurableSpace X] +lemma measurable_multisetPairing_right {v : X → X → ℝ} + (hv : Measurable (Function.uncurry v)) (s : Multiset X) + {ι : Type} [Fintype ι] : Measurable (fun x : ι → X => multisetPairing v s (configurationMultiset x)) := by + induction s using Multiset.induction_on with + | empty => simp only [multisetPairing_zero_left]; exact measurable_const + | @cons a s ih => + simp only [multisetPairing, Multiset.map_cons, Multiset.sum_cons, sum_map_configuration] at * + exact (Finset.measurable_sum _ (fun i _ => hv.comp (measurable_const.prodMk (measurable_pi_apply i)))).add ih + +lemma measurable_multisetEnergy_configuration {v : X → X → ℝ} + (hv : Measurable (Function.uncurry v)) {ι : Type} [Fintype ι] : + Measurable (fun x : ι → X => multisetEnergy v (configurationMultiset x)) := by + simp only [multisetEnergy, multisetPairing_configuration, multisetDiagonal_configuration] + apply measurable_const.mul + apply Measurable.sub + · exact Finset.measurable_sum _ (fun i _ => Finset.measurable_sum _ + (fun j _ => hv.comp (show Measurable (fun x : ι → X => (x i, x j)) from (measurable_pi_apply i).prodMk (measurable_pi_apply j)))) + · exact Finset.measurable_sum _ (fun i _ => hv.comp (show Measurable (fun x : ι → X => (x i, x i)) from (measurable_pi_apply i).prodMk (measurable_pi_apply i))) + +lemma measurableConfiguration_boltzmann {v : X → X → ℝ} + (hv : Measurable (Function.uncurry v)) (hsym : ∀ x y, v x y = v y x) (β : ℝ) : + MeasurableConfiguration (fun s => ENNReal.ofReal (Real.exp (-β * multisetEnergy v s))) := by + intro s ι _ + simp only [multisetEnergy_add hsym] + exact ENNReal.measurable_ofReal.comp (Real.measurable_exp.comp + (measurable_const.mul ((measurable_const.add (measurable_multisetEnergy_configuration hv)).add + (measurable_multisetPairing_right hv s)))) + +end MeasurableEnergy +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MeasurableFock.lean b/lean/OAI/Probability/RadialTransition/MeasurableFock.lean new file mode 100644 index 0000000000000000000000000000000000000000..d51294bd41bcdf3983d4b6ca1596d1ec98eaa0f0 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MeasurableFock.lean @@ -0,0 +1,235 @@ +import OAI.Probability.RadialTransition.PressureContinuity + +namespace OAI + +universe uX uIndex uY uZ + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition +section MeasurableFock +variable {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] + +lemma measurable_borel_sigma {ι : Type uIndex} [Countable ι] {Y : ι → Type uY} + [∀ i, TopologicalSpace (Y i)] [∀ i, MeasurableSpace (Y i)] [∀ i, BorelSpace (Y i)] + {Z : Type uZ} [MeasurableSpace Z] {f : (Σ i, Y i) → Z} + (hf : ∀ i, Measurable (fun y : Y i => f ⟨i,y⟩)) : + @Measurable _ _ (borel (Σ i, Y i)) _ f := by + let : MeasurableSpace (Σ i, Y i) := borel (Σ i, Y i) + let : BorelSpace (Σ i, Y i) := ⟨rfl⟩ + intro s hs + have he : f ⁻¹' s = ⋃ i : ι, Sigma.mk i '' ((fun x : Y i => f ⟨i,x⟩) ⁻¹' s) := + (iUnion_image_preimage_sigma_mk_eq_self (f ⁻¹' s)).symm + rw [he] + exact MeasurableSet.iUnion (fun i => + (Topology.IsOpenEmbedding.sigmaMk.measurableEmbedding).measurableSet_image.mpr (hf i hs)) + +lemma measurable_particle_prod {Y : Type uY} {Z : Type uZ} + [TopologicalSpace Y] [MeasurableSpace Y] [BorelSpace Y] [SecondCountableTopology Y] + [MeasurableSpace Z] + {f : ParticleState X → ParticleState Y → Z} + (hf : ∀ m n, Measurable (fun p : (Fin m → X) × (Fin n → Y) => f ⟨m,p.1⟩ ⟨n,p.2⟩)) : + Measurable (Function.uncurry f) := by + let : MeasurableSpace (Σ m : ℕ, (Fin m → X) × ParticleState Y) := borel _ + let : BorelSpace (Σ m : ℕ, (Fin m → X) × ParticleState Y) := ⟨rfl⟩ + let e := Homeomorph.sigmaProdDistrib (X := fun m : ℕ => Fin m → X) (Y := ParticleState Y) + have h : Measurable (fun q : Σ m : ℕ, (Fin m → X) × ParticleState Y => + f ⟨q.1,q.2.1⟩ q.2.2) := by + apply measurable_borel_sigma + intro m + let : MeasurableSpace (Σ n : ℕ, (Fin n → Y) × (Fin m → X)) := borel _ + let : BorelSpace (Σ n : ℕ, (Fin n → Y) × (Fin m → X)) := ⟨rfl⟩ + let e' := Homeomorph.sigmaProdDistrib (X := fun n : ℕ => Fin n → Y) (Y := Fin m → X) + have h' : Measurable (fun q : Σ n : ℕ, (Fin n → Y) × (Fin m → X) => + f ⟨m,q.2.2⟩ ⟨q.1,q.2.1⟩) := by + apply measurable_borel_sigma + intro n + exact (hf m n).comp measurable_swap + exact (h'.comp e'.continuous.measurable).comp measurable_swap + exact h.comp e.continuous.measurable + +variable (F : Multiset X → ℝ≥0∞) +def MeasurableConfiguration : Prop := + ∀ (s : Multiset X) (ι : Type) [Fintype ι], Measurable (fun x : ι → X => F (s+configurationMultiset x)) + +lemma measurable_particleObservable (hF : MeasurableConfiguration F) (s : Multiset X) : + Measurable (fun x : ParticleState X => F (s+particleMultiset x)) := by + apply measurable_borel_sigma + intro n + exact hF s (Fin n) + +lemma measurable_particlePairObservable (hF : MeasurableConfiguration F) (s : Multiset X) : + Measurable (fun p : ParticleState X × ParticleState X => F (s+particleMultiset p.1+particleMultiset p.2)) := by + apply measurable_particle_prod (f := fun x y => F (s+particleMultiset x+particleMultiset y)) + intro m n + have hh := (hF s (Fin m ⊕ Fin n)).comp + (show Measurable (fun p : (Fin m → X) × (Fin n → X) => Sum.elim p.1 p.2) from by + apply measurable_pi_iff.mpr + intro i + cases i with + | inl i => exact (measurable_pi_apply i).comp measurable_fst + | inr i => exact (measurable_pi_apply i).comp measurable_snd) + change Measurable (fun p : (Fin m → X) × (Fin n → X) => F (s+configurationMultiset (Sum.elim p.1 p.2))) at hh + simpa only [configurationMultiset_sum, add_assoc, particleMultiset] using hh + +lemma fockIntegral_eq_lintegral_meas (hF : MeasurableConfiguration F) (μ : Measure X) (z : ℝ) (s : Multiset X) : + fockIntegral (fun _ι _ x => F (s+configurationMultiset x)) μ z = + ∫⁻ x, F (s+particleMultiset x) ∂particleBase μ z := by + rw [lintegral_particleBase μ z (measurable_particleObservable F hF s)] + rfl + +lemma particleBase_add_observable_meas (hF : MeasurableConfiguration F) + (μ ν : Measure X) [IsFiniteMeasure μ] [IsFiniteMeasure ν] (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (μ+ν) z) = + ∫⁻ x, ∫⁻ y, F (s+particleMultiset x+particleMultiset y) ∂particleBase ν z ∂particleBase μ z := by + let G (ι : Type) [Fintype ι] (x : ι → X) := F (s+configurationMultiset x) + have hG : ∀ (ι κ : Type) [Fintype ι] [Fintype κ] (e : ι ≃ κ) (x : κ → X), G ι (x ∘ e) = G κ x := by + intros + dsimp [G] + rw [configurationMultiset_equiv] + rw [← fockIntegral_eq_lintegral_meas F hF, fockIntegral_add G hG μ ν z] + have hpair := (measurable_particlePairObservable F hF s) + rw [lintegral_particleBase μ z hpair.lintegral_prod_right] + apply tsum_congr + intro m + simp only [particleMultiset] + have hinner (x : Fin m → X) : + (∫⁻ y : ParticleState X, F (s+configurationMultiset x+configurationMultiset y.2) ∂particleBase ν z) = + ∑' n : ℕ, fockCoeff z n * ∫⁻ y : Fin n → X, F (s+configurationMultiset x+configurationMultiset y) + ∂Measure.pi (fun _ => ν) := + lintegral_particleBase ν z (measurable_particleObservable F hF (s+configurationMultiset x)) + simp_rw [hinner] + rw [lintegral_tsum] + · rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro n + rw [lintegral_const_mul' _ _ (by exact ENNReal.ofReal_ne_top)] + rw [← mul_assoc] + congr 1 + let e := MeasurableEquiv.sumPiEquivProdPi (fun _ : Fin m ⊕ Fin n => X) + have hs : ∀ i : Fin m ⊕ Fin n, SigmaFinite (Sum.elim (fun _ => μ) (fun _ => ν) i) := by + intro i + cases i + · change SigmaFinite μ; infer_instance + · change SigmaFinite ν; infer_instance + have hp := measurePreserving_sumPiEquivProdPi_symm (Sum.elim (fun _ : Fin m => μ) (fun _ : Fin n => ν)) + rw [← hp.lintegral_comp (hF s (Fin m ⊕ Fin n))] + change (∫⁻ p : (Fin m → X) × (Fin n → X), F (s+configurationMultiset (Sum.elim p.1 p.2)) + ∂(Measure.pi (fun _ => μ)).prod (Measure.pi (fun _ => ν))) = _ + have hmeas : Measurable (fun p : (Fin m → X) × (Fin n → X) => F (s+configurationMultiset (Sum.elim p.1 p.2))) := + (hF s (Fin m ⊕ Fin n)).comp e.symm.measurable + rw [lintegral_prod _ hmeas.aemeasurable] + apply lintegral_congr + intro x + apply lintegral_congr + intro y + dsimp [G] + rw [configurationMultiset_sum, add_assoc] + · intro n + apply Measurable.aemeasurable + apply Measurable.const_mul + have hh := (hF s (Fin m ⊕ Fin n)).comp + (show Measurable (fun p : (Fin m → X) × (Fin n → X) => Sum.elim p.1 p.2) from by + apply measurable_pi_iff.mpr + intro i + cases i with + | inl i => exact (measurable_pi_apply i).comp measurable_fst + | inr i => exact (measurable_pi_apply i).comp measurable_snd) + change Measurable (fun p : (Fin m → X) × (Fin n → X) => F (s+configurationMultiset (Sum.elim p.1 p.2))) at hh + simp only [configurationMultiset_sum, ← add_assoc] at hh + exact hh.lintegral_prod_right + +end MeasurableFock +section MeasurableMultiObservable +variable {I : Type} [Fintype I] {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] + [BorelSpace X] [SecondCountableTopology X] +omit [TopologicalSpace X] [BorelSpace X] [SecondCountableTopology X] in +lemma measurable_multiParticle_fixed (F : Multiset X → ℝ≥0∞) + (hF : MeasurableConfiguration F) (s : Multiset X) (n : I → ℕ) : + Measurable (fun x : ∀ i, Fin (n i) → X => F (s+∑ i, configurationMultiset (x i))) := by + have hh := (hF s (Σ i, Fin (n i))).comp + (show Measurable (fun x : ∀ i, Fin (n i) → X => fun p : Σ i, Fin (n i) => x p.1 p.2) from + measurable_pi_iff.mpr (fun p => (measurable_pi_apply p.2).comp (measurable_pi_apply p.1))) + simpa only [Function.comp_def, configurationMultiset, Fintype.sum_sigma] using hh + +omit [MeasurableSpace X] [BorelSpace X] in +lemma measurable_configurationsInverse : + @Measurable (I → ParticleState X) (Σ n : I → ℕ, ∀ i, Fin (n i) → X) + _ (borel _) (configurationsEquiv (fun _ : I => X)).symm := by + let : MeasurableSpace (Σ n : I → ℕ, ∀ i, Fin (n i) → X) := borel _ + let : BorelSpace (Σ n : I → ℕ, ∀ i, Fin (n i) → X) := ⟨rfl⟩ + exact (configurationsHomeomorph (fun _ : I => X)).symm.continuous.measurable + +lemma measurable_multiParticleObservable (F : Multiset X → ℝ≥0∞) + (hF : MeasurableConfiguration F) (s : Multiset X) : + Measurable (fun x : I → ParticleState X => F (s+multiParticleMultiset x)) := by + let : MeasurableSpace (Σ n : I → ℕ, ∀ i, Fin (n i) → X) := borel _ + let : BorelSpace (Σ n : I → ℕ, ∀ i, Fin (n i) → X) := ⟨rfl⟩ + have hc : Measurable (fun x : Σ n : I → ℕ, ∀ i, Fin (n i) → X => + F (s+∑ i, configurationMultiset (x.2 i))) := + measurable_borel_sigma (fun n => measurable_multiParticle_fixed F hF s n) + change Measurable ((fun x : Σ n : I → ℕ, ∀ i, Fin (n i) → X => + F (s+∑ i, configurationMultiset (x.2 i))) ∘ (configurationsEquiv (fun _ : I => X)).symm) + exact hc.comp (measurable_configurationsInverse (I := I) (X := X)) + +end MeasurableMultiObservable +section FiniteFock +variable {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [SecondCountableTopology X] +variable (F : Multiset X → ℝ≥0∞) (hF : MeasurableConfiguration F) +include hF + +lemma particleBase_zero_observable_meas (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (0 : Measure X) z) = F s := by + rw [lintegral_particleBase _ _ (measurable_particleObservable F hF s)] + rw [tsum_eq_single 0] + · simp [particleMultiset, configurationMultiset] + · intro n hn + have hμ : Measure.pi (fun _ : Fin n => (0 : Measure X)) = 0 := by + apply Measure.measure_univ_eq_zero.mp + rw [Measure.pi_univ] + simp [hn] + rw [hμ, lintegral_zero_measure, mul_zero] + +lemma particleBase_fin_sum_observable_meas (n : ℕ) (μ : Fin n → Measure X) + [∀ i, IsFiniteMeasure (μ i)] (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (∑ i, μ i) z) = + ∫⁻ x, F (s+multiParticleMultiset x) ∂Measure.pi (fun i => particleBase (μ i) z) := by + induction n generalizing s with + | zero => + simp only [Fin.sum_univ_zero] + rw [particleBase_zero_observable_meas F hF] + simp [multiParticleMultiset] + | succ n ih => + rw [Fin.sum_univ_succ, particleBase_add_observable_meas F hF] + simp_rw [ih] + let e := MeasurableEquiv.piFinSuccAbove (fun _ : Fin (n+1) => ParticleState X) 0 + have hp := MeasurePreserving.symm e + (measurePreserving_piFinSuccAbove (fun i => particleBase (μ i) z) 0) + have hc := (measurable_multiParticleObservable F hF s (I := Fin (n+1))) + rw [← hp.lintegral_comp hc] + change _ = ∫⁻ p : ParticleState X × (Fin n → ParticleState X), + F (s+multiParticleMultiset (e.symm p)) + ∂(particleBase (μ 0) z).prod (Measure.pi (fun i => particleBase (μ i.succ) z)) + have hpmeas : Measurable (fun p : ParticleState X × (Fin n → ParticleState X) => + F (s+multiParticleMultiset (e.symm p))) := hc.comp e.symm.measurable + rw [lintegral_prod _ hpmeas.aemeasurable] + apply lintegral_congr + intro x + apply lintegral_congr + intro y + congr 1 + simp [multiParticleMultiset, Fin.sum_univ_succ, e, + MeasurableEquiv.piFinSuccAbove_symm_apply, add_assoc] + +end FiniteFock +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MeasurableProducts.lean b/lean/OAI/Probability/RadialTransition/MeasurableProducts.lean new file mode 100644 index 0000000000000000000000000000000000000000..ac33c3a307e30b74891f8a9141d00347d4964923 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MeasurableProducts.lean @@ -0,0 +1,54 @@ +import OAI.Probability.RadialTransition.MeasurableFock + +namespace OAI + +universe uX uY + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition +section GeneralFock +variable {I : Type} [Fintype I] {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] + [BorelSpace X] [SecondCountableTopology X] + +lemma particleBase_sum_observable_meas (F : Multiset X → ℝ≥0∞) (hF : MeasurableConfiguration F) + (μ : I → Measure X) [∀ i, IsFiniteMeasure (μ i)] (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (∑ i, μ i) z) = + ∫⁻ x, F (s+multiParticleMultiset x) ∂Measure.pi (fun i => particleBase (μ i) z) := by + let e := (Fintype.equivFin I).symm + have hs : (∑ i, μ i) = ∑ j, μ (e j) := (e.sum_comp μ).symm + rw [hs, particleBase_fin_sum_observable_meas F hF] + have hp := measurePreserving_piCongrLeft (fun i => particleBase (μ i) z) e + rw [← hp.lintegral_comp (measurable_multiParticleObservable F hF s)] + apply lintegral_congr + intro x + congr 1 + dsimp [multiParticleMultiset, MeasurableEquiv.piCongrLeft] + simpa [Equiv.piCongrLeft] using + congrArg (fun q => s+q) (e.sum_comp (fun i => particleMultiset (x (e.symm i)))) + +variable (Y : I → Type uY) [∀ i, TopologicalSpace (Y i)] [∀ i, MeasurableSpace (Y i)] + [∀ i, BorelSpace (Y i)] [∀ i, SecondCountableTopology (Y i)] + +lemma particleBase_sum_map_observable_meas (F : Multiset X → ℝ≥0∞) (hF : MeasurableConfiguration F) + (ν : ∀ i, Measure (Y i)) [∀ i, IsFiniteMeasure (ν i)] + (pos : ∀ i, Y i → X) (hpos : ∀ i, Measurable (pos i)) (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (∑ i, Measure.map (pos i) (ν i)) z) = + ∫⁻ x, F (s+mappedMultiParticleMultiset Y pos x) ∂Measure.pi (fun i => particleBase (ν i) z) := by + rw [particleBase_sum_observable_meas F hF] + simp_rw [← particleBase_map _ _ (hpos _)] + rw [← Measure.pi_map_pi (fun i => (measurable_mapParticle (hpos i)).aemeasurable)] + exact lintegral_map (measurable_multiParticleObservable F hF s) + (measurable_pi_iff.mpr (fun i => (measurable_mapParticle (hpos i)).comp (measurable_pi_apply i))) + +end GeneralFock +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MixtureBounds.lean b/lean/OAI/Probability/RadialTransition/MixtureBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..42475a9d2e731ec4db1cbc271ecdd8bdedd194ca --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MixtureBounds.lean @@ -0,0 +1,121 @@ +import OAI.Probability.RadialTransition.CountWeights + +namespace OAI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff BigOperators ENNReal NNReal + +namespace RadialTransition + +def quadraticTerm (φ : Potential) (L β z b : ℝ) (n : ℕ) : ℝ := + Real.exp (z*n) * partition φ L n β * Real.exp (b*(n:ℝ)^2/L^3) + +lemma quadraticTerm_pos {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {L : ℝ} (hL : 0 < L) (β z b : ℝ) (n : ℕ) : 0 < quadraticTerm φ L β z b n := by + exact mul_pos (mul_pos (Real.exp_pos _) (partition_pos hφ hb hL n β)) (Real.exp_pos _) + +lemma quadraticTerm_tail_bound {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {L β z b c B κ D : ℝ} (hL : 0 < L) (hβ : 0 ≤ β) (hκ : 0 < κ) + (hc : κ ≤ β*c-b) (hD : 1 ≤ D) (hcut : z+β*B+2 ≤ κ*D) + (hE : ∀ n x, x ∈ configurationCube L n → c*(n:ℝ)^2/L^3-B*n ≤ energy φ x) + {n : ℕ} (hn : D*L^3 < n) : quadraticTerm φ L β z b n ≤ Real.exp (-(n:ℝ)) := by + have hV : 0 < L^3 := by positivity + have hn0 : 0 < (n:ℝ) := lt_trans (by positivity : 0 < D*L^3) hn + have hp := quadraticTerm_pos hφ hb hL β z b n + have hl := log_partition_upper_of_energy_lower hφ hb hL hβ n (hE n) + have hf := (log_factorial_bounds n).1 + have hlog : Real.log (L^3) ≤ Real.log (n:ℝ) := Real.log_le_log hV (by nlinarith) + have hentropy : (n:ℝ)*Real.log (L^3)-Real.log (n.factorial:ℝ) ≤ n := by + nlinarith [mul_le_mul_of_nonneg_left hlog hn0.le] + have hquad : κ*D*(n:ℝ) ≤ (β*c-b)*(n:ℝ)^2/L^3 := by + apply (le_div_iff₀ hV).mpr + have hh : D*L^3 ≤ (n:ℝ) := hn.le + nlinarith [mul_le_mul_of_nonneg_left hh (mul_nonneg hκ.le hn0.le), + mul_le_mul_of_nonneg_right hc (sq_nonneg (n:ℝ))] + have hlg : Real.log (quadraticTerm φ L β z b n) ≤ -(n:ℝ) := by + rw [quadraticTerm, Real.log_mul (mul_ne_zero (Real.exp_ne_zero _) (partition_pos hφ hb hL n β).ne') (Real.exp_ne_zero _), + Real.log_mul (Real.exp_ne_zero _) (partition_pos hφ hb hL n β).ne', Real.log_exp, Real.log_exp] + have he : z*(n:ℝ)-β*(c*(n:ℝ)^2/L^3-B*n)+b*(n:ℝ)^2/L^3 = + (z+β*B)*(n:ℝ)-(β*c-b)*(n:ℝ)^2/L^3 := by ring + have hh := mul_le_mul_of_nonneg_right hcut hn0.le + linarith + exact (Real.exp_log hp).symm.le.trans (Real.exp_le_exp.mpr hlg) + +lemma exp_neg_nat_summable : Summable (fun n : ℕ => Real.exp (-(n:ℝ))) := by + have he (n : ℕ) : Real.exp (-(n:ℝ)) = (Real.exp (-1))^n := by rw [← Real.exp_nat_mul]; congr 1; ring + simpa only [he] using summable_geometric_of_lt_one (Real.exp_pos (-1)).le (Real.exp_lt_one_iff.mpr (by norm_num)) + +lemma exp_neg_positive_tail : (∑' n : {n : ℕ // 0 < n}, Real.exp (-(n:ℝ))) ≤ 1 := by + have hs := exp_neg_nat_summable + have he : (∑' n : ℕ, Real.exp (-(n:ℝ))) = (1-Real.exp (-1))⁻¹ := by + have hh := tsum_geometric_of_lt_one (Real.exp_pos (-1)).le (Real.exp_lt_one_iff.mpr (by norm_num)) + convert hh using 1 + apply tsum_congr; intro n + rw [← Real.exp_nat_mul]; congr 1; ring + have hx : Real.exp (-1) ≤ (1/2:ℝ) := by + rw [Real.exp_neg, inv_le_iff_one_le_mul₀ (Real.exp_pos 1)] + have hh := Real.add_one_le_exp (1:ℝ) + linarith + have hpos : 0 < 1-Real.exp (-1) := by linarith + have hsum : (∑' n : ℕ, Real.exp (-(n:ℝ))) ≤ 2 := by + rw [he, inv_le_iff_one_le_mul₀ hpos] + linarith + have ht := hs.sum_add_tsum_compl (s := {0}) + simp only [Finset.sum_singleton, Nat.cast_zero, neg_zero, Real.exp_zero] at ht + have heq : (∑' n : {n : ℕ // n ∉ ({0}:Finset ℕ)}, Real.exp (-(n:ℝ))) = + ∑' n : {n : ℕ // 0 < n}, Real.exp (-(n:ℝ)) := by + let e : {n : ℕ // n ∉ ({0}:Finset ℕ)} ≃ {n : ℕ // 0 < n} := + Equiv.subtypeEquivProp (by funext n; apply propext; simp [Nat.pos_iff_ne_zero]) + exact e.tsum_eq (fun n => Real.exp (-(n:ℝ))) + change 1 + (∑' n : {n : ℕ // n ∉ ({0}:Finset ℕ)}, Real.exp (-(n:ℝ))) = _ at ht + rw [heq] at ht + linarith + +lemma summable_of_tail_exp {F : ℕ → ℝ} (hF : ∀ n, 0 ≤ F n) (N : ℕ) + (htail : ∀ n, N < n → F n ≤ Real.exp (-(n:ℝ))) : Summable F := by + apply Summable.of_nonneg_of_le (fun n => hF n) (f := fun n => if n ≤ N then F n else Real.exp (-(n:ℝ))) + · intro n + split_ifs with hn + · rfl + · exact htail n (by omega) + · have he : (fun n => if n ≤ N then F n else Real.exp (-(n:ℝ))) = + (fun n : ℕ => Real.exp (-(n:ℝ)) + if n ≤ N then F n-Real.exp (-(n:ℝ)) else 0) := by + funext n; split_ifs <;> ring + rw [he] + exact exp_neg_nat_summable.add (summable_of_ne_finset_zero (s := Finset.range (N+1)) (by intro n hn; simp only [Finset.mem_range, not_lt] at hn; simp [show ¬n ≤ N by omega])) + +lemma tail_le_one_of_exp {F : ℕ → ℝ} (hF : ∀ n, 0 ≤ F n) (N : ℕ) + (htail : ∀ n, N < n → F n ≤ Real.exp (-(n:ℝ))) : + (∑' n : {n : ℕ // N < n}, F n) ≤ 1 := by + have hs := summable_of_tail_exp hF N htail + have hh := (hs.subtype (fun n => N < n)).tsum_le_tsum (fun (n : {n : ℕ // N < n}) => htail n n.property) + (exp_neg_nat_summable.subtype (fun n => N < n)) + apply hh.trans + apply le_trans _ exp_neg_positive_tail + let j : {n : ℕ // N < n} → {n : ℕ // 0 < n} := fun n => ⟨n, lt_of_le_of_lt (Nat.zero_le N) n.property⟩ + exact tsum_comp_le_tsum_of_inj (i := j) (exp_neg_nat_summable.subtype (fun n => 0 < n)) + (fun _ => (Real.exp_pos _).le) (by intro a b h; apply Subtype.ext; exact congrArg (fun x : {n : ℕ // 0 < n} => (x:ℕ)) h) + +lemma truncated_sum_bound {F : ℕ → ℝ} (hF : Summable F) {N : ℕ} {M : ℝ} + (hM : 1 ≤ M) (htail : (∑' n : {n : ℕ // N < n}, F n) ≤ 1) + (hsmall : ∀ n, n ≤ N → F n ≤ M) : (∑' n, F n) ≤ ((N:ℝ)+2)*M := by + have ht := hF.sum_add_tsum_compl (s := Finset.range (N+1)) + have he := (Equiv.subtypeEquivProp (by funext n; apply propext; simp) : + {n : ℕ // n ∉ Finset.range (N+1)} ≃ {n : ℕ // N < n}).tsum_eq (fun n => F n) + change (∑' n : {n : ℕ // n ∉ Finset.range (N+1)}, F n) = + (∑' n : {n : ℕ // N < n}, F n) at he + change (∑ n ∈ Finset.range (N+1), F n) + (∑' n : {n : ℕ // n ∉ Finset.range (N+1)}, F n) = _ at ht + rw [he] at ht + have hs := Finset.sum_le_card_nsmul (Finset.range (N+1)) F M (by intro n hn; exact hsmall n (by simpa using hn)) + simp only [Finset.card_range, nsmul_eq_mul, Nat.cast_add, Nat.cast_one] at hs + linarith + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/Model.lean b/lean/OAI/Probability/RadialTransition/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..c20ee2478c9d24cbbc1ed3afa600cd3c72ef648b --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/Model.lean @@ -0,0 +1,61 @@ +import Mathlib + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +abbrev Position := EuclideanSpace ℝ (Fin 3) +abbrev Potential := ℝ≥0 → ℝ + +def cube (L : ℝ) : Set Position := + {x | ∀ k : Fin 3, 0 ≤ x k ∧ x k ≤ L} + +def configurationCube (L : ℝ) (N : ℕ) : Set (Fin N → Position) := + {x | ∀ i : Fin N, x i ∈ cube L} + +def energy (φ : Potential) {N : ℕ} (x : Fin N → Position) : ℝ := + ∑ i : Fin N, ∑ j : Fin N with i < j, φ (nndist (x i) (x j)) + +def partition (φ : Potential) (L : ℝ) (N : ℕ) (β : ℝ) : ℝ := + (N.factorial : ℝ)⁻¹ * + ∫ x in configurationCube L N, Real.exp (-β * energy φ x) + +def packingNumber (L : ℝ) : ℕ := + sSup {n : ℕ | ∃ X : Finset Position, X.card = n ∧ + (∀ x ∈ X, x ∈ cube L) ∧ + (∀ x ∈ X, ∀ y ∈ X, x ≠ y → 1 ≤ dist x y)} + +def IsPackingDensity (p : ℝ) : Prop := + Tendsto (fun L : ℝ => (packingNumber L : ℝ) / L ^ 3) atTop (nhds p) + +def IsBoundedPotential (φ : Potential) : Prop := + ∃ M : ℝ, 0 ≤ M ∧ ∀ r : ℝ≥0, |φ r| ≤ M + +def StableWith (φ : Potential) (B : ℝ) : Prop := + ∀ (N : ℕ) (x : Fin N → Position), -(B * N) ≤ energy φ x + +def AlgebraicDecayWith (φ : Potential) (C : ℝ) : Prop := + ∀ r : ℝ≥0, 1 ≤ r → |φ r| ≤ C * (r : ℝ) ^ (-(3 : ℝ) - 1 / 32) + +def IsCanonicalFreeEnergy (φ : Potential) (ρ : ℝ) (f : ℝ → ℝ) : Prop := + ∀ β : ℝ, 0 < β → + Tendsto (fun L : ℝ => + -(Real.log (partition φ L ⌊ρ * L ^ 3⌋₊ β) / (β * L ^ 3))) + atTop (nhds (f β)) + +def StrictTemperatureCorner (f : ℝ → ℝ) (βc : ℝ) : Prop := + ∃ dLeft dRight : ℝ, + HasDerivWithinAt f dLeft (Iic βc) βc ∧ + HasDerivWithinAt f dRight (Ici βc) βc ∧ + dRight < dLeft ∧ ¬DifferentiableAt ℝ f βc + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MultiConvolution.lean b/lean/OAI/Probability/RadialTransition/MultiConvolution.lean new file mode 100644 index 0000000000000000000000000000000000000000..3ca31c5b14199eed98818d956701ae45440edff3 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MultiConvolution.lean @@ -0,0 +1,85 @@ +import OAI.Probability.RadialTransition.ClusterWeights + +namespace OAI + +universe uX + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +section Multi +variable {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] + [SecondCountableTopology X] + +lemma particleBase_emptyWeight (μ : Measure X) [SigmaFinite μ] (z : ℝ) : + (∫⁻ x, emptyWeight (particleMultiset x) ∂particleBase μ z) = 1 := by + have hm := measurable_particleObservable (emptyWeight (X := X)) measurable_emptyWeight 0 + simp only [zero_add] at hm + rw [lintegral_particleBase μ z hm, tsum_eq_single 0] + · simp [particleMultiset, emptyWeight, configurationMultiset_card] + · intro n hn + simp [particleMultiset, emptyWeight, configurationMultiset_card, hn] + +def finClusterProduct : (n : ℕ) → (Fin n → Multiset X → ℝ≥0∞) → Multiset X → ℝ≥0∞ + | 0, _ => emptyWeight + | n+1, W => clusterConvolution (W 0) (finClusterProduct n (fun i => W i.succ)) + +omit [TopologicalSpace X] [BorelSpace X] [SecondCountableTopology X] in +lemma measurable_finClusterProduct (n : ℕ) (W : Fin n → Multiset X → ℝ≥0∞) + (hW : ∀ i, MeasurableConfiguration (W i)) : MeasurableConfiguration (finClusterProduct n W) := by + induction n with + | zero => exact measurable_emptyWeight + | succ n ih => exact measurable_clusterConvolution (hW 0) (ih _ (fun i => hW i.succ)) + +omit [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] in +lemma finClusterProduct_ge (n : ℕ) (W : Fin n → Multiset X → ℝ≥0∞) + (u : Fin n → Multiset X) : (∏ i, W i (u i)) ≤ finClusterProduct n W (∑ i, u i) := by + induction n with + | zero => simp [finClusterProduct, emptyWeight] + | succ n ih => + rw [Fin.prod_univ_succ, Fin.sum_univ_succ] + exact (mul_le_mul' le_rfl (ih (fun i => W i.succ) (fun i => u i.succ))).trans + (clusterConvolution_add_ge (W 0) (finClusterProduct n (fun i => W i.succ)) _ _) + +lemma particleBase_finClusterProduct (n : ℕ) (W : Fin n → Multiset X → ℝ≥0∞) + (hW : ∀ i, MeasurableConfiguration (W i)) (μ : Measure X) [SigmaFinite μ] (z : ℝ) : + (∫⁻ x, finClusterProduct n W (particleMultiset x) ∂particleBase μ z) = + ∏ i, ∫⁻ x, W i (particleMultiset x) ∂particleBase μ z := by + induction n with + | zero => simpa only [finClusterProduct, Fin.prod_univ_zero] using particleBase_emptyWeight μ z + | succ n ih => + rw [finClusterProduct, particleBase_convolution (hW 0) + (measurable_finClusterProduct _ _ (fun i => hW i.succ)), ih _ (fun i => hW i.succ), Fin.prod_univ_succ] + +variable {I : Type} [Fintype I] + +def indexedClusterProduct (W : I → Multiset X → ℝ≥0∞) : Multiset X → ℝ≥0∞ := + finClusterProduct (Fintype.card I) (fun i => W ((Fintype.equivFin I).symm i)) + +omit [TopologicalSpace X] [BorelSpace X] [SecondCountableTopology X] in +lemma measurable_indexedClusterProduct (W : I → Multiset X → ℝ≥0∞) + (hW : ∀ i, MeasurableConfiguration (W i)) : MeasurableConfiguration (indexedClusterProduct W) := + measurable_finClusterProduct _ _ (fun _i => hW _) + +omit [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] in +lemma indexedClusterProduct_ge (W : I → Multiset X → ℝ≥0∞) (u : I → Multiset X) : + (∏ i, W i (u i)) ≤ indexedClusterProduct W (∑ i, u i) := by + have hh := finClusterProduct_ge (Fintype.card I) + (fun i => W ((Fintype.equivFin I).symm i)) (fun i => u ((Fintype.equivFin I).symm i)) + rw [Equiv.sum_comp, Equiv.prod_comp (Fintype.equivFin I).symm (fun i => W i (u i))] at hh + exact hh + +lemma particleBase_indexedClusterProduct (W : I → Multiset X → ℝ≥0∞) + (hW : ∀ i, MeasurableConfiguration (W i)) (μ : Measure X) [SigmaFinite μ] (z : ℝ) : + (∫⁻ x, indexedClusterProduct W (particleMultiset x) ∂particleBase μ z) = + ∏ i, ∫⁻ x, W i (particleMultiset x) ∂particleBase μ z := by + rw [indexedClusterProduct, particleBase_finClusterProduct _ _ (fun _i => hW _)] + exact Equiv.prod_comp (Fintype.equivFin I).symm (fun i => ∫⁻ x, W i (particleMultiset x) ∂particleBase μ z) + +end Multi +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MultiScale.lean b/lean/OAI/Probability/RadialTransition/MultiScale.lean new file mode 100644 index 0000000000000000000000000000000000000000..9461df9a418d4c0c6069f0686c201393a169e11f --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MultiScale.lean @@ -0,0 +1,130 @@ +import OAI.Probability.RadialTransition.Propagation + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma multiscale_pressure_balls {P Q : ℕ → Pressure} {a δ : ℕ → ℝ} {U C C₀ k l : ℝ} + (ha : ∀ n, 0 < a n) (hδ : ∀ n, 0 ≤ δ n) (hU : 0 ≤ U) (hC : 0 ≤ C) + (hk : 0 < k) (hl : 0 < l) + (hP : ∀ n, ConvexOn ℝ positiveParameters (onParameters (P n))) + (hQ : ∀ n, ConvexOn ℝ positiveParameters (onParameters (Q n))) + (hnext : ∀ n, P (n+1)=idealAttraction (Q n) (a n)) + (happ : ∀ n x, x ∈ phaseWindow (1/4) → |onParameters (Q n) x-onParameters (P n) x| ≤ δ n) + (hlip : ∀ n x, x ∈ phaseWindow (1/4) → ∀ y ∈ phaseWindow (1/4), + |onParameters (P n) x-onParameters (P n) y| ≤ C*dist x y) + (hinc : ∀ n x, x ∈ phaseWindow (1/4) → |onParameters (P (n+1)) x-onParameters (Q n) x| ≤ C₀*a n) + (hact : ∀ n β h, 0 < β → ∃ u, ActiveShift (Q n) (a n) β h u) + (hcut : ∀ n x, x ∈ phaseWindow (1/2) → ∃ u ∈ Icc (0:ℝ) U, ActiveShift (Q n) (a n) (x 0) (x 1) u) + (hinit : ∀ x ∈ phaseWindow (1/4), HasPhaseGroups (P 0) x (phaseRadius/2) ∧ + |onParameters (P 0) x-onParameters threePlane x| ≤ pressureRadius/64) + (hdom : ∀ n, (5/4*U+k+l+1)*(∑ j ∈ Finset.range n, a j) ≤ 1/8) + (hrad : ∀ n, ∑ j ∈ Finset.range n, (2*δ j/(l*a j)+a j*U^2/2) ≤ phaseRadius/2) + (hband : ∀ n, 2*(k+2*δ n/(k*a n)+2*C*l/k+phaseRadius) 1/4-S*(∑ j ∈ Finset.range n, a j) + let r := fun n => phaseRadius/2+∑ j ∈ Finset.range n, (2*δ j/(l*a j)+a j*U^2/2) + have hS : 0 ≤ S := by dsimp [S]; positivity + have hs (n : ℕ) : 1/8 ≤ s n ∧ s n ≤ 1/4 := by + have hn := hdom n + have hm : 0 ≤ S*(∑ j ∈ Finset.range n, a j) := + mul_nonneg hS (Finset.sum_nonneg (fun j _ => (ha j).le)) + dsimp [s,S] at * + constructor <;> linarith + have hr (n : ℕ) : 0 ≤ r n ∧ r n ≤ phaseRadius := by + have hnon : 0 ≤ ∑ j ∈ Finset.range n, (2*δ j/(l*a j)+a j*U^2/2) := by + apply Finset.sum_nonneg + intro j _ + have := ha j + have := hδ j + positivity + have hb := hrad n + dsimp [r] + constructor <;> linarith [phaseRadius_pos] + have hsr (n : ℕ) : s (n+1)=s n-S*a n := by + dsimp [s] + rw [Finset.sum_range_succ] + ring + have hrr (n : ℕ) : r (n+1)=r n+2*δ n/(l*a n)+a n*U^2/2 := by + dsimp [r] + rw [Finset.sum_range_succ] + ring + have hgroups : ∀ n x, x ∈ phaseWindow (s n) → HasPhaseGroups (P n) x (r n) := by + intro n + induction n with + | zero => + intro x hx + simpa [r] using (hinit x (by simpa [s] using hx)).1 + | succ n ih => + intro x hx + rw [hnext n,hrr n] + rw [hsr] at hx + exact propagate_phase_groups (hP n) (hQ n) (ha n) (hδ n) hC hU hk hl (hr n).1 (hs n).2 + (by have := hband n; linarith [(hr n).2]) ih (happ n) (hlip n) (hact n) (hcut n) x hx + have hclose : ∀ n x, x ∈ phaseWindow (1/4) → + |onParameters (P n) x-onParameters threePlane x| ≤ + pressureRadius/64+∑ j ∈ Finset.range n, (δ j+C₀*a j) := by + intro n + induction n with + | zero => + intro x hx + simpa using (hinit x hx).2 + | succ n ih => + intro x hx + have h1 := abs_sub_le (onParameters (P (n+1)) x) (onParameters (Q n) x) (onParameters (P n) x) + have h2 := abs_sub_le (onParameters (P (n+1)) x) (onParameters (P n) x) (onParameters threePlane x) + rw [Finset.sum_range_succ] + linarith [hinc n x hx,happ n x hx,ih x hx] + intro n + apply pressure_ball_exists (hP n) + · intro x hx + have hh := hclose n x (phaseWindow_mono (by norm_num) hx) + linarith [hpress n] + · intro x hx + exact ⟨r n,(hr n).2,hgroups n x (phaseWindow_mono (hs n).1 hx)⟩ + +lemma pressure_ball_limit {P : ℕ → Pressure} {Q : Pressure} {C : ℝ} + (hQ : ConvexOn ℝ positiveParameters (onParameters Q)) + (hball : ∀ n, ∃ x ∈ Metric.ball phaseCenter (1/8), + Metric.closedBall targetSlope pressureRadius ⊆ supportSet (onParameters (P n)) positiveParameters x) + (hlip : ∀ n x, x ∈ phaseWindow (1/4) → ∀ y ∈ phaseWindow (1/4), + |onParameters (P n) x-onParameters (P n) y| ≤ C*dist x y) + (hlim : ∀ x ∈ phaseWindow (1/4), Tendsto (fun n => onParameters (P n) x) atTop (nhds (onParameters Q x))) : + ∃ x ∈ phaseWindow (1/8), Metric.closedBall targetSlope pressureRadius ⊆ + supportSet (onParameters Q) positiveParameters x := by + choose x hx hs using hball + have hx' (n : ℕ) : x n ∈ phaseWindow (1/8) := Metric.ball_subset_closedBall (hx n) + obtain ⟨z,hz,σ,hσ,hlimx⟩ := (isCompact_closedBall phaseCenter (1/8)).tendsto_subseq hx' + have hzq : z ∈ phaseWindow (1/4) := phaseWindow_mono (by norm_num) hz + have hdist : Tendsto (fun n => dist (x (σ n)) z) atTop (nhds 0) := by + simpa using hlimx.dist (tendsto_const_nhds : Tendsto (fun _ : ℕ => z) atTop (nhds z)) + have hdiff : Tendsto (fun n => onParameters (P (σ n)) (x (σ n))-onParameters (P (σ n)) z) atTop (nhds 0) := by + apply squeeze_zero_norm + · intro n + simpa only [Real.norm_eq_abs] using hlip (σ n) (x (σ n)) + (phaseWindow_mono (by norm_num) (hx' (σ n))) z hzq + · simpa using hdist.const_mul C + have hbase : Tendsto (fun n => onParameters (P (σ n)) (x (σ n))) atTop (nhds (onParameters Q z)) := by + have hh := hdiff.add ((hlim z hzq).comp hσ.tendsto_atTop) + simpa only [Function.comp_apply,sub_add_cancel,zero_add] using hh + refine ⟨z,hz,?_⟩ + intro v hv + have hsupport : SupportsOn (onParameters Q) (phaseWindow (1/4)) z v := by + apply supportsOn_of_tendsto hlimx tendsto_const_nhds hbase + (fun y hy => (hlim y hy).comp hσ.tendsto_atTop) + intro n y hy + exact hs (σ n) hv y (phaseWindow_positive (by norm_num) hy) + apply supportsOn_of_local hQ (phaseWindow_positive (by norm_num) hz) (by norm_num : (0:ℝ)<1/16) + intro y hy + exact hsupport y (phaseWindow_mono (by norm_num : (1/8:ℝ)+1/16≤1/4) (phaseWindow_near hz hy.2)) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/MultisetEnergy.lean b/lean/OAI/Probability/RadialTransition/MultisetEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..26081c41c4bd9b78d34706f40d29593bbfe1e189 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/MultisetEnergy.lean @@ -0,0 +1,291 @@ +import OAI.Probability.RadialTransition.ProductFock + +namespace OAI + +universe uX uM uIndex uY + +noncomputable section + + +open MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +section MultisetEnergy +variable {X : Type uX} + +def multisetPairing (v : X → X → ℝ) (s t : Multiset X) : ℝ := + (s.map (fun x => (t.map (v x)).sum)).sum + +def multisetDiagonal (v : X → X → ℝ) (s : Multiset X) : ℝ := + (s.map (fun x => v x x)).sum + +def multisetEnergy (v : X → X → ℝ) (s : Multiset X) : ℝ := + (1/2:ℝ) * (multisetPairing v s s - multisetDiagonal v s) + +@[simp] lemma multisetPairing_zero_left (v : X → X → ℝ) (s : Multiset X) : + multisetPairing v 0 s = 0 := by simp [multisetPairing] +@[simp] lemma multisetPairing_zero_right (v : X → X → ℝ) (s : Multiset X) : + multisetPairing v s 0 = 0 := by simp [multisetPairing] +@[simp] lemma multisetPairing_add_left (v : X → X → ℝ) (s t u : Multiset X) : + multisetPairing v (s+t) u = multisetPairing v s u + multisetPairing v t u := by + simp [multisetPairing] +@[simp] lemma multisetPairing_add_right (v : X → X → ℝ) (s t u : Multiset X) : + multisetPairing v s (t+u) = multisetPairing v s t + multisetPairing v s u := by + simp [multisetPairing, Multiset.sum_map_add] +@[simp] lemma multisetDiagonal_add (v : X → X → ℝ) (s t : Multiset X) : + multisetDiagonal v (s+t) = multisetDiagonal v s + multisetDiagonal v t := by + simp [multisetDiagonal] +@[simp] lemma multisetDiagonal_zero (v : X → X → ℝ) : multisetDiagonal v 0 = 0 := by simp [multisetDiagonal] + +lemma multisetPairing_symm {v : X → X → ℝ} (hv : ∀ x y, v x y = v y x) (s t : Multiset X) : + multisetPairing v s t = multisetPairing v t s := by + induction s using Multiset.induction_on with + | empty => simp + | @cons a s ih => + simp only [multisetPairing, Multiset.map_cons, Multiset.sum_cons] at * + simp_rw [Multiset.sum_map_add, hv a] + rw [ih] + +lemma multisetEnergy_add {v : X → X → ℝ} (hv : ∀ x y, v x y = v y x) (s t : Multiset X) : + multisetEnergy v (s+t) = multisetEnergy v s + multisetEnergy v t + multisetPairing v s t := by + simp only [multisetEnergy, multisetPairing_add_left, multisetPairing_add_right, multisetDiagonal_add] + rw [multisetPairing_symm hv t s] + ring + +lemma sum_map_configuration {ι : Type} [Fintype ι] {M : Type uM} [AddCommMonoid M] + (f : X → M) (x : ι → X) : ((configurationMultiset x).map f).sum = ∑ i, f (x i) := by + unfold configurationMultiset + rw [← Multiset.coe_mapAddMonoidHom, map_sum] + simp [Multiset.sum_sum] + +lemma multisetPairing_configuration {ι κ : Type} [Fintype ι] [Fintype κ] + (v : X → X → ℝ) (x : ι → X) (y : κ → X) : + multisetPairing v (configurationMultiset x) (configurationMultiset y) = ∑ i, ∑ j, v (x i) (y j) := by + simp only [multisetPairing, sum_map_configuration] + +lemma multisetDiagonal_configuration {ι : Type} [Fintype ι] (v : X → X → ℝ) (x : ι → X) : + multisetDiagonal v (configurationMultiset x) = ∑ i, v (x i) (x i) := by + simp only [multisetDiagonal, sum_map_configuration] + +lemma multisetEnergy_particle (v : X → X → ℝ) (s : ParticleState X) : + multisetEnergy v (particleMultiset s) = pairWithin v s := by + classical + simp only [multisetEnergy, particleMultiset, multisetPairing_configuration, multisetDiagonal_configuration, + pairWithin] + congr 1 + rw [← Finset.sum_sub_distrib] + apply Finset.sum_congr rfl + intro i _ + have hh : (∑ j : Fin s.1, v (s.2 i) (s.2 j)) = + v (s.2 i) (s.2 i) + ∑ j : Fin s.1, if i = j then 0 else v (s.2 i) (s.2 j) := by + conv_lhs => + arg 2; ext j + rw [show v (s.2 i) (s.2 j) = (if i = j then v (s.2 i) (s.2 j) else 0) + + (if i = j then 0 else v (s.2 i) (s.2 j)) by split_ifs <;> simp] + simp only [Finset.sum_add_distrib, Finset.sum_ite_eq, Finset.mem_univ, ite_true] + linarith + +lemma multisetPairing_fin_sum_left {ι : Type uIndex} (v : X → X → ℝ) (T : Finset ι) + (s : ι → Multiset X) (t : Multiset X) : + multisetPairing v (∑ i ∈ T, s i) t = ∑ i ∈ T, multisetPairing v (s i) t := by + classical + induction T using Finset.induction_on with + | empty => simp + | @insert i T hi ih => simp [hi, ih] + +lemma multisetPairing_fin_sum_right {ι : Type uIndex} (v : X → X → ℝ) (T : Finset ι) + (s : ι → Multiset X) (t : Multiset X) : + multisetPairing v t (∑ i ∈ T, s i) = ∑ i ∈ T, multisetPairing v t (s i) := by + classical + induction T using Finset.induction_on with + | empty => simp + | @insert i T hi ih => simp [hi, ih] + +lemma multisetDiagonal_fin_sum {ι : Type uIndex} (v : X → X → ℝ) (T : Finset ι) + (s : ι → Multiset X) : + multisetDiagonal v (∑ i ∈ T, s i) = ∑ i ∈ T, multisetDiagonal v (s i) := by + classical + induction T using Finset.induction_on with + | empty => simp + | @insert i T hi ih => simp [hi, ih] + +lemma multisetEnergy_sum {ι : Type uIndex} [Fintype ι] [DecidableEq ι] + (v : X → X → ℝ) (s : ι → Multiset X) : + multisetEnergy v (∑ i, s i) = ∑ i, multisetEnergy v (s i) + + (1/2:ℝ) * ∑ i, ∑ j, if i = j then 0 else multisetPairing v (s i) (s j) := by + have hh (i : ι) : (∑ j, multisetPairing v (s i) (s j)) = + multisetPairing v (s i) (s i) + ∑ j, if i = j then 0 else multisetPairing v (s i) (s j) := by + conv_lhs => + arg 2; ext j + rw [show multisetPairing v (s i) (s j) = + (if i = j then multisetPairing v (s i) (s j) else 0) + + (if i = j then 0 else multisetPairing v (s i) (s j)) by split_ifs <;> simp] + simp only [Finset.sum_add_distrib, Finset.sum_ite_eq, Finset.mem_univ, ite_true] + rw [multisetEnergy, multisetPairing_fin_sum_left, multisetDiagonal_fin_sum] + simp_rw [multisetPairing_fin_sum_right, hh] + simp only [multisetEnergy, Finset.sum_add_distrib, ← Finset.mul_sum, Finset.sum_sub_distrib] + ring + +lemma multisetEnergy_mappedMulti {I : Type} [Fintype I] [DecidableEq I] (Y : I → Type uY) + (pos : ∀ i, Y i → X) (v : X → X → ℝ) (x : ∀ i, ParticleState (Y i)) : + multisetEnergy v (mappedMultiParticleMultiset Y pos x) = + pairCellEnergy (fun i j a b => v (pos i a) (pos j b)) x := by + unfold mappedMultiParticleMultiset pairCellEnergy cellHamiltonian + rw [multisetEnergy_sum] + congr 1 + · apply Finset.sum_congr rfl + intro i _ + rw [multisetEnergy_particle] + rfl + · congr 1 + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + split_ifs + · rfl + · exact multisetPairing_configuration v _ _ + +section Continuity +variable [TopologicalSpace X] + +lemma continuous_multisetPairing_right {v : X → X → ℝ} + (hv : Continuous (Function.uncurry v)) (s : Multiset X) + {ι : Type} [Fintype ι] : Continuous (fun x : ι → X => multisetPairing v s (configurationMultiset x)) := by + induction s using Multiset.induction_on with + | empty => simpa using (continuous_const : Continuous (fun _ : ι → X => (0:ℝ))) + | @cons a s ih => + simp only [multisetPairing, Multiset.map_cons, Multiset.sum_cons, sum_map_configuration] at * + exact (continuous_finsetSum _ (fun i _ => hv.comp (continuous_const.prodMk (continuous_apply i)))).add ih + +lemma continuous_multisetEnergy_configuration {v : X → X → ℝ} + (hv : Continuous (Function.uncurry v)) {ι : Type} [Fintype ι] : + Continuous (fun x : ι → X => multisetEnergy v (configurationMultiset x)) := by + simp only [multisetEnergy, multisetPairing_configuration, multisetDiagonal_configuration] + apply continuous_const.mul + apply Continuous.sub + · exact continuous_finsetSum _ (fun i _ => continuous_finsetSum _ + (fun j _ => hv.comp (show Continuous (fun x : ι → X => (x i, x j)) from (continuous_apply i).prodMk (continuous_apply j)))) + · exact continuous_finsetSum _ (fun i _ => hv.comp (show Continuous (fun x : ι → X => (x i, x i)) from (continuous_apply i).prodMk (continuous_apply i))) + +lemma continuousConfiguration_boltzmann {v : X → X → ℝ} + (hv : Continuous (Function.uncurry v)) (hsym : ∀ x y, v x y = v y x) (β : ℝ) : + ContinuousConfiguration (fun s => ENNReal.ofReal (Real.exp (-β * multisetEnergy v s))) := by + intro s ι _ + simp only [multisetEnergy_add hsym] + exact ENNReal.continuous_ofReal.comp (Real.continuous_exp.comp + (continuous_const.mul ((continuous_const.add (continuous_multisetEnergy_configuration hv)).add + (continuous_multisetPairing_right hv s)))) + +end Continuity + +end MultisetEnergy + +def radialPair (φ : Potential) (x y : Position) : ℝ := φ (nndist x y) + +lemma continuous_radialPair {φ : Potential} (hφ : Continuous φ) : + Continuous (Function.uncurry (radialPair φ)) := + hφ.comp (continuous_fst.nndist continuous_snd) + +lemma radialPair_symm (φ : Potential) (x y : Position) : radialPair φ x y = radialPair φ y x := by + simp only [radialPair, nndist_comm] + +lemma pairWithin_radial (φ : Potential) (s : ParticleState Position) : + pairWithin (radialPair φ) s = orderedEnergy φ s.2 := by + classical + unfold pairWithin orderedEnergy + have hh : (∑ i : Fin s.1, ∑ j : Fin s.1, if i = j then 0 else radialPair φ (s.2 i) (s.2 j)) = + ∑ i : Fin s.1, ∑ j : Fin s.1, if i ≠ j then φ (nndist (s.2 i) (s.2 j)) else 0 := by + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + by_cases hij : i = j <;> simp [hij, radialPair] + rw [hh] + ring_nf + +lemma multisetEnergy_radial (φ : Potential) (s : ParticleState Position) : + multisetEnergy (radialPair φ) (particleMultiset s) = orderedEnergy φ s.2 := by + rw [multisetEnergy_particle, pairWithin_radial] + +lemma measurable_particleBoltzmann {φ : Potential} (hφ : Continuous φ) (β : ℝ) : + Measurable (fun s : ParticleState Position => Real.exp (-β * orderedEnergy φ s.2)) := by + apply Continuous.measurable + apply continuous_sigma + intro n + exact Real.continuous_exp.comp (continuous_const.mul (continuous_orderedEnergy hφ)) + +lemma lintegral_grandOn {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B β : ℝ} (hstable : StableWith φ B) (hβ : 0 ≤ β) {A : Set Position} + (hAfin : volume A ≠ ⊤) (z : ℝ) : + (∫⁻ s : ParticleState Position, ENNReal.ofReal (Real.exp (-β * orderedEnergy φ s.2)) + ∂particleBase (volume.restrict A) z) = ENNReal.ofReal (grandOn φ A β z) := by + let : IsFiniteMeasure (volume.restrict A) := isFiniteMeasure_restrict.mpr hAfin + rw [lintegral_particleBase _ _ (measurable_particleBoltzmann hφ β).ennreal_ofReal, + grandOn, ENNReal.ofReal_tsum_of_nonneg + (fun n => mul_nonneg (Real.exp_pos _).le (partitionOn_nonneg φ A n β)) + (grandOn_summable hφ hb hstable hβ hAfin z)] + apply tsum_congr + intro n + have hi := integrable_orderedBoltzmann (ι := Fin n) hφ hb β (Measure.pi (fun _ => volume.restrict A)) + rw [← ofReal_integral_eq_lintegral_ofReal hi (Eventually.of_forall (fun x => (Real.exp_pos _).le)), + ← ENNReal.ofReal_mul (by positivity)] + congr 1 + simp only [partitionOn, rawPartition, div_eq_mul_inv] + ring + +lemma continuous_radialPair_comp {X : Type uX} {Y : Type uY} [TopologicalSpace X] [TopologicalSpace Y] + {φ : Potential} (hφ : Continuous φ) {f : X → Position} {g : Y → Position} + (hf : Continuous f) (hg : Continuous g) : + Continuous (fun p : X × Y => radialPair φ (f p.1) (g p.2)) := by + change Continuous (fun p : X × Y => φ (nndist (f p.1) (g p.2))) + exact hφ.comp ((hf.comp continuous_fst).nndist (hg.comp continuous_snd)) + +theorem grandOn_cell_factorization {I : Type} [Fintype I] [DecidableEq I] + (Y : I → Type uY) [∀ i, TopologicalSpace (Y i)] [∀ i, MeasurableSpace (Y i)] + [∀ i, BorelSpace (Y i)] [∀ i, SecondCountableTopology (Y i)] + (ν : ∀ i, Measure (Y i)) [∀ i, IsFiniteMeasure (ν i)] + (pos : ∀ i, Y i → Position) (hpos : ∀ i, Continuous (pos i)) + {A : Set Position} (hAfin : volume A ≠ ⊤) + (hdecomp : volume.restrict A = ∑ i, Measure.map (pos i) (ν i)) + {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) {B β : ℝ} + (hstable : StableWith φ B) (hβ : 0 ≤ β) (z : ℝ) : + let μ := Measure.pi (fun i => particleBase (ν i) z) + let E := fun x => β * pairCellEnergy (fun i j a b => radialPair φ (pos i a) (pos j b)) x + Integrable (fun x => Real.exp (-E x)) μ ∧ boltzmannPartition μ E = grandOn φ A β z := by + dsimp only + let v : ∀ i j, Y i → Y j → ℝ := fun i j a b => radialPair φ (pos i a) (pos j b) + have hv (i j : I) : Continuous (Function.uncurry (v i j)) := by + change Continuous (fun p : Y i × Y j => radialPair φ (pos i p.1) (pos j p.2)) + exact continuous_radialPair_comp hφ (hpos i) (hpos j) + + have hE : Measurable (fun x => Real.exp (-(β * pairCellEnergy v x))) := + (Real.continuous_exp.comp (continuous_const.mul (continuous_pairCellEnergy v hv)).neg).measurable + have heq : (∫⁻ x, ENNReal.ofReal (Real.exp (-(β * pairCellEnergy v x))) + ∂Measure.pi (fun i => particleBase (ν i) z)) = ENNReal.ofReal (grandOn φ A β z) := by + have hh := particleBase_sum_map_observable Y + (fun s => ENNReal.ofReal (Real.exp (-β * multisetEnergy (radialPair φ) s))) + (continuousConfiguration_boltzmann (continuous_radialPair hφ) (radialPair_symm φ) β) + ν pos (fun i => (hpos i).measurable) z 0 + simp only [zero_add, multisetEnergy_radial, multisetEnergy_mappedMulti] at hh + rw [← hdecomp, lintegral_grandOn hφ hb hstable hβ hAfin z] at hh + simpa only [neg_mul, v] using hh.symm + have hi : Integrable (fun x => Real.exp (-(β * pairCellEnergy v x))) + (Measure.pi (fun i => particleBase (ν i) z)) := by + refine ⟨hE.aestronglyMeasurable, ?_⟩ + simp only [HasFiniteIntegral, Real.enorm_eq_ofReal (Real.exp_pos _).le] + rw [heq] + exact ENNReal.ofReal_lt_top + refine ⟨hi, ?_⟩ + rw [boltzmannPartition, integral_eq_lintegral_of_nonneg_ae + (Eventually.of_forall (fun x => (Real.exp_pos _).le)) hi.aestronglyMeasurable, heq, + ENNReal.toReal_ofReal (zero_le_one.trans (grandOn_bounds hφ hb hstable hβ hAfin z).1)] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/OccupationMoments.lean b/lean/OAI/Probability/RadialTransition/OccupationMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..cee02d4b6f6bda492d373f6f750d2bb77902fb24 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/OccupationMoments.lean @@ -0,0 +1,120 @@ +import OAI.Probability.RadialTransition.CanonicalDuality + +namespace OAI + +universe uI uX + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +theorem exp_weighted_sum_le {I : Type uI} [Fintype I] (w x : I → ℝ) + (hw : ∀ i, 0 ≤ w i) (hs : ∑ i, w i ≤ 1) : + Real.exp (∑ i, w i * x i) ≤ 1 - ∑ i, w i + ∑ i, w i * Real.exp (x i) := by + have hh := convexOn_exp.map_add_sum_le (t := Finset.univ) (w := w) (p := x) + (v := 1 - ∑ i, w i) (q := 0) (fun i _ => hw i) (by ring) + (fun _ _ => mem_univ _) (sub_nonneg.mpr hs) (mem_univ _) + simpa only [smul_eq_mul, mul_zero, zero_add, Real.exp_zero, mul_one] using hh + +theorem integral_exp_fraction_le {X : Type uX} [MeasurableSpace X] {μ : Measure X} + [IsProbabilityMeasure μ] {f : X → ℝ} (hf : Measurable f) (hf0 : ∀ x, 0 ≤ f x) + (hi : Integrable (fun x => Real.exp (f x)) μ) {η : ℝ} (hη0 : 0 ≤ η) (hη1 : η ≤ 1) : + Integrable (fun x => Real.exp (η * f x)) μ ∧ + (∫ x, Real.exp (η * f x) ∂μ) ≤ Real.exp (η * Real.log (∫ x, Real.exp (f x) ∂μ)) := by + have hib : Integrable (fun x => Real.exp (η * f x)) μ := by + apply hi.mono' (Real.measurable_exp.comp (measurable_const.mul hf)).aestronglyMeasurable + filter_upwards [] with x + change |Real.exp (η * f x)| ≤ Real.exp (f x) + rw [abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_exp.mpr (mul_le_of_le_one_left (hf0 x) hη1) + have hpos : 0 < ∫ x, Real.exp (η * f x) ∂μ := by + apply (integral_pos_iff_support_of_nonneg (fun x => (Real.exp_pos _).le) hib).mpr + simp [Function.support, Real.exp_ne_zero] + have hpos' : 0 < ∫ x, Real.exp (f x) ∂μ := by + apply (integral_pos_iff_support_of_nonneg (fun x => (Real.exp_pos _).le) hi).mpr + simp [Function.support, Real.exp_ne_zero] + have hh := log_integral_exp_convex_mix (F := fun _ : X => (0 : ℝ)) (G := f) + (sub_nonneg.mpr hη1) hη0 (by ring) (by simp) hi + (by simpa using hib) (by simp) hpos' (by simpa using hpos) + simp only [mul_zero, zero_add, Real.exp_zero, integral_const, probReal_univ, smul_eq_mul, + one_mul, Real.log_one] at hh + refine ⟨hib, ?_⟩ + simpa only [Real.exp_log hpos] using Real.exp_le_exp.mpr hh + +theorem occupation_moment_closure {I : Type uI} {X : Type uX} [Fintype I] [Nonempty I] + [MeasurableSpace X] {μ : Measure X} [IsProbabilityMeasure μ] + (f : I → X → ℝ) (θ : I → I → ℝ) {C η : ℝ} + (hC : 1 ≤ C) (hη0 : 0 ≤ η) (hη1 : η < 1) + (hf : ∀ i, Measurable (f i)) (hf0 : ∀ i x, 0 ≤ f i x) + (hi : ∀ i, Integrable (fun x => Real.exp (f i x)) μ) + (hθ : ∀ i j, 0 ≤ θ i j) (hrow : ∀ i, ∑ j, θ i j ≤ 1) + (hconditional : ∀ i, (∫ x, Real.exp (f i x) ∂μ) ≤ + C * (∫ x, Real.exp (η * ∑ j, θ i j * f j x) ∂μ)) : + ∀ i, (∫ x, Real.exp (f i x) ∂μ) ≤ Real.exp (Real.log C / (1 - η)) := by + classical + let F (i : I) := ∫ x, Real.exp (f i x) ∂μ + have hF1 (i : I) : 1 ≤ F i := by + have hh := integral_mono (integrable_const (1 : ℝ)) (hi i) + (fun x => Real.one_le_exp_iff.mpr (hf0 i x)) + simpa only [integral_const, probReal_univ, smul_eq_mul, one_mul] using hh + obtain ⟨k, _, hk⟩ := Finset.univ.exists_max_image F Finset.univ_nonempty + have hFm (i : I) : F i ≤ F k := hk i (Finset.mem_univ i) + have hfrac (i : I) := integral_exp_fraction_le (hf i) (hf0 i) (hi i) hη0 hη1.le + have hless (i : I) : ∫ x, Real.exp (η * ∑ j, θ i j * f j x) ∂μ ≤ + Real.exp (η * Real.log (F k)) := by + let g : X → ℝ := fun x => 1 - ∑ j, θ i j + ∑ j, θ i j * Real.exp (η * f j x) + have hig : Integrable g μ := + (integrable_const _).add (integrable_finsetSum _ (fun j _ => (hfrac j).1.const_mul _)) + have hpoint (x : X) : Real.exp (η * ∑ j, θ i j * f j x) ≤ g x := by + have hh := exp_weighted_sum_le (θ i) (fun j => η * f j x) (hθ i) (hrow i) + dsimp only [g] + convert hh using 1 + congr 1 + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro j _ + ring + have hmix : Integrable (fun x => Real.exp (η * ∑ j, θ i j * f j x)) μ := by + apply hig.mono' (Real.measurable_exp.comp + (measurable_const.mul (Finset.measurable_sum _ (fun j _ => measurable_const.mul (hf j))))).aestronglyMeasurable + filter_upwards [] with x + change |Real.exp (η * ∑ j, θ i j * f j x)| ≤ g x + rw [abs_of_pos (Real.exp_pos _)] + exact hpoint x + have hh := integral_mono hmix hig hpoint + have hexp1 : 1 ≤ Real.exp (η * Real.log (F k)) := by + apply Real.one_le_exp_iff.mpr + exact mul_nonneg hη0 (Real.log_nonneg (hF1 k)) + have hfs (j : I) : ∫ x, Real.exp (η * f j x) ∂μ ≤ Real.exp (η * Real.log (F k)) := + (hfrac j).2.trans (Real.exp_le_exp.mpr (mul_le_mul_of_nonneg_left + (Real.log_le_log (by linarith [hF1 j]) (hFm j)) hη0)) + dsimp only [g] at hh + rw [integral_add (integrable_const _) (integrable_finsetSum _ (fun j _ => (hfrac j).1.const_mul _)), + integral_const, probReal_univ, smul_eq_mul, one_mul, + integral_finsetSum _ (fun j _ => (hfrac j).1.const_mul _)] at hh + simp only [integral_const_mul] at hh + have hs := Finset.sum_le_sum (s := Finset.univ) + (fun j (_ : j ∈ Finset.univ) => mul_le_mul_of_nonneg_left (hfs j) (hθ i j)) + rw [← Finset.sum_mul] at hs + have := hrow i + nlinarith + have hkineq := (hconditional k).trans (mul_le_mul_of_nonneg_left (hless k) (by linarith)) + have hC0 : 0 < C := by linarith + have hFk0 : 0 < F k := by linarith [hF1 k] + have hlog := Real.log_le_log hFk0 hkineq + rw [Real.log_mul hC0.ne' (Real.exp_ne_zero _), Real.log_exp] at hlog + have hb : Real.log (F k) ≤ Real.log C / (1 - η) := by + apply (le_div_iff₀ (sub_pos.mpr hη1)).mpr + nlinarith + intro i + apply (hFm i).trans + simpa only [Real.exp_log hFk0] using Real.exp_le_exp.mpr hb + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PackingBlob.lean b/lean/OAI/Probability/RadialTransition/PackingBlob.lean new file mode 100644 index 0000000000000000000000000000000000000000..c268e44c19faa500c967c444a763263a7c372a24 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PackingBlob.lean @@ -0,0 +1,88 @@ +import OAI.Probability.RadialTransition.TetraGeometry + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +def packingBlob (ν b : ℝ) (z : Position) : Set Position := translateSet ((1+ν) • z) (cube b) + +lemma packingBlob_distance {ν b : ℝ} {z x : Position} (hb : 0 ≤ b) + (hx : x ∈ packingBlob ν b z) : dist x ((1+ν) • z) ≤ 2*b := by + apply dist_le_twice_coordinate hb + intro k + have hk := hx k + change 0 ≤ x k-(1+ν)*z k ∧ x k-(1+ν)*z k ≤ b at hk + change |x k-(1+ν)*z k| ≤ b + rw [abs_of_nonneg hk.1] + exact hk.2 + +lemma packingBlob_separation {ν b : ℝ} {z w x y : Position} (hν : 0 ≤ ν) (hb : 0 ≤ b) + (hzw : 1 ≤ dist z w) (hx : x ∈ packingBlob ν b z) (hy : y ∈ packingBlob ν b w) : + 1+ν-4*b ≤ dist x y := by + have hz := packingBlob_distance hb hx + have hw := packingBlob_distance hb hy + have hd : dist ((1+ν) • z) ((1+ν) • w) = (1+ν)*dist z w := by + rw [dist_eq_norm, ← smul_sub, norm_smul, Real.norm_eq_abs, abs_of_nonneg (by linarith), dist_eq_norm] + have he := dist_triangle4 ((1+ν) • z) x y ((1+ν) • w) + rw [hd, dist_comm ((1+ν) • z) x] at he + have hm := mul_le_mul_of_nonneg_left hzw (show 0 ≤ 1+ν by linarith) + linarith + +lemma packingBlob_subset_cube {L ν b : ℝ} (hν : 0 ≤ ν) {z : Position} (hz : z ∈ cube L) : + packingBlob ν b z ⊆ cube ((1+ν)*L+b) := by + intro x hx k + have hk := hx k + change 0 ≤ x k-(1+ν)*z k ∧ x k-(1+ν)*z k ≤ b at hk + have hzk := hz k + have hl : 0 ≤ (1+ν)*z k := mul_nonneg (by linarith) hzk.1 + have hu := mul_le_mul_of_nonneg_left hzk.2 (show 0 ≤ 1+ν by linarith) + constructor <;> linarith + +lemma core_grand_packing_lower {L ν b t β h : ℝ} (ht : 0 < t) (hb : 0 ≤ b) + (hν : 0 ≤ ν) (hsep : 1/t+4*b ≤ ν) (hβ : 0 ≤ β) : + grandOn (corePotential t) (cube b) β (t*h) ^ packingNumber L ≤ + grandOn (corePotential t) (cube ((1+ν)*L+b)) β (t*h) := by + classical + obtain ⟨X, hcard, hX⟩ := packingNumber_attained L + let φ := corePotential t + have hc := continuous_corePotential t + have hbound := bounded_corePotential t + have hstable := stable_corePotential t + have hA (z : Position) : MeasurableSet (packingBlob ν b z) := measurableSet_translate (measurableSet_cube _) + have hAfin (z : Position) : volume (packingBlob ν b z) ≠ ⊤ := by + rw [packingBlob, volume_translateSet _ _ (measurableSet_cube _), volume_cube] + finiteness + have hdist (z : Position) (hz : z ∈ X) (w : Position) (hw : w ∈ X) (hne : z ≠ w) + (x : Position) (hx : x ∈ packingBlob ν b z) (y : Position) (hy : y ∈ packingBlob ν b w) : + 1+1/t ≤ dist x y := by + have hh := packingBlob_separation hν hb (hX.2 z hz w hw hne) hx hy + linarith + have hdisj : ∀ z ∈ X, ∀ w ∈ X, z ≠ w → Disjoint (packingBlob ν b z) (packingBlob ν b w) := by + intro z hz w hw hne + apply Set.disjoint_left.mpr + intro x hx hy + have hh := hdist z hz w hw hne x hx x hy + rw [dist_self] at hh + have := one_div_pos.mpr ht + linarith + have hcross : ∀ z ∈ X, ∀ w ∈ X, z ≠ w → ∀ x ∈ packingBlob ν b z, + ∀ y ∈ packingBlob ν b w, φ (nndist x y) ≤ 0 := by + intro z hz w hw hne x hx y hy + exact le_of_eq (coreReal_zero_outer ht (hdist z hz w hw hne x hx y hy)) + have hprod := grandOn_biUnion_lower hc hbound hstable hβ X (packingBlob ν b) (t*h) + (fun z _ => hA z) (fun z _ => hAfin z) hdisj hcross + have hsub : (⋃ z ∈ X, packingBlob ν b z) ⊆ cube ((1+ν)*L+b) := by + intro x hx + obtain ⟨z,hz,hxz⟩ := Set.mem_iUnion₂.mp hx + exact packingBlob_subset_cube hν (hX.1 z hz) hxz + have hcomp := grandOn_mono hc hbound hstable hβ hsub (by rw [volume_cube]; finiteness) (t*h) + simp only [packingBlob, grandOn_translate, Finset.prod_const, hcard] at hprod + exact hprod.trans hcomp + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PackingLimit.lean b/lean/OAI/Probability/RadialTransition/PackingLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..561fd23b0aa2d610709eeadeb0e71307ebf2f1b4 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PackingLimit.lean @@ -0,0 +1,265 @@ +import OAI.Probability.RadialTransition.EnvelopeSupport + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +def IsPacking (L : ℝ) (X : Finset Position) : Prop := + (∀ x ∈ X, x ∈ cube L) ∧ (∀ x ∈ X, ∀ y ∈ X, x ≠ y → 1 ≤ dist x y) + +theorem dist_lt_one_of_coordinate_half {x y : Position} + (h : ∀ k : Fin 3, |x k - y k| < 1 / 2) : dist x y < 1 := by + have hh : dist x y ^ 2 < 1 := by + rw [EuclideanSpace.dist_sq_eq] + have hc (k : Fin 3) : dist (x k) (y k) ^ 2 < (1 / 4 : ℝ) := by + rw [Real.dist_eq] + have hp := h k + nlinarith [abs_nonneg (x k - y k)] + have hs := Finset.sum_lt_sum_of_nonempty (s := Finset.univ) + Finset.univ_nonempty (fun k _ => hc k) + norm_num at hs + linarith + nlinarith [dist_nonneg (x := x) (y := y)] + +theorem packing_card_bound {L : ℝ} {X : Finset Position} (hX : IsPacking L X) : + X.card ≤ (⌊2 * L⌋₊ + 1) ^ 3 := by + classical + let f : X → (Fin 3 → Fin (⌊2 * L⌋₊ + 1)) := fun x k => + ⟨⌊2 * (x : Position) k⌋₊, + Nat.lt_succ_of_le (Nat.floor_le_floor (by linarith [(hX.1 x x.property k).2]))⟩ + have hf : Function.Injective f := by + intro x y hxy + by_contra hne + have hne' : (x : Position) ≠ y := fun h => hne (Subtype.ext h) + have hlo := hX.2 x x.property y y.property hne' + have hhi : dist (x : Position) y < 1 := by + apply dist_lt_one_of_coordinate_half + intro k + have he : ⌊2 * (x : Position) k⌋₊ = ⌊2 * (y : Position) k⌋₊ := + congrArg Fin.val (congrFun hxy k) + have hx0 := (hX.1 x x.property k).1 + have hy0 := (hX.1 y y.property k).1 + have hxL := Nat.floor_le (show 0 ≤ 2 * (x : Position) k by positivity) + have hyL := Nat.floor_le (show 0 ≤ 2 * (y : Position) k by positivity) + have hxU := Nat.lt_floor_add_one (2 * (x : Position) k) + have hyU := Nat.lt_floor_add_one (2 * (y : Position) k) + rw [he] at hxL hxU + apply abs_lt.mpr + constructor <;> linarith + linarith + simpa using Fintype.card_le_of_injective f hf + +theorem packing_card_set_bddAbove (L : ℝ) : + BddAbove {n : ℕ | ∃ X : Finset Position, X.card = n ∧ IsPacking L X} := by + refine ⟨(⌊2 * L⌋₊ + 1) ^ 3, ?_⟩ + rintro n ⟨X, rfl, hX⟩ + exact packing_card_bound hX + +theorem packingNumber_attained (L : ℝ) : + ∃ X : Finset Position, X.card = packingNumber L ∧ IsPacking L X := by + exact Nat.sSup_mem (s := {n : ℕ | ∃ X : Finset Position, X.card = n ∧ IsPacking L X}) + ⟨0, ∅, by simp [IsPacking]⟩ (packing_card_set_bddAbove L) + +theorem packing_card_le {L : ℝ} {X : Finset Position} (hX : IsPacking L X) : + X.card ≤ packingNumber L := + le_csSup (packing_card_set_bddAbove L) ⟨X, rfl, hX⟩ + +theorem packingNumber_bound (L : ℝ) : + packingNumber L ≤ (⌊2 * L⌋₊ + 1) ^ 3 := by + obtain ⟨X, hcard, hX⟩ := packingNumber_attained L + simpa only [hcard] using packing_card_bound hX + +theorem packingNumber_pos {L : ℝ} (hL : 0 ≤ L) : 0 < packingNumber L := by + have hh : IsPacking L {0} := by + constructor + · intro x hx + simp only [Finset.mem_singleton] at hx + subst x + intro k + simp [hL] + · intro x hx y hy hne + simp only [Finset.mem_singleton] at hx hy + exact (hne (hx.trans hy.symm)).elim + have := packing_card_le hh + simp only [Finset.card_singleton] at this + omega + +def packingTranslate {n : ℕ} (s : ℝ) (j : Fin 3 → Fin n) (x : Position) : Position := + WithLp.toLp 2 (fun k => (j k : ℝ) * (s + 1) + x k) + +@[simp] theorem packingTranslate_apply {n : ℕ} (s : ℝ) (j : Fin 3 → Fin n) + (x : Position) (k : Fin 3) : packingTranslate s j x k = (j k : ℝ) * (s + 1) + x k := rfl + +theorem packingTranslate_mem_cube {n : ℕ} {s L : ℝ} (hs : 0 ≤ s) + (hn : (n : ℝ) * (s + 1) ≤ L) (j : Fin 3 → Fin n) + {x : Position} (hx : x ∈ cube s) : packingTranslate s j x ∈ cube L := by + intro k + have hj : (j k : ℝ) + 1 ≤ n := by exact_mod_cast (j k).isLt + have hj0 : 0 ≤ (j k : ℝ) := by positivity + have hx0 : 0 ≤ x k := (hx k).1 + have hh := mul_le_mul_of_nonneg_right hj (show 0 ≤ s + 1 by linarith) + simp only [packingTranslate_apply] + constructor + · positivity + · linarith [(hx k).2] + +theorem packingTranslate_dist_same {n : ℕ} (s : ℝ) (j : Fin 3 → Fin n) + (x y : Position) : dist (packingTranslate s j x) (packingTranslate s j y) = dist x y := by + simp only [dist_eq_norm] + congr 1 + ext k + simp only [PiLp.sub_apply, packingTranslate_apply] + ring + +theorem packingTranslate_separated {n : ℕ} {s : ℝ} (hs : 0 ≤ s) + {j k : Fin 3 → Fin n} (hjk : j ≠ k) {x y : Position} + (hx : x ∈ cube s) (hy : y ∈ cube s) : + 1 ≤ dist (packingTranslate s j x) (packingTranslate s k y) := by + have hcoord {j k : Fin 3 → Fin n} {x y : Position} + (hx : x ∈ cube s) (hy : y ∈ cube s) (q : Fin 3) (h : j q < k q) : + 1 ≤ dist (packingTranslate s j x) (packingTranslate s k y) := by + have hq : (j q : ℝ) + 1 ≤ (k q : ℝ) := by exact_mod_cast h + have hh := mul_le_mul_of_nonneg_right hq (show 0 ≤ s + 1 by linarith) + have hlo : 1 ≤ packingTranslate s k y q - packingTranslate s j x q := by + simp only [packingTranslate_apply] + linarith [(hx q).2, (hy q).1] + have hnorm := PiLp.norm_apply_le (packingTranslate s k y - packingTranslate s j x) q + simp only [PiLp.sub_apply, Real.norm_eq_abs] at hnorm + calc + 1 ≤ packingTranslate s k y q - packingTranslate s j x q := hlo + _ ≤ |packingTranslate s k y q - packingTranslate s j x q| := le_abs_self _ + _ ≤ ‖packingTranslate s k y - packingTranslate s j x‖ := hnorm + _ = dist (packingTranslate s j x) (packingTranslate s k y) := by rw [← dist_eq_norm, dist_comm] + obtain ⟨q, hq⟩ := Function.ne_iff.mp hjk + rcases lt_or_gt_of_ne hq with h | h + · exact hcoord hx hy q h + · simpa only [dist_comm] using hcoord hy hx q h + +theorem packingNumber_replication {s L : ℝ} (hs : 0 ≤ s) (n : ℕ) + (hn : (n : ℝ) * (s + 1) ≤ L) : + n ^ 3 * packingNumber s ≤ packingNumber L := by + classical + obtain ⟨X, hcard, hX⟩ := packingNumber_attained s + let f : (Fin 3 → Fin n) × X → Position := fun a => packingTranslate s a.1 a.2 + have hsep (a b : (Fin 3 → Fin n) × X) (hab : a ≠ b) : 1 ≤ dist (f a) (f b) := by + by_cases hj : a.1 = b.1 + · have hx : (a.2 : Position) ≠ b.2 := by + intro hx + apply hab + exact Prod.ext hj (Subtype.ext hx) + dsimp [f] + rw [hj, packingTranslate_dist_same] + exact hX.2 _ a.2.property _ b.2.property hx + · exact packingTranslate_separated hs hj (hX.1 _ a.2.property) (hX.1 _ b.2.property) + have hfinj : Function.Injective f := by + intro a b h + by_contra hab + have := hsep a b hab + norm_num [h] at this + let Y := Finset.univ.image f + have hYcard : Y.card = n ^ 3 * packingNumber s := by + rw [Finset.card_image_of_injective _ hfinj] + simp [hcard] + have hY : IsPacking L Y := by + constructor + · intro y hy + obtain ⟨a, _, rfl⟩ := Finset.mem_image.mp hy + exact packingTranslate_mem_cube hs hn a.1 (hX.1 _ a.2.property) + · intro y hy z hz hyz + obtain ⟨a, _, rfl⟩ := Finset.mem_image.mp hy + obtain ⟨b, _, rfl⟩ := Finset.mem_image.mp hz + exact hsep a b (fun hab => hyz (congrArg f hab)) + rw [← hYcard] + exact packing_card_le hY + +def packingDensity : ℝ := + sSup {r : ℝ | ∃ s : ℝ, 0 ≤ s ∧ r = (packingNumber s : ℝ) / (s + 1) ^ 3} + +theorem packing_ratio_bound {s : ℝ} (hs : 0 ≤ s) : + (packingNumber s : ℝ) / (s + 1) ^ 3 ≤ 8 := by + have hc : (packingNumber s : ℝ) ≤ ((⌊2 * s⌋₊ : ℝ) + 1) ^ 3 := by + exact_mod_cast packingNumber_bound s + have hf := Nat.floor_le (show 0 ≤ 2 * s by positivity) + have hg : ((⌊2 * s⌋₊ : ℝ) + 1) ^ 3 ≤ (2 * (s + 1)) ^ 3 := by + gcongr + linarith + apply (div_le_iff₀ (by positivity : 0 < (s + 1) ^ 3)).mpr + nlinarith [hc.trans hg] + +theorem packing_ratios_bdd : + BddAbove {r : ℝ | ∃ s : ℝ, 0 ≤ s ∧ r = (packingNumber s : ℝ) / (s + 1) ^ 3} := by + refine ⟨8, ?_⟩ + rintro r ⟨s, hs, rfl⟩ + exact packing_ratio_bound hs + +theorem packing_ratios_nonempty : + ({r : ℝ | ∃ s : ℝ, 0 ≤ s ∧ r = (packingNumber s : ℝ) / (s + 1) ^ 3}).Nonempty := + ⟨_, 0, le_rfl, rfl⟩ + +theorem packing_ratio_le_density {s : ℝ} (hs : 0 ≤ s) : + (packingNumber s : ℝ) / (s + 1) ^ 3 ≤ packingDensity := + le_csSup packing_ratios_bdd ⟨s, hs, rfl⟩ + +theorem packingDensity_pos : 0 < packingDensity := by + have h := packing_ratio_le_density (s := 0) le_rfl + have hp : (0 : ℝ) < packingNumber 0 := by exact_mod_cast packingNumber_pos (L := 0) le_rfl + norm_num at h + exact hp.trans_le h + +theorem packing_lower_approximation {s : ℝ} (hs : 0 ≤ s) : + Tendsto (fun L : ℝ => ((⌊L / (s + 1)⌋₊ : ℝ) / L) ^ 3 * packingNumber s) + atTop (nhds ((packingNumber s : ℝ) / (s + 1) ^ 3)) := by + have h := (tendsto_nat_floor_mul_div_atTop (show 0 ≤ (s + 1)⁻¹ by positivity)).pow 3 + have h' := h.mul_const (packingNumber s : ℝ) + simpa only [div_eq_mul_inv, inv_pow, mul_comm] using h' + +theorem packing_lower_approximation_le {s L : ℝ} (hs : 0 ≤ s) (hL : 0 < L) : + ((⌊L / (s + 1)⌋₊ : ℝ) / L) ^ 3 * packingNumber s ≤ + (packingNumber L : ℝ) / L ^ 3 := by + have hn : (⌊L / (s + 1)⌋₊ : ℝ) * (s + 1) ≤ L := by + apply (le_div_iff₀ (by positivity : 0 < s + 1)).mp + exact Nat.floor_le (by positivity) + have h := packingNumber_replication hs ⌊L / (s + 1)⌋₊ hn + have hr : (⌊L / (s + 1)⌋₊ : ℝ) ^ 3 * packingNumber s ≤ packingNumber L := by + exact_mod_cast h + calc + _ = ((⌊L / (s + 1)⌋₊ : ℝ) ^ 3 * packingNumber s) / L ^ 3 := by ring + _ ≤ (packingNumber L : ℝ) / L ^ 3 := div_le_div_of_nonneg_right hr (by positivity) + +theorem packing_upper_approximation_le {L : ℝ} (hL : 0 < L) : + (packingNumber L : ℝ) / L ^ 3 ≤ packingDensity * (1 + L⁻¹) ^ 3 := by + have h := packing_ratio_le_density hL.le + have h' : (packingNumber L : ℝ) ≤ packingDensity * (L + 1) ^ 3 := + (div_le_iff₀ (by positivity : 0 < (L + 1) ^ 3)).mp h + apply (div_le_iff₀ (by positivity : 0 < L ^ 3)).mpr + calc + _ ≤ packingDensity * (L + 1) ^ 3 := h' + _ = packingDensity * (1 + L⁻¹) ^ 3 * L ^ 3 := by field_simp + +theorem packingDensity_limit : IsPackingDensity packingDensity := by + apply tendsto_order.mpr + constructor + · intro a ha + obtain ⟨r, ⟨s, hs, rfl⟩, har⟩ := + (lt_csSup_iff packing_ratios_bdd packing_ratios_nonempty).mp ha + have he := (packing_lower_approximation hs).eventually_const_lt har + filter_upwards [he, eventually_gt_atTop (0 : ℝ)] with L hlow hL + exact hlow.trans_le (packing_lower_approximation_le hs hL) + · intro a ha + have hu : Tendsto (fun L : ℝ => packingDensity * (1 + L⁻¹) ^ 3) + atTop (nhds packingDensity) := by + have h := ((tendsto_const_nhds (x := (1 : ℝ))).add tendsto_inv_atTop_zero).pow 3 + simpa using h.const_mul packingDensity + filter_upwards [hu.eventually_lt_const ha, eventually_gt_atTop (0 : ℝ)] with L hhi hL + exact (packing_upper_approximation_le hL).trans_lt hhi + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PairEnsembles.lean b/lean/OAI/Probability/RadialTransition/PairEnsembles.lean new file mode 100644 index 0000000000000000000000000000000000000000..526727fd744bc753de2e87bcf36d5ca2bca007c3 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PairEnsembles.lean @@ -0,0 +1,150 @@ +import OAI.Probability.RadialTransition.MeasurableEnergy + +namespace OAI + +universe uX uY uI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +section MeasurablePairs +variable {X : Type uX} {Y : Type uY} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] + [TopologicalSpace Y] [MeasurableSpace Y] [BorelSpace Y] [SecondCountableTopology Y] + +lemma measurable_pairWithin (v : X → X → ℝ) + (hv : Measurable (Function.uncurry v)) : Measurable (pairWithin v) := by + apply measurable_particle_iff.mpr + intro n + change Measurable (fun a : Fin n → X => (1/2:ℝ) * + ∑ i : Fin n, ∑ j : Fin n, if i = j then 0 else v (a i) (a j)) + apply measurable_const.mul + apply Finset.measurable_sum + intro i _ + apply Finset.measurable_sum + intro j _ + by_cases h : i = j + · simp only [h, ite_true]; exact measurable_const + · simp only [h, ite_false] + exact hv.comp (show Measurable (fun a : Fin n → X => (a i, a j)) from + (measurable_pi_apply i).prodMk (measurable_pi_apply j)) + +lemma measurable_pairBetween (v : X → Y → ℝ) + (hv : Measurable (Function.uncurry v)) : Measurable (Function.uncurry (pairBetween v)) := by + apply measurable_particle_prod + intro m n + change Measurable (fun p : (Fin m → X) × (Fin n → Y) => + ∑ i : Fin m, ∑ j : Fin n, v (p.1 i) (p.2 j)) + exact Finset.measurable_sum _ (fun i _ => Finset.measurable_sum _ (fun j _ => + hv.comp (show Measurable (fun p : (Fin m → X) × (Fin n → Y) => (p.1 i, p.2 j)) from + ((measurable_pi_apply i).comp measurable_fst).prodMk + ((measurable_pi_apply j).comp measurable_snd)))) + +end MeasurablePairs +section MeasurablePairCells +variable {I : Type uI} [Fintype I] [DecidableEq I] {X : I → Type uX} + [∀ i, TopologicalSpace (X i)] [∀ i, MeasurableSpace (X i)] + [∀ i, BorelSpace (X i)] [∀ i, SecondCountableTopology (X i)] + +lemma measurable_pairCellEnergy (v : ∀ i j, X i → X j → ℝ) + (hv : ∀ i j, Measurable (Function.uncurry (v i j))) : Measurable (pairCellEnergy v) := by + unfold pairCellEnergy cellHamiltonian + apply Measurable.add + · exact Finset.measurable_sum _ (fun i _ => (measurable_pairWithin _ (hv i i)).comp (measurable_pi_apply i)) + · apply measurable_const.mul + apply Finset.measurable_sum + intro i _ + apply Finset.measurable_sum + intro j _ + by_cases h : i = j + · simp only [h, ite_true]; exact measurable_const + · simp only [h, ite_false] + exact (measurable_pairBetween _ (hv i j)).comp + (show Measurable (fun a : ∀ k, ParticleState (X k) => (a i, a j)) from + (measurable_pi_apply i).prodMk (measurable_pi_apply j)) + +omit [∀ i, TopologicalSpace (X i)] [∀ i, MeasurableSpace (X i)] + [∀ i, BorelSpace (X i)] [∀ i, SecondCountableTopology (X i)] in +lemma pairCellEnergy_no_cross (v : ∀ i j, X i → X j → ℝ) + (hcross : ∀ i j, i ≠ j → ∀ x y, v i j x y = 0) (x : ∀ i, ParticleState (X i)) : + pairCellEnergy v x = ∑ i, pairWithin (v i i) (x i) := by + unfold pairCellEnergy cellHamiltonian + have hz (i j : I) : (if i = j then 0 else pairBetween (v i j) (x i) (x j)) = 0 := by + split_ifs with h + · rfl + · simp [pairBetween, hcross i j h] + simp only [hz, Finset.sum_const_zero, mul_zero, add_zero] + +lemma boltzmannPartition_no_cross (ν : ∀ i, Measure (X i)) [∀ i, IsFiniteMeasure (ν i)] + (v : ∀ i j, X i → X j → ℝ) + (hcross : ∀ i j, i ≠ j → ∀ x y, v i j x y = 0) (β z : ℝ) : + boltzmannPartition (Measure.pi (fun i => particleBase (ν i) z)) (fun x => β * pairCellEnergy v x) = + ∏ i, boltzmannPartition (particleBase (ν i) z) (fun x => β * pairWithin (v i i) x) := by + unfold boltzmannPartition + simp_rw [pairCellEnergy_no_cross v hcross, ← neg_mul, Finset.mul_sum, Real.exp_sum] + exact integral_fintype_prod_eq_prod (fun i (x : ParticleState (X i)) => + Real.exp (-β * pairWithin (v i i) x)) + +end MeasurablePairCells + +section GeneralGrand +variable {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] + +def pairGrand (v : X → X → ℝ) (μ : Measure X) (β z : ℝ) : ℝ := + ∫ x, Real.exp (-β * multisetEnergy v (particleMultiset x)) ∂particleBase μ z + +lemma pairGrand_eq_cell {I : Type} [Fintype I] [DecidableEq I] + (Y : I → Type uY) [∀ i, TopologicalSpace (Y i)] [∀ i, MeasurableSpace (Y i)] + [∀ i, BorelSpace (Y i)] [∀ i, SecondCountableTopology (Y i)] + (ν : ∀ i, Measure (Y i)) [∀ i, IsFiniteMeasure (ν i)] + (pos : ∀ i, Y i → X) (hpos : ∀ i, Measurable (pos i)) + (v : X → X → ℝ) (hv : Measurable (Function.uncurry v)) (hsym : ∀ x y, v x y = v y x) + {μ : Measure X} (hdecomp : μ = ∑ i, Measure.map (pos i) (ν i)) (β z : ℝ) : + pairGrand v μ β z = boltzmannPartition (Measure.pi (fun i => particleBase (ν i) z)) + (fun x => β * pairCellEnergy (fun i j a b => v (pos i a) (pos j b)) x) := by + have hcfg := measurableConfiguration_boltzmann hv hsym β + have hleft : Measurable (fun x : ParticleState X => Real.exp (-β * multisetEnergy v (particleMultiset x))) := by + apply measurable_particle_iff.mpr + intro n + exact Real.measurable_exp.comp (measurable_const.mul (measurable_multisetEnergy_configuration hv)) + have hright : Measurable (fun x : ∀ i, ParticleState (Y i) => + Real.exp (-(β * pairCellEnergy (fun i j a b => v (pos i a) (pos j b)) x))) := by + apply Real.measurable_exp.comp + apply Measurable.neg + apply measurable_const.mul + apply measurable_pairCellEnergy + intro i j + exact hv.comp (((hpos i).comp measurable_fst).prodMk ((hpos j).comp measurable_snd)) + rw [pairGrand, boltzmannPartition, + integral_eq_lintegral_of_nonneg_ae (Eventually.of_forall (fun x => (Real.exp_pos _).le)) hleft.aestronglyMeasurable, + integral_eq_lintegral_of_nonneg_ae (Eventually.of_forall (fun x => (Real.exp_pos _).le)) hright.aestronglyMeasurable] + congr 1 + have hh := particleBase_sum_map_observable_meas Y + (fun s => ENNReal.ofReal (Real.exp (-β * multisetEnergy v s))) hcfg ν pos hpos z 0 + simp only [zero_add, multisetEnergy_mappedMulti] at hh + simpa only [hdecomp, neg_mul] using hh + +end GeneralGrand + +lemma pairGrand_radial {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B β : ℝ} (hs : StableWith φ B) (hβ : 0 ≤ β) {A : Set Position} + (hAfin : volume A ≠ ⊤) (z : ℝ) : + pairGrand (radialPair φ) (volume.restrict A) β z = grandOn φ A β z := by + have hm : Measurable (fun x : ParticleState Position => Real.exp (-β * multisetEnergy (radialPair φ) (particleMultiset x))) := by + simpa only [multisetEnergy_radial] using measurable_particleBoltzmann hφ β + rw [pairGrand, integral_eq_lintegral_of_nonneg_ae + (Eventually.of_forall (fun x => (Real.exp_pos _).le)) hm.aestronglyMeasurable] + simp only [multisetEnergy_radial] + rw [lintegral_grandOn hφ hb hs hβ hAfin z, + ENNReal.toReal_ofReal (zero_le_one.trans (grandOn_bounds hφ hb hs hβ hAfin z).1)] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ParameterPressure.lean b/lean/OAI/Probability/RadialTransition/ParameterPressure.lean new file mode 100644 index 0000000000000000000000000000000000000000..010d10f97ad456b14e2dac29448107dbea49f429 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ParameterPressure.lean @@ -0,0 +1,108 @@ +import OAI.Probability.RadialTransition.FamilyIdeal + +namespace OAI + +universe uX + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +abbrev Parameter := EuclideanSpace ℝ (Fin 2) +def parameter (β h : ℝ) : Parameter := WithLp.toLp 2 ![β,h] +def positiveParameters : Set Parameter := {x | 0 < x 0} +def onParameters (Q : Pressure) (x : Parameter) : ℝ := Q (x 0) (x 1) + +@[simp] lemma parameter_zero (β h : ℝ) : parameter β h 0 = β := rfl +@[simp] lemma parameter_one (β h : ℝ) : parameter β h 1 = h := rfl +@[simp] lemma parameter_eta (x : Parameter) : parameter (x 0) (x 1) = x := by + ext i + fin_cases i <;> rfl + +lemma parameter_inner (x y : Parameter) : inner ℝ x y = x 0*y 0+x 1*y 1 := by + simp [PiLp.inner_apply, Fin.sum_univ_two, mul_comm] + +lemma parameter_coord_abs_le (x : Parameter) (i : Fin 2) : |x i| ≤ ‖x‖ := by + simpa only [Real.norm_eq_abs] using PiLp.norm_apply_le (p := (2:ℝ≥0∞)) x i + +lemma parameter_norm_le (x : Parameter) : ‖x‖ ≤ |x 0|+|x 1| := by + have hh : ‖x‖^2 = |x 0|^2+|x 1|^2 := by + rw [EuclideanSpace.norm_sq_eq] + simp only [Fin.sum_univ_two, Real.norm_eq_abs] + nlinarith [norm_nonneg x, abs_nonneg (x 0), abs_nonneg (x 1), + mul_nonneg (abs_nonneg (x 0)) (abs_nonneg (x 1))] + +lemma continuous_parameter {X : Type uX} [TopologicalSpace X] (β h : X → ℝ) (hβ : Continuous β) (hh : Continuous h) : + Continuous (fun x => parameter (β x) (h x)) := by + apply (PiLp.continuous_toLp 2 (fun _ : Fin 2 => ℝ)).comp + apply continuous_pi + intro i + fin_cases i + · exact hβ + · exact hh + +lemma isOpen_positiveParameters : IsOpen positiveParameters := by + exact isOpen_lt continuous_const (PiLp.continuous_apply 2 (fun _ : Fin 2 => ℝ) (0:Fin 2)) + +lemma convex_positiveParameters : Convex ℝ positiveParameters := by + intro x hx y hy a b ha hb hab + change 0 < a*x 0+b*y 0 + have hh := lt_min (show 0 < x 0 from hx) (show 0 < y 0 from hy) + have hm := mul_pos (show 0 < a+b by linarith) hh + have h1 := mul_le_mul_of_nonneg_left (min_le_left (x 0) (y 0)) ha + have h2 := mul_le_mul_of_nonneg_left (min_le_right (x 0) (y 0)) hb + nlinarith + +lemma pressureSupport_iff {Q : Pressure} {x v : Parameter} : + pressureSupport Q (x 0) (x 1) (v 0) (v 1) ↔ + SupportsOn (onParameters Q) positiveParameters x v := by + constructor + · intro hs y hy + have hh := hs (y 0) (y 1) hy + simpa only [onParameters, parameter_inner, PiLp.sub_apply, add_assoc] using hh + · intro hs β h hβ + have hh := hs (parameter β h) hβ + simpa only [onParameters, parameter_inner, PiLp.sub_apply, parameter_zero, parameter_one, add_assoc] using hh + +lemma convexOn_grandPressure {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t : ℝ} (hst : StableWith φ B) (ht : 0 < t) + (hc : ∀ r : ℝ≥0, 2 ≤ (r:ℝ) → φ r ≤ 0) : + ConvexOn ℝ positiveParameters (onParameters (grandPressure φ t)) := by + refine ⟨convex_positiveParameters, ?_⟩ + intro x hx y hy a b ha hbb hab + exact grandPressure_convex_mix hφ hb hst ht hc hx.le hy.le (x 1) (y 1) ha hbb hab + +lemma convexOn_attractionBranch {Q : Pressure} (hQ : ConvexOn ℝ positiveParameters (onParameters Q)) + (a u : ℝ) : ConvexOn ℝ positiveParameters (onParameters (attractionBranch Q a u)) := by + refine ⟨convex_positiveParameters, ?_⟩ + intro x hx y hy c d hc hd hcd + have hh := hQ.2 (show parameter (x 0) (x 1+x 0*a*u) ∈ positiveParameters from hx) + (show parameter (y 0) (y 1+y 0*a*u) ∈ positiveParameters from hy) hc hd hcd + have he : c • parameter (x 0) (x 1+x 0*a*u)+d • parameter (y 0) (y 1+y 0*a*u) = + parameter (c*x 0+d*y 0) (c*x 1+d*y 1+(c*x 0+d*y 0)*a*u) := by + ext i + fin_cases i <;> simp [PiLp.add_apply, PiLp.smul_apply]; ring + rw [he] at hh + dsimp only [onParameters, attractionBranch, parameter_zero, parameter_one] at hh ⊢ + simp only [PiLp.add_apply, PiLp.smul_apply, smul_eq_mul] at hh ⊢ + nlinarith + +lemma convexOn_idealAttraction {Q : Pressure} (hQ : ConvexOn ℝ positiveParameters (onParameters Q)) + {a : ℝ} (hactive : ∀ β h, 0 < β → ∃ u, ActiveShift Q a β h u) : + ConvexOn ℝ positiveParameters (onParameters (idealAttraction Q a)) := by + refine ⟨convex_positiveParameters, ?_⟩ + intro x hx y hy c d hc hd hcd + have hz := convex_positiveParameters hx hy hc hd hcd + obtain ⟨u, hu⟩ := hactive _ _ hz + obtain ⟨v, hv⟩ := hactive _ _ hx + obtain ⟨w, hw⟩ := hactive _ _ hy + have hh := (convexOn_attractionBranch hQ a u).2 hx hy hc hd hcd + change idealAttraction Q a _ _ ≤ c*idealAttraction Q a _ _+d*idealAttraction Q a _ _ + rw [idealAttraction_eq_of_active hu, idealAttraction_eq_of_active hv, idealAttraction_eq_of_active hw] + exact hh.trans (add_le_add (mul_le_mul_of_nonneg_left (hv u) hc) (mul_le_mul_of_nonneg_left (hw u) hd)) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ParameterTools.lean b/lean/OAI/Probability/RadialTransition/ParameterTools.lean new file mode 100644 index 0000000000000000000000000000000000000000..29ffa0aeb1130bd5a3fb1ddb2e3397c258e0d2a4 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ParameterTools.lean @@ -0,0 +1,70 @@ +import OAI.Probability.RadialTransition.InitialSlopes + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma phaseWindow_coords {x : Parameter} {r : ℝ} (hx : x ∈ phaseWindow r) : + |x 0-1| ≤ r ∧ |x 1+3/4| ≤ r := by + have hn : ‖x-phaseCenter‖ ≤ r := Metric.mem_closedBall.mp hx + constructor + · exact (parameter_coord_abs_le (x-phaseCenter) 0).trans hn + · have hh := (parameter_coord_abs_le (x-phaseCenter) 1).trans hn + change |x 1-(-3/4)| ≤ r at hh + simpa only [neg_div, sub_neg_eq_add] using hh + +lemma phaseWindow_positive {x : Parameter} {r : ℝ} (hr : r < 1) (hx : x ∈ phaseWindow r) : + x ∈ positiveParameters := by + have hh := (abs_le.mp (phaseWindow_coords hx).1).1 + change 0 < x 0 + linarith + +lemma phaseWindow_mono {r s : ℝ} (h : r ≤ s) : phaseWindow r ⊆ phaseWindow s := + Metric.closedBall_subset_closedBall h + +lemma phaseWindow_near {x y : Parameter} {r s : ℝ} (hx : x ∈ phaseWindow r) + (hy : y ∈ Metric.closedBall x s) : y ∈ phaseWindow (r+s) := by + change dist y phaseCenter ≤ r+s + calc + dist y phaseCenter ≤ dist y x+dist x phaseCenter := dist_triangle _ _ _ + _ ≤ r+s := by have h1 := Metric.mem_closedBall.mp hx; have h2 := Metric.mem_closedBall.mp hy; linarith + +lemma phaseWindow_quarter_bounds {x : Parameter} (hx : x ∈ phaseWindow (1/4)) : + x 0 ∈ Icc (3/4:ℝ) (5/4) ∧ |x 1| ≤ 2 := by + have h1 := abs_le.mp (phaseWindow_coords hx).1 + have h2 := abs_le.mp (phaseWindow_coords hx).2 + constructor + · constructor <;> linarith + · rw [abs_le]; constructor <;> linarith + +lemma phaseWindow_half_bounds {x : Parameter} (hx : x ∈ phaseWindow (1/2)) : + x 0 ∈ Icc (1/2:ℝ) (3/2) ∧ |x 1| ≤ 2 := by + have h1 := abs_le.mp (phaseWindow_coords hx).1 + have h2 := abs_le.mp (phaseWindow_coords hx).2 + constructor + · constructor <;> linarith + · rw [abs_le]; constructor <;> linarith + +lemma parameter_vertical_norm (h : ℝ) : ‖parameter 0 h‖ = |h| := by + have hn := parameter_norm_le (parameter 0 h) + have hl := parameter_coord_abs_le (parameter 0 h) 1 + simp only [parameter_zero, parameter_one, abs_zero, zero_add] at hn hl + exact le_antisymm hn hl + +lemma parameter_horizontal_norm (β : ℝ) : ‖parameter β 0‖ = |β| := by + have hn := parameter_norm_le (parameter β 0) + have hl := parameter_coord_abs_le (parameter β 0) 0 + simp only [parameter_zero, parameter_one, abs_zero, add_zero] at hn hl + exact le_antisymm hn hl + +lemma parameter_sub (β h β' h' : ℝ) : parameter β h-parameter β' h'=parameter (β-β') (h-h') := by + ext i + fin_cases i <;> rfl + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ParticleMeasure.lean b/lean/OAI/Probability/RadialTransition/ParticleMeasure.lean new file mode 100644 index 0000000000000000000000000000000000000000..fa26d0ce282af094bf30398c768071b04bbc8b1c --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ParticleMeasure.lean @@ -0,0 +1,125 @@ +import OAI.Probability.RadialTransition.OccupationMoments + +namespace OAI + +universe uX uY + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +abbrev ParticleState (X : Type uX) := Σ n : ℕ, Fin n → X + +variable {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] + [BorelSpace X] [SecondCountableTopology X] +instance : MeasurableSpace (ParticleState X) := borel (ParticleState X) +instance : BorelSpace (ParticleState X) := ⟨rfl⟩ + +def particleCount (x : ParticleState X) : ℕ := x.1 + +omit [MeasurableSpace X] [BorelSpace X] [SecondCountableTopology X] in +theorem continuous_particleCount : Continuous (particleCount (X := X)) := + continuous_sigma (fun _ => continuous_const) + +theorem measurable_particle_mk (n : ℕ) : Measurable (@Sigma.mk ℕ (fun n => Fin n → X) n) := + continuous_sigmaMk.measurable + +theorem measurable_particle_iff {Y : Type uY} [MeasurableSpace Y] {f : ParticleState X → Y} : + Measurable f ↔ ∀ n, Measurable (fun x : Fin n → X => f ⟨n,x⟩) := by + constructor + · intro hf n + exact hf.comp (measurable_particle_mk n) + · intro hf s hs + have he : f ⁻¹' s = ⋃ n : ℕ, Sigma.mk n '' ((fun x : Fin n → X => f ⟨n,x⟩) ⁻¹' s) := by + exact (iUnion_image_preimage_sigma_mk_eq_self (f ⁻¹' s)).symm + rw [he] + apply MeasurableSet.iUnion + intro n + exact (Topology.IsOpenEmbedding.sigmaMk.measurableEmbedding).measurableSet_image.mpr (hf n hs) + +def particleBase (ν : Measure X) (z : ℝ) : Measure (ParticleState X) := + Measure.sum (fun n : ℕ => ENNReal.ofReal (Real.exp (z*n) / n.factorial) • + Measure.map (Sigma.mk n) (Measure.pi (fun _ : Fin n => ν))) + +theorem lintegral_particleBase (ν : Measure X) (z : ℝ) {f : ParticleState X → ℝ≥0∞} + (hf : Measurable f) : + (∫⁻ x, f x ∂particleBase ν z) = + ∑' n : ℕ, ENNReal.ofReal (Real.exp (z*n) / n.factorial) * + ∫⁻ x : Fin n → X, f ⟨n,x⟩ ∂Measure.pi (fun _ => ν) := by + rw [particleBase, lintegral_sum_measure] + apply tsum_congr + intro n + rw [lintegral_smul_measure, lintegral_map hf (measurable_particle_mk n)] + rfl + +theorem particleBase_univ {ν : Measure X} (hA : ν univ ≠ ⊤) (z : ℝ) : + particleBase ν z univ = ENNReal.ofReal (Real.exp ((ν univ).toReal * Real.exp z)) := by + let : IsFiniteMeasure ν := ⟨lt_top_iff_ne_top.mpr hA⟩ + have hV : 0 ≤ (ν univ).toReal := ENNReal.toReal_nonneg + have hf (n : ℕ) : 0 ≤ ((ν univ).toReal * Real.exp z)^n / n.factorial := by positivity + have he (n : ℕ) : ENNReal.ofReal (Real.exp (z*n) / n.factorial) * (ν univ)^n = + ENNReal.ofReal (((ν univ).toReal * Real.exp z)^n / n.factorial) := by + rw [← ENNReal.ofReal_toReal hA, ← ENNReal.ofReal_pow hV, + ← ENNReal.ofReal_mul (by positivity), mul_pow, ← Real.exp_nat_mul] + simp only [ENNReal.toReal_ofReal hV] + congr 1 + rw [mul_comm z (n : ℝ)] + ring + have hh := lintegral_particleBase ν z (f := fun _ => 1) measurable_const + simp only [lintegral_one, Measure.pi_univ, Finset.prod_const, + Finset.card_univ, Fintype.card_fin] at hh + rw [hh] + simp_rw [he] + rw [← ENNReal.ofReal_tsum_of_nonneg hf (Real.summable_pow_div_factorial _)] + congr 1 + rw [Real.exp_eq_exp_ℝ, NormedSpace.exp_eq_tsum_div] + +instance particleBase_finite {ν : Measure X} (z : ℝ) [IsFiniteMeasure (ν)] : + IsFiniteMeasure (particleBase ν z) := by + constructor + rw [particleBase_univ (measure_ne_top ν univ)] + exact ENNReal.ofReal_lt_top + +def particleVacuum : ParticleState X := ⟨0, Fin.elim0⟩ + +theorem dirac_vacuum_le_particleBase (ν : Measure X) (z : ℝ) [SigmaFinite ν] : + Measure.dirac (particleVacuum (X := X)) ≤ particleBase ν z := by + have hh := Measure.le_sum (fun n : ℕ => ENNReal.ofReal (Real.exp (z*n) / n.factorial) • + Measure.map (Sigma.mk n) (Measure.pi (fun _ : Fin n => ν))) 0 + rw [Measure.pi_of_empty _ Fin.elim0, Measure.map_dirac' (measurable_particle_mk 0)] at hh + simpa [particleBase, particleVacuum] using hh + +theorem lintegral_exp_particleCount (ν : Measure X) [IsFiniteMeasure ν] (z c : ℝ) : + (∫⁻ x, ENNReal.ofReal (Real.exp (c * particleCount x)) ∂particleBase ν z) = + ENNReal.ofReal (Real.exp ((ν univ).toReal * Real.exp (z+c))) := by + have hf : Measurable (fun x : ParticleState X => ENNReal.ofReal (Real.exp (c * particleCount x))) := + (Real.measurable_exp.comp (measurable_const.mul ((continuous_of_discreteTopology : Continuous (fun n : ℕ => (n : ℝ))).comp continuous_particleCount).measurable)).ennreal_ofReal + rw [lintegral_particleBase ν z hf, ← particleBase_univ (measure_ne_top ν univ) (z+c)] + have hh := lintegral_particleBase ν (z+c) (f := fun _ => 1) measurable_const + rw [show particleBase ν (z+c) univ = ∫⁻ _, (1 : ℝ≥0∞) ∂particleBase ν (z+c) by simp, hh] + apply tsum_congr + intro n + simp only [particleCount, lintegral_const, Measure.pi_univ, + Finset.prod_const, Finset.card_univ, Fintype.card_fin, one_mul] + rw [← mul_assoc, ← ENNReal.ofReal_mul (by positivity)] + congr 2 + rw [add_mul, Real.exp_add] + ring + +theorem integrable_exp_particleCount (ν : Measure X) [IsFiniteMeasure ν] (z c : ℝ) : + Integrable (fun x => Real.exp (c * particleCount x)) (particleBase ν z) := by + have hf : Measurable (fun x : ParticleState X => Real.exp (c * particleCount x)) := + Real.measurable_exp.comp (measurable_const.mul ((continuous_of_discreteTopology : Continuous (fun n : ℕ => (n : ℝ))).comp continuous_particleCount).measurable) + refine ⟨hf.aestronglyMeasurable, ?_⟩ + simp only [HasFiniteIntegral, Real.enorm_eq_ofReal (Real.exp_pos _).le] + rw [lintegral_exp_particleCount] + exact ENNReal.ofReal_lt_top + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PartitionReplication.lean b/lean/OAI/Probability/RadialTransition/PartitionReplication.lean new file mode 100644 index 0000000000000000000000000000000000000000..3a02c25b86d3497c3d3e4df91cb37602e43564aa --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PartitionReplication.lean @@ -0,0 +1,183 @@ +import OAI.Probability.RadialTransition.SpatialProducts + +namespace OAI + +universe uIndex uI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +theorem rawPartition_setIntegral {ι : Type uIndex} [Fintype ι] (φ : Potential) (A : Set Position) (β : ℝ) : + rawPartition φ A ι β = ∫ x in Set.univ.pi (fun _ : ι => A), Real.exp (-β * orderedEnergy φ x) := by + rw [rawPartition, volume_pi, Measure.restrict_pi_pi] + +theorem partitionOn_cube (φ : Potential) (L : ℝ) (N : ℕ) (β : ℝ) : + partitionOn φ (cube L) N β = partition φ L N β := by + rw [partitionOn, rawPartition_setIntegral] + simp_rw [orderedEnergy_fin] + have he : (Set.univ.pi (fun _ : Fin N => cube L)) = configurationCube L N := by + ext x + simp [configurationCube, Set.mem_pi] + rw [he] + rfl + +theorem partitionOn_nonneg (φ : Potential) (A : Set Position) (N : ℕ) (β : ℝ) : + 0 ≤ partitionOn φ A N β := mul_nonneg (by positivity) (rawPartition_nonneg φ A _ β) + +theorem partitionOn_zero (φ : Potential) (A : Set Position) (β : ℝ) : + partitionOn φ A 0 β = 1 := by + simp [partitionOn, rawPartition, orderedEnergy, Measure.real] + +theorem rawPartition_mono {ι : Type uIndex} [Fintype ι] {φ : Potential} + (hφ : Continuous φ) (hb : IsBoundedPotential φ) (β : ℝ) + {A B : Set Position} (hAB : A ⊆ B) (hBfin : volume B ≠ ⊤) : + rawPartition φ A ι β ≤ rawPartition φ B ι β := by + let : IsFiniteMeasure (volume.restrict B) := isFiniteMeasure_restrict.mpr hBfin + have hi : Integrable (fun x : ι → Position => Real.exp (-β * orderedEnergy φ x)) + (volume.restrict (Set.univ.pi (fun _ : ι => B))) := by + rw [volume_pi, Measure.restrict_pi_pi] + exact integrable_orderedBoltzmann hφ hb β _ + rw [rawPartition_setIntegral, rawPartition_setIntegral] + exact integral_mono_measure (Measure.restrict_mono (Set.pi_mono (fun _ _ => hAB)) le_rfl) + (Eventually.of_forall (fun _ => (Real.exp_pos _).le)) hi + +theorem partitionOn_mono {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + (β : ℝ) (N : ℕ) {A B : Set Position} (hAB : A ⊆ B) (hBfin : volume B ≠ ⊤) : + partitionOn φ A N β ≤ partitionOn φ B N β := + mul_le_mul_of_nonneg_left (rawPartition_mono hφ hb β hAB hBfin) (by positivity) + +def translateSet (a : Position) (A : Set Position) : Set Position := + (fun x => x - a) ⁻¹' A + +theorem measurableSet_translate {a : Position} {A : Set Position} (hA : MeasurableSet A) : + MeasurableSet (translateSet a A) := hA.preimage (measurable_id.sub_const a) + +theorem orderedEnergy_add {ι : Type uIndex} [Fintype ι] (φ : Potential) (x : ι → Position) (a : Position) : + orderedEnergy φ (fun i => a + x i) = orderedEnergy φ x := by + simp only [orderedEnergy, nndist_add_left] + +theorem rawPartition_translate {ι : Type uIndex} [Fintype ι] (φ : Potential) + (A : Set Position) (a : Position) (β : ℝ) : + rawPartition φ (translateSet a A) ι β = rawPartition φ A ι β := by + let τ : (ι → Position) ≃ᵐ (ι → Position) := (Homeomorph.addLeft (fun _ : ι => a)).toMeasurableEquiv + have hp : MeasurePreserving τ volume volume := measurePreserving_add_left volume _ + have hpre : τ ⁻¹' (Set.univ.pi (fun _ : ι => translateSet a A)) = Set.univ.pi (fun _ : ι => A) := by + ext x + simp [τ, translateSet, add_sub_cancel_left] + have he (x : ι → Position) : orderedEnergy φ (τ x) = orderedEnergy φ x := orderedEnergy_add φ x a + have hh := hp.setIntegral_preimage_emb τ.measurableEmbedding + (fun x => Real.exp (-β * orderedEnergy φ x)) (Set.univ.pi (fun _ : ι => translateSet a A)) + rw [hpre] at hh + simpa only [rawPartition_setIntegral, he] using hh.symm + +theorem partitionOn_translate (φ : Potential) (A : Set Position) (a : Position) (N : ℕ) (β : ℝ) : + partitionOn φ (translateSet a A) N β = partitionOn φ A N β := by + simp only [partitionOn, rawPartition_translate] + +theorem partitionOn_biUnion_lower {I : Type uI} (S : Finset I) (A : I → Set Position) + {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) {β : ℝ} (hβ : 0 ≤ β) + (hA : ∀ i ∈ S, MeasurableSet (A i)) (hAfin : ∀ i ∈ S, volume (A i) ≠ ⊤) + (hdisj : ∀ i ∈ S, ∀ j ∈ S, i ≠ j → Disjoint (A i) (A j)) + (hc : ∀ i ∈ S, ∀ j ∈ S, i ≠ j → ∀ x ∈ A i, ∀ y ∈ A j, φ (nndist x y) ≤ 0) + (n : I → ℕ) : + ∏ i ∈ S, partitionOn φ (A i) (n i) β ≤ + partitionOn φ (⋃ i ∈ S, A i) (∑ i ∈ S, n i) β := by + classical + induction S using Finset.induction_on with + | empty => simp [partitionOn_zero] + | @insert i S hi ih => + have hAs (j) (hj : j ∈ S) := hA j (Finset.mem_insert_of_mem hj) + have hfins (j) (hj : j ∈ S) := hAfin j (Finset.mem_insert_of_mem hj) + have hU : MeasurableSet (⋃ j ∈ S, A j) := S.measurableSet_biUnion hAs + have hUfin : volume (⋃ j ∈ S, A j) ≠ ⊤ := by + apply ne_top_of_le_ne_top _ (measure_biUnion_finset_le S A) + exact ENNReal.sum_ne_top.mpr hfins + have hdU : Disjoint (A i) (⋃ j ∈ S, A j) := by + simp only [Set.disjoint_iUnion_right] + intro j hj + exact hdisj i (Finset.mem_insert_self _ _) j (Finset.mem_insert_of_mem hj) (by rintro rfl; exact hi hj) + have hcU : ∀ x ∈ A i, ∀ y ∈ ⋃ j ∈ S, A j, φ (nndist x y) ≤ 0 := by + intro x hx y hy + obtain ⟨j, hj, hy⟩ := Set.mem_iUnion₂.mp hy + exact hc i (Finset.mem_insert_self _ _) j (Finset.mem_insert_of_mem hj) + (by rintro rfl; exact hi hj) x hx y hy + have hi' := ih hAs hfins + (fun j hj k hk hne => hdisj j (Finset.mem_insert_of_mem hj) k (Finset.mem_insert_of_mem hk) hne) + (fun j hj k hk hne => hc j (Finset.mem_insert_of_mem hj) k (Finset.mem_insert_of_mem hk) hne) + rw [Finset.prod_insert hi, Finset.sum_insert hi] + have hprod := mul_le_mul_of_nonneg_left hi' (partitionOn_nonneg φ (A i) (n i) β) + refine hprod.trans ?_ + have hu : (⋃ j ∈ insert i S, A j) = A i ∪ ⋃ j ∈ S, A j := by + ext x + simp + rw [hu] + exact partitionOn_union_lower hφ hb hβ + (hA i (Finset.mem_insert_self _ _)) hU hdU (hAfin i (Finset.mem_insert_self _ _)) hUfin hcU + (n i) (∑ j ∈ S, n j) + +theorem sum_all_subsets_card (N : ℕ) (F : ℕ → ℝ) : + (∑ T : Finset (Fin N), F T.card) = ∑ m ∈ Finset.range (N + 1), (N.choose m : ℝ) * F m := by + have hh := Finset.sum_powerset (Finset.univ : Finset (Fin N)) (fun T => F T.card) + simpa only [Finset.powerset_univ, Finset.card_univ, Fintype.card_fin, + Finset.sum_powersetCard, nsmul_eq_mul] using hh + +theorem factorial_choose_cancel {N m : ℕ} (hm : m ≤ N) : + (N.factorial : ℝ)⁻¹ * (N.choose m : ℝ) = + (m.factorial : ℝ)⁻¹ * ((N - m).factorial : ℝ)⁻¹ := by + have hfac : (N.choose m : ℝ) * m.factorial * (N - m).factorial = N.factorial := by + exact_mod_cast Nat.choose_mul_factorial_mul_factorial hm + have hN : (N.factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero N + have hm' : (m.factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero m + have hnm : ((N - m).factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero (N - m) + field_simp + nlinarith [hfac] + +theorem partitionOn_union_convolution {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {β : ℝ} (hβ : 0 ≤ β) + {A B : Set Position} (hA : MeasurableSet A) (hB : MeasurableSet B) (hab : Disjoint A B) + (hAfin : volume A ≠ ⊤) (hBfin : volume B ≠ ⊤) + (hc : ∀ x ∈ A, ∀ y ∈ B, φ (nndist x y) ≤ 0) (N : ℕ) : + (∑ m ∈ Finset.range (N + 1), partitionOn φ A m β * partitionOn φ B (N - m) β) ≤ + partitionOn φ (A ∪ B) N β := by + classical + have hterm (T : Finset (Fin N)) : + rawPartition φ A (Fin T.card) β * rawPartition φ B (Fin (N - T.card)) β ≤ + ∫ x : Fin N → Position, Real.exp (-β * orderedEnergy φ x) + ∂Measure.pi (fun i => if i ∈ T then volume.restrict A else volume.restrict B) := by + have hcardA : Fintype.card {i : Fin N // i ∈ T} = T.card := Fintype.card_coe T + have hcardB : Fintype.card {i : Fin N // i ∉ T} = N - T.card := by + rw [Fintype.card_subtype_compl, Fintype.card_fin, hcardA] + have hh := sector_raw_lower (fun i => i ∈ T) hφ hb hβ hA hB hAfin hBfin hc + have heA := rawPartition_equiv (Fintype.equivFinOfCardEq hcardA) φ A β + have heB := rawPartition_equiv (Fintype.equivFinOfCardEq hcardB) φ B β + convert hh using 1 + congr 1 + · convert heA.symm using 1 + congr! + · exact heB.symm + have hh := Finset.sum_le_sum (fun T (_ : T ∈ (Finset.univ : Finset (Finset (Fin N)))) => hterm T) + rw [← rawPartition_union_sum hφ hb β hB hab hAfin hBfin] at hh + rw [sum_all_subsets_card N (fun m => + rawPartition φ A (Fin m) β * rawPartition φ B (Fin (N - m)) β)] at hh + have hh' := mul_le_mul_of_nonneg_left hh (inv_nonneg.mpr (show (0 : ℝ) ≤ N.factorial by positivity)) + change _ ≤ (N.factorial : ℝ)⁻¹ * rawPartition φ (A ∪ B) (Fin N) β + refine le_trans (le_of_eq ?_) hh' + rw [Finset.mul_sum] + apply Finset.sum_congr rfl + intro m hm + have hcancel := factorial_choose_cancel (Nat.le_of_lt_succ (Finset.mem_range.mp hm)) + unfold partitionOn + calc + _ = ((m.factorial : ℝ)⁻¹ * ((N - m).factorial : ℝ)⁻¹) * + (rawPartition φ A (Fin m) β * rawPartition φ B (Fin (N - m)) β) := by ring + _ = _ := by rw [← hcancel]; ring + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PerturbationMoments.lean b/lean/OAI/Probability/RadialTransition/PerturbationMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0d14fda925e98a0606e9589abfeac879bae9fa4 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PerturbationMoments.lean @@ -0,0 +1,103 @@ +import OAI.Probability.RadialTransition.CellInteractions + +namespace OAI + +universe uX uI + +noncomputable section + + +open MeasureTheory Set Filter + +open scoped ContDiff BigOperators NNReal ENNReal + +namespace RadialTransition + +lemma secondMoment_of_exponential {X : Type uX} [MeasurableSpace X] {μ : Measure X} + {f : X → ℝ} (hf : Measurable f) {c C : ℝ} (hc : 0 < c) + (hi : Integrable (fun x => Real.exp (c*(f x)^2)) μ) + (hb : ∫ x, Real.exp (c*(f x)^2) ∂μ ≤ C) : + Integrable (fun x => (f x)^2) μ ∧ (∫ x, (f x)^2 ∂μ) ≤ C/c := by + have hbound (x : X) : (f x)^2 ≤ c⁻¹ * Real.exp (c*(f x)^2) := by + have hh := Real.add_one_le_exp (c*(f x)^2) + rw [mul_comm c⁻¹, ← div_eq_mul_inv] + apply (le_div_iff₀ hc).mpr + simpa only [mul_comm, div_eq_mul_inv] using (le_of_lt (by linarith : (f x)^2*c < Real.exp (c*(f x)^2))) + have hi' : Integrable (fun x => (f x)^2) μ := + (hi.const_mul c⁻¹).mono' (hf.pow_const 2).aestronglyMeasurable + (Eventually.of_forall (fun x => by simpa only [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg (f x))] using hbound x)) + refine ⟨hi', ?_⟩ + have hh := integral_mono hi' (hi.const_mul c⁻¹) hbound + rw [integral_const_mul] at hh + exact hh.trans (by simpa only [div_eq_mul_inv, mul_comm] using mul_le_mul_of_nonneg_left hb (inv_nonneg.mpr hc.le)) + +lemma pairMoment_of_second {X : Type uX} [MeasurableSpace X] {μ : Measure X} + {f g : X → ℝ} (hf : Measurable f) (hg : Measurable g) + {C : ℝ} (hiF : Integrable (fun x => (f x)^2) μ) (hiG : Integrable (fun x => (g x)^2) μ) + (hbF : ∫ x, (f x)^2 ∂μ ≤ C) (hbG : ∫ x, (g x)^2 ∂μ ≤ C) : + Integrable (fun x => f x * g x) μ ∧ (∫ x, f x * g x ∂μ) ≤ C := by + have hb (x : X) : |f x * g x| ≤ ((f x)^2+(g x)^2)/2 := by + apply abs_le.mpr + constructor <;> nlinarith [sq_nonneg (f x-g x), sq_nonneg (f x+g x)] + have hi : Integrable (fun x => f x*g x) μ := + ((hiF.add hiG).div_const 2).mono' (hf.mul hg).aestronglyMeasurable + (Eventually.of_forall (fun x => by simpa only [Real.norm_eq_abs, Pi.add_apply] using hb x)) + refine ⟨hi, ?_⟩ + have hh := integral_mono hi ((hiF.add hiG).div_const 2) (fun x => (le_abs_self _).trans (hb x)) + simp only [Pi.add_apply] at hh + rw [integral_div, integral_add hiF hiG] at hh + linarith + +theorem log_partition_perturbation {X : Type uX} {I : Type uI} [MeasurableSpace X] [Fintype I] + {μ : Measure X} {E F : X → ℝ} (hE : Measurable E) (hF : Measurable F) + (hiE : Integrable (fun x => Real.exp (-E x)) μ) + (hiF : Integrable (fun x => Real.exp (-F x)) μ) + (hpE : 0 < boltzmannPartition μ E) (hpF : 0 < boltzmannPartition μ F) + (n : I → X → ℝ) (hn : ∀ i, Measurable (n i)) + (K : I → I → ℝ) (hK : ∀ i j, 0 ≤ K i j) {C : ℝ} + (hsE : ∀ i, Integrable (fun x => (n i x)^2) (boltzmannMeasure μ E)) + (hsF : ∀ i, Integrable (fun x => (n i x)^2) (boltzmannMeasure μ F)) + (hbE : ∀ i, ∫ x, (n i x)^2 ∂boltzmannMeasure μ E ≤ C) + (hbF : ∀ i, ∫ x, (n i x)^2 ∂boltzmannMeasure μ F ≤ C) + (hd : ∀ x, |F x-E x| ≤ ∑ i, ∑ j, K i j * n i x * n j x) : + |Real.log (boltzmannPartition μ E) - Real.log (boltzmannPartition μ F)| ≤ + C * ∑ i, ∑ j, K i j := by + have oneSide (E F : X → ℝ) (hE : Measurable E) (hF : Measurable F) + (hiE : Integrable (fun x => Real.exp (-E x)) μ) + (hiF : Integrable (fun x => Real.exp (-F x)) μ) + (hpE : 0 < boltzmannPartition μ E) (hpF : 0 < boltzmannPartition μ F) + (hsE : ∀ i, Integrable (fun x => (n i x)^2) (boltzmannMeasure μ E)) + (hbE : ∀ i, ∫ x, (n i x)^2 ∂boltzmannMeasure μ E ≤ C) + (hd : ∀ x, |F x-E x| ≤ ∑ i, ∑ j, K i j * n i x * n j x) : + Real.log (boltzmannPartition μ E) - Real.log (boltzmannPartition μ F) ≤ C*∑ i, ∑ j, K i j := by + have hp (i j : I) := pairMoment_of_second (hn i) (hn j) (hsE i) (hsE j) (hbE i) (hbE j) + have hiTerm (i j : I) : Integrable (fun x => K i j * n i x * n j x) (boltzmannMeasure μ E) := by + simpa only [mul_assoc] using (hp i j).1.const_mul (K i j) + have hiSum := integrable_finsetSum (Finset.univ : Finset I) (fun i _ => + integrable_finsetSum (Finset.univ : Finset I) (fun j _ => hiTerm i j)) + have hiDiff : Integrable (fun x => F x-E x) (boltzmannMeasure μ E) := + hiSum.mono' (hF.sub hE).aestronglyMeasurable (Eventually.of_forall (fun x => by + simpa only [Real.norm_eq_abs] using hd x)) + apply (log_boltzmann_difference_le hE hiE hiF hpE hpF hiDiff).trans + apply (integral_mono hiDiff hiSum (fun x => (le_abs_self _).trans (hd x))).trans + rw [integral_finsetSum _ (fun i _ => integrable_finsetSum _ (fun j _ => hiTerm i j))] + simp_rw [integral_finsetSum _ (fun j _ => hiTerm _ j)] + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro i _ + rw [Finset.mul_sum] + apply Finset.sum_le_sum + intro j _ + simp_rw [mul_assoc, integral_const_mul] + simpa only [mul_comm] using mul_le_mul_of_nonneg_left (hp i j).2 (hK i j) + apply abs_le.mpr + constructor + · have hh := oneSide F E hF hE hiF hiE hpF hpE hsF hbF (fun x => by simpa only [abs_sub_comm] using hd x) + linarith + · exact oneSide E F hE hF hiE hiF hpE hpF hsE hbE hd + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PhaseGeometry.lean b/lean/OAI/Probability/RadialTransition/PhaseGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..9fc5a094b7c7ac7737fd9f59ef382a88bf255958 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PhaseGeometry.lean @@ -0,0 +1,175 @@ +import OAI.Probability.RadialTransition.TruncatedFamily + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma phaseSlope_zero : phaseSlope 0=parameter 0 0 := by simp [phaseSlope,phaseDensity] +lemma phaseSlope_one : phaseSlope 1=parameter (3*packingDensity/4) packingDensity := by + simp only [phaseSlope, phaseDensity, Matrix.cons_val_one, Matrix.cons_val_zero] + congr 1 + dsimp [phaseMass] + field_simp + ring +lemma phaseSlope_two : phaseSlope 2=parameter (12*packingDensity) (4*packingDensity) := by + change parameter (phaseMass/2*(4*packingDensity)^2) (4*packingDensity)=_ + congr 1 + dsimp [phaseMass] + field_simp + ring + +lemma phase_densities_separated (i j : Fin 3) (hij : i ≠ j) : + packingDensity ≤ |phaseSlope i 1-phaseSlope j 1| := by + have hp := packingDensity_pos + fin_cases i <;> fin_cases j <;> simp_all [phaseSlope_zero,phaseSlope_one,phaseSlope_two,abs_of_pos,abs_of_neg] <;> + linarith + +def phaseRadius : ℝ := packingDensity/128 +def pressureRadius : ℝ := packingDensity/32 +lemma phaseRadius_pos : 0 < phaseRadius := div_pos packingDensity_pos (by norm_num) +lemma pressureRadius_pos : 0 < pressureRadius := div_pos packingDensity_pos (by norm_num) +lemma phaseRadius_lt : phaseRadius < packingDensity/16 := by dsimp [phaseRadius]; linarith [packingDensity_pos] + +def directionalMax (z : Parameter) : ℝ := finiteMax (fun i : Fin 3 => inner ℝ (phaseSlope i-targetSlope) z) + +lemma directional_lower (z : Parameter) : packingDensity/8*‖z‖ ≤ directionalMax z := by + let m := directionalMax z + let A := inner ℝ (phaseSlope 0-targetSlope) z + let B := inner ℝ (phaseSlope 1-targetSlope) z + let C := inner ℝ (phaseSlope 2-targetSlope) z + have hA : A ≤ m := le_finiteMax (fun i : Fin 3 => inner ℝ (phaseSlope i-targetSlope) z) 0 + have hB : B ≤ m := le_finiteMax (fun i : Fin 3 => inner ℝ (phaseSlope i-targetSlope) z) 1 + have hC : C ≤ m := le_finiteMax (fun i : Fin 3 => inner ℝ (phaseSlope i-targetSlope) z) 2 + have hsum : A+B+C=0 := by + dsimp [A,B,C] + rw [phaseSlope_zero,phaseSlope_one,phaseSlope_two] + simp only [parameter_inner, PiLp.sub_apply, parameter_zero,parameter_one,targetSlope] + ring + have hm : 0 ≤ m := by linarith + have hAl : -2*m ≤ A := by linarith + have hBl : -2*m ≤ B := by linarith + have hCl : -2*m ≤ C := by linarith + have hcoord₀ : |packingDensity*z 0| ≤ 2*m := by + dsimp [A,B,C] at hA hB hC hAl hBl hCl + rw [phaseSlope_zero] at hA hAl + rw [phaseSlope_one] at hB hBl + rw [phaseSlope_two] at hC hCl + simp only [parameter_inner, PiLp.sub_apply, parameter_zero,parameter_one,targetSlope] at hA hB hC hAl hBl hCl + rw [abs_le] + constructor <;> nlinarith + have hcoord₁ : |packingDensity*z 1| ≤ 5*m := by + dsimp [A,B,C] at hA hB hC hAl hBl hCl + rw [phaseSlope_zero] at hA hAl + rw [phaseSlope_one] at hB hBl + rw [phaseSlope_two] at hC hCl + simp only [parameter_inner, PiLp.sub_apply, parameter_zero,parameter_one,targetSlope] at hA hB hC hAl hBl hCl + rw [abs_le] + constructor <;> nlinarith + rw [abs_mul,abs_of_pos packingDensity_pos] at hcoord₀ hcoord₁ + have hn := mul_le_mul_of_nonneg_left (parameter_norm_le z) packingDensity_pos.le + change packingDensity/8*‖z‖ ≤ m + nlinarith + +lemma mem_closedHull_of_inner_le {G : Set Parameter} {v : Parameter} + (h : ∀ z : Parameter, ∃ w ∈ G, inner ℝ v z ≤ inner ℝ w z) : + v ∈ closure (convexHull ℝ G) := by + by_contra hv + obtain ⟨ell,c,hsep,hvc⟩ := geometric_hahn_banach_closed_point + (convex_convexHull ℝ G).closure isClosed_closure hv + let z : Parameter := (InnerProductSpace.toDual ℝ Parameter).symm ell + have hell (w : Parameter) : inner ℝ w z=ell w := by + rw [real_inner_comm] + exact InnerProductSpace.toDual_symm_apply + obtain ⟨w,hw,hh⟩ := h z + have hs := hsep w (subset_closure (subset_convexHull ℝ G hw)) + rw [hell,hell] at hh + linarith + +lemma robust_phase_triangle (w : Fin 3 → Parameter) + (hw : ∀ i, w i ∈ Metric.closedBall (phaseSlope i) phaseRadius) : + Metric.closedBall targetSlope pressureRadius ⊆ closure (convexHull ℝ (range w)) := by + intro v hv + apply mem_closedHull_of_inner_le + intro z + obtain ⟨i,hi⟩ := finiteMax_attained (fun i : Fin 3 => inner ℝ (phaseSlope i-targetSlope) z) + have hd := directional_lower z + change directionalMax z=inner ℝ (phaseSlope i-targetSlope) z at hi + rw [hi] at hd + have hvn : ‖v-targetSlope‖ ≤ pressureRadius := Metric.mem_closedBall.mp hv + have hwn : ‖phaseSlope i-w i‖ ≤ phaseRadius := by + rw [norm_sub_rev] + exact Metric.mem_closedBall.mp (hw i) + have hvz := (real_inner_le_norm (v-targetSlope) z).trans (mul_le_mul_of_nonneg_right hvn (norm_nonneg z)) + have hwz := (real_inner_le_norm (phaseSlope i-w i) z).trans (mul_le_mul_of_nonneg_right hwn (norm_nonneg z)) + refine ⟨w i, mem_range_self i, ?_⟩ + rw [inner_sub_left] at hd hvz hwz + dsimp [pressureRadius,phaseRadius] at hvz hwz + nlinarith [mul_nonneg packingDensity_pos.le (norm_nonneg z)] + +def exclusionNormal : Fin 3 → Parameter := ![parameter 1 (-15/4),parameter (-1) 3,parameter 1 (-3/4)] + +lemma exclusionNormal_norm (i : Fin 3) : ‖exclusionNormal i‖ ≤ 5 := by + have hn := parameter_norm_le (exclusionNormal i) + fin_cases i <;> norm_num [exclusionNormal] at hn ⊢ <;> linarith + +lemma exclusion_gap (i j : Fin 3) (hij : j ≠ i) : + inner ℝ (phaseSlope j) (exclusionNormal i)+3*packingDensity/4 ≤ inner ℝ targetSlope (exclusionNormal i) := by + have hp := packingDensity_pos + fin_cases i <;> fin_cases j <;> try contradiction + all_goals norm_num [phaseSlope,phaseDensity,phaseMass,exclusionNormal,parameter_inner,targetSlope] + all_goals field_simp + all_goals nlinarith + +lemma exclusion_ball (i j : Fin 3) (hij : j ≠ i) {v : Parameter} + (hv : v ∈ Metric.closedBall (phaseSlope j) phaseRadius) : + inner ℝ v (exclusionNormal i) ≤ inner ℝ targetSlope (exclusionNormal i)-packingDensity/2 := by + have hn : ‖v-phaseSlope j‖ ≤ phaseRadius := Metric.mem_closedBall.mp hv + have hh := (real_inner_le_norm (v-phaseSlope j) (exclusionNormal i)).trans + (mul_le_mul hn (exclusionNormal_norm i) (norm_nonneg _) phaseRadius_pos.le) + rw [inner_sub_left] at hh + have hg := exclusion_gap i j hij + dsimp [phaseRadius] at hh + linarith [packingDensity_pos] + +lemma phase_plane_at_center (i : Fin 3) : limitingPlane i 1 (-3/4)=0 := by + have hp := packingDensity_pos.ne' + fin_cases i <;> dsimp [limitingPlane,phaseDensity,phaseOffset,phaseMass] <;> field_simp <;> ring + +lemma phase_plane_difference (i : Fin 3) (x : Parameter) : + limitingPlane i (x 0) (x 1)=inner ℝ (phaseSlope i) (x-phaseCenter) := by + have hh := phase_plane_at_center i + dsimp [limitingPlane] at hh ⊢ + simp only [phaseSlope,phaseCenter,parameter_inner,PiLp.sub_apply,parameter_zero,parameter_one] + nlinarith + +lemma threePlane_center : onParameters threePlane phaseCenter=0 := by + change finiteMax (fun i => limitingPlane i 1 (-3/4))=0 + apply le_antisymm + · apply finiteMax_le + intro i + rw [phase_plane_at_center] + · have hh := le_finiteMax (fun i => limitingPlane i 1 (-3/4)) (0:Fin 3) + rw [phase_plane_at_center] at hh + exact hh + +lemma threePlane_growth (x : Parameter) : + pressureRadius*‖x-phaseCenter‖ ≤ onParameters threePlane x-onParameters threePlane phaseCenter- + inner ℝ targetSlope (x-phaseCenter) := by + rw [threePlane_center,sub_zero] + obtain ⟨i,hi⟩ := finiteMax_attained (fun i : Fin 3 => inner ℝ (phaseSlope i-targetSlope) (x-phaseCenter)) + have hd := directional_lower (x-phaseCenter) + change directionalMax (x-phaseCenter)=_ at hi + rw [hi,inner_sub_left] at hd + have hh := le_finiteMax (fun i => limitingPlane i (x 0) (x 1)) i + rw [phase_plane_difference] at hh + change inner ℝ (phaseSlope i) (x-phaseCenter) ≤ onParameters threePlane x at hh + dsimp [pressureRadius] + nlinarith [mul_nonneg packingDensity_pos.le (norm_nonneg (x-phaseCenter))] + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PhysicalIteration.lean b/lean/OAI/Probability/RadialTransition/PhysicalIteration.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed3880aed0dcac9319f8027bf82fa34041450e93 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PhysicalIteration.lean @@ -0,0 +1,97 @@ +import OAI.Probability.RadialTransition.UniformKac + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal +open Set Filter +namespace RadialTransition + +def iterationMass (b : ℝ) : ℕ → ℝ := prepend phaseMass (scaleTail b) +def iterationBudget : ℝ := phaseMass+1 +lemma iterationBudget_pos : 0 < iterationBudget := by dsimp [iterationBudget]; linarith [phaseMass_pos] +lemma iterationMass_pos {b : ℝ} (hb : 0 < b) (n : ℕ) : 0 < iterationMass b n := by + cases n with + | zero => exact phaseMass_pos + | succ n => exact scaleTail_pos hb n +lemma iterationMass_summable {b : ℝ} (hb : 2 ≤ b) : Summable (iterationMass b) := + summable_prepend _ (summable_scaleTail hb) +lemma iterationMass_tsum {b : ℝ} (hb : 2 ≤ b) : (∑' n, iterationMass b n) ≤ iterationBudget := by + rw [iterationMass,tsum_prepend _ (summable_scaleTail hb)] + have hh := tsum_scaleTail_le hb + dsimp [iterationBudget] + linarith [inv_fourth_le_half hb] +lemma iterationMass_le {b : ℝ} (hb : 2 ≤ b) (n : ℕ) : iterationMass b n ≤ iterationBudget := by + exact ((iterationMass_summable hb).le_tsum n (fun j _ => (iterationMass_pos (by linarith) j).le)).trans (iterationMass_tsum hb) +lemma iterationMass_weight_summable {b : ℝ} (hb : 2 ≤ b) : + Summable (fun n => iterationMass b n*(scaleRange b n)^(1/32:ℝ)) := by + apply (summable_nat_add_iff 1).mp + simpa only [iterationMass,prepend_succ] using summable_scaleTail_weight hb +lemma iteration_admissible {b : ℝ} (hb : 2 ≤ b) (t : ℝ) : + AdmissibleFamily t iterationBudget (iterationMass b) (scaleRange b) := + ⟨fun n => (iterationMass_pos (by linarith) n).le,scaleRange_one_le (by linarith), + iterationMass_summable hb,iterationMass_tsum hb⟩ + +def iterationQ (t b : ℝ) (n : ℕ) : Pressure := + grandPressure (familyPotential t (reversePrefix 0 (iterationMass b) (n+1)) + (reversePrefix 1 (scaleRange b) (n+1))) t +def iterationP (t b : ℝ) (n : ℕ) : Pressure := + idealAttraction (grandPressure (familyPotential t (reversePrefix 0 (iterationMass b) n) + (reversePrefix 1 (scaleRange b) n)) t) (iterationMass b n) +lemma iterationP_zero (t b : ℝ) : iterationP t b 0= + idealAttraction (grandPressure (corePotential t) t) phaseMass := by + simp only [iterationP,reversePrefix_zero,iterationMass,prepend_zero,familyPotential_zero] +lemma iterationP_succ (t b : ℝ) (n : ℕ) : iterationP t b (n+1)=idealAttraction (iterationQ t b n) (scaleTail b n) := rfl + +lemma iteration_kac {t C K b : ℝ} (ht : 1 ≤ t) (hC : 0 < C) (_hK : 1 ≤ K) + (hb : 2 ≤ b) (hbK : 2*K ≤ b) + (hrow : 2197*t*bumpIntegral⁻¹*iterationBudget ≤ (t^2/8)/8) + (hkac : ∀ (a S : ℕ → ℝ) (m R₀ R β h : ℝ), + (∀ n, 0 ≤ a n) → (∀ n, 1 ≤ S n) → Summable a → + 2 ≤ R₀ → (∀ n, S n ≤ R₀) → 0 ≤ m → m+∑' n, a n ≤ iterationBudget → + 2197*t*bumpIntegral⁻¹*(m+∑' n, a n) ≤ (t^2/8)/8 → + K*R₀ ≤ R → β ∈ Icc (1/2:ℝ) (3/2) → h ∈ Icc (-2:ℝ) 2 → + |grandPressure (familyPotential t (prepend m a) (prepend R S)) t β h- + idealAttraction (grandPressure (familyPotential t a S) t) m β h| ≤ C*Real.sqrt (R₀/R)) : + ∀ n x, x ∈ phaseWindow (1/4) → + |onParameters (iterationQ t b n) x-onParameters (iterationP t b n) x| ≤ 2*C*(scaleTail b n)^2 := by + have ha := iteration_admissible hb t + have hbn : 1 ≤ b := by linarith + intro n x hx + have had := reversePrefix_admissible (t := t) ha.1 ha.2.1 ha.2.2.1 ha.2.2.2 n + have hadnext := reversePrefix_admissible (t := t) ha.1 ha.2.1 ha.2.2.1 ha.2.2.2 (n+1) + have hm : iterationMass b n+∑' j, reversePrefix 0 (iterationMass b) n j ≤ iterationBudget := by + simpa only [reversePrefix_succ,tsum_prepend _ (summable_reversePrefix _ _)] using hadnext.2.2.2 + have hrow' : 2197*t*bumpIntegral⁻¹*(iterationMass b n+∑' j, reversePrefix 0 (iterationMass b) n j) ≤ (t^2/8)/8 := by + apply le_trans (mul_le_mul_of_nonneg_left hm ?_) hrow + have := bumpIntegral_pos + positivity + obtain ⟨hβ, hh⟩ := phaseWindow_quarter_bounds hx + have hβ' : x 0 ∈ Icc (1/2:ℝ) (3/2) := ⟨by linarith [hβ.1],by linarith [hβ.2]⟩ + have hh' : x 1 ∈ Icc (-2:ℝ) 2 := abs_le.mp hh + cases n with + | zero => + have hh := hkac _ _ (iterationMass b 0) 2 (scaleRange b 0) (x 0) (x 1) + had.1 had.2.1 had.2.2.1 (by norm_num) (fun _ => by norm_num [reversePrefix_zero]) + (ha.1 0) hm hrow' (by nlinarith [scaleRange_base_le hbn 0]) hβ' hh' + change |onParameters (iterationQ t b 0) x-onParameters (iterationP t b 0) x| ≤ C*Real.sqrt (2/scaleRange b 0) at hh + apply hh.trans + nlinarith [mul_le_mul_of_nonneg_left (scale_kac_zero hb) hC.le] + | succ n => + have hR₂ : 2 ≤ scaleRange b n := hb.trans (scaleRange_base_le hbn n) + have hrange : ∀ j, reversePrefix 1 (scaleRange b) (n+1) j ≤ scaleRange b n := + reversePrefix_range_le (by linarith) (fun j hj => scaleRange_mono hbn (by omega)) + have hstep : K*scaleRange b n ≤ scaleRange b (n+1) := by + rw [scaleRange_succ] + have hKR : K ≤ scaleRange b n := (show K≤b by linarith).trans (scaleRange_base_le hbn n) + nlinarith [mul_nonneg (scaleRange_pos (by linarith) n).le (sub_nonneg.mpr hKR)] + have hh := hkac _ _ (iterationMass b (n+1)) (scaleRange b n) (scaleRange b (n+1)) (x 0) (x 1) + had.1 had.2.1 had.2.2.1 hR₂ hrange (ha.1 (n+1)) hm hrow' hstep hβ' hh' + change |onParameters (iterationQ t b (n+1)) x-onParameters (iterationP t b (n+1)) x| ≤ C*Real.sqrt (scaleRange b n/scaleRange b (n+1)) at hh + rw [scale_kac_succ hbn] at hh + nlinarith [sq_nonneg (scaleTail b (n+1))] + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PressureBall.lean b/lean/OAI/Probability/RadialTransition/PressureBall.lean new file mode 100644 index 0000000000000000000000000000000000000000..fbc827f13d7d3a954465da3e2c67ee41b998a4af --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PressureBall.lean @@ -0,0 +1,99 @@ +import OAI.Probability.RadialTransition.PhaseGeometry + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma support_ball_of_groups {Q : Pressure} {x : Parameter} {r : ℝ} + (hgroup : HasPhaseGroups Q x r) (hr : r ≤ phaseRadius) + (hg : targetSlope ∈ supportSet (onParameters Q) positiveParameters x) : + Metric.closedBall targetSlope pressureRadius ⊆ supportSet (onParameters Q) positiveParameters x := by + classical + let S := supportSet (onParameters Q) positiveParameters x + have hex (i : Fin 3) : ∃ w ∈ S, w ∈ Metric.closedBall (phaseSlope i) phaseRadius := by + by_contra hn + let n := exclusionNormal i + let c := inner ℝ targetSlope n-packingDensity/2 + let H : Set Parameter := {v | inner ℝ v n ≤ c} + have hc : Convex ℝ H := by + intro v hv w hw a b ha hb hab + change inner ℝ (a • v+b • w) n ≤ c + rw [inner_add_left,real_inner_smul_left,real_inner_smul_left] + have hh := add_le_add (mul_le_mul_of_nonneg_left hv ha) (mul_le_mul_of_nonneg_left hw hb) + calc + _ ≤ a*c+b*c := hh + _ = c := by rw [← add_mul,hab,one_mul] + have hclosed : IsClosed H := isClosed_le (continuous_id.inner continuous_const) continuous_const + have hSH : S ⊆ H := by + change supportSet (onParameters Q) positiveParameters x ⊆ H + rw [hgroup] + apply closure_minimal _ hclosed + apply convexHull_min _ hc + rintro v ⟨hv,j,hj⟩ + have hj' := Metric.closedBall_subset_closedBall hr hj + have hij : j ≠ i := by + intro heq + exact hn ⟨v,hv,heq ▸ hj'⟩ + exact exclusion_ball i j hij hj' + have hh := hSH hg + change inner ℝ targetSlope n ≤ inner ℝ targetSlope n-packingDensity/2 at hh + linarith [packingDensity_pos] + choose w hw hwball using hex + intro v hv + have htri := robust_phase_triangle w hwball hv + have hsub : closure (convexHull ℝ (range w)) ⊆ S := by + apply closure_minimal _ (isClosed_supportSet _ _ _) + apply convexHull_min _ (convex_supportSet _ _ _) + rintro _ ⟨i,rfl⟩ + exact hw i + exact hsub htri + +lemma pressure_ball_exists {Q : Pressure} + (hQ : ConvexOn ℝ positiveParameters (onParameters Q)) + (hclose : ∀ x ∈ phaseWindow (1/8), |onParameters Q x-onParameters threePlane x| ≤ pressureRadius/32) + (hgroups : ∀ x ∈ phaseWindow (1/8), ∃ r ≤ phaseRadius, HasPhaseGroups Q x r) : + ∃ x ∈ Metric.ball phaseCenter (1/8), + Metric.closedBall targetSlope pressureRadius ⊆ supportSet (onParameters Q) positiveParameters x := by + have hW : phaseWindow (1/8) ⊆ positiveParameters := by + intro x hx + exact phaseWindow_positive (by norm_num) hx + have hQc := hQ.continuousOn isOpen_positiveParameters + let F : Parameter → ℝ := fun x => onParameters Q x-inner ℝ targetSlope x + have hFc : ContinuousOn F (phaseWindow (1/8)) := + (hQc.mono hW).sub (continuous_const.inner continuous_id).continuousOn + have hcenter : phaseCenter ∈ phaseWindow (1/8) := Metric.mem_closedBall_self (by norm_num) + obtain ⟨x,hx,hmin⟩ := (isCompact_closedBall phaseCenter (1/8)).exists_isMinOn ⟨phaseCenter,hcenter⟩ hFc + have hdist : dist x phaseCenter < 1/8 := by + by_contra hh + have hxbound := Metric.mem_closedBall.mp hx + have heq : dist x phaseCenter=1/8 := le_antisymm hxbound (le_of_not_gt hh) + have hgrow := threePlane_growth x + rw [← dist_eq_norm,heq] at hgrow + have ha := abs_le.mp (hclose x hx) + have hb := abs_le.mp (hclose phaseCenter hcenter) + have hm := hmin hcenter + dsimp [F] at hm + rw [inner_sub_right] at hgrow + linarith [pressureRadius_pos] + have hg : targetSlope ∈ supportSet (onParameters Q) positiveParameters x := by + apply supportsOn_of_local hQ (hW hx) (sub_pos.mpr hdist) + intro y hy + have hyW : y ∈ phaseWindow (1/8) := by + change dist y phaseCenter ≤ 1/8 + calc + _ ≤ dist y x+dist x phaseCenter := dist_triangle _ _ _ + _ ≤ 1/8 := by have ht := Metric.mem_closedBall.mp hy.2; linarith + have hm := hmin hyW + dsimp [F] at hm + rw [inner_sub_right] + linarith + obtain ⟨r,hr,hgrp⟩ := hgroups x hx + exact ⟨x,hdist,support_ball_of_groups hgrp hr hg⟩ + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/PressureContinuity.lean b/lean/OAI/Probability/RadialTransition/PressureContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..9d385ca881c6766eaf0d27b206f9a13892c9916e --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/PressureContinuity.lean @@ -0,0 +1,220 @@ +import OAI.Probability.RadialTransition.CellDifferences + +namespace OAI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +theorem grandOn_grid_perturbation {I : Type} [Fintype I] [DecidableEq I] [Nonempty I] + (e : I → Cell) (he : Function.Injective e) {A : Set Position} + (hA : MeasurableSet A) (hAfin : volume A ≠ ⊤) + (hcover : ∀ x ∈ A, ∃ i, cellOf x = e i) + {φ ψ : Potential} (hφ : Continuous φ) (hψ : Continuous ψ) + (hbφ : IsBoundedPotential φ) (hbψ : IsBoundedPotential ψ) + {Bφ Bψ t β : ℝ} (hsφ : StableWith φ Bφ) (hsψ : StableWith ψ Bψ) + (ht : 0 < t) (hβ : 0 < β) (z : ℝ) + (J K : Cell → Cell → ℝ) + (hJ : ∀ i j, 0 ≤ J i j) (hJsym : ∀ i j, J i j = J j i) + (hrow : ∀ i, ∑ j, J (e i) (e j) ≤ (t^2/8)/8) + (hlφ : ∀ x y, corePotential t (nndist x y)-J (cellOf x) (cellOf y) ≤ φ (nndist x y)) + (hlψ : ∀ x y, corePotential t (nndist x y)-J (cellOf x) (cellOf y) ≤ ψ (nndist x y)) + (hK : ∀ i j, 0 ≤ K i j) + (hd : ∀ x y, |ψ (nndist x y)-φ (nndist x y)| ≤ K (cellOf x) (cellOf y)) : + |Real.log (grandOn φ A β z)-Real.log (grandOn ψ A β z)| ≤ + β/2 * (Real.exp (16/15 * (1/64) * Real.exp (z+β*(t^2/2))) / (β*(t^2/8)/4)) * + ∑ i, ∑ j, K (e i) (e j) := by + let X i := CroppedCell A (e i) + let ν i := croppedCellMeasure A (e i) + let : ∀ i, IsFiniteMeasure (ν i) := fun i => croppedCellMeasure_finite hA (e i) + let pos : ∀ i, X i → Position := fun _ => Subtype.val + have hpos (i : I) : Continuous (pos i) := continuous_subtype_val + let v : ∀ i j, X i → X j → ℝ := fun i j x y => radialPair φ (pos i x) (pos j y) + let w : ∀ i j, X i → X j → ℝ := fun i j x y => radialPair ψ (pos i x) (pos j y) + have hcell (i : I) (x : X i) : cellOf (pos i x) = e i := x.property.2 + have hdecomp := croppedCell_partition e he hA hcover + have heφ := (grandOn_cell_factorization X ν pos hpos hAfin hdecomp hφ hbφ hsφ hβ.le z).2 + have heψ := (grandOn_cell_factorization X ν pos hpos hAfin hdecomp hψ hbψ hsψ hβ.le z).2 + rw [← heφ, ← heψ] + have hv (i j : I) : Continuous (Function.uncurry (v i j)) := by + change Continuous (fun p : X i × X j => radialPair φ (pos i p.1) (pos j p.2)) + exact continuous_radialPair_comp hφ (hpos i) (hpos j) + have hw (i j : I) : Continuous (Function.uncurry (w i j)) := by + change Continuous (fun p : X i × X j => radialPair ψ (pos i p.1) (pos j p.2)) + exact continuous_radialPair_comp hψ (hpos i) (hpos j) + have hlowφ (i j : I) (x : X i) (y : X j) : + corePotential t (nndist (pos i x) (pos j y))-J (e i) (e j) ≤ v i j x y := by + simpa only [hcell, v, radialPair] using hlφ (pos i x) (pos j y) + have hlowψ (i j : I) (x : X i) (y : X j) : + corePotential t (nndist (pos i x) (pos j y))-J (e i) (e j) ≤ w i j x y := by + simpa only [hcell, w, radialPair] using hlψ (pos i x) (pos j y) + exact pairCell_log_perturbation ν pos (fun i => croppedCell_diameter) ht hβ (by norm_num) + (fun i => croppedCellMeasure_volume hA (e i)) v w hv hw + (fun i j x y => radialPair_symm φ _ _) (fun i j x y => radialPair_symm ψ _ _) + (fun i j => J (e i) (e j)) (fun i j => hJ _ _) (fun i j => hJsym _ _) hrow + (fun i => hlowφ i i) + (fun i j x y => (by have hh := hlowφ i j x y; have hn := coreReal_nonneg t (nndist (pos i x) (pos j y)); change 0 ≤ corePotential t (nndist (pos i x) (pos j y)) at hn; linarith)) + (fun i => hlowψ i i) + (fun i j x y => (by have hh := hlowψ i j x y; have hn := coreReal_nonneg t (nndist (pos i x) (pos j y)); change 0 ≤ corePotential t (nndist (pos i x) (pos j y)) at hn; linarith)) + (fun i j => K (e i) (e j)) (fun i j => hK _ _) + (fun i j x y => by simpa only [hcell, v, w, radialPair] using hd (pos i x) (pos j y)) + +lemma attractionProfile_mono {a b R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hb : ∀ n, 0 ≤ b n) (hR : ∀ n, 1 ≤ R n) + (hsa : Summable a) (hsb : Summable b) (hab : ∀ n, a n ≤ b n) (r : ℝ) : + attractionProfile a R r ≤ attractionProfile b R r := + Summable.tsum_le_tsum + (fun n => mul_le_mul_of_nonneg_right (hab n) (scaledBumpProfile_nonneg (by linarith [hR n]) r)) + (summable_attractionProfile ha hR hsa r) (summable_attractionProfile hb hR hsb r) + +lemma familyPotential_grid_lower {t : ℝ} {a m R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hm : ∀ n, 0 ≤ m n) (hR : ∀ n, 1 ≤ R n) + (hsa : Summable a) (hsm : Summable m) (ham : ∀ n, a n ≤ m n) (x y : Position) : + corePotential t (nndist x y)-familyCellMajorant t m R (cellOf x) (cellOf y) ≤ + familyPotential t a R (nndist x y) := by + have hh := (mul_le_mul_of_nonneg_left (attractionProfile_mono ha hm hR hsa hsm ham (dist x y)) ht).trans + (attraction_le_familyCellMajorant ht hm hR hsm x y) + change coreReal t (dist x y)-_ ≤ coreReal t (dist x y)-t*attractionProfile a R (dist x y) + linarith + +lemma familyPotential_grid_difference {t : ℝ} {a b R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hb : ∀ n, 0 ≤ b n) (hR : ∀ n, 1 ≤ R n) + (hsa : Summable a) (hsb : Summable b) (x y : Position) : + |familyPotential t b R (nndist x y)-familyPotential t a R (nndist x y)| ≤ + familyCellMajorant t (fun n => |b n-a n|) R (cellOf x) (cellOf y) := by + have hsd : Summable (fun n => |b n-a n|) := (hsb.sub hsa).abs + have he : |attractionProfile b R (dist x y)-attractionProfile a R (dist x y)| ≤ + attractionProfile (fun n => |b n-a n|) R (dist x y) := by + unfold attractionProfile + rw [← (summable_attractionProfile hb hR hsb _).tsum_sub (summable_attractionProfile ha hR hsa _)] + have hsn := ((summable_attractionProfile hb hR hsb (dist x y)).sub (summable_attractionProfile ha hR hsa (dist x y))).norm + have hh := norm_tsum_le_tsum_norm hsn + simp only [Real.norm_eq_abs, ← sub_mul, abs_mul] at hh + have hn (n : ℕ) : |scaledBumpProfile (R n) (dist x y)| = scaledBumpProfile (R n) (dist x y) := + abs_of_nonneg (scaledBumpProfile_nonneg (by linarith [hR n]) _) + simpa only [hn, ← sub_mul] using hh + have hh := (mul_le_mul_of_nonneg_left he ht).trans + (attraction_le_familyCellMajorant ht (fun n => abs_nonneg _) hR hsd x y) + have heq : |familyPotential t b R (nndist x y)-familyPotential t a R (nndist x y)| = + t*|attractionProfile b R (dist x y)-attractionProfile a R (dist x y)| := by + change |(coreReal t (dist x y)-t*attractionProfile b R (dist x y))- + (coreReal t (dist x y)-t*attractionProfile a R (dist x y))| = _ + rw [show (coreReal t (dist x y)-t*attractionProfile b R (dist x y))- + (coreReal t (dist x y)-t*attractionProfile a R (dist x y)) = + -(t*(attractionProfile b R (dist x y)-attractionProfile a R (dist x y))) by ring, + abs_neg, abs_mul, abs_of_nonneg ht] + rw [heq] + exact hh + +def localMomentBound (t β z : ℝ) : ℝ := + Real.exp (16/15*(1/64)*Real.exp (z+β*(t^2/2))) / (β*(t^2/8)/4) + +def familyPressureLipschitz (t β h : ℝ) : ℝ := + 216*(β/2*localMomentBound t β (t*h))*2197*bumpIntegral⁻¹ + +lemma localMomentBound_nonneg {t β : ℝ} (hβ : 0 ≤ β) (z : ℝ) : + 0 ≤ localMomentBound t β z := by unfold localMomentBound; positivity + +lemma familyPressureLipschitz_nonneg {t β h : ℝ} (hβ : 0 ≤ β) : + 0 ≤ familyPressureLipschitz t β h := by + unfold familyPressureLipschitz + have hC := localMomentBound_nonneg (t := t) hβ (t*h) + exact mul_nonneg (by positivity) (inv_nonneg.mpr bumpIntegral_pos.le) + +theorem finiteGrandPressure_family_difference {t L β h : ℝ} {a b m R : ℕ → ℝ} + (ht : 1 ≤ t) (hL : 1 ≤ L) (hβ : 0 < β) + (ha : ∀ n, 0 ≤ a n) (hb : ∀ n, 0 ≤ b n) (hm : ∀ n, 0 ≤ m n) + (hR : ∀ n, 1 ≤ R n) (hsa : Summable a) (hsb : Summable b) (hsm : Summable m) + (ham : ∀ n, a n ≤ m n) (hbm : ∀ n, b n ≤ m n) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, m n) ≤ (t^2/8)/8) : + |finiteGrandPressure (familyPotential t a R) t L β h- + finiteGrandPressure (familyPotential t b R) t L β h| ≤ + familyPressureLipschitz t β h * ∑' n, |b n-a n| := by + classical + have ht0 : 0 < t := lt_of_lt_of_le zero_lt_one ht + have hL0 : 0 < L := lt_of_lt_of_le zero_lt_one hL + have hcoeff : 0 ≤ 2197*t*bumpIntegral⁻¹ := mul_nonneg (by positivity) (inv_nonneg.mpr bumpIntegral_pos.le) + have hstable (c : ℕ → ℝ) (hc : ∀ n, 0 ≤ c n) (hsc : Summable c) (hcm : ∀ n, c n ≤ m n) : + StableWith (familyPotential t c R) (t^2/2) := by + apply stable_familyPotential ht0.le hc hR hsc + have hh := (mul_le_mul_of_nonneg_left (hsc.tsum_le_tsum hcm hsm) hcoeff).trans hrow + nlinarith [sq_nonneg t] + let I := {k // k ∈ cubeCells L} + let e : I → Cell := Subtype.val + have he : Function.Injective e := Subtype.val_injective + let : Nonempty I := ⟨⟨cellOf 0, cellOf_mem_cubeCells (by intro i; simp only [PiLp.zero_apply]; exact ⟨le_rfl, hL0.le⟩)⟩⟩ + let d n := |b n-a n| + have hd : Summable d := (hsb.sub hsa).abs + have hjrow (i : I) : ∑ j, familyCellMajorant t m R (e i) (e j) ≤ (t^2/8)/8 := + (familyCellMajorant_row e he ht0.le hm hR hsm (e i)).trans hrow + have hh := grandOn_grid_perturbation e he (measurableSet_cube L) + (by rw [volume_cube]; exact ENNReal.pow_ne_top ENNReal.ofReal_ne_top) + (fun x hx => ⟨⟨cellOf x, cellOf_mem_cubeCells hx⟩, rfl⟩) + (continuous_familyPotential ha hR hsa t) (continuous_familyPotential hb hR hsb t) + (bounded_familyPotential ha hR hsa t) (bounded_familyPotential hb hR hsb t) + (hstable a ha hsa ham) (hstable b hb hsb hbm) ht0 hβ (t*h) + (familyCellMajorant t m R) (familyCellMajorant t d R) + (familyCellMajorant_nonneg ht0.le hm hR) (familyCellMajorant_symm t m R) hjrow + (familyPotential_grid_lower ht0.le ha hm hR hsa hsm ham) + (familyPotential_grid_lower ht0.le hb hm hR hsb hsm hbm) + (familyCellMajorant_nonneg ht0.le (fun n => abs_nonneg _) hR) + (familyPotential_grid_difference ht0.le ha hb hR hsa hsb) + have hsum : (∑ i : I, ∑ j : I, familyCellMajorant t d R (e i) (e j)) ≤ + 216*L^3*(2197*t*bumpIntegral⁻¹*∑' n, d n) := by + calc + _ ≤ ∑ i : I, (2197*t*bumpIntegral⁻¹*∑' n, d n) := + Finset.sum_le_sum (fun i _ => familyCellMajorant_row e he ht0.le (fun n => abs_nonneg _) hR hd (e i)) + _ = (Fintype.card I : ℝ)*(2197*t*bumpIntegral⁻¹*∑' n, d n) := by simp + _ ≤ _ := mul_le_mul_of_nonneg_right (by simpa only [I, Fintype.card_coe] using card_cubeCells hL) + (mul_nonneg hcoeff (tsum_nonneg (fun n => abs_nonneg _))) + change |Real.log (grandOn (familyPotential t a R) (cube L) β (t*h))- + Real.log (grandOn (familyPotential t b R) (cube L) β (t*h))| ≤ + β/2*localMomentBound t β (t*h)*_ at hh + rw [grandOn_cube, grandOn_cube] at hh + unfold finiteGrandPressure + rw [← sub_div, abs_div, abs_of_pos (mul_pos ht0 (pow_pos hL0 3))] + apply (div_le_iff₀ (mul_pos ht0 (pow_pos hL0 3))).mpr + calc + _ ≤ β/2*localMomentBound t β (t*h)*(216*L^3*(2197*t*bumpIntegral⁻¹*∑' n, d n)) := + hh.trans (mul_le_mul_of_nonneg_left hsum (mul_nonneg (by positivity) (localMomentBound_nonneg hβ.le _))) + _ = _ := by unfold familyPressureLipschitz; dsimp only [d]; ring + +lemma stable_family_of_master {t : ℝ} {a m R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hsa : Summable a) (hsm : Summable m) + (ham : ∀ n, a n ≤ m n) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, m n) ≤ (t^2/8)/8) : + StableWith (familyPotential t a R) (t^2/2) := by + apply stable_familyPotential ht ha hR hsa + have hcoeff : 0 ≤ 2197*t*bumpIntegral⁻¹ := mul_nonneg (by positivity) (inv_nonneg.mpr bumpIntegral_pos.le) + have hh := (mul_le_mul_of_nonneg_left (hsa.tsum_le_tsum ham hsm) hcoeff).trans hrow + nlinarith [sq_nonneg t] + +theorem grandPressure_family_difference {t β h : ℝ} {a b m R : ℕ → ℝ} + (ht : 1 ≤ t) (hβ : 0 < β) + (ha : ∀ n, 0 ≤ a n) (hb : ∀ n, 0 ≤ b n) (hm : ∀ n, 0 ≤ m n) + (hR : ∀ n, 1 ≤ R n) (hsa : Summable a) (hsb : Summable b) (hsm : Summable m) + (ham : ∀ n, a n ≤ m n) (hbm : ∀ n, b n ≤ m n) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, m n) ≤ (t^2/8)/8) : + |grandPressure (familyPotential t a R) t β h-grandPressure (familyPotential t b R) t β h| ≤ + familyPressureLipschitz t β h * ∑' n, |b n-a n| := by + have ht0 : 0 < t := lt_of_lt_of_le zero_lt_one ht + have hlim (c : ℕ → ℝ) (hc : ∀ n, 0 ≤ c n) (hsc : Summable c) (hcm : ∀ n, c n ≤ m n) : + Tendsto (fun L : ℝ => finiteGrandPressure (familyPotential t c R) t L β h) atTop + (nhds (grandPressure (familyPotential t c R) t β h)) := + (grandPressure_spec (continuous_familyPotential hc hR hsc t) (bounded_familyPotential hc hR hsc t) + (stable_family_of_master ht0.le hc hR hsc hsm hcm hrow) ht0 hβ.le + (fun r hr => familyPotential_nonpos_outer hc hR ht hr) h).1 + apply le_of_tendsto ((hlim a ha hsa ham).sub (hlim b hb hsb hbm)).abs + filter_upwards [eventually_ge_atTop (1 : ℝ)] with L hL + exact finiteGrandPressure_family_difference ht hL hβ ha hb hm hR hsa hsb hsm ham hbm hrow + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ProductConfigurations.lean b/lean/OAI/Probability/RadialTransition/ProductConfigurations.lean new file mode 100644 index 0000000000000000000000000000000000000000..5e985f1538e10af3c395bb802a1133085049ea2d --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ProductConfigurations.lean @@ -0,0 +1,55 @@ +import OAI.Probability.RadialTransition.FockIntegral + +namespace OAI + +universe uX + +noncomputable section + + +open Filter MeasureTheory Set + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition +section ProductConfigurations +variable {I : Type} [Fintype I] (X : I → Type uX) [∀ i, TopologicalSpace (X i)] + +def configurationsEquiv : (Σ n : I → ℕ, ∀ i, Fin (n i) → X i) ≃ (∀ i, ParticleState (X i)) where + toFun s i := ⟨s.1 i, s.2 i⟩ + invFun x := ⟨fun i => (x i).1, fun i => (x i).2⟩ + left_inv s := by cases s; rfl + right_inv x := rfl + +def configurationsHomeomorph : (Σ n : I → ℕ, ∀ i, Fin (n i) → X i) ≃ₜ (∀ i, ParticleState (X i)) := + (configurationsEquiv X).toHomeomorphOfContinuousOpen + (continuous_sigma (fun _n => continuous_pi (fun i => continuous_sigmaMk.comp (continuous_apply i)))) + (isOpenMap_sigma.mpr (fun n => (Topology.IsOpenEmbedding.piMap + (fun i => (Topology.IsOpenEmbedding.sigmaMk (i := n i) : + Topology.IsOpenEmbedding (@Sigma.mk ℕ (fun k => Fin k → X i) (n i))))).isOpenMap)) + +end ProductConfigurations +section MultiObservable +variable {I : Type} [Fintype I] {X : Type uX} [TopologicalSpace X] + +def multiParticleMultiset (x : I → ParticleState X) : Multiset X := ∑ i, particleMultiset (x i) + +lemma continuous_multiParticleObservable (F : Multiset X → ℝ≥0∞) + (hF : ContinuousConfiguration F) (s : Multiset X) : + Continuous (fun x : I → ParticleState X => F (s+multiParticleMultiset x)) := by + have hc : Continuous (fun x : Σ n : I → ℕ, ∀ i, Fin (n i) → X => + F (s+∑ i, configurationMultiset (x.2 i))) := by + apply continuous_sigma + intro n + have hh := (hF s (Σ i, Fin (n i))).comp + (show Continuous (fun x : ∀ i, Fin (n i) → X => fun p : Σ i, Fin (n i) => x p.1 p.2) from by + exact continuous_pi (fun p => (continuous_apply p.2).comp (continuous_apply p.1))) + simpa only [Function.comp_def, configurationMultiset, Fintype.sum_sigma] using hh + exact hc.comp (configurationsHomeomorph (fun _ : I => X)).symm.continuous + +end MultiObservable +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ProductFock.lean b/lean/OAI/Probability/RadialTransition/ProductFock.lean new file mode 100644 index 0000000000000000000000000000000000000000..718339c00a65294480ea966c586799c329a67bfd --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ProductFock.lean @@ -0,0 +1,57 @@ +import OAI.Probability.RadialTransition.ConfigurationMaps + +namespace OAI + +universe uX uY + +noncomputable section + + +open Filter MeasureTheory Set + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition +section GeneralFock +variable {I : Type} [Fintype I] {X : Type uX} [TopologicalSpace X] [MeasurableSpace X] + [BorelSpace X] [SecondCountableTopology X] + +lemma particleBase_sum_observable (F : Multiset X → ℝ≥0∞) (hF : ContinuousConfiguration F) + (μ : I → Measure X) [∀ i, IsFiniteMeasure (μ i)] (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (∑ i, μ i) z) = + ∫⁻ x, F (s+multiParticleMultiset x) ∂Measure.pi (fun i => particleBase (μ i) z) := by + let e := (Fintype.equivFin I).symm + have hs : (∑ i, μ i) = ∑ j, μ (e j) := (e.sum_comp μ).symm + rw [hs, particleBase_fin_sum_observable F hF] + have hp := measurePreserving_piCongrLeft (fun i => particleBase (μ i) z) e + rw [← hp.lintegral_comp (continuous_multiParticleObservable F hF s).measurable] + apply lintegral_congr + intro x + congr 1 + dsimp [multiParticleMultiset, MeasurableEquiv.piCongrLeft] + simpa [Equiv.piCongrLeft] using + congrArg (fun q => s+q) (e.sum_comp (fun i => particleMultiset (x (e.symm i)))) + +variable (Y : I → Type uY) [∀ i, TopologicalSpace (Y i)] [∀ i, MeasurableSpace (Y i)] + [∀ i, BorelSpace (Y i)] [∀ i, SecondCountableTopology (Y i)] + +def mappedMultiParticleMultiset (pos : ∀ i, Y i → X) (x : ∀ i, ParticleState (Y i)) : Multiset X := + ∑ i, particleMultiset (mapParticle (pos i) (x i)) + +lemma particleBase_sum_map_observable (F : Multiset X → ℝ≥0∞) (hF : ContinuousConfiguration F) + (ν : ∀ i, Measure (Y i)) [∀ i, IsFiniteMeasure (ν i)] + (pos : ∀ i, Y i → X) (hpos : ∀ i, Measurable (pos i)) (z : ℝ) (s : Multiset X) : + (∫⁻ x, F (s+particleMultiset x) ∂particleBase (∑ i, Measure.map (pos i) (ν i)) z) = + ∫⁻ x, F (s+mappedMultiParticleMultiset Y pos x) ∂Measure.pi (fun i => particleBase (ν i) z) := by + rw [particleBase_sum_observable F hF] + simp_rw [← particleBase_map _ _ (hpos _)] + rw [← Measure.pi_map_pi (fun i => (measurable_mapParticle (hpos i)).aemeasurable)] + exact lintegral_map (continuous_multiParticleObservable F hF s).measurable + (measurable_pi_iff.mpr (fun i => (measurable_mapParticle (hpos i)).comp (measurable_pi_apply i))) + +end GeneralFock +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/Propagation.lean b/lean/OAI/Probability/RadialTransition/Propagation.lean new file mode 100644 index 0000000000000000000000000000000000000000..718695a13e7c4835fb01b8d58593ea14e94b2ece --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/Propagation.lean @@ -0,0 +1,139 @@ +import OAI.Probability.RadialTransition.PressureBall + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma parameter_shift_dist (x y : Parameter) (z : ℝ) : + dist (parameter (x 0) (x 1+z)) (parameter (y 0) (y 1+z))=dist x y := by + rw [dist_eq_norm,parameter_sub,dist_eq_norm] + congr 1 + ext i + fin_cases i <;> simp + +lemma parameter_shift_dist_self (x : Parameter) (z : ℝ) : + dist (parameter (x 0) (x 1+z)) x=|z| := by + rw [← parameter_eta x,dist_eq_norm,parameter_sub] + simp only [parameter_zero,parameter_one,sub_self,add_sub_cancel_left] + exact parameter_vertical_norm z + +lemma phaseWindow_shift {x : Parameter} {r z : ℝ} (hx : x ∈ phaseWindow r) : + parameter (x 0) (x 1+z) ∈ phaseWindow (r+|z|) := + phaseWindow_near hx (by rw [Metric.mem_closedBall,parameter_shift_dist_self]) + +lemma propagate_phase_groups {P Q : Pressure} {a δ C U k l r s : ℝ} + (hP : ConvexOn ℝ positiveParameters (onParameters P)) + (hQ : ConvexOn ℝ positiveParameters (onParameters Q)) + (ha : 0 < a) (hδ : 0 ≤ δ) (hC : 0 ≤ C) (hU : 0 ≤ U) + (hk : 0 < k) (hl : 0 < l) (hr : 0 ≤ r) (hs : s ≤ 1/4) + (hgap : 2*(k+2*δ/(k*a)+2*C*l/k+r) happ _ (phaseWindow_mono hs (htest x hxball z (hzbound z hz)))) + (fun z hz => by + have hp := hlip _ (phaseWindow_mono hs (htest y hy z (hzbound z hz))) + _ (phaseWindow_mono hs (htest x hxball z (hzbound z hz))) + rw [parameter_shift_dist] at hp + exact hp.trans (mul_le_mul_of_nonneg_left (Metric.mem_closedBall.mp hy) hC)) + apply hhh.trans + have hfirst : k*a/(2*w 0*a) ≤ k := by + apply (div_le_iff₀ (by positivity : 0 < 2*w 0*a)).mpr + have hm := mul_le_mul_of_nonneg_right (show 1 ≤ 2*w 0 by linarith [hwβ.1]) (mul_nonneg hk.le ha.le) + nlinarith only [hm] + have heq : 2*C*(l*a)/(k*a)=2*C*l/k := by field_simp + rw [heq] + dsimp [b] + linarith + obtain ⟨i,hi⟩ := common_group_of_density_band + (fun y => supportSet (onParameters P) positiveParameters y) + (Metric.closedBall x (l*a)) phaseSlope (fun v => v 1) ⟨x,hxball⟩ + (fun y hy => hgroups y (hbase y hy)) + (fun y hy => supportSet_nonempty isOpen_positiveParameters hP (hsp (hbase y hy))) + hband (fun v w => by simpa only [PiLp.sub_apply,dist_eq_norm] using parameter_coord_abs_le (v-w) 1) + phase_densities_separated hgap + have he' : parameter e u ∈ supportSet (onParameters Q) positiveParameters x := by + apply pressureSupport_iff.mp + exact he + have hnorm := support_transfer_bound (onParameters P) (onParameters Q) positiveParameters x (phaseSlope i) + (parameter e u) (mul_pos hl ha) hr hδ (fun y hy => hsp (hbase y hy)) + (fun y hy => happ y (hbaseq y hy)) + (fun y hy => by + obtain ⟨v,hv⟩ := supportSet_nonempty isOpen_positiveParameters hP (hsp (hbase y hy)) + exact ⟨v,hv,hi y hy hv⟩) he' + have hsq : u^2 ≤ U^2 := (sq_le_sq₀ hub.1 hU).mpr hub.2 + refine ⟨i, Metric.mem_closedBall.mpr ?_⟩ + rw [dist_eq_norm] + have heq : parameter (e+a*u^2/2) u-phaseSlope i = + (parameter e u-phaseSlope i)+parameter (a*u^2/2) 0 := by + ext j + fin_cases j <;> simp + ring + rw [heq] + have hnorm' := norm_add_le (parameter e u-phaseSlope i) (parameter (a*u^2/2) 0) + rw [parameter_horizontal_norm,abs_of_nonneg (by positivity : 0 ≤ a*u^2/2)] at hnorm' + nlinarith [mul_le_mul_of_nonneg_left hsq ha.le] + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/RadialKernel.lean b/lean/OAI/Probability/RadialTransition/RadialKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..bcf67c230b4b86c236837a6646d4365e1fb3d6f4 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/RadialKernel.lean @@ -0,0 +1,82 @@ +import OAI.Probability.RadialTransition.SupportControl + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +def rawBumpProfile (r : ℝ) : ℝ := Real.smoothTransition (2 - 2 * r ^ 2) + +def rawBump (x : Position) : ℝ := rawBumpProfile ‖x‖ + +theorem rawBumpProfile_nonneg (r : ℝ) : 0 ≤ rawBumpProfile r := + Real.smoothTransition.nonneg _ + +theorem rawBumpProfile_le_one (r : ℝ) : rawBumpProfile r ≤ 1 := + Real.smoothTransition.le_one _ + +theorem rawBumpProfile_zero {r : ℝ} (hr : 1 ≤ r) : rawBumpProfile r = 0 := by + apply Real.smoothTransition.zero_of_nonpos + nlinarith + +theorem continuous_rawBumpProfile : Continuous rawBumpProfile := by + exact Real.smoothTransition.continuous.comp (by fun_prop) + +theorem contDiff_rawBump : ContDiff ℝ ∞ rawBump := by + exact Real.smoothTransition.contDiff.comp + (contDiff_const.sub (contDiff_const.mul (contDiff_norm_sq ℝ))) + +theorem compactSupport_rawBump : HasCompactSupport rawBump := by + apply HasCompactSupport.of_support_subset_isCompact (isCompact_closedBall (0 : Position) 1) + intro x hx + rw [Metric.mem_closedBall, dist_zero_right] + by_contra h + exact hx (rawBumpProfile_zero (le_of_not_ge h)) + +def bumpIntegral : ℝ := ∫ x : Position, rawBump x + +theorem bumpIntegral_pos : 0 < bumpIntegral := by + apply contDiff_rawBump.continuous.integral_pos_of_hasCompactSupport_nonneg_nonzero + compactSupport_rawBump (fun x => rawBumpProfile_nonneg ‖x‖) (x := 0) + simp [rawBump, rawBumpProfile, Real.smoothTransition.one_of_one_le (by norm_num : (1 : ℝ) ≤ 2)] + +def bumpProfile (r : ℝ) : ℝ := rawBumpProfile r / bumpIntegral + +def bump (x : Position) : ℝ := bumpProfile ‖x‖ + +theorem bumpProfile_nonneg (r : ℝ) : 0 ≤ bumpProfile r := + div_nonneg (rawBumpProfile_nonneg r) bumpIntegral_pos.le + +theorem bumpProfile_bound (r : ℝ) : |bumpProfile r| ≤ bumpIntegral⁻¹ := by + rw [abs_of_nonneg (bumpProfile_nonneg r)] + simpa [bumpProfile, one_div] using + div_le_div_of_nonneg_right (rawBumpProfile_le_one r) bumpIntegral_pos.le + +theorem bumpProfile_zero {r : ℝ} (hr : 1 ≤ r) : bumpProfile r = 0 := by + rw [bumpProfile, rawBumpProfile_zero hr, zero_div] + +theorem continuous_bumpProfile : Continuous bumpProfile := + continuous_rawBumpProfile.div_const _ + +theorem contDiff_bump : ContDiff ℝ ∞ bump := contDiff_rawBump.div_const _ + +theorem compactSupport_bump : HasCompactSupport bump := by + apply compactSupport_rawBump.mono + intro x hx hr + apply hx + change rawBump x / bumpIntegral = 0 + rw [hr, zero_div] + +theorem integral_bump : ∫ x : Position, bump x = 1 := by + change (∫ x : Position, rawBump x / bumpIntegral) = 1 + rw [integral_div, ← bumpIntegral, div_self bumpIntegral_pos.ne'] + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/RangeBounds.lean b/lean/OAI/Probability/RadialTransition/RangeBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..08683b0f76deef6379bc22dfb34a3ea2bae5e497 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/RangeBounds.lean @@ -0,0 +1,381 @@ +import OAI.Probability.RadialTransition.MacroRegions + +namespace OAI + +universe uG uI + +noncomputable section + + +open Function MeasureTheory Set Filter + +open scoped ContDiff NNReal BigOperators ENNReal + +namespace RadialTransition + +lemma cellMargin_mono {R S : ℝ} (h : R ≤ S) : cellMargin R ≤ cellMargin S := by + unfold cellMargin + have hc := Int.ceil_mono (show 4*R ≤ 4*S by linarith) + omega + +lemma cellReach_mono {R S : ℝ} {i j : Cell} (h : R ≤ S) (hc : CellReach R i j) : CellReach S i j := + fun d => (hc d).trans (cellMargin_mono h) + +lemma cellMargin_toNat_le {R : ℝ} (hR : 1 ≤ R) : ((cellMargin R).toNat:ℝ) ≤ 6*R := by + have hm := cellMargin_nonneg (zero_le_one.trans hR) + have he : ((cellMargin R).toNat:ℝ) = (cellMargin R:ℝ) := by exact_mod_cast Int.toNat_of_nonneg hm + rw [he] + have hc := Int.ceil_lt_add_one (4*R) + unfold cellMargin + push_cast + linarith + +lemma deletionMajorant_le {G : Type uG} [DecidableEq G] (g : Cell → G) + {W : Cell → Cell → ℝ} (hW : ∀ i j, 0 ≤ W i j) (i j : Cell) : + deletionMajorant g W i j ≤ W i j := by + unfold deletionMajorant + split_ifs + · exact hW i j + · exact le_rfl + +lemma deletionMajorant_grid_sum {m q : ℕ} (hq : 0 < q) {R C : ℝ} (hR : 0 ≤ R) (hC : 0 ≤ C) + {W : Cell → Cell → ℝ} (hW : ∀ i j, 0 ≤ W i j) + (hrow : ∀ k, ∑ j : GridIndex (m*q), W k (gridEmbed j) ≤ C) + (hsupp : ∀ i j, ¬ CellReach R i j → W i j = 0) : + ∑ i : GridIndex (m*q), ∑ j : GridIndex (m*q), + deletionMajorant (macroOf q) W (gridEmbed i) (gridEmbed j) ≤ + (m:ℝ)^3*(6*(cellMargin R).toNat*q^2)*C := by + apply grid_sum_boundary_bound hq hC + · intro i + exact (Finset.sum_le_sum (fun j _ => deletionMajorant_le (macroOf q) hW _ _)).trans (hrow _) + · intro i j hj + apply Finset.sum_eq_zero + intro k _ + by_cases hc : CellReach R (gridEmbed (blockEmbed i j)) (gridEmbed k) + · have hk : macroOf q (gridEmbed k) = gridEmbed i := inner_block_macro hq i j hj (by + intro d + simpa only [Int.toNat_of_nonneg (cellMargin_nonneg hR)] using hc d) + simp only [deletionMajorant, blockEmbed_macro hq, hk, ite_true] + · simp only [deletionMajorant, hsupp _ _ hc, ite_self] + +lemma deletionMajorant_grid_sum_range {m q : ℕ} (hq : 0 < q) {R C : ℝ} (hR : 1 ≤ R) (hC : 0 ≤ C) + {W : Cell → Cell → ℝ} (hW : ∀ i j, 0 ≤ W i j) + (hrow : ∀ k, ∑ j : GridIndex (m*q), W k (gridEmbed j) ≤ C) + (hsupp : ∀ i j, ¬ CellReach R i j → W i j = 0) : + ∑ i : GridIndex (m*q), ∑ j : GridIndex (m*q), + deletionMajorant (macroOf q) W (gridEmbed i) (gridEmbed j) ≤ + 36*(m:ℝ)^3*q^2*R*C := by + calc + _ ≤ (m:ℝ)^3*(6*(cellMargin R).toNat*q^2)*C := + deletionMajorant_grid_sum hq (zero_le_one.trans hR) hC hW hrow hsupp + _ ≤ (m:ℝ)^3*(6*(6*R)*q^2)*C := by gcongr; exact cellMargin_toNat_le hR + _ = _ := by ring + +def referenceMajorant (t : ℝ) (a R : ℕ → ℝ) (i j : Cell) : ℝ := + cellMajorant 2 (8*t^2) i j + familyCellMajorant t a R i j + +lemma referenceMajorant_nonneg {t : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (i j : Cell) : + 0 ≤ referenceMajorant t a R i j := + add_nonneg (cellMajorant_nonneg (by norm_num) (by positivity) i j) + (familyCellMajorant_nonneg ht ha hR i j) + +lemma referenceMajorant_row {I : Type uI} [Fintype I] (e : I → Cell) (he : Function.Injective e) + {t : ℝ} {a R : ℕ → ℝ} (ht : 0 ≤ t) (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) + (hs : Summable a) (i : Cell) : + ∑ j, referenceMajorant t a R i (e j) ≤ 2197*8*t^2+2197*t*bumpIntegral⁻¹*∑' n, a n := by + simp only [referenceMajorant, Finset.sum_add_distrib] + have hc := cellMajorant_row e he (R := 2) (W := 8*t^2) (by norm_num) (by positivity) i + have ha' := familyCellMajorant_row e he ht ha hR hs i + linarith + +lemma referenceMajorant_support {t R₀ : ℝ} {a R : ℕ → ℝ} (hR₀ : 2 ≤ R₀) + (hrange : ∀ n, R n ≤ R₀) (i j : Cell) (hc : ¬ CellReach R₀ i j) : + referenceMajorant t a R i j = 0 := by + have hc₂ : ¬ CellReach 2 i j := fun h => hc (cellReach_mono hR₀ h) + have hcn (n : ℕ) : ¬ CellReach (R n) i j := fun h => hc (cellReach_mono (hrange n) h) + simp only [referenceMajorant, familyCellMajorant, cellMajorant, ite_eq_right hc₂, ite_eq_right (hcn _), + mul_zero, tsum_zero, add_zero] + +lemma core_le_cellMajorant {t : ℝ} (ht : 1 ≤ t) (x y : Position) : + corePotential t (nndist x y) ≤ cellMajorant 2 (8*t^2) (cellOf x) (cellOf y) := by + by_cases hc : CellReach 2 (cellOf x) (cellOf y) + · simp only [cellMajorant, ite_eq_left hc] + have he : ((2:ℝ)^3)⁻¹*(8*t^2) = t^2 := by ring + rw [he] + exact coreReal_le t (dist x y) + · have hd : 2 < dist x y := lt_of_not_ge (fun h => hc (cellReach_of_dist h)) + have ht0 : 0 < t := zero_lt_one.trans_le ht + have hz : corePotential t (nndist x y) = 0 := coreReal_zero_outer ht0 + (by change 1+1/t ≤ dist x y; have hi := one_div_le_one_div_of_le zero_lt_one ht; norm_num only [div_one] at hi; linarith) + rw [hz, cellMajorant, ite_eq_right hc] + +lemma family_abs_le_referenceMajorant {t : ℝ} {a R : ℕ → ℝ} (ht : 1 ≤ t) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) (x y : Position) : + |radialPair (familyPotential t a R) x y| ≤ referenceMajorant t a R (cellOf x) (cellOf y) := by + have ht0 : 0 ≤ t := zero_le_one.trans ht + have hc : |coreReal t (dist x y)| = coreReal t (dist x y) := abs_of_nonneg (coreReal_nonneg _ _) + have ha' : |t*attractionProfile a R (dist x y)| = t*attractionProfile a R (dist x y) := + abs_of_nonneg (mul_nonneg ht0 (attractionProfile_nonneg ha hR _)) + calc + _ ≤ |coreReal t (dist x y)|+|t*attractionProfile a R (dist x y)| := abs_sub _ _ + _ = coreReal t (dist x y)+t*attractionProfile a R (dist x y) := by rw [hc, ha'] + _ ≤ _ := add_le_add (core_le_cellMajorant ht x y) (attraction_le_familyCellMajorant ht0 ha hR hs x y) + +def referenceRowBound (t A : ℝ) : ℝ := 2197*8*t^2+2197*t*bumpIntegral⁻¹*A + +def boxPressureConstant (t β h A : ℝ) : ℝ := + 288*β*localMomentBound t β (t*h)*referenceRowBound t A/t + +lemma referenceRowBound_nonneg {t A : ℝ} (ht : 0 ≤ t) (hA : 0 ≤ A) : + 0 ≤ referenceRowBound t A := by + unfold referenceRowBound + have hb := bumpIntegral_pos.le + positivity + +lemma boxPressureConstant_nonneg {t β h A : ℝ} (ht : 0 ≤ t) (hβ : 0 ≤ β) (hA : 0 ≤ A) : + 0 ≤ boxPressureConstant t β h A := by + unfold boxPressureConstant + exact div_nonneg (mul_nonneg (mul_nonneg (by positivity) (localMomentBound_nonneg hβ _)) + (referenceRowBound_nonneg ht hA)) ht + +lemma family_aligned_box_comparison {m q : ℕ} (hm : 0 < m) (hq : 0 < q) + {t β h R₀ : ℝ} {a R : ℕ → ℝ} (ht : 1 ≤ t) (hβ : 0 < β) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hR₀ : 2 ≤ R₀) (hrange : ∀ n, R n ≤ R₀) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, a n) ≤ (t^2/8)/8) : + |finiteGrandPressure (familyPotential t a R) t ((m:ℝ)*q/4) β h- + finiteGrandPressure (familyPotential t a R) t ((q:ℝ)/4) β h| ≤ + boxPressureConstant t β h (∑' n, a n)*R₀/((q:ℝ)/4) := by + have ht0 : 0 < t := zero_lt_one.trans_le ht + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hm0 : (0:ℝ) < m := by exact_mod_cast hm + let : NeZero (m*q) := ⟨ne_of_gt (Nat.mul_pos hm hq)⟩ + have hcont := continuous_familyPotential ha hR hs t + have hbound := bounded_familyPotential ha hR hs t + have hstable := stable_family_of_master ht0.le ha hR hs hs (fun _ => le_rfl) hrow + let φ := familyPotential t a R + let W := referenceMajorant t a R + have hW : ∀ i j, 0 ≤ W i j := referenceMajorant_nonneg ht0.le ha hR + have hcost := deletedPair_grid_bound (@gridEmbed (m*q)) (gridEmbed_injective _) (macroOf q) + (measurableSet_halfCube ((m*q:ℕ)/4)) (halfCube_grid_cover (m*q)) hcont + (show Continuous (0 : Potential) from continuous_const) ht0 hβ (t*h) + (familyCellMajorant t a R) (fun _ _ => 0) W + (familyCellMajorant_nonneg ht0.le ha hR) (fun _ _ => le_rfl) + (fun i j => by simp only [add_zero, familyCellMajorant_symm]) + (fun i => by simpa only [add_zero] using + (familyCellMajorant_row (@gridEmbed (m*q)) (gridEmbed_injective _) ht0.le ha hR hs (gridEmbed i)).trans hrow) + (familyPotential_grid_lower ht0.le ha ha hR hs hs (fun _ => le_rfl)) + (fun _ _ => by simp only [neg_zero, radialPair, Pi.zero_apply, le_refl]) hW + (family_abs_le_referenceMajorant ht ha hR hs) + have hA : volume (halfCube (((m:ℝ)*q)/4)) ≠ ⊤ := by rw [volume_halfCube]; finiteness + have hgrand := pairGrand_radial hcont hbound hstable hβ.le hA (t*h) + simp only [add_zero, Nat.cast_mul] at hcost + rw [hgrand, grandOn_halfCube hcont hbound hstable hβ.le, grandOn_cube, + deletedPair_macro_factorization hq hcont hbound hstable hβ.le (t*h), grandOn_cube, + Real.log_pow] at hcost + have hC : 0 ≤ referenceRowBound t (∑' n, a n) := referenceRowBound_nonneg ht0.le (tsum_nonneg ha) + have hsum := deletionMajorant_grid_sum_range (m := m) hq (show 1 ≤ R₀ by linarith) hC hW + (referenceMajorant_row (@gridEmbed (m*q)) (gridEmbed_injective _) ht0.le ha hR hs) + (referenceMajorant_support hR₀ hrange) + have hcoeff : 0 ≤ β/2*localMomentBound t β (t*h) := + mul_nonneg (by positivity) (localMomentBound_nonneg hβ.le _) + have hlog := hcost.trans (mul_le_mul_of_nonneg_left hsum hcoeff) + have hden : 0 < t*((m:ℝ)*q/4)^3 := by positivity + have he : finiteGrandPressure φ t ((m:ℝ)*q/4) β h-finiteGrandPressure φ t ((q:ℝ)/4) β h = + (Real.log (grandPartition φ t ((m:ℝ)*q/4) β h)-(m:ℝ)^3*Real.log (grandPartition φ t ((q:ℝ)/4) β h)) / + (t*((m:ℝ)*q/4)^3) := by + unfold finiteGrandPressure + field_simp + change |finiteGrandPressure φ t _ β h-finiteGrandPressure φ t _ β h| ≤ _ + rw [he, abs_div, abs_of_pos hden] + apply (div_le_iff₀ hden).mpr + convert hlog using 1 <;> dsimp only [φ, W, boxPressureConstant] at * + · simp only [Nat.cast_pow] + · field_simp + ring + +theorem finiteGrandPressure_family_box_error {q : ℕ} (hq : 0 < q) + {t β h R₀ : ℝ} {a R : ℕ → ℝ} (ht : 1 ≤ t) (hβ : 0 < β) + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hR₀ : 2 ≤ R₀) (hrange : ∀ n, R n ≤ R₀) + (hrow : 2197*t*bumpIntegral⁻¹*(∑' n, a n) ≤ (t^2/8)/8) : + |finiteGrandPressure (familyPotential t a R) t ((q:ℝ)/4) β h- + grandPressure (familyPotential t a R) t β h| ≤ + boxPressureConstant t β h (∑' n, a n)*R₀/((q:ℝ)/4) := by + have ht0 : 0 < t := zero_lt_one.trans_le ht + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hl := (grandPressure_spec (continuous_familyPotential ha hR hs t) + (bounded_familyPotential ha hR hs t) + (stable_family_of_master ht0.le ha hR hs hs (fun _ => le_rfl) hrow) + ht0 hβ.le (fun r hr => familyPotential_nonpos_outer ha hR ht hr) h).1 + have hL : Tendsto (fun m : ℕ => (m:ℝ)*q/4) atTop atTop := + (tendsto_natCast_atTop_atTop.atTop_mul_const hq0).atTop_div_const (by norm_num) + have hh := ((hl.comp hL).sub_const (finiteGrandPressure (familyPotential t a R) t ((q:ℝ)/4) β h)).abs + rw [abs_sub_comm] + apply le_of_tendsto hh + filter_upwards [eventually_gt_atTop (0:ℕ)] with m hm + exact family_aligned_box_comparison hm hq ht hβ ha hR hs hR₀ hrange hrow + +def bumpLip : ℝ≥0 := Classical.choose + (ContDiff.lipschitzWith_of_hasCompactSupport compactSupport_bump contDiff_bump (by simp)) + +lemma lipschitz_bump : LipschitzWith bumpLip bump := Classical.choose_spec + (ContDiff.lipschitzWith_of_hasCompactSupport compactSupport_bump contDiff_bump (by simp)) + +lemma scaledBump_nonneg {R : ℝ} (hR : 0 < R) (x : Position) : 0 ≤ scaledBump R x := by + rw [scaledBump_radial hR] + exact scaledBumpProfile_nonneg hR _ + +lemma continuous_scaledBump (R : ℝ) : Continuous (scaledBump R) := + continuous_const.mul (contDiff_bump.continuous.comp (continuous_id.const_smul R⁻¹)) + +lemma integrable_scaledBump {R : ℝ} (hR : 0 < R) : Integrable (scaledBump R) := by + have hc : HasCompactSupport (scaledBump R) := + (compactSupport_bump.comp_smul (inv_ne_zero hR.ne')).mul_left + exact (continuous_scaledBump R).integrable_of_hasCompactSupport hc + +lemma scaledBump_bound {R : ℝ} (hR : 0 < R) (x : Position) : + |scaledBump R x| ≤ (R^3)⁻¹*bumpIntegral⁻¹ := by + unfold scaledBump + rw [abs_mul, abs_of_nonneg (inv_nonneg.mpr (pow_nonneg hR.le _))] + exact mul_le_mul_of_nonneg_left (bumpProfile_bound _) (by positivity) + +lemma scaledBump_zero {R : ℝ} (hR : 0 < R) {x : Position} (hx : R ≤ ‖x‖) : scaledBump R x = 0 := by + rw [scaledBump_radial hR, scaledBumpProfile_zero hR hx] + +lemma scaledBump_symm (R : ℝ) (x y : Position) : scaledBump R (x-y) = scaledBump R (y-x) := by + unfold scaledBump bump + rw [← neg_sub x y, smul_neg, norm_neg] + +lemma scaledBump_oscillation {R : ℝ} (hR : 0 < R) (x y : Position) : + |scaledBump R x-scaledBump R y| ≤ (bumpLip:ℝ)/R^4*dist x y := by + have hh := lipschitz_bump.dist_le_mul (R⁻¹ • x) (R⁻¹ • y) + rw [dist_smul₀, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr hR)] at hh + simp only [Real.dist_eq] at hh + calc + _ = (R^3)⁻¹*|bump (R⁻¹ • x)-bump (R⁻¹ • y)| := by + unfold scaledBump + rw [← mul_sub, abs_mul, abs_of_nonneg (by positivity)] + _ ≤ (R^3)⁻¹*((bumpLip:ℝ)*(R⁻¹*dist x y)) := mul_le_mul_of_nonneg_left hh (by positivity) + _ = _ := by field_simp + +lemma macroOrigin_mem {q : ℕ} (hq : 0 < q) (k : Cell) : macroOrigin q k ∈ macroRegion q k := by + rw [macroRegion_translate hq] + intro d + change 0 ≤ (macroOrigin q k) d-(macroOrigin q k) d ∧ + (macroOrigin q k) d-(macroOrigin q k) d < (q:ℝ)/4 + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + simp only [sub_self]; exact ⟨le_rfl, by positivity⟩ + +lemma macro_distance_origin {q : ℕ} (hq : 0 < q) (k : Cell) {x : Position} + (hx : x ∈ macroRegion q k) : dist x (macroOrigin q k) ≤ (q:ℝ)/2 := by + rw [macroRegion_translate hq] at hx + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + have hc (d : Fin 3) : |x d-(macroOrigin q k) d| ≤ (q:ℝ)/4 := by + have hh : 0 ≤ x d-(macroOrigin q k) d ∧ x d-(macroOrigin q k) d < (q:ℝ)/4 := hx d + rw [abs_of_nonneg hh.1] + exact hh.2.le + have hs : dist x (macroOrigin q k)^2 ≤ 3*((q:ℝ)/4)^2 := by + rw [EuclideanSpace.dist_sq_eq] + calc + _ ≤ ∑ _d : Fin 3, ((q:ℝ)/4)^2 := by + apply Finset.sum_le_sum + intro d _ + simpa only [Real.dist_eq] using pow_le_pow_left₀ (abs_nonneg _) (hc d) 2 + _ = _ := by simp + nlinarith [dist_nonneg (x := x) (y := macroOrigin q k)] + +lemma macro_difference_dist {q : ℕ} (hq : 0 < q) {i j : Cell} {x y : Position} + (hx : x ∈ macroRegion q i) (hy : y ∈ macroRegion q j) : + dist (x-y) (macroOrigin q i-macroOrigin q j) ≤ (q:ℝ) := by + exact (dist_sub_sub_le x y _ _).trans (by linarith [macro_distance_origin hq i hx, macro_distance_origin hq j hy]) + +lemma macroReach_of_dist {q : ℕ} (hq : 0 < q) {R : ℝ} {i j : Cell} {x y : Position} + (hx : x ∈ macroRegion q i) (hy : y ∈ macroRegion q j) (hd : dist x y ≤ R) : + CellReach (R/q+1) i j := by + rw [macroRegion_translate hq] at hx hy + have hq0 : (0:ℝ) < q := by exact_mod_cast hq + intro d + have hxy : |y d-x d| ≤ R := by + simpa only [Real.dist_eq, abs_sub_comm] using (PiLp.dist_apply_le x y d).trans hd + have hxd : 0 ≤ x d-(q:ℝ)*(i d:ℝ)/4 ∧ x d-(q:ℝ)*(i d:ℝ)/4 < (q:ℝ)/4 := hx d + have hyd : 0 ≤ y d-(q:ℝ)*(j d:ℝ)/4 ∧ y d-(q:ℝ)*(j d:ℝ)/4 < (q:ℝ)/4 := hy d + have hceil := Int.le_ceil (4*(R/(q:ℝ)+1)) + have he : (q:ℝ)*(4*(R/(q:ℝ)+1)) = 4*R+4*q := by field_simp + have hh := mul_le_mul_of_nonneg_left hceil hq0.le + change (q:ℝ)*(4*(R/(q:ℝ)+1)) ≤ (q:ℝ)*(⌈4*(R/(q:ℝ)+1)⌉:ℝ) at hh + rw [he] at hh + have hc : |((j d:ℤ):ℝ)-(i d:ℝ)| ≤ (⌈4*(R/(q:ℝ)+1)⌉:ℤ)+(1:ℝ) := by + apply abs_le.mpr + have hab := abs_le.mp hxy + constructor <;> nlinarith + unfold cellMargin + exact_mod_cast hc + +def macroKernel (q : ℕ) (R : ℝ) (i j : Cell) : ℝ := + scaledBump R (macroOrigin q i-macroOrigin q j) + +def macroKernelError (q : ℕ) (R : ℝ) (i j : Cell) : ℝ := + if CellReach (R/q+1) i j then (bumpLip:ℝ)/R^4*q else 0 + +def macroKernelUpper (q : ℕ) (R : ℝ) (i j : Cell) : ℝ := + macroKernel q R i j+macroKernelError q R i j + +def macroKernelLower (q : ℕ) (R : ℝ) (i j : Cell) : ℝ := + max 0 (macroKernel q R i j-macroKernelError q R i j) + +lemma macroKernelError_nonneg (q : ℕ) (R : ℝ) (i j : Cell) : 0 ≤ macroKernelError q R i j := by + unfold macroKernelError + split_ifs <;> positivity + +lemma macroKernelUpper_nonneg {q : ℕ} {R : ℝ} (hR : 0 < R) (i j : Cell) : + 0 ≤ macroKernelUpper q R i j := add_nonneg (scaledBump_nonneg hR _) (macroKernelError_nonneg _ _ _ _) + +lemma macroKernelLower_nonneg (q : ℕ) (R : ℝ) (i j : Cell) : 0 ≤ macroKernelLower q R i j := le_max_left _ _ + +lemma macroKernel_symm (q : ℕ) (R : ℝ) (i j : Cell) : macroKernel q R i j = macroKernel q R j i := + scaledBump_symm _ _ _ + +lemma macroKernelError_symm (q : ℕ) (R : ℝ) (i j : Cell) : + macroKernelError q R i j = macroKernelError q R j i := by + unfold macroKernelError + have he : CellReach (R/q+1) i j ↔ CellReach (R/q+1) j i := ⟨cellReach_symm, cellReach_symm⟩ + simp only [he] + +lemma macroKernelUpper_symm (q : ℕ) (R : ℝ) (i j : Cell) : + macroKernelUpper q R i j = macroKernelUpper q R j i := by + unfold macroKernelUpper + rw [macroKernel_symm, macroKernelError_symm] + +lemma macroKernelLower_symm (q : ℕ) (R : ℝ) (i j : Cell) : + macroKernelLower q R i j = macroKernelLower q R j i := by + unfold macroKernelLower + rw [macroKernel_symm, macroKernelError_symm] + +lemma macroKernel_pair_bounds {q : ℕ} (hq : 0 < q) {R : ℝ} (hR : 0 < R) + {i j : Cell} {x y : Position} (hx : x ∈ macroRegion q i) (hy : y ∈ macroRegion q j) : + macroKernelLower q R i j ≤ scaledBump R (x-y) ∧ + scaledBump R (x-y) ≤ macroKernelUpper q R i j := by + have hc : |scaledBump R (x-y)-macroKernel q R i j| ≤ macroKernelError q R i j := by + by_cases h : CellReach (R/q+1) i j + · rw [macroKernelError, ite_eq_left h] + exact (scaledBump_oscillation hR _ _).trans + (mul_le_mul_of_nonneg_left (macro_difference_dist hq hx hy) (by positivity)) + · have hd : R < dist x y := lt_of_not_ge (fun hh => h (macroReach_of_dist hq hx hy hh)) + have hd' : R < dist (macroOrigin q i) (macroOrigin q j) := + lt_of_not_ge (fun hh => h (macroReach_of_dist hq (macroOrigin_mem hq i) (macroOrigin_mem hq j) hh)) + rw [macroKernel, scaledBump_zero hR (by simpa only [dist_eq_norm] using hd.le), + scaledBump_zero hR (by simpa only [dist_eq_norm] using hd'.le), sub_self, abs_zero, + macroKernelError, ite_eq_right h] + have hh := abs_le.mp hc + constructor + · exact max_le (scaledBump_nonneg hR _) (by linarith) + · unfold macroKernelUpper + linarith + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ScaleBudgets.lean b/lean/OAI/Probability/RadialTransition/ScaleBudgets.lean new file mode 100644 index 0000000000000000000000000000000000000000..c4315627b3d2ab2db415bcb26a0eb62e212b81de --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ScaleBudgets.lean @@ -0,0 +1,86 @@ +import OAI.Probability.RadialTransition.MultiScale + +namespace OAI + +noncomputable section +open scoped BigOperators +open Set Filter +namespace RadialTransition + +lemma scale_budgets {U C C₀ D K : ℝ} (hU : 0 ≤ U) (hC : 0 ≤ C) + (hC₀ : 0 < C₀) (hD : 0 < D) : + ∃ b k l : ℝ, 2 ≤ b ∧ 2*K ≤ b ∧ 0 < k ∧ 0 < l ∧ + (∀ n, (5/4*U+k+l+1)*(∑ j ∈ Finset.range n, scaleTail b j) ≤ 1/8) ∧ + (∀ n, ∑ j ∈ Finset.range n, (2*(D*(scaleTail b j)^2)/(l*scaleTail b j)+scaleTail b j*U^2/2) ≤ phaseRadius/2) ∧ + (∀ n, 2*(k+2*(D*(scaleTail b n)^2)/(k*scaleTail b n)+2*C*l/k+phaseRadius) b⁻¹^4) atTop (nhds 0) := by + simpa using (tendsto_inv_atTop_zero : Tendsto (fun b : ℝ => b⁻¹) atTop (nhds 0)).pow 4 + have hs : ∀ᶠ b : ℝ in atTop, S*(2*b⁻¹^4) ≤ 1/8 := by + have htend : Tendsto (fun b : ℝ => S*(2*b⁻¹^4)) atTop (nhds 0) := by simpa using (hq.const_mul 2).const_mul S + exact (htend.eventually (gt_mem_nhds (by norm_num : (0:ℝ)<1/8))).mono (fun _ h => h.le) + have hr : ∀ᶠ b : ℝ in atTop, R*(2*b⁻¹^4) ≤ phaseRadius/2 := by + have htend : Tendsto (fun b : ℝ => R*(2*b⁻¹^4)) atTop (nhds 0) := by simpa using (hq.const_mul 2).const_mul R + exact (htend.eventually (gt_mem_nhds (by have := phaseRadius_pos; positivity : (0:ℝ) h.le) + have ht : ∀ᶠ b : ℝ in atTop, T*(2*b⁻¹^4) ≤ pressureRadius/64 := by + have htend : Tendsto (fun b : ℝ => T*(2*b⁻¹^4)) atTop (nhds 0) := by simpa using (hq.const_mul 2).const_mul T + exact (htend.eventually (gt_mem_nhds (by have := pressureRadius_pos; positivity : (0:ℝ) h.le) + have he : ∀ᶠ b : ℝ in atTop, 2*(k+2*D*b⁻¹^4/k+2*C*l/k+phaseRadius)

2*(k+2*D*b⁻¹^4/k+2*C*l/k+phaseRadius)) atTop + (nhds (2*(k+2*C*l/k+phaseRadius))) := by + convert ((((hq.const_mul (2*D)).div_const k).const_add k).add_const (2*C*l/k) |>.add_const phaseRadius).const_mul 2 using 1; simp + exact htend.eventually (gt_mem_nhds hgap) + obtain ⟨b,⟨⟨⟨⟨⟨hb,hbK⟩,hbs⟩,hbr⟩,hbt⟩,hbe⟩⟩ := + (eventually_ge_atTop (2:ℝ) |>.and (eventually_ge_atTop (2*K)) |>.and hs |>.and hr |>.and ht |>.and he).exists + refine ⟨b,k,l,hb,hbK,hk,hl,?_,?_,?_,?_⟩ + · intro n + exact (mul_le_mul_of_nonneg_left (sum_scaleTail_le hb n) hS).trans hbs + · intro n + have heq (j : ℕ) : 2*(D*(scaleTail b j)^2)/(l*scaleTail b j)+scaleTail b j*U^2/2=R*scaleTail b j := by + have ha := scaleTail_pos (by linarith : (0:ℝ) hpoint j)) + rw [← Finset.mul_sum] + exact (mul_le_mul_of_nonneg_left (sum_scaleTail_le hb n) hT).trans hbt + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ScaleSequence.lean b/lean/OAI/Probability/RadialTransition/ScaleSequence.lean new file mode 100644 index 0000000000000000000000000000000000000000..cae0dddcc9527e04524ad693db7d6d61d66aeb06 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ScaleSequence.lean @@ -0,0 +1,146 @@ +import OAI.Probability.RadialTransition.FamilyControls + +namespace OAI + +noncomputable section +open scoped BigOperators +open Set Filter +namespace RadialTransition + +def doublePower (q : ℝ) (n : ℕ) : ℝ := q^(2^n) +lemma doublePower_zero (q : ℝ) : doublePower q 0=q := by simp [doublePower] +lemma doublePower_succ (q : ℝ) (n : ℕ) : doublePower q (n+1)=(doublePower q n)^2 := by + change q^(2^(n+1))=(q^(2^n))^2 + rw [Nat.pow_succ,pow_mul] +lemma doublePower_pos {q : ℝ} (hq : 0 < q) (n : ℕ) : 0 < doublePower q n := pow_pos hq _ +lemma doublePower_le {q : ℝ} (hq : 0 ≤ q) (hq1 : q ≤ 1) (n : ℕ) : doublePower q n ≤ q := by + have hh : 1 ≤ 2^n := Nat.one_le_pow n 2 (by norm_num) + simpa only [doublePower,pow_one] using pow_le_pow_of_le_one hq hq1 hh +lemma doublePower_le_geometric {q : ℝ} (hq : 0 ≤ q) (hq1 : q ≤ 1) (n : ℕ) : + doublePower q n ≤ q^(n+1) := pow_le_pow_of_le_one hq hq1 (Nat.succ_le_iff.mpr Nat.lt_two_pow_self) +lemma summable_doublePower {q : ℝ} (hq : 0 ≤ q) (hq1 : q < 1) : Summable (doublePower q) := by + apply Summable.of_nonneg_of_le (fun n => pow_nonneg hq _) (doublePower_le_geometric hq hq1.le) + simpa only [pow_succ] using (summable_geometric_of_lt_one hq hq1).mul_right q +lemma tsum_doublePower_le {q : ℝ} (hq : 0 ≤ q) (hq1 : q ≤ 1/2) : ∑' n, doublePower q n ≤ 2*q := by + have hq1' : q < 1 := by linarith + have hg := (summable_geometric_of_lt_one hq hq1').mul_right q + have hh := (summable_doublePower hq hq1').tsum_le_tsum (doublePower_le_geometric hq hq1'.le) + (show Summable (fun n => q^(n+1)) by simpa only [pow_succ] using hg) + have heq : (∑' n, q^(n+1))=q/(1-q) := by + simp_rw [pow_succ] + rw [tsum_mul_right,tsum_geometric_of_lt_one hq hq1'] + ring + rw [heq] at hh + apply hh.trans + apply (div_le_iff₀ (by linarith : 0 < 1-q)).mpr + nlinarith +lemma doublePower_pow (q : ℝ) (k n : ℕ) : doublePower (q^k) n=(doublePower q n)^k := by + dsimp [doublePower] + rw [← pow_mul,← pow_mul,Nat.mul_comm k] +lemma doublePower_mul (q r : ℝ) (n : ℕ) : doublePower (q*r) n=doublePower q n*doublePower r n := mul_pow _ _ _ +lemma doublePower_inv (q : ℝ) (n : ℕ) : doublePower q⁻¹ n=(doublePower q n)⁻¹ := inv_pow _ _ + +def scaleRange (b : ℝ) (n : ℕ) : ℝ := (doublePower b n)^32 + +def scaleTail (b : ℝ) (n : ℕ) : ℝ := (doublePower b n)⁻¹^4 + +lemma doublePower_one_le {b : ℝ} (hb : 1 ≤ b) (n : ℕ) : 1 ≤ doublePower b n := one_le_pow₀ hb +lemma doublePower_le_self {b : ℝ} (hb : 1 ≤ b) (n : ℕ) : b ≤ doublePower b n := by + simpa only [doublePower,pow_one] using pow_le_pow_right₀ hb (Nat.one_le_pow n 2 (by norm_num)) +lemma scaleRange_pos {b : ℝ} (hb : 0 < b) (n : ℕ) : 0 < scaleRange b n := pow_pos (doublePower_pos hb n) _ +lemma scaleRange_one_le {b : ℝ} (hb : 1 ≤ b) (n : ℕ) : 1 ≤ scaleRange b n := one_le_pow₀ (doublePower_one_le hb n) +lemma scaleRange_base_le {b : ℝ} (hb : 1 ≤ b) (n : ℕ) : b ≤ scaleRange b n := by + exact (doublePower_le_self hb n).trans (by + change doublePower b n ≤ (doublePower b n)^32 + simpa only [pow_one] using pow_le_pow_right₀ (doublePower_one_le hb n) (by norm_num : 1≤32)) +lemma scaleRange_succ (b : ℝ) (n : ℕ) : scaleRange b (n+1)=(scaleRange b n)^2 := by + dsimp [scaleRange] + rw [doublePower_succ,← pow_mul,← pow_mul] +lemma scaleRange_mono {b : ℝ} (hb : 1 ≤ b) : Monotone (scaleRange b) := by + apply monotone_nat_of_le_succ + intro n + rw [scaleRange_succ] + nlinarith [scaleRange_one_le hb n] +lemma scaleTail_pos {b : ℝ} (hb : 0 < b) (n : ℕ) : 0 < scaleTail b n := pow_pos (inv_pos.mpr (doublePower_pos hb n)) _ +lemma scaleTail_eq (b : ℝ) (n : ℕ) : scaleTail b n=doublePower (b⁻¹^4) n := by + rw [doublePower_pow,doublePower_inv] + rfl +lemma scaleTail_succ (b : ℝ) (n : ℕ) : scaleTail b (n+1)=(scaleTail b n)^2 := by + simp only [scaleTail_eq,doublePower_succ] +lemma scaleTail_le {b : ℝ} (hb : 1 ≤ b) (n : ℕ) : scaleTail b n ≤ b⁻¹^4 := by + rw [scaleTail_eq] + exact doublePower_le (by positivity) (pow_le_one₀ (inv_nonneg.mpr (by linarith)) (inv_le_one_of_one_le₀ hb)) n +lemma scaleTail_le_one {b : ℝ} (hb : 1 ≤ b) (n : ℕ) : scaleTail b n ≤ 1 := + (scaleTail_le hb n).trans (pow_le_one₀ (inv_nonneg.mpr (by linarith)) (inv_le_one_of_one_le₀ hb)) +lemma inv_fourth_le_half {b : ℝ} (hb : 2 ≤ b) : b⁻¹^4 ≤ 1/2 := by + have h0 : 0 < b := by linarith + have h1 : b⁻¹ ≤ 1/2 := by simpa using one_div_le_one_div_of_le (by norm_num : (0:ℝ)<2) hb + have h2 := pow_le_pow_left₀ (inv_nonneg.mpr h0.le) h1 4 + norm_num only [one_div,inv_pow] at * + linarith +lemma summable_scaleTail {b : ℝ} (hb : 2 ≤ b) : Summable (scaleTail b) := by + have h0 : 0 ≤ b⁻¹^4 := by positivity + have h1 : b⁻¹^4 < 1 := by linarith [inv_fourth_le_half hb] + convert summable_doublePower h0 h1 using 1 + ext n + exact scaleTail_eq b n +lemma tsum_scaleTail_le {b : ℝ} (hb : 2 ≤ b) : ∑' n, scaleTail b n ≤ 2*b⁻¹^4 := by + simpa only [scaleTail_eq] using tsum_doublePower_le (by positivity : 0 ≤ b⁻¹^4) (inv_fourth_le_half hb) +lemma sum_scaleTail_le {b : ℝ} (hb : 2 ≤ b) (n : ℕ) : ∑ j ∈ Finset.range n, scaleTail b j ≤ 2*b⁻¹^4 := by + exact ((summable_scaleTail hb).sum_le_tsum (Finset.range n) (fun j _ => (scaleTail_pos (by linarith) j).le)).trans (tsum_scaleTail_le hb) + +lemma scaleRange_root {b : ℝ} (hb : 0 < b) (n : ℕ) : (scaleRange b n)^(1/32:ℝ)=doublePower b n := by + dsimp [scaleRange] + rw [← Real.rpow_natCast_mul (doublePower_pos hb n).le] + norm_num +lemma scaleTail_literal {b : ℝ} (hb : 0 < b) (n : ℕ) : scaleTail b n=(scaleRange b (n+1))^(-(1/16:ℝ)) := by + dsimp [scaleRange,scaleTail] + rw [← Real.rpow_natCast_mul (doublePower_pos hb (n+1)).le] + norm_num + rw [doublePower_succ] + ring +lemma scaleTail_weight {b : ℝ} (hb : 0 < b) (n : ℕ) : + scaleTail b n*(scaleRange b (n+1))^(1/32:ℝ)=doublePower (b⁻¹^2) n := by + rw [scaleRange_root hb,doublePower_succ,doublePower_pow,doublePower_inv] + dsimp [scaleTail] + field_simp +lemma summable_scaleTail_weight {b : ℝ} (hb : 2 ≤ b) : + Summable (fun n => scaleTail b n*(scaleRange b (n+1))^(1/32:ℝ)) := by + have h0 : 0 < b := by linarith + have h1 : b⁻¹ ≤ 1/2 := by simpa using one_div_le_one_div_of_le (by norm_num : (0:ℝ)<2) hb + have hh := pow_le_pow_left₀ (inv_nonneg.mpr h0.le) h1 2 + have hh' : b⁻¹^2 < 1 := by norm_num only [one_div,inv_pow] at *; linarith + convert summable_doublePower (by positivity : 0 ≤ b⁻¹^2) hh' using 1 + ext n + exact scaleTail_weight h0 n + +lemma scale_kac_succ {b : ℝ} (hb : 1 ≤ b) (n : ℕ) : + Real.sqrt (scaleRange b n/scaleRange b (n+1))=(scaleTail b (n+1))^2 := by + have h0 : 0 < doublePower b n := doublePower_pos (by linarith) n + apply (Real.sqrt_le_iff.mpr ?_).antisymm + · apply (Real.le_sqrt (sq_nonneg _) (div_nonneg (scaleRange_pos (by linarith) n).le (scaleRange_pos (by linarith) (n+1)).le)).mpr + dsimp [scaleRange,scaleTail] + rw [doublePower_succ] + field_simp + norm_num + · constructor + · positivity + · dsimp [scaleRange,scaleTail] + rw [doublePower_succ] + field_simp + norm_num +lemma scale_kac_zero {b : ℝ} (hb : 2 ≤ b) : + Real.sqrt (2/scaleRange b 0) ≤ 2*(scaleTail b 0)^2 := by + have h0 : 0 < b := by linarith + apply Real.sqrt_le_iff.mpr + constructor + · positivity + · simp only [scaleRange,scaleTail,doublePower_zero] + have hp : 1 ≤ b^16 := one_le_pow₀ (by linarith : 1≤b) + field_simp + nlinarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ScaledKernels.lean b/lean/OAI/Probability/RadialTransition/ScaledKernels.lean new file mode 100644 index 0000000000000000000000000000000000000000..c0e0c4a22a4f7a4b15a17feea11497b552ebd2ca --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ScaledKernels.lean @@ -0,0 +1,173 @@ +import OAI.Probability.RadialTransition.CellStability + +namespace OAI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +def scaledBumpProfile (R r : ℝ) : ℝ := (R ^ 3)⁻¹ * bumpProfile (r / R) + +def scaledBump (R : ℝ) (x : Position) : ℝ := (R ^ 3)⁻¹ * bump (R⁻¹ • x) + +theorem scaledBump_radial {R : ℝ} (hR : 0 < R) (x : Position) : + scaledBump R x = scaledBumpProfile R ‖x‖ := by + simp [scaledBump, scaledBumpProfile, bump, norm_smul, Real.norm_eq_abs, + abs_of_pos hR, div_eq_mul_inv, mul_comm] + +theorem integral_scaledBump {R : ℝ} (hR : 0 < R) : + ∫ x : Position, scaledBump R x = 1 := by + unfold scaledBump + rw [integral_const_mul, Measure.integral_comp_inv_smul, integral_bump] + simp [Position, abs_of_pos (pow_pos hR 3), hR.ne'] + +theorem scaledBumpProfile_nonneg {R : ℝ} (hR : 0 < R) (r : ℝ) : + 0 ≤ scaledBumpProfile R r := + mul_nonneg (inv_nonneg.mpr (pow_nonneg hR.le 3)) (bumpProfile_nonneg _) + +theorem scaledBumpProfile_bound {R : ℝ} (hR : 1 ≤ R) (r : ℝ) : + |scaledBumpProfile R r| ≤ bumpIntegral⁻¹ := by + have hR0 : 0 < R := lt_of_lt_of_le zero_lt_one hR + rw [abs_of_nonneg (scaledBumpProfile_nonneg hR0 r)] + unfold scaledBumpProfile + apply le_trans (mul_le_mul_of_nonneg_left + ((le_abs_self _).trans (bumpProfile_bound (r / R))) + (inv_nonneg.mpr (pow_nonneg hR0.le 3))) + exact mul_le_of_le_one_left (inv_nonneg.mpr bumpIntegral_pos.le) + (inv_le_one_of_one_le₀ (one_le_pow₀ hR)) + +theorem scaledBumpProfile_zero {R r : ℝ} (hR : 0 < R) (hr : R ≤ r) : + scaledBumpProfile R r = 0 := by + rw [scaledBumpProfile, bumpProfile_zero ((le_div_iff₀ hR).mpr (by simpa using hr)), + mul_zero] + +theorem continuous_scaledBumpProfile (R : ℝ) : Continuous (scaledBumpProfile R) := + continuous_const.mul (continuous_bumpProfile.comp (continuous_id.div_const _)) + +def attractionProfile (a R : ℕ → ℝ) (r : ℝ) : ℝ := + ∑' n, a n * scaledBumpProfile (R n) r + +def familyPotential (t : ℝ) (a R : ℕ → ℝ) : Potential := + fun r => coreReal t r - t * attractionProfile a R r + +theorem attractionProfile_nonneg {a R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (r : ℝ) : + 0 ≤ attractionProfile a R r := by + apply tsum_nonneg + intro n + exact mul_nonneg (ha n) (scaledBumpProfile_nonneg (lt_of_lt_of_le zero_lt_one (hR n)) r) + +theorem summable_attractionProfile {a R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) (r : ℝ) : + Summable (fun n => a n * scaledBumpProfile (R n) r) := by + apply (hs.mul_right bumpIntegral⁻¹).of_nonneg_of_le + · intro n + exact mul_nonneg (ha n) (scaledBumpProfile_nonneg (lt_of_lt_of_le zero_lt_one (hR n)) r) + · intro n + exact mul_le_mul_of_nonneg_left ((le_abs_self _).trans (scaledBumpProfile_bound (hR n) r)) (ha n) + +theorem attractionProfile_bound {a R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) (r : ℝ) : + |attractionProfile a R r| ≤ (∑' n, a n) * bumpIntegral⁻¹ := by + rw [abs_of_nonneg (attractionProfile_nonneg ha hR r)] + unfold attractionProfile + rw [← tsum_mul_right] + exact Summable.tsum_le_tsum + (fun n => mul_le_mul_of_nonneg_left + ((le_abs_self _).trans (scaledBumpProfile_bound (hR n) r)) (ha n)) + (summable_attractionProfile ha hR hs r) (hs.mul_right _) + +theorem continuous_attractionProfile {a R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) : + Continuous (attractionProfile a R) := by + apply continuous_tsum (fun n => continuous_const.mul (continuous_scaledBumpProfile (R n))) + (hs.mul_right bumpIntegral⁻¹) + intro n r + change |a n * scaledBumpProfile (R n) r| ≤ a n * bumpIntegral⁻¹ + rw [abs_mul, abs_of_nonneg (ha n)] + exact mul_le_mul_of_nonneg_left (scaledBumpProfile_bound (hR n) r) (ha n) + +theorem continuous_familyPotential {a R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) (t : ℝ) : + Continuous (familyPotential t a R) := by + exact ((continuous_coreReal t).sub (continuous_const.mul + (continuous_attractionProfile ha hR hs))).comp NNReal.continuous_coe + +theorem bounded_familyPotential {a R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) (t : ℝ) : + IsBoundedPotential (familyPotential t a R) := by + refine ⟨t ^ 2 + |t| * ((∑' n, a n) * bumpIntegral⁻¹), ?_, ?_⟩ + · exact add_nonneg (sq_nonneg _) (mul_nonneg (abs_nonneg _) + (mul_nonneg (tsum_nonneg ha) (inv_nonneg.mpr bumpIntegral_pos.le))) + · intro r + apply le_trans (abs_sub _ _) + rw [abs_of_nonneg (coreReal_nonneg t r), abs_mul] + exact add_le_add (coreReal_le t r) + (mul_le_mul_of_nonneg_left (attractionProfile_bound ha hR hs r) (abs_nonneg t)) + +theorem familyPotential_nonpos_outer {a R : ℕ → ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) {t : ℝ} (ht : 1 ≤ t) + {r : ℝ≥0} (hr : 2 ≤ (r : ℝ)) : familyPotential t a R r ≤ 0 := by + have ht0 : 0 < t := lt_of_lt_of_le zero_lt_one ht + have hinv : 1 / t ≤ 1 := by simpa using inv_le_one_of_one_le₀ ht + have hz := coreReal_zero_outer ht0 (show 1 + 1 / t ≤ (r : ℝ) by linarith) + dsimp [familyPotential] + rw [hz, zero_sub] + exact neg_nonpos.mpr (mul_nonneg ht0.le (attractionProfile_nonneg ha hR r)) + +theorem scaledBumpProfile_decay {R r κ : ℝ} (hR : 1 ≤ R) (hr : 1 ≤ r) + (hκ : 0 ≤ κ) : + scaledBumpProfile R r ≤ + bumpIntegral⁻¹ * R ^ κ * r ^ (-(3 + κ)) := by + have hR0 : 0 < R := lt_of_lt_of_le zero_lt_one hR + have hr0 : 0 < r := lt_of_lt_of_le zero_lt_one hr + by_cases hcomp : R ≤ r + · rw [scaledBumpProfile_zero hR0 hcomp] + exact mul_nonneg (mul_nonneg (inv_nonneg.mpr bumpIntegral_pos.le) + (Real.rpow_nonneg hR0.le _)) (Real.rpow_nonneg hr0.le _) + · have hrr : r ≤ R := le_of_not_ge hcomp + have hm := Real.rpow_le_rpow_of_nonpos hr0 hrr (show -(3 + κ) ≤ 0 by linarith) + have hcancel : R ^ κ * R ^ (-(3 + κ)) = (R ^ 3)⁻¹ := by + rw [← Real.rpow_add hR0] + have he : κ + -(3 + κ) = -(3 : ℝ) := by ring + rw [he, Real.rpow_neg hR0.le] + norm_cast + calc + _ ≤ (R ^ 3)⁻¹ * bumpIntegral⁻¹ := by + apply mul_le_mul_of_nonneg_left + ((le_abs_self _).trans (bumpProfile_bound _)) + (inv_nonneg.mpr (pow_nonneg hR0.le _)) + _ = bumpIntegral⁻¹ * (R ^ κ * R ^ (-(3 + κ))) := by rw [hcancel]; ring + _ ≤ _ := by + simpa only [mul_assoc] using mul_le_mul_of_nonneg_left + (mul_le_mul_of_nonneg_left hm (Real.rpow_nonneg hR0.le κ)) + (inv_nonneg.mpr bumpIntegral_pos.le) + +theorem attractionProfile_decay {a R : ℕ → ℝ} {κ : ℝ} + (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) (hs : Summable a) + (hκ : 0 ≤ κ) (hweighted : Summable (fun n => a n * R n ^ κ)) + {r : ℝ} (hr : 1 ≤ r) : + attractionProfile a R r ≤ + bumpIntegral⁻¹ * (∑' n, a n * R n ^ κ) * r ^ (-(3 + κ)) := by + have hh := Summable.tsum_le_tsum + (fun n => mul_le_mul_of_nonneg_left (scaledBumpProfile_decay (hR n) hr hκ) (ha n)) + (summable_attractionProfile ha hR hs r) + (show Summable (fun n => a n * (bumpIntegral⁻¹ * R n ^ κ * r ^ (-(3 + κ)))) from by + apply ((hweighted.mul_left bumpIntegral⁻¹).mul_right (r ^ (-(3 + κ)))).congr + intro n + ring) + have heq : (∑' n, a n * (bumpIntegral⁻¹ * R n ^ κ * r ^ (-(3 + κ)))) = + bumpIntegral⁻¹ * (∑' n, a n * R n ^ κ) * r ^ (-(3 + κ)) := by + simp_rw [show ∀ n, a n * (bumpIntegral⁻¹ * R n ^ κ * r ^ (-(3 + κ))) = + (bumpIntegral⁻¹ * (a n * R n ^ κ)) * r ^ (-(3 + κ)) by intro n; ring] + rw [tsum_mul_right, tsum_mul_left] + exact hh.trans_eq heq + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ShellGeometry.lean b/lean/OAI/Probability/RadialTransition/ShellGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..6c6068ba33089bf9367c1a77d9cdc89c8880319a --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ShellGeometry.lean @@ -0,0 +1,166 @@ +import OAI.Probability.RadialTransition.SupportGeometry + +namespace OAI + +universe uE uIndex uV + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +section Shell + +theorem independent_of_simplex_gram + {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + {ι : Type uIndex} [Fintype ι] [DecidableEq ι] (v : ι → E) {ε : ℝ} + (hε : 0 ≤ ε) (hsmall : (Fintype.card ι : ℝ) * ε < 1 / 2) + (hgram : ∀ i j, + |inner ℝ (v i) (v j) - ((1 : ℝ) / 2 + if i = j then 1 / 2 else 0)| ≤ ε) : + LinearIndependent ℝ v := by + rw [Fintype.linearIndependent_iff] + intro c hc i + let S : ℝ := ∑ j, c j ^ 2 + have hS : 0 ≤ S := Finset.sum_nonneg fun j _ => sq_nonneg (c j) + have hCS : (∑ j, |c j|) ^ 2 ≤ (Fintype.card ι : ℝ) * S := by + simpa only [Finset.card_univ, sq_abs] using + (sq_sum_le_card_mul_sum_sq (s := Finset.univ) (f := fun j => |c j|)) + have hterm (j k : ι) : + c j * c k * ((1 : ℝ) / 2 + if j = k then 1 / 2 else 0) - + ε * |c j| * |c k| ≤ c j * c k * inner ℝ (v j) (v k) := by + have hh : |c j * c k * (inner ℝ (v j) (v k) - + ((1 : ℝ) / 2 + if j = k then 1 / 2 else 0))| ≤ ε * |c j| * |c k| := by + rw [abs_mul, abs_mul] + nlinarith [mul_le_mul_of_nonneg_left (hgram j k) + (mul_nonneg (abs_nonneg (c j)) (abs_nonneg (c k)))] + have hh' := (abs_le.mp hh).1 + nlinarith [hh'] + have hsum := Finset.sum_le_sum (s := Finset.univ) fun j _ => + Finset.sum_le_sum (s := Finset.univ) fun k _ => hterm j k + have hlin : (∑ j, ∑ k, c j * c k * inner ℝ (v j) (v k)) = 0 := by + have hh : inner ℝ (∑ j, c j • v j) (∑ j, c j • v j) = 0 := by rw [hc]; simp + simpa only [sum_inner, inner_sum, real_inner_smul_left, + real_inner_smul_right, mul_assoc, mul_left_comm, mul_comm, real_inner_comm] using hh + have href : (∑ j, ∑ k, + c j * c k * ((1 : ℝ) / 2 + if j = k then 1 / 2 else 0)) = + (1 / 2 : ℝ) * (∑ j, c j) ^ 2 + (1 / 2 : ℝ) * S := by + simp only [mul_add, Finset.sum_add_distrib, mul_ite, mul_zero, + Finset.sum_ite_eq, Finset.mem_univ, ite_true] + simp only [S, sq, Finset.mul_sum, Finset.sum_mul] + congr 1 + · apply Finset.sum_congr rfl + intro j _ + apply Finset.sum_congr rfl + intro k _ + ring + · apply Finset.sum_congr rfl + intro j _ + ring + have herr : (∑ j, ∑ k, ε * |c j| * |c k|) = ε * (∑ j, |c j|) ^ 2 := by + simp only [sq, Finset.mul_sum, Finset.sum_mul] + congr 1 + ext j + congr 1 + ext k + ring + simp only [Finset.sum_sub_distrib] at hsum + rw [hlin, href, herr] at hsum + have hSzero : S = 0 := by + have he := mul_le_mul_of_nonneg_left hCS hε + nlinarith [sq_nonneg (∑ j, c j)] + have hci : c i ^ 2 = 0 := + (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => sq_nonneg (c j))).mp hSzero i + (Finset.mem_univ i) + nlinarith [hci] + +theorem no_five_unit_shell (x : Fin 5 → Position) + (hx : ∀ i j, i ≠ j → 1 ≤ dist (x i) (x j) ∧ + dist (x i) (x j) ≤ 1 + (1 : ℝ) / 1000) : False := by + let v : Fin 4 → Position := fun i => x i.succ - x 0 + have hsq (i j : Fin 5) (hij : i ≠ j) : + 1 ≤ ‖x i - x j‖ ^ 2 ∧ ‖x i - x j‖ ^ 2 ≤ (1001 / 1000 : ℝ) ^ 2 := by + have h := hx i j hij + rw [dist_eq_norm] at h + constructor <;> nlinarith [h.1, h.2] + have hnorm (i : Fin 4) : + 1 ≤ ‖v i‖ ^ 2 ∧ ‖v i‖ ^ 2 ≤ (1001 / 1000 : ℝ) ^ 2 := + hsq i.succ 0 (Fin.succ_ne_zero i) + have hgram (i j : Fin 4) : + |inner ℝ (v i) (v j) - ((1 : ℝ) / 2 + if i = j then 1 / 2 else 0)| ≤ + (2001 / 1000000 : ℝ) := by + by_cases hij : i = j + · subst j + rw [ite_eq_left rfl, real_inner_self_eq_norm_sq] + have h := hnorm i + rw [abs_le] + constructor <;> nlinarith [h.1, h.2] + · rw [ite_eq_right hij, add_zero, abs_le] + have hi := hnorm i + have hj := hnorm j + have hd := hsq i.succ j.succ (by simpa using hij) + have heq : v i - v j = x i.succ - x j.succ := by simp [v] + have hp := norm_sub_sq_real (v i) (v j) + rw [heq] at hp + constructor <;> nlinarith [hi.1, hi.2, hj.1, hj.2, hd.1, hd.2, hp] + have hind := independent_of_simplex_gram v (by norm_num : (0 : ℝ) ≤ 2001 / 1000000) + (by norm_num : (Fintype.card (Fin 4) : ℝ) * (2001 / 1000000) < 1 / 2) hgram + have hdim := hind.fintype_card_le_finrank + norm_num [Position, finrank_euclideanSpace] at hdim + +theorem no_five_shell (x : Fin 5 → Position) {l : ℝ} (hl : 0 < l) + (hx : ∀ i j, i ≠ j → l ≤ dist (x i) (x j) ∧ + dist (x i) (x j) ≤ (1 + (1 : ℝ) / 1000) * l) : False := by + apply no_five_unit_shell (fun i => l⁻¹ • x i) + intro i j hij + have h := hx i j hij + rw [dist_smul₀, Real.norm_eq_abs, abs_of_pos (inv_pos.mpr hl)] + constructor + · have hh := mul_le_mul_of_nonneg_left h.1 (inv_nonneg.mpr hl.le) + simpa [ne_of_gt hl] using hh + · have hh := mul_le_mul_of_nonneg_left h.2 (inv_nonneg.mpr hl.le) + calc + l⁻¹ * dist (x i) (x j) ≤ l⁻¹ * ((1 + (1 : ℝ) / 1000) * l) := hh + _ = 1 + (1 : ℝ) / 1000 := by field_simp + +theorem shell_edge_bound {V : Type uV} [Fintype V] (G : SimpleGraph V) + [DecidableRel G.Adj] (hG : G.CliqueFree 5) : + 8 * G.edgeFinset.card ≤ 3 * (Fintype.card V) ^ 2 := by + obtain ⟨H, hdec, hmax⟩ := SimpleGraph.exists_isTuranMaximal (V := V) (r := 4) (by norm_num) + let _ : DecidableRel H.Adj := hdec + have hle := hmax.2 hG + obtain ⟨e⟩ := (SimpleGraph.isTuranMaximal_iff_nonempty_iso_turanGraph + (G := H) (by norm_num : 0 < 4)).mp hmax + have heq := e.card_edgeFinset_eq + have hb := SimpleGraph.mul_turanNumber_le + (n := Fintype.card V) (r := 4) + unfold SimpleGraph.turanNumber at hb + rw [← heq] at hb + norm_num at hb + omega + +def shellGraph {V : Type uV} (x : V → Position) (l : ℝ) : SimpleGraph V where + Adj i j := i ≠ j ∧ l ≤ dist (x i) (x j) ∧ + dist (x i) (x j) ≤ (1 + (1 : ℝ) / 1000) * l + symm := ⟨by intro i j h; exact ⟨h.1.symm, by simpa only [dist_comm] using h.2⟩⟩ + loopless := ⟨by intro i h; exact h.1 rfl⟩ + +theorem shellGraph_cliqueFree {V : Type uV} (x : V → Position) {l : ℝ} (hl : 0 < l) : + (shellGraph x l).CliqueFree 5 := by + classical + intro s hs + let e : Fin 5 ≃ s := (Finset.equivFinOfCardEq hs.card_eq).symm + apply no_five_shell (fun i => x (e i)) hl + intro i j hij + have hne : (e i : V) ≠ (e j : V) := fun h => hij (e.injective (Subtype.ext h)) + have hh := hs.isClique (e i).property (e j).property hne + exact hh.2 + +end Shell + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/SpatialProducts.lean b/lean/OAI/Probability/RadialTransition/SpatialProducts.lean new file mode 100644 index 0000000000000000000000000000000000000000..a5cb019efadcfaca80e107258d6b5f0c4743b3e1 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/SpatialProducts.lean @@ -0,0 +1,356 @@ +import OAI.Probability.RadialTransition.CanonicalCosts + +namespace OAI + +universe uIndex uOtherIndex uX + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +def orderedEnergy (φ : Potential) {ι : Type uIndex} [Fintype ι] (x : ι → Position) : ℝ := by + classical + exact (∑ i, ∑ j, if i ≠ j then φ (nndist (x i) (x j)) else 0) / 2 + +theorem orderedEnergy_fin (φ : Potential) {N : ℕ} (x : Fin N → Position) : + orderedEnergy φ x = energy φ x := by + have h := twice_pair_sum (fun i j => φ (nndist (x i) (x j))) + (fun i j => by rw [nndist_comm]) + have hh : (∑ i : Fin N, ∑ j : Fin N, + if i ≠ j then φ (nndist (x i) (x j)) else 0) = 2 * energy φ x := h.symm + have he : orderedEnergy φ x = (∑ i : Fin N, ∑ j : Fin N, + if i ≠ j then φ (nndist (x i) (x j)) else 0) / 2 := by + unfold orderedEnergy + congr 1 + apply Finset.sum_congr rfl + intro i _ + apply Finset.sum_congr rfl + intro j _ + by_cases hij : i = j <;> simp [hij] + rw [he, hh] + ring + +theorem orderedEnergy_equiv {ι : Type uIndex} {κ : Type uOtherIndex} [Fintype ι] [Fintype κ] + (e : ι ≃ κ) (φ : Potential) (x : κ → Position) : + orderedEnergy φ (x ∘ e) = orderedEnergy φ x := by + classical + unfold orderedEnergy + congr 1 + have hi (i : ι) : (∑ j : ι, if i ≠ j then φ (nndist (x (e i)) (x (e j))) else 0) = + ∑ j : κ, if e i ≠ j then φ (nndist (x (e i)) (x j)) else 0 := by + convert e.sum_comp (fun j => if e i ≠ j then φ (nndist (x (e i)) (x j)) else 0) using 1 + simp only [ne_eq, e.injective.eq_iff] + simpa only [Function.comp_apply, hi] using + e.sum_comp (fun i => ∑ j, if i ≠ j then φ (nndist (x i) (x j)) else 0) + +theorem continuous_orderedEnergy {ι : Type uIndex} [Fintype ι] {φ : Potential} + (hφ : Continuous φ) : Continuous (fun x : ι → Position => orderedEnergy φ x) := by + classical + unfold orderedEnergy + apply Continuous.div_const + apply continuous_finsetSum + intro i _ + apply continuous_finsetSum + intro j _ + split_ifs + · exact hφ.comp ((continuous_apply i).nndist (continuous_apply j)) + · exact continuous_const + +theorem orderedEnergy_abs_bound {ι : Type uIndex} [Fintype ι] {φ : Potential} {M : ℝ} + (hM : 0 ≤ M) (hφM : ∀ r, |φ r| ≤ M) (x : ι → Position) : + |orderedEnergy φ x| ≤ (Fintype.card ι : ℝ)^2 * M := by + classical + have hh : |∑ i : ι, ∑ j : ι, if i ≠ j then φ (nndist (x i) (x j)) else 0| ≤ + ∑ i : ι, ∑ j : ι, M := by + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro i _ + apply (Finset.abs_sum_le_sum_abs _ _).trans + apply Finset.sum_le_sum + intro j _ + split_ifs + · exact hφM _ + · simpa using hM + simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul] at hh + unfold orderedEnergy + rw [abs_div, abs_of_pos (by norm_num : (0 : ℝ) < 2)] + nlinarith [mul_nonneg (sq_nonneg (Fintype.card ι : ℝ)) hM] + +theorem integrable_orderedBoltzmann {ι : Type uIndex} [Fintype ι] {φ : Potential} + (hφ : Continuous φ) (hb : IsBoundedPotential φ) (β : ℝ) + (μ : Measure (ι → Position)) [IsFiniteMeasure μ] : + Integrable (fun x : ι → Position => Real.exp (-β * orderedEnergy φ x)) μ := by + obtain ⟨M, hM, hφM⟩ := hb + apply Integrable.of_bound ((Real.continuous_exp.comp + (continuous_const.mul (continuous_orderedEnergy hφ))).aestronglyMeasurable) + (Real.exp (|β| * ((Fintype.card ι : ℝ)^2 * M))) + filter_upwards [] with x + change |Real.exp _| ≤ _ + rw [abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + calc + -β * orderedEnergy φ x ≤ |-β * orderedEnergy φ x| := le_abs_self _ + _ = |β| * |orderedEnergy φ x| := by rw [abs_mul, abs_neg] + _ ≤ _ := mul_le_mul_of_nonneg_left (orderedEnergy_abs_bound hM hφM x) (abs_nonneg β) + +def rawPartition (φ : Potential) (A : Set Position) (ι : Type uIndex) [Fintype ι] (β : ℝ) : ℝ := + ∫ x : ι → Position, Real.exp (-β * orderedEnergy φ x) ∂Measure.pi (fun _ : ι => volume.restrict A) + +def partitionOn (φ : Potential) (A : Set Position) (N : ℕ) (β : ℝ) : ℝ := + (N.factorial : ℝ)⁻¹ * rawPartition φ A (Fin N) β + +theorem rawPartition_nonneg (φ : Potential) (A : Set Position) (ι : Type uIndex) [Fintype ι] (β : ℝ) : + 0 ≤ rawPartition φ A ι β := integral_nonneg (fun _ => (Real.exp_pos _).le) + +theorem rawPartition_equiv {ι : Type uIndex} {κ : Type uOtherIndex} [Fintype ι] [Fintype κ] + (e : ι ≃ κ) (φ : Potential) (A : Set Position) (β : ℝ) : + rawPartition φ A ι β = rawPartition φ A κ β := by + have hp := measurePreserving_piCongrLeft (fun _ : κ => volume.restrict A) e + have hh := hp.integral_comp' (fun x => Real.exp (-β * orderedEnergy φ x)) + have he (x : ι → Position) : orderedEnergy φ ((MeasurableEquiv.piCongrLeft (fun _ : κ => Position) e) x) = + orderedEnergy φ x := by + have ht := orderedEnergy_equiv e φ ((MeasurableEquiv.piCongrLeft (fun _ : κ => Position) e) x) + simpa only [Function.comp_def, MeasurableEquiv.coe_piCongrLeft, + Equiv.piCongrLeft_apply_apply] using ht.symm + simpa only [rawPartition, he] using hh + +theorem measure_pi_add {ι : Type uIndex} [Fintype ι] [DecidableEq ι] {X : ι → Type uX} + [∀ i, MeasurableSpace (X i)] (μ ν : (i : ι) → Measure (X i)) + [∀ i, SigmaFinite (μ i)] [∀ i, SigmaFinite (ν i)] : + Measure.pi (fun i => μ i + ν i) = + ∑ T : Finset ι, Measure.pi (fun i => if i ∈ T then μ i else ν i) := by + classical + have hσ (T : Finset ι) : ∀ i, SigmaFinite (if i ∈ T then μ i else ν i) := by + intro i + split_ifs <;> infer_instance + refine Measure.pi_eq (μ := fun i => μ i + ν i) (fun s hs => ?_) + simp only [Measure.finsetSum_apply, Measure.pi_pi, Measure.add_apply] + rw [Fintype.prod_add] + apply Finset.sum_congr rfl + intro T _ + have he (i : ι) : (if i ∈ T then μ i else ν i) (s i) = + if i ∈ T then μ i (s i) else ν i (s i) := by split_ifs <;> rfl + simp_rw [he] + rw [Finset.prod_ite] + congr 1 <;> congr 1 <;> ext i <;> simp + +theorem sum_split_four {ι : Type uIndex} [Fintype ι] (p : ι → Prop) [DecidablePred p] + (F : ι → ι → ℝ) : + (∑ i, ∑ j, F i j) = + (∑ i : Subtype p, ∑ j : Subtype p, F i j) + + (∑ i : Subtype p, ∑ j : {j // ¬p j}, F i j) + + (∑ i : {i // ¬p i}, ∑ j : Subtype p, F i j) + + (∑ i : {i // ¬p i}, ∑ j : {j // ¬p j}, F i j) := by + rw [← Fintype.sum_subtype_add_sum_subtype p (fun i => ∑ j, F i j)] + simp_rw [← Fintype.sum_subtype_add_sum_subtype p (fun j => F _ j)] + simp only [Finset.sum_add_distrib] + ring + +theorem orderedEnergy_split {ι : Type uIndex} [Fintype ι] (p : ι → Prop) [DecidablePred p] + (φ : Potential) (x : ι → Position) : + orderedEnergy φ x = orderedEnergy φ (fun i : Subtype p => x i) + + orderedEnergy φ (fun i : {i // ¬p i} => x i) + + ∑ i : Subtype p, ∑ j : {j // ¬p j}, φ (nndist (x i) (x j)) := by + classical + have hn (i : Subtype p) (j : {i // ¬p i}) : (i : ι) ≠ j := by + intro h + exact j.property (h ▸ i.property) + unfold orderedEnergy + rw [sum_split_four p] + dsimp only + have hpp (i j : Subtype p) : (if (i : ι) ≠ (j : ι) then φ (nndist (x i) (x j)) else 0) = + if i ≠ j then φ (nndist (x i) (x j)) else 0 := by + by_cases h : i = j + · simp [h] + · simp [h, Subtype.coe_ne_coe.mpr h] + have hmm (i j : {i // ¬p i}) : (if (i : ι) ≠ (j : ι) then φ (nndist (x i) (x j)) else 0) = + if i ≠ j then φ (nndist (x i) (x j)) else 0 := by + by_cases h : i = j + · simp [h] + · simp [h, Subtype.coe_ne_coe.mpr h] + have hpm (i : Subtype p) (j : {i // ¬p i}) : + (if (i : ι) ≠ (j : ι) then φ (nndist (x i) (x j)) else 0) = φ (nndist (x i) (x j)) := by + rw [ite_eq_left (hn i j)] + have hmp (i : {i // ¬p i}) (j : Subtype p) : + (if (i : ι) ≠ (j : ι) then φ (nndist (x i) (x j)) else 0) = φ (nndist (x i) (x j)) := by + rw [ite_eq_left (hn j i).symm] + simp_rw [hpp, hmm, hpm, hmp] + have hs : (∑ i : {i // ¬p i}, ∑ j : Subtype p, φ (nndist (x i) (x j))) = + ∑ i : Subtype p, ∑ j : {j // ¬p j}, φ (nndist (x i) (x j)) := by + rw [Finset.sum_comm] + simp_rw [nndist_comm] + rw [hs] + ring_nf + +theorem orderedEnergy_split_le {ι : Type uIndex} [Fintype ι] (p : ι → Prop) [DecidablePred p] + (φ : Potential) (x : ι → Position) + (hc : ∀ i j, p i → ¬p j → φ (nndist (x i) (x j)) ≤ 0) : + orderedEnergy φ x ≤ orderedEnergy φ (fun i : Subtype p => x i) + + orderedEnergy φ (fun i : {i // ¬p i} => x i) := by + rw [orderedEnergy_split p] + have hh : (∑ i : Subtype p, ∑ j : {j // ¬p j}, φ (nndist (x i) (x j))) ≤ 0 := by + apply Finset.sum_nonpos + intro i _ + apply Finset.sum_nonpos + intro j _ + exact hc i j i.property j.property + linarith + +theorem sector_product_integral {ι : Type uIndex} [Fintype ι] (p : ι → Prop) [DecidablePred p] + (F : (Subtype p → Position) → ℝ) (G : ({i // ¬p i} → Position) → ℝ) + (μ ν : Measure Position) [SigmaFinite μ] [SigmaFinite ν] : + (∫ x : ι → Position, F (fun i => x i) * G (fun i => x i) + ∂Measure.pi (fun i => if p i then μ else ν)) = + (∫ x : Subtype p → Position, F x ∂Measure.pi (fun _ => μ)) * + ∫ x : {i // ¬p i} → Position, G x ∂Measure.pi (fun _ => ν) := by + have : ∀ i : ι, SigmaFinite (if p i then μ else ν) := by + intro i + split_ifs <;> infer_instance + have hp := measurePreserving_piEquivPiSubtypeProd (fun i => if p i then μ else ν) p + have hh := hp.integral_comp' (fun z => F z.1 * G z.2) + simp only [MeasurableEquiv.piEquivPiSubtypeProd_apply, + Subtype.prop, ite_true, (fun i : {i // ¬p i} => i.property), ite_false] at hh + exact hh.trans (integral_prod_mul F G) + +theorem sector_raw_lower {ι : Type uIndex} [Fintype ι] (p : ι → Prop) [DecidablePred p] + {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) {β : ℝ} (hβ : 0 ≤ β) + {A B : Set Position} (hA : MeasurableSet A) (hB : MeasurableSet B) + (hAfin : volume A ≠ ⊤) (hBfin : volume B ≠ ⊤) + (hc : ∀ x ∈ A, ∀ y ∈ B, φ (nndist x y) ≤ 0) : + rawPartition φ A (Subtype p) β * rawPartition φ B {i // ¬p i} β ≤ + ∫ x : ι → Position, Real.exp (-β * orderedEnergy φ x) + ∂Measure.pi (fun i => if p i then volume.restrict A else volume.restrict B) := by + let μ := fun i : ι => if p i then volume.restrict A else volume.restrict B + let : IsFiniteMeasure (volume.restrict A) := isFiniteMeasure_restrict.mpr hAfin + let : IsFiniteMeasure (volume.restrict B) := isFiniteMeasure_restrict.mpr hBfin + have : ∀ i, IsFiniteMeasure (μ i) := by + intro i + dsimp [μ] + split_ifs <;> infer_instance + have hiA := integrable_orderedBoltzmann hφ hb β (Measure.pi (fun _ : Subtype p => volume.restrict A)) + have hiB := integrable_orderedBoltzmann hφ hb β (Measure.pi (fun _ : {i // ¬p i} => volume.restrict B)) + have hp := measurePreserving_piEquivPiSubtypeProd μ p + have hip : Integrable (fun z : (Subtype p → Position) × ({i // ¬p i} → Position) => + Real.exp (-β * orderedEnergy φ z.1) * Real.exp (-β * orderedEnergy φ z.2)) + ((Measure.pi (fun i : Subtype p => μ i)).prod (Measure.pi (fun i : {i // ¬p i} => μ i))) := by + simpa only [μ, Subtype.prop, ite_true, (fun i : {i // ¬p i} => i.property), ite_false] using hiA.mul_prod hiB + have his := hp.integrable_comp_of_integrable hip + have hiQ := integrable_orderedBoltzmann hφ hb β (Measure.pi μ) + have hae : ∀ᵐ x : ι → Position ∂Measure.pi μ, ∀ i, x i ∈ (if p i then A else B) := by + apply ae_all_iff.mpr + intro i + apply (Measure.tendsto_eval_ae_ae (μ := μ)).eventually + dsimp [μ] + split_ifs <;> exact ae_restrict_mem (by assumption) + have hh := integral_mono_ae his hiQ (hae.mono (fun x hx => ?_)) + · simp only [MeasurableEquiv.piEquivPiSubtypeProd_apply, Function.comp_apply] at hh + change (∫ x : ι → Position, Real.exp (-β * orderedEnergy φ (fun i : Subtype p => x i)) * + Real.exp (-β * orderedEnergy φ (fun i : {i // ¬p i} => x i)) + ∂Measure.pi (fun i => if p i then volume.restrict A else volume.restrict B)) ≤ _ at hh + have hprod := sector_product_integral p + (fun x : Subtype p → Position => Real.exp (-β * orderedEnergy φ x)) + (fun x : {i // ¬p i} → Position => Real.exp (-β * orderedEnergy φ x)) + (volume.restrict A) (volume.restrict B) + exact hprod.symm.trans_le hh + · change Real.exp (-β * orderedEnergy φ (fun i : Subtype p => x i)) * + Real.exp (-β * orderedEnergy φ (fun i : {i // ¬p i} => x i)) ≤ _ + rw [← Real.exp_add] + apply Real.exp_le_exp.mpr + have he := orderedEnergy_split_le p φ x (fun i j hi hj => hc (x i) + (by simpa [hi] using hx i) (x j) (by simpa [hj] using hx j)) + nlinarith + +theorem rawPartition_union_sum {ι : Type uIndex} [Fintype ι] [DecidableEq ι] + {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) (β : ℝ) + {A B : Set Position} (hB : MeasurableSet B) (hab : Disjoint A B) + (hAfin : volume A ≠ ⊤) (hBfin : volume B ≠ ⊤) : + rawPartition φ (A ∪ B) ι β = + ∑ T : Finset ι, ∫ x : ι → Position, Real.exp (-β * orderedEnergy φ x) + ∂Measure.pi (fun i => if i ∈ T then volume.restrict A else volume.restrict B) := by + let : IsFiniteMeasure (volume.restrict A) := isFiniteMeasure_restrict.mpr hAfin + let : IsFiniteMeasure (volume.restrict B) := isFiniteMeasure_restrict.mpr hBfin + unfold rawPartition + simp_rw [Measure.restrict_union hab hB] + rw [measure_pi_add] + apply integral_finsetSum_measure + intro T _ + have : ∀ i : ι, IsFiniteMeasure (if i ∈ T then volume.restrict A else volume.restrict B) := by + intro i + split_ifs <;> infer_instance + exact integrable_orderedBoltzmann hφ hb β _ + +theorem rawPartition_union_lower {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {β : ℝ} (hβ : 0 ≤ β) + {A B : Set Position} (hA : MeasurableSet A) (hB : MeasurableSet B) (hab : Disjoint A B) + (hAfin : volume A ≠ ⊤) (hBfin : volume B ≠ ⊤) + (hc : ∀ x ∈ A, ∀ y ∈ B, φ (nndist x y) ≤ 0) (m n : ℕ) : + ((m + n).choose m : ℝ) * rawPartition φ A (Fin m) β * rawPartition φ B (Fin n) β ≤ + rawPartition φ (A ∪ B) (Fin (m + n)) β := by + classical + let S : Finset (Finset (Fin (m + n))) := Finset.univ.powersetCard m + let I (T : Finset (Fin (m + n))) := ∫ x : Fin (m + n) → Position, Real.exp (-β * orderedEnergy φ x) + ∂Measure.pi (fun i => if i ∈ T then volume.restrict A else volume.restrict B) + have hterm (T : Finset (Fin (m + n))) (hT : T ∈ S) : + rawPartition φ A (Fin m) β * rawPartition φ B (Fin n) β ≤ I T := by + have hcard : T.card = m := (Finset.mem_powersetCard.mp hT).2 + have hcardA : Fintype.card {i : Fin (m + n) // i ∈ T} = m := by + simpa only [Fintype.card_coe] using hcard + have hcardB : Fintype.card {i : Fin (m + n) // i ∉ T} = n := by + rw [Fintype.card_subtype_compl, hcardA, Fintype.card_fin] + omega + have hh := sector_raw_lower (fun i => i ∈ T) hφ hb hβ hA hB hAfin hBfin hc + have heA := rawPartition_equiv (Fintype.equivFinOfCardEq hcardA) φ A β + have heB := rawPartition_equiv (Fintype.equivFinOfCardEq hcardB) φ B β + convert hh using 1 + congr 1 + · convert heA.symm using 1 + congr! + · exact heB.symm + have hs := Finset.sum_le_sum hterm + have hnn (T : Finset (Fin (m + n))) : 0 ≤ I T := integral_nonneg (fun _ => (Real.exp_pos _).le) + have hsubset : S ⊆ Finset.univ := Finset.subset_univ _ + have hh := hs.trans (Finset.sum_le_sum_of_subset_of_nonneg hsubset (fun T _ _ => hnn T)) + have hcardS : S.card = (m + n).choose m := by + simp only [S, Finset.card_powersetCard, Finset.card_univ, Fintype.card_fin] + rw [Finset.sum_const, hcardS, nsmul_eq_mul] at hh + rw [rawPartition_union_sum hφ hb β hB hab hAfin hBfin] + simpa only [mul_assoc, I] using hh + +theorem partitionOn_union_lower {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {β : ℝ} (hβ : 0 ≤ β) + {A B : Set Position} (hA : MeasurableSet A) (hB : MeasurableSet B) (hab : Disjoint A B) + (hAfin : volume A ≠ ⊤) (hBfin : volume B ≠ ⊤) + (hc : ∀ x ∈ A, ∀ y ∈ B, φ (nndist x y) ≤ 0) (m n : ℕ) : + partitionOn φ A m β * partitionOn φ B n β ≤ partitionOn φ (A ∪ B) (m + n) β := by + have hh := rawPartition_union_lower hφ hb hβ hA hB hab hAfin hBfin hc m n + have hm : (m.factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero m + have hn : (n.factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero n + have hmn : ((m + n).factorial : ℝ) ≠ 0 := by exact_mod_cast Nat.factorial_ne_zero (m + n) + have hfac : ((m + n).choose m : ℝ) * m.factorial * n.factorial = (m + n).factorial := by + exact_mod_cast (by simpa using Nat.choose_mul_factorial_mul_factorial (Nat.le_add_right m n)) + have hcancel : ((m + n).factorial : ℝ)⁻¹ * ((m + n).choose m : ℝ) = + (m.factorial : ℝ)⁻¹ * (n.factorial : ℝ)⁻¹ := by + field_simp + nlinarith [hfac] + have hh' := mul_le_mul_of_nonneg_left hh + (inv_nonneg.mpr (by positivity : (0 : ℝ) ≤ (m + n).factorial)) + unfold partitionOn + have he : (m.factorial : ℝ)⁻¹ * rawPartition φ A (Fin m) β * + ((n.factorial : ℝ)⁻¹ * rawPartition φ B (Fin n) β) = + ((m + n).factorial : ℝ)⁻¹ * + (((m + n).choose m : ℝ) * rawPartition φ A (Fin m) β * rawPartition φ B (Fin n) β) := by + calc + _ = ((m.factorial : ℝ)⁻¹ * (n.factorial : ℝ)⁻¹) * + (rawPartition φ A (Fin m) β * rawPartition φ B (Fin n) β) := by ring + _ = _ := by rw [← hcancel]; ring + rw [he] + exact hh' + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/SpatialReplication.lean b/lean/OAI/Probability/RadialTransition/SpatialReplication.lean new file mode 100644 index 0000000000000000000000000000000000000000..45d278a2d9f521890e0740ce68aafd0894e2c217 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/SpatialReplication.lean @@ -0,0 +1,149 @@ +import OAI.Probability.RadialTransition.GrandPartition + +namespace OAI + +universe uIndex + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +theorem volume_translateSet (A : Set Position) (a : Position) (hA : MeasurableSet A) : + volume (translateSet a A) = volume A := by + exact (measurePreserving_sub_right volume a).measure_preimage hA.nullMeasurableSet + +def boxOrigin {n : ℕ} (s : ℝ) (j : Fin 3 → Fin n) : Position := + WithLp.toLp 2 (fun k => (j k : ℝ) * (s + 2)) + +def boxRegion {n : ℕ} (s : ℝ) (j : Fin 3 → Fin n) : Set Position := + translateSet (boxOrigin s j) (cube s) + +theorem measurableSet_boxRegion {n : ℕ} (s : ℝ) (j : Fin 3 → Fin n) : + MeasurableSet (boxRegion s j) := measurableSet_translate (measurableSet_cube s) + +theorem volume_boxRegion {n : ℕ} (s : ℝ) (j : Fin 3 → Fin n) : + volume (boxRegion s j) = ENNReal.ofReal s ^ 3 := by + rw [boxRegion, volume_translateSet _ _ (measurableSet_cube s), volume_cube] + +theorem boxRegion_subset_cube {n : ℕ} {s L : ℝ} (hs : 0 ≤ s) + (hn : (n : ℝ) * (s + 2) ≤ L) (j : Fin 3 → Fin n) : boxRegion s j ⊆ cube L := by + intro x hx k + have hxx : ∀ k, 0 ≤ x k - (j k : ℝ) * (s + 2) ∧ + x k - (j k : ℝ) * (s + 2) ≤ s := hx + have hj : (j k : ℝ) + 1 ≤ n := by exact_mod_cast (j k).isLt + have hj0 : 0 ≤ (j k : ℝ) := by positivity + have hp := mul_le_mul_of_nonneg_right hj (show 0 ≤ s + 2 by linarith) + have hp0 : 0 ≤ (j k : ℝ) * (s + 2) := mul_nonneg hj0 (by linarith) + exact ⟨by linarith [(hxx k).1], by linarith [(hxx k).2]⟩ + +theorem boxRegion_dist {n : ℕ} {s : ℝ} (hs : 0 ≤ s) {j k : Fin 3 → Fin n} + (hjk : j ≠ k) {x y : Position} (hx : x ∈ boxRegion s j) (hy : y ∈ boxRegion s k) : + 2 ≤ dist x y := by + have hc {j k : Fin 3 → Fin n} {x y : Position} (q : Fin 3) (hq : j q < k q) + (hx : x ∈ boxRegion s j) (hy : y ∈ boxRegion s k) : 2 ≤ dist x y := by + have hq' : (j q : ℝ) + 1 ≤ (k q : ℝ) := by exact_mod_cast hq + have hp := mul_le_mul_of_nonneg_right hq' (show 0 ≤ s + 2 by linarith) + have hx' : x q - (j q : ℝ) * (s + 2) ≤ s := (hx q).2 + have hy' : 0 ≤ y q - (k q : ℝ) * (s + 2) := (hy q).1 + have hh : 2 ≤ y q - x q := by linarith + calc + 2 ≤ y q - x q := hh + _ ≤ |y q - x q| := le_abs_self _ + _ ≤ ‖y - x‖ := by simpa only [PiLp.sub_apply, Real.norm_eq_abs] using PiLp.norm_apply_le (y - x) q + _ = dist x y := by rw [← dist_eq_norm, dist_comm] + obtain ⟨q, hq⟩ := Function.ne_iff.mp hjk + rcases lt_or_gt_of_ne hq with h | h + · exact hc q h hx hy + · simpa only [dist_comm] using hc q h hy hx + +theorem boxRegion_disjoint {n : ℕ} {s : ℝ} (hs : 0 ≤ s) {j k : Fin 3 → Fin n} + (hjk : j ≠ k) : Disjoint (boxRegion s j) (boxRegion s k) := by + rw [Set.disjoint_left] + intro x hx hy + have hh := boxRegion_dist hs hjk hx hy + norm_num at hh + +theorem grandOn_biUnion_lower {ι : Type uIndex} [DecidableEq ι] + {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B β : ℝ} (hstable : StableWith φ B) (hβ : 0 ≤ β) + (S : Finset ι) (A : ι → Set Position) (z : ℝ) + (hA : ∀ i ∈ S, MeasurableSet (A i)) (hAfin : ∀ i ∈ S, volume (A i) ≠ ⊤) + (hdisj : ∀ i ∈ S, ∀ j ∈ S, i ≠ j → Disjoint (A i) (A j)) + (hc : ∀ i ∈ S, ∀ j ∈ S, i ≠ j → ∀ x ∈ A i, ∀ y ∈ A j, φ (nndist x y) ≤ 0) : + (∏ i ∈ S, grandOn φ (A i) β z) ≤ grandOn φ (⋃ i ∈ S, A i) β z := by + induction S using Finset.induction_on with + | empty => + simpa using (grandOn_bounds hφ hb hstable hβ (by simp : volume (∅ : Set Position) ≠ ⊤) z).1 + | @insert i S hi ih => + have hAs : ∀ j ∈ S, MeasurableSet (A j) := fun j hj => hA j (Finset.mem_insert_of_mem hj) + have hfins : ∀ j ∈ S, volume (A j) ≠ ⊤ := fun j hj => hAfin j (Finset.mem_insert_of_mem hj) + have hU : MeasurableSet (⋃ j ∈ S, A j) := Finset.measurableSet_biUnion S hAs + have hUfin : volume (⋃ j ∈ S, A j) ≠ ⊤ := + ne_top_of_le_ne_top (ENNReal.sum_ne_top.mpr hfins) (measure_biUnion_finset_le S A) + have hdU : Disjoint (A i) (⋃ j ∈ S, A j) := by + simp only [Set.disjoint_iUnion_right] + intro j hj + exact hdisj i (Finset.mem_insert_self _ _) j (Finset.mem_insert_of_mem hj) + (by rintro rfl; exact hi hj) + have hcU : ∀ x ∈ A i, ∀ y ∈ ⋃ j ∈ S, A j, φ (nndist x y) ≤ 0 := by + intro x hx y hy + obtain ⟨j, hj, hy⟩ := Set.mem_iUnion₂.mp hy + exact hc i (Finset.mem_insert_self _ _) j (Finset.mem_insert_of_mem hj) + (by rintro rfl; exact hi hj) x hx y hy + have hi' := ih hAs hfins + (fun j hj k hk hne => hdisj j (Finset.mem_insert_of_mem hj) k (Finset.mem_insert_of_mem hk) hne) + (fun j hj k hk hne => hc j (Finset.mem_insert_of_mem hj) k (Finset.mem_insert_of_mem hk) hne) + rw [Finset.prod_insert hi] + have hnn := (grandOn_bounds hφ hb hstable hβ (hAfin i (Finset.mem_insert_self _ _)) z).1 + have hprod := mul_le_mul_of_nonneg_left hi' (show 0 ≤ grandOn φ (A i) β z by linarith) + refine hprod.trans ?_ + have hu : (⋃ j ∈ insert i S, A j) = A i ∪ ⋃ j ∈ S, A j := by ext x; simp + rw [hu] + exact grandOn_union_lower hφ hb hstable hβ + (hA i (Finset.mem_insert_self _ _)) hU hdU (hAfin i (Finset.mem_insert_self _ _)) hUfin hcU z + +theorem partition_replication {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {β s L : ℝ} (hβ : 0 ≤ β) (hs : 0 ≤ s) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) (n : ℕ) + (hn : (n : ℝ) * (s + 2) ≤ L) (m : (Fin 3 → Fin n) → ℕ) : + (∏ j, partition φ s (m j) β) ≤ partition φ L (∑ j, m j) β := by + classical + have hh := partitionOn_biUnion_lower Finset.univ (boxRegion s) hφ hb hβ + (fun j _ => measurableSet_boxRegion s j) + (fun j _ => by rw [volume_boxRegion]; finiteness) + (fun _ _ _ _ hne => boxRegion_disjoint hs hne) + (fun _ _ _ _ hne _ hx _ hy => hc _ (boxRegion_dist hs hne hx hy)) m + have hsub : (⋃ j ∈ (Finset.univ : Finset (Fin 3 → Fin n)), boxRegion s j) ⊆ cube L := by + intro x hx + obtain ⟨j, _, hx⟩ := Set.mem_iUnion₂.mp hx + exact boxRegion_subset_cube hs hn j hx + have hh' := hh.trans (partitionOn_mono hφ hb β _ hsub (by rw [volume_cube]; finiteness)) + simpa only [boxRegion, partitionOn_translate, partitionOn_cube] using hh' + +theorem grandPartition_replication {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B β s L : ℝ} (hstable : StableWith φ B) (hβ : 0 ≤ β) (hs : 0 ≤ s) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) (n : ℕ) + (hn : (n : ℝ) * (s + 2) ≤ L) (t h : ℝ) : + grandPartition φ t s β h ^ (n ^ 3) ≤ grandPartition φ t L β h := by + classical + have hh := grandOn_biUnion_lower hφ hb hstable hβ Finset.univ (boxRegion s) (t * h) + (fun j _ => measurableSet_boxRegion s j) + (fun j _ => by rw [volume_boxRegion]; finiteness) + (fun _ _ _ _ hne => boxRegion_disjoint hs hne) + (fun _ _ _ _ hne _ hx _ hy => hc _ (boxRegion_dist hs hne hx hy)) + have hsub : (⋃ j ∈ (Finset.univ : Finset (Fin 3 → Fin n)), boxRegion s j) ⊆ cube L := by + intro x hx + obtain ⟨j, _, hx⟩ := Set.mem_iUnion₂.mp hx + exact boxRegion_subset_cube hs hn j hx + have hh' := hh.trans (grandOn_mono hφ hb hstable hβ hsub (by rw [volume_cube]; finiteness) (t * h)) + simpa only [boxRegion, grandOn_translate, grandOn_cube, Finset.prod_const, + Finset.card_univ, Fintype.card_fun, Fintype.card_fin] using hh' + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/SqrtGrid.lean b/lean/OAI/Probability/RadialTransition/SqrtGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..a8a3c205f34990937955113b7d7128b3fcbc13bd --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/SqrtGrid.lean @@ -0,0 +1,58 @@ +import OAI.Probability.RadialTransition.KacVariational + +namespace OAI + +noncomputable section +open Set +namespace RadialTransition + +lemma sqrt_grid_exists {R₀ R W : ℝ} (hR₀ : 2 ≤ R₀) (hW : 0 ≤ W) + (hrange : 16*(W+1)^2*R₀ ≤ R) : + ∃ q : ℕ, 0 < q ∧ 1 ≤ (q:ℝ)/4 ∧ (q:ℝ)/4 ≤ R ∧ + R₀/((q:ℝ)/4) ≤ 2*Real.sqrt (R₀/R) ∧ + (q:ℝ)/R ≤ 4*Real.sqrt (R₀/R) ∧ W*(q:ℝ)/R ≤ 1 := by + have hW1 : 0 < W+1 := by linarith + have hfactor : 1 ≤ 16*(W+1)^2 := by nlinarith [sq_nonneg W] + have hRge : R₀ ≤ R := (le_mul_of_one_le_left (by linarith : 0 ≤ R₀) hfactor).trans hrange + have hR : 0 < R := by linarith + let z := Real.sqrt (R₀/R) + have hz : 0 ≤ z := Real.sqrt_nonneg _ + have hzsq : z^2 = R₀/R := Real.sq_sqrt (div_nonneg (by linarith) hR.le) + have hzR : z^2*R = R₀ := by rw [hzsq]; field_simp + have hz1 : z ≤ 1 := by + have hh : z^2 ≤ 1 := by rw [hzsq]; exact (div_le_one hR).mpr hRge + nlinarith + have hwz : 4*(W+1)*z ≤ 1 := by + have hh : 16*(W+1)^2*z^2 ≤ 1 := by + apply (mul_le_mul_iff_left₀ hR).mp + nlinarith [hrange] + nlinarith [mul_nonneg hW1.le hz, sq_nonneg (4*(W+1)*z)] + let x := Real.sqrt (R₀*R) + have hx : 0 ≤ x := Real.sqrt_nonneg _ + have hxsq : x^2 = R₀*R := Real.sq_sqrt (mul_nonneg (by linarith) hR.le) + have hx2 : 2 ≤ x := by nlinarith + have hxR : x ≤ R := by nlinarith [mul_le_mul_of_nonneg_right hRge hR.le] + have hxz : x = R*z := by nlinarith [sq_nonneg (x-R*z)] + let q := ⌊4*x⌋₊ + have hqle : (q:ℝ) ≤ 4*x := Nat.floor_le (by positivity) + have hqgt : 4*x < (q:ℝ)+1 := Nat.lt_floor_add_one (4*x) + have hq1 : 1 ≤ (q:ℝ)/4 := by linarith + have hq : 0 < q := by exact_mod_cast (show (0:ℝ) < q by linarith) + have hqx : x/2 ≤ (q:ℝ)/4 := by linarith + have hq0 : 0 < (q:ℝ)/4 := by linarith + refine ⟨q, hq, hq1, ?_, ?_, ?_, ?_⟩ + · linarith + · apply (div_le_iff₀ hq0).mpr + have hh := mul_le_mul_of_nonneg_left hqx (show 0 ≤ 2*z by positivity) + nlinarith + · apply (div_le_iff₀ hR).mpr + nlinarith + · apply (div_le_iff₀ hR).mpr + have hh := mul_le_mul_of_nonneg_left hqle hW + have hh' := mul_le_mul_of_nonneg_left hwz hR.le + nlinarith [mul_nonneg hR.le hz] + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/StarIntegral.lean b/lean/OAI/Probability/RadialTransition/StarIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..709099ffaa67f69e6772e0244a67a3aeb0669746 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/StarIntegral.lean @@ -0,0 +1,90 @@ +import OAI.Probability.RadialTransition.BadRemoval + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition +attribute [local instance] Classical.propDecidable + +lemma measurableSet_nearCube (r : ℝ) (x : Position) : MeasurableSet (nearCube r x) := by + simp only [nearCube, Set.ofPred_forall] + apply MeasurableSet.iInter + intro k + exact measurableSet_le (((PiLp.continuous_apply 2 (fun _ : Fin 3 => ℝ) k).sub continuous_const).abs.measurable) measurable_const + +lemma nearCube_translate (r : ℝ) (x : Position) : + nearCube r x = translateSet (x-WithLp.toLp 2 (fun _ : Fin 3 => r)) (cube (2*r)) := by + ext y + change (∀ k, |y k-x k| ≤ r) ↔ ∀ k, 0 ≤ y k-(x k-r) ∧ y k-(x k-r) ≤ 2*r + simp only [abs_le] + constructor <;> intro h k <;> obtain ⟨h1,h2⟩ := h k <;> constructor <;> linarith + +lemma volume_nearCube (r : ℝ) (x : Position) : + volume (nearCube r x) = ENNReal.ofReal (2*r)^3 := by + rw [nearCube_translate, volume_translateSet _ _ (measurableSet_cube _), volume_cube] + +lemma nearMask_self {r : ℝ} (hr : 0 ≤ r) (x : Position) : nearMask r x x = 1 := by + apply indicator_of_mem + intro k + simpa using hr + +lemma lintegral_nearMask_prod (n : ℕ) (r : ℝ) (x : Position) : + (∫⁻ y : Fin n → Position, ∏ j, nearMask r x (y j) ∂Measure.pi (fun _ => volume)) = + (ENNReal.ofReal (2*r)^3)^n := by + have he (y : Fin n → Position) : + (∏ j, nearMask r x (y j)) = (Set.pi univ (fun _ : Fin n => nearCube r x)).indicator (fun _ => 1) y := by + simp [nearMask, Set.indicator, Finset.prod_boole, Set.mem_pi] + simp_rw [he] + change (∫⁻ y, (Set.pi univ (fun _ : Fin n => nearCube r x)).indicator (1 : (Fin n → Position) → ℝ≥0∞) y ∂Measure.pi (fun _ => volume)) = _ + rw [lintegral_indicator_one, Measure.pi_pi, volume_nearCube] + · simp + · exact MeasurableSet.univ_pi (fun _ => measurableSet_nearCube r x) + +lemma lintegral_rootStar (A : Set Position) (hA : MeasurableSet A) {r : ℝ} (hr : 0 ≤ r) + (n : ℕ) (i : Fin (n+1)) : + (∫⁻ x : Fin (n+1) → Position, regionMask A (x i)*∏ j, nearMask r (x i) (x j) + ∂Measure.pi (fun _ => volume)) = volume A*(ENNReal.ofReal (2*r)^3)^n := by + have hprod : Measurable (fun p : Position × (Fin n → Position) => + regionMask A p.1 * ∏ j, nearMask r p.1 (p.2 j)) := by + apply ((measurable_regionMask hA).comp measurable_fst).mul + apply Finset.measurable_prod + intro j _ + exact (measurable_nearMask r).comp (measurable_fst.prodMk ((measurable_pi_apply j).comp measurable_snd)) + have hh := (measurePreserving_piFinSuccAbove (fun _ : Fin (n+1) => (volume : Measure Position)) i).lintegral_comp hprod + simp only [MeasurableEquiv.piFinSuccAbove_apply, Fin.insertNthEquiv_symm_apply, Fin.removeNth_apply] at hh + have he (x : Fin (n+1) → Position) : (∏ j, nearMask r (x i) (x j)) = ∏ j : Fin n, nearMask r (x i) (x (i.succAbove j)) := by + rw [i.prod_univ_succAbove, nearMask_self hr, one_mul] + simp_rw [he] + rw [hh, lintegral_prod _ hprod.aemeasurable] + have hfin (x : Position) : regionMask A x ≠ ⊤ := by + by_cases hx : x ∈ A <;> simp [regionMask, hx] + simp_rw [lintegral_const_mul' _ _ (hfin _)] + simp_rw [lintegral_nearMask_prod] + rw [lintegral_mul_const'] + · change (∫⁻ x, A.indicator (1 : Position → ℝ≥0∞) x) * _ = _ + rw [lintegral_indicator_one hA] + · exact (ENNReal.pow_ne_top (ENNReal.pow_ne_top ENNReal.ofReal_ne_top)) + +lemma lintegral_starWeight (A : Set Position) (hA : MeasurableSet A) {r : ℝ} (hr : 0 ≤ r) + (n : ℕ) : + (∫⁻ x : Fin (n+1) → Position, starWeight A r (configurationMultiset x) + ∂Measure.pi (fun _ => volume)) = (n+1 : ℕ)*(volume A*(ENNReal.ofReal (2*r)^3)^n) := by + simp only [starWeight, configurationMultiset_sum_map, configurationMultiset_prod_map] + rw [lintegral_finsetSum] + · simp_rw [lintegral_rootStar A hA hr] + simp + · intro i _ + apply ((measurable_regionMask hA).comp (measurable_pi_apply i)).mul + apply Finset.measurable_prod + intro j _ + have hm := (measurable_nearMask r).comp + ((show Measurable (fun x : Fin (n+1) → Position => x i) from measurable_pi_apply i).prodMk + (show Measurable (fun x : Fin (n+1) → Position => x j) from measurable_pi_apply j)) + simpa only [Function.comp_def, Function.uncurry_apply_pair] using hm + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/SupportControl.lean b/lean/OAI/Probability/RadialTransition/SupportControl.lean new file mode 100644 index 0000000000000000000000000000000000000000..5cef6ac9598adef00b11ed5ed087a61f9f7ddd9f --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/SupportControl.lean @@ -0,0 +1,142 @@ +import OAI.Probability.RadialTransition.CanonicalCorner + +namespace OAI + +universe uE uY uI + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +section MoreSupportGeometry +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +theorem supportsOn_of_local {F : E → ℝ} {D : Set E} {x v : E} {r : ℝ} + (hF : ConvexOn ℝ D F) (hx : x ∈ D) (hr : 0 < r) + (hlocal : SupportsOn F (D ∩ Metric.closedBall x r) x v) : SupportsOn F D x v := by + intro y hy + let a : ℝ := r / (r + ‖y - x‖ + 1) + have hd : 0 < r + ‖y - x‖ + 1 := by positivity + have ha : 0 < a := div_pos hr hd + have ha1 : a ≤ 1 := by + apply (div_le_iff₀ hd).mpr + linarith [norm_nonneg (y - x)] + have hae : a * (r + ‖y - x‖ + 1) = r := div_mul_cancel₀ _ hd.ne' + have hab : a * ‖y - x‖ ≤ r := by + nlinarith [mul_nonneg ha.le hr.le] + let z := (1 - a) • x + a • y + have hzD : z ∈ D := hF.1 hx hy (sub_nonneg.mpr ha1) ha.le (by ring) + have hzx : z - x = a • (y - x) := by dsimp [z]; module + have hzball : z ∈ Metric.closedBall x r := by + rw [Metric.mem_closedBall, dist_eq_norm, hzx, norm_smul, Real.norm_eq_abs, abs_of_pos ha] + exact hab + have hlo := hlocal z ⟨hzD, hzball⟩ + have hhi := hF.2 hx hy (sub_nonneg.mpr ha1) ha.le (show 1 - a + a = 1 by ring) + change F z ≤ (1 - a) * F x + a * F y at hhi + rw [hzx, real_inner_smul_right] at hlo + nlinarith [mul_le_mul_of_nonneg_left (show 0 ≤ (0 : ℝ) from le_rfl) ha.le] + +theorem nonempty_of_closedHull_nonempty {G : Set E} + (h : (closure (convexHull ℝ G)).Nonempty) : G.Nonempty := by + by_contra hG + have he : G = ∅ := Set.not_nonempty_iff_eq_empty.mp hG + simp [he] at h + +theorem common_group_of_density_band {Y : Type uY} {I : Type uI} + (S : Y → Set E) (A : Set Y) (c : I → E) (d : E → ℝ) + {u R b p : ℝ} (hA : A.Nonempty) + (hgen : ∀ y ∈ A, S y = closure (convexHull ℝ + {v | v ∈ S y ∧ ∃ i, v ∈ Metric.closedBall (c i) R})) + (hne : ∀ y ∈ A, (S y).Nonempty) + (hband : ∀ y ∈ A, ∀ v ∈ S y, |d v - u| ≤ b) + (hd : ∀ v w, |d v - d w| ≤ dist v w) + (hsep : ∀ i j, i ≠ j → p ≤ |d (c i) - d (c j)|) + (hgap : 2 * (b + R) < p) : + ∃ i, ∀ y ∈ A, S y ⊆ Metric.closedBall (c i) R := by + classical + have hcenter (y : Y) (hy : y ∈ A) (v : E) (hv : v ∈ S y) + (i : I) (hi : v ∈ Metric.closedBall (c i) R) : |d (c i) - u| ≤ b + R := by + have hdist : |d (c i) - d v| ≤ R := by + calc + _ ≤ dist (c i) v := hd _ _ + _ = dist v (c i) := dist_comm _ _ + _ ≤ R := hi + calc + |d (c i) - u| ≤ |d (c i) - d v| + |d v - u| := abs_sub_le _ _ _ + _ ≤ b + R := by linarith [hband y hy v hv] + obtain ⟨y₀, hy₀⟩ := hA + have hng : ({v | v ∈ S y₀ ∧ ∃ i, v ∈ Metric.closedBall (c i) R}).Nonempty := by + apply nonempty_of_closedHull_nonempty + rw [← hgen y₀ hy₀] + exact hne y₀ hy₀ + obtain ⟨v₀, hv₀, i₀, hi₀⟩ := hng + have hc₀ := hcenter y₀ hy₀ v₀ hv₀ i₀ hi₀ + refine ⟨i₀, ?_⟩ + intro y hy + rw [hgen y hy] + apply closure_minimal _ Metric.isClosed_closedBall + apply convexHull_min _ (convex_closedBall (c i₀) R) + rintro v ⟨hv, i, hi⟩ + have heq : i = i₀ := by + by_contra hne' + have hc := hcenter y hy v hv i hi + have habs : |d (c i) - d (c i₀)| ≤ 2 * (b + R) := by + calc + _ ≤ |d (c i) - u| + |u - d (c i₀)| := abs_sub_le _ _ _ + _ = |d (c i) - u| + |d (c i₀) - u| := by rw [abs_sub_comm u] + _ ≤ 2 * (b + R) := by linarith + linarith [hsep i i₀ hne'] + simpa [heq] using hi + +end MoreSupportGeometry + +theorem active_neighborhood_density_band {P Q : Pressure} + {a β h u βy hy e d η δ C r : ℝ} + (ha : 0 < a) (hβ : 0 < β) (hβy : 0 < βy) (hη : 0 < η) + (hu : ActiveShift Q a β h u) (hs : pressureSupport P βy hy e d) + (happrox : ∀ z ∈ ({0, η, -η} : Set ℝ), + |Q β (h + β * a * u + z) - P β (h + β * a * u + z)| ≤ δ) + (hlip : ∀ z ∈ ({0, η, -η} : Set ℝ), + |P βy (hy + z) - P β (h + β * a * u + z)| ≤ C * r) : + |d - u| ≤ η / (2 * β * a) + 2 * δ / η + 2 * C * r / η := by + have hzero : (0 : ℝ) ∈ ({0, η, -η} : Set ℝ) := by simp + have hplus : η ∈ ({0, η, -η} : Set ℝ) := by simp + have hminus : -η ∈ ({0, η, -η} : Set ℝ) := by simp + have happ0 := happrox 0 hzero + have hlip0 := hlip 0 hzero + simp only [add_zero] at happ0 hlip0 + have hsupport (z : ℝ) : z * d ≤ P βy (hy + z) - P βy hy := by + have hh := hs βy (hy + z) hβy + simp only [sub_self, mul_zero, add_zero, add_sub_cancel_left] at hh + nlinarith + have hup : η * (d - u) ≤ η ^ 2 / (2 * β * a) + 2 * δ + 2 * C * r := by + have hp := active_parabola ha hβ hu η + have hq := hsupport η + have ha := abs_le.mp (happrox η hplus) + have hl := abs_le.mp (hlip η hplus) + have ha0 := abs_le.mp happ0 + have hl0 := abs_le.mp hlip0 + linarith + have hlo : -(η * (d - u)) ≤ η ^ 2 / (2 * β * a) + 2 * δ + 2 * C * r := by + have hp := active_parabola ha hβ hu (-η) + have hq := hsupport (-η) + have ha := abs_le.mp (happrox (-η) hminus) + have hl := abs_le.mp (hlip (-η) hminus) + have ha0 := abs_le.mp happ0 + have hl0 := abs_le.mp hlip0 + simp only [neg_sq] at hp + linarith + have heq : η * (η / (2 * β * a) + 2 * δ / η + 2 * C * r / η) = + η ^ 2 / (2 * β * a) + 2 * δ + 2 * C * r := by + field_simp + apply abs_le.mpr + constructor <;> nlinarith + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/SupportGeometry.lean b/lean/OAI/Probability/RadialTransition/SupportGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..d4ab1101535f5309a803d61c974e60acd7328039 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/SupportGeometry.lean @@ -0,0 +1,148 @@ +import OAI.Probability.RadialTransition.IdealAttraction + +namespace OAI + +universe uE + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +section InnerSupport + +variable {E : Type uE} [NormedAddCommGroup E] [InnerProductSpace ℝ E] + +def SupportsOn (F : E → ℝ) (D : Set E) (x v : E) : Prop := + ∀ y ∈ D, F x + inner ℝ v (y - x) ≤ F y + +def supportSet (F : E → ℝ) (D : Set E) (x : E) : Set E := + {v | SupportsOn F D x v} + +theorem convex_supportSet (F : E → ℝ) (D : Set E) (x : E) : + Convex ℝ (supportSet F D x) := by + intro v hv w hw a b ha hb hab y hy + have hv' := hv y hy + have hw' := hw y hy + simp only [inner_add_left, real_inner_smul_left] + calc + F x + (a * inner ℝ v (y - x) + b * inner ℝ w (y - x)) = + a * (F x + inner ℝ v (y - x)) + b * (F x + inner ℝ w (y - x)) := by + calc + _ = (a + b) * F x + + (a * inner ℝ v (y - x) + b * inner ℝ w (y - x)) := by rw [hab, one_mul] + _ = _ := by ring + _ ≤ a * F y + b * F y := add_le_add + (mul_le_mul_of_nonneg_left hv' ha) (mul_le_mul_of_nonneg_left hw' hb) + _ = F y := by rw [← add_mul, hab, one_mul] + +theorem isClosed_supportSet (F : E → ℝ) (D : Set E) (x : E) : + IsClosed (supportSet F D x) := by + have heq : supportSet F D x = ⋂ y ∈ D, {v | F x + inner ℝ v (y - x) ≤ F y} := by + ext v + simp only [supportSet, SupportsOn, mem_ofPred_eq, mem_iInter] + rw [heq] + exact isClosed_biInter fun y _ => isClosed_le + (continuous_const.add (continuous_id.inner continuous_const)) continuous_const + +theorem norm_le_of_unit_inner_le (w : E) {R : ℝ} (hR : 0 ≤ R) + (h : ∀ z : E, ‖z‖ = 1 → inner ℝ w z ≤ R) : ‖w‖ ≤ R := by + by_cases hw : w = 0 + · simpa [hw] using hR + have hn : ‖w‖ ≠ 0 := norm_ne_zero_iff.mpr hw + have hz : ‖(‖w‖⁻¹ : ℝ) • w‖ = 1 := by + simp [norm_smul, hn] + have hi : inner ℝ w ((‖w‖⁻¹ : ℝ) • w) = ‖w‖ := by + rw [real_inner_smul_right, real_inner_self_eq_norm_sq] + field_simp + simpa only [hi] using h _ hz + +theorem support_transfer_bound (P Q : E → ℝ) (D : Set E) + (x c v : E) {r R δ : ℝ} (hr : 0 < r) (hR : 0 ≤ R) (hδ : 0 ≤ δ) + (hball : Metric.closedBall x r ⊆ D) + (happrox : ∀ y ∈ Metric.closedBall x r, |Q y - P y| ≤ δ) + (hnear : ∀ y ∈ Metric.closedBall x r, + ∃ w : E, SupportsOn P D y w ∧ ‖w - c‖ ≤ R) + (hv : SupportsOn Q D x v) : + ‖v - c‖ ≤ R + 2 * δ / r := by + apply norm_le_of_unit_inner_le _ (by positivity) + intro z hz + let y := x + r • z + have hy : y ∈ Metric.closedBall x r := by + rw [Metric.mem_closedBall, dist_eq_norm] + dsimp [y] + simp [norm_smul, Real.norm_eq_abs, abs_of_pos hr, hz] + have hx : x ∈ Metric.closedBall x r := Metric.mem_closedBall_self hr.le + obtain ⟨w, hw, hwc⟩ := hnear y hy + have hqy := hv y (hball hy) + have hpx := hw x (hball hx) + have hax := (abs_le.mp (happrox x hx)).1 + have hay := (abs_le.mp (happrox y hy)).2 + have hyx : y - x = r • z := by simp [y] + have hxy : x - y = -(r • z) := by simp [y] + rw [hyx, real_inner_smul_right] at hqy + rw [hxy, inner_neg_right, real_inner_smul_right] at hpx + have hi : inner ℝ (w - c) z ≤ R := by + calc + inner ℝ (w - c) z ≤ ‖w - c‖ * ‖z‖ := real_inner_le_norm _ _ + _ ≤ R := by simpa only [hz, mul_one] using hwc + rw [inner_sub_left] at hi ⊢ + have hg : r * (inner ℝ v z - inner ℝ c z) ≤ r * R + 2 * δ := by + nlinarith [mul_le_mul_of_nonneg_left hi hr.le] + have hd := div_mul_cancel₀ (2 * δ) (ne_of_gt hr) + nlinarith [hg, hd] + +theorem supportSet_nonempty [FiniteDimensional ℝ E] {F : E → ℝ} {D : Set E} + (hD : IsOpen D) (hF : ConvexOn ℝ D F) {x : E} (hx : x ∈ D) : + (supportSet F D x).Nonempty := by + let S : Set (E × ℝ) := {z | z.1 ∈ D ∧ F z.1 < z.2} + have hSconv : Convex ℝ S := hF.convex_strict_epigraph + have hFcont : ContinuousOn F D := ConvexOn.continuousOn hD hF + have hSopen : IsOpen S := by + rw [isOpen_iff_mem_nhds] + intro z hz + have hDnhds : D ∈ nhds z.1 := hD.mem_nhds hz.1 + have hc : ContinuousAt (fun w : E × ℝ => F w.1) z := + (hFcont.continuousAt hDnhds).comp continuous_fst.continuousAt + exact inter_mem (continuous_fst.continuousAt.preimage_mem_nhds hDnhds) + (hc.eventually_lt continuous_snd.continuousAt hz.2) + have hnot : (x, F x) ∉ S := by simp [S] + obtain ⟨ell, hsep⟩ := geometric_hahn_banach_point_open hSconv hSopen hnot + let α : ℝ := ell (0, 1) + let g : E →L[ℝ] ℝ := ell.comp (ContinuousLinearMap.inl ℝ E ℝ) + have hsplit (y : E) (r : ℝ) : ell (y, r) = g y + r * α := by + have hp : (y, r) = (y, 0) + r • (0, 1) := by ext <;> simp + rw [hp, map_add, map_smul] + rfl + have hα : 0 < α := by + have hh := hsep (x, F x + 1) (by exact ⟨hx, by dsimp; linarith⟩) + rw [hsplit, hsplit] at hh + nlinarith + have hle (y : E) (hy : y ∈ D) : g x + F x * α ≤ g y + F y * α := by + apply le_of_forall_pos_le_add + intro ε hε + have hh := hsep (y, F y + ε / α) (by exact ⟨hy, by dsimp; linarith [div_pos hε hα]⟩) + rw [hsplit, hsplit] at hh + have he := div_mul_cancel₀ ε (ne_of_gt hα) + nlinarith [hh, he] + let v : E := (InnerProductSpace.toDual ℝ E).symm ((-1 / α) • g) + refine ⟨v, ?_⟩ + intro y hy + have heq : α * inner ℝ v (y - x) = g x - g y := by + dsimp [v] + rw [InnerProductSpace.toDual_symm_apply, smul_apply, map_sub] + simp only [smul_eq_mul] + field_simp + ring + have hh := hle y hy + nlinarith [hh, heq] + +end InnerSupport + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/TetraGeometry.lean b/lean/OAI/Probability/RadialTransition/TetraGeometry.lean new file mode 100644 index 0000000000000000000000000000000000000000..739b9bfe4a57fa215a361de7f4be3c289f50fe33 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/TetraGeometry.lean @@ -0,0 +1,120 @@ +import OAI.Probability.RadialTransition.CoreUpper + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma dist_le_twice_coordinate {x y : Position} {a : ℝ} (ha : 0 ≤ a) + (hxy : ∀ k, |x k-y k| ≤ a) : dist x y ≤ 2*a := by + have hh : dist x y ^ 2 ≤ 3*a^2 := by + rw [EuclideanSpace.dist_sq_eq] + calc + _ ≤ ∑ _k : Fin 3, a^2 := Finset.sum_le_sum (fun k _ => by + simpa only [Real.dist_eq] using (sq_le_sq₀ (abs_nonneg _) ha).mpr (hxy k)) + _ = _ := by simp + nlinarith [dist_nonneg (x := x) (y := y)] + +def tetraEdge (t : ℝ) : ℝ := microLength t + microLength t/2000 + +def tetraVertex (t : ℝ) (i : Fin 4) : Position := + WithLp.toLp 2 (fun k : Fin 3 => if i.val=0 ∨ i.val=k.val+1 then 0 else tetraEdge t*Real.sqrt 2/2) + +def tetraEpsilon (t : ℝ) : ℝ := microLength t/100000 + +lemma tetraEdge_pos (t : ℝ) : 0 < tetraEdge t := by + unfold tetraEdge + have := microLength_pos t + positivity + +lemma tetraEpsilon_pos (t : ℝ) : 0 < tetraEpsilon t := div_pos (microLength_pos t) (by norm_num) + +lemma tetraVertex_zero (t : ℝ) : tetraVertex t 0 = 0 := by ext k; simp [tetraVertex] + +lemma tetraVertex_coordinate (t : ℝ) (i : Fin 4) (k : Fin 3) : + 0 ≤ tetraVertex t i k ∧ tetraVertex t i k ≤ 2*microLength t := by + have hl := (microLength_pos t).le + have hs0 := Real.sqrt_nonneg (2:ℝ) + have hs2 : Real.sqrt (2:ℝ) ≤ 2 := by nlinarith [Real.sq_sqrt (by norm_num : (0:ℝ) ≤ 2)] + change 0 ≤ (if i.val=0 ∨ i.val=k.val+1 then 0 else tetraEdge t*Real.sqrt 2/2) ∧ + (if i.val=0 ∨ i.val=k.val+1 then 0 else tetraEdge t*Real.sqrt 2/2) ≤ 2*microLength t + split_ifs + · exact ⟨le_rfl, by positivity⟩ + · constructor + · exact div_nonneg (mul_nonneg (tetraEdge_pos t).le hs0) (by norm_num) + · unfold tetraEdge + nlinarith [mul_le_mul_of_nonneg_left hs2 (tetraEdge_pos t).le] + +lemma tetraVertex_dist (t : ℝ) {i j : Fin 4} (hij : i ≠ j) : + dist (tetraVertex t i) (tetraVertex t j) = tetraEdge t := by + have hs : Real.sqrt (2:ℝ)^2 = 2 := Real.sq_sqrt (by norm_num) + have ha : (tetraEdge t*Real.sqrt 2/2)^2 = (tetraEdge t)^2/2 := by + calc + _ = (tetraEdge t)^2*(Real.sqrt 2)^2/4 := by ring + _ = _ := by rw [hs]; ring + have hd : dist (tetraVertex t i) (tetraVertex t j)^2 = (tetraEdge t)^2 := by + rw [EuclideanSpace.dist_sq_eq] + fin_cases i <;> fin_cases j <;> first + | exact (hij rfl).elim + | norm_num [tetraVertex, Fin.sum_univ_succ, Real.dist_eq, sq_abs]; nlinarith [ha] + nlinarith [dist_nonneg (x := tetraVertex t i) (y := tetraVertex t j), tetraEdge_pos t] + +def tetraRegion (t a : ℝ) : Set (Fin 4 → Position) := + {x | x 0 ∈ cube a ∧ ∀ j : Fin 3, x j.succ - x 0 - tetraVertex t j.succ ∈ cube (tetraEpsilon t)} + +lemma tetraRegion_error {t a : ℝ} {x : Fin 4 → Position} (hx : x ∈ tetraRegion t a) (i : Fin 4) : + dist (x i) (x 0+tetraVertex t i) ≤ 2*tetraEpsilon t := by + cases i using Fin.cases with + | zero => simp only [tetraVertex_zero, add_zero, dist_self]; positivity [tetraEpsilon_pos t] + | succ i => + apply dist_le_twice_coordinate (tetraEpsilon_pos t).le + intro k + have hk := hx.2 i k + change 0 ≤ x i.succ k-x 0 k-tetraVertex t i.succ k ∧ x i.succ k-x 0 k-tetraVertex t i.succ k ≤ tetraEpsilon t at hk + change |x i.succ k-(x 0 k+tetraVertex t i.succ k)| ≤ tetraEpsilon t + rw [abs_of_nonneg (by linarith : 0 ≤ x i.succ k-(x 0 k+tetraVertex t i.succ k))] + linarith + +lemma tetraRegion_core_zero {t a : ℝ} {x : Fin 4 → Position} (hx : x ∈ tetraRegion t a) : + energy (corePotential t) x = 0 := by + apply Finset.sum_eq_zero + intro i _ + apply Finset.sum_eq_zero + intro j hj + have hij := ne_of_lt (Finset.mem_filter.mp hj).2 + have hdist : dist (x 0+tetraVertex t i) (x 0+tetraVertex t j) = tetraEdge t := by + rw [dist_add_left, tetraVertex_dist t hij] + have hi := tetraRegion_error hx i + have hj := tetraRegion_error hx j + have hupper := dist_triangle4 (x i) (x 0+tetraVertex t i) (x 0+tetraVertex t j) (x j) + have hlower := dist_triangle4 (x 0+tetraVertex t i) (x i) (x j) (x 0+tetraVertex t j) + rw [hdist, dist_comm (x 0+tetraVertex t j) (x j)] at hupper + rw [hdist, dist_comm (x 0+tetraVertex t i) (x i)] at hlower + apply coreReal_zero_plateau + · change microLength t + shellStep t ≤ dist (x i) (x j) + dsimp [tetraEdge, tetraEpsilon, shellStep] at * + linarith [microLength_pos t] + · change dist (x i) (x j) ≤ microLength t + 2*shellStep t + dsimp [tetraEdge, tetraEpsilon, shellStep] at * + linarith [microLength_pos t] + +lemma tetraRegion_cube {t a : ℝ} {x : Fin 4 → Position} (hx : x ∈ tetraRegion t a) : + x ∈ configurationCube (a+3*microLength t) 4 := by + intro i k + have hl := (microLength_pos t).le + cases i using Fin.cases with + | zero => have hh := hx.1 k; constructor <;> linarith + | succ i => + have hi := hx.2 i k + change 0 ≤ x i.succ k-x 0 k-tetraVertex t i.succ k ∧ x i.succ k-x 0 k-tetraVertex t i.succ k ≤ tetraEpsilon t at hi + have hv := tetraVertex_coordinate t i.succ k + have h0 := hx.1 k + dsimp [tetraEpsilon] at hi + constructor <;> linarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/TetraIntegral.lean b/lean/OAI/Probability/RadialTransition/TetraIntegral.lean new file mode 100644 index 0000000000000000000000000000000000000000..27fb85e4d1cf9dd996fbf5b11a157af7aa6a35a6 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/TetraIntegral.lean @@ -0,0 +1,108 @@ +import OAI.Probability.RadialTransition.CorePressureLower + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition +attribute [local instance] Classical.propDecidable + +lemma measurableSet_tetraRegion (t a : ℝ) : MeasurableSet (tetraRegion t a) := by + apply MeasurableSet.inter + · exact (measurableSet_cube a).preimage (measurable_pi_apply 0) + · change MeasurableSet {x : Fin 4 → Position | ∀ j : Fin 3, x j.succ-x 0-tetraVertex t j.succ ∈ cube (tetraEpsilon t)} + rw [Set.ofPred_forall] + apply MeasurableSet.iInter + intro j + exact (measurableSet_cube _).preimage (((measurable_pi_apply j.succ).sub (measurable_pi_apply 0)).sub measurable_const) + +lemma lintegral_tetra_fiber (t : ℝ) (x : Position) : + (∫⁻ y : Fin 3 → Position, ∏ j, regionMask (cube (tetraEpsilon t)) (y j-x-tetraVertex t j.succ) + ∂Measure.pi (fun _ => volume)) = (ENNReal.ofReal (tetraEpsilon t)^3)^3 := by + have he (y : Fin 3 → Position) : + (∏ j, regionMask (cube (tetraEpsilon t)) (y j-x-tetraVertex t j.succ)) = + (Set.pi univ (fun j : Fin 3 => translateSet (x+tetraVertex t j.succ) (cube (tetraEpsilon t)))).indicator (fun _ => 1) y := by + simp only [regionMask, Set.indicator, Finset.prod_boole] + have hm : (∀ j : Fin 3, y j-x-tetraVertex t j.succ ∈ cube (tetraEpsilon t)) ↔ + y ∈ Set.pi univ (fun j : Fin 3 => translateSet (x+tetraVertex t j.succ) (cube (tetraEpsilon t))) := by + simp [Set.mem_pi, translateSet, sub_sub] + simp [hm] + simp_rw [he] + change (∫⁻ y, (Set.pi univ (fun j : Fin 3 => translateSet (x+tetraVertex t j.succ) (cube (tetraEpsilon t)))).indicator (1 : (Fin 3 → Position) → ℝ≥0∞) y ∂Measure.pi (fun _ => volume)) = _ + rw [lintegral_indicator_one, Measure.pi_pi] + · simp_rw [volume_translateSet _ _ (measurableSet_cube _), volume_cube] + simp + · exact MeasurableSet.univ_pi (fun _ => measurableSet_translate (measurableSet_cube _)) + +lemma volume_tetraRegion (t a : ℝ) : + volume (tetraRegion t a) = ENNReal.ofReal a^3*(ENNReal.ofReal (tetraEpsilon t)^3)^3 := by + let F (p : Position × (Fin 3 → Position)) : ℝ≥0∞ := + regionMask (cube a) p.1 * ∏ j, regionMask (cube (tetraEpsilon t)) (p.2 j-p.1-tetraVertex t j.succ) + have hF : Measurable F := by + apply ((measurable_regionMask (measurableSet_cube _)).comp measurable_fst).mul + apply Finset.measurable_prod + intro j _ + apply (measurable_regionMask (measurableSet_cube _)).comp + fun_prop + have he (x : Fin 4 → Position) : + (tetraRegion t a).indicator (fun _ => (1:ℝ≥0∞)) x = + F (x 0, fun j => x j.succ) := by + by_cases h1 : x 0 ∈ cube a <;> + by_cases h2 : ∀ j : Fin 3, x j.succ-x 0-tetraVertex t j.succ ∈ cube (tetraEpsilon t) <;> + simp [F, regionMask, tetraRegion, Set.indicator, Finset.prod_boole, h1, h2] + + rw [← lintegral_indicator_one (measurableSet_tetraRegion t a)] + change (∫⁻ x, (tetraRegion t a).indicator (fun _ => (1:ℝ≥0∞)) x) = _ + rw [volume_pi] + simp_rw [he] + have hh := (measurePreserving_piFinSuccAbove (fun _ : Fin 4 => (volume : Measure Position)) 0).lintegral_comp hF + simp only [MeasurableEquiv.piFinSuccAbove_apply, Fin.insertNthEquiv_symm_apply] at hh + have her (x : Fin 4 → Position) : Fin.removeNth 0 x = fun j => x j.succ := by + funext j + simp only [Fin.removeNth_apply, Fin.succAbove_zero] + simp_rw [her] at hh + rw [hh, lintegral_prod _ hF.aemeasurable] + have hfin (x : Position) : regionMask (cube a) x ≠ ⊤ := by + by_cases hx : x ∈ cube a <;> simp [regionMask, hx] + simp only [F] + simp_rw [lintegral_const_mul' _ _ (hfin _), lintegral_tetra_fiber] + rw [lintegral_mul_const'] + · change (∫⁻ x, (cube a).indicator (1 : Position → ℝ≥0∞) x) * _ = _ + rw [lintegral_indicator_one (measurableSet_cube _), volume_cube] + · exact ENNReal.pow_ne_top (ENNReal.pow_ne_top ENNReal.ofReal_ne_top) + +lemma partitionOn_tetra_lower (t a β : ℝ) (ha : 0 ≤ a) : + a^3*(tetraEpsilon t)^9/24 ≤ partitionOn (corePotential t) (cube (a+3*microLength t)) 4 β := by + have hs : tetraRegion t a ⊆ configurationCube (a+3*microLength t) 4 := fun _ hx => tetraRegion_cube hx + have hc : Set.univ.pi (fun _ : Fin 4 => cube (a+3*microLength t)) = configurationCube (a+3*microLength t) 4 := by + ext x + simp [configurationCube, Set.mem_pi] + have hfin : volume (cube (a+3*microLength t)) ≠ ⊤ := by rw [volume_cube]; finiteness + let : IsFiniteMeasure (volume.restrict (cube (a+3*microLength t))) := isFiniteMeasure_restrict.mpr hfin + have hi := integrable_orderedBoltzmann (ι := Fin 4) (continuous_corePotential t) (bounded_corePotential t) β (Measure.pi (fun _ : Fin 4 => volume.restrict (cube (a+3*microLength t)))) + rw [← Measure.restrict_pi_pi, hc, ← volume_pi] at hi + have hle := integral_mono_measure (Measure.restrict_mono hs le_rfl) + (Eventually.of_forall (fun x : Fin 4 → Position => (Real.exp_pos (-β*orderedEnergy (corePotential t) x)).le)) hi + have he : (∫ x in tetraRegion t a, Real.exp (-β*orderedEnergy (corePotential t) x)) = + a^3*(tetraEpsilon t)^9 := by + have hh : (∫ x in tetraRegion t a, Real.exp (-β*orderedEnergy (corePotential t) x)) = + ∫ _x in tetraRegion t a, (1:ℝ) := by + apply setIntegral_congr_fun (measurableSet_tetraRegion t a) + intro x hx + change Real.exp (-β*orderedEnergy (corePotential t) x) = 1 + rw [orderedEnergy_fin, tetraRegion_core_zero hx, mul_zero, Real.exp_zero] + rw [hh, integral_const, Measure.real, Measure.restrict_apply MeasurableSet.univ, Set.univ_inter, + volume_tetraRegion, smul_eq_mul, mul_one, ENNReal.toReal_mul, ENNReal.toReal_pow, + ENNReal.toReal_ofReal ha, ENNReal.toReal_pow, ENNReal.toReal_pow, + ENNReal.toReal_ofReal (tetraEpsilon_pos t).le] + ring + rw [he] at hle + rw [partitionOn, rawPartition_setIntegral, hc] + norm_num only [Nat.factorial, Nat.cast_ofNat, inv_eq_one_div] + linarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/ThermodynamicLimit.lean b/lean/OAI/Probability/RadialTransition/ThermodynamicLimit.lean new file mode 100644 index 0000000000000000000000000000000000000000..6180451fd25a90243428f6e84c512fea50abcbb6 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/ThermodynamicLimit.lean @@ -0,0 +1,301 @@ +import OAI.Probability.RadialTransition.SpatialReplication + +namespace OAI + +universe uIndex + +noncomputable section + +open scoped BigOperators NNReal ContDiff ENNReal +open Filter MeasureTheory Set + +namespace RadialTransition + +theorem separated_box_limit {F : ℝ → ℝ} {C δ : ℝ} (hC : 0 ≤ C) (hδ : 0 < δ) + (hF0 : ∀ s, 0 ≤ s → 0 ≤ F s) + (hFC : ∀ s, 0 ≤ s → F s ≤ C * s ^ 3) + (hrep : ∀ (s L : ℝ) (n : ℕ), 0 ≤ s → (n : ℝ) * (s + δ) ≤ L → + (n : ℝ) ^ 3 * F s ≤ F L) : + ∃ p : ℝ, 0 ≤ p ∧ p ≤ C ∧ + Tendsto (fun L : ℝ => F L / L ^ 3) atTop (nhds p) ∧ + ∀ s, 0 ≤ s → F s / (s + δ) ^ 3 ≤ p := by + let S : Set ℝ := {r | ∃ s : ℝ, 0 ≤ s ∧ r = F s / (s + δ) ^ 3} + have hnon : S.Nonempty := ⟨_, 0, le_rfl, rfl⟩ + have hbound : ∀ s, 0 ≤ s → F s / (s + δ) ^ 3 ≤ C := by + intro s hs + apply (div_le_iff₀ (by positivity : 0 < (s + δ) ^ 3)).mpr + calc + F s ≤ C * s ^ 3 := hFC s hs + _ ≤ C * (s + δ) ^ 3 := by gcongr; linarith + have hbd : BddAbove S := ⟨C, by rintro r ⟨s, hs, rfl⟩; exact hbound s hs⟩ + let p : ℝ := sSup S + have hpC : p ≤ C := csSup_le hnon (by rintro r ⟨s, hs, rfl⟩; exact hbound s hs) + have hsp (s : ℝ) (hs : 0 ≤ s) : F s / (s + δ) ^ 3 ≤ p := le_csSup hbd ⟨s, hs, rfl⟩ + have hp0 : 0 ≤ p := (div_nonneg (hF0 0 le_rfl) (by positivity)).trans (hsp 0 le_rfl) + refine ⟨p, hp0, hpC, ?_, hsp⟩ + apply tendsto_order.mpr + constructor + · intro a ha + obtain ⟨r, ⟨s, hs, rfl⟩, har⟩ := (lt_csSup_iff hbd hnon).mp ha + have hlim : Tendsto (fun L : ℝ => ((⌊L / (s + δ)⌋₊ : ℝ) / L) ^ 3 * F s) + atTop (nhds (F s / (s + δ) ^ 3)) := by + have hh := ((tendsto_nat_floor_mul_div_atTop (show 0 ≤ (s + δ)⁻¹ by positivity)).pow 3).mul_const (F s) + simpa only [div_eq_mul_inv, inv_pow, mul_comm] using hh + filter_upwards [hlim.eventually_const_lt har, eventually_gt_atTop (0 : ℝ)] with L hlo hL + have hn : (⌊L / (s + δ)⌋₊ : ℝ) * (s + δ) ≤ L := + (le_div_iff₀ (by positivity : 0 < s + δ)).mp (Nat.floor_le (by positivity)) + have hh := div_le_div_of_nonneg_right (hrep s L ⌊L / (s + δ)⌋₊ hs hn) + (show 0 ≤ L ^ 3 by positivity) + have heq : ((⌊L / (s + δ)⌋₊ : ℝ) / L) ^ 3 * F s = + ((⌊L / (s + δ)⌋₊ : ℝ) ^ 3 * F s) / L ^ 3 := by ring + exact hlo.trans_le (heq ▸ hh) + · intro a ha + have hlim : Tendsto (fun L : ℝ => p * (1 + δ * L⁻¹) ^ 3) atTop (nhds p) := by + have hh := ((tendsto_const_nhds (x := (1 : ℝ))).add + (tendsto_inv_atTop_zero.const_mul δ)).pow 3 + simpa using hh.const_mul p + filter_upwards [hlim.eventually_lt_const ha, eventually_gt_atTop (0 : ℝ)] with L hhi hL + apply lt_of_le_of_lt _ hhi + apply (div_le_iff₀ (by positivity : 0 < L ^ 3)).mpr + have hh := (div_le_iff₀ (by positivity : 0 < (L + δ) ^ 3)).mp (hsp L hL.le) + calc + F L ≤ p * (L + δ) ^ 3 := hh + _ = p * (1 + δ * L⁻¹) ^ 3 * L ^ 3 := by field_simp + +theorem grandPressure_exists {φ : Potential} (hφ : Continuous φ) (hb : IsBoundedPotential φ) + {B t β : ℝ} (hstable : StableWith φ B) (ht : 0 < t) (hβ : 0 ≤ β) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) (h : ℝ) : + ∃ p : ℝ, 0 ≤ p ∧ p ≤ Real.exp (β * B + t * h) / t ∧ + Tendsto (fun L : ℝ => Real.log (grandPartition φ t L β h) / (t * L ^ 3)) + atTop (nhds p) := by + have hbnd (s : ℝ) (hs : 0 ≤ s) := grandPartition_bounds hφ hb hstable hs hβ t h + obtain ⟨p, hp0, hpC, hlim, _⟩ := separated_box_limit + (F := fun L => Real.log (grandPartition φ t L β h)) + (C := Real.exp (β * B + t * h)) (δ := 2) (Real.exp_pos _).le (by norm_num) + (fun s hs => Real.log_nonneg (hbnd s hs).1) + (fun s hs => by + have hh := Real.log_le_log (show 0 < grandPartition φ t s β h by linarith [(hbnd s hs).1]) + (hbnd s hs).2 + simpa only [Real.log_exp, mul_comm] using hh) + (fun s L n hs hn => by + have hh := Real.log_le_log + (pow_pos (show 0 < grandPartition φ t s β h by linarith [(hbnd s hs).1]) _) + (grandPartition_replication hφ hb hstable hβ hs hc n hn t h) + simpa only [Real.log_pow, Nat.cast_pow] using hh) + refine ⟨p / t, div_nonneg hp0 ht.le, (div_le_div_of_nonneg_right hpC ht.le), ?_⟩ + simpa only [div_div, mul_comm] using hlim.div_const t + +theorem exists_bounded_fill (k c E : ℕ) (hc : 0 < c) (hE : E ≤ k * c) : + ∃ v : Fin k → ℕ, (∀ i, v i ≤ c) ∧ (∑ i, v i) = E ∧ + (Finset.univ.filter (fun i => v i ≠ 0)).card ≤ E / c + 1 := by + classical + let r := E / c + let a := E % c + have ha : a < c := Nat.mod_lt _ hc + have hdecomp : r * c + a = E := by + dsimp [r, a] + simpa [Nat.mul_comm, Nat.add_comm] using Nat.mod_add_div E c + have hr : r ≤ k := by + have hh : r * c ≤ k * c := by omega + exact (mul_le_mul_iff_left₀ hc).mp (by simpa [Nat.mul_comm] using hh) + let v : Fin k → ℕ := fun i => (if (i : ℕ) < r then c else 0) + + (if (i : ℕ) = r then a else 0) + have hv (i : Fin k) : v i ≤ c := by + dsimp [v] + split_ifs <;> omega + have hsum1 : (∑ i : Fin k, if (i : ℕ) < r then c else 0) = r * c := by + rw [← Finset.sum_filter] + simp only [Finset.sum_const, Fin.card_filter_val_lt, min_eq_right hr, nsmul_eq_mul, Nat.cast_id] + have hsum2 : (∑ i : Fin k, if (i : ℕ) = r then a else 0) = a := by + by_cases hr' : r < k + · let j : Fin k := ⟨r, hr'⟩ + have hiff (i : Fin k) : (i : ℕ) = r ↔ i = j := by + exact ⟨fun h => Fin.ext h, fun h => congrArg Fin.val h⟩ + simp_rw [hiff] + simp + · have he : r = k := by omega + have ha0 : a = 0 := by rw [he] at hdecomp; omega + simp [ha0] + have hcard : (Finset.univ.filter (fun i => v i ≠ 0)).card ≤ r + 1 := by + have hsub : Finset.univ.filter (fun i => v i ≠ 0) ⊆ + Finset.univ.filter (fun i : Fin k => (i : ℕ) < r + 1) := by + intro i hi + simp only [Finset.mem_filter, Finset.mem_univ, true_and] at hi ⊢ + by_contra hh + have hge : r + 1 ≤ (i : ℕ) := by omega + simp [v, show ¬(i : ℕ) < r by omega, show (i : ℕ) ≠ r by omega] at hi + exact (Finset.card_le_card hsub).trans (by rw [Fin.card_filter_val_lt]; exact min_le_right _ _) + refine ⟨v, hv, ?_, hcard⟩ + simp only [v, Finset.sum_add_distrib, hsum1, hsum2] + exact hdecomp + +theorem exists_integer_adjustment (k m q n : ℕ) (hm : 0 < m) (hmq : m < q) + (hn : n ≤ k * q) {c : ℝ} (hc : 0 < c) (hcm : c ≤ (m : ℝ)) + (hcq : c ≤ ((q - m : ℕ) : ℝ)) : + ∃ f : Fin k → ℕ, (∑ i, f i) = n ∧ (∀ i, f i ≤ q) ∧ + ((Finset.univ.filter (fun i => f i ≠ m)).card : ℝ) ≤ + |(n : ℝ) - (k : ℝ) * m| / c + 1 := by + classical + by_cases hmn : k * m ≤ n + · have hE : n - k * m ≤ k * (q - m) := by + rw [Nat.mul_sub_left_distrib] + exact Nat.sub_le_sub_right hn _ + obtain ⟨v, hv, hsv, hcv⟩ := exists_bounded_fill k (q - m) (n - k * m) + (Nat.sub_pos_of_lt hmq) hE + let f : Fin k → ℕ := fun i => m + v i + have hs : (∑ i, f i) = n := by + simp only [f, Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul, Nat.cast_id, hsv] + omega + have he : (Finset.univ.filter (fun i => f i ≠ m)) = + Finset.univ.filter (fun i => v i ≠ 0) := by + ext i + simp [f] + refine ⟨f, hs, (fun i => by dsimp [f]; have := hv i; omega), ?_⟩ + rw [he] + have hvreal : ((Finset.univ.filter (fun i => v i ≠ 0)).card : ℝ) ≤ + ((n - k * m) / (q - m) : ℕ) + 1 := by exact_mod_cast hcv + have hdiv : (((n - k * m) / (q - m) : ℕ) : ℝ) ≤ + ((n - k * m : ℕ) : ℝ) / c := by + apply Nat.cast_div_le.trans + exact div_le_div_of_nonneg_left (by positivity) hc hcq + have hdiff : ((n - k * m : ℕ) : ℝ) = |(n : ℝ) - (k : ℝ) * m| := by + rw [Nat.cast_sub hmn, Nat.cast_mul, abs_of_nonneg] + exact sub_nonneg.mpr (by exact_mod_cast hmn) + rw [hdiff] at hdiv + linarith + · have hnkm : n ≤ k * m := by omega + obtain ⟨v, hv, hsv, hcv⟩ := exists_bounded_fill k m (k * m - n) hm (Nat.sub_le _ _) + let f : Fin k → ℕ := fun i => m - v i + have hs : (∑ i, f i) = n := by + dsimp [f] + rw [Finset.sum_tsub_distrib _ (fun i _ => hv i), Finset.sum_const, hsv] + simp only [Finset.card_univ, Fintype.card_fin, nsmul_eq_mul, Nat.cast_id] + omega + have he : (Finset.univ.filter (fun i => f i ≠ m)) = + Finset.univ.filter (fun i => v i ≠ 0) := by + ext i + simp only [Finset.mem_filter, Finset.mem_univ, true_and, f] + have hvi := hv i + omega + refine ⟨f, hs, (fun i => (Nat.sub_le _ _).trans hmq.le), ?_⟩ + rw [he] + have hvreal : ((Finset.univ.filter (fun i => v i ≠ 0)).card : ℝ) ≤ + ((k * m - n) / m : ℕ) + 1 := by exact_mod_cast hcv + have hdiv : (((k * m - n) / m : ℕ) : ℝ) ≤ + ((k * m - n : ℕ) : ℝ) / c := by + apply Nat.cast_div_le.trans + exact div_le_div_of_nonneg_left (by positivity) hc hcm + have hdiff : ((k * m - n : ℕ) : ℝ) = |(n : ℝ) - (k : ℝ) * m| := by + rw [Nat.cast_sub hnkm, Nat.cast_mul, abs_of_nonpos] + · ring + · exact sub_nonpos.mpr (by exact_mod_cast hnkm) + rw [hdiff] at hdiv + linarith + +theorem sum_changed_cost {ι : Type uIndex} [Fintype ι] (f : ι → ℕ) (m : ℕ) + (H : ℕ → ℝ) {K : ℝ} (hm : |H m| ≤ K) (hf : ∀ i, |H (f i)| ≤ K) : + (∑ i, H (f i)) ≤ Fintype.card ι * H m + + 2 * K * (Finset.univ.filter (fun i => f i ≠ m)).card := by + classical + have hh : ∀ i, H (f i) ≤ H m + if f i ≠ m then 2 * K else 0 := by + intro i + split_ifs with hi + · linarith [(abs_le.mp (hf i)).2, (abs_le.mp hm).1] + · simp only [not_not] at hi + simp [hi] + have hs := Finset.sum_le_sum (s := Finset.univ) (fun i _ => hh i) + simp only [Finset.sum_add_distrib, Finset.sum_const, Finset.card_univ, + nsmul_eq_mul] at hs + have he : (∑ i, if f i ≠ m then 2 * K else 0) = + 2 * K * (Finset.univ.filter (fun i => f i ≠ m)).card := by + rw [← Finset.sum_filter, Finset.sum_const] + simp only [nsmul_eq_mul] + ring + rwa [he] at hs + +theorem finiteCanonical_replication {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {β t s L : ℝ} (hβ : 0 ≤ β) (ht : 0 < t) + (hs : 0 < s) (hL : 0 < L) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) (n : ℕ) + (hn : (n : ℝ) * (s + 2) ≤ L) (m : Fin (n ^ 3) → ℕ) : + finiteCanonical φ t L (∑ j, m j) β ≤ + s ^ 3 / L ^ 3 * ∑ j, finiteCanonical φ t s (m j) β := by + classical + let e : (Fin 3 → Fin n) ≃ Fin (n ^ 3) := Fintype.equivFinOfCardEq (by simp) + have hp := partition_replication hφ hb hβ hs.le hc n hn (m ∘ e) + have hsum : (∑ j, (m ∘ e) j) = ∑ j, m j := e.sum_comp m + have hprod : (∏ j, partition φ s ((m ∘ e) j) β) = + ∏ j, partition φ s (m j) β := e.prod_comp (fun j => partition φ s (m j) β) + rw [hsum, hprod] at hp + have hpos : ∀ j ∈ (Finset.univ : Finset (Fin (n ^ 3))), 0 < partition φ s (m j) β := + fun j _ => partition_pos hφ hb hs _ _ + have hlog := Real.log_le_log (Finset.prod_pos hpos) hp + rw [Real.log_prod (fun j hj => (hpos j hj).ne')] at hlog + have hpoint (j : Fin (n ^ 3)) : Real.log (partition φ s (m j) β) = + -(t * s ^ 3) * finiteCanonical φ t s (m j) β := by + dsimp only [finiteCanonical] + field_simp + simp_rw [hpoint] at hlog + rw [← Finset.mul_sum] at hlog + change -Real.log (partition φ L (∑ j, m j) β) / (t * L ^ 3) ≤ _ + rw [div_le_iff₀ (mul_pos ht (pow_pos hL 3))] + have he : (s ^ 3 / L ^ 3 * ∑ j, finiteCanonical φ t s (m j) β) * (t * L ^ 3) = + t * s ^ 3 * ∑ j, finiteCanonical φ t s (m j) β := by field_simp + rw [he] + linarith + +theorem finiteCanonical_adjustment {φ : Potential} (hφ : Continuous φ) + (hb : IsBoundedPotential φ) {β t s L : ℝ} (hβ : 0 ≤ β) (ht : 0 < t) + (hs : 0 < s) (hL : 0 < L) + (hc : ∀ r : ℝ≥0, 2 ≤ (r : ℝ) → φ r ≤ 0) (b m q N : ℕ) + (hbL : (b : ℝ) * (s + 2) ≤ L) (hm : 0 < m) (hmq : m < q) + (hN : N ≤ b ^ 3 * q) {c K : ℝ} (hc0 : 0 < c) (hcm : c ≤ (m : ℝ)) + (hcq : c ≤ ((q - m : ℕ) : ℝ)) (hK : 0 ≤ K) + (hcost : ∀ j ≤ q, |finiteCanonical φ t s j β| ≤ K) : + finiteCanonical φ t L N β ≤ s ^ 3 / L ^ 3 * + ((b : ℝ) ^ 3 * finiteCanonical φ t s m β + + 2 * K * (|(N : ℝ) - (b : ℝ) ^ 3 * m| / c + 1)) := by + obtain ⟨f, hfN, hfq, hfc⟩ := exists_integer_adjustment (b ^ 3) m q N hm hmq hN hc0 hcm hcq + have hr := finiteCanonical_replication hφ hb hβ ht hs hL hc b hbL f + rw [hfN] at hr + have hsum := sum_changed_cost f m (fun j => finiteCanonical φ t s j β) + (hcost m hmq.le) (fun i => hcost (f i) (hfq i)) + simp only [Fintype.card_fin, Nat.cast_pow] at hsum hfc + apply hr.trans + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact hsum.trans (by gcongr) + +def thermodynamicFilter (d : ℝ) : Filter (ℝ × ℕ) := + Filter.comap Prod.fst atTop ⊓ + Filter.comap (fun z : ℝ × ℕ => (z.2 : ℝ) / z.1 ^ 3) (nhds d) + +theorem thermodynamicFilter_side (d : ℝ) : + Tendsto Prod.fst (thermodynamicFilter d) atTop := by + exact tendsto_comap.mono_left inf_le_left + +theorem thermodynamicFilter_density (d : ℝ) : + Tendsto (fun z : ℝ × ℕ => (z.2 : ℝ) / z.1 ^ 3) + (thermodynamicFilter d) (nhds d) := by + exact tendsto_comap.mono_left inf_le_right + +theorem floor_density_tendsto {d : ℝ} (hd : 0 ≤ d) : + Tendsto (fun L : ℝ => (⌊d * L ^ 3⌋₊ : ℝ) / L ^ 3) atTop (nhds d) := by + have hh := (tendsto_nat_floor_mul_div_atTop hd).comp (tendsto_pow_atTop (by norm_num : 3 ≠ 0)) + simpa only [Function.comp_def, mul_comm] using hh + +theorem floor_tendsto_thermodynamicFilter {d : ℝ} (hd : 0 ≤ d) : + Tendsto (fun L : ℝ => (L, ⌊d * L ^ 3⌋₊)) atTop (thermodynamicFilter d) := by + apply tendsto_inf.mpr + constructor + · exact tendsto_comap_iff.mpr tendsto_id + · exact tendsto_comap_iff.mpr (floor_density_tendsto hd) + +theorem thermodynamicFilter_neBot {d : ℝ} (hd : 0 ≤ d) : NeBot (thermodynamicFilter d) := + (floor_tendsto_thermodynamicFilter hd).neBot + +end RadialTransition + +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/TruncatedFamily.lean b/lean/OAI/Probability/RadialTransition/TruncatedFamily.lean new file mode 100644 index 0000000000000000000000000000000000000000..69a9608db2134b097addd6f449c885c633ec894e --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/TruncatedFamily.lean @@ -0,0 +1,112 @@ +import OAI.Probability.RadialTransition.ScaleSequence + +namespace OAI + +noncomputable section +open scoped BigOperators NNReal +open Set Filter +namespace RadialTransition + +def reversePrefix (v : ℝ) (f : ℕ → ℝ) : ℕ → ℕ → ℝ + | 0 => fun _ => v + | n+1 => prepend (f n) (reversePrefix v f n) +@[simp] lemma reversePrefix_zero (v : ℝ) (f : ℕ → ℝ) : reversePrefix v f 0=(fun _ => v) := rfl +@[simp] lemma reversePrefix_succ (v : ℝ) (f : ℕ → ℝ) (n : ℕ) : + reversePrefix v f (n+1)=prepend (f n) (reversePrefix v f n) := rfl +lemma reversePrefix_nonneg {f : ℕ → ℝ} (hf : ∀ n, 0 ≤ f n) (n : ℕ) : ∀ j, 0 ≤ reversePrefix 0 f n j := by + induction n with + | zero => exact fun _ => le_rfl + | succ n ih => exact prepend_nonneg (hf n) ih +lemma reversePrefix_range {R : ℕ → ℝ} (hR : ∀ n, 1 ≤ R n) (n : ℕ) : ∀ j, 1 ≤ reversePrefix 1 R n j := by + induction n with + | zero => exact fun _ => le_rfl + | succ n ih => exact prepend_range (hR n) ih +lemma reversePrefix_range_le {R : ℕ → ℝ} {M : ℝ} (hM : 1 ≤ M) {n : ℕ} + (hR : ∀ j, j exact fun _ => hM + | succ n ih => + intro j + cases j with + | zero => exact hR n (by omega) + | succ j => exact ih (fun i hi => hR i (by omega)) j +lemma summable_reversePrefix (f : ℕ → ℝ) (n : ℕ) : Summable (reversePrefix 0 f n) := by + induction n with + | zero => exact summable_zero + | succ n ih => exact summable_prepend _ ih +lemma tsum_reversePrefix (f : ℕ → ℝ) (n : ℕ) : + (∑' j, reversePrefix 0 f n j)=∑ j ∈ Finset.range n, f j := by + induction n with + | zero => simp + | succ n ih => rw [reversePrefix_succ,tsum_prepend _ (summable_reversePrefix f n),Finset.sum_range_succ,ih,add_comm] +lemma attractionProfile_reversePrefix {a R : ℕ → ℝ} (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) + (n : ℕ) (r : ℝ) : attractionProfile (reversePrefix 0 a n) (reversePrefix 1 R n) r= + ∑ j ∈ Finset.range n, a j*scaledBumpProfile (R j) r := by + induction n with + | zero => simp [attractionProfile] + | succ n ih => + rw [reversePrefix_succ,reversePrefix_succ,attractionProfile_prepend (reversePrefix_nonneg ha n) + (reversePrefix_range hR n) (summable_reversePrefix a n),Finset.sum_range_succ,ih,add_comm] + +def cutMass (f : ℕ → ℝ) (n j : ℕ) : ℝ := if j simp_all +lemma summable_cutMass (f : ℕ → ℝ) (n : ℕ) : Summable (cutMass f n) := by + apply summable_of_ne_finset_zero (s := Finset.range n) + intro j hj + simp only [Finset.mem_range,not_lt] at hj + simp [cutMass,not_lt.mpr hj] +lemma tsum_cutMass (f : ℕ → ℝ) (n : ℕ) : (∑' j, cutMass f n j)=∑ j ∈ Finset.range n, f j := by + rw [tsum_eq_sum (s := Finset.range n) (fun j hj => by simp_all [cutMass])] + apply Finset.sum_congr rfl + intro j hj + simp [cutMass,Finset.mem_range.mp hj] +lemma attractionProfile_cutMass (a R : ℕ → ℝ) (n : ℕ) (r : ℝ) : attractionProfile (cutMass a n) R r= + ∑ j ∈ Finset.range n, a j*scaledBumpProfile (R j) r := by + unfold attractionProfile + rw [tsum_eq_sum (s := Finset.range n) (fun j hj => by simp_all [cutMass])] + apply Finset.sum_congr rfl + intro j hj + simp [cutMass,Finset.mem_range.mp hj] +lemma familyPotential_reverse_cut {a R : ℕ → ℝ} (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) + (t : ℝ) (n : ℕ) : familyPotential t (reversePrefix 0 a n) (reversePrefix 1 R n)= + familyPotential t (cutMass a n) R := by + funext r + simp only [familyPotential,attractionProfile_reversePrefix ha hR,attractionProfile_cutMass] +lemma reversePrefix_admissible {t A : ℝ} {a R : ℕ → ℝ} (ha : ∀ n, 0 ≤ a n) (hR : ∀ n, 1 ≤ R n) + (hs : Summable a) (hA : ∑' n, a n ≤ A) (n : ℕ) : + AdmissibleFamily t A (reversePrefix 0 a n) (reversePrefix 1 R n) := by + refine ⟨reversePrefix_nonneg ha n,reversePrefix_range hR n,summable_reversePrefix a n,?_⟩ + rw [tsum_reversePrefix] + exact (hs.sum_le_tsum _ (fun j _ => ha j)).trans hA +lemma cutMass_difference {a : ℕ → ℝ} (ha : ∀ n, 0 ≤ a n) (hs : Summable a) (n : ℕ) : + (∑' j, |a j-cutMass a n j|)=(∑' j, a j)-∑ j ∈ Finset.range n, a j := by + have he : (fun j => |a j-cutMass a n j|)=(fun j => a j-cutMass a n j) := by + funext j + exact abs_of_nonneg (sub_nonneg.mpr (cutMass_le ha n j)) + rw [he,hs.tsum_sub (summable_cutMass a n),tsum_cutMass] +lemma tendsto_cutMass_difference {a : ℕ → ℝ} (ha : ∀ n, 0 ≤ a n) (hs : Summable a) : + Tendsto (fun n => ∑' j, |a j-cutMass a n j|) atTop (nhds 0) := by + simp_rw [cutMass_difference ha hs] + simpa using (tendsto_const_nhds (x := ∑' j, a j)).sub hs.hasSum.tendsto_sum_nat +lemma grandPressure_reversePrefix_tendsto {t A β h : ℝ} {a R : ℕ → ℝ} + (ht : 1 ≤ t) (hβ : 0 < β) (had : AdmissibleFamily t A a R) + (hrow : 2197*t*bumpIntegral⁻¹*A ≤ (t^2/8)/8) : + Tendsto (fun n => grandPressure (familyPotential t (reversePrefix 0 a n) (reversePrefix 1 R n)) t β h) + atTop (nhds (grandPressure (familyPotential t a R) t β h)) := by + apply tendsto_iff_norm_sub_tendsto_zero.mpr + apply squeeze_zero_norm (a := fun n => familyPressureLipschitz t β h * ∑' j, |a j-cutMass a n j|) + · intro n + simpa only [Real.norm_eq_abs,abs_abs,familyPotential_reverse_cut had.1 had.2.1] using grandPressure_family_difference ht hβ (cutMass_nonneg had.1 n) had.1 had.1 had.2.1 + (summable_cutMass a n) had.2.2.1 had.2.2.1 (cutMass_le had.1 n) (fun _ => le_rfl) + (admissible_row (by linarith) had hrow) + · simpa using (tendsto_cutMass_difference had.1 had.2.2.1).const_mul (familyPressureLipschitz t β h) + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/UniformConstants.lean b/lean/OAI/Probability/RadialTransition/UniformConstants.lean new file mode 100644 index 0000000000000000000000000000000000000000..8424882b09b5a479a5e064076ceada8b0e809ca9 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/UniformConstants.lean @@ -0,0 +1,62 @@ +import OAI.Probability.RadialTransition.ScaleBudgets + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma boxPressureConstant_eq {t β : ℝ} (ht : 0 < t) (hβ : 0 < β) (h A : ℝ) : + boxPressureConstant t β h A = + (9216/t^3)*Real.exp (16/15*(1/64)*Real.exp (t*h+β*(t^2/2)))*referenceRowBound t A := by + unfold boxPressureConstant localMomentBound + field_simp + ring + +lemma boxPressureConstant_mono {t β γ h j A B : ℝ} (ht : 0 < t) (hβ : 0 < β) + (hβγ : β ≤ γ) (hhj : h ≤ j) (hA : 0 ≤ A) (hAB : A ≤ B) : + boxPressureConstant t β h A ≤ boxPressureConstant t γ j B := by + rw [boxPressureConstant_eq ht hβ, boxPressureConstant_eq ht (hβ.trans_le hβγ)] + apply mul_le_mul + · apply mul_le_mul_of_nonneg_left _ (by positivity) + apply Real.exp_le_exp.mpr + apply mul_le_mul_of_nonneg_left _ (by norm_num) + apply Real.exp_le_exp.mpr + exact add_le_add (mul_le_mul_of_nonneg_left hhj ht.le) + (mul_le_mul_of_nonneg_right hβγ (by positivity)) + · unfold referenceRowBound + gcongr + exact mul_nonneg (by positivity) (inv_nonneg.mpr bumpIntegral_pos.le) + · exact referenceRowBound_nonneg ht.le hA + · positivity + +lemma log_volume_error_le {F s t : ℝ} (hF : 0 ≤ F) (hs : 1 ≤ s) (ht : 0 < t) : + Real.log ((F+2)*s^3)/(t*s^3) ≤ (F+5)/(t*s) := by + have hs0 : 0 < s := by linarith + rw [Real.log_mul (by positivity) (by positivity), Real.log_pow] + have h1 := Real.log_le_sub_one_of_pos (show 0 < F+2 by linarith) + have h2 := Real.log_le_sub_one_of_pos hs0 + have hs2 : 1 ≤ s^2 := one_le_pow₀ hs + have hss : s ≤ s^2 := by nlinarith + have hnum : Real.log (F+2)+3*Real.log s ≤ (F+5)*s^2 := by + nlinarith [mul_le_mul_of_nonneg_left hs2 hF] + apply (div_le_iff₀ (by positivity : 0 < t*s^3)).mpr + calc + _ ≤ (F+5)*s^2 := by simpa using hnum + _ = _ := by field_simp [ht.ne', hs0.ne'] + +lemma kernelUpperError_le_row {q : ℕ} {R : ℝ} (hR : 0 ≤ R) : + kernelUpperError q R ≤ kernelRowError q R := by + unfold kernelUpperError kernelRowError + apply div_le_div_of_nonneg_right _ hR + have hh := mul_nonneg (inv_nonneg.mpr bumpIntegral_pos.le) (Nat.cast_nonneg (α := ℝ) q) + nlinarith + +lemma kernelUpperError_nonneg (q : ℕ) {R : ℝ} (hR : 0 ≤ R) : + 0 ≤ kernelUpperError q R := by unfold kernelUpperError; positivity + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/UniformKac.lean b/lean/OAI/Probability/RadialTransition/UniformKac.lean new file mode 100644 index 0000000000000000000000000000000000000000..7a76877e4b63a422f0bf88c3edb1acc5a01fece8 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/UniformKac.lean @@ -0,0 +1,143 @@ +import OAI.Probability.RadialTransition.SqrtGrid + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma uniform_kac_parameters {t βlo βhi H A : ℝ} + (ht : 1 ≤ t) (hb : 0 < βlo) (hb' : βlo ≤ βhi) (hH : 0 ≤ H) (hA : 0 ≤ A) + (htA : 6912*A ≤ t) : + ∃ κ D F C : ℝ, 0 < κ ∧ 1 ≤ D ∧ D ≤ F ∧ 0 ≤ C ∧ + ∀ β ∈ Icc βlo βhi, ∀ h ∈ Icc (-H) H, ∀ a ∈ Icc (0:ℝ) A, + (∀ η ∈ Icc (0:ℝ) 1, κ ≤ β*(t^2/3456)-β*t*a*(1+η)/2) ∧ + t*h+β*(t^2/2)+t+1 ≤ κ*D ∧ + Real.exp (β*(t^2/2)+t*(h+β*a*D)+1) ≤ F ∧ + ∀ B ∈ Icc (0:ℝ) A, ∀ v ∈ Icc (0:ℝ) D, + boxPressureConstant t β (h+β*a*v) B ≤ C := by + have ht0 : 0 < t := by linarith + have hb0 : 0 < βhi := hb.trans_le hb' + let κ := βlo*t^2/6912 + have hκ : 0 < κ := by dsimp [κ]; positivity + let D := 1+(t*H+βhi*(t^2/2)+t+1)/κ + have hD : 1 ≤ D := by + have hn : 0 ≤ (t*H+βhi*(t^2/2)+t+1)/κ := by positivity + dsimp [D]; linarith + let F := max D (Real.exp (βhi*(t^2/2)+t*(H+βhi*A*D)+1)) + let C := boxPressureConstant t βhi (H+βhi*A*D) A + refine ⟨κ, D, F, C, hκ, hD, le_max_left _ _, + boxPressureConstant_nonneg ht0.le hb0.le hA, ?_⟩ + intro β hβ h hh a ha + have hβ0 : 0 < β := hb.trans_le hβ.1 + have haA : t*a ≤ t^2/6912 := by + have h1 := mul_le_mul_of_nonneg_left (ha.2.trans (show A ≤ t/6912 by linarith)) ht0.le + nlinarith + have hshift (v : ℝ) (hv : v ∈ Icc (0:ℝ) D) : h+β*a*v ≤ H+βhi*A*D := by + apply add_le_add hh.2 + exact mul_le_mul (mul_le_mul hβ.2 ha.2 ha.1 hb0.le) hv.2 hv.1 (by positivity) + refine ⟨?_, ?_, ?_, ?_⟩ + · intro η hη + have he : t*a*(1+η)/2 ≤ t*a := by + have hta : 0 ≤ t*a := mul_nonneg ht0.le ha.1 + nlinarith [mul_nonneg hta (show 0 ≤ 1-η by linarith [hη.2])] + have h1 := mul_le_mul_of_nonneg_left (he.trans haA) hβ0.le + have h2 := mul_le_mul_of_nonneg_right hβ.1 (show 0 ≤ t^2/6912 by positivity) + dsimp [κ] + nlinarith + · have h1 := add_le_add (mul_le_mul_of_nonneg_left hh.2 ht0.le) + (mul_le_mul_of_nonneg_right hβ.2 (show 0 ≤ t^2/2 by positivity)) + dsimp [D] + have heq : κ*((t*H+βhi*(t^2/2)+t+1)/κ) = t*H+βhi*(t^2/2)+t+1 := by field_simp + nlinarith + · apply le_trans (Real.exp_le_exp.mpr ?_) (le_max_right _ _) + have h1 := mul_le_mul_of_nonneg_right hβ.2 (show 0 ≤ t^2/2 by positivity) + have h2 := mul_le_mul_of_nonneg_left (hshift D ⟨by linarith, le_rfl⟩) ht0.le + linarith + · intro B hB v hv + exact boxPressureConstant_mono ht0 hβ0 hβ.2 (hshift v hv) hB.1 hB.2 + +lemma kac_grid_error_bound {C F t β a βhi A W R₀ R s q : ℝ} + (hC : 0 ≤ C) (hF : 0 ≤ F) (ht : 0 < t) (hb : 0 ≤ βhi) (hA : 0 ≤ A) + (hW : 0 ≤ W) (hpref : β*a/2 ≤ βhi*A/2) + (hs : 0 < s) (hR₀ : 2 ≤ R₀) (hq : 0 ≤ q/R) + (hsratio : R₀/s ≤ 2*Real.sqrt (R₀/R)) (hqratio : q/R ≤ 4*Real.sqrt (R₀/R)) + (hlog : Real.log ((F+2)*s^3)/(t*s^3) ≤ (F+5)/(t*s)) : + 2*C*R₀/s+β*a/2*(W*q/R)*F^2+Real.log ((F+2)*s^3)/(t*s^3) ≤ + 6*(1+2*C+(F+5)/t+βhi*A/2*W*F^2)*Real.sqrt (R₀/R) := by + have hfirst : 2*C*R₀/s ≤ 4*C*Real.sqrt (R₀/R) := by + calc + _ = 2*C*(R₀/s) := by ring + _ ≤ 2*C*(2*Real.sqrt (R₀/R)) := mul_le_mul_of_nonneg_left hsratio (by positivity) + _ = _ := by ring + have hsecond : β*a/2*(W*q/R)*F^2 ≤ 4*(βhi*A/2*W*F^2)*Real.sqrt (R₀/R) := by + have hm := mul_le_mul hpref (mul_le_mul_of_nonneg_left hqratio hW) + (mul_nonneg hW hq) (show 0 ≤ βhi*A/2 by positivity) + calc + _ = β*a/2*(W*(q/R))*F^2 := by ring + _ ≤ βhi*A/2*(W*(4*Real.sqrt (R₀/R)))*F^2 := mul_le_mul_of_nonneg_right hm (sq_nonneg F) + _ = _ := by ring + have hn : 1/s ≤ Real.sqrt (R₀/R) := by + have hm := div_le_div_of_nonneg_right hR₀ hs.le + have heq : 2/s = 2*(1/s) := by ring + rw [heq] at hm + linarith + have hthird : (F+5)/(t*s) ≤ (F+5)/t*Real.sqrt (R₀/R) := by + calc + _ = (F+5)/t*(1/s) := by ring + _ ≤ _ := mul_le_mul_of_nonneg_left hn (by positivity) + have hz := Real.sqrt_nonneg (R₀/R) + have h1 := mul_nonneg hC hz + have h2 := mul_nonneg (show 0 ≤ (F+5)/t by positivity) hz + have h3 := mul_nonneg (show 0 ≤ βhi*A/2*W*F^2 by positivity) hz + nlinarith only [hfirst, hsecond, hlog, hthird, hz, h1, h2, h3] + +lemma family_kac_uniform {t βlo βhi H A : ℝ} + (ht : 1 ≤ t) (hb : 0 < βlo) (hb' : βlo ≤ βhi) (hH : 0 ≤ H) (hA : 0 ≤ A) + (htA : 6912*A ≤ t) : + ∃ C K : ℝ, 0 < C ∧ 1 ≤ K ∧ + ∀ (b S : ℕ → ℝ) (a R₀ R β h : ℝ), + (∀ n, 0 ≤ b n) → (∀ n, 1 ≤ S n) → Summable b → + 2 ≤ R₀ → (∀ n, S n ≤ R₀) → 0 ≤ a → a+∑' n, b n ≤ A → + 2197*t*bumpIntegral⁻¹*(a+∑' n, b n) ≤ (t^2/8)/8 → + K*R₀ ≤ R → β ∈ Icc βlo βhi → h ∈ Icc (-H) H → + |grandPressure (familyPotential t (prepend a b) (prepend R S)) t β h- + idealAttraction (grandPressure (familyPotential t b S) t) a β h| ≤ + C*Real.sqrt (R₀/R) := by + obtain ⟨κ, D, F, C, hκ, hD, hDF, hC0, hc⟩ := uniform_kac_parameters ht hb hb' hH hA htA + let W := 10000*(bumpLip:ℝ)+bumpIntegral⁻¹ + have hW : 0 ≤ W := by dsimp [W]; have := bumpIntegral_pos; positivity + let K := 16*(W+1)^2 + have hK : 1 ≤ K := by dsimp [K]; nlinarith [sq_nonneg W] + let E := 1+2*C+(F+5)/t+βhi*A/2*W*F^2 + have ht0 : 0 < t := by linarith + have hF0 : 0 ≤ F := by linarith + have hb0 : 0 < βhi := hb.trans_le hb' + have hE : 0 < E := by dsimp [E]; positivity + refine ⟨6*E, K, by positivity, hK, ?_⟩ + intro b S a R₀ R β h hbn hS hs hR₀ hrange ha hmass hrow hRR hβ hh + have hsum : 0 ≤ ∑' n, b n := tsum_nonneg hbn + have haA : a ∈ Icc (0:ℝ) A := ⟨ha, by linarith⟩ + have hBA : (∑' n, b n) ∈ Icc (0:ℝ) A := ⟨hsum, by linarith⟩ + obtain ⟨hq, hqpos, hq1, hqR, hRq, hqfrac, hη⟩ := sqrt_grid_exists hR₀ hW hRR + have hR0 : 0 < R := by linarith + have heq : kernelRowError hq R = W*(hq:ℝ)/R := rfl + have heta : kernelUpperError hq R ≤ 1 := (kernelUpperError_le_row hR0.le).trans (heq ▸ hη) + obtain ⟨hcoerc, hcut, hF, hC⟩ := hc β hβ h hh a haA + have hbound := family_kac_variational_grid hqpos ht (hb.trans_le hβ.1) ha hqR hq1 + hbn hS hs hR₀ hrange hrow hκ (hcoerc _ ⟨kernelUpperError_nonneg hq hR0.le, heta⟩) + hD hcut hDF hF (hC _ hBA) + apply hbound.trans + have hlog := log_volume_error_le hF0 hq1 ht0 + have hbA : β*a/2 ≤ βhi*A/2 := by + exact div_le_div_of_nonneg_right (mul_le_mul hβ.2 haA.2 ha hb0.le) (by norm_num) + have hs0 : 0 < (hq:ℝ)/4 := by linarith + rw [heq] + exact kac_grid_error_bound hC0 hF0 ht0 hb0.le hA hW hbA hs0 hR₀ + (div_nonneg (Nat.cast_nonneg hq) hR0.le) hRq hqfrac hlog + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RadialTransition/WindowLipschitz.lean b/lean/OAI/Probability/RadialTransition/WindowLipschitz.lean new file mode 100644 index 0000000000000000000000000000000000000000..596646fedaf0164ad1cad42486ef6b7a83d131e5 --- /dev/null +++ b/lean/OAI/Probability/RadialTransition/WindowLipschitz.lean @@ -0,0 +1,46 @@ +import OAI.Probability.RadialTransition.ParameterTools + +namespace OAI + +noncomputable section +open scoped BigOperators ENNReal NNReal +open MeasureTheory Set Filter +namespace RadialTransition + +lemma window_lipschitz {Q : Pressure} {M : ℝ} (hM : 0 ≤ M) + (hQ : ConvexOn ℝ positiveParameters (onParameters Q)) + (hbound : ∀ x ∈ phaseWindow (1/2), |onParameters Q x| ≤ M) : + ∀ x ∈ phaseWindow (1/4), ∀ y ∈ phaseWindow (1/4), + |onParameters Q x-onParameters Q y| ≤ 8*M*dist x y := by + have hnorm (x : Parameter) (hx : x ∈ phaseWindow (1/4)) (v : Parameter) + (hv : v ∈ supportSet (onParameters Q) positiveParameters x) : ‖v‖ ≤ 8*M := by + have hball : Metric.closedBall x (1/4) ⊆ phaseWindow (1/2) := by + intro y hy + convert phaseWindow_near hx hy using 1 + norm_num + have hh := support_norm_bound (by norm_num : (0:ℝ)<1/4) hM + (fun y hy => phaseWindow_positive (by norm_num : (1/2:ℝ)<1) (hball hy)) + (fun y hy => hbound y (hball hy)) hv + linarith + have hone (x : Parameter) (hx : x ∈ phaseWindow (1/4)) (y : Parameter) + (hy : y ∈ phaseWindow (1/4)) : onParameters Q x-onParameters Q y ≤ 8*M*dist x y := by + have hx' := phaseWindow_positive (by norm_num : (1/4:ℝ)<1) hx + have hy' := phaseWindow_positive (by norm_num : (1/4:ℝ)<1) hy + obtain ⟨v,hv⟩ := supportSet_nonempty isOpen_positiveParameters hQ hx' + have hs := hv y hy' + have hn := hnorm x hx v hv + have hh := (real_inner_le_norm v (x-y)).trans (mul_le_mul_of_nonneg_right hn (norm_nonneg _)) + have he : inner ℝ v (x-y) = -inner ℝ v (y-x) := by rw [← inner_neg_right, neg_sub] + rw [he,← dist_eq_norm] at hh + linarith + intro x hx y hy + rw [abs_le] + have ha := hone x hx y hy + have hb := hone y hy x hx + rw [dist_comm y] at hb + constructor <;> linarith + +end RadialTransition +end + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Binomial.lean b/lean/OAI/Probability/RandomSAT/Binomial.lean new file mode 100644 index 0000000000000000000000000000000000000000..ea2201d719f3c3c31a3c01022c2d03497a1a21b1 --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Binomial.lean @@ -0,0 +1,184 @@ +import OAI.Probability.RandomSAT.ClauseProcess + +namespace OAI + +/-! +Finite Bernoulli-count expectations and integrated telescoping estimates. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +def binomialMean (p : ℝ) : ℕ → (ℕ → ℝ) → ℝ + | 0, f => f 0 + | m + 1, f => (1 - p) * binomialMean p m f + + p * binomialMean p m (fun d => f (d + 1)) + +theorem binomialMean_congr {p : ℝ} {m : ℕ} {f g : ℕ → ℝ} + (h : ∀ d ≤ m, f d = g d) : binomialMean p m f = binomialMean p m g := by + induction m generalizing f g with + | zero => exact h 0 (by omega) + | succ m ih => + simp only [binomialMean] + rw [ih (fun d hd => h d (by omega)), ih (fun d hd => h (d + 1) (by omega))] + +theorem binomialMean_const (p c : ℝ) (m : ℕ) : binomialMean p m (fun _ => c) = c := by + induction m with + | zero => rfl + | succ m ih => simp only [binomialMean, ih]; ring + +theorem binomialMean_add (p : ℝ) (m : ℕ) (f g : ℕ → ℝ) : + binomialMean p m (fun d => f d + g d) = binomialMean p m f + binomialMean p m g := by + induction m generalizing f g with + | zero => rfl + | succ m ih => simp only [binomialMean, ih]; ring + +theorem binomialMean_sub (p : ℝ) (m : ℕ) (f g : ℕ → ℝ) : + binomialMean p m (fun d => f d - g d) = binomialMean p m f - binomialMean p m g := by + induction m generalizing f g with + | zero => rfl + | succ m ih => simp only [binomialMean, ih]; ring + +theorem binomialMean_mul_const (p c : ℝ) (m : ℕ) (f : ℕ → ℝ) : + binomialMean p m (fun d => f d * c) = binomialMean p m f * c := by + induction m generalizing f with + | zero => rfl + | succ m ih => simp only [binomialMean, ih]; ring + +theorem binomialMean_const_mul (p c : ℝ) (m : ℕ) (f : ℕ → ℝ) : + binomialMean p m (fun d => c * f d) = c * binomialMean p m f := by + simpa only [mul_comm] using binomialMean_mul_const p c m f + +theorem binomialMean_sum {ι : Type*} (p : ℝ) (m : ℕ) (s : Finset ι) (f : ι → ℕ → ℝ) : + binomialMean p m (fun d => ∑ i ∈ s, f i d) = ∑ i ∈ s, binomialMean p m (f i) := by + induction s using Finset.induction_on with + | empty => simp [binomialMean_const] + | @insert i s hi ih => + simp only [Finset.sum_insert hi, binomialMean_add, ih] + +theorem binomialMean_mono {p : ℝ} {m : ℕ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + {f g : ℕ → ℝ} (h : ∀ d ≤ m, f d ≤ g d) : binomialMean p m f ≤ binomialMean p m g := by + induction m generalizing f g with + | zero => exact h 0 (by omega) + | succ m ih => + exact add_le_add + (mul_le_mul_of_nonneg_left (ih (fun d hd => h d (by omega))) (sub_nonneg.mpr hp1)) + (mul_le_mul_of_nonneg_left (ih (fun d hd => h (d + 1) (by omega))) hp0) + +theorem binomialMean_nonneg {p : ℝ} {m : ℕ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + {f : ℕ → ℝ} (h : ∀ d ≤ m, 0 ≤ f d) : 0 ≤ binomialMean p m f := by + simpa only [binomialMean_const] using binomialMean_mono hp0 hp1 h + +theorem binomialMean_id (p : ℝ) (m : ℕ) : + binomialMean p m (fun d => (d : ℝ)) = (m : ℝ) * p := by + induction m with + | zero => simp [binomialMean] + | succ m ih => + simp only [binomialMean, Nat.cast_add, Nat.cast_one, binomialMean_add, + binomialMean_const, ih] + ring + +theorem binomialMean_monotone_trials {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + {f : ℕ → ℝ} (hf : Monotone f) : Monotone (fun m => binomialMean p m f) := by + apply monotone_nat_of_le_succ + intro m + have h := binomialMean_mono (m := m) hp0 hp1 (f := f) (g := fun d => f (d + 1)) + (fun d _ => hf (by omega)) + change _ ≤ (1 - p) * _ + p * _ + nlinarith + +theorem uniformMean_binomialMean {α : Type*} [Fintype α] + (p : ℝ) (m : ℕ) (f : ℕ → α → ℝ) : + uniformMean (fun a => binomialMean p m (fun d => f d a)) = + binomialMean p m (fun d => uniformMean (f d)) := by + induction m generalizing f with + | zero => rfl + | succ m ih => + simp only [binomialMean, uniformMean_add, uniformMean_const_mul, ih] + +theorem sum_shift_difference_le (P : ℕ → ℝ) (hP0 : ∀ j, 0 ≤ P j) + (hP1 : ∀ j, P j ≤ 1) (l b : ℕ) : + ∑ j ∈ Finset.range l, (P j - P (j + b)) ≤ (b : ℝ) := by + have h1 := Finset.sum_range_add P l b + have h2 := Finset.sum_range_add P b l + have hid : (∑ j ∈ Finset.range l, (P j - P (j + b))) = + ∑ j ∈ Finset.range b, (P j - P (j + l)) := by + rw [Finset.sum_sub_distrib, Finset.sum_sub_distrib] + have hc : l + b = b + l := Nat.add_comm _ _ + simp only [Nat.add_comm l] at h1 + simp only [Nat.add_comm b] at h2 + rw [hc] at h2 + linarith + rw [hid] + calc + _ ≤ ∑ _j ∈ Finset.range b, (1 : ℝ) := by + apply Finset.sum_le_sum + intro j _ + linarith [hP0 (j + l), hP1 j] + _ = b := by simp + +theorem sum_two_shift_difference_le (P : ℕ → ℝ) (hP0 : ∀ j, 0 ≤ P j) + (hP1 : ∀ j, P j ≤ 1) (l a b : ℕ) : + ∑ j ∈ Finset.range l, (P (j - a) - P (j + b)) ≤ (a : ℝ) + b := by + have h1 := sum_shift_difference_le (fun j => P (j - a)) + (fun j => hP0 _) (fun j => hP1 _) l a + simp only [Nat.add_sub_cancel] at h1 + have h2 := sum_shift_difference_le P hP0 hP1 l b + have he : (∑ j ∈ Finset.range l, (P (j - a) - P (j + b))) = + (∑ j ∈ Finset.range l, (P (j - a) - P j)) + + ∑ j ∈ Finset.range l, (P j - P (j + b)) := by + rw [← Finset.sum_add_distrib] + apply Finset.sum_congr rfl + intro j _ + ring + rw [he] + linarith + +def replacementDifference (P : ℕ → ℝ) (g j d : ℕ) : ℝ := + P (j - d) - P (j + (g - 1) * d) + +theorem replacementDifference_mono {P : ℕ → ℝ} (hP : Antitone P) (g j : ℕ) : + Monotone (replacementDifference P g j) := by + intro d e hde + apply sub_le_sub + · exact hP (Nat.sub_le_sub_left hde j) + · exact hP (Nat.add_le_add_left (Nat.mul_le_mul_left _ hde) j) + +theorem replacementDifference_sum_le {P : ℕ → ℝ} + (hP0 : ∀ j, 0 ≤ P j) (hP1 : ∀ j, P j ≤ 1) {g : ℕ} (hg : 1 ≤ g) (l d : ℕ) : + ∑ j ∈ Finset.range l, replacementDifference P g j d ≤ (g : ℝ) * d := by + have h := sum_two_shift_difference_le P hP0 hP1 l d ((g - 1) * d) + have he : (d : ℝ) + ((g - 1) * d : ℕ) = (g : ℝ) * d := by + rw [Nat.cast_mul, Nat.cast_sub hg] + push_cast + ring + simpa only [replacementDifference, he] using h + +theorem binomial_replacement_sum_le {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + {P : ℕ → ℝ} (hP : Antitone P) (hP0 : ∀ j, 0 ≤ P j) (hP1 : ∀ j, P j ≤ 1) + {g : ℕ} (hg : 1 ≤ g) (M : ℕ) : + ∑ j ∈ Finset.range (M + 1), binomialMean p j (replacementDifference P g j) ≤ + (g : ℝ) * (M : ℝ) * p := by + calc + _ ≤ ∑ j ∈ Finset.range (M + 1), binomialMean p M (replacementDifference P g j) := by + apply Finset.sum_le_sum + intro j hj + have hjM : j ≤ M := by simpa only [Finset.mem_range, Nat.lt_succ_iff] using hj + exact binomialMean_monotone_trials hp0 hp1 (replacementDifference_mono hP g j) hjM + _ = binomialMean p M (fun d => ∑ j ∈ Finset.range (M + 1), + replacementDifference P g j d) := (binomialMean_sum _ _ _ _).symm + _ ≤ binomialMean p M (fun d => (g : ℝ) * d) := + binomialMean_mono hp0 hp1 (fun d _ => replacementDifference_sum_le hP0 hP1 hg _ d) + _ = _ := by rw [binomialMean_const_mul, binomialMean_id]; ring + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/CenterBounds.lean b/lean/OAI/Probability/RandomSAT/CenterBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..a3a8112c2a369be05fa7118725bccdf6d9b9c3fd --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/CenterBounds.lean @@ -0,0 +1,521 @@ +import OAI.Probability.RandomSAT.Concentration + +namespace OAI + +/-! +Finite union bounds, a matching criterion for satisfiability, and positive finite +bounds for the normalized centers. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +theorem uniformProbability_exists_le {α β : Type*} [Fintype α] [Fintype β] + (p : α → β → Prop) : + uniformProbability (fun a => ∃ b, p a b) ≤ ∑ b, uniformProbability (fun a => p a b) := by + simp only [uniformProbability_eq_mean] + rw [← uniformMean_sum] + apply uniformMean_mono + intro a + by_cases h : ∃ b, p a b + · obtain ⟨b, hb⟩ := h + rw [ite_eq_left ⟨b, hb⟩] + calc + 1 = (if p a b then (1 : ℝ) else 0) := (ite_eq_left hb).symm + _ ≤ ∑ b, if p a b then (1 : ℝ) else 0 := + Finset.single_le_sum (f := fun b => if p a b then (1 : ℝ) else 0) + (fun b _ => by split_ifs <;> norm_num) (Finset.mem_univ b) + · rw [ite_eq_right h] + exact Finset.sum_nonneg (fun b _ => by split_ifs <;> norm_num) + +theorem uniformProbability_forall_fintype {α β : Type*} [Fintype α] [Fintype β] [DecidableEq β] + (p : α → Prop) : + uniformProbability (fun f : β → α => ∀ b, p (f b)) = uniformProbability p ^ Fintype.card β := by + unfold uniformProbability + have hc : Fintype.card {f : β → α // ∀ b, p (f b)} = + Fintype.card (β → {a : α // p a}) := + Fintype.card_congr (Equiv.subtypePiEquivPi (p := fun _ : β => p)) + simp only [← Nat.card_eq_fintype_card] at hc ⊢ + rw [hc] + simp only [Nat.card_eq_fintype_card, Fintype.card_fun, Nat.cast_pow, div_pow] + +@[simp] theorem forcedVariables_singleton {n : ℕ} (σ : Assignment n) : + forcedVariables ({σ} : Finset (Assignment n)) = Finset.univ := by + ext i + simp [forcedVariables] + +theorem randomClause_satisfies {n k : ℕ} (hkn : k ≤ n) (σ : Assignment n) : + uniformProbability (fun C : ProperClause n k => SatisfiesClause σ C) = 1 - (2 : ℝ)⁻¹ ^ k := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + have h := killingProbability_of_nonempty (k := k) {σ} (Finset.singleton_nonempty σ) + have hc : (n.choose k : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt (Nat.choose_pos hkn) + have hp : killingProbability k {σ} = + uniformProbability (fun C : ProperClause n k => ¬SatisfiesClause σ C) := by + apply uniformProbability_congr + intro C + simp [KillsSolutions] + rw [hp, uniformProbability_not, forcedVariables_singleton, Finset.card_univ, Fintype.card_fin] at h + have hr : (n.choose k : ℝ) / ((n.choose k : ℝ) * 2^k) = (2 : ℝ)⁻¹ ^ k := by + rw [inv_pow] + field_simp + rw [hr] at h + linarith + +theorem first_moment_bound {n k m : ℕ} (hkn : k ≤ n) : + properSATProbability n k m ≤ (2 : ℝ)^n * (1 - (2 : ℝ)⁻¹ ^ k)^m := by + change uniformProbability (fun F : Formula n k m => ∃ σ, Satisfies σ F) ≤ _ + have h := uniformProbability_exists_le (fun F : Formula n k m => fun σ => Satisfies σ F) + have hσ (σ : Assignment n) : + uniformProbability (fun F : Formula n k m => Satisfies σ F) = + (1 - (2 : ℝ)⁻¹ ^ k)^m := by + change uniformProbability (fun F : Formula n k m => ∀ j, SatisfiesClause σ (F j)) = _ + rw [uniformProbability_forall, randomClause_satisfies hkn] + simp only [hσ, Finset.sum_const, Finset.card_univ, Fintype.card_fun, Fintype.card_bool, + Fintype.card_fin, nsmul_eq_mul, Nat.cast_pow, Nat.cast_ofNat] at h + exact h + +theorem uniformMean_lower_tail {α : Type*} [Fintype α] (f : α → ℝ) + (hf : ∀ a, 0 ≤ f a) {t : ℝ} (_ht : 0 ≤ t) : + t * uniformProbability (fun a => t ≤ f a) ≤ uniformMean f := by + rw [uniformProbability_eq_mean, ← uniformMean_const_mul] + apply uniformMean_mono + intro a + by_cases h : t ≤ f a + · simpa only [ite_eq_left h, mul_one] using h + · simpa only [ite_eq_right h, mul_zero] using hf a + +theorem uniformMean_upper_cutoff {α : Type*} [Fintype α] [Nonempty α] + (f : α → ℝ) {M t : ℝ} (hf : ∀ a, f a ≤ M) (ht : 0 ≤ t) : + uniformMean f ≤ t + M * uniformProbability (fun a => t ≤ f a) := by + calc + _ ≤ uniformMean (fun a => t + M * if t ≤ f a then (1 : ℝ) else 0) := by + apply uniformMean_mono + intro a + by_cases h : t ≤ f a + · simp only [ite_eq_left h, mul_one] + linarith [hf a] + · simp only [ite_eq_right h, mul_zero, add_zero] + exact le_of_not_ge h + _ = _ := by rw [uniformMean_add, uniformMean_const, uniformMean_const_mul, + ← uniformProbability_eq_mean] + +theorem center_lower_by_probability {n k m : ℕ} (hkn : k ≤ n) (hm : m ≤ mainCap n k) : + (m : ℝ) / n * properSATProbability n k m ≤ center n k := by + have h := uniformMean_lower_tail (lifetime k (mainCap n k) (Finset.univ : Finset (Assignment n))) + (fun F => lifetime_nonneg _ F) (show 0 ≤ (m : ℝ) by positivity) + rw [← properSATProbability_eq_lifetime_tail hkn hm] at h + unfold center lifetimeMean + have hh := div_le_div_of_nonneg_right h (Nat.cast_nonneg n : (0 : ℝ) ≤ n) + simpa only [div_mul_eq_mul_div] using hh + +theorem center_upper_by_probability {n k m : ℕ} (hkn : k ≤ n) (hn : 0 < n) + (hm : m ≤ mainCap n k) : + center n k ≤ (m : ℝ) / n + capMultiplier k * properSATProbability n k m := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + have h := uniformMean_upper_cutoff (lifetime k (mainCap n k) (Finset.univ : Finset (Assignment n))) + (fun F => lifetime_le _ F) (show 0 ≤ (m : ℝ) by positivity) + rw [← properSATProbability_eq_lifetime_tail hkn hm] at h + unfold center lifetimeMean + have hh := div_le_div_of_nonneg_right h (Nat.cast_nonneg n : (0 : ℝ) ≤ n) + apply hh.trans_eq + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn + simp only [mainCap, Nat.cast_mul] + field_simp + +theorem satisfiable_of_matching {n k m : ℕ} (F : Formula n k m) + (f : Fin m → Fin n) (hf : Function.Injective f) + (hmem : ∀ j, f j ∈ clauseSupport (F j)) : Satisfiable F := by + let b : Fin m → Bool := fun j => ((F j).val (f j)).getD false + let σ : Assignment n := fun i => if h : ∃ j, f j = i then b (Classical.choose h) else false + refine ⟨σ, fun j => ⟨f j, ?_⟩⟩ + have he : ∃ j', f j' = f j := ⟨j, rfl⟩ + have hc : Classical.choose he = j := hf (Classical.choose_spec he) + have hs : σ (f j) = b j := by simp [σ, he, hc] + rw [hs] + obtain ⟨v, hv⟩ := Option.isSome_iff_exists.mp ((mem_clauseSupport _ _).mp (hmem j)) + simp [b, hv] + +theorem unsatisfiable_deficiency {n k m : ℕ} (F : Formula n k m) (hF : ¬Satisfiable F) : + ∃ J : Finset (Fin m), (J.biUnion fun j => clauseSupport (F j)).card < J.card := by + by_contra h + push Not at h + obtain ⟨f, hf, hmem⟩ := + (Finset.all_card_le_biUnion_card_iff_exists_injective (fun j => clauseSupport (F j))).mp h + exact hF (satisfiable_of_matching F f hf hmem) + +def firstMomentBase : ℝ := 2 * Real.exp (-1) + +theorem firstMomentBase_nonneg : 0 ≤ firstMomentBase := by + unfold firstMomentBase + positivity + +theorem firstMomentBase_lt_one : firstMomentBase < 1 := by + rw [firstMomentBase, Real.exp_neg] + have h : (2 : ℝ) < Real.exp 1 := by + have := Real.add_one_lt_exp (by norm_num : (1 : ℝ) ≠ 0) + linarith + exact (mul_inv_lt_iff₀ (Real.exp_pos 1)).mpr (by simpa using h) + +theorem first_moment_linear {n k : ℕ} (hkn : k ≤ n) : + properSATProbability n k (2^k * n) ≤ firstMomentBase^n := by + apply (first_moment_bound hkn).trans + have hq : 0 ≤ 1 - (2 : ℝ)⁻¹^k := by + have := pow_le_one₀ (by norm_num : 0 ≤ (2 : ℝ)⁻¹) (by norm_num : (2 : ℝ)⁻¹ ≤ 1) (n := k) + linarith + have hp := pow_le_pow_left₀ hq (Real.one_sub_le_exp_neg ((2 : ℝ)⁻¹^k)) (2^k * n) + have he : Real.exp (-((2 : ℝ)⁻¹^k))^(2^k * n) = Real.exp (-1)^n := by + rw [← Real.exp_nat_mul, ← Real.exp_nat_mul] + congr 1 + push_cast + rw [inv_pow] + have hk : (2 : ℝ)^k ≠ 0 := by positivity + field_simp + rw [he] at hp + simpa only [firstMomentBase, mul_pow] using mul_le_mul_of_nonneg_left hp (by positivity : (0 : ℝ) ≤ 2^n) + +theorem center_first_moment {n k : ℕ} (hkn : k ≤ n) (hn : 0 < n) : + center n k ≤ (2 : ℝ)^k + capMultiplier k * firstMomentBase^n := by + have hm : 2^k * n ≤ mainCap n k := by + dsimp [mainCap, capMultiplier] + gcongr + omega + have h := center_upper_by_probability hkn hn hm + have he : ((2^k * n : ℕ) : ℝ) / n = (2 : ℝ)^k := by + push_cast + exact mul_div_cancel_right₀ _ (by exact_mod_cast Nat.ne_of_gt hn) + rw [he] at h + exact h.trans (add_le_add_right (mul_le_mul_of_nonneg_left (first_moment_linear hkn) + (Nat.cast_nonneg (capMultiplier k) : (0 : ℝ) ≤ capMultiplier k)) _) + +theorem uniformProbability_equiv {α β : Type*} [Fintype α] [Fintype β] + (e : α ≃ β) (p : β → Prop) : + uniformProbability (fun a => p (e a)) = uniformProbability p := by + unfold uniformProbability + rw [Fintype.card_congr (Equiv.subtypeEquiv e (fun _ => Iff.rfl)), Fintype.card_congr e] + +theorem uniformProbability_prod_first {α β : Type*} [Fintype α] [Fintype β] [Nonempty β] + (p : α → Prop) : uniformProbability (fun x : α × β => p x.1) = uniformProbability p := by + let e : {x : α × β // p x.1} ≃ {a : α // p a} × β := { + toFun := fun x => (⟨x.val.1, x.property⟩, x.val.2) + invFun := fun x => ⟨(x.1.val, x.2), x.1.property⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + unfold uniformProbability + simp only [← Nat.card_eq_fintype_card] + rw [Nat.card_congr e, Nat.card_prod, Nat.card_prod, Nat.cast_mul, Nat.cast_mul] + have hb : (Nat.card β : ℝ) ≠ 0 := by + rw [Nat.card_eq_fintype_card] + exact_mod_cast Fintype.card_ne_zero (α := β) + field_simp + +theorem uniformProbability_forall_mem {α β : Type*} [Fintype α] [Nonempty α] [Fintype β] [DecidableEq β] + (J : Finset β) (p : α → Prop) : + uniformProbability (fun f : β → α => ∀ j ∈ J, p (f j)) = uniformProbability p ^ J.card := by + let e := Equiv.piEquivPiSubtypeProd (fun j => j ∈ J) (fun _ : β => α) + calc + _ = uniformProbability (fun f : β → α => ∀ j : ↥J, p ((e f).1 j)) := + uniformProbability_congr (fun f => by simp [e]) + _ = uniformProbability (fun f : (↥J → α) × ({j : β // j ∉ J} → α) => + ∀ j, p (f.1 j)) := uniformProbability_equiv + (α := β → α) (β := (↥J → α) × ({j : β // j ∉ J} → α)) e + (fun f => ∀ j, p (f.1 j)) + _ = uniformProbability (fun f : ↥J → α => ∀ j, p (f j)) := + uniformProbability_prod_first (α := ↥J → α) (β := {j : β // j ∉ J} → α) + (fun f : ↥J → α => ∀ j, p (f j)) + _ = _ := by + have h := uniformProbability_forall_fintype (α := α) (β := ↥J) p + simpa only [Fintype.card_coe] using h + +theorem uniformMean_support {n k : ℕ} (f : Finset (Fin n) → ℝ) : + uniformMean (fun C : ProperClause n k => f (clauseSupport C)) = + uniformMean (fun s : VariableSet n k => f s.val) := by + have he := uniformMean_equiv (properClauseEquiv n k) (fun s => f s.1.val) + change uniformMean (fun C : ProperClause n k => f (clauseSupport C)) = _ at he + rw [he] + have hc (s : VariableSet n k) : Fintype.card (↥s.val → Bool) = 2^k := by + simp [(Finset.mem_powersetCard.mp s.property).2] + simp only [uniformMean, Fintype.sum_sigma, Finset.sum_const, Finset.card_univ, + nsmul_eq_mul, Fintype.card_sigma, hc, Nat.cast_mul, Nat.cast_pow, Nat.cast_ofNat] + rw [← Finset.mul_sum] + have h2 : (2 : ℝ)^k ≠ 0 := by positivity + push_cast + field_simp + +theorem uniformProbability_support_subset {n k : ℕ} (T : Finset (Fin n)) : + uniformProbability (fun C : ProperClause n k => clauseSupport C ⊆ T) = + (T.card.choose k : ℝ) / n.choose k := by + have hm := uniformMean_support (k := k) (fun S => if S ⊆ T then (1 : ℝ) else 0) + have hp : uniformProbability (fun C : ProperClause n k => clauseSupport C ⊆ T) = + uniformProbability (fun s : VariableSet n k => s.val ⊆ T) := by + rw [uniformProbability_eq_mean, uniformProbability_eq_mean] + calc + _ = uniformMean (fun C : ProperClause n k => + if clauseSupport C ⊆ T then (1 : ℝ) else 0) := by + apply uniformMean_congr + intro C + by_cases h : clauseSupport C ⊆ T <;> simp only [h, ite_true, ite_false] + _ = _ := hm + _ = _ := by + apply uniformMean_congr + intro C + by_cases h : C.val ⊆ T <;> simp only [h, ite_true, ite_false] + rw [hp] + let e : {s : VariableSet n k // s.val ⊆ T} ≃ ↥(T.powersetCard k) := { + toFun := fun s => ⟨s.val.val, Finset.mem_powersetCard.mpr + ⟨s.property, (Finset.mem_powersetCard.mp s.val.property).2⟩⟩ + invFun := fun s => ⟨⟨s.val, Finset.mem_powersetCard.mpr + ⟨Finset.subset_univ _, (Finset.mem_powersetCard.mp s.property).2⟩⟩, + (Finset.mem_powersetCard.mp s.property).1⟩ + left_inv := fun _ => rfl + right_inv := fun _ => rfl } + unfold uniformProbability + simp only [← Nat.card_eq_fintype_card] + rw [Nat.card_congr e] + simp only [Nat.card_eq_fintype_card, Fintype.card_coe, Finset.card_powersetCard, Finset.card_univ, Fintype.card_fin] + +theorem choose_quotient_le_pow {b n k : ℕ} (hbn : b ≤ n) (hkn : k ≤ n) (hn : 0 < n) : + (b.choose k : ℝ) / n.choose k ≤ ((b : ℝ) / n)^k := by + have h := mul_le_mul_of_nonneg_right (killFraction_le_pow hbn hkn hn) + (by positivity : (0 : ℝ) ≤ 2^k) + have h2 : (2 : ℝ)^k ≠ 0 := by positivity + calc + _ = killFraction b n k * 2^k := by + unfold killFraction + field_simp + _ ≤ ((b : ℝ) / (2 * n))^k * 2^k := h + _ = _ := by + rw [← mul_pow] + congr 1 + field_simp + +theorem clause_subset_bound {n k : ℕ} (hkn : k ≤ n) (hn : 0 < n) (T : Finset (Fin n)) : + uniformProbability (fun C : ProperClause n k => clauseSupport C ⊆ T) ≤ + ((T.card : ℝ) / n)^k := by + rw [uniformProbability_support_subset] + exact choose_quotient_le_pow (by simpa using Finset.card_le_univ T) hkn hn + +theorem unsatisfiable_container {n k m : ℕ} (hmn : m ≤ n) (F : Formula n k m) + (hF : ¬Satisfiable F) : + ∃ t : Fin m, ∃ J : VariableSet m (t.val + 1), ∃ T : VariableSet n (t.val + 1), + ∀ j ∈ J.val, clauseSupport (F j) ⊆ T.val := by + obtain ⟨J, hdef⟩ := unsatisfiable_deficiency F hF + have ht : 0 < J.card := lt_of_le_of_lt (Nat.zero_le _) hdef + have htm : J.card ≤ m := by simpa using Finset.card_le_univ J + obtain ⟨T, hUT, _, hT⟩ := Finset.exists_subsuperset_card_eq + (Finset.subset_univ (J.biUnion fun j => clauseSupport (F j))) hdef.le + (show J.card ≤ (Finset.univ : Finset (Fin n)).card by simpa using htm.trans hmn) + have hts : J.card - 1 + 1 = J.card := Nat.sub_add_cancel ht + refine ⟨⟨J.card - 1, by omega⟩, + ⟨J, Finset.mem_powersetCard.mpr ⟨Finset.subset_univ _, hts.symm⟩⟩, + ⟨T, Finset.mem_powersetCard.mpr ⟨Finset.subset_univ _, hT.trans hts.symm⟩⟩, ?_⟩ + intro j hj i hi + exact hUT (Finset.mem_biUnion.mpr ⟨j, hj, hi⟩) + +theorem deficiency_union_bound {n k m : ℕ} (hkn : k ≤ n) (hn : 0 < n) (hmn : m ≤ n) : + 1 - properSATProbability n k m ≤ + ∑ t ∈ Finset.range m, (m.choose (t + 1) : ℝ) * n.choose (t + 1) * + (((t + 1 : ℕ) : ℝ) / n)^(k * (t + 1)) := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + let E (F : Formula n k m) (t : Fin m) (J : VariableSet m (t.val + 1)) + (T : VariableSet n (t.val + 1)) : Prop := ∀ j ∈ J.val, clauseSupport (F j) ⊆ T.val + have hsat : 1 - properSATProbability n k m = + uniformProbability (fun F : Formula n k m => ¬Satisfiable F) := + (uniformProbability_not (fun F : Formula n k m => Satisfiable F)).symm + have hE (t : Fin m) (J : VariableSet m (t.val + 1)) (T : VariableSet n (t.val + 1)) : + uniformProbability (fun F : Formula n k m => E F t J T) ≤ + (((t.val + 1 : ℕ) : ℝ) / n)^(k * (t.val + 1)) := by + dsimp [E] + rw [uniformProbability_forall_mem (α := ProperClause n k) (β := Fin m) J.val + (fun C => clauseSupport C ⊆ T.val)] + have ht := (Finset.mem_powersetCard.mp T.property).2 + have hj := (Finset.mem_powersetCard.mp J.property).2 + rw [hj] + have h := pow_le_pow_left₀ (uniformProbability_nonneg _) + (clause_subset_bound hkn hn T.val) (t.val + 1) + rwa [ht, ← pow_mul] at h + rw [hsat] + calc + _ ≤ uniformProbability (fun F : Formula n k m => ∃ t, ∃ J, ∃ T, E F t J T) := + uniformProbability_mono (fun F hF => unsatisfiable_container hmn F hF) + _ ≤ ∑ t : Fin m, uniformProbability (fun F : Formula n k m => ∃ J, ∃ T, E F t J T) := + uniformProbability_exists_le _ + _ ≤ ∑ t : Fin m, ∑ J : VariableSet m (t.val + 1), + ∑ T : VariableSet n (t.val + 1), + uniformProbability (fun F : Formula n k m => E F t J T) := by + apply Finset.sum_le_sum + intro t _ + apply (uniformProbability_exists_le _).trans + apply Finset.sum_le_sum + intro J _ + exact uniformProbability_exists_le _ + _ ≤ ∑ t : Fin m, ∑ _ : VariableSet m (t.val + 1), ∑ _ : VariableSet n (t.val + 1), + (((t.val + 1 : ℕ) : ℝ) / n)^(k * (t.val + 1)) := by + gcongr with t _ J _ T _ + exact hE t J T + _ = _ := by + simp only [Finset.sum_const, Finset.card_univ, card_variableSet, nsmul_eq_mul] + simp only [← mul_assoc] + exact Fin.sum_univ_eq_sum_range (fun t => (m.choose (t+1) : ℝ) * n.choose (t+1) * + (((t+1 : ℕ) : ℝ) / n)^(k*(t+1))) m + +theorem choose_exp_bound (N t : ℕ) (ht : 0 < t) : + (N.choose t : ℝ) ≤ (Real.exp 1 * N / t)^t := by + have ht0 : (0 : ℝ) < t := by exact_mod_cast ht + have hf0 : (0 : ℝ) < t.factorial := by exact_mod_cast Nat.factorial_pos t + have he : (t : ℝ)^t / t.factorial ≤ (Real.exp 1)^t := by + have h := Real.pow_div_factorial_le_exp (x := (t : ℝ)) (Nat.cast_nonneg t) t + simpa only [← Real.exp_nat_mul, mul_one] using h + have hinv : (t.factorial : ℝ)⁻¹ ≤ (Real.exp 1 / t)^t := by + rw [div_pow] + apply (le_div_iff₀ (pow_pos ht0 t)).mpr + simpa only [div_eq_mul_inv, mul_comm] using he + calc + (N.choose t : ℝ) ≤ (N : ℝ)^t / t.factorial := Nat.choose_le_pow_div t N + _ ≤ (N : ℝ)^t * (Real.exp 1 / t)^t := by + rw [div_eq_mul_inv] + exact mul_le_mul_of_nonneg_left hinv (by positivity) + _ = _ := by rw [← mul_pow]; congr 1; ring + +def smallDensity : ℝ := Real.exp (-2) / 4 + +theorem smallDensity_pos : 0 < smallDensity := by unfold smallDensity; positivity + +theorem smallDensity_le_one : smallDensity ≤ 1 := by + unfold smallDensity + have : Real.exp (-2) ≤ 1 := Real.exp_le_one_iff.mpr (by norm_num) + linarith + +theorem smallDensity_calibration : Real.exp 1 ^ 2 * smallDensity = 1 / 4 := by + unfold smallDensity + rw [← Real.exp_nat_mul] + norm_num + rw [← mul_div_assoc, ← Real.exp_add] + norm_num + +theorem hall_summand_bound {n k m t : ℕ} (hk : 3 ≤ k) (hn : 0 < n) (ht : 0 < t) + (htn : t ≤ n) (hm : (m : ℝ) ≤ smallDensity * n) : + (m.choose t : ℝ) * n.choose t * ((t : ℝ) / n)^(k * t) ≤ + (1 / n : ℝ) * (1 / 2 : ℝ)^t := by + have hn0 : (0 : ℝ) < n := by exact_mod_cast hn + have ht0 : (0 : ℝ) < t := by exact_mod_cast ht + have hr0 : 0 ≤ (t : ℝ) / n := by positivity + have hr1 : (t : ℝ) / n ≤ 1 := (div_le_one hn0).mpr (by exact_mod_cast htn) + have hc : (m.choose t : ℝ) * n.choose t * ((t : ℝ) / n)^(k * t) ≤ + ((1 / 4 : ℝ) * ((t : ℝ) / n))^t := by + calc + _ ≤ (Real.exp 1 * m / t)^t * (Real.exp 1 * n / t)^t * + ((t : ℝ) / n)^(3 * t) := by + apply mul_le_mul + · exact mul_le_mul (choose_exp_bound m t ht) (choose_exp_bound n t ht) + (Nat.cast_nonneg _) (by positivity) + · exact pow_le_pow_of_le_one hr0 hr1 (Nat.mul_le_mul_right t hk) + · positivity + · positivity + _ = (Real.exp 1 ^ 2 * (m / n) * ((t : ℝ) / n))^t := by + rw [pow_mul, ← mul_pow, ← mul_pow] + congr 1 + field_simp + _ ≤ (Real.exp 1 ^ 2 * smallDensity * ((t : ℝ) / n))^t := by + apply pow_le_pow_left₀ (by positivity) + gcongr + exact (div_le_iff₀ hn0).mpr hm + _ = _ := by rw [smallDensity_calibration] + apply hc.trans + calc + ((1 / 4 : ℝ) * ((t : ℝ) / n))^t = (1 / 4 : ℝ)^t * ((t : ℝ) / n)^t := mul_pow _ _ _ + _ ≤ (1 / 4 : ℝ)^t * ((t : ℝ) / n) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + simpa only [pow_one] using pow_le_pow_of_le_one hr0 hr1 ht + _ ≤ (1 / 4 : ℝ)^t * ((2 : ℝ)^t / n) := by + apply mul_le_mul_of_nonneg_left _ (by positivity) + exact div_le_div_of_nonneg_right (by exact_mod_cast (Nat.lt_two_pow_self (n := t)).le) hn0.le + _ = (1 / n : ℝ) * (1 / 2 : ℝ)^t := by + rw [← mul_div_assoc, ← mul_pow] + norm_num + ring + +theorem half_geometric_sum_le (m : ℕ) : ∑ t ∈ Finset.range m, (1 / 2 : ℝ)^(t+1) ≤ 1 := by + have h := geom_sum_mul (1 / 2 : ℝ) m + have he : ∑ t ∈ Finset.range m, (1 / 2 : ℝ)^(t+1) = + (∑ t ∈ Finset.range m, (1 / 2 : ℝ)^t) * (1 / 2) := by + simp_rw [pow_succ] + rw [Finset.sum_mul] + rw [he] + nlinarith [pow_nonneg (by norm_num : (0 : ℝ) ≤ 1 / 2) m] + +theorem small_density_probability_bound {n k m : ℕ} (hk : 3 ≤ k) (hkn : k ≤ n) + (hm : (m : ℝ) ≤ smallDensity * n) : + 1 - (1 / n : ℝ) ≤ properSATProbability n k m := by + have hn : 0 < n := by omega + have hmn : m ≤ n := by + have h := mul_le_mul_of_nonneg_right smallDensity_le_one (Nat.cast_nonneg n : (0 : ℝ) ≤ n) + exact_mod_cast (show (m : ℝ) ≤ n from hm.trans (by simpa using h)) + have h := deficiency_union_bound hkn hn hmn + have hs : (∑ t ∈ Finset.range m, (m.choose (t + 1) : ℝ) * n.choose (t + 1) * + (((t + 1 : ℕ) : ℝ) / n)^(k * (t + 1))) ≤ 1 / n := by + calc + _ ≤ ∑ t ∈ Finset.range m, (1 / n : ℝ) * (1 / 2 : ℝ)^(t+1) := by + apply Finset.sum_le_sum + intro t ht + exact hall_summand_bound hk hn (by omega) (by have := Finset.mem_range.mp ht; omega) hm + _ = (1 / n : ℝ) * ∑ t ∈ Finset.range m, (1 / 2 : ℝ)^(t+1) := (Finset.mul_sum ..).symm + _ ≤ 1 / n := by + simpa using mul_le_mul_of_nonneg_left (half_geometric_sum_le m) (by positivity : (0 : ℝ) ≤ 1/n) + linarith + +def lowerCenterBound : ℝ := smallDensity / 4 + +theorem lowerCenterBound_pos : 0 < lowerCenterBound := div_pos smallDensity_pos (by norm_num) + +theorem center_lower_explicit {n k : ℕ} (hk : 3 ≤ k) (hkn : k ≤ n) + (hn : 2 ≤ n) (hlarge : 2 ≤ smallDensity * n) : lowerCenterBound ≤ center n k := by + let m : ℕ := ⌊smallDensity * n⌋₊ + have hn0 : (0 : ℝ) < n := by exact_mod_cast (show 0 < n by omega) + have hm : (m : ℝ) ≤ smallDensity * n := Nat.floor_le (by positivity) + have hmn : m ≤ n := by + have h := mul_le_mul_of_nonneg_right smallDensity_le_one hn0.le + exact_mod_cast (show (m : ℝ) ≤ n from hm.trans (by simpa using h)) + have hmcap : m ≤ mainCap n k := hmn.trans (by + unfold mainCap + exact Nat.le_mul_of_pos_left _ (by unfold capMultiplier; positivity)) + have hprob := small_density_probability_bound hk hkn hm + have hinv : (1 / n : ℝ) ≤ 1 / 2 := by + apply one_div_le_one_div_of_le (by norm_num : (0 : ℝ) < 2) + exact_mod_cast hn + have hhalf : (1 / 2 : ℝ) ≤ properSATProbability n k m := by linarith + have hfloor : smallDensity * n < (m : ℝ) + 1 := Nat.lt_floor_add_one _ + have hratio : smallDensity / 2 ≤ (m : ℝ) / n := by + apply (le_div_iff₀ hn0).mpr + nlinarith + have hl := center_lower_by_probability hkn hmcap + have hmul := mul_le_mul hratio hhalf (by norm_num : (0 : ℝ) ≤ 1 / 2) + (div_nonneg (Nat.cast_nonneg m) hn0.le) + unfold lowerCenterBound + nlinarith + +theorem center_bounds_eventually (k : ℕ) (hk : 3 ≤ k) : + ∀ᶠ n : ℕ in Filter.atTop, lowerCenterBound ≤ center n k ∧ center n k ≤ (2 : ℝ)^k + 1 := by + have hlin : ∀ᶠ n : ℕ in Filter.atTop, 2 ≤ smallDensity * n := by + have ht := (tendsto_natCast_atTop_atTop (R := ℝ)).const_mul_atTop smallDensity_pos + exact ht.eventually (Filter.eventually_ge_atTop 2) + have hpow := tendsto_pow_atTop_nhds_zero_of_lt_one firstMomentBase_nonneg firstMomentBase_lt_one + have ht : Filter.Tendsto (fun n : ℕ => (capMultiplier k : ℝ) * firstMomentBase^n) + Filter.atTop (nhds 0) := by + simpa only [mul_zero] using hpow.const_mul (capMultiplier k : ℝ) + have hu := ht.eventually_lt_const (by norm_num : (0 : ℝ) < 1) + have hn : ∀ᶠ n : ℕ in Filter.atTop, k + 1 ≤ n := Filter.eventually_ge_atTop _ + filter_upwards [hlin, hu, hn] with n hlarge hu hn + exact ⟨center_lower_explicit hk (by omega) (by omega) hlarge, + (center_first_moment (by omega) (by omega)).trans (by linarith)⟩ + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/CenterComparison.lean b/lean/OAI/Probability/RandomSAT/CenterComparison.lean new file mode 100644 index 0000000000000000000000000000000000000000..a574c028179ee2afd5250fd4889232bc7ea2d04b --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/CenterComparison.lean @@ -0,0 +1,370 @@ +import OAI.Probability.RandomSAT.Transfer + +namespace OAI + +/-! +Partition interpolation and concentration yield summable-error comparisons +for centers of two blocks and of neighboring sizes. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +theorem auxiliary_interpolation_center_lower {r s k m : ℕ} (hk : 3 ≤ k) + (hr : k + 1 ≤ r) (hs : k + 1 ≤ s) + (hrrep : 2 * repeatPairs k ≤ r) (hsrep : 2 * repeatPairs k ≤ s) + (hrerr : concentrationError r k ≤ 1 / 2) (hserr : concentrationError s k ≤ 1 / 2) + (hm : (m : ℝ) ≤ (capMultiplier k : ℝ) * ((r : ℝ) + s)) + (hgapr : (m : ℝ) * ((r : ℝ) / (r + s)) + 2 * fluctuationWindow r k ≤ (r : ℝ) * center r k) + (hgaps : (m : ℝ) * ((s : ℝ) / (r + s)) + 2 * fluctuationWindow s k ≤ (s : ℝ) * center s k) : + (transferLower k)^2 * (1 - samplingError r k - samplingError s k) ≤ + auxiliaryProbability (r + s) k m := by + have hr0 : 0 < r := by omega + have hs0 : 0 < s := by omega + have hr' : (0 : ℝ) < r := by exact_mod_cast hr0 + have hs' : (0 : ℝ) < s := by exact_mod_cast hs0 + let p : ℝ := (r : ℝ) / (r + s) + have hp0 : 0 ≤ p := by dsimp [p]; positivity + have hp1 : p ≤ 1 := by + dsimp [p] + apply (div_le_one (by positivity : (0 : ℝ) < r + s)).mpr + linarith + have hpq : 1 - p = (s : ℝ) / (r + s) := by dsimp [p]; field_simp; ring + have hwr := fluctuationWindow_pos (k := k) hr0 + have hws := fluctuationWindow_pos (k := k) hs0 + have hpoint : ∀ j ≤ m, + (transferLower k)^2 * (1 - ((j : ℝ) - m * p)^2 / (fluctuationWindow r k)^2 - + ((j : ℝ) - m * p)^2 / (fluctuationWindow s k)^2) ≤ + auxiliaryProbability r k j * auxiliaryProbability s k (m - j) := by + intro j hj + apply product_lower_two_deviations (transferLower_pos k).le (by positivity) (by positivity) + (auxiliaryProbability_nonneg r k j) (auxiliaryProbability_nonneg s k (m - j)) + · intro hdev + apply auxiliaryProbability_center_lower hk hr hrrep hrerr + have hsq : ((j : ℝ) - m * p)^2 < (fluctuationWindow r k)^2 := + (div_lt_one (sq_pos_of_pos hwr)).mp hdev + by_contra hgap + have hdiff : fluctuationWindow r k < (j : ℝ) - m * p := by + change (m : ℝ) * p + 2 * fluctuationWindow r k ≤ (r : ℝ) * center r k at hgapr + linarith + nlinarith + · intro hdev + apply auxiliaryProbability_center_lower hk hs hsrep hserr + have hsq : ((j : ℝ) - m * p)^2 < (fluctuationWindow s k)^2 := + (div_lt_one (sq_pos_of_pos hws)).mp hdev + rw [← hpq] at hgaps + rw [Nat.cast_sub hj] + by_contra hgap + have hdiff : fluctuationWindow s k < -((j : ℝ) - m * p) := by linarith + nlinarith + have hmean := binomialMean_mono hp0 hp1 hpoint + rw [binomialMean_const_mul, binomialMean_sub, binomialMean_sub, binomialMean_const, + binomialMean_div_const, binomialMean_div_const, binomialMean_centered_square] at hmean + apply le_trans _ (hmean.trans (auxiliary_interpolation hr0 hs0 m)) + apply mul_le_mul_of_nonneg_left _ (sq_nonneg _) + have hmp : (m : ℝ) * p ≤ (capMultiplier k : ℝ) * r := by + have h := mul_le_mul_of_nonneg_right hm hp0 + have he : ((capMultiplier k : ℝ) * ((r : ℝ) + s)) * p = + (capMultiplier k : ℝ) * r := by dsimp [p]; field_simp + simpa only [he] using h + have hmq : (m : ℝ) * (1 - p) ≤ (capMultiplier k : ℝ) * s := by + have h := mul_le_mul_of_nonneg_right hm (sub_nonneg.mpr hp1) + have he : ((capMultiplier k : ℝ) * ((r : ℝ) + s)) * (1 - p) = + (capMultiplier k : ℝ) * s := by rw [hpq]; field_simp + simpa only [he] using h + have hvr : (m : ℝ) * p * (1 - p) ≤ (capMultiplier k : ℝ) * r := by + have h := mul_le_mul_of_nonneg_left (show 1 - p ≤ 1 by linarith) + (mul_nonneg (Nat.cast_nonneg m) hp0) + nlinarith + have hvs : (m : ℝ) * p * (1 - p) ≤ (capMultiplier k : ℝ) * s := by + have h := mul_le_mul_of_nonneg_left hp1 + (mul_nonneg (Nat.cast_nonneg m) (sub_nonneg.mpr hp1)) + nlinarith + have hfr := div_le_div_of_nonneg_right hvr (sq_nonneg (fluctuationWindow r k)) + have hfs := div_le_div_of_nonneg_right hvs (sq_nonneg (fluctuationWindow s k)) + unfold samplingError + linarith + +def densityWindow (n k : ℕ) : ℝ := (n : ℝ)^(-delta k) + +theorem densityWindow_pos {n k : ℕ} (hn : 0 < n) : 0 < densityWindow n k := + Real.rpow_pos_of_pos (by exact_mod_cast hn) _ + +theorem fluctuationWindow_eq_mul {n k : ℕ} (hn : 0 < n) : + fluctuationWindow n k = (n : ℝ) * densityWindow n k := by + unfold fluctuationWindow densityWindow + rw [sub_eq_add_neg, Real.rpow_add (by exact_mod_cast hn), Real.rpow_one] + +theorem fluctuationWindow_one_le {n k : ℕ} (hk : 3 ≤ k) (hn : 0 < n) : + 1 ≤ fluctuationWindow n k := by + apply Real.one_le_rpow (by exact_mod_cast hn : (1 : ℝ) ≤ n) + have h := delta_lt_half hk + linarith + +theorem densityWindow_antitone {r s k : ℕ} (hk : 3 ≤ k) (hr : 0 < r) (hrs : r ≤ s) : + densityWindow s k ≤ densityWindow r k := + Real.rpow_le_rpow_of_nonpos (by exact_mod_cast hr) (by exact_mod_cast hrs) + (neg_nonpos.mpr (delta_pos hk).le) + +theorem densityWindow_tendsto (k : ℕ) (hk : 3 ≤ k) : + Filter.Tendsto (fun n : ℕ => densityWindow n k) Filter.atTop (nhds 0) := + (tendsto_rpow_neg_atTop (delta_pos hk)).comp (tendsto_natCast_atTop_atTop (R := ℝ)) + +theorem concentrationError_tendsto (k : ℕ) (hk : 3 ≤ k) : + Filter.Tendsto (fun n : ℕ => concentrationError n k) Filter.atTop (nhds 0) := by + have hη : 0 < eta k := by rw [eta_eq_twice_delta]; positivity [delta_pos hk] + have ht := (tendsto_rpow_neg_atTop hη).comp (tendsto_natCast_atTop_atTop (R := ℝ)) + simpa only [concentrationError, Function.comp_apply, mul_zero] using ht.const_mul (varianceConstant k) + +theorem samplingError_identity {n k : ℕ} (hn : 0 < n) : + samplingError n k = (capMultiplier k : ℝ) * (n : ℝ)^(-(1 - 2 * delta k)) := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + unfold samplingError fluctuationWindow + rw [← Real.rpow_two ((n : ℝ)^(1 - delta k)), ← Real.rpow_mul hn'.le] + have he : -(1 - 2 * delta k) = 1 - (1 - delta k) * 2 := by ring + rw [he, Real.rpow_sub hn', Real.rpow_one] + ring + +theorem samplingError_tendsto (k : ℕ) (hk : 3 ≤ k) : + Filter.Tendsto (fun n : ℕ => samplingError n k) Filter.atTop (nhds 0) := by + have hd : 0 < 1 - 2 * delta k := by linarith [delta_lt_half hk] + have ht := (tendsto_rpow_neg_atTop hd).comp (tendsto_natCast_atTop_atTop (R := ℝ)) + have ht' : Filter.Tendsto (fun n : ℕ => (capMultiplier k : ℝ) * (n : ℝ)^(-(1 - 2 * delta k))) + Filter.atTop (nhds 0) := by simpa only [Function.comp_apply, mul_zero] using ht.const_mul (capMultiplier k : ℝ) + apply ht'.congr' + filter_upwards [Filter.eventually_ge_atTop 1] with n hn + exact (samplingError_identity (k := k) (by omega)).symm + +theorem fluctuationWindow_tendsto (k : ℕ) (hk : 3 ≤ k) : + Filter.Tendsto (fun n : ℕ => fluctuationWindow n k) Filter.atTop Filter.atTop := by + have hd : 0 < 1 - delta k := by linarith [delta_lt_half hk] + exact (tendsto_rpow_atTop hd).comp (tendsto_natCast_atTop_atTop (R := ℝ)) + +theorem center_lower_of_auxiliary_probability {n k : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + {c : ℝ} (hc0 : 0 ≤ c) (hcL : c ≤ capMultiplier k) + (hprob : concentrationError n k < auxiliaryProbability n k ⌊c * n⌋₊) : + c - 2 * densityWindow n k < center n k := by + have hn0 : 0 < n := by omega + have hn' : (0 : ℝ) < n := by exact_mod_cast hn0 + have hf := Nat.floor_le (mul_nonneg hc0 hn'.le) + have hm : ⌊c * (n : ℝ)⌋₊ ≤ mainCap n k := by + have h := hf.trans (mul_le_mul_of_nonneg_right hcL hn'.le) + exact_mod_cast (show (⌊c * (n : ℝ)⌋₊ : ℝ) ≤ (mainCap n k : ℝ) by + simpa only [mainCap, Nat.cast_mul] using h) + by_contra h + have hw := fluctuationWindow_one_le (n := n) hk hn0 + have he := fluctuationWindow_eq_mul (k := k) hn0 + have hc : center n k + 2 * densityWindow n k ≤ c := by linarith + have hmul := mul_le_mul_of_nonneg_left hc hn'.le + have hfloor := Nat.lt_floor_add_one (c * (n : ℝ)) + have hgap : (n : ℝ) * center n k + fluctuationWindow n k ≤ ⌊c * (n : ℝ)⌋₊ := by + nlinarith + exact not_lt_of_ge (auxiliaryProbability_center_upper hk hn hm hgap) hprob + +theorem center_sum_comparison_of_bounds {r s k : ℕ} (hk : 3 ≤ k) + (hr : k + 1 ≤ r) (hs : k + 1 ≤ s) + (hrrep : 2 * repeatPairs k ≤ r) (hsrep : 2 * repeatPairs k ≤ s) + (hrerr : concentrationError r k ≤ 1 / 2) (hserr : concentrationError s k ≤ 1 / 2) + (hrsample : samplingError r k ≤ 1 / 4) (hssample : samplingError s k ≤ 1 / 4) + (hNerr : concentrationError (r + s) k < (transferLower k)^2 / 2) + (hlow : 2 * densityWindow (min r s) k ≤ min (center r k) (center s k)) : + min (center r k) (center s k) - 4 * densityWindow (min r s) k ≤ center (r + s) k := by + have hr0 : 0 < r := by omega + have hs0 : 0 < s := by omega + have hu0 : 0 < min r s := lt_min hr0 hs0 + have hr' : (0 : ℝ) < r := by exact_mod_cast hr0 + have hs' : (0 : ℝ) < s := by exact_mod_cast hs0 + have hN' : (0 : ℝ) < (r : ℝ) + s := by positivity + let c := min (center r k) (center s k) - 2 * densityWindow (min r s) k + have hc0 : 0 ≤ c := sub_nonneg.mpr hlow + have hcL : c ≤ capMultiplier k := by + have hh := (min_le_left (center r k) (center s k)).trans (center_le_capMultiplier (by omega) hr0) + dsimp [c] + have hp := (densityWindow_pos (k := k) hu0).le + linarith + have hcr : c + 2 * densityWindow r k ≤ center r k := by + have hd := densityWindow_antitone hk hu0 (min_le_left r s) + have hh := min_le_left (center r k) (center s k) + dsimp [c] + linarith + have hcs : c + 2 * densityWindow s k ≤ center s k := by + have hd := densityWindow_antitone hk hu0 (min_le_right r s) + have hh := min_le_right (center r k) (center s k) + dsimp [c] + linarith + let m := ⌊c * ((r : ℝ) + s)⌋₊ + have hm : (m : ℝ) ≤ c * ((r : ℝ) + s) := Nat.floor_le (mul_nonneg hc0 hN'.le) + have hmr : (m : ℝ) * ((r : ℝ) / (r + s)) ≤ c * r := by + have hh := mul_le_mul_of_nonneg_right hm (show 0 ≤ (r : ℝ) / (r + s) by positivity) + have he : c * ((r : ℝ) + s) * ((r : ℝ) / (r + s)) = c * r := by field_simp + rwa [he] at hh + have hms : (m : ℝ) * ((s : ℝ) / (r + s)) ≤ c * s := by + have hh := mul_le_mul_of_nonneg_right hm (show 0 ≤ (s : ℝ) / (r + s) by positivity) + have he : c * ((r : ℝ) + s) * ((s : ℝ) / (r + s)) = c * s := by field_simp + rwa [he] at hh + have hprob := auxiliary_interpolation_center_lower hk hr hs hrrep hsrep hrerr hserr + (hm.trans (mul_le_mul_of_nonneg_right hcL hN'.le)) + (show (m : ℝ) * ((r : ℝ) / (r + s)) + 2 * fluctuationWindow r k ≤ (r : ℝ) * center r k by + rw [fluctuationWindow_eq_mul hr0] + have hh := mul_le_mul_of_nonneg_left hcr hr'.le + nlinarith) + (show (m : ℝ) * ((s : ℝ) / (r + s)) + 2 * fluctuationWindow s k ≤ (s : ℝ) * center s k by + rw [fluctuationWindow_eq_mul hs0] + have hh := mul_le_mul_of_nonneg_left hcs hs'.le + nlinarith) + have hhalf : (transferLower k)^2 / 2 ≤ auxiliaryProbability (r + s) k m := by + have hh := mul_le_mul_of_nonneg_left (show (1 / 2 : ℝ) ≤ 1 - samplingError r k - samplingError s k by linarith) + (sq_nonneg (transferLower k)) + nlinarith + have hcN := center_lower_of_auxiliary_probability hk (by omega : k + 1 ≤ r + s) hc0 hcL + (show concentrationError (r + s) k < auxiliaryProbability (r + s) k ⌊c * ((r + s : ℕ) : ℝ)⌋₊ by + simpa only [Nat.cast_add, ← show ⌊c * ((r : ℝ) + s)⌋₊ = m from rfl] using hNerr.trans_le hhalf) + have hd := densityWindow_antitone hk hu0 (show min r s ≤ r + s by omega) + dsimp [c] at hcN + linarith + +def neighborFactor (k : ℕ) : ℝ := Real.exp (-2 * (capMultiplier k : ℝ)) + +def neighborLower (k : ℕ) : ℝ := neighborFactor k * transferLower k + +theorem neighborLower_pos (k : ℕ) : 0 < neighborLower k := + mul_pos (Real.exp_pos _) (transferLower_pos k) + +@[simp] theorem auxiliaryProbability_zero (n k : ℕ) : auxiliaryProbability n k 0 = 1 := by + simp only [auxiliaryProbability, auxiliarySurvival, Function.iterate_zero, id_eq, alive_univ] + +theorem neighbor_all_left {s k m : ℕ} (hs : 0 < s) : + ((s : ℝ) / (s + 1))^m * auxiliaryProbability s k m ≤ auxiliaryProbability (s + 1) k m := by + have hs' : (0 : ℝ) < s := by exact_mod_cast hs + have hp0 : 0 ≤ (s : ℝ) / (s + 1) := by positivity + have hp1 : (s : ℝ) / (s + 1) ≤ 1 := by + apply (div_le_one (by positivity : (0 : ℝ) < s + 1)).mpr + linarith + have h := binomialMean_all_success hp0 hp1 m + (fun j => auxiliaryProbability s k j * auxiliaryProbability 1 k (m - j)) + (fun j _ => mul_nonneg (auxiliaryProbability_nonneg _ _ _) (auxiliaryProbability_nonneg _ _ _)) + simp only [Nat.sub_self, auxiliaryProbability_zero, mul_one] at h + apply h.trans + simpa only [Nat.cast_one] using (auxiliary_interpolation (k := k) hs (by omega : 0 < 1) m) + +theorem neighbor_pow_lower {s k m : ℕ} (hs : 0 < s) + (hm : (m : ℝ) ≤ (capMultiplier k : ℝ) * ((s : ℝ) + 1)) : + neighborFactor k ≤ ((s : ℝ) / (s + 1))^m := by + have hs' : (1 : ℝ) ≤ s := by exact_mod_cast hs + have hN : (0 : ℝ) < s + 1 := by linarith + have hx0 : (0 : ℝ) ≤ 1 / ((s : ℝ) + 1) := by positivity + have hx : (1 : ℝ) / ((s : ℝ) + 1) ≤ 1 / 2 := by + apply (div_le_iff₀ hN).mpr + linarith + have hbase := exp_neg_two_le_one_sub hx0 hx + have he : 1 - (1 : ℝ) / ((s : ℝ) + 1) = (s : ℝ) / (s + 1) := by field_simp; ring + rw [he] at hbase + have hpow := pow_le_pow_left₀ (Real.exp_pos _).le hbase m + rw [← Real.exp_nat_mul] at hpow + apply le_trans _ hpow + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_right hm hx0 + have he' : (capMultiplier k : ℝ) * ((s : ℝ) + 1) * (1 / ((s : ℝ) + 1)) = capMultiplier k := by field_simp + rw [he'] at hh + nlinarith + +theorem center_neighbor_comparison_of_bounds {s k : ℕ} (hk : 3 ≤ k) + (hs : k + 1 ≤ s) (hsrep : 2 * repeatPairs k ≤ s) + (hserr : concentrationError s k ≤ 1 / 2) + (hNerr : concentrationError (s + 1) k < neighborLower k) + (hlow : 2 * densityWindow s k ≤ center s k) + (hwindow : (capMultiplier k : ℝ) ≤ fluctuationWindow s k) : + center s k - 4 * densityWindow s k ≤ center (s + 1) k := by + have hs0 : 0 < s := by omega + have hs' : (0 : ℝ) < s := by exact_mod_cast hs0 + let c := center s k - 2 * densityWindow s k + have hc0 : 0 ≤ c := sub_nonneg.mpr hlow + have hcenter := center_le_capMultiplier (by omega : k ≤ s) hs0 + have hcL : c ≤ capMultiplier k := by + have hp := (densityWindow_pos (k := k) hs0).le + dsimp [c] + linarith + let m := ⌊c * ((s : ℝ) + 1)⌋₊ + have hm : (m : ℝ) ≤ c * ((s : ℝ) + 1) := Nat.floor_le (by positivity) + have hmL := hm.trans (mul_le_mul_of_nonneg_right hcL (by positivity : (0 : ℝ) ≤ (s : ℝ) + 1)) + have hgap : (m : ℝ) + fluctuationWindow s k ≤ (s : ℝ) * center s k := by + have hw := fluctuationWindow_eq_mul (k := k) hs0 + have he : c * ((s : ℝ) + 1) = (s : ℝ) * center s k - 2 * fluctuationWindow s k + c := by + rw [hw] + dsimp [c] + ring + rw [he] at hm + linarith + have hlocal := auxiliaryProbability_center_lower hk hs hsrep hserr hgap + have hpow := neighbor_pow_lower (k := k) hs0 hmL + have hprod := mul_le_mul hpow hlocal (transferLower_pos k).le + (pow_nonneg (by positivity : (0 : ℝ) ≤ (s : ℝ) / (s + 1)) m) + have hprob : neighborLower k ≤ auxiliaryProbability (s + 1) k m := + hprod.trans (neighbor_all_left hs0) + have hcN := center_lower_of_auxiliary_probability hk (by omega : k + 1 ≤ s + 1) hc0 hcL + (show concentrationError (s + 1) k < auxiliaryProbability (s + 1) k ⌊c * ((s + 1 : ℕ) : ℝ)⌋₊ by + simpa only [Nat.cast_add, Nat.cast_one] using hNerr.trans_le hprob) + have hd := densityWindow_antitone hk hs0 (Nat.le_succ s) + dsimp [c] at hcN + linarith + +structure CenterRegular (k n : ℕ) : Prop where + size : k + 1 ≤ n + repetition : 2 * repeatPairs k ≤ n + error : concentrationError n k ≤ 1 / 2 + sampling : samplingError n k ≤ 1 / 4 + sumError : concentrationError n k < (transferLower k)^2 / 2 + neighborError : concentrationError n k < neighborLower k + centerLower : lowerCenterBound ≤ center n k + densitySmall : 2 * densityWindow n k ≤ lowerCenterBound + windowLarge : (capMultiplier k : ℝ) ≤ fluctuationWindow n k + +theorem centerRegular_eventually (k : ℕ) (hk : 3 ≤ k) : + ∀ᶠ n : ℕ in Filter.atTop, CenterRegular k n := by + have hsize : ∀ᶠ n : ℕ in Filter.atTop, k + 1 ≤ n := Filter.eventually_ge_atTop _ + have hrep := (tendsto_natCast_atTop_atTop (R := ℝ)).eventually + (Filter.eventually_ge_atTop (2 * repeatPairs k)) + have he := (concentrationError_tendsto k hk).eventually_lt_const (by norm_num : (0 : ℝ) < 1 / 2) + have hs := (samplingError_tendsto k hk).eventually_lt_const (by norm_num : (0 : ℝ) < 1 / 4) + have heSum := (concentrationError_tendsto k hk).eventually_lt_const + (div_pos (sq_pos_of_pos (transferLower_pos k)) (by norm_num) : (0 : ℝ) < (transferLower k)^2 / 2) + have heNeighbor := (concentrationError_tendsto k hk).eventually_lt_const (neighborLower_pos k) + have hd := (densityWindow_tendsto k hk).eventually_lt_const + (div_pos lowerCenterBound_pos (by norm_num) : (0 : ℝ) < lowerCenterBound / 2) + have hw := (fluctuationWindow_tendsto k hk).eventually (Filter.eventually_ge_atTop (capMultiplier k : ℝ)) + filter_upwards [hsize, hrep, he, hs, heSum, heNeighbor, center_bounds_eventually k hk, hd, hw] + with n hn hr he hs hes hen hc hd hw + exact ⟨hn, hr, he.le, hs.le, hes, hen, hc.1, by linarith, hw⟩ + +theorem center_comparisons (k : ℕ) (hk : 3 ≤ k) : + ∃ N : ℕ, + (∀ r ≥ N, ∀ s ≥ N, + min (center r k) (center s k) - 4 * densityWindow (min r s) k ≤ center (r + s) k) ∧ + (∀ s ≥ N, center s k - 4 * densityWindow s k ≤ center (s + 1) k) := by + obtain ⟨N, hN⟩ := Filter.eventually_atTop.mp (centerRegular_eventually k hk) + refine ⟨N, ?_, ?_⟩ + · intro r hr s hs + have hR := hN r hr + have hS := hN s hs + have hU := hN (min r s) (le_min hr hs) + have hT := hN (r + s) (by omega) + exact center_sum_comparison_of_bounds hk hR.size hS.size hR.repetition hS.repetition + hR.error hS.error hR.sampling hS.sampling hT.sumError + (hU.densitySmall.trans (le_min hR.centerLower hS.centerLower)) + · intro s hs + have hS := hN s hs + have hT := hN (s + 1) (by omega) + exact center_neighbor_comparison_of_bounds hk hS.size hS.repetition hS.error hT.neighborError + (hS.densitySmall.trans hS.centerLower) hS.windowLarge + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/ClauseProcess.lean b/lean/OAI/Probability/RandomSAT/ClauseProcess.lean new file mode 100644 index 0000000000000000000000000000000000000000..0c6941a6ba19aff6c0fdd572e81ce59f16c9a0c5 --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/ClauseProcess.lean @@ -0,0 +1,423 @@ +import OAI.Probability.RandomSAT.FiniteMean + +namespace OAI + +/-! +Coordinate erasure, independent clause averaging, survival probabilities, and +iterated replacement. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +theorem support_card_cons {v : ℕ} (b : Option Bool) (C : Fin v → Option Bool) : + (Finset.univ.filter fun i : Fin (v + 1) => (Fin.cons (α := fun _ => Option Bool) b C i).isSome).card = + (if b.isSome then 1 else 0) + (Finset.univ.filter fun i => (C i).isSome).card := by + simp only [Finset.card_eq_sum_ones, Finset.sum_filter] + rw [Fin.sum_univ_succ] + simp + +def prependAbsent {v k : ℕ} (C : ProperClause v k) : ProperClause (v + 1) k := + ⟨Fin.cons none C.val, by simpa [support_card_cons] using C.property⟩ + +def prependPresent {v k : ℕ} (hk : 0 < k) (C : ProperClause v (k - 1)) (b : Bool) : + ProperClause (v + 1) k := + ⟨Fin.cons (some b) C.val, by + rw [support_card_cons] + simp only [Option.isSome_some, ↓reduceIte, C.property] + omega⟩ + +def clauseHeadSplit {v k : ℕ} (hk : 0 < k) (C : ProperClause (v + 1) k) : + ProperClause v k ⊕ (ProperClause v (k - 1) × Bool) := + match hb : C.val 0 with + | none => Sum.inl ⟨Fin.tail C.val, by + have h := C.property + conv_lhs at h => rw [← Fin.cons_self_tail C.val] + rw [support_card_cons, hb] at h + simpa using h⟩ + | some b => Sum.inr (⟨Fin.tail C.val, by + have h := C.property + conv_lhs at h => rw [← Fin.cons_self_tail C.val] + rw [support_card_cons, hb] at h + simp at h + omega⟩, b) + +def clauseHeadEquiv {v k : ℕ} (hk : 0 < k) : + ProperClause (v + 1) k ≃ ProperClause v k ⊕ (ProperClause v (k - 1) × Bool) where + toFun := clauseHeadSplit hk + invFun := Sum.elim prependAbsent (fun p => prependPresent hk p.1 p.2) + left_inv C := by + apply Subtype.ext + simp only [clauseHeadSplit] + split <;> simp only [Sum.elim_inl, Sum.elim_inr, prependAbsent, prependPresent] + all_goals simpa only [*] using Fin.cons_self_tail C.val + right_inv C := by + cases C with + | inl C => rfl + | inr C => + rcases C with ⟨C, b⟩ + rfl + +@[simp] theorem satisfiesClause_prependAbsent {v k : ℕ} + (σ : Assignment v) (b : Bool) (C : ProperClause v k) : + SatisfiesClause (Fin.cons b σ) (prependAbsent C) ↔ SatisfiesClause σ C := by + simp [SatisfiesClause, prependAbsent, Fin.exists_fin_succ] + +@[simp] theorem satisfiesClause_prependPresent {v k : ℕ} (hk : 0 < k) + (σ : Assignment v) (b t : Bool) (C : ProperClause v (k - 1)) : + SatisfiesClause (Fin.cons b σ) (prependPresent hk C t) ↔ t = b ∨ SatisfiesClause σ C := by + simp [SatisfiesClause, prependPresent, Fin.exists_fin_succ] + +def addClause {n k : ℕ} (S : Finset (Assignment n)) (C : ProperClause n k) : + Finset (Assignment n) := S.filter (fun σ => SatisfiesClause σ C) + +@[simp] theorem mem_addClause {n k : ℕ} (S : Finset (Assignment n)) + (C : ProperClause n k) (σ : Assignment n) : + σ ∈ addClause S C ↔ σ ∈ S ∧ SatisfiesClause σ C := by + simp [addClause] + +theorem addClause_comm {n k r : ℕ} (S : Finset (Assignment n)) + (C : ProperClause n k) (D : ProperClause n r) : + addClause (addClause S C) D = addClause (addClause S D) C := by + ext σ + simp only [mem_addClause] + tauto + +def restrictSolutions {n k : ℕ} {ι : Type*} [Fintype ι] + (S : Finset (Assignment n)) (F : ι → ProperClause n k) : Finset (Assignment n) := + S.filter (fun σ => ∀ i, SatisfiesClause σ (F i)) + +@[simp] theorem mem_restrictSolutions {n k : ℕ} {ι : Type*} [Fintype ι] + (S : Finset (Assignment n)) (F : ι → ProperClause n k) (σ : Assignment n) : + σ ∈ restrictSolutions S F ↔ σ ∈ S ∧ ∀ i, SatisfiesClause σ (F i) := by + simp [restrictSolutions] + +theorem restrictSolutions_zero {n k : ℕ} (S : Finset (Assignment n)) + (F : Formula n k 0) : restrictSolutions S F = S := by + ext σ + simp only [mem_restrictSolutions, Fin.forall_fin_zero, and_true] + +theorem restrictSolutions_cons {n k m : ℕ} (S : Finset (Assignment n)) + (C : ProperClause n k) (F : Formula n k m) : + restrictSolutions S (Fin.cons C F) = restrictSolutions (addClause S C) F := by + ext σ + simp only [mem_restrictSolutions, mem_addClause, Fin.forall_fin_succ, Fin.cons_zero, + Fin.cons_succ] + tauto + +theorem restrictSolutions_comm {n k r : ℕ} {ι κ : Type*} [Fintype ι] [Fintype κ] + (S : Finset (Assignment n)) (F : ι → ProperClause n k) (G : κ → ProperClause n r) : + restrictSolutions (restrictSolutions S F) G = restrictSolutions (restrictSolutions S G) F := by + ext σ + simp only [mem_restrictSolutions] + tauto + +theorem uniformMean_fin_succ {α : Type*} [Fintype α] {m : ℕ} + (f : (Fin (m + 1) → α) → ℝ) : + uniformMean f = uniformMean (fun a => uniformMean (fun F : Fin m → α => + f (Fin.cons a F))) := by + calc + _ = uniformMean (fun p : α × (Fin m → α) => f (Fin.cons p.1 p.2)) := + (uniformMean_equiv (Fin.consEquiv (fun _ => α)) f).symm + _ = _ := uniformMean_prod _ + +def alive {n : ℕ} (S : Finset (Assignment n)) : ℝ := if S.Nonempty then 1 else 0 + +theorem alive_nonneg {n : ℕ} (S : Finset (Assignment n)) : 0 ≤ alive S := by + unfold alive + split <;> norm_num + +theorem alive_le_one {n : ℕ} (S : Finset (Assignment n)) : alive S ≤ 1 := by + unfold alive + split <;> norm_num + +theorem alive_mono {n : ℕ} {S T : Finset (Assignment n)} (hST : S ⊆ T) : + alive S ≤ alive T := by + unfold alive + by_cases hS : S.Nonempty + · have hT := hS.mono hST + simp [hS, hT] + · simp only [ite_eq_right hS] + split <;> norm_num + +def clauseAverage {n : ℕ} (k : ℕ) (f : Finset (Assignment n) → ℝ) + (S : Finset (Assignment n)) : ℝ := + uniformMean (fun C : ProperClause n k => f (addClause S C)) + +def survival {n : ℕ} (k : ℕ) (m : ℕ) (S : Finset (Assignment n)) : ℝ := + ((clauseAverage k)^[m] alive) S + +@[simp] theorem survival_zero {n k : ℕ} (S : Finset (Assignment n)) : + survival k 0 S = alive S := rfl + +theorem survival_succ {n k m : ℕ} (S : Finset (Assignment n)) : + survival k (m + 1) S = uniformMean (fun C : ProperClause n k => + survival k m (addClause S C)) := by + rw [survival, Function.iterate_succ_apply'] + rfl + +theorem survival_eq_mean {n k m : ℕ} (S : Finset (Assignment n)) : + survival k m S = uniformMean (fun F : Formula n k m => alive (restrictSolutions S F)) := by + induction m generalizing S with + | zero => + simp only [survival_zero, restrictSolutions_zero] + exact (uniformMean_const _).symm + | succ m ih => + rw [survival_succ, uniformMean_fin_succ] + apply uniformMean_congr + intro C + rw [ih] + apply uniformMean_congr + intro F + rw [restrictSolutions_cons] + +theorem properSATProbability_eq_survival (n k m : ℕ) : + properSATProbability n k m = survival k m (Finset.univ : Finset (Assignment n)) := by + rw [survival_eq_mean] + change uniformProbability (fun F : Formula n k m => Satisfiable F) = _ + rw [uniformProbability_eq_mean] + apply uniformMean_congr + intro F + unfold alive + congr 1 + simp only [Finset.nonempty_iff_ne_empty] + apply propext + rw [← Finset.nonempty_iff_ne_empty] + simp [Finset.Nonempty, Satisfiable, Satisfies] + +theorem survival_nonneg {n k m : ℕ} (S : Finset (Assignment n)) : 0 ≤ survival k m S := by + rw [survival_eq_mean] + exact uniformMean_nonneg (fun _ => alive_nonneg _) + +theorem survival_le_one {n k m : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + survival k m S ≤ 1 := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + rw [survival_eq_mean, ← uniformMean_const (α := Formula n k m) (1 : ℝ)] + exact uniformMean_mono (fun _ => alive_le_one _) + +theorem survival_mono_solutions {n k m : ℕ} {S T : Finset (Assignment n)} (hST : S ⊆ T) : + survival k m S ≤ survival k m T := by + rw [survival_eq_mean, survival_eq_mean] + apply uniformMean_mono + intro F + apply alive_mono + intro σ hσ + rw [mem_restrictSolutions] at hσ ⊢ + exact ⟨hST hσ.1, hσ.2⟩ + +theorem survival_antitone {n k : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + Antitone (fun m => survival k m S) := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + apply antitone_nat_of_succ_le + intro m + rw [survival_succ, ← uniformMean_const (α := ProperClause n k) (survival k m S)] + apply uniformMean_mono + intro C + exact survival_mono_solutions (Finset.filter_subset _ _) + +theorem properSATProbability_antitone {n k : ℕ} (hkn : k ≤ n) : + Antitone (properSATProbability n k) := by + intro i j hij + rw [properSATProbability_eq_survival, properSATProbability_eq_survival] + exact survival_antitone hkn _ hij + +theorem clauseAverage_mono {n k : ℕ} {f g : Finset (Assignment n) → ℝ} + (hfg : ∀ S, f S ≤ g S) : ∀ S, clauseAverage k f S ≤ clauseAverage k g S := by + intro S + exact uniformMean_mono (fun C => hfg (addClause S C)) + +theorem clauseAverage_sub_const {n k : ℕ} (hkn : k ≤ n) + (f : Finset (Assignment n) → ℝ) (c : ℝ) (S : Finset (Assignment n)) : + clauseAverage k (fun T => f T - c) S = clauseAverage k f S - c := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + exact (uniformMean_sub _ _).trans (by rw [uniformMean_const]; rfl) + +theorem clauseAverage_commute {n k r : ℕ} : + Function.Commute (clauseAverage (n := n) k) (clauseAverage r) := by + intro f + funext S + unfold clauseAverage + rw [uniformMean_comm] + apply uniformMean_congr + intro C + apply uniformMean_congr + intro D + rw [addClause_comm] + +theorem clauseAverage_iterate_mono {n k m : ℕ} {f g : Finset (Assignment n) → ℝ} + (hfg : ∀ S, f S ≤ g S) : ∀ S, + ((clauseAverage k)^[m] f) S ≤ ((clauseAverage k)^[m] g) S := by + induction m with + | zero => exact hfg + | succ m ih => + simp only [Function.iterate_succ_apply'] + exact clauseAverage_mono ih + +theorem clauseAverage_iterate_sub_const {n k m : ℕ} (hkn : k ≤ n) + (f : Finset (Assignment n) → ℝ) (c : ℝ) : + (clauseAverage k)^[m] (fun T => f T - c) = + (fun S => ((clauseAverage k)^[m] f) S - c) := by + induction m with + | zero => rfl + | succ m ih => + rw [Function.iterate_succ_apply', ih, Function.iterate_succ_apply'] + funext S + exact clauseAverage_sub_const hkn _ _ _ + +theorem survival_shift {n k r m d : ℕ} (S : Finset (Assignment n)) : + ((clauseAverage k)^[m] (survival r d)) S = + ((clauseAverage r)^[d] (survival k m)) S := by + exact congrArg (fun f => f S) ((clauseAverage_commute (n := n) (k := k) (r := r)).iterate_iterate m d alive) + +theorem survival_add {n k m d : ℕ} (S : Finset (Assignment n)) : + ((clauseAverage k)^[m] (survival k d)) S = survival k (m + d) S := by + exact congrArg (fun f => f S) (Function.iterate_add_apply (clauseAverage k) m d alive).symm + +theorem survival_eq_probability {n k m : ℕ} (S : Finset (Assignment n)) : + survival k m S = uniformProbability (fun F : Formula n k m => + ∃ σ ∈ S, Satisfies σ F) := by + rw [survival_eq_mean, uniformProbability_eq_mean] + apply uniformMean_congr + intro F + unfold alive + congr 1 + apply propext + simp [Finset.Nonempty, Satisfies] + +theorem blockUNSAT_eq {n k g : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + blockUNSATProbability k g S = 1 - survival k g S := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + rw [survival_eq_probability] + exact uniformProbability_not _ + +theorem kills_iff_addClause {n k : ℕ} (S : Finset (Assignment n)) (C : ProperClause n k) : + KillsSolutions S C ↔ ¬ (addClause S C).Nonempty := by + change (∀ σ ∈ S, ¬ SatisfiesClause σ C) ↔ ¬ ∃ σ, σ ∈ addClause S C + simp only [mem_addClause, not_exists, not_and] + +theorem singleUNSAT_eq {n k : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + uniformProbability (fun C : ProperClause n k => KillsSolutions S C) = + 1 - survival k 1 S := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + rw [uniformProbability_eq_mean, survival_succ] + simp only [survival_zero] + calc + _ = uniformMean (fun C : ProperClause n k => 1 - alive (addClause S C)) := by + apply uniformMean_congr + intro C + rw [kills_iff_addClause] + unfold alive + by_cases h : (addClause S C).Nonempty <;> simp [h] + _ = _ := by rw [uniformMean_sub, uniformMean_const] + +theorem shorter_survival_replacement {n k : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (S : Finset (Assignment (n - 1))) : + survival k (replacementBlock n k) S - replacementError n k ≤ survival (k - 1) 1 S := by + have h := shorter_clause_replacement hk hn S + rw [singleUNSAT_eq (by omega), blockUNSAT_eq (by omega)] at h + linarith + +theorem shorter_survival_replacement_many {n k : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (d : ℕ) (S : Finset (Assignment (n - 1))) : + survival k (replacementBlock n k * d) S - (d : ℝ) * replacementError n k ≤ + survival (k - 1) d S := by + induction d generalizing S with + | zero => simp + | succ d ih => + let g := replacementBlock n k + let ε := replacementError n k + have hkn : k ≤ n - 1 := by omega + have hshort : k - 1 ≤ n - 1 := by omega + have ha := clauseAverage_mono (k := k - 1) ih S + have hb := clauseAverage_iterate_mono (k := k) (m := g * d) + (shorter_survival_replacement hk hn) S + rw [clauseAverage_sub_const hshort] at ha + rw [clauseAverage_iterate_sub_const hkn] at hb + dsimp only at hb + rw [survival_add] at hb + have hcomm : clauseAverage (k - 1) (survival k (g * d)) S = + ((clauseAverage k)^[g * d] (survival (k - 1) 1)) S := by + exact survival_shift (m := 1) (d := g * d) S + rw [← hcomm] at hb + change _ ≤ survival (k - 1) (d + 1) S + rw [survival_succ] + have heq : g * (d + 1) = g * d + g := by ring + rw [show replacementBlock n k * (d + 1) = g * d + g from heq] + push_cast + change survival k (g * d + g) S - ((d : ℝ) + 1) * ε ≤ _ + change _ - (d : ℝ) * ε ≤ _ at ha + change survival k (g * d + g) S - ε ≤ _ at hb + dsimp only [g, clauseAverage] at ha hb ⊢ + linarith + +theorem uniformMean_sum_type {α β : Type*} [Fintype α] [Fintype β] + [Nonempty α] [Nonempty β] (f : α ⊕ β → ℝ) : + uniformMean f = + ((Fintype.card α : ℝ) / (Fintype.card α + Fintype.card β)) * + uniformMean (fun a => f (Sum.inl a)) + + ((Fintype.card β : ℝ) / (Fintype.card α + Fintype.card β)) * + uniformMean (fun b => f (Sum.inr b)) := by + have hα : (Fintype.card α : ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + have hβ : (Fintype.card β : ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + simp only [uniformMean, Fintype.sum_sum_type, Fintype.card_sum, Nat.cast_add] + field_simp + +theorem head_incidence_ratio {v k : ℕ} (hk : 0 < k) (hkv : k ≤ v) : + ((v.choose (k - 1) * 2 ^ (k - 1) * 2 : ℕ) : ℝ) / + ((v.choose k * 2 ^ k + v.choose (k - 1) * 2 ^ (k - 1) * 2 : ℕ) : ℝ) = + (k : ℝ) / (v + 1) := by + have hks : k - 1 + 1 = k := Nat.sub_add_cancel hk + have hch : v.choose k + v.choose (k - 1) = (v + 1).choose k := by + simpa only [Nat.succ_eq_add_one, hks, add_comm] using (Nat.choose_succ_succ v (k - 1)).symm + have hmult : ((v : ℝ) + 1) * (v.choose (k - 1) : ℝ) = + ((v + 1).choose k : ℝ) * (k : ℝ) := by + exact_mod_cast (by simpa only [hks] using Nat.add_one_mul_choose_eq v (k - 1)) + have hpow : (2 : ℝ) ^ (k - 1) * 2 = 2 ^ k := by + rw [← pow_succ, hks] + have hcpos : (0 : ℝ) < (v + 1).choose k := by + exact_mod_cast Nat.choose_pos (by omega : k ≤ v + 1) + have hvpos : (0 : ℝ) < (v : ℝ) + 1 := by positivity + push_cast + simp only [mul_assoc, hpow] + rw [← add_mul] + have hc : (v.choose k : ℝ) + v.choose (k - 1) = (v + 1).choose k := by + exact_mod_cast hch + rw [hc] + apply (div_eq_div_iff (by positivity) hvpos.ne').mpr + nlinarith [congrArg (fun z : ℝ => z * 2 ^ k) hmult] + +theorem clauseHead_mean {v k : ℕ} (hk : 0 < k) (hkv : k ≤ v) + (f : (ProperClause v k ⊕ (ProperClause v (k - 1) × Bool)) → ℝ) : + uniformMean (fun C : ProperClause (v + 1) k => f (clauseHeadSplit hk C)) = + (1 - (k : ℝ) / (v + 1)) * uniformMean (fun C => f (Sum.inl C)) + + ((k : ℝ) / (v + 1)) * + uniformMean (fun Q => uniformMean (fun b : Bool => f (Sum.inr (Q, b)))) := by + let : Nonempty (ProperClause v k) := nonempty_properClause hkv + let : Nonempty (ProperClause v (k - 1)) := nonempty_properClause (by omega) + change uniformMean (fun C => f (clauseHeadEquiv hk C)) = _ + rw [uniformMean_equiv, uniformMean_sum_type, uniformMean_prod] + have hr := head_incidence_ratio hk hkv + have ht : (0 : ℝ) < Fintype.card (ProperClause v k) + + Fintype.card (ProperClause v (k - 1) × Bool) := by + exact add_pos (Nat.cast_pos.mpr Fintype.card_pos) (Nat.cast_pos.mpr Fintype.card_pos) + have hr' : (Fintype.card (ProperClause v (k - 1) × Bool) : ℝ) / + (Fintype.card (ProperClause v k) + Fintype.card (ProperClause v (k - 1) × Bool)) = + (k : ℝ) / (v + 1) := by + simpa only [Fintype.card_prod, Fintype.card_bool, card_properClause, Nat.cast_add] using hr + rw [hr', ← hr'] + congr 1 + apply congrArg (fun x : ℝ => x * uniformMean (fun C => f (Sum.inl C))) + field_simp + ring + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Clauses.lean b/lean/OAI/Probability/RandomSAT/Clauses.lean new file mode 100644 index 0000000000000000000000000000000000000000..67348622866b06dc6b12f9fdfe8b45365bbb99e7 --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Clauses.lean @@ -0,0 +1,282 @@ +import OAI.Probability.RandomSAT.Model + +namespace OAI + +/-! +Signed variable sets, clause cardinalities, and the exact probability of killing +a nonempty solution set. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +def clauseSupport {n k : ℕ} (C : ProperClause n k) : Finset (Fin n) := + Finset.univ.filter fun i => (C.val i).isSome + +@[simp] theorem clauseSupport_card {n k : ℕ} (C : ProperClause n k) : + (clauseSupport C).card = k := C.property + +@[simp] theorem mem_clauseSupport {n k : ℕ} (C : ProperClause n k) (i : Fin n) : + i ∈ clauseSupport C ↔ (C.val i).isSome := by + simp [clauseSupport] + +abbrev VariableSet (n k : ℕ) := ↥((Finset.univ : Finset (Fin n)).powersetCard k) + +abbrev SignedVariableSet (n k : ℕ) := Σ s : VariableSet n k, ↥s.val → Bool + +def clauseFromSigns {n k : ℕ} (s : VariableSet n k) (b : ↥s.val → Bool) : + ProperClause n k := + ⟨fun i => if h : i ∈ s.val then some (b ⟨i, h⟩) else none, by + have hs : (Finset.univ.filter fun i : Fin n => + (if h : i ∈ s.val then some (b ⟨i, h⟩) else none).isSome) = s.val := by + ext i + by_cases hi : i ∈ s.val <;> simp [hi] + rw [hs] + exact (Finset.mem_powersetCard.mp s.property).2⟩ + +@[simp] theorem clauseSupport_fromSigns {n k : ℕ} (s : VariableSet n k) + (b : ↥s.val → Bool) : clauseSupport (clauseFromSigns s b) = s.val := by + ext i + by_cases hi : i ∈ s.val <;> simp [clauseSupport, clauseFromSigns, hi] + +def clauseToSigns {n k : ℕ} (C : ProperClause n k) : SignedVariableSet n k := + ⟨⟨clauseSupport C, Finset.mem_powersetCard.mpr + ⟨Finset.subset_univ _, clauseSupport_card C⟩⟩, + fun i => (C.val i.val).getD false⟩ + +def properClauseEquiv (n k : ℕ) : ProperClause n k ≃ SignedVariableSet n k where + toFun := clauseToSigns + invFun := fun t => clauseFromSigns t.1 t.2 + left_inv C := by + apply Subtype.ext + funext i + dsimp [clauseToSigns, clauseFromSigns] + by_cases hi : i ∈ clauseSupport C + · rw [ite_eq_left hi] + exact Option.getD_of_ne_none (Option.isSome_iff_ne_none.mp + ((mem_clauseSupport C i).mp hi)) false + · rw [ite_eq_right hi] + exact ((Option.not_isSome_iff_eq_none).mp (by simpa using hi)).symm + right_inv t := by + rcases t with ⟨s, b⟩ + apply Sigma.ext + · apply Subtype.ext + exact clauseSupport_fromSigns s b + · apply Function.hfunext (by + change ↥(clauseSupport (clauseFromSigns s b)) = ↥s.val + rw [clauseSupport_fromSigns]) + intro i j hij + apply heq_of_eq + have hv : i.val = j.val := by + exact (Subtype.heq_iff_coe_eq (fun x => by + change x ∈ clauseSupport (clauseFromSigns s b) ↔ x ∈ s.val + rw [clauseSupport_fromSigns])).mp hij + simp [clauseToSigns, clauseFromSigns, hv, j.property] + +@[simp] theorem card_variableSet (n k : ℕ) : + Fintype.card (VariableSet n k) = n.choose k := by + simp [VariableSet] + +@[simp] theorem card_properClause (n k : ℕ) : + Fintype.card (ProperClause n k) = n.choose k * 2 ^ k := by + rw [Fintype.card_congr (properClauseEquiv n k), Fintype.card_sigma] + have hc (s : VariableSet n k) : Fintype.card (↥s.val → Bool) = 2 ^ k := by + simp [(Finset.mem_powersetCard.mp s.property).2] + simp_rw [hc] + simp + +@[simp] theorem card_formula (n k m : ℕ) : + Fintype.card (Formula n k m) = (n.choose k * 2 ^ k) ^ m := by + simp [Formula] + +theorem nonempty_properClause {n k : ℕ} (hkn : k ≤ n) : + Nonempty (ProperClause n k) := by + apply Fintype.card_pos_iff.mp + rw [card_properClause] + exact Nat.mul_pos (Nat.choose_pos hkn) (by positivity) + +theorem satisfiable_empty (n k : ℕ) (F : Formula n k 0) : Satisfiable F := by + exact ⟨fun _ => false, fun i => Fin.elim0 i⟩ + +@[simp] theorem properSATProbability_zero (n k : ℕ) : properSATProbability n k 0 = 1 := by + classical + simp [properSATProbability, Fintype.card_subtype, satisfiable_empty] + +theorem properSATProbability_nonneg (n k m : ℕ) : + 0 ≤ properSATProbability n k m := by + unfold properSATProbability + positivity + +theorem properSATProbability_le_one (n k m : ℕ) : + properSATProbability n k m ≤ 1 := by + classical + unfold properSATProbability + by_cases h : Fintype.card (Formula n k m) = 0 + · simp [h] + · apply (div_le_one (by exact_mod_cast Nat.pos_of_ne_zero h)).mpr + exact_mod_cast Fintype.card_subtype_le (fun F : Formula n k m => Satisfiable F) + +def frozenCoordinates {n : ℕ} (S : Finset (Assignment n)) (σ₀ : Assignment n) : + Finset (Fin n) := + Finset.univ.filter fun i => ∀ σ ∈ S, σ i = σ₀ i + +def KillsSolutions {n k : ℕ} (S : Finset (Assignment n)) (C : ProperClause n k) : Prop := + ∀ σ ∈ S, ¬ SatisfiesClause σ C + +theorem kills_iff {n k : ℕ} (S : Finset (Assignment n)) (σ₀ : Assignment n) + (hσ₀ : σ₀ ∈ S) (C : ProperClause n k) : + KillsSolutions S C ↔ + clauseSupport C ⊆ frozenCoordinates S σ₀ ∧ + ∀ i ∈ clauseSupport C, C.val i = some (!(σ₀ i)) := by + constructor + · intro h + have hop (σ : Assignment n) (hσ : σ ∈ S) (i : Fin n) + (hi : i ∈ clauseSupport C) : C.val i = some (!(σ i)) := by + obtain ⟨b, hb⟩ := Option.isSome_iff_exists.mp ((mem_clauseSupport C i).mp hi) + have hne : b ≠ σ i := by + intro heq + exact h σ hσ ⟨i, hb.trans (congrArg some heq)⟩ + cases hb' : b <;> cases hv : σ i <;> simp_all + refine ⟨?_, hop σ₀ hσ₀⟩ + intro i hi + simp only [frozenCoordinates, Finset.mem_filter, Finset.mem_univ, true_and] + intro σ hσ + have heq := (hop σ hσ i hi).symm.trans (hop σ₀ hσ₀ i hi) + simpa using heq + · rintro ⟨hsub, hsign⟩ σ hσ ⟨i, hi⟩ + have his : i ∈ clauseSupport C := by + rw [mem_clauseSupport, hi] + rfl + have hf : σ i = σ₀ i := by + have hf := hsub his + simp only [frozenCoordinates, Finset.mem_filter, Finset.mem_univ, true_and] at hf + exact hf σ hσ + have heq := hi.symm.trans (hsign i his) + cases hv : σ₀ i <;> simp_all + +def forcedVariables {n : ℕ} (S : Finset (Assignment n)) : Finset (Fin n) := + Finset.univ.filter fun i => S.Nonempty ∧ ∃ b : Bool, ∀ σ ∈ S, σ i = b + +@[simp] theorem forcedVariables_empty (n : ℕ) : + forcedVariables (∅ : Finset (Assignment n)) = ∅ := by + simp [forcedVariables] + +theorem forcedVariables_eq_frozen {n : ℕ} {S : Finset (Assignment n)} + {σ₀ : Assignment n} (hσ₀ : σ₀ ∈ S) : + forcedVariables S = frozenCoordinates S σ₀ := by + ext i + simp only [forcedVariables, frozenCoordinates, mem_filter, mem_univ, true_and] + constructor + · rintro ⟨_, b, hb⟩ σ hσ + exact (hb σ hσ).trans (hb σ₀ hσ₀).symm + · intro h + exact ⟨⟨σ₀, hσ₀⟩, σ₀ i, h⟩ + +def opposingClause {n k : ℕ} (σ : Assignment n) (s : VariableSet n k) : + ProperClause n k := clauseFromSigns s (fun i => !(σ i.val)) + +@[simp] theorem support_opposingClause {n k : ℕ} (σ : Assignment n) + (s : VariableSet n k) : clauseSupport (opposingClause σ s) = s.val := + clauseSupport_fromSigns _ _ + +def killingClauseEquiv {n k : ℕ} (S : Finset (Assignment n)) (σ₀ : Assignment n) + (hσ₀ : σ₀ ∈ S) : + {C : ProperClause n k // KillsSolutions S C} ≃ + ↥((frozenCoordinates S σ₀).powersetCard k) where + toFun C := ⟨clauseSupport C.val, Finset.mem_powersetCard.mpr + ⟨((kills_iff S σ₀ hσ₀ C.val).mp C.property).1, clauseSupport_card C.val⟩⟩ + invFun s := ⟨opposingClause σ₀ ⟨s.val, Finset.mem_powersetCard.mpr + ⟨Finset.subset_univ _, (Finset.mem_powersetCard.mp s.property).2⟩⟩, by + apply (kills_iff S σ₀ hσ₀ _).mpr + simp only [support_opposingClause] + refine ⟨(Finset.mem_powersetCard.mp s.property).1, ?_⟩ + intro i hi + simp [opposingClause, clauseFromSigns, hi]⟩ + left_inv C := by + apply Subtype.ext + apply Subtype.ext + funext i + change (if i ∈ clauseSupport C.val then some (!(σ₀ i)) else none) = C.val.val i + by_cases hi : i ∈ clauseSupport C.val + · rw [ite_eq_left hi] + exact (((kills_iff S σ₀ hσ₀ C.val).mp C.property).2 i hi).symm + · rw [ite_eq_right hi] + apply Eq.symm + apply Option.not_isSome_iff_eq_none.mp + simpa only [mem_clauseSupport] using hi + right_inv s := by + apply Subtype.ext + exact support_opposingClause _ _ + +theorem card_killingClauses {n k : ℕ} (S : Finset (Assignment n)) + (hS : S.Nonempty) : + Fintype.card {C : ProperClause n k // KillsSolutions S C} = + (forcedVariables S).card.choose k := by + obtain ⟨σ₀, hσ₀⟩ := hS + rw [Fintype.card_congr (killingClauseEquiv S σ₀ hσ₀), + Fintype.card_coe, Finset.card_powersetCard, forcedVariables_eq_frozen hσ₀] + +noncomputable def uniformProbability {α : Type*} [Fintype α] (p : α → Prop) : ℝ := by + classical + exact (Fintype.card {a : α // p a} : ℝ) / Fintype.card α + +theorem uniformProbability_nonneg {α : Type*} [Fintype α] (p : α → Prop) : + 0 ≤ uniformProbability p := by + unfold uniformProbability + positivity + +theorem uniformProbability_le_one {α : Type*} [Fintype α] (p : α → Prop) : + uniformProbability p ≤ 1 := by + classical + unfold uniformProbability + by_cases h : Fintype.card α = 0 + · simp [h] + · apply (div_le_one (by exact_mod_cast Nat.pos_of_ne_zero h)).mpr + exact_mod_cast Fintype.card_subtype_le p + +theorem uniformProbability_mono {α : Type*} [Fintype α] {p q : α → Prop} + (hpq : ∀ a, p a → q a) : uniformProbability p ≤ uniformProbability q := by + classical + unfold uniformProbability + apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _) + exact_mod_cast Fintype.card_le_of_injective + (fun a : {a // p a} => (⟨a.val, hpq a.val a.property⟩ : {a // q a})) + (fun _ _ h => Subtype.ext (congrArg (fun t : {a // q a} => t.val) h)) + +noncomputable def killingProbability {n : ℕ} (k : ℕ) (S : Finset (Assignment n)) : ℝ := + uniformProbability (fun C : ProperClause n k => S.Nonempty ∧ KillsSolutions S C) + +theorem killingProbability_of_nonempty {n k : ℕ} (S : Finset (Assignment n)) + (hS : S.Nonempty) : + killingProbability k S = ((forcedVariables S).card.choose k : ℝ) / + ((n.choose k : ℝ) * 2 ^ k) := by + classical + unfold killingProbability uniformProbability + simp only [hS, true_and, card_killingClauses S hS, card_properClause, + Nat.cast_mul, Nat.cast_pow, Nat.cast_ofNat] + +@[simp] theorem killingProbability_empty (n k : ℕ) : + killingProbability k (∅ : Finset (Assignment n)) = 0 := by + classical + simp [killingProbability, uniformProbability] + +theorem killingProbability_eq {n k : ℕ} (hk : 0 < k) (S : Finset (Assignment n)) : + killingProbability k S = ((forcedVariables S).card.choose k : ℝ) / + ((n.choose k : ℝ) * 2 ^ k) := by + by_cases hS : S.Nonempty + · exact killingProbability_of_nonempty S hS + · have h : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS + subst S + simp [Nat.choose_eq_zero_of_lt hk] + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Concentration.lean b/lean/OAI/Probability/RandomSAT/Concentration.lean new file mode 100644 index 0000000000000000000000000000000000000000..5eee0a0a88a724afe9a0c8badda6e115681daaa2 --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Concentration.lean @@ -0,0 +1,280 @@ +import OAI.Probability.RandomSAT.Variance + +namespace OAI + +/-! +Normalized capped centers and polynomial concentration of the proper-clause +satisfiability probability. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +def capMultiplier (k : ℕ) : ℕ := 2^(k + 1) + +def mainCap (n k : ℕ) : ℕ := capMultiplier k * n + +def center (n k : ℕ) : ℝ := + lifetimeMean k (mainCap n k) (Finset.univ : Finset (Assignment n)) / n + +def varianceConstant (k : ℕ) : ℝ := + 2 * (capMultiplier k : ℝ)^3 * k * (2 * k + capMultiplier k + 2) + +theorem capMultiplier_pos (k : ℕ) : 0 < capMultiplier k := by + unfold capMultiplier + positivity + +theorem replacementBlock_le {n k : ℕ} (hn : 1 ≤ n) : + (replacementBlock n k : ℝ) ≤ (2 * k + 1) * replacementScale n k := by + have ha := replacementScale_one_le (k := k) hn + have hc := Nat.ceil_lt_add_one (show 0 ≤ 2 * (k : ℝ) * replacementScale n k by positivity) + change (replacementBlock n k : ℝ) < 2 * k * replacementScale n k + 1 at hc + nlinarith + +theorem replacementError_mul {n k : ℕ} (hn : 0 < n) (hk : 0 < k) : + (n : ℝ) * replacementError n k = replacementScale n k := by + have ha := replacementScale_pos (k := k) hn + have hp : replacementScale n k ^ (k - 1) * replacementScale n k = (n : ℝ) := by + rw [← pow_succ, Nat.sub_add_cancel hk, replacementScale_pow hn hk] + unfold replacementError + rw [inv_pow] + rw [mul_inv_eq_iff_eq_mul₀ (pow_ne_zero _ (ne_of_gt ha))] + nlinarith [hp] + +theorem integrated_forcing_capped {n k L : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) : + ∑ j ∈ Finset.range (L * n), forcedFractionMean n k j ≤ + ((L : ℝ) * k * (2 * k + L + 2)) * replacementScale n k := by + have hn0 : 0 < n := by omega + have hn1 : (1 : ℝ) ≤ n := by exact_mod_cast hn0 + have h := integrated_forcing_finite hk hn (L * n) + have hpartial : (∑ j ∈ Finset.range (L * n), forcedFractionMean n k j) ≤ + ∑ j ∈ Finset.range (L * n + 1), forcedFractionMean n k j := by + rw [Finset.sum_range_succ] + exact le_add_of_nonneg_right (uniformMean_nonneg (fun _ => by positivity)) + have heps := replacementError_mul (k := k) hn0 (by omega) + have hg := replacementBlock_le (k := k) (by omega : 1 ≤ n) + have ha := replacementScale_pos (k := k) hn0 + have he0 := replacementError_nonneg n k + have hclean : (replacementBlock n k : ℝ) * ((L * n : ℕ) : ℝ) * ((k : ℝ) / n) + + ((L * n + 1 : ℕ) : ℝ) * ((L * n : ℕ) : ℝ) * ((k : ℝ) / n) * replacementError n k = + (L : ℝ) * k * replacementBlock n k + + ((L : ℝ) * n + 1) * L * k * replacementError n k := by + simp only [Nat.cast_add, Nat.cast_mul, Nat.cast_one] + field_simp + rw [hclean] at h + have he : replacementError n k ≤ replacementScale n k := by + nlinarith [mul_nonneg (sub_nonneg.mpr hn1) he0] + have hg' := mul_le_mul_of_nonneg_left hg (by positivity : (0 : ℝ) ≤ L * k) + have he' := mul_le_mul_of_nonneg_left he (by positivity : (0 : ℝ) ≤ L * k) + have hp : ((L : ℝ) * n + 1) * L * k * replacementError n k = + (L : ℝ)^2 * k * replacementScale n k + L * k * replacementError n k := by + nlinarith [congrArg (fun x : ℝ => (L : ℝ)^2 * k * x) heps] + rw [hp] at h + nlinarith + +theorem variance_capped {n k : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) : + lifetimeVariance k (mainCap n k) (Finset.univ : Finset (Assignment n)) ≤ + varianceConstant k * n * replacementScale n k ^ 2 := by + have hL : (1 : ℝ) ≤ capMultiplier k := by exact_mod_cast capMultiplier_pos k + have hv := lifetimeVariance_forcing_bound (n := n) (k := k) (M := mainCap n k) + (L := capMultiplier k) (by omega) (by omega) hL (by simp [mainCap]) + have hf := integrated_forcing_capped (L := capMultiplier k) hk hn + have hmul := mul_le_mul_of_nonneg_left hf + (show 0 ≤ 2 * (mainCap n k : ℝ) * capMultiplier k * replacementScale n k by + have ha := replacementScale_pos (k := k) (by omega : 0 < n) + positivity) + apply hv.trans + exact hmul.trans_eq (by simp only [mainCap, Nat.cast_mul, varianceConstant]; ring) + +theorem uniform_chebyshev {α : Type*} [Fintype α] [Nonempty α] + (f : α → ℝ) {t : ℝ} (ht : 0 < t) : + uniformProbability (fun a => t ≤ |f a - uniformMean f|) ≤ uniformVariance f / t^2 := by + rw [le_div_iff₀ (sq_pos_of_pos ht), uniformProbability_eq_mean, ← uniformMean_mul_const] + apply uniformMean_mono + intro a + by_cases h : t ≤ |f a - uniformMean f| + · simp only [ite_eq_left h, one_mul] + nlinarith [sq_abs (f a - uniformMean f)] + · simp only [ite_eq_right h, zero_mul] + exact sq_nonneg _ + +theorem alive_univ (n : ℕ) : alive (Finset.univ : Finset (Assignment n)) = 1 := by + simp [alive] + +theorem uniformProbability_fin_succ {α : Type*} [Fintype α] {m : ℕ} + (p : (Fin (m + 1) → α) → Prop) : + uniformProbability p = uniformMean (fun C : α => uniformProbability + (fun F : Fin m → α => p (Fin.cons C F))) := by + rw [uniformProbability_eq_mean, uniformMean_fin_succ] + apply uniformMean_congr + intro C + exact (uniformProbability_eq_mean _).symm + +theorem lifetime_tail_probability {n k m M : ℕ} (hkn : k ≤ n) (hm : m ≤ M) + (S : Finset (Assignment n)) : + uniformProbability (fun F : Formula n k M => S.Nonempty ∧ (m : ℝ) ≤ lifetime k M S F) = + survival k m S := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + induction m generalizing M S with + | zero => + rw [uniformProbability_eq_mean, survival_zero] + have he : (fun F : Formula n k M => if S.Nonempty ∧ (0 : ℝ) ≤ lifetime k M S F + then (1 : ℝ) else 0) = fun _ => alive S := by + funext F + simp only [and_iff_left (lifetime_nonneg S F), alive] + simp only [Nat.cast_zero, he, uniformMean_const] + | succ m ih => + cases M with + | zero => omega + | succ M => + rw [uniformProbability_fin_succ] + have he (C : ProperClause n k) (F : Formula n k M) : + (S.Nonempty ∧ ((m + 1 : ℕ) : ℝ) ≤ lifetime k (M + 1) S (Fin.cons C F)) ↔ + (addClause S C).Nonempty ∧ (m : ℝ) ≤ lifetime k M (addClause S C) F := by + rw [lifetime_cons, Nat.cast_add, Nat.cast_one] + by_cases hC : (addClause S C).Nonempty + · have hS : S.Nonempty := hC.mono (addClause_subset S C) + simp only [hS, hC, alive, ite_true, true_and] + constructor <;> intro h <;> linarith + · have hempty : addClause S C = ∅ := Finset.not_nonempty_iff_eq_empty.mp hC + simp only [hempty, alive_empty, lifetime_empty, add_zero, Finset.not_nonempty_empty, + false_and] + have hm0 : (0 : ℝ) ≤ m := Nat.cast_nonneg _ + constructor + · rintro ⟨_, hh⟩; linarith + · exact False.elim + rw [survival_succ] + apply uniformMean_congr + intro C + exact (uniformProbability_congr (he C)).trans (ih (M := M) (by omega) (addClause S C)) + +theorem properSATProbability_eq_lifetime_tail {n k m M : ℕ} (hkn : k ≤ n) (hm : m ≤ M) : + properSATProbability n k m = uniformProbability (fun F : Formula n k M => + (m : ℝ) ≤ lifetime k M Finset.univ F) := by + rw [properSATProbability_eq_survival, ← lifetime_tail_probability hkn hm] + congr 1 + funext F + simp + +def delta (k : ℕ) : ℝ := ((k : ℝ) - 2) / (4 * k) + +def eta (k : ℕ) : ℝ := ((k : ℝ) - 2) / (2 * k) + +def fluctuationWindow (n k : ℕ) : ℝ := (n : ℝ) ^ (1 - delta k) + +def concentrationError (n k : ℕ) : ℝ := varianceConstant k * (n : ℝ) ^ (-eta k) + +theorem delta_pos {k : ℕ} (hk : 3 ≤ k) : 0 < delta k := by + have hk' : (3 : ℝ) ≤ k := by exact_mod_cast hk + unfold delta + exact div_pos (by linarith) (by positivity) + +theorem delta_lt_half {k : ℕ} (hk : 3 ≤ k) : delta k < 1 / 2 := by + have hk' : (3 : ℝ) ≤ k := by exact_mod_cast hk + rw [delta, div_lt_iff₀ (by positivity : (0 : ℝ) < 4 * k)] + linarith + +theorem eta_eq_twice_delta (k : ℕ) : eta k = 2 * delta k := by + unfold eta delta + ring + +theorem varianceConstant_nonneg (k : ℕ) : 0 ≤ varianceConstant k := by + unfold varianceConstant + positivity + +theorem fluctuationWindow_pos {n k : ℕ} (hn : 0 < n) : 0 < fluctuationWindow n k := + Real.rpow_pos_of_pos (by exact_mod_cast hn) _ + +theorem concentrationError_nonneg (n k : ℕ) : 0 ≤ concentrationError n k := + mul_nonneg (varianceConstant_nonneg k) (Real.rpow_nonneg (Nat.cast_nonneg _) _) + +theorem variance_window_identity {n k : ℕ} (hn : 0 < n) (hk : 0 < k) : + (n : ℝ) * replacementScale n k ^ 2 = + fluctuationWindow n k ^ 2 * (n : ℝ)^(-eta k) := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hk' : (k : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hk + have hexp : 1 + (1 / (k : ℝ)) * 2 = (1 - delta k) * 2 + -eta k := by + unfold delta eta + field_simp + ring + calc + _ = (n : ℝ)^(1 + (1 / (k : ℝ)) * 2) := by + rw [Real.rpow_add hn', Real.rpow_one, Real.rpow_mul hn'.le, Real.rpow_two] + rfl + _ = (n : ℝ)^((1 - delta k) * 2 + -eta k) := by rw [hexp] + _ = _ := by + rw [Real.rpow_add hn', Real.rpow_mul hn'.le, Real.rpow_two] + rfl + +theorem concentration_capped {n k : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) : + uniformProbability (fun F : Formula n k (mainCap n k) => + fluctuationWindow n k ≤ |lifetime k (mainCap n k) Finset.univ F - + (n : ℝ) * center n k|) ≤ concentrationError n k := by + let : Nonempty (ProperClause n k) := nonempty_properClause (by omega) + have hn0 : 0 < n := by omega + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn0 + have hm : (n : ℝ) * center n k = lifetimeMean k (mainCap n k) (Finset.univ : Finset (Assignment n)) := by + unfold center + field_simp + rw [hm] + have h := uniform_chebyshev (lifetime k (mainCap n k) (Finset.univ : Finset (Assignment n))) + (fluctuationWindow_pos (k := k) hn0) + apply h.trans + have hv := div_le_div_of_nonneg_right (variance_capped hk hn) + (sq_nonneg (fluctuationWindow n k)) + apply hv.trans_eq + have hid := variance_window_identity (k := k) hn0 (by omega) + unfold concentrationError + calc + _ = varianceConstant k * ((n : ℝ) * replacementScale n k^2) / fluctuationWindow n k^2 := by ring + _ = _ := by + rw [hid] + field_simp [ne_of_gt (fluctuationWindow_pos (k := k) hn0)] + +theorem center_nonneg (n k : ℕ) : 0 ≤ center n k := by + unfold center lifetimeMean + exact div_nonneg (uniformMean_nonneg (fun F => lifetime_nonneg _ F)) (Nat.cast_nonneg _) + +theorem center_le_capMultiplier {n k : ℕ} (hkn : k ≤ n) (hn : 0 < n) : + center n k ≤ capMultiplier k := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + have h := uniformMean_mono (fun F : Formula n k (mainCap n k) => lifetime_le Finset.univ F) + rw [uniformMean_const] at h + unfold center lifetimeMean + rw [div_le_iff₀ (by exact_mod_cast hn : (0 : ℝ) < n)] + simpa [mainCap] using h + +theorem properSATProbability_center_upper {n k m : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (hm : m ≤ mainCap n k) + (hgap : (n : ℝ) * center n k + fluctuationWindow n k ≤ m) : + properSATProbability n k m ≤ concentrationError n k := by + rw [properSATProbability_eq_lifetime_tail (by omega) hm] + apply (uniformProbability_mono (fun F hF => ?_)).trans (concentration_capped hk hn) + exact le_trans (by linarith) (le_abs_self _) + +theorem properSATProbability_center_lower {n k m : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (hm : m ≤ mainCap n k) + (hgap : (m : ℝ) + fluctuationWindow n k ≤ (n : ℝ) * center n k) : + 1 - concentrationError n k ≤ properSATProbability n k m := by + let : Nonempty (ProperClause n k) := nonempty_properClause (by omega) + rw [properSATProbability_eq_lifetime_tail (by omega) hm] + have h := uniformProbability_mono (p := fun F : Formula n k (mainCap n k) => + ¬ (m : ℝ) ≤ lifetime k (mainCap n k) Finset.univ F) + (q := fun F => fluctuationWindow n k ≤ + |lifetime k (mainCap n k) Finset.univ F - (n : ℝ) * center n k|) (fun F hF => by + have hh : lifetime k (mainCap n k) Finset.univ F < m := lt_of_not_ge hF + exact le_trans (by linarith) (neg_le_abs _)) + rw [uniformProbability_not] at h + linarith [concentration_capped hk hn] + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Convergence.lean b/lean/OAI/Probability/RandomSAT/Convergence.lean new file mode 100644 index 0000000000000000000000000000000000000000..143ad2b253a5950163564281ad3ecdf737bb9cca --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Convergence.lean @@ -0,0 +1,180 @@ +import OAI.Probability.RandomSAT.CenterComparison + +namespace OAI + +/-! +A balanced-block geometric potential proves convergence from boundedness and +summable-min comparisons, including block counts that are not powers of two. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +def balanceConstant (β : ℝ) : ℝ := (3 : ℝ)^β / ((3 / 2 : ℝ)^β - 1) + +theorem balanceConstant_pos {β : ℝ} (hβ : 0 < β) : 0 < balanceConstant β := + div_pos (Real.rpow_pos_of_pos (by norm_num) _) (sub_pos.mpr (Real.one_lt_rpow (by norm_num) hβ)) + +theorem balanced_power_potential {β a b q : ℝ} (hβ : 0 < β) (hb : 0 < b) + (hq : 0 < q) (haq : q / 3 ≤ a) (hbq : b ≤ q / (3 / 2)) : + a^(-β) ≤ balanceConstant β * (b^(-β) - q^(-β)) := by + have hA := Real.rpow_le_rpow_of_nonpos (div_pos hq (by norm_num)) haq (neg_nonpos.mpr hβ.le) + rw [Real.div_rpow hq.le (by norm_num : (0 : ℝ) ≤ 3), Real.rpow_neg (by norm_num : (0 : ℝ) ≤ 3), + div_inv_eq_mul] at hA + have hB := Real.rpow_le_rpow_of_nonpos hb hbq (neg_nonpos.mpr hβ.le) + rw [Real.div_rpow hq.le (by norm_num : (0 : ℝ) ≤ 3 / 2), + Real.rpow_neg (by norm_num : (0 : ℝ) ≤ 3 / 2), div_inv_eq_mul] at hB + have hd : (3 / 2 : ℝ)^β - 1 ≠ 0 := ne_of_gt (sub_pos.mpr (Real.one_lt_rpow (by norm_num) hβ)) + have hf : balanceConstant β * ((3 / 2 : ℝ)^β - 1) = (3 : ℝ)^β := by + exact div_mul_cancel₀ _ hd + calc + a^(-β) ≤ q^(-β) * (3 : ℝ)^β := hA + _ = balanceConstant β * (q^(-β) * ((3 / 2 : ℝ)^β - 1)) := by rw [← hf]; ring + _ ≤ balanceConstant β * (b^(-β) - q^(-β)) := + mul_le_mul_of_nonneg_left (by nlinarith [hB]) (balanceConstant_pos hβ).le + +theorem balanced_blocks_bound (u : ℕ → ℝ) {A β : ℝ} (hA : 0 ≤ A) (hβ : 0 < β) + {N s : ℕ} (hsN : N ≤ s) (hs : 0 < s) + (hadd : ∀ r ≥ N, ∀ t ≥ N, + min (u r) (u t) - A * (min r t : ℝ)^(-β) ≤ u (r + t)) + (hnext : u s - A * (s : ℝ)^(-β) ≤ u (s + 1)) : + ∀ q : ℕ, 1 ≤ q → ∀ r : ℕ, r ≤ q → + u s - A * (s : ℝ)^(-β) - + A * balanceConstant β * (s : ℝ)^(-β) * (1 - (q : ℝ)^(-β)) ≤ u (q * s + r) := by + intro q + induction q using Nat.strong_induction_on with + | h q ih => + intro hq r hr + have hs' : (0 : ℝ) < s := by exact_mod_cast hs + have hpow : 0 ≤ (s : ℝ)^(-β) := (Real.rpow_pos_of_pos hs' _).le + have hcoef : 0 ≤ A * balanceConstant β * (s : ℝ)^(-β) := + mul_nonneg (mul_nonneg hA (balanceConstant_pos hβ).le) hpow + by_cases hq1 : q = 1 + · subst q + have hr' : r = 0 ∨ r = 1 := by omega + rcases hr' with hr0 | hr1 + · subst r + simp only [Nat.cast_one, Real.one_rpow, sub_self, mul_zero, sub_zero, one_mul, add_zero] + exact sub_le_self _ (mul_nonneg hA hpow) + · subst r + simpa only [Nat.cast_one, Real.one_rpow, sub_self, mul_zero, sub_zero, one_mul] using hnext + · have hq2 : 2 ≤ q := by omega + let a := q / 2 + let b := q - a + let r₁ := min r a + let r₂ := r - r₁ + have ha : 1 ≤ a := by dsimp [a]; omega + have hb : 1 ≤ b := by dsimp [b, a]; omega + have haq : a < q := by dsimp [a]; omega + have hbq : b < q := by dsimp [b, a]; omega + have hab : a ≤ b := by dsimp [a, b]; omega + have habq : a + b = q := by dsimp [b, a]; omega + have hqa : q ≤ 3 * a := by dsimp [a]; omega + have hbq' : 3 * b ≤ 2 * q := by dsimp [b, a]; omega + have hr₁ : r₁ ≤ a := min_le_right r a + have hr₂ : r₂ ≤ b := by dsimp [r₂, r₁, b]; omega + have hrr : r₁ + r₂ = r := by dsimp [r₂, r₁]; omega + have hiA := ih a haq ha r₁ hr₁ + have hiB := ih b hbq hb r₂ hr₂ + have ha' : (0 : ℝ) < a := by exact_mod_cast ha + have hb' : (0 : ℝ) < b := by exact_mod_cast hb + have hq' : (0 : ℝ) < q := by exact_mod_cast hq + have habpow : (b : ℝ)^(-β) ≤ (a : ℝ)^(-β) := + Real.rpow_le_rpow_of_nonpos ha' (by exact_mod_cast hab) (neg_nonpos.mpr hβ.le) + have hchild : u s - A * (s : ℝ)^(-β) - + A * balanceConstant β * (s : ℝ)^(-β) * (1 - (b : ℝ)^(-β)) ≤ + min (u (a * s + r₁)) (u (b * s + r₂)) := by + apply le_min + · have hh := mul_le_mul_of_nonneg_left habpow hcoef + nlinarith + · exact hiB + have hsizeA : N ≤ a * s + r₁ := by nlinarith + have hsizeB : N ≤ b * s + r₂ := by nlinarith + have hsize : a * s ≤ min (a * s + r₁) (b * s + r₂) := by + apply le_min <;> nlinarith + have hminpos : (0 : ℝ) < (a : ℝ) * s := mul_pos ha' hs' + have hminpow := Real.rpow_le_rpow_of_nonpos hminpos + (show (a : ℝ) * s ≤ (min (a * s + r₁) (b * s + r₂) : ℝ) by exact_mod_cast hsize) + (neg_nonpos.mpr hβ.le) + rw [Real.mul_rpow ha'.le hs'.le] at hminpow + have herr := mul_le_mul_of_nonneg_left hminpow hA + have hpotential := balanced_power_potential hβ hb' hq' + (show (q : ℝ) / 3 ≤ a by + have hh : (q : ℝ) ≤ 3 * a := by exact_mod_cast hqa + linarith) + (show (b : ℝ) ≤ q / (3 / 2) by + have hh : 3 * (b : ℝ) ≤ 2 * q := by exact_mod_cast hbq' + linarith) + have hpot := mul_le_mul_of_nonneg_left hpotential (mul_nonneg hA hpow) + have hc := hadd (a * s + r₁) hsizeA (b * s + r₂) hsizeB + have he : a * s + r₁ + (b * s + r₂) = q * s + r := by + calc + _ = (a + b) * s + (r₁ + r₂) := by ring + _ = _ := by rw [habq, hrr] + rw [he] at hc + simp only [Nat.cast_add, Nat.cast_mul] at hc + nlinarith + +theorem balanced_tail_bound (u : ℕ → ℝ) {A β : ℝ} (hA : 0 ≤ A) (hβ : 0 < β) + {N s : ℕ} (hsN : N ≤ s) (hs : 0 < s) + (hadd : ∀ r ≥ N, ∀ t ≥ N, + min (u r) (u t) - A * (min r t : ℝ)^(-β) ≤ u (r + t)) + (hnext : u s - A * (s : ℝ)^(-β) ≤ u (s + 1)) : + ∀ n ≥ s * s, + u s - A * (1 + balanceConstant β) * (s : ℝ)^(-β) ≤ u n := by + intro n hn + have hq : s ≤ n / s := (Nat.le_div_iff_mul_le hs).mpr hn + have hr : n % s ≤ n / s := (Nat.mod_lt n hs).le.trans hq + have hb := balanced_blocks_bound u hA hβ hsN hs hadd hnext (n / s) (by omega) (n % s) hr + rw [Nat.mul_comm (n / s) s, Nat.div_add_mod] at hb + have hcoef : 0 ≤ A * balanceConstant β * (s : ℝ)^(-β) * ((n / s : ℕ) : ℝ)^(-β) := by + have hB := (balanceConstant_pos hβ).le + exact mul_nonneg (mul_nonneg (mul_nonneg hA hB) (Real.rpow_nonneg (Nat.cast_nonneg _) _)) + (Real.rpow_nonneg (Nat.cast_nonneg _) _) + nlinarith + +theorem summable_min_convergence (u : ℕ → ℝ) {A β : ℝ} (hA : 0 ≤ A) (hβ : 0 < β) + (hUpper : Filter.IsBoundedUnder (· ≤ ·) Filter.atTop u) + (hLower : Filter.IsBoundedUnder (· ≥ ·) Filter.atTop u) + (hcompare : ∃ N : ℕ, + (∀ r ≥ N, ∀ s ≥ N, min (u r) (u s) - A * (min r s : ℝ)^(-β) ≤ u (r + s)) ∧ + (∀ s ≥ N, u s - A * (s : ℝ)^(-β) ≤ u (s + 1))) : + Filter.Tendsto u Filter.atTop (nhds (Filter.limsup u Filter.atTop)) := by + obtain ⟨N, hadd, hnext⟩ := hcompare + let α := Filter.limsup u Filter.atTop + apply tendsto_order.mpr + constructor + · intro a ha + let ε := (α - a) / 3 + have hε : 0 < ε := by dsimp [ε, α]; linarith + have ht := (tendsto_rpow_neg_atTop hβ).comp (tendsto_natCast_atTop_atTop (R := ℝ)) + have hcost : Filter.Tendsto (fun s : ℕ => A * (1 + balanceConstant β) * (s : ℝ)^(-β)) + Filter.atTop (nhds 0) := by + simpa only [Function.comp_apply, mul_zero] using ht.const_mul (A * (1 + balanceConstant β)) + have hsmall := hcost.eventually_lt_const hε + have hhigh : ∃ᶠ s : ℕ in Filter.atTop, α - ε < u s := + Filter.frequently_lt_of_lt_limsup hLower.isCoboundedUnder_le (by change α - ε < α; linarith) + have hgood : ∀ᶠ s : ℕ in Filter.atTop, + N ≤ s ∧ 0 < s ∧ A * (1 + balanceConstant β) * (s : ℝ)^(-β) < ε := by + filter_upwards [Filter.eventually_ge_atTop (max N 1), hsmall] with s hs he + exact ⟨by omega, by omega, he⟩ + obtain ⟨s, hsHigh, hsN, hs, hsSmall⟩ := (hhigh.and_eventually hgood).exists + have htail := balanced_tail_bound u hA hβ hsN hs hadd (hnext s hsN) + filter_upwards [Filter.eventually_ge_atTop (s * s)] with n hn + have hh := htail n hn + dsimp [ε] at hsHigh hsSmall + linarith + · intro a ha + exact Filter.eventually_lt_of_limsup_lt ha hUpper + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/FiniteMean.lean b/lean/OAI/Probability/RandomSAT/FiniteMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..76db37b7e12c8eca98eb3b9ab770712e7a99b09a --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/FiniteMean.lean @@ -0,0 +1,125 @@ +import OAI.Probability.RandomSAT.Replacement + +namespace OAI + +/-! +Uniform finite expectations and variances. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +def uniformMean {α : Type*} [Fintype α] (f : α → ℝ) : ℝ := + (∑ a, f a) / Fintype.card α + +theorem uniformMean_congr {α : Type*} [Fintype α] {f g : α → ℝ} + (h : ∀ a, f a = g a) : uniformMean f = uniformMean g := by + unfold uniformMean + congr 1 + exact Finset.sum_congr rfl (fun a _ => h a) + +theorem uniformMean_const {α : Type*} [Fintype α] [Nonempty α] (c : ℝ) : + uniformMean (fun _ : α => c) = c := by + simp [uniformMean, ne_of_gt (Nat.cast_pos.mpr Fintype.card_pos : + (0 : ℝ) < Fintype.card α)] + +theorem uniformMean_zero {α : Type*} [Fintype α] : + uniformMean (fun _ : α => (0 : ℝ)) = 0 := by + simp [uniformMean] + +theorem uniformMean_add {α : Type*} [Fintype α] (f g : α → ℝ) : + uniformMean (fun a => f a + g a) = uniformMean f + uniformMean g := by + simp [uniformMean, Finset.sum_add_distrib, add_div] + +theorem uniformMean_sub {α : Type*} [Fintype α] (f g : α → ℝ) : + uniformMean (fun a => f a - g a) = uniformMean f - uniformMean g := by + simp [uniformMean, Finset.sum_sub_distrib, sub_div] + +theorem uniformMean_mul_const {α : Type*} [Fintype α] (f : α → ℝ) (c : ℝ) : + uniformMean (fun a => f a * c) = uniformMean f * c := by + simp only [uniformMean, ← Finset.sum_mul] + ring + +theorem uniformMean_const_mul {α : Type*} [Fintype α] (c : ℝ) (f : α → ℝ) : + uniformMean (fun a => c * f a) = c * uniformMean f := by + simp only [uniformMean, ← Finset.mul_sum] + ring + +theorem uniformMean_sum {α ι : Type*} [Fintype α] (s : Finset ι) (f : ι → α → ℝ) : + uniformMean (fun a => ∑ i ∈ s, f i a) = ∑ i ∈ s, uniformMean (f i) := by + unfold uniformMean + rw [Finset.sum_comm, Finset.sum_div] + +theorem uniformMean_nonneg {α : Type*} [Fintype α] {f : α → ℝ} + (h : ∀ a, 0 ≤ f a) : 0 ≤ uniformMean f := by + exact div_nonneg (Finset.sum_nonneg (fun a _ => h a)) (Nat.cast_nonneg _) + +theorem uniformMean_mono {α : Type*} [Fintype α] {f g : α → ℝ} + (h : ∀ a, f a ≤ g a) : uniformMean f ≤ uniformMean g := by + exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun a _ => h a)) (Nat.cast_nonneg _) + +theorem uniformMean_equiv {α β : Type*} [Fintype α] [Fintype β] + (e : α ≃ β) (f : β → ℝ) : uniformMean (fun a => f (e a)) = uniformMean f := by + unfold uniformMean + rw [e.sum_comp, Fintype.card_congr e] + +theorem uniformMean_prod {α β : Type*} [Fintype α] [Fintype β] + (f : α × β → ℝ) : uniformMean f = uniformMean (fun a => uniformMean (fun b => f (a,b))) := by + simp only [uniformMean, Fintype.sum_prod_type, Fintype.card_prod, Nat.cast_mul, + ← Finset.sum_div] + ring + +theorem uniformMean_comm {α β : Type*} [Fintype α] [Fintype β] + (f : α → β → ℝ) : + uniformMean (fun a => uniformMean (f a)) = + uniformMean (fun b => uniformMean (fun a => f a b)) := by + simp only [uniformMean, ← Finset.sum_div] + rw [Finset.sum_comm] + ring + +theorem uniformProbability_eq_mean {α : Type*} [Fintype α] (p : α → Prop) : + uniformProbability p = uniformMean (fun a => if p a then 1 else 0) := by + classical + unfold uniformProbability uniformMean + congr 1 + simp [Fintype.card_subtype] + +theorem uniformMean_sq_sub {α : Type*} [Fintype α] [Nonempty α] + (f : α → ℝ) (c : ℝ) : + uniformMean (fun a => (f a - c)^2) = + uniformMean (fun a => f a ^ 2) - 2 * c * uniformMean f + c^2 := by + calc + _ = uniformMean (fun a => (f a ^ 2 - (2 * c) * f a) + c^2) := + uniformMean_congr (fun _ => by ring) + _ = _ := by rw [uniformMean_add, uniformMean_sub, uniformMean_const_mul, uniformMean_const] + +theorem uniformMean_sq_ge {α : Type*} [Fintype α] [Nonempty α] + (f : α → ℝ) : uniformMean f ^ 2 ≤ uniformMean (fun a => f a ^ 2) := by + have h := uniformMean_nonneg (fun a => sq_nonneg (f a - uniformMean f)) + rw [uniformMean_sq_sub] at h + nlinarith + +def uniformVariance {α : Type*} [Fintype α] (f : α → ℝ) : ℝ := + uniformMean (fun a => (f a - uniformMean f)^2) + +theorem uniformVariance_eq {α : Type*} [Fintype α] [Nonempty α] + (f : α → ℝ) : uniformVariance f = uniformMean (fun a => f a^2) - uniformMean f ^ 2 := by + rw [uniformVariance, uniformMean_sq_sub] + ring + +theorem uniformVariance_le_sq_dist {α : Type*} [Fintype α] [Nonempty α] + (f : α → ℝ) (c : ℝ) : uniformVariance f ≤ uniformMean (fun a => (f a - c)^2) := by + rw [uniformVariance_eq, uniformMean_sq_sub] + nlinarith [sq_nonneg (uniformMean f - c)] + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Forcing.lean b/lean/OAI/Probability/RandomSAT/Forcing.lean new file mode 100644 index 0000000000000000000000000000000000000000..184c9e4ee433d820fef58ade0672ad34b08d141e --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Forcing.lean @@ -0,0 +1,554 @@ +import OAI.Probability.RandomSAT.Binomial + +namespace OAI + +/-! +Deletion and erasure of a coordinate, permutation symmetry, and the integrated +forcing bound. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +abbrev SplitClause (v k : ℕ) := ProperClause v k ⊕ (ProperClause v (k - 1) × Bool) + +def DeletedSatisfied {v k : ℕ} (σ : Assignment v) : SplitClause v k → Prop + | .inl C => SatisfiesClause σ C + | .inr _ => True + +def ErasedSatisfied {v k : ℕ} (σ : Assignment v) : SplitClause v k → Prop + | .inl C => SatisfiesClause σ C + | .inr Q => SatisfiesClause σ Q.1 + +def deletedSolutions {v k m : ℕ} (S : Finset (Assignment v)) (F : Fin m → SplitClause v k) : + Finset (Assignment v) := S.filter (fun σ => ∀ i, DeletedSatisfied σ (F i)) + +def erasedSolutions {v k m : ℕ} (S : Finset (Assignment v)) (F : Fin m → SplitClause v k) : + Finset (Assignment v) := S.filter (fun σ => ∀ i, ErasedSatisfied σ (F i)) + +@[simp] theorem mem_deletedSolutions {v k m : ℕ} (S : Finset (Assignment v)) + (F : Fin m → SplitClause v k) (σ : Assignment v) : + σ ∈ deletedSolutions S F ↔ σ ∈ S ∧ ∀ i, DeletedSatisfied σ (F i) := by + simp [deletedSolutions] + +@[simp] theorem mem_erasedSolutions {v k m : ℕ} (S : Finset (Assignment v)) + (F : Fin m → SplitClause v k) (σ : Assignment v) : + σ ∈ erasedSolutions S F ↔ σ ∈ S ∧ ∀ i, ErasedSatisfied σ (F i) := by + simp [erasedSolutions] + +theorem erasedSolutions_subset {v k m : ℕ} (S : Finset (Assignment v)) + (F : Fin m → SplitClause v k) : erasedSolutions S F ⊆ deletedSolutions S F := by + intro σ hσ + rw [mem_erasedSolutions] at hσ + rw [mem_deletedSolutions] + refine ⟨hσ.1, fun i => ?_⟩ + have hi := hσ.2 i + cases hFi : F i with + | inl C => simpa [ErasedSatisfied, DeletedSatisfied, hFi] using hi + | inr Q => trivial + +theorem satisfies_head_split {v k : ℕ} (hk : 0 < k) (σ : Assignment v) + (b : Bool) (X : SplitClause v k) : + SatisfiesClause (Fin.cons b σ) ((clauseHeadEquiv hk).symm X) ↔ + match X with + | .inl C => SatisfiesClause σ C + | .inr Q => Q.2 = b ∨ SatisfiesClause σ Q.1 := by + cases X with + | inl C => exact satisfiesClause_prependAbsent σ b C + | inr Q => exact satisfiesClause_prependPresent hk σ b Q.2 Q.1 + +theorem head_erasure_extension {v k m : ℕ} (hk : 0 < k) + (F : Fin m → SplitClause v k) {σ : Assignment v} + (hσ : σ ∈ erasedSolutions Finset.univ F) (b : Bool) : + Satisfies (Fin.cons b σ) (fun i => (clauseHeadEquiv hk).symm (F i)) := by + intro i + rw [satisfies_head_split] + have hi := ((mem_erasedSolutions _ _ _).mp hσ).2 i + cases hFi : F i with + | inl C => simpa [ErasedSatisfied, hFi] using hi + | inr Q => exact Or.inr (by simpa [ErasedSatisfied, hFi] using hi) + +theorem head_deletion_projection {v k m : ℕ} (hk : 0 < k) + (F : Fin m → SplitClause v k) {σ : Assignment (v + 1)} + (hσ : Satisfies σ (fun i => (clauseHeadEquiv hk).symm (F i))) : + Fin.tail σ ∈ deletedSolutions Finset.univ F := by + rw [mem_deletedSolutions] + refine ⟨Finset.mem_univ _, fun i => ?_⟩ + have hi := hσ i + rw [← Fin.cons_self_tail σ, satisfies_head_split] at hi + cases hFi : F i with + | inl C => simpa [DeletedSatisfied, hFi] using hi + | inr Q => trivial + +theorem head_forced_reduction {v k m : ℕ} (hk : 0 < k) (F : Fin m → SplitClause v k) + (hf : (0 : Fin (v + 1)) ∈ forcedVariables + (restrictSolutions Finset.univ (fun i => (clauseHeadEquiv hk).symm (F i)))) : + (deletedSolutions Finset.univ F).Nonempty ∧ ¬ (erasedSolutions Finset.univ F).Nonempty := by + simp only [forcedVariables, Finset.mem_filter, Finset.mem_univ, true_and] at hf + obtain ⟨σ, hσ⟩ := hf.1 + have hsat : Satisfies σ (fun i => (clauseHeadEquiv hk).symm (F i)) := + ((mem_restrictSolutions _ _ _).mp hσ).2 + refine ⟨⟨Fin.tail σ, head_deletion_projection hk F hsat⟩, ?_⟩ + rintro ⟨τ, hτ⟩ + obtain ⟨b, hb⟩ := hf.2 + have hext (t : Bool) : Fin.cons t τ ∈ + restrictSolutions Finset.univ (fun i => (clauseHeadEquiv hk).symm (F i)) := by + rw [mem_restrictSolutions] + exact ⟨Finset.mem_univ _, head_erasure_extension hk F hτ t⟩ + have hfalse := hb _ (hext false) + have htrue := hb _ (hext true) + simp only [Fin.cons_zero] at hfalse htrue + cases b <;> simp_all + +theorem head_forced_indicator_le {v k m : ℕ} (hk : 0 < k) (F : Fin m → SplitClause v k) : + (if (0 : Fin (v + 1)) ∈ forcedVariables + (restrictSolutions Finset.univ (fun i => (clauseHeadEquiv hk).symm (F i))) + then (1 : ℝ) else 0) ≤ + alive (deletedSolutions Finset.univ F) - alive (erasedSolutions Finset.univ F) := by + split + · rename_i h + obtain ⟨hd, he⟩ := head_forced_reduction hk F h + simp [alive, hd, he] + · have h := alive_mono (erasedSolutions_subset Finset.univ F) + linarith + +theorem deletedSolutions_cons_inl {v k m : ℕ} (S : Finset (Assignment v)) + (C : ProperClause v k) (F : Fin m → SplitClause v k) : + deletedSolutions S (Fin.cons (.inl C) F) = deletedSolutions (addClause S C) F := by + ext σ + simp only [mem_deletedSolutions, mem_addClause, Fin.forall_fin_succ, + Fin.cons_zero, Fin.cons_succ, DeletedSatisfied] + tauto + +theorem deletedSolutions_cons_inr {v k m : ℕ} (S : Finset (Assignment v)) + (Q : ProperClause v (k - 1)) (b : Bool) (F : Fin m → SplitClause v k) : + deletedSolutions S (Fin.cons (.inr (Q, b)) F) = deletedSolutions S F := by + ext σ + simp only [mem_deletedSolutions, Fin.forall_fin_succ, + Fin.cons_zero, Fin.cons_succ, DeletedSatisfied, true_and] + +theorem erasedSolutions_cons_inl {v k m : ℕ} (S : Finset (Assignment v)) + (C : ProperClause v k) (F : Fin m → SplitClause v k) : + erasedSolutions S (Fin.cons (.inl C) F) = erasedSolutions (addClause S C) F := by + ext σ + simp only [mem_erasedSolutions, mem_addClause, Fin.forall_fin_succ, + Fin.cons_zero, Fin.cons_succ, ErasedSatisfied] + tauto + +theorem erasedSolutions_cons_inr {v k m : ℕ} (S : Finset (Assignment v)) + (Q : ProperClause v (k - 1)) (b : Bool) (F : Fin m → SplitClause v k) : + erasedSolutions S (Fin.cons (.inr (Q, b)) F) = erasedSolutions (addClause S Q) F := by + ext σ + simp only [mem_erasedSolutions, mem_addClause, Fin.forall_fin_succ, + Fin.cons_zero, Fin.cons_succ, ErasedSatisfied] + tauto + +def deletedMean {v k : ℕ} (hk : 0 < k) (m : ℕ) (S : Finset (Assignment v)) : ℝ := + uniformMean (fun F : Formula (v + 1) k m => + alive (deletedSolutions S (fun i => clauseHeadSplit hk (F i)))) + +def erasedMean {v k : ℕ} (hk : 0 < k) (m : ℕ) (S : Finset (Assignment v)) : ℝ := + uniformMean (fun F : Formula (v + 1) k m => + alive (erasedSolutions S (fun i => clauseHeadSplit hk (F i)))) + +@[simp] theorem deletedMean_zero {v k : ℕ} (hk : 0 < k) (S : Finset (Assignment v)) : + deletedMean hk 0 S = alive S := by + have h (F : Formula (v + 1) k 0) : + deletedSolutions S (fun i => clauseHeadSplit hk (F i)) = S := by + ext σ + simp + simp only [deletedMean, h, uniformMean_const] + +@[simp] theorem erasedMean_zero {v k : ℕ} (hk : 0 < k) (S : Finset (Assignment v)) : + erasedMean hk 0 S = alive S := by + have h (F : Formula (v + 1) k 0) : + erasedSolutions S (fun i => clauseHeadSplit hk (F i)) = S := by + ext σ + simp + simp only [erasedMean, h, uniformMean_const] + +theorem deletedMean_succ {v k m : ℕ} (hk : 0 < k) (hkv : k ≤ v) + (S : Finset (Assignment v)) : + deletedMean hk (m + 1) S = + (1 - (k : ℝ) / (v + 1)) * clauseAverage k (deletedMean hk m) S + + ((k : ℝ) / (v + 1)) * deletedMean hk m S := by + let : Nonempty (ProperClause v (k - 1)) := nonempty_properClause (by omega) + unfold deletedMean + rw [uniformMean_fin_succ] + have hcons (C : ProperClause (v + 1) k) (F : Formula (v + 1) k m) : + (fun i : Fin (m + 1) => clauseHeadSplit hk ((Fin.cons C F : Formula (v + 1) k (m + 1)) i)) = + Fin.cons (clauseHeadSplit hk C) (fun i => clauseHeadSplit hk (F i)) := by + funext i + refine Fin.cases ?_ (fun _ => ?_) i <;> rfl + simp only [hcons] + rw [clauseHead_mean hk hkv (fun X => uniformMean (fun F : Formula (v + 1) k m => + alive (deletedSolutions S (Fin.cons X (fun i => clauseHeadSplit hk (F i))))))] + simp only [deletedSolutions_cons_inl, deletedSolutions_cons_inr, + uniformMean_const] + rfl + +theorem erasedMean_succ {v k m : ℕ} (hk : 0 < k) (hkv : k ≤ v) + (S : Finset (Assignment v)) : + erasedMean hk (m + 1) S = + (1 - (k : ℝ) / (v + 1)) * clauseAverage k (erasedMean hk m) S + + ((k : ℝ) / (v + 1)) * clauseAverage (k - 1) (erasedMean hk m) S := by + unfold erasedMean + rw [uniformMean_fin_succ] + have hcons (C : ProperClause (v + 1) k) (F : Formula (v + 1) k m) : + (fun i : Fin (m + 1) => clauseHeadSplit hk ((Fin.cons C F : Formula (v + 1) k (m + 1)) i)) = + Fin.cons (clauseHeadSplit hk C) (fun i => clauseHeadSplit hk (F i)) := by + funext i + refine Fin.cases ?_ (fun _ => ?_) i <;> rfl + simp only [hcons] + rw [clauseHead_mean hk hkv (fun X => uniformMean (fun F : Formula (v + 1) k m => + alive (erasedSolutions S (Fin.cons X (fun i => clauseHeadSplit hk (F i))))))] + simp only [erasedSolutions_cons_inl, erasedSolutions_cons_inr, + uniformMean_const] + rfl + +theorem clauseAverage_binomialMean {v k : ℕ} (p : ℝ) (m : ℕ) + (f : ℕ → Finset (Assignment v) → ℝ) (S : Finset (Assignment v)) : + clauseAverage k (fun T => binomialMean p m (fun d => f d T)) S = + binomialMean p m (fun d => clauseAverage k (f d) S) := + uniformMean_binomialMean p m _ + +theorem clauseAverage_survival {v k t : ℕ} (S : Finset (Assignment v)) : + clauseAverage k (survival k t) S = survival k (t + 1) S := + (survival_succ S).symm + +theorem clauseAverage_short_survival {n k t : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (S : Finset (Assignment (n - 1))) : + survival k (t + replacementBlock n k) S - replacementError n k ≤ + clauseAverage (k - 1) (survival k t) S := by + have h := clauseAverage_iterate_mono (k := k) (m := t) + (shorter_survival_replacement hk hn) S + rw [clauseAverage_iterate_sub_const (by omega)] at h + dsimp only at h + rw [survival_add] at h + have he : clauseAverage (k - 1) (survival k t) S = + ((clauseAverage k)^[t] (survival (k - 1) 1)) S := + survival_shift (m := 1) (d := t) S + rw [he] + simpa using h + +theorem deletedMean_eq_binomial {v k m : ℕ} (hk : 0 < k) (hkv : k ≤ v) + (S : Finset (Assignment v)) : + deletedMean hk m S = binomialMean ((k : ℝ) / (v + 1)) m + (fun d => survival k (m - d) S) := by + induction m generalizing S with + | zero => simp [binomialMean] + | succ m ih => + rw [deletedMean_succ hk hkv] + have hfun : deletedMean hk m = + (fun T : Finset (Assignment v) => binomialMean ((k : ℝ) / (v + 1)) m + (fun d => survival k (m - d) T)) := funext ih + rw [hfun, clauseAverage_binomialMean] + change _ = (1 - (k : ℝ) / (v + 1)) * _ + ((k : ℝ) / (v + 1)) * _ + congr 1 + · congr 1 + apply binomialMean_congr + intro d hd + rw [clauseAverage_survival] + congr 1 + omega + · congr 1 + apply binomialMean_congr + intro d _ + congr 1 + omega + +theorem erasedMean_replacement {n k m : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (S : Finset (Assignment (n - 1))) : + binomialMean ((k : ℝ) / n) m (fun d => + survival k (m - d + replacementBlock n k * d) S - + (d : ℝ) * replacementError n k) ≤ erasedMean (by omega : 0 < k) m S := by + have hkn : k ≤ n - 1 := by omega + have hshort : k - 1 ≤ n - 1 := by omega + have hn1 : n - 1 + 1 = n := by omega + have hp0 : 0 ≤ (k : ℝ) / n := by positivity + have hp1 : (k : ℝ) / n ≤ 1 := by + apply (div_le_one (by exact_mod_cast (by omega : 0 < n))).mpr + exact_mod_cast (by omega : k ≤ n) + induction m generalizing S with + | zero => simp [binomialMean] + | succ m ih => + rw [erasedMean_succ (by omega) hkn] + have hden : ((n - 1 : ℕ) : ℝ) + 1 = n := by exact_mod_cast hn1 + rw [hden] + have hlong := clauseAverage_mono (k := k) ih S + have hshorter := clauseAverage_mono (k := k - 1) ih S + rw [clauseAverage_binomialMean] at hlong hshorter + have ha : binomialMean ((k : ℝ) / n) m (fun d => + survival k (m + 1 - d + replacementBlock n k * d) S - + (d : ℝ) * replacementError n k) ≤ clauseAverage k (erasedMean (by omega : 0 < k) m) S := by + calc + _ = binomialMean ((k : ℝ) / n) m (fun d => clauseAverage k + (fun T => survival k (m - d + replacementBlock n k * d) T - + (d : ℝ) * replacementError n k) S) := by + apply binomialMean_congr + intro d hd + rw [clauseAverage_sub_const hkn, clauseAverage_survival] + congr 2 + omega + _ ≤ _ := hlong + have hb : binomialMean ((k : ℝ) / n) m (fun d => + survival k (m + 1 - (d + 1) + replacementBlock n k * (d + 1)) S - + ((d + 1 : ℕ) : ℝ) * replacementError n k) ≤ + clauseAverage (k - 1) (erasedMean (by omega : 0 < k) m) S := by + apply le_trans _ hshorter + apply binomialMean_mono hp0 hp1 + intro d _ + rw [clauseAverage_sub_const hshort] + have h := clauseAverage_short_survival (t := m - d + replacementBlock n k * d) hk hn S + have he : m + 1 - (d + 1) + replacementBlock n k * (d + 1) = + m - d + replacementBlock n k * d + replacementBlock n k := by + rw [Nat.mul_add, Nat.mul_one] + omega + rw [he] + push_cast + linarith + exact add_le_add (mul_le_mul_of_nonneg_left ha (sub_nonneg.mpr hp1)) + (mul_le_mul_of_nonneg_left hb hp0) + +theorem replacementBlock_pos {n k : ℕ} (hn : 0 < n) (hk : 0 < k) : + 1 ≤ replacementBlock n k := by + have hp : 0 < 2 * (k : ℝ) * replacementScale n k := + mul_pos (mul_pos (by norm_num) (by exact_mod_cast hk)) (replacementScale_pos hn) + exact Nat.ceil_pos.mpr hp + +theorem replacementError_nonneg (n k : ℕ) : 0 ≤ replacementError n k := by + unfold replacementError replacementScale + positivity + +def headForcedMean (v k m : ℕ) : ℝ := + uniformMean (fun F : Formula (v + 1) k m => + if (0 : Fin (v + 1)) ∈ forcedVariables (restrictSolutions Finset.univ F) + then (1 : ℝ) else 0) + +theorem headForcedMean_le_difference {v k m : ℕ} (hk : 0 < k) : + headForcedMean v k m ≤ deletedMean (v := v) hk m Finset.univ - erasedMean (v := v) hk m Finset.univ := by + unfold headForcedMean deletedMean erasedMean + rw [← uniformMean_sub] + apply uniformMean_mono + intro F + have he : (fun i => (clauseHeadEquiv hk).symm (clauseHeadSplit hk (F i))) = F := by + funext i + exact (clauseHeadEquiv hk).symm_apply_apply (F i) + have h := head_forced_indicator_le hk (fun i => clauseHeadSplit hk (F i)) + simpa only [he] using h + +theorem headForcedMean_replacement {v k m : ℕ} (hk : 3 ≤ k) (hkv : k ≤ v) : + headForcedMean v k m ≤ + binomialMean ((k : ℝ) / (v + 1)) m + (replacementDifference (properSATProbability v k) (replacementBlock (v + 1) k) m) + + ((m : ℝ) * ((k : ℝ) / (v + 1))) * replacementError (v + 1) k := by + have hdel := deletedMean_eq_binomial (m := m) (by omega : 0 < k) hkv Finset.univ + have her := erasedMean_replacement (n := v + 1) (m := m) hk (by omega) Finset.univ + simp only [Nat.cast_add, Nat.cast_one] at her + have hforced := headForcedMean_le_difference (v := v) (m := m) (by omega : 0 < k) + rw [hdel] at hforced + have hsub : (binomialMean ((k : ℝ) / (v + 1)) m (fun d => survival k (m - d) + (Finset.univ : Finset (Assignment v)))) - + binomialMean ((k : ℝ) / (v + 1)) m (fun d => + survival k (m - d + replacementBlock (v + 1) k * d) + (Finset.univ : Finset (Assignment v)) - + (d : ℝ) * replacementError (v + 1) k) = + binomialMean ((k : ℝ) / (v + 1)) m + (replacementDifference (properSATProbability v k) (replacementBlock (v + 1) k) m) + + ((m : ℝ) * ((k : ℝ) / (v + 1))) * replacementError (v + 1) k := by + rw [← binomialMean_sub] + have hg : 1 ≤ replacementBlock (v + 1) k := replacementBlock_pos (by omega) (by omega) + calc + _ = binomialMean ((k : ℝ) / (v + 1)) m (fun d => + replacementDifference (properSATProbability v k) (replacementBlock (v + 1) k) m d + + (d : ℝ) * replacementError (v + 1) k) := by + apply binomialMean_congr + intro d hd + unfold replacementDifference + rw [properSATProbability_eq_survival, properSATProbability_eq_survival] + have he : m - d + replacementBlock (v + 1) k * d = + m + (replacementBlock (v + 1) k - 1) * d := by + have hh := Nat.sub_add_cancel hg + have := congrArg (fun a : ℕ => a * d) hh + simp only [Nat.add_mul, Nat.one_mul] at this + omega + rw [he] + ring + _ = _ := by rw [binomialMean_add, binomialMean_mul_const, binomialMean_id] + rw [← hsub] + linarith + +theorem integrated_head_forcing {v k : ℕ} (hk : 3 ≤ k) (hkv : k ≤ v) (M : ℕ) : + ∑ j ∈ Finset.range (M + 1), headForcedMean v k j ≤ + (replacementBlock (v + 1) k : ℝ) * M * ((k : ℝ) / (v + 1)) + + ((M + 1 : ℕ) : ℝ) * M * ((k : ℝ) / (v + 1)) * replacementError (v + 1) k := by + have hp0 : 0 ≤ (k : ℝ) / (v + 1) := by positivity + have hp1 : (k : ℝ) / (v + 1) ≤ 1 := by + apply (div_le_one (by positivity)).mpr + exact_mod_cast (by omega : k ≤ v + 1) + calc + _ ≤ ∑ j ∈ Finset.range (M + 1), + (binomialMean ((k : ℝ) / (v + 1)) j + (replacementDifference (properSATProbability v k) (replacementBlock (v + 1) k) j) + + ((j : ℝ) * ((k : ℝ) / (v + 1))) * replacementError (v + 1) k) := + Finset.sum_le_sum (fun _ _ => headForcedMean_replacement hk hkv) + _ = _ := Finset.sum_add_distrib + _ ≤ _ := by + apply add_le_add + · exact binomial_replacement_sum_le hp0 hp1 (properSATProbability_antitone hkv) + (fun j => properSATProbability_nonneg v k j) (fun j => properSATProbability_le_one v k j) + (replacementBlock_pos (by omega) (by omega)) M + · calc + _ ≤ ∑ _j ∈ Finset.range (M + 1), + ((M : ℝ) * ((k : ℝ) / (v + 1))) * replacementError (v + 1) k := by + apply Finset.sum_le_sum + intro j hj + have hjM : (j : ℝ) ≤ M := by + exact_mod_cast (Nat.le_of_lt_succ (Finset.mem_range.mp hj)) + exact mul_le_mul_of_nonneg_right (mul_le_mul_of_nonneg_right hjM hp0) + (replacementError_nonneg (v + 1) k) + _ = _ := by simp; ring + +def renameClause {n k : ℕ} (e : Fin n ≃ Fin n) (C : ProperClause n k) : ProperClause n k := + ⟨fun i => C.val (e i), by + have h := Fintype.card_congr + (e.subtypeEquivOfSubtype (p := fun i => (C.val i).isSome)) + simp only [Fintype.card_subtype] at h + exact h.trans C.property⟩ + +def renameClauseEquiv {n k : ℕ} (e : Fin n ≃ Fin n) : ProperClause n k ≃ ProperClause n k where + toFun := renameClause e + invFun := renameClause e.symm + left_inv C := by apply Subtype.ext; funext i; simp [renameClause] + right_inv C := by apply Subtype.ext; funext i; simp [renameClause] + +def renameAssignment {n : ℕ} (e : Fin n ≃ Fin n) (σ : Assignment n) : Assignment n := + fun i => σ (e i) + +def renameFormula {n k m : ℕ} (e : Fin n ≃ Fin n) (F : Formula n k m) : Formula n k m := + fun i => renameClause e (F i) + +def renameFormulaEquiv {n k m : ℕ} (e : Fin n ≃ Fin n) : Formula n k m ≃ Formula n k m := + Equiv.piCongrRight (fun _ => renameClauseEquiv e) + +theorem renameFormulaEquiv_apply {n k m : ℕ} (e : Fin n ≃ Fin n) (F : Formula n k m) : + renameFormulaEquiv e F = renameFormula e F := rfl + +theorem satisfiesClause_rename {n k : ℕ} (e : Fin n ≃ Fin n) (σ : Assignment n) + (C : ProperClause n k) : + SatisfiesClause (renameAssignment e σ) (renameClause e C) ↔ SatisfiesClause σ C := by + change (∃ i, C.val (e i) = some (σ (e i))) ↔ ∃ i, C.val i = some (σ i) + constructor + · rintro ⟨i, hi⟩ + exact ⟨e i, hi⟩ + · rintro ⟨i, hi⟩ + exact ⟨e.symm i, by simpa using hi⟩ + +theorem satisfies_rename {n k m : ℕ} (e : Fin n ≃ Fin n) (σ : Assignment n) + (F : Formula n k m) : + Satisfies (renameAssignment e σ) (renameFormula e F) ↔ Satisfies σ F := by + simp only [Satisfies, renameFormula, satisfiesClause_rename] + +theorem satisfies_rename_inverse {n k m : ℕ} (e : Fin n ≃ Fin n) (σ : Assignment n) + (F : Formula n k m) : + Satisfies σ (renameFormula e F) ↔ Satisfies (renameAssignment e.symm σ) F := by + have h := satisfies_rename e (renameAssignment e.symm σ) F + have he : renameAssignment e (renameAssignment e.symm σ) = σ := by + funext i + exact congrArg σ (e.symm_apply_apply i) + rw [he] at h + exact h + +theorem satisfiable_rename {n k m : ℕ} (e : Fin n ≃ Fin n) (F : Formula n k m) : + Satisfiable (renameFormula e F) ↔ Satisfiable F := by + constructor + · rintro ⟨σ, hσ⟩ + exact ⟨renameAssignment e.symm σ, (satisfies_rename_inverse e σ F).mp hσ⟩ + · rintro ⟨σ, hσ⟩ + exact ⟨renameAssignment e σ, (satisfies_rename e σ F).mpr hσ⟩ + +theorem mem_forced_formula {n k m : ℕ} (F : Formula n k m) (i : Fin n) : + i ∈ forcedVariables (restrictSolutions Finset.univ F) ↔ + Satisfiable F ∧ ∃ b, ∀ σ, Satisfies σ F → σ i = b := by + simp [forcedVariables, Finset.Nonempty, Satisfiable, Satisfies] + +theorem forcedVariables_rename {n k m : ℕ} (e : Fin n ≃ Fin n) (F : Formula n k m) (i : Fin n) : + i ∈ forcedVariables (restrictSolutions Finset.univ (renameFormula e F)) ↔ + e i ∈ forcedVariables (restrictSolutions Finset.univ F) := by + rw [mem_forced_formula, mem_forced_formula, satisfiable_rename] + constructor + · rintro ⟨hS, b, hb⟩ + refine ⟨hS, b, fun σ hσ => ?_⟩ + exact hb (renameAssignment e σ) ((satisfies_rename e σ F).mpr hσ) + · rintro ⟨hS, b, hb⟩ + refine ⟨hS, b, fun σ hσ => ?_⟩ + have h := hb (renameAssignment e.symm σ) ((satisfies_rename_inverse e σ F).mp hσ) + simpa only [renameAssignment, Equiv.symm_apply_apply] using h + +theorem forced_coordinate_mean {v k m : ℕ} (i : Fin (v + 1)) : + uniformMean (fun F : Formula (v + 1) k m => + if i ∈ forcedVariables (restrictSolutions Finset.univ F) then (1 : ℝ) else 0) = + headForcedMean v k m := by + let e : Fin (v + 1) ≃ Fin (v + 1) := Equiv.swap 0 i + calc + _ = uniformMean (fun F : Formula (v + 1) k m => + if (0 : Fin (v + 1)) ∈ forcedVariables + (restrictSolutions Finset.univ (renameFormula e F)) then (1 : ℝ) else 0) := by + apply uniformMean_congr + intro F + simp only [forcedVariables_rename, e, Equiv.swap_apply_left] + _ = _ := by + have h := uniformMean_equiv (renameFormulaEquiv (n := v + 1) (k := k) (m := m) e) + (fun F : Formula (v + 1) k m => if (0 : Fin (v + 1)) ∈ forcedVariables + (restrictSolutions Finset.univ F) then (1 : ℝ) else 0) + have heq : (fun F : Formula (v + 1) k m => if (0 : Fin (v + 1)) ∈ forcedVariables + (restrictSolutions Finset.univ (renameFormula e F)) then (1 : ℝ) else 0) = + (fun F : Formula (v + 1) k m => if (0 : Fin (v + 1)) ∈ forcedVariables + (restrictSolutions Finset.univ (renameFormulaEquiv e F)) then (1 : ℝ) else 0) := by + funext F + apply ite_congr + · rfl + · intro _; rfl + · intro _; rfl + rw [heq] + exact h + +def forcedFractionMean (n k m : ℕ) : ℝ := + uniformMean (fun F : Formula n k m => + ((forcedVariables (restrictSolutions Finset.univ F)).card : ℝ) / n) + +theorem forcedFractionMean_eq_head (v k m : ℕ) : + forcedFractionMean (v + 1) k m = headForcedMean v k m := by + have hc (F : Formula (v + 1) k m) : + ((forcedVariables (restrictSolutions Finset.univ F)).card : ℝ) = + ∑ i : Fin (v + 1), if i ∈ forcedVariables (restrictSolutions Finset.univ F) + then (1 : ℝ) else 0 := by simp + unfold forcedFractionMean + simp_rw [hc, div_eq_mul_inv] + rw [uniformMean_mul_const, uniformMean_sum] + simp only [forced_coordinate_mean, Finset.sum_const, Finset.card_univ, + Fintype.card_fin, nsmul_eq_mul] + have hv : ((v + 1 : ℕ) : ℝ) ≠ 0 := by positivity + field_simp + +theorem integrated_forcing_finite {n k : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) (M : ℕ) : + ∑ j ∈ Finset.range (M + 1), forcedFractionMean n k j ≤ + (replacementBlock n k : ℝ) * M * ((k : ℝ) / n) + + ((M + 1 : ℕ) : ℝ) * M * ((k : ℝ) / n) * replacementError n k := by + cases n with + | zero => omega + | succ v => + simp only [forcedFractionMean_eq_head] + simpa only [Nat.cast_add, Nat.cast_one] using integrated_head_forcing hk (by omega) M + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Interpolation.lean b/lean/OAI/Probability/RandomSAT/Interpolation.lean new file mode 100644 index 0000000000000000000000000000000000000000..a21b32269e6b33c99431b47147f1f718ffd5e0ee --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Interpolation.lean @@ -0,0 +1,427 @@ +import OAI.Probability.RandomSAT.CenterBounds + +namespace OAI + +/-! +Auxiliary ordered clauses allow repeated variables. Commuting finite averaging +operators give the fixed-count partition interpolation corresponding to the +marked-Poisson comparison. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +abbrev AuxiliaryClause (n k : ℕ) := Fin k → (Fin n × Bool) + +def auxiliarySatisfies {n k : ℕ} (σ : Assignment n) (C : AuxiliaryClause n k) : Prop := + ∃ j, σ (C j).1 = (C j).2 + +def finiteClauseAverage {n : ℕ} {C : Type*} [Fintype C] + (sat : C → Assignment n → Prop) (f : Finset (Assignment n) → ℝ) + (S : Finset (Assignment n)) : ℝ := uniformMean (fun c => f (S.filter (sat c))) + +theorem finiteClauseAverage_mono {n : ℕ} {C : Type*} [Fintype C] + (sat : C → Assignment n → Prop) {f g : Finset (Assignment n) → ℝ} + (hfg : ∀ S, f S ≤ g S) : ∀ S, finiteClauseAverage sat f S ≤ finiteClauseAverage sat g S := by + intro S + exact uniformMean_mono (fun c => hfg _) + +theorem finiteClauseAverage_add {n : ℕ} {C : Type*} [Fintype C] + (sat : C → Assignment n → Prop) (f g : Finset (Assignment n) → ℝ) : + finiteClauseAverage sat (fun S => f S + g S) = + (fun S => finiteClauseAverage sat f S + finiteClauseAverage sat g S) := by + funext S + exact uniformMean_add _ _ + +theorem finiteClauseAverage_const_mul {n : ℕ} {C : Type*} [Fintype C] + (sat : C → Assignment n → Prop) (f : Finset (Assignment n) → ℝ) (c : ℝ) : + finiteClauseAverage sat (fun S => c * f S) = (fun S => c * finiteClauseAverage sat f S) := by + funext S + exact uniformMean_const_mul _ _ + +theorem finiteClauseAverage_mul_const {n : ℕ} {C : Type*} [Fintype C] + (sat : C → Assignment n → Prop) (f : Finset (Assignment n) → ℝ) (c : ℝ) : + finiteClauseAverage sat (fun S => f S * c) = (fun S => finiteClauseAverage sat f S * c) := by + funext S + exact uniformMean_mul_const _ _ + +theorem finiteClauseAverage_commute {n : ℕ} {C D : Type*} [Fintype C] [Fintype D] + (satC : C → Assignment n → Prop) (satD : D → Assignment n → Prop) : + Function.Commute (finiteClauseAverage satC) (finiteClauseAverage satD) := by + intro f + funext S + unfold finiteClauseAverage + rw [uniformMean_comm] + apply uniformMean_congr + intro d + apply uniformMean_congr + intro c + congr 1 + ext σ + simp only [Finset.mem_filter] + tauto + +theorem finiteClauseAverage_binomialMean {n : ℕ} {C : Type*} [Fintype C] + (sat : C → Assignment n → Prop) (p : ℝ) (m : ℕ) + (f : ℕ → Finset (Assignment n) → ℝ) : + finiteClauseAverage sat (fun S => binomialMean p m (fun j => f j S)) = + (fun S => binomialMean p m (fun j => finiteClauseAverage sat (f j) S)) := by + funext S + exact uniformMean_binomialMean _ _ _ + +theorem iterate_compare_of_commute {X : Type*} + (A B : (X → ℝ) → (X → ℝ)) (hA : Monotone A) (hB : Monotone B) + (hcomm : Function.Commute A B) {f : X → ℝ} (hf : B f ≤ A f) (m : ℕ) : + B^[m] f ≤ A^[m] f := by + induction m with + | zero => exact le_rfl + | succ m ih => + rw [Function.iterate_succ_apply', Function.iterate_succ_apply'] + calc + B (B^[m] f) ≤ B (A^[m] f) := hB ih + _ = A^[m] (B f) := (hcomm.symm.iterate_right m f) + _ ≤ A^[m] (A f) := hA.iterate m hf + _ = A (A^[m] f) := (Function.iterate_succ_apply A m f).symm.trans + (Function.iterate_succ_apply' A m f) + +def mixedAverage {X : Type*} (p : ℝ) (A B : (X → ℝ) → (X → ℝ)) + (f : X → ℝ) : X → ℝ := fun S => (1 - p) * B f S + p * A f S + +theorem mixedAverage_mono {X : Type*} {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + {A B : (X → ℝ) → (X → ℝ)} (hA : Monotone A) (hB : Monotone B) : + Monotone (mixedAverage p A B) := by + intro f g hfg S + exact add_le_add (mul_le_mul_of_nonneg_left (hB hfg S) (sub_nonneg.mpr hp1)) + (mul_le_mul_of_nonneg_left (hA hfg S) hp0) + +theorem finiteClauseAverage_commute_mix {n : ℕ} {C D E : Type*} + [Fintype C] [Fintype D] [Fintype E] (satC : C → Assignment n → Prop) + (satD : D → Assignment n → Prop) (satE : E → Assignment n → Prop) (p : ℝ) : + Function.Commute (finiteClauseAverage satC) + (mixedAverage p (finiteClauseAverage satD) (finiteClauseAverage satE)) := by + intro f + unfold mixedAverage + rw [finiteClauseAverage_add, finiteClauseAverage_const_mul, finiteClauseAverage_const_mul, + finiteClauseAverage_commute satC satD f, finiteClauseAverage_commute satC satE f] + +def embedAuxiliaryClause {n v k : ℕ} (e : Fin v → Fin n) (C : AuxiliaryClause v k) : + AuxiliaryClause n k := fun j => (e (C j).1, (C j).2) + +def embeddedAverage {n v : ℕ} (e : Fin v → Fin n) (k : ℕ) : + (Finset (Assignment n) → ℝ) → (Finset (Assignment n) → ℝ) := + finiteClauseAverage (fun C : AuxiliaryClause v k => fun σ => auxiliarySatisfies σ (embedAuxiliaryClause e C)) + +def auxiliaryAverage {n : ℕ} (k : ℕ) : + (Finset (Assignment n) → ℝ) → (Finset (Assignment n) → ℝ) := + embeddedAverage (id : Fin n → Fin n) k + +def auxiliarySurvival {n : ℕ} (k m : ℕ) (S : Finset (Assignment n)) : ℝ := + ((auxiliaryAverage k)^[m] alive) S + +def auxiliaryProbability (n k m : ℕ) : ℝ := + auxiliarySurvival k m (Finset.univ : Finset (Assignment n)) + +def embeddedForced {n v : ℕ} (S : Finset (Assignment n)) (e : Fin v → Fin n) : Finset (Fin v) := + Finset.univ.filter (fun i => e i ∈ forcedVariables S) + +@[simp] theorem mem_embeddedForced {n v : ℕ} (S : Finset (Assignment n)) (e : Fin v → Fin n) (i : Fin v) : + i ∈ embeddedForced S e ↔ e i ∈ forcedVariables S := by simp [embeddedForced] + +@[simp] theorem embeddedForced_id {n : ℕ} (S : Finset (Assignment n)) : + embeddedForced S (id : Fin n → Fin n) = forcedVariables S := by ext i; simp + +theorem opposing_literal_iff {n v : ℕ} (S : Finset (Assignment n)) (e : Fin v → Fin n) + (σ₀ : Assignment n) (hσ₀ : σ₀ ∈ S) (l : Fin v × Bool) : + (∀ σ ∈ S, σ (e l.1) ≠ l.2) ↔ + l.1 ∈ embeddedForced S e ∧ l.2 = !(σ₀ (e l.1)) := by + rw [mem_embeddedForced, forcedVariables_eq_frozen hσ₀] + simp only [frozenCoordinates, Finset.mem_filter, Finset.mem_univ, true_and] + constructor + · intro h + have h0 := h σ₀ hσ₀ + constructor + · intro σ hσ + have hs := h σ hσ + cases h1 : σ (e l.1) <;> cases h2 : σ₀ (e l.1) <;> cases h3 : l.2 <;> simp_all + · cases h2 : σ₀ (e l.1) <;> cases h3 : l.2 <;> simp_all + · rintro ⟨h, hb⟩ σ hσ + rw [h σ hσ, hb] + cases σ₀ (e l.1) <;> decide + +theorem opposing_literal_probability {n v : ℕ} (S : Finset (Assignment n)) + (e : Fin v → Fin n) (hS : S.Nonempty) : + uniformProbability (fun l : Fin v × Bool => ∀ σ ∈ S, σ (e l.1) ≠ l.2) = + ((embeddedForced S e).card : ℝ) / (2 * v) := by + obtain ⟨σ₀, hσ₀⟩ := hS + let eqv : {l : Fin v × Bool // ∀ σ ∈ S, σ (e l.1) ≠ l.2} ≃ ↥(embeddedForced S e) := { + toFun := fun l => ⟨l.val.1, ((opposing_literal_iff S e σ₀ hσ₀ l.val).mp l.property).1⟩ + invFun := fun i => ⟨(i.val, !(σ₀ (e i.val))), + (opposing_literal_iff S e σ₀ hσ₀ _).mpr ⟨i.property, rfl⟩⟩ + left_inv := fun l => by + apply Subtype.ext + change (l.val.1, !(σ₀ (e l.val.1))) = l.val + apply Prod.ext + · rfl + · exact ((opposing_literal_iff S e σ₀ hσ₀ l.val).mp l.property).2.symm + right_inv := fun _ => rfl } + unfold uniformProbability + simp only [← Nat.card_eq_fintype_card] + rw [Nat.card_congr eqv] + simp only [Nat.card_eq_fintype_card, Fintype.card_coe, Fintype.card_prod, + Fintype.card_fin, Fintype.card_bool, Nat.cast_mul, Nat.cast_ofNat] + rw [mul_comm (v : ℝ) 2] + +theorem embedded_kill_probability {n v k : ℕ} (S : Finset (Assignment n)) + (e : Fin v → Fin n) (hS : S.Nonempty) : + uniformProbability (fun C : AuxiliaryClause v k => + ¬ (S.filter fun σ => auxiliarySatisfies σ (embedAuxiliaryClause e C)).Nonempty) = + (((embeddedForced S e).card : ℝ) / (2 * v))^k := by + calc + _ = uniformProbability (fun C : AuxiliaryClause v k => + ∀ j, ∀ σ ∈ S, σ (e (C j).1) ≠ (C j).2) := by + apply uniformProbability_congr + intro C + constructor + · intro h j σ hσ heq + apply h + exact ⟨σ, Finset.mem_filter.mpr ⟨hσ, ⟨j, heq⟩⟩⟩ + · intro h ⟨σ, hσ⟩ + obtain ⟨hσ, j, hj⟩ := Finset.mem_filter.mp hσ + exact h j σ hσ hj + _ = _ := by + change (uniformProbability (fun C : Fin k → Fin v × Bool => + ∀ j, (fun l : Fin v × Bool => ∀ σ ∈ S, σ (e l.1) ≠ l.2) (C j))) = _ + have hf := uniformProbability_forall_fintype (α := Fin v × Bool) (β := Fin k) + (fun l => ∀ σ ∈ S, σ (e l.1) ≠ l.2) + simpa only [Fintype.card_fin, opposing_literal_probability S e hS] using hf + +theorem embeddedAverage_alive {n v k : ℕ} (hv : 0 < v) (e : Fin v → Fin n) + (S : Finset (Assignment n)) : + embeddedAverage e k alive S = alive S * + (1 - (((embeddedForced S e).card : ℝ) / (2 * v))^k) := by + let : NeZero v := ⟨Nat.ne_of_gt hv⟩ + by_cases hS : S.Nonempty + · have ha : alive S = 1 := by simp [alive, hS] + rw [ha, one_mul] + have h := uniformProbability_not (fun C : AuxiliaryClause v k => + (S.filter fun σ => auxiliarySatisfies σ (embedAuxiliaryClause e C)).Nonempty) + rw [embedded_kill_probability S e hS] at h + have he : embeddedAverage e k alive S = uniformProbability (fun C : AuxiliaryClause v k => + (S.filter fun σ => auxiliarySatisfies σ (embedAuxiliaryClause e C)).Nonempty) := by + rw [uniformProbability_eq_mean] + unfold embeddedAverage finiteClauseAverage + apply uniformMean_congr + intro C + by_cases hC : (S.filter fun σ => auxiliarySatisfies σ (embedAuxiliaryClause e C)).Nonempty + · simp only [alive, ite_eq_left hC] + · simp only [alive, ite_eq_right hC] + rw [he] + linarith + · have he : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS + subst S + simp [embeddedAverage, finiteClauseAverage, alive_empty, uniformMean_zero] + +theorem auxiliaryAverage_alive {n k : ℕ} (hn : 0 < n) (S : Finset (Assignment n)) : + auxiliaryAverage k alive S = alive S * (1 - (forcedFraction S / 2)^k) := by + rw [auxiliaryAverage, embeddedAverage_alive hn, embeddedForced_id] + congr 2 + unfold forcedFraction + ring + +theorem forced_card_partition {r s : ℕ} (S : Finset (Assignment (r + s))) : + (forcedVariables S).card = (embeddedForced S (Fin.castAdd s)).card + + (embeddedForced S (Fin.natAdd r)).card := by + have h := Fin.sum_univ_add (fun i : Fin (r + s) => + if i ∈ forcedVariables S then (1 : ℕ) else 0) + simpa only [← Finset.sum_filter, Finset.sum_const, smul_eq_mul, mul_one, + Finset.filter_mem_eq_inter, Finset.univ_inter, embeddedForced] using h + +theorem partition_kill_convex {r s k : ℕ} (hr : 0 < r) (hs : 0 < s) + (S : Finset (Assignment (r + s))) : + (forcedFraction S / 2)^k ≤ + ((r : ℝ) / (r + s)) * (((embeddedForced S (Fin.castAdd s)).card : ℝ) / (2 * r))^k + + ((s : ℝ) / (r + s)) * (((embeddedForced S (Fin.natAdd r)).card : ℝ) / (2 * s))^k := by + have hr' : (0 : ℝ) < r := by exact_mod_cast hr + have hs' : (0 : ℝ) < s := by exact_mod_cast hs + have hsum : (r : ℝ) / (r + s) + (s : ℝ) / (r + s) = 1 := by field_simp + have h := (convexOn_pow (𝕜 := ℝ) k).2 + (show ((embeddedForced S (Fin.castAdd s)).card : ℝ) / (2 * r) ∈ Set.Ici (0 : ℝ) by simp only [Set.mem_Ici]; positivity) + (show ((embeddedForced S (Fin.natAdd r)).card : ℝ) / (2 * s) ∈ Set.Ici (0 : ℝ) by simp only [Set.mem_Ici]; positivity) + (show 0 ≤ (r : ℝ) / (r + s) by positivity) + (show 0 ≤ (s : ℝ) / (r + s) by positivity) hsum + simp only [smul_eq_mul] at h + convert h using 1 + congr 1 + unfold forcedFraction + rw [forced_card_partition, Nat.cast_add, Nat.cast_add] + field_simp + +theorem globalAverage_ge_local {r s k : ℕ} (hr : 0 < r) (hs : 0 < s) : + mixedAverage ((r : ℝ) / (r + s)) (embeddedAverage (Fin.castAdd s) k) + (embeddedAverage (Fin.natAdd r) k) alive ≤ auxiliaryAverage k alive := by + intro S + have hr' : (0 : ℝ) < r := by exact_mod_cast hr + have hs' : (0 : ℝ) < s := by exact_mod_cast hs + have hw : 1 - (r : ℝ) / (r + s) = (s : ℝ) / (r + s) := by field_simp; ring + unfold mixedAverage + rw [embeddedAverage_alive hr, embeddedAverage_alive hs, auxiliaryAverage_alive (by omega), hw] + have h := mul_le_mul_of_nonneg_left (partition_kill_convex (k := k) hr hs S) (alive_nonneg S) + have hsum : (r : ℝ) / (r + s) + (s : ℝ) / (r + s) = 1 := by field_simp + have hsum_mul := congrArg (fun x : ℝ => alive S * x) hsum + nlinarith + +theorem mixed_finiteAverage_iterate {n : ℕ} {C D : Type*} [Fintype C] [Fintype D] + (satC : C → Assignment n → Prop) (satD : D → Assignment n → Prop) + (p : ℝ) (m : ℕ) (f : Finset (Assignment n) → ℝ) : + (mixedAverage p (finiteClauseAverage satC) (finiteClauseAverage satD))^[m] f = + (fun S => binomialMean p m (fun j => + ((finiteClauseAverage satC)^[j] ((finiteClauseAverage satD)^[m - j] f)) S)) := by + induction m with + | zero => simp [binomialMean] + | succ m ih => + rw [Function.iterate_succ_apply', ih] + unfold mixedAverage + rw [finiteClauseAverage_binomialMean, finiteClauseAverage_binomialMean] + funext S + rw [binomialMean] + congr 1 + · congr 1 + apply binomialMean_congr + intro j hj + rw [(finiteClauseAverage_commute satD satC).iterate_right j, + ← Function.iterate_succ_apply' (finiteClauseAverage satD) (m - j) f] + rw [show (m - j).succ = m.succ - j by omega] + · congr 1 + apply binomialMean_congr + intro j hj + rw [← Function.iterate_succ_apply' (finiteClauseAverage satC) j] + simp only [Nat.add_sub_add_right] + +def blockSet {r s : ℕ} (S : Finset (Assignment r)) (T : Finset (Assignment s)) : + Finset (Assignment (r + s)) := + Finset.univ.filter (fun σ => (fun i => σ (Fin.castAdd s i)) ∈ S ∧ + (fun i => σ (Fin.natAdd r i)) ∈ T) + +@[simp] theorem mem_blockSet {r s : ℕ} (S : Finset (Assignment r)) (T : Finset (Assignment s)) + (σ : Assignment (r + s)) : σ ∈ blockSet S T ↔ + (fun i => σ (Fin.castAdd s i)) ∈ S ∧ (fun i => σ (Fin.natAdd r i)) ∈ T := by + simp [blockSet] + +@[simp] theorem blockSet_univ (r s : ℕ) : + blockSet (Finset.univ : Finset (Assignment r)) (Finset.univ : Finset (Assignment s)) = + Finset.univ := by ext σ; simp + +theorem blockSet_nonempty {r s : ℕ} (S : Finset (Assignment r)) (T : Finset (Assignment s)) : + (blockSet S T).Nonempty ↔ S.Nonempty ∧ T.Nonempty := by + constructor + · rintro ⟨σ, hσ⟩ + have h := (mem_blockSet S T σ).mp hσ + exact ⟨⟨_, h.1⟩, ⟨_, h.2⟩⟩ + · rintro ⟨⟨σ, hσ⟩, ⟨τ, hτ⟩⟩ + refine ⟨Fin.addCases σ τ, ?_⟩ + simpa only [mem_blockSet, Fin.addCases_left, Fin.addCases_right] using And.intro hσ hτ + +theorem alive_blockSet {r s : ℕ} (S : Finset (Assignment r)) (T : Finset (Assignment s)) : + alive (blockSet S T) = alive S * alive T := by + simp only [alive, blockSet_nonempty] + split_ifs <;> simp_all + +theorem filter_blockSet_left {r s k : ℕ} (S : Finset (Assignment r)) + (T : Finset (Assignment s)) (C : AuxiliaryClause r k) : + (blockSet S T).filter (fun σ => auxiliarySatisfies σ (embedAuxiliaryClause (Fin.castAdd s) C)) = + blockSet (S.filter (fun σ => auxiliarySatisfies σ C)) T := by + ext σ + constructor + · intro h + obtain ⟨hσ, hC⟩ := Finset.mem_filter.mp h + obtain ⟨hS, hT⟩ := (mem_blockSet S T σ).mp hσ + exact (mem_blockSet _ _ σ).mpr ⟨Finset.mem_filter.mpr ⟨hS, hC⟩, hT⟩ + · intro h + obtain ⟨hS, hT⟩ := (mem_blockSet _ _ σ).mp h + obtain ⟨hS, hC⟩ := Finset.mem_filter.mp hS + exact Finset.mem_filter.mpr ⟨(mem_blockSet S T σ).mpr ⟨hS, hT⟩, hC⟩ + +theorem filter_blockSet_right {r s k : ℕ} (S : Finset (Assignment r)) + (T : Finset (Assignment s)) (C : AuxiliaryClause s k) : + (blockSet S T).filter (fun σ => auxiliarySatisfies σ (embedAuxiliaryClause (Fin.natAdd r) C)) = + blockSet S (T.filter (fun σ => auxiliarySatisfies σ C)) := by + ext σ + constructor + · intro h + obtain ⟨hσ, hC⟩ := Finset.mem_filter.mp h + obtain ⟨hS, hT⟩ := (mem_blockSet S T σ).mp hσ + exact (mem_blockSet _ _ σ).mpr ⟨hS, Finset.mem_filter.mpr ⟨hT, hC⟩⟩ + · intro h + obtain ⟨hS, hT⟩ := (mem_blockSet _ _ σ).mp h + obtain ⟨hT, hC⟩ := Finset.mem_filter.mp hT + exact Finset.mem_filter.mpr ⟨(mem_blockSet S T σ).mpr ⟨hS, hT⟩, hC⟩ + +theorem auxiliarySurvival_succ {n k m : ℕ} (S : Finset (Assignment n)) : + auxiliarySurvival k (m + 1) S = uniformMean (fun C : AuxiliaryClause n k => + auxiliarySurvival k m (S.filter (fun σ => auxiliarySatisfies σ C))) := by + unfold auxiliarySurvival + rw [Function.iterate_succ_apply'] + rfl + +theorem local_iterates_block {r s k : ℕ} (j l : ℕ) (S : Finset (Assignment r)) + (T : Finset (Assignment s)) : + ((embeddedAverage (Fin.castAdd s) k)^[j] + ((embeddedAverage (Fin.natAdd r) k)^[l] alive)) (blockSet S T) = + auxiliarySurvival k j S * auxiliarySurvival k l T := by + induction j generalizing S T with + | zero => + simp only [Function.iterate_zero, id_eq] + change _ = alive S * auxiliarySurvival k l T + induction l generalizing T with + | zero => exact alive_blockSet S T + | succ l ih => + rw [Function.iterate_succ_apply', auxiliarySurvival_succ, ← uniformMean_const_mul] + unfold embeddedAverage finiteClauseAverage + apply uniformMean_congr + intro C + rw [filter_blockSet_right] + exact ih _ + | succ j ih => + rw [Function.iterate_succ_apply', auxiliarySurvival_succ, ← uniformMean_mul_const] + unfold embeddedAverage finiteClauseAverage + apply uniformMean_congr + intro C + rw [filter_blockSet_left] + exact ih _ _ + +theorem auxiliary_interpolation {r s k : ℕ} (hr : 0 < r) (hs : 0 < s) (m : ℕ) : + binomialMean ((r : ℝ) / (r + s)) m (fun j => + auxiliaryProbability r k j * auxiliaryProbability s k (m - j)) ≤ + auxiliaryProbability (r + s) k m := by + have hp0 : 0 ≤ (r : ℝ) / (r + s) := by positivity + have hp1 : (r : ℝ) / (r + s) ≤ 1 := by + apply (div_le_one (by positivity : (0 : ℝ) < r + s)).mpr + exact le_add_of_nonneg_right (Nat.cast_nonneg s) + have h := iterate_compare_of_commute (auxiliaryAverage (n := r + s) k) + (mixedAverage ((r : ℝ) / (r + s)) (embeddedAverage (Fin.castAdd s) k) + (embeddedAverage (Fin.natAdd r) k)) + (fun _ _ h => finiteClauseAverage_mono _ h) (mixedAverage_mono hp0 hp1 + (fun _ _ h => finiteClauseAverage_mono _ h) (fun _ _ h => finiteClauseAverage_mono _ h)) + (finiteClauseAverage_commute_mix _ _ _ _) (globalAverage_ge_local hr hs) m Finset.univ + change _ ≤ auxiliaryProbability (r + s) k m at h + convert h using 1 + unfold embeddedAverage + rw [mixed_finiteAverage_iterate] + apply binomialMean_congr + intro j hj + change _ = ((embeddedAverage (Fin.castAdd s) k)^[j] + ((embeddedAverage (Fin.natAdd r) k)^[m - j] alive)) Finset.univ + rw [← blockSet_univ r s, local_iterates_block] + rfl + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Main.lean b/lean/OAI/Probability/RandomSAT/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..30540d9a10c1d86955b05f15e1fc2c2920b37176 --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Main.lean @@ -0,0 +1,134 @@ +import OAI.Probability.RandomSAT.Convergence + +namespace OAI + +/-! +For every fixed clause size at least three, the proper-clause satisfiability +probability has a positive finite limiting threshold. No conclusion is asserted +at the critical density. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +def limitingCenter (k : ℕ) : ℝ := Filter.limsup (fun n : ℕ => center n k) Filter.atTop + +theorem center_tendsto (k : ℕ) (hk : 3 ≤ k) : + Filter.Tendsto (fun n : ℕ => center n k) Filter.atTop (nhds (limitingCenter k)) := by + have hb := center_bounds_eventually k hk + have hUpper : Filter.IsBoundedUnder (· ≤ ·) Filter.atTop (fun n : ℕ => center n k) := + Filter.isBoundedUnder_of_eventually_le (hb.mono (fun _ h => h.2)) + have hLower : Filter.IsBoundedUnder (· ≥ ·) Filter.atTop (fun n : ℕ => center n k) := + Filter.isBoundedUnder_of_eventually_ge (hb.mono (fun _ h => h.1)) + apply summable_min_convergence (fun n => center n k) (by norm_num : (0 : ℝ) ≤ 4) + (delta_pos hk) hUpper hLower + obtain ⟨N, hadd, hnext⟩ := center_comparisons k hk + refine ⟨N, ?_, ?_⟩ + · intro r hr s hs + simpa only [densityWindow, Nat.cast_min] using hadd r hr s hs + · intro s hs + exact hnext s hs + +theorem limitingCenter_bounds (k : ℕ) (hk : 3 ≤ k) : + lowerCenterBound ≤ limitingCenter k ∧ limitingCenter k ≤ (2 : ℝ)^k + 1 := by + have ht := center_tendsto k hk + have hb := center_bounds_eventually k hk + exact ⟨ge_of_tendsto ht (hb.mono (fun _ h => h.1)), le_of_tendsto ht (hb.mono (fun _ h => h.2))⟩ + +theorem limitingCenter_pos (k : ℕ) (hk : 3 ≤ k) : 0 < limitingCenter k := + lowerCenterBound_pos.trans_le (limitingCenter_bounds k hk).1 + +theorem limitingCenter_lt_cap (k : ℕ) (hk : 3 ≤ k) : limitingCenter k < capMultiplier k := by + have hp : (1 : ℝ) < 2^k := one_lt_pow₀ (by norm_num) (by omega : k ≠ 0) + have he : (capMultiplier k : ℝ) = 2^k * 2 := by simp [capMultiplier, pow_succ] + rw [he] + have h := (limitingCenter_bounds k hk).2 + linarith + +theorem floor_density_le_cap {n k : ℕ} {c : ℝ} (hc0 : 0 ≤ c) (hcL : c ≤ capMultiplier k) : + ⌊c * (n : ℝ)⌋₊ ≤ mainCap n k := by + have h := (Nat.floor_le (mul_nonneg hc0 (Nat.cast_nonneg n : (0 : ℝ) ≤ n))).trans + (mul_le_mul_of_nonneg_right hcL (Nat.cast_nonneg n : (0 : ℝ) ≤ n)) + exact_mod_cast (show (⌊c * (n : ℝ)⌋₊ : ℝ) ≤ (mainCap n k : ℝ) by + simpa only [mainCap, Nat.cast_mul] using h) + +theorem subcritical_limit (k : ℕ) (hk : 3 ≤ k) (c : ℝ) (hc0 : 0 ≤ c) + (hc : c < limitingCenter k) : + Filter.Tendsto (fun n : ℕ => properSATProbability n k ⌊c * (n : ℝ)⌋₊) + Filter.atTop (nhds 1) := by + have hcL : c ≤ capMultiplier k := (hc.trans (limitingCenter_lt_cap k hk)).le + have hcenter : Filter.Tendsto (fun n : ℕ => center n k - densityWindow n k) + Filter.atTop (nhds (limitingCenter k)) := by + simpa only [sub_zero] using (center_tendsto k hk).sub (densityWindow_tendsto k hk) + have hmargin := hcenter.eventually (Ioi_mem_nhds hc) + have hlower : ∀ᶠ n : ℕ in Filter.atTop, + 1 - concentrationError n k ≤ properSATProbability n k ⌊c * (n : ℝ)⌋₊ := by + filter_upwards [hmargin, Filter.eventually_ge_atTop (k + 1)] with n hmargin hn + apply properSATProbability_center_lower hk hn (floor_density_le_cap hc0 hcL) + have hn0 : 0 < n := by omega + have hn' : (0 : ℝ) < n := by exact_mod_cast hn0 + rw [fluctuationWindow_eq_mul hn0] + have hmul := mul_le_mul_of_nonneg_left hmargin.le hn'.le + have hf := Nat.floor_le (mul_nonneg hc0 hn'.le) + nlinarith + have hlowT : Filter.Tendsto (fun n : ℕ => 1 - concentrationError n k) Filter.atTop (nhds 1) := by + simpa only [sub_zero] using (concentrationError_tendsto k hk).const_sub 1 + exact tendsto_of_tendsto_of_tendsto_of_le_of_le' hlowT tendsto_const_nhds hlower + (Filter.Eventually.of_forall fun n => properSATProbability_le_one n k _) + +theorem supercritical_limit_below_cap (k : ℕ) (hk : 3 ≤ k) (c : ℝ) + (hc : limitingCenter k < c) (hcL : c ≤ capMultiplier k) : + Filter.Tendsto (fun n : ℕ => properSATProbability n k ⌊c * (n : ℝ)⌋₊) + Filter.atTop (nhds 0) := by + have hc0 : 0 ≤ c := ((limitingCenter_pos k hk).trans hc).le + have hd : Filter.Tendsto (fun n : ℕ => 2 * densityWindow n k) Filter.atTop (nhds 0) := by + simpa only [mul_zero] using (densityWindow_tendsto k hk).const_mul (2 : ℝ) + have hcenter : Filter.Tendsto (fun n : ℕ => center n k + 2 * densityWindow n k) + Filter.atTop (nhds (limitingCenter k)) := by + simpa only [add_zero] using (center_tendsto k hk).add hd + have hmargin := hcenter.eventually_lt_const hc + have hupper : ∀ᶠ n : ℕ in Filter.atTop, + properSATProbability n k ⌊c * (n : ℝ)⌋₊ ≤ concentrationError n k := by + filter_upwards [hmargin, Filter.eventually_ge_atTop (k + 1)] with n hmargin hn + apply properSATProbability_center_upper hk hn (floor_density_le_cap hc0 hcL) + have hn0 : 0 < n := by omega + have hn' : (0 : ℝ) < n := by exact_mod_cast hn0 + have hw := fluctuationWindow_one_le (n := n) hk hn0 + have he := fluctuationWindow_eq_mul (k := k) hn0 + have hmul := mul_le_mul_of_nonneg_left hmargin.le hn'.le + have hf := Nat.lt_floor_add_one (c * (n : ℝ)) + nlinarith + exact squeeze_zero' (Filter.Eventually.of_forall fun n => properSATProbability_nonneg n k _) + hupper (concentrationError_tendsto k hk) + +theorem supercritical_limit (k : ℕ) (hk : 3 ≤ k) (c : ℝ) + (hc : limitingCenter k < c) : + Filter.Tendsto (fun n : ℕ => properSATProbability n k ⌊c * (n : ℝ)⌋₊) + Filter.atTop (nhds 0) := by + let d := min c (capMultiplier k : ℝ) + have hd : limitingCenter k < d := lt_min hc (limitingCenter_lt_cap k hk) + have hdL : d ≤ capMultiplier k := min_le_right _ _ + have ht := supercritical_limit_below_cap k hk d hd hdL + apply squeeze_zero' (Filter.Eventually.of_forall fun n => properSATProbability_nonneg n k _) _ ht + filter_upwards [Filter.eventually_ge_atTop k] with n hn + apply properSATProbability_antitone hn + exact Nat.floor_mono (mul_le_mul_of_nonneg_right (min_le_left c (capMultiplier k : ℝ)) (Nat.cast_nonneg n)) + +theorem main (k : ℕ) (hk : 3 ≤ k) : HasLimitingThreshold k := by + refine ⟨limitingCenter k, limitingCenter_pos k hk, ?_, ?_⟩ + · intro c hc0 hc + exact subcritical_limit k hk c hc0 hc + · intro c hc + exact supercritical_limit k hk c hc + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Model.lean b/lean/OAI/Probability/RandomSAT/Model.lean new file mode 100644 index 0000000000000000000000000000000000000000..2bcac89162b8772cf4bbe68a9adad7d7f264638f --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Model.lean @@ -0,0 +1,49 @@ +import Mathlib + +namespace OAI + +/-! +Proper clauses choose distinct variables with independent fair signs. Formulas are +independent clause draws with replacement, and their satisfiability probability is +the literal finite cardinality ratio. The empty formula is satisfiable. When +there are fewer variables than literals, nonempty formula lengths have probability +zero by the convention that division by zero is zero. +The threshold assertion concerns fixed clause size and fixed density only, with +no assertion at the critical density. +-/ + +namespace FixedClauseThreshold + +abbrev Assignment (n : ℕ) := Fin n → Bool + +abbrev ProperClause (n k : ℕ) := + { C : Fin n → Option Bool // (Finset.univ.filter fun i => (C i).isSome).card = k } + +abbrev Formula (n k m : ℕ) := Fin m → ProperClause n k + +def SatisfiesClause {n k : ℕ} (σ : Assignment n) (C : ProperClause n k) : Prop := + ∃ i : Fin n, C.val i = some (σ i) + +def Satisfies {n k m : ℕ} (σ : Assignment n) (F : Formula n k m) : Prop := + ∀ j, SatisfiesClause σ (F j) + +def Satisfiable {n k m : ℕ} (F : Formula n k m) : Prop := + ∃ σ : Assignment n, Satisfies σ F + +noncomputable def properSATProbability (n k m : ℕ) : ℝ := by + classical + exact (Fintype.card { F : Formula n k m // Satisfiable F } : ℝ) / + (Fintype.card (Formula n k m) : ℝ) + +def HasLimitingThreshold (k : ℕ) : Prop := + ∃ α : ℝ, 0 < α ∧ + (∀ c : ℝ, 0 ≤ c → c < α → + Filter.Tendsto (fun n : ℕ => properSATProbability n k ⌊c * (n : ℝ)⌋₊) + Filter.atTop (nhds 1)) ∧ + (∀ c : ℝ, α < c → + Filter.Tendsto (fun n : ℕ => properSATProbability n k ⌊c * (n : ℝ)⌋₊) + Filter.atTop (nhds 0)) + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Replacement.lean b/lean/OAI/Probability/RandomSAT/Replacement.lean new file mode 100644 index 0000000000000000000000000000000000000000..92d8bdb8b0332c1180f851a7bb584be49f6b947f --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Replacement.lean @@ -0,0 +1,381 @@ +import OAI.Probability.RandomSAT.Clauses + +namespace OAI + +/-! +Quantitative comparison of a shorter clause with a block of independent proper +clauses, uniformly over the background solution set. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +def killFraction (b n r : ℕ) : ℝ := (b.choose r : ℝ) / ((n.choose r : ℝ) * 2 ^ r) + +theorem killFraction_nonneg (b n r : ℕ) : 0 ≤ killFraction b n r := by + unfold killFraction + positivity + +@[simp] theorem killFraction_zero (b n : ℕ) : killFraction b n 0 = 1 := by + simp [killFraction] + +theorem killFraction_succ {b n r : ℕ} (hrn : r + 1 ≤ n) : + killFraction b n (r + 1) = + killFraction b n r * ((b - r : ℕ) : ℝ) / (2 * ((n - r : ℕ) : ℝ)) := by + have hnc : (n.choose r : ℝ) ≠ 0 := by + exact_mod_cast Nat.ne_of_gt (Nat.choose_pos (by omega : r ≤ n)) + have hncs : (n.choose (r + 1) : ℝ) ≠ 0 := by + exact_mod_cast Nat.ne_of_gt (Nat.choose_pos hrn) + have hnr : ((n - r : ℕ) : ℝ) ≠ 0 := by + exact_mod_cast (by omega : n - r ≠ 0) + have hb : (b.choose (r + 1) : ℝ) * (r + 1) = + (b.choose r : ℝ) * ((b - r : ℕ) : ℝ) := by + exact_mod_cast Nat.choose_succ_right_eq b r + have hn : (n.choose (r + 1) : ℝ) * (r + 1) = + (n.choose r : ℝ) * ((n - r : ℕ) : ℝ) := by + exact_mod_cast Nat.choose_succ_right_eq n r + unfold killFraction + rw [pow_succ] + field_simp + nlinarith [congrArg (fun a : ℝ => a * (n.choose (r + 1) : ℝ)) hb, + congrArg (fun a : ℝ => a * (b.choose (r + 1) : ℝ)) hn] + +theorem sub_ratio_le {b n r : ℕ} (hbn : b ≤ n) (hrb : r ≤ b) (hrn : r < n) : + ((b - r : ℕ) : ℝ) / ((n - r : ℕ) : ℝ) ≤ (b : ℝ) / n := by + have hn : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n) + have hnr : (0 : ℝ) < (n - r : ℕ) := by exact_mod_cast Nat.sub_pos_of_lt hrn + rw [div_le_div_iff₀ hnr hn, Nat.cast_sub hrb, Nat.cast_sub (Nat.le_of_lt hrn)] + have hbn' : (b : ℝ) ≤ n := by exact_mod_cast hbn + nlinarith [mul_nonneg (Nat.cast_nonneg r : (0 : ℝ) ≤ r) (sub_nonneg.mpr hbn')] + +theorem killFraction_le_pow {b n r : ℕ} (hbn : b ≤ n) (hrn : r ≤ n) + (hn : 0 < n) : killFraction b n r ≤ ((b : ℝ) / (2 * n)) ^ r := by + induction r with + | zero => simp + | succ r ih => + by_cases hbr : b < r + 1 + · simp only [killFraction, Nat.choose_eq_zero_of_lt hbr, Nat.cast_zero, zero_div] + positivity + · have hrb : r ≤ b := by omega + have ih' := ih (by omega) + rw [killFraction_succ hrn, pow_succ] + have hratio := sub_ratio_le hbn hrb (by omega : r < n) + have hhalf : ((b - r : ℕ) : ℝ) / (2 * ((n - r : ℕ) : ℝ)) ≤ + (b : ℝ) / (2 * n) := by + simpa only [div_mul_eq_div_div_swap] using div_le_div_of_nonneg_right hratio + (by norm_num : (0 : ℝ) ≤ 2) + calc + killFraction b n r * ((b - r : ℕ) : ℝ) / (2 * ((n - r : ℕ) : ℝ)) = + killFraction b n r * (((b - r : ℕ) : ℝ) / (2 * ((n - r : ℕ) : ℝ))) := by ring + _ ≤ ((b : ℝ) / (2 * n)) ^ r * ((b : ℝ) / (2 * n)) := + mul_le_mul ih' hhalf (by positivity) (by positivity) + +theorem killFraction_le_half_pow {b n r : ℕ} (hbn : b ≤ n) (hrn : r ≤ n) + (hn : 0 < n) : killFraction b n r ≤ (1 / 2 : ℝ) ^ r := by + apply (killFraction_le_pow hbn hrn hn).trans + apply pow_le_pow_left₀ (by positivity) + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + apply (div_le_iff₀ (by positivity : (0 : ℝ) < 2 * n)).mpr + have hbn' : (b : ℝ) ≤ n := by exact_mod_cast hbn + linarith + +theorem nat_le_internal_choose {n r : ℕ} (hr : 1 ≤ r) (hrn : r < n) : + n ≤ n.choose r := by + induction n generalizing r with + | zero => omega + | succ n ih => + cases r with + | zero => omega + | succ r => + by_cases h : r = 0 + · subst r + simp + · rw [Nat.choose_succ_succ] + have hlow := ih (by omega : 1 ≤ r) (by omega : r < n) + have hpos := Nat.choose_pos (by omega : r.succ ≤ n) + omega + +theorem killFraction_small_forcing {b n r : ℕ} (hr : 1 ≤ r) (hrn : r < n) + (hbr : b ≤ r) : killFraction b n r ≤ 1 / (n + 1 : ℝ) := by + have hn : (1 : ℝ) ≤ n := by exact_mod_cast (by omega : 1 ≤ n) + have hnc : (n : ℝ) ≤ n.choose r := by exact_mod_cast nat_le_internal_choose hr hrn + have hb : (b.choose r : ℝ) ≤ 1 := by + exact_mod_cast (Nat.choose_le_choose r hbr).trans_eq (Nat.choose_self r) + have hp : (2 : ℝ) ≤ 2 ^ r := by + simpa using pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 2) hr + have hncpos : (0 : ℝ) < n.choose r := by linarith + have hden : (0 : ℝ) < (n.choose r : ℝ) * 2 ^ r := by positivity + unfold killFraction + apply (div_le_div_iff₀ hden (by positivity : (0 : ℝ) < n + 1)).mpr + nlinarith [mul_le_mul hnc hp (by positivity : (0 : ℝ) ≤ 2) (by positivity : (0 : ℝ) ≤ n.choose r)] + +theorem succ_ratio_lower {b n r : ℕ} (hrb : r + 1 ≤ b) (hrn : r < n) : + (b : ℝ) / (2 * n * (r + 1)) ≤ + ((b - r : ℕ) : ℝ) / (2 * ((n - r : ℕ) : ℝ)) := by + have hn : (0 : ℝ) < n := by exact_mod_cast (by omega : 0 < n) + have hnr : (0 : ℝ) < (n - r : ℕ) := by exact_mod_cast Nat.sub_pos_of_lt hrn + have hrb' : (r + 1 : ℝ) ≤ b := by exact_mod_cast hrb + have hr : (0 : ℝ) ≤ r := by positivity + rw [div_le_div_iff₀ (by positivity : (0 : ℝ) < 2 * n * (r + 1)) + (by positivity : (0 : ℝ) < 2 * (n - r : ℕ))] + rw [Nat.cast_sub (by omega : r ≤ b), Nat.cast_sub (Nat.le_of_lt hrn)] + have haux : (b : ℝ) ≤ (b - r) * (r + 1) := by + nlinarith [mul_nonneg hr (sub_nonneg.mpr hrb')] + nlinarith [mul_le_mul_of_nonneg_right haux hn.le, + mul_nonneg (Nat.cast_nonneg b : (0 : ℝ) ≤ b) hr] + +theorem killFraction_succ_lower {b n r : ℕ} (hrb : r + 1 ≤ b) (hrn : r < n) : + killFraction b n r * ((b : ℝ) / (2 * n)) / (r + 1) ≤ + killFraction b n (r + 1) := by + rw [killFraction_succ (by omega : r + 1 ≤ n)] + have h := mul_le_mul_of_nonneg_left (succ_ratio_lower hrb hrn) + (killFraction_nonneg b n r) + simpa only [div_eq_mul_inv, mul_inv_rev, mul_assoc, mul_comm, mul_left_comm] using h + +theorem power_survival_bound {q : ℝ} (_hq0 : 0 ≤ q) (hq1 : q ≤ 1) (g : ℕ) : + (1 - q) ^ g * (1 + (g : ℝ) * q) ≤ 1 := by + induction g with + | zero => simp + | succ g ih => + have hstep : (1 - q) * (1 + ((g : ℝ) + 1) * q) ≤ 1 + (g : ℝ) * q := by + nlinarith [mul_nonneg (by positivity : (0 : ℝ) ≤ g + 1) (sq_nonneg q)] + calc + (1 - q) ^ (g + 1) * (1 + ((g + 1 : ℕ) : ℝ) * q) = + (1 - q) ^ g * ((1 - q) * (1 + ((g : ℝ) + 1) * q)) := by + push_cast + ring + _ ≤ (1 - q) ^ g * (1 + (g : ℝ) * q) := + mul_le_mul_of_nonneg_left hstep (pow_nonneg (sub_nonneg.mpr hq1) _) + _ ≤ 1 := ih + +theorem block_ge_of_double {x q : ℝ} {g : ℕ} + (hx0 : 0 ≤ x) (hxhalf : x ≤ 1 / 2) (hq0 : 0 ≤ q) (hq1 : q ≤ 1) + (hg : 2 * x ≤ (g : ℝ) * q) : x ≤ 1 - (1 - q) ^ g := by + have h := power_survival_bound hq0 hq1 g + have hx1 : 0 ≤ 1 - x := by linarith + have hg0 : 0 ≤ (g : ℝ) * q := by positivity + have hh : 1 ≤ (1 - x) * (1 + (g : ℝ) * q) := by + nlinarith [mul_le_mul_of_nonneg_right hg hx1, mul_nonneg hx0 (by linarith : 0 ≤ 1 - 2 * x)] + have hb : (1 - q) ^ g ≤ 1 - x := by + exact (mul_le_mul_iff_left₀ (by positivity : 0 < 1 + (g : ℝ) * q)).mp + (by nlinarith) + linarith + +theorem uniformProbability_true {α : Type*} [Fintype α] [Nonempty α] : + uniformProbability (fun _ : α => True) = 1 := by + classical + unfold uniformProbability + simp only [← Nat.card_eq_fintype_card] + rw [Nat.card_congr (Equiv.subtypeUnivEquiv (fun _ => trivial))] + rw [Nat.card_eq_fintype_card] + exact div_self (by exact_mod_cast Fintype.card_ne_zero) + +theorem uniformProbability_false {α : Type*} [Fintype α] : + uniformProbability (fun _ : α => False) = 0 := by + simp [uniformProbability] + +theorem uniformProbability_congr {α : Type*} [Fintype α] {p q : α → Prop} + (h : ∀ a, p a ↔ q a) : uniformProbability p = uniformProbability q := by + unfold uniformProbability + rw [Fintype.card_congr (Equiv.subtypeEquivRight h)] + +theorem uniformProbability_not {α : Type*} [Fintype α] [Nonempty α] (p : α → Prop) : + uniformProbability (fun a => ¬ p a) = 1 - uniformProbability p := by + unfold uniformProbability + rw [Fintype.card_subtype_compl, Nat.cast_sub (Fintype.card_subtype_le p), sub_div, + div_self (by exact_mod_cast Fintype.card_ne_zero)] + +theorem uniformProbability_forall {α : Type*} [Fintype α] (p : α → Prop) (m : ℕ) : + uniformProbability (fun f : Fin m → α => ∀ i, p (f i)) = uniformProbability p ^ m := by + unfold uniformProbability + have hc : Fintype.card {f : Fin m → α // ∀ i, p (f i)} = + Fintype.card (Fin m → {a : α // p a}) := + Fintype.card_congr (Equiv.subtypePiEquivPi (p := fun _ : Fin m => p)) + simp only [← Nat.card_eq_fintype_card] at hc ⊢ + rw [hc] + simp only [Nat.card_eq_fintype_card, Fintype.card_fun, Fintype.card_fin, Nat.cast_pow, + div_pow] + +theorem uniformProbability_exists {α : Type*} [Fintype α] [Nonempty α] + (p : α → Prop) (m : ℕ) : + uniformProbability (fun f : Fin m → α => ∃ i, p (f i)) = + 1 - (1 - uniformProbability p) ^ m := by + calc + _ = uniformProbability (fun f : Fin m → α => ¬ ∀ i, ¬ p (f i)) := + uniformProbability_congr (fun _ => by simp) + _ = 1 - uniformProbability (fun f : Fin m → α => ∀ i, ¬ p (f i)) := + uniformProbability_not _ + _ = _ := by rw [uniformProbability_forall (fun a => ¬ p a) m, uniformProbability_not] + +def blockUNSATProbability {n : ℕ} (k g : ℕ) (S : Finset (Assignment n)) : ℝ := + uniformProbability (fun F : Formula n k g => + ¬ ∃ σ ∈ S, Satisfies σ F) + +theorem blockUNSAT_lower {n k g : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + 1 - (1 - uniformProbability (fun C : ProperClause n k => KillsSolutions S C)) ^ g ≤ + blockUNSATProbability k g S := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + rw [← uniformProbability_exists] + apply uniformProbability_mono + rintro F ⟨i, hi⟩ ⟨σ, hσ, hs⟩ + exact hi σ hσ (hs i) + +theorem replacement_numeric {b v r g : ℕ} {a : ℝ} + (hr : 1 ≤ r) (hrv : r < v) (hbv : b ≤ v) (ha : 0 < a) + (hsmall : 1 / (v + 1 : ℝ) ≤ a⁻¹ ^ r) + (hg : 2 * (r + 1 : ℝ) * a ≤ (g : ℝ)) : + killFraction b v r - a⁻¹ ^ r ≤ 1 - (1 - killFraction b v (r + 1)) ^ g := by + let x := killFraction b v r + let q := killFraction b v (r + 1) + have hv : 0 < v := by omega + have hx0 : 0 ≤ x := killFraction_nonneg _ _ _ + have hq0 : 0 ≤ q := killFraction_nonneg _ _ _ + have hxhalf : x ≤ 1 / 2 := by + apply (killFraction_le_half_pow hbv (Nat.le_of_lt hrv) hv).trans + calc + (1 / 2 : ℝ) ^ r ≤ (1 / 2 : ℝ) ^ 1 := + pow_le_pow_of_le_one (by norm_num) (by norm_num) hr + _ = 1 / 2 := by simp + have hq1 : q ≤ 1 := by + apply (killFraction_le_half_pow hbv (by omega) hv).trans + exact pow_le_one₀ (by norm_num) (by norm_num) + by_cases hx : x ≤ a⁻¹ ^ r + · have hpow : (1 - q) ^ g ≤ 1 := + pow_le_one₀ (sub_nonneg.mpr hq1) (by linarith) + change x - a⁻¹ ^ r ≤ 1 - (1 - q) ^ g + linarith + · have hrb : r + 1 ≤ b := by + by_contra h + have hb : b ≤ r := by omega + have hbound := killFraction_small_forcing hr hrv hb + exact hx (hbound.trans hsmall) + have ht : a⁻¹ ≤ (b : ℝ) / (2 * v) := by + by_contra h + have hle : (b : ℝ) / (2 * v) ≤ a⁻¹ := (lt_of_not_ge h).le + have hpow := pow_le_pow_left₀ (by positivity : (0 : ℝ) ≤ (b : ℝ) / (2 * v)) hle r + have hbound := killFraction_le_pow hbv (Nat.le_of_lt hrv) hv + exact hx (hbound.trans hpow) + have hat : 1 ≤ a * ((b : ℝ) / (2 * v)) := by + simpa [ne_of_gt ha] using mul_le_mul_of_nonneg_left ht ha.le + have hqlo := killFraction_succ_lower hrb hrv + have hprod : (2 * (r + 1 : ℝ) * a) * + (x * ((b : ℝ) / (2 * v)) / (r + 1)) ≤ (g : ℝ) * q := + mul_le_mul hg hqlo (by positivity) (by positivity) + have hrpos : (r + 1 : ℝ) ≠ 0 := by positivity + have heq : (2 * (r + 1 : ℝ) * a) * + (x * ((b : ℝ) / (2 * v)) / (r + 1)) = + 2 * x * (a * ((b : ℝ) / (2 * v))) := by + field_simp + rw [heq] at hprod + have hdbl : 2 * x ≤ (g : ℝ) * q := by + nlinarith [mul_le_mul_of_nonneg_left hat (by positivity : 0 ≤ 2 * x)] + have hb := block_ge_of_double hx0 hxhalf hq0 hq1 hdbl + have heps : 0 ≤ a⁻¹ ^ r := by positivity + change x - a⁻¹ ^ r ≤ 1 - (1 - q) ^ g + linarith + +def replacementScale (n k : ℕ) : ℝ := (n : ℝ) ^ (1 / (k : ℝ)) + +def replacementError (n k : ℕ) : ℝ := (replacementScale n k)⁻¹ ^ (k - 1) + +def replacementBlock (n k : ℕ) : ℕ := ⌈2 * (k : ℝ) * replacementScale n k⌉₊ + +theorem replacementScale_pos {n k : ℕ} (hn : 0 < n) : + 0 < replacementScale n k := by + exact Real.rpow_pos_of_pos (by exact_mod_cast hn) _ + +theorem replacementScale_pow {n k : ℕ} (hn : 0 < n) (hk : 0 < k) : + replacementScale n k ^ k = (n : ℝ) := by + unfold replacementScale + rw [← Real.rpow_natCast, ← Real.rpow_mul (by positivity : (0 : ℝ) ≤ n)] + have hk' : (k : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hk + rw [one_div_mul_cancel hk', Real.rpow_one] + +theorem replacementScale_one_le {n k : ℕ} (hn : 1 ≤ n) : + 1 ≤ replacementScale n k := by + unfold replacementScale + exact Real.one_le_rpow (by exact_mod_cast hn) (by positivity) + +theorem replacementError_eq {n k : ℕ} (hn : 0 < n) : + replacementError n k = (n : ℝ) ^ (-((k - 1 : ℕ) : ℝ) / k) := by + unfold replacementError replacementScale + rw [inv_pow, ← Real.rpow_natCast, ← Real.rpow_mul (by positivity : (0 : ℝ) ≤ n), + ← Real.rpow_neg (by positivity : (0 : ℝ) ≤ n)] + congr 1 + ring + +theorem replacementError_small {n k : ℕ} (hn : 0 < n) (hk : 0 < k) : + 1 / (n : ℝ) ≤ replacementError n k := by + have ha := replacementScale_pos (k := k) hn + have hpow : replacementScale n k ^ (k - 1) ≤ (n : ℝ) := by + calc + replacementScale n k ^ (k - 1) ≤ replacementScale n k ^ k := + pow_le_pow_right₀ (replacementScale_one_le (Nat.succ_le_of_lt hn)) (Nat.sub_le _ _) + _ = _ := replacementScale_pow hn hk + unfold replacementError + rw [inv_pow, ← one_div] + exact one_div_le_one_div_of_le (by positivity) hpow + +theorem shorter_clause_replacement {n k : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (S : Finset (Assignment (n - 1))) : + uniformProbability (fun Q : ProperClause (n - 1) (k - 1) => KillsSolutions S Q) - + replacementError n k ≤ blockUNSATProbability k (replacementBlock n k) S := by + have hkn : k ≤ n - 1 := by omega + let : Nonempty (ProperClause (n - 1) k) := nonempty_properClause hkn + have heps : 0 ≤ replacementError n k := + pow_nonneg (inv_nonneg.mpr (replacementScale_pos (k := k) (by omega)).le) _ + by_cases hS : S.Nonempty + · have hkill (r : ℕ) : + uniformProbability (fun Q : ProperClause (n - 1) r => KillsSolutions S Q) = + killFraction (forcedVariables S).card (n - 1) r := by + unfold killFraction + rw [← killingProbability_of_nonempty S hS] + exact (uniformProbability_congr (fun _ => by simp [hS])).symm + rw [hkill] + apply le_trans _ (blockUNSAT_lower hkn S) + rw [hkill] + have hb : (forcedVariables S).card ≤ n - 1 := by + simpa using Finset.card_le_univ (forcedVariables S) + have hg : 2 * ((k - 1 : ℕ) + 1 : ℝ) * replacementScale n k ≤ + (replacementBlock n k : ℝ) := by + have he : ((k - 1 : ℕ) : ℝ) + 1 = k := by + exact_mod_cast (Nat.sub_add_cancel (by omega : 1 ≤ k)) + rw [he] + exact Nat.le_ceil _ + have hsmall : 1 / ((n - 1 : ℕ) + 1 : ℝ) ≤ (replacementScale n k)⁻¹ ^ (k - 1) := by + have he : ((n - 1 : ℕ) : ℝ) + 1 = n := by + exact_mod_cast (Nat.sub_add_cancel (by omega : 1 ≤ n)) + rw [he] + exact replacementError_small (by omega) (by omega) + have hrep := replacement_numeric (r := k - 1) (b := (forcedVariables S).card) + (v := n - 1) (g := replacementBlock n k) (a := replacementScale n k) + (by omega) (by omega) hb (replacementScale_pos (by omega)) hsmall hg + simpa only [Nat.sub_add_cancel (by omega : 1 ≤ k), replacementError] using hrep + · have hSe : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS + subst S + have hb : blockUNSATProbability k (replacementBlock n k) + (∅ : Finset (Assignment (n - 1))) = 1 := by + unfold blockUNSATProbability + have hf : (fun F : Formula (n - 1) k (replacementBlock n k) => + ¬ ∃ σ ∈ (∅ : Finset (Assignment (n - 1))), Satisfies σ F) = + (fun _ => True) := by + funext F + simp + rw [hf] + exact uniformProbability_true + rw [hb] + have hu := uniformProbability_le_one + (fun Q : ProperClause (n - 1) (k - 1) => KillsSolutions ∅ Q) + linarith + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Transfer.lean b/lean/OAI/Probability/RandomSAT/Transfer.lean new file mode 100644 index 0000000000000000000000000000000000000000..9062c6fd3e98ecd2bc10c31c7f45cb350bcc31ff --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Transfer.lean @@ -0,0 +1,404 @@ +import OAI.Probability.RandomSAT.Interpolation + +namespace OAI + +/-! +The exact probability of distinct variables, birthday bounds, and deletion and +thinning comparisons transfer auxiliary probabilities to the proper-clause law. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +def properFraction (n k : ℕ) : ℝ := (n.descFactorial k : ℝ) / (n : ℝ)^k + +theorem card_injective_lists (n k : ℕ) : + Fintype.card {f : Fin k → Fin n // Function.Injective f} = n.descFactorial k := by + rw [Fintype.card_congr (Equiv.subtypeInjectiveEquivEmbedding (Fin k) (Fin n)), + Fintype.card_embedding_eq, Fintype.card_fin, Fintype.card_fin] + +theorem properFraction_probability (n k : ℕ) : + properFraction n k = uniformProbability (fun f : Fin k → Fin n => Function.Injective f) := by + unfold properFraction uniformProbability + simp only [← Nat.card_eq_fintype_card] + simp only [Nat.card_eq_fintype_card, card_injective_lists, Fintype.card_fun, + Fintype.card_fin, Nat.cast_pow] + +theorem properFraction_nonneg (n k : ℕ) : 0 ≤ properFraction n k := by + unfold properFraction + positivity + +theorem properFraction_le_one (n k : ℕ) : properFraction n k ≤ 1 := by + rw [properFraction_probability] + exact uniformProbability_le_one _ + +theorem repetition_count_mono {b n k : ℕ} (hbn : b ≤ n) : + (b : ℝ)^k - b.descFactorial k ≤ (n : ℝ)^k - n.descFactorial k := by + let e : {f : Fin k → Fin b // ¬ Function.Injective f} ↪ + {f : Fin k → Fin n // ¬ Function.Injective f} := { + toFun := fun f => ⟨fun i => Fin.castLE hbn (f.val i), by + intro hinj + apply f.property + intro i j hij + apply hinj + exact congrArg (Fin.castLE hbn) hij⟩ + inj' := by + intro f g h + apply Subtype.ext + funext i + apply Fin.castLE_injective hbn + exact congrFun (congrArg Subtype.val h) i } + have h := Fintype.card_le_of_embedding e + have hf (v : ℕ) : Fintype.card {f : Fin k → Fin v // ¬ Function.Injective f} = + v^k - v.descFactorial k := by + simp only [Fintype.card_subtype_compl, card_injective_lists, Fintype.card_fun, Fintype.card_fin] + have hd (v : ℕ) : v.descFactorial k ≤ v^k := by + have h := Fintype.card_subtype_le (fun f : Fin k → Fin v => Function.Injective f) + simpa only [card_injective_lists, Fintype.card_fun, Fintype.card_fin] using h + rw [hf, hf] at h + have h' := (Nat.cast_le (α := ℝ)).mpr h + simpa only [Nat.cast_sub (hd _), Nat.cast_pow] using h' + +theorem properFraction_mul_kill {b n k : ℕ} (hkn : k ≤ n) (hn : 0 < n) : + properFraction n k * killFraction b n k = + (b.descFactorial k : ℝ) / ((2 : ℝ)^k * (n : ℝ)^k) := by + have hc : (n.choose k : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt (Nat.choose_pos hkn) + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn + unfold properFraction killFraction + rw [Nat.descFactorial_eq_factorial_mul_choose n k, Nat.descFactorial_eq_factorial_mul_choose b k] + push_cast + field_simp + +theorem auxiliary_kill_le_repetition {b n k : ℕ} (hbn : b ≤ n) (hkn : k ≤ n) + (hn : 0 < n) : + ((b : ℝ) / (2 * n))^k ≤ 1 - properFraction n k + + properFraction n k * killFraction b n k := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hcount := repetition_count_mono (k := k) hbn + have hq := properFraction_le_one n k + have hden : (0 : ℝ) < (2 : ℝ)^k * (n : ℝ)^k := by positivity + have hp : (1 : ℝ) ≤ 2^k := one_le_pow₀ (by norm_num) + rw [properFraction_mul_kill hkn hn] + unfold properFraction at hq ⊢ + rw [div_le_one (by positivity)] at hq + rw [div_pow, mul_pow] + have hnonneg : 0 ≤ (n : ℝ)^k - n.descFactorial k := sub_nonneg.mpr hq + have hm := mul_le_mul_of_nonneg_right hp hnonneg + have hd : (b : ℝ)^k - b.descFactorial k ≤ + (2 : ℝ)^k * ((n : ℝ)^k - n.descFactorial k) := by nlinarith + have hdiv := div_le_div_of_nonneg_right hd hden.le + have he : (2 : ℝ)^k * ((n : ℝ)^k - n.descFactorial k) / + ((2 : ℝ)^k * (n : ℝ)^k) = 1 - (n.descFactorial k : ℝ) / (n : ℝ)^k := by + field_simp + rw [he, sub_div] at hdiv + linarith + +theorem clauseAverage_alive {n k : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + clauseAverage k alive S = alive S * (1 - killFraction (forcedVariables S).card n k) := by + by_cases hS : S.Nonempty + · have h := singleUNSAT_eq hkn S + have he : (uniformProbability (fun C : ProperClause n k => KillsSolutions S C)) = + killingProbability k S := by + apply uniformProbability_congr + exact fun _ => (and_iff_right hS).symm + rw [he, killingProbability_of_nonempty S hS] at h + change killFraction _ _ _ = 1 - clauseAverage k alive S at h + simp only [alive, ite_eq_left hS, one_mul] + linarith + · have he : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS + subst S + simp [clauseAverage, addClause, alive_empty, uniformMean_zero] + +theorem auxiliaryAverage_le_proper {n k : ℕ} (hn : 0 < n) (hkn : k ≤ n) : + auxiliaryAverage k alive ≤ clauseAverage (n := n) k alive := by + intro S + rw [auxiliaryAverage_alive hn, clauseAverage_alive hkn] + apply mul_le_mul_of_nonneg_left _ (alive_nonneg S) + apply sub_le_sub_left + have hb : (forcedVariables S).card ≤ n := by simpa using Finset.card_le_univ (forcedVariables S) + have h := killFraction_le_pow hb hkn hn + simpa only [forcedFraction, div_mul_eq_div_div_swap] using h + +theorem scaled_proper_le_auxiliaryAverage {n k : ℕ} (hn : 0 < n) (hkn : k ≤ n) : + (fun S => properFraction n k * clauseAverage k alive S) ≤ auxiliaryAverage (n := n) k alive := by + intro S + change properFraction n k * clauseAverage k alive S ≤ auxiliaryAverage k alive S + rw [auxiliaryAverage_alive hn, clauseAverage_alive hkn] + have hb : (forcedVariables S).card ≤ n := by simpa using Finset.card_le_univ (forcedVariables S) + have h := auxiliary_kill_le_repetition hb hkn hn + have hh : properFraction n k * (1 - killFraction (forcedVariables S).card n k) ≤ + 1 - (forcedFraction S / 2)^k := by + unfold forcedFraction + rw [div_div] + rw [mul_comm (n : ℝ) 2] + linarith + have hmul := mul_le_mul_of_nonneg_left hh (alive_nonneg S) + nlinarith + +theorem auxiliaryProbability_le_proper {n k : ℕ} (hn : 0 < n) (hkn : k ≤ n) (m : ℕ) : + auxiliaryProbability n k m ≤ properSATProbability n k m := by + rw [properSATProbability_eq_survival] + exact iterate_compare_of_commute (clauseAverage k) (auxiliaryAverage k) + (fun _ _ h => finiteClauseAverage_mono _ h) (fun _ _ h => finiteClauseAverage_mono _ h) + (finiteClauseAverage_commute _ _) (auxiliaryAverage_le_proper hn hkn) m Finset.univ + +theorem proper_scaled_le_auxiliaryProbability {n k : ℕ} (hn : 0 < n) (hkn : k ≤ n) (m : ℕ) : + (properFraction n k)^m * properSATProbability n k m ≤ auxiliaryProbability n k m := by + have hstep := scaled_proper_le_auxiliaryAverage hn hkn + let B : (Finset (Assignment n) → ℝ) → (Finset (Assignment n) → ℝ) := + fun f S => properFraction n k * clauseAverage k f S + have hB : Monotone B := by + intro f g h S + exact mul_le_mul_of_nonneg_left (finiteClauseAverage_mono _ h S) (properFraction_nonneg n k) + have hcomm : Function.Commute (auxiliaryAverage (n := n) k) B := by + intro f + unfold B auxiliaryAverage embeddedAverage + rw [finiteClauseAverage_const_mul] + funext S + congr 1 + exact congrFun (finiteClauseAverage_commute + (fun C : AuxiliaryClause n k => fun σ => auxiliarySatisfies σ (embedAuxiliaryClause id C)) + (fun C : ProperClause n k => fun σ => SatisfiesClause σ C) f) S + have hit (j : ℕ) (f : Finset (Assignment n) → ℝ) : + B^[j] f = (fun S => (properFraction n k)^j * (clauseAverage k)^[j] f S) := by + induction j with + | zero => funext S; simp + | succ j ih => + rw [Function.iterate_succ_apply', ih] + unfold B clauseAverage + funext S + rw [uniformMean_const_mul] + rw [Function.iterate_succ_apply', pow_succ] + ring + have h := iterate_compare_of_commute (auxiliaryAverage k) B + (fun _ _ h => finiteClauseAverage_mono _ h) hB hcomm hstep m Finset.univ + rw [hit] at h + rw [properSATProbability_eq_survival] + exact h + +def repeatPairs (k : ℕ) : ℝ := (k.choose 2 : ℝ) + +@[simp] theorem repeatPairs_zero : repeatPairs 0 = 0 := by norm_num [repeatPairs] + +theorem repeatPairs_succ (k : ℕ) : repeatPairs (k + 1) = repeatPairs k + k := by + simp only [repeatPairs, Nat.choose_succ_succ, Nat.choose_one_right, Nat.cast_add] + ring + +theorem repeatPairs_nonneg (k : ℕ) : 0 ≤ repeatPairs k := Nat.cast_nonneg _ + +theorem properFraction_succ {n k : ℕ} (hn : 0 < n) (hkn : k ≤ n) : + properFraction n (k + 1) = properFraction n k * (1 - (k : ℝ) / n) := by + have hn' : (n : ℝ) ≠ 0 := by exact_mod_cast Nat.ne_of_gt hn + unfold properFraction + rw [Nat.descFactorial_succ, Nat.cast_mul, Nat.cast_sub hkn, pow_succ] + field_simp + +theorem properFraction_lower {n k : ℕ} (hn : 0 < n) (hkn : k ≤ n) : + 1 - repeatPairs k / n ≤ properFraction n k := by + induction k with + | zero => simp [properFraction] + | succ k ih => + have hkn' : k ≤ n := by omega + have hi := ih hkn' + have hle := properFraction_le_one n k + have hprod := mul_le_mul_of_nonneg_right hle (show 0 ≤ (k : ℝ) / n by positivity) + rw [properFraction_succ hn hkn', repeatPairs_succ, add_div] + nlinarith + +theorem auxiliarySurvival_nonneg {n k : ℕ} (m : ℕ) (S : Finset (Assignment n)) : + 0 ≤ auxiliarySurvival k m S := by + induction m generalizing S with + | zero => exact alive_nonneg S + | succ m ih => rw [auxiliarySurvival_succ]; exact uniformMean_nonneg (fun _ => ih _) + +theorem auxiliarySurvival_le_one {n k : ℕ} (hn : 0 < n) (m : ℕ) (S : Finset (Assignment n)) : + auxiliarySurvival k m S ≤ 1 := by + let : NeZero n := ⟨Nat.ne_of_gt hn⟩ + induction m generalizing S with + | zero => exact alive_le_one S + | succ m ih => + rw [auxiliarySurvival_succ, ← uniformMean_const (α := AuxiliaryClause n k) (1 : ℝ)] + exact uniformMean_mono (fun _ => ih _) + +theorem auxiliaryProbability_nonneg (n k m : ℕ) : 0 ≤ auxiliaryProbability n k m := + auxiliarySurvival_nonneg _ _ + +theorem auxiliaryProbability_le_one {n : ℕ} (hn : 0 < n) (k m : ℕ) : + auxiliaryProbability n k m ≤ 1 := auxiliarySurvival_le_one hn _ _ + +theorem finite_model_sandwich {n k : ℕ} (hn : 0 < n) (hkn : k ≤ n) (m : ℕ) : + (properFraction n k)^m * properSATProbability n k m ≤ auxiliaryProbability n k m ∧ + auxiliaryProbability n k m ≤ + binomialMean (properFraction n k) m (properSATProbability n k) := by + refine ⟨proper_scaled_le_auxiliaryProbability hn hkn m, ?_⟩ + apply (auxiliaryProbability_le_proper hn hkn m).trans + rw [← binomialMean_const (properFraction n k) (properSATProbability n k m) m] + apply binomialMean_mono (properFraction_nonneg n k) (properFraction_le_one n k) + intro d hd + exact properSATProbability_antitone hkn hd + +theorem thinned_count_mean_bounds {n k m : ℕ} {L : ℝ} (hn : 0 < n) (hkn : k ≤ n) + (hm : (m : ℝ) ≤ L * n) : + (m : ℝ) - L * repeatPairs k ≤ binomialMean (properFraction n k) m (fun j => (j : ℝ)) ∧ + binomialMean (properFraction n k) m (fun j => (j : ℝ)) ≤ m := by + rw [binomialMean_id] + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hl := properFraction_lower hn hkn + have hu := properFraction_le_one n k + have h1 := mul_le_mul_of_nonneg_left hl (Nat.cast_nonneg m : (0 : ℝ) ≤ m) + have h2 := mul_le_mul_of_nonneg_right hm (show 0 ≤ repeatPairs k / n by + exact div_nonneg (repeatPairs_nonneg k) hn'.le) + have he : L * n * (repeatPairs k / n) = L * repeatPairs k := by field_simp + rw [he] at h2 + constructor + · nlinarith + · nlinarith + +theorem exp_neg_two_le_one_sub {x : ℝ} (hx0 : 0 ≤ x) (hx : x ≤ 1 / 2) : + Real.exp (-2 * x) ≤ 1 - x := by + have h := Real.add_one_le_exp (2 * x) + have hm := mul_le_mul_of_nonneg_right h (show 0 ≤ 1 - x by linarith) + have hh : 1 ≤ Real.exp (2 * x) * (1 - x) := by nlinarith + apply (mul_le_mul_iff_right₀ (Real.exp_pos (2 * x))).mp + rw [← Real.exp_add, show 2 * x + -2 * x = 0 by ring, Real.exp_zero] + simpa only [mul_comm] using hh + +def transferFactor (k : ℕ) : ℝ := Real.exp (-2 * (capMultiplier k : ℝ) * repeatPairs k) + +def transferLower (k : ℕ) : ℝ := transferFactor k / 2 + +theorem transferFactor_pos (k : ℕ) : 0 < transferFactor k := Real.exp_pos _ + +theorem transferLower_pos (k : ℕ) : 0 < transferLower k := div_pos (transferFactor_pos k) (by norm_num) + +theorem properFraction_pow_lower {n k m : ℕ} (hn : 0 < n) (hkn : k ≤ n) + (hnrep : 2 * repeatPairs k ≤ n) (hm : m ≤ mainCap n k) : + transferFactor k ≤ (properFraction n k)^m := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hx0 : 0 ≤ repeatPairs k / n := div_nonneg (repeatPairs_nonneg k) hn'.le + have hx : repeatPairs k / n ≤ 1 / 2 := (div_le_iff₀ hn').mpr (by linarith) + have hbase := (exp_neg_two_le_one_sub hx0 hx).trans (properFraction_lower hn hkn) + have hpow := pow_le_pow_left₀ (Real.exp_pos _).le hbase m + rw [← Real.exp_nat_mul] at hpow + apply le_trans _ hpow + apply Real.exp_le_exp.mpr + have hm' : (m : ℝ) ≤ (capMultiplier k : ℝ) * n := by exact_mod_cast hm + have hh := mul_le_mul_of_nonneg_right hm' hx0 + have he : ((capMultiplier k : ℝ) * n) * (repeatPairs k / n) = + (capMultiplier k : ℝ) * repeatPairs k := by field_simp + rw [he] at hh + nlinarith + +theorem auxiliaryProbability_center_lower {n k m : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (hnrep : 2 * repeatPairs k ≤ n) (herror : concentrationError n k ≤ 1 / 2) + (hgap : (m : ℝ) + fluctuationWindow n k ≤ (n : ℝ) * center n k) : + transferLower k ≤ auxiliaryProbability n k m := by + have hn0 : 0 < n := by omega + have hn' : (0 : ℝ) < n := by exact_mod_cast hn0 + have hcenter := center_le_capMultiplier (by omega : k ≤ n) hn0 + have hm : m ≤ mainCap n k := by + have hw := (fluctuationWindow_pos (k := k) hn0).le + have h := mul_le_mul_of_nonneg_left hcenter hn'.le + have : (m : ℝ) ≤ (mainCap n k : ℝ) := by + simp only [mainCap, Nat.cast_mul] + nlinarith + exact_mod_cast this + have hprob := properSATProbability_center_lower hk hn hm hgap + have hhalf : (1 / 2 : ℝ) ≤ properSATProbability n k m := by linarith + have hmul := mul_le_mul (properFraction_pow_lower hn0 (by omega) hnrep hm) hhalf + (by norm_num : (0 : ℝ) ≤ 1 / 2) (properFraction_nonneg n k |> fun h => pow_nonneg h m) + apply le_trans _ (proper_scaled_le_auxiliaryProbability hn0 (by omega) m) + simpa only [transferLower, div_eq_mul_inv, one_mul] using hmul + +theorem auxiliaryProbability_center_upper {n k m : ℕ} (hk : 3 ≤ k) (hn : k + 1 ≤ n) + (hm : m ≤ mainCap n k) + (hgap : (n : ℝ) * center n k + fluctuationWindow n k ≤ m) : + auxiliaryProbability n k m ≤ concentrationError n k := + (auxiliaryProbability_le_proper (by omega) (by omega) m).trans + (properSATProbability_center_upper hk hn hm hgap) + +theorem binomialMean_square (p : ℝ) (m : ℕ) : + binomialMean p m (fun j => (j : ℝ)^2) = m * p * (1 - p) + ((m : ℝ) * p)^2 := by + induction m with + | zero => simp [binomialMean] + | succ m ih => + rw [binomialMean] + have he : binomialMean p m (fun j => ((j + 1 : ℕ) : ℝ)^2) = + binomialMean p m (fun j => (j : ℝ)^2) + 2 * ((m : ℝ) * p) + 1 := by + calc + _ = binomialMean p m (fun j => (j : ℝ)^2 + 2 * j + 1) := by + apply binomialMean_congr + intro j _ + push_cast + ring + _ = _ := by + rw [binomialMean_add, binomialMean_add, binomialMean_const_mul, + binomialMean_id, binomialMean_const] + rw [he, ih, Nat.cast_add, Nat.cast_one] + ring + +theorem binomialMean_centered_square (p : ℝ) (m : ℕ) : + binomialMean p m (fun j => ((j : ℝ) - (m : ℝ) * p)^2) = (m : ℝ) * p * (1 - p) := by + calc + _ = binomialMean p m (fun j => (j : ℝ)^2 - 2 * ((m : ℝ) * p) * j + ((m : ℝ) * p)^2) := by + apply binomialMean_congr + intro j _ + ring + _ = _ := by + rw [binomialMean_add, binomialMean_sub, binomialMean_const_mul, + binomialMean_const, binomialMean_square, binomialMean_id] + ring + +theorem binomialMean_div_const (p c : ℝ) (m : ℕ) (f : ℕ → ℝ) : + binomialMean p m (fun j => f j / c) = binomialMean p m f / c := by + simp only [div_eq_mul_inv, binomialMean_mul_const] + +theorem binomialMean_all_success {p : ℝ} (hp0 : 0 ≤ p) (hp1 : p ≤ 1) + (m : ℕ) (f : ℕ → ℝ) (hf : ∀ j ≤ m, 0 ≤ f j) : + p^m * f m ≤ binomialMean p m f := by + induction m generalizing f with + | zero => simp [binomialMean] + | succ m ih => + rw [binomialMean, pow_succ] + have h0 := binomialMean_nonneg hp0 hp1 (m := m) (f := f) (fun j hj => hf j (by omega)) + have h1 := ih (fun j => f (j + 1)) (fun j hj => hf (j + 1) (by omega)) + have hm := mul_le_mul_of_nonneg_left h1 hp0 + nlinarith [mul_nonneg (sub_nonneg.mpr hp1) h0] + +theorem product_lower_two_deviations {κ x y a b : ℝ} (hκ : 0 ≤ κ) + (hx : 0 ≤ x) (hy : 0 ≤ y) (ha : 0 ≤ a) (hb : 0 ≤ b) + (hax : x < 1 → κ ≤ a) (hby : y < 1 → κ ≤ b) : + κ^2 * (1 - x - y) ≤ a * b := by + by_cases hx1 : x < 1 + · by_cases hy1 : y < 1 + · have hprod := mul_le_mul (hax hx1) (hby hy1) hκ ha + have hle : κ^2 * (1 - x - y) ≤ κ^2 := + by + have hh : 1 - x - y ≤ 1 := by linarith + simpa only [mul_one] using mul_le_mul_of_nonneg_left hh (sq_nonneg κ) + nlinarith + · have hle : κ^2 * (1 - x - y) ≤ 0 := + mul_nonpos_of_nonneg_of_nonpos (sq_nonneg κ) (by linarith) + exact hle.trans (mul_nonneg ha hb) + · have hle : κ^2 * (1 - x - y) ≤ 0 := + mul_nonpos_of_nonneg_of_nonpos (sq_nonneg κ) (by linarith) + exact hle.trans (mul_nonneg ha hb) + +def samplingError (n k : ℕ) : ℝ := + (capMultiplier k : ℝ) * n / (fluctuationWindow n k)^2 + +theorem samplingError_nonneg (n k : ℕ) : 0 ≤ samplingError n k := by + unfold samplingError + positivity + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/RandomSAT/Variance.lean b/lean/OAI/Probability/RandomSAT/Variance.lean new file mode 100644 index 0000000000000000000000000000000000000000..9ebd0b73e4ccb5648969ac1cfc5f0100521e1172 --- /dev/null +++ b/lean/OAI/Probability/RandomSAT/Variance.lean @@ -0,0 +1,504 @@ +import OAI.Probability.RandomSAT.Forcing + +namespace OAI + +/-! +Stopped satisfiable lifetimes, insertion delays, and the coordinate-omission +variance bound in terms of integrated forcing. +-/ + +namespace FixedClauseThreshold + +open Finset + +noncomputable section + +attribute [local instance] Classical.propDecidable + +theorem addClause_subset {n k : ℕ} (S : Finset (Assignment n)) (C : ProperClause n k) : + addClause S C ⊆ S := Finset.filter_subset _ _ + +theorem addClause_mono {n k : ℕ} {S T : Finset (Assignment n)} (hST : S ⊆ T) + (C : ProperClause n k) : addClause S C ⊆ addClause T C := by + intro σ hσ + rw [mem_addClause] at hσ ⊢ + exact ⟨hST hσ.1, hσ.2⟩ + +@[simp] theorem addClause_empty {n k : ℕ} (C : ProperClause n k) : + addClause ∅ C = ∅ := by simp [addClause] + +@[simp] theorem alive_empty {n : ℕ} : alive (∅ : Finset (Assignment n)) = 0 := by simp [alive] + +@[simp] theorem survival_empty {n k m : ℕ} : survival k m (∅ : Finset (Assignment n)) = 0 := by + rw [survival_eq_mean] + have h (F : Formula n k m) : restrictSolutions ∅ F = ∅ := by simp [restrictSolutions] + simp only [h, alive_empty, uniformMean_zero] + +def lifetime {n : ℕ} (k : ℕ) : (m : ℕ) → Finset (Assignment n) → Formula n k m → ℝ + | 0, _, _ => 0 + | m + 1, S, F => alive (addClause S (F 0)) + + lifetime k m (addClause S (F 0)) (Fin.tail F) + +@[simp] theorem lifetime_zero {n k : ℕ} (S : Finset (Assignment n)) (F : Formula n k 0) : + lifetime k 0 S F = 0 := rfl + +@[simp] theorem lifetime_cons {n k m : ℕ} (S : Finset (Assignment n)) (C : ProperClause n k) + (F : Formula n k m) : lifetime k (m + 1) S (Fin.cons C F) = + alive (addClause S C) + lifetime k m (addClause S C) F := rfl + +@[simp] theorem lifetime_empty {n k m : ℕ} (F : Formula n k m) : lifetime k m ∅ F = 0 := by + induction m with + | zero => rfl + | succ m ih => simp [lifetime, ih] + +theorem lifetime_nonneg {n k m : ℕ} (S : Finset (Assignment n)) (F : Formula n k m) : + 0 ≤ lifetime k m S F := by + induction m generalizing S with + | zero => exact le_rfl + | succ m ih => exact add_nonneg (alive_nonneg _) (ih _ _) + +theorem lifetime_le {n k m : ℕ} (S : Finset (Assignment n)) (F : Formula n k m) : + lifetime k m S F ≤ m := by + induction m generalizing S with + | zero => simp [lifetime] + | succ m ih => + simp only [lifetime, Nat.cast_add, Nat.cast_one] + linarith [alive_le_one (addClause S (F 0)), ih (addClause S (F 0)) (Fin.tail F)] + +theorem lifetime_mono {n k m : ℕ} {S T : Finset (Assignment n)} (hST : S ⊆ T) + (F : Formula n k m) : lifetime k m S F ≤ lifetime k m T F := by + induction m generalizing S T with + | zero => exact le_rfl + | succ m ih => + exact add_le_add (alive_mono (addClause_mono hST (F 0))) + (ih (addClause_mono hST (F 0)) (Fin.tail F)) + +def lifetimeMean {n : ℕ} (k m : ℕ) (S : Finset (Assignment n)) : ℝ := + uniformMean (lifetime k m S) + +def lifetimeVariance {n : ℕ} (k m : ℕ) (S : Finset (Assignment n)) : ℝ := + uniformVariance (lifetime k m S) + +theorem lifetimeMean_succ {n k m : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + lifetimeMean k (m + 1) S = clauseAverage k (fun T => alive T + lifetimeMean k m T) S := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + unfold lifetimeMean + rw [uniformMean_fin_succ] + simp only [lifetime_cons, uniformMean_add, uniformMean_const] + simp only [clauseAverage, uniformMean_add] + +theorem clauseAverage_sum {n k : ℕ} {ι : Type*} (s : Finset ι) + (f : ι → Finset (Assignment n) → ℝ) (S : Finset (Assignment n)) : + clauseAverage k (fun T => ∑ i ∈ s, f i T) S = + ∑ i ∈ s, clauseAverage k (f i) S := uniformMean_sum s _ + +theorem lifetimeMean_eq_sum {n k m : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + lifetimeMean k m S = ∑ j ∈ Finset.range m, survival k (j + 1) S := by + induction m generalizing S with + | zero => exact uniformMean_zero + | succ m ih => + rw [lifetimeMean_succ hkn] + have hfun : (fun T : Finset (Assignment n) => alive T + lifetimeMean k m T) = + fun T => ∑ j ∈ Finset.range (m + 1), survival k j T := by + funext T + rw [Finset.sum_range_succ', ih, survival_zero] + ring + rw [hfun, clauseAverage_sum] + apply Finset.sum_congr rfl + intro j _ + exact clauseAverage_survival S + +def killingChance {n : ℕ} (k : ℕ) (S : Finset (Assignment n)) : ℝ := + alive S - survival k 1 S + +theorem killingChance_nonneg {n k : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + 0 ≤ killingChance k S := by + have h := survival_antitone hkn S (Nat.zero_le 1) + exact sub_nonneg.mpr h + +theorem killingChance_le_one {n k : ℕ} (S : Finset (Assignment n)) : killingChance k S ≤ 1 := by + unfold killingChance + linarith [alive_le_one S, survival_nonneg (k := k) (m := 1) S] + +theorem killingChance_eq_mean {n k : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + killingChance k S = uniformMean (fun C : ProperClause n k => alive S - alive (addClause S C)) := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + rw [uniformMean_sub, uniformMean_const] + rfl + +theorem killingChance_eq_probability {n k : ℕ} (hkn : k ≤ n) {S : Finset (Assignment n)} + (hS : S.Nonempty) : + killingChance k S = uniformProbability (fun C : ProperClause n k => KillsSolutions S C) := by + rw [singleUNSAT_eq hkn] + simp [killingChance, alive, hS] + +theorem survival_le_geometric {n k d : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + survival k d S ≤ (1 - killingChance k S) ^ d := by + by_cases hS : S.Nonempty + · have h := blockUNSAT_lower (g := d) hkn S + rw [blockUNSAT_eq hkn, ← killingChance_eq_probability hkn hS] at h + linarith + · have he : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS + subst S + rw [survival_empty] + exact pow_nonneg (sub_nonneg.mpr (killingChance_le_one ∅)) _ + +def insertionDelay {n : ℕ} (k m : ℕ) (S : Finset (Assignment n)) + (C : ProperClause n k) (F : Formula n k m) : ℝ := + (alive S + lifetime k m S F) - (alive (addClause S C) + lifetime k m (addClause S C) F) + +def insertionSecond {n : ℕ} (k m : ℕ) (S : Finset (Assignment n)) : ℝ := + uniformMean (fun C : ProperClause n k => uniformMean (fun F : Formula n k m => + insertionDelay k m S C F ^ 2)) + +theorem insertionDelay_zero {n k : ℕ} (S : Finset (Assignment n)) (C : ProperClause n k) + (F : Formula n k 0) : insertionDelay k 0 S C F = alive S - alive (addClause S C) := by + simp [insertionDelay] + +theorem insertionDelay_cons {n k m : ℕ} (S : Finset (Assignment n)) (C D : ProperClause n k) + (F : Formula n k m) : insertionDelay k (m + 1) S C (Fin.cons D F) = + alive S - alive (addClause S C) + insertionDelay k m (addClause S D) C F := by + simp only [insertionDelay, lifetime_cons, addClause_comm S C D] + ring + +theorem pivot_sq {n k : ℕ} (S : Finset (Assignment n)) (C : ProperClause n k) : + (alive S - alive (addClause S C)) ^ 2 = alive S - alive (addClause S C) := by + have hsub := alive_mono (addClause_subset S C) + unfold alive at hsub ⊢ + split_ifs at hsub ⊢ <;> norm_num at * + +theorem insertionDelay_cross {n k m : ℕ} {S T : Finset (Assignment n)} (hTS : T ⊆ S) + (C : ProperClause n k) (F : Formula n k m) : + (alive S - alive (addClause S C)) * insertionDelay k m T C F = + (alive S - alive (addClause S C)) * (alive T + lifetime k m T F) := by + by_cases hzero : alive S - alive (addClause S C) = 0 + · rw [hzero, zero_mul, zero_mul] + · have he : addClause S C = ∅ := by + by_contra hn + have hSC := Finset.nonempty_iff_ne_empty.mpr hn + have hS := hSC.mono (addClause_subset S C) + simp [alive, hSC, hS] at hzero + have hf : addClause T C = ∅ := Finset.subset_empty.mp (by + rw [← he] + exact addClause_mono hTS C) + simp [insertionDelay, hf] + +theorem insertionDelay_cons_sq {n k m : ℕ} (S : Finset (Assignment n)) (C D : ProperClause n k) + (F : Formula n k m) : insertionDelay k (m + 1) S C (Fin.cons D F) ^ 2 = + insertionDelay k m (addClause S D) C F ^ 2 + (alive S - alive (addClause S C)) + + 2 * (alive S - alive (addClause S C)) * + (alive (addClause S D) + lifetime k m (addClause S D) F) := by + rw [insertionDelay_cons] + have h := insertionDelay_cross (addClause_subset S D) C F + have hs := pivot_sq S C + nlinarith [hs, h] + +theorem insertionSecond_zero {n k : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + insertionSecond k 0 S = killingChance k S := by + rw [killingChance_eq_mean hkn] + unfold insertionSecond + apply uniformMean_congr + intro C + simp only [insertionDelay_zero, pivot_sq, uniformMean_const] + +theorem insertionSecond_succ {n k m : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + insertionSecond k (m + 1) S = clauseAverage k (insertionSecond k m) S + + killingChance k S * (1 + 2 * lifetimeMean k (m + 1) S) := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + unfold insertionSecond + simp_rw [uniformMean_fin_succ, insertionDelay_cons_sq, uniformMean_add, + uniformMean_const_mul, uniformMean_const] + rw [uniformMean_comm (fun C D => uniformMean + (fun F : Formula n k m => insertionDelay k m (addClause S D) C F ^ 2))] + rw [← killingChance_eq_mean hkn] + have hmean : (uniformMean fun D : ProperClause n k => + alive (addClause S D) + uniformMean (lifetime k m (addClause S D))) = + lifetimeMean k (m + 1) S := (lifetimeMean_succ hkn S).symm + simp_rw [uniformMean_add, uniformMean_const] + simp only [uniformMean_add] at hmean + rw [hmean] + simp only [uniformMean_mul_const, uniformMean_const_mul, + ← killingChance_eq_mean hkn] + dsimp only [clauseAverage] + ring + +theorem killing_geometric_sum {q : ℝ} (hq0 : 0 ≤ q) (hq1 : q ≤ 1) (t : ℕ) : + q * ∑ j ∈ Finset.range t, (1 - q)^j ≤ min ((t : ℝ) * q) 1 := by + have hgeom : q * ∑ j ∈ Finset.range t, (1 - q)^j = 1 - (1 - q)^t := by + induction t with + | zero => simp + | succ t ih => rw [Finset.sum_range_succ, mul_add, ih, pow_succ]; ring + apply le_min + · calc + _ ≤ q * ∑ _j ∈ Finset.range t, (1 : ℝ) := by + exact mul_le_mul_of_nonneg_left (Finset.sum_le_sum (fun j _ => + pow_le_one₀ (by linarith) (by linarith))) hq0 + _ = _ := by simp; ring + · rw [hgeom] + linarith [pow_nonneg (sub_nonneg.mpr hq1) t] + +def truncatedKilling {n : ℕ} (k M : ℕ) (S : Finset (Assignment n)) : ℝ := + min ((M : ℝ) * killingChance k S) 1 + +theorem pivotal_local_bound {n k m M : ℕ} (hkn : k ≤ n) (hm : m + 1 ≤ M) + (S : Finset (Assignment n)) : + killingChance k S * (1 + 2 * lifetimeMean k m S) ≤ 2 * truncatedKilling k M S := by + have hq0 := killingChance_nonneg hkn S + have hq1 := killingChance_le_one (k := k) S + have hsum : 1 + lifetimeMean k m S ≤ + ∑ j ∈ Finset.range (m + 1), (1 - killingChance k S)^j := by + rw [lifetimeMean_eq_sum hkn, Finset.sum_range_succ'] + simp only [pow_zero] + simpa only [add_comm] using add_le_add_left + (Finset.sum_le_sum (fun j (_ : j ∈ Finset.range m) => + survival_le_geometric (d := j + 1) hkn S)) 1 + have hgeom := killing_geometric_sum hq0 hq1 (m + 1) + have hmin : min (((m + 1 : ℕ) : ℝ) * killingChance k S) 1 ≤ truncatedKilling k M S := by + exact min_le_min (mul_le_mul_of_nonneg_right (by exact_mod_cast hm) hq0) le_rfl + have hh := mul_le_mul_of_nonneg_left hsum hq0 + nlinarith + +def occupation {n : ℕ} (k : ℕ) (f : Finset (Assignment n) → ℝ) : + ℕ → Finset (Assignment n) → ℝ + | 0, _ => 0 + | m + 1, S => f S + clauseAverage k (occupation k f m) S + +theorem occupation_eq_sum {n k m : ℕ} (f : Finset (Assignment n) → ℝ) + (S : Finset (Assignment n)) : + occupation k f m S = ∑ j ∈ Finset.range m, ((clauseAverage k)^[j] f) S := by + induction m generalizing S with + | zero => simp [occupation] + | succ m ih => + simp only [occupation] + have he : occupation k f m = fun T => ∑ j ∈ Finset.range m, ((clauseAverage k)^[j] f) T := + funext ih + rw [he, clauseAverage_sum, Finset.sum_range_succ'] + simp only [Function.iterate_succ_apply', Function.iterate_zero, id_eq] + ring + +theorem occupation_nonneg {n k m : ℕ} {f : Finset (Assignment n) → ℝ} + (hf : ∀ S, 0 ≤ f S) (S : Finset (Assignment n)) : 0 ≤ occupation k f m S := by + induction m generalizing S with + | zero => exact le_rfl + | succ m ih => exact add_nonneg (hf S) (uniformMean_nonneg (fun C => ih _)) + +theorem insertionSecond_le_occupation {n k m M : ℕ} (hkn : k ≤ n) (hm : m + 1 ≤ M) + (S : Finset (Assignment n)) : + insertionSecond k m S ≤ 2 * occupation k (truncatedKilling k M) (m + 1) S := by + induction m generalizing S with + | zero => + rw [insertionSecond_zero hkn] + have hp := pivotal_local_bound (m := 0) hkn hm S + simpa [occupation, clauseAverage, uniformMean_zero, lifetimeMean, lifetime, uniformMean] using hp + | succ m ih => + rw [insertionSecond_succ hkn, occupation] + have hp := pivotal_local_bound (m := m + 1) hkn hm S + have havg := clauseAverage_mono (k := k) (fun T => ih (by omega) T) S + change clauseAverage k (insertionSecond k m) S ≤ + uniformMean (fun C : ProperClause n k => 2 * occupation k (truncatedKilling k M) (m + 1) + (addClause S C)) at havg + rw [uniformMean_const_mul] at havg + change clauseAverage k (insertionSecond k m) S ≤ + 2 * clauseAverage k (occupation k (truncatedKilling k M) (m + 1)) S at havg + linarith + +theorem uniformVariance_const_add {α : Type*} [Fintype α] [Nonempty α] + (f : α → ℝ) (c : ℝ) : uniformVariance (fun a => c + f a) = uniformVariance f := by + unfold uniformVariance + rw [uniformMean_add, uniformMean_const] + apply uniformMean_congr + intro a + congr 1 + ring + +theorem uniformVariance_product {α β : Type*} [Fintype α] [Fintype β] + [Nonempty α] [Nonempty β] (f : α → β → ℝ) : + uniformVariance (fun p : α × β => f p.1 p.2) = + uniformMean (fun a => uniformVariance (f a)) + + uniformVariance (fun a => uniformMean (f a)) := by + simp only [uniformVariance_eq, uniformMean_prod, uniformMean_sub] + ring + +theorem uniformVariance_fin_succ {α : Type*} [Fintype α] [Nonempty α] {m : ℕ} + (f : (Fin (m + 1) → α) → ℝ) : + uniformVariance f = uniformMean (fun C => uniformVariance (fun F : Fin m → α => + f (Fin.cons C F))) + uniformVariance (fun C => uniformMean (fun F : Fin m → α => + f (Fin.cons C F))) := by + simp only [uniformVariance_eq, uniformMean_fin_succ, uniformMean_sub] + ring + +theorem lifetimeVariance_succ_le {n k m : ℕ} (hkn : k ≤ n) (S : Finset (Assignment n)) : + lifetimeVariance k (m + 1) S ≤ + clauseAverage k (lifetimeVariance k m) S + insertionSecond k m S := by + let : Nonempty (ProperClause n k) := nonempty_properClause hkn + unfold lifetimeVariance + rw [uniformVariance_fin_succ] + simp only [lifetime_cons, uniformVariance_const_add] + apply add_le_add le_rfl + let c := alive S + lifetimeMean k m S + calc + _ ≤ uniformMean (fun C : ProperClause n k => + (uniformMean (fun F : Formula n k m => + alive (addClause S C) + lifetime k m (addClause S C) F) - c)^2) := + uniformVariance_le_sq_dist _ c + _ ≤ insertionSecond k m S := by + apply uniformMean_mono + intro C + have h := uniformMean_sq_ge (fun F : Formula n k m => insertionDelay k m S C F) + have he : uniformMean (fun F : Formula n k m => insertionDelay k m S C F) = + c - uniformMean (fun F : Formula n k m => + alive (addClause S C) + lifetime k m (addClause S C) F) := by + simp only [insertionDelay, uniformMean_sub, uniformMean_add, uniformMean_const, + c, lifetimeMean] + rw [he] at h + nlinarith + +theorem clauseAverage_const_mul {n k : ℕ} (c : ℝ) (f : Finset (Assignment n) → ℝ) + (S : Finset (Assignment n)) : + clauseAverage k (fun T => c * f T) S = c * clauseAverage k f S := + uniformMean_const_mul c _ + +theorem lifetimeVariance_le_occupation {n k m M : ℕ} (hkn : k ≤ n) (hm : m ≤ M) + (S : Finset (Assignment n)) : + lifetimeVariance k m S ≤ 2 * m * occupation k (truncatedKilling k M) m S := by + induction m generalizing S with + | zero => simp [lifetimeVariance, lifetime, uniformVariance, uniformMean] + | succ m ih => + have hv := lifetimeVariance_succ_le (m := m) hkn S + have hi := insertionSecond_le_occupation hkn hm S + have havg := clauseAverage_mono (k := k) (fun T => ih (by omega) T) S + rw [clauseAverage_const_mul] at havg + have hq : 0 ≤ truncatedKilling k M S := + le_min (mul_nonneg (Nat.cast_nonneg _) (killingChance_nonneg hkn S)) zero_le_one + have he : occupation k (truncatedKilling k M) (m + 1) S = + truncatedKilling k M S + clauseAverage k (occupation k (truncatedKilling k M) m) S := rfl + simp only [Nat.cast_add, Nat.cast_one] + nlinarith [mul_nonneg (Nat.cast_nonneg m : (0 : ℝ) ≤ m) hq] + +theorem killingChance_eq_killingProbability {n k : ℕ} (hkn : k ≤ n) + (S : Finset (Assignment n)) : killingChance k S = killingProbability k S := by + by_cases hS : S.Nonempty + · rw [killingChance_eq_probability hkn hS] + simp [killingProbability, hS] + · have he : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hS + subst S + simp [killingChance] + +def forcedFraction {n : ℕ} (S : Finset (Assignment n)) : ℝ := + ((forcedVariables S).card : ℝ) / n + +theorem forcedFraction_nonneg {n : ℕ} (S : Finset (Assignment n)) : 0 ≤ forcedFraction S := by + unfold forcedFraction + positivity + +theorem forcedFraction_le_one {n : ℕ} (S : Finset (Assignment n)) : forcedFraction S ≤ 1 := by + by_cases hn : n = 0 + · simp [forcedFraction, hn] + · rw [forcedFraction, div_le_one (by exact_mod_cast Nat.pos_of_ne_zero hn)] + exact_mod_cast (show (forcedVariables S).card ≤ n by simpa using Finset.card_le_univ (forcedVariables S)) + +theorem killingChance_le_forced_pow {n k : ℕ} (hk : 0 < k) (hkn : k ≤ n) + (S : Finset (Assignment n)) : killingChance k S ≤ forcedFraction S ^ k := by + rw [killingChance_eq_killingProbability hkn, killingProbability_eq hk] + have hn : 0 < n := lt_of_lt_of_le hk hkn + have hbn : (forcedVariables S).card ≤ n := by simpa using Finset.card_le_univ (forcedVariables S) + have h := killFraction_le_pow hbn hkn hn + apply h.trans + apply pow_le_pow_left₀ (by positivity) + unfold forcedFraction + apply div_le_div_of_nonneg_left (Nat.cast_nonneg _) (by exact_mod_cast hn) + linarith [(Nat.cast_nonneg n : (0 : ℝ) ≤ n)] + +theorem truncatedKilling_le_forced {n k M : ℕ} {L : ℝ} + (hk : 0 < k) (hkn : k ≤ n) (hL : 1 ≤ L) (hM : (M : ℝ) ≤ L * n) + (S : Finset (Assignment n)) : + truncatedKilling k M S ≤ L * replacementScale n k * forcedFraction S := by + have hn : 0 < n := lt_of_lt_of_le hk hkn + have ha := replacementScale_pos (k := k) hn + have hr := forcedFraction_nonneg S + have ht : 0 ≤ replacementScale n k * forcedFraction S := mul_nonneg ha.le hr + by_cases hsmall : replacementScale n k * forcedFraction S ≤ 1 + · calc + truncatedKilling k M S ≤ (M : ℝ) * killingChance k S := min_le_left _ _ + _ ≤ (L * n) * forcedFraction S ^ k := + mul_le_mul hM (killingChance_le_forced_pow hk hkn S) + (killingChance_nonneg hkn S) (by positivity) + _ = L * (replacementScale n k * forcedFraction S)^k := by + rw [mul_pow, replacementScale_pow hn hk] + ring + _ ≤ L * (replacementScale n k * forcedFraction S) := by + apply mul_le_mul_of_nonneg_left _ (by linarith) + have he : (replacementScale n k * forcedFraction S)^k = + (replacementScale n k * forcedFraction S)^(k - 1) * + (replacementScale n k * forcedFraction S) := by + rw [← pow_succ, Nat.sub_add_cancel hk] + rw [he] + exact mul_le_of_le_one_left ht (pow_le_one₀ ht hsmall) + _ = _ := by ring + · calc + truncatedKilling k M S ≤ 1 := min_le_right _ _ + _ ≤ L * (replacementScale n k * forcedFraction S) := by + nlinarith [mul_nonneg (sub_nonneg.mpr hL) ht] + _ = _ := by ring + +theorem clauseAverage_iterate_eq_mean {n k m : ℕ} (f : Finset (Assignment n) → ℝ) + (S : Finset (Assignment n)) : + ((clauseAverage k)^[m] f) S = uniformMean (fun F : Formula n k m => + f (restrictSolutions S F)) := by + induction m generalizing S with + | zero => + simp only [Function.iterate_zero, id_eq, restrictSolutions_zero, uniformMean_const] + | succ m ih => + rw [Function.iterate_succ_apply', uniformMean_fin_succ] + change uniformMean (fun C : ProperClause n k => + ((clauseAverage k)^[m] f) (addClause S C)) = _ + apply uniformMean_congr + intro C + rw [ih] + apply uniformMean_congr + intro F + rw [restrictSolutions_cons] + +theorem occupation_forced_eq {n k m : ℕ} : + occupation k (forcedFraction (n := n)) m Finset.univ = + ∑ j ∈ Finset.range m, forcedFractionMean n k j := by + rw [occupation_eq_sum] + apply Finset.sum_congr rfl + intro j _ + exact clauseAverage_iterate_eq_mean _ _ + +theorem occupation_mono {n k m : ℕ} {f g : Finset (Assignment n) → ℝ} + (hfg : ∀ S, f S ≤ g S) (S : Finset (Assignment n)) : + occupation k f m S ≤ occupation k g m S := by + rw [occupation_eq_sum, occupation_eq_sum] + exact Finset.sum_le_sum fun _ _ => clauseAverage_iterate_mono hfg S + +theorem occupation_const_mul {n k m : ℕ} (c : ℝ) (f : Finset (Assignment n) → ℝ) + (S : Finset (Assignment n)) : + occupation k (fun T => c * f T) m S = c * occupation k f m S := by + induction m generalizing S with + | zero => simp [occupation] + | succ m ih => + simp only [occupation] + have he : occupation k (fun T => c * f T) m = fun T => c * occupation k f m T := funext ih + rw [he, clauseAverage_const_mul] + ring + +theorem lifetimeVariance_forcing_bound {n k M : ℕ} {L : ℝ} + (hk : 0 < k) (hkn : k ≤ n) (hL : 1 ≤ L) (hM : (M : ℝ) ≤ L * n) : + lifetimeVariance k M (Finset.univ : Finset (Assignment n)) ≤ + (2 * M * L * replacementScale n k) * + ∑ j ∈ Finset.range M, forcedFractionMean n k j := by + have hv := lifetimeVariance_le_occupation hkn (le_refl M) (Finset.univ : Finset (Assignment n)) + have ho := occupation_mono (k := k) (m := M) + (fun S => truncatedKilling_le_forced hk hkn hL hM S) Finset.univ + rw [occupation_const_mul, occupation_forced_eq] at ho + have hmul := mul_le_mul_of_nonneg_left ho (by positivity : (0 : ℝ) ≤ 2 * M) + nlinarith + +end + + +end FixedClauseThreshold + +end OAI diff --git a/lean/OAI/Probability/Renewal/Annuli.lean b/lean/OAI/Probability/Renewal/Annuli.lean new file mode 100644 index 0000000000000000000000000000000000000000..15f12aafdb0ad256dafa62d7f4b23d8fb0f5791c --- /dev/null +++ b/lean/OAI/Probability/Renewal/Annuli.lean @@ -0,0 +1,96 @@ +import OAI.Probability.Renewal.Tilt + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +def annulus (M r : ℝ) : Set ℕ := {j | r⁻¹ / M < (j : ℝ) ∧ (j : ℝ) ≤ r⁻¹} + +structure AnnulusData (p : PMF ℕ) (a : ℝ) where + M : ℝ + M_one : 1 < M + d : ℝ + d_pos : 0 < d + b : ℕ + beta : ℝ + beta_pos : 0 < beta + epsilon : ℝ + epsilon_pos : 0 < epsilon + mass : ∀ r, 0 < r → r ≤ epsilon → ∀ u (hu : 0 ≤ u), u ≤ r → + d * r ^ a ≤ (tilt p u hu).toMeasure.real (annulus M r) + atom : ∀ r, 0 < r → r ≤ epsilon → ∀ u (hu : 0 ≤ u), u ≤ r → + beta ≤ (tilt p u hu).toMeasure.real {b} + geometry : ∀ r, 0 < r → r ≤ epsilon → ∀ j ∈ annulus M r, + r⁻¹ / (2 * M) ≤ (j : ℝ) - b ∧ (j : ℝ) - b ≤ r⁻¹ + +lemma annulusData_exists (p : PMF ℕ) {a : ℝ} (ha : 0 < a ∧ a < 1) + (hpower : BoundedPowerInput p a) : Nonempty (AnnulusData p a) := by + obtain ⟨M, hM, c, hc, hann⟩ := annular_mass p ha hpower + obtain ⟨X, hX⟩ := eventually_atTop.mp hann + obtain ⟨b, hb⟩ := p.support_nonempty + have hbpos : 0 < (p b).toReal := ENNReal.toReal_pos (by simpa using hb) (p.apply_ne_top b) + have hM0 : 0 < M := zero_lt_one.trans hM + let R := max X (max 1 (2 * M * b)) + have hR : 0 < R := zero_lt_one.trans_le ((le_max_left _ _).trans (le_max_right _ _)) + have hRb : (b : ℝ) ≤ R := by + have h : 2 * M * (b : ℝ) ≤ R := (le_max_right _ _).trans (le_max_right _ _) + nlinarith [Nat.cast_nonneg (α := ℝ) b] + have hrR {r : ℝ} (hr : 0 < r) (hre : r ≤ R⁻¹) : R ≤ r⁻¹ := by + exact (le_inv_comm₀ hR hr).mpr hre + have hscale {r u : ℝ} (hr : 0 < r) (hur : u ≤ r) : u * r⁻¹ ≤ 1 := by + calc u * r⁻¹ ≤ r * r⁻¹ := mul_le_mul_of_nonneg_right hur (inv_nonneg.mpr hr.le) + _ = 1 := mul_inv_cancel₀ hr.ne' + refine ⟨⟨M, hM, Real.exp (-1) * c, by positivity, b, + Real.exp (-1) * (p b).toReal, by positivity, R⁻¹, inv_pos.mpr hR, ?_, ?_, ?_⟩⟩ + · intro r hr hre u hu hur + have hRm := hrR hr hre + have hm := hX r⁻¹ ((le_max_left _ _).trans hRm) + have hpw : (r⁻¹) ^ (-a) = r ^ a := by + rw [Real.inv_rpow hr.le, Real.rpow_neg hr.le, inv_inv] + rw [hpw] at hm + have hlo := measureReal_tilt_lower p u hu (annulus M r) r⁻¹ (fun j hj => hj.2) + have hexp : Real.exp (-1) ≤ Real.exp (-u * r⁻¹) := by + apply Real.exp_le_exp.mpr + linarith [hscale hr hur] + calc + Real.exp (-1) * c * r ^ a = Real.exp (-1) * (c * r ^ a) := by ring + _ ≤ Real.exp (-1) * p.toMeasure.real (annulus M r) := + mul_le_mul_of_nonneg_left hm (Real.exp_pos _).le + _ ≤ Real.exp (-u * r⁻¹) * p.toMeasure.real (annulus M r) := by gcongr + _ ≤ _ := hlo + · intro r hr hre u hu hur + have hRm := hrR hr hre + have hbR : (b : ℝ) ≤ r⁻¹ := hRb.trans hRm + have hlo := measureReal_tilt_lower p u hu {b} (b : ℝ) (by intro j hj; rw [Set.mem_singleton_iff] at hj; subst j; rfl) + have hexp : Real.exp (-1) ≤ Real.exp (-u * (b : ℝ)) := by + apply Real.exp_le_exp.mpr + have hmul := mul_le_mul_of_nonneg_left hbR hu + linarith [hscale hr hur] + have hsingle : p.toMeasure.real {b} = (p b).toReal := by + rw [Measure.real, p.toMeasure_apply_singleton _ (measurableSet_singleton _)] + rw [hsingle] at hlo + exact (mul_le_mul_of_nonneg_right hexp ENNReal.toReal_nonneg).trans hlo + · intro r hr hre j hj + have hRm := hrR hr hre + have hRb' : 2 * M * (b : ℝ) ≤ r⁻¹ := ((le_max_right _ _).trans (le_max_right _ _)).trans hRm + have hbsmall : (b : ℝ) ≤ r⁻¹ / (2 * M) := (le_div_iff₀ (by positivity)).mpr (by nlinarith) + have hlow := hj.1 + have hid : r⁻¹ / M = 2 * (r⁻¹ / (2 * M)) := by field_simp + rw [hid] at hlow + constructor + · linarith + · linarith [hj.2, Nat.cast_nonneg (α := ℝ) b] + +lemma tilt_zero (p : PMF ℕ) : tilt p 0 le_rfl = p := by + ext j + rw [tilt_apply] + simp [laplace] + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Centered.lean b/lean/OAI/Probability/Renewal/Centered.lean new file mode 100644 index 0000000000000000000000000000000000000000..54d49f0babe1366126fc92c9c1b9f3d62b87104c --- /dev/null +++ b/lean/OAI/Probability/Renewal/Centered.lean @@ -0,0 +1,150 @@ +import OAI.Probability.Renewal.Moments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +def natMean (p : PMF ℕ) : ℝ := ∫ j : ℕ, (j : ℝ) ∂p.toMeasure + +def natVariance (p : PMF ℕ) : ℝ := ∫ j : ℕ, ((j : ℝ) - natMean p) ^ 2 ∂p.toMeasure + +def natThird (p : PMF ℕ) : ℝ := ∫ j : ℕ, |(j : ℝ) - natMean p| ^ 3 ∂p.toMeasure + +lemma natMean_nonneg (p : PMF ℕ) : 0 ≤ natMean p := integral_nonneg (fun _ => Nat.cast_nonneg _) +lemma natVariance_nonneg (p : PMF ℕ) : 0 ≤ natVariance p := integral_nonneg (fun _ => sq_nonneg _) +lemma natThird_nonneg (p : PMF ℕ) : 0 ≤ natThird p := integral_nonneg (fun _ => by positivity) + +lemma nat_memLp (p : PMF ℕ) {n : ℕ} (hn : n ≠ 0) + (hi : Integrable (fun j : ℕ => (j : ℝ) ^ n) p.toMeasure) : + MemLp (fun j : ℕ => (j : ℝ)) n p.toMeasure := by + apply (integrable_norm_rpow_iff Measurable.of_discrete.aestronglyMeasurable (by exact_mod_cast hn) (by simp)).mp + simpa only [ENNReal.toReal_natCast, Real.rpow_natCast, Real.norm_natCast] using hi + +lemma natVariance_eq_sub (p : PMF ℕ) + (hi : Integrable (fun j : ℕ => (j : ℝ) ^ 2) p.toMeasure) : + natVariance p = (∫ j : ℕ, (j : ℝ) ^ 2 ∂p.toMeasure) - natMean p ^ 2 := by + have hm := nat_memLp p (by norm_num : (2 : ℕ) ≠ 0) hi + unfold natVariance natMean + rw [← variance_eq_integral Measurable.of_discrete.aemeasurable, variance_eq_sub hm] + rfl + +lemma natVariance_le_second (p : PMF ℕ) + (hi : Integrable (fun j : ℕ => (j : ℝ) ^ 2) p.toMeasure) : + natVariance p ≤ ∫ j : ℕ, (j : ℝ) ^ 2 ∂p.toMeasure := by + rw [natVariance_eq_sub p hi] + exact sub_le_self _ (sq_nonneg _) + +lemma integrable_pair_square (p : PMF ℕ) + (h1 : Integrable (fun j : ℕ => (j : ℝ)) p.toMeasure) + (h2 : Integrable (fun j : ℕ => (j : ℝ) ^ 2) p.toMeasure) : + Integrable (fun z : ℕ × ℕ => ((z.1 : ℝ) - z.2) ^ 2) (p.toMeasure.prod p.toMeasure) := by + have h := ((h2.comp_fst p.toMeasure).sub ((h1.mul_prod h1).const_mul 2)).add (h2.comp_snd p.toMeasure) + apply h.congr + filter_upwards [] with z + simp only [Pi.sub_apply, Pi.add_apply] + ring + +lemma two_copy_variance (p : PMF ℕ) + (h1 : Integrable (fun j : ℕ => (j : ℝ)) p.toMeasure) + (h2 : Integrable (fun j : ℕ => (j : ℝ) ^ 2) p.toMeasure) : + (∫ z : ℕ × ℕ, ((z.1 : ℝ) - z.2) ^ 2 ∂(p.toMeasure.prod p.toMeasure)) = 2 * natVariance p := by + have hid : (fun z : ℕ × ℕ => ((z.1 : ℝ) - z.2) ^ 2) = + fun z => (z.1 : ℝ) ^ 2 - 2 * ((z.1 : ℝ) * z.2) + (z.2 : ℝ) ^ 2 := by ext z; ring + have hf : Integrable (fun z : ℕ × ℕ => (z.1 : ℝ) ^ 2 - 2 * ((z.1 : ℝ) * z.2)) (p.toMeasure.prod p.toMeasure) := by + exact (h2.comp_fst p.toMeasure).sub ((h1.mul_prod h1).const_mul 2) + rw [hid, integral_add hf (h2.comp_snd p.toMeasure), + integral_sub (h2.comp_fst p.toMeasure) ((h1.mul_prod h1).const_mul 2), integral_const_mul, + integral_fun_fst (fun j : ℕ => (j : ℝ) ^ 2), integral_fun_snd (fun j : ℕ => (j : ℝ) ^ 2), + integral_prod_mul (fun j : ℕ => (j : ℝ)) (fun j : ℕ => (j : ℝ)), natVariance_eq_sub p h2] + simp only [Measure.real, measure_univ, ENNReal.toReal_one, one_smul, natMean] + ring + +lemma rectangle_variance_bound (p : PMF ℕ) + (h1 : Integrable (fun j : ℕ => (j : ℝ)) p.toMeasure) + (h2 : Integrable (fun j : ℕ => (j : ℝ) ^ 2) p.toMeasure) + (s b : Set ℕ) (r : ℝ) (hlower : ∀ j ∈ s, ∀ l ∈ b, r ≤ ((j : ℝ) - l) ^ 2) : + p.toMeasure.real s * p.toMeasure.real b * r ≤ 2 * natVariance p := by + calc + p.toMeasure.real s * p.toMeasure.real b * r = ∫ _ in s ×ˢ b, r ∂(p.toMeasure.prod p.toMeasure) := by + simp [Measure.real, Measure.prod_prod, ENNReal.toReal_mul] + _ ≤ ∫ z : ℕ × ℕ in s ×ˢ b, ((z.1 : ℝ) - z.2) ^ 2 ∂(p.toMeasure.prod p.toMeasure) := by + apply setIntegral_mono_on (integrable_const _) (integrable_pair_square p h1 h2).integrableOn MeasurableSet.of_discrete + intro z hz + exact hlower z.1 hz.1 z.2 hz.2 + _ ≤ ∫ z : ℕ × ℕ, ((z.1 : ℝ) - z.2) ^ 2 ∂(p.toMeasure.prod p.toMeasure) := + setIntegral_le_integral (integrable_pair_square p h1 h2) (ae_of_all _ (fun _ => sq_nonneg _)) + _ = 2 * natVariance p := two_copy_variance p h1 h2 + +lemma natThird_le_raw (p : PMF ℕ) + (h3 : Integrable (fun j : ℕ => (j : ℝ) ^ 3) p.toMeasure) : + natThird p ≤ 4 * ((∫ j : ℕ, (j : ℝ) ^ 3 ∂p.toMeasure) + natMean p ^ 3) := by + have hm := nat_memLp p (by norm_num : (3 : ℕ) ≠ 0) h3 + have hi : Integrable (fun j : ℕ => |(j : ℝ) - natMean p| ^ 3) p.toMeasure := by + simpa only [Real.norm_eq_abs, Pi.sub_apply] using (hm.sub (memLp_const (natMean p))).integrable_norm_pow' (p := 3) + calc + natThird p ≤ ∫ j : ℕ, 4 * ((j : ℝ) ^ 3 + natMean p ^ 3) ∂p.toMeasure := by + apply integral_mono hi ((h3.add (integrable_const _)).const_mul 4) + intro j + calc + |(j : ℝ) - natMean p| ^ 3 ≤ ((j : ℝ) + natMean p) ^ 3 := by + gcongr + exact (abs_sub _ _).trans_eq (by rw [abs_of_nonneg (Nat.cast_nonneg j), abs_of_nonneg (natMean_nonneg p)]) + _ ≤ 4 * ((j : ℝ) ^ 3 + natMean p ^ 3) := by + have hh := add_pow_le (Nat.cast_nonneg (α := ℝ) j) (natMean_nonneg p) 3 + norm_num at hh + exact hh + _ = _ := by rw [integral_const_mul, integral_add h3 (integrable_const _)]; simp + +def centeredMeasure (p : PMF ℕ) : Measure ℝ := p.toMeasure.map (fun j : ℕ => (j : ℝ) - natMean p) + +instance centeredMeasure_probability (p : PMF ℕ) : IsProbabilityMeasure (centeredMeasure p) := by + unfold centeredMeasure + infer_instance + +lemma centered_integral (p : PMF ℕ) {F : ℝ → ℝ} (hF : AEStronglyMeasurable F (centeredMeasure p)) : + (∫ x, F x ∂centeredMeasure p) = ∫ j : ℕ, F ((j : ℝ) - natMean p) ∂p.toMeasure := + integral_map Measurable.of_discrete.aemeasurable hF + +lemma centered_mean (p : PMF ℕ) (h1 : Integrable (fun j : ℕ => (j : ℝ)) p.toMeasure) : + (∫ x, x ∂centeredMeasure p) = 0 := by + rw [centered_integral p (F := fun x => x) (by fun_prop), + integral_sub h1 (integrable_const _)] + simp [natMean] + +lemma centered_variance (p : PMF ℕ) : (∫ x, x ^ 2 ∂centeredMeasure p) = natVariance p := by + exact centered_integral p (by fun_prop) + +lemma centered_third (p : PMF ℕ) : (∫ x, ‖x‖ ^ 3 ∂centeredMeasure p) = natThird p := by + simpa only [Real.norm_eq_abs, natThird] using centered_integral p (F := fun x => ‖x‖ ^ 3) (by fun_prop) + +lemma centered_memLp (p : PMF ℕ) {n : ℕ} (hn : n ≠ 0) + (hi : Integrable (fun j : ℕ => (j : ℝ) ^ n) p.toMeasure) : + MemLp id n (centeredMeasure p) := by + apply (memLp_map_measure_iff measurable_id.aestronglyMeasurable Measurable.of_discrete.aemeasurable).mpr + exact (nat_memLp p hn hi).sub (memLp_const _) + +lemma centered_char (p : PMF ℕ) (t : ℝ) : + charFun (centeredMeasure p) t = Complex.exp (-((natMean p * t : ℝ) : ℂ) * Complex.I) * latticeChar p t := by + rw [charFun_apply, centeredMeasure, integral_map Measurable.of_discrete.aemeasurable (by fun_prop)] + simp only [RCLike.inner_apply, conj_trivial] + have hid : (fun j : ℕ => Complex.exp (((j : ℝ) - natMean p) * t * Complex.I)) = + fun j : ℕ => Complex.exp (-((natMean p * t : ℝ) : ℂ) * Complex.I) * Complex.exp (((j : ℝ) * t : ℝ) * Complex.I) := by + ext j + rw [← Complex.exp_add] + congr 1 + push_cast + ring + simp_rw [mul_comm t] + push_cast + push_cast at hid + rw [hid, integral_const_mul] + simp [latticeChar] + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Concentration.lean b/lean/OAI/Probability/Renewal/Concentration.lean new file mode 100644 index 0000000000000000000000000000000000000000..4da3fc2053133919c46cf180a11543536f49b8e5 --- /dev/null +++ b/lean/OAI/Probability/Renewal/Concentration.lean @@ -0,0 +1,135 @@ +import OAI.Probability.Renewal.LocalInversion +import OAI.Probability.Renewal.Envelope + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +lemma AnnulusData.original_normalized {p : PMF ℕ} {a : ℝ} (D : AnnulusData p a) + (ha : 0 < a) {k : ℕ} (hk : 0 < k) {s : ℝ} (hs : 0 < s) (hsa : s ^ a = k) + {ρ : ℝ} (hρ : 0 ≤ ρ) + (hgap : ∀ t : ℝ, D.epsilon ≤ |t| → |t| ≤ Real.pi → ‖latticeChar p t‖ ≤ ρ) + (t : ℝ) (ht : |t| ≤ Real.pi * s) : + ‖latticeChar p (t / s)‖ ^ k ≤ Real.exp (-D.decayConst * |t| ^ a) + ρ ^ k := by + have hθ : |t / s| ≤ Real.pi := by + rw [abs_div, abs_of_pos hs, div_le_iff₀ hs] + exact ht + by_cases hlo : |t / s| ≤ D.epsilon + · have hb := pow_le_pow_left₀ (norm_nonneg _) (D.original_small ha hlo) k + rw [← Real.exp_nat_mul, abs_div, abs_of_pos hs, + Real.div_rpow (abs_nonneg t) hs.le, hsa] at hb + have hid : (k : ℝ) * (-D.decayConst * (|t| ^ a / (k : ℝ))) = -D.decayConst * |t| ^ a := by + have hk' : (k : ℝ) ≠ 0 := by exact_mod_cast hk.ne' + field_simp + rw [hid] at hb + exact hb.trans (le_add_of_nonneg_right (pow_nonneg hρ k)) + · have hb := pow_le_pow_left₀ (norm_nonneg _) (hgap (t / s) (le_of_not_ge hlo) hθ) k + exact hb.trans (le_add_of_nonneg_left (Real.exp_pos _).le) + +lemma lattice_mass_upper_of_envelope (p : PMF ℕ) (k m : ℕ) {s : ℝ} (hs : 0 < s) + {g : ℝ → ℝ} (hg : Integrable g) (hg0 : ∀ t, 0 ≤ g t) {η : ℝ} (_hη : 0 ≤ η) + (hbound : ∀ t ∈ Icc (-Real.pi * s) (Real.pi * s), + ‖latticeChar p (t / s)‖ ^ k ≤ g t + η) : + 2 * Real.pi * s * (sumLaw p k m).toReal ≤ (∫ t : ℝ, g t) + 2 * Real.pi * s * η := by + have hR : 0 ≤ Real.pi * s := by positivity + have hfi := (continuous_localIntegrand p k m s).integrableOn_Icc (μ := volume) (a := -Real.pi * s) (b := Real.pi * s) + calc + _ = ‖∫ t : ℝ in Icc (-Real.pi * s) (Real.pi * s), localIntegrand p k m s t‖ := by + rw [scaled_inversion p k m hs, norm_mul] + norm_num [norm_mul, Real.norm_eq_abs, abs_of_pos hs, abs_of_pos Real.pi_pos, + abs_of_nonneg ENNReal.toReal_nonneg] + _ ≤ ∫ t : ℝ in Icc (-Real.pi * s) (Real.pi * s), ‖localIntegrand p k m s t‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t : ℝ in Icc (-Real.pi * s) (Real.pi * s), g t + η := by + apply setIntegral_mono_on hfi.norm (hg.integrableOn.add (integrable_const _)) measurableSet_Icc + intro t ht + rw [norm_localIntegrand] + exact hbound t ht + _ = (∫ t : ℝ in Icc (-Real.pi * s) (Real.pi * s), g t) + 2 * Real.pi * s * η := by + rw [integral_add hg.integrableOn (integrable_const _)] + simp only [integral_const, smul_eq_mul, measureReal_restrict_apply_univ, Real.volume_real_Icc] + rw [max_eq_left (by nlinarith : 0 ≤ Real.pi * s - -Real.pi * s)] + ring + _ ≤ _ := add_le_add (setIntegral_le_integral hg (ae_of_all _ hg0)) le_rfl + +theorem local_concentration (p : PMF ℕ) (hspan : SpanOne p) {a : ℝ} + (ha : 0 < a ∧ a < 1) (hpower : BoundedPowerInput p a) : + ∃ C > (0 : ℝ), ∀ k : ℕ, 1 ≤ k → ∀ m : ℕ, + (sumLaw p k m).toReal ≤ C * (k : ℝ) ^ (-1 / a) := by + obtain ⟨D⟩ := annulusData_exists p ha hpower + obtain ⟨ρ, hρ0, hρ1, hgap⟩ := lattice_spectral_gap p hspan D.epsilon_pos + obtain ⟨n, hn⟩ := exists_nat_ge (1 / a) + obtain ⟨T, hT⟩ := (tendsto_pow_const_mul_const_pow_of_lt_one n hρ0 hρ1).bddAbove_range + let g := fun t : ℝ => Real.exp (-D.decayConst * |t| ^ a) + have hgi : Integrable g := integrable_stretched_exp ha.1 D.decayConst_pos + have hg0 : ∀ t, 0 ≤ g t := fun t => (Real.exp_pos _).le + let I := ∫ t : ℝ, g t + have hI : 0 ≤ I := integral_nonneg hg0 + let C := I / (2 * Real.pi) + max T 1 + have hC : 0 < C := by + dsimp [C] + have : (1 : ℝ) ≤ max T 1 := le_max_right _ _ + positivity + refine ⟨C, hC, ?_⟩ + intro k hk m + have hk0 : 0 < k := lt_of_lt_of_le Nat.zero_lt_one hk + have hk' : (0 : ℝ) < k := by exact_mod_cast hk0 + have hk1 : (1 : ℝ) ≤ k := by exact_mod_cast hk + let s := (k : ℝ) ^ (1 / a) + have hs : 0 < s := Real.rpow_pos_of_pos hk' _ + have hsa : s ^ a = (k : ℝ) := by + dsimp [s] + rw [← Real.rpow_mul hk'.le, div_mul_cancel₀ _ ha.1.ne', Real.rpow_one] + have hsle : s ≤ (k : ℝ) ^ n := by + exact (Real.rpow_le_rpow_of_exponent_le hk1 hn).trans_eq (Real.rpow_natCast _ _) + have hT' : s * ρ ^ k ≤ max T 1 := by + have hb : (k : ℝ) ^ n * ρ ^ k ≤ T := hT (mem_range_self k) + exact ((mul_le_mul_of_nonneg_right hsle (pow_nonneg hρ0 k)).trans hb).trans (le_max_left _ _) + have hbound := lattice_mass_upper_of_envelope p k m hs hgi hg0 (pow_nonneg hρ0 k) (by + intro t ht + exact D.original_normalized ha.1 hk0 hs hsa hρ0 hgap t (by apply abs_le.mpr; simpa only [← neg_mul, mem_Icc] using ht)) + have hconst : (∫ t : ℝ, g t) + 2 * Real.pi * s * ρ ^ k ≤ 2 * Real.pi * C := by + have hh := mul_le_mul_of_nonneg_left hT' (by positivity : 0 ≤ 2 * Real.pi) + dsimp [C, I] + have hπ : Real.pi ≠ 0 := Real.pi_pos.ne' + field_simp + nlinarith [hh] + have hfinal : (sumLaw p k m).toReal ≤ C / s := by + apply (le_div_iff₀ hs).mpr + have hh := hbound.trans hconst + nlinarith [Real.pi_pos] + have hp : (k : ℝ) ^ (-1 / a) = s⁻¹ := by + rw [neg_div, Real.rpow_neg hk'.le] + calc + _ ≤ C / s := hfinal + _ = C * (k : ℝ) ^ (-1 / a) := by rw [hp, div_eq_mul_inv] + +theorem annular_mass_and_concentration (p : PMF ℕ) (_hp : p 0 = 0) (hspan : SpanOne p) + {a : ℝ} (ha : 0 < a ∧ a < 1) (hpower : BoundedPowerInput p a) : + ∃ M > (1 : ℝ), ∃ c₁ > (0 : ℝ), ∃ C₁ > (0 : ℝ), + (∀ᶠ x : ℝ in atTop, + c₁ * x ^ (-a) ≤ p.toMeasure.real {j | x / M < (j : ℝ) ∧ (j : ℝ) ≤ x}) ∧ + (∀ k : ℕ, 1 ≤ k → (⨆ j : ℕ, (sumLaw p k j).toReal) ≤ C₁ * (k : ℝ) ^ (-1 / a)) ∧ + (∀ k : ℕ, 1 ≤ k → ∀ t : ℝ, 0 < t → + (sumLaw p k).toMeasure.real {j | t < (j : ℝ)} ≤ C₁ * k * t ^ (-a)) := by + obtain ⟨M, hM, c, hc, hann⟩ := annular_mass p ha hpower + obtain ⟨C, hC, hconc⟩ := local_concentration p hspan ha hpower + obtain ⟨D, hD, htail⟩ := sum_tail_power p ha hpower + refine ⟨M, hM, c, hc, max C D, hC.trans_le (le_max_left _ _), hann, ?_, ?_⟩ + · intro k hk + apply ciSup_le + intro j + exact (hconc k hk j).trans (mul_le_mul_of_nonneg_right (le_max_left _ _) + (Real.rpow_nonneg (Nat.cast_nonneg k) _)) + · intro k hk t ht + exact (htail k hk t ht).trans (mul_le_mul_of_nonneg_right + (mul_le_mul_of_nonneg_right (le_max_right _ _) (Nat.cast_nonneg k)) + (Real.rpow_nonneg ht.le _)) + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Counting.lean b/lean/OAI/Probability/Renewal/Counting.lean new file mode 100644 index 0000000000000000000000000000000000000000..b3bc6424fc0acdcd1c3571298bc3d2591841f0fa --- /dev/null +++ b/lean/OAI/Probability/Renewal/Counting.lean @@ -0,0 +1,60 @@ +import OAI.Probability.Renewal.Definitions + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +def indexWindow (x r : ℝ) : Finset ℕ := Finset.Icc ⌈x⌉₊ ⌊(1 + r) * x⌋₊ + +lemma mem_indexWindow {x r : ℝ} (hx : 0 ≤ x) (hr : 0 ≤ r) {k : ℕ} + (hk : k ∈ indexWindow x r) : x ≤ (k : ℝ) ∧ (k : ℝ) ≤ (1 + r) * x := by + obtain ⟨hl, hu⟩ := Finset.mem_Icc.mp hk + exact ⟨(Nat.le_ceil x).trans (by exact_mod_cast hl), + (by exact_mod_cast hu : (k : ℝ) ≤ (⌊(1 + r) * x⌋₊ : ℝ)).trans (Nat.floor_le (by positivity))⟩ + +lemma card_indexWindow {x r : ℝ} (hx : 0 ≤ x) (_hr : 0 ≤ r) (hrx : 2 ≤ r * x) : + r * x / 2 ≤ ((indexWindow x r).card : ℝ) := by + have hceil := Nat.ceil_lt_add_one hx + have hfloor := Nat.lt_floor_add_one ((1 + r) * x) + have hcf : ⌈x⌉₊ ≤ ⌊(1 + r) * x⌋₊ := Nat.le_floor (by nlinarith) + rw [indexWindow, Nat.card_Icc, Nat.cast_sub (hcf.trans (Nat.le_succ _)), Nat.cast_succ] + nlinarith + +lemma renewalMass_eq_tsum (p : PMF ℕ) {m : ℕ} (hm : 0 < m) : + renewalMass p m = ∑' k : ℕ, sumLaw p k m := by + rw [tsum_eq_zero_add' ENNReal.summable] + simp [sumLaw, PMF.pure_apply, hm.ne', renewalMass] + +lemma renewal_lower_finset (p : PMF ℕ) {m : ℕ} (hm : 0 < m) (s : Finset ℕ) {b : ℝ} + (hb : ∀ k ∈ s, b ≤ (sumLaw p k m).toReal) : + ENNReal.ofReal (b * (s.card : ℝ)) ≤ renewalMass p m := by + calc + ENNReal.ofReal (b * (s.card : ℝ)) = ENNReal.ofReal (∑ _k ∈ s, b) := by simp [mul_comm] + _ ≤ ENNReal.ofReal (∑ k ∈ s, (sumLaw p k m).toReal) := + ENNReal.ofReal_le_ofReal (Finset.sum_le_sum hb) + _ = ∑ k ∈ s, sumLaw p k m := by + rw [ENNReal.ofReal_sum_of_nonneg (fun _ _ => ENNReal.toReal_nonneg)] + simp only [ENNReal.ofReal_toReal (PMF.apply_ne_top _ _)] + _ ≤ renewalMass p m := by rw [renewalMass_eq_tsum p hm]; exact ENNReal.sum_le_tsum s + +lemma inverse_tilt_scale {a A m : ℝ} (hA : 0 < A) (hm : 0 < m) : + m / (A / m) ^ (a - 1) = A ^ (1 - a) * m ^ a := by + rw [Real.div_rpow hA.le hm.le, div_div_eq_mul_div] + have hM : m * m ^ (a - 1) = m ^ a := by + have hh := Real.rpow_add_one hm.ne' (a - 1) + simp only [sub_add_cancel] at hh + simpa only [mul_comm] using hh.symm + rw [hM] + have hA' : A ^ (1 - a) = (A ^ (a - 1))⁻¹ := by + rw [show (1 - a : ℝ) = -(a - 1) by ring, Real.rpow_neg hA.le] + rw [hA'] + ring + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Decay.lean b/lean/OAI/Probability/Renewal/Decay.lean new file mode 100644 index 0000000000000000000000000000000000000000..a2a853f9fd0740aafee827add3e52583020f60de --- /dev/null +++ b/lean/OAI/Probability/Renewal/Decay.lean @@ -0,0 +1,127 @@ +import OAI.Probability.Renewal.Annuli +import OAI.Probability.Renewal.Moments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +lemma exp_bound_from_defect {z : ℂ} {D : ℝ} (_hz : ‖z‖ ≤ 1) + (hD : 2 * D ≤ 1 - ‖z‖ ^ 2) : ‖z‖ ≤ Real.exp (-D) := by + have he := Real.add_one_le_exp (-D) + nlinarith [sq_nonneg (1 - ‖z‖)] + +namespace AnnulusData +variable {p : PMF ℕ} {a : ℝ} (D : AnnulusData p a) + +def decayConst : ℝ := D.d * D.beta * (2 / Real.pi ^ 2) / (2 * D.M) ^ 2 / 2 + +lemma decayConst_pos : 0 < D.decayConst := by + dsimp [decayConst] + have hM : 0 < D.M := zero_lt_one.trans D.M_one + positivity [D.d_pos, D.beta_pos, Real.pi_pos] + +lemma char_bound {r : ℝ} (hr : 0 < r) (hre : r ≤ D.epsilon) + {u : ℝ} (hu : 0 ≤ u) (hur : u ≤ r) {t : ℝ} (htr : |t| ≤ r) : + ‖latticeChar (tilt p u hu) t‖ ≤ Real.exp (-D.decayConst * r ^ (a - 2) * t ^ 2) := by + let L := r⁻¹ / (2 * D.M) + have hM : 0 < D.M := zero_lt_one.trans D.M_one + have hL : 0 ≤ L := by dsimp [L]; positivity + have hrect := rectangle_defect_bound (tilt p u hu) t + ((2 / Real.pi ^ 2) * L ^ 2 * t ^ 2) (annulus D.M r) {D.b} (by + intro j hj l hl + rw [mem_singleton_iff] at hl + subst l + obtain ⟨hlow, hupp⟩ := D.geometry r hr hre j hj + have hn : 0 ≤ (j : ℝ) - D.b := hL.trans hlow + have habs : |((j : ℝ) - D.b) * t| ≤ Real.pi := by + rw [abs_mul, abs_of_nonneg hn] + calc + ((j : ℝ) - D.b) * |t| ≤ r⁻¹ * r := mul_le_mul hupp htr (abs_nonneg _) (inv_nonneg.mpr hr.le) + _ = 1 := inv_mul_cancel₀ hr.ne' + _ ≤ Real.pi := (by linarith [Real.pi_gt_three] : (1 : ℝ) ≤ Real.pi) + have hsq : L ^ 2 ≤ ((j : ℝ) - D.b) ^ 2 := sq_le_sq₀ hL hn |>.mpr hlow + have hm := mul_le_mul_of_nonneg_left (mul_le_mul_of_nonneg_right hsq (sq_nonneg t)) + (by positivity : 0 ≤ 2 / Real.pi ^ 2) + have hc := Real.cos_le_one_sub_mul_cos_sq habs + rw [mul_pow] at hc + nlinarith) + have hmass := D.mass r hr hre u hu hur + have hatom := D.atom r hr hre u hu hur + have hn : 0 ≤ (2 / Real.pi ^ 2) * L ^ 2 * t ^ 2 := by positivity + have hmulti := mul_le_mul_of_nonneg_right (mul_le_mul hmass hatom D.beta_pos.le measureReal_nonneg) hn + have hdef := hmulti.trans hrect + simp only [neg_mul] + apply exp_bound_from_defect (norm_latticeChar_le_one _ _) + have hid : 2 * (D.decayConst * r ^ (a - 2) * t ^ 2) = + (D.d * r ^ a) * D.beta * ((2 / Real.pi ^ 2) * L ^ 2 * t ^ 2) := by + dsimp [decayConst, L] + rw [Real.rpow_sub hr, Real.rpow_two] + field_simp + rw [hid] + exact hdef + +lemma intermediate {t : ℝ} (ht : 0 < |t|) (hte : |t| ≤ D.epsilon) + {u : ℝ} (hu : 0 ≤ u) (hut : u ≤ |t|) : + ‖latticeChar (tilt p u hu) t‖ ≤ Real.exp (-D.decayConst * |t| ^ a) := by + have hh := D.char_bound ht hte hu hut le_rfl + have hid : |t| ^ (a - 2) * t ^ 2 = |t| ^ a := by + rw [Real.rpow_sub ht, Real.rpow_two, sq_abs] + have htn : t ≠ 0 := abs_pos.mp ht + field_simp + simpa only [mul_assoc, hid] using hh + +lemma original_small (ha : 0 < a) {t : ℝ} (ht : |t| ≤ D.epsilon) : + ‖latticeChar p t‖ ≤ Real.exp (-D.decayConst * |t| ^ a) := by + by_cases hzero : t = 0 + · subst t + rw [abs_zero, Real.zero_rpow ha.ne'] + simp [latticeChar] + · have ht0 : 0 < |t| := abs_pos.mpr hzero + simpa only [tilt_zero] using D.intermediate ht0 ht (u := 0) le_rfl ht0.le + +end AnnulusData + +lemma tilt_spectral_gap (p : PMF ℕ) (hspan : SpanOne p) {a : ℝ} (ha : 0 < a) + (hpow : BoundedPowerInput p a) {δ : ℝ} (hδ : 0 < δ) : + ∃ ρ ∈ Ico (0 : ℝ) 1, ∃ ε > (0 : ℝ), ∀ u (hu : 0 ≤ u), u ≤ ε → + ∀ t, δ ≤ |t| → |t| ≤ Real.pi → ‖latticeChar (tilt p u hu) t‖ ≤ ρ := by + obtain ⟨ρ, hρ0, hρ1, hρ⟩ := lattice_spectral_gap p hspan hδ + obtain ⟨ε, hε, he⟩ := laplace_small p ha hpow + rcases hpow with ⟨c, hc, C, hC, x₀, hx₀, _, hL⟩ + have hlim : Tendsto (fun u : ℝ => 4 * C * u ^ a) (𝓝[>] 0) (𝓝 0) := by + have h := ((Real.continuous_rpow_const ha.le).tendsto 0).const_mul (4 * C) + simpa [Real.zero_rpow ha.ne'] using h.mono_left nhdsWithin_le_nhds + have hev : ∀ᶠ u : ℝ in 𝓝[>] 0, 4 * C * u ^ a < (1 - ρ) / 2 := + hlim.eventually (Iio_mem_nhds (by linarith)) + obtain ⟨η, hη, heη⟩ := mem_nhdsGT_iff_exists_Ioc_subset.mp hev + refine ⟨(1 + ρ) / 2, ⟨by linarith, by linarith⟩, + min η (min ε x₀⁻¹), lt_min hη (lt_min hε (inv_pos.mpr hx₀)), ?_⟩ + intro u hu hue t ht htp + rcases hu.eq_or_lt with hzero | hu + · subst u + rw [tilt_zero] + exact (hρ t ht htp).trans (by linarith) + · have hlu := (hL u hu (hue.trans ((min_le_right _ _).trans (min_le_right _ _)))).2 + have hlz := he u hu (hue.trans ((min_le_right _ _).trans (min_le_left _ _))) + have hηu := heη ⟨hu, hue.trans (min_le_left _ _)⟩ + change 4 * C * u ^ a < (1 - ρ) / 2 at hηu + have hdiff := tilt_char_difference p u hu.le t + have hzpos := laplace_pos p hu.le + have hdef : 0 ≤ 1 - laplace p u := sub_nonneg.mpr (laplace_le_one p hu.le) + have hquot : 2 * (1 - laplace p u) / laplace p u ≤ 4 * C * u ^ a := by + apply (div_le_iff₀ hzpos).mpr + have hmul := mul_le_mul_of_nonneg_left hlz (by positivity : 0 ≤ 4 * C * u ^ a) + nlinarith + have htri := norm_le_norm_add_norm_sub (latticeChar p t) (latticeChar (tilt p u hu.le) t) + rw [norm_sub_rev] at htri + have horig := hρ t ht htp + linarith + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Definitions.lean b/lean/OAI/Probability/Renewal/Definitions.lean new file mode 100644 index 0000000000000000000000000000000000000000..4432335c66151cd296fb825e3de2c334c2b7cbce --- /dev/null +++ b/lean/OAI/Probability/Renewal/Definitions.lean @@ -0,0 +1,33 @@ +import Mathlib + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter +open scoped Topology ENNReal +namespace HoneycombLocal + +def sumLaw (p : PMF ℕ) : ℕ → PMF ℕ + | 0 => PMF.pure 0 + | k + 1 => p.bind (fun j => (sumLaw p k).map (fun r => j + r)) + +def renewalMass (p : PMF ℕ) (m : ℕ) : ℝ≥0∞ := + ∑' k : ℕ, sumLaw p (k + 1) m + +def SpanOne (p : PMF ℕ) : Prop := + AddSubgroup.closure {z : ℤ | ∃ j ∈ p.support, ∃ k ∈ p.support, z = (j : ℤ) - k} = ⊤ + +def laplace (p : PMF ℕ) (u : ℝ) : ℝ := + ∫ j, Real.exp (-u * (j : ℝ)) ∂p.toMeasure + +def BoundedPowerInput (p : PMF ℕ) (a : ℝ) : Prop := + ∃ c > 0, ∃ C > 0, ∃ x₀ > 0, + (∀ x ≥ x₀, p.toMeasure.real {j | x < (j : ℝ)} ≤ C * x ^ (-a)) ∧ + (∀ u > 0, u ≤ x₀⁻¹ → + c * u ^ a ≤ 1 - laplace p u ∧ 1 - laplace p u ≤ C * u ^ a) + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Envelope.lean b/lean/OAI/Probability/Renewal/Envelope.lean new file mode 100644 index 0000000000000000000000000000000000000000..3caa1190782455d612c49a1761eb01b546790266 --- /dev/null +++ b/lean/OAI/Probability/Renewal/Envelope.lean @@ -0,0 +1,144 @@ +import OAI.Probability.Renewal.Decay +import OAI.Probability.Renewal.TiltMoments + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +lemma integrable_stretched_exp {a c : ℝ} (ha : 0 < a) (hc : 0 < c) : + Integrable (fun t : ℝ => Real.exp (-c * |t| ^ a)) := by + have hi : IntegrableOn (fun t : ℝ => Real.exp (-c * t ^ a)) (Ioi 0) := by + simpa using integrableOn_rpow_mul_exp_neg_mul_rpow (s := 0) (by norm_num) ha hc + have hp : IntegrableOn (fun t : ℝ => Real.exp (-c * |t| ^ a)) (Ioi 0) := + (integrableOn_congr_fun (fun t ht => by rw [abs_of_pos ht]) measurableSet_Ioi).mpr hi + have hn : IntegrableOn (fun t : ℝ => Real.exp (-c * |t| ^ a)) (Iic 0) := by + rw [← Measure.map_neg_eq_self (volume : Measure ℝ)] + let em : MeasurableEmbedding (fun x : ℝ => -x) := (Homeomorph.neg ℝ).measurableEmbedding + rw [em.integrableOn_map_iff] + simp only [Function.comp_def, abs_neg, neg_preimage, neg_Iic, neg_zero] + exact Iff.mpr integrableOn_Ici_iff_integrableOn_Ioi hp + simpa only [Iic_union_Ioi, integrableOn_univ] using hn.union hp + +lemma exists_integral_tail_small {g : ℝ → ℝ} (hg : Integrable g) {ε : ℝ} (hε : 0 < ε) : + ∃ ω : ℝ, 1 ≤ ω ∧ (∫ t : ℝ in (Icc (-ω) ω)ᶜ, g t) ≤ ε := by + have hlim := intervalIntegral_tendsto_integral hg tendsto_neg_atTop_atBot (tendsto_id : Tendsto (fun x : ℝ => x) atTop atTop) + have ht : Tendsto (fun ω : ℝ => (∫ t, g t) - ∫ t in -ω..ω, g t) atTop (𝓝 0) := by + simpa using (tendsto_const_nhds (x := ∫ t, g t)).sub hlim + have hεv := ht.eventually (Iio_mem_nhds hε) + obtain ⟨ω, hω, he⟩ := (eventually_ge_atTop (1 : ℝ)).and hεv |>.exists + refine ⟨ω, hω, ?_⟩ + rw [setIntegral_compl measurableSet_Icc hg, integral_Icc_eq_integral_Ioc, + ← intervalIntegral.integral_of_le (by linarith : -ω ≤ ω)] + exact he.le + +lemma sigma_rpow_bound {a u σ V : ℝ} (ha : 0 < a ∧ a < 1) (hu : 0 < u) + (hσ : 0 < σ) (hV : 0 < V) {k : ℕ} (hku : 1 ≤ (k : ℝ) * u ^ a) + (hvar : σ ^ 2 ≤ (k : ℝ) * V * u ^ (a - 2)) : + σ ^ a ≤ (max V 1) ^ a * (k : ℝ) := by + let K := (k : ℝ) * u ^ a + let H := max V 1 + have hK : 1 ≤ K := hku + have hH : 1 ≤ H := le_max_right _ _ + have hH0 : 0 < H := hV.trans_le (le_max_left _ _) + have hK0 : 0 < K := zero_lt_one.trans_le hK + have hid : u ^ (a - 2) * u ^ 2 = u ^ a := by + rw [Real.rpow_sub hu, Real.rpow_two] + field_simp + have hs : (σ * u) ^ 2 ≤ V * K := by + have hh := mul_le_mul_of_nonneg_right hvar (sq_nonneg u) + simpa only [mul_pow, mul_assoc, hid, K, mul_left_comm V (k : ℝ)] using hh + have hHK : 1 ≤ H * K := by nlinarith [mul_nonneg (by linarith : 0 ≤ H - 1) (by linarith : 0 ≤ K - 1)] + have hvhk : V * K ≤ H * K := mul_le_mul_of_nonneg_right (le_max_left _ _) hK0.le + have hsu : σ * u ≤ H * K := by + nlinarith [sq_nonneg (H * K - 1), mul_nonneg (by linarith : 0 ≤ H * K) (by linarith : 0 ≤ H * K - 1)] + have hr := Real.rpow_le_rpow (by positivity : 0 ≤ σ * u) hsu ha.1.le + rw [Real.mul_rpow hσ.le hu.le, Real.mul_rpow hH0.le hK0.le] at hr + have hr' := hr.trans (mul_le_mul_of_nonneg_left (Real.rpow_le_self_of_one_le hK ha.2.le) + (Real.rpow_pos_of_pos hH0 a).le) + apply (mul_le_mul_iff_left₀ (Real.rpow_pos_of_pos hu a)).mp + convert hr' using 1 + dsimp [H, K] + ring + +namespace AnnulusData +variable {p : PMF ℕ} {a : ℝ} (D : AnnulusData p a) (M : MomentData p a) + +def envelope (t : ℝ) : ℝ := + Real.exp (-(D.decayConst / M.varUpper) * t ^ 2) + + Real.exp (-(D.decayConst / (max M.varUpper 1) ^ a) * |t| ^ a) + +lemma envelope_nonneg (t : ℝ) : 0 ≤ D.envelope M t := by + unfold envelope + positivity + +lemma envelope_integrable (ha : 0 < a) : Integrable (D.envelope M) := by + apply Integrable.add + · apply integrable_exp_neg_mul_sq + exact div_pos D.decayConst_pos M.varUpper_pos + · apply integrable_stretched_exp ha + exact div_pos D.decayConst_pos (Real.rpow_pos_of_pos (lt_of_lt_of_le zero_lt_one (le_max_right _ _)) a) + +lemma normalized_bound (ha : 0 < a ∧ a < 1) {u σ : ℝ} (hu : 0 < u) + (huD : u ≤ D.epsilon) (huM : u ≤ M.epsilon) {k : ℕ} + (hku : 1 ≤ (k : ℝ) * u ^ a) (hσ : 0 < σ) + (hvar : σ ^ 2 = k * natVariance (tilt p u hu.le)) + {ρ : ℝ} (hρ : 0 ≤ ρ) + (hgap : ∀ t, D.epsilon ≤ |t| → |t| ≤ Real.pi → ‖latticeChar (tilt p u hu.le) t‖ ≤ ρ) + (t : ℝ) (ht : |t| ≤ Real.pi * σ) : + ‖latticeChar (tilt p u hu.le) (t / σ)‖ ^ k ≤ D.envelope M t + ρ ^ k := by + have hV := M.varUpper_pos + have hv : σ ^ 2 ≤ (k : ℝ) * M.varUpper * u ^ (a - 2) := by + rw [hvar] + simpa only [mul_assoc] using mul_le_mul_of_nonneg_left (M.var_upper u hu huM) (Nat.cast_nonneg k) + have hσa := sigma_rpow_bound ha hu hσ hV hku hv + have hC := D.decayConst_pos + have hH : 0 < max M.varUpper 1 := lt_of_lt_of_le zero_lt_one (le_max_right _ _) + have hθ : |t / σ| ≤ Real.pi := by + rw [abs_div, abs_of_pos hσ, div_le_iff₀ hσ] + exact ht + by_cases hlo : |t / σ| ≤ u + · have hb := pow_le_pow_left₀ (norm_nonneg _) (D.char_bound hu huD hu.le le_rfl hlo) k + rw [← Real.exp_nat_mul] at hb + have hbase : σ ^ 2 / M.varUpper ≤ (k : ℝ) * u ^ (a - 2) := by + apply (div_le_iff₀ hV).mpr + nlinarith [hv] + have hm := mul_le_mul_of_nonneg_right hbase (by positivity : 0 ≤ D.decayConst * (t / σ) ^ 2) + have hid : σ ^ 2 / M.varUpper * (D.decayConst * (t / σ) ^ 2) = + D.decayConst / M.varUpper * t ^ 2 := by field_simp + rw [hid] at hm + have hexp : (k : ℝ) * (-D.decayConst * u ^ (a - 2) * (t / σ) ^ 2) ≤ + -(D.decayConst / M.varUpper) * t ^ 2 := by nlinarith + have he := hb.trans (Real.exp_le_exp.mpr hexp) + exact he.trans (by + unfold envelope + nlinarith [Real.exp_pos (-(D.decayConst / (max M.varUpper 1) ^ a) * |t| ^ a), pow_nonneg hρ k]) + · by_cases hmid : |t / σ| ≤ D.epsilon + · have hθ0 : 0 < |t / σ| := hu.trans (lt_of_not_ge hlo) + have hb := pow_le_pow_left₀ (norm_nonneg _) (D.intermediate hθ0 hmid hu.le (le_of_not_ge hlo)) k + rw [← Real.exp_nat_mul] at hb + have hcoef : D.decayConst / (max M.varUpper 1) ^ a ≤ D.decayConst * k / σ ^ a := by + apply (div_le_div_iff₀ (Real.rpow_pos_of_pos hH a) (Real.rpow_pos_of_pos hσ a)).mpr + nlinarith [mul_le_mul_of_nonneg_left hσa hC.le] + have hm := mul_le_mul_of_nonneg_right hcoef (Real.rpow_nonneg (abs_nonneg t) a) + have hid : |t / σ| ^ a = |t| ^ a / σ ^ a := by + rw [abs_div, abs_of_pos hσ, Real.div_rpow (abs_nonneg t) hσ.le] + have hexp : (k : ℝ) * (-D.decayConst * |t / σ| ^ a) ≤ + -(D.decayConst / (max M.varUpper 1) ^ a) * |t| ^ a := by + rw [hid] + simpa only [div_eq_mul_inv, mul_assoc, mul_left_comm, mul_comm, neg_mul, mul_neg] using neg_le_neg hm + have he := hb.trans (Real.exp_le_exp.mpr hexp) + exact he.trans (by + unfold envelope + nlinarith [Real.exp_pos (-(D.decayConst / M.varUpper) * t ^ 2), pow_nonneg hρ k]) + · have hb := pow_le_pow_left₀ (norm_nonneg _) (hgap (t / σ) (le_of_not_ge hmid) hθ) k + exact hb.trans (le_add_of_nonneg_left (D.envelope_nonneg M t)) + +end AnnulusData +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Fourier.lean b/lean/OAI/Probability/Renewal/Fourier.lean new file mode 100644 index 0000000000000000000000000000000000000000..a77dc2ad10ec996832ffd2ec635875e0b254af33 --- /dev/null +++ b/lean/OAI/Probability/Renewal/Fourier.lean @@ -0,0 +1,239 @@ +import OAI.Probability.Renewal.Definitions + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +namespace HoneycombLocal + +def latticeChar (p : PMF ℕ) (t : ℝ) : ℂ := + ∫ j, Complex.exp (((j : ℝ) * t : ℝ) * Complex.I) ∂p.toMeasure + +lemma integrable_lattice_exp (p : PMF ℕ) (t : ℝ) : + Integrable (fun j : ℕ => Complex.exp (((j : ℝ) * t : ℝ) * Complex.I)) p.toMeasure := by + apply Integrable.of_bound (Measurable.of_discrete.aestronglyMeasurable) 1 + exact Filter.Eventually.of_forall (fun j => by rw [Complex.norm_exp_ofReal_mul_I]) + +lemma latticeChar_eq_charFun (p : PMF ℕ) (t : ℝ) : + latticeChar p t = charFun (Measure.map (fun j : ℕ => (j : ℝ)) p.toMeasure) t := by + rw [charFun_apply, integral_map Measurable.of_discrete.aemeasurable] + · simp only [latticeChar, RCLike.inner_apply, conj_trivial, mul_comm] + · exact (by fun_prop : Continuous (fun x : ℝ => Complex.exp ((inner ℝ x t : ℝ) * Complex.I))).aestronglyMeasurable + +lemma norm_latticeChar_le_one (p : PMF ℕ) (t : ℝ) : ‖latticeChar p t‖ ≤ 1 := by + rw [latticeChar_eq_charFun] + exact norm_charFun_le_one t + +lemma continuous_latticeChar (p : PMF ℕ) : Continuous (latticeChar p) := by + have he : latticeChar p = charFun (Measure.map (fun j : ℕ => (j : ℝ)) p.toMeasure) := + funext (latticeChar_eq_charFun p) + rw [he] + exact continuous_charFun + +lemma integral_lattice_exp (z : ℤ) : + (∫ t : ℝ in -Real.pi..Real.pi, + Complex.exp (((z : ℝ) * t : ℝ) * Complex.I)) = + if z = 0 then (2 * Real.pi : ℂ) else 0 := by + by_cases hz : z = 0 + · subst z + simp [intervalIntegral.integral_const] + ring + · rw [ite_eq_right hz] + have hz' : (z : ℂ) * Complex.I ≠ 0 := mul_ne_zero (by exact_mod_cast hz) Complex.I_ne_zero + have heq : (fun t : ℝ => Complex.exp (((z : ℝ) * t : ℝ) * Complex.I)) = + fun t : ℝ => Complex.exp (((z : ℂ) * Complex.I) * t) := by + ext t; congr 1; push_cast; ring + rw [heq, integral_exp_mul_complex hz'] + have he : Complex.exp (((z : ℂ) * Complex.I) * Real.pi) = + Complex.exp (((z : ℂ) * Complex.I) * (-Real.pi)) := by + have e1 : ((z : ℂ) * Complex.I) * Real.pi = ((z : ℝ) * Real.pi : ℝ) * Complex.I := by push_cast; ring + have e2 : ((z : ℂ) * Complex.I) * (-Real.pi) = -((z : ℝ) * Real.pi : ℝ) * Complex.I := by push_cast; ring + rw [e1, e2, Complex.exp_mul_I, Complex.exp_mul_I] + have hs : Complex.sin (((z : ℝ) * Real.pi : ℝ) : ℂ) = 0 := by + rw [← Complex.ofReal_sin, Real.sin_int_mul_pi]; rfl + simp only [Complex.cos_neg, Complex.sin_neg, hs, zero_mul, add_zero, neg_zero] + simp only [Complex.ofReal_neg] + rw [he, sub_self, zero_div] + +lemma lattice_inversion (p : PMF ℕ) (m : ℕ) : + (∫ t : ℝ in -Real.pi..Real.pi, + latticeChar p t * Complex.exp (-((m : ℝ) * t : ℝ) * Complex.I)) = + (2 * Real.pi : ℂ) * ((p m).toReal : ℂ) := by + have hpi : -Real.pi ≤ Real.pi := by linarith [Real.pi_pos] + let ν : Measure ℝ := volume.restrict (Ioc (-Real.pi) Real.pi) + let f : ℝ → ℕ → ℂ := fun t j => Complex.exp ((((j : ℝ) - m) * t : ℝ) * Complex.I) + have hi : Integrable (Function.uncurry f) (ν.prod p.toMeasure) := by + refine Integrable.of_bound ?_ 1 ?_ + · have : Continuous (Function.uncurry f) := by dsimp [f, Function.uncurry]; fun_prop + exact this.aestronglyMeasurable + · exact Filter.Eventually.of_forall (fun x => by dsimp [f, Function.uncurry]; rw [Complex.norm_exp_ofReal_mul_I]) + have hpoint (t : ℝ) : latticeChar p t * Complex.exp (-((m : ℝ) * t : ℝ) * Complex.I) = + ∫ j, f t j ∂p.toMeasure := by + rw [latticeChar, ← integral_mul_const] + congr 1; ext j + dsimp [f] + rw [← Complex.exp_add] + congr 1 + push_cast; ring + simp_rw [hpoint] + rw [intervalIntegral.integral_of_le hpi] + change (∫ t, ∫ j, f t j ∂p.toMeasure ∂ν) = _ + rw [integral_integral_swap hi] + have hinner (j : ℕ) : (∫ t, f t j ∂ν) = + ({m} : Set ℕ).indicator (fun _ => (2 * Real.pi : ℂ)) j := by + change (∫ t in Ioc (-Real.pi) Real.pi, f t j) = _ + rw [← intervalIntegral.integral_of_le hpi] + have he : (fun t => f t j) = fun t : ℝ => + Complex.exp ((((((j : ℤ) - m) : ℤ) : ℝ) * t : ℝ) * Complex.I) := by + ext t; dsimp [f]; push_cast; rfl + rw [he, integral_lattice_exp] + by_cases hj : j = m + · subst j; simp + · have : (j : ℤ) - m ≠ 0 := by omega + simp [this, hj] + simp_rw [hinner] + rw [integral_indicator (measurableSet_singleton _), integral_singleton] + simp [Measure.real, p.toMeasure_apply_singleton m (measurableSet_singleton _), mul_comm] + +lemma two_copy_defect (p : PMF ℕ) (t : ℝ) : + (∫ z : ℕ × ℕ, 1 - Real.cos (((z.1 : ℝ) - z.2) * t) + ∂p.toMeasure.prod p.toMeasure) = 1 - ‖latticeChar p t‖ ^ 2 := by + let e : ℕ → ℂ := fun j => Complex.exp (((j : ℝ) * t : ℝ) * Complex.I) + let d : ℕ × ℕ → ℂ := fun z => Complex.exp ((((z.1 : ℝ) - z.2) * t : ℝ) * Complex.I) + have hi : Integrable d (p.toMeasure.prod p.toMeasure) := by + refine Integrable.of_bound Measurable.of_discrete.aestronglyMeasurable 1 ?_ + exact Filter.Eventually.of_forall (fun z => by dsimp [d]; rw [Complex.norm_exp_ofReal_mul_I]) + have heq (z : ℕ × ℕ) : d z = e z.1 * star (e z.2) := by + dsimp [e, d] + rw [← Complex.exp_conj, ← Complex.exp_add] + congr 1 + simp only [map_mul, Complex.conj_ofReal, Complex.conj_I] + push_cast; ring + have hp : (∫ z, d z ∂p.toMeasure.prod p.toMeasure) = + latticeChar p t * star (latticeChar p t) := by + simp_rw [heq] + rw [integral_prod_mul e (fun j => star (e j))] + change (∫ x, e x ∂p.toMeasure) * (∫ y, (starRingEnd ℂ) (e y) ∂p.toMeasure) = _ + rw [integral_conj] + rfl + have hr (z : ℕ × ℕ) : (d z).re = Real.cos (((z.1 : ℝ) - z.2) * t) := by + simp [d, Complex.exp_re] + have hcint : Integrable (fun z : ℕ × ℕ => Real.cos (((z.1 : ℝ) - z.2) * t)) + (p.toMeasure.prod p.toMeasure) := by + simpa only [RCLike.re_to_complex, hr] using hi.re + have hc : (∫ z : ℕ × ℕ, Real.cos (((z.1 : ℝ) - z.2) * t) + ∂p.toMeasure.prod p.toMeasure) = ‖latticeChar p t‖ ^ 2 := by + simp_rw [← hr] + have hreal : (∫ z, (d z).re ∂p.toMeasure.prod p.toMeasure) = + (∫ z, d z ∂p.toMeasure.prod p.toMeasure).re := by + simpa only [RCLike.re_to_complex] using integral_re hi + rw [hreal, hp] + change (latticeChar p t * (starRingEnd ℂ) (latticeChar p t)).re = _ + rw [Complex.mul_conj', ← Complex.ofReal_pow, Complex.ofReal_re] + rw [integral_sub (integrable_const 1) hcint, hc] + simp + +lemma integrable_two_copy_defect (p : PMF ℕ) (t : ℝ) : + Integrable (fun z : ℕ × ℕ => 1 - Real.cos (((z.1 : ℝ) - z.2) * t)) + (p.toMeasure.prod p.toMeasure) := by + refine Integrable.of_bound Measurable.of_discrete.aestronglyMeasurable 2 ?_ + filter_upwards [] with z + rw [Real.norm_eq_abs, abs_of_nonneg (sub_nonneg.mpr (Real.cos_le_one _))] + linarith [Real.neg_one_le_cos (((z.1 : ℝ) - z.2) * t)] + +lemma rectangle_defect_bound (p : PMF ℕ) (t r : ℝ) (s b : Set ℕ) + (hlower : ∀ j ∈ s, ∀ l ∈ b, r ≤ 1 - Real.cos (((j : ℝ) - l) * t)) : + p.toMeasure.real s * p.toMeasure.real b * r ≤ 1 - ‖latticeChar p t‖ ^ 2 := by + let μ := p.toMeasure.prod p.toMeasure + have hi := integrable_two_copy_defect p t + have hpos : 0 ≤ fun z : ℕ × ℕ => 1 - Real.cos (((z.1 : ℝ) - z.2) * t) := + fun z => sub_nonneg.mpr (Real.cos_le_one _) + calc + p.toMeasure.real s * p.toMeasure.real b * r = ∫ z : ℕ × ℕ in s ×ˢ b, r ∂μ := by + simp [Measure.real, Measure.prod_prod, ENNReal.toReal_mul, μ] + _ ≤ ∫ z : ℕ × ℕ in s ×ˢ b, 1 - Real.cos (((z.1 : ℝ) - z.2) * t) ∂μ := by + apply setIntegral_mono_on (integrable_const r) hi.integrableOn MeasurableSet.of_discrete + intro z hz + exact hlower z.1 hz.1 z.2 hz.2 + _ ≤ ∫ z : ℕ × ℕ, 1 - Real.cos (((z.1 : ℝ) - z.2) * t) ∂μ := + setIntegral_le_integral hi (Filter.Eventually.of_forall hpos) + _ = 1 - ‖latticeChar p t‖ ^ 2 := two_copy_defect p t + +lemma support_diff_cos_eq_one (p : PMF ℕ) {t : ℝ} (hnorm : ‖latticeChar p t‖ = 1) + {j l : ℕ} (hj : j ∈ p.support) (hl : l ∈ p.support) : + Real.cos (((j : ℝ) - l) * t) = 1 := by + have h := rectangle_defect_bound p t (1 - Real.cos (((j : ℝ) - l) * t)) {j} {l} + (by intro x hx y hy; rw [mem_singleton_iff.mp hx, mem_singleton_iff.mp hy]) + have hj' : 0 < (p j).toReal := ENNReal.toReal_pos (p.mem_support_iff j |>.mp hj) (p.apply_ne_top j) + have hl' : 0 < (p l).toReal := ENNReal.toReal_pos (p.mem_support_iff l |>.mp hl) (p.apply_ne_top l) + simp only [Measure.real, p.toMeasure_apply_singleton _ (measurableSet_singleton _), hnorm, + one_pow, sub_self] at h + have hprod : 0 < (p j).toReal * (p l).toReal := mul_pos hj' hl' + have hc : 0 ≤ 1 - Real.cos (((j : ℝ) - l) * t) := sub_nonneg.mpr (Real.cos_le_one _) + nlinarith + +lemma exp_of_cos_eq_one {x : ℝ} (h : Real.cos x = 1) : + Complex.exp ((x : ℂ) * Complex.I) = 1 := by + rcases (Real.cos_eq_one_iff x).mp h with ⟨n, hn⟩ + apply Complex.exp_eq_one_iff.mpr + refine ⟨n, ?_⟩ + rw [← hn] + push_cast + ring + +lemma norm_latticeChar_lt_one (p : PMF ℕ) (hspan : SpanOne p) {t : ℝ} + (ht : t ≠ 0) (htpi : |t| ≤ Real.pi) : ‖latticeChar p t‖ < 1 := by + refine lt_of_le_of_ne (norm_latticeChar_le_one p t) ?_ + intro hnorm + have h1 : (1 : ℤ) ∈ AddSubgroup.closure + {z : ℤ | ∃ j ∈ p.support, ∃ k ∈ p.support, z = (j : ℤ) - k} := by + rw [hspan] + trivial + have hexp : Complex.exp ((((1 : ℤ) : ℝ) * t : ℝ) * Complex.I) = 1 := by + refine AddSubgroup.closure_induction (p := fun (z : ℤ) _ => + Complex.exp (((z : ℝ) * t : ℝ) * Complex.I) = 1) ?_ ?_ ?_ ?_ h1 + · intro z hz + rcases hz with ⟨j, hj, l, hl, rfl⟩ + simpa only [Int.cast_sub, Int.cast_natCast] using + exp_of_cos_eq_one (support_diff_cos_eq_one p hnorm hj hl) + · simp + · intro x y hx hy hx' hy' + have heq : ((((x + y : ℤ) : ℝ) * t : ℝ) : ℂ) * Complex.I = + (((x : ℝ) * t : ℝ) : ℂ) * Complex.I + (((y : ℝ) * t : ℝ) : ℂ) * Complex.I := by + push_cast; ring + rw [heq, Complex.exp_add, hx', hy', one_mul] + · intro x hx hx' + have heq : ((((-x : ℤ) : ℝ) * t : ℝ) : ℂ) * Complex.I = + -((((x : ℝ) * t : ℝ) : ℂ) * Complex.I) := by push_cast; ring + rw [heq, Complex.exp_neg, hx', inv_one] + have hcos : Real.cos t = 1 := by + have := congrArg Complex.re hexp + simpa only [Int.cast_one, one_mul, Complex.exp_ofReal_mul_I_re, Complex.one_re] using this + have hb := abs_le.mp htpi + exact ht ((Real.cos_eq_one_iff_of_lt_of_lt + (by linarith [Real.pi_pos]) (by linarith [Real.pi_pos])).mp hcos) + +lemma lattice_spectral_gap (p : PMF ℕ) (hspan : SpanOne p) {δ : ℝ} (hδ : 0 < δ) : + ∃ ρ : ℝ, 0 ≤ ρ ∧ ρ < 1 ∧ + ∀ t : ℝ, δ ≤ |t| → |t| ≤ Real.pi → ‖latticeChar p t‖ ≤ ρ := by + by_cases hdpi : δ ≤ Real.pi + · let s : Set ℝ := {t | δ ≤ |t|} ∩ Icc (-Real.pi) Real.pi + have hs : IsCompact s := isCompact_Icc.inter_left (isClosed_le continuous_const continuous_abs) + have hne : s.Nonempty := ⟨Real.pi, by simp [s, abs_of_pos Real.pi_pos, hdpi, Real.pi_pos.le]⟩ + obtain ⟨t, ht, hmax⟩ := hs.exists_isMaxOn hne (continuous_latticeChar p |>.norm.continuousOn) + refine ⟨‖latticeChar p t‖, norm_nonneg _, ?_, ?_⟩ + · apply norm_latticeChar_lt_one p hspan + · intro h; subst t; have := ht.1; simp only [abs_zero, mem_ofPred_eq] at this; linarith + · exact abs_le.mpr ht.2 + · intro y hy hy' + exact hmax ⟨hy, abs_le.mp hy'⟩ + · refine ⟨0, le_rfl, zero_lt_one, ?_⟩ + intro t ht ht' + exact False.elim (hdpi (ht.trans ht')) + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/GaussianCore.lean b/lean/OAI/Probability/Renewal/GaussianCore.lean new file mode 100644 index 0000000000000000000000000000000000000000..3f16524b5a36da333e403c5116b82e1ffd2e119e --- /dev/null +++ b/lean/OAI/Probability/Renewal/GaussianCore.lean @@ -0,0 +1,156 @@ +import Mathlib + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +namespace HoneycombLocal + +lemma norm_iteratedDeriv_charFun_le {μ : Measure ℝ} [IsFiniteMeasure μ] + {n : ℕ} (h : MemLp id n μ) (t : ℝ) : + ‖iteratedDeriv n (charFun μ) t‖ ≤ ∫ x, ‖x‖ ^ n ∂μ := by + rw [iteratedDeriv_charFun h, norm_mul, norm_pow, Complex.norm_I, one_pow, one_mul] + refine (norm_integral_le_integral_norm _).trans_eq ?_ + congr 1 + ext x + simp only [norm_mul, norm_pow, Complex.norm_real] + rw [← Complex.ofReal_mul, Complex.norm_exp_ofReal_mul_I, mul_one] + +lemma taylorWithinEval_eq_univ {f : ℝ → ℂ} {t : ℝ} (ht : 0 < t) + (hf : ContDiff ℝ 3 f) : + taylorWithinEval f 2 (Icc 0 t) 0 t = taylorWithinEval f 2 univ 0 t := by + simp only [taylor_within_apply] + apply Finset.sum_congr rfl + intro k hk + have hk3 : k ≤ 3 := by have := Finset.mem_range.mp hk; omega + have hd : ContDiffAt ℝ k f 0 := hf.contDiffAt.of_le (by exact_mod_cast hk3) + rw [iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Icc ht) hd ⟨le_rfl, ht.le⟩, + iteratedDerivWithin_eq_iteratedDeriv uniqueDiffOn_univ hd (mem_univ 0)] + +lemma taylor_charFun_bound_nonneg {μ : Measure ℝ} [IsProbabilityMeasure μ] + (h3 : MemLp id 3 μ) (hmean : ∫ x, x ∂μ = 0) {t : ℝ} (ht : 0 ≤ t) : + ‖charFun μ t - (1 - ((∫ x, x ^ 2 ∂μ : ℝ) : ℂ) * (t : ℂ) ^ 2 / 2)‖ ≤ + (∫ x, ‖x‖ ^ 3 ∂μ) * t ^ 3 / 2 := by + rcases ht.eq_or_lt with rfl | ht + · simp + have hc : ContDiff ℝ 3 (charFun μ) := contDiff_charFun h3 + have h2 : MemLp id 2 μ := h3.mono_exponent (by norm_num) + have h := taylor_mean_remainder_bound (n := 2) (a := 0) (b := t) + (C := ∫ x, ‖x‖ ^ 3 ∂μ) ht.le hc.contDiffOn ⟨ht.le, le_rfl⟩ (by + intro y hy + rw [iteratedDerivWithin_eq_iteratedDeriv (uniqueDiffOn_Icc ht) hc.contDiffAt hy] + exact norm_iteratedDeriv_charFun_le h3 y) + rw [taylorWithinEval_eq_univ ht hc] at h + have htaylor := taylorWithinEval_charFun_two_zero (P := μ) (X := id) + aemeasurable_id (by simpa using h2) t + simp only [Measure.map_id, id_eq, Pi.pow_apply, hmean, Complex.ofReal_zero, + zero_mul, add_zero] at htaylor + rw [htaylor] at h + simpa using h + +lemma taylor_charFun_bound {μ : Measure ℝ} [IsProbabilityMeasure μ] + (h3 : MemLp id 3 μ) (hmean : ∫ x, x ∂μ = 0) (t : ℝ) : + ‖charFun μ t - (1 - ((∫ x, x ^ 2 ∂μ : ℝ) : ℂ) * (t : ℂ) ^ 2 / 2)‖ ≤ + (∫ x, ‖x‖ ^ 3 ∂μ) * |t| ^ 3 / 2 := by + by_cases ht : 0 ≤ t + · simpa [abs_of_nonneg ht] using taylor_charFun_bound_nonneg h3 hmean ht + · have ht' : 0 ≤ -t := by linarith + have h := taylor_charFun_bound_nonneg h3 hmean ht' + have heq : charFun μ (-t) - + (1 - ((∫ x, x ^ 2 ∂μ : ℝ) : ℂ) * ((-t : ℝ) : ℂ) ^ 2 / 2) = + star (charFun μ t - (1 - ((∫ x, x ^ 2 ∂μ : ℝ) : ℂ) * (t : ℂ) ^ 2 / 2)) := by + simp [charFun_neg] + rw [heq, norm_star] at h + simpa [abs_of_neg (lt_of_not_ge ht)] using h + +lemma norm_pow_difference {z w : ℂ} (hz : ‖z‖ ≤ 1) (hw : ‖w‖ ≤ 1) (k : ℕ) : + ‖z ^ k - w ^ k‖ ≤ k * ‖z - w‖ := by + induction k with + | zero => simp + | succ k hk => + calc + ‖z ^ (k + 1) - w ^ (k + 1)‖ = + ‖z * (z ^ k - w ^ k) + (z - w) * w ^ k‖ := by congr 1; ring + _ ≤ ‖z * (z ^ k - w ^ k)‖ + ‖(z - w) * w ^ k‖ := norm_add_le _ _ + _ = ‖z‖ * ‖z ^ k - w ^ k‖ + ‖z - w‖ * ‖w‖ ^ k := by simp [norm_pow] + _ ≤ 1 * (k * ‖z - w‖) + ‖z - w‖ * 1 := by + gcongr + exact pow_le_one₀ (norm_nonneg _) hw + _ = (k + 1 : ℕ) * ‖z - w‖ := by push_cast; ring + +lemma exp_neg_error_le {y : ℝ} (hy : 0 ≤ y) (hy1 : y ≤ 1) : + ‖Complex.exp (-(y : ℂ)) - (1 - (y : ℂ))‖ ≤ y ^ 2 := by + have h := Complex.norm_exp_sub_one_sub_id_le + (x := -(y : ℂ)) (by simpa [abs_of_nonneg hy] using hy1) + convert h using 1 + · congr 1; ring + · simp [abs_of_nonneg hy] + +lemma gaussian_power_error {μ : Measure ℝ} [IsProbabilityMeasure μ] + (h3 : MemLp id 3 μ) (hmean : ∫ x, x ∂μ = 0) (k : ℕ) (t : ℝ) + (hsmall : (∫ x, x ^ 2 ∂μ) * t ^ 2 / 2 ≤ 1) : + ‖charFun μ t ^ k - Complex.exp (-((k : ℂ) * + ((∫ x, x ^ 2 ∂μ : ℝ) : ℂ) * (t : ℂ) ^ 2 / 2))‖ ≤ + k * ((∫ x, ‖x‖ ^ 3 ∂μ) * |t| ^ 3 / 2 + + ((∫ x, x ^ 2 ∂μ) * t ^ 2 / 2) ^ 2) := by + let v : ℝ := ∫ x, x ^ 2 ∂μ + let y : ℝ := v * t ^ 2 / 2 + have hv : 0 ≤ v := integral_nonneg (fun x => sq_nonneg x) + have hy : 0 ≤ y := by dsimp [y]; positivity + have hnorm : ‖Complex.exp (-(y : ℂ))‖ ≤ 1 := by + rw [← Complex.ofReal_neg, Complex.norm_exp_ofReal] + exact Real.exp_le_one_iff.mpr (neg_nonpos.mpr hy) + have hdiff : ‖charFun μ t - Complex.exp (-(y : ℂ))‖ ≤ + (∫ x, ‖x‖ ^ 3 ∂μ) * |t| ^ 3 / 2 + y ^ 2 := by + refine (norm_sub_le_norm_sub_add_norm_sub (charFun μ t) (1 - (y : ℂ)) + (Complex.exp (-(y : ℂ)))).trans ?_ + apply add_le_add + · simpa [y, v] using taylor_charFun_bound h3 hmean t + · rw [norm_sub_rev] + exact exp_neg_error_le hy hsmall + have hpow := (norm_pow_difference (norm_charFun_le_one t) hnorm k).trans + (mul_le_mul_of_nonneg_left hdiff (Nat.cast_nonneg k)) + have heq : Complex.exp (-(y : ℂ)) ^ k = + Complex.exp (-((k : ℂ) * (v : ℂ) * (t : ℂ) ^ 2 / 2)) := by + rw [← Complex.exp_nat_mul] + congr 1 + simp only [y, Complex.ofReal_div, Complex.ofReal_mul, Complex.ofReal_pow, + Complex.ofReal_ofNat] + ring + rw [heq] at hpow + exact hpow + +lemma normalized_gaussian_power_error {μ : Measure ℝ} [IsProbabilityMeasure μ] + (h3 : MemLp id 3 μ) (hmean : ∫ x, x ∂μ = 0) {k : ℕ} (hk : 0 < k) + {σ : ℝ} (hσ : 0 < σ) (hvariance : σ ^ 2 = k * ∫ x, x ^ 2 ∂μ) + (t : ℝ) (hsmall : t ^ 2 ≤ 2 * k) : + ‖charFun μ (t / σ) ^ k - Complex.exp (-((t : ℂ) ^ 2 / 2))‖ ≤ + ((k : ℝ) * (∫ x, ‖x‖ ^ 3 ∂μ) / σ ^ 3) * |t| ^ 3 / 2 + + t ^ 4 / (4 * k) := by + have hk' : (0 : ℝ) < k := by exact_mod_cast hk + have heq : (∫ x, x ^ 2 ∂μ) * (t / σ) ^ 2 / 2 = t ^ 2 / (2 * k) := by + field_simp + nlinarith [hvariance] + have h := gaussian_power_error h3 hmean k (t / σ) (by + rw [heq]; exact (div_le_one (by positivity)).2 hsmall) + have hexp : -((k : ℂ) * ((∫ x, x ^ 2 ∂μ : ℝ) : ℂ) * + ((t / σ : ℝ) : ℂ) ^ 2 / 2) = -((t : ℂ) ^ 2 / 2) := by + have hvr : (∫ x, x ^ 2 ∂μ) = σ ^ 2 / k := by + exact (eq_div_iff (ne_of_gt hk')).2 (by simpa [mul_comm] using hvariance.symm) + rw [hvr] + push_cast + have hkC : (k : ℂ) ≠ 0 := by exact_mod_cast hk.ne' + have hσC : (σ : ℂ) ≠ 0 := by exact_mod_cast hσ.ne' + field_simp + rw [hexp, heq] at h + convert h using 1 + rw [abs_div, abs_of_pos hσ] + field_simp + ring + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Laplace.lean b/lean/OAI/Probability/Renewal/Laplace.lean new file mode 100644 index 0000000000000000000000000000000000000000..0cb40ef3b8469b31f9eeeae321e98d0e66bab7eb --- /dev/null +++ b/lean/OAI/Probability/Renewal/Laplace.lean @@ -0,0 +1,164 @@ +import OAI.Probability.Renewal.Definitions + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology +namespace HoneycombLocal + +lemma integrable_laplace (p : PMF ℕ) {u : ℝ} (hu : 0 ≤ u) : + Integrable (fun j : ℕ => Real.exp (-u * (j : ℝ))) p.toMeasure := by + refine Integrable.of_bound Measurable.of_discrete.aestronglyMeasurable 1 ?_ + filter_upwards [] with j + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr hu) (Nat.cast_nonneg _)) + +lemma laplace_pos (p : PMF ℕ) {u : ℝ} (hu : 0 ≤ u) : 0 < laplace p u := + integral_exp_pos (integrable_laplace p hu) + +lemma laplace_le_one (p : PMF ℕ) {u : ℝ} (hu : 0 ≤ u) : laplace p u ≤ 1 := by + calc + laplace p u ≤ ∫ _ : ℕ, (1 : ℝ) ∂p.toMeasure := by + apply integral_mono (integrable_laplace p hu) (integrable_const 1) + intro j + exact Real.exp_le_one_iff.mpr (by nlinarith [Nat.cast_nonneg (α := ℝ) j]) + _ = 1 := by simp + +lemma integrable_deficit (p : PMF ℕ) {u : ℝ} (hu : 0 ≤ u) : + Integrable (fun j : ℕ => 1 - Real.exp (-u * (j : ℝ))) p.toMeasure := + (integrable_const 1).sub (integrable_laplace p hu) + +lemma deficit_integral (p : PMF ℕ) {u : ℝ} (hu : 0 ≤ u) : + (∫ j : ℕ, 1 - Real.exp (-u * (j : ℝ)) ∂p.toMeasure) = 1 - laplace p u := by + rw [integral_sub (integrable_const 1) (integrable_laplace p hu)] + simp [laplace] + +lemma one_sub_exp_neg_le (x : ℝ) : 1 - Real.exp (-x) ≤ x := by + linarith [Real.add_one_le_exp (-x)] + +lemma one_sub_exp_neg_lower {s : ℝ} (hs : 0 ≤ s) (hs1 : s ≤ 1) : + Real.exp (-1) * s ≤ 1 - Real.exp (-s) := by + have h := mul_le_mul_of_nonneg_right (Real.add_one_le_exp s) (Real.exp_pos (-s)).le + rw [← Real.exp_add, add_neg_cancel, Real.exp_zero] at h + have he : Real.exp (-1) ≤ Real.exp (-s) := Real.exp_le_exp.mpr (neg_le_neg hs1) + have hm := mul_le_mul_of_nonneg_right he hs + nlinarith + +lemma laplace_split_bound (p : PMF ℕ) {u y x : ℝ} (hu : 0 < u) (hy : 0 < y) : + 1 - laplace p u ≤ (u * y / Real.exp (-1)) * (1 - laplace p y⁻¹) + + p.toMeasure.real {j | y < (j : ℝ) ∧ (j : ℝ) ≤ x} + + p.toMeasure.real {j | x < (j : ℝ)} := by + let K : ℝ := u * y / Real.exp (-1) + let s : Set ℕ := {j | y < (j : ℝ) ∧ (j : ℝ) ≤ x} + let b : Set ℕ := {j | x < (j : ℝ)} + have hK : 0 ≤ K := by dsimp [K]; positivity + have hc := integrable_deficit p (inv_nonneg.mpr hy.le) + have hs : Integrable (s.indicator (fun _ => (1 : ℝ))) p.toMeasure := + (integrable_const 1).indicator MeasurableSet.of_discrete + have hb : Integrable (b.indicator (fun _ => (1 : ℝ))) p.toMeasure := + (integrable_const 1).indicator MeasurableSet.of_discrete + have hpt (j : ℕ) : 1 - Real.exp (-u * (j : ℝ)) ≤ + K * (1 - Real.exp (-y⁻¹ * (j : ℝ))) + + s.indicator (fun _ => (1 : ℝ)) j + b.indicator (fun _ => (1 : ℝ)) j := by + have hn : (0 : ℝ) ≤ j := Nat.cast_nonneg _ + have hdef : 0 ≤ 1 - Real.exp (-y⁻¹ * (j : ℝ)) := by + have he : Real.exp (-y⁻¹ * (j : ℝ)) ≤ 1 := Real.exp_le_one_iff.mpr (mul_nonpos_of_nonpos_of_nonneg + (neg_nonpos.mpr (inv_nonneg.mpr hy.le)) hn) + linarith + have hsi : 0 ≤ s.indicator (fun _ => (1 : ℝ)) j := Set.indicator_nonneg (fun _ _ => zero_le_one) _ + have hbi : 0 ≤ b.indicator (fun _ => (1 : ℝ)) j := Set.indicator_nonneg (fun _ _ => zero_le_one) _ + by_cases hj : (j : ℝ) ≤ y + · have hsmall : y⁻¹ * (j : ℝ) ≤ 1 := by + rw [inv_mul_eq_div, div_le_one hy]; exact hj + have hlo := one_sub_exp_neg_lower (mul_nonneg (inv_nonneg.mpr hy.le) hn) hsmall + have hmul := mul_le_mul_of_nonneg_left hlo hK + have hid : K * (Real.exp (-1) * (y⁻¹ * j)) = u * (j : ℝ) := by + dsimp [K]; field_simp + rw [hid] at hmul + have hup := one_sub_exp_neg_le (u * j) + simp only [neg_mul] at hlo hmul hup ⊢ + linarith + · by_cases hjx : (j : ℝ) ≤ x + · have hmem : j ∈ s := ⟨lt_of_not_ge hj, hjx⟩ + rw [Set.indicator_of_mem hmem] + nlinarith [Real.exp_pos (-u * (j : ℝ)), mul_nonneg hK hdef] + · have hmem : j ∈ b := lt_of_not_ge hjx + rw [Set.indicator_of_mem hmem] + nlinarith [Real.exp_pos (-u * (j : ℝ)), mul_nonneg hK hdef] + have h := integral_mono (integrable_deficit p hu.le) ((hc.const_mul K).add hs |>.add hb) hpt + have hsum : (∫ j : ℕ, K * (1 - Real.exp (-y⁻¹ * j)) + + s.indicator (fun _ => (1 : ℝ)) j + b.indicator (fun _ => (1 : ℝ)) j ∂p.toMeasure) = + (∫ j : ℕ, K * (1 - Real.exp (-y⁻¹ * j)) + s.indicator (fun _ => (1 : ℝ)) j ∂p.toMeasure) + + ∫ j, b.indicator (fun _ => (1 : ℝ)) j ∂p.toMeasure := by + simpa only [Pi.add_apply] using integral_add ((hc.const_mul K).add hs) hb + have hsum' : (∫ j : ℕ, K * (1 - Real.exp (-y⁻¹ * j)) + s.indicator (fun _ => (1 : ℝ)) j ∂p.toMeasure) = + (∫ j : ℕ, K * (1 - Real.exp (-y⁻¹ * j)) ∂p.toMeasure) + + ∫ j, s.indicator (fun _ => (1 : ℝ)) j ∂p.toMeasure := by + simpa only [Pi.add_apply] using integral_add (hc.const_mul K) hs + simp only [Pi.add_apply] at h + rw [deficit_integral p hu.le, hsum, hsum', integral_const_mul, + deficit_integral p (inv_nonneg.mpr hy.le), integral_indicator MeasurableSet.of_discrete, + integral_indicator MeasurableSet.of_discrete] at h + simpa [K, s, b] using h + +lemma annular_mass (p : PMF ℕ) {a : ℝ} (ha : 0 < a ∧ a < 1) + (hpower : BoundedPowerInput p a) : + ∃ M > (1 : ℝ), ∃ c₁ > (0 : ℝ), ∀ᶠ x : ℝ in atTop, + c₁ * x ^ (-a) ≤ p.toMeasure.real {j | x / M < (j : ℝ) ∧ (j : ℝ) ≤ x} := by + rcases hpower with ⟨c, hc, C, hC, x₀, hx₀, htail, hLap⟩ + have hAev : ∀ᶠ A : ℝ in atTop, 4 * C / c ≤ A ^ a := + (tendsto_rpow_atTop ha.1).eventually (eventually_ge_atTop _) + obtain ⟨A, hA, hApow⟩ := ((eventually_gt_atTop (0 : ℝ)).and hAev).exists + have hD : 0 < c * A ^ a := mul_pos hc (Real.rpow_pos_of_pos hA a) + have hCA : 4 * C ≤ c * A ^ a := by + have := (div_le_iff₀ hc).mp hApow + nlinarith + have hMlim : Tendsto (fun M : ℝ => C * A / Real.exp (-1) * M ^ (a - 1)) atTop (𝓝 0) := by + have := (tendsto_rpow_neg_atTop (sub_pos.mpr ha.2)).const_mul (C * A / Real.exp (-1)) + simpa only [neg_sub, mul_zero] using this + have hMev : ∀ᶠ M : ℝ in atTop, + C * A / Real.exp (-1) * M ^ (a - 1) < c * A ^ a / 4 := + hMlim.eventually (Iio_mem_nhds (by positivity)) + obtain ⟨M, hM, hMpow⟩ := ((eventually_gt_atTop (1 : ℝ)).and hMev).exists + have hM0 : 0 < M := zero_lt_one.trans hM + refine ⟨M, hM, c * A ^ a / 2, by positivity, ?_⟩ + filter_upwards [eventually_ge_atTop x₀, eventually_ge_atTop (A * x₀), + eventually_ge_atTop (M * x₀)] with x hx hxA hxM + have hxpos : 0 < x := hx₀.trans_le hx + have hAu : A / x ≤ x₀⁻¹ := by + rw [← one_div] + apply (div_le_div_iff₀ hxpos hx₀).mpr + simpa using hxA + have hMu : M / x ≤ x₀⁻¹ := by + rw [← one_div] + apply (div_le_div_iff₀ hxpos hx₀).mpr + simpa using hxM + have hlow := (hLap (A / x) (div_pos hA hxpos) hAu).1 + have hup := (hLap (M / x) (div_pos hM0 hxpos) hMu).2 + have hsplit := laplace_split_bound p (x := x) (div_pos hA hxpos) (div_pos hxpos hM0) + have hinv : (x / M)⁻¹ = M / x := by field_simp + rw [hinv] at hsplit + have halg : c * (A / x) ^ a = c * A ^ a * x ^ (-a) := by + rw [Real.div_rpow hA.le hxpos.le, Real.rpow_neg hxpos.le] + ring + rw [halg] at hlow + have hcoef : 0 ≤ (A / x) * (x / M) / Real.exp (-1) := by positivity + have hup' := mul_le_mul_of_nonneg_left hup hcoef + have halg' : (A / x * (x / M) / Real.exp (-1)) * (C * (M / x) ^ a) = + (C * A / Real.exp (-1) * M ^ (a - 1)) * x ^ (-a) := by + rw [Real.div_rpow hM0.le hxpos.le, Real.rpow_sub hM0, Real.rpow_one, + Real.rpow_neg hxpos.le] + field_simp + rw [halg'] at hup' + have hscale : 0 ≤ x ^ (-a) := Real.rpow_nonneg hxpos.le _ + have hms := mul_le_mul_of_nonneg_right hMpow.le hscale + have hts := htail x hx + have hcs := mul_le_mul_of_nonneg_right hCA hscale + nlinarith + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/LocalInversion.lean b/lean/OAI/Probability/Renewal/LocalInversion.lean new file mode 100644 index 0000000000000000000000000000000000000000..4aac704c2d31dbdc8a9619fd6ce1d474f096e5df --- /dev/null +++ b/lean/OAI/Probability/Renewal/LocalInversion.lean @@ -0,0 +1,197 @@ +import OAI.Probability.Renewal.Centered +import OAI.Probability.Renewal.GaussianCore + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +def localIntegrand (p : PMF ℕ) (k m : ℕ) (σ t : ℝ) : ℂ := + charFun (centeredMeasure p) (t / σ) ^ k * + Complex.exp (-(((m : ℝ) - k * natMean p) / σ * t : ℝ) * Complex.I) + +lemma localIntegrand_eq (p : PMF ℕ) (k m : ℕ) (σ t : ℝ) : + localIntegrand p k m σ t = latticeChar p (t / σ) ^ k * + Complex.exp (-((m : ℝ) * (t / σ) : ℝ) * Complex.I) := by + rw [localIntegrand, centered_char, mul_pow, ← Complex.exp_nat_mul] + have hid : ((k : ℂ) * (-((natMean p * (t / σ) : ℝ) : ℂ) * Complex.I)) + + (-(((m : ℝ) - k * natMean p) / σ * t : ℝ) * Complex.I) = + -((m : ℝ) * (t / σ) : ℝ) * Complex.I := by + push_cast + ring + rw [mul_comm (Complex.exp _), mul_assoc, ← Complex.exp_add, hid] + +lemma continuous_localIntegrand (p : PMF ℕ) (k m : ℕ) (σ : ℝ) : + Continuous (localIntegrand p k m σ) := by + unfold localIntegrand + fun_prop + +lemma norm_localIntegrand (p : PMF ℕ) (k m : ℕ) (σ t : ℝ) : + ‖localIntegrand p k m σ t‖ = ‖latticeChar p (t / σ)‖ ^ k := by + rw [localIntegrand_eq, norm_mul, norm_pow] + simp only [← Complex.ofReal_neg, Complex.norm_exp_ofReal_mul_I, mul_one] + +lemma scaled_inversion (p : PMF ℕ) (k m : ℕ) {σ : ℝ} (hσ : 0 < σ) : + (∫ t : ℝ in Icc (-Real.pi * σ) (Real.pi * σ), localIntegrand p k m σ t) = + (2 * Real.pi * σ : ℂ) * ((sumLaw p k m).toReal : ℂ) := by + rw [integral_Icc_eq_integral_Ioc, ← intervalIntegral.integral_of_le (by nlinarith [Real.pi_pos] : -Real.pi * σ ≤ Real.pi * σ)] + simp_rw [localIntegrand_eq] + rw [intervalIntegral.integral_comp_div (fun t => latticeChar p t ^ k * + Complex.exp (-((m : ℝ) * t : ℝ) * Complex.I)) hσ.ne'] + simp only [mul_div_cancel_right₀ _ hσ.ne', sumLaw_inversion, Complex.real_smul] + ring + +def gaussianIntegrand (b t : ℝ) : ℂ := + Complex.exp (-((t : ℂ) ^ 2 / 2)) * Complex.exp (-((b * t : ℝ) : ℂ) * Complex.I) + +lemma continuous_gaussianIntegrand (b : ℝ) : Continuous (gaussianIntegrand b) := by + unfold gaussianIntegrand + fun_prop + +lemma gaussianIntegrand_re (b t : ℝ) : + (gaussianIntegrand b t).re = Real.exp (-t ^ 2 / 2) * Real.cos (b * t) := by + have hid : -((t : ℂ) ^ 2 / 2) = ((-t ^ 2 / 2 : ℝ) : ℂ) := by push_cast; ring + rw [gaussianIntegrand, hid, ← Complex.ofReal_exp] + rw [Complex.mul_re] + simp only [Complex.ofReal_re, Complex.ofReal_im, zero_mul, sub_zero] + simp [Complex.exp_re, Real.cos_neg] + +lemma gaussian_core_lower {ω b : ℝ} (hω : 1 ≤ ω) (hb : |b| * ω ≤ 1) : + Real.exp (-1) ≤ (∫ t : ℝ in Icc (-ω) ω, gaussianIntegrand b t).re := by + have hω0 : 0 < ω := lt_of_lt_of_le zero_lt_one hω + have hcos {t : ℝ} (ht : t ∈ Icc (-ω) ω) : (1 : ℝ) / 2 ≤ Real.cos (b * t) := by + have habs : |b * t| ≤ 1 := by + rw [abs_mul] + exact (mul_le_mul_of_nonneg_left (abs_le.mpr ht) (abs_nonneg b)).trans hb + have hsq : (b * t) ^ 2 ≤ 1 := by nlinarith [sq_abs (b * t), abs_nonneg (b * t)] + nlinarith [Real.one_sub_sq_div_two_le_cos (x := b * t)] + have hcont : Continuous (fun t => (gaussianIntegrand b t).re) := Complex.continuous_re.comp (continuous_gaussianIntegrand b) + change Real.exp (-1) ≤ RCLike.re (∫ t : ℝ in Icc (-ω) ω, gaussianIntegrand b t) + rw [← integral_re (continuous_gaussianIntegrand b).integrableOn_Icc] + calc + Real.exp (-1) = ∫ _ : ℝ in Icc (-1) 1, Real.exp (-1) / 2 := by norm_num; ring + _ ≤ ∫ t : ℝ in Icc (-1) 1, (gaussianIntegrand b t).re := by + apply setIntegral_mono_on (integrable_const _) hcont.integrableOn_Icc measurableSet_Icc + intro t ht + have htω : t ∈ Icc (-ω) ω := ⟨by linarith [ht.1], ht.2.trans hω⟩ + rw [gaussianIntegrand_re] + have ht2 : t ^ 2 ≤ 1 := by nlinarith [ht.1, ht.2] + have hexp : Real.exp (-1) ≤ Real.exp (-t ^ 2 / 2) := Real.exp_le_exp.mpr (by linarith) + have hh := mul_le_mul hexp (hcos htω) (by norm_num : (0 : ℝ) ≤ 1 / 2) (Real.exp_pos _).le + nlinarith + _ ≤ ∫ t : ℝ in Icc (-ω) ω, (gaussianIntegrand b t).re := by + apply setIntegral_mono_set hcont.integrableOn_Icc + · filter_upwards [ae_restrict_mem measurableSet_Icc] with t ht + rw [gaussianIntegrand_re] + exact mul_nonneg (Real.exp_pos _).le (by linarith [hcos ht]) + · exact ae_of_all _ (fun t ht => ⟨by linarith [ht.1], ht.2.trans hω⟩) + +lemma local_core_error (p : PMF ℕ) + (h3 : Integrable (fun j : ℕ => (j : ℝ) ^ 3) p.toMeasure) + {k : ℕ} (hk : 0 < k) (m : ℕ) {σ ω : ℝ} (hσ : 0 < σ) (hω : 0 ≤ ω) + (hvar : σ ^ 2 = k * natVariance p) (hsmall : ω ^ 2 ≤ 2 * k) : + ‖(∫ t : ℝ in Icc (-ω) ω, localIntegrand p k m σ t) - + (∫ t : ℝ in Icc (-ω) ω, gaussianIntegrand (((m : ℝ) - k * natMean p) / σ) t)‖ ≤ + 2 * ω * ((k * natThird p / σ ^ 3) * ω ^ 3 / 2 + ω ^ 4 / (4 * k)) := by + have h1 : Integrable (fun j : ℕ => (j : ℝ)) p.toMeasure := by + have hh := (nat_memLp p (by norm_num : (3 : ℕ) ≠ 0) h3).mono_exponent (by norm_num : (1 : ENNReal) ≤ 3) + simpa using hh.integrable + rw [← integral_sub (continuous_localIntegrand p k m σ).integrableOn_Icc + (continuous_gaussianIntegrand _).integrableOn_Icc] + have hh := norm_setIntegral_le_of_norm_le_const (μ := volume) (s := Icc (-ω) ω) + (f := fun t => localIntegrand p k m σ t - gaussianIntegrand (((m : ℝ) - k * natMean p) / σ) t) + (C := (k * natThird p / σ ^ 3) * ω ^ 3 / 2 + ω ^ 4 / (4 * k)) (by simp) (fun t ht => ?_) + · rw [Real.volume_real_Icc] at hh + simp only [sub_neg_eq_add, max_eq_left (by linarith : 0 ≤ ω + ω)] at hh + exact hh.trans_eq (by ring) + · have ht2 : t ^ 2 ≤ ω ^ 2 := by + nlinarith [mul_nonneg (sub_nonneg.mpr ht.2) (by linarith [ht.1] : 0 ≤ ω + t)] + have h := normalized_gaussian_power_error (centered_memLp p (by norm_num) h3) + (centered_mean p h1) hk hσ (by simpa only [centered_variance] using hvar) t (ht2.trans hsmall) + rw [centered_third] at h + dsimp only [localIntegrand, gaussianIntegrand] + rw [← sub_mul, norm_mul, ← Complex.ofReal_neg, Complex.norm_exp_ofReal_mul_I, mul_one] + refine h.trans ?_ + apply add_le_add + · apply div_le_div_of_nonneg_right _ (by norm_num) + exact mul_le_mul_of_nonneg_left (pow_le_pow_left₀ (abs_nonneg t) (abs_le.mpr ht) 3) + (by positivity [natThird_nonneg p]) + · apply div_le_div_of_nonneg_right _ (by positivity) + nlinarith [mul_nonneg (sub_nonneg.mpr ht2) (by positivity : 0 ≤ ω ^ 2 + t ^ 2)] + +lemma fourier_tail_bound {f : ℝ → ℂ} (hf : Continuous f) {g : ℝ → ℝ} + (hg : Integrable g) (hg0 : ∀ t, 0 ≤ g t) {R ω η : ℝ} (hR : 0 ≤ R) (hη : 0 ≤ η) + (hbound : ∀ t ∈ Icc (-R) R, ‖f t‖ ≤ g t + η) : + ‖∫ t : ℝ in Icc (-R) R \ Icc (-ω) ω, f t‖ ≤ + (∫ t : ℝ in (Icc (-ω) ω)ᶜ, g t) + 2 * R * η := by + let s := Icc (-R) R \ Icc (-ω) ω + have hfi : IntegrableOn f s := hf.integrableOn_Icc.mono_set sdiff_subset + have hci : IntegrableOn (fun _ : ℝ => η) s := + (integrableOn_const (C := η) (s := Icc (-R) R) (by simp)).mono_set sdiff_subset + calc + ‖∫ t in s, f t‖ ≤ ∫ t in s, ‖f t‖ := norm_integral_le_integral_norm _ + _ ≤ ∫ t in s, g t + η := by + apply setIntegral_mono_on hfi.norm (hg.integrableOn.add hci) (measurableSet_Icc.diff measurableSet_Icc) + exact fun t ht => hbound t ht.1 + _ = (∫ t in s, g t) + ∫ _ in s, η := integral_add hg.integrableOn hci + _ ≤ (∫ t in (Icc (-ω) ω)ᶜ, g t) + ∫ _ : ℝ in Icc (-R) R, η := by + apply add_le_add + · apply setIntegral_mono_set hg.integrableOn (ae_of_all _ hg0) + exact ae_of_all _ (fun _ ht => ht.2) + · apply setIntegral_mono_set (integrable_const _) (ae_of_all _ (fun _ => hη)) + exact ae_of_all _ (fun _ ht => ht.1) + _ = _ := by + simp only [integral_const, smul_eq_mul, measureReal_restrict_apply_univ, Real.volume_real_Icc] + rw [max_eq_left (by linarith : 0 ≤ R - -R)] + ring + +lemma local_lower_of_envelope (p : PMF ℕ) + (h3 : Integrable (fun j : ℕ => (j : ℝ) ^ 3) p.toMeasure) + {k : ℕ} (hk : 0 < k) (m : ℕ) {σ ω η : ℝ} (hσ : 0 < σ) (hω : 1 ≤ ω) + (hvar : σ ^ 2 = k * natVariance p) (hsmall : ω ^ 2 ≤ 2 * k) + (hwidth : ω ≤ Real.pi * σ) + (hcenter : |((m : ℝ) - k * natMean p) / σ| * ω ≤ 1) + {g : ℝ → ℝ} (hg : Integrable g) (hg0 : ∀ t, 0 ≤ g t) (hη : 0 ≤ η) + (hbound : ∀ t ∈ Icc (-Real.pi * σ) (Real.pi * σ), + ‖latticeChar p (t / σ)‖ ^ k ≤ g t + η) + (htail : (∫ t : ℝ in (Icc (-ω) ω)ᶜ, g t) ≤ Real.exp (-1) / 4) + (hhigh : 2 * (Real.pi * σ) * η ≤ Real.exp (-1) / 4) + (herror : 2 * ω * ((k * natThird p / σ ^ 3) * ω ^ 3 / 2 + ω ^ 4 / (4 * k)) ≤ + Real.exp (-1) / 4) : + Real.exp (-1) / (8 * Real.pi * σ) ≤ (sumLaw p k m).toReal := by + have hω0 : 0 ≤ ω := zero_le_one.trans hω + have hR : 0 ≤ Real.pi * σ := by positivity + have hsub : Icc (-ω) ω ⊆ Icc (-Real.pi * σ) (Real.pi * σ) := + fun _ ht => ⟨by linarith [ht.1], ht.2.trans hwidth⟩ + have he := (local_core_error p h3 hk m hσ hω0 hvar hsmall).trans herror + have hc := gaussian_core_lower hω hcenter + have ht := fourier_tail_bound (ω := ω) (continuous_localIntegrand p k m σ) hg hg0 hR hη (by + intro t ht + rw [norm_localIntegrand] + exact hbound t (by simpa [neg_mul] using ht)) + have htail' : ‖∫ t : ℝ in Icc (-Real.pi * σ) (Real.pi * σ) \ Icc (-ω) ω, + localIntegrand p k m σ t‖ ≤ Real.exp (-1) / 2 := by + have hh := ht.trans (add_le_add htail hhigh) + simp only [← neg_mul] at hh + linarith + have hdiff := Complex.re_le_norm ((∫ t : ℝ in Icc (-ω) ω, gaussianIntegrand + (((m : ℝ) - k * natMean p) / σ) t) - ∫ t : ℝ in Icc (-ω) ω, localIntegrand p k m σ t) + rw [norm_sub_rev, Complex.sub_re] at hdiff + have hl := (abs_le.mp (Complex.abs_re_le_norm (∫ t : ℝ in Icc (-Real.pi * σ) (Real.pi * σ) \ Icc (-ω) ω, + localIntegrand p k m σ t))).1 + have hlower : -Real.exp (-1) / 2 ≤ + (∫ t : ℝ in Icc (-Real.pi * σ) (Real.pi * σ) \ Icc (-ω) ω, + localIntegrand p k m σ t).re := by linarith + rw [setIntegral_sdiff measurableSet_Icc (continuous_localIntegrand p k m σ).integrableOn_Icc hsub, + Complex.sub_re, scaled_inversion p k m hσ] at hlower + norm_num [Complex.mul_re] at hlower + apply (div_le_iff₀ (by positivity : 0 < 8 * Real.pi * σ)).mpr + nlinarith + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/LocalRenewal.lean b/lean/OAI/Probability/Renewal/LocalRenewal.lean new file mode 100644 index 0000000000000000000000000000000000000000..df00fcf4a3068bf3b5cee5ab00d33d6230ce01f1 --- /dev/null +++ b/lean/OAI/Probability/Renewal/LocalRenewal.lean @@ -0,0 +1,117 @@ +import OAI.Probability.Renewal.ScaledWindow +import OAI.Probability.Renewal.Untilt + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +theorem local_renewal_mass (p : PMF ℕ) (_hp : p 0 = 0) (hspan : SpanOne p) + {a : ℝ} (ha : 0 < a ∧ a < 1) (hpower : BoundedPowerInput p a) : + ∃ c > 0, ∀ᶠ m : ℕ in atTop, + ENNReal.ofReal (c * (m : ℝ) ^ (a - 1)) ≤ renewalMass p m := by + obtain ⟨ω, hω, L, hL, εloc, hεloc, N, hlocal⟩ := uniform_tilted_local p hspan ha hpower + obtain ⟨M⟩ := momentData_exists p ha hpower + obtain ⟨εZ, hεZ, hZ⟩ := laplace_small p ha.1 hpower + obtain ⟨c, hc, C, hC, x₀, hx₀, htail, hdef⟩ := hpower + let A := M.muUpper * (L + 1) + have hA : 0 < A := mul_pos M.muUpper_pos (by linarith) + have hAL : L ≤ A / M.muUpper := by + dsimp [A] + rw [mul_div_cancel_left₀ _ M.muUpper_pos.ne'] + linarith + let b := Real.sqrt (M.varLower / (M.muUpper * A)) + let B := Real.sqrt (2 * M.varUpper / (M.muLower * A)) + have hb : 0 < b := Real.sqrt_pos.mpr (by positivity [M.varLower_pos, M.muUpper_pos]) + have hB : 0 < B := Real.sqrt_pos.mpr (by positivity [M.varUpper_pos, M.muLower_pos]) + have hω0 : 0 < ω := zero_lt_one.trans_le hω + let r := min 1 (b / (2 * ω)) + have hr : 0 < r := lt_min zero_lt_one (by positivity) + have hr1 : r ≤ 1 := min_le_left _ _ + have hrω : r * ω ≤ b := by + have hh := (le_div_iff₀ (by positivity : 0 < 2 * ω)).mp (min_le_right (1 : ℝ) (b / (2 * ω))) + dsimp [r] + nlinarith [mul_pos hr hω0] + let cx := A ^ (1 - a) / M.muUpper + have hcx : 0 < cx := div_pos (Real.rpow_pos_of_pos hA _) M.muUpper_pos + let K := 2 * A / M.muLower + let e := Real.exp (-2 * C * K) * Real.exp (-1) / (8 * Real.pi * B) + have he : 0 < e := by dsimp [e]; positivity + let ε := min M.epsilon (min εloc (min εZ x₀⁻¹)) + have hε : 0 < ε := lt_min M.epsilon_pos (lt_min hεloc (lt_min hεZ (inv_pos.mpr hx₀))) + have hu_lim : Tendsto (fun m : ℕ => A / (m : ℝ)) atTop (𝓝 0) := tendsto_const_div_atTop_nhds_zero_nat A + have hx_lim : Tendsto (fun m : ℕ => cx * (m : ℝ) ^ a) atTop atTop := + Tendsto.const_mul_atTop hcx ((tendsto_rpow_atTop ha.1).comp tendsto_natCast_atTop_atTop) + refine ⟨e * r * cx / 2, by positivity, ?_⟩ + filter_upwards [eventually_ge_atTop (1 : ℕ), hu_lim.eventually (Iio_mem_nhds hε), + hx_lim.eventually_ge_atTop (N : ℝ), hx_lim.eventually_ge_atTop (2 / r)] with m hm hue hNx hrx + have hmpos : 0 < m := lt_of_lt_of_le Nat.zero_lt_one hm + have hm' : (0 : ℝ) < m := by exact_mod_cast hmpos + let u := A / (m : ℝ) + have hu : 0 < u := div_pos hA hm' + have hdeps : u ≤ M.epsilon ∧ u ≤ εloc ∧ u ≤ εZ ∧ u ≤ x₀⁻¹ := by + simpa only [ε, le_min_iff] using hue.le + let q := tilt p u hu.le + let μ := natMean q + let x := (m : ℝ) / μ + obtain ⟨hx, hxlo, hxuLo, hxuHi⟩ := M.center_bounds hA hm' hdeps.1 + change 0 < x at hx + change cx * (m : ℝ) ^ a ≤ x at hxlo + change A / M.muUpper ≤ x * u ^ a at hxuLo + change x * u ^ a ≤ A / M.muLower at hxuHi + have hNreal : (N : ℝ) ≤ x := hNx.trans hxlo + have hrx' : 2 ≤ r * x := by + have hh := hrx.trans hxlo + exact (div_le_iff₀ hr).mp hh |>.trans_eq (mul_comm _ _) + have hcard : r * x / 2 ≤ ((indexWindow x r).card : ℝ) := card_indexWindow hx.le hr.le hrx' + have hper : ∀ k ∈ indexWindow x r, e / (m : ℝ) ≤ (sumLaw p k m).toReal := by + intro k hk + obtain ⟨hklo, hkhi⟩ := mem_indexWindow hx.le hr.le hk + have hkN : N ≤ k := by exact_mod_cast hNreal.trans hklo + have hku : L ≤ (k : ℝ) * u ^ a := + (hAL.trans hxuLo).trans (mul_le_mul_of_nonneg_right hklo (Real.rpow_pos_of_pos hu a).le) + have hkuHi : (k : ℝ) * u ^ a ≤ K := by + have hk2 : (k : ℝ) ≤ 2 * x := hkhi.trans (by nlinarith) + have hh := mul_le_mul_of_nonneg_right hk2 (Real.rpow_pos_of_pos hu a).le + calc + _ ≤ 2 * (x * u ^ a) := by nlinarith [hh] + _ ≤ 2 * (A / M.muLower) := mul_le_mul_of_nonneg_left hxuHi (by norm_num) + _ = K := by dsimp [K]; ring + let σ := Real.sqrt ((k : ℝ) * natVariance q) + have hsig := M.sigma_window_bounds hA hm' hdeps.1 hr.le hr1 hk + change b * (m : ℝ) ≤ σ ∧ σ ≤ B * (m : ℝ) at hsig + have hσ : 0 < σ := (mul_pos hb hm').trans_le hsig.1 + have hcenter : |((m : ℝ) - k * μ) / σ| * ω ≤ 1 := + M.centered_window hA hm' hdeps.1 hr.le hr1 hω0.le hrω hk + have hpr := hlocal u hu hdeps.2.1 k hkN hku m hcenter + change Real.exp (-1) / (8 * Real.pi * σ) ≤ (sumLaw q k m).toReal at hpr + have hden : Real.exp (-1) / (8 * Real.pi * (B * (m : ℝ))) ≤ + Real.exp (-1) / (8 * Real.pi * σ) := by + apply div_le_div_of_nonneg_left (Real.exp_pos _).le (by positivity) + exact mul_le_mul_of_nonneg_left hsig.2 (by positivity) + have hupr := untilt_lower (m := m) p hu.le (hZ u hu hdeps.2.2.1) hC.le (hdef u hu hdeps.2.2.2).2 hkuHi + have htot := (mul_le_mul_of_nonneg_left (hden.trans hpr) (Real.exp_pos (-2 * C * K)).le).trans hupr + calc + e / (m : ℝ) = Real.exp (-2 * C * K) * (Real.exp (-1) / (8 * Real.pi * (B * (m : ℝ)))) := by + dsimp [e] + ring + _ ≤ _ := htot + have hfin := renewal_lower_finset p hmpos (indexWindow x r) hper + apply le_trans (ENNReal.ofReal_le_ofReal ?_) hfin + have hcard' : r * cx * (m : ℝ) ^ a / 2 ≤ ((indexWindow x r).card : ℝ) := by + have hh := mul_le_mul_of_nonneg_left hxlo hr.le + nlinarith + have hh := mul_le_mul_of_nonneg_left hcard' (div_pos he hm').le + calc + _ = (e / (m : ℝ)) * (r * cx * (m : ℝ) ^ a / 2) := by + rw [Real.rpow_sub hm', Real.rpow_one] + ring + _ ≤ _ := hh + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Main.lean b/lean/OAI/Probability/Renewal/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..a01c2bec49c42520287e40e8a6d60946b27a8497 --- /dev/null +++ b/lean/OAI/Probability/Renewal/Main.lean @@ -0,0 +1,21 @@ +import OAI.Probability.Renewal.Laplace +import OAI.Probability.Renewal.Fourier +import OAI.Probability.Renewal.GaussianCore + +import OAI.Probability.Renewal.SumLaw +import OAI.Probability.Renewal.Tilt +import OAI.Probability.Renewal.Moments +import OAI.Probability.Renewal.Annuli +import OAI.Probability.Renewal.Decay +import OAI.Probability.Renewal.Centered + +import OAI.Probability.Renewal.TiltMoments +import OAI.Probability.Renewal.LocalInversion +import OAI.Probability.Renewal.Envelope +import OAI.Probability.Renewal.UniformLocal +import OAI.Probability.Renewal.Untilt +import OAI.Probability.Renewal.Counting +import OAI.Probability.Renewal.ScaledWindow + +import OAI.Probability.Renewal.LocalRenewal +import OAI.Probability.Renewal.Concentration diff --git a/lean/OAI/Probability/Renewal/Moments.lean b/lean/OAI/Probability/Renewal/Moments.lean new file mode 100644 index 0000000000000000000000000000000000000000..4a042d412306b483e783be63602ed85ddc87347b --- /dev/null +++ b/lean/OAI/Probability/Renewal/Moments.lean @@ -0,0 +1,121 @@ +import OAI.Probability.Renewal.Tilt +import OAI.Probability.Renewal.GaussianCore + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +lemma polynomial_exp_deficit {s : ℝ} (hs : 0 ≤ s) (n : ℕ) : + s ^ (n + 1) * Real.exp (-s) ≤ + (2 : ℝ) ^ (n + 1) * n.factorial * (1 - Real.exp (-s / 2)) := by + have hf : (0 : ℝ) < n.factorial := by exact_mod_cast Nat.factorial_pos n + have hp := (div_le_iff₀ hf).mp (Real.pow_div_factorial_le_exp (s / 2) (by linarith : 0 ≤ s / 2) n) + have hmul := mul_le_mul_of_nonneg_right hp (by positivity : 0 ≤ (2 : ℝ) ^ n * s * Real.exp (-s)) + have hsum : s / 2 + -s = -s / 2 := by ring + have hid : (s / 2) ^ n * (2 ^ n * s * Real.exp (-s)) = s ^ (n + 1) * Real.exp (-s) := by + rw [div_pow, pow_succ]; field_simp + rw [hid] at hmul + have hid' : Real.exp (s / 2) * (n.factorial : ℝ) * (2 ^ n * s * Real.exp (-s)) = + 2 ^ n * n.factorial * (s * Real.exp (-s / 2)) := by + rw [← hsum, Real.exp_add]; ring + rw [hid'] at hmul + have hc := mul_le_mul_of_nonneg_right (Real.add_one_le_exp (s / 2)) (Real.exp_pos (-s / 2)).le + have he : Real.exp (s / 2) * Real.exp (-s / 2) = 1 := by rw [← Real.exp_add]; ring_nf; simp + rw [he] at hc + have hlin : s * Real.exp (-s / 2) ≤ 2 * (1 - Real.exp (-s / 2)) := by nlinarith + calc + _ ≤ 2 ^ n * n.factorial * (s * Real.exp (-s / 2)) := hmul + _ ≤ 2 ^ n * n.factorial * (2 * (1 - Real.exp (-s / 2))) := by gcongr + _ = _ := by rw [pow_succ]; ring + +lemma weighted_power_bound {u : ℝ} (hu : 0 < u) (j n : ℕ) : + Real.exp (-u * (j : ℝ)) * (j : ℝ) ^ (n + 1) ≤ + ((2 : ℝ) ^ (n + 1) * n.factorial / u ^ (n + 1)) * + (1 - Real.exp (-(u / 2) * (j : ℝ))) := by + have h := polynomial_exp_deficit (mul_nonneg hu.le (Nat.cast_nonneg j)) n + rw [div_mul_eq_mul_div] + apply (le_div_iff₀ (pow_pos hu (n + 1))).mpr + calc + (Real.exp (-u * (j : ℝ)) * (j : ℝ) ^ (n + 1)) * u ^ (n + 1) = + (u * (j : ℝ)) ^ (n + 1) * Real.exp (-(u * (j : ℝ))) := by + rw [mul_pow, neg_mul] + ring + _ ≤ (2 : ℝ) ^ (n + 1) * n.factorial * (1 - Real.exp (-(u * (j : ℝ)) / 2)) := h + _ = _ := by rw [show -(u * (j : ℝ)) / 2 = -(u / 2) * (j : ℝ) by ring] + +lemma integrable_weighted_power (p : PMF ℕ) {u : ℝ} (hu : 0 < u) (n : ℕ) : + Integrable (fun j : ℕ => Real.exp (-u * (j : ℝ)) * (j : ℝ) ^ (n + 1)) p.toMeasure := by + refine Integrable.of_bound Measurable.of_discrete.aestronglyMeasurable + ((2 : ℝ) ^ (n + 1) * n.factorial / u ^ (n + 1)) ?_ + filter_upwards [] with j + rw [Real.norm_eq_abs, abs_of_nonneg (by positivity)] + exact (weighted_power_bound hu j n).trans (mul_le_of_le_one_right (by positivity) (by linarith [Real.exp_pos (-(u / 2) * (j : ℝ))])) + +lemma weighted_moment_bound (p : PMF ℕ) {u : ℝ} (hu : 0 < u) (n : ℕ) : + (∫ j : ℕ, Real.exp (-u * (j : ℝ)) * (j : ℝ) ^ (n + 1) ∂p.toMeasure) ≤ + ((2 : ℝ) ^ (n + 1) * n.factorial / u ^ (n + 1)) * (1 - laplace p (u / 2)) := by + have hi := integral_mono (integrable_weighted_power p hu n) + ((integrable_deficit p (by positivity : 0 ≤ u / 2)).const_mul + ((2 : ℝ) ^ (n + 1) * n.factorial / u ^ (n + 1))) (fun j => weighted_power_bound hu j n) + rw [integral_const_mul, deficit_integral p (by positivity)] at hi + exact hi + +lemma tilt_moment_integrable (p : PMF ℕ) {u : ℝ} (hu : 0 < u) (n : ℕ) : + Integrable (fun j : ℕ => (j : ℝ) ^ n) (tilt p u hu.le).toMeasure := by + cases n with + | zero => simp + | succ n => + rw [integrable_tilt_iff] + exact integrable_weighted_power p hu n + +lemma laplace_small (p : PMF ℕ) {a : ℝ} (ha : 0 < a) (hpow : BoundedPowerInput p a) : + ∃ ε > (0 : ℝ), ∀ u, 0 < u → u ≤ ε → (1 / 2 : ℝ) ≤ laplace p u := by + rcases hpow with ⟨c, hc, C, hC, x₀, hx₀, _, hL⟩ + have hlim : Tendsto (fun u : ℝ => C * u ^ a) (𝓝[>] 0) (𝓝 0) := by + have h := ((Real.continuous_rpow_const ha.le).tendsto 0).const_mul C + simpa [Real.zero_rpow ha.ne'] using h.mono_left nhdsWithin_le_nhds + have hev : ∀ᶠ u : ℝ in 𝓝[>] 0, C * u ^ a < 1 / 2 := hlim.eventually (Iio_mem_nhds (by norm_num)) + obtain ⟨ε, hε, he⟩ := mem_nhdsGT_iff_exists_Ioc_subset.mp hev + refine ⟨min ε x₀⁻¹, lt_min hε (inv_pos.mpr hx₀), ?_⟩ + intro u hu hue + have hh := he ⟨hu, hue.trans (min_le_left _ _)⟩ + change C * u ^ a < 1 / 2 at hh + have hh' := (hL u hu (hue.trans (min_le_right _ _))).2 + linarith + +lemma tilt_moments_upper (p : PMF ℕ) {a : ℝ} (ha : 0 < a) (hpow : BoundedPowerInput p a) + (n : ℕ) : ∃ K > (0 : ℝ), ∃ ε > (0 : ℝ), ∀ u (hu : 0 < u), u ≤ ε → + (∫ j : ℕ, (j : ℝ) ^ (n + 1) ∂(tilt p u hu.le).toMeasure) ≤ K * u ^ (a - (n + 1)) := by + obtain ⟨ε, hε, he⟩ := laplace_small p ha hpow + rcases hpow with ⟨c, hc, C, hC, x₀, hx₀, _, hL⟩ + refine ⟨2 * ((2 : ℝ) ^ (n + 1) * n.factorial) * C, by positivity, + min ε x₀⁻¹, lt_min hε (inv_pos.mpr hx₀), ?_⟩ + intro u hu hue + have hz : (1 / 2 : ℝ) ≤ laplace p u := he u hu (hue.trans (min_le_left _ _)) + have hhalf : u / 2 ≤ x₀⁻¹ := by linarith [hue.trans (min_le_right ε x₀⁻¹)] + have hmean := weighted_moment_bound p hu n + have hdef := (hL (u / 2) (by positivity) hhalf).2 + have hpowle : (u / 2) ^ a ≤ u ^ a := Real.rpow_le_rpow (by positivity) (by linarith) ha.le + have hK : 0 ≤ (2 : ℝ) ^ (n + 1) * n.factorial / u ^ (n + 1) := by positivity + have hnum := hmean.trans (mul_le_mul_of_nonneg_left + (hdef.trans (mul_le_mul_of_nonneg_left hpowle hC.le)) hK) + rw [integral_tilt, smul_eq_mul] + simp_rw [smul_eq_mul] + have hinv : (laplace p u)⁻¹ ≤ 2 := by + apply (inv_le_comm₀ (laplace_pos p hu.le) (by norm_num : (0 : ℝ) < 2)).mpr + norm_num + exact hz + calc + (laplace p u)⁻¹ * (∫ j : ℕ, Real.exp (-u * (j : ℝ)) * (j : ℝ) ^ (n + 1) ∂p.toMeasure) ≤ + 2 * (((2 : ℝ) ^ (n + 1) * n.factorial / u ^ (n + 1)) * (C * u ^ a)) := + mul_le_mul hinv hnum (integral_nonneg (fun _ => by positivity)) (by norm_num) + _ = _ := by rw [Real.rpow_sub hu, ← Nat.cast_add_one n, Real.rpow_natCast]; field_simp + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/ScaledWindow.lean b/lean/OAI/Probability/Renewal/ScaledWindow.lean new file mode 100644 index 0000000000000000000000000000000000000000..e3b78c4cf3cdac821e0e9638fd99a7256aacc565 --- /dev/null +++ b/lean/OAI/Probability/Renewal/ScaledWindow.lean @@ -0,0 +1,144 @@ +import OAI.Probability.Renewal.UniformLocal +import OAI.Probability.Renewal.Counting + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +lemma power_moment_ratio {u : ℝ} (hu : 0 < u) (a c d : ℝ) : + (c * u ^ (a - 2)) / (d * u ^ (a - 1)) = c / (d * u) := by + calc + _ = (c / d) * (u ^ (a - 2) / u ^ (a - 1)) := by ring + _ = (c / d) * u ^ ((a - 2) - (a - 1)) := by rw [Real.rpow_sub hu (a - 2) (a - 1)] + _ = _ := by rw [show (a - 2) - (a - 1) = (-1 : ℝ) by ring, Real.rpow_neg_one]; ring + +namespace MomentData +variable {p : PMF ℕ} {a : ℝ} (M : MomentData p a) + +lemma mean_pos {u : ℝ} (hu : 0 < u) (hue : u ≤ M.epsilon) : + 0 < natMean (tilt p u hu.le) := + (mul_pos M.muLower_pos (Real.rpow_pos_of_pos hu _)).trans_le (M.mean_lower u hu hue) + +lemma ratio_bounds {u : ℝ} (hu : 0 < u) (hue : u ≤ M.epsilon) : + M.varLower / (M.muUpper * u) ≤ natVariance (tilt p u hu.le) / natMean (tilt p u hu.le) ∧ + natVariance (tilt p u hu.le) / natMean (tilt p u hu.le) ≤ M.varUpper / (M.muLower * u) := by + have hμ := M.mean_pos hu hue + have hv := M.var_lower u hu hue + have hv0 : 0 ≤ natVariance (tilt p u hu.le) := natVariance_nonneg _ + constructor + · rw [← power_moment_ratio hu a M.varLower M.muUpper] + exact div_le_div₀ (by positivity [M.varLower_pos]) hv hμ (M.mean_upper u hu hue) + · rw [← power_moment_ratio hu a M.varUpper M.muLower] + exact div_le_div₀ (by positivity [M.varUpper_pos]) (M.var_upper u hu hue) (by positivity [M.muLower_pos]) (M.mean_lower u hu hue) + +lemma center_bounds {A m : ℝ} (hA : 0 < A) (hm : 0 < m) + (hue : A / m ≤ M.epsilon) : + let u := A / m + let μ := natMean (tilt p u (div_pos hA hm).le) + let x := m / μ + 0 < x ∧ (A ^ (1 - a) / M.muUpper) * m ^ a ≤ x ∧ + A / M.muUpper ≤ x * u ^ a ∧ x * u ^ a ≤ A / M.muLower := by + intro u μ x + have hu : 0 < u := div_pos hA hm + have hμ : 0 < μ := M.mean_pos hu hue + have hl := M.mean_lower u hu hue + have hh := M.mean_upper u hu hue + have hLo : m / (M.muUpper * u ^ (a - 1)) ≤ x := + div_le_div_of_nonneg_left hm.le hμ hh + have hHi : x ≤ m / (M.muLower * u ^ (a - 1)) := + div_le_div_of_nonneg_left hm.le (by positivity [M.muLower_pos]) hl + have hid (c : ℝ) : m / (c * u ^ (a - 1)) * u ^ a = A / c := by + have hpow : u ^ a = u ^ (a - 1) * u := by simpa using Real.rpow_add_one hu.ne' (a - 1) + rw [hpow] + dsimp [u] + field_simp + refine ⟨div_pos hm hμ, ?_, ?_, ?_⟩ + · have hid' : m / (M.muUpper * u ^ (a - 1)) = (A ^ (1 - a) / M.muUpper) * m ^ a := by + calc + _ = (m / (A / m) ^ (a - 1)) / M.muUpper := by dsimp [u]; ring + _ = _ := by rw [inverse_tilt_scale hA hm]; ring + rwa [hid'] at hLo + · have ht := mul_le_mul_of_nonneg_right hLo (Real.rpow_pos_of_pos hu a).le + rwa [hid] at ht + · have ht := mul_le_mul_of_nonneg_right hHi (Real.rpow_pos_of_pos hu a).le + rwa [hid] at ht + +lemma sigma_window_bounds {A m r : ℝ} (hA : 0 < A) (hm : 0 < m) + (hue : A / m ≤ M.epsilon) (hr : 0 ≤ r) (hr1 : r ≤ 1) + {k : ℕ} (hk : k ∈ indexWindow (m / natMean (tilt p (A / m) (div_pos hA hm).le)) r) : + let σ := Real.sqrt ((k : ℝ) * natVariance (tilt p (A / m) (div_pos hA hm).le)) + Real.sqrt (M.varLower / (M.muUpper * A)) * m ≤ σ ∧ + σ ≤ Real.sqrt (2 * M.varUpper / (M.muLower * A)) * m := by + intro σ + let u := A / m + let μ := natMean (tilt p u (div_pos hA hm).le) + let v := natVariance (tilt p u (div_pos hA hm).le) + let x := m / μ + have hu : 0 < u := div_pos hA hm + have hμ : 0 < μ := M.mean_pos hu hue + have hx : 0 < x := div_pos hm hμ + obtain ⟨hklo, hkhi⟩ := mem_indexWindow hx.le hr hk + have hk2 : (k : ℝ) ≤ 2 * x := hkhi.trans (by nlinarith) + have hv : 0 ≤ v := natVariance_nonneg _ + have hkv : 0 ≤ (k : ℝ) * v := mul_nonneg (Nat.cast_nonneg _) hv + have hσ0 : 0 ≤ σ := Real.sqrt_nonneg _ + have hσ2 : σ ^ 2 = (k : ℝ) * v := Real.sq_sqrt hkv + obtain ⟨hrlo, hrhi⟩ := M.ratio_bounds hu hue + have hlo : M.varLower / (M.muUpper * A) * m ^ 2 ≤ σ ^ 2 := by + calc + _ = m * (M.varLower / (M.muUpper * u)) := by dsimp [u]; field_simp + _ ≤ m * (v / μ) := mul_le_mul_of_nonneg_left hrlo hm.le + _ = x * v := by dsimp [x]; ring + _ ≤ (k : ℝ) * v := mul_le_mul_of_nonneg_right hklo hv + _ = σ ^ 2 := hσ2.symm + have hhi : σ ^ 2 ≤ (2 * M.varUpper / (M.muLower * A)) * m ^ 2 := by + calc + _ = (k : ℝ) * v := hσ2 + _ ≤ 2 * x * v := mul_le_mul_of_nonneg_right hk2 hv + _ = 2 * m * (v / μ) := by dsimp [x]; ring + _ ≤ 2 * m * (M.varUpper / (M.muLower * u)) := mul_le_mul_of_nonneg_left hrhi (by positivity) + _ = _ := by dsimp [u]; field_simp + have hblo : 0 ≤ M.varLower / (M.muUpper * A) := by positivity [M.varLower_pos, M.muUpper_pos] + have hbhi : 0 ≤ 2 * M.varUpper / (M.muLower * A) := by positivity [M.varUpper_pos, M.muLower_pos] + have hsql := Real.sq_sqrt hblo + have hsqh := Real.sq_sqrt hbhi + constructor + · nlinarith [Real.sqrt_nonneg (M.varLower / (M.muUpper * A)), sq_nonneg σ] + · nlinarith [Real.sqrt_nonneg (2 * M.varUpper / (M.muLower * A)), + mul_nonneg (Real.sqrt_nonneg (2 * M.varUpper / (M.muLower * A))) hm.le] + +lemma centered_window {A m r ω : ℝ} (hA : 0 < A) (hm : 0 < m) + (hue : A / m ≤ M.epsilon) (hr : 0 ≤ r) (hr1 : r ≤ 1) (hω : 0 ≤ ω) + (hrω : r * ω ≤ Real.sqrt (M.varLower / (M.muUpper * A))) + {k : ℕ} (hk : k ∈ indexWindow (m / natMean (tilt p (A / m) (div_pos hA hm).le)) r) : + let μ := natMean (tilt p (A / m) (div_pos hA hm).le) + let σ := Real.sqrt ((k : ℝ) * natVariance (tilt p (A / m) (div_pos hA hm).le)) + |(m - k * μ) / σ| * ω ≤ 1 := by + intro μ σ + have hμ : 0 < μ := M.mean_pos (div_pos hA hm) hue + have hx : 0 < m / μ := div_pos hm hμ + obtain ⟨hklo, hkhi⟩ := mem_indexWindow hx.le hr hk + have hlo := (M.sigma_window_bounds hA hm hue hr hr1 hk).1 + have hσ : 0 < σ := (mul_pos (Real.sqrt_pos.mpr (by positivity [M.varLower_pos, M.muUpper_pos])) hm).trans_le hlo + have hkm : m ≤ (k : ℝ) * μ := (div_le_iff₀ hμ).mp hklo + have hkmax : (k : ℝ) * μ ≤ (1 + r) * m := by + have hh := mul_le_mul_of_nonneg_right hkhi hμ.le + field_simp at hh + exact hh + rw [abs_div, abs_of_pos hσ, abs_of_nonpos (by linarith : m - (k : ℝ) * μ ≤ 0)] + have hmul := mul_le_mul_of_nonneg_right (show (k : ℝ) * μ - m ≤ r * m by linarith) hω + have hmul2 := mul_le_mul_of_nonneg_right hrω hm.le + have hb : (-(m - (k : ℝ) * μ)) * ω ≤ σ := by nlinarith + calc + _ = (-(m - (k : ℝ) * μ) * ω) / σ := by ring + _ ≤ 1 := (div_le_one hσ).mpr hb + +end MomentData +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/SumLaw.lean b/lean/OAI/Probability/Renewal/SumLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..6347a42c977fe4ceba352d48035fd4e4a3408c5a --- /dev/null +++ b/lean/OAI/Probability/Renewal/SumLaw.lean @@ -0,0 +1,164 @@ +import OAI.Probability.Renewal.Laplace +import OAI.Probability.Renewal.Fourier + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +def pairLaw (p q : PMF ℕ) : PMF (ℕ × ℕ) := + ⟨fun z => p z.1 * q z.2, ENNReal.summable.hasSum_iff.mpr (by + rw [ENNReal.tsum_prod'] + simp only [ENNReal.tsum_mul_left, q.tsum_coe, mul_one, p.tsum_coe])⟩ + +lemma pairLaw_apply (p q : PMF ℕ) (z : ℕ × ℕ) : pairLaw p q z = p z.1 * q z.2 := rfl + +lemma pairLaw_toMeasure (p q : PMF ℕ) : + (pairLaw p q).toMeasure = p.toMeasure.prod q.toMeasure := by + apply Measure.ext_of_singleton + rintro ⟨j, l⟩ + rw [PMF.toMeasure_apply_singleton _ _ (measurableSet_singleton _), pairLaw_apply] + have hs : ({(j, l)} : Set (ℕ × ℕ)) = {j} ×ˢ {l} := by ext z; simp + rw [hs, Measure.prod_prod, p.toMeasure_apply_singleton _ (measurableSet_singleton _), + q.toMeasure_apply_singleton _ (measurableSet_singleton _)] + +lemma sumLaw_succ_map (p : PMF ℕ) (k : ℕ) : + sumLaw p (k + 1) = (pairLaw p (sumLaw p k)).map (fun z => z.1 + z.2) := by + classical + ext m + simp only [sumLaw, PMF.bind_apply, PMF.map_apply, pairLaw_apply] + rw [ENNReal.tsum_prod'] + apply tsum_congr + intro j + rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro l + split_ifs <;> simp + +lemma sumLaw_transform {𝕂 : Type*} [RCLike 𝕂] (p : PMF ℕ) (k : ℕ) (F : ℕ → 𝕂) + (h0 : F 0 = 1) (hmul : ∀ j l, F (j + l) = F j * F l) : + (∫ j, F j ∂(sumLaw p k).toMeasure) = (∫ j, F j ∂p.toMeasure) ^ k := by + induction k with + | zero => simpa [sumLaw, PMF.toMeasure_pure] using h0 + | succ k hk => + rw [sumLaw_succ_map, ← PMF.toMeasure_map _ _ Measurable.of_discrete] + rw [integral_map Measurable.of_discrete.aemeasurable Measurable.of_discrete.aestronglyMeasurable, + pairLaw_toMeasure] + simp_rw [hmul] + rw [integral_prod_mul F F, hk, pow_succ, mul_comm] + +lemma latticeChar_sumLaw (p : PMF ℕ) (k : ℕ) (t : ℝ) : + latticeChar (sumLaw p k) t = latticeChar p t ^ k := by + apply sumLaw_transform + · simp + · intro j l + rw [← Complex.exp_add] + congr 1 + push_cast + ring + +lemma laplace_sumLaw (p : PMF ℕ) (k : ℕ) (u : ℝ) : + laplace (sumLaw p k) u = laplace p u ^ k := by + apply sumLaw_transform + · simp + · intro j l + rw [← Real.exp_add] + congr 1 + push_cast + ring + +lemma sumLaw_inversion (p : PMF ℕ) (k m : ℕ) : + (∫ t : ℝ in -Real.pi..Real.pi, + latticeChar p t ^ k * Complex.exp (-((m : ℝ) * t : ℝ) * Complex.I)) = + (2 * Real.pi : ℂ) * ((sumLaw p k m).toReal : ℂ) := by + simpa only [latticeChar_sumLaw] using lattice_inversion (sumLaw p k) m + +lemma tail_from_laplace (p : PMF ℕ) {t : ℝ} (ht : 0 < t) : + (1 - Real.exp (-1)) * p.toMeasure.real {j | t < (j : ℝ)} ≤ + 1 - laplace p t⁻¹ := by + let s : Set ℕ := {j | t < (j : ℝ)} + have hf := (integrable_const (1 - Real.exp (-1))).indicator + (μ := p.toMeasure) (s := s) MeasurableSet.of_discrete + have h := integral_mono hf (integrable_deficit p (inv_nonneg.mpr ht.le)) (fun j => ?_) + · rw [integral_indicator_const _ MeasurableSet.of_discrete, deficit_integral p (inv_nonneg.mpr ht.le)] at h + simpa only [smul_eq_mul, mul_comm] using h + · by_cases hj : j ∈ s + · rw [Set.indicator_of_mem hj] + apply sub_le_sub_left + apply Real.exp_le_exp.mpr + dsimp [s] at hj + have hr : 1 ≤ t⁻¹ * (j : ℝ) := by + rw [inv_mul_eq_div, le_div_iff₀ ht] + simpa using hj.le + nlinarith + · rw [Set.indicator_of_notMem hj] + have hexp : Real.exp (-t⁻¹ * (j : ℝ)) ≤ 1 := Real.exp_le_one_iff.mpr + (mul_nonpos_of_nonpos_of_nonneg (neg_nonpos.mpr (inv_nonneg.mpr ht.le)) (Nat.cast_nonneg _)) + linarith + +lemma one_sub_pow_le_nat_mul {z : ℝ} (hz : 0 ≤ z) (hz1 : z ≤ 1) (k : ℕ) : + 1 - z ^ k ≤ k * (1 - z) := by + induction k with + | zero => simp + | succ k hk => + have hp := pow_le_one₀ hz hz1 (n := k) + have hn : 0 ≤ 1 - z := sub_nonneg.mpr hz1 + have hmul := mul_le_mul_of_nonneg_right hp hn + rw [pow_succ] + push_cast + nlinarith + +lemma sum_tail_power (p : PMF ℕ) {a : ℝ} (ha : 0 < a ∧ a < 1) + (hpower : BoundedPowerInput p a) : + ∃ D > (0 : ℝ), ∀ k : ℕ, 1 ≤ k → ∀ t : ℝ, 0 < t → + (sumLaw p k).toMeasure.real {j | t < (j : ℝ)} ≤ D * k * t ^ (-a) := by + rcases hpower with ⟨c, hc, C, hC, x₀, hx₀, htail, hLap⟩ + let w : ℝ := 1 - Real.exp (-1) + have hw : 0 < w := by dsimp [w]; have := Real.exp_lt_one_iff.mpr (by norm_num : (-1 : ℝ) < 0); linarith + let D := max (C / w) (x₀ ^ a) + have hD : 0 < D := (div_pos hC hw).trans_le (le_max_left _ _) + refine ⟨D, hD, ?_⟩ + intro k hk t ht + have hk' : (1 : ℝ) ≤ k := by exact_mod_cast hk + have hk0 : (0 : ℝ) ≤ k := Nat.cast_nonneg _ + have htpa : 0 ≤ t ^ (-a) := Real.rpow_nonneg ht.le _ + by_cases htx : x₀ ≤ t + · have hsmall : t⁻¹ ≤ x₀⁻¹ := (inv_le_inv₀ ht hx₀).mpr htx + have hlap := (hLap t⁻¹ (inv_pos.mpr ht) hsmall).2 + have hpow := one_sub_pow_le_nat_mul (laplace_pos p (inv_nonneg.mpr ht.le)).le + (laplace_le_one p (inv_nonneg.mpr ht.le)) k + have hmark := tail_from_laplace (sumLaw p k) ht + rw [laplace_sumLaw] at hmark + have hmulti := mul_le_mul_of_nonneg_left hlap hk0 + have hid : (t⁻¹) ^ a = t ^ (-a) := by rw [Real.inv_rpow ht.le, Real.rpow_neg ht.le] + rw [hid] at hmulti + have hbound : w * (sumLaw p k).toMeasure.real {j | t < (j : ℝ)} ≤ k * C * t ^ (-a) := by + dsimp [w]; nlinarith + have hcD : C ≤ D * w := (div_le_iff₀ hw).mp (le_max_left _ _) + calc + (sumLaw p k).toMeasure.real {j | t < (j : ℝ)} ≤ (k * C * t ^ (-a)) / w := by + apply (le_div_iff₀ hw).mpr + simpa only [mul_comm] using hbound + _ ≤ (k * (D * w) * t ^ (-a)) / w := by gcongr + _ = D * k * t ^ (-a) := by field_simp + · have htX : t ≤ x₀ := (lt_of_not_ge htx).le + have htpow : t ^ a ≤ x₀ ^ a := Real.rpow_le_rpow ht.le htX ha.1.le + have hpos : 0 < t ^ a := Real.rpow_pos_of_pos ht a + have hpowid : t ^ a * t ^ (-a) = 1 := by + rw [Real.rpow_neg ht.le, mul_inv_cancel₀ hpos.ne'] + have hconst : x₀ ^ a ≤ D * k := by + have := le_max_right (C / w) (x₀ ^ a) + change x₀ ^ a ≤ D at this + nlinarith + calc + (sumLaw p k).toMeasure.real {j | t < (j : ℝ)} ≤ 1 := measureReal_le_one + _ = t ^ a * t ^ (-a) := hpowid.symm + _ ≤ D * k * t ^ (-a) := mul_le_mul_of_nonneg_right (htpow.trans hconst) htpa + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Tilt.lean b/lean/OAI/Probability/Renewal/Tilt.lean new file mode 100644 index 0000000000000000000000000000000000000000..14362d789f2af69162124cfb63ef3d56d795f798 --- /dev/null +++ b/lean/OAI/Probability/Renewal/Tilt.lean @@ -0,0 +1,122 @@ +import OAI.Probability.Renewal.SumLaw + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +def tilt (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) : PMF ℕ := + letI := isProbabilityMeasure_tilted (integrable_laplace p hu) + (p.toMeasure.tilted (fun j => -u * (j : ℝ))).toPMF + +lemma tilt_toMeasure (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) : + (tilt p u hu).toMeasure = p.toMeasure.tilted (fun j => -u * (j : ℝ)) := by + let := isProbabilityMeasure_tilted (integrable_laplace p hu) + exact Measure.toPMF_toMeasure _ + +lemma tilt_apply (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (j : ℕ) : + tilt p u hu j = ENNReal.ofReal (Real.exp (-u * (j : ℝ)) / laplace p u) * p j := by + change p.toMeasure.tilted (fun j => -u * (j : ℝ)) {j} = _ + rw [Measure.tilted, withDensity_apply _ (measurableSet_singleton _), lintegral_singleton] + rw [p.toMeasure_apply_singleton _ (measurableSet_singleton _)] + rfl + +lemma tilt_apply_real (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (j : ℕ) : + (tilt p u hu j).toReal = Real.exp (-u * (j : ℝ)) / laplace p u * (p j).toReal := by + rw [tilt_apply, ENNReal.toReal_mul, ENNReal.toReal_ofReal (by positivity [laplace_pos p hu])] + +lemma integral_tilt {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (F : ℕ → E) : + (∫ j, F j ∂(tilt p u hu).toMeasure) = + (laplace p u)⁻¹ • ∫ j, Real.exp (-u * (j : ℝ)) • F j ∂p.toMeasure := by + rw [tilt_toMeasure, integral_tilted] + simp_rw [div_eq_inv_mul, mul_smul] + rw [integral_smul] + rfl + +lemma integrable_tilt_iff {E : Type*} [NormedAddCommGroup E] [NormedSpace ℝ E] + (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (F : ℕ → E) : + Integrable F (tilt p u hu).toMeasure ↔ + Integrable (fun j : ℕ => Real.exp (-u * (j : ℝ)) • F j) p.toMeasure := by + rw [tilt_toMeasure] + exact integrable_tilted_iff (integrable_laplace p hu) F + +lemma measureReal_tilt (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (s : Set ℕ) : + (tilt p u hu).toMeasure.real s = + (∫ j in s, Real.exp (-u * (j : ℝ)) ∂p.toMeasure) / laplace p u := by + rw [Measure.real, tilt_toMeasure, tilted_apply_eq_ofReal_integral] + rw [ENNReal.toReal_ofReal (integral_nonneg (fun _ => by positivity [laplace_pos p hu]))] + rw [integral_div]; rfl + +lemma measureReal_tilt_lower (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (s : Set ℕ) (x : ℝ) + (hs : ∀ j ∈ s, (j : ℝ) ≤ x) : + Real.exp (-u * x) * p.toMeasure.real s ≤ (tilt p u hu).toMeasure.real s := by + rw [measureReal_tilt] + have hpos := laplace_pos p hu + apply (le_div_iff₀ hpos).mpr + calc + (Real.exp (-u * x) * p.toMeasure.real s) * laplace p u ≤ + Real.exp (-u * x) * p.toMeasure.real s := by + exact mul_le_of_le_one_right (by positivity) (laplace_le_one p hu) + _ = ∫ _ in s, Real.exp (-u * x) ∂p.toMeasure := by simp [mul_comm] + _ ≤ ∫ j in s, Real.exp (-u * (j : ℝ)) ∂p.toMeasure := by + apply setIntegral_mono_on (integrable_const _) (integrable_laplace p hu).integrableOn + MeasurableSet.of_discrete + intro j hj + apply Real.exp_le_exp.mpr + exact mul_le_mul_of_nonpos_left (hs j hj) (neg_nonpos.mpr hu) + +lemma tilt_char_difference (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (t : ℝ) : + ‖latticeChar (tilt p u hu) t - latticeChar p t‖ ≤ + 2 * (1 - laplace p u) / laplace p u := by + let F : ℕ → ℂ := fun j => Complex.exp (((j : ℝ) * t : ℝ) * Complex.I) + have hF : ∀ j, ‖F j‖ = 1 := by intro j; simp only [F, Complex.norm_exp, Complex.mul_re, Complex.ofReal_re, Complex.I_re, Complex.ofReal_im, Complex.I_im]; simp + have hIF : Integrable F p.toMeasure := integrable_lattice_exp p t + have hEF : Integrable (fun j : ℕ => Real.exp (-u * (j : ℝ)) • F j) p.toMeasure := by + refine Integrable.of_bound Measurable.of_discrete.aestronglyMeasurable 1 ?_ + filter_upwards [] with j + rw [norm_smul, hF, mul_one, Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + exact Real.exp_le_one_iff.mpr (by nlinarith [Nat.cast_nonneg (α := ℝ) j]) + have hd : ‖(∫ j, Real.exp (-u * (j : ℝ)) • F j ∂p.toMeasure) - latticeChar p t‖ ≤ + 1 - laplace p u := by + change ‖(∫ j, Real.exp (-u * (j : ℝ)) • F j ∂p.toMeasure) - (∫ j, F j ∂p.toMeasure)‖ ≤ _ + rw [← integral_sub hEF hIF] + calc + ‖∫ j, Real.exp (-u * (j : ℝ)) • F j - F j ∂p.toMeasure‖ ≤ + ∫ j, ‖Real.exp (-u * (j : ℝ)) • F j - F j‖ ∂p.toMeasure := norm_integral_le_integral_norm _ + _ = 1 - laplace p u := by + rw [← deficit_integral p hu] + apply integral_congr_ae + filter_upwards [] with j + have hid : Real.exp (-u * (j : ℝ)) • F j - F j = (Real.exp (-u * (j : ℝ)) - 1) • F j := by simp [sub_smul] + rw [hid, norm_smul, hF, mul_one, Real.norm_eq_abs, + abs_of_nonpos (sub_nonpos.mpr (Real.exp_le_one_iff.mpr (by nlinarith [Nat.cast_nonneg (α := ℝ) j])))] + ring + change ‖(∫ j, F j ∂(tilt p u hu).toMeasure) - latticeChar p t‖ ≤ _ + rw [integral_tilt] + have hz := laplace_pos p hu + have hz1 := laplace_le_one p hu + let z := laplace p u + have hid : z⁻¹ • (∫ j, Real.exp (-u * (j : ℝ)) • F j ∂p.toMeasure) - latticeChar p t = + z⁻¹ • ((∫ j, Real.exp (-u * (j : ℝ)) • F j ∂p.toMeasure) - latticeChar p t) + + (z⁻¹ - 1) • latticeChar p t := by simp [smul_sub, sub_smul] + rw [hid] + calc + _ ≤ ‖z⁻¹ • ((∫ j, Real.exp (-u * (j : ℝ)) • F j ∂p.toMeasure) - latticeChar p t)‖ + + ‖(z⁻¹ - 1) • latticeChar p t‖ := norm_add_le _ _ + _ ≤ z⁻¹ * (1 - z) + (z⁻¹ - 1) * 1 := by + simp only [norm_smul, Real.norm_eq_abs] + rw [abs_of_pos (inv_pos.mpr hz), abs_of_nonneg (sub_nonneg.mpr ((one_le_inv₀ hz).mpr hz1))] + apply add_le_add + · exact mul_le_mul_of_nonneg_left hd (inv_nonneg.mpr hz.le) + · exact mul_le_mul_of_nonneg_left (norm_latticeChar_le_one p t) + (sub_nonneg.mpr ((one_le_inv₀ hz).mpr hz1)) + _ = 2 * (1 - laplace p u) / laplace p u := by dsimp [z]; field_simp; ring + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/TiltMoments.lean b/lean/OAI/Probability/Renewal/TiltMoments.lean new file mode 100644 index 0000000000000000000000000000000000000000..377b6105d672d19be99b11de595f48f99e69cf24 --- /dev/null +++ b/lean/OAI/Probability/Renewal/TiltMoments.lean @@ -0,0 +1,131 @@ +import OAI.Probability.Renewal.Centered +import OAI.Probability.Renewal.Annuli + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +namespace AnnulusData +variable {p : PMF ℕ} {a : ℝ} (D : AnnulusData p a) + +lemma mean_lower {u : ℝ} (hu : 0 < u) (hue : u ≤ D.epsilon) : + (D.d / D.M) * u ^ (a - 1) ≤ natMean (tilt p u hu.le) := by + let q := tilt p u hu.le + have hM : 0 < D.M := zero_lt_one.trans D.M_one + have h1 : Integrable (fun j : ℕ => (j : ℝ)) q.toMeasure := by + simpa using tilt_moment_integrable p hu 1 + have hm := D.mass u hu hue u hu.le le_rfl + have hmul := mul_le_mul_of_nonneg_right hm (by positivity : 0 ≤ u⁻¹ / D.M) + have hid : D.d * u ^ a * (u⁻¹ / D.M) = D.d / D.M * u ^ (a - 1) := by + rw [Real.rpow_sub hu, Real.rpow_one] + field_simp + rw [hid] at hmul + calc + D.d / D.M * u ^ (a - 1) ≤ q.toMeasure.real (annulus D.M u) * (u⁻¹ / D.M) := hmul + _ = ∫ _ in annulus D.M u, u⁻¹ / D.M ∂q.toMeasure := by simp + _ ≤ ∫ j : ℕ in annulus D.M u, (j : ℝ) ∂q.toMeasure := by + apply setIntegral_mono_on (integrable_const _) h1.integrableOn MeasurableSet.of_discrete + intro j hj + exact hj.1.le + _ ≤ natMean q := setIntegral_le_integral h1 (ae_of_all _ (fun _ => Nat.cast_nonneg _)) + +lemma variance_lower {u : ℝ} (hu : 0 < u) (hue : u ≤ D.epsilon) : + (D.d * D.beta / (2 * (2 * D.M) ^ 2)) * u ^ (a - 2) ≤ natVariance (tilt p u hu.le) := by + let q := tilt p u hu.le + have hM : 0 < D.M := zero_lt_one.trans D.M_one + have h1 : Integrable (fun j : ℕ => (j : ℝ)) q.toMeasure := by + simpa using tilt_moment_integrable p hu 1 + have h2 := tilt_moment_integrable p hu 2 + have hm := D.mass u hu hue u hu.le le_rfl + have hb := D.atom u hu hue u hu.le le_rfl + have hr := rectangle_variance_bound q h1 h2 (annulus D.M u) {D.b} + ((u⁻¹ / (2 * D.M)) ^ 2) (by + intro j hj l hl + rw [mem_singleton_iff] at hl + subst l + have hh := (D.geometry u hu hue j hj).1 + have hpos : 0 ≤ u⁻¹ / (2 * D.M) := by positivity + exact pow_le_pow_left₀ hpos hh 2) + have hmulti := mul_le_mul_of_nonneg_right + (mul_le_mul hm hb D.beta_pos.le measureReal_nonneg) (sq_nonneg (u⁻¹ / (2 * D.M))) + have hh := hmulti.trans hr + have hid : D.d * u ^ a * D.beta * (u⁻¹ / (2 * D.M)) ^ 2 = + 2 * ((D.d * D.beta / (2 * (2 * D.M) ^ 2)) * u ^ (a - 2)) := by + rw [Real.rpow_sub hu, Real.rpow_two] + field_simp + rw [hid] at hh + linarith + +end AnnulusData + +structure MomentData (p : PMF ℕ) (a : ℝ) where + muLower : ℝ + muLower_pos : 0 < muLower + muUpper : ℝ + muUpper_pos : 0 < muUpper + varLower : ℝ + varLower_pos : 0 < varLower + varUpper : ℝ + varUpper_pos : 0 < varUpper + thirdUpper : ℝ + thirdUpper_pos : 0 < thirdUpper + epsilon : ℝ + epsilon_pos : 0 < epsilon + mean_lower : ∀ u (hu : 0 < u), u ≤ epsilon → muLower * u ^ (a - 1) ≤ natMean (tilt p u hu.le) + mean_upper : ∀ u (hu : 0 < u), u ≤ epsilon → natMean (tilt p u hu.le) ≤ muUpper * u ^ (a - 1) + var_lower : ∀ u (hu : 0 < u), u ≤ epsilon → varLower * u ^ (a - 2) ≤ natVariance (tilt p u hu.le) + var_upper : ∀ u (hu : 0 < u), u ≤ epsilon → natVariance (tilt p u hu.le) ≤ varUpper * u ^ (a - 2) + third_upper : ∀ u (hu : 0 < u), u ≤ epsilon → natThird (tilt p u hu.le) ≤ thirdUpper * u ^ (a - 3) + +lemma momentData_exists (p : PMF ℕ) {a : ℝ} (ha : 0 < a ∧ a < 1) + (hpower : BoundedPowerInput p a) : Nonempty (MomentData p a) := by + obtain ⟨D⟩ := annulusData_exists p ha hpower + obtain ⟨K1, hK1, e1, he1, h1⟩ := tilt_moments_upper p ha.1 hpower 0 + obtain ⟨K2, hK2, e2, he2, h2⟩ := tilt_moments_upper p ha.1 hpower 1 + obtain ⟨K3, hK3, e3, he3, h3⟩ := tilt_moments_upper p ha.1 hpower 2 + have hM : 0 < D.M := zero_lt_one.trans D.M_one + let ε := min D.epsilon (min e1 (min e2 (min e3 1))) + have hε : 0 < ε := lt_min D.epsilon_pos (lt_min he1 (lt_min he2 (lt_min he3 zero_lt_one))) + have hdeps {u : ℝ} (hue : u ≤ ε) : u ≤ D.epsilon ∧ u ≤ e1 ∧ u ≤ e2 ∧ u ≤ e3 ∧ u ≤ 1 := by + dsimp [ε] at hue + simpa only [le_min_iff] using hue + refine ⟨⟨D.d / D.M, by positivity [D.d_pos], K1, hK1, + D.d * D.beta / (2 * (2 * D.M) ^ 2), by positivity [D.d_pos, D.beta_pos], + K2, hK2, 4 * (K3 + K1 ^ 3), by positivity, ε, hε, ?_, ?_, ?_, ?_, ?_⟩⟩ + · intro u hu hue + exact D.mean_lower hu (hdeps hue).1 + · intro u hu hue + simpa [natMean] using h1 u hu (hdeps hue).2.1 + · intro u hu hue + exact D.variance_lower hu (hdeps hue).1 + · intro u hu hue + exact (natVariance_le_second _ (tilt_moment_integrable p hu 2)).trans (by + have hh := h2 u hu (hdeps hue).2.2.1 + norm_num at hh + exact hh) + · intro u hu hue + have hmean : natMean (tilt p u hu.le) ≤ K1 * u ^ (a - 1) := by + simpa [natMean] using h1 u hu (hdeps hue).2.1 + have hraw : (∫ j : ℕ, (j : ℝ) ^ 3 ∂(tilt p u hu.le).toMeasure) ≤ K3 * u ^ (a - 3) := by + have hh := h3 u hu (hdeps hue).2.2.2.1 + norm_num at hh + exact hh + have hpow : (u ^ (a - 1)) ^ 3 ≤ u ^ (a - 3) := by + rw [← Real.rpow_natCast, ← Real.rpow_mul hu.le] + apply Real.rpow_le_rpow_of_exponent_ge hu (hdeps hue).2.2.2.2 + push_cast + linarith [ha.1] + have hmcube := pow_le_pow_left₀ (natMean_nonneg _) hmean 3 + rw [mul_pow] at hmcube + have hh := hmcube.trans (mul_le_mul_of_nonneg_left hpow (pow_nonneg hK1.le 3)) + have hcent := natThird_le_raw _ (tilt_moment_integrable p hu 3) + nlinarith + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/UniformLocal.lean b/lean/OAI/Probability/Renewal/UniformLocal.lean new file mode 100644 index 0000000000000000000000000000000000000000..57877af4b03638805a967bd1ce3405d28d6dc36f --- /dev/null +++ b/lean/OAI/Probability/Renewal/UniformLocal.lean @@ -0,0 +1,164 @@ +import OAI.Probability.Renewal.LocalInversion +import OAI.Probability.Renewal.Envelope + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +lemma sigma_polynomial_bound {a u σ V : ℝ} (ha : 0 < a ∧ a < 1) (hu : 0 < u) + (hσ : 0 < σ) (hV : 0 < V) {k n : ℕ} (hk : 1 ≤ k) (hn : 1 / a ≤ n) + (hku : 1 ≤ (k : ℝ) * u ^ a) (hvar : σ ^ 2 ≤ (k : ℝ) * V * u ^ (a - 2)) : + σ ≤ max V 1 * (k : ℝ) ^ n := by + have hh := sigma_rpow_bound ha hu hσ hV hku hvar + have hH : 0 < max V 1 := lt_of_lt_of_le zero_lt_one (le_max_right _ _) + have hk0 : 0 ≤ (k : ℝ) := Nat.cast_nonneg k + have hk1 : 1 ≤ (k : ℝ) := by exact_mod_cast hk + have heq (x : ℝ) (hx : 0 ≤ x) : (x ^ a) ^ (1 / a) = x := by + rw [← Real.rpow_mul hx, mul_one_div_cancel ha.1.ne', Real.rpow_one] + have hr := Real.rpow_le_rpow (Real.rpow_nonneg hσ.le a) hh (one_div_nonneg.mpr ha.1.le) + rw [heq σ hσ.le, Real.mul_rpow (Real.rpow_pos_of_pos hH a).le hk0, heq _ hH.le] at hr + refine hr.trans (mul_le_mul_of_nonneg_left ?_ hH.le) + exact (Real.rpow_le_rpow_of_exponent_le hk1 hn).trans_eq (Real.rpow_natCast _ _) + +namespace MomentData +variable {p : PMF ℕ} {a : ℝ} (M : MomentData p a) + +lemma third_ratio_small {δ : ℝ} (hδ : 0 < δ) : + ∃ L : ℝ, 1 ≤ L ∧ ∀ u (hu : 0 < u), u ≤ M.epsilon → ∀ k : ℕ, L ≤ (k : ℝ) * u ^ a → + ∀ σ : ℝ, 0 < σ → σ ^ 2 = k * natVariance (tilt p u hu.le) → + (k : ℝ) * natThird (tilt p u hu.le) / σ ^ 3 ≤ δ := by + let B := M.thirdUpper / (M.varLower * δ) + have hB : 0 < B := div_pos M.thirdUpper_pos (mul_pos M.varLower_pos hδ) + let L := max 1 (B ^ 2 / M.varLower) + refine ⟨L, le_max_left _ _, ?_⟩ + intro u hu hue k hku σ hσ hvar + have hL : B ^ 2 / M.varLower ≤ (k : ℝ) * u ^ a := (le_max_right _ _).trans hku + have hid2 : u ^ (a - 2) * u ^ 2 = u ^ a := by + rw [Real.rpow_sub hu, Real.rpow_two] + field_simp + have hv := mul_le_mul_of_nonneg_left (M.var_lower u hu hue) (Nat.cast_nonneg k) + rw [← hvar] at hv + have hsu2 : M.varLower * ((k : ℝ) * u ^ a) ≤ (σ * u) ^ 2 := by + have hh := mul_le_mul_of_nonneg_right hv (sq_nonneg u) + simpa only [mul_assoc, hid2, mul_pow, mul_left_comm M.varLower (k : ℝ)] using hh + have hB2 : B ^ 2 ≤ M.varLower * ((k : ℝ) * u ^ a) := by + have hh := (div_le_iff₀ M.varLower_pos).mp hL + nlinarith + have hBsu : B ≤ σ * u := by nlinarith [mul_pos hσ hu] + have hid3 : u ^ (a - 3) * u = u ^ (a - 2) := by + calc + _ = u ^ (a - 3) * u ^ (1 : ℝ) := by rw [Real.rpow_one] + _ = u ^ (a - 3 + 1) := (Real.rpow_add hu _ _).symm + _ = _ := by congr 1; ring + have hth := mul_le_mul_of_nonneg_right (M.third_upper u hu hue) (by positivity : 0 ≤ (k : ℝ) * u) + have hth' : ((k : ℝ) * natThird (tilt p u hu.le)) * u ≤ M.thirdUpper * ((k : ℝ) * u ^ (a - 2)) := by + have hidR : M.thirdUpper * u ^ (a - 3) * ((k : ℝ) * u) = + M.thirdUpper * ((k : ℝ) * u ^ (a - 2)) := by rw [← hid3]; ring + rw [hidR] at hth + nlinarith + have hv' := mul_le_mul_of_nonneg_left hv (div_nonneg M.thirdUpper_pos.le M.varLower_pos.le) + have hv'' : M.thirdUpper * ((k : ℝ) * u ^ (a - 2)) ≤ (M.thirdUpper / M.varLower) * σ ^ 2 := by + have hidV : (M.thirdUpper / M.varLower) * ((k : ℝ) * (M.varLower * u ^ (a - 2))) = + M.thirdUpper * ((k : ℝ) * u ^ (a - 2)) := by field_simp [M.varLower_pos.ne'] + rwa [hidV] at hv' + have hT : M.thirdUpper / M.varLower ≤ δ * (σ * u) := by + have hh := mul_le_mul_of_nonneg_left hBsu hδ.le + have hid : δ * B = M.thirdUpper / M.varLower := by dsimp [B]; field_simp + rwa [hid] at hh + have herr := hth'.trans hv'' + have hlast := mul_le_mul_of_nonneg_right hT (sq_nonneg σ) + apply (div_le_iff₀ (by positivity : 0 < σ ^ 3)).mpr + nlinarith [mul_pos hσ hu] + +lemma variance_ge_const (ha : a < 1) {u : ℝ} (hu : 0 < u) (hu1 : u ≤ 1) (hue : u ≤ M.epsilon) : + M.varLower ≤ natVariance (tilt p u hu.le) := by + have hp : 1 ≤ u ^ (a - 2) := Real.one_le_rpow_of_pos_of_le_one_of_nonpos hu hu1 (by linarith) + have hm := mul_le_mul_of_nonneg_left hp M.varLower_pos.le + simpa only [mul_one] using hm.trans (M.var_lower u hu hue) + +end MomentData + +lemma uniform_tilted_local (p : PMF ℕ) (hspan : SpanOne p) {a : ℝ} (ha : 0 < a ∧ a < 1) + (hpower : BoundedPowerInput p a) : + ∃ ω : ℝ, 1 ≤ ω ∧ ∃ L : ℝ, 1 ≤ L ∧ ∃ ε : ℝ, 0 < ε ∧ ∃ N : ℕ, + ∀ u (hu : 0 < u), u ≤ ε → ∀ k : ℕ, N ≤ k → L ≤ (k : ℝ) * u ^ a → + ∀ m : ℕ, let σ := Real.sqrt ((k : ℝ) * natVariance (tilt p u hu.le)) + |((m : ℝ) - k * natMean (tilt p u hu.le)) / σ| * ω ≤ 1 → + Real.exp (-1) / (8 * Real.pi * σ) ≤ (sumLaw (tilt p u hu.le) k m).toReal := by + obtain ⟨D⟩ := annulusData_exists p ha hpower + obtain ⟨M⟩ := momentData_exists p ha hpower + obtain ⟨ρ, hρ, εg, hεg, hgap⟩ := tilt_spectral_gap p hspan ha.1 hpower D.epsilon_pos + obtain ⟨ω, hω, htail⟩ := exists_integral_tail_small (D.envelope_integrable M ha.1) + (by positivity : 0 < Real.exp (-1) / 4) + have hω0 : 0 < ω := zero_lt_one.trans_le hω + let δ := Real.exp (-1) / (8 * ω ^ 4) + have hδ : 0 < δ := by dsimp [δ]; positivity + obtain ⟨L, hL, hratio⟩ := M.third_ratio_small hδ + obtain ⟨n, hn⟩ := exists_nat_ge (1 / a) + let H := max M.varUpper 1 + have hpoly : Tendsto (fun k : ℕ => 2 * Real.pi * H * ((k : ℝ) ^ n * ρ ^ k)) atTop (𝓝 0) := by + simpa using (tendsto_pow_const_mul_const_pow_of_lt_one n hρ.1 hρ.2).const_mul (2 * Real.pi * H) + have hhigh := hpoly.eventually (Iio_mem_nhds (by positivity : 0 < Real.exp (-1) / 4)) + have hcast := (tendsto_natCast_atTop_atTop : Tendsto (fun k : ℕ => (k : ℝ)) atTop atTop) + have hlarge : ∀ᶠ k : ℕ in atTop, + 1 ≤ k ∧ ω ^ 2 ≤ 2 * (k : ℝ) ∧ (ω / Real.pi) ^ 2 ≤ (k : ℝ) * M.varLower ∧ + 4 * ω ^ 5 / Real.exp (-1) ≤ (k : ℝ) := by + filter_upwards [eventually_ge_atTop (1 : ℕ), hcast.eventually_ge_atTop (ω ^ 2 / 2), + hcast.eventually_ge_atTop ((ω / Real.pi) ^ 2 / M.varLower), + hcast.eventually_ge_atTop (4 * ω ^ 5 / Real.exp (-1))] with k hk h2 hv he + exact ⟨hk, by linarith, (div_le_iff₀ M.varLower_pos).mp hv, he⟩ + obtain ⟨N, hN⟩ := (hlarge.and hhigh).exists_forall_of_atTop + let ε := min D.epsilon (min M.epsilon (min εg 1)) + refine ⟨ω, hω, L, hL, ε, lt_min D.epsilon_pos (lt_min M.epsilon_pos (lt_min hεg zero_lt_one)), N, ?_⟩ + intro u hu hue k hk hku m σ hcenter + have hdeps : u ≤ D.epsilon ∧ u ≤ M.epsilon ∧ u ≤ εg ∧ u ≤ 1 := by + simpa only [ε, le_min_iff] using hue + obtain ⟨⟨hk1, hk2, hkv, hke⟩, hkhigh⟩ := hN k hk + have hkpos : 0 < k := lt_of_lt_of_le Nat.zero_lt_one hk1 + have hkpos' : (0 : ℝ) < k := by exact_mod_cast hkpos + have hv0 := M.variance_ge_const ha.2 hu hdeps.2.2.2 hdeps.2.1 + have hvpos : 0 < natVariance (tilt p u hu.le) := M.varLower_pos.trans_le hv0 + have hσ : 0 < σ := Real.sqrt_pos.mpr (mul_pos hkpos' hvpos) + have hvar : σ ^ 2 = k * natVariance (tilt p u hu.le) := Real.sq_sqrt (mul_pos hkpos' hvpos).le + have hwidth : ω ≤ Real.pi * σ := by + have hh := mul_le_mul_of_nonneg_left hv0 hkpos'.le + rw [← hvar] at hh + have hsq : (ω / Real.pi) ^ 2 ≤ σ ^ 2 := hkv.trans hh + have hdiv : ω / Real.pi ≤ σ := by nlinarith [sq_nonneg σ] + exact (div_le_iff₀ Real.pi_pos).mp hdiv |>.trans_eq (mul_comm _ _) + have hσup : σ ≤ H * (k : ℝ) ^ n := by + apply sigma_polynomial_bound ha hu hσ M.varUpper_pos hk1 hn (hL.trans hku) + rw [hvar] + simpa only [mul_assoc] using mul_le_mul_of_nonneg_left (M.var_upper u hu hdeps.2.1) hkpos'.le + apply local_lower_of_envelope (tilt p u hu.le) (tilt_moment_integrable p hu 3) + hkpos m hσ hω hvar hk2 hwidth hcenter (D.envelope_integrable M ha.1) + (D.envelope_nonneg M) (pow_nonneg hρ.1 k) + · intro t ht + apply D.normalized_bound M ha hu hdeps.1 hdeps.2.1 (hL.trans hku) hσ hvar hρ.1 + (hgap u hu.le hdeps.2.2.1) + exact abs_le.mpr ⟨by simpa [neg_mul] using ht.1, ht.2⟩ + · exact htail + · have hm := mul_le_mul_of_nonneg_right hσup (mul_nonneg (by positivity : 0 ≤ 2 * Real.pi) (pow_nonneg hρ.1 k)) + nlinarith + · have hr := hratio u hu hdeps.2.1 k hku σ hσ hvar + have hfirst : (k : ℝ) * natThird (tilt p u hu.le) / σ ^ 3 * ω ^ 4 ≤ Real.exp (-1) / 8 := by + have hh := mul_le_mul_of_nonneg_right hr (pow_nonneg hω0.le 4) + have hid : δ * ω ^ 4 = Real.exp (-1) / 8 := by dsimp [δ]; field_simp + simpa only [hid] using hh + have hsecond : ω ^ 5 / (2 * (k : ℝ)) ≤ Real.exp (-1) / 8 := by + apply (div_le_iff₀ (by positivity)).mpr + have hh := (div_le_iff₀ (Real.exp_pos (-1))).mp hke + nlinarith + have hid : 2 * ω * ((k * natThird (tilt p u hu.le) / σ ^ 3) * ω ^ 3 / 2 + ω ^ 4 / (4 * k)) = + (k * natThird (tilt p u hu.le) / σ ^ 3) * ω ^ 4 + ω ^ 5 / (2 * k) := by ring + rw [hid] + linarith + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/Renewal/Untilt.lean b/lean/OAI/Probability/Renewal/Untilt.lean new file mode 100644 index 0000000000000000000000000000000000000000..57b6efd46b6bced62686d04e9ac58aa060a2fbb4 --- /dev/null +++ b/lean/OAI/Probability/Renewal/Untilt.lean @@ -0,0 +1,84 @@ +import OAI.Probability.Renewal.Tilt + +namespace OAI + +noncomputable section +open MeasureTheory ProbabilityTheory Filter Set +open scoped Topology ENNReal +namespace HoneycombLocal + +lemma sumLaw_tilt_apply (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (k m : ℕ) : + sumLaw (tilt p u hu) k m = + ENNReal.ofReal (Real.exp (-u * (m : ℝ)) / laplace p u ^ k) * sumLaw p k m := by + classical + induction k generalizing m with + | zero => + simp only [sumLaw, PMF.pure_apply, pow_zero, div_one] + split_ifs with hm <;> simp_all + | succ k hk => + simp only [sumLaw, PMF.bind_apply, PMF.map_apply, tilt_apply, hk] + rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro j + simp_rw [← ENNReal.tsum_mul_left] + apply tsum_congr + intro r + split_ifs with hsum + · subst m + have hz := laplace_pos p hu + have hid : Real.exp (-u * ((j + r : ℕ) : ℝ)) / laplace p u ^ (k + 1) = + (Real.exp (-u * (j : ℝ)) / laplace p u) * + (Real.exp (-u * (r : ℝ)) / laplace p u ^ k) := by + rw [div_mul_div_comm, ← Real.exp_add, pow_succ] + push_cast + rw [show -u * ((j : ℝ) + r) = -u * (j : ℝ) + -u * (r : ℝ) by ring] + field_simp + rw [hid, ENNReal.ofReal_mul (by positivity)] + ring + · simp + +lemma sumLaw_untilt_real (p : PMF ℕ) (u : ℝ) (hu : 0 ≤ u) (k m : ℕ) : + (sumLaw p k m).toReal = Real.exp (u * (m : ℝ)) * laplace p u ^ k * + (sumLaw (tilt p u hu) k m).toReal := by + rw [sumLaw_tilt_apply, ENNReal.toReal_mul, + ENNReal.toReal_ofReal (by positivity [laplace_pos p hu])] + have he : Real.exp (u * (m : ℝ)) * Real.exp (-u * (m : ℝ)) = 1 := by + rw [← Real.exp_add, neg_mul, add_neg_cancel, Real.exp_zero] + have hz := laplace_pos p hu + simp only [neg_mul] at he + field_simp + nlinarith [congrArg (fun x : ℝ => (sumLaw p k m).toReal * x) he] + +lemma pow_lower_from_deficit {z d : ℝ} (hz : 1 / 2 ≤ z) (hz1 : z ≤ 1) + (hd : 1 - z ≤ d) (k : ℕ) : Real.exp (-2 * k * d) ≤ z ^ k := by + have hz0 : 0 < z := by linarith + have hlog := Real.one_sub_inv_le_log_of_pos hz0 + have hinv : 1 - z⁻¹ ≥ -2 * (1 - z) := by + have hh : 0 ≤ (1 - z) * (2 * z - 1) := mul_nonneg (by linarith) (by linarith) + have hzid : z * z⁻¹ = 1 := mul_inv_cancel₀ hz0.ne' + nlinarith + have hlower : -2 * d ≤ Real.log z := by linarith + rw [← Real.exp_log (pow_pos hz0 k), Real.log_pow] + apply Real.exp_le_exp.mpr + have hh := mul_le_mul_of_nonneg_left hlower (Nat.cast_nonneg (α := ℝ) k) + nlinarith + +lemma untilt_lower (p : PMF ℕ) {a u C K : ℝ} (hu : 0 ≤ u) + (hz : 1 / 2 ≤ laplace p u) (hC : 0 ≤ C) + (hdef : 1 - laplace p u ≤ C * u ^ a) {k m : ℕ} (hk : (k : ℝ) * u ^ a ≤ K) : + Real.exp (-2 * C * K) * (sumLaw (tilt p u hu) k m).toReal ≤ (sumLaw p k m).toReal := by + have hp := pow_lower_from_deficit hz (laplace_le_one p hu) hdef k + have hm := mul_le_mul_of_nonneg_left hk (by positivity : 0 ≤ 2 * C) + have he : Real.exp (-2 * C * K) ≤ laplace p u ^ k := + (Real.exp_le_exp.mpr (by nlinarith)).trans hp + have hexp : 1 ≤ Real.exp (u * (m : ℝ)) := Real.one_le_exp_iff.mpr (by positivity) + rw [sumLaw_untilt_real p u hu k m] + have hfac : Real.exp (-2 * C * K) ≤ Real.exp (u * (m : ℝ)) * laplace p u ^ k := + he.trans (le_mul_of_one_le_left (pow_pos (laplace_pos p hu) k).le hexp) + exact mul_le_mul_of_nonneg_right hfac ENNReal.toReal_nonneg + +end HoneycombLocal + +end + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ActiveClauses.lean b/lean/OAI/Probability/SATComputability/ActiveClauses.lean new file mode 100644 index 0000000000000000000000000000000000000000..a3f8d355c659287baac0c257cf5b46cb525e7a78 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ActiveClauses.lean @@ -0,0 +1,92 @@ +import OAI.Probability.SATComputability.ClassMasks + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open scoped Classical + +abbrev IncidentClass (n : ℕ) := + (Fin 3 × SignedLiteral n × SignedLiteral n) ⊕ (Fin 3 × SignedLiteral n) ⊕ Unit +abbrev ActiveClause (n : ℕ) := Triple (SignedLiteral n) ⊕ Bool × IncidentClass n + +def activeClass {n : ℕ} : ActiveClause n → TripleClasses (SignedLiteral n) + | .inl c => .inl c + | .inr (b,.inl (i,c,d)) => .inr (.inl (i,b,c,d)) + | .inr (b,.inr (.inl (i,c))) => .inr (.inr (.inl (i,b,b,c))) + | .inr (b,.inr (.inr _)) => .inr (.inr (.inr (b,b,b))) + +theorem activeClass_injective (n : ℕ) : Function.Injective (activeClass (n := n)) := by + intro c d h + rcases c with c | ⟨b,c | (c | c)⟩ <;> + rcases d with d | ⟨a,d | (d | d)⟩ <;> + simp_all [activeClass] + all_goals exact Prod.ext h.1 h.2.2 + +noncomputable def incidentMask {n : ℕ} : IncidentClass n → Finset (DeletionCandidate n) + | .inl (_,c,d) => clauseMask ![c,d] + | .inr _ => ∅ + +noncomputable def strongerClassMask {n : ℕ} : ActiveClause n → Finset (DeletionCandidate (n+1)) + | .inl c => restoredMask (clauseMask ((tripleVectorEquiv _).symm c)) Finset.univ Finset.univ + | .inr (false,c) => restoredMask Finset.univ Finset.univ (incidentMask c) + | .inr (true,c) => restoredMask Finset.univ (incidentMask c) Finset.univ + +theorem restoredMask_mono {n : ℕ} + {B F T B' F' T' : Finset (DeletionCandidate n)} + (hB : B ⊆ B') (hF : F ⊆ F') (hT : T ⊆ T') : + restoredMask B F T ⊆ restoredMask B' F' T' := by + intro x hx + obtain ⟨hb,hx⟩ := (Finset.mem_filter.mp hx).2 + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _,hB hb,?_⟩ + rcases h0 : x 0 with _ | (_ | _) + · trivial + · exact hF (by simpa only [h0] using hx) + · exact hT (by simpa only [h0] using hx) + +theorem strongerClassMask_subset {n : ℕ} (c : ActiveClause n) : + strongerClassMask c ⊆ clauseMask (classClause (activeClass c)) := by + rw [classClause_restored] + rcases c with c | ⟨b,c | (⟨i,c⟩ | u)⟩ + · exact Finset.Subset.refl _ + · rcases c with ⟨i,c,d⟩ + cases b <;> exact Finset.Subset.refl _ + · cases b <;> + simp only [strongerClassMask, activeClass, classBaseMask, classIncidentMask, + Bool.false_eq_true, Bool.true_eq_false, or_self, ite_true, ite_false, incidentMask] + all_goals apply restoredMask_mono <;> first | exact Finset.Subset.refl _ | exact Finset.empty_subset _ + · cases b <;> exact Finset.Subset.refl _ + +theorem inactiveClass_trivial {n : ℕ} (c : TripleClasses (SignedLiteral n)) + (hc : c ∉ Set.range (activeClass (n := n))) : + clauseMask (classClause c) = Finset.univ := by + rcases c with c | (⟨i,b,c,d⟩ | (⟨i,a,b,c⟩ | ⟨a,b,c⟩)) + · exact False.elim (hc ⟨.inl c,rfl⟩) + · exact False.elim (hc ⟨.inr (b,.inl (i,c,d)),rfl⟩) + · by_cases hab : a = b + · subst b + exact False.elim (hc ⟨.inr (a,.inr (.inl (i,c))),rfl⟩) + · rw [classClause_restored_double] + clear hc + cases a <;> cases b <;> try contradiction + all_goals + ext x + rcases h0 : x 0 with _ | (_ | _) + all_goals simp [classBaseMask, classIncidentMask, restoredMask, h0] + · by_cases habc : a = b ∧ b = c + · rcases habc with ⟨hab,hbc⟩ + subst b + subst c + exact False.elim (hc ⟨.inr (a,.inr (.inr ())),rfl⟩) + · rw [classClause_restored_triple] + clear hc + cases a <;> cases b <;> cases c <;> try simp_all + all_goals + ext x + rcases h0 : x 0 with _ | (_ | _) + all_goals simp [classBaseMask, classIncidentMask, restoredMask, h0] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ActiveMaskCounts.lean b/lean/OAI/Probability/SATComputability/ActiveMaskCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..384db514c03ef88b14cd1369c76090dbabcdd153 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ActiveMaskCounts.lean @@ -0,0 +1,58 @@ +import OAI.Probability.SATComputability.ActiveClauses +import OAI.Probability.SATComputability.PoissonMaskCounts + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open scoped Classical + +theorem countsMask_mono {A X : Type*} [Fintype A] [Fintype X] + {f g : A → Finset X} (h : ∀ a, f a ⊆ g a) (c : A → ℕ) : + countsMask f c ⊆ countsMask g c := by + intro x hx + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _,?_⟩ + intro a + exact ((Finset.mem_filter.mp hx).2 a).imp_right (fun hx => h a hx) + +theorem countsMask_equiv {A B X : Type*} [Fintype A] [Fintype B] [Fintype X] + (e : A ≃ B) (f : B → Finset X) (c : A → ℕ) : + countsMask (f ∘ e) c = countsMask f (c ∘ e.symm) := by + ext x + simp only [countsMask, Finset.mem_filter, Finset.mem_univ, true_and, Function.comp_def] + constructor + · intro h b + simpa only [Equiv.apply_symm_apply] using h (e.symm b) + · intro h a + simpa only [Equiv.symm_apply_apply] using h (e a) + +theorem countsMask_active {n : ℕ} (c : TripleClasses (SignedLiteral n) → ℕ) : + countsMask (fun a => clauseMask (classClause (activeClass a))) (c ∘ activeClass) = + countsMask (fun a => clauseMask (classClause a)) c := by + ext x + simp only [countsMask, Finset.mem_filter, Finset.mem_univ, true_and, Function.comp_def] + constructor + · intro h a + by_cases ha : a ∈ Set.range (activeClass (n := n)) + · obtain ⟨b,rfl⟩ := ha + exact h b + · exact Or.inr (by rw [inactiveClass_trivial a ha]; exact Finset.mem_univ _) + · intro h a + exact h (activeClass a) + +theorem countsMask_stronger {n : ℕ} (c : ActiveClause n → ℕ) : + countsMask strongerClassMask c = + restoredMask + (countsMask (fun a => clauseMask ((tripleVectorEquiv _).symm a)) (fun a => c (.inl a))) + (countsMask incidentMask (fun a => c (.inr (true,a)))) + (countsMask incidentMask (fun a => c (.inr (false,a)))) := by + ext x + rcases h0 : x 0 with _ | (_ | _) + all_goals + simp [countsMask, strongerClassMask, restoredMask, Sum.forall, Prod.forall, + Bool.forall_bool, h0] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ActiveProcess.lean b/lean/OAI/Probability/SATComputability/ActiveProcess.lean new file mode 100644 index 0000000000000000000000000000000000000000..8cec0980ceec54cd41e837123825b0d0d9d5b85d --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ActiveProcess.lean @@ -0,0 +1,172 @@ +import OAI.Probability.SATComputability.IncidentRates +import OAI.Probability.SATComputability.GridBlockLaw + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators Classical NNReal + +noncomputable def activeMask {n : ℕ} (a : ActiveClause n) : Finset (DeletionCandidate (n+1)) := + clauseMask (classClause (activeClass a)) + +noncomputable def baseMask {n : ℕ} (a : Triple (SignedLiteral n)) : Finset (DeletionCandidate n) := + clauseMask ((tripleVectorEquiv _).symm a) + +theorem active_base_counts {n : ℕ} (c : ActiveClause n → ℕ) : + countsMask (fun a => classBaseMask (activeClass a)) c = + countsMask baseMask (fun a => c (.inl a)) := by + ext x + simp [countsMask, classBaseMask, activeClass, baseMask, Sum.forall, Prod.forall] + +theorem active_mask_counts {n : ℕ} (c : ActiveClause n → ℕ) : + countsMask activeMask c = restoredMask + (countsMask baseMask (fun a => c (.inl a))) + (countsMask (fun a => classIncidentMask false (activeClass a)) c) + (countsMask (fun a => classIncidentMask true (activeClass a)) c) := by + rw [← active_base_counts, ← countsMask_restored] + congr 1 + funext a + exact classClause_restored (activeClass a) + +theorem active_free_lifetime {n M r : ℕ} (c : ActiveClause n × Fin M → ℕ) : + maskLifetime M (freeDeletionBudgetMask (n+1) r 0) (maskGrid activeMask c) = + maskLifetime M (deletionBudgetMask n r) (maskGrid baseMask (fun p => c (.inl p.1,p.2))) := by + have he : maskGrid activeMask c = fun j => restoredMask + (countsMask baseMask (fun a => c (.inl a,j))) + (countsMask (fun a => classIncidentMask false (activeClass a)) (fun a => c (a,j))) + (countsMask (fun a => classIncidentMask true (activeClass a)) (fun a => c (a,j))) := by + funext j + exact active_mask_counts _ + rw [he, free_restored_lifetime] + rfl + +theorem active_stronger_counts {n : ℕ} (c : ActiveClause n → ℕ) : + countsMask strongerClassMask c = restoredMask + (countsMask baseMask (fun a => c (.inl a))) + (countsMask incidentMask (fun a => c (.inr (true,a)))) + (countsMask incidentMask (fun a => c (.inr (false,a)))) := + countsMask_stronger c + +theorem active_gap_domination {n M r : ℕ} (c : ActiveClause n × Fin M → ℕ) : + (maskLifetime M (freeDeletionBudgetMask (n+1) r 0) (maskGrid activeMask c) - + maskLifetime M (deletionBudgetMask (n+1) r) (maskGrid activeMask c))^(6/5 : ℝ) ≤ + (maskLifetime M (deletionBudgetMask n r) (maskGrid baseMask (fun p => c (.inl p.1,p.2))) - + maskLifetime M (deletionBudgetMask (n+1) r) (fun j => restoredMask + (countsMask baseMask (fun a => c (.inl a,j))) + (countsMask incidentMask (fun a => c (.inr (true,a),j))) + (countsMask incidentMask (fun a => c (.inr (false,a),j)))))^(6/5 : ℝ) := by + have hnon : 0 ≤ maskLifetime M (freeDeletionBudgetMask (n+1) r 0) (maskGrid activeMask c) - + maskLifetime M (deletionBudgetMask (n+1) r) (maskGrid activeMask c) := + sub_nonneg.mpr (maskLifetime_mono (deletionBudgetMask_subset_free (n+1) r 0) _) + rw [active_free_lifetime] at hnon ⊢ + apply Real.rpow_le_rpow hnon _ (by norm_num : (0 : ℝ) ≤ 6/5) + apply sub_le_sub_left + apply maskLifetime_map_le id _ _ _ _ (fun _ h => h) + intro j x hx + have he := active_stronger_counts (fun a => c (a,j)) + rw [← he] at hx + exact countsMask_mono (fun a => strongerClassMask_subset a) _ hx + +theorem poissonCountLaw_three {A B C : Type*} [Fintype A] [Fintype B] [Fintype C] + (r : ℝ≥0) (f : (A → ℕ) → (B → ℕ) → (C → ℕ) → ℝ) + (D : ℝ) (hD : ∀ a b c, |f a b c| ≤ D) : + (∫ s : A ⊕ (B ⊕ C) → ℕ, + f (fun a => s (.inl a)) (fun b => s (.inr (.inl b))) (fun c => s (.inr (.inr c))) + ∂poissonCountLaw (A ⊕ (B ⊕ C)) r) = + ∫ a, ∫ b, ∫ c, f a b c ∂poissonCountLaw C r + ∂poissonCountLaw B r ∂poissonCountLaw A r := by + rw [poissonCountLaw_sum r _ D (fun s => hD _ _ _)] + apply integral_congr_ae + filter_upwards [] with a + exact poissonCountLaw_sum r _ D (fun _ => hD _ _ _) + +theorem active_streams_expect {n M : ℕ} (r : ℝ≥0) + (ψ : (Fin M → Finset (DeletionCandidate n)) → + (Fin M → Finset (DeletionCandidate n)) → (Fin M → Finset (DeletionCandidate n)) → ℝ) : + (∫ c : ActiveClause n × Fin M → ℕ, + ψ (maskGrid baseMask (fun p => c (.inl p.1,p.2))) + (maskGrid incidentMask (fun p => c (.inr (true,p.1),p.2))) + (maskGrid incidentMask (fun p => c (.inr (false,p.1),p.2))) + ∂poissonCountLaw (ActiveClause n × Fin M) r) = + (gridMaskLaw M r baseMask).expect (fun b => + (gridMaskLaw M r incidentMask).expect (fun f => + (gridMaskLaw M r incidentMask).expect (fun t => ψ b f t))) := by + let X := Fin M → Finset (DeletionCandidate n) + let D := ∑ p : X × X × X, |ψ p.1 p.2.1 p.2.2| + have hD (b f t : X) : |ψ b f t| ≤ D := + Finset.single_le_sum (fun p _ => abs_nonneg (ψ p.1 p.2.1 p.2.2)) + (Finset.mem_univ (b,f,t)) + have he := poissonCountLaw_equiv (splitActiveGrid n M) r + (fun s => ψ (maskGrid baseMask (fun p => s (.inl p))) + (maskGrid incidentMask (fun p => s (.inr (.inr p)))) + (maskGrid incidentMask (fun p => s (.inr (.inl p))))) + change (∫ c : ActiveClause n × Fin M → ℕ, + ψ (maskGrid baseMask (fun p => c (.inl p.1,p.2))) + (maskGrid incidentMask (fun p => c (.inr (true,p.1),p.2))) + (maskGrid incidentMask (fun p => c (.inr (false,p.1),p.2))) + ∂poissonCountLaw (ActiveClause n × Fin M) r) = _ at he + rw [he, poissonCountLaw_three r + (fun (b : Triple (SignedLiteral n) × Fin M → ℕ) + (f t : IncidentClass n × Fin M → ℕ) => + ψ (maskGrid baseMask b) (maskGrid incidentMask t) (maskGrid incidentMask f)) + D (fun a b c => hD _ _ _)] + have hi (b : Triple (SignedLiteral n) × Fin M → ℕ) + (f : IncidentClass n × Fin M → ℕ) : + (∫ t, ψ (maskGrid baseMask b) (maskGrid incidentMask t) (maskGrid incidentMask f) + ∂poissonCountLaw (IncidentClass n × Fin M) r) = + (gridMaskLaw M r incidentMask).expect + (fun t => ψ (maskGrid baseMask b) t (maskGrid incidentMask f)) := + (gridMaskLaw_expect r incidentMask + (fun t => ψ (maskGrid baseMask b) t (maskGrid incidentMask f))).symm + simp_rw [hi] + have hm (b : Triple (SignedLiteral n) × Fin M → ℕ) : + (∫ f, (gridMaskLaw M r incidentMask).expect + (fun t => ψ (maskGrid baseMask b) t (maskGrid incidentMask f)) + ∂poissonCountLaw (IncidentClass n × Fin M) r) = + (gridMaskLaw M r incidentMask).expect (fun f => + (gridMaskLaw M r incidentMask).expect (fun t => ψ (maskGrid baseMask b) t f)) := + (gridMaskLaw_expect r incidentMask (fun f => + (gridMaskLaw M r incidentMask).expect (fun t => ψ (maskGrid baseMask b) t f))).symm + simp_rw [hm] + rw [← gridMaskLaw_expect r baseMask (fun b => + (gridMaskLaw M r incidentMask).expect (fun f => + (gridMaskLaw M r incidentMask).expect (fun t => ψ b t f)))] + apply FiniteLaw.expect_congr + intro b + exact finite_expect_comm _ _ _ + +theorem active_original_expect {n M : ℕ} (r : ℝ≥0) + (ψ : (Fin M → Finset (DeletionCandidate (n+1))) → ℝ) : + (∫ c : TripleClasses (SignedLiteral n) × Fin M → ℕ, + ψ (maskGrid (fun a => clauseMask (classClause a)) c) + ∂poissonCountLaw (TripleClasses (SignedLiteral n) × Fin M) r) = + ∫ c : ActiveClause n × Fin M → ℕ, ψ (maskGrid activeMask c) + ∂poissonCountLaw (ActiveClause n × Fin M) r := by + let e : ActiveClause n × Fin M → TripleClasses (SignedLiteral n) × Fin M := + fun p => (activeClass p.1,p.2) + have he : Function.Injective e := by + intro p q h + change (activeClass p.1,p.2) = (activeClass q.1,q.2) at h + exact Prod.ext (activeClass_injective n (Prod.mk.inj h).1) (Prod.mk.inj h).2 + rw [← poissonCountLaw_embedding_integral e he r] + apply integral_congr_ae + filter_upwards [] with c + congr 1 + funext j + exact (countsMask_active (fun a => c (a,j))).symm + +theorem base_grid_law {n : ℕ} [NeZero n] (M : ℕ) (r : ℝ≥0) : + gridMaskLaw M r (baseMask (n := n)) = FiniteLaw.pi (fun _ : Fin M => + candidateBlock (r*Fintype.card (Triple (SignedLiteral n))) 3 Finset.univ) := by + rw [← gridMaskLaw_equiv (tripleVectorEquiv (SignedLiteral n)) r baseMask] + have hm : baseMask ∘ tripleVectorEquiv (SignedLiteral n) = clauseMask := by + funext a + simp only [baseMask, Function.comp_apply, Equiv.symm_apply_apply] + rw [hm, gridMaskLaw_clauses] + rw [Fintype.card_congr (tripleVectorEquiv (SignedLiteral n))] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ActualFreeMoment.lean b/lean/OAI/Probability/SATComputability/ActualFreeMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..6a3f101b1d174e08537e27b0cd51b085f499a94f --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ActualFreeMoment.lean @@ -0,0 +1,86 @@ +import OAI.Probability.SATComputability.ActiveProcess + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal Classical + +local instance actualFreeMomentCandidateMeasurable (n : ℕ) : + MeasurableSpace (DeletionCandidate n) := ⊤ +local instance actualFreeMomentCandidateSingleton (n : ℕ) : + MeasurableSingletonClass (DeletionCandidate n) := ⟨fun _ => trivial⟩ + +noncomputable def freeGap (n M r : ℕ) (xs : Fin M → Finset (DeletionCandidate (n+1))) : ℝ := + (maskLifetime M (freeDeletionBudgetMask (n+1) r 0) xs - + maskLifetime M (deletionBudgetMask (n+1) r) xs)^(6/5 : ℝ) + +noncomputable def restoredGap (n M r : ℕ) + (base f t : Fin M → Finset (DeletionCandidate n)) : ℝ := + (maskLifetime M (deletionBudgetMask n r) base - + maskLifetime M (deletionBudgetMask (n+1) r) + (fun j => restoredMask (base j) (f j) (t j)))^(6/5 : ℝ) + +theorem actual_free_deletion_moment_zero {n : ℕ} [NeZero n] (r : ℕ) : + (FiniteLaw.pi (fun _ : Fin (20*(n+1)) => + candidateBlock (n := n+1) 1 3 Finset.univ)).expect (freeGap n (20*(n+1)) r) ≤ + deletionMomentConstant := by + let M := 20*(n+1) + let rate := clauseAtomRate n + let ψ := restoredGap n M r + let B := gridMaskLaw M rate (baseMask (n := n)) + let P := gridMaskLaw M rate (incidentMask (n := n)) + have hgrid := gridMaskLaw_clauses (n := n+1) M 3 rate + change gridMaskLaw M rate clauseMask = _ at hgrid + have hn := clause_atom_normalization n + change rate * Fintype.card (Fin 3 → SignedLiteral (n+1)) = 1 at hn + rw [hn] at hgrid + have hm : clauseMask (n := n+1) (k := 3) = + (fun a => clauseMask (classClause a)) ∘ clauseClassesEquiv n := by + funext a + simp only [Function.comp_apply, classClause, Equiv.symm_apply_apply] + have hleft : Integrable (fun c : ActiveClause n × Fin M → ℕ => + freeGap n M r (maskGrid activeMask c)) (poissonCountLaw (ActiveClause n × Fin M) rate) := + bounded_finite_observable _ (maskGrid activeMask) (measurable_of_countable _) (freeGap n M r) + have hright : Integrable (fun c : ActiveClause n × Fin M → ℕ => + ψ (maskGrid baseMask (fun p => c (.inl p.1,p.2))) + (maskGrid incidentMask (fun p => c (.inr (true,p.1),p.2))) + (maskGrid incidentMask (fun p => c (.inr (false,p.1),p.2)))) + (poissonCountLaw (ActiveClause n × Fin M) rate) := by + exact bounded_finite_observable _ + (fun c : ActiveClause n × Fin M → ℕ => + (maskGrid baseMask (fun p => c (.inl p.1,p.2)), + maskGrid incidentMask (fun p => c (.inr (true,p.1),p.2)), + maskGrid incidentMask (fun p => c (.inr (false,p.1),p.2)))) + (measurable_of_countable _) (fun p => ψ p.1 p.2.1 p.2.2) + calc + _ = (gridMaskLaw M rate clauseMask).expect (freeGap n M r) := by rw [hgrid] + _ = (gridMaskLaw M rate (fun a => clauseMask (classClause a))).expect (freeGap n M r) := by + exact congrArg (fun P => P.expect (freeGap n M r)) + ((congrArg (gridMaskLaw M rate) hm).trans + (gridMaskLaw_equiv (clauseClassesEquiv n) rate (fun a => clauseMask (classClause a)))) + _ = ∫ c : ActiveClause n × Fin M → ℕ, freeGap n M r (maskGrid activeMask c) + ∂poissonCountLaw (ActiveClause n × Fin M) rate := by + rw [gridMaskLaw_expect, active_original_expect] + _ ≤ ∫ c : ActiveClause n × Fin M → ℕ, + ψ (maskGrid baseMask (fun p => c (.inl p.1,p.2))) + (maskGrid incidentMask (fun p => c (.inr (true,p.1),p.2))) + (maskGrid incidentMask (fun p => c (.inr (false,p.1),p.2))) + ∂poissonCountLaw (ActiveClause n × Fin M) rate := + integral_mono hleft hright (fun c => active_gap_domination c) + _ = B.expect (fun base => P.expect (fun f => P.expect (fun t => ψ base f t))) := + active_streams_expect rate ψ + _ = P.expect (fun f => P.expect (fun t => B.expect (fun base => ψ base f t))) := by + rw [finite_expect_comm B P] + apply P.expect_congr + intro f + exact finite_expect_comm B P _ + _ ≤ deletionMomentConstant := by + dsimp only [B] + rw [base_grid_law] + exact incident_restored_uniform_moment r + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ArithmeticConstructors.lean b/lean/OAI/Probability/SATComputability/ArithmeticConstructors.lean new file mode 100644 index 0000000000000000000000000000000000000000..7b0136c970e7e394b45e4c07bac4b4901d572d5c --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ArithmeticConstructors.lean @@ -0,0 +1,84 @@ +import OAI.Probability.SATComputability.ArithmeticSyntax + +namespace OAI + +namespace FixedClauseThreshold.Computability.FiniteArithmetic + +open Encodable Denumerable Nat.Partrec +open scoped BigOperators +local instance arithmeticConstructorsRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +noncomputable def rationalExpression (q : ℚ) : Code := + .prec .zero (ofNat Code (encode q)) + +@[fun_prop] theorem rationalExpression_computable : Computable rationalExpression := by + have : Computable (ofNat Code) := (Primrec.ofNat Code).to_comp + unfold rationalExpression + fun_prop + +@[simp] theorem rationalExpression_value (q : ℚ) : + expressionValue (rationalExpression q) = q := by + simp only [rationalExpression, expressionValue, ite_true, decodedRational, + encode_ofNat, encodek, Option.getD_some] + +def exponentialExpression (e : Code) : Code := .prec .succ e +def positiveLogExpression (e : Code) : Code := .prec .left e +def reciprocalExpression (e : Code) : Code := .prec .right e + +@[simp] theorem exponentialExpression_value (e : Code) : + expressionValue (exponentialExpression e) = Real.exp (expressionValue e) := by + simp [exponentialExpression, expressionValue] +@[simp] theorem positiveLogExpression_value (e : Code) : + expressionValue (positiveLogExpression e) = Real.log (max 1 (expressionValue e)) := by + simp [positiveLogExpression, expressionValue] +@[simp] theorem reciprocalExpression_value (e : Code) : + expressionValue (reciprocalExpression e) = (max 1 (expressionValue e))⁻¹ := by + simp [reciprocalExpression, expressionValue] + +noncomputable def scaledLogExpression (q : ℚ) (e : Code) : Code := + .pair (.rfind' (positiveLogExpression (rationalExpression q⁻¹))) + (positiveLogExpression (.comp (rationalExpression q⁻¹) e)) + +theorem scaledLogExpression_value {q : ℚ} {e : Code} + (hq : 0 < q) (hq1 : q ≤ 1) (he : (q : ℝ) ≤ expressionValue e) : + expressionValue (scaledLogExpression q e) = Real.log (expressionValue e) := by + have hq' : (0 : ℝ) < q := by exact_mod_cast hq + have hq1' : (q : ℝ) ≤ 1 := by exact_mod_cast hq1 + have hi : (1 : ℝ) ≤ (q : ℝ)⁻¹ := (one_le_inv₀ hq').mpr hq1' + have he' : (1 : ℝ) ≤ (q : ℝ)⁻¹ * expressionValue e := by + calc + 1 = (q : ℝ)⁻¹ * q := (inv_mul_cancel₀ hq'.ne').symm + _ ≤ _ := mul_le_mul_of_nonneg_left he (inv_nonneg.mpr hq'.le) + simp only [scaledLogExpression, expressionValue, positiveLogExpression_value, + rationalExpression_value, Rat.cast_inv, max_eq_right hi, max_eq_right he'] + rw [Real.log_mul (inv_ne_zero hq'.ne') (ne_of_gt (hq'.trans_le he))] + ring + +def sumExpressions (es : List Code) : Code := es.foldr Code.pair .zero +def productExpressions (es : List Code) : Code := es.foldr Code.comp .succ + +@[fun_prop] theorem sumExpressions_computable : Computable sumExpressions := by + exact (Primrec.list_foldr Primrec.id (Primrec.const Code.zero) + ((Code.primrec₂_pair.comp Primrec.fst Primrec.snd).comp Primrec.snd).to₂).to_comp + +@[fun_prop] theorem productExpressions_computable : Computable productExpressions := by + exact (Primrec.list_foldr Primrec.id (Primrec.const Code.succ) + ((Code.primrec₂_comp.comp Primrec.fst Primrec.snd).comp Primrec.snd).to₂).to_comp + +@[simp] theorem sumExpressions_value (es : List Code) : + expressionValue (sumExpressions es) = (es.map expressionValue).sum := by + induction es with + | nil => rfl + | cons e es ih => simpa only [sumExpressions, List.foldr_cons, expressionValue, + List.map_cons, List.sum_cons] using congrArg (expressionValue e + ·) ih + +@[simp] theorem productExpressions_value (es : List Code) : + expressionValue (productExpressions es) = (es.map expressionValue).prod := by + induction es with + | nil => rfl + | cons e es ih => simpa only [productExpressions, List.foldr_cons, expressionValue, + List.map_cons, List.prod_cons] using congrArg (expressionValue e * ·) ih + +end FixedClauseThreshold.Computability.FiniteArithmetic + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ArithmeticEnclosures.lean b/lean/OAI/Probability/SATComputability/ArithmeticEnclosures.lean new file mode 100644 index 0000000000000000000000000000000000000000..23567e5a569793e1f917af6cd2f73df39250bc13 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ArithmeticEnclosures.lean @@ -0,0 +1,151 @@ +import OAI.Probability.SATComputability.EffectiveLog +import OAI.MathematicalPhysics.RapidForcing.ComputableProfiles + +namespace OAI + +namespace FixedClauseThreshold.Computability.FiniteArithmetic + +open Filter RapidForcing.EffectiveProfile RapidForcing.EffectiveArithmetic +open PeriodicLattice.CertifiedReal +open scoped Topology +local instance arithmeticEnclosuresRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +@[fun_prop] theorem rat_max_computable : Computable (fun p : ℚ × ℚ => max p.1 p.2) := by + simpa only [max_def] using + (show Computable (fun p : ℚ × ℚ => if p.1 ≤ p.2 then p.2 else p.1) by fun_prop) + +private theorem exp_effective : Effective (fun q : ℚ => Real.exp (q : ℝ)) := + (rational (Computable.id : Computable (id : ℚ → ℚ))).exp + +private theorem log_effective : Effective (fun q : ℚ => Real.log (max 1 (q : ℝ))) := by + have he : Effective (fun q : ℚ => ((max 1 q : ℚ) : ℝ)) := + rational (show Computable (fun q : ℚ => max 1 q) by fun_prop) + simpa only [Rat.cast_max, Rat.cast_one] using he.log + (fun q => lt_of_lt_of_le (by norm_num : (0 : ℝ) < 1) (by exact_mod_cast le_max_left (1 : ℚ) q)) + +noncomputable def expApprox : ℚ × ℕ → ℚ := Classical.choose exp_effective +noncomputable def logApprox : ℚ × ℕ → ℚ := Classical.choose log_effective + +@[fun_prop] theorem expApprox_computable : Computable expApprox := (Classical.choose_spec exp_effective).1 +@[fun_prop] theorem logApprox_computable : Computable logApprox := (Classical.choose_spec log_effective).1 + +theorem expApprox_error (q : ℚ) (n : ℕ) : + |Real.exp (q : ℝ) - (expApprox (q,n) : ℝ)| ≤ error n := + (Classical.choose_spec exp_effective).2 q n + +theorem logApprox_error (q : ℚ) (n : ℕ) : + |Real.log (max 1 (q : ℝ)) - (logApprox (q,n) : ℝ)| ≤ error n := + (Classical.choose_spec log_effective).2 q n + +noncomputable def interval (l u : ℚ) : Ball := ⟨(l+u)/2, (u-l)/2⟩ + +@[fun_prop] theorem interval_computable : Computable (fun p : ℚ × ℚ => interval p.1 p.2) := by + unfold interval + fun_prop + +theorem interval_covers {l u : ℚ} {x : ℝ} (hl : (l : ℝ) ≤ x) (hu : x ≤ (u : ℝ)) : + (interval l u).Covers x := by + unfold interval Ball.Covers + push_cast + exact abs_le.mpr ⟨by linarith, by linarith⟩ + +theorem interval_encloses {l u : ℕ → ℚ} {x : ℝ} + (hl : ∀ n, (l n : ℝ) ≤ x) (hu : ∀ n, x ≤ (u n : ℝ)) + (htl : Tendsto (fun n => (l n : ℝ)) atTop (nhds x)) + (htu : Tendsto (fun n => (u n : ℝ)) atTop (nhds x)) : + Encloses (fun n => interval (l n) (u n)) x := by + refine ⟨fun n => interval_covers (hl n) (hu n), ?_⟩ + simpa only [interval, Rat.cast_div, Rat.cast_sub, Rat.cast_ofNat, sub_self, zero_div] + using (htu.sub htl).div_const 2 + +theorem approximate_tendsto {f : ℚ → ℝ} {a : ℚ × ℕ → ℚ} + (ha : ∀ q n, |f q - (a (q,n) : ℝ)| ≤ error n) + {q : ℕ → ℚ} {x : ℝ} (hq : Tendsto (fun n => f (q n)) atTop (nhds x)) : + Tendsto (fun n => (a (q n,n) : ℝ)) atTop (nhds x) := by + have hz : Tendsto (fun n => (a (q n,n) : ℝ)-f (q n)) atTop (nhds 0) := by + apply squeeze_zero_norm (fun n => ?_) error_tendsto + simpa only [Real.norm_eq_abs, abs_sub_comm] using ha (q n) n + simpa only [sub_add_cancel, zero_add] using hz.add hq + +noncomputable def expBall (b : Ball) (n : ℕ) : Ball := + interval (expApprox (b.center-b.radius,n)-qerror n) + (expApprox (b.center+b.radius,n)+qerror n) + +noncomputable def logBall (b : Ball) (n : ℕ) : Ball := + interval (logApprox (b.center-b.radius,n)-qerror n) + (logApprox (b.center+b.radius,n)+qerror n) + +@[fun_prop] theorem expBall_computable : Computable (fun p : Ball × ℕ => expBall p.1 p.2) := by + unfold expBall + fun_prop +@[fun_prop] theorem logBall_computable : Computable (fun p : Ball × ℕ => logBall p.1 p.2) := by + unfold logBall + fun_prop + +theorem expBall_covers {b : Ball} {x : ℝ} (hb : b.Covers x) (n : ℕ) : + (expBall b n).Covers (Real.exp x) := by + have he := abs_le.mp hb + have hl := (abs_le.mp (expApprox_error (b.center-b.radius) n)).1 + have hu := (abs_le.mp (expApprox_error (b.center+b.radius) n)).2 + apply interval_covers + · push_cast + have := Real.exp_le_exp.mpr (show (b.center : ℝ)-b.radius ≤ x by linarith) + simp only [Rat.cast_sub, cast_qerror] at hl ⊢ + linarith + · push_cast + have := Real.exp_le_exp.mpr (show x ≤ (b.center : ℝ)+b.radius by linarith) + simp only [Rat.cast_add, cast_qerror] at hu ⊢ + linarith + +theorem logBall_covers {b : Ball} {x : ℝ} (hb : b.Covers x) (n : ℕ) : + (logBall b n).Covers (Real.log (max 1 x)) := by + have he := abs_le.mp hb + have hl := (abs_le.mp (logApprox_error (b.center-b.radius) n)).1 + have hu := (abs_le.mp (logApprox_error (b.center+b.radius) n)).2 + have hp (y : ℝ) : 0 < max 1 y := lt_of_lt_of_le (by norm_num) (le_max_left _ _) + apply interval_covers + · push_cast + have := Real.log_le_log (hp ((b.center : ℝ)-b.radius)) + (max_le_max_left 1 (show (b.center : ℝ)-b.radius ≤ x by linarith)) + simp only [Rat.cast_sub, cast_qerror] at hl ⊢ + linarith + · push_cast + have := Real.log_le_log (hp x) + (max_le_max_left 1 (show x ≤ (b.center : ℝ)+b.radius by linarith)) + simp only [Rat.cast_add, cast_qerror] at hu ⊢ + linarith + +theorem Encloses.exp {b : ℕ → Ball} {x : ℝ} (hb : Encloses b x) : + Encloses (fun n => expBall (b n) n) (Real.exp x) := by + have hbl : Tendsto (fun n => (((b n).center-(b n).radius : ℚ) : ℝ)) atTop (nhds x) := by + simpa only [Rat.cast_sub, sub_zero] using hb.centers.sub hb.2 + have hbu : Tendsto (fun n => (((b n).center+(b n).radius : ℚ) : ℝ)) atTop (nhds x) := by + simpa only [Rat.cast_add, add_zero] using hb.centers.add hb.2 + have hl := approximate_tendsto expApprox_error + (q := fun n => (b n).center-(b n).radius) (Real.continuous_exp.tendsto x |>.comp hbl) + have hu := approximate_tendsto expApprox_error + (q := fun n => (b n).center+(b n).radius) (Real.continuous_exp.tendsto x |>.comp hbu) + refine ⟨fun n => expBall_covers (hb.1 n) n, ?_⟩ + have hlim := ((hu.add error_tendsto).sub (hl.sub error_tendsto)).div_const 2 + simpa only [expBall, interval, Rat.cast_div, Rat.cast_sub, Rat.cast_add, + Rat.cast_ofNat, cast_qerror, add_zero, sub_zero, sub_self, zero_div] using hlim + +theorem Encloses.log {b : ℕ → Ball} {x : ℝ} (hb : Encloses b x) : + Encloses (fun n => logBall (b n) n) (Real.log (max 1 x)) := by + have hp : max (1 : ℝ) x ≠ 0 := ne_of_gt (lt_of_lt_of_le (by norm_num) (le_max_left _ _)) + have hbl : Tendsto (fun n => (((b n).center-(b n).radius : ℚ) : ℝ)) atTop (nhds x) := by + simpa only [Rat.cast_sub, sub_zero] using hb.centers.sub hb.2 + have hbu : Tendsto (fun n => (((b n).center+(b n).radius : ℚ) : ℝ)) atTop (nhds x) := by + simpa only [Rat.cast_add, add_zero] using hb.centers.add hb.2 + have hl := approximate_tendsto logApprox_error + (q := fun n => (b n).center-(b n).radius) ((tendsto_const_nhds.max hbl).log hp) + have hu := approximate_tendsto logApprox_error + (q := fun n => (b n).center+(b n).radius) ((tendsto_const_nhds.max hbu).log hp) + refine ⟨fun n => logBall_covers (hb.1 n) n, ?_⟩ + have hlim := ((hu.add error_tendsto).sub (hl.sub error_tendsto)).div_const 2 + simpa only [logBall, interval, Rat.cast_div, Rat.cast_sub, Rat.cast_add, + Rat.cast_ofNat, cast_qerror, add_zero, sub_zero, sub_self, zero_div] using hlim + +end FixedClauseThreshold.Computability.FiniteArithmetic + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ArithmeticSyntax.lean b/lean/OAI/Probability/SATComputability/ArithmeticSyntax.lean new file mode 100644 index 0000000000000000000000000000000000000000..7a4136df98215e8f020a87d8430e0e4965cf4677 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ArithmeticSyntax.lean @@ -0,0 +1,113 @@ +import OAI.Probability.SATComputability.ArithmeticEnclosures + +namespace OAI + +namespace FixedClauseThreshold.Computability.FiniteArithmetic + +open Encodable Nat.Partrec RapidForcing.EffectiveProfile RapidForcing.EffectiveArithmetic +open PeriodicLattice.CertifiedReal Filter +open scoped Topology +local instance arithmeticSyntaxRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable +local instance arithmeticSyntaxCodeEq : DecidableEq Code := Encodable.decidableEqOfEncodable Code + +noncomputable def clampBall (b : Ball) : Ball := ⟨max 1 b.center, b.radius⟩ + +@[fun_prop] theorem clampBall_computable : Computable clampBall := by + unfold clampBall + fun_prop + +theorem clampBall_covers {b : Ball} {x : ℝ} (hb : b.Covers x) : + (clampBall b).Covers (max 1 x) := by + have h := abs_max_sub_max_le_abs (b.center : ℝ) x 1 + simpa only [clampBall, Ball.Covers, Rat.cast_max, Rat.cast_one, max_comm] using h.trans hb + +theorem encloses_clamp {b : ℕ → Ball} {x : ℝ} (hb : Encloses b x) : + Encloses (fun n => clampBall (b n)) (max 1 x) := + ⟨fun n => clampBall_covers (hb.1 n), hb.2⟩ + +noncomputable def decodedRational (e : Code) : ℚ := (decode (encode e)).getD 0 + +@[fun_prop] theorem decodedRational_computable : Computable decodedRational := by + unfold decodedRational + fun_prop + +noncomputable def expressionValue : Code → ℝ + | .zero => 0 + | .succ => 1 + | .left => 2 + | .right => 3 + | .pair a b => expressionValue a + expressionValue b + | .comp a b => expressionValue a * expressionValue b + | .prec tag b => if tag = .zero then (decodedRational b : ℝ) + else if tag = .succ then Real.exp (expressionValue b) + else if tag = .left then Real.log (max 1 (expressionValue b)) + else (max 1 (expressionValue b))⁻¹ + | .rfind' a => -expressionValue a + +noncomputable def expressionBall : Code → ℕ → Ball + | .zero, _ => Ball.exact 0 + | .succ, _ => Ball.exact 1 + | .left, _ => Ball.exact 2 + | .right, _ => Ball.exact 3 + | .pair a b, n => (expressionBall a n).add (expressionBall b n) + | .comp a b, n => (expressionBall a n).mul (expressionBall b n) + | .prec tag b, n => if tag = .zero then Ball.exact (decodedRational b) + else if tag = .succ then expBall (expressionBall b n) n + else if tag = .left then logBall (expressionBall b n) n + else (clampBall (expressionBall b n)).denInv + | .rfind' a, n => (Ball.exact (-1)).mul (expressionBall a n) + +@[fun_prop] theorem expressionBall_computable : + Computable (fun p : Code × ℕ => expressionBall p.1 p.2) := by + have h := Code.computable_recOn (c := fun p : Code × ℕ => p.1) Computable.fst + (z := fun _ => Ball.exact 0) (by fun_prop) + (s := fun _ => Ball.exact 1) (by fun_prop) + (l := fun _ => Ball.exact 2) (by fun_prop) + (r := fun _ => Ball.exact 3) (by fun_prop) + (pr := fun _ p => p.2.2.1.add p.2.2.2) (by unfold Computable₂; fun_prop) + (co := fun _ p => p.2.2.1.mul p.2.2.2) (by unfold Computable₂; fun_prop) + (pc := fun x p => if p.1 = .zero then Ball.exact (decodedRational p.2.1) + else if p.1 = .succ then expBall p.2.2.2 x.2 + else if p.1 = .left then logBall p.2.2.2 x.2 + else (clampBall p.2.2.2).denInv) (by unfold Computable₂; fun_prop) + (rf := fun _ p => (Ball.exact (-1)).mul p.2) (by unfold Computable₂; fun_prop) + apply h.of_eq + intro p + induction p.1 <;> simp_all only [expressionBall] + +theorem expressionBall_encloses (e : Code) : Encloses (expressionBall e) (expressionValue e) := by + induction e with + | zero => simpa only [expressionBall, expressionValue, Rat.cast_zero] using encloses_exact 0 + | succ => simpa only [expressionBall, expressionValue, Rat.cast_one] using encloses_exact 1 + | left => exact encloses_exact 2 + | right => exact encloses_exact 3 + | pair a b ha hb => exact ha.add hb + | comp a b ha hb => exact ha.mul hb + | prec tag b _ hb => + by_cases hz : tag = .zero + · simpa only [expressionBall, expressionValue, hz, ite_true] using encloses_exact (decodedRational b) + · by_cases he : tag = .succ + · simpa [expressionBall, expressionValue, he] using Encloses.exp hb + · by_cases hl : tag = .left + · simpa [expressionBall, expressionValue, hl] using Encloses.log hb + · simpa only [expressionBall, expressionValue, hz, he, hl, ite_false] using + (encloses_clamp hb).denInv (show (1/16 : ℝ) ≤ max 1 (expressionValue b) from + (by norm_num : (1/16 : ℝ) ≤ 1).trans (le_max_left _ _)) + | rfind' a ha => + simpa only [expressionBall, expressionValue, Rat.cast_neg, Rat.cast_one, neg_one_mul] using + (encloses_exact (-1)).mul ha + +theorem expressionValue_effective : Effective expressionValue := by + apply of_enclosures + (q := fun p => (expressionBall p.1 p.2).center) + (e := fun p => (expressionBall p.1 p.2).radius) + · exact primrec_ball_center.to_comp.comp expressionBall_computable + · exact primrec_ball_radius.to_comp.comp expressionBall_computable + · intro a n + simpa only [Ball.Covers, abs_sub_comm] using (expressionBall_encloses a).1 n + · intro a + exact (expressionBall_encloses a).2 + +end FixedClauseThreshold.Computability.FiniteArithmetic + +end OAI diff --git a/lean/OAI/Probability/SATComputability/AuxiliaryEnergy.lean b/lean/OAI/Probability/SATComputability/AuxiliaryEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..15dbd874fdee53a5f15d343a3656f9c8ad0eb26b --- /dev/null +++ b/lean/OAI/Probability/SATComputability/AuxiliaryEnergy.lean @@ -0,0 +1,131 @@ +import OAI.Probability.SATComputability.RootEnergy +import OAI.Probability.RandomSAT.Transfer +import OAI.Probability.DilutedSpin.RootProductLaw + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped Classical BigOperators NNReal + +theorem finiteClauseAverage_iterate {n m : ℕ} {C : Type*} [Fintype C] + (sat : C → Assignment n → Prop) (S : Finset (Assignment n)) : + ((finiteClauseAverage sat)^[m] alive) S = + uniformMean (fun F : Fin m → C => alive (S.filter (fun s => ∀ j, sat (F j) s))) := by + induction m generalizing S with + | zero => + simp only [Function.iterate_zero_apply, Fin.forall_fin_zero, Finset.filter_true] + exact (uniformMean_const _).symm + | succ m ih => + rw [Function.iterate_succ_apply', finiteClauseAverage, uniformMean_fin_succ] + apply uniformMean_congr + intro c + rw [ih] + apply uniformMean_congr + intro F + congr 1 + ext s + simp only [Finset.mem_filter, Fin.forall_fin_succ, Fin.cons_zero, Fin.cons_succ] + tauto + +def relaxedClauseEquiv (n : ℕ) : RelaxedClause n ≃ AuxiliaryClause n 3 where + toFun c j := (c.1 j, c.2 j) + invFun c := (fun j => (c j).1, fun j => (c j).2) + left_inv _ := rfl + right_inv _ := rfl + +theorem relaxedClauseEquiv_satisfies {n : ℕ} (c : RelaxedClause n) (s : Assignment n) : + auxiliarySatisfies s (relaxedClauseEquiv n c) ↔ + relaxedClauseSatisfied s c.1 c.2 := by + rfl + +theorem clauseMinimum_zero_iff {n m : ℕ} (cs : Fin m → RelaxedClause n) : + clauseMinimum cs = 0 ↔ ∃ s : Assignment n, ∀ j, + relaxedClauseSatisfied s (cs j).1 (cs j).2 := by + constructor + · intro h + obtain ⟨s, hs⟩ := relaxedMinimum_attained (fun j => (cs j).1) (fun j => (cs j).2) + refine ⟨s, ?_⟩ + change relaxedViolations s _ _ = clauseMinimum cs at hs + rw [h] at hs + simpa only [relaxedViolations, Finset.card_eq_zero, Finset.filter_eq_empty_iff, + Finset.mem_univ, true_implies, not_not] using hs + · rintro ⟨s, hs⟩ + have h := relaxedMinimum_le (fun j => (cs j).1) (fun j => (cs j).2) s + have hz : relaxedViolations s (fun j => (cs j).1) (fun j => (cs j).2) = 0 := by + simp only [relaxedViolations, hs, not_true_eq_false, Finset.filter_false, + Finset.card_empty] + exact Nat.eq_zero_of_le_zero (hz ▸ h) + +theorem auxiliaryProbability_eq_minimum (n m : ℕ) : + auxiliaryProbability n 3 m = + uniformMean (fun cs : Fin m → RelaxedClause n => + if clauseMinimum cs = 0 then 1 else 0) := by + unfold auxiliaryProbability auxiliarySurvival auxiliaryAverage embeddedAverage + rw [finiteClauseAverage_iterate] + let e := Equiv.piCongrRight (fun _ : Fin m => relaxedClauseEquiv n) + rw [← uniformMean_equiv e] + apply uniformMean_congr + intro cs + unfold alive + congr 1 + apply propext + rw [clauseMinimum_zero_iff] + simp only [Finset.filter_nonempty_iff, Finset.mem_univ, true_and] + rfl + +theorem integral_rootMinimum_zero (n m : ℕ) [NeZero n] : + (∫ x : RootPath (RelaxedClause n) m, + (if rootMinimum n m x = 0 then (1 : ℝ) else 0) + ∂rootLaw m (fun _ => finiteUniform (RelaxedClause n))) = auxiliaryProbability n 3 m := by + rw [auxiliaryProbability_eq_minimum] + change (∫ x, (if (clauseMinimum (rootArray m x) : ℝ) = 0 then (1 : ℝ) else 0) + ∂rootLaw m (fun _ => finiteUniform (RelaxedClause n))) = _ + simp only [Nat.cast_eq_zero] + rw [integral_rootArray_eq_pi (finiteUniform (RelaxedClause n)) m + (fun cs => if clauseMinimum cs = 0 then (1 : ℝ) else 0), + finiteUniform_pi, integral_finiteUniform] + simp only [uniformMean, smul_eq_mul, div_eq_mul_inv, mul_comm] + +theorem rootSatisfiableProbability_eq_auxiliary (n : ℕ) [NeZero n] (r : ℝ≥0) : + rootSatisfiableProbability n (finiteUniform (RelaxedClause n)) r = + ∫ m : ℕ, auxiliaryProbability n 3 m ∂poissonMeasure r := by + unfold rootSatisfiableProbability poissonRootAverage rootAverage + simp only [integral_rootMinimum_zero] + +noncomputable def relaxedFixedMinimum (n m : ℕ) : ℝ := + uniformMean (fun cs : Fin m → RelaxedClause n => (clauseMinimum cs : ℝ)) + +noncomputable def relaxedPoissonMinimum (n : ℕ) (a : ℝ≥0) : ℝ := + ∫ m : ℕ, relaxedFixedMinimum n m ∂poissonMeasure (a*n) + +theorem relaxedFixedMinimum_nonneg (n m : ℕ) : 0 ≤ relaxedFixedMinimum n m := + uniformMean_nonneg (fun _ => Nat.cast_nonneg _) + +theorem relaxedFixedMinimum_le (n m : ℕ) [NeZero n] : relaxedFixedMinimum n m ≤ m := by + calc + _ ≤ uniformMean (fun _cs : Fin m → RelaxedClause n => (m : ℝ)) := + uniformMean_mono (fun cs => by exact_mod_cast clauseMinimum_le_length cs) + _ = _ := uniformMean_const _ + +theorem relaxedPoissonMinimum_nonneg (n : ℕ) (a : ℝ≥0) : + 0 ≤ relaxedPoissonMinimum n a := integral_nonneg (fun _ => relaxedFixedMinimum_nonneg _ _) + +theorem integral_rootMinimum_eq (n m : ℕ) [NeZero n] : + (∫ x : RootPath (RelaxedClause n) m, rootMinimum n m x + ∂rootLaw m (fun _ => finiteUniform (RelaxedClause n))) = relaxedFixedMinimum n m := by + simp only [rootMinimum] + rw [integral_rootArray_eq_pi (finiteUniform (RelaxedClause n)) m + (fun cs => (clauseMinimum cs : ℝ)), finiteUniform_pi, integral_finiteUniform] + simp only [relaxedFixedMinimum, uniformMean, smul_eq_mul, div_eq_mul_inv, mul_comm] + +theorem poissonRootAverage_minimum_eq (n : ℕ) [NeZero n] (a : ℝ≥0) : + poissonRootAverage (finiteUniform (RelaxedClause n)) (a*n) (rootMinimum n) = + relaxedPoissonMinimum n a := by + unfold poissonRootAverage rootAverage relaxedPoissonMinimum + simp only [integral_rootMinimum_eq] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/BatchKilling.lean b/lean/OAI/Probability/SATComputability/BatchKilling.lean new file mode 100644 index 0000000000000000000000000000000000000000..99e0217b04c8f0119b1560b8c7b281961ca0f975 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/BatchKilling.lean @@ -0,0 +1,78 @@ +import OAI.Probability.SATComputability.ReplacementEstimate + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped BigOperators Classical + +def testKills {n k : ℕ} (U : Finset (DeletionCandidate n)) + (c : Fin k → SignedLiteral n) : Prop := + ∀ x ∈ U, ∀ l, literalFalse x (c l) + +def batchKills {n k d : ℕ} (U : Finset (DeletionCandidate n)) + (cs : Fin d → Fin k → SignedLiteral n) : Prop := + ∀ x ∈ U, ∃ j, ∀ l, literalFalse x (cs j l) + +noncomputable def batchKillProbability {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k d : ℕ) : ℝ := + (FiniteLaw.uniform : FiniteLaw (Fin d → Fin k → SignedLiteral n)).expect + (fun cs => if batchKills U cs then 1 else 0) + +theorem batchKillProbability_ge {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k d : ℕ) : + 1 - (1 - oneTestKill U k)^d ≤ batchKillProbability U k d := by + let f : (Fin k → SignedLiteral n) → ℝ := fun c => if ¬testKills U c then 1 else 0 + have hf : (FiniteLaw.uniform : FiniteLaw (Fin k → SignedLiteral n)).expect f = + 1 - oneTestKill U k := by + have he (c : Fin k → SignedLiteral n) : + f c = 1 - (if testKills U c then 1 else 0) := by + dsimp [f] + by_cases h : testKills U c <;> simp [h] + rw [show f = (fun c => 1 - (if testKills U c then 1 else 0)) from funext he] + rw [FiniteLaw.expect_sub, FiniteLaw.expect_const] + simp only [oneTestKill, testKills] + congr 1 + apply FiniteLaw.expect_congr + intro c + split_ifs with h + · exact ite_eq_left h + · exact ite_eq_right h + have hp : (FiniteLaw.uniform : FiniteLaw (Fin d → Fin k → SignedLiteral n)).expect + (fun cs => ∏ j, f (cs j)) = (1 - oneTestKill U k)^d := by + rw [uniformFiniteLaw_pi] + calc + _ = ∏ _ : Fin d, (FiniteLaw.uniform : FiniteLaw (Fin k → SignedLiteral n)).expect f := + FiniteLaw.expect_pi_product (fun _ => FiniteLaw.uniform) (fun _ => f) + _ = _ := by simp [hf] + have hpoint (cs : Fin d → Fin k → SignedLiteral n) : + 1 - ∏ j, f (cs j) ≤ if batchKills U cs then 1 else 0 := by + dsimp [f] + rw [Fintype.prod_boole] + by_cases h : ∀ j, ¬testKills U (cs j) + · rw [ite_eq_left h, sub_self] + split <;> norm_num + · obtain ⟨j, hj⟩ := not_forall.mp h + have hj' := not_not.mp hj + have hb : batchKills U cs := fun x hx => ⟨j, hj' x hx⟩ + rw [ite_eq_right h, ite_eq_left hb] + norm_num + have hmean := (FiniteLaw.uniform : FiniteLaw (Fin d → Fin k → SignedLiteral n)).expect_mono hpoint + rw [FiniteLaw.expect_sub, FiniteLaw.expect_const, hp] at hmean + exact hmean + +theorem relaxed_one_replacement {n : ℕ} [NeZero n] + {U : Finset (DeletionCandidate n)} (hU : U.Nonempty) {d : ℕ} (hd : 0 < d) : + oneTestKill U 2 - 1 / (d : ℝ)^2 ≤ batchKillProbability U 3 d := by + have hn := frozenFraction_nonneg U + have hh := frozenFraction_le_half hU + have hr := two_to_three_replacement hn hh hd + have hb := batchKillProbability_ge U 3 d + rw [oneTestKill_eq] at hb + rw [oneTestKill_eq] + linarith + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CandidateEncoding.lean b/lean/OAI/Probability/SATComputability/CandidateEncoding.lean new file mode 100644 index 0000000000000000000000000000000000000000..a6e08b72508a1a170faf185a0af5c9b180a271e9 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CandidateEncoding.lean @@ -0,0 +1,62 @@ +import OAI.Probability.SATComputability.RelaxedCandidates +import OAI.Probability.SATComputability.VariableDeletion + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Finset +open scoped Classical + +def encodeDeletion {n : ℕ} (D : Finset (Fin n)) (s : Fin n → Bool) : DeletionCandidate n := + fun v => if v ∈ D then none else some (s v) + +def deletedVariables {n : ℕ} (x : DeletionCandidate n) : Finset (Fin n) := + univ.filter (fun v => x v = none) + +theorem literalFalse_encode {n : ℕ} (D : Finset (Fin n)) (s : Fin n → Bool) + (v : Fin n) (b : Bool) : + ¬literalFalse (encodeDeletion D s) (v, b) ↔ v ∈ D ∨ s v = b := by + by_cases hv : v ∈ D + · simp [literalFalse, encodeDeletion, hv] + · cases hb : s v <;> cases b <;> simp [literalFalse, encodeDeletion, hv, hb] + +theorem deletedVariables_encode {n : ℕ} (D : Finset (Fin n)) (s : Fin n → Bool) : + deletedVariables (encodeDeletion D s) = D := by + ext v + by_cases hv : v ∈ D <;> simp [deletedVariables, encodeDeletion, hv] + +theorem deletionSatisfiable_iff_candidate {n m r : ℕ} + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : + deletionSatisfiable r indices signs ↔ + ∃ x : DeletionCandidate n, (deletedVariables x).card ≤ r ∧ + ∀ j, ∃ l, ¬literalFalse x (indices j l, signs j l) := by + constructor + · rintro ⟨D, hD, s, hs⟩ + refine ⟨encodeDeletion D s, ?_, ?_⟩ + · simpa only [deletedVariables_encode] using hD + · intro j + rcases hs j with ⟨l, hl⟩ | ⟨l, hl⟩ + · exact ⟨l, (literalFalse_encode D s _ _).mpr (Or.inl hl)⟩ + · exact ⟨l, (literalFalse_encode D s _ _).mpr (Or.inr hl)⟩ + · rintro ⟨x, hx, hs⟩ + let D := deletedVariables x + let s : Fin n → Bool := fun v => (x v).getD false + refine ⟨D, hx, s, ?_⟩ + intro j + obtain ⟨l, hl⟩ := hs j + cases hv : x (indices j l) with + | none => + left + exact ⟨l, by simp [D, deletedVariables, hv]⟩ + | some b => + right + refine ⟨l, ?_⟩ + have hb : b = signs j l := by + cases b <;> cases hsign : signs j l <;> + simp_all [literalFalse] + simpa only [s, hv, Option.getD_some] using hb + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CandidateEnergy.lean b/lean/OAI/Probability/SATComputability/CandidateEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..d5f41e1a2e2246b76ab7234a876ed8eaac55f893 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CandidateEnergy.lean @@ -0,0 +1,57 @@ +import OAI.Probability.SATComputability.MeanSurvival + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped Classical NNReal + +theorem candidateStep_minimumDeletions_le {n : ℕ} [NeZero n] (m : ℕ) : + (candidateStep (n := n) 3)^[m] (fun U => (minimumDeletions U : ℝ)) Finset.univ ≤ + relaxedFixedMinimum n m := by + rw [candidateStep_iterate, finite_uniform_expect_eq_mean] + let e := Equiv.piCongrRight (fun _ : Fin m => relaxedClauseEquiv n) + rw [← uniformMean_equiv e] + apply uniformMean_mono + intro cs + exact_mod_cast candidate_minimumDeletions_le cs + +theorem candidateBlock_minimumDeletions_le (n : ℕ) [NeZero n] (a : ℝ≥0) : + (candidateBlock (n := n) (a*n) 3 Finset.univ).expect + (fun U => (minimumDeletions U : ℝ)) ≤ relaxedPoissonMinimum n a := by + rw [candidateBlock_expect, relaxedPoissonMinimum] + apply integral_mono + · simpa only [candidateFixedBlock_expect] using + poissonMixture_integrable_expect (a*n) + (fun m => candidateFixedBlock (n := n) 3 m Finset.univ) + (fun U => (minimumDeletions U : ℝ)) + · apply (poisson_integrable_count (a*n)).mono' + (measurable_of_countable _).aestronglyMeasurable + exact ae_of_all _ (fun m => by + simpa only [Real.norm_eq_abs, abs_of_nonneg (relaxedFixedMinimum_nonneg n m)] using + relaxedFixedMinimum_le n m) + · exact candidateStep_minimumDeletions_le + +theorem mean_lifetime_energy_lower {n r t : ℕ} [NeZero n] + (hr : r ≤ n+1) (ht : 0 < t) (htM : t ≤ 20*n) (a : ℝ≥0) + (hta : (t : ℝ≥0) ≤ a*n) : + (r : ℝ)*(1- + (FiniteLaw.pi (fun _ : Fin (20*n) => candidateBlock (n := n) 1 3 Finset.univ)).expect + (maskLifetime (20*n) (deletionBudgetMask n r)) / t) ≤ + relaxedPoissonMinimum n a := by + have htR : (0 : ℝ) < t := by exact_mod_cast ht + have hs := survival_le_mean_lifetime htM (deletionBudgetMask n r) + have hp := candidateBlock_survival_antitone 3 (deletionBudgetMask n r) hta + have hq : (candidateBlock (n := n) t 3 (deletionBudgetMask n r)).expect candidateAlive ≤ + (FiniteLaw.pi (fun _ : Fin (20*n) => candidateBlock (n := n) 1 3 Finset.univ)).expect + (maskLifetime (20*n) (deletionBudgetMask n r)) / t := + (le_div_iff₀ htR).mpr (by nlinarith only [hs]) + have hb := block_minimumDeletions_lower hr (a*n) + have hm := candidateBlock_minimumDeletions_le n a + exact (mul_le_mul_of_nonneg_left (sub_le_sub_left (hp.trans hq) 1) + (Nat.cast_nonneg r)).trans (hb.trans hm) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CandidateMasks.lean b/lean/OAI/Probability/SATComputability/CandidateMasks.lean new file mode 100644 index 0000000000000000000000000000000000000000..975684bdb875661bad8416fbd8f3aacce516e9f9 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CandidateMasks.lean @@ -0,0 +1,56 @@ +import OAI.Probability.SATComputability.CandidateSurvival + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory +open scoped NNReal Classical + +theorem candidateResidual_inter {n k d : ℕ} (U : Finset (DeletionCandidate n)) + (cs : Fin d → Fin k → SignedLiteral n) : + candidateResidual U cs = U ∩ candidateResidual Finset.univ cs := by + ext x + simp only [candidateResidual, Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and] + +theorem candidateFixedBlock_mask {n : ℕ} [NeZero n] (k d : ℕ) + (U : Finset (DeletionCandidate n)) (f : Finset (DeletionCandidate n) → ℝ) : + (candidateFixedBlock k d Finset.univ).expect (fun V => f (U ∩ V)) = + (candidateFixedBlock k d U).expect f := by + simp only [candidateFixedBlock_expect, candidateStep_iterate] + apply FiniteLaw.expect_congr + intro cs + rw [candidateResidual_inter U cs] + +theorem candidateBlock_mask {n : ℕ} [NeZero n] (r : ℝ≥0) (k : ℕ) + (U : Finset (DeletionCandidate n)) (f : Finset (DeletionCandidate n) → ℝ) : + (candidateBlock r k Finset.univ).expect (fun V => f (U ∩ V)) = + (candidateBlock r k U).expect f := by + simp only [candidateBlock, poissonMixture_expect, candidateFixedBlock_mask] + +noncomputable def maskRun {n : ℕ} : (m : ℕ) → Finset (DeletionCandidate n) → + (Fin m → Finset (DeletionCandidate n)) → Finset (DeletionCandidate n) + | 0, U, _ => U + | m+1, U, xs => maskRun m (U ∩ xs 0) (Fin.tail xs) + +theorem maskRun_law {n : ℕ} [NeZero n] (r : ℝ≥0) (k m : ℕ) + (U : Finset (DeletionCandidate n)) (f : Finset (DeletionCandidate n) → ℝ) : + (FiniteLaw.pi (fun _ : Fin m => candidateBlock r k Finset.univ)).expect + (fun xs => f (maskRun m U xs)) = (candidateBlock (r*m) k U).expect f := by + induction m generalizing U with + | zero => + simp only [maskRun, FiniteLaw.expect_const, Nat.cast_zero, mul_zero] + rw [candidateBlock_expect, integral_poissonMeasure] + simp [zero_pow_eq, ite_div, ite_mul] + | succ m ih => + rw [FiniteLaw.expect_pi_cons] + simp only [maskRun, Fin.cons_zero, Fin.tail_cons, ih] + rw [candidateBlock_mask r k U (fun V => (candidateBlock (r*m) k V).expect f)] + rw [← candidateBlock_comp] + congr 2 + push_cast + ring + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CandidateProbability.lean b/lean/OAI/Probability/SATComputability/CandidateProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..3bdedabf9c80882ad00813e04f3f3e73fb504ba0 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CandidateProbability.lean @@ -0,0 +1,80 @@ +import OAI.Probability.SATComputability.SupercriticalProbability +import OAI.Probability.SATComputability.MaskDeletionTimes + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped Classical NNReal + +theorem candidate_budget_survival {n m r : ℕ} (cs : Fin m → Fin 3 → SignedLiteral n) : + (candidateResidual (deletionBudgetMask n r) cs).Nonempty ↔ + deletionSatisfiable r (fun j l => (cs j l).1) (fun j l => (cs j l).2) := by + rw [deletionSatisfiable_iff_candidate] + simp only [candidateResidual, deletionBudgetMask, Finset.filter_nonempty_iff, + Finset.mem_filter, Finset.mem_univ, true_and, not_forall, Prod.eta] + +theorem candidate_zero_survival {n m : ℕ} (cs : Fin m → Fin 3 → SignedLiteral n) : + (candidateResidual (deletionBudgetMask n 0) cs).Nonempty ↔ + (Finset.univ.filter (fun s : Assignment n => ∀ j, auxiliarySatisfies s (cs j))).Nonempty := by + rw [candidate_budget_survival] + simp only [Finset.filter_nonempty_iff, Finset.mem_univ, true_and] + constructor + · rintro ⟨D,hD,s,hs⟩ + have hD0 : D = ∅ := Finset.card_eq_zero.mp (Nat.eq_zero_of_le_zero hD) + subst D + exact ⟨s,fun j => by simpa [auxiliarySatisfies, relaxedClauseSatisfied] using hs j⟩ + · rintro ⟨s,hs⟩ + exact ⟨∅,by simp,s,fun j => Or.inr (hs j)⟩ + +theorem finite_uniform_expect_eq_mean {A : Type*} [Fintype A] [Nonempty A] (f : A → ℝ) : + (FiniteLaw.uniform : FiniteLaw A).expect f = uniformMean f := by + simp only [FiniteLaw.expect, FiniteLaw.uniform, uniformMean, + div_eq_mul_inv, Finset.sum_mul, mul_comm] + +theorem candidateStep_zero_survival {n : ℕ} [NeZero n] (m : ℕ) : + (candidateStep (n := n) 3)^[m] candidateAlive (deletionBudgetMask n 0) = + auxiliaryProbability n 3 m := by + rw [candidateStep_iterate, finite_uniform_expect_eq_mean] + unfold auxiliaryProbability auxiliarySurvival auxiliaryAverage embeddedAverage + rw [finiteClauseAverage_iterate] + apply uniformMean_congr + intro cs + unfold candidateAlive alive + congr 1 + exact propext (candidate_zero_survival cs) + +theorem candidateBlock_zero_survival {n : ℕ} [NeZero n] (r : ℝ≥0) : + (candidateBlock r 3 (deletionBudgetMask n 0)).expect candidateAlive = + ∫ m : ℕ, auxiliaryProbability n 3 m ∂poissonMeasure r := by + rw [candidateBlock_expect] + simp only [candidateStep_zero_survival] + +theorem candidate_full_nonempty {n m : ℕ} (cs : Fin m → Fin 3 → SignedLiteral n) : + (candidateResidual Finset.univ cs).Nonempty := by + refine ⟨fun _ => none, ?_⟩ + simp only [candidateResidual, Finset.mem_filter, Finset.mem_univ, true_and] + intro j hj + have h := hj 0 + simp [literalFalse] at h + +theorem candidate_minimumDeletions_le {n m : ℕ} (cs : Fin m → RelaxedClause n) : + minimumDeletions (candidateResidual Finset.univ (fun j l => ((cs j).1 l, (cs j).2 l))) ≤ + clauseMinimum cs := by + obtain ⟨s,hs⟩ := relaxedMinimum_attained (fun j => (cs j).1) (fun j => (cs j).2) + have hd := delete_one_per_violation s (fun j => (cs j).1) (fun j => (cs j).2) + change relaxedViolations s (fun j => (cs j).1) (fun j => (cs j).2) = clauseMinimum cs at hs + rw [hs] at hd + rw [deletionSatisfiable_iff_candidate] at hd + obtain ⟨x,hx,hxs⟩ := hd + apply (minimumDeletions_le_iff (candidate_full_nonempty _)).mpr + refine ⟨x, ?_, hx⟩ + simp only [candidateResidual, Finset.mem_filter, Finset.mem_univ, true_and] + intro j hj + obtain ⟨l,hl⟩ := hxs j + exact hl (hj l) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CandidateProcess.lean b/lean/OAI/Probability/SATComputability/CandidateProcess.lean new file mode 100644 index 0000000000000000000000000000000000000000..665093818da37fa861406fe732646ad631f32841 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CandidateProcess.lean @@ -0,0 +1,186 @@ +import OAI.Probability.SATComputability.BatchKilling +import OAI.Probability.DilutedSpin.FiniteProducts +import OAI.Probability.DilutedSpin.FiniteProjection + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped BigOperators Classical + +noncomputable def candidateResidual {n k d : ℕ} (U : Finset (DeletionCandidate n)) + (cs : Fin d → Fin k → SignedLiteral n) : Finset (DeletionCandidate n) := + U.filter (fun x => ∀ j, ¬∀ l, literalFalse x (cs j l)) + +def candidateAlive {n : ℕ} (U : Finset (DeletionCandidate n)) : ℝ := + if U.Nonempty then 1 else 0 + +noncomputable def candidateStep {n : ℕ} [NeZero n] (k : ℕ) + (f : Finset (DeletionCandidate n) → ℝ) (U : Finset (DeletionCandidate n)) : ℝ := + (FiniteLaw.uniform : FiniteLaw (Fin k → SignedLiteral n)).expect + (fun c => f (U.filter (fun x => ¬∀ l, literalFalse x (c l)))) + +theorem candidateResidual_cons {n k d : ℕ} (U : Finset (DeletionCandidate n)) + (c : Fin k → SignedLiteral n) (cs : Fin d → Fin k → SignedLiteral n) : + candidateResidual U (Fin.cons c cs) = + candidateResidual (U.filter (fun x => ¬∀ l, literalFalse x (c l))) cs := by + ext x + simp [candidateResidual, Fin.forall_fin_succ, and_assoc] + +theorem candidateResidual_empty_iff {n k d : ℕ} (U : Finset (DeletionCandidate n)) + (cs : Fin d → Fin k → SignedLiteral n) : + candidateResidual U cs = ∅ ↔ batchKills U cs := by + simp only [candidateResidual, Finset.filter_eq_empty_iff, batchKills] + constructor + · intro h x hx + by_contra hn + apply h hx + intro j hj + exact hn ⟨j, hj⟩ + · intro h x hx hn + obtain ⟨j, hj⟩ := h x hx + exact hn j hj + +theorem candidateStep_mono {n : ℕ} [NeZero n] (k : ℕ) : + Monotone (candidateStep (n := n) k) := by + intro f g h U + exact FiniteLaw.expect_mono _ (fun _ => h _) + +theorem candidateStep_add_const {n : ℕ} [NeZero n] (k : ℕ) + (f : Finset (DeletionCandidate n) → ℝ) (c : ℝ) : + candidateStep k (f + fun _ => c) = candidateStep k f + fun _ => c := by + funext U + exact (FiniteLaw.expect_add _ _ _).trans (by simp [candidateStep, Pi.add_apply]) + +theorem candidateStep_comm {n : ℕ} [NeZero n] (k l : ℕ) : + Function.Commute (candidateStep (n := n) k) (candidateStep l) := by + intro f + funext U + unfold candidateStep + rw [FiniteLaw.expect_comm] + apply FiniteLaw.expect_congr + intro c + apply FiniteLaw.expect_congr + intro d + congr 1 + ext x + simp only [Finset.mem_filter] + tauto + +theorem candidateStep_iterate {n : ℕ} [NeZero n] (k d : ℕ) + (f : Finset (DeletionCandidate n) → ℝ) (U : Finset (DeletionCandidate n)) : + (candidateStep k)^[d] f U = + (FiniteLaw.uniform : FiniteLaw (Fin d → Fin k → SignedLiteral n)).expect + (fun cs => f (candidateResidual U cs)) := by + induction d generalizing U with + | zero => simp [candidateResidual, FiniteLaw.expect, FiniteLaw.uniform] + | succ d ih => + rw [Function.iterate_succ_apply', candidateStep] + simp_rw [ih] + conv_rhs => rw [uniformFiniteLaw_pi, FiniteLaw.expect_pi_cons] + rw [← uniformFiniteLaw_pi] + apply FiniteLaw.expect_congr + intro c + apply FiniteLaw.expect_congr + intro cs + rw [candidateResidual_cons] + +theorem candidateKill_iterate {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k d : ℕ) : + batchKillProbability U k d = 1 - (candidateStep k)^[d] candidateAlive U := by + rw [candidateStep_iterate] + have he (cs : Fin d → Fin k → SignedLiteral n) : + (if batchKills U cs then (1 : ℝ) else 0) = + 1 - candidateAlive (candidateResidual U cs) := by + rw [candidateAlive, ← candidateResidual_empty_iff] + by_cases h : candidateResidual U cs = ∅ + · simp [h] + · simp [h, Finset.nonempty_iff_ne_empty] + simp_rw [batchKillProbability, he, FiniteLaw.expect_sub, FiniteLaw.expect_const] + +theorem operator_iterate_add_const {X : Type*} (A : (X → ℝ) → X → ℝ) + (hA : ∀ f c, A (f + fun _ => c) = A f + fun _ => c) + (m : ℕ) (f : X → ℝ) (c : ℝ) : + A^[m] (f + fun _ => c) = A^[m] f + fun _ => c := by + induction m with + | zero => rfl + | succ m ih => rw [Function.iterate_succ_apply', ih, hA, Function.iterate_succ_apply'] + +theorem operator_replacement {X : Type*} (A B : (X → ℝ) → X → ℝ) + (hA : Monotone A) (hB : Monotone B) + (hAc : ∀ f c, A (f + fun _ => c) = A f + fun _ => c) + (hBc : ∀ f c, B (f + fun _ => c) = B f + fun _ => c) + (hcomm : Function.Commute A B) (f : X → ℝ) (δ : ℝ) + (hone : A f ≤ B f + fun _ => δ) (d : ℕ) : + A^[d] f ≤ B^[d] f + fun _ => (d : ℝ)*δ := by + induction d with + | zero => intro x; simp + | succ d ih => + have h₁ := hA.iterate d hone + rw [operator_iterate_add_const A hAc, hcomm.iterate_left d f] at h₁ + have h₂ := hB ih + rw [hBc, ← Function.iterate_succ_apply' B d f] at h₂ + intro x + have h₁x := h₁ x + have h₂x := h₂ x + simp only [Pi.add_apply] at h₁x h₂x + rw [Function.iterate_succ_apply] + change A^[d] (A f) x ≤ B^[d+1] f x + ((d+1 : ℕ) : ℝ)*δ + push_cast + linarith + +theorem relaxed_sequential_replacement {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) {d : ℕ} (hd : 0 < d) (L : ℕ) : + batchKillProbability U 2 L - (L : ℝ)/(d : ℝ)^2 ≤ + batchKillProbability U 3 (L*d) := by + have hone : (candidateStep (n := n) 3)^[d] candidateAlive ≤ + candidateStep 2 candidateAlive + fun _ => 1/(d : ℝ)^2 := by + intro V + by_cases hV : V.Nonempty + · have h := relaxed_one_replacement hV hd + have he : batchKillProbability V 2 1 = oneTestKill V 2 := by + rw [candidateKill_iterate, Function.iterate_one, candidateStep] + unfold oneTestKill + rw [← FiniteLaw.expect_const (FiniteLaw.uniform : FiniteLaw (Fin 2 → SignedLiteral n)) 1, + ← FiniteLaw.expect_sub] + apply FiniteLaw.expect_congr + intro c + have hf : (V.filter (fun x => ¬∀ l, literalFalse x (c l))).Nonempty ↔ + ¬testKills V c := by + constructor + · rintro ⟨x, hx⟩ hk + exact (Finset.mem_filter.mp hx).2 (hk x (Finset.mem_filter.mp hx).1) + · intro hk + by_contra he + apply hk + intro x hx + by_contra hh + exact he ⟨x, Finset.mem_filter.mpr ⟨hx, hh⟩⟩ + simp only [FiniteLaw.expect_const] + by_cases hc : ∀ x ∈ V, ∀ l, literalFalse x (c l) + · have he : ¬(V.filter (fun x => ¬∀ l, literalFalse x (c l))).Nonempty := + fun hne => (hf.mp hne) hc + rw [candidateAlive, ite_eq_right he, ite_eq_left hc] + norm_num + · have he : (V.filter (fun x => ¬∀ l, literalFalse x (c l))).Nonempty := hf.mpr hc + rw [candidateAlive, ite_eq_left he, ite_eq_right hc] + norm_num + rw [← he, candidateKill_iterate, candidateKill_iterate, Function.iterate_one] at h + exact (by dsimp only [Pi.add_apply]; linarith) + · have he : V = ∅ := Finset.not_nonempty_iff_eq_empty.mp hV + subst V + simp [candidateStep_iterate, candidateStep, candidateResidual, candidateAlive] + have h := operator_replacement (candidateStep (n := n) 3)^[d] (candidateStep 2) + ((candidateStep_mono 3).iterate d) (candidateStep_mono 2) + (operator_iterate_add_const _ (candidateStep_add_const 3) d) + (candidateStep_add_const 2) ((candidateStep_comm 3 2).iterate_left d) + candidateAlive (1/(d : ℝ)^2) hone L U + rw [← Function.iterate_mul, Nat.mul_comm d L] at h + rw [candidateKill_iterate, candidateKill_iterate] + simp only [Pi.add_apply, mul_one_div] at h + linarith + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CandidateSurvival.lean b/lean/OAI/Probability/SATComputability/CandidateSurvival.lean new file mode 100644 index 0000000000000000000000000000000000000000..bea144b558139d1a7ae02a914531fb25851d185f --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CandidateSurvival.lean @@ -0,0 +1,143 @@ +import OAI.Probability.SATComputability.PoissonSemigroup +import OAI.Probability.SATComputability.MarkovOccupation + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal + +theorem candidateResidual_subset {n k d : ℕ} (U : Finset (DeletionCandidate n)) + (cs : Fin d → Fin k → SignedLiteral n) : candidateResidual U cs ⊆ U := by + classical + exact Finset.filter_subset _ _ + +theorem candidateResidual_mono {n k d : ℕ} {U V : Finset (DeletionCandidate n)} + (h : U ⊆ V) (cs : Fin d → Fin k → SignedLiteral n) : + candidateResidual U cs ⊆ candidateResidual V cs := by + classical + exact Finset.filter_subset_filter _ h + +theorem candidateAlive_mono {n : ℕ} : + Monotone (candidateAlive (n := n)) := by + intro U V h + unfold candidateAlive + split_ifs with hU hV + · rfl + · exact (hV (hU.mono h)).elim + · norm_num + · rfl + +theorem candidateBlock_expect_mono_state {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) {f : Finset (DeletionCandidate n) → ℝ} + (hf : Monotone f) : Monotone (fun U => (candidateBlock r k U).expect f) := by + intro U V hUV + simp only [candidateBlock, poissonMixture_expect] + apply integral_mono (poissonMixture_integrable_expect r + (fun d => candidateFixedBlock k d U) f) + (poissonMixture_integrable_expect r (fun d => candidateFixedBlock k d V) f) + intro d + simp only [candidateFixedBlock_expect, candidateStep_iterate] + exact FiniteLaw.expect_mono _ (fun cs => hf (candidateResidual_mono hUV cs)) + +theorem candidateBlock_expect_le_of_subset {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) + (f g : Finset (DeletionCandidate n) → ℝ) + (h : ∀ V ⊆ U, f V ≤ g V) : + (candidateBlock r k U).expect f ≤ (candidateBlock r k U).expect g := by + simp only [candidateBlock, poissonMixture_expect] + apply integral_mono (poissonMixture_integrable_expect r _ f) + (poissonMixture_integrable_expect r _ g) + intro d + simp only [candidateFixedBlock_expect, candidateStep_iterate] + exact FiniteLaw.expect_mono _ (fun cs => h _ (candidateResidual_subset U cs)) + +theorem candidateBlock_expect_alive {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) : + (candidateBlock r k U).expect candidateAlive = 1 - poissonKillProbability U k r := by + have he : candidateAlive (n := n) = fun V => 1 - (if V = ∅ then 1 else 0) := by + classical + funext V + by_cases h : V = ∅ <;> simp [candidateAlive, h, Finset.nonempty_iff_ne_empty] + rw [he, FiniteLaw.expect_sub, FiniteLaw.expect_const, candidateBlock_kill] + +theorem candidateBlock_empty {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) (f : Finset (DeletionCandidate n) → ℝ) : + (candidateBlock r k ∅).expect f = f ∅ := by + simp only [candidateBlock_expect, candidateStep_iterate, candidateResidual, + Finset.filter_empty, FiniteLaw.expect_const, integral_const, probReal_univ, one_smul] + +theorem candidateBlock_survival_le {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) : + (candidateBlock r k U).expect candidateAlive ≤ candidateAlive U := by + apply (candidateBlock_expect_le_of_subset r k U candidateAlive + (fun _ => candidateAlive U) (fun _ h => candidateAlive_mono h)).trans_eq + exact FiniteLaw.expect_const _ _ + +theorem candidateBlock_survival_submultiplicative {n : ℕ} [NeZero n] + (r s : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) : + (candidateBlock (r+s) k U).expect candidateAlive ≤ + (candidateBlock r k U).expect candidateAlive * + (candidateBlock s k U).expect candidateAlive := by + rw [candidateBlock_comp] + calc + _ ≤ (candidateBlock r k U).expect (fun V => + candidateAlive V * (candidateBlock s k U).expect candidateAlive) := by + apply candidateBlock_expect_le_of_subset + intro V hV + by_cases h : V.Nonempty + · simpa only [candidateAlive, ite_eq_left h, one_mul] using + candidateBlock_expect_mono_state s k candidateAlive_mono hV + · have he : V = ∅ := Finset.not_nonempty_iff_eq_empty.mp h + subst V + simp [candidateBlock_empty, candidateAlive] + _ = _ := FiniteLaw.expect_mul_right _ _ _ + +theorem candidateBlock_survival_geometric {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) + {δ : ℝ} (hδ : δ ≤ poissonKillProbability U k r) (m : ℕ) : + (candidateBlock (r*m) k U).expect candidateAlive ≤ (1-δ)^m := by + have hs := FiniteLaw.expect_nonneg (candidateBlock r k U) candidateAlive_nonneg + have hb : (candidateBlock r k U).expect candidateAlive ≤ 1-δ := by + rw [candidateBlock_expect_alive] + linarith + have hd : 0 ≤ 1-δ := hs.trans hb + induction m with + | zero => simp [candidateBlock_expect, integral_poissonMeasure, zero_pow_eq, ite_div, ite_mul, + candidateAlive_le_one] + | succ m ih => + have he : r * ((m+1 : ℕ) : ℝ≥0) = r*m+r := by push_cast; ring + rw [he, pow_succ] + exact (candidateBlock_survival_submultiplicative (r*m) r k U).trans + (mul_le_mul ih hb hs (pow_nonneg hd m)) + +theorem candidateBlock_occupation {n : ℕ} [NeZero n] + (r : ℝ≥0) (k L M : ℕ) (bin : Finset (DeletionCandidate n) → Prop) + [DecidablePred bin] {δ : ℝ} (hδ : 0 < δ) + (hbin : ∀ U, bin U → U.Nonempty ∧ δ ≤ poissonKillProbability U k (r*L)) + (U : Finset (DeletionCandidate n)) : + (∑ t ∈ Finset.range M, + (candidateBlock (r*t) k U).expect (fun V => if bin V then 1 else 0)) ≤ + (L : ℝ)/δ := by + have hi (m : ℕ) (f : Finset (DeletionCandidate n) → ℝ) : + (finiteKernelStep (candidateBlock r k))^[m] f U = + (candidateBlock (r*m) k U).expect f := poissonCandidateStep_iterate r k m U f + have h := finiteKernel_occupation (candidateBlock r k) candidateAlive + (fun V => if bin V then 1 else 0) candidateAlive_nonneg candidateAlive_le_one hδ L + (fun V => ?_) M U + · simpa only [hi] using h + · change δ * (if bin V then 1 else 0) ≤ candidateAlive V - + (poissonCandidateStep r k)^[L] candidateAlive V + rw [poissonCandidateStep_iterate] + by_cases hb : bin V + · obtain ⟨hne, hk⟩ := hbin V hb + rw [ite_eq_left hb, mul_one, candidateAlive, ite_eq_left hne, + candidateBlock_expect_alive] + linarith + · rw [ite_eq_right hb, mul_zero] + exact sub_nonneg.mpr (candidateBlock_survival_le _ _ _) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CavityExpressions.lean b/lean/OAI/Probability/SATComputability/CavityExpressions.lean new file mode 100644 index 0000000000000000000000000000000000000000..4f99d27534d465fbb6721860370533abb94c0c83 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CavityExpressions.lean @@ -0,0 +1,205 @@ +import OAI.Probability.SATComputability.PhysicalExpressions +import OAI.Probability.DilutedSpin.CavityBounds + +namespace OAI + +namespace FixedClauseThreshold.Computability.FiniteArithmetic + +open Nat.Partrec DilutedSpinGlass RapidForcing.EffectiveArithmetic +open scoped BigOperators +local instance cavityExpressionsRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +noncomputable def boltzmannAtom {p : ℕ} (θ : ℚ) (xs : Fin p → Code) + (s : Fin p → Bool) : Code := + .pair (rationalExpression θ) + (sumExpressions (List.ofFn (fun i => logQExpression (xs i) (s i)))) + +@[fun_prop] theorem boltzmannAtom_computable (p : ℕ) : + Computable (fun a : ℚ × (Fin p → Code) × (Fin p → Bool) => + boltzmannAtom a.1 a.2.1 a.2.2) := by + have hv : Computable (fun a : ℚ × (Fin p → Code) × (Fin p → Bool) => + List.ofFn (fun i => logQExpression (a.2.1 i) (a.2.2 i))) := by + apply Computable.list_ofFn + intro i + fun_prop + unfold boltzmannAtom + fun_prop + +theorem exp_boltzmannAtom {p : ℕ} (θ : ℚ) (xs : Fin p → Code) (s : Fin p → Bool) : + Real.exp (expressionValue (boltzmannAtom θ xs s)) = + Real.exp (θ : ℝ) * ∏ i, q (expressionValue (xs i)) (s i) := by + simp only [boltzmannAtom, expressionValue, rationalExpression_value, + sumExpressions_value, List.map_ofFn, List.sum_ofFn, Function.comp_def, + Real.exp_add, Real.exp_sum, exp_logQExpression] + +def clausePenalty (β : ℚ) (J s : Fin 3 → Bool) : ℚ := + if ∀ i, s i ≠ J i then -β else 0 + +@[fun_prop] theorem clausePenalty_computable : + Computable (fun p : ℚ × (Fin 3 → Bool) × (Fin 3 → Bool) => + clausePenalty p.1 p.2.1 p.2.2) := by + have h : Computable (fun p : ℚ × (Fin 3 → Bool) × (Fin 3 → Bool) => + if p.2.2 0 ≠ p.2.1 0 ∧ p.2.2 1 ≠ p.2.1 1 ∧ p.2.2 2 ≠ p.2.1 2 + then -p.1 else 0) := by fun_prop + exact h.of_eq (fun p => by simp [clausePenalty, Fin.forall_fin_succ]) + +theorem clausePenalty_cast (β : ℚ) (J s : Fin 3 → Bool) : + (clausePenalty β J s : ℝ) = satInteraction (β : ℝ) J s := by + unfold clausePenalty satInteraction + split <;> simp + +theorem sum_bool_vector_succ {p : ℕ} (f : (Fin (p+1) → Bool) → ℝ) : + (∑ s, f s) = + (∑ t : Fin p → Bool, f (Fin.cons false t)) + + ∑ t : Fin p → Bool, f (Fin.cons true t) := by + rw [← (Fin.consEquiv (fun _ : Fin (p+1) => Bool)).sum_comp, Fintype.sum_prod_type] + simp only [Fintype.sum_bool] + exact add_comm _ _ + +noncomputable def edgeExpression (β : ℚ) (J : Fin 3 → Bool) (xs : Fin 3 → Code) : Code := + binaryLogSumExpression + (binaryLogSumExpression + (binaryLogSumExpression (boltzmannAtom (clausePenalty β J ![false,false,false]) xs ![false,false,false]) + (boltzmannAtom (clausePenalty β J ![false,false,true]) xs ![false,false,true])) + (binaryLogSumExpression (boltzmannAtom (clausePenalty β J ![false,true,false]) xs ![false,true,false]) + (boltzmannAtom (clausePenalty β J ![false,true,true]) xs ![false,true,true]))) + (binaryLogSumExpression + (binaryLogSumExpression (boltzmannAtom (clausePenalty β J ![true,false,false]) xs ![true,false,false]) + (boltzmannAtom (clausePenalty β J ![true,false,true]) xs ![true,false,true])) + (binaryLogSumExpression (boltzmannAtom (clausePenalty β J ![true,true,false]) xs ![true,true,false]) + (boltzmannAtom (clausePenalty β J ![true,true,true]) xs ![true,true,true]))) + +@[fun_prop] theorem edgeExpression_computable : + Computable (fun p : ℚ × (Fin 3 → Bool) × (Fin 3 → Code) => + edgeExpression p.1 p.2.1 p.2.2) := by + unfold edgeExpression + fun_prop + +theorem exp_edgeExpression (β : ℚ) (J : Fin 3 → Bool) (xs : Fin 3 → Code) : + Real.exp (expressionValue (edgeExpression β J xs)) = + edge (satInteraction (β : ℝ) J) (fun i => expressionValue (xs i)) := by + unfold edgeExpression edge + simp only [exp_binaryLogSumExpression, exp_boltzmannAtom, clausePenalty_cast] + rw [sum_bool_vector_succ] + simp_rw [sum_bool_vector_succ] + simp only [Fintype.sum_unique] + rfl + +theorem edgeExpression_value (β : ℚ) (J : Fin 3 → Bool) (xs : Fin 3 → Code) : + expressionValue (edgeExpression β J xs) = + Real.log (edge (satInteraction (β : ℝ) J) (fun i => expressionValue (xs i))) := by + rw [← exp_edgeExpression, Real.log_exp] + +@[fun_prop] theorem spinsThree_computable : + Computable (fun p : Bool × Bool × Bool => ![p.1,p.2.1,p.2.2]) := by + apply computable_fin_lambda + intro i + fin_cases i <;> simp only [Matrix.cons_val_zero', Matrix.cons_val_succ'] + all_goals fun_prop + +def extendSpins (a b ε : Bool) : Fin 3 → Bool := ![a,b,ε] + +@[fun_prop] theorem extendSpins_computable : + Computable (fun p : Bool × Bool × Bool => extendSpins p.1 p.2.1 p.2.2) := + spinsThree_computable + +noncomputable def messageExpression (β : ℚ) (J : Fin 3 → Bool) + (xs : Fin 2 → Code) (ε : Bool) : Code := + binaryLogSumExpression + (binaryLogSumExpression + (boltzmannAtom (clausePenalty β J (extendSpins false false ε)) xs ![false,false]) + (boltzmannAtom (clausePenalty β J (extendSpins false true ε)) xs ![false,true])) + (binaryLogSumExpression + (boltzmannAtom (clausePenalty β J (extendSpins true false ε)) xs ![true,false]) + (boltzmannAtom (clausePenalty β J (extendSpins true true ε)) xs ![true,true])) + +@[fun_prop] theorem messageExpression_computable : + Computable (fun p : ℚ × (Fin 3 → Bool) × (Fin 2 → Code) × Bool => + messageExpression p.1 p.2.1 p.2.2.1 p.2.2.2) := by + unfold messageExpression + fun_prop + +theorem appendSpin_three (a b ε : Bool) : + appendSpin (p := 3) ![a,b] ε = ![a,b,ε] := by + funext i + fin_cases i <;> rfl + +theorem messageExpression_value (β : ℚ) (J : Fin 3 → Bool) + (xs : Fin 2 → Code) (ε : Bool) : + expressionValue (messageExpression β J xs ε) = + message (satInteraction (β : ℝ) J) (fun i => expressionValue (xs i)) ε := by + rw [← Real.log_exp (expressionValue (messageExpression β J xs ε))] + unfold messageExpression message + congr 1 + simp only [exp_binaryLogSumExpression, exp_boltzmannAtom, clausePenalty_cast] + simp_rw [sum_bool_vector_succ] + simp only [Fintype.sum_unique] + have ht (a b : Bool) (t : Fin 0 → Bool) : Fin.cons a (Fin.cons b t) = ![a,b] := by + funext i + fin_cases i <;> rfl + simp only [ht, appendSpin_three, extendSpins] + +abbrev SiteExpressionDatum := (Fin 3 → Bool) × (Fin 2 → Code) + +noncomputable def siteExpression (β : ℚ) (data : List SiteExpressionDatum) : Code := + binaryLogMeanExpression + (sumExpressions (data.map (fun z => messageExpression β z.1 z.2 false))) + (sumExpressions (data.map (fun z => messageExpression β z.1 z.2 true))) + +@[fun_prop] theorem siteExpression_computable : + Computable (fun p : ℚ × List SiteExpressionDatum => siteExpression p.1 p.2) := by + have hm (ε : Bool) : Computable (fun p : ℚ × List SiteExpressionDatum => + p.2.map (fun z => messageExpression p.1 z.1 z.2 ε)) := by + apply computable_list_map Computable.snd + unfold Computable₂ + fun_prop + unfold siteExpression + fun_prop + +theorem siteExpression_value (β : ℚ) (data : List SiteExpressionDatum) : + expressionValue (siteExpression β data) = + siteLog (fun j : Fin data.length => satSample (β : ℝ) (data.get j).1) 0 + (fun i => expressionValue ((data.get i.1).2 i.2)) := by + have hs (ε : Bool) : (data.map (fun z => + message (satInteraction (β : ℝ) z.1) (fun i => expressionValue (z.2 i)) ε)).sum = + ∑ j : Fin data.length, message (satInteraction (β : ℝ) (data.get j).1) + (fun i => expressionValue ((data.get j).2 i)) ε := by + rw [← List.sum_ofFn] + have h := congrArg (fun ds : List SiteExpressionDatum => + (ds.map (fun z => message (satInteraction (β : ℝ) z.1) + (fun i => expressionValue (z.2 i)) ε)).sum) (List.ofFn_get data) + simpa only [List.map_ofFn, Function.comp_def] using h.symm + simp only [siteExpression, binaryLogMeanExpression_value, sumExpressions_value, + List.map_map, Function.comp_def, messageExpression_value, hs] + simp only [siteLog, zero_mul, zero_add, satSample, Fintype.sum_bool] + congr 2 + exact add_comm _ _ + +attribute [local irreducible] edgeExpression siteExpression + +theorem edgeExpression_comp {A : Type} [Primcodable A] + (β : A → ℚ) (J : A → Fin 3 → Bool) (xs : A → Fin 3 → Code) + (hβ : Computable β) (hJ : Computable J) (hx : Computable xs) : + Computable (fun a => edgeExpression (β a) (J a) (xs a)) := by + exact edgeExpression_computable.comp (hβ.pair (hJ.pair hx)) + +theorem siteExpression_comp {A : Type} [Primcodable A] + (β : A → ℚ) (data : A → List SiteExpressionDatum) + (hβ : Computable β) (hd : Computable data) : + Computable (fun a => siteExpression (β a) (data a)) := by + exact siteExpression_computable.comp (hβ.pair hd) + +theorem siteExpression_ofFn_value {k : ℕ} (β : ℚ) + (J : Fin k → Fin 3 → Bool) (xs : Fin k → Fin 2 → Code) : + expressionValue (siteExpression β (List.ofFn (fun j => (J j,xs j)))) = + siteLog (fun j => satSample (β : ℝ) (J j)) 0 + (fun i => expressionValue (xs i.1 i.2)) := by + simp only [siteExpression, binaryLogMeanExpression_value, sumExpressions_value, + List.map_ofFn, List.sum_ofFn, Function.comp_def, messageExpression_value] + simp only [siteLog, zero_mul, zero_add, satSample, Fintype.sum_bool] + congr 2 + exact add_comm _ _ + +end FixedClauseThreshold.Computability.FiniteArithmetic + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CertificateSearch.lean b/lean/OAI/Probability/SATComputability/CertificateSearch.lean new file mode 100644 index 0000000000000000000000000000000000000000..570e74ae9797730b920a6dcb9842b0945f7db9f1 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CertificateSearch.lean @@ -0,0 +1,105 @@ +import OAI.MathematicalPhysics.RapidForcing.RatOperations +import Mathlib.Computability.PartrecCode + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Filter +open scoped Topology +open RapidForcing.EffectiveArithmetic + +def tolerance (r : ℕ) : ℚ := (2 ^ r : ℚ)⁻¹ + +@[fun_prop] +theorem tolerance_computable : Computable tolerance := by + unfold tolerance + fun_prop + +theorem tolerance_pos (r : ℕ) : 0 < tolerance r := by + unfold tolerance + positivity + +def certificateTest (lower upper : ℕ → ℚ) (valid : ℕ → Bool) + (r n : ℕ) : Option ℚ := + let i := n.unpair.1 + let j := n.unpair.2 + if valid j = true ∧ upper j - lower i ≤ 2 * tolerance r then + some ((lower i + upper j) / 2) + else none + +theorem certificateTest_computable {lower upper : ℕ → ℚ} {valid : ℕ → Bool} + (hl : Computable lower) (hu : Computable upper) (hv : Computable valid) : + Computable₂ (certificateTest lower upper valid) := by + unfold Computable₂ certificateTest + fun_prop + +def certificateProgram (lower upper : ℕ → ℚ) (valid : ℕ → Bool) + (r : ℕ) : Part ℚ := + Nat.rfindOpt (certificateTest lower upper valid r) + +theorem certificateProgram_partrec {lower upper : ℕ → ℚ} {valid : ℕ → Bool} + (hl : Computable lower) (hu : Computable upper) (hv : Computable valid) : + Partrec (certificateProgram lower upper valid) := + Partrec.rfindOpt (certificateTest_computable hl hu hv) + +theorem certificateTest_sound {α : ℝ} {lower upper : ℕ → ℚ} {valid : ℕ → Bool} + (hl : ∀ i, (lower i : ℝ) ≤ α) + (hu : ∀ j, valid j = true → α ≤ (upper j : ℝ)) + {r n : ℕ} {q : ℚ} (hq : q ∈ certificateTest lower upper valid r n) : + |(q : ℝ) - α| ≤ (tolerance r : ℝ) := by + dsimp only [certificateTest] at hq + split_ifs at hq with h + · obtain rfl := Option.mem_some_iff.mp hq + have hlo := hl n.unpair.1 + have hup := hu n.unpair.2 h.1 + have hwidth : (upper n.unpair.2 : ℝ) - lower n.unpair.1 ≤ + 2 * (tolerance r : ℝ) := by exact_mod_cast h.2 + push_cast + apply abs_le.mpr + constructor <;> linarith + · contradiction + +theorem certificateProgram_total {α : ℝ} {lower upper : ℕ → ℚ} {valid : ℕ → Bool} + (hl : ∀ ε : ℝ, 0 < ε → ∃ i, α - ε < (lower i : ℝ)) + (hu : ∀ ε : ℝ, 0 < ε → ∃ j, valid j = true ∧ (upper j : ℝ) < α + ε) + (r : ℕ) : (certificateProgram lower upper valid r).Dom := by + have hε : (0 : ℝ) < tolerance r := by exact_mod_cast tolerance_pos r + obtain ⟨i, hi⟩ := hl (tolerance r) hε + obtain ⟨j, hj, hj'⟩ := hu (tolerance r) hε + apply Nat.rfindOpt_dom.mpr + refine ⟨Nat.pair i j, (lower i + upper j) / 2, ?_⟩ + have hwidth : upper j - lower i ≤ 2 * tolerance r := by + have : (upper j : ℝ) - lower i ≤ 2 * (tolerance r : ℝ) := by linarith + exact_mod_cast this + simp [certificateTest, hj, hwidth] + +theorem finite_certificate_search {α : ℝ} + {lower upper : ℕ → ℚ} {valid : ℕ → Bool} + (hlc : Computable lower) (huc : Computable upper) (hvc : Computable valid) + (hls : ∀ i, (lower i : ℝ) ≤ α) + (hus : ∀ j, valid j = true → α ≤ (upper j : ℝ)) + (hld : ∀ ε : ℝ, 0 < ε → ∃ i, α - ε < (lower i : ℝ)) + (hud : ∀ ε : ℝ, 0 < ε → ∃ j, valid j = true ∧ (upper j : ℝ) < α + ε) : + ∃ q : ℕ → ℚ, Computable q ∧ + (∀ r, q r ∈ certificateProgram lower upper valid r) ∧ + ∀ r, |(q r : ℝ) - α| ≤ (2 ^ r : ℝ)⁻¹ := by + let total := certificateProgram_total hld hud + let q := fun r => (certificateProgram lower upper valid r).get (total r) + have hq (r : ℕ) : q r ∈ certificateProgram lower upper valid r := Part.get_mem _ + refine ⟨q, (certificateProgram_partrec hlc huc hvc).of_eq_tot hq, hq, ?_⟩ + intro r + obtain ⟨n, hn⟩ := Nat.rfindOpt_spec (hq r) + simpa only [tolerance, Rat.cast_inv, Rat.cast_pow, Rat.cast_ofNat] using + certificateTest_sound hls hus hn + +theorem rational_sequence_code {q : ℕ → ℚ} (hq : Computable q) : + ∃ c : Nat.Partrec.Code, ∀ r, + Nat.Partrec.Code.eval c r = Part.some (Encodable.encode (q r)) := by + have hencode := Computable.encode.comp hq + obtain ⟨c, hc⟩ := Nat.Partrec.Code.exists_code.mp (Partrec.nat_iff.mp hencode) + exact ⟨c, fun r => congrFun hc r⟩ + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ClassMasks.lean b/lean/OAI/Probability/SATComputability/ClassMasks.lean new file mode 100644 index 0000000000000000000000000000000000000000..de915c9e10c075bdce8d65fb4f0b5f8afbb15779 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ClassMasks.lean @@ -0,0 +1,101 @@ +import OAI.Probability.SATComputability.ClauseClasses + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open scoped Classical + +def classClause {n : ℕ} (c : TripleClasses (SignedLiteral n)) : Fin 3 → SignedLiteral (n+1) := + (clauseClassesEquiv n).symm c + +noncomputable def classBaseMask {n : ℕ} : TripleClasses (SignedLiteral n) → Finset (DeletionCandidate n) + | .inl c => clauseMask ((tripleVectorEquiv _).symm c) + | .inr _ => Finset.univ + +noncomputable def classIncidentMask {n : ℕ} (v : Bool) : + TripleClasses (SignedLiteral n) → Finset (DeletionCandidate n) + | .inl _ => Finset.univ + | .inr (.inl (_,b,c,d)) => if v = b then Finset.univ else clauseMask ![c,d] + | .inr (.inr (.inl (_,a,b,c))) => if v = a ∨ v = b then Finset.univ else clauseMask ![c] + | .inr (.inr (.inr (a,b,c))) => if v = a ∨ v = b ∨ v = c then Finset.univ else ∅ + +theorem classClause_base {n : ℕ} (c : Triple (SignedLiteral n)) : + classClause (.inl c) = fun j => liftLiteral ((tripleVectorEquiv _).symm c j) := by + funext j + fin_cases j <;> rfl + +theorem literalFalse_distinguished {n : ℕ} (x : DeletionCandidate n) (v : Option Bool) (b : Bool) : + literalFalse (restoreCandidate v x) (0,b) ↔ v = some (!b) := Iff.rfl + +theorem literalFalse_restored {n : ℕ} (x : DeletionCandidate n) (v : Option Bool) + (l : SignedLiteral n) : + literalFalse (restoreCandidate v x) (liftLiteral l) ↔ literalFalse x l := Iff.rfl + +theorem classClause_restored_base {n : ℕ} (c : Triple (SignedLiteral n)) : + clauseMask (classClause (.inl c)) = restoredMask (classBaseMask (.inl c)) + (classIncidentMask false (.inl c)) (classIncidentMask true (.inl c)) := by + rw [classClause_base] + ext x + simp only [clauseMask_lift, classBaseMask, classIncidentMask, restoredMask, + Finset.mem_filter, Finset.mem_univ, true_and] + cases x 0 with + | none => simp + | some b => cases b <;> simp + +theorem classClause_restored_single {n : ℕ} (i : Fin 3) (b : Bool) + (c d : SignedLiteral n) : + clauseMask (classClause (.inr (.inl (i,b,c,d)))) = + restoredMask (classBaseMask (.inr (.inl (i,b,c,d)))) + (classIncidentMask false (.inr (.inl (i,b,c,d)))) + (classIncidentMask true (.inr (.inl (i,b,c,d)))) := by + ext x + have hx : restoreCandidate (x 0) (Fin.tail x) = x := Fin.cons_self_tail x + conv_lhs => rw [← hx] + fin_cases i <;> cases b <;> rcases h0 : x 0 with _ | (_ | _) + all_goals simp [classClause, clauseClassesEquiv, tripleClassesEquiv, joinTriple, + tripleVectorEquiv, literalSplitEquiv, Equiv.arrowCongr, classBaseMask, + classIncidentMask, restoredMask, clauseMask, literalFalse, restoreCandidate, + Fin.forall_fin_succ, Fin.tail_def, h0, Bool.not_false, Bool.not_true] + +theorem classClause_restored_double {n : ℕ} (i : Fin 3) (a b : Bool) + (c : SignedLiteral n) : + clauseMask (classClause (.inr (.inr (.inl (i,a,b,c))))) = + restoredMask (classBaseMask (.inr (.inr (.inl (i,a,b,c))))) + (classIncidentMask false (.inr (.inr (.inl (i,a,b,c))))) + (classIncidentMask true (.inr (.inr (.inl (i,a,b,c))))) := by + ext x + have hx : restoreCandidate (x 0) (Fin.tail x) = x := Fin.cons_self_tail x + conv_lhs => rw [← hx] + fin_cases i <;> cases a <;> cases b <;> rcases h0 : x 0 with _ | (_ | _) + all_goals simp [classClause, clauseClassesEquiv, tripleClassesEquiv, joinTriple, + tripleVectorEquiv, literalSplitEquiv, Equiv.arrowCongr, classBaseMask, + classIncidentMask, restoredMask, clauseMask, literalFalse, restoreCandidate, + Fin.forall_fin_succ, Fin.tail_def, h0, Bool.not_false, Bool.not_true] + +theorem classClause_restored_triple {n : ℕ} (a b c : Bool) : + clauseMask (classClause (n := n) (.inr (.inr (.inr (a,b,c))))) = + restoredMask (classBaseMask (.inr (.inr (.inr (a,b,c))))) + (classIncidentMask false (.inr (.inr (.inr (a,b,c))))) + (classIncidentMask true (.inr (.inr (.inr (a,b,c))))) := by + ext x + have hx : restoreCandidate (x 0) (Fin.tail x) = x := Fin.cons_self_tail x + conv_lhs => rw [← hx] + cases a <;> cases b <;> cases c <;> rcases h0 : x 0 with _ | (_ | _) + all_goals simp [classClause, clauseClassesEquiv, tripleClassesEquiv, joinTriple, + tripleVectorEquiv, literalSplitEquiv, Equiv.arrowCongr, classBaseMask, + classIncidentMask, restoredMask, clauseMask, literalFalse, restoreCandidate, + Fin.forall_fin_succ, Fin.tail_def, h0, Bool.not_false, Bool.not_true] + +theorem classClause_restored {n : ℕ} (c : TripleClasses (SignedLiteral n)) : + clauseMask (classClause c) = restoredMask (classBaseMask c) + (classIncidentMask false c) (classIncidentMask true c) := by + rcases c with c | (⟨i,b,c,d⟩ | (⟨i,a,b,c⟩ | ⟨a,b,c⟩)) + · exact classClause_restored_base c + · exact classClause_restored_single i b c d + · exact classClause_restored_double i a b c + · exact classClause_restored_triple a b c + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ClauseClasses.lean b/lean/OAI/Probability/SATComputability/ClauseClasses.lean new file mode 100644 index 0000000000000000000000000000000000000000..e8f1605d266078c84493eff2fdd2e8ccc78512f5 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ClauseClasses.lean @@ -0,0 +1,87 @@ +import OAI.Probability.SATComputability.ClauseRestoration + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open scoped Classical + +abbrev Triple (A : Type*) := A × A × A +abbrev TripleClasses (A : Type*) := + Triple A ⊕ (Fin 3 × Bool × A × A) ⊕ (Fin 3 × Bool × Bool × A) ⊕ Triple Bool + +def splitTriple {A : Type*} : Triple (Bool ⊕ A) → TripleClasses A + | (.inr a,.inr b,.inr c) => .inl (a,b,c) + | (.inl a,.inr b,.inr c) => .inr (.inl (0,a,b,c)) + | (.inr a,.inl b,.inr c) => .inr (.inl (1,b,a,c)) + | (.inr a,.inr b,.inl c) => .inr (.inl (2,c,a,b)) + | (.inr a,.inl b,.inl c) => .inr (.inr (.inl (0,b,c,a))) + | (.inl a,.inr b,.inl c) => .inr (.inr (.inl (1,a,c,b))) + | (.inl a,.inl b,.inr c) => .inr (.inr (.inl (2,a,b,c))) + | (.inl a,.inl b,.inl c) => .inr (.inr (.inr (a,b,c))) + +def joinTriple {A : Type*} : TripleClasses A → Triple (Bool ⊕ A) + | .inl (a,b,c) => (.inr a,.inr b,.inr c) + | .inr (.inl (i,b,a,c)) => + if i = 0 then (.inl b,.inr a,.inr c) + else if i = 1 then (.inr a,.inl b,.inr c) + else (.inr a,.inr c,.inl b) + | .inr (.inr (.inl (i,a,b,c))) => + if i = 0 then (.inr c,.inl a,.inl b) + else if i = 1 then (.inl a,.inr c,.inl b) + else (.inl a,.inl b,.inr c) + | .inr (.inr (.inr (a,b,c))) => (.inl a,.inl b,.inl c) + +def tripleClassesEquiv (A : Type*) : Triple (Bool ⊕ A) ≃ TripleClasses A where + toFun := splitTriple + invFun := joinTriple + left_inv := by + rintro ⟨a,b,c⟩ + cases a <;> cases b <;> cases c <;> rfl + right_inv := by + rintro (⟨a,b,c⟩ | (⟨i,a,b,c⟩ | (⟨i,a,b,c⟩ | ⟨a,b,c⟩))) + · rfl + · fin_cases i <;> rfl + · fin_cases i <;> rfl + · rfl + +def literalSplitEquiv (n : ℕ) : SignedLiteral (n+1) ≃ Bool ⊕ SignedLiteral n where + toFun l := Fin.cases (.inl l.2) (fun j => .inr (j,l.2)) l.1 + invFun := fun l => match l with + | .inl b => (0,b) + | .inr (j,b) => (j.succ,b) + left_inv := by + rintro ⟨i,b⟩ + refine Fin.cases rfl (fun j => ?_) i + rfl + right_inv := by + rintro (b | ⟨j,b⟩) <;> rfl + +def tripleVectorEquiv (A : Type*) : (Fin 3 → A) ≃ Triple A where + toFun f := (f 0,f 1,f 2) + invFun t := ![t.1,t.2.1,t.2.2] + left_inv := by intro f; funext i; fin_cases i <;> rfl + right_inv := by rintro ⟨a,b,c⟩; rfl + +def clauseClassesEquiv (n : ℕ) : (Fin 3 → SignedLiteral (n+1)) ≃ TripleClasses (SignedLiteral n) := + (Equiv.arrowCongr (Equiv.refl _) (literalSplitEquiv n)).trans + ((tripleVectorEquiv _).trans (tripleClassesEquiv _)) + +theorem clauseClasses_base_card (n : ℕ) : + Fintype.card (Triple (SignedLiteral n)) = 8*n^3 := by + simp [Triple, SignedLiteral, Fintype.card_prod, Fintype.card_fin] + ring + +theorem clauseClasses_single_card (n : ℕ) : + Fintype.card (Fin 3 × Bool × SignedLiteral n × SignedLiteral n) = 24*n^2 := by + simp [SignedLiteral, Fintype.card_prod, Fintype.card_fin] + ring + +theorem clauseClasses_double_card (n : ℕ) : + Fintype.card (Fin 3 × Bool × Bool × SignedLiteral n) = 24*n := by + simp [SignedLiteral, Fintype.card_prod, Fintype.card_fin] + ring + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ClauseProcess.lean b/lean/OAI/Probability/SATComputability/ClauseProcess.lean new file mode 100644 index 0000000000000000000000000000000000000000..4608d0055eacb3256aebc75f52bde86b22cc2e08 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ClauseProcess.lean @@ -0,0 +1,79 @@ +import OAI.Probability.SATComputability.ActiveMaskCounts +import OAI.Probability.SATComputability.PoissonGrid +import OAI.Probability.SATComputability.FiniteProductPushforward + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators Classical NNReal + +theorem countsMask_restored {A : Type*} [Fintype A] {n : ℕ} + (B F T : A → Finset (DeletionCandidate n)) (c : A → ℕ) : + countsMask (fun a => restoredMask (B a) (F a) (T a)) c = + restoredMask (countsMask B c) (countsMask F c) (countsMask T c) := by + ext x + simp only [countsMask, restoredMask, Finset.mem_filter, Finset.mem_univ, true_and] + rcases x 0 with _ | (_ | _) + all_goals simp only [and_true, or_and_left, forall_and] + +def splitActiveGrid (n M : ℕ) : ActiveClause n × Fin M ≃ + (Triple (SignedLiteral n) × Fin M) ⊕ + ((IncidentClass n × Fin M) ⊕ (IncidentClass n × Fin M)) where + toFun p := match p.1 with + | .inl a => .inl (a,p.2) + | .inr (false,a) => .inr (.inl (a,p.2)) + | .inr (true,a) => .inr (.inr (a,p.2)) + invFun p := match p with + | .inl (a,j) => (.inl a,j) + | .inr (.inl (a,j)) => (.inr (false,a),j) + | .inr (.inr (a,j)) => (.inr (true,a),j) + left_inv := by rintro ⟨a,j⟩; rcases a with a | ⟨(_ | _),a⟩ <;> rfl + right_inv := by rintro (⟨a,j⟩ | (⟨a,j⟩ | ⟨a,j⟩)) <;> rfl + +noncomputable def maskGrid {A : Type*} [Fintype A] {n M : ℕ} + (mask : A → Finset (DeletionCandidate n)) (c : A × Fin M → ℕ) : + Fin M → Finset (DeletionCandidate n) := fun j => countsMask mask (fun a => c (a,j)) + +local instance clauseProcessCandidateMeasurable (n : ℕ) : + MeasurableSpace (DeletionCandidate n) := ⊤ +local instance clauseProcessCandidateSingleton (n : ℕ) : + MeasurableSingletonClass (DeletionCandidate n) := ⟨fun _ => trivial⟩ + +noncomputable def gridMaskLaw {A : Type*} [Fintype A] {n : ℕ} + (M : ℕ) (r : ℝ≥0) (mask : A → Finset (DeletionCandidate n)) : + FiniteLaw (Fin M → Finset (DeletionCandidate n)) := + finitePushforward (poissonCountLaw (A × Fin M) r) (maskGrid mask) + (measurable_of_countable _) + +theorem gridMaskLaw_expect {A : Type*} [Fintype A] {n M : ℕ} + (r : ℝ≥0) (mask : A → Finset (DeletionCandidate n)) + (f : (Fin M → Finset (DeletionCandidate n)) → ℝ) : + (gridMaskLaw M r mask).expect f = + ∫ c, f (maskGrid mask c) ∂poissonCountLaw (A × Fin M) r := + finitePushforward_expect _ _ _ _ + +theorem gridMaskLaw_frontload {A : Type*} [Fintype A] {n M : ℕ} + (r : ℝ≥0) (mask : A → Finset (DeletionCandidate n)) + (f : Finset (DeletionCandidate n) → ℝ) : + (gridMaskLaw M r mask).expect (fun xs => f (frontloadMask xs)) = + ∫ c, f (countsMask mask c) ∂poissonCountLaw A (M*r) := by + rw [gridMaskLaw_expect] + have hfront (c : A × Fin M → ℕ) : frontloadMask (maskGrid mask c) = + countsMask mask (fun a => ∑ j, c (a,j)) := + frontload_countsMask mask (fun j a => c (a,j)) + simp only [hfront] + rw [← poissonCountLaw_uncurry_integral] + have hh := poissonCountLaw_row_sums (A := A) (B := Fin M) r + have h := integral_map (φ := fun c : A → Fin M → ℕ => fun a => ∑ j, c a j) + (μ := Measure.pi (fun _ : A => poissonCountLaw (Fin M) r)) + (f := fun c => f (countsMask mask c)) + (measurable_of_countable _).aemeasurable + (measurable_of_countable _).aestronglyMeasurable + rw [hh] at h + simpa only [Fintype.card_fin] using h.symm + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ClauseRestoration.lean b/lean/OAI/Probability/SATComputability/ClauseRestoration.lean new file mode 100644 index 0000000000000000000000000000000000000000..1ecba8b9d02e29e81298c4af9c94ab1f39050e87 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ClauseRestoration.lean @@ -0,0 +1,91 @@ +import OAI.Probability.SATComputability.RestoredCandidates + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped Classical + +noncomputable def clauseMask {n k : ℕ} (c : Fin k → SignedLiteral n) : + Finset (DeletionCandidate n) := + Finset.univ.filter (fun x => ¬∀ l, literalFalse x (c l)) + +def liftLiteral {n : ℕ} (l : SignedLiteral n) : SignedLiteral (n+1) := (l.1.succ,l.2) + +def touchesDistinguished {n k : ℕ} (c : Fin k → SignedLiteral (n+1)) : Prop := + ∃ l, (c l).1 = 0 + +noncomputable def baseClauseMask {n k : ℕ} (c : Fin k → SignedLiteral (n+1)) : + Finset (DeletionCandidate n) := + if touchesDistinguished c then Finset.univ else + Finset.univ.filter (fun x => restoreCandidate none x ∈ clauseMask c) + +noncomputable def incidentClauseMask {n k : ℕ} (c : Fin k → SignedLiteral (n+1)) + (b : Bool) : Finset (DeletionCandidate n) := + if touchesDistinguished c then + Finset.univ.filter (fun x => restoreCandidate (some b) x ∈ clauseMask c) + else Finset.univ + +theorem literalFalse_lift {n : ℕ} (x : DeletionCandidate (n+1)) (l : SignedLiteral n) : + literalFalse x (liftLiteral l) ↔ literalFalse (Fin.tail x) l := Iff.rfl + +theorem clauseMask_lift {n k : ℕ} (x : DeletionCandidate (n+1)) + (c : Fin k → SignedLiteral n) : + x ∈ clauseMask (fun l => liftLiteral (c l)) ↔ Fin.tail x ∈ clauseMask c := by + simp only [clauseMask, Finset.mem_filter, Finset.mem_univ, true_and, literalFalse_lift] + +theorem clauseMask_forget_zero {n k : ℕ} (c : Fin k → SignedLiteral (n+1)) + (hc : ¬ touchesDistinguished c) (x : DeletionCandidate (n+1)) (b : Option Bool) : + restoreCandidate b (Fin.tail x) ∈ clauseMask c ↔ x ∈ clauseMask c := by + have hn (l : Fin k) : (c l).1 ≠ 0 := fun h => hc ⟨l,h⟩ + have hl (l : Fin k) : + literalFalse (restoreCandidate b (Fin.tail x)) (c l) ↔ literalFalse x (c l) := by + obtain ⟨j,hj⟩ := Fin.exists_succ_eq_of_ne_zero (hn l) + simp only [literalFalse, restoreCandidate, ← hj, Fin.cons_succ, Fin.tail_def] + simp only [clauseMask, Finset.mem_filter, Finset.mem_univ, true_and, hl] + +theorem clauseMask_deleted_zero {n k : ℕ} (c : Fin k → SignedLiteral (n+1)) + (hc : touchesDistinguished c) (x : DeletionCandidate n) : + restoreCandidate none x ∈ clauseMask c := by + obtain ⟨l,hl⟩ := hc + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _, ?_⟩ + intro h + have he := h l + simp [literalFalse, restoreCandidate, hl] at he + +theorem clauseMask_restored {n k : ℕ} (c : Fin k → SignedLiteral (n+1)) : + clauseMask c = restoredMask (baseClauseMask c) + (incidentClauseMask c false) (incidentClauseMask c true) := by + ext x + by_cases hc : touchesDistinguished c + · simp only [baseClauseMask, incidentClauseMask, ite_eq_left hc, restoredMask, + Finset.mem_filter, Finset.mem_univ, true_and] + have he : restoreCandidate (x 0) (Fin.tail x) = x := Fin.cons_self_tail x + cases hx : x 0 with + | none => + apply iff_true_intro + have hm := clauseMask_deleted_zero c hc (Fin.tail x) + have he' : restoreCandidate none (Fin.tail x) = x := by simpa only [hx] using he + exact he' ▸ hm + | some b => + have he' : restoreCandidate (some b) (Fin.tail x) = x := by + simpa only [hx] using he + cases b + · change (x ∈ clauseMask c) ↔ (restoreCandidate (some false) (Fin.tail x) ∈ clauseMask c) + exact (congrArg (fun y => y ∈ clauseMask c) he').symm.to_iff + · change (x ∈ clauseMask c) ↔ (restoreCandidate (some true) (Fin.tail x) ∈ clauseMask c) + exact (congrArg (fun y => y ∈ clauseMask c) he').symm.to_iff + + · have he := clauseMask_forget_zero c hc x none + simp only [baseClauseMask, incidentClauseMask, ite_eq_right hc, restoredMask, + Finset.mem_filter, Finset.mem_univ, true_and] + cases x 0 with + | none => simpa only [and_true] using he.symm + | some b => + cases b <;> simpa only [and_true] using he.symm + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/CompiledTrials.lean b/lean/OAI/Probability/SATComputability/CompiledTrials.lean new file mode 100644 index 0000000000000000000000000000000000000000..e4dd07da9c71e629e40d9a4cd2f3df956514057b --- /dev/null +++ b/lean/OAI/Probability/SATComputability/CompiledTrials.lean @@ -0,0 +1,85 @@ +import OAI.Probability.SATComputability.EffectiveTrialValues +import OAI.Probability.SATComputability.UpperCertificates + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass Nat.Partrec PeriodicLattice.CertifiedReal +open scoped NNReal + +local instance compiledTrialsRatPrimcodable : Primcodable ℚ := + PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +noncomputable def decodeTrial (j : ℕ) : TrialData := + (Encodable.decode j).getD (0,0,.zero,[]) + +@[fun_prop] theorem decodeTrial_computable : Computable decodeTrial := by + unfold decodeTrial + fun_prop + +theorem decodeTrial_encode (t : TrialData) : decodeTrial (Encodable.encode t) = t := by + simp [decodeTrial] + +noncomputable def trialDataValid (t : TrialData) : Bool := + decide (0 < t.1 ∧ 0 < t.2.1) && exponentCheck t.2.2.2 + +@[fun_prop] theorem trialDataValid_computable : Computable trialDataValid := by + unfold trialDataValid + fun_prop + +theorem trialDataValid_iff (t : TrialData) : trialDataValid t = true ↔ + 0 < t.1 ∧ 0 < t.2.1 ∧ exponentCheck t.2.2.2 = true := by + simp only [trialDataValid, Bool.and_eq_true, decide_eq_true_eq, and_assoc] + +private noncomputable def trialApproximation : TrialData × ℕ → ℚ := + Classical.choose trialValue_effective + +private theorem trialApproximation_computable : Computable trialApproximation := + (Classical.choose_spec trialValue_effective).1 + +private theorem trialApproximation_error (t : TrialData) (s : ℕ) : + |trialValue t - (trialApproximation (t,s) : ℝ)| ≤ error s := + (Classical.choose_spec trialValue_effective).2 t s + +noncomputable def satTrialEvaluation : TrialEvaluation where + density j := (decodeTrial j).1 + valid j := trialDataValid (decodeTrial j) + value j := trialValue (decodeTrial j) + approximate p := trialApproximation (decodeTrial p.1, 2^p.2) + density_computable := by fun_prop + valid_computable := by fun_prop + approximate_computable := trialApproximation_computable.comp (by fun_prop) + density_positive j hj := ((trialDataValid_iff _).mp hj).1 + approximation_error j s _ := by + rw [abs_sub_comm] + apply (trialApproximation_error _ _).trans + simp only [error, tolerance, Rat.cast_inv, Rat.cast_pow, Rat.cast_ofNat] + rw [one_div] + apply inv_anti₀ (by positivity) + push_cast + exact le_add_of_nonneg_right (by norm_num) + +theorem satTrialEvaluation_valid {j : ℕ} (hj : satTrialEvaluation.valid j = true) : + 0 < (decodeTrial j).1 ∧ 0 < (decodeTrial j).2.1 ∧ + exponentCheck (decodeTrial j).2.2.2 = true := + (trialDataValid_iff _).mp hj + +theorem satTrialEvaluation_penalty {j : ℕ} (hj : satTrialEvaluation.valid j = true) : + 0 < (decodeTrial j).2.1 := (satTrialEvaluation_valid hj).2.1 + +theorem satTrialEvaluation_bound {j : ℕ} (hj : satTrialEvaluation.valid j = true) : + satPressure (trialDensityNN (decodeTrial j)) ((decodeTrial j).2.1 : ℝ) ≤ + satTrialEvaluation.value j := by + have ht := satTrialEvaluation_valid hj + change _ ≤ trialValue (decodeTrial j) + rw [trialValue_eq_functional _ ht.2.2] + apply satPressure_le_rational_trial + · change (0 : ℝ) < (max 0 (decodeTrial j).1 : ℚ) + exact_mod_cast lt_max_of_lt_right ht.1 + · exact_mod_cast ht.2.1 + · exact (exponentCheck_iff _).mp ht.2.2 + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DeletionEnergy.lean b/lean/OAI/Probability/SATComputability/DeletionEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..3bd78d9035792ce38b8341372b187a56f9e5f28a --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DeletionEnergy.lean @@ -0,0 +1,66 @@ +import OAI.Probability.SATComputability.DeletionHistory + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped Classical + +theorem encode_deletedVariables {n : ℕ} (x : DeletionCandidate n) : + encodeDeletion (deletedVariables x) (fun v => (x v).getD false) = x := by + funext v + cases hx : x v <;> simp [encodeDeletion, deletedVariables, hx] + +noncomputable def minimumDeletions {n : ℕ} (U : Finset (DeletionCandidate n)) : ℕ := + if h : U.Nonempty then U.inf' h (fun x => (deletedVariables x).card) else n+1 + +theorem minimumDeletions_le_iff {n r : ℕ} {U : Finset (DeletionCandidate n)} + (hU : U.Nonempty) : minimumDeletions U ≤ r ↔ + ∃ x ∈ U, (deletedVariables x).card ≤ r := by + rw [minimumDeletions, dite_eq_left hU] + exact Finset.inf'_le_iff hU + +theorem DeletionHistory.best_nonneg {n M r : ℕ} (H : DeletionHistory n M) : + 0 ≤ bestDeletionTime H.realStop r := by + have h0 : (0 : ℝ) ≤ H.realStop ∅ := Nat.cast_nonneg _ + apply h0.trans + exact Finset.le_sup' _ (by simp [allowedDeletions]) + +theorem DeletionHistory.minimumDeletions_lower {n M t r : ℕ} + (H : DeletionHistory n M) (ht : 0 < t) (hr : r ≤ n) : + (r : ℝ) * (1 - bestDeletionTime H.realStop r / t) ≤ + minimumDeletions (H.state t) := by + have ht0 : (0 : ℝ) < t := by exact_mod_cast ht + have hfrac : 0 ≤ bestDeletionTime H.realStop r / t := + div_nonneg H.best_nonneg ht0.le + have hmul : (r : ℝ) * (1 - bestDeletionTime H.realStop r / t) ≤ r := by + nlinarith [show (0 : ℝ) ≤ r from Nat.cast_nonneg r] + by_cases hU : (H.state t).Nonempty + · by_cases hmin : minimumDeletions (H.state t) ≤ r + · obtain ⟨x, hx, hxr⟩ := (minimumDeletions_le_iff hU).mp hmin + have hs : candidateSurvives (H.state t) (deletedVariables x) := + ⟨fun v => (x v).getD false, by simpa only [encode_deletedVariables] using hx⟩ + have htime := H.survival_le_best hxr hs + have hratio : 1 ≤ bestDeletionTime H.realStop r / t := + (le_div_iff₀ ht0).mpr (by simpa using htime.le) + have hnonpos : (r : ℝ) * (1 - bestDeletionTime H.realStop r / t) ≤ 0 := + mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg r) (by linarith) + exact hnonpos.trans (Nat.cast_nonneg _) + · have hm : (r : ℝ) ≤ minimumDeletions (H.state t) := by + exact_mod_cast (Nat.le_of_lt (Nat.lt_of_not_ge hmin)) + exact hmul.trans hm + · rw [minimumDeletions, dite_eq_right hU] + exact hmul.trans (by exact_mod_cast (hr.trans (Nat.le_succ n))) + +theorem mean_minimumDeletions_lower {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) + {n M t r : ℕ} (H : Ω → DeletionHistory n M) (ht : 0 < t) (hr : r ≤ n) : + (r : ℝ) * (1 - P.expect (fun ω => bestDeletionTime (H ω).realStop r) / t) ≤ + P.expect (fun ω => (minimumDeletions ((H ω).state t) : ℝ)) := by + have h := P.expect_mono (fun ω => (H ω).minimumDeletions_lower ht hr) + simpa only [FiniteLaw.expect_mul_left, FiniteLaw.expect_sub, + FiniteLaw.expect_const, FiniteLaw.expect_div] using h + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DeletionHistory.lean b/lean/OAI/Probability/SATComputability/DeletionHistory.lean new file mode 100644 index 0000000000000000000000000000000000000000..db6466df7e0fa8a5be40825acf4a94a366fbdf98 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DeletionHistory.lean @@ -0,0 +1,118 @@ +import OAI.Probability.SATComputability.CandidateProcess +import OAI.Probability.SATComputability.CandidateEncoding +import OAI.Probability.SATComputability.DeletionIncrement + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Finset +open scoped Classical + +def eraseCandidate {n : ℕ} (D : Finset (Fin n)) (x : DeletionCandidate n) : + DeletionCandidate n := fun v => if v ∈ D then none else x v + +def DeletionClosed {n : ℕ} (U : Finset (DeletionCandidate n)) : Prop := + ∀ x ∈ U, ∀ D : Finset (Fin n), eraseCandidate D x ∈ U + +theorem literalFalse_of_erase {n : ℕ} {D : Finset (Fin n)} + {x : DeletionCandidate n} {l : SignedLiteral n} + (h : literalFalse (eraseCandidate D x) l) : literalFalse x l := by + by_cases hl : l.1 ∈ D + · simp [literalFalse, eraseCandidate, hl] at h + · simpa only [literalFalse, eraseCandidate, ite_eq_right hl] using h + +theorem candidateResidual_deletionClosed {n k d : ℕ} + {U : Finset (DeletionCandidate n)} (hU : DeletionClosed U) + (cs : Fin d → Fin k → SignedLiteral n) : + DeletionClosed (candidateResidual U cs) := by + intro x hx D + obtain ⟨hxU, hx⟩ := Finset.mem_filter.mp hx + apply Finset.mem_filter.mpr + refine ⟨hU x hxU D, ?_⟩ + intro j hj + exact hx j (fun l => literalFalse_of_erase (hj l)) + +def candidateSurvives {n : ℕ} (U : Finset (DeletionCandidate n)) + (D : Finset (Fin n)) : Prop := ∃ s : Fin n → Bool, encodeDeletion D s ∈ U + +theorem eraseCandidate_encode {n : ℕ} {D E : Finset (Fin n)} (hDE : D ⊆ E) + (s : Fin n → Bool) : eraseCandidate E (encodeDeletion D s) = encodeDeletion E s := by + funext v + by_cases hv : v ∈ E + · simp [eraseCandidate, encodeDeletion, hv] + · have hD : v ∉ D := fun h => hv (hDE h) + simp [eraseCandidate, encodeDeletion, hv, hD] + +theorem candidateSurvives_mono {n : ℕ} {U : Finset (DeletionCandidate n)} + (hU : DeletionClosed U) {D E : Finset (Fin n)} (hDE : D ⊆ E) + (hD : candidateSurvives U D) : candidateSurvives U E := by + obtain ⟨s, hs⟩ := hD + refine ⟨s, ?_⟩ + simpa only [eraseCandidate_encode hDE s] using hU _ hs E + +theorem candidateSurvives_subset {n : ℕ} {U V : Finset (DeletionCandidate n)} + (hUV : U ⊆ V) {D : Finset (Fin n)} (hU : candidateSurvives U D) : + candidateSurvives V D := by + obtain ⟨s, hs⟩ := hU + exact ⟨s, hUV hs⟩ + +structure DeletionHistory (n M : ℕ) where + state : ℕ → Finset (DeletionCandidate n) + antitone : Antitone state + closed : ∀ t, DeletionClosed (state t) + capped : state M = ∅ + +theorem DeletionHistory.failure_exists {n M : ℕ} (H : DeletionHistory n M) + (D : Finset (Fin n)) : ∃ t, ¬candidateSurvives (H.state t) D := by + refine ⟨M, ?_⟩ + simp [H.capped, candidateSurvives] + +noncomputable def DeletionHistory.stop {n M : ℕ} (H : DeletionHistory n M) + (D : Finset (Fin n)) : ℕ := Nat.find (H.failure_exists D) + +theorem DeletionHistory.stop_le_cap {n M : ℕ} (H : DeletionHistory n M) + (D : Finset (Fin n)) : H.stop D ≤ M := + Nat.find_min' _ (by simp [H.capped, candidateSurvives]) + +theorem DeletionHistory.before_stop_iff {n M t : ℕ} (H : DeletionHistory n M) + (D : Finset (Fin n)) : t < H.stop D ↔ candidateSurvives (H.state t) D := by + constructor + · intro ht + exact Classical.not_not.mp (Nat.find_min (H.failure_exists D) ht) + · intro ht + by_contra hn + have hf : ¬candidateSurvives (H.state (H.stop D)) D := + Nat.find_spec (H.failure_exists D) + exact hf (candidateSurvives_subset (H.antitone (Nat.le_of_not_gt hn)) ht) + +theorem DeletionHistory.stop_mono {n M : ℕ} (H : DeletionHistory n M) : + Monotone H.stop := by + intro D E hDE + by_contra hn + have hd := (H.before_stop_iff D).mp (Nat.lt_of_not_ge hn) + have he := candidateSurvives_mono (H.closed (H.stop E)) hDE hd + exact Nat.find_spec (H.failure_exists E) he + +noncomputable def DeletionHistory.realStop {n M : ℕ} (H : DeletionHistory n M) + (D : Finset (Fin n)) : ℝ := H.stop D + +theorem DeletionHistory.realStop_mono {n M : ℕ} (H : DeletionHistory n M) : + Monotone H.realStop := by + intro D E hDE + change (H.stop D : ℝ) ≤ H.stop E + exact_mod_cast H.stop_mono hDE + +theorem DeletionHistory.survival_le_best {n M t r : ℕ} + (H : DeletionHistory n M) {D : Finset (Fin n)} (hD : D.card ≤ r) + (hs : candidateSurvives (H.state t) D) : + (t : ℝ) < bestDeletionTime H.realStop r := by + have ht : (t : ℝ) < H.realStop D := by + change (t : ℝ) < H.stop D + exact_mod_cast (H.before_stop_iff D).mpr hs + apply ht.trans_le + exact Finset.le_sup' _ (by simp [allowedDeletions, hD]) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DeletionIncrement.lean b/lean/OAI/Probability/SATComputability/DeletionIncrement.lean new file mode 100644 index 0000000000000000000000000000000000000000..dce5659c84af39da948898e56886035afd26fbee --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DeletionIncrement.lean @@ -0,0 +1,127 @@ +import OAI.Probability.SATComputability.VariableDeletion +import OAI.Probability.DilutedSpin.FiniteLaw + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Finset +open DilutedSpinGlass +open scoped BigOperators + +def allowedDeletions (n r : ℕ) : Finset (Finset (Fin n)) := + univ.filter (fun D => D.card ≤ r) + +theorem allowedDeletions_nonempty (n r : ℕ) : (allowedDeletions n r).Nonempty := + ⟨∅, by simp [allowedDeletions]⟩ + +noncomputable def bestDeletionTime {n : ℕ} (t : Finset (Fin n) → ℝ) (r : ℕ) : ℝ := + (allowedDeletions n r).sup' (allowedDeletions_nonempty n r) t + +noncomputable def freeDeletionTime {n : ℕ} (t : Finset (Fin n) → ℝ) + (r : ℕ) (v : Fin n) : ℝ := + (allowedDeletions n r).sup' (allowedDeletions_nonempty n r) (fun D => t (insert v D)) + +theorem bestDeletionTime_mono {n : ℕ} (t : Finset (Fin n) → ℝ) : + Monotone (bestDeletionTime t) := by + intro r s hrs + apply Finset.sup'_le + intro D hD + apply Finset.le_sup' + simp only [allowedDeletions, Finset.mem_filter, Finset.mem_univ, true_and] at hD ⊢ + exact hD.trans hrs + +theorem bestDeletionTime_le_free {n : ℕ} {t : Finset (Fin n) → ℝ} + (ht : Monotone t) (r : ℕ) (v : Fin n) : + bestDeletionTime t r ≤ freeDeletionTime t r v := by + apply Finset.sup'_le + intro D hD + apply (ht (Finset.subset_insert v D)).trans + exact Finset.le_sup' (fun E => t (insert v E)) hD + +theorem freeDeletionTime_le_next {n : ℕ} (t : Finset (Fin n) → ℝ) + (r : ℕ) (v : Fin n) : + freeDeletionTime t r v ≤ bestDeletionTime t (r+1) := by + apply Finset.sup'_le + intro D hD + apply Finset.le_sup' + simp only [allowedDeletions, Finset.mem_filter, Finset.mem_univ, true_and] at hD ⊢ + exact (Finset.card_insert_le _ _).trans (Nat.add_le_add_right hD 1) + +theorem freeDeletionTime_eq_at_max {n r : ℕ} (t : Finset (Fin n) → ℝ) + (hr : 1 ≤ r) {D : Finset (Fin n)} (hD : D.card = r) + (hmax : bestDeletionTime t r = t D) {v : Fin n} (hv : v ∈ D) : + freeDeletionTime t (r-1) v = bestDeletionTime t r := by + apply le_antisymm + · simpa only [Nat.sub_add_cancel hr] using freeDeletionTime_le_next t (r-1) v + · rw [hmax] + have he : D.erase v ∈ allowedDeletions n (r-1) := by + simp only [allowedDeletions, Finset.mem_filter, Finset.mem_univ, true_and, + Finset.card_erase_of_mem hv, hD, le_refl] + have h := Finset.le_sup' (fun E => t (insert v E)) he + simpa only [freeDeletionTime, Finset.insert_erase hv] using h + +theorem deletion_increment_rpow {n r : ℕ} {t : Finset (Fin n) → ℝ} + (ht : Monotone t) (hr : 1 ≤ r) {p : ℝ} (hp : 0 < p) : + (r : ℝ) * (bestDeletionTime t r - bestDeletionTime t (r-1))^p ≤ + ∑ v : Fin n, (freeDeletionTime t (r-1) v - bestDeletionTime t (r-1))^p := by + obtain ⟨D, hD, hmax⟩ := Finset.exists_mem_eq_sup' + (allowedDeletions_nonempty n r) t + change bestDeletionTime t r = t D at hmax + have hcard : D.card ≤ r := by simpa only [allowedDeletions, Finset.mem_filter, + Finset.mem_univ, true_and] using hD + have hnonneg (v : Fin n) : + 0 ≤ freeDeletionTime t (r-1) v - bestDeletionTime t (r-1) := + sub_nonneg.mpr (bestDeletionTime_le_free ht (r-1) v) + by_cases hsmall : D.card < r + · have he : D ∈ allowedDeletions n (r-1) := by + simp only [allowedDeletions, Finset.mem_filter, Finset.mem_univ, true_and] + omega + have hle : bestDeletionTime t r ≤ bestDeletionTime t (r-1) := by + rw [hmax] + exact Finset.le_sup' t he + have heq := le_antisymm hle (bestDeletionTime_mono t (Nat.sub_le r 1)) + rw [heq, sub_self, Real.zero_rpow hp.ne', mul_zero] + exact Finset.sum_nonneg (fun v _ => Real.rpow_nonneg (hnonneg v) _) + · have hcard' : D.card = r := by omega + calc + _ = ∑ v ∈ D, (bestDeletionTime t r - bestDeletionTime t (r-1))^p := by + simp only [Finset.sum_const, nsmul_eq_mul, hcard'] + _ = ∑ v ∈ D, (freeDeletionTime t (r-1) v - bestDeletionTime t (r-1))^p := by + apply Finset.sum_congr rfl + intro v hv + rw [freeDeletionTime_eq_at_max t hr hcard' hmax hv] + _ ≤ _ := Finset.sum_le_sum_of_subset_of_nonneg (Finset.subset_univ D) + (fun v _ _ => Real.rpow_nonneg (hnonneg v) _) + +theorem mean_deletion_increment {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) + {n r : ℕ} (t : Ω → Finset (Fin n) → ℝ) (ht : ∀ ω, Monotone (t ω)) + (hr : 1 ≤ r) {p C : ℝ} (hp : 1 ≤ p) + (hmoment : ∀ v : Fin n, P.expect (fun ω => + (freeDeletionTime (t ω) (r-1) v - bestDeletionTime (t ω) (r-1))^p) ≤ C) : + P.expect (fun ω => bestDeletionTime (t ω) r - bestDeletionTime (t ω) (r-1)) ≤ + ((n : ℝ) * C / r) ^ (1/p) := by + let delta := fun ω => bestDeletionTime (t ω) r - bestDeletionTime (t ω) (r-1) + have hd (ω : Ω) : 0 ≤ delta ω := + sub_nonneg.mpr (bestDeletionTime_mono (t ω) (Nat.sub_le r 1)) + have hpow : (r : ℝ) * P.expect (fun ω => (delta ω)^p) ≤ n*C := by + have hi := P.expect_mono (fun ω => deletion_increment_rpow (ht ω) hr + (show 0 < p by linarith)) + rw [FiniteLaw.expect_mul_left, FiniteLaw.expect_fintype_sum] at hi + apply hi.trans + have hs := Finset.sum_le_sum (fun v (_ : v ∈ (Finset.univ : Finset (Fin n))) => + hmoment v) + simpa only [Finset.sum_const, Finset.card_univ, Fintype.card_fin, nsmul_eq_mul] using hs + have hr0 : (0 : ℝ) < r := by exact_mod_cast (Nat.zero_lt_of_lt hr) + have hi : P.expect (fun ω => (delta ω)^p) ≤ (n : ℝ)*C/r := + (le_div_iff₀ hr0).mpr (by simpa only [mul_comm] using hpow) + have hm := Real.arith_mean_le_rpow_mean Finset.univ P.weight delta + (fun ω _ => P.nonneg ω) P.total (fun ω _ => hd ω) hp + change P.expect delta ≤ _ at hm + apply hm.trans + exact Real.rpow_le_rpow (P.expect_nonneg (fun ω => Real.rpow_nonneg (hd ω) p)) hi + (by positivity) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DeletionMean.lean b/lean/OAI/Probability/SATComputability/DeletionMean.lean new file mode 100644 index 0000000000000000000000000000000000000000..e4ba2f0307f1597794c0e72572d859117c743ad3 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DeletionMean.lean @@ -0,0 +1,64 @@ +import OAI.Probability.SATComputability.DeletionIncrement + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory +open scoped BigOperators + +theorem sum_inverse_five_sixths (r : ℕ) : + (∑ j ∈ Finset.range r, ((j : ℝ)+1)^(-(5/6 : ℝ))) ≤ + 6 * (r : ℝ)^(1/6 : ℝ) := by + have ha : AntitoneOn (fun x : ℝ => x^(-(5/6 : ℝ))) (Set.Ioc 0 (r : ℝ)) := by + intro x hx y _ hxy + exact Real.rpow_le_rpow_of_nonpos hx.1 hxy (by norm_num) + have hi : IntervalIntegrable (fun x : ℝ => x^(-(5/6 : ℝ))) volume 0 (r : ℝ) := + intervalIntegral.intervalIntegrable_rpow' (by norm_num) + have hfi : IntegrableOn (fun x : ℝ => x^(-(5/6 : ℝ))) (Set.Icc 0 (r : ℝ)) := + (intervalIntegrable_iff_integrableOn_Icc_of_le (Nat.cast_nonneg r) (by simp)).mp hi + have hb := (show AntitoneOn (fun x : ℝ => x^(-(5/6 : ℝ))) + (Set.Ioc 0 (0+(r : ℝ))) by simpa using ha).sum_le_integral_of_integrableOn + (by simpa using hfi) + simp only [zero_add, Nat.cast_add, Nat.cast_one] at hb + apply hb.trans_eq + rw [integral_rpow (Or.inl (by norm_num : (-1 : ℝ) < -(5/6 : ℝ)))] + norm_num + ring + +theorem finite_deletion_mean {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) + {n r : ℕ} (t : Ω → Finset (Fin n) → ℝ) (ht : ∀ ω, Monotone (t ω)) + {C : ℝ} (hC : 0 ≤ C) + (hmoment : ∀ j < r, ∀ v : Fin n, P.expect (fun ω => + (freeDeletionTime (t ω) j v - bestDeletionTime (t ω) j)^(6/5 : ℝ)) ≤ C) : + P.expect (fun ω => bestDeletionTime (t ω) r) - + P.expect (fun ω => bestDeletionTime (t ω) 0) ≤ + 6 * ((n : ℝ)*C)^(5/6 : ℝ) * (r : ℝ)^(1/6 : ℝ) := by + let A := fun j => P.expect (fun ω => bestDeletionTime (t ω) j) + have hnc : 0 ≤ (n : ℝ)*C := mul_nonneg (Nat.cast_nonneg _) hC + have hj (j : ℕ) (hj : j < r) : + A (j+1) - A j ≤ ((n : ℝ)*C)^(5/6 : ℝ) * + ((j : ℝ)+1)^(-(5/6 : ℝ)) := by + have h := mean_deletion_increment P t ht (Nat.succ_pos j) + (by norm_num : (1 : ℝ) ≤ 6/5) (by + simpa only [Nat.succ_sub_one] using hmoment j hj) + simp only [Nat.succ_sub_one, Nat.cast_succ, one_div, FiniteLaw.expect_sub] at h + norm_num only [inv_div, div_one] at h + apply h.trans_eq + rw [Real.div_rpow hnc (by positivity), div_eq_mul_inv, + ← Real.rpow_neg (by positivity)] + change A r - A 0 ≤ _ + calc + _ = ∑ j ∈ Finset.range r, (A (j+1)-A j) := (Finset.sum_range_sub A r).symm + _ ≤ ∑ j ∈ Finset.range r, ((n : ℝ)*C)^(5/6 : ℝ) * + ((j : ℝ)+1)^(-(5/6 : ℝ)) := + Finset.sum_le_sum (fun j hj' => hj j (Finset.mem_range.mp hj')) + _ = ((n : ℝ)*C)^(5/6 : ℝ) * + ∑ j ∈ Finset.range r, ((j : ℝ)+1)^(-(5/6 : ℝ)) := by rw [Finset.mul_sum] + _ ≤ ((n : ℝ)*C)^(5/6 : ℝ) * (6*(r : ℝ)^(1/6 : ℝ)) := + mul_le_mul_of_nonneg_left (sum_inverse_five_sixths r) (Real.rpow_nonneg hnc _) + _ = _ := by ring + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DeletionScaling.lean b/lean/OAI/Probability/SATComputability/DeletionScaling.lean new file mode 100644 index 0000000000000000000000000000000000000000..cd2af4980df81158a3a433be7975f22e85efa5a3 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DeletionScaling.lean @@ -0,0 +1,55 @@ +import OAI.Probability.SATComputability.UniformFreeMoment + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass Filter +open scoped NNReal Topology + +noncomputable def deletionSlope (q : ℕ) : ℝ := + 6*uniformFreeConstant^(5/6 : ℝ)*((q : ℝ)⁻¹)^(1/6 : ℝ) + +theorem deletionSlope_tendsto : Tendsto deletionSlope atTop (nhds 0) := by + change Tendsto (fun q : ℕ => 6*uniformFreeConstant^(5/6 : ℝ)* + ((q : ℝ)⁻¹)^(1/6 : ℝ)) atTop (nhds 0) + have h := (tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop).rpow_const_nhds_zero + (by norm_num : (0 : ℝ) < 1/6) + simpa only [Function.comp_apply, mul_zero] using h.const_mul (6*uniformFreeConstant^(5/6 : ℝ)) + +theorem deletionSlope_small {δ : ℝ} (hδ : 0 < δ) : + ∃ q : ℕ, 0 < q ∧ deletionSlope q < δ := by + obtain ⟨q,hq,hs⟩ := ((eventually_gt_atTop 0).and + (deletionSlope_tendsto.eventually (gt_mem_nhds hδ))).exists + exact ⟨q,hq,hs⟩ + +theorem deletion_increment_linear (n q : ℕ) [NeZero n] (hq : 0 < q) : + let P := FiniteLaw.pi (fun _ : Fin (20*n) => candidateBlock (n := n) 1 3 Finset.univ) + P.expect (maskLifetime (20*n) (deletionBudgetMask n (n/q))) - + P.expect (maskLifetime (20*n) (deletionBudgetMask n 0)) ≤ deletionSlope q*n := by + dsimp only + apply (actual_deletion_mean n (n/q)).trans + have hn : (0 : ℝ) < n := by exact_mod_cast NeZero.pos n + have hqR : (0 : ℝ) < q := by exact_mod_cast hq + have hd : ((n/q : ℕ) : ℝ) ≤ (n : ℝ)*(q : ℝ)⁻¹ := by + rw [← div_eq_mul_inv, le_div_iff₀ hqR] + exact_mod_cast Nat.div_mul_le_self n q + have hpow := Real.rpow_le_rpow (Nat.cast_nonneg (n/q)) hd + (by norm_num : (0 : ℝ) ≤ 1/6) + calc + _ ≤ 6*((n : ℝ)*uniformFreeConstant)^(5/6 : ℝ)* + ((n : ℝ)*(q : ℝ)⁻¹)^(1/6 : ℝ) := + mul_le_mul_of_nonneg_left hpow (mul_nonneg (by norm_num) + (Real.rpow_nonneg (mul_nonneg hn.le uniformFreeConstant_nonneg) _)) + _ = deletionSlope q*n := by + rw [Real.mul_rpow hn.le uniformFreeConstant_nonneg, + Real.mul_rpow hn.le (inv_nonneg.mpr hqR.le)] + calc + _ = deletionSlope q*((n : ℝ)^(5/6 : ℝ)*(n : ℝ)^(1/6 : ℝ)) := by + unfold deletionSlope + ring + _ = _ := by rw [← Real.rpow_add hn]; norm_num + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DiscreteDelay.lean b/lean/OAI/Probability/SATComputability/DiscreteDelay.lean new file mode 100644 index 0000000000000000000000000000000000000000..4685525334ba023a7ab190b772669920e92afad0 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DiscreteDelay.lean @@ -0,0 +1,57 @@ +import OAI.Probability.SATComputability.DeletionMean +import OAI.Probability.SATComputability.DyadicBlocks + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory +open scoped BigOperators + +theorem sixth_fifth_power_le_sum (d : ℕ) : + (d : ℝ)^(6/5 : ℝ) ≤ + (6/5 : ℝ) * ∑ j ∈ Finset.range d, ((j : ℝ)+1)^(1/5 : ℝ) := by + have hm : MonotoneOn (fun x : ℝ => x^(1/5 : ℝ)) (Set.Icc 0 (0+(d : ℝ))) := by + intro x hx y _ hxy + exact Real.rpow_le_rpow hx.1 hxy (by norm_num) + have h := hm.integral_le_sum + simp only [zero_add, Nat.cast_add, Nat.cast_one] at h + rw [integral_rpow (Or.inl (by norm_num : (-1 : ℝ) < 1/5))] at h + norm_num at h + nlinarith + +theorem finite_fractional_moment {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) + (f : Ω → ℝ) (hf : ∀ ω, 0 ≤ f ω) : + P.expect (fun ω => (f ω)^(1/5 : ℝ)) ≤ (P.expect f)^(1/5 : ℝ) := by + exact (Real.concaveOn_rpow (by norm_num : (0 : ℝ) ≤ 1/5) + (by norm_num : (1/5 : ℝ) ≤ 1)).le_map_sum + (fun ω _ => P.nonneg ω) P.total (fun ω _ => hf ω) + +theorem reverse_interval_sum (A B : ℕ) (hAB : A ≤ B) (f : ℕ → ℝ) : + (∑ t ∈ Finset.Ico A B, f (B-t)) = + ∑ j ∈ Finset.range (B-A), f (j+1) := by + rw [Finset.sum_Ico_eq_sum_range, ← Finset.sum_range_reflect] + apply Finset.sum_congr rfl + intro j hj + congr 1 + have hj' := Finset.mem_range.mp hj + omega + +theorem discrete_delay_moment {A B M : ℕ} (hAB : A ≤ B) (hBM : B ≤ M) : + ((B-A : ℕ) : ℝ)^(6/5 : ℝ) ≤ (6/5 : ℝ) * + ∑ t ∈ Finset.range M, + if A ≤ t ∧ t < B then ((B-t : ℕ) : ℝ)^(1/5 : ℝ) else 0 := by + have he : (∑ t ∈ Finset.range M, + if A ≤ t ∧ t < B then ((B-t : ℕ) : ℝ)^(1/5 : ℝ) else 0) = + ∑ t ∈ Finset.Ico A B, ((B-t : ℕ) : ℝ)^(1/5 : ℝ) := by + rw [← Finset.sum_filter] + congr 1 + ext t + simp only [Finset.mem_filter, Finset.mem_range, Finset.mem_Ico] + omega + rw [he, reverse_interval_sum A B hAB (fun j => (j : ℝ)^(1/5 : ℝ))] + simpa only [Nat.cast_add, Nat.cast_one] using sixth_fifth_power_le_sum (B-A) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DisorderEnumeration.lean b/lean/OAI/Probability/SATComputability/DisorderEnumeration.lean new file mode 100644 index 0000000000000000000000000000000000000000..b0a8961e19cb0f615a8475a7d58c4c0cc0197bc1 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DisorderEnumeration.lean @@ -0,0 +1,113 @@ +import OAI.Probability.SATComputability.PacketExpressions +import OAI.Probability.SATComputability.PoissonEvaluation + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass Nat.Partrec FiniteArithmetic RapidForcing.EffectiveArithmetic +open scoped BigOperators Classical +local instance disorderEnumerationRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +noncomputable def signAlphabet : List (Fin 3 → Bool) := Finset.univ.toList + +@[fun_prop] theorem signWords_computable : + Computable (fun k => words signAlphabet k) := + words_primrec.to_comp.comp (Computable.const signAlphabet) Computable.id + +theorem sum_words {A : Type} [Fintype A] [DecidableEq A] (k : ℕ) + (f : List A → ℝ) : + ((words (Finset.univ.toList : List A) k).map f).sum = + ∑ x : Fin k → A, f (List.ofFn x) := by + induction k generalizing f with + | zero => simp [words] + | succ k ih => + simp only [words, List.map_flatMap, sum_flatMap_eq, List.map_map, Function.comp_def] + simp_rw [ih] + rw [Finset.sum_map_toList, ← (Fin.consEquiv (fun _ : Fin (k+1) => A)).sum_comp, + Fintype.sum_prod_type] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro x _ + rw [List.ofFn_succ] + rfl + +noncomputable def averagedSiteExpression (β : ℚ) (root : Code) (ms : List ℚ) (k : ℕ) : Code := + .comp (rationalExpression ((8 : ℚ)^k)⁻¹) + (sumExpressions ((words signAlphabet k).map (fun signs => siteTrialExpression β signs root ms))) + +attribute [local irreducible] siteTrialExpression edgeTrialExpression + +@[fun_prop] theorem averagedSiteExpression_computable : + Computable (fun p : (ℚ × Code × List ℚ) × ℕ => + averagedSiteExpression p.1.1 p.1.2.1 p.1.2.2 p.2) := by + have hs : Computable (fun p : (ℚ × Code × List ℚ) × ℕ => + (words signAlphabet p.2).map (fun signs => + siteTrialExpression p.1.1 signs p.1.2.1 p.1.2.2)) := by + apply computable_list_map (signWords_computable.comp Computable.snd) + unfold Computable₂ + exact siteTrialExpression_computable.comp + (g := fun p : ((ℚ × Code × List ℚ) × ℕ) × List (Fin 3 → Bool) => + (p.1.1.1,p.2,p.1.1.2.1,p.1.1.2.2)) (by fun_prop) + unfold averagedSiteExpression + fun_prop + +theorem trialLog_site_cast {k l r : ℕ} (h : k = l) (β : ℝ) + (ζ : Hierarchy (r+1)) (m : Fin r → ℝ) (J : Fin l → Fin 3 → Bool) : + trialLog r ζ m (siteLog (fun j : Fin k => satSample β (J (Fin.cast h j))) 0) = + trialLog r ζ m (siteLog (fun j => satSample β (J j)) 0) := by + subst l + rfl + +theorem averagedSiteExpression_value (β : ℚ) (root : Code) (ms : List ℚ) (k : ℕ) : + expressionValue (averagedSiteExpression β root ms k) = + (FiniteLaw.uniform : FiniteLaw (Fin k → Fin 3 → Bool)).expect (fun signs => + trialLog ms.length (rationalTreeValue (ms.length+1) (decodeTree (ms.length+1) root)) + (fun i => (ms.get i : ℝ)) (siteLog (fun j => satSample (β : ℝ) (signs j)) 0)) := by + simp only [averagedSiteExpression, expressionValue, rationalExpression_value, + sumExpressions_value, List.map_map, Function.comp_def, signAlphabet, sum_words] + simp only [FiniteLaw.expect, FiniteLaw.uniform, Fintype.card_fun, Fintype.card_fin, + Fintype.card_bool, Nat.cast_pow, Nat.cast_ofNat, Rat.cast_inv, Rat.cast_pow, + Rat.cast_ofNat, ← Finset.mul_sum] + norm_num + apply Finset.sum_congr rfl + intro J _ + rw [siteTrialExpression_value] + simpa only [List.get_ofFn, List.get_eq_getElem, List.getElem_ofFn, Fin.cast] using + trialLog_site_cast (List.length_ofFn (f := J)) (β : ℝ) + (rationalTreeValue (ms.length+1) (decodeTree (ms.length+1) root)) + (fun i => (ms.get i : ℝ)) J + +noncomputable def averagedEdgeExpression (β : ℚ) (root : Code) (ms : List ℚ) : Code := + .comp (rationalExpression (1/8)) + (sumExpressions (signAlphabet.map (fun J => edgeTrialExpression β J root ms))) + +@[fun_prop] theorem averagedEdgeExpression_computable : + Computable (fun p : ℚ × Code × List ℚ => averagedEdgeExpression p.1 p.2.1 p.2.2) := by + have hs : Computable (fun p : ℚ × Code × List ℚ => + signAlphabet.map (fun J => edgeTrialExpression p.1 J p.2.1 p.2.2)) := by + apply computable_list_map (Computable.const signAlphabet) + unfold Computable₂ + exact edgeTrialExpression_computable.comp + (g := fun p : (ℚ × Code × List ℚ) × (Fin 3 → Bool) => + (p.1.1,p.2,p.1.2.1,p.1.2.2)) (by fun_prop) + unfold averagedEdgeExpression + fun_prop + +theorem averagedEdgeExpression_value (β : ℚ) (root : Code) (ms : List ℚ) : + expressionValue (averagedEdgeExpression β root ms) = + (FiniteLaw.uniform : FiniteLaw (Fin 3 → Bool)).expect (fun J => + trialLog ms.length (rationalTreeValue (ms.length+1) (decodeTree (ms.length+1) root)) + (fun i => (ms.get i : ℝ)) (fun x => Real.log (edge (satInteraction (β : ℝ) J) x))) := by + simp only [averagedEdgeExpression, expressionValue, rationalExpression_value, + sumExpressions_value, List.map_map, Function.comp_def, signAlphabet, Finset.sum_map_toList, + edgeTrialExpression_value] + simp only [FiniteLaw.expect, FiniteLaw.uniform, Fintype.card_fun, Fintype.card_fin, + Fintype.card_bool, Nat.cast_pow, Nat.cast_ofNat, Rat.cast_div, Rat.cast_one, + Rat.cast_ofNat, ← Finset.mul_sum] + norm_num + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DyadicBlocks.lean b/lean/OAI/Probability/SATComputability/DyadicBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..2138096d024851e0e059df56415a030486101af3 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DyadicBlocks.lean @@ -0,0 +1,99 @@ +import OAI.Probability.SATComputability.PoissonBlockBound +import OAI.Probability.SATComputability.CandidateSurvival + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal Classical + +noncomputable def dyadicLevel (j : ℕ) : ℝ := ((2 : ℝ)^j)⁻¹ +def dyadicTruncation (j : ℕ) : ℕ := j+122 +def dyadicMultiplicity (j : ℕ) : ℕ := 2*(j+122)*2^((j+1)/2) +def dyadicBlock (j : ℕ) : ℕ := 32*dyadicTruncation j*dyadicMultiplicity j + +theorem dyadicLevel_pos (j : ℕ) : 0 < dyadicLevel j := by + unfold dyadicLevel + positivity + +theorem dyadicLevel_le_one (j : ℕ) : dyadicLevel j ≤ 1 := by + unfold dyadicLevel + exact inv_le_one_of_one_le₀ (one_le_pow₀ (by norm_num)) + +theorem dyadic_truncation_error (j : ℕ) : + Real.exp 60 / (2 : ℝ)^(dyadicTruncation j) ≤ dyadicLevel j/4 := by + have he : Real.exp 60 ≤ (2 : ℝ)^120 := by + calc + _ = (Real.exp 1)^60 := by rw [← Real.exp_nat_mul]; norm_num + _ ≤ (4 : ℝ)^60 := pow_le_pow_left₀ (Real.exp_pos 1).le + (Real.exp_one_lt_three.le.trans (by norm_num : (3 : ℝ) ≤ 4)) 60 + _ = _ := by norm_num + have hden : (2 : ℝ)^(dyadicTruncation j) = (2 : ℝ)^j * (2 : ℝ)^122 := by + rw [dyadicTruncation, pow_add] + rw [dyadicLevel, hden] + apply (div_le_iff₀ (by positivity)).mpr + field_simp + nlinarith + +theorem dyadic_multiplicity_pos (j : ℕ) : 0 < dyadicMultiplicity j := by + unfold dyadicMultiplicity + positivity + +theorem dyadic_replacement_error (j : ℕ) : + (dyadicTruncation j : ℝ) / (dyadicMultiplicity j : ℝ)^2 ≤ dyadicLevel j/4 := by + have hp : j ≤ (j+1)/2*2 := by omega + have hpow : (2 : ℝ)^j ≤ ((2 : ℝ)^((j+1)/2))^2 := by + rw [← pow_mul] + exact pow_le_pow_right₀ (by norm_num) hp + have hL : (1 : ℝ) ≤ j+122 := by exact_mod_cast (show 1 ≤ j+122 by omega) + have hmul : (4 : ℝ)*((j:ℝ)+122)*(2:ℝ)^j ≤ + (2*((j:ℝ)+122)*(2:ℝ)^((j+1)/2))^2 := by + have hprod := mul_le_mul_of_nonneg_left hpow + (show (0 : ℝ) ≤ 4*((j:ℝ)+122) by positivity) + have hrest := mul_nonneg + (show (0 : ℝ) ≤ (j:ℝ)+122-1 by linarith) + (show (0 : ℝ) ≤ 4*((j:ℝ)+122)*((2:ℝ)^((j+1)/2))^2 by positivity) + nlinarith + unfold dyadicTruncation dyadicMultiplicity dyadicLevel + push_cast + apply (div_le_iff₀ (by positivity)).mpr + rw [show (2^j : ℝ)⁻¹ / 4 * (2*((j:ℝ)+122)*2^((j+1)/2))^2 = + (2*((j:ℝ)+122)*2^((j+1)/2))^2 / (4*2^j) by field_simp] + apply (le_div_iff₀ (by positivity)).mpr + nlinarith + +theorem dyadic_block_kills {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (j : ℕ) (rate : ℝ≥0) + (hrate : (1 : ℝ)/8 ≤ rate) + (hq : dyadicLevel j ≤ poissonKillProbability U 2 60) : + dyadicLevel j/4 ≤ poissonKillProbability U 3 (rate*dyadicBlock j) := by + apply poisson_two_to_three_block U (dyadic_multiplicity_pos j) + (show 0 < dyadicTruncation j by unfold dyadicTruncation; omega) hq + (dyadic_truncation_error j) (dyadic_replacement_error j) + simp only [dyadicBlock, NNReal.coe_mul, NNReal.coe_natCast, Nat.cast_mul, + Nat.cast_ofNat, NNReal.coe_ofNat] + have h := mul_le_mul_of_nonneg_right hrate + (show (0 : ℝ) ≤ 32*(dyadicTruncation j : ℝ)*dyadicMultiplicity j by positivity) + nlinarith + +def dyadicBin {n : ℕ} [NeZero n] (j : ℕ) (U : Finset (DeletionCandidate n)) : Prop := + U.Nonempty ∧ dyadicLevel j ≤ poissonKillProbability U 2 60 ∧ + poissonKillProbability U 2 60 ≤ 2*dyadicLevel j + +theorem dyadic_bin_occupation {n : ℕ} [NeZero n] + (rate : ℝ≥0) (hrate : (1 : ℝ)/8 ≤ rate) (j M : ℕ) + (U : Finset (DeletionCandidate n)) : + (∑ t ∈ Finset.range M, (candidateBlock (rate*t) 3 U).expect + (fun V => if dyadicBin j V then 1 else 0)) ≤ + 4*(dyadicBlock j : ℝ)/dyadicLevel j := by + classical + have h := candidateBlock_occupation rate 3 (dyadicBlock j) M (dyadicBin j) + (show 0 < dyadicLevel j/4 by positivity [dyadicLevel_pos j]) + (fun V hV => ⟨hV.1, dyadic_block_kills V j rate hrate hV.2.1⟩) U + convert h using 1 + ring + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/DyadicMoment.lean b/lean/OAI/Probability/SATComputability/DyadicMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..be800571983c21464cd74ecfa529d6526087574b --- /dev/null +++ b/lean/OAI/Probability/SATComputability/DyadicMoment.lean @@ -0,0 +1,158 @@ +import OAI.Probability.SATComputability.MaskDelay + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass Filter +open scoped BigOperators NNReal Topology + +theorem poissonKillProbability_le_one {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k : ℕ) (r : ℝ≥0) : + poissonKillProbability U k r ≤ 1 := by + have h := FiniteLaw.expect_nonneg (candidateBlock r k U) candidateAlive_nonneg + rw [candidateBlock_expect_alive] at h + linarith + +theorem positive_killing_in_dyadic_bin {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (hU : U.Nonempty) + (hq : 0 < poissonKillProbability U 2 60) : ∃ j, dyadicBin j U := by + obtain ⟨j, hj, hj'⟩ := exists_nat_pow_near_of_lt_one hq + (poissonKillProbability_le_one U 2 60) + (by norm_num : (0 : ℝ) < 2⁻¹) (by norm_num : (2 : ℝ)⁻¹ < 1) + refine ⟨j+1, hU, ?_, ?_⟩ + · simpa only [dyadicLevel, inv_pow] using hj.le + · have he : 2*dyadicLevel (j+1) = ((2 : ℝ)⁻¹)^j := by + simp only [dyadicLevel, inv_pow, pow_succ] + norm_num + ring + rwa [he] + +noncomputable def dyadicLifetimeBound (j : ℕ) : ℝ := + (4*(dyadicBlock j : ℝ)/dyadicLevel j)^(1/5 : ℝ) + +theorem dyadicLifetimeBound_nonneg (j : ℕ) : 0 ≤ dyadicLifetimeBound j := by + unfold dyadicLifetimeBound + positivity [dyadicLevel_pos j] + +theorem dyadic_lifetime_bound {n : ℕ} [NeZero n] (r : ℝ≥0) + (hr : (1 : ℝ)/8 ≤ r) (m j : ℕ) (U : Finset (DeletionCandidate n)) + (hU : dyadicBin j U) : + (FiniteLaw.pi (fun _ : Fin m => candidateBlock (n := n) r 3 Finset.univ)).expect + (fun xs => (maskLifetime m U xs)^(1/5 : ℝ)) ≤ dyadicLifetimeBound j := by + have h := maskLifetime_fractional_moment r 3 m (dyadicBlock j) U + (show 0 < dyadicLevel j/4 by positivity [dyadicLevel_pos j]) + (dyadic_block_kills U j r hr hU.2.1) + convert h using 1 + unfold dyadicLifetimeBound + congr 1 + field_simp + +theorem capped_lifetime_fractional_bound {n : ℕ} [NeZero n] + (r : ℝ≥0) (k m M : ℕ) (hm : m ≤ M) (U : Finset (DeletionCandidate n)) : + (FiniteLaw.pi (fun _ : Fin m => candidateBlock (n := n) r k Finset.univ)).expect + (fun xs => (maskLifetime m U xs)^(1/5 : ℝ)) ≤ (M : ℝ)^(1/5 : ℝ) := by + apply (FiniteLaw.expect_mono _ (g := fun _ => (M : ℝ)^(1/5 : ℝ)) (fun xs => Real.rpow_le_rpow + (maskLifetime_nonneg U xs) ((maskLifetime_le U xs).trans (by exact_mod_cast hm)) + (by norm_num : (0 : ℝ) ≤ 1/5))).trans_eq + exact FiniteLaw.expect_const _ _ + +theorem dyadicLevel_rpow (j : ℕ) : dyadicLevel j = (2 : ℝ)^(-(j : ℝ)) := by + rw [dyadicLevel, Real.rpow_neg (by norm_num : (0 : ℝ) ≤ 2), Real.rpow_natCast] + +theorem dyadicBlock_growth (j : ℕ) : + (dyadicBlock j : ℝ) ≤ 128*((j : ℝ)+122)^2 * (2 : ℝ)^((j : ℝ)/2) := by + have he : (((j+1)/2 : ℕ) : ℝ) ≤ (j : ℝ)/2+1 := by + have h : 2*((j+1)/2) ≤ j+2 := by omega + have h' : (2 : ℝ)*((j+1)/2 : ℕ) ≤ (j : ℝ)+2 := by exact_mod_cast h + linarith + have hp : (2 : ℝ)^((j+1)/2) ≤ 2*(2 : ℝ)^((j : ℝ)/2) := by + rw [← Real.rpow_natCast] + apply (Real.rpow_le_rpow_of_exponent_le (by norm_num) he).trans_eq + rw [Real.rpow_add (by norm_num : (0 : ℝ) < 2), Real.rpow_one] + ring + unfold dyadicBlock dyadicMultiplicity dyadicTruncation + push_cast + nlinarith [mul_le_mul_of_nonneg_left hp (show 0 ≤ 64*((j : ℝ)+122)^2 by positivity)] + +noncomputable def dyadicMomentCoefficient (j : ℕ) : ℝ := + (dyadicLevel j)^2 * (4*(dyadicBlock j : ℝ)/dyadicLevel j)^(6/5 : ℝ) + +theorem dyadicMomentCoefficient_nonneg (j : ℕ) : 0 ≤ dyadicMomentCoefficient j := by + unfold dyadicMomentCoefficient + positivity [dyadicLevel_pos j] + +theorem dyadicMomentCoefficient_bound (j : ℕ) : + dyadicMomentCoefficient j ≤ + (512 : ℝ)^(6/5 : ℝ) * ((j : ℝ)+122)^3 * ((2 : ℝ)^(-1/5 : ℝ))^j := by + have hx : 0 < (j : ℝ)+122 := by positivity + have hpow : (2 : ℝ)^((j : ℝ)/2) * (2 : ℝ)^(j : ℝ) = + (2 : ℝ)^(3*(j : ℝ)/2) := by + rw [← Real.rpow_add (by norm_num : (0 : ℝ) < 2)] + congr 1 + ring + have hA : 4*(dyadicBlock j : ℝ)/dyadicLevel j ≤ + 512*((j : ℝ)+122)^2 * (2 : ℝ)^(3*(j : ℝ)/2) := by + calc + _ = 4*(dyadicBlock j : ℝ)*(2 : ℝ)^(j : ℝ) := by + simp only [dyadicLevel, div_eq_mul_inv, inv_inv, Real.rpow_natCast] + _ ≤ 4*(128*((j : ℝ)+122)^2*(2 : ℝ)^((j : ℝ)/2)) * (2 : ℝ)^(j : ℝ) := by + gcongr + exact dyadicBlock_growth j + _ = _ := by rw [show 4*(128*((j : ℝ)+122)^2*(2 : ℝ)^((j : ℝ)/2)) * + (2 : ℝ)^(j : ℝ) = 512*((j : ℝ)+122)^2 * + ((2 : ℝ)^((j : ℝ)/2)*(2 : ℝ)^(j : ℝ)) by ring, hpow] + have hq : (dyadicLevel j)^2 = (2 : ℝ)^(-2*(j : ℝ)) := by + rw [dyadicLevel_rpow, pow_two, ← Real.rpow_add (by norm_num : (0 : ℝ) < 2)] + congr 1 + ring + have hxp : (((j : ℝ)+122)^2)^(6/5 : ℝ) = ((j : ℝ)+122)^(12/5 : ℝ) := by + rw [← Real.rpow_natCast, ← Real.rpow_mul hx.le] + norm_num + have htwo : ((2 : ℝ)^(3*(j : ℝ)/2))^(6/5 : ℝ) = (2 : ℝ)^(9*(j : ℝ)/5) := by + rw [← Real.rpow_mul (by norm_num : (0 : ℝ) ≤ 2)] + congr 1 + ring + have he : (2 : ℝ)^(-2*(j : ℝ)) * (2 : ℝ)^(9*(j : ℝ)/5) = + ((2 : ℝ)^(-1/5 : ℝ))^j := by + rw [← Real.rpow_add (by norm_num : (0 : ℝ) < 2), + ← Real.rpow_mul_natCast (by norm_num : (0 : ℝ) ≤ 2)] + congr 1 + ring + calc + _ ≤ (dyadicLevel j)^2 * + (512*((j : ℝ)+122)^2*(2 : ℝ)^(3*(j : ℝ)/2))^(6/5 : ℝ) := by + exact mul_le_mul_of_nonneg_left + (Real.rpow_le_rpow (by positivity [dyadicLevel_pos j]) hA (by norm_num)) (sq_nonneg _) + _ = (512 : ℝ)^(6/5 : ℝ) * ((j : ℝ)+122)^(12/5 : ℝ) * + ((2 : ℝ)^(-1/5 : ℝ))^j := by + rw [Real.mul_rpow (by positivity) (by positivity), + Real.mul_rpow (by norm_num : (0 : ℝ) ≤ 512) (sq_nonneg _), hq, hxp, htwo] + calc + _ = (512 : ℝ)^(6/5 : ℝ) * ((j : ℝ)+122)^(12/5 : ℝ) * + ((2 : ℝ)^(-2*(j : ℝ))*(2 : ℝ)^(9*(j : ℝ)/5)) := by ring + _ = _ := by rw [he] + _ ≤ _ := by + gcongr + rw [← Real.rpow_natCast] + exact Real.rpow_le_rpow_of_exponent_le (by linarith [Nat.cast_nonneg (α := ℝ) j]) (by norm_num) + +theorem dyadicMomentCoefficient_summable : Summable dyadicMomentCoefficient := by + let ρ : ℝ := 2^(-1/5 : ℝ) + have hρ : ‖ρ‖ < 1 := by + rw [Real.norm_eq_abs, abs_of_pos (Real.rpow_pos_of_pos (by norm_num) _)] + exact Real.rpow_lt_one_of_one_lt_of_neg (by norm_num) (by norm_num) + have hpoly : Summable (fun j : ℕ => ((j : ℝ)+122)^3*ρ^j) := by + have h0 := (summable_geometric_of_norm_lt_one hρ).mul_left (122^3 : ℝ) + have h1 := (summable_pow_mul_geometric_of_norm_lt_one 1 hρ).mul_left (3*122^2 : ℝ) + have h2 := (summable_pow_mul_geometric_of_norm_lt_one 2 hρ).mul_left (3*122 : ℝ) + have h3 := summable_pow_mul_geometric_of_norm_lt_one 3 hρ + apply (h3.add (h2.add (h1.add h0))).congr + intro j + ring + apply Summable.of_nonneg_of_le dyadicMomentCoefficient_nonneg dyadicMomentCoefficient_bound + simpa only [mul_assoc, ρ] using hpoly.mul_left ((512 : ℝ)^(6/5 : ℝ)) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/EffectiveLog.lean b/lean/OAI/Probability/SATComputability/EffectiveLog.lean new file mode 100644 index 0000000000000000000000000000000000000000..ece99de10f607221021c80be7fce890e05acc59a --- /dev/null +++ b/lean/OAI/Probability/SATComputability/EffectiveLog.lean @@ -0,0 +1,135 @@ +import OAI.Analysis.PeriodicLattice.ElementaryFunctions +import OAI.MathematicalPhysics.RapidForcing.RatOperations +import OAI.MathematicalPhysics.RapidForcing.RecursiveComputable + +namespace OAI + +namespace PeriodicLattice.CertifiedReal + +open Encodable Filter +open scoped Topology +local instance effectiveLogRatPrimcodable : Primcodable ℚ := RecursiveArithmetic.ratPrimcodable + +section +variable {A : Type*} [Primcodable A] + +def logLower (z : ℕ) : ℚ := (decode z.unpair.1).getD 0 +def logUpper (z : ℕ) : ℚ := (decode z.unpair.2.unpair.1).getD 0 +def logAccuracy (z : ℕ) : ℕ := z.unpair.2.unpair.2 + +@[fun_prop] theorem logLower_computable : Computable logLower := by + unfold logLower + fun_prop +@[fun_prop] theorem logUpper_computable : Computable logUpper := by + unfold logUpper + fun_prop +@[fun_prop] theorem logAccuracy_computable : Computable logAccuracy := by + unfold logAccuracy + fun_prop + +abbrev logTest (q : A × ℕ → ℚ) (e : ℚ × ℕ → ℚ) (an : A × ℕ) (z : ℕ) : Prop := + logUpper z - logLower z ≤ 2*qerror an.2 ∧ + e (logLower z, logAccuracy z) + 2*qerror (logAccuracy z) < q (an.1, logAccuracy z) ∧ + q (an.1, logAccuracy z) + 2*qerror (logAccuracy z) < e (logUpper z, logAccuracy z) + +instance logTest_decidable (q : A × ℕ → ℚ) (e : ℚ × ℕ → ℚ) (an : A × ℕ) (z : ℕ) : + Decidable (logTest q e an z) := inferInstanceAs (Decidable (_ ∧ _ ∧ _)) + +theorem logTest_computable {q : A × ℕ → ℚ} {e : ℚ × ℕ → ℚ} + (hq : Computable q) (he : Computable e) : + Computable (fun p : (A × ℕ) × ℕ => decide (logTest q e p.1 p.2)) := by + unfold logTest + simp only [Bool.decide_and] + apply Primrec.and.to_comp.comp + · exact RecursiveArithmetic.ratLE.decide.to_comp.comp (by fun_prop) (by fun_prop) + · apply Primrec.and.to_comp.comp + · exact RecursiveArithmetic.ratLT.decide.to_comp.comp (by fun_prop) (by fun_prop) + · exact RecursiveArithmetic.ratLT.decide.to_comp.comp (by fun_prop) (by fun_prop) + +omit [Primcodable A] in +theorem logTest_exists {f : A → ℝ} (q : A × ℕ → ℚ) (e : ℚ × ℕ → ℚ) + (eq : ∀ a n, |f a - (q (a,n) : ℝ)| ≤ error n) + (ee : ∀ (a : ℚ) n, |Real.exp (a : ℝ) - (e (a,n) : ℝ)| ≤ error n) + (hpos : ∀ a, 0 < f a) (an : A × ℕ) : ∃ z, logTest q e an z := by + obtain ⟨l, hl, hl'⟩ := exists_rat_btwn + (show Real.log (f an.1) - error an.2 < Real.log (f an.1) by linarith [error_pos an.2]) + obtain ⟨u, hu, hu'⟩ := exists_rat_btwn + (show Real.log (f an.1) < Real.log (f an.1) + error an.2 by linarith [error_pos an.2]) + have hlExp : Real.exp (l : ℝ) < f an.1 := by + rw [← Real.exp_log (hpos an.1)] + exact Real.exp_lt_exp.mpr hl' + have huExp : f an.1 < Real.exp (u : ℝ) := by + rw [← Real.exp_log (hpos an.1)] + exact Real.exp_lt_exp.mpr hu + have tq := Effective.approximants_tendsto eq an.1 + have tl := Effective.approximants_tendsto ee l + have tu := Effective.approximants_tendsto ee u + have tl' := (tl.add (error_tendsto.const_mul 2)).eventually_lt tq + (by simpa using hlExp) + have tu' := (tq.add (error_tendsto.const_mul 2)).eventually_lt tu + (by simpa using huExp) + obtain ⟨s, hs, hs'⟩ := (tl'.and tu').exists + refine ⟨Nat.pair (encode l) (Nat.pair (encode u) s), ?_⟩ + have hw : u-l ≤ 2*qerror an.2 := by + have : (u : ℝ)-(l : ℝ) ≤ 2*error an.2 := by linarith + exact_mod_cast (show (u : ℝ)-(l : ℝ) ≤ 2*(qerror an.2 : ℝ) by simpa using this) + have hsl : e (l,s)+2*qerror s < q (an.1,s) := by + exact_mod_cast (show (e (l,s) : ℝ)+2*(qerror s : ℝ) < (q (an.1,s) : ℝ) by simpa using hs) + have hsu : q (an.1,s)+2*qerror s < e (u,s) := by + exact_mod_cast (show (q (an.1,s) : ℝ)+2*(qerror s : ℝ) < (e (u,s) : ℝ) by simpa using hs') + simpa only [logTest, logLower, logUpper, logAccuracy, Nat.unpair_pair, encodek, Option.getD_some] + using And.intro hw (And.intro hsl hsu) + +omit [Primcodable A] in +theorem logTest_sound {f : A → ℝ} (q : A × ℕ → ℚ) (e : ℚ × ℕ → ℚ) + (eq : ∀ a n, |f a - (q (a,n) : ℝ)| ≤ error n) + (ee : ∀ (a : ℚ) n, |Real.exp (a : ℝ) - (e (a,n) : ℝ)| ≤ error n) + (hpos : ∀ a, 0 < f a) (a : A) (n z : ℕ) (hs : logTest q e (a,n) z) : + |Real.log (f a) - (((logLower z+logUpper z)/2 : ℚ) : ℝ)| ≤ error n := by + obtain ⟨hw, hl, hu⟩ := hs + have el := ee (logLower z) (logAccuracy z) + have eu := ee (logUpper z) (logAccuracy z) + have ef := eq a (logAccuracy z) + have hlr : (e (logLower z,logAccuracy z) : ℝ)+2*error (logAccuracy z) < q (a,logAccuracy z) := by + simpa only [cast_qerror] using (show (e (logLower z,logAccuracy z) : ℝ)+2*(qerror (logAccuracy z) : ℝ) < + (q (a,logAccuracy z) : ℝ) by exact_mod_cast hl) + have hur : (q (a,logAccuracy z) : ℝ)+2*error (logAccuracy z) < e (logUpper z,logAccuracy z) := by + simpa only [cast_qerror] using (show (q (a,logAccuracy z) : ℝ)+2*(qerror (logAccuracy z) : ℝ) < + (e (logUpper z,logAccuracy z) : ℝ) by exact_mod_cast hu) + have hlo : Real.exp (logLower z : ℝ) < f a := by + have h1 := (abs_le.mp el).2 + have h2 := (abs_le.mp ef).1 + linarith + have hhi : f a < Real.exp (logUpper z : ℝ) := by + have h1 := (abs_le.mp eu).1 + have h2 := (abs_le.mp ef).2 + linarith + have hloglo : (logLower z : ℝ) < Real.log (f a) := by + rw [← Real.exp_log (hpos a)] at hlo + exact Real.exp_lt_exp.mp hlo + have hloghi : Real.log (f a) < (logUpper z : ℝ) := by + rw [← Real.exp_log (hpos a)] at hhi + exact Real.exp_lt_exp.mp hhi + have hwidth : (logUpper z : ℝ)-(logLower z : ℝ) ≤ 2*error n := by + simpa only [cast_qerror] using + (show (logUpper z : ℝ)-(logLower z : ℝ) ≤ 2*(qerror n : ℝ) by exact_mod_cast hw) + change |Real.log (f a) - (((logLower z+logUpper z)/2 : ℚ) : ℝ)| ≤ error n + push_cast + exact abs_le.mpr ⟨by linarith, by linarith⟩ + +theorem Effective.log {f : A → ℝ} (hf : Effective f) (hpos : ∀ a, 0 < f a) : + Effective (fun a => Real.log (f a)) := by + obtain ⟨q, hq, eq⟩ := hf + obtain ⟨e, he, ee⟩ := (rational (Computable.id : Computable (id : ℚ → ℚ))).exp + change ∀ (a : ℚ) (n : ℕ), |Real.exp (a : ℝ) - (e (a,n) : ℝ)| ≤ error n at ee + have hex := logTest_exists q e eq ee hpos + let pick (an : A × ℕ) := Nat.find (hex an) + have hpick : Computable pick := computable_find (logTest_computable hq he) hex + refine ⟨fun an => (logLower (pick an)+logUpper (pick an))/2, by fun_prop, ?_⟩ + intro a n + exact logTest_sound q e eq ee hpos a n (pick (a,n)) (Nat.find_spec (hex (a,n))) + +end +end PeriodicLattice.CertifiedReal + +end OAI diff --git a/lean/OAI/Probability/SATComputability/EffectiveSums.lean b/lean/OAI/Probability/SATComputability/EffectiveSums.lean new file mode 100644 index 0000000000000000000000000000000000000000..abe5205147761fc9cd282ed5041d332bb30fbcfb --- /dev/null +++ b/lean/OAI/Probability/SATComputability/EffectiveSums.lean @@ -0,0 +1,57 @@ +import OAI.Probability.SATComputability.EffectiveLog + +namespace OAI + +namespace PeriodicLattice.CertifiedReal + +open Encodable Filter +open scoped Topology BigOperators +local instance effectiveSumsRatPrimcodable : Primcodable ℚ := RecursiveArithmetic.ratPrimcodable + +variable {A : Type*} [Primcodable A] + +theorem Effective.sum_range {f : A → ℕ → ℝ} + (hf : Effective (fun p : A × ℕ => f p.1 p.2)) + {m : A → ℕ} (hm : Computable m) : + Effective (fun a => ∑ i ∈ Finset.range (m a), f a i) := by + obtain ⟨q, hq, herror⟩ := hf + apply of_enclosures + (q := fun an => ∑ i ∈ Finset.range (m an.1), q ((an.1,i),an.2)) + (e := fun an => (m an.1 : ℚ)*qerror an.2) + · apply computable_sum (hm.comp Computable.fst) + unfold Computable₂ + fun_prop + · fun_prop + · intro a n + simp only [Rat.cast_sum, Rat.cast_mul, Rat.cast_natCast, cast_qerror] + rw [← Finset.sum_sub_distrib] + calc + _ ≤ ∑ i ∈ Finset.range (m a), |f a i - (q ((a,i),n) : ℝ)| := + Finset.abs_sum_le_sum_abs _ _ + _ ≤ ∑ _i ∈ Finset.range (m a), error n := + Finset.sum_le_sum (fun i _ => herror (a,i) n) + _ = _ := by simp + · intro a + simpa only [Rat.cast_mul, Rat.cast_natCast, cast_qerror, mul_zero] using + error_tendsto.const_mul (m a : ℝ) + +theorem effective_limit {f : A → ℝ} {g : A → ℕ → ℝ} + (hg : Effective (fun p : A × ℕ => g p.1 p.2)) + (tail : A × ℕ → ℚ) (htail : Computable tail) + (hbound : ∀ a n, |f a - g a n| ≤ (tail (a,n) : ℝ)) + (hzero : ∀ a, Tendsto (fun n => (tail (a,n) : ℝ)) atTop (nhds 0)) : + Effective f := by + obtain ⟨q, hq, he⟩ := hg + apply of_enclosures (q := fun an => q ((an.1,an.2),an.2)) + (e := fun an => tail an + qerror an.2) + · fun_prop + · fun_prop + · intro a n + simp only [Rat.cast_add, cast_qerror] + exact (abs_sub_le _ _ _).trans (add_le_add (hbound a n) (he (a,n) n)) + · intro a + simpa only [Rat.cast_add, cast_qerror, add_zero] using (hzero a).add error_tendsto + +end PeriodicLattice.CertifiedReal + +end OAI diff --git a/lean/OAI/Probability/SATComputability/EffectiveTrialValues.lean b/lean/OAI/Probability/SATComputability/EffectiveTrialValues.lean new file mode 100644 index 0000000000000000000000000000000000000000..2b7f3b55288e5a4723e9cb751b1a6bf8fdef6c20 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/EffectiveTrialValues.lean @@ -0,0 +1,117 @@ +import OAI.Probability.SATComputability.TrialDescriptions + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory Nat.Partrec FiniteArithmetic +open PeriodicLattice.CertifiedReal RapidForcing.EffectiveArithmetic +open scoped NNReal +local instance effectiveTrialValuesRatPrimcodable : Primcodable ℚ := + PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +abbrev TrialData := ℚ × ℕ × Code × List ℚ + +noncomputable def guardedSiteExpression (t : TrialData) (k : ℕ) : Code := + if positiveExponents t.2.2.2 then + averagedSiteExpression (t.2.1 : ℚ) t.2.2.1 t.2.2.2 k else .zero + +attribute [local irreducible] averagedSiteExpression averagedEdgeExpression positiveExponents + +@[fun_prop] theorem guardedSiteExpression_computable : + Computable (fun p : TrialData × ℕ => guardedSiteExpression p.1 p.2) := by + have he : Computable (fun p : TrialData × ℕ => + averagedSiteExpression (p.1.2.1 : ℚ) p.1.2.2.1 p.1.2.2.2 p.2) := + averagedSiteExpression_computable.comp + (g := fun p : TrialData × ℕ => (((p.1.2.1 : ℚ),p.1.2.2.1,p.1.2.2.2),p.2)) + (by fun_prop) + unfold guardedSiteExpression + fun_prop + +noncomputable def guardedSiteValue (t : TrialData) (k : ℕ) : ℝ := + expressionValue (guardedSiteExpression t k) + +theorem guardedSiteValue_effective : Effective (fun p : TrialData × ℕ => guardedSiteValue p.1 p.2) := + expressionValue_effective.comp guardedSiteExpression_computable + +theorem guardedSiteValue_bound (t : TrialData) (k : ℕ) : + |guardedSiteValue t k| ≤ (t.2.1 : ℝ)*((k : ℝ)+1) := by + unfold guardedSiteValue guardedSiteExpression + split_ifs with h + · have hp := (positiveExponents_iff t.2.2.2).mp h + apply (packetSiteValue_bound (β := (t.2.1 : ℚ)) (by positivity) + t.2.2.1 t.2.2.2 hp k).trans + push_cast + nlinarith [show (0 : ℝ) ≤ t.2.1 from Nat.cast_nonneg _] + · simp only [expressionValue, abs_zero] + positivity + +noncomputable def trialRate (t : TrialData) : ℚ := 3 * max 0 t.1 + +@[fun_prop] theorem trialRate_computable : Computable trialRate := by + unfold trialRate + fun_prop + +theorem trialRate_nonneg (t : TrialData) : 0 ≤ trialRate t := by + unfold trialRate + positivity + +noncomputable def trialDensityNN (t : TrialData) : ℝ≥0 := + ⟨(max 0 t.1 : ℚ), by exact_mod_cast le_max_left (0 : ℚ) t.1⟩ + +noncomputable def trialValue (t : TrialData) : ℝ := + Real.log 2 + + (∫ k, guardedSiteValue t k ∂poissonMeasure (trialDensityNN t * 3)) - + 2*(max 0 t.1 : ℚ)*packetEdgeValue (t.2.1 : ℚ) t.2.2.1 t.2.2.2 + +attribute [local irreducible] guardedSiteValue packetEdgeValue + +private theorem siteExpectation_effective : Effective (fun t : TrialData => + ∫ k, guardedSiteValue t k ∂poissonMeasure (trialDensityNN t * 3)) := by + have hs := effective_poisson_expectation trialRate trialRate_computable trialRate_nonneg + (fun t : TrialData => t.2.1) (by fun_prop) guardedSiteValue + guardedSiteValue_effective guardedSiteValue_bound + convert hs using 1 + funext t + congr 1 + congr 1 + apply Subtype.ext + change ((max 0 t.1 : ℚ) : ℝ)*3 = ((3*max 0 t.1 : ℚ) : ℝ) + push_cast + ring + +private theorem edgePacket_effective : + Effective (fun t : TrialData => packetEdgeValue (t.2.1 : ℚ) t.2.2.1 t.2.2.2) := by + simpa only [packetEdgeValue] using expressionValue_effective.comp + (averagedEdgeExpression_computable.comp + (g := fun t : TrialData => ((t.2.1 : ℚ),t.2.2.1,t.2.2.2)) (by fun_prop)) + +theorem trialValue_effective : Effective trialValue := by + have hlog : Effective (fun _t : TrialData => Real.log 2) := + (rational (Computable.const (2 : ℚ))).log (fun _ => by norm_num) + have ha : Effective (fun t : TrialData => ((2*(max 0 t.1) : ℚ) : ℝ)) := + rational (by fun_prop) + apply ((hlog.add siteExpectation_effective).sub (ha.mul edgePacket_effective)).congr + intro t + simp only [trialValue, Rat.cast_mul, Rat.cast_ofNat] + +theorem trialValue_eq_functional (t : TrialData) + (hm : exponentCheck t.2.2.2 = true) : + trialValue t = functional (satModel (trialDensityNN t) (t.2.1 : ℝ)) t.2.2.2.length + (rationalTreeValue (t.2.2.2.length+1) (decodeTree (t.2.2.2.length+1) t.2.2.1)) + (fun i => (t.2.2.2.get i : ℝ)) := by + have hp := exponentCheck_positive hm + have he (k : ℕ) : guardedSiteValue t k = packetSiteValue (t.2.1 : ℚ) t.2.2.1 t.2.2.2 k := by + simp only [guardedSiteValue, guardedSiteExpression, hp, ite_true, packetSiteValue] + have hf := packet_functional (trialDensityNN t) (t.2.1 : ℚ) t.2.2.1 t.2.2.2 + ((positiveExponents_iff _).mp hp) + simp only [Rat.cast_natCast] at hf + rw [hf] + have hc : (trialDensityNN t : ℝ) = (max 0 t.1 : ℚ) := rfl + simp only [trialValue, he, hc] + push_cast + ring + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ExchangeableBlocks.lean b/lean/OAI/Probability/SATComputability/ExchangeableBlocks.lean new file mode 100644 index 0000000000000000000000000000000000000000..906547eda169e4720641bd1450ab29fac9ee3908 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ExchangeableBlocks.lean @@ -0,0 +1,44 @@ +import OAI.Probability.SATComputability.MaskPermutations +import OAI.Probability.SATComputability.GridBlockLaw + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory +open scoped NNReal Classical + +theorem maskGrid_permutation {n k M : ℕ} (e : Equiv.Perm (Fin n)) + (c : (Fin k → SignedLiteral n) × Fin M → ℕ) : + (fun j => renameMask e (maskGrid clauseMask c j)) = + maskGrid clauseMask (fun p => c ((clausePermutation e k).symm p.1,p.2)) := by + funext j + exact countsMask_permutation e (fun a => c (a,j)) + +theorem gridMaskLaw_permutation {n k M : ℕ} (e : Equiv.Perm (Fin n)) (r : ℝ≥0) + (f : (Fin M → Finset (DeletionCandidate n)) → ℝ) : + (gridMaskLaw M r (clauseMask (n := n) (k := k))).expect + (fun xs => f (fun j => renameMask e (xs j))) = + (gridMaskLaw M r (clauseMask (n := n) (k := k))).expect f := by + simp only [gridMaskLaw_expect, maskGrid_permutation] + have h := poissonCountLaw_equiv + ((clausePermutation e k).prodCongr (Equiv.refl (Fin M))) r + (fun c => f (maskGrid clauseMask c)) + exact h + +theorem candidatePath_permutation {n : ℕ} [NeZero n] (M k : ℕ) + (e : Equiv.Perm (Fin n)) (r : ℝ≥0) + (f : (Fin M → Finset (DeletionCandidate n)) → ℝ) : + (FiniteLaw.pi (fun _ : Fin M => candidateBlock r k Finset.univ)).expect + (fun xs => f (fun j => renameMask e (xs j))) = + (FiniteLaw.pi (fun _ : Fin M => candidateBlock r k Finset.univ)).expect f := by + have hc : (Fintype.card (Fin k → SignedLiteral n) : ℝ≥0) ≠ 0 := by + exact_mod_cast Fintype.card_ne_zero + have h := gridMaskLaw_permutation (k := k) (M := M) e + (r/Fintype.card (Fin k → SignedLiteral n)) f + rw [gridMaskLaw_clauses, div_mul_cancel₀ _ hc] at h + exact h + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ExponentContinuity.lean b/lean/OAI/Probability/SATComputability/ExponentContinuity.lean new file mode 100644 index 0000000000000000000000000000000000000000..f4a83911e5e995adbc7a16e108dabbae6fccfb6e --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ExponentContinuity.lean @@ -0,0 +1,156 @@ +import OAI.Probability.DilutedSpin.FunctionalContinuity +import OAI.Probability.SATComputability.RationalExponents + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory Filter Set +open scoped Topology BigOperators NNReal + +local instance exponentContinuityMeasurable (X : TopCat) : MeasurableSpace X := borel X +local instance exponentContinuityBorel (X : TopCat) : BorelSpace X := ⟨rfl⟩ + +abbrev UnitExponents (r : ℕ) := {m : Fin r → ℝ // ∀ i, 0 < m i ∧ m i < 1} + +def exponentTail {r : ℕ} (m : UnitExponents (r+1)) : UnitExponents r := + ⟨fun i => m.val i.succ, fun i => m.property i.succ⟩ + +theorem exponentTail_continuous (r : ℕ) : + Continuous (exponentTail (r := r)) := by + apply Continuous.subtype_mk + exact continuous_pi (fun i => (continuous_apply i.succ).comp continuous_subtype_val) + +theorem logMean_continuous_exponents {ι : Type} [Fintype ι] + (r : ℕ) (g : (ι → ℝ) → ℝ) (hg : Continuous g) + {B : ℝ} (hB : ∀ x, |g x| ≤ B) (eta : ι → Hierarchy r) : + Continuous (fun m : UnitExponents r => logMean r g m.val eta) := by + induction r with + | zero => exact continuous_const + | succ r ih => + let (i : ι) : IsProbabilityMeasure ((eta i).toMeasure) := by + exact (eta i : ProbabilityMeasure (Hierarchy r)).property + have hBn : 0 ≤ B := (abs_nonneg (g (fun _ => 0))).trans (hB _) + have hc : Continuous (fun m : UnitExponents (r+1) => + ∫ x : ι → Hierarchy r, Real.exp (m.val 0 * logMean r g (fun i => m.val i.succ) x) + ∂Measure.pi (fun i => (eta i).toMeasure)) := by + apply continuous_of_dominated (bound := fun _ => Real.exp B) + · intro m + exact (Real.continuous_exp.comp ((logMean_continuous_bound r g hg hB _ + (fun i => (m.property i.succ).1)).1.const_mul (m.val 0))).aestronglyMeasurable + · intro m + apply ae_of_all + intro x + rw [Real.norm_eq_abs, abs_of_pos (Real.exp_pos _)] + apply Real.exp_le_exp.mpr + have hb := (logMean_continuous_bound r g hg hB _ + (fun i => (m.property i.succ).1)).2 x + calc + _ ≤ m.val 0 * B := mul_le_mul_of_nonneg_left (le_abs_self _ |>.trans hb) (m.property 0).1.le + _ ≤ B := by nlinarith [(m.property 0).2] + · exact integrable_const _ + · apply ae_of_all + intro x + exact Real.continuous_exp.comp (((continuous_apply 0).comp continuous_subtype_val).mul + ((ih x).comp (exponentTail_continuous r))) + have hpos (m : UnitExponents (r+1)) : + 0 < ∫ x : ι → Hierarchy r, + Real.exp (m.val 0 * logMean r g (fun i => m.val i.succ) x) + ∂Measure.pi (fun i => (eta i).toMeasure) := + MeasureMean.exp_integral_pos _ + (logMean_continuous_bound r g hg hB _ (fun i => (m.property i.succ).1)).1.measurable + (logMean_continuous_bound r g hg hB _ (fun i => (m.property i.succ).1)).2 _ + exact (hc.log (fun m => (hpos m).ne')).div + ((continuous_apply 0).comp continuous_subtype_val) (fun m => (m.property 0).1.ne') + +theorem trialLog_continuous_exponents {ι : Type} [Fintype ι] + (r : ℕ) (g : (ι → ℝ) → ℝ) (hg : Continuous g) + {B : ℝ} (hB : ∀ x, |g x| ≤ B) (ζ : Hierarchy (r+1)) : + Continuous (fun m : UnitExponents r => trialLog r ζ m.val g) := by + let : IsProbabilityMeasure ζ.toMeasure := (ζ : ProbabilityMeasure (Hierarchy r)).property + apply continuous_of_dominated (bound := fun _ => B) + · intro m + exact (logMean_continuous_bound r g hg hB m.val (fun i => (m.property i).1)).1.aestronglyMeasurable + · intro m + exact ae_of_all _ (fun eta => by + simpa only [Real.norm_eq_abs] using + (logMean_continuous_bound r g hg hB m.val (fun i => (m.property i).1)).2 eta) + · exact integrable_const _ + · exact ae_of_all _ (logMean_continuous_exponents r g hg hB) + +theorem functional_continuous_unit_exponents {p r : ℕ} (M : Model p) + (hθ : Integrable (fun z : InteractionSample p => ‖z.1‖) M.disorder.toMeasure) + (hh : Integrable (fun h : ℝ => |h|) M.field.toMeasure) + (ζ : Hierarchy (r+1)) : + Continuous (fun m : UnitExponents r => functional M r ζ m.val) := by + have hcfield (k : ℕ) (θ : Fin k → InteractionSample p) : + Continuous (fun m : UnitExponents r => trialSiteField M m.val ζ θ) := by + apply continuous_of_dominated (bound := fun h : ℝ => |h|+∑ j, ‖(θ j).1‖) + · intro m + exact (integrable_trial_site_field M m.val (fun i => (m.property i).1) hh ζ θ).aestronglyMeasurable + · intro m + exact ae_of_all _ (fun h => by + simpa only [Real.norm_eq_abs] using (trial_site_bound r m.val (fun i => (m.property i).1) ζ θ h)) + · exact hh.add (integrable_const _) + · exact ae_of_all _ (fun h => trialLog_continuous_exponents r _ + (continuous_siteLog θ h) (siteLog_bound θ h) ζ) + have hcdisorder (k : ℕ) : + Continuous (fun m : UnitExponents r => trialSiteDisorder M m.val ζ k) := by + apply continuous_of_dominated (bound := fun θ : Fin k → InteractionSample p => + (∫ h : ℝ, |h| ∂M.field.toMeasure)+∑ j, ‖(θ j).1‖) + · intro m + exact (stronglyMeasurable_trialSiteField M m.val (fun i => (m.property i).1) ζ k).aestronglyMeasurable + · intro m + exact ae_of_all _ (fun θ => by + simpa only [Real.norm_eq_abs] using (trialSiteField_bound M m.val (fun i => (m.property i).1) hh ζ θ)) + · exact (integrable_const _).add (interaction_sum_integrable M hθ k) + · exact ae_of_all _ (hcfield k) + have hcsite : Continuous (fun m : UnitExponents r => + ∫ k, trialSiteDisorder M m.val ζ k ∂poissonMeasure (M.alpha*p)) := by + apply continuous_of_dominated (bound := fun k : ℕ => + (∫ h : ℝ, |h| ∂M.field.toMeasure)+k*(∫ z : InteractionSample p, ‖z.1‖ ∂M.disorder.toMeasure)) + · intro m + exact (measurable_of_countable _).aestronglyMeasurable + · intro m + exact ae_of_all _ (fun k => by + simpa only [Real.norm_eq_abs] using (trialSiteDisorder_bound M m.val (fun i => (m.property i).1) hθ hh ζ k)) + · exact (integrable_const _).add ((poisson_integrable_count _).mul_const _) + · exact ae_of_all _ hcdisorder + have hcedge : Continuous (fun m : UnitExponents r => + ∫ θ : InteractionSample p, trialLog r ζ m.val (fun x => Real.log (edge θ.1 x)) + ∂M.disorder.toMeasure) := by + apply continuous_of_dominated (bound := fun θ : InteractionSample p => ‖θ.1‖) + · intro m + exact (((trial_edge_lipschitz r m.val (fun i => (m.property i).1) ζ).continuous.comp + continuous_fst).aestronglyMeasurable) + · intro m + exact ae_of_all _ (fun θ => by + simpa only [Real.norm_eq_abs] using (trial_edge_bound r m.val (fun i => (m.property i).1) ζ θ.1)) + · exact hθ + · exact ae_of_all _ (fun θ => trialLog_continuous_exponents r _ + (continuous_log_edge θ.1) (log_edge_bound θ.1) ζ) + exact (continuous_const.add hcsite).sub (continuous_const.mul hcedge) + +theorem isOpen_unit_exponents (r : ℕ) : + IsOpen {m : Fin r → ℝ | ∀ i, 0 < m i ∧ m i < 1} := by + have he : {m : Fin r → ℝ | ∀ i, 0 < m i ∧ m i < 1} = + ⋂ i : Fin r, {m | 0 < m i ∧ m i < 1} := by ext; simp + rw [he] + exact isOpen_iInter_of_finite (fun i => + (isOpen_lt continuous_const (continuous_apply i)).inter + (isOpen_lt (continuous_apply i) continuous_const)) + +theorem functional_continuousAt_exponents {p r : ℕ} (M : Model p) + (hθ : Integrable (fun z : InteractionSample p => ‖z.1‖) M.disorder.toMeasure) + (hh : Integrable (fun h : ℝ => |h|) M.field.toMeasure) + (ζ : Hierarchy (r+1)) {m : Fin r → ℝ} (hm : Exponents m) : + ContinuousAt (fun m => functional M r ζ m) m := by + have hc : ContinuousOn (fun m => functional M r ζ m) + {m : Fin r → ℝ | ∀ i, 0 < m i ∧ m i < 1} := + continuousOn_iff_continuous_domRestrict.mpr + (functional_continuous_unit_exponents M hθ hh ζ) + exact (hc m hm.2).continuousAt ((isOpen_unit_exponents r).mem_nhds hm.2) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/FiniteEnumeration.lean b/lean/OAI/Probability/SATComputability/FiniteEnumeration.lean new file mode 100644 index 0000000000000000000000000000000000000000..71876f00d7bb3f5c05958f16f19d8c054f9549b9 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/FiniteEnumeration.lean @@ -0,0 +1,323 @@ +import OAI.Probability.SATComputability.LowerBounds +import OAI.Probability.SATComputability.CertificateSearch +import OAI.MathematicalPhysics.RapidForcing.BoundsPrograms + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open RapidForcing.EffectiveArithmetic + +def words {α : Type*} (alphabet : List α) : ℕ → List (List α) + | 0 => [[]] + | n + 1 => alphabet.flatMap fun a => (words alphabet n).map (a :: ·) + +theorem mem_words {α : Type*} (alphabet : List α) (n : ℕ) (w : List α) : + w ∈ words alphabet n ↔ w.length = n ∧ ∀ a ∈ w, a ∈ alphabet := by + induction n generalizing w with + | zero => cases w <;> simp [words] + | succ n ih => + cases w with + | nil => simp [words] + | cons a w => simp [words, ih, and_assoc, and_left_comm] + +theorem nodup_words {α : Type*} {alphabet : List α} (ha : alphabet.Nodup) + (n : ℕ) : (words alphabet n).Nodup := by + induction n with + | zero => simp [words] + | succ n ih => + apply List.nodup_flatMap.mpr + refine ⟨fun a _ => ih.map (fun _ _ h => (List.cons.inj h).2), ?_⟩ + apply ha.imp + intro a b hab w haw hbw + obtain ⟨u, _, rfl⟩ := List.mem_map.mp haw + obtain ⟨v, _, hv⟩ := List.mem_map.mp hbw + exact hab (List.cons.inj hv).1.symm + +theorem words_primrec {α : Type*} [Primcodable α] : + Primrec₂ (@words α) := by + have h := Primrec.nat_rec' (f := fun p : List α × ℕ => p.2) + (g := fun _ => ([[]] : List (List α))) + (h := fun p q => p.1.flatMap fun a => q.2.map (a :: ·)) + Primrec.snd (Primrec.const _) ?_ + · exact h.of_eq fun p => by + induction p.2 <;> simp_all [words] + · apply Primrec.list_flatMap (Primrec.fst.comp Primrec.fst) + apply Primrec.list_map (Primrec.snd.comp (Primrec.snd.comp Primrec.fst)) + exact Primrec.list_cons.comp + (Primrec.snd.comp Primrec.fst) Primrec.snd + +private theorem length_of_enumeration {α β : Type*} [Fintype α] + [DecidableEq β] (l : List β) (hl : l.Nodup) (f : α → β) + (hf : Function.Injective f) (hm : ∀ b, b ∈ l ↔ ∃ a, f a = b) : + l.length = Fintype.card α := by + let g : α → ↥l.toFinset := fun a => ⟨f a, by simp [hm]⟩ + have hg : Function.Bijective g := by + constructor + · intro a b h + exact hf (congrArg Subtype.val h) + · intro b + obtain ⟨a, ha⟩ := (hm b).mp (List.mem_toFinset.mp b.property) + exact ⟨a, Subtype.ext ha⟩ + rw [← List.toFinset_card_of_nodup hl, ← Fintype.card_coe] + exact (Fintype.card_congr (Equiv.ofBijective g hg)).symm + +def clauseAlphabet : List (Option Bool) := [none, some false, some true] + +def clauseWords (n k : ℕ) : List (List (Option Bool)) := + (words clauseAlphabet n).filter fun c => (c.filter Option.isSome).length = k + +def encodeClause {n k : ℕ} (c : ProperClause n k) : List (Option Bool) := + List.ofFn c.val + +theorem literal_count_ofFn {n : ℕ} (c : Fin n → Option Bool) : + ((List.ofFn c).filter Option.isSome).length = + (Finset.univ.filter fun i => (c i).isSome).card := by + induction n with + | zero => simp + | succ n ih => + rw [List.ofFn_succ, Fin.card_filter_univ_succ] + simp only [List.filter_cons] + split <;> simp_all + +theorem mem_clauseWords_iff (n k : ℕ) (w : List (Option Bool)) : + w ∈ clauseWords n k ↔ ∃ c : ProperClause n k, encodeClause c = w := by + simp only [clauseWords, List.mem_filter, decide_eq_true_eq, mem_words] + constructor + · rintro ⟨⟨hlen, _⟩, hc⟩ + let f : Fin n → Option Bool := fun i => w.get ⟨i.val, by omega⟩ + have hf : List.ofFn f = w := by + subst n + exact List.ofFn_get w + have hp : (Finset.univ.filter fun i => (f i).isSome).card = k := by + rw [← literal_count_ofFn, hf] + exact hc + exact ⟨⟨f, hp⟩, hf⟩ + · rintro ⟨c, rfl⟩ + refine ⟨⟨List.length_ofFn, ?_⟩, ?_⟩ + · intro a _ + cases a with + | none => simp [clauseAlphabet] + | some b => cases b <;> simp [clauseAlphabet] + · simpa only [encodeClause, literal_count_ofFn] using c.property + +theorem encodeClause_injective {n k : ℕ} : + Function.Injective (@encodeClause n k) := by + intro a b h + apply Subtype.ext + exact List.ofFn_injective h + +def formulaWords (n k m : ℕ) : List (List (List (Option Bool))) := + words (clauseWords n k) m + +def encodeFormula {n k m : ℕ} (f : Formula n k m) : List (List (Option Bool)) := + List.ofFn fun j => encodeClause (f j) + +theorem encodeFormula_injective {n k m : ℕ} : + Function.Injective (@encodeFormula n k m) := by + intro a b h + have he := List.ofFn_injective h + funext j + exact encodeClause_injective (congrFun he j) + +theorem mem_formulaWords_iff (n k m : ℕ) (w : List (List (Option Bool))) : + w ∈ formulaWords n k m ↔ ∃ f : Formula n k m, encodeFormula f = w := by + rw [formulaWords, mem_words] + constructor + · rintro ⟨hlen, hw⟩ + have hget (i : Fin m) : ∃ c : ProperClause n k, + encodeClause c = w.get ⟨i.val, by omega⟩ := + (mem_clauseWords_iff n k _).mp + (hw _ (List.get_mem w ⟨i.val, by omega⟩)) + choose f hf using hget + refine ⟨f, ?_⟩ + unfold encodeFormula + simp_rw [hf] + subst m + exact List.ofFn_get w + · rintro ⟨f, rfl⟩ + refine ⟨List.length_ofFn, ?_⟩ + intro c hc + obtain ⟨i, rfl⟩ := List.mem_ofFn.mp hc + exact (mem_clauseWords_iff n k _).mpr ⟨f i, rfl⟩ + +theorem formulaWords_length (n k m : ℕ) : + (formulaWords n k m).length = Fintype.card (Formula n k m) := by + apply length_of_enumeration _ _ encodeFormula encodeFormula_injective + (mem_formulaWords_iff n k m) + exact nodup_words ((nodup_words (by decide : clauseAlphabet.Nodup) n).filter _) m + +def clauseHolds (s : List Bool) (c : List (Option Bool)) : Prop := + ∃ i ∈ List.range s.length, c.getD i none = some (s.getD i false) + +instance (s : List Bool) (c : List (Option Bool)) : Decidable (clauseHolds s c) := by + unfold clauseHolds + infer_instance + +def formulaHolds (s : List Bool) (f : List (List (Option Bool))) : Prop := + ∀ c ∈ f, clauseHolds s c + +instance (s : List Bool) (f : List (List (Option Bool))) : Decidable (formulaHolds s f) := by + unfold formulaHolds + infer_instance + +def formulaSatisfiable (n : ℕ) (f : List (List (Option Bool))) : Prop := + ∃ s ∈ words [false, true] n, formulaHolds s f + +instance (n : ℕ) (f : List (List (Option Bool))) : Decidable (formulaSatisfiable n f) := by + unfold formulaSatisfiable + infer_instance + +theorem clauseHolds_ofFn {n k : ℕ} (s : Assignment n) (c : ProperClause n k) : + clauseHolds (List.ofFn s) (encodeClause c) ↔ SatisfiesClause s c := by + simp only [clauseHolds, List.length_ofFn, List.mem_range, SatisfiesClause] + constructor + · rintro ⟨i, hi, h⟩ + exact ⟨⟨i, hi⟩, by simpa [encodeClause, List.getD, hi] using h⟩ + · rintro ⟨i, hi⟩ + exact ⟨i.val, i.isLt, by simpa [encodeClause, List.getD, i.isLt] using hi⟩ + +theorem formulaHolds_ofFn {n k m : ℕ} (s : Assignment n) (f : Formula n k m) : + formulaHolds (List.ofFn s) (encodeFormula f) ↔ Satisfies s f := by + constructor + · intro h j + exact (clauseHolds_ofFn s (f j)).mp (h _ (List.mem_ofFn.mpr ⟨j, rfl⟩)) + · intro h c hc + obtain ⟨j, rfl⟩ := List.mem_ofFn.mp hc + exact (clauseHolds_ofFn s (f j)).mpr (h j) + +theorem formulaSatisfiable_encode {n k m : ℕ} (f : Formula n k m) : + formulaSatisfiable n (encodeFormula f) ↔ Satisfiable f := by + constructor + · rintro ⟨s, hs, hf⟩ + obtain ⟨hlen, _⟩ := (mem_words _ _ _).mp hs + let a : Assignment n := fun i => s.get ⟨i.val, by omega⟩ + have ha : List.ofFn a = s := by subst n; exact List.ofFn_get s + exact ⟨a, (formulaHolds_ofFn a f).mp (ha ▸ hf)⟩ + · rintro ⟨s, hs⟩ + refine ⟨List.ofFn s, (mem_words _ _ _).mpr ⟨List.length_ofFn, ?_⟩, + (formulaHolds_ofFn s f).mpr hs⟩ + intro b _ + cases b <;> simp + +def satisfiableWords (n k m : ℕ) : List (List (List (Option Bool))) := + (formulaWords n k m).filter (formulaSatisfiable n) + +theorem satisfiableWords_length (n k m : ℕ) : + (satisfiableWords n k m).length = + Fintype.card {f : Formula n k m // Satisfiable f} := by + refine length_of_enumeration _ ?_ (fun f => encodeFormula f.val) ?_ ?_ + · exact ((nodup_words ((nodup_words (by decide : clauseAlphabet.Nodup) n).filter _) m).filter _) + · intro a b h + exact Subtype.ext (encodeFormula_injective h) + · intro w + simp only [satisfiableWords, List.mem_filter, decide_eq_true_eq, mem_formulaWords_iff] + constructor + · rintro ⟨⟨f, rfl⟩, hf⟩ + exact ⟨⟨f, formulaSatisfiable_encode f |>.mp hf⟩, rfl⟩ + · rintro ⟨⟨f, hf⟩, rfl⟩ + exact ⟨⟨f, rfl⟩, (formulaSatisfiable_encode f).mpr hf⟩ + +def enumeratedProbability (n k m : ℕ) : ℚ := + (satisfiableWords n k m).length / (formulaWords n k m).length + +theorem enumeratedProbability_eq (n k m : ℕ) : + enumeratedProbability n k m = rationalProbability n k m := by + simp only [enumeratedProbability, satisfiableWords_length, formulaWords_length, + rationalProbability] + +theorem clauseWords_primrec : Primrec₂ clauseWords := by + have hi : PrimrecPred (fun c : Option Bool => c.isSome) := + Primrec.eq.comp Primrec.option_isSome (Primrec.const true) + have hc : Primrec (fun c : List (Option Bool) => (c.filter Option.isSome).length) := by + simpa only [decide_eq_true_eq, Bool.decide_coe] using + Primrec.list_length.comp (Primrec.listFilter hi) + have hp : PrimrecRel (fun c : List (Option Bool) => fun k : ℕ => + (c.filter Option.isSome).length = k) := + Primrec.eq.comp (hc.comp Primrec.fst) Primrec.snd + exact hp.listFilter.comp + (words_primrec.comp (Primrec.const clauseAlphabet) Primrec.fst) Primrec.snd + +theorem formulaWords_primrec : Primrec (fun p : ℕ × ℕ × ℕ => + formulaWords p.1 p.2.1 p.2.2) := by + exact words_primrec.comp + (clauseWords_primrec.comp Primrec.fst (Primrec.fst.comp Primrec.snd)) + (Primrec.snd.comp Primrec.snd) + +theorem clauseHolds_primrec : PrimrecRel clauseHolds := by + have hbase : PrimrecRel (fun i : ℕ => fun p : List Bool × List (Option Bool) => + p.2.getD i none = some (p.1.getD i false)) := + Primrec.eq.comp + ((Primrec.list_getD none).comp (Primrec.snd.comp Primrec.snd) Primrec.fst) + (Primrec.option_some.comp + ((Primrec.list_getD false).comp (Primrec.fst.comp Primrec.snd) Primrec.fst)) + exact hbase.exists_mem_list.comp + (Primrec.list_range.comp (Primrec.list_length.comp Primrec.fst)) Primrec.id + +theorem formulaHolds_primrec : PrimrecRel formulaHolds := by + have hc : PrimrecRel (fun c : List (Option Bool) => fun s : List Bool => + clauseHolds s c) := clauseHolds_primrec.comp Primrec.snd Primrec.fst + exact hc.forall_mem_list.comp Primrec.snd Primrec.fst + +theorem formulaSatisfiable_primrec : PrimrecRel formulaSatisfiable := by + exact formulaHolds_primrec.exists_mem_list.comp + (words_primrec.comp (Primrec.const [false, true]) Primrec.fst) Primrec.snd + +theorem satisfiableWords_primrec : Primrec (fun p : ℕ × ℕ × ℕ => + satisfiableWords p.1 p.2.1 p.2.2) := by + have hs : PrimrecRel (fun f : List (List (Option Bool)) => fun n : ℕ => + formulaSatisfiable n f) := formulaSatisfiable_primrec.comp Primrec.snd Primrec.fst + exact hs.listFilter.comp formulaWords_primrec Primrec.fst + +@[fun_prop] theorem rationalProbability_computable : + Computable (fun p : ℕ × ℕ × ℕ => rationalProbability p.1 p.2.1 p.2.2) := by + have hn := (Primrec.list_length.comp satisfiableWords_primrec).to_comp + have hd := (Primrec.list_length.comp formulaWords_primrec).to_comp + have he : Computable (fun p : ℕ × ℕ × ℕ => enumeratedProbability p.1 p.2.1 p.2.2) := by + unfold enumeratedProbability + fun_prop + exact he.of_eq (fun p => enumeratedProbability_eq p.1 p.2.1 p.2.2) + +attribute [local irreducible] rationalProbability + +private theorem probabilities_map_computable : + Computable₂ (fun p : ℕ × ℕ => fun j : ℕ => + rationalProbability p.1 p.2 (j + 1)) := by + have hi : Computable (fun p : (ℕ × ℕ) × ℕ => (p.1.1, p.1.2, p.2 + 1)) := by + fun_prop + change Computable (fun p : (ℕ × ℕ) × ℕ => + (fun q : ℕ × ℕ × ℕ => rationalProbability q.1 q.2.1 q.2.2) + (p.1.1, p.1.2, p.2 + 1)) + exact Computable.comp rationalProbability_computable hi + +private theorem cap_computable : Computable (fun p : ℕ × ℕ => mainCap p.1 p.2) := by + unfold mainCap capMultiplier + fun_prop + +@[fun_prop] theorem rationalCenter_computable : + Computable (fun p : ℕ × ℕ => rationalCenter p.1 p.2) := by + have hs : Computable (fun p : ℕ × ℕ => + ((List.range (mainCap p.1 p.2)).map fun j => + rationalProbability p.1 p.2 (j + 1)).sum) := by + apply (computable_list_sum computable_rat_add).comp + apply computable_list_map + · exact Primrec.list_range.to_comp.comp cap_computable + · exact probabilities_map_computable + have he : Computable (fun p : ℕ × ℕ => + ((List.range (mainCap p.1 p.2)).map fun j => + rationalProbability p.1 p.2 (j + 1)).sum / p.1) := by fun_prop + apply he.of_eq + intro p + have hl (N : ℕ) : + ((List.range N).map fun j => rationalProbability p.1 p.2 (j + 1)).sum = + ∑ j ∈ Finset.range N, rationalProbability p.1 p.2 (j + 1) := by + induction N with + | zero => simp + | succ N ih => simp [List.range_succ, Finset.sum_range_succ, ih] + change _ = rationalCenter p.1 p.2 + unfold rationalCenter + rw [hl] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/FiniteProductPushforward.lean b/lean/OAI/Probability/SATComputability/FiniteProductPushforward.lean new file mode 100644 index 0000000000000000000000000000000000000000..eb676dabe4a6dee5ce89c81b5ac8a02675bee53a --- /dev/null +++ b/lean/OAI/Probability/SATComputability/FiniteProductPushforward.lean @@ -0,0 +1,62 @@ +import OAI.Probability.SATComputability.FinitePushforward +import Mathlib.MeasureTheory.Integral.Pi + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory +open scoped BigOperators Classical + +theorem product_indicator_eq {I : Type*} [Fintype I] {X : I → Type*} + (x y : ∀ i, X i) : + (if x = y then (1 : ℝ) else 0) = ∏ i, if x i = y i then 1 else 0 := by + by_cases h : x = y + · simp [h] + · obtain ⟨i,hi⟩ := Function.ne_iff.mp h + rw [ite_eq_right h] + exact (Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi)).symm + +theorem finitePushforward_pi {I : Type*} [Fintype I] [DecidableEq I] + {X Y : I → Type*} [∀ i, MeasurableSpace (X i)] [∀ i, Fintype (Y i)] + [∀ i, MeasurableSpace (Y i)] [∀ i, MeasurableSingletonClass (Y i)] + (μ : ∀ i, Measure (X i)) [∀ i, IsProbabilityMeasure (μ i)] + (g : ∀ i, X i → Y i) (hg : ∀ i, Measurable (g i)) : + finitePushforward (Measure.pi μ) (fun x i => g i (x i)) + (Measurable.of_eval (fun i => (hg i).comp (measurable_pi_apply i))) = + FiniteLaw.pi (fun i => finitePushforward (μ i) (g i) (hg i)) := by + classical + let : DecidableEq ((i : I) → Y i) := Classical.decEq _ + apply FiniteLaw.weights_ext + intro y + simp only [finitePushforward, FiniteLaw.pi] + have he (x : ∀ i, X i) : + (if (fun i => g i (x i)) = y then (1 : ℝ) else 0) = + ∏ i, if g i (x i) = y i then (1 : ℝ) else 0 := by + by_cases h : (fun i => g i (x i)) = y + · have hh (i : I) := congrFun h i + simp [hh] + · rw [ite_eq_right h] + obtain ⟨i,hi⟩ := Function.ne_iff.mp h + exact (Finset.prod_eq_zero (Finset.mem_univ i) (ite_eq_right hi)).symm + exact (integral_congr_ae (ae_of_all (Measure.pi μ) he)).trans + (integral_fintype_prod_eq_prod (μ := μ) (fun i x => if g i x = y i then (1 : ℝ) else 0)) + +theorem finitePushforward_congr {X Y : Type*} [MeasurableSpace X] + [Fintype Y] [MeasurableSpace Y] [MeasurableSingletonClass Y] + (μ : Measure X) [IsProbabilityMeasure μ] (f g : X → Y) + (hf : Measurable f) (hg : Measurable g) (he : ∀ x, f x = g x) : + finitePushforward μ f hf = finitePushforward μ g hg := by + cases funext he + rfl + +theorem finiteLaw_eq_of_expect {Y : Type*} [Fintype Y] (P Q : FiniteLaw Y) + (h : ∀ f, P.expect f = Q.expect f) : P = Q := by + apply FiniteLaw.weights_ext + intro y + simpa only [FiniteLaw.expect, mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', + Finset.mem_univ, ite_true] using h (fun x => if x = y then 1 else 0) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/FinitePushforward.lean b/lean/OAI/Probability/SATComputability/FinitePushforward.lean new file mode 100644 index 0000000000000000000000000000000000000000..adcf338358abf19357372d6d8a1ffc287ccc083e --- /dev/null +++ b/lean/OAI/Probability/SATComputability/FinitePushforward.lean @@ -0,0 +1,53 @@ +import OAI.Probability.SATComputability.IncidentMasks +import OAI.Probability.SATComputability.PoissonCounts + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators Classical + +theorem finite_indicator_integrable {X Y : Type*} [MeasurableSpace X] + [Fintype Y] [MeasurableSpace Y] [MeasurableSingletonClass Y] + (μ : Measure X) [IsProbabilityMeasure μ] (g : X → Y) (hg : Measurable g) (y : Y) : + Integrable (fun x => if g x = y then (1 : ℝ) else 0) μ := by + apply Integrable.of_bound + (((measurable_of_countable (fun z : Y => if z = y then (1 : ℝ) else 0)).comp hg).aestronglyMeasurable) 1 + filter_upwards [] with x + dsimp only [Function.comp_def] + split_ifs <;> norm_num + +noncomputable def finitePushforward {X Y : Type*} [MeasurableSpace X] + [Fintype Y] [MeasurableSpace Y] [MeasurableSingletonClass Y] + (μ : Measure X) [IsProbabilityMeasure μ] (g : X → Y) (hg : Measurable g) : FiniteLaw Y where + weight y := ∫ x, if g x = y then 1 else 0 ∂μ + nonneg y := integral_nonneg (fun x => by split_ifs <;> norm_num) + total := by + rw [← integral_finsetSum _ (fun y _ => finite_indicator_integrable μ g hg y)] + simp + +theorem finitePushforward_expect {X Y : Type*} [MeasurableSpace X] + [Fintype Y] [MeasurableSpace Y] [MeasurableSingletonClass Y] + (μ : Measure X) [IsProbabilityMeasure μ] (g : X → Y) (hg : Measurable g) (f : Y → ℝ) : + (finitePushforward μ g hg).expect f = ∫ x, f (g x) ∂μ := by + simp only [FiniteLaw.expect, finitePushforward] + simp_rw [← integral_mul_const] + rw [← integral_finsetSum _ (fun y _ => (finite_indicator_integrable μ g hg y).mul_const (f y))] + apply integral_congr_ae + filter_upwards [] with x + simp + +theorem bounded_finite_observable {X Y : Type*} [MeasurableSpace X] + [Fintype Y] [MeasurableSpace Y] [MeasurableSingletonClass Y] + (μ : Measure X) [IsProbabilityMeasure μ] (g : X → Y) (hg : Measurable g) (f : Y → ℝ) : + Integrable (fun x => f (g x)) μ := by + apply Integrable.of_bound ((measurable_of_countable f).comp hg).aestronglyMeasurable + (∑ y, |f y|) + filter_upwards [] with x + rw [Real.norm_eq_abs] + exact Finset.single_le_sum (fun y _ => abs_nonneg (f y)) (Finset.mem_univ (g x)) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/FiniteTrialEvaluation.lean b/lean/OAI/Probability/SATComputability/FiniteTrialEvaluation.lean new file mode 100644 index 0000000000000000000000000000000000000000..ed2d8d0dc2eb3ce5572271c17cb3e8837c8a120f --- /dev/null +++ b/lean/OAI/Probability/SATComputability/FiniteTrialEvaluation.lean @@ -0,0 +1,58 @@ +import OAI.Probability.SATComputability.RationalHierarchy +import OAI.Probability.DilutedSpin.QSubtreePotential + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory +open scoped BigOperators + +local instance finiteTrialEvaluationMeasurable (X : TopCat) : MeasurableSpace X := borel X +local instance finiteTrialEvaluationBorel (X : TopCat) : BorelSpace X := ⟨rfl⟩ + +noncomputable def finiteLogMean {ι : Type} [Fintype ι] : + (r : ℕ) → ((ι → ℝ) → ℝ) → (Fin r → ℝ) → (ι → RationalTree r) → ℝ + | 0, g, _, t => g (fun i => Rat.cast (K := ℝ) (t i)) + | r+1, g, m, t => by + classical + exact Real.log ((FiniteLaw.pi (fun i => (t i).2.1.toLaw)).expect (fun a => + Real.exp (m 0 * finiteLogMean r g (fun j => m j.succ) (fun i => (t i).2.2 (a i))))) / m 0 + +theorem rationalTreeValue_asProbability (r : ℕ) (t : RationalTree (r+1)) : + rationalTreeValue (r+1) t = + t.2.1.toLaw.asProbability (fun a => rationalTreeValue r (t.2.2 a)) := by + rfl + +theorem finiteLogMean_eq {ι : Type} [Fintype ι] (r : ℕ) + (g : (ι → ℝ) → ℝ) (m : Fin r → ℝ) (t : ι → RationalTree r) : + finiteLogMean r g m t = logMean r g m (fun i => rationalTreeValue r (t i)) := by + classical + induction r with + | zero => rfl + | succ r ih => + simp only [finiteLogMean, logMean, rationalTreeValue_asProbability] + rw [FiniteLaw.integral_pi_asProbability] + congr 2 + apply FiniteLaw.expect_congr + intro a + rw [ih] + +noncomputable def finiteTrialLog {ι : Type} [Fintype ι] (r : ℕ) + (t : RationalTree (r+1)) (m : Fin r → ℝ) (g : (ι → ℝ) → ℝ) : ℝ := by + classical + exact (FiniteLaw.pi (fun _ : ι => t.2.1.toLaw)).expect + (fun a => finiteLogMean r g m (fun i => t.2.2 (a i))) + +theorem finiteTrialLog_eq {ι : Type} [Fintype ι] (r : ℕ) + (t : RationalTree (r+1)) (m : Fin r → ℝ) (g : (ι → ℝ) → ℝ) : + finiteTrialLog r t m g = trialLog r (rationalTreeValue (r+1) t) m g := by + classical + rw [trialLog, rationalTreeValue_asProbability, FiniteLaw.integral_pi_asProbability] + apply FiniteLaw.expect_congr + intro a + exact finiteLogMean_eq r g m _ + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/GridBlockLaw.lean b/lean/OAI/Probability/SATComputability/GridBlockLaw.lean new file mode 100644 index 0000000000000000000000000000000000000000..6650a85a02c0328bc938696919a84b3cebd69453 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/GridBlockLaw.lean @@ -0,0 +1,70 @@ +import OAI.Probability.SATComputability.ClauseProcess + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal Classical + +local instance gridBlockCandidateMeasurable (n : ℕ) : + MeasurableSpace (DeletionCandidate n) := ⊤ +local instance gridBlockCandidateSingleton (n : ℕ) : + MeasurableSingletonClass (DeletionCandidate n) := ⟨fun _ => trivial⟩ + +theorem gridMaskLaw_pi_of_expect {A : Type*} [Fintype A] {n M : ℕ} + (r : ℝ≥0) (mask : A → Finset (DeletionCandidate n)) + (Q : FiniteLaw (Finset (DeletionCandidate n))) + (hQ : ∀ f, Q.expect f = ∫ c, f (countsMask mask c) ∂poissonCountLaw A r) : + gridMaskLaw M r mask = FiniteLaw.pi (fun _ : Fin M => Q) := by + classical + let μ := poissonCountLaw A r + have hsingle : finitePushforward μ (countsMask mask) (measurable_of_countable _) = Q := by + apply finiteLaw_eq_of_expect + intro f + rw [finitePushforward_expect] + exact (hQ f).symm + apply finiteLaw_eq_of_expect + intro f + rw [gridMaskLaw_expect] + have htranspose := poissonCountLaw_equiv (Equiv.prodComm (Fin M) A) r + (fun c => f (maskGrid mask c)) + rw [← htranspose, ← poissonCountLaw_uncurry_integral] + change (∫ c : Fin M → A → ℕ, f (fun j => countsMask mask (c j)) + ∂Measure.pi (fun _ : Fin M => μ)) = _ + rw [← finitePushforward_expect (Measure.pi (fun _ : Fin M => μ)) + (fun c j => countsMask mask (c j)) + (Measurable.of_eval (fun j => (measurable_of_countable (countsMask mask)).comp + (measurable_pi_apply j))) f, + finitePushforward_pi _ _ (fun _ => measurable_of_countable _)] + simp only [hsingle] + +theorem gridMaskLaw_equiv {A B : Type} [Fintype A] [Fintype B] {n M : ℕ} + (e : A ≃ B) (r : ℝ≥0) (mask : B → Finset (DeletionCandidate n)) : + gridMaskLaw M r (mask ∘ e) = gridMaskLaw M r mask := by + apply finiteLaw_eq_of_expect + intro f + simp only [gridMaskLaw_expect] + have he (c : A × Fin M → ℕ) : + maskGrid (mask ∘ e) c = maskGrid mask (c ∘ (e.prodCongr (Equiv.refl (Fin M))).symm) := by + funext j + exact countsMask_equiv e mask (fun a => c (a,j)) + simp only [he] + simpa only [Function.comp_def] using + poissonCountLaw_equiv (e.prodCongr (Equiv.refl (Fin M))) r (fun c => f (maskGrid mask c)) + +theorem gridMaskLaw_clauses {n : ℕ} [NeZero n] (M k : ℕ) (r : ℝ≥0) : + gridMaskLaw M r (clauseMask (n := n) (k := k)) = + FiniteLaw.pi (fun _ : Fin M => candidateBlock + (r*Fintype.card (Fin k → SignedLiteral n)) k Finset.univ) := by + apply gridMaskLaw_pi_of_expect + intro f + rw [candidateBlock_counts] + simp only [mul_div_cancel_right₀ _ (show + (Fintype.card (Fin k → SignedLiteral n) : ℝ≥0) ≠ 0 by + exact_mod_cast Fintype.card_ne_zero)] + rfl + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/HierarchyBounds.lean b/lean/OAI/Probability/SATComputability/HierarchyBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..233c623a2a49353fe56c7851d7fe8603201ed28b --- /dev/null +++ b/lean/OAI/Probability/SATComputability/HierarchyBounds.lean @@ -0,0 +1,66 @@ +import OAI.Probability.SATComputability.HierarchyEncoding +import OAI.Probability.SATComputability.FiniteEnumeration + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Encodable Denumerable Nat.Partrec + +theorem branchEntry_code_le (c : Code) : encode (branchEntry c).2 ≤ encode c := by + cases c with + | comp w c => exact (Code.encode_lt_comp w c).2.le + | zero => rfl + | succ => exact Nat.zero_le _ + | left => exact Nat.zero_le _ + | right => exact Nat.zero_le _ + | pair c d => exact Nat.zero_le _ + | prec c d => exact Nat.zero_le _ + | rfind' c => exact Nat.zero_le _ + +theorem rawBranches_code_le (c : Code) : + ∀ b ∈ rawBranches c, encode b.2 ≤ encode c := by + induction c with + | pair c d _ ih => + intro b hb + rcases List.mem_cons.mp hb with h | h + · subst b + exact (branchEntry_code_le c).trans (Code.encode_lt_pair c d).1.le + · exact (ih b h).trans (Code.encode_lt_pair c d).2.le + | zero | succ | left | right | comp _ _ _ _ | prec _ _ _ _ | rfind' _ _ => + simp only [rawBranches, List.not_mem_nil, false_implies, implies_true] + +theorem normalizedBranches_code_le (c : Code) : + ∀ b ∈ normalizedBranches c, encode b.2 ≤ encode c := by + dsimp only [normalizedBranches] + split_ifs + · intro b hb + have h : b = (1, Code.zero) := by simpa only [List.mem_singleton] using hb + subst b + exact Nat.zero_le _ + · intro b hb + obtain ⟨x, hx, rfl⟩ := List.mem_map.mp hb + exact rawBranches_code_le c x hx + +def codeAlphabet (bound : ℕ) : List Code := + (List.range (bound+1)).map (ofNat Code) + +theorem mem_codeAlphabet (bound : ℕ) (c : Code) : + c ∈ codeAlphabet bound ↔ encode c ≤ bound := by + constructor + · intro h + obtain ⟨n, hn, rfl⟩ := List.mem_map.mp h + simpa only [List.mem_range, encode_ofNat, Nat.lt_succ_iff] using hn + · intro h + exact List.mem_map.mpr ⟨encode c, List.mem_range.mpr (Nat.lt_succ_iff.mpr h), ofNat_encode c⟩ + +def hierarchyStates (bound labels : ℕ) : List (List Code) := words (codeAlphabet bound) labels + +theorem mem_hierarchyStates (bound labels : ℕ) (cs : List Code) : + cs ∈ hierarchyStates bound labels ↔ + cs.length = labels ∧ ∀ c ∈ cs, encode c ≤ bound := by + simp only [hierarchyStates, mem_words, mem_codeAlphabet] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/HierarchyEncoding.lean b/lean/OAI/Probability/SATComputability/HierarchyEncoding.lean new file mode 100644 index 0000000000000000000000000000000000000000..6e932185a784e914e0757d7ea742a3902b939001 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/HierarchyEncoding.lean @@ -0,0 +1,145 @@ +import OAI.Probability.SATComputability.RationalHierarchy +import OAI.Probability.SATComputability.ArithmeticConstructors + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Encodable Denumerable Nat.Partrec FiniteArithmetic +open scoped BigOperators +local instance hierarchyEncodingRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +noncomputable def branchEntry : Code → ℚ × Code + | .comp w c => (decodedRational w, c) + | _ => (0, .zero) + +noncomputable def rawBranches : Code → List (ℚ × Code) + | .pair c rest => branchEntry c :: rawBranches rest + | _ => [] + +noncomputable def encodeBranches (bs : List (ℚ × Code)) : Code := + bs.foldr (fun b rest => .pair (.comp (ofNat Code (encode b.1)) b.2) rest) .zero + +theorem rawBranches_encode (bs : List (ℚ × Code)) : rawBranches (encodeBranches bs) = bs := by + induction bs with + | nil => rfl + | cons b bs ih => + simp only [encodeBranches, List.foldr_cons, rawBranches, branchEntry, decodedRational, + encode_ofNat, encodek, Option.getD_some] + exact congrArg (b :: ·) ih + +noncomputable def normalizedBranches (c : Code) : List (ℚ × Code) := + let bs := rawBranches c + let s := (bs.map (fun b => |b.1|)).sum + if s = 0 then [(1, .zero)] else bs.map (fun b => (|b.1|/s, b.2)) + +theorem normalizedBranches_nonneg (c : Code) : + ∀ b ∈ normalizedBranches c, 0 ≤ b.1 := by + dsimp only [normalizedBranches] + split_ifs with hs + · simp + · intro b hb + obtain ⟨x, _, rfl⟩ := List.mem_map.mp hb + exact div_nonneg (abs_nonneg _) (List.sum_nonneg (fun _ hx => by + obtain ⟨y, _, rfl⟩ := List.mem_map.mp hx + exact abs_nonneg _)) + +theorem normalizedBranches_sum (c : Code) : + ((normalizedBranches c).map Prod.fst).sum = 1 := by + dsimp only [normalizedBranches] + split_ifs with hs + · simp + · simp only [List.map_map, Function.comp_def] + simp only [div_eq_mul_inv] + rw [List.sum_map_mul_right] + exact mul_inv_cancel₀ hs + +theorem normalizedBranches_encode {bs : List (ℚ × Code)} + (hpos : ∀ b ∈ bs, 0 ≤ b.1) (hs : (bs.map Prod.fst).sum = 1) : + normalizedBranches (encodeBranches bs) = bs := by + have ha : bs.map (fun b => |b.1|) = bs.map Prod.fst := by + apply List.map_congr_left + intro b hb + exact abs_of_nonneg (hpos b hb) + simp only [normalizedBranches, rawBranches_encode, ha, hs, one_ne_zero, ite_false, div_one] + conv_rhs => rw [← List.map_id bs] + apply List.map_congr_left + intro b hb + exact Prod.ext (abs_of_nonneg (hpos b hb)) rfl + +noncomputable def branchWeights (c : Code) : + RationalWeights (Fin (normalizedBranches c).length) := + ⟨fun i => ((normalizedBranches c).get i).1, by + constructor + · intro i + exact normalizedBranches_nonneg c _ (List.get_mem _ _) + · have h : (List.ofFn (fun i : Fin (normalizedBranches c).length => + ((normalizedBranches c).get i).1)).sum = 1 := by + simp only [List.get_eq_getElem] + rw [List.ofFn_getElem_eq_map, normalizedBranches_sum] + simpa only [List.sum_ofFn] using h⟩ + +noncomputable def decodeTree : (r : ℕ) → Code → RationalTree r + | 0, c => decodedRational c + | r+1, c => ⟨(normalizedBranches c).length, branchWeights c, + fun i => decodeTree r ((normalizedBranches c).get i).2⟩ + +noncomputable def encodeTree : (r : ℕ) → RationalTree r → Code + | 0, q => ofNat Code (@encode ℚ Rat.instEncodable q) + | r+1, t => encodeBranches (List.ofFn (fun i : Fin t.1 => + (t.2.1.val i, encodeTree r (t.2.2 i)))) + +theorem normalizedBranches_encodeTree (r : ℕ) (t : RationalTree (r+1)) : + normalizedBranches (encodeTree (r+1) t) = + List.ofFn (fun i : Fin t.1 => (t.2.1.val i, encodeTree r (t.2.2 i))) := by + apply normalizedBranches_encode + · intro b hb + obtain ⟨i, rfl⟩ := List.mem_ofFn.mp hb + exact t.2.1.property.1 i + · rw [List.map_ofFn, List.sum_ofFn] + exact t.2.1.property.2 + +theorem rationalTree_node_ext {r n k : ℕ} (hn : n = k) + (w : RationalWeights (Fin n)) (v : RationalWeights (Fin k)) + (x : Fin n → RationalTree r) (y : Fin k → RationalTree r) + (hw : ∀ i, w.val i = v.val (Fin.cast hn i)) + (hx : ∀ i, x i = y (Fin.cast hn i)) : + (⟨n, w, x⟩ : RationalTree (r+1)) = ⟨k, v, y⟩ := by + subst k + apply congrArg (Sigma.mk n) + apply Prod.ext + · exact Subtype.ext (funext hw) + · exact funext hx + +theorem decodeTree_encodeTree (r : ℕ) (t : RationalTree r) : + decodeTree r (encodeTree r t) = t := by + induction r with + | zero => + change decodedRational (ofNat Code (@encode ℚ Rat.instEncodable t)) = t + simp only [decodedRational, encode_ofNat] + exact congrArg (fun o : Option ℚ => o.getD 0) (@Encodable.encodek ℚ Rat.instEncodable t) + | succ r ih => + obtain ⟨n, w, x⟩ := t + let c := encodeTree (r+1) ⟨n, w, x⟩ + have he : normalizedBranches c = + List.ofFn (fun i : Fin n => (w.val i, encodeTree r (x i))) := + normalizedBranches_encodeTree r ⟨n, w, x⟩ + change (⟨(normalizedBranches c).length, branchWeights c, + fun i => decodeTree r ((normalizedBranches c).get i).2⟩ : + Σ k : ℕ, RationalWeights (Fin k) × (Fin k → RationalTree r)) = ⟨n, w, x⟩ + have hn : (normalizedBranches c).length = n := by rw [he, List.length_ofFn] + apply rationalTree_node_ext hn + · intro i + change ((normalizedBranches c).get i).1 = w.val (Fin.cast hn i) + simp only [List.get_eq_getElem, he, List.getElem_ofFn] + rfl + · intro i + simp only [List.get_eq_getElem, he, List.getElem_ofFn] + exact ih (x (Fin.cast hn i)) + +theorem decodeTree_surjective (r : ℕ) : Function.Surjective (decodeTree r) := + fun t => ⟨encodeTree r t, decodeTree_encodeTree r t⟩ + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/HierarchyEvaluator.lean b/lean/OAI/Probability/SATComputability/HierarchyEvaluator.lean new file mode 100644 index 0000000000000000000000000000000000000000..0e5eb6ee33f21d7a430bb1b8e9327ae8d21d15c8 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/HierarchyEvaluator.lean @@ -0,0 +1,109 @@ +import OAI.Probability.SATComputability.HierarchySemantics + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Encodable Denumerable Nat.Partrec FiniteArithmetic RapidForcing.EffectiveArithmetic +local instance hierarchyEvaluatorRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +@[fun_prop] theorem codeAlphabet_computable : Computable codeAlphabet := by + unfold codeAlphabet + apply computable_list_map (by fun_prop) + exact ((Primrec.ofNat Code).to_comp.comp Computable.snd).to₂ + +@[fun_prop] theorem hierarchyStates_computable : + Computable (fun p : ℕ × ℕ => hierarchyStates p.1 p.2) := by + unfold hierarchyStates + exact words_primrec.to_comp.comp (codeAlphabet_computable.comp Computable.fst) Computable.snd + +variable {A : Type} + +attribute [local irreducible] hierarchyTable hierarchyStates chooseChildren + tableLookup rationalExpression + +noncomputable def trialExpression (leaf : A → List Code → Code) (a : A) + (root : Code) (ms : List ℚ) (L : ℕ) : Code := + let states := hierarchyStates (encode root) L + let tab := hierarchyTable states ms (states.map (fun ds => (ds, leaf a ds))) + sumExpressions ((chooseChildren (List.replicate L root)).map (fun b => + Code.comp (rationalExpression b.1) (tableLookup tab b.2))) + +theorem trialExpression_computable [Primcodable A] (leaf : A → List Code → Code) + (hleaf : Computable (fun p : A × List Code => leaf p.1 p.2)) : + Computable (fun p : A × Code × List ℚ × ℕ => + trialExpression leaf p.1 p.2.1 p.2.2.1 p.2.2.2) := by + have hc : Computable (fun p : Code × Code => p.1.comp p.2) := + Code.primrec₂_comp.to_comp + have hr : Computable (fun p : ℕ × Code => List.replicate p.1 p.2) := by + have h : Computable (fun p : ℕ × Code => (List.range p.1).map (fun _ => p.2)) := by + apply computable_list_map (Primrec.list_range.to_comp.comp Computable.fst) + unfold Computable₂ + fun_prop + exact h.of_eq (fun p => by simp) + have hi : Computable (fun p : A × Code × List ℚ × ℕ => + (hierarchyStates (encode p.2.1) p.2.2.2).map (fun ds => (ds, leaf p.1 ds))) := by + apply computable_list_map (by fun_prop) + unfold Computable₂ + fun_prop + have ht : Computable (fun p : A × Code × List ℚ × ℕ => + hierarchyTable (hierarchyStates (encode p.2.1) p.2.2.2) p.2.2.1 + ((hierarchyStates (encode p.2.1) p.2.2.2).map (fun ds => (ds, leaf p.1 ds)))) := by + fun_prop + unfold trialExpression + apply sumExpressions_computable.comp + apply computable_list_map (by fun_prop) + unfold Computable₂ + have hw : Computable (fun p : (A × Code × List ℚ × ℕ) × (ℚ × List Code) => + rationalExpression p.2.1) := rationalExpression_computable.comp (by fun_prop) + have hl : Computable (fun p : (A × Code × List ℚ × ℕ) × (ℚ × List Code) => + tableLookup (hierarchyTable (hierarchyStates (encode p.1.2.1) p.1.2.2.2) p.1.2.2.1 + ((hierarchyStates (encode p.1.2.1) p.1.2.2.2).map (fun ds => (ds, leaf p.1.1 ds)))) + p.2.2) := + tableLookup_computable.comp ((ht.comp Computable.fst).pair (by fun_prop)) + exact hc.comp (hw.pair hl) + +theorem trialExpression_value (leaf : A → List Code → Code) (a : A) + (root : Code) (ms : List ℚ) (L : ℕ) : + expressionValue (trialExpression leaf a root ms L) = + branchSum (chooseChildren (List.replicate L root)) + (listLogMean ms (fun ds => expressionValue (leaf a ds))) := by + have hroot : List.replicate L root ∈ hierarchyStates (encode root) L := by + apply (mem_hierarchyStates _ _ _).mpr + refine ⟨List.length_replicate, ?_⟩ + intro c hc + have h := List.eq_of_mem_replicate hc + subst c + exact le_rfl + simp only [trialExpression, sumExpressions_value, List.map_map, + Function.comp_def, expressionValue, rationalExpression_value, branchSum] + apply congrArg List.sum + apply List.map_congr_left + intro b hb + congr 1 + apply hierarchyTable_value + · intro cs hcs + rw [tableLookup_map _ _ hcs] + · exact chooseChildren_in_states hroot b hb + +theorem trialExpression_eq_trialLog {L : ℕ} (leaf : A → List Code → Code) (a : A) + (g : (Fin L → ℝ) → ℝ) (hleaf : ∀ ds, expressionValue (leaf a ds) = g (leafFields L ds)) + (root : Code) (ms : List ℚ) : + expressionValue (trialExpression leaf a root ms L) = + DilutedSpinGlass.trialLog ms.length + (rationalTreeValue (ms.length+1) (decodeTree (ms.length+1) root)) + (fun i => (ms.get i : ℝ)) g := by + rw [trialExpression_value] + have hg : (fun ds => expressionValue (leaf a ds)) = fun ds => g (leafFields L ds) := + funext hleaf + rw [hg, listTrialLog_eq_finite, finiteTrialLog_eq] + +theorem trialExpression_effective [Primcodable A] (leaf : A → List Code → Code) + (hleaf : Computable (fun p : A × List Code => leaf p.1 p.2)) : + PeriodicLattice.CertifiedReal.Effective (fun p : A × Code × List ℚ × ℕ => + expressionValue (trialExpression leaf p.1 p.2.1 p.2.2.1 p.2.2.2)) := + expressionValue_effective.comp (trialExpression_computable leaf hleaf) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/HierarchyExpectation.lean b/lean/OAI/Probability/SATComputability/HierarchyExpectation.lean new file mode 100644 index 0000000000000000000000000000000000000000..03bc813d70adc6c837a6a07f0ce80092374927f7 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/HierarchyExpectation.lean @@ -0,0 +1,85 @@ +import OAI.Probability.SATComputability.HierarchyProgram +import OAI.Probability.DilutedSpin.FiniteProducts + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass Nat.Partrec +open scoped BigOperators + +noncomputable def branchSum (bs : List (ℚ × List Code)) (f : List Code → ℝ) : ℝ := + (bs.map (fun b => (b.1 : ℝ) * f b.2)).sum + +theorem normalizedBranches_expect (c : Code) (f : Code → ℝ) : + ((normalizedBranches c).map (fun b => (b.1 : ℝ)*f b.2)).sum = + (branchWeights c).toLaw.expect (fun i => f ((normalizedBranches c).get i).2) := by + unfold DilutedSpinGlass.FiniteLaw.expect + change _ = ∑ i : Fin (normalizedBranches c).length, + (((normalizedBranches c).get i).1 : ℝ) * f ((normalizedBranches c).get i).2 + rw [← List.sum_ofFn] + have h := congrArg (fun bs : List (ℚ × Code) => + (bs.map (fun b => (b.1 : ℝ)*f b.2)).sum) (List.ofFn_get (normalizedBranches c)) + simpa only [List.map_ofFn, Function.comp_def] using h.symm + +theorem branchSum_cons (c : Code) (cs : List Code) (f : List Code → ℝ) : + branchSum (chooseChildren (c::cs)) f = + ((normalizedBranches c).map (fun b => (b.1 : ℝ) * + branchSum (chooseChildren cs) (fun rest => f (b.2::rest)))).sum := by + simp only [branchSum, chooseChildren, List.foldr_cons, List.map_flatMap, + sum_flatMap_eq, List.map_map, Function.comp_def, Rat.cast_mul] + apply congrArg List.sum + apply List.map_congr_left + intro b _ + rw [← List.sum_map_mul_left] + congr 1 + apply List.map_congr_left + intro r _ + exact mul_assoc _ _ _ + +theorem chooseChildren_expect (cs : List Code) (f : List Code → ℝ) : + branchSum (chooseChildren cs) f = + (FiniteLaw.pi (fun i : Fin cs.length => (branchWeights (cs.get i)).toLaw)).expect + (fun a => f (List.ofFn (fun i => + ((normalizedBranches (cs.get i)).get (a i)).2))) := by + induction cs generalizing f with + | nil => simp [branchSum, chooseChildren, FiniteLaw.expect, FiniteLaw.pi] + | cons c cs ih => + rw [branchSum_cons] + simp_rw [ih] + rw [normalizedBranches_expect c (fun d => + (FiniteLaw.pi (fun i : Fin cs.length => (branchWeights (cs.get i)).toLaw)).expect + (fun a => f (d :: List.ofFn (fun i => + ((normalizedBranches (cs.get i)).get (a i)).2)))), FiniteLaw.expect_pi_cons] + apply FiniteLaw.expect_congr + intro a + apply FiniteLaw.expect_congr + intro rest + congr 1 + rw [List.ofFn_succ] + rfl + +theorem chooseChildren_expect_ofFn {L : ℕ} (cs : Fin L → Code) (f : List Code → ℝ) : + branchSum (chooseChildren (List.ofFn cs)) f = + (FiniteLaw.pi (fun i : Fin L => (branchWeights (cs i)).toLaw)).expect + (fun a => f (List.ofFn (fun i => ((normalizedBranches (cs i)).get (a i)).2))) := by + induction L generalizing f with + | zero => simp [branchSum, chooseChildren, FiniteLaw.expect, FiniteLaw.pi] + | succ L ih => + rw [List.ofFn_succ, branchSum_cons] + simp_rw [ih] + rw [normalizedBranches_expect (cs 0) (fun d => + (FiniteLaw.pi (fun i : Fin L => (branchWeights (cs i.succ)).toLaw)).expect + (fun a => f (d :: List.ofFn (fun i => + ((normalizedBranches (cs i.succ)).get (a i)).2)))), FiniteLaw.expect_pi_cons] + apply FiniteLaw.expect_congr + intro a + apply FiniteLaw.expect_congr + intro rest + congr 1 + rw [List.ofFn_succ] + rfl + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/HierarchyProgram.lean b/lean/OAI/Probability/SATComputability/HierarchyProgram.lean new file mode 100644 index 0000000000000000000000000000000000000000..72dd3a8e3c539fad5382d2a2aeebcb47a2e90221 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/HierarchyProgram.lean @@ -0,0 +1,112 @@ +import OAI.Probability.SATComputability.HierarchyEncoding +import OAI.MathematicalPhysics.RapidForcing.BoundsPrograms + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Nat.Partrec FiniteArithmetic RapidForcing.EffectiveArithmetic +open PeriodicLattice.CertifiedReal +local instance hierarchyProgramRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +@[fun_prop] theorem branchEntry_computable : Computable branchEntry := by + have h := Code.computable_recOn (c := id) Computable.id + (z := fun _ => ((0 : ℚ), Code.zero)) (by fun_prop) + (s := fun _ => ((0 : ℚ), Code.zero)) (by fun_prop) + (l := fun _ => ((0 : ℚ), Code.zero)) (by fun_prop) + (r := fun _ => ((0 : ℚ), Code.zero)) (by fun_prop) + (pr := fun _ _ => ((0 : ℚ), Code.zero)) (by unfold Computable₂; fun_prop) + (co := fun _ p => (decodedRational p.1, p.2.1)) (by unfold Computable₂; fun_prop) + (pc := fun _ _ => ((0 : ℚ), Code.zero)) (by unfold Computable₂; fun_prop) + (rf := fun _ _ => ((0 : ℚ), Code.zero)) (by unfold Computable₂; fun_prop) + exact h.of_eq (fun c => by cases c <;> rfl) + +@[fun_prop] theorem rawBranches_computable : Computable rawBranches := by + have h := Code.computable_recOn (c := id) Computable.id + (z := fun _ => ([] : List (ℚ × Code))) (by fun_prop) + (s := fun _ => ([] : List (ℚ × Code))) (by fun_prop) + (l := fun _ => ([] : List (ℚ × Code))) (by fun_prop) + (r := fun _ => ([] : List (ℚ × Code))) (by fun_prop) + (pr := fun _ p => branchEntry p.1 :: p.2.2.2) (by unfold Computable₂; fun_prop) + (co := fun _ _ => ([] : List (ℚ × Code))) (by unfold Computable₂; fun_prop) + (pc := fun _ _ => ([] : List (ℚ × Code))) (by unfold Computable₂; fun_prop) + (rf := fun _ _ => ([] : List (ℚ × Code))) (by unfold Computable₂; fun_prop) + apply h.of_eq + intro c + induction c <;> simp_all only [rawBranches, id_eq] + +attribute [local irreducible] rawBranches + +@[fun_prop] theorem normalizedBranches_computable : Computable normalizedBranches := by + have hm : Computable (fun c => (rawBranches c).map (fun b => |b.1|)) := + computable_list_map rawBranches_computable (by unfold Computable₂; fun_prop) + have hs : Computable (fun c => ((rawBranches c).map (fun b => |b.1|)).sum) := + (computable_list_sum computable_rat_add).comp hm + have hz : CompPred (fun c => ((rawBranches c).map (fun b => |b.1|)).sum = 0) := by + unfold CompPred + have he : Computable (fun p : ℚ × ℚ => decide (p.1 = p.2)) := by fun_prop + exact he.comp (hs.pair (Computable.const 0)) + have hf : Computable (fun c => (rawBranches c).map (fun b => + (|b.1| / ((rawBranches c).map (fun x => |x.1|)).sum, b.2))) := by + apply computable_list_map rawBranches_computable + unfold Computable₂ + have hd : Computable (fun p : Code × (ℚ × Code) => + ((rawBranches p.1).map (fun x => |x.1|)).sum) := hs.comp Computable.fst + fun_prop + exact computable_ite hz (Computable.const [(1, Code.zero)]) hf + +theorem sum_flatMap_eq {A B : Type*} [AddMonoid B] (xs : List A) (f : A → List B) : + (xs.flatMap f).sum = (xs.map (fun a => (f a).sum)).sum := by + induction xs with + | nil => rfl + | cons a xs ih => simp only [List.flatMap_cons, List.sum_append, List.map_cons, + List.sum_cons, ih] + +noncomputable def chooseChildren (cs : List Code) : List (ℚ × List Code) := + cs.foldr (fun c rest => (normalizedBranches c).flatMap (fun b => + rest.map (fun r => (b.1*r.1, b.2::r.2)))) [(1, [])] + +@[fun_prop] theorem chooseChildren_computable : Computable chooseChildren := by + have hs : Computable (fun p : Code × List (ℚ × List Code) => + (normalizedBranches p.1).flatMap (fun b => + p.2.map (fun r => (b.1*r.1, b.2::r.2)))) := by + apply computable_list_flatMap (normalizedBranches_computable.comp Computable.fst) + unfold Computable₂ + apply computable_list_map (Computable.snd.comp Computable.fst) + unfold Computable₂ + fun_prop + exact computable_list_foldr Computable.id (Computable.const [(1, [])]) + (hs.comp Computable.snd).to₂ + +theorem chooseChildren_nonneg (cs : List Code) : ∀ b ∈ chooseChildren cs, 0 ≤ b.1 := by + induction cs with + | nil => simp [chooseChildren] + | cons c cs ih => + intro b hb + obtain ⟨x, hx, hz⟩ := List.mem_flatMap.mp hb + obtain ⟨y, hy, rfl⟩ := List.mem_map.mp hz + exact mul_nonneg (normalizedBranches_nonneg c x hx) (ih y hy) + +theorem chooseChildren_sum (cs : List Code) : ((chooseChildren cs).map Prod.fst).sum = 1 := by + induction cs with + | nil => simp [chooseChildren] + | cons c cs ih => + change (((normalizedBranches c).flatMap (fun b => + (chooseChildren cs).map (fun r => (b.1*r.1, b.2::r.2)))).map Prod.fst).sum = 1 + simp only [List.map_flatMap, sum_flatMap_eq, List.map_map, Function.comp_def, + List.sum_map_mul_left, ih, mul_one] + exact normalizedBranches_sum c + +theorem chooseChildren_length (cs : List Code) : + ∀ b ∈ chooseChildren cs, b.2.length = cs.length := by + induction cs with + | nil => simp [chooseChildren] + | cons c cs ih => + intro b hb + obtain ⟨x, _, hx⟩ := List.mem_flatMap.mp hb + obtain ⟨y, hy, rfl⟩ := List.mem_map.mp hx + simpa only [List.length_cons] using congrArg Nat.succ (ih y hy) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/HierarchySemantics.lean b/lean/OAI/Probability/SATComputability/HierarchySemantics.lean new file mode 100644 index 0000000000000000000000000000000000000000..f514c5f3e7da6c2f57c2cc113625f80783f0c59a --- /dev/null +++ b/lean/OAI/Probability/SATComputability/HierarchySemantics.lean @@ -0,0 +1,51 @@ +import OAI.Probability.SATComputability.HierarchyTable +import OAI.Probability.SATComputability.FiniteTrialEvaluation + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass Nat.Partrec FiniteArithmetic +attribute [local irreducible] normalizedBranches branchWeights + +noncomputable def leafFields (L : ℕ) (cs : List Code) : Fin L → ℝ := + fun i => decodedRational (cs[i.val]?.getD .zero) + +theorem leafFields_ofFn {L : ℕ} (cs : Fin L → Code) : + leafFields L (List.ofFn cs) = fun i => (decodedRational (cs i) : ℝ) := by + funext i + simp [leafFields, i.isLt] + +theorem listLogMean_eq_finite {L : ℕ} (ms : List ℚ) (g : (Fin L → ℝ) → ℝ) + (cs : Fin L → Code) : + listLogMean ms (fun ds => g (leafFields L ds)) (List.ofFn cs) = + finiteLogMean ms.length g (fun i => (ms.get i : ℝ)) + (fun i => decodeTree ms.length (cs i)) := by + induction ms generalizing cs with + | nil => + change g (leafFields L (List.ofFn cs)) = g (fun i => (decodedRational (cs i) : ℝ)) + rw [leafFields_ofFn] + | cons m ms ih => + rw [listLogMean, chooseChildren_expect_ofFn] + simp_rw [ih] + simp only [List.length_cons, finiteLogMean, decodeTree, List.get_eq_getElem, + List.getElem_cons_zero, List.getElem_cons_succ, Fin.val_zero, Fin.val_succ] + rw [show (instDecidableEqFin L : DecidableEq (Fin L)) = + (fun a b => Classical.propDecidable (a = b)) from Subsingleton.elim _ _] + +theorem listTrialLog_eq_finite {L : ℕ} (ms : List ℚ) (g : (Fin L → ℝ) → ℝ) + (root : Code) : + branchSum (chooseChildren (List.replicate L root)) + (listLogMean ms (fun ds => g (leafFields L ds))) = + finiteTrialLog ms.length (decodeTree (ms.length+1) root) + (fun i => (ms.get i : ℝ)) g := by + rw [← List.ofFn_const L root, chooseChildren_expect_ofFn] + simp_rw [listLogMean_eq_finite] + simp only [finiteTrialLog, decodeTree] + rw [show (instDecidableEqFin L : DecidableEq (Fin L)) = + (fun a b => Classical.propDecidable (a = b)) from Subsingleton.elim _ _] + rfl + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/HierarchyTable.lean b/lean/OAI/Probability/SATComputability/HierarchyTable.lean new file mode 100644 index 0000000000000000000000000000000000000000..63a16de648453345d167fb07bb3f479defb48776 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/HierarchyTable.lean @@ -0,0 +1,140 @@ +import OAI.Probability.SATComputability.HierarchyExpectation +import OAI.Probability.SATComputability.HierarchyBounds +import OAI.Probability.SATComputability.WeightedExpressions + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Nat.Partrec Encodable Denumerable FiniteArithmetic +open RapidForcing.EffectiveArithmetic +local instance hierarchyTableRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable +local instance hierarchyTableCodeEq : DecidableEq Code := Encodable.decidableEqOfEncodable Code +local instance hierarchyTableListBEq : BEq (List Code) := instBEqOfDecidableEq + +abbrev ExpressionTable := List (List Code × Code) + +noncomputable def tableLookup (tab : ExpressionTable) (cs : List Code) : Code := + (tab.lookup cs).getD .zero + +@[fun_prop] theorem tableLookup_computable : + Computable (fun p : ExpressionTable × List Code => tableLookup p.1 p.2) := by + unfold tableLookup + exact (Primrec.option_getD.comp + ((Primrec.listLookup (α := List Code) (β := Code)).comp Primrec.snd Primrec.fst) + (Primrec.const Code.zero)).to_comp + +theorem tableLookup_map (states : List (List Code)) (f : List Code → Code) + {cs : List Code} (hcs : cs ∈ states) : + tableLookup (states.map (fun ds => (ds, f ds))) cs = f cs := by + unfold tableLookup + rw [List.lookup_graph f hcs] + rfl + +noncomputable def layerExpression (m : ℚ) (tab : ExpressionTable) (cs : List Code) : Code := + .comp (rationalExpression m⁻¹) + (logMixtureExpression ((chooseChildren cs).map (fun b => + (b.1, Code.comp (rationalExpression m) (tableLookup tab b.2))))) + +@[fun_prop] theorem layerExpression_computable : + Computable (fun p : ℚ × ExpressionTable × List Code => layerExpression p.1 p.2.1 p.2.2) := by + have hl : Computable (fun p : ℚ × ExpressionTable × List Code => + (chooseChildren p.2.2).map (fun b => + (b.1, Code.comp (rationalExpression p.1) (tableLookup p.2.1 b.2)))) := by + apply computable_list_map (chooseChildren_computable.comp (by fun_prop)) + unfold Computable₂ + fun_prop + unfold layerExpression + fun_prop + +noncomputable def tableLayer (states : List (List Code)) (m : ℚ) (tab : ExpressionTable) : + ExpressionTable := states.map (fun cs => (cs, layerExpression m tab cs)) + +@[fun_prop] theorem tableLayer_computable : + Computable (fun p : List (List Code) × ℚ × ExpressionTable => tableLayer p.1 p.2.1 p.2.2) := by + unfold tableLayer + apply computable_list_map Computable.fst + unfold Computable₂ + fun_prop + +noncomputable def hierarchyTable (states : List (List Code)) (ms : List ℚ) + (initial : ExpressionTable) : ExpressionTable := + ms.foldr (fun m tab => tableLayer states m tab) initial + +@[fun_prop] theorem hierarchyTable_computable : + Computable (fun p : List (List Code) × List ℚ × ExpressionTable => + hierarchyTable p.1 p.2.1 p.2.2) := by + unfold hierarchyTable + exact computable_list_foldr + (f := fun p : List (List Code) × List ℚ × ExpressionTable => p.2.1) + (g := fun p => p.2.2) (h := fun p q => tableLayer p.1 q.1 q.2) + (by fun_prop) (by fun_prop) (by unfold Computable₂; fun_prop) + +noncomputable def listLogMean : List ℚ → (List Code → ℝ) → List Code → ℝ + | [], g, cs => g cs + | m::ms, g, cs => Real.log (branchSum (chooseChildren cs) + (fun ds => Real.exp ((m : ℝ)*listLogMean ms g ds))) / (m : ℝ) + +theorem layerExpression_value (m : ℚ) (tab : ExpressionTable) (cs : List Code) : + expressionValue (layerExpression m tab cs) = + Real.log (branchSum (chooseChildren cs) + (fun ds => Real.exp ((m : ℝ)*expressionValue (tableLookup tab ds)))) / (m : ℝ) := by + have hw : ∀ b ∈ (chooseChildren cs).map (fun b => + (b.1, Code.comp (rationalExpression m) (tableLookup tab b.2))), 0 ≤ b.1 := by + intro b hb + obtain ⟨d, hd, rfl⟩ := List.mem_map.mp hb + exact chooseChildren_nonneg cs d hd + have hs : (((chooseChildren cs).map (fun b => + (b.1, Code.comp (rationalExpression m) (tableLookup tab b.2)))).map Prod.fst).sum = 1 := by + simpa only [List.map_map, Function.comp_def] using chooseChildren_sum cs + simp only [layerExpression, expressionValue, rationalExpression_value, Rat.cast_inv, + logMixtureExpression_value _ hw hs, List.map_map, Function.comp_def, branchSum] + ring + +theorem chooseChildren_in_states {B L : ℕ} {cs : List Code} + (hcs : cs ∈ hierarchyStates B L) : + ∀ b ∈ chooseChildren cs, b.2 ∈ hierarchyStates B L := by + obtain ⟨hL, hB⟩ := (mem_hierarchyStates B L cs).mp hcs + intro b hb + apply (mem_hierarchyStates B L b.2).mpr + refine ⟨(chooseChildren_length cs b hb).trans hL, ?_⟩ + have hall : ∀ c ∈ cs, Encodable.encode c ≤ B := hB + clear hL hcs hB + induction cs generalizing b with + | nil => + have he : b = (1, []) := by simpa only [chooseChildren, List.foldr_nil, List.mem_singleton] using hb + simp [he] + | cons c cs ih => + obtain ⟨x, hx, hymap⟩ := List.mem_flatMap.mp hb + obtain ⟨y, hymem, rfl⟩ := List.mem_map.mp hymap + intro d hd + rcases List.mem_cons.mp hd with rfl | hd + · exact (normalizedBranches_code_le c x hx).trans (hall c (by simp)) + · exact ih y hymem (fun z hz => hall z (List.mem_cons_of_mem c hz)) d hd + +theorem hierarchyTable_value (B L : ℕ) (ms : List ℚ) (initial : ExpressionTable) + (g : List Code → ℝ) + (hinit : ∀ cs ∈ hierarchyStates B L, expressionValue (tableLookup initial cs) = g cs) + (cs : List Code) (hcs : cs ∈ hierarchyStates B L) : + expressionValue (tableLookup (hierarchyTable (hierarchyStates B L) ms initial) cs) = + listLogMean ms g cs := by + induction ms generalizing cs with + | nil => exact hinit cs hcs + | cons m ms ih => + change expressionValue (tableLookup + (tableLayer (hierarchyStates B L) m (hierarchyTable (hierarchyStates B L) ms initial)) cs) = _ + rw [tableLayer, tableLookup_map _ _ hcs, + layerExpression_value, listLogMean] + congr 2 + unfold branchSum + congr 1 + apply List.map_congr_left + intro b hb + change (b.1 : ℝ) * Real.exp ((m : ℝ) * expressionValue + (tableLookup (hierarchyTable (hierarchyStates B L) ms initial) b.2)) = + (b.1 : ℝ) * Real.exp ((m : ℝ) * listLogMean ms g b.2) + rw [ih b.2 (chooseChildren_in_states hcs b hb)] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/IncidentMasks.lean b/lean/OAI/Probability/SATComputability/IncidentMasks.lean new file mode 100644 index 0000000000000000000000000000000000000000..cb911ab3748118f506519eb28660219354089925 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/IncidentMasks.lean @@ -0,0 +1,115 @@ +import OAI.Probability.SATComputability.ObstructionMoment + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory +open scoped BigOperators Classical NNReal + +noncomputable def finiteMap {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + [DecidableEq Ξ] (P : FiniteLaw Ω) (f : Ω → Ξ) : FiniteLaw Ξ where + weight y := P.expect (fun x => if f x = y then 1 else 0) + nonneg y := P.expect_nonneg (fun x => by split_ifs <;> norm_num) + total := by + rw [← FiniteLaw.expect_fintype_sum] + simp + +theorem finiteMap_expect {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + [DecidableEq Ξ] (P : FiniteLaw Ω) (f : Ω → Ξ) (g : Ξ → ℝ) : + (finiteMap P f).expect g = P.expect (fun x => g (f x)) := by + simp only [FiniteLaw.expect, finiteMap, Finset.sum_mul, mul_ite, mul_one, mul_zero] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro x _ + simp + +noncomputable def unionMaskLaw {n : ℕ} + (P Q : FiniteLaw (Finset (DeletionCandidate n))) : FiniteLaw (Finset (DeletionCandidate n)) := + finiteMap (P.bind (fun _ => Q)) (fun p => p.1 ∪ p.2) + +theorem unionMaskLaw_killing {n : ℕ} + (P Q : FiniteLaw (Finset (DeletionCandidate n))) (U : Finset (DeletionCandidate n)) : + (unionMaskLaw P Q).expect (fun I => if U ∩ I = ∅ then 1 else 0) = + P.expect (fun I => if U ∩ I = ∅ then 1 else 0) * + Q.expect (fun I => if U ∩ I = ∅ then 1 else 0) := by + rw [unionMaskLaw, finiteMap_expect, FiniteLaw.expect_bind] + have he (I J : Finset (DeletionCandidate n)) : + (if U ∩ (I ∪ J) = ∅ then (1 : ℝ) else 0) = + (if U ∩ I = ∅ then 1 else 0) * (if U ∩ J = ∅ then 1 else 0) := by + simp only [Finset.inter_union_distrib_left, Finset.union_eq_empty] + split_ifs <;> simp_all + simp only [he, FiniteLaw.expect_mul_left, FiniteLaw.expect_mul_right] + +noncomputable def catastropheLaw (n : ℕ) (ρ : ℝ≥0) : FiniteLaw (Finset (DeletionCandidate n)) := + poissonMixture ρ (fun d => finiteMap (FiniteLaw.uniform : FiniteLaw Unit) + (fun _ => if d = 0 then Finset.univ else ∅)) + +theorem catastropheLaw_bound (n : ℕ) (ρ : ℝ≥0) : + (catastropheLaw n ρ).expect (fun I => if I = Finset.univ then 0 else 1) ≤ ρ := by + rw [catastropheLaw, poissonMixture_expect] + simp only [finiteMap_expect, FiniteLaw.expect_const] + have hi : Integrable (fun d : ℕ => + if (if d = 0 then (Finset.univ : Finset (DeletionCandidate n)) else ∅) = Finset.univ + then (0 : ℝ) else 1) (poissonMeasure ρ) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + filter_upwards [] with d + split_ifs <;> norm_num + apply (integral_mono hi (poisson_integrable_count ρ) (fun d => ?_)).trans_eq (poisson_mean ρ) + by_cases hd : d = 0 + · simp [hd] + · have hd' : (1 : ℝ) ≤ d := by exact_mod_cast (Nat.pos_of_ne_zero hd) + split_ifs <;> linarith + +noncomputable def incidentSignLaw {n : ℕ} [NeZero n] (ρ : ℝ≥0) : + FiniteLaw (Finset (DeletionCandidate n)) := + finiteMap ((candidateBlock 60 2 Finset.univ).bind (fun _ => catastropheLaw n ρ)) + (fun p => p.1 ∩ p.2) + +theorem incidentSignLaw_killing {n : ℕ} [NeZero n] (ρ : ℝ≥0) + (U : Finset (DeletionCandidate n)) : + (incidentSignLaw ρ).expect (fun I => if U ∩ I = ∅ then 1 else 0) ≤ + poissonKillProbability U 2 60 + ρ := by + rw [incidentSignLaw, finiteMap_expect, FiniteLaw.expect_bind] + have hb (I J : Finset (DeletionCandidate n)) : + (if U ∩ (I ∩ J) = ∅ then (1 : ℝ) else 0) ≤ + (if U ∩ I = ∅ then 1 else 0) + (if J = Finset.univ then 0 else 1) := by + by_cases hJ : J = Finset.univ + · simp [hJ] + · split_ifs <;> norm_num + have h := (candidateBlock (n := n) 60 2 Finset.univ).expect_mono (fun I => + (catastropheLaw n ρ).expect_mono (hb I)) + simp only [FiniteLaw.expect_add, FiniteLaw.expect_const] at h + have he : (candidateBlock 60 2 (Finset.univ : Finset (DeletionCandidate n))).expect + (fun I => if U ∩ I = ∅ then 1 else 0) = poissonKillProbability U 2 60 := by + rw [candidateBlock_mask 60 2 U (fun V => if V = ∅ then 1 else 0), candidateBlock_kill] + rw [he] at h + exact h.trans (add_le_add le_rfl (catastropheLaw_bound n ρ)) + +noncomputable def dominatingIncidentLaw {n : ℕ} [NeZero n] (ρ : ℝ≥0) : + FiniteLaw (Finset (DeletionCandidate n)) := unionMaskLaw (incidentSignLaw ρ) (incidentSignLaw ρ) + +theorem dominatingIncidentLaw_killing {n : ℕ} [NeZero n] (ρ : ℝ≥0) + (U : Finset (DeletionCandidate n)) : + (dominatingIncidentLaw ρ).expect (fun I => if U.Nonempty ∧ U ∩ I = ∅ then 1 else 0) ≤ + (poissonKillProbability U 2 60 + ρ)^2 := by + by_cases hU : U.Nonempty + · simp only [hU, true_and, dominatingIncidentLaw, unionMaskLaw_killing] + rw [← pow_two] + exact pow_le_pow_left₀ (FiniteLaw.expect_nonneg _ (fun I => by split_ifs <;> norm_num)) + (incidentSignLaw_killing ρ U) 2 + · simp only [hU, false_and, ite_false, FiniteLaw.expect_const] + exact sq_nonneg _ + +theorem dominatingIncidentLaw_delay {n : ℕ} [NeZero n] + (r : ℝ≥0) (hr : (1 : ℝ)/8 ≤ r) (M : ℕ) (ρ : ℝ≥0) + (U : Finset (DeletionCandidate n)) : + (dominatingIncidentLaw ρ).expect (fun I => maskDelayMoment r 3 M U I) ≤ + (48/5 : ℝ) * (∑' j, dyadicMomentCoefficient j) + + (12/5 : ℝ)*(ρ : ℝ)^2*(M : ℝ)^(6/5 : ℝ) := + maskDelayMoment_of_obstruction r hr M (dominatingIncidentLaw ρ) ρ + (dominatingIncidentLaw_killing ρ) U + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/IncidentObstruction.lean b/lean/OAI/Probability/SATComputability/IncidentObstruction.lean new file mode 100644 index 0000000000000000000000000000000000000000..c948855489016a518c84dc99f6b3078d0a6523a3 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/IncidentObstruction.lean @@ -0,0 +1,115 @@ +import OAI.Probability.SATComputability.ClauseProcess +import OAI.Probability.SATComputability.PoissonMaskAggregation + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal Classical + +abbrev SingleIncident (n : ℕ) := Fin 3 × SignedLiteral n × SignedLiteral n +abbrev BadIncident (n : ℕ) := (Fin 3 × SignedLiteral n) ⊕ Unit + +def singleIncidentEquiv (n : ℕ) : SingleIncident n ≃ (Fin 2 → SignedLiteral n) × Fin 3 where + toFun p := (![p.2.1,p.2.2],p.1) + invFun p := (p.2,p.1 0,p.1 1) + left_inv := by rintro ⟨i,a,b⟩; rfl + right_inv := by + rintro ⟨f,i⟩ + apply Prod.ext + · funext j; fin_cases j <;> rfl + · rfl + +noncomputable def singleIncidentMask {n : ℕ} (p : SingleIncident n) : + Finset (DeletionCandidate n) := clauseMask ![p.2.1,p.2.2] + +theorem singleIncident_law {n : ℕ} [NeZero n] (r : ℝ≥0) + (f : Finset (DeletionCandidate n) → ℝ) : + (∫ c, f (countsMask singleIncidentMask c) ∂poissonCountLaw (SingleIncident n) r) = + (candidateBlock (3*r*Fintype.card (Fin 2 → SignedLiteral n)) 2 Finset.univ).expect f := by + have he : singleIncidentMask (n := n) = + (fun p : (Fin 2 → SignedLiteral n) × Fin 3 => clauseMask p.1) ∘ singleIncidentEquiv n := rfl + rw [he] + simp_rw [countsMask_equiv] + rw [show (∫ c, f (countsMask (fun p : (Fin 2 → SignedLiteral n) × Fin 3 => clauseMask p.1) + (c ∘ (singleIncidentEquiv n).symm)) ∂poissonCountLaw (SingleIncident n) r) = + ∫ c, f (countsMask (fun p : (Fin 2 → SignedLiteral n) × Fin 3 => clauseMask p.1) c) + ∂poissonCountLaw ((Fin 2 → SignedLiteral n) × Fin 3) r from by + simpa only [Function.comp_def] using poissonCountLaw_equiv (singleIncidentEquiv n) r + (fun c => f (countsMask (fun p : (Fin 2 → SignedLiteral n) × Fin 3 => clauseMask p.1) c)), + poissonCountLaw_redundant_mask] + rw [candidateBlock_counts] + congr 2 + simp only [Fintype.card_fin, mul_div_cancel_right₀ _ (show + (Fintype.card (Fin 2 → SignedLiteral n) : ℝ≥0) ≠ 0 by + exact_mod_cast Fintype.card_ne_zero)] + norm_num + +theorem incident_killing_pointwise {n : ℕ} (U : Finset (DeletionCandidate n)) + (c : IncidentClass n → ℕ) : + (if U ∩ countsMask incidentMask c = ∅ then (1 : ℝ) else 0) ≤ + (if U ∩ countsMask singleIncidentMask (fun a => c (.inl a)) = ∅ then 1 else 0) + + (∑ b : BadIncident n, c (.inr b) : ℕ) := by + by_cases hz : ∑ b : BadIncident n, c (.inr b) = 0 + · have hb (b : BadIncident n) : c (.inr b) = 0 := + (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => Nat.zero_le (c (.inr j)))).mp hz b + (Finset.mem_univ b) + have hm : countsMask incidentMask c = + countsMask singleIncidentMask (fun a => c (.inl a)) := by + ext x + simp [countsMask, incidentMask, singleIncidentMask, Sum.forall, hb] + rw [hm,hz,Nat.cast_zero,add_zero] + · have hpos : (1 : ℝ) ≤ (∑ b : BadIncident n, c (.inr b) : ℕ) := by + exact_mod_cast Nat.one_le_iff_ne_zero.mpr hz + split_ifs <;> linarith + +theorem incident_killing_bound {n : ℕ} [NeZero n] (r : ℝ≥0) + (U : Finset (DeletionCandidate n)) : + (∫ c, if U ∩ countsMask incidentMask c = ∅ then (1 : ℝ) else 0 + ∂poissonCountLaw (IncidentClass n) r) ≤ + poissonKillProbability U 2 (3*r*Fintype.card (Fin 2 → SignedLiteral n)) + + Fintype.card (BadIncident n)*(r : ℝ) := by + let μ := poissonCountLaw (IncidentClass n) r + let g := fun c : IncidentClass n → ℕ => + if U ∩ countsMask singleIncidentMask (fun a => c (.inl a)) = ∅ then (1 : ℝ) else 0 + let b := fun c : IncidentClass n → ℕ => ((∑ a : BadIncident n, c (.inr a) : ℕ) : ℝ) + have hg : Integrable g μ := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + filter_upwards [] with c + dsimp only [g] + split_ifs <;> norm_num + have hres : HasLaw (fun c : IncidentClass n → ℕ => fun a : BadIncident n => c (.inr a)) + (poissonCountLaw (BadIncident n) r) μ := + ⟨(measurable_of_countable _).aemeasurable, + poissonCountLaw_embedding Sum.inr Sum.inr_injective r⟩ + have hsum := (poissonCountLaw_hasLaw_sum (fun _ : BadIncident n => r)).comp hres + have hb : Integrable b μ := + hsum.integrable_comp (poisson_integrable_count _) + have hi : Integrable (fun c : IncidentClass n → ℕ => + if U ∩ countsMask incidentMask c = ∅ then (1 : ℝ) else 0) μ := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + filter_upwards [] with c + split_ifs <;> norm_num + have h := integral_mono hi (hg.add hb) (incident_killing_pointwise U) + simp only [Pi.add_apply] at h + rw [integral_add hg hb] at h + have hbg : (∫ c, b c ∂μ) = Fintype.card (BadIncident n)*(r : ℝ) := by + have he := hsum.integral_comp (f := fun k : ℕ => (k : ℝ)) + (measurable_of_countable _).aestronglyMeasurable + rw [poisson_mean] at he + simpa only [Function.comp_def, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, + NNReal.coe_mul, NNReal.coe_natCast] using he + have hgg : (∫ c, g c ∂μ) = + poissonKillProbability U 2 (3*r*Fintype.card (Fin 2 → SignedLiteral n)) := by + have he := poissonCountLaw_embedding_integral (A := IncidentClass n) (B := SingleIncident n) + Sum.inl Sum.inl_injective r + (fun c => if U ∩ countsMask singleIncidentMask c = ∅ then (1 : ℝ) else 0) + change (∫ c, g c ∂μ) = _ at he + rw [he, singleIncident_law r (fun I => if U ∩ I = ∅ then (1 : ℝ) else 0)] + rw [candidateBlock_mask _ _ U (fun V => if V = ∅ then (1 : ℝ) else 0), candidateBlock_kill] + rwa [hbg,hgg] at h + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/IncidentRates.lean b/lean/OAI/Probability/SATComputability/IncidentRates.lean new file mode 100644 index 0000000000000000000000000000000000000000..c17e35a27168f7c434acb001d52b82951ea5621d --- /dev/null +++ b/lean/OAI/Probability/SATComputability/IncidentRates.lean @@ -0,0 +1,109 @@ +import OAI.Probability.SATComputability.IncidentObstruction + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped NNReal + +noncomputable def clauseAtomRate (n : ℕ) : ℝ≥0 := (8*((n+1 : ℕ) : ℝ≥0)^3)⁻¹ + +theorem clause_atom_normalization (n : ℕ) : + clauseAtomRate n * Fintype.card (Fin 3 → SignedLiteral (n+1)) = 1 := by + have hc : (Fintype.card (Fin 3 → SignedLiteral (n+1)) : ℝ≥0) = + 8*((n+1 : ℕ) : ℝ≥0)^3 := by + simp only [Fintype.card_fun, SignedLiteral, Fintype.card_prod, Fintype.card_fin, + Fintype.card_bool, Nat.cast_pow, Nat.cast_mul, Nat.cast_ofNat] + ring + rw [hc, clauseAtomRate, inv_mul_cancel₀ (by positivity)] + +theorem incident_pair_card (n : ℕ) : Fintype.card (Fin 2 → SignedLiteral n) = 4*n^2 := by + simp [SignedLiteral, Fintype.card_prod] + ring + +theorem incident_bad_card (n : ℕ) : Fintype.card (BadIncident n) = 6*n+1 := by + simp [BadIncident, SignedLiteral, Fintype.card_sum, Fintype.card_prod] + ring + +theorem clause_base_rate {n : ℕ} (hn : 0 < n) : + (1 : ℝ)/8 ≤ (clauseAtomRate n * Fintype.card (Triple (SignedLiteral n)) : ℝ≥0) := by + have hnR : (1 : ℝ) ≤ n := by exact_mod_cast hn + have hpos : (0 : ℝ) < (n : ℝ)+1 := by positivity + have hr : (1 : ℝ)/2 ≤ (n : ℝ)/((n : ℝ)+1) := + (le_div_iff₀ hpos).mpr (by linarith) + have hp := pow_le_pow_left₀ (by norm_num : (0 : ℝ) ≤ 1/2) hr 3 + rw [clauseClasses_base_card] + change (1 : ℝ)/8 ≤ ((clauseAtomRate n : ℝ) * (8*n^3 : ℕ)) + simp only [clauseAtomRate, NNReal.coe_inv, NNReal.coe_mul, NNReal.coe_ofNat, + NNReal.coe_pow, Nat.cast_add, Nat.cast_one, Nat.cast_mul, + Nat.cast_ofNat, Nat.cast_pow] + push_cast + convert hp using 1 <;> first | (solve | norm_num) | (solve | field_simp) + +theorem incident_single_rate (n : ℕ) : + 3*(((20*(n+1) : ℕ) : ℝ≥0)*clauseAtomRate n)* + Fintype.card (Fin 2 → SignedLiteral n) ≤ 60 := by + apply NNReal.coe_le_coe.mp + rw [incident_pair_card] + simp only [clauseAtomRate, NNReal.coe_inv, NNReal.coe_mul, NNReal.coe_ofNat, + NNReal.coe_pow, Nat.cast_add, Nat.cast_one, Nat.cast_mul, + Nat.cast_ofNat, Nat.cast_pow] + push_cast + have hp : (0 : ℝ) < (n : ℝ)+1 := by positivity + have he : (3 : ℝ)*(20*((n : ℝ)+1)*(8*((n : ℝ)+1)^3)⁻¹)*(4*(n : ℝ)^2) = + 30*(n : ℝ)^2/((n : ℝ)+1)^2 := by field_simp; ring + rw [he, div_le_iff₀ (sq_pos_of_pos hp)] + nlinarith [Nat.cast_nonneg (α := ℝ) n] + +theorem incident_bad_rate (n : ℕ) : + (Fintype.card (BadIncident n) : ℝ)* + ((((20*(n+1) : ℕ) : ℝ≥0)*clauseAtomRate n) : ℝ) ≤ 60/((n : ℝ)+1) := by + rw [incident_bad_card] + simp only [clauseAtomRate, NNReal.coe_inv, NNReal.coe_mul, NNReal.coe_ofNat, + NNReal.coe_pow, Nat.cast_add, Nat.cast_one, Nat.cast_mul, Nat.cast_ofNat] + push_cast + have hp : (0 : ℝ) < (n : ℝ)+1 := by positivity + have he : (6*(n : ℝ)+1)*(20*((n : ℝ)+1)*(8*((n : ℝ)+1)^3)⁻¹) = + (15*(n : ℝ)+(5/2 : ℝ))/((n : ℝ)+1)^2 := by field_simp; ring + rw [he, div_le_div_iff₀ (sq_pos_of_pos hp) hp] + nlinarith [Nat.cast_nonneg (α := ℝ) n] + +theorem incident_grid_obstruction {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) : + (finiteMap (gridMaskLaw (20*(n+1)) (clauseAtomRate n) incidentMask) frontloadMask).expect + (fun I => if U ∩ I = ∅ then 1 else 0) ≤ + poissonKillProbability U 2 60 + 60/((n : ℝ)+1) := by + rw [finiteMap_expect, gridMaskLaw_frontload _ _ + (fun I => if U ∩ I = ∅ then 1 else 0)] + exact (incident_killing_bound _ U).trans + (add_le_add (poissonKillProbability_mono_rate U 2 (incident_single_rate n)) + (incident_bad_rate n)) + +theorem incident_restored_uniform_moment {n : ℕ} [NeZero n] (r : ℕ) : + let M := 20*(n+1) + let P := gridMaskLaw M (clauseAtomRate n) (incidentMask (n := n)) + let rate := clauseAtomRate n * Fintype.card (Triple (SignedLiteral n)) + P.expect (fun f => P.expect (fun t => + (FiniteLaw.pi (fun _ : Fin M => candidateBlock rate 3 Finset.univ)).expect (fun base => + (maskLifetime M (deletionBudgetMask n r) base - + maskLifetime M (deletionBudgetMask (n+1) r) + (fun j => restoredMask (base j) (f j) (t j)))^(6/5 : ℝ)))) ≤ + deletionMomentConstant := by + dsimp only + have h := restored_process_moment (20*(n+1)) r + (clauseAtomRate n * Fintype.card (Triple (SignedLiteral n))) + (clause_base_rate (NeZero.pos n)) + (gridMaskLaw (20*(n+1)) (clauseAtomRate n) incidentMask) + (60/((n : ℝ)+1)) incident_grid_obstruction + apply h.trans + unfold deletionMomentConstant + apply add_le_add le_rfl + rw [mul_assoc] + apply mul_le_mul_of_nonneg_left _ (by norm_num : (0 : ℝ) ≤ 12/5) + simpa only [Nat.succ_eq_add_one, Nat.cast_add, Nat.cast_one] using + capped_incident_error (Nat.succ_pos n) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/InterpolationInputs.lean b/lean/OAI/Probability/SATComputability/InterpolationInputs.lean new file mode 100644 index 0000000000000000000000000000000000000000..af4c28458837983c45ea8c300e72026c68899386 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/InterpolationInputs.lean @@ -0,0 +1,48 @@ +import OAI.Probability.DilutedSpin.PoissonCountThinning + +namespace OAI + +namespace FixedClauseThreshold.Computability.PositiveInterpolation +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators + +structure InterpolationAdmissible {p : ℕ} (M : Model p) : Prop where + arity : 2 ≤ p + density : 0 < M.alpha + interaction_integrable : Integrable (fun z : InteractionSample p => ‖z.1‖) + M.disorder.toMeasure + field_integrable : Integrable (fun h : ℝ => |h|) M.field.toMeasure + factorization : ∀ᵐ z ∂M.disorder.toMeasure, + 0 < z.2.1 ∧ ∀ s : Fin p → Spin, + Real.exp (z.1 s) = z.2.1 * (1 + z.2.2.1 * ∏ l, z.2.2.2 l (s l)) ∧ + |z.2.2.1 * ∏ l, z.2.2.2 l (s l)| < 1 + independent_f : iIndepFun (fun l (z : InteractionSample p) => z.2.2.2 l) + M.disorder.toMeasure + identically_distributed_f : ∀ l j : Fin p, + IdentDistrib (fun z : InteractionSample p => z.2.2.2 l) + (fun z : InteractionSample p => z.2.2.2 j) + M.disorder.toMeasure M.disorder.toMeasure + independent_b : IndepFun (fun z : InteractionSample p => z.2.2.1) + (fun z : InteractionSample p => z.2.2.2) M.disorder.toMeasure + finite_b_moments : ∀ n : ℕ, 1 ≤ n → + Integrable (fun z : InteractionSample p => (-z.2.2.1) ^ n) M.disorder.toMeasure + positivity : ∀ n : ℕ, 1 ≤ n → + 0 ≤ ∫ z : InteractionSample p, (-z.2.2.1) ^ n ∂M.disorder.toMeasure + + raw_nonnegative : ∀ (n : ℕ), 1 ≤ n → ∀ (j : Fin p) + (P B : FiniteLaw (Fin n → Spin)), + 0 ≤ rawReplicaMoment M (fun _ : Fin p => P) - + (p : ℝ) * rawReplicaMoment M (fun l : Fin p => if l = j then P else B) + + ((p - 1 : ℕ) : ℝ) * rawReplicaMoment M (fun _ : Fin p => B) + +lemma rawReplica_combination_nonneg {p n : ℕ} (M : Model p) + (hM : InterpolationAdmissible M) (hn : 1 ≤ n) (j : Fin p) + (P B : FiniteLaw (Fin n → Spin)) : + 0 ≤ rawReplicaMoment M (fun _ : Fin p => P) - + (p : ℝ) * rawReplicaMoment M (fun l : Fin p => if l = j then P else B) + + ((p - 1 : ℕ) : ℝ) * rawReplicaMoment M (fun _ : Fin p => B) := + hM.raw_nonnegative n hn j P B + +end FixedClauseThreshold.Computability.PositiveInterpolation + +end OAI diff --git a/lean/OAI/Probability/SATComputability/InterpolationUpper.lean b/lean/OAI/Probability/SATComputability/InterpolationUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..e21185611785e1ca7434136188581d540943e7e9 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/InterpolationUpper.lean @@ -0,0 +1,1211 @@ +import OAI.Probability.SATComputability.InterpolationInputs +import OAI.Probability.DilutedSpin.DenseUpper + +namespace OAI + +noncomputable section +open DilutedSpinGlass DilutedSpinGlass.PrescribedTree DilutedSpinGlass.KernelTower +open _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory Filter Set +open scoped BigOperators NNReal ENNReal Topology + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSingletonClass R] in +lemma upperDatum_integrable_norm (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) : + Integrable (fun a : UpperDatum p N R => ‖a.1.1‖) (upperDatumLaw (N := N) M Q) := + measurePreserving_fst.integrable_comp_of_integrable hM.interaction_integrable + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma datumRoot_integrable_firstMoment (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (T : KernelTower Ω n) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) (f : FinitePath Ω n → ℝ) + (k l : ℕ) {B : ℝ} (hf : ∀ y,|f y|≤B) : + Integrable (fun z : RootPath (UpperDatum p N R) k × RootPath (UpperDatum p N R) l => + datumRoot T U V x m j f k l z.1 z.2) + ((rootLaw k (fun _ => upperDatumLaw (N := N) M Q)).prod (rootLaw l (fun _ => upperDatumLaw (N := N) M Q))) := by + have hk := integrable_rootArray_sum (upperDatumLaw (N := N) M Q) (fun a => ‖a.1.1‖) (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperDatum_integrable_norm M hM Q) k + have hl := integrable_rootArray_sum (upperDatumLaw (N := N) M Q) (fun a => ‖a.1.1‖) (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperDatum_integrable_norm M hM Q) l + apply ((integrable_const B).add (hk.comp_fst (rootLaw l (fun _ => upperDatumLaw (N := N) M Q)))).add (hl.comp_snd (rootLaw k (fun _ => upperDatumLaw (N := N) M Q))) |>.mono' + (measurable_datumRoot T U V x m j f k l).aestronglyMeasurable + exact ae_of_all _ (fun z => datumRoot_norm_bound T U V x m hm j f k l z.1 z.2 hf) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma upperCountMean_bound_firstMoment (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) (f : FinitePath Ω n → ℝ) + (k l : ℕ) {B : ℝ} (hf : ∀ y,|f y|≤B) : + |upperCountMean M T Q U V x m j f k l|≤B+(∫ a,‖a.1‖ ∂M.disorder.toMeasure)*(k+l) := by + let g := fun a : UpperDatum p N R => ‖a.1.1‖ + have hg := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperDatum_integrable_norm (N := N) M hM Q + have hk := integrable_rootArray_sum (upperDatumLaw (N := N) M Q) g hg k + have hl := integrable_rootArray_sum (upperDatumLaw (N := N) M Q) g hg l + have hB := ((integrable_const B).add (hk.comp_fst (rootLaw l (fun _ => upperDatumLaw (N := N) M Q)))).add (hl.comp_snd (rootLaw k (fun _ => upperDatumLaw (N := N) M Q))) + unfold upperCountMean + rw [← integral_prod _ (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.datumRoot_integrable_firstMoment M hM Q T U V x m hm j f k l hf)] + apply (abs_integral_le_integral_abs).trans + apply (integral_mono (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.datumRoot_integrable_firstMoment M hM Q T U V x m hm j f k l hf).abs hB + (fun z => datumRoot_norm_bound T U V x m hm j f k l z.1 z.2 hf)).trans_eq + change (∫ z : RootPath (UpperDatum p N R) k × RootPath (UpperDatum p N R) l, + (B + ∑ a, g (rootArray k z.1 a)) + ∑ a, g (rootArray l z.2 a) + ∂(rootLaw k (fun _ => upperDatumLaw (N := N) M Q)).prod (rootLaw l (fun _ => upperDatumLaw (N := N) M Q))) = _ + have he1 := integral_add ((integrable_const B).add (hk.comp_fst (rootLaw l (fun _ => upperDatumLaw (N := N) M Q)))) (hl.comp_snd (rootLaw k (fun _ => upperDatumLaw (N := N) M Q))) + have he2 := integral_add (integrable_const B) (hk.comp_fst (rootLaw l (fun _ => upperDatumLaw (N := N) M Q))) + simp only [Pi.add_apply] at he1 he2 + rw [he1,he2] + have hek : (∫ z : RootPath (UpperDatum p N R) k × RootPath (UpperDatum p N R) l, + ∑ a,g (rootArray k z.1 a) ∂(rootLaw k (fun _ => upperDatumLaw (N := N) M Q)).prod + (rootLaw l (fun _ => upperDatumLaw (N := N) M Q))) = + ∫ z : RootPath (UpperDatum p N R) k,∑ a,g (rootArray k z a) ∂rootLaw k (fun _ => upperDatumLaw (N := N) M Q) := + by simpa only [probReal_univ,one_smul] using (integral_fun_fst (μ := rootLaw k (fun _ => upperDatumLaw (N := N) M Q)) (ν := rootLaw l (fun _ => upperDatumLaw (N := N) M Q)) (fun z => ∑ a,g (rootArray k z a))) + have hel : (∫ z : RootPath (UpperDatum p N R) k × RootPath (UpperDatum p N R) l, + ∑ a,g (rootArray l z.2 a) ∂(rootLaw k (fun _ => upperDatumLaw (N := N) M Q)).prod + (rootLaw l (fun _ => upperDatumLaw (N := N) M Q))) = + ∫ z : RootPath (UpperDatum p N R) l,∑ a,g (rootArray l z a) ∂rootLaw l (fun _ => upperDatumLaw (N := N) M Q) := + by simpa only [probReal_univ,one_smul] using (integral_fun_snd (μ := rootLaw k (fun _ => upperDatumLaw (N := N) M Q)) (ν := rootLaw l (fun _ => upperDatumLaw (N := N) M Q)) (fun z => ∑ a,g (rootArray l z a))) + rw [hek,hel,integral_rootArray_sum _ g hg k,integral_rootArray_sum _ g hg l] + have he : (∫ a,g a ∂upperDatumLaw (N := N) M Q)=∫ a,‖a.1‖ ∂M.disorder.toMeasure := by + simpa only [g,upperDatumLaw,probReal_univ,one_smul] using (integral_fun_fst (μ := M.disorder.toMeasure) (ν := ((FiniteLaw.pi (fun _ : Fin p => (FiniteLaw.uniform : FiniteLaw (Fin N)))).asProbability id).toMeasure.prod ((FiniteLaw.pi (fun _ : Fin p => Q)).asProbability id).toMeasure) (fun a : InteractionSample p => ‖a.1‖)) + rw [he] + simp only [integral_const,probReal_univ,one_smul] + ring + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integrable_mixedLogAvg (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ j, 0 ≤ m j) + (hnz : ∀ j : Fin n,m j.succ≠0) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (sel : Fin p → Bool) {t : ℝ} (ht : |t|<1) : + Integrable (fun z => mixedLogAvg T Q U V x m z sel t) M.disorder.toMeasure := by + apply Integrable.of_bound (measurable_mixedLogAvg T Q U V x m sel t).aestronglyMeasurable + (∑' k : ℕ,|t|^(k+1)/(k+1)) + filter_upwards [hM.factorization] with z hz + simpa only [Real.norm_eq_abs,Finset.range_zero,Finset.sum_empty,sub_zero,Nat.add_zero, + Nat.cast_zero,add_zero] using mixedLogAvg_negative_tail T Q U V x m hm hpos hnz hroot hend + z (fun s => (hz.2 s).2.le) sel ht 0 + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integrable_mixedNormalizedAvg (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : ∀ j : Fin n,0 < m j.succ) + (sel : Fin p → Bool) {t : ℝ} (ht0 : 0≤t) (ht : t<1) : + Integrable (fun z => mixedNormalizedAvg T Q U V x m z sel t) M.disorder.toMeasure := by + apply (hM.interaction_integrable.const_mul 2).mono' + (measurable_mixedNormalizedAvg T Q U V x m sel t).aestronglyMeasurable + filter_upwards [hM.factorization] with z hz + simpa only [Real.norm_eq_abs] using mixedNormalizedAvg_bound T Q U V x m hm z hz sel ht0 ht + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integrable_mixedLeafAvg (M : Model p) (hM : InterpolationAdmissible M) + (S : PrescribedTree n) (T : KernelTower Ω n) + (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (sel : Fin p → Bool) : Integrable (fun z => mixedLeafAvg S T Q U V x z sel) M.disorder.toMeasure := by + apply Integrable.of_bound (measurable_mixedLeafAvg S T Q U V x sel).aestronglyMeasurable 1 + filter_upwards [hM.factorization] with z hz + simpa only [Real.norm_eq_abs] using mixedLeafAvg_bound S T Q U V x z (fun s => (hz.2 s).2.le) sel + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integral_mixedLogAvg_negative_tail (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ j, 0 ≤ m j) + (hnz : ∀ j : Fin n,m j.succ≠0) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (sel : Fin p → Bool) {t : ℝ} (ht : |t|<1) (K : ℕ) : + |(∫ z,mixedLogAvg T Q U V x m z sel t ∂M.disorder.toMeasure)-∑ k∈Finset.range K, + -(t^(k+1)/(k+1))*qExpect m + (fun S => ∫ z,mixedLeafAvg S T Q U V x z sel ∂M.disorder.toMeasure) k (single n)| ≤ + ∑' k : ℕ,|t|^(k+K+1)/(k+K+1) := by + have hi (S : PrescribedTree n) := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integrable_mixedLeafAvg M hM S T Q U V x sel + simp_rw [← integral_qExpect _ m _ hi,← integral_const_mul] + rw [← integral_finsetSum _ (fun k _ => (integrable_qExpect _ m _ hi k (single n)).const_mul _)] + rw [← integral_sub (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integrable_mixedLogAvg M hM T Q U V x m hm hpos hnz hroot hend sel ht) + (integrable_finsetSum _ (fun k _ => (integrable_qExpect _ m _ hi k (single n)).const_mul _))] + have hb : ∀ᵐ z ∂M.disorder.toMeasure, + ‖mixedLogAvg T Q U V x m z sel t-∑ k∈Finset.range K, + -(t^(k+1)/(k+1))*qExpect m (fun S => mixedLeafAvg S T Q U V x z sel) k (single n)‖ ≤ + ∑' k : ℕ,|t|^(k+K+1)/(k+K+1) := by + filter_upwards [hM.factorization] with z hz + simpa only [Real.norm_eq_abs] using mixedLogAvg_negative_tail T Q U V x m hm hpos hnz hroot hend + z (fun s => (hz.2 s).2.le) sel ht K + simpa only [Real.norm_eq_abs,probReal_univ,mul_one] using norm_integral_le_of_norm_le_const hb + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma integrable_insertionPoint {Z : Type} [Fintype Z] {p n N : ℕ} [NeZero N] + (M : Model p) (hM : InterpolationAdmissible M) (old : Fin N → Fin n → Spin) (Q : FiniteLaw Z) + (x : Z → Fin n → ℝ) (sel : Fin p → Bool) : + Integrable (fun z => insertionPoint z old Q x sel) M.disorder.toMeasure := by + apply Integrable.of_bound (measurable_insertionPoint old Q x sel).aestronglyMeasurable 1 + filter_upwards [hM.factorization] with z hz + simpa only [Real.norm_eq_abs] using insertionPoint_bound z (fun s => (hz.2 s).2.le) old Q x sel + +end +end FixedClauseThreshold.Computability.PositiveInterpolation + +namespace FixedClauseThreshold.Computability.PositiveInterpolation +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma integral_expected_insertionPoint {Ω Z : Type} [Fintype Ω] [Fintype Z] + {p n N : ℕ} [NeZero N] (M : Model p) (hM : InterpolationAdmissible M) + (P : FiniteLaw Ω) (old : Ω → Fin N → Fin n → Spin) + (Q : FiniteLaw Z) (x : Z → Fin n → ℝ) (sel : Fin p → Bool) : + (∫ z,P.expect (fun w => insertionPoint z (old w) Q x sel) ∂M.disorder.toMeasure)= + P.expect (fun w => insertionCoefficient M (old w) Q x sel) := + FiniteLaw.integral_expect P M.disorder.toMeasure _ + (fun w => FixedClauseThreshold.Computability.PositiveInterpolation.integrable_insertionPoint M hM (old w) Q x sel) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integratedMixedLeaf_identity (M : Model p) (hM : InterpolationAdmissible M) + (S : PrescribedTree n) (T : KernelTower Ω n) + (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (sel : Fin p → Bool) : + (∫ z,mixedLeafAvg S T Q U V x z sel ∂M.disorder.toMeasure)= + (S.sampleLaw T).expect (fun old => insertionCoefficient M + (fun i a => V (S.pathAt ((Fintype.equivFin S.Leaf).symm a) old) i) + (Q.bind (fun r => S.sampleLaw (U r))) + (fun w a => x w.1 (S.pathAt ((Fintype.equivFin S.Leaf).symm a) w.2)) sel) := by + unfold mixedLeafAvg + simp_rw [common_tree_point] + exact FixedClauseThreshold.Computability.PositiveInterpolation.integral_expected_insertionPoint M hM _ _ _ _ _ + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma insertionCoefficient_combination_nonneg {Z : Type} [Fintype Z] + {p n N : ℕ} [NeZero N] (M : Model p) (hM : InterpolationAdmissible M) (hn : 1≤n) + (old : Fin N → Fin n → Spin) (Q : FiniteLaw Z) (x : Z → Fin n → ℝ) (j : Fin p) : + 0 ≤ insertionCoefficient M old Q x (fun _ => true) - + (p:ℝ)*insertionCoefficient M old Q x (fun l => decide (l=j)) + + ((p-1:ℕ):ℝ)*insertionCoefficient M old Q x (fun _ => false) := by + simp only [insertionCoefficient_eq_raw,↓reduceIte,Bool.false_eq_true,decide_eq_true_eq] + exact FixedClauseThreshold.Computability.PositiveInterpolation.rawReplica_combination_nonneg M hM hn j _ _ + +end +end FixedClauseThreshold.Computability.PositiveInterpolation + +namespace FixedClauseThreshold.Computability.PositiveInterpolation +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma expected_insertionCoefficient_nonneg {Ω Z : Type} [Fintype Ω] [Fintype Z] + {p n N : ℕ} [NeZero N] (M : Model p) (hM : InterpolationAdmissible M) (hn : 1≤n) + (P : FiniteLaw Ω) (old : Ω → Fin N → Fin n → Spin) + (Q : FiniteLaw Z) (x : Z → Fin n → ℝ) (j : Fin p) : + 0 ≤ P.expect (fun w => insertionCoefficient M (old w) Q x (fun _ => true)) - + (p:ℝ)*P.expect (fun w => insertionCoefficient M (old w) Q x (fun l => decide (l=j))) + + ((p-1:ℕ):ℝ)*P.expect (fun w => insertionCoefficient M (old w) Q x (fun _ => false)) := by + rw [← FiniteLaw.expect_mul_left,← FiniteLaw.expect_sub,← FiniteLaw.expect_mul_left, + ← FiniteLaw.expect_add] + exact P.expect_nonneg (fun w => FixedClauseThreshold.Computability.PositiveInterpolation.insertionCoefficient_combination_nonneg M hM hn (old w) Q x j) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integratedMixedLeaf_combination_nonneg (M : Model p) (hM : InterpolationAdmissible M) + (S : PrescribedTree n) (T : KernelTower Ω n) + (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) (j : Fin p) : + 0 ≤ (∫ z,mixedLeafAvg S T Q U V x z (fun _ => true) ∂M.disorder.toMeasure)- + (p:ℝ)*(∫ z,mixedLeafAvg S T Q U V x z (fun l => decide (l=j)) ∂M.disorder.toMeasure)+ + ((p-1:ℕ):ℝ)*(∫ z,mixedLeafAvg S T Q U V x z (fun _ => false) ∂M.disorder.toMeasure) := by + simp only [FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integratedMixedLeaf_identity M hM] + apply FixedClauseThreshold.Computability.PositiveInterpolation.expected_insertionCoefficient_nonneg M hM + rw [card_leaf] + exact leaves_pos S + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma mixedQMoment_combination_nonneg (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ j, 0 ≤ m j) + (k : ℕ) (S : PrescribedTree n) (j : Fin p) : + 0 ≤ qExpect m (fun S => ∫ z,mixedLeafAvg S T Q U V x z (fun _ => true) ∂M.disorder.toMeasure) k S- + (p:ℝ)*qExpect m (fun S => ∫ z,mixedLeafAvg S T Q U V x z (fun l => decide (l=j)) ∂M.disorder.toMeasure) k S+ + ((p-1:ℕ):ℝ)*qExpect m (fun S => ∫ z,mixedLeafAvg S T Q U V x z (fun _ => false) ∂M.disorder.toMeasure) k S := by + rw [← qExpect_linear_combination] + exact qExpect_nonneg m hm hpos _ (fun S => FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integratedMixedLeaf_combination_nonneg M hM S T Q U V x j) k S + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integral_mixedLog_combination_nonpos (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ j, 0 ≤ m j) + (hnz : ∀ j : Fin n,m j.succ≠0) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (j : Fin p) {t : ℝ} (ht0 : 0≤t) (ht : t<1) : + (∫ z,mixedLogAvg T Q U V x m z (fun _ => true) t ∂M.disorder.toMeasure)- + (p:ℝ)*(∫ z,mixedLogAvg T Q U V x m z (fun l => decide (l=j)) t ∂M.disorder.toMeasure)+ + ((p-1:ℕ):ℝ)*(∫ z,mixedLogAvg T Q U V x m z (fun _ => false) t ∂M.disorder.toMeasure) ≤0 := by + have ht' : |t|<1 := by rwa [abs_of_nonneg ht0] + have hlim : Tendsto (fun K : ℕ => (1+(p:ℝ)+((p-1:ℕ):ℝ))* + ∑' k : ℕ,|t|^(k+K+1)/(k+K+1)) atTop (𝓝 0) := by + convert (tendsto_sum_nat_add (fun k : ℕ => |t|^(k+1)/(k+1))).const_mul + (1+(p:ℝ)+((p-1:ℕ):ℝ)) using 1 <;> simp + apply ge_of_tendsto hlim + exact Eventually.of_forall (fun K => negative_series_combination (Nat.cast_nonneg p) + (Nat.cast_nonneg (p-1)) ht0 _ _ _ K + (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedLogAvg_negative_tail M hM T Q U V x m hm hpos hnz hroot hend _ ht' K) + (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedLogAvg_negative_tail M hM T Q U V x m hm hpos hnz hroot hend _ ht' K) + (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedLogAvg_negative_tail M hM T Q U V x m hm hpos hnz hroot hend _ ht' K) + (fun k => FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.mixedQMoment_combination_nonneg M hM T Q U V x m hm hpos k (single n) j)) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integrable_mixedEnergyAvg (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : ∀ j : Fin n,0 < m j.succ) (sel : Fin p → Bool) : + Integrable (fun z => mixedEnergyAvg T Q U V x m z sel) M.disorder.toMeasure := by + apply hM.interaction_integrable.mono' (measurable_mixedEnergyAvg T Q U V x m sel).aestronglyMeasurable + exact ae_of_all _ (fun z => by simpa only [Real.norm_eq_abs] using mixedEnergyAvg_bound T Q U V x m hm z sel) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integral_mixedNormalizedAvg_limit (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : ∀ j : Fin n,0 < m j.succ) (sel : Fin p → Bool) : + Tendsto (fun k => ∫ z,mixedNormalizedAvg T Q U V x m z sel (regularization k) ∂M.disorder.toMeasure) + atTop (𝓝 ((∫ z,mixedEnergyAvg T Q U V x m z sel ∂M.disorder.toMeasure)- + ∫ z,z.1 (fun _ => false) ∂M.disorder.toMeasure)) := by + have href : Integrable (fun z : InteractionSample p => z.1 (fun _ => false)) M.disorder.toMeasure := + hM.interaction_integrable.mono' (by fun_prop) (ae_of_all _ (fun z => norm_le_pi_norm z.1 _)) + rw [← integral_sub (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integrable_mixedEnergyAvg M hM T Q U V x m hm sel) href] + apply tendsto_integral_of_dominated_convergence (fun z : InteractionSample p => 2*‖z.1‖) + · intro k + exact (measurable_mixedNormalizedAvg T Q U V x m sel _).aestronglyMeasurable + · exact hM.interaction_integrable.const_mul 2 + · intro k + filter_upwards [hM.factorization] with z hz + simpa only [Real.norm_eq_abs] using mixedNormalizedAvg_bound T Q U V x m hm z hz sel + (regularization_nonneg k) (regularization_lt_one k) + · filter_upwards [hM.factorization] with z hz + exact (mixedNormalizedAvg_limit T Q U V x m (fun j => ne_of_gt (hm j)) z hz sel).comp regularization_limit + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integral_mixedEnergy_combination_nonpos (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ j, 0 ≤ m j) + (hstrict : ∀ j : Fin n,0 < m j.succ) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (j : Fin p) : + (∫ z,mixedEnergyAvg T Q U V x m z (fun _ => true) ∂M.disorder.toMeasure)- + (p:ℝ)*(∫ z,mixedEnergyAvg T Q U V x m z (fun l => decide (l=j)) ∂M.disorder.toMeasure)+ + ((p-1:ℕ):ℝ)*(∫ z,mixedEnergyAvg T Q U V x m z (fun _ => false) ∂M.disorder.toMeasure) ≤0 := by + have hp : ((p-1:ℕ):ℝ)=(p:ℝ)-1 := by + rw [Nat.cast_sub (by have h := hM.arity; omega : 1≤p)]; norm_num + have hr (k : ℕ) : + (∫ z,mixedNormalizedAvg T Q U V x m z (fun _ => true) (regularization k) ∂M.disorder.toMeasure)- + (p:ℝ)*(∫ z,mixedNormalizedAvg T Q U V x m z (fun l => decide (l=j)) (regularization k) ∂M.disorder.toMeasure)+ + ((p-1:ℕ):ℝ)*(∫ z,mixedNormalizedAvg T Q U V x m z (fun _ => false) (regularization k) ∂M.disorder.toMeasure) ≤0 := by + have ht0 := regularization_nonneg k + have ht := regularization_lt_one k + have ht' : |regularization k|<1 := by rwa [abs_of_nonneg ht0] + have hi (sel : Fin p → Bool) := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integrable_mixedLogAvg M hM T Q U V x m hm hpos (fun l => ne_of_gt (hstrict l)) hroot hend sel ht' + have hn (sel : Fin p → Bool) := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integrable_mixedNormalizedAvg M hM T Q U V x m hstrict sel ht0 ht + have hd : Integrable (fun z => Real.log (1+regularization k*referenceD z)) M.disorder.toMeasure := by + convert (hi (fun _ => false)).sub (hn (fun _ => false)) using 1 + funext z + simp only [Pi.sub_apply,mixedNormalizedAvg] + ring + simp only [mixedNormalizedAvg] + rw [integral_sub (hi _) hd,integral_sub (hi _) hd,integral_sub (hi _) hd] + have hs := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedLog_combination_nonpos M hM T Q U V x m hm hpos + (fun l => ne_of_gt (hstrict l)) hroot hend j ht0 ht + rw [hp] at hs ⊢ + nlinarith only [hs] + have hlim := ((FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedNormalizedAvg_limit M hM T Q U V x m hstrict (fun _ => true)).sub + ((FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedNormalizedAvg_limit M hM T Q U V x m hstrict (fun l => decide (l=j))).const_mul (p:ℝ))).add + ((FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedNormalizedAvg_limit M hM T Q U V x m hstrict (fun _ => false)).const_mul ((p-1:ℕ):ℝ)) + have hs := le_of_tendsto hlim (Eventually.of_forall hr) + rw [hp] at hs ⊢ + nlinarith only [hs] + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSpace R] [MeasurableSingletonClass R] in +lemma integral_mixedRoot_combination_nonpos (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ j,0 ≤ m j) + (hstrict : ∀ j : Fin n,0 < m j.succ) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (f : FinitePath Ω n → ℝ) (j : Fin p) : + (∫ z,mixedRootIncrement T Q U V x m f z (fun _ => true) ∂M.disorder.toMeasure)- + (p:ℝ)*(∫ z,mixedRootIncrement T Q U V x m f z (fun l => decide (l=j)) ∂M.disorder.toMeasure)+ + ((p-1:ℕ):ℝ)*(∫ z,mixedRootIncrement T Q U V x m f z (fun _ => false) ∂M.disorder.toMeasure) ≤0 := by + simp only [mixedRootIncrement_eq] + exact FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedEnergy_combination_nonpos M hM _ Q U V x m hm hpos hstrict hroot hend j + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma freshRoot_mean_sub_firstMoment (M : Model p) (hM : InterpolationAdmissible M) + (Q : FiniteLaw R) (T : KernelTower Ω n) + (U : R → KernelTower Λ n) (V : FinitePath Ω n → Fin N → Spin) + (x : R → FinitePath Λ n → ℝ) (m : Fin (n+1) → ℝ) (hm : ∀ d : Fin n,0 < m d.succ) + (f : FinitePath Ω n → ℝ) (sel : Fin p → Bool) {B : ℝ} + (hf : ∀ y,|f y|≤B) : + (∫ a,freshRoot T U V x (fun d => m d.succ) f sel a ∂upperDatumLaw M Q)- + backwardLog n T (fun d => m d.succ) f = + ∫ θ,mixedRootIncrement T Q U V x m f θ sel ∂M.disorder.toMeasure := by + let g := freshRoot T U V x (fun d => m d.succ) f sel + have hg := measurable_freshRoot T U V x (fun d => m d.succ) f sel + have hb (a : InteractionSample p) (i : Fin p → Fin N) (r : Fin p → R) : |g (a,i,r)|≤B+‖a.1‖ := + freshRoot_bound T U V x _ hm f sel (a,i,r) hf + have hi : Integrable g (upperDatumLaw M Q) := by + apply ((integrable_const B).add (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperDatum_integrable_norm M hM Q)).mono' hg.aestronglyMeasurable + exact ae_of_all _ (fun a => hb a.1 a.2.1 a.2.2) + rw [integral_upperDatumLaw_integrable M Q g hg hi] + let G := fun θ => (FiniteLaw.pi (fun _ : Fin p => (FiniteLaw.uniform : FiniteLaw (Fin N)))).expect + (fun i => (FiniteLaw.pi (fun _ : Fin p => Q)).expect (fun r => g (θ,i,r))) + have hG : Measurable G := FiniteLaw.measurable_expect _ (fun i => + FiniteLaw.measurable_expect _ (fun r => hg.comp (measurable_id.prodMk measurable_const))) + have hiG : Integrable G M.disorder.toMeasure := by + apply ((integrable_const B).add hM.interaction_integrable).mono' hG.aestronglyMeasurable + exact ae_of_all _ (fun a => FiniteLaw.abs_expect_le _ (fun i => FiniteLaw.abs_expect_le _ (hb a i))) + change (∫ θ,G θ ∂M.disorder.toMeasure)-_=_ + have hc : backwardLog n T (fun d => m d.succ) f = + ∫ _θ : InteractionSample p, backwardLog n T (fun d => m d.succ) f ∂M.disorder.toMeasure := by simp + rw [hc,← integral_sub hiG (integrable_const _)] + apply integral_congr_ae + filter_upwards [] with θ + simp only [mixedRootIncrement,FiniteLaw.expect_sub,FiniteLaw.expect_const] + rfl + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma freshRoot_replacement_firstMoment (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ d,0 ≤ m d) + (hstrict : ∀ d : Fin n,0 < m d.succ) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (f : FinitePath Ω n → ℝ) (j : Fin p) {B : ℝ} + (hf : ∀ y,|f y|≤B) : + (∫ a,freshRoot T U V x (fun d => m d.succ) f (fun _ => true) a ∂upperDatumLaw M Q)+ + ((p-1:ℕ):ℝ)*backwardLog n T (fun d => m d.succ) f ≤ + (p:ℝ)*(∫ a,freshRoot T U V x (fun d => m d.succ) f (fun d => decide (d=j)) a ∂upperDatumLaw M Q)- + ((p-1:ℕ):ℝ)*(∫ a,edgeRoot Q U x (fun d => m d.succ) a ∂M.disorder.toMeasure) := by + have h := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.integral_mixedRoot_combination_nonpos M hM T Q U V x m hm hpos hstrict hroot hend f j + simp_rw [mixedRootIncrement_false] at h + rw [← FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.freshRoot_mean_sub_firstMoment M hM Q T U V x m hstrict f (fun _ => true) hf, + ← FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.freshRoot_mean_sub_firstMoment M hM Q T U V x m hstrict f (fun d => decide (d=j)) hf] at h + have hp : ((p-1:ℕ):ℝ)=(p:ℝ)-1 := by rw [Nat.cast_sub (by have := hM.arity; omega : 1≤p),Nat.cast_one] + rw [hp] at h ⊢ + nlinarith + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma datumRoot_conditional_replacement_firstMoment (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ d,0 ≤ m d) + (hstrict : ∀ d : Fin n,0 < m d.succ) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (j : Fin p) (f : FinitePath Ω n → ℝ) (k l : ℕ) + (z : RootPath (UpperDatum p N R) k) (w : RootPath (UpperDatum p N R) l) + : + (∫ a,datumRoot T U V x (fun d => m d.succ) j f (k+1) l (a,z) w ∂upperDatumLaw M Q)+ + ((p-1:ℕ):ℝ)*datumRoot T U V x (fun d => m d.succ) j f k l z w ≤ + (p:ℝ)*(∫ a,datumRoot T U V x (fun d => m d.succ) j f k (l+1) z (a,w) ∂upperDatumLaw M Q)- + ((p-1:ℕ):ℝ)*(∫ a,edgeRoot Q U x (fun d => m d.succ) a ∂M.disorder.toMeasure) := by + let F := cavityEnergy V x j l (rootMap (fun a => a.2.2) l w) + (rootMap (fun a => a.2.1) l w) (rootMap Prod.fst l w) + (realCountEnergy V k (rootMap (fun a => a.2.1) k z) (rootMap Prod.fst k z) f) + have h := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.freshRoot_replacement_firstMoment M hM + (cavityTower T U l (rootMap (fun a => a.2.2) l w)) Q U + (fun y => V (pathMap (cavityProject l) n y)) x m hm hpos hstrict hroot hend F j + (fun y => norm_le_pi_norm F y) + dsimp only [F] at h + simp only [datumRoot_fresh_true,datumRoot_fresh_selected] at h + exact h + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma upperCountMean_replacement_firstMoment (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ d,0 ≤ m d) + (hstrict : ∀ d : Fin n,0 < m d.succ) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (j : Fin p) (f : FinitePath Ω n → ℝ) (k l : ℕ) + : + upperCountMean M T Q U V x (fun d => m d.succ) j f (k+1) l+ + ((p-1:ℕ):ℝ)*upperCountMean M T Q U V x (fun d => m d.succ) j f k l ≤ + (p:ℝ)*upperCountMean M T Q U V x (fun d => m d.succ) j f k (l+1)- + ((p-1:ℕ):ℝ)*(∫ a,edgeRoot Q U x (fun d => m d.succ) a ∂M.disorder.toMeasure) := by + let D := upperDatumLaw (N := N) M Q + let μ := rootLaw k (fun _ => D) + let ν := rootLaw l (fun _ => D) + let F := fun zw : RootPath (UpperDatum p N R) k × RootPath (UpperDatum p N R) l => + datumRoot T U V x (fun d => m d.succ) j f k l zw.1 zw.2 + let G := fun azw : (UpperDatum p N R × RootPath (UpperDatum p N R) k) × RootPath (UpperDatum p N R) l => + datumRoot T U V x (fun d => m d.succ) j f (k+1) l azw.1 azw.2 + let H := fun zaw : RootPath (UpperDatum p N R) k × (UpperDatum p N R × RootPath (UpperDatum p N R) l) => + datumRoot T U V x (fun d => m d.succ) j f k (l+1) zaw.1 zaw.2 + have hF : Integrable F (μ.prod ν) := + FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.datumRoot_integrable_firstMoment M hM Q T U V x _ hstrict j f k l (fun y => norm_le_pi_norm f y) + have hG : Integrable G ((D.prod μ).prod ν) := + FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.datumRoot_integrable_firstMoment M hM Q T U V x _ hstrict j f (k+1) l (fun y => norm_le_pi_norm f y) + have hH : Integrable H (μ.prod (D.prod ν)) := + FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.datumRoot_integrable_firstMoment M hM Q T U V x _ hstrict j f k (l+1) (fun y => norm_le_pi_norm f y) + have ig := integrable_triple_rotate D μ ν G hG + have ih := integrable_triple_middle_swap μ D ν H hH + let e := ((p-1:ℕ):ℝ)*(∫ a,edgeRoot Q U x (fun d => m d.succ) a ∂M.disorder.toMeasure) + have hg := integral_mono (ig.add (hF.const_mul ((p-1:ℕ):ℝ))) ((ih.const_mul p).sub (integrable_const e)) + (fun zw => FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.datumRoot_conditional_replacement_firstMoment M hM T Q U V x m hm hpos hstrict hroot hend j f k l zw.1 zw.2) + simp only [Pi.add_apply,Pi.sub_apply] at hg + rw [integral_add ig (hF.const_mul _),integral_sub (ih.const_mul _) (integrable_const e), + integral_const_mul,integral_const_mul] at hg + have he : ∫ _zw,e ∂μ.prod ν=e := by + have := rootLawProbability k (fun _ => D) + have := rootLawProbability l (fun _ => D) + simp + rw [he,integral_prod _ ig,integral_prod _ ih,integral_prod _ hF, + ← integral_triple_rotate D μ ν G hG,← integral_triple_middle_swap μ D ν H hH] at hg + exact hg + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma upperPoissonCount_bound_firstMoment (M : Model p) (hM : InterpolationAdmissible M) + (T : KernelTower Ω n) (Q : FiniteLaw R) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Fin N → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin (n+1) → ℝ) (hm : Monotone m) (hpos : ∀ d,0 ≤ m d) + (hstrict : ∀ d : Fin n,0 < m d.succ) (hroot : m 0=0) (hend : m (Fin.last n)=1) + (j : Fin p) (f : FinitePath Ω n → ℝ) (r : ℝ≥0) + : + (∫ k,upperCountMean M T Q U V x (fun d => m d.succ) j f k 0 ∂poissonMeasure (r/p))+ + (r:ℝ)*(((p-1:ℕ):ℝ)/p)*(∫ a,edgeRoot Q U x (fun d => m d.succ) a ∂M.disorder.toMeasure) ≤ + ∫ l,upperCountMean M T Q U V x (fun d => m d.succ) j f 0 l ∂poissonMeasure r := by + have hp : 0 < p := by have := hM.arity; omega + let : NeZero p := ⟨Nat.ne_of_gt hp⟩ + have hpR : (p:ℝ)≠0 := by exact_mod_cast Nat.ne_of_gt hp + let e := ∫ a,edgeRoot Q U x (fun d => m d.succ) a ∂M.disorder.toMeasure + have hh := poisson_count_replacement r p + (upperCountMean M T Q U V x (fun d => m d.succ) j f) + ((((p-1:ℕ):ℝ)/p)*e) (show 0 ≤ ∫ a : InteractionSample p, ‖a.1‖ ∂M.disorder.toMeasure from + integral_nonneg (fun a => norm_nonneg a.1)) + (fun k l => FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperCountMean_bound_firstMoment M hM T Q U V x _ hstrict j f k l + (fun y => norm_le_pi_norm f y)) + (fun k l => ?_) + · simpa only [mul_assoc] using hh + · have h := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperCountMean_replacement_firstMoment M hM T Q U V x m hm hpos hstrict hroot hend j f k l + convert h using 1 + dsimp only [e] + field_simp + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma allocatedDatumRoot_integrable (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (T : KernelTower Ω n) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) (s : Fin N) + (f : FinitePath Ω n → ℝ) (l : ℕ) : + Integrable (fun z : RootPath (Fin N) l × RootPath (InteractionSample p × (Fin p → R)) l => + allocatedDatumRoot T U V x m j s f l z.1 z.2) + ((rootLaw l (fun _ => finiteUniform (Fin N))).prod + (rootLaw l (fun _ => M.disorder.toMeasure.prod + ((FiniteLaw.pi (fun _ : Fin p => Q)).asProbability id).toMeasure))) := by + have hi : Integrable (fun z : InteractionSample p × (Fin p → R) => ‖z.1.1‖) + (M.disorder.toMeasure.prod ((FiniteLaw.pi (fun _ : Fin p => Q)).asProbability id).toMeasure) := + measurePreserving_fst.integrable_comp_of_integrable hM.interaction_integrable + apply ((integrable_const ‖f‖).add ((integrable_rootArray_sum _ _ hi l).comp_snd + (rootLaw l (fun _ => finiteUniform (Fin N))))).mono' + (measurable_allocatedDatumRoot T U V x m j s f l).aestronglyMeasurable + exact ae_of_all _ (fun z => allocatedDatumRoot_bound T U V x m hm j s f l z.1 z.2) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma upperAllocated_integrable (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (T : KernelTower Ω n) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) (s : Fin N) + (f : FinitePath Ω n → ℝ) (l : ℕ) : + Integrable (fun z : RootPath (UpperDatum p N R) l => + backwardLog n (cavityTower T U l (rootMap (fun a => a.2.2) l z)) m + (allocatedEnergy V x j s l (rootMap (fun a => a.2.2) l z) + (rootMap (fun a => a.2.1 j) l z) (rootMap Prod.fst l z) f)) + (rootLaw l (fun _ => upperDatumLaw M Q)) := by + have h := ((measurePreserving_rootSplit _ _ l).comp + (measurePreserving_rootMap (upperDatum_site_projection M Q j) l)).integrable_comp_of_integrable + (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.allocatedDatumRoot_integrable M hM Q T U V x m hm j s f l) + simpa only [Function.comp_def,allocatedDatumRoot,rootMap_comp] using h + +omit [MeasurableSingletonClass R] in + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma upperAllocatedMean (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (T : KernelTower Ω n) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) (s : Fin N) + (f : FinitePath Ω n → ℝ) (l : ℕ) : + (∫ z : RootPath (UpperDatum p N R) l, + backwardLog n (cavityTower T U l (rootMap (fun a => a.2.2) l z)) m + (allocatedEnergy V x j s l (rootMap (fun a => a.2.2) l z) + (rootMap (fun a => a.2.1 j) l z) (rootMap Prod.fst l z) f) + ∂rootLaw l (fun _ => upperDatumLaw M Q))= + ∫ c,activeCountMean M Q T U V x m j f + (selectedCount l (rootMap (fun a => decide (a=s)) l c)) + ∂rootLaw l (fun _ => finiteUniform (Fin N)) := by + let F := fun z : RootPath (Fin N) l × RootPath (InteractionSample p × (Fin p → R)) l => + allocatedDatumRoot T U V x m j s f l z.1 z.2 + have hFm := measurable_allocatedDatumRoot T U V x m j s f l + have he : (fun z : RootPath (UpperDatum p N R) l => + backwardLog n (cavityTower T U l (rootMap (fun a => a.2.2) l z)) m + (allocatedEnergy V x j s l (rootMap (fun a => a.2.2) l z) + (rootMap (fun a => a.2.1 j) l z) (rootMap Prod.fst l z) f))= + fun z => F (rootMap Prod.fst l (rootMap (fun a => (a.2.1 j,(a.1,a.2.2))) l z), + rootMap Prod.snd l (rootMap (fun a => (a.2.1 j,(a.1,a.2.2))) l z)) := by + funext z + simp only [F,allocatedDatumRoot,rootMap_comp,Function.comp_def] + rw [he] + apply (integral_rootMap (upperDatum_site_projection M Q j) l + (fun z => F (rootMap Prod.fst l z,rootMap Prod.snd l z)) + (hFm.comp ((measurable_rootMap Prod.fst measurable_fst l).prodMk + (measurable_rootMap Prod.snd measurable_snd l)))).trans + rw [integral_rootSplit _ _ l F hFm (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.allocatedDatumRoot_integrable M hM Q T U V x m hm j s f l)] + apply integral_congr_ae + filter_upwards [] with c + exact allocatedMean_selected M Q T U V x m j f s l c + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma upperCountMean_separable (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (T : Fin N → KernelTower Ω n) (U : R → KernelTower Λ n) + (V : Fin N → FinitePath Ω n → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) + (f : Fin N → FinitePath Ω n → ℝ) (l : ℕ) : + upperCountMean M (KernelTower.pi n T) Q U (fun y s => V s (FinitePath.proj n y s)) x m j + (fun y => ∑ s,f s (FinitePath.proj n y s)) 0 l= + ∑ s : Fin N,∫ c,activeCountMean M Q (T s) U (V s) x m j (f s) + (selectedCount l (rootMap (fun a => decide (a=s)) l c)) + ∂rootLaw l (fun _ => finiteUniform (Fin N)) := by + rw [upperCountMean_cavity] + simp_rw [cavityRoot_separable,rootMap_comp,Function.comp_def] + rw [integral_finsetSum _ (fun s _ => FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperAllocated_integrable M hM Q (T s) U (V s) x m hm j s (f s) l)] + exact Finset.sum_congr rfl (fun s _ => FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperAllocatedMean M hM Q (T s) U (V s) x m hm j s (f s) l) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma activeCountMean_bound (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (T : KernelTower Ω n) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) + (f : FinitePath Ω n → ℝ) (l : ℕ) {B : ℝ} (hf : ∀ y,|f y|≤B) : + |activeCountMean M Q T U V x m j f l|≤B+(∫ a,‖a.1‖ ∂M.disorder.toMeasure)*l := by + let ν := M.disorder.toMeasure.prod ((FiniteLaw.pi (fun _ : Fin p => Q)).asProbability id).toMeasure + have hi : Integrable (fun z : InteractionSample p × (Fin p → R) => ‖z.1.1‖) ν := + measurePreserving_fst.integrable_comp_of_integrable hM.interaction_integrable + have hs := integrable_rootArray_sum ν (fun z => ‖z.1.1‖) hi l + have hB (z : RootPath (InteractionSample p × (Fin p → R)) l) : + |activeDatumRoot T U V x m j f l z|≤B+∑ i,‖(rootArray l z i).1.1‖ := by + apply backwardLog_bound n _ m hm + intro y + simpa only [rootArray_rootMap] using activeEnergy_bound V x j l + (rootMap Prod.snd l z) (rootMap Prod.fst l z) f hf y + have hF : Integrable (activeDatumRoot T U V x m j f l) (rootLaw l (fun _ => ν)) := + ((integrable_const B).add hs).mono' + (measurable_activeDatumRoot T U V x m j f l).aestronglyMeasurable (ae_of_all _ hB) + unfold activeCountMean + apply abs_integral_le_integral_abs.trans + apply (integral_mono hF.abs ((integrable_const B).add hs) hB).trans_eq + simp only [Pi.add_apply] + rw [integral_add (integrable_const B) hs,integral_rootArray_sum ν _ hi l] + have he : (∫ a : InteractionSample p × (Fin p → R),‖a.1.1‖ ∂ν)= + ∫ a : InteractionSample p,‖a.1‖ ∂M.disorder.toMeasure := by + simpa only [ν,probReal_univ,one_smul] using + (integral_fun_fst (μ := M.disorder.toMeasure) + (ν := ((FiniteLaw.pi (fun _ : Fin p => Q)).asProbability id).toMeasure) + (fun a : InteractionSample p => ‖a.1‖)) + rw [he] + simp only [integral_const,probReal_univ,one_smul,mul_comm] + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma upperSelectedCountMean_bound (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (T : KernelTower Ω n) (U : R → KernelTower Λ n) + (V : FinitePath Ω n → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) (s : Fin N) + (f : FinitePath Ω n → ℝ) (l : ℕ) : + |∫ c,activeCountMean M Q T U V x m j f + (selectedCount l (rootMap (fun a => decide (a=s)) l c)) + ∂rootLaw l (fun _ => finiteUniform (Fin N))|≤ + ‖f‖+(∫ a,‖a.1‖ ∂M.disorder.toMeasure)*l := by + apply abs_integral_le_bound_ae + apply ae_of_all + intro c + apply (FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.activeCountMean_bound M hM Q T U V x m hm j f _ (fun y => norm_le_pi_norm f y)).trans + apply add_le_add le_rfl + apply mul_le_mul_of_nonneg_left _ (integral_nonneg (fun a => norm_nonneg a.1)) + rw [selectedCount_eq_successCountAt] + exact_mod_cast successCountAt_le s (rootArray l c) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma upperPoisson_cavity_separable (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (T : Fin N → KernelTower Ω n) (U : R → KernelTower Λ n) + (V : Fin N → FinitePath Ω n → Spin) (x : R → FinitePath Λ n → ℝ) + (m : Fin n → ℝ) (hm : ∀ d,0 < m d) (j : Fin p) + (f : Fin N → FinitePath Ω n → ℝ) (r : ℝ≥0) : + (∫ l,upperCountMean M (KernelTower.pi n T) Q U (fun y s => V s (FinitePath.proj n y s)) x m j + (fun y => ∑ s,f s (FinitePath.proj n y s)) 0 l ∂poissonMeasure r)= + ∑ s : Fin N,∫ k,activeCountMean M Q (T s) U (V s) x m j (f s) k + ∂poissonMeasure (r/N) := by + simp_rw [FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperCountMean_separable M hM Q T U V x m hm j f] + rw [integral_finsetSum] + · apply Finset.sum_congr rfl + intro s _ + exact integral_poisson_rootSelection r N s _ (integral_nonneg (fun a : InteractionSample p => norm_nonneg a.1)) + (fun l => FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.activeCountMean_bound M hM Q (T s) U (V s) x m hm j (f s) l + (fun y => norm_le_pi_norm (f s) y)) + · intro s _ + apply ((integrable_const ‖f s‖).add ((poisson_integrable_count r).const_mul + (∫ a,‖a.1‖ ∂M.disorder.toMeasure))).mono' (measurable_of_countable _).aestronglyMeasurable + exact ae_of_all _ (fun l => FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperSelectedCountMean_bound M hM Q (T s) U (V s) x m hm j s (f s) l) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSingletonClass R] in +lemma upperCountMean_real_firstMoment (M : Model p) (hM : InterpolationAdmissible M) (T : KernelTower Ω n) (Q : FiniteLaw R) + (U : R → KernelTower Λ n) (V : FinitePath Ω n → Fin N → Spin) + (x : R → FinitePath Λ n → ℝ) (m : Fin n → ℝ) (hm : ∀ d,0 < m d) + (j : Fin p) (f : FinitePath Ω n → ℝ) (k : ℕ) : + upperCountMean M T Q U V x m j f k 0 = + ∫ z : Fin k → InteractionSample p, + (FiniteLaw.uniform : FiniteLaw (Fin k → Fin p → Fin N)).expect + (fun i => backwardLog n T m (fun y => f y+∑ a,(z a).1 (fun b => V y (i a b)))) + ∂Measure.pi (fun _ : Fin k => M.disorder.toMeasure) := by + let F : RootPath (InteractionSample p × (Fin p → Fin N)) k → ℝ := fun z => + backwardLog n T m (fun y => f y+∑ a,(rootArray k z a).1.1 (fun b => V y ((rootArray k z a).2 b))) + have hFm : Measurable F := by + apply measurable_backwardLog + intro y + apply measurable_const.add + apply Finset.measurable_sum + intro a _ + exact (measurable_pi_apply (V y)).comp ((PhysicalRoot.measurable_indexedPotential (fun x : InteractionSample p => x) + (fun σ => (measurable_pi_apply σ).comp measurable_fst)).comp (measurable_rootArray k a)) + have he : upperCountMean M T Q U V x m j f k 0 = + ∫ z,F (rootMap (fun a : UpperDatum p N R => (a.1,a.2.1)) k z) + ∂rootLaw k (fun _ => upperDatumLaw M Q) := by + let : IsProbabilityMeasure (rootLaw 0 (fun _ : Fin 0 => upperDatumLaw (N := N) M Q)) := Measure.dirac.isProbabilityMeasure + unfold upperCountMean + apply integral_congr_ae + filter_upwards [] with z + simp only [datumRoot,cavityRoot,cavityTower,cavityEnergy,realCountEnergy, + rootArray_rootMap,F] + simp only [integral_const,Measure.real,measure_univ,ENNReal.toReal_one,one_smul] + rfl + rw [he,integral_rootMap (upperDatum_real_projection M Q) k F hFm] + apply integral_root_prod_finite_integrable M.disorder.toMeasure k + (fun z : (Fin k → InteractionSample p) × (Fin k → Fin p → Fin N) => backwardLog n T m (fun y => f y+∑ a,(z.1 a).1 (fun b => V y (z.2 a b)))) + · apply measurable_from_prod_countable_left + intro i + apply measurable_backwardLog + intro y + change Measurable (fun z : Fin k → InteractionSample p => f y+∑ a,(z a).1 (fun b => V y (i a b))) + exact measurable_const.add (Finset.measurable_sum _ (fun a _ => + (measurable_pi_apply _).comp (measurable_fst.comp (measurable_pi_apply a)))) + · apply ((integrable_const ‖f‖).add ((integrable_finsetSum Finset.univ + (fun (a : Fin k) _ => integrable_comp_eval (μ := fun _ : Fin k => M.disorder.toMeasure) (i := a) + hM.interaction_integrable)).comp_fst (Measure.pi (fun _ : Fin k => finiteUniform (Fin p → Fin N))))).mono' + · apply Measurable.aestronglyMeasurable + apply measurable_from_prod_countable_left + intro i + apply measurable_backwardLog + intro y + change Measurable (fun z : Fin k → InteractionSample p => f y+∑ a,(z a).1 (fun b => V y (i a b))) + exact measurable_const.add (Finset.measurable_sum _ (fun a _ => + (measurable_pi_apply _).comp (measurable_fst.comp (measurable_pi_apply a)))) + · exact ae_of_all _ (fun z => backwardLog_bound n T m hm (fun y => + (abs_add_le _ _).trans (add_le_add (norm_le_pi_norm f y) + ((Finset.abs_sum_le_sum_abs _ _).trans + (Finset.sum_le_sum (fun a _ => norm_le_pi_norm (z.1 a).1 _)))))) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +omit [MeasurableSingletonClass R] in +lemma upperCountMean_real_terminal (M : Model p) (hM : InterpolationAdmissible M) (Q : FiniteLaw R) + (r : ℕ) (U : R → KernelTower Λ (r+1)) (x : R → FinitePath Λ (r+1) → ℝ) + (m : Fin (r+1) → ℝ) (hm : ∀ d,0 < m d) (hend : m (Fin.last r)=1) + (j : Fin p) (h : Fin N → ℝ) (k : ℕ) : + upperCountMean M (KernelTower.pi (r+1) (fun _ : Fin N => + terminalTower false (FiniteLaw.uniform : FiniteLaw Spin) r)) Q U + (fun y s => terminalState r (FinitePath.proj (r+1) y s)) x m j + (fun y => ∑ s,h s*spin (terminalState r (FinitePath.proj (r+1) y s))) k 0= + ∫ z : Fin k → InteractionSample p, + (FiniteLaw.uniform : FiniteLaw (Fin k → Fin p → Fin N)).expect + (fun i => logPartition z h i-(N:ℝ)*Real.log 2) + ∂Measure.pi (fun _ : Fin k => M.disorder.toMeasure) := by + rw [FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperCountMean_real_firstMoment M hM] + · apply integral_congr_ae + filter_upwards [] with z + apply FiniteLaw.expect_congr + intro i + rw [backwardLog_pi_terminal (fun _ : Fin N => false) + (fun _ => (FiniteLaw.uniform : FiniteLaw Spin)) r m (fun d => (hm d).ne') + (fun σ => (∑ s,h s*spin (σ s))+∑ a,(z a).1 (fun b => σ (i a b))),hend,FiniteLaw.pi_uniform, + FiniteLaw.logMean_uniform] + unfold logPartition + congr 1 + · congr 1 + apply Finset.sum_congr rfl + intro σ _ + congr 1 + unfold logWeight + ring + · simp [Real.log_pow] + · exact hm + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma activeCountMean_site (q : ℕ) (M : Model (q+1)) (hM : InterpolationAdmissible M) + (a : Λ) (r : ℕ) (Q : FiniteLaw R) (U : R → KernelTower Λ r) + (x : R → FinitePath Λ r → ℝ) (m : Fin (r+1) → ℝ) + (hm : ∀ d,0 < m d) (hend : m (Fin.last r)=1) (k : ℕ) (h : ℝ) : + activeCountMean M Q (terminalTower false (FiniteLaw.uniform : FiniteLaw Spin) r) + (fun b => pad a r (U b)) (terminalState r) + (fun b y => x b (pathPrefix r y)) m (Fin.last q) + (fun y => h*spin (terminalState r y)) k= + ∫ z : Fin k → InteractionSample (q+1), + trialLog r (finiteTrialLaw r Q U x) (fun d => m d.castSucc) (siteLog z h) + ∂Measure.pi (fun _ : Fin k => M.disorder.toMeasure) := by + let F := fun z : RootPath (InteractionSample (q+1)) k × RootPath (Fin (q+1) → R) k => + backwardLog (r+1) + (cavityTower (terminalTower false (FiniteLaw.uniform : FiniteLaw Spin) r) + (fun b => pad a r (U b)) k z.2) m + (activeEnergy (terminalState r) (fun b y => x b (pathPrefix r y)) (Fin.last q) k z.2 z.1 + (fun y => h*spin (terminalState r y))) + have hFm : Measurable F := by + apply measurable_from_prod_countable_left + intro b + dsimp only [F] + exact measurable_backwardLog (r+1) _ m (measurable_activeEnergy (terminalState r) + (fun b y => x b (pathPrefix r y)) (Fin.last q) k b id measurable_id + (fun y => h*spin (terminalState r y))) + have hB (z : RootPath (InteractionSample (q+1)) k × RootPath (Fin (q+1) → R) k) : + |F z|≤|h|+∑ i,‖(rootArray k z.1 i).1‖ := by + apply backwardLog_bound _ _ _ hm + intro y + apply activeEnergy_bound _ _ _ _ _ _ _ _ y + intro y + simp only [abs_mul,abs_spin,mul_one] + exact le_refl _ + have hi : Integrable F ((rootLaw k (fun _ => M.disorder.toMeasure)).prod + (rootLaw k (fun _ => ((FiniteLaw.pi (fun _ : Fin (q+1) => Q)).asProbability id).toMeasure))) := by + exact ((integrable_const |h|).add ((integrable_rootArray_sum M.disorder.toMeasure + (fun a => ‖a.1‖) hM.interaction_integrable k).comp_fst _)).mono' + hFm.aestronglyMeasurable (ae_of_all _ hB) + unfold activeCountMean activeDatumRoot + change (∫ z,F (rootMap Prod.fst k z,rootMap Prod.snd k z) ∂rootLaw k (fun _ => _))=_ + rw [integral_rootSplit _ _ k F hFm hi] + have he (z : RootPath (InteractionSample (q+1)) k) : + (∫ b,F (z,b) ∂rootLaw k (fun _ => ((FiniteLaw.pi (fun _ : Fin (q+1) => Q)).asProbability id).toMeasure))= + trialLog r (finiteTrialLaw r Q U x) (fun d => m d.castSucc) (siteLog (rootArray k z) h) := + activeRoot_site_mean a r Q U x m hend q k z h + simp only [he] + exact integral_rootArray_eq_pi M.disorder.toMeasure k + (fun z : Fin k → InteractionSample (q+1) => + trialLog r (finiteTrialLaw r Q U x) (fun d => m d.castSucc) (siteLog z h)) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma finiteTrial_upper_fixedField (M : Model (q+1)) (hM : InterpolationAdmissible M) + (a : Λ) (r : ℕ) (Q : FiniteLaw R) (U : R → KernelTower Λ r) + (x : R → FinitePath Λ r → ℝ) (m : Fin r → ℝ) (hm : Exponents m) (h : Fin N → ℝ) : + (∫ k,∫ z : Fin k → InteractionSample (q+1), + (FiniteLaw.uniform : FiniteLaw (Fin k → Fin (q+1) → Fin N)).expect + (fun i => logPartition z h i-(N:ℝ)*Real.log 2) + ∂Measure.pi (fun _ : Fin k => M.disorder.toMeasure) ∂poissonMeasure (M.alpha*N))+ + (M.alpha:ℝ)*N*q*(∫ z,trialLog r (finiteTrialLaw r Q U x) m + (fun y => Real.log (edge z.1 y)) ∂M.disorder.toMeasure) ≤ + ∑ s : Fin N,∫ k,∫ z : Fin k → InteractionSample (q+1), + trialLog r (finiteTrialLaw r Q U x) m (siteLog z (h s)) + ∂Measure.pi (fun _ : Fin k => M.disorder.toMeasure) ∂poissonMeasure (M.alpha*(q+1)) := by + let m' : Fin (r+1) → ℝ := Fin.snoc m 1 + let m₀ : Fin (r+2) → ℝ := Fin.cons 0 m' + have hpos : ∀ d,0 < m' d := snoc_exponents_pos hm + have hend : m' (Fin.last r)=1 := Fin.snoc_last _ _ + have hend₀ : m₀ (Fin.last (r+1))=1 := by + change Fin.cons (α := fun _ => ℝ) 0 m' (Fin.last r).succ=1 + simpa only [Fin.cons_succ] using hend + let T : Fin N → KernelTower Spin (r+1) := fun _ => terminalTower false FiniteLaw.uniform r + let V : Fin N → FinitePath Spin (r+1) → Spin := fun _ => terminalState r + let f : Fin N → FinitePath Spin (r+1) → ℝ := fun s y => h s*spin (terminalState r y) + let Up : R → KernelTower Λ (r+1) := fun b => pad a r (U b) + let xp : R → FinitePath Λ (r+1) → ℝ := fun b y => x b (pathPrefix r y) + have hx := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperPoissonCount_bound_firstMoment M hM (KernelTower.pi (r+1) T) Q Up + (fun y s => V s (FinitePath.proj (r+1) y s)) xp m₀ + (cons_snoc_exponents_mono hm) (cons_snoc_exponents_nonneg hm) + (fun d => hpos d) rfl hend₀ (Fin.last q) + (fun y => ∑ s,f s (FinitePath.proj (r+1) y s)) (M.alpha*(q+1)*N) + have hr : (M.alpha*(q+1)*N:ℝ≥0)/(q+1)=M.alpha*N := by + have hp : (q+1:ℝ≥0)≠0 := by positivity + field_simp + have hs : (M.alpha*(q+1)*N:ℝ≥0)/N=M.alpha*(q+1) := by + have hN : (N:ℝ≥0)≠0 := by exact_mod_cast NeZero.ne N + exact mul_div_cancel_right₀ _ hN + simp only [m₀,Fin.cons_succ,Nat.cast_add,Nat.cast_one] at hx + change (∫ k,upperCountMean M (KernelTower.pi (r+1) T) Q Up + (fun y s => V s (FinitePath.proj (r+1) y s)) xp m' (Fin.last q) + (fun y => ∑ s,f s (FinitePath.proj (r+1) y s)) k 0 ∂poissonMeasure ((M.alpha*(q+1)*N)/(q+1)))+ + ((M.alpha*(q+1)*N:ℝ≥0):ℝ)*(((q+1-1:ℕ):ℝ)/(q+1))* + (∫ z,edgeRoot Q Up xp m' z ∂M.disorder.toMeasure) ≤ _ at hx + rw [hr,FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperPoisson_cavity_separable M hM Q T Up V xp m' hpos (Fin.last q) f,hs] at hx + dsimp only [T,V,f,Up,xp] at hx + simp_rw [FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.upperCountMean_real_terminal M hM Q r _ _ m' hpos hend, + FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.activeCountMean_site q M hM a r Q U x m' hpos hend, + edgeRoot_pad r a Q U x m' (by rw [hend]; norm_num)] at hx + have he : (fun d : Fin r => m' d.castSucc)=m := by funext d; exact Fin.snoc_castSucc _ _ d + rw [he] at hx + have hc : ((M.alpha*(q+1)*N:ℝ≥0):ℝ)*(((q+1-1:ℕ):ℝ)/(q+1))=(M.alpha:ℝ)*N*q := by + simp only [Nat.add_sub_cancel,NNReal.coe_mul,NNReal.coe_add,NNReal.coe_natCast,NNReal.coe_one] + have hp : (q:ℝ)+1≠0 := by positivity + field_simp + rwa [hc] at hx + +end +end FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree + +namespace FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma finiteTrial_pressure_le (M : Model (q+1)) (hM : InterpolationAdmissible M) + (a : Λ) (r : ℕ) (Q : FiniteLaw R) (U : R → KernelTower Λ r) + (x : R → FinitePath Λ r → ℝ) (m : Fin r → ℝ) (hm : Exponents m) : + pressure M N ≤ functional M r (finiteTrialLaw r Q U x) m := by + let ζ := finiteTrialLaw r Q U x + let μ := Measure.pi (fun _ : Fin N => M.field.toMeasure) + let S : ℝ → ℝ := fun h => ∫ k,trialDisorderAt M m ζ k h ∂poissonMeasure (M.alpha*(q+1)) + let E := ∫ z,trialLog r ζ m (fun y => Real.log (edge z.1 y)) ∂M.disorder.toMeasure + have hp : ∀ d,0 < m d := fun d => (hm.2 d).1 + have hS : Integrable S M.field.toMeasure := + (trialDisorderAt_joint_integrable M m hp ζ hM.interaction_integrable hM.field_integrable _).integral_prod_right + have hF := (centeredDisorderAt_joint_integrable (N := N) M hM.interaction_integrable + hM.field_integrable (M.alpha*N)).integral_prod_right + have hiS (s : Fin N) : Integrable (fun h : Fin N → ℝ => S (h s)) μ := + integrable_comp_eval (μ := fun _ : Fin N => M.field.toMeasure) (i := s) hS + have hb (h : Fin N → ℝ) : + (∫ k,centeredDisorderAt M k h ∂poissonMeasure (M.alpha*N))+(M.alpha:ℝ)*N*q*E ≤ ∑ s,S (h s) := by + have he := FixedClauseThreshold.Computability.PositiveInterpolation.PrescribedTree.finiteTrial_upper_fixedField M hM a r Q U x m hm h + simpa only [FiniteLaw.expect_sub,FiniteLaw.expect_const,FiniteLaw.expect_uniform, + centeredDisorderAt,indexAverage,trialDisorderAt,S,E,ζ] using he + have hi := integral_mono (hF.add (integrable_const ((M.alpha:ℝ)*N*q*E))) + (integrable_finsetSum Finset.univ (fun s _ => hiS s)) hb + simp only [Pi.add_apply] at hi + rw [integral_add hF (integrable_const _),integral_const,probReal_univ,one_smul, + centeredPressure_field_order M hM.interaction_integrable hM.field_integrable, + integral_finsetSum _ (fun s _ => hiS s)] at hi + dsimp only [μ] at hi + simp only [integral_comp_eval (μ := fun _ : Fin N => M.field.toMeasure) hS.aestronglyMeasurable, + Finset.sum_const,Finset.card_univ,Fintype.card_fin,nsmul_eq_mul] at hi + dsimp only [S] at hi + rw [trialPoisson_field_order M m hp ζ hM.interaction_integrable hM.field_integrable] at hi + have hN : (0:ℝ) V (b,y)) m hm + have he : finiteTrialLaw r T.1 T.2 (fun b y => V (b,y))=ζ := hT + rwa [he] at h + +end +end FixedClauseThreshold.Computability.PositiveInterpolation + +namespace FixedClauseThreshold.Computability.PositiveInterpolation +section +variable {Ω Λ R : Type} [Fintype Ω] [Fintype Λ] [Fintype R] + [MeasurableSpace R] [MeasurableSingletonClass R] + {n p N q : ℕ} [NeZero N] + +lemma pressure_le_functional (M : Model (q+1)) (hM : InterpolationAdmissible M) + (r : ℕ) (ζ : Hierarchy (r+1)) (m : Fin r → ℝ) (hm : Exponents m) : + pressure M N ≤ functional M r ζ m := by + have hc : IsClosed {ζ : Hierarchy (r+1) | pressure M N ≤ functional M r ζ m} := + isClosed_le continuous_const (functional_continuous M m (fun d => (hm.2 d).1) + hM.interaction_integrable hM.field_integrable) + have hs : {ζ : Hierarchy (r+1) | FiniteHierarchy (r+1) ζ} ⊆ + {ζ : Hierarchy (r+1) | pressure M N ≤ functional M r ζ m} := by + intro η hη + exact FixedClauseThreshold.Computability.PositiveInterpolation.finiteHierarchy_pressure_le M hM r η hη m hm + exact closure_minimal hs hc ((finiteHierarchy_dense (r+1)) ζ) + +end +end FixedClauseThreshold.Computability.PositiveInterpolation + +end + +end OAI diff --git a/lean/OAI/Probability/SATComputability/LowerBounds.lean b/lean/OAI/Probability/SATComputability/LowerBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..57436074cc68fb3b2b2d819402d43a39c643899a --- /dev/null +++ b/lean/OAI/Probability/SATComputability/LowerBounds.lean @@ -0,0 +1,144 @@ +import OAI.Probability.RandomSAT.Main + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Filter +open scoped Topology + +instance decidableClauseSatisfaction {n k : ℕ} (σ : Assignment n) + (C : ProperClause n k) : Decidable (SatisfiesClause σ C) := by + unfold SatisfiesClause + infer_instance + +instance decidableFormulaSatisfaction {n k m : ℕ} (σ : Assignment n) + (F : Formula n k m) : Decidable (Satisfies σ F) := by + unfold Satisfies + infer_instance + +instance decidableSatisfiability {n k m : ℕ} (F : Formula n k m) : + Decidable (Satisfiable F) := by + unfold Satisfiable + infer_instance + +def rationalProbability (n k m : ℕ) : ℚ := + (Fintype.card {F : Formula n k m // Satisfiable F} : ℚ) / + (Fintype.card (Formula n k m) : ℚ) + +theorem rationalProbability_cast (n k m : ℕ) : + (rationalProbability n k m : ℝ) = properSATProbability n k m := by + simp only [rationalProbability, properSATProbability, Rat.cast_div, Rat.cast_natCast, + ← Nat.card_eq_fintype_card] + +def rationalCenter (n k : ℕ) : ℚ := + (∑ j ∈ Finset.range (mainCap n k), rationalProbability n k (j + 1)) / n + +theorem rationalCenter_cast {n k : ℕ} (hkn : k ≤ n) : + (rationalCenter n k : ℝ) = center n k := by + simp only [rationalCenter, Rat.cast_div, Rat.cast_sum, Rat.cast_natCast, + rationalProbability_cast, center, lifetimeMean_eq_sum hkn] + congr 1 + apply Finset.sum_congr rfl + intro j _ + exact properSATProbability_eq_survival n k (j + 1) + +theorem center_lower_certificate (k : ℕ) (hk : 3 ≤ k) : + ∃ N : ℕ, ∀ s ≥ N, 0 < s → + center s k - 4 * (1 + balanceConstant (delta k)) * (s : ℝ)^(-delta k) ≤ + limitingCenter k := by + obtain ⟨N, hadd, hnext⟩ := center_comparisons k hk + refine ⟨N, ?_⟩ + intro s hs hpos + apply ge_of_tendsto (center_tendsto k hk) + filter_upwards [eventually_ge_atTop (s * s)] with n hn + apply balanced_tail_bound (fun n => center n k) (by norm_num : (0 : ℝ) ≤ 4) + (delta_pos hk) hs hpos ?_ ?_ n hn + · intro r hr t ht + simpa only [densityWindow, Nat.cast_min] using hadd r hr t ht + · simpa only [densityWindow] using hnext s hs + +theorem rational_lower_certificates : + ∃ C N : ℕ, 0 < C ∧ 3 ≤ N ∧ + ∀ s : ℕ, + ((rationalCenter ((N + s + 1)^12) 3 - (C : ℚ) / (s + 1) : ℚ) : ℝ) ≤ + limitingCenter 3 := by + obtain ⟨N, hN⟩ := center_lower_certificate 3 (by omega) + obtain ⟨C, hC⟩ := exists_nat_gt (4 * (1 + balanceConstant (delta 3))) + have hB : 0 < balanceConstant (delta 3) := balanceConstant_pos (delta_pos (by omega)) + refine ⟨C, max N 3, ?_, le_max_right _ _, ?_⟩ + · have : (0 : ℝ) < C := by linarith + exact_mod_cast this + · intro s + let b := max N 3 + s + 1 + have hb : 0 < b := by dsimp [b]; omega + have hbN : N ≤ b^12 := by + have hle : b ≤ b^12 := Nat.le_pow (by omega) + dsimp [b] at * + omega + have hb3 : 3 ≤ b^12 := by + have hle : b ≤ b^12 := Nat.le_pow (by omega) + dsimp [b] at * + omega + have hbR : (0 : ℝ) < b := by exact_mod_cast hb + have hp : ((b^12 : ℕ) : ℝ)^(-delta 3) = (b : ℝ)⁻¹ := by + rw [Nat.cast_pow, ← Real.rpow_natCast_mul hbR.le] + norm_num [delta, Real.rpow_neg_one] + have hbound := hN (b^12) hbN (pow_pos hb _) + rw [hp] at hbound + have hi : (b : ℝ)⁻¹ ≤ ((s : ℝ) + 1)⁻¹ := by + apply inv_anti₀ (by positivity) + dsimp [b] + push_cast + linarith [(Nat.cast_nonneg N : (0 : ℝ) ≤ N), le_max_left (N : ℝ) 3] + have hcost : 4 * (1 + balanceConstant (delta 3)) * (b : ℝ)⁻¹ ≤ + (C : ℝ) / (s + 1) := by + calc + _ ≤ (C : ℝ) * (b : ℝ)⁻¹ := mul_le_mul_of_nonneg_right hC.le (inv_nonneg.mpr hbR.le) + _ ≤ (C : ℝ) * ((s : ℝ) + 1)⁻¹ := + mul_le_mul_of_nonneg_left hi (Nat.cast_nonneg _) + _ = _ := by rw [div_eq_mul_inv] + change ((rationalCenter (b^12) 3 - (C : ℚ) / (s + 1) : ℚ) : ℝ) ≤ _ + rw [Rat.cast_sub, rationalCenter_cast hb3] + push_cast + linarith + +theorem rational_lower_certificates_tendsto (C N : ℕ) : + Tendsto (fun s : ℕ => + ((rationalCenter ((N + s + 1)^12) 3 - (C : ℚ) / (s + 1) : ℚ) : ℝ)) + atTop (nhds (limitingCenter 3)) := by + have hsize : Tendsto (fun s : ℕ => (N + s + 1)^12) atTop atTop := by + apply tendsto_atTop_mono _ tendsto_id + intro s + have hle : N + s + 1 ≤ (N + s + 1)^12 := Nat.le_pow (by omega) + change s ≤ (N + s + 1)^12 + omega + have hcenter := (center_tendsto 3 (by omega)).comp hsize + have hreal : Tendsto (fun s : ℕ => (s : ℝ) + 1) atTop atTop := + tendsto_atTop_add_const_right atTop 1 tendsto_natCast_atTop_atTop + have hcorrection : Tendsto (fun s : ℕ => (C : ℝ) / ((s : ℝ) + 1)) + atTop (nhds 0) := by + simpa only [div_eq_mul_inv, mul_zero, Function.comp_apply] using + (tendsto_inv_atTop_zero.comp hreal).const_mul (C : ℝ) + apply (show Tendsto (fun s : ℕ => + center ((N + s + 1)^12) 3 - (C : ℝ) / ((s : ℝ) + 1)) + atTop (nhds (limitingCenter 3)) from + by simpa only [sub_zero, Function.comp_apply] using hcenter.sub hcorrection).congr' + filter_upwards [hsize.eventually (eventually_ge_atTop 3)] with s hs + simp only [Rat.cast_sub, rationalCenter_cast hs, Rat.cast_div, + Rat.cast_natCast, Rat.cast_add, Rat.cast_one] + +theorem exists_rational_lower_certificates : + ∃ C N : ℕ, 0 < C ∧ 3 ≤ N ∧ + (∀ s : ℕ, + ((rationalCenter ((N + s + 1)^12) 3 - (C : ℚ) / (s + 1) : ℚ) : ℝ) ≤ + limitingCenter 3) ∧ + Tendsto (fun s : ℕ => + ((rationalCenter ((N + s + 1)^12) 3 - (C : ℚ) / (s + 1) : ℚ) : ℝ)) + atTop (nhds (limitingCenter 3)) := by + obtain ⟨C, N, hC, hN, hbound⟩ := rational_lower_certificates + exact ⟨C, N, hC, hN, hbound, rational_lower_certificates_tendsto C N⟩ + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/LowerProgram.lean b/lean/OAI/Probability/SATComputability/LowerProgram.lean new file mode 100644 index 0000000000000000000000000000000000000000..1475e7d0745e85951cae5e8f050dcd0051f739e7 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/LowerProgram.lean @@ -0,0 +1,55 @@ +import OAI.Probability.SATComputability.FiniteEnumeration +import OAI.Probability.SATComputability.UpperCertificates + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Filter RapidForcing.EffectiveArithmetic +open scoped Topology + +def lowerProgram (C N s : ℕ) : ℚ := + rationalCenter ((N + s + 1)^12) 3 - (C : ℚ) / (s + 1) + +attribute [local irreducible] rationalCenter + +private theorem sampleCenter_computable (N : ℕ) : + Computable (fun s : ℕ => rationalCenter ((N + s + 1)^12) 3) := by + have hi : Computable (fun s : ℕ => (((N + s + 1)^12), (3 : ℕ))) := by fun_prop + exact Computable.comp (f := fun p : ℕ × ℕ => rationalCenter p.1 p.2) + (g := fun s : ℕ => (((N + s + 1)^12), (3 : ℕ))) rationalCenter_computable hi + +private theorem correction_computable (C : ℕ) : + Computable (fun s : ℕ => (C : ℚ) / (s + 1)) := by + have hi : Computable (fun s : ℕ => ((C : ℤ), s + 1)) := by fun_prop + have h := Computable.comp (f := fun p : ℤ × ℕ => (p.1 : ℚ) / p.2) + (g := fun s : ℕ => ((C : ℤ), s + 1)) computable_rat_divNat hi + exact h.of_eq (fun s => by simp) + +@[fun_prop] theorem lowerProgram_computable (C N : ℕ) : + Computable (lowerProgram C N) := + computable_rat_sub.comp ((sampleCenter_computable N).pair (correction_computable C)) + +theorem exists_lowerProgram : + ∃ lower : ℕ → ℚ, Computable lower ∧ + (∀ i, (lower i : ℝ) ≤ limitingCenter 3) ∧ + (∀ ε : ℝ, 0 < ε → ∃ i, limitingCenter 3 - ε < (lower i : ℝ)) := by + obtain ⟨C, N, _, _, hbound, hlim⟩ := exists_rational_lower_certificates + refine ⟨lowerProgram C N, lowerProgram_computable C N, hbound, ?_⟩ + intro ε hε + exact (hlim.eventually (Ioi_mem_nhds (sub_lt_self _ hε))).exists + +theorem threshold_program_of_trial_separation {T : TrialEvaluation} + (hT : TrialSeparation T (limitingCenter 3)) : + ∃ (q : ℕ → ℚ) (c : Nat.Partrec.Code), + Computable q ∧ + (∀ r, c.eval r = Part.some (Encodable.encode (q r))) ∧ + (∀ r, |(q r : ℝ) - limitingCenter 3| ≤ (2 ^ r : ℝ)⁻¹) := by + obtain ⟨lower, hl, hs, hd⟩ := exists_lowerProgram + obtain ⟨q, hq, he⟩ := computable_of_trial_separation hT hl hs hd + obtain ⟨c, hc⟩ := rational_sequence_code hq + exact ⟨q, c, hq, hc, he⟩ + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/Main.lean b/lean/OAI/Probability/SATComputability/Main.lean new file mode 100644 index 0000000000000000000000000000000000000000..12611645c42456aa9bddacc38b9cd017ff95e3d6 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/Main.lean @@ -0,0 +1,51 @@ +import OAI.Probability.SATComputability.SupercriticalEnergy +import OAI.Probability.SATComputability.PressureUpper +import OAI.Probability.SATComputability.TrialCompleteness +import OAI.Probability.SATComputability.LowerProgram + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Filter +open scoped Topology NNReal + +theorem satTrialSeparation : TrialSeparation satTrialEvaluation (limitingCenter 3) := by + constructor + · exact fun _ hj hn => satTrialEvaluation_sound hj hn + · intro a ha + have haR : (0 : ℝ) < a := (limitingCenter_pos 3 (by decide)).trans ha + have haQ : 0 < a := by exact_mod_cast haR + let aNN : ℝ≥0 := ⟨a,haR.le⟩ + have haNN : 0 < aNN := haR + obtain ⟨ε,hε,hV⟩ := relaxedPoissonMinimum_supercritical (a := aNN) ha + obtain ⟨b,hb,hnegative⟩ := negative_pressure_of_violation_density haNN hε hV + exact satTrialEvaluation_negative_witness a haQ b hb hnegative + +theorem threshold_program : + ∃ (q : ℕ → ℚ) (c : Nat.Partrec.Code), + Computable q ∧ + (∀ r, c.eval r = Part.some (Encodable.encode (q r))) ∧ + (∀ r, |(q r : ℝ)-limitingCenter 3| ≤ (2^r : ℝ)⁻¹) := + threshold_program_of_trial_separation satTrialSeparation + +def MainStatement : Prop := + ∃ (α : ℝ) (q : ℕ → ℚ) (c : Nat.Partrec.Code), + 0 < α ∧ + (∀ a : ℝ, 0 ≤ a → a < α → + Tendsto (fun n : ℕ => properSATProbability n 3 ⌊a*(n : ℝ)⌋₊) atTop (nhds 1)) ∧ + (∀ a : ℝ, α < a → + Tendsto (fun n : ℕ => properSATProbability n 3 ⌊a*(n : ℝ)⌋₊) atTop (nhds 0)) ∧ + Computable (fun r => Encodable.encode (q r)) ∧ + (∀ r, c.eval r = Part.some (Encodable.encode (q r))) ∧ + (∀ r, |(q r : ℝ)-α| ≤ (2^r : ℝ)⁻¹) + +theorem main : MainStatement := by + obtain ⟨q,c,hq,hc,he⟩ := threshold_program + exact ⟨limitingCenter 3,q,c,limitingCenter_pos 3 (by decide), + subcritical_limit 3 (by decide),supercritical_limit 3 (by decide), + Computable.encode_iff.mpr hq,hc,he⟩ + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/MarkovOccupation.lean b/lean/OAI/Probability/SATComputability/MarkovOccupation.lean new file mode 100644 index 0000000000000000000000000000000000000000..2e9ae222ab3acf3a9c47cfdf2077cd06d8e1b006 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/MarkovOccupation.lean @@ -0,0 +1,98 @@ +import OAI.Probability.DilutedSpin.FiniteLaw + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped BigOperators + +noncomputable def finiteKernelStep {Ω : Type*} [Fintype Ω] + (K : Ω → FiniteLaw Ω) (f : Ω → ℝ) (x : Ω) : ℝ := (K x).expect f + +theorem finiteKernelStep_mono {Ω : Type*} [Fintype Ω] (K : Ω → FiniteLaw Ω) : + Monotone (finiteKernelStep K) := by + intro f g h x + exact (K x).expect_mono h + +theorem finiteKernelStep_iterate_const {Ω : Type*} [Fintype Ω] + (K : Ω → FiniteLaw Ω) (t : ℕ) (c : ℝ) : + (finiteKernelStep K)^[t] (fun _ => c) = fun _ => c := by + induction t with + | zero => rfl + | succ t ih => + rw [Function.iterate_succ_apply', ih] + funext x + exact (K x).expect_const c + +theorem finiteKernelStep_iterate_sub {Ω : Type*} [Fintype Ω] + (K : Ω → FiniteLaw Ω) (t : ℕ) (f g : Ω → ℝ) : + (finiteKernelStep K)^[t] (f-g) = + (finiteKernelStep K)^[t] f - (finiteKernelStep K)^[t] g := by + induction t with + | zero => rfl + | succ t ih => + simp only [Function.iterate_succ_apply', ih] + funext x + exact (K x).expect_sub _ _ + +theorem finiteKernelStep_iterate_mul {Ω : Type*} [Fintype Ω] + (K : Ω → FiniteLaw Ω) (t : ℕ) (c : ℝ) (f : Ω → ℝ) : + (finiteKernelStep K)^[t] (fun x => c*f x) = + fun x => c*((finiteKernelStep K)^[t] f x) := by + induction t with + | zero => rfl + | succ t ih => + simp only [Function.iterate_succ_apply', ih] + funext x + exact (K x).expect_mul_left c _ + +theorem sum_shift_difference_le (u : ℕ → ℝ) (hu0 : ∀ t, 0 ≤ u t) + (hu1 : ∀ t, u t ≤ 1) (M L : ℕ) : + (∑ t ∈ Finset.range M, (u t-u (t+L))) ≤ L := by + have hM := Finset.sum_range_add u M L + have hL := Finset.sum_range_add u L M + rw [Nat.add_comm L M] at hL + have hnonneg : 0 ≤ ∑ t ∈ Finset.range L, u (M+t) := + Finset.sum_nonneg (fun t _ => hu0 _) + have hbound : (∑ t ∈ Finset.range L, u t) ≤ L := by + calc + _ ≤ ∑ _t ∈ Finset.range L, (1 : ℝ) := Finset.sum_le_sum (fun t _ => hu1 t) + _ = _ := by simp + have he : (∑ t ∈ Finset.range M, u (t+L)) = + ∑ t ∈ Finset.range M, u (L+t) := by + apply Finset.sum_congr rfl + intro t _ + rw [Nat.add_comm t L] + rw [Finset.sum_sub_distrib, he] + linarith + +theorem finiteKernel_occupation {Ω : Type*} [Fintype Ω] + (K : Ω → FiniteLaw Ω) (alive bin : Ω → ℝ) + (ha0 : ∀ x, 0 ≤ alive x) (ha1 : ∀ x, alive x ≤ 1) + {δ : ℝ} (hδ : 0 < δ) (L : ℕ) + (hblock : ∀ x, δ * bin x ≤ alive x - (finiteKernelStep K)^[L] alive x) + (M : ℕ) (x : Ω) : + (∑ t ∈ Finset.range M, (finiteKernelStep K)^[t] bin x) ≤ (L : ℝ)/δ := by + have hstep (t : ℕ) : δ * (finiteKernelStep K)^[t] bin x ≤ + (finiteKernelStep K)^[t] alive x - (finiteKernelStep K)^[t+L] alive x := by + have h := (finiteKernelStep_mono K).iterate t hblock x + rw [finiteKernelStep_iterate_mul] at h + change δ * (finiteKernelStep K)^[t] bin x ≤ + (finiteKernelStep K)^[t] (alive - (finiteKernelStep K)^[L] alive) x at h + rw [finiteKernelStep_iterate_sub] at h + simpa only [Function.iterate_add_apply, Pi.sub_apply] using h + have hbounds (t : ℕ) : 0 ≤ (finiteKernelStep K)^[t] alive x ∧ + (finiteKernelStep K)^[t] alive x ≤ 1 := by + have hlo := (finiteKernelStep_mono K).iterate t ha0 x + have hhi := (finiteKernelStep_mono K).iterate t ha1 x + rw [finiteKernelStep_iterate_const] at hlo hhi + exact ⟨hlo, hhi⟩ + apply (le_div_iff₀ hδ).mpr + rw [mul_comm, Finset.mul_sum] + apply (Finset.sum_le_sum (fun t _ => hstep t)).trans + exact sum_shift_difference_le _ (fun t => (hbounds t).1) (fun t => (hbounds t).2) M L + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/MaskDelay.lean b/lean/OAI/Probability/SATComputability/MaskDelay.lean new file mode 100644 index 0000000000000000000000000000000000000000..db96a028731e7bf4b6fdbecd0fea4aebc9d618ec --- /dev/null +++ b/lean/OAI/Probability/SATComputability/MaskDelay.lean @@ -0,0 +1,176 @@ +import OAI.Probability.SATComputability.MaskLifetime + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory +open scoped BigOperators Classical NNReal + +theorem sixth_fifth_increment {x : ℝ} (hx : 0 ≤ x) : + (x+1)^(6/5 : ℝ) - x^(6/5 : ℝ) ≤ + (6/5 : ℝ) * (x+1)^(1/5 : ℝ) := by + have h := intervalIntegral.integral_mono_on (μ := volume) + (show x ≤ x+1 by linarith) + (intervalIntegral.intervalIntegrable_rpow' (by norm_num : (-1 : ℝ) < 1/5)) + (intervalIntegrable_const : IntervalIntegrable (fun _ : ℝ => (x+1)^(1/5 : ℝ)) + volume x (x+1)) + (fun y hy => Real.rpow_le_rpow (hx.trans hy.1) hy.2 (by norm_num : (0 : ℝ) ≤ 1/5)) + rw [integral_rpow (Or.inl (by norm_num : (-1 : ℝ) < 1/5)), + intervalIntegral.integral_const] at h + norm_num at h + nlinarith + +theorem maskLifetime_mono {n m : ℕ} {U V : Finset (DeletionCandidate n)} + (hUV : U ⊆ V) (xs : Fin m → Finset (DeletionCandidate n)) : + maskLifetime m U xs ≤ maskLifetime m V xs := by + induction m generalizing U V with + | zero => exact le_rfl + | succ m ih => + exact add_le_add (candidateAlive_mono hUV) + (ih (Finset.inter_subset_inter_right hUV) (Fin.tail xs)) + +theorem maskLifetime_empty {n m : ℕ} + (xs : Fin m → Finset (DeletionCandidate n)) : maskLifetime m ∅ xs = 0 := by + induction m with + | zero => rfl + | succ m ih => simp [maskLifetime, candidateAlive, ih] + +noncomputable def maskDelayMoment {n : ℕ} [NeZero n] + (r : ℝ≥0) (k m : ℕ) (U I : Finset (DeletionCandidate n)) : ℝ := + (FiniteLaw.pi (fun _ : Fin m => candidateBlock r k Finset.univ)).expect + (fun xs => (maskLifetime m U xs - maskLifetime m (U ∩ I) xs)^(6/5 : ℝ)) + +theorem maskDelayMoment_zero {n : ℕ} [NeZero n] (r : ℝ≥0) (k : ℕ) + (U I : Finset (DeletionCandidate n)) : maskDelayMoment r k 0 U I = 0 := by + simp [maskDelayMoment, maskLifetime] + +theorem maskDelayMoment_step {n : ℕ} [NeZero n] (r : ℝ≥0) (k m : ℕ) + (U I : Finset (DeletionCandidate n)) : + maskDelayMoment r k (m+1) U I ≤ + (candidateBlock r k U).expect (fun V => maskDelayMoment r k m V I) + + if U.Nonempty ∧ U ∩ I = ∅ then + (6/5 : ℝ) * + (FiniteLaw.pi (fun _ : Fin (m+1) => candidateBlock r k Finset.univ)).expect + (fun xs => (maskLifetime (m+1) U xs)^(1/5 : ℝ)) + else 0 := by + let P := FiniteLaw.pi (fun _ : Fin m => candidateBlock (n := n) r k Finset.univ) + have he : (candidateBlock r k Finset.univ).expect (fun V => + P.expect (fun xs => (maskLifetime m (U ∩ V) xs - + maskLifetime m ((U ∩ V) ∩ I) xs)^(6/5 : ℝ))) = + (candidateBlock r k U).expect (fun V => maskDelayMoment r k m V I) := by + simpa only [maskDelayMoment, P] using + candidateBlock_mask r k U (fun V => maskDelayMoment r k m V I) + unfold maskDelayMoment + rw [FiniteLaw.expect_pi_cons] + by_cases h : U.Nonempty ∧ U ∩ I = ∅ + · rw [ite_eq_left h] + rw [FiniteLaw.expect_pi_cons] + simp only [maskLifetime, Fin.cons_zero, Fin.tail_cons] + have hpoint (V : Finset (DeletionCandidate n)) (xs : Fin m → Finset (DeletionCandidate n)) : + (candidateAlive U + maskLifetime m (U ∩ V) xs - + (candidateAlive (U ∩ I) + maskLifetime m ((U ∩ I) ∩ V) xs))^(6/5 : ℝ) ≤ + (maskLifetime m (U ∩ V) xs - maskLifetime m ((U ∩ V) ∩ I) xs)^(6/5 : ℝ) + + (6/5 : ℝ) * (candidateAlive U + maskLifetime m (U ∩ V) xs)^(1/5 : ℝ) := by + simp only [h.2, Finset.empty_inter, maskLifetime_empty, + show (U ∩ V) ∩ I = ∅ by rw [Finset.inter_right_comm, h.2, Finset.empty_inter], + candidateAlive, ite_eq_left h.1, Finset.not_nonempty_empty, ite_false, zero_add, sub_zero] + have hi := sixth_fifth_increment (maskLifetime_nonneg (U ∩ V) xs) + simpa only [add_comm] using (sub_le_iff_le_add.mp hi) + have hb := (candidateBlock r k Finset.univ).expect_mono (fun V => + P.expect_mono (hpoint V)) + simp only [FiniteLaw.expect_add, FiniteLaw.expect_mul_left] at hb + rw [he] at hb + exact hb + · rw [ite_eq_right h, add_zero] + have halive : candidateAlive U = candidateAlive (U ∩ I) := by + by_cases hU : U.Nonempty + · have hI : (U ∩ I).Nonempty := Finset.nonempty_iff_ne_empty.mpr (fun he => h ⟨hU, he⟩) + simp [candidateAlive, hU, hI] + · have hI : ¬ (U ∩ I).Nonempty := fun hi => hU (hi.mono Finset.inter_subset_left) + simp [candidateAlive, hU, hI] + simp only [maskLifetime, Fin.cons_zero, Fin.tail_cons, halive, add_sub_add_left_eq_sub] + simpa only [Finset.inter_right_comm, P, maskDelayMoment] using le_of_eq he + +theorem finite_expect_comm {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ] + (P : FiniteLaw Ω) (Q : FiniteLaw Ξ) (f : Ω → Ξ → ℝ) : + P.expect (fun x => Q.expect (f x)) = Q.expect (fun y => P.expect (fun x => f x y)) := by + simp only [FiniteLaw.expect, Finset.mul_sum] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro y _ + apply Finset.sum_congr rfl + intro x _ + ring + +theorem finiteKernel_accumulation {Ω : Type*} [Fintype Ω] + (K : Ω → FiniteLaw Ω) (g : ℕ → Ω → ℝ) (cost : Ω → ℝ) (M : ℕ) + (hzero : ∀ x, g 0 x ≤ 0) + (hstep : ∀ m < M, ∀ x, g (m+1) x ≤ (K x).expect (g m) + cost x) (x : Ω) : + g M x ≤ ∑ t ∈ Finset.range M, (finiteKernelStep K)^[t] cost x := by + have hi (m : ℕ) (hm : m ≤ M) : + ∀ y, g m y ≤ ∑ t ∈ Finset.range m, (finiteKernelStep K)^[t] cost y := by + induction m with + | zero => simpa using hzero + | succ m ih => + intro y + apply (hstep m (by omega) y).trans + have hb := (K y).expect_mono (ih (by omega)) + apply (add_le_add hb le_rfl).trans_eq + rw [FiniteLaw.expect_sum, Finset.sum_range_succ'] + simp only [Function.iterate_zero, id_eq, Function.iterate_succ_apply'] + rfl + exact hi M le_rfl x + +theorem maskDelayMoment_occupation {n : ℕ} [NeZero n] + (r : ℝ≥0) (k M : ℕ) (P : FiniteLaw (Finset (DeletionCandidate n))) + (bound : Finset (DeletionCandidate n) → ℝ) + (hbound : ∀ m < M, ∀ U, + (FiniteLaw.pi (fun _ : Fin (m+1) => candidateBlock (n := n) r k Finset.univ)).expect + (fun xs => (maskLifetime (m+1) U xs)^(1/5 : ℝ)) ≤ bound U) + (U : Finset (DeletionCandidate n)) : + P.expect (fun I => maskDelayMoment r k M U I) ≤ + ∑ t ∈ Finset.range M, (candidateBlock (r*t) k U).expect (fun V => + (6/5 : ℝ) * P.expect (fun I => if V.Nonempty ∧ V ∩ I = ∅ then 1 else 0) * bound V) := by + let cost := fun V => (6/5 : ℝ) * + P.expect (fun I => if V.Nonempty ∧ V ∩ I = ∅ then 1 else 0) * bound V + have hs (m : ℕ) (hm : m < M) (V : Finset (DeletionCandidate n)) : + P.expect (fun I => maskDelayMoment r k (m+1) V I) ≤ + (candidateBlock r k V).expect (fun W => P.expect (fun I => maskDelayMoment r k m W I)) + cost V := by + have hi := P.expect_mono (fun I => maskDelayMoment_step r k m V I) + rw [FiniteLaw.expect_add, finite_expect_comm] at hi + apply hi.trans + apply add_le_add le_rfl + have he : P.expect (fun I => + if V.Nonempty ∧ V ∩ I = ∅ then (6/5 : ℝ) * + (FiniteLaw.pi (fun _ : Fin (m+1) => candidateBlock (n := n) r k Finset.univ)).expect + (fun xs => (maskLifetime (m+1) V xs)^(1/5 : ℝ)) else 0) = + (6/5 : ℝ) * P.expect (fun I => if V.Nonempty ∧ V ∩ I = ∅ then 1 else 0) * + (FiniteLaw.pi (fun _ : Fin (m+1) => candidateBlock (n := n) r k Finset.univ)).expect + (fun xs => (maskLifetime (m+1) V xs)^(1/5 : ℝ)) := by + let z := (FiniteLaw.pi (fun _ : Fin (m+1) => + candidateBlock (n := n) r k Finset.univ)).expect + (fun xs => (maskLifetime (m+1) V xs)^(1/5 : ℝ)) + change P.expect (fun I => if V.Nonempty ∧ V ∩ I = ∅ then (6/5 : ℝ)*z else 0) = + (6/5 : ℝ) * P.expect (fun I => if V.Nonempty ∧ V ∩ I = ∅ then 1 else 0) * z + calc + _ = P.expect (fun I => (if V.Nonempty ∧ V ∩ I = ∅ then 1 else 0) * ((6/5 : ℝ)*z)) := by + apply P.expect_congr + intro I + split_ifs <;> simp + _ = _ := by rw [FiniteLaw.expect_mul_right]; ring + rw [he] + exact mul_le_mul_of_nonneg_left (hbound m hm V) + (mul_nonneg (by norm_num) (P.expect_nonneg (fun I => by split_ifs <;> norm_num))) + have hz : ∀ V, P.expect (fun I => maskDelayMoment r k 0 V I) ≤ 0 := by + intro V + simp only [maskDelayMoment_zero, FiniteLaw.expect_const, le_refl] + have h := finiteKernel_accumulation (candidateBlock r k) + (fun m V => P.expect (fun I => maskDelayMoment r k m V I)) cost M hz hs U + change P.expect (fun I => maskDelayMoment r k M U I) ≤ + ∑ t ∈ Finset.range M, (poissonCandidateStep r k)^[t] cost U at h + simpa only [poissonCandidateStep_iterate, cost] using h + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/MaskDeletionTimes.lean b/lean/OAI/Probability/SATComputability/MaskDeletionTimes.lean new file mode 100644 index 0000000000000000000000000000000000000000..7c770f47df472ebd877c53fe84bb890cca858a8a --- /dev/null +++ b/lean/OAI/Probability/SATComputability/MaskDeletionTimes.lean @@ -0,0 +1,107 @@ +import OAI.Probability.SATComputability.IncidentMasks +import OAI.Probability.SATComputability.DeletionEnergy + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped BigOperators Classical + +theorem maskLifetime_union {n m : ℕ} (U V : Finset (DeletionCandidate n)) + (xs : Fin m → Finset (DeletionCandidate n)) : + maskLifetime m (U ∪ V) xs = max (maskLifetime m U xs) (maskLifetime m V xs) := by + induction m generalizing U V with + | zero => simp [maskLifetime] + | succ m ih => + by_cases hU : U.Nonempty + · by_cases hV : V.Nonempty + · have hUV : (U ∪ V).Nonempty := hU.mono Finset.subset_union_left + simp only [maskLifetime, candidateAlive, ite_eq_left hU, ite_eq_left hV, + ite_eq_left hUV, Finset.union_inter_distrib_right, ih, max_add_add_left] + · have hVe : V = ∅ := Finset.not_nonempty_iff_eq_empty.mp hV + subst V + simp only [Finset.union_empty, maskLifetime_empty, max_eq_left (maskLifetime_nonneg U xs)] + · have hUe : U = ∅ := Finset.not_nonempty_iff_eq_empty.mp hU + subst U + simp only [Finset.empty_union, maskLifetime_empty, max_eq_right (maskLifetime_nonneg V xs)] + +theorem maskLifetime_biUnion {ι : Type*} [DecidableEq ι] {n m : ℕ} + (S : Finset ι) (hS : S.Nonempty) (F : ι → Finset (DeletionCandidate n)) + (xs : Fin m → Finset (DeletionCandidate n)) : + maskLifetime m (S.biUnion F) xs = S.sup' hS (fun i => maskLifetime m (F i) xs) := by + induction S using Finset.induction_on with + | empty => simp at hS + | @insert a S ha ih => + by_cases hne : S.Nonempty + · rw [Finset.biUnion_insert, maskLifetime_union, ih hne, Finset.sup'_insert hne] + · have he : S = ∅ := Finset.not_nonempty_iff_eq_empty.mp hne + subst S + simp + +def deletionMask {n : ℕ} (D : Finset (Fin n)) : Finset (DeletionCandidate n) := + Finset.univ.filter (fun x => deletedVariables x ⊆ D) + +def deletionBudgetMask (n r : ℕ) : Finset (DeletionCandidate n) := + Finset.univ.filter (fun x => (deletedVariables x).card ≤ r) + +def freeDeletionBudgetMask (n r : ℕ) (v : Fin n) : Finset (DeletionCandidate n) := + (allowedDeletions n r).biUnion (fun D => deletionMask (insert v D)) + +theorem deletionMask_mono {n : ℕ} : Monotone (deletionMask (n := n)) := by + intro D E hDE x hx + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, (Finset.mem_filter.mp hx).2.trans hDE⟩ + +theorem deletionBudgetMask_union (n r : ℕ) : + (allowedDeletions n r).biUnion (deletionMask (n := n)) = deletionBudgetMask n r := by + ext x + simp only [Finset.mem_biUnion, deletionMask, deletionBudgetMask, allowedDeletions, + Finset.mem_filter, Finset.mem_univ, true_and] + constructor + · rintro ⟨D,hD,hx⟩ + exact (Finset.card_le_card hx).trans hD + · intro hx + exact ⟨deletedVariables x,hx,Finset.Subset.refl _⟩ + +noncomputable def fixedMaskDeletionTime {n m : ℕ} + (xs : Fin m → Finset (DeletionCandidate n)) (D : Finset (Fin n)) : ℝ := + maskLifetime m (deletionMask D) xs + +theorem fixedMaskDeletionTime_mono {n m : ℕ} + (xs : Fin m → Finset (DeletionCandidate n)) : Monotone (fixedMaskDeletionTime xs) := by + intro D E hDE + exact maskLifetime_mono (deletionMask_mono hDE) xs + +theorem bestMaskDeletionTime_eq {n m : ℕ} + (xs : Fin m → Finset (DeletionCandidate n)) (r : ℕ) : + bestDeletionTime (fixedMaskDeletionTime xs) r = maskLifetime m (deletionBudgetMask n r) xs := by + rw [← deletionBudgetMask_union, maskLifetime_biUnion _ (allowedDeletions_nonempty n r)] + rfl + +theorem freeMaskDeletionTime_eq {n m : ℕ} + (xs : Fin m → Finset (DeletionCandidate n)) (r : ℕ) (v : Fin n) : + freeDeletionTime (fixedMaskDeletionTime xs) r v = maskLifetime m (freeDeletionBudgetMask n r v) xs := by + rw [freeDeletionBudgetMask, maskLifetime_biUnion _ (allowedDeletions_nonempty n r)] + rfl + +theorem maskLifetime_frontload {n m : ℕ} (U : Finset (DeletionCandidate n)) + (base incident : Fin m → Finset (DeletionCandidate n)) (I : Finset (DeletionCandidate n)) + (hI : ∀ j, I ⊆ incident j) : + maskLifetime m (U ∩ I) base ≤ maskLifetime m U (fun j => base j ∩ incident j) := by + induction m generalizing U with + | zero => exact le_rfl + | succ m ih => + simp only [maskLifetime] + apply add_le_add (candidateAlive_mono Finset.inter_subset_left) + have hsub : (U ∩ I) ∩ base 0 ⊆ (U ∩ (base 0 ∩ incident 0)) ∩ I := by + intro x hx + obtain ⟨hxUI,hxb⟩ := Finset.mem_inter.mp hx + obtain ⟨hxU,hxI⟩ := Finset.mem_inter.mp hxUI + exact Finset.mem_inter.mpr ⟨Finset.mem_inter.mpr + ⟨hxU,Finset.mem_inter.mpr ⟨hxb,hI 0 hxI⟩⟩,hxI⟩ + exact (maskLifetime_mono hsub (Fin.tail base)).trans + (ih (U ∩ (base 0 ∩ incident 0)) (Fin.tail base) (Fin.tail incident) (fun j => hI j.succ)) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/MaskLifetime.lean b/lean/OAI/Probability/SATComputability/MaskLifetime.lean new file mode 100644 index 0000000000000000000000000000000000000000..d8591da0a65015485979d25b92e7dc47dd1b1364 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/MaskLifetime.lean @@ -0,0 +1,101 @@ +import OAI.Probability.SATComputability.CandidateMasks +import OAI.Probability.SATComputability.DiscreteDelay + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped BigOperators NNReal Classical + +noncomputable def maskLifetime {n : ℕ} : (m : ℕ) → Finset (DeletionCandidate n) → + (Fin m → Finset (DeletionCandidate n)) → ℝ + | 0, _, _ => 0 + | m+1, U, xs => candidateAlive U + maskLifetime m (U ∩ xs 0) (Fin.tail xs) + +theorem maskLifetime_nonneg {n m : ℕ} (U : Finset (DeletionCandidate n)) + (xs : Fin m → Finset (DeletionCandidate n)) : 0 ≤ maskLifetime m U xs := by + induction m generalizing U with + | zero => exact (le_rfl : (0 : ℝ) ≤ 0) + | succ m ih => exact add_nonneg (candidateAlive_nonneg U) (ih _ _) + +theorem maskLifetime_le {n m : ℕ} (U : Finset (DeletionCandidate n)) + (xs : Fin m → Finset (DeletionCandidate n)) : maskLifetime m U xs ≤ m := by + induction m generalizing U with + | zero => simp [maskLifetime] + | succ m ih => + simp only [maskLifetime, Nat.cast_add, Nat.cast_one] + linarith [candidateAlive_le_one U, ih (U ∩ xs 0) (Fin.tail xs)] + +theorem candidateBlock_zero_expect {n : ℕ} [NeZero n] (k : ℕ) + (U : Finset (DeletionCandidate n)) (f : Finset (DeletionCandidate n) → ℝ) : + (candidateBlock 0 k U).expect f = f U := by + rw [candidateBlock_expect, ProbabilityTheory.integral_poissonMeasure] + simp [zero_pow_eq, ite_div, ite_mul] + +theorem maskLifetime_mean {n : ℕ} [NeZero n] (r : ℝ≥0) (k m : ℕ) + (U : Finset (DeletionCandidate n)) : + (FiniteLaw.pi (fun _ : Fin m => candidateBlock r k Finset.univ)).expect + (maskLifetime m U) = + ∑ t ∈ Finset.range m, (candidateBlock (r*t) k U).expect candidateAlive := by + induction m generalizing U with + | zero => simp [maskLifetime] + | succ m ih => + rw [FiniteLaw.expect_pi_cons] + simp only [maskLifetime, Fin.cons_zero, Fin.tail_cons, FiniteLaw.expect_add, + FiniteLaw.expect_const, ih, FiniteLaw.expect_sum] + rw [Finset.sum_range_succ'] + simp only [Nat.cast_zero, mul_zero, candidateBlock_zero_expect] + rw [add_comm (candidateAlive U)] + congr 1 + apply Finset.sum_congr rfl + intro t _ + rw [candidateBlock_mask r k U (fun V => (candidateBlock (r*t) k V).expect candidateAlive)] + rw [← candidateBlock_comp] + congr 2 + push_cast + ring + +theorem candidateBlock_kill_antitone {n : ℕ} [NeZero n] (r : ℝ≥0) (k : ℕ) + {U V : Finset (DeletionCandidate n)} (hVU : V ⊆ U) : + poissonKillProbability U k r ≤ poissonKillProbability V k r := by + have h := candidateBlock_expect_mono_state r k candidateAlive_mono hVU + change (candidateBlock r k V).expect candidateAlive ≤ + (candidateBlock r k U).expect candidateAlive at h + rw [candidateBlock_expect_alive, candidateBlock_expect_alive] at h + linarith + +theorem maskLifetime_mean_le {n : ℕ} [NeZero n] (r : ℝ≥0) (k m L : ℕ) + (U : Finset (DeletionCandidate n)) {δ : ℝ} (hδ : 0 < δ) + (hkill : δ ≤ poissonKillProbability U k (r*L)) : + (FiniteLaw.pi (fun _ : Fin m => candidateBlock r k Finset.univ)).expect + (maskLifetime m U) ≤ (L : ℝ)/δ := by + let bin := fun V : Finset (DeletionCandidate n) => V.Nonempty ∧ V ⊆ U + have hb (V : Finset (DeletionCandidate n)) (hV : bin V) : + V.Nonempty ∧ δ ≤ poissonKillProbability V k (r*L) := + ⟨hV.1, hkill.trans (candidateBlock_kill_antitone _ _ hV.2)⟩ + have he (t : ℕ) : (candidateBlock (r*t) k U).expect candidateAlive = + (candidateBlock (r*t) k U).expect (fun V => if bin V then 1 else 0) := by + apply le_antisymm + · apply candidateBlock_expect_le_of_subset + intro V hV + by_cases hne : V.Nonempty <;> simp [candidateAlive, bin, hne, hV] + · apply candidateBlock_expect_le_of_subset + intro V hV + by_cases hne : V.Nonempty <;> simp [candidateAlive, bin, hne, hV] + rw [maskLifetime_mean] + simp_rw [he] + exact candidateBlock_occupation r k L m bin hδ hb U + +theorem maskLifetime_fractional_moment {n : ℕ} [NeZero n] (r : ℝ≥0) (k m L : ℕ) + (U : Finset (DeletionCandidate n)) {δ : ℝ} (hδ : 0 < δ) + (hkill : δ ≤ poissonKillProbability U k (r*L)) : + (FiniteLaw.pi (fun _ : Fin m => candidateBlock r k Finset.univ)).expect + (fun xs => (maskLifetime m U xs)^(1/5 : ℝ)) ≤ ((L : ℝ)/δ)^(1/5 : ℝ) := by + apply (finite_fractional_moment _ _ (maskLifetime_nonneg U)).trans + apply Real.rpow_le_rpow (FiniteLaw.expect_nonneg _ (maskLifetime_nonneg U)) + (maskLifetime_mean_le r k m L U hδ hkill) (by norm_num) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/MaskPermutations.lean b/lean/OAI/Probability/SATComputability/MaskPermutations.lean new file mode 100644 index 0000000000000000000000000000000000000000..bd2fd316238257bfba17cc674a5ca5e264ef68f9 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/MaskPermutations.lean @@ -0,0 +1,152 @@ +import OAI.Probability.SATComputability.RestoredCandidates +import OAI.Probability.SATComputability.PoissonMaskCounts + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped Classical + +noncomputable section + +local instance maskPermutationsDecidableEq (n : ℕ) : DecidableEq (DeletionCandidate n) := + Classical.decEq _ + +def candidatePermutation {n : ℕ} (e : Equiv.Perm (Fin n)) : + Equiv.Perm (DeletionCandidate n) where + toFun x v := x (e.symm v) + invFun x v := x (e v) + left_inv x := by funext v; simp + right_inv x := by funext v; simp + +def literalPermutation {n : ℕ} (e : Equiv.Perm (Fin n)) : Equiv.Perm (SignedLiteral n) := + e.prodCongr (Equiv.refl Bool) + +noncomputable def renameMask {n : ℕ} (e : Equiv.Perm (Fin n)) + (U : Finset (DeletionCandidate n)) : Finset (DeletionCandidate n) := + U.image (candidatePermutation e) + +theorem deletedVariables_permutation {n : ℕ} (e : Equiv.Perm (Fin n)) (x : DeletionCandidate n) : + deletedVariables (candidatePermutation e x) = (deletedVariables x).image e := by + ext v + constructor + · intro h + have hx : x (e.symm v) = none := (Finset.mem_filter.mp h).2 + exact Finset.mem_image.mpr ⟨e.symm v, + Finset.mem_filter.mpr ⟨Finset.mem_univ _,hx⟩,e.apply_symm_apply v⟩ + · intro h + obtain ⟨w,hw,hwe⟩ := Finset.mem_image.mp h + have hx : x w = none := (Finset.mem_filter.mp hw).2 + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _,?_⟩ + change x (e.symm v) = none + rw [← hwe,Equiv.symm_apply_apply] + exact hx + +theorem deletionBudget_permutation {n r : ℕ} (e : Equiv.Perm (Fin n)) (x : DeletionCandidate n) : + candidatePermutation e x ∈ deletionBudgetMask n r ↔ x ∈ deletionBudgetMask n r := by + simp only [deletionBudgetMask, Finset.mem_filter, Finset.mem_univ, true_and, + deletedVariables_permutation, Finset.card_image_of_injective _ e.injective] + +theorem mem_freeDeletionBudgetMask_erase {n r : ℕ} (v : Fin n) (x : DeletionCandidate n) : + x ∈ freeDeletionBudgetMask n r v ↔ ((deletedVariables x).erase v).card ≤ r := by + simp only [freeDeletionBudgetMask, Finset.mem_biUnion, allowedDeletions, deletionMask, + Finset.mem_filter, Finset.mem_univ, true_and] + constructor + · rintro ⟨D,hD,hx⟩ + have he : (deletedVariables x).erase v ⊆ D := by + intro w hw + exact (Finset.mem_insert.mp (hx (Finset.mem_of_mem_erase hw))).resolve_left + (Finset.ne_of_mem_erase hw) + exact (Finset.card_le_card he).trans hD + · intro hx + refine ⟨(deletedVariables x).erase v,hx,?_⟩ + intro w hw + by_cases he : w = v + · exact Finset.mem_insert.mpr (Or.inl he) + · exact Finset.mem_insert.mpr (Or.inr (Finset.mem_erase.mpr ⟨he,hw⟩)) + +theorem freeDeletionBudget_permutation {n r : ℕ} (e : Equiv.Perm (Fin n)) + (v : Fin n) (x : DeletionCandidate n) : + candidatePermutation e x ∈ freeDeletionBudgetMask n r (e v) ↔ + x ∈ freeDeletionBudgetMask n r v := by + rw [mem_freeDeletionBudgetMask_erase, mem_freeDeletionBudgetMask_erase, + deletedVariables_permutation, ← Finset.image_erase e.injective, + Finset.card_image_of_injective _ e.injective] + +theorem maskLifetime_permutation {n M : ℕ} (e : Equiv.Perm (Fin n)) + (U V : Finset (DeletionCandidate n)) (xs : Fin M → Finset (DeletionCandidate n)) + (hUV : ∀ x, candidatePermutation e x ∈ V ↔ x ∈ U) : + maskLifetime M V (fun j => renameMask e (xs j)) = maskLifetime M U xs := by + apply le_antisymm + · apply maskLifetime_map_le (candidatePermutation e).symm + · intro x hx + have h := (hUV ((candidatePermutation e).symm x)).mp + exact h (by simpa only [Equiv.apply_symm_apply] using hx) + · intro j x hx + obtain ⟨y,hy,rfl⟩ := Finset.mem_image.mp hx + simpa only [Equiv.symm_apply_apply] using hy + · apply maskLifetime_map_le (candidatePermutation e) + · intro x hx + exact (hUV x).mpr hx + · intro j x hx + exact Finset.mem_image.mpr ⟨x,hx,rfl⟩ + +theorem clauseMask_permutation_mem {n k : ℕ} (e : Equiv.Perm (Fin n)) + (cs : Fin k → SignedLiteral n) (x : DeletionCandidate n) : + candidatePermutation e x ∈ clauseMask (fun j => literalPermutation e (cs j)) ↔ + x ∈ clauseMask cs := by + simp only [clauseMask, Finset.mem_filter, Finset.mem_univ, true_and] + change (¬∀ j, x (e.symm (e (cs j).1)) = some (!(cs j).2)) ↔ + (¬∀ j, x (cs j).1 = some (!(cs j).2)) + simp only [Equiv.symm_apply_apply] + +def clausePermutation {n : ℕ} (e : Equiv.Perm (Fin n)) (k : ℕ) : + Equiv.Perm (Fin k → SignedLiteral n) where + toFun c j := literalPermutation e (c j) + invFun c j := (literalPermutation e).symm (c j) + left_inv c := by funext j; exact (literalPermutation e).symm_apply_apply _ + right_inv c := by funext j; exact (literalPermutation e).apply_symm_apply _ + +private theorem mem_clauseCounts {n k : ℕ} (x : DeletionCandidate n) + (c : (Fin k → SignedLiteral n) → ℕ) : + x ∈ countsMask clauseMask c ↔ ∀ a, c a = 0 ∨ x ∈ clauseMask a := by + simp only [countsMask, Finset.mem_filter, Finset.mem_univ, true_and] + +theorem countsMask_permutation {n k : ℕ} (e : Equiv.Perm (Fin n)) + (c : (Fin k → SignedLiteral n) → ℕ) : + renameMask e (countsMask clauseMask c) = + countsMask clauseMask (fun a => c ((clausePermutation e k).symm a)) := by + ext x + rw [renameMask, Finset.mem_image] + constructor + · rintro ⟨y,hy,rfl⟩ + apply (mem_clauseCounts _ _).mpr + intro a + rcases (mem_clauseCounts y c).mp hy ((clausePermutation e k).symm a) with hz | hm + · exact Or.inl hz + · right + have he : (fun j => literalPermutation e (((clausePermutation e k).symm a) j)) = a := + (clausePermutation e k).apply_symm_apply a + rw [← he] + exact (clauseMask_permutation_mem e _ y).mpr hm + · intro hx + refine ⟨(candidatePermutation e).symm x, ?_, (candidatePermutation e).apply_symm_apply x⟩ + apply (mem_clauseCounts _ _).mpr + intro a + have h := (mem_clauseCounts x _).mp hx ((clausePermutation e k) a) + simp only [Equiv.symm_apply_apply] at h + rcases h with hz | hm + · exact Or.inl hz + · right + have hmem := (clauseMask_permutation_mem e a ((candidatePermutation e).symm x)).mp + apply hmem + change x ∈ clauseMask (fun j => literalPermutation e (a j)) at hm + simpa only [Equiv.apply_symm_apply] using hm + +end + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/MeanSurvival.lean b/lean/OAI/Probability/SATComputability/MeanSurvival.lean new file mode 100644 index 0000000000000000000000000000000000000000..1497c938a32d73a68a099841160f3391cac2ce9f --- /dev/null +++ b/lean/OAI/Probability/SATComputability/MeanSurvival.lean @@ -0,0 +1,118 @@ +import OAI.Probability.SATComputability.CandidateProbability + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped NNReal BigOperators Classical + +theorem candidateBlock_survival_antitone {n : ℕ} [NeZero n] (k : ℕ) + (U : Finset (DeletionCandidate n)) : + Antitone (fun r => (candidateBlock r k U).expect candidateAlive) := by + intro r s hrs + simp only [candidateBlock_expect_alive] + exact sub_le_sub_left (poissonKillProbability_mono_rate U k hrs) 1 + +theorem survival_le_mean_lifetime {n M t : ℕ} [NeZero n] + (ht : t ≤ M) (U : Finset (DeletionCandidate n)) : + (t : ℝ)*(candidateBlock (n := n) t 3 U).expect candidateAlive ≤ + (FiniteLaw.pi (fun _ : Fin M => candidateBlock (n := n) 1 3 Finset.univ)).expect + (maskLifetime M U) := by + rw [maskLifetime_mean] + simp only [one_mul] + calc + _ = ∑ _s ∈ Finset.range t, (candidateBlock (n := n) t 3 U).expect candidateAlive := by + simp + _ ≤ ∑ s ∈ Finset.range t, (candidateBlock (n := n) s 3 U).expect candidateAlive := by + apply Finset.sum_le_sum + intro s hs + exact candidateBlock_survival_antitone 3 U (by exact_mod_cast + (Finset.mem_range.mp hs).le) + _ ≤ ∑ s ∈ Finset.range M, (candidateBlock (n := n) s 3 U).expect candidateAlive := by + apply Finset.sum_le_sum_of_subset_of_nonneg (Finset.range_mono ht) + intro s _ _ + exact FiniteLaw.expect_nonneg _ candidateAlive_nonneg + +theorem antitone_sum_bound (q : ℕ → ℝ) (hq : Antitone q) + (h0 : ∀ s, 0 ≤ q s) (h1 : ∀ s, q s ≤ 1) (M t : ℕ) : + ∑ s ∈ Finset.range M, q s ≤ t + (M : ℝ)*q t := by + by_cases ht : t ≤ M + · rw [← Nat.add_sub_of_le ht, Finset.sum_range_add] + have hfirst : ∑ s ∈ Finset.range t, q s ≤ (t : ℝ) := by + calc + _ ≤ ∑ _s ∈ Finset.range t, (1 : ℝ) := Finset.sum_le_sum (fun s _ => h1 s) + _ = _ := by simp + have hlast : ∑ s ∈ Finset.range (M-t), q (t+s) ≤ (M-t : ℕ)*q t := by + calc + _ ≤ ∑ _s ∈ Finset.range (M-t), q t := + Finset.sum_le_sum (fun s _ => hq (Nat.le_add_right t s)) + _ = _ := by simp + have htail : ((M-t : ℕ) : ℝ)*q t ≤ (t+(M-t) : ℕ)*q t := + mul_le_mul_of_nonneg_right (by exact_mod_cast Nat.le_add_left (M-t) t) (h0 t) + push_cast at htail ⊢ + linarith + · have hMt : M ≤ t := (Nat.lt_of_not_ge ht).le + calc + _ ≤ ∑ _s ∈ Finset.range M, (1 : ℝ) := Finset.sum_le_sum (fun s _ => h1 s) + _ = M := by simp + _ ≤ t := by exact_mod_cast hMt + _ ≤ t + (M : ℝ)*q t := le_add_of_nonneg_right (mul_nonneg (Nat.cast_nonneg M) (h0 t)) + +theorem zero_lifetime_mean_upper (n : ℕ) [NeZero n] (b : ℝ≥0) : + (FiniteLaw.pi (fun _ : Fin (20*n) => candidateBlock (n := n) 1 3 Finset.univ)).expect + (maskLifetime (20*n) (deletionBudgetMask n 0)) ≤ + ⌈(b : ℝ)*n⌉₊ + (20*n : ℕ)*auxiliaryPoissonProbability n b := by + rw [maskLifetime_mean] + simp only [one_mul] + have h := antitone_sum_bound + (fun s => (candidateBlock (n := n) s 3 (deletionBudgetMask n 0)).expect candidateAlive) + (fun s t hst => candidateBlock_survival_antitone 3 _ (by exact_mod_cast hst)) + (fun _ => FiniteLaw.expect_nonneg _ candidateAlive_nonneg) + (fun _ => (FiniteLaw.expect_mono _ candidateAlive_le_one).trans_eq (FiniteLaw.expect_const _ 1)) + (20*n) ⌈(b : ℝ)*n⌉₊ + apply h.trans + apply add_le_add le_rfl + apply mul_le_mul_of_nonneg_left _ (Nat.cast_nonneg _) + have hb : b*n ≤ (⌈(b : ℝ)*n⌉₊ : ℝ≥0) := by + apply NNReal.coe_le_coe.mp + simpa only [NNReal.coe_mul, NNReal.coe_natCast] using Nat.le_ceil ((b : ℝ)*n) + have hs := candidateBlock_survival_antitone 3 (deletionBudgetMask n 0) hb + simpa only [candidateBlock_zero_survival, auxiliaryPoissonProbability] using hs + +theorem minimumDeletions_survival_lower {n r : ℕ} (hr : r ≤ n+1) + (U : Finset (DeletionCandidate n)) : + (r : ℝ)*(1-candidateAlive (U ∩ deletionBudgetMask n r)) ≤ minimumDeletions U := by + by_cases h : (U ∩ deletionBudgetMask n r).Nonempty + · simp only [candidateAlive, ite_eq_left h, sub_self, mul_zero] + exact Nat.cast_nonneg _ + · simp only [candidateAlive, ite_eq_right h, sub_zero, mul_one] + by_cases hU : U.Nonempty + · have hm : r < minimumDeletions U := by + apply Nat.lt_of_not_ge + intro hm + obtain ⟨x,hx,hxr⟩ := (minimumDeletions_le_iff hU).mp hm + exact h ⟨x,Finset.mem_inter.mpr ⟨hx,Finset.mem_filter.mpr ⟨Finset.mem_univ _,hxr⟩⟩⟩ + exact_mod_cast hm.le + · rw [minimumDeletions, dite_eq_right hU] + exact_mod_cast hr + +theorem block_minimumDeletions_lower {n r : ℕ} [NeZero n] (hr : r ≤ n+1) (t : ℝ≥0) : + (r : ℝ)*(1-(candidateBlock t 3 (deletionBudgetMask n r)).expect candidateAlive) ≤ + (candidateBlock (n := n) t 3 Finset.univ).expect (fun U => (minimumDeletions U : ℝ)) := by + have h := (candidateBlock (n := n) t 3 Finset.univ).expect_mono + (minimumDeletions_survival_lower hr) + rw [FiniteLaw.expect_mul_left, FiniteLaw.expect_sub, FiniteLaw.expect_const] at h + have he : (candidateBlock (n := n) t 3 Finset.univ).expect + (fun x => candidateAlive (x ∩ deletionBudgetMask n r)) = + (candidateBlock t 3 (deletionBudgetMask n r)).expect candidateAlive := by + calc + _ = (candidateBlock (n := n) t 3 Finset.univ).expect + (fun x => candidateAlive (deletionBudgetMask n r ∩ x)) := + FiniteLaw.expect_congr _ (fun x => congrArg candidateAlive (Finset.inter_comm x _)) + _ = _ := candidateBlock_mask t 3 (deletionBudgetMask n r) candidateAlive + rwa [he] at h + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ObstructionMoment.lean b/lean/OAI/Probability/SATComputability/ObstructionMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..251204b3d64a3365f2f075c96a4efb3244ed45c4 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ObstructionMoment.lean @@ -0,0 +1,191 @@ +import OAI.Probability.SATComputability.DyadicMoment + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory +open scoped BigOperators Classical NNReal + +theorem poissonKillProbability_nonneg {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k : ℕ) (r : ℝ≥0) : + 0 ≤ poissonKillProbability U k r := + integral_nonneg (fun d => batchKillProbability_nonneg U k d) + +noncomputable def dyadicIndex {n : ℕ} [NeZero n] (U : Finset (DeletionCandidate n)) : ℕ := + if h : U.Nonempty ∧ 0 < poissonKillProbability U 2 60 then + Nat.find (positive_killing_in_dyadic_bin U h.1 h.2) else 0 + +theorem dyadicIndex_spec {n : ℕ} [NeZero n] (U : Finset (DeletionCandidate n)) + (h : U.Nonempty ∧ 0 < poissonKillProbability U 2 60) : dyadicBin (dyadicIndex U) U := by + simp only [dyadicIndex, dite_eq_left h] + exact Nat.find_spec (positive_killing_in_dyadic_bin U h.1 h.2) + +noncomputable def dyadicCapBound {n : ℕ} [NeZero n] + (M : ℕ) (U : Finset (DeletionCandidate n)) : ℝ := + if U.Nonempty ∧ 0 < poissonKillProbability U 2 60 then + min ((M : ℝ)^(1/5 : ℝ)) (dyadicLifetimeBound (dyadicIndex U)) + else (M : ℝ)^(1/5 : ℝ) + +theorem dyadicCapBound_nonneg {n : ℕ} [NeZero n] + (M : ℕ) (U : Finset (DeletionCandidate n)) : 0 ≤ dyadicCapBound M U := by + unfold dyadicCapBound + split_ifs + · exact le_min (by positivity) (dyadicLifetimeBound_nonneg _) + · positivity + +theorem dyadicCapBound_le_cap {n : ℕ} [NeZero n] + (M : ℕ) (U : Finset (DeletionCandidate n)) : + dyadicCapBound M U ≤ (M : ℝ)^(1/5 : ℝ) := by + unfold dyadicCapBound + split_ifs + · exact min_le_left _ _ + · rfl + +theorem dyadicCapBound_controls {n : ℕ} [NeZero n] (r : ℝ≥0) + (hr : (1 : ℝ)/8 ≤ r) (m M : ℕ) (hm : m ≤ M) + (U : Finset (DeletionCandidate n)) : + (FiniteLaw.pi (fun _ : Fin m => candidateBlock (n := n) r 3 Finset.univ)).expect + (fun xs => (maskLifetime m U xs)^(1/5 : ℝ)) ≤ dyadicCapBound M U := by + have hc := capped_lifetime_fractional_bound r 3 m M hm U + unfold dyadicCapBound + split_ifs with h + · exact le_min hc (dyadic_lifetime_bound r hr m _ U (dyadicIndex_spec U h)) + · exact hc + +theorem dyadicCapBound_weighted {n : ℕ} [NeZero n] + (M J : ℕ) (U : Finset (DeletionCandidate n)) + (hJ : dyadicIndex U < J) (hU : U.Nonempty) : + (poissonKillProbability U 2 60)^2 * dyadicCapBound M U ≤ + ∑ j ∈ Finset.range J, if dyadicBin j U then + 4*(dyadicLevel j)^2*dyadicLifetimeBound j else 0 := by + have hn : ∀ j, 0 ≤ if dyadicBin j U then + 4*(dyadicLevel j)^2*dyadicLifetimeBound j else 0 := by + intro j + split_ifs <;> positivity [dyadicLifetimeBound_nonneg j] + by_cases hp : 0 < poissonKillProbability U 2 60 + · have hb := dyadicIndex_spec U ⟨hU,hp⟩ + have hR : dyadicCapBound M U ≤ dyadicLifetimeBound (dyadicIndex U) := by + simp only [dyadicCapBound, ite_eq_left (And.intro hU hp)] + exact min_le_right _ _ + have hq : (poissonKillProbability U 2 60)^2 ≤ 4*(dyadicLevel (dyadicIndex U))^2 := by + have hqp := dyadicLevel_pos (dyadicIndex U) + nlinarith [hb.2.2] + calc + _ ≤ 4*(dyadicLevel (dyadicIndex U))^2 * dyadicLifetimeBound (dyadicIndex U) := + mul_le_mul hq hR (dyadicCapBound_nonneg M U) (by positivity) + _ = (if dyadicBin (dyadicIndex U) U then + 4*(dyadicLevel (dyadicIndex U))^2*dyadicLifetimeBound (dyadicIndex U) else 0) := + (ite_eq_left hb).symm + _ ≤ _ := Finset.single_le_sum (fun j _ => hn j) (Finset.mem_range.mpr hJ) + · have hz : poissonKillProbability U 2 60 = 0 := + le_antisymm (le_of_not_gt hp) (poissonKillProbability_nonneg U 2 60) + rw [hz, zero_pow (by decide : 2 ≠ 0), zero_mul] + exact Finset.sum_nonneg (fun j _ => hn j) + +theorem obstruction_cost_bound {n : ℕ} [NeZero n] + (P : FiniteLaw (Finset (DeletionCandidate n))) (M J : ℕ) (ε : ℝ) + (U : Finset (DeletionCandidate n)) (hJ : dyadicIndex U < J) + (hP : P.expect (fun I => if U.Nonempty ∧ U ∩ I = ∅ then 1 else 0) ≤ + (poissonKillProbability U 2 60 + ε)^2) : + (6/5 : ℝ) * P.expect (fun I => if U.Nonempty ∧ U ∩ I = ∅ then 1 else 0) * + dyadicCapBound M U ≤ + (12/5 : ℝ) * (∑ j ∈ Finset.range J, if dyadicBin j U then + 4*(dyadicLevel j)^2*dyadicLifetimeBound j else 0) + + (12/5 : ℝ)*ε^2*(M : ℝ)^(1/5 : ℝ) := by + by_cases hU : U.Nonempty + · have hq := dyadicCapBound_weighted M J U hJ hU + have he := mul_le_mul_of_nonneg_left (dyadicCapBound_le_cap M U) (sq_nonneg ε) + have hs : (poissonKillProbability U 2 60 + ε)^2 ≤ + 2*(poissonKillProbability U 2 60)^2 + 2*ε^2 := by + nlinarith [sq_nonneg (poissonKillProbability U 2 60 - ε)] + have hb := mul_le_mul_of_nonneg_right (hP.trans hs) (dyadicCapBound_nonneg M U) + nlinarith + · simp only [hU, false_and, ite_false, FiniteLaw.expect_const, mul_zero, zero_mul] + apply add_nonneg + · apply mul_nonneg (by norm_num) + exact Finset.sum_nonneg (fun j _ => by split_ifs <;> positivity [dyadicLifetimeBound_nonneg j]) + · positivity + +theorem dyadic_bin_cost_occupation {n : ℕ} [NeZero n] + (r : ℝ≥0) (hr : (1 : ℝ)/8 ≤ r) (j M : ℕ) + (U : Finset (DeletionCandidate n)) : + (∑ t ∈ Finset.range M, (candidateBlock (r*t) 3 U).expect + (fun V => if dyadicBin j V then + 4*(dyadicLevel j)^2*dyadicLifetimeBound j else 0)) ≤ + 4*dyadicMomentCoefficient j := by + let A : ℝ := 4*(dyadicBlock j : ℝ)/dyadicLevel j + have hA : 0 < A := by + dsimp [A, dyadicBlock, dyadicTruncation] + positivity [dyadicLevel_pos j, dyadic_multiplicity_pos j] + have he (V : Finset (DeletionCandidate n)) : + (if dyadicBin j V then 4*(dyadicLevel j)^2*dyadicLifetimeBound j else 0) = + (4*(dyadicLevel j)^2*dyadicLifetimeBound j) * (if dyadicBin j V then 1 else 0) := by + split_ifs <;> simp + simp_rw [he, FiniteLaw.expect_mul_left] + rw [← Finset.mul_sum] + have ho := mul_le_mul_of_nonneg_left (dyadic_bin_occupation r hr j M U) + (show 0 ≤ 4*(dyadicLevel j)^2*dyadicLifetimeBound j by + positivity [dyadicLifetimeBound_nonneg j]) + apply ho.trans_eq + have hp : A^(6/5 : ℝ) = A^(1/5 : ℝ)*A := by + have h := Real.rpow_add hA (1/5 : ℝ) 1 + norm_num at h + exact h + change (4*(dyadicLevel j)^2*A^(1/5 : ℝ))*A = 4*((dyadicLevel j)^2*A^(6/5 : ℝ)) + rw [hp] + ring + +theorem maskDelayMoment_of_obstruction {n : ℕ} [NeZero n] + (r : ℝ≥0) (hr : (1 : ℝ)/8 ≤ r) (M : ℕ) + (P : FiniteLaw (Finset (DeletionCandidate n))) (ε : ℝ) + (hP : ∀ U, P.expect (fun I => if U.Nonempty ∧ U ∩ I = ∅ then 1 else 0) ≤ + (poissonKillProbability U 2 60 + ε)^2) + (U : Finset (DeletionCandidate n)) : + P.expect (fun I => maskDelayMoment r 3 M U I) ≤ + (48/5 : ℝ) * (∑' j, dyadicMomentCoefficient j) + + (12/5 : ℝ)*ε^2*(M : ℝ)^(6/5 : ℝ) := by + let J := (Finset.univ.sup (fun V : Finset (DeletionCandidate n) => dyadicIndex V))+1 + have hJ (V : Finset (DeletionCandidate n)) : dyadicIndex V < J := by + exact Nat.lt_succ_of_le (Finset.le_sup (f := fun V : Finset (DeletionCandidate n) => + dyadicIndex V) (Finset.mem_univ V)) + let c : ℕ → Finset (DeletionCandidate n) → ℝ := fun j V => + if dyadicBin j V then 4*(dyadicLevel j)^2*dyadicLifetimeBound j else 0 + let B : ℝ := (12/5 : ℝ)*ε^2*(M : ℝ)^(1/5 : ℝ) + have ho := maskDelayMoment_occupation r 3 M P (dyadicCapBound M) + (fun m hm V => dyadicCapBound_controls r hr (m+1) M (by omega) V) U + have hc (V : Finset (DeletionCandidate n)) : + (6/5 : ℝ) * P.expect (fun I => if V.Nonempty ∧ V ∩ I = ∅ then 1 else 0) * + dyadicCapBound M V ≤ (12/5 : ℝ)*(∑ j ∈ Finset.range J, c j V)+B := + obstruction_cost_bound P M J ε V (hJ V) (hP V) + apply ho.trans + calc + _ ≤ ∑ t ∈ Finset.range M, (candidateBlock (r*t) 3 U).expect + (fun V => (12/5 : ℝ)*(∑ j ∈ Finset.range J, c j V)+B) := + Finset.sum_le_sum (fun t _ => FiniteLaw.expect_mono _ hc) + _ = (12/5 : ℝ)*(∑ j ∈ Finset.range J, + ∑ t ∈ Finset.range M, (candidateBlock (r*t) 3 U).expect (c j)) + (M : ℝ)*B := by + simp only [FiniteLaw.expect_add, FiniteLaw.expect_mul_left, FiniteLaw.expect_sum, + FiniteLaw.expect_const, Finset.sum_add_distrib, Finset.sum_const, Finset.card_range, + nsmul_eq_mul, ← Finset.mul_sum] + rw [Finset.sum_comm] + _ ≤ (12/5 : ℝ)*(∑ j ∈ Finset.range J, 4*dyadicMomentCoefficient j) + (M : ℝ)*B := by + gcongr with j hj + exact dyadic_bin_cost_occupation r hr j M U + _ ≤ (48/5 : ℝ)*(∑' j, dyadicMomentCoefficient j) + (12/5 : ℝ)*ε^2*(M : ℝ)^(6/5 : ℝ) := by + have hs := dyadicMomentCoefficient_summable.sum_le_tsum (Finset.range J) + (fun j _ => dyadicMomentCoefficient_nonneg j) + rw [← Finset.mul_sum] + have hp : (M : ℝ)*(M : ℝ)^(1/5 : ℝ) = (M : ℝ)^(6/5 : ℝ) := by + by_cases hM : M = 0 + · subst M + norm_num + · have h := (Real.rpow_add (by positivity : (0 : ℝ) < M) 1 (1/5 : ℝ)).symm + norm_num at h + exact h + dsimp only [B] + nlinarith + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PacketExpressions.lean b/lean/OAI/Probability/SATComputability/PacketExpressions.lean new file mode 100644 index 0000000000000000000000000000000000000000..00a821b9ab2d6e8f2d9eed795d11d18f909f15fb --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PacketExpressions.lean @@ -0,0 +1,170 @@ +import OAI.Probability.SATComputability.HierarchyEvaluator +import OAI.Probability.SATComputability.CavityExpressions +import OAI.Probability.DilutedSpin.FiniteEncoding + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass Nat.Partrec FiniteArithmetic RapidForcing.EffectiveArithmetic +local instance packetExpressionsRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +noncomputable def fieldExpression (cs : List Code) (i : ℕ) : Code := + rationalExpression (decodedRational (cs[i]?.getD .zero)) + +@[fun_prop] theorem fieldExpression_computable : + Computable (fun p : List Code × ℕ => fieldExpression p.1 p.2) := by + have hget : Computable (fun p : List Code × ℕ => p.1[p.2]?.getD Code.zero) := + (Primrec.option_getD.comp (Primrec.list_getElem?.comp Primrec.fst Primrec.snd) + (Primrec.const Code.zero)).to_comp + unfold fieldExpression + fun_prop + +theorem fieldExpression_value (cs : List Code) (i : ℕ) : + expressionValue (fieldExpression cs i) = (decodedRational (cs[i]?.getD .zero) : ℝ) := by + exact rationalExpression_value _ + +attribute [local irreducible] fieldExpression edgeExpression siteExpression trialExpression + +noncomputable def fieldVector (k : ℕ) (cs : List Code) : Fin k → Code := + fun i => fieldExpression cs i.val + +@[fun_prop] theorem fieldVector_computable (k : ℕ) : Computable (fieldVector k) := by + apply computable_fin_lambda + intro i + exact fieldExpression_computable.comp (Computable.id.pair (Computable.const i.val)) + +attribute [local irreducible] fieldVector + +noncomputable def edgeLeaf (p : ℚ × (Fin 3 → Bool)) (cs : List Code) : Code := + edgeExpression p.1 p.2 (fieldVector 3 cs) + +attribute [local irreducible] edgeLeaf + +@[fun_prop] theorem edgeLeaf_computable : + Computable (fun p : (ℚ × (Fin 3 → Bool)) × List Code => edgeLeaf p.1 p.2) := by + have hf := (fieldVector_computable 3).comp + (show Computable (fun p : (ℚ × (Fin 3 → Bool)) × List Code => p.2) from Computable.snd) + unfold edgeLeaf + exact edgeExpression_comp _ _ _ (by fun_prop) (by fun_prop) hf + +theorem edgeLeaf_value (p : ℚ × (Fin 3 → Bool)) (cs : List Code) : + expressionValue (edgeLeaf p cs) = + Real.log (edge (satInteraction (p.1 : ℝ) p.2) (leafFields 3 cs)) := by + simp only [edgeLeaf, edgeExpression_value, fieldVector, fieldExpression_value] + rfl + +noncomputable def edgeTrialExpression (β : ℚ) (J : Fin 3 → Bool) + (root : Code) (ms : List ℚ) : Code := trialExpression edgeLeaf (β,J) root ms 3 + +@[fun_prop] theorem edgeTrialExpression_computable : + Computable (fun p : ℚ × (Fin 3 → Bool) × Code × List ℚ => + edgeTrialExpression p.1 p.2.1 p.2.2.1 p.2.2.2) := by + have ht := trialExpression_computable edgeLeaf edgeLeaf_computable + unfold edgeTrialExpression + exact ht.comp (g := fun p : ℚ × (Fin 3 → Bool) × Code × List ℚ => + ((p.1,p.2.1),p.2.2.1,p.2.2.2,3)) (by fun_prop) + +theorem edgeTrialExpression_value (β : ℚ) (J : Fin 3 → Bool) + (root : Code) (ms : List ℚ) : + expressionValue (edgeTrialExpression β J root ms) = + trialLog ms.length (rationalTreeValue (ms.length+1) (decodeTree (ms.length+1) root)) + (fun i => (ms.get i : ℝ)) (fun x => Real.log (edge (satInteraction (β : ℝ) J) x)) := by + exact trialExpression_eq_trialLog edgeLeaf (β,J) _ (fun cs => edgeLeaf_value _ cs) root ms + +noncomputable def siteData (signs : List (Fin 3 → Bool)) (cs : List Code) : + List SiteExpressionDatum := + (List.range signs.length).map (fun j => + (signs[j]?.getD (fun _ => false), fun i : Fin 2 => fieldExpression cs (2*j+i.val))) + +attribute [local irreducible] siteData + +@[fun_prop] theorem siteData_computable : + Computable (fun p : List (Fin 3 → Bool) × List Code => siteData p.1 p.2) := by + have hget : Computable (fun p : List (Fin 3 → Bool) × ℕ => + p.1[p.2]?.getD (fun _ => false)) := + (Primrec.option_getD.comp (Primrec.list_getElem?.comp Primrec.fst Primrec.snd) + (Primrec.const (fun _ : Fin 3 => false))).to_comp + unfold siteData + apply computable_list_map + (f := fun p : List (Fin 3 → Bool) × List Code => List.range p.1.length) + (g := fun p j => (p.1[j]?.getD (fun _ => false), + fun i : Fin 2 => fieldExpression p.2 (2*j+i.val))) (by fun_prop) + unfold Computable₂ + apply Computable.pair + · exact hget.comp (g := fun p : (List (Fin 3 → Bool) × List Code) × ℕ => + (p.1.1,p.2)) ((Computable.fst.comp Computable.fst).pair Computable.snd) + · apply computable_fin_lambda + intro i + exact fieldExpression_computable.comp + (g := fun p : (List (Fin 3 → Bool) × List Code) × ℕ => (p.1.2,2*p.2+i.val)) + ((Computable.snd.comp Computable.fst).pair (by fun_prop)) + +theorem siteData_ofFn (signs : List (Fin 3 → Bool)) (cs : List Code) : + siteData signs cs = List.ofFn (fun j : Fin signs.length => + (signs.get j, fun i : Fin 2 => fieldExpression cs (2*j.val+i.val))) := by + apply List.ext_getElem + · simp [siteData] + · intro i hi hj + have hi' : i < signs.length := by simpa only [List.length_ofFn] using hj + simp [siteData, hi'] + +noncomputable def siteLeaf (p : ℚ × List (Fin 3 → Bool)) (cs : List Code) : Code := + siteExpression p.1 (siteData p.2 cs) + +attribute [local irreducible] siteLeaf + +@[fun_prop] theorem siteLeaf_computable : + Computable (fun p : (ℚ × List (Fin 3 → Bool)) × List Code => siteLeaf p.1 p.2) := by + have hd : Computable (fun p : (ℚ × List (Fin 3 → Bool)) × List Code => + siteData p.1.2 p.2) := + siteData_computable.comp + (g := fun p : (ℚ × List (Fin 3 → Bool)) × List Code => (p.1.2,p.2)) + ((Computable.snd.comp Computable.fst).pair Computable.snd) + have hb : Computable (fun p : (ℚ × List (Fin 3 → Bool)) × List Code => p.1.1) := + Computable.fst.comp Computable.fst + unfold siteLeaf + exact siteExpression_comp _ _ hb hd + +theorem siteLeaf_value (p : ℚ × List (Fin 3 → Bool)) (cs : List Code) : + expressionValue (siteLeaf p cs) = + siteLog (fun j : Fin p.2.length => satSample (p.1 : ℝ) (p.2.get j)) 0 + (fun i => leafFields (p.2.length*2) cs (finProdFinEquiv i)) := by + rw [siteLeaf, siteData_ofFn, siteExpression_ofFn_value] + simp only [fieldExpression_value] + have he : (fun i : Fin p.2.length × Fin 2 => + (decodedRational (cs[2*i.1.val+i.2.val]?.getD .zero) : ℝ)) = + (fun i => leafFields (p.2.length*2) cs (finProdFinEquiv i)) := by + funext i + change (decodedRational (cs[2*i.1.val+i.2.val]?.getD .zero) : ℝ) = + (decodedRational (cs[i.2.val+2*i.1.val]?.getD .zero) : ℝ) + rw [Nat.add_comm (2*i.1.val)] + rw [he] + +noncomputable def siteTrialExpression (β : ℚ) (signs : List (Fin 3 → Bool)) + (root : Code) (ms : List ℚ) : Code := + trialExpression siteLeaf (β,signs) root ms (signs.length*2) + +@[fun_prop] theorem siteTrialExpression_computable : + Computable (fun p : ℚ × List (Fin 3 → Bool) × Code × List ℚ => + siteTrialExpression p.1 p.2.1 p.2.2.1 p.2.2.2) := by + have ht := trialExpression_computable siteLeaf siteLeaf_computable + unfold siteTrialExpression + exact ht.comp (g := fun p : ℚ × List (Fin 3 → Bool) × Code × List ℚ => + ((p.1,p.2.1),p.2.2.1,p.2.2.2,p.2.1.length*2)) (by fun_prop) + +theorem siteTrialExpression_value (β : ℚ) (signs : List (Fin 3 → Bool)) + (root : Code) (ms : List ℚ) : + expressionValue (siteTrialExpression β signs root ms) = + trialLog ms.length (rationalTreeValue (ms.length+1) (decodeTree (ms.length+1) root)) + (fun i => (ms.get i : ℝ)) + (siteLog (fun j : Fin signs.length => satSample (β : ℝ) (signs.get j)) 0) := by + rw [siteTrialExpression, trialExpression_eq_trialLog siteLeaf (β,signs) + (fun x => siteLog (fun j : Fin signs.length => satSample (β : ℝ) (signs.get j)) 0 + (fun i => x (finProdFinEquiv i))) + (fun cs => siteLeaf_value (β,signs) cs)] + exact trialLog_reindex finProdFinEquiv ms.length _ _ _ + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PhysicalExpressions.lean b/lean/OAI/Probability/SATComputability/PhysicalExpressions.lean new file mode 100644 index 0000000000000000000000000000000000000000..5c9af6843d82e2953301f726b217b3cf9fb0d155 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PhysicalExpressions.lean @@ -0,0 +1,92 @@ +import OAI.Probability.SATComputability.WeightedExpressions +import OAI.Probability.SATComputability.SATModel + +namespace OAI + +namespace FixedClauseThreshold.Computability.FiniteArithmetic + +open Nat.Partrec DilutedSpinGlass RapidForcing.EffectiveArithmetic +open scoped BigOperators +local instance physicalExpressionsRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +noncomputable def logTwoExpression : Code := positiveLogExpression .left + +theorem logTwoExpression_value : expressionValue logTwoExpression = Real.log 2 := by + norm_num [logTwoExpression, positiveLogExpression_value, expressionValue] + +noncomputable def binaryLogMeanExpression (x y : Code) : Code := + logMixtureExpression [(1/2, x), (1/2, y)] + +noncomputable def binaryLogSumExpression (x y : Code) : Code := + .pair logTwoExpression (binaryLogMeanExpression x y) + +@[fun_prop] theorem binaryLogMeanExpression_computable : + Computable (fun p : Code × Code => binaryLogMeanExpression p.1 p.2) := by + unfold binaryLogMeanExpression + fun_prop + +@[fun_prop] theorem binaryLogSumExpression_computable : + Computable (fun p : Code × Code => binaryLogSumExpression p.1 p.2) := by + unfold binaryLogSumExpression + fun_prop + +theorem binaryLogMeanExpression_value (x y : Code) : + expressionValue (binaryLogMeanExpression x y) = + Real.log ((Real.exp (expressionValue x)+Real.exp (expressionValue y))/2) := by + rw [binaryLogMeanExpression, logMixtureExpression_value] + · congr 1 + norm_num + ring + · intro b hb + simp only [List.mem_cons, List.not_mem_nil, or_false] at hb + rcases hb with rfl | rfl <;> norm_num + · norm_num + +theorem binaryLogSumExpression_value (x y : Code) : + expressionValue (binaryLogSumExpression x y) = + Real.log (Real.exp (expressionValue x)+Real.exp (expressionValue y)) := by + rw [binaryLogSumExpression, expressionValue, logTwoExpression_value, + binaryLogMeanExpression_value, Real.log_div (by positivity) (by norm_num)] + ring + +theorem exp_binaryLogSumExpression (x y : Code) : + Real.exp (expressionValue (binaryLogSumExpression x y)) = + Real.exp (expressionValue x)+Real.exp (expressionValue y) := by + rw [binaryLogSumExpression_value, Real.exp_log (by positivity)] + +def signedExpression (x : Code) (b : Bool) : Code := if b then x else .rfind' x + +@[fun_prop] theorem signedExpression_computable : + Computable (fun p : Code × Bool => signedExpression p.1 p.2) := by + unfold signedExpression + fun_prop + +theorem signedExpression_value (x : Code) (b : Bool) : + expressionValue (signedExpression x b) = expressionValue x * spin b := by + cases b <;> simp [signedExpression, spin, expressionValue] + +noncomputable def logQExpression (x : Code) (b : Bool) : Code := + .pair (signedExpression x b) (.rfind' (binaryLogSumExpression (.rfind' x) x)) + +@[fun_prop] theorem logQExpression_computable : + Computable (fun p : Code × Bool => logQExpression p.1 p.2) := by + unfold logQExpression + fun_prop + +theorem exp_logQExpression (x : Code) (b : Bool) : + Real.exp (expressionValue (logQExpression x b)) = q (expressionValue x) b := by + have hp : 0 < Real.exp (-expressionValue x)+Real.exp (expressionValue x) := by positivity + rw [logQExpression, expressionValue, signedExpression_value, + show expressionValue (.rfind' (binaryLogSumExpression (.rfind' x) x)) = + -expressionValue (binaryLogSumExpression (.rfind' x) x) from rfl, + binaryLogSumExpression_value] + change Real.exp (expressionValue x * spin b + + -Real.log (Real.exp (-expressionValue x)+Real.exp (expressionValue x))) = _ + rw [← sub_eq_add_neg, Real.exp_sub, Real.exp_log hp] + simp only [q, Real.cosh_eq] + congr 1 + ring + +end FixedClauseThreshold.Computability.FiniteArithmetic + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonBlockBound.lean b/lean/OAI/Probability/SATComputability/PoissonBlockBound.lean new file mode 100644 index 0000000000000000000000000000000000000000..fe9180fc5eb4971f3ddd803cd4685a8f9f2c8240 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonBlockBound.lean @@ -0,0 +1,96 @@ +import OAI.Probability.SATComputability.PoissonKernel + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory Filter +open scoped NNReal + +theorem poisson_count_lower_half {M : ℕ} (hM : 0 < M) (μ : ℝ≥0) + (hμ : 4 * (M : ℝ) ≤ μ) : + (1 : ℝ)/2 ≤ ∫ m : ℕ, if M ≤ m then (1 : ℝ) else 0 ∂poissonMeasure μ := by + have hMn : (1 : ℝ) ≤ M := by exact_mod_cast hM + have hden : 0 < (μ : ℝ) - M := by linarith + have hint : Integrable (fun m : ℕ => if m < M then (1 : ℝ) else 0) + (poissonMeasure μ) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun m => by split <;> norm_num) + have hvar : Integrable (fun m : ℕ => ((m : ℝ)-(μ : ℝ))^2) (poissonMeasure μ) := by + convert ((poisson_integrable_count_sq μ).sub + ((poisson_integrable_count μ).const_mul (2*(μ : ℝ)))).add + (integrable_const ((μ : ℝ)^2)) using 1 + funext m + dsimp only [Pi.add_apply, Pi.sub_apply] + ring + have htail : (∫ m : ℕ, if m < M then (1 : ℝ) else 0 ∂poissonMeasure μ) ≤ + (μ : ℝ) / ((μ : ℝ)-M)^2 := by + calc + _ ≤ ∫ m : ℕ, ((m : ℝ)-(μ : ℝ))^2 / ((μ : ℝ)-M)^2 ∂poissonMeasure μ := by + apply integral_mono hint (hvar.div_const _) + intro m + dsimp only + split_ifs with hm + · have hm' : (m : ℝ) < M := by exact_mod_cast hm + apply (le_div_iff₀ (sq_pos_of_pos hden)).mpr + nlinarith [sq_nonneg ((m : ℝ)-(μ : ℝ))] + · positivity + _ = _ := by rw [integral_div, poisson_variance] + have hnum : (μ : ℝ) / ((μ : ℝ)-M)^2 ≤ (1 : ℝ)/2 := by + apply (div_le_iff₀ (sq_pos_of_pos hden)).mpr + have hfour : (4 : ℝ) ≤ μ := by linarith + have hproduct := mul_nonneg (show (0 : ℝ) ≤ μ-4*M by linarith) + (show (0 : ℝ) ≤ μ+2*M-2 by linarith) + have hMproduct := mul_nonneg (show (0 : ℝ) ≤ M-1 by linarith) + (show (0 : ℝ) ≤ 9*M by positivity) + nlinarith + have he : (∫ m : ℕ, if M ≤ m then (1 : ℝ) else 0 ∂poissonMeasure μ) = + 1 - ∫ m : ℕ, if m < M then (1 : ℝ) else 0 ∂poissonMeasure μ := by + have hp (m : ℕ) : (if M ≤ m then (1 : ℝ) else 0) = + 1 - (if m < M then (1 : ℝ) else 0) := by + by_cases h : M ≤ m <;> simp [h, Nat.not_lt.mpr, Nat.lt_of_not_ge] + simp_rw [hp] + rw [integral_sub (integrable_const 1) hint] + simp + rw [he] + linarith + +theorem poisson_block_kill_lower {n M : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k : ℕ) (hM : 0 < M) (μ : ℝ≥0) + (hμ : 4 * (M : ℝ) ≤ μ) : + batchKillProbability U k M / 2 ≤ poissonKillProbability U k μ := by + have hi : Integrable (fun m => batchKillProbability U k m) (poissonMeasure μ) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun m => abs_le.mpr + ⟨by linarith [batchKillProbability_nonneg U k m], batchKillProbability_le_one U k m⟩) + have hj : Integrable (fun m : ℕ => if M ≤ m then (1 : ℝ) else 0) + (poissonMeasure μ) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun m => by split <;> norm_num) + have h := integral_mono (hj.const_mul (batchKillProbability U k M)) hi (fun m => by + dsimp only + split_ifs with hm + · simpa using batchKillProbability_mono U k hm + · simpa using batchKillProbability_nonneg U k m) + rw [integral_const_mul] at h + have hl := mul_le_mul_of_nonneg_left (poisson_count_lower_half hM μ hμ) + (batchKillProbability_nonneg U k M) + unfold poissonKillProbability + linarith + +theorem poisson_two_to_three_block {n L d : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (hd : 0 < d) (hL : 0 < L) + {q : ℝ} (hq : q ≤ poissonKillProbability U 2 60) + (htail : Real.exp 60 / (2 : ℝ)^L ≤ q/4) + (hrepl : (L : ℝ)/(d : ℝ)^2 ≤ q/4) + (μ : ℝ≥0) (hμ : 4 * (L*d : ℕ) ≤ (μ : ℝ)) : + q/4 ≤ poissonKillProbability U 3 μ := by + have ht := poissonKillProbability_truncate U 2 L 60 + have hr := relaxed_sequential_replacement U hd L + have hb := poisson_block_kill_lower U 3 (Nat.mul_pos hL hd) μ hμ + norm_num only [NNReal.coe_ofNat] at ht + linarith + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonCountBounds.lean b/lean/OAI/Probability/SATComputability/PoissonCountBounds.lean new file mode 100644 index 0000000000000000000000000000000000000000..e993e09f03e95287336f45042a982d35e028da85 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonCountBounds.lean @@ -0,0 +1,60 @@ +import OAI.Probability.DilutedSpin.MarkedPoisson + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology + +theorem poisson_upper_deviation (r : ℝ≥0) {d : ℝ} (hd : 0 < d) : + (∫ m : ℕ, (if (r : ℝ) + d < m then (1 : ℝ) else 0) ∂poissonMeasure r) ≤ + (r : ℝ) / d^2 := by + have hi : Integrable (fun m : ℕ => if (r : ℝ)+d < m then (1 : ℝ) else 0) + (poissonMeasure r) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact ae_of_all _ (fun m => by split <;> norm_num) + have hs : Integrable (fun m : ℕ => ((m : ℝ)-(r : ℝ))^2) (poissonMeasure r) := + ((memLp_two_iff_integrable_sq (measurable_of_countable + (fun m : ℕ => (m : ℝ))).aestronglyMeasurable).mpr + (poisson_integrable_count_sq r) |>.sub (memLp_const (r : ℝ))).integrable_sq + have h := integral_mono hi (hs.div_const (d^2)) (fun m => show + (if (r : ℝ)+d < m then (1 : ℝ) else 0) ≤ ((m : ℝ)-(r : ℝ))^2 / d^2 from by + split_ifs with hm + · apply (le_div_iff₀ (sq_pos_of_pos hd)).mpr + nlinarith + · exact div_nonneg (sq_nonneg _) (sq_nonneg _)) + rw [integral_div, poisson_variance] at h + exact h + +theorem poisson_density_upper_tail {a : ℝ≥0} {b : ℝ} (hab : (a : ℝ) < b) + {n : ℕ} (hn : 0 < n) : + (∫ m : ℕ, (if b*n < m then (1 : ℝ) else 0) ∂poissonMeasure (a*n)) ≤ + (a : ℝ) / ((b-a)^2*n) := by + have hn' : (0 : ℝ) < n := by exact_mod_cast hn + have hd : 0 < (b-a)*(n : ℝ) := mul_pos (sub_pos.mpr hab) hn' + have h := poisson_upper_deviation (a*n) hd + have he : (a*n : ℝ≥0) + (b-(a : ℝ))*(n : ℝ) = b*n := by + push_cast + ring + rw [he] at h + convert h using 1 + push_cast + field_simp + +theorem poisson_density_upper_tail_tendsto {a : ℝ≥0} {b : ℝ} (hab : (a : ℝ) < b) : + Tendsto (fun n : ℕ => ∫ m : ℕ, (if b*n < m then (1 : ℝ) else 0) + ∂poissonMeasure (a*n)) atTop (nhds 0) := by + have hlim : Tendsto (fun n : ℕ => (a : ℝ) / ((b-a)^2*n)) atTop (nhds 0) := by + simpa only [mul_zero] using + ((tendsto_inv_atTop_zero.comp tendsto_natCast_atTop_atTop).const_mul + ((a : ℝ)/(b-a)^2)).congr + (fun n => by simp only [Function.comp_apply, div_eq_mul_inv, mul_inv]; ring) + apply squeeze_zero' (Eventually.of_forall (fun n => integral_nonneg (fun m => by positivity))) + _ hlim + filter_upwards [eventually_gt_atTop 0] with n hn + exact poisson_density_upper_tail hab hn + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonCountProducts.lean b/lean/OAI/Probability/SATComputability/PoissonCountProducts.lean new file mode 100644 index 0000000000000000000000000000000000000000..6bae379773500d2ad22501a55a33460d888e9194 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonCountProducts.lean @@ -0,0 +1,116 @@ +import OAI.Probability.SATComputability.FinitePushforward +import OAI.Probability.DilutedSpin.FiniteEncoding + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal Classical + +noncomputable def poissonCountLaw (A : Type*) [Fintype A] (r : ℝ≥0) : Measure (A → ℕ) := + Measure.pi (fun _ : A => poissonMeasure r) + +instance poissonCountLaw_probability (A : Type*) [Fintype A] (r : ℝ≥0) : + IsProbabilityMeasure (poissonCountLaw A r) := by unfold poissonCountLaw; infer_instance + +theorem poissonCountLaw_equiv {A B : Type*} [Fintype A] [Fintype B] + (e : A ≃ B) (r : ℝ≥0) (f : (B → ℕ) → ℝ) : + (∫ c, f (fun b => c (e.symm b)) ∂poissonCountLaw A r) = + ∫ c, f c ∂poissonCountLaw B r := by + have hp (c : A → ℕ) : (MeasurableEquiv.piCongrLeft (fun _ : B => ℕ) e) c = + fun b => c (e.symm b) := by + funext b + change (Equiv.piCongrLeft (fun _ : B => ℕ) e) c b = _ + rw [Equiv.piCongrLeft_apply] + simp + simpa only [poissonCountLaw, hp] using + (measurePreserving_piCongrLeft (fun _ : B => poissonMeasure r) e).integral_comp' f + +theorem poissonCountLaw_sum {A B : Type*} [Fintype A] [Fintype B] + (r : ℝ≥0) (f : (A ⊕ B → ℕ) → ℝ) (C : ℝ) (hC : ∀ c, |f c| ≤ C) : + (∫ c, f c ∂poissonCountLaw (A ⊕ B) r) = + ∫ a, ∫ b, f (Sum.elim a b) ∂poissonCountLaw B r ∂poissonCountLaw A r := by + have he := (measurePreserving_sumPiEquivProdPi_symm + (fun _ : A ⊕ B => poissonMeasure r)).integral_comp' f + unfold poissonCountLaw + rw [← he] + change (∫ p : (A → ℕ) × (B → ℕ), f (Sum.elim p.1 p.2) + ∂(poissonCountLaw A r).prod (poissonCountLaw B r)) = _ + apply integral_prod + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable C + filter_upwards [] with p + simpa only [Real.norm_eq_abs] using hC (Sum.elim p.1 p.2) + +theorem poisson_zero_eq_dirac : poissonMeasure 0 = Measure.dirac (0 : ℕ) := by + apply Measure.ext_of_singleton + intro n + rw [poissonMeasure_singleton] + cases n <;> simp + +theorem poissonCountLaw_hasLaw_sum {A : Type*} [Fintype A] + (r : A → ℝ≥0) : + HasLaw (fun c : A → ℕ => ∑ a, c a) (poissonMeasure (∑ a, r a)) + (Measure.pi (fun a => poissonMeasure (r a))) := by + let μ := Measure.pi (fun a => poissonMeasure (r a)) + have hi : iIndepFun (fun a (c : A → ℕ) => c a) μ := + iIndepFun_pi (fun a => measurable_id.aemeasurable) + have hcoord (a : A) : HasLaw (fun c : A → ℕ => c a) (poissonMeasure (r a)) μ := + ⟨(measurable_pi_apply a).aemeasurable, (measurePreserving_eval _ a).map_eq⟩ + have hs (S : Finset A) : HasLaw (fun c : A → ℕ => ∑ a ∈ S, c a) + (poissonMeasure (∑ a ∈ S, r a)) μ := by + induction S using Finset.induction_on with + | empty => + simp only [Finset.sum_empty, poisson_zero_eq_dirac] + exact ⟨measurable_const.aemeasurable, by simp⟩ + | @insert a S ha ih => + have hind := (hi.indepFun_finsetSum_of_notMem (fun a => measurable_pi_apply a) ha).symm + have he : (∑ j ∈ S, fun c : A → ℕ => c j) = (fun c => ∑ j ∈ S, c j) := by + funext c + simp only [Finset.sum_apply] + rw [he] at hind + have h := hind.hasLaw_add_poissonMeasure (hcoord a) ih + have hf : ((fun c : A → ℕ => c a) + (fun c => ∑ j ∈ S, c j)) = + (fun c => c a + ∑ j ∈ S, c j) := rfl + rw [hf] at h + simpa only [Finset.sum_insert ha] using h + exact hs Finset.univ + +theorem poissonCountLaw_sum_integral {A : Type*} [Fintype A] + (r : A → ℝ≥0) (f : ℕ → ℝ) : + (∫ c : A → ℕ, f (∑ a, c a) ∂Measure.pi (fun a => poissonMeasure (r a))) = + ∫ k, f k ∂poissonMeasure (∑ a, r a) := + (poissonCountLaw_hasLaw_sum r).integral_comp (measurable_of_countable f).aestronglyMeasurable + +theorem poissonCountLaw_embedding {A B : Type*} [Fintype A] [Fintype B] + (e : B → A) (he : Function.Injective e) (r : ℝ≥0) : + Measure.map (fun c : A → ℕ => c ∘ e) (poissonCountLaw A r) = + poissonCountLaw B r := by + have hi : iIndepFun (fun a (c : A → ℕ) => c a) (poissonCountLaw A r) := + iIndepFun_pi (fun _ => measurable_id.aemeasurable) + have h := (hi.precomp he).map_fun_eq_pi_map + (fun b => (measurable_pi_apply (e b)).aemeasurable) + simpa only [Function.comp_def, poissonCountLaw, + (measurePreserving_eval (fun _ : A => poissonMeasure r) _).map_eq] using h + +theorem poissonCountLaw_embedding_integral {A B : Type*} [Fintype A] [Fintype B] + (e : B → A) (he : Function.Injective e) (r : ℝ≥0) (f : (B → ℕ) → ℝ) : + (∫ c, f (c ∘ e) ∂poissonCountLaw A r) = ∫ c, f c ∂poissonCountLaw B r := by + rw [← poissonCountLaw_embedding e he r] + exact (integral_map (measurable_of_countable _).aemeasurable + (measurable_of_countable f).aestronglyMeasurable).symm + +theorem poissonCountLaw_row_sums {A B : Type*} [Fintype A] [Fintype B] + (r : ℝ≥0) : + Measure.map (fun c : A → B → ℕ => fun a => ∑ b, c a b) + (Measure.pi (fun _ : A => poissonCountLaw B r)) = + poissonCountLaw A (Fintype.card B * r) := by + rw [Measure.pi_map_pi (fun _ => (measurable_of_countable _).aemeasurable)] + congr 1 + funext a + simpa only [poissonCountLaw, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] using + (poissonCountLaw_hasLaw_sum (fun _ : B => r)).map_eq + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonCounts.lean b/lean/OAI/Probability/SATComputability/PoissonCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..26927250008e0e04e49030e7db10434d41bf697e --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonCounts.lean @@ -0,0 +1,63 @@ +import OAI.Probability.SATComputability.PoissonMarks + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped NNReal ENNReal BigOperators + +theorem compoundPoisson_dirac_nsmul {E : Type*} + [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] (r : ℝ≥0) (v : E) : + compoundPoisson r (Measure.dirac v) = + Measure.map (fun m : ℕ => m • v) (poissonMeasure r) := by + rw [compoundPoisson, poissonMeasure, + Measure.map_sum (measurable_of_countable _).aemeasurable] + congr 1 + funext m + rw [Measure.map_smul _ (measurable_of_countable _).aemeasurable, + Measure.map_dirac' (measurable_of_countable _)] + congr 1 + have ha : ∀ᵐ x ∂Measure.pi (fun _ : Fin m => Measure.dirac v), ∀ i, x i = v := + Filter.eventually_all.mpr (fun i => (Measure.tendsto_eval_ae_ae + (μ := fun _ : Fin m => Measure.dirac v) (i := i)).eventually + (show ∀ᵐ x ∂Measure.dirac v, x = v from by simp)) + rw [Measure.map_congr (ha.mono (fun x hx => + show (∑ i, x i) = m • v by simp only [hx, Finset.sum_const, Finset.card_univ, Fintype.card_fin]))] + simp + +theorem uniform_poisson_count_vector {A : Type*} [Fintype A] [Nonempty A] + [DecidableEq A] [MeasurableSpace A] [MeasurableSingletonClass A] + (r : ℝ≥0) : + compoundPoisson r (Measure.map (fun a : A => Pi.single a (1 : ℝ)) (finiteUniform A)) = + Measure.map (fun counts : A → ℕ => fun a => (counts a : ℝ)) + (Measure.pi (fun _ : A => poissonMeasure (r / Fintype.card A))) := by + rw [uniform_poisson_marks] + simp_rw [compoundPoisson_dirac_nsmul] + rw [← Measure.pi_map_pi (μ := fun _ : A => poissonMeasure (r / Fintype.card A)) + (f := fun a (m : ℕ) => m • (Pi.single a (1 : ℝ) : A → ℝ)) (fun a : A => + (measurable_of_countable (fun m : ℕ => m • (Pi.single a (1 : ℝ) : A → ℝ))).aemeasurable)] + rw [Measure.map_map (by fun_prop) (by fun_prop)] + congr 1 + funext counts a + simp [Finset.sum_apply, Pi.single_apply] + +theorem uniform_poisson_weighted_counts {A E : Type*} [Fintype A] [Nonempty A] + [MeasurableSpace A] [MeasurableSingletonClass A] + [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] [CompleteSpace E] (r : ℝ≥0) (V : A → E) : + compoundPoisson r (Measure.map V (finiteUniform A)) = + Measure.map (fun counts : A → ℕ => ∑ a, counts a • V a) + (Measure.pi (fun _ : A => poissonMeasure (r / Fintype.card A))) := by + rw [uniform_poisson_marks] + simp_rw [compoundPoisson_dirac_nsmul] + rw [← Measure.pi_map_pi (μ := fun _ : A => poissonMeasure (r / Fintype.card A)) + (f := fun a (m : ℕ) => m • V a) (fun a => + (measurable_of_countable (fun m : ℕ => m • V a)).aemeasurable)] + rw [Measure.map_map (by fun_prop) (by fun_prop)] + rfl + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonEvaluation.lean b/lean/OAI/Probability/SATComputability/PoissonEvaluation.lean new file mode 100644 index 0000000000000000000000000000000000000000..8b7ca74feb890a5d96be8fe6a839e3fa5f81ff40 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonEvaluation.lean @@ -0,0 +1,149 @@ +import OAI.Probability.SATComputability.PoissonKilling +import OAI.Probability.SATComputability.ArithmeticConstructors +import OAI.Probability.SATComputability.EffectiveSums + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal Topology +local instance poissonEvaluationRatPrimcodable : Primcodable ℚ := PeriodicLattice.RecursiveArithmetic.ratPrimcodable + +theorem nat_succ_le_two_pow_real (k : ℕ) : (k : ℝ)+1 ≤ (2 : ℝ)^k := by + induction k with + | zero => norm_num + | succ k ih => + rw [Nat.cast_succ, pow_succ] + have hk : 0 ≤ (k : ℝ) := Nat.cast_nonneg k + nlinarith + +theorem poisson_linear_integrable (r : ℝ≥0) (f : ℕ → ℝ) {C : ℝ} + (hC : 0 ≤ C) (hf : ∀ k, |f k| ≤ C*((k : ℝ)+1)) : + Integrable f (poissonMeasure r) := by + apply Integrable.mono' ((poisson_power_integrable r (by norm_num : (0 : ℝ) ≤ 2)).const_mul C) + (measurable_of_countable _).aestronglyMeasurable + filter_upwards [] with k + rw [Real.norm_eq_abs] + exact (hf k).trans (mul_le_mul_of_nonneg_left (nat_succ_le_two_pow_real k) hC) + +theorem poisson_linear_tail (r : ℝ≥0) (f : ℕ → ℝ) {C : ℝ} + (hC : 0 ≤ C) (hf : ∀ k, |f k| ≤ C*((k : ℝ)+1)) (L : ℕ) : + |(∫ k, f k ∂poissonMeasure r) - + ∑ k ∈ Finset.range L, (Real.exp (-(r : ℝ))*(r : ℝ)^k/k.factorial)*f k| ≤ + C*Real.exp (3*(r : ℝ))/(2 : ℝ)^L := by + let low : ℕ → ℝ := fun k => if k < L then f k else 0 + let high : ℕ → ℝ := fun k => if k < L then 0 else f k + have hl : Integrable low (poissonMeasure r) := + poisson_linear_integrable r low hC (fun k => by + dsimp only [low] + split_ifs + · exact hf k + · simpa using mul_nonneg hC (by positivity : (0 : ℝ) ≤ (k : ℝ)+1)) + have hh : Integrable high (poissonMeasure r) := + poisson_linear_integrable r high hC (fun k => by + dsimp only [high] + split_ifs + · simpa using mul_nonneg hC (by positivity : (0 : ℝ) ≤ (k : ℝ)+1) + · exact hf k) + have he : ∫ k, low k ∂poissonMeasure r = + ∑ k ∈ Finset.range L, (Real.exp (-(r : ℝ))*(r : ℝ)^k/k.factorial)*f k := by + rw [integral_poissonMeasure] + rw [tsum_eq_sum (s := Finset.range L)] + · apply Finset.sum_congr rfl + intro k hk + simp only [smul_eq_mul, low, ite_eq_left (Finset.mem_range.mp hk)] + · intro k hk + simp only [low, Finset.mem_range, not_lt] at hk ⊢ + simp [Nat.not_lt.mpr hk] + have hs : f = fun k => low k + high k := by + funext k + dsimp [low, high] + split_ifs <;> simp + rw [← he, hs, integral_add hl hh, add_sub_cancel_left] + apply (abs_integral_le_integral_abs).trans + calc + _ ≤ ∫ k : ℕ, C*(4 : ℝ)^k/(2 : ℝ)^L ∂poissonMeasure r := by + apply integral_mono hh.abs + (((poisson_power_integrable r (by norm_num : (0 : ℝ) ≤ 4)).const_mul C).div_const _) + intro k + dsimp only [high] + split_ifs with hk + · simp only [abs_zero] + positivity + · apply (hf k).trans + apply (mul_le_mul_of_nonneg_left (nat_succ_le_two_pow_real k) hC).trans + apply (le_div_iff₀ (by positivity)).mpr + have hp : (2 : ℝ)^L ≤ (2 : ℝ)^k := + pow_le_pow_right₀ (by norm_num) (Nat.le_of_not_gt hk) + calc + C*2^k*2^L ≤ C*2^k*2^k := mul_le_mul_of_nonneg_left hp (by positivity) + _ = C*4^k := by rw [mul_assoc, ← mul_pow]; norm_num + _ = _ := by + rw [integral_div, integral_const_mul, poisson_power_integral r (by norm_num : (0 : ℝ) ≤ 4)] + congr 2 + norm_num + ring + +@[fun_prop] theorem factorial_computable : Computable Nat.factorial := by + have h := Computable.nat_rec (f := fun n : ℕ => n) (g := fun _ => (1 : ℕ)) + (h := fun _ p => (p.1+1)*p.2) Computable.id (Computable.const 1) + (by unfold Computable₂; fun_prop) + exact h.of_eq (fun n => by induction n <;> simp_all [Nat.factorial_succ]) + +theorem exp_le_three_natCeil (q : ℚ) : + Real.exp (q : ℝ) ≤ (3 : ℝ)^⌈q⌉₊ := by + have hceil : (q : ℝ) ≤ (⌈q⌉₊ : ℕ) := by exact_mod_cast (Nat.le_ceil q) + calc + _ ≤ Real.exp (⌈q⌉₊ : ℕ) := Real.exp_le_exp.mpr hceil + _ = (Real.exp 1)^⌈q⌉₊ := by rw [← Real.exp_nat_mul]; simp + _ ≤ _ := pow_le_pow_left₀ (Real.exp_pos 1).le Real.exp_one_lt_three.le _ + +theorem effective_poisson_expectation {A : Type} [Primcodable A] + (rate : A → ℚ) (hrate : Computable rate) (hnonneg : ∀ a, 0 ≤ rate a) + (C : A → ℕ) (hC : Computable C) (f : A → ℕ → ℝ) + (hf : PeriodicLattice.CertifiedReal.Effective (fun p : A × ℕ => f p.1 p.2)) + (hbound : ∀ a k, |f a k| ≤ (C a : ℝ)*((k : ℝ)+1)) : + PeriodicLattice.CertifiedReal.Effective (fun a => + ∫ k, f a k ∂poissonMeasure ⟨rate a, by exact_mod_cast hnonneg a⟩) := by + let rateNN : A → ℝ≥0 := fun a => ⟨rate a, by exact_mod_cast hnonneg a⟩ + let g : A → ℕ → ℝ := fun a L => + ∑ k ∈ Finset.range L, (Real.exp (-(rate a : ℝ))*(rate a : ℝ)^k/k.factorial)*f a k + have ht : PeriodicLattice.CertifiedReal.Effective (fun p : A × ℕ => + (Real.exp (-(rate p.1 : ℝ))*(rate p.1 : ℝ)^p.2/p.2.factorial)*f p.1 p.2) := by + have he := (PeriodicLattice.CertifiedReal.rational + (show Computable (fun p : A × ℕ => -rate p.1) by fun_prop)).exp + have hr := PeriodicLattice.CertifiedReal.rational + (show Computable (fun p : A × ℕ => (rate p.1)^p.2/(p.2.factorial : ℚ)) by fun_prop) + convert (he.mul hr).mul hf using 1 + funext p + push_cast + ring + have hg : PeriodicLattice.CertifiedReal.Effective (fun p : A × ℕ => g p.1 p.2) := by + apply PeriodicLattice.CertifiedReal.Effective.sum_range (m := Prod.snd) + · exact ht.comp (show Computable (fun p : (A × ℕ) × ℕ => (p.1.1,p.2)) by fun_prop) + · exact Computable.snd + let tail : A × ℕ → ℚ := fun p => (C p.1 : ℚ)*3^⌈3*rate p.1⌉₊/2^p.2 + apply PeriodicLattice.CertifiedReal.effective_limit hg tail + · dsimp only [tail] + fun_prop + · intro a L + have h := poisson_linear_tail (rateNN a) (f a) (Nat.cast_nonneg (C a)) (hbound a) L + apply h.trans + have hExp := exp_le_three_natCeil (3*rate a) + change (C a : ℝ) * Real.exp (3*(rateNN a : ℝ))/(2 : ℝ)^L ≤ (tail (a,L) : ℝ) + dsimp only [tail, rateNN] + push_cast at hExp ⊢ + gcongr + exact hExp + · intro a + dsimp only [tail] + push_cast + have h := (tendsto_pow_atTop_nhds_zero_of_lt_one + (by norm_num : (0 : ℝ) ≤ 2⁻¹) (by norm_num : (2 : ℝ)⁻¹ < 1)).const_mul + ((C a : ℝ)*3^⌈3*rate a⌉₊) + simpa only [div_eq_mul_inv, inv_pow, mul_zero] using h + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonGrid.lean b/lean/OAI/Probability/SATComputability/PoissonGrid.lean new file mode 100644 index 0000000000000000000000000000000000000000..9337a8b71187f5a53cc5027512599d65863c95b0 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonGrid.lean @@ -0,0 +1,65 @@ +import OAI.Probability.SATComputability.PoissonCountProducts +import OAI.Probability.SATComputability.RestoredProcessMoment +import OAI.Probability.SATComputability.PoissonMaskCounts + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators Classical NNReal + +theorem poissonCountLaw_uncurry {A B : Type*} [Fintype A] [Fintype B] (r : ℝ≥0) : + Measure.map (fun c : A → B → ℕ => fun p : A × B => c p.1 p.2) + (Measure.pi (fun _ : A => poissonCountLaw B r)) = poissonCountLaw (A × B) r := by + apply Measure.ext_of_singleton + intro c + rw [Measure.map_apply (measurable_of_countable _) (measurableSet_singleton c)] + have he : (fun x : A → B → ℕ => fun p : A × B => x p.1 p.2) ⁻¹' {c} = + {fun a b => c (a,b)} := by + ext x + simp only [Set.mem_preimage, Set.mem_singleton_iff, funext_iff, Prod.forall] + rw [he] + simp only [poissonCountLaw, Measure.pi_singleton, Fintype.prod_prod_type] + +theorem poissonCountLaw_uncurry_integral {A B : Type*} [Fintype A] [Fintype B] + (r : ℝ≥0) (f : (A × B → ℕ) → ℝ) : + (∫ c : A → B → ℕ, f (fun p => c p.1 p.2) + ∂Measure.pi (fun _ : A => poissonCountLaw B r)) = + ∫ c, f c ∂poissonCountLaw (A × B) r := by + rw [← poissonCountLaw_uncurry r] + exact (integral_map (measurable_of_countable _).aemeasurable + (measurable_of_countable f).aestronglyMeasurable).symm + +theorem countsMask_sum {A I X : Type*} [Fintype A] [Fintype I] [Fintype X] + (mask : A → Finset X) (c : I → A → ℕ) (x : X) : + (∀ i, x ∈ countsMask mask (c i)) ↔ + x ∈ countsMask mask (fun a => ∑ i, c i a) := by + simp only [countsMask, Finset.mem_filter, Finset.mem_univ, true_and] + constructor + · intro h a + by_cases hx : x ∈ mask a + · exact Or.inr hx + · left + apply Finset.sum_eq_zero + intro i _ + exact (h i a).resolve_right hx + · intro h i a + rcases h a with hz | hx + · left + exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => Nat.zero_le (c j a))).mp hz i + (Finset.mem_univ i) + · exact Or.inr hx + +theorem frontload_countsMask {A : Type*} [Fintype A] {n M : ℕ} + (mask : A → Finset (DeletionCandidate n)) (c : Fin M → A → ℕ) : + frontloadMask (fun j => countsMask mask (c j)) = + countsMask mask (fun a => ∑ j, c j a) := by + ext x + rw [frontloadMask, mem_maskRun] + simp only [Finset.mem_univ, true_and] + exact countsMask_sum mask c x + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonKernel.lean b/lean/OAI/Probability/SATComputability/PoissonKernel.lean new file mode 100644 index 0000000000000000000000000000000000000000..4bbdd58a556870bcbf16759db55240cd155e2bb2 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonKernel.lean @@ -0,0 +1,99 @@ +import OAI.Probability.SATComputability.PoissonKilling + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal + +theorem finiteLaw_weight_le_one {Ω : Type*} [Fintype Ω] (P : FiniteLaw Ω) (x : Ω) : + P.weight x ≤ 1 := by + rw [← P.total] + exact Finset.single_le_sum (fun y _ => P.nonneg y) (Finset.mem_univ x) + +theorem poisson_weight_integrable {Ω : Type*} [Fintype Ω] + (r : ℝ≥0) (P : ℕ → FiniteLaw Ω) (x : Ω) : + Integrable (fun m => (P m).weight x) (poissonMeasure r) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun m => abs_le.mpr + ⟨by linarith [(P m).nonneg x], finiteLaw_weight_le_one (P m) x⟩) + +noncomputable def poissonMixture {Ω : Type*} [Fintype Ω] + (r : ℝ≥0) (P : ℕ → FiniteLaw Ω) : FiniteLaw Ω where + weight x := ∫ m, (P m).weight x ∂poissonMeasure r + nonneg x := integral_nonneg (fun m => (P m).nonneg x) + total := by + rw [← integral_finsetSum _ (fun x _ => poisson_weight_integrable r P x)] + simp only [(P _).total, integral_const, probReal_univ, one_smul] + +theorem poissonMixture_expect {Ω : Type*} [Fintype Ω] + (r : ℝ≥0) (P : ℕ → FiniteLaw Ω) (f : Ω → ℝ) : + (poissonMixture r P).expect f = + ∫ m, (P m).expect f ∂poissonMeasure r := by + simp only [FiniteLaw.expect, poissonMixture] + rw [integral_finsetSum _ (fun x _ => (poisson_weight_integrable r P x).mul_const (f x))] + apply Finset.sum_congr rfl + intro x _ + rw [integral_mul_const] + +theorem poissonMixture_integrable_expect {Ω : Type*} [Fintype Ω] + (r : ℝ≥0) (P : ℕ → FiniteLaw Ω) (f : Ω → ℝ) : + Integrable (fun m => (P m).expect f) (poissonMeasure r) := by + unfold FiniteLaw.expect + exact integrable_finsetSum _ (fun x _ => (poisson_weight_integrable r P x).mul_const (f x)) + +noncomputable def candidateFixedBlock {n : ℕ} [NeZero n] + (k d : ℕ) (U : Finset (DeletionCandidate n)) : FiniteLaw (Finset (DeletionCandidate n)) where + weight V := (FiniteLaw.uniform : FiniteLaw (Fin d → Fin k → SignedLiteral n)).expect + (fun cs => if candidateResidual U cs = V then 1 else 0) + nonneg V := FiniteLaw.expect_nonneg _ (fun _ => by split <;> norm_num) + total := by + classical + rw [← FiniteLaw.expect_fintype_sum] + simp + +theorem candidateFixedBlock_expect {n : ℕ} [NeZero n] + (k d : ℕ) (U : Finset (DeletionCandidate n)) + (f : Finset (DeletionCandidate n) → ℝ) : + (candidateFixedBlock k d U).expect f = (candidateStep k)^[d] f U := by + classical + rw [candidateStep_iterate] + change (∑ V, FiniteLaw.expect _ _ * f V) = _ + simp_rw [← FiniteLaw.expect_mul_right] + rw [← FiniteLaw.expect_fintype_sum] + apply FiniteLaw.expect_congr + intro cs + simp + +noncomputable def candidateBlock {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) : + FiniteLaw (Finset (DeletionCandidate n)) := + poissonMixture r (fun d => candidateFixedBlock k d U) + +theorem candidateBlock_expect {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) + (f : Finset (DeletionCandidate n) → ℝ) : + (candidateBlock r k U).expect f = + ∫ d, (candidateStep k)^[d] f U ∂poissonMeasure r := by + rw [candidateBlock, poissonMixture_expect] + simp only [candidateFixedBlock_expect] + +theorem candidateBlock_kill {n : ℕ} [NeZero n] + (r : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) : + (candidateBlock r k U).expect (fun V => if V = ∅ then 1 else 0) = + poissonKillProbability U k r := by + classical + rw [candidateBlock, poissonMixture_expect] + unfold poissonKillProbability + congr 1 + funext d + rw [candidateFixedBlock_expect, candidateStep_iterate] + unfold batchKillProbability + apply FiniteLaw.expect_congr + intro cs + exact if_congr (candidateResidual_empty_iff U cs) rfl rfl + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonKilling.lean b/lean/OAI/Probability/SATComputability/PoissonKilling.lean new file mode 100644 index 0000000000000000000000000000000000000000..0ef9b2aa2bf856471a41e385eb06308a5946d175 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonKilling.lean @@ -0,0 +1,158 @@ +import OAI.Probability.SATComputability.CandidateProcess + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal + +theorem candidateAlive_nonneg {n : ℕ} (U : Finset (DeletionCandidate n)) : + 0 ≤ candidateAlive U := by unfold candidateAlive; split <;> norm_num + +theorem candidateAlive_le_one {n : ℕ} (U : Finset (DeletionCandidate n)) : + candidateAlive U ≤ 1 := by unfold candidateAlive; split <;> norm_num + +theorem candidateStep_alive_le {n : ℕ} [NeZero n] (k : ℕ) : + candidateStep (n := n) k candidateAlive ≤ candidateAlive := by + intro U + by_cases hU : U.Nonempty + · calc + _ ≤ (FiniteLaw.uniform : FiniteLaw (Fin k → SignedLiteral n)).expect (fun _ => 1) := + FiniteLaw.expect_mono _ (fun _ => candidateAlive_le_one _) + _ = candidateAlive U := by simp [candidateAlive, hU] + · have he : U = ∅ := Finset.not_nonempty_iff_eq_empty.mp hU + simp [he, candidateStep, candidateAlive] + +theorem batchKillProbability_mono {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k : ℕ) : Monotone (batchKillProbability U k) := by + have hstep (d : ℕ) : (candidateStep k)^[d+1] candidateAlive ≤ + (candidateStep (n := n) k)^[d] candidateAlive := by + rw [Function.iterate_succ_apply] + exact (candidateStep_mono k).iterate d (candidateStep_alive_le k) + have ha : Antitone (fun d => (candidateStep k)^[d] candidateAlive U) := + antitone_nat_of_succ_le (fun d => hstep d U) + intro d e hde + rw [candidateKill_iterate, candidateKill_iterate] + linarith [ha hde] + +theorem batchKillProbability_nonneg {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k d : ℕ) : 0 ≤ batchKillProbability U k d := by + apply FiniteLaw.expect_nonneg + intro cs + split <;> norm_num + +theorem batchKillProbability_le_one {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k d : ℕ) : batchKillProbability U k d ≤ 1 := by + apply (FiniteLaw.expect_mono _ (g := fun _ => 1) ?_).trans_eq (FiniteLaw.expect_const _ _) + intro cs + split <;> norm_num + +theorem poisson_power_integrable (r : ℝ≥0) {x : ℝ} (hx : 0 ≤ x) : + Integrable (fun m : ℕ => x^m) (poissonMeasure r) := by + rw [integrable_poissonMeasure_iff] + have h := ((NormedSpace.expSeries_div_hasSum_exp ((r : ℝ)*x)).mul_left + (Real.exp (-(r : ℝ)))).summable + convert h using 1 + funext m + rw [Real.norm_eq_abs, abs_of_nonneg (pow_nonneg hx m), mul_pow] + ring + +theorem poisson_power_integral (r : ℝ≥0) {x : ℝ} (hx : 0 ≤ x) : + (∫ m : ℕ, x^m ∂poissonMeasure r) = Real.exp ((r : ℝ)*(x-1)) := by + rw [integral_poissonMeasure' (poisson_power_integrable r hx)] + have h := (NormedSpace.expSeries_div_hasSum_exp ((r : ℝ)*x)).mul_left + (Real.exp (-(r : ℝ))) + calc + _ = ∑' m : ℕ, Real.exp (-(r : ℝ)) * (((r : ℝ)*x)^m / m.factorial) := by + apply tsum_congr + intro m + simp only [smul_eq_mul, mul_pow] + ring + _ = Real.exp (-(r : ℝ)) * Real.exp ((r : ℝ)*x) := by + simpa only [← Real.exp_eq_exp_ℝ] using h.tsum_eq + _ = _ := by rw [← Real.exp_add]; congr 1; ring + +theorem poisson_tail_dyadic (r : ℝ≥0) (L : ℕ) : + (∫ m : ℕ, if L < m then (1 : ℝ) else 0 ∂poissonMeasure r) ≤ + Real.exp r / (2 : ℝ)^L := by + have hi : Integrable (fun m : ℕ => if L < m then (1 : ℝ) else 0) + (poissonMeasure r) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun m => by split <;> norm_num) + calc + _ ≤ ∫ m : ℕ, (2 : ℝ)^m / (2 : ℝ)^L ∂poissonMeasure r := by + apply integral_mono hi ((poisson_power_integrable r (by norm_num : (0 : ℝ) ≤ 2)).div_const _) + intro m + dsimp only + split_ifs with hm + · apply (le_div_iff₀ (by positivity)).mpr + simpa using (pow_le_pow_right₀ (by norm_num : (1 : ℝ) ≤ 2) hm.le) + · positivity + _ = _ := by rw [integral_div, poisson_power_integral r (by norm_num : (0 : ℝ) ≤ 2)]; norm_num + +noncomputable def poissonKillProbability {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k : ℕ) (r : ℝ≥0) : ℝ := + ∫ d : ℕ, batchKillProbability U k d ∂poissonMeasure r + +theorem poissonKillProbability_truncate {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k L : ℕ) (r : ℝ≥0) : + poissonKillProbability U k r ≤ batchKillProbability U k L + + Real.exp r / (2 : ℝ)^L := by + have hi : Integrable (fun d => batchKillProbability U k d) (poissonMeasure r) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun d => (abs_le.mpr + ⟨by linarith [batchKillProbability_nonneg U k d], batchKillProbability_le_one U k d⟩)) + have ht : Integrable (fun d : ℕ => if L < d then (1 : ℝ) else 0) + (poissonMeasure r) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun d => by split <;> norm_num) + unfold poissonKillProbability + calc + _ ≤ ∫ d : ℕ, batchKillProbability U k L + + (if L < d then (1 : ℝ) else 0) ∂poissonMeasure r := by + apply integral_mono hi ((integrable_const _).add ht) + intro d + dsimp only [Pi.add_apply] + split_ifs with hd + · linarith [batchKillProbability_le_one U k d, batchKillProbability_nonneg U k L] + · simpa using batchKillProbability_mono U k (Nat.le_of_not_gt hd) + _ = batchKillProbability U k L + + (∫ d : ℕ, if L < d then (1 : ℝ) else 0 ∂poissonMeasure r) := by + rw [integral_add (integrable_const _) ht, integral_const, probReal_univ, one_smul] + _ ≤ _ := add_le_add le_rfl (poisson_tail_dyadic r L) + +theorem poissonKillProbability_mono_rate {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k : ℕ) : + Monotone (poissonKillProbability U k) := by + have hi (r : ℝ≥0) : Integrable (fun d => batchKillProbability U k d) + (poissonMeasure r) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun d => abs_le.mpr + ⟨by linarith [batchKillProbability_nonneg U k d], batchKillProbability_le_one U k d⟩) + intro r s hrs + have hs : s = r + (s-r) := (add_tsub_cancel_of_le hrs).symm + unfold poissonKillProbability + rw [hs, ← poissonMeasure_conv_poissonMeasure, integral_conv (by + simpa only [poissonMeasure_conv_poissonMeasure] using hi (r+(s-r)))] + apply integral_mono (hi r) + · apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun d => by + simpa only [Real.norm_eq_abs] using + (abs_integral_le_bound (μ := poissonMeasure (s-r)) (fun e => abs_le.mpr + ⟨by linarith [batchKillProbability_nonneg U k (d+e)], + batchKillProbability_le_one U k (d+e)⟩))) + · intro d + have hshift : Integrable (fun e => batchKillProbability U k (d+e)) + (poissonMeasure (s-r)) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact Eventually.of_forall (fun e => abs_le.mpr + ⟨by linarith [batchKillProbability_nonneg U k (d+e)], batchKillProbability_le_one U k (d+e)⟩) + calc + _ = ∫ _e : ℕ, batchKillProbability U k d ∂poissonMeasure (s-r) := by simp + _ ≤ _ := integral_mono (integrable_const _) hshift + (fun e => batchKillProbability_mono U k (Nat.le_add_right d e)) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonMarks.lean b/lean/OAI/Probability/SATComputability/PoissonMarks.lean new file mode 100644 index 0000000000000000000000000000000000000000..13d22fd783bfe19e387f293d728ae7ecee758405 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonMarks.lean @@ -0,0 +1,40 @@ +import OAI.Probability.DilutedSpin.FinitePoissonSplit + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal + +theorem uniform_poisson_marks {A E : Type*} [Fintype A] [Nonempty A] + [MeasurableSpace A] [MeasurableSingletonClass A] + [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] [CompleteSpace E] + (r : ℝ≥0) (V : A → E) : + compoundPoisson r (Measure.map V (finiteUniform A)) = + Measure.map (fun x : A → E => ∑ a, x a) + (Measure.pi (fun a => compoundPoisson (r / Fintype.card A) (Measure.dirac (V a)))) := by + have hV : Measurable V := measurable_of_countable V + let : IsProbabilityMeasure (Measure.map V (finiteUniform A)) := + (Measure.isProbabilityMeasure_map_iff hV.aemeasurable).mpr inferInstance + apply Measure.ext_of_charFunDual + funext L + rw [charFunDual_compoundPoisson, charFunDual_map_sum_pi_eq_prod] + simp only [Finset.prod_apply] + simp_rw [charFunDual_compoundPoisson, charFunDual_apply, integral_dirac] + rw [← Complex.exp_sum] + congr 1 + rw [integral_map hV.aemeasurable (by fun_prop), integral_finiteUniform] + have hcard : (Fintype.card A : ℂ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero + simp only [NNReal.coe_div, NNReal.coe_natCast, Complex.ofReal_div, + Complex.ofReal_natCast, Complex.real_smul, Complex.ofReal_inv] + simp_rw [mul_sub] + rw [Finset.sum_sub_distrib, ← Finset.mul_sum] + simp only [mul_one, Finset.sum_const, Finset.card_univ, nsmul_eq_mul] + field_simp + simp only [mul_comm Complex.I] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonMaskAggregation.lean b/lean/OAI/Probability/SATComputability/PoissonMaskAggregation.lean new file mode 100644 index 0000000000000000000000000000000000000000..cb5e6e27888bfb28c009c43b16ef94c1f73346fd --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonMaskAggregation.lean @@ -0,0 +1,50 @@ +import OAI.Probability.SATComputability.PoissonGrid + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators Classical NNReal + +theorem countsMask_product {A B X : Type*} [Fintype A] [Fintype B] [Fintype X] + (mask : A → Finset X) (c : A × B → ℕ) : + countsMask (fun p : A × B => mask p.1) c = + countsMask mask (fun a => ∑ b, c (a,b)) := by + ext x + simp only [countsMask, Finset.mem_filter, Finset.mem_univ, true_and, Prod.forall] + constructor + · intro h a + by_cases hx : x ∈ mask a + · exact Or.inr hx + · left + exact Finset.sum_eq_zero (fun b _ => (h a b).resolve_right hx) + · intro h a b + rcases h a with hz | hx + · left + exact (Finset.sum_eq_zero_iff_of_nonneg (fun j _ => Nat.zero_le (c (a,j)))).mp hz b + (Finset.mem_univ b) + · exact Or.inr hx + +theorem poissonCountLaw_redundant_mask {A B X : Type*} + [Fintype A] [Fintype B] [Fintype X] (r : ℝ≥0) + (mask : A → Finset X) (f : Finset X → ℝ) : + (∫ c, f (countsMask (fun p : A × B => mask p.1) c) + ∂poissonCountLaw (A × B) r) = + ∫ c, f (countsMask mask c) ∂poissonCountLaw A (Fintype.card B*r) := by + rw [← poissonCountLaw_uncurry_integral] + simp only [countsMask_product] + rw [← poissonCountLaw_row_sums (A := A) (B := B) r, + integral_map (measurable_of_countable _).aemeasurable + (measurable_of_countable _).aestronglyMeasurable] + +theorem poissonCountLaw_total_mean {A : Type*} [Fintype A] (r : ℝ≥0) : + (∫ c : A → ℕ, ((∑ a, c a : ℕ) : ℝ) ∂poissonCountLaw A r) = + Fintype.card A * (r : ℝ) := by + rw [poissonCountLaw, poissonCountLaw_sum_integral] + rw [poisson_mean] + simp + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonMaskCounts.lean b/lean/OAI/Probability/SATComputability/PoissonMaskCounts.lean new file mode 100644 index 0000000000000000000000000000000000000000..ee2b2f83e0bb8163cf49980a966a044e50231e4e --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonMaskCounts.lean @@ -0,0 +1,140 @@ +import OAI.Probability.SATComputability.FinitePushforward +import OAI.Probability.SATComputability.ClauseRestoration +import OAI.Probability.DilutedSpin.RootProductLaw + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal Classical + +noncomputable def zeroMask {X : Type*} [Fintype X] (z : X → ℝ) : Finset X := + Finset.univ.filter (fun x => z x = 0) + +theorem zeroMask_measurable {X : Type*} [Fintype X] [MeasurableSpace X] + [MeasurableSingletonClass X] : Measurable (zeroMask (X := X)) := by + apply measurable_finset_iff.mpr + intro x + simp only [zeroMask, Finset.mem_filter, Finset.mem_univ, true_and] + exact (measurable_pi_apply x).eq_const 0 + +noncomputable def maskDefect {A X : Type*} [Fintype X] + (mask : A → Finset X) (a : A) : X → ℝ := + fun x => if x ∈ mask a then 0 else 1 + +noncomputable def countsMask {A X : Type*} [Fintype A] [Fintype X] + (mask : A → Finset X) (counts : A → ℕ) : Finset X := + Finset.univ.filter (fun x => ∀ a, counts a = 0 ∨ x ∈ mask a) + +theorem zeroMask_sum_defect {A X : Type*} [Fintype A] [Fintype X] + (mask : A → Finset X) (counts : A → ℕ) : + zeroMask (∑ a, counts a • maskDefect mask a) = countsMask mask counts := by + ext x + simp only [zeroMask, countsMask, Finset.mem_filter, Finset.mem_univ, true_and, + Finset.sum_apply, nsmul_eq_mul] + change (∑ a, (counts a : ℝ)*(if x ∈ mask a then 0 else 1)) = 0 ↔ + ∀ a, counts a = 0 ∨ x ∈ mask a + rw [Finset.sum_eq_zero_iff_of_nonneg (fun a _ => by split_ifs <;> positivity)] + simp only [Finset.mem_univ, true_implies] + apply forall_congr' + intro a + by_cases hx : x ∈ mask a <;> simp [hx] + +theorem zeroMask_sum_marks {A X : Type*} [Fintype X] (mask : A → Finset X) + {d : ℕ} (as : Fin d → A) : + zeroMask (∑ j, maskDefect mask (as j)) = + Finset.univ.filter (fun x => ∀ j, x ∈ mask (as j)) := by + ext x + simp only [zeroMask, Finset.mem_filter, Finset.mem_univ, true_and, Finset.sum_apply, + maskDefect] + rw [Finset.sum_eq_zero_iff_of_nonneg (fun j _ => by positivity)] + simp + +theorem compoundPoisson_uniform_integral {A E : Type} [Fintype A] [Nonempty A] + [MeasurableSpace A] [MeasurableSingletonClass A] + [NormedAddCommGroup E] [NormedSpace ℝ E] [MeasurableSpace E] [BorelSpace E] + [SecondCountableTopology E] [CompleteSpace E] + (r : ℝ≥0) (V : A → E) (f : E → ℝ) (hf : Measurable f) + (B : ℝ) (hb : ∀ z, |f z| ≤ B) : + (∫ z, f z ∂compoundPoisson r (Measure.map V (finiteUniform A))) = + ∫ d : ℕ, (FiniteLaw.uniform : FiniteLaw (Fin d → A)).expect + (fun as => f (∑ j, V (as j))) ∂poissonMeasure r := by + have hV : Measurable V := measurable_of_countable V + let ν := Measure.map V (finiteUniform A) + let : IsProbabilityMeasure ν := + (Measure.isProbabilityMeasure_map_iff hV.aemeasurable).mpr inferInstance + have hi : Integrable f (compoundPoisson r ν) := + Integrable.of_bound hf.aestronglyMeasurable B + (Filter.Eventually.of_forall (fun z => by simpa only [Real.norm_eq_abs] using hb z)) + rw [compoundPoisson, integral_sum_measure hi, integral_poissonMeasure] + apply tsum_congr + intro d + rw [integral_smul_measure, ENNReal.toReal_ofReal (by positivity), + integral_map (by fun_prop) hf.aestronglyMeasurable] + change _ • (∫ z : Fin d → E, f (∑ j, z j) + ∂Measure.pi (fun _ => Measure.map V (finiteUniform A))) = _ + rw [← Measure.pi_map_pi (μ := fun _ : Fin d => finiteUniform A) + (f := fun _ a => V a) (fun _ => hV.aemeasurable), + integral_map (φ := fun x : Fin d → A => fun i => V (x i)) + (f := fun z : Fin d → E => f (∑ j, z j)) + (Measurable.of_eval (fun i => hV.comp (measurable_pi_apply i))).aemeasurable + (hf.comp (by fun_prop)).aestronglyMeasurable, + finiteUniform_pi, integral_finiteUniform] + simp only [FiniteLaw.expect, FiniteLaw.uniform, smul_eq_mul, ← Finset.mul_sum] + +noncomputable def markedMaskLaw {A X : Type*} [Fintype A] [Nonempty A] [Fintype X] + (r : ℝ≥0) (mask : A → Finset X) : FiniteLaw (Finset X) := + poissonMixture r (fun d => finiteMap (FiniteLaw.uniform : FiniteLaw (Fin d → A)) + (fun as => Finset.univ.filter (fun x => ∀ j, x ∈ mask (as j)))) + +theorem markedMaskLaw_counts {A X : Type} [Fintype A] [Nonempty A] [Fintype X] + [MeasurableSpace A] [MeasurableSingletonClass A] + [MeasurableSpace X] [MeasurableSingletonClass X] + (r : ℝ≥0) (mask : A → Finset X) (f : Finset X → ℝ) : + (markedMaskLaw r mask).expect f = + ∫ counts : A → ℕ, f (countsMask mask counts) + ∂Measure.pi (fun _ : A => poissonMeasure (r / Fintype.card A)) := by + have hg : Measurable (fun z : X → ℝ => f (zeroMask z)) := + (measurable_of_countable f).comp zeroMask_measurable + have hb (z : X → ℝ) : |f (zeroMask z)| ≤ ∑ U : Finset X, |f U| := + Finset.single_le_sum (fun U _ => abs_nonneg (f U)) (Finset.mem_univ _) + have he := compoundPoisson_uniform_integral r (maskDefect mask) + (fun z => f (zeroMask z)) hg _ hb + simp only [zeroMask_sum_marks] at he + rw [uniform_poisson_weighted_counts, integral_map + (measurable_of_countable (fun counts : A → ℕ => ∑ a, counts a • maskDefect mask a)).aemeasurable + hg.aestronglyMeasurable] at he + simp only [zeroMask_sum_defect] at he + rw [markedMaskLaw, poissonMixture_expect] + simp only [finiteMap_expect] + exact he.symm + +theorem candidateBlock_counts {n : ℕ} [NeZero n] (r : ℝ≥0) (k : ℕ) + (f : Finset (DeletionCandidate n) → ℝ) : + (candidateBlock r k (Finset.univ : Finset (DeletionCandidate n))).expect f = + ∫ counts : (Fin k → SignedLiteral n) → ℕ, + f (countsMask clauseMask counts) + ∂Measure.pi (fun _ : Fin k → SignedLiteral n => + poissonMeasure (r / Fintype.card (Fin k → SignedLiteral n))) := by + classical + let : MeasurableSpace (DeletionCandidate n) := ⊤ + let : MeasurableSingletonClass (DeletionCandidate n) := ⟨fun _ => trivial⟩ + rw [← markedMaskLaw_counts r (clauseMask (n := n) (k := k)) f, + markedMaskLaw, poissonMixture_expect, candidateBlock_expect] + apply integral_congr_ae + filter_upwards [] with d + rw [candidateStep_iterate] + simp only [finiteMap, FiniteLaw.expect, Finset.sum_mul, mul_ite, mul_one, mul_zero, ite_mul, + zero_mul] + rw [Finset.sum_comm] + apply Finset.sum_congr rfl + intro cs _ + simp only [Finset.sum_ite_eq, Finset.mem_univ, ite_true] + congr 2 + ext x + simp only [candidateResidual, clauseMask, Finset.mem_filter, Finset.mem_univ, true_and] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonSATProbability.lean b/lean/OAI/Probability/SATComputability/PoissonSATProbability.lean new file mode 100644 index 0000000000000000000000000000000000000000..6094b02e358b89e3df6e40ef8973fd05974cabdc --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonSATProbability.lean @@ -0,0 +1,76 @@ +import OAI.Probability.SATComputability.AuxiliaryEnergy +import OAI.Probability.SATComputability.PoissonCountBounds +import OAI.Probability.RandomSAT.Main + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology Classical + +noncomputable def auxiliaryPoissonProbability (n : ℕ) (a : ℝ≥0) : ℝ := + ∫ m : ℕ, auxiliaryProbability n 3 m ∂poissonMeasure (a*n) + +theorem auxiliaryPoissonProbability_lower {n : ℕ} (hn : 6 ≤ n) (a : ℝ≥0) + {b : ℝ} (hb0 : 0 ≤ b) (hbcap : b ≤ capMultiplier 3) : + transferFactor 3 * properSATProbability n 3 ⌊b*n⌋₊ * + (1 - ∫ m : ℕ, (if b*n < m then (1 : ℝ) else 0) ∂poissonMeasure (a*n)) ≤ + auxiliaryPoissonProbability n a := by + have hn0 : 0 < n := by omega + have h3 : 3 ≤ n := by omega + have hcap := floor_density_le_cap (n := n) hb0 hbcap + let c := transferFactor 3 * properSATProbability n 3 ⌊b*n⌋₊ + have hp : ∀ m : ℕ, c * (1 - if b*n < m then (1 : ℝ) else 0) ≤ auxiliaryProbability n 3 m := by + intro m + by_cases hm : b*n < m + · simpa only [ite_eq_left hm, sub_self, mul_zero] using auxiliaryProbability_nonneg n 3 m + · have hmc : m ≤ ⌊b*n⌋₊ := Nat.le_floor (le_of_not_gt hm) + have hfac := properFraction_pow_lower hn0 h3 + (by norm_num [repeatPairs]; omega : 2 * repeatPairs 3 ≤ n) (hmc.trans hcap) + have hsat := properSATProbability_antitone h3 hmc + have hprod := mul_le_mul hfac hsat (properSATProbability_nonneg n 3 _) + (pow_nonneg (properFraction_nonneg n 3) m) + simpa only [ite_eq_right hm, sub_zero, mul_one, c] using + hprod.trans (proper_scaled_le_auxiliaryProbability hn0 h3 m) + have hi : Integrable (fun m : ℕ => if b*n < m then (1 : ℝ) else 0) + (poissonMeasure (a*n)) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact ae_of_all _ (fun m => by split <;> norm_num) + have ha : Integrable (fun m => auxiliaryProbability n 3 m) (poissonMeasure (a*n)) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable 1 + exact ae_of_all _ (fun m => abs_le.mpr ⟨by linarith [auxiliaryProbability_nonneg n 3 m], + auxiliaryProbability_le_one hn0 3 m⟩) + have h := integral_mono ((integrable_const 1).sub hi |>.const_mul c) ha hp + rw [integral_const_mul] at h + simp only [Pi.sub_apply] at h + rw [integral_sub (integrable_const 1) hi] at h + simpa only [integral_const, probReal_univ, smul_eq_mul, one_mul, c, + auxiliaryPoissonProbability] using h + +theorem auxiliaryPoissonProbability_subcritical {a : ℝ≥0} + (ha : (a : ℝ) < limitingCenter 3) : + ∀ᶠ n : ℕ in atTop, transferFactor 3 / 4 ≤ auxiliaryPoissonProbability n a := by + obtain ⟨b, hab, hb⟩ := exists_between ha + have hb0 : 0 ≤ b := (show (0 : ℝ) ≤ a from a.property).trans hab.le + have hbcap : b ≤ capMultiplier 3 := (hb.trans (limitingCenter_lt_cap 3 (by decide))).le + have hs := (subcritical_limit 3 (by decide) b hb0 hb).eventually + (Ioi_mem_nhds (by norm_num : (1/2 : ℝ) < 1)) + have ht := (poisson_density_upper_tail_tendsto hab).eventually + (Iio_mem_nhds (by norm_num : (0 : ℝ) < 1/2)) + filter_upwards [hs, ht, eventually_ge_atTop 6] with n hn ht hn6 + have h := auxiliaryPoissonProbability_lower hn6 a hb0 hbcap + have hc := transferFactor_pos 3 + have hx : (1/4 : ℝ) ≤ properSATProbability n 3 ⌊b*n⌋₊ * + (1 - ∫ m : ℕ, (if b*n < m then (1 : ℝ) else 0) ∂poissonMeasure (a*n)) := by + have hmul := mul_le_mul hn.le (show (1/2 : ℝ) ≤ 1 - + ∫ m : ℕ, (if b*n < m then (1 : ℝ) else 0) ∂poissonMeasure (a*n) by linarith) + (by norm_num : (0 : ℝ) ≤ 1/2) (properSATProbability_nonneg n 3 ⌊b*n⌋₊) + norm_num at hmul + exact hmul + have hprod := mul_le_mul_of_nonneg_left hx hc.le + nlinarith + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PoissonSemigroup.lean b/lean/OAI/Probability/SATComputability/PoissonSemigroup.lean new file mode 100644 index 0000000000000000000000000000000000000000..7bd2c00c30fd1c3db569c5d0dc51f927b050b76f --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PoissonSemigroup.lean @@ -0,0 +1,87 @@ +import OAI.Probability.SATComputability.PoissonKernel + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory Filter +open scoped BigOperators NNReal + +theorem finite_expect_integral {Ω X : Type*} [Fintype Ω] [MeasurableSpace X] + (P : FiniteLaw Ω) (μ : Measure X) (f : X → Ω → ℝ) + (hf : ∀ x, Integrable (fun m => f m x) μ) : + P.expect (fun x => ∫ m, f m x ∂μ) = ∫ m, P.expect (f m) ∂μ := by + unfold FiniteLaw.expect + rw [integral_finsetSum _ (fun x _ => (hf x).const_mul (P.weight x))] + apply Finset.sum_congr rfl + intro x _ + rw [integral_const_mul] + +theorem candidateStep_iterate_bound {n : ℕ} [NeZero n] + (k d : ℕ) (f : Finset (DeletionCandidate n) → ℝ) {B : ℝ} + (hf : ∀ U, |f U| ≤ B) (U : Finset (DeletionCandidate n)) : + |(candidateStep k)^[d] f U| ≤ B := by + rw [← candidateFixedBlock_expect] + exact FiniteLaw.abs_expect_le _ hf + +theorem candidateBlock_comp {n : ℕ} [NeZero n] + (r s : ℝ≥0) (k : ℕ) (U : Finset (DeletionCandidate n)) + (f : Finset (DeletionCandidate n) → ℝ) : + (candidateBlock (r+s) k U).expect f = + (candidateBlock r k U).expect (fun V => (candidateBlock s k V).expect f) := by + let B := ∑ V : Finset (DeletionCandidate n), |f V| + have hf : ∀ V, |f V| ≤ B := fun V => + Finset.single_le_sum (fun W _ => abs_nonneg (f W)) (Finset.mem_univ V) + have hi (v : ℝ≥0) (V : Finset (DeletionCandidate n)) : + Integrable (fun d => (candidateStep k)^[d] f V) (poissonMeasure v) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable B + exact Eventually.of_forall (fun d => by + simpa only [Real.norm_eq_abs] using candidateStep_iterate_bound k d f hf V) + symm + calc + _ = (candidateBlock r k U).expect + (fun V => ∫ e, (candidateStep k)^[e] f V ∂poissonMeasure s) := by + simp only [candidateBlock_expect] + _ = ∫ e, (candidateBlock r k U).expect + (fun V => (candidateStep k)^[e] f V) ∂poissonMeasure s := + finite_expect_integral _ _ _ (hi s) + _ = ∫ e, ∫ d, (candidateStep k)^[d] ((candidateStep k)^[e] f) U + ∂poissonMeasure r ∂poissonMeasure s := by simp only [candidateBlock_expect] + _ = ∫ e, ∫ d, (candidateStep k)^[e+d] f U + ∂poissonMeasure r ∂poissonMeasure s := by + apply integral_congr_ae + exact Eventually.of_forall (fun e => integral_congr_ae + (Eventually.of_forall (fun d => by + dsimp only + rw [Nat.add_comm e d, Function.iterate_add_apply]))) + _ = ∫ m, (candidateStep k)^[m] f U ∂poissonMeasure (r+s) := by + rw [add_comm r s, ← poissonMeasure_conv_poissonMeasure, + integral_conv (by simpa only [poissonMeasure_conv_poissonMeasure] using hi (s+r) U)] + _ = _ := (candidateBlock_expect _ _ _ _).symm + +noncomputable def poissonCandidateStep {n : ℕ} [NeZero n] (r : ℝ≥0) (k : ℕ) + (f : Finset (DeletionCandidate n) → ℝ) (U : Finset (DeletionCandidate n)) : ℝ := + (candidateBlock r k U).expect f + +theorem poissonCandidateStep_iterate {n : ℕ} [NeZero n] + (r : ℝ≥0) (k m : ℕ) (U : Finset (DeletionCandidate n)) + (f : Finset (DeletionCandidate n) → ℝ) : + (poissonCandidateStep r k)^[m] f U = (candidateBlock (r*m) k U).expect f := by + induction m generalizing U f with + | zero => + rw [Function.iterate_zero_apply, Nat.cast_zero, mul_zero, candidateBlock_expect] + rw [integral_poissonMeasure] + simp [zero_pow_eq, ite_div, ite_mul] + | succ m ih => + rw [Function.iterate_succ_apply'] + change (candidateBlock r k U).expect ((poissonCandidateStep r k)^[m] f) = _ + have he : (poissonCandidateStep r k)^[m] f = + fun V => (candidateBlock (r*m) k V).expect f := funext (fun V => ih V f) + rw [he, ← candidateBlock_comp] + congr 2 + push_cast + ring + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PressureSigns.lean b/lean/OAI/Probability/SATComputability/PressureSigns.lean new file mode 100644 index 0000000000000000000000000000000000000000..d409539c9f299d57ea6973a1ad9334aa70b144ae --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PressureSigns.lean @@ -0,0 +1,91 @@ +import OAI.Probability.SATComputability.SubcriticalEnergy +import OAI.Probability.SATComputability.SATVariational + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory Filter +open scoped NNReal Topology + +attribute [local irreducible] relaxedLogPartition + +theorem relaxedFixedLogPartition_eq_mean (n m : ℕ) (β : ℝ) : + relaxedFixedLogPartition n m β = uniformMean + (fun cs : Fin m → RelaxedClause n => + relaxedLogPartition β (fun j => (cs j).1) (fun j => (cs j).2)) := by + let e : (Fin m → RelaxedClause n) ≃ + (Fin m → Fin 3 → Fin n) × (Fin m → Fin 3 → Bool) := + Equiv.arrowProdEquivProdArrow (Fin m) (fun _ => Fin 3 → Fin n) (fun _ => Fin 3 → Bool) + calc + _ = uniformMean (fun p : (Fin m → Fin 3 → Fin n) × (Fin m → Fin 3 → Bool) => + relaxedLogPartition β p.1 p.2) := by + rw [uniformMean_prod, uniformMean_comm] + rfl + _ = uniformMean (fun cs : Fin m → RelaxedClause n => + relaxedLogPartition β (e cs).1 (e cs).2) := + (uniformMean_equiv e (fun p : (Fin m → Fin 3 → Fin n) × (Fin m → Fin 3 → Bool) => + relaxedLogPartition β p.1 p.2)).symm + _ = _ := uniformMean_congr (fun _ => rfl) + +theorem relaxedFixedLogPartition_lower (n m : ℕ) (β : ℝ) : + -β * relaxedFixedMinimum n m ≤ relaxedFixedLogPartition n m β := by + rw [relaxedFixedLogPartition_eq_mean, relaxedFixedMinimum, ← uniformMean_const_mul] + exact uniformMean_mono (fun _ => relaxedLogPartition_lower _ _ _) + +theorem relaxedFixedLogPartition_bound (n m : ℕ) [NeZero n] {β : ℝ} (hβ : 0 ≤ β) : + |relaxedFixedLogPartition n m β| ≤ n*Real.log 2 + β*m := by + rw [relaxedFixedLogPartition_eq_mean, abs_le] + constructor + · have h := uniformMean_mono (f := fun _cs : Fin m → RelaxedClause n => -(β*(m : ℝ))) + (g := fun cs => relaxedLogPartition β (fun j => (cs j).1) (fun j => (cs j).2)) + (fun cs => ?_) + · rw [uniformMean_const] at h + have hl : 0 ≤ (n : ℝ)*Real.log 2 := mul_nonneg (Nat.cast_nonneg _) + (Real.log_nonneg (by norm_num)) + linarith + · have hl := relaxedLogPartition_lower β (fun j => (cs j).1) (fun j => (cs j).2) + have hm : (clauseMinimum cs : ℝ) ≤ m := by exact_mod_cast clauseMinimum_le_length cs + change -β * (clauseMinimum cs : ℝ) ≤ _ at hl + exact le_trans (by nlinarith) hl + · have h := uniformMean_mono (f := fun cs : Fin m → RelaxedClause n => + relaxedLogPartition β (fun j => (cs j).1) (fun j => (cs j).2)) + (g := fun _ => (n : ℝ)*Real.log 2 + β*m) (fun cs => ?_) + · simpa only [uniformMean_const] using h + · have hu := relaxedLogPartition_upper hβ (fun j => (cs j).1) (fun j => (cs j).2) + have hpos := mul_nonneg hβ (Nat.cast_nonneg (clauseMinimum cs) : (0 : ℝ) ≤ _) + nlinarith [mul_nonneg hβ (Nat.cast_nonneg m)] + +theorem relaxedPoissonPressure_lower (n : ℕ) [NeZero n] (a : ℝ≥0) + {β : ℝ} (hβ : 0 ≤ β) : + -β * (relaxedPoissonMinimum n a / n) ≤ relaxedPoissonPressure a β n := by + have hE : Integrable (fun m => relaxedFixedMinimum n m) (poissonMeasure (a*n)) := by + apply (poisson_integrable_count (a*n)).mono' + (measurable_of_countable _).aestronglyMeasurable + exact ae_of_all _ (fun m => by + simpa only [Real.norm_eq_abs, abs_of_nonneg (relaxedFixedMinimum_nonneg n m)] using + relaxedFixedMinimum_le n m) + have hZ : Integrable (fun m => relaxedFixedLogPartition n m β) (poissonMeasure (a*n)) := by + apply (((integrable_const ((n : ℝ)*Real.log 2)).add + ((poisson_integrable_count (a*n)).const_mul β))).mono' + (measurable_of_countable _).aestronglyMeasurable + exact ae_of_all _ (relaxedFixedLogPartition_bound n · hβ) + have h := integral_mono (hE.const_mul (-β)) hZ (fun m => relaxedFixedLogPartition_lower n m β) + rw [integral_const_mul] at h + have hd := div_le_div_of_nonneg_right h (Nat.cast_nonneg n : (0 : ℝ) ≤ n) + simpa only [relaxedPoissonMinimum, relaxedPoissonPressure, mul_div_assoc] using hd + +theorem satPressure_subcritical {a : ℝ≥0} (ha : 0 < a) + (haα : (a : ℝ) < limitingCenter 3) {β : ℝ} (hβ : 0 < β) : + 0 ≤ satPressure a β := by + have hl := (relaxedPoissonMinimum_subcritical haα).const_mul (-β) + have hb : ∀ᶠ n : ℕ in atTop, + -β * (relaxedPoissonMinimum n a / n) ≤ relaxedPoissonPressure a β n := by + filter_upwards [eventually_gt_atTop 0] with n hn + let : NeZero n := ⟨Nat.ne_of_gt hn⟩ + exact relaxedPoissonPressure_lower n a hβ.le + simpa only [mul_zero] using le_of_tendsto_of_tendsto hl (relaxedPressure_tendsto ha hβ) hb + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/PressureUpper.lean b/lean/OAI/Probability/SATComputability/PressureUpper.lean new file mode 100644 index 0000000000000000000000000000000000000000..e795ee04f7ffd4b237f2584397a85bbfa4a43f26 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/PressureUpper.lean @@ -0,0 +1,61 @@ +import OAI.Probability.SATComputability.PressureSigns + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory Filter +open scoped Topology NNReal + +theorem relaxedFixedLogPartition_upper (n m : ℕ) [NeZero n] {β : ℝ} (hβ : 0 ≤ β) : + relaxedFixedLogPartition n m β ≤ (n : ℝ)*Real.log 2 - β*relaxedFixedMinimum n m := by + rw [relaxedFixedLogPartition_eq_mean, relaxedFixedMinimum] + have h := uniformMean_mono (fun cs : Fin m → RelaxedClause n => + relaxedLogPartition_upper hβ (fun j => (cs j).1) (fun j => (cs j).2)) + simpa only [uniformMean_sub, uniformMean_const_mul, uniformMean_const, clauseMinimum] using h + +theorem relaxedPoissonPressure_upper (n : ℕ) [NeZero n] (a : ℝ≥0) + {β : ℝ} (hβ : 0 ≤ β) : + relaxedPoissonPressure a β n ≤ Real.log 2 - β*(relaxedPoissonMinimum n a/n) := by + have hn : (0 : ℝ) < n := by exact_mod_cast NeZero.pos n + have hE : Integrable (fun m => relaxedFixedMinimum n m) (poissonMeasure (a*n)) := by + apply (poisson_integrable_count (a*n)).mono' + (measurable_of_countable _).aestronglyMeasurable + exact ae_of_all _ (fun m => by + simpa only [Real.norm_eq_abs, abs_of_nonneg (relaxedFixedMinimum_nonneg n m)] using + relaxedFixedMinimum_le n m) + have hZ : Integrable (fun m => relaxedFixedLogPartition n m β) (poissonMeasure (a*n)) := by + apply (((integrable_const ((n : ℝ)*Real.log 2)).add + ((poisson_integrable_count (a*n)).const_mul β))).mono' + (measurable_of_countable _).aestronglyMeasurable + exact ae_of_all _ (relaxedFixedLogPartition_bound n · hβ) + have h := integral_mono hZ ((integrable_const _).sub (hE.const_mul β)) + (fun m => relaxedFixedLogPartition_upper n m hβ) + simp only [Pi.sub_apply] at h + simp only [integral_sub (integrable_const _) (hE.const_mul β), integral_const_mul, + integral_const, probReal_univ, one_smul] at h + have hd := div_le_div_of_nonneg_right h hn.le + simpa only [relaxedPoissonPressure, relaxedPoissonMinimum, sub_div, mul_div_assoc, + mul_div_cancel_left₀ _ hn.ne'] using hd + +theorem negative_pressure_of_violation_density {a : ℝ≥0} (ha : 0 < a) + {ε : ℝ} (hε : 0 < ε) + (hV : ∀ᶠ n : ℕ in atTop, ε ≤ relaxedPoissonMinimum n a/n) : + ∃ β : ℕ, 0 < β ∧ satPressure a β < 0 := by + obtain ⟨β,hβ⟩ := exists_nat_gt (max 0 (Real.log 2/ε)) + have hβ0 : (0 : ℝ) < β := (le_max_left _ _).trans_lt hβ + have hβN : 0 < β := by exact_mod_cast hβ0 + have hnegative : Real.log 2 - (β : ℝ)*ε < 0 := by + have hgt : Real.log 2/ε < β := (le_max_right _ _).trans_lt hβ + have hh := (div_lt_iff₀ hε).mp hgt + linarith + refine ⟨β,hβN,lt_of_le_of_lt ?_ hnegative⟩ + apply le_of_tendsto (relaxedPressure_tendsto ha hβ0) + filter_upwards [hV,eventually_gt_atTop 0] with n hn hn0 + let : NeZero n := ⟨Nat.ne_of_gt hn0⟩ + exact (relaxedPoissonPressure_upper n a hβ0.le).trans + (sub_le_sub_left (mul_le_mul_of_nonneg_left hn hβ0.le) _) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RationalExponents.lean b/lean/OAI/Probability/SATComputability/RationalExponents.lean new file mode 100644 index 0000000000000000000000000000000000000000..e4e5777187d075a1b8b5fbffac857db292b9d367 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RationalExponents.lean @@ -0,0 +1,46 @@ +import OAI.Probability.DilutedSpin.Model + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass Set Filter +open scoped Topology + +theorem isOpen_exponents (r : ℕ) : IsOpen {m : Fin r → ℝ | Exponents m} := by + have he : {m : Fin r → ℝ | Exponents m} = + (⋂ i : Fin r, ⋂ j : Fin r, {m | i < j → m i < m j}) ∩ + (⋂ i : Fin r, {m | 0 < m i ∧ m i < 1}) := by + ext m + simp only [mem_ofPred_eq, mem_inter_iff, mem_iInter, Exponents, StrictMono] + rw [he] + apply IsOpen.inter + · apply isOpen_iInter_of_finite + intro i + apply isOpen_iInter_of_finite + intro j + by_cases h : i < j + · simpa only [h, true_implies] using isOpen_lt (continuous_apply i) (continuous_apply j) + · simp only [h, false_implies, ofPred_true] + exact isOpen_univ + · apply isOpen_iInter_of_finite + intro i + exact (isOpen_lt continuous_const (continuous_apply i)).inter + (isOpen_lt (continuous_apply i) continuous_const) + +theorem rationalExponent_dense (r : ℕ) : + DenseRange (fun q : Fin r → ℚ => fun i => (q i : ℝ)) := + DenseRange.piMap (fun _ => Rat.denseRange_cast) + +theorem exists_rational_exponents {r : ℕ} {m : Fin r → ℝ} (hm : Exponents m) + {s : Set (Fin r → ℝ)} (hs : s ∈ nhds m) : + ∃ q : Fin r → ℚ, Exponents (fun i => (q i : ℝ)) ∧ (fun i => (q i : ℝ)) ∈ s := by + have hn : {m : Fin r → ℝ | Exponents m} ∩ s ∈ nhds m := + inter_mem ((isOpen_exponents r).mem_nhds hm) hs + obtain ⟨x, hx, hxs⟩ := mem_closure_iff_nhds.mp ((rationalExponent_dense r) m) _ hn + obtain ⟨q, rfl⟩ := hxs + exact ⟨q, hx.1, hx.2⟩ + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RationalHierarchy.lean b/lean/OAI/Probability/SATComputability/RationalHierarchy.lean new file mode 100644 index 0000000000000000000000000000000000000000..e6dd4563d836560ca24deaef183d4568d5e86f73 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RationalHierarchy.lean @@ -0,0 +1,103 @@ +import OAI.Probability.SATComputability.RationalWeights +import OAI.Probability.DilutedSpin.FiniteHierarchyDense + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory Set Filter TopologicalSpace +open scoped Topology BigOperators NNReal + +noncomputable def RationalWeights.toAtomic {ι : Type*} [Fintype ι] + (w : RationalWeights ι) : AtomicWeights ι := + ⟨fun i => ⟨w.val i, by exact_mod_cast w.property.1 i⟩, by + exact NNReal.coe_injective ((NNReal.coe_sum Finset.univ + (fun i => (⟨(w.val i : ℝ), by exact_mod_cast w.property.1 i⟩ : ℝ≥0))).trans + (by + change (∑ i, (w.val i : ℝ)) = 1 + exact_mod_cast w.property.2))⟩ + +theorem rationalWeights_atomic_dense {ι : Type*} [Fintype ι] : + DenseRange (RationalWeights.toAtomic (ι := ι)) := by + intro w + apply Metric.mem_closure_iff.mpr + intro ε hε + let P : FiniteLaw ι := ⟨fun i => w.val i, fun i => (w.val i).property, by + simpa using congrArg (fun q : ℝ≥0 => (q : ℝ)) w.property⟩ + obtain ⟨q, hq⟩ := exists_rational_weights_near P hε + refine ⟨q.toAtomic, ⟨q, rfl⟩, ?_⟩ + rw [dist_comm] + change dist (fun i => (q.toAtomic.val i)) w.val < ε + apply (dist_pi_lt_iff hε).mpr + intro i + change |(q.val i : ℝ) - (w.val i : ℝ)| < ε + exact hq i + +def RationalTree : ℕ → Type + | 0 => ℚ + | r+1 => Σ n : ℕ, RationalWeights (Fin n) × (Fin n → RationalTree r) + +instance rationalWeightsEncodable (n : ℕ) : Encodable (RationalWeights (Fin n)) := by + unfold RationalWeights + infer_instance + +@[instance_reducible] def rationalTreeEncoding : (r : ℕ) → Encodable (RationalTree r) + | 0 => Rat.instEncodable + | r+1 => by + letI := rationalTreeEncoding r + exact inferInstanceAs (Encodable (Σ n : ℕ, + RationalWeights (Fin n) × (Fin n → RationalTree r))) + +instance rationalTreeEncodable (r : ℕ) : Encodable (RationalTree r) := rationalTreeEncoding r + +local instance rationalHierarchyMeasurableSpace (space : TopCat) : MeasurableSpace space := + borel space +local instance rationalHierarchyBorelSpace (space : TopCat) : BorelSpace space := ⟨rfl⟩ + +noncomputable def rationalTreeValue : (r : ℕ) → RationalTree r → Hierarchy r + | 0, x => Rat.cast (K := ℝ) x + | r+1, ⟨_, q, x⟩ => atomicProbability (fun i => rationalTreeValue r (x i)) q.toAtomic + +theorem rationalTreeValue_finite (r : ℕ) (x : RationalTree r) : + FiniteHierarchy r (rationalTreeValue r x) := by + induction r with + | zero => trivial + | succ r ih => + obtain ⟨n, q, x⟩ := x + exact ⟨n, fun i => rationalTreeValue r (x i), q.toAtomic, + fun i => ih (x i), rfl⟩ + +theorem rationalTreeValue_dense (r : ℕ) : DenseRange (rationalTreeValue r) := by + induction r with + | zero => + change DenseRange (fun x : ℚ => (x : ℝ)) + exact Rat.denseRange_cast + | succ r ih => + let : MetrizableSpace (Hierarchy r) := (hierarchy_properties r).1 + let : MetricSpace (Hierarchy r) := metrizableSpaceMetric (Hierarchy r) + let : SeparableSpace (Hierarchy r) := (hierarchy_properties r).2 + let S := range (rationalTreeValue (r+1)) + let T := {μ : ProbabilityMeasure (Hierarchy r) | ∃ (n : ℕ) + (x : Fin n → Hierarchy r) (w : AtomicWeights (Fin n)), + (∀ i, x i ∈ range (rationalTreeValue r)) ∧ μ = atomicProbability x w} + have hd : Dense T := finite_atomic_dense (range (rationalTreeValue r)) ih + have hs : T ⊆ closure S := by + rintro μ ⟨n, x, w, hx, rfl⟩ + choose y hy using hx + have hnear := mem_closure_image (continuous_atomicProbability x).continuousAt + (rationalWeights_atomic_dense w) + apply (closure_mono (show atomicProbability x '' range RationalWeights.toAtomic ⊆ S from ?_)) hnear + rintro μ ⟨q, ⟨q', rfl⟩, rfl⟩ + refine ⟨⟨n, q', y⟩, ?_⟩ + change atomicProbability (fun i => rationalTreeValue r (y i)) q'.toAtomic = _ + congr 1 + exact funext hy + intro μ + have h := (closure_mono hs) (hd μ) + change μ ∈ closure (closure S) at h + rw [closure_closure] at h + exact h + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RationalWeights.lean b/lean/OAI/Probability/SATComputability/RationalWeights.lean new file mode 100644 index 0000000000000000000000000000000000000000..06a66223f98995ab5d3ce755dab73f618f87e694 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RationalWeights.lean @@ -0,0 +1,103 @@ +import OAI.Probability.DilutedSpin.FiniteLaw + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped BigOperators + +def RationalWeights (ι : Type*) [Fintype ι] := + {w : ι → ℚ // (∀ i, 0 ≤ w i) ∧ ∑ i, w i = 1} + +noncomputable def RationalWeights.toLaw {ι : Type*} [Fintype ι] + (w : RationalWeights ι) : FiniteLaw ι where + weight i := w.val i + nonneg i := by exact_mod_cast w.property.1 i + total := by exact_mod_cast w.property.2 + +abbrev ProbabilityVector (ι : Type*) [Fintype ι] := + {w : ι → ℝ // (∀ i, 0 ≤ w i) ∧ ∑ i, w i = 1} + +noncomputable def RationalWeights.real {ι : Type*} [Fintype ι] + (w : RationalWeights ι) : ProbabilityVector ι := + ⟨w.toLaw.weight, w.toLaw.nonneg, w.toLaw.total⟩ + +theorem exists_rational_weights_near {ι : Type*} [Fintype ι] + (w : FiniteLaw ι) {ε : ℝ} (hε : 0 < ε) : + ∃ q : RationalWeights ι, ∀ i, |(q.val i : ℝ) - w.weight i| < ε := by + classical + let δ := ε / (2 * (Fintype.card ι + 1)) + have hδ : 0 < δ := by dsimp [δ]; positivity + have hsmall : (Fintype.card ι + 1 : ℝ) * δ < ε := by + dsimp [δ] + have hn : (0 : ℝ) < Fintype.card ι + 1 := by positivity + field_simp + linarith + have hex (i : ι) : ∃ q : ℚ, w.weight i < q ∧ (q : ℝ) < w.weight i + δ := + exists_rat_btwn (by linarith) + choose v hv using hex + let S : ℚ := ∑ i, v i + have hSreal : (S : ℝ) = ∑ i, (v i : ℝ) := by simp [S] + have hS : 1 ≤ (S : ℝ) := by + rw [hSreal, ← w.total] + exact Finset.sum_le_sum (fun i _ => (hv i).1.le) + have hSupper : (S : ℝ) ≤ 1 + Fintype.card ι * δ := by + calc + (S : ℝ) = ∑ i, (v i : ℝ) := hSreal + _ ≤ ∑ i, (w.weight i + δ) := Finset.sum_le_sum (fun i _ => (hv i).2.le) + _ = _ := by simp [Finset.sum_add_distrib, w.total] + have hSpos : 0 < S := by exact_mod_cast (show (0 : ℝ) < S by linarith) + let q : RationalWeights ι := ⟨fun i => v i / S, by + constructor + · intro i + have hv0 : 0 ≤ v i := by exact_mod_cast ((w.nonneg i).trans (hv i).1.le) + exact div_nonneg hv0 hSpos.le + · rw [← Finset.sum_div] + exact div_self hSpos.ne'⟩ + refine ⟨q, fun i => ?_⟩ + have hwi : w.weight i ≤ 1 := by + rw [← w.total] + exact Finset.single_le_sum (fun j _ => w.nonneg j) (Finset.mem_univ i) + have hvi := hv i + have hw0 := w.nonneg i + have hs0 : 0 < (S : ℝ) := by linarith + have hδsmall : δ < ε := by + have hn : (1 : ℝ) ≤ Fintype.card ι + 1 := by + linarith [show (0 : ℝ) ≤ Fintype.card ι from Nat.cast_nonneg _] + nlinarith + have hnsmall : (Fintype.card ι : ℝ) * δ < ε := by linarith + have hprod := mul_le_mul_of_nonneg_left hSupper hw0 + have hcard := mul_le_mul_of_nonneg_right hwi + (show 0 ≤ (Fintype.card ι : ℝ) * δ by positivity) + have heps := mul_le_mul_of_nonneg_left hS hε.le + have hws := mul_le_mul_of_nonneg_left hS hw0 + change |((v i / S : ℚ) : ℝ) - w.weight i| < ε + rw [Rat.cast_div, abs_lt] + constructor + · have : w.weight i - ε < (v i : ℝ) / S := by + apply (lt_div_iff₀ hs0).mpr + nlinarith + linarith + · have : (v i : ℝ) / S < w.weight i + ε := by + apply (div_lt_iff₀ hs0).mpr + nlinarith + linarith + +theorem rationalWeights_dense {ι : Type*} [Fintype ι] : + DenseRange (RationalWeights.real (ι := ι)) := by + intro w + apply Metric.mem_closure_iff.mpr + intro ε hε + let P : FiniteLaw ι := ⟨w.val, w.property.1, w.property.2⟩ + obtain ⟨q, hq⟩ := exists_rational_weights_near P hε + refine ⟨q.real, ⟨q, rfl⟩, ?_⟩ + rw [dist_comm] + change dist (fun i => (q.val i : ℝ)) w.val < ε + apply (dist_pi_lt_iff hε).mpr + intro i + simpa only [Real.dist_eq] using hq i + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RelaxedCandidates.lean b/lean/OAI/Probability/SATComputability/RelaxedCandidates.lean new file mode 100644 index 0000000000000000000000000000000000000000..3aaa15edb0db487d7f9dd8f4bea36dd753a13fda --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RelaxedCandidates.lean @@ -0,0 +1,104 @@ +import OAI.Probability.SATComputability.SignLaw + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped BigOperators Classical + +abbrev DeletionCandidate (n : ℕ) := Fin n → Option Bool +abbrev SignedLiteral (n : ℕ) := Fin n × Bool + +def literalFalse {n : ℕ} (x : DeletionCandidate n) (l : SignedLiteral n) : Prop := + x l.1 = some (!l.2) + +def frozenLiteral {n : ℕ} (U : Finset (DeletionCandidate n)) (l : SignedLiteral n) : Prop := + ∀ x ∈ U, literalFalse x l + +noncomputable def frozenFraction {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) : ℝ := + (FiniteLaw.uniform : FiniteLaw (SignedLiteral n)).expect + (fun l => if frozenLiteral U l then 1 else 0) + +theorem uniform_prod_expect {A B : Type*} [Fintype A] [Fintype B] + [Nonempty A] [Nonempty B] (f : A × B → ℝ) : + (FiniteLaw.uniform : FiniteLaw (A × B)).expect f = + (FiniteLaw.uniform : FiniteLaw A).expect (fun a => + (FiniteLaw.uniform : FiniteLaw B).expect (fun b => f (a, b))) := by + simp only [FiniteLaw.expect, FiniteLaw.uniform, Fintype.sum_prod_type, + Fintype.card_prod, Nat.cast_mul, mul_inv, Finset.mul_sum] + apply Finset.sum_congr rfl + intro a _ + apply Finset.sum_congr rfl + intro b _ + ring + +theorem frozenFraction_nonneg {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) : 0 ≤ frozenFraction U := by + apply FiniteLaw.expect_nonneg + intro l + split <;> norm_num + +theorem frozenFraction_le_half {n : ℕ} [NeZero n] + {U : Finset (DeletionCandidate n)} (hU : U.Nonempty) : + frozenFraction U ≤ (1 : ℝ) / 2 := by + classical + obtain ⟨x, hx⟩ := hU + unfold frozenFraction + rw [uniform_prod_expect] + calc + _ ≤ (FiniteLaw.uniform : FiniteLaw (Fin n)).expect (fun _ => (1 : ℝ) / 2) := by + apply FiniteLaw.expect_mono + intro v + calc + _ ≤ (FiniteLaw.uniform : FiniteLaw Bool).expect + (fun s => if literalFalse x (v, s) then 1 else 0) := by + apply FiniteLaw.expect_mono + intro s + by_cases hf : frozenLiteral U (v, s) + · rw [ite_eq_left hf, ite_eq_left (hf x hx)] + · rw [ite_eq_right hf] + split <;> norm_num + _ ≤ 1 / 2 := by + cases h : x v with + | none => norm_num [literalFalse, h, FiniteLaw.expect, FiniteLaw.uniform] + | some b => cases b <;> + norm_num [literalFalse, h, FiniteLaw.expect, FiniteLaw.uniform, Fintype.sum_bool] + _ = _ := FiniteLaw.expect_const _ _ + +noncomputable def oneTestKill {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k : ℕ) : ℝ := + (FiniteLaw.uniform : FiniteLaw (Fin k → SignedLiteral n)).expect + (fun c => if ∀ x ∈ U, ∀ l, literalFalse x (c l) then 1 else 0) + +theorem oneTestKill_eq {n : ℕ} [NeZero n] + (U : Finset (DeletionCandidate n)) (k : ℕ) : + oneTestKill U k = frozenFraction U ^ k := by + classical + have hi (c : Fin k → SignedLiteral n) : + (if ∀ x ∈ U, ∀ l, literalFalse x (c l) then (1 : ℝ) else 0) = + ∏ l, if frozenLiteral U (c l) then 1 else 0 := by + rw [Fintype.prod_boole] + congr 1 + simp only [frozenLiteral] + apply propext + constructor + · intro h l x hx + exact h x hx l + · intro h x hx l + exact h l x hx + unfold oneTestKill + simp_rw [hi] + rw [uniformFiniteLaw_pi] + calc + _ = ∏ _ : Fin k, (FiniteLaw.uniform : FiniteLaw (SignedLiteral n)).expect + (fun l => if frozenLiteral U l then 1 else 0) := + FiniteLaw.expect_pi_product + (fun _ : Fin k => (FiniteLaw.uniform : FiniteLaw (SignedLiteral n))) + (fun _ l => if frozenLiteral U l then 1 else 0) + _ = _ := by simp only [frozenFraction, Finset.prod_const, Finset.card_univ, Fintype.card_fin] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RelaxedEnergy.lean b/lean/OAI/Probability/SATComputability/RelaxedEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..eec13b6831aad3491016b77ce5a0d792017194a6 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RelaxedEnergy.lean @@ -0,0 +1,86 @@ +import OAI.Probability.SATComputability.RelaxedPressure + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open Finset +open scoped BigOperators + +noncomputable def relaxedMinimumViolations {n m : ℕ} + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : ℕ := + Nat.find (show ∃ v : ℕ, ∃ s : Fin n → Bool, + relaxedViolations s indices signs = v from + ⟨relaxedViolations (fun _ => false) indices signs, (fun _ => false), rfl⟩) + +theorem relaxedMinimum_attained {n m : ℕ} + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : + ∃ s, relaxedViolations s indices signs = relaxedMinimumViolations indices signs := by + unfold relaxedMinimumViolations + exact Nat.find_spec (p := fun v => ∃ s, relaxedViolations s indices signs = v) _ + +theorem relaxedMinimum_le {n m : ℕ} + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) (s : Fin n → Bool) : + relaxedMinimumViolations indices signs ≤ relaxedViolations s indices signs := + Nat.find_min' _ ⟨s, rfl⟩ + +theorem relaxedMinimum_gt_of_deletion_unsat {n m r : ℕ} + {indices : Fin m → Fin 3 → Fin n} {signs : Fin m → Fin 3 → Bool} + (h : ¬deletionSatisfiable r indices signs) : + r < relaxedMinimumViolations indices signs := by + obtain ⟨s, hs⟩ := relaxedMinimum_attained indices signs + rw [← hs] + exact violations_gt_of_deletion_unsat h s + +theorem relaxedLogPartition_lower {n m : ℕ} (β : ℝ) + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : + -β * relaxedMinimumViolations indices signs ≤ relaxedLogPartition β indices signs := by + obtain ⟨s, hs⟩ := relaxedMinimum_attained indices signs + have he : Real.exp (-β * relaxedMinimumViolations indices signs) ≤ + relaxedPartition β indices signs := by + rw [← hs] + exact Finset.single_le_sum (fun a _ => + (Real.exp_pos (-β * relaxedViolations a indices signs)).le) (Finset.mem_univ s) + have := Real.log_le_log (Real.exp_pos _) he + simpa only [Real.log_exp, relaxedLogPartition] using this + +theorem relaxedLogPartition_upper {n m : ℕ} {β : ℝ} (hβ : 0 ≤ β) + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : + relaxedLogPartition β indices signs ≤ + n * Real.log 2 - β * relaxedMinimumViolations indices signs := by + have hb : relaxedPartition β indices signs ≤ (2 : ℝ)^n * + Real.exp (-β * relaxedMinimumViolations indices signs) := by + calc + _ ≤ ∑ _s : Fin n → Bool, Real.exp (-β * relaxedMinimumViolations indices signs) := by + apply Finset.sum_le_sum + intro s _ + apply Real.exp_le_exp.mpr + have h : (relaxedMinimumViolations indices signs : ℝ) ≤ + relaxedViolations s indices signs := by exact_mod_cast relaxedMinimum_le indices signs s + nlinarith + _ = _ := by simp + have hz : 0 < relaxedPartition β indices signs := + Finset.sum_pos (fun _ _ => Real.exp_pos _) Finset.univ_nonempty + have h := Real.log_le_log hz hb + rw [Real.log_mul (by positivity) (Real.exp_pos _).ne', Real.log_exp, Real.log_pow] at h + simpa only [relaxedLogPartition, sub_eq_add_neg, neg_mul] using h + +theorem relaxedMinimum_time_lower {n m r : ℕ} {a τ : ℝ} + (hn : 0 < n) (ha : 0 < a) (hτ : 0 ≤ τ) + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) + (hsurvive : deletionSatisfiable r indices signs → a*n ≤ τ) : + (r : ℝ) * (1 - τ/(a*n)) ≤ relaxedMinimumViolations indices signs := by + have hden : 0 < a*(n : ℝ) := mul_pos ha (by exact_mod_cast hn) + by_cases hs : deletionSatisfiable r indices signs + · have htime : 1 ≤ τ/(a*n) := (le_div_iff₀ hden).mpr (by simpa using hsurvive hs) + exact (mul_nonpos_of_nonneg_of_nonpos (Nat.cast_nonneg r) + (show (1 : ℝ) - τ/(a*n) ≤ 0 by linarith)).trans + (Nat.cast_nonneg _) + · have hm : (r : ℝ) ≤ relaxedMinimumViolations indices signs := by + exact_mod_cast (relaxedMinimum_gt_of_deletion_unsat hs).le + have ht : 0 ≤ τ/(a*n) := div_nonneg hτ hden.le + nlinarith [show (0 : ℝ) ≤ r from Nat.cast_nonneg r] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RelaxedPressure.lean b/lean/OAI/Probability/SATComputability/RelaxedPressure.lean new file mode 100644 index 0000000000000000000000000000000000000000..577800621b608d6a750e9727d52ce479051349e1 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RelaxedPressure.lean @@ -0,0 +1,111 @@ +import OAI.Probability.SATComputability.SignLaw +import OAI.Probability.SATComputability.VariableDeletion + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal + +noncomputable def relaxedPartition {n m : ℕ} (β : ℝ) + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : ℝ := + ∑ s : Fin n → Bool, Real.exp (-β * relaxedViolations s indices signs) + +noncomputable def relaxedLogPartition {n m : ℕ} (β : ℝ) + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : ℝ := + Real.log (relaxedPartition β indices signs) + +theorem satModel_logWeight {n m : ℕ} (β : ℝ) + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) + (s : Fin n → Bool) : + logWeight (fun j => satSample β (signs j)) (fun _ => 0) indices s = + -β * relaxedViolations s indices signs := by + classical + have h (j : Fin m) : satInteraction β (signs j) (fun l => s (indices j l)) = + -β * (if ¬relaxedClauseSatisfied s (indices j) (signs j) then 1 else 0) := by + simp [satInteraction, relaxedClauseSatisfied, not_exists] + simp only [logWeight, satSample, zero_mul, Finset.sum_const_zero, add_zero, h, + ← Finset.mul_sum] + congr 1 + simp only [relaxedViolations, Finset.card_eq_sum_ones, Nat.cast_sum, + Finset.sum_filter, ite_not, apply_ite, Nat.cast_one, Nat.cast_zero] + +theorem satModel_logPartition {n m : ℕ} (β : ℝ) + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : + DilutedSpinGlass.logPartition (fun j => satSample β (signs j)) (fun _ => 0) indices = + relaxedLogPartition β indices signs := by + simp only [DilutedSpinGlass.logPartition, satModel_logWeight, + relaxedLogPartition, relaxedPartition] + +theorem zeroField_integral (n : ℕ) (f : (Fin n → ℝ) → ℝ) : + (∫ h, f h ∂Measure.pi (fun _ : Fin n => Measure.dirac (0 : ℝ))) = + f (fun _ => 0) := by + have h : (fun h : Fin n → ℝ => fun i => h i) =ᵐ[ + Measure.pi (fun _ : Fin n => Measure.dirac (0 : ℝ))] (fun _ => fun _ => 0) := + Measure.ae_eq_pi (fun _ => ae_eq_dirac (fun x : ℝ => x)) + calc + _ = ∫ _h, f (fun _ => 0) ∂Measure.pi (fun _ : Fin n => Measure.dirac (0 : ℝ)) := by + apply integral_congr_ae + filter_upwards [h] with h hh + exact congrArg f hh + _ = _ := by simp + +theorem signLaw_pi_integral (m : ℕ) (f : (Fin m → Fin 3 → Bool) → ℝ) : + (∫ J, f J ∂Measure.pi (fun _ : Fin m => signLaw.toMeasure)) = + (∑ J, f J) / Fintype.card (Fin m → Fin 3 → Bool) := by + have he : Measure.pi (fun _ : Fin m => signLaw.toMeasure) = + (PMF.uniformOfFintype (Fin m → Fin 3 → Bool)).toMeasure := by + apply Measure.ext_of_singleton + intro J + simp [Measure.pi_singleton, signLaw, Nat.cast_pow, + ENNReal.inv_pow] + rw [he, PMF.integral_eq_sum] + simp only [PMF.uniformOfFintype_apply, ENNReal.toReal_inv, ENNReal.toReal_natCast, + smul_eq_mul, ← Finset.mul_sum, div_eq_mul_inv] + ring + +theorem disorder_pi_integral (a : ℝ≥0) (β : ℝ) (m : ℕ) + (f : (Fin m → InteractionSample 3) → ℝ) (hf : Measurable f) : + (∫ z, f z ∂Measure.pi (fun _ : Fin m => (satModel a β).disorder.toMeasure)) = + (∑ J : Fin m → Fin 3 → Bool, f (fun j => satSample β (J j))) / + Fintype.card (Fin m → Fin 3 → Bool) := by + change (∫ z, f z ∂Measure.pi (fun _ : Fin m => + Measure.map (satSample β) signLaw.toMeasure)) = _ + rw [← Measure.pi_map_pi (fun _ : Fin m => + (measurable_of_countable (satSample β)).aemeasurable)] + rw [integral_map (measurable_of_countable (fun J : Fin m → Fin 3 → Bool => + fun j => satSample β (J j))).aemeasurable + hf.aestronglyMeasurable] + exact signLaw_pi_integral m _ + +noncomputable def relaxedFixedLogPartition (n m : ℕ) (β : ℝ) : ℝ := + (∑ J : Fin m → Fin 3 → Bool, + (∑ indices : Fin m → Fin 3 → Fin n, relaxedLogPartition β indices J) / + Fintype.card (Fin m → Fin 3 → Fin n)) / + Fintype.card (Fin m → Fin 3 → Bool) + +noncomputable def relaxedPoissonPressure (a : ℝ≥0) (β : ℝ) (n : ℕ) : ℝ := + (∫ m : ℕ, relaxedFixedLogPartition n m β ∂poissonMeasure (a * n)) / n + +theorem satModel_pressure (a : ℝ≥0) (β : ℝ) (n : ℕ) : + pressure (satModel a β) n = relaxedPoissonPressure a β n := by + unfold pressure relaxedPoissonPressure + congr 1 + apply integral_congr_ae + filter_upwards [] with m + change (∫ z : Fin m → InteractionSample 3, + ∫ h : Fin n → ℝ, + (∑ indices : Fin m → Fin 3 → Fin n, DilutedSpinGlass.logPartition z h indices) / + Fintype.card (Fin m → Fin 3 → Fin n) + ∂Measure.pi (fun _ : Fin n => Measure.dirac (0 : ℝ)) + ∂Measure.pi (fun _ : Fin m => (satModel a β).disorder.toMeasure)) = _ + simp_rw [zeroField_integral] + rw [disorder_pi_integral a β m _ (by + unfold DilutedSpinGlass.logPartition logWeight + fun_prop)] + simp only [satModel_logPartition, relaxedFixedLogPartition] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ReplacementEstimate.lean b/lean/OAI/Probability/SATComputability/ReplacementEstimate.lean new file mode 100644 index 0000000000000000000000000000000000000000..4805d58ed8707b10d06e6122219642ce33f3ffd9 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ReplacementEstimate.lean @@ -0,0 +1,60 @@ +import OAI.Probability.SATComputability.RelaxedCandidates + +namespace OAI + +namespace FixedClauseThreshold.Computability + +private theorem cubic_loss_bound {x d : ℝ} (hx : 0 ≤ x) (hd : 0 < d) : + x^2 - d * x^3 / 2 ≤ 1 / d^2 := by + have hp : (d*x)^2 - (d*x)^3 / 2 ≤ 1 := by + have hs := mul_nonneg (sq_nonneg (d*x - 4/3)) + (show 0 ≤ d*x + 2/3 by positivity) + nlinarith + apply (le_div_iff₀ (sq_pos_of_pos hd)).mpr + nlinarith + +theorem two_to_three_exp_replacement {x d : ℝ} + (hx : 0 ≤ x) (hxhalf : x ≤ 1/2) (hd : 0 < d) : + x^2 - (1 - Real.exp (-d*x^3)) ≤ 1 / d^2 := by + let z := d*x^3 + have hz : 0 ≤ z := by dsimp [z]; positivity + have he : Real.exp (-z) ≤ 1 / (1+z) := by + rw [Real.exp_neg, one_div] + exact inv_anti₀ (by positivity : 0 < 1+z) (by + simpa only [add_comm] using Real.add_one_le_exp z) + have he' : Real.exp (-d*x^3) ≤ 1 / (1+z) := by + simpa only [z, neg_mul] using he + by_cases hz1 : z ≤ 1 + · have hlin : z / 2 ≤ 1 - Real.exp (-d*x^3) := by + have ht : 1 / (1+z) ≤ 1-z/2 := by + apply (div_le_iff₀ (by positivity : 0 < 1+z)).mpr + nlinarith + linarith + have hc := cubic_loss_bound hx hd + dsimp [z] at hlin + linarith + · have hlarge : 1 / (1+z) ≤ (1:ℝ)/2 := by + apply (div_le_iff₀ (by positivity : 0 < 1+z)).mpr + linarith + have hxx : x^2 ≤ (1:ℝ)/4 := by nlinarith + have hpos : 0 ≤ 1 / d^2 := by positivity + linarith + +theorem two_to_three_replacement {x : ℝ} (hx : 0 ≤ x) (hxhalf : x ≤ 1/2) + {d : ℕ} (hd : 0 < d) : + x^2 - (1 - (1-x^3)^d) ≤ 1 / (d : ℝ)^2 := by + have hbase : 0 ≤ 1-x^3 := by nlinarith [sq_nonneg x] + have he : (1-x^3)^d ≤ Real.exp (-((d : ℝ)*x^3)) := by + calc + _ ≤ (Real.exp (-(x^3)))^d := by + apply pow_le_pow_left₀ hbase + have := Real.add_one_le_exp (-(x^3)) + linarith + _ = _ := by rw [← Real.exp_nat_mul]; congr 1; ring + have hr := two_to_three_exp_replacement hx hxhalf (show (0:ℝ) < d by exact_mod_cast hd) + simp only [neg_mul] at hr + linarith + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/ReplicaPositivity.lean b/lean/OAI/Probability/SATComputability/ReplicaPositivity.lean new file mode 100644 index 0000000000000000000000000000000000000000..b2358cb1c304b7669a09aef89b0c8a15c59b3943 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/ReplicaPositivity.lean @@ -0,0 +1,68 @@ +import OAI.Probability.SATComputability.SignMoment +import OAI.Probability.SATComputability.InterpolationInputs +import OAI.Probability.DilutedSpin.RawPatternIdentity + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory PositiveInterpolation +open scoped BigOperators NNReal + +theorem satModel_rawMoment {n : ℕ} (a : ℝ≥0) (β : ℝ) + (P : Fin 3 → FiniteLaw (Fin n → Spin)) : + rawReplicaMoment (satModel a β) P = + (1 - Real.exp (-β)) ^ n * ∏ l, signFeature (P l) := by + rw [rawReplicaMoment_eq_product] + change (∫ z : InteractionSample 3, (-z.2.2.1)^n * + ∏ l, (P l).expect (fun s => ∏ i, z.2.2.2 l (s i)) + ∂Measure.map (satSample β) signLaw.toMeasure) = _ + rw [integral_map (measurable_of_countable _).aemeasurable + (by unfold FiniteLaw.expect; fun_prop)] + simp only [satSample, neg_sub] + rw [integral_const_mul] + rw [signLaw_product (fun l J => (P l).expect (fun s => ∏ i, literalFactor J (s i)))] + rfl + +theorem satModel_raw_nonnegative {n : ℕ} (a : ℝ≥0) {β : ℝ} (hβ : 0 ≤ β) + (j : Fin 3) (P B : FiniteLaw (Fin n → Spin)) : + 0 ≤ rawReplicaMoment (satModel a β) (fun _ : Fin 3 => P) - + (3 : ℝ) * rawReplicaMoment (satModel a β) (fun l => if l = j then P else B) + + (2 : ℝ) * rawReplicaMoment (satModel a β) (fun _ : Fin 3 => B) := by + rw [satModel_rawMoment, satModel_rawMoment, satModel_rawMoment] + exact signFeature_cubic_nonnegative hβ j P B + +theorem satModel_interpolation_admissible {a : ℝ≥0} (ha : 0 < a) + {β : ℝ} (hβ : 0 < β) : InterpolationAdmissible (satModel a β) := by + refine ⟨by norm_num, ha, satModel_interaction_integrable a hβ.le, + satModel_field_integrable a β, ?_, satModel_independent a β, + satModel_identically_distributed a β, ?_, ?_, ?_, ?_⟩ + · filter_upwards [satModel_supported a β] with z hz + obtain ⟨J, rfl⟩ := hz + refine ⟨by norm_num [satSample], fun s => ?_⟩ + exact ⟨satSample_factorization β J s, satSample_product_bound hβ J s⟩ + · apply (indepFun_const_left (Real.exp (-β) - 1) + (fun z : InteractionSample 3 => z.2.2.2)).congr + · filter_upwards [satModel_supported a β] with z hz + obtain ⟨J, rfl⟩ := hz + rfl + · rfl + · intro n _ + apply (integrable_const ((1 - Real.exp (-β)) ^ n)).congr + filter_upwards [satModel_supported a β] with z hz + obtain ⟨J, rfl⟩ := hz + simp [satSample] + · intro n _ + apply integral_nonneg_of_ae + filter_upwards [satModel_supported a β] with z hz + obtain ⟨J, rfl⟩ := hz + change 0 ≤ (-(Real.exp (-β) - 1)) ^ n + apply pow_nonneg + have he : Real.exp (-β) ≤ 1 := Real.exp_le_one_iff.mpr (by linarith) + linarith + · intro n _ j P B + exact satModel_raw_nonnegative a hβ.le j P B + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RestoredCandidates.lean b/lean/OAI/Probability/SATComputability/RestoredCandidates.lean new file mode 100644 index 0000000000000000000000000000000000000000..66121ba275fafe9680d836bf7abdac0766a9cd9a --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RestoredCandidates.lean @@ -0,0 +1,183 @@ +import OAI.Probability.SATComputability.MaskDeletionTimes + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped Classical + +def restoreCandidate {n : ℕ} (b : Option Bool) (x : DeletionCandidate n) : + DeletionCandidate (n+1) := Fin.cons b x + +theorem deletedVariables_tail_image {n : ℕ} (x : DeletionCandidate (n+1)) : + (deletedVariables (Fin.tail x)).image Fin.succ = (deletedVariables x).erase 0 := by + ext i + rw [Finset.mem_image, Finset.mem_erase] + constructor + · rintro ⟨j,hj,rfl⟩ + refine ⟨Fin.succ_ne_zero _,?_⟩ + exact Finset.mem_filter.mpr ⟨Finset.mem_univ _,(Finset.mem_filter.mp hj).2⟩ + · rintro ⟨hi0,hi⟩ + obtain ⟨j,rfl⟩ := Fin.exists_succ_eq_of_ne_zero hi0 + exact ⟨j,Finset.mem_filter.mpr ⟨Finset.mem_univ _,(Finset.mem_filter.mp hi).2⟩,rfl⟩ + +theorem deletedVariables_restore_card {n : ℕ} (b : Bool) (x : DeletionCandidate n) : + (deletedVariables (restoreCandidate (some b) x)).card = (deletedVariables x).card := by + have h0 : (0 : Fin (n+1)) ∉ deletedVariables (restoreCandidate (some b) x) := by + intro h + have hx := (Finset.mem_filter.mp h).2 + simp [restoreCandidate] at hx + have he := deletedVariables_tail_image (restoreCandidate (some b) x) + rw [Finset.erase_eq_of_notMem h0] at he + rw [← he, Finset.card_image_of_injective _ (Fin.succ_injective n)] + rfl + +theorem mem_freeDeletionBudgetMask {n r : ℕ} (x : DeletionCandidate (n+1)) : + x ∈ freeDeletionBudgetMask (n+1) r 0 ↔ + (deletedVariables (Fin.tail x)).card ≤ r := by + simp only [freeDeletionBudgetMask, Finset.mem_biUnion, allowedDeletions, deletionMask, + Finset.mem_filter, Finset.mem_univ, true_and] + have hc : ((deletedVariables (Fin.tail x)).image Fin.succ).card = + (deletedVariables (Fin.tail x)).card := Finset.card_image_of_injective _ (Fin.succ_injective n) + constructor + · rintro ⟨D,hD,hx⟩ + have hsub : (deletedVariables (Fin.tail x)).image Fin.succ ⊆ D := by + rw [deletedVariables_tail_image] + intro i hi + obtain ⟨hi0,hi⟩ := Finset.mem_erase.mp hi + exact (Finset.mem_insert.mp (hx hi)).resolve_left hi0 + rw [← hc] + exact (Finset.card_le_card hsub).trans hD + · intro hx + refine ⟨(deletedVariables (Fin.tail x)).image Fin.succ, by simpa only [hc] using hx, ?_⟩ + intro i hi + by_cases hi0 : i = 0 + · exact Finset.mem_insert.mpr (Or.inl hi0) + · exact Finset.mem_insert.mpr (Or.inr (by + rw [deletedVariables_tail_image] + exact Finset.mem_erase.mpr ⟨hi0,hi⟩)) + +theorem maskLifetime_map_le {n N m : ℕ} (f : DeletionCandidate n → DeletionCandidate N) + (U : Finset (DeletionCandidate n)) (V : Finset (DeletionCandidate N)) + (xs : Fin m → Finset (DeletionCandidate n)) (ys : Fin m → Finset (DeletionCandidate N)) + (hUV : ∀ x ∈ U, f x ∈ V) + (hxy : ∀ j x, x ∈ xs j → f x ∈ ys j) : + maskLifetime m U xs ≤ maskLifetime m V ys := by + induction m generalizing U V with + | zero => exact le_rfl + | succ m ih => + apply add_le_add + · unfold candidateAlive + split_ifs with hU hV hV + · exact le_rfl + · obtain ⟨x,hx⟩ := hU + exact False.elim (hV ⟨f x,hUV x hx⟩) + · norm_num + · exact le_rfl + · exact ih (U ∩ xs 0) (V ∩ ys 0) (Fin.tail xs) (Fin.tail ys) + (fun x hx => Finset.mem_inter.mpr + ⟨hUV x (Finset.mem_inter.mp hx).1,hxy 0 x (Finset.mem_inter.mp hx).2⟩) + (fun j x hx => hxy j.succ x hx) + +noncomputable def restoredMask {n : ℕ} (B F T : Finset (DeletionCandidate n)) : + Finset (DeletionCandidate (n+1)) := + Finset.univ.filter (fun x => Fin.tail x ∈ B ∧ + match x 0 with + | none => True + | some false => Fin.tail x ∈ F + | some true => Fin.tail x ∈ T) + +theorem restoredMask_tail {n : ℕ} (B F T : Finset (DeletionCandidate n)) + {x : DeletionCandidate (n+1)} (hx : x ∈ restoredMask B F T) : Fin.tail x ∈ B := + (Finset.mem_filter.mp hx).2.1 + +theorem restore_none_mem {n : ℕ} (B F T : Finset (DeletionCandidate n)) + {x : DeletionCandidate n} (hx : x ∈ B) : + restoreCandidate none x ∈ restoredMask B F T := by + simpa [restoredMask, restoreCandidate] using hx + +theorem restore_some_mem {n : ℕ} (B F T : Finset (DeletionCandidate n)) + (b : Bool) {x : DeletionCandidate n} (hx : x ∈ B) + (hi : x ∈ if b then T else F) : + restoreCandidate (some b) x ∈ restoredMask B F T := by + cases b <;> simpa [restoredMask, restoreCandidate, hx] using hi + +theorem free_restored_lifetime {n r m : ℕ} + (base f t : Fin m → Finset (DeletionCandidate n)) : + maskLifetime m (freeDeletionBudgetMask (n+1) r 0) + (fun j => restoredMask (base j) (f j) (t j)) = + maskLifetime m (deletionBudgetMask n r) base := by + apply le_antisymm + · apply maskLifetime_map_le (fun x => Fin.tail x) + · intro x hx + simpa only [deletionBudgetMask, Finset.mem_filter, Finset.mem_univ, true_and, + mem_freeDeletionBudgetMask] using hx + · intro j x hx + exact restoredMask_tail _ _ _ hx + · apply maskLifetime_map_le (restoreCandidate none) + · intro x hx + rw [mem_freeDeletionBudgetMask] + simpa only [restoreCandidate, Fin.tail_cons, deletionBudgetMask, + Finset.mem_filter, Finset.mem_univ, true_and] using hx + · intro j x hx + exact restore_none_mem _ _ _ hx + +theorem restored_frontload_lifetime {n r m : ℕ} + (base f t : Fin m → Finset (DeletionCandidate n)) + (F T : Finset (DeletionCandidate n)) + (hF : ∀ j, F ⊆ f j) (hT : ∀ j, T ⊆ t j) : + maskLifetime m (deletionBudgetMask n r ∩ (F ∪ T)) base ≤ + maskLifetime m (deletionBudgetMask (n+1) r) + (fun j => restoredMask (base j) (f j) (t j)) := by + rw [Finset.inter_union_distrib_left, maskLifetime_union] + apply max_le + · apply le_trans (maskLifetime_frontload _ base f F hF) + apply maskLifetime_map_le (restoreCandidate (some false)) + · intro x hx + simpa only [deletionBudgetMask, Finset.mem_filter, Finset.mem_univ, true_and, + deletedVariables_restore_card] using hx + · intro j x hx + exact restore_some_mem _ _ _ false (Finset.mem_inter.mp hx).1 + (Finset.mem_inter.mp hx).2 + · apply le_trans (maskLifetime_frontload _ base t T hT) + apply maskLifetime_map_le (restoreCandidate (some true)) + · intro x hx + simpa only [deletionBudgetMask, Finset.mem_filter, Finset.mem_univ, true_and, + deletedVariables_restore_card] using hx + · intro j x hx + exact restore_some_mem _ _ _ true (Finset.mem_inter.mp hx).1 + (Finset.mem_inter.mp hx).2 + +theorem deletionBudgetMask_subset_free (n r : ℕ) (v : Fin n) : + deletionBudgetMask n r ⊆ freeDeletionBudgetMask n r v := by + intro x hx + apply Finset.mem_biUnion.mpr + refine ⟨deletedVariables x, ?_, ?_⟩ + · simpa only [allowedDeletions, deletionBudgetMask, Finset.mem_filter, + Finset.mem_univ, true_and] using hx + · exact Finset.mem_filter.mpr ⟨Finset.mem_univ _, Finset.subset_insert _ _⟩ + +theorem restored_gap_nonneg {n r m : ℕ} + (base f t : Fin m → Finset (DeletionCandidate n)) : + 0 ≤ maskLifetime m (deletionBudgetMask n r) base - + maskLifetime m (deletionBudgetMask (n+1) r) + (fun j => restoredMask (base j) (f j) (t j)) := by + rw [← free_restored_lifetime base f t] + exact sub_nonneg.mpr (maskLifetime_mono (deletionBudgetMask_subset_free (n+1) r 0) _) + +theorem restored_gap_bound {n r m : ℕ} + (base f t : Fin m → Finset (DeletionCandidate n)) + (F T : Finset (DeletionCandidate n)) + (hF : ∀ j, F ⊆ f j) (hT : ∀ j, T ⊆ t j) : + (maskLifetime m (deletionBudgetMask n r) base - + maskLifetime m (deletionBudgetMask (n+1) r) + (fun j => restoredMask (base j) (f j) (t j)))^(6/5 : ℝ) ≤ + (maskLifetime m (deletionBudgetMask n r) base - + maskLifetime m (deletionBudgetMask n r ∩ (F ∪ T)) base)^(6/5 : ℝ) := by + apply Real.rpow_le_rpow (restored_gap_nonneg base f t) + (sub_le_sub_left (restored_frontload_lifetime base f t F T hF hT) _) (by norm_num) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RestoredProcessMoment.lean b/lean/OAI/Probability/SATComputability/RestoredProcessMoment.lean new file mode 100644 index 0000000000000000000000000000000000000000..028f84b200fccab640f8128aa95ebc1c8f9de416 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RestoredProcessMoment.lean @@ -0,0 +1,65 @@ +import OAI.Probability.SATComputability.RestoredCandidates +import OAI.Probability.SATComputability.UniformDelayConstant + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass +open scoped Classical NNReal + +theorem mem_maskRun {n m : ℕ} (U : Finset (DeletionCandidate n)) + (xs : Fin m → Finset (DeletionCandidate n)) (x : DeletionCandidate n) : + x ∈ maskRun m U xs ↔ x ∈ U ∧ ∀ j, x ∈ xs j := by + induction m generalizing U with + | zero => simp [maskRun] + | succ m ih => + simp only [maskRun, ih, Finset.mem_inter, Fin.forall_fin_succ, Fin.tail_def, and_assoc] + +noncomputable def frontloadMask {n m : ℕ} (xs : Fin m → Finset (DeletionCandidate n)) : + Finset (DeletionCandidate n) := maskRun m Finset.univ xs + +theorem frontloadMask_subset {n m : ℕ} (xs : Fin m → Finset (DeletionCandidate n)) + (j : Fin m) : frontloadMask xs ⊆ xs j := by + intro x hx + exact (mem_maskRun _ xs x).mp hx |>.2 j + +theorem restored_process_moment {n : ℕ} [NeZero n] (M r : ℕ) + (rate : ℝ≥0) (hrate : (1 : ℝ)/8 ≤ rate) + (P : FiniteLaw (Fin M → Finset (DeletionCandidate n))) (ε : ℝ) + (hP : ∀ U, (finiteMap P frontloadMask).expect + (fun I => if U ∩ I = ∅ then 1 else 0) ≤ poissonKillProbability U 2 60 + ε) : + P.expect (fun f => P.expect (fun t => + (FiniteLaw.pi (fun _ : Fin M => candidateBlock rate 3 Finset.univ)).expect (fun base => + (maskLifetime M (deletionBudgetMask n r) base - + maskLifetime M (deletionBudgetMask (n+1) r) + (fun j => restoredMask (base j) (f j) (t j)))^(6/5 : ℝ)))) ≤ + (48/5 : ℝ)*(∑' j, dyadicMomentCoefficient j) + + (12/5 : ℝ)*ε^2*(M : ℝ)^(6/5 : ℝ) := by + let Q := finiteMap P frontloadMask + have hQ (U : Finset (DeletionCandidate n)) : + (unionMaskLaw Q Q).expect (fun I => if U.Nonempty ∧ U ∩ I = ∅ then 1 else 0) ≤ + (poissonKillProbability U 2 60 + ε)^2 := by + by_cases hU : U.Nonempty + · simp only [hU, true_and, unionMaskLaw_killing] + rw [← pow_two] + exact pow_le_pow_left₀ (FiniteLaw.expect_nonneg _ (fun I => by split_ifs <;> norm_num)) + (hP U) 2 + · simp only [hU, false_and, ite_false, FiniteLaw.expect_const] + exact sq_nonneg _ + have h := maskDelayMoment_of_obstruction rate hrate M (unionMaskLaw Q Q) ε hQ + (deletionBudgetMask n r) + apply le_trans ?_ h + rw [unionMaskLaw, finiteMap_expect, FiniteLaw.expect_bind] + simp only [Q, finiteMap_expect] + apply P.expect_mono + intro f + apply P.expect_mono + intro t + exact FiniteLaw.expect_mono _ (fun base => + restored_gap_bound base f t (frontloadMask f) (frontloadMask t) + (frontloadMask_subset f) (frontloadMask_subset t)) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/RootEnergy.lean b/lean/OAI/Probability/SATComputability/RootEnergy.lean new file mode 100644 index 0000000000000000000000000000000000000000..15b40ec35b9c35dae3329cc579d0dc2d96486454 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/RootEnergy.lean @@ -0,0 +1,169 @@ +import OAI.Probability.SATComputability.RelaxedEnergy +import OAI.Probability.DilutedSpin.PoissonVariance + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal + +abbrev RelaxedClause (n : ℕ) := (Fin 3 → Fin n) × (Fin 3 → Bool) + +noncomputable def clauseMinimum {n m : ℕ} (cs : Fin m → RelaxedClause n) : ℕ := + relaxedMinimumViolations (fun j => (cs j).1) (fun j => (cs j).2) + +theorem relaxedViolations_eq_sum {n m : ℕ} (s : Fin n → Bool) + (indices : Fin m → Fin 3 → Fin n) (signs : Fin m → Fin 3 → Bool) : + relaxedViolations s indices signs = + ∑ j, if relaxedClauseSatisfied s (indices j) (signs j) then 0 else 1 := by + simp only [relaxedViolations, Finset.card_eq_sum_ones, Finset.sum_filter, ite_not] + +theorem clauseMinimum_le_length {n m : ℕ} (cs : Fin m → RelaxedClause n) : + clauseMinimum cs ≤ m := by + exact (relaxedMinimum_le _ _ (fun _ => false)).trans + ((Finset.card_filter_le _ _).trans_eq (Fintype.card_fin m)) + +theorem clauseMinimum_le_add_one {n m : ℕ} (cs ds : Fin m → RelaxedClause n) + (q : Fin m) (h : ∀ j, j ≠ q → cs j = ds j) : + clauseMinimum cs ≤ clauseMinimum ds + 1 := by + classical + obtain ⟨s, hs⟩ := relaxedMinimum_attained (fun j => (ds j).1) (fun j => (ds j).2) + apply (relaxedMinimum_le _ _ s).trans + unfold clauseMinimum + rw [← hs] + let S := Finset.univ.filter fun j => ¬relaxedClauseSatisfied s (ds j).1 (ds j).2 + have hsub : (Finset.univ.filter fun j => + ¬relaxedClauseSatisfied s (cs j).1 (cs j).2) ⊆ insert q S := by + intro j hj + by_cases hjq : j = q + · exact Finset.mem_insert.mpr (Or.inl hjq) + · apply Finset.mem_insert_of_mem + apply Finset.mem_filter.mpr + refine ⟨Finset.mem_univ _, ?_⟩ + rw [← h j hjq] + exact (Finset.mem_filter.mp hj).2 + exact (Finset.card_le_card hsub).trans (Finset.card_insert_le _ _) + +theorem clauseMinimum_update_bound {n m : ℕ} (cs : Fin m → RelaxedClause n) + (q : Fin m) (c : RelaxedClause n) : + |(clauseMinimum cs : ℝ) - clauseMinimum (Function.update cs q c)| ≤ 1 := by + have h : ∀ j, j ≠ q → cs j = Function.update cs q c j := by + intro j hj + exact (Function.update_of_ne hj c cs).symm + have h₁ := clauseMinimum_le_add_one cs (Function.update cs q c) q h + have h₂ := clauseMinimum_le_add_one (Function.update cs q c) cs q + (fun j hj => (h j hj).symm) + have h₁' : (clauseMinimum cs : ℝ) ≤ clauseMinimum (Function.update cs q c) + 1 := by + exact_mod_cast h₁ + have h₂' : (clauseMinimum (Function.update cs q c) : ℝ) ≤ clauseMinimum cs + 1 := by + exact_mod_cast h₂ + exact abs_le.mpr ⟨by linarith, by linarith⟩ + +theorem clauseMinimum_cons_bounds {n m : ℕ} (cs : Fin m → RelaxedClause n) + (c : RelaxedClause n) : + clauseMinimum cs ≤ clauseMinimum (Fin.cons c cs) ∧ + clauseMinimum (Fin.cons c cs) ≤ clauseMinimum cs + 1 := by + have he (s : Fin n → Bool) : + relaxedViolations s (fun j => ((Fin.cons c cs : Fin (m+1) → RelaxedClause n) j).1) + (fun j => ((Fin.cons c cs : Fin (m+1) → RelaxedClause n) j).2) = + (if relaxedClauseSatisfied s c.1 c.2 then 0 else 1) + + relaxedViolations s (fun j => (cs j).1) (fun j => (cs j).2) := by + simp only [relaxedViolations_eq_sum, Fin.sum_univ_succ, Fin.cons_zero, Fin.cons_succ] + constructor + · obtain ⟨s, hs⟩ := relaxedMinimum_attained + (fun j => ((Fin.cons c cs : Fin (m+1) → RelaxedClause n) j).1) + (fun j => ((Fin.cons c cs : Fin (m+1) → RelaxedClause n) j).2) + apply (relaxedMinimum_le _ _ s).trans + change _ ≤ relaxedMinimumViolations _ _ + rw [← hs, he] + omega + · obtain ⟨s, hs⟩ := relaxedMinimum_attained (fun j => (cs j).1) (fun j => (cs j).2) + apply (relaxedMinimum_le _ _ s).trans + change _ ≤ relaxedMinimumViolations _ _ + 1 + rw [he, ← hs] + split <;> omega + +noncomputable def rootMinimum (n m : ℕ) (x : RootPath (RelaxedClause n) m) : ℝ := + clauseMinimum (rootArray m x) + +theorem rootMinimum_bound (n m : ℕ) (x : RootPath (RelaxedClause n) m) : + |rootMinimum n m x| ≤ m := by + rw [rootMinimum, abs_of_nonneg (Nat.cast_nonneg _)] + exact_mod_cast clauseMinimum_le_length (rootArray m x) + +theorem rootMinimum_replace (n m : ℕ) (q : Fin m) + (x : RootPath (RelaxedClause n) m) (c : RelaxedClause n) : + |rootMinimum n m x - rootMinimum n m (replaceRoot m x q c)| ≤ 1 := by + simp only [rootMinimum, rootArray_replace] + exact clauseMinimum_update_bound _ _ _ + +theorem rootMinimum_cons (n m : ℕ) (c : RelaxedClause n) + (x : RootPath (RelaxedClause n) m) : + |rootMinimum n (m+1) (c,x) - rootMinimum n m x| ≤ 1 := by + obtain ⟨hlo,hhi⟩ := clauseMinimum_cons_bounds (rootArray m x) c + have hlo' : (clauseMinimum (rootArray m x) : ℝ) ≤ + clauseMinimum (Fin.cons c (rootArray m x)) := by exact_mod_cast hlo + have hhi' : (clauseMinimum (Fin.cons c (rootArray m x)) : ℝ) ≤ + clauseMinimum (rootArray m x) + 1 := by exact_mod_cast hhi + change |(clauseMinimum (Fin.cons c (rootArray m x)) : ℝ)-clauseMinimum (rootArray m x)| ≤ 1 + exact abs_le.mpr ⟨by linarith, by linarith⟩ + +theorem rootMinimum_variance (n : ℕ) (μ : Measure (RelaxedClause n)) + [IsProbabilityMeasure μ] (r : ℝ≥0) : + (∫ m : ℕ, ∫ x, (rootMinimum n m x - poissonRootAverage μ r (rootMinimum n))^2 + ∂rootLaw m (fun _ => μ) ∂poissonMeasure r) ≤ 3/2 * (r : ℝ) := by + have h := poisson_root_second_moment μ r + (fun m => measurable_of_countable (rootMinimum n m)) (rootMinimum_bound n) + (show (0 : ℝ) ≤ 1 by norm_num) (rootMinimum_replace n) (rootMinimum_cons n) + (poissonRootAverage μ r (rootMinimum n)) + norm_num only [sub_self, zero_pow (by decide : 2 ≠ 0), add_zero, one_pow] at h + exact h + +noncomputable def rootSatisfiableProbability (n : ℕ) (μ : Measure (RelaxedClause n)) + (r : ℝ≥0) : ℝ := + poissonRootAverage μ r (fun m x => if rootMinimum n m x = 0 then 1 else 0) + +theorem rootMinimum_mean_sq (n : ℕ) (μ : Measure (RelaxedClause n)) + [IsProbabilityMeasure μ] (r : ℝ≥0) : + rootSatisfiableProbability n μ r * (poissonRootAverage μ r (rootMinimum n))^2 ≤ + 3/2 * (r : ℝ) := by + let c := poissonRootAverage μ r (rootMinimum n) + have hinner (m : ℕ) : Integrable (fun x : RootPath (RelaxedClause n) m => + (rootMinimum n m x-c)^2) (rootLaw m (fun _ => μ)) := by + apply Integrable.of_bound (measurable_of_countable _).aestronglyMeasurable ((m+|c|)^2) + apply ae_of_all + intro x + rw [Real.norm_eq_abs, abs_of_nonneg (sq_nonneg _)] + have h := (abs_sub (rootMinimum n m x) c).trans + (add_le_add (rootMinimum_bound n m x) le_rfl) + nlinarith [sq_abs (rootMinimum n m x-c), abs_nonneg (rootMinimum n m x-c), + abs_nonneg c, Nat.cast_nonneg (α := ℝ) m] + have houter : Integrable (fun m : ℕ => ∫ x, (rootMinimum n m x-c)^2 + ∂rootLaw m (fun _ => μ)) (poissonMeasure r) := by + apply poisson_integrable_quadratic r (A := 2*c^2) (B := 2) + intro m + apply abs_integral_le_bound + intro x + rw [abs_of_nonneg (sq_nonneg _)] + have h := rootMinimum_bound n m x + have hsq : (rootMinimum n m x)^2 ≤ (m : ℝ)^2 := by + nlinarith [sq_abs (rootMinimum n m x), abs_nonneg (rootMinimum n m x), + Nat.cast_nonneg (α := ℝ) m] + nlinarith [sq_nonneg (rootMinimum n m x+c)] + have hpoint (m : ℕ) (x : RootPath (RelaxedClause n) m) : + (if rootMinimum n m x = 0 then (1 : ℝ) else 0)*c^2 ≤ + (rootMinimum n m x-c)^2 := by + split_ifs with h + · rw [h]; ring_nf; exact le_rfl + · simpa only [zero_mul] using sq_nonneg (rootMinimum n m x-c) + have hb := integral_mono_of_nonneg (μ := poissonMeasure r) + (ae_of_all _ (fun m => integral_nonneg (fun x => by positivity))) houter + (ae_of_all _ (fun m => integral_mono_of_nonneg + (ae_of_all _ (fun x => by positivity)) (hinner m) (ae_of_all _ (hpoint m)))) + simp only [integral_mul_const] at hb + exact hb.trans (rootMinimum_variance n μ r) + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/SATModel.lean b/lean/OAI/Probability/SATComputability/SATModel.lean new file mode 100644 index 0000000000000000000000000000000000000000..5650f7464b8e81fb0f882d189e439f046fae7ce0 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/SATModel.lean @@ -0,0 +1,146 @@ +import OAI.Probability.DilutedSpin.Model + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass MeasureTheory ProbabilityTheory +open scoped BigOperators NNReal + +def literalFactor (sign value : Bool) : ℝ := if value = sign then 0 else 1 + +theorem literalFactor_nonneg (sign value : Bool) : 0 ≤ literalFactor sign value := by + unfold literalFactor + split <;> norm_num + +theorem literalFactor_le_one (sign value : Bool) : literalFactor sign value ≤ 1 := by + unfold literalFactor + split <;> norm_num + +theorem product_literalFactor (J s : Fin 3 → Bool) : + (∏ l, literalFactor (J l) (s l)) = if ∀ l, s l ≠ J l then 1 else 0 := by + classical + split_ifs with h + · apply Finset.prod_eq_one + intro l _ + simp [literalFactor, h l] + · obtain ⟨l, hl⟩ := not_forall.mp h + apply Finset.prod_eq_zero (Finset.mem_univ l) + simp only [not_not] at hl + simp [literalFactor, hl] + +noncomputable def satInteraction (β : ℝ) (J : Fin 3 → Bool) : Interaction 3 := + fun s => if ∀ l, s l ≠ J l then -β else 0 + +noncomputable def satSample (β : ℝ) (J : Fin 3 → Bool) : InteractionSample 3 := + (satInteraction β J, 1, Real.exp (-β) - 1, fun l => literalFactor (J l)) + +theorem satSample_factorization (β : ℝ) (J s : Fin 3 → Bool) : + Real.exp ((satSample β J).1 s) = + (satSample β J).2.1 * + (1 + (satSample β J).2.2.1 * ∏ l, (satSample β J).2.2.2 l (s l)) := by + simp only [satSample, satInteraction, product_literalFactor] + split_ifs <;> simp + +theorem satInteraction_norm_le {β : ℝ} (hβ : 0 ≤ β) (J : Fin 3 → Bool) : + ‖satInteraction β J‖ ≤ β := by + apply (pi_norm_le_iff_of_nonneg hβ).mpr + intro s + unfold satInteraction + split <;> simp [Real.norm_eq_abs, abs_of_nonneg hβ, hβ] + +theorem satSample_product_bound {β : ℝ} (hβ : 0 < β) (J s : Fin 3 → Bool) : + |(satSample β J).2.2.1 * ∏ l, (satSample β J).2.2.2 l (s l)| < 1 := by + have he : Real.exp (-β) < 1 := Real.exp_lt_one_iff.mpr (by linarith) + have hp := Real.exp_pos (-β) + simp only [satSample, product_literalFactor] + split_ifs + · rw [mul_one, abs_of_neg (by linarith)] + linarith + · norm_num + +noncomputable def signLaw : ProbabilityMeasure (Fin 3 → Bool) := + ⟨(PMF.uniformOfFintype (Fin 3 → Bool)).toMeasure, inferInstance⟩ + +noncomputable def satModel (a : ℝ≥0) (β : ℝ) : Model 3 where + alpha := a + disorder := signLaw.map (satSample β) + field := ⟨Measure.dirac 0, inferInstance⟩ + +theorem satModel_supported (a : ℝ≥0) (β : ℝ) : + ∀ᵐ z ∂(satModel a β).disorder.toMeasure, ∃ J, satSample β J = z := by + exact ae_map_mem_range (Set.finite_range _).measurableSet + (measurable_of_countable _).aemeasurable + +theorem satModel_interaction_integrable (a : ℝ≥0) {β : ℝ} (hβ : 0 ≤ β) : + Integrable (fun z : InteractionSample 3 => ‖z.1‖) (satModel a β).disorder.toMeasure := by + apply Integrable.of_bound (by fun_prop) β + filter_upwards [satModel_supported a β] with z hz + obtain ⟨J, rfl⟩ := hz + simpa only [norm_norm, satSample] using satInteraction_norm_le hβ J + +theorem satModel_field_integrable (a : ℝ≥0) (β : ℝ) : + Integrable (fun h : ℝ => |h|) (satModel a β).field.toMeasure := by + change Integrable (fun h : ℝ => |h|) (Measure.dirac 0) + exact integrable_dirac (by simp) + +theorem signLaw_equiv (e : (Fin 3 → Bool) ≃ (Fin 3 → Bool)) : + Measure.map e signLaw.toMeasure = signLaw.toMeasure := by + apply Measure.ext_of_singleton + intro J + rw [Measure.map_apply (measurable_of_countable _) (measurableSet_singleton J)] + have he : e ⁻¹' {J} = {e.symm J} := by + ext K + change e K = J ↔ K = e.symm J + constructor + · intro h + simpa using congrArg e.symm h + · intro h + simpa using congrArg e h + rw [he] + change (PMF.uniformOfFintype (Fin 3 → Bool)).toMeasure {e.symm J} = + (PMF.uniformOfFintype (Fin 3 → Bool)).toMeasure {J} + rw [PMF.toMeasure_apply_singleton, PMF.toMeasure_apply_singleton] <;> simp + +def permuteSigns (e : Equiv.Perm (Fin 3)) : (Fin 3 → Bool) ≃ (Fin 3 → Bool) where + toFun J := fun l => J (e.symm l) + invFun J := fun l => J (e l) + left_inv J := by funext l; simp + right_inv J := by funext l; simp + +theorem satInteraction_permute (β : ℝ) (e : Equiv.Perm (Fin 3)) (J s : Fin 3 → Bool) : + satInteraction β J (fun l => s (e l)) = + satInteraction β (permuteSigns e J) s := by + have h : (∀ l, s (e l) ≠ J l) ↔ ∀ l, s l ≠ J (e.symm l) := by + constructor + · intro h l + simpa using h (e.symm l) + · intro h l + simpa using h (e l) + simp only [satInteraction, permuteSigns, Equiv.coe_fn_mk] + exact if_congr h rfl rfl + +theorem satModel_symmetric (a : ℝ≥0) (β : ℝ) (e : Equiv.Perm (Fin 3)) : + IdentDistrib (fun z : InteractionSample 3 => z.1) + (fun z : InteractionSample 3 => fun s : Fin 3 → Spin => z.1 (fun l => s (e l))) + (satModel a β).disorder.toMeasure (satModel a β).disorder.toMeasure := by + constructor + · exact measurable_fst.aemeasurable + · exact (show Measurable (fun z : InteractionSample 3 => fun s : Fin 3 → Spin => + z.1 (fun l => s (e l))) by fun_prop).aemeasurable + · change Measure.map _ (Measure.map (satSample β) signLaw.toMeasure) = + Measure.map _ (Measure.map (satSample β) signLaw.toMeasure) + rw [Measure.map_map measurable_fst (measurable_of_countable _), + Measure.map_map (show Measurable (fun z : InteractionSample 3 => fun s : Fin 3 → Spin => + z.1 (fun l => s (e l))) by fun_prop) (measurable_of_countable _)] + change Measure.map (satInteraction β) signLaw.toMeasure = + Measure.map (fun J => fun s => satInteraction β J (fun l => s (e l))) signLaw.toMeasure + simp_rw [satInteraction_permute] + change Measure.map (satInteraction β) signLaw.toMeasure = + Measure.map (satInteraction β ∘ permuteSigns e) signLaw.toMeasure + rw [← Measure.map_map (measurable_of_countable (satInteraction β)) + (measurable_of_countable (permuteSigns e)), signLaw_equiv] + +end FixedClauseThreshold.Computability + +end OAI diff --git a/lean/OAI/Probability/SATComputability/SATVariational.lean b/lean/OAI/Probability/SATComputability/SATVariational.lean new file mode 100644 index 0000000000000000000000000000000000000000..48ad5e66b56fe1081bdb1dd839c6dbdf930fc311 --- /dev/null +++ b/lean/OAI/Probability/SATComputability/SATVariational.lean @@ -0,0 +1,96 @@ +import OAI.Probability.SATComputability.InterpolationUpper +import OAI.Probability.SATComputability.ReplicaPositivity +import OAI.Probability.SATComputability.RationalHierarchy +import OAI.Probability.SATComputability.RelaxedPressure +import OAI.Probability.SATComputability.ExponentContinuity +import OAI.Probability.DilutedSpin.SymmetricTrialLower + +namespace OAI + +namespace FixedClauseThreshold.Computability + +open DilutedSpinGlass _root_.MeasureTheory _root_.OAI.MeasureTheory ProbabilityTheory Filter +open scoped Topology NNReal + +noncomputable def satPressure (a : ℝ≥0) (β : ℝ) : ℝ := + liminf (pressure (satModel a β)) atTop + +theorem satPressure_tendsto {a : ℝ≥0} (ha : 0 < a) {β : ℝ} (hβ : 0 < β) : + Tendsto (pressure (satModel a β)) atTop (nhds (satPressure a β)) := by + have hθ := satModel_interaction_integrable a hβ.le + have hh := satModel_field_integrable a β + have hb := pressure_bounded (satModel a β) hθ hh + have hs : limsup (pressure (satModel a β)) atTop ≤ satPressure a β := by + apply le_of_forall_pos_le_add + intro ε hε + obtain ⟨r, ζ, m, hm, happrox⟩ := symmetric_trial_lower (satModel a β) ha + hθ hh (satModel_symmetric a β) hε + have hu : limsup (pressure (satModel a β)) atTop ≤ functional (satModel a β) r ζ m := by + apply limsup_le_of_le hb.2.isCobounded_le + filter_upwards [eventually_gt_atTop 0] with N hN + let : NeZero N := ⟨Nat.ne_of_gt hN⟩ + exact PositiveInterpolation.pressure_le_functional (satModel a β) + (satModel_interpolation_admissible ha hβ) r ζ m hm + exact hu.trans happrox + exact tendsto_of_le_liminf_of_limsup_le le_rfl hs hb.1 hb.2 + +theorem relaxedPressure_tendsto {a : ℝ≥0} (ha : 0 < a) {β : ℝ} (hβ : 0 < β) : + Tendsto (relaxedPoissonPressure a β) atTop (nhds (satPressure a β)) := by + have he : pressure (satModel a β) = relaxedPoissonPressure a β := + funext (satModel_pressure a β) + rw [← he] + exact satPressure_tendsto ha hβ + +theorem satPressure_le_rational_trial {a : ℝ≥0} (ha : 0 < a) {β : ℝ} (hβ : 0 < β) + (r : ℕ) (t : RationalTree (r+1)) (m : Fin r → ℝ) (hm : Exponents m) : + satPressure a β ≤ functional (satModel a β) r (rationalTreeValue (r+1) t) m := by + apply le_of_tendsto (satPressure_tendsto ha hβ) + filter_upwards [eventually_gt_atTop 0] with N hN + let : NeZero N := ⟨Nat.ne_of_gt hN⟩ + exact PositiveInterpolation.finiteHierarchy_pressure_le (satModel a β) + (satModel_interpolation_admissible ha hβ) r _ (rationalTreeValue_finite _ _) m hm + +theorem exists_rational_trial_near_pressure {a : ℝ≥0} (ha : 0 < a) {β : ℝ} (hβ : 0 < β) + {ε : ℝ} (hε : 0 < ε) : + ∃ (r : ℕ) (t : RationalTree (r+1)) (m : Fin r → ℝ), Exponents m ∧ + functional (satModel a β) r (rationalTreeValue (r+1) t) m < satPressure a β + ε := by + obtain ⟨r, ζ, m, hm, happrox⟩ := symmetric_trial_lower (satModel a β) ha + (satModel_interaction_integrable a hβ.le) (satModel_field_integrable a β) + (satModel_symmetric a β) (show 0 < ε/2 by positivity) + have hc := functional_continuous (satModel a β) m (fun i => (hm.2 i).1) + (satModel_interaction_integrable a hβ.le) (satModel_field_integrable a β) + have hn : {η | functional (satModel a β) r η m < satPressure a β+ε} ∈ nhds ζ := + hc.continuousAt.preimage_mem_nhds (Iio_mem_nhds (by + change functional (satModel a β) r ζ m ≤ satPressure a β+ε/2 at happrox + linarith)) + obtain ⟨η, hη, hη'⟩ := mem_closure_iff_nhds.mp ((rationalTreeValue_dense (r+1)) ζ) _ hn + obtain ⟨t, rfl⟩ := hη' + exact ⟨r, t, m, hm, hη⟩ + +theorem exists_fully_rational_trial_near_pressure {a : ℝ≥0} (ha : 0 < a) + {β : ℝ} (hβ : 0 < β) {ε : ℝ} (hε : 0 < ε) : + ∃ (r : ℕ) (t : RationalTree (r+1)) (m : Fin r → ℚ), + Exponents (fun i => (m i : ℝ)) ∧ + functional (satModel a β) r (rationalTreeValue (r+1) t) (fun i => (m i : ℝ)) < + satPressure a β + ε := by + obtain ⟨r, t, m, hm, ht⟩ := exists_rational_trial_near_pressure ha hβ hε + have hc := functional_continuousAt_exponents (satModel a β) + (satModel_interaction_integrable a hβ.le) (satModel_field_integrable a β) + (rationalTreeValue (r+1) t) hm + have hn : {m : Fin r → ℝ | functional (satModel a β) r + (rationalTreeValue (r+1) t) m < satPressure a β + ε} ∈ nhds m := + hc.preimage_mem_nhds (Iio_mem_nhds ht) + obtain ⟨q, hq, hv⟩ := exists_rational_exponents hm hn + exact ⟨r, t, q, hq, hv⟩ + +theorem negative_pressure_has_rational_trial {a : ℝ≥0} (ha : 0 < a) + {β : ℝ} (hβ : 0 < β) (hneg : satPressure a β < 0) : + ∃ (r : ℕ) (t : RationalTree (r+1)) (m : Fin r → ℚ), + Exponents (fun i => (m i : ℝ)) ∧ + functional (satModel a β) r (rationalTreeValue (r+1) t) (fun i => (m i : ℝ)) < 0 := by + obtain ⟨r, t, m, hm, hv⟩ := exists_fully_rational_trial_near_pressure ha hβ (neg_pos.mpr hneg) + exact ⟨r, t, m, hm, by simpa only [add_neg_cancel] using hv⟩ + +end FixedClauseThreshold.Computability + +end OAI